Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174import CoreGraphicsimport Foundationimport ParcelConfigimport ParcelCoreimport ParcelIPCimport ParcelUIimport Testing
@testable import ParcelApp@testable import ParcelTestSupport
@Suite @MainActorstruct CoreCommandFixtureInputTests { @Test func liveConfigurationMakesOverflowAnExplicitChoice() throws { var configuration = E2EConfiguration() let unlimited = try TOMLParser.parse(configuration.source) #expect(ConfigValidator.validate(unlimited).configuration?.layout.global.windowCap == 0) configuration.windowCap = nil let defaults = try TOMLParser.parse(configuration.source) #expect(ConfigValidator.validate(defaults).configuration?.layout.global.windowCap == 3) }
@Test(arguments: [[:], ["PARCEL_E2E": "0"], ["PARCEL_E2E": "true"], ["PARCEL_E2E": "1 "]]) func rejectsKeyboardInputOutsideExplicitE2EMode(environment: [String: String]) { #expect(throws: IPCError.self) { try AppFixtureKeyInput(arguments: ["7", ConfigCommand.stack.rawValue], environment: environment) } }
@Test(arguments: [ [], ["7"], ["0", "stack"], ["-1", "stack"], ["4294967296", "stack"], ["7", "unknown-command"], ["7", "stack", "extra"], ["7", String(repeating: "x", count: 129)], ]) func rejectsMalformedKeyboardRequests(arguments: [String]) { #expect(throws: IPCError.self) { try AppFixtureKeyInput(arguments: arguments, environment: ["PARCEL_E2E": "1"]) } }
@Test func parsesCommandsAndUsesOnlyTheirActiveRegisteredBindings() throws { let request = try AppFixtureKeyInput( arguments: ["7", ConfigCommand.stack.rawValue], environment: ["PARCEL_E2E": "1"]) #expect(request.window == WindowID(rawValue: 7)) #expect(request.command == .stack) let bindings = ParcelConfiguration.defaults.keybindings let configured = try #require(bindings[.stack]) #expect(throws: IPCError.self) { try AppFixtureKeyInput(arguments: ["7", configured.description], environment: ["PARCEL_E2E": "1"]) } #expect(try request.chord(activeBindings: bindings) == configured) #expect(throws: IPCError.self) { try request.chord(activeBindings: [:]) } let counted = try AppFixtureKeyInput( arguments: ["7", "set-window-cap 2"], environment: ["PARCEL_E2E": "1"]) #expect(counted.command.rawValue == "set-window-cap 2") #expect(try counted.chord(activeBindings: bindings) == bindings[counted.command]) }
@Test func keyboardTargetMustBeManagedFocusedAndOnAnActiveWorkspace() throws { let request = try AppFixtureKeyInput(arguments: ["7", "stack"], environment: ["PARCEL_E2E": "1"]) let display = DisplayID(rawValue: "fixture-display") let space = SpaceID(rawValue: 1) let key = WorkspaceKey(display: display, space: space) let window = ManagedWindow(id: request.window, app: AppID(pid: 123, bundleID: "fixture")) let state = State( displays: [Display(id: display, frame: Rect(width: 1200, height: 800))], activeSpaces: [display: space], workspaces: [key: Workspace(key: key, order: [request.window])], windows: [request.window: window], focusedWindow: request.window) #expect(try request.targetPID(state: state) == 123) var unfocused = state unfocused.focusedWindow = nil #expect(throws: IPCError.self) { try request.targetPID(state: unfocused) } var inactive = state inactive.activeSpaces[display] = SpaceID(rawValue: 2) #expect(throws: IPCError.self) { try request.targetPID(state: inactive) } var unmanaged = state unmanaged.windows = [:] #expect(throws: IPCError.self) { try request.targetPID(state: unmanaged) } }
@Test func keyboardPostingRejectsOtherApplicationsAndBackgroundOrTerminatedFixtures() throws { try AppFixtureKeyInput.requireFrontmostFixture( pid: 123, executableName: "FixtureApp", frontmostPID: 123, terminated: false) let names: [String?] = [nil, "Parcel", "UnrelatedApp"] for name in names { #expect(throws: IPCError.self) { try AppFixtureKeyInput.requireFrontmostFixture( pid: 123, executableName: name, frontmostPID: 123, terminated: false) } } #expect(throws: IPCError.self) { try AppFixtureKeyInput.requireFrontmostFixture( pid: 123, executableName: "FixtureApp", frontmostPID: 456, terminated: false) } #expect(throws: IPCError.self) { try AppFixtureKeyInput.requireFrontmostFixture( pid: 123, executableName: "FixtureApp", frontmostPID: 123, terminated: true) } }
@Test func keyboardEventsUseConfiguredPhysicalKeysWithoutRepeating() throws { let chord = try #require(ParcelConfiguration.defaults.keybindings[.stack]) let events = try AppFixtureKeyInput.events(chord: chord, pid: 123) #expect(events.map(\.type) == [.keyDown, .keyUp]) let expectedFlags = NativeAppRuntime.hotkey(chord).modifiers.eventFlags #expect(events[0].flags == expectedFlags) #expect(events[1].flags.isEmpty) for event in events { #expect(event.getIntegerValueField(.keyboardEventKeycode) == Int64(chord.keyCode)) #expect(event.getIntegerValueField(.eventTargetUnixProcessID) == 123) #expect(event.getIntegerValueField(.keyboardEventAutorepeat) == 0) } }
@Test func injectedModifierRecoveryRequiresTheExactExplicitFixtureCommand() throws { let command = ConfigCommand.setWindowCap(2) let chord = try #require(ParcelConfiguration.defaults.keybindings[command]) let flags = NativeAppRuntime.hotkey(chord).modifiers.eventFlags let environment = [ "PARCEL_E2E": "1", "PARCEL_E2E_TOKEN": "fixture-token", "PARCEL_E2E_RECOVER_INJECTED_COMMAND": command.rawValue, ] #expect( AppFixtureKeyInput.canRecoverInjectedModifiers( command: command, chord: chord, environment: environment, flags: flags, heldKeys: [55, 58, 59])) for key in ["PARCEL_E2E", "PARCEL_E2E_TOKEN", "PARCEL_E2E_RECOVER_INJECTED_COMMAND"] { var missing = environment missing[key] = nil #expect( !AppFixtureKeyInput.canRecoverInjectedModifiers( command: command, chord: chord, environment: missing, flags: flags, heldKeys: [55, 58, 59])) } #expect( !AppFixtureKeyInput.canRecoverInjectedModifiers( command: command, chord: chord, environment: environment, flags: .maskShift, heldKeys: [56])) #expect( !AppFixtureKeyInput.canRecoverInjectedModifiers( command: command, chord: chord, environment: environment, flags: flags, heldKeys: [55, 58, 59, 0])) #expect( !AppFixtureKeyInput.canRecoverInjectedModifiers( command: command, chord: chord, environment: environment, flags: flags, heldKeys: [])) }
@Test(arguments: [ [], ["display"], ["", "2"], ["display", "0"], ["display", "6"], ["display", "two"], ["display", "2", "extra"], ]) func fixtureMenuRejectsMalformedTargetsWithAnArgumentFailure(arguments: [String]) { #expect(throws: AppFixtureMenuFailure(stage: .arguments)) { try AppFixtureMenuFailure.windowCount(arguments) } }
@Test(arguments: [1, 5]) func fixtureMenuAcceptsItsSupportedWindowCountBounds(count: Int) throws { #expect(try AppFixtureMenuFailure.windowCount(["display", String(count)]) == count) }
@Test func fixtureMenuFailuresExplainTheFailedStageInsteadOfReopeningTheTour() { let messages = AppFixtureMenuFailure.Stage.allCases.map { AppFixtureMenuFailure(stage: $0).localizedDescription } #expect(Set(messages).count == AppFixtureMenuFailure.Stage.allCases.count) #expect(messages.allSatisfy { !$0.isEmpty && !$0.contains("Reopen the tour") }) #expect(AppFixtureMenuFailure(stage: .presentation).localizedDescription.contains("five seconds")) #expect(AppFixtureMenuFailure(stage: .selectionDispatch).localizedDescription.contains("scheduled selection")) #expect(AppFixtureMenuFailure(stage: .capture).localizedDescription.contains("captured")) }
@Test func missingKeyboardPosterRejectsWithoutLaunchingOrSendingInput() async { let handler = AppIPCHandler( services: EngineShellServices(), configPath: "/tmp/unused-fixture.toml", permission: { true }) await #expect(throws: IPCError.self) { try await handler.run(command: "e2e-key", args: ["7", "stack"]) } }}