Tdd

From pageel/para-workspace · View interactive version

Tdd is an AI agent skill from the GitHub repository pageel/para-workspace. Strict Test-Driven Development workflow rules, anti-patterns, and the Red-Green-Refactor cycle.

How to use this skill

Skill file

Skill: Test-Driven Development (TDD)

Context: This skill governs execution-time behavior for AI Agents when writing code. It prevents hallucinations, bloated code, and missing test coverage by enforcing strict TDD principles.

Load this reference when: The user requests TDD, the active plan specifies strict TDD/testing, you are writing tests, or you are refactoring existing code.

1. The Iron Law

⛔ NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.

This rule is absolute. If you are instructed to implement a feature, you MUST write the test first, observe it fail, and only then write the production code. If you find yourself writing production code without a corresponding failing test, STOP. Delete the code. Write the test.

2. The TDD Cycle (Bite-Sized Tasks)

Do not attempt to write 500 lines of code at once. Break the work into 5-minute bite-sized cycles:

🔴 RED: Write a Failing Test

Write a test for the _exact_ behavior you are about to implement.

⛔ FALSE RED GUARD: A valid RED state means the test fails because the logic is missing (e.g., Assertion Error: Expected A but got B, or TypeError: function is not defined). If the test fails due to a Syntax Error or Missing Import in the test file itself, you MUST fix the test structure before proceeding. It is NOT a valid RED if the test code is simply broken.

⛔ NO WATCH MODE: When executing tests in the terminal, Agent MUST use one-shot execution commands (e.g., CI=true npm test or npm run test:run) and MUST NOT use watch mode (--watch). Watch mode will block the terminal process and break the workflow.

🟢 GREEN: Write Minimal Code

  1. Write ONLY the production code necessary to make the failing test pass.
  2. Do not anticipate future needs (YAGNI - You Aren't Gonna Need It).
  3. Do not format or clean up code excessively at this stage. Just make it pass.
  4. Run the test command and verify it is completely green.

🟣 REFACTOR: Clean and Optimize

  1. You may only refactor when all tests are green.
  2. Clean up duplications (DRY), rename variables for clarity, and extract helper functions.
  3. Warning: Do NOT add new behavior or logic during the Refactor phase.

3. Testing Anti-Patterns

Anti-Pattern A: Testing Mock Behavior

Anti-Pattern B: Test-Only Methods in Production

Anti-Pattern C: Incomplete Mocks

Anti-Pattern D: Integration Tests as an Afterthought

Anti-Pattern E: Bypassing TDD for Ad-Hoc Tasks

4. Execution Checkpoints

When acting as an implementing Agent, you MUST:

5. Integration with TDD Plans

If you are executing tasks from a TDD Plan (e.g., generated via detail-plan-tdd.md), you MUST strictly tick the [ ] checkboxes in the Plan file as you progress through the RED, GREEN, and REFACTOR cycles. Do not mark a task as completely Done until all its TDD cycle checkboxes are ticked and the corresponding code is committed. This guarantees the Walkthrough Completion Gate can be audited.

6. TDD Evidence Log

When executing a TDD Plan, Agent MUST use the evidence logger script instead of running test commands directly. This creates an on-disk audit trail that survives conversation truncation.

Usage (Cwd-Agnostic Path Resolution)

The script path .agents/skills/tdd/scripts/tdd-test.sh is relative to the workspace root (directory containing .para-workspace.yml). Since Agent typically runs commands from Projects/<name>/repo/, the relative path varies depending on depth.

Agent MUST resolve the script path before invocation:

  1. Determine workspace root by locating .para-workspace.yml (usually 3 levels up from repo/).
  2. Construct the full path: <workspace-root>/.agents/skills/tdd/scripts/tdd-test.sh

Examples by Cwd:

# Cwd = workspace root (/)
bash .agents/skills/tdd/scripts/tdd-test.sh npm test --run test/foo.test.ts

# Cwd = Projects/<name>/repo/ (most common during plan execution)
bash ../../../.agents/skills/tdd/scripts/tdd-test.sh npm test --run test/foo.test.ts

# Cwd = Projects/<name>/ (project root)
bash ../../.agents/skills/tdd/scripts/tdd-test.sh npm test --run test/foo.test.ts

Cross-platform notes:

⛔ SCRIPT NOT FOUND GUARD: If tdd-test.sh returns exit code 127 (command not found),

Agent MUST:

1. Re-read this skill to verify the correct path

2. Try resolving from workspace root (find .agents/ directory)

3. STOP and report if still not found — DO NOT fall back to raw test commands

Running tests without the evidence logger is a TDD compliance violation

(Anti-Pattern: "Skipped evidence logger").

The script:

  1. Runs the test command and captures output + exit code.
  2. Appends an evidence entry (timestamp, status FAIL/PASS, command, output snippet) to artifacts/tests/tdd-evidence.log.
  3. Passes through the original output and exit code to the Agent.

TDD Gate (Step 5 in TDD Cycle)

Before committing, Agent MUST read artifacts/tests/tdd-evidence.log and verify:

Lifecycle

| Event | Action |

| :--------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ |

| Plan starts | Script creates artifacts/tests/tdd-evidence.log on first run |

| During plan | Evidence entries accumulate (append-only) |

| Session ends (/end) | Agent runs Quarantine hook to move artifacts/tests/* to tmp/ and appends .bak. This prevents sandbox trash buildup while preserving audit trails. |

| Plan done (Status → ✅ Done) | Agent renames to artifacts/tests/tdd-evidence-<version>.log (e.g., tdd-evidence-v0.13.2.log) |

| Next plan starts | Fresh artifacts/tests/tdd-evidence.log created automatically |

| .gitignore | artifacts/tests/ should be ignored |

Resource Router

| Resource | Relative Path | Description |

| :-------------------------- | :---------------------------- | :--------------------------------------------------------------------------------------------------------- |

| TDD Evidence Logger | scripts/tdd-test.sh | Bash wrapper that logs test FAIL/PASS to artifacts/tests/tdd-evidence.log for TDD Gate verification |

| Transcript Telemetry Parser | scripts/parse-transcript.py | Python script to parse Antigravity session transcript locally for tool counts, commands, and mutated files |

Transcript Parser Usage

When executing TDD Drift Verification & Cleanup or auditing session telemetry, run this script to parse conversation transcripts locally without context bloat:

python3 .agents/skills/tdd/scripts/parse-transcript.py [path_to_transcript_or_directory]

7. Isolated TDD Protocol (Workspace & Repo Protection)

To protect the active workspace from configuration pollution (junk files) and avoid committing ad-hoc test scripts to the open-source templates repository, Agent MUST follow the Isolated TDD Protocol:

A. Workspace Isolation (Mock/Sandbox output)

B. Temporary Test Scripts Management

C. Repo State Snapshot (Junk File Prevention)

Example Plan Task Templates:

To implement this protocol, a TDD-hardened plan MUST include the following tasks:

  1. Phase 0 (Start Snapshot):

```markdown

```

  1. At the end of intermediate phases (Phase 1, Phase 2, Phase 3...):

```markdown

```

  1. Pre-commit Gate (before Git Commit task):

```markdown

```

  1. Walkthrough (Final Post-Release Audit):

```markdown

```

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.