chore: generate
This commit is contained in:
parent
abaab29cb3
commit
72845e09fc
2 changed files with 24 additions and 26 deletions
|
|
@ -19,8 +19,7 @@ import {
|
||||||
} from "@modelcontextprotocol/sdk/types.js"
|
} from "@modelcontextprotocol/sdk/types.js"
|
||||||
import { Effect, Layer } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
|
|
||||||
const PNG =
|
const PNG = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
|
||||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
|
|
||||||
|
|
||||||
const SERVER = "fixtures"
|
const SERVER = "fixtures"
|
||||||
|
|
||||||
|
|
@ -141,8 +140,8 @@ async function buildTool() {
|
||||||
|
|
||||||
const layer = Layer.mergeAll(
|
const layer = Layer.mergeAll(
|
||||||
Layer.mock(Plugin.Service, {
|
Layer.mock(Plugin.Service, {
|
||||||
trigger: (((_name: unknown, _input: unknown, output: unknown) =>
|
trigger: ((_name: unknown, _input: unknown, output: unknown) =>
|
||||||
Effect.succeed(output)) as Plugin.Interface["trigger"]),
|
Effect.succeed(output)) as Plugin.Interface["trigger"],
|
||||||
}),
|
}),
|
||||||
Layer.mock(Truncate.Service, {
|
Layer.mock(Truncate.Service, {
|
||||||
output: (text: string) => Effect.succeed({ content: text, truncated: false as const }),
|
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", () => {
|
test("the appended catalog inlines full signatures with real MCP schemas", () => {
|
||||||
expect(description).toContain("Available tools (COMPLETE list")
|
expect(description).toContain("Available tools (COMPLETE list")
|
||||||
expect(description).toContain("- fixtures (4 tools)")
|
expect(description).toContain("- fixtures (4 tools)")
|
||||||
expect(description).toContain(
|
expect(description).toContain("tools.fixtures.add(input: { a: number; b: number }): Promise<{ sum: number }>")
|
||||||
"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("tools.fixtures.get_text(input: { name: string }): Promise<unknown>")
|
||||||
expect(description).toContain("// Add two numbers and return the structured sum")
|
expect(description).toContain("// Add two numbers and return the structured sum")
|
||||||
expect(description).not.toContain("$codemode")
|
expect(description).not.toContain("$codemode")
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,5 @@
|
||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import {
|
import { CODE_MODE_TOOL, CodeModeTool, Parameters, describeCatalog } from "@/tool/code-mode"
|
||||||
CODE_MODE_TOOL,
|
|
||||||
CodeModeTool,
|
|
||||||
Parameters,
|
|
||||||
describeCatalog,
|
|
||||||
} from "@/tool/code-mode"
|
|
||||||
import type { Tool as MCPToolDef } from "@modelcontextprotocol/sdk/types.js"
|
import type { Tool as MCPToolDef } from "@modelcontextprotocol/sdk/types.js"
|
||||||
import type { PermissionV1 } from "@opencode-ai/core/v1/permission"
|
import type { PermissionV1 } from "@opencode-ai/core/v1/permission"
|
||||||
import { Agent } from "@/agent/agent"
|
import { Agent } from "@/agent/agent"
|
||||||
|
|
@ -157,7 +152,9 @@ describe("code mode execute", () => {
|
||||||
expect(description).not.toContain("Browse one namespace")
|
expect(description).not.toContain("Browse one namespace")
|
||||||
expect(description).toContain("## Workflow")
|
expect(description).toContain("## Workflow")
|
||||||
expect(description).toContain("1. Pick a tool from the list under `## Available tools`")
|
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).toContain("Return only the fields you need")
|
||||||
expect(description).not.toContain("total_count")
|
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.zeta.only_tool(input: { topic: string }): Promise<unknown>")
|
||||||
expect(description).toContain("tools.$codemode.search(")
|
expect(description).toContain("tools.$codemode.search(")
|
||||||
expect(description).toContain("1. Find a tool (skip when it is already listed below)")
|
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).not.toContain("total_count")
|
||||||
expect(description).toContain("tools.alpha.op_0(")
|
expect(description).toContain("tools.alpha.op_0(")
|
||||||
expect(description).not.toContain("tools.alpha.op_99(")
|
expect(description).not.toContain("tools.alpha.op_99(")
|
||||||
|
|
@ -240,7 +239,10 @@ describe("code mode execute", () => {
|
||||||
linear_search: mcpTool("search", () => ""),
|
linear_search: mcpTool("search", () => ""),
|
||||||
})
|
})
|
||||||
const output = await Effect.runPromise(
|
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 })
|
expect(JSON.parse(output.output)).toEqual({ namespaces: ["github", "linear"], count: 2 })
|
||||||
})
|
})
|
||||||
|
|
@ -547,7 +549,12 @@ describe("code mode execute", () => {
|
||||||
const tool = await build({
|
const tool = await build({
|
||||||
docs_find: mcpTool("find", () => ({
|
docs_find: mcpTool("find", () => ({
|
||||||
content: [
|
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" },
|
{ type: "resource_link", uri: "file:///tmp/notes.md", name: "notes.md" },
|
||||||
],
|
],
|
||||||
})),
|
})),
|
||||||
|
|
@ -562,9 +569,7 @@ describe("code mode execute", () => {
|
||||||
const tool = await build({
|
const tool = await build({
|
||||||
shot_take: mcpTool("take", () => ({ content: [{ type: "image", data: "PNGDATA", mimeType: "image/png" }] })),
|
shot_take: mcpTool("take", () => ({ content: [{ type: "image", data: "PNGDATA", mimeType: "image/png" }] })),
|
||||||
})
|
})
|
||||||
const out = await Effect.runPromise(
|
const out = await Effect.runPromise(tool.execute({ code: "await tools.shot.take({}); return 'captured'" }, ctx))
|
||||||
tool.execute({ code: "await tools.shot.take({}); return 'captured'" }, ctx),
|
|
||||||
)
|
|
||||||
expect(out.output).toBe("captured")
|
expect(out.output).toBe("captured")
|
||||||
expect(out.attachments).toHaveLength(1)
|
expect(out.attachments).toHaveLength(1)
|
||||||
})
|
})
|
||||||
|
|
@ -680,9 +685,7 @@ describe("code mode permission visibility", () => {
|
||||||
expect(denied.output).not.toContain("permission")
|
expect(denied.output).not.toContain("permission")
|
||||||
expect(called).toEqual([])
|
expect(called).toEqual([])
|
||||||
|
|
||||||
const allowed = await Effect.runPromise(
|
const allowed = await Effect.runPromise(tool.execute({ code: "return await tools.github.list_issues({})" }, ctx))
|
||||||
tool.execute({ code: "return await tools.github.list_issues({})" }, ctx),
|
|
||||||
)
|
|
||||||
expect(allowed.metadata.error).toBeUndefined()
|
expect(allowed.metadata.error).toBeUndefined()
|
||||||
expect(allowed.output).toBe("ok")
|
expect(allowed.output).toBe("ok")
|
||||||
})
|
})
|
||||||
|
|
@ -695,9 +698,7 @@ describe("code mode permission visibility", () => {
|
||||||
["github"],
|
["github"],
|
||||||
[askRule("github_list_issues")],
|
[askRule("github_list_issues")],
|
||||||
)
|
)
|
||||||
const out = await Effect.runPromise(
|
const out = await Effect.runPromise(tool.execute({ code: "return await tools.github.list_issues({})" }, askCtx))
|
||||||
tool.execute({ code: "return await tools.github.list_issues({})" }, askCtx),
|
|
||||||
)
|
|
||||||
expect(out.output).toBe("ok")
|
expect(out.output).toBe("ok")
|
||||||
expect(asked).toEqual(["github_list_issues"])
|
expect(asked).toEqual(["github_list_issues"])
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue