-
Notifications
You must be signed in to change notification settings - Fork 400
Harden teardown guards and keychain no-UI query handling #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
artuskg
wants to merge
10
commits into
steipete:main
Choose a base branch
from
artuskg:codex/fix-menu-refresh-teardown-warning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e9dfbc
Guard menu refresh teardown paths in tests
artuskg 674a2b8
Restore strict no-UI keychain query policy
artuskg 651a37e
Harden menu refresh gating and test cleanup
artuskg 9ef63ae
Add runtime-toggle regression coverage for menu refresh
artuskg 6b4152a
Fix keychain no-UI policy constant handling
artuskg 34a3621
Guard Darwin import for non-macOS builds
artuskg c685354
Harden test teardown and serialize animation suite
artuskg ddb1c94
Gate test-time UI mutations after teardown
artuskg 71451a3
Close remaining teardown guard gaps
artuskg 428fd68
Guard login refresh after test teardown
artuskg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,41 @@ | ||
| import Foundation | ||
|
|
||
| #if os(macOS) | ||
| import Darwin | ||
| import LocalAuthentication | ||
| import Security | ||
|
|
||
| enum KeychainNoUIQuery { | ||
| private static let uiFailPolicy = KeychainNoUIQuery.resolveUIFailPolicy() | ||
|
|
||
| static func apply(to query: inout [String: Any]) { | ||
| let context = LAContext() | ||
| context.interactionNotAllowed = true | ||
| query[kSecUseAuthenticationContext as String] = context | ||
|
|
||
| // NOTE: While Apple recommends using LAContext.interactionNotAllowed, that alone is not sufficient to | ||
| // prevent the legacy keychain "Allow/Deny" prompt on some configurations. We also set the UI policy to fail | ||
| // so SecItemCopyMatching returns errSecInteractionNotAllowed instead of showing UI. | ||
| query[kSecUseAuthenticationUI as String] = kSecUseAuthenticationUIFail | ||
| // Keep explicit UI-fail policy for legacy keychain behavior on macOS where | ||
| // `interactionNotAllowed` alone can still surface Allow/Deny prompts. | ||
| query[kSecUseAuthenticationUI as String] = self.uiFailPolicy as CFString | ||
| } | ||
|
|
||
| static func uiFailPolicyForTesting() -> String { | ||
| self.uiFailPolicy | ||
| } | ||
|
|
||
| private static func resolveUIFailPolicy() -> String { | ||
| // Resolve the Security symbol at runtime to preserve the true constant value | ||
| // without directly referencing deprecated API at compile time. | ||
| let securityPath = "/System/Library/Frameworks/Security.framework/Security" | ||
| guard let handle = dlopen(securityPath, RTLD_NOW) else { | ||
| return "u_AuthUIF" | ||
| } | ||
| defer { dlclose(handle) } | ||
|
|
||
| guard let symbol = dlsym(handle, "kSecUseAuthenticationUIFail") else { | ||
| return "u_AuthUIF" | ||
| } | ||
| let valuePointer = symbol.assumingMemoryBound(to: CFString?.self) | ||
| return (valuePointer.pointee as String?) ?? "u_AuthUIF" | ||
| } | ||
| } | ||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
releaseStatusItemsForTesting()only cancelsloginTask, but an in-flight switch-account task still runs itsdefer(activeLoginProvider = nil,loginTask = nil), and those property observers callrefreshMenusForLoginStateChange()which still reachesattachMenus()without anisReleasedForTestingguard. In tests that tear down while login is in progress, this can recreate/mutate status items after teardown and reintroduce the post-release AppKit mutation race this change is trying to prevent.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in
428fd68.What changed:
refreshMenusForLoginStateChange()so login-task/property-observer callbacks no-op afterreleaseStatusItemsForTesting().Added regression test:
loginStateCallbacksDoNotAttachMenusAfterRelease()inTests/CodexBarTests/StatusMenuTests.swiftto verify login-state callbacks after release do not reattach menus or recreate status items.Validation rerun:
pnpm check./Scripts/compile_and_run.shBoth passed.