diff --git a/.github/workflows/desktop-replay.yml b/.github/workflows/desktop-replay.yml index 0b10d9f25b..aebe689b33 100644 --- a/.github/workflows/desktop-replay.yml +++ b/.github/workflows/desktop-replay.yml @@ -26,7 +26,29 @@ on: # Drafts run nothing (each job checks `draft`); marking one ready runs it. types: [opened, synchronize, reopened, ready_for_review] paths: - - packages/flow/openadapt_flow/** + - packages/flow/openadapt_flow/backend.py + - packages/flow/openadapt_flow/backends/** + - packages/flow/openadapt_flow/runtime/** + - packages/flow/openadapt_flow/compiler/** + - packages/flow/openadapt_flow/desktop_record.py + - packages/flow/openadapt_flow/recorder.py + - packages/flow/openadapt_flow/approval_mode/** + - packages/flow/openadapt_flow/policy.py + - packages/flow/openadapt_flow/qualification/** + - packages/flow/openadapt_flow/ir.py + - packages/flow/openadapt_flow/contracts.py + - packages/flow/openadapt_flow/identity_signals.py + - packages/flow/openadapt_flow/record_check_identity.py + - packages/flow/openadapt_flow/submit_binding.py + - packages/flow/openadapt_flow/verify.py + - packages/flow/openadapt_flow/verify_run.py + - packages/flow/openadapt_flow/verifier.py + - packages/flow/openadapt_flow/action_evidence.py + - packages/flow/openadapt_flow/choice_capture.py + - packages/flow/openadapt_flow/_windows_directory.py + - packages/flow/openadapt_flow/crypto.py + - packages/flow/openadapt_flow/at_rest.py + - packages/flow/openadapt_flow/sealed_set.py - packages/flow/scripts/desktop/pn_db.py - packages/flow/scripts/desktop/patient_notes.ps1 - packages/flow/tests/e2e/test_windows_hosted_replay.py diff --git a/.github/workflows/link-check.yml b/.github/workflows/link-check.yml index ca54ec0b0a..175152a100 100644 --- a/.github/workflows/link-check.yml +++ b/.github/workflows/link-check.yml @@ -13,6 +13,9 @@ on: types: [opened, synchronize, reopened, ready_for_review] paths: - "**/*.md" + - "!**/CHANGELOG.md" + - "!.github/**/*.md" + - "!legacy/**/*.md" - ".github/workflows/link-check.yml" - "scripts/ci/install_checked_tool.py" - "scripts/ci/run_lychee.py" @@ -20,6 +23,9 @@ on: branches: [main] paths: - "**/*.md" + - "!**/CHANGELOG.md" + - "!.github/**/*.md" + - "!legacy/**/*.md" - ".github/workflows/link-check.yml" - "scripts/ci/install_checked_tool.py" - "scripts/ci/run_lychee.py" diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index afa54b0169..cf4c73c671 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -129,6 +129,7 @@ jobs: program_graph: ${{ steps.classify.outputs.program_graph }} seal_view: ${{ steps.classify.outputs.seal_view }} weight: ${{ steps.classify.outputs.weight }} + fast_checks: ${{ steps.classify.outputs.fast_checks }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -148,7 +149,7 @@ jobs: if [ "$EVENT_NAME" = pull_request ]; then unit_shards=4; else unit_shards=2; fi echo "flow_unit_shards=$unit_shards" >> "$GITHUB_OUTPUT" all() { - for pkg in flow flow_at_rest flow_onprem flow_agent_frameworks types agent eligibility verify capture privacy desktop tray program_graph seal_view weight; do echo "$pkg=true" >> "$GITHUB_OUTPUT"; done + for pkg in flow flow_at_rest flow_onprem flow_agent_frameworks types agent eligibility verify capture privacy desktop tray program_graph seal_view weight fast_checks; do echo "$pkg=true" >> "$GITHUB_OUTPUT"; done exit 0 } case "$EVENT_NAME" in @@ -181,9 +182,15 @@ jobs: # against the in-tree capture. flow="$(hit "^packages/(flow|capture|types)/|$browser_support|$wf")" # Sub-package gates on pull requests and queue groups; pushes to main, - # schedules and dispatches follow `flow`. Encryption at rest is the - # default for every store, so any Flow, Types or Capture code change can - # regress it; only prose (docs/ and top-level *.md) skips these jobs. + # schedules and dispatches follow `flow`. + # On PRs, `flow_at_rest` uses a fail-closed deny-list: every Python/code + # path under packages/{flow,capture,types}/ selects `flow-default-at-rest` + # (including benchmark/*.py, examples/*.py, chrome_extension/native_host/*.py, + # tests/*.py, and cli_tasks.py). Only non-Python docs, paper, and static + # data/asset files under benchmark/, examples/, and chrome_extension/ skip + # the duplicate 4-shard run. An AST test in tests/test_ci_efficiency_gating.py + # enforces that zero .py files are excluded and 100% of at-rest importers + # select true. if [ "$EVENT_NAME" != pull_request ] && [ "$EVENT_NAME" != merge_group ]; then flow_at_rest="$flow" flow_onprem="$flow" @@ -192,7 +199,10 @@ jobs: code_changed="$(grep -Ev '^packages/(flow|capture|types)/(docs/|[^/]*\.md$)' <<<"$changed" || true)" hit_code() { if grep -Eq "$1" <<<"$code_changed"; then echo true; else echo false; fi; } flow_code="$(hit_code "^packages/(flow|capture|types)/|$browser_support|$wf")" - flow_at_rest="$flow_code" + at_rest_excluded='^packages/flow/([^/]*\.md$|(docs|paper|benchmark|examples|chrome_extension)/.*\.(json|jsonl|md|tex|bib|log|csv|txt|png|svg|gif|html|css|js)$)' + at_rest_changed="$(grep -Ev "$at_rest_excluded" <<<"$code_changed" || true)" + hit_at_rest() { if grep -Eq "$1" <<<"$at_rest_changed"; then echo true; else echo false; fi; } + flow_at_rest="$(hit_at_rest "^packages/(flow|capture|types)/|$browser_support|$wf")" flow_onprem="$flow_code" flow_agent_frameworks="$flow_code" fi @@ -215,6 +225,13 @@ jobs: # Any package's metadata, or the launcher's, can change what an # install pulls in. weight="$(hit "^packages/|^pyproject\.toml$|^openadapt/|^hatch_build\.py$|^scripts/install_weight/|$wf")" + # Combined fast-checks job runs lightweight lint/release contracts for + # capture, privacy, tray, and (on PRs) desktop-release-intent on one VM. + if [ "$capture" = true ] || [ "$privacy" = true ] || [ "$tray" = true ] || { [ "$EVENT_NAME" = pull_request ] && [ "$desktop" = true ]; }; then + fast_checks=true + else + fast_checks=false + fi { echo "flow=$flow" echo "flow_at_rest=$flow_at_rest" @@ -231,6 +248,7 @@ jobs: echo "program_graph=$program_graph" echo "seal_view=$seal_view" echo "weight=$weight" + echo "fast_checks=$fast_checks" } | tee -a "$GITHUB_OUTPUT" types: @@ -696,14 +714,17 @@ jobs: flow-default-at-rest: # The whole flow suite under the product default: encryption at rest on - # (no plaintext opt-out). Required on code-changing pull requests (prose-only - # Flow PRs skip it via flow_at_rest). Tests that read or plant plaintext files - # directly, and known open limitations, are skipped in this mode with their - # reason (tests/default_at_rest_skips.txt, #2423). + # (no plaintext opt-out). Runs on PRs that touch encryption/storage/durable/ + # sealing/harness/lock/types/workflow paths (saving a duplicate 4-shard run + # on unrelated Flow PRs while flow-unit shard 1 still runs the 21 core + # encrypted-at-rest tests) and on every push to main that touches Flow. + # Tests that read or plant plaintext files directly, and known open + # limitations, are skipped in this mode (tests/default_at_rest_skips.txt, #2423). name: flow default at rest (shard ${{ matrix.shard }}/${{ matrix.of }}) needs: scope - # PR tier only (as on main): avoids untriaged nightly e2e under encrypted mode. - if: github.event_name == 'pull_request' && github.event.pull_request.draft != true && needs.scope.outputs.flow_at_rest == 'true' + # PR (when flow_at_rest=true) and push-to-main (when flow=true); skips + # merge_group and nightly/dispatch (avoids untriaged nightly e2e under encrypted mode). + if: (github.event_name == 'pull_request' || github.event_name == 'push') && github.event.pull_request.draft != true && needs.scope.outputs.flow_at_rest == 'true' runs-on: ubuntu-latest # The nightly tier (a schedule or a dispatch) also measures coverage, # which slows the suite by about a third; it gets 60 minutes. @@ -715,7 +736,7 @@ jobs: # ubuntu-latest) and pays about 35 s of setup. Files are packed by # measured time (scripts/ci/flow_shards.py), so the shards finish # together. - include: [{"shard":1,"of":4},{"shard":2,"of":4},{"shard":3,"of":4},{"shard":4,"of":4}] + include: ${{ fromJSON(needs.scope.outputs.flow_unit_shards == '4' && '[{"shard":1,"of":4},{"shard":2,"of":4},{"shard":3,"of":4},{"shard":4,"of":4}]' || '[{"shard":1,"of":2},{"shard":2,"of":2}]') }} defaults: run: working-directory: packages/flow @@ -1695,51 +1716,6 @@ jobs: OPENADAPT_CI_NO_INPUT_INJECTION: "1" run: uv run --no-sync pytest tests/test_performance.py -v -m slow --timeout=300 - capture-contract: - name: capture lint and release contract - needs: scope - if: github.event.pull_request.draft != true && (needs.scope.outputs.capture == 'true') - runs-on: ubuntu-latest - timeout-minutes: 15 - defaults: - run: - working-directory: packages/capture - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 - with: - enable-cache: true - cache-dependency-glob: "packages/capture/uv.lock" - - name: Set up Python - run: uv python install 3.12 - - name: Install - run: uv sync --locked --extra dev - - name: Ruff - run: uv run --no-sync ruff check openadapt_capture/ - - name: Syntax at the oldest supported Python (3.10) - # The PR lane runs Python 3.12 only, so syntax that needs a newer - # Python than requires-python allows (a 3.12 f-string, say) passed it - # and failed only after merge. Check every file at the minimum. - # Bytecode goes to a temp directory, so later archive checks see a - # clean tree. - env: - PYTHONPYCACHEPREFIX: ${{ runner.temp }}/pycache-oldest - run: | - uv run --no-sync ruff check --isolated --select E9 --target-version py310 . - uv run --no-project --python 3.10 python -m compileall -q -x '(^|/)(\.venv|node_modules|build|dist)/' . - - name: Verify the maintained changelog - # --skip-tags: the monorepo's v* tags are the launcher's. Capture's - # release tags through v1.2.2 live in OpenAdaptAI/openadapt-capture. - run: uv run --no-sync python scripts/check_changelog.py --skip-tags - - name: Build wheel and source distribution - run: uv build - - name: Verify release archive boundaries - run: | - uv run --no-sync python scripts/verify_distribution.py dist/* - uv run --no-sync python scripts/check_source_boundary.py --require-dist - privacy: name: privacy (py${{ matrix.python-version }}) needs: scope @@ -1796,47 +1772,6 @@ jobs: - name: Test run: uv run --no-sync pytest tests/ -v - privacy-contract: - name: privacy lint and release contract - needs: scope - if: github.event.pull_request.draft != true && (needs.scope.outputs.privacy == 'true') - runs-on: ubuntu-latest - timeout-minutes: 15 - defaults: - run: - working-directory: packages/privacy - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 - with: - enable-cache: true - cache-dependency-glob: "packages/privacy/uv.lock" - - name: Set up Python - run: uv python install 3.12 - - name: Install - run: uv sync --locked --python 3.12 --extra dev - - name: Ruff - run: uv run --no-sync ruff check openadapt_privacy tests scripts - - name: Syntax at the oldest supported Python (3.10) - # The PR lane runs Python 3.12 only, so syntax that needs a newer - # Python than requires-python allows (a 3.12 f-string, say) passed it - # and failed only after merge. Check every file at the minimum. - # Bytecode goes to a temp directory, so later archive checks see a - # clean tree. - env: - PYTHONPYCACHEPREFIX: ${{ runner.temp }}/pycache-oldest - run: | - uv run --no-sync ruff check --isolated --select E9 --target-version py310 . - uv run --no-project --python 3.10 python -m compileall -q -x '(^|/)(\.venv|node_modules|build|dist)/' . - - name: Changelog matches the version and the release workflow - run: uv run --no-sync pytest tests/test_release_config.py -v - - name: Build wheel and source distribution - run: uv build - - name: Verify release archive boundaries - run: uv run --no-sync python scripts/check_source_boundary.py --require-dist - desktop-test: name: desktop test needs: scope @@ -1883,48 +1818,6 @@ jobs: PYSTRAY_BACKEND: ${{ runner.os == 'Linux' && 'dummy' || '' }} run: uv run --no-sync pytest tests -q - tray-contract: - name: tray lint and release contract - needs: scope - if: github.event.pull_request.draft != true && (needs.scope.outputs.tray == 'true') - runs-on: ubuntu-latest - timeout-minutes: 15 - defaults: - run: - working-directory: packages/tray - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 - with: - enable-cache: true - cache-dependency-glob: "packages/tray/uv.lock" - - name: Set up Python - run: uv python install 3.12 - - name: Install - run: uv sync --locked --python 3.12 --extra dev - # The whole package, including examples/ and the root helper scripts. - - name: Ruff - run: uv run --no-sync ruff check . - - name: Syntax at the oldest supported Python (3.10) - # The PR lane runs Python 3.12 only, so syntax that needs a newer - # Python than requires-python allows (a 3.12 f-string, say) passed it - # and failed only after merge. Check every file at the minimum. - # Bytecode goes to a temp directory, so later archive checks see a - # clean tree. - env: - PYTHONPYCACHEPREFIX: ${{ runner.temp }}/pycache-oldest - run: | - uv run --no-sync ruff check --isolated --select E9 --target-version py310 . - uv run --no-project --python 3.10 python -m compileall -q -x '(^|/)(\.venv|node_modules|build|dist)/' . - - name: Build wheel and source distribution - run: uv build - - name: Versions agree and both distributions exist - run: uv run --no-sync python scripts/check_release_consistency.py --require-dist - - name: Verify release archive boundaries - run: uv run --no-sync python scripts/check_source_boundary.py --require-dist - tray-desktop-ipc: # Desktop's socket server against this tray's IPC client, both from this # commit. desktop-test.yml runs the same test when Desktop changes. @@ -2095,16 +1988,14 @@ jobs: # yet, so a change that should ship must bump the version in its own pull # request. This fails a feat, fix or perf without a bump (and prints the # prepare_release.py command), and checks a bump's version sources and - # changelog section. - desktop-release-intent: - name: desktop release intent + # Consolidated lightweight lint, syntax, release-contract, and desktop + # release-intent checks sharing one Ubuntu VM, checkout, and uv setup. + fast-checks: + name: fast-checks (lint and release contracts) needs: scope - if: github.event.pull_request.draft != true && (github.event_name == 'pull_request' && needs.scope.outputs.desktop == 'true') + if: github.event.pull_request.draft != true && (needs.scope.outputs.fast_checks == 'true') runs-on: ubuntu-latest - timeout-minutes: 10 - defaults: - run: - working-directory: packages/desktop + timeout-minutes: 20 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -2113,11 +2004,64 @@ jobs: - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: "3.12" - - name: Require a version bump for a change that should ship - # The checkout is the pull request's merge commit: HEAD^1 is the base - # tip. HEAD (the merge) is the head: its versions and changelog are what - # would land, and HEAD^1..HEAD lists exactly the pull request's commits. + - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 + with: + enable-cache: true + cache-dependency-glob: | + packages/capture/uv.lock + packages/privacy/uv.lock + packages/tray/uv.lock + cache-suffix: fast-checks + - name: Desktop release intent + if: github.event_name == 'pull_request' && needs.scope.outputs.desktop == 'true' + working-directory: packages/desktop run: python scripts/check_release_intent.py --base HEAD^1 --head HEAD + - name: Capture lint and release contract + if: needs.scope.outputs.capture == 'true' + working-directory: packages/capture + env: + PYTHONPYCACHEPREFIX: ${{ runner.temp }}/pycache-capture + run: | + set -euo pipefail + uv python install 3.12 + uv sync --locked --extra dev + uv run --no-sync ruff check openadapt_capture/ + uv run --no-sync ruff check --isolated --select E9 --target-version py310 . + uv run --no-project --python 3.10 python -m compileall -q -x '(^|/)(\.venv|node_modules|build|dist)/' . + uv run --no-sync python scripts/check_changelog.py --skip-tags + uv build + uv run --no-sync python scripts/verify_distribution.py dist/* + uv run --no-sync python scripts/check_source_boundary.py --require-dist + - name: Privacy lint and release contract + if: needs.scope.outputs.privacy == 'true' + working-directory: packages/privacy + env: + PYTHONPYCACHEPREFIX: ${{ runner.temp }}/pycache-privacy + run: | + set -euo pipefail + uv python install 3.12 + uv sync --locked --python 3.12 --extra dev + uv run --no-sync ruff check openadapt_privacy tests scripts + uv run --no-sync ruff check --isolated --select E9 --target-version py310 . + uv run --no-project --python 3.10 python -m compileall -q -x '(^|/)(\.venv|node_modules|build|dist)/' . + uv run --no-sync pytest tests/test_release_config.py -v + uv build + uv run --no-sync python scripts/check_source_boundary.py --require-dist + - name: Tray lint and release contract + if: needs.scope.outputs.tray == 'true' + working-directory: packages/tray + env: + PYTHONPYCACHEPREFIX: ${{ runner.temp }}/pycache-tray + run: | + set -euo pipefail + uv python install 3.12 + uv sync --locked --python 3.12 --extra dev + uv run --no-sync ruff check . + uv run --no-sync ruff check --isolated --select E9 --target-version py310 . + uv run --no-project --python 3.10 python -m compileall -q -x '(^|/)(\.venv|node_modules|build|dist)/' . + uv build + uv run --no-sync python scripts/check_release_consistency.py --require-dist + uv run --no-sync python scripts/check_source_boundary.py --require-dist packages-gate: name: packages-gate @@ -2139,20 +2083,17 @@ jobs: - capture-linux - capture-macos - capture-windows - - capture-contract - privacy - privacy-presidio - - privacy-contract - desktop-test - desktop-build - tray - - tray-contract - tray-desktop-ipc - program-graph - seal-view - install-weight - capture-core-record - - desktop-release-intent + - fast-checks # Always runs, so the required check reports on every event, drafts too. if: always() runs-on: ubuntu-latest @@ -2197,19 +2138,16 @@ jobs: "capture-linux": "capture", "capture-macos": "capture", "capture-windows": "capture", - "capture-contract": "capture", "capture-core-record": "capture", "privacy": "privacy", "privacy-presidio": "privacy", - "privacy-contract": "privacy", "desktop-test": "desktop", "desktop-build": "desktop", - "desktop-release-intent": "desktop", "tray": "tray", - "tray-contract": "tray", "tray-desktop-ipc": "tray", "program-graph": "program_graph", "install-weight": "weight", + "fast-checks": "fast_checks", } # Post-merge tier only: skipped on a pull request and in the merge # queue; required on a push to main and on dispatch. @@ -2222,8 +2160,10 @@ jobs: # Skipped in the merge queue only: the pull request already passed # it on its merge with main (packages-gate is required there). not_in_queue = {"flow-unit"} + # PR and push-to-main only: skipped in merge queue and nightly runs. + pr_or_push_only = {"flow-default-at-rest"} # PR tier only: checks a pull request's own diff. - pr_only = {"desktop-release-intent", "flow-default-at-rest"} + pr_only = set() scope = needs["scope"] outputs = scope.get("outputs", {}) bad = {} @@ -2242,6 +2182,7 @@ jobs: off_tier = ( ((pr_tier or queue_tier) and name in post_merge_only) or (queue_tier and name in not_in_queue) + or ((not pr_tier and event != "push") and name in pr_or_push_only) or (not pr_tier and name in pr_only) ) if result == "skipped" and selected and not off_tier: diff --git a/.github/workflows/platform-manifest.yml b/.github/workflows/platform-manifest.yml index 6e8416529e..395b6479fb 100644 --- a/.github/workflows/platform-manifest.yml +++ b/.github/workflows/platform-manifest.yml @@ -93,20 +93,26 @@ jobs: echo "run=$run" | tee -a "$GITHUB_OUTPUT" - name: Set up Python - if: steps.scope.outputs.run == 'true' uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 with: python-version: '3.12' - name: Install uv - if: steps.scope.outputs.run == 'true' uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 with: enable-cache: true cache-dependency-glob: .github/ci-tools/uv.lock - # Cheapest decisive check first: structure, signature honesty, and - # repo agreement need no network and cannot be flaky. + # Run the offline source-boundary check BEFORE networked manifest checks + # so remote manifest drift can never mask a source-boundary violation. + # The guard reads its rules from source-policy.public.json (rendered from + # the canonical private manifest) and fails closed when that file is + # missing or incomplete. Stdlib only: no dependency install. + - name: Check open-core source boundary + run: python scripts/check_source_boundary.py + + # Cheapest decisive manifest check first: structure, signature honesty, + # and repo agreement need no network and cannot be flaky. - name: Validate platform manifest structure (offline) if: steps.scope.outputs.run == 'true' run: python scripts/validate_platform_manifest.py --offline @@ -118,16 +124,20 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: python scripts/validate_platform_manifest.py - - name: Prove the drift guard fails when it should + - name: Prove the manifest drift and source boundary guards fail when they should # The daily/dispatched production check is intentionally stdlib-only. - # This characterization suite belongs on source changes, not every - # remote drift probe, so scheduled checks stay fast and network-light. - if: steps.scope.outputs.run == 'true' && (github.event_name == 'pull_request' || github.event_name == 'push') + # Characterization suites belong on PR/push source changes so scheduled + # checks stay fast and network-light, sharing one VM and one install. + if: github.event_name == 'pull_request' || github.event_name == 'push' + env: + RUN_MANIFEST_TESTS: ${{ steps.scope.outputs.run }} run: | python scripts/ci/locked_install.py --lock .github/ci-tools:test - python -m pytest \ - tests/test_platform_manifest_drift.py \ - tests/test_platform_version_display.py -q + test_files=(tests/test_source_boundary.py) + if [ "$RUN_MANIFEST_TESTS" = "true" ]; then + test_files+=(tests/test_platform_manifest_drift.py tests/test_platform_version_display.py) + fi + python -m pytest "${test_files[@]}" -q report-manifest-drift: # A red scheduled run in a repository nobody has open is not a signal. @@ -161,35 +171,3 @@ jobs: else gh issue create --repo "${{ github.repository }}" --title "$TITLE" --body "$BODY" fi - - check-source-boundary: - if: github.event.pull_request.draft != true - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - - name: Set up Python - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 - with: - python-version: '3.12' - - - name: Install uv - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 - with: - enable-cache: true - cache-dependency-glob: .github/ci-tools/uv.lock - - # The guard reads its rules from source-policy.public.json (rendered from - # the canonical private manifest) and fails closed when that file is - # missing or incomplete. Stdlib only: no dependency install. - - name: Check open-core source boundary - run: python scripts/check_source_boundary.py - - # Prove the guard still blocks what it blocked before the rules moved out - # of the script, and that it fails closed without them. - - name: Prove the boundary guard fails when it should - if: github.event_name == 'pull_request' || github.event_name == 'push' - run: | - python scripts/ci/locked_install.py --lock .github/ci-tools:test - python -m pytest tests/test_source_boundary.py -q diff --git a/.github/workflows/protected-safety-review.yml b/.github/workflows/protected-safety-review.yml index 6cf4038d87..4ccfaafea7 100644 --- a/.github/workflows/protected-safety-review.yml +++ b/.github/workflows/protected-safety-review.yml @@ -13,8 +13,8 @@ on: branches: [main] concurrency: - group: protected-safety-review-${{ github.event.issue.number || github.event.pull_request.number || github.event.merge_group.head_sha }} - cancel-in-progress: true + group: protected-safety-review-${{ github.event.pull_request.number || github.event.issue.number || github.event.merge_group.head_sha || github.ref }} + cancel-in-progress: false permissions: contents: read diff --git a/packages/desktop/CLAUDE.md b/packages/desktop/CLAUDE.md index a38da3b3b2..ebea9875f9 100644 --- a/packages/desktop/CLAUDE.md +++ b/packages/desktop/CLAUDE.md @@ -26,7 +26,7 @@ perf: short description -> patch bump ### Releasing A pull request with a `feat`, `fix` or `perf` commit must bump the version, or -the `desktop release intent` check fails. Run +the `Desktop release intent` step (in `fast-checks`) fails. Run `python scripts/prepare_release.py` in `packages/desktop`, review the new `CHANGELOG.md` section, and commit. After merge, once Packages passes on main, `desktop-release.yml` builds the wheel, the sdist and every installer, and diff --git a/packages/desktop/RELEASES.md b/packages/desktop/RELEASES.md index 62a2f374bb..930bf67b96 100644 --- a/packages/desktop/RELEASES.md +++ b/packages/desktop/RELEASES.md @@ -13,7 +13,7 @@ launcher's. `--version X.Y.Z`). It sets `pyproject.toml`, `openadapt_desktop/__init__.py`, `uv.lock` and the five native installer version files, and writes a dated `CHANGELOG.md` section from the conventional commits since the last version. -2. The `desktop release intent` check fails a pull request with a `feat`, `fix` +2. The `Desktop release intent` check (run inside `fast-checks`) fails a pull request with a `feat`, `fix` or `perf` commit under `packages/desktop` that keeps the version, and prints the command above. It also requires every version source, native included, to carry the one version. diff --git a/tests/test_ci_efficiency_gating.py b/tests/test_ci_efficiency_gating.py index c04e0f627b..5bcc9ade60 100644 --- a/tests/test_ci_efficiency_gating.py +++ b/tests/test_ci_efficiency_gating.py @@ -25,7 +25,9 @@ def _triggers(workflow: dict) -> dict: def _run_classifier( - changed_files: list[str], event_name: str = "pull_request", tmp_path: Path | None = None + changed_files: list[str], + event_name: str = "pull_request", + tmp_path: Path | None = None, ) -> dict[str, str]: """Run the actual `Classify the change` bash step with `git diff` stubbed.""" classify_step = next( @@ -82,7 +84,9 @@ def test_packages_workflow_pins_every_action_to_40_char_sha() -> None: for ref in uses: if ref.startswith("./"): continue - assert re.search(r"@[0-9a-f]{40}$", ref), f"unpinned action in {name}: {ref}" + assert re.search(r"@[0-9a-f]{40}$", ref), ( + f"unpinned action in {name}: {ref}" + ) def test_packages_workflow_enables_loadscope_and_caches() -> None: @@ -95,7 +99,8 @@ def test_packages_workflow_enables_loadscope_and_caches() -> None: unit_enc = next( s for s in jobs["flow-unit"]["steps"] - if s.get("name") == "Rollback, checkpoint and key tests under the default (encrypted) mode" + if s.get("name") + == "Rollback, checkpoint and key tests under the default (encrypted) mode" ) assert "pytest -n logical --dist loadscope" in unit_enc["run"] @@ -107,7 +112,9 @@ def test_packages_workflow_enables_loadscope_and_caches() -> None: assert "pytest -n logical --dist loadscope" in at_rest_test["run"] onprem_uv = next( - s for s in jobs["flow-onprem-offline"]["steps"] if "setup-uv@" in s.get("uses", "") + s + for s in jobs["flow-onprem-offline"]["steps"] + if "setup-uv@" in s.get("uses", "") ) assert onprem_uv["with"]["enable-cache"] is True @@ -118,46 +125,140 @@ def test_packages_workflow_enables_loadscope_and_caches() -> None: @pytest.mark.parametrize( - ("changed_files", "expect_flow", "expect_code"), + ("changed_files", "expect_flow", "expect_at_rest", "expect_code"), [ - # #2423-style encryption/storage/runtime/compiler/test/lock paths MUST select - (["packages/flow/openadapt_flow/crypto.py"], "true", "true"), - (["packages/flow/openadapt_flow/stream_aead.py"], "true", "true"), - (["packages/flow/openadapt_flow/key_rotation.py"], "true", "true"), - (["packages/flow/openadapt_flow/retention.py"], "true", "true"), - (["packages/flow/openadapt_flow/compiler/distill.py"], "true", "true"), - (["packages/flow/tests/conftest.py"], "true", "true"), - (["packages/flow/uv.lock"], "true", "true"), - (["packages/types/openadapt_types/models.py"], "true", "true"), - (["packages/capture/openadapt_capture/recorder.py"], "true", "true"), - ([".github/workflows/packages.yml"], "true", "true"), - # Prose-only Flow PRs skip the heavy encrypted/on-prem/framework jobs - (["packages/flow/docs/LIMITS.md"], "true", "false"), - (["packages/flow/README.md", "packages/flow/CHANGELOG.md"], "true", "false"), - (["packages/flow/docs/commands/run.md"], "true", "false"), + # Fail-closed deny-list: all Flow/Capture/Types code selects flow_at_rest=true + (["packages/flow/openadapt_flow/crypto.py"], "true", "true", "true"), + (["packages/flow/openadapt_flow/stream_aead.py"], "true", "true", "true"), + (["packages/flow/openadapt_flow/key_rotation.py"], "true", "true", "true"), + (["packages/flow/openadapt_flow/sealed_set.py"], "true", "true", "true"), + (["packages/flow/openadapt_flow/retention.py"], "true", "true", "true"), + ( + ["packages/flow/openadapt_flow/runtime/durable/resume.py"], + "true", + "true", + "true", + ), + (["packages/flow/openadapt_flow/api.py"], "true", "true", "true"), + (["packages/flow/openadapt_flow/cli_tasks.py"], "true", "true", "true"), + (["packages/flow/openadapt_flow/compiler/distill.py"], "true", "true", "true"), + ( + ["packages/flow/chrome_extension/native_host/openadapt_extension_host.py"], + "true", + "true", + "true", + ), + ( + ["packages/flow/tests/test_chrome_extension_cws.py"], + "true", + "true", + "true", + ), + (["packages/capture/openadapt_capture/recorder.py"], "true", "true", "true"), + (["packages/flow/tests/conftest.py"], "true", "true", "true"), + (["packages/flow/uv.lock"], "true", "true", "true"), + (["packages/types/openadapt_types/models.py"], "true", "true", "true"), + ([".github/workflows/packages.yml"], "true", "true", "true"), + # Provably non-Python docs/assets/data skip the duplicate 4-shard flow-default-at-rest run + (["packages/flow/chrome_extension/content.js"], "true", "false", "true"), + ( + ["packages/flow/benchmark/canvas_ladder/results.json"], + "true", + "false", + "true", + ), + (["packages/flow/paper/main.tex"], "true", "false", "true"), + # Prose-only Flow PRs skip all heavy sub-package jobs + (["packages/flow/docs/LIMITS.md"], "true", "false", "false"), + ( + ["packages/flow/README.md", "packages/flow/CHANGELOG.md"], + "true", + "false", + "false", + ), + (["packages/flow/docs/commands/run.md"], "true", "false", "false"), # Mixed prose + code MUST select ( ["packages/flow/docs/LIMITS.md", "packages/flow/openadapt_flow/api.py"], "true", "true", + "true", ), - # Unrelated package PR selects neither - (["packages/tray/README.md"], "false", "false"), + # Unrelated package PR selects none + (["packages/tray/README.md"], "false", "false", "false"), ], ) def test_classifier_selects_all_flow_code_and_skips_prose_only_prs( tmp_path: Path, changed_files: list[str], expect_flow: str, + expect_at_rest: str, expect_code: str, ) -> None: out = _run_classifier(changed_files, event_name="pull_request", tmp_path=tmp_path) assert out["flow"] == expect_flow - assert out["flow_at_rest"] == expect_code + assert out["flow_at_rest"] == expect_at_rest assert out["flow_onprem"] == expect_code assert out["flow_agent_frameworks"] == expect_code +def test_every_at_rest_importer_selects_flow_at_rest(tmp_path: Path) -> None: + """AST proof: zero .py files under packages/{flow,capture} are excluded and 100% of at-rest importers select flow_at_rest=true.""" + import ast + + classify_step = next( + s + for s in _load("packages.yml")["jobs"]["scope"]["steps"] + if s.get("name") == "Classify the change" + ) + m = re.search(r"at_rest_excluded='([^']+)'", classify_step["run"]) + assert m is not None + excluded_re = re.compile(m.group(1)) + + sensitive = {"at_rest", "sealed_set", "crypto", "stream_aead", "key_hierarchy"} + importers: list[str] = [] + excluded_py: list[str] = [] + for base in (ROOT / "packages/flow", ROOT / "packages/capture"): + for py_file in sorted(base.rglob("*.py")): + rel = py_file.relative_to(ROOT).as_posix() + if "/.venv/" in rel or "/build/" in rel or "/dist/" in rel: + continue + if excluded_re.search(rel): + excluded_py.append(rel) + try: + tree = ast.parse(py_file.read_text(encoding="utf-8")) + except SyntaxError: + continue + hits = False + for node in ast.walk(tree): + if isinstance(node, ast.ImportFrom): + mod_parts = set((node.module or "").split(".")) + alias_names = {a.name for a in node.names} + if mod_parts & sensitive or alias_names & sensitive: + hits = True + break + elif isinstance(node, ast.Import): + for alias in node.names: + if set(alias.name.split(".")) & sensitive: + hits = True + break + if hits: + break + if hits: + importers.append(rel) + + assert excluded_py == [], ( + f"Python files must not be excluded by flow_at_rest deny-list: {excluded_py}" + ) + assert importers, "expected at least one at-rest/sealing importer" + missed = [p for p in importers if excluded_re.search(p)] + assert missed == [], f"at-rest importers excluded by deny-list: {missed}" + # Spot-check through the full bash classifier on the first, middle, and last importer + for sample in {importers[0], importers[len(importers) // 2], importers[-1]}: + out = _run_classifier([sample], event_name="pull_request", tmp_path=tmp_path) + assert out["flow_at_rest"] == "true", f"{sample} did not select flow_at_rest" + + @pytest.mark.parametrize( ("event", "outputs", "job_results", "expected"), [ @@ -251,7 +352,25 @@ def test_classifier_selects_all_flow_code_and_skips_prose_only_prs( }, 0, ), - # Push to main skips flow-default-at-rest cleanly (pr_only, as on main) + # Push to main requires flow-default-at-rest when flow_at_rest=true + ( + "push", + { + "flow": "true", + "flow_at_rest": "true", + "flow_onprem": "true", + "flow_agent_frameworks": "true", + }, + { + "flow-unit": "success", + "flow-critical": "success", + "flow-default-at-rest": "success", + "flow-onprem-offline": "success", + "flow-agent-frameworks": "success", + }, + 0, + ), + # Push to main fails gate if flow-default-at-rest was skipped when selected ( "push", { @@ -267,6 +386,24 @@ def test_classifier_selects_all_flow_code_and_skips_prose_only_prs( "flow-onprem-offline": "success", "flow-agent-frameworks": "success", }, + 1, + ), + # Scheduled nightly run skips flow-default-at-rest cleanly (not_in_nightly) + ( + "schedule", + { + "flow": "true", + "flow_at_rest": "true", + "flow_onprem": "true", + "flow_agent_frameworks": "true", + }, + { + "flow-unit": "success", + "flow-critical": "success", + "flow-default-at-rest": "skipped", + "flow-onprem-offline": "success", + "flow-agent-frameworks": "success", + }, 0, ), ], @@ -295,3 +432,89 @@ def test_packages_gate_enforces_sub_package_flow_selection( check=False, ) assert result.returncode == expected, result.stdout + result.stderr + + +def test_desktop_replay_link_check_and_protected_safety_phase2_invariants() -> None: + desktop_replay = _load("desktop-replay.yml") + dr_paths = _triggers(desktop_replay)["pull_request"]["paths"] + assert "packages/flow/openadapt_flow/**" not in dr_paths + assert "packages/flow/openadapt_flow/backends/**" in dr_paths + assert "packages/flow/openadapt_flow/runtime/**" in dr_paths + + link_check = _load("link-check.yml") + for event in ("pull_request", "push"): + lc_paths = _triggers(link_check)[event]["paths"] + assert "!**/CHANGELOG.md" in lc_paths + assert "!.github/**/*.md" in lc_paths + assert "!legacy/**/*.md" in lc_paths + + psr = _load("protected-safety-review.yml") + conc = psr["concurrency"] + assert "github.event.pull_request.number" in conc["group"] + assert "github.event.issue.number" in conc["group"] + assert conc["cancel-in-progress"] is False + + pkg_jobs = _load("packages.yml")["jobs"] + assert "fast-checks" in pkg_jobs + for removed in ( + "capture-contract", + "privacy-contract", + "tray-contract", + "desktop-release-intent", + ): + assert removed not in pkg_jobs + assert "fast-checks" in pkg_jobs["packages-gate"]["needs"] + + pm_jobs = _load("platform-manifest.yml")["jobs"] + assert "check-source-boundary" not in pm_jobs + step_names = [s.get("name") for s in pm_jobs["validate-platform-manifest"]["steps"]] + assert "Check open-core source boundary" in step_names + assert step_names.index("Check open-core source boundary") < step_names.index( + "Validate platform manifest against published artifacts" + ) + + # Safety-core modules stay covered by desktop-replay.yml + for safety_mod in ( + "packages/flow/openadapt_flow/identity_signals.py", + "packages/flow/openadapt_flow/verify.py", + "packages/flow/openadapt_flow/verify_run.py", + "packages/flow/openadapt_flow/record_check_identity.py", + ): + assert safety_mod in dr_paths + + +def test_fast_checks_classifier_selection(tmp_path: Path) -> None: + assert ( + _run_classifier(["packages/capture/README.md"], "pull_request", tmp_path)[ + "fast_checks" + ] + == "true" + ) + assert ( + _run_classifier(["packages/privacy/README.md"], "pull_request", tmp_path)[ + "fast_checks" + ] + == "true" + ) + assert ( + _run_classifier(["packages/tray/README.md"], "pull_request", tmp_path)[ + "fast_checks" + ] + == "true" + ) + assert ( + _run_classifier(["packages/desktop/README.md"], "pull_request", tmp_path)[ + "fast_checks" + ] + == "true" + ) + assert ( + _run_classifier( + ["packages/flow/openadapt_flow/api.py"], "pull_request", tmp_path + )["fast_checks"] + == "false" + ) + assert ( + _run_classifier(["README.md"], "pull_request", tmp_path)["fast_checks"] + == "false" + )