Files
DeepTutor/.github/workflows/tests.yml
Renn F dbd270cfdb feat(api): add opt-in fastapi-guard request screening
Add an off-by-default `security_guard` setting (system.json, with
DEEPTUTOR_GUARD_* deployment overrides) that mounts fastapi-guard's
pure-ASGI middleware in front of the routers: per-address rate limit,
IP allow/deny lists, ban list and an attack-pattern scan of path, query
and headers. Request bodies, WebSocket handshakes, Redis, CORS and
security headers are left alone.

The guard is added before the access-log and CORS middlewares so CORS
stays outermost and 429/403 responses carry CORS headers. When disabled
the package is never imported. When enabled without the package the
backend fails at startup with an install hint. fastapi-guard ships as
the optional `guard` extra (requirements/guard.txt, DEEPTUTOR_EXTRAS).
2026-10-16 16:24:52 +02:00

316 lines
11 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Tests
on:
workflow_dispatch:
schedule:
- cron: "17 3 * * *"
push:
branches:
- main
- dev
paths:
- "deeptutor/**"
- "deeptutor_cli/**"
- "tests/**"
- "requirements/**"
- "requirements.txt"
- "pyproject.toml"
- "web/**"
- ".github/workflows/tests.yml"
pull_request:
branches:
- main
- dev
paths:
- "deeptutor/**"
- "deeptutor_cli/**"
- "tests/**"
- "requirements/**"
- "requirements.txt"
- "pyproject.toml"
- "web/**"
- ".github/workflows/tests.yml"
jobs:
lint:
name: Lint and Format
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install lint tools
run: |
python -m pip install --upgrade pip
pip install ruff==0.16.0 import-linter==2.11
- name: Run Ruff lint
run: ruff check .
- name: Run Ruff format check
run: ruff format --check .
- name: Enforce dependency boundaries
run: |
lint-imports
python scripts/check_architecture.py
web-tests:
name: Web Node Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
working-directory: web
run: npm ci --legacy-peer-deps
- name: Run complete deterministic frontend gate
working-directory: web
run: npm run check
- name: Install Playwright Chromium
working-directory: web
run: npx playwright install --with-deps chromium
- name: Run interaction, accessibility, and visual matrix audits
working-directory: web
run: |
npm start -- --hostname 127.0.0.1 --port 3000 > /tmp/deeptutor-web-audit.log 2>&1 &
audit_server_pid=$!
trap 'kill "$audit_server_pid"' EXIT
for attempt in $(seq 1 100); do
if curl --fail --silent http://127.0.0.1:3000/ > /dev/null; then
break
fi
if ! kill -0 "$audit_server_pid" 2>/dev/null; then
cat /tmp/deeptutor-web-audit.log
exit 1
fi
sleep 0.1
done
WEB_BASE_URL=http://127.0.0.1:3000 npm run audit
multi-worker-web:
name: Four-worker browser acceptance
if: vars.DEEPTUTOR_MULTI_WORKER_E2E_URL != ''
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
working-directory: web
run: npm ci --legacy-peer-deps
- name: Install Playwright Chromium
working-directory: web
run: npx playwright install --with-deps chromium
- name: Run desktop and mobile four-worker scenarios
working-directory: web
run: >-
npx playwright test
--project=multi-worker-turns-desktop
--project=multi-worker-turns-mobile
env:
DEEPTUTOR_MULTI_WORKER_E2E: "1"
WEB_BASE_URL: ${{ vars.DEEPTUTOR_MULTI_WORKER_E2E_URL }}
NEXT_PUBLIC_API_BASE: ${{ vars.DEEPTUTOR_MULTI_WORKER_E2E_URL }}
DEEPTUTOR_MULTI_WORKER_CONTROL_URL: ${{ vars.DEEPTUTOR_MULTI_WORKER_CONTROL_URL || vars.DEEPTUTOR_MULTI_WORKER_E2E_URL }}
- name: Upload browser traces and videos
if: always()
uses: actions/upload-artifact@v4
with:
name: multi-worker-browser-evidence
path: |
web/playwright-report
web/test-results
if-no-files-found: ignore
import-check:
name: Import Check (Python ${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
env:
PYTHONIOENCODING: utf-8
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.11"
os: ubuntu-latest
- python-version: "3.12"
os: ubuntu-latest
- python-version: "3.13"
os: ubuntu-latest
- python-version: "3.14"
os: ubuntu-latest
- python-version: "3.14"
os: macos-latest
- python-version: "3.14"
os: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements/server.txt', 'requirements/cli.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install minimal dependencies for import check
run: |
python -m pip install --upgrade pip
pip install -r requirements/server.txt
# Exercise project metadata too, especially `requires-python`.
pip install -e . --no-deps
- name: Check module imports
run: |
echo "Testing with Python ${{ matrix.python-version }}"
python -c "from deeptutor.runtime.orchestrator import ChatOrchestrator; print('Orchestrator imports OK')"
python -c "from deeptutor.runtime.registry.tool_registry import get_tool_registry; print('Tool registry imports OK')"
python -c "from deeptutor.runtime.registry.capability_registry import get_capability_registry; print('Capability registry imports OK')"
python -c "from deeptutor.services.config.runtime_settings import RuntimeSettingsService; print('RuntimeSettingsService imports OK')"
python -c "from deeptutor.api.routers.unified_ws import unified_websocket; print('Unified WS imports OK')"
python -c "from deeptutor.services.prompt.manager import PromptManager; print('Prompt manager imports OK')"
python -c "from deeptutor.logging import configure_logging, bind_log_context, capture_process_logs, ProcessLogEvent; print('Logging imports OK')"
env:
PYTHONPATH: ${{ github.workspace }}
- name: Check lazy startup and isolated worker protocol
run: |
python -c "import sys; import deeptutor.runtime.registry.tool_registry; assert 'deeptutor.agents.chat.agentic_pipeline' not in sys.modules; print('Tool implementations stay cold')"
python -c "from deeptutor.runtime.isolated_worker import run_in_isolated_process_sync; assert run_in_isolated_process_sync('operator:add', 20, 22, timeout=15) == 42; print('Isolated worker protocol OK')"
env:
PYTHONPATH: ${{ github.workspace }}
python-tests:
name: Python Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
needs: import-check
services:
redis:
image: redis:7.4-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 3s
--health-retries 10
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13", "3.14"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements/server.txt', 'requirements/cli.txt', 'requirements/partners.txt', 'pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install smoke test dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/server.txt
pip install -r requirements/partners.txt
pip install pytest pytest-asyncio
- name: Install optional fastapi-guard
run: pip install -r requirements/guard.txt
- name: Install optional LightRAG SDK
if: matrix.python-version == '3.12'
run: pip install "lightrag-hku==1.5.7"
- name: Install optional GraphRAG SDK
if: matrix.python-version == '3.12'
run: pip install "graphrag>=3.0.1,<4.0.0"
- name: Create minimal runtime config
run: |
mkdir -p data/user/settings
cat > data/user/settings/main.yaml <<'YAML'
system:
language: en
logging:
level: WARNING
YAML
cp tests/fixtures/ci_model_catalog.json data/user/settings/model_catalog.json
- name: Run Python tests
run: |
echo "🧪 Running Python tests on Python ${{ matrix.python-version }}"
pytest -q tests deeptutor/learning/tests
env:
PYTHONPATH: ${{ github.workspace }}
DEEPTUTOR_TEST_REDIS_URL: redis://127.0.0.1:6379/0
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [lint, web-tests, multi-worker-web, import-check, python-tests]
if: always()
steps:
- name: Check test results
run: |
echo "## 🧪 Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Lint and format | ${{ needs.lint.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Web node tests | ${{ needs.web-tests.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Four-worker browser acceptance | ${{ needs.multi-worker-web.result == 'success' && '✅ Passed' || needs.multi-worker-web.result == 'skipped' && '⏭️ Fixture not configured' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Import/lazy/worker check (3.11–3.14; 3.14 on Linux/macOS/Windows) | ${{ needs.import-check.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Python tests (3.11/3.12/3.13/3.14) | ${{ needs.python-tests.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
- name: Fail if tests failed
if: needs.lint.result == 'failure' || needs.web-tests.result == 'failure' || needs.multi-worker-web.result == 'failure' || needs.import-check.result == 'failure' || needs.python-tests.result == 'failure'
run: exit 1