Files
archie/ui/test/webmcp.test.ts
T
sam ea6385879f fix(ui): stop calling operations the binary does not serve (#2121)
The dashboard is embedded in the single binary, which serves api/openapi.yaml.
It was still calling the old services' routes, so pages that read them answered
with a not-found: the task board, its activity feed and setup panel, logs,
alerts, audit and its export, bindings, schedules, channels, repositories,
skills, curators, the control-plane settings pages, identities and org agents,
the org switcher, secret-reference checks, task metadata, and the audit, usage,
summary and version reads.

Each of those surfaces is removed, and a test compares every /api path in the
dashboard's source with api/openapi.yaml so the next one fails the gate
instead of the browser. Settings that the binary does serve (model providers,
instructions, policies, members) keep their pages.
2026-11-27 19:03:02 +11:00

148 lines
4.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
const { registerWebMcpTools, createWebMcpRegistrar } =
await import("../src/lib/webmcp.ts");
const { archieWebMcpTools } = await import("../src/lib/webmcp-tools.ts");
interface FakeRegistered {
name: string;
description: string;
inputSchema: unknown;
annotations: Record<string, unknown> | undefined;
signal: AbortSignal | undefined;
execute: (input: Record<string, unknown>) => unknown;
}
function installModelContext(): { registered: FakeRegistered[] } {
const registered: FakeRegistered[] = [];
Object.defineProperty(globalThis, "document", {
configurable: true,
value: {
modelContext: {
registerTool: async (
tool: Omit<FakeRegistered, "signal">,
options?: { signal?: AbortSignal },
) => {
registered.push({ ...tool, signal: options?.signal });
},
},
},
});
return { registered };
}
function installNoModelContext(): void {
Object.defineProperty(globalThis, "document", {
configurable: true,
value: {},
});
}
function fakeClient(): Parameters<typeof archieWebMcpTools>[0] {
const reply = (method: string, args: unknown[]) => ({ ok: true, method, args });
return {
health: async () => reply("health", []),
captures: async (limit?: number) => reply("captures", [limit]),
};
}
test("registration no-ops without document.modelContext instead of throwing", async () => {
installNoModelContext();
const registration = await registerWebMcpTools(
archieWebMcpTools(fakeClient()),
);
assert.equal(registration.registered, false);
assert.doesNotThrow(() => registration.dispose());
});
test("registration passes each tool's schema and annotations, and disposes via the signal", async () => {
const { registered } = installModelContext();
const tools = archieWebMcpTools(fakeClient());
const registration = await registerWebMcpTools(tools);
assert.equal(registration.registered, true);
assert.deepEqual(
registered.map((tool) => tool.name),
tools.map((tool) => tool.name),
);
for (const tool of registered) {
assert.ok(tool.description.length > 0, `${tool.name} has no description`);
assert.equal(typeof tool.inputSchema, "object");
assert.ok(
tool.signal instanceof AbortSignal,
`${tool.name} has no abort signal`,
);
assert.equal(tool.signal.aborted, false);
}
registration.dispose();
for (const tool of registered) {
assert.equal(
tool.signal?.aborted,
true,
`${tool.name} was not unregistered`,
);
}
});
test("every tool is read-only", () => {
const annotations = new Map(
archieWebMcpTools(fakeClient()).map((tool) => [
tool.name,
tool.annotations,
]),
);
for (const name of ["recent_events", "daemon_health"]) {
assert.equal(
annotations.get(name)?.readOnlyHint,
true,
`${name} should be read-only`,
);
assert.notEqual(
annotations.get(name)?.consequentialHint,
true,
`${name} must not be consequential`,
);
}
});
test("tools returning agent, operator or inbound content carry untrustedContentHint", () => {
const annotations = new Map(
archieWebMcpTools(fakeClient()).map((tool) => [
tool.name,
tool.annotations,
]),
);
for (const name of ["recent_events"]) {
assert.equal(
annotations.get(name)?.untrustedContentHint,
true,
`${name} returns untrusted content`,
);
}
assert.equal(annotations.get("daemon_health")?.untrustedContentHint, false);
});
test("re-registering replaces the previous registration", async () => {
const { registered } = installModelContext();
const register = createWebMcpRegistrar(
archieWebMcpTools(fakeClient()),
);
const count = archieWebMcpTools(fakeClient()).length;
const first = await register();
const second = await register();
assert.notEqual(first, second);
assert.equal(registered.length, count * 2);
for (const tool of registered.slice(0, count)) {
assert.equal(
tool.signal?.aborted,
true,
"the first registration was left live",
);
}
});