name: Test Suite on: workflow_dispatch: push: branches: [main] pull_request: branches: [main] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: contents: read jobs: changes: name: Detect changes runs-on: ubuntu-latest outputs: python_required: ${{ steps.paths.outputs.python_required }} webui_required: ${{ steps.paths.outputs.webui_required }} tui_required: ${{ steps.paths.outputs.tui_required }} docker_required: ${{ steps.paths.outputs.docker_required }} native_required: ${{ steps.paths.outputs.native_required }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Select checks by affected contracts id: paths shell: bash env: EVENT_NAME: ${{ github.event_name }} BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} run: >- python scripts/ci_scope.py --event "$EVENT_NAME" --base "$BASE_SHA" --head "$HEAD_SHA" test: name: Python (${{ matrix.name }}) needs: changes if: needs.changes.outputs.python_required == 'true' runs-on: ${{ matrix.os }} # Windows runs real isolated update jobs before the complete compatibility # suite; that suite was still progressing at the former 20-minute job cap. timeout-minutes: ${{ matrix.os == 'windows-latest' && 30 || 20 }} env: PYTEST_ADDOPTS: "-o tmp_path_retention_policy=failed -p scripts.pytest_timing" strategy: fail-fast: false matrix: include: - name: minimum, 3.11 os: ubuntu-latest python-version: "3.11" coverage: false # Keep exact Rich output and real prompt_toolkit pipes in a fresh # CLI process: long-lived workers can exceed select()'s fd limit. pytest_args: "-n auto --dist loadfile --ignore=tests/cli/test_commands.py --ignore=tests/cli/test_cli_input.py --ignore=tests/cli/test_desktop_target.py --ignore=tests/cli/test_desktop_target_entrypoints.py" - name: latest, 3.14 + coverage os: ubuntu-latest python-version: "3.14" coverage: true pytest_args: "-n auto --dist loadfile --ignore=tests/cli/test_commands.py --ignore=tests/cli/test_cli_input.py --ignore=tests/cli/test_desktop_target.py --ignore=tests/cli/test_desktop_target_entrypoints.py" - name: Windows, 3.14 os: windows-latest python-version: "3.14" coverage: false # Process identities run serially; isolated update jobs use case-level # scheduling below so one file cannot serialize all real venv work. # Retain main's three-worker budget and the separate native-process job. pytest_args: "-n 3 --dist loadfile --ignore=tests/cli/test_commands.py --ignore=tests/cli/test_cli_input.py --ignore=tests/cli/test_desktop_target.py --ignore=tests/cli/test_desktop_target_entrypoints.py --ignore=tests/tools/test_exec_platform.py --ignore=tests/cli/test_wsl_browser.py --ignore=tests/test_install_scripts.py --ignore=tests/test_update_jobs.py --ignore=tests/test_update_profiles.py" steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Check Python import boundaries if: matrix.coverage run: python -m scripts.check_import_boundaries - name: Install uv uses: astral-sh/setup-uv@v4 with: enable-cache: true cache-dependency-glob: pyproject.toml - name: Install system dependencies (Linux) if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install -y libolm-dev build-essential - name: Install dependencies run: uv sync --all-extras --dev - name: Install channel dependencies run: uv run --no-sync python -m scripts.install_channel_dependencies --all-channels - name: Verify dependency consistency run: uv pip check - name: Install pipx for offline installer checks if: runner.os == 'Linux' shell: bash run: | uv tool install pipx==1.17.12 uv tool dir --bin >> "$GITHUB_PATH" # Channel requirements live in manifests rather than uv.lock. Avoid a # later uv run sync pruning the packages installed by the previous step. - name: Lint with ruff if: matrix.coverage run: uv run --no-sync ruff check nanobot tests conftest.py scripts/check_import_boundaries.py scripts/pytest_timing.py scripts/ci_scope.py scripts/ci_gate.py scripts/native_acceptance_input.py scripts/verify_packaged_update.py - name: Type check with BasedPyright (strict) if: matrix.coverage run: uv run --no-sync basedpyright - name: Check Windows update coordination before the full suite if: runner.os == 'Windows' run: >- uv run --no-sync python -m pytest tests/test_installation_lock.py tests/test_update_profiles.py tests/utils/test_helpers.py::test_atomic_record_reader_does_not_block_concurrent_replacement tests/gateway/test_runtime.py::test_runtime_state_publish_keeps_existing_snapshot_readable tests/gateway/test_runtime.py::test_runtime_state_reader_does_not_block_publish_while_decoding -q --junitxml=test-results/coordination.xml --timing-report=test-results/coordination.json # Each update job owns its venv, HOME, profile and lock directory. Preserve # the real installation/restore checks, but avoid a loadfile straggler and # disk contention with timing-sensitive runtime-registration checks. - name: Run Windows isolated update jobs if: runner.os == 'Windows' && github.event_name != 'push' && needs.changes.outputs.native_required == 'true' run: >- uv run --no-sync python -m pytest tests/test_update_jobs.py -n 3 --dist load -vv --durations=25 --durations-min=1.0 --junitxml=test-results/update-jobs.xml --timing-report=test-results/update-jobs.json - name: Run tests with coverage if: matrix.coverage run: >- uv run --no-sync python -m pytest ${{ matrix.pytest_args }} --cov=nanobot --cov-report=term-missing:skip-covered -o faulthandler_timeout=60 --junitxml=test-results/main.xml --timing-report=test-results/main.json --durations=25 --durations-min=1.0 - name: Run serial CLI input and command tests with coverage if: matrix.coverage run: >- uv run --no-sync python -m pytest tests/cli/test_cli_input.py tests/cli/test_desktop_target.py tests/cli/test_desktop_target_entrypoints.py tests/cli/test_commands.py --cov=nanobot --cov-append --cov-report=term-missing:skip-covered --junitxml=test-results/cli.xml --timing-report=test-results/cli.json --durations=25 --durations-min=1.0 - name: Run compatibility tests if: ${{ !matrix.coverage }} run: >- uv run --no-sync python -m pytest ${{ matrix.pytest_args }} --junitxml=test-results/main.xml --timing-report=test-results/main.json --durations=25 --durations-min=1.0 - name: Run serial CLI input and command compatibility tests if: ${{ !matrix.coverage }} run: >- uv run --no-sync python -m pytest tests/cli/test_cli_input.py tests/cli/test_desktop_target.py tests/cli/test_desktop_target_entrypoints.py tests/cli/test_commands.py --junitxml=test-results/cli.xml --timing-report=test-results/cli.json --durations=25 --durations-min=1.0 - name: Upload Python test timings if: always() uses: actions/upload-artifact@v4 with: name: python-timings-${{ matrix.os }}-${{ matrix.python-version }} path: test-results/ retention-days: 7 windows_process: name: Python (Windows process compatibility) env: PYTEST_ADDOPTS: "-o tmp_path_retention_policy=failed -p scripts.pytest_timing" needs: changes if: needs.changes.outputs.python_required == 'true' runs-on: windows-latest timeout-minutes: 20 steps: - uses: actions/checkout@v4 - name: Set up Python 3.14 uses: actions/setup-python@v5 with: python-version: "3.14" - name: Install uv uses: astral-sh/setup-uv@v4 with: enable-cache: true cache-dependency-glob: pyproject.toml - name: Install dependencies run: uv sync --all-extras --dev - name: Install channel dependencies run: uv run --no-sync python -m scripts.install_channel_dependencies --all-channels - name: Verify dependency consistency run: uv pip check - name: Run Windows process compatibility tests run: >- uv run --no-sync python -m pytest tests/tools/test_exec_platform.py tests/cli/test_wsl_browser.py --junitxml=test-results/process.xml --timing-report=test-results/process.json --durations=25 --durations-min=1.0 - name: Upload Windows process test timings if: always() uses: actions/upload-artifact@v4 with: name: python-timings-windows-process path: test-results/ retention-days: 7 windows_installers: name: Python (Windows installer compatibility) needs: changes if: github.event_name != 'push' && needs.changes.outputs.python_required == 'true' && needs.changes.outputs.native_required == 'true' runs-on: windows-latest # The real installer matrix took 18m06s alone; process checks and teardown # previously pushed the combined job beyond its 20-minute bound. timeout-minutes: 25 env: PYTEST_ADDOPTS: "-o tmp_path_retention_policy=failed -p scripts.pytest_timing" steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.14' - uses: astral-sh/setup-uv@v4 with: enable-cache: true cache-dependency-glob: pyproject.toml - name: Install dependencies run: uv sync --all-extras --dev - name: Install pipx for offline installer checks shell: bash run: | uv tool install pipx==1.17.12 uv tool dir --bin >> "$GITHUB_PATH" # Each case owns an isolated manager/config root. Keep the existing # four-worker budget, independent of process-identity compatibility checks. - name: Run Windows installer checks run: >- uv run --no-sync python -m pytest tests/test_install_scripts.py -n 4 --dist load -x -vv --durations=10 --junitxml=test-results/installers.xml --timing-report=test-results/installers.json - name: Upload Windows process test timings if: always() uses: actions/upload-artifact@v4 with: name: python-timings-windows-installers path: test-results/ retention-days: 7 webui_checks: name: WebUI checks and build needs: changes if: needs.changes.outputs.webui_required == 'true' runs-on: ubuntu-latest timeout-minutes: 15 steps: - uses: actions/checkout@v4 - name: Set up Bun uses: oven-sh/setup-bun@v2 with: bun-version: 1.3.13 - name: Verify npm lockfile working-directory: webui run: npm ci --ignore-scripts --dry-run - name: Install WebUI dependencies working-directory: webui run: bun install --frozen-lockfile - name: Check WebUI import boundaries working-directory: webui run: bun run check:imports - name: Test client import checker with WebUI dependencies working-directory: webui run: bun run test:imports - name: Lint WebUI working-directory: webui run: bun run lint - name: Type check WebUI and unit tests working-directory: webui run: bun run typecheck - name: Test WebUI working-directory: webui run: bun run test:coverage - name: Build WebUI working-directory: webui run: bun run build webui_browser: name: WebUI browser needs: changes if: needs.changes.outputs.webui_required == 'true' runs-on: ubuntu-latest timeout-minutes: 15 steps: - uses: actions/checkout@v4 - name: Set up Bun uses: oven-sh/setup-bun@v2 with: bun-version: 1.3.13 - name: Install WebUI dependencies working-directory: webui run: bun install --frozen-lockfile - name: Install browser for layout regressions working-directory: webui run: bun x playwright install --with-deps chromium - name: Test browser layout and history motion working-directory: webui run: bun run test:browser webui: needs: [changes, webui_checks, webui_browser] if: always() && needs.changes.outputs.webui_required == 'true' runs-on: ubuntu-latest timeout-minutes: 1 steps: # Keep the existing check name dependent on every WebUI acceptance check. - name: Require both WebUI jobs to pass env: CHECKS_RESULT: ${{ needs.webui_checks.result }} BROWSER_RESULT: ${{ needs.webui_browser.result }} run: test "$CHECKS_RESULT" = success && test "$BROWSER_RESULT" = success tui: needs: changes if: needs.changes.outputs.tui_required == 'true' name: ${{ matrix.name }} runs-on: ${{ matrix.os }} timeout-minutes: 10 strategy: fail-fast: false matrix: include: - name: Terminal UI os: ubuntu-latest - name: Terminal UI (Windows) os: windows-latest steps: - uses: actions/checkout@v4 - name: Set up Bun uses: oven-sh/setup-bun@v2 with: bun-version: 1.3.13 # Build with baseline Bun directly: its Windows cross-target extractor is unreliable. bun-download-url: ${{ runner.os == 'Windows' && 'https://github.com/oven-sh/bun/releases/download/bun-v1.3.13/bun-windows-x64-baseline.zip' || '' }} - name: Install TUI dependencies working-directory: tui run: bun install --frozen-lockfile - name: Check TUI import boundaries working-directory: tui run: bun run check:imports - name: Test client import checker with TUI dependencies working-directory: tui run: bun run test:imports - name: Check TUI working-directory: tui run: bun run check - name: Test TUI working-directory: tui run: bun run test - name: Test TUI in a real pseudo-terminal if: runner.os != 'Windows' working-directory: tui run: python3 scripts/pty_smoke.py - name: Set up Python for native package acceptance uses: actions/setup-python@v5 with: python-version: '3.11' - name: Test TUI in a real ConPTY terminal if: runner.os == 'Windows' working-directory: tui shell: pwsh run: | python -m pip install --disable-pip-version-check pywinpty==3.0.5 python scripts/conpty_smoke.py - name: Build TUI working-directory: tui run: bun run build - name: Verify licensed Linux release archive if: runner.os == 'Linux' working-directory: tui run: | bun scripts/release-notices.ts linux-x64 python3 scripts/package-release.py linux-x64 - name: Verify licensed Windows release archive if: runner.os == 'Windows' working-directory: tui shell: pwsh run: | bun scripts/release-notices.ts win32-x64 python scripts/package-release.py win32-x64 native: name: Native package acceptance needs: changes if: github.event_name != 'push' && needs.changes.outputs.native_required == 'true' uses: ./.github/workflows/native-acceptance.yml docker: needs: changes if: needs.changes.outputs.docker_required == 'true' runs-on: ubuntu-latest timeout-minutes: 20 steps: - uses: actions/checkout@v4 - name: Build image with default channel dependencies run: docker build -t nanobot:test . - name: Verify first-boot WebUI and API run: python scripts/docker_compose_smoke.py --image nanobot:test - name: Verify Docker Compose startup and privilege boundary env: HOME: ${{ runner.temp }} run: | docker compose run --rm --no-deps --build -T nanobot-cli status docker compose run --rm --no-deps -T --entrypoint sh nanobot-cli -s <<'OUTER' set -eu field() { awk -v key="$1:" '$1 == key { print $2 }' /proc/self/status } test "$(id -u)" = "0" test "$(field NoNewPrivs)" = "1" setpriv --reuid=nanobot --regid=nanobot --init-groups sh -s <<'INNER' set -eu field() { awk -v key="$1:" '$1 == key { print $2 }' /proc/self/status } test "$(id -u)" = "1000" test "$(field NoNewPrivs)" = "1" for capability_set in CapInh CapPrm CapEff CapAmb; do test "$(field "$capability_set")" = "0000000000000000" done INNER OUTER docker compose -f docker-compose.yml -f docker-compose.bwrap.yml --profile cli \ config --format json > "${RUNNER_TEMP}/bwrap-compose.json" python - <<'PY' import json import os from pathlib import Path config = json.loads(Path(os.environ["RUNNER_TEMP"], "bwrap-compose.json").read_text()) for service_name in ("nanobot-gateway", "nanobot-api", "nanobot-cli"): service = config["services"][service_name] assert {"CHOWN", "SETGID", "SETUID", "SYS_ADMIN"} <= set(service["cap_add"]) assert "no-new-privileges:true" in service["security_opt"] PY - name: Verify default WhatsApp dependencies run: docker run --rm --entrypoint python nanobot:test -c "import neonize, segno" - name: Verify runtime dependency permissions run: >- docker run --rm --user 1000:1000 --entrypoint sh nanobot:test -c 'test -w /app/.venv && test ! -w /app && test ! -w /app/nanobot && python -m scripts.install_channel_dependencies discord && python -c "import discord"' required: name: CI required needs: [changes, test, windows_process, windows_installers, webui_checks, webui_browser, webui, tui, docker, native] if: always() runs-on: ubuntu-latest timeout-minutes: 2 steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Require every selected check env: CHECK_RESULTS: ${{ toJSON(needs) }} EVENT_NAME: ${{ github.event_name }} run: python scripts/ci_gate.py