Files
orca/src/shared/keybindings-conflicts.test.ts
T
Neil 9367169888 refactor(tests): split every oversized test file off the max-lines suppression list (#14728)
* refactor(tests): split oversized test files off the max-lines suppression list

Every `*.test.ts`/`*.spec.ts` that carried an `eslint/oxlint-disable max-lines`
directive is now split into focused, behavior-scoped suites that fit the 800-line
test budget, with shared setup extracted into co-located `*-test-harness.ts` /
`*-test-fixtures.ts` modules (300-line budget). 83 files became ~930; the largest
output is 797 effective lines. `orca-runtime.test.ts` is intentionally untouched.

Test bodies were moved by scripted line-range slicing rather than retyped, so
assertions are byte-identical. The only permitted body edits were mechanical
rebinding where a shared value moved into a harness (e.g. `tmpHome` ->
`homes.tmpHome`).

Registries that enumerate test files were updated in lockstep:
- config/max-lines-baseline.txt: pruned 341 -> 258 entries (all 83 removed).
- config/reliability-gates.jsonc: 33 gates repointed at the split files, with
  assertionRefs split per file where a gate's coverage now spans several.
- .github/workflows/pr.yml: the real-zsh lane now lists the 4 split files that
  actually exercise zsh, so they keep running in the dedicated shell lane.

Also renamed agent-hooks `server-test-fixtures.ts` to `server.test-fixtures.ts`
so the global-fetch call-site audit keeps skipping it, and added `.js` extensions
to the CLI suites' dynamic harness imports (node16 resolution) to unbreak
`build:cli`.

Verification: full suite 52,449 passing vs 52,448 at baseline with zero
assertions lost; `pnpm lint`, `pnpm typecheck`, and `pnpm build:cli` all exit 0;
the terminal-pane e2e spec runs 31/31 headless.

* refactor(tests): split hook-idle arbitration suite that oxfmt pushed over budget

The pre-commit oxfmt pass reflowed pty-connection-hook-idle-arbitration.test.ts
to 811 effective lines, 11 over the test budget. Split the hook-completion side
effect and replacement-agent veto cases into their own suite; both files now sit
well under the cap and the 15 tests are unchanged.

* test: port upstream test changes into the split files after rebase

Rebasing onto main surfaced 27 tests that main had added to files this branch
deleted, plus edits to tests that had already moved. Taking the deletion side of
those modify/delete conflicts would have dropped that coverage silently, so each
upstream change is ported into the split file that now owns the behavior — for
example main's six orchestration mailbox tests land across orchestration-runs,
-send, and -check.

Also repoints `orchestration.notification-mailbox-consistency`, a gate main added
after this branch's gate remap, at those same three split files, and re-prunes
the max-lines baseline against main's (257 entries).

Verified: all 27 upstream test titles present; full suite 52,761 passing with the
only diff vs baseline being 12 tests main itself removed and 3 that moved from
skipped to passing; lint and typecheck exit 0.

* fix(test): flush pending continuations before tearing down terminal test globals

CI shard 5/16 failed on both Node 24 and 26 with `ReferenceError: window is not
defined` from pty-connection.ts, surfacing through
pty-connection-daemon-snapshot-replay.test.ts.

The reattach/settle chains `await` a real promise and then touch `window.api`.
Under fake timers those continuations cannot run, so they only become schedulable
once restoreTerminalTestGlobals() switches back to real timers — which previously
happened immediately before `delete globalThis.window`, so a late continuation
threw and failed the whole file. Flush async ticks in that window instead.

This is latent in the source rather than new: the pre-split 25k-line file kept
running other tests after these, which gave the chains time to settle before
teardown. Splitting the file moved teardown directly behind them.

* fix(test): keep an inert window after terminal test teardown instead of deleting it

The async-tick flush was not enough: the reattach/settle chain can resolve after
teardown regardless of how long we drain, so CI shard 5/16 still failed with
`ReferenceError: window is not defined` from pty-connection.ts.

A real renderer never loses `window`, so deleting it was the artificial part.
Swap in an inert proxy whose properties resolve to callables and whose calls
resolve to undefined, making a late `window.api.pty.*` call a harmless no-op.
The next test replaces it wholesale via installTerminalTestGlobals(), and no test
asserts that `window` is absent.
2026-08-15 00:54:20 -07:00

200 lines
6.4 KiB
TypeScript

// Override resolution and the conflict detector behind Settings → Shortcuts.
import { describe, expect, it } from 'vitest'
import {
agentTabActionId,
findKeybindingActionsForBinding,
findKeybindingConflicts,
getEffectiveKeybindingsForAction,
keybindingMatchesAction
} from './keybindings'
describe('keybindings', () => {
it('uses overrides as the complete effective binding list for an action', () => {
const overrides = {
'worktree.quickOpen': ['Ctrl+Alt+O', 'not-a-shortcut']
}
expect(getEffectiveKeybindingsForAction('worktree.quickOpen', 'linux', overrides)).toEqual([
'Ctrl+Alt+O'
])
expect(
keybindingMatchesAction(
'worktree.quickOpen',
{ key: 'o', code: 'KeyO', control: true, meta: false, alt: true, shift: false },
'linux',
overrides
)
).toBe(true)
expect(
keybindingMatchesAction(
'worktree.quickOpen',
{ key: 'p', code: 'KeyP', control: true, meta: false, alt: false, shift: false },
'linux',
overrides
)
).toBe(false)
})
it('reports conflicts across default and customized actions', () => {
expect(findKeybindingConflicts('linux')).toEqual([])
const conflicts = findKeybindingConflicts('linux', { 'view.tasks': ['Mod+P'] })
expect(conflicts).toContainEqual({
binding: 'Mod+P',
actionIds: expect.arrayContaining(['worktree.quickOpen', 'view.tasks'])
})
})
it('keeps zoom reset on Mod+0 and focuses worktree list on a distinct chord', () => {
// Why: both actions previously defaulted to Mod+0, so main-process zoom
// reset always won and Focus worktree list was unreachable (#8584).
for (const platform of ['darwin', 'linux', 'win32'] as const) {
expect(getEffectiveKeybindingsForAction('zoom.reset', platform)).toEqual(['Mod+0'])
expect(getEffectiveKeybindingsForAction('sidebar.focusWorktreeList', platform)).toEqual([
'Mod+Shift+0'
])
}
const zoomResetInput = {
key: '0',
code: 'Digit0',
meta: true,
control: false,
alt: false,
shift: false
}
const focusListInput = { ...zoomResetInput, shift: true }
expect(keybindingMatchesAction('zoom.reset', zoomResetInput, 'darwin')).toBe(true)
expect(keybindingMatchesAction('sidebar.focusWorktreeList', zoomResetInput, 'darwin')).toBe(
false
)
expect(keybindingMatchesAction('sidebar.focusWorktreeList', focusListInput, 'darwin')).toBe(
true
)
expect(keybindingMatchesAction('zoom.reset', focusListInput, 'darwin')).toBe(false)
expect(
findKeybindingConflicts('darwin', { 'sidebar.focusWorktreeList': ['Mod+0'] })
).toContainEqual({
binding: 'Mod+0',
actionIds: expect.arrayContaining(['zoom.reset', 'sidebar.focusWorktreeList'])
})
})
it('finds app-level owners of a prospective plugin chord with overrides', () => {
expect(findKeybindingActionsForBinding('Mod+P', 'darwin')).toContain('worktree.quickOpen')
expect(
findKeybindingActionsForBinding('Mod+Alt+T', 'linux', {
'view.tasks': ['Mod+Alt+T']
})
).toContain('view.tasks')
expect(findKeybindingActionsForBinding('Mod+F', 'darwin')).not.toContain('editor.find')
})
it('reports quick-command menu conflicts with global shortcuts and digit ranges', () => {
expect(
findKeybindingConflicts('darwin', {
'tab.openQuickCommandsMenu': ['Mod+P']
})
).toContainEqual({
binding: 'Mod+P',
actionIds: expect.arrayContaining(['worktree.quickOpen', 'tab.openQuickCommandsMenu'])
})
expect(
findKeybindingConflicts('darwin', {
'tab.openQuickCommandsMenu': ['Cmd+P']
})
).toContainEqual({
binding: 'Mod+P',
actionIds: expect.arrayContaining(['worktree.quickOpen', 'tab.openQuickCommandsMenu'])
})
expect(
findKeybindingConflicts('linux', {
'tab.openQuickCommandsMenu': ['Ctrl+P']
})
).toContainEqual({
binding: 'Mod+P',
actionIds: expect.arrayContaining(['worktree.quickOpen', 'tab.openQuickCommandsMenu'])
})
expect(
findKeybindingConflicts('darwin', {
'tab.openQuickCommandsMenu': ['Mod+3']
})
).toContainEqual({
binding: 'Mod+3',
actionIds: expect.arrayContaining(['workspace.selectByIndex', 'tab.openQuickCommandsMenu'])
})
expect(
findKeybindingConflicts('darwin', {
'tab.openQuickCommandsMenu': ['Cmd+3']
})
).toContainEqual({
binding: 'Cmd+3',
actionIds: expect.arrayContaining(['workspace.selectByIndex', 'tab.openQuickCommandsMenu'])
})
expect(
findKeybindingConflicts('linux', {
'tab.openQuickCommandsMenu': ['Ctrl+3']
})
).toContainEqual({
binding: 'Ctrl+3',
actionIds: expect.arrayContaining(['workspace.selectByIndex', 'tab.openQuickCommandsMenu'])
})
expect(
findKeybindingConflicts('linux', {
'tab.openQuickCommandsMenu': ['Alt+4']
})
).toContainEqual({
binding: 'Alt+4',
actionIds: expect.arrayContaining(['tab.selectByIndex', 'tab.openQuickCommandsMenu'])
})
})
it('flags the global send-review-notes command against editor chords it can shadow', () => {
// Why: it fires from the global capture handler even while the editor is
// focused, so Settings must warn when a user binds it over Add Review Note.
expect(
findKeybindingConflicts('darwin', { 'sourceControl.sendReviewNotes': ['Mod+Shift+A'] })
).toContainEqual(
expect.objectContaining({
binding: 'Mod+Shift+A',
actionIds: expect.arrayContaining(['editor.addReviewNote', 'sourceControl.sendReviewNotes'])
})
)
})
it('ignores selected actions when checking shortcut conflicts', () => {
expect(
findKeybindingConflicts(
'darwin',
{
'tab.newAgent.claude': ['Mod+Alt+Shift+K'],
'tab.newAgent.codex': ['Mod+Alt+Shift+K']
},
{ ignoredActionIds: [agentTabActionId('claude')] }
)
).toEqual([])
})
it('reports customized renderer conflicts with native menu accelerators', () => {
expect(findKeybindingConflicts('darwin')).toEqual([])
const conflicts = findKeybindingConflicts('darwin', {
'worktree.palette': ['Mod+Shift+E']
})
expect(conflicts).toContainEqual({
binding: 'Mod+Shift+E',
actionIds: expect.arrayContaining(['sidebar.explorer.toggle', 'worktree.palette'])
})
})
})