From bce6abb38b750137e3c807a7458388387bd3eec7 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Mon, 23 Nov 2026 20:16:02 +0100 Subject: [PATCH 1/6] =?UTF-8?q?test(editor):=20pin=20Home=20repoint=20as?= =?UTF-8?q?=20a=20document=20departure=20=E2=80=94=20RED=20at=20ca265d3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PostsModelRepointTests (6 pins over a two-Home same-slug rig, projects/posts/shared/post.md in both libraries): the gate runs before anything changes (failed flush, unanswered #67, never-loaded retype — sessionMayDepart's three legs), the same-slug piece opens from B and saves there (flush AND quit), a no-collision repoint lands the dirty buffer before tearing down, and a pass started after the repoint runs against the new library. RED at ca265d3bd359e663216aa91d4778e2bdef8a36eb on the rail (-only-testing:MuseionTests/PostsModelRepointTests): 6 executed / 0 passed / 6 failed, zero compile errors — each on the finding's signature: the retained A session under the B binding (session.text = "A body, typed in A", targets(home: B) false), B's edits landing on A's disk, watchedHome = B despite a refused flush, and the no-collision vanish path dropping the dirty buffer. The tests speak the Settings path as it exists at base (bind), which has no gate to refuse through; the fix commit moves each repoint call to the gated entry. EditorSession gains the pure identity predicates the assertions speak in (targets(postID:home:) / targets(home:)) — read-only, no behavior change. --- Museion/EditorSession.swift | 18 ++ MuseionTests/PostsModelRepointTests.swift | 209 ++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 MuseionTests/PostsModelRepointTests.swift diff --git a/Museion/EditorSession.swift b/Museion/EditorSession.swift index 37e6311..8462562 100644 --- a/Museion/EditorSession.swift +++ b/Museion/EditorSession.swift @@ -63,6 +63,24 @@ final class EditorSession { return nil } + /// brief-28: document identity — a post session is (Home, ID), never the + /// bare id: two libraries can hold the same slug, and only the pair says + /// which piece the buffer belongs to. The target is immutable, so the + /// Home here is the one the session was BORN under — a model whose + /// `watchedHome` moved past it must treat this session as a foreign + /// document, not as its own open piece. + func targets(postID id: String, home: URL) -> Bool { + guard case let .post(mine, myHome) = target else { return false } + return mine == id && myHome == home + } + + /// brief-28: the Home half alone — does this post session live under + /// `home`? External guests never do. + func targets(home: URL) -> Bool { + guard case let .post(_, myHome) = target else { return false } + return myHome == home + } + /// The document's folder — the piece's resolved folder under projects/ /// or archive/ for posts (image resolution #71; resolved once at init, /// ADR-0012 — a vanished piece still needs some path, so an unresolvable diff --git a/MuseionTests/PostsModelRepointTests.swift b/MuseionTests/PostsModelRepointTests.swift new file mode 100644 index 0000000..346fb11 --- /dev/null +++ b/MuseionTests/PostsModelRepointTests.swift @@ -0,0 +1,209 @@ +// +// PostsModelRepointTests.swift +// MuseionTests +// +// brief-28 (home-repoint-retains-old-editor-target): a Home repoint is a +// document departure. Settings used to commit the new Home and flip +// `watchedHome` (bind → startWatching) without departing the open +// session: the session's immutable target kept the OLD Home, a same-slug +// piece in the new library made the ID-only reselect return it, and +// autosave/Save/quit wrote the old library while structural operations +// resolved against the new one (#198's departure gate never saw this +// seam). Pins: the gate runs BEFORE anything changes (a refused repoint +// leaves Home A, the binding, the session's (Home, ID) target and its +// buffer untouched — all three `sessionMayDepart` legs), an accepted +// repoint lands the edits on A first and leaves no live session targeting +// an A piece under B, the same-slug piece opens from B and saves there +// (flush AND quit), a no-collision repoint tears down cleanly (the old +// vanish path dropped the dirty buffer), a card scan from the old library +// never lands on the new library's piece (identity re-check at +// COMPLETION), and a pass started after the repoint runs against the new +// library. +// +// Two-Home rig: `projects/posts/shared/post.md` in BOTH libraries — the +// collision shape the finding names; differing bodies so a wrong-library +// read is observable. +// + +import Foundation +@testable import Museion +import Testing + +@Suite("PostsModelRepointTests") +@MainActor +struct PostsModelRepointTests { + private func denyWrites(to dir: URL) throws { + try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: dir.path) + } + + private func allowWrites(to dir: URL) throws { + try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: dir.path) + } + + /// Two Homes holding the SAME slug — `writeNew` derives `shared` from + /// the `# Shared` title in both (a non-Shared bodyA makes a unique + /// slug instead: the no-collision shape). The model is bound to A. + // swiftlint:disable:next large_tuple + private func makeTwoHomes(bodyA: String, bodyB: String) throws -> (model: PostsModel, homeA: URL, homeB: URL) { + let base = FileManager.default.temporaryDirectory + .appendingPathComponent("repoint-\(UUID().uuidString)", isDirectory: true) + let homeA = base.appendingPathComponent("A", isDirectory: true) + let homeB = base.appendingPathComponent("B", isDirectory: true) + for home in [homeA, homeB] { + try FileManager.default.createDirectory(at: home, withIntermediateDirectories: true) + } + _ = try PostStore.writeNew(body: bodyA, home: homeA) + _ = try PostStore.writeNew(body: bodyB, home: homeB) + let model = PostsModel() + model.bind(home: homeA) + return (model, homeA, homeB) + } + + @Test func `a same-slug piece opens from the new library after a repoint and saves there, never the old one`() throws { + let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Shared\n\nA body\n", bodyB: "# Shared\n\nB body\n") + model.select("shared") + #expect(model.session?.text == "# Shared\n\nA body\n") + model.session?.edit("# Shared\n\nA body, typed in A\n") + + model.bind(home: homeB) // the Settings repoint + model.select("shared") + + // B's piece opened from B — not the retained A session (whose + // ID-only reselect used to return it under the new UI). + #expect(model.session?.text == "# Shared\n\nB body\n") + #expect(model.session?.targets(postID: "shared", home: homeB) == true) + model.session?.edit("# Shared\n\nB body, typed in B\n") + model.session?.flush() // ⌘S — the debounce's own sink + #expect(PostStore.readBody(id: "shared", home: homeB) == "# Shared\n\nB body, typed in B\n") + // A holds exactly what the departure flushed — never B's edits. + #expect(PostStore.readBody(id: "shared", home: homeA) == "# Shared\n\nA body, typed in A\n") + model.session?.edit("# Shared\n\nB body, typed in B again\n") + model.shutdown() // quit rides the departure gate (#200) + #expect(PostStore.readBody(id: "shared", home: homeB) == "# Shared\n\nB body, typed in B again\n") + #expect(PostStore.readBody(id: "shared", home: homeA) == "# Shared\n\nA body, typed in A\n") + } + + @Test func `repoint refuses when the open piece's flush fails and changes nothing`() throws { + let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Shared\n\nA body\n", bodyB: "# Shared\n\nB body\n") + model.select("shared") + model.session?.edit("# Shared\n\nA body, typed in A\n") + let pieceDir = try #require(PostStore.folder(of: "shared", home: homeA)) + try denyWrites(to: pieceDir) + defer { try? allowWrites(to: pieceDir) } + + model.bind(home: homeB) // the Settings repoint + + // ORDERING: the gate fired before ANY state changed — the binding, + // the selection, the session's (Home, ID) target and its buffer. + #expect(model.watchedHome == homeA) + #expect(model.selectedPostID == "shared") + #expect(model.session?.postID == "shared") + #expect(model.session?.targets(postID: "shared", home: homeA) == true) + #expect(model.session?.text == "# Shared\n\nA body, typed in A\n") + #expect(model.session?.saveState == .failed) + #expect(model.lastError != nil) + #expect(PostStore.readBody(id: "shared", home: homeB) == "# Shared\n\nB body\n") + + // Writability restored → the edits land on A first, then the + // repoint goes through and departs the session. + try allowWrites(to: pieceDir) + model.bind(home: homeB) + #expect(PostStore.readBody(id: "shared", home: homeA) == "# Shared\n\nA body, typed in A\n") + #expect(model.session == nil) + #expect(model.selectedPostID == nil) + #expect(model.watchedHome == homeB) + } + + @Test func `repoint refuses while the conflict alert is unanswered`() throws { + let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Shared\n\nA body\n", bodyB: "# Shared\n\nB body\n") + model.select("shared") + model.session?.edit("# Shared\n\nA body, typed in A\n") + // #67: a foreign disk body arrived — the alert is up, unanswered. + model.session?.diskDidChange(diskText: "foreign body from disk") + + model.bind(home: homeB) // the Settings repoint + + #expect(model.watchedHome == homeA) + #expect(model.selectedPostID == "shared") + #expect(model.session?.postID == "shared") + #expect(model.session?.targets(postID: "shared", home: homeA) == true) + #expect(model.session?.conflictAlert == true) + #expect(model.session?.text == "# Shared\n\nA body, typed in A\n") + #expect(model.lastError != nil) + // Never over the foreign body, never into the new library. + #expect(PostStore.readBody(id: "shared", home: homeA) == "# Shared\n\nA body\n") + #expect(PostStore.readBody(id: "shared", home: homeB) == "# Shared\n\nB body\n") + } + + @Test func `repoint refuses over a never-loaded session with retyped text`() throws { + let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Shared\n\nA body\n", bodyB: "# Shared\n\nB body\n") + // The file turns unreadable between scan and open: the session + // opens empty (loadFailed), the writer retypes into it (#200's leg). + let file = try #require(PostStore.folder(of: "shared", home: homeA)) + .appendingPathComponent("post.md") + try FileManager.default.setAttributes([.posixPermissions: 0o000], ofItemAtPath: file.path) + defer { try? FileManager.default.setAttributes([.posixPermissions: 0o644], ofItemAtPath: file.path) } + model.select("shared") + #expect(model.session?.loadFailed == true) + model.session?.edit("# Retyped words over a file that never loaded") + + model.bind(home: homeB) // the Settings repoint + + #expect(model.watchedHome == homeA) + #expect(model.selectedPostID == "shared") + #expect(model.session?.targets(postID: "shared", home: homeA) == true) + #expect(model.session?.text == "# Retyped words over a file that never loaded") + #expect(model.lastError != nil) + } + + @Test func `a no-collision repoint lands the open piece's edits first and tears it down cleanly`() async throws { + let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Unique\n\nA body\n", bodyB: "# Shared\n\nB body\n") + model.select("unique") + model.session?.edit("# Unique\n\nA body, typed in A\n") + + model.bind(home: homeB) // the Settings repoint + + // The old session's edits landed on A BEFORE anything moved — the + // vanish path used to tear it down without a flush. + #expect(PostStore.readBody(id: "unique", home: homeA) == "# Unique\n\nA body, typed in A\n") + #expect(model.session == nil) + #expect(model.selectedPostID == nil) + // No ghost: the new library's rescan leaves nothing selected, nothing open. + try await pollUntil { model.posts.contains { $0.id == "shared" } } + #expect(model.session == nil) + #expect(model.selectedPostID == nil) + #expect(model.watchedHome == homeB) + } + + @Test func `a pass started after the repoint runs against the new library`() async throws { + let (model, homeA, mentor) = try makePassRig() + defer { mentor.shutdown() } + await mentor.openSession() + _ = try PostStore.writeNew(body: "# Shared\n\nA body\n", home: homeA) + let homeB = FileManager.default.temporaryDirectory + .appendingPathComponent("repoint-pass-\(UUID().uuidString)", isDirectory: true) + try FileManager.default.createDirectory(at: homeB, withIntermediateDirectories: true) + _ = try PostStore.writeNew(body: "# Shared\n\nB body\n", home: homeB) + model.select("shared") + #expect(model.session?.text == "# Shared\n\nA body\n") + + model.bind(home: homeB) // the Settings repoint + model.select("shared") + #expect(model.session?.text == "# Shared\n\nB body\n") + + await model.runPass(.pass1, mentor: mentor) + + // Snapshot and the advance landed on B's piece with B's body — the + // retained A session used to hand its text to the new library. + let snapshot = try String( + contentsOf: homeB.appendingPathComponent("projects/posts/shared/passes/pass-1.md"), + encoding: .utf8, + ) + #expect(snapshot.contains("B body")) + let onDiskB = try String(contentsOf: homeB.appendingPathComponent("projects/posts/shared/post.md"), encoding: .utf8) + #expect(onDiskB.contains("pass_state: Pass-1 Done")) + let onDiskA = try String(contentsOf: homeA.appendingPathComponent("projects/posts/shared/post.md"), encoding: .utf8) + #expect(onDiskA.contains("pass_state: First Draft")) + #expect(!FileManager.default.fileExists(atPath: homeA.appendingPathComponent("projects/posts/shared/passes/pass-1.md").path)) + } +} -- 2.36.6 From 8b0d43aed8ba3c7c3ae7e67853639451763d4c6f Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Mon, 23 Nov 2026 20:23:57 +0100 Subject: [PATCH 2/6] fix(editor): Home repoint rides the departure gate; document identity is (Home, ID) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings committed the new Home and bind flipped watchedHome without departing the open session: the session's immutable target kept the OLD Home, a same-slug piece in the new library made the ID-only reselect return it, and autosave/Save/quit wrote the old library while structural operations resolved against the new one. #198's departure gate never saw this seam; a no-collision piece was torn down by the vanish path with its dirty buffer dropped. The gate runs BEFORE anything commits. PostsModel.repoint(to:) is a document departure through the same sessionMayDepart (all three legs: unanswered #67, failed flush, never-loaded retype — no parallel gate); on refusal nothing changes (preference, watchedHome, the session's (A, id) target, its buffer), on acceptance the departed piece's state dies with it. AppGateState.repointMuseionHome(to:) commits the preference and its persistence only after the gate; WorkspaceView's Settings binding routes through it and the root .task(id:) binds the model after that commit — the dumb binder. A refusal speaks the #198 reason the way #200's quit refusal does (hosted-guarded alert: no Posts strip is in sight from Settings). Nothing auto-reopens after an accepted repoint — the writer picks from the new list; the in-memory draft survives (no Home until first save; dropping it would drop the only copy). Document identity is (Home, ID) everywhere — EditorSession.targets is the pair, PostsModel.openSessionTargets the model-side question; every ID-only session comparison is retired: select's reselect no-op, openUnguarded, the structural rail (rename/trash/move/archive/ restore/unarchive + flushOrAbort), conversion, the pass guard (its answer now carries the Home it validated), Micropub's launch, the lock's arm/body reads. Async continuations re-validate identity at COMPLETION: refreshCards (launch and hop-back — the old ID-only guard let a scan from the previous library land its cards on the new library's same-slug piece) and rescan (the stale-Home verdict is hoisted: a scan that outlived a repoint applies nothing, not just the vanish check; the #67 disk read runs only for a session targeting the scan's own Home). scanPieceCards is the per-model injectable scanner the deterministic stale-scan pin needs. Tests: PostsModelRepointTests (7) move to the gated entry and go green (17/17 with PostsModelDepartureTests — the #198 matrix stays green and composes); the stale-scan pin's RED is a mutation check (completion guard reverted to ID-only → only that pin fails, cards → ["Hedging"]; restored byte-exact). The #179 mid-pass repoint pin drives the real Settings path now (repoint + bind). swiftformat 0/152, swiftlint 0. --- Museion/HomeResolution.swift | 15 ++++ Museion/Micropub.swift | 10 ++- Museion/PostsModel.swift | 18 ++-- Museion/PostsModelCards.swift | 19 ++-- Museion/PostsModelIdentity.swift | 25 ++++++ Museion/PostsModelOutline.swift | 14 +-- Museion/PostsModelPasses.swift | 32 +++---- Museion/PostsModelWatcher.swift | 77 +++++++++++++--- Museion/PostsModelWrites.swift | 16 ++-- Museion/WorkspaceView.swift | 36 +++++++- MuseionTests/PostsModelRepointTests.swift | 103 ++++++++++++++++++---- MuseionTests/PostsModelTests.swift | 5 +- 12 files changed, 298 insertions(+), 72 deletions(-) create mode 100644 Museion/PostsModelIdentity.swift diff --git a/Museion/HomeResolution.swift b/Museion/HomeResolution.swift index cd0f491..ae08203 100644 --- a/Museion/HomeResolution.swift +++ b/Museion/HomeResolution.swift @@ -80,4 +80,19 @@ extension AppGateState { nonisolated static func storeHome(_ home: URL, in defaults: UserDefaults) { defaults.set(home.absoluteString, forKey: "museionHome") } + + /// brief-28 (home-repoint-retains-old-editor-target): the ONE repoint + /// entry at runtime — the departure gate runs FIRST (`posts.repoint`: + /// every open document lands, or nothing changes and `posts.lastError` + /// names the piece); the preference and its persistence (`museionHome`'s + /// didSet) commit only after. True = committed. WorkspaceView's Settings + /// binding routes through here; the root `.task(id: museionHome)` binds + /// the model after the commit, so `watchedHome` can never move past a + /// live session again. + @discardableResult + func repointMuseionHome(to newHome: URL) -> Bool { + guard posts.repoint(to: newHome) else { return false } + museionHome = newHome + return true + } } diff --git a/Museion/Micropub.swift b/Museion/Micropub.swift index 6f531e4..0f19c66 100644 --- a/Museion/Micropub.swift +++ b/Museion/Micropub.swift @@ -250,9 +250,16 @@ extension PostsModel { token: String, transport: Micropub.Transport = Micropub.urlSessionTransport, ) async -> Micropub.Outcome { + // brief-28: identity — the open session must target THIS library's + // selected piece (Home, ID); the wire below reads the session's OWN + // library, never the current Home's same-slug file. The completion + // stamp targets the same captured pair — the piece actually sent, + // wherever the writer has since pointed the app. guard let session, let id = session.postID, + let home = watchedHome, id == selectedPostID, + session.targets(postID: id, home: home), draft == nil, externalSession == nil, outlineGuardPieceID == nil @@ -267,8 +274,7 @@ extension PostsModel { // name) and the frontmatter-stripped body (the stamp is // bookkeeping, never prose; the body itself is never stripped, // GLOSSARY). No scan dependency: the list can lag the open piece. - guard let home = watchedHome, - let dir = PostStore.folder(of: id, home: home), + guard let dir = PostStore.folder(of: id, home: home), let raw = try? String(contentsOf: dir.appendingPathComponent("post.md"), encoding: .utf8) else { return .refused("Couldn't read the piece before sending.") diff --git a/Museion/PostsModel.swift b/Museion/PostsModel.swift index 5f60072..ec74ac5 100644 --- a/Museion/PostsModel.swift +++ b/Museion/PostsModel.swift @@ -154,6 +154,11 @@ final class PostsModel { /// #143 (OPT-F3): scan parse memo — a rescan re-parses only changed /// post.md files, not the library (see PostScanCache). let scanCache = PostScanCache() + /// brief-28: the card scanner behind `refreshCards` — injectable so the + /// stale-result pin can HOLD an old-library scan past a repoint (a + /// detached disk read is otherwise faster than any test can arrange). + /// Per-model, never static (the hosted suite runs tests in parallel). + var scanPieceCards: @Sendable (URL) -> [FixCardStore.StoredFixCard] = FixCardStore.scan /// #93: per-file watcher on the open external file — the #67 conflict /// check reused verbatim for foreign files. var externalWatcher = PostsWatcher() @@ -260,7 +265,9 @@ final class PostsModel { // guarded one: the piece is open under a prior answer, and firing // the ask again would nil its session without teardown (the armed // debounce would then flush mid-ask, outside any owned session). - if let session, session.postID == id { + // brief-28: identity, not id — only THIS library's piece counts as + // open; a session born under another Home departs below. + if let session, let home = watchedHome, session.targets(postID: id, home: home) { return } if let session { @@ -306,9 +313,10 @@ final class PostsModel { if externalSession != nil { return true } - guard let session, session.postID == selectedPostID else { return false } - let outline = session.postID != proseOverridePostID - && (lastDraftWasOutline || posts.first(where: { $0.id == session.postID })?.type == .outline) + // brief-28: this library's piece, by identity (Home, ID). + guard let session, let id = selectedPostID, openSessionTargets(id) else { return false } + let outline = id != proseOverridePostID + && (lastDraftWasOutline || posts.first(where: { $0.id == id })?.type == .outline) return !outline } @@ -322,7 +330,7 @@ final class PostsModel { if let externalSession { return externalSession.text } - if let session, session.postID == selectedPostID { + if let session, let id = selectedPostID, openSessionTargets(id) { // brief-28: this library's piece, by identity return session.text } return nil diff --git a/Museion/PostsModelCards.swift b/Museion/PostsModelCards.swift index 9bc303f..c7e6a80 100644 --- a/Museion/PostsModelCards.swift +++ b/Museion/PostsModelCards.swift @@ -20,9 +20,14 @@ extension PostsModel { /// transitions — the piece-roots watcher already fires on cards/ writes. /// #122: the same pass also derives `openPieceHasSnapshot` (the Blind /// Read's base) — one detached read of the open piece's disk facts. + /// brief-28: identity at BOTH ends. At launch the open session must + /// target (watchedHome, id) — a session born under another Home has no + /// cards here. At COMPLETION the re-check is identity too: the old + /// ID-only guard let a scan started under the previous library land its + /// cards on the new library's same-slug piece after a repoint. func refreshCards() { - guard let id = session?.postID, - let home = watchedHome, + guard let session, let id = session.postID, let home = watchedHome, + session.targets(postID: id, home: home), // brief-28 let folder = PostStore.folder(of: id, home: home) else { openPieceCards = [] @@ -31,13 +36,15 @@ extension PostsModel { } // Plain disk reads re-run on every watcher burst (typing retriggers // rescan) — keep the I/O off MainActor, same posture as rescan's - // Post.scan. The id re-check on hop-back drops a scan that raced a - // piece switch. + // Post.scan. The identity re-check on hop-back drops a scan that + // raced a piece switch or a Home repoint. + let scan = scanPieceCards // detached capture, not a property read Task.detached { [weak self] in - let cards = FixCardStore.scan(pieceURL: folder) + let cards = scan(folder) let hasSnapshot = PostStore.latestPassSnapshot(id: id, home: home) != nil await MainActor.run { [weak self] in - guard let self, session?.postID == id else { return } + // brief-28: (Home, ID) at completion, never the id alone. + guard let self, self.session?.targets(postID: id, home: home) == true else { return } openPieceCards = cards openPieceHasSnapshot = hasSnapshot } diff --git a/Museion/PostsModelIdentity.swift b/Museion/PostsModelIdentity.swift new file mode 100644 index 0000000..26be0cf --- /dev/null +++ b/Museion/PostsModelIdentity.swift @@ -0,0 +1,25 @@ +// +// PostsModelIdentity.swift +// Museion +// +// brief-28 (home-repoint-retains-old-editor-target): document identity for +// the open session. Every "is this piece open" question in the model +// routes through here — select, the structural rail, the pass guard, the +// card refresh, Micropub. The bare `session.postID == id` comparison is +// retired: two libraries can hold the same slug, and the id alone matched +// a session retained from another library (the repoint finding's seam). +// + +import Foundation + +extension PostsModel { + /// brief-28: is the open session THIS library's piece `id`? Identity is + /// (Home, ID) — `watchedHome` is the Home half, so the answer is "the + /// buffer belongs to the piece the current library lists under that id". + /// A session born under another Home (or an external guest) is never + /// the open piece, whatever its id says; nothing bound = nothing open. + func openSessionTargets(_ id: String) -> Bool { + guard let session, let home = watchedHome else { return false } + return session.targets(postID: id, home: home) + } +} diff --git a/Museion/PostsModelOutline.swift b/Museion/PostsModelOutline.swift index 8fee1b6..75564ee 100644 --- a/Museion/PostsModelOutline.swift +++ b/Museion/PostsModelOutline.swift @@ -67,13 +67,15 @@ extension PostsModel { /// this one open body. func openUnguarded(_ id: String) { guard let home = watchedHome, dismissExternal() else { return } // brief-25: the guest's edits land or the open aborts - if let session, session.postID != id { + // brief-28: identity — a session born under another Home is never + // "the same piece", whatever its id says; it departs here too. + if let session, !session.targets(postID: id, home: home) { // brief-25: a failed flush (or an unanswered #67 conflict) // aborts here — the dirty session stays up and honest. guard sessionMayDepart(session) else { return } session.teardown(flushFirst: false) // the gate already flushed } - session = id == session?.postID ? session : EditorSession(postID: id, home: home) + session = session?.targets(postID: id, home: home) == true ? session : EditorSession(postID: id, home: home) draft = nil pendingProject = nil lastDraftWasOutline = false @@ -101,7 +103,7 @@ extension PostsModel { /// for prose typed since the last flush (#114 audit). func stageConversion(_ post: Post) { guard post.type == .outline else { return } - let body: String = if let session, session.postID == post.id { + let body: String = if let session, openSessionTargets(post.id) { // brief-28: identity session.text } else if let home = watchedHome { PostStore.readBody(id: post.id, home: home) ?? "" @@ -143,9 +145,9 @@ extension PostsModel { } performWrite { home in try PostStore.convert(id: pending.id, headingsLadder: headingsLadder, home: home) - if session?.postID == pending.id { - session?.teardown(flushFirst: false) // flushOrAbort already wrote - session = nil + if let session, openSessionTargets(pending.id) { // brief-28: identity + session.teardown(flushFirst: false) // flushOrAbort already wrote + self.session = nil proseOverridePostID = pending.id openUnguarded(pending.id) } diff --git a/Museion/PostsModelPasses.swift b/Museion/PostsModelPasses.swift index cbd93fc..d0eb11f 100644 --- a/Museion/PostsModelPasses.swift +++ b/Museion/PostsModelPasses.swift @@ -19,12 +19,13 @@ extension PostsModel { /// Read, named honestly whichever runner asks), the mentor not /// mid-reply with its engine ready, and an open SAVED piece (never a /// draft, the external guest, or a held #111 guard ask). The refusal - /// lands in lastError naming the blocker; answers the open piece's id - /// and session — the run's target — or nil (refused). - func guardOpenPieceRun( - _ action: String, - mentor: MentorSessionModel, - ) -> (id: String, session: EditorSession)? { + /// lands in lastError naming the blocker; answers the open piece's id, + /// session and Home — the run's target — or nil (refused). + /// brief-28: identity — the open session must target THIS library's + /// selected piece (Home, ID); a session born under another Home never + /// runs (its snapshot/stats/lint would land in the wrong library). + // swiftlint:disable:next large_tuple + func guardOpenPieceRun(_ action: String, mentor: MentorSessionModel) -> (id: String, session: EditorSession, home: URL)? { guard runningPass == nil else { lastError = "A pass is already running." return nil @@ -43,7 +44,9 @@ extension PostsModel { } guard let session, let id = session.postID, + let home = watchedHome, id == selectedPostID, + session.targets(postID: id, home: home), // brief-28 draft == nil, externalSession == nil, outlineGuardPieceID == nil @@ -51,7 +54,7 @@ extension PostsModel { lastError = "Open a saved post to run \(action)." return nil } - return (id, session) + return (id, session, home) } } @@ -64,7 +67,7 @@ extension PostsModel { /// and never when fix cards resolve. Passes run in any order /// (advancePassState is monotonic). func runPass(_ kind: PassKind, mentor: MentorSessionModel) async { - guard let (id, session) = guardOpenPieceRun("a pass", mentor: mentor) else { return } + guard let (id, session, home) = guardOpenPieceRun("a pass", mentor: mentor) else { return } // #137 (S4): the pass profile's provider has no key — name it and // point at Settings. Nothing has touched disk yet (the snapshot // comes after this guard). @@ -73,8 +76,8 @@ extension PostsModel { return } guard flushOrAbort(id) else { return } // the engine reads disk - // #179: the model owns the Home; an open piece implies a bound one. - guard let home = watchedHome else { return } + // #179: the model owns the Home — the guard answered the session's + // OWN library (brief-28 identity); every write below lands there. do { try PostStore.snapshotPass(id: id, kind: kind, body: session.text, home: home) } catch { @@ -137,12 +140,11 @@ extension PostsModel { /// the transient transcript and die with it. The writer stays judge of /// record. func blindRead(mentor: MentorSessionModel) async { - guard let (id, session) = guardOpenPieceRun("a Blind Read", mentor: mentor) else { return } + guard let (id, session, home) = guardOpenPieceRun("a Blind Read", mentor: mentor) else { return } guard flushOrAbort(id) else { return } - // #179: the model owns the Home; an open piece implies a bound one. - guard let home = watchedHome, - let base = PostStore.latestPassSnapshot(id: id, home: home) - else { + // #179: the model owns the Home — the guard answered the session's + // OWN library (brief-28 identity). + guard let base = PostStore.latestPassSnapshot(id: id, home: home) else { lastError = "No Pass snapshot yet — run a Pass first." return } diff --git a/Museion/PostsModelWatcher.swift b/Museion/PostsModelWatcher.swift index 6669176..3cd1791 100644 --- a/Museion/PostsModelWatcher.swift +++ b/Museion/PostsModelWatcher.swift @@ -67,11 +67,55 @@ extension PostsModel { /// scan + start (or restart) the watcher. Called from WorkspaceView's /// root `.task(id: museionHome)` — first frame and every Home repoint, /// pane-independent. + /// brief-28: the dumb binder — it flips `watchedHome` unconditionally. + /// A REPOINT reaches it only after `repoint(to:)` passed its departure + /// gate (the Settings binding runs the gate before committing the + /// preference; the `.task` fires after that commit). func bind(home: URL) { startWatching(home: home) Task { await rescan() } } + /// brief-28 (home-repoint-retains-old-editor-target): a Home repoint is + /// a DOCUMENT DEPARTURE — the gate runs FIRST, the binding commits + /// after. The Settings path used to flip `watchedHome` under the open + /// session: the session's immutable target kept the OLD Home, a + /// same-slug piece in the new library made the ID-only reselect return + /// it, and autosave/Save/quit wrote the old library while structural + /// operations resolved against the new one (#198's departure gate never + /// saw this seam; a no-collision piece was torn down by the vanish + /// path with its dirty buffer dropped). + /// True = every open document landed through `sessionMayDepart` (the + /// three legs: unanswered #67, failed flush, never-loaded retype) and + /// the departed piece's state is cleared — the caller may bind the new + /// Home. False = `lastError` says why and NOTHING changed: the + /// preference stays A, `watchedHome` stays A, the session keeps its + /// (A, id) target and its buffer. No parallel gate — the same one + /// `select`/`newPost`/quit ride. + /// The in-memory draft survives: it has no Home until first save (#62) + /// and lands in the new library — the only alternative is dropping the + /// only copy. A running pass or Blind Read keeps its own completion + /// guard (#179: the advance refuses once `watchedHome` moved). + @discardableResult + func repoint(to newHome: URL) -> Bool { + guard newHome != watchedHome else { return true } // first bind / the same folder: nothing departs + guard departOpenDocuments() else { return false } + // The departed piece's state dies with it: a stale id under the new + // library is a ghost selection (a same-slug piece would read as + // open over an empty editor) and a stale ask would act on the new + // library's piece. Nothing auto-reopens — the writer picks from + // the new list (the reopen machinery stays where it is). + selectedPostID = nil + openPieceCards = [] + openPieceHasSnapshot = false + outlineGuardPieceID = nil + proseOverridePostID = nil + pendingConversion = nil + lastDraftWasOutline = false + pendingProject = nil + return true + } + private func startWatching(home: URL) { guard watchedHome != home else { return } watchedHome = home @@ -91,11 +135,16 @@ extension PostsModel { guard let home = watchedHome else { return } // Scan + the #67 disk read both run off-main (a synced large post.md // must never stall the UI on a watcher burst). - let openPostID = session?.postID // #114 audit: identity, not id — a same-id reopen (convert/restore/ // move) must not receive the OLD session's stale disk text as a // spurious #67 conflict. let openSession = session + // brief-28: the Home half of that identity — the open post's disk + // text is read from the session's OWN library. A session targeting + // another Home has no piece in this scan's tree; reading the + // current Home's same-slug file for it raised a spurious #67 on the + // old session. + let openPostID = openSession?.targets(home: home) == true ? openSession?.postID : nil let scanMemo = scanCache // detached capture, not a property read // The search's content signal: a re-read post.md (a cache miss) // changed library content even when its Post compares equal. Read @@ -108,6 +157,18 @@ extension PostsModel { return (posts, disk) }.value guard !Task.isCancelled else { return } + // Stale-scan guard (#137 suite find / finish): the snapshot can + // PREDATE the current selection, and a scan that outlived a Home + // repoint speaks for the OLD tree — bind's initial rescan (detached + // scan over the empty tree) can land its continuation after a + // select its scan never saw, "vanishing" a piece that exists, and a + // pre-repoint scan would land the old library's list under the new + // binding. Disk is the truth for vanished; a stale snapshot must + // not kill a live session (teardown cancels the debounce — + // unflushed edits would die with it); the new Home's own rescan + // owns everything (brief-28: hoisted — the list, the revision and + // the #67 text ride the same verdict, not just the vanish check). + guard watchedHome == home else { return } // #143: @Observable invalidates on assignment regardless of equality — // skip the no-op so panes don't regroup on our own autosave echoes. let listChanged = scanned != posts @@ -122,19 +183,9 @@ extension PostsModel { if listChanged || scanMemo.misses > missesBefore { contentRevision += 1 } - // Stale-scan guard (#137 suite find): the snapshot can PREDATE the - // current selection — bind's initial rescan (detached scan over the - // empty tree) can land its continuation after a select its scan never - // saw, "vanishing" a piece that exists. Disk is the truth for - // vanished; a stale snapshot must not kill a live session (teardown - // cancels the debounce — unflushed edits would die with it). - // #137 audit (finish): a scan that outlived a Home repoint speaks - // for the OLD tree — never let it kill a session selected under - // the NEW home (the id is missing from the old snapshot by - // 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 }), PostStore.folder(of: id, home: home) == nil { selectedPostID = nil // the post vanished (deleted in Finder or here) - if let open = session, open.postID == id { + if let open = session, open.targets(postID: id, home: home) { open.teardown(flushFirst: false) // post is gone; cancel the debounce session = nil } diff --git a/Museion/PostsModelWrites.swift b/Museion/PostsModelWrites.swift index 08802fb..68500a9 100644 --- a/Museion/PostsModelWrites.swift +++ b/Museion/PostsModelWrites.swift @@ -57,7 +57,7 @@ extension PostsModel { let moved = try PostStore.rename(post, to: title, home: home) if selectedPostID == post.id { selectedPostID = moved.id - if session?.postID == post.id { + if openSessionTargets(post.id) { // brief-28: identity session = EditorSession(postID: moved.id, home: home) wireSession() } @@ -74,7 +74,7 @@ extension PostsModel { try PostStore.trash(post, home: home) if selectedPostID == post.id { selectedPostID = nil - if let open = session, open.postID == post.id { + if let open = session, openSessionTargets(post.id) { // brief-28: identity open.teardown(flushFirst: false) session = nil } @@ -129,7 +129,9 @@ extension PostsModel { /// #33: internal — the Micropub draft flow (Micropub.swift) flushes /// through the same rail. func flushOrAbort(_ postID: String) -> Bool { - guard let session, session.postID == postID else { return true } + // brief-28: identity — only THIS library's open piece flushes here; a + // session born under another Home is not the caller's piece. + guard let session, openSessionTargets(postID) else { return true } return sessionMayDepart(session) } @@ -208,7 +210,7 @@ extension PostsModel { guard flushOrAbort(post.id) else { return } performWrite { home in try PostStore.move(post, to: project, home: home) - if session?.postID == post.id { + if openSessionTargets(post.id) { // brief-28: identity session = EditorSession(postID: post.id, home: home) wireSession() } @@ -226,7 +228,7 @@ extension PostsModel { if selectedPostID == post.id { selectedPostID = nil } - if let open = session, open.postID == post.id { + if let open = session, openSessionTargets(post.id) { // brief-28: identity open.teardown(flushFirst: false) // already flushed above session = nil } @@ -242,7 +244,7 @@ extension PostsModel { guard flushOrAbort(post.id) else { return } performWrite { home in try PostStore.restore(post, home: home) - if let open = session, open.postID == post.id { + if openSessionTargets(post.id) { // brief-28: identity session = EditorSession(postID: post.id, home: home) wireSession() } else { @@ -263,7 +265,7 @@ extension PostsModel { // invisible. dir − 1 = project dir (…/archive/), − 2 = root. guard let boundHome = watchedHome else { return } func openPieceInArchivedProject() -> String? { - guard let id = session?.postID, + guard let id = session?.postID, openSessionTargets(id), // brief-28: identity let projectDir = PostStore.folder(of: id, home: boundHome)?.deletingLastPathComponent(), projectDir.lastPathComponent == name, projectDir.deletingLastPathComponent().lastPathComponent == "archive" diff --git a/Museion/WorkspaceView.swift b/Museion/WorkspaceView.swift index a126643..7ba362e 100644 --- a/Museion/WorkspaceView.swift +++ b/Museion/WorkspaceView.swift @@ -12,6 +12,7 @@ // WorkspaceChrome.swift; RailButton stays (the rail is its only caller). // +import AppKit import SwiftUI /// The post-gate main surface. Posts shows the full four-column workspace; @@ -248,6 +249,37 @@ struct WorkspaceView: View { ) } + /// brief-28 (home-repoint-retains-old-editor-target): a Home repoint is a + /// document departure. The binding's setter IS the gate — + /// `repointMuseionHome` runs the departure gate first and commits the + /// preference (and its persistence) only when every open document + /// landed; the root `.task(id: museionHome)` binds the model after that + /// commit. A refusal keeps Home A and every buffer, and speaks the #198 + /// reason the way #200's quit refusal does — the Posts strip that shows + /// `lastError` is not in sight from Settings. + private var homeRepointBinding: Binding { + Binding( + get: { gate.museionHome }, + set: { newHome in + guard gate.repointMuseionHome(to: newHome) else { + presentRepointRefusal() + return + } + }, + ) + } + + /// Hosted tests never present (the quit refusal's guard convention). + private func presentRepointRefusal() { + guard !AppGateState.hostedTestRun else { return } + let alert = NSAlert() + alert.messageText = "Home not changed — a piece needs you first" + alert.informativeText = gate.posts.lastError + ?? "An open piece could not be saved. Tend to it, then choose the folder again." + alert.addButton(withTitle: "Back to Museion") + alert.runModal() + } + /// #151: the pill/card state — the gate's phase machine plus the /// provisioning failure verdict. private var statusVisibility: EngineStatusSurface.Visibility { @@ -259,7 +291,6 @@ struct WorkspaceView: View { @ViewBuilder private func paneContent(_ geo: GeometryProxy) -> some View { - @Bindable var gate = gate switch selection { case .posts: // #14: mentor column hands in the app-scoped model + gate's winner. @@ -303,8 +334,9 @@ struct WorkspaceView: View { // #137 (S4): a committed Chat model change restarts the resident // chat engine in place (slice A's engine-side API; deferred to // turn end while streaming). + // brief-28: the Home control binds through the repoint gate. SettingsPaneView( - home: $gate.museionHome, + home: homeRepointBinding, binaryPath: gate.gateModel.currentBinaryPath, onChatSurfaceWrite: { gate.mentor.requestRestart() }, ) diff --git a/MuseionTests/PostsModelRepointTests.swift b/MuseionTests/PostsModelRepointTests.swift index 346fb11..b561819 100644 --- a/MuseionTests/PostsModelRepointTests.swift +++ b/MuseionTests/PostsModelRepointTests.swift @@ -17,18 +17,35 @@ // (flush AND quit), a no-collision repoint tears down cleanly (the old // vanish path dropped the dirty buffer), a card scan from the old library // never lands on the new library's piece (identity re-check at -// COMPLETION), and a pass started after the repoint runs against the new -// library. +// COMPLETION — the scan seam holds it past the repoint), and a pass +// started after the repoint runs against the new library. // // Two-Home rig: `projects/posts/shared/post.md` in BOTH libraries — the // collision shape the finding names; differing bodies so a wrong-library -// read is observable. +// 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 +// WorkspaceView's binding and root `.task(id:)` drive them. // import Foundation @testable import Museion import Testing +/// brief-28 rig: a Sendable one-shot flag the stale card-scan pin's park +/// probe reads (the detached scanner sets it from off-main; pollUntil's +/// per-iteration probe must not consume anything). +private final class ParkedFlag: @unchecked Sendable { + private let lock = NSLock() + private var value = false + var isSet: Bool { + lock.withLock { value } + } + + func set() { + lock.withLock { value = true } + } +} + @Suite("PostsModelRepointTests") @MainActor struct PostsModelRepointTests { @@ -65,7 +82,17 @@ struct PostsModelRepointTests { #expect(model.session?.text == "# Shared\n\nA body\n") model.session?.edit("# Shared\n\nA body, typed in A\n") - model.bind(home: homeB) // the Settings repoint + // The Settings repoint: the gate first, the binding after. + #expect(model.repoint(to: homeB)) + // Ordering: the departure landed on A and NOTHING has moved yet — + // watchedHome is still A until the binding commits, and no live + // session targets an A piece. + #expect(PostStore.readBody(id: "shared", home: homeA) == "# Shared\n\nA body, typed in A\n") + #expect(model.watchedHome == homeA) + #expect(model.session == nil) + #expect(model.selectedPostID == nil) + model.bind(home: homeB) + #expect(model.watchedHome == homeB) model.select("shared") // B's piece opened from B — not the retained A session (whose @@ -91,7 +118,8 @@ struct PostsModelRepointTests { try denyWrites(to: pieceDir) defer { try? allowWrites(to: pieceDir) } - model.bind(home: homeB) // the Settings repoint + // The Settings repoint — refused: the gate fires before any change. + #expect(model.repoint(to: homeB) == false) // ORDERING: the gate fired before ANY state changed — the binding, // the selection, the session's (Home, ID) target and its buffer. @@ -104,11 +132,13 @@ struct PostsModelRepointTests { #expect(model.lastError != nil) #expect(PostStore.readBody(id: "shared", home: homeB) == "# Shared\n\nB body\n") - // Writability restored → the edits land on A first, then the - // repoint goes through and departs the session. + // Writability restored → the edits land on A first (watchedHome + // still A until the binding commits), then the repoint departs. try allowWrites(to: pieceDir) - model.bind(home: homeB) + #expect(model.repoint(to: homeB)) #expect(PostStore.readBody(id: "shared", home: homeA) == "# Shared\n\nA body, typed in A\n") + #expect(model.watchedHome == homeA) + model.bind(home: homeB) #expect(model.session == nil) #expect(model.selectedPostID == nil) #expect(model.watchedHome == homeB) @@ -121,7 +151,8 @@ struct PostsModelRepointTests { // #67: a foreign disk body arrived — the alert is up, unanswered. model.session?.diskDidChange(diskText: "foreign body from disk") - model.bind(home: homeB) // the Settings repoint + // The Settings repoint — refused. + #expect(model.repoint(to: homeB) == false) #expect(model.watchedHome == homeA) #expect(model.selectedPostID == "shared") @@ -147,7 +178,8 @@ struct PostsModelRepointTests { #expect(model.session?.loadFailed == true) model.session?.edit("# Retyped words over a file that never loaded") - model.bind(home: homeB) // the Settings repoint + // The Settings repoint — refused: the retype is the only copy. + #expect(model.repoint(to: homeB) == false) #expect(model.watchedHome == homeA) #expect(model.selectedPostID == "shared") @@ -161,13 +193,14 @@ struct PostsModelRepointTests { model.select("unique") model.session?.edit("# Unique\n\nA body, typed in A\n") - model.bind(home: homeB) // the Settings repoint - - // The old session's edits landed on A BEFORE anything moved — the - // vanish path used to tear it down without a flush. + // The Settings repoint — accepted: the old session's edits landed + // on A BEFORE anything moved (the vanish path used to tear it down + // without a flush). + #expect(model.repoint(to: homeB)) #expect(PostStore.readBody(id: "unique", home: homeA) == "# Unique\n\nA body, typed in A\n") #expect(model.session == nil) #expect(model.selectedPostID == nil) + model.bind(home: homeB) // No ghost: the new library's rescan leaves nothing selected, nothing open. try await pollUntil { model.posts.contains { $0.id == "shared" } } #expect(model.session == nil) @@ -175,6 +208,44 @@ struct PostsModelRepointTests { #expect(model.watchedHome == homeB) } + @Test func `a card scan from the old library never lands on the new library's same-slug piece`() async throws { + let (model, homeA, homeB) = try makeTwoHomes(bodyA: "# Shared\n\nA body\n", bodyB: "# Shared\n\nB body\n") + let folderA = try #require(PostStore.folder(of: "shared", home: homeA)) + let folderB = try #require(PostStore.folder(of: "shared", home: homeB)) + _ = try FixCardStore.submit(piecePath: folderA.path, cards: [card(pattern: "Hedging", quote: "A body")]) + _ = try FixCardStore.submit(piecePath: folderB.path, cards: [card(pattern: "Telling", quote: "B body")]) + // HOLD the old library's scan past the repoint: the injected scanner + // parks on A's folder until the test releases it (a detached disk + // read is otherwise faster than any arrangement); B's scans run + // free. The park probe is a flag, never a consuming semaphore wait — + // pollUntil re-evaluates its condition per iteration. + let parked = ParkedFlag() + let release = DispatchSemaphore(value: 0) + model.scanPieceCards = { url in + if url == folderA { + parked.set() + _ = release.wait(timeout: .now() + 30) // bounded: a failed test must not leak a parked thread + } + return FixCardStore.scan(pieceURL: url) + } + model.select("shared") // the A scan parks inside the detached read + try await pollUntil { parked.isSet } + + // The repoint, then B's same-slug piece opens and ITS scan lands. + #expect(model.repoint(to: homeB)) + model.bind(home: homeB) + model.select("shared") + try await pollUntil { model.openPieceCards.map(\.pattern) == ["Telling"] } + #expect(model.openPieceCards.map(\.pattern) == ["Telling"]) + + // Release the stale A scan: its continuation completes AFTER the new + // library's piece is open — identity at completion, never the id. + 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 hop-back land + #expect(model.openPieceCards.map(\.pattern) == ["Telling"]) // never A's cards + } + @Test func `a pass started after the repoint runs against the new library`() async throws { let (model, homeA, mentor) = try makePassRig() defer { mentor.shutdown() } @@ -187,7 +258,9 @@ struct PostsModelRepointTests { model.select("shared") #expect(model.session?.text == "# Shared\n\nA body\n") - model.bind(home: homeB) // the Settings repoint + // The Settings repoint: gate, then binding. + #expect(model.repoint(to: homeB)) + model.bind(home: homeB) model.select("shared") #expect(model.session?.text == "# Shared\n\nB body\n") diff --git a/MuseionTests/PostsModelTests.swift b/MuseionTests/PostsModelTests.swift index 0d7542f..c6f322b 100644 --- a/MuseionTests/PostsModelTests.swift +++ b/MuseionTests/PostsModelTests.swift @@ -579,7 +579,10 @@ struct PostsModelWriteRailTests { let homeB = FileManager.default.temporaryDirectory .appendingPathComponent("repoint-\(UUID().uuidString)", isDirectory: true) try FileManager.default.createDirectory(at: homeB, withIntermediateDirectories: true) - rig.model.bind(home: homeB) // the Settings repoint, mid-pass + // the Settings repoint, mid-pass — brief-28: gate first (the open + // piece departs cleanly), then the binding commits. + #expect(rig.model.repoint(to: homeB)) + rig.model.bind(home: homeB) // Release the held turn as a NORMALLY ended one — .ended + no refusal. // Poll for the PARK first: runningPass flips before the one-shot // engine spawns, so ending the hold in that window false-fails -- 2.36.6 From 108075239d6c754383e4bca2daedf08a6231c15c Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Mon, 23 Nov 2026 20:26:27 +0100 Subject: [PATCH 3/6] docs(brief-28): session log, INDEX row, changelog entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Home repoint rides the departure gate — devlog with the pattern- exhaustive identity table, the decisions (gate placement, nothing auto-reopens, draft survives, refusal posture, the disclosed not- converted sites), the gotchas (pollUntil's consuming probe, the free-function filter trap, the current-session teardown shape), and the Verify line: RED 6/6 at ca265d3b, full rail 715/715 at 8b0d43a, stale-scan pin mutation-checked, lint 0/0. The AGENTS.md DOX pass ships as an owner-apply patch beside the handoff (~/daedalus-builds/museion/brief-28-agents-owner-apply.patch, git apply --check clean against the branch head) — never written by this session, per the brief's standing rule. --- CHANGELOG.md | 2 + ...e-repoint-retains-old-editor-target_log.md | 220 ++++++++++++++++++ docs/devlog/INDEX.md | 1 + 3 files changed, 223 insertions(+) create mode 100644 docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 65516ed..1ed51e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. The format ### Fixed +- **editor:** A Home repoint is a guarded document departure (finding `museion/home-repoint-retains-old-editor-target`, argus cycle-5; unticketed fix, brief-28) — Settings → Choose… committed the new Home and flipped `watchedHome` without departing the open session: the session's immutable target kept the OLD Home, so a same-slug piece in the new library made the ID-only reselect return it (autosave/Save/quit wrote the old library while structural operations resolved against the new one), the new library's rescan raised a spurious reload conflict on it, a no-collision piece was torn down by the vanish path with its dirty buffer dropped, and a card scan from the old library could land on the new library's same-slug piece. #198's departure gate never saw this seam. Now `PostsModel.repoint(to:)` runs the SAME gate (`sessionMayDepart`'s three legs — unanswered conflict, failed flush, never-loaded retype; no parallel gate) BEFORE anything commits: a refusal changes nothing (preference, binding, the session's target and buffer stay; the #198 reason spoken once, the #200 quit-refusal posture, since no Posts strip is in sight from Settings), an acceptance lands the edits on the old library first and clears the departed piece's state — nothing auto-reopens. Document identity is (Home, ID) everywhere (`EditorSession.targets`, `PostsModel.openSessionTargets`): every bare `session.postID ==` comparison is retired across select, the structural rail, conversion, the pass guard, Micropub and the card refresh, and async continuations re-validate identity at COMPLETION (the card-scan hop-back; `rescan`'s stale-Home verdict is hoisted to cover the list, the revision and the #67 text, not just the vanish check). The in-memory draft survives a repoint (no Home until first save). +7 tests over a two-Home same-slug rig (the three refusal legs with ordering pinned, same-slug open + save on flush AND quit, no-collision cleanup, stale card scan via the per-model `scanPieceCards` seam — mutation-checked, pass after repoint), RED-first 6/6 at the pin. Suite 715 (unticketed fix, brief-28) + - **editor:** Quit no longer bypasses the document departure gate (#200, follow-up to the #198 audit) — `PostsModel.shutdown()` flushed both sessions best-effort and ignored the results, so quitting with an unanswered reload-conflict alert wrote the local text over the foreign disk body (`flush()` holds for conflicts only in the debounce, never itself), and a failed quit-time flush silently dropped the only copy of the edits. Quit now routes through the same departure gate as navigation (`documentsMayDepart` → `sessionMayDepart`): an unanswered conflict never writes over the foreign body, and the failed-flush-at-quit posture is BLOCK QUIT — `WritingLockAppDelegate.applicationShouldTerminate` refuses termination with one spoken reason (running before the Cold Turkey ask, so a refusal never strands a walked-away block), pinned at the pure `quitReply(posts:)` seam. Finish-audit additions: a never-loaded session's retyped words refuse too (their flush is a vacuous success — the same gap closed for navigation), and the external guest's quit-time flush is pinned. +5 tests, all flip-verified. Suite 708 - **acp:** Engine backpressure can no longer defeat request deadlines, Stop, or teardown (finding `museion/acp-backpressure-defeats-timeout-and-shutdown`, argus cycle-4) — a hung engine that stops reading stdin fills the 64 KB pipe, and the ACP client's synchronous send blocked its ONE serial queue, the same queue carrying request-id allocation, pending registration, the timeout deadline, and close()'s bookkeeping barrier: the deadline never fired (a 0.1 s timeout on a 2 MB prompt stayed pending forever), a follow-up request hung at registration, Stop queued behind the stuck write, and close() synced behind it before SIGTERM was ever reachable — on MainActor (restart/quit) that was an app-wide unbounded hang. Stdin writes (and the stdin handle's own close, which a blocked write may still own) now ride a dedicated serial writer queue, leaving the state queue I/O-free: deadlines fire, Stop is accepted, bookkeeping answers, and close() runs SIGTERM → grace → SIGKILL → reap without queueing behind the writer. Wire order preserved (every send funnels through the one serial writer); healthy-engine contract untouched. +4 real-process smokes over two new zsh-fake modes (`neverRead` execs /bin/sleep — the probe's inert non-reading child, never a real profile; `serverPing` pins -32601 reply delivery): 3 RED-first at base on exactly the three mechanisms, healthy-contract pin green at base. Suite 697 (unticketed fix, brief-27) diff --git a/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md b/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md new file mode 100644 index 0000000..732bb6d --- /dev/null +++ b/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md @@ -0,0 +1,220 @@ +# brief-28 — Home repoint rides the departure gate (document identity is (Home, ID)) + +> **Date:** 2026-11-23 +> **Type:** fix (unticketed) +> **Reference:** finding `museion/home-repoint-retains-old-editor-target` (argus cycle-5 bugs pass, `museion-bugs.md` finding 1; HIGH, certain) — branch `fix/home-repoint-retains-old-editor-target` off `main` at `ca265d3bd359e663216aa91d4778e2bdef8a36eb` + +## Goal + +Settings → Content → Choose… committed the new Home (preference + UserDefaults +through `AppGateState.museionHome.didSet`) and the root `.task(id:)` → `bind` → +`startWatching` flipped `watchedHome` WITHOUT departing the open session. The +session's immutable `SessionTarget` kept the OLD Home, so under the new UI: + +- a same-slug piece in the new library made `select`'s ID-only reselect return + the retained A session — autosave/Save/quit wrote A while structural + operations resolved against B; +- the new library's rescan read B's same-slug `post.md` for the A session and + raised a spurious #67 on it (differing bodies); +- a no-collision piece was torn down by the vanish path with its dirty buffer + dropped (data loss); +- a card scan started under A landed its cards on B's same-slug piece when it + completed after a reselect (the ID-only hop-back guard). + +#198's departure gate never saw this seam (it guards navigations, not the +Home binding). Fix direction (argus, binding): repoint = a GUARDED DOCUMENT +DEPARTURE before any commit; identity (Home, ID) everywhere, re-checked at +async COMPLETION. + +## What Was Done + +**The gate (gate-first, commit-after):** + +- `PostsModel.repoint(to:) -> Bool` (PostsModelWatcher.swift, beside `bind`): + `guard newHome != watchedHome` (first bind / same folder: nothing departs) + → `departOpenDocuments()` (the brief-25 gate — `sessionMayDepart`'s three + legs: unanswered #67, failed flush, never-loaded retype; NO parallel gate) + → on true, the departed piece's state dies with it (`selectedPostID`, + `openPieceCards`, `openPieceHasSnapshot`, `outlineGuardPieceID`, + `proseOverridePostID`, `pendingConversion`, `lastDraftWasOutline`, + `pendingProject`). On false NOTHING changed: `lastError` says why (#198's + strings), the preference/binding/target/buffer are untouched. +- `AppGateState.repointMuseionHome(to:)` (HomeResolution.swift): `guard + posts.repoint(to:)` FIRST, `museionHome = newHome` (its `didSet` persists) + only after. The ONE runtime repoint entry. +- WorkspaceView: the Settings Home control binds through `homeRepointBinding` + — the binding's setter IS the gate (`repointMuseionHome`, then nothing + else: the root `.task(id: museionHome)` binds the model after the commit). + `$gate.museionHome` and the now-dead `@Bindable var gate` are gone from + `paneContent`. A refusal presents one hosted-guarded `NSAlert` carrying + `posts.lastError` (#200's quit-refusal posture — the Posts strip that shows + it is not in sight from Settings). +- `bind` stays the dumb binder by design (see Decisions). + +**Document identity is (Home, ID) — the pattern-exhaustive sweep:** + +- `EditorSession.targets(postID:home:)` / `targets(home:)` — the pair; the + target is immutable, so a session born under another Home is a foreign + document to a model whose `watchedHome` moved past it. +- `PostsModelIdentity.swift` (new): `openSessionTargets(_:)` — the model's ONE + "is this piece open" question (`session.targets(postID: watchedHome, id)`). +- Every model-side ID-only session comparison converted: + +| Site | Was | Now | +|------|-----|-----| +| `PostsModel.select` reselect no-op | `session.postID == id` | `session.targets(postID: id, home: watchedHome)` — a foreign session departs below | +| `PostsModel.canArmWritingLock` / `editorBodyText` | `session.postID == selectedPostID` | `openSessionTargets(id)` | +| `PostsModelOutline.openUnguarded` (depart test + reuse test) | `postID != id` / `id == postID` | `!targets(postID:home:)` / `targets(postID:home:)` | +| `PostsModelOutline.stageConversion` / `convertToPost` | `session.postID == post.id` | `openSessionTargets` | +| `PostsModelWrites.flushOrAbort` | `session.postID == postID` | `openSessionTargets(postID)` | +| `PostsModelWrites` rename / trash / moveToProject / archivePost / restorePost / `unarchiveProject`'s `openPieceInArchivedProject` | `session?.postID == post.id` | `openSessionTargets(post.id)` | +| `PostsModelPasses.guardOpenPieceRun` | `id == selectedPostID` (+ callers re-read `watchedHome`) | `session.targets(postID: id, home: watchedHome)`; the answer carries the validated `home` (3-tuple, callers stop re-reading) | +| `Micropub.micropubSendDraft` launch | `id == selectedPostID`, then `watchedHome` + `folder(of:)` | identity at launch; the wire reads the session's OWN library | +| `PostsModelCards.refreshCards` launch | `session?.postID` + `watchedHome` | `session.targets(postID:home:)` | + +**Async continuations re-validate at COMPLETION:** + +- `refreshCards` hop-back: `self.session?.targets(postID: id, home: home)` — + the seeded site (PostsModelCards:24-42). The scanner is now the per-model + injectable `scanPieceCards` (never static — the hosted suite runs in + parallel) so the deterministic stale-result pin can HOLD an old-library scan + past a repoint. +- `rescan` (PostsModelWatcher): the stale-Home verdict is HOISTED — `guard + watchedHome == home` right after the detached scan, so a scan that outlived + a repoint applies NOTHING (list, revision, vanish check, #67 text), not + just the vanish check as before; the #67 disk read runs only for a session + targeting the scan's own Home (`openPostID` is identity-gated); the vanish + teardown matches identity and still tears down the CURRENT session. +- `Micropub`'s completion stamp (`stampMicropubURL(id:home:)` after the + awaits) keeps the CAPTURED pair — the piece actually sent — by construction; + re-validating against the live session would skip a correct write after a + mid-send repoint. Disclosed, left as is. + +**Tests:** `PostsModelRepointTests` (7, new file) over a two-Home same-slug +rig (`projects/posts/shared/post.md` in both, differing bodies); the #179 +mid-pass repoint pin (`PostsModelWriteRailTests`) now drives the real Settings +path (`repoint(to:)` then `bind`). + +## Decisions & Rationale + +| Decision | Rationale | +|----------|-----------| +| Gate in the Settings binding's setter + `repointMuseionHome`, NOT in `bind` | The gate must precede the preference commit (`museionHome.didSet` persists immediately). A gate inside `bind` would leave `museionHome` = B while `watchedHome` = A — the UI showing a Home the model isn't watching. `bind` is reached only after a passed gate (or the same Home / first frame), so it stays unconditional. | +| `sessionMayDepart` via `departOpenDocuments` — no parallel gate | The brief's acceptance (1) and brief-25's contract: one gate, three legs, #198's strings. The refusal tests prove the composition (PostsModelDepartureTests 10/10 stay green beside the new suite). | +| Nothing auto-reopens after an accepted repoint | The brief left it to the implementer within existing machinery. Auto-reopening B's same-slug piece would be a NEW UX (the writer never chose it) and cannot even be decided at gate time — B isn't scanned until `bind` + rescan land. `selectedPostID = nil` is the #198 departure semantics (newPost/openExternal do the same); the writer picks from the new list. | +| The in-memory draft survives a repoint | A draft has no Home until first save (#62); it lands in the new library. The only alternatives — dropping it (the only copy) or refusing the repoint (new UX) — are worse. Disclosed; `pendingProject` (a stale A project name) IS cleared. | +| A running pass / Blind Read is not cancelled by the repoint | `sessionMayDepart` flushes; the session departs; the engine turn keeps its own completion guard (#179: the advance refuses once `watchedHome` moved) — pinned by the mid-pass test. Cancelling would desync the pass bar's Cancel ↔ Run state. | +| `pendingImportURLs` / `askNewProject` left alone | Both are sheet-modal (OriginAsk / NewProject) — a repoint cannot be requested while either is up, and neither is piece-specific. An import batch landing in B after a repoint is the writer's chosen library. | +| Refusal = one `NSAlert` (the #200 posture), not a Settings strip | Settings shows no `lastError` strip (PostsPaneView owns it); a silent Choose… is the dishonest outcome. The alert carries the exact #198 `lastError` string; hosted-guarded like the quit refusal. | +| `openSessionTargets` on the model + `targets` on the session (two helpers) | The session owns the pair (it knows its target); the model owns "which Home is current". `rescan` needs the scan's captured `home`, not `watchedHome`, so the session-level predicate is public within the module. | +| Rescan hoist of `watchedHome == home` | The old inline guard covered only the vanish check; a stale list could still land under the new binding (and bump `contentRevision`). One verdict at the top covers everything the continuation writes. | +| View-layer `session.postID == selectedPostID` (PostsPaneView:125) NOT converted | A render gate on the same pair; with the model invariant (the open session always targets `watchedHome`) it is correct by construction, and the view has no Home-identity vocabulary. Other view reads are nil-checks (`session?.postID != nil`) or title lookups, not comparisons. Disclosed, not exposed. | + +## Gotchas & Fixes + +| Problem | Root Cause | Fix | +|---------|------------|-----| +| Stale-scan pin's park probe never passed (5 s poll timeout) | `pollUntil` re-evaluates its `where !condition()` per iteration WITHOUT sleeping when true, and `DispatchSemaphore.wait` consumes — two parked scans drained the count in two iterations, the final `#expect(condition())` saw zero | A non-consuming `ParkedFlag` (NSLock box, `@unchecked Sendable`); the park itself is a bounded `release.wait(timeout: .now() + 30)` so a failed test never leaks a parked cooperative thread | +| `-only-testing:MuseionTests/PostsModelTests` matched ZERO tests in a filtered run (17 executed, not more) | Those `@Test`s are free functions; MuseionTests/AGENTS.md: "Suite-name filters do not run free functions" — the rail passed only because the sibling filters matched | The mid-pass pin is a `PostsModelWriteRailTests` member and ran in the FULL rail (715); no verification claim was taken from the filtered run for it | +| Vanish-path rewrite first tore down the CAPTURED session | `openSessionTargets(id)` reads `session` now while `openSession?.teardown` hit the pre-scan object — a same-id reopen mid-scan would leave the live session armed | `if let open = session, open.targets(postID: id, home: home)` — the original shape (current session), identity-matched | +| `swiftlint:disable:next large_tuple` flagged superfluous | The return type sat on the `) ->` line, not the `func` line the `:next` covers | Signature on one line so the tuple starts on the covered line (PostStore.swift:259 precedent) | +| A context-fuzzy patch duplicated "The refusal" in a doc comment | The edit span started mid-line | Re-read and re-patched the two lines | + +## Files Changed + +| File | Change Summary | +|------|---------------| +| `Museion/PostsModelWatcher.swift` | `repoint(to:)` (the gate); `bind` documented as the dumb binder; rescan: identity-gated #67 read, hoisted stale-Home verdict, identity vanish teardown | +| `Museion/PostsModelIdentity.swift` (new) | `openSessionTargets(_:)` | +| `Museion/EditorSession.swift` | `targets(postID:home:)` / `targets(home:)` | +| `Museion/HomeResolution.swift` | `AppGateState.repointMuseionHome(to:)` | +| `Museion/WorkspaceView.swift` | `homeRepointBinding` (gate in the setter) + hosted-guarded refusal alert; `import AppKit`; dead `@Bindable` removed | +| `Museion/PostsModel.swift` | `select` reselect by identity; `canArmWritingLock`/`editorBodyText` by identity; `scanPieceCards` seam | +| `Museion/PostsModelWrites.swift` | `flushOrAbort` + the six structural ops by identity | +| `Museion/PostsModelOutline.swift` | `openUnguarded`, `stageConversion`, `convertToPost` by identity | +| `Museion/PostsModelCards.swift` | identity at launch AND completion; scanner through the seam | +| `Museion/PostsModelPasses.swift` | `guardOpenPieceRun` identity + returns the validated Home; callers consume it | +| `Museion/Micropub.swift` | identity at launch | +| `MuseionTests/PostsModelRepointTests.swift` (new) | 7 pins | +| `MuseionTests/PostsModelTests.swift` | mid-pass pin drives `repoint(to:)` + `bind` | +| `CHANGELOG.md`, `docs/devlog/INDEX.md`, this log | docs | +| `AGENTS.md`, `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | OWNER-APPLY patch only (see Open Items) — never written by this session | + +## Open Items & Next Steps + +- [ ] AGENTS.md DOX pass ships as an owner-apply patch: + `~/daedalus-builds/museion/brief-28-agents-owner-apply.patch` — `git + apply --check` clean against `8b0d43a` (3 files, 25 changed lines: the + PostsModel/Watcher/Writes/Editor-core/Settings/WorkspaceView bullets, the + `AppGateState.museionHome` bullet, the MuseionTests suite map row, and the + root 10-most-recent window row). Apply from the branch head with + `git apply ~/daedalus-builds/museion/brief-28-agents-owner-apply.patch`. +- [ ] GitNexus `impact`/`detect_changes` were NOT run: `.gitnexus/run.cjs` is + absent at base and no GitNexus capability is exposed (the argus cycle-5 + audit hit the same wall). The blast radius was traced by hand instead — the + table above IS the caller trace. The root AGENTS.md index-count line + (`7133 symbols …`) is therefore NOT refreshed in the patch. +- [ ] Coupled (HELD behind this PR's merge, per the brief): + `museion/external-watch-compares-unnormalized-text` dispatches from the + merged state. This diff touched `rescan`'s :94-98 (identity-gated read) and + the vanish block (:135-146 → hoisted verdict), NOT the normalization seam + itself (`readBody`'s representation at the former :107 and + PostsModelImports.swift:69-70 are untouched) — the two changes are + disjoint in mechanism. +- [ ] Not in scope, observed while tracing: `newProjectPending(named:)` sets + `pendingProject` BEFORE `newPost()` and leaves it set when the departure + gate refuses the new post (a stale pending target with no draft). Reported + to @aegis as an observation; `repoint` clears `pendingProject` on its own + path regardless. + +## Verification + +- **Base / pin:** `ca265d3bd359e663216aa91d4778e2bdef8a36eb` = live `main` tip + at claim (`tea api repos/AlexKucera/museion/branches/main`, 20:05 CET) and + still at handoff (`git ls-remote`, 20:26 CET; re-checked again before the + final report). Zero drift. +- **RED first** at the pin (commit `bce6abb`), rail-filtered + `./scripts/full-test.sh start -- -only-testing:MuseionTests/PostsModelRepointTests`: + `6 executed / 0 passed / 6 failed / 0 skipped (xcodebuild exit 65)`, zero + compile errors — each on the finding's signature: `session.text → "A body, + typed in A"` under the B binding, `targets(postID: "shared", home: homeB) + → false`, B's edits landing on A's disk, `watchedHome → …/B` despite a + refused flush / unanswered conflict / never-loaded retype, and the + no-collision vanish path dropping the dirty buffer (`readBody(A) → "# Unique + \n\nA body\n"`). +- **GREEN, full rail** at `8b0d43a` (the fix commit; tree clean at start): + `./scripts/full-test.sh start` → `./scripts/full-test.sh status` → + `715 executed / 715 passed / 0 failed / 0 skipped (xcodebuild exit 0)`; + `summary.json` → `result: Passed, totalTestCount: 715`; `** TEST SUCCEEDED **`; + 715 = the cycle-5 baseline 708 + the 7 new pins, all 7 named passed in the + log; `PostsModelDepartureTests` 10/10 (#198 + #200 matrix green beside the + new suite — the gates compose); the mid-pass `PostsModelWriteRailTests` pin + passed on its new path. +- **Mutation check** (the stale card-scan pin's honest RED — its seam cannot + exist at base, so it is GREEN-only there): completion guard reverted to the + ID-only base form → rail-filtered `7 executed / 6 passed / 1 failed`, ONLY + that pin, `openPieceCards → ["Hedging"]` (A's cards on B's piece); restored + byte-exact (sha256 prefix `9c8fb55264f5ac1c` before and after), zero + `MUTATION-CHECK` tokens repo-wide. +- **Lint:** `swiftformat --lint .` → `0/152 files require formatting`; + `swiftlint lint --quiet` → zero violations (both at `8b0d43a`; the pre-push + hook's scoped gate passed on both pushes). +- **Evidence types:** failing-test proof (RED → GREEN on the rail) for the + gate, the ordering, the same-slug save sinks, the no-collision cleanup, the + pass-after-repoint; mutation-check proof for the completion re-check; + structural proof for the view wiring (`homeRepointBinding` → + `repointMuseionHome` → `posts.repoint` precedes `museionHome = newHome`) — + the preference leg is NOT unit-pinned: `AppGateState`'s `didSet` writes the + REAL `UserDefaults.standard` (MuseionTests/AGENTS.md: never touch the + machine), so driving a repoint through `AppGateState` in a hosted test + would point the owner's next launch at a temp dir. Unverified by design; + disclosed. +- **Not run:** the MuseionUITests smoke (outside the rail by design); no GUI + reproduction of the Settings flow (same posture as the scan — static trace + + model-level pins). +- `pool: 0 in flight` at handoff — no subagents spawned (Z.ai draws: this + main only). + +--- + +*Log written by daedalus (brief-28, profile daedalus) — format per the write-log skill* diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index 29dc47a..f424ff0 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| +| 2026-11-23 | fix | [20261123-home-repoint-retains-old-editor-target_log.md](20261123-home-repoint-retains-old-editor-target_log.md) | Unticketed fix (brief-28, argus cycle-5): a Home repoint is a guarded document departure — the gate runs before the preference/binding commit, the refusal keeps Home A and the buffers; document identity is (Home, ID) across the model and re-checked at async completion (card scan, rescan); RED-first 6/6 at ca265d3b, stale-scan pin mutation-checked; rail 715/715 | | 2026-11-19 | fix | [20261119-issue200-gate-quit-time-flushes-through-departure-gate_log.md](20261119-issue200-gate-quit-time-flushes-through-departure-gate_log.md) | Quit routes through the departure gate (#200): conflict-held shutdown, BLOCK-QUIT at applicationShouldTerminate, never-loaded-retype guard; finish-audit fixes; rail 708/708 | | 2026-11-17 | fix | [20261117-acp-backpressure-defeats-timeout-and-shutdown_log.md](20261117-acp-backpressure-defeats-timeout-and-shutdown_log.md) | Unticketed fix (brief-27, argus cycle-4): stdin writes move to a dedicated writer queue — engine backpressure can no longer defeat the request deadline, Stop, or a bounded reaping close; neverRead/serverPing fake modes, 3 RED-first smokes + healthy-contract pin, suite 697/697 | | 2026-11-17 | issue | [20261117-issue193-split-fat-files-along-postsmodel-pattern_log.md](20261117-issue193-split-fat-files-along-postsmodel-pattern_log.md) | Three most-re-read files split into 8 domain-extension files, move-only (three audits concur); 693/693 | -- 2.36.6 From 97712fbacb637e472e964a51e92cf44f5d2fd942 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Mon, 23 Nov 2026 20:26:54 +0100 Subject: [PATCH 4/6] =?UTF-8?q?docs(brief-28):=20name=20the=20filter=20tra?= =?UTF-8?q?p=20precisely=20=E2=80=94=20file=20name=20=E2=89=A0=20suite=20n?= =?UTF-8?q?ame?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PostsModelTests.swift file holds free-function @Tests AND the PostsModelWriteRailTests suite; the filter matched neither. The devlog row said 'free functions' alone, which undersold it. --- .../20261123-home-repoint-retains-old-editor-target_log.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md b/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md index 732bb6d..2b56fd9 100644 --- a/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md +++ b/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md @@ -115,7 +115,7 @@ path (`repoint(to:)` then `bind`). | Problem | Root Cause | Fix | |---------|------------|-----| | Stale-scan pin's park probe never passed (5 s poll timeout) | `pollUntil` re-evaluates its `where !condition()` per iteration WITHOUT sleeping when true, and `DispatchSemaphore.wait` consumes — two parked scans drained the count in two iterations, the final `#expect(condition())` saw zero | A non-consuming `ParkedFlag` (NSLock box, `@unchecked Sendable`); the park itself is a bounded `release.wait(timeout: .now() + 30)` so a failed test never leaks a parked cooperative thread | -| `-only-testing:MuseionTests/PostsModelTests` matched ZERO tests in a filtered run (17 executed, not more) | Those `@Test`s are free functions; MuseionTests/AGENTS.md: "Suite-name filters do not run free functions" — the rail passed only because the sibling filters matched | The mid-pass pin is a `PostsModelWriteRailTests` member and ran in the FULL rail (715); no verification claim was taken from the filtered run for it | +| `-only-testing:MuseionTests/PostsModelTests` matched ZERO tests in a filtered run (17 executed, not more) | The filter names a FILE, not a suite: `PostsModelTests.swift` holds free-function `@Test`s (unfilterable by suite) AND the `@Suite("write rail #179") struct PostsModelWriteRailTests`; "PostsModelTests" matches neither, and the rail's zero-match guard stays silent when sibling filters match | Filter by SUITE name (`grep '@Suite(' `), never by file name. The mid-pass pin ran in the FULL rail (715) under its suite; no verification claim was taken from the filtered run for it | | Vanish-path rewrite first tore down the CAPTURED session | `openSessionTargets(id)` reads `session` now while `openSession?.teardown` hit the pre-scan object — a same-id reopen mid-scan would leave the live session armed | `if let open = session, open.targets(postID: id, home: home)` — the original shape (current session), identity-matched | | `swiftlint:disable:next large_tuple` flagged superfluous | The return type sat on the `) ->` line, not the `func` line the `:next` covers | Signature on one line so the tuple starts on the covered line (PostStore.swift:259 precedent) | | A context-fuzzy patch duplicated "The refusal" in a doc comment | The edit span started mid-line | Re-read and re-patched the two lines | -- 2.36.6 From 92344e224cbff198e45f994939249e5a0906067b Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Mon, 23 Nov 2026 22:34:23 +0100 Subject: [PATCH 5/6] test(editor): pin the rescan stale-Home verdict and the draft-survives repoint (review r1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MF-1: the hoisted `guard watchedHome == home` in rescan was live logic with no pin — the only new guard still observable after the gate (a scan started under A can sit in its detached hop while the gate passes and bind flips to B; landing after B's own scan it would hold A's list under the B binding until the next B-side event, which with nothing open is never). `scanLibrary` is the per-model injectable library scanner beside `scanPieceCards` (captured before the hop); the pin parks an A scan past the repoint, lets B's scan land, releases, and asserts the list is still B's and `contentRevision` did not move. Mutation check: hoist removed → rail-filtered `9 executed / 8 passed / 1 failed`, ONLY that pin, `posts.map(\.id) → ["alpha"]` and `contentRevision → 3` vs `revision → 2`; restored byte-exact (sha256 prefix d86ce09d6b7e6bd2 before and after). N-1: the draft-survives-repoint decision pinned — newPost targets the selected A piece's project, the draft rides the repoint intact, and `saveDraft()` lands under B only, in the draft's OWN project even though B does not have it (materialize creates with intermediates). Filtered GREEN: PostsModelRepointTests + PostsModelDepartureTests 19/19. swiftformat 0/152, swiftlint 0. --- Museion/PostsModel.swift | 4 ++ Museion/PostsModelWatcher.swift | 3 +- MuseionTests/PostsModelRepointTests.swift | 69 +++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/Museion/PostsModel.swift b/Museion/PostsModel.swift index ec74ac5..0b8fb76 100644 --- a/Museion/PostsModel.swift +++ b/Museion/PostsModel.swift @@ -159,6 +159,10 @@ final class PostsModel { /// detached disk read is otherwise faster than any test can arrange). /// Per-model, never static (the hosted suite runs tests in parallel). var scanPieceCards: @Sendable (URL) -> [FixCardStore.StoredFixCard] = FixCardStore.scan + /// brief-28 r1 (MF-1): the library scanner behind `rescan` — the same + /// injection shape, so the stale-Home pin can HOLD an old library's scan + /// past a repoint and watch its continuation land under the new binding. + var scanLibrary: @Sendable (URL, PostScanCache?) -> [Post] = Post.scan /// #93: per-file watcher on the open external file — the #67 conflict /// check reused verbatim for foreign files. var externalWatcher = PostsWatcher() diff --git a/Museion/PostsModelWatcher.swift b/Museion/PostsModelWatcher.swift index 3cd1791..2ec4c3c 100644 --- a/Museion/PostsModelWatcher.swift +++ b/Museion/PostsModelWatcher.swift @@ -151,8 +151,9 @@ extension PostsModel { // the counter before the scan so the delta after it says "this // scan saw disk change" (#144's mounted half). let missesBefore = scanMemo.misses + let scan = scanLibrary // detached capture, not a property read let (scanned, openDiskText) = await Task.detached(priority: .userInitiated) { - let posts = Post.scan(home: home, cache: scanMemo) + let posts = scan(home, scanMemo) let disk = openPostID.flatMap { PostStore.readBody(id: $0, home: home) } return (posts, disk) }.value diff --git a/MuseionTests/PostsModelRepointTests.swift b/MuseionTests/PostsModelRepointTests.swift index b561819..73940d3 100644 --- a/MuseionTests/PostsModelRepointTests.swift +++ b/MuseionTests/PostsModelRepointTests.swift @@ -25,6 +25,10 @@ // 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 // 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 @@ -279,4 +283,69 @@ struct PostsModelRepointTests { #expect(onDiskA.contains("pass_state: First Draft")) #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) + } } -- 2.36.6 From cac66f6e764ae3486cf86db024b99a188fd556d4 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Mon, 23 Nov 2026 22:38:43 +0100 Subject: [PATCH 6/6] docs(brief-28 r1): evidence classes, r1 verify line, changelog/index to 717 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit N-2: "Identity checks — evidence classes" — pinned (card hop-back, rescan hoist, #179 guard) vs correct by construction (the Micropub stamp) vs invariant-equivalent defensive depth (the synchronous sweep and openPostID's gate: never independently observable under the gate-first invariant — belt to the gate's suspenders, not "every site test-verified"). Verify line for r1 at 92344e2: full rail 717/717, filtered 19/19, MF-1 mutation 9/8/1 restored byte-exact, lint 0/0. Gotchas: the partial patch regeneration, the status/current race. N-3 is the regenerated owner-apply patch beside the handoff. --- CHANGELOG.md | 2 +- ...e-repoint-retains-old-editor-target_log.md | 73 ++++++++++++++----- docs/devlog/INDEX.md | 2 +- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed51e9..7f25ce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. The format ### Fixed -- **editor:** A Home repoint is a guarded document departure (finding `museion/home-repoint-retains-old-editor-target`, argus cycle-5; unticketed fix, brief-28) — Settings → Choose… committed the new Home and flipped `watchedHome` without departing the open session: the session's immutable target kept the OLD Home, so a same-slug piece in the new library made the ID-only reselect return it (autosave/Save/quit wrote the old library while structural operations resolved against the new one), the new library's rescan raised a spurious reload conflict on it, a no-collision piece was torn down by the vanish path with its dirty buffer dropped, and a card scan from the old library could land on the new library's same-slug piece. #198's departure gate never saw this seam. Now `PostsModel.repoint(to:)` runs the SAME gate (`sessionMayDepart`'s three legs — unanswered conflict, failed flush, never-loaded retype; no parallel gate) BEFORE anything commits: a refusal changes nothing (preference, binding, the session's target and buffer stay; the #198 reason spoken once, the #200 quit-refusal posture, since no Posts strip is in sight from Settings), an acceptance lands the edits on the old library first and clears the departed piece's state — nothing auto-reopens. Document identity is (Home, ID) everywhere (`EditorSession.targets`, `PostsModel.openSessionTargets`): every bare `session.postID ==` comparison is retired across select, the structural rail, conversion, the pass guard, Micropub and the card refresh, and async continuations re-validate identity at COMPLETION (the card-scan hop-back; `rescan`'s stale-Home verdict is hoisted to cover the list, the revision and the #67 text, not just the vanish check). The in-memory draft survives a repoint (no Home until first save). +7 tests over a two-Home same-slug rig (the three refusal legs with ordering pinned, same-slug open + save on flush AND quit, no-collision cleanup, stale card scan via the per-model `scanPieceCards` seam — mutation-checked, pass after repoint), RED-first 6/6 at the pin. Suite 715 (unticketed fix, brief-28) +- **editor:** A Home repoint is a guarded document departure (finding `museion/home-repoint-retains-old-editor-target`, argus cycle-5; unticketed fix, brief-28) — Settings → Choose… committed the new Home and flipped `watchedHome` without departing the open session: the session's immutable target kept the OLD Home, so a same-slug piece in the new library made the ID-only reselect return it (autosave/Save/quit wrote the old library while structural operations resolved against the new one), the new library's rescan raised a spurious reload conflict on it, a no-collision piece was torn down by the vanish path with its dirty buffer dropped, and a card scan from the old library could land on the new library's same-slug piece. #198's departure gate never saw this seam. Now `PostsModel.repoint(to:)` runs the SAME gate (`sessionMayDepart`'s three legs — unanswered conflict, failed flush, never-loaded retype; no parallel gate) BEFORE anything commits: a refusal changes nothing (preference, binding, the session's target and buffer stay; the #198 reason spoken once, the #200 quit-refusal posture, since no Posts strip is in sight from Settings), an acceptance lands the edits on the old library first and clears the departed piece's state — nothing auto-reopens. Document identity is (Home, ID) everywhere (`EditorSession.targets`, `PostsModel.openSessionTargets`): every bare `session.postID ==` comparison is retired across select, the structural rail, conversion, the pass guard, Micropub and the card refresh, and async continuations re-validate identity at COMPLETION (the card-scan hop-back; `rescan`'s stale-Home verdict is hoisted to cover the list, the revision and the #67 text, not just the vanish check). The in-memory draft survives a repoint (no Home until first save). +9 tests over a two-Home same-slug rig (the three refusal legs with ordering pinned, same-slug open + save on flush AND quit, no-collision cleanup, stale card scan via the per-model `scanPieceCards` seam — mutation-checked, pass after repoint; review r1: the hoisted `rescan` stale-Home verdict via the `scanLibrary` seam — mutation-checked — and the draft-survives repoint), RED-first 6/6 at the pin. Suite 717 (unticketed fix, brief-28) - **editor:** Quit no longer bypasses the document departure gate (#200, follow-up to the #198 audit) — `PostsModel.shutdown()` flushed both sessions best-effort and ignored the results, so quitting with an unanswered reload-conflict alert wrote the local text over the foreign disk body (`flush()` holds for conflicts only in the debounce, never itself), and a failed quit-time flush silently dropped the only copy of the edits. Quit now routes through the same departure gate as navigation (`documentsMayDepart` → `sessionMayDepart`): an unanswered conflict never writes over the foreign body, and the failed-flush-at-quit posture is BLOCK QUIT — `WritingLockAppDelegate.applicationShouldTerminate` refuses termination with one spoken reason (running before the Cold Turkey ask, so a refusal never strands a walked-away block), pinned at the pure `quitReply(posts:)` seam. Finish-audit additions: a never-loaded session's retyped words refuse too (their flush is a vacuous success — the same gap closed for navigation), and the external guest's quit-time flush is pinned. +5 tests, all flip-verified. Suite 708 diff --git a/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md b/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md index 2b56fd9..71e5053 100644 --- a/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md +++ b/docs/devlog/20261123-home-repoint-retains-old-editor-target_log.md @@ -90,10 +90,22 @@ async COMPLETION. re-validating against the live session would skip a correct write after a mid-send repoint. Disclosed, left as is. -**Tests:** `PostsModelRepointTests` (7, new file) over a two-Home same-slug +**Tests:** `PostsModelRepointTests` (9, new file) over a two-Home same-slug rig (`projects/posts/shared/post.md` in both, differing bodies); the #179 mid-pass repoint pin (`PostsModelWriteRailTests`) now drives the real Settings -path (`repoint(to:)` then `bind`). +path (`repoint(to:)` then `bind`). r1 (athena) added the two the review +asked for: the hoisted `rescan` verdict (MF-1, via the `scanLibrary` seam) +and the draft-survives decision (N-1). + +## Identity checks — evidence classes (r1, athena N-2) + +"Identity everywhere" is NOT "every site test-verified". Three classes: + +| Class | Sites | Proof | +|-------|-------|-------| +| **Pinned** (failing-test / mutation proof) | `refreshCards` hop-back (the seeded site); `rescan`'s hoisted stale-Home verdict; the #179 mid-pass advance guard (pre-existing, its `lastError ==` line) | Mutation checks: ID-only card guard → `openPieceCards → ["Hedging"]`; hoist removed → `posts → ["alpha"]` + `contentRevision → 3` vs `2`. Both restored byte-exact. | +| **Correct by construction** | Micropub's completion stamp — the captured (Home, ID) of the piece actually sent | Not independently pinnable: a re-validate against the live session would SKIP a correct write after a mid-send repoint. Disclosed, left as is. | +| **Invariant-equivalent defensive depth** — never independently observable under the gate-first invariant | The whole synchronous sweep: `select` reselect, `openUnguarded`×2, `stageConversion`, `convertToPost`, `flushOrAbort`, the six structural ops, `guardOpenPieceRun`, Micropub launch, `refreshCards` launch, `canArmWritingLock`/`editorBodyText`, the vanish teardown, AND `rescan`'s `openPostID` identity gate (the #67 read) | None possible while the gate holds: a live session always targets `watchedHome`, so the id-only and identity forms agree on every reachable state (athena's run removed `openPostID`'s gate and reverted `select` to ID-only — the rail stayed green). They are belt to the gate's suspenders: any future path that bypasses `repoint` (a direct `bind` under a live session — what the mid-pass pin used to do) falls through to a departure instead of matching across libraries. Correct as design; not test-verified; say so. | ## Decisions & Rationale @@ -119,6 +131,8 @@ path (`repoint(to:)` then `bind`). | Vanish-path rewrite first tore down the CAPTURED session | `openSessionTargets(id)` reads `session` now while `openSession?.teardown` hit the pre-scan object — a same-id reopen mid-scan would leave the live session armed | `if let open = session, open.targets(postID: id, home: home)` — the original shape (current session), identity-matched | | `swiftlint:disable:next large_tuple` flagged superfluous | The return type sat on the `) ->` line, not the `func` line the `:next` covers | Signature on one line so the tuple starts on the covered line (PostStore.swift:259 precedent) | | A context-fuzzy patch duplicated "The refusal" in a doc comment | The edit span started mid-line | Re-read and re-patched the two lines | +| Regenerating the owner-apply patch from FRESH scratch copies kept only the r1 edits (9 changed lines vs the reviewed 19) | The regeneration script carries the full edit set; a partial re-run silently drops the earlier anchors | Re-ran the FULL pair set from fresh `a/` copies and compared hunk count/line count against the reviewed patch (69 lines / 5 hunks) before trusting it | +| `full-test.sh status` reported the MUTATION run's `9 / 8 / 1` while the full rail was in flight | `status` reads `current`, which a newer launch repoints; the loop broke on a finished-but-stale verdict | Read each run's OWN `summary.json` by run dir — the per-dir numbers are the record (full: Passed / 717) | ## Files Changed @@ -129,13 +143,13 @@ path (`repoint(to:)` then `bind`). | `Museion/EditorSession.swift` | `targets(postID:home:)` / `targets(home:)` | | `Museion/HomeResolution.swift` | `AppGateState.repointMuseionHome(to:)` | | `Museion/WorkspaceView.swift` | `homeRepointBinding` (gate in the setter) + hosted-guarded refusal alert; `import AppKit`; dead `@Bindable` removed | -| `Museion/PostsModel.swift` | `select` reselect by identity; `canArmWritingLock`/`editorBodyText` by identity; `scanPieceCards` seam | +| `Museion/PostsModel.swift` | `select` reselect by identity; `canArmWritingLock`/`editorBodyText` by identity; `scanPieceCards` + `scanLibrary` (r1) seams | | `Museion/PostsModelWrites.swift` | `flushOrAbort` + the six structural ops by identity | | `Museion/PostsModelOutline.swift` | `openUnguarded`, `stageConversion`, `convertToPost` by identity | | `Museion/PostsModelCards.swift` | identity at launch AND completion; scanner through the seam | | `Museion/PostsModelPasses.swift` | `guardOpenPieceRun` identity + returns the validated Home; callers consume it | | `Museion/Micropub.swift` | identity at launch | -| `MuseionTests/PostsModelRepointTests.swift` (new) | 7 pins | +| `MuseionTests/PostsModelRepointTests.swift` (new) | 9 pins (7 + r1's two) | | `MuseionTests/PostsModelTests.swift` | mid-pass pin drives `repoint(to:)` + `bind` | | `CHANGELOG.md`, `docs/devlog/INDEX.md`, this log | docs | | `AGENTS.md`, `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | OWNER-APPLY patch only (see Open Items) — never written by this session | @@ -144,10 +158,11 @@ path (`repoint(to:)` then `bind`). - [ ] AGENTS.md DOX pass ships as an owner-apply patch: `~/daedalus-builds/museion/brief-28-agents-owner-apply.patch` — `git - apply --check` clean against `8b0d43a` (3 files, 25 changed lines: the + apply --check` clean at the r1 head (3 files, 5 hunks: the PostsModel/Watcher/Writes/Editor-core/Settings/WorkspaceView bullets, the - `AppGateState.museionHome` bullet, the MuseionTests suite map row, and the - root 10-most-recent window row). Apply from the branch head with + `AppGateState.museionHome` bullet, the MuseionTests suite map row with the + r1 pins and the `scanLibrary` seam, and the root 10-most-recent window + row). Apply from the branch head with `git apply ~/daedalus-builds/museion/brief-28-agents-owner-apply.patch`. - [ ] GitNexus `impact`/`detect_changes` were NOT run: `.gitnexus/run.cjs` is absent at base and no GitNexus capability is exposed (the argus cycle-5 @@ -171,8 +186,28 @@ path (`repoint(to:)` then `bind`). - **Base / pin:** `ca265d3bd359e663216aa91d4778e2bdef8a36eb` = live `main` tip at claim (`tea api repos/AlexKucera/museion/branches/main`, 20:05 CET) and - still at handoff (`git ls-remote`, 20:26 CET; re-checked again before the - final report). Zero drift. + still at r1 handoff (`git ls-remote`, 22:36 CET). Zero drift. Round 1 + (athena) reviewed `97712fb`; this round appends `92344e2` (code) and the + docs commit on top — 4 linear commits kept, no force-push. +- **r1 (athena MF-1/N-1), full rail at `92344e2`** (tree pristine vs the + commit, watcher blob sha256 prefix `d86ce09d6b7e6bd2`): run dir + `_build/full-test/20261123T213424Z-Museion` → `717 executed / 717 passed / + 0 failed / 0 skipped (xcodebuild exit 0)`, `summary.json` `Passed / 717`, + `** TEST SUCCEEDED **`; 717 = 715 + the two r1 pins; `PostsModelRepointTests` + 9/9 (both r1 pins named passed), `PostsModelDepartureTests` 10/10, + `PostsModelWriteRailTests` 5/5. Filtered GREEN (repoint + departure) → + run dir `…T213313Z` `19 / 19`. +- **r1 mutation check (MF-1):** hoisted `guard watchedHome == home` removed + → run dir `…T213345Z` `9 executed / 8 passed / 1 failed (exit 65)`, ONLY + `a library scan from the old Home lands nothing under the new binding`, + `posts.map(\.id) → ["alpha"]` and `contentRevision → 3` vs `revision → 2`; + restored byte-exact (prefix `d86ce09d6b7e6bd2` before and after), zero + `MUTATION-CHECK` tokens repo-wide. Lint at `92344e2`: `swiftformat --lint .` + 0/152, `swiftlint` 0. +- **r1 owner-apply patch regenerated** for the seam + the two pins (N-3): + 69 lines / 5 hunks — the reviewed patch's shape — `git apply --check` CLEAN + at the new head (re-checked after the docs commit). +- **Round 0 (first report) follows.** - **RED first** at the pin (commit `bce6abb`), rail-filtered `./scripts/full-test.sh start -- -only-testing:MuseionTests/PostsModelRepointTests`: `6 executed / 0 passed / 6 failed / 0 skipped (xcodebuild exit 65)`, zero @@ -199,16 +234,16 @@ path (`repoint(to:)` then `bind`). - **Lint:** `swiftformat --lint .` → `0/152 files require formatting`; `swiftlint lint --quiet` → zero violations (both at `8b0d43a`; the pre-push hook's scoped gate passed on both pushes). -- **Evidence types:** failing-test proof (RED → GREEN on the rail) for the - gate, the ordering, the same-slug save sinks, the no-collision cleanup, the - pass-after-repoint; mutation-check proof for the completion re-check; - structural proof for the view wiring (`homeRepointBinding` → - `repointMuseionHome` → `posts.repoint` precedes `museionHome = newHome`) — - the preference leg is NOT unit-pinned: `AppGateState`'s `didSet` writes the - REAL `UserDefaults.standard` (MuseionTests/AGENTS.md: never touch the - machine), so driving a repoint through `AppGateState` in a hosted test - would point the owner's next launch at a temp dir. Unverified by design; - disclosed. +- **Evidence types:** see "Identity checks — evidence classes" above — + pinned (card hop-back, rescan hoist, #179 guard) vs by-construction + (Micropub stamp) vs invariant-equivalent defensive depth (the synchronous + sweep and `openPostID`'s gate). The preference leg is NOT unit-pinned: + `AppGateState`'s `didSet` writes the REAL `UserDefaults.standard` + (MuseionTests/AGENTS.md: never touch the machine), so driving a repoint + through `AppGateState` in a hosted test would point the owner's next launch + at a temp dir. The view wiring is structural proof only + (`homeRepointBinding` → `repointMuseionHome` → `posts.repoint` precedes + `museionHome = newHome`). Unverified by design; disclosed. - **Not run:** the MuseionUITests smoke (outside the rail by design); no GUI reproduction of the Settings flow (same posture as the scan — static trace + model-level pins). diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index f424ff0..bd4ce5e 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,7 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| -| 2026-11-23 | fix | [20261123-home-repoint-retains-old-editor-target_log.md](20261123-home-repoint-retains-old-editor-target_log.md) | Unticketed fix (brief-28, argus cycle-5): a Home repoint is a guarded document departure — the gate runs before the preference/binding commit, the refusal keeps Home A and the buffers; document identity is (Home, ID) across the model and re-checked at async completion (card scan, rescan); RED-first 6/6 at ca265d3b, stale-scan pin mutation-checked; rail 715/715 | +| 2026-11-23 | fix | [20261123-home-repoint-retains-old-editor-target_log.md](20261123-home-repoint-retains-old-editor-target_log.md) | Unticketed fix (brief-28, argus cycle-5): a Home repoint is a guarded document departure — the gate runs before the preference/binding commit, the refusal keeps Home A and the buffers; document identity is (Home, ID) across the model and re-checked at async completion (card scan, rescan — both mutation-checked); RED-first 6/6 at ca265d3b, review r1 +2 pins (rescan hoist, draft survives); rail 717/717 | | 2026-11-19 | fix | [20261119-issue200-gate-quit-time-flushes-through-departure-gate_log.md](20261119-issue200-gate-quit-time-flushes-through-departure-gate_log.md) | Quit routes through the departure gate (#200): conflict-held shutdown, BLOCK-QUIT at applicationShouldTerminate, never-loaded-retype guard; finish-audit fixes; rail 708/708 | | 2026-11-17 | fix | [20261117-acp-backpressure-defeats-timeout-and-shutdown_log.md](20261117-acp-backpressure-defeats-timeout-and-shutdown_log.md) | Unticketed fix (brief-27, argus cycle-4): stdin writes move to a dedicated writer queue — engine backpressure can no longer defeat the request deadline, Stop, or a bounded reaping close; neverRead/serverPing fake modes, 3 RED-first smokes + healthy-contract pin, suite 697/697 | | 2026-11-17 | issue | [20261117-issue193-split-fat-files-along-postsmodel-pattern_log.md](20261117-issue193-split-fat-files-along-postsmodel-pattern_log.md) | Three most-re-read files split into 8 domain-extension files, move-only (three audits concur); 693/693 | -- 2.36.6