refactor(process): remove fixed scenario ceilings
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
prepareReplayPlan,
|
||||
type EnabledJavaScriptReplayPolicy,
|
||||
type JavaScriptReplayHost,
|
||||
} from "./JavaScriptReplayPlanning.js";
|
||||
import { controlledReplayInputSchema } from "../domain/javascriptReplay.js";
|
||||
|
||||
const root = "/approved";
|
||||
const policy: EnabledJavaScriptReplayPolicy = {
|
||||
status: "enabled",
|
||||
roots: [root],
|
||||
nodePath: "/runtime/node",
|
||||
bubblewrapPath: "/runtime/bwrap",
|
||||
systemdRunPath: "/runtime/systemd-run",
|
||||
systemctlPath: "/runtime/systemctl",
|
||||
shellPath: "/runtime/sh",
|
||||
};
|
||||
|
||||
const inputWithExpandedManifest = () => {
|
||||
const modules = Array.from({ length: 130 }, (_, index) => ({
|
||||
alias: `module-${index}`,
|
||||
path: `${root}/module.mjs`,
|
||||
format: "esm" as const,
|
||||
role: "module" as const,
|
||||
dependencies: {},
|
||||
}));
|
||||
const first = modules[0];
|
||||
if (first === undefined) throw new TypeError("Missing fixture module");
|
||||
modules[0] = {
|
||||
...first,
|
||||
dependencies: Object.fromEntries(
|
||||
Array.from({ length: 129 }, (_, index) => [
|
||||
`dependency-${index}`,
|
||||
`module-${index + 1}`,
|
||||
]),
|
||||
),
|
||||
};
|
||||
return controlledReplayInputSchema.parse({
|
||||
mode: "plan",
|
||||
left: {
|
||||
modules,
|
||||
entry_alias: "module-0",
|
||||
entry_export: "default",
|
||||
},
|
||||
cases: Array.from({ length: 129 }, (_, index) => ({
|
||||
case_id: `case-${index}`,
|
||||
arguments: Array.from({ length: 17 }, () => "value"),
|
||||
})),
|
||||
});
|
||||
};
|
||||
|
||||
describe("controlled replay planning input bounds", () => {
|
||||
it("accepts module, dependency, case, and argument counts beyond old quotas", () => {
|
||||
const input = inputWithExpandedManifest();
|
||||
|
||||
expect(input.left.modules).toHaveLength(130);
|
||||
expect(Object.keys(input.left.modules[0]?.dependencies ?? {})).toHaveLength(
|
||||
129,
|
||||
);
|
||||
expect(input.cases).toHaveLength(129);
|
||||
expect(input.cases[0]?.arguments).toHaveLength(17);
|
||||
});
|
||||
|
||||
it("rejects an oversized protocol manifest before probing or reading", async () => {
|
||||
const probe = vi.fn(async () => undefined);
|
||||
const readSource = vi.fn(async () => ({
|
||||
canonicalPath: `${root}/module.mjs`,
|
||||
bytes: new Uint8Array(),
|
||||
}));
|
||||
const host: JavaScriptReplayHost = {
|
||||
readSource,
|
||||
identifyExecutable: vi.fn(async (path) => ({
|
||||
path,
|
||||
version: "1",
|
||||
sha256: "0".repeat(64),
|
||||
})),
|
||||
identifyWorker: vi.fn(async () => ({
|
||||
path: "/worker.js",
|
||||
version: "1",
|
||||
sha256: "0".repeat(64),
|
||||
})),
|
||||
identifyRuntimeClosure: vi.fn(async () => []),
|
||||
seccompDigest: () => "0".repeat(64),
|
||||
probe,
|
||||
};
|
||||
const input = controlledReplayInputSchema.parse({
|
||||
mode: "plan",
|
||||
left: {
|
||||
modules: Array.from({ length: 300 }, (_, index) => ({
|
||||
alias: `module-${index}`,
|
||||
path: `/${"p".repeat(4_095)}`,
|
||||
format: "esm",
|
||||
dependencies: {},
|
||||
})),
|
||||
entry_alias: "module-0",
|
||||
},
|
||||
cases: [{ case_id: "empty", arguments: [] }],
|
||||
limits: { protocol_bytes: 1024 * 1024 },
|
||||
});
|
||||
|
||||
await expect(prepareReplayPlan(input, policy, host)).rejects.toThrow(
|
||||
"Replay plan input exceeds its protocol byte limit",
|
||||
);
|
||||
expect(probe).not.toHaveBeenCalled();
|
||||
expect(readSource).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -373,10 +373,7 @@ export const captureTerminalFrames = (options: {
|
||||
options.terminal.onData((data) => {
|
||||
options.onOutput();
|
||||
const bytes = Buffer.byteLength(data);
|
||||
if (
|
||||
options.frames.length >= options.scenario.limits.frames ||
|
||||
outputBytes + bytes > options.scenario.limits.output_bytes
|
||||
) {
|
||||
if (outputBytes + bytes > options.scenario.limits.output_bytes) {
|
||||
truncated = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,17 +30,19 @@ it("returns detached terminal and filesystem checkpoint observations", async ()
|
||||
columns: 40,
|
||||
rows: 12,
|
||||
scrollback: 100,
|
||||
maxFrames: 10,
|
||||
maxBytes: 10_000,
|
||||
maxBytes: 100_000,
|
||||
normalize: (value) => value,
|
||||
recordEvent: (collection, index) =>
|
||||
observed.push(`${collection}:${String(index)}`),
|
||||
});
|
||||
renderer.write("A", 20);
|
||||
renderer.resize(40, 12, 10);
|
||||
for (let index = 0; index < 20; index += 1)
|
||||
renderer.resize(40, 12, 11 + index);
|
||||
const frames = await renderer.frames();
|
||||
expect(frames.map(({ at_ms }) => at_ms)).toEqual([20, 10]);
|
||||
expect(observed).toEqual(["rendered_frames:0", "rendered_frames:1"]);
|
||||
expect(frames).toHaveLength(22);
|
||||
expect(frames.slice(0, 2).map(({ at_ms }) => at_ms)).toEqual([20, 10]);
|
||||
expect(observed).toHaveLength(22);
|
||||
if (frames[0] !== undefined) Reflect.set(frames[0], "cursor_x", 999);
|
||||
expect((await renderer.frames())[0]?.cursor_x).not.toBe(999);
|
||||
await renderer.dispose();
|
||||
|
||||
@@ -106,7 +106,6 @@ const createTerminalRenderer = (
|
||||
columns: scenario.terminal.columns,
|
||||
rows: scenario.terminal.rows,
|
||||
scrollback: scenario.terminal.scrollback,
|
||||
maxFrames: scenario.limits.frames,
|
||||
maxBytes: scenario.limits.output_bytes,
|
||||
normalize: (value) =>
|
||||
normalizeProcessText(value, scenario, temporaryRoot, terminalPid()),
|
||||
|
||||
@@ -35,8 +35,26 @@ export interface ProcessReactiveTimerHost {
|
||||
|
||||
const systemTimerHost: ProcessReactiveTimerHost = {
|
||||
schedule: (callback, delayMs) => {
|
||||
const timer = setTimeout(callback, delayMs);
|
||||
return { cancel: () => clearTimeout(timer) };
|
||||
const maximumTimerDelay = 2_147_483_647;
|
||||
let remaining = Math.max(0, delayMs);
|
||||
let timer: NodeJS.Timeout | undefined;
|
||||
let cancelled = false;
|
||||
const scheduleNext = (): void => {
|
||||
if (cancelled) return;
|
||||
const interval = Math.min(remaining, maximumTimerDelay);
|
||||
timer = setTimeout(() => {
|
||||
remaining -= interval;
|
||||
if (remaining === 0) callback();
|
||||
else scheduleNext();
|
||||
}, interval);
|
||||
};
|
||||
scheduleNext();
|
||||
return {
|
||||
cancel: () => {
|
||||
cancelled = true;
|
||||
if (timer !== undefined) clearTimeout(timer);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -17,14 +17,13 @@ interface TerminalRendererOptions {
|
||||
readonly columns: number;
|
||||
readonly rows: number;
|
||||
readonly scrollback: number;
|
||||
readonly maxFrames: number;
|
||||
readonly maxBytes: number;
|
||||
readonly normalize: (value: string) => string;
|
||||
readonly recordEvent?: RecordProcessCaptureEvent;
|
||||
}
|
||||
|
||||
/** Owns one headless terminal and serializes writes into deterministic frames. */
|
||||
/**
|
||||
* Owns one headless terminal and serializes writes into deterministic frames.
|
||||
* Reconstructs bounded terminal states while raw PTY chunks remain authoritative.
|
||||
*
|
||||
* Rendered frames answer what an operator saw after control-sequence handling;
|
||||
@@ -108,10 +107,7 @@ export class TerminalRenderer {
|
||||
const bytes =
|
||||
Buffer.byteLength(serializedState) +
|
||||
lines.reduce((total, line) => total + Buffer.byteLength(line), 0);
|
||||
if (
|
||||
this.#frames.length >= this.options.maxFrames ||
|
||||
this.#capturedBytes + bytes > this.options.maxBytes
|
||||
) {
|
||||
if (this.#capturedBytes + bytes > this.options.maxBytes) {
|
||||
this.#truncated = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user