Files
DeepTutor/.github/workflows/tests.yml
Leveling 9bed004617 test(parsing): stop racing interpreter startup in the MinerU lifecycle checks (#3089)
* test(parsing): stop racing interpreter startup in the MinerU lifecycle checks

The Windows `import-check` job flakes on `dev`. It failed at 2026-11-30 03:12
and 03:32 on `79a66cb3` and `6b00f010`, passed on the same step 90 minutes
later in another run, and passed on `218dbe31` the evening before. Nothing
between those runs touched `.github/`, `tests/services/parsing/`,
`tests/runtime/` or the MinerU engine, so the workflow and the code under test
were identical in the green and red runs.

Reproduced, and the cause is a timing premise in the tests, not the runner.

The race
--------

`test_deadline_and_cancellation_settle_the_owned_tree[True]` sets
`timeout=0.8` and only cancels once the fixture child has spawned a grandchild
and written `child.pid`:

    def check():
        if cancelled and list(...glob(".../child.pid")):
            raise IndexingCancelled(...)

`local.py` starts its clock before `cli_process()`, which on Windows creates a
Job Object, spawns a suspended interpreter, resumes it and queries its threads.
That work plus two more interpreter startups has to fit inside the same 0.8s.
When it does not, the deadline wins before the marker exists and the assertion
reports `TIMEOUT is not CANCELLED`.

Measured on an idle machine the marker lands in 0.067-0.085s, so the margin
looked comfortable. Delaying only the child's first write, with no CPU
contention at all:

    startup delay | result    | expected  | verdict
         0.0s     | cancelled | cancelled | pass
         0.5s     | cancelled | cancelled | pass
         0.7s     | timeout   | cancelled | FAIL
         0.9s     | timeout   | cancelled | FAIL
         1.2s     | timeout   | cancelled | FAIL

CPU contention alone reproduced the same signature
`assert <LocalParseReason.TIMEOUT> is <LocalParseReason.CANCELLED>` at line 138,
plus `assert 2.087 < 2` and `assert 3.757 < 1.5` on neighbouring cases.

The production ordering is correct and is left alone: `run.check()` is
evaluated before the deadline comparison, so an available cancellation always
wins. What the tests must not do is depend on how fast the runner started a
Python interpreter.

What changed
------------

- `_await_marker()` waits for a fixture marker with a real timeout and a
  message that distinguishes "the CLI never started" from "the runner was
  slow". Bare `(path,) = glob(...)` unpacking turned both into
  `ValueError: not enough values to unpack (expected 1, got 0)`, which is what
  made these CI failures unreadable.
- The cancellation case waits for the recorded child before raising, so the
  interruption is decided by policy rather than by interpreter startup. A 3s
  startup delay now passes where 0.7s used to fail.
- Wall-clock bounds that were only guarding "did not wait for the descendant"
  were widened off the interpreter-startup budget (`elapsed < 2` -> `< 15`,
  `elapsed < 1.5` -> `< 10`, `elapsed < 2.5` -> `< 15`). The idle-threshold and
  deadline assertions that carry the actual meaning are unchanged.
- `_await_settled()` treats `psutil.AccessDenied` as "not settled yet" instead
  of raising mid-test.
- The decoy process in `test_parent_exit_does_not_wait_for_descendant_stdout`
  lives 120s instead of 10s, so a slow run cannot make it die of old age and be
  reported as "cleanup touched an unrelated process".
- `test_detached_venv_launcher_has_no_console` asserts the marker exists before
  reading it, instead of raising `FileNotFoundError` after its 15s wait.

Observability
-------------

The Windows step now runs with `-rA --durations=15`. Without them the job
reported only "Process completed with exit code 1" with no test name, which is
why these failures needed a local reproduction to attribute.

Verification
------------

- `pytest -q -rA --durations=15 tests/services/parsing/test_mineru_process_lifecycle.py tests/runtime/test_launcher.py::test_detached_venv_launcher_has_no_console`
  -> 7 passed, 10 skipped (the skips are POSIX/Darwin-only cases).
- Deliberate-startup-delay harness: 0.0/0.5/0.9/1.5/3.0s all report
  `cancelled` after the change; 0.7s+ reported `timeout` before it.
- `ruff check` and `ruff format --check` clean on both files; workflow YAML
  parses.

No production code is changed.

* test(parsing): synchronise the deadline fixtures with grandchild startup

Addresses review on #3089. Two real defects:

1. The deadline case of test_deadline_and_cancellation_settle_the_owned_tree
   still raced. Only the cancellation branch waited for `child.pid`; the
   deadline branch killed the fixture at 0.8s and then read a marker that was
   never written, so a 1.3s startup delay produced `TIMEOUT` and then a failed
   marker read. Both branches now synchronise through `check()`: it waits for
   the recorded grandchild and only then either raises (cancellation) or returns
   and lets the deadline comparison run. The timeout assertion is preserved.

   test_explicit_client_timeout_also_bounds_parent_runtime had the same shape —
   it read `deadline.txt` after a 1.2s kill. The record is written before the
   child parks, so it exists whenever the child started at all, and the read now
   reports "CLI did not start" instead of an unpacking error.

2. test_parent_exit_does_not_wait_for_descendant_stdout had lost its teeth: the
   new 10s bound exceeded the grandchild's 2s sleep, so an implementation that
   waited for inherited stdout could finish inside the bound and pass. The
   grandchild now lives 60s and the bound is 20s, derived from the fixture, so
   waiting for it fails the test again.

Verified with a 1.3s pre-startup delay (the reviewer's repro): both lifecycle
cases report the expected reason and the tree is settled. 0.0/1.3/2.0/3.0s all
pass. `7 passed, 10 skipped`; ruff clean.

* test: wait for the MinerU deadline record before enforcing the timeout

---------

Co-authored-by: Qiuner <wdst3635@163.com>
2026-11-30 05:55:09 -03:00

439 lines
16 KiB
YAML
Raw Permalink 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
- preview
paths:
- "deeptutor/**"
- "deeptutor_cli/**"
- "tests/**"
- "requirements/**"
- "requirements.txt"
- "pyproject.toml"
- "web/**"
- "packages/chat-engine/**"
- "apps/desktop/**"
- ".github/workflows/tests.yml"
pull_request:
branches:
- main
- dev
- preview
paths:
- "deeptutor/**"
- "deeptutor_cli/**"
- "tests/**"
- "requirements/**"
- "requirements.txt"
- "pyproject.toml"
- "web/**"
- "packages/chat-engine/**"
- "apps/desktop/**"
- ".github/workflows/tests.yml"
# A new push supersedes every earlier run for the same PR/branch. Without this,
# each fix-up commit leaves the previous full matrix running to completion,
# delaying feedback for the author and every other PR in the queue.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# Keep Linux runners on the LTS supported by the pinned browser toolchain.
jobs:
desktop:
name: Desktop Shell (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
# Windows exercises taskkill-based shutdown; the others process groups.
os: [ubuntu-24.04, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: apps/desktop/package-lock.json
- name: Check and test the shell
working-directory: apps/desktop
shell: bash
env:
ELECTRON_SKIP_BINARY_DOWNLOAD: "1"
run: npm ci && npm run check && npm test
chat-engine:
name: Experimental TypeScript Chat Engine
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: packages/chat-engine/package-lock.json
- name: Check scheduler contracts and dependency boundaries
working-directory: packages/chat-engine
run: npm ci && npm test
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install compatibility adapters
run: pip install -r requirements/full.txt -r requirements/partners.txt pytest pytest-asyncio
- name: Create synthetic model configuration
run: |
mkdir -p data/user/settings
cp tests/fixtures/ci_model_catalog.json data/user/settings/model_catalog.json
- name: Exercise chat and partner behavior through TypeScript
env:
DEEPTUTOR_CHAT_ENGINE: typescript
PYTHONPATH: ${{ github.workspace }}
run: |
pytest -q tests/agents/chat tests/runtime/test_ts_engine.py \
tests/services/partners/test_partner_runtime.py \
tests/capabilities/test_partner_group_capability.py \
tests/capabilities/test_mastery_loop_pipeline.py
- name: Exercise the Python reference and durable event subscriptions
env:
DEEPTUTOR_CHAT_ENGINE: python
PYTHONPATH: ${{ github.workspace }}
run: |
pytest -q tests/agents/chat/test_agent_loop.py \
tests/runtime/coordination/test_event_notifications.py \
tests/app/test_turn_application_service.py
- name: Exercise native model, history, tool boundaries and lazy API admission
env:
PYTHONPATH: ${{ github.workspace }}
run: |
pytest -q tests/runtime/test_native_engine.py \
tests/api/test_router_loader.py
lint:
name: Lint and Format
runs-on: ubuntu-24.04
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-24.04
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-24.04
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-24.04
- python-version: "3.12"
os: ubuntu-24.04
- python-version: "3.13"
os: ubuntu-24.04
- python-version: "3.14"
os: ubuntu-24.04
- 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/full.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/full.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 }}
- name: Verify native process ownership and hidden launch on Windows
if: runner.os == 'Windows'
run: |
python -m pip install pytest pytest-asyncio pywin32
# -rA and --durations make a failure triageable without the job log:
# without them this step reported only "exit code 1", and the 2026-11-30
# failures could not be attributed to a test or a timing margin.
python -m pytest -q -rA --durations=15 tests/services/parsing/test_mineru_process_lifecycle.py tests/runtime/test_launcher.py::test_detached_venv_launcher_has_no_console
env:
PYTHONPATH: ${{ github.workspace }}
DEEPTUTOR_HOME: ${{ runner.temp }}/mineru-process-tests
python-tests:
name: Python Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-24.04
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/full.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/full.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
video-lesson-sandbox:
name: Video lesson isolation (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install test dependencies
run: pip install -r requirements/full.txt pytest pytest-asyncio
- name: Check real rendering, isolation, cancellation and timeout
env:
DEEPTUTOR_TEST_VIDEO_SANDBOX: "1"
DEEPTUTOR_REMOTION_RUNTIME: ${{ runner.temp }}/remotion
PYTHONPATH: ${{ github.workspace }}
run: |
pytest -q tests/agents/video_lesson tests/services/sandbox/test_process_cancellation.py
node --test tests/services/sandbox/javascript.test.mjs
test-summary:
name: Test Summary
runs-on: ubuntu-24.04
needs: [desktop, chat-engine, lint, web-tests, multi-worker-web, import-check, python-tests, video-lesson-sandbox]
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 "| macOS desktop shell | ${{ needs.desktop.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| TypeScript chat engine | ${{ needs.chat-engine.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Video lesson isolation | ${{ needs.video-lesson-sandbox.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $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.video-lesson-sandbox.result != 'success' || needs.desktop.result == 'failure' || needs.chat-engine.result == 'failure' || 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