Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197import Foundationimport ParcelCoreimport ParcelEngineimport Testing
@Suite @MainActorstruct SuspendedCommandTests { @Test(arguments: DisplaySuspension.Reason.allCases) func commandsOnASuspendedDisplayFailBeforeChangingTheLayout(reason: DisplaySuspension.Reason) async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) let before = harness.engine.snapshot.state let writes = harness.world.allWrites let suspension = DisplaySuspension(display: engineDisplay, reason: reason, since: .now) harness.world.emit(.displaySuspensionsChanged([suspension])) harness.world.emit(.suspendedDisplaysChanged([engineDisplay])) var failures: [EngineCommandSuspensionError] = [] harness.engine.onFailure = { if let failure = $0 as? EngineCommandSuspensionError { failures.append(failure) } } do { _ = try await harness.engine.perform(.swap(.right)) Issue.record("Suspended display accepted a swap") } catch let failure as EngineCommandSuspensionError { #expect(failure.display == engineDisplay) #expect(failure.reason == reason) #expect(failure.errorDescription == suspension.status) } #expect(failures.count == 1) #expect(harness.engine.snapshot.state.frames == before.frames) #expect(harness.engine.snapshot.state.workspaces == before.workspaces) #expect(harness.world.allWrites == writes) harness.world.emit(.suspendedDisplaysChanged([])) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.frames == before.frames) #expect(harness.world.allWrites == writes) await harness.engine.stop() }
@Test func verifiedNativeFullscreenExitIsAllowedWhileTilePlacementIsSuspended() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) var fullscreen = engineWindow(99) fullscreen.facts = WindowFacts(bundleID: engineApp.bundleID, role: "AXWindow", isFullScreen: true) harness.world.commandWindow = fullscreen let before = harness.engine.snapshot.state let writes = harness.world.allWrites harness.world.emit( .displaySuspensionsChanged([ DisplaySuspension(display: engineDisplay, reason: .fullscreenSpace, since: .now) ])) harness.world.emit(.suspendedDisplaysChanged([engineDisplay])) _ = try await harness.engine.perform(.toggleFullscreen) #expect(harness.world.fullscreenToggles == [fullscreen.id]) #expect(harness.engine.snapshot.state.workspaces == before.workspaces) #expect(harness.world.allWrites == writes) await harness.engine.stop() }
@Test(arguments: DisplaySuspension.Reason.allCases.filter { $0 != .fullscreenSpace }) func nativeFullscreenExitStillRejectsEveryOtherUnsafeReason(reason: DisplaySuspension.Reason) async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1]) var fullscreen = engineWindow(99) fullscreen.facts = WindowFacts(bundleID: engineApp.bundleID, role: "AXWindow", isFullScreen: true) harness.world.commandWindow = fullscreen harness.world.emit( .displaySuspensionsChanged([ DisplaySuspension(display: engineDisplay, reason: .fullscreenSpace, since: .now), DisplaySuspension(display: engineDisplay, reason: reason, since: .now), ])) harness.world.emit(.suspendedDisplaysChanged([engineDisplay])) do { _ = try await harness.engine.perform(.toggleFullscreen) Issue.record("Native fullscreen exit ignored an unsafe display state") } catch let failure as EngineCommandSuspensionError { #expect(failure.reason == reason) } #expect(harness.world.fullscreenToggles.isEmpty) await harness.engine.stop() }
@Test(arguments: ["entry", "unverified", "close", "unknown-suspension"]) func fullscreenSuspensionExemptionRequiresAVerifiedExit(scenario: String) async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1]) var window = engineWindow(99) window.facts = WindowFacts( bundleID: engineApp.bundleID, role: "AXWindow", isFullScreen: scenario != "entry") if scenario != "unverified" { harness.world.commandWindow = window } if scenario != "unknown-suspension" { harness.world.emit( .displaySuspensionsChanged([ DisplaySuspension(display: engineDisplay, reason: .fullscreenSpace, since: .now) ])) } harness.world.emit(.suspendedDisplaysChanged([engineDisplay])) await #expect(throws: EngineCommandSuspensionError.self) { try await harness.engine.perform(scenario == "close" ? .close : .toggleFullscreen) } #expect(harness.world.fullscreenToggles.isEmpty) #expect(harness.world.closed.isEmpty) await harness.engine.stop() }
@Test func workspaceAndPhysicalWindowCommandsRespectTheirDisplayGate() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) harness.world.emit(.suspendedDisplaysChanged([engineDisplay])) await #expect(throws: EngineCommandSuspensionError.self) { try await harness.engine.perform(.setLayout(.rows), in: engineWorkspace) } await #expect(throws: EngineCommandSuspensionError.self) { try await harness.engine.perform(.toggleFloat, targeting: WindowID(rawValue: 1)) } await harness.engine.stop() }
@Test(arguments: [ Command.focus(.right), .swap(.right), .move(.right), .stack(.right), .moveToDisplay(.right), .snap(.nextDisplay), .snap(.previousDisplay), ]) func crossDisplayCommandsRejectASuspendedDestination(command: Command) async throws { let harness = try EngineHarness(initialState: engineInitialState(twoDisplays: true)) try await harness.start() try harness.add([1]) let destination = WorkspaceKey(display: secondEngineDisplay, space: SpaceID(rawValue: 2)) try harness.add([2], app: secondEngineApp, workspace: destination) harness.engine.send(.focusChanged(WindowID(rawValue: 1))) try harness.scheduler.runReady() harness.world.emit(.suspendedDisplaysChanged([secondEngineDisplay])) let before = harness.engine.snapshot.state.frames do { _ = try await harness.engine.perform(command) Issue.record("Command accepted a suspended destination") } catch let failure as EngineCommandSuspensionError { #expect(failure.display == secondEngineDisplay) } #expect(harness.engine.snapshot.state.workspace(containing: WindowID(rawValue: 1)) == engineWorkspace) #expect(harness.engine.snapshot.state.frames == before) await harness.engine.stop() }
@Test(arguments: [Command.snap(.restore), .undo]) func restoringACrossDisplayEditRejectsTheSuspendedOriginalDisplay(command: Command) async throws { let harness = try EngineHarness(initialState: engineInitialState(twoDisplays: true)) try await harness.start() let original = WorkspaceKey(display: secondEngineDisplay, space: SpaceID(rawValue: 2)) let window = WindowID(rawValue: 1) try harness.add([1], workspace: original) harness.engine.send(.focusChanged(window)) harness.engine.send(.commandIssued(.snap(.nextDisplay))) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.workspace(containing: window) == engineWorkspace) harness.world.emit(.suspendedDisplaysChanged([secondEngineDisplay])) await #expect(throws: EngineCommandSuspensionError.self) { try await harness.engine.perform(command) } #expect(harness.engine.snapshot.state.workspace(containing: window) == engineWorkspace) await harness.engine.stop() }
@Test func aQueuedFocusChangeIsAppliedBeforeTheFollowingCommandChecksSuspension() async throws { let harness = try EngineHarness(initialState: engineInitialState(twoDisplays: true)) try await harness.start() try harness.add([1]) let destination = WorkspaceKey(display: secondEngineDisplay, space: SpaceID(rawValue: 2)) try harness.add([2, 3], app: secondEngineApp, workspace: destination) harness.engine.send(.focusChanged(WindowID(rawValue: 1))) try harness.scheduler.runReady() let before = harness.engine.snapshot.state.workspaces[destination] harness.world.emit(.suspendedDisplaysChanged([secondEngineDisplay])) var failures: [EngineCommandSuspensionError] = [] harness.engine.onFailure = { if let failure = $0 as? EngineCommandSuspensionError { failures.append(failure) } } harness.engine.send(.focusChanged(WindowID(rawValue: 2))) harness.engine.send(.commandIssued(.setLayout(.rows))) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.activeDisplay == secondEngineDisplay) #expect(harness.engine.snapshot.state.workspaces[destination]?.layout == before?.layout) #expect(failures.first?.display == secondEngineDisplay) await harness.engine.stop() }
@Test func aCommandQueuedBeforeSuspensionCannotMutateTheModelAfterward() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) let before = harness.engine.snapshot.state.frames harness.engine.send(.commandIssued(.swap(.right))) harness.world.emit(.suspendedDisplaysChanged([engineDisplay])) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.frames == before) await harness.engine.stop() }}