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

test/render-media.test.ts is never red on a pull whose diff it does not touch #8274

Merged opened this

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

Merged

scout/forge:scout/8269-test-render-media-test-ts-is-never-red-o → main 1 commit fork

  • Merged. scout/8269-test-render-media-test-ts-is-never-red-o was merged into main as 4020042.

Review

Sign in to review this change.
1 file changed +18 −5
test/render-media.test.ts +18 −5
@@ -4,6 +4,12 @@
44 * file too long for the page to read still plays, and seeks by Range; a
55 * name the bytes contradict keeps the source view; and the "can't play"
66 * note is in the markup for the shell script to show.
7 *
8 * The pages are read signed in, and the crawl clock is held "behind" (#8269):
9 * an anonymous reader's deep-page budget is 30 a minute, a quarter of that
10 * while the event loop runs late, and under the gate's load this file's
11 * twelve reads ran past it and were answered 429. What is drawn here does
12 * not depend on who reads it; the budget has its own suite.
713 */
814
915 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
@@ -11,7 +17,9 @@ import { mkdtemp, rm } from "node:fs/promises";
1117 import { tmpdir } from "node:os";
1218 import { join } from "node:path";
1319 import { createApp, type App } from "../src/app.ts";
20 import { createSession } from "../src/core/sessions.ts";
1421 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
22 import { setCrawlClock } from "../src/http/crawl.ts";
1523 import { serve, type Servers } from "../src/http/server.ts";
1624 import { shellJs } from "../src/web/client.ts";
1725 import { MEDIA_PLAY_JS } from "../src/web/render/player.ts";
@@ -48,9 +56,13 @@ let dataDir = "";
4856 let app: App;
4957 let servers: Servers;
5058 let base = "";
59 let cookie = "";
60
61 const get = (path: string, headers: Record<string, string> = {}): Promise<Response> =>
62 fetch(`${base}${path}`, { headers: { cookie, ...headers } });
5163
5264 const page = async (path: string): Promise<string> => {
53 const res = await fetch(`${base}/alice/tapes/blob/main/${path}`);
65 const res = await get(`/alice/tapes/blob/main/${path}`);
5466 expect(res.status).toBe(200);
5567 return res.text();
5668 };
@@ -60,8 +72,11 @@ beforeAll(async () => {
6072 app = createApp({ dataDir, port: 0 });
6173 servers = await serve(app);
6274 base = servers.url;
75 // The gate's load, on every run: the anonymous budget at its smallest.
76 setCrawlClock(app, Date.now, true);
6377 const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-media-passphrase" });
6478 if (!a.ok) throw new Error("signup failed");
79 cookie = `forge_session=${createSession(app.db, a.value.id).token}`;
6580 const repo = await createRepo(app, a.value, { name: "tapes", visibility: "public" });
6681 if (!repo.ok) throw new Error("repo failed");
6782 const made = await commitToBranch(app, a.value, repo.value, {
@@ -116,7 +131,7 @@ describe("audio and video on the blob page", () => {
116131 });
117132
118133 test("Source drops the player", async () => {
119 const res = await fetch(`${base}/alice/tapes/blob/main/v.mp4?view=source`);
134 const res = await get("/alice/tapes/blob/main/v.mp4?view=source");
120135 const text = await res.text();
121136 expect(text).not.toContain("<video");
122137 expect(text).toContain("Binary file");
@@ -126,9 +141,7 @@ describe("audio and video on the blob page", () => {
126141 const text = await page("long.mp4");
127142 expect(text).toContain('<source src="/alice/tapes/media/main/long.mp4" type="video/mp4"');
128143 expect(text).toContain("1.4 MB · MPEG-4");
129 const res = await fetch(`${base}/alice/tapes/media/main/long.mp4`, {
130 headers: { range: "bytes=750000-750099" },
131 });
144 const res = await get("/alice/tapes/media/main/long.mp4", { range: "bytes=750000-750099" });
132145 expect(res.status).toBe(206);
133146 expect(res.headers.get("content-range")).toBe(`bytes 750000-750099/${LONG.length}`);
134147 expect(res.headers.get("content-type")).toBe("video/mp4");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs