refactor(posts): route every library write through one rail
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:
AlexKucera committed 2026-11-10 08:45:04 +01:00
1 parent 627ecf515e
commit 5bf09552f6
27 files changed
+572 -345

No files matched your search

+28 -28
View File
@@ -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"))