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 Windows branch reconciliation containment fixtures (#10293)

[._.]/62bc8da6e1e6
diff --git a/server/services/branchReconcile.test.js b/server/services/branchReconcile.test.js
index b95f0d6dd4..50c7dd0361 100644
--- a/server/services/branchReconcile.test.js
+++ b/server/services/branchReconcile.test.js
@@ -9,6 +9,7 @@
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import { join } from 'node:path';
vi.mock('./git.js', () => ({
getBranches: vi.fn(),
@@ -75,19 +76,23 @@ vi.mock('../lib/gitRemote.js', () => ({
// SUPERSEDED verdict cache); the default `tryReadFile` returns null = no ledger,
// which is the fail-open "analyze everything" path the pre-#3842 suite assumes.
const tryReadFileMock = vi.fn(async () => null);
-vi.mock('../lib/fileUtils.js', () => ({
- // `data` added alongside `root`/`cos` because `formatInFlightForPrompt`'s
- // dispatch-hint lookup now reaches `issueNumberFromRef` from
- // `issueReconcile.js`, whose module graph (via jira.js) reads `PATHS.data`
- // at import time — an incomplete PATHS here crashed with a raw TypeError
- // rather than a test failure.
- PATHS: { root: '/repo', cos: '/repo/data/cos', data: '/repo/data', worktrees: '/repo/data/cos/worktrees' },
- safeJSONParse: (raw, fallback) => { try { return JSON.parse(raw); } catch { return fallback; } },
- isPathInsideDir: (dir, candidate) => typeof dir === 'string' && typeof candidate === 'string'
- && candidate.startsWith(`${dir}/`),
- tryReadFile: (...args) => tryReadFileMock(...args),
- atomicWrite: vi.fn(async () => {})
-}));
+vi.mock('../lib/fileUtils.js', async () => {
+ // Keep native separator, resolution and platform case-folding semantics while
+ // file I/O stays mocked. A raw startsWith(`${dir}/`) rejects Windows roots.
+ const { isPathInsideDir } = await vi.importActual('../lib/pathSafety.js');
+ return {
+ // `data` added alongside `root`/`cos` because `formatInFlightForPrompt`'s
+ // dispatch-hint lookup now reaches `issueNumberFromRef` from
+ // `issueReconcile.js`, whose module graph (via jira.js) reads `PATHS.data`
+ // at import time — an incomplete PATHS here crashed with a raw TypeError
+ // rather than a test failure.
+ PATHS: { root: '/repo', cos: '/repo/data/cos', data: '/repo/data', worktrees: '/repo/data/cos/worktrees' },
+ safeJSONParse: (raw, fallback) => { try { return JSON.parse(raw); } catch { return fallback; } },
+ isPathInsideDir,
+ tryReadFile: (...args) => tryReadFileMock(...args),
+ atomicWrite: vi.fn(async () => {})
+ };
+});
const backupSupersededBranchMock = vi.fn(async (_repoPath, branch) => ({
dir: `/repo/data/cos/abandoned-worktree-backups/${branch.branch.replace(/\//g, '-')}`,
@@ -338,15 +343,32 @@ describe('retired claim markers in reconcile', () => {
});
describe('cleanupMerged', () => {
- it('removes worktree + deletes branch when merged and clean', async () => {
+ it.each([
+ ['forward-slash fixture', '/repo/.claude/worktrees/next-2190'],
+ ['native-joined fixture', join('/repo', '.claude', 'worktrees', 'next-2190')]
+ ])('removes worktree + deletes branch when merged and clean (%s)', async (_label, worktreePath) => {
git.hasBranchMergeEvidence.mockResolvedValue(true);
execGit.mockResolvedValue({ stdout: '', exitCode: 0 }); // clean worktree
- const res = await cleanupMerged('/repo', 'main', [{ branch: 'next/issue-2190', worktreePath: '/repo/.claude/worktrees/next-2190' }]);
+ const res = await cleanupMerged('/repo', 'main', [{ branch: 'next/issue-2190', worktreePath }]);
expect(res.cleaned).toEqual(['next/issue-2190']);
- expect(wt.forceRemoveWorktreeDir).toHaveBeenCalledWith('/repo', '/repo/.claude/worktrees/next-2190', expect.any(Object));
+ expect(res.skipped).toEqual([]);
+ expect(wt.forceRemoveWorktreeDir).toHaveBeenCalledWith('/repo', worktreePath, expect.any(Object));
expect(git.deleteBranch).toHaveBeenCalledWith('/repo', 'next/issue-2190', { local: true });
});
+ it.each([
+ '/repo/.claude/worktrees-other/next-2190',
+ '/repo/.claude/worktrees/../outside/next-2190'
+ ])('holds a merged clean worktree outside the managed root (%s)', async (worktreePath) => {
+ git.hasBranchMergeEvidence.mockResolvedValue(true);
+ execGit.mockResolvedValue({ stdout: '', exitCode: 0 });
+ const res = await cleanupMerged('/repo', 'main', [{ branch: 'next/issue-2190', worktreePath }]);
+ expect(res.cleaned).toEqual([]);
+ expect(res.skipped).toEqual([{ branch: 'next/issue-2190', reason: 'worktree-unmanaged-location' }]);
+ expect(wt.forceRemoveWorktreeDir).not.toHaveBeenCalled();
+ expect(git.deleteBranch).not.toHaveBeenCalled();
+ });
+
it('does not delete the branch or report it cleaned when the worktree survives removal', async () => {
git.hasBranchMergeEvidence.mockResolvedValue(true);
execGit.mockResolvedValue({ stdout: '', exitCode: 0 }); // clean worktree