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 { return { service: "github", captured: false, ...overrides }; } test("credential status distinguishes uncaptured, ready, expiring and expired bindings", () => { const cases: Array<[Partial, string]> = [ [{}, "unconfigured"], [{ captured: true, expires_at: "2026-10-02T13:00:00Z" }, "ready"], [{ captured: true, expires_at: new Date(now + EXPIRING_WINDOW_MS - 1000).toISOString() }, "expiring"], [{ captured: true, expires_at: "2026-10-02T11:00:00Z" }, "expired"], [{ captured: true }, "ready"], [{ captured: true, expires_at: "not-a-date" }, "ready"], ]; for (const [overrides, expected] of cases) { assert.equal(bindingStatus(binding(overrides), now), expected, JSON.stringify(overrides)); } }); test("setup terminals preserve secure transport, encode the profile and carry the size", () => { const cases: Array<[string, Pick, number, number, string]> = [ [ "claude-kit", { protocol: "http:", host: "127.0.0.1:8484" }, 80, 24, "ws://127.0.0.1:8484/api/harness/terminal?profile=claude-kit&cols=80&rows=24", ], [ "claude kit", { protocol: "https:", host: "archie.example" }, 80, 24, "wss://archie.example/api/harness/terminal?profile=claude+kit&cols=80&rows=24", ], [ "claude-kit", { protocol: "https:", host: "archie.example" }, 120, 30, "wss://archie.example/api/harness/terminal?profile=claude-kit&cols=120&rows=30", ], ]; for (const [profile, location, cols, rows, expected] of cases) { assert.equal(setupTerminalURL(profile, location, cols, rows), expected, profile); } });