diff --git a/agent_reach/channels/xiaoyuzhou.py b/agent_reach/channels/xiaoyuzhou.py index 5afee0e1a..ae8ffebc4 100644 --- a/agent_reach/channels/xiaoyuzhou.py +++ b/agent_reach/channels/xiaoyuzhou.py @@ -61,5 +61,22 @@ def check(self, config=None): " 2. 运行: agent-reach configure groq-key(隐藏输入)" ) + # The shipped script invokes all three before it can produce a + # transcript. ffmpeg alone can be installed while ffprobe is absent. + missing = [] + for tool, flag in (("ffprobe", "-version"), ("curl", "--version"), ("perl", "-v")): + tool_probe = probe_command(tool, [flag], timeout=10) + if tool_probe.status == "missing": + missing.append(tool) + elif not tool_probe.ok: + return "error", f"小宇宙转录工具 {tool} 无法执行,请修复该工具后重试" + if missing: + return "off", ( + "小宇宙转录还缺少运行工具:" + "、".join(missing) + "。\n" + " ffprobe 随 ffmpeg 安装;curl/perl 可通过系统包管理器安装。\n" + " Ubuntu/Debian: apt install ffmpeg curl perl\n" + " macOS: brew install ffmpeg curl perl" + ) + self.active_backend = "groq-whisper" return "ok", "完整可用(播客下载 + Whisper 转录)" diff --git a/tests/test_xiaoyuzhou_runtime.py b/tests/test_xiaoyuzhou_runtime.py new file mode 100644 index 000000000..6a9407fbc --- /dev/null +++ b/tests/test_xiaoyuzhou_runtime.py @@ -0,0 +1,39 @@ +"""Probe real PATH executables before promising podcast transcription.""" + +import os + +import pytest + +from agent_reach.channels.xiaoyuzhou import XiaoyuzhouChannel + + +@pytest.mark.skipif(os.name == "nt", reason="native POSIX executable PATH fixture") +@pytest.mark.parametrize( + "unusable,broken", + [("ffprobe", False), ("curl", False), ("perl", False), ("ffprobe", True), (None, False)], +) +def test_mandatory_script_tools_are_checked(tmp_path, monkeypatch, isolated_home, unusable, broken): + bins = tmp_path / "bin" + bins.mkdir() + for tool in ("ffmpeg", "ffprobe", "curl", "perl"): + if tool == unusable and not broken: + continue + executable = bins / tool + exit_code = 127 if tool == unusable else 0 + executable.write_text(f"#!/bin/sh\nprintf 'test version\\n'\nexit {exit_code}\n") + executable.chmod(0o755) + script = isolated_home / ".agent-reach/tools/xiaoyuzhou/transcribe.sh" + script.parent.mkdir(parents=True) + script.write_text("#!/bin/bash\n", encoding="utf-8") + monkeypatch.setenv("PATH", str(bins)) + monkeypatch.setenv("GROQ_API_KEY", "test-only-explicit-key") + + channel = XiaoyuzhouChannel() + status, message = channel.check() + if unusable is None: + assert status == "ok" + assert channel.active_backend == "groq-whisper" + else: + assert status == ("error" if broken else "off") + assert unusable in message + assert channel.active_backend is None