Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
test(spaces-macos): make the hung window listing test deterministic (#5037)
Francesco Bonaccib72e91c42074
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/StreamRowsModel.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/StreamRowsModel.swiftindex ef3b5da51b..bc9c1e8a34 100644--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/StreamRowsModel.swift+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/StreamRowsModel.swift@@ -33,14 +33,18 @@ final class StreamRowsModel: ObservableObject {private let listWindows: Windowsprivate let primaryDisplay: Displayprivate let appIcons: Icons+ /// When a window listing times out (tests fire it by hand).+ private let deadline: DeadlineSchedulerinit(os: AppSpaceOs, osName: String?, windows: @escaping Windows,- display: @escaping Display, icons: @escaping Icons) {+ display: @escaping Display, icons: @escaping Icons,+ deadline: @escaping DeadlineScheduler = dispatchDeadline) {self.os = osself.osName = osNameself.listWindows = windowsself.primaryDisplay = displayself.appIcons = icons+ self.deadline = deadline}/// From the app's backend.@@ -75,12 +79,12 @@ final class StreamRowsModel: ObservableObject {/// Reads the windows and the display once./// How long a window listing may take: a hung one would keep "Looking/// for this Space's windows…" up forever; past this it reads as failed.- static var windowsTimeout: Double = 15+ static let windowsTimeout: Double = 15func refresh() async {async let d = primaryDisplay()do {- windows = try await withTimeout(seconds: Self.windowsTimeout) { [listWindows] in+ windows = try await withTimeout(seconds: Self.windowsTimeout, deadline: deadline) { [listWindows] intry await listWindows()}.get()failed = falsediff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/StreamRowsTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/StreamRowsTests.swiftindex 6ba7b308f7..cf6c2625e4 100644--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/StreamRowsTests.swift+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/StreamRowsTests.swift@@ -7,6 +7,7 @@ import CuaSpacesFFI@testable import CuaSpacesMacKitimport CuaSpacesStreamingimport Foundation+import osimport Testing/// Stream rows fixtures: an Ubuntu Space with a screen target, two Firefox@@ -72,19 +73,22 @@ struct StreamRowsTests {/// A listing that never answers does not keep "Looking for this/// Space's windows…" up: past the bound it reads as failed, with the/// Desktop row still there.+ /// The deadline fires at once here, so the test does not depend on the+ /// runner's speed.@Test func aHungWindowListingFailsInsteadOfLoadingForever() async {- let saved = StreamRowsModel.windowsTimeout- StreamRowsModel.windowsTimeout = 0.2- defer { StreamRowsModel.windowsTimeout = saved }+ let scheduled = OSAllocatedUnfairLock<[Double]>(initialState: [])let m = StreamRowsModel(os: .linux, osName: "Ubuntu 24.04",windows: {try await Task.sleep(for: .seconds(3600))return []},- display: { nil }, icons: { _ in [] })- let started = ContinuousClock.now+ display: { nil }, icons: { _ in [] },+ deadline: { seconds, fire in+ scheduled.withLock { $0.append(seconds) }+ fire()+ })await m.refresh()- #expect(ContinuousClock.now - started < .seconds(5))+ #expect(scheduled.withLock { $0 } == [StreamRowsModel.windowsTimeout])#expect(m.failed)#expect(m.windows == [])#expect(m.section().rows.map(\.label) == ["Desktop"])