Files
openrig-studio/test/floor-surface.test.mjs
T
Mike Schwarz 652d2980b5 FLOOR: finished work, and find by id (#1)
A person looking at a rig's floor can now see its finished work, with each item's answer first in plain words, and find an item by id. Coverage is honest: a bounded or unreadable read says so instead of claiming there's nothing. An artifact reference wraps without changing its text.

Six files (+291/-8): the floor page and server, the runtime contract, and tests. Source-only entry; no tag, pin, release or deploy.
2026-10-23 01:45:42 -07:00

88 lines
4.3 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const SURFACE = path.join(REPO, "app", "surfaces", "floor.html");
const surface = fs.readFileSync(SURFACE, "utf8");
test("FLOOR renders seats and queue as semantic tables instead of cards", () => {
assert.match(surface, /<title>Rig Floor<\/title>/, "positive control: loaded the FLOOR surface");
assert.equal((surface.match(/<table\b/g) || []).length, 3, "seats, queue and finished work");
for (const heading of ["Seat", "Pod / member", "State", "Lifecycle", "Age", "Pending"]) {
assert.match(surface, new RegExp(`<th[^>]*>${heading.replace(" / ", " \\/ ")}<\\/th>`, "i"));
}
for (const heading of ["Work", "State", "Source", "Destination"]) {
assert.match(surface, new RegExp(`<th[^>]*>${heading}<\\/th>`, "i"));
}
assert.doesNotMatch(surface, /<article class="seat\b/);
assert.doesNotMatch(surface, /<article class="queue-item\b/);
});
test("FLOOR keeps detached states distinct and always marks them down", () => {
const start = surface.indexOf("if (state.attached === false)");
const end = surface.indexOf("rig.textContent = state.rig", start);
assert.notEqual(start, -1, "detached-state branch exists");
assert.notEqual(end, -1, "attached-state branch follows detached handling");
const detached = surface.slice(start, end);
assert.match(detached, /'no-rig': 'No rig is running on this box\.'/);
assert.match(detached, /'no-rig-cli': 'The rig CLI is not installed on this box\.'/);
assert.match(detached, /'rig-error': 'The rig is installed but could not be read\.'/);
assert.match(detached, /setConnection\('down'/);
assert.doesNotMatch(detached, /setConnection\('live'/);
});
test("FLOOR keeps its declared welcome and delegated agent launcher", () => {
assert.match(surface, /fetch\('\/surfaces\.json'/);
assert.match(surface, /welcome = d && typeof d\.welcome === 'object'/);
assert.match(surface, /content\.addEventListener\('click'/);
assert.match(surface, /parent\.postMessage\(\{ t: 'open-agent', seat: b\.dataset\.seat \}/);
});
test("FLOOR defines every visual token used by the declared welcome", () => {
const root = surface.match(/:root\s*\{([\s\S]*?)\}/)?.[1] ?? "";
assert.match(root, /--text\s*:/, "positive control: the root token block was not read");
for (const token of ["edge2", "body", "faint", "bone"]) {
assert.match(root, new RegExp(`--${token}\\s*:`), `welcome token --${token} is undefined`);
}
});
test("FLOOR keeps the all-rig caption and live-to-polling refresh path", () => {
assert.match(surface, /rig\.textContent = state\.rig/);
assert.match(surface, /new EventSource\('\/api\/events'\)/);
assert.match(surface, /setConnection\('polling', 'polling fallback'\)/);
assert.match(surface, /setInterval\(refresh, 15000\)/);
});
// ---- the agent panel renders a configured-but-stopped member honestly -------
// The roster carries a per-seat `status`. The shell used to ignore it and render
// every row as the same enabled, attachable button, so a member that was down
// looked identical to one that was running until you clicked it.
const SHELL = fs.readFileSync(path.join(REPO, "app", "shell.html"), "utf8");
test("a non-running seat is rendered as unattachable rather than dropped", () => {
assert.match(SHELL, /\.seatTile\.down/, "positive control: the down style was not found");
assert.match(SHELL, /b\.disabled = !running/, "a stopped member is still clickable");
assert.match(SHELL, /so there is no session to attach to/, "the tile does not say WHY it is unavailable");
});
test("an absent status is treated as attachable, so a hand-declared roster is not greyed out", () => {
// The over-correction to avoid: a consumer that declares {seat, name} rows by
// hand supplies no status, and treating unknown as down would grey out every
// seat on the honest path.
assert.match(SHELL, /s\.status === undefined \|\| s\.status === "running"/);
});
test("the panel does not default its selection onto a seat it cannot attach to", () => {
assert.match(SHELL, /const firstUp = seats\.find\(canAttach\)/,
"selection still takes seats[0] blind, which lands on a stopped member");
});