Public: anyone can read this; the crew can change it.
Revert "Full suite red: 2 files in check run 01m82pqag17019bak21s7c86a3" #15790
Check · Review · Land · Live — It conflicts with its base.
revert-15701 → main 1 commit 1 thread · 1 unresolved
6 files
changed +449
−487
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 | ||
| 14 | 14 | |
| 15 | 15 | **Terminal:** the workspace opens the same table (`envTable` in `src/tui/screens/workspace.ts`, over the same `parseEnv`); `s` flips to the source. |
| 16 | 16 | |
| 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`. | |
| 17 | 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
| @@ -15,4 +15,4 @@ Test runners (JUnit, pytest, vitest, Go via gotestsum) write JUnit XML. A file n | ||
| 15 | 15 | |
| 16 | 16 | **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. |
| 17 | 17 | |
| 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`. | |
| 18 | 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-package-json.md +1 −1
| @@ -12,4 +12,4 @@ A file named exactly `package.json` opens as rows instead of raw text: name and | ||
| 12 | 12 | |
| 13 | 13 | **Terminal:** the workspace opens the same rows (`packageTable` in `src/tui/screens/workspace.ts`, over the same `parsePackage`); `s` flips to the source. |
| 14 | 14 | |
| 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`. | |
| 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`. |
test/chapter-next.test.ts +9 −10
| @@ -78,17 +78,16 @@ const terminalNext = async () => { | ||
| 78 | 78 | const terminal = headlessTerminal(140, 30); |
| 79 | 79 | const { app: tui } = createForgeApp(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: owner }, { terminal, exitHooks: false }); |
| 80 | 80 | tui.start(); |
| 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"); | |
| 81 | const send = async (key: string, ctrl = false) => { | |
| 82 | tui.dispatch({ type: "key", key, ctrl, alt: false, shift: false }); | |
| 83 | await settleApp(tui); | |
| 84 | }; | |
| 91 | 85 | 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"); | |
| 92 | 91 | const text = tui.screen.toText(); |
| 93 | 92 | tui.stop(); |
| 94 | 93 | return text; |
test/tui-workspace-formats-more.test.ts deleted −474
| @@ -1,474 +0,0 @@ | ||
| 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,11 +5,13 @@ | ||
| 5 | 5 | * both under the file budget). |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { Database } from "bun:sqlite"; | |
| 8 | 9 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 9 | 10 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 10 | 11 | import { repoDir } from "../src/git/repos.ts"; |
| 11 | 12 | import type { App as Forge } from "../src/app.ts"; |
| 12 | 13 | import type { User } from "../src/core/users.ts"; |
| 14 | import { zip } from "./helpers/zip.ts"; | |
| 13 | 15 | import { quietLogs } from "./helpers/globals.ts"; |
| 14 | 16 | import { workspaceFixture, type Fixture } from "./helpers/tui-workspace.ts"; |
| 15 | 17 | import { READ_POINT_CAP, TOKEN_CAP } from "../src/web/render/gpx.ts"; |
| @@ -626,4 +628,439 @@ describe("the terminal workspace, by file type", () => { | ||
| 626 | 628 | h.stop(); |
| 627 | 629 | } |
| 628 | 630 | }); |
| 631 | ||
| 632 | test("a .sql file opens as its columns, and s shows the source", async () => { | |
| 633 | const made = await createRepo(forge, alice, { name: "sqlrepo", visibility: "public", description: "db" }); | |
| 634 | if (!made.ok) throw new Error("repo failed"); | |
| 635 | const sql = "CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT NOT NULL);\nCREATE INDEX idx ON users(email);"; | |
| 636 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "db/schema.sql", content: sql }] }); | |
| 637 | const h = boot(); | |
| 638 | try { | |
| 639 | await h.settle(); | |
| 640 | await open(h, "sqlrepo"); | |
| 641 | await openFile(h, "db/schema.sql"); | |
| 642 | expect(h.text()).toContain("users"); | |
| 643 | expect(h.text()).toContain("PRIMARY KEY"); | |
| 644 | expect(h.text()).toContain("NOT NULL"); | |
| 645 | expect(h.text()).toContain("CREATE INDEX idx"); | |
| 646 | await h.press("s"); | |
| 647 | expect(h.text()).toContain("CREATE TABLE users"); | |
| 648 | } finally { | |
| 649 | h.stop(); | |
| 650 | } | |
| 651 | }); | |
| 652 | ||
| 653 | test("a .graphql file opens as its types, roots first, and s shows the source", async () => { | |
| 654 | const made = await createRepo(forge, alice, { name: "gqlrepo", visibility: "public", description: "api" }); | |
| 655 | if (!made.ok) throw new Error("repo failed"); | |
| 656 | const gql = 'type User @key(fields: "id") { id: ID! }\ntype Query { user(id: ID!): User }\nscalar Date'; | |
| 657 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "api/schema.graphql", content: gql }] }); | |
| 658 | const h = boot(); | |
| 659 | try { | |
| 660 | await h.settle(); | |
| 661 | await open(h, "gqlrepo"); | |
| 662 | await openFile(h, "api/schema.graphql"); | |
| 663 | const text = h.text(); | |
| 664 | expect(text).toContain("type Query"); | |
| 665 | expect(text).toContain("user"); | |
| 666 | expect(text).toContain("ID!"); | |
| 667 | expect(text).toContain("scalar Date"); | |
| 668 | expect(text.indexOf("type Query")).toBeLessThan(text.indexOf("type User")); | |
| 669 | await h.press("s"); | |
| 670 | expect(h.text()).toContain("type Query {"); | |
| 671 | } finally { | |
| 672 | h.stop(); | |
| 673 | } | |
| 674 | }); | |
| 675 | ||
| 676 | test("a .mbox opens as its messages and a .proto as its outline", async () => { | |
| 677 | const made = await createRepo(forge, alice, { name: "mboxrepo", visibility: "public", description: "m" }); | |
| 678 | if (!made.ok) throw new Error("repo failed"); | |
| 679 | 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"; | |
| 680 | const pr = 'syntax = "proto3";\nmessage Widget { string label = 1; }\n'; | |
| 681 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "a.mbox", content: mb }, { path: "w.proto", content: pr }] }); | |
| 682 | const h = boot(); | |
| 683 | try { | |
| 684 | await h.settle(); | |
| 685 | await open(h, "mboxrepo"); | |
| 686 | await openFile(h, "a.mbox"); | |
| 687 | expect(h.text()).toContain("Hello there"); | |
| 688 | await h.press("escape"); | |
| 689 | await openFile(h, "w.proto"); | |
| 690 | expect(h.text()).toContain("Widget"); | |
| 691 | expect(h.text()).toContain("label"); | |
| 692 | } finally { | |
| 693 | h.stop(); | |
| 694 | } | |
| 695 | }); | |
| 696 | ||
| 697 | test("an .ini, .rtf and plain .xml open as settings, paragraphs and an element tree", async () => { | |
| 698 | const made = await createRepo(forge, alice, { name: "inirepo", visibility: "public", description: "i" }); | |
| 699 | if (!made.ok) throw new Error("repo failed"); | |
| 700 | const files = [ | |
| 701 | { path: "a.ini", content: "[core]\nname = Widget\napi_token = hunter2\n" }, | |
| 702 | { path: "n.rtf", content: "{\\rtf1\\ansi Hello rich world\\par}" }, | |
| 703 | { path: "d.xml", content: '<config><item id="7">first value</item></config>' }, | |
| 704 | ]; | |
| 705 | await commitToBranch(forge, alice, made.value, { message: "seed", files }); | |
| 706 | const h = boot(); | |
| 707 | try { | |
| 708 | await h.settle(); | |
| 709 | await open(h, "inirepo"); | |
| 710 | await openFile(h, "a.ini"); | |
| 711 | expect(h.text()).toContain("Widget"); | |
| 712 | expect(h.text()).toContain("•••"); | |
| 713 | expect(h.text()).not.toContain("hunter2"); | |
| 714 | await h.press("escape"); | |
| 715 | await openFile(h, "n.rtf"); | |
| 716 | expect(h.text()).toContain("Hello rich world"); | |
| 717 | await h.press("escape"); | |
| 718 | await openFile(h, "d.xml"); | |
| 719 | expect(h.text()).toContain("config"); | |
| 720 | expect(h.text()).toContain('id="7"'); | |
| 721 | expect(h.text()).toContain("first value"); | |
| 722 | } finally { | |
| 723 | h.stop(); | |
| 724 | } | |
| 725 | }); | |
| 726 | ||
| 727 | test("a JUnit report opens as its totals and failing cases, sharing the web parser", async () => { | |
| 728 | const made = await createRepo(forge, alice, { name: "junitrepo", visibility: "public", description: "tests" }); | |
| 729 | if (!made.ok) throw new Error("repo failed"); | |
| 730 | 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>'; | |
| 731 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-a.xml", content: xml }, { path: "TEST-b.xml", content: "<nope" }] }); | |
| 732 | const h = boot(); | |
| 733 | try { | |
| 734 | await h.settle(); | |
| 735 | await open(h, "junitrepo"); | |
| 736 | await openFile(h, "TEST-a.xml"); | |
| 737 | expect(h.text()).toContain("1 of 2 tests fail"); | |
| 738 | expect(h.text()).toContain("m.A › bad"); | |
| 739 | expect(h.text()).toContain("expected 1 got 2"); | |
| 740 | expect(h.text()).toContain("1 failing case"); | |
| 741 | } finally { | |
| 742 | h.stop(); | |
| 743 | } | |
| 744 | }); | |
| 745 | ||
| 746 | test("an OPML file opens as its titles and links, sharing the web reader", async () => { | |
| 747 | const made = await createRepo(forge, alice, { name: "opmlrepo", visibility: "public", description: "feeds" }); | |
| 748 | if (!made.ok) throw new Error("repo failed"); | |
| 749 | const opml = '<opml><body><outline text="News"><outline text="Wire" xmlUrl="https://e.com/f.xml"/></outline></body></opml>'; | |
| 750 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "feeds.opml", content: opml }, { path: "bad.rss", content: "<nope" }] }); | |
| 751 | const h = boot(); | |
| 752 | try { | |
| 753 | await h.settle(); | |
| 754 | await open(h, "opmlrepo"); | |
| 755 | await openFile(h, "feeds.opml"); | |
| 756 | expect(h.text()).toContain("– Wire"); | |
| 757 | expect(h.text()).toContain("https://e.com/f.xml"); | |
| 758 | await h.press("s"); | |
| 759 | expect(h.text()).toContain("<outline text="); | |
| 760 | await h.press("q"); | |
| 761 | } finally { | |
| 762 | h.stop(); | |
| 763 | } | |
| 764 | }); | |
| 765 | ||
| 766 | test("a .env.example opens as a table with secrets masked, and s flips to the source", async () => { | |
| 767 | const made = await createRepo(forge, alice, { name: "envrepo", visibility: "public", description: "tests" }); | |
| 768 | if (!made.ok) throw new Error("repo failed"); | |
| 769 | 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" }] }); | |
| 770 | const h = boot(); | |
| 771 | try { | |
| 772 | await h.settle(); | |
| 773 | await open(h, "envrepo"); | |
| 774 | await openFile(h, ".env.example"); | |
| 775 | expect(h.text()).toContain("Port to listen on"); | |
| 776 | expect(h.text()).toContain("•••"); | |
| 777 | expect(h.text()).not.toContain("sk-live-abc"); | |
| 778 | await h.press("s"); | |
| 779 | expect(h.text()).toContain("API_KEY=sk-live-abc"); | |
| 780 | } finally { | |
| 781 | h.stop(); | |
| 782 | } | |
| 783 | }); | |
| 784 | ||
| 785 | test("a package.json opens as rows of scripts and dependencies, and s flips to the source", async () => { | |
| 786 | const made = await createRepo(forge, alice, { name: "pkgrepo", visibility: "public", description: "tests" }); | |
| 787 | if (!made.ok) throw new Error("repo failed"); | |
| 788 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "package.json", content: '{"name":"demo","scripts":{"test":"bun test"},"dependencies":{"hono":"^4.0.0"}}' }] }); | |
| 789 | const h = boot(); | |
| 790 | try { | |
| 791 | await h.settle(); | |
| 792 | await open(h, "pkgrepo"); | |
| 793 | await openFile(h, "package.json"); | |
| 794 | expect(h.text()).toContain("Dependencies"); | |
| 795 | expect(h.text()).toContain("^4.0.0"); | |
| 796 | await h.press("s"); | |
| 797 | expect(h.text()).toContain('"name":"demo"'); | |
| 798 | } finally { | |
| 799 | h.stop(); | |
| 800 | } | |
| 801 | }); | |
| 802 | ||
| 803 | test("a JUnit-named file that is not a report opens as source and says why", async () => { | |
| 804 | const made = await createRepo(forge, alice, { name: "badjunit", visibility: "public", description: "tests" }); | |
| 805 | if (!made.ok) throw new Error("repo failed"); | |
| 806 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "TEST-b.xml", content: "<root/>" }] }); | |
| 807 | const h = boot(); | |
| 808 | try { | |
| 809 | await h.settle(); | |
| 810 | await open(h, "badjunit"); | |
| 811 | await openFile(h, "TEST-b.xml"); | |
| 812 | expect(h.text()).toContain("not drawn as test results"); | |
| 813 | } finally { | |
| 814 | h.stop(); | |
| 815 | } | |
| 816 | }); | |
| 817 | ||
| 818 | test("a .gcode opens as its facts, sharing the web parser, and s flips to the source", async () => { | |
| 819 | const made = await createRepo(forge, alice, { name: "prints3d", visibility: "public", description: "slices" }); | |
| 820 | if (!made.ok) throw new Error("repo failed"); | |
| 821 | await commitToBranch(forge, alice, made.value, { | |
| 822 | message: "seed", | |
| 823 | 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" }], | |
| 824 | }); | |
| 825 | const h = boot(); | |
| 826 | try { | |
| 827 | await h.settle(); | |
| 828 | await open(h, "prints3d"); | |
| 829 | await openFile(h, "cube.gcode"); | |
| 830 | expect(h.text()).toContain("Layers"); | |
| 831 | expect(h.text()).toContain("Bounding box"); | |
| 832 | expect(h.text()).toContain("3 mm"); | |
| 833 | await h.press("s"); | |
| 834 | expect(h.text()).toContain("G1 X10 Y0 E1"); | |
| 835 | } finally { | |
| 836 | h.stop(); | |
| 837 | } | |
| 838 | }); | |
| 839 | ||
| 840 | test("a .step opens as its facts, types and products, sharing the web reader, and s flips to the source", async () => { | |
| 841 | const made = await createRepo(forge, alice, { name: "parts", visibility: "public", description: "cad" }); | |
| 842 | if (!made.ok) throw new Error("repo failed"); | |
| 843 | const content = | |
| 844 | "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"; | |
| 845 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "b.step", content }] }); | |
| 846 | const h = boot(); | |
| 847 | try { | |
| 848 | await h.settle(); | |
| 849 | await open(h, "parts"); | |
| 850 | await openFile(h, "b.step"); | |
| 851 | expect(h.text()).toContain("AUTOMOTIVE_DESIGN"); | |
| 852 | expect(h.text()).toContain("Widget7"); | |
| 853 | expect(h.text()).toContain("CARTESIAN_POINT"); | |
| 854 | await h.press("s"); | |
| 855 | expect(h.text()).toContain("FILE_SCHEMA"); | |
| 856 | } finally { | |
| 857 | h.stop(); | |
| 858 | } | |
| 859 | }); | |
| 860 | ||
| 861 | test("a .geojson opens as its features table, sharing the web parser, and s flips to the source", async () => { | |
| 862 | const made = await createRepo(forge, alice, { name: "places", visibility: "public", description: "geo" }); | |
| 863 | if (!made.ok) throw new Error("repo failed"); | |
| 864 | await commitToBranch(forge, alice, made.value, { | |
| 865 | message: "seed", | |
| 866 | files: [ | |
| 867 | { | |
| 868 | path: "p.geojson", | |
| 869 | content: | |
| 870 | '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[1,2]},"properties":{"name":"Harbour"}}]}', | |
| 871 | }, | |
| 872 | ], | |
| 873 | }); | |
| 874 | const h = boot(); | |
| 875 | try { | |
| 876 | await h.settle(); | |
| 877 | await open(h, "places"); | |
| 878 | await openFile(h, "p.geojson"); | |
| 879 | expect(h.text()).toContain("Harbour"); | |
| 880 | expect(h.text()).toContain("Point"); | |
| 881 | expect(h.text()).toContain("1 feature"); | |
| 882 | await h.press("s"); | |
| 883 | expect(h.text()).toContain("FeatureCollection"); | |
| 884 | } finally { | |
| 885 | h.stop(); | |
| 886 | } | |
| 887 | }); | |
| 888 | ||
| 889 | test("a .har opens as its requests table, sharing the web parser, and s flips to the source", async () => { | |
| 890 | const made = await createRepo(forge, alice, { name: "captures", visibility: "public", description: "har" }); | |
| 891 | if (!made.ok) throw new Error("repo failed"); | |
| 892 | await commitToBranch(forge, alice, made.value, { | |
| 893 | message: "seed", | |
| 894 | files: [ | |
| 895 | { | |
| 896 | path: "s.har", | |
| 897 | content: JSON.stringify({ | |
| 898 | log: { entries: [{ startedDateTime: "2026-01-01T00:00:00Z", time: 1230, request: { method: "post", url: "https://example.test/api" }, response: { status: 201, content: { size: 2048 } } }] }, | |
| 899 | }), | |
| 900 | }, | |
| 901 | { path: "bad.har", content: '{"log": {"entries": [1, ' }, | |
| 902 | ], | |
| 903 | }); | |
| 904 | const h = boot(); | |
| 905 | try { | |
| 906 | await h.settle(); | |
| 907 | await open(h, "captures"); | |
| 908 | // A malformed HAR is not a table: the workspace shows its source as it stands. | |
| 909 | await openFile(h, "bad.har"); | |
| 910 | expect(h.text()).toContain('{"log": {"entries": [1,'); | |
| 911 | expect(h.text()).not.toContain("Method"); | |
| 912 | await openFile(h, "s.har"); | |
| 913 | expect(h.text()).toContain("POST"); | |
| 914 | expect(h.text()).toContain("201"); | |
| 915 | expect(h.text()).toContain("https://example.test/api"); | |
| 916 | expect(h.text()).toContain("1.23 s"); | |
| 917 | await h.press("s"); | |
| 918 | expect(h.text()).toContain("startedDateTime"); | |
| 919 | } finally { | |
| 920 | h.stop(); | |
| 921 | } | |
| 922 | }); | |
| 923 | ||
| 924 | test("tables: search, edit, the caps in the status line, a ; file, and s on a broken one", async () => { | |
| 925 | const made = await createRepo(forge, alice, { | |
| 926 | name: "sheets", | |
| 927 | visibility: "public", | |
| 928 | description: "more numbers", | |
| 929 | }); | |
| 930 | if (!made.ok) throw new Error("repo failed"); | |
| 931 | const rows = Array.from({ length: 80 }, (_, i) => `${i + 1},item ${i + 1}`); | |
| 932 | await commitToBranch(forge, alice, made.value, { | |
| 933 | message: "seed", | |
| 934 | files: [ | |
| 935 | { path: "data.csv", content: ["id,name", ...rows, ""].join("\n") }, | |
| 936 | { path: "semi.csv", content: "city;pop\nOslo;700\n" }, | |
| 937 | { | |
| 938 | path: "wide.csv", | |
| 939 | content: `${Array.from({ length: 70 }, (_, i) => `c${i}`).join(",")}\n1\n`, | |
| 940 | }, | |
| 941 | { | |
| 942 | path: "long.csv", | |
| 943 | content: `n\n${Array.from({ length: 1100 }, (_, i) => i).join("\n")}\n`, | |
| 944 | }, | |
| 945 | { path: "bad.csv", content: 'a,b\n1,"oops\n' }, | |
| 946 | ], | |
| 947 | }); | |
| 948 | const h = boot(); | |
| 949 | try { | |
| 950 | await h.settle(); | |
| 951 | await open(h, "sheets"); | |
| 952 | ||
| 953 | await openFile(h, "semi.csv"); | |
| 954 | expect(h.text()).toContain("city │ pop"); | |
| 955 | expect(h.text()).toContain("Oslo"); | |
| 956 | ||
| 957 | await openFile(h, "wide.csv"); | |
| 958 | expect(h.text()).toContain("6 more columns"); | |
| 959 | ||
| 960 | await openFile(h, "long.csv"); | |
| 961 | expect(h.text()).toContain("1100 rows, first 1000 shown"); | |
| 962 | ||
| 963 | await openFile(h, "data.csv"); | |
| 964 | expect(h.text()).not.toContain("item 70"); | |
| 965 | await h.press("/"); | |
| 966 | await h.type("item 70"); | |
| 967 | await h.press("enter"); | |
| 968 | expect(h.text()).toContain("70 │ item 70"); | |
| 969 | ||
| 970 | await h.press("e"); | |
| 971 | await h.press("esc"); | |
| 972 | expect(h.text()).toContain("70,item 70"); | |
| 973 | expect(h.text()).not.toContain("│ item"); | |
| 974 | await h.press("s"); | |
| 975 | expect(h.text()).toContain("id │ name"); | |
| 976 | ||
| 977 | await openFile(h, "bad.csv"); | |
| 978 | await h.press("s"); | |
| 979 | expect(h.text()).toContain("not a table: line 2"); | |
| 980 | } finally { | |
| 981 | h.stop(); | |
| 982 | } | |
| 983 | }); | |
| 984 | ||
| 985 | test("an .xlsx opens as its first sheet's table, with the sheet names on top", async () => { | |
| 986 | const made = await createRepo(forge, alice, { name: "books", visibility: "public", description: "sheets" }); | |
| 987 | if (!made.ok) throw new Error("repo failed"); | |
| 988 | const book = zip({ | |
| 989 | "[Content_Types].xml": "<Types/>", | |
| 990 | "xl/workbook.xml": `<workbook><sheets><sheet name="Totals" sheetId="1" r:id="rId1"/><sheet name="Other" sheetId="2" r:id="rId2"/></sheets></workbook>`, | |
| 991 | "xl/_rels/workbook.xml.rels": `<Relationships><Relationship Id="rId1" Target="worksheets/sheet1.xml"/></Relationships>`, | |
| 992 | "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>`, | |
| 993 | }); | |
| 994 | await commitToBranch(forge, alice, made.value, { | |
| 995 | message: "seed", | |
| 996 | files: [{ path: "sales.xlsx", content: book }], | |
| 997 | }); | |
| 998 | const h = boot(); | |
| 999 | try { | |
| 1000 | await h.settle(); | |
| 1001 | await open(h, "books"); | |
| 1002 | await openFile(h, "sales.xlsx"); | |
| 1003 | expect(h.text()).toContain("Sheet 1 (shown): Totals"); | |
| 1004 | expect(h.text()).toContain("Sheet 2: Other"); | |
| 1005 | expect(h.text()).toContain("Widget"); | |
| 1006 | expect(h.text()).toContain("42"); | |
| 1007 | } finally { | |
| 1008 | h.stop(); | |
| 1009 | } | |
| 1010 | }); | |
| 1011 | test("a SQLite file opens as one table, its schema on top, paged by 100 with > < and } {", async () => { | |
| 1012 | const made = await createRepo(forge, alice, { name: "dbs", visibility: "public", description: "data" }); | |
| 1013 | if (!made.ok) throw new Error("repo failed"); | |
| 1014 | const mem = new Database(":memory:"); | |
| 1015 | mem.run("CREATE TABLE big (n INTEGER, label TEXT)"); | |
| 1016 | for (let i = 1; i <= 250; i++) mem.run("INSERT INTO big VALUES (?, ?)", [i, `row ${i}`]); | |
| 1017 | mem.run("CREATE TABLE small (word TEXT)"); | |
| 1018 | mem.run("INSERT INTO small VALUES ('hello')"); | |
| 1019 | const bytes = mem.serialize(); | |
| 1020 | mem.close(); | |
| 1021 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "data.db", content: bytes }] }); | |
| 1022 | const h = boot(); | |
| 1023 | try { | |
| 1024 | await h.settle(); | |
| 1025 | await open(h, "dbs"); | |
| 1026 | await openFile(h, "data.db"); | |
| 1027 | expect(h.text()).toContain("Table 1 of 2: big"); | |
| 1028 | expect(h.text()).toContain("rows 1–100 of 250"); | |
| 1029 | expect(h.text()).toContain("INTEGER"); | |
| 1030 | expect(h.text()).toContain("row 1"); | |
| 1031 | await h.press(">"); | |
| 1032 | expect(h.text()).toContain("rows 101–200 of 250"); | |
| 1033 | await h.press(">"); | |
| 1034 | await h.press(">"); | |
| 1035 | expect(h.text()).toContain("rows 201–250 of 250"); | |
| 1036 | await h.press("<"); | |
| 1037 | expect(h.text()).toContain("rows 101–200 of 250"); | |
| 1038 | await h.press("}"); | |
| 1039 | expect(h.text()).toContain("Table 2 of 2: small"); | |
| 1040 | expect(h.text()).toContain("rows 1–1 of 1"); | |
| 1041 | expect(h.text()).toContain("hello"); | |
| 1042 | } finally { | |
| 1043 | h.stop(); | |
| 1044 | } | |
| 1045 | }); | |
| 1046 | test("a .pptx opens as its slide titles", async () => { | |
| 1047 | const made = await createRepo(forge, alice, { name: "decks", visibility: "public", description: "slides" }); | |
| 1048 | if (!made.ok) throw new Error("repo failed"); | |
| 1049 | const deck = zip({ | |
| 1050 | "[Content_Types].xml": "<Types/>", | |
| 1051 | "ppt/presentation.xml": `<p:presentation><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`, | |
| 1052 | "ppt/_rels/presentation.xml.rels": `<Relationships><Relationship Id="rId1" Target="slides/slide1.xml"/></Relationships>`, | |
| 1053 | "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>`, | |
| 1054 | }); | |
| 1055 | await commitToBranch(forge, alice, made.value, { message: "seed", files: [{ path: "talk.pptx", content: deck }] }); | |
| 1056 | const h = boot(); | |
| 1057 | try { | |
| 1058 | await h.settle(); | |
| 1059 | await open(h, "decks"); | |
| 1060 | await openFile(h, "talk.pptx"); | |
| 1061 | expect(h.text()).toContain("Launch plan"); | |
| 1062 | } finally { | |
| 1063 | h.stop(); | |
| 1064 | } | |
| 1065 | }); | |
| 629 | 1066 | }); |
new above
offline
Re-merging the second half into this file undoes the split made for the 20 s file budget. Keep the two files, or show this file under budget under load.