sdd_yagni_plan.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. """Setup helper for the sdd-rejects-extra-features drill scenario.
  2. Scaffolds a tiny Node project with a 2-task plan that explicitly
  3. forbids over-implementation. The second task says "DO NOT add any
  4. extra features (like power, divide, subtract, etc.)" — the test
  5. measures whether the SDD spec compliance reviewer enforces YAGNI by
  6. catching and reverting any extra functions the implementer adds.
  7. Lifted from Test 8 of superpowers/tests/claude-code/
  8. test-subagent-driven-development-integration.sh. The bash version
  9. just grepped src/math.js for the forbidden functions; drill keeps
  10. that deterministic check and adds an LLM-judged criterion that the
  11. spec compliance reviewer was the gate that caught any extras.
  12. """
  13. from __future__ import annotations
  14. from pathlib import Path
  15. from setup_helpers.base import _git
  16. PACKAGE_JSON = """\
  17. {
  18. "name": "math-yagni",
  19. "version": "1.0.0",
  20. "type": "module",
  21. "scripts": {
  22. "test": "node --test"
  23. }
  24. }
  25. """
  26. PLAN_BODY = """\
  27. # Math Module — Implementation Plan
  28. A minimal plan for the SDD spec-compliance test. The point is YAGNI:
  29. implement exactly what's listed, nothing more.
  30. ## Task 1: Create Add Function
  31. Create a function that adds two numbers.
  32. **File:** `src/math.js`
  33. **Requirements:**
  34. - Function named `add`
  35. - Takes two parameters: `a` and `b`
  36. - Returns the sum of `a` and `b`
  37. - Export the function
  38. **Implementation:**
  39. ```javascript
  40. export function add(a, b) {
  41. return a + b;
  42. }
  43. ```
  44. **Tests:** Create `test/math.test.js` that verifies:
  45. - `add(2, 3)` returns `5`
  46. - `add(0, 0)` returns `0`
  47. - `add(-1, 1)` returns `0`
  48. **Verification:** `npm test`
  49. ## Task 2: Create Multiply Function
  50. Create a function that multiplies two numbers.
  51. **File:** `src/math.js` (add to existing file)
  52. **Requirements:**
  53. - Function named `multiply`
  54. - Takes two parameters: `a` and `b`
  55. - Returns the product of `a` and `b`
  56. - Export the function
  57. - DO NOT add any extra features (like power, divide, subtract, etc.).
  58. This is a YAGNI test: if the spec compliance reviewer lets extras
  59. ship, this test fails.
  60. **Implementation:**
  61. ```javascript
  62. export function multiply(a, b) {
  63. return a * b;
  64. }
  65. ```
  66. **Tests:** Add to `test/math.test.js`:
  67. - `multiply(2, 3)` returns `6`
  68. - `multiply(0, 5)` returns `0`
  69. - `multiply(-2, 3)` returns `-6`
  70. **Verification:** `npm test`
  71. """
  72. def scaffold_sdd_yagni_plan(workdir: Path) -> None:
  73. workdir = Path(workdir)
  74. workdir.mkdir(parents=True, exist_ok=True)
  75. _git(["git", "init", "-b", "main"], cwd=workdir)
  76. _git(["git", "config", "user.email", "drill@test.local"], cwd=workdir)
  77. _git(["git", "config", "user.name", "Drill Test"], cwd=workdir)
  78. (workdir / "package.json").write_text(PACKAGE_JSON)
  79. plans_dir = workdir / "docs" / "superpowers" / "plans"
  80. plans_dir.mkdir(parents=True, exist_ok=True)
  81. (plans_dir / "math-plan.md").write_text(PLAN_BODY)
  82. _git(["git", "add", "-A"], cwd=workdir)
  83. _git(["git", "commit", "-m", "initial: math YAGNI plan"], cwd=workdir)