Skip to content

feat(v2): AppMonetizationKit audit M+N polish (closes #80) - #97

Merged
wei18 merged 1 commit into
mainfrom
feat/v2-audit-code-polish-2
May 22, 2026
Merged

wei18 merged 1 commit into
mainfrom
feat/v2-audit-code-polish-2

Conversation

@wei18

@wei18 wei18 commented May 22, 2026

Copy link
Copy Markdown
Owner

Closes #80. Resolves 5 Medium + 6 Nit findings from 2026-05-21 Code Reviewer audit. B1 + B2 already merged earlier.

Code Reviewer approved after one revision (M5 test fix; flip-guard technique used to verify M5 rule actually exercised). Review at meetings/2026-05-22_v2-audit-code-polish.review.md.

Highlights:

  • AdGate gains optional onPersistenceError closure (host-side Telemetry routing)
  • AdGate gains wall-clock tamper guard (lastSeenWallClock + 24h tolerance)
  • LiveStoreKit2IAPClient catalog-desync telemetry + em-dash placeholder
  • AdPresentationAnchor narrowed to UUID; resolver split into separate file
  • ProtocolShapeTests Sendable compile-time coverage

Public MonetizationCore surface stable (no new public types).

Test delta: AppMonetizationKit 82 → 87 (+5). SudokuKit 28/28 affected suites green.

Verification:

  • swift build clean both packages
  • Isolation audit: 1 import GoogleMobileAds (LiveAdMobBridge.swift)

Address all 5 Medium + 6 Nit findings from 2026-05-21 Code Reviewer audit
(B1 + B2 already merged in #73 + #71). Code Reviewer approved 2026-05-22
after one revision (test fix for M5 false-positive).

M1 — design ↔ code reconciliation
- docs/v2/design.md §How.3 removed misleading lastShownDate gating rule;
  clarified lastShownDate is recorded for telemetry only (matches code)

M2 — onPersistenceError closure
- AdGate.init(store:calendar:onPersistenceError:) — new optional closure
  parameter; MonetizationCore stays Telemetry-free, host wires the route
- Live wiring in SudokuKit/AppComposition/Live.swift fan-outs to Telemetry
- AdGate.mutate(_:) catch now invokes the closure (was a comment)
- Test: saveFailureSurfacesViaOnPersistenceError

M3 — empty displayPrice + catalog-desync telemetry
- LiveStoreKit2IAPClient: empty fallback now "—" (em-dash placeholder)
- New optional onCatalogDesync closure → Telemetry.errorOccurred

M4 — timezone-shift test
- AdGateLogicTests.dismissedTodayAcrossDateLineCrossing

M5 — system-clock-manipulation defense
- AdGateState.lastSeenWallClock: Date? (new optional field)
- AdGate.clockTamperTolerance = 24h
- shouldShowBanner refuses grace if now < lastSeen - tolerance
- Monotonic advance on show/dismiss/purchase paths
- LiveMonetizationStateStore CloudKit field add-via-write
- Tests: clockMovedBackwardsRefusesGraceAdvance (firstLaunch 2024-01-01),
  clockToleranceWithin24hStillShows (verified by flip-guard technique
  per Code Reviewer reject + revision)

N1 — AdPresentationAnchor narrowed AnyHashable → UUID; drop @unchecked
N2 — actor-vs-class re-eval deferred to post-v2.3.5 (noted)
N3 — AdPresentationAnchor resolver split into separate file (Foundation-
     only type vs UIKit/AppKit resolvers); enables future Linux exclude
N4 — LiveStoreKitBridge.transactionUpdates priority .background → .utility
N5 — FakeIAPClient single-consumer constraint — diagnostic tracking
     (purchaseUpdatesWasSubscribed) instead of crashing tests
N6 — ProtocolShapeTests.valueTypesRemainSendable compile-time Sendable
     coverage on AdGateState, IAPProduct, IAPPurchaseEvent variants,
     IAPPurchaseResult, AdBannerStatus, AdPresentationAnchor

Public surface stable: only optional init params + optional struct field
+ resolver file split. No SemVer-breaking additions.

Verification:
- AppMonetizationKit: 87/87 tests (was 82, +5)
- SudokuKit affected suites: 28/28 (HomeViewBanner saveCount assertion
  relaxed from == 1 → >= 1 per new wall-clock advance semantics)
- swift build clean both packages
- Isolation audit: 1 GoogleMobileAds import (LiveAdMobBridge.swift)

§未決 (impl-notes)
- M5 wall-clock advance writes on every shouldShowBanner — acceptable for
  v2; throttle in v2.x if CloudKit quota matters
- N5 Fake vs Live multi-subscriber semantics differ (diagnostic-only)
- AdPresentationAnchorRegistry still v2.2 backlog

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@wei18
wei18 merged commit 3a963de into main May 22, 2026
@wei18
wei18 deleted the feat/v2-audit-code-polish-2 branch May 22, 2026 13:20
wei18 added a commit that referenced this pull request May 23, 2026
…or registry) (#108)

3 deferred items from PR #97 (AppMonetizationKit M+N polish):

1. AdGate.advanceWallClock throttled to ≤1×/6h
   New lastPersistedWallClock actor var separate from cache high-water
   mark — throttle gates writes, not cache motion. Tamper-guard remains
   precise (cache still advances every call). +2 tests.

2. FakeIAPClient.purchaseUpdates() multi-subscriber fan-out
   [UUID: AsyncStream.Continuation] broadcaster guarded by
   OSAllocatedUnfairLock. Each call allocates fresh stream + UUID-keyed
   continuation; onTermination removes entry on cancel/finish. Dropped
   the precondition-style single-subscriber guard. +2 tests.

3. AdPresentationAnchorRegistry (NEW MonetizationCore actor)
   register/unregister/resolve/liveEntryCount + WindowRef weak box for
   Sendable safety. Foundation-only public surface; AdsAdMob casts at
   call site to UIWindow/NSWindow. +6 tests.

Leader-applied test fix: Registry tests originally compiled in
isolation but subagent's later edits adjusted the API to accept
WindowRef instead of raw AnyObject. Updated test call sites + cast
syntax to match the shipped API.

Verification:
- swift test: 97/97 (was 87, +10: 2 throttle + 2 fake + 6 registry)
- AppMonetizationKit isolation: still 1 import GoogleMobileAds hit
- swift build clean

Co-authored-by: Claude Opus 4.7 <[email protected]>
wei18 added a commit that referenced this pull request May 25, 2026
… v2.5 user-owned)

Plan.md was still tagged DRAFT/awaiting-v2.0-dispatch despite v2.0–v2.4
having fully shipped across ~15 PRs. Rewrite to align with code:

- Add §Status snapshot table (phase × status × PR refs, 75 @test count)
- Mark every step with [x]/[~]/[ ] + originating PR for traceability
- Add §Phase v2.4★ to backfill audit/polish work shipped after original
  plan (#97 #101 #102 #103 #106 #108 #109)
- Add steps v2.0.6 (anchor registry split) and v2.3.6.1
  (MonetizationStateController + ToastController)
- Correct existing step prose: StoreKitBridge symmetric split,
  RootView.init real 6-param signature with 4 optional slots,
  boot order via MonetizationBootCoordinator, AdMob isolation
  audit count = 2 files (protocol + live wrapper)
- Shrink §v2.5 to phase summary; defer detailed checklist to
  v2.5-readiness.md (single source of truth)
- Add §Decisions D-v2-01..06 capturing execution-phase decisions
  (AdMob v13/UMP v3, v11 ObjC API, macOS Noop, anchor registry,
  purchaseUpdates split, RootView optional slots)
- Add §下一動作 explicit user-owned next steps

340 → 275 lines.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
wei18 added a commit that referenced this pull request May 25, 2026
… v2.5 user-owned) (#130)

Plan.md was still tagged DRAFT/awaiting-v2.0-dispatch despite v2.0–v2.4
having fully shipped across ~15 PRs. Rewrite to align with code:

- Add §Status snapshot table (phase × status × PR refs, 75 @test count)
- Mark every step with [x]/[~]/[ ] + originating PR for traceability
- Add §Phase v2.4★ to backfill audit/polish work shipped after original
  plan (#97 #101 #102 #103 #106 #108 #109)
- Add steps v2.0.6 (anchor registry split) and v2.3.6.1
  (MonetizationStateController + ToastController)
- Correct existing step prose: StoreKitBridge symmetric split,
  RootView.init real 6-param signature with 4 optional slots,
  boot order via MonetizationBootCoordinator, AdMob isolation
  audit count = 2 files (protocol + live wrapper)
- Shrink §v2.5 to phase summary; defer detailed checklist to
  v2.5-readiness.md (single source of truth)
- Add §Decisions D-v2-01..06 capturing execution-phase decisions
  (AdMob v13/UMP v3, v11 ObjC API, macOS Noop, anchor registry,
  purchaseUpdates split, RootView optional slots)
- Add §下一動作 explicit user-owned next steps

340 → 275 lines.

Co-authored-by: Claude Opus 4.7 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2 audit (Code): umbrella for AppMonetizationKit M1–M5 + N1–N6

1 participant