Files
reverse-engineering-anything/tests/acceptance/artifactComparisonPyInstaller.test.ts
T

91 lines
3.0 KiB
TypeScript

import { expect, it } from "vitest";
import {
PYTHON_39_MAGIC,
cArchiveExecutable,
storedPyzMember,
type CArchiveFixtureMember,
} from "../../src/artifacts/pyinstaller/CArchive.fixture.js";
import { occurrenceAt } from "../fixtures/artifactEvidence.js";
import { connectArtifactFixtureComparison } from "../fixtures/artifactComparisonMcp.js";
const connectArchiveComparison = () =>
connectArtifactFixtureComparison(
"rea-pyinstaller-comparison-",
(members: readonly CArchiveFixtureMember[]) =>
cArchiveExecutable({ layout: "2.1", pythonVersion: 309, members }),
);
it("reports a changed PyInstaller declaration whose member bytes are unavailable", async () => {
const { inspect, compare } = await connectArchiveComparison();
const link = (name: string) => [
{ name, typeCode: "n", payload: Buffer.from("target"), compress: false },
];
// A rebuild on another filesystem can store the link name decomposed.
// Normalization pairs the links; their stored names stay distinct.
const nfc = "café-link";
const left = await inspect("nfc", link(nfc));
const right = await inspect("nfd", link("café-link"));
expect(occurrenceAt(left, nfc)).toMatchObject({
hash_status: "not-hashed",
format_metadata: { source_name: nfc },
});
expect(occurrenceAt(right, nfc)).toMatchObject({
hash_status: "not-hashed",
format_metadata: { source_name: "café-link" },
});
const result = await compare(left, right);
expect(
result.changes.find(({ logical_path }) => logical_path === nfc),
).toMatchObject({
classification: "changed",
dimensions: ["metadata", "availability"],
left_occurrence_id: occurrenceAt(left, nfc).occurrence_id,
right_occurrence_id: occurrenceAt(right, nfc).occurrence_id,
});
});
it("reports a PYZ namespace record that becomes encrypted", async () => {
const { inspect, compare } = await connectArchiveComparison();
const pyz = storedPyzMember({
magic: PYTHON_39_MAGIC,
modules: [
{
name: "ns.branch",
typeCode: 3,
body: Buffer.from("legacy namespace payload"),
legacyNamespacePayload: true,
},
],
});
const namespace = "PYZ.pyz/ns/branch";
const plain = await inspect("plain", [pyz]);
// The legacy key module also encrypts a nonempty namespace payload.
const encrypted = await inspect("encrypted", [
{
name: "pyimod00_crypto_key",
typeCode: "m",
payload: Buffer.from("key module"),
compress: false,
},
pyz,
]);
expect(occurrenceAt(encrypted, namespace)).toMatchObject({
entry_kind: "metadata",
artifact_id: null,
encrypted: true,
});
const result = await compare(plain, encrypted);
expect(
result.changes.find(({ logical_path }) => logical_path === namespace),
).toMatchObject({
classification: "changed",
dimensions: ["metadata"],
left_occurrence_id: occurrenceAt(plain, namespace).occurrence_id,
right_occurrence_id: occurrenceAt(encrypted, namespace).occurrence_id,
});
});