tdd

A TDD command guides test-driven development: define the interface, write a failing test, implement the smallest passing solution, and then improve the code.

In plain words
What is it for?
Use it for new features, functions, components, bug fixes, refactoring, and important business logic. It repeats the test-and-implementation cycle and adds tests when coverage is low.
Why use it?
It makes expected behavior explicit before implementation and checks that changes keep working while aiming for at least 80% test coverage.

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/luohaothu/everything-codex/tdd
Clone the repo
git clone --depth 1 https://github.com/Luohaothu/everything-codex
Per session 37 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,309 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 91% 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.00037 $0.02309
Opus 5 $0.00018 $0.01154
Sonnet 5 $0.00007 $0.00462
Haiku 4.5 $0.00004 $0.00231

Measured yesterday against content hash c0286b0c286d, 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

91% identical to tdd — 194 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.

docs/zh-CN/commands/tdd.md · 331 lines

How it starts

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

TDD 命令

此命令调用 tdd-guide 代理来强制执行测试驱动开发方法。

此命令的作用

  1. 搭建接口 - 首先定义类型/接口
  2. 首先生成测试 - 编写失败的测试(红)
  3. 实现最小化代码 - 编写刚好足够的代码以通过测试(绿)
  4. 重构 - 改进代码,同时保持测试通过(重构)
  5. 验证覆盖率 - 确保 80%+ 的测试覆盖率

何时使用

在以下情况下使用 /tdd

  • 实现新功能时
  • 添加新函数/组件时
  • 修复错误时(首先编写重现错误的测试)
  • 重构现有代码时
  • 构建关键业务逻辑时

工作原理

tdd-guide 代理将:

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

TDD 循环

RED → GREEN → REFACTOR → REPEAT

RED:      Write a failing test
GREEN:    Write minimal code to pass
REFACTOR: Improve code, keep tests passing
REPEAT:   Next feature/scenario

使用示例

User: /tdd I need a function to calculate market liquidity score

Agent (tdd-guide):
# TDD Session: Market Liquidity Score Calculator

## Step 1: Define Interface (SCAFFOLD)

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

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

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

// 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 day ago
    }

    const score = calculateLiquidityScore(market)

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

Read the full file on GitHub · 331 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 · 331 lines · 37 tokens per session scan A c0286b0c286d

Subscribe to this mod's changes

tdd is a command published in the GitHub repository Luohaothu/everything-codex (24 stars, last pushed 21d ago), licensed MIT. It adds 37 tokens to every session and 2,309 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. It is 91% identical to tdd, differing in 194 lines, and is treated as a copy.