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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user