row 175 (#1673): tester reads, W1-W7 writes recorded as tester, human-only verbs refuse tester-refused
TESTER_VERBS gains usage, names, limits, plugins, instances, project.list, thread.list, name.set and project.create; TESTER_ORGANIZATION_VERBS lets a tester read limits, plugins and instances and send plugins.set, instances.set and routes.set, each logged with actor tester. The project file verbs refuse a tester tester-refused. The broker and CLI drop the [mos test] prefix rule (mos-0872 Q1). The CLI takes --tester on the seven reads and the W1-W7 write forms and refuses it (exit 4) elsewhere. project init --tester checks the project area, binds the tester with one agents read, then commits the layout as tester (mos-0872 Q2).
This commit is contained in:
1 parent
1bfc9833b1
commit
e5e64afecb
24 files changed
+629
-118
No files matched your search
@@ -54,6 +54,6 @@ test("name and names refuse the wrong number of arguments with the usage", async
|
||||
assert.ok(r.error.endsWith(USAGE), r.error);
|
||||
}
|
||||
assert.equal(s.calls.length, 0);
|
||||
assert.match(USAGE, /^ {2}mosaic name <instance> <name> \[--business <id>\]$/m);
|
||||
assert.match(USAGE, /^ {2}mosaic names \[--business <id>\] \[--json\]$/m);
|
||||
assert.match(USAGE, /^ {2}mosaic name <instance> <name> \[--business <id>\] \[--tester\]$/m);
|
||||
assert.match(USAGE, /^ {2}mosaic names \[--business <id>\] \[--json\] \[--tester\]$/m);
|
||||
});
|
||||
@@ -0,0 +1,185 @@
|
||||
// Row 175 (#1673, Q173, mos-0870 N2, mos-0872): the CLI's tester forms. The seven reads print what
|
||||
// the human's forms print, every write form outside W1-W7 refuses --tester before any call, and
|
||||
// `project init --tester` checks the project area, binds the tester, then commits as `tester`.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { existsSync, readdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { main } from "../src/cli.mjs";
|
||||
import { BusError } from "../../bus/src/broker.mjs";
|
||||
import { startBroker } from "../../bus/src/runtime.mjs";
|
||||
import { systemFor, writeJson } from "../../business/tests/helpers.mjs";
|
||||
import { fixture, humanEnv, io, tmp } from "./helpers.mjs";
|
||||
|
||||
const none = { authority: { withinRole: ["message.send"], crossRole: [] } };
|
||||
const inAgent = (env) => io({ ...env, CLAUDECODE: "1", CLAUDE_CODE_ENTRYPOINT: "sdk-ts" });
|
||||
const bus = (vars = { "bus.tester": true }) => ({
|
||||
acme: {
|
||||
id: "acme", human: "jason", arbiters: { technical: "coder", delivery: "coder" }, ...(vars ? { vars } : {}),
|
||||
roles: { coder: { definition: "coder", ...none }, assistant: { definition: "assistant", ...none } },
|
||||
},
|
||||
});
|
||||
|
||||
// The runtime in this process behind stand-in transports, as instances.test.mjs.
|
||||
async function setup(t) {
|
||||
const root = tmp(t, "mosaic-cli-tester-reads-");
|
||||
const f = fixture(root, "acme");
|
||||
const rt = await startBroker({ dataRoot: f.dataRoot, businesses: bus(), organization: { dir: join(root, "config"), rolesDir: f.roles, system: systemFor(root) } });
|
||||
t.after(() => rt.close());
|
||||
const human = rt.broker.bindHuman({ business: "acme", human: "jason", via: "cli", outsideAgent: true });
|
||||
const tester = rt.broker.bindTester({ business: "acme" });
|
||||
const calls = { human: [], tester: [] };
|
||||
const via = (cap, list) => (business) => async (verb, args = {}) => {
|
||||
list.push(verb);
|
||||
try {
|
||||
return structuredClone(rt.broker.request(cap, { verb, args }));
|
||||
} catch (e) {
|
||||
if (!(e instanceof BusError)) throw e;
|
||||
const error = new Error(e.code);
|
||||
error.code = e.code;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
const deps = { system: { dataRoot: f.dataRoot }, transport: via(human, calls.human), testerTransport: via(tester, calls.tester), talkPollMs: 5 };
|
||||
const call = (verb, args = {}) => rt.broker.request(human, { verb, args });
|
||||
return { root, f, rt, human, tester, calls, deps, call };
|
||||
}
|
||||
|
||||
const READS = [
|
||||
["usage"],
|
||||
["names"],
|
||||
["limits"],
|
||||
["plugins"],
|
||||
["threads"],
|
||||
["project", "list"],
|
||||
];
|
||||
|
||||
test("row 175: each read with --tester inside an agent prints the human form's output, and refuses without --tester", async (t) => {
|
||||
const s = await setup(t);
|
||||
s.call("plugins.set", { revision: s.call("plugins").revision, plugins: { channel: ["cli", "webui"] } });
|
||||
s.call("name.set", { instance: "coder", name: "rex" });
|
||||
const project = s.call("project.create", { name: "alpha" }).id;
|
||||
s.call("thread.create", { project, name: "one" });
|
||||
const forms = [...READS.map((argv) => [...argv, "--business", "acme"]), ["business", "instances", "acme"]];
|
||||
for (const argv of forms) {
|
||||
const name = argv.slice(0, 2).join(" ");
|
||||
const h = io(s.f.env);
|
||||
await main(argv, h, s.deps);
|
||||
const humanCalls = s.calls.human.length;
|
||||
const testerCalls = s.calls.tester.length;
|
||||
const x = inAgent(s.f.env);
|
||||
await main([...argv, "--tester"], x, s.deps);
|
||||
assert.equal(x.out.text, h.out.text, name);
|
||||
assert.ok(x.out.text.length > 0, name);
|
||||
assert.equal(s.calls.human.length, humanCalls, `${name}: the tester form made no human call`);
|
||||
assert.ok(s.calls.tester.length > testerCalls, `${name}: the tester form called the tester transport`);
|
||||
await assert.rejects(main(argv, inAgent(s.f.env), s.deps), (e) => e.exitCode === 3, `${name} without --tester`);
|
||||
assert.equal(s.calls.human.length, humanCalls, `${name}: the refusal came before any call`);
|
||||
}
|
||||
// Not empty: the names, the thread and the project the human made are in the tester's view.
|
||||
const x = inAgent(s.f.env);
|
||||
await main(["threads", "--business", "acme", "--json", "--tester"], x, s.deps);
|
||||
assert.deepEqual(JSON.parse(x.out.text).map((r) => r.name), ["one"]);
|
||||
});
|
||||
|
||||
test("row 175: --tester on limits set, reset and migrate and every write form outside W1-W7 exits 4 before any call", async (t) => {
|
||||
const s = await setup(t);
|
||||
for (const argv of [
|
||||
["limits", "set", "--file", "patch.json", "--business", "acme"],
|
||||
["limits", "reset", "total", "--business", "acme"],
|
||||
["limits", "migrate", "--file", "org.json", "--models", "map.json"],
|
||||
["decide", "d1", "yes", "--business", "acme"],
|
||||
["inbox", "--read", "abcdefgh", "--business", "acme"],
|
||||
["inbox", "--read-all", "--business", "acme"],
|
||||
["thread", "create", "alpha", "one", "--business", "acme"],
|
||||
["thread", "open", "t-1", "--business", "acme"],
|
||||
["thread", "read", "t-1", "--business", "acme"],
|
||||
["talk", "--thread", "t-1", "hello", "--business", "acme"],
|
||||
["follow", "--thread", "t-1", "--business", "acme"],
|
||||
["stop", "run-1"],
|
||||
["launches", "off", "--business", "acme"],
|
||||
["launches", "on", "--business", "acme"],
|
||||
["launches", "list"],
|
||||
["project", "check", "acme", "stack"],
|
||||
["project", "init", "acme", "stack", "--tester"],
|
||||
]) {
|
||||
const x = inAgent(s.f.env);
|
||||
await assert.rejects(main([...argv, "--tester"], x, s.deps), (e) => e.exitCode === 4, argv.join(" "));
|
||||
}
|
||||
assert.deepEqual(s.calls, { human: [], tester: [] });
|
||||
assert.equal(existsSync(join(s.f.dataRoot, "projects")), false);
|
||||
});
|
||||
|
||||
// W7 through the real tester transport: the CLI runs as its own process, so the tester-cli.mjs it
|
||||
// spawns can reach the runtime in this one.
|
||||
const MOSAIC = fileURLToPath(new URL("../../../scripts/mosaic", import.meta.url));
|
||||
function mosaic(args, env) {
|
||||
const clean = Object.fromEntries(Object.entries(env).filter(([k]) => !/^MOSAIC_BUS_(TESTER|CLI)_NONCE$/.test(k)));
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(MOSAIC, args, { env: clean, timeout: 60000 });
|
||||
let out = "";
|
||||
let err = "";
|
||||
child.stdout.on("data", (d) => (out += d));
|
||||
child.stderr.on("data", (d) => (err += d));
|
||||
child.on("error", reject);
|
||||
child.on("close", (status) => resolve({ status, out, err }));
|
||||
});
|
||||
}
|
||||
const listing = (dir) => readdirSync(dir, { recursive: true }).map(String).sort();
|
||||
async function w7(t, vars, edit) {
|
||||
const root = tmp(t, "mosaic-cli-tester-init-");
|
||||
const f = fixture(root, "acme", edit);
|
||||
const rt = await startBroker({ dataRoot: f.dataRoot, businesses: bus(vars) });
|
||||
t.after(() => rt.close());
|
||||
return { root, f, agent: { ...f.env, CLAUDECODE: "1", CLAUDE_CODE_ENTRYPOINT: "sdk-ts" } };
|
||||
}
|
||||
|
||||
test("row 175 W7: project init --tester makes the repository under the project area, committed by tester", async (t) => {
|
||||
const { f, agent } = await w7(t);
|
||||
const r = await mosaic(["project", "init", "acme", "stack", "--tester"], agent);
|
||||
assert.equal(r.status, 0, r.err);
|
||||
const repo = join(f.dataRoot, "projects", "acme", "stack");
|
||||
assert.match(r.out, new RegExp(`^initialized ${repo}\ncommit [0-9a-f]{40}\n$`));
|
||||
const log = spawnSync("git", ["-C", repo, "log", "--format=%an|%cn"], { encoding: "utf8" });
|
||||
assert.equal(log.stdout, "tester|tester\n");
|
||||
// Without --tester the same init inside an agent refuses, as before.
|
||||
const again = await mosaic(["project", "init", "acme", "stack"], agent);
|
||||
assert.equal(again.status, 3);
|
||||
assert.match(again.err, /outside any agent run/);
|
||||
});
|
||||
|
||||
test("row 175 W7: a repo outside the project area refuses tester-project-area before any bus call, and nothing changes", async (t) => {
|
||||
// The switch is off: a bind would refuse tester-off (exit 3), so exit 2 shows the area check ran first.
|
||||
const { f, agent } = await w7(t, null, (doc) => {
|
||||
doc.projects.stack.repo = join(doc.projects.stack.root, "..", "records");
|
||||
return doc;
|
||||
});
|
||||
const records = f.doc.projects.stack.repo;
|
||||
const data = listing(f.dataRoot);
|
||||
const r = await mosaic(["project", "init", "acme", "stack", "--tester"], agent);
|
||||
assert.equal(r.status, 2, r.err);
|
||||
assert.match(r.err, /tester-project-area/);
|
||||
assert.equal(existsSync(records), false);
|
||||
assert.deepEqual(listing(f.dataRoot), data);
|
||||
});
|
||||
|
||||
test("row 175 W7: the tester bind refuses tester-off and tester-required before any directory", async (t) => {
|
||||
const off = await w7(t, null);
|
||||
const data = listing(off.f.dataRoot);
|
||||
const r = await mosaic(["project", "init", "acme", "stack", "--tester"], off.agent);
|
||||
assert.equal(r.status, 3, r.err);
|
||||
assert.match(r.err, /tester-off/);
|
||||
assert.deepEqual(listing(off.f.dataRoot), data);
|
||||
assert.equal(existsSync(join(off.f.dataRoot, "projects")), false);
|
||||
const on = await w7(t);
|
||||
const before = listing(on.f.dataRoot);
|
||||
for (const marker of ["MOSAIC_RUN_ID", "MOSAIC_BUS_CAP", "MOSAIC_AGENT_RUN"]) {
|
||||
const under = await mosaic(["project", "init", "acme", "stack", "--tester"], { ...on.agent, [marker]: "x" });
|
||||
assert.equal(under.status, 3, `${marker}: ${under.err}`);
|
||||
assert.match(under.err, /tester-required/, marker);
|
||||
}
|
||||
assert.deepEqual(listing(on.f.dataRoot), before);
|
||||
assert.equal(existsSync(join(on.f.dataRoot, "projects")), false);
|
||||
});
|
||||
@@ -38,7 +38,7 @@ function setup(t, extra = {}) {
|
||||
// The tester runs inside an agent: a T3 seat or Mos.
|
||||
const inAgent = () => io({ ...humanEnv(), CLAUDECODE: "1", CLAUDE_CODE_ENTRYPOINT: "sdk-ts" });
|
||||
|
||||
test("talk --tester sends a [mos test] message as tester from inside an agent and prints the role's reply", async (t) => {
|
||||
test("talk --tester sends a message as tester from inside an agent and prints the role's reply", async (t) => {
|
||||
const s = setup(t);
|
||||
const x = inAgent();
|
||||
const deps = {
|
||||
@@ -57,7 +57,7 @@ test("talk --tester sends a [mos test] message as tester from inside an agent an
|
||||
};
|
||||
},
|
||||
};
|
||||
await main(["talk", "coder", "[mos test] is the plan current?", "--tester", "--business", "demo"], x, deps);
|
||||
await main(["talk", "coder", "is the plan current?", "--tester", "--business", "demo"], x, deps);
|
||||
assert.match(x.out.text, /^sent [0-9a-f-]{8} to coder\n/);
|
||||
assert.match(x.out.text, /coder \(INFO, re [0-9a-f-]{8}\) [0-9a-f-]{8}:\nthe plan is current\n/);
|
||||
assert.deepEqual(s.calls.human, []);
|
||||
@@ -69,11 +69,13 @@ test("talk --tester sends a [mos test] message as tester from inside an agent an
|
||||
assert.equal(s.store.get("SELECT count(*) n FROM events WHERE kind='human.input'").n, 0);
|
||||
});
|
||||
|
||||
test("talk --tester refuses text without the [mos test] prefix before any call", async (t) => {
|
||||
// Row 175 (#1673, mos-0872 Q1): the test system needs no "[mos test]" prefix; the body goes as typed.
|
||||
test("talk --tester sends text with no prefix, and follow --tester reads", async (t) => {
|
||||
const s = setup(t);
|
||||
await assert.rejects(main(["talk", "coder", "is the plan current?", "--tester", "--business", "demo"], inAgent(), s.deps), (e) => e.exitCode === 2 && /starts with "\[mos test\]"/.test(e.message));
|
||||
assert.deepEqual(s.calls.tester, []);
|
||||
// follow sends nothing, so it takes no prefix.
|
||||
await main(["talk", "coder", "is the plan current?", "--tester", "--wait", "0", "--business", "demo"], inAgent(), s.deps);
|
||||
assert.deepEqual(s.calls.tester.map((c) => c.verb), ["message.send"]);
|
||||
assert.equal(s.store.get("SELECT body FROM messages WHERE from_role='tester'").body, "is the plan current?");
|
||||
s.calls.tester.length = 0;
|
||||
const controller = new AbortController();
|
||||
const deps = { ...s.deps, signal: controller.signal, testerTransport: (b) => async (verb, args) => (controller.abort(), s.deps.testerTransport(b)(verb, args)) };
|
||||
await main(["follow", "--tester", "--business", "demo"], inAgent(), deps);
|
||||
@@ -116,7 +118,6 @@ test("the tester transport runs tester-cli.mjs, and the tester's refusals exit 3
|
||||
assert.deepEqual(seen.argv, [TESTER_CLI, "/run/fake.sock"]);
|
||||
assert.deepEqual(JSON.parse(seen.input), { business: "acme", verb: "agents", args: {} });
|
||||
for (const code of ["tester-required", "tester-off", "tester-refused"]) assert.equal(busExit(code), 3, code);
|
||||
assert.equal(busExit("tester-prefix"), 2);
|
||||
});
|
||||
|
||||
test("with no stand-in transport, --tester runs tester-cli.mjs on the data root's socket", async (t) => {
|
||||
|
||||
Reference in new issue
Block a user