|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { execFileSync } from "node:child_process"; |
| 3 | +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 4 | +import { tmpdir } from "node:os"; |
| 5 | +import { join } from "node:path"; |
| 6 | +import test from "node:test"; |
| 7 | + |
| 8 | +import { readReviewGit } from "../dist/pr-review-evidence.js"; |
| 9 | + |
| 10 | +test("readReviewGit keeps raw reads isolated with a Git-compatible null device", () => { |
| 11 | + const root = mkdtempSync(join(tmpdir(), "clawsweeper-review-git-")); |
| 12 | + const repo = join(root, "repo"); |
| 13 | + const malformedGlobalConfig = join(root, "malformed-global.gitconfig"); |
| 14 | + const previousGlobalConfig = process.env.GIT_CONFIG_GLOBAL; |
| 15 | + try { |
| 16 | + execFileSync("git", ["init", "-q", repo], { stdio: "pipe" }); |
| 17 | + writeFileSync(malformedGlobalConfig, "[broken\n"); |
| 18 | + process.env.GIT_CONFIG_GLOBAL = malformedGlobalConfig; |
| 19 | + |
| 20 | + const output = readReviewGit(repo, ["rev-parse", "--is-inside-work-tree"]); |
| 21 | + |
| 22 | + assert.equal(output?.toString("utf8").trim(), "true"); |
| 23 | + assert.equal(process.env.GIT_CONFIG_GLOBAL, malformedGlobalConfig); |
| 24 | + } finally { |
| 25 | + if (previousGlobalConfig === undefined) delete process.env.GIT_CONFIG_GLOBAL; |
| 26 | + else process.env.GIT_CONFIG_GLOBAL = previousGlobalConfig; |
| 27 | + rmSync(root, { recursive: true, force: true }); |
| 28 | + } |
| 29 | +}); |
0 commit comments