now with notifications

This commit is contained in:
Mark Gregory
2026-11-05 10:42:10 +00:00
parent 6643ba72c8
commit 35e1d44697
4 changed files with 121 additions and 22 deletions
+20
View File
@@ -289,6 +289,26 @@ final class MockProtocol: URLProtocol, @unchecked Sendable {
check(completionFixture.complete, "Full measured progress is completed")
completionFixture.progress = 0.9999
check(!completionFixture.complete, "Rounded near-100-percent progress is not completed")
var notificationTracker = DownloadNotificationTracker()
var eventTorrent = queue[0]
eventTorrent.state = "queuedDL"; eventTorrent.progress = 0
check(notificationTracker.observe([eventTorrent]).isEmpty, "Initial notification snapshot is silent")
eventTorrent.state = "metaDL"
check(notificationTracker.observe([eventTorrent]).isEmpty, "Metadata lookup does not notify download start")
eventTorrent.state = "downloading"
check(notificationTracker.observe([eventTorrent]).map(\.type) == [.started], "Queued torrent entering downloading emits a start event")
check(notificationTracker.observe([eventTorrent]).isEmpty, "Unchanged polling never repeats start notifications")
eventTorrent.state = "pausedDL"
check(notificationTracker.observe([eventTorrent]).isEmpty, "Pausing emits no download notification")
eventTorrent.state = "forcedDL"
check(notificationTracker.observe([eventTorrent]).map(\.type) == [.started], "Resuming emits a new start event")
eventTorrent.progress = 1; eventTorrent.state = "uploading"
check(notificationTracker.observe([eventTorrent]).map(\.type) == [.completed], "Completion emits only a completion event")
check(notificationTracker.observe([eventTorrent]).isEmpty, "Unchanged completion does not repeat")
var reconnectTracker = DownloadNotificationTracker()
check(reconnectTracker.observe([eventTorrent]).isEmpty, "Reconnect does not alert existing completed torrents")
eventTorrent.hash = "new-download"; eventTorrent.progress = 0; eventTorrent.state = "downloading"
check(reconnectTracker.observe([eventTorrent]).map(\.type) == [.started], "Newly added active download alerts after baseline")
another.close(); transport.close(); print("\(checks) contract checks passed.")
}
}