CMDCTest.EventCapture (cmdc_test v0.1.0)

Copy Markdown View Source

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 订阅自动清理。

Summary

Functions

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

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

Functions

start_capture(session)

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

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

参数

  • session — pid 或 session_id 字符串

返回 :ok{:error, :invalid_session}

stop_capture(session)

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

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