Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions .claude/skills/pr-flow/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,26 @@ npm run format # TypeScript; in a Python server: uv run --fro
npm run local:gate; echo "EXIT=$?"
```

`local:gate` runs every check CI runs, for both languages, whatever the change
touched. Verify by the exit code, not by grepping the output. What each stage
checks and how to fix a red one is `/pre-push-gate`; the stage list is
`local:gate` runs every check CI runs, for both languages. Its per-server
stages run for the servers the change touches, and for every server when any
file outside a server directory changed; it prints which, and why. Verify by
the exit code, not by grepping the output. What each stage checks and how to
fix a red one is `/pre-push-gate`; the stage list and the scope rule are in
[`docs/quality-gate.md`](../../../docs/quality-gate.md).

**A draft PR** (`gh pr create --draft`) needs less until it is marked ready
(`AGENTS.md` **Before pushing**):

| The PR is | Before each push | In CI |
| --- | --- | --- |
| A draft | `npm run local:gate:draft` (exit 0): `verify:dco` and the touched servers' full `validate` / `validate:py` | Format, lint, typecheck, build and tests; coverage, the boot smoke, the interface diff and the image smoke are skipped |
| Being marked ready | A full `npm run local:gate` (exit 0), then `gh pr ready <PR>` | `ready_for_review` runs what the draft skipped |
| Ready | `npm run local:gate`, as above | Everything |

A draft is for work still moving, when you want CI or a reviewer's eye before
it settles. A PR that is finished when it opens is opened ready, after a full
gate, as above; the Copilot loop (step 7) starts once it is ready.

One thing the gate deliberately leaves out:

| Change touches | Also run |
Expand Down
58 changes: 50 additions & 8 deletions .claude/skills/pre-push-gate/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ disable-model-invocation: false

**The rule** (stated in [`AGENTS.md`](../../../AGENTS.md#before-pushing)): run
**`npm run local:gate`** before every push, and push only when it exits 0.
`npm run validate` is the inner-loop check and is **not** a substitute.
`npm run validate` is the inner-loop check and is **not** a substitute. The
one lighter gate is **`npm run local:gate:draft`**, for a push to a PR that is
still a draft; marking the PR ready for review needs a full `local:gate`
first, and so does every push after that.

What each stage covers, and how the gate relates to CI, is
[`docs/quality-gate.md`](../../../docs/quality-gate.md). The stage list is
Expand Down Expand Up @@ -41,6 +44,33 @@ The gate stops at the first failing stage, so the last stage header in the
output is the one that failed. Fix it, then **re-run the whole gate**, not just
that stage: the stages after it have not run yet.

## Which servers it ran

The per-server stages (`check`, `coverage`, `validate:py`, `coverage:py`,
`smoke`) run through `scripts/gate-servers.mjs`, which prints its choice
first:

```
[gate] base 002bcceed159
[gate] servers: memory — every changed file is under `src/memory/`
```

and then one `[gate] <stage>: <command>` line per step, with `passed (Ns)` or
`FAILED (exit N, Ns)` after it. A change confined to server directories gates
those servers; **any file outside one gates every server**, and the line names
the first few such files. If it gated more than you expected, that line says
why: an untracked file in the worktree root counts too (`git status`). Do not
work around the scope; the rule is in
[`docs/quality-gate.md`](../../../docs/quality-gate.md#which-servers-the-gate-runs).

- **"could not decide which servers to gate"**: usually `origin/v2/main` is
missing, so `git fetch origin v2/main`. On a stacked branch,
`GATE_BASE=<parent branch> npm run local:gate` scopes against the parent.
- **Each suite runs once, under coverage.** A failing test shows up in the
`coverage` or `coverage:py` step, not in a plain `test` or `pytest` step;
fix it as under [`test`](#test-a-typescript-workspace) or `validate:py`'s
`pytest` below.

## Diagnosing a failing stage

Each heading is a stage or guard name as it appears in the output.
Expand Down Expand Up @@ -148,7 +178,9 @@ mean a change broke one of its invariants
- **"every CI job needs a timeout"**: a job was added without
`timeout-minutes`.
- **"local:gate must run …"**: a stage was dropped from `local:gate:stages`,
or `local:gate` is no longer exactly the lease wrapper.
or `local:gate` is no longer exactly the lease wrapper. The per-server
stages are pinned through `gatePlan` in `scripts/gate-servers.mjs` ("the
full gate must run …").

Do not edit the guard to make these pass; the split they enforce is the design.

Expand All @@ -159,15 +191,23 @@ a warning fails exactly as an error does. Fix the finding. If a rule genuinely
must be waived on one line, use its inline disable comment **with a one-line
justification**; never widen an ignore list or turn the rule off.

### `check` (a TypeScript workspace)

The workspace's `validate` without its tests: `format:check`, `lint`,
`typecheck`, `build`, in that order. The failing one is named in the npm
output; each has its own section here.

### `typecheck` / `build`

`typecheck` runs `tsc -p tsconfig.test.json` (source and tests); `build` runs
the server's own `tsc`. An error in a test file only shows in `typecheck`.

### `test` (a TypeScript workspace)

Re-run just that suite to iterate: `npm test -w src/<server>`. Read the failure
before changing a timeout: an assertion that races is a bug in the test.
The full gate runs the suite only under `coverage`; `local:gate:draft` runs it
plainly, inside each workspace's `validate`. Re-run just that suite to
iterate: `npm test -w src/<server>`. Read the failure before changing a
timeout: an assertion that races is a bug in the test.

### `coverage`

Expand All @@ -179,8 +219,8 @@ ERROR: Coverage for branches (71.42%) does not meet global threshold (90%) for r
```

("global threshold" is Vitest's wording; with `perFile: true` it is checked
per file.) The root `npm run coverage` carries on into the remaining
workspaces after a failure, so **the failing report is not the last thing
per file.) Over several workspaces, `npm run coverage` carries on into the
remaining ones after a failure, so **the failing report is not the last thing
printed**: find the `npm ERR!` block, which names the workspace
(`in workspace: @modelcontextprotocol/server-<name>`), and read the `ERROR:`
lines just above it.
Expand All @@ -207,7 +247,9 @@ fix it as under `test`, above.

The summary at the end names the failing server, and the step that failed is
the last `[validate:py] <server>: <step>` line above it. Re-run one server with
`npm run validate:py -- <server>`.
`npm run validate:py -- <server>`. The full gate passes `--no-pytest`, since
`coverage:py` runs the suite next; `local:gate:draft` and a bare
`npm run validate:py` run it here.

| Step | Fix |
| --- | --- |
Expand Down Expand Up @@ -260,7 +302,7 @@ of the server's stderr. Re-run a subset with

- **"dist/index.js does not exist — build first"**: you ran the smoke on its
own before building. `npm run build -w src/<server>`. Inside the gate this
cannot happen, since `validate` builds first.
cannot happen, since `check` builds first.
- **".venv does not exist — sync first"**: the same for a Python server. The
smoke never creates an environment; `npm run validate:py -- <server>` does.
- **The server exited before answering**: the stderr tail shows why. This is
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/image-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ on:
branches: [main, v2/main]
# No branch filter: PRs to v2/main and to main both run, and so does a PR
# stacked on another PR's branch. The base is the PR's own base either way.
# A draft PR is skipped (#5759, the `if:` on `changes`); `ready_for_review`
# runs it once it is marked ready, and every later push runs it too.
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:

permissions:
Expand All @@ -50,6 +53,9 @@ concurrency:
jobs:
changes:
name: Choose the images to build
# Every other job here needs this one, so skipping it on a draft skips
# the whole run.
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
timeout-minutes: 10
runs-on: ubuntu-latest
outputs:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/mcp-interface-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ on:
branches: [main, v2/main]
# No branch filter: PRs to v2/main and to main both run, and so does a PR
# stacked on another PR's branch. The base is the PR's own base either way.
# A draft PR is skipped (#5759, the `if:` on `changes`); `ready_for_review`
# runs it once it is marked ready, and every later push runs it too.
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
# A published Release (a milestone, tagged vX.Y.Z on main; see RELEASING.md)
# surfaces the cumulative interface delta since the previous Release, for
# each server that changed in between. This replaces #3260's
Expand Down Expand Up @@ -99,6 +102,9 @@ concurrency:
jobs:
changes:
name: Choose the servers to diff
# Every other job here needs this one, so skipping it on a draft skips
# the whole run.
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
timeout-minutes: 10
runs-on: ubuntu-latest
permissions:
Expand Down
63 changes: 56 additions & 7 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Python

on:
# Push only, as in the Inspector: with pull_request as well, every commit on a
# PR branch ran each workflow twice (once per event). PR checks still report
# from the push run of the head commit.
# Push, as in the Inspector: with every pull_request event as well, every
# commit on a PR branch ran each workflow twice (once per event). PR checks
# still report from the push run of the head commit. The one pull_request
# event taken, `ready_for_review` below, runs only what a draft skipped.
push:
# A push made with the workflow token starts no workflow, so the version PRs
# that automation opens (Version Packages, Prepare Python Release) get no
Expand All @@ -13,6 +14,11 @@ on:
# leaves dispatched checks out, so the `dispatch-status` jobs below report
# the run as a commit status instead.
workflow_dispatch:
# A draft pull request's pushes skip the coverage gate (#5759; see the
# `draft` job). Marking it ready for review runs exactly that, against the
# PR's merge commit; every later push runs it too.
pull_request:
types: [ready_for_review]

# Superseded runs on the same ref are cancelled (e.g. rapid amend-pushes),
# except on main, where every merge keeps its own CI run
Expand All @@ -28,6 +34,37 @@ permissions:
contents: read

jobs:
# Whether this push goes to a draft pull request's branch (#5759): the same
# job as in typescript.yml. A draft still gets ruff, pyright, pytest and the
# build on every push; the coverage gate waits until it is marked ready. Any
# other run, and a failed lookup, reads as not a draft.
draft:
timeout-minutes: 5
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
draft: ${{ steps.state.outputs.draft }}
steps:
- name: Look up the branch's pull request
id: state
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
EVENT: ${{ github.event_name }}
BRANCH: ${{ github.ref_name }}
run: |
DRAFT=false
# v2/main is the head of the release merge PR into main, which can
# be a draft; neither long-lived branch is ever a draft's branch.
if [ "$EVENT" = push ] && [ "$BRANCH" != v2/main ] && [ "$BRANCH" != main ]; then
DRAFT=$(gh pr list --head "$BRANCH" --state open --json isDraft \
--jq 'if length > 0 and all(.[]; .isDraft) then "true" else "false" end') \
|| DRAFT=false
fi
echo "draft=$DRAFT" >> "$GITHUB_OUTPUT"
echo "draft pull request: $DRAFT"

detect-packages:
timeout-minutes: 5
runs-on: ubuntu-latest
Expand All @@ -45,6 +82,9 @@ jobs:

script-tests:
timeout-minutes: 5
# The draft's last push ran it; the ready event re-runs only what a
# draft skips.
if: github.event_name != 'pull_request'
name: Test the Python gate script
runs-on: ubuntu-latest
steps:
Expand All @@ -59,7 +99,8 @@ jobs:

test:
timeout-minutes: 15
needs: [detect-packages]
needs: [detect-packages, draft]
if: github.event_name != 'pull_request'
strategy:
matrix:
package: ${{ fromJson(needs.detect-packages.outputs.packages) }}
Expand All @@ -81,17 +122,23 @@ jobs:
node-version: 24

# The same per-server chain `npm run validate:py` runs locally: locked
# sync, ruff check, ruff format --check, pyright, pytest, uv build.
# sync, ruff check, ruff format --check, pyright, pytest, uv build. Each
# suite runs once (#5759): pytest is left to the `coverage` job, which
# runs it instrumented, except on a draft, where `coverage` is skipped.
- name: Validate
run: node scripts/validate-py.mjs ${{ matrix.package }}
env:
NO_PYTEST: ${{ needs.draft.outputs.draft != 'true' && '--no-pytest' || '' }}
run: node scripts/validate-py.mjs $NO_PYTEST ${{ matrix.package }}

# The per-file coverage gate (#4855), in parallel with `test`: every file of
# each server at >= 90% on lines and on branches. The same script
# `npm run coverage:py` runs locally, one server per leg. fail-fast is off so
# one server's shortfall does not cancel the other legs' verdicts.
coverage:
timeout-minutes: 15
needs: [detect-packages]
needs: [detect-packages, draft]
# Skipped on a draft (#5759), whose `test` legs run pytest instead.
if: needs.draft.outputs.draft != 'true'
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -121,6 +168,7 @@ jobs:
test-windows:
timeout-minutes: 20
needs: [detect-packages]
if: github.event_name != 'pull_request'
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -239,6 +287,7 @@ jobs:
needs:
[
dispatch-status-pending,
draft,
detect-packages,
script-tests,
test,
Expand Down
Loading