feat(home): pin iCloud Home for fresh installs (#171)
CI / ci (push) Canceled after 0s

With no stored Home override, launch resolves once and PINS the
winner, so the Home never silently moves: a legacy
~/Documents/Museion directory wins (existing Homes migrate manually,
never silently), else <CloudDocs>/Museion when iCloud Drive is
present (dynamically resolved unprefixed path, plain FileManager —
no ubiquity entitlements, ADR-0009), else the silent Documents
fallback. Repoint-only stands (ADR-0004), zero mover code.

The ladder + probes live in HomeResolution.swift (own file —
MuseionApp.swift stays under the lint line cap); init takes an
injectable probe/defaults seam, and default constructions under
hosted tests take an early return so the runner app's real iCloud
state and defaults are never touched. 9 seam-driven tests replace
the old default-Home pin; implement + finish-audit reviews landed
the legacy-probe dir gate, the non-destructive hosted no-write
guard, and the flip-verified CloudDocs spelling pin.

Suite 628/628 (xcresult executed count). DOX: Museion/AGENTS.md,
MuseionTests/AGENTS.md, GLOSSARY.md; devlog + INDEX + CHANGELOG.

Closes #171

Co-Authored-By: Cipher <cipher@hermes.local>
This commit is contained in:
AlexKuceraandCipher committed 2026-11-05 13:10:44 +01:00
1 parent c485cfac60
commit ad021b5267
10 files changed
+282 -34

No files matched your search

@@ -0,0 +1,60 @@
# S1 — Default Museion Home flips to iCloud (CloudDocs), pinned once with legacy guard
> **Date:** 2026-11-05
> **Type:** issue
> **Reference:** [issue #171](https://git.babylondreams.de/AlexKucera/museion/issues/171) (resolution slice of #170/map #167, plain build slice for #145)
## Goal
Fresh installs resolve their Museion Home once through a legacy-guarded ladder and PIN the winner, so the Home never silently moves: (1) stored override (unchanged semantics — file URLs only), (2) legacy `~/Documents/Museion` directory → pin it (existing Homes migrate manually, never silently), (3) `<CloudDocs>/Museion` when iCloud Drive is present (dynamically resolved unprefixed path, plain FileManager — no ubiquity API, ADR-0009), (4) silent Documents fallback — no dialog, no rail pill. Repoint-only stands (ADR-0004); zero mover code.
## What Was Done
- `Museion/HomeResolution.swift` (new) — `extension AppGateState`: the ladder (`resolvedInitialHome(legacyHomeExists:cloudDocsDir:)`), `defaultMuseionHome` (legacy + fallback, unchanged path), `fileHomeURL(in:)` (stored-override read, file-URL gate), `liveCloudDocsDir()` → `existingDirectory(cloudDocsURL(under:))` (dir-gated probes), `cloudDocsURL(under:)` (the unprefixed path construction — spelling-pinned seam), `hostedTestRun`, `storeHome(_:in:)` (the one defaults write).
- `Museion/MuseionApp.swift` — `AppGateState.init` takes injectable `defaults` + probes; no stored override → resolve once → pin. Default construction under hosted tests takes an early return (legacy fallback Home): neither the real probes nor the pin run, so the runner app's real iCloud state and defaults are never touched (WritingLockTests/GatelessLaunchTests construct the model directly). File extracted to keep MuseionApp.swift at 398 lines (lint cap; WritingLockState precedent).
- `MuseionTests/PostLibraryTests.swift` — the old `home default is documents museion` pin re-pinned to the seam; 9 tests: ladder ×3 (legacy guard wins over iCloud, CloudDocs without legacy, silent fallback), `existingDirectory` dir-gate edges over temp paths, stored-override wins, non-file stored value falls through to ladder + pins, pin-once/never-silently-moves (legacy "appearing" after the pin doesn't move it), hosted no-write guard (`.standard` byte-unchanged across a default construction), CloudDocs path spelling.
- DOX: `Museion/AGENTS.md` (museionHome bullet — the ladder + seam), `MuseionTests/AGENTS.md` (PostLibraryTests line), `GLOSSARY.md` (Home definition: fresh installs pin CloudDocs; legacy always wins).
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Pin-once at init, explicit `storeHome` write | didSet doesn't fire in init; one shared write helper keeps the key + absoluteString shape single-sourced with the repoint didSet. |
| Legacy probe requires a DIRECTORY (`existingDirectory`), not bare `fileExists` | Spec says "EXISTS on disk", but a stray plain file is not a Home — "the Home is always a folder" invariant + the repo trust-boundary rule (guard mirrors sink shape exactly). A file at that path falls through to iCloud instead of pinning a broken Home. (Implement-close review catch.) |
| Hosted-test guard = early return, not a conditional pin | First shape skipped only the pin write; the finish/implement convergence showed probes still READ real iCloud state. The early return skips probes AND pin — satisfies the ticket's "never touch" literally and is simpler (no `!==` identity tangle in the pin condition). |
| Hosted no-write pin asserts `.standard` byte-unchanged, never a destructive remove | The first version removed the real key with a defer restore — the #33 save/restore-around-real-state pattern (finish-audit security + general converged finding). The unchanged-assertion fails exactly when a write occurs; a write requires key-absent + guard-gone, which is also the only harmful case (a write over an existing stored value can't happen — the stored branch returns first). |
| `cloudDocsURL(under:)` seam + spelling pin | The unprefixed path is the ticket's explicit "never a hard-coded `iCloud~` form" constraint and had zero coverage — a typo silently disables iCloud detection into the Documents fallback. (Finish-audit general catch.) |
| Injection: probes + defaults per-init params, not a probe struct | Three params, all driven by tests; a struct would be abstraction for one caller shape. |
| `defaultMuseionHome` kept, not renamed `legacyDefaultHome` | Still the fallback; shortest diff. |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Wrapped `if` condition list reflowed by swiftformat → swiftlint `opening_brace` | The #142 lesson (root AGENTS.md): formatter pushes the brace; don't fight it | Hoisted `hostedTestRun` helper → single-line condition |
| `museionHome = defaultMuseionHome` bare in instance init → "static member cannot be used on instance" | Static member needs `Self.` in instance context | `Self.defaultMuseionHome` |
| `defer { … }()` → "Consecutive statements on a line must be separated by ';'" | IIFE habit; defer takes a closure, no call | Dropped `()` |
| Path-spelling pin failed on EVERY tree | URL equality is string-based: `appendingPathComponent(_, isDirectory: true)` appends a trailing slash; the expected literal had none — the first "flip fail" was this bug, not the flip | Expectation built with the same `isDirectory: true`; gotcha filed to swift wiki (foundation-files rule 2, builder side) |
| Flip-run of the hosted no-write pin passed with the guard provably disabled | No observable write to the real domain occurs in this harness even with the guard off (fresh binary proven by the spelling flip firing); the feared hosted-write scenario doesn't reproduce here | Documented as flip-inert in this harness; the pin stays as the correct non-destructive observable (green on good tree; fails by construction when a write occurs) |
| `-only-testing` with stacked/free-function names matched zero tests, twice (exit 0 = vacuous green) | The known Swift Testing filter trap (names with spaces; stacked flags) | Tally check from xcresult caught it; full-suite runs used instead |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/HomeResolution.swift` | NEW — ladder, probes, hosted guard helper, defaults write (78 lines) |
| `Museion/MuseionApp.swift` | init: injectable seam, resolve-once-pin, hosted early return; didSet via storeHome (398 lines) |
| `MuseionTests/PostLibraryTests.swift` | 9 seam-driven Home-resolution tests replacing the old default pin |
| `Museion/AGENTS.md`, `MuseionTests/AGENTS.md`, `GLOSSARY.md` | DOX pass — ladder contract, test inventory, Home definition |
| `CHANGELOG.md` | [Unreleased] → Changed: home entry |
## Open Items & Next Steps
- [ ] The 5 pre-existing `XCTestConfigurationFilePath` probe sites can adopt `AppGateState.hostedTestRun` on next touch (deliberate next-touch; drive-by refactor avoided this session).
- [ ] The hosted no-write pin is flip-inert in this harness (no observable hosted write even guard-off); if a future environment makes hosted writes observable, the pin discriminates unchanged.
---
**Verification:** `xcodebuild -project Museion.xcodeproj -scheme Museion -destination 'platform=macOS' test` — **628/628 passed, 0 failed** (xcresult executed count, `/tmp/verify171.xcresult`); swiftlint clean on changed files; swiftformat idempotent on changed files. GitNexus impact LOW (0 upstream callers of `defaultMuseionHome`), detect-changes scoped to the expected symbols, analyze re-run. Implement-close review (standards + spec) and finish-audit fanout (ponytail 0 / security 1 Low fixed / general 2 nits fixed) both landed fixes; spelling pin flip-verified (fails with `iCloud~` prefix).
*Log written by write-log skill*
+1
View File
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
<!-- write-log: full-index -->
| Date | Type | File | Summary |
|------|------|------|---------|
| 2026-11-05 | issue | [20261105-issue171-default-home-icloud-pin-once-legacy-guard_log.md](20261105-issue171-default-home-icloud-pin-once-legacy-guard_log.md) | Fresh installs pin `<CloudDocs>/Museion` with a legacy-dir guard; injectable probe seam, 9 tests (#171) |
| 2026-11-04 | issue | [20261104-issue158-wayfinder-map-cold-turkey-closed_log.md](20261104-issue158-wayfinder-map-cold-turkey-closed_log.md) | #158: Cold Turkey map closed — frontier empty, build on main, hotkey fog parked; #140 ready to close |
| 2026-11-04 | issue | [20261104-issue166-preset-chips-cold-turkey-arm-bar_log.md](20261104-issue166-preset-chips-cold-turkey-arm-bar_log.md) | #166: preset chips ruled NO — typeable value + defaults + steppers cover arming; frontier now empty |
| 2026-11-04 | issue | [20261104-issue165-s5-1-tie-in-cold-turkey-block-first-draft-eligibility_log.md](20261104-issue165-s5-1-tie-in-cold-turkey-block-first-draft-eligibility_log.md) | #165: S5.1 tie-in ruled NO — capture stays pass-gated; revisit trigger parked in map Out of scope |