From 20f3aa8c15968c434ad2428280fac614d907df6d Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sun, 1 Nov 2026 00:59:57 -0400 Subject: [PATCH 1/2] fix(smoke): stop Calculator, Text Editor and Settings lookups waiting far too long when the app is missing Closes #1038 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- .../features/steps/gnome_calculator_steps.py | 12 ++-- .../features/steps/gnome_settings_steps.py | 18 ++---- .../features/steps/gnome_text_editor_steps.py | 12 ++-- tests/unit/test_gnome_calculator_steps.py | 22 +++++++ tests/unit/test_gnome_settings_steps.py | 12 ++++ tests/unit/test_gnome_text_editor_steps.py | 58 +++++++++++-------- 6 files changed, 88 insertions(+), 46 deletions(-) diff --git a/tests/smoke/features/steps/gnome_calculator_steps.py b/tests/smoke/features/steps/gnome_calculator_steps.py index 236a4433e..c7466c3db 100644 --- a/tests/smoke/features/steps/gnome_calculator_steps.py +++ b/tests/smoke/features/steps/gnome_calculator_steps.py @@ -42,12 +42,14 @@ def _skip_if_no_atspi(context) -> bool: def _calculator_app(): + """Take one ``applications()`` snapshot; dogtail's per-name lookup retries internally.""" last_error = None - for name in CALCULATOR_APP_NAMES: - try: - return tree.root.application(name) - except Exception as exc: # noqa: BLE001 - last_error = exc + try: + for app in tree.root.applications(): + if (getattr(app, "name", "") or "").strip("'\" ") in CALCULATOR_APP_NAMES: + return app + except Exception as exc: # noqa: BLE001 + last_error = exc raise AssertionError( f"GNOME Calculator application was not found via AT-SPI: {last_error}" ) diff --git a/tests/smoke/features/steps/gnome_settings_steps.py b/tests/smoke/features/steps/gnome_settings_steps.py index 9020b678c..26c82f3b8 100644 --- a/tests/smoke/features/steps/gnome_settings_steps.py +++ b/tests/smoke/features/steps/gnome_settings_steps.py @@ -80,21 +80,13 @@ def _settings_app(timeout: int = 15): clean = name.strip("'\" ") if clean in SETTINGS_APP_NAMES or "settings" in clean.lower() or "control-center" in clean.lower(): return app - except Exception: # noqa: BLE001 - pass - for name in SETTINGS_APP_NAMES: - try: - return tree.root.application(name) - except Exception as exc: # noqa: BLE001 - last_error = exc - if time.monotonic() >= deadline: - break - sleep(0.5) - for name in SETTINGS_APP_NAMES: - try: - return tree.root.application(name) + last_error = f"none of {SETTINGS_APP_NAMES} registered" except Exception as exc: # noqa: BLE001 last_error = exc + remaining = deadline - time.monotonic() + if remaining <= 0: + break + sleep(min(0.5, remaining)) raise AssertionError(f"GNOME Settings application was not found via AT-SPI after {timeout}s: {last_error}") diff --git a/tests/smoke/features/steps/gnome_text_editor_steps.py b/tests/smoke/features/steps/gnome_text_editor_steps.py index 12a45991a..e55c8d27a 100644 --- a/tests/smoke/features/steps/gnome_text_editor_steps.py +++ b/tests/smoke/features/steps/gnome_text_editor_steps.py @@ -35,12 +35,14 @@ def _skip_if_no_atspi(context) -> bool: def _text_editor_app(): + """Take one ``applications()`` snapshot; dogtail's per-name lookup retries internally.""" last_error = None - for name in TEXT_EDITOR_APP_NAMES: - try: - return tree.root.application(name) - except Exception as exc: # noqa: BLE001 - last_error = exc + try: + for app in tree.root.applications(): + if (getattr(app, "name", "") or "").strip("'\" ") in TEXT_EDITOR_APP_NAMES: + return app + except Exception as exc: # noqa: BLE001 + last_error = exc raise AssertionError( f"GNOME Text Editor application was not found via AT-SPI: {last_error}" ) diff --git a/tests/unit/test_gnome_calculator_steps.py b/tests/unit/test_gnome_calculator_steps.py index 9c00631f9..73e8bbcdd 100644 --- a/tests/unit/test_gnome_calculator_steps.py +++ b/tests/unit/test_gnome_calculator_steps.py @@ -244,3 +244,25 @@ def test_visible_app_fails_within_nominal_budget(self, monkeypatch): m.calculator_is_no_longer_running(MagicMock()) assert clock.now == 10.0 # 20 polls x 0.5s, nothing multiplied assert root.application_calls == [] + + +class TestCalculatorApp: + def _run(self, monkeypatch, apps): + m = _import_calculator_steps() + clock = types.SimpleNamespace(now=0.0) + root = _RetryingRoot(clock, apps) + monkeypatch.setattr(m, "tree", types.SimpleNamespace(root=root)) + return m, clock, root + + def test_returns_app_matching_any_alias(self, monkeypatch): + app = _App("Calculator") + m, clock, root = self._run(monkeypatch, [_App("gnome-shell"), app]) + assert m._calculator_app() is app + assert root.application_calls == [] + + def test_missing_app_fails_without_retrying_lookup(self, monkeypatch): + m, clock, root = self._run(monkeypatch, []) + with pytest.raises(AssertionError, match="GNOME Calculator application was not found"): + m._calculator_app() + assert clock.now == 0.0 + assert root.application_calls == [] diff --git a/tests/unit/test_gnome_settings_steps.py b/tests/unit/test_gnome_settings_steps.py index 05e687b47..053434c6d 100644 --- a/tests/unit/test_gnome_settings_steps.py +++ b/tests/unit/test_gnome_settings_steps.py @@ -129,6 +129,18 @@ def test_finds_settings_via_applications_list(self): assert result is app + def test_missing_app_fails_within_nominal_budget(self, monkeypatch): + clock = SimpleNamespace(now=0.0) + root = _RetryingRoot(clock) + monkeypatch.setattr(self.mod, "tree", SimpleNamespace(root=root)) + monkeypatch.setattr(self.mod, "sleep", lambda s: setattr(clock, "now", clock.now + s)) + monkeypatch.setattr("time.monotonic", lambda: clock.now) + with pytest.raises(AssertionError, match="GNOME Settings application was not found"): + self.mod._settings_app(timeout=2) + assert clock.now == 2.0 # deadline holds; no per-alias retry waits + assert root.application_calls == [] + + class _RetryingRoot: """``tree.root`` whose per-name lookup costs dogtail's default retry wait.""" diff --git a/tests/unit/test_gnome_text_editor_steps.py b/tests/unit/test_gnome_text_editor_steps.py index 7ffeaabdb..1c44c5fbc 100644 --- a/tests/unit/test_gnome_text_editor_steps.py +++ b/tests/unit/test_gnome_text_editor_steps.py @@ -122,35 +122,40 @@ def setup_method(self): def test_returns_first_matching_app(self): mock_app = MagicMock() + mock_app.name = "gnome-text-editor" tree_mock = MagicMock() - tree_mock.root.application.return_value = mock_app + tree_mock.root.applications.return_value = [mock_app] with patch.object(self.m, "tree", tree_mock): result = self.m._text_editor_app() assert result is mock_app - def test_tries_next_name_when_first_raises(self): - mock_app = MagicMock() - call_count = {"n": 0} - - def side_effect(name): - call_count["n"] += 1 - if call_count["n"] == 1: - raise RuntimeError("not found") - return mock_app - + def test_matches_any_alias_in_snapshot(self): + other = MagicMock() + other.name = "gnome-shell" + editor = MagicMock() + editor.name = "Text Editor" tree_mock = MagicMock() - tree_mock.root.application.side_effect = side_effect + tree_mock.root.applications.return_value = [other, editor] with patch.object(self.m, "tree", tree_mock): result = self.m._text_editor_app() - assert result is mock_app - assert call_count["n"] == 2 + assert result is editor + tree_mock.root.application.assert_not_called() - def test_raises_assertion_error_when_all_names_fail(self): + def test_raises_without_per_alias_lookup_when_app_missing(self): tree_mock = MagicMock() - tree_mock.root.application.side_effect = RuntimeError("not found") + tree_mock.root.applications.return_value = [] with patch.object(self.m, "tree", tree_mock): with pytest.raises(AssertionError, match="GNOME Text Editor application was not found"): self.m._text_editor_app() + tree_mock.root.application.assert_not_called() + + def test_reports_snapshot_error(self): + tree_mock = MagicMock() + tree_mock.root.applications.side_effect = RuntimeError("bus gone") + with patch.object(self.m, "tree", tree_mock): + with pytest.raises(AssertionError, match="bus gone"): + self.m._text_editor_app() + tree_mock.root.application.assert_not_called() # --------------------------------------------------------------------------- @@ -540,7 +545,8 @@ def test_sets_context_save_dialog_when_found(self): context = MagicMock() app, dialog = self._make_app_with_save_dialog() tree_mock = MagicMock() - tree_mock.root.application.return_value = app + app.name = "gnome-text-editor" + tree_mock.root.applications.return_value = [app] with patch.object(self.m, "tree", tree_mock), \ patch("time.sleep"): self.m.text_editor_save_dialog_is_open(context) @@ -550,7 +556,8 @@ def test_raises_when_no_save_dialog_found(self): app = MagicMock() app.findChildren.return_value = [] tree_mock = MagicMock() - tree_mock.root.application.return_value = app + app.name = "gnome-text-editor" + tree_mock.root.applications.return_value = [app] with patch.object(self.m, "tree", tree_mock), \ patch("time.sleep"): with pytest.raises(AssertionError, match="save dialog was not found"): @@ -579,7 +586,8 @@ def app_find(pred): app.findChildren.side_effect = app_find tree_mock = MagicMock() - tree_mock.root.application.return_value = app + app.name = "gnome-text-editor" + tree_mock.root.applications.return_value = [app] with patch.object(self.m, "tree", tree_mock), \ patch("time.sleep"): self.m.text_editor_save_dialog_is_open(context) @@ -621,7 +629,8 @@ def test_sets_context_discard_dialog_when_found(self): context = MagicMock() app, dialog = self._make_app_with_discard_dialog() tree_mock = MagicMock() - tree_mock.root.application.return_value = app + app.name = "gnome-text-editor" + tree_mock.root.applications.return_value = [app] with patch.object(self.m, "tree", tree_mock), \ patch("time.sleep"): self.m.text_editor_discard_dialog_is_open(context) @@ -650,7 +659,8 @@ def app_find(pred): app.findChildren.side_effect = app_find tree_mock = MagicMock() - tree_mock.root.application.return_value = app + app.name = "gnome-text-editor" + tree_mock.root.applications.return_value = [app] with patch.object(self.m, "tree", tree_mock), \ patch("time.sleep"): with pytest.raises(AssertionError, match="discard dialog"): @@ -660,7 +670,8 @@ def test_raises_when_no_dialogs_at_all(self): app = MagicMock() app.findChildren.return_value = [] tree_mock = MagicMock() - tree_mock.root.application.return_value = app + app.name = "gnome-text-editor" + tree_mock.root.applications.return_value = [app] with patch.object(self.m, "tree", tree_mock), \ patch("time.sleep"): with pytest.raises(AssertionError, match="discard dialog"): @@ -689,7 +700,8 @@ def app_find(pred): app.findChildren.side_effect = app_find tree_mock = MagicMock() - tree_mock.root.application.return_value = app + app.name = "gnome-text-editor" + tree_mock.root.applications.return_value = [app] with patch.object(self.m, "tree", tree_mock), \ patch("time.sleep"): self.m.text_editor_discard_dialog_is_open(context) From 85c9364201e9fdc387057d16595b5b77da4c7eab Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sun, 1 Nov 2026 02:30:24 -0500 Subject: [PATCH 2/2] fix(smoke): name the missing Calculator/Text Editor aliases in lookup errors Empty applications() snapshots raised '... not found via AT-SPI: None'. Mirror _settings_app and report which aliases were not registered. Also drop the stale Firefox per-name fallback description from the GNOME test-authoring skill doc. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- docs/skills/test-authoring/gnome/SKILL.md | 2 +- tests/smoke/features/steps/gnome_calculator_steps.py | 3 ++- tests/smoke/features/steps/gnome_text_editor_steps.py | 3 ++- tests/unit/test_gnome_calculator_steps.py | 2 +- tests/unit/test_gnome_text_editor_steps.py | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/skills/test-authoring/gnome/SKILL.md b/docs/skills/test-authoring/gnome/SKILL.md index e788cd96e..0f4e41216 100644 --- a/docs/skills/test-authoring/gnome/SKILL.md +++ b/docs/skills/test-authoring/gnome/SKILL.md @@ -160,7 +160,7 @@ In GNOME 50: In GNOME 50, Firefox exposes its top-level window as `filler` or `frame` in AT-SPI, while web content and iframes within tabs also expose nested `frame` nodes (often containing child widgets such as `push button`). When tabs crash under containerized or headless environments, Firefox may also spawn `Tab crash reporter — Mozilla Firefox` frame nodes in the AT-SPI tree. To resolve the genuine browser window reliably: -1. Resolve the app with `_firefox_app()`, which first scans the live `tree.root.applications()` list matching `FIREFOX_APP_NAMES` case-insensitively, then falls back to per-name `tree.root.application()` lookups, polling until a short elapsed-time deadline (3 s by default). Keep `"Firefox"` (the name GNOME 50 registers) first in `FIREFOX_APP_NAMES` so the fallback lookup hits on its first attempt. +1. Resolve the app with `_firefox_app()`, which first scans the live `tree.root.applications()` list matching `FIREFOX_APP_NAMES` case-insensitively (falling back to the qecore `context.firefox.instance`), polling until a short elapsed-time deadline (3 s by default). There is no per-name `tree.root.application()` fallback: dogtail retries that call internally, multiplying the deadline. 2. Filter out Mozilla crash reporter windows (`"crash reporter" in name.lower()`) so stale or crashed frames carrying a `page tab list` are not misidentified as browser windows. 3. Prioritize top-level candidates (`app.children`) before recursive searching, and require genuine browser chrome: `combo box`, `entry`, `autocomplete`, or `page tab list`. In GNOME 50, the Firefox address bar exposes role `combo box` (name `"Search with Google or enter address"`), and buttons use role `button`. 4. In headless Wayland container environments where `/dev/uinput` evdev keystrokes are not routed to windows by the compositor, provide an AT-SPI fallback via `atspi_click` targeting the `"Open a new tab (Ctrl+T)"` and tab `"Close tab"` buttons. diff --git a/tests/smoke/features/steps/gnome_calculator_steps.py b/tests/smoke/features/steps/gnome_calculator_steps.py index c7466c3db..cd0882a81 100644 --- a/tests/smoke/features/steps/gnome_calculator_steps.py +++ b/tests/smoke/features/steps/gnome_calculator_steps.py @@ -51,7 +51,8 @@ def _calculator_app(): except Exception as exc: # noqa: BLE001 last_error = exc raise AssertionError( - f"GNOME Calculator application was not found via AT-SPI: {last_error}" + f"GNOME Calculator application was not found via AT-SPI: " + f"{last_error or f'none of {CALCULATOR_APP_NAMES} registered'}" ) diff --git a/tests/smoke/features/steps/gnome_text_editor_steps.py b/tests/smoke/features/steps/gnome_text_editor_steps.py index e55c8d27a..0d77a3551 100644 --- a/tests/smoke/features/steps/gnome_text_editor_steps.py +++ b/tests/smoke/features/steps/gnome_text_editor_steps.py @@ -44,7 +44,8 @@ def _text_editor_app(): except Exception as exc: # noqa: BLE001 last_error = exc raise AssertionError( - f"GNOME Text Editor application was not found via AT-SPI: {last_error}" + f"GNOME Text Editor application was not found via AT-SPI: " + f"{last_error or f'none of {TEXT_EDITOR_APP_NAMES} registered'}" ) diff --git a/tests/unit/test_gnome_calculator_steps.py b/tests/unit/test_gnome_calculator_steps.py index 73e8bbcdd..ec2008953 100644 --- a/tests/unit/test_gnome_calculator_steps.py +++ b/tests/unit/test_gnome_calculator_steps.py @@ -262,7 +262,7 @@ def test_returns_app_matching_any_alias(self, monkeypatch): def test_missing_app_fails_without_retrying_lookup(self, monkeypatch): m, clock, root = self._run(monkeypatch, []) - with pytest.raises(AssertionError, match="GNOME Calculator application was not found"): + with pytest.raises(AssertionError, match="GNOME Calculator application was not found via AT-SPI: none of .* registered"): m._calculator_app() assert clock.now == 0.0 assert root.application_calls == [] diff --git a/tests/unit/test_gnome_text_editor_steps.py b/tests/unit/test_gnome_text_editor_steps.py index 1c44c5fbc..a140140e8 100644 --- a/tests/unit/test_gnome_text_editor_steps.py +++ b/tests/unit/test_gnome_text_editor_steps.py @@ -145,7 +145,7 @@ def test_raises_without_per_alias_lookup_when_app_missing(self): tree_mock = MagicMock() tree_mock.root.applications.return_value = [] with patch.object(self.m, "tree", tree_mock): - with pytest.raises(AssertionError, match="GNOME Text Editor application was not found"): + with pytest.raises(AssertionError, match="GNOME Text Editor application was not found via AT-SPI: none of .* registered"): self.m._text_editor_app() tree_mock.root.application.assert_not_called()