fix: harden PTY events and configured roots
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { scanAuthorizedArtifactInventory } from "../src/application/AuthorizedArtifactInventory.js";
|
||||
|
||||
const LIMITS = {
|
||||
maxEntries: 100,
|
||||
maxTotalBytes: 1024 * 1024,
|
||||
maxEntryBytes: 1024 * 1024,
|
||||
maxCompressionRatio: 100,
|
||||
maxDepth: 10,
|
||||
maxPathBytes: 1024,
|
||||
} as const;
|
||||
|
||||
describe("authorized artifact inventory", () => {
|
||||
it("uses a valid input root when another configured root is missing", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-artifact-roots-"));
|
||||
try {
|
||||
const path = join(root, "artifact.js");
|
||||
await writeFile(path, "export const value = 1;\n");
|
||||
const inventory = await scanAuthorizedArtifactInventory(
|
||||
path,
|
||||
[join(root, "missing"), root],
|
||||
LIMITS,
|
||||
);
|
||||
expect(inventory.manifest.root_format).toBe("javascript-bundle");
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -93,6 +93,21 @@ describe("evidence bundle filesystem adapter", () => {
|
||||
).toMatchObject({ ok: true });
|
||||
});
|
||||
|
||||
it("uses valid evidence roots when another configured root is missing", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-evidence-roots-"));
|
||||
const path = join(directory, "bundle.json");
|
||||
const configured = {
|
||||
...policy(directory),
|
||||
roots: [join(directory, "missing"), directory],
|
||||
};
|
||||
expect(
|
||||
await writeEvidenceBundle(bundle(), path, false, configured),
|
||||
).toMatchObject({ ok: true });
|
||||
expect(await readEvidenceBundle(path, configured)).toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects traversal and symlink escape from approved roots", async () => {
|
||||
directory = await mkdtemp(join(tmpdir(), "rea-evidence-"));
|
||||
const root = join(directory, "approved");
|
||||
|
||||
Vendored
+7
@@ -18,6 +18,13 @@ if (mode === "interactive") {
|
||||
process.stdin.on("data", (value) => {
|
||||
process.stdout.write(`input:${value.toString()} unicode:雪\n`);
|
||||
});
|
||||
} else if (mode === "silent-interactive") {
|
||||
process.stdin.setRawMode?.(true);
|
||||
process.stdin.resume();
|
||||
process.stdin.on("data", (value) => {
|
||||
process.stdout.write(`input:${value.toString()}\n`);
|
||||
process.exit(0);
|
||||
});
|
||||
} else if (mode === "partial") {
|
||||
process.stdout.write("partial-");
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -1067,6 +1067,47 @@ describe("process capture adapter", () => {
|
||||
expect(result.value.exit.code).toBe(0);
|
||||
});
|
||||
|
||||
it("dispatches scheduled events before a silent PTY produces output", async () => {
|
||||
const capability = await probeProcessCaptureCapability();
|
||||
if (!capability.available) return;
|
||||
const result = await captureProcessScenario(
|
||||
parseProcessScenario({
|
||||
approved: true,
|
||||
executable: process.execPath,
|
||||
arguments: [processFixture, "silent-interactive"],
|
||||
working_directory: dirname(processFixture),
|
||||
events: [
|
||||
{ type: "resize", at_ms: 25, columns: 100, rows: 40 },
|
||||
{ type: "input", at_ms: 50, data: "answer" },
|
||||
],
|
||||
timeout_ms: 2_000,
|
||||
idle_timeout_ms: 2_000,
|
||||
}),
|
||||
{
|
||||
enabled: true,
|
||||
executableRoots: [
|
||||
join(dirname(process.execPath), "missing"),
|
||||
dirname(process.execPath),
|
||||
],
|
||||
workingRoots: [
|
||||
join(dirname(processFixture), "missing"),
|
||||
dirname(processFixture),
|
||||
],
|
||||
allowedEnvironment: [],
|
||||
allowExternalNetwork: true,
|
||||
},
|
||||
);
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.frames.map(({ data }) => data).join("")).toContain(
|
||||
"input:answer",
|
||||
);
|
||||
expect(result.value.interaction_events).toMatchObject([
|
||||
{ type: "resize", outcome: "dispatched" },
|
||||
{ type: "input", outcome: "dispatched" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("samples and cleans a source-owned child and grandchild process tree", async () => {
|
||||
const capability = await probeProcessCaptureCapability();
|
||||
if (!capability.available) return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { chmod, mkdtemp, stat } from "node:fs/promises";
|
||||
import { chmod, mkdtemp, stat, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
@@ -62,6 +62,17 @@ describe("project permission store", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("classifies malformed JSON as an invalid store", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-invalid-"));
|
||||
const path = join(project, "permissions.json");
|
||||
await writeFile(path, "{", { mode: 0o600 });
|
||||
|
||||
expect(await readProjectPermissionStore(path, project)).toMatchObject({
|
||||
ok: false,
|
||||
error: { reason: "invalid" },
|
||||
});
|
||||
});
|
||||
|
||||
it("serializes concurrent grant revocations without losing an update", async () => {
|
||||
const project = await mkdtemp(join(tmpdir(), "rea-policy-revoke-"));
|
||||
const path = join(project, ".rea", "permissions.json");
|
||||
|
||||
@@ -34,12 +34,16 @@ const fixture = async (parent: string, name: string): Promise<string> => {
|
||||
return root;
|
||||
};
|
||||
|
||||
const importTree = (root: string, approvedRoot: string, signal?: AbortSignal) =>
|
||||
const importTree = (
|
||||
root: string,
|
||||
approvedRoot: string | readonly string[],
|
||||
signal?: AbortSignal,
|
||||
) =>
|
||||
importReferenceSource({
|
||||
root,
|
||||
caller: "reference-import-test",
|
||||
policy: {
|
||||
roots: [approvedRoot],
|
||||
roots: typeof approvedRoot === "string" ? [approvedRoot] : approvedRoot,
|
||||
secretPatterns: [".env", ".env.*"],
|
||||
...limits,
|
||||
},
|
||||
@@ -153,6 +157,20 @@ describe("reference source import", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("uses a valid reference root when another configured root is missing", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-reference-roots-"));
|
||||
try {
|
||||
const root = await fixture(parent, "tree");
|
||||
const imported = await importTree(root, [
|
||||
join(parent, "missing"),
|
||||
parent,
|
||||
]);
|
||||
expect(imported).toMatchObject({ ok: true });
|
||||
} finally {
|
||||
await rm(parent, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("records bounded local Git state without invoking Git", async () => {
|
||||
const parent = await mkdtemp(join(tmpdir(), "rea-reference-git-"));
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user