diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 135cfbd65..ed549eda3 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -25,19 +25,46 @@ jobs:
run: |
pip install -r requirements.txt
pip install pytest pytest-asyncio freezegun
- - name: Run smoke test
+ - name: Prepare test config
working-directory: main/xiaozhi-server
run: |
- if [ -f tests/test_smoke.py ]; then
- pytest tests/test_smoke.py -x -q
- else
- echo "::warning::Slice 2 not done yet — tests/test_smoke.py missing"
- exit 0
- fi
+ # config/settings.py 在 import 期就要这个文件,缺了整套用例连收集都过不去。
+ # data/ 在 .gitignore 里,只能由这一步现造
+ mkdir -p data
+ printf '{}\n' > data/.config.yaml
+ - name: Run tests
+ working-directory: main/xiaozhi-server
+ run: |
+ # Edge TTS 那条要连微软公网,runner 的出口 IP 会被风控挡掉,先排除。
+ # 根治办法是给它打 live 标记,让 mock 模式下自动不收(另开一条改)
+ pytest tests/ -v -k "not test_tts_text_to_speak_writes_file"
java:
name: Java (manager-api)
runs-on: ubuntu-latest
+ # 三个 @SpringBootTest 要真连 MySQL 和 Redis,空库即可,Liquibase 会自己建表
+ services:
+ mysql:
+ image: mysql:8.0
+ env:
+ MYSQL_ROOT_PASSWORD: 123456
+ MYSQL_DATABASE: xiaozhi_esp32_server
+ ports:
+ - 3306:3306
+ options: >-
+ --health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -p123456"
+ --health-interval=10s
+ --health-timeout=5s
+ --health-retries=20
+ redis:
+ image: redis:8.0
+ ports:
+ - 6379:6379
+ options: >-
+ --health-cmd="redis-cli ping"
+ --health-interval=10s
+ --health-timeout=5s
+ --health-retries=20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
@@ -47,7 +74,7 @@ jobs:
cache: 'maven'
- name: Run tests
working-directory: main/manager-api
- run: mvn -B -q test -DfailIfNoTests=false
+ run: mvn -B test -DskipTests=false -DfailIfNoTests=false
web:
name: Vue (manager-web)
@@ -63,4 +90,6 @@ jobs:
working-directory: main/manager-web
run: |
npm ci --no-audit --no-fund
+ npm run test:contract
npm run test:unit
+ npm run build
diff --git a/main/manager-api/pom.xml b/main/manager-api/pom.xml
index 455ee6e11..e94004843 100644
--- a/main/manager-api/pom.xml
+++ b/main/manager-api/pom.xml
@@ -32,7 +32,7 @@
4.20.0
4.1.0
3.4.0
- true
+ false
diff --git a/main/manager-api/src/test/java/xiaozhi/modules/correctword/service/impl/CorrectWordFileServiceImplTest.java b/main/manager-api/src/test/java/xiaozhi/modules/correctword/service/impl/CorrectWordFileServiceImplTest.java
index 25fbebea7..b41953db6 100644
--- a/main/manager-api/src/test/java/xiaozhi/modules/correctword/service/impl/CorrectWordFileServiceImplTest.java
+++ b/main/manager-api/src/test/java/xiaozhi/modules/correctword/service/impl/CorrectWordFileServiceImplTest.java
@@ -14,9 +14,14 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
+import org.apache.ibatis.builder.MapperBuilderAssistant;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
+
import xiaozhi.modules.agent.dao.AgentCorrectWordMappingDao;
import xiaozhi.modules.agent.entity.AgentCorrectWordMappingEntity;
import xiaozhi.modules.correctword.dao.CorrectWordFileDao;
@@ -37,6 +42,20 @@ class CorrectWordFileServiceImplTest {
private final CorrectWordFileServiceImpl service =
new CorrectWordFileServiceImpl(fileDao, itemDao, mappingDao);
+ @BeforeAll
+ static void registerEntityMetadata() {
+ // 这条用例不起 Spring 上下文,MyBatis-Plus 的实体元数据没人注册,
+ // LambdaQueryWrapper 拼条件时找不到 lambda 缓存就抛异常。
+ // 全量跑的时候是前面的上下文测试顺带注册好的,单独跑就露馅。
+ // 这里自己补上,单独跑和跟着全量跑结果一样。
+ TableInfoHelper.initTableInfo(
+ new MapperBuilderAssistant(new MybatisConfiguration(), ""),
+ CorrectWordItemEntity.class);
+ TableInfoHelper.initTableInfo(
+ new MapperBuilderAssistant(new MybatisConfiguration(), ""),
+ CorrectWordFileEntity.class);
+ }
+
@Test
void getAllItemsByAgentId_returns_empty_list_when_no_mappings() {
when(mappingDao.selectByAgentId(AGENT_ID)).thenReturn(Collections.emptyList());
diff --git a/main/xiaozhi-server/tests/conftest.py b/main/xiaozhi-server/tests/conftest.py
index a269bb77f..b2c20386a 100644
--- a/main/xiaozhi-server/tests/conftest.py
+++ b/main/xiaozhi-server/tests/conftest.py
@@ -323,35 +323,25 @@ def _install_mock_layer() -> None:
asyncio.sleep = _fast_sleep # type: ignore[assignment]
- # 网络层 mock:如果真实 httpx 已加载,把它的 AsyncClient.send 替换成
+ # 网络层 mock:如果真实 httpx 已加载,把它的 send 替换成
# 立即抛 ConnectError 的桩,触发 ``_should_retry`` 走到 ``raise``,
# 但避免真发请求。Live 模式完全不安装这层。
if not LIVE_API_TESTS:
try:
- import httpx as _httpx # noqa: F401
+ import httpx as _httpx
- class _FakeAsyncClient:
- def __init__(self, *args, **kwargs):
- pass
+ async def _fake_async_send(self, request, **kwargs):
+ raise _httpx.ConnectError("MOCK: connect refused")
- async def send(self, *args, **kwargs):
- raise _httpx.ConnectError("MOCK: connect refused")
+ def _fake_send(self, request, **kwargs):
+ raise _httpx.ConnectError("MOCK: connect refused")
- async def aclose(self):
- return None
-
- class _FakeClient:
- def __init__(self, *args, **kwargs):
- pass
-
- def send(self, *args, **kwargs):
- raise _httpx.ConnectError("MOCK: connect refused")
-
- def close(self):
- return None
-
- _httpx.AsyncClient = _FakeAsyncClient # type: ignore[misc]
- _httpx.Client = _FakeClient # type: ignore[misc]
+ # 只换 send 这一个方法,不换整个类。有些库(openai 2.x 的
+ # SyncHttpxClientWrapper)继承 httpx.Client 再自己拼请求,
+ # 整个类被换掉的话它们继承到的是假类,拼请求时直接
+ # AttributeError,报错还完全看不出是 mock 层的问题
+ _httpx.AsyncClient.send = _fake_async_send # type: ignore[assignment]
+ _httpx.Client.send = _fake_send # type: ignore[assignment]
except ImportError:
pass
diff --git a/main/xiaozhi-server/tests/test_llm.py b/main/xiaozhi-server/tests/test_llm.py
index 931a16f9f..5a83f5826 100644
--- a/main/xiaozhi-server/tests/test_llm.py
+++ b/main/xiaozhi-server/tests/test_llm.py
@@ -65,6 +65,13 @@ def _build_provider():
ptype = get_provider_type("LLM", name)
if not ptype:
pytest.skip(f"LLM '{name}' 的 type 字段缺失")
+ if not LIVE_API_TESTS:
+ # mock 模式把网络拦了,这条链路拿不到真实回复,跑下来只是一次连接失败。
+ # 真要验这条链路,用 RUN_LIVE_API_TESTS=1 配真 key 跑
+ pytest.skip(
+ f"mock 模式不发真请求,跳过 LLM '{name}' 的链路验证。"
+ "真请求模式:export RUN_LIVE_API_TESTS=1 并填真 key 后再跑。"
+ )
from core.utils.llm import create_instance
return create_instance(ptype, cfg)