From 9c33332a5c44faf941b7f2dc1cb640d85176fa6f Mon Sep 17 00:00:00 2001 From: Robert Ursu Date: Wed, 25 Nov 2026 16:43:13 +0200 Subject: [PATCH] test(codex-sdk): make the suite pass on Windows uipath-python's "Test Integrations" workflow runs this suite on windows-latest, where 10 tests fail on every PR: - Seven contract tests read Codex's rollout with the locale encoding (cp1252 there), which cannot decode the UTF-8 it holds. Read it as UTF-8. - test_c6_rollout_path_pattern matched a forward-slash pattern against str() of a relative path, which uses backslashes there. Use as_posix(). - Three tests need Codex to run a shell command. With a read-only agent, Codex on Windows rejects the command before starting it ("blocked by policy"), so no command item reaches the runtime. Those tests now use an agent with the full-access sandbox; the others keep the default. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Fmj9j6BHFgyskAHtyrUX7i --- .../uipath-codex-sdk/tests/contract/harness.py | 2 +- .../tests/contract/test_durable_contract.py | 2 +- .../uipath-codex-sdk/tests/durable/conftest.py | 15 +++++++++++++++ .../uipath-codex-sdk/tests/durable/test_e2e.py | 8 ++++---- .../tests/durable/test_tracing.py | 8 +++++--- packages/uipath-codex-sdk/tests/test_debug.py | 18 +++++++++++++++--- 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/packages/uipath-codex-sdk/tests/contract/harness.py b/packages/uipath-codex-sdk/tests/contract/harness.py index da8fe981..91366141 100644 --- a/packages/uipath-codex-sdk/tests/contract/harness.py +++ b/packages/uipath-codex-sdk/tests/contract/harness.py @@ -251,7 +251,7 @@ def rollout_for_thread(codex_home: Path, thread_id: str) -> Path | None: def read_rollout(path: Path) -> list[JsonObj]: out: list[JsonObj] = [] try: - text = path.read_text() + text = path.read_text(encoding="utf-8") except FileNotFoundError: return out for line in text.splitlines(): diff --git a/packages/uipath-codex-sdk/tests/contract/test_durable_contract.py b/packages/uipath-codex-sdk/tests/contract/test_durable_contract.py index f587aae5..97a25632 100644 --- a/packages/uipath-codex-sdk/tests/contract/test_durable_contract.py +++ b/packages/uipath-codex-sdk/tests/contract/test_durable_contract.py @@ -389,7 +389,7 @@ def test_c6_rollout_path_pattern(cenv: ContractEnv, evidence: Evidence): cid = new_call_id() s = start_and_hold(cenv, evidence, [cid]) wait_quiet(cenv, s.home, s.thread_id) - rels = [str(p.relative_to(s.home)) for p in find_rollouts(s.home)] + rels = [p.relative_to(s.home).as_posix() for p in find_rollouts(s.home)] evidence.add("rollout files", rels) evidence.add("CODEX_HOME top level", sorted(p.name for p in s.home.iterdir())) assert len(rels) == 1, evidence.dump() diff --git a/packages/uipath-codex-sdk/tests/durable/conftest.py b/packages/uipath-codex-sdk/tests/durable/conftest.py index cfeed8f7..849b470e 100644 --- a/packages/uipath-codex-sdk/tests/durable/conftest.py +++ b/packages/uipath-codex-sdk/tests/durable/conftest.py @@ -112,6 +112,21 @@ def project(tmp_path: Path, monkeypatch) -> Path: return proj +@pytest.fixture +def shell_project(project: Path) -> Path: + """``project`` with an agent whose shell commands run on Windows too. + + There Codex has no sandbox for a read-only agent's commands and rejects + them unstarted, without the command item these tests are about. + """ + (project / "main.py").write_text( + AGENT_MAIN.replace( + 'model="mock-model"', 'model="mock-model", sandbox="full-access"' + ) + ) + return project + + @pytest.fixture def cli_env(tmp_path: Path, monkeypatch, world: FakeOrchestrator): """A project for the real ``uipath`` CLI, which calls ``asyncio.run`` diff --git a/packages/uipath-codex-sdk/tests/durable/test_e2e.py b/packages/uipath-codex-sdk/tests/durable/test_e2e.py index b19e1886..f8e0148b 100644 --- a/packages/uipath-codex-sdk/tests/durable/test_e2e.py +++ b/packages/uipath-codex-sdk/tests/durable/test_e2e.py @@ -257,7 +257,7 @@ async def test_explicit_resume_payload(project, upstream, world): @pytest.mark.parametrize("sibling_after", [True, False], ids=["after", "before"]) async def test_shell_sibling_is_paired_on_resume( - project, upstream, world, sibling_after + shell_project, upstream, world, sibling_after ): """A non-durable sibling in the same response as a held call. @@ -270,11 +270,11 @@ async def test_shell_sibling_is_paired_on_resume( upstream.script = script cid, sib = script.call_ids[0], SiblingScript.SIBLING_ID - result, _ = await _run(project, {}, resume=False) + result, _ = await _run(shell_project, {}, resume=False) assert result.status == UiPathRuntimeStatus.SUSPENDED, result world.finish(world.invocations[0].job_key, "Successful", {"sum": 3}) - _new_robot(project) - result, _ = await _run(project, None, resume=True) + _new_robot(shell_project) + result, _ = await _run(shell_project, None, resume=True) assert result.status == UiPathRuntimeStatus.SUCCESSFUL, result req = _resume_request(upstream, [cid, sib]) diff --git a/packages/uipath-codex-sdk/tests/durable/test_tracing.py b/packages/uipath-codex-sdk/tests/durable/test_tracing.py index cbe687ea..0a81320b 100644 --- a/packages/uipath-codex-sdk/tests/durable/test_tracing.py +++ b/packages/uipath-codex-sdk/tests/durable/test_tracing.py @@ -441,13 +441,15 @@ def finishing_client(): assert await _saved_trace(project) is None -async def test_items_codex_runs_itself_are_traced(project, upstream, world, spans): +async def test_items_codex_runs_itself_are_traced( + shell_project, upstream, world, spans +): """A shell command next to the durable call: a Tool call span.""" upstream.script = SiblingScript(sibling_after=False) - result = await _run(project, {}, resume=False) + result = await _run(shell_project, {}, resume=False) assert result.status == UiPathRuntimeStatus.SUSPENDED, result finished = spans.get_finished_spans() - saved = await _saved_trace(project) + saved = await _saved_trace(shell_project) assert saved is not None [shell] = _by_name(finished, "Tool call - shell") assert _parent_id(shell) == int(saved["span_id"], 16) diff --git a/packages/uipath-codex-sdk/tests/test_debug.py b/packages/uipath-codex-sdk/tests/test_debug.py index 5b19feae..520f0221 100644 --- a/packages/uipath-codex-sdk/tests/test_debug.py +++ b/packages/uipath-codex-sdk/tests/test_debug.py @@ -51,6 +51,10 @@ agent = UiPathCodexAgent(model="mock-model", prompt="Say hi to {name}.") """ +SHELL_MAIN = PLAIN_MAIN.replace( + 'model="mock-model"', 'model="mock-model", sandbox="full-access"' +) + class ShellScript: """Mock model: run one shell command, then answer.""" @@ -159,11 +163,20 @@ def plain_project(project: Path) -> Path: return project -async def test_state_events_reach_the_debug_bridge(plain_project, upstream, caplog): +@pytest.fixture +def plain_shell_project(project: Path) -> Path: + """Shell commands run on Windows too: see ``shell_project``.""" + (project / "main.py").write_text(SHELL_MAIN) + return project + + +async def test_state_events_reach_the_debug_bridge( + plain_shell_project, upstream, caplog +): upstream.script = ShellScript() bridge = ScriptedBridge() with caplog.at_level(logging.WARNING, logger=RUNTIME_LOGGER): - events = await _debug_run(plain_project, bridge, {"name": "Ada"}) + events = await _debug_run(plain_shell_project, bridge, {"name": "Ada"}) assert events[-1].status == UiPathRuntimeStatus.SUCCESSFUL assert bridge.log == ["connect", "started", "completed:SUCCESSFUL", "disconnect"] @@ -174,7 +187,6 @@ async def test_state_events_reach_the_debug_bridge(plain_project, upstream, capl ] assert len(shell) == 1, [e.node_name for e in bridge.state_events] assert shell[0].node_name == "tools" - # Whether the command itself ran depends on the host's sandbox support. assert "echo debug-ran" in shell[0].payload["command"] assert {e.node_name for e in bridge.state_events} <= {"agent", "tools"} assert all(e.execution_id == RUNTIME_ID for e in bridge.state_events)