|
|
@@ -1,10 +1,5 @@
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
-import {
|
|
|
- CODE_MODE_TOOL,
|
|
|
- CodeModeTool,
|
|
|
- Parameters,
|
|
|
- describeCatalog,
|
|
|
-} from "@/tool/code-mode"
|
|
|
+import { CODE_MODE_TOOL, CodeModeTool, Parameters, describeCatalog } from "@/tool/code-mode"
|
|
|
import type { Tool as MCPToolDef } from "@modelcontextprotocol/sdk/types.js"
|
|
|
import type { PermissionV1 } from "@opencode-ai/core/v1/permission"
|
|
|
import { Agent } from "@/agent/agent"
|
|
|
@@ -157,7 +152,9 @@ describe("code mode execute", () => {
|
|
|
expect(description).not.toContain("Browse one namespace")
|
|
|
expect(description).toContain("## Workflow")
|
|
|
expect(description).toContain("1. Pick a tool from the list under `## Available tools`")
|
|
|
- expect(description).toContain('`const data = typeof res === "string" ? JSON.parse(res) : res` - most tools return JSON as a string')
|
|
|
+ expect(description).toContain(
|
|
|
+ '`const data = typeof res === "string" ? JSON.parse(res) : res` - most tools return JSON as a string',
|
|
|
+ )
|
|
|
expect(description).toContain("Return only the fields you need")
|
|
|
expect(description).not.toContain("total_count")
|
|
|
})
|
|
|
@@ -206,7 +203,9 @@ describe("code mode execute", () => {
|
|
|
expect(description).toContain("tools.zeta.only_tool(input: { topic: string }): Promise<unknown>")
|
|
|
expect(description).toContain("tools.$codemode.search(")
|
|
|
expect(description).toContain("1. Find a tool (skip when it is already listed below)")
|
|
|
- expect(description).toContain('- Browse one namespace: `await tools.$codemode.search({ query: "", namespace: "<name>" })`.')
|
|
|
+ expect(description).toContain(
|
|
|
+ '- Browse one namespace: `await tools.$codemode.search({ query: "", namespace: "<name>" })`.',
|
|
|
+ )
|
|
|
expect(description).not.toContain("total_count")
|
|
|
expect(description).toContain("tools.alpha.op_0(")
|
|
|
expect(description).not.toContain("tools.alpha.op_99(")
|
|
|
@@ -240,7 +239,10 @@ describe("code mode execute", () => {
|
|
|
linear_search: mcpTool("search", () => ""),
|
|
|
})
|
|
|
const output = await Effect.runPromise(
|
|
|
- tool.execute({ code: "const namespaces = Object.keys(tools); return { namespaces, count: namespaces.length }" }, ctx),
|
|
|
+ tool.execute(
|
|
|
+ { code: "const namespaces = Object.keys(tools); return { namespaces, count: namespaces.length }" },
|
|
|
+ ctx,
|
|
|
+ ),
|
|
|
)
|
|
|
expect(JSON.parse(output.output)).toEqual({ namespaces: ["github", "linear"], count: 2 })
|
|
|
})
|
|
|
@@ -547,7 +549,12 @@ describe("code mode execute", () => {
|
|
|
const tool = await build({
|
|
|
docs_find: mcpTool("find", () => ({
|
|
|
content: [
|
|
|
- { type: "resource_link", uri: "https://example.com/guide.pdf", name: "guide.pdf", mimeType: "application/pdf" },
|
|
|
+ {
|
|
|
+ type: "resource_link",
|
|
|
+ uri: "https://example.com/guide.pdf",
|
|
|
+ name: "guide.pdf",
|
|
|
+ mimeType: "application/pdf",
|
|
|
+ },
|
|
|
{ type: "resource_link", uri: "file:///tmp/notes.md", name: "notes.md" },
|
|
|
],
|
|
|
})),
|
|
|
@@ -562,9 +569,7 @@ describe("code mode execute", () => {
|
|
|
const tool = await build({
|
|
|
shot_take: mcpTool("take", () => ({ content: [{ type: "image", data: "PNGDATA", mimeType: "image/png" }] })),
|
|
|
})
|
|
|
- const out = await Effect.runPromise(
|
|
|
- tool.execute({ code: "await tools.shot.take({}); return 'captured'" }, ctx),
|
|
|
- )
|
|
|
+ const out = await Effect.runPromise(tool.execute({ code: "await tools.shot.take({}); return 'captured'" }, ctx))
|
|
|
expect(out.output).toBe("captured")
|
|
|
expect(out.attachments).toHaveLength(1)
|
|
|
})
|
|
|
@@ -680,9 +685,7 @@ describe("code mode permission visibility", () => {
|
|
|
expect(denied.output).not.toContain("permission")
|
|
|
expect(called).toEqual([])
|
|
|
|
|
|
- const allowed = await Effect.runPromise(
|
|
|
- tool.execute({ code: "return await tools.github.list_issues({})" }, ctx),
|
|
|
- )
|
|
|
+ const allowed = await Effect.runPromise(tool.execute({ code: "return await tools.github.list_issues({})" }, ctx))
|
|
|
expect(allowed.metadata.error).toBeUndefined()
|
|
|
expect(allowed.output).toBe("ok")
|
|
|
})
|
|
|
@@ -695,9 +698,7 @@ describe("code mode permission visibility", () => {
|
|
|
["github"],
|
|
|
[askRule("github_list_issues")],
|
|
|
)
|
|
|
- const out = await Effect.runPromise(
|
|
|
- tool.execute({ code: "return await tools.github.list_issues({})" }, askCtx),
|
|
|
- )
|
|
|
+ const out = await Effect.runPromise(tool.execute({ code: "return await tools.github.list_issues({})" }, askCtx))
|
|
|
expect(out.output).toBe("ok")
|
|
|
expect(asked).toEqual(["github_list_issues"])
|
|
|
})
|