diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 6cf4a3b54..6a6339287 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -98,8 +98,9 @@ # execution under this model. Still open: a beads-only RBE_INSTANCE. The farm # refuses client action-cache writes (only its workers write; rbe-west D2). # In pr.yml's run the bd artifact is bazel-ci-build-artifacts, so it cannot -# collide with the build-artifacts job's ci-build-artifacts; pr.yml's -# package gates consume it where build-artifacts stands down (D2 step 3). +# collide with the build-artifacts job's ci-build-artifacts. F3: the package +# gates no longer consume this artifact (they build their own bd); it is +# kept for the F3.5.3 SHA256SUMS comparison and for debugging. # # Runner cache: one entry per (.bazelversion, MODULE.bazel.lock) pair, about # 2 GB (Bazel's content-addressable --repository_cache, re-hashed on every @@ -187,6 +188,19 @@ on: type: string required: false default: "off" + # "on" (pr.yml only) runs package-mcp and package-npm in this call, + # which waits on nothing but the rbe job (F3: the legacy pr.yml jobs + # those gates used to need: detect-package-gates, build-artifacts, + # bazel-coverage, and the whole bazel call). bazel-farm.yml, nightly.yml + # and direct runs (push, dispatch) keep the default "off": main.yml + # keeps its own package jobs, and a fork-farm run has no bd artifact + # consumer waiting on these. + package-gates: + description: > + "on" (pr.yml only) runs the MCP and npm package gates in this call. + type: string + required: false + default: "off" # Only what the rbe job and setup-bazel need; callers pass them # explicitly. None is required: fork and Dependabot runs have none. secrets: @@ -229,6 +243,12 @@ on: bazel-server-storage: description: "bazel-server-storage's job.status" value: ${{ jobs.bazel-server-storage.outputs.result }} + package-mcp: + description: "package-mcp's job.status (empty unless package-gates is 'on')" + value: ${{ jobs.package-mcp.outputs.result }} + package-npm: + description: "package-npm's job.status (empty unless package-gates is 'on')" + value: ${{ jobs.package-npm.outputs.result }} # Main runs always finish (they may save the runner cache); PR runs (called # from pr.yml or bazel-farm.yml, whose own groups cancel the calling run too) @@ -255,7 +275,12 @@ jobs: # runs read vars but get no secrets, so they come out cache, not remote. rbe: name: execution mode - runs-on: ubuntu-latest + # Same-repo PRs (and merge_group/push/dispatch/schedule runs, which are + # never forks) get the org's Blacksmith pool; a pull_request_target farm + # run and any fork or Dependabot PR stay on GitHub-hosted runners. This + # job reads no repository code and holds no secret value (see below), so + # Blacksmith sees nothing sensitive either way. + runs-on: ${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }} timeout-minutes: 5 outputs: enabled: ${{ steps.decide.outputs.enabled }} @@ -406,10 +431,11 @@ jobs: # pr.yml's build-artifacts job, built by Bazel: the same artifact name # and layout (bd-linux-gms-pure, SHA256SUMS, build-manifest.txt). Where - # build-artifacts stands down (D2 step 3), pr.yml's package gates take - # it; its other consumers (PR Core, domain+uow) stand down there too. - # The script documents which binary and how it differs from `go - # build`'s. + # build-artifacts stands down (D2 step 3), its other consumers (PR + # Core, domain+uow) stand down there too. F3: the package gates build + # their own bd and no longer consume this artifact; it is kept for the + # F3.5.3 SHA256SUMS comparison and for debugging. The script documents + # which binary and how it differs from `go build`'s. - name: Package bd (ci-build-artifacts layout) id: bd-artifact if: ${{ always() && steps.test.outcome != 'skipped' }} @@ -1214,3 +1240,244 @@ jobs: env: JOB_STATUS: ${{ job.status }} run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT" + + # F3: moved here from pr.yml so the gate depends on nothing but the rbe + # job's decision (not detect-package-gates, build-artifacts, bazel-coverage + # or the whole bazel call). Only pr.yml opts in (package-gates: "on"); + # bazel-farm.yml and nightly.yml keep the default "off" and this job does + # not run for them. Same-repo PRs get a Bazel-built bd (no --config=ci: + # only test:ci is defined in .bazelrc, so bazel build //cmd/bd:bd_for_tests + # is run directly); forks, Dependabot and rbe-off/skip runs fall back to + # `go build`, same as package-mcp.sh's own prepare_bd_binary() does when + # BEADS_TEST_BD_BINARY is unset. + package-mcp: + name: Package Gate (MCP) + needs: rbe + # 4 vCPU on purpose: pytest-xdist -n 8 measured ~2.7-3x on 4 CPUs + # (tools/f3 timing, 2026-10), well past 2 vCPU's ceiling. + runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }} + if: ${{ inputs.package-gates == 'on' }} + timeout-minutes: 30 + outputs: + result: ${{ steps.result.outputs.result }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.checkout-sha }} + fetch-depth: 0 + persist-credentials: false + allow-unsafe-pr-checkout: ${{ inputs.fork-farm == 'authorized' && github.event_name == 'pull_request_target' }} + + - name: Decide applicability + id: detect + env: + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PUSH_BEFORE_SHA: ${{ github.event.before }} + PUSH_AFTER_SHA: ${{ github.sha }} + run: ./scripts/ci/detect-package-gates.sh + + - name: Set up Bazel + id: bazel + if: ${{ steps.detect.outputs.mcp_package == 'true' && needs.rbe.outputs.enabled == 'true' }} + uses: ./.github/actions/setup-bazel + env: + BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }} + RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }} + RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }} + RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }} + RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }} + BAZEL_FORK_CACHE: ${{ needs.rbe.outputs.mode == 'cache' && 'true' || '' }} + + # No --config=ci: only test:ci is defined in .bazelrc, and `bazel + # build --config=foo` fails when only test:foo exists. The explicit + # --@rules_go//go/config:race matches test:ci's top-level build + # setting (test:ci -> test:prcore), so bd_for_tests' race="off" + # transition lands in the same k8-fastbuild-ST-... output directory + # and action-cache key `bazel test --config=ci` already populated, + # instead of plain k8-fastbuild's; race itself still builds a non-race + # bd (verified with cquery: both configs cquery to the identical + # bazel-out/k8-fastbuild-ST-.../bin/cmd/bd/bd_for_tests/bd path). + - name: bazel build //cmd/bd:bd_for_tests + if: ${{ steps.detect.outputs.mcp_package == 'true' && needs.rbe.outputs.enabled == 'true' }} + run: bazel build --@rules_go//go/config:race //cmd/bd:bd_for_tests --remote_download_regex='.*/bin/cmd/bd/bd_for_tests/bd$' + + - name: Package the Bazel-built bd + if: ${{ steps.detect.outputs.mcp_package == 'true' && needs.rbe.outputs.enabled == 'true' }} + run: | + ./scripts/ci/package-bazel-bd.sh "$RUNNER_TEMP/bd-artifacts" + echo "BEADS_TEST_BD_BINARY=$RUNNER_TEMP/bd-artifacts/bd-linux-gms-pure" >> "$GITHUB_ENV" + # Defense in depth: nothing after this step needs the Bazel server + # or its RBE client key (uv sync and pytest run PR-controlled + # code). Shutting down also frees the JVM's memory for the 8 + # xdist workers that follow on this 4 vCPU runner. + bazel shutdown + rm -rf "$RUNNER_TEMP/bazel-ci-secret" + + - name: Set up Go + id: setup-go + if: ${{ steps.detect.outputs.mcp_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: 'go.mod' + cache: false + + - name: Restore Go module cache + if: ${{ steps.detect.outputs.mcp_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/go/pkg/mod + key: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum') }} + restore-keys: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}- + + - name: Verify Go modules + if: ${{ steps.detect.outputs.mcp_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + run: go mod verify + + - name: Restore non-race Go build cache + if: ${{ steps.detect.outputs.mcp_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/go-cache/non-race + key: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-non-race-${{ github.sha }} + restore-keys: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-non-race- + + - name: Set up Python + if: ${{ steps.detect.outputs.mcp_package == 'true' }} + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: '3.14' + + - name: Install uv + if: ${{ steps.detect.outputs.mcp_package == 'true' }} + run: python -m pip install uv==0.11.16 + + - name: Run MCP package gate + if: ${{ steps.detect.outputs.mcp_package == 'true' }} + env: + GOCACHE: ${{ runner.temp }}/go-cache/non-race + run: make ci-package-mcp + + # Last step: the job's result as a workflow_call output for pr.yml's + # ci-gate. always() runs it after a failure, a timeout or a + # cancellation too; package-gates == 'on' is the only skip condition + # (the job itself), so PACKAGE_MCP is never "skipped" on pr.yml. + - name: Record job result + id: result + if: ${{ always() }} + env: + JOB_STATUS: ${{ job.status }} + run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT" + + # F3: npm's twin of package-mcp above. Structurally identical apart from + # the language setup (Node instead of Python/uv) and the `make` target. + package-npm: + name: Package Gate (npm) + needs: rbe + runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }} + if: ${{ inputs.package-gates == 'on' }} + timeout-minutes: 30 + outputs: + result: ${{ steps.result.outputs.result }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.checkout-sha }} + fetch-depth: 0 + persist-credentials: false + allow-unsafe-pr-checkout: ${{ inputs.fork-farm == 'authorized' && github.event_name == 'pull_request_target' }} + + - name: Decide applicability + id: detect + env: + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PUSH_BEFORE_SHA: ${{ github.event.before }} + PUSH_AFTER_SHA: ${{ github.sha }} + run: ./scripts/ci/detect-package-gates.sh + + - name: Set up Bazel + id: bazel + if: ${{ steps.detect.outputs.npm_package == 'true' && needs.rbe.outputs.enabled == 'true' }} + uses: ./.github/actions/setup-bazel + env: + BAZEL_REMOTE_EXECUTOR: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_WEST_EXECUTOR || '' }} + RBE_TLS_CERT: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CERT || '' }} + RBE_TLS_KEY: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_KEY || '' }} + RBE_TLS_CA: ${{ needs.rbe.outputs.enabled == 'true' && secrets.RBE_TLS_CA || '' }} + RBE_INSTANCE: ${{ needs.rbe.outputs.enabled == 'true' && 'oss' || '' }} + BAZEL_FORK_CACHE: ${{ needs.rbe.outputs.mode == 'cache' && 'true' || '' }} + + # No --config=ci: only test:ci is defined in .bazelrc, and `bazel + # build --config=foo` fails when only test:foo exists. The explicit + # --@rules_go//go/config:race matches test:ci's top-level build + # setting (test:ci -> test:prcore), so bd_for_tests' race="off" + # transition lands in the same k8-fastbuild-ST-... output directory + # and action-cache key `bazel test --config=ci` already populated, + # instead of plain k8-fastbuild's; race itself still builds a non-race + # bd (verified with cquery: both configs cquery to the identical + # bazel-out/k8-fastbuild-ST-.../bin/cmd/bd/bd_for_tests/bd path). + - name: bazel build //cmd/bd:bd_for_tests + if: ${{ steps.detect.outputs.npm_package == 'true' && needs.rbe.outputs.enabled == 'true' }} + run: bazel build --@rules_go//go/config:race //cmd/bd:bd_for_tests --remote_download_regex='.*/bin/cmd/bd/bd_for_tests/bd$' + + - name: Package the Bazel-built bd + if: ${{ steps.detect.outputs.npm_package == 'true' && needs.rbe.outputs.enabled == 'true' }} + run: | + ./scripts/ci/package-bazel-bd.sh "$RUNNER_TEMP/bd-artifacts" + echo "BEADS_TEST_BD_BINARY=$RUNNER_TEMP/bd-artifacts/bd-linux-gms-pure" >> "$GITHUB_ENV" + # Defense in depth: nothing after this step needs the Bazel server + # or its RBE client key (npm install runs PR-controlled code). + bazel shutdown + rm -rf "$RUNNER_TEMP/bazel-ci-secret" + + - name: Set up Go + id: setup-go + if: ${{ steps.detect.outputs.npm_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: 'go.mod' + cache: false + + - name: Restore Go module cache + if: ${{ steps.detect.outputs.npm_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/go/pkg/mod + key: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum') }} + restore-keys: beads-go-mod-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}- + + - name: Verify Go modules + if: ${{ steps.detect.outputs.npm_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + run: go mod verify + + - name: Restore non-race Go build cache + if: ${{ steps.detect.outputs.npm_package == 'true' && needs.rbe.outputs.enabled != 'true' }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/go-cache/non-race + key: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-non-race-${{ github.sha }} + restore-keys: beads-go-build-v2-${{ runner.os }}-${{ runner.arch }}-go-${{ steps.setup-go.outputs.go-version }}-base-gms_pure_go-non-race- + + - name: Set up Node.js + if: ${{ steps.detect.outputs.npm_package == 'true' }} + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6 + with: + node-version: '24' + + - name: Run npm package gate + if: ${{ steps.detect.outputs.npm_package == 'true' }} + env: + GOCACHE: ${{ runner.temp }}/go-cache/non-race + run: make ci-package-npm + + # Last step: the job's result as a workflow_call output for pr.yml's + # ci-gate. always() runs it after a failure, a timeout or a + # cancellation too; package-gates == 'on' is the only skip condition + # (the job itself), so PACKAGE_NPM is never "skipped" on pr.yml. + - name: Record job result + id: result + if: ${{ always() }} + env: + JOB_STATUS: ${{ job.status }} + run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/pr-risk.yml b/.github/workflows/pr-risk.yml index efc5ade93..f65b665d8 100644 --- a/.github/workflows/pr-risk.yml +++ b/.github/workflows/pr-risk.yml @@ -34,7 +34,14 @@ env: jobs: detect-ci-tier: name: Detect CI tier - runs-on: ubuntu-latest + # F3: same-repo PRs and merge_group get the org's Blacksmith pool; forks, + # Dependabot and any other event stay GitHub-hosted. This job restores no + # GitHub-saved cache. + runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }} + # F3: now on Blacksmith for same-repo PRs; a hang used to burn only the + # default 360 minutes of a free GitHub-hosted runner, now Blacksmith + # minutes too. + timeout-minutes: 10 outputs: full_embedded: ${{ steps.tier.outputs.full_embedded }} reason: ${{ steps.tier.outputs.reason }} @@ -88,7 +95,13 @@ jobs: # variable and runs no repository code. bazel-coverage: name: Bazel tier coverage - runs-on: ubuntu-latest + # F3: same-repo PRs and merge_group get the org's Blacksmith pool; forks, + # Dependabot and any other event stay GitHub-hosted. This job restores no + # GitHub-saved cache, so Blacksmith's inability to see one does not cost + # it anything. Must stay byte-identical to pr.yml's copy + # (TestPRRiskBazelCoverageJob) and to the TestSameRepoBlacksmithRunners + # pin. + runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }} timeout-minutes: 5 outputs: embedded: ${{ steps.decide.outputs.embedded }} @@ -555,7 +568,16 @@ jobs: ci-gate: name: PR Risk Gate / Required - runs-on: ubuntu-latest + # F3: same-repo PRs and merge_group get the org's Blacksmith pool; forks, + # Dependabot and any other event stay GitHub-hosted. This job restores no + # GitHub-saved cache. Must match the TestSameRepoBlacksmithRunners pin; + # the gate's NAME must never change (ruleset requires exactly "PR Risk + # Gate / Required"). + runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }} + # F3: now on Blacksmith for same-repo PRs; a hang used to burn only the + # default 360 minutes of a free GitHub-hosted runner, now Blacksmith + # minutes too. + timeout-minutes: 10 needs: - detect-ci-tier - bazel-coverage diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a6f3e55c8..219d46274 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -38,9 +38,10 @@ jobs: # D2 step 3: stands down where bazel-coverage says pr_lanes (same-repo, # non-Dependabot PRs while BAZEL_RETIRES_LEGACY_PR_LANES is "true"): its - # consumers then stand down too, or (the package gates) take bazel.yml's - # bazel-ci-build-artifacts, the same layout built by Bazel / - # test, which ci-gate then requires to have run remotely and passed. + # consumers then stand down too. F3: the package gates (package-mcp, + # package-npm) are no longer among those consumers - they moved into + # bazel.yml and build their own bd (Bazel-built on same-repo PRs, `go + # build` otherwise), needing only the call's rbe job. build-artifacts: name: Build Artifacts runs-on: ubuntu-latest @@ -733,154 +734,10 @@ jobs: fi echo "No .beads/issues.jsonl changes detected" - detect-package-gates: - name: Detect package gates - runs-on: ubuntu-latest - outputs: - mcp_package: ${{ steps.detect.outputs.mcp_package }} - npm_package: ${{ steps.detect.outputs.npm_package }} - reason: ${{ steps.detect.outputs.reason }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - with: - fetch-depth: 0 - - - name: Decide package gates - id: detect - env: - PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} - PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - PUSH_BEFORE_SHA: ${{ github.event.before }} - PUSH_AFTER_SHA: ${{ github.sha }} - run: ./scripts/ci/detect-package-gates.sh - - package-mcp: - name: Package Gate (MCP) - runs-on: ubuntu-latest - # D2 step 3: where bazel-coverage says pr_lanes, build-artifacts stands - # down and this gate takes the Bazel-built bd (bazel-ci-build-artifacts, - # uploaded by the bazel call's `test` lane), so it waits for the call. - needs: [detect-package-gates, build-artifacts, bazel-coverage, bazel] - if: ${{ !cancelled() && needs.detect-package-gates.result == 'success' && needs.bazel-coverage.result == 'success' && (needs.bazel-coverage.outputs.pr_lanes == 'true' || needs.build-artifacts.result == 'success') }} - steps: - - name: Check applicability - id: applicability - run: | - echo "run=${{ needs.detect-package-gates.outputs.mcp_package }}" >> "$GITHUB_OUTPUT" - if [[ "${{ needs.detect-package-gates.outputs.mcp_package }}" != "true" ]]; then - echo "MCP package gate is not applicable: ${{ needs.detect-package-gates.outputs.reason }}" - fi - - # D2 step 3: where build-artifacts stood down, the bd comes from the - # bazel call's `test` lane, which runs only in mode remote; say so - # instead of failing on a missing artifact (ci-gate is red then too, - # BAZEL_PR_LANES_RETIRED). - - name: Check the Bazel-built bd exists - if: steps.applicability.outputs.run == 'true' && needs.bazel-coverage.outputs.pr_lanes == 'true' - env: - BAZEL_RBE_MODE: ${{ needs.bazel.outputs.rbe-mode }} - run: | - if [[ "$BAZEL_RBE_MODE" != "remote" ]]; then - echo "::error::Build Artifacts stood down for Bazel / test (BAZEL_RETIRES_LEGACY_PR_LANES), but the Bazel call ran in mode '${BAZEL_RBE_MODE:-none}', so no bd was built for this gate. See BAZEL_PR_LANES_RETIRED in CI Gate / Required." - exit 1 - fi - - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - if: steps.applicability.outputs.run == 'true' - - - name: Set up Python - if: steps.applicability.outputs.run == 'true' - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: '3.14' - - - name: Install uv - if: steps.applicability.outputs.run == 'true' - run: python -m pip install uv==0.11.16 - - - name: Download build artifacts - if: steps.applicability.outputs.run == 'true' - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: ${{ needs.bazel-coverage.outputs.pr_lanes == 'true' && 'bazel-ci-build-artifacts' || 'ci-build-artifacts' }} - path: ci-build-artifacts - - - name: Verify build artifacts - if: steps.applicability.outputs.run == 'true' - run: | - set -euo pipefail - cd ci-build-artifacts - sha256sum -c SHA256SUMS - chmod +x bd-linux-gms-pure - - - name: Run MCP package gate - if: steps.applicability.outputs.run == 'true' - env: - BEADS_TEST_BD_BINARY: ${{ github.workspace }}/ci-build-artifacts/bd-linux-gms-pure - run: make ci-package-mcp - - package-npm: - name: Package Gate (npm) - runs-on: ubuntu-latest - # D2 step 3: where bazel-coverage says pr_lanes, build-artifacts stands - # down and this gate takes the Bazel-built bd (bazel-ci-build-artifacts, - # uploaded by the bazel call's `test` lane), so it waits for the call. - needs: [detect-package-gates, build-artifacts, bazel-coverage, bazel] - if: ${{ !cancelled() && needs.detect-package-gates.result == 'success' && needs.bazel-coverage.result == 'success' && (needs.bazel-coverage.outputs.pr_lanes == 'true' || needs.build-artifacts.result == 'success') }} - steps: - - name: Check applicability - id: applicability - run: | - echo "run=${{ needs.detect-package-gates.outputs.npm_package }}" >> "$GITHUB_OUTPUT" - if [[ "${{ needs.detect-package-gates.outputs.npm_package }}" != "true" ]]; then - echo "npm package gate is not applicable: ${{ needs.detect-package-gates.outputs.reason }}" - fi - - # D2 step 3: where build-artifacts stood down, the bd comes from the - # bazel call's `test` lane, which runs only in mode remote; say so - # instead of failing on a missing artifact (ci-gate is red then too, - # BAZEL_PR_LANES_RETIRED). - - name: Check the Bazel-built bd exists - if: steps.applicability.outputs.run == 'true' && needs.bazel-coverage.outputs.pr_lanes == 'true' - env: - BAZEL_RBE_MODE: ${{ needs.bazel.outputs.rbe-mode }} - run: | - if [[ "$BAZEL_RBE_MODE" != "remote" ]]; then - echo "::error::Build Artifacts stood down for Bazel / test (BAZEL_RETIRES_LEGACY_PR_LANES), but the Bazel call ran in mode '${BAZEL_RBE_MODE:-none}', so no bd was built for this gate. See BAZEL_PR_LANES_RETIRED in CI Gate / Required." - exit 1 - fi - - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - if: steps.applicability.outputs.run == 'true' - - - name: Set up Node.js - if: steps.applicability.outputs.run == 'true' - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6 - with: - node-version: '24' - - - name: Download build artifacts - if: steps.applicability.outputs.run == 'true' - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: ${{ needs.bazel-coverage.outputs.pr_lanes == 'true' && 'bazel-ci-build-artifacts' || 'ci-build-artifacts' }} - path: ci-build-artifacts - - - name: Verify build artifacts - if: steps.applicability.outputs.run == 'true' - run: | - set -euo pipefail - cd ci-build-artifacts - sha256sum -c SHA256SUMS - chmod +x bd-linux-gms-pure - - - name: Run npm package gate - if: steps.applicability.outputs.run == 'true' - env: - BEADS_TEST_BD_BINARY: ${{ github.workspace }}/ci-build-artifacts/bd-linux-gms-pure - run: make ci-package-npm - - + # F3: package-mcp and package-npm (and the detect job that fed them) moved + # into bazel.yml, which pr.yml calls with package-gates: "on" below. They + # now depend on nothing but the rbe job's decision, so they no longer wait + # on build-artifacts, bazel-coverage or the rest of the bazel call. pr-policy-wrapper: name: PR Policy (wrapper timing) runs-on: ubuntu-latest @@ -1972,7 +1829,9 @@ jobs: # same-repo PRs run it remotely, fork and Dependabot PRs locally with the # read-only cache. Its bd artifact is renamed # (bazel-ci-build-artifacts) so it cannot collide with build-artifacts' - # upload; the package gates take it where build-artifacts stands down. + # upload. F3: the package gates build their own bd (via this call's rbe + # job) and do not consume this artifact; it is kept for the F3.5.3 + # SHA256SUMS comparison and for debugging. bazel: name: Bazel permissions: @@ -1986,6 +1845,9 @@ jobs: with: build-artifact-name: bazel-ci-build-artifacts integration: "on" + # F3: only pr.yml opts in; the package-mcp/package-npm jobs run inside + # this call, needing only its rbe job. + package-gates: "on" # D2: pr-risk.yml's bazel-coverage job, verbatim (policy-tested # identical). Where it says a tier is covered, PR Risk skips that tier's @@ -1995,7 +1857,13 @@ jobs: # lanes to have run remotely and passed in this run. bazel-coverage: name: Bazel tier coverage - runs-on: ubuntu-latest + # F3: same-repo PRs and merge_group get the org's Blacksmith pool; forks, + # Dependabot and any other event stay GitHub-hosted. This job restores no + # GitHub-saved cache, so Blacksmith's inability to see one does not cost + # it anything. Must stay byte-identical to pr-risk.yml's copy + # (TestPRRiskBazelCoverageJob) and to the TestSameRepoBlacksmithRunners + # pin. + runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }} timeout-minutes: 5 outputs: embedded: ${{ steps.decide.outputs.embedded }} @@ -2051,7 +1919,16 @@ jobs: ci-gate: name: CI Gate / Required - runs-on: ubuntu-latest + # F3: same-repo PRs and merge_group get the org's Blacksmith pool; forks, + # Dependabot and any other event stay GitHub-hosted. This job restores no + # GitHub-saved cache. Must match the TestSameRepoBlacksmithRunners pin; + # the gate's NAME must never change (ruleset requires exactly "CI Gate / + # Required"). + runs-on: ${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }} + # F3: now on Blacksmith for same-repo PRs; a hang used to burn only the + # default 360 minutes of a free GitHub-hosted runner, now Blacksmith + # minutes too. + timeout-minutes: 10 needs: - build-artifacts - check-build-tags @@ -2065,9 +1942,6 @@ jobs: - check-doc-freshness-platforms - pr-preflight-platforms - check-no-beads-changes - - detect-package-gates - - package-mcp - - package-npm - pr-policy-wrapper - pr-core-wrapper - scripts-go-checks @@ -2100,7 +1974,6 @@ jobs: CHECK_DOC_FRESHNESS_PLATFORMS PR_PREFLIGHT_PLATFORMS CHECK_NO_BEADS_CHANGES - DETECT_PACKAGE_GATES PACKAGE_MCP PACKAGE_NPM PR_POLICY_WRAPPER @@ -2137,9 +2010,12 @@ jobs: CHECK_DOC_FRESHNESS_PLATFORMS: ${{ needs.check-doc-freshness-platforms.result }} PR_PREFLIGHT_PLATFORMS: ${{ needs.pr-preflight-platforms.result }} CHECK_NO_BEADS_CHANGES: ${{ needs.check-no-beads-changes.result }} - DETECT_PACKAGE_GATES: ${{ needs.detect-package-gates.result }} - PACKAGE_MCP: ${{ needs.package-mcp.result }} - PACKAGE_NPM: ${{ needs.package-npm.result }} + # F3: package-mcp/package-npm now run inside the bazel call; their + # job.status surfaces as a call output exactly like the Bazel lanes + # below, never "skipped" on pr.yml (package-gates is always "on" + # here). + PACKAGE_MCP: ${{ needs.bazel.outputs.package-mcp || 'skipped' }} + PACKAGE_NPM: ${{ needs.bazel.outputs.package-npm || 'skipped' }} PR_POLICY_WRAPPER: ${{ needs.pr-policy-wrapper.result }} PR_CORE_WRAPPER: ${{ needs.pr-core-wrapper.result }} SCRIPTS_GO_CHECKS: ${{ needs.scripts-go-checks.result }} diff --git a/BUILD.bazel b/BUILD.bazel index b4ebcdbb6..ec54b7b7f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -169,6 +169,20 @@ filegroup( visibility = ["//scripts:__pkg__"], ) +# F3: TestMCPPytestWorkerCountPinned (ci_workflow_test.go) reads the MCP +# package's pytest-xdist pin directly from its manifest and lock file, so it +# runs under `bazel test` as well as `go test`. integrations/beads-mcp has no +# BUILD.bazel of its own (unlike npm-package/, it is not .bazelignore'd), so +# these are ordinary sources under this package. +filegroup( + name = "mcp_package_policy_files", + srcs = [ + "integrations/beads-mcp/pyproject.toml", + "integrations/beads-mcp/uv.lock", + ], + visibility = ["//scripts:__pkg__"], +) + go_library( name = "beads", srcs = [ diff --git a/engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md b/engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md index abbcba763..3bf651ad0 100644 --- a/engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md +++ b/engdocs/CI_REQUIRED_CHECK_TOPOLOGY.md @@ -733,19 +733,30 @@ manifests. On those PRs they are the tiers' only pre-merge run, and the flag too, only so the shared `bazel-coverage` job stays identical; nothing in PR Risk reads `pr_lanes`. - Artifact consumers: `build-artifacts`' `ci-build-artifacts` fed PR Core, - domain+uow and the package gates. The first two stand down with it. - The package gates (`package-mcp`, `package-npm`) now also need - `bazel-coverage` and the `bazel` call, and download - `bazel-ci-build-artifacts` (published by `bazel-test`, same layout, bd - built as `//cmd/bd:bd_for_tests`) where `pr_lanes` is `true`. They wait - for the whole call, so on PRs that change a package they finish a few - minutes after it. The Bazel bd carries no vcs build info (`bd version` - prints `1.3.0 (dev)`, no commit); no consumer reads it. Verified - 2026-10-02: both package gates pass with the Bazel-built bd (MCP: 228 - passed, 5 skipped; npm: all tests and the pack dry run), the same as - with a `go build` bd. No other job in any workflow reads `pr.yml`'s - artifacts (`docs-autofix.yml` reads `check-doc-flags`' + domain+uow and (before F3) the package gates; all three now stand down + with it. No other job in any workflow reads `pr.yml`'s artifacts + (`docs-autofix.yml` reads `check-doc-flags`' `cli-docs-freshness-patch`, which is unaffected). + - F3: the package gates (`package-mcp`, `package-npm`) moved into + `bazel.yml` itself, behind the caller input `package-gates` (`pr.yml` + passes `"on"`; `bazel-farm.yml`/`nightly.yml` keep the default `"off"`). + They need only the `rbe` job, not `bazel-coverage`, `build-artifacts` or + the rest of the `bazel` call, and no longer download an artifact: on a + same-repo PR (`needs.rbe.outputs.enabled == 'true'`) each job builds its + own bd with `bazel build --@rules_go//go/config:race + //cmd/bd:bd_for_tests` (the race flag matches `test:ci`'s top-level + build setting, so the action keys and output path equal `bazel-test`'s + `bd_for_tests`, race itself still off for the binary); otherwise (forks, + Dependabot, rbe off/skip) they fall back to `go build ./cmd/bd`, same as + before F3. The Bazel bd carries no vcs build info (`bd version` prints + `1.3.0 (dev)`, no commit); no consumer reads it. Verified 2026-10-02: + both package gates pass with the Bazel-built bd (MCP: 228 passed, 5 + skipped; npm: all tests and the pack dry run), the same as with a + `go build` bd. Both run on `blacksmith-4vcpu-ubuntu-2404` when + `rbe.outputs.enabled == 'true'` (4 vCPU: `pytest -n 8` is pinned to + timing measured there), `ubuntu-latest` otherwise. `bazel-test`'s own + `bazel-ci-build-artifacts` upload is no longer consumed by anything; it + is kept for the F3.5.3 SHA256SUMS comparison and for debugging. - Kept on every PR: the Dolt server fingerprint (container image vs the pinned dolt CLI the Bazel dolt-server lanes start), formerly `test-domain-uow`'s first step, is its own required job diff --git a/integrations/beads-mcp/pyproject.toml b/integrations/beads-mcp/pyproject.toml index 023042541..fd126676a 100644 --- a/integrations/beads-mcp/pyproject.toml +++ b/integrations/beads-mcp/pyproject.toml @@ -98,6 +98,7 @@ dev = [ "pytest>=9.0.3", "pytest-asyncio>=1.2.0", "pytest-cov>=7.0.0", + "pytest-xdist>=3.8.0", "ruff>=0.14.0", "types-requests>=2.31.0", ] diff --git a/integrations/beads-mcp/uv.lock b/integrations/beads-mcp/uv.lock index 796f3be40..dfb385957 100644 --- a/integrations/beads-mcp/uv.lock +++ b/integrations/beads-mcp/uv.lock @@ -21,7 +21,7 @@ resolution-markers = [ "python_full_version < '3.11' and sys_platform != 'win32'", ] dependencies = [ - { name = "caio", version = "0.9.25", source = { registry = "https://pypi.org/simple" } }, + { name = "caio", version = "0.9.25", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/67/e2/d7cb819de8df6b5c1968a2756c3cb4122d4fa2b8fc768b53b7c9e5edb646/aiofile-3.9.0.tar.gz", hash = "sha256:e5ad718bb148b265b6df1b3752c4d1d83024b93da9bd599df74b9d9ffcf7919b", size = 17943, upload-time = "2024-10-08T10:39:35.846Z" } wheels = [ @@ -41,7 +41,7 @@ resolution-markers = [ "(python_full_version >= '3.11' and python_full_version < '3.14' and sys_platform != 'emscripten' and sys_platform != 'win32') or (python_full_version == '3.11.*' and sys_platform == 'emscripten')", ] dependencies = [ - { name = "caio", version = "0.12.2", source = { registry = "https://pypi.org/simple" } }, + { name = "caio", version = "0.12.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/14/31/edb06aabd8f8f0b56d659f30800795f40b93cba96be946ce179f6931e3a5/aiofile-3.12.3.tar.gz", hash = "sha256:caa6aa746b5e47e2165f7abd741b6415e49cf4d44fddc0f61844612cc3924d41", size = 21600, upload-time = "2026-08-04T22:59:27.171Z" } wheels = [ @@ -192,6 +192,7 @@ dev = [ { name = "pytest" }, { name = "pytest-asyncio" }, { name = "pytest-cov" }, + { name = "pytest-xdist" }, { name = "ruff" }, { name = "types-requests" }, ] @@ -210,6 +211,7 @@ dev = [ { name = "pytest", specifier = ">=9.0.3" }, { name = "pytest-asyncio", specifier = ">=1.2.0" }, { name = "pytest-cov", specifier = ">=7.0.0" }, + { name = "pytest-xdist", specifier = ">=3.8.0" }, { name = "ruff", specifier = ">=0.14.0" }, { name = "types-requests", specifier = ">=2.31.0" }, ] @@ -707,6 +709,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/8a/0e/97c33bf5009bdbac74fd2beace167cab3f978feb69cc36f1ef79360d6c4e/exceptiongroup-1.3.1-py3-none-any.whl", hash = "sha256:a7a39a3bd276781e98394987d3a5701d0c4edffb633bb7a5144577f82c773598", size = 16740, upload-time = "2025-11-21T23:01:53.443Z" }, ] +[[package]] +name = "execnet" +version = "2.1.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bf/89/780e11f9588d9e7128a3f87788354c7946a9cbb1401ad38a48c4db9a4f07/execnet-2.1.2.tar.gz", hash = "sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd", size = 166622, upload-time = "2025-11-12T09:56:37.75Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ab/84/02fc1827e8cdded4aa65baef11296a9bbe595c474f0d6d758af082d849fd/execnet-2.1.2-py3-none-any.whl", hash = "sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec", size = 40708, upload-time = "2025-11-12T09:56:36.333Z" }, +] + [[package]] name = "fastmcp" version = "4.0.5" @@ -795,8 +806,8 @@ name = "httpcore2" version = "2.13.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "h11" }, - { name = "truststore" }, + { name = "h11", marker = "python_full_version < '3.12' or python_full_version >= '3.14' or sys_platform != 'emscripten'" }, + { name = "truststore", marker = "python_full_version < '3.12' or python_full_version >= '3.14' or sys_platform != 'emscripten'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/cb/f3/1db7aa2bc2524062192bb0e0323969492d1883152a232fe36eea65f4e35c/httpcore2-2.13.1.tar.gz", hash = "sha256:e0aa977abe17e69a3b820a24542a6fa88702676d83880b8d194dcd18408e5103", size = 68071, upload-time = "2026-09-23T07:47:22.372Z" } wheels = [ @@ -843,7 +854,7 @@ name = "importlib-metadata" version = "9.0.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "zipp" }, + { name = "zipp", marker = "(python_full_version < '3.14' and sys_platform != 'emscripten') or (python_full_version < '3.12' and sys_platform == 'emscripten')" }, ] sdist = { url = "https://files.pythonhosted.org/packages/6f/7e/1e7e8dc30634b93ebb3d58a3dea569ad146e656218d3960ab04f62047b29/importlib_metadata-9.0.1.tar.gz", hash = "sha256:ab830580bc0ef3db61ce8fae716389e5462b67e033018bab6d8f80ef17172f99", size = 59124, upload-time = "2026-08-28T15:30:34.646Z" } wheels = [ @@ -1604,6 +1615,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678", size = 22876, upload-time = "2026-03-21T20:11:14.438Z" }, ] +[[package]] +name = "pytest-xdist" +version = "3.8.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "execnet" }, + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/78/b4/439b179d1ff526791eb921115fca8e44e596a13efeda518b9d845a619450/pytest_xdist-3.8.0.tar.gz", hash = "sha256:7e578125ec9bc6050861aa93f2d59f1d8d085595d6551c2c90b6f4fad8d3a9f1", size = 88069, upload-time = "2025-07-01T13:30:59.346Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ca/31/d4e37e9e550c2b92a9cbc2e4d0b7420a27224968580b5a447f420847c975/pytest_xdist-3.8.0-py3-none-any.whl", hash = "sha256:202ca578cfeb7370784a8c33d6d05bc6e13b4f25b5053c30a152269fd10f0b88", size = 46396, upload-time = "2025-07-01T13:30:56.632Z" }, +] + [[package]] name = "python-dotenv" version = "1.2.3" @@ -2048,8 +2072,8 @@ name = "secretstorage" version = "3.5.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "cryptography" }, - { name = "jeepney" }, + { name = "cryptography", marker = "(python_full_version < '3.12' and sys_platform == 'emscripten') or (python_full_version >= '3.14' and sys_platform == 'emscripten') or (python_full_version >= '3.15' and sys_platform == 'win32') or (sys_platform != 'emscripten' and sys_platform != 'win32')" }, + { name = "jeepney", marker = "(python_full_version < '3.12' and sys_platform == 'emscripten') or (python_full_version >= '3.14' and sys_platform == 'emscripten') or (python_full_version >= '3.15' and sys_platform == 'win32') or (sys_platform != 'emscripten' and sys_platform != 'win32')" }, ] sdist = { url = "https://files.pythonhosted.org/packages/1c/03/e834bcd866f2f8a49a85eaff47340affa3bfa391ee9912a952a1faa68c7b/secretstorage-3.5.0.tar.gz", hash = "sha256:f04b8e4689cbce351744d5537bf6b1329c6fc68f91fa666f60a380edddcd11be", size = 19884, upload-time = "2025-11-23T19:02:53.191Z" } wheels = [ diff --git a/scripts/BUILD.bazel b/scripts/BUILD.bazel index a999e1406..894c61591 100644 --- a/scripts/BUILD.bazel +++ b/scripts/BUILD.bazel @@ -46,6 +46,7 @@ go_test( ":scripts_files", "//:.goreleaser.yml", "//:bazel_policy_files", + "//:mcp_package_policy_files", "//:test_sh_files", "//:workflow_files", "//internal/testutil:testdoltcommon.go", diff --git a/scripts/bazel_cache_mode_test.go b/scripts/bazel_cache_mode_test.go index d1fb08dcb..56befa6c7 100644 --- a/scripts/bazel_cache_mode_test.go +++ b/scripts/bazel_cache_mode_test.go @@ -192,6 +192,14 @@ func TestBazelCacheModeReachesTheRC(t *testing.T) { } var wantSkips []string for lane, id := range bazelLaneGateIDs { + // F3: package-mcp/package-npm skip only when the caller's + // package-gates input is off, never because of rbe mode; + // bazel-gate.sh knows nothing about them (its skip list is + // mode-derived only), so this scenario's with (which never + // sets package-gates here) must not expect them either. + if bazelPackageJobs[lane] { + continue + } if !ran[lane] { wantSkips = append(wantSkips, id) } diff --git a/scripts/bazel_farm_workflow_test.go b/scripts/bazel_farm_workflow_test.go index ea9cc1269..a36d9fb99 100644 --- a/scripts/bazel_farm_workflow_test.go +++ b/scripts/bazel_farm_workflow_test.go @@ -244,6 +244,13 @@ func TestBazelWorkflowForkFarmInputs(t *testing.T) { } checkouts++ want := map[string]string{"ref": bazelCheckoutRef, "persist-credentials": "false", "allow-unsafe-pr-checkout": bazelAllowUnsafeCheckout} + // F3: package-mcp/package-npm's detect step diffs PR_BASE_SHA + // against PR_HEAD_SHA (scripts/ci/detect-package-gates.sh, same + // as pr.yml's legacy detect job used); that needs full history, + // unlike every other lane's shallow, history-free checkout. + if bazelPackageJobs[name] { + want["fetch-depth"] = "0" + } if !reflect.DeepEqual(step.With, want) { t.Errorf("%s job %s checkout with = %v, want %v", bazelWorkflowName, name, step.With, want) } diff --git a/scripts/ci/detect-package-gates.sh b/scripts/ci/detect-package-gates.sh index b5753ae8a..4ff5d0b3f 100755 --- a/scripts/ci/detect-package-gates.sh +++ b/scripts/ci/detect-package-gates.sh @@ -82,7 +82,12 @@ while IFS= read -r path; do ;; esac case "$path" in - scripts/ci/detect-package-gates.sh|.github/workflows/pr.yml|.github/workflows/main.yml|.github/workflows/pr-risk.yml|.github/workflows/ci-measurements.yml|Makefile) + # F3: package-mcp/package-npm's job definitions (this detect step + # included) now live in bazel.yml, not pr.yml, so a change there + # must run both gates the same way a pr.yml/main.yml change does. + # package-bazel-bd.sh packages the Bazel-built bd both gates use on + # the remote-execution path. + scripts/ci/detect-package-gates.sh|scripts/ci/package-bazel-bd.sh|.github/workflows/bazel.yml|.github/workflows/pr.yml|.github/workflows/main.yml|.github/workflows/pr-risk.yml|.github/workflows/ci-measurements.yml|Makefile) mcp_package=true npm_package=true ;; diff --git a/scripts/ci/package-bazel-bd.sh b/scripts/ci/package-bazel-bd.sh index 63d9551d0..20bf87f66 100755 --- a/scripts/ci/package-bazel-bd.sh +++ b/scripts/ci/package-bazel-bd.sh @@ -4,8 +4,11 @@ # # The binary is //cmd/bd:bd_for_tests, the non-race gms_pure_go cgo bd that # Bazel's own tests exec (//cmd/bd:bd is race built under --config=ci); run -# after `bazel test //... --config=ci`, whose test:ci downloads it. Unlike -# `go build`, it carries no vcs.* or CGO_ENABLED build settings, so +# after `bazel test //... --config=ci` (whose test:ci downloads it) or after +# `bazel build //cmd/bd:bd_for_tests` directly (bazel.yml's package gates: +# only test:ci is defined in .bazelrc, so `bazel build --config=ci` fails). +# Either way the same bd_for_tests output path is what this script packages. +# Unlike `go build`, it carries no vcs.* or CGO_ENABLED build settings, so # `bd version` shows no commit and scripts/verify-cgo.sh would pass # vacuously; no consumer of the artifact reads either. # diff --git a/scripts/ci/package-mcp.sh b/scripts/ci/package-mcp.sh index d234b42c9..5b14a7041 100755 --- a/scripts/ci/package-mcp.sh +++ b/scripts/ci/package-mcp.sh @@ -52,7 +52,11 @@ mcp_mypy() { mcp_pytest() { cd "$MCP_DIR" - uv run pytest --durations=50 + # Explicit worker count, not "auto": CI runners' reported CPU count + # doesn't always match the cgroup quota, and -n 8 is pinned to measured + # timing (tools/f3, 2026-10) on both 2 vCPU (2.7x) and 4 vCPU (~3x) + # runners. pytest-xdist is a pinned dev dependency (pyproject.toml). + uv run pytest -n 8 --durations=50 } mcp_build() { diff --git a/scripts/ci_workflow_test.go b/scripts/ci_workflow_test.go index b304f5e85..6d7dda79e 100644 --- a/scripts/ci_workflow_test.go +++ b/scripts/ci_workflow_test.go @@ -1205,11 +1205,13 @@ func assertNoUnmanagedGoCacheSteps(t *testing.T, workflows map[string]ciWorkflow const ( setupGoActionFamily = "actions/setup-go" setupNodeActionFamily = "actions/setup-node" + setupPythonActionFamily = "actions/setup-python" cacheMonolithicActionFamily = "actions/cache" cacheRestoreActionFamily = "actions/cache/restore" cacheSaveActionFamily = "actions/cache/save" setupGoSHA = "b7ad1dad31e06c5925ef5d2fc7ad053ef454303e" setupNodeSHA = "820762786026740c76f36085b0efc47a31fe5020" + setupPythonSHA = "5fda3b95a4ea91299a34e894583c3862153e4b97" cacheSHA = "55cc8345863c7cc4c66a329aec7e433d2d1c52a9" goCacheSchema = "v2" goBaseTag = "gms_pure_go" @@ -1773,7 +1775,20 @@ const ( bazelIntegJobName = "bazel-integration" bazelProxiedJobName = "bazel-proxied" bazelServerJobName = "bazel-server-storage" - setupBazelActionDir = ".github/actions/setup-bazel" + // F3: the MCP and npm package gates, moved here from pr.yml so they need + // only the rbe job. Unlike every other lane they do not mirror a Bazel + // config; pr.yml opts them in with package-gates: "on". + bazelPackageMCPJobName = "package-mcp" + bazelPackageNPMJobName = "package-npm" + setupBazelActionDir = ".github/actions/setup-bazel" +) + +// F3: package-mcp and package-npm, the two lanes bazel-gate.sh does not +// know about at all - their skip reason is the caller's package-gates +// input, never the rbe job's mode. +var bazelPackageJobs = map[string]bool{bazelPackageMCPJobName: true, bazelPackageNPMJobName: true} + +const ( uploadArtifactSHA = "043fb46d1a93c77aae656e7c1c64a875d1fc6a0a" downloadArtifactSHA = "3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c" checkoutSHA = "3d3c42e5aac5ba805825da76410c181273ba90b1" @@ -1787,8 +1802,9 @@ const ( ) // bazel.yml's jobs: the rbe job that decides the execution mode, the -// --config=ci lane, and one job per CI job a Bazel config mirrors. -var bazelJobNames = []string{bazelDoltJobName, bazelEmbedJobName, bazelIntegJobName, bazelProxiedJobName, bazelPureJobName, bazelServerJobName, bazelJobName, bazelRBEJobName} +// --config=ci lane, one job per CI job a Bazel config mirrors, and the two +// package gates (F3), sorted alphabetically to match TestBazelWorkflowJobsAndExecutionMode's sort.Strings. +var bazelJobNames = []string{bazelDoltJobName, bazelEmbedJobName, bazelIntegJobName, bazelProxiedJobName, bazelPureJobName, bazelServerJobName, bazelJobName, bazelPackageMCPJobName, bazelPackageNPMJobName, bazelRBEJobName} // The lanes that only run remotely (skipped unless the rbe job chose remote); // bazel-integration runs remotely or with the read-only cache (bazelIntegIf); @@ -1826,6 +1842,10 @@ var bazelLaneGateIDs = map[string]string{ // twins run only on push to main: remotely on same-repo PRs, locally // with the read-only cache (mode cache) on fork and Dependabot PRs. bazelIntegJobName: "BAZEL_INTEGRATION", + // F3: never skippable on pr.yml (package-gates is always "on" there), so + // bazel-gate.sh's skip list never names them. + bazelPackageMCPJobName: "PACKAGE_MCP", + bazelPackageNPMJobName: "PACKAGE_NPM", } // None today: every lane is gated. Kept so a future lane that pr.yml's call @@ -1841,6 +1861,28 @@ var bazelAdvisoryLanes = map[string]string{} // lane keeps running on main. const bazelIntegIf = "${{ (needs.rbe.outputs.mode == 'remote' || needs.rbe.outputs.mode == 'cache') && inputs.integration != 'off' }}" +// F3: package-mcp and package-npm's if. Unlike every other lane's, it does +// not read the rbe job's outputs at all - only the caller's package-gates +// input - so these two never skip because of execution mode, only because a +// caller left package-gates at its default "off". +const bazelPackageGatesIf = "${{ inputs.package-gates == 'on' }}" + +// F3: the package gates' runner. 4 vCPU, not bazel.yml's usual 2: pytest-xdist +// -n 8 is pinned to measured timing on a 4 vCPU runner (tools/f3). +const bazelPackageRunsOn = "${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-4vcpu-ubuntu-2404' || 'ubuntu-latest' }}" + +// F3: the rbe job's own runner (not gated by its own outputs - it decides +// them). Same-repo PRs and merge_group/push/dispatch/schedule (never forks) +// get Blacksmith; a pull_request_target farm run and any fork or Dependabot +// PR stay GitHub-hosted. Pinned verbatim by TestSameRepoBlacksmithRunners. +const wantRBERunsOn = "${{ (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}" + +// F3: the same "same-repo PR, or merge_group" Blacksmith expression used by +// pr.yml's and pr-risk.yml's bazel-coverage/ci-gate/detect-ci-tier jobs - a +// package-level const so every test that needs it (TestSameRepoBlacksmithRunners, +// TestPRRiskBazelCoverageJob, ...) reads the one literal. +const sameRepoBlacksmith2vcpu = "${{ (github.event_name == 'merge_group' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}" + // pr.yml's call of bazel.yml: exactly these inputs (review D1 v2 N3). An rbe // override would put every PR in local mode and ungate the embedded tier // while the gate stays self-consistent; integration: "off" would drop the @@ -1849,6 +1891,9 @@ const bazelIntegIf = "${{ (needs.rbe.outputs.mode == 'remote' || needs.rbe.outpu var bazelPRCallWith = map[string]string{ "build-artifact-name": "bazel-ci-build-artifacts", "integration": "on", + // F3: only pr.yml opts in; bazel-farm.yml and nightly.yml keep the + // default "off" (TestBazelGateSimulation's other callers). + "package-gates": "on", } // The call's aggregate result (needs.bazel.result, through bazel-gate.sh). @@ -1931,6 +1976,15 @@ func TestBazelWorkflowJobsAndExecutionMode(t *testing.T) { "RBE_INSTANCE": "${{ " + gate + "'oss' || '' }}", "BAZEL_FORK_CACHE": "${{ needs.rbe.outputs.mode == 'cache' && 'true' || '' }}", } + // F3: the rbe job itself runs on Blacksmith for same-repo PRs (and + // merge_group/push/dispatch/schedule, which are never forks); a + // pull_request_target farm run and any fork or Dependabot PR stay + // GitHub-hosted. Pinned again, verbatim, by TestSameRepoBlacksmithRunners. + if rbe, ok := workflow.Jobs[bazelRBEJobName]; !ok { + t.Fatalf("%s has no %s job", bazelWorkflowName, bazelRBEJobName) + } else if rbe.RunsOn != wantRBERunsOn { + t.Errorf("%s runs-on = %q, want %q", bazelRBEJobName, rbe.RunsOn, wantRBERunsOn) + } for name, job := range workflow.Jobs { if name == bazelRBEJobName { continue @@ -1938,18 +1992,22 @@ func TestBazelWorkflowJobsAndExecutionMode(t *testing.T) { if !reflect.DeepEqual([]string(job.Needs), []string{bazelRBEJobName}) { t.Errorf("%s needs = %v, want [%s]", name, job.Needs, bazelRBEJobName) } - if job.RunsOn != wantRunsOn { - t.Errorf("%s runs-on = %q, want %q", name, job.RunsOn, wantRunsOn) + // F3: the package gates use a 4 vCPU runner (pytest-xdist -n 8) and + // their own if (the caller's package-gates input, not the rbe job's + // mode - they never skip for execution-mode reasons). + wantJobRunsOn, wantJobIf := wantRunsOn, wantIf + if bazelPackageJobs[name] { + wantJobRunsOn, wantJobIf = bazelPackageRunsOn, bazelPackageGatesIf + } else if bazelRemoteOnlyJobs[name] { + wantJobIf = wantRemoteOnlyIf + } else if name == bazelIntegJobName { + wantJobIf = bazelIntegIf } - want := wantIf - if bazelRemoteOnlyJobs[name] { - want = wantRemoteOnlyIf + if job.RunsOn != wantJobRunsOn { + t.Errorf("%s runs-on = %q, want %q", name, job.RunsOn, wantJobRunsOn) } - if name == bazelIntegJobName { - want = bazelIntegIf - } - if job.If != want { - t.Errorf("%s if = %q, want %q", name, job.If, want) + if job.If != wantJobIf { + t.Errorf("%s if = %q, want %q", name, job.If, wantJobIf) } for _, step := range job.Steps { if step.Uses == "./"+setupBazelActionDir && !reflect.DeepEqual(step.Env, wantSetupEnv) { @@ -1959,6 +2017,113 @@ func TestBazelWorkflowJobsAndExecutionMode(t *testing.T) { } } +// F3: bazelPackageRunsOn's comment and the package-mcp job's 4 vCPU runner +// are both premised on mcp_pytest() in package-mcp.sh passing an explicit +// "-n 8" (not "-n auto", which would reintroduce the CPU-count/cgroup-quota +// mismatch -n 8 was pinned to avoid), and on pytest-xdist itself being a +// locked dev dependency so that worker count is reproducible across CI runs. +// Neither half of that premise is checked by any other policy test, so pin +// both here directly against the script and the MCP package's manifest/lock. +func TestMCPPytestWorkerCountPinned(t *testing.T) { + root := sourceRepoRoot(t) + script := readPolicyFile(t, root, "scripts/ci/package-mcp.sh") + if !strings.Contains(script, "pytest -n 8") { + t.Errorf("scripts/ci/package-mcp.sh mcp_pytest() does not pass an explicit -n 8") + } + if strings.Contains(script, "-n auto") { + t.Errorf("scripts/ci/package-mcp.sh mcp_pytest() uses -n auto; want the pinned -n 8") + } + pyproject := readPolicyFile(t, root, "integrations/beads-mcp/pyproject.toml") + if !regexp.MustCompile(`(?m)^\s*"pytest-xdist[><=]`).MatchString(pyproject) { + t.Errorf("integrations/beads-mcp/pyproject.toml does not pin pytest-xdist as a dev dependency") + } + lock := readPolicyFile(t, root, "integrations/beads-mcp/uv.lock") + if !strings.Contains(lock, "name = \"pytest-xdist\"") { + t.Errorf("integrations/beads-mcp/uv.lock has no locked pytest-xdist entry; run uv lock") + } +} + +// F3: package-mcp and package-npm's job definitions (including the very +// detect step this script's output feeds) moved into bazel.yml, so a PR that +// edits only bazel.yml's package-gate logic must still self-trigger both +// gates the same way editing pr.yml/main.yml/pr-risk.yml does; otherwise a +// change to the job that runs the gates could ship without the gates having +// run against it. No other policy test reads this script's content. +func TestDetectPackageGatesCoversBazelWorkflow(t *testing.T) { + root := sourceRepoRoot(t) + script := readPolicyFile(t, root, "scripts/ci/detect-package-gates.sh") + re := regexp.MustCompile(`(?s)scripts/ci/detect-package-gates\.sh\|[^)]*\)\s*\n\s*mcp_package=true\s*\n\s*npm_package=true`) + loc := re.FindString(script) + if loc == "" { + t.Fatalf("scripts/ci/detect-package-gates.sh has no case arm forcing both mcp_package and npm_package true alongside its own path") + } + if !strings.Contains(loc, ".github/workflows/bazel.yml") { + t.Errorf("scripts/ci/detect-package-gates.sh's both-gates case arm does not include .github/workflows/bazel.yml, where the package-mcp/package-npm job definitions now live") + } + // F3 review NIT-6: package-bazel-bd.sh packages the Bazel-built bd for + // both package-mcp and package-npm on the remote-execution path, so a + // change to it must run both gates too. + if !strings.Contains(loc, "scripts/ci/package-bazel-bd.sh") { + t.Errorf("scripts/ci/detect-package-gates.sh's both-gates case arm does not include scripts/ci/package-bazel-bd.sh, which both package gates use to package the Bazel-built bd") + } +} + +// F3: the exact "same-repo PR, or merge_group" Blacksmith expression, pinned +// once per job so a future edit cannot drift one copy from another. Reads no +// repo variable, so the rollback is a plain revert. The rbe job's own +// version additionally covers push, workflow_dispatch and schedule (never +// forks); every other job below reads only merge_group and pull_request. +func TestSameRepoBlacksmithRunners(t *testing.T) { + want := map[string]map[string]string{ + "pr.yml": {"bazel-coverage": sameRepoBlacksmith2vcpu, "ci-gate": sameRepoBlacksmith2vcpu}, + "pr-risk.yml": {"bazel-coverage": sameRepoBlacksmith2vcpu, "ci-gate": sameRepoBlacksmith2vcpu, "detect-ci-tier": sameRepoBlacksmith2vcpu}, + bazelWorkflowName: {bazelRBEJobName: wantRBERunsOn}, + } + // The two required gates' display names are a stable external contract + // (branch protection rule names) - moving them to Blacksmith must not + // rename them. Reviewed 2026-10-03: a rename of either survived every + // other policy test, since nothing else reads job.Name. + wantGateName := map[string]map[string]string{ + "pr.yml": {"ci-gate": "CI Gate / Required"}, + "pr-risk.yml": {"ci-gate": "PR Risk Gate / Required"}, + } + for file, jobs := range want { + workflow := readCIWorkflow(t, file) + for name, wantRunsOn := range jobs { + job, ok := workflow.Jobs[name] + if !ok { + t.Fatalf("%s has no %s job", file, name) + } + if job.RunsOn != wantRunsOn { + t.Errorf("%s %s runs-on = %q, want %q", file, name, job.RunsOn, wantRunsOn) + } + if wantName := wantGateName[file][name]; wantName != "" && job.Name != wantName { + t.Errorf("%s %s name = %q, want %q", file, name, job.Name, wantName) + } + // F3: every job moved onto Blacksmith needs its own + // timeout-minutes - a hang there burns paid Blacksmith minutes, + // not just a free GitHub-hosted runner's default 360. + if job.TimeoutMinutes == 0 { + t.Errorf("%s %s has no timeout-minutes (now runs on Blacksmith for same-repo PRs)", file, name) + } + } + } + // No other job in pr.yml or pr-risk.yml may name a Blacksmith label: F4 + // adds one more (not in this slice's scope), but nothing here should. + for _, file := range []string{"pr.yml", "pr-risk.yml"} { + workflow := readCIWorkflow(t, file) + allowed := want[file] + for name, job := range workflow.Jobs { + if allowed[name] != "" { + continue + } + if strings.Contains(job.RunsOn, "blacksmith-") { + t.Errorf("%s job %s runs-on %q names a Blacksmith label; only %v may", file, name, job.RunsOn, allowed) + } + } + } +} + type bazelWorkflowCall struct { Inputs map[string]struct { Type string `yaml:"type"` @@ -2135,7 +2300,13 @@ func TestBazelLaneIsGatedAlongsideLegacy(t *testing.T) { wantBazelIDs = append(wantBazelIDs, r.retiredID) } for lane, id := range bazelLaneGateIDs { - wantBazelIDs = append(wantBazelIDs, id) + // F3: package-mcp/package-npm's ids (PACKAGE_MCP, PACKAGE_NPM) do not + // follow the "BAZEL" naming convention the prefix filter below + // groups by - they predate bazel.yml and keep their names - so they + // are checked here but excluded from wantBazelIDs. + if !bazelPackageJobs[lane] { + wantBazelIDs = append(wantBazelIDs, id) + } if want := "${{ needs.bazel.outputs." + lane + " || 'skipped' }}"; evaluate.Env[id] != want { t.Errorf("ci-gate env %s = %q, want %q", id, evaluate.Env[id], want) } @@ -2291,6 +2462,14 @@ func bazelLaneRunModes(t *testing.T, lane, ifExpr string, with map[string]string return map[string]bool{} } return map[string]bool{"remote": true, "cache": true} + case bazelPackageGatesIf: + // F3: unlike every other lane, these two never skip because of the + // rbe job's decision - only because the caller turned them off + // entirely (pr.yml always passes "on"). + if strings.EqualFold(with["package-gates"], "on") { + return map[string]bool{"remote": true, "cache": true, "local": true, "skip": true} + } + return map[string]bool{} } t.Fatalf("%s if = %q: teach bazelLaneRunModes which modes run it", lane, ifExpr) return nil @@ -2424,6 +2603,13 @@ func TestBazelGateSimulation(t *testing.T) { var wantSkips []string anyRuns := false for lane, modes := range lanes { + // F3: bazel-gate.sh's skip list and its BAZEL aggregate are + // mode-derived only; it has never heard of package-mcp/npm + // (their own PACKAGE_MCP/PACKAGE_NPM scenarios are exercised + // below, by lane, not through this script). + if bazelPackageJobs[lane] { + continue + } if modes[mode] { anyRuns = true } else if id, gated := bazelLaneGateIDs[lane]; gated { @@ -2697,6 +2883,7 @@ func TestBazelWorkflowActionsArePinned(t *testing.T) { } want := map[string]string{ setupNodeActionFamily: setupNodeSHA, + setupPythonActionFamily: setupPythonSHA, "actions/checkout": checkoutSHA, setupGoActionFamily: setupGoSHA, cacheRestoreActionFamily: cacheSHA, @@ -3975,9 +4162,13 @@ func TestBazelWorkflowSecretsAndFailureSurface(t *testing.T) { func TestBazelRBEJobDecidesOnce(t *testing.T) { workflow := readCIWorkflow(t, bazelWorkflowName) job := workflow.job(t, bazelRBEJobName) - if len(job.Needs) != 0 || job.If != "" || job.RunsOn != "ubuntu-latest" || len(job.Env) != 0 { - t.Errorf("%s: needs %v, if %q, runs-on %q, env %v; want no needs, if or env, on ubuntu-latest", - bazelRBEJobName, job.Needs, job.If, job.RunsOn, job.Env) + // F3: runs-on picks the *venue* (Blacksmith for trusted same-repo PRs, + // ubuntu-latest otherwise) - a separate concern from the RBE mode + // decision (remote/cache/local/skip), which still lives solely in the + // decide step's outputs below. + if len(job.Needs) != 0 || job.If != "" || job.RunsOn != wantRBERunsOn || len(job.Env) != 0 { + t.Errorf("%s: needs %v, if %q, runs-on %q, env %v; want no needs, if or env, on %q", + bazelRBEJobName, job.Needs, job.If, job.RunsOn, job.Env, wantRBERunsOn) } wantOutputs := map[string]string{ "enabled": "${{ steps.decide.outputs.enabled }}", @@ -4032,6 +4223,14 @@ func TestBazelRBEJobDecidesOnce(t *testing.T) { if key || !rederive.MatchString(value) || strings.HasPrefix(path, ".jobs."+bazelRBEJobName+".steps[0].env.") { return } + // F3: the rbe job's own runs-on picks a runner venue (Blacksmith vs + // ubuntu-latest) for trusted same-repo PRs; it shares some of the + // same trust predicates (github.actor, dependabot) as the mode + // decision but decides something else entirely (where the decide + // step runs, not what it decides) - not a re-derivation of mode. + if path == ".jobs."+bazelRBEJobName+".runs-on" { + return + } // The checkout opt-in for fork code (TestBazelWorkflowForkFarmInputs // pins it): a checkout input, not an execution-mode decision. if value == bazelAllowUnsafeCheckout && strings.HasSuffix(path, ".with.allow-unsafe-pr-checkout") { diff --git a/scripts/pr_lanes_bazel_coverage_test.go b/scripts/pr_lanes_bazel_coverage_test.go index 5acb08934..60d8aaf0d 100644 --- a/scripts/pr_lanes_bazel_coverage_test.go +++ b/scripts/pr_lanes_bazel_coverage_test.go @@ -26,18 +26,12 @@ import ( const ( // The legacy jobs' if: not covered. - prLaneLegacyIf = "needs." + prRiskCoverageJobName + ".outputs.pr_lanes != 'true'" - // The package gates: they run whenever detection and the decision did, - // on build-artifacts' bd, or on Bazel's where build-artifacts stood down. - prPackageGateIf = "${{ !cancelled() && needs.detect-package-gates.result == 'success' && needs." + prRiskCoverageJobName + - ".result == 'success' && (needs." + prRiskCoverageJobName + ".outputs.pr_lanes == 'true' || needs.build-artifacts.result == 'success') }}" - prPackageGateArtifact = "${{ needs." + prRiskCoverageJobName + ".outputs.pr_lanes == 'true' && 'bazel-ci-build-artifacts' || 'ci-build-artifacts' }}" - prFingerprintJob = "test-dolt-server-fingerprint" - prFingerprintID = "TEST_DOLT_SERVER_FINGERPRINT" - prAllowlistedStep = "Run the Go tests the Bazel lane skips" - prScriptsChecksJob = "scripts-go-checks" - prPackageBDCheck = "Check the Bazel-built bd exists" - prScriptsChecksID = "SCRIPTS_GO_CHECKS" + prLaneLegacyIf = "needs." + prRiskCoverageJobName + ".outputs.pr_lanes != 'true'" + prFingerprintJob = "test-dolt-server-fingerprint" + prFingerprintID = "TEST_DOLT_SERVER_FINGERPRINT" + prAllowlistedStep = "Run the Go tests the Bazel lane skips" + prScriptsChecksJob = "scripts-go-checks" + prScriptsChecksID = "SCRIPTS_GO_CHECKS" // bazel.yml's lanes for the step add --config=sole-run in mode remote. bazelSoleRunEnv = "${{ needs.rbe.outputs.mode == 'remote' && '--config=sole-run' || '' }}" bazelSoleRunArg = `${BAZEL_SOLE_RUN:+"$BAZEL_SOLE_RUN"}` @@ -45,9 +39,12 @@ const ( bazelSoleRunEvictionLine = "test:sole-run --experimental_remote_cache_eviction_retries=0" ) -// The package gates (consumers of build-artifacts' ci-build-artifacts that -// keep running where it stands down). -var prPackageGates = map[string]string{"package-mcp": "PACKAGE_MCP", "package-npm": "PACKAGE_NPM"} +// F3: the package gates moved into bazel.yml (package-mcp, package-npm); +// they depend only on the caller's package-gates input, not on +// bazel-coverage's decision or build-artifacts (TestPackageGateJobs). This +// map is only their CI_GATE_REQUIRED ids, for the gate-simulation scenarios +// below (pr.yml no longer has jobs by these names). +var prPackageGateIDs = map[string]string{"package-mcp": "PACKAGE_MCP", "package-npm": "PACKAGE_NPM"} // Each retired job's needs, exactly. var prLaneLegacyNeeds = map[string][]string{ @@ -172,9 +169,10 @@ func prLegacyJobResult(job string, sc bazelGateScenario) string { return "skipped" } } - if _, ok := prPackageGates[job]; ok && !decided { - return "skipped" - } + // F3: package-mcp/package-npm are bazel.yml call outputs now + // (needs.bazel.outputs.package-mcp), not pr.yml job results, so + // runPRGateStep never calls this helper for them - they are simulated + // through sc.outputs instead (see the scenario loop below). return "success" } @@ -211,25 +209,27 @@ func TestPRLegacyLanesDeferToBazelLanes(t *testing.T) { t.Errorf("pr.yml tier lanes = %v", tier.bazelLanes) } - // Only the retired jobs, the package gates and the gate read the - // decision; only they and the gate need build-artifacts. + // Only the retired jobs and the gate read the decision; only they and + // the gate need build-artifacts. The package gates moved into bazel.yml + // (F3) and never depend on this decision or on build-artifacts at all - + // they build bd for themselves, via Bazel or a go build fallback + // (TestPackageGateJobs). for name, job := range pr.Jobs { _, retired := tier.jobs[name] - _, pkg := prPackageGates[name] - if retired || pkg || name == "ci-gate" || name == prRiskCoverageJobName { + if retired || name == "ci-gate" || name == prRiskCoverageJobName { continue } if strings.Contains(job.If, prRiskCoverageJobName) || contains(job.Needs, prRiskCoverageJobName) { - t.Errorf("%s depends on %s; only the retired jobs and the package gates may", name, prRiskCoverageJobName) + t.Errorf("%s depends on %s; only the retired jobs may", name, prRiskCoverageJobName) } if contains(job.Needs, "build-artifacts") { - t.Errorf("%s needs build-artifacts, which stands down on covered PRs; take the artifact like the package gates do", name) + t.Errorf("%s needs build-artifacts, which stands down on covered PRs", name) } } - // Artifact consumers: the retired jobs read build-artifacts' artifact - // (they only run where it does); the package gates read Bazel's where - // it stood down. Nothing downloads by pattern or without a name. + // Artifact consumers: only the retired jobs read build-artifacts' + // artifact (they only run where it does). Nothing downloads by pattern + // or without a name. for name, job := range pr.Jobs { for _, step := range job.Steps { if !strings.HasPrefix(step.Uses, "actions/download-artifact@") { @@ -243,51 +243,15 @@ func TestPRLegacyLanesDeferToBazelLanes(t *testing.T) { if !strings.Contains(art, "ci-build-artifacts") { continue } - _, retired := tier.jobs[name] - _, pkg := prPackageGates[name] - switch { - case retired && art == "ci-build-artifacts": - case pkg && art == prPackageGateArtifact: - default: - t.Errorf("%s downloads %q; only the retired jobs (ci-build-artifacts) and the package gates (%s) may", name, art, prPackageGateArtifact) + if _, retired := tier.jobs[name]; !retired || art != "ci-build-artifacts" { + t.Errorf("%s downloads %q; only the retired jobs (ci-build-artifacts) may", name, art) } if step.With["path"] != "ci-build-artifacts" { t.Errorf("%s downloads into %q, want ci-build-artifacts (the layout its steps read)", name, step.With["path"]) } } } - for name, id := range prPackageGates { - job := pr.job(t, name) - want := []string{"detect-package-gates", "build-artifacts", prRiskCoverageJobName, "bazel"} - if job.If != prPackageGateIf || !reflect.DeepEqual([]string(job.Needs), want) { - t.Errorf("%s: if %q, needs %v; want if %q, needs %v", name, job.If, job.Needs, prPackageGateIf, want) - } - if dl := job.step(t, "Download build artifacts"); dl.With["name"] != prPackageGateArtifact { - t.Errorf("%s downloads %q, want %q", name, dl.With["name"], prPackageGateArtifact) - } - if v := job.step(t, "Verify build artifacts").Run; !strings.Contains(v, "sha256sum -c SHA256SUMS") || !strings.Contains(v, "chmod +x bd-linux-gms-pure") { - t.Errorf("%s no longer verifies the artifact:\n%s", name, v) - } - if !contains(required, id) { - t.Errorf("ci-gate does not require %s", id) - } - // Review L2: with the farm off (mode skip) on a covered PR, say why - // there is no bd before the download fails on a missing artifact. - check := job.step(t, prPackageBDCheck) - if check.If != "steps.applicability.outputs.run == 'true' && needs."+prRiskCoverageJobName+".outputs.pr_lanes == 'true'" || - !reflect.DeepEqual(check.Env, map[string]string{"BAZEL_RBE_MODE": "${{ needs.bazel.outputs.rbe-mode }}"}) || check.ContinueOnError != nil || - job.stepIndex(t, prPackageBDCheck) > job.stepIndex(t, "Download build artifacts") { - t.Errorf("%s step %q: if %q, env %v; want it before the download, on covered applicable runs, reading the call's mode", name, prPackageBDCheck, check.If, check.Env) - } - for mode, wantOK := range map[string]bool{"remote": true, "skip": false, "cache": false, "local": false, "": false} { - cmd := exec.Command("bash", "--noprofile", "--norc", "-eo", "pipefail", "-c", check.Run) - cmd.Env = []string{"PATH=" + os.Getenv("PATH"), "BAZEL_RBE_MODE=" + mode} - out, err := cmd.CombinedOutput() - if (err == nil) != wantOK || (!wantOK && !(strings.Contains(string(out), "::error::") && strings.Contains(string(out), "BAZEL_PR_LANES_RETIRED"))) { - t.Errorf("%s bd check in mode %q: ok %v, want %v\n%s", name, mode, err == nil, wantOK, out) - } - } - } + testPackageGateJobs(t, required) // Bazel's artifact: bazel-test publishes it (always, after its tests) // under the name pr.yml passes, with build-artifacts' layout // (TestBazelWorkflowPublishesBuildArtifacts). @@ -353,17 +317,25 @@ func TestPRLegacyLanesDeferToBazelLanes(t *testing.T) { for _, res := range []string{"skipped", "failure", "cancelled"} { for _, job := range []string{prFingerprintJob, "package-mcp", "package-npm", "pr-preflight-platforms", prScriptsChecksJob} { sc := prGateFor(t, lanes, "pull_request", "remote", cov(c)) - sc.results = map[string]string{job: res} + // F3: package-mcp/package-npm are bazel.yml call outputs + // (needs.bazel.outputs.package-mcp), not pr.yml job + // results, so the gate simulation overrides sc.outputs for + // them instead of sc.results. + if _, pkg := prPackageGateIDs[job]; pkg { + sc.outputs[job] = res + } else { + sc.results = map[string]string{job: res} + } id := map[string]string{prFingerprintJob: prFingerprintID, "pr-preflight-platforms": "PR_PREFLIGHT_PLATFORMS", prScriptsChecksJob: prScriptsChecksID}[job] if id == "" { - id = prPackageGates[job] + id = prPackageGateIDs[job] } add(fmt.Sprintf("covered=%s, %s %s", c, job, res), sc, false, id) } } } - // A failed decision: the retired jobs and the package gates skip - // through needs, and the gate is red. + // A failed decision: the retired jobs skip through needs (the package + // gates do not depend on the decision at all, F3), and the gate is red. for _, res := range []string{"failure", "cancelled", "skipped"} { sc := prGateFor(t, lanes, "pull_request", "remote", cov("")) sc.coverage = res @@ -391,6 +363,163 @@ func sortedKeys[V any](m map[string]V) []string { return out } +// F3: the package gates (bazel.yml's package-mcp, package-npm). They depend +// only on the caller turning package-gates on (never on bazel-coverage or +// build-artifacts: TestPRLegacyLanesDeferToBazelLanes already checked that +// nothing but the retired jobs reads either), build bd for themselves - via +// the Bazel lane's binary when the farm is up, a go build fallback +// otherwise (package-mcp.sh/package-npm.sh's prepare_bd_binary) - and are +// structurally identical apart from their language setup and `make` target. +// Their runs-on/if/needs/result-recorder are already pinned for every +// bazel.yml job by TestBazelWorkflowJobsAndExecutionMode and +// TestBazelLaneIsGatedAlongsideLegacy; this test pins the step-by-step +// detail those generic checks do not. +func testPackageGateJobs(t *testing.T, prGateRequired []string) { + t.Helper() + workflow := readCIWorkflow(t, bazelWorkflowName) + // main.yml's own package-mcp/package-npm jobs (nightly, not gated by + // rbe) run the same language setup; bazel.yml's copy must not drift + // from it. + mainWorkflow := readCIWorkflow(t, "main.yml") + type pkgLane struct { + job, detectOutput, langStepName, makeTarget string + } + lanes := []pkgLane{ + {bazelPackageMCPJobName, "mcp_package", "Set up Python", "make ci-package-mcp"}, + {bazelPackageNPMJobName, "npm_package", "Set up Node.js", "make ci-package-npm"}, + } + for _, lane := range lanes { + id := bazelLaneGateIDs[lane.job] + if !contains(prGateRequired, id) { + t.Errorf("ci-gate does not require %s (%s)", lane.job, id) + } + job, ok := workflow.Jobs[lane.job] + if !ok { + t.Fatalf("%s has no %s job", bazelWorkflowName, lane.job) + } + if !reflect.DeepEqual([]string(job.Needs), []string{bazelRBEJobName}) || job.If != bazelPackageGatesIf || job.RunsOn != bazelPackageRunsOn { + t.Errorf("%s: needs %v, if %q, runs-on %q; want needs [%s], if %q, runs-on %q", + lane.job, job.Needs, job.If, job.RunsOn, bazelRBEJobName, bazelPackageGatesIf, bazelPackageRunsOn) + } + + detectCond := "steps.detect.outputs." + lane.detectOutput + " == 'true'" + detectIf := "${{ " + detectCond + " }}" + bazelPathIf := "${{ " + detectCond + " && needs." + bazelRBEJobName + ".outputs.enabled == 'true' }}" + fallbackIf := "${{ " + detectCond + " && needs." + bazelRBEJobName + ".outputs.enabled != 'true' }}" + wantNames := []string{ + "", // checkout (no name) + "Decide applicability", + "Set up Bazel", + "bazel build //cmd/bd:bd_for_tests", + "Package the Bazel-built bd", + "Set up Go", + "Restore Go module cache", + "Verify Go modules", + "Restore non-race Go build cache", + lane.langStepName, + } + if lane.job == bazelPackageMCPJobName { + wantNames = append(wantNames, "Install uv") + } + wantNames = append(wantNames, "Run "+map[string]string{bazelPackageMCPJobName: "MCP", bazelPackageNPMJobName: "npm"}[lane.job]+" package gate", "Record job result") + + var gotNames []string + for _, s := range job.Steps { + gotNames = append(gotNames, s.Name) + } + if !reflect.DeepEqual(gotNames, wantNames) { + t.Errorf("%s step names = %q, want %q", lane.job, gotNames, wantNames) + } + + checkout := job.Steps[0] + if checkout.Uses != "actions/checkout@"+checkoutSHA || checkout.With["fetch-depth"] != "0" { + t.Errorf("%s checkout = %+v; want fetch-depth 0 (detect-package-gates.sh diffs full history)", lane.job, checkout) + } + + detect := job.step(t, "Decide applicability") + wantDetectEnv := map[string]string{ + "PR_BASE_SHA": "${{ github.event.pull_request.base.sha }}", + "PR_HEAD_SHA": "${{ github.event.pull_request.head.sha }}", + "PUSH_BEFORE_SHA": "${{ github.event.before }}", + "PUSH_AFTER_SHA": "${{ github.sha }}", + } + if detect.ID != "detect" || detect.Run != "./scripts/ci/detect-package-gates.sh" || !reflect.DeepEqual(detect.Env, wantDetectEnv) { + t.Errorf("%s detect step: id %q, run %q, env %v; want id detect, run ./scripts/ci/detect-package-gates.sh, env %v", + lane.job, detect.ID, detect.Run, detect.Env, wantDetectEnv) + } + + // The Bazel-built-bd path: gated on the farm being up, in addition + // to detection. No --config=ci (only test:ci exists). The explicit + // --@rules_go//go/config:race matches test:ci's top-level build + // setting, so bd_for_tests' race="off" transition lands in the same + // output directory and action-cache key `bazel test --config=ci` + // already populated (verified with cquery against origin/main + // e2b78f7d7a: both configs cquery to the identical + // bazel-out/k8-fastbuild-ST-.../bin/cmd/bd/bd_for_tests/bd path). + buildStep := job.step(t, "bazel build //cmd/bd:bd_for_tests") + if buildStep.If != bazelPathIf || buildStep.Run != `bazel build --@rules_go//go/config:race //cmd/bd:bd_for_tests --remote_download_regex='.*/bin/cmd/bd/bd_for_tests/bd$'` { + t.Errorf("%s bazel build step: if %q, run %q; want if %q", lane.job, buildStep.If, buildStep.Run, bazelPathIf) + } + pkgBD := job.step(t, "Package the Bazel-built bd") + if pkgBD.If != bazelPathIf || !strings.Contains(pkgBD.Run, `./scripts/ci/package-bazel-bd.sh "$RUNNER_TEMP/bd-artifacts"`) || + !strings.Contains(pkgBD.Run, "BEADS_TEST_BD_BINARY=$RUNNER_TEMP/bd-artifacts/bd-linux-gms-pure") { + t.Errorf("%s package-the-Bazel-built-bd step: if %q, run %q", lane.job, pkgBD.If, pkgBD.Run) + } + // F3 review NIT-5: nothing past this step needs the Bazel server or + // its RBE client key (uv sync/pytest/npm install run PR-controlled + // code), so both are torn down here, defense in depth. + if !strings.Contains(pkgBD.Run, "bazel shutdown") || !strings.Contains(pkgBD.Run, `rm -rf "$RUNNER_TEMP/bazel-ci-secret"`) { + t.Errorf("%s package-the-Bazel-built-bd step does not shut down Bazel and remove the RBE client key: run %q", lane.job, pkgBD.Run) + } + setupBazel := job.step(t, "Set up Bazel") + if setupBazel.If != bazelPathIf || setupBazel.Uses != "./"+setupBazelActionDir { + t.Errorf("%s Set up Bazel: if %q, uses %q; want if %q", lane.job, setupBazel.If, setupBazel.Uses, bazelPathIf) + } + + // The go-build-fallback path: gated on detection and the farm being + // down; it restores caches but never sets BEADS_TEST_BD_BINARY, so + // prepare_bd_binary() falls back to `go build`. + for _, name := range []string{"Set up Go", "Restore Go module cache", "Verify Go modules", "Restore non-race Go build cache"} { + if st := job.step(t, name); st.If != fallbackIf { + t.Errorf("%s step %q: if %q, want %q", lane.job, name, st.If, fallbackIf) + } + } + + // The language setup and the gate command run whenever detection + // did, whichever bd path provided the binary. + if st := job.step(t, lane.langStepName); st.If != detectIf { + t.Errorf("%s step %q: if %q, want %q", lane.job, lane.langStepName, st.If, detectIf) + } + + // The language setup itself must not drift from main.yml's copy of + // the same job (python-version / Node version / the uv install + // command): main.yml's jobs are ungated by rbe, so they are the one + // other place this exact setup is pinned. + mainJob := mainWorkflow.job(t, lane.job) + langStep := job.step(t, lane.langStepName) + mainLangStep := mainJob.step(t, lane.langStepName) + if langStep.Uses != mainLangStep.Uses || !reflect.DeepEqual(langStep.With, mainLangStep.With) { + t.Errorf("%s %q: uses %q, with %v; main.yml's %s has uses %q, with %v", + lane.job, lane.langStepName, langStep.Uses, langStep.With, lane.job, mainLangStep.Uses, mainLangStep.With) + } + if lane.job == bazelPackageMCPJobName { + installUv := job.step(t, "Install uv") + mainInstallUv := mainJob.step(t, "Install uv") + if installUv.Run != mainInstallUv.Run { + t.Errorf("%s Install uv: run %q; main.yml's has run %q", lane.job, installUv.Run, mainInstallUv.Run) + } + } + gateName := "Run " + map[string]string{bazelPackageMCPJobName: "MCP", bazelPackageNPMJobName: "npm"}[lane.job] + " package gate" + gate := job.step(t, gateName) + if gate.If != detectIf || gate.Run != lane.makeTarget { + t.Errorf("%s gate step: if %q, run %q; want if %q, run %q", lane.job, gate.If, gate.Run, detectIf, lane.makeTarget) + } + if job.stepIndex(t, gateName) != len(job.Steps)-2 { + t.Errorf("%s gate step is not the last step before the result recorder", lane.job) + } + } +} + // The Dolt server fingerprint (container image vs the pinned dolt CLI the // Bazel dolt-server lanes start) runs on every PR in its own required job, // whatever bazel-coverage says, and nowhere else in pr.yml. diff --git a/scripts/pr_risk_bazel_coverage_test.go b/scripts/pr_risk_bazel_coverage_test.go index 06e6fb3f4..6b50f2127 100644 --- a/scripts/pr_risk_bazel_coverage_test.go +++ b/scripts/pr_risk_bazel_coverage_test.go @@ -271,9 +271,12 @@ func workflowEnv(t *testing.T, name string) map[string]string { func TestPRRiskBazelCoverageJob(t *testing.T) { risk := readCIWorkflow(t, prRiskWorkflowName) job := risk.job(t, prRiskCoverageJobName) - if len(job.Needs) != 0 || job.If != "" || job.RunsOn != "ubuntu-latest" || len(job.Env) != 0 || job.ContinueOnError || job.TimeoutMinutes == 0 { - t.Errorf("%s: needs %v, if %q, runs-on %q, env %v, continue-on-error %v, timeout %d; want no needs, if, env or continue-on-error, ubuntu-latest, a timeout", - prRiskCoverageJobName, job.Needs, job.If, job.RunsOn, job.Env, job.ContinueOnError, job.TimeoutMinutes) + // F3: this job moved to Blacksmith for same-repo PRs (and merge_group); + // forks and Dependabot stay on ubuntu-latest (TestSameRepoBlacksmithRunners + // pins the same literal for pr.yml's copy). + if len(job.Needs) != 0 || job.If != "" || job.RunsOn != sameRepoBlacksmith2vcpu || len(job.Env) != 0 || job.ContinueOnError || job.TimeoutMinutes == 0 { + t.Errorf("%s: needs %v, if %q, runs-on %q, env %v, continue-on-error %v, timeout %d; want no needs, if, env or continue-on-error, on %q, a timeout", + prRiskCoverageJobName, job.Needs, job.If, job.RunsOn, job.Env, job.ContinueOnError, job.TimeoutMinutes, sameRepoBlacksmith2vcpu) } wantOutputs := map[string]string{} wantEnv := map[string]string{"PULL_REQUEST": prRiskPullRequestValue, "DEPENDABOT": prRiskDependabotValue} @@ -332,6 +335,15 @@ func TestPRRiskBazelCoverageJob(t *testing.T) { if secretRef.MatchString(value) { t.Errorf("%s: %s reads secrets (%q); PR Risk needs none", prRiskWorkflowName, path, value) } + // F3: detect-ci-tier/bazel-coverage/ci-gate's own runs-on picks a + // runner venue (Blacksmith vs ubuntu-latest) for trusted same-repo + // PRs; it shares some predicates (github.actor, dependabot, + // head.repo.full_name) with the coverage decision but decides + // something else entirely - not a re-derivation of the decision + // (TestSameRepoBlacksmithRunners pins the literal). + if strings.HasSuffix(path, ".runs-on") && value == sameRepoBlacksmith2vcpu { + return + } if facts.MatchString(value) && !strings.HasPrefix(path, stepEnv) && !strings.HasPrefix(path, ".jobs."+prRiskCoverageJobName+".steps[0].run") { t.Errorf("%s: %s re-derives the Bazel coverage decision (%q); read needs.%s.outputs", prRiskWorkflowName, path, value, prRiskCoverageJobName) }