event-sourcing-tests
БесплатноБез исполняемых скриптовНе проверенUse when an event-sourced aggregate gains or changes an event type, snapshots are added, or a CQRS read model is projected from events. Tests…
от testland★ 18 звёзд на GitHubОб этом скилле
event-sourcing-tests
Tests for an event-sourced system verify replay determinism, snapshot equivalence, and version-evolution correctness - without them, the event log silently drifts from the rebuilt state.
When to use
- Domain model is event-sourced (orders, accounts, inventory).
- Audit / compliance requirements demand event log as system of record.
- Adding a new event type or changing payload schema - retro-compat tests are mandatory.
How to use
- Write the aggregate's given-events / when-command / then-events test first (see Worked example) - it is the base every other check builds on.
- Add a replay-determinism assertion: replay the same log twice and assert
identical state; this catches
time.now()/ random-ID leaks at the source. - When snapshots are introduced, assert snapshot-at-N equals replay-to-N - see references/snapshot-versioning-projections.md.
- When an event type or payload schema changes, add versioned upcasters and a mixed-version replay test - see the references (versioning + upcasting).
- For read models, add the projection tests below - determinism, idempotent + out-of-order apply, rebuild + swap - and assert the documented convergence window per references/convergence-windows.md.
- Gate appends on optimistic concurrency (expected version) and suppress external calls in replay mode - see the references (concurrency, replay mode).
Worked example - one event-sourced aggregate, end to end
The base test for any event-sourced aggregate is given-events / when-command / then-events: seed the aggregate with its prior events, handle one command, then assert the events it emits and the resulting state. Per [Fowler - Event Sourcing], replay = "rebuild application state from scratch by replaying events in order."
def test_confirm_order_emits_order_confirmed():
# GIVEN - the aggregate's prior event history
history = [
OrderCreated(order_id="o1", customer="c1"),
ItemAdded(order_id="o1", sku="sku1", qty=2),
]
order = OrderAggregate.replay(history)
# WHEN - one command is handled
new_events = order.handle(ConfirmOrder(order_id="o1"))
# THEN - assert the emitted events, not only the final state
assert new_events == [OrderConfirmed(order_id="o1")]
# AND replay is deterministic: the same log rebuilds the same state
state_a = OrderAggregate.replay(history + new_events)
state_b = OrderAggregate.replay(history + new_events)
assert state_a == state_b
assert state_a.status == "confirmed"
assert state_a.line_items == [("sku1", 2)]
If handle emits events derived from time.now() or random IDs,
state_a == state_b fails - the test catches non-deterministic replay
before it drifts the log from the rebuilt state.
Once this base test is green, layer on the operational checks - order independence within causality, snapshot equivalence, event versioning + upcasting, projection rebuild, retroactive correction, replay-mode side-effect suppression, and optimistic-concurrency appends - in references/snapshot-versioning-projections.md.
Projection rebuild (CQRS read models)
Per [Fowler - CQRS], the read model is rebuilt from the write model's event stream; test it like the aggregate - deterministic, idempotent, rebuildable:
- Determinism -
apply_all(events)twice yields the same materialized state; current-time / random-ID reads inapplybreak it. - Per-event delta - each event type produces one well-defined change
(parameterize:
ProductPriceChanged→{"sku1.price": 120}, etc.). - Idempotent apply - the same event applied twice leaves state unchanged (track applied event IDs per projection).
- Out-of-order delivery - the projection buffers or versions when
Updatedarrives beforeCreated; if it assumes in-order (Kafka per-partition), test that assumption end-to-end. - Rebuild + zero-downtime swap - rebuild from a known event range
and compare to a fixture; at the swap point assert
new_proj.materialize() == old_proj.materialize()before switching reads. Full swap mechanic + the read-your-writes guard (202 Accepted → pending → active) are in references/rebuild-swap-and-read-your-writes.md. - Convergence window - async projections lag; document the window ("read model converges within 5s of write") and assert it with the deadline + poll + assert pattern in references/convergence-windows.md, which also covers monotonic-read and bounded-staleness assertions.
Test each projection off one stream independently (search index, materialized SQL view, OLAP cube) so a flawed one doesn't mask the others.
Anti-patterns
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| R |
Установить event-sourcing-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл event-sourcing-tests?
Use when an event-sourced aggregate gains or changes an event type, snapshots are added, or a CQRS read model is projected from events. Tests given-events/when-command/then-events, replay determinism, upcasting, snapshot equivalence, projections and eventual-consistency windows.
Как установить скилл event-sourcing-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл event-sourcing-tests запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic