open-standards/wai/wai-studio/test/palette.test.mjs
Transaction Science f85a0a7273 WAI Studio on the web: one front end, its core in WebAssembly, served by wai dev at /_wai/
wai/wai-studio: the panels (Inspect, Verify and receipts, Encode/decode/package, Rooms,
Run, Quantum) and the command palette; actions generated from the operation catalogue
with a drift check; the core (wai-studio-core) binding the wai crate for the tab. wai dev
serves Studio at /_wai/ on its own origin, with the dev stack's routes for it under
/_wai/api/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 15:22:51 -04:00

51 lines
2.3 KiB
JavaScript

// The command palette's "where it runs", from the catalogue and Studio's bindings, on each host.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { ACTIONS } from '../src/actions.generated.js';
import { BINDINGS, PANELS, runs } from '../src/bindings.js';
import { where, whereText } from '../src/palette.js';
const byId = (id) => ACTIONS.find((a) => a.id === id);
test('every operation of the catalogue is in the palette, by its id', () => {
const ids = ACTIONS.map((a) => a.id);
assert.equal(new Set(ids).size, ids.length);
for (const a of ACTIONS) assert.match(a.id, /^[a-z0-9]+\.[a-z0-9]+$/);
});
test('an operation this host runs opens its panel, and one panel the host does not show is never opened', () => {
for (const host of ['hosted', 'local']) {
for (const [id, b] of Object.entries(BINDINGS)) {
const a = byId(id);
if (!a) continue;
const w = where(a, host);
if (b[host]) {
const p = PANELS.find((x) => x.id === b.panel);
assert.ok(p.hosts.includes(host), `${id} runs in ${p.id}, which ${host} shows`);
assert.equal(w.panel, b.panel);
assert.match(whereText(a, host), /^Runs here/);
} else {
assert.equal(w.here, null, `${id} on ${host}`);
}
}
}
});
test('an operation that runs elsewhere says where, from the catalogue', () => {
// A command line and an MCP tool.
assert.match(whereText(byId('toolchain.test'), 'hosted'), /Runs elsewhere: wai hello/);
assert.match(whereText(byId('dev.stop'), 'local'), /wai mcp, tool dev_stop/);
// A route of the room service: through wai dev, on the local host.
assert.match(whereText(byId('room.grant'), 'local'), /wai dev at POST \/room-api\/grant/);
assert.match(whereText(byId('room.grant'), 'hosted'), /wai-room: POST \/grant/);
// What runs only through wai dev, seen from the hosted Studio.
assert.match(whereText(byId('dev.start'), 'hosted'), /Studio served by wai dev, at \/_wai\//);
// Placed for the browser, run from the command line.
assert.match(whereText(byId('receipt.fetch'), 'hosted'), /wai http receipts/);
assert.equal(runs('receipt.fetch', 'hosted'), null);
});
test('the Run panel is the local host\'s alone', () => {
assert.deepEqual(PANELS.find((p) => p.id === 'run').hosts, ['local']);
assert.equal(where(byId('dev.start'), 'local').panel, 'run');
});