From e49c2f66ffecfeec31c6c494d2a85b5a77361246 Mon Sep 17 00:00:00 2001 From: Dan Shapiro <3732858+danshapiro@users.noreply.github.com> Date: Sat, 29 Aug 2026 14:15:12 -0700 Subject: [PATCH] fix(test): make build-id HEAD test run without checkout .git MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The computeBuildId test asserted against this checkout's HEAD, which is impossible on the cloud vitest/backend images: .git/ is excluded from the build context (.gcloudignore/.dockerignore), so 'git rev-parse HEAD' fails there deterministically. Build a fixture git repo in a tmpdir instead — same coverage, works everywhere a git binary exists. --- test/server/build-id.test.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/server/build-id.test.ts b/test/server/build-id.test.ts index d1a48ab00..10fe2e7c2 100644 --- a/test/server/build-id.test.ts +++ b/test/server/build-id.test.ts @@ -38,10 +38,25 @@ describe('server build id', () => { }) it('computeBuildId returns the current git HEAD sha for the repository', () => { - const expected = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: REPO_ROOT }) - .toString() - .trim() - expect(computeBuildId(REPO_ROOT)).toBe(expected) + // Build a fixture repo instead of probing this checkout: CI cloud images + // ship the source tree without .git/ (see .gcloudignore/.dockerignore), + // so asserting against REPO_ROOT's HEAD is impossible there. Only a git + // binary is required anywhere this suite runs. + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'build-id-fixture-repo-')) + try { + execFileSync('git', ['init', '-q', '-b', 'main'], { cwd: dir }) + execFileSync( + 'git', + ['-c', 'user.email=test@example.com', '-c', 'user.name=Test', 'commit', '-q', '--allow-empty', '-m', 'init'], + { cwd: dir }, + ) + const expected = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir }) + .toString() + .trim() + expect(computeBuildId(dir)).toBe(expected) + } finally { + fs.rmSync(dir, { recursive: true, force: true }) + } }) it('computeBuildId falls back to "unknown" outside a git repository', () => {