From 2f0895db74efb38136956ddf0f0fccea4ec1c892 Mon Sep 17 00:00:00 2001 From: Bryandero98 Date: Thu, 3 Sep 2026 13:26:57 -0500 Subject: [PATCH] test: fix ~3% flake in resetGitWorktreeSandbox worktree-listing assertion (#6059) The test asserted `.not.toContain('wt-a'/'wt-b')` against the raw `git worktree list --porcelain` output, which always includes the parent sandbox's own entry. When that entry's random mkdtemp() suffix happens to start with 'a' or 'b', the substring can coincidentally appear inside the parent's own path and the assertion false-fails (~3.2% chance per prefix). Replaced it with a parse of the porcelain output into worktree entries (mirroring the parsing resetGitWorktreeSandbox itself already does in gitTestRepo.js, which drops the first entry as always being the parent) and assert exactly 1 entry remains. This avoids the collision and also sidesteps comparing full paths directly, which git can respell on Windows (see the assertPath test in this same file, #6003). Verified by forcing the exact collision deterministically (parent sandbox created at a path ending in `wt-b-XXXXXX`): confirmed the old assertion fails in that case and the new one does not. Co-Authored-By: Claude Sonnet 5 --- server/lib/gitTestRepo.test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/lib/gitTestRepo.test.js b/server/lib/gitTestRepo.test.js index f60d0fb91c..0597d9d5e5 100644 --- a/server/lib/gitTestRepo.test.js +++ b/server/lib/gitTestRepo.test.js @@ -182,9 +182,15 @@ describe('resetGitWorktreeSandbox', () => { await resetGitWorktreeSandbox(dest, initialHead); + // Parse porcelain into worktree entries and assert only `dest` itself + // remains, rather than substring-matching 'wt-a'/'wt-b' against the raw + // listing — that substring can coincidentally appear inside dest's own + // random mkdtemp() suffix (~3.2% chance per prefix) and false-fail (#6059). + // Counting entries also sidesteps comparing absolute paths directly, + // which git can respell on Windows (see the assertPath test above, #6003). const listing = (await execGit(['worktree', 'list', '--porcelain'], dest)).stdout; - expect(listing).not.toContain('wt-a'); - expect(listing).not.toContain('wt-b'); + const worktreeEntries = listing.split(/\r?\n/).filter((line) => line.startsWith('worktree ')); + expect(worktreeEntries).toHaveLength(1); expect((await execGit(['branch', '--format=%(refname:short)'], dest)).stdout.trim()).toBe('main'); expect((await execGit(['rev-parse', 'HEAD'], dest)).stdout.trim()).toBe(initialHead); });