From 7ffc119df882da011448d5b909792fa2cf24b637 Mon Sep 17 00:00:00 2001 From: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com> Date: Wed, 14 Oct 2026 04:41:15 +0800 Subject: [PATCH] fix(snapshot): revise workflow and PDB coverage profiles Invalidate workflow Evidence written before upstream limitation propagation, including workflows that previously had no revision. Advance the PE Program PDB observation contract to prevent replaying legacy nullable-state projections while retaining historical Evidence. Validation: 219 focused tests across 15 suites pass, with two Windows-only cases skipped on Linux. Three historical-profile regressions fail before the fix and pass afterward. Current workflow snapshots replay without extra provider startup or calls; standalone typecheck and changed-file lint pass. --- src/application/InvestigationProviders.ts | 6 +- src/ghidra/GhidraAnalysisProfile.ts | 2 +- src/ghidra/GhidraProvider.behavior.test.ts | 54 +++++++++++++ .../directAnalysisSnapshotReplay.test.ts | 80 ++++++++++++++++++- 4 files changed, 135 insertions(+), 7 deletions(-) diff --git a/src/application/InvestigationProviders.ts b/src/application/InvestigationProviders.ts index af23463f4..a4c4d1458 100644 --- a/src/application/InvestigationProviders.ts +++ b/src/application/InvestigationProviders.ts @@ -19,12 +19,12 @@ export const workflowAnalysisProfile = ( createAnalysisProfile(REA_WORKFLOW_PROVIDER, { upstream_analysis_profile: upstream, ...(operation === "binary_overview" - ? { workflow_revision: 3 } + ? { workflow_revision: 4 } : operation === "batch_decompile" || operation === "get_call_graph" || operation === "trace_feature" - ? { workflow_revision: 2 } - : {}), + ? { workflow_revision: 3 } + : { workflow_revision: 1 }), }); /** Provider identity for deterministic artifact inventories. */ diff --git a/src/ghidra/GhidraAnalysisProfile.ts b/src/ghidra/GhidraAnalysisProfile.ts index da39ce53c..bf0263913 100644 --- a/src/ghidra/GhidraAnalysisProfile.ts +++ b/src/ghidra/GhidraAnalysisProfile.ts @@ -216,7 +216,7 @@ export const resolveGhidraAnalysisProfile = async ( ].sort(), import_mode: "ephemeral-source-immutable", ...(target.format === "pe" - ? { pdb_observations: "program-info-v1" } + ? { pdb_observations: "program-info-v2" } : {}), annotation_policy: "atomic-function-entry-metadata-v1", load_image_observations: "source-mappings-entry-context-v2", diff --git a/src/ghidra/GhidraProvider.behavior.test.ts b/src/ghidra/GhidraProvider.behavior.test.ts index 4cfeafb8f..50a3a1cc6 100644 --- a/src/ghidra/GhidraProvider.behavior.test.ts +++ b/src/ghidra/GhidraProvider.behavior.test.ts @@ -35,6 +35,11 @@ import { WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON } from "../process/WindowsA import { ProviderCleanupError } from "../domain/providerCleanupError.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; import { ProviderStartupDeadline } from "../process/ProviderDeadline.js"; +import { createAnalysisProfile } from "../domain/analysisProfile.js"; +import { createAnalysisExecution } from "../application/AnalysisProvider.js"; +import { AnalysisSnapshotCache } from "../application/binary/AnalysisSnapshotCache.js"; +import { createEvidence } from "../domain/evidence.js"; +import { createEvidenceBundle } from "../domain/evidenceBundle.js"; const INSTALL = "/opt/ghidra_12.1.4_PUBLIC"; const installationHost = ( @@ -80,6 +85,55 @@ const createElfClient = async (ghidra: GhidraProvider) => { return ghidra.createClient(target, resolved.value.profile); }; +it("retains historical PE PDB Evidence without replaying its old projection", async () => { + const target = peTarget("x86_64"); + const resolved = await provider().resolveAnalysisProfile(target); + if (!resolved.ok || resolved.value.profile === null) + throw new Error("Expected admitted PE profile"); + const current = resolved.value.profile; + const prior = createAnalysisProfile(current.provider, { + ...current.parameters, + pdb_observations: "program-info-v1", + }); + const operation = "search_procedures"; + const parameters = { pattern: "wmain" }; + const limitations = ["Legacy projection collapsed unknown PDB load state."]; + const cache = new AnalysisSnapshotCache(); + cache.record({ + target, + profile: prior, + operation, + parameters, + execution: createAnalysisExecution([], prior.provider, { + subject: target, + analysisProfile: prior, + limitations, + }), + }); + const evidence = createEvidence(target, prior.provider, { + operation, + parameters, + result: [], + analysisProfile: prior, + limitations, + }); + const exported = cache.export( + target, + prior, + createEvidenceBundle([evidence]), + ); + if (!exported.ok) throw exported.error; + const imported = new AnalysisSnapshotCache(); + expect(imported.import(exported.value, undefined, () => ok(0)).ok).toBe(true); + expect( + imported.lookup(target, current, operation, parameters), + ).toBeUndefined(); + expect( + imported.lookup(target, prior, operation, parameters)?.limitations, + ).toEqual(expect.arrayContaining(limitations)); + expect(exported.value.evidence_bundle.records).toContainEqual(evidence); +}); + describe("Ghidra provider", () => { it("commits DOS loader and real-mode language while retaining the CPU family", async () => { const ghidra = provider(); diff --git a/tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts b/tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts index 7adf193f4..708ddbe5a 100644 --- a/tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts +++ b/tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts @@ -136,6 +136,7 @@ interface SnapshotProviderOptions { readonly profile?: ReturnType; readonly identity?: ProviderIdentity; readonly supportedOperations?: readonly CapabilityDescriptor["operation"][]; + readonly limitations?: readonly string[]; } const makeProvider = ( @@ -209,6 +210,7 @@ const makeProvider = ( createAnalysisExecution(result, profile.provider, { analysisProfile: profile, rawResult: result, + limitations: options.limitations ?? [], }), ); }, @@ -253,11 +255,11 @@ const withAlternateWorkflowProfile = ( snapshot: AnalysisSnapshot, path: string, current: Evidence, -): AnalysisSnapshot => { - const alternateProfile = createAnalysisProfile(REA_WORKFLOW_PROVIDER, { + alternateProfile = createAnalysisProfile(REA_WORKFLOW_PROVIDER, { workflow: "binary_overview", fixture: "alternate-profile", - }); + }), +): AnalysisSnapshot => { if ( typeof current.normalized_result !== "object" || current.normalized_result === null || @@ -466,6 +468,78 @@ const verifyWindowsSnapshotAdmission = async ( ).toHaveLength(1); }; +it.each([ + { tool: "binary_overview", arguments: {}, priorRevision: 3 }, + { + tool: "inspect_native_api", + arguments: { procedure: "0x1000" }, + priorRevision: undefined, + }, +] as const)( + "refreshes pre-coverage $tool Evidence and replays the current revision", + async (scenario) => { + const fixture = await createSnapshotReplayFixture("rea-prior-coverage-"); + const limitation = "Original PDB names may be missing."; + const provider = fixture.createProvider({ + supportedOperations: workflowProviderOperations, + limitations: [limitation], + }); + const dependencies = fixture.dependencies(provider); + const options = { snapshotPath: fixture.snapshotPath }; + const first = parseEvidence( + await runDirectAnalysis( + dependencies, + fixture.path, + scenario.tool, + scenario.arguments, + options, + ), + ); + const saved = await readAnalysisSnapshot(fixture.snapshotPath); + if (!saved.ok) throw saved.error; + const priorProfile = createAnalysisProfile(REA_WORKFLOW_PROVIDER, { + upstream_analysis_profile: saved.value.binding.analysis_profile, + ...(scenario.priorRevision === undefined + ? {} + : { workflow_revision: scenario.priorRevision }), + }); + const prior = withAlternateWorkflowProfile( + saved.value, + fixture.path, + { ...first, limitations: ["Derived by an REA composed workflow."] }, + priorProfile, + ); + const written = await withArtifactResourceScope((resources) => + writeAnalysisSnapshot(prior, fixture.snapshotPath, true, resources), + ); + if (!written.ok) throw written.error; + const refreshed = parseEvidence( + await runDirectAnalysis( + dependencies, + fixture.path, + scenario.tool, + scenario.arguments, + options, + ), + ); + expect(refreshed.limitations).toContain(limitation); + expect(refreshed.analysis_profile?.digest).not.toBe(priorProfile.digest); + expect(refreshed.normalized_result).toEqual(first.normalized_result); + const starts = [...fixture.starts]; + const calls = [...fixture.calls]; + const replayed = await runDirectAnalysis( + dependencies, + fixture.path, + scenario.tool, + scenario.arguments, + options, + ); + expect(replayed).toEqual(refreshed); + expect(fixture.starts).toEqual(starts); + expect(fixture.calls).toEqual(calls); + }, +); + describe("direct analysis composed snapshot replay", () => { it.skipIf(process.platform !== "win32")( "does not replay a CLI snapshot through a Windows junction",