mirror of
https://github.com/stablyai/orca.git
synced 2026-10-14 16:02:57 +00:00
fix: append large workspace history safely
This commit is contained in:
@@ -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 })
|
||||
})
|
||||
})
|
||||
@@ -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'>
|
||||
|
||||
Reference in New Issue
Block a user