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

A file that opens as plain source says in one line why it was not drawn #15723

Merged opened this

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

Merged

scout/forge:scout/15719-a-file-that-opens-as-plain-source-says-i → main 0 commits fork 4 threads · 4 unresolved

  • Merged. scout/15719-a-file-that-opens-as-plain-source-says-i was merged into main as 5f17f15.

Review

Sign in to review this change.
9 files changed +304 −10
docs/features/plain-source-reason.md added +18
@@ -0,0 +1,18 @@
1 ---
2 topic: Files in the browser
3 row: Why a file opened as plain source
4 ---
5 # Why a file opened as plain source
6
7 When a file's name says it is a drawable kind (a picture, a table, a PSD) but its bytes do not look like it,
8 for example a `.png` whose bytes are text, the file opens as plain source and one quiet line says why:
9 `its bytes do not look like image`. A kind the forge has no viewer for says `no viewer for <kind> yet`.
10 A file over its kind's size limit says `too large (2.1 MB; the limit for html is 2 MB)`, and the
11 empty state under it only offers the download, so the size and the limit are said once.
12 Ordinary text files show no line.
13
14 On the web, open `/<owner>/<repo>/blob/<ref>/<path>`: the line sits above the source.
15 In the terminal (`FORGE_APP_SSH`), open the file in the workspace: the same words stand as the first row
16 of the file view, text or hex, and stay while you scroll; a too-large file says them in its note.
17
18 Try it: commit a `.png` containing text, then open it on either door.
src/tui/screens/workspace.ts +19 −2
@@ -132,6 +132,7 @@ import { archiveNote } from "../ui/archive-note.ts";
132132 import { holdsExif, readExif } from "../../web/render/exif.ts";
133133 import { psdNote } from "../ui/psd-note.ts";
134134 import { mediaNote } from "../ui/media-note.ts";
135 import { plainReason } from "../../web/render/renderers.ts";
135136 import { undrawable, UNDRAWN } from "../../web/render/undrawable.ts";
136137 import { tokColor, type Tokens } from "../ui/theme.ts";
137138 import { card, emptyState, input, noteLines, scrollbar } from "../ui/widgets.ts";
@@ -872,6 +873,8 @@ class Tab {
872873 note = "";
873874 noteTitle = "Not shown";
874875 noteDetail = "";
876 /** The one line saying why this file is plain source; empty for ordinary text. */
877 why = "";
875878 /**
876879 * Non-empty when `raw` is only the start of a larger file: the sentence that says so. It is never
877880 * edited.
@@ -1229,6 +1232,8 @@ interface CacheEntry {
12291232 /** A last line under the note: where to get the file. */
12301233 readonly noteDetail: string;
12311234 readonly cut?: string;
1235 /** Why the file is plain source though its name says otherwise; stands above the text. */
1236 readonly why?: string;
12321237 readonly raw: Uint8Array | null;
12331238 readonly picture: Uint8Array | null;
12341239 readonly sheet: Table | null;
@@ -1548,7 +1553,9 @@ export function workspaceScreen(
15481553 } else if (read.value.kind === "too_large") {
15491554 // One line a part, so the pane keeps the whole reason and the way to the download.
15501555 const said = undrawable(t.path, read.value, formatSize);
1551 const lines = said === undefined ? [`${formatSize(read.value.size)} — over the render cap.`] : [said.name, said.size, said.reason];
1556 // The registry's too-large line, when it has one, stands in for the reason: said once.
1557 const why = plainReason(t.path, read.value);
1558 const lines = said === undefined ? [why ?? `${formatSize(read.value.size)} — over the render cap.`] : [said.name, said.size, why ?? said.reason];
15521559 // A photo's EXIF is in its head, so its facts are read even when the file is not.
15531560 const photo = holdsExif(t.path) && read.value.head !== undefined ? readExif(read.value.head).map((f) => `${f.label}: ${f.value}`) : [];
15541561 note = `${[...lines, ...photo].join("\n")}\n\n${downloadAt(t.path)}`;
@@ -1589,7 +1596,9 @@ export function workspaceScreen(
15891596 cut = `Showing the first ${formatSize(read.value.body.length)} of ${formatSize(read.value.size)}, read-only. The rest is in the raw file.`;
15901597 }
15911598 }
1592 entry = { note, noteTitle, noteDetail, cut, raw, picture, sheet, db, ...(big === undefined ? {} : { big }) };
1599 // A too-large file says its reason in the note; the line above the source is for the rest.
1600 const why = read.ok && read.value.kind !== "too_large" ? (plainReason(t.path, read.value) ?? "") : "";
1601 entry = { note, noteTitle, noteDetail, cut, why, raw, picture, sheet, db, ...(big === undefined ? {} : { big }) };
15931602 remember(key, entry);
15941603 }
15951604 if (stale(mine)) return;
@@ -1599,6 +1608,7 @@ export function workspaceScreen(
15991608 t.noteDetail = entry.noteDetail;
16001609 t.raw = entry.raw;
16011610 t.cut = entry.cut ?? "";
1611 t.why = entry.why ?? "";
16021612 if (t.cut !== "") ctx.toast(t.cut, "attn");
16031613 t.sheet = entry.sheet;
16041614 t.db = entry.db;
@@ -3264,6 +3274,13 @@ export function workspaceScreen(
32643274 drawTable(s, r, c, t);
outdated

The extra row shifts drawCode by one; confirm click/scroll hit-testing assumes the old offset and test it. Also long reasons are clipped to the width with no ellipsis.

32653275 return;
32663276 }
3277 if (t.why !== "" && r.h > 1) {
3278 // Cut with an ellipsis, never mid-word unannounced; the code under it starts one row down,
3279 // and the wheel and keys scroll by lines, so nothing measures from the pane's top row.
3280 s.text(r.x, r.y, truncate(t.why, Math.max(1, r.w - 1)), style(c.muted, c.bg), r.x + Math.max(0, r.w - 1));
3281 drawCode(s, { x: r.x, y: r.y + 1, w: r.w, h: r.h - 1 }, c, t);
3282 return;
3283 }
32673284 drawCode(s, r, c, t);
32683285 }
32693286
src/web/pages/repo.ts +12 −2
@@ -118,7 +118,7 @@ import { EXIF_WINDOW, holdsExif } from "../render/exif.ts";
118118 import { READ_CEILING } from "../render/psd-read.ts";
119119 import { NO_MEMBER, openMember } from "../render/json-big.ts";
120120 import { CSV_PREFIX_BYTES, fileKind, HEAD_BYTES, isJsonPath, isTablePath, JSON_PREFIX_BYTES, kindByName, needsPaths, RENDER_CAP, sniffType } from "../render/kinds.ts";
121 import { RENDERERS, rendererFor } from "../render/renderers.ts";
121 import { plainReason, RENDERERS, rendererFor, TOO_LARGE } from "../render/renderers.ts";
122122 import { downloadHref, mediaHref } from "./media.ts";
123123 import { browseBase, localScope, type RepoScope } from "../scope.ts";
124124 import { repoForkOf } from "../../core/origins.ts";
@@ -1202,6 +1202,9 @@ function blobRenderer(scope: RepoScope, path: string, blob: Blob): ReturnType<ty
12021202 return found?.render === RENDERERS.pdf && scope.kind !== "local" ? undefined : found;
12031203 }
12041204
1205 /** The empty state's note when the reason line above it already says the size and the limit. */
1206 const SAID_ABOVE = "Download it to read it.";
1207
12051208 /** Why an archive too big to list is not listed, as one sentence. */
12061209 function overCap(path: string, blob: Blob): string | undefined {
12071210 if (kindByName(path) === "notebook" && blob.size > RENDER_CAP.notebook)
@@ -1308,11 +1311,17 @@ export function renderBlob(
13081311 })
13091312 : undefined;
13101313 const fellBack = drawn?.fallback;
1314 // A kind's own over-the-cap sentence (G-code, a notebook, an archive) already says why.
1315 const capSays = overCap(o.path, blob);
1316 // The registry's own reason a file is plain source; nothing for ordinary text.
1317 const plainWhy = renderer === undefined && capSays === undefined ? plainReason(o.path, blob, RENDERERS, { media: scope.kind === "local" }) : undefined;
1318 // The line above says the size and the limit, so the empty state under it does not (say it once).
1319 const saysSize = plainWhy?.startsWith(TOO_LARGE) === true;
13111320 const { content, lines, summary } =
13121321 drawn !== undefined && fellBack === undefined
13131322 ? drawn
13141323 : {
1315 ...blobBody(base, o.ref, o.path, blob, o.highlighted, o.all, o.rows, fellBack ?? overCap(o.path, blob)),
1324 ...blobBody(base, o.ref, o.path, blob, o.highlighted, o.all, o.rows, fellBack ?? capSays ?? (saysSize && blob.kind === "too_large" ? SAID_ABOVE : undefined)),
13161325 summary: undefined,
13171326 };
13181327 const sizeText =
@@ -1378,6 +1387,7 @@ export function renderBlob(
13781387 fellBack !== undefined,
13791388 () => html`<p class="muted small mb">Showing the source: ${fellBack}</p>`,
13801389 )}
1390 ${when(plainWhy !== undefined, () => html`<p class="muted small mb" data-plain-why>${plainWhy}</p>`)}
13811391 ${content}
13821392 </div>`;
13831393 }
src/web/render/renderers.ts +51 −4
@@ -49,6 +49,7 @@ import { htmlPreview } from "./html_preview.ts";
4949 import { image } from "./image.ts";
5050 import { holdsExif } from "./exif.ts";
5151 import { fileKind, HEAD_BYTES, isJsonPath, kindByName, NO_BYTES, RENDER_CAP, type FileKind } from "./kinds.ts";
52 import { limit } from "./undrawable.ts";
5253 import { log, drawsLog } from "./log.ts";
5354 import { makefile } from "./makefile.ts";
5455 import { markdown } from "./markdown.ts";
@@ -235,6 +236,43 @@ export function rendererFor(
235236 renderers: Partial<Readonly<Record<FileKind, Renderer>>> = RENDERERS,
236237 where: { readonly media: boolean } = { media: true },
237238 ): { render: Renderer; body: Uint8Array } | undefined {
239 const d = decide(path, blob, renderers, where);
240 return "render" in d ? d : undefined;
241 }
242
243 /**
244 * Why a file that is not plain text opens as plain source, in one line, or undefined when it is
245 * drawn or needs no renderer (ordinary text, a binary with its own view). Decided by the same
246 * call as `rendererFor`, never re-derived by a page.
247 */
248 export function plainReason(
249 path: string,
250 blob: Blob,
251 renderers: Partial<Readonly<Record<FileKind, Renderer>>> = RENDERERS,
252 where: { readonly media: boolean } = { media: true },
253 ): string | undefined {
254 const d = decide(path, blob, renderers, where);
255 return "render" in d ? undefined : d.why;
256 }
257
258 /**
259 * The too-large reason, as the issue words it: `too large (3.2 MB; the limit for html is 2 MB)`.
260 */
261 function tooLarge(size: number, kind: FileKind): string {
262 return `${TOO_LARGE} (${limit(size)}; the limit for ${kind} is ${limit(RENDER_CAP[kind])})`;
263 }
264
265 /** How a too-large reason begins, so a door can tell it from the others and not say it twice. */
266 export const TOO_LARGE = "too large";
267
268 type Decision = { render: Renderer; body: Uint8Array } | { why?: string };
269
270 function decide(
271 path: string,
272 blob: Blob,
273 renderers: Partial<Readonly<Record<FileKind, Renderer>>>,
274 where: { readonly media: boolean },
275 ): Decision {
238276 // A file the source gave no bytes of is taken at its name: STL, OBJ and
239277 // glTF have no signature to read anyway.
240278 const named =
@@ -245,12 +283,21 @@ export function rendererFor(
245283 : kindByName(path);
246284 // A bill of materials too big to parse keeps the JSON view it had, outline and all.
247285 const kind = named === "sbom" && blob.size > RENDER_CAP.sbom ? "config" : named;
outdated

Principle 1 / issue box 1: too-large returns {} so no too large (N MB; the limit for <kind> is M MB) line exists. Return the reason here and drop the duplicate empty-state sentence.

286 // A file the source did not read whole has no bytes to compare with its name.
287 const said = blob.kind !== "too_large";
288 const byName = kindByName(path);
289 const plain = kind === "text" || kind === "binary";
248290 // A table's cap is lifted only for a body the source already cut to a prefix.
249291 const prefixed = kind === "csv" && blob.kind === "text" && blob.partial === true;
250292 const outlined = kind === "config" && blob.kind === "text" && blob.partial === true && isJsonPath(path);
251 if (blob.size > RENDER_CAP[kind] && !prefixed && !outlined) return undefined;
252 if (MEDIA_KINDS.has(kind) && !where.media) return undefined;
253 if (blob.kind === "too_large" && !MEDIA_KINDS.has(kind) && kind !== "psd" && kind !== "cad") return undefined;
293 if (said && plain && byName !== "text" && byName !== "binary" && renderers[byName] !== undefined)
294 return { why: `its bytes do not look like ${byName}` };
295 // Over its kind's own limit: the line says both sizes, and the doors' empty states do not repeat
296 // it.
297 if (blob.size > RENDER_CAP[kind] && !prefixed && !outlined)
298 return plain ? {} : { why: tooLarge(blob.size, kind) };
299 if (MEDIA_KINDS.has(kind) && !where.media) return {};
300 if (blob.kind === "too_large" && !MEDIA_KINDS.has(kind) && kind !== "psd" && kind !== "cad") return {};
254301 // A kind may draw only some of its files: `config` draws JSON, YAML and
255302 // TOML as a form, and leaves the rest (INI, .env …) their source.
256303 // A log with no escape and no marked line keeps the source view, exactly as plain text.
@@ -260,7 +307,7 @@ export function rendererFor(
260307 (kind === "log" && blob.kind !== "too_large" && !drawsLog(blob.body)) ||
261308 (kind === "package" && blob.kind !== "too_large" && readPackage(blob.body) === undefined);
262309 const render = declined ? undefined : renderers[kind];
263 if (render === undefined) return undefined;
310 if (render === undefined) return said && !plain && !declined ? { why: `no viewer for ${kind} yet` } : {};
264311 // A PSD over the read ceiling is drawn from its head: the header holds the facts. So is a
265312 // photo's: its EXIF is in the first 64 KiB.
266313 const fromHead = kind === "psd" || kind === "cad" || (kind === "image" && holdsExif(path));
src/web/render/undrawable.ts +2 −1
@@ -19,7 +19,8 @@ export interface UndrawnBlob {
1919 }
2020
2121 const MB = 1_000_000;
22 const limit = (bytes: number): string => (bytes >= MB ? `${+(bytes / MB).toFixed(1)} MB` : `${Math.round(bytes / 1000)} kB`);
22 /** A size as the limits are written: `2 MB`, `800 kB`. */
23 export const limit = (bytes: number): string => (bytes >= MB ? `${+(bytes / MB).toFixed(1)} MB` : `${Math.round(bytes / 1000)} kB`);
2324 const MEDIA: ReadonlySet<FileKind> = new Set<FileKind>(["image", "svg", "pdf", "html", "audio", "video", "model3d"]);
2425
2526 const baseName = (path: string): string => path.slice(path.lastIndexOf("/") + 1);
test/blob-media-ceiling.test.ts +3 −1
@@ -192,7 +192,9 @@ describe("a large blob on the page", () => {
192192 test("a 3 MB .mp4 of words, and a 3 MB Markdown file, keep the over-cap note", async () => {
193193 for (const path of ["words.mp4", "notes.md"]) {
194194 const text = await (await fetch(`${base}/alice/big/blob/main/${path}`)).text();
195 expect(text).toContain("Over the 1 MB limit");
195 // The limit is said once: the reason line above, or the empty state's note when there is
196 // none.
197 expect((text.match(/Over the 1 MB limit|too large \(/g) ?? []).length).toBe(1);
196198 expect(text).not.toContain("<video");
197199 }
198200 });
test/blob-notebook-page.test.ts +3
@@ -62,7 +62,10 @@ describe("a .ipynb on its blob page", () => {
6262 const res = await fetch(`${base}/alice/p/blob/main/big.ipynb`);
6363 const text = await res.text();
6464 expect(res.status).toBe(200);
65 // The notebook's own sentence says the limit, once; the generic reason line does not repeat it
66 // (#15719).
6567 expect(text).toContain("This notebook is over 1 MB, so it is not drawn as cells");
68 expect(text).not.toContain("data-plain-why");
6669 expect(text).not.toContain("In [");
6770 });
6871
test/gcode-page.test.ts +2
@@ -120,6 +120,8 @@ describe("a G-code file on the page", () => {
120120 expect(text).toContain("Download");
121121 expect(text).not.toContain("gcode-view");
122122 expect(text).not.toContain('name="layer"');
123 // The G-code sentence says the limit; the generic reason line does not say it again (#15719).
124 expect(text).not.toContain("data-plain-why");
123125 });
124126
125127 test("the local source reads a G-code file past 5 MB, up to the cap, and no further", async () => {
test/plain-reason.test.ts added +194
@@ -0,0 +1,194 @@
1 /**
2 * A file that opens as plain source says in one line why it was not drawn (#15719): too large,
3 * bytes that do not match its name, a kind with no renderer. Ordinary text says nothing.
4 */
5 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
11 import { repoDir } from "../src/git/repos.ts";
12 import { serve, type Servers } from "../src/http/server.ts";
13 import { plainReason, RENDERERS } from "../src/web/render/renderers.ts";
14 import { seedAdmin } from "./helpers/admin.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16 import { workspaceFixture, type Fixture } from "./helpers/tui-workspace.ts";
17
18 quietLogs();
19
20 const enc = (s: string): Uint8Array => new TextEncoder().encode(s);
21 const text = (s: string, size = s.length) => ({ kind: "text" as const, body: enc(s), size });
22
23 /** Commits a 2.1 MB `big.html` onto main in the repository at `dir`, with git plumbing. */
24 function addBig(dir: string): void {
25 const run = (args: string[], stdin?: Uint8Array | string): string => {
26 const out = Bun.spawnSync(["git", ...args], {
27 cwd: dir,
28 stdin: typeof stdin === "string" ? enc(stdin) : (stdin ?? "ignore"),
29 env: { ...process.env, GIT_AUTHOR_NAME: "alice", GIT_AUTHOR_EMAIL: "[email protected]", GIT_COMMITTER_NAME: "alice", GIT_COMMITTER_EMAIL: "[email protected]" },
30 });
31 if (out.exitCode !== 0) throw new Error(`git ${args[0]}: ${out.stderr.toString()}`);
32 return out.stdout.toString().trim();
33 };
34 const blob = run(["hash-object", "-w", "--stdin"], enc("<p>" + "x".repeat(2_100_000) + "</p>"));
35 const tree = run(["mktree"], `${run(["ls-tree", "main"])}\n100644 blob ${blob}\tbig.html\n`);
36 run(["update-ref", "refs/heads/main", run(["commit-tree", tree, "-p", "main", "-m", "big"])]);
37 }
38
39 describe("plainReason", () => {
40 test("too large names the size and its kind's limit", () => {
41 expect(plainReason("a.html", text("<p>x</p>", 2_500_000))).toBe("too large (2.5 MB; the limit for html is 2 MB)");
42 expect(plainReason("a.html", { kind: "too_large", size: 3_000_000 })).toBe("too large (3 MB; the limit for html is 2 MB)");
43 });
44 test("bytes that do not look like the name", () => {
45 expect(plainReason("a.png", text("just words"))).toBe("its bytes do not look like image");
46 });
47 test("a kind with no renderer", () => {
48 const { markdown: _gone, ...rest } = RENDERERS;
49 expect(plainReason("a.md", text("# hi"), rest)).toBe("no viewer for markdown yet");
50 });
51 test("ordinary text, and a drawn file, say nothing", () => {
52 expect(plainReason("a.txt", text("hello"))).toBeUndefined();
53 expect(plainReason("a.ts", text("let x = 1"))).toBeUndefined();
54 expect(plainReason("a.md", text("# hi"))).toBeUndefined();
55 expect(plainReason("a.txt", text("hello", 900_000))).toBeUndefined();
56 });
57 });
58
59 describe("the file page and the terminal", () => {
60 let dataDir: string;
61 let app: App;
62 let servers: Servers;
63 let fx: Fixture;
64
65 beforeAll(async () => {
66 dataDir = await mkdtemp(join(tmpdir(), "forge-plain-"));
67 app = createApp({ dataDir, port: 0 });
68 servers = await serve(app);
69 const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-plain-passphrase" });
70 if (!a.ok) throw new Error("signup failed");
71 const r = await createRepo(app, a.value, { name: "p", visibility: "public" });
72 if (!r.ok) throw new Error("repo failed");
73 const made = await commitToBranch(app, a.value, r.value, {
74 message: "seed",
75 files: [
76 { path: "fake.png", content: "<b>not a picture</b>" },
77 { path: "notes.txt", content: "plain" },
78 { path: "bad.pem", content: "-----BEGIN CERTIFICATE-----\nnot a certificate\n-----END CERTIFICATE-----\n" },
79 ],
80 });
81 if (!made.ok) throw new Error("commit failed " + JSON.stringify(made.error));
82 // Past the commit limit, so written with git itself.
83 addBig(repoDir(app.reposRoot, "alice", "p"));
84 fx = await workspaceFixture();
85 const tl = await createRepo(fx.forge, fx.alice, { name: "tl", visibility: "public", description: "t" });
86 if (!tl.ok) throw new Error("repo failed");
87 const long = Array.from({ length: 200 }, (_, i) => `row ${i + 1}`).join("\n");
88 await commitToBranch(fx.forge, fx.alice, tl.value, { message: "seed", files: [{ path: "long.png", content: long }] });
89 addBig(repoDir(fx.forge.reposRoot, "alice", "tl"));
90 }, 60_000);
91
92 afterAll(async () => {
93 await servers?.stop();
94 app?.close();
95 await fx?.close();
96 await rm(dataDir, { recursive: true, force: true });
97 });
98
99 const page = async (path: string) => (await fetch(`${servers.url}/alice/p/blob/main/${path}`)).text();
100
101 test("bytes that do not match: one line, escaped", async () => {
102 const body = await page("fake.png");
103 expect(body).toContain(`data-plain-why>its bytes do not look like image</p>`);
104 expect(body).not.toContain("<b>not a picture</b>");
105 });
106 test("too large: one line says the size and the limit, and the empty state does not repeat it", async () => {
107 const body = await page("big.html");
108 expect(body).toContain(`data-plain-why>too large (2.1 MB; the limit for html is 2 MB)</p>`);
109 expect(body.match(/limit for html/g)).toHaveLength(1);
110 expect(body).toContain("Download it to read it.");
111 });
112 test("a file that falls back and has a reason shows at most one reason line", async () => {
113 const body = await page("bad.pem");
114 const lines = (body.match(/data-plain-why>/g) ?? []).length + (body.match(/Showing the source: /g) ?? []).length;
115 expect(lines).toBe(1);
116 });
117 test("plain text adds no line", async () => {
118 expect(await page("notes.txt")).not.toContain("data-plain-why");
119 });
120
121 test("the terminal keeps the line above a binary file too, not as a toast", async () => {
122 const made = await createRepo(fx.forge, fx.alice, { name: "tb", visibility: "public", description: "t" });
123 if (!made.ok) throw new Error("repo failed");
124 await commitToBranch(fx.forge, fx.alice, made.value, { message: "seed", files: [{ path: "bin.pcap", content: new Uint8Array([0, 1, 2, 0, 0, 255]) }] });
125 const h = fx.boot();
126 try {
127 await h.settle();
128 await fx.open(h, "tb");
129 await fx.openFile(h, "bin.pcap");
130 expect(h.text()).toContain("its bytes do not look like pcap");
131 await h.settle();
132 expect(h.text()).toContain("its bytes do not look like pcap");
133 } finally {
134 h.stop();
135 }
136 });
137
138 test("the terminal: under the reason row, the wheel scrolls by lines and the rows are the right ones", async () => {
139 const h = fx.boot(undefined, 120, 20);
140 try {
141 await h.settle();
142 await fx.open(h, "tl");
143 await fx.openFile(h, "long.png");
144 const screen = (): string[] => h.text().split("\n");
145 const why = screen().findIndex((r) => r.includes("its bytes do not look like image"));
146 expect(why).toBeGreaterThanOrEqual(0);
147 // The row under the reason is line 1, not line 2: the code starts one row down, nothing
148 // skipped.
149 expect(screen()[why + 1]).toMatch(/\b1 row 1\b/);
150 h.app.dispatch({ type: "mouse", kind: "wheel-down", button: 0, x: 100, y: why + 3, ctrl: false, alt: false, shift: false });
151 await h.settle();
152 const top = screen()[why + 1]!;
153 const n = Number(/(\d+) row (\d+)/.exec(top)?.[1]);
154 expect(n).toBeGreaterThan(1);
155 expect(top).toContain(`row ${n}`);
156 // The reason row holds still, and the last line is reachable: the pane is one row shorter,
157 // not cut.
158 expect(screen()[why]).toContain("its bytes do not look like image");
159 await h.press("G");
160 expect(h.text()).toContain("row 200");
161 } finally {
162 h.stop();
163 }
164 });
165
166 test("the terminal says the too-large words once, in the note", async () => {
167 const h = fx.boot();
168 try {
169 await h.settle();
170 await fx.open(h, "tl");
171 await fx.openFile(h, "big.html");
172 const screen = h.text();
173 expect(screen).toContain("too large (2.1 MB; the limit for html is 2 MB)");
174 expect(screen.match(/limit for html/g)).toHaveLength(1);
175 } finally {
176 h.stop();
177 }
178 });
179
180 test("the terminal says the same words", async () => {
181 const made = await createRepo(fx.forge, fx.alice, { name: "tp", visibility: "public", description: "t" });
182 if (!made.ok) throw new Error("repo failed");
183 await commitToBranch(fx.forge, fx.alice, made.value, { message: "seed", files: [{ path: "fake.png", content: "just words" }] });
184 const h = fx.boot();
185 try {
186 await h.settle();
187 await fx.open(h, "tp");
188 await fx.openFile(h, "fake.png");
189 expect(h.text()).toContain("its bytes do not look like image");
190 } finally {
191 h.stop();
192 }
193 });
194 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs