test(maestro): give the SPA a test runner and a reachable pure core
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:
co-authored by
Claude Opus 5
parent
db44650a17
commit
031c80a40b
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { hydrate } from "./persistence.js";
|
||||
import { leaves } from "./layout.js";
|
||||
|
||||
describe("hydrate", () => {
|
||||
it("rejects anything that is not a tab-bearing object", () => {
|
||||
expect(hydrate(null)).toBeNull();
|
||||
expect(hydrate("nope")).toBeNull();
|
||||
expect(hydrate({})).toBeNull();
|
||||
expect(hydrate({ tabs: [] })).toBeNull();
|
||||
expect(hydrate({ tabs: "no" })).toBeNull();
|
||||
});
|
||||
|
||||
it("rebuilds tabs and re-issues ids rather than trusting stored ones", () => {
|
||||
const layout = hydrate({
|
||||
tabs: [{ id: "old", title: "Work", root: { kind: "leaf", id: "l1", sessionId: "s1" } }],
|
||||
activeTabId: "old",
|
||||
});
|
||||
|
||||
expect(layout).not.toBeNull();
|
||||
expect(layout!.tabs).toHaveLength(1);
|
||||
expect(layout!.tabs[0].title).toBe("Work");
|
||||
expect(layout!.tabs[0].id).not.toBe("old");
|
||||
expect(layout!.activeTabId).toBe(layout!.tabs[0].id);
|
||||
expect(leaves(layout!.tabs[0].root)[0].sessionId).toBe("s1");
|
||||
});
|
||||
|
||||
it("carries the focused leaf across the id reissue", () => {
|
||||
const layout = hydrate({
|
||||
tabs: [
|
||||
{
|
||||
id: "t",
|
||||
root: {
|
||||
kind: "split",
|
||||
dir: "row",
|
||||
a: { kind: "leaf", id: "l1", sessionId: "s1" },
|
||||
b: { kind: "leaf", id: "l2", sessionId: "s2" },
|
||||
},
|
||||
focusedLeafId: "l2",
|
||||
},
|
||||
],
|
||||
activeTabId: "t",
|
||||
});
|
||||
|
||||
const tab = layout!.tabs[0];
|
||||
const focused = leaves(tab.root).find((l) => l.id === tab.focusedLeafId);
|
||||
expect(focused?.sessionId).toBe("s2");
|
||||
});
|
||||
|
||||
it("falls back to a default title and the first tab as active", () => {
|
||||
const layout = hydrate({ tabs: [{ id: "a" }, { id: "b" }], activeTabId: "missing" });
|
||||
expect(layout!.tabs[0].title).toBe("Tab 1");
|
||||
expect(layout!.activeTabId).toBe(layout!.tabs[0].id);
|
||||
});
|
||||
|
||||
it("drops a malformed split branch instead of failing the whole layout", () => {
|
||||
const layout = hydrate({
|
||||
tabs: [{ id: "t", root: { kind: "split", dir: "row", a: null, b: { kind: "leaf", id: "l", sessionId: "s" } } }],
|
||||
activeTabId: "t",
|
||||
});
|
||||
expect(leaves(layout!.tabs[0].root).map((l) => l.sessionId)).toEqual(["s"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user