refactor(terminal): harden shortcut docs test + fix e2e selection order

- docs test: throw on malformed entries in formatKeyLabel instead of
  emitting '?' placeholder that would silently ship a broken doc; add
  guard assertion that every entry applies to at least one platform;
  add direct test of the throw path.
- e2e copy-selection: focus the terminal BEFORE programmatic selectAll
  so the xterm helper-textarea focus event cannot collapse the selection
  before the chord is sent.
- docs: clarify regeneration instructions and mark the reserved-chords
  section as editorial (not enforced by the parity test). Rewrote the
  opening sentence so it no longer contains a literal BEGIN:MAC marker
  string that collided with the parity test's indexOf scan.
This commit is contained in:
brennanb2025 2026-04-19 23:36:25 -07:00
parent 6a61e1aea4
commit 9e8375708f
3 changed files with 29 additions and 3 deletions

View file

@ -1,6 +1,6 @@
# Terminal Shortcuts
This document is **generated from** `src/renderer/src/components/terminal-pane/terminal-shortcut-table.ts` and is enforced by `terminal-shortcut-table.docs.test.ts`. If the table changes, this file must be regenerated (run the parity test and paste in the expected output).
This document is **generated from** `src/renderer/src/components/terminal-pane/terminal-shortcut-table.ts` and is enforced by `terminal-shortcut-table.docs.test.ts`. If the table changes, this file must be regenerated: run the parity test in `terminal-shortcut-table.docs.test.ts`, then replace the rows inside the `BEGIN:MAC`/`END:MAC` and `BEGIN:NONMAC`/`END:NONMAC` HTML-comment markers below with the `expected` value from the assertion diff.
Notation:
- `Mod` = Cmd on macOS, Ctrl on Windows/Linux
@ -58,6 +58,8 @@ Shortcuts that depend on the Mac "Option as Alt" setting (Option+letter composin
## Reserved shell chords (never intercepted)
(This section is editorial and is not enforced by the parity test — it describes chords intentionally left out of the table.)
These fall through to xterm.js and the shell regardless of platform:
- `Ctrl+C` — SIGINT

View file

@ -53,7 +53,9 @@ function formatKeyLabel(entry: ShortcutEntry): string {
}
return first
}
return '?'
// Surface malformed entries at the parity test rather than corrupting the
// generated doc with a '?' placeholder that would silently pass review.
throw new Error(`ShortcutEntry '${entry.id}' has no key, keyLower, or code`)
}
function formatChord(entry: ShortcutEntry): string {
@ -126,4 +128,23 @@ describe('terminal-shortcuts.md parity with TERMINAL_SHORTCUTS', () => {
const actual = extractSection(doc, 'NONMAC')
expect(actual).toEqual(expected)
})
it('every entry applies to at least one platform', () => {
// An entry with mac=false && nonMac=false is dead code — it can never fire.
for (const e of TERMINAL_SHORTCUTS) {
expect(e.mac || e.nonMac, `ShortcutEntry '${e.id}' fires on no platform`).toBe(true)
}
})
it('formatKeyLabel throws on an entry with no key, keyLower, or code', () => {
const malformed: ShortcutEntry = {
id: 'malformed-test',
description: 'test',
mac: true,
nonMac: true,
match: { modifiers: [] },
action: { type: 'toggleSearch' }
}
expect(() => formatKeyLabel(malformed)).toThrow(/malformed-test/)
})
})

View file

@ -189,8 +189,11 @@ test.describe('Terminal Shortcuts', () => {
// Why: must run before Cmd+K clears the buffer; selectAll + Mod+Shift+C
// must route through the shortcut policy and write the selection through
// the clipboard:writeText IPC (which the spy captured).
await selectAllActiveTerminal(orcaPage)
// Why: focus must happen BEFORE selectAll — focusing the xterm helper
// textarea after a programmatic selection can collapse the selection in
// some xterm configurations, so we focus first and then select.
await focusActiveTerminal(orcaPage)
await selectAllActiveTerminal(orcaPage)
await orcaPage.keyboard.press(`${mod}+Shift+c`)
await expect
.poll(async () => (await getClipboardWrites(electronApp)).some((t) => t.includes(marker)), {