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(deepresearch): adapt byte-exact and symlink tests for Windows
程凯bf61e92cb8a6
diff --git a/tests/unit_tests/agentserver/test_deepresearch_artifact_naming.py b/tests/unit_tests/agentserver/test_deepresearch_artifact_naming.pyindex 370792e3ce..cbbbca03ec 100644--- a/tests/unit_tests/agentserver/test_deepresearch_artifact_naming.py+++ b/tests/unit_tests/agentserver/test_deepresearch_artifact_naming.py@@ -245,7 +245,12 @@ def test_allocate_initial_paths_treats_direct_and_dangling_candidate_symlinks_astarget = tmp_path / "target.md"if not dangling:target.write_text("target", encoding="utf-8")- first.markdown_path.symlink_to(target)+ try:+ first.markdown_path.symlink_to(target)+ 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")allocated = api.allocate_initial_paths(tmp_path, "report.md")@@ -415,7 +420,10 @@ def test_allocate_next_paths_skips_symlink_sidecars_without_following_them(tmp_pparent.write_text("# Report\n", encoding="utf-8")target = tmp_path / "target.json"target.write_text(json.dumps(_provenance(version_number=99)), encoding="utf-8")- (tmp_path / "linked.provenance.json").symlink_to(target)+ try:+ (tmp_path / "linked.provenance.json").symlink_to(target)+ except OSError:+ pytest.skip("symlink creation requires privilege on this platform")allocated = api.allocate_next_paths(parent, _provenance(version_number=1), "# Report\n")@@ -469,7 +477,10 @@ def test_allocate_next_paths_rejects_same_document_legacy_symlink_markdown(tmp_pparent = tmp_path / "report-v1.md"parent.write_text("# Report\n", encoding="utf-8")legacy = tmp_path / "legacy-v2.md"- legacy.symlink_to(tmp_path / "outside.md")+ try:+ legacy.symlink_to(tmp_path / "outside.md")+ except OSError:+ pytest.skip("symlink creation requires privilege on this platform")legacy.with_suffix(".provenance.json").write_text(json.dumps({"document_id": "document-a", "rewrite_history": [{}]}),encoding="utf-8",diff --git a/tests/unit_tests/agentserver/test_deepresearch_document_rewrite.py b/tests/unit_tests/agentserver/test_deepresearch_document_rewrite.pyindex 995aa96be7..36ec53da07 100644--- a/tests/unit_tests/agentserver/test_deepresearch_document_rewrite.py+++ b/tests/unit_tests/agentserver/test_deepresearch_document_rewrite.py@@ -25,7 +25,10 @@ from jiuwenswarm.agents.harness.common.tools.deepresearch_plugin.document_rewritdef _write_document(root: Path, body: str) -> tuple[Path, dict]:report = root / "report-v1.md"- report.write_text(body, encoding="utf-8")+ # write_bytes, not write_text: content_sha256 is computed over body's+ # exact UTF-8 bytes, and text mode would translate \n -> \r\n on+ # Windows, breaking the byte-exact hash check in prepare_rewrite.+ report.write_bytes(body.encode("utf-8"))authoritative_citation = {"id": 3,"reference_index": 1,@@ -2501,6 +2504,10 @@ def test_commit_retries_markdown_publication_collision_without_overwrite(assert rewrite_module._DOCUMENT_LOCKS == {}+ os.name == "nt",+ reason="concurrent sidecar swap requires POSIX unlink-while-open semantics",+)def test_commit_publication_failure_preserves_concurrent_content_and_parent(tmp_path, monkeypatch):@@ -2572,6 +2579,10 @@ def test_commit_keyboard_interrupt_cleans_owned_provenance_and_reraises(assert rewrite_module._DOCUMENT_LOCKS == {}+ os.name == "nt",+ reason="concurrent sidecar swap requires POSIX unlink-while-open semantics",+)def test_commit_keyboard_interrupt_preserves_replaced_provenance(tmp_path, monkeypatch):report, _ = _write_document(tmp_path, "original\n")prepared = _prepare(tmp_path, report, "original")@@ -2710,7 +2721,12 @@ def _replace_with_unsafe_leaf(path.unlink()if kind == "symlink":outside.write_bytes(original)- path.symlink_to(outside)+ try:+ path.symlink_to(outside)+ 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")elif kind == "hardlink":outside.write_bytes(original)os.link(outside, path)@@ -2766,7 +2782,10 @@ def test_prepare_rejects_initial_symlink_workspace_root(tmp_path):outside.mkdir()outside_report, _ = _write_document(outside, "original\n")workspace = tmp_path / "workspace"- workspace.symlink_to(outside, target_is_directory=True)+ try:+ workspace.symlink_to(outside, target_is_directory=True)+ except OSError:+ pytest.skip("symlink creation requires privilege on this platform")report = workspace / outside_report.namewith pytest.raises(RewriteError) as caught:@@ -2808,7 +2827,10 @@ def test_prepare_html_export_rejects_initial_symlink_workspace_root(tmp_path):_, result = _committed_child(outside)outside_child = Path(result["report_path"])workspace = tmp_path / "workspace"- workspace.symlink_to(outside, target_is_directory=True)+ try:+ workspace.symlink_to(outside, target_is_directory=True)+ except OSError:+ pytest.skip("symlink creation requires privilege on this platform")with pytest.raises(RewriteError) as caught:prepare_html_export(diff --git a/tests/unit_tests/agentserver/test_deepresearch_report_bundle.py b/tests/unit_tests/agentserver/test_deepresearch_report_bundle.pyindex 47002e3be5..838b9eb075 100644--- a/tests/unit_tests/agentserver/test_deepresearch_report_bundle.py+++ b/tests/unit_tests/agentserver/test_deepresearch_report_bundle.py@@ -63,12 +63,22 @@ def test_build_report_bundle_rejects_occupied_resource_paths_without_mutation(elif occupied_kind == "directory_symlink":outside_dir = tmp_path / "outside-dir"outside_dir.mkdir()- chart_dir.symlink_to(outside_dir, target_is_directory=True)+ try:+ chart_dir.symlink_to(outside_dir, 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")else:chart_dir.mkdir()target = chart_dir / "chart-a.png"if occupied_kind == "file_symlink":- target.symlink_to(outside)+ try:+ target.symlink_to(outside)+ except OSError:+ pytest.skip(+ "symlink creation requires privilege on this platform"+ )else:os.link(outside, target)@@ -83,6 +93,9 @@ def test_build_report_bundle_rejects_occupied_resource_paths_without_mutation(assert list(chart_dir.iterdir()) == []+ os.name == "nt", reason="POSIX mode bits are not materialized on Windows"+)def test_build_report_bundle_publishes_private_files_and_direct_manifest(tmp_path, monkeypatch):report_base = tmp_path / "report-v1"real_fsync = bundle_module.os.fsync@@ -213,6 +226,9 @@ def test_build_report_bundle_cleans_owned_resources_after_rewrite_failure(tmp_paassert not (tmp_path / "report-v1_charts").exists()+ os.name == "nt", reason="POSIX directory descriptor contract"+)def test_build_report_bundle_rejects_directory_descriptor_swap_without_outside_write(tmp_path, monkeypatch):diff --git a/tests/unit_tests/agentserver/test_deepresearch_rewrite_tools.py b/tests/unit_tests/agentserver/test_deepresearch_rewrite_tools.pyindex f5132fe0f5..f677a0a56c 100644--- a/tests/unit_tests/agentserver/test_deepresearch_rewrite_tools.py+++ b/tests/unit_tests/agentserver/test_deepresearch_rewrite_tools.py@@ -16,7 +16,9 @@ from jiuwenswarm.agents.harness.common.tools.deepresearch import rewrite_tools adef _document(root: Path, citation_artifacts: dict[str, str] | None = None):body = "原句。\n"report = root / "report.md"- report.write_text(body, encoding="utf-8")+ # write_bytes: content_sha256 hashes body's exact UTF-8 bytes; text mode+ # would translate \n -> \r\n on Windows and break the hash check.+ report.write_bytes(body.encode("utf-8"))snapshot = {"response_content": body,"citation_messages": {"code": 0, "msg": "success", "data": []},diff --git a/tests/unit_tests/agentserver/test_deepresearch_runtime.py b/tests/unit_tests/agentserver/test_deepresearch_runtime.pyindex 09235e46f9..b527a3bb29 100644--- a/tests/unit_tests/agentserver/test_deepresearch_runtime.py+++ b/tests/unit_tests/agentserver/test_deepresearch_runtime.py@@ -46,7 +46,12 @@ def test_resolve_python_executable_preserves_symlinked_venv_identity(bin_dir.mkdir(parents=True)(venv_root / "pyvenv.cfg").write_text("home = /usr/bin\n", encoding="utf-8")python = bin_dir / "python"- python.symlink_to(sys.executable)+ try:+ python.symlink_to(sys.executable)+ except OSError:+ # Creating symlinks needs privilege on Windows; the resolution+ # semantics are covered where symlinks are creatable.+ pytest.skip("symlink creation requires privilege on this platform")monkeypatch.setattr(sys, "executable", str(python))resolved = resolve_python_executable()child_env = build_child_env(resolved)@@ -95,6 +100,8 @@ def test_resolve_python_executable_rejects_invalid_current_runtime(elif invalid_kind == "missing":configured = str(tmp_path / "missing" / "python")elif invalid_kind == "not_executable":+ if os.name == "nt":+ pytest.skip("execute bits are not materialized on Windows")configured = str(_fake_venv_python(tmp_path, executable=False))monkeypatch.setattr(sys, "executable", configured)@@ -108,6 +115,8 @@ def test_build_child_env_isolates_python_and_allows_only_http_proxy_family():from jiuwenswarm.agents.harness.common.tools.deepresearch.runtime import build_child_env+ if os.name == "nt":+ pytest.skip("env var case distinction is unavailable on Windows")python = _fake_venv_python(tmp_path)process_proxies = {"HTTP_PROXY": "http://process-upper-http",