tdd
Fix a bug by writing a regression test that fails first, when a cheap local test path exists.
- License 许可
- MIT
- 所属仓库
- ryuudotgg/skills
- 最近更新
- 2026-11-14
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- tdd
- description
- Fix a bug by writing a regression test that fails first, when a cheap local test path exists.
- disable-model-invocation
- true
02 资源文件 1
- 参考文档agents/openai.yaml43 B
03 SKILL.md 正文
TDD Bug Fix
When fixing a bug with a clear, cheap test path, make the broken behavior executable before changing production code. The goal is a focused regression test that fails before the fix and passes after it.
Do not force a test when it would be impractical. If the available test would require broad harness setup, brittle mocks, slow end-to-end infrastructure, production-only state, vague reproduction steps, or large unrelated fixture churn, skip adding a new test and use the closest useful verification instead.
Workflow
- Understand the bug. Identify the intended behavior, current behavior, affected path, and smallest observable reproduction.
- Choose the narrowest executable check. Prefer the closest unit, component, integration, or regression test already used for that codepath. If no practical test path is obvious, do not create one from scratch just to satisfy the workflow.
- Write the failing test first. Add the smallest focused test that would have caught the bug. Assert on the outcome of the operation, not on which internal calls were made; a test that mirrors the implementation passes for the wrong reason and breaks on the next refactor.
- Run the new test before fixing. Confirm it fails for the intended reason. If it passes or fails for an unrelated reason, correct the test or reproduction before editing the implementation.
- Fix the bug. Make the smallest production change that satisfies the intended behavior while preserving nearby contracts.
- Rerun the regression test. Confirm the test now passes.
- Run nearby validation. Run relevant adjacent tests, type checks, lint, or scenario checks when the change has broader risk.
If a Failing Test Is Impractical
Do not silently skip the regression step. Before fixing, explicitly explain why a failing test is impossible or not worth the cost, then choose the closest executable regression check available. Examples include a targeted script, manual reproduction command, browser automation, snapshot comparison, log assertion, or focused integration check.
Prefer no new test over a bad test. A bad test is one that mostly tests mocks, encodes current implementation details, depends on timing or unrelated global state, needs expensive infrastructure for a small fix, or would be deleted immediately after proving the fix.
Guardrails
- Do not change tests merely to match a wrong implementation.
- Do not weaken existing assertions unless the expected behavior has genuinely changed and the reason is clear.
- Keep the regression test focused on the bug; avoid broad fixture churn or unrelated coverage expansion.
- Do not add tests when the practical signal is weak; use manual or scripted verification and say why.
- If the bug is flaky, make the test deterministic where possible and document the signal being locked down.
- If the bug exposes a broader class of failures, first land the focused regression path, then consider additional sibling coverage.
- Run tests against whatever the project already has running. Never kill, restart or hijack a process, server or database you did not start in this session. If one is in the way, say so and ask.
- Leave the test and the fix unstaged on the
feat/*branch for the handback, the playbook skill'splaybooks/handing-back.md; who stages, commits, pushes and posts is stated once, in the playbook skill'sreferences/delivery.md. - No code comments in the test or the fix. No em dashes, no en dashes, no hyphen used as a dash.
Final Response
Report the evidence, not just the outcome:
- Name the failing-before test or executable check and the failure it produced.
- Name the passing-after test run and any nearby validation performed.
- If failing-before evidence could not be demonstrated, state why and describe the closest regression check used instead.
04 同仓库更多 Skills
unslop
Cut AI tells from any writing. Must always apply.
technical-writing
Write or review docs, RFCs, readmes, and PR descriptions against a layered standard: Diátaxis structure, Google developer style sentences, STE instruction rules, and Global English syntax.
show-me-your-work
Keep a reviewable decision trail for unattended work: a TSV log, one row per decision (project, plan, branch, evidence, result), local and uncommitted.
principle-type-system-discipline
Apply when designing types, reviewing a function signature, or writing code in any statically-typed language. Make illegal states unrepresentable, brand semantic primitives, parse external data at boundaries, refuse to lie to the compiler, exhaust variants, derive from authoritative schemas.
principle-subtract-before-you-add
Apply when sequencing an addition, refactor, or rewrite. Remove dead weight, redundant validators, and stub references first, then build on the simpler base.
principle-sequence-verifiable-units
Apply to multi-step work: sweeps, migrations, runs of similar edits. Break work into small units that each end in a verifiable state, check each before the next, and order the work so the sequence proves itself to a reviewer.