refactor(tools): return complete analysis results inline

This commit is contained in:
morluto
2026-09-29 14:53:50 +08:00
parent c34efca4cd
commit 2a6eb41147
156 changed files with 2529 additions and 1891 deletions
@@ -27,7 +27,7 @@ it("reads local source maps as part of static artifact analysis", async () => {
);
});
it("does not follow symlinks or exceed the internal text-file safety boundary", async () => {
it("does not follow symlinks and analyzes text beyond the former file-size cap", async () => {
const root = await fixtureDirectory();
const outside = await createTestTempDirectory("rea-javascript-outside-");
const outsideFile = join(outside, "secret.js");
@@ -36,22 +36,23 @@ it("does not follow symlinks or exceed the internal text-file safety boundary",
'fetch("https://outside-secret.invalid/credential");',
);
await symlink(outsideFile, join(root, "escape.js"));
await writeFile(
join(root, "oversized.js"),
`const oversizedSecret = "${"private-marker-".repeat(600_000)}";`,
);
const baseline = await reconstructJavaScriptArtifact({ input_path: root });
const oversizedSource = `// ${"private-marker-".repeat(600_000)}\nfetch("https://inside.invalid");\n`;
await writeFile(join(root, "oversized.js"), oversizedSource);
const result = await reconstructJavaScriptArtifact({ input_path: root });
const encoded = JSON.stringify(result);
expect(result.statistics.limit_omitted_text_files).toBeGreaterThan(0);
expect(result.statistics.text_bytes_read).toBeGreaterThan(8 * 1024 * 1024);
expect(result.graph.coverage).toMatchObject({
status: "partial",
truncated: true,
status: "complete",
truncated: false,
});
expect(encoded).not.toContain(outsideFile);
expect(encoded).not.toContain("outside-secret.invalid");
expect(encoded).not.toContain("private-marker-private-marker");
expect(result.statistics.visited_ast_nodes).toBeGreaterThan(
baseline.statistics.visited_ast_nodes,
);
});
it("keeps malformed JavaScript, package metadata, and source maps as explicit unknowns", async () => {
@@ -13,7 +13,10 @@ import {
import { MANAGED_STATIC_PROVIDER } from "../../../src/application/InvestigationProviders.js";
import { createPermissionAuthority } from "../../../src/application/PermissionAuthority.js";
import { createEvidence } from "../../../src/domain/evidence.js";
import { managedRuntimeCorrelationResultSchema } from "../../../src/domain/managedRuntimeCorrelation.js";
import {
managedRuntimeCorrelationInputSchema,
managedRuntimeCorrelationResultSchema,
} from "../../../src/domain/managedRuntimeCorrelation.js";
import type { PermissionCeiling } from "../../../src/domain/permissionPolicy.js";
import { inspectManagedMembersBytes } from "../../../src/dotnet/ManagedMemberInspector.js";
import {
@@ -81,6 +84,24 @@ describe("managed runtime correlation planning", () => {
const plan = managedRuntimeCorrelationResultSchema.parse(
result.value.normalized_result,
);
expect(
managedRuntimeCorrelationInputSchema.safeParse({
...inputFor(fixture.evidence, fixture.method),
bounds: {
timeout_ms: 60_001,
max_threads: 257,
max_output_bytes: 1_048_577,
allow_network: false,
allow_ui: false,
},
}).success,
).toBe(true);
expect(
managedRuntimeCorrelationResultSchema.safeParse({
...plan,
limitations: Array.from({ length: 1_001 }, () => "x".repeat(4_097)),
}).success,
).toBe(true);
expect(plan).toMatchObject({
executed: false,
authority_model: {
@@ -17,6 +17,7 @@ import type {
} from "../../../src/application/JavaScriptReplayPlanning.js";
import { PermissionAuthority } from "../../../src/application/PermissionAuthority.js";
import { createPermissionPolicy } from "../../../src/domain/permissionPolicy.js";
import { createRuntimeCharacterizationPlan } from "../../../src/domain/runtimeCharacterization.js";
import {
nodeCharacterizationPreparationInputSchema,
nodeCharacterizationPreparationOutputSchema,
@@ -41,6 +42,12 @@ describe("Node runtime characterization", () => {
const output = nodeCharacterizationPreparationOutputSchema.parse(
prepared.value,
);
const { plan_sha256: _planSha256, ...planWithoutDigest } = output.plan;
const expandedPlan = createRuntimeCharacterizationPlan({
...planWithoutDigest,
limits: { ...output.plan.limits, max_calls: 10_001 },
});
expect(expandedPlan.limits.max_calls).toBe(10_001);
expect(output).toMatchObject({
phase: "preparation",
plan: {
@@ -92,14 +99,26 @@ describe("Node runtime characterization", () => {
expect(await readFile(fixture.path)).toEqual(Buffer.from(fixture.bytes));
});
it("rejects aliases that cannot fit the provider-neutral plan identity", async () => {
it("accepts aliases longer than the former identity ceiling", async () => {
const input = preparationInput(await createFixture());
expect(() =>
const alias = "a".repeat(201);
expect(
nodeCharacterizationPreparationInputSchema.parse({
...input,
selected_alias: "a".repeat(201),
}),
).toThrow();
selected_alias: alias,
replay: {
...input.replay,
left: {
...input.replay.left,
entry_alias: alias,
modules: input.replay.left.modules.map((module) => ({
...module,
alias,
})),
},
},
}).selected_alias,
).toBe(alias);
});
it("maps replay-only alias syntax to a provider-neutral module identity", async () => {
@@ -22,35 +22,7 @@ describe("runtime identification", () => {
it("identifies APK runtime families and exposes missing semantic providers", async () => {
const root = await createTestTempDirectory("rea-runtime-");
const path = join(root, "Fixture.apk");
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add(
"AndroidManifest.xml",
new Uint8ArrayReader(Uint8Array.from([3, 0, 8, 0, 8, 0, 0, 0])),
);
await writer.add(
"classes.dex",
new Uint8ArrayReader(
Uint8Array.from([...Buffer.from("dex\n035\0"), 0, 0, 0, 0]),
),
);
await writer.add(
"assets/Fixture.class",
new Uint8ArrayReader(
Uint8Array.from([0xca, 0xfe, 0xba, 0xbe, 0, 0, 0, 61]),
),
);
await writer.add(
"assets/module.wasm",
new Uint8ArrayReader(Uint8Array.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0])),
);
await writer.add("assets/main.js", new TextReader("bridge.call();"));
await writer.add(
"lib/arm64-v8a/libfixture.so",
new Uint8ArrayReader(
Uint8Array.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1, 0]),
),
);
await writeFile(path, await writer.close());
await writeApkRuntimeFixture(path);
const inventory = parseEvidence(
await runProviderAnalysis(path, "inventory_artifact", {}),
@@ -101,6 +73,28 @@ describe("runtime identification", () => {
}),
]),
);
const widened = runtimeIdentificationResultSchema.parse({
...first,
root_format: "x".repeat(101),
source_evidence_ids: Array.from(
{ length: 101 },
() => inventory.evidence_id,
),
limitations: Array.from({ length: 101 }, () => "x".repeat(4_097)),
runtimes: first.runtimes.map((runtime) => ({
...runtime,
...(runtime.provider_id === null
? { reason: "x".repeat(1_001) }
: { provider_id: `provider-${"x".repeat(200)}` }),
observations: runtime.observations.map((observation) => ({
...observation,
path: "x".repeat(4_097),
format: "x".repeat(101),
})),
})),
});
expect(widened.limitations).toHaveLength(101);
expect(widened.runtimes[0]?.observations[0]?.path).toHaveLength(4_097);
const available = first.runtimes.find(
({ inspection }) => inspection === "available",
);
@@ -165,3 +159,33 @@ describe("runtime identification", () => {
);
});
});
const writeApkRuntimeFixture = async (path: string): Promise<void> => {
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add(
"AndroidManifest.xml",
new Uint8ArrayReader(Uint8Array.from([3, 0, 8, 0, 8, 0, 0, 0])),
);
await writer.add(
"classes.dex",
new Uint8ArrayReader(
Uint8Array.from([...Buffer.from("dex\n035\0"), 0, 0, 0, 0]),
),
);
await writer.add(
"assets/Fixture.class",
new Uint8ArrayReader(
Uint8Array.from([0xca, 0xfe, 0xba, 0xbe, 0, 0, 0, 61]),
),
);
await writer.add(
"assets/module.wasm",
new Uint8ArrayReader(Uint8Array.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0])),
);
await writer.add("assets/main.js", new TextReader("bridge.call();"));
await writer.add(
"lib/arm64-v8a/libfixture.so",
new Uint8ArrayReader(Uint8Array.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1, 0])),
);
await writeFile(path, await writer.close());
};