test(maestro): give the SPA a test runner and a reachable pure core
ci / rust (pull_request) Successful in 2m28s
ci / web (pull_request) Successful in 23s
ci / web (push) Successful in 26s
ci / rust (push) Successful in 1m38s

The browser app had no tests and no way to run any: package.json shipped
dev/build/preview/typecheck, and CI installed Node and pnpm but never ran
anything with them. Its densest logic was module-private, so even with a
runner none of it was reachable.

Extracts four pure modules out of DOM-heavy ones — tree.ts (directory
grouping), keys.ts (terminal escape encoding), paths.ts (completion
arithmetic), html.ts (one escaper, replacing four copies). Extraction
rather than `export` because attach.ts imports xterm's CSS at module
level, which a node test cannot load.

CatalogStore takes an injectable socket factory, scheduler and refetch, so
the reducer and the backoff schedule run without a server. snapshot() now
returns a copy: it returned the live object while events mutated it in
place, so listeners could not diff and every event rebuilt the whole tree.

36 tests across 6 files, and a `web` CI job running typecheck, test and
build. vitest is pinned to 2.x — 4.x requires vite >= 6 and this is vite 5.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit was merged in pull request #44.
This commit is contained in:
Miguel Palhas
2026-08-22 14:08:14 +01:00
co-authored by Claude Opus 5
parent db44650a17
commit 031c80a40b
20 changed files with 1037 additions and 187 deletions
+6 -37
View File
@@ -3,6 +3,8 @@ import { Terminal } from "@xterm/xterm";
import "@xterm/xterm/css/xterm.css";
import { attachWsUrl } from "./routes.js";
import { escapeHtml } from "./html.js";
import { applyModsToChar, cursorSeq } from "./keys.js";
import type { ClientControl, Uuid } from "./types.js";
/**
@@ -44,14 +46,6 @@ export interface AttachInfo {
command: string;
}
function esc(s: string): string {
return s
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}
export function createAttachConnection(
sessionId: Uuid,
opts: AttachOptions = {},
@@ -62,16 +56,16 @@ export function createAttachConnection(
// Useful identity over a bare UUID: name · command. The full id stays in the
// tooltip for when you really need it.
const titleHtml = info
? `<span class="at-name">${esc(info.name)}</span>` +
? `<span class="at-name">${escapeHtml(info.name)}</span>` +
(info.command && info.command !== info.name
? `<span class="at-cmd">${esc(info.command)}</span>`
? `<span class="at-cmd">${escapeHtml(info.command)}</span>`
: "")
: `session <span class="sid">${esc(sessionId.slice(0, 8))}</span>`;
: `session <span class="sid">${escapeHtml(sessionId.slice(0, 8))}</span>`;
const titleAttr = info ? `${info.name} · ${info.command} (${sessionId})` : sessionId;
el.innerHTML = `
<header class="attach-header">
<a class="btn btn-ghost back" href="#/" aria-label="Back to catalog" title="Back to catalog">←</a>
<span class="attach-title" title="${esc(titleAttr)}">${titleHtml}</span>
<span class="attach-title" title="${escapeHtml(titleAttr)}">${titleHtml}</span>
<span class="attach-state" data-state="connecting">connecting…</span>
<button class="btn btn-ghost btn-icon disconnect" type="button" aria-label="Disconnect" title="Disconnect this session">⏻</button>
</header>
@@ -422,31 +416,6 @@ const KEY_DEFS: KeyDef[] = [
* Fold a single character into its control code: letters and `@[\]^_` map to
* 0x00–0x1f, space → NUL, `?` → DEL. Anything else is returned unchanged.
*/
function toCtrl(ch: string): string {
if (ch.length !== 1) return ch;
const upper = ch.toUpperCase().codePointAt(0) ?? 0;
if (upper >= 0x40 && upper <= 0x5f) return String.fromCodePoint(upper & 0x1f);
if (ch === " ") return "\x00";
if (ch === "?") return "\x7f";
return ch;
}
/** Apply pending modifiers to a single typed character: Ctrl → control code,
* Alt → ESC prefix (xterm meta). Both compose (Ctrl+Alt = ESC + control). */
function applyModsToChar(ch: string, ctrl: boolean, alt: boolean): string {
let out = ctrl ? toCtrl(ch) : ch;
if (alt) out = "\x1b" + out;
return out;
}
/** Cursor/nav-key sequence, promoted to the modified CSI form when Ctrl/Alt are
* pending — `\x1b[1;<n><final>`, n = 1 + alt(2) + ctrl(4) (xterm convention). */
function cursorSeq(final: string, ctrl: boolean, alt: boolean): string {
if (!ctrl && !alt) return `\x1b[${final}`;
const n = 1 + (alt ? 2 : 0) + (ctrl ? 4 : 0);
return `\x1b[1;${n}${final}`;
}
interface KeyBar {
readonly el: HTMLElement;
/** Fold pending modifiers into typed input (soft keyboard), consuming them. */