Annotate is a macOS menu bar app (Swift 6, AppKit, SwiftPM plus a generated Xcode project). This file is for agents and contributors. Keep it short, and update the enforcer table when an enforcer lands.
swift build
swift test # full suite, about 20 seconds
swift test --filter 'AboutViewTests|RedactionTests' # one class
swift test --filter 'AboutViewTests|RedactionTests/testName' # one testKeep AboutViewTests in every filter. It runs first and sets up NSApp; without it the runner crashes in the first test's setUp because NSApp is nil (TestHelpers.recordOpenWindows()).
CI (.github/workflows/ci.yml) also builds and tests through Xcode. Annotate.xcodeproj is generated by XcodeGen and gitignored:
brew install xcodegen
xcodegen generate
xcodebuild -project Annotate.xcodeproj -scheme Annotate -configuration Debug \
-destination "platform=macOS" testNeither needs any interaction. Tests create real AppKit windows, so run them from a logged-in desktop session. SSH into a logged-in Mac should work too, but no run over SSH is on record. Xcode runs the tests inside Annotate.app, so they use your real Annotate preferences, and SettingsViewTests resets four of them. Prefer swift test locally. If xcodebuild test sits idle after Test Suite 'All tests' passed while other xcodebuild test runs share the Mac, add -enableCodeCoverage NO and a separate -derivedDataPath. This hang was seen once, with five runs at the same time, and the two flags were only tried together.
Testing Shortcuts actions end to end needs a build signed with an Apple Development certificate. In the #135 live check, an ad-hoc signed Debug build (Xcode's Sign to Run Locally) listed the actions in Shortcuts, but each one failed with "Shortcuts couldn't communicate with the app". Quit the installed Annotate first, since Shortcuts finds the app by bundle ID.
Capture Screen and Capture Area are commands (AnnotateCommand.capture) and Shortcuts actions, but never annotate:// links (runsFromLinks), so check them from Shortcuts, the menu, or the keyboard. Their actions don't go through AnnotateCommand.run, which returns before the capture finishes. They await AppDelegate.captureForShortcuts and return the PNG as an IntentFile: the saved file when it is in the default folder, otherwise a temporary file (Copy to clipboard, or a folder chosen in Settings). Shortcuts silently drops a file URL in a chosen folder, which Annotate reaches only through a security scope, even though Annotate can read it (CaptureIntentFile). Capture Area from Shortcuts opens the overlay and waits for the drag, so a live check has to drag or press Escape.
To check how a failed capture save is reported (the HUD, or the alert with Hide Tool Feedback on), launch a Debug build with --fail-capture-saves, for example open build/dd/Build/Products/Debug/Annotate.app --args --fail-capture-saves. Every save fails and the clipboard copy still works. open passes the argument only when the app isn't already running.
SwiftLint runs in CI through the SwiftLintPlugins package. With strict: true, any violation that isn't recorded in .swiftlint-baseline.json fails the run, warnings included:
swift package plugin --allow-writing-to-package-directory swiftlint # lint; also downloads the binary the next line needs
./scripts/ci/check_swiftlint_custom_rules.sh # custom rules against their fixture
swift package plugin --allow-writing-to-package-directory swiftlint lint --write-baseline .swiftlint-baseline.jsonBaseline entries match on file path plus line text, so editing or moving a baselined line makes it count as new. Fix it, or regenerate the baseline (last line above) and review the diff, since regenerating also records any new violation. When you add or change a custom rule in .swiftlint.yml, add the rule to RULES in the check script and add lines to scripts/ci/swiftlint-fixtures/AnnotateTests/CustomRulesFixture.swift, ending each line that must trigger it with // expect: <rule>.
- Never start a real Sparkle updater. Calling
startUpdater()under xctest schedules a modal alert. In #79 a test that built its own controller and started it hung CI for 6 hours. Create test controllers withstartingUpdater: falseand assert onupdater.canCheckForUpdates, asAboutViewTestsdoes.AppDelegatealso skips the start in Debug builds (#49, added for unsigned builds), which keepsAppDelegateTestsfrom starting one. - Wait through the run loop. Use
wait(for:)fromAnnotateTests/TestHelpers.swift, which runs.defaultModesoasyncAfterblocks drain. Don't block a@MainActortest on anXCTestExpectation, and don't run.common. To wait for a condition, poll with a deadline likewaitForPickerToDismiss()inOverlayWindowTests, because CI can stall one run-loop pass for seconds (4c5fbd0). - Find layers and views by name, not position. #91 inserted the dimming layer first, so a cursor test's
sublayers.firstbecame the dimming layer and the spotlight lost coverage while the test kept passing. #92 looks both layers up by name. - Never call ScreenCaptureKit. CI has no Screen Recording permission. Capture tests set
appDelegate.captureServiceto aCaptureServiceoverStubDisplayCapturingwith a temporary folder and a private pasteboard (useStubCapture()inAnnotateCommandTests). Capture action tests callcaptureFile(temporaryDirectory:)with a temporary folder instead ofperform(). - Isolate settings. Inject
TestUserDefaults.create()and callTestUserDefaults.removeSuite()when done. - Assert on pixels for drawing changes. Render the view offscreen into a bitmap and check colors (see
renderedColorinRedactionTestsandrenderedPixelCountinOverlayViewTests) instead of only checking model state.
"Planned" means a pull request is open or in progress and the enforcer is not on main yet. When it merges, move it to "Today".
| Class | Rule | Today | Planned |
|---|---|---|---|
| A. Overlay redraw and draw order | Every overlay state change triggers a redraw. A redaction covers everything created before it and sits under everything created after; selection chrome (bounding box, text box outline, drag marquee) paints last. | Tests only: paint-order and resample tests in RedactionTests, offscreen render tests in OverlayViewTests. Nothing stops a new state write that skips needsDisplay (73 manual needsDisplay = true sites, 25 in OverlayWindow.swift). |
OverlayDocument model that redraws on mutation, with draw order defined by type rather than statement order (OverlayView split). CI ratchet that caps needsDisplay = true and setNeedsDisplay( sites at 14 across Annotate/ and at 0 in OverlayWindow.swift. |
| B. Settings sync | Each setting has one key, one default, one accessor, and a README entry. | Every key is declared once in SettingsStore.swift as a SettingKey<Value> with its key string, default, and decoding. The only accessors are settings[.key] and @AppStorage(.key). CI runs scripts/ci/check_settings_access.sh, which fails outside the store, TestHelpers.swift, and SettingsStoreTests.swift on raw UserDefaults access and on any @AppStorage or @SceneStorage (including AppStorage<T>() whose key, after an optional wrappedValue:, doesn't start with .. Known limits, since it is line-based: multi-line calls, block comments, and non-literal keys passed to other UserDefaults or KVC methods. Tests inject TestUserDefaults. README is synced by hand. |
None. |
| C. Keyboard handling | Each letter shortcut matches one layer of the active layout. Customizable bindings and the fixed selection and text commands use the base layer (charactersIgnoringModifiers). Command+W, Z, Shift+Z, and R use the Command layer (event.characters, #99) so Dvorak - QWERTY ⌘ and Russian work. Don't move a shortcut between layers. |
KeyChord (KeyChord.swift) parses each event once into a base key and a Command-layer key. Matchers call ShortcutBinding.matches(_:on:ignoring:), which uses the base layer unless a caller passes .command, as OverlayWindow.keyDown does for Command+Z, Shift+Z, and R, and OverlayWindow.performKeyEquivalent for Command+W. No other code reads characters or charactersIgnoringModifiers, though no check enforces that. Covered by KeyChordTests, ShortcutBindingTests, and KeyboardLayoutShortcutTests (AZERTY, QWERTZ, Dvorak, Russian). |
None. |
| D. Weak or hanging tests | No real updater, no positional lookups, run-loop waits through the helpers. | Debug-only startingUpdater: false, CI timeout-minutes: 20, the helpers above, and review. CI runs SwiftLint with two error-level custom rules scoped to AnnotateTests/: real_updater_in_tests fails on any .startUpdater() call and positional_layer_lookup on a bare .sublayers?.first or .subviews[. scripts/ci/check_swiftlint_custom_rules.sh checks both against a fixture. Run-loop waits are still enforced by review only. |
None. |
| E. App Intents in Release | Every type in the App Intents metadata Xcode extracts survives optimization, so Shortcuts can find each action at runtime. Each action lists AppIntent in its own conformances, not only AnnotateCommandIntent or AnnotateCaptureIntent: Release drops a type whose only stated conformance is one of those, and Shortcuts fails with ActionNotFound (Debug keeps it). |
CI builds Release for arm64 and x86_64 and runs scripts/ci/check_app_intents_types.py --require-arch arm64 --require-arch x86_64. It fails on a missing slice (read from each slice's own Mach-O header) and on any mangledTypeName in extract.actionsdata whose canonical mangled name, kind included, isn't in each slice's __swift5_types section. release.yml runs it on the archive before export. scripts/ci/check_app_intents_types_test.sh checks it against probe binaries. Unit tests run Debug and can't catch this. |
None. |
When a change affects what the overlay, toolbar, quick pickers, or cursor effects draw, post before and after screenshots in the PR, cropped to the affected area (example from #73). Tests check the model; screenshots check the pixels.
-
Quit the installed Annotate. Debug builds share its bundle ID (
com.epilande.Annotate), preferences, and global shortcuts. They never start the updater. -
Build and open the base first. Run
git worktree add ../annotate-base origin/main, then in../annotate-base:xcodegen generate xcodebuild -project Annotate.xcodeproj -scheme Annotate -configuration Debug \ -destination "platform=macOS" -derivedDataPath build/dd build open build/dd/Build/Products/Debug/Annotate.app -
Set up the state to show (tool, settings, display, light or dark mode), then capture:
screencapture -x -T 3 -R 100,100,600,400 before.png # region in points, 3 s delay screencapture -i -o before.png # or pick: drag a region, or Space for a window
The terminal needs Screen Recording permission. Cursor effects stay visible during
screencapture -iand follow its crosshair, so to capture them, place the cursor and use-Rwith-T. They hide only during the system Shift+Command+4 or 5 selection (#111). -
Quit the base build. In your branch checkout, run the step 2 commands and capture again with the same state and region, saving
after.png. Run one Debug build at a time: they share preferences and global shortcuts, so with two open you can capture the wrong one. -
Add both images to the PR, labeled with the commit each came from.