stacks-tdd

Guides red-green-refactor test-driven development in Stacks projects using bun test.

625|19|Updated Apr 26, 2022
One-click install
npx skills add https://github.com/stacksjs/stacks --skill stacks-tdd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: stacks-tdd
Source: https://github.com/stacksjs/stacks/tree/main/storage/framework/defaults/ai/skills/stacks-tdd
Command: npx skills add https://github.com/stacksjs/stacks --skill stacks-tdd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing tests that survive refactors and actually verify behavior is hard. This Skill enforces the discipline of test-driven development in a Stacks project: choosing the right seam to test at, avoiding anti-patterns like tautological assertions and implementation-coupled mocks, and running the red-green loop correctly with bun test and @stacksjs/testing.

Core Features & Use Cases

  • Seam Selection: Defines four test seams (route, action, model, function) and requires agreeing on seams with the user before any test is written.
  • Anti-Pattern Detection: Identifies implementation-coupled tests, tautological assertions, horizontal slicing, and state leaking between test files, with side-by-side good and bad examples in EXAMPLES.md.
  • Loop Rules: Enforces red-before-green, one vertical slice per cycle, narrow test runs during iteration, and typechecking alongside development.
  • Use Case: When adding a checkout feature to a Stacks app, use this Skill to write a failing test at the action seam first, run bun test on the narrow path, implement the minimal code to go green, then hand off to code review.

Quick Start

Ask the AI to build a new feature test-first in your Stacks project using the red-green-refactor loop with bun test.

Frequently Asked Questions about stacks-tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I do test-driven development in a Stacks project?

Write a failing test at an agreed seam first, then implement only enough code to pass it. Run the narrow test file with bun test during the loop, typecheck with ./buddy typecheck, and work in vertical slices of one test and one implementation per cycle.

What is a test seam and where should tests go?

A seam is the public boundary where you observe behavior without reaching inside. Stacks defines four seams from highest to lowest: route, action, model, and function. Prefer the highest seam that can go red on the behavior you care about.

Should I mock the database in Stacks tests?

No. Use setupDatabase() to create the test SQLite database and refreshDatabase() to re-migrate it between tests. Mocking User.find() only tests the mock. Reserve stand-ins for third-party HTTP, time, randomness, and queue dispatch assertions.

How do I test that a queue job was dispatched?

Use fake() from @stacksjs/queue, perform the action, then call queue.assertDispatched('JobName'). Always call restore() in the same test or in afterEach, because fake() mutates global state and leaks into other tests otherwise.

What are tautological tests and why avoid them?

A tautological test recomputes the expected value the same way the implementation does, so it passes by construction and can never catch a bug. Expected values must come from an independent source such as a known-good literal or a worked example.

When should I run the full test suite instead of one file?

Run the narrow file with bun test during the red-green loop for fast feedback. Run the full buddy test suite once at the end as a gate, and run /stacks-review after the slice is green.