From 26bafdf46793de5e89912dbfb3080bbcd78671b3 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Thu, 5 Nov 2026 05:21:45 -0500 Subject: [PATCH] Verify Tidy rollback with native window frames Signed-off-by: Vincent Taverna --- Sources/ParcelApp/AppTourIntegration.swift | 7 +- .../TourTidyEndToEndTests.swift | 28 +++++--- .../CoverageOracleTests.swift | 5 ++ .../FrameOracleTests.swift | 2 +- Tests/Reality/README.md | 1 + Tests/Reality/RealityScenarios.swift | 5 ++ Tests/Reality/RecoveryCoverageReality.swift | 2 +- Tests/Reality/TourRollbackReality.swift | 67 +++++++++++++++++++ 8 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 Tests/Reality/TourRollbackReality.swift diff --git a/Sources/ParcelApp/AppTourIntegration.swift b/Sources/ParcelApp/AppTourIntegration.swift index 8a6ffb28..fb26b739 100644 --- a/Sources/ParcelApp/AppTourIntegration.swift +++ b/Sources/ParcelApp/AppTourIntegration.swift @@ -10,6 +10,7 @@ import ServiceManagement @MainActor enum AppTourIntegration { private static var fixtureTidyFailure = false + private static var fixtureLayoutFailureCount = 0 static func actions( settings: SettingsModel, services: EngineShellServices, permissions: SystemPermissionProvider, @@ -163,7 +164,10 @@ enum AppTourIntegration { guard try await engine.perform(.setLayout(layout), in: draft.workspace).isAccepted else { throw TourSetupFailure.tidyFailed } - if fixtureTidyFailure { throw TourSetupFailure.tidyFailed } + if fixtureTidyFailure { + fixtureLayoutFailureCount += 1 + throw TourSetupFailure.tidyFailed + } guard try await engine.perform(.setWindowCap(count), in: draft.workspace).isAccepted else { throw TourSetupFailure.tidyFailed } @@ -274,6 +278,7 @@ enum AppTourIntegration { } return .object([ "accepted": .bool(true), "step": .string(setup.step.rawValue), "presented": .bool(setup.isPresented), + "failureAfterLayoutCount": .integer(Int64(fixtureLayoutFailureCount)), "skipConfirmation": .bool(setup.isSkipConfirmationPresented), "applicationActive": .bool(NSApplication.shared.isActive), "keyWindowNumber": NSApplication.shared.keyWindow.map { .integer(Int64($0.windowNumber)) } ?? .null, diff --git a/Tests/ParcelE2ETests/TourTidyEndToEndTests.swift b/Tests/ParcelE2ETests/TourTidyEndToEndTests.swift index eaf8e12e..8b5aa02a 100644 --- a/Tests/ParcelE2ETests/TourTidyEndToEndTests.swift +++ b/Tests/ParcelE2ETests/TourTidyEndToEndTests.swift @@ -14,6 +14,7 @@ private struct TourFixtureStatus: Decodable { let keyWindowNumber: Int? let keyWindowFloating: Bool let keyWindowTitled: Bool + let failureAfterLayoutCount: Int } private func configurationBytes(_ url: URL) throws -> Data? { @@ -349,15 +350,25 @@ extension RealAppEndToEndTests { try await session.command("e2e-tour", "tidy-fail-after-layout") } // The restored tour hold preserves real frames, not the paused model's calculated targets. - try await waitUntil("failed Tidy restores the original real frames") { + do { + try await waitUntil("failed Tidy restores the original real frames") { + let actual = try session.frames(for: fixture) + let restored = try await session.windows(for: fixture) + return Set(restored.map(\.id)) == Set(windows.map(\.id)) && actual.count == frames.count + && frames.allSatisfy { id, frame in actual[id].map { framesMatch($0, frame) } == true } + && restored.allSatisfy { window in + guard let observed = actual[window.id], let reported = window.frame else { return false } + return framesMatch(observed, reported) + } + } + } catch { let actual = try session.frames(for: fixture) - let restored = try await session.windows(for: fixture) - return Set(restored.map(\.id)) == Set(windows.map(\.id)) && actual.count == frames.count - && frames.allSatisfy { id, frame in actual[id].map { framesMatch($0, frame) } == true } - && restored.allSatisfy { window in - guard let observed = actual[window.id], let reported = window.frame else { return false } - return framesMatch(observed, reported) - } + let reported = try await session.windows(for: fixture) + let receipt = try await fixture.snapshot() + throw E2EError( + description: + "\(error): paused=\(paused), original=\(frames), CG=\(actual), model=\(reported), fixture=\(receipt)" + ) } let restoredWorkspace = try await session.workspace(for: session.windows(for: fixture)) #expect(restoredWorkspace.layout == workspace.layout) @@ -377,6 +388,7 @@ extension RealAppEndToEndTests { let status = try JSONDecoder().decode( TourFixtureStatus.self, from: await session.cli(["run", "--json", "e2e-tour", "status"])) #expect(status.presented && status.step == "tidy") + #expect(status.failureAfterLayoutCount == 1) try await session.command("e2e-tour", "tidy") let retried: AppConfig = try await session.query("config") diff --git a/Tests/ParcelRealitySupportTests/CoverageOracleTests.swift b/Tests/ParcelRealitySupportTests/CoverageOracleTests.swift index 4394b02b..d5062264 100644 --- a/Tests/ParcelRealitySupportTests/CoverageOracleTests.swift +++ b/Tests/ParcelRealitySupportTests/CoverageOracleTests.swift @@ -431,6 +431,11 @@ extension RealityOracleTests { let destroy = try RealityRecoveryHooks(kind: .missedDestroy, token: "owned-43") #expect(destroy.environment["PARCEL_E2E_DROP_ONE_DESTROYED"] == "1") #expect(destroy.notification.rawValue == "dev.vinnymac.parcel.e2e.owned-43.wake") + let tour = try RealityRecoveryHooks(kind: .tourRollback, token: "owned-44") + #expect( + coverageLaunchEnvironment(inherited, hooks: tour) == [ + "PARCEL_E2E": "1", "PARCEL_E2E_TOKEN": "owned-44", "PARCEL_E2E_REAL_APPS": "1", "KEEP": "yes", + ]) } @Test func privacyLifecycleReceiptDoesNotInventAnAbsentReadback() throws { diff --git a/Tests/ParcelRealitySupportTests/FrameOracleTests.swift b/Tests/ParcelRealitySupportTests/FrameOracleTests.swift index 1341156f..5849b2d2 100644 --- a/Tests/ParcelRealitySupportTests/FrameOracleTests.swift +++ b/Tests/ParcelRealitySupportTests/FrameOracleTests.swift @@ -295,7 +295,7 @@ import Testing "shortcuts", "voiceover-shortcuts", "modifier-drag", "focus-mode", "no-peek", "clean-space", "automatic-tiling-shortcut", "display-full-swap", "display-full-stack", "pause-resume", "retile", "activity", "relaunch-memory", "language-restart", "setups", "setups-hide", "spaces", "displays", - "config-reload", "stack-cycle", "reserved-edges", + "config-reload", "stack-cycle", "reserved-edges", "tour-rollback", "tour-rollback-paused", ] #expect(required.isSubset(of: unique)) for layout in ["grid", "columns", "rows", "side", "tree", "bsp", "accordion"] { diff --git a/Tests/Reality/README.md b/Tests/Reality/README.md index c885441d..c3be7b92 100644 --- a/Tests/Reality/README.md +++ b/Tests/Reality/README.md @@ -148,6 +148,7 @@ session off. A skip is not a live accessibility pass. | activity | Automatic, keyboard and mouse placement counts match independent CG movement; unchanged Retile adds zero; quit flushes and collection off removes the isolated file | | relaunch-memory | Reopened IDs regain saved layout/cap/ratio/stack frames; reopening only overflow members restores available tiles rather than a collapsed stack | | language-restart | Settings saves an isolated language choice; product restart restores real frames and retains that owned suite/config/state; cleanup removes the suite | +| tour-rollback / tour-rollback-paused | Token-scoped failed Tidy after a layout change restores three owned native documents' exact CG frames and config, holds them, then retries; paused variant starts with a hand placement | | setups | Without hiding, saved TextEdit/Notes columns reopen a freshly owned Notes process and restore both apps' saved CG tile positions | | setups-hide | With hiding on, the same restoration hides only a fresh owned Calculator process; CG confirms its disappearance and cleanup restores its visibility | | spaces | Explicit skip until two owned Spaces and Mission Control bindings are established | diff --git a/Tests/Reality/RealityScenarios.swift b/Tests/Reality/RealityScenarios.swift index 806c733d..8f8bb34a 100644 --- a/Tests/Reality/RealityScenarios.swift +++ b/Tests/Reality/RealityScenarios.swift @@ -85,6 +85,8 @@ struct RealityScenario: Sendable { Self(name: "activity", feature: "Activity counts confirmed placements and collection off stores nothing"), Self(name: "relaunch-memory", feature: "Automatic memory restores layout, cap and ratio"), Self(name: "language-restart", feature: "Language restart restores real frames before reopening"), + Self(name: "tour-rollback", feature: "Failed Tidy restores every owned native document's original frame"), + Self(name: "tour-rollback-paused", feature: "Failed Tidy restores hand placements while paused"), Self(name: "setups", feature: "Saved setup reopens an owned app and restores its real tile positions"), Self(name: "setups-hide", feature: "Saved setup hides only an owned app and restores real tile positions"), Self(name: "spaces", feature: "Native Space round trip"), @@ -107,6 +109,9 @@ extension RealityScenario { case "shortcuts-off": try await checkShortcutsOff(session); return case "phantom-gap": try await checkPhantomGap(session); return case "clean-space-sleep": try await checkCleanSpaceSimulatedSleep(session); return + case "tour-rollback", "tour-rollback-paused": + try await checkTourRollback(session, paused: name == "tour-rollback-paused") + return default: break } if name == "app-quickTime" { diff --git a/Tests/Reality/RecoveryCoverageReality.swift b/Tests/Reality/RecoveryCoverageReality.swift index 3726785a..967f4561 100644 --- a/Tests/Reality/RecoveryCoverageReality.swift +++ b/Tests/Reality/RecoveryCoverageReality.swift @@ -2,7 +2,7 @@ import AppKit import Foundation struct RealityRecoveryHooks: Sendable { - enum Kind: Equatable, Sendable { case missedDestroy, simulatedSleep } + enum Kind: Equatable, Sendable { case missedDestroy, simulatedSleep, tourRollback } let kind: Kind let token: String diff --git a/Tests/Reality/TourRollbackReality.swift b/Tests/Reality/TourRollbackReality.swift new file mode 100644 index 00000000..0942320e --- /dev/null +++ b/Tests/Reality/TourRollbackReality.swift @@ -0,0 +1,67 @@ +import Foundation + +@MainActor +func checkTourRollback(_ session: RealitySession, paused: Bool) async throws { + let hooks = try RealityRecoveryHooks(kind: .tourRollback, token: UUID().uuidString) + try session.configure(motionEnabled: true) + let owned = try await session.startingWindows([.textEdit, .textEdit, .textEdit]) + try await session.start(recoveryHooks: hooks) + try await session.tiles(owned) + if paused { + try await session.command("toggle-automatic-tiling") + let frame = try session.readFrames(owned)[0] + try await session.apps.arrange( + owned[0], + frame: ScreenRect(x: frame.x + 20, y: frame.y + 40, width: frame.width, height: frame.height * 0.7)) + } + try await tourAction(session, "begin") + for _ in 0..<3 { try await tourAction(session, "next") } + let original = try session.readFrames(owned) + let configuration = try Data(contentsOf: session.config) + try encodeJSON(original, to: session.directory.appendingPathComponent("tour-original-cg-frames.json")) + try await tourAction(session, "draft", "rows", "2", "none", "4", "stack") + try await tourAction(session, "next") + let failure = try await session.cli(["run", "--json", "e2e-tour", "tidy-fail-after-layout"]) + try encodeJSON(failure, to: session.directory.appendingPathComponent("tour-failure.json")) + guard failure.status != 0 else { throw RealityError("Injected Tidy failure unexpectedly succeeded") } + try await session.expect("Failed Tidy restores every original owned CG frame", timeout: .seconds(15)) { + zip(try FrameOracle.frames($0, ids: owned.map(\.id)), original).allSatisfy { $0.matches($1, tolerance: 1) } + } + guard try Data(contentsOf: session.config) == configuration else { + throw RealityError("Failed Tidy did not restore the original isolated configuration") + } + let holdUntil = ContinuousClock.now.advanced(by: .milliseconds(500)) + try await session.expect("The resumed tour hold preserves restored CG frames for half a second") { + guard + zip(try FrameOracle.frames($0, ids: owned.map(\.id)), original).allSatisfy({ $0.matches($1, tolerance: 1) }) + else { + throw RealityError("A late write changed a restored native document") + } + return ContinuousClock.now >= holdUntil + } + let status = try await session.cli(["run", "--json", "e2e-tour", "status"]) + guard status.status == 0 else { throw RealityError("Tour status failed: \(status.errors)") } + let progress = try JSONDecoder().decode(TourRollbackStatus.self, from: Data(status.output.utf8)) + guard progress.presented, progress.step == "tidy", progress.failureAfterLayoutCount == 1 else { + throw RealityError("Failed Tidy did not resume its review step") + } + try await tourAction(session, "tidy") + try await session.expect("Retry applies the new layout to the same owned native documents") { + !zip(try FrameOracle.frames($0, ids: owned.map(\.id)), original).allSatisfy { $0.matches($1, tolerance: 1) } + } +} + +@MainActor +private func tourAction(_ session: RealitySession, _ arguments: String...) async throws { + let result = try await session.cli(["run", "--json", "e2e-tour"] + arguments) + guard result.status == 0 else { throw RealityError("Tour action failed: \(result.output) \(result.errors)") } + let acceptance = try JSONDecoder().decode( + RealitySession.CommandAcceptance.self, from: Data(result.output.utf8)) + guard acceptance.accepted else { throw RealityError("Tour action was rejected: \(result.output)") } +} + +private struct TourRollbackStatus: Decodable { + let presented: Bool + let step: String + let failureAfterLayoutCount: Int +} -- knotmirror 0.0.1