Files
nanobot/.github/workflows/ci.yml
T
Xubin Renandchengyongru fbb61a373f feat(update): integrate managed installs and recoverable in-app updates (#6168)
Add owner-aware Stable and Preview updates with explicit consent, verified release plans, protected process handoff and bounded service recovery. Keep configuration and conversations separate from program rollback.

Include the compact About controls, Windows long-path support, native package recovery checks and optional macOS Dock lifecycle integration. Preserve documented guidance for installations owned by other managers.

This code integration does not publish packages, enable signing or advance the public update channel.

Co-authored-by: chengyongru <61816729+chengyongru@users.noreply.github.com>
2026-10-21 19:16:56 +08:00

637 lines
24 KiB
YAML

name: Test Suite
on:
workflow_dispatch:
push:
branches: [main]
paths-ignore:
- docs/**
- .agent/**
- .github/ISSUE_TEMPLATE/**
- AGENTS.md
- CLAUDE.md
- COMMUNICATION.md
- CONTRIBUTING.md
- README.md
- SECURITY.md
- webui/README.md
pull_request:
branches: [main]
paths-ignore:
- docs/**
- .agent/**
- .github/ISSUE_TEMPLATE/**
- AGENTS.md
- CLAUDE.md
- COMMUNICATION.md
- CONTRIBUTING.md
- README.md
- SECURITY.md
- webui/README.md
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 }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect Python-relevant changes
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_required=true
webui_required=true
tui_required=true
docker_required=true
if [[ "$EVENT_NAME" == "pull_request" ]]; then
diff_range="${BASE_SHA}...${HEAD_SHA}"
else
diff_range="${BASE_SHA}..${HEAD_SHA}"
fi
if git cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null &&
changed_files="$(git diff --name-only --no-renames "$diff_range")" &&
[[ -n "$changed_files" ]]; then
python_required=false
webui_required=false
tui_required=false
docker_required=false
while IFS= read -r file; do
case "$file" in
.github/workflows/*)
# A workflow change must exercise every affected execution path.
python_required=true
webui_required=true
tui_required=true
docker_required=true
;;
webui/*|nanobot/channels/*/webui/*|nanobot/channels/*/tests/webui/*)
webui_required=true
# The Docker image builds and bundles both WebUI trees.
docker_required=true
;;
nanobot/*)
# Channel WebUI files were handled by the previous case.
python_required=true
docker_required=true
;;
tests/test_docker.sh)
docker_required=true
;;
pyproject.toml|hatch_build.py|scripts/install_channel_dependencies.py)
python_required=true
docker_required=true
;;
scripts/check_client_import_boundaries.*)
webui_required=true
tui_required=true
;;
tests/*|conftest.py|uv.lock|scripts/*)
python_required=true
;;
Dockerfile|Dockerfile.*|.dockerignore|docker-compose*.yml|entrypoint.sh|render-config.json|README.md|LICENSE|THIRD_PARTY_NOTICES.md)
docker_required=true
;;
tui/*)
tui_required=true
;;
docs/*|.agent/*|.github/ISSUE_TEMPLATE/*|AGENTS.md|CLAUDE.md|COMMUNICATION.md|CONTRIBUTING.md|README.md|SECURITY.md|webui/README.md|render.yaml)
# Documentation-only changes are already filtered at the event level.
;;
*)
# Keep new or unclassified paths covered until they are categorized.
python_required=true
webui_required=true
tui_required=true
docker_required=true
;;
esac
done <<< "$changed_files"
fi
echo "python_required=$python_required" >> "$GITHUB_OUTPUT"
echo "webui_required=$webui_required" >> "$GITHUB_OUTPUT"
echo "tui_required=$tui_required" >> "$GITHUB_OUTPUT"
echo "docker_required=$docker_required" >> "$GITHUB_OUTPUT"
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
- 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'
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: Install pipx for offline installer checks
shell: bash
run: |
uv tool install pipx==1.17.12
uv tool dir --bin >> "$GITHUB_PATH"
# Installer subprocesses run here, parallel to the broad Windows suite.
# Each case owns an isolated manager/config root, so individual cases can
# run concurrently without sharing a console or package installation.
# Keep four workers: three exceed this job's budget on native Windows.
- 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-process
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' || needs.changes.outputs.python_required == 'true' || needs.changes.outputs.webui_required == 'true'
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
# Native build + clean install + recovery/next-update journeys on Windows.
# Each subprocess is separately bounded by the acceptance harness.
timeout-minutes: 60
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
- name: Build and install the native application package
shell: bash
env:
NATIVE_TARGET: ${{ runner.os == 'Windows' && 'win32-x64' || 'linux-x64' }}
run: |
python -m pip install --disable-pip-version-check build
python -m build --outdir "$RUNNER_TEMP/python-dist"
# Archive verification shares the installed launcher's dependencies.
# Install the intermediate in this build environment, not the separate
# clean-home environment used by the public-installer acceptance probe.
python -m pip install --disable-pip-version-check "$(find "$RUNNER_TEMP/python-dist" -name '*.whl' -print -quit)"
python -m scripts.build_tui_wheels \
--wheel "$(find "$RUNNER_TEMP/python-dist" -name '*.whl' -print -quit)" \
--tui-dir tui/dist --target "$NATIVE_TARGET" --out-dir "$RUNNER_TEMP/native-wheel"
version="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')"
python -I scripts/verify_installed_release.py \
--install-wheel "$(find "$RUNNER_TEMP/native-wheel" -name '*.whl' -print -quit)" \
--version "$version" --commit "$(git rev-parse HEAD)" --gateway \
--report "$RUNNER_TEMP/native-install-report.json"
- name: Exercise updates with the default Windows path policy
if: runner.os == 'Windows'
shell: pwsh
run: |
# Only this disposable runner changes. Do not require users to enable
# machine-wide long paths for an ordinary update's atomic temp files.
$key = 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem'
Set-ItemProperty -Path $key -Name LongPathsEnabled -Value 0
if ((Get-ItemPropertyValue -Path $key -Name LongPathsEnabled) -ne 0) {
throw 'Native update acceptance requires LongPathsEnabled=0'
}
Write-Output 'Packaged update/recovery acceptance: LongPathsEnabled=0'
- name: Verify packaged upgrades and automatic service recovery
shell: bash
run: |
python -I scripts/verify_packaged_update.py \
--wheel "$(find "$RUNNER_TEMP/native-wheel" -name '*.whl' -print -quit)" \
--commit "$(git rev-parse HEAD)" --output "$RUNNER_TEMP/packaged-update"
- name: Retain the native package acceptance report
if: always()
uses: actions/upload-artifact@v4
with:
name: native-install-${{ runner.os }}-${{ github.run_id }}-${{ github.run_attempt }}
path: |
${{ runner.temp }}/native-install-report.json
${{ runner.temp }}/packaged-update/packaged-update-report.json
${{ runner.temp }}/packaged-update/*/result.json
if-no-files-found: error
retention-days: 3
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"'