@nodii/review-gates
v0.4.1
Published
Hermetic review gates for the Nodii microservice stack — the D367 / 12-testing-doctrine §3.1 service-wired gate (proves a service SERVES its own gRPC/consumers) as a consuming-repo-relative runner + BIN, so services adopt one dependency instead of copying
Readme
@nodii/review-gates (TS)
Hermetic review gates for the Nodii microservice stack, packaged as a runner + BIN so services adopt one dependency instead of copying a template into every repo.
Today it ships the service-wired gate (D367 / 12-testing-doctrine §3.1):
proves a service actually serves its own gRPC + boots its own consumers,
so a contract is never marked implemented while UNWIRED (the R1
deploy-readiness failure caught on nodii-crm-service 2026-06-18).
Wired = all three (D367 §3.1):
addService(...)registered for EVERY served gRPC service the repo declares (proto/*.proto, excludingproto/client/), and the generated stubs (bun grpc:genoutput) present.- Every declared consumer/replica + owned outbox drainer is actually BOOTED
(
startReplicaConsumer(...)/startDispatcher(...)), not just defined. - Generated gRPC stubs exist (typecheck is enforced by the same review run).
It is hermetic (only node:fs/node:path, no network) and inert
until the service declares ≥1 served gRPC service or ≥1 consumer/producer — a
greenfield service passes vacuously.
Programmatic use
import { runServiceWiredGate } from "@nodii/review-gates";
// Defaults root to process.cwd() (the consuming service repo):
const result = runServiceWiredGate();
// or against an explicit repo root:
const result2 = runServiceWiredGate({ root: "/path/to/service" });
if (!result.ok) {
for (const f of result.findings) {
console.error(`${f.kind}:${f.target} — ${f.message}`);
}
process.exit(1);
}GateResult = { ok, servedServices, consumers, findings };
GateFinding = { kind: "grpc" | "consumer" | "codegen"; target; message }.
Proto-copy gate
nodii-proto-copy-gate fails a repository that holds a hand-copied contract
(LIB-CON-4, S07-49, S07-51). Run it from the repository root, in pre-push and CI.
Exit 1 on any finding, else 0. A repository that vendors no protos passes.
It checks every .proto under proto/client, proto/peers, test and tests.
Each one must be listed in proto/contract-sources.json:
{
"sources": [
{
"path": "proto/client/auth.proto",
"package": "@nodii/grpc-interfaces",
"version": "1.2.3",
"packagePath": "proto/nodii/auth/v1/auth.proto"
}
]
}The gate requires package.json to pin that exact version, the package to be
installed at it, and the file to match the package's file byte for byte. It keeps
no stored hash, and has no write mode or waiver list: the only way to pass is to
consume the published artifact (Q-112 rules out a temporary exception).
Better still, load the proto from the package and hold no copy at all.
BIN
# from a service repo root:
bunx nodii-service-wired-gate # exit 1 on a gap, else 0 (inert greenfield → 0)package.json bin: nodii-service-wired-gate → ./dist/bin/service-wired-gate.js.
Adoption (per service)
- Delete the copied
scripts/review/service-wired-gate.ts. bun add -d @nodii/review-gates.- In
scripts/review/ai-review.ts, import from the package:import { runServiceWiredGate } from "@nodii/review-gates";and callrunServiceWiredGate({ root: process.cwd() }). - Wire the bin in CI (a
service:wiredstep runningbunx nodii-service-wired-gate).
nodii-test-shard — split a test suite across CI jobs, and prove it all ran
bun test runs a suite as one serial process. Splitting it across several
CI (continuous integration) jobs is the fastest way to cut wall-clock time, and
also the easiest way to stop running tests without noticing. This bin does the
split and then proves the split lost nothing.
nodii-test-shard plan 4 # per-shard files + estimated minutes
nodii-test-shard check 4 # every file in exactly one shard, no empty shard
nodii-test-shard run 2/4 --out-dir test-results -- --timeout 30000
nodii-test-shard verify 4 --out-dir test-results --expect-empty scripts/ci/test-expected-empty.txt
nodii-test-shard timings --out-dir test-results --write scripts/ci/test-timings.jsonHow the proof works:
- Discovery mirrors
bun test: every*.test.*,*_test.*,*.spec.*and*_spec.*file with a js/ts extension anywhere under the repo (includingsrc/anddist/), skippingnode_modulesand dot-directories. - The split is deterministic: longest file first onto the lightest shard,
using
scripts/ci/test-timings.json(--timingsto move it). An untimed file weighs the median. Every job computes the same plan on its own. runpasses exact paths. A barebun test tests/a.test.tsis a substring filter that also runstests/deep/tests/a.test.ts, and an empty list runs the whole suite.runpasses./-prefixed paths and refuses an empty shard. It writesjunit-<k>.xmlandshard-<k>.json(its plan and bun's exit code) to--out-dir, and exits with bun's exit code.verifyrecomputes the plan and checks every shard's results. It fails if:- a shard left no result (skipped, cancelled, artifact lost);
- a shard ran a different list than the plan, or a file outside its plan;
- bun exited non-zero;
- a file ran twice, or never;
- any test failed.
- Files that register no tests must be listed. bun writes nothing to junit
for a file with no tests, so such a file cannot be told apart from one that
never ran. List it in an
--expect-emptyfile, one path per line. A stale entry in that list also fails.
In a workflow, run each shard in a matrix job that uploads --out-dir as an
artifact. Then run one aggregator job, if: always(), that downloads every
shard's artifact into one directory and runs verify. Give the aggregator
the name of the old single test job, so the required status check keeps
working without a branch-protection edit.
Lint and format: bun-canary (D1428)
One pinned Bun build lints and formats every Nodii repo. Add this package, then three small config files, and your repo runs bun lint and bun fmt with the same rules as every other Nodii repo, replacing Biome, ESLint and Prettier.
bun lint and bun fmt exist only in Bun's canary (nightly) builds today. This package pins one exact canary build for the whole fleet, so linting never changes under you. Your repo's runtime Bun (tests, typecheck, Docker images) is not affected; only linting and formatting use the canary.
Changing the pinned build? Only ever through BUMPING.md. Never bump one repo on its own.
What's inside
| Piece | What it is |
|---|---|
| bun-canary | Runs the pinned build. Use it like bun: bun-canary lint, bun-canary fmt --check, bun-canary --revision. Works under Bun, npm and pnpm (it is a plain Node launcher). |
| bun-canary-bump-check | Shows what a canary bump changes in your repo (used by BUMPING.md). |
| oxlintrc.json | The shared lint rules for backends. |
| oxlintrc.react.json | The shared rules plus React and accessibility rules, for frontends. |
| prettier.json | The shared format options (the fleet's existing style: 2 spaces, width 80, double quotes, trailing commas, semicolons). |
| canary.json | The pinned build: npm version and revision. |
| rules-mapping.json | Every Biome rule the fleet ran, and the Bun rule that replaced it (or why none did). |
| BUMPING.md | How to move the fleet to a newer canary build. |
Why it is shaped this way.
- The binary comes from Bun's per-platform npm packages (
@oven/bun-darwin-aarch64,@oven/bun-linux-x64, …), pinned exactly. Your lockfile records each with a sha512 hash, and only your platform's package installs. oven-sh/setup-buncannot install a dated canary, and the GitHubcanaryrelease is overwritten every day, so neither can pin a build.- The launcher is called
bun-canary, neverbun, so it can never shadow your runtime Bun inside package scripts. - Never run it through
bunx: if the package isn't installed,bunxmay fetch something else from npm.
Install weight. The pinned binary comes in as an optional dependency, so every repo that installs @nodii/review-gates, including those that only use nodii-service-wired-gate or nodii-test-shard, also downloads one platform's Bun canary binary (tens of megabytes). That is intended: under D1428 every Nodii repo lints with it. Keep @nodii/review-gates under devDependencies, never dependencies, so the binary never reaches a production image. A dedicated package would avoid the extra download; it waits on someone who can reserve a new @nodii npm name. A canary bump is therefore a @nodii/review-gates release, adopted through BUMPING.md.
Supported platforms:
- Covered: macOS (Apple silicon and Intel) and Linux x64 / arm64 with glibc. That covers developer machines and the self-hosted runners (Amazon Linux 2023, x64).
- Not covered: Alpine (musl) and x64 CPUs without AVX2 ("baseline" builds).
- On musl, the launcher refuses with a clear message.
- On a CPU without AVX2, the binary dies on an illegal instruction and the launcher says why.
- Ask before linting in such an environment, so we can add the variant to the pin.
Formatting from stdin. bun-canary fmt --stdin-filepath=<path> reads stdin in the launcher first, then hands bun the whole input and closes it. If stdin neither sends data nor ends for 60 seconds, it exits 124 with a message instead of waiting forever: the caller never closed stdin (node's execFileSync with a large input, under load, can do this). If bun then neither takes more of the input nor exits for the same limit, the launcher kills it and exits 124. After end-of-input that limit also covers formatting and writing the output. Set NODII_BUN_CANARY_STDIN_IDLE_MS to change the limit (raise it for a producer that pauses longer between chunks). An interactive terminal is never limited. For big inputs, formatting a file is still more reliable than piping.
Adopting it in a repo
1. Install, at an exact version
bun add -d -E @nodii/review-gates # or: npm i -D -E … / pnpm add -D -E …Remove @biomejs/biome, eslint, @eslint/js, typescript-eslint, prettier and their plugins.
Check that the lockfile lists every platform's binary (@oven/bun-linux-x64, @oven/bun-darwin-aarch64, …). Lockfiles written on macOS by Bun 1.3, npm 11 and pnpm 10 did, in the 2026-10-22 Linux install test. Older npm versions can drop other platforms' optional packages (npm/cli#4828), which makes Linux CI fail with "not installed". If that happens, regenerate the lockfile with node_modules removed.
2. .oxlintrc.json (lint rules)
Backends extend the shared rules and add only what is specific to the repo:
{
"extends": ["./node_modules/@nodii/review-gates/oxlintrc.json"],
"ignorePatterns": [
"dist/**",
"coverage/**",
"src/grpc/generated/**",
"scripts/review/naming-conventions-lint.ts"
],
"overrides": [
{ "files": ["src/**"], "rules": { "no-console": "error" } }
]
}- Frontends extend
oxlintrc.react.jsoninstead. .gitignored files are never linted.- In
overrides, a later entry wins over an earlier one. scripts/review/naming-conventions-lint.tsis vendored byte-for-byte from the planning hub, so always ignore it in both lint and format.
3. .prettierrc and .prettierignore (format options)
.prettierrc holds one line, naming the shared options:
"@nodii/review-gates/prettier".prettierignore keeps formatting to what Biome formatted. Biome never touched Markdown, YAML or TOML, and generated files must stay exactly as their generator wrote them:
*.md
*.mdx
*.yml
*.yaml
*.toml
docs/
.claude/
dist/
coverage/
src/grpc/generated/
**/openapi*.json
scripts/review/naming-conventions-lint.ts4. Scripts: keep the names, change the commands
Build pipelines, hooks, skills and tests call scripts by name, so keep every existing name:
| Script | Command | Notes |
|---|---|---|
| lint | bun-canary lint -c .oxlintrc.json && bun-canary fmt --check | Biome's check did both |
| lint:strict | bun-canary lint -c .oxlintrc.json && bun-canary fmt --check | Was biome ci |
| lint:fix | bun-canary lint -c .oxlintrc.json --fix && bun-canary fmt | |
| format | bun-canary fmt --check | Was biome format, which only reported |
| format:write | bun-canary fmt | |
Repos that came from ESLint keep their path globs (for example bun-canary lint -c .oxlintrc.json src tests scripts).
Always pass -c .oxlintrc.json. It makes bun lint use the root config only. Without it, Bun also applies any nested .oxlintrc.json it finds, such as one inside a vendored folder. bun-canary-bump-check does the same, so a bump is measured against exactly what the repo runs. A repo whose scripts pass paths gives bump-check the same ones: bun-canary-bump-check snapshot --lint src --lint tests --fmt 'src/**/*.ts'.
5. Pre-commit hook (lefthook)
pre-commit:
commands:
format:
run: node_modules/.bin/bun-canary fmt --staged
lint:
glob: "*.{ts,tsx,js,mjs,cjs}"
run: node_modules/.bin/bun-canary lint -c .oxlintrc.json --fix {staged_files}
stage_fixed: trueHooks run in a plain shell, where node_modules/.bin is not on PATH, so call the launcher by its path. Package scripts don't need this.
6. Errors the old tool didn't report
The shared rules can report a few errors your old setup missed (for example (a?.b as T).c, which throws when a is undefined). Record them once, so they don't fail the build, and commit the file:
bun-canary lint -c .oxlintrc.json --suppress-all # writes oxlint-suppressions.jsonWhen one of them gets fixed, bun-canary lint fails until you run bun-canary lint -c .oxlintrc.json --prune-suppressions. Commit oxlint-suppressions.json (with an .oxlintrc.json config, Bun names it after oxlint, not ESLint). The list can only shrink.
7. Tell agents how it works
Add to the repo's CLAUDE.md:
## Lint and format
`bun run lint` / `bun run lint:fix` run the pinned Bun canary from
`@nodii/review-gates`. Never bump that package on its own: follow
`node_modules/@nodii/review-gates/BUMPING.md`, which moves every repo
together.Suppression comments
bun lint honours ESLint-style comments only. biome-ignore comments are ignored, so convert them:
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- the SDK types this as any
const raw: any = sdk.read();- Several rules go in one comment, separated by commas.
- The directive must sit directly above the code line, not above another comment.
- To skip formatting, use
// prettier-ignore. - A comment that disables nothing is reported, so remove it.
The rules: what carried over from Biome
scripts/generate-rules.ts builds both configs from Biome 2.5.2's own rule metadata:
- Biome's recommended rules at Biome's severities, plus the overrides most repos shared. These come from nodii-auth's
biome.json, which about 19 repos copied. - Bun's own defaults (ESLint + typescript-eslint recommended), so repos that came from ESLint keep every check.
- Every rule listed explicitly, with every category switched off, so a canary bump can't silently add or drop a rule.
Changed on purpose:
no-undefis off. The TypeScript compiler already checks undeclared names, and Biome never ran this rule.no-use-before-defineonly reports uses that would throw (same scope, before the declaration), as Biome did.
Gaps: Biome checks with no Bun equivalent. All of them were warnings unless marked otherwise:
| Biome rule | Why there's no replacement |
|---|---|
| useOptionalChain | Needs type information (type-aware linting is out of scope) |
| useExportType | Bun's equivalent needs type information |
| noVoidTypeReturn (error) | No equivalent without type information |
| noStringCaseMismatch (error) | No equivalent |
| noSvgWithoutTitle (error, frontends) | Not in jsx-a11y |
| noUselessStringRaw, noUselessContinue, noEmptyTypeParameters, noThisInStatic, noRedundantUseStrict, noSuspiciousSemicolonInJsx, noDynamicNamespaceImportAccess, useSimpleNumberKeys, noFlatMapIdentity | No equivalent |
Measured behaviour differences (parity runs on every Biome repo, 2026-10-22):
- Checks Bun can't make the way Biome did. These are lost; nothing is downgraded.
- React hooks: Biome also flags extra dependencies on
useEffect, and functions inside a component that capture nothing;react-hooks/exhaustive-depsdoesn't. - Accessibility: Biome's
useFocusableInteractiveflags elements without handlers, anduseAriaPropsSupportedByRoleflags role-less elements; Bun's equivalents don't. useTemplate(Biome 1.9 repos): concatenations involving template literals aren't flagged.noAssignInExpressions: logical assignments such as(m[k] ??= []).push()aren't flagged.noUnusedTemplateLiteral: Bun has no stylistic quotes rule.
- React hooks: Biome also flags extra dependencies on
- Checks Bun makes that Biome didn't. These are real problems, so they stay errors; a migrating repo records them once with
--suppress-all.no-unsafe-optional-chainingsees throughascasts:(x?.y as T).zthrows when the chain short-circuits.valid-expectcatches un-awaitedexpect(…).rejects, which can never fail a test.
- Broader than Biome's rule, with no option to narrow it. Kept, so that none of Biome's errors get downgraded.
jsx-a11y/prefer-tag-over-rolealso flagsrole="status"and roles on components.no-script-urlchecks every string, not justhref; it fires on XSS test data.
- Deliberate adjustments, so Bun matches TypeScript-aware Biome:
no-redeclareis off for TS files (it misreads legalconst X+type Xpairs; tsc checks real redeclarations).- The implicit-any
letcheck runs on TS files only.
Also lost: Biome's linting of stylesheets and JSON. bun lint only lints JavaScript and TypeScript. Formatting of stylesheets and JSON stays.
Known upstream issues
no-inner-declarationswith.oxlintrc.jsonstill reports block-level functions in ES modules despiteblockScopedFunctions: "allow"(a bunfig config behaves). A handful of findings, so the migration records them in the baseline.no-cond-assignreports twice. In"always"mode (which matches Biome'snoAssignInExpressions), each finding is printed twice. It's a warning, so nothing fails.bun lint --print-config <file>ignoresoverrides. It shows only the base rules, although linting applies overrides correctly. Sobun-canary-bump-checkcompares the repo's base rules plus every file it lints, but can't see rules that only an override enables. A bump that renames or removes such a rule still fails loudly (exit 2), but one that makes it detect less shows up only if it had findings (seeSnapshot.rulesinsrc/bump-check.ts).
Developing this package
bun run generate:rules # rebuild the shared configs from Biome's metadata
bun run build && bun test # tests run the real pinned binary against golden fixtures
bun scripts/set-pin.ts <version> # move to another canary: see BUMPING.mdThe tests are golden, and a canary bump that changes rule or formatter behaviour fails them on purpose:
tests/bun-tooling-fixtures/: code that must and must not be flagged, plus formatter input and expected output.tests/bun-tooling-rule-examples.snapshot.json: for every active rule, whether it fires on its own documented examples.
