Moai workflow tdd

From modu-ai/moai-adk · View interactive version

Moai workflow tdd is an AI agent skill from the GitHub repository modu-ai/moai-adk. Test-Driven Development workflow specialist using RED-GREEN-REFACTOR cycle for test-first software development. Use when developing new features from scratch or when behavior specification drives implementation.

How to use this skill

Skill file

Test-Driven Development (TDD) Workflow

Development Mode Configuration (CRITICAL)

[NOTE] This workflow is selected based on .moai/config/sections/quality.yaml:

constitution:
  development_mode: tdd    # or ddd

When to use this workflow:

Key distinction:

Quick Reference

Test-Driven Development provides a disciplined approach for creating new functionality where tests define the expected behavior before implementation.

Core Cycle - RED-GREEN-REFACTOR:

When to Use TDD:

When NOT to Use TDD:


Core Philosophy

TDD vs DDD Comparison

TDD Approach:

DDD Approach:

Test-First Principle

The golden rule of TDD is that tests must be written before implementation code:


Implementation Guide

Phase 1: RED - Write a Failing Test

The RED phase focuses on defining the desired behavior through a failing test.

Writing Effective Tests

Before writing any implementation code:

Test Structure

Follow the Arrange-Act-Assert pattern:

Verification

The test must fail initially:

Phase 2: GREEN - Make the Test Pass

The GREEN phase focuses on writing minimal code to satisfy the test.

Minimal Implementation

Write only enough code to make the test pass:

Verification

Run the test to confirm it passes:

Phase 3: REFACTOR - Improve the Code

The REFACTOR phase focuses on improving code quality while maintaining behavior.

Safe Refactoring

With passing tests as a safety net:

Continuous Verification

After each refactoring step:


TDD Workflow Execution

Standard TDD Session

When executing TDD through manager-develop:

Step 1 - Understand Requirements:

Step 2 - RED Phase:

Step 3 - GREEN Phase:

Step 4 - REFACTOR Phase:

Step 5 - Repeat:

TDD Loop Pattern

For features requiring multiple test cases:


Quality Metrics

TDD Success Criteria

Test Coverage (Required):

Code Quality (Goals):

TDD-Specific TRUST Validation

Apply TRUST 5 framework with TDD focus:


Integration Points

With DDD Workflow

TDD and DDD are complementary:

With Testing Workflow

TDD integrates with testing workflow:

With Quality Framework

TDD outputs feed into quality assessment:


Troubleshooting

Common Issues

Test is Too Complex:

Implementation Grows Too Fast:

Refactoring Breaks Tests:

Recovery Procedures

When TDD discipline breaks down:


Version: 1.0.0

Status: Active

<!-- moai:evolvable-start id="rationalizations" -->

Common Rationalizations

| Rationalization | Reality |

|---|---|

| "I'll add tests after the implementation works" | Post-hoc tests verify what the code does, not what it should do. They miss the bugs RED phase catches. |

| "The existing tests cover this case" | Existing tests verify old behavior. New behavior needs its own failing test first. |

| "This function is too simple to test" | Simple functions accumulate complexity. The test documents expected behavior before drift. |

| "I tested it manually in the terminal" | Manual checks do not persist. Tomorrow's change breaks the contract with no signal. |

| "The test requires complex mocking" | If the test is hard to write, the code is hard to reason about. Refactor the design first. |

| "Tests slow me down" | Test-first surfaces design problems early, when they are cheapest to fix. |

| "I'll skip REFACTOR this cycle to keep moving" | Skipped refactors compound. The next cycle starts from a worse baseline. |

DAMP over DRY: In test code, prefer Descriptive And Meaningful Phrases over Don't Repeat Yourself. Duplication inside a test that makes the intent obvious is better than an abstraction that hides it.

Beyonce Rule: If you liked it, you should have put a test on it. Any behavior CI does not verify will eventually break without warning.

<!-- moai:evolvable-end -->

<!-- moai:evolvable-start id="red-flags" -->

Red Flags

<!-- moai:evolvable-end -->

<!-- moai:evolvable-start id="verification" -->

Verification

<!-- moai:evolvable-end -->

Test-First Anti-Cheat

[ZONE:Evolvable] [HARD] The Red Flags and Verification checklists above sit in advisory (evolvable) blocks and are consumed by no completion gate. This section promotes them into two enforced invariants that make test-first falsifiable in the completion matrix.

These two invariants close the falsifiability gap: before them, a fully-passing self-verification matrix was producible with NO RED evidence, so test-first could not be distinguished from test-after by the completion report. After them, the matrix requires the verbatim pre-GREEN RED output, so a run that skipped RED has no such output to supply and the matrix is structurally incomplete.

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.