refactor(domain): remove provider-specific target and snapshot state
Move Hopper loader derivation and compatibility projection into the Hopper adapter so BinaryTarget carries only provider-neutral identity and format metadata. Introduce bounded canonical analysis-profile commitments, exact provider/profile snapshot v2 bindings, legacy snapshot rejection guidance, and backward-compatible profiled Evidence v2 records. Partition cache and replay behavior by target, concrete provider build, and profile while preserving custom Hopper loader overrides. Propagate profiles consistently through CLI, MCP, composed workflows, and session lifecycle; preserve the 78-tool contract and legacy loaderArgs response projection. Add migration documentation, generated API updates, property regressions, package verification, and real Hopper coverage.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
analysisProfileSchema,
|
||||
analysisProfilesEqual,
|
||||
createAnalysisProfile,
|
||||
} from "../src/domain/analysisProfile.js";
|
||||
|
||||
const PROVIDER = {
|
||||
id: "fixture",
|
||||
name: "Fixture analysis provider",
|
||||
version: "1.2.3",
|
||||
} as const;
|
||||
|
||||
describe("analysis profile commitments", () => {
|
||||
it("canonicalizes parameter key order and validates its digest", () => {
|
||||
const first = createAnalysisProfile(PROVIDER, 1, {
|
||||
architecture: "arm64",
|
||||
analyzers: { strings: true, functions: true },
|
||||
});
|
||||
const reordered = createAnalysisProfile(PROVIDER, 1, {
|
||||
analyzers: { functions: true, strings: true },
|
||||
architecture: "arm64",
|
||||
});
|
||||
expect(reordered.digest).toBe(first.digest);
|
||||
expect(analysisProfilesEqual(first, reordered)).toBe(true);
|
||||
expect(analysisProfileSchema.parse(first)).toEqual(first);
|
||||
});
|
||||
|
||||
it("separates provider builds, profile schemas, and semantic parameters", () => {
|
||||
const baseline = createAnalysisProfile(PROVIDER, 1, { loader: "default" });
|
||||
const changedBuild = createAnalysisProfile(
|
||||
{ ...PROVIDER, version: "1.2.4" },
|
||||
1,
|
||||
{ loader: "default" },
|
||||
);
|
||||
const changedSchema = createAnalysisProfile(PROVIDER, 2, {
|
||||
loader: "default",
|
||||
});
|
||||
const changedParameters = createAnalysisProfile(PROVIDER, 1, {
|
||||
loader: "override",
|
||||
});
|
||||
expect(
|
||||
new Set([
|
||||
baseline.digest,
|
||||
changedBuild.digest,
|
||||
changedSchema.digest,
|
||||
changedParameters.digest,
|
||||
]).size,
|
||||
).toBe(4);
|
||||
});
|
||||
|
||||
it("rejects digest tampering and unbounded parameters", () => {
|
||||
const profile = createAnalysisProfile(PROVIDER, 1, { loader: "default" });
|
||||
expect(() =>
|
||||
analysisProfileSchema.parse({ ...profile, digest: "0".repeat(64) }),
|
||||
).toThrow(/digest/u);
|
||||
expect(() =>
|
||||
createAnalysisProfile(PROVIDER, 1, {
|
||||
oversized: "x".repeat(65 * 1024),
|
||||
}),
|
||||
).toThrow(/limit/u);
|
||||
});
|
||||
});
|
||||
+131
-92
@@ -4,23 +4,40 @@ import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createAnalysisExecution } from "../src/application/AnalysisProvider.js";
|
||||
import { AnalysisSnapshotCache } from "../src/application/AnalysisSnapshotCache.js";
|
||||
import {
|
||||
readAnalysisSnapshot,
|
||||
writeAnalysisSnapshot,
|
||||
} from "../src/application/AnalysisSnapshotFiles.js";
|
||||
import { AnalysisSnapshotCache } from "../src/application/AnalysisSnapshotCache.js";
|
||||
import { createAnalysisProfile } from "../src/domain/analysisProfile.js";
|
||||
import {
|
||||
createAnalysisSnapshotEntry,
|
||||
parseAnalysisSnapshot,
|
||||
snapshotBinding,
|
||||
snapshotEvidenceForQuery,
|
||||
snapshotTarget,
|
||||
type AnalysisSnapshot,
|
||||
} from "../src/domain/analysisSnapshot.js";
|
||||
import { createEvidenceBundle } from "../src/domain/evidenceBundle.js";
|
||||
import type { BinaryTarget } from "../src/domain/binaryTarget.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
import { createAnalysisExecution } from "../src/application/AnalysisProvider.js";
|
||||
import { createEvidenceBundle } from "../src/domain/evidenceBundle.js";
|
||||
|
||||
let directory: string | undefined;
|
||||
|
||||
const TARGET: BinaryTarget = {
|
||||
path: "/tmp/app",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "executable",
|
||||
format: "mach-o",
|
||||
architecture: "arm64",
|
||||
availableArchitectures: ["arm64"],
|
||||
};
|
||||
const PROVIDER = { id: "fixture", name: "Fixture", version: "1" } as const;
|
||||
const PROFILE = createAnalysisProfile(PROVIDER, 1, {
|
||||
loader: "mach-o-arm64",
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
if (directory !== undefined)
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
@@ -28,24 +45,19 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe("analysis snapshots", () => {
|
||||
it("returns detached cache entries and evidence bundles", () => {
|
||||
it("returns detached cache data only from the exact provider/profile partition", () => {
|
||||
const cache = new AnalysisSnapshotCache();
|
||||
const target = {
|
||||
path: "/tmp/app",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "executable",
|
||||
format: "mach-o",
|
||||
architecture: "arm64",
|
||||
loaderArgs: [],
|
||||
} as const;
|
||||
const provider = { id: "fixture", name: "Fixture", version: "1" };
|
||||
cache.record(
|
||||
target,
|
||||
"address_name",
|
||||
{ address: "0x1000", document: "fixture" },
|
||||
createAnalysisExecution("main", provider),
|
||||
);
|
||||
const exported = cache.export(target, createEvidenceBundle([]));
|
||||
const execution = createAnalysisExecution("main", PROVIDER, {
|
||||
analysisProfile: PROFILE,
|
||||
});
|
||||
cache.record({
|
||||
target: TARGET,
|
||||
profile: PROFILE,
|
||||
operation: "address_name",
|
||||
parameters: { address: "0x1000", document: "fixture" },
|
||||
execution,
|
||||
});
|
||||
const exported = cache.export(TARGET, PROFILE, createEvidenceBundle([]));
|
||||
expect(exported.ok).toBe(true);
|
||||
if (!exported.ok) return;
|
||||
const entry = exported.value.entries[0];
|
||||
@@ -55,95 +67,100 @@ describe("analysis snapshots", () => {
|
||||
name: "Forged",
|
||||
version: "9",
|
||||
});
|
||||
(entry.execution.limitations as string[]).push("forged");
|
||||
entry.execution.limitations.push("forged");
|
||||
}
|
||||
|
||||
expect(
|
||||
cache.lookup(
|
||||
target,
|
||||
"address_name",
|
||||
{ address: "0x1000", document: "fixture" },
|
||||
provider,
|
||||
),
|
||||
cache.lookup(TARGET, PROFILE, "address_name", {
|
||||
address: "0x1000",
|
||||
document: "fixture",
|
||||
}),
|
||||
).toMatchObject({
|
||||
provider,
|
||||
provider: PROVIDER,
|
||||
analysisProfile: PROFILE,
|
||||
limitations: [expect.stringContaining("local REA analysis snapshot")],
|
||||
});
|
||||
});
|
||||
|
||||
it("finds exact CLI evidence for provider-free replay", () => {
|
||||
const target = {
|
||||
path: "/tmp/app",
|
||||
sha256: "b".repeat(64),
|
||||
kind: "executable",
|
||||
format: "mach-o",
|
||||
architecture: "arm64",
|
||||
loaderArgs: [],
|
||||
} as const;
|
||||
const evidence = createEvidence(
|
||||
target,
|
||||
{ id: "fixture", name: "Fixture", version: "1" },
|
||||
{
|
||||
operation: "analyze_function",
|
||||
parameters: { procedure: "main" },
|
||||
result: { summary: "cached" },
|
||||
},
|
||||
);
|
||||
const snapshot: AnalysisSnapshot = {
|
||||
snapshot_version: 1,
|
||||
target: {
|
||||
sha256: target.sha256,
|
||||
format: target.format,
|
||||
architecture: target.architecture,
|
||||
loader_args: [],
|
||||
},
|
||||
entries: [],
|
||||
evidence_bundle: createEvidenceBundle([evidence]),
|
||||
};
|
||||
const changedProfile = createAnalysisProfile(PROVIDER, 1, {
|
||||
loader: "configured-override",
|
||||
});
|
||||
expect(
|
||||
snapshotEvidenceForQuery(snapshot, {
|
||||
target,
|
||||
operation: "analyze_function",
|
||||
parameters: {
|
||||
procedure: "main",
|
||||
},
|
||||
provider: { id: "fixture", name: "Fixture", version: "1" },
|
||||
cache.lookup(TARGET, changedProfile, "address_name", {
|
||||
address: "0x1000",
|
||||
document: "fixture",
|
||||
}),
|
||||
).toEqual(evidence);
|
||||
).toBeUndefined();
|
||||
const changedProviderProfile = createAnalysisProfile(
|
||||
{ id: "other", name: "Other", version: "1" },
|
||||
1,
|
||||
{ loader: "mach-o-arm64" },
|
||||
);
|
||||
expect(
|
||||
snapshotEvidenceForQuery(snapshot, {
|
||||
target,
|
||||
operation: "analyze_function",
|
||||
parameters: {
|
||||
procedure: "other",
|
||||
},
|
||||
provider: { id: "fixture", name: "Fixture", version: "1" },
|
||||
cache.lookup(TARGET, changedProviderProfile, "address_name", {
|
||||
address: "0x1000",
|
||||
document: "fixture",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("writes canonical private JSON and rejects a changed query identity", async () => {
|
||||
it("finds only Evidence committed to the exact binding and evidence profile", () => {
|
||||
const evidence = createEvidence(TARGET, PROVIDER, {
|
||||
operation: "analyze_function",
|
||||
parameters: { procedure: "main" },
|
||||
result: { summary: "cached" },
|
||||
analysisProfile: PROFILE,
|
||||
});
|
||||
const legacy = createEvidence(TARGET, PROVIDER, {
|
||||
operation: "legacy_query",
|
||||
parameters: {},
|
||||
result: { summary: "legacy" },
|
||||
});
|
||||
const snapshot: AnalysisSnapshot = {
|
||||
snapshot_version: 2,
|
||||
target: snapshotTarget(TARGET),
|
||||
binding: snapshotBinding(PROFILE),
|
||||
entries: [],
|
||||
evidence_bundle: createEvidenceBundle([evidence, legacy]),
|
||||
};
|
||||
expect(
|
||||
snapshotEvidenceForQuery(snapshot, {
|
||||
target: TARGET,
|
||||
bindingProfile: PROFILE,
|
||||
operation: "analyze_function",
|
||||
parameters: { procedure: "main" },
|
||||
provider: PROVIDER,
|
||||
evidenceProfile: PROFILE,
|
||||
}),
|
||||
).toEqual(evidence);
|
||||
expect(
|
||||
snapshotEvidenceForQuery(snapshot, {
|
||||
target: TARGET,
|
||||
bindingProfile: PROFILE,
|
||||
operation: "legacy_query",
|
||||
parameters: {},
|
||||
provider: PROVIDER,
|
||||
evidenceProfile: PROFILE,
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("writes canonical private v2 JSON and rejects changed query identity", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-analysis-snapshot-"));
|
||||
const path = join(directory, "analysis.json");
|
||||
const target: AnalysisSnapshot["target"] = {
|
||||
sha256: "a".repeat(64),
|
||||
format: "mach-o",
|
||||
architecture: "arm64",
|
||||
loader_args: [],
|
||||
};
|
||||
const entry = createAnalysisSnapshotEntry(
|
||||
const target = snapshotTarget(TARGET);
|
||||
const binding = snapshotBinding(PROFILE);
|
||||
const entry = createAnalysisSnapshotEntry({
|
||||
target,
|
||||
"address_name",
|
||||
{ address: "0x1000" },
|
||||
createAnalysisExecution("main", {
|
||||
id: "fixture",
|
||||
name: "Fixture analysis provider",
|
||||
version: "1",
|
||||
binding,
|
||||
operation: "address_name",
|
||||
parameters: { address: "0x1000" },
|
||||
execution: createAnalysisExecution("main", PROVIDER, {
|
||||
analysisProfile: PROFILE,
|
||||
}),
|
||||
);
|
||||
});
|
||||
const snapshot: AnalysisSnapshot = {
|
||||
snapshot_version: 1,
|
||||
snapshot_version: 2,
|
||||
target,
|
||||
binding,
|
||||
entries: [entry],
|
||||
evidence_bundle: createEvidenceBundle([]),
|
||||
};
|
||||
@@ -160,12 +177,34 @@ describe("analysis snapshots", () => {
|
||||
expect((await stat(path)).mode & 0o777).toBe(0o600);
|
||||
expect((await readAnalysisSnapshot(path, policy)).ok).toBe(true);
|
||||
|
||||
const altered = JSON.parse(await readFile(path, "utf8"));
|
||||
altered.entries[0].parameters.address = "0x2000";
|
||||
const altered: unknown = JSON.parse(await readFile(path, "utf8"));
|
||||
if (
|
||||
typeof altered !== "object" ||
|
||||
altered === null ||
|
||||
!("entries" in altered) ||
|
||||
!Array.isArray(altered.entries)
|
||||
)
|
||||
throw new TypeError("fixture snapshot is malformed");
|
||||
const first: unknown = altered.entries[0];
|
||||
if (
|
||||
typeof first !== "object" ||
|
||||
first === null ||
|
||||
!("parameters" in first) ||
|
||||
typeof first.parameters !== "object" ||
|
||||
first.parameters === null
|
||||
)
|
||||
throw new TypeError("fixture entry is malformed");
|
||||
Reflect.set(first.parameters, "address", "0x2000");
|
||||
await writeFile(path, JSON.stringify(altered));
|
||||
const loaded = await readAnalysisSnapshot(path, policy);
|
||||
expect(loaded.ok).toBe(false);
|
||||
if (!loaded.ok) expect(loaded.error._tag).toBe("EvidenceIntegrityError");
|
||||
expect(() => parseAnalysisSnapshot(altered)).toThrow(/identifier/u);
|
||||
});
|
||||
|
||||
it("rejects snapshot v1 with explicit recapture guidance", () => {
|
||||
expect(() => parseAnalysisSnapshot({ snapshot_version: 1 })).toThrow(
|
||||
/v1.*recapture.*v2/iu,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -413,7 +413,6 @@ const target = (
|
||||
sha256: "0".repeat(64),
|
||||
kind: format === "directory" ? "executable" : "archive",
|
||||
format: format === "directory" ? "mach-o" : format,
|
||||
loaderArgs: [],
|
||||
});
|
||||
|
||||
const limits = () => ({ maxDepth: 20, maxPathBytes: 4_096 });
|
||||
|
||||
@@ -13,8 +13,9 @@ import {
|
||||
HopperStartError,
|
||||
ProviderAdapterError,
|
||||
} from "../src/domain/errors.js";
|
||||
import { err } from "../src/domain/result.js";
|
||||
import { err, ok as resultOk } from "../src/domain/result.js";
|
||||
import { createEvidenceBundle } from "../src/domain/evidenceBundle.js";
|
||||
import { createAnalysisProfile } from "../src/domain/analysisProfile.js";
|
||||
import { createInvestigationWorkspace } from "../src/domain/investigationWorkspace.js";
|
||||
import { observed as ok } from "./fixtures/analysisExecution.js";
|
||||
|
||||
@@ -195,6 +196,47 @@ describe("binary session", () => {
|
||||
expect(opened.ok).toBe(false);
|
||||
if (!opened.ok) expect(opened.error._tag).toBe("EvidenceIntegrityError");
|
||||
await mismatch.close();
|
||||
|
||||
const profileMismatchCalls: string[] = [];
|
||||
const profileMismatchProvider = cacheProvider(profileMismatchCalls);
|
||||
const identity = profileMismatchProvider.identity();
|
||||
profileMismatchProvider.resolveAnalysisProfile = () =>
|
||||
Promise.resolve(
|
||||
resultOk({
|
||||
profile: createAnalysisProfile(
|
||||
{
|
||||
id: identity.id,
|
||||
name: identity.name,
|
||||
version: identity.version ?? "fixture-unresolved",
|
||||
},
|
||||
1,
|
||||
{ fixture: "different-profile" },
|
||||
),
|
||||
compatibility: {},
|
||||
}),
|
||||
);
|
||||
const profileMismatch = new BinarySession(profileMismatchProvider);
|
||||
expect(profileMismatch.importAnalysisSnapshot(snapshot.value).ok).toBe(
|
||||
true,
|
||||
);
|
||||
const profileOpened = await profileMismatch.open(first);
|
||||
expect(profileOpened.ok).toBe(false);
|
||||
if (!profileOpened.ok) {
|
||||
expect(profileOpened.error._tag).toBe("EvidenceIntegrityError");
|
||||
expect(profileOpened.error.message).toContain("profile_mismatch");
|
||||
}
|
||||
expect(profileMismatchCalls).toEqual([]);
|
||||
await profileMismatch.close();
|
||||
|
||||
const activeProfileMismatch = new BinarySession(profileMismatchProvider);
|
||||
expect((await activeProfileMismatch.open(first)).ok).toBe(true);
|
||||
const activeImport = activeProfileMismatch.importAnalysisSnapshot(
|
||||
snapshot.value,
|
||||
);
|
||||
expect(activeImport.ok).toBe(false);
|
||||
if (!activeImport.ok)
|
||||
expect(activeImport.error.message).toContain("profile_mismatch");
|
||||
await activeProfileMismatch.close();
|
||||
});
|
||||
|
||||
it("does not snapshot reads that depend on the provider cursor", async () => {
|
||||
@@ -594,6 +636,13 @@ const cacheProvider = (
|
||||
} as const;
|
||||
return {
|
||||
identity: () => identity,
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({
|
||||
profile: createAnalysisProfile(identity, 1, { fixture: true }),
|
||||
compatibility: {},
|
||||
}),
|
||||
),
|
||||
capabilities: () => [
|
||||
cacheCapability(identity, "address_name", false, mayWriteFilesystem),
|
||||
cacheCapability(identity, "set_address_name", true),
|
||||
|
||||
@@ -39,23 +39,16 @@ describe("executable header parsing", () => {
|
||||
const bytes = fat([0x01000007, 0x0100000c]);
|
||||
const arm = parseExecutableHeader(bytes, "arm64");
|
||||
const intel = parseExecutableHeader(bytes, "x64");
|
||||
expect(arm.ok && arm.value.loaderArgs).toContain("--aarch64");
|
||||
expect(intel.ok && intel.value.loaderArgs).toContain("--intel-64");
|
||||
expect(arm.ok && arm.value).toMatchObject({
|
||||
architecture: "arm64",
|
||||
availableArchitectures: ["x86_64", "arm64"],
|
||||
});
|
||||
expect(intel.ok && intel.value).toMatchObject({
|
||||
architecture: "x86_64",
|
||||
availableArchitectures: ["x86_64", "arm64"],
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
[thinMach(0xfeedfacf, 0x0100000c), ["-l", "Mach-O", "--aarch64"]],
|
||||
[thinMach(0xcefaedfe, 0x01000007), ["-l", "Mach-O", "--intel-64"]],
|
||||
[elf(2, 2, 183), ["-l", "ELF", "--aarch64"]],
|
||||
[pe(0x8664), ["-l", "WinPE", "--intel-64"]],
|
||||
] as const)(
|
||||
"emits a complete non-interactive Hopper selection",
|
||||
(bytes, args) => {
|
||||
const result = parseExecutableHeader(bytes, "arm64");
|
||||
expect(result.ok && result.value.loaderArgs).toEqual(args);
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects FAT files without a host-compatible slice", () => {
|
||||
expect(parseExecutableHeader(fat([0x01000007]), "arm64")).toMatchObject({
|
||||
ok: false,
|
||||
@@ -84,12 +77,10 @@ describe("binary target I/O", () => {
|
||||
expect(archive.ok && archive.value).toMatchObject({
|
||||
kind: "archive",
|
||||
format: "apk",
|
||||
loaderArgs: [],
|
||||
});
|
||||
expect(javascript.ok && javascript.value).toMatchObject({
|
||||
kind: "artifact",
|
||||
format: "javascript",
|
||||
loaderArgs: [],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -190,8 +181,7 @@ describe("binary target I/O", () => {
|
||||
);
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
kind: "database",
|
||||
format: "hopper",
|
||||
loaderArgs: [],
|
||||
format: "analysis-database",
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@ import { ok } from "../src/domain/result.js";
|
||||
const target: BinaryTarget = {
|
||||
path: "/fixture",
|
||||
kind: "database",
|
||||
format: "hopper",
|
||||
format: "analysis-database",
|
||||
sha256: "0".repeat(64),
|
||||
loaderArgs: [],
|
||||
};
|
||||
|
||||
describe("composite analysis provider", () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
@@ -7,10 +7,20 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { writeAnalysisSnapshot } from "../src/application/AnalysisSnapshotFiles.js";
|
||||
import { runDirectAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import type { AnalysisSnapshot } from "../src/domain/analysisSnapshot.js";
|
||||
import {
|
||||
snapshotBinding,
|
||||
snapshotTarget,
|
||||
} from "../src/domain/analysisSnapshot.js";
|
||||
import { parseBinaryTarget } from "../src/domain/binaryTarget.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
import { createEvidenceBundle } from "../src/domain/evidenceBundle.js";
|
||||
import { permissionAuthorityForRoot } from "./fixtures/permissionAuthority.js";
|
||||
import {
|
||||
REA_WORKFLOW_PROVIDER,
|
||||
workflowAnalysisProfile,
|
||||
} from "../src/application/InvestigationProviders.js";
|
||||
import { HOPPER_PROVIDER_IDENTITY } from "../src/hopper/HopperProvider.js";
|
||||
import { resolveHopperAnalysisProfile } from "../src/hopper/HopperAnalysisProfile.js";
|
||||
|
||||
let directory: string | undefined;
|
||||
|
||||
@@ -25,26 +35,29 @@ describe("direct analysis snapshot permissions", () => {
|
||||
it("replays a cache hit with snapshot read authority only", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-direct-snapshot-"));
|
||||
const snapshotPath = join(directory, "analysis.json");
|
||||
const launcherPath = join(directory, "hopper-launcher");
|
||||
await writeFile(launcherPath, "fixture Hopper launcher");
|
||||
const target = await parseBinaryTarget(process.execPath);
|
||||
if (!target.ok) throw target.error;
|
||||
const provider = {
|
||||
id: "rea-workflow",
|
||||
name: "REA composed investigation workflow",
|
||||
version: "1",
|
||||
} as const;
|
||||
const evidence = createEvidence(target.value, provider, {
|
||||
const resolved = await resolveHopperAnalysisProfile(target.value, {
|
||||
launcherPath,
|
||||
loaderArgsOverride: [],
|
||||
provider: HOPPER_PROVIDER_IDENTITY,
|
||||
});
|
||||
if (!resolved.ok || resolved.value.profile === null)
|
||||
throw new Error("fixture Hopper profile did not resolve");
|
||||
const profile = resolved.value.profile;
|
||||
const workflowProfile = workflowAnalysisProfile(profile);
|
||||
const evidence = createEvidence(target.value, REA_WORKFLOW_PROVIDER, {
|
||||
operation: "binary_overview",
|
||||
parameters: {},
|
||||
result: { cached: true },
|
||||
analysisProfile: workflowProfile,
|
||||
});
|
||||
const snapshot: AnalysisSnapshot = {
|
||||
snapshot_version: 1,
|
||||
target: {
|
||||
sha256: target.value.sha256,
|
||||
format: target.value.format,
|
||||
architecture: target.value.architecture ?? null,
|
||||
loader_args: [...target.value.loaderArgs],
|
||||
},
|
||||
snapshot_version: 2,
|
||||
target: snapshotTarget(target.value),
|
||||
binding: snapshotBinding(profile),
|
||||
entries: [],
|
||||
evidence_bundle: createEvidenceBundle([evidence]),
|
||||
};
|
||||
@@ -64,6 +77,7 @@ describe("direct analysis snapshot permissions", () => {
|
||||
["snapshot_read"],
|
||||
);
|
||||
vi.stubEnv("REA_ANALYSIS_SNAPSHOT_ROOTS_JSON", JSON.stringify([directory]));
|
||||
vi.stubEnv("HOPPER_LAUNCHER_PATH", launcherPath);
|
||||
|
||||
await expect(
|
||||
runDirectAnalysis(
|
||||
|
||||
+47
-1
@@ -10,6 +10,7 @@ import {
|
||||
} from "../src/domain/evidence.js";
|
||||
import { createEvidenceBundle } from "../src/domain/evidenceBundle.js";
|
||||
import { recordUnknownInputSchema } from "../src/domain/residualUnknown.js";
|
||||
import { createAnalysisProfile } from "../src/domain/analysisProfile.js";
|
||||
|
||||
const TARGET: BinaryTarget = {
|
||||
path: "/tmp/fixture",
|
||||
@@ -18,11 +19,25 @@ const TARGET: BinaryTarget = {
|
||||
format: "mach-o",
|
||||
architecture: "arm64",
|
||||
availableArchitectures: ["arm64"],
|
||||
loaderArgs: ["-l", "Mach-O", "--aarch64"],
|
||||
};
|
||||
const PROVIDER = { id: "fixture", name: "Fixture provider", version: "1" };
|
||||
const PROFILE = createAnalysisProfile(PROVIDER, 1, { loader: "default" });
|
||||
|
||||
describe("analysis evidence", () => {
|
||||
it("keeps the public object schema extensible for typed consumers", () => {
|
||||
expect(evidenceSchema.shape.analysis_profile).toBeDefined();
|
||||
expect(evidenceSchema.shape.provider).toBeDefined();
|
||||
});
|
||||
|
||||
it("derives identity after normalizing prototype-named parameter keys", () => {
|
||||
const evidence = createEvidence(TARGET, PROVIDER, {
|
||||
operation: "health",
|
||||
parameters: Object.fromEntries([["__proto__", false]]),
|
||||
result: true,
|
||||
});
|
||||
expect(parseEvidence(evidence)).toEqual(evidence);
|
||||
});
|
||||
|
||||
it.prop([
|
||||
fc.dictionary(
|
||||
fc.string({ minLength: 1, maxLength: 12 }),
|
||||
@@ -89,6 +104,37 @@ describe("analysis evidence", () => {
|
||||
expect(createEvidence(TARGET, PROVIDER, observation)).toEqual(evidence);
|
||||
});
|
||||
|
||||
it("preserves legacy IDs while committing profiles on new observations", () => {
|
||||
const legacy = createEvidence(TARGET, PROVIDER, {
|
||||
operation: "procedure_info",
|
||||
parameters: { procedure: "main" },
|
||||
result: { name: "main" },
|
||||
});
|
||||
expect("analysis_profile" in legacy).toBe(false);
|
||||
expect(parseEvidence(legacy)).toEqual(legacy);
|
||||
|
||||
const profiled = createEvidence(TARGET, PROVIDER, {
|
||||
operation: "procedure_info",
|
||||
parameters: { procedure: "main" },
|
||||
result: { name: "main" },
|
||||
analysisProfile: PROFILE,
|
||||
});
|
||||
expect(profiled).toMatchObject({ analysis_profile: PROFILE });
|
||||
expect(profiled.evidence_id).not.toBe(legacy.evidence_id);
|
||||
expect(() =>
|
||||
createEvidence(
|
||||
TARGET,
|
||||
{ ...PROVIDER, id: "other" },
|
||||
{
|
||||
operation: "procedure_info",
|
||||
parameters: {},
|
||||
result: null,
|
||||
analysisProfile: PROFILE,
|
||||
},
|
||||
),
|
||||
).toThrow(/profile provider/u);
|
||||
});
|
||||
|
||||
it("excludes local paths but includes redacted raw results in identity", () => {
|
||||
const observation = {
|
||||
operation: "health",
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import type { BinaryTarget } from "../src/domain/binaryTarget.js";
|
||||
import {
|
||||
hopperLoaderArgsForTarget,
|
||||
resolveHopperAnalysisProfile,
|
||||
} from "../src/hopper/HopperAnalysisProfile.js";
|
||||
import { HOPPER_PROVIDER_IDENTITY } from "../src/hopper/HopperProvider.js";
|
||||
|
||||
let directory: string | undefined;
|
||||
|
||||
afterEach(async () => {
|
||||
if (directory !== undefined)
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
directory = undefined;
|
||||
});
|
||||
|
||||
describe("Hopper analysis profiles", () => {
|
||||
it.each([
|
||||
[target("mach-o", "arm64"), ["-l", "Mach-O", "--aarch64"]],
|
||||
[target("elf", "x86_64"), ["-l", "ELF", "--intel-64"]],
|
||||
[target("pe", "x86"), ["-l", "WinPE", "--intel-32"]],
|
||||
[
|
||||
{
|
||||
...target("mach-o", "arm64"),
|
||||
availableArchitectures: ["x86_64", "arm64"],
|
||||
} satisfies BinaryTarget,
|
||||
["-l", "FAT", "--aarch64", "-l", "Mach-O"],
|
||||
],
|
||||
[
|
||||
{
|
||||
path: "/tmp/fixture.hop",
|
||||
sha256: "b".repeat(64),
|
||||
kind: "database",
|
||||
format: "analysis-database",
|
||||
} satisfies BinaryTarget,
|
||||
[],
|
||||
],
|
||||
] as const)("derives complete non-interactive options", (input, expected) => {
|
||||
expect(hopperLoaderArgsForTarget(input)).toEqual({
|
||||
ok: true,
|
||||
value: expected,
|
||||
});
|
||||
expect("loaderArgs" in input).toBe(false);
|
||||
});
|
||||
|
||||
it("commits launcher build and configured overrides without target coupling", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-hopper-profile-"));
|
||||
const launcher = join(directory, "hopper");
|
||||
await writeFile(launcher, "Hopper build A");
|
||||
const input = target("mach-o", "arm64");
|
||||
const derived = await resolveHopperAnalysisProfile(input, {
|
||||
launcherPath: launcher,
|
||||
loaderArgsOverride: [],
|
||||
provider: HOPPER_PROVIDER_IDENTITY,
|
||||
});
|
||||
const overridden = await resolveHopperAnalysisProfile(input, {
|
||||
launcherPath: launcher,
|
||||
loaderArgsOverride: ["-l", "Mach-O", "--intel-64"],
|
||||
provider: HOPPER_PROVIDER_IDENTITY,
|
||||
});
|
||||
if (
|
||||
!derived.ok ||
|
||||
derived.value.profile === null ||
|
||||
!overridden.ok ||
|
||||
overridden.value.profile === null
|
||||
)
|
||||
throw new Error("fixture profiles did not resolve");
|
||||
expect(derived.value.compatibility).toEqual({
|
||||
loaderArgs: ["-l", "Mach-O", "--aarch64"],
|
||||
});
|
||||
expect(overridden.value.compatibility).toEqual({
|
||||
loaderArgs: ["-l", "Mach-O", "--intel-64"],
|
||||
});
|
||||
expect(overridden.value.profile.digest).not.toBe(
|
||||
derived.value.profile.digest,
|
||||
);
|
||||
expect(derived.value.profile.provider.version).toMatch(
|
||||
/^launcher-sha256:[a-f0-9]{64}$/u,
|
||||
);
|
||||
|
||||
await writeFile(launcher, "Hopper build B");
|
||||
const changedBuild = await resolveHopperAnalysisProfile(input, {
|
||||
launcherPath: launcher,
|
||||
loaderArgsOverride: [],
|
||||
provider: HOPPER_PROVIDER_IDENTITY,
|
||||
});
|
||||
if (!changedBuild.ok || changedBuild.value.profile === null)
|
||||
throw new Error("changed fixture profile did not resolve");
|
||||
expect(changedBuild.value.profile.provider.version).not.toBe(
|
||||
derived.value.profile.provider.version,
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps compatibility output but declines cache identity when version is unresolved", async () => {
|
||||
const resolved = await resolveHopperAnalysisProfile(
|
||||
target("elf", "x86_64"),
|
||||
{
|
||||
launcherPath: "/missing/hopper",
|
||||
loaderArgsOverride: [],
|
||||
provider: HOPPER_PROVIDER_IDENTITY,
|
||||
},
|
||||
);
|
||||
expect(resolved).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
profile: null,
|
||||
compatibility: {
|
||||
loaderArgs: ["-l", "ELF", "--intel-64"],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const target = (
|
||||
format: "mach-o" | "elf" | "pe",
|
||||
architecture: "x86" | "x86_64" | "arm" | "arm64",
|
||||
): BinaryTarget => ({
|
||||
path: "/tmp/fixture",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "executable",
|
||||
format,
|
||||
architecture,
|
||||
availableArchitectures: [architecture],
|
||||
});
|
||||
@@ -339,7 +339,6 @@ const machoTarget = (path: string, sourcePath?: string): BinaryTarget => ({
|
||||
format: "mach-o",
|
||||
architecture: "arm64",
|
||||
availableArchitectures: ["x86_64", "arm64"],
|
||||
loaderArgs: [],
|
||||
});
|
||||
|
||||
const fixture = (name: string): Promise<string> =>
|
||||
|
||||
@@ -18,6 +18,14 @@ import {
|
||||
} from "../src/domain/evidenceBundle.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
import { silentLogger } from "../src/logger.js";
|
||||
import { createAnalysisProfile } from "../src/domain/analysisProfile.js";
|
||||
import { ok as resultOk } from "../src/domain/result.js";
|
||||
|
||||
const SNAPSHOT_PROFILE = createAnalysisProfile(
|
||||
{ id: "fixture", name: "Fixture analysis provider", version: "1" },
|
||||
1,
|
||||
{ fixture: true },
|
||||
);
|
||||
|
||||
const resources: Array<{ close(): Promise<unknown> }> = [];
|
||||
const processFixture = fileURLToPath(
|
||||
@@ -37,7 +45,12 @@ describe("target-free MCP lifecycle", () => {
|
||||
const targetPath = join(directory, "mutable.hop");
|
||||
await writeFile(targetPath, "first");
|
||||
const closed: string[] = [];
|
||||
const session = new BinarySession((target) => client(target.path, closed));
|
||||
const session = new BinarySession((target) => client(target.path, closed), {
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({ profile: SNAPSHOT_PROFILE, compatibility: {} }),
|
||||
),
|
||||
});
|
||||
const server = createServer(session, session, { logger: silentLogger });
|
||||
const mcp = new Client({ name: "replaced-target", version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] =
|
||||
@@ -87,7 +100,12 @@ describe("target-free MCP lifecycle", () => {
|
||||
await writeFile(first, "one");
|
||||
await writeFile(second, "two");
|
||||
const closed: string[] = [];
|
||||
const session = new BinarySession((target) => client(target.path, closed));
|
||||
const session = new BinarySession((target) => client(target.path, closed), {
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({ profile: SNAPSHOT_PROFILE, compatibility: {} }),
|
||||
),
|
||||
});
|
||||
const server = createServer(session, session, {
|
||||
logger: silentLogger,
|
||||
evidenceFilePolicy: {
|
||||
|
||||
@@ -6,7 +6,10 @@ import { ok } from "../src/domain/result.js";
|
||||
import { err } from "../src/domain/result.js";
|
||||
import { HopperProcessError } from "../src/domain/errors.js";
|
||||
import { toCallToolResult } from "../src/server/toolResult.js";
|
||||
import { createEvidence, evidenceSchema } from "../src/domain/evidence.js";
|
||||
import {
|
||||
createEvidence,
|
||||
evidenceEnvelopeSchema,
|
||||
} from "../src/domain/evidence.js";
|
||||
|
||||
const contract: ToolContract = {
|
||||
name: "provider_neutral_fixture",
|
||||
@@ -74,7 +77,7 @@ describe("tool result projection", () => {
|
||||
);
|
||||
const evidenceContract: ToolContract = {
|
||||
...contract,
|
||||
outputSchema: evidenceSchema,
|
||||
outputSchema: evidenceEnvelopeSchema,
|
||||
};
|
||||
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user