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
@@ -31,46 +31,46 @@ struct PostsModelWriteRailTests {
|
||||
// create post — the draft's first save is the write
|
||||
model.newPost()
|
||||
model.updateDraft("# Rail One\n")
|
||||
model.saveDraft(home: home)
|
||||
model.saveDraft()
|
||||
rail("saveDraft")
|
||||
|
||||
// session-born post
|
||||
_ = model.newPostFromSession(body: "# Rail Two\n", home: home)
|
||||
_ = model.newPostFromSession(body: "# Rail Two\n")
|
||||
rail("newPostFromSession")
|
||||
|
||||
// project creation (reason returns to the sheet; still railed)
|
||||
#expect(model.createProject(named: "essays", home: home) == nil)
|
||||
#expect(model.createProject(named: "essays") == nil)
|
||||
rail("createProject")
|
||||
|
||||
// move to project
|
||||
let movable = try PostStore.writeNew(body: "# Movables\n", home: home)
|
||||
model.moveToProject(movable, project: "essays", home: home)
|
||||
model.moveToProject(movable, project: "essays")
|
||||
rail("moveToProject")
|
||||
|
||||
// rename
|
||||
let toRename = try PostStore.writeNew(body: "# Rename Me\n", home: home)
|
||||
model.rename(toRename, to: "Renamed Title", home: home)
|
||||
model.rename(toRename, to: "Renamed Title")
|
||||
rail("rename")
|
||||
|
||||
// archive → restore (id survives both — one Post value drives them)
|
||||
let toArchive = try PostStore.writeNew(body: "# Archive Me\n", home: home)
|
||||
model.archivePost(toArchive, home: home)
|
||||
model.archivePost(toArchive)
|
||||
rail("archivePost")
|
||||
model.restorePost(toArchive, home: home)
|
||||
model.restorePost(toArchive)
|
||||
rail("restorePost")
|
||||
|
||||
// whole-project unarchive: an archived piece in "essays" restores
|
||||
// the project's other child (moved earlier) too
|
||||
let inProject = try PostStore.writeNew(body: "# In Project\n", project: "essays", home: home)
|
||||
model.archivePost(inProject, home: home)
|
||||
model.archivePost(inProject)
|
||||
rail("archivePost (project member)")
|
||||
model.unarchiveProject("essays", home: home)
|
||||
model.unarchiveProject("essays")
|
||||
rail("unarchiveProject")
|
||||
|
||||
// convert
|
||||
let outline = try PostStore.writeNew(body: "- one\n- two\n", type: .outline, home: home)
|
||||
model.stageConversion(outline, home: home) // staging asks, never writes
|
||||
model.convertToPost(headingsLadder: false, home: home)
|
||||
model.stageConversion(outline) // staging asks, never writes
|
||||
model.convertToPost(headingsLadder: false)
|
||||
rail("convertToPost")
|
||||
|
||||
// import batch — ONE paired rescan for the whole batch
|
||||
@@ -78,12 +78,12 @@ struct PostsModelWriteRailTests {
|
||||
.appendingPathComponent("rail-import-\(UUID().uuidString).md")
|
||||
try "# Imported\n".write(to: ext, atomically: true, encoding: .utf8)
|
||||
model.stageImport([ext])
|
||||
model.importFiles(origin: .writer, home: home)
|
||||
model.importFiles(origin: .writer)
|
||||
rail("importFiles")
|
||||
|
||||
// trash
|
||||
let toTrash = try PostStore.writeNew(body: "# Trash Me\n", home: home)
|
||||
model.trash(toTrash, home: home)
|
||||
model.trash(toTrash)
|
||||
rail("trash")
|
||||
|
||||
#expect(model.lastError == nil)
|
||||
@@ -97,7 +97,7 @@ struct PostsModelWriteRailTests {
|
||||
defer { mentor.shutdown() } // #124: the engine dies with the test
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Pass Piece\n", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
// Wait for the bind rescan to surface the piece (PassRunTests poll).
|
||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
@@ -105,27 +105,27 @@ struct PostsModelWriteRailTests {
|
||||
|
||||
var events: [PostsModelRailEvent] = []
|
||||
model.onRailEvent = { events.append($0) }
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
#expect(events == [.write, .pairedRescan])
|
||||
#expect(model.lastError == nil)
|
||||
}
|
||||
|
||||
/// #179: the failure pairing — a write that throws rides the rail
|
||||
/// once, pairs NO rescan (nothing changed on disk), and the strip owns
|
||||
/// the reason.
|
||||
/// once (`.write` + `.writeFailed`), pairs NO rescan (nothing changed
|
||||
/// on disk), and the strip owns the reason.
|
||||
@Test func `a failed write rides the rail once and pairs no rescan`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
var events: [PostsModelRailEvent] = []
|
||||
model.onRailEvent = { events.append($0) }
|
||||
let post = try PostStore.writeNew(body: "# Trashed Twice\n", home: home)
|
||||
|
||||
model.trash(post, home: home) // first: rides + pairs
|
||||
model.trash(post) // first: rides + pairs
|
||||
#expect(events == [.write, .pairedRescan])
|
||||
events.removeAll()
|
||||
|
||||
model.trash(post, home: home) // folder already gone → the write throws
|
||||
#expect(events == [.write])
|
||||
model.trash(post) // folder already gone → the write throws
|
||||
#expect(events == [.write, .writeFailed])
|
||||
#expect(model.lastError != nil)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user