@windyroad/tdd 0.1.3 → 0.1.4-preview.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @windyroad/tdd
2
+
3
+ **TDD state machine enforcement for Claude Code.** Forces the Red-Green-Refactor cycle so your AI agent writes tests before implementation -- every time.
4
+
5
+ Part of [Windy Road Agent Plugins](../../README.md).
6
+
7
+ ## What It Does
8
+
9
+ AI agents love to jump straight to implementation. This plugin stops that. It enforces a strict TDD state machine:
10
+
11
+ ```
12
+ IDLE ──> RED ──> GREEN ──> RED (next test)
13
+
14
+ └──> Refactor (staying GREEN)
15
+ ```
16
+
17
+ - **IDLE** -- No test written yet. Implementation file edits are blocked.
18
+ - **RED** -- A failing test exists. Implementation edits are allowed.
19
+ - **GREEN** -- Tests pass. You can refactor or write a new failing test.
20
+ - **BLOCKED** -- Test runner error or timeout. Fix the setup before continuing.
21
+
22
+ The agent must write a failing test first. There are no shortcuts.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ npx @windyroad/tdd
28
+ ```
29
+
30
+ Restart Claude Code after installing.
31
+
32
+ ## Usage
33
+
34
+ The plugin activates automatically. On first use in a project without a test framework, it directs you to set one up:
35
+
36
+ ```
37
+ /wr-tdd:setup-tests
38
+ ```
39
+
40
+ This examines your codebase, recommends a test runner, configures `package.json`, and creates an example test.
41
+
42
+ Once active, the workflow is enforced on every edit:
43
+
44
+ 1. Write a test file (`*.test.ts`, `*.spec.ts`, etc.) that describes the desired behaviour
45
+ 2. The test must fail (RED state) -- proving the test is meaningful
46
+ 3. Write the minimum implementation to make it pass (GREEN state)
47
+ 4. Refactor while keeping tests green
48
+ 5. Repeat
49
+
50
+ Test files and config/doc files are always writable regardless of state.
51
+
52
+ ## How It Works
53
+
54
+ | Hook | Trigger | What it does |
55
+ |------|---------|-------------|
56
+ | `tdd-inject.sh` | Every prompt | Injects the current TDD state into the prompt |
57
+ | `tdd-enforce-edit.sh` | Edit or Write | Blocks implementation edits in IDLE or BLOCKED state |
58
+ | `tdd-post-write.sh` | After edit | Runs tests and transitions the state machine |
59
+ | `tdd-setup-marker.sh` | Skill completes | Marks test setup as done |
60
+ | `tdd-reset.sh` | Session end | Resets the TDD state |
61
+
62
+ ## Updating and Uninstalling
63
+
64
+ ```bash
65
+ npx @windyroad/tdd --update
66
+ npx @windyroad/tdd --uninstall
67
+ ```
68
+
69
+ ## Licence
70
+
71
+ [MIT](../../LICENSE)
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env bats
2
+
3
+ # Tests for tdd-gate.sh shared library functions
4
+
5
+ setup() {
6
+ SCRIPT_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
7
+ source "$SCRIPT_DIR/lib/tdd-gate.sh"
8
+ TEST_SESSION="test-$$-$BATS_TEST_NUMBER"
9
+ }
10
+
11
+ teardown() {
12
+ tdd_cleanup "$TEST_SESSION" 2>/dev/null || true
13
+ rm -f "/tmp/tdd-setup-active-${TEST_SESSION}"
14
+ }
15
+
16
+ # --- tdd_classify_file ---
17
+
18
+ @test "classify_file: .test.ts is test" {
19
+ result=$(tdd_classify_file "src/utils.test.ts")
20
+ [ "$result" = "test" ]
21
+ }
22
+
23
+ @test "classify_file: .spec.jsx is test" {
24
+ result=$(tdd_classify_file "src/App.spec.jsx")
25
+ [ "$result" = "test" ]
26
+ }
27
+
28
+ @test "classify_file: __tests__ directory is test" {
29
+ result=$(tdd_classify_file "src/__tests__/utils.ts")
30
+ [ "$result" = "test" ]
31
+ }
32
+
33
+ @test "classify_file: .config.ts is exempt" {
34
+ result=$(tdd_classify_file "vitest.config.ts")
35
+ [ "$result" = "exempt" ]
36
+ }
37
+
38
+ @test "classify_file: .setup.ts is exempt" {
39
+ result=$(tdd_classify_file "vitest.setup.ts")
40
+ [ "$result" = "exempt" ]
41
+ }
42
+
43
+ @test "classify_file: .json is exempt" {
44
+ result=$(tdd_classify_file "package.json")
45
+ [ "$result" = "exempt" ]
46
+ }
47
+
48
+ @test "classify_file: .css is exempt" {
49
+ result=$(tdd_classify_file "src/styles.css")
50
+ [ "$result" = "exempt" ]
51
+ }
52
+
53
+ @test "classify_file: .md is exempt" {
54
+ result=$(tdd_classify_file "README.md")
55
+ [ "$result" = "exempt" ]
56
+ }
57
+
58
+ @test "classify_file: .sh is exempt" {
59
+ result=$(tdd_classify_file "scripts/build.sh")
60
+ [ "$result" = "exempt" ]
61
+ }
62
+
63
+ @test "classify_file: .ts is impl" {
64
+ result=$(tdd_classify_file "src/utils.ts")
65
+ [ "$result" = "impl" ]
66
+ }
67
+
68
+ @test "classify_file: .tsx is impl" {
69
+ result=$(tdd_classify_file "src/App.tsx")
70
+ [ "$result" = "impl" ]
71
+ }
72
+
73
+ @test "classify_file: .js is impl" {
74
+ result=$(tdd_classify_file "src/index.js")
75
+ [ "$result" = "impl" ]
76
+ }
77
+
78
+ @test "classify_file: unknown extension is exempt" {
79
+ result=$(tdd_classify_file "Dockerfile")
80
+ [ "$result" = "exempt" ]
81
+ }
82
+
83
+ # --- tdd_has_test_script ---
84
+
85
+ @test "has_test_script: returns false when no package.json" {
86
+ cd "$(mktemp -d)"
87
+ run tdd_has_test_script
88
+ [ "$status" -ne 0 ]
89
+ }
90
+
91
+ @test "has_test_script: returns false for default npm test script" {
92
+ local tmpdir=$(mktemp -d)
93
+ echo '{"scripts":{"test":"echo \"Error: no test specified\" && exit 1"}}' > "$tmpdir/package.json"
94
+ cd "$tmpdir"
95
+ run tdd_has_test_script
96
+ [ "$status" -ne 0 ]
97
+ rm -rf "$tmpdir"
98
+ }
99
+
100
+ @test "has_test_script: returns true for real test script" {
101
+ local tmpdir=$(mktemp -d)
102
+ echo '{"scripts":{"test":"vitest"}}' > "$tmpdir/package.json"
103
+ cd "$tmpdir"
104
+ run tdd_has_test_script
105
+ [ "$status" -eq 0 ]
106
+ rm -rf "$tmpdir"
107
+ }
108
+
109
+ # --- tdd state ---
110
+
111
+ @test "read_state: returns IDLE when no state file" {
112
+ result=$(tdd_read_state "$TEST_SESSION")
113
+ [ "$result" = "IDLE" ]
114
+ }
115
+
116
+ @test "write_state and read_state roundtrip" {
117
+ tdd_write_state "$TEST_SESSION" "RED"
118
+ result=$(tdd_read_state "$TEST_SESSION")
119
+ [ "$result" = "RED" ]
120
+ }
121
+
122
+ @test "cleanup removes state files" {
123
+ tdd_write_state "$TEST_SESSION" "GREEN"
124
+ tdd_cleanup "$TEST_SESSION"
125
+ result=$(tdd_read_state "$TEST_SESSION")
126
+ [ "$result" = "IDLE" ]
127
+ }
128
+
129
+ @test "cleanup removes setup marker" {
130
+ touch "/tmp/tdd-setup-active-${TEST_SESSION}"
131
+ tdd_cleanup "$TEST_SESSION"
132
+ [ ! -f "/tmp/tdd-setup-active-${TEST_SESSION}" ]
133
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windyroad/tdd",
3
- "version": "0.1.3",
3
+ "version": "0.1.4-preview.26",
4
4
  "description": "TDD state machine enforcement (Red-Green-Refactor cycle)",
5
5
  "bin": {
6
6
  "windyroad-tdd": "./bin/install.mjs"
@@ -1,5 +1,5 @@
1
1
  ---
2
- name: setup-tests
2
+ name: wr-tdd:setup-tests
3
3
  description: Set up a test framework for the project. Examines the codebase, recommends a test runner, configures package.json, and creates an example test.
4
4
  allowed-tools: Read, Write, Edit, Bash, Glob, Grep, AskUserQuestion
5
5
  ---