fix(editor): quit rides the departure gate
shutdown() flushed both sessions best-effort and ignored the results — quitting with an unanswered #67 conflict wrote local text over the foreign disk body (flush() holds for conflicts only in the debounce), 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 runs both sessions through sessionMayDepart, and the failed-flush-at-quit posture is BLOCK QUIT — applicationShouldTerminate (quitReply(posts:), before the Cold Turkey ask) refuses termination with one spoken reason via a hosted-guarded alert. PostsModel.active (weak, registered by AppGateState.init — the WritingLockState.active precedent) is the delegate's reachability. Finish-audit fixes folded in: sessionMayDepart refuses a never-loaded session's retyped words (its flush is a vacuous success — the same gap closed for navigation); shutdown stays void (no production reader of a Bool). +5 pins (conflict hold, clean flush, guest flush, never-loaded refusal, delegate refusal incl. chmod-injected flush failure), all flip-verified. Rail 708/708; format+lint clean. Closes #200
This commit is contained in:
1 parent
55be3d1a2f
commit
2334afc392
6 files changed
+198
-2
No files matched your search
@@ -253,6 +253,44 @@ struct WritingLockTests {
|
||||
#expect(delegate.applicationShouldTerminate(NSApplication.shared) == .terminateNow)
|
||||
}
|
||||
|
||||
// MARK: - #200: the quit-time departure gate
|
||||
|
||||
@Test @MainActor
|
||||
func `quit refuses while an open piece cannot depart and proceeds once it can`() throws {
|
||||
// The failed-flush-at-quit posture, pinned: block quit (this
|
||||
// delegate's own refusal precedent) — never silently drop the
|
||||
// only copy of the edits. quitReply is the pure decision seam;
|
||||
// the refusal ALERT itself is hosted-guarded like the kiosk.
|
||||
let delegate = WritingLockAppDelegate()
|
||||
|
||||
// No model alive → nothing open, nothing to lose.
|
||||
#expect(delegate.quitReply(posts: nil) == .terminateNow)
|
||||
|
||||
// A dirty-but-clean-writable session departs: quit proceeds and
|
||||
// the flush lands.
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# A\n", home: home)
|
||||
model.select(post.id)
|
||||
model.session?.edit("# A\n\nlast words before quitting")
|
||||
#expect(delegate.quitReply(posts: model) == .terminateNow)
|
||||
#expect(PostStore.readBody(id: post.id, home: home) == "# A\n\nlast words before quitting")
|
||||
|
||||
// An unanswered #67 conflict refuses termination — the foreign
|
||||
// disk body must survive the quit attempt.
|
||||
try PostStore.overwrite(id: post.id, body: "foreign body from disk", home: home)
|
||||
model.session?.diskDidChange(diskText: "foreign body from disk")
|
||||
#expect(delegate.quitReply(posts: model) == .terminateCancel)
|
||||
#expect(PostStore.readBody(id: post.id, home: home) == "foreign body from disk")
|
||||
|
||||
// A failed flush refuses termination too — the pinned posture.
|
||||
model.session?.keepLocal() // #67 No: the writer keeps their words
|
||||
let pieceDir = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FileManager.default.setAttributes([.posixPermissions: 0o555], ofItemAtPath: pieceDir.path)
|
||||
defer { try? FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: pieceDir.path) }
|
||||
#expect(delegate.quitReply(posts: model) == .terminateCancel)
|
||||
#expect(model.lastError != nil)
|
||||
}
|
||||
|
||||
/// Bounded poll for the watched scan to surface a piece (the
|
||||
/// PostsModelTests poll pattern — the FSEvents latency window).
|
||||
@MainActor
|
||||
|
||||
Reference in new issue
Block a user