diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 91da730a..421f383a 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -20,6 +20,8 @@ on: permissions: contents: write pull-requests: write + # verify-ci's `gh api` calls read the CI workflow's runs + jobs. + actions: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -72,6 +74,106 @@ jobs: echo "version=${{ steps.release.outputs.version }}" >> "$GITHUB_OUTPUT" fi + # ---------------------------------------------------------------- + # verify-ci: gate the release on the SAME tag commit's CI result. + # + # We do NOT re-run cargo tests here — we QUERY the existing `CI` workflow + # run for the exact tag commit SHA (event=push, branch=main) and wait for + # its `CI Success` job to conclude. Gating on that single job (which itself + # needs test/audit/windows) is the right wait point: it excludes the slow + # informational Coverage job. + # + # Topology: this runs IN PARALLEL with build-binaries (build-binaries needs + # only release-please), so the ~430s cross-compile overlaps with the CI wait. + # The gate is enforced downstream at upload-assets (which lists verify-ci in + # `needs`) — the first public-facing step that touches the GitHub Release. + # build-binaries only produces throwaway artifacts (retention-days: 1), so a + # failed/timed-out verify-ci blocks upload-assets + publish-release and leaves + # the Release a DRAFT, without weakening the gate. + # + # This job ALWAYS RUNS when a tag was cut (build_artifacts=='true'); it must + # never be SKIPPED, because upload-assets lists it in `needs` and a skipped + # needed job would cascade-skip upload-assets. On the workflow_dispatch + # (manual re-attach) path there is no new CI run, so the job short-circuits + # to success as a no-op; the polling steps run only on the push path. + # ---------------------------------------------------------------- + verify-ci: + name: Verify CI Passed + needs: release-please + if: needs.release-please.outputs.build_artifacts == 'true' + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Manual re-attach — skip CI gate (no-op success) + if: github.event_name == 'workflow_dispatch' + run: | + echo "workflow_dispatch: re-attaching binaries to an existing tag; no new CI run to gate on — passing." + + - name: Checkout tag + if: github.event_name == 'push' + uses: actions/checkout@v5 + with: + fetch-depth: 0 + ref: ${{ needs.release-please.outputs.tag_name }} + + - name: Resolve tag commit SHA + id: sha + if: github.event_name == 'push' + run: echo "sha=$(git rev-list -n1 '${{ needs.release-please.outputs.tag_name }}')" >> "$GITHUB_OUTPUT" + + - name: Wait for CI Success on the tag commit + if: github.event_name == 'push' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + HEAD_SHA: ${{ steps.sha.outputs.sha }} + run: | + set -euo pipefail + # Bounded poll: ~25 min cap (100 iterations x 15s) inside timeout-minutes: 30. + max_iters=100 + sleep_secs=15 + run_id="" + for i in $(seq 1 "$max_iters"); do + # Select the CI workflow's push run on main for the exact tag SHA; + # if several exist, take the most recent by created_at. + run_id=$(gh api "repos/${REPO}/actions/runs?head_sha=${HEAD_SHA}&event=push&branch=main&per_page=100" \ + --jq '[.workflow_runs[] | select(.name == "CI")] | sort_by(.created_at) | last | .id // empty') + if [ -n "$run_id" ]; then + echo "Found CI run ${run_id} for ${HEAD_SHA}" + break + fi + echo "No CI run for ${HEAD_SHA} yet (attempt ${i}/${max_iters}); sleeping ${sleep_secs}s..." + sleep "$sleep_secs" + done + if [ -z "$run_id" ]; then + echo "❌ Timed out waiting for a CI run on ${HEAD_SHA}; leaving release as draft." + exit 1 + fi + for i in $(seq 1 "$max_iters"); do + status=$(gh api "repos/${REPO}/actions/runs/${run_id}/jobs?per_page=100" \ + --jq '.jobs[] | select(.name == "CI Success") | .status') + conclusion=$(gh api "repos/${REPO}/actions/runs/${run_id}/jobs?per_page=100" \ + --jq '.jobs[] | select(.name == "CI Success") | .conclusion // ""') + if [ -z "$status" ]; then + echo "CI Success job not present in run ${run_id} yet (attempt ${i}/${max_iters}); sleeping ${sleep_secs}s..." + sleep "$sleep_secs" + continue + fi + if [ "$status" != "completed" ]; then + echo "CI Success job status=${status} (attempt ${i}/${max_iters}); sleeping ${sleep_secs}s..." + sleep "$sleep_secs" + continue + fi + if [ "$conclusion" = "success" ]; then + echo "✅ CI Success passed for ${HEAD_SHA}." + exit 0 + fi + echo "❌ CI Success concluded '${conclusion}' for ${HEAD_SHA}; blocking release (draft preserved)." + exit 1 + done + echo "❌ Timed out waiting for CI Success to complete on ${HEAD_SHA}; leaving release as draft." + exit 1 + # ---------------------------------------------------------------- # build-binaries: cross-compile release artifacts for all targets. # Gated on a cut tag. The CLI crate is `codegraph-rs`, binary `codegraph`. @@ -182,7 +284,7 @@ jobs: # ---------------------------------------------------------------- upload-assets: name: Upload Release Assets - needs: [release-please, build-binaries] + needs: [release-please, build-binaries, verify-ci] if: needs.release-please.outputs.build_artifacts == 'true' runs-on: ubuntu-latest timeout-minutes: 15 diff --git a/crates/codegraph-mcp/tests/reopen.rs b/crates/codegraph-mcp/tests/reopen.rs index bf0100c4..48952767 100644 --- a/crates/codegraph-mcp/tests/reopen.rs +++ b/crates/codegraph-mcp/tests/reopen.rs @@ -134,31 +134,34 @@ fn reopens_cached_engine_when_db_replaced_with_new_inode() { ); let reopens_before = reopen_count(); - // When: the db is REPLACED on disk with a fresh index (new identity) whose - // content differs (a new symbol `betaSymbol`). The cached engine still holds - // an open WAL connection, which on windows blocks deleting the db dir - // (OS error 32). Drop the live connections first — `close_cached_handles` - // keeps the cache RECORD (with its old identity) while releasing the file - // handle, so the next call still detects the identity change and counts - // exactly one reopen. Removing the dir first guarantees a freshly built db. - let id_before = db_identity(project.path()); + // When: the db is REPLACED on disk with a fresh index whose content differs + // (a new symbol `betaSymbol`). The cached engine still holds an open WAL + // connection, which on windows blocks deleting the db dir (OS error 32). + // Drop the live connections first — `close_cached_handles` releases the file + // handle while keeping the cache RECORD, so the next call reopens exactly + // once and re-reads the freshly built db from disk. Removing the dir first + // guarantees a freshly built db. + // + // We deliberately do NOT assert the raw `DbIdentity` changed here. On unix + // the identity is the inode, and the OS is free to RECYCLE the just-deleted + // db's inode for the rebuilt file (observed under `cargo llvm-cov`: both = + // 1343671), so an `assert_ne!(id_before, id_after)` gambles on an OS + // implementation detail that delete+rebuild does not guarantee. That inode + // assertion was the sole flake source and is redundant with #925's real + // contract, which is the BEHAVIORAL outcome asserted below and does not + // depend on inode luck: the SAME cached server reopens its engine and serves + // the NEW on-disk content. Serving `betaSymbol` (not `alphaSymbol`, not an + // open error) is itself the proof the engine reopened against the fresh db. server.close_cached_handles(); fs::remove_dir_all(project.path().join(".codegraph")).unwrap(); index_into( project.path(), &[("src/b.ts", "export function betaSymbol() {}\n")], ); - let id_after = db_identity(project.path()); - assert_ne!( - id_before, id_after, - "replace must change DbIdentity (inode on unix; \ - len/creation_time/header-sig fold on non-unix — the rebuild changes \ - the SQLite page count + schema cookie deterministically)" - ); // Then: the SAME server's SAME tool call must REOPEN the engine — without the - // #925 fix the cached engine keeps serving inode A and `reopen_count` never - // advances (this delta is the deterministic RED probe). + // #925 fix the cached engine keeps serving the old db and `reopen_count` + // never advances (this delta is the deterministic RED probe). let after = search(&mut server, project.path(), "betaSymbol"); let reopens_after = reopen_count(); assert_eq!(