feat(home): pin iCloud Home for fresh installs (#171)
CI / ci (push) Canceled after 0s
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:
1 parent
c485cfac60
commit
ad021b5267
10 files changed
+282
-34
No files matched your search
+31
-16
@@ -44,29 +44,44 @@ final class AppGateState {
|
||||
/// locked, `isFocused` cannot leave true (the ⌥⌘F refusal IS the
|
||||
/// lock), hover-reveal zones stay suppressed, and the kiosk holds.
|
||||
let writingLock = WritingLockState()
|
||||
/// #17: the Museion Home — repoint-only (ADR-0004). Defaults to
|
||||
/// `~/Documents/Museion`; UserDefaults is the persistence floor: a Home is
|
||||
/// a plain folder, nothing app-owned to put in a database. Non-file URLs
|
||||
/// read back as nil (the default wins) — the Home is always a folder.
|
||||
/// #17: the Museion Home — repoint-only (ADR-0004). #171: fresh installs
|
||||
/// resolve once through the ladder below and PIN the winner (UserDefaults
|
||||
/// is the persistence floor: a Home is a plain folder, nothing
|
||||
/// app-owned to put in a database). Non-file URLs read back as nil (the
|
||||
/// ladder wins) — the Home is always a folder.
|
||||
var museionHome: URL {
|
||||
didSet { UserDefaults.standard.set(museionHome.absoluteString, forKey: "museionHome") }
|
||||
didSet { Self.storeHome(museionHome, in: UserDefaults.standard) }
|
||||
}
|
||||
|
||||
init() {
|
||||
/// #171: fresh-install Home resolution — runs only when no stored
|
||||
/// override exists, then pins so the Home never silently moves (the
|
||||
/// ladder + probes live in HomeResolution.swift). Probes and defaults
|
||||
/// are injectable: hosted tests drive the ladder without touching the
|
||||
/// machine's real iCloud state or the runner's real defaults.
|
||||
/// `defaults` serves resolution + pin only — the repoint `didSet`
|
||||
/// always writes the real standard defaults.
|
||||
init(
|
||||
defaults: UserDefaults = .standard,
|
||||
legacyHomeExists: () -> Bool = { AppGateState.existingDirectory(AppGateState.defaultMuseionHome) != nil },
|
||||
cloudDocsDir: () -> URL? = AppGateState.liveCloudDocsDir,
|
||||
) {
|
||||
// Explicit init: `Self` in a stored-property initializer trips
|
||||
// @ObservationTracked's macro expansion (covariant Self).
|
||||
museionHome = UserDefaults.standard.string(forKey: "museionHome")
|
||||
.flatMap(URL.init(string:))
|
||||
.flatMap { $0.isFileURL ? $0 : nil }
|
||||
?? Self.defaultMuseionHome
|
||||
// #70: the six prose-typography slot defaults.
|
||||
if let stored = Self.fileHomeURL(in: defaults) {
|
||||
museionHome = stored
|
||||
return
|
||||
}
|
||||
// Default construction under hosted tests (WritingLockTests &
|
||||
// friends): skip the real probes and the pin alike.
|
||||
if Self.hostedTestRun, defaults === UserDefaults.standard {
|
||||
museionHome = Self.defaultMuseionHome
|
||||
return
|
||||
}
|
||||
let resolved = Self.resolvedInitialHome(legacyHomeExists: legacyHomeExists, cloudDocsDir: cloudDocsDir)
|
||||
museionHome = resolved
|
||||
Self.storeHome(resolved, in: defaults)
|
||||
}
|
||||
|
||||
/// The default Home, absent a stored override — `~/Documents/Museion`
|
||||
/// (b3daac9: Documents, not the account root; TCC note in ADR-0004).
|
||||
nonisolated static let defaultMuseionHome = FileManager.default.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent("Documents/Museion", isDirectory: true)
|
||||
|
||||
/// #151: the gateless launch check — arms the auto-fire chain, then
|
||||
/// runs the once-per-launch async check (`beginAutomaticCheck`'s
|
||||
/// `hasStarted` preserves #41's one-check-per-launch, first-window-only
|
||||
|
||||
Reference in new issue
Block a user