From 66a0a7c9c8815d8841b10162251c4361e768f3af Mon Sep 17 00:00:00 2001 From: huanghuoguoguo <1051233107@qq.com> Date: Fri, 8 May 2026 14:52:21 +0800 Subject: [PATCH] fix(test): make test-quick reliable as developer gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes for D-001验收问题: 1. test-quick.sh: use set -euo pipefail, uv run ruff, no tail pipe 2. Remove unused imports in factories (app.py, platform.py, provider.py) 3. Fix unused variable in smoke test 4. Add noqa: E402 to test_n8nsvapi.py lazy imports 5. Update smoke test docs: "minimal fake flow" not full pipeline Now test-quick is a reliable gate: lint failures exit 1, test failures propagate. Co-Authored-By: Claude Opus 4.7 --- scripts/test-quick.sh | 19 +++++++-------- tests/factories/app.py | 2 -- tests/factories/platform.py | 1 - tests/factories/provider.py | 2 +- tests/smoke/test_fake_message_flow.py | 28 +++++++++++++--------- tests/unit_tests/pipeline/test_n8nsvapi.py | 6 ++--- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/scripts/test-quick.sh b/scripts/test-quick.sh index e91cff76..511c457c 100755 --- a/scripts/test-quick.sh +++ b/scripts/test-quick.sh @@ -4,31 +4,30 @@ # Runs linting, unit tests, and smoke tests without requiring real provider keys # Suitable for local branch validation -set -e +set -euo pipefail echo "=== LangBot Quick Self-Test ===" echo "" # 1. Ruff check echo "[1/3] Running ruff check..." -if command -v ruff &> /dev/null; then - ruff check src/langbot/ tests/ --quiet || { - echo "⚠ Ruff check found issues. Run 'ruff check --fix' to auto-fix." - } -else - echo "⚠ ruff not installed, skipping lint check" -fi +uv run ruff check src/langbot/ tests/ --output-format=concise || { + echo "" + echo "⚠ Ruff check found issues. Run 'uv run ruff check --fix' to auto-fix." + exit 1 +} +echo "✓ Ruff check passed" echo "" # 2. Unit tests echo "[2/3] Running unit tests..." -uv run pytest tests/unit_tests/ -q --tb=short 2>&1 | tail -5 +uv run pytest tests/unit_tests/ -q --tb=short echo "" # 3. Smoke tests (if exists) echo "[3/3] Running smoke tests..." if [ -d "tests/smoke" ]; then - uv run pytest tests/smoke/ -q --tb=short 2>&1 | tail -5 + uv run pytest tests/smoke/ -q --tb=short else echo "No smoke tests found, skipping" fi diff --git a/tests/factories/app.py b/tests/factories/app.py index 80b0650a..cf1bbaf4 100644 --- a/tests/factories/app.py +++ b/tests/factories/app.py @@ -8,8 +8,6 @@ from __future__ import annotations from unittest.mock import AsyncMock, Mock -import langbot_plugin.api.entities.builtin.provider.session as provider_session - class FakeApp: """Mock Application object providing all basic dependencies needed by stages.""" diff --git a/tests/factories/platform.py b/tests/factories/platform.py index e0c113e5..725cead9 100644 --- a/tests/factories/platform.py +++ b/tests/factories/platform.py @@ -13,7 +13,6 @@ import typing import langbot_plugin.api.entities.builtin.platform.message as platform_message import langbot_plugin.api.entities.builtin.platform.events as platform_events import langbot_plugin.api.entities.builtin.platform.entities as platform_entities -import langbot_plugin.api.entities.builtin.provider.session as provider_session class FakePlatform: diff --git a/tests/factories/provider.py b/tests/factories/provider.py index 7895cd2c..d5097854 100644 --- a/tests/factories/provider.py +++ b/tests/factories/provider.py @@ -6,7 +6,7 @@ Provides a deterministic fake provider that simulates LLM responses without real from __future__ import annotations -from unittest.mock import AsyncMock, Mock +from unittest.mock import Mock import typing import langbot_plugin.api.entities.builtin.provider.message as provider_message diff --git a/tests/smoke/test_fake_message_flow.py b/tests/smoke/test_fake_message_flow.py index 3acef665..aa1bf827 100644 --- a/tests/smoke/test_fake_message_flow.py +++ b/tests/smoke/test_fake_message_flow.py @@ -1,8 +1,10 @@ """ -Smoke tests for LangBot core message flow. +Minimal fake flow smoke tests for LangBot. -These tests verify the basic message processing flow works correctly -using fake providers and platforms. +These tests verify basic component interactions using fake providers and platforms. +Not a full pipeline integration test - tests individual factory components. + +For full pipeline tests, see tests/integration/ (planned). """ from __future__ import annotations @@ -272,21 +274,25 @@ class TestFakeMessageFlow: class TestMessageFlowIntegration: - """Integration smoke tests for full message flow.""" + """Minimal fake flow integration tests. + + These tests verify component interactions but do NOT run full LangBot pipeline. + For real pipeline tests, integration tests are needed (planned). + """ @pytest.mark.asyncio async def test_minimal_message_flow(self): - """Smoke test: message enters, fake provider responds, platform captures outbound. + """Minimal fake flow test: fake query -> fake provider -> fake platform. This test verifies: - 1. Fake app is created - 2. Fake text message enters - 3. Fake provider returns LANGBOT_FAKE_PONG - 4. Fake platform captures outbound response - 5. No unexpected exception + 1. Fake text query is created + 2. Fake provider returns LANGBOT_FAKE_PONG + 3. Fake platform captures outbound response + 4. No unexpected exception + + Note: This does NOT run actual LangBot pipeline stages. """ # Setup - app = FakeApp() platform = FakePlatform(bot_account_id="test-bot") provider = fake_provider_pong() model = fake_model(provider=provider) diff --git a/tests/unit_tests/pipeline/test_n8nsvapi.py b/tests/unit_tests/pipeline/test_n8nsvapi.py index 68f3cdcc..975fd0d2 100644 --- a/tests/unit_tests/pipeline/test_n8nsvapi.py +++ b/tests/unit_tests/pipeline/test_n8nsvapi.py @@ -23,9 +23,9 @@ sys.modules.setdefault('langbot.pkg.provider.runner', _mock_runner) sys.modules.setdefault('langbot.pkg.core.app', MagicMock()) sys.modules.setdefault('langbot.pkg.utils.httpclient', MagicMock()) -import pytest -import langbot_plugin.api.entities.builtin.provider.message as provider_message -from langbot.pkg.provider.runners.n8nsvapi import N8nServiceAPIRunner +import pytest # noqa: E402 +import langbot_plugin.api.entities.builtin.provider.message as provider_message # noqa: E402 +from langbot.pkg.provider.runners.n8nsvapi import N8nServiceAPIRunner # noqa: E402 # ---------------------------------------------------------------------------