refactor: return complete tool results inline
This commit is contained in:
@@ -42,11 +42,7 @@ describe("Android application projection", () => {
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {
|
||||
node_limit: 500,
|
||||
occurrence_limit: 500,
|
||||
edge_limit: 500,
|
||||
}),
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const first = projectAndroidApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
|
||||
@@ -49,11 +49,7 @@ describe("Apple application projection", () => {
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {
|
||||
node_limit: 500,
|
||||
occurrence_limit: 500,
|
||||
edge_limit: 500,
|
||||
}),
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const first = projectAppleApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
|
||||
@@ -14,8 +14,6 @@ const nonHopperProvider = (operations: string[]): AnalysisProvider => {
|
||||
{
|
||||
provider: { id: "fixture", name: "Fixture", version: "1" },
|
||||
operation: "address_name",
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: true,
|
||||
reason: null,
|
||||
pagination: "none",
|
||||
@@ -134,7 +132,6 @@ describe("binary session", () => {
|
||||
observation: {
|
||||
status: "verified",
|
||||
observed_at: "2026-07-22T10:00:00.000Z",
|
||||
schema_version: 1,
|
||||
launcher_pid: 100,
|
||||
launcher_parent_pid: 1,
|
||||
process_group_id: 100,
|
||||
|
||||
-1
@@ -89,7 +89,6 @@ describe("binary session", () => {
|
||||
name: identity.name,
|
||||
version: identity.version ?? "fixture-unresolved",
|
||||
},
|
||||
1,
|
||||
{ fixture: "different-profile" },
|
||||
),
|
||||
compatibility: {},
|
||||
|
||||
+2
-1
@@ -34,7 +34,8 @@ describe("binary session", () => {
|
||||
expect.objectContaining({
|
||||
operation: "address_name",
|
||||
available: false,
|
||||
reason: "Provider became unavailable during this session.",
|
||||
reason:
|
||||
"ProviderAdapterError: Provider fixture adapter failed during address_name",
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
-2
@@ -28,8 +28,6 @@ describe("binary session", () => {
|
||||
{
|
||||
provider: { id: "partial", name: "Partial", version: "1" },
|
||||
operation: "address_name",
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: false,
|
||||
reason: "fixture intentionally omits symbol lookup",
|
||||
pagination: "none",
|
||||
|
||||
@@ -200,8 +200,6 @@ const capability = (
|
||||
): CapabilityDescriptor => ({
|
||||
provider: providerIdentity,
|
||||
operation,
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: true,
|
||||
reason: null,
|
||||
pagination: "none",
|
||||
|
||||
@@ -45,10 +45,9 @@ describe("cross-version inventory", () => {
|
||||
const calls: string[] = [];
|
||||
const controller = new AbortController();
|
||||
const scanner: VersionInventoryScanner = (...arguments_) => {
|
||||
const [path, roots, limits, options] = arguments_;
|
||||
const [path, limits, options] = arguments_;
|
||||
if (options === undefined) throw new Error("Expected scanner options");
|
||||
calls.push(path);
|
||||
expect(roots).toEqual([root]);
|
||||
expect(limits).toBe(LIMITS);
|
||||
expect(options.signal).toBe(controller.signal);
|
||||
expect(options.integrity).toBe(INTEGRITY);
|
||||
@@ -59,7 +58,6 @@ describe("cross-version inventory", () => {
|
||||
{
|
||||
leftPath: "left",
|
||||
rightPath: "right",
|
||||
inputRoots: [root],
|
||||
limits: LIMITS,
|
||||
signal: controller.signal,
|
||||
integrity: INTEGRITY,
|
||||
@@ -87,7 +85,6 @@ describe("cross-version inventory", () => {
|
||||
{
|
||||
leftPath: "left",
|
||||
rightPath: "right",
|
||||
inputRoots: ["/approved"],
|
||||
limits: LIMITS,
|
||||
integrity: INTEGRITY,
|
||||
},
|
||||
|
||||
@@ -71,13 +71,6 @@ describe("managed application graph projection", () => {
|
||||
managed_artifact: artifactEvidence,
|
||||
managed_members: memberEvidence,
|
||||
managed_native_boundaries: boundaryEvidence,
|
||||
limits: {
|
||||
max_types: 100,
|
||||
max_methods: 100,
|
||||
max_fields: 100,
|
||||
max_pinvoke_imports: 100,
|
||||
max_native_implementations: 100,
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
@@ -154,15 +147,10 @@ describe("managed application graph projection", () => {
|
||||
case_sensitive: true,
|
||||
},
|
||||
direction: "incoming",
|
||||
limits: {
|
||||
max_seed_matches: 5,
|
||||
max_depth: 4,
|
||||
max_nodes: 50,
|
||||
max_edges: 100,
|
||||
max_paths: 10,
|
||||
},
|
||||
});
|
||||
expect(trace.ok).toBe(true);
|
||||
expect(trace.ok, trace.ok ? undefined : JSON.stringify(trace.error)).toBe(
|
||||
true,
|
||||
);
|
||||
if (!trace.ok) throw new Error("trace failed");
|
||||
expect(trace.value.normalized_result).toMatchObject({
|
||||
source_evidence_id: parsed.evidence_id,
|
||||
@@ -172,7 +160,7 @@ describe("managed application graph projection", () => {
|
||||
});
|
||||
|
||||
describe("managed application graph coverage", () => {
|
||||
it("preserves source-page omissions in graph and per-fact coverage", () => {
|
||||
it("preserves partial parser coverage in graph and per-fact coverage", () => {
|
||||
const bytes = buildManagedPeFixture();
|
||||
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
|
||||
const members = inspectManagedMembersBytes(
|
||||
@@ -180,76 +168,8 @@ describe("managed application graph coverage", () => {
|
||||
binary,
|
||||
MANAGED_MEMBER_FIXTURE_LIMITS,
|
||||
);
|
||||
const partialMembers = {
|
||||
...members,
|
||||
methods: {
|
||||
...members.methods,
|
||||
total: 2,
|
||||
returned: 1,
|
||||
dropped: 1,
|
||||
complete: false,
|
||||
},
|
||||
};
|
||||
const memberEvidence = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: partialMembers,
|
||||
rawResult: null,
|
||||
limitations: partialMembers.limitations,
|
||||
locations: [{ kind: "artifact-path", path: binary.path }],
|
||||
});
|
||||
|
||||
const evidence = projectManagedApplicationGraphEvidence({
|
||||
managed_members: memberEvidence,
|
||||
limits: {
|
||||
max_types: 100,
|
||||
max_methods: 100,
|
||||
max_fields: 100,
|
||||
max_pinvoke_imports: 100,
|
||||
max_native_implementations: 100,
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
evidence.ok,
|
||||
evidence.ok
|
||||
? undefined
|
||||
: `${JSON.stringify(evidence.error)} cause=${String(evidence.error.cause)}`,
|
||||
).toBe(true);
|
||||
if (!evidence.ok) throw new Error("projection failed");
|
||||
const result = managedApplicationGraphResultSchema.parse(
|
||||
parseEvidence(evidence.value).normalized_result,
|
||||
);
|
||||
const graph = parseJavaScriptApplicationGraph(result.graph);
|
||||
expect(result.coverage).toMatchObject({
|
||||
status: "truncated",
|
||||
omitted_types: 0,
|
||||
omitted_methods: 1,
|
||||
omitted_fields: 0,
|
||||
});
|
||||
expect(graph.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
truncated: true,
|
||||
omitted_count: 1,
|
||||
});
|
||||
const method = graph.nodes.find(({ kind }) => kind === "managed-method");
|
||||
expect(method?.observations[0]?.evidence.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
truncated: true,
|
||||
omitted_count: 1,
|
||||
});
|
||||
expect(
|
||||
graph.edges.find(
|
||||
({ target_node_id }) => target_node_id === method?.node_id,
|
||||
)?.evidence.coverage,
|
||||
).toMatchObject({
|
||||
status: "partial",
|
||||
truncated: true,
|
||||
omitted_count: 1,
|
||||
});
|
||||
|
||||
const parserPartialMembers = {
|
||||
...partialMembers,
|
||||
...members,
|
||||
coverage: {
|
||||
state: "partial" as const,
|
||||
issues: [
|
||||
@@ -275,13 +195,6 @@ describe("managed application graph coverage", () => {
|
||||
);
|
||||
const parserPartialProjection = projectManagedApplicationGraphEvidence({
|
||||
managed_members: parserPartialEvidence,
|
||||
limits: {
|
||||
max_types: 100,
|
||||
max_methods: 100,
|
||||
max_fields: 100,
|
||||
max_pinvoke_imports: 100,
|
||||
max_native_implementations: 100,
|
||||
},
|
||||
});
|
||||
|
||||
expect(parserPartialProjection.ok).toBe(true);
|
||||
@@ -292,7 +205,6 @@ describe("managed application graph coverage", () => {
|
||||
);
|
||||
expect(parserPartialResult.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
omitted_methods: 1,
|
||||
});
|
||||
expect(parserPartialResult.graph.coverage).toEqual({
|
||||
status: "partial",
|
||||
|
||||
@@ -219,7 +219,6 @@ const deepProvider = (id: string): DeepProviderFixture => {
|
||||
ok({
|
||||
profile: createAnalysisProfile(
|
||||
{ id, name: identity.name, version: "1" },
|
||||
1,
|
||||
{ provider: id },
|
||||
),
|
||||
compatibility: {},
|
||||
@@ -295,8 +294,6 @@ const capability = (
|
||||
): CapabilityDescriptor => ({
|
||||
provider,
|
||||
operation,
|
||||
inputContractVersion: 1,
|
||||
outputContractVersion: 1,
|
||||
available: true,
|
||||
reason: null,
|
||||
pagination: "none",
|
||||
|
||||
@@ -1,49 +1,41 @@
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { PermissionAuthority } from "../../../src/application/PermissionAuthority.js";
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { parseJavaScriptApplicationGraph } from "../../../src/domain/javascriptApplicationGraph.js";
|
||||
import { analyzeJavaScriptApplicationInputSchema } from "../../../src/domain/javascriptApplicationAnalysis.js";
|
||||
import { createPermissionPolicy } from "../../../src/domain/permissionPolicy.js";
|
||||
import { writeElectronBoundaryFixture } from "../../fixtures/electronBoundaryApplication.js";
|
||||
|
||||
describe("static Electron application analysis", () => {
|
||||
it("requires explicit approval, an absolute path, and graph-safe combined bounds", () => {
|
||||
it("accepts a caller path and caller-selected analysis bounds", () => {
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.safeParse({
|
||||
input_path: "relative/app.asar",
|
||||
approved: true,
|
||||
}).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.safeParse({
|
||||
input_path: "/tmp/app.asar",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
).toBe(true);
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.safeParse({
|
||||
input_path: "/tmp/app.asar",
|
||||
approved: true,
|
||||
limits: {
|
||||
max_entries: 100_000,
|
||||
max_findings: 200_000,
|
||||
},
|
||||
}).success,
|
||||
).toBe(false);
|
||||
).toBe(true);
|
||||
expect(
|
||||
analyzeJavaScriptApplicationInputSchema.parse({
|
||||
input_path: "/tmp/app.asar",
|
||||
approved: true,
|
||||
}),
|
||||
).toMatchObject({
|
||||
format: "auto",
|
||||
source_map_read_approved: false,
|
||||
limits: { max_findings: 8_000 },
|
||||
});
|
||||
});
|
||||
@@ -65,42 +57,27 @@ describe("static Electron application analysis", () => {
|
||||
expectElectronBoundaries(graph);
|
||||
});
|
||||
|
||||
it("returns Evidence v2 only after exact investigation-input authorization", async () => {
|
||||
it("analyzes the selected local application directory directly", async () => {
|
||||
const root = await fixtureDirectory();
|
||||
const authority = permissionAuthority(root);
|
||||
|
||||
const result = await analyzeJavaScriptApplication(authority, {
|
||||
const result = await analyzeJavaScriptApplication({
|
||||
input_path: root,
|
||||
approved: true,
|
||||
});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
const evidence = parseEvidence(result.value);
|
||||
expect(evidence).toMatchObject({
|
||||
operation: "analyze_javascript_application",
|
||||
predicate_type: "rea.javascript-application-analysis/v2",
|
||||
predicate_type: "rea.javascript-application-analysis",
|
||||
provider: { id: "rea-javascript-application" },
|
||||
authority: "shipped-artifact",
|
||||
confidence: "derived",
|
||||
subject: { local_path: root, format: "directory" },
|
||||
normalized_result: {
|
||||
schema_version: 2,
|
||||
input_path: root,
|
||||
summary: { browser_windows: 3 },
|
||||
},
|
||||
});
|
||||
|
||||
const denied = await analyzeJavaScriptApplication(
|
||||
permissionAuthority(root),
|
||||
{
|
||||
input_path: join(root, ".."),
|
||||
approved: true,
|
||||
},
|
||||
);
|
||||
expect(denied).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "PermissionRequiredError" },
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a tagged cancellation without executing application code", async () => {
|
||||
@@ -110,8 +87,7 @@ describe("static Electron application analysis", () => {
|
||||
Reflect.deleteProperty(globalThis, "__rea_electron_fixture_executed");
|
||||
|
||||
const result = await analyzeJavaScriptApplication(
|
||||
permissionAuthority(root),
|
||||
{ input_path: root, approved: true },
|
||||
{ input_path: root },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
|
||||
@@ -313,28 +289,3 @@ const fixtureDirectory = async (): Promise<string> => {
|
||||
await writeElectronBoundaryFixture(root);
|
||||
return root;
|
||||
};
|
||||
|
||||
const permissionAuthority = (root: string): PermissionAuthority =>
|
||||
new PermissionAuthority(
|
||||
createPermissionPolicy(
|
||||
[scope(root)],
|
||||
[
|
||||
{
|
||||
...scope(root),
|
||||
grant_id: "test:investigation-input",
|
||||
lifetime: "session",
|
||||
operation_identity: null,
|
||||
expires_at: null,
|
||||
},
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
const scope = (root: string) => ({
|
||||
capability: "investigation_input" as const,
|
||||
roots: [root],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
network: "none" as const,
|
||||
mount: false,
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import { scanArtifactInventory } from "../../../src/application/ArtifactInventory.js";
|
||||
import { parseJavaScriptApplicationGraph } from "../../../src/domain/javascriptApplicationGraph.js";
|
||||
import { javaScriptApplicationAnalysisResultV2Schema } from "../../../src/domain/javascriptApplicationAnalysis.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascriptApplicationAnalysis.js";
|
||||
import { createJavaScriptSemanticGraph } from "../../../src/domain/javascriptSemanticGraph.js";
|
||||
import { parseJavaScriptSemanticGraph } from "../../../src/domain/javascriptSemanticGraphSerialization.js";
|
||||
import { writeJavaScriptArtifactFixture } from "../../fixtures/javascriptArtifactApplication.js";
|
||||
@@ -20,7 +20,6 @@ it("reconstructs package, Electron roles, Webpack/Rspack modules, and cross-laye
|
||||
|
||||
const result = await reconstructJavaScriptArtifact({
|
||||
input_path: root,
|
||||
source_map_read_approved: true,
|
||||
});
|
||||
const graph = parseJavaScriptApplicationGraph(result.graph);
|
||||
const semanticGraph = parseJavaScriptSemanticGraph(result.semantic_graph);
|
||||
@@ -31,7 +30,6 @@ it("reconstructs package, Electron roles, Webpack/Rspack modules, and cross-laye
|
||||
modules: 4,
|
||||
parse_failures: 0,
|
||||
omitted_text_files: 0,
|
||||
policy_filtered_text_files: 0,
|
||||
});
|
||||
expect(graph.nodes.map(({ kind }) => kind)).toEqual(
|
||||
expect.arrayContaining([
|
||||
@@ -111,12 +109,10 @@ it("produces deterministic ASAR graphs with unpacked native linkage and complete
|
||||
const first = await reconstructJavaScriptArtifact({
|
||||
input_path: archive,
|
||||
format: "asar",
|
||||
source_map_read_approved: true,
|
||||
});
|
||||
const second = await reconstructJavaScriptArtifact({
|
||||
input_path: archive,
|
||||
format: "asar",
|
||||
source_map_read_approved: true,
|
||||
});
|
||||
|
||||
expect(first.graph).toEqual(second.graph);
|
||||
@@ -191,7 +187,6 @@ it("keeps ASAR analysis usable when unpacked native companion bytes are absent",
|
||||
const result = await reconstructJavaScriptArtifact({
|
||||
input_path: archive,
|
||||
format: "asar",
|
||||
source_map_read_approved: true,
|
||||
});
|
||||
|
||||
expect(result.statistics.parsed_javascript_files).toBeGreaterThan(0);
|
||||
@@ -214,7 +209,6 @@ it("recurses into filesystem-backed ASAR containers without losing container-rel
|
||||
|
||||
const result = await reconstructJavaScriptArtifact({
|
||||
input_path: outer,
|
||||
source_map_read_approved: true,
|
||||
});
|
||||
|
||||
expect(result.statistics.nested_asar_containers).toBe(1);
|
||||
@@ -257,9 +251,8 @@ const assertSemanticLinks = (
|
||||
});
|
||||
const { electron_summary: summary, ...analysisResult } = result;
|
||||
expect(() =>
|
||||
javaScriptApplicationAnalysisResultV2Schema.parse({
|
||||
javascriptApplicationAnalysisResultSchema.parse({
|
||||
...analysisResult,
|
||||
schema_version: 2,
|
||||
summary,
|
||||
semantic_graph: mismatchedSemanticGraph,
|
||||
}),
|
||||
|
||||
@@ -13,7 +13,6 @@ import { javascriptRuntimeReconciliationResultSchema } from "../../../src/domain
|
||||
import { electronActiveObservationInputSchema } from "../../../src/domain/electronActiveObservation.js";
|
||||
import { inspectElectronPageInputSchema } from "../../../src/domain/electronObservation.js";
|
||||
import { createWebTextArtifact } from "../../../src/domain/webContentArtifact.js";
|
||||
import { permissionAuthorityForRoot } from "../../fixtures/permissionAuthority.js";
|
||||
import { createElectronActiveObservationFixtureResult } from "../../../src/domain/electronActiveObservation.fixture.js";
|
||||
|
||||
const SOURCE = `const worker = new Worker("./worker.js");\nexport const observed = worker;\n`;
|
||||
@@ -165,7 +164,7 @@ it("keeps source-map declarations outside primary matching authority", async ()
|
||||
|
||||
expect(result.source_map_authority).toMatchObject({
|
||||
used_for_primary_matching: false,
|
||||
static_layers_with_read_approval: 0,
|
||||
static_layer_count: 1,
|
||||
runtime_script_declarations: 0,
|
||||
});
|
||||
});
|
||||
@@ -175,7 +174,6 @@ it("reconciles active Electron as a partial target-only runtime capture", async
|
||||
const staticEvidence = await analyzeFixture(fixture);
|
||||
const applicationPath = join(fixture, "main.js");
|
||||
const input = electronActiveObservationInputSchema.parse({
|
||||
schema_version: 1,
|
||||
executable_path: process.execPath,
|
||||
application_path: applicationPath,
|
||||
application_root: fixture,
|
||||
@@ -217,7 +215,6 @@ it("hashes the retained Electron scenario projection, not raw selectors or secre
|
||||
const applicationPath = join(fixture, "main.js");
|
||||
const makeInput = (secret: string, selector: string) =>
|
||||
electronActiveObservationInputSchema.parse({
|
||||
schema_version: 1,
|
||||
executable_path: process.execPath,
|
||||
application_path: applicationPath,
|
||||
application_root: fixture,
|
||||
@@ -331,14 +328,8 @@ const applicationFixture = async (): Promise<string> => {
|
||||
};
|
||||
|
||||
const analyzeFixture = async (root: string) => {
|
||||
const authority = await permissionAuthorityForRoot(
|
||||
root,
|
||||
["investigation_input"],
|
||||
["investigation_input"],
|
||||
);
|
||||
const result = await analyzeJavaScriptApplication(authority, {
|
||||
const result = await analyzeJavaScriptApplication({
|
||||
input_path: root,
|
||||
approved: true,
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
return result.value;
|
||||
@@ -381,7 +372,6 @@ const electronRuntimeEvidence = (
|
||||
"inspect_electron_page",
|
||||
input,
|
||||
{
|
||||
schema_version: 1,
|
||||
browser: {
|
||||
product: "Electron/fixture",
|
||||
protocol_version: "1.3",
|
||||
|
||||
Reference in New Issue
Block a user