Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing mcpx

What to run when you change mcpx, and what you never run. Each section names the issue that decides the policy; where this page and an issue disagree, the issue wins. Agents get the short version from internal/AGENTS.md, which opencode attaches when a file under internal/ is read.

Never the whole suite locally

go test ./... is a CI command. It is minutes of internal/e2e for a change that usually touches one package, and the cost only grows as the suite does. Run it only to reproduce a CI failure, and then only the packages CI named. (Decided in #1966; the measurement behind the rule is in #1909.)

What to run, by change

You changedRunCost
anythingnothing — read the diff first—
one packagego test ./internal/<pkg> -count=1seconds
a test you just wrotego test ./internal/<pkg> -run TestTheName -count=1 -vseconds
a registry, table or manifestits guard test (see below), then the packageseconds
CLI or daemon behaviour a unit test cannot seethe named e2e tests that cover it: go test ./internal/e2e -run 'TestThatOne' -count=1~10 s per test
a shared helper used by e2ego test ./internal/e2e -count=1~2 min
anything, before merginggo test ./... -count=1 in CI, not on your machine~3 min

docs/testing/inventory.md is the per-package map: test counts, which packages hide time, randomness or ports, and which are flake-prone. Check it before picking e2e tests — it says where the sleeps are.

A test per bug

Every bug, from any source, gets at least one new test in the same PR as the fix, and the test fails without the fix. Cover the bug’s permutations, not just the input that tripped it: a parser bug gets the neighbouring shapes, a state bug gets the transitions either side of it. Skip the test only when writing it is genuinely expensive, and say so in the PR body. (Decided in #1969.)

Enforcement (#1969, option C): the basic-tier check basic: mcpx fix carries a test (#1969) (workflow .github/workflows/mcpx-fix-test-guard.yml, script .github/scripts/check-mcpx-fix-test.sh, contract tests in .github/scripts/check-mcpx-fix-test.test.sh) runs on pull requests touching pkgs/mcpx/**. A PR counts as a fix when its title starts with fix (fix:, fix(mcpx):, …) or its body has a Fixes/Closes/ Resolves link to an issue labelled bug/kind/bug. A fix PR passes when it changes a *_test.go or *.test.ts file under pkgs/mcpx/, or when its body contains No test: <reason> with a non-empty reason — the reason is printed in the check output and the job summary, so the skip is attested, not silent. The check proves presence only: whether the test actually fails without the fix stays a review item. Non-fix PRs and PRs that touch no mcpx file are unaffected (the workflow’s path filter means no check fires for them at all).

Guards, not instances

When the bug is one member of a class — a declaration and its use that live apart, a registry whose entries must each satisfy something — the test must fail for every member of the class, present and future, not the instance you found. Iterate the registry; do not hand-list entries. A setting must be able to change behaviour, not merely be read. (Decided in #1971.)

Existing examples to copy: internal/settings/compendium_test.go (every markdown file is placed in the book), internal/settings/registry_test.go (every setting is documented), internal/conformance (every protocol cell has a covering test).

Flakes

A flake is a bug in the test or the code under it; a retry hides it.

  • Look for them with -race, -shuffle=on and repeat runs: go test ./internal/<pkg> -race -shuffle=on -count=5.
  • Do this on changed tests in the PR, and on everything nightly — not on the full suite locally.
  • When you find one: fix it. If you cannot yet, quarantine it with a skip that names the issue and an expiry date, and file the issue. A quarantine without an owner and a date is a silent retry with extra steps.
  • CI’s PR gate is Linux only; the nightly stress job below also runs macOS, so a macOS-only difference surfaces within a day (#35). Say so in the PR when the change is platform-sensitive. (Decided in #1973.)

The flake policy in CI (#1973, approach C)

Implemented in .github/workflows/mcpx.yml; detection happens by repetition off the critical path, never by retrying a failure away:

  • Per PR — the stress-pr job runs the packages the PR changed with -race, a deterministic -shuffle=<seed> (derived from the workflow run identity and printed in the job log, so a failing order reproduces with the same seed; never -shuffle=on in CI), -count=10 for unit packages and -count=3 for internal/e2e. It runs in parallel with the main test job and is not a required check.
  • Nightly — the stress-nightly job runs the whole suite with -race -shuffle=<seed> -count=3 on ubuntu-latest and macos-latest. On failure it opens or updates the single “mcpx nightly stress failure” issue; it never blocks a PR.
  • Explicit timeouts. -count=3 runs every pass of a package inside one test binary, and one internal/e2e pass is about five minutes of real-time waits, so go test’s default 10m timeout cannot hold it (#10489). The e2e stress run passes -timeout 25m and the nightly passes -timeout 50m, each under its job’s own limit, so a real hang still panics with goroutine dumps instead of being killed by the runner.
  • Fix first. A flake the stress jobs surface is a bug: fix it. Only when a fix genuinely cannot land yet, quarantine the test with testsupport.Quarantine(t, "<issue URL>", "YYYY-MM-DD") from internal/testsupport — it skips until the expiry date and fails after it, and the guard test in that package fails the suite on any quarantine call missing an issue link or past its expiry.
  • No hiding retries anywhere: no --rerun-fails, no re-run-until-green merge path. A retry that turns a flake green destroys the evidence.

Reproducing a CI failure

  1. Read the failing job, not just the summary — the log names the package and the test.
  2. Run exactly that, whole-package if the failure could be shared state: go test ./internal/<pkg> -run '<Test>' -count=1 -v
  3. Add -race if the failure looks like a data race, -count=5 if it passed once locally.
  4. If it only fails in CI, match the Go version in go.mod and check whether the test is order-dependent (-shuffle=on).

Policy status

The policies above are stated as decided so agents have one rule set, but the issues are still open and may refine them: #1909 (the policy bundle), #1966 (which tests), #1969 (a test per bug), #1971 (guards), #1973 (flakes). If you settle one, update this page in the same PR.

Keeping this page honest

Every command quoted here must exist and run. When a recipe is renamed, the rename edits this page and internal/AGENTS.md in the same PR.