diff --git a/packages/flow/openadapt_flow/backends/win_agent/server.py b/packages/flow/openadapt_flow/backends/win_agent/server.py index 53fc9b1448..9c9f1a1460 100644 --- a/packages/flow/openadapt_flow/backends/win_agent/server.py +++ b/packages/flow/openadapt_flow/backends/win_agent/server.py @@ -1336,14 +1336,26 @@ def incomplete(stage: str, error: Exception | None = None): return incomplete("ancestor_depth") except Exception as exc: # noqa: BLE001 - unknown query scope is incomplete return incomplete("selector", exc) - try: - candidate = _candidate( - control, get=_read_control_value if strict_walk else _control_value - ) - except Exception as exc: # noqa: BLE001 - changing sensitive metadata is no complete census - if strict_walk: - return incomplete("candidate_properties", exc) - raise + if strict_walk and not possible: + # The guarded facts above already rule this control out: its + # AutomationId, Name and role are the same values _candidate would + # compare, so it can't match. Skipping the second, guarded read of + # its metadata, bounds and window ancestry changes no match set, + # and keeps a census of a large window inside the client's + # timeout. (A control whose guard starts refusing after its facts + # were read no longer marks the census incomplete; its facts + # already ruled it out.) + candidate = None + else: + try: + candidate = _candidate( + control, + get=_read_control_value if strict_walk else _control_value, + ) + except Exception as exc: # noqa: BLE001 - changing sensitive metadata is no complete census + if strict_walk: + return incomplete("candidate_properties", exc) + raise if strict_walk and possible and candidate is None: return incomplete("candidate_unavailable") if candidate is not None: diff --git a/packages/flow/tests/e2e/test_windows_approval_completeness.py b/packages/flow/tests/e2e/test_windows_approval_completeness.py index 69ec24a5e2..6ed470730a 100644 --- a/packages/flow/tests/e2e/test_windows_approval_completeness.py +++ b/packages/flow/tests/e2e/test_windows_approval_completeness.py @@ -109,7 +109,9 @@ def _command(root: Path, command: str) -> dict: temporary = root / "approval-command.tmp" temporary.write_text(command) temporary.replace(root / "approval-command") - deadline = time.monotonic() + 15 + # A cold Windows PowerShell WinForms start on a hosted runner can take + # longer than 15 s before its timer answers the first command. + deadline = time.monotonic() + 60 while not ack.is_file(): assert time.monotonic() < deadline, "synthetic approval fixture timed out" time.sleep(0.05) @@ -297,15 +299,25 @@ def identity(): int((rect.left + rect.right) / 2), int((rect.top + rect.bottom) / 2), ) + # Each phase is its own run with exactly one verified window: the + # "long" phase relaunches the app in a new window, and captures + # from an earlier window would make the approval window ambiguous, + # so the approval read would refuse before reaching the agent. + backend.clear_verified_windows() assert backend.record_verified_window("probe", *point) + projections_before = sum( + 1 for e in evidence["transport"] if e["path"] == "/window/form-fields" + ) fields = backend.approval_form_fields("save") + # This phase must have sent its own form-fields request, so the + # refusal or projection below is this phase's, never a stale one. + phase_projections = [ + e for e in evidence["transport"] if e["path"] == "/window/form-fields" + ] + assert len(phase_projections) == projections_before + 1 # Already retained response only: never run another source getter # to identify a refused control/channel after this request. - projection_response = next( - entry["response"] - for entry in reversed(evidence["transport"]) - if entry["path"] == "/window/form-fields" - ) + projection_response = phase_projections[-1]["response"] phase = { "name": name, "managed_before": managed, @@ -330,6 +342,8 @@ def identity(): and observed.reason == "provider_native_value_disagreement" ) assert phase["uia_utf16_units"] == 4096 and fields is None + # The agent itself refused the 4096-unit provider prefix. + assert projection_response.get("refusal") else: assert observed.complete and observed.value == expected assert observed.proof is not None and valid_value_proof(