Tests

The cairn test suite doubles as the conformance spec for CairnCore: any behavior change to a protocol there should land alongside a test that pins the new contract, so a future Kotlin/Android port has something concrete to match. The suite runs against macOS + Linux via swift test (no Apple-only test types here — those live in CairnIOSCoreTests).

Where to look first

If you’re trying to understand a piece of cairn’s behavior without reading every line of the implementation, these tests are the highest signal-to-noise:

Engine semantics

State stores (the protocols a Kotlin port would re-implement)

  • ObservedStoreTests.swift — The “ever-seen” SHA1 set that distinguishes “user deleted this from iPhone” from “this was never on iPhone.”
  • ConfirmedDeletedStoreTests.swift — Per-checksum confirmation timestamps that drive the quarantine clock. First-write-wins on timestamps; the rationale is in the test names.
  • EditRetirementStoreTests.swift — First-observed SHA1 anchoring per localIdentifier. Critical for edit-handling correctness; the “edit → revert → edit again” worked scenario is pinned here.
  • ExclusionStoreTests.swift — User-protected checksums. Survives index resets.

API + journal

iOS-specific impls

Tests/CairnIOSCoreTests/ mirrors CairnIOSCoreTests. Highlights:

Conventions

  • Tests use Swift Testing (@Test, @Suite, #expect), not XCTest.
  • Test names describe the contract being pinned, not the implementation strategy (“first-write-wins on timestamp” rather than “test confirmed-deleted union with overlapping checksums”). Read them like a spec.
  • Suites that share global state (like MockURLProtocol.handler) are marked .serialized so parallel execution doesn’t race them.
  • CairnFixtures (in Sources/CairnIOSCore/UI/CairnFixtures.swift) is the canonical source of preview / test data — reuse rather than re-rolling fake assets per test file.

Running

swift test                              # full suite, both modules
swift test --filter ReconciliationEngine # one suite
swift test --filter "first-write-wins"   # by test-name pattern

iOS-app integration testing (against the simulator) is the make test lane in iOS/Makefile; it currently wraps the same SPM suite. Snapshot tests for the SwiftUI screens are planned but not yet present.