fix: update session-manager tests to use factory pattern
This commit is contained in:
parent
476f154ef5
commit
c688e978fd
@ -1,9 +1,12 @@
|
|||||||
import { describe, test, expect } from "bun:test"
|
import { describe, test, expect } from "bun:test"
|
||||||
import { session_list, session_read, session_search, session_info } from "./tools"
|
import { createSessionManagerTools } from "./tools"
|
||||||
import type { ToolContext } from "@opencode-ai/plugin/tool"
|
import type { ToolContext } from "@opencode-ai/plugin/tool"
|
||||||
|
import type { PluginInput } from "@opencode-ai/plugin"
|
||||||
|
|
||||||
const projectDir = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
const projectDir = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
||||||
|
|
||||||
|
const mockCtx = { directory: projectDir } as PluginInput
|
||||||
|
|
||||||
const mockContext: ToolContext = {
|
const mockContext: ToolContext = {
|
||||||
sessionID: "test-session",
|
sessionID: "test-session",
|
||||||
messageID: "test-message",
|
messageID: "test-message",
|
||||||
@ -15,6 +18,9 @@ const mockContext: ToolContext = {
|
|||||||
ask: async () => {},
|
ask: async () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tools = createSessionManagerTools(mockCtx)
|
||||||
|
const { session_list, session_read, session_search, session_info } = tools
|
||||||
|
|
||||||
describe("session-manager tools", () => {
|
describe("session-manager tools", () => {
|
||||||
test("session_list executes without error", async () => {
|
test("session_list executes without error", async () => {
|
||||||
const result = await session_list.execute({}, mockContext)
|
const result = await session_list.execute({}, mockContext)
|
||||||
@ -38,23 +44,23 @@ describe("session-manager tools", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test("session_list filters by project_path", async () => {
|
test("session_list filters by project_path", async () => {
|
||||||
// given
|
//#given
|
||||||
const projectPath = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
const projectPath = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
||||||
|
|
||||||
// when
|
//#when
|
||||||
const result = await session_list.execute({ project_path: projectPath }, mockContext)
|
const result = await session_list.execute({ project_path: projectPath }, mockContext)
|
||||||
|
|
||||||
// then
|
//#then
|
||||||
expect(typeof result).toBe("string")
|
expect(typeof result).toBe("string")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("session_list uses process.cwd() as default project_path", async () => {
|
test("session_list uses ctx.directory as default project_path", async () => {
|
||||||
// given - no project_path provided
|
//#given - no project_path provided
|
||||||
|
|
||||||
// when
|
//#when
|
||||||
const result = await session_list.execute({}, mockContext)
|
const result = await session_list.execute({}, mockContext)
|
||||||
|
|
||||||
// then - should not throw and return string (uses process.cwd() internally)
|
//#then
|
||||||
expect(typeof result).toBe("string")
|
expect(typeof result).toBe("string")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user