refactor(posts): route every library write through one rail
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
#179: every library-reflecting store write (draft save, session-born post, rename, move to project, archive/restore, trash, convert, project creation, import batch, pass advance) now rides one internal seam — performWrite pairs the write with exactly one rescan and owns the error strip (cleared BEFORE the write so importFiles' per-file failure messages survive the success tail; a nil-Home refusal writes nothing). The model owns the Home: watchedHome is private(set), set only by bind (construction + the Settings repoint); no public method takes a Home parameter — 14 view call sites and ~115 test call sites swept, dead home plumbing cut. The editor's debounced flush, the card closes, the pass substrate and the micropub publish stay off the rail by design (own error semantics, no library regroup). A converged review finding is closed with a guard: the pass advance re-resolves watchedHome after the engine's minutes-long turn, so a mid-pass Settings repoint now refuses the advance with an honest strip message instead of silently stamping pass state into the repointed library (wrong-piece write on a slug collision). createProject failures now surface in the sheet AND the strip — the rail-owns-the- strip posture supersedes the #108 sheet-only rule. Five rail pins (PostsModelWriteRailTests, suite members): write → one library refresh + strip cleared, failed write owns the strip, nil-Home refusal, import batch keeps per-file messages, mid-pass repoint refuses the advance — the last two flip-verified against their guards. ScriptedEngine gains endHeldPrompt (release a held turn as ended). Verification: suite 657/657 the evening this landed; the next-morning re-run could not start — both test runners hung before establishing connection (#134 testmanagerd wedge; an untouched control suite hangs identically — machine state, not this diff; reboot pending). Rail pins 5/5 isolated after the last test-only edit; swiftlint at baseline parity; swiftformat clean. Closes #179 [Generated by AI]
This commit is contained in:
1 parent
627ecf515e
commit
5bf09552f6
27 files changed
+572
-345
No files matched your search
@@ -19,7 +19,7 @@ extension PostsModel {
|
||||
/// engine's turn ends normally — never on cancel, refusal, or crash,
|
||||
/// and never when fix cards resolve. Passes run in any order
|
||||
/// (advancePassState is monotonic).
|
||||
func runPass(_ kind: PassKind, home: URL, mentor: MentorSessionModel) async {
|
||||
func runPass(_ kind: PassKind, mentor: MentorSessionModel) async {
|
||||
guard runningPass == nil, !runningBlindRead else {
|
||||
lastError = "A pass is already running."
|
||||
return
|
||||
@@ -53,6 +53,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 }
|
||||
do {
|
||||
try PostStore.snapshotPass(id: id, kind: kind, body: session.text, home: home)
|
||||
} catch {
|
||||
@@ -82,13 +84,18 @@ extension PostsModel {
|
||||
guard case let .ended(stopReason) = outcome, stopReason != "refusal" else {
|
||||
return // cancelled / refused / failed — the transcript tells the story
|
||||
}
|
||||
do {
|
||||
_ = try PostStore.advancePassState(id: id, kind: kind, home: home)
|
||||
lastError = nil
|
||||
Task { await rescan() } // the library regroups by Pass State
|
||||
} catch {
|
||||
lastError = error.localizedDescription
|
||||
// #179 audit: the engine ran for minutes — a Settings repoint since
|
||||
// the snapshot re-bound watchedHome to another library. Advancing
|
||||
// through the rail would stamp pass-state frontmatter onto THAT
|
||||
// library (an unrelated same-slug piece on collision — silently).
|
||||
// Refuse honestly; the snapshot stays in the pass's own library.
|
||||
guard watchedHome == home else {
|
||||
lastError = "The library changed while the pass ran — its Pass State was not advanced."
|
||||
return
|
||||
}
|
||||
// #179: the pass-advance write rides the rail — one rescan, and the
|
||||
// strip ownership is the rail's (the library regroups by Pass State).
|
||||
performWrite { try PostStore.advancePassState(id: id, kind: kind, home: $0) }
|
||||
}
|
||||
|
||||
/// #24 (S3.1): the pass bar's Cancel — the existing session/cancel
|
||||
@@ -109,7 +116,7 @@ extension PostsModel {
|
||||
/// advance, no cards, no Learnings — the verdict and the reveal live in
|
||||
/// the transient transcript and die with it. The writer stays judge of
|
||||
/// record.
|
||||
func blindRead(home: URL, mentor: MentorSessionModel) async {
|
||||
func blindRead(mentor: MentorSessionModel) async {
|
||||
guard runningPass == nil else {
|
||||
lastError = "A pass is already running."
|
||||
return
|
||||
@@ -138,7 +145,10 @@ extension PostsModel {
|
||||
return
|
||||
}
|
||||
guard flushOrAbort(id) else { return }
|
||||
guard let base = PostStore.latestPassSnapshot(id: id, home: home) else {
|
||||
// #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 {
|
||||
lastError = "No Pass snapshot yet — run a Pass first."
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user