Skip to content

Commit 1df44eb

Browse files
committed
fix(cli): type-check the cancellation tests
Same CI gate as the parent commit, applied to the tests this branch adds: give the module-level events a real Event type instead of letting them infer None, annotate the recording callback against the JobReporter protocol, and cast the _FakeRequest stand-ins at the handle_stop call sites.
1 parent 5468b7d commit 1df44eb

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

packages/uipath/tests/cli/test_server_async.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,10 @@ async def test_http_stop_reaches_the_registry(monkeypatch):
539539
registry = _RecordingStopRegistry()
540540
monkeypatch.setattr(cli_server, "get_registry", lambda: registry)
541541

542-
response = await cli_server.handle_stop(_FakeRequest("job-1", {}))
542+
response = await cli_server.handle_stop(_fake_request("job-1", {}))
543543

544544
assert response.status == 200
545-
body = json.loads(response.text)
545+
body = _body(response)
546546
assert body["stopped"] is True
547547
assert registry.calls == [("job-1", None)]
548548

@@ -551,7 +551,7 @@ async def test_http_stop_forwards_the_resume_version(monkeypatch):
551551
registry = _RecordingStopRegistry()
552552
monkeypatch.setattr(cli_server, "get_registry", lambda: registry)
553553

554-
await cli_server.handle_stop(_FakeRequest("job-1", {"resumeVersion": 2}))
554+
await cli_server.handle_stop(_fake_request("job-1", {"resumeVersion": 2}))
555555

556556
assert registry.calls == [("job-1", 2)]
557557

@@ -562,10 +562,10 @@ async def test_http_stop_reports_a_refused_stop(monkeypatch):
562562
cli_server, "get_registry", lambda: _RecordingStopRegistry(stopped=False)
563563
)
564564

565-
response = await cli_server.handle_stop(_FakeRequest("job-1", {}))
565+
response = await cli_server.handle_stop(_fake_request("job-1", {}))
566566

567567
assert response.status == 200
568-
assert json.loads(response.text)["stopped"] is False
568+
assert _body(response)["stopped"] is False
569569

570570

571571
async def test_ipc_stop_forwards_the_dto_fields(monkeypatch):

packages/uipath/tests/cli/test_server_cancellation.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"""
88

99
import asyncio
10+
import threading
1011
import time
12+
from typing import Any
1113

1214
import click
1315
import pytest
@@ -25,21 +27,22 @@ def _fresh_state(monkeypatch):
2527

2628
class FakeCallback:
2729
def __init__(self) -> None:
28-
self.results: list[dict] = []
30+
self.results: list[dict[str, Any]] = []
2931
self.done = asyncio.Event()
3032

31-
async def post_result(self, job_key, payload):
33+
async def post_result(self, job_key: str, payload: dict[str, Any]) -> bool:
3234
self.results.append(payload)
3335
self.done.set()
3436
return True
3537

36-
async def post_logs(self, job_key, lines):
38+
async def post_logs(self, job_key: str, lines: list[dict[str, Any]]) -> bool:
3739
return True
3840

3941

4042
# Shaped like the real commands: a click command whose body is asyncio.run(...).
41-
_started = None
42-
_cleanup_ran = None
43+
# Rebound per test by the _events fixture.
44+
_started = threading.Event()
45+
_cleanup_ran = threading.Event()
4346

4447

4548
@click.command()
@@ -98,12 +101,12 @@ def _blocking_command() -> None:
98101
@pytest.fixture(autouse=True)
99102
def _events():
100103
global _started, _cleanup_ran
101-
_started = __import__("threading").Event()
102-
_cleanup_ran = __import__("threading").Event()
104+
_started = threading.Event()
105+
_cleanup_ran = threading.Event()
103106
yield
104107

105108

106-
async def _wait_for(event, timeout=10.0):
109+
async def _wait_for(event: threading.Event, timeout: float = 10.0) -> None:
107110
deadline = asyncio.get_running_loop().time() + timeout
108111
while not event.is_set():
109112
if asyncio.get_running_loop().time() > deadline:

0 commit comments

Comments
 (0)