feat(native): add inspection primitives, dispatch traces and approved UI observation (#500)
* fix(hopper): normalize string-backed addresses and update verification * feat(native): add inspection primitives, dispatch traces and approved UI observation * test: prioritize real artifact E2E and captured golden regressions * fix(process): queue observed output before reactive rendering actions * test: prune redundant cases and strengthen boundary assertions * fix(cli): route native value tracing through shared workflows * test: replace synthetic success with real workflows and captured data * fix(catalog): separate portable metadata from native host availability
This commit is contained in:
@@ -84,12 +84,6 @@ describe("Android application projection", () => {
|
||||
expect.objectContaining({ basis: "react-native-convention" }),
|
||||
]);
|
||||
expect(JSON.stringify(left)).not.toContain("opaque signing");
|
||||
expect(
|
||||
androidApplicationProjectionResultSchema.safeParse({
|
||||
...left,
|
||||
limitations: Array.from({ length: 101 }, () => "x".repeat(4_097)),
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects non-APK inventory Evidence", async () => {
|
||||
|
||||
@@ -9,25 +9,18 @@ import {
|
||||
} from "@zip.js/zip.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { fragmentInventoryEvidence } from "../../fixtures/artifactEvidence.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { projectAppleApplicationEvidence } from "../../../src/application/AppleApplicationService.js";
|
||||
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
||||
import { appleApplicationProjectionResultSchema } from "../../../src/domain/appleApplication.js";
|
||||
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
|
||||
// Sized to prove the claims this projection makes -- multiple inventory pages,
|
||||
// every component retained, and one bridge candidate per script/native pair --
|
||||
// and to cross any ceiling a truncation regression would plausibly introduce.
|
||||
// A fixture of a dozen frameworks and 16 candidates would pass unnoticed
|
||||
// against a cap at 100, which is the truncation this guards against. The
|
||||
// original 1_001 frameworks x 101 pages produced 10_201 candidates and cost
|
||||
// ~6.4s, roughly half the composition lane, to assert the same properties an
|
||||
// order of magnitude above the plausible-ceiling range.
|
||||
// Real ZIP entries cross the former component and bridge-candidate limits.
|
||||
const FRAMEWORK_COUNT = 250;
|
||||
const SCRIPT_COUNT = 40;
|
||||
const NATIVE_COUNT = 40;
|
||||
const INVENTORY_PAGE_COUNT = 3;
|
||||
|
||||
async function createCompleteAppleProjection() {
|
||||
const root = await createTestTempDirectory("rea-apple-complete-");
|
||||
@@ -59,43 +52,20 @@ async function createCompleteAppleProjection() {
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const subject = inventory.subject;
|
||||
expect(subject).not.toBeNull();
|
||||
if (subject === null)
|
||||
throw new TypeError("Missing fixture inventory subject");
|
||||
const inventoryPages = Array.from(
|
||||
{ length: INVENTORY_PAGE_COUNT },
|
||||
(_, index) =>
|
||||
createEvidence(
|
||||
{
|
||||
path: subject.local_path,
|
||||
sha256: subject.digest.sha256,
|
||||
format: subject.format,
|
||||
...(subject.architecture === null
|
||||
? {}
|
||||
: { architecture: subject.architecture }),
|
||||
},
|
||||
inventory.provider,
|
||||
{
|
||||
predicateType: inventory.predicate_type,
|
||||
operation: inventory.operation,
|
||||
parameters: {
|
||||
...inventory.parameters,
|
||||
projection_test_page: index,
|
||||
},
|
||||
result: inventory.normalized_result,
|
||||
},
|
||||
),
|
||||
);
|
||||
const fragments = fragmentInventoryEvidence(inventory, 3);
|
||||
const result = projectAppleApplicationEvidence({
|
||||
inventory_evidence: inventoryPages,
|
||||
inventory_evidence: fragments,
|
||||
});
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw new TypeError("Could not project fixture inventory");
|
||||
return appleApplicationProjectionResultSchema.parse(
|
||||
const projection = appleApplicationProjectionResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
);
|
||||
expect([...projection.source_evidence_ids].sort()).toEqual(
|
||||
fragments.map(({ evidence_id }) => evidence_id).sort(),
|
||||
);
|
||||
return projection;
|
||||
}
|
||||
|
||||
describe("Apple application projection", () => {
|
||||
@@ -149,33 +119,6 @@ describe("Apple application projection", () => {
|
||||
second.value.normalized_result,
|
||||
);
|
||||
expect(left).toEqual(right);
|
||||
const longPath = `Payload/${"deep/".repeat(1_000)}Fixture.app`;
|
||||
expect(
|
||||
appleApplicationProjectionResultSchema.parse({
|
||||
...left,
|
||||
application_roots: [longPath],
|
||||
}).application_roots,
|
||||
).toEqual([longPath]);
|
||||
expect(
|
||||
appleApplicationProjectionResultSchema.parse({
|
||||
...left,
|
||||
limitations: ["x".repeat(5_000)],
|
||||
}).limitations,
|
||||
).toEqual(["x".repeat(5_000)]);
|
||||
const [framework, ...otherFrameworks] = left.components.frameworks;
|
||||
if (framework === undefined) throw new Error("Expected framework fixture");
|
||||
expect(
|
||||
appleApplicationProjectionResultSchema.parse({
|
||||
...left,
|
||||
components: {
|
||||
...left.components,
|
||||
frameworks: [
|
||||
{ ...framework, format: "x".repeat(500) },
|
||||
...otherFrameworks,
|
||||
],
|
||||
},
|
||||
}).components.frameworks[0]?.format,
|
||||
).toBe("x".repeat(500));
|
||||
expect(left).toMatchObject({
|
||||
root_format: "ipa",
|
||||
application_roots: ["Payload/Fixture.app"],
|
||||
@@ -224,18 +167,14 @@ describe("Apple application projection", () => {
|
||||
});
|
||||
|
||||
describe("Apple application projection completeness", () => {
|
||||
it("returns every component, inventory page, and bridge hypothesis", async () => {
|
||||
it("returns every component and bridge hypothesis from fragments of a real ZIP inventory", async () => {
|
||||
const projection = await createCompleteAppleProjection();
|
||||
expect(projection.components.frameworks).toHaveLength(FRAMEWORK_COUNT);
|
||||
expect(projection.components.bundle_metadata).toHaveLength(FRAMEWORK_COUNT);
|
||||
expect(projection.components.javascript).toHaveLength(SCRIPT_COUNT);
|
||||
expect(projection.components.native_libraries).toHaveLength(NATIVE_COUNT);
|
||||
expect(projection.source_evidence_ids).toHaveLength(INVENTORY_PAGE_COUNT);
|
||||
// Every inventory page is retained exactly once.
|
||||
expect(new Set(projection.source_evidence_ids).size).toBe(
|
||||
projection.source_evidence_ids.length,
|
||||
);
|
||||
expect(projection.source_evidence_ids.length).toBeGreaterThan(1);
|
||||
expect(projection.source_evidence_ids).toHaveLength(3);
|
||||
expect(new Set(projection.source_evidence_ids).size).toBe(3);
|
||||
// One candidate per script/native pair. Deriving this catches a pairing
|
||||
// regression, which the previous literal 10_201 could not.
|
||||
expect(projection.bridge_candidates).toHaveLength(
|
||||
@@ -249,12 +188,13 @@ describe("Apple application projection completeness", () => {
|
||||
expect(projection).not.toHaveProperty("omitted_bridge_candidates");
|
||||
});
|
||||
|
||||
it("infers an application root when the IPA omits directory entries", async () => {
|
||||
it("retains long ZIP application roots when the IPA omits directory entries", async () => {
|
||||
const root = await createTestTempDirectory("rea-apple-root-");
|
||||
const path = join(root, "Fixture.ipa");
|
||||
const applicationRoot = `Payload/${"LongApp".repeat(750)}.app`;
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
"Payload/Fixture.app/Fixture",
|
||||
`${applicationRoot}/Fixture`,
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]),
|
||||
),
|
||||
@@ -274,7 +214,7 @@ describe("Apple application projection completeness", () => {
|
||||
result.value.normalized_result,
|
||||
),
|
||||
).toMatchObject({
|
||||
application_roots: ["Payload/Fixture.app"],
|
||||
application_roots: [applicationRoot],
|
||||
components: { executables: [expect.any(Object)] },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { fragmentInventoryEvidence } from "../../fixtures/artifactEvidence.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { inventoryArtifact } from "../../../src/application/ArtifactInventory.js";
|
||||
@@ -39,26 +40,6 @@ const observe = async (path: string) => {
|
||||
);
|
||||
};
|
||||
|
||||
const evidencePages = (
|
||||
inventory: Awaited<ReturnType<typeof observe>>,
|
||||
side: string,
|
||||
) =>
|
||||
Array.from({ length: 101 }, (_, index) =>
|
||||
createEvidence(
|
||||
{
|
||||
path: `${side}-${String(index)}`,
|
||||
sha256: inventory.subject?.digest.sha256 ?? "0".repeat(64),
|
||||
format: inventory.subject?.format ?? "directory",
|
||||
},
|
||||
PROVIDER,
|
||||
{
|
||||
operation: "inventory_artifact",
|
||||
parameters: { page: index, side },
|
||||
result: jsonValueSchema.parse(inventory.normalized_result),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const changedArtifactComparison = async () => {
|
||||
const parent = await createTestTempDirectory("rea-artifact-compare-");
|
||||
const leftPath = join(parent, "left.app");
|
||||
@@ -113,30 +94,6 @@ describe("artifact comparison", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("accepts all reported comparison dimensions", async () => {
|
||||
const result = (await changedArtifactComparison()).result;
|
||||
const firstChange = result.changes[0];
|
||||
if (firstChange === undefined) throw new Error("Expected artifact change");
|
||||
|
||||
const dimensions = [
|
||||
"content",
|
||||
"kind",
|
||||
"format",
|
||||
"size",
|
||||
"executable",
|
||||
"relations",
|
||||
"metadata",
|
||||
"availability",
|
||||
"integrity",
|
||||
] as const;
|
||||
expect(
|
||||
artifactComparisonResultSchema.parse({
|
||||
...result,
|
||||
changes: [{ ...firstChange, dimensions }, ...result.changes.slice(1)],
|
||||
}).changes[0]?.dimensions,
|
||||
).toEqual(dimensions);
|
||||
});
|
||||
|
||||
it("reports incomplete inventory as truncated, never unchanged", async () => {
|
||||
const root = await createTestTempDirectory("rea-artifact-truncated-");
|
||||
await writeFile(join(root, "one.txt"), "one");
|
||||
@@ -220,27 +177,63 @@ describe("artifact comparison completeness", () => {
|
||||
});
|
||||
}, 15_000);
|
||||
|
||||
it("retains every inventory citation when comparing many evidence pages", async () => {
|
||||
const parent = await createTestTempDirectory(
|
||||
"rea-artifact-pages-evidence-",
|
||||
);
|
||||
it("assembles real inventory fragments and retains every citation", async () => {
|
||||
const parent = await createTestTempDirectory("rea-artifact-fragments-");
|
||||
const leftPath = join(parent, "left.app");
|
||||
const rightPath = join(parent, "right.app");
|
||||
await Promise.all([mkdir(leftPath), mkdir(rightPath)]);
|
||||
await Promise.all([
|
||||
writeFile(join(leftPath, "main.js"), "left();"),
|
||||
writeFile(join(rightPath, "main.js"), "right();"),
|
||||
]);
|
||||
|
||||
const leftInventory = await observe(leftPath);
|
||||
const rightInventory = await observe(rightPath);
|
||||
const comparison = compareArtifacts(
|
||||
evidencePages(leftInventory, "left"),
|
||||
evidencePages(rightInventory, "right"),
|
||||
// Cross the former 100-citation limit with distinct, real graph members.
|
||||
const fragmentCount = 101;
|
||||
await Promise.all(
|
||||
Array.from({ length: fragmentCount }, async (_, index) => {
|
||||
await Promise.all([
|
||||
writeFile(join(leftPath, `file-${index}.js`), `left(${index});`),
|
||||
writeFile(join(rightPath, `file-${index}.js`), `right(${index});`),
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
expect(comparison.changes[0]?.evidence_links).toHaveLength(202);
|
||||
});
|
||||
const left = await observe(leftPath);
|
||||
const right = await observe(rightPath);
|
||||
const leftFragments = fragmentInventoryEvidence(left, fragmentCount);
|
||||
const rightFragments = fragmentInventoryEvidence(right, fragmentCount);
|
||||
const citations = [...leftFragments, ...rightFragments]
|
||||
.map(({ evidence_id }) => evidence_id)
|
||||
.sort();
|
||||
expect(new Set(citations).size).toBe(fragmentCount * 2);
|
||||
const comparison = compareArtifacts(leftFragments, rightFragments);
|
||||
const complete = compareArtifacts(left, right);
|
||||
expect(
|
||||
comparison.changes
|
||||
.filter(({ logical_path }) => logical_path !== ".")
|
||||
.map(({ logical_path, classification }) => ({
|
||||
logical_path,
|
||||
classification,
|
||||
}))
|
||||
.sort((left, right) =>
|
||||
left.logical_path.localeCompare(right.logical_path),
|
||||
),
|
||||
).toEqual(
|
||||
Array.from({ length: fragmentCount }, (_, index) => ({
|
||||
logical_path: `file-${index}.js`,
|
||||
classification: "changed",
|
||||
})).sort((left, right) =>
|
||||
left.logical_path.localeCompare(right.logical_path),
|
||||
),
|
||||
);
|
||||
expect({
|
||||
...comparison,
|
||||
changes: comparison.changes.map((change) => ({
|
||||
...change,
|
||||
evidence_links: [...change.evidence_links].sort(),
|
||||
})),
|
||||
}).toEqual({
|
||||
...complete,
|
||||
changes: complete.changes.map((change) => ({
|
||||
...change,
|
||||
evidence_links: citations,
|
||||
})),
|
||||
});
|
||||
}, 15_000);
|
||||
|
||||
it("rejects non-inventory and tampered Evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-artifact-invalid-");
|
||||
|
||||
@@ -514,6 +514,7 @@ describe("typed unavailability without dispatching", () => {
|
||||
const session = createTestBinarySession(() => client());
|
||||
expect((await session.execute("binary_overview", {})).ok).toBe(false);
|
||||
expect(await session.close()).toEqual({ ok: true, value: null });
|
||||
expect(await session.close()).toEqual({ ok: true, value: null });
|
||||
});
|
||||
|
||||
it("keeps the active client when a switch fails", async () => {
|
||||
@@ -622,14 +623,14 @@ describe("active client replacement", () => {
|
||||
clients.push(value);
|
||||
return value;
|
||||
});
|
||||
await session.open(first);
|
||||
expect((await session.open(first)).ok).toBe(true);
|
||||
const call = session.execute("procedure_pseudo_code", {});
|
||||
const switching = session.open(second);
|
||||
await Promise.resolve();
|
||||
expect(clients[0]?.closed).toBe(0);
|
||||
active.resolve(ok(null));
|
||||
await call;
|
||||
await switching;
|
||||
expect((await call).ok).toBe(true);
|
||||
expect((await switching).ok).toBe(true);
|
||||
expect(clients[0]?.closed).toBe(1);
|
||||
});
|
||||
|
||||
@@ -744,8 +745,9 @@ describe("cancellation during profile resolution", () => {
|
||||
clients.push(value);
|
||||
return value;
|
||||
});
|
||||
await session.open(first);
|
||||
await session.open(second);
|
||||
expect((await session.open(first)).ok).toBe(true);
|
||||
expect((await session.open(second)).ok).toBe(false);
|
||||
expect((await session.execute("address_name", {})).ok).toBe(true);
|
||||
expect(clients[1]?.closed).toBe(1);
|
||||
expect(clients[0]?.closed).toBe(1);
|
||||
expect(clients[2]?.closed).toBe(0);
|
||||
@@ -770,10 +772,12 @@ describe("cancellation during profile resolution", () => {
|
||||
return Promise.resolve();
|
||||
},
|
||||
}));
|
||||
await session.open(first);
|
||||
await session.open(second);
|
||||
expect((await session.open(first)).ok).toBe(true);
|
||||
expect((await session.open(second)).ok).toBe(true);
|
||||
expect(liveClients).toBe(1);
|
||||
expect(overlapped).toBe(false);
|
||||
await session.close();
|
||||
expect(liveClients).toBe(0);
|
||||
});
|
||||
|
||||
it("clears session state while preserving a typed provider cleanup failure", async () => {
|
||||
|
||||
@@ -10,28 +10,18 @@ import { analyzeJavaScriptApplicationInputSchema } from "../../../src/domain/jav
|
||||
import { writeElectronBoundaryFixture } from "../../fixtures/electronBoundaryApplication.js";
|
||||
|
||||
describe("static Electron application analysis", () => {
|
||||
it("accepts an absolute caller path without caller-selected analysis bounds", () => {
|
||||
it("rejects relative paths and caller-selected analysis bounds", () => {
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.safeParse({
|
||||
input_path: "relative/app.asar",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.safeParse({
|
||||
input_path: "/tmp/app.asar",
|
||||
}).success,
|
||||
).toBe(true);
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.safeParse({
|
||||
input_path: "/tmp/app.asar",
|
||||
limits: { max_findings: 200_000 },
|
||||
}).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.parse({
|
||||
input_path: "/tmp/app.asar",
|
||||
}),
|
||||
).toEqual({ input_path: "/tmp/app.asar", format: "auto" });
|
||||
});
|
||||
|
||||
it("maps windows, preload, contextBridge, IPC, validations, utility, and native boundaries without execution", async () => {
|
||||
|
||||
@@ -26,15 +26,6 @@ it("reconstructs package, Electron roles, Webpack/Rspack modules, and cross-laye
|
||||
|
||||
expect(Reflect.get(globalThis, "__rea_bundle_executed")).toBeUndefined();
|
||||
expect(result.input_path).toBe(root);
|
||||
const longPath = `/${"deep/".repeat(4_000)}application`;
|
||||
const { electron_summary: summary, ...analysisResult } = result;
|
||||
expect(
|
||||
javascriptApplicationAnalysisResultSchema.parse({
|
||||
...analysisResult,
|
||||
summary,
|
||||
input_path: longPath,
|
||||
}).input_path,
|
||||
).toBe(longPath);
|
||||
expect(result.statistics).toMatchObject({
|
||||
modules: 4,
|
||||
parse_failures: 0,
|
||||
@@ -127,7 +118,6 @@ it("produces deterministic ASAR graphs with unpacked native linkage and complete
|
||||
|
||||
expect(first.graph).toEqual(second.graph);
|
||||
expect(first.inventory_graph_sha256).toBe(second.inventory_graph_sha256);
|
||||
expect(first.graph.graph_id).toBe(second.graph.graph_id);
|
||||
expect(first.graph.nodes).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -56,6 +56,11 @@ it("matches renderer, frame, script bytes, and worker without claiming execution
|
||||
expect(() =>
|
||||
javascriptRuntimeReconciliationResultSchema.parse(result),
|
||||
).not.toThrow();
|
||||
expect(result.source_map_authority).toMatchObject({
|
||||
used_for_primary_matching: false,
|
||||
static_layer_count: 1,
|
||||
runtime_script_declarations: 0,
|
||||
});
|
||||
expect(result.summary).toMatchObject({
|
||||
runtime_targets: 1,
|
||||
runtime_frames: 1,
|
||||
@@ -153,22 +158,6 @@ it("reports a captured digest disagreement instead of accepting a path match", a
|
||||
expect(script?.candidate_static_nodes).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps source-map declarations outside primary matching authority", async () => {
|
||||
const fixture = await applicationFixture();
|
||||
const staticEvidence = await analyzeFixture(fixture);
|
||||
const runtimeEvidence = electronRuntimeEvidence(fixture, SOURCE);
|
||||
const result = reconcileJavaScriptRuntime({
|
||||
static_layers: [{ role: "application", analysis: staticEvidence }],
|
||||
runtime_observations: [runtimeEvidence],
|
||||
});
|
||||
|
||||
expect(result.source_map_authority).toMatchObject({
|
||||
used_for_primary_matching: false,
|
||||
static_layer_count: 1,
|
||||
runtime_script_declarations: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it("reconciles active Electron as a partial target-only runtime capture", async () => {
|
||||
const fixture = await applicationFixture();
|
||||
const staticEvidence = await analyzeFixture(fixture);
|
||||
|
||||
Reference in New Issue
Block a user