Following PLAYBOOK.md, I wrote the tests before any implementation.
cd tests && npm test -- --run cli.test.tsTest Status:
- ✅ 19 existing tests passing
- ❌ 6 new macro execution tests failing (AS EXPECTED)
Expected: "6"
Received: "[object Object]"
Why it fails: Macro is not executed. The call addOne(5) returns the closure object instead of executing the macro function at bundle time.
Expected: "15"
Received: "[object Object]"
Why it fails: Same issue - macro not executed, so withAdd(10) returns a closure object.
Expected: "12"
Received: "[object Object]"
Why it fails: addTwo(5) should expand through multiple iterations, but macros aren't being executed at all.
Expected: exit code 1 with error message
Received: exit code 0 (no error)
Why it fails: No macro execution means no infinite loop detection.
Expected: "5) + 1" (expanded code)
Received: Full macro function definition in output
Why it fails: Macros are being bundled as regular functions instead of being executed and removed.
All fixtures are in tests/fixtures/macro/:
- simple_macro.ts - Basic
addOne(5)macro - macro_with_refs.ts - Macro that adds references to closure
- recursive_macro.ts - Macro calling another macro
- infinite_macro.ts - Infinite recursion test case
✅ Tests are comprehensive - They cover:
- Simple macro expansion
- Reference handling
- Recursive expansion
- Error cases (infinite loops)
- Tree-shaking (macros removed from output)
✅ Tests fail for the right reasons - Each failure clearly shows what's missing:
- Macros output
[object Object]→ not being executed - Macro functions in bundle → not being removed
- No error on infinite recursion → no iteration limit
✅ We know exactly what to implement - Make these 6 tests pass:
- Detect macros during graph construction
- Execute macros using deno_core
- Replace call sites with results
- Handle iterative expansion
- Add max_iterations guard
- Remove macro definitions from final bundle
Now that we have failing tests, we implement Step 3 following STEP3_MACRO_EXECUTION.md:
- Phase 1: Implement MacroRuntime with deno_core
- Phase 2: Integrate into SourceGraph
- Phase 3: Handle recursive expansion
- Phase 4: Commit when all tests pass
- Phase 1: 1-2 days
- Phase 2: 2-3 days
- Phase 3: 1 day
- Total: ~1 week
✅ Followed PLAYBOOK.md exactly:
- ✅ Wrote E2E tests FIRST in
tests/cli.test.ts - ✅ Created fixtures in
tests/fixtures/macro/ - ✅ Tests FAIL before implementation
- ⏳ Implement the feature (next phase)
- ⏳ Tests PASS after implementation (success criteria)
This is proper TDD! 🎯