test(posts): pin library write-rail seam (#179)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
RED: PostsModelRail skeleton (one internal seam pairing a library write with exactly one rescan + the error strip, three error routings) and the seam-observability suite. On the base every verb hand-copies the write-then-rescan-then-strip choreography, so nothing reaches the rail: executed 3 / failed 3, events [] at every verb. Fixes #179
This commit is contained in:
1 parent
627ecf515e
commit
8c5ceffa3c
3 files changed
+211
No files matched your search
@@ -171,6 +171,11 @@ final class PostsModel {
|
||||
/// Last failed-op message surfaced in the editor (nil = clean).
|
||||
/// #146: setter internal — the split-out domain extensions set it.
|
||||
var lastError: String?
|
||||
/// #179: rail observability — the write-rail suite drives every
|
||||
/// store-write verb and asserts one `.write` + one `.pairedRescan`
|
||||
/// each. Nil in production (no observer, no cost).
|
||||
@ObservationIgnored
|
||||
var onRailEvent: (@MainActor (PostsModelRailEvent) -> Void)?
|
||||
/// Home the watcher is bound to; also the rescan target.
|
||||
private var watchedHome: URL?
|
||||
private var watcher = PostsWatcher()
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// PostsModelRail.swift
|
||||
// Museion
|
||||
//
|
||||
// #179: the library write rail — ONE internal seam every library verb's
|
||||
// store write rides. The rail pairs the write with exactly ONE library
|
||||
// rescan and routes the failure; a verb that bypasses it is a silent
|
||||
// stale-library bug (the hand-copied write-then-rescan choreography this
|
||||
// file replaces). The editor's flush keeps its own posture outside the
|
||||
// rail (different error semantics, editor-owned — EditorSession), as do
|
||||
// the pass substrate's snapshot/stats writes (they never regroup the
|
||||
// library) and the publish stamp (wire-owned, deliberately quiet).
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// #179: rail observability — what the write-rail suite reads off the
|
||||
/// seam. `.write` = a verb's body rode the rail; `.pairedRescan` = the
|
||||
/// rail scheduled the verb's ONE rescan.
|
||||
enum PostsModelRailEvent: Equatable {
|
||||
case write
|
||||
case pairedRescan
|
||||
}
|
||||
|
||||
// MARK: Write rail (#179)
|
||||
|
||||
extension PostsModel {
|
||||
/// #179: the rail's default entry — strip-routed. The op runs the
|
||||
/// verb's store write FIRST, then its state updates (a throw leaves
|
||||
/// nothing half-updated); success clears the strip and pairs exactly
|
||||
/// one rescan, a throw routes the failure into the strip.
|
||||
@discardableResult
|
||||
func performLibraryWrite<T>(_ op: () throws -> T) -> T? {
|
||||
onRailEvent?(.write)
|
||||
do {
|
||||
let result = try op()
|
||||
lastError = nil
|
||||
pairRailRescan()
|
||||
return result
|
||||
} catch {
|
||||
lastError = error.localizedDescription
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/// #179: the reason-returning entry (project creation) — the sheet
|
||||
/// owns its inline reason and the strip behind the sheet must not
|
||||
/// double-message one error. Same ONE rescan on success.
|
||||
func performLibraryWrite(returningReason op: () throws -> Void) -> String? {
|
||||
onRailEvent?(.write)
|
||||
do {
|
||||
try op()
|
||||
pairRailRescan()
|
||||
return nil
|
||||
} catch {
|
||||
return error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
/// #179: the strip-keeping entry (the import batch) — per-file
|
||||
/// failures continue inside the op and the strip keeps the verb's own
|
||||
/// message; the rail only pairs the ONE rescan.
|
||||
func performLibraryWrite(keepingStrip op: () -> Void) {
|
||||
onRailEvent?(.write)
|
||||
op()
|
||||
pairRailRescan()
|
||||
}
|
||||
|
||||
/// #179: the ONE pairing point — a write through any verb is followed
|
||||
/// by exactly one rescan, pinned here and nowhere else.
|
||||
private func pairRailRescan() {
|
||||
onRailEvent?(.pairedRescan)
|
||||
Task { await rescan() }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user