optimize-tests
БесплатноЗапускает вложенные скриптыНе проверенMake the test suite faster without losing coverage. A periodic, coverage-guarded cleanup pass that finds slow/redundant tests, applies free structural…
от getstackit★ 32 звезды на GitHubОб этом скилле
/optimize-tests
Make the suite run faster while keeping every line of coverage. This is a periodic cleanup pass, not a one-off: each run targets the current hotspots, banks the wins, and reports what's left for next time.
The goal is to maximize the value of each test — fewer tests, each asserting more, running in less wall-clock — without ever dropping a covered line or a real assertion.
The safety contract (read this first)
Two guarantees must hold for every change. The first is automated; the second is your judgement. Both are mandatory.
Coverage floor — automated.
coverage-guard.shcompares the set of covered blocks before and after, not the percentage. Two suites can share a percentage while covering different lines, so the percentage is a lie; the block set is the truth. If any block covered before is uncovered after, the guard fails and names the lines. This is what makes "delete / merge tests" safe: you may remove anything as long as the covered-block set never shrinks.Assertion value — judgement. Coverage means a line ran, not that its result was checked. A line can execute with nothing asserting its behavior. So when you collapse or remove a test, every distinct assertion and every distinct input in the originals must survive in the result. Dedupe setup, never assertions. The guard cannot see this — you must.
If you can't satisfy both, don't make the change.
Usage
/optimize-tests [scope] [--dry-run]
scope(optional) — a test tier (fast|git|integration|unit|all) or a Go package pattern (./internal/engine/...). Default:integration(usually the slowest tier and the biggest win). Pick a hotspot; don't boil the ocean every run.--dry-run— measure and produce the worklist, but make no edits.
Examples:
/optimize-tests # incremental pass over the integration tier
/optimize-tests ./internal/git/... # focus one package
/optimize-tests fast --dry-run # just show me the opportunities
Scripts
Deterministic steps live in .claude/skills/optimize-tests/scripts/. Use them
instead of inlining go test / rg — they encode the right flags (cache off,
-coverpkg=./..., -covermode=set) and keep invocations identical across runs.
| Script | Purpose |
|---|---|
measure-time.sh <scope> <out.json> |
Time a run (no coverage — instrumentation distorts timing); capture per-test timings. Prints wall_seconds=. |
measure-cover.sh <scope> <out.cover> |
Capture a coverage profile (-coverpkg=./..., set mode). Prints total_pct=. Use the same scope before & after. |
slowest.sh <out.json> [N] |
Rank the slowest tests and packages — your hotspot list. |
coverage-guard.sh <before.cover> <after.cover> |
The gate. Exit 1 + named blocks if any covered line was lost. |
scan-antipatterns.sh |
List coverage-safe structural speedups (the "free wins"). |
Work in a scratch dir, e.g. /tmp/stackit-test-opt/.
The loop
Step 0 — Scope
Resolve scope (default integration). State it up front: "Optimizing the
integration tier…". A periodic pass is incremental — target where the time
is now, not the whole tree.
Step 1 — Baseline
D=/tmp/stackit-test-opt && mkdir -p "$D"
bash .claude/skills/optimize-tests/scripts/measure-time.sh "$SCOPE" "$D/before.json"
bash .claude/skills/optimize-tests/scripts/measure-cover.sh "$SCOPE" "$D/before.cover"
bash .claude/skills/optimize-tests/scripts/slowest.sh "$D/before.json" 25
bash .claude/skills/optimize-tests/scripts/scan-antipatterns.sh
Record the numbers: wall_seconds, total_pct, the slowest tests/packages.
These are the before/after yardstick. Do not paste full test files into
context — work from the hotspot list and open files as needed.
If --dry-run, skip to Step 6 and report the worklist without editing.
Step 2 — Free structural wins first (Tier A — zero coverage risk)
Apply everything scan-antipatterns.sh surfaced. These change how a test runs,
not what it asserts, so they cannot move coverage — knock them out first, they
are usually the biggest wall-time win:
- Missing
t.Parallel()(top-level and each subtest) → add it. NewTestShell((spawns a process) →NewTestShellInProcess((~8ms/cmd).WithRemote()where the test never pushes/pulls/syncs → drop it.- 3+ hand-rolled
CreateAndCheckoutBranchcalls → a fixture (CreateLinearStack3(),CreateDiamondStack()).
After this batch, validate parallelization with the race detector using the
flags CI actually uses (check .github/workflows/ — here it's
go test -race -p=1 -parallel=2). Do NOT trust a default-GOMAXPROCS run:
default over-parallelism crashes subprocess-heavy tests under -race (git child
processes segfault) in ways CI never reproduces, AND a plain run can pass a
genuinely broken parallel test by luck of timing. Match CI, and re-run
Установить optimize-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Bash(bash:*)Bash(go:*)Bash(git:*)Bash(mise:*)Bash(rg:*)Bash(jq:*)Bash(fd:*)ReadEditWriteGrepGlobTaskВложенные файлы
FAQ
Что делает скилл optimize-tests?
Make the test suite faster without losing coverage. A periodic, coverage-guarded cleanup pass that finds slow/redundant tests, applies free structural speedups (parallel, in-process, drop remote), and consolidates similar tests (table-driven merges, combined asserts) — verifying after every change that no covered line was lost. Keywords test speed, slow tests, test runtime, test cleanup, consolidate tests, parallel tests, combine asserts, coverage-safe, maximize test value.
Как установить скилл optimize-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл optimize-tests запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic