-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
cua-driver: fix #1481 app name resolution — bundle ID + locale fallbacks #1492
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
110 changes: 110 additions & 0 deletions
110
libs/cua-driver/Tests/integration/test_app_name_locale_fallback.py
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 |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """Integration test: app name resolution fallback (#1481). | ||
|
|
||
| Verifies that launch_app accepts more than just the exact bundle-file name: | ||
|
|
||
| 1. Bundle ID passed as `name` (e.g. "com.apple.calculator") resolves via | ||
| LaunchServices — callers don't need to use the `bundle_id` parameter. | ||
|
|
||
| 2. Case-insensitive match on CFBundleName / display name works so | ||
| "calculator" and "CALCULATOR" both resolve to Calculator.app. | ||
|
|
||
| 3. Exact name still works (regression guard). | ||
|
|
||
| The JP-locale localizedName path ("計算機") cannot be exercised on an EN | ||
| locale machine; that path is exercised by the same NSRunningApplication | ||
| localizedName lookup and would pass on a JP-locale host. | ||
|
|
||
| Run: | ||
| scripts/test.sh test_app_name_locale_fallback | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import subprocess | ||
| import sys | ||
| import time | ||
| import unittest | ||
|
|
||
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||
| from driver_client import DriverClient, default_binary_path, reset_calculator | ||
|
|
||
| CALCULATOR_BUNDLE = "com.apple.calculator" | ||
|
|
||
|
|
||
| def _kill_calc() -> None: | ||
| subprocess.run(["pkill", "-x", "Calculator"], check=False) | ||
| time.sleep(0.4) | ||
|
|
||
|
|
||
| class AppNameLocaleFallbackTests(unittest.TestCase): | ||
| """launch_app name= accepts bundle IDs and case-insensitive display names.""" | ||
|
|
||
| def setUp(self) -> None: | ||
| reset_calculator() | ||
| self.client = DriverClient(default_binary_path()).__enter__() | ||
|
|
||
| def tearDown(self) -> None: | ||
| self.client.__exit__(None, None, None) | ||
| _kill_calc() | ||
|
|
||
| def _launch_by_name(self, name: str) -> dict: | ||
| result = self.client.call_tool("launch_app", {"name": name}) | ||
| return result | ||
|
|
||
| def test_bundle_id_as_name_resolves(self) -> None: | ||
| """Bundle ID string passed as name= launches the correct app.""" | ||
| result = self._launch_by_name(CALCULATOR_BUNDLE) | ||
| self.assertFalse( | ||
| result.get("isError"), | ||
| f"launch_app(name='{CALCULATOR_BUNDLE}') failed: {result}", | ||
| ) | ||
| sc = result.get("structuredContent", {}) | ||
| self.assertEqual( | ||
| sc.get("bundle_id"), | ||
| CALCULATOR_BUNDLE, | ||
| f"Unexpected bundle_id in response: {sc}", | ||
| ) | ||
| self.assertGreater(sc.get("pid", 0), 0) | ||
|
|
||
| def test_case_insensitive_name_lowercase(self) -> None: | ||
| """Lowercase name= ('calculator') matches Calculator.app.""" | ||
| result = self._launch_by_name("calculator") | ||
| self.assertFalse( | ||
| result.get("isError"), | ||
| f"launch_app(name='calculator') failed: {result}", | ||
| ) | ||
| sc = result.get("structuredContent", {}) | ||
| self.assertEqual(sc.get("bundle_id"), CALCULATOR_BUNDLE) | ||
|
|
||
| def test_case_insensitive_name_uppercase(self) -> None: | ||
| """All-caps name= ('CALCULATOR') matches Calculator.app.""" | ||
| result = self._launch_by_name("CALCULATOR") | ||
| self.assertFalse( | ||
| result.get("isError"), | ||
| f"launch_app(name='CALCULATOR') failed: {result}", | ||
| ) | ||
| sc = result.get("structuredContent", {}) | ||
| self.assertEqual(sc.get("bundle_id"), CALCULATOR_BUNDLE) | ||
|
|
||
| def test_exact_name_still_works(self) -> None: | ||
| """Exact canonical name= ('Calculator') still works (regression guard).""" | ||
| result = self._launch_by_name("Calculator") | ||
| self.assertFalse( | ||
| result.get("isError"), | ||
| f"launch_app(name='Calculator') failed: {result}", | ||
| ) | ||
| sc = result.get("structuredContent", {}) | ||
| self.assertEqual(sc.get("bundle_id"), CALCULATOR_BUNDLE) | ||
|
|
||
| def test_unknown_name_returns_error(self) -> None: | ||
| """Completely unknown name returns isError (not a silent empty result).""" | ||
| result = self._launch_by_name("ThisAppDefinitelyDoesNotExist_xyzzy") | ||
| self.assertTrue( | ||
| result.get("isError"), | ||
| f"Expected isError for unknown app name, got: {result}", | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
CFBundle fallback order is implemented incorrectly
On Line 294-Line 299,
CFBundleDisplayName ?? CFBundleName ?? stemonly tests one value. IfCFBundleDisplayNameexists but doesn’t match,CFBundleNameis never compared, so valid names can still fail resolution.Suggested fix
🤖 Prompt for AI Agents