TESTER_VERBS gains usage, names, limits, plugins, instances, project.list, thread.list, name.set and project.create. A tester reads limits, plugins and instances and sends 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, bus start and stop included. project init --tester checks the project area, refuses the area root itself, binds the tester with one agents read, then commits the layout as tester (mos-0872 Q2). scripts/mosaic sends plugins, name, names, follow, threads and thread to packages/cli (sage-1081). The row 164 pins are untouched. Built by Dewey on9e74925c2(three commits to 989699f7c, manifest 2e30f2a1...29d5f), approved by Filbert in round 3 (#1673 comment 29279), Sage's gate green on716ddcf1eplus the patch.
60 lines
2.5 KiB
JavaScript
60 lines
2.5 KiB
JavaScript
// Row 141 (#1635, REQ-MSG-2): `mosaic name` and `mosaic names`, through the in-process broker from
|
|
// helpers.mjs. The broker's own checks are in packages/bus/tests/names.test.mjs.
|
|
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { main, USAGE } from "../src/cli.mjs";
|
|
import { CliError } from "../src/errors.mjs";
|
|
import { broker, io, tmp } from "./helpers.mjs";
|
|
|
|
function setup(t) {
|
|
const bus = broker(t);
|
|
const dataRoot = tmp(t);
|
|
const run = async (argv, x = io()) => {
|
|
try {
|
|
await main(argv, x, { system: { dataRoot }, transport: bus.transport });
|
|
return { code: 0, io: x };
|
|
} catch (e) {
|
|
if (!(e instanceof CliError)) throw e;
|
|
return { code: e.exitCode, error: e.message, io: x };
|
|
}
|
|
};
|
|
return { ...bus, run };
|
|
}
|
|
|
|
test("the human names an instance, lists it, and talk's message.send reaches it by that name", async (t) => {
|
|
const s = setup(t);
|
|
const named = await s.run(["name", "coder", "rex", "--business", "demo"]);
|
|
assert.equal(named.code, 0, named.error);
|
|
assert.equal(named.io.out.text, "named coder rex\n");
|
|
assert.deepEqual(s.calls.at(-1), { business: "demo", verb: "name.set", args: { instance: "coder", name: "rex" } });
|
|
|
|
const listed = await s.run(["names", "--business", "demo"]);
|
|
assert.equal(listed.code, 0, listed.error);
|
|
assert.equal(listed.io.out.text, "coder rex\n");
|
|
const json = await s.run(["names", "--json", "--business", "demo"]);
|
|
assert.deepEqual(
|
|
JSON.parse(json.io.out.text).map(({ instance, name }) => ({ instance, name })),
|
|
[{ instance: "coder", name: "rex" }],
|
|
);
|
|
|
|
const sent = await s.run(["talk", "rex", "hello", "--wait", "0", "--business", "demo"]);
|
|
assert.equal(sent.code, 0, sent.error);
|
|
assert.match(sent.io.out.text, /^sent [0-9a-f]{8} to rex\n/);
|
|
const [m] = s.b.request(s.coder, { verb: "message.receive" });
|
|
assert.equal(m.to_role, "coder");
|
|
assert.equal(m.to_name, "rex");
|
|
});
|
|
|
|
test("name and names refuse the wrong number of arguments with the usage", async (t) => {
|
|
const s = setup(t);
|
|
for (const argv of [["name", "coder"], ["name", "coder", "rex", "extra"], ["names", "coder"]]) {
|
|
const r = await s.run([...argv, "--business", "demo"]);
|
|
assert.equal(r.code, 4, argv.join(" "));
|
|
assert.ok(r.error.endsWith(USAGE), r.error);
|
|
}
|
|
assert.equal(s.calls.length, 0);
|
|
assert.match(USAGE, /^ {2}mosaic name <instance> <name> \[--business <id>\] \[--tester\]$/m);
|
|
assert.match(USAGE, /^ {2}mosaic names \[--business <id>\] \[--json\] \[--tester\]$/m);
|
|
});
|