Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 9.39 KB

TESTING.md

File metadata and controls

38 lines (31 loc) · 9.39 KB

Testing, security and release gate

Goal: no feature ships unless unit, integration, UI/usability and security checks pass, locally and in CI. Real Bluetooth with the Pixel cannot run in CI; it is covered by a manual hardware checklist.

Why not Playwright

Playwright automates browsers, Electron and web views. Pickup is a native AppKit/SwiftUI menu bar app, so Playwright cannot see its windows. XCUITest would be the Apple way, but it needs an Xcode UI-test bundle and runner and fails under swift test ("Device is not configured for UI testing"). We therefore drive the app through the macOS Accessibility API (AXUIElement and CGEvent) from a plain XCTest package (App/Tests/PickupUITests), plus in-process tests.

Test pyramid

  1. Unit (XCTest, swift test) – pure logic with no hardware: PickupCore (AT parser, CallEngine, DialNumber, redaction, sanitizer, reconnect controller), PickupBluetooth with fake links, App pure types (contact search, keypad rules, key combos, number format). Already about 230 tests; every bug fix adds a regression test.
  2. Scenario tests (XCTest) – a scripted phone (ScriptedPhoneTransport/fake transport) plays complete calls through CallEngine and the app model: incoming → accept / decline / missed, outgoing → remote answers / cancel, hang up during dialing, call waiting, link loss and call resume, sleep/wake, SCO opened unexpectedly. Replays of real Pixel logs (Fixtures/) stay.
  3. Property and fuzz tests – seeded randomised tests for everything that parses untrusted input: AT lines from the phone, tel:/callto: URLs, pasted text, DialNumber, ATLogSanitizer, PhoneNumberRedaction; random event sequences into CallEngine must never crash, never leave a call stuck, never dial without a command. Failing seeds are printed and added as fixtures.
  4. UI and usability tests (Accessibility API harness, scripts/run-ui-tests.sh) – the real Pickup.app launched with -PickupTestScenario <name>, which swaps AppleHFPTransport for the scripted phone and contacts for invented ones (no Bluetooth, no real contacts, no real calls). Checks: popover opens from the status item and the global shortcut; search → ↑/↓ → Return dials the right row; digits typed open the keypad and light the key; + long press; Esc semantics; ⌘, ⌘Q ⌘W; banner shows caller, Accept/Decline work, banner never takes keyboard focus; HUD timer, hang-up, ended state; the call-UI stress cycle (the stack-overflow regression); Settings opens in front and stays compact. Accessibility checks (labels, roles, identifiers and values present; performAccessibilityAudit is not available outside XCUITest), full keyboard operation, VoiceOver labels, Reduce Motion, light/dark, and English and German (no truncated or overlapping text). Screenshot snapshots of key views in both languages and appearances catch visual regressions.
  5. Hardware checklist (manual, maintainer) – a short smoke script for reconnect, sleep/wake, real call with the Pixel. Not part of the automated gate.

Security

Threat model (short): untrusted inputs are AT lines from the phone, tel:/callto: URLs from any app or web page, pasted text, contact data; dangerous outputs are placing calls (cost, service codes such as call forwarding), AT command injection, and leaking numbers, names or DTMF into logs. The app has no network access and no third-party dependencies, and should keep it that way.

  • Automated checks: injection tests (CR/LF/;/%0D/%3B, service codes, MMI via tel:), no dialing without an explicit Return/click, log canary tests (run scenarios with canary numbers/names/DTMF and assert none appears in any log file or unified-log message), entitlement audit (only Bluetooth and Contacts; sandbox state recorded; hardened runtime for release builds), codesign --verify --strict --deep, no networking symbols/frameworks linked, Package.resolved has no external packages.
  • Static analysis and hygiene: warnings as errors, SwiftLint (no force-unwrap/try!/fatalError outside tests and explicit exceptions, unused code), secret scan (gitleaks), CodeQL for Swift and dependency review on GitHub, AddressSanitizer and ThreadSanitizer test runs (swift test --sanitize=address|thread), a leak check in the stress self-test.
  • Review: code-reviewer before every commit that touches Bluetooth or audio, but after two rounds test instead of reviewing more.

The local gate: scripts/verify.sh

One command runs, in order: build all packages with warnings as errors → lint → localization check → unit/scenario/property tests (root, App, spikes) → sanitizer runs → security checks → UI tests (need the Accessibility permission for the process running the gate; they take over mouse and keyboard for about two minutes; never skipped in release). It exits non-zero on the first failure and writes a stamp for the current git tree hash. scripts/build-app.sh runs the gate first and refuses to produce Pickup.app unless it passed (PICKUP_SKIP_VERIFY=1 only for quick local builds; ignored for release).

CI/CD (prepared; runs in the public macx/pickup)

Details and the setup checklist: docs/RELEASING.md.

  1. .github/workflows/ci.yml on every pull request into main, on pushes to main, weekly and on demand: release tooling (pnpm frozen install, release-it, version files), lint, localization, test (root, App, spikes when present; warnings as errors), sanitizers (address root+App, thread root), security (scripts/security-checks.sh --strict with gitleaks and semgrep), then build (needs: all of them) packages an unsigned DMG/ZIP. pr-title.yml checks that the pull request title is a Conventional Commit. The main ruleset requires all of them. Runner: GitHub's xcode-27 image (macOS 27, preview).
  2. UI tests stay a local gate (scripts/verify.sh, run by David on the release pull request): the CI job exists but is opt-in and may not fail the run until the runner's Accessibility permission is proven.
  3. Releases: prepare-release.yml (manual) runs release-it on a release/vX.Y.Z branch and opens the release pull request; squash-merging it starts release.yml, which runs ci.yml again on that commit, then (protected environment release) tags, builds, signs and notarises (or packages an unsigned 0.x pre-release), publishes the GitHub Release and updates the Homebrew tap for signed releases.
  4. Dependabot (Actions and the pnpm release tooling, Conventional titles); every action is pinned to a commit SHA (scripts/pin-actions.sh). The workflows never run outside macx/pickup (repository guard).

App test hooks (-PickupTestScenario, debug builds only)

  • Compiled out of release: App/Package.swift defines PICKUP_TESTING for the debug configuration only; swift build -c release (and scripts/build-app.sh release) contains none of the hook code (checked: no PickupTestScenario, ScriptedTransport or control-channel strings in the release binary). TestMode.isActive is a constant false there.
  • Launch: Pickup -PickupTestScenario <name> [-PickupTestFastClock YES] [-PickupTestClockScale 0.25] [-PickupTestAutoAdvance <ms>] -AppleLanguages "(de)". The app shows "Connected to Test Phone" and uses a scripted phone (ScriptedTransport); no Bluetooth, no CNContactStore, no default-app change, no global shortcut registration, no notification or TCC prompts, logs in $TMPDIR/pickup-test-logs, the real preferences are never read or written for the phone.
  • Scenarios: idle, incoming-accept, incoming-decline, incoming-missed, incoming-withheld, outgoing-answered, outgoing-busy, outgoing-cancel, call-waiting, link-loss-resume, stress-cycle. Incoming ones ring Jane Doe (withheld: no number) 0.4 s after launch; outgoing ones start when the UI dials (the scripted phone answers ATD).
  • Advancing the script: post the distributed notification dev.eiken.pickup.test.advance (DistributedNotificationCenter.default().post(name: .init("dev.eiken.pickup.test.advance"), object: nil)); each post runs the next step (see TestHarness.script(for:): e.g. outgoing-answered = alerting, answered, remote hangs up). -PickupTestAutoAdvance <ms> steps automatically.
  • Fast clock: with -PickupTestFastClock YES the engine's delays (setup-end grace, 4 s ended display, timeouts) run at scale (default 0.25), so the ended state stays visible about 1 s. The call timer still shows real seconds.
  • Invented contacts (any scenario or -PickupDemo): Jane Doe +49 170 0000123, John Roe +49 171 0000456 (both mobile), a very long German name, Max Mustermann with mobile/work/home numbers, Øystein Åberg.
  • Identifiers: status-item, popover-root, search-field, search-clear, keypad-toggle, key-0...key-9, key-star, key-hash, key-plus (the "+" under 0; long-press key-0 instead), keypad-call, call-row, contact-row-<id>-<index> (ids: jane, john, long, multi, oystein), more-button, menu items menu-settings, menu-about, menu-quit, incoming-banner, banner-caller, banner-accept, banner-decline, call-hud, hud-caller, hud-timer, hud-state, hud-hangup, hud-close, hud-mute, hud-keypad, hud-move-to-phone, window settings-window, settings-phone-picker, settings-phone-options, settings-take-calls, settings-shortcut-recorder, settings-shortcut-clear, settings-make-default, settings-contacts-button, settings-notifications-toggle, settings-launch-at-login.