Files
stack/packages/bus/tests/channel-proof.test.mjs
jason.woltje 4a9c7a931c feat(organization): triage is system-only, no organization gains it (#1873, lane triage-fence)
One list, SYSTEM_ONLY in vocabulary.mjs, names triage; every path by which an
organization could gain one refuses with the one code template-system-only:
hire prepare at org, project and root level and a change onto it (hire.raise,
hire.start.console, decision.raise naming role.hire or role.change); the hire
and definitions template lists omit it; definition import; a definition copied
from it; organization roles, root agents and project agents; a pack record
pinning it; a starter pack defining it, so pack preview and apply refuse an
installed pack that names it; instances.set add and change for the human and
the tester, and the instances add list omits it. The broker passes the code
through and the webui tables map it. The template itself still loads and
validates. Red-first tests in organization and bus system-only.test.mjs; the
channel-proof hash of webui bus.mjs and the broker import pin are updated.
2026-11-16 11:38:17 -06:00

77 lines
5.4 KiB
JavaScript

// Row 164 freezes reviewed proof bytes and the literal entry-path rule.
// Row 196 intentionally re-pins human.mjs for the distinct user nonce and shared human
// walk, and webui bus.mjs for initial-spawn nonce plus peer refusal status. Entry paths
// and the ban on channel plug-ins importing a proof caller are retained.
// Row 254 (#1759) re-pins human-cli.mjs for the 130 s library.sync client timeout and webui
// bus.mjs for six library-* STATUS entries; no proof or transport change.
// Row 236 (#1742) re-pins human-cli.mjs for the same 130 s wait on the grants verbs; no proof or
// transport change.
// Row 252 (#1753, Webby N5) re-pins human.mjs, whose readProcess also keeps the five
// MOSAIC_BUS_CONSOLE_* keys for the Console wrapper's proof, and webui bus.mjs for consoleCall,
// which shares humanCall's spawn as transport(). The human proof and its spawn are unchanged.
// Row 225 (C2-10b) re-pins webui bus.mjs for one STATUS entry, library-revert-not-agent: 409; no proof
// or transport change.
// E2E6 fix 6 re-pins human-cli.mjs, which exits 5 when its connect failed before the request was
// written, and cli transport.mjs, which reads that exit as bus-not-running. The proof is unchanged.
import test from "node:test";
import assert from "node:assert/strict";
import { createHash } from "node:crypto";
import { readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { provedRuntime } from "../../cli/tests/channel-fixture.mjs";
import { Client } from "../src/client.mjs";
const baselines = {
"packages/bus/src/human.mjs": "bb13c146717cdc46d75d157177e400edac4d3e10f14fe511027a25fd44cec885",
"packages/bus/src/human-cli.mjs": "410892787cc70440b0ba4c45d6f24861d12ee5e70cba678cfeb1ed86b796c149",
// Row 239 (#1745): EXIT outcome-unknown-revoked 1; no proof or transport change.
// E2E6 fix 6: shim exit 5 with outcome-unknown becomes bus-not-running (exit 3, start and recover next).
"packages/cli/src/transport.mjs": "101870f7ffb47a9cbd54ebd8c1901734cc9f442d6770cb2a0d059afd4d14b160",
// Row 165 (#1662): seven STATUS entries for the role instance routes (organization-instance-exists,
// organization-unknown-instance, organization-credentials-out-of-scope, organization-launch-not-configured,
// organization-no-change, organization-project-mismatch, organization-unresolvable-instance), no proof or
// transport change. Row 155 (#1649) added eight for the assistant routes.
// Row 171 (#1668): project-name-is-repo maps to 409; no proof or transport change.
// Row 194 (#1692, brief item 7, sage-1610 a): organization-tracker-required 400 and
// organization-tracker-bot-taken 409; no proof or transport change.
// Row 301 (#1808, mos-1449): the user transport moved from user-bus.mjs into bus.mjs; humanCall unchanged.
// Row 239 (#1745): outcome-unknown-revoked joins OPEN (duckworth-0165 C1), and STATUS gets
// revision-conflict-revoked 409 and outcome-unknown-revoked 503; no proof or transport change.
// #1839: artifact Console replies alone may use 2 MiB; the proof and other limits are unchanged.
// #1873 U1: humanCall, busCaller, userCall and userCaller take an optional signal and absolute
// deadline; userCall shares transport(). Nonces, argv and limits are unchanged.
// #1873 A3: STATUS maps credential-unbound, copy-refused, project-refused and project-agent-elsewhere
// to 409; no proof or transport change.
// #1873 triage-fence: STATUS maps template-system-only to 400; no proof or transport change.
"packages/webui/src/bus.mjs": "cd08e1beb49e9e881bb1b308f2ab3343a480b47dd9b17ccbd16e120d341d7511",
};
const repoFile = path => new URL("../../../" + path, import.meta.url);
test("channel conversion preserves the four proof/transport byte baselines and modules cannot import a proof caller", () => {
for (const [file, hash] of Object.entries(baselines))
assert.equal(createHash("sha256").update(readFileSync(repoFile(file))).digest("hex"), hash, file);
for (const name of ["cli", "webui"]) {
const source = readFileSync(repoFile(`packages/plugins/channel/${name}/index.mjs`), "utf8");
assert.doesNotMatch(source, /human-cli|humanTransport|humanCall|verifyHuman|readProcess|child_process|spawn/);
}
});
test("channel recovery still requires the same shim path and rejects an absent or forged proof", { timeout: 20000 }, async t => {
const s = await provedRuntime(t);
const direct = new Client({ path: s.socket });
await assert.rejects(direct.call("plugins"), e => ["invalid-envelope", "unauthenticated", "human-required"].includes(e.code));
const forged = new Client({ path: s.socket, human: { business: "demo", pid: process.pid, startTime: "0", nonce: "a".repeat(64) } });
await assert.rejects(forged.call("plugins"), e => e.code === "human-required");
const genuine = await s.shimCall(s.shim, { business: "demo", verb: "plugins" });
assert.equal(genuine.status, 0, genuine.stderr);
assert.deepEqual(JSON.parse(genuine.stdout).plugins.channel, []);
let other = readFileSync(s.shim, "utf8");
other = other.replace("'./client.mjs'", JSON.stringify(new URL("../src/client.mjs", import.meta.url).href));
other = other.replace("'./human.mjs'", JSON.stringify(new URL("../src/human.mjs", import.meta.url).href));
const differentPath = join(s.root, "other-human-cli.mjs");
writeFileSync(differentPath, other);
const refused = await s.shimCall(differentPath, { business: "demo", verb: "plugins" });
assert.notEqual(refused.status, 0);
assert.equal(refused.stderr.trim(), "human-required");
});