Files
archie/ui/test/captures.test.js
T
sam a8f9f1b339 feat(webui): event inspector -- see captured payloads in the dashboard
Adds GET /api/captures (token-gated, matching the memory/skills
enabled-false-not-an-error convention when Server.Captures is nil) and a
new dashboard page at /captures listing recent inbound captures, newest
first, with per-row expand to explore the redacted payload and headers
pretty-printed.

Live updates reuse the existing operator-activity event pipeline
(Server.emit -> Events.Publish -> the /events SSE stream every other page
already subscribes to) rather than polling or inventing new push
plumbing: handleCapture now emits a Kind "capture" event with the same
field shape the list endpoint returns, so a captured event appears in the
inspector without a manual refresh.

Frontend follows the tasks/task-row.js precedent: row rendering is split
into ui/src/captures/capture-row.js so it can be unit tested without the
page's fetch/SSE wiring.

"Unbound" is shown for every row today since no binding data model exists
yet (t2db.4) -- the column is wired now so that bead only needs to change
what it renders, not add it.
2026-08-22 05:10:27 +10:00

66 lines
2.5 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import "./shim.js";
import { captureRow, captureDetailRow, prettyPrint } from "../src/captures/capture-row.js";
test("prettyPrint indents valid JSON", () => {
const out = prettyPrint('{"action":"opened","n":1}');
assert.equal(out, JSON.stringify({ action: "opened", n: 1 }, null, 2));
});
test("prettyPrint returns non-JSON payloads unchanged rather than failing", () => {
assert.equal(prettyPrint("not json"), "not json");
});
test("collapsed capture row renders only the summary row", () => {
const nodes = captureRow(
{ id: 1, source: "github", content_type: "application/json" },
{ expanded: false, onToggle: () => {} },
);
assert.equal(nodes.length, 1);
});
test("expanded capture row appends a detail row", () => {
const nodes = captureRow(
{ id: 1, source: "github", content_type: "application/json" },
{ expanded: true, onToggle: () => {} },
);
assert.equal(nodes.length, 2);
});
test("capture row reflects expanded state via aria-expanded", () => {
const [collapsedRow] = captureRow({ id: 1 }, { expanded: false, onToggle: () => {} });
const [expandedRow] = captureRow({ id: 1 }, { expanded: true, onToggle: () => {} });
assert.equal(collapsedRow.getAttribute("aria-expanded"), "false");
assert.equal(expandedRow.getAttribute("aria-expanded"), "true");
});
test("capture row shows the source and content type", () => {
const [row] = captureRow(
{ id: 1, source: "github", content_type: "application/json" },
{ expanded: false, onToggle: () => {} },
);
assert.match(row.textContent, /github/);
assert.match(row.textContent, /application\/json/);
});
test("capture row shows an unknown source as a placeholder rather than blank", () => {
const [row] = captureRow({ id: 1 }, { expanded: false, onToggle: () => {} });
assert.match(row.textContent, /\(unknown\)/);
});
test("every capture row shows Unbound: no binding data model exists yet (t2db.4)", () => {
const [row] = captureRow({ id: 1, source: "github" }, { expanded: false, onToggle: () => {} });
assert.match(row.textContent, /Unbound/);
});
test("capture detail row pretty-prints a JSON payload", () => {
const detail = captureDetailRow({ body: '{"a":1}', headers: "{}" });
assert.match(detail.textContent, /"a": 1/);
});
test("capture detail row shows a placeholder for an empty payload", () => {
const detail = captureDetailRow({ body: "", headers: "" });
assert.match(detail.textContent, /\(empty\)/);
});