Files
archie/ui/test/harness.test.ts
T
sam 5e1623f82f feat(webui): the harness settings page and its setup terminal
A Settings > Runtime page lists every credential binding with the capture
state of its OAuth token set (expiry, scopes, time; never the tokens), and
offers the setup terminal for the Kit profiles the daemon advertises. The
terminal is xterm.js over the WebSocket the harness route upgrades, lazy
loaded so xterm stays out of the shell bundle. The page reports the
terminal as unavailable when the process cannot open one, rather than
offering a control that fails (archie-core-egkf.7).

Wire shapes and URL building live in ui/src/harness/harness.ts and are
covered by ui/test/harness.test.ts; ui/dist is regenerated.
2026-10-02 09:42:26 +10:00

76 lines
2.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
bindingStatus,
setupTerminalURL,
EXPIRING_WINDOW_MS,
} from "../src/harness/harness.ts";
import type { HarnessBinding } from "../src/harness/harness.ts";
const now = Date.parse("2026-10-02T12:00:00Z");
function binding(overrides: Partial<HarnessBinding> = {}): HarnessBinding {
return { service: "github", captured: false, ...overrides };
}
test("an uncaptured binding reads as unconfigured", () => {
assert.equal(bindingStatus(binding(), now), "unconfigured");
});
test("a captured binding with a future expiry reads as ready", () => {
assert.equal(
bindingStatus(
binding({ captured: true, expires_at: "2026-10-02T13:00:00Z" }),
now,
),
"ready",
);
});
test("a captured binding inside the expiring window reads as expiring", () => {
const almost = new Date(now + EXPIRING_WINDOW_MS - 1000).toISOString();
assert.equal(
bindingStatus(binding({ captured: true, expires_at: almost }), now),
"expiring",
);
});
test("a captured binding past its expiry reads as expired", () => {
assert.equal(
bindingStatus(
binding({ captured: true, expires_at: "2026-10-02T11:00:00Z" }),
now,
),
"expired",
);
});
test("a capture with no parseable expiry counts as ready, not expired", () => {
// The provider did not tell archie when the token lapses; treating that as
// expired would be a guess, and the wrong one.
assert.equal(
bindingStatus(binding({ captured: true }), now),
"ready",
);
assert.equal(
bindingStatus(binding({ captured: true, expires_at: "not-a-date" }), now),
"ready",
);
});
test("the terminal URL upgrades the scheme and carries the profile", () => {
assert.equal(
setupTerminalURL("claude-kit", { protocol: "http:", host: "127.0.0.1:8484" }),
"ws://127.0.0.1:8484/api/harness/terminal?profile=claude-kit",
);
});
test("an https dashboard opens awss terminal", () => {
assert.equal(
setupTerminalURL("claude kit", { protocol: "https:", host: "archie.example" }),
"wss://archie.example/api/harness/terminal?profile=claude+kit",
);
});