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

Full suite red: 2 files in check run 01m82pqag17019bak21s7c86a3 #15701

Merged opened this in answer to

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

Merged

torque/forge:torque/15672-full-suite-red-2-files-in-check-run-01m8 → main 0 commits fork

  • Merged. torque/15672-full-suite-red-2-files-in-check-run-01m8 was merged into main as 5da4b6f.

Review

Sign in to review this change.
6 files changed +487 −449
docs/features/file-env.md +1 −1
@@ -14,4 +14,4 @@ A file named exactly `.env.example`, `.env.sample` or `.env.template` opens as a
1414
1515 **Terminal:** the workspace opens the same table (`envTable` in `src/tui/screens/workspace.ts`, over the same `parseEnv`); `s` flips to the source.
1616
17 Code: `src/web/render/env.ts`, `src/web/render/kinds.ts`. Tests: `test/render-env.test.ts`, `test/tui-workspace-formats.test.ts`.
17 Code: `src/web/render/env.ts`, `src/web/render/kinds.ts`. Tests: `test/render-env.test.ts`, `test/tui-workspace-formats-more.test.ts`.
docs/features/file-junit.md +1 −1
@@ -15,4 +15,4 @@ Test runners (JUnit, pytest, vitest, Go via gotestsum) write JUnit XML. A file n
1515
1616 **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.
1717
18 Code: `src/web/render/junit.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-junit.test.ts`, `test/tui-workspace-formats.test.ts`.
18 Code: `src/web/render/junit.ts`, `src/tui/screens/workspace.ts`. Tests: `test/render-junit.test.ts`, `test/tui-workspace-formats-more.test.ts`.
docs/features/file-package-json.md +1 −1
@@ -12,4 +12,4 @@ A file named exactly `package.json` opens as rows instead of raw text: name and
1212
1313 **Terminal:** the workspace opens the same rows (`packageTable` in `src/tui/screens/workspace.ts`, over the same `parsePackage`); `s` flips to the source.
1414
15 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`.
15 Code: `src/web/render/package-json.ts`, `src/web/render/kinds.ts`. Tests: `test/render-package-json.test.ts`, `test/tui-workspace-formats-more.test.ts`.
test/chapter-next.test.ts +10 −9
@@ -78,16 +78,17 @@ const terminalNext = async () => {
7878 const terminal = headlessTerminal(140, 30);
7979 const { app: tui } = createForgeApp(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: owner }, { terminal, exitHooks: false });
8080 tui.start();
81 const send = async (key: string, ctrl = false) => {
82 tui.dispatch({ type: "key", key, ctrl, alt: false, shift: false });
83 await settleApp(tui);
84 };
81 const key = (k: string, ctrl = false) => tui.dispatch({ type: "key", key: k, ctrl, alt: false, shift: false });
82 // Typed ahead without a settle per character: the app drains its queue in order.
83 await settleApp(tui);
84 key("k", true);
85 await settleApp(tui);
86 for (const ch of "Next up in a repository") key(ch);
87 key("enter");
88 await settleApp(tui);
89 for (const ch of slug) key(ch);
90 key("enter");
8591 await settleApp(tui);
86 await send("k", true);
87 for (const ch of "Next up in a repository") await send(ch);
88 await send("enter");
89 for (const ch of slug) await send(ch);
90 await send("enter");
9192 const text = tui.screen.toText();
9293 tui.stop();
9394 return text;
test/tui-workspace-formats-more.test.ts added +474
@@ -0,0 +1,474 @@
1 /**
2 * The workspace opens a file by what it is, second half (split from
3 * test/tui-workspace-formats.test.ts to keep both under the file budget, #15672). Each test seeds
4 * its own repository and drives the headless TUI against it; the fixture is shared with
5 * test/tui-workspace.test.ts (split from it to keep both under the file budget).
6 */
7
8 import { Database } from "bun:sqlite";
9 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
10 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
11 import type { App as Forge } from "../src/app.ts";
12 import type { User } from "../src/core/users.ts";
13 import { zip } from "./helpers/zip.ts";
14 import { quietLogs } from "./helpers/globals.ts";
15 import { workspaceFixture, type Fixture } from "./helpers/tui-workspace.ts";
16
17 quietLogs();
18
19 describe("the terminal workspace, by file type", () => {
20 let fx: Fixture;
21 let forge: Forge;
22 let alice: User;
23 let boot: Fixture["boot"];
24 let open: Fixture["open"];
25 let openFile: Fixture["openFile"];
26
27 beforeAll(async () => {
28 fx = await workspaceFixture();
29 ({ forge, alice, boot, open, openFile } = fx);
30 });
31
32 afterAll(() => fx.close());
33
34 test("a .sql file opens as its columns, and s shows the source", async () => {
35 const made = await createRepo(forge, alice, { name: "sqlrepo", visibility: "public", description: "db" });
36 if (!made.ok) throw new Error("repo failed");
37 const sql = "CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT NOT NULL);\nCREATE INDEX idx ON users(email);";
38 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "db/schema.sql", content: sql }] });
39 const h = boot();
40 try {
41 await h.settle();
42 await open(h, "sqlrepo");
43 await openFile(h, "db/schema.sql");
44 expect(h.text()).toContain("users");
45 expect(h.text()).toContain("PRIMARY KEY");
46 expect(h.text()).toContain("NOT NULL");
47 expect(h.text()).toContain("CREATE INDEX idx");
48 await h.press("s");
49 expect(h.text()).toContain("CREATE TABLE users");
50 } finally {
51 h.stop();
52 }
53 });
54
55 test("a .graphql file opens as its types, roots first, and s shows the source", async () => {
56 const made = await createRepo(forge, alice, { name: "gqlrepo", visibility: "public", description: "api" });
57 if (!made.ok) throw new Error("repo failed");
58 const gql = 'type User @key(fields: "id") { id: ID! }\ntype Query { user(id: ID!): User }\nscalar Date';
59 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "api/schema.graphql", content: gql }] });
60 const h = boot();
61 try {
62 await h.settle();
63 await open(h, "gqlrepo");
64 await openFile(h, "api/schema.graphql");
65 const text = h.text();
66 expect(text).toContain("type Query");
67 expect(text).toContain("user");
68 expect(text).toContain("ID!");
69 expect(text).toContain("scalar Date");
70 expect(text.indexOf("type Query")).toBeLessThan(text.indexOf("type User"));
71 await h.press("s");
72 expect(h.text()).toContain("type Query {");
73 } finally {
74 h.stop();
75 }
76 });
77
78 test("a .mbox opens as its messages and a .proto as its outline", async () => {
79 const made = await createRepo(forge, alice, { name: "mboxrepo", visibility: "public", description: "m" });
80 if (!made.ok) throw new Error("repo failed");
81 const mb = "From [email protected] Mon Jan 1 00:00:00 2024\nFrom: Ann <[email protected]>\nSubject: Hello there\nDate: Mon, 1 Jan 2024\n\nbody\n";
82 const pr = 'syntax = "proto3";\nmessage Widget { string label = 1; }\n';
83 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "a.mbox", content: mb }, { path: "w.proto", content: pr }] });
84 const h = boot();
85 try {
86 await h.settle();
87 await open(h, "mboxrepo");
88 await openFile(h, "a.mbox");
89 expect(h.text()).toContain("Hello there");
90 await h.press("escape");
91 await openFile(h, "w.proto");
92 expect(h.text()).toContain("Widget");
93 expect(h.text()).toContain("label");
94 } finally {
95 h.stop();
96 }
97 });
98
99 test("an .ini, .rtf and plain .xml open as settings, paragraphs and an element tree", async () => {
100 const made = await createRepo(forge, alice, { name: "inirepo", visibility: "public", description: "i" });
101 if (!made.ok) throw new Error("repo failed");
102 const files = [
103 { path: "a.ini", content: "[core]\nname = Widget\napi_token = hunter2\n" },
104 { path: "n.rtf", content: "{\\rtf1\\ansi Hello rich world\\par}" },
105 { path: "d.xml", content: '<config><item id="7">first value</item></config>' },
106 ];
107 await commitToBranch(forge, alice, made.value, { message: "seed", files });
108 const h = boot();
109 try {
110 await h.settle();
111 await open(h, "inirepo");
112 await openFile(h, "a.ini");
113 expect(h.text()).toContain("Widget");
114 expect(h.text()).toContain("•••");
115 expect(h.text()).not.toContain("hunter2");
116 await h.press("escape");
117 await openFile(h, "n.rtf");
118 expect(h.text()).toContain("Hello rich world");
119 await h.press("escape");
120 await openFile(h, "d.xml");
121 expect(h.text()).toContain("config");
122 expect(h.text()).toContain('id="7"');
123 expect(h.text()).toContain("first value");
124 } finally {
125 h.stop();
126 }
127 });
128
129 test("a JUnit report opens as its totals and failing cases, sharing the web parser", async () => {
130 const made = await createRepo(forge, alice, { name: "junitrepo", visibility: "public", description: "tests" });
131 if (!made.ok) throw new Error("repo failed");
132 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>';
133 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-a.xml", content: xml }, { path: "TEST-b.xml", content: "<nope" }] });
134 const h = boot();
135 try {
136 await h.settle();
137 await open(h, "junitrepo");
138 await openFile(h, "TEST-a.xml");
139 expect(h.text()).toContain("1 of 2 tests fail");
140 expect(h.text()).toContain("m.A › bad");
141 expect(h.text()).toContain("expected 1 got 2");
142 expect(h.text()).toContain("1 failing case");
143 } finally {
144 h.stop();
145 }
146 });
147
148 test("an OPML file opens as its titles and links, sharing the web reader", async () => {
149 const made = await createRepo(forge, alice, { name: "opmlrepo", visibility: "public", description: "feeds" });
150 if (!made.ok) throw new Error("repo failed");
151 const opml = '<opml><body><outline text="News"><outline text="Wire" xmlUrl="https://e.com/f.xml"/></outline></body></opml>';
152 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "feeds.opml", content: opml }, { path: "bad.rss", content: "<nope" }] });
153 const h = boot();
154 try {
155 await h.settle();
156 await open(h, "opmlrepo");
157 await openFile(h, "feeds.opml");
158 expect(h.text()).toContain("– Wire");
159 expect(h.text()).toContain("https://e.com/f.xml");
160 await h.press("s");
161 expect(h.text()).toContain("<outline text=");
162 await h.press("q");
163 } finally {
164 h.stop();
165 }
166 });
167
168 test("a .env.example opens as a table with secrets masked, and s flips to the source", async () => {
169 const made = await createRepo(forge, alice, { name: "envrepo", visibility: "public", description: "tests" });
170 if (!made.ok) throw new Error("repo failed");
171 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" }] });
172 const h = boot();
173 try {
174 await h.settle();
175 await open(h, "envrepo");
176 await openFile(h, ".env.example");
177 expect(h.text()).toContain("Port to listen on");
178 expect(h.text()).toContain("•••");
179 expect(h.text()).not.toContain("sk-live-abc");
180 await h.press("s");
181 expect(h.text()).toContain("API_KEY=sk-live-abc");
182 } finally {
183 h.stop();
184 }
185 });
186
187 test("a package.json opens as rows of scripts and dependencies, and s flips to the source", async () => {
188 const made = await createRepo(forge, alice, { name: "pkgrepo", visibility: "public", description: "tests" });
189 if (!made.ok) throw new Error("repo failed");
190 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "package.json", content: '{"name":"demo","scripts":{"test":"bun test"},"dependencies":{"hono":"^4.0.0"}}' }] });
191 const h = boot();
192 try {
193 await h.settle();
194 await open(h, "pkgrepo");
195 await openFile(h, "package.json");
196 expect(h.text()).toContain("Dependencies");
197 expect(h.text()).toContain("^4.0.0");
198 await h.press("s");
199 expect(h.text()).toContain('"name":"demo"');
200 } finally {
201 h.stop();
202 }
203 });
204
205 test("a JUnit-named file that is not a report opens as source and says why", async () => {
206 const made = await createRepo(forge, alice, { name: "badjunit", visibility: "public", description: "tests" });
207 if (!made.ok) throw new Error("repo failed");
208 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-b.xml", content: "<root/>" }] });
209 const h = boot();
210 try {
211 await h.settle();
212 await open(h, "badjunit");
213 await openFile(h, "TEST-b.xml");
214 expect(h.text()).toContain("not drawn as test results");
215 } finally {
216 h.stop();
217 }
218 });
219
220 test("a .gcode opens as its facts, sharing the web parser, and s flips to the source", async () => {
221 const made = await createRepo(forge, alice, { name: "prints3d", visibility: "public", description: "slices" });
222 if (!made.ok) throw new Error("repo failed");
223 await commitToBranch(forge, alice, made.value, {
224 message: "seed",
225 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" }],
226 });
227 const h = boot();
228 try {
229 await h.settle();
230 await open(h, "prints3d");
231 await openFile(h, "cube.gcode");
232 expect(h.text()).toContain("Layers");
233 expect(h.text()).toContain("Bounding box");
234 expect(h.text()).toContain("3 mm");
235 await h.press("s");
236 expect(h.text()).toContain("G1 X10 Y0 E1");
237 } finally {
238 h.stop();
239 }
240 });
241
242 test("a .step opens as its facts, types and products, sharing the web reader, and s flips to the source", async () => {
243 const made = await createRepo(forge, alice, { name: "parts", visibility: "public", description: "cad" });
244 if (!made.ok) throw new Error("repo failed");
245 const content =
246 "ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION(('Bracket'),'2;1');\nFILE_NAME('b.step','2026-01-02',('Ada'),('Acme'),'p','CAD','');\nFILE_SCHEMA(('AUTOMOTIVE_DESIGN'));\nENDSEC;\nDATA;\n#1=PRODUCT('Widget7','x','',(#9));\n#2=CARTESIAN_POINT('',(0.,0.,0.));\nENDSEC;\nEND-ISO-10303-21;\n";
247 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "b.step", content }] });
248 const h = boot();
249 try {
250 await h.settle();
251 await open(h, "parts");
252 await openFile(h, "b.step");
253 expect(h.text()).toContain("AUTOMOTIVE_DESIGN");
254 expect(h.text()).toContain("Widget7");
255 expect(h.text()).toContain("CARTESIAN_POINT");
256 await h.press("s");
257 expect(h.text()).toContain("FILE_SCHEMA");
258 } finally {
259 h.stop();
260 }
261 });
262
263 test("a .geojson opens as its features table, sharing the web parser, and s flips to the source", async () => {
264 const made = await createRepo(forge, alice, { name: "places", visibility: "public", description: "geo" });
265 if (!made.ok) throw new Error("repo failed");
266 await commitToBranch(forge, alice, made.value, {
267 message: "seed",
268 files: [
269 {
270 path: "p.geojson",
271 content:
272 '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":{"name":"Harbour"}}]}',
273 },
274 ],
275 });
276 const h = boot();
277 try {
278 await h.settle();
279 await open(h, "places");
280 await openFile(h, "p.geojson");
281 expect(h.text()).toContain("Harbour");
282 expect(h.text()).toContain("Point");
283 expect(h.text()).toContain("1 feature");
284 await h.press("s");
285 expect(h.text()).toContain("FeatureCollection");
286 } finally {
287 h.stop();
288 }
289 });
290
291 test("a .har opens as its requests table, sharing the web parser, and s flips to the source", async () => {
292 const made = await createRepo(forge, alice, { name: "captures", visibility: "public", description: "har" });
293 if (!made.ok) throw new Error("repo failed");
294 await commitToBranch(forge, alice, made.value, {
295 message: "seed",
296 files: [
297 {
298 path: "s.har",
299 content: JSON.stringify({
300 log: { entries: [{ startedDateTime: "2026-01-01T00:00:00Z", time: 1230, request: { method: "post", url: "https://example.test/api" }, response: { status: 201, content: { size: 2048 } } }] },
301 }),
302 },
303 { path: "bad.har", content: '{"log": {"entries": [1, ' },
304 ],
305 });
306 const h = boot();
307 try {
308 await h.settle();
309 await open(h, "captures");
310 // A malformed HAR is not a table: the workspace shows its source as it stands.
311 await openFile(h, "bad.har");
312 expect(h.text()).toContain('{"log": {"entries": [1,');
313 expect(h.text()).not.toContain("Method");
314 await openFile(h, "s.har");
315 expect(h.text()).toContain("POST");
316 expect(h.text()).toContain("201");
317 expect(h.text()).toContain("https://example.test/api");
318 expect(h.text()).toContain("1.23 s");
319 await h.press("s");
320 expect(h.text()).toContain("startedDateTime");
321 } finally {
322 h.stop();
323 }
324 });
325
326 test("tables: search, edit, and s back to the table", async () => {
327 const made = await createRepo(forge, alice, { name: "sheets", visibility: "public", description: "more numbers" });
328 if (!made.ok) throw new Error("repo failed");
329 const rows = Array.from({ length: 80 }, (_, i) => `${i + 1},item ${i + 1}`);
330 await commitToBranch(forge, alice, made.value, {
331 message: "seed",
332 files: [{ path: "data.csv", content: ["id,name", ...rows, ""].join("\n") }],
333 });
334 const h = boot();
335 try {
336 await h.settle();
337 await open(h, "sheets");
338 await openFile(h, "data.csv");
339 expect(h.text()).not.toContain("item 70");
340 await h.press("/");
341 await h.type("item 70");
342 await h.press("enter");
343 expect(h.text()).toContain("70 │ item 70");
344
345 await h.press("e");
346 await h.press("esc");
347 expect(h.text()).toContain("70,item 70");
348 expect(h.text()).not.toContain("│ item");
349 await h.press("s");
350 expect(h.text()).toContain("id │ name");
351 } finally {
352 h.stop();
353 }
354 });
355
356 test("tables: the caps in the status line, a ; file, and s on a broken one", async () => {
357 const made = await createRepo(forge, alice, { name: "capsheets", visibility: "public", description: "caps" });
358 if (!made.ok) throw new Error("repo failed");
359 await commitToBranch(forge, alice, made.value, {
360 message: "seed",
361 files: [
362 { path: "semi.csv", content: "city;pop\nOslo;700\n" },
363 { path: "wide.csv", content: `${Array.from({ length: 70 }, (_, i) => `c${i}`).join(",")}\n1\n` },
364 { path: "long.csv", content: `n\n${Array.from({ length: 1100 }, (_, i) => i).join("\n")}\n` },
365 { path: "bad.csv", content: 'a,b\n1,"oops\n' },
366 ],
367 });
368 const h = boot();
369 try {
370 await h.settle();
371 await open(h, "capsheets");
372
373 await openFile(h, "semi.csv");
374 expect(h.text()).toContain("city │ pop");
375 expect(h.text()).toContain("Oslo");
376
377 await openFile(h, "wide.csv");
378 expect(h.text()).toContain("6 more columns");
379
380 await openFile(h, "long.csv");
381 expect(h.text()).toContain("1100 rows, first 1000 shown");
382
383 await openFile(h, "bad.csv");
384 await h.press("s");
385 expect(h.text()).toContain("not a table: line 2");
386 } finally {
387 h.stop();
388 }
389 });
390
391 test("an .xlsx opens as its first sheet's table, with the sheet names on top", async () => {
392 const made = await createRepo(forge, alice, { name: "books", visibility: "public", description: "sheets" });
393 if (!made.ok) throw new Error("repo failed");
394 const book = zip({
395 "[Content_Types].xml": "<Types/>",
396 "xl/workbook.xml": `<workbook><sheets><sheet name="Totals" sheetId="1" r:id="rId1"/><sheet name="Other" sheetId="2" r:id="rId2"/></sheets></workbook>`,
397 "xl/_rels/workbook.xml.rels": `<Relationships><Relationship Id="rId1" Target="worksheets/sheet1.xml"/></Relationships>`,
398 "xl/worksheets/sheet1.xml": `<worksheet><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>Widget</t></is></c><c r="B1"><v>42</v></c></row></sheetData></worksheet>`,
399 });
400 await commitToBranch(forge, alice, made.value, {
401 message: "seed",
402 files: [{ path: "sales.xlsx", content: book }],
403 });
404 const h = boot();
405 try {
406 await h.settle();
407 await open(h, "books");
408 await openFile(h, "sales.xlsx");
409 expect(h.text()).toContain("Sheet 1 (shown): Totals");
410 expect(h.text()).toContain("Sheet 2: Other");
411 expect(h.text()).toContain("Widget");
412 expect(h.text()).toContain("42");
413 } finally {
414 h.stop();
415 }
416 });
417
418 test("a SQLite file opens as one table, its schema on top, paged by 100 with > < and } {", async () => {
419 const made = await createRepo(forge, alice, { name: "dbs", visibility: "public", description: "data" });
420 if (!made.ok) throw new Error("repo failed");
421 const mem = new Database(":memory:");
422 mem.run("CREATE TABLE big (n INTEGER, label TEXT)");
423 for (let i = 1; i <= 250; i++) mem.run("INSERT INTO big VALUES (?, ?)", [i, `row ${i}`]);
424 mem.run("CREATE TABLE small (word TEXT)");
425 mem.run("INSERT INTO small VALUES ('hello')");
426 const bytes = mem.serialize();
427 mem.close();
428 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "data.db", content: bytes }] });
429 const h = boot();
430 try {
431 await h.settle();
432 await open(h, "dbs");
433 await openFile(h, "data.db");
434 expect(h.text()).toContain("Table 1 of 2: big");
435 expect(h.text()).toContain("rows 1–100 of 250");
436 expect(h.text()).toContain("INTEGER");
437 expect(h.text()).toContain("row 1");
438 await h.press(">");
439 expect(h.text()).toContain("rows 101–200 of 250");
440 await h.press(">");
441 await h.press(">");
442 expect(h.text()).toContain("rows 201–250 of 250");
443 await h.press("<");
444 expect(h.text()).toContain("rows 101–200 of 250");
445 await h.press("}");
446 expect(h.text()).toContain("Table 2 of 2: small");
447 expect(h.text()).toContain("rows 1–1 of 1");
448 expect(h.text()).toContain("hello");
449 } finally {
450 h.stop();
451 }
452 });
453
454 test("a .pptx opens as its slide titles", async () => {
455 const made = await createRepo(forge, alice, { name: "decks", visibility: "public", description: "slides" });
456 if (!made.ok) throw new Error("repo failed");
457 const deck = zip({
458 "[Content_Types].xml": "<Types/>",
459 "ppt/presentation.xml": `<p:presentation><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`,
460 "ppt/_rels/presentation.xml.rels": `<Relationships><Relationship Id="rId1" Target="slides/slide1.xml"/></Relationships>`,
461 "ppt/slides/slide1.xml": `<p:sld><p:sp><p:nvSpPr><p:nvPr><p:ph type="title"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:r><a:t>Launch plan</a:t></a:r></a:p></p:txBody></p:sp></p:sld>`,
462 });
463 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "talk.pptx", content: deck }] });
464 const h = boot();
465 try {
466 await h.settle();
467 await open(h, "decks");
468 await openFile(h, "talk.pptx");
469 expect(h.text()).toContain("Launch plan");
470 } finally {
471 h.stop();
472 }
473 });
474 });
test/tui-workspace-formats.test.ts −437
@@ -5,13 +5,11 @@
55 * both under the file budget).
66 */
77
8 import { Database } from "bun:sqlite";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1110 import { repoDir } from "../src/git/repos.ts";
1211 import type { App as Forge } from "../src/app.ts";
1312 import type { User } from "../src/core/users.ts";
14 import { zip } from "./helpers/zip.ts";
1513 import { quietLogs } from "./helpers/globals.ts";
1614 import { workspaceFixture, type Fixture } from "./helpers/tui-workspace.ts";
1715
@@ -590,439 +588,4 @@ describe("the terminal workspace, by file type", () => {
590588 h.stop();
591589 }
592590 });
593
594 test("a .sql file opens as its columns, and s shows the source", async () => {
595 const made = await createRepo(forge, alice, { name: "sqlrepo", visibility: "public", description: "db" });
596 if (!made.ok) throw new Error("repo failed");
597 const sql = "CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT NOT NULL);\nCREATE INDEX idx ON users(email);";
598 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "db/schema.sql", content: sql }] });
599 const h = boot();
600 try {
601 await h.settle();
602 await open(h, "sqlrepo");
603 await openFile(h, "db/schema.sql");
604 expect(h.text()).toContain("users");
605 expect(h.text()).toContain("PRIMARY KEY");
606 expect(h.text()).toContain("NOT NULL");
607 expect(h.text()).toContain("CREATE INDEX idx");
608 await h.press("s");
609 expect(h.text()).toContain("CREATE TABLE users");
610 } finally {
611 h.stop();
612 }
613 });
614
615 test("a .graphql file opens as its types, roots first, and s shows the source", async () => {
616 const made = await createRepo(forge, alice, { name: "gqlrepo", visibility: "public", description: "api" });
617 if (!made.ok) throw new Error("repo failed");
618 const gql = 'type User @key(fields: "id") { id: ID! }\ntype Query { user(id: ID!): User }\nscalar Date';
619 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "api/schema.graphql", content: gql }] });
620 const h = boot();
621 try {
622 await h.settle();
623 await open(h, "gqlrepo");
624 await openFile(h, "api/schema.graphql");
625 const text = h.text();
626 expect(text).toContain("type Query");
627 expect(text).toContain("user");
628 expect(text).toContain("ID!");
629 expect(text).toContain("scalar Date");
630 expect(text.indexOf("type Query")).toBeLessThan(text.indexOf("type User"));
631 await h.press("s");
632 expect(h.text()).toContain("type Query {");
633 } finally {
634 h.stop();
635 }
636 });
637
638 test("a .mbox opens as its messages and a .proto as its outline", async () => {
639 const made = await createRepo(forge, alice, { name: "mboxrepo", visibility: "public", description: "m" });
640 if (!made.ok) throw new Error("repo failed");
641 const mb = "From [email protected] Mon Jan 1 00:00:00 2024\nFrom: Ann <[email protected]>\nSubject: Hello there\nDate: Mon, 1 Jan 2024\n\nbody\n";
642 const pr = 'syntax = "proto3";\nmessage Widget { string label = 1; }\n';
643 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "a.mbox", content: mb }, { path: "w.proto", content: pr }] });
644 const h = boot();
645 try {
646 await h.settle();
647 await open(h, "mboxrepo");
648 await openFile(h, "a.mbox");
649 expect(h.text()).toContain("Hello there");
650 await h.press("escape");
651 await openFile(h, "w.proto");
652 expect(h.text()).toContain("Widget");
653 expect(h.text()).toContain("label");
654 } finally {
655 h.stop();
656 }
657 });
658
659 test("an .ini, .rtf and plain .xml open as settings, paragraphs and an element tree", async () => {
660 const made = await createRepo(forge, alice, { name: "inirepo", visibility: "public", description: "i" });
661 if (!made.ok) throw new Error("repo failed");
662 const files = [
663 { path: "a.ini", content: "[core]\nname = Widget\napi_token = hunter2\n" },
664 { path: "n.rtf", content: "{\\rtf1\\ansi Hello rich world\\par}" },
665 { path: "d.xml", content: '<config><item id="7">first value</item></config>' },
666 ];
667 await commitToBranch(forge, alice, made.value, { message: "seed", files });
668 const h = boot();
669 try {
670 await h.settle();
671 await open(h, "inirepo");
672 await openFile(h, "a.ini");
673 expect(h.text()).toContain("Widget");
674 expect(h.text()).toContain("•••");
675 expect(h.text()).not.toContain("hunter2");
676 await h.press("escape");
677 await openFile(h, "n.rtf");
678 expect(h.text()).toContain("Hello rich world");
679 await h.press("escape");
680 await openFile(h, "d.xml");
681 expect(h.text()).toContain("config");
682 expect(h.text()).toContain('id="7"');
683 expect(h.text()).toContain("first value");
684 } finally {
685 h.stop();
686 }
687 });
688
689 test("a JUnit report opens as its totals and failing cases, sharing the web parser", async () => {
690 const made = await createRepo(forge, alice, { name: "junitrepo", visibility: "public", description: "tests" });
691 if (!made.ok) throw new Error("repo failed");
692 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>';
693 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-a.xml", content: xml }, { path: "TEST-b.xml", content: "<nope" }] });
694 const h = boot();
695 try {
696 await h.settle();
697 await open(h, "junitrepo");
698 await openFile(h, "TEST-a.xml");
699 expect(h.text()).toContain("1 of 2 tests fail");
700 expect(h.text()).toContain("m.A › bad");
701 expect(h.text()).toContain("expected 1 got 2");
702 expect(h.text()).toContain("1 failing case");
703 } finally {
704 h.stop();
705 }
706 });
707
708 test("an OPML file opens as its titles and links, sharing the web reader", async () => {
709 const made = await createRepo(forge, alice, { name: "opmlrepo", visibility: "public", description: "feeds" });
710 if (!made.ok) throw new Error("repo failed");
711 const opml = '<opml><body><outline text="News"><outline text="Wire" xmlUrl="https://e.com/f.xml"/></outline></body></opml>';
712 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "feeds.opml", content: opml }, { path: "bad.rss", content: "<nope" }] });
713 const h = boot();
714 try {
715 await h.settle();
716 await open(h, "opmlrepo");
717 await openFile(h, "feeds.opml");
718 expect(h.text()).toContain("– Wire");
719 expect(h.text()).toContain("https://e.com/f.xml");
720 await h.press("s");
721 expect(h.text()).toContain("<outline text=");
722 await h.press("q");
723 } finally {
724 h.stop();
725 }
726 });
727
728 test("a .env.example opens as a table with secrets masked, and s flips to the source", async () => {
729 const made = await createRepo(forge, alice, { name: "envrepo", visibility: "public", description: "tests" });
730 if (!made.ok) throw new Error("repo failed");
731 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" }] });
732 const h = boot();
733 try {
734 await h.settle();
735 await open(h, "envrepo");
736 await openFile(h, ".env.example");
737 expect(h.text()).toContain("Port to listen on");
738 expect(h.text()).toContain("•••");
739 expect(h.text()).not.toContain("sk-live-abc");
740 await h.press("s");
741 expect(h.text()).toContain("API_KEY=sk-live-abc");
742 } finally {
743 h.stop();
744 }
745 });
746
747 test("a package.json opens as rows of scripts and dependencies, and s flips to the source", async () => {
748 const made = await createRepo(forge, alice, { name: "pkgrepo", visibility: "public", description: "tests" });
749 if (!made.ok) throw new Error("repo failed");
750 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "package.json", content: '{"name":"demo","scripts":{"test":"bun test"},"dependencies":{"hono":"^4.0.0"}}' }] });
751 const h = boot();
752 try {
753 await h.settle();
754 await open(h, "pkgrepo");
755 await openFile(h, "package.json");
756 expect(h.text()).toContain("Dependencies");
757 expect(h.text()).toContain("^4.0.0");
758 await h.press("s");
759 expect(h.text()).toContain('"name":"demo"');
760 } finally {
761 h.stop();
762 }
763 });
764
765 test("a JUnit-named file that is not a report opens as source and says why", async () => {
766 const made = await createRepo(forge, alice, { name: "badjunit", visibility: "public", description: "tests" });
767 if (!made.ok) throw new Error("repo failed");
768 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-b.xml", content: "<root/>" }] });
769 const h = boot();
770 try {
771 await h.settle();
772 await open(h, "badjunit");
773 await openFile(h, "TEST-b.xml");
774 expect(h.text()).toContain("not drawn as test results");
775 } finally {
776 h.stop();
777 }
778 });
779
780 test("a .gcode opens as its facts, sharing the web parser, and s flips to the source", async () => {
781 const made = await createRepo(forge, alice, { name: "prints3d", visibility: "public", description: "slices" });
782 if (!made.ok) throw new Error("repo failed");
783 await commitToBranch(forge, alice, made.value, {
784 message: "seed",
785 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" }],
786 });
787 const h = boot();
788 try {
789 await h.settle();
790 await open(h, "prints3d");
791 await openFile(h, "cube.gcode");
792 expect(h.text()).toContain("Layers");
793 expect(h.text()).toContain("Bounding box");
794 expect(h.text()).toContain("3 mm");
795 await h.press("s");
796 expect(h.text()).toContain("G1 X10 Y0 E1");
797 } finally {
798 h.stop();
799 }
800 });
801
802 test("a .step opens as its facts, types and products, sharing the web reader, and s flips to the source", async () => {
803 const made = await createRepo(forge, alice, { name: "parts", visibility: "public", description: "cad" });
804 if (!made.ok) throw new Error("repo failed");
805 const content =
806 "ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION(('Bracket'),'2;1');\nFILE_NAME('b.step','2026-01-02',('Ada'),('Acme'),'p','CAD','');\nFILE_SCHEMA(('AUTOMOTIVE_DESIGN'));\nENDSEC;\nDATA;\n#1=PRODUCT('Widget7','x','',(#9));\n#2=CARTESIAN_POINT('',(0.,0.,0.));\nENDSEC;\nEND-ISO-10303-21;\n";
807 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "b.step", content }] });
808 const h = boot();
809 try {
810 await h.settle();
811 await open(h, "parts");
812 await openFile(h, "b.step");
813 expect(h.text()).toContain("AUTOMOTIVE_DESIGN");
814 expect(h.text()).toContain("Widget7");
815 expect(h.text()).toContain("CARTESIAN_POINT");
816 await h.press("s");
817 expect(h.text()).toContain("FILE_SCHEMA");
818 } finally {
819 h.stop();
820 }
821 });
822
823 test("a .geojson opens as its features table, sharing the web parser, and s flips to the source", async () => {
824 const made = await createRepo(forge, alice, { name: "places", visibility: "public", description: "geo" });
825 if (!made.ok) throw new Error("repo failed");
826 await commitToBranch(forge, alice, made.value, {
827 message: "seed",
828 files: [
829 {
830 path: "p.geojson",
831 content:
832 '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":{"name":"Harbour"}}]}',
833 },
834 ],
835 });
836 const h = boot();
837 try {
838 await h.settle();
839 await open(h, "places");
840 await openFile(h, "p.geojson");
841 expect(h.text()).toContain("Harbour");
842 expect(h.text()).toContain("Point");
843 expect(h.text()).toContain("1 feature");
844 await h.press("s");
845 expect(h.text()).toContain("FeatureCollection");
846 } finally {
847 h.stop();
848 }
849 });
850
851 test("a .har opens as its requests table, sharing the web parser, and s flips to the source", async () => {
852 const made = await createRepo(forge, alice, { name: "captures", visibility: "public", description: "har" });
853 if (!made.ok) throw new Error("repo failed");
854 await commitToBranch(forge, alice, made.value, {
855 message: "seed",
856 files: [
857 {
858 path: "s.har",
859 content: JSON.stringify({
860 log: { entries: [{ startedDateTime: "2026-01-01T00:00:00Z", time: 1230, request: { method: "post", url: "https://example.test/api" }, response: { status: 201, content: { size: 2048 } } }] },
861 }),
862 },
863 { path: "bad.har", content: '{"log": {"entries": [1, ' },
864 ],
865 });
866 const h = boot();
867 try {
868 await h.settle();
869 await open(h, "captures");
870 // A malformed HAR is not a table: the workspace shows its source as it stands.
871 await openFile(h, "bad.har");
872 expect(h.text()).toContain('{"log": {"entries": [1,');
873 expect(h.text()).not.toContain("Method");
874 await openFile(h, "s.har");
875 expect(h.text()).toContain("POST");
876 expect(h.text()).toContain("201");
877 expect(h.text()).toContain("https://example.test/api");
878 expect(h.text()).toContain("1.23 s");
879 await h.press("s");
880 expect(h.text()).toContain("startedDateTime");
881 } finally {
882 h.stop();
883 }
884 });
885
886 test("tables: search, edit, the caps in the status line, a ; file, and s on a broken one", async () => {
887 const made = await createRepo(forge, alice, {
888 name: "sheets",
889 visibility: "public",
890 description: "more numbers",
891 });
892 if (!made.ok) throw new Error("repo failed");
893 const rows = Array.from({ length: 80 }, (_, i) => `${i + 1},item ${i + 1}`);
894 await commitToBranch(forge, alice, made.value, {
895 message: "seed",
896 files: [
897 { path: "data.csv", content: ["id,name", ...rows, ""].join("\n") },
898 { path: "semi.csv", content: "city;pop\nOslo;700\n" },
899 {
900 path: "wide.csv",
901 content: `${Array.from({ length: 70 }, (_, i) => `c${i}`).join(",")}\n1\n`,
902 },
903 {
904 path: "long.csv",
905 content: `n\n${Array.from({ length: 1100 }, (_, i) => i).join("\n")}\n`,
906 },
907 { path: "bad.csv", content: 'a,b\n1,"oops\n' },
908 ],
909 });
910 const h = boot();
911 try {
912 await h.settle();
913 await open(h, "sheets");
914
915 await openFile(h, "semi.csv");
916 expect(h.text()).toContain("city │ pop");
917 expect(h.text()).toContain("Oslo");
918
919 await openFile(h, "wide.csv");
920 expect(h.text()).toContain("6 more columns");
921
922 await openFile(h, "long.csv");
923 expect(h.text()).toContain("1100 rows, first 1000 shown");
924
925 await openFile(h, "data.csv");
926 expect(h.text()).not.toContain("item 70");
927 await h.press("/");
928 await h.type("item 70");
929 await h.press("enter");
930 expect(h.text()).toContain("70 │ item 70");
931
932 await h.press("e");
933 await h.press("esc");
934 expect(h.text()).toContain("70,item 70");
935 expect(h.text()).not.toContain("│ item");
936 await h.press("s");
937 expect(h.text()).toContain("id │ name");
938
939 await openFile(h, "bad.csv");
940 await h.press("s");
941 expect(h.text()).toContain("not a table: line 2");
942 } finally {
943 h.stop();
944 }
945 });
946
947 test("an .xlsx opens as its first sheet's table, with the sheet names on top", async () => {
948 const made = await createRepo(forge, alice, { name: "books", visibility: "public", description: "sheets" });
949 if (!made.ok) throw new Error("repo failed");
950 const book = zip({
951 "[Content_Types].xml": "<Types/>",
952 "xl/workbook.xml": `<workbook><sheets><sheet name="Totals" sheetId="1" r:id="rId1"/><sheet name="Other" sheetId="2" r:id="rId2"/></sheets></workbook>`,
953 "xl/_rels/workbook.xml.rels": `<Relationships><Relationship Id="rId1" Target="worksheets/sheet1.xml"/></Relationships>`,
954 "xl/worksheets/sheet1.xml": `<worksheet><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>Widget</t></is></c><c r="B1"><v>42</v></c></row></sheetData></worksheet>`,
955 });
956 await commitToBranch(forge, alice, made.value, {
957 message: "seed",
958 files: [{ path: "sales.xlsx", content: book }],
959 });
960 const h = boot();
961 try {
962 await h.settle();
963 await open(h, "books");
964 await openFile(h, "sales.xlsx");
965 expect(h.text()).toContain("Sheet 1 (shown): Totals");
966 expect(h.text()).toContain("Sheet 2: Other");
967 expect(h.text()).toContain("Widget");
968 expect(h.text()).toContain("42");
969 } finally {
970 h.stop();
971 }
972 });
973 test("a SQLite file opens as one table, its schema on top, paged by 100 with > < and } {", async () => {
974 const made = await createRepo(forge, alice, { name: "dbs", visibility: "public", description: "data" });
975 if (!made.ok) throw new Error("repo failed");
976 const mem = new Database(":memory:");
977 mem.run("CREATE TABLE big (n INTEGER, label TEXT)");
978 for (let i = 1; i <= 250; i++) mem.run("INSERT INTO big VALUES (?, ?)", [i, `row ${i}`]);
979 mem.run("CREATE TABLE small (word TEXT)");
980 mem.run("INSERT INTO small VALUES ('hello')");
981 const bytes = mem.serialize();
982 mem.close();
983 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "data.db", content: bytes }] });
984 const h = boot();
985 try {
986 await h.settle();
987 await open(h, "dbs");
988 await openFile(h, "data.db");
989 expect(h.text()).toContain("Table 1 of 2: big");
990 expect(h.text()).toContain("rows 1–100 of 250");
991 expect(h.text()).toContain("INTEGER");
992 expect(h.text()).toContain("row 1");
993 await h.press(">");
994 expect(h.text()).toContain("rows 101–200 of 250");
995 await h.press(">");
996 await h.press(">");
997 expect(h.text()).toContain("rows 201–250 of 250");
998 await h.press("<");
999 expect(h.text()).toContain("rows 101–200 of 250");
1000 await h.press("}");
1001 expect(h.text()).toContain("Table 2 of 2: small");
1002 expect(h.text()).toContain("rows 1–1 of 1");
1003 expect(h.text()).toContain("hello");
1004 } finally {
1005 h.stop();
1006 }
1007 });
1008 test("a .pptx opens as its slide titles", async () => {
1009 const made = await createRepo(forge, alice, { name: "decks", visibility: "public", description: "slides" });
1010 if (!made.ok) throw new Error("repo failed");
1011 const deck = zip({
1012 "[Content_Types].xml": "<Types/>",
1013 "ppt/presentation.xml": `<p:presentation><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`,
1014 "ppt/_rels/presentation.xml.rels": `<Relationships><Relationship Id="rId1" Target="slides/slide1.xml"/></Relationships>`,
1015 "ppt/slides/slide1.xml": `<p:sld><p:sp><p:nvSpPr><p:nvPr><p:ph type="title"/></p:nvPr></p:nvSpPr><p:txBody><a:p><a:r><a:t>Launch plan</a:t></a:r></a:p></p:txBody></p:sp></p:sld>`,
1016 });
1017 await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "talk.pptx", content: deck }] });
1018 const h = boot();
1019 try {
1020 await h.settle();
1021 await open(h, "decks");
1022 await openFile(h, "talk.pptx");
1023 expect(h.text()).toContain("Launch plan");
1024 } finally {
1025 h.stop();
1026 }
1027 });
1028591 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs