From 90831a1b3fc52d8392435e655a0d55e0a7b19a3b Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 26 Aug 2026 20:25:12 +0530 Subject: [PATCH] test(desktop): isolate FloatingBar notification owner authority Same defect #12192 fixes in RewindCaptureExclusionGenerationTests, in a suite that issue #12039 did not name. Both owner-seeding tests wrote auth_userId directly: defaults.set(owner, forKey: DefaultsKey.authUserId.rawValue) Runtime owner authorization is process-wide and fails closed on exactly that write: RuntimeOwnerIdentity.swift:51 calls revokeUnexpectedOwnerMismatch() once the authority has bootstrapped a different owner, and stays revoked without a real transition. So the result depended on whether an owner-bound suite ran first. Both tests now establish their owner through RuntimeOwnerAuthorityTestFixture, which crosses the same serialized transition boundary production uses, and restore in tearDown rather than a defer -- a defer cannot await, and more importantly a failed assertion must not leave the process-wide authority revoked for whatever runs next. Adopting the fixture also enrolls this suite in the runner's derived owner-isolation cluster, since swift-test-suites.sh greps for that symbol. Verified the guard does the work rather than assuming it. Same command, same three owner-bound suites, only the fix differing: before: Executed 28 tests, with 1 failure FloatingBarNotificationPreviewPolicyTests.swift:218: error: XCTAssertEqual failed: ("rejectedOwnerChange") is not equal to ("suppressed") after: Executed 28 tests, with 0 failures In isolation the suite passed both before and after (19/19), which is why the flake read as nondeterministic. Failure-Class: FC-hand-listed-test-isolation-membership --- ...ingBarNotificationPreviewPolicyTests.swift | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/desktop/macos/Desktop/Tests/FloatingBarNotificationPreviewPolicyTests.swift b/desktop/macos/Desktop/Tests/FloatingBarNotificationPreviewPolicyTests.swift index 25d9c2b498a..6f419b7c774 100644 --- a/desktop/macos/Desktop/Tests/FloatingBarNotificationPreviewPolicyTests.swift +++ b/desktop/macos/Desktop/Tests/FloatingBarNotificationPreviewPolicyTests.swift @@ -12,6 +12,23 @@ import XCTest /// enabled is the one case that falls back to a native system banner so the /// notification is never fully silenced. final class FloatingBarNotificationPreviewPolicyTests: XCTestCase { + /// Runtime owner authorization is process-wide and fails closed on an + /// out-of-band `authUserId` write, staying revoked for every later suite in + /// the xctest process. The two owner-seeding tests below therefore establish + /// their owner through the production transition boundary, and restore runs + /// in `tearDown` rather than a `defer` so a failed assertion cannot leave the + /// authority revoked for whatever runs next. + private var ownerFixture: RuntimeOwnerAuthorityTestFixture? + + override func setUp() async throws { + ownerFixture = await RuntimeOwnerAuthorityTestFixture() + } + + override func tearDown() async throws { + await ownerFixture?.restore() + ownerFixture = nil + } + func testPreviewsAndBarEnabledShowsPreviewWithNoForcedBanner() { XCTAssertTrue( FloatingBarNotificationPreviewPolicy.shouldShowInBarPreview( @@ -166,11 +183,9 @@ final class FloatingBarNotificationPreviewPolicyTests: XCTestCase { /// `presentContextDirectorNotification` makes this call return `.queued` from the /// banner path instead of `.suppressed`, failing the test. @MainActor - func testDirectorDeliveryWithDisabledCategoryToggleIsSuppressedAtTheEntryPoint() throws { + func testDirectorDeliveryWithDisabledCategoryToggleIsSuppressedAtTheEntryPoint() async throws { let defaults = UserDefaults.standard let pinnedKeys = [ - DefaultsKey.authUserId.rawValue, - DefaultsKey.automationOwnerOverride.rawValue, NotificationService.masterEnabledDefaultsKey, NotificationService.frequencyDefaultsKey, DefaultsKey.desktopIsPaywalled.rawValue, @@ -192,8 +207,8 @@ final class FloatingBarNotificationPreviewPolicyTests: XCTestCase { } let owner = "owner-category-gate-\(UUID().uuidString)" - defaults.set(owner, forKey: DefaultsKey.authUserId.rawValue) - defaults.removeObject(forKey: DefaultsKey.automationOwnerOverride.rawValue) + let fixture = try XCTUnwrap(ownerFixture) + await fixture.establish(authOwnerID: owner) defaults.set(true, forKey: NotificationService.masterEnabledDefaultsKey) defaults.set(5, forKey: NotificationService.frequencyDefaultsKey) defaults.set(false, forKey: DefaultsKey.desktopIsPaywalled.rawValue) @@ -228,11 +243,9 @@ final class FloatingBarNotificationPreviewPolicyTests: XCTestCase { /// host cannot perform, failing the test; with the gate present they return /// before any surface and leave the presentation ledger untouched. @MainActor - func testGoalAndMeetingProducersHonorTheirCategoryTogglesAtTheSharedBoundary() throws { + func testGoalAndMeetingProducersHonorTheirCategoryTogglesAtTheSharedBoundary() async throws { let defaults = UserDefaults.standard let pinnedKeys = [ - DefaultsKey.authUserId.rawValue, - DefaultsKey.automationOwnerOverride.rawValue, NotificationService.masterEnabledDefaultsKey, NotificationService.frequencyDefaultsKey, DefaultsKey.desktopIsPaywalled.rawValue, @@ -256,8 +269,8 @@ final class FloatingBarNotificationPreviewPolicyTests: XCTestCase { } let owner = "owner-producer-gate-\(UUID().uuidString)" - defaults.set(owner, forKey: DefaultsKey.authUserId.rawValue) - defaults.removeObject(forKey: DefaultsKey.automationOwnerOverride.rawValue) + let fixture = try XCTUnwrap(ownerFixture) + await fixture.establish(authOwnerID: owner) defaults.set(true, forKey: NotificationService.masterEnabledDefaultsKey) defaults.set(5, forKey: NotificationService.frequencyDefaultsKey) defaults.set(false, forKey: DefaultsKey.desktopIsPaywalled.rawValue)