opencode-agent[bot] 2 mesi fa
parent
commit
72845e09fc

+ 4 - 7
packages/opencode/test/tool/code-mode-integration.test.ts

@@ -19,8 +19,7 @@ import {
 } from "@modelcontextprotocol/sdk/types.js"
 import { Effect, Layer } from "effect"
 
-const PNG =
-  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
+const PNG = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
 
 const SERVER = "fixtures"
 
@@ -141,8 +140,8 @@ async function buildTool() {
 
   const layer = Layer.mergeAll(
     Layer.mock(Plugin.Service, {
-      trigger: (((_name: unknown, _input: unknown, output: unknown) =>
-        Effect.succeed(output)) as Plugin.Interface["trigger"]),
+      trigger: ((_name: unknown, _input: unknown, output: unknown) =>
+        Effect.succeed(output)) as Plugin.Interface["trigger"],
     }),
     Layer.mock(Truncate.Service, {
       output: (text: string) => Effect.succeed({ content: text, truncated: false as const }),
@@ -172,9 +171,7 @@ describe("code mode integration (real MCP server)", () => {
   test("the appended catalog inlines full signatures with real MCP schemas", () => {
     expect(description).toContain("Available tools (COMPLETE list")
     expect(description).toContain("- fixtures (4 tools)")
-    expect(description).toContain(
-      "tools.fixtures.add(input: { a: number; b: number }): Promise<{ sum: number }>",
-    )
+    expect(description).toContain("tools.fixtures.add(input: { a: number; b: number }): Promise<{ sum: number }>")
     expect(description).toContain("tools.fixtures.get_text(input: { name: string }): Promise<unknown>")
     expect(description).toContain("// Add two numbers and return the structured sum")
     expect(description).not.toContain("$codemode")

+ 20 - 19
packages/opencode/test/tool/code-mode.test.ts

@@ -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"])
   })