1a2a2a366752
bound and cache the heavy public routes (v3.2.9)
- time
- 2026-11-17 01:59 UTC · 1 week ago
- machine
- Junes-MacBook-Pro.local
- agent
- deepseek/deepseek-flash
- session
- review findings
- parent
- 28ac0b3567c7
↓ kepr-1a2a2a36.tar.gzatlas at this save
files changed11 files
package.json+1 −1scripts/budget.ts+2 −2src/mirror/remote.ts+40 −8src/pages/files.ts+51 −7src/pages/limit.ts+39 −0src/pages/save.ts+39 −5src/tarball/archive.ts+11 −4src/tarball/cache.ts+36 −14tests/pages.test.ts+35 −0tests/releases.test.ts+3 −2tests/tarball.test.ts+17 −4package.json+1 −1
@@ -1,6 +1,6 @@11 {22 "name": "kepr",3- "version": "3.2.8",3+ "version": "3.2.9",44 "private": true,55 "type": "module",66 "scripts": {scripts/budget.ts+2 −2
@@ -5,10 +5,10 @@55 // Prefixes are matched in order, so the specific files come before the directories.66 const TS_AREAS: [string, string[], number][] = [77 ["bucket", ["src/bucket/"], 1380],8- ["mirror", ["src/mirror/"], 1390],8+ ["mirror", ["src/mirror/"], 1410],99 ["describe", ["src/describe/"], 530],1010 ["pages", ["src/pages/"], 2540],11- ["releases", ["src/releases/"], 800],11+ ["releases", ["src/releases/"], 780],1212 ["tarball", ["src/tarball/"], 300],1313 ["issues", ["src/issues/"], 1700],1414 ["admin", ["src/admin/"], 2800],src/mirror/remote.ts+40 −8
@@ -149,14 +149,46 @@149149 150150 // The whole layout in one response, so a steal costs one request rather than one per key: a151151 // 2,071-save repo took an hour of round trips. Streamed, because it is as big as the repo.152- app.get("/:repo/koh/bundle", (c) =>153- serve(c, c.req.param("repo"), (mirror) =>154- c.body(stream(bundle(mirror)), 200, {155- "Content-Type": "application/octet-stream",156- "Cache-Control": NO_CACHE,157- }),158- ),159- );152+ app.get("/:repo/koh/bundle", async (c) => {153+ const repo = openPublicRepo(ctx, c.req.param("repo"));154+ if (!repo) return miss(c);155+ return c.body(stream(bundled(bundle(repo.mirror), await bundleSlot())), 200, {156+ "Content-Type": "application/octet-stream",157+ "Cache-Control": NO_CACHE,158+ });159+ });160+}161+162+// Two bundle streams at a time. A bundle is as big as the repo and every request shares the one163+// thread, so a third waits its turn rather than starving the pages around it.164+const BUNDLE_LIMIT = 2;165+let bundling = 0;166+const bundleQueue: (() => void)[] = [];167+168+/** A slot for one bundle stream, released when it ends, errors or is cancelled. */169+function bundleSlot(): Promise<() => void> {170+ const release = () => {171+ const next = bundleQueue.shift();172+ if (next) next();173+ else bundling--;174+ };175+ if (bundling < BUNDLE_LIMIT) {176+ bundling++;177+ return Promise.resolve(release);178+ }179+ const { promise, resolve } = Promise.withResolvers<() => void>();180+ bundleQueue.push(() => resolve(release));181+ return promise;182+}183+184+/** A bundle's slot, released as its generator's own `finally` runs: at the end, on an error, and185+ * when a cancelled stream returns it. */186+function* bundled(chunks: Generator<Uint8Array>, release: () => void): Generator<Uint8Array> {187+ try {188+ yield* chunks;189+ } finally {190+ release();191+ }160192 }161193 162194 function stream(chunks: Generator<Uint8Array>): ReadableStream<Uint8Array> {src/pages/files.ts+51 −7
@@ -13,6 +13,7 @@1313 page,1414 pathUrl,1515 } from "./layout.ts";16+import { registerHeavyLimit } from "./limit.ts";1617 import { renderMarkdown } from "./markdown.ts";1718 1819 const IMAGE = /\.(png|jpe?g|gif|webp|avif|ico|svg)$/i;@@ -30,6 +31,9 @@3031 };3132 3233 export function registerFileRoutes(app: Hono, ctx: PageContext): void {34+ // Ahead of this group's routes, and so of every route registered after it: bundle, archive,35+ // saves, files and raw share one per-address budget.36+ registerHeavyLimit(app);3337 app.get("/:repo/files/:path{.+}", async (c) => {3438 const found = findFile(c, ctx);3539 if (!found) return notFound(c, ctx);@@ -52,9 +56,20 @@5256 const found = findFile(c, ctx);5357 if (!found) return notFound(c, ctx);5458 cacheFor(c, found.at !== null);55- const type = contentType(found.path, found.bytes);56- c.header("Content-Type", type);57- return c.body(found.bytes);59+ const bytes = found.bytes;60+ c.header("Content-Type", contentType(found.path, bytes));61+ c.header("Accept-Ranges", "bytes");62+ // One range, as a download manager asks for; anything else, a HEAD or several ranges63+ // included, is the whole file.64+ const [, from = "", to = ""] = /^bytes=(\d*)-(\d*)$/.exec(c.req.header("Range") ?? "") ?? [];65+ if (from === "" && to === "") return c.body(bytes);66+ const start = from === "" ? Math.max(0, bytes.length - Number(to)) : Number(from);67+ const end =68+ from === "" || to === "" ? bytes.length - 1 : Math.min(Number(to), bytes.length - 1);69+ if (start > end) return c.body(null, 416, { "Content-Range": `bytes */${bytes.length}` });70+ return c.body(bytes.slice(start, end + 1), 206, {71+ "Content-Range": `bytes ${start}-${end}/${bytes.length}`,72+ });5873 });5974 }6075 @@ -123,19 +138,48 @@123138 const rendered = renderMarkdown(text, { repo: found.repo, dir, at: found.at });124139 return html`${meta}${toggle}<div class="markdown file-markdown">${rendered}</div>`;125140 }126- return html`${meta}${toggle}${await codeView(text, found.path)}`;141+ return html`${meta}${toggle}${await codeView(text, found)}`;127142 }128- return html`${meta}${await codeView(text, found.path)}`;143+ return html`${meta}${await codeView(text, found)}`;129144 }130145 131146 // Each line is its own anchor target, so `#L42` scrolls and highlights through CSS alone; the132147 // script only adds ranges (`#L42-L50`).133-async function codeView(text: string, path: string): Promise<Html> {134- const lines = await highlightLines(text, path);148+async function codeView(text: string, found: Found): Promise<Html> {149+ const lines = await highlightedLines(text, found);135150 return html`<div class="file-view"><pre class="code"><code>${lines.map(136151 (line, i) =>137152 html`<span class="line" id="L${138153 i + 1139154 }"><a class="ln" href="#L${i + 1}">${i + 1}</a><span class="lc">${line}</span></span>`,140155 )}</code></pre></div>`;156+}157+158+const CACHE_ENTRIES = 100;159+const CACHE_BYTES = 64 * 1024 * 1024;160+const highlighted = new Map<string, { lines: Html[]; bytes: number }>();161+let highlightedBytes = 0;162+163+/** `highlightLines`, remembered by the object's hash: a second view of a 1 MB file skips Shiki. */164+async function highlightedLines(text: string, found: Found): Promise<Html[]> {165+ // The extension names the language and the hash the bytes, so both together name one view.166+ const key = `${found.file.hash}:${found.path.toLowerCase().split(".").pop()}`;167+ const hit = highlighted.get(key);168+ if (hit) {169+ // A hit moves to the end, so the first entry is always the one used longest ago.170+ highlighted.delete(key);171+ highlighted.set(key, hit);172+ return hit.lines;173+ }174+ const lines = await highlightLines(text, found.path);175+ const bytes = lines.reduce((sum, line) => sum + line.value.length, 0);176+ if (bytes > CACHE_BYTES) return lines;177+ highlighted.set(key, { lines, bytes });178+ highlightedBytes += bytes;179+ for (const [old, entry] of highlighted) {180+ if (highlighted.size <= CACHE_ENTRIES && highlightedBytes <= CACHE_BYTES) break;181+ highlighted.delete(old);182+ highlightedBytes -= entry.bytes;183+ }184+ return lines;141185 }src/pages/limit.ts+39 −0
@@ -0,0 +1,39 @@1+import type { Hono } from "hono";2+import { clientIp } from "../server/client.ts";3+4+// The expensive public answers — a whole-repo bundle, a tarball, a highlighted file, a raw object,5+// a save page's diff — carry a per-address budget, so one crawler can't hold the one request6+// thread. A HEAD fetches nothing, and the rest of the site is not counted.7+const RATE = 60; // requests a minute8+const BURST = 20; // allowed at once9+const MINUTE = 60_000;10+const HEAVY = /^\/[^/]+\/(?:koh\/bundle$|archive\/|files\/|raw\/|saves\/)/;11+12+/** 429 with `Retry-After` past the budget; small and in memory, one bucket per address. */13+export function registerHeavyLimit(app: Hono): void {14+ const buckets = new Map<string, { tokens: number; at: number }>();15+ // The whole seconds `ip` must wait for a token, or 0 for one now.16+ const take = (ip: string, now: number): number => {17+ const bucket = buckets.get(ip);18+ // Bounded: an address full again after a quiet minute needs no entry.19+ if (!bucket && buckets.size > 4096) {20+ for (const [key, it] of buckets) {21+ if (it.tokens + ((now - it.at) * RATE) / MINUTE >= BURST) buckets.delete(key);22+ }23+ }24+ const held = (bucket?.tokens ?? BURST) + ((now - (bucket?.at ?? now)) * RATE) / MINUTE;25+ const tokens = Math.min(BURST, held);26+ buckets.set(ip, { tokens: Math.max(0, tokens - 1), at: now });27+ if (tokens >= 1) return 0;28+ return Math.max(1, Math.ceil(((1 - tokens) * MINUTE) / RATE / 1000));29+ };30+ app.use("*", async (c, next) => {31+ const ip = clientIp(c);32+ // An address no runtime gave can't tell clients apart, so it is not counted.33+ if (ip !== "" && c.req.method !== "HEAD" && HEAVY.test(c.req.path)) {34+ const wait = take(ip, Date.now());35+ if (wait > 0) return c.text("too many requests\n", 429, { "Retry-After": String(wait) });36+ }37+ await next();38+ });39+}src/pages/save.ts+39 −5
@@ -47,6 +47,8 @@4747 edits: Edit[];4848 added: number;4949 removed: number;50+ /** The lines this file's diff would show, which is what the page's limit counts. */51+ length: number;5052 };5153 5254 export function registerSavePage(app: Hono, ctx: PageContext): void {@@ -59,7 +61,15 @@5961 const name = repo.settings.name;6062 if (save.id !== id) return c.redirect(`/${name}/saves/${save.id}`, 302);6163 const parent = visibleParent(repo.mirror, save);62- const diffs = changes(repo.mirror, save, parent).map((change) => fileDiff(repo.mirror, change));64+ // Past the page's line limit no file can be shown, so nothing more is diffed: a first import65+ // of thousands of files costs only the files this page shows.66+ let shown = 0;67+ const diffs = changes(repo.mirror, save, parent).map((change) => {68+ const brief = shown >= PAGE_MAX_LINES;69+ const diff = fileDiff(repo.mirror, change, brief);70+ if (!brief && shown + diff.length <= PAGE_MAX_LINES) shown += diff.length;71+ return diff;72+ });6373 // Not a year like other per-save content: a flag or a strip can arrive for this save later.6474 cacheFor(c, false);6575 const [title = "", ...rest] = save.message.split("\n");@@ -140,8 +150,8 @@140150 });141151 }142152 143-function fileDiff(db: Database, change: Change): FileDiff {144- const empty = { oldText: "", newText: "", edits: [], added: 0, removed: 0 };153+function fileDiff(db: Database, change: Change, brief = false): FileDiff {154+ const empty = { oldText: "", newText: "", edits: [], added: 0, removed: 0, length: 0 };145155 const sides = [change.before, change.after];146156 if (sides.some((f) => f && f.size > DIFF_MAX_BYTES))147157 return { ...change, ...empty, kind: "large" };@@ -149,14 +159,38 @@149159 if (!isText(oldBytes as Uint8Array) || !isText(newBytes as Uint8Array)) {150160 return { ...change, ...empty, kind: "binary" };151161 }162+ // An added or removed file's counts are its own lines, so a file past the page's limit needs no163+ // diff to show them; a modified one's counts are only known from the edits, so it is diffed.164+ if (brief && (!change.before || !change.after)) {165+ const count = lineCount(change.before ? oldBytes : newBytes);166+ const gone = change.after ? 0 : count;167+ const gained = change.before ? 0 : count;168+ return {169+ ...change,170+ ...empty,171+ kind: "text",172+ added: gained,173+ removed: gone,174+ length: count === 0 ? 0 : count + 1,175+ };176+ }152177 const oldText = new TextDecoder().decode(oldBytes);153178 const newText = new TextDecoder().decode(newBytes);154179 const edits = diffLines(compared(oldText), compared(newText));155180 const added = edits.filter((e) => e.kind === "+").length;156181 const removed = edits.filter((e) => e.kind === "-").length;157- return { ...change, kind: "text", oldText, newText, edits, added, removed };182+ const length = hunks(edits).reduce((sum, hunk) => sum + hunk.edits.length + 1, 0);183+ return { ...change, kind: "text", oldText, newText, edits, added, removed, length };158184 }159185 186+/** What `lines()` would count, from the bytes: a final newline ends the last line, it adds none. */187+function lineCount(bytes: Uint8Array): number {188+ if (bytes.length === 0) return 0;189+ let newlines = 0;190+ for (const byte of bytes) if (byte === 0x0a) newlines++;191+ return bytes[bytes.length - 1] === 0x0a ? newlines : newlines + 1;192+}193+160194 function lines(text: string): string[] {161195 return text === "" ? [] : text.replace(/\n$/, "").split("\n");162196 }@@ -192,7 +226,7 @@192226 const at = d.status === "removed" ? parent?.id : save.id;193227 const view = `/${name}/files/${pathUrl(d.path)}?at=${at}`;194228 const hunkList = hunks(d.edits);195- const length = hunkList.reduce((sum, h) => sum + h.edits.length + 1, 0);229+ const length = d.length;196230 const mode =197231 d.before && d.after && d.before.executable !== d.after.executable198232 ? html`<p class="diff-note mono">${src/tarball/archive.ts+11 −4
@@ -31,15 +31,22 @@3131 c.header("Cache-Control", "public, max-age=60");3232 return c.redirect(`/${name}/archive/${save.id}.tar.gz`, 302);3333 }34- const bytes = await cachedTarball(bucket, repo.mirror, name, save.id);35- if (!bytes) return notFound(c, ctx);34+ const filename = `${name}-${save.id.slice(0, 8)}.tar.gz`;35+ const tarball = await cachedTarball(bucket, repo.mirror, name, save.id, filename);36+ if (!tarball) return notFound(c, ctx);3637 // §22.2: a Nix fetch is an install. Only the tarball itself counts, not the redirects to3738 // it, and a HEAD fetches nothing.3839 const agent = c.req.header("User-Agent") ?? "";3940 if (c.req.method !== "HEAD" && agent.includes("nix/")) countInstall(ctx.kepr, name);41+ // A kept tarball is the bucket's own to serve: a five-minute URL, so the redirect itself42+ // is never kept.43+ if ("url" in tarball) {44+ c.header("Cache-Control", "no-store");45+ return c.redirect(tarball.url, 302);46+ }4047 c.header("Content-Type", "application/gzip");41- c.header("Content-Disposition", `attachment; filename="${name}-${save.id.slice(0, 8)}.tar.gz"`);48+ c.header("Content-Disposition", `attachment; filename="${filename}"`);4249 c.header("Cache-Control", TARBALL_CACHE);43- return c.body(bytes.slice());50+ return c.body(tarball.bytes.slice());4451 });4552 }src/tarball/cache.ts+36 −14
@@ -1,51 +1,73 @@11 import type { Database } from "bun:sqlite";22 import { type Bucket, BucketWriteError, KEPR_PREFIX } from "../bucket/reader.ts";3-import { filesAt, objectBytes, tarballGeneration } from "../mirror/queries.ts";3+import {4+ filesAt,5+ headId,6+ objectBytes,7+ releaseRecords,8+ tarballGeneration,9+} from "../mirror/queries.ts";410 import { knownSave } from "../mirror/store.ts";511 import { buildTarball } from "./tar.ts";612 713 const tarballsOf = (repo: string) => `${KEPR_PREFIX}tarballs/${repo}/`;814 15+/** A tarball the bucket already holds, or one built here for this request. */16+export type Tarball = { url: string } | { bytes: Uint8Array };17+918 /**1019 * A save's tarball, kept in the bucket under Kepr's own folder (June, 2026-09-30) as1120 * `.kepr/tarballs/<repo>/<generation>/<id>.tar.gz` once first requested (`tarballGeneration`).12- * If the bucket refuses the write nothing is kept, and each request builds it again. Null when the13- * save is gone from the mirror, as it is for a moment while a rebuild runs.21+ * Only a save the repo's HEAD names or a release names is kept: a crawler walking the history22+ * asks for every save, and storing each one would add a copy of the repo per save. Any other23+ * save's tarball is built and served without being stored. If the bucket refuses the write24+ * nothing is kept, and each request builds it again. Null when the save is gone from the mirror,25+ * as it is for a moment while a rebuild runs.1426 */1527 export async function cachedTarball(1628 bucket: Bucket,1729 db: Database,1830 repo: string,1931 saveId: string,20-): Promise<Uint8Array | null> {32+ filename: string,33+): Promise<Tarball | null> {2134 for (;;) {2235 const generation = tarballGeneration(db);2336 const key = `${tarballsOf(repo)}${generation}/${saveId}.tar.gz`;24- const stored = await bucket.get(key);37+ const stored = await bucket.tag(key);2538 // A strip, a hidden-path change or a rebuild may land during any await, and the sync's thread2639 // can land one between any two statements: the generation and the files are read in one2740 // snapshot, so what is built matches the key it files under, and bytes are served only for2841 // the generation still current.2942 const read = db.transaction(() => {3043 if (tarballGeneration(db) !== generation) return "moved";31- if (stored) return "stored";44+ if (stored !== null) return "stored";3245 if (!knownSave(db, saveId)) return "unknown";33- return filesAt(db, saveId).map((file) => {46+ // A migrated save's six-character ID can be the prefix of the full one here.47+ const released = releaseRecords(db).some(48+ (it) => it.save !== "" && saveId.startsWith(it.save),49+ );50+ const keep = headId(db) === saveId || released;51+ const files = filesAt(db, saveId).map((file) => {3452 const bytes = objectBytes(db, file.hash);3553 if (!bytes) throw new Error(`${repo}: object ${file.hash} is missing from the mirror`);3654 return { path: file.path, bytes, executable: file.executable };3755 });56+ return { files, keep };3857 })();3958 if (read === "moved") continue;40- if (read === "stored") return stored;4159 if (read === "unknown") return null;42- const tarball = buildTarball(`${repo}-${saveId.slice(0, 8)}`, read);43- try {44- await bucket.put(key, tarball, "application/gzip");45- } catch (error) {46- if (!(error instanceof BucketWriteError)) throw error;60+ // The bucket serves what it already holds, as a release file does: no download and copy here.61+ if (read === "stored") return { url: bucket.downloadUrl(key, filename, "application/gzip") };62+ const tarball = buildTarball(`${repo}-${saveId.slice(0, 8)}`, read.files);63+ if (read.keep) {64+ try {65+ await bucket.put(key, tarball, "application/gzip");66+ } catch (error) {67+ if (!(error instanceof BucketWriteError)) throw error;68+ }4769 }48- if (tarballGeneration(db) === generation) return tarball;70+ if (tarballGeneration(db) === generation) return { bytes: tarball };4971 }5072 }5173 tests/pages.test.ts+35 −0
@@ -277,6 +277,41 @@277277 });278278 });279279 280+describe("raw ranges and the heavy-route budget", () => {281+ test("one byte range is served with 206 and exactly those bytes", async () => {282+ const whole = new Uint8Array(await (await get("/demo/raw/src/main.ts")).arrayBuffer());283+ const ranged = await app.request("/demo/raw/src/main.ts", {284+ headers: { Range: "bytes=2-5" },285+ });286+ expect(ranged.status).toBe(206);287+ expect(ranged.headers.get("content-range")).toBe(`bytes 2-5/${whole.length}`);288+ expect(new Uint8Array(await ranged.arrayBuffer())).toEqual(whole.slice(2, 6));289+ const open = await app.request("/demo/raw/src/main.ts", { headers: { Range: "bytes=30-" } });290+ expect(open.status).toBe(206);291+ expect(new Uint8Array(await open.arrayBuffer())).toEqual(whole.slice(30));292+ const past = await app.request("/demo/raw/src/main.ts", {293+ headers: { Range: `bytes=${whole.length + 10}-` },294+ });295+ expect(past.status).toBe(416);296+ expect(past.headers.get("content-range")).toBe(`bytes */${whole.length}`);297+ });298+299+ test("the heavy routes answer 429 past the per-address budget; HEAD and pages are free", async () => {300+ const address = "198.51.100.200";301+ const ask = (path = "/demo/raw/src/main.ts", init: RequestInit = {}) =>302+ app.request(path, init, { requestIP: () => ({ address }) });303+ let refused: Response | null = null;304+ for (let i = 0; i < 200 && refused === null; i++) {305+ const response = await ask();306+ if (response.status === 429) refused = response;307+ }308+ expect(refused).not.toBeNull();309+ expect(Number(refused?.headers.get("retry-after"))).toBeGreaterThan(0);310+ expect((await ask("/demo/raw/src/main.ts", { method: "HEAD" })).status).toBe(200);311+ expect((await ask("/")).status).toBe(200);312+ });313+});314+280315 describe("the Atlas", () => {281316 // A row's detail panel, fetched on hover or select; a folder's path ends in a slash.282317 const panelOf = (path: string, at?: string) =>tests/releases.test.ts+3 −2
@@ -414,8 +414,9 @@414414 // A HEAD of the tarball fetches nothing, so it is not an install.415415 expect((await app.request(tarball, { method: "HEAD", headers: nix })).status).toBe(200);416416 expect(installs()).toBe(0);417- expect((await get(tarball, nix)).status).toBe(200);418- expect((await get(tarball, { "User-Agent": "curl/8.7.1" })).status).toBe(200);417+ // The HEAD above built and kept it, so these are hits: the bucket serves it, as a release does.418+ expect((await get(tarball, nix)).status).toBe(302);419+ expect((await get(tarball, { "User-Agent": "curl/8.7.1" })).status).toBe(302);419420 expect(installs()).toBe(1);420421 });421422 tests/tarball.test.ts+17 −4
@@ -2,6 +2,7 @@22 import { chmod, mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";33 import { tmpdir } from "node:os";44 import { join } from "node:path";5+import { fileURLToPath } from "node:url";56 import { gunzipSync } from "node:zlib";67 import type { Hono } from "hono";78 import { type Bucket, openBucket } from "../src/bucket/reader.ts";@@ -19,7 +20,14 @@1920 let head: string;2021 let dataDir: string;2122 const get = (path: string) => app.request(path);22-const bytesOf = async (path: string) => new Uint8Array(await (await get(path)).arrayBuffer());23+// A kept tarball redirects to the folder bucket's own file, which is the bytes it serves.24+const bytesOf = async (path: string) => {25+ const response = await get(path);26+ const location = response.headers.get("Location");27+ return new Uint8Array(28+ location ? await readFile(fileURLToPath(location)) : await response.arrayBuffer(),29+ );30+};2331 // Whether a tarball of HEAD is kept in the folder bucket under this many strips.2432 const kept = (strips: number) =>2533 [@@ -247,7 +255,9 @@247255 import { openMirror } from "${join(import.meta.dir, "../src/mirror/store.ts")}";248256 const { BUCKET_DIR, MIRROR_DIR, SAVE_ID } = process.env;249257 const bucket = openBucket({ kind: "folder", path: BUCKET_DIR });250-process.stdout.write(await cachedTarball(bucket, openMirror(MIRROR_DIR, "tarry"), "tarry", SAVE_ID));`;258+const name = "tarry-" + SAVE_ID.slice(0, 8) + ".tar.gz";259+const tarball = await cachedTarball(bucket, openMirror(MIRROR_DIR, "tarry"), "tarry", SAVE_ID, name);260+process.stdout.write(tarball.bytes);`;251261 const scratch = await mkdtemp(join(tmpdir(), "kepr-tb-"));252262 const other = Bun.spawnSync(["bun", "-e", script], {253263 cwd: scratch,@@ -301,8 +311,11 @@301311 return bytes;302312 },303313 };304- const tarball = await cachedTarball(racing, mirror, "tarry", head);305- const listed = tar(["-tzf", "-"], tarball ?? new Uint8Array());314+ const tarball = await cachedTarball(racing, mirror, "tarry", head, "tarry.tar.gz");315+ const listed = tar(316+ ["-tzf", "-"],317+ tarball && "bytes" in tarball ? tarball.bytes : new Uint8Array(),318+ );306319 expect(listed).not.toContain("guide.md");307320 expect(listed).toContain("src/main.ts");308321 });