Public: anyone can read this; the crew can change it.

Full suite red: test/tui-workspace.test.ts #12666

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/12636-full-suite-red-test-tui-workspace-test-t → main 1 commit fork

  • Merged. mason/12636-full-suite-red-test-tui-workspace-test-t was merged into main as c05d786.

Review

Sign in to review this change.
12 files changed +839 −764
docs/features/file-dockerfile.md +1 −1
@@ -9,4 +9,4 @@ A file named `Dockerfile`, `Containerfile` or `*.Dockerfile` (any case) opens as
99 - **Terminal:** the workspace screen opens a Dockerfile as a table (stage, instruction, arguments: the ports and ENV names first, then one row per instruction), with the same fallback reason; `s` shows the source.
1010 - Every value is escaped, drawn on the server; no script, no new CSS, no dependency.
1111
12 Code: `src/web/render/dockerfile.ts`, `src/web/render/kinds.ts`, `src/tui/screens/workspace.ts`. Test: `test/render-dockerfile.test.ts`, `test/tui-workspace.test.ts`.
12 Code: `src/web/render/dockerfile.ts`, `src/web/render/kinds.ts`, `src/tui/screens/workspace.ts`. Test: `test/render-dockerfile.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/file-env.md +1 −1
@@ -10,4 +10,4 @@ A file named exactly `.env.example`, `.env.sample` or `.env.template` opens as a
1010
1111 **Terminal:** the workspace opens the same table (`envTable` in `src/tui/screens/workspace.ts`, over the same `parseEnv`); `s` flips to the source.
1212
13 Code: `src/web/render/env.ts`, `src/web/render/kinds.ts`. Tests: `test/render-env.test.ts`, `test/tui-workspace.test.ts`.
13 Code: `src/web/render/env.ts`, `src/web/render/kinds.ts`. Tests: `test/render-env.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/file-junit.md +1 −1
@@ -11,4 +11,4 @@ Test runners (JUnit, pytest, vitest, Go via gotestsum) write JUnit XML. A file n
1111
1212 **Terminal:** opening such a file in the workspace shows a table of result, case and message, headed by a totals row (`junitTable` in `src/tui/screens/workspace.ts`, over the same `parseJunit`), "N failing cases" in the status line; `s` flips to the source. A file that is not a report opens as source with the same reason.
1313
14 Code: `src/web/render/junit.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-junit.test.ts`, `test/tui-workspace.test.ts`.
14 Code: `src/web/render/junit.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-junit.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/file-lcov.md +1 −1
@@ -11,4 +11,4 @@
1111
1212 **Terminal:** opening an lcov file in the workspace shows File, Lines, Functions and Branches, worst first, "N files" in the status line (`lcovTable` in `src/tui/screens/workspace.ts`, over the same `parseLcov`); `s` flips to the source.
1313
14 Code: `src/web/render/lcov.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-lcov.test.ts`, `test/tui-workspace.test.ts`.
14 Code: `src/web/render/lcov.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-lcov.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/file-openapi.md +1 −1
@@ -10,4 +10,4 @@
1010
1111 **Terminal:** the workspace opens it as Tag, Method, Path and Summary rows ("N operations" in the status line, deprecated in the summary), over the same `parseOpenApi`; `s` flips to the source.
1212
13 Code: `src/web/render/openapi.ts`, `src/web/render/kinds.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-openapi.test.ts`, `test/tui-workspace.test.ts`.
13 Code: `src/web/render/openapi.ts`, `src/web/render/kinds.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-openapi.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/file-package-json.md +1 −1
@@ -8,4 +8,4 @@ A file named exactly `package.json` opens as rows instead of raw text: name and
88
99 **Terminal:** the workspace opens the same rows (`packageTable` in `src/tui/screens/workspace.ts`, over the same `parsePackage`); `s` flips to the source.
1010
11 Code: `src/web/render/package-json.ts`, `src/web/render/kinds.ts`. Tests: `test/render-package-json.test.ts`, `test/tui-workspace.test.ts`.
11 Code: `src/web/render/package-json.ts`, `src/web/render/kinds.ts`. Tests: `test/render-package-json.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/file-sarif.md +1 −1
@@ -11,4 +11,4 @@ Security scanners (CodeQL, Semgrep, eslint) write SARIF. A `.sarif` file in a re
1111
1212 **Terminal:** opening a `.sarif` in the workspace shows a table of level, rule, location, message and tool (`sarifTable` in `src/tui/screens/workspace.ts`, over the same `parseSarif`), "N findings" in the status line; `s` flips to the source. Locations are text there.
1313
14 Code: `src/web/render/sarif.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-sarif.test.ts`, `test/tui-workspace.test.ts`.
14 Code: `src/web/render/sarif.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-sarif.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/file-workflow.md +1 −1
@@ -10,4 +10,4 @@ A file under `.github/workflows/` ending `.yml` or `.yaml` opens as what it does
1010 - **Terminal:** the workspace screen opens a workflow as a table (job, kind, value: triggers, then each job's runs-on, needs, matrix and steps), with the same fallback reason; `s` shows the source.
1111 - `${{ … }}` expressions show as written; nothing is evaluated. Every value is escaped, drawn on the server; no script, no new CSS, no dependency.
1212
13 Code: `src/web/render/workflow.ts`, `src/web/render/kinds.ts`, `src/tui/screens/workspace.ts`. Test: `test/render-workflow.test.ts`, `test/blob-workflow-page.test.ts`, `test/tui-workspace.test.ts`.
13 Code: `src/web/render/workflow.ts`, `src/web/render/kinds.ts`, `src/tui/screens/workspace.ts`. Test: `test/render-workflow.test.ts`, `test/blob-workflow-page.test.ts`, `test/tui-workspace-formats.test.ts`.
docs/features/html-preview.md +1 −1
@@ -6,4 +6,4 @@ How it is held: the frame points at the media route, which serves the file as `t
66
77 Layout: the frame is 80vh tall (60vh and 360px at least on a phone, 390px wide included), with one hairline and no card around it. It is `color-scheme: light`, so its canvas is white and the page inside looks the same in either theme. Fixed height, so nothing shifts.
88
9 Terminal (SSH): the file opens as its source, like any text file; the rendered page is a web-only door, because a terminal cannot draw a page. `test/tui-workspace.test.ts` holds that.
9 Terminal (SSH): the file opens as its source, like any text file; the rendered page is a web-only door, because a terminal cannot draw a page. `test/tui-workspace-formats.test.ts` holds that.
test/helpers/tui-workspace.ts added +129
@@ -0,0 +1,129 @@
1 /**
2 * The terminal workspace's shared fixture: a real forge in a temp directory,
3 * an admin named alice, and a headless TUI booted against it. Two suites
4 * (test/tui-workspace.test.ts, test/tui-workspace-formats.test.ts) share it so
5 * neither goes past the file budget.
6 */
7
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App as Forge } from "../../src/app.ts";
12 import type { User } from "../../src/core/users.ts";
13 import type { App } from "../../src/tui/app/app.ts";
14 import { createForgeApp } from "../../src/tui/forge.ts";
15 import type { TuiIdentity } from "../../src/tui/session.ts";
16 import { headlessTerminal, type HeadlessTerminal } from "../../src/tui/term/terminal.ts";
17 import { seedAdmin } from "./admin.ts";
18 import { settleApp, settleUntil } from "./tui.ts";
19
20 export interface Harness {
21 app: App;
22 terminal: HeadlessTerminal;
23 text(): string;
24 press(...keys: string[]): Promise<void>;
25 type(text: string): Promise<void>;
26 settle(): Promise<void>;
27 until(what: string): Promise<void>;
28 stop(): void;
29 }
30
31 export interface Fixture {
32 forge: Forge;
33 alice: User;
34 boot(identity?: TuiIdentity, cols?: number, rows?: number, term?: string): Harness;
35 open(h: Harness, name?: string): Promise<void>;
36 openFile(h: Harness, query: string): Promise<void>;
37 close(): Promise<void>;
38 }
39
40 export async function workspaceFixture(): Promise<Fixture> {
41 const dataDir = await mkdtemp(join(tmpdir(), "forge-tui-workspace-"));
42 const forge = createApp({ dataDir, port: 0 });
43 const a = await seedAdmin(forge, {
44 username: "alice",
45 email: "[email protected]",
46 password: "a-long-passphrase",
47 });
48 if (!a.ok) throw new Error("signup failed");
49 const alice = a.value;
50
51 const asAlice = (): TuiIdentity => ({
52 sshUsername: "alice",
53 remoteAddress: "127.0.0.1",
54 fingerprint: "SHA256:test",
55 user: alice,
56 });
57
58 function boot(
59 identity: TuiIdentity = asAlice(),
60 cols = 120,
61 rows = 40,
62 term?: string,
63 ): Harness {
64 const terminal = headlessTerminal(cols, rows, term);
65 const { app } = createForgeApp(forge, identity, {
66 terminal,
67 exitHooks: false,
68 });
69 app.start();
70 const settle = (): Promise<void> => settleApp(app);
71 const send = (key: string): void => {
72 const ctrl = key.startsWith("ctrl+");
73 const shift = key.startsWith("shift+");
74 app.dispatch({
75 type: "key",
76 key: ctrl ? key.slice(5) : shift ? key.slice(6) : key,
77 ctrl,
78 alt: false,
79 shift,
80 });
81 };
82 return {
83 app,
84 terminal,
85 text: () => app.screen.toText(),
86 async press(...keys) {
87 for (const key of keys) send(key);
88 await settle();
89 },
90 async type(text) {
91 for (const ch of text) send(ch);
92 await settle();
93 },
94 settle,
95 until: (what) => settleUntil(app, what),
96 stop: () => app.stop(),
97 };
98 }
99
100 /** Dashboard → this repository's workspace, by name rather than by row. */
101 async function open(h: Harness, name = "lighthouse"): Promise<void> {
102 await h.press("/");
103 await h.type(name);
104 await h.press("enter");
105 await h.press("enter");
106 await h.until(`alice/${name}`);
107 }
108
109 /** The finder is the deterministic way to a file: no row order to guess. */
110 async function openFile(h: Harness, query: string): Promise<void> {
111 await h.press("t");
112 await h.settle();
113 await h.type(query);
114 await h.press("enter");
115 await h.settle();
116 }
117
118 return {
119 forge,
120 alice,
121 boot,
122 open,
123 openFile,
124 async close() {
125 forge.close();
126 await rm(dataDir, { recursive: true, force: true });
127 },
128 };
129 }
test/tui-workspace-formats.test.ts added +689
@@ -0,0 +1,689 @@
1 /**
2 * The workspace opens a file by what it is: a table, its facts, its findings.
3 * Each test seeds its own repository and drives the headless TUI against it;
4 * the fixture is shared with test/tui-workspace.test.ts (split from it to keep
5 * both under the file budget).
6 */
7
8 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
9 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
10 import type { App as Forge } from "../src/app.ts";
11 import type { User } from "../src/core/users.ts";
12 import { quietLogs } from "./helpers/globals.ts";
13 import { workspaceFixture, type Fixture } from "./helpers/tui-workspace.ts";
14
15 quietLogs();
16
17 describe("the terminal workspace, by file type", () => {
18 let fx: Fixture;
19 let forge: Forge;
20 let alice: User;
21 let boot: Fixture["boot"];
22 let open: Fixture["open"];
23 let openFile: Fixture["openFile"];
24
25 beforeAll(async () => {
26 fx = await workspaceFixture();
27 ({ forge, alice, boot, open, openFile } = fx);
28 });
29
30 afterAll(() => fx.close());
31
32 test("a .csv opens as an aligned table with a pinned header, and s flips to the source", async () => {
33 const made = await createRepo(forge, alice, {
34 name: "ledger",
35 visibility: "public",
36 description: "numbers",
37 });
38 if (!made.ok) throw new Error("repo failed");
39 const rows = Array.from({ length: 80 }, (_, i) => `${i + 1},item ${i + 1}`);
40 await commitToBranch(forge, alice, made.value, {
41 message: "seed",
42 files: [
43 { path: "data.csv", content: ["id,name", ...rows, ""].join("\n") },
44 { path: "qty.tsv", content: "name, full\tqty\nwidget\t4\n" },
45 { path: "bad.csv", content: 'a,b\n1,"oops\n' },
46 ],
47 });
48 const h = boot();
49 try {
50 await h.settle();
51 await open(h, "ledger");
52 await openFile(h, "data.csv");
53 expect(h.text()).toContain("id │ name");
54 expect(h.text()).toContain("1 │ item 1");
55 expect(h.text()).toContain("80 rows");
56 await h.press("G");
57 expect(h.text()).toContain("id │ name");
58 expect(h.text()).toContain("80 │ item 80");
59 await h.press("s");
60 expect(h.text()).toContain("id,name");
61 expect(h.text()).not.toContain("│ item");
62 await h.press("s");
63 expect(h.text()).toContain("id │ name");
64
65 await openFile(h, "qty.tsv");
66 expect(h.text()).toContain("name, full │ qty");
67 expect(h.text()).toContain("widget");
68 expect(h.text()).toContain("1 row");
69
70 await openFile(h, "bad.csv");
71 expect(h.text()).toContain("a,b");
72 expect(h.text()).toContain("not a table: line 2");
73 } finally {
74 h.stop();
75 }
76 });
77
78 test("a .html file opens as its source: the page preview is a web-only door", async () => {
79 const made = await createRepo(forge, alice, { name: "pages", visibility: "public", description: "pages" });
80 if (!made.ok) throw new Error("repo failed");
81 await commitToBranch(forge, alice, made.value, {
82 message: "seed",
83 files: [{ path: "index.html", content: "<h1>hello page</h1>\n" }],
84 });
85 const h = boot();
86 try {
87 await h.settle();
88 await open(h, "pages");
89 await openFile(h, "index.html");
90 expect(h.text()).toContain("<h1>hello page</h1>");
91 } finally {
92 h.stop();
93 }
94 });
95
96 test("a .patch opens as the diff a pull shows, v flips to the source, a non-diff stays text", async () => {
97 const made = await createRepo(forge, alice, {
98 name: "patches",
99 visibility: "public",
100 description: "diffs",
101 });
102 if (!made.ok) throw new Error("repo failed");
103 const patch = [
104 "diff --git a/one.txt b/one.txt",
105 "--- a/one.txt",
106 "+++ b/one.txt",
107 "@@ -1,2 +1,2 @@",
108 " keep",
109 "-old line",
110 "+new line",
111 "",
112 ].join("\n");
113 await commitToBranch(forge, alice, made.value, {
114 message: "seed",
115 files: [
116 { path: "fix.patch", content: patch },
117 { path: "notes.diff", content: "just some notes\n" },
118 ],
119 });
120 const h = boot();
121 try {
122 await h.settle();
123 await open(h, "patches");
124 await openFile(h, "fix.patch");
125 expect(h.text()).toContain("one.txt");
126 expect(h.text()).toContain("new line");
127 expect(h.text()).not.toContain("diff --git");
128 await h.press("v");
129 expect(h.text()).toContain("diff --git a/one.txt b/one.txt");
130 await openFile(h, "notes.diff");
131 expect(h.text()).toContain("just some notes");
132 } finally {
133 h.stop();
134 }
135 });
136
137 test("a .srt opens as a Start/Text table sharing the web parser, and s flips to the source", async () => {
138 const made = await createRepo(forge, alice, {
139 name: "captions",
140 visibility: "public",
141 description: "subtitles",
142 });
143 if (!made.ok) throw new Error("repo failed");
144 await commitToBranch(forge, alice, made.value, {
145 message: "seed",
146 files: [
147 {
148 path: "talk.srt",
149 content:
150 "1\n00:00:01,500 --> 00:00:03,000\nHello <i>there</i>\n\n2\n00:00:0x --> nope\nBroken\n",
151 },
152 ],
153 });
154 const h = boot();
155 try {
156 await h.settle();
157 await open(h, "captions");
158 await openFile(h, "talk.srt");
159 expect(h.text()).toContain("Start");
160 expect(h.text()).toContain("00:00:01.500 │ Hello there");
161 expect(h.text()).toContain("1 cue");
162 expect(h.text()).toContain("1 unreadable, check their arrow lines");
163 await h.press("s");
164 expect(h.text()).toContain("00:00:01,500 --> 00:00:03,000");
165 } finally {
166 h.stop();
167 }
168 });
169
170 test("a .ics opens as a table of its events sharing the web parser, and s flips to the source", async () => {
171 const made = await createRepo(forge, alice, {
172 name: "calendars",
173 visibility: "public",
174 description: "events",
175 });
176 if (!made.ok) throw new Error("repo failed");
177 await commitToBranch(forge, alice, made.value, {
178 message: "seed",
179 files: [
180 {
181 path: "team.ics",
182 content:
183 "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20260301T090000Z\r\nSUMMARY:Planning\r\nLOCATION:Room 1\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
184 },
185 ],
186 });
187 const h = boot();
188 try {
189 await h.settle();
190 await open(h, "calendars");
191 await openFile(h, "team.ics");
192 expect(h.text()).toContain("Summary");
193 expect(h.text()).toContain("2026-03-01 09:00 UTC");
194 expect(h.text()).toContain("Planning");
195 expect(h.text()).toContain("1 event");
196 await h.press("s");
197 expect(h.text()).toContain("SUMMARY:Planning");
198 } finally {
199 h.stop();
200 }
201 });
202
203 test("a .vcf opens as a table of its contacts sharing the web parser, and s flips to the source", async () => {
204 const made = await createRepo(forge, alice, {
205 name: "people",
206 visibility: "public",
207 description: "contacts",
208 });
209 if (!made.ok) throw new Error("repo failed");
210 await commitToBranch(forge, alice, made.value, {
211 message: "seed",
212 files: [
213 {
214 path: "team.vcf",
215 content:
216 "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Ada Lovelace\r\nORG:Analytical\r\nEMAIL:[email protected]\r\nEND:VCARD\r\n",
217 },
218 ],
219 });
220 const h = boot();
221 try {
222 await h.settle();
223 await open(h, "people");
224 await openFile(h, "team.vcf");
225 expect(h.text()).toContain("Organisation");
226 expect(h.text()).toContain("Ada Lovelace");
227 expect(h.text()).toContain("[email protected]");
228 expect(h.text()).toContain("1 contact");
229 await h.press("s");
230 expect(h.text()).toContain("FN:Ada Lovelace");
231 } finally {
232 h.stop();
233 }
234 });
235
236 test("an .eml opens as its header rows and body, and s flips to the source", async () => {
237 const made = await createRepo(forge, alice, { name: "mail", visibility: "public", description: "mail" });
238 if (!made.ok) throw new Error("repo failed");
239 await commitToBranch(forge, alice, made.value, {
240 message: "seed",
241 files: [
242 {
243 path: "note.eml",
244 content: `From: Ada <[email protected]>\r\nSubject: Hello there\r\nDate: Mon, 1 Jan 2026 10:00:00 +0000\r\nContent-Type: multipart/mixed; boundary=BB\r\n\r\n--BB\r\nContent-Type: text/plain\r\n\r\nBody line one\r\n--BB\r\nContent-Type: application/pdf; name="r.pdf"\r\nContent-Transfer-Encoding: base64\r\n\r\n${Buffer.from("x".repeat(2048)).toString("base64")}\r\n--BB--\r\n`,
245 },
246 ],
247 });
248 const h = boot();
249 try {
250 await h.settle();
251 await open(h, "mail");
252 await openFile(h, "note.eml");
253 expect(h.text()).toContain("Subject");
254 expect(h.text()).toContain("Hello there");
255 expect(h.text()).toContain("Body line one");
256 expect(h.text()).toContain("2.0 KB");
257 await h.press("s");
258 expect(h.text()).toContain("From: Ada");
259 } finally {
260 h.stop();
261 }
262 });
263
264 test("a .gpx opens as its facts, sharing the web parser, and s flips to the source", async () => {
265 const made = await createRepo(forge, alice, {
266 name: "tracks",
267 visibility: "public",
268 description: "routes",
269 });
270 if (!made.ok) throw new Error("repo failed");
271 await commitToBranch(forge, alice, made.value, {
272 message: "seed",
273 files: [
274 {
275 path: "ride.gpx",
276 content:
277 '<gpx><trk><name>Morning ride</name><trkseg><trkpt lat="10" lon="20"><ele>100</ele></trkpt><trkpt lat="11" lon="20"><ele>150</ele></trkpt></trkseg></trk></gpx>',
278 },
279 ],
280 });
281 const h = boot();
282 try {
283 await h.settle();
284 await open(h, "tracks");
285 await openFile(h, "ride.gpx");
286 expect(h.text()).toContain("Morning ride");
287 expect(h.text()).toContain("111.2 km");
288 expect(h.text()).toContain("50 m");
289 expect(h.text()).toContain("4 facts");
290 await h.press("s");
291 expect(h.text()).toContain("<trkpt");
292 } finally {
293 h.stop();
294 }
295 });
296
297 test("a .sarif opens as its findings, sharing the web parser, and s flips to the source", async () => {
298 const made = await createRepo(forge, alice, { name: "scans", visibility: "public", description: "findings" });
299 if (!made.ok) throw new Error("repo failed");
300 const sarif = JSON.stringify({
301 version: "2.1.0",
302 runs: [{ tool: { driver: { name: "CodeQL" } }, results: [{ ruleId: "js/xss", level: "error", message: { text: "tainted value" }, locations: [{ physicalLocation: { artifactLocation: { uri: "src/a.ts" }, region: { startLine: 12 } } }] }] }],
303 });
304 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "scan.sarif", content: sarif }] });
305 const h = boot();
306 try {
307 await h.settle();
308 await open(h, "scans");
309 await openFile(h, "scan.sarif");
310 expect(h.text()).toContain("js/xss");
311 expect(h.text()).toContain("src/a.ts:12");
312 expect(h.text()).toContain("1 finding");
313 await h.press("s");
314 expect(h.text()).toContain("runs");
315 } finally {
316 h.stop();
317 }
318 });
319
320 test("a .sarif that is not SARIF opens as source and the status line says why", async () => {
321 const made = await createRepo(forge, alice, { name: "badscans", visibility: "public", description: "findings" });
322 if (!made.ok) throw new Error("repo failed");
323 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "scan.sarif", content: '{"version":"2.1.0"}' }] });
324 const h = boot();
325 try {
326 await h.settle();
327 await open(h, "badscans");
328 await openFile(h, "scan.sarif");
329 expect(h.text()).toContain('"version"');
330 expect(h.text()).toContain("not drawn as findings: it has no `runs` array");
331 } finally {
332 h.stop();
333 }
334 });
335
336 test("an lcov.info opens as coverage per file, worst first, and a broken one says why", async () => {
337 const made = await createRepo(forge, alice, { name: "covered", visibility: "public", description: "coverage" });
338 if (!made.ok) throw new Error("repo failed");
339 const info = "SF:src/good.ts\nLF:10\nLH:10\nend_of_record\nSF:src/bad.ts\nLF:4\nLH:1\nFNF:2\nFNH:1\nend_of_record\n";
340 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "lcov.info", content: info }, { path: "sub/lcov.info", content: "SF:x\n" }] });
341 const h = boot();
342 try {
343 await h.settle();
344 await open(h, "covered");
345 await openFile(h, "lcov.info");
346 expect(h.text()).toContain("1/4 25.0%");
347 expect(h.text()).toContain("2 files");
348 expect(h.text().indexOf("src/bad.ts")).toBeLessThan(h.text().indexOf("src/good.ts"));
349 } finally {
350 h.stop();
351 }
352 const broken = boot();
353 try {
354 await broken.settle();
355 await open(broken, "covered");
356 await openFile(broken, "sub/lcov.info");
357 expect(broken.text()).toContain("SF:x");
358 expect(broken.text()).toContain("not drawn as coverage: the record for x has no end_of_record");
359 } finally {
360 broken.stop();
361 }
362 });
363
364 test("an openapi.json opens as its operations, and s shows the source", async () => {
365 const made = await createRepo(forge, alice, { name: "apidoc", visibility: "public", description: "api" });
366 if (!made.ok) throw new Error("repo failed");
367 const spec = JSON.stringify({ openapi: "3.0.0", paths: { "/pets": { get: { tags: ["pets"], summary: "List pets" } }, "/old": { post: { summary: "Gone", deprecated: true } } } });
368 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "openapi.json", content: spec }] });
369 const h = boot();
370 try {
371 await h.settle();
372 await open(h, "apidoc");
373 await openFile(h, "openapi.json");
374 expect(h.text()).toContain("/pets");
375 expect(h.text()).toContain("List pets");
376 expect(h.text()).toContain("Gone (deprecated)");
377 expect(h.text()).toContain("2 operations");
378 await h.press("s");
379 expect(h.text()).toContain('"openapi":"3.0.0"');
380 } finally {
381 h.stop();
382 }
383 });
384
385 test("a Dockerfile opens as its stages, and s shows the source", async () => {
386 const made = await createRepo(forge, alice, { name: "dockerdoc", visibility: "public", description: "build" });
387 if (!made.ok) throw new Error("repo failed");
388 const df = "FROM oven/bun:1 AS build\nEXPOSE 3000\nENV TOKEN=abc\nRUN <<EOF\nbun install\nEOF\nFROM scratch\nCOPY --from=build /app /app\n";
389 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "Dockerfile", content: df }, { path: "sub/Containerfile", content: "RUN x\n" }] });
390 const h = boot();
391 try {
392 await h.settle();
393 await open(h, "dockerdoc");
394 await openFile(h, "Dockerfile");
395 expect(h.text()).toContain("oven/bun:1 as build");
396 expect(h.text()).toContain("3000");
397 expect(h.text()).toContain("TOKEN");
398 expect(h.text()).not.toContain("abc");
399 expect(h.text()).toContain("COPY");
400 expect(h.text()).toContain("instructions");
401 await h.press("s");
402 expect(h.text()).toContain("TOKEN=abc");
403 } finally {
404 h.stop();
405 }
406 });
407
408 test("a workflow opens as its jobs, a broken one says why, and s shows the source", async () => {
409 const made = await createRepo(forge, alice, { name: "flowdoc", visibility: "public", description: "ci" });
410 if (!made.ok) throw new Error("repo failed");
411 const wf = "on: [push]\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n ship:\n needs: build\n runs-on: ubuntu-latest\n steps:\n - run: bun test\n";
412 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: ".github/workflows/ci.yml", content: wf }, { path: ".github/workflows/bad.yml", content: "a: [\n" }] });
413 const h = boot();
414 try {
415 await h.settle();
416 await open(h, "flowdoc");
417 await openFile(h, ".github/workflows/ci.yml");
418 expect(h.text()).toContain("runs-on");
419 expect(h.text()).toContain("needs");
420 expect(h.text()).toContain("actions/checkout@v4");
421 expect(h.text()).toContain("bun test");
422 await h.press("s");
423 expect(h.text()).toContain("runs-on: ubuntu-latest");
424 } finally {
425 h.stop();
426 }
427 });
428
429 test("a .sql file opens as its columns, and s shows the source", async () => {
430 const made = await createRepo(forge, alice, { name: "sqlrepo", visibility: "public", description: "db" });
431 if (!made.ok) throw new Error("repo failed");
432 const sql = "CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT NOT NULL);\nCREATE INDEX idx ON users(email);";
433 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "db/schema.sql", content: sql }] });
434 const h = boot();
435 try {
436 await h.settle();
437 await open(h, "sqlrepo");
438 await openFile(h, "db/schema.sql");
439 expect(h.text()).toContain("users");
440 expect(h.text()).toContain("PRIMARY KEY");
441 expect(h.text()).toContain("NOT NULL");
442 expect(h.text()).toContain("CREATE INDEX idx");
443 await h.press("s");
444 expect(h.text()).toContain("CREATE TABLE users");
445 } finally {
446 h.stop();
447 }
448 });
449
450 test("a .graphql file opens as its types, roots first, and s shows the source", async () => {
451 const made = await createRepo(forge, alice, { name: "gqlrepo", visibility: "public", description: "api" });
452 if (!made.ok) throw new Error("repo failed");
453 const gql = 'type User @key(fields: "id") { id: ID! }\ntype Query { user(id: ID!): User }\nscalar Date';
454 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "api/schema.graphql", content: gql }] });
455 const h = boot();
456 try {
457 await h.settle();
458 await open(h, "gqlrepo");
459 await openFile(h, "api/schema.graphql");
460 const text = h.text();
461 expect(text).toContain("type Query");
462 expect(text).toContain("user");
463 expect(text).toContain("ID!");
464 expect(text).toContain("scalar Date");
465 expect(text.indexOf("type Query")).toBeLessThan(text.indexOf("type User"));
466 await h.press("s");
467 expect(h.text()).toContain("type Query {");
468 } finally {
469 h.stop();
470 }
471 });
472
473 test("a JUnit report opens as its totals and failing cases, sharing the web parser", async () => {
474 const made = await createRepo(forge, alice, { name: "junitrepo", visibility: "public", description: "tests" });
475 if (!made.ok) throw new Error("repo failed");
476 const xml = '<testsuite name="s"><testcase classname="m.A" name="ok"/><testcase classname="m.A" name="bad"><failure message="expected 1 got 2"/></testcase></testsuite>';
477 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-a.xml", content: xml }, { path: "TEST-b.xml", content: "<nope" }] });
478 const h = boot();
479 try {
480 await h.settle();
481 await open(h, "junitrepo");
482 await openFile(h, "TEST-a.xml");
483 expect(h.text()).toContain("1 of 2 tests fail");
484 expect(h.text()).toContain("m.A › bad");
485 expect(h.text()).toContain("expected 1 got 2");
486 expect(h.text()).toContain("1 failing case");
487 } finally {
488 h.stop();
489 }
490 });
491
492 test("a .env.example opens as a table with secrets masked, and s flips to the source", async () => {
493 const made = await createRepo(forge, alice, { name: "envrepo", visibility: "public", description: "tests" });
494 if (!made.ok) throw new Error("repo failed");
495 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: ".env.example", content: "# Port to listen on\nPORT=3000\nAPI_KEY=sk-live-abc\n" }] });
496 const h = boot();
497 try {
498 await h.settle();
499 await open(h, "envrepo");
500 await openFile(h, ".env.example");
501 expect(h.text()).toContain("Port to listen on");
502 expect(h.text()).toContain("•••");
503 expect(h.text()).not.toContain("sk-live-abc");
504 await h.press("s");
505 expect(h.text()).toContain("API_KEY=sk-live-abc");
506 } finally {
507 h.stop();
508 }
509 });
510
511 test("a package.json opens as rows of scripts and dependencies, and s flips to the source", async () => {
512 const made = await createRepo(forge, alice, { name: "pkgrepo", visibility: "public", description: "tests" });
513 if (!made.ok) throw new Error("repo failed");
514 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "package.json", content: '{"name":"demo","scripts":{"test":"bun test"},"dependencies":{"hono":"^4.0.0"}}' }] });
515 const h = boot();
516 try {
517 await h.settle();
518 await open(h, "pkgrepo");
519 await openFile(h, "package.json");
520 expect(h.text()).toContain("Dependencies");
521 expect(h.text()).toContain("^4.0.0");
522 await h.press("s");
523 expect(h.text()).toContain('"name":"demo"');
524 } finally {
525 h.stop();
526 }
527 });
528
529 test("a JUnit-named file that is not a report opens as source and says why", async () => {
530 const made = await createRepo(forge, alice, { name: "badjunit", visibility: "public", description: "tests" });
531 if (!made.ok) throw new Error("repo failed");
532 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-b.xml", content: "<root/>" }] });
533 const h = boot();
534 try {
535 await h.settle();
536 await open(h, "badjunit");
537 await openFile(h, "TEST-b.xml");
538 expect(h.text()).toContain("not drawn as test results");
539 } finally {
540 h.stop();
541 }
542 });
543
544 test("a .gcode opens as its facts, sharing the web parser, and s flips to the source", async () => {
545 const made = await createRepo(forge, alice, { name: "prints3d", visibility: "public", description: "slices" });
546 if (!made.ok) throw new Error("repo failed");
547 await commitToBranch(forge, alice, made.value, {
548 message: "seed",
549 files: [{ path: "cube.gcode", content: "G21\nG90\nM82\nG92 E0\nG1 Z0.2\nG1 X10 Y0 E1\nG1 X10 Y10 E2\nG1 Z0.4\nG1 X0 Y10 E3\n" }],
550 });
551 const h = boot();
552 try {
553 await h.settle();
554 await open(h, "prints3d");
555 await openFile(h, "cube.gcode");
556 expect(h.text()).toContain("Layers");
557 expect(h.text()).toContain("Bounding box");
558 expect(h.text()).toContain("3 mm");
559 await h.press("s");
560 expect(h.text()).toContain("G1 X10 Y0 E1");
561 } finally {
562 h.stop();
563 }
564 });
565
566 test("a .geojson opens as its features table, sharing the web parser, and s flips to the source", async () => {
567 const made = await createRepo(forge, alice, { name: "places", visibility: "public", description: "geo" });
568 if (!made.ok) throw new Error("repo failed");
569 await commitToBranch(forge, alice, made.value, {
570 message: "seed",
571 files: [
572 {
573 path: "p.geojson",
574 content:
575 '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":{"name":"Harbour"}}]}',
576 },
577 ],
578 });
579 const h = boot();
580 try {
581 await h.settle();
582 await open(h, "places");
583 await openFile(h, "p.geojson");
584 expect(h.text()).toContain("Harbour");
585 expect(h.text()).toContain("Point");
586 expect(h.text()).toContain("1 feature");
587 await h.press("s");
588 expect(h.text()).toContain("FeatureCollection");
589 } finally {
590 h.stop();
591 }
592 });
593
594 test("a .har opens as its requests table, sharing the web parser, and s flips to the source", async () => {
595 const made = await createRepo(forge, alice, { name: "captures", visibility: "public", description: "har" });
596 if (!made.ok) throw new Error("repo failed");
597 await commitToBranch(forge, alice, made.value, {
598 message: "seed",
599 files: [
600 {
601 path: "s.har",
602 content: JSON.stringify({
603 log: { entries: [{ startedDateTime: "2026-01-01T00:00:00Z", time: 1230, request: { method: "post", url: "https://example.test/api" }, response: { status: 201, content: { size: 2048 } } }] },
604 }),
605 },
606 { path: "bad.har", content: '{"log": {"entries": [1, ' },
607 ],
608 });
609 const h = boot();
610 try {
611 await h.settle();
612 await open(h, "captures");
613 // A malformed HAR is not a table: the workspace shows its source as it stands.
614 await openFile(h, "bad.har");
615 expect(h.text()).toContain('{"log": {"entries": [1,');
616 expect(h.text()).not.toContain("Method");
617 await openFile(h, "s.har");
618 expect(h.text()).toContain("POST");
619 expect(h.text()).toContain("201");
620 expect(h.text()).toContain("https://example.test/api");
621 expect(h.text()).toContain("1.23 s");
622 await h.press("s");
623 expect(h.text()).toContain("startedDateTime");
624 } finally {
625 h.stop();
626 }
627 });
628
629 test("tables: search, edit, the caps in the status line, a ; file, and s on a broken one", async () => {
630 const made = await createRepo(forge, alice, {
631 name: "sheets",
632 visibility: "public",
633 description: "more numbers",
634 });
635 if (!made.ok) throw new Error("repo failed");
636 const rows = Array.from({ length: 80 }, (_, i) => `${i + 1},item ${i + 1}`);
637 await commitToBranch(forge, alice, made.value, {
638 message: "seed",
639 files: [
640 { path: "data.csv", content: ["id,name", ...rows, ""].join("\n") },
641 { path: "semi.csv", content: "city;pop\nOslo;700\n" },
642 {
643 path: "wide.csv",
644 content: `${Array.from({ length: 70 }, (_, i) => `c${i}`).join(",")}\n1\n`,
645 },
646 {
647 path: "long.csv",
648 content: `n\n${Array.from({ length: 1100 }, (_, i) => i).join("\n")}\n`,
649 },
650 { path: "bad.csv", content: 'a,b\n1,"oops\n' },
651 ],
652 });
653 const h = boot();
654 try {
655 await h.settle();
656 await open(h, "sheets");
657
658 await openFile(h, "semi.csv");
659 expect(h.text()).toContain("city │ pop");
660 expect(h.text()).toContain("Oslo");
661
662 await openFile(h, "wide.csv");
663 expect(h.text()).toContain("6 more columns");
664
665 await openFile(h, "long.csv");
666 expect(h.text()).toContain("1100 rows, first 1000 shown");
667
668 await openFile(h, "data.csv");
669 expect(h.text()).not.toContain("item 70");
670 await h.press("/");
671 await h.type("item 70");
672 await h.press("enter");
673 expect(h.text()).toContain("70 │ item 70");
674
675 await h.press("e");
676 await h.press("esc");
677 expect(h.text()).toContain("70,item 70");
678 expect(h.text()).not.toContain("│ item");
679 await h.press("s");
680 expect(h.text()).toContain("id │ name");
681
682 await openFile(h, "bad.csv");
683 await h.press("s");
684 expect(h.text()).toContain("not a table: line 2");
685 } finally {
686 h.stop();
687 }
688 });
689 });
test/tui-workspace.test.ts +12 −755
@@ -15,28 +15,20 @@
1515 */
1616
1717 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
18 import { mkdtemp, rm } from "node:fs/promises";
19 import { tmpdir } from "node:os";
20 import { join } from "node:path";
2118 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
22 import { createApp, type App as Forge } from "../src/app.ts";
19 import type { App as Forge } from "../src/app.ts";
2320 import { audienceFor } from "../src/core/audience.ts";
2421 import { getMirrorTarget, recordMirrorPush, setMirrorTarget } from "../src/core/migrate_mirror.ts";
2522 import { getRepo, type Repo } from "../src/core/repos.ts";
2623 import { listPulls } from "../src/core/pulls.ts";
2724 import type { User } from "../src/core/users.ts";
25 import { join } from "node:path";
2826 import { blobForRender } from "../src/git/read.ts";
2927 import { listBranches } from "../src/git/branches.ts";
3028 import { quietLogs } from "./helpers/globals.ts";
31 import { App } from "../src/tui/app/app.ts";
32 import { createForgeApp } from "../src/tui/forge.ts";
29 import type { App } from "../src/tui/app/app.ts";
3330 import type { TuiIdentity } from "../src/tui/session.ts";
34 import {
35 headlessTerminal,
36 type HeadlessTerminal,
37 } from "../src/tui/term/terminal.ts";
38 import { settleApp, settleUntil } from "./helpers/tui.ts";
39 import { seedAdmin } from "./helpers/admin.ts";
31 import { workspaceFixture, type Fixture } from "./helpers/tui-workspace.ts";
4032
4133 quietLogs();
4234
@@ -70,23 +62,15 @@ function longBody(): string[] {
7062 );
7163 }
7264
73 interface Harness {
74 app: App;
75 terminal: HeadlessTerminal;
76 text(): string;
77 press(...keys: string[]): Promise<void>;
78 type(text: string): Promise<void>;
79 settle(): Promise<void>;
80 until(what: string): Promise<void>;
81 stop(): void;
82 }
83
8465 describe("the terminal workspace", () => {
85 let dataDir: string;
66 let fx: Fixture;
8667 let forge: Forge;
8768 let alice: User;
8869 let repo: Repo;
8970 let dir: string;
71 let boot: Fixture["boot"];
72 let open: Fixture["open"];
73 let openFile: Fixture["openFile"];
9074
9175 const asAlice = (): TuiIdentity => ({
9276 sshUsername: "alice",
@@ -95,76 +79,9 @@ describe("the terminal workspace", () => {
9579 user: alice,
9680 });
9781
98 function boot(
99 identity: TuiIdentity = asAlice(),
100 cols = 120,
101 rows = 40,
102 term?: string,
103 ): Harness {
104 const terminal = headlessTerminal(cols, rows, term);
105 const { app } = createForgeApp(forge, identity, {
106 terminal,
107 exitHooks: false,
108 });
109 app.start();
110 const settle = (): Promise<void> => settleApp(app);
111 const send = (key: string): void => {
112 const ctrl = key.startsWith("ctrl+");
113 const shift = key.startsWith("shift+");
114 app.dispatch({
115 type: "key",
116 key: ctrl ? key.slice(5) : shift ? key.slice(6) : key,
117 ctrl,
118 alt: false,
119 shift,
120 });
121 };
122 return {
123 app,
124 terminal,
125 text: () => app.screen.toText(),
126 async press(...keys) {
127 for (const key of keys) send(key);
128 await settle();
129 },
130 async type(text) {
131 for (const ch of text) send(ch);
132 await settle();
133 },
134 settle,
135 until: (what) => settleUntil(app, what),
136 stop: () => app.stop(),
137 };
138 }
139
140 /** Dashboard → this repository's workspace, by name rather than by row. */
141 async function open(h: Harness, name = "lighthouse"): Promise<void> {
142 await h.press("/");
143 await h.type(name);
144 await h.press("enter");
145 await h.press("enter");
146 await h.until(`alice/${name}`);
147 }
148
149 /** The finder is the deterministic way to a file: no row order to guess. */
150 async function openFile(h: Harness, query: string): Promise<void> {
151 await h.press("t");
152 await h.settle();
153 await h.type(query);
154 await h.press("enter");
155 await h.settle();
156 }
157
15882 beforeAll(async () => {
159 dataDir = await mkdtemp(join(tmpdir(), "forge-tui-workspace-"));
160 forge = createApp({ dataDir, port: 0 });
161 const a = await seedAdmin(forge, {
162 username: "alice",
163 email: "[email protected]",
164 password: "a-long-passphrase",
165 });
166 if (!a.ok) throw new Error("signup failed");
167 alice = a.value;
83 fx = await workspaceFixture();
84 ({ forge, alice, boot, open, openFile } = fx);
16885
16986 const made = await createRepo(forge, alice, {
17087 name: "lighthouse",
@@ -200,10 +117,7 @@ describe("the terminal workspace", () => {
200117 });
201118 });
202119
203 afterAll(async () => {
204 forge.close();
205 await rm(dataDir, { recursive: true, force: true });
206 });
120 afterAll(() => fx.close());
207121
208122 test("a mirror that stopped says why in the status line, and U stops mirroring", async () => {
209123 forge.db.run("PRAGMA foreign_keys = OFF");
@@ -263,664 +177,6 @@ describe("the terminal workspace", () => {
263177 }
264178 });
265179
266 test("a .csv opens as an aligned table with a pinned header, and s flips to the source", async () => {
267 const made = await createRepo(forge, alice, {
268 name: "ledger",
269 visibility: "public",
270 description: "numbers",
271 });
272 if (!made.ok) throw new Error("repo failed");
273 const rows = Array.from({ length: 80 }, (_, i) => `${i + 1},item ${i + 1}`);
274 await commitToBranch(forge, alice, made.value, {
275 message: "seed",
276 files: [
277 { path: "data.csv", content: ["id,name", ...rows, ""].join("\n") },
278 { path: "qty.tsv", content: "name, full\tqty\nwidget\t4\n" },
279 { path: "bad.csv", content: 'a,b\n1,"oops\n' },
280 ],
281 });
282 const h = boot();
283 try {
284 await h.settle();
285 await open(h, "ledger");
286 await openFile(h, "data.csv");
287 expect(h.text()).toContain("id │ name");
288 expect(h.text()).toContain("1 │ item 1");
289 expect(h.text()).toContain("80 rows");
290 await h.press("G");
291 expect(h.text()).toContain("id │ name");
292 expect(h.text()).toContain("80 │ item 80");
293 await h.press("s");
294 expect(h.text()).toContain("id,name");
295 expect(h.text()).not.toContain("│ item");
296 await h.press("s");
297 expect(h.text()).toContain("id │ name");
298
299 await openFile(h, "qty.tsv");
300 expect(h.text()).toContain("name, full │ qty");
301 expect(h.text()).toContain("widget");
302 expect(h.text()).toContain("1 row");
303
304 await openFile(h, "bad.csv");
305 expect(h.text()).toContain("a,b");
306 expect(h.text()).toContain("not a table: line 2");
307 } finally {
308 h.stop();
309 }
310 });
311
312 test("a .html file opens as its source: the page preview is a web-only door", async () => {
313 const made = await createRepo(forge, alice, { name: "pages", visibility: "public", description: "pages" });
314 if (!made.ok) throw new Error("repo failed");
315 await commitToBranch(forge, alice, made.value, {
316 message: "seed",
317 files: [{ path: "index.html", content: "<h1>hello page</h1>\n" }],
318 });
319 const h = boot();
320 try {
321 await h.settle();
322 await open(h, "pages");
323 await openFile(h, "index.html");
324 expect(h.text()).toContain("<h1>hello page</h1>");
325 } finally {
326 h.stop();
327 }
328 });
329
330 test("a .patch opens as the diff a pull shows, v flips to the source, a non-diff stays text", async () => {
331 const made = await createRepo(forge, alice, {
332 name: "patches",
333 visibility: "public",
334 description: "diffs",
335 });
336 if (!made.ok) throw new Error("repo failed");
337 const patch = [
338 "diff --git a/one.txt b/one.txt",
339 "--- a/one.txt",
340 "+++ b/one.txt",
341 "@@ -1,2 +1,2 @@",
342 " keep",
343 "-old line",
344 "+new line",
345 "",
346 ].join("\n");
347 await commitToBranch(forge, alice, made.value, {
348 message: "seed",
349 files: [
350 { path: "fix.patch", content: patch },
351 { path: "notes.diff", content: "just some notes\n" },
352 ],
353 });
354 const h = boot();
355 try {
356 await h.settle();
357 await open(h, "patches");
358 await openFile(h, "fix.patch");
359 expect(h.text()).toContain("one.txt");
360 expect(h.text()).toContain("new line");
361 expect(h.text()).not.toContain("diff --git");
362 await h.press("v");
363 expect(h.text()).toContain("diff --git a/one.txt b/one.txt");
364 await openFile(h, "notes.diff");
365 expect(h.text()).toContain("just some notes");
366 } finally {
367 h.stop();
368 }
369 });
370
371 test("a .srt opens as a Start/Text table sharing the web parser, and s flips to the source", async () => {
372 const made = await createRepo(forge, alice, {
373 name: "captions",
374 visibility: "public",
375 description: "subtitles",
376 });
377 if (!made.ok) throw new Error("repo failed");
378 await commitToBranch(forge, alice, made.value, {
379 message: "seed",
380 files: [
381 {
382 path: "talk.srt",
383 content:
384 "1\n00:00:01,500 --> 00:00:03,000\nHello <i>there</i>\n\n2\n00:00:0x --> nope\nBroken\n",
385 },
386 ],
387 });
388 const h = boot();
389 try {
390 await h.settle();
391 await open(h, "captions");
392 await openFile(h, "talk.srt");
393 expect(h.text()).toContain("Start");
394 expect(h.text()).toContain("00:00:01.500 │ Hello there");
395 expect(h.text()).toContain("1 cue");
396 expect(h.text()).toContain("1 unreadable, check their arrow lines");
397 await h.press("s");
398 expect(h.text()).toContain("00:00:01,500 --> 00:00:03,000");
399 } finally {
400 h.stop();
401 }
402 });
403
404 test("a .ics opens as a table of its events sharing the web parser, and s flips to the source", async () => {
405 const made = await createRepo(forge, alice, {
406 name: "calendars",
407 visibility: "public",
408 description: "events",
409 });
410 if (!made.ok) throw new Error("repo failed");
411 await commitToBranch(forge, alice, made.value, {
412 message: "seed",
413 files: [
414 {
415 path: "team.ics",
416 content:
417 "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20260301T090000Z\r\nSUMMARY:Planning\r\nLOCATION:Room 1\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
418 },
419 ],
420 });
421 const h = boot();
422 try {
423 await h.settle();
424 await open(h, "calendars");
425 await openFile(h, "team.ics");
426 expect(h.text()).toContain("Summary");
427 expect(h.text()).toContain("2026-03-01 09:00 UTC");
428 expect(h.text()).toContain("Planning");
429 expect(h.text()).toContain("1 event");
430 await h.press("s");
431 expect(h.text()).toContain("SUMMARY:Planning");
432 } finally {
433 h.stop();
434 }
435 });
436
437 test("a .vcf opens as a table of its contacts sharing the web parser, and s flips to the source", async () => {
438 const made = await createRepo(forge, alice, {
439 name: "people",
440 visibility: "public",
441 description: "contacts",
442 });
443 if (!made.ok) throw new Error("repo failed");
444 await commitToBranch(forge, alice, made.value, {
445 message: "seed",
446 files: [
447 {
448 path: "team.vcf",
449 content:
450 "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Ada Lovelace\r\nORG:Analytical\r\nEMAIL:[email protected]\r\nEND:VCARD\r\n",
451 },
452 ],
453 });
454 const h = boot();
455 try {
456 await h.settle();
457 await open(h, "people");
458 await openFile(h, "team.vcf");
459 expect(h.text()).toContain("Organisation");
460 expect(h.text()).toContain("Ada Lovelace");
461 expect(h.text()).toContain("[email protected]");
462 expect(h.text()).toContain("1 contact");
463 await h.press("s");
464 expect(h.text()).toContain("FN:Ada Lovelace");
465 } finally {
466 h.stop();
467 }
468 });
469
470 test("an .eml opens as its header rows and body, and s flips to the source", async () => {
471 const made = await createRepo(forge, alice, { name: "mail", visibility: "public", description: "mail" });
472 if (!made.ok) throw new Error("repo failed");
473 await commitToBranch(forge, alice, made.value, {
474 message: "seed",
475 files: [
476 {
477 path: "note.eml",
478 content: `From: Ada <[email protected]>\r\nSubject: Hello there\r\nDate: Mon, 1 Jan 2026 10:00:00 +0000\r\nContent-Type: multipart/mixed; boundary=BB\r\n\r\n--BB\r\nContent-Type: text/plain\r\n\r\nBody line one\r\n--BB\r\nContent-Type: application/pdf; name="r.pdf"\r\nContent-Transfer-Encoding: base64\r\n\r\n${Buffer.from("x".repeat(2048)).toString("base64")}\r\n--BB--\r\n`,
479 },
480 ],
481 });
482 const h = boot();
483 try {
484 await h.settle();
485 await open(h, "mail");
486 await openFile(h, "note.eml");
487 expect(h.text()).toContain("Subject");
488 expect(h.text()).toContain("Hello there");
489 expect(h.text()).toContain("Body line one");
490 expect(h.text()).toContain("2.0 KB");
491 await h.press("s");
492 expect(h.text()).toContain("From: Ada");
493 } finally {
494 h.stop();
495 }
496 });
497
498 test("a .gpx opens as its facts, sharing the web parser, and s flips to the source", async () => {
499 const made = await createRepo(forge, alice, {
500 name: "tracks",
501 visibility: "public",
502 description: "routes",
503 });
504 if (!made.ok) throw new Error("repo failed");
505 await commitToBranch(forge, alice, made.value, {
506 message: "seed",
507 files: [
508 {
509 path: "ride.gpx",
510 content:
511 '<gpx><trk><name>Morning ride</name><trkseg><trkpt lat="10" lon="20"><ele>100</ele></trkpt><trkpt lat="11" lon="20"><ele>150</ele></trkpt></trkseg></trk></gpx>',
512 },
513 ],
514 });
515 const h = boot();
516 try {
517 await h.settle();
518 await open(h, "tracks");
519 await openFile(h, "ride.gpx");
520 expect(h.text()).toContain("Morning ride");
521 expect(h.text()).toContain("111.2 km");
522 expect(h.text()).toContain("50 m");
523 expect(h.text()).toContain("4 facts");
524 await h.press("s");
525 expect(h.text()).toContain("<trkpt");
526 } finally {
527 h.stop();
528 }
529 });
530
531 test("a .sarif opens as its findings, sharing the web parser, and s flips to the source", async () => {
532 const made = await createRepo(forge, alice, { name: "scans", visibility: "public", description: "findings" });
533 if (!made.ok) throw new Error("repo failed");
534 const sarif = JSON.stringify({
535 version: "2.1.0",
536 runs: [{ tool: { driver: { name: "CodeQL" } }, results: [{ ruleId: "js/xss", level: "error", message: { text: "tainted value" }, locations: [{ physicalLocation: { artifactLocation: { uri: "src/a.ts" }, region: { startLine: 12 } } }] }] }],
537 });
538 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "scan.sarif", content: sarif }] });
539 const h = boot();
540 try {
541 await h.settle();
542 await open(h, "scans");
543 await openFile(h, "scan.sarif");
544 expect(h.text()).toContain("js/xss");
545 expect(h.text()).toContain("src/a.ts:12");
546 expect(h.text()).toContain("1 finding");
547 await h.press("s");
548 expect(h.text()).toContain("runs");
549 } finally {
550 h.stop();
551 }
552 });
553
554 test("a .sarif that is not SARIF opens as source and the status line says why", async () => {
555 const made = await createRepo(forge, alice, { name: "badscans", visibility: "public", description: "findings" });
556 if (!made.ok) throw new Error("repo failed");
557 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "scan.sarif", content: '{"version":"2.1.0"}' }] });
558 const h = boot();
559 try {
560 await h.settle();
561 await open(h, "badscans");
562 await openFile(h, "scan.sarif");
563 expect(h.text()).toContain('"version"');
564 expect(h.text()).toContain("not drawn as findings: it has no `runs` array");
565 } finally {
566 h.stop();
567 }
568 });
569
570 test("an lcov.info opens as coverage per file, worst first, and a broken one says why", async () => {
571 const made = await createRepo(forge, alice, { name: "covered", visibility: "public", description: "coverage" });
572 if (!made.ok) throw new Error("repo failed");
573 const info = "SF:src/good.ts\nLF:10\nLH:10\nend_of_record\nSF:src/bad.ts\nLF:4\nLH:1\nFNF:2\nFNH:1\nend_of_record\n";
574 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "lcov.info", content: info }, { path: "sub/lcov.info", content: "SF:x\n" }] });
575 const h = boot();
576 try {
577 await h.settle();
578 await open(h, "covered");
579 await openFile(h, "lcov.info");
580 expect(h.text()).toContain("1/4 25.0%");
581 expect(h.text()).toContain("2 files");
582 expect(h.text().indexOf("src/bad.ts")).toBeLessThan(h.text().indexOf("src/good.ts"));
583 } finally {
584 h.stop();
585 }
586 const broken = boot();
587 try {
588 await broken.settle();
589 await open(broken, "covered");
590 await openFile(broken, "sub/lcov.info");
591 expect(broken.text()).toContain("SF:x");
592 expect(broken.text()).toContain("not drawn as coverage: the record for x has no end_of_record");
593 } finally {
594 broken.stop();
595 }
596 });
597
598 test("an openapi.json opens as its operations, and s shows the source", async () => {
599 const made = await createRepo(forge, alice, { name: "apidoc", visibility: "public", description: "api" });
600 if (!made.ok) throw new Error("repo failed");
601 const spec = JSON.stringify({ openapi: "3.0.0", paths: { "/pets": { get: { tags: ["pets"], summary: "List pets" } }, "/old": { post: { summary: "Gone", deprecated: true } } } });
602 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "openapi.json", content: spec }] });
603 const h = boot();
604 try {
605 await h.settle();
606 await open(h, "apidoc");
607 await openFile(h, "openapi.json");
608 expect(h.text()).toContain("/pets");
609 expect(h.text()).toContain("List pets");
610 expect(h.text()).toContain("Gone (deprecated)");
611 expect(h.text()).toContain("2 operations");
612 await h.press("s");
613 expect(h.text()).toContain('"openapi":"3.0.0"');
614 } finally {
615 h.stop();
616 }
617 });
618
619 test("a Dockerfile opens as its stages, and s shows the source", async () => {
620 const made = await createRepo(forge, alice, { name: "dockerdoc", visibility: "public", description: "build" });
621 if (!made.ok) throw new Error("repo failed");
622 const df = "FROM oven/bun:1 AS build\nEXPOSE 3000\nENV TOKEN=abc\nRUN <<EOF\nbun install\nEOF\nFROM scratch\nCOPY --from=build /app /app\n";
623 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "Dockerfile", content: df }, { path: "sub/Containerfile", content: "RUN x\n" }] });
624 const h = boot();
625 try {
626 await h.settle();
627 await open(h, "dockerdoc");
628 await openFile(h, "Dockerfile");
629 expect(h.text()).toContain("oven/bun:1 as build");
630 expect(h.text()).toContain("3000");
631 expect(h.text()).toContain("TOKEN");
632 expect(h.text()).not.toContain("abc");
633 expect(h.text()).toContain("COPY");
634 expect(h.text()).toContain("instructions");
635 await h.press("s");
636 expect(h.text()).toContain("TOKEN=abc");
637 } finally {
638 h.stop();
639 }
640 });
641
642 test("a workflow opens as its jobs, a broken one says why, and s shows the source", async () => {
643 const made = await createRepo(forge, alice, { name: "flowdoc", visibility: "public", description: "ci" });
644 if (!made.ok) throw new Error("repo failed");
645 const wf = "on: [push]\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n ship:\n needs: build\n runs-on: ubuntu-latest\n steps:\n - run: bun test\n";
646 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: ".github/workflows/ci.yml", content: wf }, { path: ".github/workflows/bad.yml", content: "a: [\n" }] });
647 const h = boot();
648 try {
649 await h.settle();
650 await open(h, "flowdoc");
651 await openFile(h, ".github/workflows/ci.yml");
652 expect(h.text()).toContain("runs-on");
653 expect(h.text()).toContain("needs");
654 expect(h.text()).toContain("actions/checkout@v4");
655 expect(h.text()).toContain("bun test");
656 await h.press("s");
657 expect(h.text()).toContain("runs-on: ubuntu-latest");
658 } finally {
659 h.stop();
660 }
661 });
662
663 test("a .sql file opens as its columns, and s shows the source", async () => {
664 const made = await createRepo(forge, alice, { name: "sqlrepo", visibility: "public", description: "db" });
665 if (!made.ok) throw new Error("repo failed");
666 const sql = "CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT NOT NULL);\nCREATE INDEX idx ON users(email);";
667 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "db/schema.sql", content: sql }] });
668 const h = boot();
669 try {
670 await h.settle();
671 await open(h, "sqlrepo");
672 await openFile(h, "db/schema.sql");
673 expect(h.text()).toContain("users");
674 expect(h.text()).toContain("PRIMARY KEY");
675 expect(h.text()).toContain("NOT NULL");
676 expect(h.text()).toContain("CREATE INDEX idx");
677 await h.press("s");
678 expect(h.text()).toContain("CREATE TABLE users");
679 } finally {
680 h.stop();
681 }
682 });
683
684 test("a .graphql file opens as its types, roots first, and s shows the source", async () => {
685 const made = await createRepo(forge, alice, { name: "gqlrepo", visibility: "public", description: "api" });
686 if (!made.ok) throw new Error("repo failed");
687 const gql = 'type User @key(fields: "id") { id: ID! }\ntype Query { user(id: ID!): User }\nscalar Date';
688 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "api/schema.graphql", content: gql }] });
689 const h = boot();
690 try {
691 await h.settle();
692 await open(h, "gqlrepo");
693 await openFile(h, "api/schema.graphql");
694 const text = h.text();
695 expect(text).toContain("type Query");
696 expect(text).toContain("user");
697 expect(text).toContain("ID!");
698 expect(text).toContain("scalar Date");
699 expect(text.indexOf("type Query")).toBeLessThan(text.indexOf("type User"));
700 await h.press("s");
701 expect(h.text()).toContain("type Query {");
702 } finally {
703 h.stop();
704 }
705 });
706
707 test("a JUnit report opens as its totals and failing cases, sharing the web parser", async () => {
708 const made = await createRepo(forge, alice, { name: "junitrepo", visibility: "public", description: "tests" });
709 if (!made.ok) throw new Error("repo failed");
710 const xml = '<testsuite name="s"><testcase classname="m.A" name="ok"/><testcase classname="m.A" name="bad"><failure message="expected 1 got 2"/></testcase></testsuite>';
711 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-a.xml", content: xml }, { path: "TEST-b.xml", content: "<nope" }] });
712 const h = boot();
713 try {
714 await h.settle();
715 await open(h, "junitrepo");
716 await openFile(h, "TEST-a.xml");
717 expect(h.text()).toContain("1 of 2 tests fail");
718 expect(h.text()).toContain("m.A › bad");
719 expect(h.text()).toContain("expected 1 got 2");
720 expect(h.text()).toContain("1 failing case");
721 } finally {
722 h.stop();
723 }
724 });
725
726 test("a .env.example opens as a table with secrets masked, and s flips to the source", async () => {
727 const made = await createRepo(forge, alice, { name: "envrepo", visibility: "public", description: "tests" });
728 if (!made.ok) throw new Error("repo failed");
729 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: ".env.example", content: "# Port to listen on\nPORT=3000\nAPI_KEY=sk-live-abc\n" }] });
730 const h = boot();
731 try {
732 await h.settle();
733 await open(h, "envrepo");
734 await openFile(h, ".env.example");
735 expect(h.text()).toContain("Port to listen on");
736 expect(h.text()).toContain("•••");
737 expect(h.text()).not.toContain("sk-live-abc");
738 await h.press("s");
739 expect(h.text()).toContain("API_KEY=sk-live-abc");
740 } finally {
741 h.stop();
742 }
743 });
744
745 test("a package.json opens as rows of scripts and dependencies, and s flips to the source", async () => {
746 const made = await createRepo(forge, alice, { name: "pkgrepo", visibility: "public", description: "tests" });
747 if (!made.ok) throw new Error("repo failed");
748 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "package.json", content: '{"name":"demo","scripts":{"test":"bun test"},"dependencies":{"hono":"^4.0.0"}}' }] });
749 const h = boot();
750 try {
751 await h.settle();
752 await open(h, "pkgrepo");
753 await openFile(h, "package.json");
754 expect(h.text()).toContain("Dependencies");
755 expect(h.text()).toContain("^4.0.0");
756 await h.press("s");
757 expect(h.text()).toContain('"name":"demo"');
758 } finally {
759 h.stop();
760 }
761 });
762
763 test("a JUnit-named file that is not a report opens as source and says why", async () => {
764 const made = await createRepo(forge, alice, { name: "badjunit", visibility: "public", description: "tests" });
765 if (!made.ok) throw new Error("repo failed");
766 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-b.xml", content: "<root/>" }] });
767 const h = boot();
768 try {
769 await h.settle();
770 await open(h, "badjunit");
771 await openFile(h, "TEST-b.xml");
772 expect(h.text()).toContain("not drawn as test results");
773 } finally {
774 h.stop();
775 }
776 });
777
778 test("a .gcode opens as its facts, sharing the web parser, and s flips to the source", async () => {
779 const made = await createRepo(forge, alice, { name: "prints3d", visibility: "public", description: "slices" });
780 if (!made.ok) throw new Error("repo failed");
781 await commitToBranch(forge, alice, made.value, {
782 message: "seed",
783 files: [{ path: "cube.gcode", content: "G21\nG90\nM82\nG92 E0\nG1 Z0.2\nG1 X10 Y0 E1\nG1 X10 Y10 E2\nG1 Z0.4\nG1 X0 Y10 E3\n" }],
784 });
785 const h = boot();
786 try {
787 await h.settle();
788 await open(h, "prints3d");
789 await openFile(h, "cube.gcode");
790 expect(h.text()).toContain("Layers");
791 expect(h.text()).toContain("Bounding box");
792 expect(h.text()).toContain("3 mm");
793 await h.press("s");
794 expect(h.text()).toContain("G1 X10 Y0 E1");
795 } finally {
796 h.stop();
797 }
798 });
799
800 test("a .geojson opens as its features table, sharing the web parser, and s flips to the source", async () => {
801 const made = await createRepo(forge, alice, { name: "places", visibility: "public", description: "geo" });
802 if (!made.ok) throw new Error("repo failed");
803 await commitToBranch(forge, alice, made.value, {
804 message: "seed",
805 files: [
806 {
807 path: "p.geojson",
808 content:
809 '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":{"name":"Harbour"}}]}',
810 },
811 ],
812 });
813 const h = boot();
814 try {
815 await h.settle();
816 await open(h, "places");
817 await openFile(h, "p.geojson");
818 expect(h.text()).toContain("Harbour");
819 expect(h.text()).toContain("Point");
820 expect(h.text()).toContain("1 feature");
821 await h.press("s");
822 expect(h.text()).toContain("FeatureCollection");
823 } finally {
824 h.stop();
825 }
826 });
827
828 test("a .har opens as its requests table, sharing the web parser, and s flips to the source", async () => {
829 const made = await createRepo(forge, alice, { name: "captures", visibility: "public", description: "har" });
830 if (!made.ok) throw new Error("repo failed");
831 await commitToBranch(forge, alice, made.value, {
832 message: "seed",
833 files: [
834 {
835 path: "s.har",
836 content: JSON.stringify({
837 log: { entries: [{ startedDateTime: "2026-01-01T00:00:00Z", time: 1230, request: { method: "post", url: "https://example.test/api" }, response: { status: 201, content: { size: 2048 } } }] },
838 }),
839 },
840 { path: "bad.har", content: '{"log": {"entries": [1, ' },
841 ],
842 });
843 const h = boot();
844 try {
845 await h.settle();
846 await open(h, "captures");
847 // A malformed HAR is not a table: the workspace shows its source as it stands.
848 await openFile(h, "bad.har");
849 expect(h.text()).toContain('{"log": {"entries": [1,');
850 expect(h.text()).not.toContain("Method");
851 await openFile(h, "s.har");
852 expect(h.text()).toContain("POST");
853 expect(h.text()).toContain("201");
854 expect(h.text()).toContain("https://example.test/api");
855 expect(h.text()).toContain("1.23 s");
856 await h.press("s");
857 expect(h.text()).toContain("startedDateTime");
858 } finally {
859 h.stop();
860 }
861 });
862
863 test("tables: search, edit, the caps in the status line, a ; file, and s on a broken one", async () => {
864 const made = await createRepo(forge, alice, {
865 name: "sheets",
866 visibility: "public",
867 description: "more numbers",
868 });
869 if (!made.ok) throw new Error("repo failed");
870 const rows = Array.from({ length: 80 }, (_, i) => `${i + 1},item ${i + 1}`);
871 await commitToBranch(forge, alice, made.value, {
872 message: "seed",
873 files: [
874 { path: "data.csv", content: ["id,name", ...rows, ""].join("\n") },
875 { path: "semi.csv", content: "city;pop\nOslo;700\n" },
876 {
877 path: "wide.csv",
878 content: `${Array.from({ length: 70 }, (_, i) => `c${i}`).join(",")}\n1\n`,
879 },
880 {
881 path: "long.csv",
882 content: `n\n${Array.from({ length: 1100 }, (_, i) => i).join("\n")}\n`,
883 },
884 { path: "bad.csv", content: 'a,b\n1,"oops\n' },
885 ],
886 });
887 const h = boot();
888 try {
889 await h.settle();
890 await open(h, "sheets");
891
892 await openFile(h, "semi.csv");
893 expect(h.text()).toContain("city │ pop");
894 expect(h.text()).toContain("Oslo");
895
896 await openFile(h, "wide.csv");
897 expect(h.text()).toContain("6 more columns");
898
899 await openFile(h, "long.csv");
900 expect(h.text()).toContain("1100 rows, first 1000 shown");
901
902 await openFile(h, "data.csv");
903 expect(h.text()).not.toContain("item 70");
904 await h.press("/");
905 await h.type("item 70");
906 await h.press("enter");
907 expect(h.text()).toContain("70 │ item 70");
908
909 await h.press("e");
910 await h.press("esc");
911 expect(h.text()).toContain("70,item 70");
912 expect(h.text()).not.toContain("│ item");
913 await h.press("s");
914 expect(h.text()).toContain("id │ name");
915
916 await openFile(h, "bad.csv");
917 await h.press("s");
918 expect(h.text()).toContain("not a table: line 2");
919 } finally {
920 h.stop();
921 }
922 });
923
924180 test("moving in the explorer changes nothing in the file pane", async () => {
925181 const h = boot();
926182 try {
@@ -1511,3 +767,4 @@ async function commitCount(dir: string, ref: string): Promise<number> {
1511767 await proc.exited;
1512768 return Number(out.trim());
1513769 }
770

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs