From 4eb586b597d1dba97fbf3dd671be9c419d45d087 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 24 Oct 2026 00:59:59 +0000 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=20runner=20=E8=A1=A5=E4=B8=8A=20libop?= =?UTF-8?q?us=EF=BC=8C=E4=BF=AE=E6=8E=89=E9=9F=B3=E9=A2=91=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit opuslib_next 是 ctypes 绑定,真正编解码靠系统里的 libopus。runner 上默认 没有,import 失败后测试里换上的是自己写的桩,桩里的编码器只有构造方法, 一调就报错。正式镜像里是装了这个库的,CI 少了这一步。 顺手把桩的报错改成一句人话,别再让人对着缺方法的报错猜根因。 --- .github/workflows/test.yml | 7 +++++++ main/xiaozhi-server/tests/conftest.py | 25 ++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ed549eda3..91e4dff1f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,13 @@ jobs: python-version: '3.10' cache: 'pip' cache-dependency-path: 'main/xiaozhi-server/requirements.txt' + - name: Install system dependencies + run: | + # opuslib_next 是 ctypes 绑定,pip 装上的是纯 Python 包,真正的编解码 + # 靠系统里的 libopus.so。runner 上默认没有,import 会失败,音频相关的 + # 用例直接报错。正式镜像 Dockerfile-server-base 里也是装 libopus0 的 + sudo apt-get update + sudo apt-get install -y --no-install-recommends libopus0 - name: Install dependencies working-directory: main/xiaozhi-server run: | diff --git a/main/xiaozhi-server/tests/conftest.py b/main/xiaozhi-server/tests/conftest.py index b2c20386a..24af688b6 100644 --- a/main/xiaozhi-server/tests/conftest.py +++ b/main/xiaozhi-server/tests/conftest.py @@ -47,10 +47,29 @@ if str(_PROJECT_ROOT) not in sys.path: # --------------------------------------------------------------------------- try: import opuslib_next # noqa: F401 -except Exception: +except Exception as _opus_import_error: + # opuslib_next 是 ctypes 绑定,pip 装上的是纯 Python 包,真正的编解码靠系统里的 + # libopus.so。runner 上没装 libopus 时 import 会失败,这里换桩顶上。 + # 桩只能撑住 import 链路,真要编解码得先把 libopus 装上 + # (apt-get install libopus0,正式镜像 Dockerfile-server-base 里也是这么装的)。 + print( + f"[conftest] opuslib_next 不可用,改用桩:{_opus_import_error}", + flush=True, + ) + + def _opus_unavailable(_self, *_args, **_kwargs): + raise RuntimeError( + "libopus 没装,Opus 编解码跑不了。" + "装法:apt-get install libopus0(正式镜像 Dockerfile-server-base 里也是这么装的)" + ) + _stub = types.ModuleType("opuslib_next") - _stub.Encoder = type("Encoder", (), {"__init__": lambda *a, **kw: None}) - _stub.Decoder = type("Decoder", (), {"__init__": lambda *a, **kw: None}) + _stub.Encoder = type( + "Encoder", (), {"__init__": lambda *a, **kw: None, "encode": _opus_unavailable} + ) + _stub.Decoder = type( + "Decoder", (), {"__init__": lambda *a, **kw: None, "decode": _opus_unavailable} + ) _stub.APPLICATION_AUDIO = 0 _stub.OpusError = type("OpusError", (Exception,), {}) _stub.constants = types.SimpleNamespace()