test-driven-development
Writes a failing test before the code that makes it pass, for a feature or bug fix whose expected behavior is known and testable through the production code.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-15
- Stars
- ★ 15
- Forks
- 4
01 前言 Front Matter
- name
- test-driven-development
- description
- Writes a failing test before the code that makes it pass, for a feature or bug fix whose expected behavior is known and testable through the production code.
- compatibility
- [ "Python 3.11+ standard library" ]
02 资源文件 1
- 参考文档references/testing-anti-patterns.md3.7 KB
03 SKILL.md 正文
Test-Driven Development
The response model establishes a meaningful failing test for accepted behavior, implements that behavior, and observes the resulting pass. The test's expected result comes from the human user's requirement and source contract.
Applicability
Apply RED-first when the required behavior is known, its expected result can be stated independently of the proposed implementation, and an automated test can exercise the relevant production path.
If the premise, data flow, target or behavior is unknown, use bounded discovery or an implementation proof first. When that work establishes a testable production contract, apply RED-first to the subsequent implementation. Configuration, generated output and instruction changes without a meaningful behavioral test use their accepted source or runtime validation instead. Follow an explicit instruction that the human user enters in the conversation about implementation and verification order, under the common contract's instruction precedence rule.
Before starting, the response model identifies the expected failure, the production path and the independent basis for the assertion. Unknown answers require discovery under systematic-debugging or the accepted design workflow; they do not justify inventing a test.
RED: establish the intended failure
Write a focused test with a descriptive name and an assertion about required behavior. Prefer the real production path; use a mock only for a dependency whose contract is understood. Load testing-anti-patterns.md when choosing mocks or test utilities.
Invoke the project's actual runner with the exact test target. Retain the original command, output, status and evidence locator. Judge whether the failure demonstrates the missing behavior rather than an invalid fixture, syntax error or unavailable dependency.
If the test passes, determine whether the behavior already exists or the test misses the intended condition. If the test errors, correct the fixture or prerequisite and observe the affected result. Follow systematic-debugging to count failed repair rounds.
For applicable work, observe this intended failure before writing production code. If the response model prematurely wrote production code, remove only its own authorized premature change before rebuilding from the test. Preserve local changes already present in the checkout that this work did not make and retained original failure evidence; git does not record who made the change.
GREEN: satisfy the behavior
Implement the accepted behavior to the depth required by the observed cause. A structural defect may need a structural correction; passing one assertion does not settle other required acceptance criteria. Exclude unrelated features and refactors.
Run the same relevant target and inspect its result. If it fails, compare the failure with the acceptance criterion: correct production behavior when it violates that acceptance criterion, or correct an assertion or fixture that misstates it. A passing implementation must not depend on weakening a valid requirement.
Use verification-before-completion's Evidence selection and stop gate for affected additional checks and verify-or-reuse for retained results. Report unrelated failures without claiming they were caused or resolved by this change.
REFACTOR
Once required behavior passes, simplify duplication, names or interfaces only within the task being implemented. Preserve behavior and check the affected paths under the same evidence-selection procedure. Begin another RED step only for another required behavior.
Worked example
The accepted operation makes at most three attempts and returns the successful result. This illustrative test exercises the operation through a controllable dependency:
test('returns success on the third allowed attempt', async () => {
let attempts = 0;
const operation = async () => {
attempts++;
if (attempts < 3) throw new Error('temporary failure');
return 'success';
};
expect(await retryOperation(operation)).toBe('success');
expect(attempts).toBe(3);
});
The response model first observes the intended failure in the actual project, then implements the accepted attempt limit:
async function retryOperation<T>(operation: () => Promise<T>): Promise<T> {
for (let attempt = 0; attempt < 3; attempt++) {
try {
return await operation();
} catch (error) {
if (attempt === 2) throw error;
}
}
throw new Error('unreachable');
}
The example covers success on the third attempt. If the contract also requires propagating the final failure, that distinct behavior needs its own evidence. Neither sample code nor its presence in this skill proves that a test ran.
Failure modes and result
Do not replace an unknown requirement with an implementation-shaped assertion, count mock configuration as production behavior, or treat RED-first order alone as proof of coverage. When setup is difficult, inspect the actual dependencies before prescribing interface changes or asking the user for an implementation detail.
Return the behavior covered, original RED and GREEN observations, changed production target and any unresolved requirement. Verification-before-completion defines the completion judgment, including how this evidence supports the whole result that the human user requested.
04 同仓库更多 Skills
skill-evolution
Recommends skill changes from recorded tool-call patterns and conduct corrections asserted by the human user or observed by the response model, when the human user asks for such recommendations or their pending backlog, or authorizes that analysis.
session-intent-analyzer
Records the response model's new or changed interpretation of the input the response model is answering as its `interpreted-as` record before the first tool call of work, and reads that record when it can change the objective, constraints, work choice or whether earlier work continues.
necessity-gate
Judges whether proposed work is justified, needs a narrower scope or is unjustified, when the response model proposes new work or the human user asks whether to do it.
merge-companion
Reviews the installer's backups of external changes to installed skills and merges each into the new skill version, discards or defers it as the human user chooses, before a task changes or reinstalls an installed skill, or when the human user asks for that review.
compact-handoff
Writes a handoff of the task's objective, scope, evidence and next action when a long conversation, compaction or handover to another session or agent could lose them, and resumes the task from it afterwards.
writing-skills
Writes a new skill or changes an existing one in its folder (SKILL.md, references and scripts) and tests it.