// Removing or disabling every channel must leave the proved management writer usable. import test from "node:test"; import assert from "node:assert/strict"; import { writeFileSync, readFileSync } from "node:fs"; import { join } from "node:path"; import { provedRuntime } from "./channel-fixture.mjs"; test("both channels off recover through the existing human CLI, socket and organization writer", { timeout: 20000 }, async t => { const s = await provedRuntime(t); const off = await s.cli(["threads"]); assert.equal(off.status, 3, off.stderr); assert.match(off.stderr, /mosaic plugins.*mosaic plugins set/s); const view = await s.cli(["plugins", "--json"]); assert.equal(view.status, 0, view.stderr); const state = JSON.parse(view.stdout); assert.deepEqual(state.plugins.channel, []); const patch = join(s.root, "enable.json"); writeFileSync(patch, JSON.stringify({ revision: state.revision, plugins: { channel: ["cli", "webui"] } })); const done = await s.cli(["plugins", "set", "--file", patch]); assert.equal(done.status, 0, done.stderr); assert.deepEqual(JSON.parse(done.stdout).plugins.channel, ["cli", "webui"]); assert.deepEqual(JSON.parse(readFileSync(s.file, "utf8")).plugins.channel, ["cli", "webui"]); const receipt = s.history().at(-1); assert.equal(receipt.actor, "jason"); assert.equal(receipt.state, "committed"); const threads = await s.cli(["threads"]); assert.deepEqual([threads.status, threads.stdout, threads.stderr], [0, "no threads\n", ""]); const before = readFileSync(s.file, "utf8"); const stale = await s.cli(["plugins", "set", "--file", patch]); assert.notEqual(stale.status, 0); assert.match(stale.stderr, /revision-conflict/); assert.equal(readFileSync(s.file, "utf8"), before); // Removing the key is also off, and does not remove the recovery read path. const now = JSON.parse((await s.cli(["plugins"])).stdout); writeFileSync(patch, JSON.stringify({ revision: now.revision, plugins: { channel: null } })); assert.equal((await s.cli(["plugins", "set", "--file", patch])).status, 0); assert.equal((await s.cli(["threads"])).status, 3); assert.equal((await s.cli(["plugins"])).status, 0); });