packages/plugins holds the kind registry and the loader for in-repo plug-in modules (REQ-PLUG-1). The first two kinds are usage-source and limit-check (REQ-LIMIT-4). The business file's plugins key turns modules on per kind, through plugin-settings.mjs and step 5's write path (REQ-ROLE-3). A refused load is logged and keeps the kind's old modules. Any filesystem error other than ENOENT or ENOTDIR refuses as unreadable. The organization writer validates the bytes it writes as well as the document. stack-copy ships packages/plugins. Nothing is wired into a host process yet. Candidate 466c835f7dce79d20c7ab74c197a52b70e7fdeb0efae0456222dc6d0a633f219, Dewey packet80797a539(round 2), base0bdd573ff. Filbert approved round 2 in 28568 and Darkwing in 28570. Landing gate atf7d249634: 24 suites green, 0 failed. 14 package suites passed 1586 tests (plugins 21, business 92, bus 171, cli 195, webui 112). The 10 script suites passed. Follow-up: P19 task 293, coded writer refusals. Co-Authored-By: Claude Opus 5.5 <[email protected]>
48 lines
2.9 KiB
JavaScript
48 lines
2.9 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 and limit-check at interface version 1, each a list", () => {
|
|
assert.deepEqual(Object.keys(KINDS), ["usage-source", "limit-check"]);
|
|
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: 1, exports: ["mayLaunch", "mustStop"], switch: "list" });
|
|
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"]);
|
|
});
|