fix(editor): Home repoint rides the departure gate; document identity is (Home, ID)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Settings committed the new Home and bind flipped watchedHome without departing the open session: the session's immutable target kept the OLD Home, a same-slug piece in the new library made the ID-only reselect return it, and autosave/Save/quit wrote the old library while structural operations resolved against the new one. #198's departure gate never saw this seam; a no-collision piece was torn down by the vanish path with its dirty buffer dropped. The gate runs BEFORE anything commits. PostsModel.repoint(to:) is a document departure through the same sessionMayDepart (all three legs: unanswered #67, failed flush, never-loaded retype — no parallel gate); on refusal nothing changes (preference, watchedHome, the session's (A, id) target, its buffer), on acceptance the departed piece's state dies with it. AppGateState.repointMuseionHome(to:) commits the preference and its persistence only after the gate; WorkspaceView's Settings binding routes through it and the root .task(id:) binds the model after that commit — the dumb binder. A refusal speaks the #198 reason the way #200's quit refusal does (hosted-guarded alert: no Posts strip is in sight from Settings). Nothing auto-reopens after an accepted repoint — the writer picks from the new list; the in-memory draft survives (no Home until first save; dropping it would drop the only copy). Document identity is (Home, ID) everywhere — EditorSession.targets is the pair, PostsModel.openSessionTargets the model-side question; every ID-only session comparison is retired: select's reselect no-op, openUnguarded, the structural rail (rename/trash/move/archive/ restore/unarchive + flushOrAbort), conversion, the pass guard (its answer now carries the Home it validated), Micropub's launch, the lock's arm/body reads. Async continuations re-validate identity at COMPLETION: refreshCards (launch and hop-back — the old ID-only guard let a scan from the previous library land its cards on the new library's same-slug piece) and rescan (the stale-Home verdict is hoisted: a scan that outlived a repoint applies nothing, not just the vanish check; the #67 disk read runs only for a session targeting the scan's own Home). scanPieceCards is the per-model injectable scanner the deterministic stale-scan pin needs. Tests: PostsModelRepointTests (7) move to the gated entry and go green (17/17 with PostsModelDepartureTests — the #198 matrix stays green and composes); the stale-scan pin's RED is a mutation check (completion guard reverted to ID-only → only that pin fails, cards → ["Hedging"]; restored byte-exact). The #179 mid-pass repoint pin drives the real Settings path now (repoint + bind). swiftformat 0/152, swiftlint 0.
This commit is contained in:
1 parent
bce6abb38b
commit
8b0d43aed8
12 files changed
+298
-72
No files matched your search
@@ -19,12 +19,13 @@ extension PostsModel {
|
||||
/// Read, named honestly whichever runner asks), the mentor not
|
||||
/// mid-reply with its engine ready, and an open SAVED piece (never a
|
||||
/// draft, the external guest, or a held #111 guard ask). The refusal
|
||||
/// lands in lastError naming the blocker; answers the open piece's id
|
||||
/// and session — the run's target — or nil (refused).
|
||||
func guardOpenPieceRun(
|
||||
_ action: String,
|
||||
mentor: MentorSessionModel,
|
||||
) -> (id: String, session: EditorSession)? {
|
||||
/// lands in lastError naming the blocker; answers the open piece's id,
|
||||
/// session and Home — the run's target — or nil (refused).
|
||||
/// brief-28: identity — the open session must target THIS library's
|
||||
/// selected piece (Home, ID); a session born under another Home never
|
||||
/// runs (its snapshot/stats/lint would land in the wrong library).
|
||||
// swiftlint:disable:next large_tuple
|
||||
func guardOpenPieceRun(_ action: String, mentor: MentorSessionModel) -> (id: String, session: EditorSession, home: URL)? {
|
||||
guard runningPass == nil else {
|
||||
lastError = "A pass is already running."
|
||||
return nil
|
||||
@@ -43,7 +44,9 @@ extension PostsModel {
|
||||
}
|
||||
guard let session,
|
||||
let id = session.postID,
|
||||
let home = watchedHome,
|
||||
id == selectedPostID,
|
||||
session.targets(postID: id, home: home), // brief-28
|
||||
draft == nil,
|
||||
externalSession == nil,
|
||||
outlineGuardPieceID == nil
|
||||
@@ -51,7 +54,7 @@ extension PostsModel {
|
||||
lastError = "Open a saved post to run \(action)."
|
||||
return nil
|
||||
}
|
||||
return (id, session)
|
||||
return (id, session, home)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +67,7 @@ extension PostsModel {
|
||||
/// and never when fix cards resolve. Passes run in any order
|
||||
/// (advancePassState is monotonic).
|
||||
func runPass(_ kind: PassKind, mentor: MentorSessionModel) async {
|
||||
guard let (id, session) = guardOpenPieceRun("a pass", mentor: mentor) else { return }
|
||||
guard let (id, session, home) = guardOpenPieceRun("a pass", mentor: mentor) else { return }
|
||||
// #137 (S4): the pass profile's provider has no key — name it and
|
||||
// point at Settings. Nothing has touched disk yet (the snapshot
|
||||
// comes after this guard).
|
||||
@@ -73,8 +76,8 @@ extension PostsModel {
|
||||
return
|
||||
}
|
||||
guard flushOrAbort(id) else { return } // the engine reads disk
|
||||
// #179: the model owns the Home; an open piece implies a bound one.
|
||||
guard let home = watchedHome else { return }
|
||||
// #179: the model owns the Home — the guard answered the session's
|
||||
// OWN library (brief-28 identity); every write below lands there.
|
||||
do {
|
||||
try PostStore.snapshotPass(id: id, kind: kind, body: session.text, home: home)
|
||||
} catch {
|
||||
@@ -137,12 +140,11 @@ extension PostsModel {
|
||||
/// the transient transcript and die with it. The writer stays judge of
|
||||
/// record.
|
||||
func blindRead(mentor: MentorSessionModel) async {
|
||||
guard let (id, session) = guardOpenPieceRun("a Blind Read", mentor: mentor) else { return }
|
||||
guard let (id, session, home) = guardOpenPieceRun("a Blind Read", mentor: mentor) else { return }
|
||||
guard flushOrAbort(id) else { return }
|
||||
// #179: the model owns the Home; an open piece implies a bound one.
|
||||
guard let home = watchedHome,
|
||||
let base = PostStore.latestPassSnapshot(id: id, home: home)
|
||||
else {
|
||||
// #179: the model owns the Home — the guard answered the session's
|
||||
// OWN library (brief-28 identity).
|
||||
guard let base = PostStore.latestPassSnapshot(id: id, home: home) else {
|
||||
lastError = "No Pass snapshot yet — run a Pass first."
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user