Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
robert-ursu committed Aug 19, 2026
commit e14f4b29d26780f990ec952bdaf69a80b8ff9f1a
10 changes: 5 additions & 5 deletions packages/uipath/tests/cli/test_server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,10 @@ async def test_http_stop_reaches_the_registry(monkeypatch):
registry = _RecordingStopRegistry()
monkeypatch.setattr(cli_server, "get_registry", lambda: registry)

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

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

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

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

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

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

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

assert response.status == 200
assert json.loads(response.text)["stopped"] is False
assert _body(response)["stopped"] is False


async def test_ipc_stop_forwards_the_dto_fields(monkeypatch):
Expand Down
19 changes: 11 additions & 8 deletions packages/uipath/tests/cli/test_server_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"""

import asyncio
import threading
import time
from typing import Any

import click
import pytest
Expand All @@ -25,21 +27,22 @@ def _fresh_state(monkeypatch):

class FakeCallback:
def __init__(self) -> None:
self.results: list[dict] = []
self.results: list[dict[str, Any]] = []
self.done = asyncio.Event()

async def post_result(self, job_key, payload):
async def post_result(self, job_key: str, payload: dict[str, Any]) -> bool:
self.results.append(payload)
self.done.set()
return True

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


# Shaped like the real commands: a click command whose body is asyncio.run(...).
_started = None
_cleanup_ran = None
# Rebound per test by the _events fixture.
_started = threading.Event()
_cleanup_ran = threading.Event()


@click.command()
Expand Down Expand Up @@ -98,12 +101,12 @@ def _blocking_command() -> None:
@pytest.fixture(autouse=True)
def _events():
global _started, _cleanup_ran
_started = __import__("threading").Event()
_cleanup_ran = __import__("threading").Event()
_started = threading.Event()
_cleanup_ran = threading.Event()
yield


async def _wait_for(event, timeout=10.0):
async def _wait_for(event: threading.Event, timeout: float = 10.0) -> None:
deadline = asyncio.get_running_loop().time() + timeout
while not event.is_set():
if asyncio.get_running_loop().time() > deadline:
Expand Down
Loading