fix: resolve validation and artifact edge cases

This commit is contained in:
N0zoM1z0
2026-07-14 16:15:24 +08:00
parent 6a3fd5b4ce
commit ef7f2f9374
9 changed files with 138 additions and 67 deletions
+2 -2
View File
@@ -53,7 +53,7 @@ describe("artifact graph provider", () => {
machO,
);
await writeFile(join(app, "Contents", "Resources", "main.js"), "main();\n");
await writeFile(join(app, "Contents", "Resources", "main.js.map"), "{}\n");
await writeFile(join(app, "Contents", "Resources", "main.js.MAP"), "{}\n");
await symlink("/etc/passwd", join(app, "Contents", "Resources", "outside"));
const client = new ArtifactProvider().createClient(
target(app, "directory"),
@@ -88,7 +88,7 @@ describe("artifact graph provider", () => {
path.endsWith("main.js"),
);
const sourceMap = left.occurrences.items.find(({ logical_path: path }) =>
path.endsWith("main.js.map"),
path.endsWith("main.js.MAP"),
);
expect(left.edges.items).toEqual(
expect.arrayContaining([
+21
View File
@@ -239,6 +239,27 @@ describe("persistent cross-version investigation workspace", () => {
});
});
it("enforces shared JSON depth limits while reading workspaces", async () => {
const { path, input } = await fixture();
if (directory === undefined) throw new Error("missing fixture root");
const completed = await runCrossVersionInvestigation(
input,
policy(directory),
{ inputRoots: [directory] },
);
if (!completed.ok) throw completed.error;
await expect(
readInvestigationWorkspace(path, {
...policy(directory),
maxDepth: 1,
}),
).resolves.toMatchObject({
ok: false,
error: { _tag: "InvestigationWorkspaceError", reason: "too-large" },
});
});
it("resumes from a comparison checkpoint without recomputing its identity", async () => {
const { input } = await fixture();
if (directory === undefined) throw new Error("missing fixture root");
+36
View File
@@ -0,0 +1,36 @@
import { describe, expect, it } from "vitest";
import { isJsonWithinLimits } from "../src/domain/jsonLimits.js";
const limits = {
maxDepth: 3,
maxStringLength: 8,
maxNodes: 6,
};
describe("JSON limits", () => {
it("traverses nested object and array values", () => {
expect(isJsonWithinLimits({ one: ["two", { three: 3 }] }, limits)).toBe(
true,
);
expect(
isJsonWithinLimits({ one: ["two", { three: "too-long-value" }] }, limits),
).toBe(false);
});
it("enforces depth, node, and object-key limits", () => {
expect(
isJsonWithinLimits(
{ one: { two: { three: null } } },
{
...limits,
maxDepth: 2,
},
),
).toBe(false);
expect(isJsonWithinLimits([1, 2, 3], { ...limits, maxNodes: 3 })).toBe(
false,
);
expect(isJsonWithinLimits({ "too-long-key": true }, limits)).toBe(false);
});
});
+36
View File
@@ -176,6 +176,42 @@ describe("permission policy", () => {
});
});
it("reports a missing scope when revoked grants cover a different root", () => {
const ceiling = {
capability: "evidence_write" as const,
roots: ["/workspace"],
executables: [],
environment_names: [],
network: "none" as const,
mount: false,
};
const granted = grantPermission(createPermissionPolicy([ceiling]), {
...ceiling,
roots: ["/workspace/first"],
grant_id: "revoked-other-root",
lifetime: "project",
operation_identity: null,
expires_at: null,
});
expect(granted.ok).toBe(true);
if (!granted.ok) return;
expect(
evaluatePermission(
revokePermission(granted.value, "revoked-other-root"),
{
...ceiling,
roots: ["/workspace/second"],
operation_identity: "write:report.json",
},
),
).toMatchObject({
allowed: false,
reason: "grant_required",
missing: { roots: ["/workspace/second"] },
});
});
it("expires grants, removes session authority on disconnect, and never combines partial grants", () => {
const ceiling = {
capability: "process_capture" as const,