Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

cqrs-testing

БесплатноБез исполняемых скриптовНе проверен

Asserts a python-cqrs handler through cqrs.testing.test_harness. Use when a test must check a command, a query, a domain event, a notification, an outbox, an…

vadikko2от vadikko2258 установок в других каталогах

Об этом скилле

Testing python-cqrs

Read the feature skill before writing the handler. This file only says which journal to assert.

Import from cqrs.testing import test_harness. It is not in cqrs.__all__. The package is already installed. Do not add an install step. Do not copy examples/testing/ into the application.

async with test_harness(...) as harness builds the mediators. Arguments match bootstrap. The builder passes compensation_retry_delay=0 unless the test passes a delay. async with test_harness.around(...) as harness wraps mediators the application already built and does not change that delay. around puts resolve, the broker, saga storage, and the listener back in finally.

If the application mediator has a real broker and no broker= argument is passed, around forwards each message to that real broker and records it. To keep a unit test isolated, pass a CapturingMessageBroker with no inner broker: async with test_harness.around(mediator, broker=CapturingMessageBroker()) as harness. The real broker's send_message is then redirected to the capture, so no message leaves the process.

test_harness(...) creates a memory outbox and a memory inbox on harness.outbox_repository and harness.inbox_repository. It does not bind them. The test binds the port.

For ScopeStrategy.SEND, pass di.Container. Do not pass TestContainer. TestContainer is register(type, instance) and async resolve.

Do not read DevnullMessageBroker.MESSAGE_BUS. If the mediator holds that broker, the harness replaces it with CapturingMessageBroker for the block and restores it afterwards.

An invocation record has handler, method (handle, act, or compensate), argument, argument_type, and handler_instance.

contains is a boolean and does not raise. assert_contains, assert_one, and assert_empty raise AssertionError with the recorded rows. Those methods are not on every journal:

  • requests, handled, unhandled, and published have contains.
  • handled and unhandled have assert_empty. They do not have assert_contains or assert_one.
  • published has contains, assert_contains, assert_one, and assert_empty.
  • outbox has assert_empty. It does not have contains, assert_contains, or assert_one.
  • invocations has assert_entered and assert_not_entered. It does not have contains, assert_contains, assert_one, or assert_empty.
  • requests does not have assert_contains, assert_one, or assert_empty.

There is no pytest plugin.

Short shape for a command, a domain event, and a notification: assets/test_order.py.

Command

Assert requests and invocations. send returns the same result requests stored. published stays empty unless the command also emits a notification.

Query

Assert requests. handled, published, and outbox stay empty.

view = await harness.mediator.send(ReadOrder(order_id="1"))
harness.handled.assert_empty()
harness.published.assert_empty()
harness.outbox.assert_empty()

Domain event

Assert handled and invocations. A follow-up event is also on handled and enters the next handler. published stays empty.

Notification

Assert published (topic, message_name, payload, message_id). The notice is not on handled.

published.contains(OrderCreated) is false for a domain event. published.assert_contains names handled or invocations in the error when the event was recorded there and was not sent to the broker.

Parallel domain handlers

concurrent_event_handle_enable=True with ScopeStrategy.HANDLER or NONE. Both classes are on invocations. Do not assert order.

Swallowed domain-handler error

send returns the command result. The error is on handler_errors. requests still holds that result.

result = await harness.mediator.send(CreateOrder(sku="book"))
assert harness.handler_errors.of(OrderCreated, AuditHandler)

Event with no handler

The type is on unhandled. send does not raise. The missing handler is not on invocations.

EventMediator

await harness.event_mediator.send(event) enters handle on invocations. EventMediator goes through EventDispatcher, not EventEmitter, so this path is not handled. A follow-up also goes to the dispatcher.

Request fallback

Primary raises. Both classes are on invocations. The response on requests is the fallback's.

Event fallback

Same for an event from a command and for EventMediator. Both classes are on invocations.

Circuit breaker

Use a fake ICircuitBreaker. Do not install aiobreaker. An open breaker leaves the primary off invocations and enters the fallback.

Middleware

middlewares records the type, the request, and whether handle was called. If middleware does not call handle, invocations does not contain the handler, called_next is false, and requests holds the middleware's response.

harne
Полный SKILL.md на ClawHub

Установить cqrs-testing в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл cqrs-testing?

Asserts a python-cqrs handler through cqrs.testing.test_harness. Use when a test must check a command, a query, a domain event, a notification, an outbox, an inbox, a saga, a chain, a stream, a fallback, or middleware.

Как установить скилл cqrs-testing?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл cqrs-testing запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить cqrs-testing с