fix/gsd-bg-shell-stale-cwd: normalize bg-shell worktree cwd detection

This commit is contained in:
Ryan Harrington 2026-03-16 17:02:58 -04:00
parent 8b8ba0d207
commit f87b4938ca
2 changed files with 10 additions and 3 deletions

View file

@ -4,7 +4,6 @@
import { createRequire } from "node:module";
import { existsSync } from "node:fs";
import { sep } from "node:path";
// ── Windows VT Input Restoration ────────────────────────────────────────────
// Child processes (esp. Git Bash / MSYS2) can strip the ENABLE_VIRTUAL_TERMINAL_INPUT
@ -61,8 +60,7 @@ export function resolveBgShellPersistenceCwd(
liveCwd = process.cwd(),
pathExists: (path: string) => boolean = existsSync,
): string {
const worktreeMarker = `${sep}.gsd${sep}worktrees${sep}`;
const cachedIsAutoWorktree = cachedCwd.includes(worktreeMarker);
const cachedIsAutoWorktree = /(?:^|[\\/])\.gsd[\\/]worktrees[\\/]/.test(cachedCwd);
if (!cachedIsAutoWorktree) return cachedCwd;
if (cachedCwd === liveCwd && pathExists(cachedCwd)) return cachedCwd;
if (!pathExists(cachedCwd)) return liveCwd;

View file

@ -27,6 +27,15 @@ test("rewrites mismatched auto-worktree cwd to live cwd even if old path still e
);
});
test("rewrites Windows-style auto-worktree cwd to live cwd", () => {
const cached = "C:\\repo\\.gsd\\worktrees\\M001";
const live = "C:\\repo";
assert.equal(
resolveBgShellPersistenceCwd(cached, live, () => true),
live,
);
});
test("keeps current auto-worktree cwd when it still matches process cwd", () => {
const cached = "/repo/.gsd/worktrees/M001";
assert.equal(