Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
ci: scope native acceptance and bind release candidate artifacts (#6378)
chengyongru67fc220c8ad7
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex ccf6b152a..b76e45851 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -4,30 +4,8 @@ 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.mdpull_request:branches: [main]- paths-ignore:- - docs/**- - .agent/**- - .github/ISSUE_TEMPLATE/**- - AGENTS.md- - CLAUDE.md- - COMMUNICATION.md- - CONTRIBUTING.md- - README.md- - SECURITY.md- - webui/README.mdconcurrency:group: ${{ github.workflow }}-${{ github.ref }}@@ -45,96 +23,23 @@ jobs: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@v4with:fetch-depth: 0- - name: Detect Python-relevant changes+ - name: Select checks by affected contractsid: pathsshell: bashenv: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"+ run: >-+ python scripts/ci_scope.py --event "$EVENT_NAME"+ --base "$BASE_SHA" --head "$HEAD_SHA"test:name: Python (${{ matrix.name }})@@ -213,7 +118,7 @@ jobs:# later uv run sync pruning the packages installed by the previous step.- name: Lint with ruffif: matrix.coverage- run: uv run --no-sync ruff check nanobot tests conftest.py scripts/check_import_boundaries.py scripts/pytest_timing.py+ 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@@ -234,7 +139,7 @@ jobs:# 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'+ 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@@ -325,16 +230,43 @@ jobs:--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 checksshell: bashrun: |uv tool install pipx==1.17.12uv 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.+ # Each case owns an isolated manager/config root. Keep the existing+ # four-worker budget, independent of process-identity compatibility checks.- name: Run Windows installer checksrun: >-uv run --no-sync python -m pytest tests/test_install_scripts.py@@ -345,7 +277,7 @@ jobs:if: always()uses: actions/upload-artifact@v4with:- name: python-timings-windows-process+ name: python-timings-windows-installerspath: test-results/retention-days: 7@@ -439,12 +371,10 @@ jobs:tui:needs: changes- if: needs.changes.outputs.tui_required == 'true' || needs.changes.outputs.python_required == 'true' || needs.changes.outputs.webui_required == 'true'+ if: needs.changes.outputs.tui_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+ timeout-minutes: 10strategy:fail-fast: falsematrix:@@ -521,57 +451,11 @@ jobs:bun scripts/release-notices.ts win32-x64python 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+ native:+ name: Native package acceptance+ needs: changes+ if: github.event_name != 'push' && needs.changes.outputs.native_required == 'true'+ uses: ./.github/workflows/native-acceptance.ymldocker:needs: changes@@ -634,3 +518,19 @@ jobs: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.pydiff --git a/.github/workflows/native-acceptance.yml b/.github/workflows/native-acceptance.ymlnew file mode 100644index 000000000..d377d7b7d--- /dev/null+++ b/.github/workflows/native-acceptance.yml@@ -0,0 +1,135 @@+name: Native package acceptance++on:+ workflow_call:+ inputs:+ candidate:+ description: Download exact candidate wheels instead of building PR test packages+ type: boolean+ default: false+ candidate_commit:+ type: string+ default: ''+ manifest_sha256:+ type: string+ default: ''+ linux_artifact_id:+ type: string+ default: ''+ windows_artifact_id:+ type: string+ default: ''++permissions:+ contents: read++jobs:+ native:+ name: Native acceptance (${{ matrix.target }})+ runs-on: ${{ matrix.os }}+ timeout-minutes: 60+ strategy:+ fail-fast: false+ matrix:+ include:+ - os: ubuntu-latest+ target: linux-x64+ wheel_tag: manylinux_2_17_x86_64+ - os: windows-latest+ target: win32-x64+ wheel_tag: win_amd64+ defaults:+ run:+ shell: bash+ steps:+ - uses: actions/checkout@v4+ with:+ persist-credentials: false++ - uses: actions/setup-python@v5+ with:+ python-version: '3.11'++ - uses: oven-sh/setup-bun@v2+ if: ${{ !inputs.candidate }}+ with:+ bun-version: 1.3.13+ bun-download-url: ${{ runner.os == 'Windows' && 'https://github.com/oven-sh/bun/releases/download/bun-v1.3.13/bun-windows-x64-baseline.zip' || '' }}++ - name: Build native test bundle+ if: ${{ !inputs.candidate }}+ working-directory: tui+ run: |+ bun install --frozen-lockfile+ bun run build+ bun scripts/release-notices.ts "${{ matrix.target }}"+ python scripts/package-release.py "${{ matrix.target }}"++ - name: Build native test wheel+ if: ${{ !inputs.candidate }}+ run: |+ python -m pip install --disable-pip-version-check build+ python -m build --outdir "$RUNNER_TEMP/python-dist"+ # The archive verifier imports the installed launcher's dependency stack.+ 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 "${{ matrix.target }}" --out-dir "$RUNNER_TEMP/native-wheel"++ - name: Download exact candidate wheel and manifest+ if: inputs.candidate+ uses: actions/download-artifact@v4+ with:+ # Producer IDs survive a failed-jobs-only retry without rebuilding bytes.+ artifact-ids: ${{ matrix.target == 'linux-x64' && inputs.linux_artifact_id || inputs.windows_artifact_id }}+ merge-multiple: true+ path: ${{ runner.temp }}/native-wheel++ - name: Verify acceptance input identity+ env:+ CANDIDATE: ${{ inputs.candidate }}+ EXPECTED_COMMIT: ${{ inputs.candidate_commit }}+ EXPECTED_MANIFEST: ${{ inputs.manifest_sha256 }}+ WHEEL_TAG: ${{ matrix.wheel_tag }}+ run: python scripts/native_acceptance_input.py++ - name: Install acceptance controller dependencies+ run: python -m pip install --disable-pip-version-check "$ACCEPTANCE_WHEEL"++ - name: Exercise default Windows path policy+ if: runner.os == 'Windows'+ shell: pwsh+ run: |+ $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'+ }++ - name: Verify clean public installation and startup+ run: |+ python -I scripts/verify_installed_release.py \+ --install-wheel "$ACCEPTANCE_WHEEL" --version "$ACCEPTANCE_VERSION" \+ --commit "$ACCEPTANCE_COMMIT" --gateway \+ --report "$RUNNER_TEMP/native-install-report.json"++ - name: Verify packaged upgrades and automatic service recovery+ run: |+ python -I scripts/verify_packaged_update.py \+ --wheel "$ACCEPTANCE_WHEEL" --commit "$ACCEPTANCE_COMMIT" \+ --output "$RUNNER_TEMP/packaged-update"++ # Raw acceptance logs contain disposable credentials. Export only structured evidence.+ - name: Retain native acceptance evidence+ if: always()+ uses: actions/upload-artifact@v4+ with:+ name: native-acceptance-${{ matrix.target }}-${{ github.run_id }}-${{ github.run_attempt }}+ path: |+ ${{ runner.temp }}/native-input.json+ ${{ runner.temp }}/native-install-report.json+ ${{ runner.temp }}/packaged-update/packaged-update-report.json+ ${{ runner.temp }}/packaged-update/packaged-update-timings.json+ ${{ runner.temp }}/packaged-update/*/result.json+ if-no-files-found: error+ retention-days: 3diff --git a/.github/workflows/release-candidate.yml b/.github/workflows/release-candidate.ymlindex 4884b97bb..a9b3d6d75 100644--- a/.github/workflows/release-candidate.yml+++ b/.github/workflows/release-candidate.yml@@ -25,6 +25,12 @@ jobs:candidate:runs-on: ubuntu-latesttimeout-minutes: 45+ outputs:+ candidate_commit: ${{ steps.identity.outputs.candidate_commit }}+ manifest_sha256: ${{ steps.identity.outputs.manifest_sha256 }}+ linux_artifact_id: ${{ steps.linux_input.outputs.artifact-id }}+ windows_artifact_id: ${{ steps.windows_input.outputs.artifact-id }}+ prepared_artifact_id: ${{ steps.prepared.outputs.artifact-id }}env:SOURCE_COMMIT: ${{ github.sha }}NEXT_STABLE: ${{ inputs.next_stable }}@@ -122,20 +128,45 @@ jobs:python -m twine check "$RUNNER_TEMP/release-artifacts/"*.whl \"$RUNNER_TEMP/release-artifacts/"*.tar.gz- - name: Install and probe the Linux wheel without frontend build tools- working-directory: ${{ env.CANDIDATE_DIR }}+ - name: Record exact acceptance identity+ id: identity+ env:+ MANIFEST: ${{ runner.temp }}/release-artifacts/release-manifest.jsonrun: |- version="${NEXT_STABLE}.dev${PREVIEW_SEQUENCE}"- uv_bin="$(command -v uv)"- uv venv --python 3.11 "$RUNNER_TEMP/installed-candidate"- mkdir "$RUNNER_TEMP/empty-install-path"- env PATH="$RUNNER_TEMP/empty-install-path" "$uv_bin" pip install \- --python "$RUNNER_TEMP/installed-candidate/bin/python" --only-binary :all: \- "$RUNNER_TEMP/release-artifacts/nanobot_ai-${version}-py3-none-manylinux_2_17_x86_64.whl"- uv pip check --python "$RUNNER_TEMP/installed-candidate/bin/python"- "$RUNNER_TEMP/installed-candidate/bin/python" -I scripts/verify_installed_release.py \- --version "$version" --commit "$(git rev-parse HEAD)" --gateway \- --report "$RUNNER_TEMP/installed-candidate-report.json"+ python - <<'PY'+ import hashlib, json, os+ from pathlib import Path+ payload = Path(os.environ['MANIFEST']).read_bytes()+ manifest = json.loads(payload)+ with open(os.environ['GITHUB_OUTPUT'], 'a') as output:+ output.write(f"candidate_commit={manifest['candidate_commit']}\n")+ output.write(f"manifest_sha256={hashlib.sha256(payload).hexdigest()}\n")+ PY++ # Temporary same-run inputs, not approved release handoffs. Do not rebuild on consumers.+ - name: Transfer exact Linux acceptance input+ id: linux_input+ uses: actions/upload-artifact@v4+ with:+ name: candidate-native-linux-x64-${{ github.run_number }}-${{ github.run_attempt }}+ path: |+ ${{ runner.temp }}/release-artifacts/*-manylinux_2_17_x86_64.whl+ ${{ runner.temp }}/release-artifacts/release-manifest.json+ if-no-files-found: error+ retention-days: 1+ compression-level: 0++ - name: Transfer exact Windows acceptance input+ id: windows_input+ uses: actions/upload-artifact@v4+ with:+ name: candidate-native-win32-x64-${{ github.run_number }}-${{ github.run_attempt }}+ path: |+ ${{ runner.temp }}/release-artifacts/*-win_amd64.whl+ ${{ runner.temp }}/release-artifacts/release-manifest.json+ if-no-files-found: error+ retention-days: 1+ compression-level: 0- name: Generate the exact candidate installation handoffworking-directory: ${{ env.CANDIDATE_DIR }}@@ -144,25 +175,14 @@ jobs:--artifacts "$RUNNER_TEMP/release-artifacts" \--output "$RUNNER_TEMP/install-candidate.md"- - name: Verify packaged Linux upgrades and service recovery- working-directory: ${{ env.CANDIDATE_DIR }}- run: |- version="${NEXT_STABLE}.dev${PREVIEW_SEQUENCE}"- python -I scripts/verify_packaged_update.py \- --wheel "$RUNNER_TEMP/release-artifacts/nanobot_ai-${version}-py3-none-manylinux_2_17_x86_64.whl" \- --commit "$(git rev-parse HEAD)" --output "$RUNNER_TEMP/packaged-update"-- # Keep the default preflight cheap: no ~400 MB archive upload per manual run.- # These reports are not installable releases or publication approvals.- - name: Retain identity, structural and native Linux probe reports+ # These reports are neither native acceptance nor publication approval.+ - name: Retain candidate identity and structural reportsuses: actions/upload-artifact@v4with:name: candidate-report-${{ github.run_number }}-${{ github.run_attempt }}path: |${{ runner.temp }}/candidate.json${{ runner.temp }}/release-artifacts/release-manifest.json- ${{ runner.temp }}/installed-candidate-report.json- ${{ runner.temp }}/packaged-update/packaged-update-report.json${{ runner.temp }}/install-candidate.mdif-no-files-found: errorretention-days: 3@@ -177,12 +197,63 @@ jobs:--artifacts "$RUNNER_TEMP/release-artifacts" \--output "$RUNNER_TEMP/retained-candidate"- - name: Retain installable candidate for approved release handoff+ - name: Transfer prepared candidate pending native acceptance+ id: preparedif: ${{ inputs.retain_installable }}uses: actions/upload-artifact@v4+ with:+ name: prepared-candidate-${{ github.run_number }}-${{ github.run_attempt }}+ path: ${{ runner.temp }}/retained-candidate+ if-no-files-found: error+ compression-level: 0+ retention-days: 1++ native:+ name: Candidate native acceptance+ needs: candidate+ uses: ./.github/workflows/native-acceptance.yml+ with:+ candidate: true+ candidate_commit: ${{ needs.candidate.outputs.candidate_commit }}+ manifest_sha256: ${{ needs.candidate.outputs.manifest_sha256 }}+ linux_artifact_id: ${{ needs.candidate.outputs.linux_artifact_id }}+ windows_artifact_id: ${{ needs.candidate.outputs.windows_artifact_id }}++ verified:+ name: Candidate required+ needs: [candidate, native]+ if: always()+ runs-on: ubuntu-latest+ timeout-minutes: 10+ steps:+ - name: Require build and both native acceptance jobs+ env:+ BUILD_RESULT: ${{ needs.candidate.result }}+ NATIVE_RESULT: ${{ needs.native.result }}+ run: test "$BUILD_RESULT" = success && test "$NATIVE_RESULT" = success++ - name: Restore the exact retained candidate after acceptance+ if: inputs.retain_installable+ uses: actions/download-artifact@v4+ with:+ artifact-ids: ${{ needs.candidate.outputs.prepared_artifact_id }}+ merge-multiple: true+ path: ${{ runner.temp }}/retained-candidate++ - name: Retain accepted installable candidate for separate approval+ if: inputs.retain_installable+ uses: actions/upload-artifact@v4with:name: installable-candidate-${{ github.run_number }}-${{ github.run_attempt }}path: ${{ runner.temp }}/retained-candidateif-no-files-found: errorcompression-level: 0retention-days: 1++ - name: Record accepted identity+ env:+ CANDIDATE_COMMIT: ${{ needs.candidate.outputs.candidate_commit }}+ MANIFEST_SHA256: ${{ needs.candidate.outputs.manifest_sha256 }}+ run: |+ printf 'Candidate: `%s`\n\nManifest SHA-256: `%s`\n\nLinux and Windows native acceptance passed. Publication requires separate approval.\n' \+ "$CANDIDATE_COMMIT" "$MANIFEST_SHA256" >> "$GITHUB_STEP_SUMMARY"diff --git a/docs/ci.md b/docs/ci.mdnew file mode 100644index 000000000..90d372bba--- /dev/null+++ b/docs/ci.md@@ -0,0 +1,27 @@+# CI execution boundaries++Code validation and release acceptance have different owners. `Test Suite` validates PRs and the merged `main` tree. `Verify Release Candidate` builds an explicit candidate and validates its exact installable bytes. Neither workflow publishes releases, signs manifests or advances `release-index`; that branch is a release catalogue, not a product source branch.++## Code validation++`scripts/ci_scope.py` owns the ordered path rules and explains each decision in the run summary. PR selection uses the merge-base diff; pushes use the complete before/after range, including all commits in the push. Renames consider both old and new paths. Missing revisions, failed or empty diffs, unknown paths and manual dispatch select the full validation set. Ordinary documentation changes still produce the stable `CI required` result without scheduling product jobs.++Python retains its Linux minimum/latest and Windows compatibility matrix. WebUI changes retain lint, types, unit coverage, build, browser regression and Docker checks. TUI functionality retains both platforms' checks, tests, terminal smoke, build and archive verification. Shared backend client contracts select the consuming clients as well. Docker continues checking installed assets, startup, dependencies and container privilege boundaries; frontend changes are not assumed irrelevant to the image.++Native packaging, installation and update lifecycle changes additionally select Linux and Windows native acceptance on PRs. Windows isolated update jobs and installer checks use the same high-risk selection. The installer matrix has its own bounded job, separate from process-identity checks; an 18-minute installer run must not consume the process job's timeout or hide its result. Pushes to `main` run the selected code checks but do not repeat those specialized installer/update journeys or full native acceptance. A manual `Test Suite` dispatch requests all checks. Scope changes must keep new shared contracts and lifecycle dependencies classified; directory names alone do not establish the dependency graph.++`CI required` checks the selected job results, including matrix and reusable-workflow results. Failure, cancellation, an unexpected skip or a missing selector output fails the gate. Only an intentional unselected skip is accepted. Administrators should require this stable check in branch protection/rulesets; defining the job does not enable repository protection or remove any existing required check.++## Candidate acceptance++The candidate producer builds five platform bundles and records the candidate commit and manifest SHA-256. It transfers only the Linux x64 and Windows x64 wheels and the manifest to parallel native consumers. Consumers download by immutable producer artifact IDs, including when only failed jobs are retried, and verify the build-output manifest hash, candidate commit, wheel size/hash and embedded commit before installing or executing the wheel. They never rebuild candidate packages. The same reusable native acceptance workflow also builds private test packages for high-risk PRs.++Each native consumer runs the clean public installer, installed startup/assets probes, and all nine packaged upgrade/recovery scenarios, including subsequent successful updates after restoration. Windows acceptance retains the default short-path policy. Scenarios remain serial within their private environment: sharing that installation across parallel scenarios would invalidate the test. These controlled version/fault fixtures do not replace real supported historical baselines, public-download acceptance, other native platforms, or interactive UI acceptance; see [the release checklist](releasing.md).++`Candidate required` requires both the producer and the complete native matrix. Only after success may an explicitly requested prepared source/installation handoff be promoted to `installable-candidate`. Temporary same-run wheel transfers expire after one day, even when no installable handoff was requested. Reports are retained for three days; an explicitly requested installable handoff expires after one day. Preserve accepted bytes and evidence before expiry. The final gate is not publication approval: the existing separate approval, public artifact verification and serialized catalogue advancement remain mandatory.++## Timing and evidence++Packaged acceptance writes `packaged-update-timings.json` incrementally, including failed phases and completed scenarios. It measures environment setup, initial dependencies, fixture generation, baseline installation, each preparation/worker/verification journey, cleanup and scenario totals. Scenario totals overlap their phases and must not be added to them. Completed checkpoints are diagnostic evidence, not an overall pass.++Upload only the explicit structured reports. Private acceptance logs, configuration, sessions, backups and live test environments can contain credentials and are not upload sets. Do not remove hash checks or durable production writes merely to reduce CI time. Compare wall time and raw runner-minutes separately, with the same scenario coverage and exact source/produced package identity; moving work out of daily CI does not prove that the specialized acceptance itself became faster.diff --git a/docs/releasing.md b/docs/releasing.mdindex 875c00eda..04813ca25 100644--- a/docs/releasing.md+++ b/docs/releasing.md@@ -24,8 +24,8 @@ Packaging is maintainer-triggered, not scheduled or push-triggered. Record the r### Maintainer-triggered Preview procedure1. Select an exact reviewed `main` commit with passing required CI; skip it if its source SHA matches the last accepted candidate. Record the next unreleased stable base and an unused increasing Preview sequence.-2. Run **Verify Release Candidate** for that ref and base. It prepares a version-only candidate, builds the WebUI and five native TUI bundles, and verifies the package set without publication. Users receive built packages, not a checkout requiring Bun.-3. Select `retain_installable` and preserve the handoff before expiry. Complete native and packaged old-to-new update/recovery acceptance against those exact bytes. Keep candidate SHA, manifest hash, coverage, known issues and source-offer approval together; CI reports alone are neither installable artifacts nor publication consent.+2. Run **Verify Release Candidate** for that ref and base. It prepares a version-only candidate, builds the WebUI and five native TUI bundles once, and runs Linux x64 and Windows x64 clean-install and packaged update/recovery acceptance against the exact manifest-bound wheels without publication. Require the **Candidate required** check to pass; build-only reports are insufficient. Users receive built packages, not a checkout requiring Bun.+3. Select `retain_installable` and preserve the accepted `installable-candidate` handoff before expiry. Temporary `candidate-native` inputs and `prepared-candidate` artifacts are not accepted handoffs. Complete the remaining native-platform and real historical-baseline acceptance against those exact bytes; the automated fault-injection fixtures do not establish compatibility with a previously published version. Keep candidate SHA, manifest hash, coverage, known issues and source-offer approval together; CI reports alone are neither installable artifacts nor publication consent.4. With separate approval, publish immutable `v<version>` at the **candidate** commit and a GitHub prerelease, never the latest stable release. Upload the complete verified set, manifest and notes; make the pinned installer source publicly reachable.5. Verify all public sizes/hashes and clean public install/update acceptance before advancing `preview` with a new catalogue generation. Validate against the latest catalogue, preserve `stable` and withdrawals, and serialize stable, Preview and withdrawal writes. A stale publisher must reread and revalidate.6. After partial upload, leave the feed unchanged and resume only from the original verified files. Lost or changed bytes require a new version and repeated acceptance. Withdraw unsafe candidates with a reason and offer a newer fix; never rewind the feed or restore user data.diff --git a/scripts/ci_gate.py b/scripts/ci_gate.pynew file mode 100644index 000000000..ac1700650--- /dev/null+++ b/scripts/ci_gate.py@@ -0,0 +1,41 @@+"""Require success for selected jobs; never confuse a broken selector with no work."""++from __future__ import annotations++import json+import os+++def check_results(needs: dict, event: str) -> list[str]:+ changes = needs["changes"]+ if changes["result"] != "success":+ return ["Change selection did not succeed"]+ outputs = changes["outputs"]+ selected = {}+ for domain in ("python", "webui", "tui", "docker", "native"):+ value = outputs.get(f"{domain}_required")+ if value not in ("true", "false"):+ return [f"Invalid or missing selection: {domain}"]+ selected[domain] = value == "true"+ jobs = {"test": selected["python"], "windows_process": selected["python"],+ "webui_checks": selected["webui"], "webui_browser": selected["webui"],+ "webui": selected["webui"], "tui": selected["tui"], "docker": selected["docker"],+ "native": selected["native"] and event != "push",+ "windows_installers": selected["python"] and selected["native"] and event != "push"}+ errors = []+ for job, required in jobs.items():+ result = needs[job]["result"]+ if result != "success" and (required or result != "skipped"):+ errors.append(f"{job}: {'required' if required else 'unselected'}, got {result}")+ return errors+++def main() -> None:+ errors = check_results(json.loads(os.environ["CHECK_RESULTS"]), os.environ["EVENT_NAME"])+ if errors:+ raise SystemExit("\n".join(errors))+ print("All selected checks passed; other checks were intentionally skipped.")+++if __name__ == "__main__":+ main()diff --git a/scripts/ci_scope.py b/scripts/ci_scope.pynew file mode 100644index 000000000..8bf5f0243--- /dev/null+++ b/scripts/ci_scope.py@@ -0,0 +1,168 @@+#!/usr/bin/env python3+"""Conservative, stdlib-only CI path selection; importable without running git.++Rules describe validation needs, not event policy: the workflow may restrict native+acceptance to PRs, but dispatch and fallback still request every validation lane.+"""++from __future__ import annotations++import argparse+import html+import json+import os+import re+import subprocess+from fnmatch import fnmatchcase+from pathlib import Path++JOBS = ("python_required", "webui_required", "tui_required", "docker_required", "native_required")+ALL = frozenset(JOBS)+PYTHON = frozenset({"python_required"})+DOCKER = frozenset({"docker_required"})+WEBUI = frozenset({"webui_required"})+TUI = frozenset({"tui_required"})+NATIVE = frozenset({"native_required"})++# Ordered first-match rules. Keep Docker README inputs before documentation rules,+# and embedded channel frontend trees before the Python production catch-all.+RULES = (+ ((".github/workflows/ci.yml", ".github/workflows/native-acceptance.yml",+ "scripts/ci_scope.py", "tests/scripts/test_ci_scope.py",+ "scripts/native_acceptance_input.py", "tests/scripts/test_native_acceptance_input.py",+ "scripts/ci_gate.py", "tests/scripts/test_ci_gate.py", "tests/scripts/test_ci_workflows.py"),+ ALL, "CI selector or execution contract"),+ ((".github/workflows/release-candidate.yml", ".github/workflows/release-approve.yml"),+ PYTHON | NATIVE, "release workflow (including Python parse/collection validation)"),+ ((".github/workflows/tui-release.yml",), PYTHON | TUI | NATIVE, "native TUI publication workflow"),+ ((".github/workflows/*",), ALL, "unknown workflow"),+ (("pyproject.toml", "uv.lock", "hatch_build.py", "nanobot/webui/build.py", "scripts/install*",+ "scripts/build*"), ALL, "cross-domain dependency, build or installation contract"),+ (("tests/test_docker*.py",), PYTHON | DOCKER, "Docker Python regression tests"),+ (("Dockerfile", "Dockerfile.*", ".dockerignore", "docker-compose*.yml", "entrypoint.sh",+ "render-config.json", "README.md", "LICENSE", "THIRD_PARTY_NOTICES.md",+ "tests/test_docker*", "scripts/docker_compose_smoke.py"), DOCKER, "Docker input or acceptance"),+ (("docs/*", ".agent/*", ".github/ISSUE_TEMPLATE/*", "AGENTS.md", "CLAUDE.md",+ "COMMUNICATION.md", "CONTRIBUTING.md", "SECURITY.md", "webui/README.md",+ "tui/README.md", "render.yaml", "images/*"), frozenset(), "documentation only"),+ (("scripts/check_client_import_boundaries.*",), WEBUI | TUI, "shared client import boundary checker"),+ (("packages/client-events/*",), WEBUI | TUI | DOCKER, "shared client event protocol"),+ (("webui/*", "nanobot/channels/*/webui/*", "nanobot/channels/*/tests/webui/*"),+ WEBUI | DOCKER, "WebUI source or embedded channel frontend"),+ (("tui/scripts/package-release.py", "tui/scripts/release-notices.ts", "tui/scripts/prepare-target.ts",+ "tui/scripts/build.ts", "tui/package.json", "tui/bun.lock"), TUI | NATIVE, "native TUI packaging or dependencies"),+ (("tui/*",), TUI, "TUI functionality"),+ (("nanobot/channels/websocket/runtime.py", "nanobot/webui/gateway_endpoint.py"),+ PYTHON | DOCKER | WEBUI | TUI | NATIVE, "shared gateway lifecycle and client protocol"),+ # These modules own wire events, transport and session representations used+ # by both clients. Other backend WebUI modules need only the WebUI consumer.+ (("nanobot/webui/client_contract.py", "nanobot/webui/outbound_*.py",+ "nanobot/webui/inbound_commands.py", "nanobot/webui/ws_http.py",+ "nanobot/webui/gateway_*.py", "nanobot/webui/session_*.py",+ "nanobot/webui/history.py", "nanobot/webui/transcript.py",+ "nanobot/webui/sidebar_state.py", "nanobot/webui/settings_*.py",+ "nanobot/webui/workspaces.py", "nanobot/webui/skills_api.py",+ "nanobot/webui/cli_apps_api.py", "nanobot/webui/mcp_presets_api.py",+ "nanobot/webui/recovery.py", "nanobot/webui/forking.py", "nanobot/session/*", "nanobot/events.py",+ "nanobot/bus/events.py", "nanobot/api/*", "nanobot/channels/websocket/*.py"),+ PYTHON | DOCKER | WEBUI | TUI, "shared backend client protocol, transport or session representation"),+ (("nanobot/webui/local_client_assets.py",), PYTHON | DOCKER | WEBUI | NATIVE,+ "installed client asset discovery"),+ (("nanobot/webui/*",), PYTHON | DOCKER | WEBUI, "WebUI backend"),+ (("nanobot/update*", "nanobot/release*", "nanobot/installation*", "nanobot/bun.py",+ "nanobot/build_info.py", "nanobot/__init__.py", "nanobot/__main__.py",+ "nanobot/nanobot.py", "nanobot/process_runtime.py", "nanobot/runtime_admission.py", "nanobot/data_access.py",+ "nanobot/gateway/*", "nanobot/cli/entry.py", "nanobot/cli/commands.py",+ "nanobot/cli/gateway*.py", "nanobot/cli/update.py", "nanobot/cli/process_identity.py",+ "nanobot/cli/desktop*.py", "nanobot/cli/tui_launcher.py", "nanobot/cli/dock.py",+ "nanobot/cli/_macos_dock.py", "nanobot/cli/runtime_config.py", "nanobot/cli/webui.py", "nanobot/cli/webui_support.py",+ "nanobot/config/paths.py", "nanobot/utils/rotating_output.py",+ "nanobot/utils/atomic_file.py", "nanobot/utils/file_io.py", "nanobot/utils/runtime.py",+ "nanobot/utils/restart.py", "nanobot/skills/update-setup/*"),+ PYTHON | DOCKER | NATIVE, "installed application lifecycle, update or runtime"),+ (("nanobot/*",), PYTHON | DOCKER, "Python production source"),+ (("tests/test_update*", "tests/test_windows_update*", "tests/test_release*",+ "tests/test_install*", "tests/test_packaged_update*", "tests/test_bun.py",+ "tests/test_build_info.py", "tests/gateway/*", "tests/cli/test_entry.py",+ "tests/cli/test_commands.py", "tests/cli/test_gateway*", "tests/cli/test_process_identity.py",+ "tests/cli/test_desktop*", "tests/cli/test_tui*", "tests/cli/test_restart*",+ "tests/utils/test_atomic*", "tests/utils/test_file_io*", "tests/test_process*",+ "tests/test_runtime*", "scripts/verify_*", "scripts/release_*",+ ".github/release-signing-requirements.*"), PYTHON | NATIVE, "lifecycle or installed-release verification"),+ (("tests/*.py", "conftest.py", "scripts/*.py"), PYTHON, "Python tests or tooling"),+)+++def classify_paths(paths: list[str]) -> dict:+ """Select the union of requirements, preserving a reason for every path."""+ required = set()+ decisions = []+ for path in paths:+ for patterns, jobs, reason in RULES:+ if any(fnmatchcase(path, pattern) for pattern in patterns):+ break+ else:+ jobs, reason = ALL, "unknown path; conservative full validation"+ required.update(jobs)+ decisions.append({"path": path, "reason": reason, "jobs": sorted(jobs)})+ if not paths:+ required.update(ALL)+ return {+ "outputs": {job: job in required for job in JOBS},+ "reason": "classified changed paths" if paths else "empty diff; conservative full validation",+ "paths": decisions,+ }+++def select_scope(event: str, base: str, head: str, *, cwd: Path | None = None) -> dict:+ """Use merge-base diff for PRs, endpoint diff for pushes, full for dispatch."""+ if event == "workflow_dispatch":+ result = classify_paths([])+ result["reason"] = "manual dispatch; full validation"+ return result+ if event not in {"pull_request", "push"}:+ raise ValueError(f"unsupported event: {event}")+ # Accept only commit IDs, never option-like revision expressions from env.+ if not all(re.fullmatch(r"[0-9a-fA-F]{40}|[0-9a-fA-F]{64}", sha) for sha in (base, head)):+ result = classify_paths([])+ result["reason"] = "invalid or missing commit SHA; conservative full validation"+ return result+ diff_range = f"{base}{'...' if event == 'pull_request' else '..'}{head}"+ try:+ diff = subprocess.run(+ ["git", "diff", "--name-only", "--no-renames", "-z", diff_range, "--"],+ cwd=cwd, check=True, capture_output=True, timeout=60,+ )+ except (OSError, subprocess.SubprocessError) as exc:+ result = classify_paths([])+ result["reason"] = f"git diff unavailable ({type(exc).__name__}); conservative full validation"+ return result+ paths = diff.stdout.decode("utf-8", errors="surrogateescape").split("\0")+ result = classify_paths([path for path in paths if path])+ result["diff_range"] = diff_range+ return result+++def main() -> int:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--event", required=True, choices=("pull_request", "push", "workflow_dispatch"))+ parser.add_argument("--base", default="")+ parser.add_argument("--head", default="")+ args = parser.parse_args()+ result = select_scope(args.event, args.base, args.head)+ report = json.dumps(result, indent=2, ensure_ascii=True)+ print(report)+ if output := os.environ.get("GITHUB_OUTPUT"):+ with open(output, "a", encoding="utf-8") as stream:+ for job, required in result["outputs"].items():+ stream.write(f"{job}={str(required).lower()}\n")+ if summary := os.environ.get("GITHUB_STEP_SUMMARY"):+ with open(summary, "a", encoding="utf-8") as stream:+ # JSON escapes path newlines; HTML escaping also prevents Markdown or+ # raw HTML in filenames from escaping the summary's preformatted block.+ stream.write("## CI scope\n\n<pre>" + html.escape(report) + "</pre>\n")+ return 0+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/scripts/native_acceptance_input.py b/scripts/native_acceptance_input.pynew file mode 100644index 000000000..b6800a0c0--- /dev/null+++ b/scripts/native_acceptance_input.py@@ -0,0 +1,70 @@+"""Bind native acceptance to the exact wheel produced by this workflow run."""++from __future__ import annotations++import hashlib+import json+import os+import re+import subprocess+import tomllib+from pathlib import Path+from zipfile import ZipFile+++def acceptance_input(directory: Path, *, tag: str, commit: str,+ manifest_sha256: str = "", version: str = "") -> dict[str, str]:+ if not re.fullmatch(r"[0-9a-f]{40}", commit):+ raise ValueError("Acceptance requires an exact candidate commit")+ if manifest_sha256:+ manifest_bytes = (directory / "release-manifest.json").read_bytes()+ if hashlib.sha256(manifest_bytes).hexdigest() != manifest_sha256:+ raise ValueError("Candidate manifest differs from the build output")+ manifest = json.loads(manifest_bytes)+ if manifest["candidate_commit"] != commit:+ raise ValueError("Candidate commit differs from the build output")+ version = manifest["version"]+ if not re.fullmatch(r"[0-9][A-Za-z0-9.]*", version):+ raise ValueError("Invalid acceptance version")+ filename = f"nanobot_ai-{version}-py3-none-{tag}.whl"+ wheel = directory / filename+ if wheel.is_symlink() or not wheel.is_file():+ raise ValueError("Acceptance requires the exact native wheel")+ with wheel.open("rb") as stream:+ sha256 = hashlib.file_digest(stream, "sha256").hexdigest()+ if manifest_sha256:+ records = [item for item in manifest["artifacts"] if item["filename"] == filename]+ if len(records) != 1 or (records[0]["sha256"], records[0]["size"]) != (sha256, wheel.stat().st_size):+ raise ValueError("Candidate wheel differs from its manifest")+ with ZipFile(wheel) as archive:+ if archive.read("nanobot/_build_commit.txt").decode().strip() != commit:+ raise ValueError("Wheel build commit differs from the acceptance target")+ return {"wheel": str(wheel.resolve()), "version": version, "commit": commit,+ "wheel_sha256": sha256, "manifest_sha256": manifest_sha256}+++def main() -> None:+ root = Path(os.environ["RUNNER_TEMP"])+ candidate = os.environ["CANDIDATE"] == "true"+ if candidate:+ commit = os.environ["EXPECTED_COMMIT"]+ manifest_sha256 = os.environ["EXPECTED_MANIFEST"]+ if not re.fullmatch(r"[0-9a-f]{64}", manifest_sha256):+ raise ValueError("Candidate acceptance requires the build's manifest hash")+ version = ""+ else:+ commit = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip()+ manifest_sha256 = ""+ version = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["project"]["version"]+ record = acceptance_input(root / "native-wheel", tag=os.environ["WHEEL_TAG"], commit=commit,+ manifest_sha256=manifest_sha256, version=version)+ (root / "native-input.json").write_text(json.dumps(record, indent=2) + "\n", encoding="utf-8")+ with Path(os.environ["GITHUB_ENV"]).open("a", encoding="utf-8") as stream:+ for key in ("wheel", "version", "commit"):+ if "\n" in record[key] or "\r" in record[key]:+ raise ValueError("Invalid acceptance environment value")+ stream.write(f"ACCEPTANCE_{key.upper()}={record[key]}\n")+++if __name__ == "__main__":+ main()diff --git a/scripts/verify_packaged_update.py b/scripts/verify_packaged_update.pyindex f9e49837a..06035e33a 100644--- a/scripts/verify_packaged_update.py+++ b/scripts/verify_packaged_update.py@@ -26,7 +26,7 @@ import sqlite3import subprocessimport sysimport time-from contextlib import closing+from contextlib import closing, contextmanagerfrom pathlib import Pathfrom unittest.mock import patchfrom urllib.parse import quote@@ -49,6 +49,35 @@ def write(path: Path, value) -> None:path.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")+class Timings:+ """Separate, incrementally persisted evidence; never include commands or logs."""++ def __init__(self, output: Path):+ self.output = output+ self.records: list[dict] = []++ @contextmanager+ def measure(self, phase: str, *, scenario: str | None = None, journey: int | None = None):+ started = time.perf_counter()+ succeeded = False+ try:+ yield+ succeeded = True+ finally:+ record = {"phase": phase, "scenario": scenario, "journey": journey,+ "seconds": time.perf_counter() - started,+ "status": "succeeded" if succeeded else "failed"}+ self.records.append(record)+ # The controller owns this exclusive root before starting any timer.+ # Replace the checkpoint atomically so a later failed phase cannot+ # leave a partially written report. This is not a durability/fsync test.+ temporary = self.output.with_suffix(".tmp")+ write(temporary, {"schema_version": 1, "clock": "perf_counter", "timings": self.records})+ temporary.replace(self.output)+ label = "/".join(str(value) for value in (scenario, journey, phase) if value is not None)+ print(f"TIMING {label}: {record['seconds']:.3f}s ({record['status']})", flush=True)++def replace_once(source: bytes, old: bytes, new: bytes) -> bytes:if source.count(old) != 1:raise ValueError("The fault-injection seam changed; review the acceptance fixture")@@ -612,6 +641,7 @@ def run(args) -> dict:original_hash = digest(target)root = args.output.resolve()root.mkdir(mode=0o700) # Exclusive evidence root. Never use a user's installation.+ timings = Timings(root / "packaged-update-timings.json")environment = root / "managed"python = environment / ("Scripts/python.exe" if os.name == "nt" else "bin/python")base = Version(version).release@@ -635,103 +665,117 @@ def run(args) -> dict:system["PATH"] = str(Path(system["SYSTEMROOT"]) / "System32")# Install once, without inherited user pip settings; every case resets only# nanobot in this private environment. Dependencies stay pinned by its snapshot.- subprocess.run([sys.executable, "-I", "-m", "venv", str(environment)], check=True, env=system, timeout=90)- subprocess.run([str(python), "-I", "-m", "pip", "install", "--only-binary=:all:", str(target)],- check=True, env=system, timeout=600, stdout=subprocess.DEVNULL)+ with timings.measure("venv"):+ subprocess.run([sys.executable, "-I", "-m", "venv", str(environment)], check=True, env=system, timeout=90)+ with timings.measure("initial_dependency_install"):+ subprocess.run([str(python), "-I", "-m", "pip", "install", "--only-binary=:all:", str(target)],+ check=True, env=system, timeout=600, stdout=subprocess.DEVNULL)write(environment / "nanobot-install.json", {"schema_version": 1, "owner": "nanobot-installer","environment": str(environment), "extras": []})for scenario in args.scenario or SCENARIOS:- case_root = root / scenario- case_root.mkdir()- account = case_root / "account"- account.mkdir()- env = dict(system, HOME=str(account), USERPROFILE=str(account), APPDATA=str(account / "config"),- LOCALAPPDATA=str(account / "data"), XDG_CONFIG_HOME=str(account / "config"),- XDG_CACHE_HOME=str(root / "cache"), XDG_DATA_HOME=str(account / "data"),- TMPDIR=str(case_root), TMP=str(case_root), TEMP=str(case_root))- selected = target- feed = case_root / "feed.json"- if scenario in {"upgrade-again", "import-failure", "restart-failure", "restore-interruption"}:- intermediate = Version(version).base_version + ".dev0"- if not Version(baseline_version) < Version(intermediate) < Version(version):- raise ValueError("Consecutive updates require baseline < target.dev0 < target")- # Faults and the instrumented intermediate get a distinct version:- # never overwrite a previously observed version with healthy bytes.- selected = fixture_wheel(target, case_root / "intermediate", intermediate,- feed=feed if scenario == "upgrade-again" else None, scenario=scenario)- write(feed, feed_records(selected, args.commit))- earlier = baseline_version- if scenario == "skipped-preview" and not args.baseline_wheel:- earlier = Version(version).base_version + ".dev0"- if Version(earlier) >= Version(version):- raise ValueError("Skipped Preview requires a target newer than dev0")- baseline = fixture_wheel(baseline_source, case_root / "baseline", earlier, feed=feed, scenario=scenario)- case = {"scenario": scenario, "baseline_version": earlier, "dock": args.dock,- "target_version": str(parse_wheel_filename(selected.name)[1]),- "baseline_kind": "instrumented historical wheel" if args.baseline_wheel else "instrumented version fixture",- "baseline_source_sha256": digest(baseline_source), "baseline_fixture_sha256": digest(baseline),- "target_wheel": str(selected), "target_sha256": digest(selected), "commit": args.commit,- "target_unmodified": selected == target}- write(case_root / "case.json", case)- subprocess.run([str(python), "-I", "-m", "pip", "install", "--no-deps", "--force-reinstall", str(baseline)],- check=True, env=env, timeout=120, stdout=subprocess.DEVNULL)- child = [str(python), "-I", str(Path(__file__).resolve())]- with (case_root / "acceptance.log").open("w", encoding="utf-8") as log:- def journey():- subprocess.run([*child, "--phase", "prepare", "--output", str(case_root)],- check=True, env=env, cwd=case_root, stdout=log, stderr=log, timeout=180)- launch = read(case_root / "launch.json")- subprocess.run(launch["command"], check=True, env=env, cwd=launch["directory"],- stdout=log, stderr=log, timeout=420)- subprocess.run([*child, "--phase", "verify", "--output", str(case_root)],- check=True, env=env, cwd=case_root, stdout=log, stderr=log, timeout=180)- return read(case_root / "result.json")-- try:- result = journey()- if result["phase"] == "restored" or scenario == "upgrade-again":- previous_job = read(case_root / "launch.json")["directory"]- write(feed, feed_records(target, args.commit, generation=2))- write(case_root / "case.json", {- **case, "scenario": "upgrade", "baseline_version": result["running_version"],- "baseline_kind": "previous journey's running installation",- "baseline_source_sha256": (case["baseline_source_sha256"] if result["phase"] == "restored"- else case["target_sha256"]),- "baseline_fixture_sha256": (case["baseline_fixture_sha256"] if result["phase"] == "restored"- else case["target_sha256"]),- "target_version": version, "target_wheel": str(target),- "target_sha256": original_hash, "target_unmodified": True,- })- result["subsequent_update"] = journey()- assert read(case_root / "launch.json")["directory"] != previous_job- assert result["subsequent_update"]["phase"] == "succeeded"- write(case_root / "result.json", result)- results.append(result)- except (subprocess.CalledProcessError, subprocess.TimeoutExpired):- log.flush()- tail = (case_root / "acceptance.log").read_text(encoding="utf-8", errors="replace")[-8192:]- config_file = account / ".nanobot/config.json"- if config_file.exists():- token = read(config_file)["channels"]["websocket"]["tokenIssueSecret"]- tail = tail.replace(token, "[redacted]")- print(tail, file=sys.stderr)- raise- finally:- subprocess.run([str(python), "-I", "-m", "nanobot", "gateway", "stop", "--config",- str(account / ".nanobot/config.json")], env=env, cwd=case_root,- stdout=log, stderr=log, timeout=60, check=True)- config_file = account / ".nanobot/config.json"- if config_file.exists():- config = read(config_file)- _wait_for_closed_listeners((config["gateway"]["port"], config["channels"]["websocket"]["port"]))- results[-1]["gateway_process_stopped"] = True- dock_address = results[-1].get("dock_socket")- if not dock_address:- dock_address = results[-1].get("subsequent_update", {}).get("dock_socket")- if dock_address:- _wait_dock(Path(dock_address), present=False)- results[-1]["dock_stopped"] = True- print(f"PASS {scenario}: {results[-1]['phase']}", flush=True)+ with timings.measure("scenario_total", scenario=scenario):+ with timings.measure("fixture", scenario=scenario, journey=1):+ case_root = root / scenario+ case_root.mkdir()+ account = case_root / "account"+ account.mkdir()+ env = dict(system, HOME=str(account), USERPROFILE=str(account), APPDATA=str(account / "config"),+ LOCALAPPDATA=str(account / "data"), XDG_CONFIG_HOME=str(account / "config"),+ XDG_CACHE_HOME=str(root / "cache"), XDG_DATA_HOME=str(account / "data"),+ TMPDIR=str(case_root), TMP=str(case_root), TEMP=str(case_root))+ selected = target+ feed = case_root / "feed.json"+ if scenario in {"upgrade-again", "import-failure", "restart-failure", "restore-interruption"}:+ intermediate = Version(version).base_version + ".dev0"+ if not Version(baseline_version) < Version(intermediate) < Version(version):+ raise ValueError("Consecutive updates require baseline < target.dev0 < target")+ # Faults and the instrumented intermediate get a distinct version:+ # never overwrite a previously observed version with healthy bytes.+ selected = fixture_wheel(target, case_root / "intermediate", intermediate,+ feed=feed if scenario == "upgrade-again" else None, scenario=scenario)+ write(feed, feed_records(selected, args.commit))+ earlier = baseline_version+ if scenario == "skipped-preview" and not args.baseline_wheel:+ earlier = Version(version).base_version + ".dev0"+ if Version(earlier) >= Version(version):+ raise ValueError("Skipped Preview requires a target newer than dev0")+ baseline = fixture_wheel(baseline_source, case_root / "baseline", earlier, feed=feed, scenario=scenario)+ case = {"scenario": scenario, "baseline_version": earlier, "dock": args.dock,+ "target_version": str(parse_wheel_filename(selected.name)[1]),+ "baseline_kind": "instrumented historical wheel" if args.baseline_wheel else "instrumented version fixture",+ "baseline_source_sha256": digest(baseline_source), "baseline_fixture_sha256": digest(baseline),+ "target_wheel": str(selected), "target_sha256": digest(selected), "commit": args.commit,+ "target_unmodified": selected == target}+ write(case_root / "case.json", case)+ with timings.measure("baseline_install", scenario=scenario, journey=1):+ subprocess.run([str(python), "-I", "-m", "pip", "install", "--no-deps", "--force-reinstall", str(baseline)],+ check=True, env=env, timeout=120, stdout=subprocess.DEVNULL)+ child = [str(python), "-I", str(Path(__file__).resolve())]+ # Raw logs stay private to this local evidence root, including on success.+ with (case_root / "acceptance.log").open("w", encoding="utf-8") as log:+ def journey(number):+ with timings.measure("prepare", scenario=scenario, journey=number):+ subprocess.run([*child, "--phase", "prepare", "--output", str(case_root)],+ check=True, env=env, cwd=case_root, stdout=log, stderr=log, timeout=180)+ launch = read(case_root / "launch.json")+ with timings.measure("worker", scenario=scenario, journey=number):+ subprocess.run(launch["command"], check=True, env=env, cwd=launch["directory"],+ stdout=log, stderr=log, timeout=420)+ with timings.measure("verify", scenario=scenario, journey=number):+ subprocess.run([*child, "--phase", "verify", "--output", str(case_root)],+ check=True, env=env, cwd=case_root, stdout=log, stderr=log, timeout=180)+ return read(case_root / "result.json")++ try:+ result = journey(1)+ if result["phase"] == "restored" or scenario == "upgrade-again":+ with timings.measure("fixture", scenario=scenario, journey=2):+ previous_job = read(case_root / "launch.json")["directory"]+ write(feed, feed_records(target, args.commit, generation=2))+ write(case_root / "case.json", {+ **case, "scenario": "upgrade", "baseline_version": result["running_version"],+ "baseline_kind": "previous journey's running installation",+ "baseline_source_sha256": (case["baseline_source_sha256"] if result["phase"] == "restored"+ else case["target_sha256"]),+ "baseline_fixture_sha256": (case["baseline_fixture_sha256"] if result["phase"] == "restored"+ else case["target_sha256"]),+ "target_version": version, "target_wheel": str(target),+ "target_sha256": original_hash, "target_unmodified": True,+ })+ result["subsequent_update"] = journey(2)+ assert read(case_root / "launch.json")["directory"] != previous_job+ assert result["subsequent_update"]["phase"] == "succeeded"+ write(case_root / "result.json", result)+ results.append(result)+ except (subprocess.CalledProcessError, subprocess.TimeoutExpired):+ log.flush()+ tail = (case_root / "acceptance.log").read_text(encoding="utf-8", errors="replace")[-8192:]+ config_file = account / ".nanobot/config.json"+ if config_file.exists():+ token = read(config_file)["channels"]["websocket"]["tokenIssueSecret"]+ tail = tail.replace(token, "[redacted]")+ print(tail, file=sys.stderr)+ raise+ finally:+ with timings.measure("cleanup", scenario=scenario):+ subprocess.run([str(python), "-I", "-m", "nanobot", "gateway", "stop", "--config",+ str(account / ".nanobot/config.json")], env=env, cwd=case_root,+ stdout=log, stderr=log, timeout=60, check=True)+ config_file = account / ".nanobot/config.json"+ if config_file.exists():+ config = read(config_file)+ _wait_for_closed_listeners((config["gateway"]["port"], config["channels"]["websocket"]["port"]))+ # No journey result exists on failure; successful journeys+ # also retain the existing native Dock shutdown assertion.+ if results and results[-1]["scenario"] == scenario:+ results[-1]["gateway_process_stopped"] = True+ dock_address = results[-1].get("dock_socket")+ if not dock_address:+ dock_address = results[-1].get("subsequent_update", {}).get("dock_socket")+ if dock_address:+ _wait_dock(Path(dock_address), present=False)+ results[-1]["dock_stopped"] = True+ print(f"PASS {scenario}: {results[-1]['phase']}", flush=True)assert digest(target) == original_hashreturn {"platform": platform.system(), "machine": platform.machine(), "python": platform.python_version(),"target_sha256": original_hash, "candidate_commit": args.commit, "version": version,diff --git a/tests/scripts/test_ci_gate.py b/tests/scripts/test_ci_gate.pynew file mode 100644index 000000000..491be4679--- /dev/null+++ b/tests/scripts/test_ci_gate.py@@ -0,0 +1,65 @@+"""Protect the required-check contract when GitHub skips conditional jobs."""++import pytest++from scripts.ci_gate import check_results+++def results(*domains):+ return {+ "changes": {"result": "success", "outputs": {+ f"{domain}_required": str(domain in domains).lower()+ for domain in ("python", "webui", "tui", "docker", "native")+ }},+ **{job: {"result": "skipped"} for job in (+ "test", "windows_process", "windows_installers", "webui_checks", "webui_browser", "webui", "tui", "docker", "native",+ )},+ }+++def test_documentation_needs_no_product_jobs():+ assert check_results(results(), "pull_request") == []++[email protected]("result", ["failure", "cancelled", "skipped"])+def test_selected_job_must_succeed(result):+ needs = results("webui")+ for job in ("webui_checks", "webui_browser", "webui"):+ needs[job]["result"] = "success"+ needs["webui_browser"]["result"] = result+ assert check_results(needs, "pull_request")+++def test_native_runs_on_high_risk_pr_but_not_main_push():+ needs = results("native")+ assert check_results(needs, "pull_request")+ assert check_results(needs, "push") == []+ needs["native"]["result"] = "success"+ assert check_results(needs, "pull_request") == []+++def test_failed_or_incomplete_selection_is_not_documentation_only():+ needs = results()+ needs["changes"]["result"] = "failure"+ assert check_results(needs, "pull_request")+ needs["changes"]["result"] = "success"+ del needs["changes"]["outputs"]["native_required"]+ assert check_results(needs, "pull_request")+++def test_unexpected_failure_is_not_ignored():+ needs = results()+ needs["native"]["result"] = "cancelled"+ assert check_results(needs, "push")+++def test_selected_windows_installers_are_required_independently_of_process_tests():+ needs = results("python", "native")+ for job in ("test", "windows_process", "native"):+ needs[job]["result"] = "success"+ assert check_results(needs, "pull_request") == ["windows_installers: required, got skipped"]+ needs["windows_installers"]["result"] = "success"+ assert check_results(needs, "pull_request") == []+ needs["windows_installers"]["result"] = "skipped"+ needs["native"]["result"] = "skipped"+ assert check_results(needs, "push") == []diff --git a/tests/scripts/test_ci_scope.py b/tests/scripts/test_ci_scope.pynew file mode 100644index 000000000..3168eb7bb--- /dev/null+++ b/tests/scripts/test_ci_scope.py@@ -0,0 +1,205 @@+"""Path policy and real git range regressions for the CI selector."""++import html+import json+import os+import subprocess+import sys+from pathlib import Path+from zipfile import ZipFile++import pytest++from scripts.ci_scope import JOBS, classify_paths, select_scope++ROOT = Path(__file__).resolve().parents[2]+++def selected(result):+ return {name.removesuffix("_required") for name, value in result["outputs"].items() if value}+++ ("path", "expected"),+ [+ ("docs/releasing.md", set()),+ ("webui/README.md", set()),+ ("README.md", {"docker"}),+ ("Dockerfile", {"docker"}),+ ("entrypoint.sh", {"docker"}),+ ("tests/test_docker_config.py", {"python", "docker"}),+ ("tests/test_docker_smoke.py", {"python", "docker"}),+ ("webui/package.json", {"webui", "docker"}),+ ("nanobot/channels/discord/webui/index.ts", {"webui", "docker"}),+ ("tui/package.json", {"tui", "native"}),+ ("tui/scripts/build.ts", {"tui", "native"}),+ ("tui/src/composer/textarea.ts", {"tui"}),+ ("nanobot/channels/websocket/runtime.py", {"python", "webui", "tui", "docker", "native"}),+ ("nanobot/providers/registry.py", {"python", "docker"}),+ ("nanobot/webui/native_file_picker.py", {"python", "webui", "docker"}),+ ("nanobot/webui/client_contract.py", {"python", "webui", "tui", "docker"}),+ ("nanobot/webui/forking.py", {"python", "webui", "tui", "docker"}),+ ("nanobot/cli/webui.py", {"python", "docker", "native"}),+ ("nanobot/webui/ws_http.py", {"python", "webui", "tui", "docker"}),+ ("nanobot/session/session_messages.py", {"python", "webui", "tui", "docker"}),+ ("packages/client-events/notifications.ts", {"webui", "tui", "docker"}),+ ("nanobot/update_recovery.py", {"python", "docker", "native"}),+ ("nanobot/release_trust.py", {"python", "docker", "native"}),+ ("nanobot/gateway/runtime.py", {"python", "docker", "native"}),+ ("nanobot/process_runtime.py", {"python", "docker", "native"}),+ ("nanobot/cli/entry.py", {"python", "docker", "native"}),+ ("nanobot/utils/atomic_file.py", {"python", "docker", "native"}),+ ("tests/test_update_backup.py", {"python", "native"}),+ ("tests/test_install_scripts.py", {"python", "native"}),+ ("tests/providers/test_cached_tokens.py", {"python"}),+ ("scripts/pytest_timing.py", {"python"}),+ ("tests/scripts/test_pytest_timing.py", {"python"}),+ ("scripts/verify_packaged_update.py", {"python", "native"}),+ ("scripts/check_client_import_boundaries.mjs", {"webui", "tui"}),+ (".github/workflows/release-candidate.yml", {"python", "native"}),+ (".github/workflows/release-approve.yml", {"python", "native"}),+ (".github/workflows/tui-release.yml", {"python", "tui", "native"}),+ ("pyproject.toml", {"python", "webui", "tui", "docker", "native"}),+ ("hatch_build.py", {"python", "webui", "tui", "docker", "native"}),+ ("scripts/install_channel_dependencies.py", {"python", "webui", "tui", "docker", "native"}),+ (".github/workflows/ci.yml", {"python", "webui", "tui", "docker", "native"}),+ ("scripts/ci_scope.py", {"python", "webui", "tui", "docker", "native"}),+ ("nanobot/webui/build.py", {"python", "webui", "tui", "docker", "native"}),+ ("nanobot/webui/local_client_assets.py", {"python", "webui", "docker", "native"}),+ ],+)+def test_existing_path_policy(path, expected):+ # These are reachable repository inputs, not merely invented glob matches.+ assert (ROOT / path).is_file()+ result = classify_paths([path])+ assert selected(result) == expected+ assert result["paths"][0]["reason"]++[email protected]("path", ["new-domain/source.txt", ".github/workflows/publish-index.yml", "uv.lock"])+def test_new_or_cross_domain_paths_require_every_job(path):+ assert all(classify_paths([path])["outputs"].values())+++def test_union_preserves_each_reason():+ result = classify_paths(["docs/releasing.md", "tui/package.json", "nanobot/providers/registry.py"])+ assert selected(result) == {"python", "docker", "tui", "native"}+ assert len(result["paths"]) == 3+++def repo(tmp_path):+ def git(*args, input=None):+ return subprocess.run(+ ["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True, input=input,+ ).stdout.strip()++ git("init", "-b", "main")+ git("config", "user.name", "CI scope test")+ git("config", "user.email", "[email protected]")++ def commit(path, text):+ target = tmp_path / path+ target.parent.mkdir(parents=True, exist_ok=True)+ target.write_text(text, encoding="utf-8")+ git("add", "--all")+ git("commit", "-m", "fixture change")+ return git("rev-parse", "HEAD")++ return tmp_path, git, commit+++def test_push_includes_all_commits_not_only_last(repo):+ cwd, _, commit = repo+ base = commit("docs/guide.md", "initial")+ commit("nanobot/providers/new.py", "production")+ head = commit("webui/src/new.ts", "frontend")+ result = select_scope("push", base, head, cwd=cwd)+ assert selected(result) == {"python", "webui", "docker"}+ assert result["diff_range"] == f"{base}..{head}"+++def test_pr_uses_merge_base_not_base_tip(repo):+ cwd, git, commit = repo+ commit("docs/guide.md", "initial")+ git("checkout", "-b", "feature")+ head = commit("webui/src/new.ts", "frontend")+ git("checkout", "main")+ base = commit("tui/src/base-only.ts", "base branch only")+ assert selected(select_scope("pull_request", base, head, cwd=cwd)) == {"webui", "docker"}+ assert selected(select_scope("push", base, head, cwd=cwd)) == {"webui", "docker", "tui"}+++def test_rename_and_delete_keep_old_domain(repo):+ cwd, git, commit = repo+ commit("nanobot/providers/old.py", "production")+ base = commit("tui/src/removed.ts", "native package")+ target = cwd / "docs" / "renamed file.md"+ target.parent.mkdir()+ (cwd / "nanobot/providers/old.py").rename(target)+ (cwd / "tui/src/removed.ts").unlink()+ git("add", "--all")+ git("commit", "-m", "rename and delete")+ result = select_scope("push", base, git("rev-parse", "HEAD"), cwd=cwd)+ assert selected(result) == {"python", "docker", "tui"}+ assert {item["path"] for item in result["paths"]} == {+ "nanobot/providers/old.py", "tui/src/removed.ts", "docs/renamed file.md",+ }+++def test_empty_missing_and_invalid_diff_are_full(repo):+ cwd, _, commit = repo+ head = commit("docs/guide.md", "initial")+ for base, expected in [(head, "empty diff"), ("0" * 40, "git diff unavailable"), ("--help", "invalid")]:+ result = select_scope("push", base, head, cwd=cwd)+ assert all(result["outputs"].values())+ assert expected in result["reason"]+++def test_non_repository_and_dispatch_are_full(tmp_path):+ result = select_scope("pull_request", "1" * 40, "2" * 40, cwd=tmp_path)+ assert all(result["outputs"].values())+ assert "git diff unavailable" in result["reason"]+ result = select_scope("workflow_dispatch", "", "", cwd=tmp_path)+ assert all(result["outputs"].values())+ assert "manual dispatch" in result["reason"]+++def test_cli_emits_only_fixed_boolean_outputs_and_escaped_summary(repo):+ cwd, git, commit = repo+ base = commit("docs/guide.md", "initial")+ # A PR authored on Unix can contain names Windows cannot check out or add+ # to its index. Build the actual Git tree directly, without materializing it.+ blob = git("rev-parse", "HEAD:docs/guide.md")+ subtree = git("mktree", "-z", input=f"100644 blob {blob}\t```\npython_required=false<script>.ts\0")+ tree = git("mktree", "-z", input=f"040000 tree {subtree}\twebui\0")+ head = git("commit-tree", tree, "-p", base, "-m", "untrusted filename")+ output, summary = cwd / "output", cwd / "summary"+ proc = subprocess.run(+ [sys.executable, str(ROOT / "scripts/ci_scope.py"), "--event", "push", "--base", base, "--head", head],+ cwd=cwd, check=True, capture_output=True, text=True,+ env={**os.environ, "GITHUB_OUTPUT": str(output), "GITHUB_STEP_SUMMARY": str(summary)},+ )+ result = json.loads(proc.stdout)+ assert selected(result) == {"webui", "docker"}+ assert output.read_text().splitlines() == [+ f"{job}={str(result['outputs'][job]).lower()}" for job in JOBS+ ]+ assert "<script>" in summary.read_text()+ assert "\\npython_required=false" in summary.read_text()+ summary_json = summary.read_text().split("<pre>", 1)[1].removesuffix("</pre>\n")+ assert json.loads(html.unescape(summary_json)) == result+++def test_every_frozen_worker_source_selects_native_acceptance(tmp_path):+ from nanobot.update_jobs import _worker_archive++ archive = tmp_path / "worker.pyz"+ _worker_archive(archive)+ with ZipFile(archive) as bundle:+ sources = ["nanobot/" + name.removeprefix("_nanobot_update/")+ for name in bundle.namelist()+ if name.startswith("_nanobot_update/") and not name.endswith("__init__.py")]+ assert sources+ for path in sources:+ assert classify_paths([path])["outputs"]["native_required"], pathdiff --git a/tests/scripts/test_ci_workflows.py b/tests/scripts/test_ci_workflows.pynew file mode 100644index 000000000..f1223595b--- /dev/null+++ b/tests/scripts/test_ci_workflows.py@@ -0,0 +1,55 @@+"""Producer/consumer artifact wiring must survive failed-jobs-only retries."""++from pathlib import Path++import pytest+import yaml++WORKFLOWS = Path(__file__).resolve().parents[2] / ".github/workflows"+++def workflow(name):+ return yaml.load((WORKFLOWS / name).read_text(encoding="utf-8"), Loader=yaml.BaseLoader)++[email protected]("platform,step", [("linux", "linux_input"), ("windows", "windows_input")])+def test_native_consumers_receive_immutable_producer_ids(platform, step):+ jobs = workflow("release-candidate.yml")["jobs"]+ key = f"{platform}_artifact_id"+ producer = jobs["candidate"]+ assert producer["outputs"][key] == "${{ steps." + step + ".outputs.artifact-id }}"+ upload = next(item for item in producer["steps"] if item.get("id") == step)+ assert upload["uses"] == "actions/upload-artifact@v4"+ assert jobs["native"]["with"][key] == "${{ needs.candidate.outputs." + key + " }}"+ consumer = workflow("native-acceptance.yml")["jobs"]["native"]+ download = next(item for item in consumer["steps"] if item.get("uses") == "actions/download-artifact@v4")+ assert "inputs." + key in download["with"]["artifact-ids"]+ assert "name" not in download["with"]+ assert download["with"]["merge-multiple"] == "true"+++def test_accepted_handoff_uses_the_producer_id_and_requires_native_success():+ jobs = workflow("release-candidate.yml")["jobs"]+ assert jobs["candidate"]["outputs"]["prepared_artifact_id"] == "${{ steps.prepared.outputs.artifact-id }}"+ verified = jobs["verified"]+ assert set(verified["needs"]) == {"candidate", "native"}+ gate = verified["steps"][0]+ assert gate["env"]["NATIVE_RESULT"] == "${{ needs.native.result }}"+ assert gate["run"] == 'test "$BUILD_RESULT" = success && test "$NATIVE_RESULT" = success'+ download = next(item for item in verified["steps"] if item.get("uses") == "actions/download-artifact@v4")+ assert download["with"]["artifact-ids"] == "${{ needs.candidate.outputs.prepared_artifact_id }}"+ assert download["with"]["merge-multiple"] == "true"+ assert "name" not in download["with"]+++def test_windows_installer_matrix_has_an_independent_required_job():+ jobs = workflow("ci.yml")["jobs"]+ installer = jobs["windows_installers"]+ assert installer["runs-on"] == "windows-latest"+ assert "native_required" in installer["if"] and "python_required" in installer["if"]+ assert "github.event_name != 'push'" in installer["if"]+ commands = [step.get("run", "") for step in installer["steps"]]+ assert any("tests/test_install_scripts.py" in command and "-n 4" in command for command in commands)+ assert not any("tests/test_install_scripts.py" in step.get("run", "")+ for step in jobs["windows_process"]["steps"])+ assert "windows_installers" in jobs["required"]["needs"]diff --git a/tests/scripts/test_native_acceptance_input.py b/tests/scripts/test_native_acceptance_input.pynew file mode 100644index 000000000..0b7b960f7--- /dev/null+++ b/tests/scripts/test_native_acceptance_input.py@@ -0,0 +1,62 @@+"""Acceptance must use the built candidate bytes, not a rebuilt substitute."""++import hashlib+import json+from zipfile import ZipFile++import pytest++from scripts.native_acceptance_input import acceptance_input++COMMIT = "a" * 40+TAG = "win_amd64"+++def candidate(tmp_path):+ wheel = tmp_path / "nanobot_ai-0.3.6.dev42-py3-none-win_amd64.whl"+ with ZipFile(wheel, "w") as archive:+ archive.writestr("nanobot/_build_commit.txt", COMMIT + "\n")+ manifest = {"candidate_commit": COMMIT, "version": "0.3.6.dev42", "artifacts": [{+ "filename": wheel.name, "size": wheel.stat().st_size,+ "sha256": hashlib.sha256(wheel.read_bytes()).hexdigest(),+ }]}+ payload = json.dumps(manifest).encode()+ (tmp_path / "release-manifest.json").write_bytes(payload)+ return wheel, hashlib.sha256(payload).hexdigest()+++def test_select_exact_candidate_wheel(tmp_path):+ wheel, digest = candidate(tmp_path)+ result = acceptance_input(tmp_path, tag=TAG, commit=COMMIT, manifest_sha256=digest)+ assert result["wheel"] == str(wheel)+ assert result["version"] == "0.3.6.dev42"+ assert result["manifest_sha256"] == digest+++def test_reject_replaced_wheel(tmp_path):+ wheel, digest = candidate(tmp_path)+ wheel.write_bytes(wheel.read_bytes() + b"changed")+ with pytest.raises(ValueError, match="wheel differs"):+ acceptance_input(tmp_path, tag=TAG, commit=COMMIT, manifest_sha256=digest)+++def test_reject_replaced_manifest(tmp_path):+ _, digest = candidate(tmp_path)+ path = tmp_path / "release-manifest.json"+ path.write_bytes(path.read_bytes() + b" ")+ with pytest.raises(ValueError, match="manifest differs"):+ acceptance_input(tmp_path, tag=TAG, commit=COMMIT, manifest_sha256=digest)+++def test_reject_wrong_candidate_commit(tmp_path):+ _, digest = candidate(tmp_path)+ with pytest.raises(ValueError, match="Candidate commit differs"):+ acceptance_input(tmp_path, tag=TAG, commit="b" * 40, manifest_sha256=digest)+++def test_pr_package_must_embed_checked_out_commit(tmp_path):+ wheel, _ = candidate(tmp_path)+ result = acceptance_input(tmp_path, tag=TAG, commit=COMMIT, version="0.3.6.dev42")+ assert result["wheel_sha256"] == hashlib.sha256(wheel.read_bytes()).hexdigest()+ with pytest.raises(ValueError, match="Wheel build commit differs"):+ acceptance_input(tmp_path, tag=TAG, commit="b" * 40, version="0.3.6.dev42")diff --git a/tests/test_install_scripts.py b/tests/test_install_scripts.pyindex 36face203..0bb626bb9 100644--- a/tests/test_install_scripts.py+++ b/tests/test_install_scripts.py@@ -17,6 +17,7 @@ import sslimport subprocessimport sysimport sysconfig+import tempfileimport threadingimport tomllibimport urllib.request@@ -91,9 +92,25 @@ def _python(environment):return environment / ("Scripts/python.exe" if WINDOWS else "bin/python")-def _run(command, sandbox, *, check=True):- result = subprocess.run(command, cwd=sandbox["cwd"], env=sandbox["env"],- capture_output=True, text=True, encoding="utf-8", timeout=90)+def _run(command, sandbox, *, check=True, timeout=90):+ # Installer subprocesses may inherit output handles. Bound the command's+ # lifetime, not pipe EOF, and retain partial output when the command times out.+ with tempfile.TemporaryFile() as stdout, tempfile.TemporaryFile() as stderr:+ try:+ process = subprocess.run(command, cwd=sandbox["cwd"], env=sandbox["env"],+ stdout=stdout, stderr=stderr, timeout=timeout)+ except subprocess.TimeoutExpired:+ stdout.seek(0)+ stderr.seek(0)+ output = stdout.read().decode("utf-8", errors="replace")+ error = stderr.read().decode("utf-8", errors="replace")+ pytest.fail(f"Installer command exceeded {timeout}s: {command!r}\n"+ f"stdout:\n{output}\nstderr:\n{error}", pytrace=False)+ stdout.seek(0)+ stderr.seek(0)+ result = subprocess.CompletedProcess(command, process.returncode,+ stdout.read().decode("utf-8", errors="replace"),+ stderr.read().decode("utf-8", errors="replace"))if check:assert result.returncode == 0, result.stdout + result.stderrreturn result@@ -832,3 +849,11 @@ def test_generated_bootstrap_command_downloads_and_upgrades_original_owner(sandbassert Path(identity["prefix"]).resolve() == prefixassert requests[0] == installer_url and len(requests) == 3assert not list(sandbox["root"].glob("*/install.sh"))+++def test_installer_command_timeout_preserves_partial_diagnostics(sandbox):+ command = [BASE_PYTHON, "-I", "-c",+ "import sys, time; print('installer-stage', flush=True); "+ "print('manager-stage', file=sys.stderr, flush=True); time.sleep(10)"]+ with pytest.raises(pytest.fail.Exception, match="(?s)installer-stage.*manager-stage"):+ _run(command, sandbox, timeout=1)diff --git a/tests/test_packaged_update_probe.py b/tests/test_packaged_update_probe.pyindex d6dea8141..5debcf1c2 100644--- a/tests/test_packaged_update_probe.py+++ b/tests/test_packaged_update_probe.py@@ -15,6 +15,7 @@ import pytestfrom nanobot.release_feed import ReleaseFeedfrom scripts.verify_packaged_update import (+ Timings,assert_canonical_preserved,assert_history_preserved,canonical_records,@@ -187,3 +188,68 @@ def test_unisolated_probe_refuses_before_creating_output(tmp_path):capture_output=True, text=True, timeout=10)assert result.returncode == 2 and "python -I" in result.stderrassert not output.exists()+++def test_timings_checkpoint_real_fixture_and_keep_result_schema_separate(tmp_path, capsys):+ output = tmp_path / "packaged-update-timings.json"+ timings = Timings(output)+ source = wheel(tmp_path, "0.3.6")+ with timings.measure("scenario_total", scenario="upgrade"):+ with timings.measure("fixture", scenario="upgrade", journey=1):+ baseline = fixture_wheel(source, tmp_path / "baseline", "0.3.5", feed=tmp_path / "feed.json")+ # Evidence is available before the outer context exits.+ checkpoint = json.loads(output.read_text())+ assert checkpoint["clock"] == "perf_counter"+ assert checkpoint["schema_version"] == 1+ assert len(checkpoint["timings"]) == 1+ assert checkpoint["timings"][0]["phase"] == "fixture"+ assert baseline.exists()+ for number in (1, 2):+ with timings.measure("verify", scenario="upgrade", journey=number):+ assert digest(source) != digest(baseline)+ records = json.loads(output.read_text())["timings"]+ assert [(row["phase"], row["journey"]) for row in records] == [+ ("fixture", 1), ("verify", 1), ("verify", 2), ("scenario_total", None)]+ assert all(row["status"] == "succeeded" and row["seconds"] >= 0 for row in records)+ assert records[-1]["seconds"] >= sum(row["seconds"] for row in records[:-1])+ assert not (tmp_path / "result.json").exists()+ assert not (tmp_path / "packaged-update-report.json").exists()+ stdout = capsys.readouterr().out+ assert "TIMING upgrade/1/fixture:" in stdout+ assert "TIMING upgrade/2/verify:" in stdout+ assert "TIMING upgrade/scenario_total:" in stdout++[email protected]("failure", ["exit", "timeout", "assertion"])+def test_timings_persist_failure_and_finally_cleanup_without_exporting_secrets(tmp_path, capsys, failure):+ output = tmp_path / "packaged-update-timings.json"+ timings = Timings(output)+ secret = "sensitive-token-must-stay-local"+ error = {"exit": subprocess.CalledProcessError, "timeout": subprocess.TimeoutExpired,+ "assertion": AssertionError}[failure]+ with pytest.raises(error):+ with timings.measure("scenario_total", scenario="restart-failure"):+ try:+ with timings.measure("worker", scenario="restart-failure", journey=2):+ if failure == "assertion":+ raise AssertionError(secret)+ command = ("raise SystemExit(91)" if failure == "exit" else "import time; time.sleep(30)")+ subprocess.run([sys.executable, "-I", "-c", command, secret], check=True,+ capture_output=True, timeout=0.1 if failure == "timeout" else 10)+ finally:+ with timings.measure("cleanup", scenario="restart-failure"):+ # Read the failed phase from disk before cleanup completes.+ assert json.loads(output.read_text())["timings"][0]["status"] == "failed"+ (tmp_path / "cleaned").touch()+ assert (tmp_path / "cleaned").exists()+ document = output.read_text()+ records = json.loads(document)["timings"]+ assert [(row["phase"], row["status"]) for row in records] == [+ ("worker", "failed"), ("cleanup", "succeeded"), ("scenario_total", "failed")]+ assert all(row["seconds"] >= 0 for row in records)+ assert records[-1]["seconds"] >= sum(row["seconds"] for row in records[:-1])+ assert secret not in document+ captured = capsys.readouterr()+ assert secret not in captured.out + captured.err+ assert "TIMING restart-failure/2/worker:" in captured.out+ assert "TIMING restart-failure/scenario_total:" in captured.out