| name | spk-tdd |
| description | TDD loop แบบเข้มงวด - RED test ก่อน, GREEN implement ขั้นต่ำ, REFACTOR หลัง green พร้อม verification gates |
| argument-hint | [feature, behavior, bug, หรือ plan reference] |
spk-tdd
รัน TDD loop แบบเข้มงวด: เขียน test ที่ fail ยืนยันว่า fail ด้วยเหตุผลที่ถูกต้อง implement ขั้นต่ำให้ pass refactor แล้วทำซ้ำ
รวบรวม Context
- ถ้าอยู่ใน git worktree ให้รัน
git status --short และ git log -3 --oneline; ถ้าไม่ใช่ git repo ให้ข้าม git context และทำงานต่อ
- ระบุ test setup (package.json, pyproject.toml, pytest.ini, jest.config, vitest.config)
TDD Cycle
RED: เขียน Failing Test
- เขียน behavior test ขั้นต่ำที่กำหนด expected behavior
- Test ต้องเจาะจงและโฟกัสที่ behavior เดียว
Verify RED
- รัน focused test และยืนยันว่า fail ด้วยเหตุผลที่คาดไว้
- ถ้า test pass ทันที ให้แก้ test ก่อน code (มัน test สิ่งผิด)
GREEN: Implementation ขั้นต่ำ
- เขียน implementation ที่เล็กที่สุดที่ทำให้ test pass
- อย่าเพิ่ม features, optimizations หรือ refactoring
Verify GREEN
- รัน focused test ต้อง pass
- รัน regression suite ที่เกี่ยวข้อง ไม่มีอะไรพัง
REFACTOR
- ทำความสะอาด code เฉพาะตอนที่ tests green
- รัน tests ที่เกี่ยวข้องทั้งหมดหลัง refactor
Evidence
- บันทึก evidence ของ TDD cycle ที่ตรวจสอบแล้ว
- Commit เฉพาะเมื่อผู้ใช้อนุญาต action นี้แยกต่างหาก แล้วทำซ้ำสำหรับ behavior ถัดไป
Output Format
## TDD Cycle Report
- Behavior: <สิ่งที่ implement>
- Test file: <path>
- RED: <confirmed - test fails ด้วยเหตุผลที่คาดไว้>
- GREEN: <confirmed - test passes>
- REFACTOR: <สิ่งที่ทำความสะอาด>
- Regression suite: <pass/fail>
- Commit: <hash, proposed message หรือ "not authorized">
- Remaining behaviors: <list หรือ "none">
Hard Stops
- ถ้า test แรก pass ทันที ให้แก้ test ก่อน code
- ถ้าไม่มี test harness ที่ใช้ได้ ให้ return
NEEDS_TEST_HARNESS พร้อม harness ที่เล็กที่สุดที่ควรเพิ่ม
- ถ้าแก้ bug ให้รวม regression test ที่ fail ก่อน fix
- ห้าม commit, push หรือ deploy เว้นแต่ผู้ใช้อนุญาต action นั้นแยกต่างหาก
ข้อควรระวัง
- อย่ายอมรับ tests ที่ pass ก่อน implementation
- อย่าข้าม tests
- อย่ารวมหลาย behaviors ในหนึ่ง cycle หนึ่ง behavior ต่อ cycle
- อย่า refactor ตอน red
- ถ้าได้รับอนุญาตให้ commit ให้ใช้เฉพาะ cycle ที่ตรวจสอบแล้ว