AI coding tools have a well-known failure mode: they generate production code with no tests, the tests never get written, and your coverage ratchets steadily downward. TDD Mode closes this loophole at the infrastructure level. With TDD Mode enabled, Kode cannot write a production file until a corresponding test file is present — and when you runDocumentation Index
Fetch the complete documentation index at: https://docs.trykode.xyz/llms.txt
Use this file to discover all available pages before exploring further.
kode loop, the test suite must be executed and the results verified before production code is accepted.
How TDD Mode works
TDD Mode activates aTDDEnforcer that runs before any file write. It inspects every file in the proposed patch and classifies each one as either a test file or a production file.
Test file detection: A file is considered a test file if its name matches any of these patterns:
| Pattern | Language |
|---|---|
*_test.go | Go |
*.test.ts | TypeScript |
*.spec.ts | TypeScript |
*.test.tsx | TypeScript (React) |
*.spec.tsx | TypeScript (React) |
*.test.js | JavaScript |
*.spec.js | JavaScript |
*_test.py | Python |
Configuring TDD Mode
Enable TDD Mode in.kode/kode.json under the engine section:
test_command, Kode auto-detects the correct command by scanning your project for language markers:
| File found | Auto-detected command |
|---|---|
go.mod | go test ./... |
package.json | npm test |
Cargo.toml | cargo test |
pyproject.toml | pytest |
requirements.txt | python -m pytest |
node_modules, .git, and vendor directories.
What happens in a loop with TDD Mode on
When you runkode loop with TDD Mode enabled, Kode enforces a strict test-first sequence:
Kode generates a test file for the new functionality. Because no production file exists yet, the test file write is always allowed — TDD Mode only blocks production files, never test files.
Kode executes your test command. At this stage the tests should fail because the implementation doesn’t exist yet. A failing test result here is expected and correct — it means your tests are actually testing something. Kode records this as a healthy TDD signal.
With a test file in place and the tests confirmed failing, Kode generates the production implementation. The patch contains both the test file (already on disk) and the production file.
Example configuration
Here is a completekode.json for a Go project with TDD Mode enabled:
Related pages
- Guides: Loop mode — full walkthrough of the
kode loopworkflow with test integration and rollback behaviour