feat: expand cross-platform investigation workflows
This commit is contained in:
+232
-45
@@ -20,6 +20,11 @@ describe("real Hopper fixture binding", () => {
|
||||
primary: { path: join(root ?? "", "c") },
|
||||
secondary: { path: join(root ?? "", "version-v2") },
|
||||
large: { path: join(root ?? "", "large") },
|
||||
versionV1: { path: join(root ?? "", "version-v1") },
|
||||
versionV2: { path: join(root ?? "", "version-v2") },
|
||||
objc: { path: join(root ?? "", "objc") },
|
||||
napi: { path: join(root ?? "", "napi") },
|
||||
swift: { path: join(root ?? "", "swift") },
|
||||
largeOracle: {
|
||||
symbolPrefix: "_rea_page_",
|
||||
symbolCount: 1_205,
|
||||
@@ -35,10 +40,49 @@ describe("real Hopper fixture binding", () => {
|
||||
leafString: "REA_C_LEAF",
|
||||
globalName: "rea_c_global",
|
||||
},
|
||||
versionV1Expectations: {
|
||||
symbols: ["_rea_version_entry", "_rea_version_leaf"],
|
||||
strings: ["REA_VERSION_ONE"],
|
||||
},
|
||||
versionV2Expectations: {
|
||||
symbols: ["_rea_version_entry", "_rea_version_leaf", "_rea_added"],
|
||||
strings: ["REA_VERSION_TWO"],
|
||||
},
|
||||
objcExpectations: {
|
||||
symbols: ["_OBJC_CLASS_$_REAWidget"],
|
||||
strings: ["REAWidget", "REAWidgetDelegate", "performAction:error:"],
|
||||
},
|
||||
napiExpectations: {
|
||||
symbols: ["_napi_register_module_v1"],
|
||||
strings: ["reaProbeOne", "reaProbeTwo", "reaProbeThree"],
|
||||
},
|
||||
swiftExpectations: {
|
||||
strings: [
|
||||
"REA_SWIFT_EXECUTE",
|
||||
"REAService",
|
||||
"REARecord",
|
||||
"REAState",
|
||||
"REAProtocol",
|
||||
],
|
||||
},
|
||||
compilers: {
|
||||
c: {
|
||||
path: "/usr/bin/clang",
|
||||
version: "clang fixture",
|
||||
arguments: ["-O0"],
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("binds manifests that omit the optional swift fixture", async () => {
|
||||
const manifest = await fixtureManifest({ includeSwift: false });
|
||||
const targets = await loadRealHopperFixtureTargets(manifest);
|
||||
expect(targets.swift).toBeUndefined();
|
||||
expect(targets.swiftExpectations).toBeUndefined();
|
||||
});
|
||||
|
||||
it("rejects digest drift and artifacts escaping the manifest root", async () => {
|
||||
const manifest = await fixtureManifest();
|
||||
await writeFile(join(root ?? "", "c"), "changed");
|
||||
@@ -65,67 +109,210 @@ describe("real Hopper fixture binding", () => {
|
||||
fixtures: { name: string; artifact: string; artifactSha256: string }[];
|
||||
};
|
||||
const primary = parsed.fixtures.find(({ name }) => name === "c");
|
||||
const secondary = parsed.fixtures.find(({ name }) => name === "version-v2");
|
||||
if (primary === undefined || secondary === undefined)
|
||||
const objc = parsed.fixtures.find(({ name }) => name === "objc");
|
||||
if (primary === undefined || objc === undefined)
|
||||
throw new Error("Fixture manifest setup failed");
|
||||
secondary.artifact = primary.artifact;
|
||||
secondary.artifactSha256 = primary.artifactSha256;
|
||||
objc.artifact = primary.artifact;
|
||||
objc.artifactSha256 = primary.artifactSha256;
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/distinct artifacts/u,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a missing mandatory fixture", async () => {
|
||||
const manifest = await fixtureManifest();
|
||||
const parsed = JSON.parse(await readFile(manifest, "utf8")) as {
|
||||
fixtures: { name: string }[];
|
||||
};
|
||||
parsed.fixtures = parsed.fixtures.filter(({ name }) => name !== "objc");
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/Missing fixture objc/u,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects malformed expectations (empty record, empty array, non-string)", async () => {
|
||||
const manifest = await fixtureManifest();
|
||||
const parsed = JSON.parse(await readFile(manifest, "utf8")) as {
|
||||
fixtures: {
|
||||
name: string;
|
||||
expectations?: Record<string, unknown>;
|
||||
}[];
|
||||
};
|
||||
|
||||
const napi = parsed.fixtures.find(({ name }) => name === "napi");
|
||||
if (napi === undefined) throw new Error("Fixture manifest setup failed");
|
||||
napi.expectations = {};
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/Fixture napi expectations must be nonempty/u,
|
||||
);
|
||||
|
||||
napi.expectations = { exports: [] };
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/Fixture napi expectation exports must be nonempty/u,
|
||||
);
|
||||
|
||||
napi.expectations = { exports: ["rea_napi_a", ""] };
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/Fixture napi expectation exports must be nonempty strings/u,
|
||||
);
|
||||
|
||||
napi.expectations = { exports: ["rea_napi_a", 7] };
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/Fixture napi expectation exports must be nonempty strings/u,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a mandatory fixture that omits expectations", async () => {
|
||||
const manifest = await fixtureManifest();
|
||||
const parsed = JSON.parse(await readFile(manifest, "utf8")) as {
|
||||
fixtures: {
|
||||
name: string;
|
||||
expectations?: Record<string, unknown>;
|
||||
}[];
|
||||
};
|
||||
const objc = parsed.fixtures.find(({ name }) => name === "objc");
|
||||
if (objc === undefined) throw new Error("Fixture manifest setup failed");
|
||||
delete objc.expectations;
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/Fixture objc omitted its expectations/u,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects missing compiler provenance", async () => {
|
||||
const manifest = await fixtureManifest();
|
||||
const parsed = JSON.parse(await readFile(manifest, "utf8")) as {
|
||||
fixtures: { name: string; compiler?: unknown }[];
|
||||
};
|
||||
const objc = parsed.fixtures.find(({ name }) => name === "objc");
|
||||
if (objc === undefined) throw new Error("Fixture manifest setup failed");
|
||||
delete objc.compiler;
|
||||
await writeFile(manifest, JSON.stringify(parsed));
|
||||
await expect(loadRealHopperFixtureTargets(manifest)).rejects.toThrow(
|
||||
/compiler provenance/u,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const fixtureManifest = async (): Promise<string> => {
|
||||
type FixtureSpec = {
|
||||
readonly name: string;
|
||||
readonly artifact: string;
|
||||
readonly expectations?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
const fixtureManifest = async (options?: {
|
||||
readonly includeSwift?: boolean;
|
||||
}): Promise<string> => {
|
||||
root = await mkdtemp(join(tmpdir(), "rea-hopper-fixture-"));
|
||||
const primary = Buffer.from("primary");
|
||||
const secondary = Buffer.from("secondary");
|
||||
await Promise.all([
|
||||
writeFile(join(root, "c"), primary),
|
||||
writeFile(join(root, "version-v2"), secondary),
|
||||
writeFile(join(root, "large"), Buffer.from("large")),
|
||||
]);
|
||||
const buffers: Record<string, Buffer> = {
|
||||
c: Buffer.from("primary"),
|
||||
"version-v1": Buffer.from("version-v1"),
|
||||
"version-v2": Buffer.from("secondary"),
|
||||
objc: Buffer.from("objc"),
|
||||
napi: Buffer.from("napi"),
|
||||
large: Buffer.from("large"),
|
||||
swift: Buffer.from("swift"),
|
||||
};
|
||||
await Promise.all(
|
||||
Object.entries(buffers).map(([name, buffer]) =>
|
||||
writeFile(join(root ?? "", name), buffer),
|
||||
),
|
||||
);
|
||||
const includeSwift = options?.includeSwift ?? true;
|
||||
const fixtures: FixtureSpec[] = [
|
||||
{
|
||||
name: "c",
|
||||
artifact: "c",
|
||||
expectations: {
|
||||
hopperOracle: {
|
||||
mainProcedure: "main",
|
||||
entryProcedure: "rea_entry",
|
||||
branchProcedure: "rea_branch",
|
||||
leafProcedure: "rea_leaf",
|
||||
entryString: "REA_C_ENTRY",
|
||||
leafString: "REA_C_LEAF",
|
||||
globalName: "rea_c_global",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "version-v1",
|
||||
artifact: "version-v1",
|
||||
expectations: {
|
||||
symbols: ["_rea_version_entry", "_rea_version_leaf"],
|
||||
strings: ["REA_VERSION_ONE"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "version-v2",
|
||||
artifact: "version-v2",
|
||||
expectations: {
|
||||
symbols: ["_rea_version_entry", "_rea_version_leaf", "_rea_added"],
|
||||
strings: ["REA_VERSION_TWO"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "objc",
|
||||
artifact: "objc",
|
||||
expectations: {
|
||||
symbols: ["_OBJC_CLASS_$_REAWidget"],
|
||||
strings: ["REAWidget", "REAWidgetDelegate", "performAction:error:"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "napi",
|
||||
artifact: "napi",
|
||||
expectations: {
|
||||
symbols: ["_napi_register_module_v1"],
|
||||
strings: ["reaProbeOne", "reaProbeTwo", "reaProbeThree"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "large",
|
||||
artifact: "large",
|
||||
expectations: {
|
||||
symbolPrefix: "_rea_page_",
|
||||
symbolCount: 1_205,
|
||||
stringPrefix: "REA_PAGE_",
|
||||
stringCount: 1_205,
|
||||
},
|
||||
},
|
||||
];
|
||||
if (includeSwift)
|
||||
fixtures.push({
|
||||
name: "swift",
|
||||
artifact: "swift",
|
||||
expectations: {
|
||||
strings: [
|
||||
"REA_SWIFT_EXECUTE",
|
||||
"REAService",
|
||||
"REARecord",
|
||||
"REAState",
|
||||
"REAProtocol",
|
||||
],
|
||||
},
|
||||
});
|
||||
const manifest = join(root, "manifest.json");
|
||||
await writeFile(
|
||||
manifest,
|
||||
JSON.stringify({
|
||||
schemaVersion: 1,
|
||||
fixtures: [
|
||||
{
|
||||
name: "c",
|
||||
artifact: "c",
|
||||
artifactSha256: digest(primary),
|
||||
expectations: {
|
||||
hopperOracle: {
|
||||
mainProcedure: "main",
|
||||
entryProcedure: "rea_entry",
|
||||
branchProcedure: "rea_branch",
|
||||
leafProcedure: "rea_leaf",
|
||||
entryString: "REA_C_ENTRY",
|
||||
leafString: "REA_C_LEAF",
|
||||
globalName: "rea_c_global",
|
||||
},
|
||||
},
|
||||
fixtures: fixtures.map((fixture) => ({
|
||||
...fixture,
|
||||
artifactSha256: digest(buffers[fixture.artifact] ?? Buffer.from("")),
|
||||
compiler: {
|
||||
path: "/usr/bin/clang",
|
||||
version: "clang fixture",
|
||||
arguments: ["-O0"],
|
||||
},
|
||||
{
|
||||
name: "version-v2",
|
||||
artifact: "version-v2",
|
||||
artifactSha256: digest(secondary),
|
||||
},
|
||||
{
|
||||
name: "large",
|
||||
artifact: "large",
|
||||
artifactSha256: digest(Buffer.from("large")),
|
||||
expectations: {
|
||||
symbolPrefix: "_rea_page_",
|
||||
symbolCount: 1_205,
|
||||
stringPrefix: "REA_PAGE_",
|
||||
stringCount: 1_205,
|
||||
},
|
||||
},
|
||||
],
|
||||
})),
|
||||
}),
|
||||
);
|
||||
return manifest;
|
||||
|
||||
Reference in New Issue
Block a user