Files
stack/packages/webui/tests/channel-chat.test.mjs
T
jason.woltjeandClaude Opus 5.5 008746b6ed plugins: channel kind for the CLI and Console chat paths (row 164, #1661)
Adds plugin kind `channel` (interfaceVersion 1, dispatch(request, {call}))
with cli and webui modules. Project and thread surfaces and thread
talk/follow in the CLI and the Console chat go through the selected
channel. An empty or absent channel selection is off: the CLI exits 3 and
the Console answers 503, each naming `mosaic plugins` and `mosaic plugins
set` with the business selector. Management plugins and plugins.set stay
on the core transport. The loader gains a synchronous snapshot(kind)
getter; loaded(), modules() and last-good handling are unchanged. No lock
is held across dispatch. serve.mjs, public/ and the bus are untouched.

Owner Rocko. Reviewer Dewey: r1 changes (comment 28980, B1: the recovery
sentence was never asserted), r2 approve (comment 28984) on candidate
manifest ae2fcfda...1fc8, the B1 assert killing mutant D1. Design accepted
by Mos (mos-0768, mos-0773). Fixture rewrite at project.test.mjs:47 acked
by Mos (mos-0789) on Dewey's line-by-line check: lines 48-51 identical,
one added assert. Sage gate on e5b10d275: 25 steps green, 2081 package tests, 156 queue node tests, 422 script selftests, 0 failed.

Live stays as pinned. The re-pin that takes this live puts `mosaic
plugins set` in Jason's window right after activate (mos-0768).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 14:24:42 -05:00

84 lines
3.9 KiB
JavaScript

// Row 164: the chat switch and fixed recovery message stay local to chat HTTP.
import test from "node:test";
import assert from "node:assert/strict";
import { request } from "node:http";
import { createChat } from "../src/chat.mjs";
import { startServer } from "../src/serve.mjs";
import { BusReadError } from "../src/bus.mjs";
import { close } from "./fixture.mjs";
const P = "10000000-0000-4000-8000-000000000001";
const T = "20000000-0000-4000-8000-000000000002";
const preview = { host: "chat.example.com", header: "remote-user", user: "jason" };
const headers = { host: preview.host, "remote-user": "jason", origin: "https://chat.example.com", "sec-fetch-site": "same-origin", "content-type": "application/json" };
function http(port, path, body) {
const raw = body === undefined ? undefined : JSON.stringify(body);
return new Promise((resolve, reject) => {
const req = request({ host: '127.0.0.1', port, path, method: raw === undefined ? 'GET' : 'POST',
headers: { ...headers, ...(raw === undefined ? {} : { 'content-length': Buffer.byteLength(raw) }) },
}, res => {
let text = '';
res.on('data', chunk => text += chunk);
res.on('end', () => resolve({ status: res.statusCode, data: JSON.parse(text) }));
});
req.on('error', reject); req.end(raw);
});
}
async function setup(t, selected) {
const calls = [], logs = [];
const chat = createChat({ call: async (verb, args) => {
calls.push([verb, args]);
if (verb === "plugins") return { business: "demo", revision: "a".repeat(64), plugins: selected === undefined ? {} : { channel: selected } };
return [];
} });
const server = await startServer({ port: 0, chat, preview, send: async () => ({}), log: line => logs.push(line) });
t.after(() => close(server));
return { calls, logs, async request(path, body) {
return http(server.address().port, path, body);
} };
}
test("WebUI channel off returns 503 and named recovery for every chat route without a chat operation", async t => {
for (const selected of [[], undefined, ["cli"]]) {
const s = await setup(t, selected);
for (const [path, body] of [
["/api/chat/projects"], ["/api/chat/threads"], [`/api/chat/threads/${T}/messages`],
["/api/chat/projects", { name: "work" }], ["/api/chat/threads", { project: P, name: "chat" }],
[`/api/chat/threads/${T}/messages`, { body: "private body" }], [`/api/chat/threads/${T}/open`, {}],
]) {
s.calls.length = 0;
const res = await s.request(path, body);
assert.equal(res.status, 503);
assert.equal(res.data.error, "channel-disabled");
assert.match(res.data.message, /mosaic plugins.*mosaic plugins set/s);
assert.match(res.data.message, /plugins\.channel/);
assert.match(res.data.message, /cli.*webui/);
if (body !== undefined) assert.equal(res.data.sent, false);
assert.deepEqual(s.calls, [["plugins", {}]]);
assert.doesNotMatch(JSON.stringify(res.data), /private body/);
}
}
});
test("WebUI only selection keeps web chat enabled while retaining the old read envelope", async t => {
const s = await setup(t, ["webui"]);
const res = await s.request("/api/chat/projects");
assert.equal(res.status, 200);
assert.deepEqual(res.data.rows, []);
assert.deepEqual(s.calls, [["plugins", {}], ["project.list", {}]]);
});
test("WebUI channel-disabled recovery text is fixed and never echoes transport text", async t => {
const chat = createChat({ call: async () => { throw new BusReadError("channel-disabled", "SENTINEL-private-input"); } });
const server = await startServer({ port: 0, chat, preview, send: async () => ({}), log: () => {} });
t.after(() => close(server));
const res = await http(server.address().port, '/api/chat/projects');
const result = res.data;
assert.equal(res.status, 503);
assert.equal(result.error, "channel-disabled");
assert.match(result.message, /mosaic plugins.*mosaic plugins set/s);
assert.doesNotMatch(JSON.stringify(result), /SENTINEL/);
});