refactor: return complete tool results inline
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user