fix(session-manager): add missing context parameter to tool execute functions

The tool() wrapper from @opencode-ai/plugin requires execute(args, context: ToolContext) signature. Updated all session-manager tool functions (session_list, session_read, session_search, session_info) to accept the context parameter, and updated corresponding tests with mockContext.

🤖 Generated with assistance of OhMyOpenCode
This commit is contained in:
YeonGyu-Kim
2025-12-25 18:31:35 +09:00
parent a8fdb78796
commit 48476e7257
2 changed files with 24 additions and 16 deletions

View File

@@ -1,15 +1,23 @@
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 { session_list, session_read, session_search, session_info } from "./tools"
import type { ToolContext } from "@opencode-ai/plugin/tool"
const mockContext: ToolContext = {
sessionID: "test-session",
messageID: "test-message",
agent: "test-agent",
abort: new AbortController().signal,
}
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({}) const result = await session_list.execute({}, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
test("session_list respects limit parameter", async () => { test("session_list respects limit parameter", async () => {
const result = await session_list.execute({ limit: 5 }) const result = await session_list.execute({ limit: 5 }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
@@ -18,13 +26,13 @@ describe("session-manager tools", () => {
const result = await session_list.execute({ const result = await session_list.execute({
from_date: "2025-12-01T00:00:00Z", from_date: "2025-12-01T00:00:00Z",
to_date: "2025-12-31T23:59:59Z", to_date: "2025-12-31T23:59:59Z",
}) }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
test("session_read handles non-existent session", async () => { test("session_read handles non-existent session", async () => {
const result = await session_read.execute({ session_id: "ses_nonexistent" }) const result = await session_read.execute({ session_id: "ses_nonexistent" }, mockContext)
expect(result).toContain("not found") expect(result).toContain("not found")
}) })
@@ -34,7 +42,7 @@ describe("session-manager tools", () => {
session_id: "ses_test123", session_id: "ses_test123",
include_todos: true, include_todos: true,
include_transcript: true, include_transcript: true,
}) }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
@@ -43,13 +51,13 @@ describe("session-manager tools", () => {
const result = await session_read.execute({ const result = await session_read.execute({
session_id: "ses_test123", session_id: "ses_test123",
limit: 10, limit: 10,
}) }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
test("session_search executes without error", async () => { test("session_search executes without error", async () => {
const result = await session_search.execute({ query: "test" }) const result = await session_search.execute({ query: "test" }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
@@ -58,7 +66,7 @@ describe("session-manager tools", () => {
const result = await session_search.execute({ const result = await session_search.execute({
query: "test", query: "test",
session_id: "ses_test123", session_id: "ses_test123",
}) }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
@@ -67,7 +75,7 @@ describe("session-manager tools", () => {
const result = await session_search.execute({ const result = await session_search.execute({
query: "TEST", query: "TEST",
case_sensitive: true, case_sensitive: true,
}) }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
@@ -76,19 +84,19 @@ describe("session-manager tools", () => {
const result = await session_search.execute({ const result = await session_search.execute({
query: "test", query: "test",
limit: 5, limit: 5,
}) }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })
test("session_info handles non-existent session", async () => { test("session_info handles non-existent session", async () => {
const result = await session_info.execute({ session_id: "ses_nonexistent" }) const result = await session_info.execute({ session_id: "ses_nonexistent" }, mockContext)
expect(result).toContain("not found") expect(result).toContain("not found")
}) })
test("session_info executes with valid session", async () => { test("session_info executes with valid session", async () => {
const result = await session_info.execute({ session_id: "ses_test123" }) const result = await session_info.execute({ session_id: "ses_test123" }, mockContext)
expect(typeof result).toBe("string") expect(typeof result).toBe("string")
}) })

View File

@@ -16,7 +16,7 @@ export const session_list = tool({
from_date: tool.schema.string().optional().describe("Filter sessions from this date (ISO 8601 format)"), from_date: tool.schema.string().optional().describe("Filter sessions from this date (ISO 8601 format)"),
to_date: tool.schema.string().optional().describe("Filter sessions until this date (ISO 8601 format)"), to_date: tool.schema.string().optional().describe("Filter sessions until this date (ISO 8601 format)"),
}, },
execute: async (args: SessionListArgs) => { execute: async (args: SessionListArgs, _context) => {
try { try {
let sessions = getAllSessions() let sessions = getAllSessions()
@@ -43,7 +43,7 @@ export const session_read = tool({
include_transcript: tool.schema.boolean().optional().describe("Include transcript log if available (default: false)"), include_transcript: tool.schema.boolean().optional().describe("Include transcript log if available (default: false)"),
limit: tool.schema.number().optional().describe("Maximum number of messages to return (default: all)"), limit: tool.schema.number().optional().describe("Maximum number of messages to return (default: all)"),
}, },
execute: async (args: SessionReadArgs) => { execute: async (args: SessionReadArgs, _context) => {
try { try {
if (!sessionExists(args.session_id)) { if (!sessionExists(args.session_id)) {
return `Session not found: ${args.session_id}` return `Session not found: ${args.session_id}`
@@ -72,7 +72,7 @@ export const session_search = tool({
case_sensitive: tool.schema.boolean().optional().describe("Case-sensitive search (default: false)"), case_sensitive: tool.schema.boolean().optional().describe("Case-sensitive search (default: false)"),
limit: tool.schema.number().optional().describe("Maximum number of results to return (default: 20)"), limit: tool.schema.number().optional().describe("Maximum number of results to return (default: 20)"),
}, },
execute: async (args: SessionSearchArgs) => { execute: async (args: SessionSearchArgs, _context) => {
try { try {
const sessions = args.session_id ? [args.session_id] : getAllSessions() const sessions = args.session_id ? [args.session_id] : getAllSessions()
@@ -92,7 +92,7 @@ export const session_info = tool({
args: { args: {
session_id: tool.schema.string().describe("Session ID to inspect"), session_id: tool.schema.string().describe("Session ID to inspect"),
}, },
execute: async (args: SessionInfoArgs) => { execute: async (args: SessionInfoArgs, _context) => {
try { try {
const info = getSessionInfo(args.session_id) const info = getSessionInfo(args.session_id)