Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Sources/Shared/Next/NextSelfTest.swift3// Description: End-to-end self-test steps of the SP Mail Next features against the dev backend: labels, pin ordering, snooze and wake, reminders,4// operator search across two mailboxes and saved searches, bulk action in the unified inbox, contacts (create, suggest, merge), attachment5// gallery and ZIP, dashboard and navigation, AI disabled state, summary and reply suggestion through the scripted local provider6// (Scripts/dev-ai-stub.mjs — no model call), vacation responder round trip.7#if DEBUG8import SPMailCore9import SwiftUI1011extension SelfTest {12 static func featureSteps(_ model: AppModel, a: MeResponse.Box, b: MeResponse.Box, run: String, report: (String, Bool, String) -> Void) async {13 func step(_ name: String, _ ok: Bool, _ detail: String = "") { report(name, ok, detail) }14 let next = model.next, scene = model.main, api = next.api15 let token = "nx\(run)"1617 await next.refresh(force: true)18 step("next: capabilities announced, services started", next.isAvailable && next.has(.labels) && next.has(.snooze) && next.has(.searchAll) && next.has(.contacts) && next.has(.dashboard) && next.store != nil && model.hooks.snooze != nil,19 "features \(next.capabilities.features.sorted())")20 guard next.isAvailable else { return }2122 // fixtures: two messages A → B (the first with an attachment), one B → A23 func send(from: MeResponse.Box, to: MeResponse.Box, subject: String, attachment: String? = nil) async -> Bool {24 await model.switchAccount(from.id)25 await model.compose(.new)26 guard let composer = model.composeRequest.flatMap({ model.composers[$0] }) else { return false }27 composer.to = [EmailAddress(name: "Essai", email: to.address)]28 composer.subject = subject29 composer.body = AttributedString("Bonjour, pouvons-nous nous rencontrer vendredi ? \(token)")30 if let attachment { composer.addAttachment(name: attachment, type: "text/plain", data: Data("pièce \(token)".utf8)) }31 composer.edited()32 let state = await composer.send()33 model.composerClosed(composer.id); model.composeRequest = nil34 return state == .accepted35 }36 let sentAlpha = await send(from: a, to: b, subject: "Alpha \(token)", attachment: "note-\(token).txt")37 try? await Task.sleep(for: .seconds(2)) // alpha is older than beta38 let sentBeta = await send(from: a, to: b, subject: "Beta \(token)")39 let sentGamma = await send(from: b, to: a, subject: "Gamma \(token)")40 await model.switchAccount(b.id)41 scene.selection = scene.mailbox(.inbox).map { .mailbox($0.id) }42 let arrived = await wait(45) {43 await scene.reloadThreads()44 return scene.list.threads.contains { $0.email.subject == "Alpha \(token)" } && scene.list.threads.contains { $0.email.subject == "Beta \(token)" }45 }46 step("next: fixtures sent and received", sentAlpha && sentBeta && sentGamma && arrived, "sent \(sentAlpha) \(sentBeta) \(sentGamma) arrived \(arrived)")47 guard let alpha = scene.list.threads.first(where: { $0.email.subject == "Alpha \(token)" }), let beta = scene.list.threads.first(where: { $0.email.subject == "Beta \(token)" }) else { return }48 func stored(_ account: String, _ id: String) async -> EmailSummary? { (try? await model.store?.email(account, id: id)) ?? nil }4950 // labels: create, apply (plain JMAP keyword through the engine), filter = `label:` search, delete51 let label = await next.createLabel(name: "AT \(run)", color: LabelPalette.hex(3))52 step("labels: create", label != nil && label?.keyword.hasPrefix("lbl_") == true && next.labels.contains { $0.id == label?.id }, "keyword \(label?.keyword ?? "-")")53 if let label {54 await scene.perform(.keyword(label.keyword, true), on: [alpha.id])55 let applied = await stored(b.id, alpha.id)?.keywords.contains(label.keyword) == true56 let data = ConversationRowData(row: ThreadSummary(email: await stored(b.id, alpha.id) ?? alpha.email, count: 1, unreadCount: 0, anyFlagged: false), showRecipients: false).decorated(by: next, account: b.id)57 step("labels: apply to a conversation (row shows its dot)", applied && data.labels == [3], "applied \(applied) dots \(data.labels)")58 scene.selection = .label(label.id)59 scene.didSelectSidebar()60 let filtered = await wait(30) {61 if !scene.next.search.rows.contains(where: { $0.email.id == alpha.id }) { await scene.runRemoteSearch() }62 return scene.next.search.rows.contains { $0.email.id == alpha.id && $0.account == b.id }63 }64 step("labels: filter by label is a `label:` search", filtered && scene.next.search.chips.first?.op == .label && !scene.next.search.rows.contains { $0.email.id == beta.id }, "rows \(scene.next.search.rows.count) chips \(scene.next.search.chips.map(\.token))")65 try? "next-label".write(to: progressURL, atomically: true, encoding: .utf8)66 try? await Task.sleep(for: .seconds(3))67 await scene.perform(.keyword(label.keyword, false), on: [alpha.id])68 await next.deleteLabel(label)69 let remoteLabels = (try? await api.labels()) ?? []70 step("labels: delete", !next.labels.contains { $0.id == label.id } && !remoteLabels.contains { $0.id == label.id })71 }72 scene.selection = scene.mailbox(.inbox).map { .mailbox($0.id) }73 scene.didSelectSidebar()7475 // pin: the older conversation goes first in its folder, and back when unpinned76 _ = await wait(10) { await scene.reloadThreads(); return scene.list.threads.contains { $0.id == alpha.id } }77 let before = scene.list.threads.map(\.id)78 await scene.perform(.pin(true), on: [alpha.id])79 await scene.reloadThreads()80 // (other pinned conversations may already sit at the top: alpha must be among the pinned head of the list, above beta)81 let now = scene.list.threads, ai = now.firstIndex { $0.id == alpha.id } ?? Int.max, bi = now.firstIndex { $0.id == beta.id } ?? -182 let pinnedFirst = ai < bi && now.prefix(ai + 1).allSatisfy(\.isPinned)83 await scene.perform(.pin(false), on: [alpha.id])84 await scene.reloadThreads()85 step("pin: pinned conversation first in the folder list, order restored after unpin", pinnedFirst && (before.firstIndex(of: alpha.id) ?? 0) > (before.firstIndex(of: beta.id) ?? 0) && scene.list.threads.map(\.id) == before,86 "pinned first \(pinnedFirst) before \(before.prefix(3))")87 // the same with a loaded window that does NOT reach the pinned conversation: the server's `hasKeyword` answer brings it to the top88 await scene.perform(.pin(true), on: [alpha.id])89 try? await model.engines[b.id]?.syncNowAndWait()90 scene.list.limit = 191 await scene.reloadThreads()92 await scene.refreshPinned(force: true)93 let buried = scene.list.threads.map(\.id)94 let serverPinned = ((try? await model.engines[b.id]?.emails(inMailbox: scene.mailbox(.inbox)?.id ?? "", withKeyword: NextKeyword.pinned))?.results ?? []).map(\.id)95 await scene.perform(.pin(false), on: [alpha.id])96 scene.list.limit = 20097 await scene.reloadThreads()98 step("pin: a pinned conversation below the loaded window is listed first (server query merged), gone when unpinned",99 serverPinned.contains(alpha.id) && buried.contains(alpha.id) && buried.count >= 2 && (buried.firstIndex(of: alpha.id) ?? 9) < buried.count - 1 && scene.list.threads.map(\.id) == before,100 "window+pins \(buried.count) server \(serverPinned.count) alpha at \(buried.firstIndex(of: alpha.id) ?? -1)")101102 // snooze and wake: server-side, the message leaves the inbox and comes back103 await scene.snooze(ids: [beta.id])104 let asked = scene.next.snoozeRequest105 scene.next.snoozeRequest = nil106 let snoozed = await next.snooze(account: b.id, emailIds: [beta.id], until: Date().addingTimeInterval(3600))107 scene.didSnooze(account: b.id, ids: [beta.id])108 let inbox = scene.mailbox(.inbox)?.id ?? ""109 let left = await wait(20) { try? await model.engines[b.id]?.syncNow(); let e = await stored(b.id, beta.id); return e == nil || e?.mailboxIds.contains(inbox) == false }110 let entry = next.snoozes.first { $0.emailId == beta.id || $0.subject == "Beta \(token)" }111 step("snooze: the hook opens the picker; the message leaves the inbox and is listed in « En veille »", asked?.mode == .snooze && asked?.emailIds == [beta.id] && snoozed && left && entry != nil && !scene.customMailboxes.contains { $0.isSnoozedFolder },112 "asked \(asked != nil) snoozed \(snoozed) left \(left) listed \(entry != nil)")113 if let entry {114 let woke = await next.wake(entry)115 let back = await wait(25) {116 try? await model.engines[b.id]?.syncNow(); await scene.reloadThreads()117 return scene.list.threads.contains { $0.email.subject == "Beta \(token)" }118 }119 step("snooze: wake now brings it back to the inbox", woke && back && !next.snoozes.contains { $0.id == entry.id }, "woke \(woke) back \(back)")120 }121 let betaNow = scene.list.threads.first { $0.email.subject == "Beta \(token)" } ?? beta122123 // reminder124 let reminder = await next.remind(account: b.id, emailId: alpha.id, dueAt: Date().addingTimeInterval(86_400), onlyIfNoReply: true, note: "Relancer \(run)")125 step("reminder: created with « only if no reply » and a note, listed as pending", reminder?.onlyIfNoReply == true && reminder?.note == "Relancer \(run)" && next.reminders.contains { $0.id == reminder?.id && $0.status == .pending },126 "status \(reminder?.status.rawValue ?? "-") listed \(next.reminders.count)")127 if let reminder { await next.cancelReminder(reminder) }128129 // operator search across the two mailboxes, inline parse error, saved search130 scene.openSearch()131 scene.next.search.allMailboxes = true132 scene.next.search.draft = "subject:\(token) "133 let found = await wait(40) {134 await scene.runRemoteSearch()135 return Set(scene.next.search.rows.compactMap(\.account)) == [a.id, b.id]136 }137 let subjects = Set(scene.next.search.rows.map(\.email.subject))138 step("search: operator query across two mailboxes (chips from the server's parse)", found && scene.next.search.chips.map(\.op) == [.subject] && scene.next.search.draft.isEmpty && subjects.isSuperset(of: ["Alpha \(token)", "Gamma \(token)"]) && !scene.next.search.isOffline,139 "rows \(scene.next.search.rows.count) accounts \(Set(scene.next.search.rows.compactMap(\.account)).count) chips \(scene.next.search.chips.map(\.token))")140 try? "next-search".write(to: progressURL, atomically: true, encoding: .utf8)141 try? await Task.sleep(for: .seconds(3))142 scene.next.search.allMailboxes = false143 await scene.runRemoteSearch()144 step("search: scope « this mailbox »", !scene.next.search.rows.isEmpty && Set(scene.next.search.rows.compactMap(\.account)) == [b.id], "accounts \(Set(scene.next.search.rows.compactMap(\.account)))")145 scene.next.search.chips = []; scene.next.search.draft = "before:pas-une-date "146 await scene.runRemoteSearch()147 step("search: a parse error is shown inline, nothing is run", !scene.next.search.errors.isEmpty && scene.next.search.rows.isEmpty, "errors \(scene.next.search.errors.map(\.message))")148 let saved = await next.saveSearch(name: "AT \(run)", query: "subject:\(token) has:attachment", scope: .all)149 step("saved search: created, listed in the sidebar", saved != nil && next.savedSearches.contains { $0.id == saved?.id }, "saved \(saved?.id ?? "-")")150 if let saved {151 scene.selection = .savedSearch(saved.id)152 scene.didSelectSidebar()153 let opened = await wait(30) {154 if scene.next.search.rows.isEmpty { await scene.runRemoteSearch(scope: saved.scope) }155 return scene.next.search.rows.contains { $0.email.subject == "Alpha \(token)" }156 }157 step("saved search: opens as a list", opened && scene.next.search.title == "AT \(run)" && scene.next.search.rows.allSatisfy { $0.email.hasAttachment }, "rows \(scene.next.search.rows.map(\.email.subject))")158 await next.deleteSavedSearch(saved)159 _ = await next.store?.flush(force: true)160 let remoteSearches = (try? await api.savedSearches()) ?? []161 step("saved search: delete", !next.savedSearches.contains { $0.id == saved.id } && !remoteSearches.contains { $0.id == saved.id })162 }163164 // unified inbox: multi-selection and one bulk action reaching both mailboxes165 scene.selection = .unified(.inbox)166 scene.didSelectSidebar()167 let listed = await wait(40) {168 await scene.reloadUnified()169 return scene.unified.rows.contains { $0.email.subject == "Alpha \(token)" } && scene.unified.rows.contains { $0.email.subject == "Gamma \(token)" }170 }171 let picked = scene.unified.rows.filter { $0.email.subject == "Alpha \(token)" || $0.email.subject == "Gamma \(token)" }172 scene.next.selection = Set(picked.map(\.id))173 let rows = scene.selectedRemoteRows174 await scene.performSelection(.flag(true), rows: rows)175 var flagged = 0176 for row in picked { if let account = row.account, await stored(account, row.email.id)?.isFlagged == true { flagged += 1 } }177 step("unified inbox: bulk action on a multi-selection across mailboxes", listed && rows.count == 2 && Set(rows.compactMap(\.account)) == [a.id, b.id] && flagged == 2 && scene.unified.rows.filter { scene.next.selection.contains($0.id) }.allSatisfy(\.email.isFlagged),178 "listed \(listed) selected \(rows.count) flagged \(flagged)")179 try? "next-unified-bulk".write(to: progressURL, atomically: true, encoding: .utf8)180 try? await Task.sleep(for: .seconds(3))181 await scene.performSelection(.flag(false), rows: rows)182 scene.next.selection = []183184 // contacts: create, suggestion from the correspondents, merge duplicates185 scene.selection = .contacts186 scene.didSelectSidebar()187 let first = await scene.saveContact(nil, ContactContent(kind: .saved, name: "Autotest \(run)", emails: [ContactEmail(email: "autotest-\(run)@example.org")], organization: "SP Mail"))188 let second = await scene.saveContact(nil, ContactContent(kind: .saved, name: "Autotest \(run)", emails: [ContactEmail(email: "autotest2-\(run)@example.org")]))189 await scene.reloadContacts()190 step("contacts: create (listed as saved)", first != nil && second != nil && scene.next.contacts.contacts.contains { $0.id == first?.id && $0.isSaved }, "listed \(scene.next.contacts.contacts.count)")191 let suggested = await wait(20) { ((try? await api.suggestContacts("autotest-\(run)", limit: 8)) ?? []).contains { $0.email == "autotest-\(run)@example.org" } }192 // (both test mailboxes belong to the same user, and the server never harvests the user's own addresses: no harvested correspondent can exist here)193 _ = try? await next.store?.refresh([.suggestions])194 let cachedSuggestion = await next.store?.suggest("autotest-\(run)", limit: 8).contains { $0.email == "autotest-\(run)@example.org" } ?? false195 step("contacts: suggestions (server ranking, and the cached copy for offline)", suggested && cachedSuggestion, "server \(suggested) cached \(cachedSuggestion)")196 await scene.loadDuplicates()197 let group = scene.next.contacts.duplicates.first { g in g.contacts.contains { $0.id == first?.id } && g.contacts.contains { $0.id == second?.id } }198 if let group, let first, let keep = group.contacts.first(where: { $0.id == first.id }) {199 let merged = await scene.mergeContacts(keep: keep, merge: group.contacts.filter { $0.id != keep.id })200 step("contacts: merge duplicates", merged?.emails.count == 2 && merged?.id == first.id && !scene.next.contacts.duplicates.contains { $0.id == group.id }, "emails \(merged?.emails.map(\.email) ?? [])")201 if let merged {202 await scene.selectContact(merged)203 try? "next-contacts".write(to: progressURL, atomically: true, encoding: .utf8)204 try? await Task.sleep(for: .seconds(3))205 await scene.deleteContact(merged)206 }207 } else {208 step("contacts: merge duplicates", false, "duplicates \(scene.next.contacts.duplicates.count)")209 if let first { await scene.deleteContact(first) }210 if let second { await scene.deleteContact(second) }211 }212213 // attachment gallery: listing with a file-name search, ZIP in the engine-managed temporary folder214 scene.selection = .attachments215 scene.didSelectSidebar()216 scene.next.gallery.query = "note-\(token)"217 let galleryOK = await wait(40) { await scene.reloadGallery(); return scene.next.gallery.items.contains { $0.name == "note-\(token).txt" } }218 step("attachments: gallery lists the file (search by name)", galleryOK, "items \(scene.next.gallery.items.map(\.name)) error \(scene.next.gallery.error ?? "-")")219 try? "next-attachments".write(to: progressURL, atomically: true, encoding: .utf8)220 try? await Task.sleep(for: .seconds(3))221 if let item = scene.next.gallery.items.first(where: { $0.name == "note-\(token).txt" && $0.mailboxId == b.id }) ?? scene.next.gallery.items.first {222 let file = try? await scene.galleryFile(item)223 let zip = try? await scene.galleryZip([item])224 let head = zip.flatMap { try? Data(contentsOf: $0).prefix(2) }225 let temp = model.store?.temporaryFilesDirectory.path ?? "-"226 step("attachments: file from the sealed cache and ZIP, both in the engine's temporary folder",227 file.flatMap { try? String(contentsOf: $0, encoding: .utf8) } == "pièce \(token)" && head == Data("PK".utf8) && zip?.path.hasPrefix(temp) == true && file?.path.hasPrefix(temp) == true,228 "file \(file?.lastPathComponent ?? "-") zip \(zip?.lastPathComponent ?? "-")")229 } else { step("attachments: file from the sealed cache and ZIP, both in the engine's temporary folder", false, "no item") }230 scene.next.gallery.query = ""231232 // dashboard: load, navigation, layout stored under `dashboard` only233 scene.selection = .dashboard234 scene.didSelectSidebar()235 let note = await next.loadDashboard(fresh: true)236 step("dashboard: loads", note == nil && next.dashboard != nil && Set(next.dashboard?.inbox.map(\.mailboxId) ?? []).isSuperset(of: [a.id, b.id]) && next.dashboard?.sync.isHealthy == true, "note \(note ?? "-") inbox \(next.dashboard?.inbox.count ?? 0)")237 try? "next-dashboard".write(to: progressURL, atomically: true, encoding: .utf8)238 try? await Task.sleep(for: .seconds(3))239 await scene.navigate(.followUps)240 let toFollowUps = scene.selection == .followUps241 await scene.navigate(.inbox(a.id))242 let toInbox = scene.currentAccount == a.id && scene.selection == scene.mailbox(.inbox).map { .mailbox($0.id) }243 scene.next.messageRequest = nil244 await scene.navigate(.message(account: b.id, emailId: alpha.id))245 let toMessage = scene.next.messageRequest?.emailId == alpha.id246 scene.next.messageRequest = nil247 step("dashboard: items navigate (follow-ups, a mailbox's inbox, a message)", toFollowUps && toInbox && toMessage, "\(toFollowUps) \(toInbox) \(toMessage)")248 _ = try? await model.api.patchPrefs(["dashboard": ["order": ["storage", "futureWidget", "inbox"], "hidden": ["sync"], "columns": 3], "selftestKeep": "x"])249 var layout = DashboardLayout(json: (try? await model.api.me())?.user.prefs?["dashboard"] ?? .null)250 let read = layout.order.prefix(2) == [.storage, .inbox] && layout.hidden == [.sync] && layout.order.count == DashboardWidget.allCases.count251 layout.hidden.insert(.contacts)252 next.dashboardLayout = layout253 await next.saveDashboardLayout()254 let prefs = (try? await model.api.me())?.user.prefs255 step("dashboard: layout saved under `dashboard`, unknown keys and other preferences intact",256 read && prefs?["selftestKeep"] == "x" && prefs?["dashboard"]["columns"] == 3 && prefs?["dashboard"]["order"].stringArray.contains("futureWidget") == true && Set(prefs?["dashboard"]["hidden"].stringArray ?? []) == ["contacts", "sync"],257 "read \(read) dashboard \(String(describing: prefs?["dashboard"]))")258 _ = try? await model.api.patchPrefs(["dashboard": nil, "selftestKeep": nil])259 next.dashboardLayout = DashboardLayout()260 await model.switchAccount(b.id)261262 // intelligence: off by default → every surface hidden and the server refuses; then the scripted local provider263 try? await next.setAI(AISettingsUpdate(provider: .off))264 var refusal: Error?265 do { _ = try await api.summarize(mailboxId: b.id, threadId: alpha.threadId) } catch { refusal = error }266 step("intelligence: disabled state (surfaces hidden, server answers ai_disabled)", !next.aiEnabled(.summary) && !next.aiEnabled(.reply) && !next.aiEnabled(.triage) && (refusal as? NextError) == .aiDisabled && next.describe(NextError.aiDisabled) != nil,267 "refusal \(String(describing: refusal))")268 var consent: Error?269 do { try await next.setAI(AISettingsUpdate(provider: .anthropic)) } catch { consent = error }270 step("intelligence: the external provider is refused without the explicit consent", next.ai.provider != .anthropic && ((consent as? NextError) == .consentRequired || (consent as? APIError)?.code == "provider_unavailable"), "error \(String(describing: consent))")271 if next.ai.localAvailable {272 try? await next.setAI(AISettingsUpdate(provider: .local, features: ["summary": true, "reply": true, "triage": true]))273 scene.selection = scene.mailbox(.inbox).map { .mailbox($0.id) }274 scene.didSelectSidebar()275 _ = await wait(10) { await scene.reloadThreads(); return scene.list.threads.contains { $0.id == alpha.id } }276 scene.list.selectedIds = [alpha.id]277 await scene.open(emailId: alpha.id)278 await scene.summarize()279 let summary = scene.next.ai.summary280 step("intelligence: summary from the scripted local provider, labelled with its provider", next.aiEnabled(.summary) && summary?.provider == "local" && summary?.summary.isEmpty == false && summary?.actionItems.count == 2281 && next.providerLabel(provider: summary?.provider ?? "", model: summary?.model ?? "").contains("MacLustr"), "error \(scene.next.ai.summaryError ?? "-") model \(summary?.model ?? "-")")282 scene.next.ai.tone = .concise; scene.next.ai.language = "fr"283 await scene.suggestReplies()284 let suggestions = scene.next.ai.replies?.suggestions ?? []285 try? "next-ai".write(to: progressURL, atomically: true, encoding: .utf8)286 try? await Task.sleep(for: .seconds(4))287 let outboxBefore = ((try? await model.store?.outbox()) ?? []).filter { $0.state != .draft }.count288 var opened = false, inserted = false, unsent = false289 if let suggestion = suggestions.first, let target = scene.replyTarget(), let id = await scene.composeReply(to: target, inserting: suggestion.text), let composer = model.composers[id] {290 opened = scene.composeRequest == id || model.composers[id] != nil291 let m = composer.currentMessage()292 inserted = composer.plainText.hasPrefix(suggestion.text) && m.to.first?.email == a.address && !m.inReplyTo.isEmpty293 try? await Task.sleep(for: .seconds(2))294 let outboxAfter = ((try? await model.store?.outbox()) ?? []).filter { $0.state != .draft }.count295 unsent = composer.status != .sending && composer.status != .accepted && outboxAfter == outboxBefore296 await composer.discard(); model.composerClosed(id); scene.composeRequest = nil297 }298 step("intelligence: a reply suggestion opens the composer with the text — nothing is sent", suggestions.count == 3 && scene.next.ai.replies?.provider == "local" && opened && inserted && unsent,299 "suggestions \(suggestions.count) opened \(opened) inserted \(inserted) unsent \(unsent) error \(scene.next.ai.repliesError ?? "-")")300 await next.loadTriage(account: b.id, emailIds: [alpha.id])301 step("intelligence: triage badge only while the feature is on", next.triage(account: b.id, emailId: alpha.id) != nil, "category \(next.triage(account: b.id, emailId: alpha.id)?.category.rawValue ?? "-")")302 try? await next.setAI(AISettingsUpdate(provider: .off))303 step("intelligence: back to off hides everything again", !next.aiEnabled(.summary) && next.triage(account: b.id, emailId: alpha.id) == nil)304 } else {305 step("intelligence: summary from the scripted local provider, labelled with its provider", false, "the dev backend has no local provider (start it with Scripts/dev-backend.sh)")306 }307308 // vacation responder: written into the « spmail » Sieve script (as the web client does), read back, switched off again309 if let engine = model.engines[b.id] {310 let service = SieveService(jmap: engine.jmap)311 do {312 let initial = try await service.load()313 var config = initial.config314 config.vacation = VacationConfig(enabled: true, subject: "Absent \(run)", text: "De retour lundi.\n\(token)", from: "2026-12-20", to: "2027-01-05", days: 2)315 let trash = model.mailboxes(for: b.id).first { $0.knownRole == .trash }?.name ?? "Deleted Items"316 let stored = try await service.save(config, previous: initial, trashFolder: trash)317 let back = try await service.load()318 config.vacation.enabled = false319 let off = try await service.save(config, previous: back, trashFolder: trash)320 let final = try await service.load()321 step("vacation responder: round trip through the Sieve script (active, re-read, switched off)",322 stored.active && back.active && !back.custom && back.config.vacation == VacationConfig(enabled: true, subject: "Absent \(run)", text: "De retour lundi.\n\(token)", from: "2026-12-20", to: "2027-01-05", days: 2)323 && back.raw.contains("vacation :days 2") && off.scriptId == back.scriptId && !final.config.vacation.enabled && !final.raw.contains("vacation :days") && final.config.rules == initial.config.rules,324 "active \(back.active) custom \(back.custom) vacation \(back.config.vacation.enabled)")325 } catch { step("vacation responder: round trip through the Sieve script (active, re-read, switched off)", false, String(describing: error)) }326 let quota = try? await engine.quota()327 step("storage: quota read through JMAP", quota != nil, "\(quota?.count ?? -1) quota objects")328 }329330 // offline: snooze and reminders are refused with an explanation, never queued silently; search falls back to the local caches331 let offlineAPI = NextAPI(APIClient(baseURL: URL(string: "http://127.0.0.1:9")!, token: "x"))332 var offlineError: Error?333 do { _ = try await offlineAPI.snooze(mailboxId: b.id, emailIds: [alpha.id], until: Date().addingTimeInterval(3600)) } catch { offlineError = error }334 let localHits = ((try? await model.store?.search(b.id, text: "Alpha \(token)")) ?? []).count335 step("offline: snooze is refused (not queued) and the local caches can answer a search", offlineError.map(NextError.isOffline) == true && localHits >= 1, "local hits \(localHits)")336337 // tidy: the fixtures of this run leave both mailboxes338 scene.selection = scene.mailbox(.inbox).map { .mailbox($0.id) }339 scene.didSelectSidebar()340 for box in [a, b] {341 guard let engine = model.engines[box.id] else { continue }342 let ids = ((try? await model.store?.search(box.id, text: token)) ?? []).map(\.id)343 if !ids.isEmpty { await engine.destroy(ids: ids) }344 }345 _ = betaNow346 }347}348#endif349