tdd-workflow: Implementing Red-Green-Refactor in Agent Conversations

Introduction

When building features, writing tests first and then implementing the code is a clear approach. But once you enter multi-turn Agent conversations, the order often gets disrupted: the model modifies business code directly, tests are added afterward or skipped entirely, and regressions become hard to track. Manually repeating the cycle of “write a failing test, write minimal implementation, then refactor” is costly, and the standard is inconsistent across different sessions.

The Skill introduced below packages the Test-Driven Development (TDD) workflow into a SKILL.md file that an Agent can read, enforcing a fixed Red-Green-Refactor rhythm to constrain collaboration—rather than relying on ad-hoc verbal agreements.

What Is This

tdd-workflow is an enterprise-sourced Skill on SkillHub, with the coordinate @org-02qudk26/tdd-workflow-zh. The current version is 1.0.0, categorized under dev-programming, and published by Zhiyu Technology. The README lists its name as “Test-Driven Development Cycle,” with the unique identifier hub-tdd-workflow.

Official summary: Test-Driven Development workflow principles; Red-Green-Refactor cycle. Tagged with requires_api_key=false, meaning installation and usage do not depend on any additional API Key. The Skill declares the following available tools: Read, Write, Edit, Glob, Grep, Bash.

SkillHub page: https://www.skillhub.cn/skills/org-02qudk26/tdd-workflow-zh
API registration: https://api.skillhub.cn/org-02qudk26/tdd-workflow-zh

(SkillHub statistics, based on scraped data: rating 100000, 831 downloads, 0 installs.)

Core Features

The Skill body is organized around the principle of “write tests first, code second,” and includes the following capability descriptions written into SKILL.md.

Red-Green-Refactor Cycle

  1. Red: Write a failing test.
  2. Green: Write the minimum code to make the test pass.
  3. Refactor: Improve code quality while keeping all tests passing, then move to the next round.

Three Laws of TDD

  1. Only write production code to make a failing test pass.
  2. Only write enough test code to prove it is failing.
  3. Only write enough code to make the test pass.

Phase Rules (Summary)

Red phase: The test must fail first; the test name describes the expected behavior; ideally, each test contains a single assertion. Focus areas include behavior, edge cases, and error states.

Green phase: Follow YAGNI—pass the test in the simplest way possible; do not optimize, just make the test pass.

Refactor phase: Eliminate duplication, clarify naming, improve structure, simplify logic; all tests must remain green; make small incremental changes, and commit after each refactoring step.

AAA and Test Priority

Each test is organized as Arrange (setup) → Act (execute) → Assert (verify).

Test priority order: happy path → error cases → edge cases → performance.

Applicability and Anti-Patterns

SKILL.md indicates that new features, bug fixes, and complex logic scenarios are well-suited for TDD; exploratory development and pure UI layout have lower value.

Anti-patterns include: skipping the Red phase, writing the implementation first and adding tests later, over-designing from the start, stuffing multiple assertions into a single test, and testing implementation details rather than behavior.

AI-Enhanced TDD (Multi-Agent Division)

The document suggests an optional division of labor: Agent A writes the failing test (Red), Agent B writes the minimal implementation (Green), and Agent C handles refactoring and optimization.

Installation and Activation

Follow the official SkillHub installation guide (https://skillhub.cn/install/skillhub.md). The Skill detail page requires installing the coordinate @org-02qudk26/tdd-workflow-zh per that document.

1. Check the CLI

command -v skillhub && skillhub --version

If not installed, run:

curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash

CLI only:

curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash -s -- --cli-only

2. Install into the Current Agent’s Skills Directory

--dir must point to the skills directory actually used by the current Agent.

skillhub install @org-02qudk26/tdd-workflow-zh --dir <skills directory>

Common paths (from the official installation docs):

  • Cursor: ~/.cursor/skills/
  • Claude Code: ~/.claude/skills/
  • Codex: ~/.codex/skills/ or the project’s .agents/skills/

Cursor example:

skillhub install @org-02qudk26/tdd-workflow-zh --dir ~/.cursor/skills/

After installation, refresh or restart the Agent as required to index the Skill.

Typical Usage

The README capability summary: Follow Red-Green-Refactor and AAA—first make a test fail, write a minimal implementation to pass it, then improve naming, duplication, and complexity while everything is green.

The official “use-case material” describes three scenarios (not standalone repos, intended to illustrate how the Skill guides an Agent):

  1. Fixing an edge-case bug: First write a failing test that reproduces the error, then apply the minimal logic fix and verify via regression.
  2. Complex new rules: Incrementally add tests covering the happy path, errors, and edge behaviors, turning tests into an executable specification.
  3. Feature works but has duplication: Perform small-step refactoring after all tests are green, keeping each step reversible and verifiable.

In actual conversations, you can declare at the start of a task that you are following tdd-workflow, and specify the project’s test-run command so that the Agent advances through SKILL.md phases when reading/writing code and executing Bash.

Use Cases and Considerations

Better suited for:

  • Teams or individuals using Cursor, Codex, Claude Code, etc., who want a unified TDD standard.
  • New features, defect fixes, and complex logic—scenarios SKILL.md marks as high-value.

Things to note:

  • The Skill defines the workflow and principles but does not ship with a test framework; you must configure test commands and directory structure within your project.
  • requires_api_key=false refers only to the Skill itself; API keys for external services your business depends on should still be managed per project conventions.
  • For exploratory prototyping or pure UI layout tasks, the documentation recommends reducing TDD weight to avoid mechanical application.
  • The multi-agent Red/Green/Refactor split is a suggested pattern in the docs; whether to split into separate sessions is up to your own process.

Conclusion

tdd-workflow encodes the Three Laws of TDD, the Red-Green-Refactor cycle, AAA, priority ordering, and anti-patterns into an Agent-readable SKILL.md, helping maintain the “tests as specification” rhythm across multi-turn collaboration. See SkillHub for installation details and metadata: https://www.skillhub.cn/skills/org-02qudk26/tdd-workflow-zh

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye