fix(sessions): re-review fixes for MMDB-2925 (PR #29 review round 2)
Round 2 of adversarial review confirmed defects 2,3,4,5,7 fixed and raised three new ones; all three are fixed here, plus the guard-message nit. NEW-1 (the FAIL driver): the OneDrive send path overwrote the truthful status from handleDidShareItems with its own success text, silently dropping an archive failure and any state-refresh problem. The seam now takes the caller's success summary and composes ONE truthful message: summary (the share itself did complete) + archive error if any + refresh problems if any. Both callers (AirDrop delegate, OneDrive) pass their summary; the OneDrive text is never clobbered. NEW-2: if the replacement open session could not be created after the archive rename (disk full), the store kept reporting the already-archived session as the open one. SpoolStore now has a truth guard (ensureOpenSession): the open session is verified to really exist on disk and be in state .open before any read/mutate; a stale one is replaced by a genuinely fresh session, or the call fails loudly. Never a lie. NEW-3: archivedSessions() read the folder tie-break dates AFTER reconciliation, so a healed same-second session could bump its own modification date and outrank a genuinely newer peer. The dates are now read BEFORE reconciling. Nit: the startNewSession guard now reports "A new session is already being started." when the refusal is about a concurrent session start, not a send. Also added REDLINE_SELFTEST_PHASE=sendtruth (mirroring the existing =onedrive escape hatch) so the SEND-TRUTH selftest can run without the picker chain's display-dependent REGION-PERSIST phase. Evidence: 136 swift tests pass (2 new: OneDrive summary survives archiving; stale open session never returned as current). REDLINE_SELFTEST_PHASE=sendtruth -> SEND-TRUTH PASS. REDLINE_SELFTEST_PHASE=onedrive -> ONEDRIVE-SELFTEST PASS against the real OneDrive sync root.
This commit is contained in:
@@ -426,7 +426,7 @@ public final class AppModel {
|
||||
// the menu's `.disabled` state cannot stop a Task that was queued just before
|
||||
// a send started.
|
||||
guard !isSending, !isStartingNewSession else {
|
||||
setStatus("Finish the current send first.")
|
||||
setStatus(isSending ? "Finish the current send first." : "A new session is already being started.")
|
||||
return
|
||||
}
|
||||
isStartingNewSession = true
|
||||
|
||||
@@ -241,7 +241,10 @@ enum PickerSelfTest {
|
||||
sendTruthFail("fail path status missing 'nothing was sent': \(model.statusLine ?? "nil")")
|
||||
}
|
||||
|
||||
await model.handleDidShareItems(fileName: pending.fileName, pageCount: pending.pageCount)
|
||||
let pageWord = pending.pageCount == 1 ? "page" : "pages"
|
||||
await model.handleDidShareItems(
|
||||
fileName: pending.fileName,
|
||||
sentSummary: "Sent — \(pending.pageCount) \(pageWord).")
|
||||
let fresh = try await model.spool.currentSession()
|
||||
guard fresh.isEmpty, fresh.id != openID, fresh.state == .open else {
|
||||
sendTruthFail("success path did not mint a fresh empty session")
|
||||
@@ -592,6 +595,38 @@ enum PickerSelfTest {
|
||||
return true
|
||||
}
|
||||
|
||||
/// Entry point for running ONLY the SEND-TRUTH phase, bypassing the on-screen picker
|
||||
/// chain entirely — the chain's REGION-PERSIST phase needs an active display
|
||||
/// (CGDisplayIsActive) and exits before SEND-TRUTH in headless/remote sessions.
|
||||
/// Escape hatch: `REDLINE_SELFTEST_PHASE=sendtruth`.
|
||||
static func runSendTruthOnlyIfRequested() {
|
||||
guard ProcessInfo.processInfo.environment["REDLINE_SELFTEST_PHASE"] == "sendtruth" else {
|
||||
return
|
||||
}
|
||||
// Same hop as runOneDriveOnlyIfRequested(): a plain main-queue turn after NSApp
|
||||
// starts, so AppKit/PDFKit calls inside the phase are not racing app launch.
|
||||
DispatchQueue.main.async {
|
||||
MainActor.assumeIsolated {
|
||||
runSendTruthAndExit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static func runSendTruthAndExit() {
|
||||
Task { @MainActor in
|
||||
do {
|
||||
try await executeSendTruth()
|
||||
print("SEND-TRUTH PASS")
|
||||
fflush(stdout)
|
||||
exit(0)
|
||||
} catch {
|
||||
print("SEND-TRUTH FAIL \(error)")
|
||||
fflush(stdout)
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Entry point for running ONLY this phase, bypassing the on-screen picker chain
|
||||
/// entirely. The harness has no other per-phase selector, so this is the escape
|
||||
/// hatch: `REDLINE_SELFTEST_PHASE=onedrive`.
|
||||
|
||||
@@ -95,10 +95,10 @@ extension AppModel: SendCapable {
|
||||
case .oneDrive:
|
||||
// No AirDrop, no anchor needed — the PDF is already in the watched
|
||||
// OneDrive folder. Archive immediately; the iPad marks it up in place.
|
||||
await handleDidShareItems(fileName: pending.fileName, pageCount: pending.pageCount)
|
||||
let pageWord = pending.pageCount == 1 ? "page" : "pages"
|
||||
setStatus(
|
||||
"Saved to OneDrive — \(pending.pageCount) \(pageWord). Open it in Files on your iPad."
|
||||
await handleDidShareItems(
|
||||
fileName: pending.fileName,
|
||||
sentSummary: "Saved to OneDrive — \(pending.pageCount) \(pageWord). Open it in Files on your iPad."
|
||||
)
|
||||
setSending(false)
|
||||
|
||||
@@ -113,9 +113,10 @@ extension AppModel: SendCapable {
|
||||
try Sharing.airDrop(fileURL: pending.fileURL, from: anchor) { [weak self] success in
|
||||
guard let self else { return }
|
||||
if success {
|
||||
let pageWord = pending.pageCount == 1 ? "page" : "pages"
|
||||
await self.handleDidShareItems(
|
||||
fileName: pending.fileName,
|
||||
pageCount: pending.pageCount
|
||||
sentSummary: "Sent — \(pending.pageCount) \(pageWord)."
|
||||
)
|
||||
} else {
|
||||
self.handleDidFailToShareItems(fileName: pending.fileName)
|
||||
@@ -194,16 +195,17 @@ extension AppModel: SendCapable {
|
||||
)
|
||||
}
|
||||
|
||||
/// `NSSharingServiceDelegate.sharingService(_:didShareItems:)` seam.
|
||||
func handleDidShareItems(fileName: String, pageCount: Int) async {
|
||||
/// `NSSharingServiceDelegate.sharingService(_:didShareItems:)` seam — also the
|
||||
/// OneDrive completion path. Composes ONE truthful status from the caller's success
|
||||
/// summary (the share itself DID complete) plus, when they happened, the archive
|
||||
/// error and any state-refresh problem — nothing is overwritten or hidden.
|
||||
func handleDidShareItems(fileName: String, sentSummary: String) async {
|
||||
guard !session.isEmpty else { return }
|
||||
var message: String
|
||||
var message = sentSummary
|
||||
do {
|
||||
_ = try await spool.archiveCurrent(pdfFileName: fileName)
|
||||
let pageWord = pageCount == 1 ? "page" : "pages"
|
||||
message = "Sent — \(pageCount) \(pageWord)."
|
||||
} catch {
|
||||
message = (error as? ShotdeckError)?.errorDescription ?? "Could not archive the session."
|
||||
message += " \((error as? ShotdeckError)?.errorDescription ?? "Could not archive the session.")"
|
||||
}
|
||||
// Refresh model state from the store on BOTH paths: after a successful archive
|
||||
// the current session and the past-submissions list are stale until reloaded,
|
||||
|
||||
@@ -10,6 +10,9 @@ if ProcessInfo.processInfo.environment["SHOTDECK_SNAPSHOT_DIR"] != nil {
|
||||
if ProcessInfo.processInfo.environment["REDLINE_SELFTEST_PHASE"] == "onedrive" {
|
||||
MainActor.assumeIsolated { PickerSelfTest.runOneDriveOnlyIfRequested() }
|
||||
}
|
||||
if ProcessInfo.processInfo.environment["REDLINE_SELFTEST_PHASE"] == "sendtruth" {
|
||||
MainActor.assumeIsolated { PickerSelfTest.runSendTruthOnlyIfRequested() }
|
||||
}
|
||||
if ProcessInfo.processInfo.environment["SHOTDECK_PICKER_SELFTEST"] != nil {
|
||||
MainActor.assumeIsolated { PickerSelfTest.runIfRequested() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user