mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-15 04:46:03 +00:00
40 lines
1.4 KiB
Swift
40 lines
1.4 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import OpenClaw
|
|
|
|
struct AgentOverviewRefreshGateTests {
|
|
@Test func `new overview refresh invalidates an older result`() {
|
|
var gate = AgentOverviewRefreshGate()
|
|
|
|
let first = gate.begin()
|
|
let second = gate.begin()
|
|
|
|
#expect(!gate.isCurrent(first))
|
|
#expect(gate.isCurrent(second))
|
|
}
|
|
|
|
@Test func `current overview refresh remains accepted until superseded`() {
|
|
var gate = AgentOverviewRefreshGate()
|
|
let generation = gate.begin()
|
|
|
|
#expect(gate.isCurrent(generation))
|
|
}
|
|
|
|
@Test func `automatic refresh coalesces before invalidating current work`() throws {
|
|
let source = try String(contentsOf: Self.gatewayDataSourceURL(), encoding: .utf8)
|
|
let method = try #require(source.range(of: "func refreshOverview(force: Bool) async"))
|
|
let tail = source[method.lowerBound...]
|
|
let coalescingGuard = try #require(tail.range(of: "if self.overviewLoading, !force"))
|
|
let generation = try #require(tail.range(of: "let generation = self.overviewRefreshGate.begin()"))
|
|
|
|
#expect(coalescingGuard.lowerBound < generation.lowerBound)
|
|
}
|
|
|
|
private static func gatewayDataSourceURL() -> URL {
|
|
URL(fileURLWithPath: #filePath)
|
|
.deletingLastPathComponent()
|
|
.deletingLastPathComponent()
|
|
.appendingPathComponent("Sources/Design/AgentProTab+GatewayData.swift")
|
|
}
|
|
}
|