|
|
@@ -25,6 +25,10 @@
|
|
|
|
// read is observable. The Settings path in these pins is the model's two
|
|
|
|
// read is observable. The Settings path in these pins is the model's two
|
|
|
|
// steps — `repoint(to:)` (the gate) then `bind` (the commit) — exactly as
|
|
|
|
// steps — `repoint(to:)` (the gate) then `bind` (the commit) — exactly as
|
|
|
|
// WorkspaceView's binding and root `.task(id:)` drive them.
|
|
|
|
// WorkspaceView's binding and root `.task(id:)` drive them.
|
|
|
|
|
|
|
|
// r1 (athena MF-1/N-1): the hoisted stale-Home verdict in `rescan` (the
|
|
|
|
|
|
|
|
// library-scan sibling of the card hop-back — the per-model `scanLibrary`
|
|
|
|
|
|
|
|
// seam holds it past the repoint) and the draft-survives decision are
|
|
|
|
|
|
|
|
// pinned too.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Foundation
|
|
|
@@ -279,4 +283,69 @@ struct PostsModelRepointTests {
|
|
|
|
#expect(onDiskA.contains("pass_state: First Draft"))
|
|
|
|
#expect(onDiskA.contains("pass_state: First Draft"))
|
|
|
|
#expect(!FileManager.default.fileExists(atPath: homeA.appendingPathComponent("projects/posts/shared/passes/pass-1.md").path))
|
|
|
|
#expect(!FileManager.default.fileExists(atPath: homeA.appendingPathComponent("projects/posts/shared/passes/pass-1.md").path))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// r1 (MF-1): the hoisted stale-Home verdict in `rescan` — the sibling
|
|
|
|
|
|
|
|
/// continuation of the card hop-back, and the one guard still observable
|
|
|
|
|
|
|
|
/// in production after the gate. A scan started under A sits in its
|
|
|
|
|
|
|
|
/// detached hop while the gate passes and `bind` flips to B; landing
|
|
|
|
|
|
|
|
/// after B's own scan it would put A's list under the B binding until
|
|
|
|
|
|
|
|
/// the next B-side event — which, with nothing open, can be never.
|
|
|
|
|
|
|
|
@Test func `a library scan from the old Home lands nothing under the new binding`() async throws {
|
|
|
|
|
|
|
|
let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Alpha\n\nA body\n", bodyB: "# Bravo\n\nB body\n")
|
|
|
|
|
|
|
|
// The rig's first rescan lands first: posts is A's list, steady state.
|
|
|
|
|
|
|
|
try await pollUntil { model.posts.map(\.id) == ["alpha"] }
|
|
|
|
|
|
|
|
// HOLD the next A scan past the repoint (the card pin's shape).
|
|
|
|
|
|
|
|
let parked = ParkedFlag()
|
|
|
|
|
|
|
|
let release = DispatchSemaphore(value: 0)
|
|
|
|
|
|
|
|
model.scanLibrary = { home, cache in
|
|
|
|
|
|
|
|
if home == homeA {
|
|
|
|
|
|
|
|
parked.set()
|
|
|
|
|
|
|
|
_ = release.wait(timeout: .now() + 30) // bounded: a failed test must not leak a parked thread
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Post.scan(home: home, cache: cache)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Task { await model.rescan() } // parks inside the detached scan
|
|
|
|
|
|
|
|
try await pollUntil { parked.isSet }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The Settings repoint: gate, then binding; B's own scan lands.
|
|
|
|
|
|
|
|
#expect(model.repoint(to: homeB))
|
|
|
|
|
|
|
|
model.bind(home: homeB)
|
|
|
|
|
|
|
|
try await pollUntil { model.posts.map(\.id) == ["bravo"] }
|
|
|
|
|
|
|
|
let revision = model.contentRevision
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Release the stale A scan: its continuation completes AFTER B's scan
|
|
|
|
|
|
|
|
// — the hoisted verdict applies nothing it found (list, revision).
|
|
|
|
|
|
|
|
release.signal()
|
|
|
|
|
|
|
|
release.signal() // a second A scan, if one ever queued, must not park the teardown
|
|
|
|
|
|
|
|
try await Task.sleep(nanoseconds: 200_000_000) // let the continuation land
|
|
|
|
|
|
|
|
#expect(model.posts.map(\.id) == ["bravo"]) // never A's list under the B binding
|
|
|
|
|
|
|
|
#expect(model.contentRevision == revision) // and no revision bump for it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// r1 (N-1): the draft-survives decision, pinned — a draft has no Home
|
|
|
|
|
|
|
|
/// until first save (#62), so the repoint leaves its buffer alone and
|
|
|
|
|
|
|
|
/// the lazy folder lands under B, in the draft's OWN project even when
|
|
|
|
|
|
|
|
/// B does not have it yet (materialize creates with intermediates).
|
|
|
|
|
|
|
|
@Test func `an in-memory draft survives a repoint and first-saves into the new library only`() async throws {
|
|
|
|
|
|
|
|
let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Piece\n\nA body\n", bodyB: "# Bravo\n\nB body\n")
|
|
|
|
|
|
|
|
// A holds `projects/alpha/in-alpha` — a project B does not have.
|
|
|
|
|
|
|
|
let alphaPiece = try PostStore.writeNew(body: "# In Alpha\n\nA body\n", project: "alpha", home: homeA)
|
|
|
|
|
|
|
|
try await pollUntil { model.posts.contains { $0.id == alphaPiece.id } } // the list must know the piece (targetProject reads it)
|
|
|
|
|
|
|
|
model.select(alphaPiece.id)
|
|
|
|
|
|
|
|
model.newPost() // targets the selected piece's project
|
|
|
|
|
|
|
|
#expect(model.draft?.project == "alpha")
|
|
|
|
|
|
|
|
model.updateDraft("# Draft Words\n\nTyped in A, saved in B")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The Settings repoint: gate, then binding — the draft rides along.
|
|
|
|
|
|
|
|
#expect(model.repoint(to: homeB))
|
|
|
|
|
|
|
|
model.bind(home: homeB)
|
|
|
|
|
|
|
|
#expect(model.draft?.text == "# Draft Words\n\nTyped in A, saved in B") // intact
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.saveDraft()
|
|
|
|
|
|
|
|
#expect(PostStore.readBody(id: "draft-words", home: homeB) == "# Draft Words\n\nTyped in A, saved in B")
|
|
|
|
|
|
|
|
#expect(PostStore.readBody(id: "draft-words", home: homeA) == nil) // never A
|
|
|
|
|
|
|
|
#expect(Post.scan(home: homeB).contains { $0.id == "draft-words" && $0.project == "alpha" }) // B-absent project created
|
|
|
|
|
|
|
|
#expect(model.session?.targets(postID: "draft-words", home: homeB) == true) // and it opens there
|
|
|
|
|
|
|
|
#expect(model.draft == nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|