refactor(posts): route every library write through one rail
CI / ci (push) Canceled after 0s
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:
1 parent
627ecf515e
commit
5bf09552f6
27 files changed
+572
-345
No files matched your search
@@ -39,7 +39,7 @@ Conventions every suite follows. Per-suite pin inventories are NOT kept here —
|
||||
- `MicropubTests`, `MicropubModelTests`, `MicropubMediaTests` — publish wire contract, model flow, media/illustration surface.
|
||||
- `MCPToolsTests`, `MCPServerWireTests`, `MCPToolsPromoteTests`, `ToolPayloadsTests`, `LearningsPaneTests`, `LearningDecayTests` — museion-tools store, wire, promote, tool-payload decoder shapes (strict + lenient, #177), learnings pane, decay.
|
||||
- `FixCardApplyTests` — fix-card apply/skip/done lifecycle.
|
||||
- `PostsModelTests`, `PassRunTests`, `BlindReadTests`, `EngineLifecycleTests`, `SessionLifecycleTests`, `SessionScopeTests`, `TranscriptRailTests` — model orchestration over the scripted in-process engine (#178): passes, blind read, per-surface engines, session lifecycle, scoped hosting, the typed transcript rail (#177 — speaker/notice type facts through the scripted engine, prefix-free invariant, append-seam classifiers).
|
||||
- `PostsModelTests`, `PassRunTests`, `BlindReadTests`, `EngineLifecycleTests`, `SessionLifecycleTests`, `SessionScopeTests`, `TranscriptRailTests` — model orchestration over the scripted in-process engine (#178): passes, blind read, per-surface engines, session lifecycle, scoped hosting, the typed transcript rail (#177 — speaker/notice type facts through the scripted engine, prefix-free invariant, append-seam classifiers), and the #179 write-rail pins in PostsModelTests (write → one library refresh + strip cleared; failed write owns the strip; nil-Home refuses cleanly; import batch keeps per-file strip messages; mid-pass Home repoint refuses the advance — `endHeldPrompt` is the rig hook that ends a held turn normally).
|
||||
- `DeslopLintTests` (with the `DeslopLintWiringTests` member) — native lint findings, config story, emit loop.
|
||||
- `EditorSessionTests`, `ReadingPresenterTests`, `ProsePresenterTests`, `FocusModeTests`, `ImportExternalTests`, `ImageIngestTests` — editor session, reading pipeline, editing-surface parity, focus math, import + image ingest.
|
||||
- `OutlineTreeTests`, `OutlinePresenterTests`, `OutlineDragTests`, `EscEventProbeTests` — outliner model, projection, drag plumbing, Esc delivery probe.
|
||||
|
||||
@@ -117,7 +117,7 @@ struct BlindReadTests {
|
||||
private func openJudgedPiece(on model: PostsModel, home: URL, snapshot: String, current: String) async throws -> String {
|
||||
let post = try PostStore.writeNew(body: current, home: home)
|
||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: snapshot, 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)
|
||||
}
|
||||
@@ -199,14 +199,14 @@ struct BlindReadTests {
|
||||
await rig.mentor.openSession()
|
||||
_ = try await openJudgedPiece(on: rig.model, home: rig.home, snapshot: "Older prose.", current: "Newer prose.")
|
||||
|
||||
let run = Task { await rig.model.blindRead(home: rig.home, mentor: rig.mentor) }
|
||||
let run = Task { await rig.model.blindRead(mentor: rig.mentor) }
|
||||
for _ in 0 ..< 250 where !rig.model.runningBlindRead {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
#expect(rig.model.runningBlindRead)
|
||||
|
||||
// Mutual exclusion — a pass refuses while the read owns the rail.
|
||||
await rig.model.runPass(.pass1, home: rig.home, mentor: rig.mentor)
|
||||
await rig.model.runPass(.pass1, mentor: rig.mentor)
|
||||
#expect(rig.model.lastError?.contains("already running") == true)
|
||||
|
||||
// The pass bar's Cancel rail ends the held read — no reveal,
|
||||
@@ -237,7 +237,7 @@ struct BlindReadTests {
|
||||
snapshot: "MARKER-the-older-text", current: "# Judged\n\nMARKER-the-newer-text",
|
||||
)
|
||||
|
||||
await rig.model.blindRead(home: rig.home, mentor: rig.mentor)
|
||||
await rig.model.blindRead(mentor: rig.mentor)
|
||||
|
||||
// The prompt carried BOTH bodies inline — and no path: the judge
|
||||
// cannot learn which file is which (the engines' prompt log).
|
||||
@@ -262,20 +262,20 @@ struct BlindReadTests {
|
||||
defer { rig.mentor.shutdown() }
|
||||
await rig.mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Fresh\n\nNo pass yet.", 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)
|
||||
}
|
||||
|
||||
// No pass ever ran — refuse, spawn nothing beyond the resident engine.
|
||||
await rig.model.blindRead(home: rig.home, mentor: rig.mentor)
|
||||
await rig.model.blindRead(mentor: rig.mentor)
|
||||
#expect(rig.model.lastError?.contains("run a Pass") == true)
|
||||
#expect(museionSpawns(rig) == 1)
|
||||
|
||||
// Snapshot exists but the document is unchanged since — a vacuous
|
||||
// read refuses honestly.
|
||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: "# Fresh\n\nNo pass yet.", home: rig.home)
|
||||
await rig.model.blindRead(home: rig.home, mentor: rig.mentor)
|
||||
await rig.model.blindRead(mentor: rig.mentor)
|
||||
#expect(rig.model.lastError?.contains("No edits") == true)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ struct EngineSmokeTests {
|
||||
await mentor.openSession() // the resident chat engine
|
||||
let chatPid = try #require(mentor.childProcessIdentifier)
|
||||
let post = try PostStore.writeNew(body: "# Smoke Pass\n\nVerdict me.", 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)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ struct EngineSmokeTests {
|
||||
// In a Task — the pass child's pid is only observable while it runs
|
||||
// (the old EngineLifecycleTests poll; the zsh wire latency holds the
|
||||
// turn open long enough to catch it).
|
||||
let run = Task { await model.runPass(kind, home: home, mentor: mentor) }
|
||||
let run = Task { await model.runPass(kind, mentor: mentor) }
|
||||
var passPid: pid_t?
|
||||
var polls = 0
|
||||
while passPid == nil, polls < 250 {
|
||||
|
||||
@@ -23,7 +23,7 @@ import Testing
|
||||
/// hop-back instead of asserting synchronously (PostsModelTests convention).
|
||||
/// The post-loop expect makes a silent timeout a failure, not a pass.
|
||||
@MainActor
|
||||
private func pollUntil(_ condition: @MainActor () -> Bool) async throws {
|
||||
func pollUntil(_ condition: @MainActor () -> Bool) async throws {
|
||||
for _ in 0 ..< 250 where !condition() {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ struct FixCardApplyTests {
|
||||
piecePath: folder.path,
|
||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
||||
)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
let session = try #require(model.session)
|
||||
let generation = session.loadGeneration
|
||||
|
||||
@@ -59,7 +59,7 @@ struct FixCardApplyTests {
|
||||
// buffer first (flush-first, like every op that reads the piece).
|
||||
session.edit("# Carded\n\nThe anchor sentence.\nPlus a typed line.\n")
|
||||
|
||||
#expect(model.applyCard(written[0].card, home: home) == .applied)
|
||||
#expect(model.applyCard(written[0].card) == .applied)
|
||||
|
||||
// Disk carries the replacement over the flushed buffer...
|
||||
#expect(PostStore.readBody(id: post.id, home: home) == "# Carded\n\nThe replaced sentence.\nPlus a typed line.\n")
|
||||
@@ -80,14 +80,14 @@ struct FixCardApplyTests {
|
||||
piecePath: folder.path,
|
||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
||||
)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
// The Post changed after the card was issued — the quote is gone.
|
||||
model.session?.edit("# Carded\n\nThe sentence changed.\n")
|
||||
model.session?.flush()
|
||||
let postURL = folder.appendingPathComponent("post.md")
|
||||
let before = try Data(contentsOf: postURL)
|
||||
|
||||
#expect(model.applyCard(written[0].card, home: home) == .stale)
|
||||
#expect(model.applyCard(written[0].card) == .stale)
|
||||
|
||||
#expect(try Data(contentsOf: postURL) == before) // nothing selected, nothing changed
|
||||
let diskCard = try #require(FixCardStore.scan(pieceURL: folder).first)
|
||||
@@ -104,11 +104,11 @@ struct FixCardApplyTests {
|
||||
piecePath: folder.path,
|
||||
cards: [card(pattern: "Demo", fix: "The replaced sentence.", quote: "The anchor sentence.", lane: .demonstration)],
|
||||
)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
let postURL = folder.appendingPathComponent("post.md")
|
||||
let before = try Data(contentsOf: postURL)
|
||||
|
||||
let outcome = model.applyCard(written[0].card, home: home)
|
||||
let outcome = model.applyCard(written[0].card)
|
||||
guard case let .refused(why) = outcome else {
|
||||
Issue.record("expected refusal, got \(outcome)")
|
||||
return
|
||||
@@ -127,7 +127,7 @@ struct FixCardApplyTests {
|
||||
piecePath: folder.path,
|
||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
||||
)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
// A foreign write lands on disk underneath the writer (#67) — the
|
||||
// reload question is up and unanswered.
|
||||
let postURL = folder.appendingPathComponent("post.md")
|
||||
@@ -135,7 +135,7 @@ struct FixCardApplyTests {
|
||||
model.session?.diskDidChange(diskText: "foreign text on disk")
|
||||
let before = try Data(contentsOf: postURL)
|
||||
|
||||
let outcome = model.applyCard(written[0].card, home: home)
|
||||
let outcome = model.applyCard(written[0].card)
|
||||
guard case let .refused(why) = outcome else {
|
||||
Issue.record("expected refusal, got \(outcome)")
|
||||
return
|
||||
@@ -157,15 +157,15 @@ struct FixCardApplyTests {
|
||||
card(pattern: "Telling", quote: "The anchor sentence."),
|
||||
],
|
||||
)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
let postURL = folder.appendingPathComponent("post.md")
|
||||
let before = try Data(contentsOf: postURL)
|
||||
|
||||
model.skipCard(written[0].card, home: home)
|
||||
model.skipCard(written[0].card)
|
||||
try await pollUntil { model.openPieceCards.first(where: { $0.id == written[0].card.id })?.status == .skipped }
|
||||
#expect(try FixCardStore.scan(pieceURL: folder).first(where: { $0.id == written[0].card.id })?.status == .skipped)
|
||||
|
||||
model.doneCard(written[1].card, home: home)
|
||||
model.doneCard(written[1].card)
|
||||
try await pollUntil { model.openPieceCards.first(where: { $0.id == written[1].card.id })?.status == .done }
|
||||
#expect(try FixCardStore.scan(pieceURL: folder).first(where: { $0.id == written[1].card.id })?.status == .done)
|
||||
|
||||
@@ -241,7 +241,7 @@ struct FixCardApplyTests {
|
||||
piecePath: folder.path,
|
||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
||||
)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
model.session?.edit("# Carded\n\nThe sentence changed.\n") // stale the anchor
|
||||
model.session?.flush()
|
||||
let postURL = folder.appendingPathComponent("post.md")
|
||||
@@ -252,7 +252,7 @@ struct FixCardApplyTests {
|
||||
try FileManager.default.setAttributes([.posixPermissions: 0o000], ofItemAtPath: cardsDir.path)
|
||||
defer { try? FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: cardsDir.path) }
|
||||
|
||||
#expect(model.applyCard(written[0].card, home: home) == .stale) // the primary contract holds…
|
||||
#expect(model.applyCard(written[0].card) == .stale) // the primary contract holds…
|
||||
#expect(model.lastError?.contains("card close failed") == true) // …and the flag failure is loud
|
||||
#expect(try Data(contentsOf: postURL) == before) // still nothing selected or changed
|
||||
}
|
||||
@@ -270,12 +270,12 @@ struct FixCardApplyTests {
|
||||
)
|
||||
|
||||
try FileManager.default.removeItem(at: folder.appendingPathComponent("post.md")) // the read will fail
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
#expect(model.session?.loadFailed == true)
|
||||
// The writer typed the anchor into the empty failed-session buffer.
|
||||
model.session?.edit("The anchor sentence. typed nowhere durable.")
|
||||
|
||||
let outcome = model.applyCard(written[0].card, home: home)
|
||||
let outcome = model.applyCard(written[0].card)
|
||||
guard case .refused = outcome else {
|
||||
Issue.record("expected refusal, got \(outcome)")
|
||||
return
|
||||
@@ -295,9 +295,9 @@ struct FixCardApplyTests {
|
||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
let written = try FixCardStore.submit(piecePath: folder.path, cards: [card()])
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
#expect(model.promoteCard(written[0].card, home: home) == .promoted)
|
||||
#expect(model.promoteCard(written[0].card) == .promoted)
|
||||
|
||||
let learnings = home.appendingPathComponent("learnings/posts", isDirectory: true)
|
||||
#expect(try FileManager.default.contentsOfDirectory(atPath: learnings.path).filter { $0.hasSuffix(".md") }.count == 1)
|
||||
@@ -306,7 +306,7 @@ struct FixCardApplyTests {
|
||||
|
||||
// Already promoted → refused, no second file (one confirm = one entry).
|
||||
let scanned = try #require(FixCardStore.scan(pieceURL: folder).first)
|
||||
#expect(model.promoteCard(scanned, home: home) == .refused("card already promoted"))
|
||||
#expect(model.promoteCard(scanned) == .refused("card already promoted"))
|
||||
#expect(try FileManager.default.contentsOfDirectory(atPath: learnings.path).filter { $0.hasSuffix(".md") }.count == 1)
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ struct FixCardApplyTests {
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
let written = try FixCardStore.submit(piecePath: folder.path, cards: [card()])
|
||||
|
||||
#expect(model.promoteCard(written[0].card, home: home) == .refused("open the piece to work its cards"))
|
||||
#expect(model.promoteCard(written[0].card) == .refused("open the piece to work its cards"))
|
||||
#expect(!FileManager.default.fileExists(atPath: home.appendingPathComponent("learnings").path))
|
||||
#expect(model.lastError == nil)
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `sendDraft flushes the open piece and sends the disk body with the title`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Flush Me\n\nOriginal.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
model.session?.edit("# Flush Me\n\nEdited on the way.") // inside the debounce window
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/flush-me"], log: log),
|
||||
)
|
||||
|
||||
@@ -40,10 +40,10 @@ struct MicropubModelTests {
|
||||
}
|
||||
|
||||
@Test @MainActor func `sendDraft refuses without an open saved piece`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let (model, _) = try makeModelHome()
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
guard case .refused = outcome else {
|
||||
@@ -54,11 +54,11 @@ struct MicropubModelTests {
|
||||
}
|
||||
|
||||
@Test @MainActor func `sendDraft refuses an unsaved draft`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let (model, _) = try makeModelHome()
|
||||
model.newPost() // staged draft — no folder, no session
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
guard case .refused = outcome else {
|
||||
@@ -73,11 +73,11 @@ struct MicropubModelTests {
|
||||
// All-whitespace body — no Title, no content (a heading-only
|
||||
// piece DOES send: the Title line is content on Micro.blog).
|
||||
let post = try PostStore.writeNew(body: " \n", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", log: log),
|
||||
)
|
||||
guard case .refused = outcome else {
|
||||
@@ -91,7 +91,7 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `frontmatter category never travels`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Categorized\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
// The writer's own category frontmatter — permitted, inert.
|
||||
let fileURL = try #require(PostStore.folder(of: post.id, home: home)?.appendingPathComponent("post.md"))
|
||||
let raw = try String(contentsOf: fileURL, encoding: .utf8)
|
||||
@@ -100,7 +100,7 @@ struct MicropubModelTests {
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/categorized"], log: log),
|
||||
)
|
||||
|
||||
@@ -113,11 +113,11 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `a failed draft stamps nothing`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Fails\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(500, body: "{}", log: log),
|
||||
)
|
||||
|
||||
@@ -127,15 +127,15 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `re-drafting overwrites the remembered url`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Again\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/first"], log: log),
|
||||
)
|
||||
_ = await model.micropubSendDraft(
|
||||
home: home, token: "tok",
|
||||
token: "tok",
|
||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/second"], log: log),
|
||||
)
|
||||
|
||||
@@ -147,7 +147,7 @@ struct MicropubModelTests {
|
||||
/// Plants a PNG beside the piece; returns the piece's post.md URL.
|
||||
@MainActor private func plantIllustratedPiece(_ model: PostsModel, _ home: URL, body: String) throws -> URL {
|
||||
let post = try PostStore.writeNew(body: body, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
let dir = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FileManager.default.createDirectory(at: dir.appendingPathComponent("assets", isDirectory: true), withIntermediateDirectories: true)
|
||||
try micropubPNG().write(to: dir.appendingPathComponent("assets/path.png"))
|
||||
@@ -162,7 +162,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
#expect(outcome == .drafted(url: "https://example.micro.blog/inked", preview: nil))
|
||||
// The three hops, in order: q=config → upload → create.
|
||||
@@ -197,7 +197,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case let .refused(reason) = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -228,7 +228,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case let .refused(reason) = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -246,7 +246,7 @@ struct MicropubModelTests {
|
||||
)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
#expect(outcome == .drafted(url: "https://example.micro.blog/inked", preview: nil))
|
||||
// config + ONE upload + create — the FILE uploads once, not once per ref.
|
||||
@@ -266,7 +266,7 @@ struct MicropubModelTests {
|
||||
) // path.png planted, ghost.png never
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
let outcome = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
let outcome = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
guard case .refused = outcome else {
|
||||
Issue.record("expected refused, got \(outcome)")
|
||||
@@ -278,10 +278,10 @@ struct MicropubModelTests {
|
||||
@Test @MainActor func `a piece without illustrations sends exactly one request`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Plain\n\nBody.", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
let log = MicropubRequestLog()
|
||||
_ = await model.micropubSendDraft(home: home, token: "tok", transport: micropubMediaScripted(log: log))
|
||||
_ = await model.micropubSendDraft(token: "tok", transport: micropubMediaScripted(log: log))
|
||||
|
||||
// The #33 path unchanged: no config round-trip, straight to the create.
|
||||
#expect(log.requests.count == 1)
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
// #108 audit: the model-layer lifecycle the store tests can't see —
|
||||
// archive clearing the open session, move reopening it at the new parent,
|
||||
// restore keeping the writer in the piece, New Project's draft targeting.
|
||||
// #179: the write-rail pins — one seam pairs every library store write
|
||||
// with exactly one rescan and owns the error strip; the model owns the
|
||||
// Home (no method takes one).
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@@ -27,10 +30,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
@Test @MainActor func `archiving the open piece clears selection and session`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Gone Soon\n", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
#expect(model.session?.postID == post.id)
|
||||
|
||||
model.archivePost(post, home: home)
|
||||
model.archivePost(post)
|
||||
|
||||
#expect(model.selectedPostID == nil)
|
||||
#expect(model.session == nil)
|
||||
@@ -41,10 +44,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
@Test @MainActor func `moving the open piece reopens its session at the new parent`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Traveler\n", project: "essays", home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
#expect(model.session?.folderURL.path.contains("projects/essays") == true)
|
||||
|
||||
model.moveToProject(post, project: "posts", home: home)
|
||||
model.moveToProject(post, project: "posts")
|
||||
|
||||
#expect(model.session?.postID == post.id) // same piece, fresh session
|
||||
#expect(model.session?.folderURL.path.contains("projects/posts/\(post.id)") == true)
|
||||
@@ -55,10 +58,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Revived\n", home: home)
|
||||
try PostStore.archive(post, home: home)
|
||||
model.select(post.id, home: home) // opened from the Archive pane
|
||||
model.select(post.id) // opened from the Archive pane
|
||||
#expect(model.session?.folderURL.path.contains("archive/") == true)
|
||||
|
||||
model.restorePost(post, home: home)
|
||||
model.restorePost(post)
|
||||
|
||||
#expect(model.selectedPostID == post.id) // the writer stays in it
|
||||
#expect(model.session?.folderURL.path.contains("projects/posts/\(post.id)") == true)
|
||||
@@ -73,7 +76,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
#expect(model.draft?.project == "essays")
|
||||
|
||||
model.updateDraft("# Fresh\n")
|
||||
model.saveDraft(home: home)
|
||||
model.saveDraft()
|
||||
|
||||
let scanned = Post.scan(home: home)
|
||||
#expect(scanned.first?.project == "essays")
|
||||
@@ -100,10 +103,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Keeper\n", home: home)
|
||||
try PostStore.archive(post, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
model.session?.edit("# Keeper\n\nDirty.") // inside the debounce window
|
||||
|
||||
model.unarchiveProject("posts", home: home)
|
||||
model.unarchiveProject("posts")
|
||||
|
||||
// The edits landed on disk (readBody resolves by id — through the move).
|
||||
#expect(PostStore.readBody(id: post.id, home: home) == "# Keeper\n\nDirty.")
|
||||
@@ -121,7 +124,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
model.newOutline()
|
||||
|
||||
@@ -142,7 +145,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
let (model, home) = try makeModelHome()
|
||||
|
||||
model.newOutline()
|
||||
model.saveDraft(home: home)
|
||||
model.saveDraft()
|
||||
|
||||
#expect(model.draft == nil)
|
||||
#expect(model.lastError == nil)
|
||||
@@ -157,7 +160,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
||||
let (model, home) = try makeModelHome()
|
||||
try PostStore.createProject(named: "essays", home: home) // empty — no pieces
|
||||
|
||||
#expect(model.moveTargets(home: home) == ["essays", "posts"])
|
||||
#expect(model.moveTargets() == ["essays", "posts"])
|
||||
// "posts" exists too (bind created it); a dot-project never shows.
|
||||
}
|
||||
|
||||
@@ -177,7 +180,7 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home)
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
#expect(model.outlineGuardPieceID == post.id) // the ask is up
|
||||
#expect(model.session == nil) // nothing editable while it's up
|
||||
@@ -191,8 +194,8 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home)
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.openGuardedOutlineInProse(home: home)
|
||||
model.select(post.id)
|
||||
model.openGuardedOutlineInProse()
|
||||
|
||||
#expect(model.outlineGuardPieceID == nil)
|
||||
#expect(model.session?.postID == post.id)
|
||||
@@ -209,8 +212,8 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home)
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.openGuardedOutlineAsOutline(home: home)
|
||||
model.select(post.id)
|
||||
model.openGuardedOutlineAsOutline()
|
||||
|
||||
#expect(model.outlineGuardPieceID == nil)
|
||||
#expect(model.session?.postID == post.id)
|
||||
@@ -226,13 +229,13 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home)
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
model.cancelOutlineGuard()
|
||||
|
||||
#expect(model.outlineGuardPieceID == nil)
|
||||
#expect(model.session == nil)
|
||||
// Still guarded: the next open re-fires the ask, file untouched.
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
#expect(model.outlineGuardPieceID == post.id)
|
||||
}
|
||||
|
||||
@@ -242,12 +245,12 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home)
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.openGuardedOutlineAsOutline(home: home) // consent; disk still mixed
|
||||
model.select(post.id)
|
||||
model.openGuardedOutlineAsOutline() // consent; disk still mixed
|
||||
let session = try #require(model.session)
|
||||
session.edit("- one\n- two\nedited") // dirty; debounce armed
|
||||
|
||||
model.select(post.id, home: home) // muscle-memory re-click on the open row
|
||||
model.select(post.id) // muscle-memory re-click on the open row
|
||||
|
||||
#expect(model.outlineGuardPieceID == nil) // no re-ask over a prior answer
|
||||
#expect(model.session === session) // the open session survives, dirty state intact
|
||||
@@ -257,15 +260,15 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home)
|
||||
|
||||
model.select(post.id, home: home) // ask up
|
||||
model.select(post.id) // ask up
|
||||
model.newPost() // ⌘N fires while the sheet is up
|
||||
#expect(model.outlineGuardPieceID == nil) // the ask died with the displacement
|
||||
#expect(model.draft != nil)
|
||||
|
||||
model.updateDraft("# Keep me\n")
|
||||
// Answering the (now-gone) ask is inert — the draft survives.
|
||||
model.openGuardedOutlineInProse(home: home)
|
||||
model.openGuardedOutlineAsOutline(home: home)
|
||||
model.openGuardedOutlineInProse()
|
||||
model.openGuardedOutlineAsOutline()
|
||||
#expect(model.draft != nil)
|
||||
#expect(model.selectedPostID == nil) // the draft still owns the editor
|
||||
}
|
||||
@@ -279,7 +282,7 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
}
|
||||
#expect(model.posts.contains(where: { $0.id == post.id }))
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
#expect(model.outlineGuardPieceID == post.id) // the scan path guards too
|
||||
}
|
||||
|
||||
@@ -288,11 +291,11 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let clean = try PostStore.writeNew(body: "# Clean\n\n- one\n- two\n", type: .outline, home: home)
|
||||
let prose = try PostStore.writeNew(body: "# Plain\n\nA paragraph.\n", home: home)
|
||||
|
||||
model.select(clean.id, home: home)
|
||||
model.select(clean.id)
|
||||
#expect(model.outlineGuardPieceID == nil)
|
||||
#expect(model.session?.postID == clean.id)
|
||||
|
||||
model.select(prose.id, home: home)
|
||||
model.select(prose.id)
|
||||
#expect(model.outlineGuardPieceID == nil)
|
||||
#expect(model.session?.postID == prose.id)
|
||||
}
|
||||
@@ -302,12 +305,12 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
@Test @MainActor func `convert reopens the open piece routed to prose`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Chapter\n- one\n - nested", type: .outline, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
model.stageConversion(post, home: home)
|
||||
model.stageConversion(post)
|
||||
#expect(model.pendingConversion?.id == post.id)
|
||||
#expect(model.pendingConversion?.lossy == false) // clean outline
|
||||
model.convertToPost(headingsLadder: true, home: home)
|
||||
model.convertToPost(headingsLadder: true)
|
||||
|
||||
#expect(model.pendingConversion == nil)
|
||||
#expect(model.session?.postID == post.id) // reopened on the converted body
|
||||
@@ -321,10 +324,10 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let open = try PostStore.writeNew(body: "# Stay\n", home: home)
|
||||
let outline = try PostStore.writeNew(body: "- a\n - b", type: .outline, home: home)
|
||||
model.select(open.id, home: home)
|
||||
model.select(open.id)
|
||||
|
||||
model.stageConversion(outline, home: home)
|
||||
model.convertToPost(headingsLadder: false, home: home)
|
||||
model.stageConversion(outline)
|
||||
model.convertToPost(headingsLadder: false)
|
||||
|
||||
#expect(model.session?.postID == open.id) // untouched
|
||||
#expect(model.selectedPostID == open.id)
|
||||
@@ -344,9 +347,9 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
}
|
||||
#expect(model.posts.first(where: { $0.id == post.id })?.type == .outline)
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.stageConversion(post, home: home)
|
||||
model.convertToPost(headingsLadder: false, home: home) // VERBATIM
|
||||
model.select(post.id)
|
||||
model.stageConversion(post)
|
||||
model.convertToPost(headingsLadder: false) // VERBATIM
|
||||
|
||||
#expect(model.proseOverridePostID == post.id)
|
||||
#expect(model.session?.postID == post.id)
|
||||
@@ -362,11 +365,11 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
@Test @MainActor func `dirty open piece flushes before the convert`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Chapter\n- one", type: .outline, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
model.session?.edit("# Chapter\n- one\n - typed child") // unflushed edit
|
||||
model.stageConversion(post, home: home)
|
||||
model.convertToPost(headingsLadder: false, home: home)
|
||||
model.stageConversion(post)
|
||||
model.convertToPost(headingsLadder: false)
|
||||
|
||||
let onDisk = try String(contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8)
|
||||
#expect(onDisk.contains("type: post"))
|
||||
@@ -376,11 +379,11 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
@Test @MainActor func `staging warns from the session text when the piece is dirty`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Clean\n- one\n- two", type: .outline, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
// prose typed since the last flush — disk still clean, session is not
|
||||
model.session?.edit("# Clean\n- one\nA paragraph between bullets.\n- two")
|
||||
model.stageConversion(post, home: home)
|
||||
model.stageConversion(post)
|
||||
|
||||
#expect(model.pendingConversion?.lossy == true) // from session.text, not stale disk
|
||||
}
|
||||
@@ -389,7 +392,7 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home) // closed piece — disk is the truth
|
||||
|
||||
model.stageConversion(post, home: home)
|
||||
model.stageConversion(post)
|
||||
|
||||
#expect(model.pendingConversion?.lossy == true)
|
||||
}
|
||||
@@ -398,13 +401,13 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Clean\n- one\n- two", type: .outline, home: home)
|
||||
|
||||
model.stageConversion(post, home: home) // staged clean, no warning shown
|
||||
model.stageConversion(post) // staged clean, no warning shown
|
||||
// a foreign write makes the body mixed while the sheet was up
|
||||
let file = home.appendingPathComponent("projects/posts/\(post.id)/post.md", isDirectory: false)
|
||||
try PostStore.stamped(body: "# Clean\n- one\nA paragraph between bullets.\n- two", passState: .firstDraft, origin: .writer, type: .outline)
|
||||
.write(to: file, atomically: true, encoding: .utf8)
|
||||
|
||||
model.convertToPost(headingsLadder: true, home: home)
|
||||
model.convertToPost(headingsLadder: true)
|
||||
|
||||
#expect(model.lastError?.contains("nothing was converted") == true)
|
||||
#expect(model.session?.postID == nil || model.session?.postID != post.id)
|
||||
@@ -413,8 +416,8 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
#expect(onDisk.contains("A paragraph between bullets."))
|
||||
|
||||
// the consented path still converts: a WARNED mixed piece + Headings proceeds
|
||||
model.stageConversion(post, home: home) // now stages lossy from disk
|
||||
model.convertToPost(headingsLadder: true, home: home)
|
||||
model.stageConversion(post) // now stages lossy from disk
|
||||
model.convertToPost(headingsLadder: true)
|
||||
let converted = try String(contentsOf: file, encoding: .utf8)
|
||||
#expect(converted.contains("type: post"))
|
||||
#expect(!converted.contains("A paragraph between bullets.")) // dropped, as consented
|
||||
@@ -423,14 +426,14 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
@Test @MainActor func `unanswered conflict aborts the convert`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Clean\n- one", type: .outline, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
|
||||
// #67 conflict up: disk holds foreign text, the editor's version unwritten
|
||||
model.session?.diskDidChange(diskText: "# Foreign rewrite\nbody")
|
||||
#expect(model.session?.conflictAlert == true)
|
||||
|
||||
model.stageConversion(post, home: home)
|
||||
model.convertToPost(headingsLadder: false, home: home)
|
||||
model.stageConversion(post)
|
||||
model.convertToPost(headingsLadder: false)
|
||||
|
||||
#expect(model.lastError?.contains("reload question") == true)
|
||||
#expect(model.session?.conflictAlert == true) // still answerable, not trampled
|
||||
@@ -441,13 +444,13 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
@Test @MainActor func `failed flush aborts the convert`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Chapter\n- one", type: .outline, home: home)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
model.session?.edit("# Chapter\n- one\n - child") // dirty
|
||||
// vanish the piece: the flush throws (never resurrects), convert must abort
|
||||
try FileManager.default.removeItem(at: home.appendingPathComponent("projects/posts/\(post.id)", isDirectory: true))
|
||||
|
||||
model.stageConversion(post, home: home)
|
||||
model.convertToPost(headingsLadder: true, home: home)
|
||||
model.stageConversion(post)
|
||||
model.convertToPost(headingsLadder: true)
|
||||
|
||||
#expect(model.lastError?.contains("nothing was changed") == true)
|
||||
#expect(model.session?.postID == post.id) // session stays up, dirty and honest
|
||||
@@ -457,11 +460,11 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try writeMixedOutline(home: home)
|
||||
|
||||
model.select(post.id, home: home) // guard fires, open held
|
||||
model.select(post.id) // guard fires, open held
|
||||
#expect(model.outlineGuardPieceID == post.id)
|
||||
|
||||
model.stageConversion(post, home: home)
|
||||
model.convertToPost(headingsLadder: false, home: home)
|
||||
model.stageConversion(post)
|
||||
model.convertToPost(headingsLadder: false)
|
||||
|
||||
#expect(model.outlineGuardPieceID == nil) // the stale ask died with the outline
|
||||
#expect(model.selectedPostID == nil) // cancel teardown: nothing was open
|
||||
@@ -483,13 +486,118 @@ private func waitForCards(_ model: PostsModel, _ count: Int) async throws {
|
||||
}
|
||||
}
|
||||
|
||||
// #179: the rail's rescan lands via Task — bounded poll (FixCardApplyTests'
|
||||
// pollUntil, made internal; the post-loop expect makes a silent timeout a
|
||||
// failure, not a pass).
|
||||
|
||||
/// Scenario: one write rail for every library verb (from #179).
|
||||
/// Given a model bound to a Home, when a verb's store write runs, then it
|
||||
/// lands through the ONE seam — the library reflects it via exactly one
|
||||
/// rescan and a stale error strip is cleared on success.
|
||||
/// Suite member (not free function): suite-name filters must reach the
|
||||
/// rail pins (MuseionTests/AGENTS.md rule).
|
||||
@Suite("write rail #179")
|
||||
struct PostsModelWriteRailTests {
|
||||
@Test @MainActor func `pairs the write with the library refresh and clears the strip`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Rail Pin\n", home: home)
|
||||
try await pollUntil { model.posts.contains { $0.id == post.id } }
|
||||
|
||||
model.lastError = "stale strip" // the rail owns the strip from here
|
||||
model.rename(post, to: "Rail Pin Two")
|
||||
|
||||
#expect(model.lastError == nil)
|
||||
try await pollUntil { model.posts.contains { $0.id == "rail-pin-two" } }
|
||||
#expect(model.posts.contains { $0.id == post.id } == false)
|
||||
}
|
||||
|
||||
/// Scenario: the rail owns the error strip on a failed write (from #179).
|
||||
/// Given a bound model and a store write that throws, the verb's failure
|
||||
/// reason lands in the strip AND rides the return for the sheet.
|
||||
@Test @MainActor func `owns the strip when the write throws`() throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
try PostStore.createProject(named: "dup", home: home) // the store already has it
|
||||
|
||||
let reason = model.createProject(named: "dup")
|
||||
|
||||
#expect(reason != nil)
|
||||
#expect(model.lastError == reason)
|
||||
}
|
||||
|
||||
/// Scenario: the rail refuses cleanly with no Home bound (from #179).
|
||||
/// Given a model that was never bound, a write verb refuses with a reason
|
||||
/// and nothing reaches any disk.
|
||||
@Test @MainActor func `refuses cleanly before a home is bound`() {
|
||||
let model = PostsModel()
|
||||
|
||||
let reason = model.createProject(named: "nowhere")
|
||||
|
||||
#expect(reason != nil)
|
||||
#expect(model.lastError == reason)
|
||||
#expect(model.posts.isEmpty)
|
||||
}
|
||||
|
||||
/// Scenario: a mid-batch import failure keeps its strip message while
|
||||
/// the good files land (from #179 — the rail clears the strip BEFORE
|
||||
/// the write exactly so the per-file failures set inside the closure
|
||||
/// survive the success tail).
|
||||
@Test @MainActor func `import batch keeps per-file failure messages on the strip`() async throws {
|
||||
let (model, _) = try makeModelHome()
|
||||
let scratch = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("import-batch-\(UUID().uuidString)", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: scratch, withIntermediateDirectories: true)
|
||||
let good = scratch.appendingPathComponent("good.md")
|
||||
try "# Good Piece\n".write(to: good, atomically: true, encoding: .utf8)
|
||||
let missing = scratch.appendingPathComponent("missing.md") // never written — the read throws
|
||||
|
||||
model.stageImport([good, missing])
|
||||
model.importFiles(origin: .writer)
|
||||
|
||||
#expect(model.lastError?.contains("Import failed — missing.md") == true)
|
||||
// the library refresh rides the rail's rescan Task — poll for it
|
||||
try await pollUntil { model.posts.contains { $0.id == "good-piece" } }
|
||||
#expect(model.selectedPostID == "good-piece") // …and opened (synchronous select)
|
||||
}
|
||||
|
||||
/// Scenario: a Home repoint while a pass runs refuses the pass advance
|
||||
/// (from #179 audit — the rail resolves watchedHome at call time, and
|
||||
/// the engine's turn spans minutes). Given a pass that ends normally
|
||||
/// after its library was repointed, the advance is refused with the
|
||||
/// honest strip message, both libraries keep their pass states, and
|
||||
/// nothing was written into the new library.
|
||||
@Test @MainActor func `home repoint mid-pass refuses the advance`() async throws {
|
||||
let rig = try makeScriptedRig(mode: "hangOnPrompt")
|
||||
defer { rig.mentor.shutdown() }
|
||||
await rig.mentor.openSession()
|
||||
let post = try PostStore.writeNew(body: "# Repoint\n", home: rig.home)
|
||||
rig.model.select(post.id)
|
||||
|
||||
let run = Task { await rig.model.runPass(.pass1, mentor: rig.mentor) }
|
||||
try await pollUntil { rig.model.runningPass == .pass1 } // the engine holds the turn
|
||||
let homeB = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("repoint-\(UUID().uuidString)", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: homeB, withIntermediateDirectories: true)
|
||||
rig.model.bind(home: homeB) // the Settings repoint, mid-pass
|
||||
// Release the held turn as a NORMALLY ended one — .ended + no refusal.
|
||||
// #require: nothing held means the parked prompt already timed out
|
||||
// under machine load — fail loudly, not on a confusing nil strip.
|
||||
let engine = try #require(rig.mentor.host.oneShot as? ScriptedEngine)
|
||||
try #require(engine.endHeldPrompt())
|
||||
await run.value
|
||||
|
||||
#expect(rig.model.lastError == "The library changed while the pass ran — its Pass State was not advanced.")
|
||||
#expect(Post.scan(home: rig.home).first?.passState == .firstDraft) // the pass's own library: not advanced
|
||||
#expect(Post.scan(home: homeB).isEmpty) // the new library: nothing stamped
|
||||
}
|
||||
}
|
||||
|
||||
@Test @MainActor func `opening a piece surfaces its stored fix cards`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
#expect(model.openPieceCards.map(\.pattern) == ["Hedging"])
|
||||
@@ -501,7 +609,7 @@ private func waitForCards(_ model: PostsModel, _ count: Int) async throws {
|
||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
// An MCP client submits another card while the piece stays open —
|
||||
@@ -520,7 +628,7 @@ private func waitForCards(_ model: PostsModel, _ count: Int) async throws {
|
||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
model.newPost()
|
||||
@@ -536,7 +644,7 @@ private func waitForCards(_ model: PostsModel, _ count: Int) async throws {
|
||||
#expect(folder.path.contains("/archive/"))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
|
||||
model.select(post.id, home: home) // opened from the Archive pane
|
||||
model.select(post.id) // opened from the Archive pane
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
#expect(model.openPieceCards.count == 1)
|
||||
|
||||
@@ -234,6 +234,23 @@ final class ScriptedEngine: EngineTransport, @unchecked Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
/// Test hook (#179 audit): release a held prompt as a NORMALLY ended
|
||||
/// turn — session/cancel answers "cancelled"; the mid-pass repoint pin
|
||||
/// needs the turn to end .ended after the hold. Returns false (and
|
||||
/// no-ops) when nothing is held — e.g. the parked request already hit
|
||||
/// its deadline under machine load — so the caller can fail loudly
|
||||
/// instead of reading a confusing nil strip.
|
||||
@discardableResult
|
||||
func endHeldPrompt() -> Bool {
|
||||
queue.sync {
|
||||
guard let id = self.heldPromptID,
|
||||
let continuation = self.parked.removeValue(forKey: id) else { return false }
|
||||
self.heldPromptID = nil
|
||||
continuation.resume(returning: .object(["stopReason": .string("end_turn")]))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/// Test hook: the kill(pid, SIGKILL) rail's in-process twin (#178 B2) —
|
||||
/// the engine dies unexpectedly: onCrash fires, every pending request
|
||||
/// fails. The crash-restart pins drive real crashes through this.
|
||||
|
||||
@@ -31,12 +31,12 @@ struct SessionLifecycleTests {
|
||||
let defaultSession = try #require(mentor.activeEntry)
|
||||
let rosterBefore = mentor.roster.count
|
||||
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)
|
||||
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)
|
||||
|
||||
// The roster never grew — the pass entry is transient.
|
||||
#expect(mentor.roster.count == rosterBefore)
|
||||
@@ -69,7 +69,7 @@ struct SessionLifecycleTests {
|
||||
/// newest-first, active; a non-nil pieceTitle rides the entry —
|
||||
/// association by convention only.
|
||||
@Test @MainActor func `freeform new session is rostered newest-first and active`() async throws {
|
||||
let (model, home, mentor) = try makePassRig()
|
||||
let (_, _, mentor) = try makePassRig()
|
||||
defer { mentor.shutdown() }
|
||||
#expect(!mentor.canStartSession) // never opened — nothing may start
|
||||
await mentor.openSession()
|
||||
@@ -200,7 +200,7 @@ struct SessionLifecycleTests {
|
||||
/// renders, the raw slash command never does, the summary streams into
|
||||
/// the transcript — and is refused while a turn streams.
|
||||
@Test @MainActor func `compact sends the labeled command and is refused while streaming`() async throws {
|
||||
let (model, home, mentor) = try makePassRig()
|
||||
let (_, _, mentor) = try makePassRig()
|
||||
defer { mentor.shutdown() }
|
||||
await mentor.openSession()
|
||||
|
||||
@@ -330,7 +330,7 @@ struct SessionLifecycleTests {
|
||||
#expect(SessionsPaneView.openPiece(in: nil) == nil) // no Posts at all
|
||||
|
||||
let post = try PostStore.writeNew(body: "# Open Piece\n", 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)
|
||||
}
|
||||
|
||||
@@ -172,13 +172,13 @@ struct WritingLockTests {
|
||||
// the outline routing reads the real type, not the lagging list).
|
||||
let post = try PostStore.writeNew(body: "# Prose piece\n\nBody words.\n", home: home)
|
||||
try await Self.waitForScan(model, id: post.id)
|
||||
model.select(post.id, home: home)
|
||||
model.select(post.id)
|
||||
#expect(model.canArmWritingLock)
|
||||
#expect(model.editorBodyText == "# Prose piece\n\nBody words.\n")
|
||||
|
||||
let outline = try PostStore.writeNew(body: "- an outline\n", project: "posts", type: .outline, home: home)
|
||||
try await Self.waitForScan(model, id: outline.id)
|
||||
model.select(outline.id, home: home)
|
||||
model.select(outline.id)
|
||||
#expect(!model.canArmWritingLock)
|
||||
|
||||
// A MIXED outline fires the #111 guard ask instead — the held
|
||||
@@ -186,7 +186,7 @@ struct WritingLockTests {
|
||||
// branch's fourth path, pinned so the mirror can't drift.
|
||||
let mixed = try PostStore.writeNew(body: "- bullet\nprose between bullets\n", project: "posts", type: .outline, home: home)
|
||||
try await Self.waitForScan(model, id: mixed.id)
|
||||
model.select(mixed.id, home: home)
|
||||
model.select(mixed.id)
|
||||
#expect(model.outlineGuardPieceID == mixed.id)
|
||||
#expect(!model.canArmWritingLock)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user