# `CMDCTest.EventCapture`
[🔗](https://github.com/tupleyun/cmdc_test/blob/v0.1.0/lib/cmdc_test/event_capture.ex#L1)

EventBus 订阅 helper — 让调用方进程接收指定 session 的所有 `{:cmdc_event, sid, ...}` 消息。

与 `CMDCTest.Assertions` 配合使用：

    use ExUnit.Case
    import CMDCTest.Assertions

    test "..." do
      {:ok, session} = CMDC.create_agent(...)
      :ok = CMDCTest.EventCapture.start_capture(session)

      CMDC.prompt(session, "go")

      assert_event_emitted(session, :agent_end)
    end

无需手动 `stop_capture`：测试进程退出时 EventBus 订阅自动清理。

# `start_capture`

```elixir
@spec start_capture(CMDC.session()) :: :ok | {:error, term()}
```

在当前进程订阅指定 session 的所有事件。

## 参数

- `session` — pid 或 session_id 字符串

返回 `:ok` 或 `{:error, :invalid_session}`。

# `stop_capture`

```elixir
@spec stop_capture(CMDC.session()) :: :ok | {:error, term()}
```

在当前进程取消订阅指定 session 的所有事件。

---

*Consult [api-reference.md](api-reference.md) for complete listing*
