test(root): clean up pre-commit temp repos

This commit is contained in:
Vincent Koc
2026-04-06 05:39:20 +01:00
parent bcf6e89e90
commit 728aee277f

View File

@@ -1,14 +1,15 @@
import { execFileSync } from "node:child_process";
import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from "node:fs";
import os from "node:os";
import { mkdirSync, symlinkSync, writeFileSync } from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { afterEach, describe, expect, it } from "vitest";
import { cleanupTempDirs, makeTempRepoRoot } from "./helpers/temp-repo.js";
const baseGitEnv = {
GIT_CONFIG_NOSYSTEM: "1",
GIT_TERMINAL_PROMPT: "0",
};
const baseRunEnv: NodeJS.ProcessEnv = { ...process.env, ...baseGitEnv };
const tempDirs: string[] = [];
const run = (cwd: string, cmd: string, args: string[] = [], env?: NodeJS.ProcessEnv) => {
return execFileSync(cmd, args, {
@@ -25,9 +26,13 @@ function writeExecutable(dir: string, name: string, contents: string): void {
});
}
afterEach(() => {
cleanupTempDirs(tempDirs);
});
describe("git-hooks/pre-commit (integration)", () => {
it("does not treat staged filenames as git-add flags (e.g. --all)", () => {
const dir = mkdtempSync(path.join(os.tmpdir(), "openclaw-pre-commit-"));
const dir = makeTempRepoRoot(tempDirs, "openclaw-pre-commit-");
run(dir, "git", ["init", "-q", "--initial-branch=main"]);
// Use the real hook script and lightweight helper stubs.
@@ -74,7 +79,7 @@ describe("git-hooks/pre-commit (integration)", () => {
});
it("skips pnpm check when FAST_COMMIT is enabled", () => {
const dir = mkdtempSync(path.join(os.tmpdir(), "openclaw-pre-commit-yolo-"));
const dir = makeTempRepoRoot(tempDirs, "openclaw-pre-commit-yolo-");
run(dir, "git", ["init", "-q", "--initial-branch=main"]);
mkdirSync(path.join(dir, "git-hooks"), { recursive: true });