From d5b2edddc47a85531f6c0c041a5bd22c66e063dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Magyar?= Date: Tue, 26 May 2026 15:40:08 +0100 Subject: [PATCH] fix(test): use retry cleanup in antigravity e2e to prevent ENOTEMPTY flake (#1838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(test): use retry cleanup in antigravity e2e to prevent ENOTEMPTY flake Replace bare `fsp.rm` / `fs.rmSync` in antigravity-hook-e2e.test.ts afterAll with `cleanupTempDir` / `cleanupTempDirSync` from test-db.ts which retry with backoff on transient filesystem errors. Also make `shouldSwallowCleanupError` swallow ENOTEMPTY on all platforms (was Windows-only). The CI failure on macOS was ENOTEMPTY on a deeply nested node-gyp cache directory inside the temp HOME — a cleanup-time race that retries usually resolve, but the final attempt must not crash the test suite if the race persists. * fix: restore fsp import needed for mkdtemp/mkdir --------- Co-authored-by: Test --- gitnexus/test/helpers/test-db.ts | 3 +++ gitnexus/test/integration/antigravity-hook-e2e.test.ts | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gitnexus/test/helpers/test-db.ts b/gitnexus/test/helpers/test-db.ts index 5be063a2c..3c845dbe0 100644 --- a/gitnexus/test/helpers/test-db.ts +++ b/gitnexus/test/helpers/test-db.ts @@ -21,6 +21,9 @@ const cleanupBackoffMs = (attempt: number): number => 100 * (attempt + 1); const shouldSwallowCleanupError = (err: unknown): boolean => { const code = (err as NodeJS.ErrnoException | undefined)?.code; + // ENOTEMPTY can race on any platform (macOS node-gyp cache, Linux + // parallel test teardown) — swallow after retries are exhausted. + if (code === 'ENOTEMPTY') return true; return process.platform === 'win32' && WINDOWS_NATIVE_LOCK_CODES.has(code ?? ''); }; diff --git a/gitnexus/test/integration/antigravity-hook-e2e.test.ts b/gitnexus/test/integration/antigravity-hook-e2e.test.ts index 5e8683471..617214c0c 100644 --- a/gitnexus/test/integration/antigravity-hook-e2e.test.ts +++ b/gitnexus/test/integration/antigravity-hook-e2e.test.ts @@ -20,6 +20,7 @@ import { spawnSync } from 'child_process'; import fs from 'fs'; import fsp from 'fs/promises'; import path from 'path'; +import { cleanupTempDir, cleanupTempDirSync } from '../helpers/test-db.js'; import os from 'os'; import { runHook, parseHookOutput } from '../utils/hook-test-helpers.js'; import { setupCommand } from '../../src/cli/setup.js'; @@ -84,8 +85,8 @@ beforeAll(async () => { afterAll(async () => { process.env.HOME = originalHome; process.env.USERPROFILE = originalUserProfile; - if (tempHome) await fsp.rm(tempHome, { recursive: true, force: true }); - if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true }); + if (tempHome) await cleanupTempDir(tempHome); + if (tmpDir) cleanupTempDirSync(tmpDir); }); describe('antigravity hook adapter e2e', () => { @@ -402,7 +403,7 @@ describe('antigravity hook adapter e2e', () => { }); afterAll(() => { - fs.rmSync(cleanupRoot, { recursive: true, force: true }); + cleanupTempDirSync(cleanupRoot); }); it('ignores AfterTool when no .gitnexus exists in cwd or any ancestor', () => {