Skip to content

"Vibe-Trading: Your Personal Trading Agent"

test: make path-handling tests pass on Windows runners

Teerapat Vatpitak5eb8390921d9
diff --git a/agent/tests/test_backtest_runner_security.py b/agent/tests/test_backtest_runner_security.py
index c89928a3d..d0220a8f4 100644
--- a/agent/tests/test_backtest_runner_security.py
+++ b/agent/tests/test_backtest_runner_security.py
@@ -16,12 +16,17 @@ def _module_name() -> str:
def test_signal_engine_rejects_top_level_execution(tmp_path) -> None:
artifact = tmp_path / "top_level_rce"
+ # ``Path.as_posix()`` so the embedded path uses forward slashes; the raw
+ # Windows form ``C:\Users\...`` looks like ``\U`` (a unicode escape) when
+ # interpolated into Python source and breaks ``ast.parse`` before the
+ # security scrubber under test ever runs.
+ artifact_str = artifact.as_posix()
signal_file = tmp_path / "signal_engine.py"
signal_file.write_text(
"\n".join(
[
"import os",
- f"os.system('touch {artifact}')",
+ f"os.system('touch {artifact_str}')",
"class SignalEngine:",
" def generate(self, *args, **kwargs):",
" return []",
@@ -38,13 +43,14 @@ def test_signal_engine_rejects_top_level_execution(tmp_path) -> None:
def test_signal_engine_rejects_class_level_execution(tmp_path) -> None:
artifact = tmp_path / "class_level_rce"
+ artifact_str = artifact.as_posix() # see top_level test for rationale
signal_file = tmp_path / "signal_engine.py"
signal_file.write_text(
"\n".join(
[
"import os",
"class SignalEngine:",
- f" os.system('touch {artifact}')",
+ f" os.system('touch {artifact_str}')",
" def generate(self, *args, **kwargs):",
" return []",
]
diff --git a/agent/tests/test_loop_helpers.py b/agent/tests/test_loop_helpers.py
index ac2d73501..93e61d35c 100644
--- a/agent/tests/test_loop_helpers.py
+++ b/agent/tests/test_loop_helpers.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import json
+import os
from pathlib import Path
import pytest
@@ -274,6 +275,13 @@ class TestNormalizeToolRunDir:
assert out["run_dir"] == str((Path("/tmp/run_123") / "risk_parity_run").resolve())
def test_preserves_absolute_run_dir(self) -> None:
- args = {"run_dir": "/var/tmp/custom_run"}
+ # ``os.path.abspath`` produces a platform-correct absolute path: on
+ # POSIX it stays ``/var/tmp/custom_run``; on Windows it becomes
+ # ``C:\var\tmp\custom_run``. ``Path.is_absolute()`` only treats the
+ # latter as absolute on Windows, so the bare Unix-style literal would
+ # otherwise be classified as relative and resolved against
+ # ``memory_run_dir`` — defeating the point of the test.
+ absolute_run_dir = os.path.abspath("/var/tmp/custom_run")
+ args = {"run_dir": absolute_run_dir}
out = _normalize_tool_run_dir(args, "/tmp/run_123")
- assert out["run_dir"] == "/var/tmp/custom_run"
+ assert out["run_dir"] == absolute_run_dir