Make the intelligence gate a named capability !12
merged
merged by cmc on 2026-10-24 05:44 UTC
· krz/domain-dig:intelligence-capability into main
6 files changed, +22 −23
Layout: unified · split
DomainDig/ContentView.swift
+1 −1
| @@ -436,7 +436,7 @@ struct ContentView: View { |
| 436 | 436 | IntelligenceSectionView( |
| 437 | 437 | isCollapsed: sectionCollapsedBinding(.intelligence), |
| 438 | 438 | report: report, |
| 439 | | showsPlaceholder: FeatureAccessService.currentTier != .proPlus |
| 439 | showsPlaceholder: !FeatureAccessService.hasAccess(to: .intelligenceDetail) |
| 440 | 440 | ) |
| 441 | 441 | } |
| 442 | 442 | |
DomainDig/DomainInsightEngine.swift
−17
| @@ -192,7 +192,6 @@ enum DomainInsightEngine { |
| 192 | 192 | tally.add(4, "Observed risk has increased materially since the previous snapshot", .negative) |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | | scoreReputation(snapshot, into: &tally) |
| 196 | 195 | |
| 197 | 196 | let clampedScore = min(max(tally.score, 0), 100) |
| 198 | 197 | let level: RiskLevel |
| @@ -330,19 +329,6 @@ enum DomainInsightEngine { |
| 330 | 329 | } |
| 331 | 330 | } |
| 332 | 331 | |
| 333 | | private static func scoreReputation(_ snapshot: LookupSnapshot, into tally: inout RiskTally) { |
| 334 | | guard let reputation = snapshot.reputation else { return } |
| 335 | | switch reputation.status { |
| 336 | | case .listed: |
| 337 | | let sourceList = reputation.listedSources.isEmpty ? "" : " (\(reputation.listedSources.joined(separator: ", ")))" |
| 338 | | tally.add(25, "Domain is flagged by a configured reputation source\(sourceList)", .negative) |
| 339 | | case .clean: |
| 340 | | tally.add(0, "Domain is clean against the configured reputation source", .positive) |
| 341 | | case .unknown: |
| 342 | | break |
| 343 | | } |
| 344 | | } |
| 345 | | |
| 346 | 332 | private static func insights( |
| 347 | 333 | for snapshot: LookupSnapshot, |
| 348 | 334 | previousSnapshot: LookupSnapshot?, |
| @@ -353,9 +339,6 @@ enum DomainInsightEngine { |
| 353 | 339 | ) -> [String] { |
| 354 | 340 | var items: [String] = [] |
| 355 | 341 | |
| 356 | | if snapshot.reputation?.status == .listed { |
| 357 | | items.append("Domain is flagged by a configured reputation source") |
| 358 | | } |
| 359 | 342 | if let group = subdomainGroups.first(where: { $0.label == "staging" || $0.label == "dev" }) { |
| 360 | 343 | items.append("Multiple \(group.label) subdomains suggest non-production environments are exposed") |
| 361 | 344 | } |
DomainDig/FeatureAccessService.swift
+5 −2
| @@ -31,6 +31,7 @@ enum FeatureCapability: String, CaseIterable, Identifiable { |
| 31 | 31 | case extendedSubdomains |
| 32 | 32 | case sharedPortfolios |
| 33 | 33 | case auditDepth |
| 34 | case intelligenceDetail |
| 34 | 35 | |
| 35 | 36 | var id: String { rawValue } |
| 36 | 37 | |
| @@ -58,6 +59,8 @@ enum FeatureCapability: String, CaseIterable, Identifiable { |
| 58 | 59 | return "Shared portfolios" |
| 59 | 60 | case .auditDepth: |
| 60 | 61 | return "Unlimited audits" |
| 62 | case .intelligenceDetail: |
| 63 | return "Intelligence detail" |
| 61 | 64 | } |
| 62 | 65 | } |
| 63 | 66 | } |
| @@ -169,7 +172,7 @@ enum FeatureAccessService { |
| 169 | 172 | case .workflows, .batchOperations, .automatedMonitoring, .localAlerts, .advancedExports, |
| 170 | 173 | .extendedSubdomains: |
| 171 | 174 | return "Available in Pro" |
| 172 | | case .sharedPortfolios, .auditDepth: |
| 175 | case .sharedPortfolios, .auditDepth, .intelligenceDetail: |
| 173 | 176 | return "Available in Pro+" |
| 174 | 177 | case .limitedTracking: |
| 175 | 178 | return "Tracking is limited on Free" |
| @@ -231,7 +234,7 @@ enum FeatureAccessService { |
| 231 | 234 | static func upgradePrompt(for capability: FeatureCapability) -> UpgradePromptContext { |
| 232 | 235 | let title: String |
| 233 | 236 | switch capability { |
| 234 | | case .sharedPortfolios, .auditDepth: |
| 237 | case .sharedPortfolios, .auditDepth, .intelligenceDetail: |
| 235 | 238 | title = "Available in Pro+" |
| 236 | 239 | default: |
| 237 | 240 | title = "Available in Pro" |
DomainDig/HistoryView.swift
+1 −1
| @@ -183,7 +183,7 @@ struct HistoryDetailView: View { |
| 183 | 183 | IntelligenceSectionView( |
| 184 | 184 | isCollapsed: .constant(false), |
| 185 | 185 | report: report, |
| 186 | | showsPlaceholder: FeatureAccessService.currentTier != .proPlus |
| 186 | showsPlaceholder: !FeatureAccessService.hasAccess(to: .intelligenceDetail) |
| 187 | 187 | ) |
| 188 | 188 | .padding(.top, 8) |
| 189 | 189 | DomainSectionView( |
DomainDig/PaywallView.swift
+2 −1
| @@ -10,7 +10,7 @@ struct PaywallView: View { |
| 10 | 10 | NavigationStack { |
| 11 | 11 | List { |
| 12 | 12 | Section { |
| 13 | | Text("Pro unlocks scale, background monitoring, alerts, exports, and extended subdomain discovery. Pro+ adds shared portfolios and unlimited audits.") |
| 13 | Text("Pro unlocks scale, background monitoring, alerts, exports, and extended subdomain discovery. Pro+ adds shared portfolios, unlimited audits, and the full intelligence breakdown.") |
| 14 | 14 | .font(appDensity.font(.body, design: .default)) |
| 15 | 15 | .foregroundStyle(Color(.appTextSecondary)) |
| 16 | 16 | .fixedSize(horizontal: false, vertical: true) |
| @@ -29,6 +29,7 @@ struct PaywallView: View { |
| 29 | 29 | Section("What Pro+ Unlocks") { |
| 30 | 30 | featureRow("Shared portfolios") |
| 31 | 31 | featureRow("Unlimited audit sessions") |
| 32 | featureRow("Intelligence detail") |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | 35 | Section("Subscription") { |
DomainDigTests/FeatureAccessTests.swift
+13 −1
| @@ -58,6 +58,7 @@ final class FeatureAccessTests: XCTestCase { |
| 58 | 58 | |
| 59 | 59 | XCTAssertFalse(pro.capabilities.contains(.sharedPortfolios)) |
| 60 | 60 | XCTAssertFalse(pro.capabilities.contains(.auditDepth)) |
| 61 | XCTAssertFalse(pro.capabilities.contains(.intelligenceDetail)) |
| 61 | 62 | } |
| 62 | 63 | |
| 63 | 64 | func testProLiftsTheAllowances() { |
| @@ -71,11 +72,22 @@ final class FeatureAccessTests: XCTestCase { |
| 71 | 72 | |
| 72 | 73 | // MARK: Pro+ |
| 73 | 74 | |
| 74 | | func testProPlusAddsSharedPortfoliosAndAuditDepth() { |
| 75 | func testProPlusAddsSharedPortfoliosAuditDepthAndIntelligence() { |
| 75 | 76 | let proPlus = FeatureAccessService.entitlements(for: .proPlus) |
| 76 | 77 | |
| 77 | 78 | XCTAssertTrue(proPlus.capabilities.contains(.sharedPortfolios)) |
| 78 | 79 | XCTAssertTrue(proPlus.capabilities.contains(.auditDepth)) |
| 80 | XCTAssertTrue(proPlus.capabilities.contains(.intelligenceDetail)) |
| 81 | } |
| 82 | |
| 83 | /// The intelligence breakdown was gated by a bare `currentTier != .proPlus` |
| 84 | /// in two view bodies, which no audit of the capability table could see. It |
| 85 | /// is a capability now so the table, the paywall and `enabledFeatureLabels` |
| 86 | /// all agree, and so a test like this one can exist at all. |
| 87 | func testIntelligenceDetailIsAProPlusCapability() { |
| 88 | XCTAssertFalse(FeatureAccessService.entitlements(for: .free).capabilities.contains(.intelligenceDetail)) |
| 89 | XCTAssertFalse(FeatureAccessService.entitlements(for: .pro).capabilities.contains(.intelligenceDetail)) |
| 90 | XCTAssertTrue(FeatureAccessService.entitlements(for: .proPlus).capabilities.contains(.intelligenceDetail)) |
| 79 | 91 | } |
| 80 | 92 | |
| 81 | 93 | /// The finding this table replaces: Pro+ cost twice Pro and its only |