rebenitez1802 commented on code in PR #44114:
URL: https://github.com/apache/superset/pull/44114#discussion_r3978561641


##########
tests/unit_tests/utils/webdriver_test.py:
##########
@@ -1494,6 +1529,77 @@ def 
test_report_readiness_uses_shared_deadline_and_phase_reserves(self):
 
         assert page.wait_for_function.call_args.kwargs["timeout"] == 590_000
 
+    def test_capture_readiness_wires_stable_predicate_and_timeout(self):
+        page = MagicMock()
+        element = MagicMock()
+        page.screenshot.return_value = _png("white")
+        page.evaluate.return_value = False
+
+        def signature_checked_wait(
+            expression,
+            *,
+            arg=None,
+            timeout=None,
+            polling=None,
+        ):
+            assert "__supersetCaptureReadiness" in expression
+            assert arg["stabilityMs"] == REPORT_CAPTURE_READINESS_STABILITY_MS
+
+        page.wait_for_function.side_effect = signature_checked_wait
+
+        result = WebDriverPlaywright._get_validated_screenshot(
+            page,
+            element,
+            "standalone",
+            "execution_id=test",
+            report_execution_context=_report_context(),
+        )
+
+        assert result == _png("white")
+        readiness_call = page.wait_for_function.call_args
+        assert "__supersetCaptureReadiness" in readiness_call.args[0]
+        assert (
+            readiness_call.kwargs["arg"]["stabilityMs"]
+            == REPORT_CAPTURE_READINESS_STABILITY_MS
+        )
+        assert readiness_call.kwargs["timeout"] == 690_000
+
+    def test_chart_capture_uses_chart_container_stable_predicate(self):
+        page = MagicMock()
+        element = MagicMock()
+        element.screenshot.return_value = _png("white")
+        page.evaluate.return_value = False
+
+        WebDriverPlaywright._get_validated_screenshot(
+            page,
+            element,
+            "chart-container",
+            "execution_id=test",
+            report_execution_context=_report_context(chart_id=7),
+        )
+
+        predicate = page.wait_for_function.call_args.args[0]
+        assert "document.querySelector('.chart-container')" in predicate
+
+    def test_capture_skips_stability_dwell_when_budget_is_too_short(self):
+        page = MagicMock()
+        element = MagicMock()
+        page.screenshot.return_value = _png("white")
+        page.evaluate.return_value = False
+        context = _report_context()
+        context.deadline._clock = lambda: 689.6

Review Comment:
   🔴 **Blocker — this test errors instead of running: `FrozenInstanceError`**
   
   `ReportExecutionDeadline` is a `@dataclass(frozen=True)` 
(`superset/utils/report_execution.py:119`), so `context.deadline._clock = 
lambda: 689.6` raises `dataclasses.FrozenInstanceError: cannot assign to field 
'_clock'` before any assertion runs. Running `pytest 
tests/unit_tests/utils/webdriver_test.py 
tests/unit_tests/utils/test_screenshot_utils.py` locally gives **`1 failed, 135 
passed`**.
   
   Beyond reddening the backend suite, this means the near-deadline **skip** 
path — the fix for the readiness-dwell regression — currently has no *passing* 
end-to-end coverage; only the helper-level 
`test_stable_readiness_skips_impossible_dwell` exercises it.
   
   Rebuild the frozen deadline instead of mutating it. Verified locally: the 
test then passes and actually drives the skip branch (`available = 210.4 − 210 
= 0.4s ≤ 0.5s`, so `wait_for_function` is skipped and capture proceeds):
   
   ```suggestion
           from dataclasses import replace
   
           context = _report_context()
           context = replace(
               context,
               deadline=replace(context.deadline, _clock=lambda: 689.6),
           )
   ```
   
   (A local `from dataclasses import replace` matches the file's existing 
in-test import style, e.g. 
`test_report_readiness_budget_exhaustion_skips_poll_and_capture`.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to