Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: fix ~3% flake in resetGitWorktreeSandbox worktree-listing assertion (#6059)

Bryandero982f0895db74ef
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);
});