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

+8 -8
View File
@@ -51,7 +51,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
let chatBefore = rig.mentor.host.chat
let rosterBefore = rig.mentor.roster.count
let post = try PostStore.writeNew(body: "# Own Engine\n\nVerdict me.", home: rig.home)
rig.model.select(post.id, home: rig.home)
rig.model.select(post.id)
for _ in 0 ..< 250 where !rig.model.posts.contains(where: { $0.id == post.id }) {
try await Task.sleep(nanoseconds: 20_000_000)
}
@@ -59,7 +59,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
// In a Task — a full-mode scripted pass can complete inside one poll
// sleep (no child-process latency anymore), so the pass ENGINE is
// captured after the run from the spawn records, not polled mid-flight.
let run = Task { await rig.model.runPass(.pass1, home: rig.home, mentor: rig.mentor) }
let run = Task { await rig.model.runPass(.pass1, mentor: rig.mentor) }
_ = await run.value
let passEngine = rig.engines.engines.last { $0.spawnedProfile == "museion-pass1" }
let passEngineClosed = try #require(passEngine, "pass engine never spawned")
@@ -104,9 +104,9 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
await rig.mentor.openSession()
let rosterBefore = rig.mentor.roster.count
let post = try PostStore.writeNew(body: "# Held Pass\n\nCancel me.", home: rig.home)
rig.model.select(post.id, home: rig.home)
rig.model.select(post.id)
let run = Task { await rig.model.runPass(.pass1, home: rig.home, mentor: rig.mentor) }
let run = Task { await rig.model.runPass(.pass1, mentor: rig.mentor) }
let heldEngine = try #require(await pollOneShot(of: rig.mentor), "pass engine never spawned")
#expect(rig.mentor.isPassEngineRunning)
@@ -291,7 +291,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
rig.mentor.passReadinessWriter = writer
await rig.mentor.refreshPassReadiness()
let post = try PostStore.writeNew(body: "# No Key\n\nPass me.", home: rig.home)
rig.model.select(post.id, home: rig.home)
rig.model.select(post.id)
for _ in 0 ..< 250 where rig.model.session?.postID != post.id {
try await Task.sleep(nanoseconds: 20_000_000)
}
@@ -299,7 +299,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
// this pin vacuously.
try #require(rig.model.session?.postID == post.id)
await rig.model.runPass(.pass1, home: rig.home, mentor: rig.mentor)
await rig.model.runPass(.pass1, mentor: rig.mentor)
#expect(rig.model.lastError == "Pass 1 needs a z.ai API key — add it in Settings → Provider Keys.")
let piece = rig.home.appendingPathComponent("projects/posts/\(post.id)")
@@ -320,7 +320,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
_ = await rig.mentor.newSession(name: "Second", pieceTitle: nil) // sess-2 active
let target = try #require(rig.mentor.roster.last) // sess-1, NOT active
let post = try PostStore.writeNew(body: "# Held Load\n\nResume races a pass.", home: rig.home)
rig.model.select(post.id, home: rig.home)
rig.model.select(post.id)
for _ in 0 ..< 250 where !rig.model.posts.contains(where: { $0.id == post.id }) {
try await Task.sleep(nanoseconds: 20_000_000)
}
@@ -338,7 +338,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
// pass prompt then HOLDS, so isStreaming is guaranteed when the parked
// load completes, and the #124 Cancel rail frees it afterwards.
rig.engines.mode = "hangOnPrompt"
let run = Task { await rig.model.runPass(.pass1, home: rig.home, mentor: rig.mentor) }
let run = Task { await rig.model.runPass(.pass1, mentor: rig.mentor) }
for _ in 0 ..< 250 where !rig.mentor.isPassEngineRunning {
try await Task.sleep(nanoseconds: 20_000_000)
}