跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
开发与测试

tdd

Implement a ticket using Test-Driven Development (RED-GREEN-REFACTOR)

rlajous · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add rlajous/claude-code-commands --skill tdd

技能说明


name: tdd description: Implement a ticket using Test-Driven Development (RED-GREEN-REFACTOR) argument-hint: "" disable-model-invocation: false allowed-tools: Read, Grep, Glob, Bash, AskUserQuestion, Edit, Write user-invocable: true

Cross-runtime: follow runtime compatibility for invocation, delegation, configuration precedence, state paths, and permissions.

You are helping implement a ticket using Test-Driven Development (TDD). Your task is to guide the user through the RED-GREEN-REFACTOR cycle: write failing tests first, implement code to pass tests, then refactor while keeping tests green.

Step 1: Load Configuration

Check for configuration and context:

# Check for config and context files
if [ -f ".git-workflow/config.yaml" ]; then
  CONFIG_PATH=".git-workflow/config.yaml"
elif [ -f ".claude/config.yaml" ]; then
  CONFIG_PATH=".claude/config.yaml" # legacy read-only fallback
else
  CONFIG_PATH=""
fi
if [ -f ".git-workflow/pr-context.json" ]; then
  CONTEXT_PATH=".git-workflow/pr-context.json"
elif [ -f ".claude/.pr-context.json" ]; then
  CONTEXT_PATH=".claude/.pr-context.json" # legacy read-only fallback
else
  CONTEXT_PATH=""
fi

Load from the resolved CONFIG_PATH (if one exists):

qa:
  tdd:
    confirmBeforeGreen: true
    confirmBeforeRefactor: true
    maxRedAttempts: 3
    runFullSuiteEachPhase: false
    autoStartServer: false
testing:
  unit: auto
  lint: auto
  typeCheck: auto
issueTracker:
  type: auto

Default Values (when no config):

qa:
  tdd:
    confirmBeforeGreen: true
    confirmBeforeRefactor: true
    maxRedAttempts: 3
    runFullSuiteEachPhase: false
    autoStartServer: false

Step 2: Parse Arguments

Extract from $ARGUMENTS:

$ARGUMENTS

Patterns to Extract:

PatternExampleMeaning
Ticket IDPROJ-123, ENG-456Issue tracker ticket
GitHub Issue#789GitHub issue number
Linear URLhttps://linear.app/.../ENG-456/...Extract ticket ID
Jira URLhttps://....atlassian.net/browse/PROJ-123Extract ticket ID

Parsing Logic:

  • Extract ticket ID from URL if provided
  • Linear: Pattern /issue/([A-Z]+-\d+)/
  • Jira: Pattern /browse/([A-Z]+-\d+)
  • GitHub: Pattern issues/(\d+) or #(\d+)

Validation:

  • Ticket ID is required for TDD workflow
  • If not provided, prompt the user for it

Step 3: Fetch Ticket Details

Auto-Detect Issue Tracker Type

Based on ticket format and available MCP servers:

  • ^[A-Z]+-\d+$ with Linear MCP available -> Linear
  • ^[A-Z]+-\d+$ with Jira config/MCP available -> Jira
  • ^#?\d+$ or GitHub URL -> GitHub Issues (via gh CLI)

Linear Integration

If Linear ticket format is detected, use the Linear MCP server:

mcp__linear__get_issue(id: ticketId)

Extract:

  • Title
  • Description
  • Acceptance criteria
  • Labels (to determine bug vs feature)

Jira Integration

If Jira is configured, use the Jira MCP server:

mcp__jira__get_issue(issueKey: ticketId)

Extract:

  • Summary (title)
  • Description
  • Acceptance criteria
  • Issue type (Bug/Story/Task)

GitHub Issues

If GitHub format detected:

gh issue view {issue_number} --repo {owner}/{repo} --json title,body,labels

Determine Ticket Type

From ticket labels/type, determine:

Label/TypeClassificationTDD Behavior
bug, Bug, defectBugInclude reproduction step
feature, Story, enhancementFeatureSkip reproduction
refactor, tech-debtRefactorFocus on existing tests first

Step 4: Explore Codebase

Gather context about the codebase:

Find Related Files

Search for files related to the ticket:

# Search for keywords from ticket title/description
# Look for existing implementations
# Find related test files

Look for:

  • Files matching keywords from ticket
  • Existing test files in same area
  • Related service/controller files
  • Configuration files

Analyze Test Patterns

Identify existing test patterns:

# Find test files
find . -name "*.test.ts" -o -name "*.spec.ts" -o -name "*_test.py" -o -name "*_test.go" | head -20

# Check test framework imports
grep -r "describe\|it\|test\|expect" --include="*.test.*" -l | head -5

Extract:

  • Test file naming convention (*.test.ts, *.spec.ts, *_test.py, etc.)
  • Test framework (Jest, Vitest, pytest, go test, etc.)
  • Test structure (describe/it, test(), etc.)
  • Mock patterns used

Detect Test Framework

Full per-language detection commands, tables, and the detection-results JSON shape: see references/test-frameworks.md.

Step 5: Reproduce Issue (Bugs Only)

Skip this step for features and refactors.

For bugs, attempt to reproduce the issue:

Optional: Start Development Server

If qa.tdd.autoStartServer: true:

# Detect and start dev server (background)
npm run dev &
# or
pnpm dev &
# Wait for server to be ready
sleep 5

Manual Reproduction

Ask the user to confirm the bug reproduction:

Question: "Can you reproduce the bug? Describe the steps and current behavior."

Options:

  1. Yes, I can reproduce it
  2. No, let me try first
  3. Skip reproduction (proceed to tests)

Document Expected vs Actual

If user reproduces:

{
  "reproduction": {
    "steps": ["Step 1", "Step 2"],
    "currentBehavior": "What happens now",
    "expectedBehavior": "What should happen"
  }
}

Step 6: TDD RED Phase - Write Failing Tests

Create Test File

If test file doesn't exist, create it following project conventions:

# Determine test file location
# Based on source file: src/services/auth.ts -> tests/services/auth.test.ts
# Or co-located: src/servi
阅读完整来源 ↗