updates for lock screen

This commit is contained in:
Mark Gregory
2026-11-04 15:25:14 +00:00
parent 66adec42e3
commit b16c56baab
5 changed files with 170 additions and 2 deletions
+31
View File
@@ -218,6 +218,37 @@ final class MockProtocol: URLProtocol, @unchecked Sendable {
presentation.authenticate = { _ in false }
await presentation.updateScene(.active)
check(presentation.locked && presentation.unlockNeedsRetry, "Incomplete authentication offers a retry instead of a permanent spinner")
var history = TransferHistory()
let origin = Date(timeIntervalSince1970: 10000)
history.record(download: 100, upload: 20, at: origin)
history.record(download: 200, upload: 30, at: origin.addingTimeInterval(3))
check(history.samples.count == 2 && history.samples.last?.download == 200, "History records actual upload and download speed samples")
history.record(download: -1, upload: -5, at: origin.addingTimeInterval(3.5))
check(history.samples.count == 2 && history.samples.last?.download == 0 && history.samples.last?.upload == 0, "Rapid refreshes coalesce and negative speeds clamp to zero")
history.record(download: 99, upload: 99, at: origin)
check(history.samples.count == 2, "Out-of-order speed samples cannot corrupt the timeline")
history.record(download: 300, upload: 30, at: origin.addingTimeInterval(30))
check(history.samples.last?.segment == 1, "Background and network gaps start a new chart segment")
history.record(download: 400, upload: 40, at: origin.addingTimeInterval(1000))
check(history.samples.count == 1, "History expires samples older than fifteen minutes")
var dense = TransferHistory()
for second in 0...700 { dense.record(download: 1, upload: 2, at: origin.addingTimeInterval(Double(second))) }
check(dense.samples.count == TransferHistory.maximumSamples, "History storage remains bounded during frequent refreshes")
check(model.transferHistory.samples.isEmpty, "Disconnected session has no previous server history")
let historyTransport = try Transport(Credentials(server: "https://example.test"), configuration: config)
let liveHistory = AppModel()
liveHistory.client = historyTransport; liveHistory.connected = true; liveHistory.locked = false
MockProtocol.handler = { request in
if request.url!.path.hasSuffix("torrents/info") { return (200, "[]") }
return (200, "{\"server_state\":{\"dl_info_speed\":1234,\"up_info_speed\":567}}")
}
await liveHistory.refresh()
check(liveHistory.transferHistory.samples.last?.download == 1234 && liveHistory.transferHistory.samples.last?.upload == 567, "Successful dashboard refresh records both speed series")
MockProtocol.handler = { _ in throw URLError(.notConnectedToInternet) }
await liveHistory.refresh()
check(liveHistory.transferHistory.samples.count == 1, "Failed refresh never fabricates a speed sample")
liveHistory.disconnect()
check(liveHistory.transferHistory.samples.isEmpty, "Disconnect removes actual collected history")
another.close(); transport.close(); print("\(checks) contract checks passed.")
}
}