Commit c9d5d4266a

c9d5d4266a030441b3b780f64ddfaffbbfbca5f2

parent: b3ff249129

Unsigned

cmc <hello@cleberg.net> · 2026-10-26 05:20 UTC

Clear the app's store before each audit launch (!51)

Makes the enforced accessibility suite deterministic, and corrects a claim I put
in `Docs/ACCESSIBILITY.txt` two MRs ago that turned out to be wrong.

**The problem.** The suite audits several screens in their empty state, and
nothing guaranteed they were empty: `AccessibilityAuditHarness.launch` only
added launch arguments, so whatever a previous run, a manual launch or another
test target had left in the app's container was still there. The result
therefore depended on what ran before it — `testTrackedDomainsScreen` passed
with one finding in isolation, and reported six including an enforced
`[FAIL][dynamicType]` on `EditButton` during the full `xcodebuild test` the
pre-push hook runs. `EditButton` only renders when the watchlist has rows, so
the screen genuinely had data.

**The fix.** `AuditFixtures.resetStoreIfRequested` clears the defaults domain
and the history files when `DOMAIN_DIG_RESET_STORE` is passed, and the harness
passes it on every launch. It runs as the view model's `defaults:` argument
rather than inside `init()`, because a property's default value is evaluated
before the initialiser body — a reset there would run after the first read.

**The correction.** My note in !49 blamed the seeded fixtures. That was wrong:
`seedAuditFixturesIfRequested` writes only to the live view model and
`auditFixturesActive` blocks persistence specifically so they cannot leak, and
running the whole audit class against a cleared store reproduces neither the
failure nor the extra findings. I also ruled out the unit target, which leaves
`trackedDomains` as an empty array in the app's own defaults. **I never isolated
where the rows came from**, and the file now says that rather than naming a
cause I had not established.

**Measured on the invocation that failed**, same dirty simulator, no uninstall:
enforced failures go from one to none, `AccessibilityAuditTests` from 13 of 14
passing to 14, and `tracked-domains` back to a single characterised-noise
finding. The push of this branch produced no `[FAIL]` line at all.

A side effect worth having: the recent-searches section recorded earlier as
never audited can now be audited deliberately, by seeding it and launching
without the reset, instead of only showing up when a stray lookup contaminated
the store.

377 tests green on iOS 18.6 and 27.0. Ratchet unchanged at 280.

Layout: unified · split

Docs/ACCESSIBILITY.txt +46
@@ -184,6 +184,52 @@ These are latent rather than new: nothing in the section changed when Inspect
184moved to a `List`. They need a seeded recent-searches fixture to be audited 184moved to a `List`. They need a seeded recent-searches fixture to be audited
185properly, which the seed harness does not have. 185properly, which the seed harness does not have.
186 186
187## The empty-state screens are cleared before each launch
188
189The enforced suite audits several screens in their empty state, and nothing used
190to guarantee they were empty: `AccessibilityAuditHarness.launch` only added
191launch arguments, so whatever a previous run, a manual launch or another test
192target had left in the app's container was still there.
193
194That made the result depend on what ran before it. `testTrackedDomainsScreen`
195passed with one finding in isolation, and reported six — including an enforced
196`[FAIL][dynamicType]` on `EditButton`, which only renders when the watchlist has
197rows — during a full `xcodebuild test`, which is what the pre-push hook runs.
198
199**A correction to what this file said first.** The initial note blamed the
200seeded fixtures. That was wrong: `seedAuditFixturesIfRequested` writes only to
201the live view model and `auditFixturesActive` blocks persistence precisely so
202they cannot leak, and running the whole audit class against a cleared store
203reproduces neither the failure nor the extra findings. Ruled out as well: the
204unit target, which leaves `trackedDomains` as an empty array in the app's own
205defaults. The source of the rows was never isolated.
206
207What fixed it is making the question moot. `AuditFixtures.resetStoreIfRequested`
208clears the app's defaults domain and the history files when
209`DOMAIN_DIG_RESET_STORE` is passed, and the harness passes it on every launch.
210It runs as the view model's `defaults:` argument rather than inside `init()`,
211because a property's default value is evaluated before the initialiser body —
212a reset in the body would run after the first read.
213
214Measured: the same full `xcodebuild test` that reported one enforced failure
215reports none, `AccessibilityAuditTests` goes from 13 of 14 passing to 14, and
216`tracked-domains` is back to a single characterised-noise finding.
217
218## Recent searches are never audited
219
220The empty-state suite launches a fresh install, so Inspect's recent-searches
221section — which only appears once a lookup has been run — is never in the tree
222when the audit walks it. Driving one real lookup and re-auditing surfaced four
223findings in it on iOS 27.0:
224
225- `dynamicType` on the "RECENT" header and on the "Clear" button
226- `hitRegion` too small on "Clear"
227- `sufficientElementDescription`, "label not human-readable", on a domain chip
228
229These are latent rather than new: nothing in the section changed when Inspect
230moved to a `List`. They need a seeded recent-searches fixture to be audited
231properly, which the seed harness does not have.
232
187## The empty-state screens are not reliably empty 233## The empty-state screens are not reliably empty
188 234
189`AccessibilityAuditHarness.launch` only adds launch arguments; it never resets 235`AccessibilityAuditHarness.launch` only adds launch arguments; it never resets
DomainDig/AuditFixtures.swift +28
@@ -18,6 +18,34 @@ import Foundation
18/// certificate badges, pinned, noted, changed, monitoring on/off, a 18/// certificate badges, pinned, noted, changed, monitoring on/off, a
19/// stress-length domain name, and every batch status including failure. 19/// stress-length domain name, and every batch status including failure.
20enum AuditFixtures { 20enum AuditFixtures {
21 /// Clears the app's own store so an audit launch starts from a known
22 /// state.
23 ///
24 /// The fixtures below are in-memory and never persist, but nothing stopped
25 /// *other* state — whatever a previous run, a manual launch, or another
26 /// test target left in the container — from reaching a screen the enforced
27 /// suite audits as empty. That made the result depend on what ran before
28 /// it: `testTrackedDomainsScreen` passes with one finding in isolation and
29 /// reported an enforced `dynamicType` failure on `EditButton`, which only
30 /// renders when the watchlist has rows, during a full `xcodebuild test`.
31 ///
32 /// Returns the store it cleared so a caller can thread it into whatever
33 /// reads it first, which is what stops the reset being ordered after the
34 /// read by accident.
35 @discardableResult
36 static func resetStoreIfRequested(_ defaults: UserDefaults = .standard) -> UserDefaults {
37 guard ProcessInfo.processInfo.arguments.contains(resetStoreArgument) else {
38 return defaults
39 }
40 if let domain = Bundle.main.bundleIdentifier {
41 defaults.removePersistentDomain(forName: domain)
42 }
43 HistoryFileStore.removeAll(at: .default)
44 return defaults
45 }
46
47 static let resetStoreArgument = "DOMAIN_DIG_RESET_STORE"
48
21 static let launchArgument = "DOMAIN_DIG_SEED_FIXTURES" 49 static let launchArgument = "DOMAIN_DIG_SEED_FIXTURES"
22 50
23 static var requested: Bool { 51 static var requested: Bool {
DomainDig/DomainDigApp.swift +7
@@ -14,7 +14,14 @@ struct DomainDigApp: App {
14 @AppStorage(AppDensity.userDefaultsKey) private var density = AppDensity.compact.rawValue 14 @AppStorage(AppDensity.userDefaultsKey) private var density = AppDensity.compact.rawValue
15 @AppStorage(AppAppearance.userDefaultsKey) private var appearance = AppAppearance.system.rawValue 15 @AppStorage(AppAppearance.userDefaultsKey) private var appearance = AppAppearance.system.rawValue
16 @AppStorage(AccentTheme.userDefaultsKey) private var accent = AccentTheme.default.rawValue 16 @AppStorage(AccentTheme.userDefaultsKey) private var accent = AccentTheme.default.rawValue
17 // The store is cleared as the view model's argument rather than in
18 // `init()`, because a property's default value is evaluated before the
19 // initialiser body — a reset there would run after the first read.
20 #if DEBUG
21 @State private var viewModel = DomainViewModel(defaults: AuditFixtures.resetStoreIfRequested())
22 #else
17 @State private var viewModel = DomainViewModel() 23 @State private var viewModel = DomainViewModel()
24 #endif
18 @State private var purchaseService = PurchaseService.shared 25 @State private var purchaseService = PurchaseService.shared
19 @State private var cloudSyncService = CloudSyncService.shared 26 @State private var cloudSyncService = CloudSyncService.shared
20 @State private var localAPIService = LocalAPIService.shared 27 @State private var localAPIService = LocalAPIService.shared
DomainDigUITests/AccessibilityAuditHarness.swift +5 −1
@@ -27,6 +27,8 @@ enum AccessibilityAuditHarness {
27 /// Launch argument that lifts feature gating so Pro-only screens are 27 /// Launch argument that lifts feature gating so Pro-only screens are
28 /// reachable. `PurchaseService` honours this in `DEBUG` builds only. 28 /// reachable. `PurchaseService` honours this in `DEBUG` builds only.
29 private static let forceProPlusArgument = "DOMAIN_DIG_FORCE_PRO_PLUS" 29 private static let forceProPlusArgument = "DOMAIN_DIG_FORCE_PRO_PLUS"
30 /// Matches `AuditFixtures.resetStoreArgument`.
31 private static let resetStoreArgument = "DOMAIN_DIG_RESET_STORE"
30 32
31 /// Audit categories that fail the build on the empty-state suite. A named 33 /// Audit categories that fail the build on the empty-state suite. A named
32 /// finding in any of these is a regression in the phase 1–5 work. 34 /// finding in any of these is a regression in the phase 1–5 work.
@@ -59,7 +61,9 @@ enum AccessibilityAuditHarness {
59 /// content size category and with the audit fixtures seeded. 61 /// content size category and with the audit fixtures seeded.
60 static func launch(contentSizeCategory: String? = nil, seeded: Bool = false) -> XCUIApplication { 62 static func launch(contentSizeCategory: String? = nil, seeded: Bool = false) -> XCUIApplication {
61 let app = XCUIApplication() 63 let app = XCUIApplication()
62 app.launchArguments = [forceProPlusArgument] 64 // Every launch starts from a cleared store, so a screen the enforced
65 // suite audits as empty is empty whatever ran before it.
66 app.launchArguments = [forceProPlusArgument, resetStoreArgument]
63 if seeded { 67 if seeded {
64 app.launchArguments.append(seedFixturesArgument) 68 app.launchArguments.append(seedFixturesArgument)
65 } 69 }