import Foundation import ParcelConfig import ParcelCore import RealityDriverSupport import Testing @testable import ParcelRealityTests @Suite @MainActor struct RealityConfigurationTests { @Test(arguments: [LayoutGaps(), RealityGeometry.defaultGaps, LayoutGaps(inner: 18, outer: 22)]) func explicitStimulusAndOraclesUseTheSameConfiguredGaps(_ requested: LayoutGaps) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let visible = ScreenRect(x: 0, y: 38, width: 1600, height: 900) let session = try RealitySession( directory: root, appURL: URL(fileURLWithPath: "/tmp/nonexistent.app"), visible: visible, inputBaseline: DriverInputState(heldKeys: [], flags: 0)) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } try session.configure(outerGap: requested.outer, innerGap: requested.inner) let saved = try session.configuredLayout().gaps #expect(saved == requested) let frames = FrameOracle.stripes(count: 2, visible: visible, vertical: true, gaps: saved) #expect(frames[0].width == (visible.width - 2 * requested.outer - requested.inner) / 2) #expect( FrameOracle.stripeShape( frames, visible: visible, vertical: true, inner: saved.inner, outer: saved.outer)) #expect(CoverageOracle.repairedGap(frames, visible: visible, gaps: saved)) } @Test(arguments: [nil, "", "screen", "screen 1", "screen 41", "screen 42 extra"] as [String?]) func missingScreenOwnershipSkipsOnlyTheCurrentScenario(_ owner: String?) throws { do { try RealityScreenPrecondition.requireOwner(owner, parentPID: 42) Issue.record("Missing screen ownership was accepted") } catch let skip as RealitySkip { #expect(!RealityLaneDecision.afterScenario(failures: [skip], cleanupFailed: false).stopsLane) } } @Test(arguments: ["screen 42", "screen 42\n", "screen\t42\n"]) func screenOwnerAllowsTheExistingLockWithoutAnExternalMarker(_ owner: String) throws { try RealityScreenPrecondition.requireOwner(owner, parentPID: 42) } @Test func runningParcelInstancesBlockRealityRuns() throws { try RealityMain.rejectRunningInstances(0) #expect(throws: RealityError.self) { try RealityMain.rejectRunningInstances(1) } #expect(throws: RealityError.self) { try RealityMain.rejectRunningInstances(2) } } @Test(arguments: ["grid", "columns", "rows", "side", "tree", "bsp", "accordion"]) func generatedConfigIsValidAndOwnsOnlyTokenDocuments(_ layout: String) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let session = try RealitySession( directory: root, appURL: URL(fileURLWithPath: "/tmp/Parcel.app"), visible: ScreenRect(x: 0, y: 25, width: 1600, height: 900), inputBaseline: DriverInputState(heldKeys: [], flags: 0)) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } try session.configure(layout: layout, cap: 0, memory: true, minSize: true) let source = try String(contentsOf: session.config, encoding: .utf8) let result = ConfigValidator.validate(try TOMLDocument(parsing: source)) #expect(result.diagnostics.isEmpty) let configuration = try #require(result.configuration) #expect(configuration.layout.global.defaultLayout.rawValue == layout) #expect(configuration.layout.global.windowCap == 0) #expect(configuration.layout.global.gaps.inner == 12) #expect(configuration.layout.global.gaps.outer == 16) #expect(configuration.memory.enabled) #expect(!configuration.motion.enabled) #expect(configuration.keybindings[.tabView] == DefaultKeybindings.bindings()[.tabView]) for bundle in session.ignoredBundles { #expect(configuration.rules.contains { $0.bundleID == bundle && $0.action == .ignore }) } let documentRules = configuration.rules.filter { $0.titleContains == session.apps.token } #expect( Set(documentRules.compactMap(\.bundleID)) == Set([ "com.apple.TextEdit", "com.apple.finder", "com.apple.Safari", "org.mozilla.firefox", "org.chromium.Chromium", "com.microsoft.VSCode", "com.apple.Terminal", "dev.vinnymac.parcel.reality-fixture", ])) #expect(documentRules.allSatisfy { $0.action == .tile }) #expect(configuration.rules.last?.bundleID == "com.apple.systempreferences") #expect(configuration.rules.last?.action == .tile) } @Test(arguments: [0.1, 2.0]) func motionScenarioConfigEnablesTheRequestedSpeed(_ speed: Double) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let session = try RealitySession( directory: root, appURL: URL(fileURLWithPath: "/tmp/Parcel.app"), visible: ScreenRect(x: 0, y: 25, width: 1600, height: 900), inputBaseline: DriverInputState(heldKeys: [], flags: 0)) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } try session.configure(motionEnabled: true, motionSpeed: speed) let result = ConfigValidator.validate( try TOMLDocument(parsing: String(contentsOf: session.config, encoding: .utf8))) #expect(result.diagnostics.isEmpty) let configuration = try #require(result.configuration) #expect(configuration.motion.enabled) #expect(configuration.motion.speed == speed) #expect(configuration.motion.level == .playful) #expect(configuration.motion.transitions == .glide) #expect(RealityScenario.all.contains { $0.name == "motion-speed" }) } @Test(arguments: ConfigReloadGeometry.sequence) func reloadScenarioGeneratesValidGeometry(geometry: ConfigReloadGeometry) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let session = try RealitySession( directory: root, appURL: URL(fileURLWithPath: "/tmp/Parcel.app"), visible: ScreenRect(x: 0, y: 38, width: 1600, height: 900), inputBaseline: DriverInputState(heldKeys: [], flags: 0)) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } try session.configure(outerGap: geometry.outerGap, reservedTop: geometry.reservedTop) let result = ConfigValidator.validate( try TOMLDocument(parsing: String(contentsOf: session.config, encoding: .utf8))) #expect(result.diagnostics.isEmpty) let configuration = try #require(result.configuration) #expect(configuration.layout.global.gaps.outer == geometry.outerGap) #expect(configuration.layout.global.reserved.top == geometry.reservedTop) #expect(configuration.layout.global.reserved.bottom == 0) #expect(!configuration.memory.enabled && !configuration.motion.enabled) } @Test func reloadGeometryRejectsEarlierFramesAndRestoresOriginalTargets() { let visible = ScreenRect(x: 0, y: 38, width: 1600, height: 900) let sequence = ConfigReloadGeometry.sequence.map { $0.columns(count: 2, visible: visible) } #expect(sequence[0] != sequence[1]) #expect(sequence[1] != sequence[2]) #expect(sequence[0] == sequence[3]) #expect(sequence[3] != sequence[4]) #expect(sequence[0] == sequence[5]) #expect(sequence[0][0] == ScreenRect(x: 16, y: 54, width: 778, height: 868)) #expect(RealityScenario.all.contains { $0.name == "config-reload" }) } @Test(arguments: [false, true]) func configTransactionRestoresBytesPermissionsOrAbsence(existing: Bool) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let storage = try RealityStorage(parent: root) let file = storage.fileURL("parcel.toml") let original = Data("original configuration\n".utf8) if existing { try original.write(to: file) try FileManager.default.setAttributes([.posixPermissions: 0o640], ofItemAtPath: file.path) } let transaction = try RealityConfigTransaction(storage: storage, directory: root) for text in ["A", "B", "A"] { try transaction.write(Data(text.utf8)) } try transaction.restore() if existing { #expect(try Data(contentsOf: file) == original) #expect( (try FileManager.default.attributesOfItem(atPath: file.path)[.posixPermissions] as? NSNumber)?.intValue == 0o640) } else { #expect(!FileManager.default.fileExists(atPath: file.path)) } #expect(FileManager.default.fileExists(atPath: root.appendingPathComponent("config-restoration.json").path)) } @Test(arguments: [false, true]) func configTransactionRefusesExternalEditsOrReplacement(replacement: Bool) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let storage = try RealityStorage(parent: root) let file = storage.fileURL("parcel.toml") let transaction = try RealityConfigTransaction(storage: storage, directory: root) try transaction.write(Data("A".utf8)) let external = Data((replacement ? "A" : "external edit").utf8) try external.write(to: file, options: replacement ? .atomic : []) #expect(throws: RealityError.self) { try transaction.write(Data("B".utf8)) } #expect(throws: RealityError.self) { try transaction.restore() } #expect(try Data(contentsOf: file) == external) } @Test func configTransactionRefusesSymbolicAndHardLinks() throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let original = root.appendingPathComponent("original.toml") try Data("original".utf8).write(to: original) let storage = try RealityStorage(parent: root) let file = storage.fileURL("parcel.toml") try FileManager.default.createSymbolicLink(at: file, withDestinationURL: original) #expect(throws: RealityError.self) { try RealityConfigTransaction(storage: storage, directory: root) } try FileManager.default.removeItem(at: file) try FileManager.default.linkItem(at: original, to: file) #expect(throws: RealityError.self) { try RealityConfigTransaction(storage: storage, directory: root) } #expect(try Data(contentsOf: original) == Data("original".utf8)) } @Test func motionSpeedReceiptRequiresTheRunningEngineConfiguration() throws { let config = URL(fileURLWithPath: "/tmp/motion-isolated/parcel.toml") let source = #"{"path":"/tmp/motion-isolated/parcel.toml","running":true,"motion":{"enabled":true,"level":"playful","speed":2,"transitions":"glide"}}"# let receipt = try JSONDecoder().decode(MotionSpeedRuntimeReceipt.self, from: Data(source.utf8)) try receipt.requireApplied(config: config, speed: 2) #expect(throws: RealityError.self) { try receipt.requireApplied(config: config, speed: 0.1) } #expect(throws: RealityError.self) { try receipt.requireApplied(config: URL(fileURLWithPath: "/tmp/wrong.toml"), speed: 2) } } @Test func motionSpeedOracleRequiresIntermediateFramesAndConvergence() throws { let from = [ScreenRect(x: 0, y: 0, width: 300, height: 400)] let middle = [ScreenRect(x: 150, y: 0, width: 300, height: 400)] let to = [ScreenRect(x: 300, y: 0, width: 300, height: 400)] let samples = [ MotionSpeedSample(elapsedSeconds: 0, frames: from), MotionSpeedSample(elapsedSeconds: 0.1, frames: middle), MotionSpeedSample(elapsedSeconds: 0.2, frames: to), MotionSpeedSample(elapsedSeconds: 0.21, frames: to), MotionSpeedSample(elapsedSeconds: 0.22, frames: to), ] #expect(try MotionSpeedOracle.duration(samples: samples, from: from, to: to) == 0.1) #expect(throws: RealityError.self) { try MotionSpeedOracle.duration(samples: [samples[0]] + samples.suffix(3), from: from, to: to) } #expect(throws: RealityError.self) { try MotionSpeedOracle.duration(samples: Array(samples.dropLast()), from: from, to: to) } #expect(throws: RealityError.self) { try MotionSpeedOracle.duration(samples: samples, from: from, to: from) } let stalled = [ samples[0], samples[1], MotionSpeedSample(elapsedSeconds: 1, frames: to), MotionSpeedSample(elapsedSeconds: 1.01, frames: to), MotionSpeedSample(elapsedSeconds: 1.02, frames: to), ] #expect(throws: RealityError.self) { try MotionSpeedOracle.duration(samples: stalled, from: from, to: to) } } @Test func motionSpeedOracleRejectsNoDifferenceAndInsufficientSlowMotion() throws { try MotionSpeedOracle.requireSpeedDifference(fast: 0.1, slow: 1.0) #expect(throws: RealityError.self) { try MotionSpeedOracle.requireSpeedDifference(fast: 0.1, slow: 0.1) } #expect(throws: RealityError.self) { try MotionSpeedOracle.requireSpeedDifference(fast: 0.1, slow: 0.4) } #expect(throws: RealityError.self) { try MotionSpeedOracle.requireSpeedDifference(fast: 0.4, slow: 0.7) } #expect(throws: RealityError.self) { try MotionSpeedOracle.requireSpeedDifference(fast: .nan, slow: 1) } } @Test(arguments: [false, true]) func automaticTilingCommandReceiptDecodesTheReturnedState(enabled: Bool) throws { let source = "{\"accepted\":true,\"automatic_tiling\":\(enabled)}" let receipt = try JSONDecoder().decode(RealitySession.CommandAcceptance.self, from: Data(source.utf8)) #expect(receipt.accepted) #expect(receipt.automaticTiling == enabled) } @Test func activityRuntimeReceiptAcknowledgesRunningLoadedIsolatedConfiguration() throws { let config = URL(fileURLWithPath: "/tmp/activity-isolated/parcel.toml") let source = #"{"path":"/tmp/activity-isolated/parcel.toml","running":true,"config_load_state":"loaded"}"# let receipt = try JSONDecoder().decode(ActivityRuntimeReceipt.self, from: Data(source.utf8)) try receipt.requireStarted(config: config) #expect(receipt.running) #expect(receipt.path == config.path) #expect(receipt.configLoadState == "loaded") } @Test func activityFileChecksFollowTheAcknowledgedRelaunchStorage() throws { let original = URL(fileURLWithPath: "/tmp/activity-original/parcel.toml") let relaunched = URL(fileURLWithPath: "/tmp/activity-relaunched/parcel.toml") let receipt = ActivityRuntimeReceipt(path: relaunched.path, running: true, configLoadState: "loaded") let file = try receipt.activityFileURL(config: relaunched) #expect(file == relaunched.deletingLastPathComponent().appendingPathComponent("activity.json")) #expect(file != original.deletingLastPathComponent().appendingPathComponent("activity.json")) #expect(throws: RealityError.self) { try receipt.activityFileURL(config: original) } } @Test(arguments: ["not-running", "wrong-config-path", "defaults", "rejected", "not-loaded"]) func activityRuntimeReceiptRejectsUnacknowledgedStartup(_ condition: String) { let config = URL(fileURLWithPath: "/tmp/activity-isolated/parcel.toml") let state: String = switch condition { case "defaults": "missingFileUsingDefaults" case "rejected": "rejected" case "not-loaded": "notLoaded" default: "loaded" } let receipt = ActivityRuntimeReceipt( path: condition == "wrong-config-path" ? "/tmp/other/parcel.toml" : config.path, running: condition != "not-running", configLoadState: state) #expect(throws: RealityError.self) { try receipt.requireStarted(config: config) } #expect(throws: RealityError.self) { try receipt.activityFileURL(config: config) } } @Test func unrelatedCommandReceiptDoesNotInventAnAutomaticTilingState() throws { let receipt = try JSONDecoder().decode( RealitySession.CommandAcceptance.self, from: Data(#"{"accepted":true}"#.utf8)) #expect(receipt.accepted) #expect(receipt.automaticTiling == nil) } @Test func automaticTilingCommandReceiptRejectsMalformedState() { #expect(throws: DecodingError.self) { try JSONDecoder().decode( RealitySession.CommandAcceptance.self, from: Data(#"{"accepted":true,"automatic_tiling":"false"}"#.utf8) ) } } @Test(arguments: ConfigWhenDisplayFull.allCases, [false, true]) func shortcutParityConfigPreservesGlobalSettings(policy: ConfigWhenDisplayFull, enabled: Bool) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let session = try RealitySession( directory: root, appURL: URL(fileURLWithPath: "/tmp/Parcel.app"), visible: ScreenRect(x: 0, y: 25, width: 1600, height: 900), inputBaseline: DriverInputState(heldKeys: [], flags: 0)) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } try session.configure(whenDisplayFull: policy, shortcutsEnabled: enabled) let result = ConfigValidator.validate( try TOMLDocument(parsing: String(contentsOf: session.config, encoding: .utf8))) #expect(result.diagnostics.isEmpty) let configuration = try #require(result.configuration) #expect(configuration.general.whenDisplayFull == policy) #expect(configuration.general.shortcutsEnabled == enabled) for command in [ConfigCommand.toggleAutomaticTiling, .ratioIncrease, .ratioDecrease, .resetSizes] { #expect(configuration.keybindings[command] == DefaultKeybindings.bindings()[command]) } } @Test(arguments: [0, 1, 3]) func retileReceiptPreservesConfirmedMovementCount(_ count: Int) throws { let source = "{\"accepted\":true,\"reports\":[{\"retiled\":{\"moved\":\(count)}}]}" let receipt = try JSONDecoder().decode(RealitySession.CommandAcceptance.self, from: Data(source.utf8)) #expect(receipt.reports == [.retiled(moved: count)]) } @Test func shortcutParityScenariosCoverEveryLayoutAndBothFullDisplayPolicies() { let names = Set(RealityScenario.all.map(\.name)) for layout in ConfigLayout.allCases { #expect(names.contains("sizes-\(layout.rawValue)")) } #expect(names.contains("automatic-tiling-shortcut")) #expect(names.contains("display-full-swap")) #expect(names.contains("display-full-stack")) } @Test func retileOracleCountsOnlyIndependentlyChangedFrames() { let first = ScreenRect(x: 0, y: 0, width: 600, height: 400) let second = ScreenRect(x: 612, y: 0, width: 600, height: 400) let noise = ScreenRect(x: 612.5, y: 0, width: 600, height: 400) #expect(RetileMovementOracle.count(before: [first, second], after: [first, second]) == 0) #expect(RetileMovementOracle.count(before: [first, second], after: [first, noise]) == 1) #expect(RetileMovementOracle.count(before: [first.inset(60), second], after: [first, second]) == 1) #expect(RetileMovementOracle.count(before: [first, second], after: [second, first]) == 2) } @Test func activityRetileRebuildsRatherThanRestoresIncrementalColumns() { let visible = ScreenRect(x: 0, y: 38, width: 1512, height: 886) let incremental = [ ScreenRect(x: 16, y: 54, width: 734, height: 854), ScreenRect(x: 762, y: 54, width: 361, height: 854), ScreenRect(x: 1135, y: 54, width: 361, height: 854), ] let balanced = [ ScreenRect(x: 16, y: 54, width: 485, height: 854), ScreenRect(x: 513, y: 54, width: 486, height: 854), ScreenRect(x: 1011, y: 54, width: 485, height: 854), ] #expect(FrameOracle.stripeShape(incremental, visible: visible, vertical: true)) #expect(!RetileMovementOracle.matchesBalancedColumns(incremental, count: 3, visible: visible)) #expect(RetileMovementOracle.matchesBalancedColumns(balanced, count: 3, visible: visible)) let disturbed = [incremental[0].inset(60), incremental[1], incremental[2]] #expect(RetileMovementOracle.count(before: disturbed, after: balanced) == 3) #expect(RetileMovementOracle.count(before: balanced, after: balanced) == 0) } @Test(arguments: ["displaced", "one-point-overflow", "reordered", "missing", "empty"]) func activityRetileOracleRejectsIncorrectRealFrames(_ condition: String) { let visible = ScreenRect(x: 0, y: 38, width: 1512, height: 886) var frames = FrameOracle.balancedColumns(count: 3, visible: visible) switch condition { case "displaced": frames[0] = frames[0].inset(60) case "one-point-overflow": let frame = frames[2] frames[2] = ScreenRect(x: frame.x + 1, y: frame.y, width: frame.width, height: frame.height) case "reordered": frames.swapAt(0, 1) case "missing": frames.removeLast() case "empty": frames.removeAll() default: preconditionFailure("Unknown Retile oracle regression") } #expect(!RetileMovementOracle.matchesBalancedColumns(frames, count: 3, visible: visible)) } @Test(arguments: ["Application Support", "Preferences", ".config"]) func storageRefusesRealStatePathComponentsBeforeCreatingAnything(_ component: String) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let forbidden = root.appendingPathComponent(component).appendingPathComponent("dev.vinnymac.parcel") #expect(throws: RealityError.self) { try RealityStorage(parent: forbidden) } #expect(!FileManager.default.fileExists(atPath: root.path)) } @Test(arguments: RealityStorage.files, [false, true]) func storageRefusesRedirectedAndSharedStateFiles(name: String, hardLink: Bool) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let storage = try RealityStorage(parent: root) let outside = root.appendingPathComponent("sentinel") let bytes = Data("never touch".utf8) try bytes.write(to: outside) if hardLink { try FileManager.default.linkItem(at: outside, to: storage.fileURL(name)) } else { try FileManager.default.createSymbolicLink(at: storage.fileURL(name), withDestinationURL: outside) } #expect(throws: RealityError.self) { try storage.validate() } #expect(throws: RealityError.self) { try storage.prepare() } #expect(throws: RealityError.self) { try storage.successor() } #expect(try Data(contentsOf: outside) == bytes) } @Test(arguments: [false, true]) func storageRefusesReplacedOrNonprivateDirectories(replaced: Bool) throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let storage = try RealityStorage(parent: root) if replaced { try FileManager.default.moveItem(at: storage.directory, to: root.appendingPathComponent("retained")) try FileManager.default.createDirectory( at: storage.directory, withIntermediateDirectories: false, attributes: [.posixPermissions: 0o700]) } else { try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: storage.directory.path) } #expect(throws: RealityError.self) { try storage.validate() } #expect(throws: RealityError.self) { try storage.preferences() } } @Test func replacementStorageCopiesOnlyOwnedStateAndUsesDistinctDomainsAndPaths() throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let first = try RealityStorage(parent: root) defer { do { try first.removePreferences() } catch { Issue.record(error) } } try first.prepare() #expect(throws: RealityError.self) { try first.prepare() } let bytes = Data("owned memory".utf8) for name in RealityStorage.files { try bytes.write(to: first.fileURL(name)) } try Data("not state".utf8).write(to: first.directory.appendingPathComponent("artifact.json")) let defaults = try first.preferences() defaults.set(["fr"], forKey: "AppleLanguages") #expect(defaults.synchronize()) let second = try first.successor() defer { do { try second.removePreferences() } catch { Issue.record(error) } } #expect(first.token != second.token) #expect(first.preferencesDomain != second.preferencesDomain) #expect(first.fileURL("parcel.toml") != second.fileURL("parcel.toml")) for name in RealityStorage.files { #expect(try Data(contentsOf: second.fileURL(name)) == bytes) } #expect(!FileManager.default.fileExists(atPath: second.directory.appendingPathComponent("artifact.json").path)) #expect( try second.preferences().persistentDomain(forName: second.preferencesDomain)?["AppleLanguages"] as? [String] == ["fr"]) #expect(second.environment["PARCEL_REALITY_ISOLATION_TOKEN"] == second.token.uuidString) #expect(second.environment["PARCEL_REALITY_STATE_DIRECTORY"] == second.directory.path) #expect(second.arguments == ["--reality-isolated"]) try second.removePreferences() #expect(defaults.persistentDomain(forName: first.preferencesDomain)?["AppleLanguages"] as? [String] == ["fr"]) } @Test func freshFirstRunStorageHasNoPersistedCompletionOrAutomaticTilingOverride() throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) .resolvingSymlinksInPath() try FileManager.default.createDirectory(at: root, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } let storage = try RealityStorage(parent: root) defer { do { try storage.removePreferences() } catch { Issue.record(error) } } try storage.prepare(firstRun: true) #expect(try storage.preferences().persistentDomain(forName: storage.preferencesDomain) == nil) } @Test func inheritedProductOverridesCannotEscapeRealityIsolation() { let result = coverageLaunchEnvironment( [ "KEEP": "yes", "PARCEL_CONFIG_PATH": "/not-owned/config", "PARCEL_ACTIVITY_PATH": "/not-owned/activity", "PARCEL_SETUPS_PATH": "/not-owned/setups", "PARCEL_REALITY_DRIVER_SOCKET": "/not-owned/socket", "PARCEL_REALITY_ISOLATION_TOKEN": "foreign", "PARCEL_E2E_LOG_PATH": "/not-owned/log", ], hooks: nil) #expect(result == ["KEEP": "yes", "PARCEL_E2E": "0"]) } @Test func capGrowthOracleRejectsCollapsedTilesAndPartialMemoryRequiresTwoDistinctFrames() { let visible = ScreenRect(x: 0, y: 38, width: 1600, height: 900) let three = FrameOracle.stripes(count: 3, visible: visible, vertical: true) #expect(capStackGroups([three[0], three[1], three[2], three[2]]).map(\.count).sorted() == [1, 1, 2]) #expect(capStackGroups([three[0], three[0], three[0], three[0]]).map(\.count).sorted() != [1, 1, 2]) let two = FrameOracle.stripes(count: 2, visible: visible, vertical: true, ratio: 0.55) #expect(FrameOracle.matchesUnordered(Array(two.reversed()), two)) #expect(!FrameOracle.matchesUnordered([two[1], two[1]], two)) } @Test func configurationDoesNotForceCalculatorToTileOrFloat() throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) let session = try RealitySession( directory: root, appURL: URL(fileURLWithPath: "/tmp/Parcel.app"), visible: ScreenRect(x: 0, y: 25, width: 1600, height: 900), inputBaseline: DriverInputState(heldKeys: [], flags: 0)) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record(error) } } try session.configure() let result = ConfigValidator.validate( try TOMLDocument(parsing: String(contentsOf: session.config, encoding: .utf8))) let configuration = try #require(result.configuration) #expect(!configuration.rules.contains { $0.bundleID == "com.apple.calculator" && $0.action != .ignore }) #expect(!configuration.memory.enabled) } }