Adds plugin kind `channel` (interfaceVersion 1, dispatch(request, {call}))
with cli and webui modules. Project and thread surfaces and thread
talk/follow in the CLI and the Console chat go through the selected
channel. An empty or absent channel selection is off: the CLI exits 3 and
the Console answers 503, each naming `mosaic plugins` and `mosaic plugins
set` with the business selector. Management plugins and plugins.set stay
on the core transport. The loader gains a synchronous snapshot(kind)
getter; loaded(), modules() and last-good handling are unchanged. No lock
is held across dispatch. serve.mjs, public/ and the bus are untouched.
Owner Rocko. Reviewer Dewey: r1 changes (comment 28980, B1: the recovery
sentence was never asserted), r2 approve (comment 28984) on candidate
manifest ae2fcfda...1fc8, the B1 assert killing mutant D1. Design accepted
by Mos (mos-0768, mos-0773). Fixture rewrite at project.test.mjs:47 acked
by Mos (mos-0789) on Dewey's line-by-line check: lines 48-51 identical,
one added assert. Sage gate on e5b10d275: 25 steps green, 2081 package tests, 156 queue node tests, 422 script selftests, 0 failed.
Live stays as pinned. The re-pin that takes this live puts `mosaic
plugins set` in Jason's window right after activate (mos-0768).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
76 lines
3.9 KiB
JavaScript
76 lines
3.9 KiB
JavaScript
// Private fixture runtime only; no live host, unit, store or organization file.
|
|
import { spawn } from "node:child_process";
|
|
import { once } from "node:events";
|
|
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { fixture, BUSINESSES } from "./helpers.mjs";
|
|
import { systemFor } from "../../business/tests/helpers.mjs";
|
|
|
|
export async function childResult(file, args, env, input) {
|
|
const child = spawn(file, args, { env, stdio: ["pipe", "pipe", "pipe"] });
|
|
let stdout = "", stderr = "";
|
|
child.stdout.on("data", b => stdout += b);
|
|
child.stderr.on("data", b => stderr += b);
|
|
child.stdin.on("error", () => {});
|
|
child.stdin.end(input);
|
|
const [status, signal] = await once(child, "close");
|
|
return { status, signal, stdout, stderr };
|
|
}
|
|
|
|
export async function provedRuntime(t) {
|
|
const root = mkdtempSync(join(tmpdir(), "channel-recovery-"));
|
|
let host;
|
|
t.after(async () => {
|
|
try {
|
|
if (host && host.exitCode === null && host.signalCode === null) {
|
|
const done = once(host, "close");
|
|
const timer = setTimeout(() => host.kill("SIGKILL"), 3000);
|
|
host.kill("SIGTERM");
|
|
try { await done; } finally { clearTimeout(timer); }
|
|
}
|
|
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
});
|
|
const f = fixture(root, "demo", doc => ({ ...doc, plugins: { channel: [] } }));
|
|
mkdirSync(f.dataRoot, { mode: 0o700 });
|
|
const url = rel => new URL(rel, import.meta.url).href;
|
|
const humanURL = url("../../bus/src/human.mjs");
|
|
const script = join(root, "fixture-runtime.mjs");
|
|
// As in stack-copy.test.mjs, isolate the fixture's ancestry from the seat.
|
|
// The real PID, UID, argv path, start time, nonce and verifier still run.
|
|
writeFileSync(script, `
|
|
import { mock } from 'node:test';
|
|
const real = await import(${JSON.stringify(humanURL)});
|
|
mock.module(${JSON.stringify(humanURL)}, { namedExports: {
|
|
readProcess: real.readProcess,
|
|
verifyHuman: (proof, options) => real.verifyHuman(proof, { ...options,
|
|
readProcess: pid => ({ ...real.readProcess(pid), ppid: 1 }) }),
|
|
} });
|
|
const { startBroker } = await import(${JSON.stringify(url("../../bus/src/runtime.mjs"))});
|
|
const runtime = await startBroker({ dataRoot: ${JSON.stringify(f.dataRoot)},
|
|
businesses: ${JSON.stringify(BUSINESSES)},
|
|
organization: { dir: ${JSON.stringify(join(root, "config"))}, rolesDir: ${JSON.stringify(f.roles)}, system: ${JSON.stringify(systemFor(root))} } });
|
|
process.on('SIGTERM', async () => { await runtime.close(); process.exit(0); });
|
|
console.log('fixture ready');
|
|
`);
|
|
const env = { PATH: process.env.PATH, HOME: root, TMPDIR: process.env.TMPDIR,
|
|
MOSAIC_CONFIG: f.config, MOSAIC_ROLES_DIR: f.roles };
|
|
host = spawn(process.execPath, ["--experimental-test-module-mocks", script], { env, stdio: ["ignore", "pipe", "pipe"] });
|
|
let output = "", errors = "";
|
|
host.stderr.on("data", b => errors += b);
|
|
await new Promise((resolve, reject) => {
|
|
host.stdout.on("data", b => { output += b; if (output.includes("fixture ready")) resolve(); });
|
|
host.once("exit", code => reject(new Error(`fixture failed ${code}: ${errors}`)));
|
|
host.once("error", reject);
|
|
});
|
|
const cli = fileURLToPath(new URL("../src/cli.mjs", import.meta.url));
|
|
const shim = fileURLToPath(new URL("../../bus/src/human-cli.mjs", import.meta.url));
|
|
return { root, f, env, shim, socket: join(f.dataRoot, "bus/broker.sock"),
|
|
cli: argv => childResult(process.execPath, [cli, ...argv, "--business", "demo"], env),
|
|
shimCall: (file, request) => childResult(process.execPath, [file, join(f.dataRoot, "bus/broker.sock")], env, JSON.stringify(request) + "\n"),
|
|
file: join(root, "config/businesses/demo.json"),
|
|
history: () => readFileSync(join(root, "config/businesses/.history/demo/changes.jsonl"), "utf8").trim().split("\n").map(JSON.parse),
|
|
};
|
|
}
|