fix(snapshot): bind replayed subjects to the selected target path
Rebind display paths only for matching artifact identities in primitive and composed replay. Preserve semantic Evidence IDs, payloads, and historical snapshot provenance. Classify snapshot filesystem workflows as boundary tests. Validation: cache, direct workflow, MCP replay, and Evidence tests; combined checks and temporary-directory hygiene. Provider interactions are simulated for replay verification.
This commit is contained in:
+51
-17
@@ -1,48 +1,48 @@
|
||||
import { parseConfig } from "../../src/config/parseConfig.js";
|
||||
import { parseConfig } from "../../../src/config/parseConfig.js";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { runDirectAnalysis } from "../../src/application/DirectAnalysis.js";
|
||||
import { runDirectAnalysis } from "../../../src/application/DirectAnalysis.js";
|
||||
import type {
|
||||
AnalysisProvider,
|
||||
CapabilityDescriptor,
|
||||
ProviderIdentity,
|
||||
} from "../../src/application/AnalysisProvider.js";
|
||||
import type { DirectAnalysisDependencies } from "../../src/application/DirectAnalysisDependencies.js";
|
||||
import { createAnalysisProfile } from "../../src/domain/analysisProfile.js";
|
||||
import { createAnalysisExecution } from "../../src/application/AnalysisProvider.js";
|
||||
import { ok } from "../../src/domain/result.js";
|
||||
} from "../../../src/application/AnalysisProvider.js";
|
||||
import type { DirectAnalysisDependencies } from "../../../src/application/DirectAnalysisDependencies.js";
|
||||
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import {
|
||||
readAnalysisSnapshot,
|
||||
writeAnalysisSnapshot,
|
||||
} from "../../src/application/binary/AnalysisSnapshotFiles.js";
|
||||
} from "../../../src/application/binary/AnalysisSnapshotFiles.js";
|
||||
import {
|
||||
createEvidence,
|
||||
parseEvidence,
|
||||
type Evidence,
|
||||
} from "../../src/domain/evidence.js";
|
||||
import { createEvidenceBundle } from "../../src/domain/evidenceBundle.js";
|
||||
} from "../../../src/domain/evidence.js";
|
||||
import { createEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
|
||||
import {
|
||||
REA_WORKFLOW_PROVIDER,
|
||||
workflowAnalysisProfile,
|
||||
} from "../../src/application/InvestigationProviders.js";
|
||||
} from "../../../src/application/InvestigationProviders.js";
|
||||
import {
|
||||
createAnalysisSnapshotWorkflowEntry,
|
||||
type AnalysisSnapshot,
|
||||
} from "../../src/domain/analysisSnapshot.js";
|
||||
} from "../../../src/domain/analysisSnapshot.js";
|
||||
import {
|
||||
createTestBinarySession,
|
||||
createTestProviderRouter,
|
||||
} from "../fixtures/binarySession.js";
|
||||
import { BinarySession } from "../../src/application/binary/BinarySession.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
} from "../../fixtures/binarySession.js";
|
||||
import { BinarySession } from "../../../src/application/binary/BinarySession.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
CAPABILITIES as GHIDRA_CAPABILITIES,
|
||||
GHIDRA_PROVIDER_IDENTITY,
|
||||
} from "../../src/ghidra/GhidraProviderCapabilities.js";
|
||||
} from "../../../src/ghidra/GhidraProviderCapabilities.js";
|
||||
|
||||
const IDENTITY = {
|
||||
id: "snapshot-fixture",
|
||||
@@ -550,6 +550,40 @@ describe("binary overview snapshot replay", () => {
|
||||
expect(second).toEqual(first);
|
||||
expect(fixture.calls.toSorted()).toEqual(operations.toSorted());
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
|
||||
const relocatedPath = join(dirname(fixture.path), "relocated.hop");
|
||||
await writeFile(relocatedPath, "fixture");
|
||||
const relocated = await runDirectAnalysis(
|
||||
dependencies,
|
||||
relocatedPath,
|
||||
"binary_overview",
|
||||
{},
|
||||
{ snapshotPath: fixture.snapshotPath },
|
||||
);
|
||||
const firstEvidence = parseEvidence(first);
|
||||
const relocatedEvidence = parseEvidence(relocated);
|
||||
expect(relocatedEvidence).toMatchObject({
|
||||
evidence_id: firstEvidence.evidence_id,
|
||||
subject: {
|
||||
local_path: relocatedPath,
|
||||
name: basename(relocatedPath),
|
||||
},
|
||||
});
|
||||
expect(relocatedEvidence.normalized_result).toEqual(
|
||||
firstEvidence.normalized_result,
|
||||
);
|
||||
expect(relocatedEvidence.raw_result).toEqual(firstEvidence.raw_result);
|
||||
expect(relocatedEvidence.locations).toEqual(firstEvidence.locations);
|
||||
expect(fixture.calls.toSorted()).toEqual(operations.toSorted());
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
|
||||
const persisted = await readAnalysisSnapshot(fixture.snapshotPath);
|
||||
if (!persisted.ok) throw persisted.error;
|
||||
expect(
|
||||
persisted.value.evidence_bundle.records.find(
|
||||
(record) => record.evidence_id === firstEvidence.evidence_id,
|
||||
)?.subject?.local_path,
|
||||
).toBe(fixture.path);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { parseConfig } from "../../../src/config/parseConfig.js";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
@@ -136,6 +136,20 @@ describe("MCP composed workflow snapshot replay", () => {
|
||||
})
|
||||
.passthrough()
|
||||
.parse(output);
|
||||
const primitiveResult = await mcp.callTool({
|
||||
name: "list_strings",
|
||||
arguments: { document: "fixture" },
|
||||
});
|
||||
expect(
|
||||
primitiveResult.isError,
|
||||
JSON.stringify(primitiveResult.content),
|
||||
).not.toBe(true);
|
||||
const primitiveEvidence = toolContract("list_strings").outputSchema.parse(
|
||||
primitiveResult.structuredContent,
|
||||
);
|
||||
expect(primitiveEvidence).toMatchObject({
|
||||
subject: { local_path: targetPath },
|
||||
});
|
||||
const afterAnalysisCalls = [...calls];
|
||||
const afterAnalysisStarts = [...starts];
|
||||
|
||||
@@ -163,6 +177,47 @@ describe("MCP composed workflow snapshot replay", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const relocatedPath = join(dirname(targetPath), "relocated.hop");
|
||||
await writeFile(relocatedPath, "fixture.hop");
|
||||
const reopened = await mcp.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: relocatedPath, snapshot_path: snapshotPath },
|
||||
});
|
||||
expect(reopened.isError, JSON.stringify(reopened.content)).not.toBe(true);
|
||||
const cachedPrimitive = await mcp.callTool({
|
||||
name: "list_strings",
|
||||
arguments: { document: "fixture" },
|
||||
});
|
||||
expect(
|
||||
cachedPrimitive.isError,
|
||||
JSON.stringify(cachedPrimitive.content),
|
||||
).not.toBe(true);
|
||||
const cachedEvidence = toolContract("list_strings").outputSchema.parse(
|
||||
cachedPrimitive.structuredContent,
|
||||
);
|
||||
expect(cachedEvidence).toMatchObject({
|
||||
subject: { local_path: relocatedPath },
|
||||
});
|
||||
expect(cachedEvidence.normalized_result).toEqual(
|
||||
primitiveEvidence.normalized_result,
|
||||
);
|
||||
expect(cachedEvidence.raw_result).toEqual(primitiveEvidence.raw_result);
|
||||
const retained = await mcp.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
});
|
||||
expect(retained.isError, JSON.stringify(retained.content)).not.toBe(true);
|
||||
const retainedBundle = toolContract(
|
||||
"get_evidence_bundle",
|
||||
).outputSchema.parse(retained.structuredContent).result;
|
||||
expect(
|
||||
retainedBundle.records.find(
|
||||
({ evidence_id }) => evidence_id === primitiveEvidence.evidence_id,
|
||||
)?.subject?.local_path,
|
||||
).toBe(targetPath);
|
||||
expect(calls).toEqual(afterAnalysisCalls);
|
||||
expect(starts).toEqual(afterAnalysisStarts);
|
||||
|
||||
const dependencies: DirectAnalysisDependencies = {
|
||||
readConfiguration: () => parseConfig({}),
|
||||
createBinarySession: () => createWorkflowSession(provider),
|
||||
@@ -180,7 +235,9 @@ describe("MCP composed workflow snapshot replay", () => {
|
||||
expect(calls).toEqual(afterAnalysisCalls);
|
||||
expect(starts).toEqual(afterAnalysisStarts);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MCP live workflow snapshot policy", () => {
|
||||
it("does not bind a workflow when an upstream operation is live", async () => {
|
||||
const { targetPaths, snapshotPath } = await createWorkflowFiles(
|
||||
"rea-mcp-live-workflow-snapshot-",
|
||||
|
||||
Reference in New Issue
Block a user