From 07eaeb7350eec8102d5efe0b4aec175c7b77bd98 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 19:16:33 +0000 Subject: [PATCH] test(perf): reduce per-case setup in script and git-hook tests --- test/git-hooks-pre-commit.test.ts | 9 ++++-- test/scripts/ios-team-id.test.ts | 49 +++++++++++++++---------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/test/git-hooks-pre-commit.test.ts b/test/git-hooks-pre-commit.test.ts index 6e74aaa4d8a..b966bedaae8 100644 --- a/test/git-hooks-pre-commit.test.ts +++ b/test/git-hooks-pre-commit.test.ts @@ -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 }); diff --git a/test/scripts/ios-team-id.test.ts b/test/scripts/ios-team-id.test.ts index 127b1c01b94..e6f1f4de3f1 100644 --- a/test/scripts/ios-team-id.test.ts +++ b/test/scripts/ios-team-id.test.ts @@ -12,7 +12,9 @@ const BASE_PATH = process.env.PATH ?? "/usr/bin:/bin"; const BASE_LANG = process.env.LANG ?? "C"; let fixtureRoot = ""; let sharedBinDir = ""; -let caseId = 0; +let sharedHomeDir = ""; +let sharedHomeBinDir = ""; +let sharedFakePythonPath = ""; async function writeExecutable(filePath: string, body: string): Promise { await writeFile(filePath, body, "utf8"); @@ -57,6 +59,14 @@ describe("scripts/ios-team-id.sh", () => { fixtureRoot = await mkdtemp(path.join(os.tmpdir(), "openclaw-ios-team-id-")); sharedBinDir = path.join(fixtureRoot, "shared-bin"); await mkdir(sharedBinDir, { recursive: true }); + sharedHomeDir = path.join(fixtureRoot, "home"); + sharedHomeBinDir = path.join(sharedHomeDir, "bin"); + await mkdir(sharedHomeBinDir, { recursive: true }); + await mkdir(path.join(sharedHomeDir, "Library", "Preferences"), { recursive: true }); + await writeFile( + path.join(sharedHomeDir, "Library", "Preferences", "com.apple.dt.Xcode.plist"), + "", + ); await writeExecutable( path.join(sharedBinDir, "plutil"), `#!/usr/bin/env bash @@ -94,6 +104,13 @@ PLIST fi exit 1`, ); + sharedFakePythonPath = path.join(sharedHomeBinDir, "fake-python"); + await writeExecutable( + sharedFakePythonPath, + `#!/usr/bin/env bash +printf 'AAAAA11111\\t0\\tAlpha Team\\r\\n' +printf 'BBBBB22222\\t0\\tBeta Team\\r\\n'`, + ); }); afterAll(async () => { @@ -103,33 +120,15 @@ exit 1`, await rm(fixtureRoot, { recursive: true, force: true }); }); - async function createHomeDir(): Promise<{ homeDir: string; binDir: string }> { - const homeDir = path.join(fixtureRoot, `case-${caseId++}`); - await mkdir(homeDir, { recursive: true }); - const binDir = path.join(homeDir, "bin"); - await mkdir(binDir, { recursive: true }); - await mkdir(path.join(homeDir, "Library", "Preferences"), { recursive: true }); - await writeFile(path.join(homeDir, "Library", "Preferences", "com.apple.dt.Xcode.plist"), ""); - return { homeDir, binDir }; - } - it("resolves fallback and preferred team IDs from Xcode team listings", async () => { - const { homeDir, binDir } = await createHomeDir(); - await writeExecutable( - path.join(binDir, "fake-python"), - `#!/usr/bin/env bash -printf 'AAAAA11111\\t0\\tAlpha Team\\r\\n' -printf 'BBBBB22222\\t0\\tBeta Team\\r\\n'`, - ); - - const fallbackResult = runScript(homeDir, { - IOS_PYTHON_BIN: path.join(binDir, "fake-python"), + const fallbackResult = runScript(sharedHomeDir, { + IOS_PYTHON_BIN: sharedFakePythonPath, }); expect(fallbackResult.ok).toBe(true); expect(fallbackResult.stdout).toBe("AAAAA11111"); - const crlfResult = runScript(homeDir, { - IOS_PYTHON_BIN: path.join(binDir, "fake-python"), + const crlfResult = runScript(sharedHomeDir, { + IOS_PYTHON_BIN: sharedFakePythonPath, IOS_PREFERRED_TEAM_ID: "BBBBB22222", }); expect(crlfResult.ok).toBe(true); @@ -137,9 +136,7 @@ printf 'BBBBB22222\\t0\\tBeta Team\\r\\n'`, }); it("prints actionable guidance when Xcode account exists but no Team ID is resolvable", async () => { - const { homeDir } = await createHomeDir(); - - const result = runScript(homeDir); + const result = runScript(sharedHomeDir); expect(result.ok).toBe(false); expect( result.stderr.includes("An Apple account is signed in to Xcode") ||