From 2bfa7179ccc5415b6589930a4662f5053c071ee5 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Mon, 16 Nov 2026 05:16:28 -0600 Subject: [PATCH] fix(mcpx): resync dogfood plugin copy with pkgs/mcpx/plugin The main mcpx 'basic: test' job (e.g. run 43833553567, head 81d10205) fails its sync guard: .opencode/plugin had drifted from the canonical sources under pkgs/mcpx/plugin. Copy the canonical files: - pkgs/mcpx/plugin/opencode/mcpx/ -> .opencode/plugin/mcpx/ - pkgs/mcpx/plugin/core/ -> .opencode/plugin/core/ - pkgs/mcpx/plugin/opencode/mcpx-session.ts -> .opencode/plugin/mcpx-session.ts The drift was functional, not cosmetic: core/ was missing options.ts and timing.ts (inlining duplicate Options/truthy helpers), and ops.gen.ts was missing the apis_add/apis_remove and plugin_session_* operations. Verified in the worktree: all three sync diffs are empty, and `bun test plugin/opencode/mcpx/ plugin/core/` from pkgs/mcpx is green (68 pass, 5 skip). The gofmt half of the same failing run is already clean on current main, and the docs/environment.md half is owned by PR #10571. --- .opencode/plugin/core/daemon.test.ts | 8 +- .opencode/plugin/core/daemon.ts | 35 ++- .opencode/plugin/core/ops.gen.ts | 102 +++++++ .opencode/plugin/core/ops.test.ts | 386 +++++++++++++------------- .opencode/plugin/core/options.test.ts | 63 +++++ .opencode/plugin/core/options.ts | 149 ++++++++++ .opencode/plugin/core/timing.test.ts | 29 ++ .opencode/plugin/core/timing.ts | 44 +++ .opencode/plugin/mcpx-session.ts | 36 +-- .opencode/plugin/mcpx/biome.json | 4 +- .opencode/plugin/mcpx/ceiling.test.ts | 28 +- 11 files changed, 632 insertions(+), 252 deletions(-) create mode 100644 .opencode/plugin/core/options.test.ts create mode 100644 .opencode/plugin/core/options.ts create mode 100644 .opencode/plugin/core/timing.test.ts create mode 100644 .opencode/plugin/core/timing.ts diff --git a/.opencode/plugin/core/daemon.test.ts b/.opencode/plugin/core/daemon.test.ts index fa867510d7..426ccb7432 100644 --- a/.opencode/plugin/core/daemon.test.ts +++ b/.opencode/plugin/core/daemon.test.ts @@ -87,13 +87,17 @@ const serveFake = (socket: string, opts: FakeOptions = {}): Fake => { status: "ok", version: opts.version ?? "test", pid: 1, - ...(opts.missingOperationFingerprint ? {} : { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }), + ...(opts.missingOperationFingerprint + ? {} + : { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }), }); } if (url.pathname === "/v1/status") { return Response.json({ version: opts.version ?? "test", - ...(opts.missingOperationFingerprint ? {} : { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }), + ...(opts.missingOperationFingerprint + ? {} + : { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }), pid: 1, socket, config: opts.config, diff --git a/.opencode/plugin/core/daemon.ts b/.opencode/plugin/core/daemon.ts index f160e3c705..e00fa2b2be 100644 --- a/.opencode/plugin/core/daemon.ts +++ b/.opencode/plugin/core/daemon.ts @@ -92,7 +92,16 @@ export const TUNING = { */ export const goDurationMs = (v: string | undefined): number | undefined => { if (!v) return undefined; - const unit: Record = { ns: 1e-6, us: 1e-3, µs: 1e-3, μs: 1e-3, ms: 1, s: 1000, m: 60_000, h: 3_600_000 }; + const unit: Record = { + ns: 1e-6, + us: 1e-3, + µs: 1e-3, + μs: 1e-3, + ms: 1, + s: 1000, + m: 60_000, + h: 3_600_000, + }; // Go's number grammar is digits[.digits*] or .digits, so ".5s" and // "1.s" are whole components (#3490); Go also accepts both mu // codepoints for microseconds -- U+00B5 (micro sign) and U+03BC @@ -428,13 +437,19 @@ export class DaemonClient { private async verifyOperationCompatibility(): Promise { const health = await this.health(); if (!health) { - throw new Error("mcpx: cannot verify /v1 operation compatibility because the daemon health endpoint did not answer; update or restart the mcpx daemon and plugin"); + throw new Error( + "mcpx: cannot verify /v1 operation compatibility because the daemon health endpoint did not answer; update or restart the mcpx daemon and plugin", + ); } if (typeof health.operationFingerprint !== "string" || health.operationFingerprint.length === 0) { - throw new Error("mcpx: cannot verify /v1 operation compatibility because the daemon does not publish an operation fingerprint; update and restart the mcpx daemon before using generated plugin operations"); + throw new Error( + "mcpx: cannot verify /v1 operation compatibility because the daemon does not publish an operation fingerprint; update and restart the mcpx daemon before using generated plugin operations", + ); } if (health.operationFingerprint !== OPERATION_FINGERPRINT) { - throw new Error(`mcpx: /v1 operation table mismatch (plugin ${OPERATION_FINGERPRINT}, daemon ${health.operationFingerprint}); update the mcpx plugin and daemon from matching versions`); + throw new Error( + `mcpx: /v1 operation table mismatch (plugin ${OPERATION_FINGERPRINT}, daemon ${health.operationFingerprint}); update the mcpx plugin and daemon from matching versions`, + ); } } @@ -503,7 +518,17 @@ export class DaemonClient { */ async health( timeoutMs = TUNING.healthTimeoutMs, - ): Promise<{ status: string; version?: string; pid?: number; uptime?: string; endpoint?: string; operationFingerprint?: string } | undefined> { + ): Promise< + | { + status: string; + version?: string; + pid?: number; + uptime?: string; + endpoint?: string; + operationFingerprint?: string; + } + | undefined + > { try { return await this.get("/v1/health", timeoutMs); } catch { diff --git a/.opencode/plugin/core/ops.gen.ts b/.opencode/plugin/core/ops.gen.ts index afbad0365c..00c3b82dce 100644 --- a/.opencode/plugin/core/ops.gen.ts +++ b/.opencode/plugin/core/ops.gen.ts @@ -47,6 +47,31 @@ export const OPS: Record = { }, response: "json", }, + apis_add: { + method: "POST", + path: "/v1/apis", + params: { + name: { in: "body", required: true }, + spec: { in: "body", required: true }, + baseUrl: { in: "body" }, + include: { in: "body" }, + exclude: { in: "body" }, + methods: { in: "body" }, + includeDeprecated: { in: "body" }, + headers: { in: "body" }, + description: { in: "body" }, + replace: { in: "body" }, + }, + response: "json", + }, + apis_remove: { + method: "DELETE", + path: "/v1/apis/{name}", + params: { + name: { in: "path", required: true }, + }, + response: "json", + }, artifact_delete: { method: "DELETE", path: "/v1/artifacts/{id}", @@ -446,6 +471,38 @@ export const OPS: Record = { params: {}, response: "json", }, + plugin_session_close: { + method: "DELETE", + path: "/v1/plugin-sessions/{id}", + params: { + id: { in: "path", required: true }, + }, + response: "json", + }, + plugin_session_get: { + method: "GET", + path: "/v1/plugin-sessions/{id}", + params: { + id: { in: "path", required: true }, + }, + response: "json", + }, + plugin_sessions_list: { + method: "GET", + path: "/v1/plugin-sessions", + params: {}, + response: "json", + }, + plugin_sessions_open: { + method: "POST", + path: "/v1/plugin-sessions", + params: { + plugin: { in: "body", required: true }, + capabilities: { in: "body" }, + hooks: { in: "body" }, + }, + response: "json", + }, preflight: { method: "POST", path: "/v1/preflight", @@ -931,6 +988,23 @@ export class DaemonOps { return this.invoke("adapters_remove", args, opts) as Promise } + /** + * Add an API declaration, live. `POST /v1/apis`. + * Privileged: it changes the daemon rather than reading it. + */ + apisAdd(args: { name: string; spec: string; baseUrl?: string; include?: unknown[]; exclude?: unknown[]; methods?: unknown[]; includeDeprecated?: boolean; headers?: Record; description?: string; replace?: boolean }, opts: CallOptions = {}): Promise { + return this.invoke("apis_add", args, opts) as Promise + } + + /** + * Remove an API declaration, live. `DELETE /v1/apis/{name}`. + * Privileged: it changes the daemon rather than reading it. + * Destructive: it cannot be undone, and other callers are affected. + */ + apisRemove(args: { name: string }, opts: CallOptions = {}): Promise { + return this.invoke("apis_remove", args, opts) as Promise + } + /** * Forget one artifact. `DELETE /v1/artifacts/{id}`. * Privileged: it changes the daemon rather than reading it. @@ -1231,6 +1305,34 @@ export class DaemonOps { return this.invoke("openapi", args, opts) as Promise } + /** + * End a plugin session, dropping everything it owns. `DELETE /v1/plugin-sessions/{id}`. + */ + pluginSessionClose(args: { id: string }, opts: CallOptions = {}): Promise { + return this.invoke("plugin_session_close", args, opts) as Promise + } + + /** + * One live plugin session. `GET /v1/plugin-sessions/{id}`. + */ + pluginSessionGet(args: { id: string }, opts: CallOptions = {}): Promise { + return this.invoke("plugin_session_get", args, opts) as Promise + } + + /** + * Live plugin sessions and what each one owns. `GET /v1/plugin-sessions`. + */ + pluginSessionsList(args: Record = {}, opts: CallOptions = {}): Promise { + return this.invoke("plugin_sessions_list", args, opts) as Promise + } + + /** + * Open a plugin session and be issued its id. `POST /v1/plugin-sessions`. + */ + pluginSessionsOpen(args: { plugin: string; capabilities?: unknown[]; hooks?: unknown[] }, opts: CallOptions = {}): Promise { + return this.invoke("plugin_sessions_open", args, opts) as Promise + } + /** * Check a script's servers are ready before running it. `POST /v1/preflight`. */ diff --git a/.opencode/plugin/core/ops.test.ts b/.opencode/plugin/core/ops.test.ts index 1b62a84c7c..c88cfcf14d 100644 --- a/.opencode/plugin/core/ops.test.ts +++ b/.opencode/plugin/core/ops.test.ts @@ -12,129 +12,129 @@ * anyone wrote for it while the daemon ignored its arguments. */ -import { afterEach, describe, expect, test } from "bun:test" -import { mkdtempSync, rmSync } from "node:fs" -import { tmpdir } from "node:os" -import { join } from "node:path" +import { afterEach, describe, expect, test } from "bun:test"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; -import { DaemonClient, renderExec } from "./daemon.ts" -import { buildRequest, OPERATION_FINGERPRINT, OpError, OPS } from "./ops.gen.ts" +import { DaemonClient, renderExec } from "./daemon.ts"; +import { buildRequest, OPERATION_FINGERPRINT, OpError, OPS } from "./ops.gen.ts"; -type Seen = { method: string; path: string; type: string | null; body: Uint8Array } +type Seen = { method: string; path: string; type: string | null; body: Uint8Array }; -const cleanup: Array<() => void> = [] +const cleanup: Array<() => void> = []; afterEach(() => { - while (cleanup.length) cleanup.pop()?.() -}) + while (cleanup.length) cleanup.pop()?.(); +}); /** A daemon that records every request and answers with `reply`. */ const fake = (reply: (s: Seen) => Response = () => Response.json({ ok: true })) => { - const dir = mkdtempSync(join(tmpdir(), "mcpxo-")) - const socket = join(dir, "d.sock") - const seen: Seen[] = [] + const dir = mkdtempSync(join(tmpdir(), "mcpxo-")); + const socket = join(dir, "d.sock"); + const seen: Seen[] = []; const server = Bun.serve({ unix: socket, async fetch(req) { - const url = new URL(req.url) + const url = new URL(req.url); // Every generated operation first verifies the daemon's operation-table // fingerprint. Answer that handshake without recording it, so `seen` // stays the list of operations the test is asserting about. if (url.pathname === "/v1/health") { - return Response.json({ status: "ok", operationFingerprint: OPERATION_FINGERPRINT }) + return Response.json({ status: "ok", operationFingerprint: OPERATION_FINGERPRINT }); } const s: Seen = { method: req.method, path: url.pathname + url.search, type: req.headers.get("content-type"), body: new Uint8Array(await req.arrayBuffer()), - } - seen.push(s) - return reply(s) + }; + seen.push(s); + return reply(s); }, - }) + }); cleanup.push(() => { - server.stop(true) - rmSync(dir, { recursive: true, force: true }) - }) - return { client: new DaemonClient({ kind: "socket", path: socket }), seen } -} + server.stop(true); + rmSync(dir, { recursive: true, force: true }); + }); + return { client: new DaemonClient({ kind: "socket", path: socket }), seen }; +}; -const text = (b: Uint8Array) => new TextDecoder().decode(b) +const text = (b: Uint8Array) => new TextDecoder().decode(b); describe("buildRequest", () => { test("escapes path parameters rather than letting them split the path", () => { - const { path } = buildRequest("task_get", { id: "a b/c" }) - expect(path).toBe("/v1/tasks/a%20b%2Fc") - }) + const { path } = buildRequest("task_get", { id: "a b/c" }); + expect(path).toBe("/v1/tasks/a%20b%2Fc"); + }); test("sends query parameters as scalars, and a switch as 1 or 0", () => { - const { path, init } = buildRequest("types", { ns: "fs,git", instructions: "0" }) - expect(path).toBe("/v1/types?ns=fs%2Cgit&instructions=0") - expect(init.body).toBeUndefined() - expect(buildRequest("task_result", { id: "t", waitMs: 5 }).path).toBe("/v1/tasks/t/result?waitMs=5") - }) + const { path, init } = buildRequest("types", { ns: "fs,git", instructions: "0" }); + expect(path).toBe("/v1/types?ns=fs%2Cgit&instructions=0"); + expect(init.body).toBeUndefined(); + expect(buildRequest("task_result", { id: "t", waitMs: 5 }).path).toBe("/v1/tasks/t/result?waitMs=5"); + }); test("a bare-document route receives the document, not an object around it", () => { - const { init } = buildRequest("tool_invoke", { tool: "mcpx_health", arguments: { a: 1 } }) - expect(JSON.parse(init.body as string)).toEqual({ a: 1 }) - const rec = buildRequest("log_record", { record: { msg: "hi" }, level: "warn" }) - expect(rec.path).toBe("/v1/log?level=warn") - expect(JSON.parse(rec.init.body as string)).toEqual({ msg: "hi" }) - }) + const { init } = buildRequest("tool_invoke", { tool: "mcpx_health", arguments: { a: 1 } }); + expect(JSON.parse(init.body as string)).toEqual({ a: 1 }); + const rec = buildRequest("log_record", { record: { msg: "hi" }, level: "warn" }); + expect(rec.path).toBe("/v1/log?level=warn"); + expect(JSON.parse(rec.init.body as string)).toEqual({ msg: "hi" }); + }); test("a POST with nothing to send still sends an object", () => { - const { init } = buildRequest("refresh") - expect(init.method).toBe("POST") - expect(init.body).toBe("{}") - }) + const { init } = buildRequest("refresh"); + expect(init.method).toBe("POST"); + expect(init.body).toBe("{}"); + }); test("refuses an argument the route does not take, and a missing required one", () => { - expect(() => buildRequest("task_get", { id: "x", nope: 1 })).toThrow("takes no argument nope") - expect(() => buildRequest("task_get", {})).toThrow("id is required") - }) + expect(() => buildRequest("task_get", { id: "x", nope: 1 })).toThrow("takes no argument nope"); + expect(() => buildRequest("task_get", {})).toThrow("id is required"); + }); test("declares every operation the table has", () => { // A spot check that the table is the whole table and not a subset. for (const name of ["health", "resolve", "protocol", "artifact_put", "ask_begin", "events", "settings_set"]) { - expect(OPS[name]).toBeDefined() + expect(OPS[name]).toBeDefined(); } - }) -}) + }); +}); describe("DaemonOps against a fake daemon", () => { test("an artifact is sent as its bytes", async () => { - const { client, seen } = fake(() => Response.json({ id: "art-1" })) - const bytes = new Uint8Array([0, 255, 1, 254, 10, 13]) - await client.ops.artifactPut({ name: "b.bin", content: bytes }) - expect(seen[0].method).toBe("POST") - expect(seen[0].path).toBe("/v1/artifacts?name=b.bin") - expect(seen[0].type).toBe("application/octet-stream") - expect([...seen[0].body]).toEqual([...bytes]) - }) + const { client, seen } = fake(() => Response.json({ id: "art-1" })); + const bytes = new Uint8Array([0, 255, 1, 254, 10, 13]); + await client.ops.artifactPut({ name: "b.bin", content: bytes }); + expect(seen[0].method).toBe("POST"); + expect(seen[0].path).toBe("/v1/artifacts?name=b.bin"); + expect(seen[0].type).toBe("application/octet-stream"); + expect([...seen[0].body]).toEqual([...bytes]); + }); test("a text or byte route hands back the response to read as either", async () => { - const { client } = fake(() => new Response("declare const x: 1\n")) - const res = await client.ops.types({ ns: "fs" }) - expect(await res.text()).toBe("declare const x: 1\n") - }) + const { client } = fake(() => new Response("declare const x: 1\n")); + const res = await client.ops.types({ ns: "fs" }); + expect(await res.text()).toBe("declare const x: 1\n"); + }); test("a refusal throws with the daemon's own message", async () => { - const { client } = fake(() => Response.json({ error: "no task t; it may have expired" }, { status: 404 })) - const err = await client.ops.taskGet({ id: "t" }).catch((e) => e) - expect(err).toBeInstanceOf(OpError) - expect((err as OpError).status).toBe(404) - expect(String(err)).toContain("no task t; it may have expired") - }) + const { client } = fake(() => Response.json({ error: "no task t; it may have expired" }, { status: 404 })); + const err = await client.ops.taskGet({ id: "t" }).catch((e) => e); + expect(err).toBeInstanceOf(OpError); + expect((err as OpError).status).toBe(404); + expect(String(err)).toContain("no task t; it may have expired"); + }); test("call() sends the arguments under the key /v1/call reads", async () => { // It sent `arguments` and `sessionId`; the route reads `args` and // `session`, so every tool it called got nothing. - const { client, seen } = fake(() => Response.json({ result: "ok" })) - await client.call("demo", "echo", { message: "hi" }, "s-1") - const body = JSON.parse(text(seen[0].body)) - expect(body).toEqual({ server: "demo", tool: "echo", args: { message: "hi" }, session: "s-1" }) - }) -}) + const { client, seen } = fake(() => Response.json({ result: "ok" })); + await client.call("demo", "echo", { message: "hi" }, "s-1"); + const body = JSON.parse(text(seen[0].body)); + expect(body).toEqual({ server: "demo", tool: "echo", args: { message: "hi" }, session: "s-1" }); + }); +}); describe("DaemonClient.exec", () => { // The daemon's own answer: a bare execsvc.Result, no { result } envelope and @@ -149,102 +149,102 @@ describe("DaemonClient.exec", () => { artifacts: [], exitCode: 0, durationMs: 12, - } + }; test("sends the session under options.session, where the route reads it", async () => { - const { client, seen } = fake(() => Response.json(result)) - await client.exec("console.log(2)", "ses_abc") - expect(seen[0].method).toBe("POST") - expect(seen[0].path).toBe("/v1/exec") + const { client, seen } = fake(() => Response.json(result)); + await client.exec("console.log(2)", "ses_abc"); + expect(seen[0].method).toBe("POST"); + expect(seen[0].path).toBe("/v1/exec"); expect(JSON.parse(text(seen[0].body))).toEqual({ source: "console.log(2)", options: { output: "structured", session: "ses_abc" }, - }) - }) + }); + }); test("names no session when the caller has none", async () => { - const { client, seen } = fake(() => Response.json(result)) - await client.exec("console.log(2)") + const { client, seen } = fake(() => Response.json(result)); + await client.exec("console.log(2)"); expect(JSON.parse(text(seen[0].body))).toEqual({ source: "console.log(2)", options: { output: "structured" }, - }) - }) + }); + }); test("answers with the Result itself, not an envelope", async () => { - const { client } = fake(() => Response.json(result)) - const res = await client.exec("console.log(2)", "s-1") - expect(res?.runId).toBe("r-1") - expect(res?.stdout).toBe("two\n") - expect(res?.exitCode).toBe(0) - }) + const { client } = fake(() => Response.json(result)); + const res = await client.exec("console.log(2)", "s-1"); + expect(res?.runId).toBe("r-1"); + expect(res?.stdout).toBe("two\n"); + expect(res?.exitCode).toBe(0); + }); test("two execs in one session carry the same session, and another session differs", async () => { // The session is what the daemon leases a pooled instance by, so a // plugin that drops it routes every script to whichever instance is free. - const seenSessions: Array = [] + const seenSessions: Array = []; const { client } = fake((s) => { - const body = JSON.parse(text(s.body)) as { options?: { session?: string } } - seenSessions.push(body.options?.session) - return Response.json({ ...result, runId: `run-${seenSessions.length}` }) - }) - const one = await client.exec("first", "ses_one") - const two = await client.exec("second", "ses_one") - const other = await client.exec("third", "ses_two") - expect(seenSessions).toEqual(["ses_one", "ses_one", "ses_two"]) - expect([one?.runId, two?.runId, other?.runId]).toEqual(["run-1", "run-2", "run-3"]) - }) + const body = JSON.parse(text(s.body)) as { options?: { session?: string } }; + seenSessions.push(body.options?.session); + return Response.json({ ...result, runId: `run-${seenSessions.length}` }); + }); + const one = await client.exec("first", "ses_one"); + const two = await client.exec("second", "ses_one"); + const other = await client.exec("third", "ses_two"); + expect(seenSessions).toEqual(["ses_one", "ses_one", "ses_two"]); + expect([one?.runId, two?.runId, other?.runId]).toEqual(["run-1", "run-2", "run-3"]); + }); test("a daemon with no /v1/exec is a version difference, not a failure", async () => { - const { client } = fake(() => new Response("not found", { status: 404 })) - expect(await client.exec("console.log(1)", "s-1")).toBeUndefined() - }) + const { client } = fake(() => new Response("not found", { status: 404 })); + expect(await client.exec("console.log(1)", "s-1")).toBeUndefined(); + }); test("a real refusal still throws", async () => { - const { client } = fake(() => Response.json({ error: "a server is waiting on a secret" }, { status: 409 })) - const err = await client.exec("console.log(1)", "s-1").catch((e) => e) - expect(err).toBeInstanceOf(OpError) - expect((err as OpError).status).toBe(409) - expect(String(err)).toContain("waiting on a secret") - }) + const { client } = fake(() => Response.json({ error: "a server is waiting on a secret" }, { status: 409 })); + const err = await client.exec("console.log(1)", "s-1").catch((e) => e); + expect(err).toBeInstanceOf(OpError); + expect((err as OpError).status).toBe(409); + expect(String(err)).toContain("waiting on a secret"); + }); test("an aborted caller signal cancels the in-flight exec (PLG-38, #1940)", async () => { - const dir = mkdtempSync(join(tmpdir(), "mcpxa-")) - const socket = join(dir, "d.sock") - let serverSawAbort = false + const dir = mkdtempSync(join(tmpdir(), "mcpxa-")); + const socket = join(dir, "d.sock"); + let serverSawAbort = false; const server = Bun.serve({ unix: socket, async fetch(req) { - const url = new URL(req.url) + const url = new URL(req.url); if (url.pathname === "/v1/health") { - return Response.json({ status: "ok", operationFingerprint: OPERATION_FINGERPRINT }) + return Response.json({ status: "ok", operationFingerprint: OPERATION_FINGERPRINT }); } await new Promise((resolve) => { - const t = setTimeout(resolve, 8000) + const t = setTimeout(resolve, 8000); req.signal.addEventListener("abort", () => { - serverSawAbort = true - clearTimeout(t) - resolve() - }) - }) - return Response.json(result) + serverSawAbort = true; + clearTimeout(t); + resolve(); + }); + }); + return Response.json(result); }, - }) + }); cleanup.push(() => { - server.stop(true) - rmSync(dir, { recursive: true, force: true }) - }) - const client = new DaemonClient({ kind: "socket", path: socket }) - const controller = new AbortController() - const started = Date.now() - const pending = client.exec("console.log(1)", "s-1", controller.signal) - setTimeout(() => controller.abort(), 150) - const err = await pending.catch((e) => e) - expect(err).toBeInstanceOf(Error) - expect(Date.now() - started).toBeLessThan(5000) - expect(serverSawAbort).toBe(true) - }) -}) + server.stop(true); + rmSync(dir, { recursive: true, force: true }); + }); + const client = new DaemonClient({ kind: "socket", path: socket }); + const controller = new AbortController(); + const started = Date.now(); + const pending = client.exec("console.log(1)", "s-1", controller.signal); + setTimeout(() => controller.abort(), 150); + const err = await pending.catch((e) => e); + expect(err).toBeInstanceOf(Error); + expect(Date.now() - started).toBeLessThan(5000); + expect(serverSawAbort).toBe(true); + }); +}); describe("renderExec", () => { test("prints the script's value, its emits, and its stdout", () => { @@ -253,94 +253,94 @@ describe("renderExec", () => { emits: [{ progress: 1 }], stdout: "hello", exitCode: 0, - }) - expect(out).toContain('"ok": true') - expect(out).toContain('"progress":1') - expect(out).toContain("hello") - expect(out.indexOf("hello")).toBeGreaterThan(out.indexOf('"ok"')) - }) + }); + expect(out).toContain('"ok": true'); + expect(out).toContain('"progress":1'); + expect(out).toContain("hello"); + expect(out.indexOf("hello")).toBeGreaterThan(out.indexOf('"ok"')); + }); test("a string result is the text, not a quoted JSON string", () => { - expect(renderExec({ result: "done", exitCode: 0 })).toBe("done") - }) + expect(renderExec({ result: "done", exitCode: 0 })).toBe("done"); + }); test("the invented output field is never rendered", () => { // No execsvc.Result has ever had `output`; reading it was the defect. - const out = renderExec({ result: "kept", output: "dropped" } as never) - expect(out).toBe("kept") - expect(out).not.toContain("dropped") - }) + const out = renderExec({ result: "kept", output: "dropped" } as never); + expect(out).toBe("kept"); + expect(out).not.toContain("dropped"); + }); test("says so rather than printing nothing", () => { - expect(renderExec({ exitCode: 0 })).toBe("(no output)") - }) + expect(renderExec({ exitCode: 0 })).toBe("(no output)"); + }); test("a failure is visible even when the script also printed", () => { - const out = renderExec({ error: "boom", stdout: "half way", exitCode: 1 }) - expect(out).toContain("boom") - expect(out).toContain("half way") - expect(out).toContain("exit 1") - }) -}) + const out = renderExec({ error: "boom", stdout: "half way", exitCode: 1 }); + expect(out).toContain("boom"); + expect(out).toContain("half way"); + expect(out).toContain("exit 1"); + }); +}); // The live half. The Go test TestThePluginSuiteRunsAgainstARealDaemon starts // a daemon with one fake server and passes its socket. -const live = process.env.OPS_LIVE_SOCKET +const live = process.env.OPS_LIVE_SOCKET; describe.skipIf(!live)("DaemonOps against a real daemon", () => { - const client = () => new DaemonClient({ kind: "socket", path: live as string }) + const client = () => new DaemonClient({ kind: "socket", path: live as string }); test("every read that needs no arguments answers", async () => { - const c = client() + const c = client(); for (const [name, spec] of Object.entries(OPS)) { - const needs = Object.values(spec.params).some((p) => p.required) - if (spec.method !== "GET" || needs || spec.response === "response") continue - const out = await c.ops.invoke(name) - expect(out).toBeDefined() + const needs = Object.values(spec.params).some((p) => p.required); + if (spec.method !== "GET" || needs || spec.response === "response") continue; + const out = await c.ops.invoke(name); + expect(out).toBeDefined(); } - }) + }); test("call() reaches the tool with its arguments", async () => { - const res = await client().call("demo", "echo", { message: "through the plugin" }) - expect(JSON.stringify(res)).toContain("through the plugin") - }) + const res = await client().call("demo", "echo", { message: "through the plugin" }); + expect(JSON.stringify(res)).toContain("through the plugin"); + }); test("exec carries a session, and what one exec did is there for the next", async () => { // #1910 defects 2+3: the plugin sent no session, so every script ran on // whichever pooled instance was free, and it read an `output` field the // daemon does not send, so the answer was the whole Result document. - const c = client() - const session = "s-exec-round-trip" - const marker = `mark-${process.pid}-${Date.now()}` + const c = client(); + const session = "s-exec-round-trip"; + const marker = `mark-${process.pid}-${Date.now()}`; const first = await c.exec( `const r = await demo.open({ value: ${JSON.stringify(marker)} }); console.log(JSON.stringify(r))`, session, - ) - expect(first).toBeDefined() - expect(first?.runId).toBeTruthy() - expect(renderExec(first as NonNullable)).toContain("opened") + ); + expect(first).toBeDefined(); + expect(first?.runId).toBeTruthy(); + expect(renderExec(first as NonNullable)).toContain("opened"); - const second = await c.exec("console.log(JSON.stringify(await demo.state({})))", session) - expect(renderExec(second as NonNullable)).toContain(marker) + const second = await c.exec("console.log(JSON.stringify(await demo.state({})))", session); + expect(renderExec(second as NonNullable)).toContain(marker); // Two script runs, each paying a runtime start; bun's 5s default covers // one on a warm machine and nothing more. - }, 30_000) + }, 30_000); test("an artifact round-trips byte for byte", async () => { - const c = client() - const bytes = new Uint8Array(512).map((_, i) => (i * 37) % 256) - const put = (await c.ops.artifactPut({ name: "p.bin", content: bytes })) as { id: string; size: number } - expect(put.size).toBe(bytes.length) - const got = new Uint8Array(await (await c.ops.artifactGet({ id: put.id })).arrayBuffer()) - expect([...got]).toEqual([...bytes]) - await c.ops.artifactDelete({ id: put.id }) - const gone = await c.ops.artifactGet({ id: put.id }).catch((e) => e) - expect(gone).toBeInstanceOf(OpError) - }) + const c = client(); + const bytes = new Uint8Array(512).map((_, i) => (i * 37) % 256); + const put = (await c.ops.artifactPut({ name: "p.bin", content: bytes })) as { id: string; size: number }; + expect(put.size).toBe(bytes.length); + const got = new Uint8Array(await (await c.ops.artifactGet({ id: put.id })).arrayBuffer()); + expect([...got]).toEqual([...bytes]); + await c.ops.artifactDelete({ id: put.id }); + const gone = await c.ops.artifactGet({ id: put.id }).catch((e) => e); + expect(gone).toBeInstanceOf(OpError); + }); test("resolve answers for the daemon's own directory", async () => { - const dir = process.env.OPS_LIVE_DIR as string - const res = (await client().ops.resolve({ dir })) as { running?: boolean } - expect(res.running).toBe(true) - }) -}) + const dir = process.env.OPS_LIVE_DIR as string; + const res = (await client().ops.resolve({ dir })) as { running?: boolean }; + expect(res.running).toBe(true); + }); +}); diff --git a/.opencode/plugin/core/options.test.ts b/.opencode/plugin/core/options.test.ts new file mode 100644 index 0000000000..3928de596e --- /dev/null +++ b/.opencode/plugin/core/options.test.ts @@ -0,0 +1,63 @@ +/** + * Core option resolution, against the v1 semantics the resolver + * documents (oracle: the resolveOptions contract in options.ts -- + * plugin option first, then the environment variable, then the + * caller's default; an explicit empty bin is a decision to forbid + * spawning, never an absence; an unrecognised truthy value is + * undefined, so the default applies). + * + * bun test plugin/core/options.test.ts + */ +import { describe, expect, test } from "bun:test"; +import { resolveOptions, truthy } from "./options.ts"; + +describe("truthy (oracle: v1 truthy parse)", () => { + test("recognised spellings parse, unrecognised is undefined", () => { + expect(truthy("1")).toBe(true); + expect(truthy("off")).toBe(false); + expect(truthy(true)).toBe(true); + expect(truthy("maybe")).toBeUndefined(); + expect(truthy("")).toBeUndefined(); + expect(truthy(undefined)).toBeUndefined(); + }); +}); + +describe("resolveOptions (oracle: option > env > default)", () => { + test("defaults land when nothing is set", () => { + const r = resolveOptions(undefined, {}); + expect(r.backend).toBe("auto"); + expect(r.remember).toBe("session"); + expect(r.annotate).toBe(true); + expect(r.tools).toBe(false); + expect(r.instructions).toBe(false); + expect(r.toolTiming).toBe(false); + expect(r.answerSampling).toBe(true); + expect(r.endpoint).toBeUndefined(); + expect(r.bin).toBeUndefined(); + }); + + test("env beats default, option beats env", () => { + const env = { MCPX_PLUGIN_BACKEND: "cli", MCPX_DAEMON_ENDPOINT: "unix:///tmp/x" }; + expect(resolveOptions(undefined, env).backend).toBe("cli"); + expect(resolveOptions({ backend: "v1" }, env).backend).toBe("v1"); + expect(resolveOptions(undefined, env).endpoint).toBe("unix:///tmp/x"); + }); + + test("an explicit empty bin forbids spawning and survives resolution", () => { + expect(resolveOptions({ bin: "" }, { MCPX_PLUGIN_BIN: "/usr/bin/mcpx" }).bin).toBe(""); + expect(resolveOptions(undefined, { MCPX_PLUGIN_BIN: "/usr/bin/mcpx" }).bin).toBe("/usr/bin/mcpx"); + }); + + test("binArgs strings split, arrays pass through", () => { + expect(resolveOptions({ binArgs: "--flag value" }, {}).binArgs).toEqual(["--flag", "value"]); + expect(resolveOptions({ binArgs: ["a"] }, {}).binArgs).toEqual(["a"]); + }); + + test("disabledTools parses arrays and separated strings", () => { + expect(resolveOptions({ disabledTools: ["mcpx_exec"] }, {}).disabledTools).toEqual(["mcpx_exec"]); + expect(resolveOptions(undefined, { MCPX_PLUGIN_DISABLED_TOOLS: "mcpx_exec, mcpx_search" }).disabledTools).toEqual([ + "mcpx_exec", + "mcpx_search", + ]); + }); +}); diff --git a/.opencode/plugin/core/options.ts b/.opencode/plugin/core/options.ts new file mode 100644 index 0000000000..30349cc9df --- /dev/null +++ b/.opencode/plugin/core/options.ts @@ -0,0 +1,149 @@ +/** + * Plugin options, harness-free core (#1861): the single home for the + * Options type, the v1-way resolver and its helpers, consumed by both + * OpenCode adapters. v2 resolves through resolveOptions below; v1 + * (mcpx-session.ts) imports the shared Options type and truthy parse + * and applies its own adapter defaults on top (full env by default, + * TUNING.bin / TUNING.missCooldownMs fallbacks, headless detection) -- + * those defaults are adapter decisions, not core semantics. + * + * Settings guard: TestThePluginReadsNoUndeclaredSetting scans plugin/**, + * so the v2 tree reads only names the registry or the script-env contract + * declares — the MCPX_PLUGIN_* names in internal/settings/plugin.go, plus + * MCPX_DAEMON_ENDPOINT / MCPX_ENDPOINT / MCPX_SOCKET from scriptenv.go, + * the same names v1 reads. The reads are + * property accesses (env.MCPX_PLUGIN_BIN and friends), never quoted + * literals: TestTheScriptEnvironmentIsWhatTheCodeSets treats a quoted + * MCPX_* name as a variable the plugin SETS into a child's environment, + * and these are reads, not sets. (An earlier draft listed the names in + * a quoted array and failed that test on all twelve.) + */ +import { goDurationMs, splitArgs } from "./daemon.ts"; + +export type Options = { + /** A daemon named outright. `unix:///path` or `http://host:port`. */ + endpoint?: string; + /** A socket named outright. */ + socket?: string; + /** The mcpx binary, or "" to forbid spawning one. */ + bin?: string; + /** Arguments to put before mcpx's own, as a vector or a string. */ + binArgs?: string[] | string; + /** Where the opt-in tools get their answers: auto, v1 or cli. */ + backend?: "auto" | "v1" | "cli"; + /** Default scope for a daemon choice made this session. */ + remember?: "session" | "until-gone" | "indefinite"; + /** How much to inject into shell environments. */ + env?: "minimal" | "standard" | "full"; + instructions?: boolean; + toolTiming?: boolean; + /** + * Answer mcpx sampling questions (broker sample rows routed to the + * agent) with ctx.generate.text. Default on when the host offers + * ctx.generate; false turns the watcher off. Plugin-option only -- + * no env name is declared for it in the settings registry, and the + * settings guard forbids reading undeclared MCPX_* names. + */ + answerSampling?: boolean; + tools?: boolean; + /** Offer mcpx_daemon_status and mcpx_daemon_select. Default: when unclear. */ + daemonTools?: boolean; + /** Report ambiguity on tool results. Default on. */ + annotate?: boolean; + /** Override the "is anyone looking at this" guess. */ + headless?: boolean; + /** + * Model-facing mcpx tool names (mcpx_exec, ...) hidden from every + * session this plugin serves (#5122): the user-facing writer for the + * per-session tool-filter policy — setup records it as each new + * session's policy in ctx.storage, unless that session already has + * a policy of its own. Env: MCPX_PLUGIN_DISABLED_TOOLS (comma- or + * space-separated). Names outside the mcpx_ namespace are dropped + * when the policy is read, so this can never hide a host tool. + */ + disabledTools?: string[]; +}; + +/** A tool-name list from an option array or a separated env string. */ +const nameList = (v: unknown): string[] | undefined => { + if (Array.isArray(v)) + return v + .map(String) + .map((x) => x.trim()) + .filter(Boolean); + if (typeof v === "string") + return v + .split(/[\s,]+/) + .map((x) => x.trim()) + .filter(Boolean); + return undefined; +}; + +const str = (v: unknown): string | undefined => (v === undefined || v === null || v === "" ? undefined : String(v)); + +/** + * The bin resolution only: nullish, the v1 way. An explicit "" is a + * decision — forbid spawning — not an absence: str() would collapse it + * to undefined and runBin would fall back to MCPX_PLUGIN_BIN or the + * default binary, spawning exactly what the user forbade. + */ +const binStr = (v: unknown): string | undefined => (v === undefined || v === null ? undefined : String(v)); + +/** The v1 truthy parse: an unrecognised value is undefined, not false. */ +export const truthy = (v: unknown): boolean | undefined => { + if (v === undefined || v === null || v === "") return undefined; + if (typeof v === "boolean") return v; + const s = String(v).toLowerCase(); + if (s === "1" || s === "true" || s === "yes" || s === "on") return true; + if (s === "0" || s === "false" || s === "no" || s === "off") return false; + return undefined; +}; + +/** + * Resolve raw options the v1 way — plugin option first, then the + * environment variable, then the caller's default — for the settings + * the v2 core needs. Unset fields stay undefined, except toolTiming, + * whose v1 default is false (opt-in): a resolved false is a decision, + * and index.ts registers no timing hook for it. + * + * `discoveryRetryMs` is not a v1 Options field; it is the resolved + * plugin.discoveryRetry setting (a duration the registry declares and + * v1 applied to its discovery ladder), carried beside the options + * because tools.ts's ladder is its only consumer in this tree. + * + * Still unresolved here, deliberately: env / headless. The v2 core + * has no consumer for them yet — env sized v1's shell.env payload + * (the v2 environment route sends the full env by design, §3), and + * headless gated v1's toasts (the v2 context slice has no TUI + * channel). Resolving a setting nothing reads would be the + * declared-but-unread bug in a new costume. (instructions was on + * this list until the tools slice: the context hook now gates its + * paragraph on it, exactly as v1's system transform did, so it is + * resolved above.) + */ +export type ResolvedOptions = Options & { discoveryRetryMs?: number }; + +export function resolveOptions(raw: Options | undefined, env: Record): ResolvedOptions { + const o = raw ?? {}; + return { + endpoint: str(o.endpoint) ?? str(env.MCPX_DAEMON_ENDPOINT) ?? str(env.MCPX_ENDPOINT), + socket: str(o.socket) ?? str(env.MCPX_SOCKET), + bin: binStr(o.bin) ?? str(env.MCPX_PLUGIN_BIN), + binArgs: Array.isArray(o.binArgs) + ? o.binArgs + : typeof o.binArgs === "string" + ? splitArgs(o.binArgs) + : splitArgs(env.MCPX_PLUGIN_BIN_ARGS), + backend: (str(o.backend) ?? str(env.MCPX_PLUGIN_BACKEND) ?? "auto") as Options["backend"], + remember: (str(o.remember) ?? str(env.MCPX_PLUGIN_REMEMBER) ?? "session") as Options["remember"], + env: (str(o.env) ?? str(env.MCPX_PLUGIN_ENV)) as Options["env"], + tools: o.tools ?? truthy(env.MCPX_PLUGIN_TOOLS) ?? false, + instructions: o.instructions ?? truthy(env.MCPX_PLUGIN_INSTRUCTIONS) ?? false, + daemonTools: o.daemonTools ?? truthy(env.MCPX_PLUGIN_DAEMON_TOOLS), + annotate: o.annotate ?? truthy(env.MCPX_PLUGIN_ANNOTATE) ?? true, + toolTiming: o.toolTiming ?? truthy(env.MCPX_PLUGIN_TOOL_TIMING) ?? false, + answerSampling: o.answerSampling ?? true, + discoveryRetryMs: goDurationMs(env.MCPX_PLUGIN_DISCOVERY_RETRY), + disabledTools: nameList(o.disabledTools) ?? nameList(env.MCPX_PLUGIN_DISABLED_TOOLS), + }; +} diff --git a/.opencode/plugin/core/timing.test.ts b/.opencode/plugin/core/timing.test.ts new file mode 100644 index 0000000000..9302a0df12 --- /dev/null +++ b/.opencode/plugin/core/timing.test.ts @@ -0,0 +1,29 @@ +/** + * Core timing log (oracle: the createTimingLog contract in + * timing.ts -- every execute.after input becomes one record, in + * order, handed to the optional sink; failures are first-class + * rows, not invisible). + * + * bun test plugin/core/timing.test.ts + */ +import { describe, expect, test } from "bun:test"; +import { createTimingLog, type ToolTimingRecord } from "./timing.ts"; + +describe("createTimingLog (oracle: one record per input, sink sees each)", () => { + test("records completed and error rows in order and sinks them", () => { + const seen: ToolTimingRecord[] = []; + const log = createTimingLog((r) => seen.push(r)); + const a = log.hook({ tool: "mcpx_exec", sessionID: "s1", status: "completed" }); + const b = log.hook({ tool: "mcpx_search", sessionID: "s1", status: "error" }); + expect(log.records).toEqual([a, b]); + expect(seen).toEqual([a, b]); + expect(b.status).toBe("error"); + expect(typeof a.at).toBe("number"); + }); + + test("works without a sink", () => { + const log = createTimingLog(); + log.hook({ tool: "t", sessionID: "s", status: "completed" }); + expect(log.records.length).toBe(1); + }); +}); diff --git a/.opencode/plugin/core/timing.ts b/.opencode/plugin/core/timing.ts new file mode 100644 index 0000000000..69c72a178e --- /dev/null +++ b/.opencode/plugin/core/timing.ts @@ -0,0 +1,44 @@ +/** + * Tool timing records, harness-free core (#1861): the record shape and + * the in-memory log both adapters share; the v2 tree re-exports this + * module from v2/timing.ts. + * + * Tool timing from tool.hook("execute.after") (design doc §2.1). Unlike v1, + * the hook input is a status union — { status: "completed", result } or + * { status: "error", ... } — so failures are recorded as first-class rows + * instead of being invisible. Records are kept in memory for the session and + * handed to an optional sink (the caller decides where timings go). + */ +export type ToolTimingRecord = { + tool: string; + sessionID: string; + status: "completed" | "error"; + at: number; +}; + +export type ExecuteAfterInput = { + tool: string; + sessionID: string; + status: "completed" | "error"; +}; + +export function createTimingLog(sink?: (record: ToolTimingRecord) => void): { + hook: (input: ExecuteAfterInput) => ToolTimingRecord; + records: ToolTimingRecord[]; +} { + const records: ToolTimingRecord[] = []; + return { + records, + hook(input) { + const record: ToolTimingRecord = { + tool: input.tool, + sessionID: input.sessionID, + status: input.status, + at: Date.now(), + }; + records.push(record); + sink?.(record); + return record; + }, + }; +} diff --git a/.opencode/plugin/mcpx-session.ts b/.opencode/plugin/mcpx-session.ts index bd80b73492..9d1018ddda 100644 --- a/.opencode/plugin/mcpx-session.ts +++ b/.opencode/plugin/mcpx-session.ts @@ -24,6 +24,7 @@ import { type DiscoverOptions, type Target, } from "../core/daemon.ts"; +import { truthy, type Options } from "../core/options.ts"; // The only reliable way to tell, in v1, whether anyone is looking at a // screen. See `headless` below. import { isMainThread } from "node:worker_threads"; @@ -75,43 +76,8 @@ import { isMainThread } from "node:worker_threads"; */ /** Everything this plugin can be told, from config or from the environment. */ -type Options = { - /** A daemon named outright. `unix:///path` or `http://host:port`. */ - endpoint?: string; - /** A socket named outright. */ - socket?: string; - /** The mcpx binary, or "" to forbid spawning one. */ - bin?: string; - /** Arguments to put before mcpx's own, as a vector or a string. */ - binArgs?: string[] | string; - /** Where the opt-in tools get their answers: auto, v1 or cli. */ - backend?: "auto" | "v1" | "cli"; - /** Default scope for a daemon choice made this session. */ - remember?: "session" | "until-gone" | "indefinite"; - /** How much to inject into shell environments. */ - env?: "minimal" | "standard" | "full"; - instructions?: boolean; - toolTiming?: boolean; - tools?: boolean; - /** Offer mcpx_daemon_status and mcpx_daemon_select. Default: when unclear. */ - daemonTools?: boolean; - /** Report ambiguity on tool results. Default on. */ - annotate?: boolean; - /** Override the "is anyone looking at this" guess. */ - headless?: boolean; -}; - type Level = "minimal" | "standard" | "full"; -const truthy = (v: unknown): boolean | undefined => { - if (v === undefined || v === null || v === "") return undefined; - if (typeof v === "boolean") return v; - const s = String(v).toLowerCase(); - if (s === "1" || s === "true" || s === "yes" || s === "on") return true; - if (s === "0" || s === "false" || s === "no" || s === "off") return false; - return undefined; -}; - /** Set a variable only when it is actually something. */ const put = (env: Record, key: string, value: unknown): void => { if (value === undefined || value === null) return; diff --git a/.opencode/plugin/mcpx/biome.json b/.opencode/plugin/mcpx/biome.json index 728c1939ec..8e2f4f2f8b 100644 --- a/.opencode/plugin/mcpx/biome.json +++ b/.opencode/plugin/mcpx/biome.json @@ -1,9 +1,7 @@ { "$schema": "https://biomejs.dev/schemas/2.5.15/schema.json", "root": false, - "extends": [ - "../../../../../biome.json" - ], + "extends": ["../../../../../biome.json"], "linter": { "rules": { "suspicious": { diff --git a/.opencode/plugin/mcpx/ceiling.test.ts b/.opencode/plugin/mcpx/ceiling.test.ts index 94c804f5f0..f6ecb03f1a 100644 --- a/.opencode/plugin/mcpx/ceiling.test.ts +++ b/.opencode/plugin/mcpx/ceiling.test.ts @@ -5,29 +5,29 @@ * passes its socket; without one there is nothing to test, and the file * registers nothing rather than reporting a skip. */ -import { existsSync } from "node:fs" -import { describe, expect, test } from "bun:test" +import { existsSync } from "node:fs"; +import { describe, expect, test } from "bun:test"; -import { DaemonClient } from "../../core/daemon.ts" +import { DaemonClient } from "../../core/daemon.ts"; -const socket = process.env.CEILING_SOCKET -const mark = process.env.CEILING_MARK as string +const socket = process.env.CEILING_SOCKET; +const mark = process.env.CEILING_MARK as string; if (socket) { describe("the plugin under autonomy.max propose", () => { test("asking intent and recipe_run to run is lowered, reported, and does not run", async () => { - const ops = new DaemonClient({ kind: "socket", path: socket }).ops + const ops = new DaemonClient({ kind: "socket", path: socket }).ops; const answers = [ await ops.intent({ prompt: "leave a mark on the filesystem", autonomy: "run", placeholders: { path: mark } }), await ops.recipeRun({ name: "mark", autonomy: "run", placeholders: { path: mark } }), - ] as Array> + ] as Array>; for (const a of answers) { - expect(a.autonomy).toBe("propose") - expect(a.requested).toBe("run") - expect(String(a.clampedBy)).toStartWith("autonomy.max") - expect(a.result).toBeUndefined() + expect(a.autonomy).toBe("propose"); + expect(a.requested).toBe("run"); + expect(String(a.clampedBy)).toStartWith("autonomy.max"); + expect(a.result).toBeUndefined(); } - expect(existsSync(mark)).toBe(false) - }) - }) + expect(existsSync(mark)).toBe(false); + }); + }); }