/mermaid-event-model:add-tests [slice] [test intent...]from mermaid-event-model
Authors Given/When/Then test specifications for a vertical slice and appends them to the slice's spec file. Grounds every element and field against the slice's Model section and refuses to invent data.
Ships in mermaid-event-model. 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.
None: SKILL.md is the whole skill.
You are authoring one or more sliceTests test declarations for a single
vertical slice and appending them to the ## Tests section of that slice's
spec file (<model>-slices/<slug>.md). Tests are driven by a natural-language
statement of intent — "books a room for a registered guest", "rejects a
duplicate room number", "reports total revenue across two payments" — from
which you infer the flow type, the participating elements, and the subset of
fields the test actually exercises. Every element name, label, and field must
be grounded in the slice's ## Model snippet; you never invent data.
$ARGUMENTS may carry, in any order and any partially:
Both are optional. Resolve what's missing interactively (below). The user may
also ask for several tests at once; treat each distinct behavior as its own
test[...] declaration.
Tests live in the ## Tests section of a slice spec file produced by
spec-slices. This skill does not create spec files or parse the raw
eventModel DSL directly — it operates on the already-stamped spec, whose
## Model section is the ground-truth element inventory for the slice.
Locate the model. Resolve the DSL file the same way the sibling skills
do: an explicit path in $ARGUMENTS, else the most recently referenced DSL
file in the conversation, else blueprint_dsl.md in the project root. Its
spec directory is the sibling <model>-slices/.
If the spec directory or the target slice's spec file does not exist,
stop and tell the user to run spec-slices first (offer to run it for
them). Do not fabricate a spec file — spec-slices owns the Model and
Description sections and must stamp them from the live model.
The target slice can be given explicitly or inferred from the test itself — you rarely need to name it.
Explicit selector. If a slice selector was given, resolve it to a spec
file: slugify the provided id/title (lowercase, runs of non-alphanumerics →
single -, trim) and match it against the filenames in <model>-slices/,
or match the <!-- slice id: <id> --> comment inside each file. If it's
ambiguous or has no match, list the available slices and ask.
Infer from the test's action element. If no selector was given, don't ask
yet — the test's own Given/When/Then usually names its slice. Build a
cross-slice index by reading the ## Model section of every spec file in
<model>-slices/ and recording, per slice, the labels of its elements by
kind. Then key off the action element the intent describes:
then. A
view-only read model belongs to one view slice.Match that action element's label (fuzzily against the intent's wording)
against the index. Do not match on Given/Then domainEvents alone — a
domain event is a boundary node that is the output of one slice and the input
of another, so it appears in multiple slices and can't disambiguate on its
own. Use the events only to corroborate a command/read-model match.
event-model / add-slices if the behavior isn't modeled yet.Fall back to asking. Only when inference is ambiguous or empty (or the intent itself is still unknown) list every spec file (title + id) and ask.
Read the chosen spec file and parse the eventModel snippet inside its
## Model fence. Build the slice's element inventory — for each element:
ui, command, domainEvent, externalEvent, readModel, or
automation.["..."] text (this is what a sliceTests item carries).:).{ name: type ... } data section, verbatim.This inventory is the source of truth for element labels and field names in the generated tests.
Include the command's reads [...] events as valid given preconditions.
A command reads [...] clause is a DCB consistency directive — never a flow
edge, so it does not add nodes to the slice diagram or draw arrows (see the
add-slices and spec-slices skills, which correctly ignore it for layout).
But the events a command reads are precisely its consistency boundary: the
prior history it examines to accept or reject. That makes each reads event a
legitimate given for this slice's tests. The event's declaration (label +
fields) usually lives in the parent model rather than the slice's Model
snippet — the snippet shows the ids in the reads [...] tag but not the full
event bodies — so resolve any reads-only event by looking it up in the parent
DSL file (<model>.md) by id, and use that declaration to ground it. An event
that is reachable by a slice edge (e.g. the slice's own output event) is
groundable directly from the snippet as before; reads only adds to the
given-inventory, it never removes anything.
Each maps to a canonical sliceTests shape (see blueprint_sliceTests.md).
The item kinds and labels come from the slice's Model; only the
given/when/then arrangement is fixed by the flow type.
| Flow type | given | when | then |
|---|---|---|---|
| State change | prior domainEvent(s) that set up the scenario | the command under test | emitted domainEvent(s) |
| Rejection | prior domainEvent(s) | the command under test | error["<message>"] |
| State view | the domainEvent(s) that feed the view | (omitted) | the readModel projection |
| External input | prior externalEvent/domainEvent(s) | the translating command | emitted domainEvent(s) |
| External output | the readModel holding what to emit | the command under test | emitted domainEvent(s) |
If you inferred the slice from the test's action element (above), you already have a flow type in hand — carry it forward and just confirm it. Otherwise propose a default from the slice's model shape and the intent's wording:
command → domainEvent edge and the intent describes a success
→ State change.domainEvent(s) → readModel with no command (a View slice) → State view.externalEvent/event into domain events via a command →
External input.readModel via a command (outbound
translation) → External output.State the inferred type and why. If the user passed an explicit flow type in
$ARGUMENTS, honor it without asking. Otherwise offer the inference as the
default and let them override — and note that a slice can legitimately warrant
several tests of different types (e.g., a state-change and its rejection).
This is the core discipline of the skill, mirroring
validate-completeness's field-traceability rule.
Read the intent and identify every attribute it references — anything the test claims to set up, act on, or assert (e.g., "verify the booking timestamp", "for a registered guest", "when the room number is already taken").
For each referenced attribute:
event-model skill, then
re-run spec-slices). Do not silently add the field and do not guess a
plausible name.Do the same for element labels: every given/when/then item must
correspond to a real element in the slice. If the intent implies an event,
command, or read model the slice doesn't contain, that's a gap — raise it.
Most tests verify only a subsection of an element's data, so do not copy whole data sections by default. Instead:
roomType or capacity.A field earns its place only if it correlates or is asserted. Apply this to
every field, and especially to identifier fields — do not reflexively include
the *Id: UUID keys. A field belongs in the test when either:
given / when / then, so it ties the
scenario together; orA field that would appear in exactly one section earns no place. It is either noise, or — worse — an assertion about a value the implementation generates, which forces deterministic or mocked id generation just to make the test pass.
Two worked cases from this repo:
book_room, roomId correlates: it appears in the given Room Added, in
the Book Room command, and in the emitted Room Booked. Include it.register, guestId does not. The command carries only name,
email, password, so the handler mints guestId on the emitted
Registered; pinning it to a value tests id generation, not registration.
The field that actually correlates the duplicate-registration scenario is
email. Omit guestId.So the question to ask is which field ties the given to the when — that is the
correlating key, and it is not always the *Id: UUID. Natural keys (an
email, a room number) correlate scenarios at least as often as surrogate ones.
Escape hatch for generated values. When a test genuinely needs to assert
that an element carries a field whose value the implementation mints, include
it type-only (bookingId: UUID, no =). That asserts presence without
pinning a value — see step 3a. Reach for this only when presence is the point;
otherwise omit the field.
Copy each included field's declared type from the model verbatim
(bookedAt: timestamp, not a guessed type).
Data-section fields support a sliceTests-only extension: field: type = value,
which renders value-forward (field = value) and doubles as a code-generation
fixture. Author an example value for every field you include — this is what
makes a test demonstrate its case rather than merely restate the schema.
checkIn/checkOut must literally overlap the command's requested
dates; for the "allowed because previously checked out" variant, the
checkedOutAt must fall before the requested check-in. If the numbers don't
make the outcome true, the test is lying.roomId = "room-101" in the given event,
the command, and the emitted event; tie a Checked Out back to its booking by
repeating the bookingId."room-101"), write
dates/timestamps as ISO literals (2026-08-12, 2026-08-11T09:30:00Z),
numbers and booleans bare (4, true)."bk-001", not a 36-char hex) —
they read better in the card and still map cleanly to generated fixtures.field: type.For a Rejection test, the error["<message>"] string is read verbatim by
downstream code generation — each error[...] maps to throwing the target
framework's domain exception with the exact string. So:
## Description already states as the rejection
reason; otherwise derive a precise message from the intent.Emit each test as a test["<Title>"] declaration in sliceTests DSL,
tab-indented to match the fence body in the spec file (test at one tab,
section keywords given/when/then at two tabs, items at three, fields at
four with a closing } at three). Give each test a short, behavior-describing
title derived from the intent. Omit the when section for State-view tests.
Include a data section on an item only when step 3 selected fields for it.
## Tests, preserving everything else## Tests heading and its ```mermaid fence containing
sliceTests. Its content runs from the heading to the next ## heading or
end-of-file.test["Describe what this test verifies"] with its comment lines and
no real items), replace that skeleton with the new test(s).test[...] block(s) after the last existing
test, inside the same fence, separated by one blank line. Never modify,
reorder, or delete existing tests.## Tests section at all (an older stamp), add one with a
sliceTests fence containing the new tests.## Model and ## Description sections — and any other sections —
byte-for-byte unchanged. Write the file back.Tell the user: the slice and spec file, the flow type used (and whether it was inferred or chosen), each test added with its title, and — if any — the traceability gaps you raised and how they were resolved. If gaps were left unresolved, say plainly that no tests were written for those.
Spec file blueprint_dsl_dcb-slices/book-room.md, whose Model declares a
command bookRoom["Book Room"] { guestId: UUID, roomId: UUID, checkIn: date, checkOut: date }, given events Registered { guestId: UUID, name, email } and
Room Added { roomId: UUID, roomNumber, roomType }, and an emitted
Room Booked { bookingId: UUID, guestId: UUID, roomId: UUID, bookedAt: timestamp }.
Intent: "books a room for a registered guest and stamps the booking time."
command → domainEvent, success wording).guestId (on Registered and the
command); "booking time" → bookedAt on Room Booked — both present in the
model. ✓ No gaps.guestId and roomId — each correlates, appearing in a
given, the command, and the outcome — plus bookedAt because the intent
explicitly asserts it. Omit name, email, roomNumber, roomType,
checkIn, checkOut — the test doesn't speak to them. Also omit
bookingId: it would appear in then alone, and the handler mints it, so
pinning bookingId = "bk-001" would assert generated data. (If a test did
need to claim the event carries one, it would write bookingId: UUID
type-only.) Note that in the sibling test — "allows booking when the
overlapping booking was already checked out" — bookingId does earn its
place, because it ties the given Room Booked to the given Checked Out.guestId = "g-001" and roomId = "room-101" across the
given, command, and outcome so the scenario traces as one; give bookedAt a
concrete timestamp.Appended:
test["Books a room for a registered guest and stamps the booking time"]
given
domainEvent["Registered"] {
guestId: UUID = "g-001"
}
domainEvent["Room Added"] {
roomId: UUID = "room-101"
}
when
command["Book Room"] {
guestId: UUID = "g-001"
roomId: UUID = "room-101"
}
then
domainEvent["Room Booked"] {
guestId: UUID = "g-001"
roomId: UUID = "room-101"
bookedAt: timestamp = 2026-08-12T14:00:00Z
}
Counter-example — a gap that must be raised: intent "rejects the booking when
the guest's loyaltyTier is expired." No element in the book_room slice
carries loyaltyTier. Stop and report: loyaltyTier is not present on any
given event, the command, or any outcome in this slice (the command carries
guestId, roomId, checkIn, checkOut). Ask whether to correct the intent,
drop the assertion, or extend the model first. Write nothing until resolved.
## Tests section of the chosen spec file.sliceTests grammar (item kinds, error[...], data sections) is defined
in slice-tests.js and documented in the README's "Slice Tests" section —
keep generated output within it.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (howarddierking/mermaid-event-model) — no native marketplace selected
npx claudepluginhub p/howarddierking-mermaid-event-model6 skills in this plugin
/add-slicesAnalyze an Event Model DSL file and (re)write its `slice` declarations from scratch based on the edges currently in the file. Strips any existing slices first so re-running cleanly replaces stale slices instead of accumulating them. Every slice is classified against the four canonical Event Modeling patterns — Command, View, Automation, and Translation — with `externalEvent` as the sole discriminator between Automation and Translation, since the two are structurally identical. Slices that match no canonical shape are flagged rather than forced into a bucket, and the run also reports model defects the classification exposes: read sides that mix two systems, and orphan events that should have been declared external. The pattern is reported, never written into the DSL./create-event-modelSeed a project with a working Event Model. Writes (1) a markdown file containing the canonical hotel-booking DSL inside a `mermaid` fenced block, and (2) a `model-viewer.html` page that renders that markdown plus any sibling `<model>-slices/` directory created later by the `spec-slices` skill. Useful for bootstrapping a new model or resetting to the reference example. The model defaults to `blueprint_dsl.md`; the viewer is always written as a sibling named `model-viewer.html`.Other plugins' skills for the same job