Files
rea/tests/boundary/filesystem/replaySourceRead.test.ts
T
morlutoandGitHub b5e98915c6 fix(tools)!: simplify direct invocation and harden boundary contracts (#555)
Remove REA permission grants, scope ceilings, approval confirmations, and inert settings. Preserve selected local evidence, accept caller-chosen commands and paths, and report actual runtime failures.

Harden provider results, schema serialization, snapshot evidence binding, archive paths, source maps, native screenshots, managed EH parsing, and cancellation cleanup. Regenerate tool metadata and document direct invocation.

BREAKING CHANGE: Removed permission configuration and policy commands, approval fields, filesystem scope inputs, and fixed confirmation options. Process capture inherits the host environment and accepts command names; callers must refresh tool schemas and migrate removed fields.
2026-10-05 20:16:44 +08:00

80 lines
2.6 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { prepareReplayPlan } from "../../../src/application/JavaScriptReplayPlanning.js";
import { controlledReplayInputSchema } from "../../../src/domain/javascriptReplay.js";
import { SystemJavaScriptReplayHost } from "../../../src/replay/SystemJavaScriptReplayHost.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
describe("replay source byte admission", () => {
it.each([0, 16, 65_537])("reads exactly %i admitted bytes", async (limit) => {
const root = await createTestTempDirectory("rea-replay-source-");
const path = join(root, "module.mjs");
const bytes = Buffer.alloc(limit, 0x61);
await writeFile(path, bytes);
expect(
await new SystemJavaScriptReplayHost().readSource(path, limit),
).toEqual({
canonicalPath: path,
bytes,
});
});
it("rejects an oversized source and a directory", async () => {
const root = await createTestTempDirectory("rea-replay-source-");
const path = join(root, "module.mjs");
await writeFile(path, "oversized");
const host = new SystemJavaScriptReplayHost();
await expect(host.readSource(path, 1)).rejects.toThrow("declared limit");
await expect(host.readSource(root, 1)).rejects.toThrow();
});
});
it("rejects a host result larger than the remaining module budget", async () => {
const path = process.execPath;
const identity = { path, version: "fixture", sha256: "1".repeat(64) };
const input = controlledReplayInputSchema.parse({
mode: "plan",
left: {
modules: [
{
alias: "entry",
path,
format: "esm",
role: "module",
dependencies: {},
},
],
entry_alias: "entry",
entry_export: "default",
},
cases: [{ case_id: "one", arguments: [] }],
limits: { module_bytes: 16 },
});
await expect(
prepareReplayPlan(
input,
{
nodePath: path,
bubblewrapPath: path,
systemdRunPath: path,
systemctlPath: path,
shellPath: path,
},
{
readSource: async (canonicalPath, maximumBytes) => ({
canonicalPath,
bytes: Buffer.alloc(maximumBytes + 1),
}),
identifyExecutable: async () => identity,
identifyWorker: async () => identity,
identifyRuntimeClosure: async () => [],
seccompDigest: () => "2".repeat(64),
probe: async () => undefined,
},
),
).rejects.toThrow("Replay module bytes exceed the aggregate limit");
});