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
+343
-342
No files matched your search
@@ -149,7 +149,7 @@ private struct CardRow: View {
|
|||||||
.controlSize(.small)
|
.controlSize(.small)
|
||||||
} else {
|
} else {
|
||||||
Button("Done") {
|
Button("Done") {
|
||||||
gate.posts.doneCard(card, home: gate.museionHome)
|
gate.posts.doneCard(card)
|
||||||
}
|
}
|
||||||
.buttonStyle(.bordered)
|
.buttonStyle(.bordered)
|
||||||
.controlSize(.small)
|
.controlSize(.small)
|
||||||
@@ -217,7 +217,7 @@ private struct SkipButton: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button("Skip") {
|
Button("Skip") {
|
||||||
gate.posts.skipCard(card, home: gate.museionHome)
|
gate.posts.skipCard(card)
|
||||||
}
|
}
|
||||||
.buttonStyle(.borderless)
|
.buttonStyle(.borderless)
|
||||||
.controlSize(.small)
|
.controlSize(.small)
|
||||||
@@ -289,7 +289,7 @@ private struct ApplyAskSheet: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func apply() {
|
private func apply() {
|
||||||
switch posts.applyCard(card, home: home) {
|
switch posts.applyCard(card) {
|
||||||
case .applied:
|
case .applied:
|
||||||
dismiss()
|
dismiss()
|
||||||
case .stale:
|
case .stale:
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ private struct PassBarView: View {
|
|||||||
|
|
||||||
private func runPass() {
|
private func runPass() {
|
||||||
guard let posts, let home else { return }
|
guard let posts, let home else { return }
|
||||||
Task { await posts.runPass(kind, home: home, mentor: model) }
|
Task { await posts.runPass(kind, mentor: model) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #122: the Blind Read — one purposeful click judges the current
|
/// #122: the Blind Read — one purposeful click judges the current
|
||||||
@@ -561,7 +561,7 @@ private struct PassBarView: View {
|
|||||||
disabled: blindReadBlocked != nil,
|
disabled: blindReadBlocked != nil,
|
||||||
) {
|
) {
|
||||||
guard let posts, let home else { return }
|
guard let posts, let home else { return }
|
||||||
Task { await posts.blindRead(home: home, mentor: model) }
|
Task { await posts.blindRead(mentor: model) }
|
||||||
}
|
}
|
||||||
.help(
|
.help(
|
||||||
blindReadBlocked
|
blindReadBlocked
|
||||||
|
|||||||
@@ -244,12 +244,13 @@ extension PostsModel {
|
|||||||
/// un-sends the draft; it lands in lastError while the outcome stays
|
/// un-sends the draft; it lands in lastError while the outcome stays
|
||||||
/// honest. Publishing (step 2) is stateless: the sheet calls
|
/// honest. Publishing (step 2) is stateless: the sheet calls
|
||||||
/// `Micropub.publish` against the remembered URL directly.
|
/// `Micropub.publish` against the remembered URL directly.
|
||||||
|
/// #179: no Home parameter — the model owns its Home.
|
||||||
func micropubSendDraft(
|
func micropubSendDraft(
|
||||||
home: URL,
|
|
||||||
token: String,
|
token: String,
|
||||||
transport: Micropub.Transport = Micropub.urlSessionTransport,
|
transport: Micropub.Transport = Micropub.urlSessionTransport,
|
||||||
) async -> Micropub.Outcome {
|
) async -> Micropub.Outcome {
|
||||||
guard let session,
|
guard let home = boundHome,
|
||||||
|
let session,
|
||||||
let id = session.postID,
|
let id = session.postID,
|
||||||
id == selectedPostID,
|
id == selectedPostID,
|
||||||
draft == nil,
|
draft == nil,
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ struct MicropubPublishSheet: View {
|
|||||||
refusal = nil
|
refusal = nil
|
||||||
phase = .drafting
|
phase = .drafting
|
||||||
Task {
|
Task {
|
||||||
switch await posts.micropubSendDraft(home: home, token: token) {
|
switch await posts.micropubSendDraft(token: token) {
|
||||||
case let .drafted(url, preview):
|
case let .drafted(url, preview):
|
||||||
draftURL = url
|
draftURL = url
|
||||||
previewURL = preview
|
previewURL = preview
|
||||||
|
|||||||
+82
-95
@@ -4,8 +4,9 @@
|
|||||||
//
|
//
|
||||||
// #18 (S1.1): the Posts pane's write side — FSEvents watcher on the piece
|
// #18 (S1.1): the Posts pane's write side — FSEvents watcher on the piece
|
||||||
// roots (projects/ + archive/, #107) with a ~0.5 s debounced rescan (#61),
|
// roots (projects/ + archive/, #107) with a ~0.5 s debounced rescan (#61),
|
||||||
// selection, and the New Post draft lifecycle (#62). Own ops route through
|
// selection, and the New Post draft lifecycle (#62). #179: every library
|
||||||
// the same rescan: one path.
|
// verb's store write rides the write rail (PostsModelRail.swift) — one
|
||||||
|
// seam pairing the write with the rescan and the error strip.
|
||||||
// #108: project targeting + the move/archive/restore ops behind the
|
// #108: project targeting + the move/archive/restore ops behind the
|
||||||
// variant-B library and the Archive pane.
|
// variant-B library and the Archive pane.
|
||||||
// #146: the domain extensions (#111/#114/#24/#122/#23/#25/#26) live in
|
// #146: the domain extensions (#111/#114/#24/#122/#23/#25/#26) live in
|
||||||
@@ -176,8 +177,11 @@ final class PostsModel {
|
|||||||
/// each. Nil in production (no observer, no cost).
|
/// each. Nil in production (no observer, no cost).
|
||||||
@ObservationIgnored
|
@ObservationIgnored
|
||||||
var onRailEvent: (@MainActor (PostsModelRailEvent) -> Void)?
|
var onRailEvent: (@MainActor (PostsModelRailEvent) -> Void)?
|
||||||
/// Home the watcher is bound to; also the rescan target.
|
/// #179: the Home the model owns — set by `bind` ALONE (app
|
||||||
private var watchedHome: URL?
|
/// construction and the Settings repoint are the only two places it is
|
||||||
|
/// set); every verb reads it, none takes it. Watcher root + rescan
|
||||||
|
/// target.
|
||||||
|
private(set) var boundHome: URL?
|
||||||
private var watcher = PostsWatcher()
|
private var watcher = PostsWatcher()
|
||||||
/// #143 (OPT-F3): scan parse memo — a rescan re-parses only changed
|
/// #143 (OPT-F3): scan parse memo — a rescan re-parses only changed
|
||||||
/// post.md files, not the library (see PostScanCache).
|
/// post.md files, not the library (see PostScanCache).
|
||||||
@@ -265,22 +269,22 @@ final class PostsModel {
|
|||||||
|
|
||||||
/// First save of the draft (#62): lazy folder, slug, #59 stamp all fire
|
/// First save of the draft (#62): lazy folder, slug, #59 stamp all fire
|
||||||
/// here. The saved post opens straight into an editing session — the
|
/// here. The saved post opens straight into an editing session — the
|
||||||
/// writer keeps typing where they were. Rescans immediately (the watcher
|
/// writer keeps typing where they were. #179: rides the write rail —
|
||||||
/// would too, after its window).
|
/// the paired rescan fires immediately (the watcher would too, after
|
||||||
func saveDraft(home: URL) {
|
/// its window).
|
||||||
guard let draft else { return }
|
func saveDraft() {
|
||||||
do {
|
guard let staged = draft, let home = boundHome else { return }
|
||||||
let post = try PostStore.writeNew(body: draft.text, project: draft.project, type: draft.type, home: home)
|
let text = staged.text
|
||||||
lastDraftWasOutline = draft.type == .outline // #109: covers the lagging rescan
|
let project = staged.project
|
||||||
self.draft = nil
|
let type = staged.type
|
||||||
|
railWrite {
|
||||||
|
let post = try PostStore.writeNew(body: text, project: project, type: type, home: home)
|
||||||
|
lastDraftWasOutline = type == .outline // #109: covers the lagging rescan
|
||||||
|
draft = nil
|
||||||
pendingProject = nil // #108: the explicit target landed with the draft
|
pendingProject = nil // #108: the explicit target landed with the draft
|
||||||
selectedPostID = post.id
|
selectedPostID = post.id
|
||||||
session = EditorSession(postID: post.id, home: home)
|
session = EditorSession(postID: post.id, home: home)
|
||||||
wireSession()
|
wireSession()
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,17 +292,14 @@ final class PostsModel {
|
|||||||
/// draft stamped `origin: ai` (never stats-eligible) and open it in
|
/// draft stamped `origin: ai` (never stats-eligible) and open it in
|
||||||
/// Posts (select's open path; the WorkspaceView selection onChange
|
/// Posts (select's open path; the WorkspaceView selection onChange
|
||||||
/// hops the pane). Nil + lastError on failure; Cancel never gets here.
|
/// hops the pane). Nil + lastError on failure; Cancel never gets here.
|
||||||
|
/// #179: rides the write rail.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func newPostFromSession(body: String, home: URL) -> Post? {
|
func newPostFromSession(body: String) -> Post? {
|
||||||
do {
|
guard let home = boundHome else { return nil }
|
||||||
|
return railWrite {
|
||||||
let post = try PostStore.writeNew(body: body, origin: .ai, home: home)
|
let post = try PostStore.writeNew(body: body, origin: .ai, home: home)
|
||||||
select(post.id, home: home)
|
select(post.id)
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
return post
|
return post
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +312,8 @@ final class PostsModel {
|
|||||||
/// fires the mixed-content guard — the open is held (routing stays
|
/// fires the mixed-content guard — the open is held (routing stays
|
||||||
/// prose) until the writer picks. The old session still ends here:
|
/// prose) until the writer picks. The old session still ends here:
|
||||||
/// its flush is prose-mode, so it can't drop anything.
|
/// its flush is prose-mode, so it can't drop anything.
|
||||||
func select(_ id: String, home: URL) {
|
func select(_ id: String) {
|
||||||
|
guard let home = boundHome else { return }
|
||||||
dismissExternal()
|
dismissExternal()
|
||||||
// A reselect of the already-open piece is a no-op — INCLUDING a
|
// A reselect of the already-open piece is a no-op — INCLUDING a
|
||||||
// guarded one: the piece is open under a prior answer, and firing
|
// guarded one: the piece is open under a prior answer, and firing
|
||||||
@@ -323,7 +325,7 @@ final class PostsModel {
|
|||||||
if let session {
|
if let session {
|
||||||
session.teardown(flushFirst: true)
|
session.teardown(flushFirst: true)
|
||||||
}
|
}
|
||||||
if isGuardedOutline(id, home: home) {
|
if isGuardedOutline(id) {
|
||||||
outlineGuardPieceID = id
|
outlineGuardPieceID = id
|
||||||
proseOverridePostID = nil
|
proseOverridePostID = nil
|
||||||
session = nil
|
session = nil
|
||||||
@@ -331,13 +333,13 @@ final class PostsModel {
|
|||||||
pendingProject = nil
|
pendingProject = nil
|
||||||
lastDraftWasOutline = false
|
lastDraftWasOutline = false
|
||||||
selectedPostID = id
|
selectedPostID = id
|
||||||
refreshCards(home: home) // #23: nil session — the held ask shows no cards
|
refreshCards() // #23: nil session — the held ask shows no cards
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// The prior session was torn down above; openUnguarded's guards
|
// The prior session was torn down above; openUnguarded's guards
|
||||||
// are dead code on this path (session is nil or a different id) —
|
// are dead code on this path (session is nil or a different id) —
|
||||||
// kept: one open body answers select and the ask alike.
|
// kept: one open body answers select and the ask alike.
|
||||||
openUnguarded(id, home: home)
|
openUnguarded(id)
|
||||||
proseOverridePostID = nil // #111: the override died with the open it covered
|
proseOverridePostID = nil // #111: the override died with the open it covered
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,13 +387,14 @@ final class PostsModel {
|
|||||||
/// Explicit Rename = retitle + move (#60). Renaming the open post flushes
|
/// Explicit Rename = retitle + move (#60). Renaming the open post flushes
|
||||||
/// first (rename reads the file from disk — unflushed edits must land
|
/// first (rename reads the file from disk — unflushed edits must land
|
||||||
/// before the move), then reopens a session at the new id. Sets lastError
|
/// before the move), then reopens a session at the new id. Sets lastError
|
||||||
/// on failure.
|
/// on failure. #179: the move rides the write rail.
|
||||||
func rename(_ post: Post, to title: String, home: URL) {
|
func rename(_ post: Post, to title: String) {
|
||||||
|
guard let home = boundHome else { return }
|
||||||
// #108 audit 2: rename reads the file from disk — a failed write
|
// #108 audit 2: rename reads the file from disk — a failed write
|
||||||
// aborts (moving the folder would strand unflushed edits), and the
|
// aborts (moving the folder would strand unflushed edits), and the
|
||||||
// session stays up, dirty and honest.
|
// session stays up, dirty and honest.
|
||||||
guard flushOrAbort(post.id) else { return }
|
guard flushOrAbort(post.id) else { return }
|
||||||
do {
|
railWrite {
|
||||||
let moved = try PostStore.rename(post, to: title, home: home)
|
let moved = try PostStore.rename(post, to: title, home: home)
|
||||||
if selectedPostID == post.id {
|
if selectedPostID == post.id {
|
||||||
selectedPostID = moved.id
|
selectedPostID = moved.id
|
||||||
@@ -400,18 +403,16 @@ final class PostsModel {
|
|||||||
wireSession()
|
wireSession()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a Post (Trash, recoverable — #18 AC). Clears selection if it
|
/// Delete a Post (Trash, recoverable — #18 AC). Clears selection if it
|
||||||
/// was the post; the session is torn down (cancel only — the folder is
|
/// was the post; the session is torn down (cancel only — the folder is
|
||||||
/// leaving, a flush would resurrect nothing but churn the watcher).
|
/// leaving, a flush would resurrect nothing but churn the watcher).
|
||||||
func trash(_ post: Post, home: URL) {
|
/// #179: rides the write rail.
|
||||||
do {
|
func trash(_ post: Post) {
|
||||||
|
guard let home = boundHome else { return }
|
||||||
|
railWrite {
|
||||||
try PostStore.trash(post, home: home)
|
try PostStore.trash(post, home: home)
|
||||||
if selectedPostID == post.id {
|
if selectedPostID == post.id {
|
||||||
selectedPostID = nil
|
selectedPostID = nil
|
||||||
@@ -420,10 +421,6 @@ final class PostsModel {
|
|||||||
session = nil
|
session = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,15 +433,15 @@ final class PostsModel {
|
|||||||
newPost()
|
newPost()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #108: raw create — the sheet composes on it. The failure reason on
|
/// #108: raw create — the sheet composes on it. The failure reason
|
||||||
/// false (shown inline in the sheet; never routed into lastError — the
|
/// returns to the sheet (shown inline; never routed into lastError —
|
||||||
/// strip behind the sheet must not double-message one error).
|
/// the strip behind the sheet must not double-message one error).
|
||||||
func createProject(named name: String, home: URL) -> String? {
|
/// #179: rides the write rail's reason-returning entry — the pairing
|
||||||
do {
|
/// is the rail's, the error routing stays the sheet's.
|
||||||
|
func createProject(named name: String) -> String? {
|
||||||
|
guard let home = boundHome else { return "No library Home yet — try again in a moment." }
|
||||||
|
return railWriteReturningReason {
|
||||||
try PostStore.createProject(named: name, home: home)
|
try PostStore.createProject(named: name, home: home)
|
||||||
return nil // success
|
|
||||||
} catch {
|
|
||||||
return error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,9 +459,9 @@ final class PostsModel {
|
|||||||
/// projects/ plus the default (bind creates the roots, not posts/ — an
|
/// projects/ plus the default (bind creates the roots, not posts/ — an
|
||||||
/// empty Home must still offer it), localized-sorted to match the
|
/// empty Home must still offer it), localized-sorted to match the
|
||||||
/// library's section order.
|
/// library's section order.
|
||||||
func moveTargets(home: URL) -> [String] {
|
func moveTargets() -> [String] {
|
||||||
let root = home.appendingPathComponent("projects", isDirectory: true)
|
let root = boundHome?.appendingPathComponent("projects", isDirectory: true)
|
||||||
let onDisk = (try? FileManager.default.contentsOfDirectory(atPath: root.path)) ?? []
|
let onDisk = root.flatMap { try? FileManager.default.contentsOfDirectory(atPath: $0.path) } ?? []
|
||||||
var names = Set(onDisk.filter { !$0.hasPrefix(".") })
|
var names = Set(onDisk.filter { !$0.hasPrefix(".") })
|
||||||
names.insert(Post.defaultProject)
|
names.insert(Post.defaultProject)
|
||||||
return names.sorted { $0.localizedStandardCompare($1) == .orderedAscending }
|
return names.sorted { $0.localizedStandardCompare($1) == .orderedAscending }
|
||||||
@@ -498,27 +495,24 @@ final class PostsModel {
|
|||||||
/// #108: Move to Project — flush first (move reads disk), then the
|
/// #108: Move to Project — flush first (move reads disk), then the
|
||||||
/// folder moves under projects/. Id stays the same; the session is
|
/// folder moves under projects/. Id stays the same; the session is
|
||||||
/// reopened anyway so folderURL re-resolves to the new parent.
|
/// reopened anyway so folderURL re-resolves to the new parent.
|
||||||
func moveToProject(_ post: Post, project: String, home: URL) {
|
/// #179: rides the write rail.
|
||||||
guard flushOrAbort(post.id) else { return }
|
func moveToProject(_ post: Post, project: String) {
|
||||||
do {
|
guard let home = boundHome, flushOrAbort(post.id) else { return }
|
||||||
|
railWrite {
|
||||||
try PostStore.move(post, to: project, home: home)
|
try PostStore.move(post, to: project, home: home)
|
||||||
if session?.postID == post.id {
|
if session?.postID == post.id {
|
||||||
session = EditorSession(postID: post.id, home: home)
|
session = EditorSession(postID: post.id, home: home)
|
||||||
wireSession()
|
wireSession()
|
||||||
}
|
}
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #108: Move to Archive. Archiving the open piece clears it — the
|
/// #108: Move to Archive. Archiving the open piece clears it — the
|
||||||
/// editor is empty until the next selection (archived pieces open from
|
/// editor is empty until the next selection (archived pieces open from
|
||||||
/// the Archive pane, where they're listed).
|
/// the Archive pane, where they're listed). #179: rides the write rail.
|
||||||
func archivePost(_ post: Post, home: URL) {
|
func archivePost(_ post: Post) {
|
||||||
guard flushOrAbort(post.id) else { return }
|
guard let home = boundHome, flushOrAbort(post.id) else { return }
|
||||||
do {
|
railWrite {
|
||||||
try PostStore.archive(post, home: home)
|
try PostStore.archive(post, home: home)
|
||||||
if selectedPostID == post.id {
|
if selectedPostID == post.id {
|
||||||
selectedPostID = nil
|
selectedPostID = nil
|
||||||
@@ -527,10 +521,6 @@ final class PostsModel {
|
|||||||
open.teardown(flushFirst: false) // already flushed above
|
open.teardown(flushFirst: false) // already flushed above
|
||||||
session = nil
|
session = nil
|
||||||
}
|
}
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,20 +528,17 @@ final class PostsModel {
|
|||||||
/// the writer stays in the piece they just revived. A session already
|
/// the writer stays in the piece they just revived. A session already
|
||||||
/// open on the piece survives `select` — reopen it so folderURL points
|
/// open on the piece survives `select` — reopen it so folderURL points
|
||||||
/// at projects/, not the archive path it was born with.
|
/// at projects/, not the archive path it was born with.
|
||||||
func restorePost(_ post: Post, home: URL) {
|
/// #179: rides the write rail.
|
||||||
guard flushOrAbort(post.id) else { return }
|
func restorePost(_ post: Post) {
|
||||||
do {
|
guard let home = boundHome, flushOrAbort(post.id) else { return }
|
||||||
|
railWrite {
|
||||||
try PostStore.restore(post, home: home)
|
try PostStore.restore(post, home: home)
|
||||||
if let open = session, open.postID == post.id {
|
if let open = session, open.postID == post.id {
|
||||||
session = EditorSession(postID: post.id, home: home)
|
session = EditorSession(postID: post.id, home: home)
|
||||||
wireSession()
|
wireSession()
|
||||||
} else {
|
} else {
|
||||||
select(post.id, home: home)
|
select(post.id)
|
||||||
}
|
}
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,11 +546,13 @@ final class PostsModel {
|
|||||||
/// Flush-first like every folder move (a dirty open piece inside the
|
/// Flush-first like every folder move (a dirty open piece inside the
|
||||||
/// project would otherwise race the move), and its session is reopened so
|
/// project would otherwise race the move), and its session is reopened so
|
||||||
/// folderURL re-resolves off archive/ (same reason as restorePost).
|
/// folderURL re-resolves off archive/ (same reason as restorePost).
|
||||||
func unarchiveProject(_ name: String, home: URL) {
|
/// #179: rides the write rail.
|
||||||
/// #108 audit 2: disk-derived membership — the posts snapshot is stale
|
func unarchiveProject(_ name: String) {
|
||||||
/// the moment a Finder move lands. Captured BEFORE the move: after it
|
guard let home = boundHome else { return }
|
||||||
/// the piece resolves under projects/ and its archive membership is
|
// #108 audit 2: disk-derived membership — the posts snapshot is stale
|
||||||
/// invisible. dir − 1 = project dir (…/archive/<name>), − 2 = root.
|
// the moment a Finder move lands. Captured BEFORE the move: after it
|
||||||
|
// the piece resolves under projects/ and its archive membership is
|
||||||
|
// invisible. dir − 1 = project dir (…/archive/<name>), − 2 = root.
|
||||||
func openPieceInArchivedProject() -> String? {
|
func openPieceInArchivedProject() -> String? {
|
||||||
guard let id = session?.postID,
|
guard let id = session?.postID,
|
||||||
let projectDir = PostStore.folder(of: id, home: home)?.deletingLastPathComponent(),
|
let projectDir = PostStore.folder(of: id, home: home)?.deletingLastPathComponent(),
|
||||||
@@ -577,16 +566,12 @@ final class PostsModel {
|
|||||||
// #108 audit 2: the only #108 folder move that skipped the gate.
|
// #108 audit 2: the only #108 folder move that skipped the gate.
|
||||||
guard flushOrAbort(openID) else { return }
|
guard flushOrAbort(openID) else { return }
|
||||||
}
|
}
|
||||||
do {
|
railWrite {
|
||||||
try PostStore.unarchiveProject(name, home: home)
|
try PostStore.unarchiveProject(name, home: home)
|
||||||
if let openID {
|
if let openID {
|
||||||
session = EditorSession(postID: openID, home: home)
|
session = EditorSession(postID: openID, home: home)
|
||||||
wireSession()
|
wireSession()
|
||||||
}
|
}
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,11 +634,13 @@ final class PostsModel {
|
|||||||
/// default, reversible; never an alert, never an abort). The last
|
/// default, reversible; never an alert, never an abort). The last
|
||||||
/// imported post opens; a failure anywhere keeps its message up even
|
/// imported post opens; a failure anywhere keeps its message up even
|
||||||
/// when other files landed. #107: the batch lands in the selected
|
/// when other files landed. #107: the batch lands in the selected
|
||||||
/// post's project (newPost's target rule).
|
/// post's project (newPost's target rule). #179: rides the write
|
||||||
func importFiles(origin: Post.Origin, home: URL) {
|
/// rail's strip-keeping entry — ONE paired rescan for the whole batch.
|
||||||
guard let urls = pendingImportURLs else { return }
|
func importFiles(origin: Post.Origin) {
|
||||||
|
guard let urls = pendingImportURLs, let home = boundHome else { return }
|
||||||
pendingImportURLs = nil
|
pendingImportURLs = nil
|
||||||
let project = targetProject
|
let project = targetProject
|
||||||
|
railWriteKeepingStrip {
|
||||||
var last: Post?
|
var last: Post?
|
||||||
var failures = 0
|
var failures = 0
|
||||||
for url in urls {
|
for url in urls {
|
||||||
@@ -665,12 +652,12 @@ final class PostsModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let last {
|
if let last {
|
||||||
select(last.id, home: home)
|
select(last.id)
|
||||||
}
|
}
|
||||||
if failures == 0 {
|
if failures == 0 {
|
||||||
lastError = nil
|
lastError = nil
|
||||||
}
|
}
|
||||||
Task { await rescan() }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #146: internal — the split-out domain extensions wire sessions too.
|
/// #146: internal — the split-out domain extensions wire sessions too.
|
||||||
@@ -685,8 +672,8 @@ final class PostsModel {
|
|||||||
|
|
||||||
extension PostsModel {
|
extension PostsModel {
|
||||||
private func startWatching(home: URL) {
|
private func startWatching(home: URL) {
|
||||||
guard watchedHome != home else { return }
|
guard boundHome != home else { return }
|
||||||
watchedHome = home
|
boundHome = home
|
||||||
let roots = Post.containerRoots.map { home.appendingPathComponent($0, isDirectory: true) }
|
let roots = Post.containerRoots.map { home.appendingPathComponent($0, isDirectory: true) }
|
||||||
for root in roots {
|
for root in roots {
|
||||||
try? FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
|
try? FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
|
||||||
@@ -700,7 +687,7 @@ extension PostsModel {
|
|||||||
/// no second debounce on top.
|
/// no second debounce on top.
|
||||||
/// #146: internal — the split-out domain extensions trigger rescans.
|
/// #146: internal — the split-out domain extensions trigger rescans.
|
||||||
func rescan() async {
|
func rescan() async {
|
||||||
guard let home = watchedHome else { return }
|
guard let home = boundHome else { return }
|
||||||
// Scan + the #67 disk read both run off-main (a synced large post.md
|
// Scan + the #67 disk read both run off-main (a synced large post.md
|
||||||
// must never stall the UI on a watcher burst).
|
// must never stall the UI on a watcher burst).
|
||||||
let openPostID = session?.postID
|
let openPostID = session?.postID
|
||||||
@@ -730,7 +717,7 @@ extension PostsModel {
|
|||||||
// for the OLD tree — never let it kill a session selected under
|
// for the OLD tree — never let it kill a session selected under
|
||||||
// the NEW home (the id is missing from the old snapshot by
|
// the NEW home (the id is missing from the old snapshot by
|
||||||
// construction); the next rescan under the new home owns it.
|
// construction); the next rescan under the new home owns it.
|
||||||
if let id = selectedPostID, !posts.contains(where: { $0.id == id }), watchedHome == home, PostStore.folder(of: id, home: home) == nil {
|
if let id = selectedPostID, !posts.contains(where: { $0.id == id }), boundHome == home, PostStore.folder(of: id, home: home) == nil {
|
||||||
selectedPostID = nil // the post vanished (deleted in Finder or here)
|
selectedPostID = nil // the post vanished (deleted in Finder or here)
|
||||||
if let open = session, open.postID == id {
|
if let open = session, open.postID == id {
|
||||||
open.teardown(flushFirst: false) // post is gone; cancel the debounce
|
open.teardown(flushFirst: false) // post is gone; cancel the debounce
|
||||||
@@ -744,6 +731,6 @@ extension PostsModel {
|
|||||||
}
|
}
|
||||||
// #23: the open piece's stored fix cards ride the same rescan —
|
// #23: the open piece's stored fix cards ride the same rescan —
|
||||||
// the watcher fires on <piece>/cards/ writes too.
|
// the watcher fires on <piece>/cards/ writes too.
|
||||||
refreshCards(home: home)
|
refreshCards()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,8 +20,12 @@ extension PostsModel {
|
|||||||
/// transitions — the piece-roots watcher already fires on cards/ writes.
|
/// transitions — the piece-roots watcher already fires on cards/ writes.
|
||||||
/// #122: the same pass also derives `openPieceHasSnapshot` (the Blind
|
/// #122: the same pass also derives `openPieceHasSnapshot` (the Blind
|
||||||
/// Read's base) — one detached read of the open piece's disk facts.
|
/// Read's base) — one detached read of the open piece's disk facts.
|
||||||
func refreshCards(home: URL) {
|
/// #179: no Home parameter — the model's bound Home is the one target.
|
||||||
guard let id = session?.postID, let folder = PostStore.folder(of: id, home: home) else {
|
func refreshCards() {
|
||||||
|
guard let id = session?.postID,
|
||||||
|
let home = boundHome,
|
||||||
|
let folder = PostStore.folder(of: id, home: home)
|
||||||
|
else {
|
||||||
openPieceCards = []
|
openPieceCards = []
|
||||||
openPieceHasSnapshot = false
|
openPieceHasSnapshot = false
|
||||||
return
|
return
|
||||||
@@ -68,7 +72,7 @@ extension PostsModel {
|
|||||||
/// flags the card and touches no text. A failed close after a landed
|
/// flags the card and touches no text. A failed close after a landed
|
||||||
/// edit is reported via lastError, never silent.
|
/// edit is reported via lastError, never silent.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func applyCard(_ card: FixCardStore.StoredFixCard, home: URL) -> FixCardApplyOutcome {
|
func applyCard(_ card: FixCardStore.StoredFixCard) -> FixCardApplyOutcome {
|
||||||
guard card.status == .open else { return .refused("card already closed") }
|
guard card.status == .open else { return .refused("card already closed") }
|
||||||
guard card.lane == .mechanical else { return .refused("demonstration cards close Done or Skip") }
|
guard card.lane == .mechanical else { return .refused("demonstration cards close Done or Skip") }
|
||||||
guard let session, let postID = session.postID else {
|
guard let session, let postID = session.postID else {
|
||||||
@@ -86,30 +90,29 @@ extension PostsModel {
|
|||||||
} catch {
|
} catch {
|
||||||
lastError = "card close failed: \(error.localizedDescription)"
|
lastError = "card close failed: \(error.localizedDescription)"
|
||||||
}
|
}
|
||||||
refreshCards(home: home)
|
refreshCards()
|
||||||
return .stale
|
return .stale
|
||||||
}
|
}
|
||||||
guard session.adoptText(newText) else { return .refused(lastError ?? "write failed") }
|
guard session.adoptText(newText) else { return .refused(lastError ?? "write failed") }
|
||||||
closeCard(card, status: .applied, home: home)
|
closeCard(card, status: .applied)
|
||||||
return .applied
|
return .applied
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #25 (S3.3): Skip — not this instance. Closes the card recording
|
/// #25 (S3.3): Skip — not this instance. Closes the card recording
|
||||||
/// NOTHING beyond the status flip (CONTEXT.md).
|
/// NOTHING beyond the status flip (CONTEXT.md).
|
||||||
func skipCard(_ card: FixCardStore.StoredFixCard, home: URL) {
|
func skipCard(_ card: FixCardStore.StoredFixCard) {
|
||||||
closeCard(card, status: .skipped, home: home)
|
closeCard(card, status: .skipped)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #25 (S3.3): Done — the writer rewrote the span themselves. Same
|
/// #25 (S3.3): Done — the writer rewrote the span themselves. Same
|
||||||
/// flip, different terminal.
|
/// flip, different terminal.
|
||||||
func doneCard(_ card: FixCardStore.StoredFixCard, home: URL) {
|
func doneCard(_ card: FixCardStore.StoredFixCard) {
|
||||||
closeCard(card, status: .done, home: home)
|
closeCard(card, status: .done)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func closeCard(
|
private func closeCard(
|
||||||
_ card: FixCardStore.StoredFixCard,
|
_ card: FixCardStore.StoredFixCard,
|
||||||
status: FixCardStore.StoredFixCard.Status,
|
status: FixCardStore.StoredFixCard.Status,
|
||||||
home: URL,
|
|
||||||
) {
|
) {
|
||||||
guard let session else {
|
guard let session else {
|
||||||
lastError = "open the piece to work its cards"
|
lastError = "open the piece to work its cards"
|
||||||
@@ -120,7 +123,7 @@ extension PostsModel {
|
|||||||
} catch {
|
} catch {
|
||||||
lastError = "card close failed: \(error.localizedDescription)"
|
lastError = "card close failed: \(error.localizedDescription)"
|
||||||
}
|
}
|
||||||
refreshCards(home: home)
|
refreshCards()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +143,7 @@ extension PostsModel {
|
|||||||
/// counter; the store guarantees the one-stamp rule). Touches no text
|
/// counter; the store guarantees the one-stamp rule). Touches no text
|
||||||
/// and flushes nothing: this writes a Learning, not an edit.
|
/// and flushes nothing: this writes a Learning, not an edit.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func promoteCard(_ card: FixCardStore.StoredFixCard, home: URL) -> FixCardPromoteOutcome {
|
func promoteCard(_ card: FixCardStore.StoredFixCard) -> FixCardPromoteOutcome {
|
||||||
guard card.promotedAt == nil else { return .refused("card already promoted") }
|
guard card.promotedAt == nil else { return .refused("card already promoted") }
|
||||||
guard let session else { return .refused("open the piece to work its cards") }
|
guard let session else { return .refused("open the piece to work its cards") }
|
||||||
do {
|
do {
|
||||||
@@ -149,7 +152,7 @@ extension PostsModel {
|
|||||||
lastError = "learning write failed: \(error.localizedDescription)"
|
lastError = "learning write failed: \(error.localizedDescription)"
|
||||||
return .refused("learning write failed: \(error.localizedDescription)")
|
return .refused("learning write failed: \(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
refreshCards(home: home)
|
refreshCards()
|
||||||
return .promoted
|
return .promoted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,10 +19,11 @@ extension PostsModel {
|
|||||||
/// Type: the scan's word when the list knows it (archive pane opens,
|
/// Type: the scan's word when the list knows it (archive pane opens,
|
||||||
/// app-start selection), the frontmatter's word during the rescan lag
|
/// app-start selection), the frontmatter's word during the rescan lag
|
||||||
/// (the same window lastDraftWasOutline covers) — ONE disk read derives
|
/// (the same window lastDraftWasOutline covers) — ONE disk read derives
|
||||||
/// both. No watched home yet (pre-bind) = post: nothing to guard.
|
/// both. No bound Home yet (pre-bind) = post: nothing to guard.
|
||||||
/// #146: internal — `select` (PostsModel.swift) asks the guard.
|
/// #146: internal — `select` (PostsModel.swift) asks the guard.
|
||||||
func isGuardedOutline(_ id: String, home: URL) -> Bool {
|
func isGuardedOutline(_ id: String) -> Bool {
|
||||||
guard let dir = PostStore.folder(of: id, home: home),
|
guard let home = boundHome,
|
||||||
|
let dir = PostStore.folder(of: id, home: home),
|
||||||
let text = try? String(contentsOf: dir.appendingPathComponent("post.md"), encoding: .utf8)
|
let text = try? String(contentsOf: dir.appendingPathComponent("post.md"), encoding: .utf8)
|
||||||
else { return false }
|
else { return false }
|
||||||
let type: Post.ContentType = if let known = posts.first(where: { $0.id == id })?.type {
|
let type: Post.ContentType = if let known = posts.first(where: { $0.id == id })?.type {
|
||||||
@@ -37,17 +38,17 @@ extension PostsModel {
|
|||||||
/// outliner never mounts, nothing drops); Outline = explicit consent,
|
/// outliner never mounts, nothing drops); Outline = explicit consent,
|
||||||
/// opens the outliner (saves normalize/drop as today). Cancel = back
|
/// opens the outliner (saves normalize/drop as today). Cancel = back
|
||||||
/// out (no session); the piece stays guarded on the next open.
|
/// out (no session); the piece stays guarded on the next open.
|
||||||
func openGuardedOutlineInProse(home: URL) {
|
func openGuardedOutlineInProse() {
|
||||||
guard let id = outlineGuardPieceID else { return }
|
guard let id = outlineGuardPieceID else { return }
|
||||||
outlineGuardPieceID = nil
|
outlineGuardPieceID = nil
|
||||||
proseOverridePostID = id // routing: prose until the next open
|
proseOverridePostID = id // routing: prose until the next open
|
||||||
openUnguarded(id, home: home)
|
openUnguarded(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func openGuardedOutlineAsOutline(home: URL) {
|
func openGuardedOutlineAsOutline() {
|
||||||
guard let id = outlineGuardPieceID else { return }
|
guard let id = outlineGuardPieceID else { return }
|
||||||
outlineGuardPieceID = nil
|
outlineGuardPieceID = nil
|
||||||
openUnguarded(id, home: home)
|
openUnguarded(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #111 (S7): the ask's Cancel — the held open dies (no session opens,
|
/// #111 (S7): the ask's Cancel — the held open dies (no session opens,
|
||||||
@@ -64,7 +65,8 @@ extension PostsModel {
|
|||||||
/// explicit choice the ruling requires.
|
/// explicit choice the ruling requires.
|
||||||
/// #146: internal — `select` (PostsModel.swift) routes its tail through
|
/// #146: internal — `select` (PostsModel.swift) routes its tail through
|
||||||
/// this one open body.
|
/// this one open body.
|
||||||
func openUnguarded(_ id: String, home: URL) {
|
func openUnguarded(_ id: String) {
|
||||||
|
guard let home = boundHome else { return }
|
||||||
dismissExternal()
|
dismissExternal()
|
||||||
if let session, session.postID != id {
|
if let session, session.postID != id {
|
||||||
session.teardown(flushFirst: true)
|
session.teardown(flushFirst: true)
|
||||||
@@ -76,7 +78,7 @@ extension PostsModel {
|
|||||||
outlineGuardPieceID = nil // the open displaces any held ask
|
outlineGuardPieceID = nil // the open displaces any held ask
|
||||||
selectedPostID = id
|
selectedPostID = id
|
||||||
wireSession()
|
wireSession()
|
||||||
refreshCards(home: home) // #23: the newly opened piece's cards, now
|
refreshCards() // #23: the newly opened piece's cards, now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,8 +97,8 @@ extension PostsModel {
|
|||||||
/// The open session's text is the truth when the piece is open — disk
|
/// The open session's text is the truth when the piece is open — disk
|
||||||
/// lags the debounce, and a stale-clean read would drop the warning
|
/// lags the debounce, and a stale-clean read would drop the warning
|
||||||
/// for prose typed since the last flush (#114 audit).
|
/// for prose typed since the last flush (#114 audit).
|
||||||
func stageConversion(_ post: Post, home: URL) {
|
func stageConversion(_ post: Post) {
|
||||||
guard post.type == .outline else { return }
|
guard post.type == .outline, let home = boundHome else { return }
|
||||||
let body: String = if let session, session.postID == post.id {
|
let body: String = if let session, session.postID == post.id {
|
||||||
session.text
|
session.text
|
||||||
} else {
|
} else {
|
||||||
@@ -115,11 +117,11 @@ extension PostsModel {
|
|||||||
/// reopen the session routed to prose — proseOverridePostID covers the
|
/// reopen the session routed to prose — proseOverridePostID covers the
|
||||||
/// rescan lag (lastDraftWasOutline's machinery, reversed). A piece that
|
/// rescan lag (lastDraftWasOutline's machinery, reversed). A piece that
|
||||||
/// isn't open just converts; nothing else moves. One-way in v1.
|
/// isn't open just converts; nothing else moves. One-way in v1.
|
||||||
func convertToPost(headingsLadder: Bool, home: URL) {
|
/// #179: the convert rides the write rail.
|
||||||
|
func convertToPost(headingsLadder: Bool) {
|
||||||
guard let pending = pendingConversion else { return }
|
guard let pending = pendingConversion else { return }
|
||||||
pendingConversion = nil
|
pendingConversion = nil
|
||||||
guard flushOrAbort(pending.id) else { return }
|
guard let home = boundHome, flushOrAbort(pending.id) else { return }
|
||||||
do {
|
|
||||||
// The sheet's warning covered the STAGED body. If the
|
// The sheet's warning covered the STAGED body. If the
|
||||||
// answer-time body went lossy behind the ask (foreign write,
|
// answer-time body went lossy behind the ask (foreign write,
|
||||||
// late edit) and the writer was never warned, Headings would
|
// late edit) and the writer was never warned, Headings would
|
||||||
@@ -128,22 +130,19 @@ extension PostsModel {
|
|||||||
lastError = "The outline changed since the sheet opened — nothing was converted."
|
lastError = "The outline changed since the sheet opened — nothing was converted."
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
railWrite {
|
||||||
try PostStore.convert(id: pending.id, headingsLadder: headingsLadder, home: home)
|
try PostStore.convert(id: pending.id, headingsLadder: headingsLadder, home: home)
|
||||||
if session?.postID == pending.id {
|
if session?.postID == pending.id {
|
||||||
session?.teardown(flushFirst: false) // flushOrAbort already wrote
|
session?.teardown(flushFirst: false) // flushOrAbort already wrote
|
||||||
session = nil
|
session = nil
|
||||||
proseOverridePostID = pending.id
|
proseOverridePostID = pending.id
|
||||||
openUnguarded(pending.id, home: home)
|
openUnguarded(pending.id)
|
||||||
}
|
}
|
||||||
if outlineGuardPieceID == pending.id {
|
if outlineGuardPieceID == pending.id {
|
||||||
// Multi-window: the held #111 ask targets an outline that no
|
// Multi-window: the held #111 ask targets an outline that no
|
||||||
// longer is — dismiss it as a cancel (the ask's own teardown).
|
// longer is — dismiss it as a cancel (the ask's own teardown).
|
||||||
cancelOutlineGuard()
|
cancelOutlineGuard()
|
||||||
}
|
}
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() }
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ extension PostsModel {
|
|||||||
/// engine's turn ends normally — never on cancel, refusal, or crash,
|
/// engine's turn ends normally — never on cancel, refusal, or crash,
|
||||||
/// and never when fix cards resolve. Passes run in any order
|
/// and never when fix cards resolve. Passes run in any order
|
||||||
/// (advancePassState is monotonic).
|
/// (advancePassState is monotonic).
|
||||||
func runPass(_ kind: PassKind, home: URL, mentor: MentorSessionModel) async {
|
func runPass(_ kind: PassKind, mentor: MentorSessionModel) async {
|
||||||
guard runningPass == nil, !runningBlindRead else {
|
guard runningPass == nil, !runningBlindRead else {
|
||||||
lastError = "A pass is already running."
|
lastError = "A pass is already running."
|
||||||
return
|
return
|
||||||
@@ -42,7 +42,8 @@ extension PostsModel {
|
|||||||
// The pass targets the open Piece: a never-saved draft has no
|
// The pass targets the open Piece: a never-saved draft has no
|
||||||
// folder, and the external guest and a held #111 guard ask are
|
// folder, and the external guest and a held #111 guard ask are
|
||||||
// not Pieces.
|
// not Pieces.
|
||||||
guard let session,
|
guard let home = boundHome,
|
||||||
|
let session,
|
||||||
let id = session.postID,
|
let id = session.postID,
|
||||||
id == selectedPostID,
|
id == selectedPostID,
|
||||||
draft == nil,
|
draft == nil,
|
||||||
@@ -82,12 +83,11 @@ extension PostsModel {
|
|||||||
guard case let .ended(stopReason) = outcome, stopReason != "refusal" else {
|
guard case let .ended(stopReason) = outcome, stopReason != "refusal" else {
|
||||||
return // cancelled / refused / failed — the transcript tells the story
|
return // cancelled / refused / failed — the transcript tells the story
|
||||||
}
|
}
|
||||||
do {
|
// #179: the library-visible write of a completed pass — Pass State
|
||||||
|
// advance — rides the write rail; the snapshot/stats/lint writes
|
||||||
|
// above never do (they don't regroup the library).
|
||||||
|
railWrite {
|
||||||
_ = try PostStore.advancePassState(id: id, kind: kind, home: home)
|
_ = try PostStore.advancePassState(id: id, kind: kind, home: home)
|
||||||
lastError = nil
|
|
||||||
Task { await rescan() } // the library regroups by Pass State
|
|
||||||
} catch {
|
|
||||||
lastError = error.localizedDescription
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ extension PostsModel {
|
|||||||
/// advance, no cards, no Learnings — the verdict and the reveal live in
|
/// advance, no cards, no Learnings — the verdict and the reveal live in
|
||||||
/// the transient transcript and die with it. The writer stays judge of
|
/// the transient transcript and die with it. The writer stays judge of
|
||||||
/// record.
|
/// record.
|
||||||
func blindRead(home: URL, mentor: MentorSessionModel) async {
|
func blindRead(mentor: MentorSessionModel) async {
|
||||||
guard runningPass == nil else {
|
guard runningPass == nil else {
|
||||||
lastError = "A pass is already running."
|
lastError = "A pass is already running."
|
||||||
return
|
return
|
||||||
@@ -127,7 +127,8 @@ extension PostsModel {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Same open-piece rule as a pass: the read judges ONE saved piece.
|
// Same open-piece rule as a pass: the read judges ONE saved piece.
|
||||||
guard let session,
|
guard let home = boundHome,
|
||||||
|
let session,
|
||||||
let id = session.postID,
|
let id = session.postID,
|
||||||
id == selectedPostID,
|
id == selectedPostID,
|
||||||
draft == nil,
|
draft == nil,
|
||||||
|
|||||||
@@ -16,28 +16,38 @@ import Foundation
|
|||||||
|
|
||||||
/// #179: rail observability — what the write-rail suite reads off the
|
/// #179: rail observability — what the write-rail suite reads off the
|
||||||
/// seam. `.write` = a verb's body rode the rail; `.pairedRescan` = the
|
/// seam. `.write` = a verb's body rode the rail; `.pairedRescan` = the
|
||||||
/// rail scheduled the verb's ONE rescan.
|
/// rail scheduled the verb's ONE rescan; `.writeFailed` = the verb's
|
||||||
|
/// write threw (the strip owns the reason; nothing paired).
|
||||||
enum PostsModelRailEvent: Equatable {
|
enum PostsModelRailEvent: Equatable {
|
||||||
case write
|
case write
|
||||||
case pairedRescan
|
case pairedRescan
|
||||||
|
case writeFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Write rail (#179)
|
// MARK: Write rail (#179)
|
||||||
|
|
||||||
|
/// #179: ONE rail, three error routings — deliberately NOT overloads: a
|
||||||
|
/// shared base name let unlabeled trailing-closure calls resolve into the
|
||||||
|
/// wrong entry (Swift binds a trailing closure to a labeled first
|
||||||
|
/// parameter, and the non-generic overload wins) — a verb meant for the
|
||||||
|
/// strip silently took the reason-returning path and never touched
|
||||||
|
/// `lastError`. Distinct names make the routing choice unambiguous at
|
||||||
|
/// every call site.
|
||||||
extension PostsModel {
|
extension PostsModel {
|
||||||
/// #179: the rail's default entry — strip-routed. The op runs the
|
/// #179: the rail's default entry — strip-routed. The op runs the
|
||||||
/// verb's store write FIRST, then its state updates (a throw leaves
|
/// verb's store write FIRST, then its state updates (a throw leaves
|
||||||
/// nothing half-updated); success clears the strip and pairs exactly
|
/// nothing half-updated); success clears the strip and pairs exactly
|
||||||
/// one rescan, a throw routes the failure into the strip.
|
/// one rescan, a throw routes the failure into the strip.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func performLibraryWrite<T>(_ op: () throws -> T) -> T? {
|
func railWrite<T>(_ operation: () throws -> T) -> T? {
|
||||||
onRailEvent?(.write)
|
onRailEvent?(.write)
|
||||||
do {
|
do {
|
||||||
let result = try op()
|
let result = try operation()
|
||||||
lastError = nil
|
lastError = nil
|
||||||
pairRailRescan()
|
pairRailRescan()
|
||||||
return result
|
return result
|
||||||
} catch {
|
} catch {
|
||||||
|
onRailEvent?(.writeFailed)
|
||||||
lastError = error.localizedDescription
|
lastError = error.localizedDescription
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -46,10 +56,10 @@ extension PostsModel {
|
|||||||
/// #179: the reason-returning entry (project creation) — the sheet
|
/// #179: the reason-returning entry (project creation) — the sheet
|
||||||
/// owns its inline reason and the strip behind the sheet must not
|
/// owns its inline reason and the strip behind the sheet must not
|
||||||
/// double-message one error. Same ONE rescan on success.
|
/// double-message one error. Same ONE rescan on success.
|
||||||
func performLibraryWrite(returningReason op: () throws -> Void) -> String? {
|
func railWriteReturningReason(_ operation: () throws -> Void) -> String? {
|
||||||
onRailEvent?(.write)
|
onRailEvent?(.write)
|
||||||
do {
|
do {
|
||||||
try op()
|
try operation()
|
||||||
pairRailRescan()
|
pairRailRescan()
|
||||||
return nil
|
return nil
|
||||||
} catch {
|
} catch {
|
||||||
@@ -60,9 +70,9 @@ extension PostsModel {
|
|||||||
/// #179: the strip-keeping entry (the import batch) — per-file
|
/// #179: the strip-keeping entry (the import batch) — per-file
|
||||||
/// failures continue inside the op and the strip keeps the verb's own
|
/// failures continue inside the op and the strip keeps the verb's own
|
||||||
/// message; the rail only pairs the ONE rescan.
|
/// message; the rail only pairs the ONE rescan.
|
||||||
func performLibraryWrite(keepingStrip op: () -> Void) {
|
func railWriteKeepingStrip(_ operation: () -> Void) {
|
||||||
onRailEvent?(.write)
|
onRailEvent?(.write)
|
||||||
op()
|
operation()
|
||||||
pairRailRescan()
|
pairRailRescan()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ struct PostsPaneView: View {
|
|||||||
draftText: draft.text,
|
draftText: draft.text,
|
||||||
draftEdited: { model.updateDraft($0) },
|
draftEdited: { model.updateDraft($0) },
|
||||||
draftSave: {
|
draftSave: {
|
||||||
model.saveDraft(home: home)
|
model.saveDraft()
|
||||||
},
|
},
|
||||||
outline: draft.type == .outline,
|
outline: draft.type == .outline,
|
||||||
)
|
)
|
||||||
@@ -317,7 +317,7 @@ struct PostsLibraryColumn: View {
|
|||||||
.background(LaunchFocusReset())
|
.background(LaunchFocusReset())
|
||||||
.sheet(item: $renamingPost) { post in
|
.sheet(item: $renamingPost) { post in
|
||||||
RenamePostSheet(post: post) { title in
|
RenamePostSheet(post: post) { title in
|
||||||
model.rename(post, to: title, home: home)
|
model.rename(post, to: title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(item: $movingPost) { post in
|
.sheet(item: $movingPost) { post in
|
||||||
@@ -325,8 +325,8 @@ struct PostsLibraryColumn: View {
|
|||||||
// the library renders (Unicode-scalar sort split them), and it
|
// the library renders (Unicode-scalar sort split them), and it
|
||||||
// includes empty projects (a fresh New Project has no pieces yet —
|
// includes empty projects (a fresh New Project has no pieces yet —
|
||||||
// it must already be a move target).
|
// it must already be a move target).
|
||||||
MoveToProjectSheet(post: post, projects: model.moveTargets(home: home)) { project in
|
MoveToProjectSheet(post: post, projects: model.moveTargets()) { project in
|
||||||
model.moveToProject(post, project: project, home: home)
|
model.moveToProject(post, project: project)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #144: keystroke-debounced (250 ms), structured body scan —
|
// #144: keystroke-debounced (250 ms), structured body scan —
|
||||||
@@ -355,7 +355,7 @@ struct PostsLibraryColumn: View {
|
|||||||
/// render the same row (#144: results carry the full menu too).
|
/// render the same row (#144: results carry the full menu too).
|
||||||
private func postRow(_ post: Post) -> some View {
|
private func postRow(_ post: Post) -> some View {
|
||||||
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
|
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
}
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
Button("Rename…") { renamingPost = post }
|
Button("Rename…") { renamingPost = post }
|
||||||
@@ -363,15 +363,15 @@ struct PostsLibraryColumn: View {
|
|||||||
// body transform, then the piece becomes a prose post.
|
// body transform, then the piece becomes a prose post.
|
||||||
if post.type == .outline {
|
if post.type == .outline {
|
||||||
Button("Convert to Post…") {
|
Button("Convert to Post…") {
|
||||||
model.stageConversion(post, home: home)
|
model.stageConversion(post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button("Move to Project…") { movingPost = post }
|
Button("Move to Project…") { movingPost = post }
|
||||||
Button("Move to Archive") {
|
Button("Move to Archive") {
|
||||||
model.archivePost(post, home: home)
|
model.archivePost(post)
|
||||||
}
|
}
|
||||||
Button("Move to Trash", role: .destructive) {
|
Button("Move to Trash", role: .destructive) {
|
||||||
model.trash(post, home: home)
|
model.trash(post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ struct PromoteAskSheet: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func promote() {
|
private func promote() {
|
||||||
switch posts.promoteCard(card, home: home) {
|
switch posts.promoteCard(card) {
|
||||||
case .promoted:
|
case .promoted:
|
||||||
dismiss()
|
dismiss()
|
||||||
case let .refused(reason):
|
case let .refused(reason):
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ struct SessionsPaneView: View {
|
|||||||
/// (ApplyAskSheet posture — the edited draft is never destroyed).
|
/// (ApplyAskSheet posture — the edited draft is never destroyed).
|
||||||
private func newPostFromSession() -> String? {
|
private func newPostFromSession() -> String? {
|
||||||
guard let posts, let home else { return "No library to write into." }
|
guard let posts, let home else { return "No library to write into." }
|
||||||
if posts.newPostFromSession(body: sessionDraft ?? "", home: home) == nil {
|
if posts.newPostFromSession(body: sessionDraft ?? "") == nil {
|
||||||
return posts.lastError ?? "The piece couldn't be written."
|
return posts.lastError ?? "The piece couldn't be written."
|
||||||
}
|
}
|
||||||
sessionDraft = nil
|
sessionDraft = nil
|
||||||
|
|||||||
+10
-10
@@ -117,14 +117,14 @@ struct WorkspaceView: View {
|
|||||||
// answer (Esc/Cancel) drops the batch.
|
// answer (Esc/Cancel) drops the batch.
|
||||||
.sheet(isPresented: originAskBinding) {
|
.sheet(isPresented: originAskBinding) {
|
||||||
OriginAskSheet(count: gate.posts.pendingImportURLs?.count ?? 0) { origin in
|
OriginAskSheet(count: gate.posts.pendingImportURLs?.count ?? 0) { origin in
|
||||||
gate.posts.importFiles(origin: origin, home: gate.museionHome)
|
gate.posts.importFiles(origin: origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #108: File ▸ New Project… ask — commands can't present sheets, so
|
// #108: File ▸ New Project… ask — commands can't present sheets, so
|
||||||
// the model stages and this window presents (OriginAsk pattern).
|
// the model stages and this window presents (OriginAsk pattern).
|
||||||
.sheet(isPresented: newProjectAskBinding) {
|
.sheet(isPresented: newProjectAskBinding) {
|
||||||
NewProjectSheet { name in
|
NewProjectSheet { name in
|
||||||
if let reason = gate.posts.createProject(named: name, home: gate.museionHome) {
|
if let reason = gate.posts.createProject(named: name) {
|
||||||
return reason
|
return reason
|
||||||
}
|
}
|
||||||
gate.posts.newProjectPending(named: name)
|
gate.posts.newProjectPending(named: name)
|
||||||
@@ -137,9 +137,9 @@ struct WorkspaceView: View {
|
|||||||
// drop; Esc/Cancel backs out with nothing opened.
|
// drop; Esc/Cancel backs out with nothing opened.
|
||||||
.sheet(isPresented: outlineGuardBinding) {
|
.sheet(isPresented: outlineGuardBinding) {
|
||||||
OutlineGuardSheet {
|
OutlineGuardSheet {
|
||||||
gate.posts.openGuardedOutlineInProse(home: gate.museionHome)
|
gate.posts.openGuardedOutlineInProse()
|
||||||
} openAsOutline: {
|
} openAsOutline: {
|
||||||
gate.posts.openGuardedOutlineAsOutline(home: gate.museionHome)
|
gate.posts.openGuardedOutlineAsOutline()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #114 (S4): the Convert to Post ask — which body the outline
|
// #114 (S4): the Convert to Post ask — which body the outline
|
||||||
@@ -147,7 +147,7 @@ struct WorkspaceView: View {
|
|||||||
// is the default: lossless. Esc/Cancel converts nothing.
|
// is the default: lossless. Esc/Cancel converts nothing.
|
||||||
.sheet(isPresented: convertAskBinding) {
|
.sheet(isPresented: convertAskBinding) {
|
||||||
ConvertSheet(lossy: gate.posts.pendingConversion?.lossy ?? false) { headingsLadder in
|
ConvertSheet(lossy: gate.posts.pendingConversion?.lossy ?? false) { headingsLadder in
|
||||||
gate.posts.convertToPost(headingsLadder: headingsLadder, home: gate.museionHome)
|
gate.posts.convertToPost(headingsLadder: headingsLadder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,7 +437,7 @@ private struct ArchivePaneView: View {
|
|||||||
// 'Unarchive Group' — it moves the whole
|
// 'Unarchive Group' — it moves the whole
|
||||||
// project, not one piece.
|
// project, not one piece.
|
||||||
Button("Unarchive Group") {
|
Button("Unarchive Group") {
|
||||||
model.unarchiveProject(project, home: home)
|
model.unarchiveProject(project)
|
||||||
}
|
}
|
||||||
.buttonStyle(BorderedSecondaryButtonStyle(minHeight: 24))
|
.buttonStyle(BorderedSecondaryButtonStyle(minHeight: 24))
|
||||||
.help("Move the whole project back to projects/")
|
.help("Move the whole project back to projects/")
|
||||||
@@ -453,7 +453,7 @@ private struct ArchivePaneView: View {
|
|||||||
// at x28 (the one indent). The hairline is
|
// at x28 (the one indent). The hairline is
|
||||||
// BOUNDED to the fixed frame: x14 → 706.
|
// BOUNDED to the fixed frame: x14 → 706.
|
||||||
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
|
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
onOpenPiece()
|
onOpenPiece()
|
||||||
}
|
}
|
||||||
.overlay(alignment: .bottom) {
|
.overlay(alignment: .bottom) {
|
||||||
@@ -464,14 +464,14 @@ private struct ArchivePaneView: View {
|
|||||||
}
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
Button("Move Back to \(post.project)") {
|
Button("Move Back to \(post.project)") {
|
||||||
model.restorePost(post, home: home)
|
model.restorePost(post)
|
||||||
}
|
}
|
||||||
Button("Rename…") { renamingPost = post }
|
Button("Rename…") { renamingPost = post }
|
||||||
// #114 (S4): works archived too — the piece
|
// #114 (S4): works archived too — the piece
|
||||||
// stays where it is, only type + body flip.
|
// stays where it is, only type + body flip.
|
||||||
if post.type == .outline {
|
if post.type == .outline {
|
||||||
Button("Convert to Post…") {
|
Button("Convert to Post…") {
|
||||||
model.stageConversion(post, home: home)
|
model.stageConversion(post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -496,7 +496,7 @@ private struct ArchivePaneView: View {
|
|||||||
.background(DesignTokens.background)
|
.background(DesignTokens.background)
|
||||||
.sheet(item: $renamingPost) { post in
|
.sheet(item: $renamingPost) { post in
|
||||||
RenamePostSheet(post: post) { title in
|
RenamePostSheet(post: post) { title in
|
||||||
model.rename(post, to: title, home: home)
|
model.rename(post, to: title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ struct BlindReadTests {
|
|||||||
private func openJudgedPiece(on model: PostsModel, home: URL, snapshot: String, current: String) async throws -> String {
|
private func openJudgedPiece(on model: PostsModel, home: URL, snapshot: String, current: String) async throws -> String {
|
||||||
let post = try PostStore.writeNew(body: current, home: home)
|
let post = try PostStore.writeNew(body: current, home: home)
|
||||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: snapshot, 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 }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
@@ -199,14 +199,14 @@ struct BlindReadTests {
|
|||||||
await rig.mentor.openSession()
|
await rig.mentor.openSession()
|
||||||
_ = try await openJudgedPiece(on: rig.model, home: rig.home, snapshot: "Older prose.", current: "Newer prose.")
|
_ = 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 {
|
for _ in 0 ..< 250 where !rig.model.runningBlindRead {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
#expect(rig.model.runningBlindRead)
|
#expect(rig.model.runningBlindRead)
|
||||||
|
|
||||||
// Mutual exclusion — a pass refuses while the read owns the rail.
|
// 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)
|
#expect(rig.model.lastError?.contains("already running") == true)
|
||||||
|
|
||||||
// The pass bar's Cancel rail ends the held read — no reveal,
|
// 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",
|
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
|
// The prompt carried BOTH bodies inline — and no path: the judge
|
||||||
// cannot learn which file is which (the engines' prompt log).
|
// cannot learn which file is which (the engines' prompt log).
|
||||||
@@ -262,20 +262,20 @@ struct BlindReadTests {
|
|||||||
defer { rig.mentor.shutdown() }
|
defer { rig.mentor.shutdown() }
|
||||||
await rig.mentor.openSession()
|
await rig.mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Fresh\n\nNo pass yet.", home: rig.home)
|
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 }) {
|
for _ in 0 ..< 250 where !rig.model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// No pass ever ran — refuse, spawn nothing beyond the resident engine.
|
// 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(rig.model.lastError?.contains("run a Pass") == true)
|
||||||
#expect(museionSpawns(rig) == 1)
|
#expect(museionSpawns(rig) == 1)
|
||||||
|
|
||||||
// Snapshot exists but the document is unchanged since — a vacuous
|
// Snapshot exists but the document is unchanged since — a vacuous
|
||||||
// read refuses honestly.
|
// read refuses honestly.
|
||||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: "# Fresh\n\nNo pass yet.", home: rig.home)
|
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)
|
#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 chatBefore = rig.mentor.host.chat
|
||||||
let rosterBefore = rig.mentor.roster.count
|
let rosterBefore = rig.mentor.roster.count
|
||||||
let post = try PostStore.writeNew(body: "# Own Engine\n\nVerdict me.", home: rig.home)
|
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 }) {
|
for _ in 0 ..< 250 where !rig.model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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
|
// In a Task — a full-mode scripted pass can complete inside one poll
|
||||||
// sleep (no child-process latency anymore), so the pass ENGINE is
|
// sleep (no child-process latency anymore), so the pass ENGINE is
|
||||||
// captured after the run from the spawn records, not polled mid-flight.
|
// 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
|
_ = await run.value
|
||||||
let passEngine = rig.engines.engines.last { $0.spawnedProfile == "museion-pass1" }
|
let passEngine = rig.engines.engines.last { $0.spawnedProfile == "museion-pass1" }
|
||||||
let passEngineClosed = try #require(passEngine, "pass engine never spawned")
|
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()
|
await rig.mentor.openSession()
|
||||||
let rosterBefore = rig.mentor.roster.count
|
let rosterBefore = rig.mentor.roster.count
|
||||||
let post = try PostStore.writeNew(body: "# Held Pass\n\nCancel me.", home: rig.home)
|
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")
|
let heldEngine = try #require(await pollOneShot(of: rig.mentor), "pass engine never spawned")
|
||||||
#expect(rig.mentor.isPassEngineRunning)
|
#expect(rig.mentor.isPassEngineRunning)
|
||||||
|
|
||||||
@@ -291,7 +291,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
|
|||||||
rig.mentor.passReadinessWriter = writer
|
rig.mentor.passReadinessWriter = writer
|
||||||
await rig.mentor.refreshPassReadiness()
|
await rig.mentor.refreshPassReadiness()
|
||||||
let post = try PostStore.writeNew(body: "# No Key\n\nPass me.", home: rig.home)
|
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 {
|
for _ in 0 ..< 250 where rig.model.session?.postID != post.id {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
@@ -299,7 +299,7 @@ private func pollOneShot(of mentor: MentorSessionModel) async throws -> Scripted
|
|||||||
// this pin vacuously.
|
// this pin vacuously.
|
||||||
try #require(rig.model.session?.postID == post.id)
|
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.")
|
#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)")
|
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
|
_ = await rig.mentor.newSession(name: "Second", pieceTitle: nil) // sess-2 active
|
||||||
let target = try #require(rig.mentor.roster.last) // sess-1, NOT 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)
|
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 }) {
|
for _ in 0 ..< 250 where !rig.model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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
|
// pass prompt then HOLDS, so isStreaming is guaranteed when the parked
|
||||||
// load completes, and the #124 Cancel rail frees it afterwards.
|
// load completes, and the #124 Cancel rail frees it afterwards.
|
||||||
rig.engines.mode = "hangOnPrompt"
|
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 {
|
for _ in 0 ..< 250 where !rig.mentor.isPassEngineRunning {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ struct EngineSmokeTests {
|
|||||||
await mentor.openSession() // the resident chat engine
|
await mentor.openSession() // the resident chat engine
|
||||||
let chatPid = try #require(mentor.childProcessIdentifier)
|
let chatPid = try #require(mentor.childProcessIdentifier)
|
||||||
let post = try PostStore.writeNew(body: "# Smoke Pass\n\nVerdict me.", home: home)
|
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 }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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
|
// In a Task — the pass child's pid is only observable while it runs
|
||||||
// (the old EngineLifecycleTests poll; the zsh wire latency holds the
|
// (the old EngineLifecycleTests poll; the zsh wire latency holds the
|
||||||
// turn open long enough to catch it).
|
// 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 passPid: pid_t?
|
||||||
var polls = 0
|
var polls = 0
|
||||||
while passPid == nil, polls < 250 {
|
while passPid == nil, polls < 250 {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ struct FixCardApplyTests {
|
|||||||
piecePath: folder.path,
|
piecePath: folder.path,
|
||||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
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 session = try #require(model.session)
|
||||||
let generation = session.loadGeneration
|
let generation = session.loadGeneration
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ struct FixCardApplyTests {
|
|||||||
// buffer first (flush-first, like every op that reads the piece).
|
// buffer first (flush-first, like every op that reads the piece).
|
||||||
session.edit("# Carded\n\nThe anchor sentence.\nPlus a typed line.\n")
|
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...
|
// 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")
|
#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,
|
piecePath: folder.path,
|
||||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
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.
|
// The Post changed after the card was issued — the quote is gone.
|
||||||
model.session?.edit("# Carded\n\nThe sentence changed.\n")
|
model.session?.edit("# Carded\n\nThe sentence changed.\n")
|
||||||
model.session?.flush()
|
model.session?.flush()
|
||||||
let postURL = folder.appendingPathComponent("post.md")
|
let postURL = folder.appendingPathComponent("post.md")
|
||||||
let before = try Data(contentsOf: postURL)
|
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
|
#expect(try Data(contentsOf: postURL) == before) // nothing selected, nothing changed
|
||||||
let diskCard = try #require(FixCardStore.scan(pieceURL: folder).first)
|
let diskCard = try #require(FixCardStore.scan(pieceURL: folder).first)
|
||||||
@@ -104,11 +104,11 @@ struct FixCardApplyTests {
|
|||||||
piecePath: folder.path,
|
piecePath: folder.path,
|
||||||
cards: [card(pattern: "Demo", fix: "The replaced sentence.", quote: "The anchor sentence.", lane: .demonstration)],
|
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 postURL = folder.appendingPathComponent("post.md")
|
||||||
let before = try Data(contentsOf: postURL)
|
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 {
|
guard case let .refused(why) = outcome else {
|
||||||
Issue.record("expected refusal, got \(outcome)")
|
Issue.record("expected refusal, got \(outcome)")
|
||||||
return
|
return
|
||||||
@@ -127,7 +127,7 @@ struct FixCardApplyTests {
|
|||||||
piecePath: folder.path,
|
piecePath: folder.path,
|
||||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
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
|
// A foreign write lands on disk underneath the writer (#67) — the
|
||||||
// reload question is up and unanswered.
|
// reload question is up and unanswered.
|
||||||
let postURL = folder.appendingPathComponent("post.md")
|
let postURL = folder.appendingPathComponent("post.md")
|
||||||
@@ -135,7 +135,7 @@ struct FixCardApplyTests {
|
|||||||
model.session?.diskDidChange(diskText: "foreign text on disk")
|
model.session?.diskDidChange(diskText: "foreign text on disk")
|
||||||
let before = try Data(contentsOf: postURL)
|
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 {
|
guard case let .refused(why) = outcome else {
|
||||||
Issue.record("expected refusal, got \(outcome)")
|
Issue.record("expected refusal, got \(outcome)")
|
||||||
return
|
return
|
||||||
@@ -157,15 +157,15 @@ struct FixCardApplyTests {
|
|||||||
card(pattern: "Telling", quote: "The anchor sentence."),
|
card(pattern: "Telling", quote: "The anchor sentence."),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
let postURL = folder.appendingPathComponent("post.md")
|
let postURL = folder.appendingPathComponent("post.md")
|
||||||
let before = try Data(contentsOf: postURL)
|
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 }
|
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)
|
#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 }
|
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)
|
#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,
|
piecePath: folder.path,
|
||||||
cards: [card(fix: "The replaced sentence.", quote: "The anchor sentence.")],
|
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?.edit("# Carded\n\nThe sentence changed.\n") // stale the anchor
|
||||||
model.session?.flush()
|
model.session?.flush()
|
||||||
let postURL = folder.appendingPathComponent("post.md")
|
let postURL = folder.appendingPathComponent("post.md")
|
||||||
@@ -252,7 +252,7 @@ struct FixCardApplyTests {
|
|||||||
try FileManager.default.setAttributes([.posixPermissions: 0o000], ofItemAtPath: cardsDir.path)
|
try FileManager.default.setAttributes([.posixPermissions: 0o000], ofItemAtPath: cardsDir.path)
|
||||||
defer { try? FileManager.default.setAttributes([.posixPermissions: 0o755], 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(model.lastError?.contains("card close failed") == true) // …and the flag failure is loud
|
||||||
#expect(try Data(contentsOf: postURL) == before) // still nothing selected or changed
|
#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
|
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)
|
#expect(model.session?.loadFailed == true)
|
||||||
// The writer typed the anchor into the empty failed-session buffer.
|
// The writer typed the anchor into the empty failed-session buffer.
|
||||||
model.session?.edit("The anchor sentence. typed nowhere durable.")
|
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 {
|
guard case .refused = outcome else {
|
||||||
Issue.record("expected refusal, got \(outcome)")
|
Issue.record("expected refusal, got \(outcome)")
|
||||||
return
|
return
|
||||||
@@ -295,9 +295,9 @@ struct FixCardApplyTests {
|
|||||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
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 folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||||
let written = try FixCardStore.submit(piecePath: folder.path, cards: [card()])
|
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)
|
let learnings = home.appendingPathComponent("learnings/posts", isDirectory: true)
|
||||||
#expect(try FileManager.default.contentsOfDirectory(atPath: learnings.path).filter { $0.hasSuffix(".md") }.count == 1)
|
#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).
|
// Already promoted → refused, no second file (one confirm = one entry).
|
||||||
let scanned = try #require(FixCardStore.scan(pieceURL: folder).first)
|
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)
|
#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 folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||||
let written = try FixCardStore.submit(piecePath: folder.path, cards: [card()])
|
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(!FileManager.default.fileExists(atPath: home.appendingPathComponent("learnings").path))
|
||||||
#expect(model.lastError == nil)
|
#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 {
|
@Test @MainActor func `sendDraft flushes the open piece and sends the disk body with the title`() async throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Flush Me\n\nOriginal.", home: home)
|
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
|
model.session?.edit("# Flush Me\n\nEdited on the way.") // inside the debounce window
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
let log = MicropubRequestLog()
|
||||||
let outcome = await model.micropubSendDraft(
|
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),
|
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/flush-me"], log: log),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ struct MicropubModelTests {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let log = MicropubRequestLog()
|
let log = MicropubRequestLog()
|
||||||
let outcome = await model.micropubSendDraft(
|
let outcome = await model.micropubSendDraft(
|
||||||
home: home, token: "tok",
|
token: "tok",
|
||||||
transport: micropubCanned(201, body: "{}", log: log),
|
transport: micropubCanned(201, body: "{}", log: log),
|
||||||
)
|
)
|
||||||
guard case .refused = outcome else {
|
guard case .refused = outcome else {
|
||||||
@@ -58,7 +58,7 @@ struct MicropubModelTests {
|
|||||||
model.newPost() // staged draft — no folder, no session
|
model.newPost() // staged draft — no folder, no session
|
||||||
let log = MicropubRequestLog()
|
let log = MicropubRequestLog()
|
||||||
let outcome = await model.micropubSendDraft(
|
let outcome = await model.micropubSendDraft(
|
||||||
home: home, token: "tok",
|
token: "tok",
|
||||||
transport: micropubCanned(201, body: "{}", log: log),
|
transport: micropubCanned(201, body: "{}", log: log),
|
||||||
)
|
)
|
||||||
guard case .refused = outcome else {
|
guard case .refused = outcome else {
|
||||||
@@ -73,11 +73,11 @@ struct MicropubModelTests {
|
|||||||
// All-whitespace body — no Title, no content (a heading-only
|
// All-whitespace body — no Title, no content (a heading-only
|
||||||
// piece DOES send: the Title line is content on Micro.blog).
|
// piece DOES send: the Title line is content on Micro.blog).
|
||||||
let post = try PostStore.writeNew(body: " \n", home: home)
|
let post = try PostStore.writeNew(body: " \n", home: home)
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
let log = MicropubRequestLog()
|
||||||
let outcome = await model.micropubSendDraft(
|
let outcome = await model.micropubSendDraft(
|
||||||
home: home, token: "tok",
|
token: "tok",
|
||||||
transport: micropubCanned(201, body: "{}", log: log),
|
transport: micropubCanned(201, body: "{}", log: log),
|
||||||
)
|
)
|
||||||
guard case .refused = outcome else {
|
guard case .refused = outcome else {
|
||||||
@@ -91,7 +91,7 @@ struct MicropubModelTests {
|
|||||||
@Test @MainActor func `frontmatter category never travels`() async throws {
|
@Test @MainActor func `frontmatter category never travels`() async throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Categorized\n\nBody.", home: home)
|
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.
|
// The writer's own category frontmatter — permitted, inert.
|
||||||
let fileURL = try #require(PostStore.folder(of: post.id, home: home)?.appendingPathComponent("post.md"))
|
let fileURL = try #require(PostStore.folder(of: post.id, home: home)?.appendingPathComponent("post.md"))
|
||||||
let raw = try String(contentsOf: fileURL, encoding: .utf8)
|
let raw = try String(contentsOf: fileURL, encoding: .utf8)
|
||||||
@@ -100,7 +100,7 @@ struct MicropubModelTests {
|
|||||||
|
|
||||||
let log = MicropubRequestLog()
|
let log = MicropubRequestLog()
|
||||||
_ = await model.micropubSendDraft(
|
_ = await model.micropubSendDraft(
|
||||||
home: home, token: "tok",
|
token: "tok",
|
||||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/categorized"], log: log),
|
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 {
|
@Test @MainActor func `a failed draft stamps nothing`() async throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Fails\n\nBody.", home: home)
|
let post = try PostStore.writeNew(body: "# Fails\n\nBody.", home: home)
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
let log = MicropubRequestLog()
|
||||||
_ = await model.micropubSendDraft(
|
_ = await model.micropubSendDraft(
|
||||||
home: home, token: "tok",
|
token: "tok",
|
||||||
transport: micropubCanned(500, body: "{}", log: log),
|
transport: micropubCanned(500, body: "{}", log: log),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -127,15 +127,15 @@ struct MicropubModelTests {
|
|||||||
@Test @MainActor func `re-drafting overwrites the remembered url`() async throws {
|
@Test @MainActor func `re-drafting overwrites the remembered url`() async throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Again\n\nBody.", home: home)
|
let post = try PostStore.writeNew(body: "# Again\n\nBody.", home: home)
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
let log = MicropubRequestLog()
|
||||||
_ = await model.micropubSendDraft(
|
_ = await model.micropubSendDraft(
|
||||||
home: home, token: "tok",
|
token: "tok",
|
||||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/first"], log: log),
|
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/first"], log: log),
|
||||||
)
|
)
|
||||||
_ = await model.micropubSendDraft(
|
_ = await model.micropubSendDraft(
|
||||||
home: home, token: "tok",
|
token: "tok",
|
||||||
transport: micropubCanned(201, body: "{}", headers: ["Location": "https://example.micro.blog/second"], log: log),
|
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.
|
/// 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 {
|
@MainActor private func plantIllustratedPiece(_ model: PostsModel, _ home: URL, body: String) throws -> URL {
|
||||||
let post = try PostStore.writeNew(body: body, home: home)
|
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))
|
let dir = try #require(PostStore.folder(of: post.id, home: home))
|
||||||
try FileManager.default.createDirectory(at: dir.appendingPathComponent("assets", isDirectory: true), withIntermediateDirectories: true)
|
try FileManager.default.createDirectory(at: dir.appendingPathComponent("assets", isDirectory: true), withIntermediateDirectories: true)
|
||||||
try micropubPNG().write(to: dir.appendingPathComponent("assets/path.png"))
|
try micropubPNG().write(to: dir.appendingPathComponent("assets/path.png"))
|
||||||
@@ -162,7 +162,7 @@ struct MicropubModelTests {
|
|||||||
)
|
)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
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))
|
#expect(outcome == .drafted(url: "https://example.micro.blog/inked", preview: nil))
|
||||||
// The three hops, in order: q=config → upload → create.
|
// The three hops, in order: q=config → upload → create.
|
||||||
@@ -197,7 +197,7 @@ struct MicropubModelTests {
|
|||||||
)
|
)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
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 {
|
guard case let .refused(reason) = outcome else {
|
||||||
Issue.record("expected refused, got \(outcome)")
|
Issue.record("expected refused, got \(outcome)")
|
||||||
@@ -228,7 +228,7 @@ struct MicropubModelTests {
|
|||||||
)
|
)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
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 {
|
guard case let .refused(reason) = outcome else {
|
||||||
Issue.record("expected refused, got \(outcome)")
|
Issue.record("expected refused, got \(outcome)")
|
||||||
@@ -246,7 +246,7 @@ struct MicropubModelTests {
|
|||||||
)
|
)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
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))
|
#expect(outcome == .drafted(url: "https://example.micro.blog/inked", preview: nil))
|
||||||
// config + ONE upload + create — the FILE uploads once, not once per ref.
|
// config + ONE upload + create — the FILE uploads once, not once per ref.
|
||||||
@@ -266,7 +266,7 @@ struct MicropubModelTests {
|
|||||||
) // path.png planted, ghost.png never
|
) // path.png planted, ghost.png never
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
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 {
|
guard case .refused = outcome else {
|
||||||
Issue.record("expected refused, got \(outcome)")
|
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 {
|
@Test @MainActor func `a piece without illustrations sends exactly one request`() async throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Plain\n\nBody.", home: home)
|
let post = try PostStore.writeNew(body: "# Plain\n\nBody.", home: home)
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
|
|
||||||
let log = MicropubRequestLog()
|
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.
|
// The #33 path unchanged: no config round-trip, straight to the create.
|
||||||
#expect(log.requests.count == 1)
|
#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
|
defer { mentor.shutdown() } // #124: at rig creation — the child dies with the test, however it exits
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Pass Piece\n\nThe body under pass.", home: home)
|
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
|
// Wait for the bind rescan to surface the piece — the pass label reads
|
||||||
// the library's title for it (the PostsModelTests poll pattern).
|
// the library's title for it (the PostsModelTests poll pattern).
|
||||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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 piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||||
let snapshot = try String(contentsOf: piece.appendingPathComponent("passes/pass-1.md"), encoding: .utf8)
|
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() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Cancel Me\n\nStill first draft.", home: home)
|
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)")
|
let piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||||
// Pre-pass is unconditional — the snapshot landed anyway.
|
// Pre-pass is unconditional — the snapshot landed anyway.
|
||||||
@@ -91,9 +91,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Refused\n\nAlso first draft.", home: home)
|
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(
|
let onDisk = try String(
|
||||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||||
@@ -108,7 +108,7 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
model.newPost() // draft staged — no folder exists
|
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)
|
#expect(model.lastError?.contains("post") == true)
|
||||||
// Nothing landed on disk — the draft never even materialized a folder.
|
// Nothing landed on disk — the draft never even materialized a folder.
|
||||||
@@ -120,15 +120,15 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Held\n\nMid-pass.", home: home)
|
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 {
|
for _ in 0 ..< 250 where model.runningPass == nil {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
#expect(model.runningPass == .pass1)
|
#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)
|
#expect(model.lastError?.contains("already running") == true)
|
||||||
|
|
||||||
model.cancelPass(mentor: mentor) // the pass bar's Cancel rail
|
model.cancelPass(mentor: mentor) // the pass bar's Cancel rail
|
||||||
@@ -147,9 +147,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Held\n\nCancel me.", home: home)
|
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 {
|
for _ in 0 ..< 250 where model.runningPass == nil {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Busy\n\nMentor chatting.", home: home)
|
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") }
|
let chat = Task { await mentor.sendPrompt("just chatting") }
|
||||||
for _ in 0 ..< 250 where !mentor.isStreaming {
|
for _ in 0 ..< 250 where !mentor.isStreaming {
|
||||||
@@ -185,7 +185,7 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
}
|
}
|
||||||
#expect(mentor.isStreaming)
|
#expect(mentor.isStreaming)
|
||||||
|
|
||||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
await model.runPass(.pass1, mentor: mentor)
|
||||||
#expect(model.lastError?.contains("mid-reply") == true)
|
#expect(model.lastError?.contains("mid-reply") == true)
|
||||||
// The guard fired before the snapshot — nothing on disk.
|
// The guard fired before the snapshot — nothing on disk.
|
||||||
#expect(!FileManager.default.fileExists(
|
#expect(!FileManager.default.fileExists(
|
||||||
@@ -199,9 +199,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
let (model, home, mentor) = try makePassRig() // never opened — engine idle
|
let (model, home, mentor) = try makePassRig() // never opened — engine idle
|
||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
let post = try PostStore.writeNew(body: "# Cold\n\nNo engine yet.", home: home)
|
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(model.lastError?.contains("isn't ready") == true)
|
||||||
#expect(!FileManager.default.fileExists(
|
#expect(!FileManager.default.fileExists(
|
||||||
@@ -214,10 +214,10 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Flush First\n\nOriginal.", home: home)
|
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
|
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 piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||||
let snapshot = try String(contentsOf: piece.appendingPathComponent("passes/pass-1.md"), encoding: .utf8)
|
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() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Free Order\n\nStraight to two.", home: home)
|
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(
|
let onDisk = try String(
|
||||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||||
@@ -248,12 +248,12 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Stats Piece\n\nOne two three. Four five! Six?", home: home)
|
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 }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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(
|
let onDisk = try String(
|
||||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||||
@@ -275,9 +275,9 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Cancelled Stats\n\nOne two three. Four five!", home: home)
|
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(
|
let onDisk = try String(
|
||||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
||||||
@@ -295,12 +295,12 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
|||||||
defer { mentor.shutdown() }
|
defer { mentor.shutdown() }
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# AI Piece\n\nMachine-born prose.", origin: .ai, home: home)
|
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 }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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(
|
let onDisk = try String(
|
||||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8,
|
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 — "
|
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."
|
+ "and again — and once more — to clear the dash budget. Utilize it twice."
|
||||||
let post = try PostStore.writeNew(body: body, home: home)
|
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 }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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 piece = home.appendingPathComponent("projects/posts/\(post.id)")
|
||||||
let cards = FixCardStore.scan(pieceURL: piece.appendingPathComponent("post.md"))
|
let cards = FixCardStore.scan(pieceURL: piece.appendingPathComponent("post.md"))
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
@Test @MainActor func `archiving the open piece clears selection and session`() throws {
|
@Test @MainActor func `archiving the open piece clears selection and session`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Gone Soon\n", home: home)
|
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)
|
#expect(model.session?.postID == post.id)
|
||||||
|
|
||||||
model.archivePost(post, home: home)
|
model.archivePost(post)
|
||||||
|
|
||||||
#expect(model.selectedPostID == nil)
|
#expect(model.selectedPostID == nil)
|
||||||
#expect(model.session == nil)
|
#expect(model.session == nil)
|
||||||
@@ -41,10 +41,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
@Test @MainActor func `moving the open piece reopens its session at the new parent`() throws {
|
@Test @MainActor func `moving the open piece reopens its session at the new parent`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Traveler\n", project: "essays", home: home)
|
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)
|
#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?.postID == post.id) // same piece, fresh session
|
||||||
#expect(model.session?.folderURL.path.contains("projects/posts/\(post.id)") == true)
|
#expect(model.session?.folderURL.path.contains("projects/posts/\(post.id)") == true)
|
||||||
@@ -55,10 +55,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Revived\n", home: home)
|
let post = try PostStore.writeNew(body: "# Revived\n", home: home)
|
||||||
try PostStore.archive(post, 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)
|
#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.selectedPostID == post.id) // the writer stays in it
|
||||||
#expect(model.session?.folderURL.path.contains("projects/posts/\(post.id)") == true)
|
#expect(model.session?.folderURL.path.contains("projects/posts/\(post.id)") == true)
|
||||||
@@ -73,7 +73,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
#expect(model.draft?.project == "essays")
|
#expect(model.draft?.project == "essays")
|
||||||
|
|
||||||
model.updateDraft("# Fresh\n")
|
model.updateDraft("# Fresh\n")
|
||||||
model.saveDraft(home: home)
|
model.saveDraft()
|
||||||
|
|
||||||
let scanned = Post.scan(home: home)
|
let scanned = Post.scan(home: home)
|
||||||
#expect(scanned.first?.project == "essays")
|
#expect(scanned.first?.project == "essays")
|
||||||
@@ -100,10 +100,10 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Keeper\n", home: home)
|
let post = try PostStore.writeNew(body: "# Keeper\n", home: home)
|
||||||
try PostStore.archive(post, 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.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).
|
// The edits landed on disk (readBody resolves by id — through the move).
|
||||||
#expect(PostStore.readBody(id: post.id, home: home) == "# Keeper\n\nDirty.")
|
#expect(PostStore.readBody(id: post.id, home: home) == "# Keeper\n\nDirty.")
|
||||||
@@ -121,7 +121,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
}
|
}
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
|
|
||||||
model.newOutline()
|
model.newOutline()
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
|
|
||||||
model.newOutline()
|
model.newOutline()
|
||||||
model.saveDraft(home: home)
|
model.saveDraft()
|
||||||
|
|
||||||
#expect(model.draft == nil)
|
#expect(model.draft == nil)
|
||||||
#expect(model.lastError == nil)
|
#expect(model.lastError == nil)
|
||||||
@@ -157,7 +157,7 @@ func makeModelHome() throws -> (PostsModel, URL) {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
try PostStore.createProject(named: "essays", home: home) // empty — no pieces
|
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.
|
// "posts" exists too (bind created it); a dot-project never shows.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home)
|
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.outlineGuardPieceID == post.id) // the ask is up
|
||||||
#expect(model.session == nil) // nothing editable while it's up
|
#expect(model.session == nil) // nothing editable while it's up
|
||||||
@@ -191,8 +191,8 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home)
|
let post = try writeMixedOutline(home: home)
|
||||||
|
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
model.openGuardedOutlineInProse(home: home)
|
model.openGuardedOutlineInProse()
|
||||||
|
|
||||||
#expect(model.outlineGuardPieceID == nil)
|
#expect(model.outlineGuardPieceID == nil)
|
||||||
#expect(model.session?.postID == post.id)
|
#expect(model.session?.postID == post.id)
|
||||||
@@ -209,8 +209,8 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home)
|
let post = try writeMixedOutline(home: home)
|
||||||
|
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
model.openGuardedOutlineAsOutline(home: home)
|
model.openGuardedOutlineAsOutline()
|
||||||
|
|
||||||
#expect(model.outlineGuardPieceID == nil)
|
#expect(model.outlineGuardPieceID == nil)
|
||||||
#expect(model.session?.postID == post.id)
|
#expect(model.session?.postID == post.id)
|
||||||
@@ -226,13 +226,13 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home)
|
let post = try writeMixedOutline(home: home)
|
||||||
|
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
model.cancelOutlineGuard()
|
model.cancelOutlineGuard()
|
||||||
|
|
||||||
#expect(model.outlineGuardPieceID == nil)
|
#expect(model.outlineGuardPieceID == nil)
|
||||||
#expect(model.session == nil)
|
#expect(model.session == nil)
|
||||||
// Still guarded: the next open re-fires the ask, file untouched.
|
// 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)
|
#expect(model.outlineGuardPieceID == post.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,12 +242,12 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home)
|
let post = try writeMixedOutline(home: home)
|
||||||
|
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
model.openGuardedOutlineAsOutline(home: home) // consent; disk still mixed
|
model.openGuardedOutlineAsOutline() // consent; disk still mixed
|
||||||
let session = try #require(model.session)
|
let session = try #require(model.session)
|
||||||
session.edit("- one\n- two\nedited") // dirty; debounce armed
|
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.outlineGuardPieceID == nil) // no re-ask over a prior answer
|
||||||
#expect(model.session === session) // the open session survives, dirty state intact
|
#expect(model.session === session) // the open session survives, dirty state intact
|
||||||
@@ -257,15 +257,15 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home)
|
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
|
model.newPost() // ⌘N fires while the sheet is up
|
||||||
#expect(model.outlineGuardPieceID == nil) // the ask died with the displacement
|
#expect(model.outlineGuardPieceID == nil) // the ask died with the displacement
|
||||||
#expect(model.draft != nil)
|
#expect(model.draft != nil)
|
||||||
|
|
||||||
model.updateDraft("# Keep me\n")
|
model.updateDraft("# Keep me\n")
|
||||||
// Answering the (now-gone) ask is inert — the draft survives.
|
// Answering the (now-gone) ask is inert — the draft survives.
|
||||||
model.openGuardedOutlineInProse(home: home)
|
model.openGuardedOutlineInProse()
|
||||||
model.openGuardedOutlineAsOutline(home: home)
|
model.openGuardedOutlineAsOutline()
|
||||||
#expect(model.draft != nil)
|
#expect(model.draft != nil)
|
||||||
#expect(model.selectedPostID == nil) // the draft still owns the editor
|
#expect(model.selectedPostID == nil) // the draft still owns the editor
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
}
|
}
|
||||||
#expect(model.posts.contains(where: { $0.id == post.id }))
|
#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
|
#expect(model.outlineGuardPieceID == post.id) // the scan path guards too
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,11 +288,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 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)
|
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.outlineGuardPieceID == nil)
|
||||||
#expect(model.session?.postID == clean.id)
|
#expect(model.session?.postID == clean.id)
|
||||||
|
|
||||||
model.select(prose.id, home: home)
|
model.select(prose.id)
|
||||||
#expect(model.outlineGuardPieceID == nil)
|
#expect(model.outlineGuardPieceID == nil)
|
||||||
#expect(model.session?.postID == prose.id)
|
#expect(model.session?.postID == prose.id)
|
||||||
}
|
}
|
||||||
@@ -302,12 +302,12 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
@Test @MainActor func `convert reopens the open piece routed to prose`() throws {
|
@Test @MainActor func `convert reopens the open piece routed to prose`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Chapter\n- one\n - nested", type: .outline, home: home)
|
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?.id == post.id)
|
||||||
#expect(model.pendingConversion?.lossy == false) // clean outline
|
#expect(model.pendingConversion?.lossy == false) // clean outline
|
||||||
model.convertToPost(headingsLadder: true, home: home)
|
model.convertToPost(headingsLadder: true)
|
||||||
|
|
||||||
#expect(model.pendingConversion == nil)
|
#expect(model.pendingConversion == nil)
|
||||||
#expect(model.session?.postID == post.id) // reopened on the converted body
|
#expect(model.session?.postID == post.id) // reopened on the converted body
|
||||||
@@ -321,10 +321,10 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let open = try PostStore.writeNew(body: "# Stay\n", home: home)
|
let open = try PostStore.writeNew(body: "# Stay\n", home: home)
|
||||||
let outline = try PostStore.writeNew(body: "- a\n - b", type: .outline, 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.stageConversion(outline)
|
||||||
model.convertToPost(headingsLadder: false, home: home)
|
model.convertToPost(headingsLadder: false)
|
||||||
|
|
||||||
#expect(model.session?.postID == open.id) // untouched
|
#expect(model.session?.postID == open.id) // untouched
|
||||||
#expect(model.selectedPostID == open.id)
|
#expect(model.selectedPostID == open.id)
|
||||||
@@ -344,9 +344,9 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
}
|
}
|
||||||
#expect(model.posts.first(where: { $0.id == post.id })?.type == .outline)
|
#expect(model.posts.first(where: { $0.id == post.id })?.type == .outline)
|
||||||
|
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
model.stageConversion(post, home: home)
|
model.stageConversion(post)
|
||||||
model.convertToPost(headingsLadder: false, home: home) // VERBATIM
|
model.convertToPost(headingsLadder: false) // VERBATIM
|
||||||
|
|
||||||
#expect(model.proseOverridePostID == post.id)
|
#expect(model.proseOverridePostID == post.id)
|
||||||
#expect(model.session?.postID == post.id)
|
#expect(model.session?.postID == post.id)
|
||||||
@@ -362,11 +362,11 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
@Test @MainActor func `dirty open piece flushes before the convert`() throws {
|
@Test @MainActor func `dirty open piece flushes before the convert`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Chapter\n- one", type: .outline, home: home)
|
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.session?.edit("# Chapter\n- one\n - typed child") // unflushed edit
|
||||||
model.stageConversion(post, home: home)
|
model.stageConversion(post)
|
||||||
model.convertToPost(headingsLadder: false, home: home)
|
model.convertToPost(headingsLadder: false)
|
||||||
|
|
||||||
let onDisk = try String(contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8)
|
let onDisk = try String(contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/post.md"), encoding: .utf8)
|
||||||
#expect(onDisk.contains("type: post"))
|
#expect(onDisk.contains("type: post"))
|
||||||
@@ -376,11 +376,11 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
@Test @MainActor func `staging warns from the session text when the piece is dirty`() throws {
|
@Test @MainActor func `staging warns from the session text when the piece is dirty`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Clean\n- one\n- two", type: .outline, home: home)
|
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
|
// 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.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
|
#expect(model.pendingConversion?.lossy == true) // from session.text, not stale disk
|
||||||
}
|
}
|
||||||
@@ -389,7 +389,7 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home) // closed piece — disk is the truth
|
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)
|
#expect(model.pendingConversion?.lossy == true)
|
||||||
}
|
}
|
||||||
@@ -398,13 +398,13 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Clean\n- one\n- two", type: .outline, home: home)
|
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
|
// a foreign write makes the body mixed while the sheet was up
|
||||||
let file = home.appendingPathComponent("projects/posts/\(post.id)/post.md", isDirectory: false)
|
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)
|
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)
|
.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.lastError?.contains("nothing was converted") == true)
|
||||||
#expect(model.session?.postID == nil || model.session?.postID != post.id)
|
#expect(model.session?.postID == nil || model.session?.postID != post.id)
|
||||||
@@ -413,8 +413,8 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
#expect(onDisk.contains("A paragraph between bullets."))
|
#expect(onDisk.contains("A paragraph between bullets."))
|
||||||
|
|
||||||
// the consented path still converts: a WARNED mixed piece + Headings proceeds
|
// the consented path still converts: a WARNED mixed piece + Headings proceeds
|
||||||
model.stageConversion(post, home: home) // now stages lossy from disk
|
model.stageConversion(post) // now stages lossy from disk
|
||||||
model.convertToPost(headingsLadder: true, home: home)
|
model.convertToPost(headingsLadder: true)
|
||||||
let converted = try String(contentsOf: file, encoding: .utf8)
|
let converted = try String(contentsOf: file, encoding: .utf8)
|
||||||
#expect(converted.contains("type: post"))
|
#expect(converted.contains("type: post"))
|
||||||
#expect(!converted.contains("A paragraph between bullets.")) // dropped, as consented
|
#expect(!converted.contains("A paragraph between bullets.")) // dropped, as consented
|
||||||
@@ -423,14 +423,14 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
@Test @MainActor func `unanswered conflict aborts the convert`() throws {
|
@Test @MainActor func `unanswered conflict aborts the convert`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Clean\n- one", type: .outline, home: home)
|
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
|
// #67 conflict up: disk holds foreign text, the editor's version unwritten
|
||||||
model.session?.diskDidChange(diskText: "# Foreign rewrite\nbody")
|
model.session?.diskDidChange(diskText: "# Foreign rewrite\nbody")
|
||||||
#expect(model.session?.conflictAlert == true)
|
#expect(model.session?.conflictAlert == true)
|
||||||
|
|
||||||
model.stageConversion(post, home: home)
|
model.stageConversion(post)
|
||||||
model.convertToPost(headingsLadder: false, home: home)
|
model.convertToPost(headingsLadder: false)
|
||||||
|
|
||||||
#expect(model.lastError?.contains("reload question") == true)
|
#expect(model.lastError?.contains("reload question") == true)
|
||||||
#expect(model.session?.conflictAlert == true) // still answerable, not trampled
|
#expect(model.session?.conflictAlert == true) // still answerable, not trampled
|
||||||
@@ -441,13 +441,13 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
@Test @MainActor func `failed flush aborts the convert`() throws {
|
@Test @MainActor func `failed flush aborts the convert`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try PostStore.writeNew(body: "# Chapter\n- one", type: .outline, home: home)
|
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
|
model.session?.edit("# Chapter\n- one\n - child") // dirty
|
||||||
// vanish the piece: the flush throws (never resurrects), convert must abort
|
// vanish the piece: the flush throws (never resurrects), convert must abort
|
||||||
try FileManager.default.removeItem(at: home.appendingPathComponent("projects/posts/\(post.id)", isDirectory: true))
|
try FileManager.default.removeItem(at: home.appendingPathComponent("projects/posts/\(post.id)", isDirectory: true))
|
||||||
|
|
||||||
model.stageConversion(post, home: home)
|
model.stageConversion(post)
|
||||||
model.convertToPost(headingsLadder: true, home: home)
|
model.convertToPost(headingsLadder: true)
|
||||||
|
|
||||||
#expect(model.lastError?.contains("nothing was changed") == true)
|
#expect(model.lastError?.contains("nothing was changed") == true)
|
||||||
#expect(model.session?.postID == post.id) // session stays up, dirty and honest
|
#expect(model.session?.postID == post.id) // session stays up, dirty and honest
|
||||||
@@ -457,11 +457,11 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
|||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
let post = try writeMixedOutline(home: home)
|
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)
|
#expect(model.outlineGuardPieceID == post.id)
|
||||||
|
|
||||||
model.stageConversion(post, home: home)
|
model.stageConversion(post)
|
||||||
model.convertToPost(headingsLadder: false, home: home)
|
model.convertToPost(headingsLadder: false)
|
||||||
|
|
||||||
#expect(model.outlineGuardPieceID == nil) // the stale ask died with the outline
|
#expect(model.outlineGuardPieceID == nil) // the stale ask died with the outline
|
||||||
#expect(model.selectedPostID == nil) // cancel teardown: nothing was open
|
#expect(model.selectedPostID == nil) // cancel teardown: nothing was open
|
||||||
@@ -489,7 +489,7 @@ private func waitForCards(_ model: PostsModel, _ count: Int) async throws {
|
|||||||
let folder = try #require(PostStore.folder(of: post.id, 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.")])
|
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)
|
try await waitForCards(model, 1)
|
||||||
|
|
||||||
#expect(model.openPieceCards.map(\.pattern) == ["Hedging"])
|
#expect(model.openPieceCards.map(\.pattern) == ["Hedging"])
|
||||||
@@ -501,7 +501,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 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 folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
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)
|
try await waitForCards(model, 1)
|
||||||
|
|
||||||
// An MCP client submits another card while the piece stays open —
|
// An MCP client submits another card while the piece stays open —
|
||||||
@@ -520,7 +520,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 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 folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
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)
|
try await waitForCards(model, 1)
|
||||||
|
|
||||||
model.newPost()
|
model.newPost()
|
||||||
@@ -536,7 +536,7 @@ private func waitForCards(_ model: PostsModel, _ count: Int) async throws {
|
|||||||
#expect(folder.path.contains("/archive/"))
|
#expect(folder.path.contains("/archive/"))
|
||||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
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)
|
try await waitForCards(model, 1)
|
||||||
|
|
||||||
#expect(model.openPieceCards.count == 1)
|
#expect(model.openPieceCards.count == 1)
|
||||||
|
|||||||
@@ -31,46 +31,46 @@ struct PostsModelWriteRailTests {
|
|||||||
// create post — the draft's first save is the write
|
// create post — the draft's first save is the write
|
||||||
model.newPost()
|
model.newPost()
|
||||||
model.updateDraft("# Rail One\n")
|
model.updateDraft("# Rail One\n")
|
||||||
model.saveDraft(home: home)
|
model.saveDraft()
|
||||||
rail("saveDraft")
|
rail("saveDraft")
|
||||||
|
|
||||||
// session-born post
|
// session-born post
|
||||||
_ = model.newPostFromSession(body: "# Rail Two\n", home: home)
|
_ = model.newPostFromSession(body: "# Rail Two\n")
|
||||||
rail("newPostFromSession")
|
rail("newPostFromSession")
|
||||||
|
|
||||||
// project creation (reason returns to the sheet; still railed)
|
// project creation (reason returns to the sheet; still railed)
|
||||||
#expect(model.createProject(named: "essays", home: home) == nil)
|
#expect(model.createProject(named: "essays") == nil)
|
||||||
rail("createProject")
|
rail("createProject")
|
||||||
|
|
||||||
// move to project
|
// move to project
|
||||||
let movable = try PostStore.writeNew(body: "# Movables\n", home: home)
|
let movable = try PostStore.writeNew(body: "# Movables\n", home: home)
|
||||||
model.moveToProject(movable, project: "essays", home: home)
|
model.moveToProject(movable, project: "essays")
|
||||||
rail("moveToProject")
|
rail("moveToProject")
|
||||||
|
|
||||||
// rename
|
// rename
|
||||||
let toRename = try PostStore.writeNew(body: "# Rename Me\n", home: home)
|
let toRename = try PostStore.writeNew(body: "# Rename Me\n", home: home)
|
||||||
model.rename(toRename, to: "Renamed Title", home: home)
|
model.rename(toRename, to: "Renamed Title")
|
||||||
rail("rename")
|
rail("rename")
|
||||||
|
|
||||||
// archive → restore (id survives both — one Post value drives them)
|
// archive → restore (id survives both — one Post value drives them)
|
||||||
let toArchive = try PostStore.writeNew(body: "# Archive Me\n", home: home)
|
let toArchive = try PostStore.writeNew(body: "# Archive Me\n", home: home)
|
||||||
model.archivePost(toArchive, home: home)
|
model.archivePost(toArchive)
|
||||||
rail("archivePost")
|
rail("archivePost")
|
||||||
model.restorePost(toArchive, home: home)
|
model.restorePost(toArchive)
|
||||||
rail("restorePost")
|
rail("restorePost")
|
||||||
|
|
||||||
// whole-project unarchive: an archived piece in "essays" restores
|
// whole-project unarchive: an archived piece in "essays" restores
|
||||||
// the project's other child (moved earlier) too
|
// the project's other child (moved earlier) too
|
||||||
let inProject = try PostStore.writeNew(body: "# In Project\n", project: "essays", home: home)
|
let inProject = try PostStore.writeNew(body: "# In Project\n", project: "essays", home: home)
|
||||||
model.archivePost(inProject, home: home)
|
model.archivePost(inProject)
|
||||||
rail("archivePost (project member)")
|
rail("archivePost (project member)")
|
||||||
model.unarchiveProject("essays", home: home)
|
model.unarchiveProject("essays")
|
||||||
rail("unarchiveProject")
|
rail("unarchiveProject")
|
||||||
|
|
||||||
// convert
|
// convert
|
||||||
let outline = try PostStore.writeNew(body: "- one\n- two\n", type: .outline, home: home)
|
let outline = try PostStore.writeNew(body: "- one\n- two\n", type: .outline, home: home)
|
||||||
model.stageConversion(outline, home: home) // staging asks, never writes
|
model.stageConversion(outline) // staging asks, never writes
|
||||||
model.convertToPost(headingsLadder: false, home: home)
|
model.convertToPost(headingsLadder: false)
|
||||||
rail("convertToPost")
|
rail("convertToPost")
|
||||||
|
|
||||||
// import batch — ONE paired rescan for the whole batch
|
// import batch — ONE paired rescan for the whole batch
|
||||||
@@ -78,12 +78,12 @@ struct PostsModelWriteRailTests {
|
|||||||
.appendingPathComponent("rail-import-\(UUID().uuidString).md")
|
.appendingPathComponent("rail-import-\(UUID().uuidString).md")
|
||||||
try "# Imported\n".write(to: ext, atomically: true, encoding: .utf8)
|
try "# Imported\n".write(to: ext, atomically: true, encoding: .utf8)
|
||||||
model.stageImport([ext])
|
model.stageImport([ext])
|
||||||
model.importFiles(origin: .writer, home: home)
|
model.importFiles(origin: .writer)
|
||||||
rail("importFiles")
|
rail("importFiles")
|
||||||
|
|
||||||
// trash
|
// trash
|
||||||
let toTrash = try PostStore.writeNew(body: "# Trash Me\n", home: home)
|
let toTrash = try PostStore.writeNew(body: "# Trash Me\n", home: home)
|
||||||
model.trash(toTrash, home: home)
|
model.trash(toTrash)
|
||||||
rail("trash")
|
rail("trash")
|
||||||
|
|
||||||
#expect(model.lastError == nil)
|
#expect(model.lastError == nil)
|
||||||
@@ -97,7 +97,7 @@ struct PostsModelWriteRailTests {
|
|||||||
defer { mentor.shutdown() } // #124: the engine dies with the test
|
defer { mentor.shutdown() } // #124: the engine dies with the test
|
||||||
await mentor.openSession()
|
await mentor.openSession()
|
||||||
let post = try PostStore.writeNew(body: "# Pass Piece\n", home: home)
|
let post = try PostStore.writeNew(body: "# Pass Piece\n", home: home)
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
// Wait for the bind rescan to surface the piece (PassRunTests poll).
|
// Wait for the bind rescan to surface the piece (PassRunTests poll).
|
||||||
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
try await Task.sleep(nanoseconds: 20_000_000)
|
||||||
@@ -105,27 +105,27 @@ struct PostsModelWriteRailTests {
|
|||||||
|
|
||||||
var events: [PostsModelRailEvent] = []
|
var events: [PostsModelRailEvent] = []
|
||||||
model.onRailEvent = { events.append($0) }
|
model.onRailEvent = { events.append($0) }
|
||||||
await model.runPass(.pass1, home: home, mentor: mentor)
|
await model.runPass(.pass1, mentor: mentor)
|
||||||
|
|
||||||
#expect(events == [.write, .pairedRescan])
|
#expect(events == [.write, .pairedRescan])
|
||||||
#expect(model.lastError == nil)
|
#expect(model.lastError == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// #179: the failure pairing — a write that throws rides the rail
|
/// #179: the failure pairing — a write that throws rides the rail
|
||||||
/// once, pairs NO rescan (nothing changed on disk), and the strip owns
|
/// once (`.write` + `.writeFailed`), pairs NO rescan (nothing changed
|
||||||
/// the reason.
|
/// on disk), and the strip owns the reason.
|
||||||
@Test func `a failed write rides the rail once and pairs no rescan`() throws {
|
@Test func `a failed write rides the rail once and pairs no rescan`() throws {
|
||||||
let (model, home) = try makeModelHome()
|
let (model, home) = try makeModelHome()
|
||||||
var events: [PostsModelRailEvent] = []
|
var events: [PostsModelRailEvent] = []
|
||||||
model.onRailEvent = { events.append($0) }
|
model.onRailEvent = { events.append($0) }
|
||||||
let post = try PostStore.writeNew(body: "# Trashed Twice\n", home: home)
|
let post = try PostStore.writeNew(body: "# Trashed Twice\n", home: home)
|
||||||
|
|
||||||
model.trash(post, home: home) // first: rides + pairs
|
model.trash(post) // first: rides + pairs
|
||||||
#expect(events == [.write, .pairedRescan])
|
#expect(events == [.write, .pairedRescan])
|
||||||
events.removeAll()
|
events.removeAll()
|
||||||
|
|
||||||
model.trash(post, home: home) // folder already gone → the write throws
|
model.trash(post) // folder already gone → the write throws
|
||||||
#expect(events == [.write])
|
#expect(events == [.write, .writeFailed])
|
||||||
#expect(model.lastError != nil)
|
#expect(model.lastError != nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,12 +31,12 @@ struct SessionLifecycleTests {
|
|||||||
let defaultSession = try #require(mentor.activeEntry)
|
let defaultSession = try #require(mentor.activeEntry)
|
||||||
let rosterBefore = mentor.roster.count
|
let rosterBefore = mentor.roster.count
|
||||||
let post = try PostStore.writeNew(body: "# Pass Piece\n\nThe body under pass.", home: home)
|
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 }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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.
|
// The roster never grew — the pass entry is transient.
|
||||||
#expect(mentor.roster.count == rosterBefore)
|
#expect(mentor.roster.count == rosterBefore)
|
||||||
@@ -330,7 +330,7 @@ struct SessionLifecycleTests {
|
|||||||
#expect(SessionsPaneView.openPiece(in: nil) == nil) // no Posts at all
|
#expect(SessionsPaneView.openPiece(in: nil) == nil) // no Posts at all
|
||||||
|
|
||||||
let post = try PostStore.writeNew(body: "# Open Piece\n", home: home)
|
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 }) {
|
for _ in 0 ..< 250 where !model.posts.contains(where: { $0.id == post.id }) {
|
||||||
try await Task.sleep(nanoseconds: 20_000_000)
|
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).
|
// 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)
|
let post = try PostStore.writeNew(body: "# Prose piece\n\nBody words.\n", home: home)
|
||||||
try await Self.waitForScan(model, id: post.id)
|
try await Self.waitForScan(model, id: post.id)
|
||||||
model.select(post.id, home: home)
|
model.select(post.id)
|
||||||
#expect(model.canArmWritingLock)
|
#expect(model.canArmWritingLock)
|
||||||
#expect(model.editorBodyText == "# Prose piece\n\nBody words.\n")
|
#expect(model.editorBodyText == "# Prose piece\n\nBody words.\n")
|
||||||
|
|
||||||
let outline = try PostStore.writeNew(body: "- an outline\n", project: "posts", type: .outline, home: home)
|
let outline = try PostStore.writeNew(body: "- an outline\n", project: "posts", type: .outline, home: home)
|
||||||
try await Self.waitForScan(model, id: outline.id)
|
try await Self.waitForScan(model, id: outline.id)
|
||||||
model.select(outline.id, home: home)
|
model.select(outline.id)
|
||||||
#expect(!model.canArmWritingLock)
|
#expect(!model.canArmWritingLock)
|
||||||
|
|
||||||
// A MIXED outline fires the #111 guard ask instead — the held
|
// 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.
|
// 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)
|
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)
|
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.outlineGuardPieceID == mixed.id)
|
||||||
#expect(!model.canArmWritingLock)
|
#expect(!model.canArmWritingLock)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user