Commit f690cb4f54

f690cb4f54358c644c1ee2e2c2317341c2f33423

parent: e40c6d02e6

Unsigned

cmc <hello@cleberg.net> · 2026-10-25 04:02 UTC

Retention per tier, and an honest Settings caption (!27)

D1's retention dial, the last of W5: **50 snapshots free, 250 Pro, 2000 Pro+**,
as `historyRetentionLimit` on `FeatureEntitlements`.

It replaces the single 250 hard cap, which three places each held their own copy
of — `DomainViewModel.maxHistory`,
`DomainDataPortabilityService.historyStorageCap` and
`DomainMonitoringService.maxHistoryEntries`. All three are gone.

## A downgrade never deletes

Review Focus #6 requires a lapsed Pro+ subscriber with 2000 snapshots to lose
none of them. So the ceiling a new snapshot is stored under is
`max(tier limit, what is already held)`: the store stops growing without
pruning, and holds there rather than draining to the lower tier a row per
lookup. For anyone at or under their limit that is just the limit.

It has to be read *before* the insert, or the row being added raises its own
ceiling and nothing is ever pruned — which is the bug this shape invites.

The user's own auto-prune choice is separate: it may ask for less than the tier
allows and it *is* permitted to delete, because they chose it. "Unlimited" now
means the tier's limit rather than unbounded.

## The monitoring run follows the same rule

It had its own 250, so a background run on a lapsed Pro+ install would have
pruned a history the app itself keeps. Found while removing the orphaned
constants.

## The caption

`SettingsViews` said auto-prune "defaults to unlimited". That was never true —
there has always been a hard ceiling, which is what made it a finding. It names
the tier's limit now, and when a store is above that limit it says nothing
already saved is removed, which is what the store actually does.

## Coverage

9 tests: the three tier numbers and that they rise; the growth ceiling at and
above the limit (Review Focus #6); the user's choice clamped by the tier and
allowed to prune; "unlimited" meaning the tier's limit; and the caption naming
the limit, never saying "unlimited", and reassuring when over.

Drops `testTheHardCapAppliesEvenWhenPruningIsUnlimited` from !21, which
asserted the same thing against a pinned 250.

## Verification

Both tiers from cold: 233 tests, 0 failures on iOS 18.6 (iPhone 16) and iOS
27.0 (iPhone Air).

Layout: unified · split

DomainDataPortabilityService.swift −4
@@ -758,10 +758,6 @@ enum DomainDataPortabilityService {
758 /// reads it; nothing else should. 758 /// reads it; nothing else should.
759 static let legacyHistoryBlobKey = StorageKey.history 759 static let legacyHistoryBlobKey = StorageKey.history
760 760
761 /// The hard ceiling on history, independent of the user's auto-prune
762 /// setting. The per-tier retention dial D1 settled on (50/250/2000)
763 /// replaces this constant; until then every tier shares it.
764 static let historyStorageCap = 250
765 761
766 762
767 static func loadAuditSessions(defaults: UserDefaults = .standard) -> [AuditSession] { 763 static func loadAuditSessions(defaults: UserDefaults = .standard) -> [AuditSession] {
DomainDig/DomainMonitoringService.swift +6 −4
@@ -259,7 +259,6 @@ final class DomainMonitoringService {
259 static let shared = DomainMonitoringService() 259 static let shared = DomainMonitoringService()
260 260
261 private let inspectionService = DomainInspectionService() 261 private let inspectionService = DomainInspectionService()
262 private let maxHistoryEntries = 250
263 private let calendar = Calendar.current 262 private let calendar = Calendar.current
264 263
265 func performMonitoring( 264 func performMonitoring(
@@ -599,10 +598,13 @@ final class DomainMonitoringService {
599 failures: .init(snapshot: snapshot) 598 failures: .init(snapshot: snapshot)
600 ) 599 )
601 600
601 // Same retention rule as the view model's: the tier's limit, but never
602 // below what is already stored, so a monitoring run on a lapsed Pro+
603 // install does not prune a history the app itself would keep. Read
604 // before the insert, or the row being added raises its own ceiling.
605 let storedLimit = max(FeatureAccessService.historyRetentionLimit, history.count)
602 history.insert(entry, at: 0) 606 history.insert(entry, at: 0)
603 if history.count > maxHistoryEntries { 607 history = Array(history.prefix(storedLimit))
604 history = Array(history.prefix(maxHistoryEntries))
605 }
606 608
607 if let index = trackedDomains.firstIndex(where: { $0.id == trackedDomainID }) { 609 if let index = trackedDomains.firstIndex(where: { $0.id == trackedDomainID }) {
608 trackedDomains[index].lastSnapshotID = entry.id 610 trackedDomains[index].lastSnapshotID = entry.id
DomainDig/DomainViewModel.swift +74 −28
@@ -302,7 +302,6 @@ final class DomainViewModel {
302 var trackedDomains: [TrackedDomain] 302 var trackedDomains: [TrackedDomain]
303 303
304 private static let historyKey = "lookupHistory" 304 private static let historyKey = "lookupHistory"
305 private static let maxHistory = 250
306 var history: [HistoryEntry] 305 var history: [HistoryEntry]
307 var auditSessions: [AuditSession] 306 var auditSessions: [AuditSession]
308 private static let workflowsKey = "domainWorkflows" 307 private static let workflowsKey = "domainWorkflows"
@@ -859,7 +858,7 @@ final class DomainViewModel {
859 } 858 }
860 } 859 }
861 persistTrackedDomains() 860 persistTrackedDomains()
862 relinked.forEach { storeHistoryEntry($0, replacingExisting: true) } 861 relinked.forEach { updateStoredHistory($0) }
863 sanitizeMonitoringSelection() 862 sanitizeMonitoringSelection()
864 } 863 }
865 864
@@ -875,7 +874,7 @@ final class DomainViewModel {
875 } 874 }
876 } 875 }
877 persistTrackedDomains() 876 persistTrackedDomains()
878 relinked.forEach { storeHistoryEntry($0, replacingExisting: true) } 877 relinked.forEach { updateStoredHistory($0) }
879 sanitizeMonitoringSelection() 878 sanitizeMonitoringSelection()
880 } 879 }
881 880
@@ -1809,6 +1808,9 @@ final class DomainViewModel {
1809 currentHistoryEntryID = entry.id 1808 currentHistoryEntryID = entry.id
1810 } 1809 }
1811 1810
1811 // Before the insert: afterwards `history.count` includes this entry
1812 // and `growthHistoryLimit` would never prune anything.
1813 let storedLimit = growthHistoryLimit
1812 let replacedLatest = replaceLatest 1814 let replacedLatest = replaceLatest
1813 && !history.isEmpty 1815 && !history.isEmpty
1814 && history[0].domain.caseInsensitiveCompare(snapshot.domain) == .orderedSame 1816 && history[0].domain.caseInsensitiveCompare(snapshot.domain) == .orderedSame
@@ -1816,7 +1818,7 @@ final class DomainViewModel {
1816 history[0] = entry 1818 history[0] = entry
1817 } else { 1819 } else {
1818 history.insert(entry, at: 0) 1820 history.insert(entry, at: 0)
1819 trimHistoryToLimit() 1821 history = Array(history.prefix(storedLimit))
1820 } 1822 }
1821 1823
1822 updateTrackedDomainSnapshotMetadata( 1824 updateTrackedDomainSnapshotMetadata(
@@ -1829,7 +1831,11 @@ final class DomainViewModel {
1829 certificateWarningLevel: DomainDiffService.certificateWarningLevel(for: snapshot), 1831 certificateWarningLevel: DomainDiffService.certificateWarningLevel(for: snapshot),
1830 certificateDaysRemaining: snapshot.sslInfo?.daysUntilExpiry 1832 certificateDaysRemaining: snapshot.sslInfo?.daysUntilExpiry
1831 ) 1833 )
1832 storeHistoryEntry(entry, replacingExisting: replacedLatest) 1834 if replacedLatest {
1835 updateStoredHistory(entry)
1836 } else {
1837 appendStoredHistory(entry, cap: storedLimit)
1838 }
1833 notifyIfNeeded(for: entry, snapshot: snapshot, previousSnapshot: previousSnapshot) 1839 notifyIfNeeded(for: entry, snapshot: snapshot, previousSnapshot: previousSnapshot)
1834 return entry 1840 return entry
1835 } 1841 }
@@ -1837,25 +1843,34 @@ final class DomainViewModel {
1837 /// A single snapshot written on its own. `persistHistory` rewrites every 1843 /// A single snapshot written on its own. `persistHistory` rewrites every
1838 /// row because it cannot tell what changed; these callers can, and at the 1844 /// row because it cannot tell what changed; these callers can, and at the
1839 /// Pro+ cap that is the difference between 23 ms and 656 ms. 1845 /// Pro+ cap that is the difference between 23 ms and 656 ms.
1840 private func storeHistoryEntry(_ entry: HistoryEntry, replacingExisting: Bool) { 1846 /// Replaces one stored snapshot. No cap: an update changes a row that is
1847 /// already there and cannot push the store past its limit.
1848 private func updateStoredHistory(_ entry: HistoryEntry) {
1841 if historyPersistenceSuspended { 1849 if historyPersistenceSuspended {
1842 historyPersistenceDirty = true 1850 historyPersistenceDirty = true
1843 return 1851 return
1844 } 1852 }
1845 if replacingExisting { 1853 DomainDataPortabilityService.updateHistoryEntry(
1846 DomainDataPortabilityService.updateHistoryEntry( 1854 entry,
1847 entry, 1855 defaults: defaults,
1848 defaults: defaults, 1856 historyLocation: historyLocation
1849 historyLocation: historyLocation 1857 )
1850 ) 1858 refreshDataLifecycleSummary()
1851 } else { 1859 }
1852 DomainDataPortabilityService.appendHistoryEntry( 1860
1853 entry, 1861 /// Stores a new snapshot under `cap`, which the caller reads before its
1854 cap: effectiveHistoryLimit, 1862 /// own insert so the row being added does not raise its own ceiling.
1855 defaults: defaults, 1863 private func appendStoredHistory(_ entry: HistoryEntry, cap: Int) {
1856 historyLocation: historyLocation 1864 if historyPersistenceSuspended {
1857 ) 1865 historyPersistenceDirty = true
1866 return
1858 } 1867 }
1868 DomainDataPortabilityService.appendHistoryEntry(
1869 entry,
1870 cap: cap,
1871 defaults: defaults,
1872 historyLocation: historyLocation
1873 )
1859 refreshDataLifecycleSummary() 1874 refreshDataLifecycleSummary()
1860 } 1875 }
1861 1876
@@ -1874,7 +1889,8 @@ final class DomainViewModel {
1874 1889
1875 /// Rewrites the whole store. Only the auto-prune setting needs this — it 1890 /// Rewrites the whole store. Only the auto-prune setting needs this — it
1876 /// drops rows from the middle and cannot say which. Every other writer 1891 /// drops rows from the middle and cannot say which. Every other writer
1877 /// goes through `storeHistoryEntry` or `removeStoredHistory`. 1892 /// goes through `appendStoredHistory`, `updateStoredHistory` or
1893 /// `removeStoredHistory`.
1878 private func persistHistory() { 1894 private func persistHistory() {
1879 if historyPersistenceSuspended { 1895 if historyPersistenceSuspended {
1880 historyPersistenceDirty = true 1896 historyPersistenceDirty = true
@@ -1894,14 +1910,14 @@ final class DomainViewModel {
1894 func setHistoryAutoPruneOption(_ option: HistoryAutoPruneOption) { 1910 func setHistoryAutoPruneOption(_ option: HistoryAutoPruneOption) {
1895 historyAutoPruneOption = option 1911 historyAutoPruneOption = option
1896 defaults.set(option.rawValue, forKey: Self.historyAutoPruneKey) 1912 defaults.set(option.rawValue, forKey: Self.historyAutoPruneKey)
1897 trimHistoryToLimit() 1913 history = Array(history.prefix(requestedHistoryLimit))
1898 persistHistory() 1914 persistHistory()
1899 } 1915 }
1900 1916
1901 func updateHistoryNote(_ note: String, for entry: HistoryEntry) { 1917 func updateHistoryNote(_ note: String, for entry: HistoryEntry) {
1902 guard let index = history.firstIndex(where: { $0.id == entry.id }) else { return } 1918 guard let index = history.firstIndex(where: { $0.id == entry.id }) else { return }
1903 history[index].note = note.trimmingCharacters(in: .whitespacesAndNewlines).nilIfEmpty 1919 history[index].note = note.trimmingCharacters(in: .whitespacesAndNewlines).nilIfEmpty
1904 storeHistoryEntry(history[index], replacingExisting: true) 1920 updateStoredHistory(history[index])
1905 } 1921 }
1906 1922
1907 #if DEBUG 1923 #if DEBUG
@@ -1958,14 +1974,44 @@ final class DomainViewModel {
1958 refreshDataLifecycleSummary() 1974 refreshDataLifecycleSummary()
1959 } 1975 }
1960 1976
1961 /// The number of snapshots this install keeps: the user's auto-prune 1977 /// What Settings says under the auto-prune picker. The old copy claimed
1962 /// choice, never above the store's own ceiling. 1978 /// auto-prune "defaults to unlimited", which was never true — there has
1963 private var effectiveHistoryLimit: Int { 1979 /// always been a hard ceiling, and under D1 it is the tier's.
1964 min(historyAutoPruneOption.keepCount ?? Self.maxHistory, Self.maxHistory) 1980 var historyRetentionCaption: String {
1981 let limit = tierHistoryLimit
1982 let base = "History stays on this device. Your plan keeps up to \(limit) snapshots"
1983 guard history.count > limit else {
1984 return base + "; auto-prune trims to fewer if you want."
1985 }
1986 return base
1987 + ", and you have \(history.count). Nothing already saved is removed —"
1988 + " new snapshots replace the oldest instead."
1989 }
1990
1991 /// Snapshots this tier keeps: 50 free, 250 Pro, 2000 Pro+ under D1.
1992 private var tierHistoryLimit: Int {
1993 FeatureAccessService.historyRetentionLimit
1994 }
1995
1996 /// The ceiling a newly stored snapshot is kept under, computed before the
1997 /// insert. Never below what is already held: a lapsed Pro+ subscriber with
1998 /// 2000 snapshots keeps all 2000 (Review Focus #6), and the store holds
1999 /// there rather than draining to the lower tier a row at a time. For
2000 /// anyone at or under their tier's limit this is just that limit.
2001 var growthHistoryLimit: Int {
2002 max(tierHistoryLimit, history.count)
2003 }
2004
2005 /// What the user's own auto-prune choice asks for, which may be less than
2006 /// the tier allows but never more. This one is permitted to delete,
2007 /// because the user chose it.
2008 var requestedHistoryLimit: Int {
2009 min(historyAutoPruneOption.keepCount ?? tierHistoryLimit, tierHistoryLimit)
1965 } 2010 }
1966 2011
2012 /// Caps growth without pruning what is already stored.
1967 private func trimHistoryToLimit() { 2013 private func trimHistoryToLimit() {
1968 history = Array(history.prefix(effectiveHistoryLimit)) 2014 history = Array(history.prefix(growthHistoryLimit))
1969 } 2015 }
1970 2016
1971 private func nextSnapshotIndex(for domain: String, trackedDomainID: UUID?) -> Int { 2017 private func nextSnapshotIndex(for domain: String, trackedDomainID: UUID?) -> Int {
@@ -2099,7 +2145,7 @@ final class DomainViewModel {
2099 } 2145 }
2100 } 2146 }
2101 2147
2102 relinked.forEach { storeHistoryEntry($0, replacingExisting: true) } 2148 relinked.forEach { updateStoredHistory($0) }
2103 2149
2104 if let latestEntry = history.first(where: { $0.domain.caseInsensitiveCompare(domain) == .orderedSame }), 2150 if let latestEntry = history.first(where: { $0.domain.caseInsensitiveCompare(domain) == .orderedSame }),
2105 let trackedIndex = trackedDomains.firstIndex(where: { $0.id == trackedDomain.id }) { 2151 let trackedIndex = trackedDomains.firstIndex(where: { $0.id == trackedDomain.id }) {
DomainDig/FeatureAccessService.swift +16 −3
@@ -73,6 +73,10 @@ struct FeatureEntitlements: Equatable {
73 let batchSizeLimit: Int? 73 let batchSizeLimit: Int?
74 /// Concurrently open audit sessions; nil is unlimited. 74 /// Concurrently open audit sessions; nil is unlimited.
75 let activeAuditSessionLimit: Int? 75 let activeAuditSessionLimit: Int?
76 /// Snapshots kept per install, the retention dial D1 settled on. Not
77 /// optional: every tier has a ceiling, and the store is not a place to
78 /// accumulate without one.
79 let historyRetentionLimit: Int
76} 80}
77 81
78struct UpgradePromptContext: Identifiable, Equatable { 82struct UpgradePromptContext: Identifiable, Equatable {
@@ -108,7 +112,8 @@ enum FeatureAccessService {
108 trackedDomainLimit: 5, 112 trackedDomainLimit: 5,
109 workflowLimit: 1, 113 workflowLimit: 1,
110 batchSizeLimit: 10, 114 batchSizeLimit: 10,
111 activeAuditSessionLimit: 1 115 activeAuditSessionLimit: 1,
116 historyRetentionLimit: 50
112 ) 117 )
113 case .pro: 118 case .pro:
114 return FeatureEntitlements( 119 return FeatureEntitlements(
@@ -127,7 +132,8 @@ enum FeatureAccessService {
127 trackedDomainLimit: effectivelyUnlimitedTrackedDomains, 132 trackedDomainLimit: effectivelyUnlimitedTrackedDomains,
128 workflowLimit: nil, 133 workflowLimit: nil,
129 batchSizeLimit: nil, 134 batchSizeLimit: nil,
130 activeAuditSessionLimit: nil 135 activeAuditSessionLimit: nil,
136 historyRetentionLimit: 250
131 ) 137 )
132 case .proPlus: 138 case .proPlus:
133 return FeatureEntitlements( 139 return FeatureEntitlements(
@@ -136,11 +142,18 @@ enum FeatureAccessService {
136 trackedDomainLimit: effectivelyUnlimitedTrackedDomains, 142 trackedDomainLimit: effectivelyUnlimitedTrackedDomains,
137 workflowLimit: nil, 143 workflowLimit: nil,
138 batchSizeLimit: nil, 144 batchSizeLimit: nil,
139 activeAuditSessionLimit: nil 145 activeAuditSessionLimit: nil,
146 historyRetentionLimit: 2_000
140 ) 147 )
141 } 148 }
142 } 149 }
143 150
151 /// Snapshots this tier keeps. A downgrade lowers what the store may grow
152 /// to; it never prunes what is already there (Review Focus #6).
153 static var historyRetentionLimit: Int {
154 entitlements.historyRetentionLimit
155 }
156
144 static func hasAccess(to capability: FeatureCapability) -> Bool { 157 static func hasAccess(to capability: FeatureCapability) -> Bool {
145 entitlements.capabilities.contains(capability) 158 entitlements.capabilities.contains(capability)
146 } 159 }
DomainDig/SettingsViews.swift +1 −1
@@ -165,7 +165,7 @@ private struct HistoryNetworkSettingsView: View {
165 } 165 }
166 } 166 }
167 167
168 Text("History remains local-first. Auto-prune only trims older local snapshots on this device and defaults to unlimited.") 168 Text(viewModel.historyRetentionCaption)
169 .font(appDensity.font(.caption, design: .default)) 169 .font(appDensity.font(.caption, design: .default))
170 .foregroundStyle(Color(.appTextSecondary)) 170 .foregroundStyle(Color(.appTextSecondary))
171 } 171 }
DomainDigTests/DomainViewModelStoreTests.swift +91 −10
@@ -166,23 +166,104 @@ final class DomainViewModelStoreTests: XCTestCase {
166 XCTAssertEqual(viewModel.history.map(\.id), seeded.prefix(50).map(\.id)) 166 XCTAssertEqual(viewModel.history.map(\.id), seeded.prefix(50).map(\.id))
167 } 167 }
168 168
169 /// "Unlimited" is unlimited only up to the store's own hard cap. The 169 /// A store already over the cap must still be readable. Pruning happens on
170 /// setting has no bearing on that ceiling. 170 /// a write, not on a read, so loading must not drop rows.
171 func testTheHardCapAppliesEvenWhenPruningIsUnlimited() { 171 func testAStoreAlreadyOverTheCapLoadsEveryRow() {
172 DomainDataPortabilityService.saveHistoryEntries(makeEntries(300), defaults: scratch, historyLocation: historyLocation)
173
174 XCTAssertEqual(makeViewModel().history.count, 300)
175 }
176
177 // MARK: Retention
178
179 /// At or under the tier's limit, the ceiling a new snapshot is stored
180 /// under is simply that limit.
181 func testTheGrowthLimitIsTheTierLimitWhenUnderIt() {
182 let limit = FeatureAccessService.historyRetentionLimit
183 let viewModel = makeViewModel()
184
185 viewModel.history = []
186 XCTAssertEqual(viewModel.growthHistoryLimit, limit)
187
188 viewModel.history = makeEntries(limit)
189 XCTAssertEqual(viewModel.growthHistoryLimit, limit)
190 }
191
192 /// Review Focus #6. A lapsed Pro+ subscriber holds more snapshots than the
193 /// new tier allows, so the ceiling is what they hold — the store stops
194 /// growing without deleting anything, rather than draining to the lower
195 /// tier a row per lookup.
196 func testTheGrowthLimitNeverFallsBelowWhatIsHeld() {
197 let limit = FeatureAccessService.historyRetentionLimit
198 let viewModel = makeViewModel()
199 viewModel.history = makeEntries(limit + 200)
200
201 XCTAssertEqual(viewModel.growthHistoryLimit, limit + 200)
202 }
203
204 /// The user's own auto-prune choice may ask for less than the tier allows,
205 /// never more.
206 func testTheRequestedLimitIsClampedByTheTier() {
207 let limit = FeatureAccessService.historyRetentionLimit
208 let viewModel = makeViewModel()
209
210 viewModel.setHistoryAutoPruneOption(.keep50)
211 XCTAssertEqual(viewModel.requestedHistoryLimit, min(50, limit))
212
213 viewModel.setHistoryAutoPruneOption(.unlimited)
214 XCTAssertEqual(viewModel.requestedHistoryLimit, limit, "unlimited is the tier's limit, not unbounded")
215 }
216
217 /// The user asked, so this one is allowed to delete.
218 func testTheUsersAutoPruneChoiceIsAllowedToPrune() {
219 let viewModel = makeViewModel()
220 viewModel.history = makeEntries(120)
221
222 viewModel.setHistoryAutoPruneOption(.keep50)
223
224 XCTAssertEqual(viewModel.history.count, 50)
225 XCTAssertEqual(
226 DomainDataPortabilityService.loadHistoryIndex(
227 defaults: scratch,
228 historyLocation: historyLocation
229 ).count,
230 50
231 )
232 }
233
234 func testUnlimitedAutoPruneTrimsToTheTierLimit() {
235 let limit = FeatureAccessService.historyRetentionLimit
172 let viewModel = makeViewModel() 236 let viewModel = makeViewModel()
173 viewModel.history = makeEntries(300) 237 viewModel.history = makeEntries(limit + 50)
174 238
175 viewModel.setHistoryAutoPruneOption(.unlimited) 239 viewModel.setHistoryAutoPruneOption(.unlimited)
176 240
177 XCTAssertEqual(viewModel.history.count, 250) 241 XCTAssertEqual(viewModel.history.count, limit)
178 } 242 }
179 243
180 /// A store already over the cap must still be readable. Pruning happens on 244 // MARK: The Settings caption
181 /// a write, not on a read, so loading must not drop rows.
182 func testAStoreAlreadyOverTheCapLoadsEveryRow() {
183 DomainDataPortabilityService.saveHistoryEntries(makeEntries(300), defaults: scratch, historyLocation: historyLocation)
184 245
185 XCTAssertEqual(makeViewModel().history.count, 300) 246 /// The old copy said auto-prune "defaults to unlimited", which was never
247 /// true: there has always been a hard ceiling.
248 func testTheRetentionCaptionNamesTheLimitAndNotUnlimited() {
249 let viewModel = makeViewModel()
250 viewModel.history = []
251
252 let caption = viewModel.historyRetentionCaption
253
254 XCTAssertTrue(caption.contains("\(FeatureAccessService.historyRetentionLimit)"))
255 XCTAssertFalse(caption.lowercased().contains("unlimited"))
256 }
257
258 /// Over the limit the caption says nothing already saved is removed, which
259 /// is what the store actually does.
260 func testTheRetentionCaptionReassuresWhenOverTheLimit() {
261 let viewModel = makeViewModel()
262 viewModel.history = makeEntries(FeatureAccessService.historyRetentionLimit + 10)
263
264 let caption = viewModel.historyRetentionCaption
265
266 XCTAssertTrue(caption.contains("Nothing already saved is removed"))
186 } 267 }
187 268
188 // MARK: Tracking 269 // MARK: Tracking
DomainDigTests/FeatureAccessTests.swift +19
@@ -129,6 +129,25 @@ final class FeatureAccessTests: XCTestCase {
129 XCTAssertFalse(names.contains("dnsHistory")) 129 XCTAssertFalse(names.contains("dnsHistory"))
130 } 130 }
131 131
132 // MARK: Retention
133
134 /// The dial D1 settled on. These are the numbers the paywall promises and
135 /// the store enforces, so they are pinned here rather than inferred.
136 func testEachTierHasItsRetentionLimit() {
137 XCTAssertEqual(FeatureAccessService.entitlements(for: .free).historyRetentionLimit, 50)
138 XCTAssertEqual(FeatureAccessService.entitlements(for: .pro).historyRetentionLimit, 250)
139 XCTAssertEqual(FeatureAccessService.entitlements(for: .proPlus).historyRetentionLimit, 2_000)
140 }
141
142 func testRetentionRisesWithTheTier() {
143 let free = FeatureAccessService.entitlements(for: .free).historyRetentionLimit
144 let pro = FeatureAccessService.entitlements(for: .pro).historyRetentionLimit
145 let proPlus = FeatureAccessService.entitlements(for: .proPlus).historyRetentionLimit
146
147 XCTAssertLessThan(free, pro)
148 XCTAssertLessThan(pro, proPlus)
149 }
150
132 // MARK: Downgrade safety 151 // MARK: Downgrade safety
133 152
134 /// A lapsed subscriber keeps data above the new ceiling. Nothing may refuse 153 /// A lapsed subscriber keeps data above the new ceiling. Nothing may refuse