diff --git a/scripts/lib/real-ghidra-snapshot-lifecycle.mjs b/scripts/lib/real-ghidra-snapshot-lifecycle.mjs index 7b4221bc92..73d5e69ab3 100644 --- a/scripts/lib/real-ghidra-snapshot-lifecycle.mjs +++ b/scripts/lib/real-ghidra-snapshot-lifecycle.mjs @@ -9,7 +9,7 @@ import { join } from "node:path"; import { parseAnalysisSnapshot } from "../../dist/domain/analysisSnapshot.js"; import { parseEvidenceBundle } from "../../dist/domain/evidenceBundle.js"; -/** Keep mutable Ghidra observations out of immutable snapshots across target opens. */ +/** Keep live Ghidra edits distinct from historical Evidence across snapshots. */ export async function verifyGhidraSnapshotLifecycle( client, target, @@ -93,18 +93,21 @@ export async function verifyGhidraSnapshotLifecycle( const bundle = parseEvidenceBundle( JSON.parse(await readFile(bundlePath, "utf8")), ); - assert.ok( - bundle.records.some( - (record) => record.operation === "annotate_native_function", - ), + const annotation = bundle.records.find( + (record) => + record.operation === "annotate_native_function" && + record.normalized_result.annotations.name === edited.procedure.name && + record.normalized_result.annotations.address === + edited.procedure.address, ); - assert.ok( - bundle.records.some( - (record) => - record.operation === "inspect_native_api" && - record.normalized_result.procedure.name === edited.procedure.name, - ), + const editedApi = bundle.records.find( + (record) => + record.operation === "inspect_native_api" && + record.normalized_result.procedure.name === edited.procedure.name && + record.normalized_result.procedure.address === edited.procedure.address, ); + assert.ok(annotation); + assert.ok(editedApi); await call("close_binary"); await call("open_binary", { @@ -124,14 +127,13 @@ export async function verifyGhidraSnapshotLifecycle( const fresh = parseAnalysisSnapshot( JSON.parse(await readFile(freshPath, "utf8")), ); - assert.ok( - !fresh.evidence_bundle.records.some( - (record) => - record.operation === "annotate_native_function" || - (record.operation === "inspect_native_api" && - record.normalized_result.procedure.name === edited.procedure.name), - ), - ); + for (const historical of [annotation, editedApi]) + assert.deepEqual( + fresh.evidence_bundle.records.find( + (record) => record.evidence_id === historical.evidence_id, + ), + historical, + ); await call("open_binary", { path: target.path, provider_id: "ghidra",