fix: keep a session cwd that is a subdirectory of the repository
pathUnderOf(base, target) answers "is target under base", so the effectiveBase guard has to be called as (canonicalTop, base). It was called as (base, canonicalTop), which asks the opposite question and always fell back to the repository toplevel — every workspace-relative path opened through the sidebar then resolved one level too high (deliverable cards reported cannot read ... ENOENT). Also adds the regression case the suite was missing: a workspace registered at a plain SUBDIRECTORY of the repository (base != top).
This commit is contained in:
1 parent
43db17f23b
commit
c03adfa628
2 files changed
+18
-1
No files matched your search
@@ -519,7 +519,7 @@ async function resolveActiveWorktreeRoot(ctx: Context, sessionId: string, base:
|
||||
return base
|
||||
}
|
||||
const canonicalTop = requireAbsolute(top)
|
||||
const effectiveBase = pathUnderOf(base, canonicalTop) ? base : canonicalTop
|
||||
const effectiveBase = pathUnderOf(canonicalTop, base) ? base : canonicalTop
|
||||
const active = await activeRootFromEvents(await sessionEventsOf(ctx, sessionId), effectiveBase)
|
||||
const root = active ?? effectiveBase
|
||||
cachePut(activeWorktreeRootCache, sessionId, { root, base, directoryEpoch, eventSeq, gitResolved: true, expires: Date.now() + ACTIVE_ROOT_TTL_MS }, ACTIVE_ROOT_CACHE_MAX)
|
||||
|
||||
@@ -162,6 +162,23 @@ describe('active worktree root', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps a session cwd that is a SUBDIRECTORY of the repository', async () => {
|
||||
// A workspace registered at `<repo>/workspace` (a plain subdirectory, not a
|
||||
// linked worktree) must stay the root: replacing it with the repository
|
||||
// toplevel makes every relative path resolve one level too high.
|
||||
const root = mkdtempSync(join(tmpdir(), 'dsh-active-root-'))
|
||||
const repo = join(root, 'repo')
|
||||
const subdir = join(repo, 'workspace')
|
||||
try {
|
||||
initRepo(repo, 'a.txt')
|
||||
mkdirSync(subdir)
|
||||
const ctx = sessionCtx(subdir, [])
|
||||
await expect(activeWorktreeRootOf(ctx, 's-subdir', subdir)).resolves.toBe(realpathSync.native(subdir))
|
||||
} finally {
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
it('probes the REAL path, never its case-folded identity (Linux is case-sensitive)', async () => {
|
||||
// `addActivePath` keys candidates by a lowercased identity; probing that
|
||||
// KEY instead of the path silently drops every candidate whose path has an
|
||||
|
||||
Reference in new issue
Block a user