import { describe, expect, it } from "vitest"; import { runCli } from "./cli-runner.js"; describe("runCli", () => { it("runs argv without shell interpolation", async () => { const out = await runCli(process.execPath, ["-e", "console.log(process.argv[1])", "hello&world"], 10_000); expect(out).toBe("hello&world"); }); it("reports nonzero exits as errors", async () => { const out = await runCli(process.execPath, ["-e", "console.log('bad'); process.exit(7)"], 10_000); expect(out).toContain("CLI exited 7"); }); it("pipes stdin", async () => { const out = await runCli(process.execPath, ["-e", "process.stdin.pipe(process.stdout)"], 10_000, { stdin: "hello stdin", }); expect(out).toBe("hello stdin"); }); it("blocks commands denied by inherited policy", async () => { const deniedFlag = "--" + "force"; const out = await runCli("git", ["push", "origin", "main", deniedFlag], 10_000, { policy: { deny: ["git push --" + "force"] }, }); expect(out).toContain("CLI blocked by policy"); }); });