tdd

A command that applies test-driven development (TDD): define the expected interface, write tests before the implementation, then write the smallest code needed to pass them and refactor it.

In plain words
What is it for?
Use it when adding features or functions, fixing bugs, refactoring code, or building core business logic.
Why use it?
It makes the expected behaviour explicit before code is written and helps catch bugs and untested paths. It also checks that test coverage reaches at least 80%.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/codelably/harmony-claude-code/tdd
Clone the repo
git clone --depth 1 https://github.com/codelably/harmony-claude-code
Per session 28 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,563 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 81% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.02563
Opus 5 $0.00014 $0.01282
Sonnet 5 $0.00006 $0.00513
Haiku 4.5 $0.00003 $0.00256

Measured yesterday against content hash bdd3ab3e444b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

tdd scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

81% identical to tdd — 162 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

commands/tdd.md · 327 lines

How it starts

The opening of the file, as written. The whole thing — 327 lines — stays where its author put it; the contents beside it link to each section on GitHub.

TDD 命令

此命令调用 tdd-guide 智能体(Agent)来强制执行测试驱动开发(TDD)方法论。

此命令的作用

  1. 搭建接口(Scaffold Interfaces) - 首先定义类型/接口
  2. 先生成测试 - 编写失败的测试(红/RED)
  3. 编写最小化实现代码 - 只编写刚好能通过测试的代码(绿/GREEN)
  4. 重构(Refactor) - 在保持测试通过的前提下优化代码(重构/REFACTOR)
  5. 验证覆盖率 - 确保测试覆盖率达到 80% 以上

适用场景

在以下情况下使用 /tdd

  • 实现新功能
  • 添加新的函数/组件
  • 修复 Bug(先编写重现该 Bug 的测试)
  • 重构现有代码
  • 构建核心业务逻辑

工作原理

tdd-guide 智能体将:

  1. 为输入/输出定义接口
  2. 编写会失败(FAIL)的测试(因为代码尚未存在)
  3. 运行测试并验证它们因预期的原因而失败
  4. 编写最小化实现以使测试通过
  5. 运行测试并验证它们通过
  6. 在保持测试通过的前提下重构代码
  7. 检查覆盖率,如果低于 80% 则添加更多测试

TDD 循环

红 (RED) → 绿 (GREEN) → 重构 (REFACTOR) → 重复 (REPEAT)

红 (RED):      编写一个失败的测试
绿 (GREEN):    编写最小化代码以通过测试
重构 (REFACTOR): 改进代码,保持测试通过
重复 (REPEAT):   下一个功能/场景

使用示例

User: /tdd 我需要一个计算市场流动性评分(market liquidity score)的函数

Agent (tdd-guide):
# TDD 会话:市场流动性评分计算器

## 步骤 1:定义接口 (SCAFFOLD)

```typescript
// lib/liquidity.ts
export interface MarketData {
  totalVolume: number
  bidAskSpread: number
  activeTraders: number
  lastTradeTime: Date
}

export function calculateLiquidityScore(market: MarketData): number {
  // TODO: 待实现
  throw new Error('Not implemented')
}

步骤 2:编写失败的测试 (RED)

// lib/liquidity.test.ts
import { calculateLiquidityScore } from './liquidity'

describe('calculateLiquidityScore', () => {
  it('should return high score for liquid market', () => {
    const market = {
      totalVolume: 100000,
      bidAskSpread: 0.01,
      activeTraders: 500,
      lastTradeTime: new Date()
    }

    const score = calculateLiquidityScore(market)

    expect(score).toBeGreaterThan(80)
    expect(score).toBeLessThanOrEqual(100)
  })

  it('should return low score for illiquid market', () => {
    const market = {
      totalVolume: 100,
      bidAskSpread: 0.5,
      activeTraders: 2,
      lastTradeTime: new Date(Date.now() - 86400000) // 1 天前
    }

    const score = calculateLiquidityScore(market)

    expect(score).toBeLessThan(30)
    expect(score).toBeGreaterThanOrEqual(0)
  })

Read the full file on GitHub · 327 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 327 lines · 28 tokens per session scan A bdd3ab3e444b

Subscribe to this mod's changes

tdd is a command published in the GitHub repository codelably/harmony-claude-code (42 stars, last pushed 6mo ago), licensed MIT. It adds 28 tokens to every session and 2,563 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. It is 81% identical to tdd, differing in 162 lines, and is treated as a copy.