from pathlib import Path ROOT=Path(__file__).resolve().parents[1] def test_version(): assert (ROOT/'VERSION').read_text(encoding='utf-8').strip()=='4.6.20' def test_harness_receives_recent_conversation_history(): py=(ROOT/"services/chat_runtime.py").read_text(encoding="utf-8") assert "_format_recent_thread_history(" in py assert "[PRIOR_CONVERSATION_HISTORY]" in py assert "max_chars=24000" in py def test_health_intent_does_not_trigger_on_domain_names_alone(): py=(ROOT/"services/chat_runtime.py").read_text(encoding="utf-8") block=py[py.index("def _is_marine_health_prompt"):py.index("def _is_fisheries_inventory_prompt")] assert '"ocean、tuna、squid"' not in block assert "status_terms" in block assert "domain_terms" in block def test_direct_health_never_defaults_all_domains_online(): py=(ROOT/"services/chat_runtime.py").read_text(encoding="utf-8") block=py[py.index("async def _direct_marine_health_answer"):py.index("def _is_explicit_new_data_query")] assert 'labels={key:"未确认"' in block assert '/domains' in block assert "平台不会把它自动当成在线" in block def test_native_harness_preserves_tool_evidence(): py=(ROOT/"codex_native_harness.py").read_text(encoding="utf-8") assert "tool_names: tuple[str, ...]" in py assert "_tool_names_from_event" in py assert "tool_events=tuple(tool_events)" in py def test_harness_export_is_fail_closed(): py=(ROOT/"services/chat_runtime.py").read_text(encoding="utf-8") assert 'tool_names=tuple(getattr(result,"tool_names"' in py assert "export_tool_completed=any(" in py assert "_ocean_export_execution_error(" in py def test_adapter_does_not_store_shared_mutable_session_id(): py=(ROOT/"codex_harness.py").read_text(encoding="utf-8") assert "request_session_id" in py assert "self._session_id =" not in py def test_harness_errors_are_sanitized(): py=(ROOT/"services/chat_runtime.py").read_text(encoding="utf-8") assert "public_error=_public_error(str(exc))" in py assert '"text":public_error' in py def test_frontend_sends_more_recent_context(): js=(ROOT/"static/js/app.js").read_text(encoding="utf-8") assert "function historyPayload(x,limit=12)" in js