agentleFS
MorningStar0709MorningStar0709/trae-agent-enhancements/skills/test-driven-development/SKILL.md

test-driven-development

Skill17 starsChanged 7 months agoMITView on GitHub

Use when implementing behavior with tests first, including new features, bug fixes, behavior changes, and regression protection, and including Chinese requests such as “先写测试”“补回归”“按 TDD 修复”. Do not use for pure copy edits, generated outputs with little test value, or tasks where the user explicitly wants to skip testing and accepts the risk.

191 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use chinese-code-review, chinese-commit-conventions and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Leodorareluctant259Skill

    chinese-code-review

    中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈

    Also in 8 projects that use this

  • Leodorareluctant259Skill

    chinese-commit-conventions

    中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化

    Also in 8 projects that use this

  • steven123397Skill

    accessibility-engineering

    Audits existing interfaces for WCAG 2.2 AA conformance and remediates the violations found. Use when auditing a page or component for accessibility, running axe-core or pa11y, triaging a11y violations, or checking screen reader and contrast issues before shipping.

    Also in 4 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 46 projects that use this

  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 21 projects that use this

  • LLl0k0laDSkill

    git-workflow-and-versioning

    Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

    Also in 54 projects that use this

  • +1 more from Leodorareluctant259
  • +2 more from LLl0k0laD

The file

Show its rules and text

We split this skill into the rules it gives an agent

26 rules. 0 are common, 23 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 182 edited versions we read keep these.

  • 23

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Core Principle: If you don't see the test fail first, you don't know if it's actually protecting the correct behavior.

    line 10
  2. Distinctive:

    Only modifying copy, comments, or static configs without behavioral changes.

    line 21
  3. Distinctive:

    Behavioral target unclear: Do not start the TDD loop.

    line 37
  4. Distinctive:

    Context Payload available: Read it during Phase 0 before writing the failing test.

    line 38
  5. Very specific:

    If the current task was handed off from an upstream skill (e.g., systematic-debugging), check the conversation for a [Context Payload] …

    line 45
  6. Distinctive:

    If a Context Payload is present, incorporate its content into the failing test design and implementation scope.

    line 52
  7. Distinctive:

    Test only one behavior at a time.

    line 59
  8. Distinctive:

    Use PowerShell-compatible commands on a Windows host, for example:

    line 83
  9. Distinctive:

    If the test passes immediately upon writing, it means it is not protecting the actual new behavior.

    line 97
  10. Distinctive:

    Write only the minimum code required to make the current failing test pass.

    line 101
  11. Distinctive:

    Run the exact same test command again and confirm:

    line 120
  12. Distinctive:

    Only alter implementation code, not test code.

    line 130
  13. Distinctive:

    Do not break code unrelated to what the test is verifying.

    line 132
  14. Distinctive:

    If the test does not fail under mutation, the test is not protective — it is a false-green test.

    line 136
  15. Distinctive:

    If you cannot make the test fail under mutation, escalate: this likely means the code cannot fail from the outside, which is a design issue.

    line 139
  16. Distinctive:

    After refactoring, you must run the tests again to ensure behavior remains unchanged.

    line 172
  17. Distinctive:

    When fixing a bug, write the bug as a failing test first, instead of fixing the implementation directly.

    line 176
  18. Distinctive:

    Run it to get a red light, then fix:

    line 185
  19. Distinctive:

    When running validations, use the project's native test commands and maintain PowerShell compatibility on the Windows host.

    line 200
  20. Distinctive:

    Do only one thing per cycle: write failing test, run it, write minimal implementation, run it again, perform mutation test, restore, then …

    line 201
  21. Very specific:

    After the fix is complete, if preparing to declare success, continue using verification-before-completion.

    line 202
  22. Distinctive:

    Write code first, add tests at the end.

    line 206
  23. Distinctive:

    Existing code lacks tests: Start from the behavior being modified.

    line 219
  24. Distinctive:

    When completing a TDD cycle, you must at least state:

    line 223
  25. Distinctive:

    If there is no evidence of a red light, do not claim you did TDD.

    line 230
  26. Very specific:

    Next Step: After the TDD cycle is complete, must invoke verification-before-completion to independently verify the fix before declaring …

    line 232

“Common” is measured: kept by at least 6 in 10 of the 182 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test-Driven Development

Overview

Core Principle: If you don't see the test fail first, you don't know if it's actually protecting the correct behavior.

Use This Skill

  • Developing new features.
  • Fixing bugs and adding regression protection.
  • Changing existing behavior.
  • Adding safety nets to legacy code lacking tests.

Do Not Use

  • Only modifying copy, comments, or static configs without behavioral changes.
  • Generating files or third-party artifacts with very low testing value.
  • The user explicitly asks to skip testing and accepts the corresponding risk.
  • The current task is just discussing solutions; use brainstorming or writing-plans first.

Input Contract

Required Inputs:

  • A clear behavioral target: what behavior needs to be implemented, fixed, or changed.

Optional but highly recommended inputs:

  • Existing project testing patterns and framework configuration.
  • Related test files or code paths.
  • Context Payload from upstream skill (e.g., systematic-debugging, writing-plans): When handed off from an upstream skill, check the conversation for a [Context Payload] block. It preserves the confirmed root cause, ruled-out paths, residual risks, and fix guidance that should inform the failing test design.

Missing input handling:

  • Behavioral target unclear: Do not start the TDD loop; clarify first.
  • Context Payload available: Read it during Phase 0 before writing the failing test.
  • Context Payload absent: Proceed without it.

Execution Protocol

Phase 0: Read Upstream Context (if handed off from upstream skill)

If the current task was handed off from an upstream skill (e.g., systematic-debugging), check the conversation for a [Context Payload] block before starting the TDD loop. Pay special attention to these fields:

  • Root Cause (from systematic-debugging): Confirmed root cause that the fix must address.
  • Ruled Out (from systematic-debugging): What was already investigated — avoid repeating dead ends.
  • Residual Risk (from systematic-debugging): Edge cases or uncertainties that the TDD regression test should cover.
  • Fix Guidance (from systematic-debugging): One-sentence summary of what needs to change.

If a Context Payload is present, incorporate its content into the failing test design and implementation scope. If absent, proceed without it.

1. Red Light: Write Failing Test First

The test must first express the expected behavior, then expose the current gap.

A good failing test should:

  • Test only one behavior at a time.
  • Have a clear name.
  • Prioritize testing real behavior, not the mock itself.
  • Be minimally reproducible.

Example:

test('retries failed operations 3 times', async () => {
  let attempts = 0;
  const operation = async () => {
    attempts += 1;
    if (attempts < 3) throw new Error('fail');
    return 'success';
  };

  const result = await retryOperation(operation);

  expect(result).toBe('success');
  expect(attempts).toBe(3);
});

2. Verify Red Light: Must See It Fail

Use PowerShell-compatible commands on a Windows host, for example:

npm test -- path\to\retry.test.ts

Or:

pytest tests/test_retry.py -k retries_failed_operations

Confirm three things:

  • The test fails, not the test file itself throwing a syntax/load error.
  • The failure reason matches expectations.
  • The failure comes from missing behavior, not typos or environment errors.

If the test passes immediately upon writing, it means it is not protecting the actual new behavior.

3. Green Light: Write Minimal Implementation

Write only the minimum code required to make the current failing test pass. Do not opportunistically expand interfaces or optimize unrelated logic.

Example:

async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
  for (let i = 0; i < 3; i += 1) {
    try {
      return await fn();
    } catch (error) {
      if (i === 2) throw error;
    }
  }

  throw new Error('unreachable');
}

4. Verify Green Light: Re-run Tests

Run the exact same test command again and confirm:

  • The target test passes.
  • Related tests do not regress.
  • The output has no new errors or obvious warnings.

5. Mutation Test: Break Then Verify (Anti-False-Green)

Deliberately alter one line of the implementation code you just wrote to prove the test can catch the defect.

Rules:

  • Only alter implementation code, not test code.
  • Make a targeted, minimal break (e.g., flip a boolean, remove a guard clause, return a wrong value, comment out a key line).
  • Do not break code unrelated to what the test is verifying.
  • Re-run the exact same test and confirm it fails with a meaningful error.
  • Restore the broken code immediately after verification.

If the test does not fail under mutation, the test is not protective — it is a false-green test. In that case:

  1. Fix the test to actually assert meaningful behavior.
  2. Repeat the mutation test until the test fails when the implementation is broken.
  3. If you cannot make the test fail under mutation, escalate: this likely means the code cannot fail from the outside, which is a design issue.
  4. Log via self-improvement: Record the false-green pattern as an anti-pattern experience so future agents can recognize and avoid similar testing mistakes.

Example mutation sequence for a validation function:

// Original implementation:
function submitForm(data: FormData) {
  if (!data.email?.trim()) {
    return { error: 'Email required' };
  }
  return { ok: true };
}

// Mutation: comment out the guard
function submitForm(data: FormData) {
  // if (!data.email?.trim()) {
  //   return { error: 'Email required' };
  // }
  return { ok: true };
}

// Run test → expect FAIL with meaningful error
// Then restore immediately

6. Refactor: Only After Mutation Passes

You are only allowed to do these when the tests are green:

  • Deduplicate code.
  • Rename variables/functions.
  • Extract helper functions.
  • Simplify structures.

After refactoring, you must run the tests again to ensure behavior remains unchanged.

Bug Fix Pattern

When fixing a bug, write the bug as a failing test first, instead of fixing the implementation directly.

test('rejects empty email', async () => {
  const result = await submitForm({ email: '' });
  expect(result.error).toBe('Email required');
});

Run it to get a red light, then fix:

function submitForm(data: FormData) {
  if (!data.email?.trim()) {
    return { error: 'Email required' };
  }

  return { ok: true };
}

Trae / Windows Conventions

  • In Trae, use Read, Grep, GetDiagnostics to understand existing testing patterns before writing new tests.
  • When running validations, use the project's native test commands and maintain PowerShell compatibility on the Windows host.
  • Do only one thing per cycle: write failing test, run it, write minimal implementation, run it again, perform mutation test, restore, then refactor.
  • After the fix is complete, if preparing to declare success, continue using verification-before-completion.

Common Anti-Patterns

  • Write code first, add tests at the end.
  • The test passes as soon as it is written.
  • Testing the number of mock calls instead of behavioral results.
  • Modifying production code to be harder to understand just to make it easier to test.
  • Writing a lot of implementation at once, then going back to add a bunch of tests.

See more anti-patterns in: testing-anti-patterns.md

Failure Handling

  • Test won't stably fail: Fix the test environment or minimal reproduction first; do not enter implementation.
  • Test is too hard to write: Usually indicates the interface design is too heavy or tightly coupled; simplify the design first.
  • Requires massive mocking to test: Prioritize checking dependency injection, boundary splitting, and responsibility separation.
  • Existing code lacks tests: Start from the behavior being modified; add minimal regression tests first.

Output Contract

When completing a TDD cycle, you must at least state:

  • Which test was added or modified.
  • What failure was seen during the red light phase.
  • What minimal implementation was used to make it green.
  • What validations were run at the end.
  • What mutation test was performed to verify test protection.

If there is no evidence of a red light, do not claim you did TDD.

Next Step: After the TDD cycle is complete, must invoke verification-before-completion to independently verify the fix before declaring "fixed" or entering the commit process.

Checklist

  • Wrote a failing test first.
  • Saw the test fail for the expected reason with my own eyes.
  • Wrote only the minimal implementation to pass the test.
  • Re-ran the test and confirmed it passed.
  • Related tests did not regress.
  • Performed mutation test: broke implementation and confirmed test failure.
  • Restored implementation after mutation verification.
  • If refactored, verified again after refactoring.

Integration

  • systematic-debugging: Locate the root cause first, then return to TDD to fix.
  • verification-before-completion: Re-verify conclusions before claiming "fixed".

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.