OpenTalon / app · opentalon.ai / native / CompanionCore / Tests / CompanionCoreTests / CompanionCoreTests.swift
| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import CompanionCore |
| 4 | |
| 5 | @Test @MainActor func mcpAvailabilitySyncsBothDirectionsWithoutATaskEdit() async throws { |
| 6 | let folder = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 7 | defer { try? FileManager.default.removeItem(at: folder) } |
| 8 | let transport = LocalCompanionTransport(directory: folder) |
| 9 | try await transport.prepare(account: "test") |
| 10 | let id = UUID() |
| 11 | let legacy = PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], availableAgents: [.codex]) |
| 12 | #expect(!legacy.canUseAgents) |
| 13 | var cached = legacy |
| 14 | for ready in [false, true, false, true] { |
| 15 | let updated = PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], availableAgents: [.codex], agentConnectionReady: ready) |
| 16 | #expect(updated.shouldReplace(cached)) |
| 17 | try await transport.publish(updated) |
| 18 | guard case .updated(let incoming) = try await transport.snapshot(newerThan: cached) else { |
| 19 | Issue.record("MCP state was cached at the same task revision"); return |
| 20 | } |
| 21 | #expect(incoming.canUseAgents == ready) |
| 22 | cached = incoming |
| 23 | } |
| 24 | let encoded = try JSONEncoder().encode(cached) |
| 25 | #expect(try JSONDecoder().decode(PhoneSnapshot.self, from: encoded).canUseAgents) |
| 26 | } |
| 27 | |
| 28 | @Test func doneOrderUsesRecordedCompletionAndStableLegacyFallback() { |
| 29 | func task(_ id: String, created: Double?, completed: Double? = nil) -> PhoneTask { |
| 30 | PhoneTask(id: id, projectID: "project", title: id, notes: "", definitionOfDone: "", status: .done, |
| 31 | priority: .none, dueDate: nil, revision: 1, assigned: false, |
| 32 | createdAt: created.map(Date.init(timeIntervalSinceReferenceDate:)), |
| 33 | completedAt: completed.map(Date.init(timeIntervalSinceReferenceDate:))) |
| 34 | } |
| 35 | let items = [task("legacy-new", created: 100), task("legacy-undated", created: nil), |
| 36 | task("completed-last", created: 1, completed: 90), task("legacy-first", created: 50), |
| 37 | task("completed-first", created: 30, completed: 40)] |
| 38 | #expect(DoneOrder.recent.ordered(items, completionDate: \.completedAt, creationDate: \.createdAt).map(\.id) |
| 39 | == ["completed-last", "completed-first", "legacy-new", "legacy-first", "legacy-undated"]) |
| 40 | #expect(DoneOrder.oldest.ordered(items, completionDate: \.completedAt, creationDate: \.createdAt).map(\.id) |
| 41 | == ["completed-first", "completed-last", "legacy-first", "legacy-new", "legacy-undated"]) |
| 42 | #expect(DoneOrder.manual.ordered(items, completionDate: \.completedAt, creationDate: \.createdAt).map(\.id) |
| 43 | == items.map(\.id)) |
| 44 | } |
| 45 | |
| 46 | @Test @MainActor func cardDatesSyncWithoutChangingTheWorkspaceRevision() async throws { |
| 47 | let folder = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 48 | defer { try? FileManager.default.removeItem(at: folder) } |
| 49 | let transport = LocalCompanionTransport(directory: folder) |
| 50 | try await transport.prepare(account: "test") |
| 51 | |
| 52 | let workspace = UUID() |
| 53 | let created = Date(timeIntervalSinceReferenceDate: 15) |
| 54 | let completed = created.addingTimeInterval(10) |
| 55 | let updated = completed.addingTimeInterval(10) |
| 56 | let trashed = updated.addingTimeInterval(10) |
| 57 | func task(updatedAt: Date?) -> PhoneTask { |
| 58 | PhoneTask(id: "done", projectID: "personal", title: "Completed", notes: "", definitionOfDone: "", |
| 59 | status: .done, priority: .none, dueDate: nil, revision: 4, assigned: false, |
| 60 | createdAt: created, completedAt: completed, updatedAt: updatedAt) |
| 61 | } |
| 62 | let legacy = PhoneSnapshot(workspaceID: workspace, revision: 5, projects: [], tasks: [task(updatedAt: nil)], |
| 63 | trashedTasks: [PhoneTrashedTask(id: "trash", projectID: "personal", title: "Archived", revision: 5)], |
| 64 | agentConnectionReady: false) |
| 65 | try await transport.publish(legacy) |
| 66 | let current = PhoneSnapshot(workspaceID: workspace, revision: 5, projects: [], tasks: [task(updatedAt: updated)], |
| 67 | trashedTasks: [PhoneTrashedTask(id: "trash", projectID: "personal", title: "Archived", revision: 5, |
| 68 | updatedAt: trashed, deletedAt: trashed)], |
| 69 | agentConnectionReady: false, includesTaskUpdateDates: true) |
| 70 | try await transport.publish(current) |
| 71 | guard case .updated(let incoming) = try await transport.snapshot(newerThan: legacy) else { |
| 72 | Issue.record("Item timestamps did not reach a phone holding the same workspace revision.") |
| 73 | return |
| 74 | } |
| 75 | #expect(incoming.tasks.first?.updatedAt == updated) |
| 76 | #expect(incoming.tasks.first?.completedAt == completed) |
| 77 | #expect(incoming.trashedTasks?.first?.deletedAt == trashed) |
| 78 | #expect(incoming.trashedTasks?.first?.updatedAt == trashed) |
| 79 | #expect(!legacy.shouldReplace(current)) |
| 80 | |
| 81 | let decoded = try JSONDecoder().decode(PhoneSnapshot.self, from: JSONEncoder().encode(legacy)) |
| 82 | #expect(decoded.tasks.first?.updatedAt == nil) |
| 83 | #expect(decoded.trashedTasks?.first?.deletedAt == nil) |
| 84 | } |
| 85 | |
| 86 | @Test func markdownCodeFencesKeepNestedMarkersInsideTheCodeBlock() { |
| 87 | let fence = PlanCodeFence("````swift")! |
| 88 | #expect(!fence.closes(with: "```")) |
| 89 | #expect(!fence.closes(with: "~~~~")) |
| 90 | #expect(!fence.closes(with: "````comment")) |
| 91 | #expect(fence.closes(with: " ````` ")) |
| 92 | #expect(PlanCodeFence("~~~swift")!.closes(with: "~~~")) |
| 93 | #expect(PlanCodeFence("`inline`") == nil) |
| 94 | } |
| 95 | |
| 96 | @Test func markdownPlansKeepUnicodeAndSafeFilenamesAndRejectInvalidDocuments() throws { |
| 97 | let markdown = "# Plan\n\n- [ ] Review café notes.\n\n```swift\nprint(\"hello\")\n```\n" |
| 98 | #expect(try TaskPlan.decode(Data(markdown.utf8)) == markdown) |
| 99 | #expect(TaskPlan.filename(reference: "ink-001") == "INK-001-plan.md") |
| 100 | #expect(!TaskPlan.filename(reference: "../../file").contains("/")) |
| 101 | #expect(throws: TaskPlan.PlanError.self) { try TaskPlan.decode(Data([0xff, 0xfe, 0x00])) } |
| 102 | #expect(throws: TaskPlan.PlanError.self) { try TaskPlan.validate("a\0b") } |
| 103 | #expect(throws: TaskPlan.PlanError.self) { try TaskPlan.validate(String(repeating: "x", count: 100_001)) } |
| 104 | #expect(TaskPlan.requested(in: "Create a task with a plan to review the launch")) |
| 105 | #expect(!TaskPlan.requested(in: "Review the planet illustration")) |
| 106 | #expect(TaskReference.normalized(in: "Set ink-1 priority to High") == "INK-001") |
| 107 | #expect(TaskReference.normalized(in: "Open INK–001") == "INK-001") |
| 108 | #expect(TaskReference.normalized(in: "01a1cbb7-abc-1234-8610-89b71dfe8a4a") == nil) |
| 109 | } |
| 110 | |
| 111 | @Test func planRequestsRetainExpectedContentAndUpgradeOlderSnapshots() throws { |
| 112 | let workspace = UUID() |
| 113 | let old = PhoneSnapshot(workspaceID: workspace, revision: 3, projects: [], tasks: []) |
| 114 | let upgraded = PhoneSnapshot(workspaceID: workspace, revision: 3, projects: [], tasks: [], supportsTaskPlans: true) |
| 115 | #expect(!old.supportsTaskPlans) |
| 116 | #expect(upgraded.shouldReplace(old)) |
| 117 | let request = PhoneRequest(workspaceID: workspace, action: .savePlan(taskID: "stable-task-id", expectedMarkdown: "# Original", markdown: "# Revised")) |
| 118 | let restored = try JSONDecoder().decode(PhoneRequest.self, from: JSONEncoder().encode(request)) |
| 119 | #expect(restored.id == request.id) |
| 120 | #expect(restored.taskID == "stable-task-id") |
| 121 | guard case .savePlan(_, let expected, let markdown) = restored.action else { Issue.record("Wrong plan action"); return } |
| 122 | #expect(expected == "# Original") |
| 123 | #expect(markdown == "# Revised") |
| 124 | let capture = PhoneRequest(workspaceID: workspace, action: .create(projectID: "personal", title: "Task", notes: "Summary", priority: .medium, |
| 125 | sendToAgent: false, planMarkdown: "# Steps")) |
| 126 | let saved = try JSONDecoder().decode(PhoneRequest.self, from: JSONEncoder().encode(capture)) |
| 127 | guard case .create(_, _, _, _, _, _, _, _, _, _, let plan, _) = saved.action else { Issue.record("Wrong create action"); return } |
| 128 | #expect(plan == "# Steps") |
| 129 | } |
| 130 | |
| 131 | @Test func taskOrganizationCapabilityAndRequestsRoundTrip() throws { |
| 132 | let workspace = UUID() |
| 133 | let legacy = PhoneSnapshot(workspaceID: workspace, revision: 7, projects: [], tasks: []) |
| 134 | let current = PhoneSnapshot(workspaceID: workspace, revision: 7, projects: [], tasks: [], |
| 135 | supportsTaskOrganization: true) |
| 136 | #expect(!legacy.supportsTaskOrganization) |
| 137 | #expect(current.shouldReplace(legacy)) |
| 138 | #expect(try JSONDecoder().decode(PhoneSnapshot.self, from: JSONEncoder().encode(current)).supportsTaskOrganization) |
| 139 | for destination: PhoneRequest.TaskDestination in [.archive, .trash, .active] { |
| 140 | let request = PhoneRequest(workspaceID: workspace, action: .organizeTask(taskID: "task", destination: destination)) |
| 141 | let restored = try JSONDecoder().decode(PhoneRequest.self, from: JSONEncoder().encode(request)) |
| 142 | #expect(restored.id == request.id) |
| 143 | #expect(restored.taskID == "task") |
| 144 | #expect(restored.changesTask) |
| 145 | guard case .organizeTask(_, let decoded) = restored.action else { |
| 146 | Issue.record("Organization request did not round-trip") |
| 147 | return |
| 148 | } |
| 149 | #expect(decoded == destination) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | @Test func retriesKeepRequestIdentityAndWaitForTheAppliedRevision() throws { |
| 154 | let workspace = UUID() |
| 155 | let request = PhoneRequest(workspaceID: workspace, action: .create( |
| 156 | projectID: "work", title: "Private task", notes: "Do the work", priority: .urgent, sendToAgent: true |
| 157 | )) |
| 158 | let bytes = try JSONEncoder().encode(request) |
| 159 | let replay = try JSONDecoder().decode(PhoneRequest.self, from: bytes) |
| 160 | #expect(replay.id == request.id) |
| 161 | #expect(replay.workspaceID == workspace) |
| 162 | |
| 163 | let waiting = PhoneReceipt(requestID: request.id, outcome: .waiting, message: "Configure an agent.") |
| 164 | #expect(!waiting.isSettled(at: 3)) |
| 165 | |
| 166 | let applied = PhoneReceipt(requestID: request.id, outcome: .applied, revision: 2) |
| 167 | #expect(!applied.isSettled(at: 1)) |
| 168 | #expect(applied.isSettled(at: 2)) |
| 169 | } |
| 170 | |
| 171 | @Test func queuedTicketsRetainCompletionCriteriaAndOlderRequestsStillDecode() throws { |
| 172 | let request = PhoneRequest(workspaceID: UUID(), action: .create( |
| 173 | projectID: "work", title: "Verify the handoff", notes: "Review the checklist.", priority: .high, |
| 174 | sendToAgent: false, definitionOfDone: "Checklist reviewed and signed off." |
| 175 | )) |
| 176 | let data = try JSONEncoder().encode(request) |
| 177 | let restored = try JSONDecoder().decode(PhoneRequest.self, from: data) |
| 178 | guard case .create(_, _, _, _, _, let criteria, _, _, _, _, _, _) = restored.action else { |
| 179 | Issue.record("The queued ticket did not decode as a creation request.") |
| 180 | return |
| 181 | } |
| 182 | #expect(criteria == "Checklist reviewed and signed off.") |
| 183 | |
| 184 | let legacy = """ |
| 185 | { |
| 186 | "id": "\(request.id.uuidString)", |
| 187 | "workspaceID": "\(request.workspaceID.uuidString)", |
| 188 | "createdAt": 0, |
| 189 | "action": {"create": { |
| 190 | "projectID": "work", "title": "Legacy task", "notes": "", "priority": "High", "sendToAgent": false |
| 191 | }} |
| 192 | } |
| 193 | """ |
| 194 | let previous = try JSONDecoder().decode(PhoneRequest.self, from: Data(legacy.utf8)) |
| 195 | guard case .create(_, let title, _, _, _, let legacyCriteria, _, _, let legacyComment, let newProject, _, _) = previous.action else { |
| 196 | Issue.record("The older creation request did not decode.") |
| 197 | return |
| 198 | } |
| 199 | #expect(title == "Legacy task") |
| 200 | #expect(legacyCriteria == nil) |
| 201 | #expect(legacyComment == nil) |
| 202 | #expect(newProject == nil) |
| 203 | } |
| 204 | |
| 205 | #if DEBUG && os(macOS) |
| 206 | @MainActor |
| 207 | @Test func modelCatalogChangesSyncAtTheSameWorkspaceRevision() async throws { |
| 208 | let directory = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 209 | defer { try? FileManager.default.removeItem(at: directory) } |
| 210 | let transport = LocalCompanionTransport(directory: directory) |
| 211 | try await transport.prepare(account: transport.accountKey()) |
| 212 | let id = UUID() |
| 213 | var cached = PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], availableAgents: [.codex]) |
| 214 | try await transport.publish(cached) |
| 215 | let example = AgentModelChoice(agent: .codex, id: "provider-next-model", title: "New Model") |
| 216 | for catalog: [AgentModelChoice] in [[example], []] { |
| 217 | try await transport.publish(PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], |
| 218 | availableAgents: [.codex], agentModels: catalog)) |
| 219 | guard case .updated(let latest) = try await transport.snapshot(newerThan: cached) else { |
| 220 | Issue.record("The phone did not receive the changed model catalog.") |
| 221 | return |
| 222 | } |
| 223 | #expect(latest.agentModels == catalog) |
| 224 | cached = latest |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | @MainActor |
| 229 | @Test func upgradedMacEnablesEditingWithoutRequiringATaskChange() async throws { |
| 230 | let directory = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 231 | defer { try? FileManager.default.removeItem(at: directory) } |
| 232 | let transport = LocalCompanionTransport(directory: directory) |
| 233 | try await transport.prepare(account: transport.accountKey()) |
| 234 | |
| 235 | let id = UUID() |
| 236 | let previous = PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], commentsByTask: [:]) |
| 237 | try await transport.publish(previous) |
| 238 | let upgraded = PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], |
| 239 | commentsByTask: [:], supportsNoteEditing: true) |
| 240 | try await transport.publish(upgraded) |
| 241 | |
| 242 | guard case .updated(let refreshed) = try await transport.snapshot(newerThan: previous) else { |
| 243 | Issue.record("The phone did not see the capability change at the same workspace revision.") |
| 244 | return |
| 245 | } |
| 246 | #expect(refreshed.supportsNoteEditing) |
| 247 | #expect(!refreshed.supportsFieldEditing) |
| 248 | |
| 249 | let fieldEditing = PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], |
| 250 | commentsByTask: [:], supportsNoteEditing: true, supportsFieldEditing: true) |
| 251 | try await transport.publish(fieldEditing) |
| 252 | guard case .updated(let latest) = try await transport.snapshot(newerThan: refreshed) else { |
| 253 | Issue.record("The phone did not see the ticket fields capability at the same revision.") |
| 254 | return |
| 255 | } |
| 256 | #expect(latest.supportsFieldEditing) |
| 257 | } |
| 258 | #endif |
| 259 | |
| 260 | @Test func urgentToDosLeadAndEachGroupIsNewestFirst() throws { |
| 261 | let older = try #require(TaskCreationOrder.date(from: "2026-11-13T22:00:00Z")) |
| 262 | let newer = try #require(TaskCreationOrder.date(from: "2026-11-14T01:00:00.123Z")) |
| 263 | #expect(TaskCreationOrder.precedes(urgent: true, createdAt: older, otherUrgent: false, otherCreatedAt: newer) == true) |
| 264 | #expect(TaskCreationOrder.precedes(urgent: true, createdAt: newer, otherUrgent: true, otherCreatedAt: older) == true) |
| 265 | #expect(TaskCreationOrder.precedes(urgent: false, createdAt: older, otherUrgent: false, otherCreatedAt: newer) == false) |
| 266 | #expect(TaskCreationOrder.precedes(urgent: false, createdAt: nil, otherUrgent: false, otherCreatedAt: newer) == false) |
| 267 | } |
| 268 | |
| 269 | @Test func phoneDisplaysOnlyCanonicalTaskIDs() { |
| 270 | let uuid = UUID().uuidString |
| 271 | func ticket(_ key: String?) -> PhoneTask { |
| 272 | PhoneTask(id: uuid, projectID: "jotley", title: "Check task ID", notes: "", definitionOfDone: "", |
| 273 | status: .todo, priority: .medium, dueDate: nil, revision: 1, assigned: false, taskKey: key) |
| 274 | } |
| 275 | #expect(ticket("JOT-004").displayTaskID == "JOT-004") |
| 276 | #expect(ticket("ink-1").displayTaskID == "INK-001") |
| 277 | #expect(ticket("int-1435").displayTaskID == "INT-1435") |
| 278 | #expect(ticket(nil).displayTaskID == nil) |
| 279 | #expect(ticket(uuid).displayTaskID == nil) |
| 280 | } |
| 281 | |
| 282 | @Test func quickAddRoutesNamedProjectsAndDefaultsToPersonalAndMedium() { |
| 283 | let studio = PhoneProject(id: "studio", name: "Studio Launch") |
| 284 | let personal = PhoneProject(id: "personal", name: "Personal") |
| 285 | let projects = [studio, personal] |
| 286 | let named = TaskDrafting.captureDestination(in: "For project studio launch verify the download button.", |
| 287 | projects: projects, suggestedName: nil) |
| 288 | #expect(named.projectID == studio.id) |
| 289 | #expect(named.newProjectName == nil) |
| 290 | |
| 291 | let newProject = TaskDrafting.captureDestination(in: "For a new project called Harbor Launch, write the brief.", |
| 292 | projects: projects, suggestedName: studio.name) |
| 293 | #expect(newProject.newProjectName == "Harbor Launch") |
| 294 | |
| 295 | let fallback = TaskDrafting.captureDestination(in: "Call the plumber.", projects: projects, suggestedName: studio.name) |
| 296 | #expect(fallback.projectID == personal.id) |
| 297 | let missingPersonal = TaskDrafting.captureDestination(in: "Call the plumber.", projects: [studio], suggestedName: nil) |
| 298 | #expect(missingPersonal.newProjectName == "Personal") |
| 299 | |
| 300 | #expect(TaskDrafting.capturePriority(in: "Make this a critical task.") == .urgent) |
| 301 | #expect(TaskDrafting.capturePriority(in: "Set this task as high priority.") == .high) |
| 302 | #expect(TaskDrafting.capturePriority(in: "Call the plumber.") == .medium) |
| 303 | } |
| 304 | |
| 305 | #if DEBUG && os(macOS) |
| 306 | @MainActor |
| 307 | @Test func agentAvailabilityRefreshesWithoutATaskChange() async throws { |
| 308 | let directory = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 309 | defer { try? FileManager.default.removeItem(at: directory) } |
| 310 | let transport = LocalCompanionTransport(directory: directory) |
| 311 | try await transport.prepare(account: transport.accountKey()) |
| 312 | let id = UUID() |
| 313 | var cached = PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], |
| 314 | includesCardMetadata: true) |
| 315 | try await transport.publish(cached) |
| 316 | for agents: [PhoneAgent] in [[.codex], [.codex, .claude], []] { |
| 317 | try await transport.publish(PhoneSnapshot(workspaceID: id, revision: 7, projects: [], tasks: [], |
| 318 | includesCardMetadata: true, availableAgents: agents)) |
| 319 | guard case .updated(let latest) = try await transport.snapshot(newerThan: cached) else { |
| 320 | Issue.record("The phone did not receive updated agent availability.") |
| 321 | return |
| 322 | } |
| 323 | #expect(latest.availableAgents == agents) |
| 324 | cached = latest |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | @MainActor |
| 329 | @Test func sameRevisionSnapshotRefreshAddsCardMetadata() async throws { |
| 330 | let directory = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString) |
| 331 | defer { try? FileManager.default.removeItem(at: directory) } |
| 332 | let transport = LocalCompanionTransport(directory: directory) |
| 333 | try await transport.prepare(account: transport.accountKey()) |
| 334 | let workspaceID = UUID() |
| 335 | let legacyTask = PhoneTask(id: "test", projectID: "project", title: "Task", notes: "", definitionOfDone: "", |
| 336 | status: .todo, priority: .urgent, dueDate: nil, revision: 7, assigned: false) |
| 337 | let legacy = PhoneSnapshot(workspaceID: workspaceID, revision: 7, projects: [], tasks: [legacyTask], |
| 338 | supportsFieldEditing: true) |
| 339 | try await transport.publish(legacy) |
| 340 | guard case .updated(let cached) = try await transport.snapshot(newerThan: nil) else { |
| 341 | Issue.record("The old snapshot did not decode.") |
| 342 | return |
| 343 | } |
| 344 | #expect(cached.tasks.first?.createdAt == nil) |
| 345 | #expect(cached.tasks.first?.position == nil) |
| 346 | #expect(!cached.supportsTaskReordering) |
| 347 | let createdAt = Date(timeIntervalSinceReferenceDate: 123) |
| 348 | let newTask = PhoneTask(id: "test", projectID: "project", title: "Task", notes: "", definitionOfDone: "", |
| 349 | status: .todo, priority: .urgent, dueDate: nil, revision: 7, assigned: false, |
| 350 | taskKey: "PRO-001", createdAt: createdAt) |
| 351 | let upgraded = PhoneSnapshot(workspaceID: workspaceID, revision: 7, projects: [], tasks: [newTask], |
| 352 | supportsFieldEditing: true, includesCardMetadata: true) |
| 353 | try await transport.publish(upgraded) |
| 354 | guard case .updated(let refreshed) = try await transport.snapshot(newerThan: cached) else { |
| 355 | Issue.record("An unchanged workspace revision suppressed the new metadata.") |
| 356 | return |
| 357 | } |
| 358 | #expect(refreshed.tasks.first?.taskKey == "PRO-001") |
| 359 | #expect(refreshed.tasks.first?.createdAt == createdAt) |
| 360 | let positioned = PhoneTask(id: "test", projectID: "project", title: "Task", notes: "", definitionOfDone: "", |
| 361 | status: .todo, priority: .urgent, dueDate: nil, revision: 7, assigned: false, |
| 362 | taskKey: "PRO-001", createdAt: createdAt, position: 2) |
| 363 | let withOrder = PhoneSnapshot(workspaceID: workspaceID, revision: 7, projects: [], tasks: [positioned], |
| 364 | supportsFieldEditing: true, includesCardMetadata: true, supportsTaskReordering: true) |
| 365 | try await transport.publish(withOrder) |
| 366 | guard case .updated(let current) = try await transport.snapshot(newerThan: refreshed) else { |
| 367 | Issue.record("The phone did not receive manual positions when the Mac was upgraded.") |
| 368 | return |
| 369 | } |
| 370 | #expect(current.tasks.first?.position == 2) |
| 371 | #expect(current.supportsTaskReordering) |
| 372 | #expect(current.tasks.first?.completedAt == nil) |
| 373 | let completedAt = Date(timeIntervalSinceReferenceDate: 456) |
| 374 | let done = PhoneTask(id: "test", projectID: "project", title: "Task", notes: "", definitionOfDone: "", |
| 375 | status: .done, priority: .urgent, dueDate: nil, revision: 7, assigned: false, |
| 376 | createdAt: createdAt, completedAt: completedAt) |
| 377 | let withCompletionDate = PhoneSnapshot(workspaceID: workspaceID, revision: 7, projects: [], tasks: [done], |
| 378 | supportsTaskReordering: true, includesCompletionDates: true) |
| 379 | try await transport.publish(withCompletionDate) |
| 380 | guard case .updated(let completed) = try await transport.snapshot(newerThan: current) else { |
| 381 | Issue.record("An unchanged workspace revision suppressed recorded completion dates.") |
| 382 | return |
| 383 | } |
| 384 | #expect(completed.tasks.first?.completedAt == completedAt) |
| 385 | } |
| 386 | #endif |
| 387 | |
| 388 | @Test func bugInferenceRequiresAnExplicitBugIntent() throws { |
| 389 | #expect(IssueType.inferred(from: "Create a critical bug for the frozen task menu") == .bug) |
| 390 | #expect(IssueType.inferred(from: "Bug: due date cannot change") == .bug) |
| 391 | #expect(IssueType.inferred(from: "Buy bug spray") == .issue) |
| 392 | #expect(IssueType.inferred(from: "Write a release checklist") == .issue) |
| 393 | } |
| 394 | |
| 395 | @Test func revisionHistoryRoundTripsAndNeverReplaysDispatch() throws { |
| 396 | let data = Data(##"{"taskID":"task","revision":12,"entries":[{"id":"entry","version":3,"savedAt":"2026-11-19T12:00:00Z","action":"update_task","origin":"Mobile app","changedFields":["notes"],"state":{"title":"A bug","notes":"Original notes","definitionOfDone":"Test it","planMarkdown":"# Plan","issueType":"Bug","projectID":"project","projectName":"Studio","taskKey":"STU-001","status":"Sent to agent","priority":"High","dueDate":null,"position":0,"archived":false,"trashed":false}}],"nextBefore":3}"##.utf8) |
| 397 | let page = try JSONDecoder().decode(TaskHistoryPage.self, from: data) |
| 398 | #expect(page.entries[0].state.restoredStatus == .todo) |
| 399 | #expect(page.entries[0].state.issueType == .bug) |
| 400 | #expect(page.entries[0].summary == "Notes") |
| 401 | #expect(try JSONDecoder().decode(TaskHistoryPage.self, from: JSONEncoder().encode(page)) == page) |
| 402 | let request = PhoneRequest(workspaceID: UUID(), action: .restoreRevision(taskID: "task", historyID: "entry", revision: 12)) |
| 403 | #expect(request.changesTask) |
| 404 | #expect(request.taskID == "task") |
| 405 | let load = PhoneRequest(workspaceID: request.workspaceID, action: .loadHistory(taskID: "task", beforeVersion: 3)) |
| 406 | #expect(!load.changesTask) |
| 407 | let receipt = PhoneReceipt(requestID: load.id, outcome: .applied, revision: 12, history: page) |
| 408 | #expect(try JSONDecoder().decode(PhoneReceipt.self, from: JSONEncoder().encode(receipt)) == receipt) |
| 409 | let ended = try JSONDecoder().decode(TaskHistoryPage.self, from: Data(##"{"taskID":"task","revision":12,"entries":[],"nextBefore":null}"##.utf8)) |
| 410 | #expect(page.merging(ended).nextBefore == nil) |
| 411 | #expect(page.merging(page).entries.count == 1) |
| 412 | } |
| 413 | |
| 414 | @Test func activityPagesRoundTripKeepContinuousHistoryAndDiscardGaps() throws { |
| 415 | func entry(_ n: Int, kind: String = "change") -> TaskActivityEntry { |
| 416 | TaskActivityEntry(id: String(n), sequence: n, createdAt: "2026-11-19T15:00:00Z", actor: "You", kind: kind, summary: "Changed task", detail: "To do → In progress", images: []) |
| 417 | } |
| 418 | let older = TaskActivityPage(taskID: "task", revision: 9, entries: (1...5).reversed().map { entry($0) }, nextBefore: nil) |
| 419 | let current = TaskActivityPage(taskID: "task", revision: 10, entries: (5...9).reversed().map { entry($0) }, nextBefore: 5) |
| 420 | let merged = current.keepingOlder(from: older) |
| 421 | #expect(merged.entries.map(\.sequence) == Array((1...9).reversed())) |
| 422 | #expect(merged.nextBefore == nil) |
| 423 | let gap = TaskActivityPage(taskID: "task", revision: 20, entries: [entry(20), entry(19)], nextBefore: 19) |
| 424 | #expect(gap.keepingOlder(from: merged) == gap) |
| 425 | let restored = TaskActivityPage(taskID: "task", revision: 11, entries: [entry(10, kind: "restore"), entry(9)], nextBefore: 9) |
| 426 | #expect(restored.keepingOlder(from: merged) == restored) |
| 427 | let request = PhoneRequest(workspaceID: UUID(), action: .loadActivity(taskID: "task", beforeSequence: 5)) |
| 428 | #expect(!request.changesTask) |
| 429 | #expect(try JSONDecoder().decode(PhoneRequest.self, from: JSONEncoder().encode(request)).taskID == "task") |
| 430 | let receipt = PhoneReceipt(requestID: request.id, outcome: .applied, revision: 10, activity: merged) |
| 431 | #expect(try JSONDecoder().decode(PhoneReceipt.self, from: JSONEncoder().encode(receipt)).activity == merged) |
| 432 | let old = PhoneSnapshot(workspaceID: request.workspaceID, revision: 10, projects: [], tasks: []) |
| 433 | let updated = PhoneSnapshot(workspaceID: request.workspaceID, revision: 10, projects: [], tasks: [], activityByTask: ["task": current]) |
| 434 | #expect(updated.shouldReplace(old)) |
| 435 | #expect(try JSONDecoder().decode(PhoneSnapshot.self, from: JSONEncoder().encode(old)).activityByTask == nil) |
| 436 | } |
| 437 | |
| 438 | @Test func commentsHideUnknownLegacyAuthorsAndDoNotTreatPickupAsActedOn() throws { |
| 439 | let old = try JSONDecoder().decode(PhoneComment.self, from: Data(#"{"id":"legacy","text":"Agent report","createdAt":"2026-11-19T12:00:00Z","delivery":"delivered","pickedUpAt":"2026-11-19T12:01:00Z"}"#.utf8)) |
| 440 | #expect(!old.isUserComment(hasSeparatedActivity: false)) |
| 441 | #expect(old.isUserComment(hasSeparatedActivity: true)) // v18 Mac already filtered this stream. |
| 442 | #expect(!old.wasActedOn) |
| 443 | let user = PhoneComment(id: "user", text: "Change the date", createdAt: "2026-11-19T12:00:00Z", source: "user", actedOnAt: "2026-11-19T12:02:00Z", activityID: "report") |
| 444 | #expect(user.isUserComment(hasSeparatedActivity: false)) |
| 445 | #expect(user.wasActedOn) |
| 446 | let legacy = PhoneComment(id: "other", text: "Earlier message", createdAt: "2026-11-19T12:00:00Z", source: "legacy") |
| 447 | #expect(!legacy.isUserComment(hasSeparatedActivity: true)) |
| 448 | let workspace = UUID() |
| 449 | let previous = PhoneSnapshot(workspaceID: workspace, revision: 8, projects: [], tasks: [], activityByTask: [:]) |
| 450 | let current = PhoneSnapshot(workspaceID: workspace, revision: 8, projects: [], tasks: [], activityByTask: [:], supportsCommentActivity: true) |
| 451 | #expect(current.shouldReplace(previous)) |
| 452 | let request = PhoneRequest(workspaceID: workspace, action: .loadCommentActivity(taskID: "task", commentID: "user", beforeSequence: nil)) |
| 453 | #expect(!request.changesTask) |
| 454 | #expect(try JSONDecoder().decode(PhoneRequest.self, from: JSONEncoder().encode(request)).taskID == "task") |
| 455 | let taskPage = TaskActivityPage(taskID: "task", revision: 8, entries: [], nextBefore: nil) |
| 456 | let commentPage = TaskActivityPage(taskID: "task", revision: 8, entries: [], nextBefore: nil, commentID: "user") |
| 457 | #expect(taskPage.merging(commentPage) == taskPage) |
| 458 | #expect(try JSONDecoder().decode(TaskActivityPage.self, from: JSONEncoder().encode(commentPage)).commentID == "user") |
| 459 | } |
| 460 | |
| 461 | @Test func openFeedUsesCreationOrderUnlessAnotherSortIsSelected() { |
| 462 | struct Task: Identifiable { |
| 463 | let id: String |
| 464 | let created: Date? |
| 465 | let rank: Int |
| 466 | let due: String? |
| 467 | } |
| 468 | let tasks = [ |
| 469 | Task(id: "legacy", created: nil, rank: 0, due: nil), |
| 470 | Task(id: "urgent", created: .distantPast.addingTimeInterval(1), rank: 0, due: "2026-12-02"), |
| 471 | Task(id: "new", created: .now, rank: 4, due: "2026-12-01") |
| 472 | ] |
| 473 | func ids(_ sort: OpenTaskSort) -> [String] { |
| 474 | sort.ordered(tasks, created: \.created, priorityRank: \.rank, due: \.due).map(\.id) |
| 475 | } |
| 476 | #expect(ids(.newest) == ["new", "urgent", "legacy"]) |
| 477 | #expect(ids(.priority) == ["urgent", "legacy", "new"]) |
| 478 | #expect(ids(.dueDate) == ["new", "urgent", "legacy"]) |
| 479 | } |
| 480 | |
| 481 | @Test func geminiReachesCurrentAppsWithoutBreakingEarlierOnes() throws { |
| 482 | // The agent contract shipped before Gemini. An unknown agent anywhere in it fails the whole snapshot. |
| 483 | struct EarlierSnapshot: Decodable { |
| 484 | enum Agent: String, Decodable { case claude = "claude-code", codex } |
| 485 | struct Model: Decodable { let agent: Agent; let id: String } |
| 486 | let defaultAgent: Agent? |
| 487 | let availableAgents: [Agent]? |
| 488 | let agentModels: [Model]? |
| 489 | } |
| 490 | let models = [ |
| 491 | AgentModelChoice(agent: .codex, id: "gpt-6.2-sol", title: "GPT-6.2 Sol"), |
| 492 | AgentModelChoice(agent: .gemini, id: "gemini-4-hydrogen-high", title: "Gemini 4 Hydrogen"), |
| 493 | ] |
| 494 | let id = UUID() |
| 495 | let snapshot = PhoneSnapshot(workspaceID: id, revision: 3, projects: [], tasks: [], defaultAgent: .gemini, |
| 496 | availableAgents: [.claude, .codex, .gemini], agentModels: models) |
| 497 | let data = try JSONEncoder().encode(snapshot) |
| 498 | |
| 499 | let earlier = try JSONDecoder().decode(EarlierSnapshot.self, from: data) |
| 500 | #expect(earlier.defaultAgent == nil) |
| 501 | #expect(earlier.availableAgents == [.claude, .codex]) |
| 502 | #expect(earlier.agentModels?.map(\.id) == ["gpt-6.2-sol"]) |
| 503 | |
| 504 | let current = try JSONDecoder().decode(PhoneSnapshot.self, from: data) |
| 505 | #expect(current.agents.defaultAgent == .gemini) |
| 506 | #expect(current.agents.availableAgents == [.claude, .codex, .gemini]) |
| 507 | #expect(current.agents.agentModels == models) |
| 508 | #expect(PhoneAgent.gemini.title == "Gemini") |
| 509 | #expect(PhoneTaskFieldEdit.status(.sent, agent: .gemini).label == "Send to Gemini") |
| 510 | // Gemini's Agent default names the model it sends. Claude and Codex choose their own. |
| 511 | #expect(PhoneAgent.gemini.agentDefaultTitle(models: models) == "Agent default (Gemini 4 Hydrogen)") |
| 512 | #expect(PhoneAgent.gemini.agentDefaultTitle(models: [models[0]]) == "Agent default") |
| 513 | #expect(PhoneAgent.codex.agentDefaultTitle(models: models) == "Agent default") |
| 514 | |
| 515 | // A Mac that has not been updated sends only the earlier fields. |
| 516 | let olderMac = try JSONDecoder().decode(PhoneSnapshot.self, from: Data(""" |
| 517 | {"version":1,"workspaceID":"\(id.uuidString)","revision":3,"updatedAt":0,"projects":[],"tasks":[], |
| 518 | "defaultAgent":"codex","availableAgents":["codex"],"agentModels":[{"agent":"codex","id":"gpt-6.2-sol","title":"Sol"}]} |
| 519 | """.utf8)) |
| 520 | #expect(olderMac.agents.defaultAgent == .codex) |
| 521 | #expect(olderMac.agents.availableAgents == [.codex]) |
| 522 | // Gemini becoming available replaces a stored snapshot at the same task revision. |
| 523 | let withoutGemini = PhoneSnapshot(workspaceID: id, revision: 3, projects: [], tasks: [], defaultAgent: .codex, |
| 524 | availableAgents: [.codex], agentModels: [models[0]]) |
| 525 | #expect(snapshot.shouldReplace(withoutGemini)) |
| 526 | #expect(snapshot.shouldReplace(olderMac)) |
| 527 | #expect(!snapshot.shouldReplace(snapshot)) |
| 528 | } |
| 529 | |
| 530 | private func withdrawalSnapshot(workspace: UUID, supported: Bool, comments: [PhoneComment] = []) -> PhoneSnapshot { |
| 531 | PhoneSnapshot(workspaceID: workspace, revision: 4, projects: [], tasks: [], |
| 532 | commentsByTask: ["task-1": comments], supportsCommentActivity: true, |
| 533 | filesByTask: [:], supportsRevisionWithdrawal: supported) |
| 534 | } |
| 535 | |
| 536 | @Test func withdrawalRequestsRoundTripAndOlderMacsNeverReceiveThem() throws { |
| 537 | let workspace = UUID() |
| 538 | let withdrawal = PhoneRequest(workspaceID: workspace, action: .withdrawComment(taskID: "task-1", commentID: "abc")) |
| 539 | let restored = try JSONDecoder().decode(PhoneRequest.self, from: JSONEncoder().encode(withdrawal)) |
| 540 | #expect(restored.id == withdrawal.id) |
| 541 | #expect(restored.taskID == "task-1") |
| 542 | #expect(restored.withdrawnRevisionID == "abc") |
| 543 | #expect(!restored.changesTask) |
| 544 | |
| 545 | // A Mac that predates withdrawal publishes no capability, and its snapshot still decodes. |
| 546 | let older = withdrawalSnapshot(workspace: workspace, supported: false) |
| 547 | let current = withdrawalSnapshot(workspace: workspace, supported: true) |
| 548 | let decoded = try JSONDecoder().decode(PhoneSnapshot.self, from: JSONEncoder().encode(older)) |
| 549 | #expect(!decoded.supportsRevisionWithdrawal) |
| 550 | #expect(try JSONDecoder().decode(PhoneSnapshot.self, from: JSONEncoder().encode(current)).supportsRevisionWithdrawal) |
| 551 | // The upgraded Mac republishes at the same workspace revision so phones learn the capability. |
| 552 | #expect(current.projectionVersion == 24) |
| 553 | #expect(current.shouldReplace(older)) |
| 554 | #expect(!older.shouldReplace(current)) |
| 555 | |
| 556 | let comment = PhoneRequest(workspaceID: workspace, action: .comment(taskID: "task-1", text: "Offered to iCloud")) |
| 557 | #expect(throws: RevisionWithdrawal.Failure.updateMac) { |
| 558 | try RevisionWithdrawal.plan(revisionID: comment.revisionID!, taskID: "task-1", pending: [comment], |
| 559 | unsent: [], snapshot: older) |
| 560 | } |
| 561 | // A request that never left the phone needs no Mac support at all. |
| 562 | #expect(try RevisionWithdrawal.plan(revisionID: comment.revisionID!, taskID: "task-1", pending: [comment], |
| 563 | unsent: [comment.id], snapshot: older) == .discard(requestID: comment.id)) |
| 564 | } |
| 565 | |
| 566 | @Test func withdrawalPlansUseTheStableIDAndStayInsideTheTaskAndWorkspace() throws { |
| 567 | let workspace = UUID() |
| 568 | let queued = PhoneRequest(workspaceID: workspace, action: .comment(taskID: "task-1", text: "Queued here")) |
| 569 | let stable = try #require(queued.revisionID) |
| 570 | #expect(stable == queued.id.uuidString.lowercased()) |
| 571 | let saved = PhoneComment(id: "saved-1", text: "Waiting", createdAt: "2026-11-23T10:00:00Z", delivery: "queued", source: "user") |
| 572 | let received = PhoneComment(id: "saved-2", text: "With the agent", createdAt: "2026-11-23T10:00:00Z", delivery: "delivered", |
| 573 | pickedUpAt: "2026-11-23T10:01:00Z", source: "user") |
| 574 | let acted = PhoneComment(id: "saved-3", text: "Applied", createdAt: "2026-11-23T10:00:00Z", delivery: "delivered", |
| 575 | source: "user", actedOnAt: "2026-11-23T10:05:00Z", activityID: "activity-1") |
| 576 | let legacy = PhoneComment(id: "saved-4", text: "Agent note", createdAt: "2026-11-23T10:00:00Z", delivery: "local", source: "legacy") |
| 577 | let snapshot = withdrawalSnapshot(workspace: workspace, supported: true, comments: [saved, received, acted, legacy]) |
| 578 | |
| 579 | #expect(try RevisionWithdrawal.plan(revisionID: stable, taskID: "task-1", pending: [queued], unsent: [], |
| 580 | snapshot: snapshot) == .request(commentID: stable)) |
| 581 | #expect(try RevisionWithdrawal.plan(revisionID: "saved-1", taskID: "task-1", pending: [], unsent: [], |
| 582 | snapshot: snapshot) == .request(commentID: "saved-1")) |
| 583 | // A request the agent holds but has not acted on can still be withdrawn. Applied work cannot. |
| 584 | #expect(received.reachedAgent && received.canWithdraw) |
| 585 | #expect(try RevisionWithdrawal.plan(revisionID: "saved-2", taskID: "task-1", pending: [], unsent: [], |
| 586 | snapshot: snapshot) == .request(commentID: "saved-2")) |
| 587 | #expect(throws: RevisionWithdrawal.Failure.alreadyActedOn) { |
| 588 | try RevisionWithdrawal.plan(revisionID: "saved-3", taskID: "task-1", pending: [], unsent: [], snapshot: snapshot) |
| 589 | } |
| 590 | #expect(!RevisionWithdrawal.isOffered(for: acted, in: snapshot)) |
| 591 | #expect(!RevisionWithdrawal.isOffered(for: legacy, in: snapshot)) |
| 592 | #expect(RevisionWithdrawal.isOffered(for: saved, in: snapshot)) |
| 593 | #expect(!RevisionWithdrawal.isOffered(for: saved, in: withdrawalSnapshot(workspace: workspace, supported: false))) |
| 594 | |
| 595 | // Another task or another workspace never matches. |
| 596 | #expect(throws: RevisionWithdrawal.Failure.missing) { |
| 597 | try RevisionWithdrawal.plan(revisionID: "saved-1", taskID: "task-2", pending: [], unsent: [], snapshot: snapshot) |
| 598 | } |
| 599 | #expect(throws: RevisionWithdrawal.Failure.missing) { |
| 600 | try RevisionWithdrawal.plan(revisionID: stable, taskID: "task-2", pending: [queued], unsent: [queued.id], snapshot: snapshot) |
| 601 | } |
| 602 | let elsewhere = PhoneRequest(workspaceID: UUID(), action: .comment(taskID: "task-1", text: "Other workspace")) |
| 603 | #expect(throws: RevisionWithdrawal.Failure.missing) { |
| 604 | try RevisionWithdrawal.plan(revisionID: elsewhere.revisionID!, taskID: "task-1", pending: [elsewhere], |
| 605 | unsent: [elsewhere.id], snapshot: snapshot) |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | @Test func withdrawnRequestsSettleQuietlyAndStayHiddenUntilBothRequestsLeaveTheQueue() { |
| 610 | let workspace = UUID() |
| 611 | let comment = PhoneRequest(workspaceID: workspace, action: .comment(taskID: "task-1", text: "Changed my mind")) |
| 612 | let stable = comment.revisionID! |
| 613 | let withdrawal = PhoneRequest(workspaceID: workspace, action: .withdrawComment(taskID: "task-1", commentID: stable)) |
| 614 | let other = PhoneRequest(workspaceID: workspace, action: .comment(taskID: "task-1", text: "Still wanted")) |
| 615 | |
| 616 | #expect(RevisionWithdrawal.hidesRejection(of: comment, withdrawing: [stable])) |
| 617 | #expect(!RevisionWithdrawal.hidesRejection(of: other, withdrawing: [stable])) |
| 618 | #expect(!RevisionWithdrawal.hidesRejection(of: withdrawal, withdrawing: [stable]), "A refused withdrawal is reported") |
| 619 | #expect(RevisionWithdrawal.stillWithdrawing([stable], pending: [comment, withdrawal, other]) == [stable]) |
| 620 | #expect(RevisionWithdrawal.stillWithdrawing([stable], pending: [comment, other]) == [stable]) |
| 621 | #expect(RevisionWithdrawal.stillWithdrawing([stable], pending: [other]).isEmpty) |
| 622 | } |
| 623 | |
| 624 | #if DEBUG && os(macOS) |
| 625 | @MainActor |
| 626 | @Test func theMacAppliesAWithdrawalBeforeTheRequestItCancelsAndKeepsEachReceipt() async throws { |
| 627 | let directory = FileManager.default.temporaryDirectory.appending(path: "opentalon-withdraw-" + UUID().uuidString) |
| 628 | defer { try? FileManager.default.removeItem(at: directory) } |
| 629 | let transport = LocalCompanionTransport(directory: directory) |
| 630 | try await transport.prepare(account: try await transport.accountKey()) |
| 631 | let workspace = UUID() |
| 632 | try await transport.publish(withdrawalSnapshot(workspace: workspace, supported: true)) |
| 633 | |
| 634 | // The phone queued a request offline, then withdrew it. Both reach iCloud in one pass. |
| 635 | let comment = PhoneRequest(workspaceID: workspace, action: .comment(taskID: "task-1", text: "Queued offline")) |
| 636 | let edit = PhoneRequest(workspaceID: workspace, action: .forceComplete(taskID: "task-2")) |
| 637 | let withdrawal = PhoneRequest(workspaceID: workspace, |
| 638 | action: .withdrawComment(taskID: "task-1", commentID: comment.revisionID!)) |
| 639 | for request in [comment, edit, withdrawal] { #expect(try await transport.submit(request) == nil) } |
| 640 | |
| 641 | let ordered = PhoneRequest.applicationOrder(try await transport.pendingRequests(for: workspace)) |
| 642 | #expect(ordered.map(\.id) == [withdrawal.id, comment.id, edit.id]) |
| 643 | |
| 644 | // The Mac records the withdrawal, then turns the late request away. Each keeps its own receipt on retry. |
| 645 | try await transport.acknowledge(PhoneReceipt(requestID: withdrawal.id, outcome: .applied, revision: 5)) |
| 646 | try await transport.acknowledge(PhoneReceipt(requestID: comment.id, outcome: .rejected, |
| 647 | message: "This revision request was withdrawn before it reached your Mac.")) |
| 648 | #expect(try await transport.pendingRequests(for: workspace).map(\.id) == [edit.id]) |
| 649 | #expect(try await transport.submit(withdrawal)?.outcome == .applied) |
| 650 | let refused = try #require(try await transport.submit(comment)) |
| 651 | #expect(refused.outcome == .rejected) |
| 652 | #expect(refused.isSettled(at: 4)) |
| 653 | #expect(RevisionWithdrawal.hidesRejection(of: comment, withdrawing: [comment.revisionID!])) |
| 654 | } |
| 655 | #endif |