test(tools): update MCP, delegate-task, skill, and slashcommand tests
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, test, expect } from "bun:test"
|
||||
import { createSessionManagerTools } from "./tools"
|
||||
import type { ToolContext } from "@opencode-ai/plugin/tool"
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import type { SessionInfo, SessionMessage, SearchResult, SessionMetadata, TodoItem } from "./types"
|
||||
|
||||
const projectDir = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
||||
|
||||
@@ -18,23 +19,83 @@ const mockContext: ToolContext = {
|
||||
ask: async () => {},
|
||||
}
|
||||
|
||||
const tools = createSessionManagerTools(mockCtx)
|
||||
const { session_list, session_read, session_search, session_info } = tools
|
||||
function createTestTools() {
|
||||
return createSessionManagerTools(mockCtx, {
|
||||
setStorageClient: () => {},
|
||||
getMainSessions: async (): Promise<SessionMetadata[]> => [
|
||||
{
|
||||
id: "ses_test123",
|
||||
projectID: "project-1",
|
||||
directory: projectDir,
|
||||
time: { created: Date.now(), updated: Date.now() },
|
||||
},
|
||||
{
|
||||
id: "ses_test456",
|
||||
projectID: "project-1",
|
||||
directory: projectDir,
|
||||
time: { created: Date.now(), updated: Date.now() },
|
||||
},
|
||||
],
|
||||
filterSessionsByDate: async (sessionIDs) => sessionIDs,
|
||||
formatSessionList: async (sessionIDs) => `sessions:${sessionIDs.join(",")}`,
|
||||
sessionExists: async (sessionID) => sessionID === "ses_test123",
|
||||
readSessionMessages: async (sessionID): Promise<SessionMessage[]> =>
|
||||
sessionID === "ses_test123"
|
||||
? [{
|
||||
id: `${sessionID}-msg`,
|
||||
role: "user",
|
||||
time: { created: Date.now() },
|
||||
parts: [{ id: `${sessionID}-part`, type: "text", text: "hello" }],
|
||||
}]
|
||||
: [],
|
||||
readSessionTodos: async (): Promise<TodoItem[]> => [],
|
||||
formatSessionMessages: (messages) => `messages:${messages.length}`,
|
||||
getAllSessions: async () => ["ses_test123", "ses_test456"],
|
||||
searchInSession: async (sessionID): Promise<SearchResult[]> => [
|
||||
{
|
||||
session_id: sessionID,
|
||||
message_id: `${sessionID}-msg`,
|
||||
excerpt: "test snippet",
|
||||
role: "user",
|
||||
match_count: 1,
|
||||
},
|
||||
],
|
||||
formatSearchResults: (results) => `results:${results.length}`,
|
||||
getSessionInfo: async (sessionID): Promise<SessionInfo | null> =>
|
||||
sessionID === "ses_test123"
|
||||
? {
|
||||
id: sessionID,
|
||||
message_count: 1,
|
||||
first_message: new Date(),
|
||||
last_message: new Date(),
|
||||
agents_used: ["test-agent"],
|
||||
has_todos: false,
|
||||
has_transcript: false,
|
||||
todos: [],
|
||||
transcript_entries: 0,
|
||||
}
|
||||
: null,
|
||||
formatSessionInfo: (info) => `info:${info.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
describe("session-manager tools", () => {
|
||||
test("session_list executes without error", async () => {
|
||||
const { session_list } = createTestTools()
|
||||
const result = await session_list.execute({}, mockContext)
|
||||
|
||||
expect(typeof result).toBe("string")
|
||||
})
|
||||
|
||||
test("session_list respects limit parameter", async () => {
|
||||
const { session_list } = createTestTools()
|
||||
const result = await session_list.execute({ limit: 5 }, mockContext)
|
||||
|
||||
expect(typeof result).toBe("string")
|
||||
})
|
||||
|
||||
test("session_list filters by date range", async () => {
|
||||
const { session_list } = createTestTools()
|
||||
const result = await session_list.execute({
|
||||
from_date: "2025-12-01T00:00:00Z",
|
||||
to_date: "2025-12-31T23:59:59Z",
|
||||
@@ -44,6 +105,7 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_list filters by project_path", async () => {
|
||||
const { session_list } = createTestTools()
|
||||
//#given
|
||||
const projectPath = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
||||
|
||||
@@ -55,6 +117,7 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_list uses ctx.directory as default project_path", async () => {
|
||||
const { session_list } = createTestTools()
|
||||
//#given - no project_path provided
|
||||
|
||||
//#when
|
||||
@@ -65,12 +128,14 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_read handles non-existent session", async () => {
|
||||
const { session_read } = createTestTools()
|
||||
const result = await session_read.execute({ session_id: "ses_nonexistent" }, mockContext)
|
||||
|
||||
expect(result).toContain("not found")
|
||||
})
|
||||
|
||||
test("session_read executes with valid parameters", async () => {
|
||||
const { session_read } = createTestTools()
|
||||
const result = await session_read.execute({
|
||||
session_id: "ses_test123",
|
||||
include_todos: true,
|
||||
@@ -81,6 +146,7 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_read respects limit parameter", async () => {
|
||||
const { session_read } = createTestTools()
|
||||
const result = await session_read.execute({
|
||||
session_id: "ses_test123",
|
||||
limit: 10,
|
||||
@@ -90,12 +156,14 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_search executes without error", async () => {
|
||||
const { session_search } = createTestTools()
|
||||
const result = await session_search.execute({ query: "test" }, mockContext)
|
||||
|
||||
expect(typeof result).toBe("string")
|
||||
})
|
||||
|
||||
test("session_search filters by session_id", async () => {
|
||||
const { session_search } = createTestTools()
|
||||
const result = await session_search.execute({
|
||||
query: "test",
|
||||
session_id: "ses_test123",
|
||||
@@ -105,6 +173,7 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_search respects case_sensitive parameter", async () => {
|
||||
const { session_search } = createTestTools()
|
||||
const result = await session_search.execute({
|
||||
query: "TEST",
|
||||
case_sensitive: true,
|
||||
@@ -114,6 +183,7 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_search respects limit parameter", async () => {
|
||||
const { session_search } = createTestTools()
|
||||
const result = await session_search.execute({
|
||||
query: "test",
|
||||
limit: 5,
|
||||
@@ -123,12 +193,14 @@ describe("session-manager tools", () => {
|
||||
})
|
||||
|
||||
test("session_info handles non-existent session", async () => {
|
||||
const { session_info } = createTestTools()
|
||||
const result = await session_info.execute({ session_id: "ses_nonexistent" }, mockContext)
|
||||
|
||||
expect(result).toContain("not found")
|
||||
})
|
||||
|
||||
test("session_info executes with valid session", async () => {
|
||||
const { session_info } = createTestTools()
|
||||
const result = await session_info.execute({ session_id: "ses_test123" }, mockContext)
|
||||
|
||||
expect(typeof result).toBe("string")
|
||||
|
||||
Reference in New Issue
Block a user