mirror of
https://github.com/stablyai/orca.git
synced 2026-09-23 00:02:29 +00:00
#14397 split `shared/types.ts` into 46 per-domain modules but kept the path as a re-export barrel so the import sites did not have to change. This removes the barrel: every consumer now imports from the module that actually declares the type, and `src/shared/types.ts` is deleted. Barrels hide where a type lives, make every consumer look like it depends on the whole domain, and let an unrelated edit invalidate a module that ~2,000 files transitively import. 2,323 import declarations across 2,321 files. Rewritten mechanically: each specifier was resolved to an absolute path via the TypeScript AST and recomputed, rather than string-substituted, so alias forms (`@/../../shared/ types`) and per-specifier `type` modifiers survive. Four cases the mechanical pass had to handle, each found by a gate rather than by reading the diff: - Modules inside `src/shared` import the barrel as `./types`, not `shared/types`. A pre-filter on the latter string skipped 176 of them and left imports dangling at a deleted file, which surfaced as confusing `Property 'x' is optional in type 'Repo' but required in Pick<Repo, ...>` errors rather than "module not found". - The barrel RENAMED one type on the way through (`WorkspaceSource as WorkspaceCreateTelemetrySource`), so the original name in the owning module has to be re-aliased at each consumer. - Three test files put `;(globalThis as ...)` on the line after the import. TypeScript parses that `;` as the import statement's terminator, so replacing through `statement.getEnd()` deletes it and breaks ASI. The rewrite now stops at the module specifier. - A file that already imported directly from a module got a SECOND import from it, because the barrel re-exported those same names — which trips `import/no-duplicates` under `--deny-warnings`. A post-pass merges declarations sharing a specifier and type-only-ness; the `import type` plus `import` pair from one module is left alone, since that form is allowed. Splitting one barrel import into several genuinely adds lines, which pushed `terminal-layout-pty-ownership.ts` to 301 counted lines: its 107-character import must wrap, and neither local type collapses onto one line (101 and 116 characters). Rather than contort a type declaration to fit a line budget, `collectLeafIds` and `pruneLeaves` move to `terminal-pane-layout-tree.ts` — they are pure structural operations on the layout tree and independent of PTY ownership. `visible-worktrees.ts` similarly loses its own mini-barrel re-export of `isDefaultBranchWorkspace`, with the four real consumers repointed at the declaring module. No `max-lines` bypass added. Verified: cold `tsc --noEmit` green on node, cli, and web (buildinfo deleted first — these projects are `composite: true` and reuse stale caches); the full `pnpm lint` green, not just bare oxlint — the narrower local check is what let the duplicate imports reach CI; max-lines ratchet OK at 344.
243 lines
7.5 KiB
TypeScript
243 lines
7.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { GlobalSettings } from './global-settings-types'
|
|
import type { Repo } from './repo-types'
|
|
import type { DetectedWorktree, DetectedWorktreeListResult, Worktree } from './worktree/types'
|
|
import {
|
|
getHiddenExternalWorktrees,
|
|
getHiddenImportableExternalWorktrees,
|
|
getNewExternalWorktreeInboxWorktrees,
|
|
getVisibleExternalWorktrees,
|
|
getVisibleNonOrcaWorktrees,
|
|
mergeExternalWorktreeInboxPaths,
|
|
shouldOfferNewExternalWorktreeInbox
|
|
} from './external-worktree-inbox'
|
|
import {
|
|
buildKnownOrcaWorkspaceLayouts,
|
|
EXTERNAL_WORKTREE_VISIBILITY_ROLLOUT_AT,
|
|
toDetectedWorktree
|
|
} from './worktree/ownership'
|
|
|
|
const repo: Repo = {
|
|
id: 'repo-1',
|
|
path: '/repo',
|
|
displayName: 'orca',
|
|
badgeColor: '#000000',
|
|
addedAt: Date.UTC(2026, 4, 24),
|
|
externalWorktreeVisibility: 'hide',
|
|
externalWorktreeVisibilityPromptDismissedAt: 1
|
|
}
|
|
|
|
function detectedWorktree(overrides: Partial<DetectedWorktree> = {}): DetectedWorktree {
|
|
return {
|
|
id: 'repo-1::/repo-worktree',
|
|
repoId: repo.id,
|
|
path: '/repo-worktree',
|
|
displayName: 'repo-worktree',
|
|
branch: 'refs/heads/feature',
|
|
head: 'abc123',
|
|
isBare: false,
|
|
isMainWorktree: false,
|
|
comment: '',
|
|
linkedIssue: null,
|
|
linkedPR: null,
|
|
linkedLinearIssue: null,
|
|
isArchived: false,
|
|
isUnread: false,
|
|
isPinned: false,
|
|
sortOrder: 0,
|
|
lastActivityAt: 0,
|
|
ownership: 'external',
|
|
selectedCheckout: false,
|
|
visible: false,
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
function detectedResult(worktrees: DetectedWorktree[]): DetectedWorktreeListResult {
|
|
return {
|
|
repoId: repo.id,
|
|
authoritative: true,
|
|
source: 'git',
|
|
worktrees
|
|
}
|
|
}
|
|
|
|
function makeSettings(): GlobalSettings {
|
|
return {
|
|
workspaceDir: '/orca/workspaces',
|
|
nestWorkspaces: true,
|
|
workspaceDirHistory: [],
|
|
refreshLocalBaseRefOnWorktreeCreate: false,
|
|
localBaseRefSuggestionDismissed: false,
|
|
branchPrefix: 'none',
|
|
branchPrefixCustom: '',
|
|
theme: 'system',
|
|
appFontFamily: 'Geist',
|
|
editorAutoSave: false,
|
|
editorAutoSaveDelayMs: 1000,
|
|
editorMinimapEnabled: false,
|
|
markdownReviewToolsEnabled: true,
|
|
terminalFontSize: 14,
|
|
terminalFontFamily: 'monospace',
|
|
terminalFontWeight: 400,
|
|
terminalLineHeight: 1.2
|
|
} as unknown as GlobalSettings
|
|
}
|
|
|
|
function makeGitWorktree(overrides: Partial<Worktree> = {}): Worktree {
|
|
return {
|
|
id: `repo-1::${overrides.path ?? '/repo'}`,
|
|
repoId: repo.id,
|
|
path: '/repo',
|
|
displayName: 'repo',
|
|
branch: 'refs/heads/main',
|
|
head: 'abc123',
|
|
isBare: false,
|
|
isMainWorktree: true,
|
|
comment: '',
|
|
linkedIssue: null,
|
|
linkedPR: null,
|
|
linkedLinearIssue: null,
|
|
linkedGitLabMR: null,
|
|
linkedGitLabIssue: null,
|
|
isArchived: false,
|
|
isUnread: false,
|
|
isPinned: false,
|
|
sortOrder: 0,
|
|
lastActivityAt: 0,
|
|
workspaceStatus: 'todo',
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
describe('external worktree inbox', () => {
|
|
it('merges inbox paths without duplicates when paths match after normalization', () => {
|
|
expect(mergeExternalWorktreeInboxPaths(['/repo/one/'], ['/repo/one', '/repo/two'])).toEqual([
|
|
'/repo/one/',
|
|
'/repo/two'
|
|
])
|
|
})
|
|
|
|
it('offers the inbox only after the initial prompt is dismissed and discovery is not suppressed', () => {
|
|
expect(shouldOfferNewExternalWorktreeInbox(repo)).toBe(true)
|
|
expect(
|
|
shouldOfferNewExternalWorktreeInbox({
|
|
...repo,
|
|
externalWorktreeVisibilityPromptDismissedAt: undefined
|
|
})
|
|
).toBe(false)
|
|
expect(
|
|
shouldOfferNewExternalWorktreeInbox({
|
|
...repo,
|
|
externalWorktreeDiscoverySuppressedAt: 1
|
|
})
|
|
).toBe(false)
|
|
expect(
|
|
shouldOfferNewExternalWorktreeInbox({
|
|
...repo,
|
|
externalWorktreeVisibility: 'show'
|
|
})
|
|
).toBe(false)
|
|
})
|
|
|
|
it('returns only hidden external worktrees outside the inbox baseline', () => {
|
|
const hidden = detectedWorktree({ id: 'hidden', path: '/scratch/new-one' })
|
|
const baselined = detectedWorktree({ id: 'baselined', path: '/scratch/old-one' })
|
|
const detected = detectedResult([
|
|
hidden,
|
|
baselined,
|
|
detectedWorktree({ id: 'visible', visible: true }),
|
|
detectedWorktree({ id: 'orca-managed', ownership: 'orca-managed' })
|
|
])
|
|
|
|
expect(getHiddenExternalWorktrees(detected)).toEqual([hidden, baselined])
|
|
expect(
|
|
getNewExternalWorktreeInboxWorktrees(detected, {
|
|
...repo,
|
|
externalWorktreeInboxBaselinePaths: ['/scratch/old-one']
|
|
})
|
|
).toEqual([hidden])
|
|
})
|
|
|
|
it('excludes explicitly visible agent scratch from visibility-control counts', () => {
|
|
const visible = detectedWorktree({ id: 'visible', visible: true })
|
|
const scratch = detectedWorktree({
|
|
id: 'agent-scratch',
|
|
ownership: 'agent-scratch',
|
|
visible: true
|
|
})
|
|
|
|
expect(getVisibleExternalWorktrees(detectedResult([visible, scratch]))).toEqual([visible])
|
|
expect(getVisibleNonOrcaWorktrees(detectedResult([visible, scratch]))).toEqual([
|
|
visible,
|
|
scratch
|
|
])
|
|
})
|
|
|
|
it('lists hidden agent scratch among importable worktrees so recovery stays reachable', () => {
|
|
// Why: the visibility toggle can never reveal scratch (#9388), so if no list
|
|
// offers it for per-path import, a hidden scratch worktree is lost for good (#10324).
|
|
const hiddenScratch = detectedWorktree({
|
|
id: 'hidden-scratch',
|
|
path: '/repo/.claude/worktrees/scratch-1',
|
|
ownership: 'agent-scratch'
|
|
})
|
|
const hiddenExternal = detectedWorktree({ id: 'hidden-external' })
|
|
const detected = detectedResult([
|
|
hiddenScratch,
|
|
hiddenExternal,
|
|
detectedWorktree({ id: 'visible-scratch', ownership: 'agent-scratch', visible: true }),
|
|
detectedWorktree({ id: 'orca-managed', ownership: 'orca-managed' }),
|
|
detectedWorktree({ id: 'checked-out', selectedCheckout: true })
|
|
])
|
|
|
|
expect(getHiddenImportableExternalWorktrees(detected)).toEqual([hiddenScratch, hiddenExternal])
|
|
// Why: scratch stays out of discovery counts even though the dialog controls it.
|
|
expect(getHiddenExternalWorktrees(detected)).toEqual([hiddenExternal])
|
|
})
|
|
|
|
it('offers no importable worktrees from a non-authoritative snapshot', () => {
|
|
const scratch = detectedWorktree({ id: 'scratch', ownership: 'agent-scratch' })
|
|
|
|
expect(
|
|
getHiddenImportableExternalWorktrees({ ...detectedResult([scratch]), authoritative: false })
|
|
).toEqual([])
|
|
expect(getHiddenImportableExternalWorktrees(undefined)).toEqual([])
|
|
})
|
|
|
|
it('offers metadata-free nested Orca workspace worktrees through the inbox', () => {
|
|
const settings = makeSettings()
|
|
const manual = toDetectedWorktree({
|
|
repo,
|
|
settings,
|
|
worktree: makeGitWorktree({
|
|
path: '/orca/workspaces/orca/manual-from-git',
|
|
displayName: 'manual-from-git',
|
|
branch: 'refs/heads/manual-from-git',
|
|
isMainWorktree: false
|
|
}),
|
|
knownOrcaLayouts: buildKnownOrcaWorkspaceLayouts(settings, repo)
|
|
})
|
|
|
|
expect(manual.ownership).toBe('external')
|
|
expect(manual.visible).toBe(false)
|
|
expect(getNewExternalWorktreeInboxWorktrees(detectedResult([manual]), repo)).toEqual([manual])
|
|
})
|
|
|
|
it('suppresses non-authoritative detected results', () => {
|
|
expect(
|
|
getNewExternalWorktreeInboxWorktrees(detectedResult([detectedWorktree()]), {
|
|
...repo,
|
|
addedAt: EXTERNAL_WORKTREE_VISIBILITY_ROLLOUT_AT + 1
|
|
})
|
|
).toEqual([detectedWorktree()])
|
|
expect(
|
|
getNewExternalWorktreeInboxWorktrees(
|
|
{ ...detectedResult([detectedWorktree()]), authoritative: false },
|
|
repo
|
|
)
|
|
).toEqual([])
|
|
})
|
|
})
|