// Row 164: switching CLI chat off never gates the core management verbs. import test from "node:test"; import assert from "node:assert/strict"; import { run } from "../src/cli.mjs"; import { io, tmp } from "./helpers.mjs"; function setup(t, selected) { const calls = []; const deps = { system: { dataRoot: tmp(t, "channel-cli-") }, transport: () => async (verb, args = {}) => { calls.push([verb, args]); if (verb === "plugins") return { business: "demo", revision: "a".repeat(64), plugins: selected === undefined ? {} : { channel: selected } }; if (["project.list", "thread.list"].includes(verb)) return []; assert.fail("unexpected operation " + verb); } }; return { calls, async cli(argv) { const x = io(); return { code: await run([...argv, "--business", "demo"], x, deps), out: x.out.text, err: x.err.text }; } }; } test("CLI off, absent and other-only channel selections refuse every project/thread flow before any effect", async t => { for (const selected of [[], undefined, ["webui"]]) { const s = setup(t, selected); for (const argv of [["project", "list"], ["project", "create", "work"], ["threads"], ["thread", "read", "stack/chat"], ["thread", "open", "stack/chat"], ["thread", "create", "stack", "chat"], ["talk", "--thread", "stack/chat", "hello", "--wait", "0"], ["follow", "--thread", "stack/chat"]]) { s.calls.length = 0; const result = await s.cli(argv); assert.equal(result.code, 3, argv.join(" ")); assert.match(result.err, /mosaic plugins.*mosaic plugins set/s); assert.match(result.err, /plugins\.channel/); assert.ok(result.err.includes('Pass --business "demo" to both commands.')); assert.match(result.err, /cli.*webui/); assert.equal(result.out, ""); assert.deepEqual(s.calls, [["plugins", {}]]); } } }); test("CLI enabled project/thread lists dispatch through selection without changing output", async t => { const s = setup(t, ["cli"]); assert.deepEqual(await s.cli(["project", "list"]), { code: 0, out: "no projects\n", err: "" }); assert.deepEqual(s.calls, [["plugins", {}], ["project.list", {}]]); s.calls.length = 0; assert.deepEqual(await s.cli(["threads"]), { code: 0, out: "no threads\n", err: "" }); assert.deepEqual(s.calls, [["plugins", {}], ["thread.list", {}]]); });