Skip to content

refactor(persistence): inject per-app CK identifiers via PrivateCKConfig - #219

Merged
wei18 merged 1 commit into
mainfrom
refactor/persistence-ck-config
May 31, 2026
Merged

wei18 merged 1 commit into
mainfrom
refactor/persistence-ck-config

Conversation

@wei18

@wei18 wei18 commented May 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extract zoneName / subscriptionID from the Sudoku-hardcoded PrivateCKConstants into a new PrivateCKConfig value-type, injected at the LivePersistence / LivePrivateCKGateway boundary.
  • PrivateCKConfig.sudoku holds the original strings (com.wei18.sudoku.userZone + .changes); Sudoku's AppComposition.Live passes it explicitly.
  • Record-type names (SavedGame / PersonalRecord / MonetizationState) stay in PrivateCKConstants — they're scoped to each app's CKContainer and safe to share verbatim across apps.

Context — RFC

PR A of 3 preparing the repo to host a second app (Minesweeper) alongside Sudoku in the same workspace. See `meetings/2026-05-31_minesweeper-rfc.md` §5.1 for the full audit and §6 for the phasing.

  • PR A (this): PersistenceKit Config injection
  • PR B (next): AppMonetizationKit IAP/Ad ID injection
  • PR C (last): Minesweeper Tuist skeleton + new MinesweeperCoreKit / MinesweeperKit packages

Design notes

  • ckConfig: is required (no default): prevents a future Minesweeper composition root from silently binding to Sudoku's CKContainer zone via parameter omission. There is exactly ONE caller today; the diff cost is minimal.
  • nonisolated let ckConfig on the LivePersistence actor — required because monetizationStateStore() is already nonisolated. Safe: `PrivateCKConfig` is an immutable Sendable Equatable struct.
  • Param order in LivePrivateCKGateway.init: required `config:` first, defaulted `container:` second (CR nit applied).

Behavior preserved

  • Sudoku's CloudKit interaction is byte-identical: same zoneName / subscriptionID strings reach CKRecordZone.ID and CKDatabaseSubscription.
  • `ZoneProvisioningTests.sudokuConfigMatchesDesign` pins the strings against the design doc.

Test plan

  • `swift build --package-path Packages/PersistenceKit` — green
  • `swift test --package-path Packages/PersistenceKit` — 50/50 pass
  • `swift build --package-path Packages/SudokuKit` — green (downstream AppComposition compiles against new init)
  • CI: lint:swift_strict, iOS + macOS test suites, snapshot tests

Review

Reviewed by Code Reviewer subagent: APPROVE_WITH_NITS → param-order nit applied.

🤖 Generated with Claude Code

Extract `zoneName` / `subscriptionID` from `PrivateCKConstants` (Sudoku-
hardcoded) into a new `PrivateCKConfig` value-type injected at the
`LivePersistence` / `LivePrivateCKGateway` boundary. `PrivateCKConfig.sudoku`
holds the original strings — Sudoku's `AppComposition.Live` passes it
explicitly. Required (no default) so a second consumer (Minesweeper, planned
in `meetings/2026-05-31_minesweeper-rfc.md`) cannot accidentally bind to
Sudoku's CKContainer zone.

Record-type names (`SavedGame` / `PersonalRecord` / `MonetizationState`)
stay in `PrivateCKConstants` — they're scoped to each app's CKContainer
and thus safe to share verbatim across apps.

`LivePersistence.ckConfig` is `nonisolated let` so the existing
`nonisolated monetizationStateStore()` factory can read it without an
actor hop (PrivateCKConfig is Sendable Equatable).

PR A of 3 (PR B: AppMonetizationKit IDs; PR C: Minesweeper skeleton).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@wei18
wei18 merged commit f9d5a9b into main May 31, 2026
5 checks passed
@wei18
wei18 deleted the refactor/persistence-ck-config branch May 31, 2026 12:50
wei18 added a commit that referenced this pull request May 31, 2026
* refactor(monetization): inject per-app banner ad unit + IAP IDs

Move Sudoku-specific monetization identifiers out of AppMonetizationKit
into the Sudoku app's composition root (`AppComposition.Live`), so the
package can serve a second app (Minesweeper, planned in PR D / RFC
`meetings/2026-05-31_minesweeper-rfc.md`) without baking Sudoku's
ASC product ID and AdMob banner unit into its binary.

API changes
-----------
- `LiveStoreKit2IAPClient.init(onCatalogDesync:)`
  → `LiveStoreKit2IAPClient.init(knownProductIds:onCatalogDesync:)`
  Required `knownProductIds:` (no default) prevents Minesweeper from
  silently inheriting Sudoku's `com.wei18.sudoku.iap.remove_ads` via
  arg omission.
- `LiveAdMobAdProvider.init()` → `LiveAdMobAdProvider.init(bannerAdUnitID:)`
- `LiveAdMobBridge.init()` → `LiveAdMobBridge.init(bannerAdUnitID:)`
  (internal — only `LiveAdMobAdProvider` constructs it)

The Sudoku-only `IAPProductIDs` enum stays as an internal test fixture
(in-package tests reference it as the canonical value). Production no
longer reads it; `AppComposition.Live` spells out the literal IDs.

Release-safety relocation
-------------------------
The `#if DEBUG / #else fatalError` swap point for the Sudoku banner ad
unit ID moves from a module-level computed `var` in `LiveAdMobBridge`
to an immediately-invoked closure inside the `#if os(iOS)` branch of
`AppComposition.Live`. Two semantic shifts worth flagging:
  * Crash timing: was lazy (first ad load); now eager (composition-root).
    Misconfigured Release builds fail at launch instead of mid-session —
    surfaces on smoke test, not in user gameplay. Net positive.
  * Per-platform: macOS direct builds skip the closure entirely (they
    use NoopAdProvider), preserving the existing macOS behaviour.

PR B of 4 (A: persistence config #219 ✓ ; B: this; C: rename App/ →
Sudoku/ + Workspace.swift; D: Minesweeper skeleton + new packages).

Reviewed by Code Reviewer subagent: APPROVE_WITH_NITS → 2 doc-comment
nits applied.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* ci(swiftlint): convert pre-existing TODO to issue ref (#221)

The TODO at LiveAdMobBridge.swift:92 was pre-existing (not introduced
by this PR), but the strict swiftlint check runs only on changed files,
so this PR's touch surfaced it as a violation. Filed #221 to track the
`dispose(handle:)` work and converted the comment to an issue ref.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
wei18 added a commit that referenced this pull request May 31, 2026
* refactor(tuist): rename App/ → Sudoku/, project Sudoku → Game

Prep for hosting a second app (Minesweeper, planned in PR D / RFC
`meetings/2026-05-31_minesweeper-rfc.md`) as a sibling target under
the same Tuist project umbrella. The Sudoku TARGET keeps its name,
bundle id `com.wei18.sudoku`, and scheme; only the umbrella project
becomes `Game` and the app's source/resource dir becomes `Sudoku/`.

Path renames
------------
- App/                → Sudoku/                (all 11 contents move via git mv)
- Project.swift `App/X` paths → `Sudoku/X`     (5 occurrences)
- license_plist.yml outputPath                 (App/Resources → Sudoku/Resources)
- .gitignore Settings.bundle entry             (same rename)

Project rename
--------------
- `Project(name: "Sudoku")` → `Project(name: "Game")`
- Generated artifacts: Sudoku.xcodeproj → Game.xcodeproj, similarly .xcworkspace
- Heads-up: Xcode Cloud workflows in App Store Connect reference the
  .xcworkspace path → needs user reconfig post-merge (user-owned).
- Local Xcode "Open Recent" entries break for everyone (acceptable).

Doc comment updates
-------------------
.mise.toml / ci_scripts/ci_post_clone.sh / Packages/SudokuKit/Package.swift
/ Packages/SudokuKit/Tests/AppCompositionTests/{L10nTests,PrivacyManifestTests}.swift
— all reference the path or generated artifact name.

LiveAdMobBridge.swift comments mentioning `App/Info.plist` are intentionally
NOT touched here (PR B deletes those lines as part of the Monetization
config refactor — resolving on rebase rather than touching the same lines
in two PRs).

Verification
------------
- `tuist generate --no-open` → produces `Game.xcodeproj` + `Game.xcworkspace`
- `tuist build Sudoku --platform iOS` → Build Succeeded

PR C of 4 (A: persistence config #219 ✓ ; B: monetization config #220 ⏳ ;
C: this; D: Minesweeper skeleton + new packages).

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* docs: address CR misses (README, ci_post_clone, symlink wording)

Three follow-ups to PR C's rename sweep flagged by Code Reviewer:

1. README.md L6/L28/L51 — three stale `App/` references in user-facing
   doc updated to `Sudoku/` + line 51 mentions Game umbrella for future
   Minesweeper sibling.
2. ci_scripts/ci_post_clone.sh L37 — workspace name reference
   `Sudoku.xcworkspace` → `Game.xcworkspace`.
3. Packages/SudokuKit/Package.swift L170 + L10nTests.swift / L10nCompletenessTests.swift /
   PrivacyManifestTests.swift comments — claim "via symlinks under
   Resources/" was stale; actual implementation uses literal copies
   (with `.xcstrings` → `.json` extension hack so the xcstrings
   compiler skips it). Corrected.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
wei18 added a commit that referenced this pull request May 31, 2026
…ackages (#223)

* feat(minesweeper): add app target skeleton + MinesweeperCoreKit/Kit packages

Closes the 4-PR Minesweeper-prep arc (A: persistence config #219 ✓; B:
monetization config #220 ✓; C: rename + project→Game #222 ✓; D: this).

Adds a second app target `Minesweeper` (bundleId `com.wei18.minesweeper`)
inside the existing Game project, plus two new local SwiftPM packages
mirroring the Sudoku{CoreKit,Kit} shape:

- `Packages/MinesweeperCoreKit/` — pure-Swift game core, single module
  `MinesweeperEngine` (placeholder `public struct`) + smoke test
- `Packages/MinesweeperKit/` — UI + composition, modules `MinesweeperUI`
  (placeholder `MinesweeperRootView` "Hello, Minesweeper" screen) and
  `MinesweeperAppComposition` (`bootRootView()` factory)

App target dir `Minesweeper/` mirrors `Sudoku/`:
- `MinesweeperApp.swift` (@main → `MinesweeperAppComposition.bootRootView()`)
- `Info.plist` (no AdMob keys yet)
- `Minesweeper.entitlements` — separate iCloud container
  `iCloud.com.wei18.minesweeper`, app-sandbox, GameKit
- `Assets.xcassets/` — placeholder (copied from Sudoku; flip when
  Minesweeper has its own AppIcon art)
- `Resources/Localizable.xcstrings` — empty `en` catalog
- `Resources/PrivacyInfo.xcprivacy` — copied verbatim from Sudoku
  (anticipates AdMob wiring; revisit when monetization actually lands)
- `Minesweeper.xctestplan` — pointed at `MinesweeperEngineTests` only

`Project.swift`:
- Adds `minesweeperTarget` (same `appTargetSettings` icon-name override)
- Adds `Packages/MinesweeperKit` to `packages:`
- Adds Minesweeper scheme alongside the existing Sudoku scheme

Module names (`MinesweeperEngine` / `MinesweeperUI` / `MinesweeperAppComposition`)
are namespaced to avoid colliding with SudokuCoreKit's `GameState` and
SudokuKit's `SudokuUI` / `AppComposition` in the same Xcode project's
package graph.

Verified
--------
- `tuist generate --no-open` → produces `Game.xcworkspace` with both schemes
- `tuist build Sudoku --platform iOS` → green (regression)
- `tuist build Minesweeper --platform iOS` → green
- `swift test --package-path Packages/MinesweeperCoreKit` → 1/1 pass

Follow-ups (filed as separate work, NOT part of this skeleton)
- Provision `iCloud.com.wei18.minesweeper` CloudKit container in Dashboard
- Wire Minesweeper's own AdMob banner + IAP product IDs (consumes the
  PR B parameterization)
- Wire `LivePersistence` with a `PrivateCKConfig.minesweeper` constant
  (consumes the PR A parameterization)
- Replace placeholder MinesweeperEngine with real mine placement +
  flood-fill + win/lose detection
- Replace placeholder AppIcon with Minesweeper art

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* docs(minesweeper): address CR nits

1. PrivacyInfo.xcprivacy header — prepend Minesweeper PR D context note
   explaining the verbatim copy + flip condition (no XML change).
2. MinesweeperEngine.swift — drop unused `internal import Foundation`.
3. Project.swift header — generalize the bundle-id / deployment-target
   bullet to cover both Sudoku and Minesweeper targets.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
wei18 added a commit that referenced this pull request Jun 3, 2026
…zone/subscription namespace (#257)

Mini-PR ahead of MS monetization wire Phase 3 (per
meetings/2026-06-02_minesweeper-monetization-wire-proposal.md §Phase 3
prerequisite). PR #219's per-app injection pattern for `PrivateCKConfig`
already supported this; now adds the Minesweeper counterpart.

- `PrivateCKConfig.minesweeper`:
  - `zoneName: "com.wei18.minesweeper.userZone"`
  - `subscriptionID: "com.wei18.minesweeper.userZone.changes"`
- CKContainer itself (`iCloud.com.wei18.minesweeper`) resolved by
  `CKContainer.default()` from the Minesweeper App target's
  entitlements — not encoded in PersistenceKit
- Sentinel test `minesweeperConfigUsesDistinctNamespace` confirms
  zone+subscription IDs are distinct from `.sudoku`

User has already provisioned the MS CK container on Apple Developer
portal + bound to the MS App ID (audit U4, 2026-06-02). MS production
schema deploy is a separate user task post-Phase-3 ship.

Subagent stalled at verification phase; Leader applied + verified
(4/4 PersistenceTests pass).

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.

1 participant