← 返回 Skills 市场
axelhu

Superpowers Tdd

作者 AxelHu · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
321
总下载
0
收藏
2
当前安装
1
版本数
在 OpenClaw 中安装
/install superpowers-tdd
功能描述
Enforces strict RED-GREEN-REFACTOR TDD cycle by writing failing real-code tests before implementation, verifying failures, coding minimally, then refactoring...
使用说明 (SKILL.md)

Superpowers TDD - 测试驱动开发

核心准则

先写测试,看着它失败,写最少的代码让它通过。

如果没看过测试失败,就不知道测试的是不是对的东西。

违反规则的字面意思 = 违反规则的精神。

铁律

没有失败的测试,就不能写生产代码

先写代码后写测试?删除它。从头开始。

没有例外:

  • 不要留着当"参考"
  • 不要在写测试时"改编"它
  • 不要看它
  • 删除就是删除

红-绿-重构循环

RED - 写失败的测试

写一个最小测试,展示应该发生什么。

# Good: 清晰名称,测试真实行为,一件事
def test_retries_failed_operations_3_times():
    attempts = 0
    def operation():
        nonlocal attempts
        attempts += 1
        if attempts \x3C 3:
            raise Exception('fail')
        return 'success'
    
    result = retry_operation(operation)
    assert result == 'success'
    assert attempts == 3
❌ Bad: 模糊名称,测试 mock 而不是真实代码
def test_retry_works():
    mock = MagicMock()
    mock.side_effect = [Exception(), Exception(), 'success']

要求:

  • 一个行为
  • 清晰名称
  • 真实代码(除非不可避免才用 mock)

验证 RED - 看着它失败

必须执行,从不跳过。

pytest tests/path/test_name.py -v
# 或项目对应的测试命令

确认:

  • 测试失败(不是错误)
  • 失败信息符合预期
  • 失败是因为功能缺失(不是拼写错误)

测试通过了? 你在测试已有行为。修复测试。

GREEN - 最少代码

写最简单的代码让测试通过。

# Good: 刚好够通过测试
def retry_operation(fn, max_retries=3):
    for i in range(max_retries):
        try:
            return fn()
        except Exception as e:
            if i == max_retries - 1:
                raise e
❌ Bad: 过度设计,加入了测试没要求的功能
def retry_operation(fn, options={max_retries=3, backoff='linear', onRetry=...})
    # YAGNI - 你不需要这个

不要添加功能、不要重构其他代码、不要"改进"超过测试要求。

验证 GREEN - 看着它通过

必须执行。

pytest tests/path/test_name.py -v

确认:

  • 测试通过
  • 其他测试仍然通过
  • 输出干净(无错误、无警告)

测试失败? 修代码,不是测试。

其他测试失败? 立刻修。

REFACTOR - 重构

只有在 green 之后:

  • 移除重复
  • 改进名称
  • 提取辅助函数

保持测试 green。不添加行为。

重复

下一个失败测试对应下一个功能。

好测试的特征

质量
最小 一件事。名称里有"and"?拆开它。 test_validates_email_and_domain_and_whitespace
清晰 名称描述行为 test_test1
展示意图 展示期望的 API 掩盖代码应该做什么

常见借口(别信)

借口 现实
"太简单了不用测" 简单代码也会坏。测试只用30秒。
"我之后测" 测试立即通过什么也证明不了。
"之后测试也能达到同样目标" 之后测试 = "这代码干了什么?" 先写测试 = "这代码应该干什么?"
"我已经手动测试了" 手动测试是随意的。没有记录,不能重跑。
"删除 X 小时的工作太浪费" 沉没成本谬误。留着不可信的代码是技术债。
"留着当参考" 你会改编它。那就是之后测试。删除就是删除。
"TDD 太教条" TDD 是务实的:比事后调试快。

红旗 - 停止并从头开始

  • 先写代码后写测试
  • 实现之后才写测试
  • 测试立即通过
  • 说不清为什么测试失败
  • "之后"添加的测试
  • 合理化"就这一次"
  • "我已经手动测试了"
  • "之后测试能达到同样目的"
  • "这是精神不是仪式"
  • "留着当参考"或"改编现有代码"

所有这些意味着:删除代码。从头用 TDD。

Bug 修复示例

Bug: 空邮箱被接受

RED

def test_rejects_empty_email():
    result = submit_form({'email': ''})
    assert result['error'] == 'Email required'

Verify RED

$ pytest
FAIL: expected 'Email required', got undefined

GREEN

def submit_form(data):
    if not data.get('email', '').strip():
        return {'error': 'Email required'}
    # ...

Verify GREEN

$ pytest
PASS

REFACTOR 如需要可提取多字段验证。

完成前检查表

  • 每个新函数/方法都有测试
  • 实现前看过每个测试失败
  • 每个测试失败原因符合预期(功能缺失,不是 typo)
  • 写了最少的代码让每个测试通过
  • 所有测试通过
  • 输出干净(无错误、无警告)
  • 测试使用真实代码(除非不可避免才用 mock)
  • 覆盖了边界情况和错误

不能全部打勾?跳过了 TDD。从头开始。

安全使用建议
This skill is coherent for a strict TDD coach — it tells an agent to write failing tests, run pytest, implement minimal code, and refactor. Before you use or let an agent run this skill: (1) ensure your project is under version control and committed (or work in a disposable branch) so 'delete code' guidance can't cause data loss; (2) confirm the correct test command (pytest or project-specific) and that the runtime environment has necessary tooling; (3) if you allow autonomous agent actions, restrict write permissions or require manual approval for file modifications; (4) be aware the skill is dogmatic — it may insist on deleting code or restarting work if its TDD rules detect violations. If these precautions are acceptable, the skill is internally consistent with its stated purpose.
能力评估
Purpose & Capability
Name/description promise (enforce RED-GREEN-REFACTOR TDD) directly matches the SKILL.md instructions, which are focused on writing tests, running pytest, implementing minimal code, and refactoring. No unrelated credentials, binaries, or installs are requested.
Instruction Scope
Instructions stay within TDD workflow (writing tests, running pytest, editing code). However the guidance is prescriptive about deleting existing code if tests were written after implementation — this is potentially destructive for a user's repository if followed blindly. The skill tells the agent to run pytest and modify/delete code, which is expected for a TDD tutor but has real-world side effects.
Install Mechanism
No install spec and no code files — lowest-risk instruction-only skill. There is nothing downloaded or written to disk by the skill itself.
Credentials
The skill declares no environment variables, no credentials, and no config paths. The runtime instructions reference only typical developer tools (pytest) and project files; nothing asks for unrelated secrets or access.
Persistence & Privilege
always:false (no forced presence). The skill can be invoked autonomously by the agent (platform default). Because the instructions include modifying/deleting project code, granting the agent file-system or repo write access could be risky — exercise the usual caution when allowing autonomous actions.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install superpowers-tdd
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /superpowers-tdd 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release: OpenClaw-adapted skill for the Superpowers development methodology suite.
元数据
Slug superpowers-tdd
版本 1.0.0
许可证 MIT-0
累计安装 2
当前安装数 2
历史版本数 1
常见问题

Superpowers Tdd 是什么?

Enforces strict RED-GREEN-REFACTOR TDD cycle by writing failing real-code tests before implementation, verifying failures, coding minimally, then refactoring... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 321 次。

如何安装 Superpowers Tdd?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install superpowers-tdd」即可一键安装,无需额外配置。

Superpowers Tdd 是免费的吗?

是的,Superpowers Tdd 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Superpowers Tdd 支持哪些平台?

Superpowers Tdd 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Superpowers Tdd?

由 AxelHu(@axelhu)开发并维护,当前版本 v1.0.0。

💬 留言讨论