Fix macOS F1 shortcut recorder crash#584
Conversation
Greptile SummaryFixes a macOS crash in the F1 shortcut recorder by replacing the invalid Swift
Confidence Score: 4/5Safe 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
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
Reviews (1): Last reviewed commit: "Fix macOS F1 shortcut recorder crash" | Re-trigger Greptile |
| 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 |
There was a problem hiding this comment.
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.
| 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 |
Summary
kVK_F1...kVK_F20Carbon key-code range with explicit function-key cases.Test Plan
swift build --package-path macos/AgentCLI/tmp/agentcli-pytest-venv311/bin/python -m pytest tests/test_macos_app.py -q --no-cov