Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273import ParcelCoreimport Testing
private let recordedEngineEvents = #""" {"event":{"displaySetChanged":{"_0":[{"frame":{"origin":{"xCoordinate":0,"yCoordinate":0},"size":{"height":800,"width":1200}},"id":"00000000-0000-0000-0000-000000000001"},{"frame":{"origin":{"xCoordinate":1200,"yCoordinate":0},"size":{"height":800,"width":1200}},"id":"00000000-0000-0000-0000-000000000002"}]}},"version":1} {"event":{"activeSpaceChanged":{"display":"00000000-0000-0000-0000-000000000001","space":1}},"version":1} {"event":{"activeSpaceChanged":{"display":"00000000-0000-0000-0000-000000000002","space":2}},"version":1} {"event":{"windowAppeared":{"_0":{"app":{"bundleID":"test.fixture","pid":100},"id":1,"isFloating":false,"role":"AXWindow","title":"Window 1"},"frame":{"origin":{"xCoordinate":30,"yCoordinate":40},"size":{"height":200,"width":300}},"workspace":{"display":"00000000-0000-0000-0000-000000000001","space":1}}},"version":1} {"event":{"windowAppeared":{"_0":{"app":{"bundleID":"test.fixture","pid":100},"id":2,"isFloating":false,"role":"AXWindow","title":"Window 2"},"frame":{"origin":{"xCoordinate":30,"yCoordinate":40},"size":{"height":200,"width":300}},"workspace":{"display":"00000000-0000-0000-0000-000000000001","space":1}}},"version":1} {"event":{"windowAppeared":{"_0":{"app":{"bundleID":"test.fixture","pid":100},"id":3,"isFloating":false,"role":"AXWindow","title":"Window 3"},"frame":{"origin":{"xCoordinate":30,"yCoordinate":40},"size":{"height":200,"width":300}},"workspace":{"display":"00000000-0000-0000-0000-000000000002","space":2}}},"version":1} {"event":{"focusChanged":{"_0":1}},"version":1} {"event":{"commandIssued":{"_0":{"setWindowCap":{"_0":1}}}},"version":1} {"event":{"commandIssued":{"_0":{"moveToDisplay":{"_0":"right"}}}},"version":1} {"event":{"commandIssued":{"_0":{"setLayout":{"_0":"rows"}}}},"version":1} """#
@Suite("Engine recorded event replay")@MainActorstruct ParcelEngineReplayTests { @Test func recordedJSONLinesMatchCoreReplayThroughEngine() async throws { var configuration = engineConfiguration(layout: .grid) configuration.layout.global.windowCap = 3 let harness = try EngineHarness(configuration: configuration, initialState: State()) try await harness.start() let events = try EventStream.decode(recordedEngineEvents) #expect(events.count == 10) let expected = try Replay.run(jsonLines: recordedEngineEvents)
for event in events { harness.engine.send(event) try harness.scheduler.runReady() try harness.scheduler.advance(by: 0.1) }
#expect(harness.engine.snapshot.state == expected.state) #expect(harness.engine.snapshot.focusedWindow == WindowID(rawValue: 1)) #expect( harness.engine.snapshot.state.workspace(containing: WindowID(rawValue: 1)) == WorkspaceKey(display: secondEngineDisplay, space: SpaceID(rawValue: 2))) #expect( harness.engine.snapshot.state.frames[WindowID(rawValue: 1)] == Rect(x: 1200, y: 400, width: 1200, height: 400)) #expect( harness.engine.snapshot.state.frames[WindowID(rawValue: 3)] == Rect(x: 1200, y: 0, width: 1200, height: 400) ) for tile in harness.engine.snapshot.tiles { #expect(harness.world.frames[tile.window] == tile.frame) } #expect(harness.engine.isIdle) #expect(harness.log.platformFailures.isEmpty) #expect(harness.log.motionErrors.isEmpty) await harness.engine.stop() }
@Test func recordedJSONLinesCanBeCoalescedIntoOnePass() async throws { var configuration = engineConfiguration(layout: .grid) configuration.layout.global.windowCap = 3 let harness = try EngineHarness(configuration: configuration, initialState: State()) try await harness.start() let events = try EventStream.decode(recordedEngineEvents) let expected = Replay.run(events) let passes = harness.engine.layoutPassCount for event in events { harness.engine.send(event) } try harness.scheduler.runReady()
#expect(harness.engine.layoutPassCount == passes + 1) #expect(harness.engine.snapshot.state == expected.state) #expect(harness.scheduler.pendingCount == 1) try harness.scheduler.runNext() for tile in harness.engine.snapshot.tiles { #expect(harness.world.frames[tile.window] == tile.frame) } #expect(harness.engine.isIdle) await harness.engine.stop() }}