Token导航 LogoToken导航TokenDH.com
前端设计external-servicegithub未标认证来源可访问许可证需确认审计通过

tdd-workflowTDD 工作流程

Agent Skill

tdd-workflow 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

535

周安装

23

GitHub Stars

8

下载量

188
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:tdd-workflow(TDD 工作流程)
来源仓库:https://github.com/hieutrtr/ai1-skills
仓库路径:skills/tdd-workflow
安装命令:
npx skills add https://github.com/hieutrtr/ai1-skills --skill tdd-workflow
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/hieutrtr/ai1-skills --skill tdd-workflow

简介

tdd-workflow 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装,需确认权限和维护状态。
  • 使用前建议核验具体用法,注意是否会触发联网、命令执行或文件读写操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

TDD Workflow

When to Use

Activate this skill when:

  • The user explicitly requests TDD, test-first, or red-green-refactor
  • Implementing new functions, methods, endpoints, or components where test-first is valuable
  • Fixing bugs where a regression test should be written first
  • The user says "write the test first", "TDD this", or "red-green-refactor"

Do NOT use this skill for:

  • Configuration files, environment setup, or static content
  • One-line fixes or trivial changes
  • Exploratory prototyping or proof-of-concept code
  • Code that cannot be meaningfully tested in isolation
  • Testing pattern details (use pytest-patterns or react-testing-patterns for HOW to write tests)

Instructions

The TDD Cycle

┌─────────────────────────────────────────────────────┐
│                                                     │
│   ┌─────┐     ┌───────┐     ┌──────────┐          │
│   │ RED │ ──→ │ GREEN │ ──→ │ REFACTOR │ ──→ ...  │
│   └─────┘     └───────┘     └──────────┘          │
│                                                     │
│   Write ONE    Write MINIMUM   Clean up code        │
│   failing      code to make    while ALL tests      │
│   test         it pass         stay GREEN            │
│                                                     │
└─────────────────────────────────────────────────────┘

Phase 1: RED — Write a Failing Test

  1. Write exactly ONE test that describes the expected behavior
  2. The test must be specific: test one behavior, not multiple
  3. Run the test suite and confirm the new test FAILS
  4. The failure message should clearly describe what is missing

Backend (pytest):

pytest tests/unit/test_user_service.py::test_create_user_returns_user -x
# Expected: FAILED (function/class does not exist yet)

Frontend (Vitest):

npx vitest run src/hooks/useAuth.test.ts --reporter=verbose
# Expected: FAILED (hook/component does not exist yet)

Rules for RED phase:

  • Write the simplest test that expresses the requirement
  • The test should fail for the RIGHT reason (missing implementation, not syntax error)
  • Don't write more than one failing test at a time
  • Import from the location where the code WILL live (even though it doesn't exist yet)

Phase 2: GREEN — Make It Pass

  1. Write the MINIMUM code to make the failing test pass
  2. Do NOT add extra functionality, error handling, or edge cases
  3. It's okay to hardcode values or use simple implementations
  4. Run the test suite and confirm ALL tests pass (not just the new one)
# Backend
pytest tests/unit/test_user_service.py -x

# Frontend
npx vitest run src/hooks/useAuth.test.ts

Rules for GREEN phase:

  • Minimum code means minimum — if a constant satisfies the test, use a constant
  • Do not add code that no test requires
  • Do not refactor during this phase
  • Do not write additional tests during this phase
  • If tests pass, move to REFACTOR

Phase 3: REFACTOR — Clean Up

  1. Improve code quality while keeping all tests green
  2. Remove duplication (DRY)
  3. Improve naming and readability
  4. Extract functions or classes if needed
  5. Run tests after EVERY change — they must stay green
# After each refactoring change
pytest tests/ -x    # Must pass
npx vitest run      # Must pass

Rules for REFACTOR phase:

  • Every change must keep tests green
  • Refactor both production code AND test code
  • Do NOT add new functionality (that requires a new RED phase)
  • If you break a test, undo the refactoring immediately

Phase 4: COMMIT

After a successful REFACTOR phase:

  1. Stage all changes (test + implementation)
  2. Commit with a descriptive message
  3. Return to Phase 1 (RED) for the next behavior

Strict TDD Rules

These rules are non-negotiable when this skill is active:

  1. NEVER write production code without a failing test first
  2. NEVER write more than one failing test at a time
  3. NEVER add functionality that no test requires
  4. ALWAYS run tests after every change
  5. ALWAYS commit after each successful GREEN-REFACTOR cycle
  6. ALWAYS keep the RED-GREEN-REFACTOR cycle short (minutes, not hours)

Backend TDD Flow (pytest)

1. Write test:     tests/unit/test_user_service.py::test_create_user_returns_user
2. Run:            pytest tests/unit/test_user_service.py::test_create_user_returns_user -x
3. See:            FAILED - ImportError or AssertionError
4. Implement:      app/services/user_service.py (minimum code)
5. Run:            pytest tests/unit/test_user_service.py -x
6. See:            PASSED
7. Refactor:       Clean up, run tests again
8. Commit:         "Add UserService.create_user"
9. Next test:      test_create_user_rejects_duplicate_email

Frontend TDD Flow (Testing Library)

1. Write test:     src/components/UserCard.test.tsx::renders user name
2. Run:            npx vitest run src/components/UserCard.test.tsx
3. See:            FAILED - module not found
4. Implement:      src/components/UserCard.tsx (minimum code)
5. Run:            npx vitest run src/components/UserCard.test.tsx
6. See:            PASSED
7. Refactor:       Clean up, run tests again
8. Commit:         "Add UserCard component"
9. Next test:      calls onEdit when button clicked

Bug Fix TDD Flow

When fixing a bug, always start with a failing test that reproduces the bug:

1. Reproduce:      Understand the bug and its trigger condition
2. Write test:     Test that exercises the exact scenario that causes the bug
3. Run:            Confirm FAILED (the test reproduces the bug)
4. Fix:            Implement the minimum fix
5. Run:            Confirm PASSED (bug is fixed)
6. Refactor:       Clean up if needed
7. Commit:         "Fix: [describe the bug]"

This guarantees the bug cannot regress — the test will catch it.

Examples

TDD: UserService.create_user (3 Cycles)

Cycle 1 — RED: Test that create_user returns a user

async def test_create_user_returns_user(db_session):
    service = UserService(db_session)
    user = await service.create_user(UserCreate(email="a@b.com", password="12345678", display_name="A"))
    assert user.email == "a@b.com"
    assert user.id is not None

GREEN: Implement UserService.create_user with basic logic. REFACTOR: Extract password hashing. Commit.

Cycle 2 — RED: Test that duplicate email raises error

async def test_create_user_rejects_duplicate_email(db_session):
    service = UserService(db_session)
    await service.create_user(UserCreate(email="a@b.com", password="12345678", display_name="A"))
    with pytest.raises(ConflictError):
        await service.create_user(UserCreate(email="a@b.com", password="87654321", display_name="B"))

GREEN: Add duplicate check before insert. REFACTOR: Clean up. Commit.

Cycle 3 — RED: Test that password is hashed

async def test_create_user_hashes_password(db_session):
    service = UserService(db_session)
    user = await service.create_user(UserCreate(email="a@b.com", password="12345678", display_name="A"))
    assert user.hashed_password != "12345678"
    assert verify_password("12345678", user.hashed_password)

GREEN: Already passing from cycle 1 refactor? Then this test is a verification, not a RED. Write a test for a NEW behavior instead.

Edge Cases

  • When to skip TDD: Configuration files (.env, tsconfig.json), static content, auto-generated code (Alembic migrations), one-off scripts, and exploratory prototyping.
  • TDD with external dependencies: Mock at the boundary. If testing a service that calls an external API, mock the API client, not the HTTP library. Test the service's behavior, not the mock.
  • Large features: Break the feature into small, testable behaviors. Each behavior gets its own RED-GREEN-REFACTOR cycle. The sum of all cycles implements the full feature.
  • Refactoring existing code without tests: First write tests for the existing behavior (characterization tests). Then refactor with those tests as a safety net. This is not strict TDD but is a valid use of the test-first mindset.
  • Pair with pattern skills: This skill defines the WORKFLOW (when to write tests vs code). Use pytest-patterns or react-testing-patterns for the PATTERNS (how to structure tests, which assertions to use).

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.18%
按下载量换算66

Claude

28.12%
按下载量换算53

Cursor

21.02%
按下载量换算40

Gemini CLI

8.76%
按下载量换算16

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills