| 1 | import { execFileSync } from "node:child_process"; |
| 2 | import { expect, it } from "vitest"; |
| 3 | import { getDocsHooks } from "./i18n/dictionaries"; |
| 4 | |
| 5 | it("the documented shell gate emits an unconditional valid deny verdict in both languages", () => { |
| 6 | for (const locale of ["en", "zh"]) { |
| 7 | const section = getDocsHooks(locale).sections.find((entry) => entry.id === "gate")!; |
| 8 | const script = section.blocks.find((block) => "code" in block && block.code.startsWith("#!/bin/sh")); |
| 9 | expect(script && "code" in script).toBe(true); |
| 10 | if (!script || !("code" in script)) throw new Error("Missing hook script"); |
| 11 | for (const command of ["git push --force", "git push origin main --force", "git push --force-with-lease", "echo benign"]) { |
| 12 | const output = execFileSync("sh", ["-c", script.code], { encoding: "utf8", env: { NODE_ENV: "test", DEEPSEEK_TOOL_ARGS: JSON.stringify({ command }) } }); |
| 13 | expect(JSON.parse(output)).toEqual({ decision: "deny", reason: "Shell calls are blocked by this hook." }); |
| 14 | } |
| 15 | } |
| 16 | }); |
| 17 |