Files
next-tjwater-agent/tests/frontendAction/callIdPlugin.test.ts
T
jiang 6a49d2209e feat(agent): unify MCP tools and adopt Responses delivery
Move project and host queries into native MCP with host-owned OAuth/context,
while retaining memory, skills, actions and publication plugins. Add nearby-model
queries and explicit chat/task/learning model defaults.

Adopt Responses HTTP/SSE and native steer/queue inbox delivery, preserving scoped
session ownership, pending input edits and investigation communication.

Disable local-provider discovery: Server /health allowed native vLLM to probe
/v1/models on port 8000. A native before/after regression prevents recurrence.

Validation: 170 focused Bun tests; service/plugin typechecks; native discovery,
provider-discovery and input-inbox smoke checks; no paid model inference.
2026-10-19 18:46:58 +08:00

40 lines
2.7 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import plugin from "../../.opencode/plugins/tjwater-tools.js";
describe("OpenCode 2 business tool registration", () => {
it("registers business tools for direct dispatch, forwards the native call ID and validates inputs", async () => {
const tools = new Map<string, any>();
const storage = new Map<string, unknown>();
let rpcList: (() => Promise<unknown>) | undefined;
let readTodos: ((input: { session_id: string }) => Promise<unknown>) | undefined;
await plugin.setup({
tool: { transform: async (fn: (editor: unknown) => void) => fn({ list: () => Array.from(tools, ([id, tool]) => ({ ...tool, id })), add: (tool: any) => tools.set(tool.name, tool), remove: (name: string) => tools.delete(name), update: () => {} }), list: async () => Array.from(tools, ([id, tool]) => ({ ...tool, id })) },
mcp: { transform: async (fn: (editor: unknown) => void) => fn({ list: () => [] }), list: async () => ({ data: [] }) },
shell: { hook: async () => {} },
permission: { hook: async () => {} },
session: { hook: async () => {} },
rpc: { register: async (_definition: unknown, handlers: { list: () => Promise<unknown>; read_todos: (input: { session_id: string }) => Promise<unknown> }) => { rpcList = handlers.list; readTodos = handlers.read_todos; } },
storage: { set: async (key: string, value: unknown) => storage.set(key, value), get: async (key: string) => storage.get(key) },
} as never);
expect(tools.get("render_scada_analysis").options).toEqual({ codemode: false, permission: "render_scada_analysis" });
for (const name of ["publish_task_progress", "publish_task_presentation"]) {
expect(tools.get(name).options).toEqual({ codemode: false, permission: name });
}
const render = tools.get("render_scada_analysis");
await expect(render.execute({ reason: "test", items: [{ device_id: "x", level: "wrong" }] }, { sessionID: "s", id: "call-native" })).rejects.toThrow();
const todo = tools.get("todowrite");
const todos = [{ content: "check", status: "pending" }];
await todo.execute({ todos }, { sessionID: "s" });
expect(tools.has("todoread")).toBeFalse();
expect(await readTodos!({ session_id: "s" })).toEqual(todos);
expect(await readTodos!({ session_id: "another" })).toEqual([]);
const discovery = await rpcList!();
expect(JSON.parse(JSON.stringify(discovery))).toEqual(discovery);
});
it("exports a single native plugin entrypoint", async () => {
const module = await import("../../.opencode/plugins/tjwater-tools.js");
expect(Object.keys(module)).toEqual(["default"]);
expect(module.default.id).toBe("tjwater.tools");
});
});