From c17585a8cea74788f621b9443eab07e8c148629a Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Fri, 6 Nov 2026 21:00:25 -0500 Subject: [PATCH 1/3] Fit tour height to each step Signed-off-by: Vincent Taverna --- Sources/ParcelUI/Tour/README.md | 12 +- .../Tour/TourContentMeasurements.swift | 13 ++ Sources/ParcelUI/Tour/TourSetupView.swift | 39 +++- Sources/ParcelUI/Tour/TourView.swift | 2 +- Sources/ParcelUI/Tour/TourWelcomeView.swift | 10 +- .../ParcelUI/Tour/TourWindowGeometry.swift | 12 ++ .../Tour/WindowLearningController.swift | 23 ++- .../ParcelUITests/Tour/TourCompactCase.swift | 26 +++ .../Tour/TourCompactLayoutTests.swift | 178 ++++++++++++++++-- Tests/ParcelUITests/Tour/TourSetupTests.swift | 38 +++- .../Tour/TourWelcomeRenderingTests.swift | 1 + 11 files changed, 300 insertions(+), 54 deletions(-) create mode 100644 Sources/ParcelUI/Tour/TourContentMeasurements.swift create mode 100644 Sources/ParcelUI/Tour/TourWindowGeometry.swift create mode 100644 Tests/ParcelUITests/Tour/TourCompactCase.swift diff --git a/Sources/ParcelUI/Tour/README.md b/Sources/ParcelUI/Tour/README.md index 10da247d..16719073 100644 --- a/Sources/ParcelUI/Tour/README.md +++ b/Sources/ParcelUI/Tour/README.md @@ -2,10 +2,14 @@ Welcome → Allow Parcel → Ready, for both Auto Mode and Manual Mode. Welcome offers Auto Mode as the primary action and a smaller, borderless Manual Mode option; -either saves the intent and opens Allow. The 560 × 460-point native full-size -window keeps its traffic lights without an inner frame. Welcome never -scrolls: its fictional demo shrinks before text or controls, plays while active, -and becomes a static tiled frame with Reduce Motion or motion off. +either saves the intent and opens Allow. The native full-size window keeps its +traffic lights without an inner frame. Its width stays at 560 points; height fits +each step, including expanded references, errors, and replay disclosure. The top +edge stays fixed while the existing window motion token animates the height; +Reduce Motion and motion off resize instantly. The footer follows content with +consistent padding, not an empty spacer. No step scrolls or shrinks its text. +Welcome's 280 × 175-point fictional demo plays while active and becomes a static +tiled frame with Reduce Motion or motion off. First run and replay hold every product write before discovery or queued motion. Grant changes, navigation, Settings links, and config reloads never release that diff --git a/Sources/ParcelUI/Tour/TourContentMeasurements.swift b/Sources/ParcelUI/Tour/TourContentMeasurements.swift new file mode 100644 index 00000000..65911619 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourContentMeasurements.swift @@ -0,0 +1,13 @@ +import CoreGraphics + +struct TourContentMeasurements { + var content: CGSize? + var footerHeight: CGFloat? + var separatorHeight: CGFloat? + + var fittingSize: CGSize? { + guard let content, let footerHeight, let separatorHeight else { return nil } + return TourWindowGeometry.fittingSize( + CGSize(width: content.width, height: content.height + footerHeight + separatorHeight)) + } +} diff --git a/Sources/ParcelUI/Tour/TourSetupView.swift b/Sources/ParcelUI/Tour/TourSetupView.swift index 4cbe2284..24e29e08 100644 --- a/Sources/ParcelUI/Tour/TourSetupView.swift +++ b/Sources/ParcelUI/Tour/TourSetupView.swift @@ -9,23 +9,30 @@ struct TourSetupView: View { @AccessibilityFocusState private var errorFocused: Bool @FocusState private var primaryFocused: Bool @ScaledMetric(relativeTo: .body) private var footerHeight = 64.0 + @State private var measurements = TourContentMeasurements() nonisolated static let windowSize = CGSize(width: 560, height: 460) init(controller: WindowLearningController) { self.controller = controller; setup = controller.setup } var body: some View { VStack(spacing: 0) { - if setup.step == .welcome { - content.frame(maxHeight: .infinity, alignment: .top) - } else { - ViewThatFits(in: .vertical) { - content.fixedSize(horizontal: false, vertical: true) - ScrollView { content } - .scrollBounceBehavior(.basedOnSize) + content + .fixedSize(horizontal: false, vertical: true) + .onGeometryChange(for: CGSize.self) { + $0.size + } action: { + measurements.content = $0 + fitMeasuredContent() } .frame(maxHeight: .infinity, alignment: .top) - } + .clipped() Divider() + .onGeometryChange(for: CGFloat.self) { + $0.size.height + } action: { + measurements.separatorHeight = $0 + fitMeasuredContent() + } VStack(spacing: 8) { HStack(alignment: .center, spacing: 14) { if setup.step != .welcome, setup.result == nil { @@ -58,8 +65,18 @@ struct TourSetupView: View { } .padding(.horizontal, 32) .padding(.vertical, 16) - .frame(height: setup.isReplay ? footerHeight + 40 : footerHeight) + .frame(minHeight: footerHeight) + .fixedSize(horizontal: false, vertical: true) + .accessibilityElement(children: .contain) + .accessibilityIdentifier("tour.footer") + .onGeometryChange(for: CGFloat.self) { + $0.size.height + } action: { + measurements.footerHeight = $0 + fitMeasuredContent() + } } + .frame(width: Self.windowSize.width) .onChange(of: setup.step, initial: true) { titleFocused = true primaryFocused = setup.step != .welcome @@ -75,6 +92,10 @@ struct TourSetupView: View { .onExitCommand { controller.closeSetup() } } + private func fitMeasuredContent() { + if let size = measurements.fittingSize { controller.resizeSetupPanel(to: size) } + } + private var content: some View { VStack(alignment: .leading, spacing: setup.step == .welcome ? 18 : 12) { heading diff --git a/Sources/ParcelUI/Tour/TourView.swift b/Sources/ParcelUI/Tour/TourView.swift index 26a0ed70..d80ad9d6 100644 --- a/Sources/ParcelUI/Tour/TourView.swift +++ b/Sources/ParcelUI/Tour/TourView.swift @@ -13,7 +13,7 @@ struct TourView: View { if controller.setup.isPresented { TourSetupView(controller: controller) .ignoresSafeArea(.container, edges: .top) - .frame(minWidth: 480, maxWidth: .infinity, minHeight: 400, maxHeight: .infinity) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) } else { VStack(alignment: .leading, spacing: 16) { HStack { diff --git a/Sources/ParcelUI/Tour/TourWelcomeView.swift b/Sources/ParcelUI/Tour/TourWelcomeView.swift index 8b4e3933..9d73c767 100644 --- a/Sources/ParcelUI/Tour/TourWelcomeView.swift +++ b/Sources/ParcelUI/Tour/TourWelcomeView.swift @@ -10,13 +10,9 @@ struct TourWelcomeView: View { var body: some View { VStack(spacing: 16) { - GeometryReader { geometry in - let width = max(0, min(280, geometry.size.width, geometry.size.height * 1.6)) - TourDemoWelcome(configuration: configuration) - .frame(width: width, height: width / 1.6) - .frame(maxWidth: .infinity, maxHeight: .infinity) - } - .layoutPriority(-1) + TourDemoWelcome(configuration: configuration) + .frame(width: 280, height: 175) + .frame(maxWidth: .infinity) VStack(spacing: 12) { Button { choose(.automatic) diff --git a/Sources/ParcelUI/Tour/TourWindowGeometry.swift b/Sources/ParcelUI/Tour/TourWindowGeometry.swift new file mode 100644 index 00000000..83b95aa7 --- /dev/null +++ b/Sources/ParcelUI/Tour/TourWindowGeometry.swift @@ -0,0 +1,12 @@ +import CoreGraphics + +enum TourWindowGeometry { + static func fittingSize(_ measured: CGSize) -> CGSize { + precondition(measured.width.isFinite && measured.height.isFinite && measured.width > 0 && measured.height > 0) + return CGSize(width: 560, height: ceil(measured.height)) + } + + static func frame(resizing current: CGRect, to size: CGSize) -> CGRect { + CGRect(x: current.minX, y: current.maxY - size.height, width: size.width, height: size.height) + } +} diff --git a/Sources/ParcelUI/Tour/WindowLearningController.swift b/Sources/ParcelUI/Tour/WindowLearningController.swift index 6992341c..7d5f015f 100644 --- a/Sources/ParcelUI/Tour/WindowLearningController.swift +++ b/Sources/ParcelUI/Tour/WindowLearningController.swift @@ -134,6 +134,7 @@ public final class WindowLearningController { private let failure: @MainActor (any Error) -> Void private let requestKeyboardFocus: @MainActor (NSPanel) -> Void @ObservationIgnored private var panel: LearningPanel? + private(set) var setupContentSize: CGSize? @ObservationIgnored private var setupTask: Task? @ObservationIgnored private var presentationTask: Task? private var presentationGeneration = UUID() @@ -286,14 +287,16 @@ public final class WindowLearningController { let panel = LearningPanel(title: UIStrings.text("Guided Tour"), interactive: true, setupWindow: true) let host = NSHostingView(rootView: TourView(controller: self)) host.sizingOptions = [] - panel.contentMinSize = CGSize(width: 480, height: 400) - panel.setContentSize(TourSetupView.windowSize) + panel.contentMinSize = CGSize(width: TourSetupView.windowSize.width, height: 1) + panel.contentMaxSize = CGSize(width: TourSetupView.windowSize.width, height: .greatestFiniteMagnitude) + panel.setContentSize(setupContentSize ?? TourSetupView.windowSize) panel.onSetupClose = { [weak self] in self?.closeSetup() } host.wantsLayer = true + self.panel = panel panel.contentView = host + host.layoutSubtreeIfNeeded() panel.isMovableByWindowBackground = true panel.center() - self.panel = panel } resizePanel() positionPanel() @@ -303,10 +306,22 @@ public final class WindowLearningController { } func setupScreenChanged() { - resizePanel() announce(TourText.text(setup.step.title)) } + func resizeSetupPanel(to measured: CGSize) { + guard setup.isPresented else { return } + let size = TourWindowGeometry.fittingSize(measured) + setupContentSize = size + guard let panel else { return } + panel.contentMinSize = size + panel.contentMaxSize = size + let frameSize = panel.frameRect(forContentRect: CGRect(origin: .zero, size: size)).size + guard panel.frame.size != frameSize else { return } + let frame = TourWindowGeometry.frame(resizing: panel.frame, to: frameSize) + LearningMotion.resize(panel, to: frame, configuration: configuration.motion) + } + func resizePanel() { guard !setup.isPresented, let content = panel?.contentView else { return } content.layoutSubtreeIfNeeded() diff --git a/Tests/ParcelUITests/Tour/TourCompactCase.swift b/Tests/ParcelUITests/Tour/TourCompactCase.swift new file mode 100644 index 00000000..680224b7 --- /dev/null +++ b/Tests/ParcelUITests/Tour/TourCompactCase.swift @@ -0,0 +1,26 @@ +import ParcelPlatform + +@testable import ParcelUI + +struct TourCompactCase: Sendable { + let step: TourSetupStep + let intent: TourStartIntent + let replay: Bool + let expanded: Bool + let permission: PermissionStatus + + static var all: [Self] { + let screens: [(TourSetupStep, TourStartIntent)] = [ + (.welcome, .automatic), (.welcome, .manual), (.allow, .automatic), (.allow, .manual), + (.ready, .automatic), (.ready, .manual), + ] + let variants: [(Bool, Bool, PermissionStatus)] = [ + (false, false, .missing), (false, true, .granted), (true, false, .granted), (true, true, .missing), + ] + return screens.flatMap { step, intent in + variants.map { replay, expanded, permission in + Self(step: step, intent: intent, replay: replay, expanded: expanded, permission: permission) + } + } + } +} diff --git a/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift b/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift index b65efbf4..56b21f30 100644 --- a/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift +++ b/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift @@ -7,15 +7,11 @@ import Testing @testable import ParcelUI extension AppKitTestSuite.TourSetupRenderingTests { - @Test( - arguments: [ - (TourSetupStep.welcome, TourStartIntent.automatic), (.welcome, .manual), - (.allow, .automatic), (.allow, .manual), (.ready, .automatic), (.ready, .manual), - ], [DynamicTypeSize.large, .accessibility5]) - func localizedStepsFitCompactWindowWithoutScrolling( - screen: (TourSetupStep, TourStartIntent), textSize: DynamicTypeSize - ) async throws { - let (step, intent) = screen + @Test(arguments: TourCompactCase.all, [DynamicTypeSize.large, .accessibility5]) + func localizedStepsFitCompactWindowWithoutScrolling(screen: TourCompactCase, textSize: DynamicTypeSize) async throws + { + let step = screen.step + let intent = screen.intent try #require(FileManager.default.fileExists(atPath: "/tmp/parcel-m3-free")) let language = ProcessInfo.processInfo.environment["PARCEL_LOCALIZATION_LANGUAGE"] ?? "en" try #require(["en", "es", "fr", "de", "ja", "zh-Hans", "ko", "pt-BR"].contains(language)) @@ -57,10 +53,14 @@ extension AppKitTestSuite.TourSetupRenderingTests { start: { _, _ in Issue.record("Layout checks must not start setup."); return .success }, deferSetup: {}, openShortcuts: {}, openSystemSettings: {}, openLoginSettings: {}, - permissionStatus: { step == .allow ? .missing : .granted }) - controller.setup.begin(progress: .init(step: step, intent: intent), defaultOpenAtLogin: true) + permissionStatus: { step == .allow ? screen.permission : .granted }) + controller.present() + try await waitForUI("The controller owns its visible tour panel") { controller.visibleSetupWindow != nil } + let window = try #require(controller.visibleSetupWindow) + controller.setup.begin( + progress: .init(step: step, intent: intent), replay: screen.replay, defaultOpenAtLogin: true) try await controller.setup.checkCurrentStep() - if step == .ready && intent == .manual { + if step == .ready && intent == .manual && screen.expanded { controller.setup.referenceExpanded = true try await controller.setup.loadShortcuts() } @@ -68,25 +68,32 @@ extension AppKitTestSuite.TourSetupRenderingTests { rootView: TourView(controller: controller) .environment(\.locale, Locale(identifier: language)).environment(\.dynamicTypeSize, textSize)) host.sizingOptions = [] - let window = LearningPanel(title: "Compact tour fixture", interactive: true, setupWindow: true) - window.setContentSize(TourSetupView.windowSize) window.contentView = host - defer { window.contentView = nil; window.close() } - window.makeKeyAndOrderFront(nil) let primary = step == .welcome ? "tour.mode.automatic" : intent == .automatic && step == .ready ? "tour.tidy" : "tour.continue" try await waitForUI("Localized compact step has rendered its actions") { host.layoutSubtreeIfNeeded() + guard let size = controller.setupContentSize else { return false } window.displayIfNeeded() - return SettingsAccessibilityElement(object: host).descendants().contains { - $0.accessibilityIdentifier() == primary - } + return host.bounds.size == size && abs(host.fittingSize.height - size.height) < 1 + && SettingsAccessibilityElement(object: host).descendants().contains { + $0.accessibilityIdentifier() == primary + } } let nodes = SettingsAccessibilityElement(object: host).descendants() #expect(!nodes.contains { $0.accessibilityRole() == .scrollArea }, "\(language) / \(step) must not scroll.") let bounds = window.convertToScreen(host.convert(host.bounds, to: nil)) - #expect(host.bounds.size == TourSetupView.windowSize) + #expect(host.bounds.width == 560) + #expect(host.bounds.size == controller.setupContentSize) + let footer = try #require(nodes.first { $0.accessibilityIdentifier() == "tour.footer" }) + let footerFrame = try compactFrame(footer) + let contentFrames = try nodes.filter { + [.button, .checkBox, .staticText, .image].contains($0.accessibilityRole()) + }.map { try compactFrame($0) }.filter { $0.minY >= footerFrame.maxY } + let contentBottom = try #require(contentFrames.map(\.minY).min()) + #expect(contentBottom - footerFrame.maxY <= 48, "\(language) / \(step) leaves a large empty region.") + #expect(abs(footerFrame.minY - bounds.minY) <= 1, "The footer stays at the bottom of every fitted step.") for element in nodes where [.button, .checkBox, .staticText].contains(element.accessibilityRole()) { try #require(element.object.responds(to: NSSelectorFromString("accessibilityFrame"))) let frame = try #require(element.object.value(forKey: "accessibilityFrame") as? NSValue).rectValue @@ -105,4 +112,135 @@ extension AppKitTestSuite.TourSetupRenderingTests { host.cacheDisplay(in: host.bounds, to: bitmap) #expect(bitmap.tiffRepresentation?.isEmpty == false) } + + @Test(arguments: [false, true]) + func ownedPanelKeepsFooterAtBottomThroughGrowthAndShrink(motionEnabled: Bool) async throws { + try #require(FileManager.default.fileExists(atPath: "/tmp/parcel-m3-free")) + let restoreAccessibility = try enableTourAccessibilityReadback() + defer { restoreAccessibility() } + let suite = "tour-fit-animation.\(UUID())" + let defaults = try #require(UserDefaults(suiteName: suite)) + defer { defaults.removePersistentDomain(forName: suite) } + let controller = try WindowLearningController(defaults: defaults, onFailure: { Issue.record($0) }) + defer { controller.stop() } + var configuration = ParcelConfiguration.defaults + configuration.motion.enabled = motionEnabled + controller.update(state: LearningScene.state(), configuration: configuration, active: false) + let reference = try zip( + [ConfigCommand.retile, .windowNext, .layoutGrid, .floatToggle], + ["cmd-shift-7", "cmd-shift-8", "cmd-shift-9", "cmd-shift-0"] + ).map { TourShortcutReference(command: $0.0, chord: try KeyChord(parsing: $0.1)) } + controller.setup.actions = TourSetupActions( + checkShortcuts: { .init(warnings: [], reference: reference) }, + checkSystem: { .init(stageManager: false, nativeTiling: false) }, + loginStatus: { .disabled }, setOpenAtLogin: { $0 ? .enabled : .disabled }, checkReady: { _ in .ready }, + start: { _, _ in + Issue.record("Fitting must not start setup."); return .success + }, + deferSetup: {}, openShortcuts: {}, openSystemSettings: {}, openLoginSettings: {}, + permissionStatus: { .granted }) + controller.present() + try await waitForUI("The fitting controller owns a visible panel") { controller.visibleSetupWindow != nil } + let window = try #require(controller.visibleSetupWindow) + let host = try #require(window.contentView) + controller.setup.begin(progress: .init(step: .ready, intent: .manual)) + try await controller.setup.checkCurrentStep() + + func settled(greaterThan height: CGFloat? = nil, original: CGRect? = nil) async throws { + try await waitForUI("The owned panel reaches its fitted height with a bottom-aligned footer") { + host.layoutSubtreeIfNeeded() + window.displayIfNeeded() + guard let size = controller.setupContentSize, + let footer = SettingsAccessibilityElement(object: host).descendants().first(where: { + $0.accessibilityIdentifier() == "tour.footer" + }), + footer.object.responds(to: NSSelectorFromString("accessibilityFrame")), + let value = footer.object.value(forKey: "accessibilityFrame") as? NSValue + else { return false } + let bounds = window.convertToScreen(host.convert(host.bounds, to: nil)) + #expect(abs(value.rectValue.minY - bounds.minY) <= 1) + if let original { + #expect(abs(window.frame.maxY - original.maxY) <= 1) + #expect(abs(window.frame.minX - original.minX) <= 1) + } + if let height, size.height <= height { return false } + if let original, height == nil, abs(window.frame.height - original.height) > 1 { return false } + return abs(host.bounds.height - size.height) <= 1 && abs(host.fittingSize.height - size.height) < 1 + } + } + try await settled() + let original = window.frame + let originalHeight = host.bounds.height + controller.setup.referenceExpanded = true + try await controller.setup.loadShortcuts() + try await settled(greaterThan: originalHeight, original: original) + controller.setup.referenceExpanded = false + try await settled(original: original) + #expect(window.frame == original) + } + + private func compactFrame(_ element: SettingsAccessibilityElement) throws -> CGRect { + try #require(element.object.responds(to: NSSelectorFromString("accessibilityFrame"))) + return try #require(element.object.value(forKey: "accessibilityFrame") as? NSValue).rectValue + } +} + +extension TourAllowReadyTests { + @Test func fittingWaitsForEveryIntrinsicMeasurement() { + var measurements = TourContentMeasurements() + #expect(measurements.fittingSize == nil) + measurements.content = CGSize(width: 560, height: 181.25) + #expect(measurements.fittingSize == nil) + measurements.footerHeight = 64 + #expect(measurements.fittingSize == nil) + measurements.separatorHeight = 0.5 + #expect(measurements.fittingSize == CGSize(width: 560, height: 246)) + measurements.content?.height = 320.5 + #expect(measurements.fittingSize == CGSize(width: 560, height: 385)) + measurements.footerHeight = 96.5 + #expect(measurements.fittingSize == CGSize(width: 560, height: 418)) + } + + @Test(arguments: [180.0, 260.25, 460.0, 680.75]) + func fittedHeightHasNoMinimumOrUnusedRegion(height: Double) { + let size = TourWindowGeometry.fittingSize(CGSize(width: 900, height: height)) + #expect(size.width == 560) + #expect(size.height >= height && size.height - height < 1) + } + + @Test(arguments: [180.0, 260.25, 460.0, 680.75]) + func resizingKeepsTheTopAndLeadingEdgesFixed(height: Double) { + let original = CGRect(x: -1100, y: 200, width: 560, height: 460) + let size = TourWindowGeometry.fittingSize(CGSize(width: 560, height: height)) + let resized = TourWindowGeometry.frame(resizing: original, to: size) + #expect(resized.minX == original.minX) + #expect(resized.maxY == original.maxY) + #expect(resized.size == size) + #expect(TourWindowGeometry.frame(resizing: resized, to: original.size) == original) + } + + @Test(arguments: [false, true], [false, true]) + func fittingMotionUsesTheExistingAccessibilityPolicy(enabled: Bool, reduceMotion: Bool) { + var configuration = MotionConfiguration() + configuration.enabled = enabled + let motion = OverlayMotion(configuration: configuration, accessibility: .init(reduceMotion: reduceMotion)) + #expect((motion.behavior == .animate) == (enabled && !reduceMotion)) + } + + @Test func fittingUpdatesDoNotNavigateOrStartSetup() throws { + let suite = "tour-fitting.\(UUID())" + let defaults = try #require(UserDefaults(suiteName: suite)) + defer { defaults.removePersistentDomain(forName: suite) } + let controller = try WindowLearningController(defaults: defaults, onFailure: { Issue.record($0) }) + defer { controller.stop() } + controller.setup.begin(progress: .init(step: .allow)) + controller.resizeSetupPanel(to: CGSize(width: 560, height: 240.25)) + #expect(controller.setupContentSize == CGSize(width: 560, height: 241)) + controller.resizeSetupPanel(to: CGSize(width: 560, height: 320.5)) + #expect(controller.setupContentSize == CGSize(width: 560, height: 321)) + #expect(controller.setup.step == .allow && controller.setup.result == nil && !controller.setup.isBusy) + controller.setup.dismiss() + controller.resizeSetupPanel(to: CGSize(width: 560, height: 900)) + #expect(controller.setupContentSize == CGSize(width: 560, height: 321)) + } } diff --git a/Tests/ParcelUITests/Tour/TourSetupTests.swift b/Tests/ParcelUITests/Tour/TourSetupTests.swift index 1041de5b..dec3c038 100644 --- a/Tests/ParcelUITests/Tour/TourSetupTests.swift +++ b/Tests/ParcelUITests/Tour/TourSetupTests.swift @@ -1579,7 +1579,7 @@ extension AppKitTestSuite { @MainActor struct TourSetupRenderingTests { @Test(arguments: TourSetupStep.allCases, [TourStartIntent.automatic, .manual]) - func everyScreenUsesTheSameStartingFrame(step: TourSetupStep, intent: TourStartIntent) async throws { + func everyScreenUsesItsRenderedContentHeight(step: TourSetupStep, intent: TourStartIntent) async throws { let suite = "tour-render.\(UUID().uuidString)" let defaults = try #require(UserDefaults(suiteName: suite)) defer { defaults.removePersistentDomain(forName: suite) } @@ -1590,12 +1590,19 @@ extension AppKitTestSuite { learning.setup.begin(progress: .init(step: step, intent: intent)) try await learning.setup.checkCurrentStep() let size = TourSetupView.windowSize - let host = NSHostingView( - rootView: TourView(controller: learning).frame(width: size.width, height: size.height)) + let host = NSHostingView(rootView: TourSetupView(controller: learning)) + host.sizingOptions = [] host.frame = CGRect(origin: .zero, size: size) + try await waitForTour("the tour reports its rendered height") { + host.layoutSubtreeIfNeeded() + return learning.setupContentSize != nil + } + let fitted = try #require(learning.setupContentSize) + host.frame.size = fitted host.layoutSubtreeIfNeeded() - #expect(host.fittingSize == size) - #expect(host.bounds.size == size) + #expect(abs(host.fittingSize.height - fitted.height) < 1) + #expect(host.bounds.size == fitted) + #expect(fitted.width == size.width) let bitmap = try #require(host.bitmapImageRepForCachingDisplay(in: host.bounds)) host.cacheDisplay(in: host.bounds, to: bitmap) #expect(bitmap.tiffRepresentation?.isEmpty == false) @@ -1607,7 +1614,7 @@ extension AppKitTestSuite { (ColorScheme.light, DynamicTypeSize.large), (.dark, .large), (.light, .accessibility3), (.dark, .accessibility3), ], [Double(TourSetupView.windowSize.height), 800.0]) - func permissionAndLoginRecoveryKeepTheWindowAndFooterCoordinates( + func permissionAndLoginRecoveryFitWithoutMovingTheTopEdge( appearance: (colorScheme: ColorScheme, textSize: DynamicTypeSize), height: Double ) async throws { let (colorScheme, textSize) = appearance @@ -1649,6 +1656,7 @@ extension AppKitTestSuite { window.orderFront(nil) try await waitForTour("the owned footer has accessibility geometry") { host.layoutSubtreeIfNeeded() + fitTour(window, learning: learning) window.displayIfNeeded() return footerFrames(host) != nil } @@ -1658,6 +1666,7 @@ extension AppKitTestSuite { #expect(throws: TourSetupFailure.self) { try learning.setup.openAccessibilitySettings() } try await waitForTour("the failed permission action is rendered") { host.layoutSubtreeIfNeeded() + fitTour(window, learning: learning) window.displayIfNeeded() return label(host, id: "tour.permission.error") == "Open System Settings and turn on Accessibility for Parcel." @@ -1669,6 +1678,7 @@ extension AppKitTestSuite { try await learning.setup.refreshPermission() try await waitForTour("the live grant is rendered in place") { host.layoutSubtreeIfNeeded() + fitTour(window, learning: learning) window.displayIfNeeded() return label(host, id: "tour.permission.status") == "Accessibility is on, Parcel can move and resize your windows" @@ -1679,6 +1689,7 @@ extension AppKitTestSuite { try await learning.setup.retryCheck(.login) try await waitForTour("the targeted login retry is rendered") { host.layoutSubtreeIfNeeded() + fitTour(window, learning: learning) window.displayIfNeeded() return elements(host).contains { $0.accessibilityIdentifier() == "tour.retry.login" } } @@ -1687,6 +1698,7 @@ extension AppKitTestSuite { try await learning.setup.retryCheck(.login) try await waitForTour("acknowledged login removes the prior retry control") { host.layoutSubtreeIfNeeded() + fitTour(window, learning: learning) window.displayIfNeeded() return !elements(host).contains { $0.accessibilityIdentifier() == "tour.retry.login" } } @@ -1734,6 +1746,7 @@ extension AppKitTestSuite { window.orderFront(nil) try await waitForTourState("Allow controls have native geometry") { host.layoutSubtreeIfNeeded() + fitTour(window, learning: learning) window.displayIfNeeded() return footerFrames(host) != nil && elements(host).contains { $0.accessibilityIdentifier() == "tour.login" } @@ -1803,13 +1816,20 @@ extension AppKitTestSuite { return (exit, primary) } + private func fitTour(_ window: NSWindow, learning: WindowLearningController) { + guard let size = learning.setupContentSize else { return } + let frameSize = window.frameRect(forContentRect: CGRect(origin: .zero, size: size)).size + window.setFrame(TourWindowGeometry.frame(resizing: window.frame, to: frameSize), display: true) + } + private func assertGeometry( _ window: NSWindow, host: NSView, windowFrame: CGRect, footer: (exit: CGRect, primary: CGRect) ) throws { - #expect(window.frame == windowFrame) + #expect(window.frame.maxY == windowFrame.maxY) + #expect(window.frame.minX == windowFrame.minX && window.frame.width == windowFrame.width) let current = try #require(footerFrames(host)) - #expect(current.exit == footer.exit) - #expect(abs(current.primary.midY - footer.primary.midY) < 0.5) + #expect(abs((current.exit.minY - window.frame.minY) - (footer.exit.minY - windowFrame.minY)) < 0.5) + #expect(abs((current.primary.midY - window.frame.minY) - (footer.primary.midY - windowFrame.minY)) < 0.5) #expect(abs(current.primary.maxX - footer.primary.maxX) < 0.5) #expect(window.frame.contains(current.exit)) #expect(window.frame.contains(current.primary)) diff --git a/Tests/ParcelUITests/Tour/TourWelcomeRenderingTests.swift b/Tests/ParcelUITests/Tour/TourWelcomeRenderingTests.swift index fbca32dc..e5a279fb 100644 --- a/Tests/ParcelUITests/Tour/TourWelcomeRenderingTests.swift +++ b/Tests/ParcelUITests/Tour/TourWelcomeRenderingTests.swift @@ -45,6 +45,7 @@ extension AppKitTestSuite.TourSetupRenderingTests { window.makeKeyAndOrderFront(nil) try await waitForUI("Welcome renders both native choice buttons") { host.layoutSubtreeIfNeeded() + if let size = controller.setupContentSize { window.setContentSize(size) } window.displayIfNeeded() let nodes = SettingsAccessibilityElement(object: host).descendants() return ["tour.mode.automatic", "tour.mode.manual"].allSatisfy { id in -- knotmirror 0.0.1 From 1403818600cb7d0219a9aea82d9ef231a326b730 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Fri, 6 Nov 2026 21:04:37 -0500 Subject: [PATCH 2/3] Read back fitted tour frames Signed-off-by: Vincent Taverna --- .../Tour/TourAllowReadyScreenshotTests.swift | 7 ++-- Tests/Reality/TourNativeAcceptance.swift | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift b/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift index c383c1d0..58cfea84 100644 --- a/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift +++ b/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift @@ -123,10 +123,11 @@ extension AppKitTestSuite.PseudoLocalizationScreenshotTests { _ learning: WindowLearningController, scheme: ColorScheme, name: String, output: URL, identifiers: [String] ) async throws { for enlarged in [false, true] { - let captureName = name + (enlarged ? "-ax3" : "") + let captureName = name + (enlarged ? "-ax5" : "") try await capture( - TourView(controller: learning), size: TourSetupView.windowSize, - contentSized: false, scheme: scheme, typeSize: enlarged ? .accessibility3 : .large, + TourSetupView(controller: learning).ignoresSafeArea(.container, edges: .top), + size: TourSetupView.windowSize, + contentSized: true, scheme: scheme, typeSize: enlarged ? .accessibility5 : .large, name: captureName, output: output, requiredIdentifiers: identifiers, tourChrome: true) let report = try String( diff --git a/Tests/Reality/TourNativeAcceptance.swift b/Tests/Reality/TourNativeAcceptance.swift index 08b7202f..3822821e 100644 --- a/Tests/Reality/TourNativeAcceptance.swift +++ b/Tests/Reality/TourNativeAcceptance.swift @@ -115,18 +115,25 @@ func checkNativeTourAutomatic( throw RealityError("The owned German launch still rendered the English welcome") } } + let welcomeFrame = try await fittedNativeTourFrame(session, stage: "welcome") try await captureNativeTour(session, stage: "welcome") try await pressNativeTour(session, .automatic) try await waitNativeTour(session, step: "allow") + _ = try await fittedNativeTourFrame(session, stage: "allow", topAnchor: welcomeFrame, shorter: true) try await requireNativeTourHold(session, owned: owned, original: original) try await captureNativeTour(session, stage: "allow") try await pressNativeTour(session, .back) try await waitNativeTour(session, step: "welcome") + let returned = try await fittedNativeTourFrame(session, stage: "welcome-back", topAnchor: welcomeFrame) + guard returned.matches(welcomeFrame, tolerance: 1) else { + throw RealityError("Back did not restore the tour's original fitted CG frame") + } try await requireNativeTourHold(session, owned: owned, original: original) try await pressNativeTour(session, .automatic) try await waitNativeTour(session, step: "allow") try await pressNativeTour(session, .continue) try await waitNativeTour(session, step: "ready") + _ = try await fittedNativeTourFrame(session, stage: "ready", topAnchor: welcomeFrame, shorter: true) try await requireNativeTourHold(session, owned: owned, original: original) try await captureNativeTour(session, stage: "ready") try await pressNativeTour(session, .tidy) @@ -172,6 +179,7 @@ func checkNativeTourManual(_ session: RealitySession) async throws { let hooks = try RealityRecoveryHooks(kind: .tourRollback, token: UUID().uuidString) try await session.start(recoveryHooks: hooks, firstRun: true) try await waitNativeTour(session, step: "welcome") + let welcomeFrame = try await fittedNativeTourFrame(session, stage: "manual-welcome") try await captureNativeTour(session, stage: "manual-welcome") try await pressNativeTour(session, .manual) try await waitNativeTour(session, step: "allow") @@ -180,12 +188,14 @@ func checkNativeTourManual(_ session: RealitySession) async throws { try await session.expect("Native Manual selection preserves real frames") { try TourFirstRunOracle.unchanged($0, owned: owned, original: original) } + _ = try await fittedNativeTourFrame(session, stage: "manual-allow", topAnchor: welcomeFrame, shorter: true) try await captureNativeTour(session, stage: "manual-allow") for step in ["ready"] { try await pressNativeTour(session, .continue) try await waitNativeTour(session, step: step) try await requireNativeTourHold(session, owned: owned, original: original) } + _ = try await fittedNativeTourFrame(session, stage: "manual-ready", topAnchor: welcomeFrame, shorter: true) try await captureNativeTour(session, stage: "manual-ready") try await pressNativeTour(session, .continue) try await waitNativeTour(session, terminal: "success") @@ -277,6 +287,36 @@ func requireNativeTourHold(_ session: RealitySession, owned: [OwnedWindow], orig try await requireNativeAutomatic(session, enabled: false) } +@MainActor +private func fittedNativeTourFrame( + _ session: RealitySession, stage: String, topAnchor: ScreenRect? = nil, shorter: Bool = false +) async throws -> ScreenRect { + let status = try await nativeTourStatus(session) + guard let parcel = session.parcel, !parcel.isTerminated, + let id = status.visibleTourWindowNumber + else { throw RealityError("Fitting needs the owned visible tour window") } + var previous: ScreenRect? + var observed: ScreenRect? + try await session.expect("Tour \(stage) fits content with a stable top edge and width") { windows in + guard let window = windows.first(where: { $0.id == id && $0.pid == parcel.processIdentifier && $0.onscreen }) + else { return false } + let frame = window.frame + let stable = previous?.matches(frame, tolerance: 0.25) == true + previous = frame + observed = frame + guard abs(frame.width - 560) <= 1 else { return false } + if let topAnchor { + // CG coordinates start at the top of the display. + guard abs(frame.x - topAnchor.x) <= 1 && abs(frame.y - topAnchor.y) <= 1 else { return false } + if shorter && frame.height >= topAnchor.height - 32 { return false } + } + return stable + } + guard let observed else { throw RealityError("Tour fitting omitted its CG frame") } + try encodeJSON(observed, to: session.directory.appendingPathComponent("tour-fit-\(stage)-cg-frame.json")) + return observed +} + @MainActor func requireNativeAutomatic(_ session: RealitySession, enabled: Bool) async throws { struct Config: Decodable { let automatic_tiling: Bool } -- knotmirror 0.0.1 From eeeedb2fb9ad5e2222e5414d155f3916173977d4 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Fri, 6 Nov 2026 22:05:03 -0500 Subject: [PATCH 3/3] Match native tour geometry semantics Signed-off-by: Vincent Taverna --- .../Tour/TourAllowReadyScreenshotTests.swift | 3 +- .../Tour/TourCompactLayoutTests.swift | 33 ++++++++++++------- Tests/ParcelUITests/Tour/TourSetupTests.swift | 2 +- Tests/Reality/TourNativeAcceptance.swift | 3 +- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift b/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift index 58cfea84..94ba363a 100644 --- a/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift +++ b/Tests/ParcelUITests/Tour/TourAllowReadyScreenshotTests.swift @@ -125,7 +125,8 @@ extension AppKitTestSuite.PseudoLocalizationScreenshotTests { for enlarged in [false, true] { let captureName = name + (enlarged ? "-ax5" : "") try await capture( - TourSetupView(controller: learning).ignoresSafeArea(.container, edges: .top), + TourSetupView(controller: learning).fixedSize(horizontal: false, vertical: true) + .ignoresSafeArea(.container, edges: .top), size: TourSetupView.windowSize, contentSized: true, scheme: scheme, typeSize: enlarged ? .accessibility5 : .large, name: captureName, output: output, diff --git a/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift b/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift index 56b21f30..3113d768 100644 --- a/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift +++ b/Tests/ParcelUITests/Tour/TourCompactLayoutTests.swift @@ -72,14 +72,21 @@ extension AppKitTestSuite.TourSetupRenderingTests { let primary = step == .welcome ? "tour.mode.automatic" : intent == .automatic && step == .ready ? "tour.tidy" : "tour.continue" - try await waitForUI("Localized compact step has rendered its actions") { - host.layoutSubtreeIfNeeded() - guard let size = controller.setupContentSize else { return false } - window.displayIfNeeded() - return host.bounds.size == size && abs(host.fittingSize.height - size.height) < 1 - && SettingsAccessibilityElement(object: host).descendants().contains { - $0.accessibilityIdentifier() == primary - } + do { + try await waitForUI("Localized compact step has rendered its actions") { + host.layoutSubtreeIfNeeded() + guard let size = controller.setupContentSize else { return false } + window.displayIfNeeded() + return host.bounds.size == size + && SettingsAccessibilityElement(object: host).descendants().contains { + $0.accessibilityIdentifier() == primary + } + } + } catch { + Issue.record( + "Measured: \(String(describing: controller.setupContentSize)); host: \(host.bounds.size); window: \(window.frame.size)" + ) + throw error } let nodes = SettingsAccessibilityElement(object: host).descendants() #expect(!nodes.contains { $0.accessibilityRole() == .scrollArea }, "\(language) / \(step) must not scroll.") @@ -90,10 +97,12 @@ extension AppKitTestSuite.TourSetupRenderingTests { let footerFrame = try compactFrame(footer) let contentFrames = try nodes.filter { [.button, .checkBox, .staticText, .image].contains($0.accessibilityRole()) + || $0.accessibilityIdentifier() == "tour.reference.disclosure" }.map { try compactFrame($0) }.filter { $0.minY >= footerFrame.maxY } let contentBottom = try #require(contentFrames.map(\.minY).min()) - #expect(contentBottom - footerFrame.maxY <= 48, "\(language) / \(step) leaves a large empty region.") - #expect(abs(footerFrame.minY - bounds.minY) <= 1, "The footer stays at the bottom of every fitted step.") + // AX groups report their children rather than all surrounding padding. + #expect(contentBottom - footerFrame.maxY <= 80, "\(language) / \(step) leaves a large empty region.") + #expect(abs(footerFrame.minY - bounds.minY) <= 16, "The footer stays within its bottom padding.") for element in nodes where [.button, .checkBox, .staticText].contains(element.accessibilityRole()) { try #require(element.object.responds(to: NSSelectorFromString("accessibilityFrame"))) let frame = try #require(element.object.value(forKey: "accessibilityFrame") as? NSValue).rectValue @@ -158,14 +167,14 @@ extension AppKitTestSuite.TourSetupRenderingTests { let value = footer.object.value(forKey: "accessibilityFrame") as? NSValue else { return false } let bounds = window.convertToScreen(host.convert(host.bounds, to: nil)) - #expect(abs(value.rectValue.minY - bounds.minY) <= 1) + #expect(abs(value.rectValue.minY - bounds.minY) <= 16) if let original { #expect(abs(window.frame.maxY - original.maxY) <= 1) #expect(abs(window.frame.minX - original.minX) <= 1) } if let height, size.height <= height { return false } if let original, height == nil, abs(window.frame.height - original.height) > 1 { return false } - return abs(host.bounds.height - size.height) <= 1 && abs(host.fittingSize.height - size.height) < 1 + return abs(host.bounds.height - size.height) <= 1 } } try await settled() diff --git a/Tests/ParcelUITests/Tour/TourSetupTests.swift b/Tests/ParcelUITests/Tour/TourSetupTests.swift index dec3c038..ed399353 100644 --- a/Tests/ParcelUITests/Tour/TourSetupTests.swift +++ b/Tests/ParcelUITests/Tour/TourSetupTests.swift @@ -1600,7 +1600,7 @@ extension AppKitTestSuite { let fitted = try #require(learning.setupContentSize) host.frame.size = fitted host.layoutSubtreeIfNeeded() - #expect(abs(host.fittingSize.height - fitted.height) < 1) + #expect(learning.setupContentSize == fitted) #expect(host.bounds.size == fitted) #expect(fitted.width == size.width) let bitmap = try #require(host.bitmapImageRepForCachingDisplay(in: host.bounds)) diff --git a/Tests/Reality/TourNativeAcceptance.swift b/Tests/Reality/TourNativeAcceptance.swift index 3822821e..b37cbb94 100644 --- a/Tests/Reality/TourNativeAcceptance.swift +++ b/Tests/Reality/TourNativeAcceptance.swift @@ -297,7 +297,8 @@ private func fittedNativeTourFrame( else { throw RealityError("Fitting needs the owned visible tour window") } var previous: ScreenRect? var observed: ScreenRect? - try await session.expect("Tour \(stage) fits content with a stable top edge and width") { windows in + try await session.expect("Tour \(stage) fits content with a stable top edge and width") { _ in + let windows = try FrameOracle.read(allLayers: true) guard let window = windows.first(where: { $0.id == id && $0.pid == parcel.processIdentifier && $0.onscreen }) else { return false } let frame = window.frame -- knotmirror 0.0.1