fix(cli): bound exec approvals stdin

This commit is contained in:
Vincent Koc
2026-06-07 04:08:13 +02:00
parent 51b64b8198
commit 801df108f0
2 changed files with 27 additions and 5 deletions

View File

@@ -1,9 +1,10 @@
// Exec approvals CLI tests cover approval command registration and output handling.
import { Readable } from "node:stream";
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
import * as execApprovals from "../infra/exec-approvals.js";
import type { ExecApprovalsFile } from "../infra/exec-approvals.js";
import { registerExecApprovalsCli } from "./exec-approvals-cli.js";
import { registerExecApprovalsCli, testing } from "./exec-approvals-cli.js";
const mocks = vi.hoisted(() => {
const runtimeErrors: string[] = [];
@@ -560,4 +561,11 @@ describe("exec approvals CLI", () => {
});
expect(runtimeErrors).toHaveLength(0);
});
it("bounds approvals JSON read from stdin", async () => {
await expect(testing.readStdin(Readable.from(["12345"]), 5)).resolves.toBe("12345");
await expect(testing.readStdin(Readable.from(["12345", "6"]), 5)).rejects.toThrow(
"Exec approvals stdin exceeds 5 bytes.",
);
});
});