superspec-tdd

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Superspec TDD (Mechanical Enforcement)

Superspec TDD(机械强制实施)

Iron Law

铁律

NO PRODUCTION CODE BEFORE A VERIFIED FAILING TEST.
在通过验证的失败测试编写完成前,禁止编写任何生产代码。

Task Tags

任务标签

  • [TDD][RED]
  • [TDD][VERIFY_RED]
  • [TDD][GREEN]
  • [TDD][VERIFY_GREEN]
  • [TDD][REFACTOR]
  • [NON-TDD][DO]
  • [NON-TDD][VERIFY]
  • [TDD][RED]
  • [TDD][VERIFY_RED]
  • [TDD][GREEN]
  • [TDD][VERIFY_GREEN]
  • [TDD][REFACTOR]
  • [NON-TDD][DO]
  • [NON-TDD][VERIFY]

Allowed [NON-TDD] Scope (ONLY)

允许的[NON-TDD]范围(仅限以下场景)

  • docs-only
  • config-only (no behavior change)
  • generated outputs
  • formatting/renaming only
  • 仅文档修改
  • 仅配置修改(无行为变更)
  • 生成的输出内容
  • 仅格式调整/重命名

Core Principle

核心原则

If you didn't watch the test fail, you don't know if it tests the right thing.
如果你没有看到测试失败,你就无法确定该测试是否验证了正确的内容。

Gates (non-negotiable)

强制关卡(无协商空间)

  • A task line with
    [TDD][GREEN]
    MUST NOT be executed unless its corresponding
    [TDD][VERIFY_RED]
    task for the same Scenario is completed.
  • A
    [NON-TDD][DO]
    task MUST NOT be executed unless there is a corresponding
    [NON-TDD][VERIFY]
    task line.
  • 带有
    [TDD][GREEN]
    的任务行,只有当对应场景的
    [TDD][VERIFY_RED]
    任务完成后,才可执行。
  • [NON-TDD][DO]
    任务只有在存在对应的
    [NON-TDD][VERIFY]
    任务行时,才可执行。

VERIFY_RED Decision Table (zero-decision)

VERIFY_RED决策表(无主观判断)

A
[TDD][VERIFY_RED]
task MUST result in exactly one of these outcomes:
  • PASS: STOP. The test is not proving missing behavior. Fix the test/spec/Test Obligation. Do not write production code.
  • ERROR (test runner/config/typo): STOP. Fix the error and re-run until it FAILs for the expected reason.
  • FAIL: Continue only if output contains the required
    Expected (RED)
    substring.
[TDD][VERIFY_RED]
任务必须产生以下结果之一:
  • 通过:停止。该测试未验证缺失的行为。修复测试/规格说明/测试义务,不要编写生产代码。
  • 错误(测试运行器/配置/输入错误):停止。修复错误后重新运行,直到因预期原因失败。
  • 失败:仅当输出包含所需的
    Expected (RED)
    子字符串时,才可继续。

VERIFY_GREEN Decision Table (zero-decision)

VERIFY_GREEN决策表(无主观判断)

A
[TDD][VERIFY_GREEN]
task MUST result in exactly one of these outcomes:
  • PASS: Continue.
  • FAIL: Fix production code (not the test).
  • Other tests failing: STOP and fix until all relevant tests are green.
[TDD][VERIFY_GREEN]
任务必须产生以下结果之一:
  • 通过:继续。
  • 失败:修复生产代码(而非测试)。
  • 其他测试失败:停止并修复,直到所有相关测试通过。

REFACTOR Rule

重构规则

  • [TDD][REFACTOR]
    is allowed only after
    [TDD][VERIFY_GREEN]
    .
  • After refactor, re-run the same Verify Command and confirm it still passes.
  • 仅在
    [TDD][VERIFY_GREEN]
    完成后,才可执行
    [TDD][REFACTOR]
  • 重构后,重新运行相同的验证命令,确认测试仍可通过。

[NON-TDD] Verification Rule

[NON-TDD]验证规则

  • A
    [NON-TDD][VERIFY]
    step MUST be mechanical (command output / file existence /
    openspec validate --all --json
    ), not a manual check.
  • If you cannot express verification as a command or deterministic check, this is not [NON-TDD].
  • [NON-TDD][VERIFY]
    步骤必须是机械性的(命令输出/文件存在性检查/
    openspec validate --all --json
    ),而非人工检查。
  • 如果你无法将验证表达为命令或确定性检查,则不属于[NON-TDD]场景。

When Stuck (zero-decision)

遇到困境时(无主观判断)

  • Don't know how to test: the contract is unclear. Update
    specs/**/spec.md
    Test Obligation and/or
    design.md
    Test Commands.
  • Test setup is huge: simplify the contract or split the Scenario.
  • Must mock everything: code is too coupled. Stop and revise design boundaries.
  • 不知道如何测试:契约不清晰。更新
    specs/**/spec.md
    中的测试义务和/或
    design.md
    中的测试命令。
  • 测试设置过于复杂:简化契约或拆分场景。
  • 必须模拟所有内容:代码耦合度过高。停止并重新设计边界。

Strict Prohibitions

严格禁令

  • NEVER test mock behavior.
  • NEVER add test-only methods to production code.
  • NEVER mock without understanding dependency side effects.
Reference:
references/testing-anti-patterns.md
  • 绝不要测试模拟行为。
  • 绝不要在生产代码中添加仅用于测试的方法。
  • 绝不要在未理解依赖项副作用的情况下进行模拟。
参考文档:
references/testing-anti-patterns.md