|
| 1 | +--- |
| 2 | +name: pre-push-gate |
| 3 | +description: "Run this repo's pre-push gate and fix it when it goes red. Use when npm run local:gate fails or a stage of it does (verify:install-fresh, a root guard, lint, typecheck, ruff, pyright, pytest, verify:skills:cli, the boot smoke); when the gate says it is waiting on the gate lease; or when checking whether a gate run really passed." |
| 4 | +disable-model-invocation: false |
| 5 | +--- |
| 6 | + |
| 7 | +# The pre-push gate |
| 8 | + |
| 9 | +**The rule** (stated in [`AGENTS.md`](../../../AGENTS.md#before-pushing)): run |
| 10 | +**`npm run local:gate`** before every push, and push only when it exits 0. |
| 11 | +`npm run validate` is the inner-loop check and is **not** a substitute. |
| 12 | + |
| 13 | +What each stage covers, and how the gate relates to CI, is |
| 14 | +[`docs/quality-gate.md`](../../../docs/quality-gate.md). The stage list is |
| 15 | +written out there and nowhere else, on purpose. This skill is how to run the |
| 16 | +gate and what to do when it goes red. |
| 17 | + |
| 18 | +## Run it |
| 19 | + |
| 20 | +```sh |
| 21 | +cd <repo root> |
| 22 | +npm run format # TypeScript. It rewrites files; the gate only checks. |
| 23 | +npm run local:gate; echo "EXIT=$?" |
| 24 | +``` |
| 25 | + |
| 26 | +In a Python server you changed, format with `uv run --frozen ruff format .` |
| 27 | +from that server's directory. |
| 28 | + |
| 29 | +**Verify by exit code, not by grepping the output.** A Prettier failure is a |
| 30 | +few `[warn]` lines that match no obvious failure pattern, and `validate:py` |
| 31 | +prints `PASS` for two servers above the `FAIL` for the third. |
| 32 | + |
| 33 | +⚠️ If you run it as a background task, the harness's "exit code 0" |
| 34 | +notification describes the _wrapper_ (the trailing `echo`), not the gate. Read |
| 35 | +the `EXIT=` line. |
| 36 | + |
| 37 | +**Background it and wait for the notification.** Do not spend turns tailing |
| 38 | +the log; see `AGENTS.md` **Waiting on long-running work**. |
| 39 | + |
| 40 | +The gate stops at the first failing stage, so the last stage header in the |
| 41 | +output is the one that failed. Fix it, then **re-run the whole gate**, not just |
| 42 | +that stage: the stages after it have not run yet. |
| 43 | + |
| 44 | +## Diagnosing a failing stage |
| 45 | + |
| 46 | +Each heading is a stage or guard name as it appears in the output. |
| 47 | + |
| 48 | +### `verify:install-fresh` |
| 49 | + |
| 50 | +An installed package's version disagrees with `package-lock.json` |
| 51 | +(`node_modules` is older than the tree you pulled), or a `package.json` |
| 52 | +declares a dependency the lockfile does not record. **Run `npm install` at the |
| 53 | +repo root**, commit the lockfile if it changed, and re-run. It is the first stage because a stale install otherwise |
| 54 | +passes every static check and fails later as a test reporting the _old_ |
| 55 | +dependency's behavior. Do not "fix" that test. |
| 56 | + |
| 57 | +### `format:check` / `format:check:root` |
| 58 | + |
| 59 | +Run `npm run format` at the **root**. It covers `scripts/`, the root configs |
| 60 | +and every workspace; a single workspace's `format` does not. |
| 61 | + |
| 62 | +### `verify:format-coverage` |
| 63 | + |
| 64 | +A tracked source file is matched by no `format:check` glob, so nothing checks |
| 65 | +its formatting. Put it where a glob reaches it, or extend the glob. Do not add |
| 66 | +it to `.prettierignore` to make the guard pass. |
| 67 | + |
| 68 | +### `verify:skills` / `verify:skills:cli` |
| 69 | + |
| 70 | +A `.claude/skills` manifest does not parse, declares no |
| 71 | +`disable-model-invocation`, a model-invoked skill lacks its eval cases, or the |
| 72 | +listing is over budget. The message names the skill. The usual cause is an |
| 73 | +unquoted `#` or `:` in a `description`. |
| 74 | + |
| 75 | +`verify:skills:cli` is the authoritative validator. It fetches the pinned |
| 76 | +Claude Code CLI with `npx` when the installed one is a different version, so it |
| 77 | +**fails offline**. (`validate:py`'s `sync` step is the other stage that can: |
| 78 | +`uv sync --locked` downloads when a server's environment is missing or stale.) |
| 79 | + |
| 80 | +### `verify:typecheck-coverage` |
| 81 | + |
| 82 | +A tracked `.ts` file lands in no `tsc` program. Usually a new test or config |
| 83 | +file outside the server's `tsconfig.test.json` `include`. Add it there. |
| 84 | + |
| 85 | +### `verify:dep-lockstep` |
| 86 | + |
| 87 | +Two workspaces declare different ranges of a shared toolchain package |
| 88 | +(`typescript`, `vitest`, `@vitest/coverage-v8`, `prettier`, `@types/node`). |
| 89 | +Bump it in **every** workspace that declares it, then `npm install`. |
| 90 | + |
| 91 | +### `verify:no-test-retries` |
| 92 | + |
| 93 | +A test declares a retry: Vitest's `retry:` option or `--retry` flag, a pytest |
| 94 | +rerun plugin, or a `flaky` marker. Remove it and fix why the test fails. A race |
| 95 | +is fixed with fake timers or an awaited condition; a port collision with a port |
| 96 | +the OS hands out. |
| 97 | + |
| 98 | +The guard matches spellings, not semantics, so an unrelated `retry:` property |
| 99 | +in server source trips it too. Rename the property, or restructure so the key |
| 100 | +is not written as `retry:` at the start of an expression. |
| 101 | + |
| 102 | +### `test:scripts` |
| 103 | + |
| 104 | +A guard's own unit test failed. Two of these are about the gate itself and |
| 105 | +mean a change broke one of its invariants |
| 106 | +(`scripts/lib/workflow-gate.test.mjs`): |
| 107 | + |
| 108 | +- **"GitHub CI must not run a local-only script"**: a workflow invokes a |
| 109 | + `local:*` script. Call the underlying checks as their own steps instead. |
| 110 | +- **"every CI job needs a timeout"**: a job was added without |
| 111 | + `timeout-minutes`. |
| 112 | +- **"local:gate must run …"**: a stage was dropped from `local:gate:stages`, |
| 113 | + or `local:gate` is no longer exactly the lease wrapper. |
| 114 | + |
| 115 | +Do not edit the guard to make these pass; the split they enforce is the design. |
| 116 | + |
| 117 | +### `lint` |
| 118 | + |
| 119 | +**There is no warning tier.** Every `lint` script runs `--max-warnings 0`, so |
| 120 | +a warning fails exactly as an error does. Fix the finding. If a rule genuinely |
| 121 | +must be waived on one line, use its inline disable comment **with a one-line |
| 122 | +justification**; never widen an ignore list or turn the rule off. |
| 123 | + |
| 124 | +### `typecheck` / `build` |
| 125 | + |
| 126 | +`typecheck` runs `tsc -p tsconfig.test.json` (source and tests); `build` runs |
| 127 | +the server's own `tsc`. An error in a test file only shows in `typecheck`. |
| 128 | + |
| 129 | +### `test` (a TypeScript workspace) |
| 130 | + |
| 131 | +Re-run just that suite to iterate: `npm test -w src/<server>`. Read the failure |
| 132 | +before changing a timeout: an assertion that races is a bug in the test. |
| 133 | + |
| 134 | +### `validate:py` |
| 135 | + |
| 136 | +The summary at the end names the failing server, and the step that failed is |
| 137 | +the last `[validate:py] <server>: <step>` line above it. Re-run one server with |
| 138 | +`npm run validate:py -- <server>`. |
| 139 | + |
| 140 | +| Step | Fix | |
| 141 | +| --- | --- | |
| 142 | +| `sync` | `uv.lock` no longer matches `pyproject.toml`. Run `uv lock` in that server and commit the lockfile | |
| 143 | +| `ruff check` | Fix the finding; `uv run --frozen ruff check --fix .` handles the mechanical ones | |
| 144 | +| `ruff format --check` | `uv run --frozen ruff format .` | |
| 145 | +| `pyright` | A type error. Add the missing hint rather than an ignore | |
| 146 | +| `pytest` | `uv run --frozen pytest -k <name>` in that server to iterate | |
| 147 | +| `build` | A packaging error in `pyproject.toml` | |
| 148 | + |
| 149 | +`uv: command not found` means `uv` is not installed. Never substitute `pip`. |
| 150 | + |
| 151 | +### `smoke` |
| 152 | + |
| 153 | +`smoke — FAIL <server> over <transport>` followed by the reason and the tail |
| 154 | +of the server's stderr. Re-run a subset with |
| 155 | +`node scripts/smoke-servers.mjs <server> [<server> …]`. |
| 156 | + |
| 157 | +- **"dist/index.js does not exist — build first"**: you ran the smoke on its |
| 158 | + own before building. `npm run build -w src/<server>`. Inside the gate this |
| 159 | + cannot happen, since `validate` builds first. |
| 160 | +- **".venv does not exist — sync first"**: the same for a Python server. The |
| 161 | + smoke never creates an environment; `npm run validate:py -- <server>` does. |
| 162 | +- **The server exited before answering**: the stderr tail shows why. This is |
| 163 | + what the smoke is for: the unit tests import the source, so a wrong `bin` |
| 164 | + path, a file missing from `dist/`, or an import that only resolves under the |
| 165 | + test runner passes them and fails here. |
| 166 | +- **"tools/list does not include …"**: a tool was renamed or removed. A |
| 167 | + published tool is never renamed (`AGENTS.md` **MCP protocol**); if the change |
| 168 | + is intended, update that server's entry in `SERVERS`. |
| 169 | +- **A new server fails `test:scripts`** with "every server directory in the |
| 170 | + repo has a smoke entry": add it to `SERVERS` in `scripts/smoke-servers.mjs`. |
| 171 | + |
| 172 | +## Waiting on the lease |
| 173 | + |
| 174 | +A gate that starts with |
| 175 | + |
| 176 | +``` |
| 177 | +gate-lease: pid 12345 in /path/to/other-worktree, running for 40s holds the gate lease; waiting for its turn so the gates do not contend. SERVERS_SKIP_GATE_LEASE=1 runs anyway. |
| 178 | +``` |
| 179 | + |
| 180 | +is queued behind another worktree's gate. That is normal: it starts once the |
| 181 | +holder (and any gate that arrived before it) finishes. The line names the |
| 182 | +holder's pid and worktree, so you can tell whether to wait or to stop that |
| 183 | +gate. |
| 184 | + |
| 185 | +- A holder that was **killed** stops refreshing its lock and is taken over |
| 186 | + after 30 seconds. Nothing needs cleaning up. |
| 187 | +- A waiter that prints `gave up after 45m` names a lock path. Check whether |
| 188 | + the holder it names is alive and hung (stop it), or dead with a lock |
| 189 | + directory that could not be removed (remove that directory). |
| 190 | +- Do **not** set `SERVERS_SKIP_GATE_LEASE=1` to get a result sooner. Two |
| 191 | + overlapping gates each take longer than one queued behind the other. |
| 192 | +- Do **not** write your own "wait until no gate is running" loop. Two of them |
| 193 | + deadlock on each other, and a `pgrep` for the gate's command line matches the |
| 194 | + loop itself. |
| 195 | + |
| 196 | +The details of the lease are in |
| 197 | +[`docs/quality-gate.md`](../../../docs/quality-gate.md#the-gate-lease). |
| 198 | + |
| 199 | +## Not part of the gate |
| 200 | + |
| 201 | +`npm run skills:eval` (real model calls) and `npm run coverage` (a report; no |
| 202 | +threshold is enforced yet) are separate commands. Run the eval suite when you |
| 203 | +add a skill or change a description. |
0 commit comments