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
+1 -20
View File
@@ -12,6 +12,7 @@
//
// Failures (offline daemon, permission denied) degrade to no suggestions.
import { longestCommonPrefix, splitPath } from "./paths.js";
import { listDir } from "./api.js";
export interface DirAutocompleteHandle {
@@ -26,26 +27,6 @@ const FETCH_DEBOUNCE_MS = 90;
/** Split a path value into the directory to list and the trailing fragment
* being typed within it. The directory keeps its trailing `/` (or is empty,
* meaning "the daemon's home dir"). */
function splitPath(value: string): { dir: string; prefix: string } {
const slash = value.lastIndexOf("/");
if (slash === -1) return { dir: "", prefix: value };
return { dir: value.slice(0, slash + 1), prefix: value.slice(slash + 1) };
}
/** Longest common prefix of a list of strings (case-sensitive, preserving the
* actual on-disk casing). */
function longestCommonPrefix(items: string[]): string {
if (items.length === 0) return "";
let lcp = items[0];
for (const s of items.slice(1)) {
let i = 0;
while (i < lcp.length && i < s.length && lcp[i] === s[i]) i++;
lcp = lcp.slice(0, i);
if (lcp === "") break;
}
return lcp;
}
export function attachDirAutocomplete(input: HTMLInputElement): DirAutocompleteHandle {
const dropdown = document.createElement("ul");
dropdown.className = "dir-ac";