UNPKG

tdd-guard

Version:

TDD Guard enforces Test-Driven Development principles using Claude Code hooks

2 lines 2.37 kB
export declare const EDIT_ANALYSIS = "## Analyzing Edit Operations\n\n### Your Task\nYou are reviewing an Edit operation where existing code is being modified. You must determine if this edit violates TDD principles.\n\n**IMPORTANT**: First identify if this is a test file or implementation file by checking the file path for `.test.`, `.spec.`, or `test/`.\n\n### How to Count New Tests\n**CRITICAL**: A test is only \"new\" if it doesn't exist in the old content.\n\n1. **Compare old content vs new content character by character**\n - Find test declarations: `test(`, `it(`, `describe(`\n - A test that exists in both old and new is NOT new\n - Only count tests that appear in new but not in old\n - Count the NUMBER of new tests added, not the total tests in the file\n\n2. **What counts as a new test:**\n - A test block that wasn't in the old content\n - NOT: Moving an existing test to a different location\n - NOT: Renaming an existing test\n - NOT: Reformatting or refactoring existing tests\n\n3. **Multiple test check:**\n - One new test = Allowed (part of TDD cycle)\n - Two or more new tests = Violation\n\n**Example**: If old content has 1 test and new content has 2 tests, that's adding 1 new test (allowed), NOT 2 tests total.\n\n### Analyzing Test File Changes\n\n**For test files**: Adding ONE new test is ALWAYS allowed - no test output required. This is the foundation of TDD.\n\n### Analyzing Implementation File Changes\n\n**For implementation files**:\n\n1. **Check the test output** to understand the current failure\n2. **Match implementation to failure type:**\n - \"not defined\" \u2192 Only create empty class/function\n - \"not a constructor\" \u2192 Only create empty class\n - \"not a function\" \u2192 Only add method stub\n - Assertion error (e.g., \"expected 0 to be 4\") \u2192 Implement minimal logic to make it pass\n \n3. **Verify minimal implementation:**\n - Don't add extra methods\n - Don't add error handling unless tested\n - Don't implement features beyond current test\n\n### Example Analysis\n\n**Scenario**: Test fails with \"Calculator is not defined\"\n- Allowed: Add `export class Calculator {}`\n- Violation: Add `export class Calculator { add(a, b) { return a + b; } }`\n- **Reason**: Should only fix \"not defined\", not implement methods"; //# sourceMappingURL=edit-analysis.d.ts.map