Skip to content

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

fix: 流水线跨基线兼容 (跳过 Windows-only 测试 + audit_emit 可选导入)

zhouzhiming6dca9357a5753
diff --git a/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py b/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py
index 9739a4434b..5ba98c4ea7 100644
--- a/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py
+++ b/jiuwenswarm/agents/harness/common/tools/send_file_to_user.py
@@ -26,6 +26,44 @@ from jiuwenswarm.edition import is_enterprise
logger = logging.getLogger(__name__)
+# Enterprise audit shims. ``jiuwenswarm.common.audit_emit`` lives only on the
+# dev-stable line — some downstream forks (e.g. dev-stable-ee) ship without
+# it, so importing it eagerly would break the OBS path at runtime. Wrap the
+# import in :func:`_safe_emit_audit_evt` / :func:`_safe_emit_audit_ua` so the
+# tool degrades silently to no-op when the module is unavailable. On forks
+# that do ship ``audit_emit``, this routes through its internal
+# ``telemetry.audit`` adapter (see :mod:`jiuwenswarm.common.audit_emit`).
+try:
+ from jiuwenswarm.common.audit_emit import (
+ emit_audit_evt as _emit_audit_evt_impl,
+ emit_audit_ua as _emit_audit_ua_impl,
+ )
+ _AUDIT_EMIT_AVAILABLE: bool = True
+except ImportError:
+ _emit_audit_evt_impl = None # type: ignore[assignment]
+ _emit_audit_ua_impl = None # type: ignore[assignment]
+ _AUDIT_EMIT_AVAILABLE = False
+
+
+def _safe_emit_audit_evt(**fields: Any) -> None:
+ """Best-effort ``emit_audit_evt`` with graceful no-op when unavailable."""
+ if not _AUDIT_EMIT_AVAILABLE or _emit_audit_evt_impl is None:
+ return
+ try:
+ _emit_audit_evt_impl(**fields)
+ except Exception as exc: # noqa: BLE001 - audit must never break delivery
+ logger.warning("[SendFileToolkit] emit_audit_evt failed: %s", exc)
+
+
+def _safe_emit_audit_ua(**fields: Any) -> None:
+ """Best-effort ``emit_audit_ua`` with graceful no-op when unavailable."""
+ if not _AUDIT_EMIT_AVAILABLE or _emit_audit_ua_impl is None:
+ return
+ try:
+ _emit_audit_ua_impl(**fields)
+ except Exception as exc: # noqa: BLE001 - audit must never break delivery
+ logger.warning("[SendFileToolkit] emit_audit_ua failed: %s", exc)
+
# Per-request send_file routing context (session_id / request_id / channel_id / metadata).
# send_file_to_user 工具按全局名注册成单例时,并发请求会互相覆盖实例字段。
# 此 ContextVar 按 async 上下文隔离;工具执行时优先据此解析当前请求路由,
@@ -327,12 +365,10 @@ class SendFileToolkit:
logger.warning("[SendFileToolkit] 文件不存在: %s", fp)
if not valid_files:
- from jiuwenswarm.common.audit_emit import emit_audit_evt
-
msg_parts = ["发送文件失败:所有文件均不存在"]
for mf in missing_files:
msg_parts.append(f" - {mf}")
- emit_audit_evt(
+ _safe_emit_audit_evt(
SUBMDL="file",
PROC="send_file_to_user",
MSG=msg_parts[0],
@@ -538,11 +574,10 @@ class SendFileToolkit:
load_minio_upload_config,
upload_local_file_to_minio,
)
- from jiuwenswarm.common.audit_emit import emit_audit_evt, emit_audit_ua
session = get_subagent_parent_session()
if session is None or not hasattr(session, "write_stream"):
- emit_audit_evt(
+ _safe_emit_audit_evt(
SUBMDL="file",
PROC="send_file_to_user",
MSG="no_write_stream",
@@ -558,7 +593,7 @@ class SendFileToolkit:
minio_cfg = load_minio_upload_config()
except Exception as exc:
logger.warning("[SendFileToolkit] OBS 配置不可用: %s", exc)
- emit_audit_evt(
+ _safe_emit_audit_evt(
SUBMDL="file",
PROC="send_file_to_user",
MSG=str(exc)[:512],
@@ -603,7 +638,7 @@ class SendFileToolkit:
parts = ["发送文件失败:全部文件上传对象存储失败"]
for ff in failed_files:
parts.append(f" - {ff['file']}: {ff['error']}")
- emit_audit_evt(
+ _safe_emit_audit_evt(
SUBMDL="file",
PROC="send_file_to_user",
MSG=parts[0],
@@ -633,7 +668,7 @@ class SendFileToolkit:
"[SendFileToolkit] write_stream chat.file 失败 session_id=%s",
route.session_id,
)
- emit_audit_evt(
+ _safe_emit_audit_evt(
SUBMDL="file",
PROC="send_file_to_user",
MSG=str(exc)[:512],
@@ -643,7 +678,7 @@ class SendFileToolkit:
return f"发送文件失败:写入对话流失败({exc})"
_mark_files_sent(route.session_id, sent_ok)
- emit_audit_ua(
+ _safe_emit_audit_ua(
SUBMDL="file",
PROC="send_file_to_user",
session_id=route.session_id,
diff --git a/tests/unit_tests/harness/test_empty_output_guard.py b/tests/unit_tests/harness/test_empty_output_guard.py
index 11f7173457..e0267c67e8 100644
--- a/tests/unit_tests/harness/test_empty_output_guard.py
+++ b/tests/unit_tests/harness/test_empty_output_guard.py
@@ -314,7 +314,10 @@ def test_prepend_does_not_prepend_workspace_paths(
monkeypatch.setattr(
"os.access", _force_readonly(workspace_skill)
)
- system_dirs = ["C:\\system1", "C:\\system2"]
+ # System PATH tokens must contain no os.pathsep (";" / ":") so this test
+ # runs on both Windows and POSIX (where os.pathsep is ":", splitting
+ # "C:\\system1" into ["C", "\\system1"]).
+ system_dirs = ["sentinel1", "sentinel2"]
initial_path = os.pathsep.join(system_dirs)
with patch("os.getcwd", return_value=str(workspace_skill.parent.parent.parent)):
env = {"PATH": initial_path}
@@ -377,6 +380,7 @@ def test_prepend_is_noop_without_tool_dirs(
# ---------------------------------------------------------------------------
[email protected](os.name != "nt", reason="Windows-only PATH hardening")
@pytest.mark.parametrize(
"stderr, exit_code, expect_hint",
[
@@ -690,6 +694,7 @@ def test_xlsx_size_warning_5999_vs_6000_boundary(tmp_path: Path) -> None:
# ---------------------------------------------------------------------------
[email protected](os.name != "nt", reason="Windows-only PATH hardening")
def test_windows_not_found_hint_marker_text_paths() -> None:
"""All three marker families trigger the hint."""
assert (
@@ -706,6 +711,7 @@ def test_windows_not_found_hint_marker_text_paths() -> None:
)
[email protected](os.name != "nt", reason="Windows-only PATH hardening")
def test_windows_not_found_hint_exit_code_9009_path() -> None:
"""exit_code=9009 path triggers regardless of stderr text."""
assert (