From 7e2e4d41f5d0e0d17682576f8b0a5a220bfee070 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 10:22:15 -0500 Subject: [PATCH] test(il2cpp): consolidate section geometry and prefix checks (#12863) --- tests/acceptance/il2cppMetadataCli.test.ts | 111 +++++++++--------- .../il2cpp/il2cppMetadataFile.test.ts | 30 +---- 2 files changed, 54 insertions(+), 87 deletions(-) diff --git a/tests/acceptance/il2cppMetadataCli.test.ts b/tests/acceptance/il2cppMetadataCli.test.ts index 666b335a22..f9061476ec 100644 --- a/tests/acceptance/il2cppMetadataCli.test.ts +++ b/tests/acceptance/il2cppMetadataCli.test.ts @@ -496,70 +496,65 @@ cliTest( const root = await createTestTempDirectory("rea-il2cpp-prefix-fail-"); const { client, call } = await connectLocalToolsMcp(); - for (const length of [4, 5, 6, 7]) { - const path = join(root, `magic-${length}.dat`); - const bytes = Buffer.alloc(length); - bytes.writeUInt32LE(0xfab11baf, 0); - await writeFile(path, bytes); + const path = join(root, "incomplete-version.dat"); + const bytes = Buffer.from([0xaf, 0x1b, 0xb1, 0xfa, 37, 0, 0]); + await writeFile(path, bytes); - const expected = { - code: "invalid_request", - details: { - operation: "inspect_il2cpp_metadata", - issues: [ - { - path: ["path"], - reason: "invalid_format", - message: expect.stringContaining( - "truncated-header: the file has", - ), - }, - ], - partial_observation: { - normalized_result: { - artifact: { - path, - bytes: length, - sha256: createHash("sha256").update(bytes).digest("hex"), - }, - inventory_status: "not-returned-as-complete", + const expected = { + code: "invalid_request", + details: { + operation: "inspect_il2cpp_metadata", + issues: [ + { + path: ["path"], + reason: "invalid_format", + message: expect.stringContaining("truncated-header"), + }, + ], + partial_observation: { + normalized_result: { + artifact: { + path, + bytes: bytes.length, + sha256: createHash("sha256").update(bytes).digest("hex"), }, + inventory_status: "not-returned-as-complete", }, }, - }; - const result = await cli.run({ - arguments: ["inspect-il2cpp-metadata", path, "--json"], - }); - expect(result.exitCode).toBe(1); - expect(result.json).toMatchObject(expected); + }, + }; + const result = await cli.run({ + arguments: ["inspect-il2cpp-metadata", path, "--json"], + }); + expect(result.exitCode).toBe(1); + expect(result.json).toMatchObject(expected); - const response = await call("inspect_il2cpp_metadata", { path }); - const projected = parseMcpToolError(response).error; - expect(projected).toMatchObject({ - ...expected, - details: { - ...expected.details, - partial_observation: { - kind: "retained-evidence", - evidence_id: expect.any(String), - }, + const response = await call("inspect_il2cpp_metadata", { path }); + const projected = parseMcpToolError(response).error; + expect(projected).toMatchObject({ + ...expected, + details: { + ...expected.details, + partial_observation: { + kind: "retained-evidence", + evidence_id: expect.any(String), }, - }); - const reference = projected.details?.partial_observation as { - evidence_id: string; - }; - const bundle = parseEvidenceBundle( - toolContract("get_evidence_bundle").outputSchema.parse( - (await call("get_evidence_bundle", { detail: "complete" })) - .structuredContent, - ).result, - ); - expect( - bundle.records.find( - ({ evidence_id }) => evidence_id === reference.evidence_id, - ), - ).toMatchObject(expected.details.partial_observation); - } + }, + }); + const reference = projected.details?.partial_observation as { + evidence_id: string; + }; + const bundle = parseEvidenceBundle( + toolContract("get_evidence_bundle").outputSchema.parse( + (await call("get_evidence_bundle", { detail: "complete" })) + .structuredContent, + ).result, + ); + expect( + bundle.records.find( + ({ evidence_id }) => evidence_id === reference.evidence_id, + ), + ).toMatchObject(expected.details.partial_observation); await client.ping(); }, ); diff --git a/tests/boundary/il2cpp/il2cppMetadataFile.test.ts b/tests/boundary/il2cpp/il2cppMetadataFile.test.ts index 65a9ecc294..dcef38ab3a 100644 --- a/tests/boundary/il2cpp/il2cppMetadataFile.test.ts +++ b/tests/boundary/il2cpp/il2cppMetadataFile.test.ts @@ -155,18 +155,13 @@ describe("IL2CPP global-metadata version 39", () => { }, ); - it("accepts empty sections that share an offset with occupied sections and padding gaps", () => { + it("accepts an empty section whose offset is inside an occupied section", () => { const bytes = mutated((fixture, target) => { const methods = fixture.section("methods"); target.writeInt32LE( methods.offset + 3, fixture.header("windowsRuntimeStrings", "offset"), ); - // Grow strings into trailing padding that no other section occupies. - target.writeInt32LE( - fixture.section("strings").size, - fixture.header("strings", "size"), - ); }); expect(readIl2cppMetadata(bytes).types).toEqual(FIXTURE_TYPES); }); @@ -501,29 +496,6 @@ describe("rejected IL2CPP metadata references", () => { ); }); - it("rejects a string section overlapping literal data", () => { - rejects( - mutated((fixture, bytes) => { - bytes.writeInt32LE( - fixture.section("strings").offset - 1, - fixture.header("strings", "offset"), - ); - }), - "section-overlap", - ); - }); - - it("decodes a valid string suffix from its byte offset", () => { - const fixture = createIl2cppMetadataFixture({ - typeNames: { 0: "xPlayer" }, - }); - const bytes = Buffer.from(fixture.bytes); - const originalOffset = fixture.record("typeDefinitions", 0); - bytes.writeInt32LE(bytes.readInt32LE(originalOffset) + 1, originalOffset); - - expect(readIl2cppMetadata(bytes).types[0]?.name).toBe("Player"); - }); - it("accepts a UTF-8 code-point boundary suffix and rejects a split code point", () => { const fixture = createIl2cppMetadataFixture({ typeNames: { 0: "xéclair" },