bus, cli: a tester message to a role nobody holds refuses tester-target-not-running, and talk --tester exits 3 (row 170, #1667)

This commit is contained in:
dewey authored and Jason Woltje committed 2026-10-19 13:59:15 -05:00
1 parent 228aeb5037
commit cb43dcb45e
6 files changed
+123 -16

No files matched your search

+8 -4
View File
@@ -127,8 +127,8 @@ mosaic launches list [--json]
when the bus told `launch.by`; `pm isn't running, and the business names
no launch.by` with no launch block; `pm isn't running and isn't in the
launch block, so chief can't launch it` when the role isn't one of
`launch.instances` (row 152, #1646); `pm isn't running; a tester's message
tells nobody to launch it` for `--tester`. When `launch.by` itself isn't
`launch.instances` (row 152, #1646). A `--tester` message to such a role is
refused instead (see `--tester` below). When `launch.by` itself isn't
running, talk prints `<launch.by> isn't running` (or `isn't running
either` after the told line, but not after the launch-block line) and the
command that starts it:
@@ -168,8 +168,12 @@ mosaic launches list [--json]
(`tester-off`), each exit 3. Like the human commands, `--tester` works
only from the tree the bus runs from ("One pinned copy" below).
`talk --tester` text must start with
`[mos test]`, else exit 2 before any call. The role's reply comes back to
the tester, not to the human's inbox. `decide`, `stop`, `launches` and
`[mos test]`, else exit 2 before any call. When no run holds the role
(row 170, #1667), the bus refuses the message with
`tester-target-not-running` and stores nothing, and talk prints `pm isn't
running, so the tester's message was refused and nothing was stored` and
exits 3. A run launched but not yet claimed counts as not running. The
role's reply comes back to the tester, not to the human's inbox. `decide`, `stop`, `launches` and
`inbox --read` or `--read-all` take no `--tester` (exit 4).
## The app
+5 -2
View File
@@ -339,8 +339,6 @@ function waitingLines(w, business) {
// Row 152 (#1646): launch.by can launch only launch.instances. An older bus sends no
// launchable, so only an explicit false prints this line.
if (w.launchable === false) return `${w.role} isn't running and isn't in the launch block, so ${w.launcher} can't launch it\n`;
// A human's message to another role always tells launch.by; a tester's never does.
if (!w.told) return `${w.role} isn't running; a tester's message tells nobody to launch it\n`;
return `${w.role} isn't running, ${w.launcher} has been told\n` + (w.launcherRunning ? "" : restart(w.launcher, " either"));
}
@@ -383,6 +381,11 @@ async function talk(rest, io, deps, receiveOnly = false) {
if (e.code === "thread-required-use-thread-send") {
throw new CliError(`${to} runs in threads, so a message to it names one: mosaic talk --thread <thread> <text>; mosaic threads lists yours`, 2);
}
// Row 170 (#1667): the bus stores no tester message to a role nobody holds. Exit 3 like the
// other tester refusals; transport.mjs's EXIT map stays as row 164 pinned it.
if (e.code === "tester-target-not-running" && parsed.flags.has("--tester")) {
throw new CliError(`${to} isn't running, so the tester's message was refused and nothing was stored`, 3);
}
throw e;
}
io.stdout.write(`sent ${shortId(sent.id)} to ${to}\n`);
+37 -5
View File
@@ -127,11 +127,43 @@ test("with no stand-in transport, --tester runs tester-cli.mjs on the data root'
assert.deepEqual(seen, [{ argv: [TESTER_CLI, join(dataRoot, "bus", "broker.sock")], input: { business: "demo", verb: "agents", args: {} } }]);
});
// Row 146 (#1640): a tester's message to a stopped role tells launch.by nothing, and talk says so.
test("talk --tester to a stopped role says nobody is told to launch it", async (t) => {
// Row 170 (#1667): the bus refuses a tester's message to a stopped role and stores nothing, and
// talk says so and exits 3.
test("talk --tester to a stopped role exits 3, prints no sent line and stores nothing", async (t) => {
const s = setup(t, { launch: { by: "pm", instances: ["cto", "coder"], models: {}, limits: {} } });
const x = inAgent();
await main(["talk", "cto", "[mos test] hello", "--tester", "--wait", "0", "--business", "demo"], x, s.deps);
assert.match(x.out.text, /^sent [0-9a-f-]{8} to cto\ncto isn't running; a tester's message tells nobody to launch it\n$/);
assert.equal(s.store.get("SELECT count(*) n FROM messages WHERE from_role='_bus'").n, 0);
await assert.rejects(main(["talk", "cto", "[mos test] hello", "--tester", "--wait", "0", "--business", "demo"], x, s.deps), (e) => {
assert.equal(e.exitCode, 3);
assert.equal(e.message, "cto isn't running, so the tester's message was refused and nothing was stored");
return true;
});
assert.equal(x.out.text, "");
assert.equal(s.store.get("SELECT count(*) n FROM messages").n, 0);
assert.deepEqual(s.calls.tester.map((c) => c.verb), ["message.send"]);
});
test("only a --tester send refused tester-target-not-running is rewritten", async (t) => {
const s = setup(t);
const refusing = (code) => () => async (verb) => {
const error = new Error(code);
error.code = code;
error.exitCode = 3;
throw error;
};
// Another refusal of a tester send keeps the bus's error.
for (const code of ["tester-off", "tester-required", "tester-refused", "unknown-role"]) {
const x = inAgent();
await assert.rejects(main(["talk", "cto", "[mos test] hello", "--tester", "--wait", "0", "--business", "demo"], x, { ...s.deps, testerTransport: refusing(code) }), (e) => {
assert.equal(e.code, code);
assert.equal(e.message, code);
return true;
}, code);
assert.equal(x.out.text, "");
}
// The human's send never gets the tester's line, whatever its transport says.
await assert.rejects(main(["talk", "cto", "hello", "--wait", "0", "--business", "demo"], io(humanEnv()), { ...s.deps, transport: refusing("tester-target-not-running") }), (e) => {
assert.equal(e.code, "tester-target-not-running");
assert.equal(e.message, "tester-target-not-running");
return true;
});
});