refactor(posts): route every library write through the write rail (#179)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
One internal seam (PostsModelRail.swift) now pairs every library verb store write with exactly one library rescan and owns the error strip: saveDraft, newPostFromSession, rename, trash, createProject, moveToProject, archivePost, restorePost, unarchiveProject, importFiles, convertToPost, and runPass pass-state advance (12 sites on this base; the pass snapshot/stats writes, the publish stamp, and the editor flush stay outside by design). The model owns the Home: boundHome is set by bind() alone (app construction + Settings repoint); every public verb lost its home: parameter (create post/outline/session-born, rename, move, archive, restore, trash, convert, project creation, import, select, cards, passes, blind read, publish). The three rail entries are railWrite/railWriteReturningReason/ railWriteKeepingStrip — deliberately NOT overloads: a shared base name let unlabeled trailing-closure calls resolve into the labeled non-generic entry (Swift binds trailing closures to labeled first parameters), silently bypassing the strip and the pairing. Views + 11 test files swept to the homeless signatures (160 sites). RED suite green: 3/3. Full unit suite: 654/654. Fixes #179
This commit is contained in:
1 parent
8c5ceffa3c
commit
06283b6287
23 files changed
+364
-363
No files matched your search
@@ -20,8 +20,12 @@ extension PostsModel {
|
||||
/// transitions — the piece-roots watcher already fires on cards/ writes.
|
||||
/// #122: the same pass also derives `openPieceHasSnapshot` (the Blind
|
||||
/// Read's base) — one detached read of the open piece's disk facts.
|
||||
func refreshCards(home: URL) {
|
||||
guard let id = session?.postID, let folder = PostStore.folder(of: id, home: home) else {
|
||||
/// #179: no Home parameter — the model's bound Home is the one target.
|
||||
func refreshCards() {
|
||||
guard let id = session?.postID,
|
||||
let home = boundHome,
|
||||
let folder = PostStore.folder(of: id, home: home)
|
||||
else {
|
||||
openPieceCards = []
|
||||
openPieceHasSnapshot = false
|
||||
return
|
||||
@@ -68,7 +72,7 @@ extension PostsModel {
|
||||
/// flags the card and touches no text. A failed close after a landed
|
||||
/// edit is reported via lastError, never silent.
|
||||
@discardableResult
|
||||
func applyCard(_ card: FixCardStore.StoredFixCard, home: URL) -> FixCardApplyOutcome {
|
||||
func applyCard(_ card: FixCardStore.StoredFixCard) -> FixCardApplyOutcome {
|
||||
guard card.status == .open else { return .refused("card already closed") }
|
||||
guard card.lane == .mechanical else { return .refused("demonstration cards close Done or Skip") }
|
||||
guard let session, let postID = session.postID else {
|
||||
@@ -86,30 +90,29 @@ extension PostsModel {
|
||||
} catch {
|
||||
lastError = "card close failed: \(error.localizedDescription)"
|
||||
}
|
||||
refreshCards(home: home)
|
||||
refreshCards()
|
||||
return .stale
|
||||
}
|
||||
guard session.adoptText(newText) else { return .refused(lastError ?? "write failed") }
|
||||
closeCard(card, status: .applied, home: home)
|
||||
closeCard(card, status: .applied)
|
||||
return .applied
|
||||
}
|
||||
|
||||
/// #25 (S3.3): Skip — not this instance. Closes the card recording
|
||||
/// NOTHING beyond the status flip (CONTEXT.md).
|
||||
func skipCard(_ card: FixCardStore.StoredFixCard, home: URL) {
|
||||
closeCard(card, status: .skipped, home: home)
|
||||
func skipCard(_ card: FixCardStore.StoredFixCard) {
|
||||
closeCard(card, status: .skipped)
|
||||
}
|
||||
|
||||
/// #25 (S3.3): Done — the writer rewrote the span themselves. Same
|
||||
/// flip, different terminal.
|
||||
func doneCard(_ card: FixCardStore.StoredFixCard, home: URL) {
|
||||
closeCard(card, status: .done, home: home)
|
||||
func doneCard(_ card: FixCardStore.StoredFixCard) {
|
||||
closeCard(card, status: .done)
|
||||
}
|
||||
|
||||
private func closeCard(
|
||||
_ card: FixCardStore.StoredFixCard,
|
||||
status: FixCardStore.StoredFixCard.Status,
|
||||
home: URL,
|
||||
) {
|
||||
guard let session else {
|
||||
lastError = "open the piece to work its cards"
|
||||
@@ -120,7 +123,7 @@ extension PostsModel {
|
||||
} catch {
|
||||
lastError = "card close failed: \(error.localizedDescription)"
|
||||
}
|
||||
refreshCards(home: home)
|
||||
refreshCards()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +143,7 @@ extension PostsModel {
|
||||
/// counter; the store guarantees the one-stamp rule). Touches no text
|
||||
/// and flushes nothing: this writes a Learning, not an edit.
|
||||
@discardableResult
|
||||
func promoteCard(_ card: FixCardStore.StoredFixCard, home: URL) -> FixCardPromoteOutcome {
|
||||
func promoteCard(_ card: FixCardStore.StoredFixCard) -> FixCardPromoteOutcome {
|
||||
guard card.promotedAt == nil else { return .refused("card already promoted") }
|
||||
guard let session else { return .refused("open the piece to work its cards") }
|
||||
do {
|
||||
@@ -149,7 +152,7 @@ extension PostsModel {
|
||||
lastError = "learning write failed: \(error.localizedDescription)"
|
||||
return .refused("learning write failed: \(error.localizedDescription)")
|
||||
}
|
||||
refreshCards(home: home)
|
||||
refreshCards()
|
||||
return .promoted
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user