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
@@ -42,14 +42,14 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() } // #124: at rig creation — the child dies with the test, however it exits
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Pass Piece\n\nThe body under pass.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
// Wait for the bind rescan to surface the piece — the pass label reads
|
||||
// the library's title for it (the PostsModelTests poll pattern).
|
||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||
let snapshot = try String(contentsOf: piece.appendingPathComponent("passes/pass-1.md"), encoding: .utf8)
|
||||
@@ -73,9 +73,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Cancel Me\n\nStill first draft.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||
// Pre-pass is unconditional — the snapshot landed anyway.
|
||||
@@ -91,9 +91,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Refused\n\nAlso first draft.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let onDisk = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||
@@ -108,7 +108,7 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
await mentor.openSession()
|
||||
model.newPost() // draft staged — no folder exists
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
#expect(model.lastError?.contains("post") == true)
|
||||
// Nothing landed on disk — the draft never even materialized a folder.
|
||||
@@ -120,15 +120,15 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Held\n\nMid-pass.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let first = Task { await model.runPass(.pass1, home: home, mentor: mentor) }
|
||||
let first = Task { await model.runPass(.pass1, mentor: mentor) }
|
||||
for _ in 0 ..< 250 where model.runningPass == nil {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
#expect(model.runningPass == .pass1)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor) // one pass at a time
|
||||
await model.runPass(.pass1, mentor: mentor) // one pass at a time
|
||||
#expect(model.lastError?.contains("already running") == true)
|
||||
|
||||
model.cancelPass(mentor: mentor) // the pass bar's Cancel rail
|
||||
@@ -147,9 +147,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Held\n\nCancel me.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let run = Task { await model.runPass(.pass1, home: home, mentor: mentor) }
|
||||
let run = Task { await model.runPass(.pass1, mentor: mentor) }
|
||||
for _ in 0 ..< 250 where model.runningPass == nil {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Busy\n\nMentor chatting.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let chat = Task { await mentor.sendPrompt("just chatting") }
|
||||
for _ in 0 ..< 250 where !mentor.isStreaming {
|
||||
@@ -185,7 +185,7 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
}
|
||||
#expect(mentor.isStreaming)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
#expect(model.lastError?.contains("mid-reply") == true)
|
||||
// The guard fired before the snapshot — nothing on disk.
|
||||
#expect(!FileManager.default.fileExists(
|
||||
@@ -199,9 +199,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
let (model, home, mentor) = try makePassRig() // never opened — engine idle
|
||||
defer { mentor.shutdown() }
|
||||
let post = try PostStore.writeNew(body: "# Cold\n\nNo engine yet.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
#expect(model.lastError?.contains("isn't ready") == true)
|
||||
#expect(!FileManager.default.fileExists(
|
||||
@@ -214,10 +214,10 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Flush First\n\nOriginal.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
model.session?.edit("# Flush First\n\nEdited on the way.") // inside the debounce window
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||
let snapshot = try String(contentsOf: piece.appendingPathComponent("passes/pass-1.md"), encoding: .utf8)
|
||||
@@ -231,9 +231,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Free Order\n\nStraight to two.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
await model.runPass(.pass2, home: home, mentor: mentor)
|
||||
await model.runPass(.pass2, mentor: mentor)
|
||||
|
||||
let onDisk = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||
@@ -248,12 +248,12 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Stats Piece\n\nOne two three. Four five! Six?", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let onDisk = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||
@@ -275,9 +275,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Cancelled Stats\n\nOne two three. Four five!", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let onDisk = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||
@@ -295,12 +295,12 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# AI Piece\n\nMachine-born prose.", origin: .ai, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let onDisk = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||
@@ -326,12 +326,12 @@ struct DeslopLintWiringTests {
|
||||
let body = "# Lint Piece\n\nUtilize the index — and delve twice — notably once, and again — "
|
||||
+ "and again — and once more — to clear the dash budget. Utilize it twice."
|
||||
let post = try PostStore.writeNew(body: body, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
|
||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
let piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||
let cards = FixCardStore.scan(pieceURL: piece.appendingPathComponent("post.md"))
|
||||
|
||||
Reference in new issue
Block a user