Adds the harness plug-in kind (interface 1). packages/plugins/harness/pi and claude-code hold what core branched on: the adapter, thinking levels, preflight, version probe, sandbox mounts, builtins line, typed tool names, gate timeout, bundle files, adapter env, turn end and session-files path. Core reaches a module only through the loader. A session's route is the instance's harness, model and thinking vars, or the three fallback. vars; a missing one refuses no-route, and the system file's execution keys are never read for a session. The launcher checks the primary route, then the fallback: harness-off, harness-refused, thinking-unsupported, then preflight. A failed preflight falls back when a fallback is set, and any refusal of the fallback names the primary's failure too. Account checks run only when the route's module counts an account. The manifest records route, routeReason and harnessVersion, replacing piVersion and claudeVersion. pi gets --thinking, Claude Code --effort, both from MOSAIC_THINKING. The business file refuses a partial fallback. routes and routes.set are human-only bus verbs outside ORGANIZATION_KEYS; checkRoutes is shared by routes.set, instances.set and limits.set and checks only changed routes. The chief of staff changes an instance's model, and the assistant's whole vars (Q169), through limits.set, so its route write runs the same checks. A model outside launch.models refuses unknown-model, primary or fallback, and routes.set passes that code through. A new run binds only on a switched-on harness module name and records its transcript path, which the usage reader uses. Settings gains a Routing table with six selects per instance and loses the Role models fieldset; it posts changed rows to /api/routes. webui/src/bus.mjs is unchanged. Until Jason's `mosaic plugins set` adds "harness": ["claude-code"], a new launch refuses harness-off.
57 lines
3.6 KiB
JavaScript
57 lines
3.6 KiB
JavaScript
// REQ-PLUG-1: the kind registry and the organization file's `plugins` shape (row 131).
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { KINDS, NAME, PluginError, checkPlugins } from "../src/kinds.mjs";
|
|
|
|
const code = expected => e => e instanceof PluginError && e.code === expected;
|
|
|
|
test("REQ-PLUG-1 REQ-LIMIT-4 the registry: usage-source at interface version 1, limit-check at 2 (row 125), each a list", () => {
|
|
assert.deepEqual(Object.keys(KINDS), ["usage-source", "limit-check", "search-source", "channel", "harness"]);
|
|
assert.deepEqual({ ...KINDS["usage-source"], exports: [...KINDS["usage-source"].exports] },
|
|
{ kind: "usage-source", interfaceVersion: 1, exports: ["readTurn"], switch: "list" });
|
|
assert.deepEqual({ ...KINDS["limit-check"], exports: [...KINDS["limit-check"].exports] },
|
|
{ kind: "limit-check", interfaceVersion: 2, exports: ["mayLaunch", "mustStop", "report"], switch: "list" });
|
|
assert.deepEqual({ ...KINDS["search-source"], exports: [...KINDS["search-source"].exports] },
|
|
{ kind: "search-source", interfaceVersion: 1, exports: ["search"], switch: "one" });
|
|
// Row 65 (REQ-PLUG-2, Q156): the harness kind, a list, at interface version 1.
|
|
assert.deepEqual({ ...KINDS.harness, exports: [...KINDS.harness.exports] }, {
|
|
kind: "harness", interfaceVersion: 1, switch: "list",
|
|
exports: ["adapter", "levels", "preflight", "version", "countsAccount", "mounts", "builtinWeb", "builtins",
|
|
"typedName", "reliesOn", "gateTimeout", "bundle", "env", "turnEnd", "transcript"],
|
|
});
|
|
assert.ok(Object.isFrozen(KINDS.harness) && Object.isFrozen(KINDS.harness.exports));
|
|
assert.ok(Object.isFrozen(KINDS) && Object.isFrozen(KINDS["usage-source"]) && Object.isFrozen(KINDS["limit-check"].exports));
|
|
assert.equal(String(NAME), "/^[a-z][a-z0-9-]*$/");
|
|
});
|
|
|
|
test("REQ-PLUG-1 checkPlugins accepts one key per kind, each a list of names, empty included", () => {
|
|
for (const value of [{}, { "usage-source": [] }, { "usage-source": ["a", "b-2"], "limit-check": ["cap"] }]) {
|
|
assert.equal(checkPlugins(value, "plugins"), value);
|
|
}
|
|
});
|
|
|
|
test("REQ-PLUG-1 checkPlugins refuses bad shapes, unknown kinds, bad names and duplicates", () => {
|
|
for (const value of [null, [], "x", 3]) assert.throws(() => checkPlugins(value, "plugins"), code("bad-setting"));
|
|
assert.throws(() => checkPlugins({ "made-up": [] }, "plugins"), code("unknown-kind"));
|
|
assert.throws(() => checkPlugins({ toString: [] }, "plugins"), code("unknown-kind"));
|
|
assert.throws(() => checkPlugins({ "usage-source": "meter" }, "plugins"), code("bad-setting"));
|
|
for (const name of ["Meter", "1m", "m_x", "../x", "a/b", ".x", "", 7, null]) {
|
|
assert.throws(() => checkPlugins({ "usage-source": [name] }, "plugins"), code("bad-name"), String(name));
|
|
}
|
|
assert.throws(() => checkPlugins({ "limit-check": ["cap", "cap"] }, "plugins"), code("bad-setting"));
|
|
});
|
|
|
|
test("REQ-PLUG-1 a kind that switches on one module takes one name, not a list", () => {
|
|
const kinds = { single: { kind: "single", interfaceVersion: 1, exports: ["run"], switch: "one" } };
|
|
assert.ok(checkPlugins({ single: "only" }, "plugins", { kinds }));
|
|
assert.throws(() => checkPlugins({ single: ["only"] }, "plugins", { kinds }), code("bad-setting"));
|
|
assert.throws(() => checkPlugins({ single: "Only" }, "plugins", { kinds }), code("bad-name"));
|
|
});
|
|
|
|
test("REQ-PLUG-1 checkPlugins reports through the caller's fail callback", () => {
|
|
const seen = [];
|
|
const fail = (c, message) => { seen.push(c); throw new Error(message); };
|
|
assert.throws(() => checkPlugins({ "made-up": [] }, "x plugins", { fail }), /x plugins names unknown kind/);
|
|
assert.deepEqual(seen, ["unknown-kind"]);
|
|
});
|