Completes t2db.8's remaining UI half. Mirrors ui/src/mappings/ exactly: bindings.jsx (list + editor), binding-editor.jsx (pure StatusPill/ BindingRow), bindings.css, wired into main.jsx's route table with a new icon. API helpers (bindingCreate/Update/Delete/Approve) added to api.jsx following the existing mapping* pattern. CRITICAL FIX, found via real browser verification (AGENTS.md's UI rule), not by inspection: every JSX-based page in this app -- dashboard, tasks, logs, captures, mappings, skills, workflows, memory, curators, channels, settings, and now bindings -- silently rendered the literal text "[object Object]" instead of its content. Root cause: main.jsx's router passed each page's Preact VNode into dom.jsx's mount()/append(), which only knows how to append real DOM Nodes or stringify everything else -- so a VNode object became exactly that string. Confirmed this predates tonight's work entirely: extracted and served the already-committed ui/dist bundle in isolation and reproduced the identical failure on the stock dashboard, unrelated to any change here. Fix: main.jsx's show() now detects a Preact VNode vs. a real DOM Node (the unused `soon: true`/comingSoon() fallback) and calls Preact's own render() for the former, leaving the generic mount() helper and its other four vanilla-DOM call sites untouched. Verified every single page renders correctly post-fix via a throwaway, fully-isolated webui.Server harness (temp SQLite, no real config/forge/network calls) driven by Playwright -- not assumed from the source diff alone. Also found and fixed a second real bug the same way: editing a binding without retyping its secret (the intended "leave blank to keep the current one" UX, matching UpdateBinding's own documented COALESCE contract) was rejected with 400, because the API handler validated edits with the create-time Validate(), which unconditionally required a full-length secret. Root-cause fix: split Binding.Validate() (create, unchanged) from a new ValidateForUpdate() (skips the length floor only when the secret is empty -- preserving the existing one -- still enforces it on a genuinely-supplied new secret). Full state machine (draft -> edit -> pending_approval -> approve -> armed -> delete) verified end-to-end in the browser afterward. Filed archie-core-mlro separately for the Pill component's pre-existing duplication across 11 files -- not fixed here, out of scope for this ticket, following this session's established discipline.
71 lines
2.9 KiB
JavaScript
71 lines
2.9 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { h } from "preact";
|
|
import { render } from "@testing-library/preact";
|
|
import { StatusPill, BindingRow } from "../src/bindings/binding-editor.jsx";
|
|
|
|
test("statusPill labels draft as idle", () => {
|
|
const { container } = render(h(StatusPill, { status: "draft" }));
|
|
assert.match(container.textContent, /draft/);
|
|
assert.ok(container.querySelector(".pill-idle"));
|
|
});
|
|
|
|
test("statusPill labels pending_approval as warn, with a human-readable label", () => {
|
|
const { container } = render(h(StatusPill, { status: "pending_approval" }));
|
|
assert.match(container.textContent, /pending approval/);
|
|
assert.ok(container.querySelector(".pill-warn"));
|
|
});
|
|
|
|
test("statusPill labels armed as ok", () => {
|
|
const { container } = render(h(StatusPill, { status: "armed" }));
|
|
assert.match(container.textContent, /armed/);
|
|
assert.ok(container.querySelector(".pill-ok"));
|
|
});
|
|
|
|
test("statusPill falls back to the raw status for an unrecognised value", () => {
|
|
const { container } = render(h(StatusPill, { status: "weird" }));
|
|
assert.match(container.textContent, /weird/);
|
|
});
|
|
|
|
test("bindingRow shows name, matcher source, workflow, and status", () => {
|
|
const { container } = render(h(BindingRow, {
|
|
binding: { id: 1, name: "sentry alerts", matcher: { source: "sentry" }, workflow: "implement", status: "draft" },
|
|
onEdit: () => {},
|
|
onApprove: () => {},
|
|
onDelete: () => {},
|
|
}));
|
|
assert.match(container.textContent, /sentry alerts/);
|
|
assert.match(container.textContent, /sentry/);
|
|
assert.match(container.textContent, /implement/);
|
|
assert.match(container.textContent, /draft/);
|
|
});
|
|
|
|
test("bindingRow shows the owner/repo pin when set, or a placeholder when not", () => {
|
|
const pinned = render(h(BindingRow, {
|
|
binding: { id: 1, name: "a", matcher: { source: "s" }, workflow: "implement", status: "draft", owner: "acme", repo: "widget" },
|
|
}));
|
|
assert.match(pinned.container.textContent, /acme\/widget/);
|
|
|
|
const unpinned = render(h(BindingRow, {
|
|
binding: { id: 2, name: "b", matcher: { source: "s" }, workflow: "implement", status: "draft" },
|
|
}));
|
|
assert.match(unpinned.container.textContent, /—/);
|
|
});
|
|
|
|
test("bindingRow shows an Approve action only when pending_approval", () => {
|
|
const pending = render(h(BindingRow, {
|
|
binding: { id: 1, name: "a", matcher: { source: "s" }, workflow: "implement", status: "pending_approval" },
|
|
}));
|
|
assert.match(pending.container.textContent, /Approve/);
|
|
|
|
const draft = render(h(BindingRow, {
|
|
binding: { id: 2, name: "b", matcher: { source: "s" }, workflow: "implement", status: "draft" },
|
|
}));
|
|
assert.doesNotMatch(draft.container.textContent, /Approve/);
|
|
|
|
const armed = render(h(BindingRow, {
|
|
binding: { id: 3, name: "c", matcher: { source: "s" }, workflow: "implement", status: "armed" },
|
|
}));
|
|
assert.doesNotMatch(armed.container.textContent, /Approve/);
|
|
});
|