Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233import Foundationimport ParcelConfigimport ParcelUIimport Testing
@testable import ParcelRealityTests
struct RealityFixtureTests { @Test(arguments: [false, true]) func finderPopulationPreservesMetadataAndAcceptsDirectoryURLMarkers(metadata: Bool) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() let folder = root.appendingPathComponent("owned-folder") try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let data = Data("Finder metadata".utf8) let store = folder.appendingPathComponent(".DS_Store") if metadata { try data.write(to: store) } let input = URL(fileURLWithPath: folder.path, isDirectory: !metadata) let names = try RealApps.populateFinderFolder(input, in: root) #expect(names == (1...12).map { "Owned item \($0).txt" }.sorted()) if metadata { #expect(try Data(contentsOf: store) == data) } }
@Test(arguments: [false, true]) func finderPopulationRefusesNonemptyAndRedirectedFolders(redirected: Bool) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() let folder = root.appendingPathComponent("owned-folder") let target = root.appendingPathComponent("target") try FileManager.default.createDirectory(at: target, withIntermediateDirectories: true) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let data = Data("Keep this file".utf8) if redirected { try FileManager.default.createSymbolicLink(at: folder, withDestinationURL: target) } else { try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: false) try data.write(to: folder.appendingPathComponent("existing.txt")) } #expect(throws: RealityError.self) { try RealApps.populateFinderFolder(folder, in: root) } #expect(try FileManager.default.contentsOfDirectory(atPath: target.path).isEmpty) if !redirected { #expect(try Data(contentsOf: folder.appendingPathComponent("existing.txt")) == data) } }
@Test func receiptRequiresMatchingNativeKeyDownAndUp() throws { let receipt = try JSONDecoder().decode( RealityFixtureReply.self, from: Data( """ {"id":"test","pid":42,"inputEvents":[ {"key":124,"down":true,"flags":0,"windowID":7,"timestamp":1}, {"key":124,"down":false,"flags":0,"windowID":7,"timestamp":2}]} """.utf8)) #expect(try receipt.received(124, windowID: 7)) #expect(try !receipt.received(123, windowID: 7)) #expect(try !receipt.received(124, windowID: 8)) }
@Test(arguments: [ "{\"id\":\"test\",\"pid\":42}", "{\"id\":\"test\",\"pid\":42,\"overflow\":true,\"inputEvents\":[]}", "{\"id\":\"test\",\"pid\":42,\"error\":\"recorder failed\",\"inputEvents\":[]}", ]) func incompleteAndFailedRecordersCannotProveDelivery(_ source: String) throws { let receipt = try JSONDecoder().decode(RealityFixtureReply.self, from: Data(source.utf8)) #expect(throws: RealityError.self) { try receipt.received(124, windowID: 7) } }
@Test(arguments: [ "Parcel couldn’t check setup. Try again.", "Parcel konnte die Einrichtung nicht prüfen. Versuchen Sie es erneut.", ]) func onlyStructuredUnavailableCanBeRetriedDuringFirstRunReadiness(_ message: String) { let unavailable = "Error: Parcel rejected the command (tour_unavailable): \(message)\n" #expect(TourFirstRunReadiness.isUnavailable(CommandOutput(status: 1, output: "", errors: unavailable))) let otherFailures = [ CommandOutput(status: 0, output: "", errors: unavailable), CommandOutput(status: 2, output: "", errors: unavailable), CommandOutput(status: 1, output: "unexpected output", errors: unavailable), CommandOutput(status: 1, output: "", errors: "(handler_error): a different product failure"), CommandOutput(status: 1, output: "", errors: "(tour_unavailable)"), CommandOutput( status: 1, output: "", errors: "(handler_error): \(TourSetupFailure.unavailable.localizedDescription)"), CommandOutput( status: 1, output: "", errors: "(engine_stopped): \(TourSetupFailure.unavailable.localizedDescription)"), CommandOutput(status: 1, output: "", errors: "another failure\n\(unavailable)"), ] for result in otherFailures { #expect(!TourFirstRunReadiness.isUnavailable(result)) } }
@Test(arguments: [ "valid", "background", "hidden", "busy", "wrong-step", "tidied", "missing-window", "zero-window", "multiple-windows", "feedback-window", "missing-text", ]) func firstRunWelcomeRequiresRenderedNativeWindow(_ state: String) throws { let visible = state == "missing-text" ? "[]" : "[\"Welcome\"]" let number = state == "zero-window" ? "0" : "42" let window = "{\"number\":\(number),\"visible\":true,\"canBecomeKey\":true,\"canBecomeMain\":true,\"width\":440,\"height\":394}" let feedback = "{\"number\":43,\"visible\":true,\"canBecomeKey\":true,\"canBecomeMain\":false,\"width\":320,\"height\":116}" let windows = switch state { case "missing-window": "[]" case "multiple-windows": "[\(window),\(window)]" case "feedback-window": "[\(window),\(feedback)]" default: "[\(window)]" } let key = state == "background" ? "null" : "42" let status = try JSONDecoder().decode( TourFirstRunStatus.self, from: Data( """ {"presented":\(state != "hidden"),"step":"\(state == "wrong-step" ? "ready" : "welcome")", "intent":"automatic","canContinue":true,"isBusy":\(state == "busy"),"didTidy":\(state == "tidied"), "skippedApplications":[],"visibleSetupText":\(visible),"keyWindowNumber":\(key), "nativeWindows":\(windows),"noticeIsVisible":false} """.utf8)) #expect(status.isVisibleWelcome == (["valid", "background", "feedback-window"].contains(state))) }
@Test func firstRunScenarioIsListedExactlyOnce() { #expect(RealityScenario.all.filter { $0.name == "tour-first-run-unresponsive" }.count == 1) }
@Test(arguments: ["tour-native-manual", "tour-native-replay-on", "tour-native-replay-off"]) func unverifiedTourSelectorsRemainExplicitCoverageGaps(_ name: String) throws { let scenario = try #require(RealityScenario.all.first { $0.name == name }) #expect(scenario.coverageBlocker != nil) #expect(!RealityScenario.supported.contains { $0.name == name }) #expect(scenario.skipStatus(explicitlyRequested: true) == .skip) }
@Test(arguments: [ "valid", "missing-headline", "missing-safety-copy", "notice-only", "hidden", "busy", "tidied", "wrong-step", "partial", "missing-terminal", ]) func unknownDiscoveryRequiresVisibleFailureBeforeWriteSafetyCopy(_ state: String) throws { var text = ["Parcel couldn’t arrange your windows.", "Your windows haven’t moved. Automatic tiling is off."] if state == "missing-headline" { text.removeFirst() } if state == "missing-safety-copy" { text.removeLast() } if state == "notice-only" { text = [] } let visible = String(decoding: try JSONEncoder().encode(text), as: UTF8.self) let terminal = state == "missing-terminal" ? "null" : "\"\(state == "partial" ? "partial" : "failed-before-write")\"" let status = try JSONDecoder().decode( TourFirstRunStatus.self, from: Data( """ {"presented":\(state != "hidden"),"step":"\(state == "wrong-step" ? "welcome" : "ready")", "intent":"automatic","canContinue":true,"isBusy":\(state == "busy"),"didTidy":\(state == "tidied"),"terminal":\(terminal), "visibleSetupText":\(visible),"noticeTitle":"Your windows haven’t moved. Automatic tiling is off.","noticeIsVisible":true} """.utf8)) if state == "valid" { try status.requireFailedBeforeWrite() } else { #expect(throws: RealityError.self) { try status.requireFailedBeforeWrite() } } }
@Test(arguments: ["missing-window", "wrong-owner", "offscreen", "collapsed", "overflow", "terminal-too-small"]) func firstRunGridCannotPassOnPartialOrIncorrectCGFrames(_ failure: String) throws { let visible = ScreenRect(x: 0, y: 38, width: 1600, height: 900) let gaps = LayoutGaps(inner: 12, outer: 16) let owned = [ OwnedWindow(app: .finder, pid: 2, id: 2), OwnedWindow(app: .finder, pid: 2, id: 3), OwnedWindow(app: .textEdit, pid: 4, id: 4), OwnedWindow(app: .terminal, pid: 5, id: 5), ] var slots = TourFirstRunOracle.gridSlots(visible: visible, gaps: gaps) if failure == "collapsed" { slots[1] = slots[0] } if failure == "overflow" { slots[0].width += 1 } if failure == "terminal-too-small" { slots[3].width -= 11 } var rows = zip(owned, slots).map { RealWindow(id: $0.id, pid: $0.pid, frame: $1, layer: 0, onscreen: true, alpha: 1) } if failure == "missing-window" { rows.removeLast() } if failure == "wrong-owner" { rows[0] = RealWindow(id: 2, pid: 99, frame: slots[0], layer: 0, onscreen: true, alpha: 1) } if failure == "offscreen" { rows[0] = RealWindow(id: 2, pid: 2, frame: slots[0], layer: 0, onscreen: false, alpha: 1) } let terminal = try #require(owned.last) let increment = ResizeIncrement(width: 10, height: 16, source: "test") if ["missing-window", "wrong-owner", "offscreen"].contains(failure) { #expect(throws: RealityError.self) { try TourFirstRunOracle.grid( rows, owned: owned, visible: visible, gaps: gaps, terminal: terminal, increment: increment) } } else { #expect( try !TourFirstRunOracle.grid( rows, owned: owned, visible: visible, gaps: gaps, terminal: terminal, increment: increment)) } }
@Test func firstRunGridAcceptsContainedMeasuredTerminalIncrementAndArbitraryRanks() throws { let visible = ScreenRect(x: 0, y: 38, width: 1600, height: 900) let gaps = LayoutGaps(inner: 12, outer: 16) let owned = [ OwnedWindow(app: .finder, pid: 2, id: 2), OwnedWindow(app: .finder, pid: 2, id: 3), OwnedWindow(app: .textEdit, pid: 4, id: 4), OwnedWindow(app: .terminal, pid: 5, id: 5), ] var slots = Array(TourFirstRunOracle.gridSlots(visible: visible, gaps: gaps).reversed()) slots[3].width -= 8 slots[3].height -= 12 let rows = zip(owned, slots).map { RealWindow(id: $0.id, pid: $0.pid, frame: $1, layer: 0, onscreen: true, alpha: 1) } #expect( try TourFirstRunOracle.grid( rows, owned: owned, visible: visible, gaps: gaps, terminal: #require(owned.last), increment: ResizeIncrement(width: 10, height: 16, source: "test"))) }
@Test func fixtureArtifactMustBeAnExactOwnedBundle() throws { let root = URL(fileURLWithPath: "/tmp/parcel-fixture-artifact-tests") let url = root.appendingPathComponent("fixture-\(UUID().uuidString).app") #expect(try RealAppOwnedArtifact(url: url, kind: .fixtureBundle).cleanupURL(in: root) == url) let foreign = root.appendingPathComponent("FixtureApp.app") #expect(throws: RealityError.self) { try RealAppOwnedArtifact(url: foreign, kind: .fixtureBundle).cleanupURL(in: root) } }}