import ParcelConfig import ParcelCore import Testing @testable import ParcelEngine @MainActor struct AdaptiveReloadIntegrationTests { nonisolated private static let screens = [Rect(width: 1080, height: 1920), Rect(width: 2560, height: 1080)] @Test(arguments: screens, [0, 100]) func unrelatedReloadPreservesAdaptiveShapeRuntimeOverridesAndCachedDividers(screen: Rect, cap: Int) async throws { var configuration = engineConfiguration(layout: .side) configuration.layout.global.portraitLayout = .side configuration.layout.global.windowCap = 5 let fresh = try AppliedConfiguration(configuration).workspace( engineWorkspace, in: screen, preservingLayout: true) #expect(fresh.layout == .side) #expect(fresh.layoutDefaults == LayoutDefaults(landscape: .side, portrait: .side)) #expect(fresh.configuredRatio == .half) #expect(fresh.windowCap == 5) let harness = try EngineHarness(configuration: configuration) try await harness.start() try harness.add([1, 2, 3]) let secondary = try #require(harness.engine.snapshot.state.tileEdges.first { $0.path == [.second] }) harness.engine.send(.tileEdgeResized(secondary, delta: 40)) harness.engine.send(.commandIssued(.setRatio(.twoThirds))) harness.engine.send(.commandIssued(.setWindowCap(cap))) try harness.scheduler.runReady() let regular = try #require(harness.engine.snapshot.state.workspaces[engineWorkspace]) harness.world.emit(.observed(.displaySetChanged([Display(id: engineDisplay, frame: screen)]))) try harness.scheduler.runReady() let before = try #require(harness.engine.snapshot.state.workspaces[engineWorkspace]) configuration.layout.global.gaps.inner = 10 configuration.layout.global.reserved.top = 20 configuration.layout.global.whenFull = .float try harness.engine.applyConfiguration(configuration) try harness.scheduler.runReady() var expected = before expected.gaps.inner = 10 expected.reservedEdges.top = 20 expected.whenFull = .float #expect(harness.engine.snapshot.state.workspaces[engineWorkspace] == expected) #expect(expected.windowCap == (cap == 0 ? Int.max : cap)) #expect(expected.effectiveWindowCap == (cap == 0 ? Int.max : 5)) harness.world.emit(.observed(.displaySetChanged([Display(id: engineDisplay, frame: engineScreen)]))) try harness.scheduler.runReady() let restored = try #require(harness.engine.snapshot.state.workspaces[engineWorkspace]) #expect(restored.tree == regular.tree) #expect(restored.ratio == regular.ratio) #expect(restored.configuredRatio == .half) await harness.engine.stop() } @Test func changedRatioReloadUpdatesWideMainAndCachedStandardMainWithoutResettingSidebar() async throws { var configuration = engineConfiguration(layout: .side) let harness = try EngineHarness(configuration: configuration) try await harness.start() try harness.add([1, 2, 3]) let secondary = try #require(harness.engine.snapshot.state.tileEdges.first { $0.path == [.second] }) harness.engine.send(.tileEdgeResized(secondary, delta: 40)) try harness.scheduler.runReady() let customFraction = try #require(harness.engine.snapshot.state.tileEdges.first { $0.path == [.second] }) .fraction harness.world.emit(.observed(.displaySetChanged([Display(id: engineDisplay, frame: Self.screens[1])]))) try harness.scheduler.runReady() configuration.layout.global.ratio = 0.6 try harness.engine.applyConfiguration(configuration) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.tileEdges.first { $0.path == [.first] }?.fraction == 0.6) #expect(harness.engine.snapshot.state.workspaces[engineWorkspace]?.configuredRatio == .threeFifths) harness.world.emit(.observed(.displaySetChanged([Display(id: engineDisplay, frame: engineScreen)]))) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.tileEdges.first { $0.path.isEmpty }?.fraction == 0.6) #expect(harness.engine.snapshot.state.tileEdges.first { $0.path == [.second] }?.fraction == customFraction) await harness.engine.stop() } }