Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,49 @@ name: CI
on:
pull_request:
branches: [main]
# A docs-only change moves no Swift, so the 100%-on-touched-files coverage
# gate has nothing to measure and the run is pure cost.
# `scripts/` is deliberately NOT ignored: the gate and its allowlist must
# still be evaluated when the tooling that measures coverage changes.
paths-ignore:
- '**.md'
- 'docs/**'

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
# Pure Python, needs no Xcode, so it costs an ubuntu minute instead of a
# macOS one and answers before simulator work starts.
dynamic-type:
name: Dynamic Type Guard
runs-on: ubuntu-latest
# A hung guard fails at 5 min instead of billing the 360 min default.
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Check Dynamic Type
run: |
python3 scripts/check_dynamic_type.py --paths FitCheck
python3 scripts/check_dynamic_type.py --self-test

tests:
name: Unit Tests
needs: dynamic-type
# Xcode 26 ships the iOS 26 SDK, which the app's deployment target needs.
# macOS runners are billed at 10x on a private repository, hence the
# timeout and the single job.
# macOS runners are billed at 10x on a private repository.
# 12 min against a median 2.3 min / p90 2.8 min: a hang fails at $0.74
# instead of billing the full 30 min at $1.86.
runs-on: macos-26
timeout-minutes: 30
timeout-minutes: 12
steps:
# Full history and tags: the coverage gate diffs against the merge base,
# which a shallow clone does not carry.
- uses: actions/checkout@v4
with:
fetch-depth: 0

# The Dynamic Type guard needs no Xcode, so it answers first: a fixed text
# size fails the pull request before any simulator work starts.
- name: Check Dynamic Type
run: |
python3 scripts/check_dynamic_type.py --paths FitCheck
python3 scripts/check_dynamic_type.py --self-test

- name: Install XcodeGen
run: brew install xcodegen

Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
name: gitleaks

# Secret scanning runs on every push and every pull request, not only on PRs.
# Secret scanning runs once per change: on the pull request, and on main after
# the merge. The unfiltered push trigger scanned the same commit twice.
on:
push:
branches: [main]
pull_request:

# A superseded scan of the same ref has nothing left to say.
concurrency:
group: gitleaks-${{ github.ref }}
cancel-in-progress: true

# On a pull_request event the action lists the PR's commits to decide what to
# scan, which the default read-only token can't do — the job died on a 403
# while the identical push-event run passed.
Expand Down
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ kebab-case slug. One issue per branch. Never work directly on `main`.
CI test jobs run only on pull requests into `main`: a push to a branch or to
`main` starts no test run. Run the full unit suite locally before every push —
the PR check is the second opinion, not the first. Secret scanning is the
exception: it runs on every commit and every push.
exception: every commit through the local pre-commit hook, and in CI on every
pull request plus every push to `main`.

`main` is PR-only. A [`pre-push`](.githooks/pre-push) hook blocks direct pushes
to it. This is a *local* guardrail: server-side branch protection is
Expand Down Expand Up @@ -94,8 +95,8 @@ Simulator names are version-specific and go stale — `xcodebuild` prints the va
- **Parametric tests for the same body with different inputs** — see `CategoryGlyphTests`, which runs one test over `ClothingCategory.allCases` instead of ten copies.
- **Real store, fake world.** A test may use a real in-memory `ModelContainer` (`makeContext()` in the `ClothingItem` suite): SwiftData's behaviour is part of what is being tested. Anything that leaves the device — the network, the clock, Apple Intelligence — is replaced or avoided. Views are not unit-tested; their logic lives in `AppState` and the services so it can be.
- **Assert on the artefact, not on the call.** The closet export is checked by reading the produced zip back ([`ZipArchive`](FitCheckTests/ZipArchive.swift)), because the archive format is the promise made in Settings. The app reads that format with its own [`ZipReader`](FitCheck/Services/ZipReader.swift) — production code, typed failures, and the exporter's staging folder, stored and raw-DEFLATE entries all in scope — while `ZipArchive` stays the test side's fixture reader. Above it, [`ClosetImporter`](FitCheck/Services/ClosetImporter.swift) splits in two: a pure `plan` that takes the index bytes and the archive's files and hands back garments plus the imported/duplicate/invalid counts, and a `@MainActor apply` that takes the app's own `ModelContext`. Neither half is on the allowlist: the parsing rules are provable without SwiftData, and the insert runs against a real in-memory container.
- **No fixed text size.** Every text size scales through a `@ScaledMetric` declared in the same file as the view that draws it (or a semantic style), so [`scripts/check_dynamic_type.py`](scripts/check_dynamic_type.py) fails a `.system(size:)` or `UIFont.systemFont(ofSize:)` whose size is a literal — or arithmetic rooted in one — rather than a scaled property in the same file. `Theme` holds the raw numbers only — palette and metrics, plus a scaled-control wrapper that view bodies read — and each view scales the dimension it draws, so no token decides a text size on its own. The one way past the check is a reason on the same line — `// dynamic-type-ok: <why it cannot scale>`, for decoration or a measuring artefact — because a per-file allowlist would let a screen be exempted quietly, while a per-line reason has to argue for the exact size it excuses. It runs in CI in the same job as the coverage gate, before the Xcode work, with `--self-test` replaying the fixtures in [`scripts/tests/`](scripts/tests/).
- **Coverage standard.** 100% line coverage on every file the branch touches, measured once at the gate. The same gate runs in CI on every pull request, in the one job that also runs the Dynamic Type check: [`scripts/coverage_gate.py`](scripts/coverage_gate.py) diffs the branch against its base and fails on any Swift file under `FitCheck/` short of 100%, with [`scripts/coverage-allowlist.txt`](scripts/coverage-allowlist.txt) the only way past it — so a new service arrives with its tests rather than borrowing coverage from its neighbours.
- **No fixed text size.** Every text size scales through a `@ScaledMetric` declared in the same file as the view that draws it (or a semantic style), so [`scripts/check_dynamic_type.py`](scripts/check_dynamic_type.py) fails a `.system(size:)` or `UIFont.systemFont(ofSize:)` whose size is a literal — or arithmetic rooted in one — rather than a scaled property in the same file. `Theme` holds the raw numbers only — palette and metrics, plus a scaled-control wrapper that view bodies read — and each view scales the dimension it draws, so no token decides a text size on its own. The one way past the check is a reason on the same line — `// dynamic-type-ok: <why it cannot scale>`, for decoration or a measuring artefact — because a per-file allowlist would let a screen be exempted quietly, while a per-line reason has to argue for the exact size it excuses. It runs in CI in its own `ubuntu-latest` job that the macOS job waits on, before any Xcode work, with `--self-test` replaying the fixtures in [`scripts/tests/`](scripts/tests/).
- **Coverage standard.** 100% line coverage on every file the branch touches, measured once at the gate. The same gate runs in CI on every pull request in the macOS job: [`scripts/coverage_gate.py`](scripts/coverage_gate.py) diffs the branch against its base and fails on any Swift file under `FitCheck/` short of 100%, with [`scripts/coverage-allowlist.txt`](scripts/coverage-allowlist.txt) the only way past it — so a new service arrives with its tests rather than borrowing coverage from its neighbours.
- **Coverage allowlist.** Some files cannot reach 100% from the unit target. They are named here, with the reason, so an exclusion is a decision on the record instead of a silent gap — **anything not on this list is expected at 100%, and a gap there is a defect in the branch.** The prose below is documentation; the copy CI actually reads is [`scripts/coverage-allowlist.txt`](scripts/coverage-allowlist.txt), one path and its reason per line, and the two must not disagree — a reason changed here changes there in the same commit. The list is the final gate measurement against base `20a90fc` (304 tests, 48 suites, app target 23.00%, 3481/15132); remove an entry when its reason stops being true, never by lowering the standard.
1. **SwiftUI view bodies** — `FitCheck/Features/**`, `RootView`, `ComposerView`, `SettingsView`, `WeatherSheet`, `SavedLookSheet`, and in `DesignSystem` the views themselves: `GarmentViews`, `GlassComponents`, `SnappingSlider.swift` (a `Slider` wrapper, body only) and `Theme.swift` (palette, metric constants and the scaled-control wrapper, read only from view bodies). The unit target cannot evaluate a view body, so their logic was pushed into services and `AppState` and is tested there (`ComposerView` 82.2%, `HomeView` 41.0%, the rest 0–41%); the views themselves are only reachable from the UI tests. This one does not expire — it is the boundary the architecture was built around, and a view that grows logic gets the logic moved out rather than a test bolted on. The Debug-only [`ClassifierBenchmarkView`](FitCheck/Features/Diagnostics/ClassifierBenchmarkView.swift) is here for a sharper reason than its body: its runner reads 39 bundled PNGs and asks the live model, so nothing in it can execute in the unit target. Everything it decides is the pure `ClassifierBenchmark` — which labels are equal, which colour family a name belongs to, what a percentage is out of, how a value is quoted — and that is the half the unit target covers — the gap here is the runner, not a rule. The file is compiled into Debug builds alone, so a release build carries neither the screen nor the runner.
2. **Apple-framework adapters** — `MapKitPlaceNamer`, `MapKitPlaceSearch`, the `CLLocationManager` delegate callbacks and its `recentLocation` extension, and `ReminderScheduler`'s `UNUserNotificationCenter` calls. They are the real CoreLocation, MapKit and UserNotifications, which cannot answer in the unit target, and the rules around them are tested through the `PlaceNaming` / `PlaceSearching` / `LocationFixRequester` fakes; the adapters themselves are exercised in a running app. `ReminderScheduler.storedLocalization` is here for the same reason: its only path is `sync`, which awaits `UNUserNotificationCenter.current().notificationSettings()` first, so covering it from the unit target would fire a real authorisation prompt against the host app and write the host's preference domain (the code hardcodes `UserDefaults.forCurrentRun`). Removed per adapter only by pulling logic out of it and behind a fakeable seam — never by faking the framework to chase the number.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ xcodebuild -project FitCheck.xcodeproj -scheme FitCheck \
test -only-testing:FitCheckTests
```

`.github/workflows/ci.yml` runs the same command on a macOS runner for every pull request, prints the coverage report, then runs [`scripts/coverage_gate.py`](./scripts/coverage_gate.py), which requires **100% line coverage on every Swift file under `FitCheck/` that the pull request touches.** A file that cannot reach the standard from the unit target is named in [`scripts/coverage-allowlist.txt`](./scripts/coverage-allowlist.txt) with its reason, one path per line; anything missing from that list has no excuse, and [AGENTS.md](./AGENTS.md#testing) documents the entries and why each one exists. On a push to `main` the gate does not run: the merge that landed there already ran it. `ClosetExporter` is still checked by reading the archive it produces back, and `Features/` is exercised by the UI tests.
`.github/workflows/ci.yml` runs the same command on a macOS runner for every pull request, prints the coverage report, then runs [`scripts/coverage_gate.py`](./scripts/coverage_gate.py), which requires **100% line coverage on every Swift file under `FitCheck/` that the pull request touches.** A file that cannot reach the standard from the unit target is named in [`scripts/coverage-allowlist.txt`](./scripts/coverage-allowlist.txt) with its reason, one path per line; anything missing from that list has no excuse, and [AGENTS.md](./AGENTS.md#testing) documents the entries and why each one exists. On a push to `main` the gate does not run: the merge that landed there already ran it. A documentation-only pull request (markdown files, [`docs/`](./docs)) starts no CI run — the secret scan is the only job it triggers — because there is no Swift to measure and nothing for the simulator to prove, while a change under [`scripts/`](./scripts) still runs the gate. `ClosetExporter` is still checked by reading the archive it produces back, and `Features/` is exercised by the UI tests.

Text scales with the system setting through `@ScaledMetric`, so [`scripts/check_dynamic_type.py`](./scripts/check_dynamic_type.py) fails any `.system(size:)` — or raw `UIFont.systemFont(ofSize:)` — added under `FitCheck/` whose size is a literal or arithmetic rooted in one instead of a `@ScaledMetric` property declared in the same file; the only way past it is a reason on that same line (`// dynamic-type-ok: <why it cannot scale>`), for decoration or a measuring artefact that has no text to scale. A reason sits on the line it excuses rather than in a per-file allowlist, so a screen cannot be exempted quietly — each fixed size has to argue for itself. The check runs in the same CI job as the coverage gate, before the Xcode work. At the default text size the layout is unchanged: a `@ScaledMetric` starts at the value it replaced, so it is the larger settings that grow, not the baseline design.
Text scales with the system setting through `@ScaledMetric`, so [`scripts/check_dynamic_type.py`](./scripts/check_dynamic_type.py) fails any `.system(size:)` — or raw `UIFont.systemFont(ofSize:)` — added under `FitCheck/` whose size is a literal or arithmetic rooted in one instead of a `@ScaledMetric` property declared in the same file; the only way past it is a reason on that same line (`// dynamic-type-ok: <why it cannot scale>`), for decoration or a measuring artefact that has no text to scale. A reason sits on the line it excuses rather than in a per-file allowlist, so a screen cannot be exempted quietly — each fixed size has to argue for itself. The check runs in its own `ubuntu-latest` job that the macOS job waits on, so a fixed text size fails the pull request before any simulator work starts. At the default text size the layout is unchanged: a `@ScaledMetric` starts at the value it replaced, so it is the larger settings that grow, not the baseline design.

---

Expand All @@ -253,6 +253,6 @@ This repo uses [gitleaks](https://github.com/gitleaks/gitleaks) to catch API key
git config core.hooksPath .githooks
```
Requires `gitleaks` installed locally (`brew install gitleaks`).
* **CI check:** every push and pull request is also scanned automatically via the [gitleaks GitHub Action](.github/workflows/gitleaks.yml), so secrets are caught even if the local hook is skipped.
* **CI check:** the scan also runs automatically via the [gitleaks GitHub Action](.github/workflows/gitleaks.yml) on every pull request and on every push to `main` — one scan per change — so secrets are caught even if the local hook is skipped.

Config lives in [`.gitleaks.toml`](.gitleaks.toml); add allowlist entries there for confirmed false positives.
Loading