From 80ed81fb3dbedceef5513771d77c9a1e25440a69 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:51:12 +0800 Subject: [PATCH] test(artifacts): distinguish Godot PCK capacity guards (#12013) --- src/artifacts/GodotPckArtifactReader.test.ts | 62 +++++++++++++------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/src/artifacts/GodotPckArtifactReader.test.ts b/src/artifacts/GodotPckArtifactReader.test.ts index d8ea5825e8..660b01f436 100644 --- a/src/artifacts/GodotPckArtifactReader.test.ts +++ b/src/artifacts/GodotPckArtifactReader.test.ts @@ -18,7 +18,11 @@ import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory import { renameOpenParent } from "../../tests/fixtures/renameOpenParent.js"; import { openRegularFile } from "../filesystem/RegularFile.js"; -import type { ArtifactEntry } from "../resources/ArtifactReader.js"; +import type { + ArtifactEntry, + ArtifactReaderTraversal, + ArtifactTraversalOptions, +} from "../resources/ArtifactReader.js"; import { ArtifactEmbeddedFormatProbes } from "./ArtifactEmbeddedFormatProbes.js"; import { GodotPckArtifactReader } from "./GodotPckArtifactReader.js"; import { DEFAULT_GODOT_READER_LIMITS } from "../domain/artifactReaderLimits.js"; @@ -31,9 +35,11 @@ const writePck = async (bytes: Buffer): Promise => { const list = async ( reader: GodotPckArtifactReader, + options?: ArtifactTraversalOptions, ): Promise => { const entries: ArtifactEntry[] = []; - for await (const entry of reader.entries()) entries.push(entry); + for await (const entry of reader.entries(undefined, options)) + entries.push(entry); return entries; }; @@ -56,13 +62,11 @@ const members: readonly GodotPckMember[] = [ ]; it("recovers the same PCK directory after raising encoded metadata admission", async () => { - const bytes = buildGodotPck(4, [ - { path: "res://main.gd", data: "extends Node\n" }, - ]); + const bytes = buildGodotPck(4, [{ path: "a", data: "extends Node\n" }]); const path = await writePck(bytes); const refused = new GodotPckArtifactReader(path, undefined, { ...DEFAULT_GODOT_READER_LIMITS, - directory_bytes: 128, + directory_bytes: 320, }); try { await expect(list(refused)).rejects.toMatchObject({ @@ -70,7 +74,7 @@ it("recovers the same PCK directory after raising encoded metadata admission", a boundary: "memory", readerLimit: { parameter: "artifact_limits.godot.directory_bytes", - effective_value: 128, + effective_value: 320, }, }); } finally { @@ -82,7 +86,7 @@ it("recovers the same PCK directory after raising encoded metadata admission", a }); try { const entries = await list(recovered); - expect(entries).toMatchObject([{ path: "main.gd", declaredSize: 13 }]); + expect(entries).toMatchObject([{ path: "a", declaredSize: 13 }]); expect(await text(await recovered.open(entries[0]!))).toBe( "extends Node\n", ); @@ -91,6 +95,31 @@ it("recovers the same PCK directory after raising encoded metadata admission", a } }); +it("refuses a fully framed path over the remaining metadata budget", async () => { + const path = await writePck( + buildGodotPck(2, [ + { path: "a", data: "" }, + { path: "b".repeat(64), data: "" }, + ]), + ); + const reader = new GodotPckArtifactReader(path, undefined, { + ...DEFAULT_GODOT_READER_LIMITS, + directory_bytes: 1400, + }); + try { + await expect(list(reader)).rejects.toMatchObject({ + reason: "limit", + boundary: "memory", + readerLimit: { + parameter: "artifact_limits.godot.directory_bytes", + effective_value: 1400, + }, + }); + } finally { + await reader.close(); + } +}); + it("applies selected aggregate work before yielding Godot members", async () => { const path = await writePck( buildGodotPck(4, [{ path: "res://main.gd", data: "extends Node\n" }]), @@ -178,7 +207,11 @@ describe("GodotPckArtifactReader format 1", () => { it("keeps a valid empty Godot 3 format 1 inventory complete", async () => { await withReader(buildGodotPck1([]), async (reader) => { - expect(await list(reader)).toEqual([]); + const coverage: ArtifactReaderTraversal[] = []; + expect( + await list(reader, { onCoverage: (facts) => coverage.push(facts) }), + ).toEqual([]); + expect(coverage).toEqual([{ status: "complete", limitations: [] }]); expect(reader.formatMetadata()).toMatchObject({ format_version: 1, directory_status: "available", @@ -318,17 +351,6 @@ describe("GodotPckArtifactReader", () => { }); }); - it("refuses a fully framed path over the metadata budget", async () => { - const path = "a".repeat(Math.floor((64 * 1024 * 1024) / 18) + 1); - const bytes = buildGodotPck(2, [{ path, data: "" }]); - await withReader(bytes, async (reader) => { - await expect(list(reader)).rejects.toMatchObject({ - reason: "limit", - boundary: "memory", - }); - }); - }); - it.each([ [ "a patch removal entry",