/skraft:test-design-mandatesfrom skraft
Enforces five test design mandates for Clean Architecture: layer boundary enforcement, business language abstraction, and test placement rules. Applied after Gherkin scenarios, before implementation.
Ships in skraft. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Five mandatory rules that govern how tests are designed in a Clean Architecture context. Applied after Gherkin scenarios are written, before any implementation starts.
Core principle: Tests enter through a use case boundary and assert at the next visible boundary. Never test internal classes directly.
Rule: Every AC names its use case boundary — the Application layer entry point the test enters through. All tests at the Application layer enter through that use case. Assertions are made via application interfaces (repositories, gateways) or the use case return value. Never instantiate an internal domain class directly in a test that is exercising Application behaviour.
Why: Prevents TBU (Tested But Unwired) defects — production code that works in isolation but is never called through the real composition root.
Application:
{UseCaseName} use case / command handlerTBU detection checklist (run after GREEN):
InMemory implementation, not the real one? → Correct for unit pass; add integration test for real wiringRule: Maintain 3 strictly separated layers of abstraction in test code. No technical vocabulary leaks upward.
| Layer | Location | Language | Example |
|---|---|---|---|
| Gherkin | .feature files | Pure business | Given a driver with a clean record |
| Step methods | Step definition classes | Bridge — calls use case | eligibilityUseCase.handle(command) |
| Business services / Use cases | Test helpers or application | Technical | new CheckEligibilityCommand(driverId, ...) |
Violations:
Given the EligibilityApplicationService is instantiatedvar command = EligibilityCommandBuilder.forDriverWith(cleanRecord);Implementation:
{Feature}Builder / {Feature}Mother test factories in step definition layerRule: Tests validate complete user journeys, not isolated operations. A scenario must include setup, action, and observable outcome — all three, always.
Structure:
Setup (Given) → state of the system before the action
Action (When) → ONE business trigger
Outcome (Then) → observable business result (not internal state)
Incomplete journey anti-patterns:
Given + When with no assertion → setup test, not a behaviour testThen asserting internal state (e.g., field value on domain object) → not observable by userJourney completeness check: Ask "could a user observe this outcome in the real system?" If yes, the Then is correctly observable.
Default rule: Acceptance tests do the work. No domain unit test by default, even when a pure function is extracted by refactoring. A regression that breaks 2+ AC together is the correct business signal — the duplicated red is the proof that the rule traverses multiple user journeys, not a redundancy to eliminate.
Anti-pattern this rule prevents — DOUBLE-COVERAGE: A pure function whose every behavioral branch is already reached by planned acceptance scenarios MUST NOT receive a dedicated domain test. Two suites asserting the same behavior drift together on every rule change and add zero failure-discrimination value.
A domain unit test is REQUIRED if and only if one of the two gates opens:
[Theory], @ParameterizedTest, table-driven).No gate opens → REJECT extraction. Record in the test plan: M4 negative — saturated by AC.
Process for each candidate pure function P:
B(P) — distinct behavioral branches of P.A(P) — branches reached by planned AC scenarios.A(P) == B(P) AND combinatorial size ≤ 10–15 → forbidden to extract, log M4 negative — saturated by AC.Extraction Reason code.Counter-example (STORY-41 contrefactual): Vehicle.MinimumAge() has B(P) = {21, 16}. Five planned AC reach both outputs, so A(P) == B(P). Combinatorial size = 3 cases, well under threshold. Both gates closed → no domain test. The 5 AC do all the work; if MinimumAge() breaks, all 5 turn red — that is the intended business signal.
Rule: Any AC expressed in visual, positional, or style terms (pixel position, full-page width,
background colour, relative alignment between two elements) is closed ONLY by a Playwright E2E test
performing a real measurement (boundingBox(), computed colour, computed layout) against a real
browser engine. A jsdom/unit test is NOT a valid closure for this AC type.
Why: jsdom has no layout engine (getBoundingClientRect() → zeros). Unit assertions proxy via
DOM order/class presence, not rendered proof. Without this mandate, a unit-TDD-only contributor
believes the AC is verified while CSS/mount/z-index regressions go uncaught.
Enforcement:
@visual (see bdd-methodology).Layer = E2E, Double Type = Real browser (Playwright).@visual w/o tests/e2e/ spec → coverage gap, block story (G9 check).Build this matrix for every story before implementation starts. Any row with Layer = Domain MUST carry an Extraction Reason code (see Mandate 4). Without a reason code, the row is not authorized — remove it.
Allowed Extraction Reason codes:
branch_unreachable_via_AC — Gate (a)combinatorial_economy — Gate (b)| Scenario | Use Case Boundary | Layer | Extraction Reason | Double Type | Walking Skeleton | Priority |
|---|---|---|---|---|---|---|
| Happy path — driver eligible | CheckEligibilityUseCase | Application | — | InMemory repository | A | P1 |
| Edge — driver at age limit | CheckEligibilityUseCase | Application | — | InMemory repository | A | P1 |
| Rejection — too many accidents | CheckEligibilityUseCase | Application | — | InMemory repository | A | P2 |
| Combinatorial sweep — premium grid | PricingPolicy.computePremium | Domain | combinatorial_economy | None (pure function) | — | P2 |
| Infrastructure — real persistence | IEligibilityRepository | Infrastructure | — | Real DB (Testcontainers) | — | P3 |
Priority:
A walking skeleton is the thinnest possible slice that exercises the full path from use case to output — enough to prove the wiring works.
| Strategy | When to use | Setup |
|---|---|---|
| A — Full InMemory | Feature is purely internal (no external services) | InMemory repository, no real I/O |
| B — Real local + Fake costly | Feature needs a local DB but avoids expensive external calls | Testcontainers DB + fake/stub for external service |
| C — Real local | Feature integrates with controllable local infrastructure | Testcontainers for all local dependencies |
| D — Configurable | Feature must run in both unit and integration mode | Strategy/feature flag selects double type at test startup |
Does the feature write to or read from persistent storage?
├── NO → Strategy A (full InMemory)
└── YES → Does it call an expensive external service (payment, SMS, AI)?
├── YES → Strategy B (real local DB + fake external)
└── NO → Is the storage local and controllable?
├── YES → Strategy C (real local with Testcontainers)
└── NO → Strategy D (configurable)
@smoke for fast validation| What to test | Test project | Layer | Double type |
|---|---|---|---|
| Use case / command handler | UnitTest | Application | InMemory application interfaces |
| Domain policy / specification | UnitTest | Domain | None (pure function — call directly) |
| Repository adapter | IntegrationTest | Infrastructure | Real DB via Testcontainers |
| API controller / endpoint | IntegrationTest | API | In-process app host (WebApplicationFactory or equivalent) |
| Architecture boundaries | IntegrationTest | Architecture | Static analysis (NetArchTest, ArchUnit, etc.) |
Visual/positional/style assertion (@visual) | E2E (Playwright) | Presentation (E2E) | Real browser engine — boundingBox(), getComputedStyle() |
Never:
UnitTestWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
clean-architecture, test-design, gherkin, bdd, test-boundaries
npx claudepluginhub sebastiendegodez/skraft-plugin --plugin skraft44 skills in this plugin
/acceptance-review-criteriaUse when reviewing DISTILL artefacts (Gherkin scenarios, test plans, implementation plans) for quality, completeness, and alignment. Contains the gate definitions and scoring rubric for the acceptance-designer-reviewer lenses./adr-eligibility-gateUse when deciding WHETHER a candidate architectural choice deserves an architecture decision record, before any record is drafted: a story enters DESIGN with a list of candidate choices, a reviewer flags ADR inflation, or someone asks "should I write an ADR for X?", "how many ADRs does this story need?", "is this ADR-worthy?", "this feels like too many ADRs", "disambiguate baseline from decision". Runs a baseline-vs-decision gate over each candidate and returns ELIGIBLE or NOT ELIGIBLE with the baseline, convention or architecture test that already covers it. Do NOT use when the decision is already settled and the user asks for the record to be written, when the request is about the ADR template, status transitions, superseding or lifecycle, or when the question is which pattern to adopt — those belong to architecture-decisions and architecture-patterns.
/adversarial-review-lensesUse when reviewing a phase artifact — a discovery brief, a plan, a design, an acceptance specification, or a slice reported as delivered — and the review has to end in a defensible pass-or-block verdict rather than a list of remarks. Covers judging whether the artifact covers everything that fed into it, whether it matches the business intent, whether it holds together internally, and what it puts at risk downstream, then weighing those into a single call. Not for routine code review of an ordinary change./architecture-decisionsUse when documenting architecture decisions as ADRs, evaluating trade-offs between alternatives, or managing the lifecycle of existing decisions. Covers ADR template, status transitions, consequence analysis, and quality criteria./architecture-patternsUse when selecting architecture patterns for a new feature, performing Event Modeling, defining bounded contexts, choosing DDD tactical patterns, evaluating pattern fitness, or understanding how patterns compose. Covers Event Modeling methodology, DDD strategic design, DDD tactical patterns, Clean Architecture, CQRS, and Event Sourcing./architecture-review-criteriaUse when reviewing DESIGN artefacts (event models, ADRs, component diagrams, context maps, interface contracts) for quality, DDD compliance, and architectural correctness. Contains gate definitions and scoring rubric for the solution-architect-reviewer lenses.Other plugins' skills for the same job