Skip to content

Fix macOS F1 shortcut recorder crash#584

Merged
basnijholt merged 1 commit into
mainfrom
fix/macos-f1-shortcut-crash
Jun 5, 2026
Merged

Fix macOS F1 shortcut recorder crash#584
basnijholt merged 1 commit into
mainfrom
fix/macos-f1-shortcut-crash

Conversation

@basnijholt
Copy link
Copy Markdown
Owner

Summary

  • Replace invalid kVK_F1...kVK_F20 Carbon key-code range with explicit function-key cases.
  • Add macOS packaging regression coverage so the invalid range does not return.

Test Plan

  • swift build --package-path macos/AgentCLI
  • /tmp/agentcli-pytest-venv311/bin/python -m pytest tests/test_macos_app.py -q --no-cov

@basnijholt basnijholt merged commit 2ede226 into main Jun 5, 2026
10 checks passed
@basnijholt basnijholt deleted the fix/macos-f1-shortcut-crash branch June 5, 2026 20:30
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 5, 2026

Greptile Summary

Fixes a macOS crash in the F1 shortcut recorder by replacing the invalid Swift ClosedRange pattern kVK_F1...kVK_F20 with explicit per-key cases. Because kVK_F1 (122) is numerically greater than kVK_F20 (118), the original range expression triggered a Swift runtime trap whenever the function-key check was reached.

  • Shortcuts.swift: isFunctionRowKey now enumerates all twenty function-key constants individually, making it correct for the non-contiguous Carbon key-code layout.
  • test_macos_app.py: New regression test verifies the bad range pattern is absent and each kVK_Fxx constant is present; substring matching for kVK_F1/kVK_F2 is a minor weakness (see inline comment).

Confidence Score: 4/5

Safe to merge — the Swift change is a targeted, correct replacement of a crash-inducing invalid range with explicit key-case enumeration.

The Swift fix is unambiguously correct and the regression test adds real protection. The only gap is that the test's substring checks for kVK_F1 and kVK_F2 can pass via kVK_F10 and kVK_F20, leaving a narrow blind spot where dropping the single-digit function keys would go undetected.

tests/test_macos_app.py — the substring matching in the new test needs anchor characters to distinguish bare kVK_F1 from kVK_F10.

Important Files Changed

Filename Overview
macos/AgentCLI/Sources/AgentCLI/Shortcuts.swift Replaces the invalid Carbon range kVK_F1...kVK_F20 (which crashes at runtime because kVK_F1=122 > kVK_F20=118) with explicit per-key cases — a correct, minimal fix.
tests/test_macos_app.py Adds regression test asserting the invalid range is absent and each function key appears in the Swift source, but substring matching allows kVK_F1/kVK_F2 checks to pass via kVK_F10/kVK_F20 even if those single-digit keys are missing.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ShortcutDisplay.shortcutForDisplay] --> B{carbonModifiers has Fn mask?}
    B -- No --> C[Return shortcut as-is]
    B -- Yes --> D[shouldTreatFunctionFlagAsModifier]
    D --> E[isFunctionRowKey carbonKeyCode]
    E --> F{Explicit case match\nkVK_F1 through kVK_F20}
    F -- Matched --> G[return true]
    F -- Default --> H[return false]
    G --> I[FunctionShortcutPersistence.rawShortcut]
    H --> I
Loading

Reviews (1): Last reviewed commit: "Fix macOS F1 shortcut recorder crash" | Re-trigger Greptile

Comment thread tests/test_macos_app.py
Comment on lines +110 to +133
assert "case kVK_F1...kVK_F20:" not in shortcuts
for key in (
"kVK_F1",
"kVK_F2",
"kVK_F3",
"kVK_F4",
"kVK_F5",
"kVK_F6",
"kVK_F7",
"kVK_F8",
"kVK_F9",
"kVK_F10",
"kVK_F11",
"kVK_F12",
"kVK_F13",
"kVK_F14",
"kVK_F15",
"kVK_F16",
"kVK_F17",
"kVK_F18",
"kVK_F19",
"kVK_F20",
):
assert key in shortcuts
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The substring check "kVK_F1" in shortcuts will always pass as long as kVK_F10 (or F11–F19) is present, because "kVK_F1" is a substring of "kVK_F10". The same applies to "kVK_F2" being a substring of "kVK_F20". If a future edit accidentally drops the standalone F1 or F2 case, this test would not catch the regression.

Suggested change
assert "case kVK_F1...kVK_F20:" not in shortcuts
for key in (
"kVK_F1",
"kVK_F2",
"kVK_F3",
"kVK_F4",
"kVK_F5",
"kVK_F6",
"kVK_F7",
"kVK_F8",
"kVK_F9",
"kVK_F10",
"kVK_F11",
"kVK_F12",
"kVK_F13",
"kVK_F14",
"kVK_F15",
"kVK_F16",
"kVK_F17",
"kVK_F18",
"kVK_F19",
"kVK_F20",
):
assert key in shortcuts
assert "case kVK_F1...kVK_F20:" not in shortcuts
for key in (
"kVK_F1,",
"kVK_F2,",
"kVK_F3,",
"kVK_F4,",
"kVK_F5,",
"kVK_F6,",
"kVK_F7,",
"kVK_F8,",
"kVK_F9,",
"kVK_F10,",
"kVK_F11,",
"kVK_F12,",
"kVK_F13,",
"kVK_F14,",
"kVK_F15,",
"kVK_F16,",
"kVK_F17,",
"kVK_F18,",
"kVK_F19,",
"kVK_F20:",
):
assert key in shortcuts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant