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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/8269-test-render-media-test-ts-is-never-red-o → main 1 commit fork
1 file
changed +18
−5
test/render-media.test.ts +18 −5
| @@ -4,6 +4,12 @@ | ||
| 4 | 4 | * file too long for the page to read still plays, and seeks by Range; a |
| 5 | 5 | * name the bytes contradict keeps the source view; and the "can't play" |
| 6 | 6 | * 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. | |
| 7 | 13 | */ |
| 8 | 14 | |
| 9 | 15 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| @@ -11,7 +17,9 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 11 | 17 | import { tmpdir } from "node:os"; |
| 12 | 18 | import { join } from "node:path"; |
| 13 | 19 | import { createApp, type App } from "../src/app.ts"; |
| 20 | import { createSession } from "../src/core/sessions.ts"; | |
| 14 | 21 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 22 | import { setCrawlClock } from "../src/http/crawl.ts"; | |
| 15 | 23 | import { serve, type Servers } from "../src/http/server.ts"; |
| 16 | 24 | import { shellJs } from "../src/web/client.ts"; |
| 17 | 25 | import { MEDIA_PLAY_JS } from "../src/web/render/player.ts"; |
| @@ -48,9 +56,13 @@ let dataDir = ""; | ||
| 48 | 56 | let app: App; |
| 49 | 57 | let servers: Servers; |
| 50 | 58 | let base = ""; |
| 59 | let cookie = ""; | |
| 60 | ||
| 61 | const get = (path: string, headers: Record<string, string> = {}): Promise<Response> => | |
| 62 | fetch(`${base}${path}`, { headers: { cookie, ...headers } }); | |
| 51 | 63 | |
| 52 | 64 | 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}`); | |
| 54 | 66 | expect(res.status).toBe(200); |
| 55 | 67 | return res.text(); |
| 56 | 68 | }; |
| @@ -60,8 +72,11 @@ beforeAll(async () => { | ||
| 60 | 72 | app = createApp({ dataDir, port: 0 }); |
| 61 | 73 | servers = await serve(app); |
| 62 | 74 | base = servers.url; |
| 75 | // The gate's load, on every run: the anonymous budget at its smallest. | |
| 76 | setCrawlClock(app, Date.now, true); | |
| 63 | 77 | const a = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-media-passphrase" }); |
| 64 | 78 | if (!a.ok) throw new Error("signup failed"); |
| 79 | cookie = `forge_session=${createSession(app.db, a.value.id).token}`; | |
| 65 | 80 | const repo = await createRepo(app, a.value, { name: "tapes", visibility: "public" }); |
| 66 | 81 | if (!repo.ok) throw new Error("repo failed"); |
| 67 | 82 | const made = await commitToBranch(app, a.value, repo.value, { |
| @@ -116,7 +131,7 @@ describe("audio and video on the blob page", () => { | ||
| 116 | 131 | }); |
| 117 | 132 | |
| 118 | 133 | 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"); | |
| 120 | 135 | const text = await res.text(); |
| 121 | 136 | expect(text).not.toContain("<video"); |
| 122 | 137 | expect(text).toContain("Binary file"); |
| @@ -126,9 +141,7 @@ describe("audio and video on the blob page", () => { | ||
| 126 | 141 | const text = await page("long.mp4"); |
| 127 | 142 | expect(text).toContain('<source src="/alice/tapes/media/main/long.mp4" type="video/mp4"'); |
| 128 | 143 | 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" }); | |
| 132 | 145 | expect(res.status).toBe(206); |
| 133 | 146 | expect(res.headers.get("content-range")).toBe(`bytes 750000-750099/${LONG.length}`); |
| 134 | 147 | expect(res.headers.get("content-type")).toBe("video/mp4"); |
new above
offline