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:
@@ -187,6 +187,35 @@ func theSendArchivePathAppliesRetention() async throws {
|
||||
#expect(kept.allSatisfy { $0.pdfFileName != nil })
|
||||
}
|
||||
|
||||
// MARK: - 7. a stale open session is never returned as current (truth guard)
|
||||
|
||||
@Test
|
||||
func aStaleOpenSessionIsNeverReturnedAsCurrent() async throws {
|
||||
let (root, paths) = try makeIsolatedPaths()
|
||||
defer { try? FileManager.default.removeItem(at: root) }
|
||||
|
||||
let store = try SpoolStore(paths: paths)
|
||||
_ = try await store.append(
|
||||
pngData: try makePNGData(width: 6, height: 6, red: 0.7, green: 0.7, blue: 0.1),
|
||||
pixelWidth: 6, pixelHeight: 6, scale: 1.0, capturedAt: Date())
|
||||
let archived = try await store.archiveCurrent(pdfFileName: "Redline-20261011-120200.pdf")
|
||||
|
||||
// Simulate the mid-run failure the truth guard exists for: the archived session
|
||||
// moved away and the replacement open session's folder is gone (e.g. the fresh
|
||||
// session could not be created / survive). The store must mint a real fresh
|
||||
// session — never report the already-archived one as open.
|
||||
let fresh = try await store.currentSession()
|
||||
try FileManager.default.removeItem(at: paths.sessionDirectory(fresh.id))
|
||||
|
||||
let recovered = try await store.currentSession()
|
||||
#expect(recovered.id != fresh.id)
|
||||
#expect(recovered.id != archived.id)
|
||||
#expect(recovered.state == .open)
|
||||
#expect(recovered.isEmpty)
|
||||
let past = try await store.archivedSessions()
|
||||
#expect(past.map(\.id) == [archived.id])
|
||||
}
|
||||
|
||||
// MARK: - Fixtures
|
||||
|
||||
private enum FixtureError: Error {
|
||||
|
||||
Reference in New Issue
Block a user