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
@@ -21,8 +21,9 @@ extension PostsModel {
|
||||
/// (the same window lastDraftWasOutline covers) — ONE disk read derives
|
||||
/// both. No watched home yet (pre-bind) = post: nothing to guard.
|
||||
/// #146: internal — `select` (PostsModel.swift) asks the guard.
|
||||
func isGuardedOutline(_ id: String, home: URL) -> Bool {
|
||||
guard let dir = PostStore.folder(of: id, home: home),
|
||||
func isGuardedOutline(_ id: String) -> Bool {
|
||||
guard let home = watchedHome,
|
||||
let dir = PostStore.folder(of: id, home: home),
|
||||
let text = try? String(contentsOf: dir.appendingPathComponent("post.md"), encoding: .utf8)
|
||||
else { return false }
|
||||
let type: Post.ContentType = if let known = posts.first(where: { $0.id == id })?.type {
|
||||
@@ -37,17 +38,17 @@ extension PostsModel {
|
||||
/// outliner never mounts, nothing drops); Outline = explicit consent,
|
||||
/// opens the outliner (saves normalize/drop as today). Cancel = back
|
||||
/// out (no session); the piece stays guarded on the next open.
|
||||
func openGuardedOutlineInProse(home: URL) {
|
||||
func openGuardedOutlineInProse() {
|
||||
guard let id = outlineGuardPieceID else { return }
|
||||
outlineGuardPieceID = nil
|
||||
proseOverridePostID = id // routing: prose until the next open
|
||||
openUnguarded(id, home: home)
|
||||
openUnguarded(id)
|
||||
}
|
||||
|
||||
func openGuardedOutlineAsOutline(home: URL) {
|
||||
func openGuardedOutlineAsOutline() {
|
||||
guard let id = outlineGuardPieceID else { return }
|
||||
outlineGuardPieceID = nil
|
||||
openUnguarded(id, home: home)
|
||||
openUnguarded(id)
|
||||
}
|
||||
|
||||
/// #111 (S7): the ask's Cancel — the held open dies (no session opens,
|
||||
@@ -64,7 +65,8 @@ extension PostsModel {
|
||||
/// explicit choice the ruling requires.
|
||||
/// #146: internal — `select` (PostsModel.swift) routes its tail through
|
||||
/// this one open body.
|
||||
func openUnguarded(_ id: String, home: URL) {
|
||||
func openUnguarded(_ id: String) {
|
||||
guard let home = watchedHome else { return }
|
||||
dismissExternal()
|
||||
if let session, session.postID != id {
|
||||
session.teardown(flushFirst: true)
|
||||
@@ -76,7 +78,7 @@ extension PostsModel {
|
||||
outlineGuardPieceID = nil // the open displaces any held ask
|
||||
selectedPostID = id
|
||||
wireSession()
|
||||
refreshCards(home: home) // #23: the newly opened piece's cards, now
|
||||
refreshCards() // #23: the newly opened piece's cards, now
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,12 +97,14 @@ extension PostsModel {
|
||||
/// The open session's text is the truth when the piece is open — disk
|
||||
/// lags the debounce, and a stale-clean read would drop the warning
|
||||
/// for prose typed since the last flush (#114 audit).
|
||||
func stageConversion(_ post: Post, home: URL) {
|
||||
func stageConversion(_ post: Post) {
|
||||
guard post.type == .outline else { return }
|
||||
let body: String = if let session, session.postID == post.id {
|
||||
session.text
|
||||
} else {
|
||||
} else if let home = watchedHome {
|
||||
PostStore.readBody(id: post.id, home: home) ?? ""
|
||||
} else {
|
||||
""
|
||||
}
|
||||
pendingConversion = PendingConversion(id: post.id, lossy: OutlineTree.parsesWithLoss(body))
|
||||
}
|
||||
@@ -110,40 +114,44 @@ extension PostsModel {
|
||||
pendingConversion = nil
|
||||
}
|
||||
|
||||
/// #114 audit: consent recheck — the sheet's warning covered the STAGED
|
||||
/// body; if the answer-time body went lossy behind the ask (foreign
|
||||
/// write, late edit) and the writer was never warned, Headings would
|
||||
/// drop unconsented prose.
|
||||
private func conversionWentLossyBehindAsk(_ pending: PendingConversion, headingsLadder: Bool) -> Bool {
|
||||
guard headingsLadder, !pending.lossy, let home = watchedHome,
|
||||
let body = PostStore.readBody(id: pending.id, home: home)
|
||||
else { return false }
|
||||
return OutlineTree.parsesWithLoss(body)
|
||||
}
|
||||
|
||||
/// #114 (S4): the answer. Flush-first when the piece is open (the
|
||||
/// transform reads disk), flip `type` + transform the body once, then
|
||||
/// reopen the session routed to prose — proseOverridePostID covers the
|
||||
/// rescan lag (lastDraftWasOutline's machinery, reversed). A piece that
|
||||
/// isn't open just converts; nothing else moves. One-way in v1.
|
||||
func convertToPost(headingsLadder: Bool, home: URL) {
|
||||
/// #179: the write rides the rail.
|
||||
func convertToPost(headingsLadder: Bool) {
|
||||
guard let pending = pendingConversion else { return }
|
||||
pendingConversion = nil
|
||||
guard flushOrAbort(pending.id) else { return }
|
||||
do {
|
||||
// The sheet's warning covered the STAGED body. If the
|
||||
// answer-time body went lossy behind the ask (foreign write,
|
||||
// late edit) and the writer was never warned, Headings would
|
||||
// drop unconsented prose — abort, nothing converted (#114 audit).
|
||||
if headingsLadder, !pending.lossy, let body = PostStore.readBody(id: pending.id, home: home), OutlineTree.parsesWithLoss(body) {
|
||||
lastError = "The outline changed since the sheet opened — nothing was converted."
|
||||
return
|
||||
}
|
||||
if conversionWentLossyBehindAsk(pending, headingsLadder: headingsLadder) {
|
||||
lastError = "The outline changed since the sheet opened — nothing was converted."
|
||||
return
|
||||
}
|
||||
performWrite { home in
|
||||
try PostStore.convert(id: pending.id, headingsLadder: headingsLadder, home: home)
|
||||
if session?.postID == pending.id {
|
||||
session?.teardown(flushFirst: false) // flushOrAbort already wrote
|
||||
session = nil
|
||||
proseOverridePostID = pending.id
|
||||
openUnguarded(pending.id, home: home)
|
||||
openUnguarded(pending.id)
|
||||
}
|
||||
if outlineGuardPieceID == pending.id {
|
||||
// Multi-window: the held #111 ask targets an outline that no
|
||||
// longer is — dismiss it as a cancel (the ask's own teardown).
|
||||
cancelOutlineGuard()
|
||||
}
|
||||
lastError = nil
|
||||
Task { await rescan() }
|
||||
} catch {
|
||||
lastError = error.localizedDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user