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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user