JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
test: force UTF-8 stdio and fix locale-dependent tests
程凯0a230bd285e5
diff --git a/tests/unit_tests/agentserver/test_deep_adapter_interrupt.py b/tests/unit_tests/agentserver/test_deep_adapter_interrupt.pyindex 5093354077..f7b4a162a0 100644--- a/tests/unit_tests/agentserver/test_deep_adapter_interrupt.py+++ b/tests/unit_tests/agentserver/test_deep_adapter_interrupt.py@@ -970,9 +970,14 @@ def test_runtime_route_keeps_artifact_leaf_lexical(tmp_path: Path) -> None:outside = tmp_path / "outside"agent_workspace.mkdir()outside.mkdir()- (agent_workspace / "projects").symlink_to(- outside, target_is_directory=True- )+ try:+ (agent_workspace / "projects").symlink_to(+ outside, target_is_directory=True+ )+ except OSError:+ # Creating symlinks needs privilege on Windows; the rejection+ # semantics are covered where symlinks are creatable.+ pytest.skip("symlink creation requires privilege on this platform")adapter = _make_adapter(_env_service_id="service-output",_env_agent_id="agent-output",diff --git a/tests/unit_tests/agentserver/test_team_entity_store.py b/tests/unit_tests/agentserver/test_team_entity_store.pyindex 22a31e577a..edf6eb6dbb 100644--- a/tests/unit_tests/agentserver/test_team_entity_store.py+++ b/tests/unit_tests/agentserver/test_team_entity_store.py@@ -220,7 +220,12 @@ def test_team_entity_store_delete_does_not_follow_team_symlink(tmp_path) -> Noneexternal_file = external_path / "keep.txt"external_file.write_text("keep", encoding="utf-8")team_link = teams_home / "research_team"- team_link.symlink_to(external_path, target_is_directory=True)+ try:+ team_link.symlink_to(external_path, target_is_directory=True)+ except OSError:+ # Creating symlinks needs privilege on Windows; the rejection+ # semantics are covered where symlinks are creatable.+ pytest.skip("symlink creation requires privilege on this platform")store = TeamEntityStore(teams_home)diff --git a/tests/unit_tests/channel/test_trajectory_frontend_artifacts.py b/tests/unit_tests/channel/test_trajectory_frontend_artifacts.pyindex 670f4981ce..f9e913c579 100644--- a/tests/unit_tests/channel/test_trajectory_frontend_artifacts.py+++ b/tests/unit_tests/channel/test_trajectory_frontend_artifacts.py@@ -53,6 +53,8 @@ def test_trajectory_license_and_notice_ship_in_vite_dist_and_python_wheel(tmp_pacheck=True,capture_output=True,text=True,+ encoding="utf-8",+ errors="replace",)public_root = _FRONTEND_ROOT / "public" / _NOTICE_ROOT@@ -91,6 +93,10 @@ def test_trajectory_license_and_notice_ship_in_vite_dist_and_python_wheel(tmp_pawith zipfile.ZipFile(wheel_paths[0]) as wheel:for artifact_name in _ARTIFACT_FILES:archive_name = f"{wheel_prefix}/{_NOTICE_ROOT.as_posix()}/{artifact_name}"- wheel_contents[artifact_name] = wheel.read(archive_name).decode("utf-8")+ # Normalize line endings: on Windows checkouts the packaged bytes+ # keep CRLF while read_text() above yields LF.+ wheel_contents[artifact_name] = wheel.read(archive_name).decode(+ "utf-8"+ ).replace("\r\n", "\n")assert wheel_contents == public_contents_assert_notice_contents(wheel_contents)diff --git a/tests/unit_tests/cli/test_chat.py b/tests/unit_tests/cli/test_chat.pyindex a6ee1ecbd2..090d4be8d3 100644--- a/tests/unit_tests/cli/test_chat.py+++ b/tests/unit_tests/cli/test_chat.py@@ -9,7 +9,6 @@ import asyncioimport ioimport jsonimport os-import tempfilefrom pathlib import Pathfrom unittest.mock import patch@@ -178,7 +177,9 @@ class TestBuildRequest:trusted_dir=None,)req = _build_request(args, "test")- assert req["params"]["cwd"] == "/custom/cwd"+ # The CLI resolves the argument; compare resolved forms so the+ # assertion holds on both POSIX and Windows path shapes.+ assert Path(req["params"]["cwd"]) == Path("/custom/cwd").resolve()@staticmethoddef test_with_project_dir(monkeypatch):@@ -191,7 +192,9 @@ class TestBuildRequest:trusted_dir=None,)req = _build_request(args, "test")- assert req["params"]["project_dir"] == "/custom/project"+ assert Path(req["params"]["project_dir"]) == Path(+ "/custom/project"+ ).resolve()@staticmethoddef test_with_trusted_dirs(monkeypatch):@@ -208,9 +211,9 @@ class TestBuildRequest:trusted_dir=["/dir1", "/dir2"],)req = _build_request(args, "test")- assert sorted(str(d) for d in req["params"]["trusted_dirs"]) == sorted(- ["/dir1", "/dir2"]- )+ assert sorted(+ Path(d) for d in req["params"]["trusted_dirs"]+ ) == sorted([Path("/dir1").resolve(), Path("/dir2").resolve()])@staticmethoddef test_mode_included(monkeypatch):@@ -1005,8 +1008,6 @@ class TestSpinner:@staticmethoddef test_spinner_verb_rotates():- from jiuwenswarm.cli.render import _VERBS-fake_time = 1000.0def mock_monotonic():diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.pyindex 71af65ffcd..099e04fd68 100644--- a/tests/unit_tests/conftest.py+++ b/tests/unit_tests/conftest.py@@ -19,11 +19,23 @@ functions, hence this hook.from __future__ import annotationsimport os+import sysfrom pathlib import Pathimport pytest-import jiuwenswarm.common.utils as _utils+# Force UTF-8 stdio for the test process and any child it spawns. On Windows+# the interpreter starts with locale (GBK) std streams; app logging that+# reaches the original stdout/stderr then writes GBK bytes into pytest's+# UTF-8 fd-level capture, breaking the whole run at test boundaries.+os.environ.setdefault("PYTHONUTF8", "1")+for _stream in (sys.__stdout__, sys.__stderr__):+ try:+ _stream.reconfigure(encoding="utf-8", errors="replace")+ except (AttributeError, OSError, ValueError):+ pass++import jiuwenswarm.common.utils as _utils # noqa: E402 (must follow the stdio reconfigure above)_REAL_GET_CONFIG_FILE = _utils.get_config_file_REAL_GET_AGENT_WORKSPACE_DIR = _utils.get_agent_workspace_dirdiff --git a/tests/unit_tests/extensions/test_agentos_router.py b/tests/unit_tests/extensions/test_agentos_router.pyindex 36bfc69f25..1436812b80 100644--- a/tests/unit_tests/extensions/test_agentos_router.py+++ b/tests/unit_tests/extensions/test_agentos_router.py@@ -2,6 +2,7 @@ from __future__ import annotationsimport asynciofrom collections.abc import AsyncIterator+from pathlib import Pathfrom typing import Anyimport pytest@@ -221,7 +222,11 @@ def test_resolve_agent_workspace_defaults_under_agentos_users(tmp_path, monkeypaassert resolve_agent_workspace("alice/../bob") == (str(expected_root / "alice_.._bob"))- assert resolve_agent_workspace("u1", workspace_root="/data/ws") == "/data/ws/u1"+ # Compare resolved forms: on Windows the rooted POSIX-style literal+ # resolves against the current drive.+ assert Path(+ resolve_agent_workspace("u1", workspace_root="/data/ws")+ ) == Path("/data/ws/u1").resolve()@pytest.mark.asyncio@@ -764,7 +769,9 @@ async def test_create_uses_configured_workspace_root() -> None:session_id="sess-1",)assert response["ok"] is True- assert yuanrong.create_payloads[0]["workspace"] == "/mnt/workspaces/u1"+ assert Path(yuanrong.create_payloads[0]["workspace"]) == Path(+ "/mnt/workspaces/u1"+ ).resolve()finally:await client.shutdown()diff --git a/tests/unit_tests/test_dependency_constraints.py b/tests/unit_tests/test_dependency_constraints.pyindex b312ee4196..93bdf709af 100644--- a/tests/unit_tests/test_dependency_constraints.py+++ b/tests/unit_tests/test_dependency_constraints.py@@ -16,7 +16,9 @@ OTEL_REQUIREMENTS = {def test_offline_html_runtime_dependency_includes_python_markdown():- pyproject = tomllib.loads((PROJECT_ROOT / "pyproject.toml").read_text())+ pyproject = tomllib.loads(+ (PROJECT_ROOT / "pyproject.toml").read_text(encoding="utf-8")+ )requirements = {Requirement(raw).name for raw in pyproject["project"]["dependencies"]}@@ -25,7 +27,9 @@ def test_offline_html_runtime_dependency_includes_python_markdown():def test_opentelemetry_dependencies_exclude_protobuf4_only_proto_versions():- pyproject = tomllib.loads((PROJECT_ROOT / "pyproject.toml").read_text())+ pyproject = tomllib.loads(+ (PROJECT_ROOT / "pyproject.toml").read_text(encoding="utf-8")+ )requirements = {Requirement(raw).name: Requirement(raw)for raw in pyproject["project"]["dependencies"]