row 183 (#1681): chat.mjs names the transport it is given
The chat.mjs header comment now says the seam takes the bus transport it is given: the human one from the signed-in listener, the tester one from the row 176 listener (row 177). The TypeError for a missing or non-function call says 'chat needs a bus transport function' and no longer says human. No behavior changes. The webui README doesn't repeat either phrase and is unchanged. A new chat.test.mjs test passes undefined, null, a string, a number, an object, an array and no call, and reads the new TypeError text. Putting the old text back fails it. Dewey approved round 1 in #1681 comment 29376. Their notes (the tester line names no file, and the test title says both transports pass when only a stand-in function does) need no change.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
// Row 129: the single seam between Console chat operations and the current human transport.
|
||||
// Row 129: the single seam between Console chat operations and the bus transport it is given.
|
||||
// The signed-in listener passes the human transport (cli.mjs, `chat = createChat({ call })`); the row 176
|
||||
// tester listener passes the tester transport (row 177, `createChat({ call })` over TESTER_CLI).
|
||||
// No browser-selected bus verb, tenant, owner, capability or message class crosses this seam.
|
||||
import { createChannelCaller } from '../../plugins/src/channel.mjs';
|
||||
import { PluginError } from '../../plugins/src/kinds.mjs';
|
||||
import { BusReadError } from './bus.mjs';
|
||||
|
||||
export function createChat({ call }) {
|
||||
if (typeof call !== 'function') throw new TypeError('chat needs a human transport');
|
||||
if (typeof call !== 'function') throw new TypeError('chat needs a bus transport function');
|
||||
const dispatch = createChannelCaller({ name: 'webui', call });
|
||||
const channel = async (verb, args) => {
|
||||
try { return await dispatch(verb, args); }
|
||||
|
||||
@@ -318,3 +318,12 @@ test('chat assets, GET purity, method and unknown-route refusals are explicit',
|
||||
assert.equal((await c.get('/api/chat/projects', { method:'DELETE' })).status, 405);
|
||||
assert.deepEqual(c.calls, []);
|
||||
});
|
||||
|
||||
test('the chat seam names the transport it is given: the human one and the tester one both pass, anything else is a TypeError', () => {
|
||||
// Row 177 hands chat the tester transport too, so the refusal must not call it a human transport.
|
||||
for (const call of [undefined, null, 'call', 42, {}, []]) {
|
||||
assert.throws(() => createChat({ call }), err => err instanceof TypeError && err.message === 'chat needs a bus transport function', String(call));
|
||||
}
|
||||
assert.throws(() => createChat({}), { name: 'TypeError', message: 'chat needs a bus transport function' });
|
||||
assert.equal(typeof createChat({ call: async () => ({}) }).projects, 'function');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user