fix: append large workspace history safely

This commit is contained in:
Neil
2026-05-30 05:15:27 -07:00
parent c45f6609f1
commit 871a9c49b3
2 changed files with 38 additions and 2 deletions
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import type { GlobalSettings, Repo } from './types'
import { buildKnownOrcaWorkspaceLayouts } from './worktree-ownership'
describe('buildKnownOrcaWorkspaceLayouts', () => {
it('handles workspace directory history larger than the JavaScript argument limit', () => {
const workspaceDirHistory = Array.from({ length: 130_000 }, (_, index) => ({
path: `/old/workspaces/${index}`,
nestWorkspaces: index % 2 === 0
}))
const settings = {
workspaceDir: '/orca/workspaces',
nestWorkspaces: true,
workspaceDirHistory
} satisfies Pick<GlobalSettings, 'workspaceDir' | 'nestWorkspaces' | 'workspaceDirHistory'>
const repo = {
path: '/repos/app'
} satisfies Pick<Repo, 'path' | 'connectionId'>
const layouts = buildKnownOrcaWorkspaceLayouts(settings, repo)
expect(layouts).toHaveLength(workspaceDirHistory.length + 1)
expect(layouts.at(-1)).toEqual({ path: '/old/workspaces/129999', nestWorkspaces: false })
})
})
+13 -2
View File
@@ -49,11 +49,11 @@ export function buildKnownOrcaWorkspaceLayouts(
const layouts: OrcaWorkspaceLayout[] = []
if (!repo?.connectionId && settings.workspaceDir) {
layouts.push({ path: settings.workspaceDir, nestWorkspaces: settings.nestWorkspaces })
layouts.push(...(settings.workspaceDirHistory ?? []))
appendWorkspaceLayouts(layouts, settings.workspaceDirHistory ?? [])
}
const wslLayouts = repo ? buildWslWorkspaceLayouts(repo.path, settings) : []
layouts.push(...wslLayouts)
appendWorkspaceLayouts(layouts, wslLayouts)
const seen = new Set<string>()
return layouts.filter((layout) => {
@@ -66,6 +66,17 @@ export function buildKnownOrcaWorkspaceLayouts(
})
}
function appendWorkspaceLayouts(
target: OrcaWorkspaceLayout[],
source: readonly OrcaWorkspaceLayout[]
): void {
// Why: persisted workspace history is unbounded; using push(...source) can
// exceed V8's argument limit before ownership classification can recover.
for (const layout of source) {
target.push(layout)
}
}
function buildWslWorkspaceLayouts(
repoPath: string,
settings: Pick<GlobalSettings, 'nestWorkspaces' | 'workspaceDirHistory'>