test(perf): reduce per-case setup in script and git-hook tests

This commit is contained in:
Peter Steinberger
2026-03-02 19:16:33 +00:00
parent 83ec545bed
commit 07eaeb7350
2 changed files with 30 additions and 28 deletions

View File

@@ -4,18 +4,23 @@ import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
const baseGitEnv = {
GIT_CONFIG_NOSYSTEM: "1",
GIT_TERMINAL_PROMPT: "0",
};
const run = (cwd: string, cmd: string, args: string[] = [], env?: NodeJS.ProcessEnv) => {
return execFileSync(cmd, args, {
cwd,
encoding: "utf8",
env: env ? { ...process.env, ...env } : process.env,
env: { ...process.env, ...baseGitEnv, ...env },
}).trim();
};
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-"));
run(dir, "git", ["init", "-q"]);
run(dir, "git", ["init", "-q", "--initial-branch=main"]);
// Use the real hook script and lightweight helper stubs.
mkdirSync(path.join(dir, "git-hooks"), { recursive: true });