Test helpers for verifying strategy contract compliance.
Validates that a strategy module correctly implements all callbacks
defined in Cyclium.EpisodeRunner.Strategy and that the episode loop
terminates within budget.
Usage
defmodule MyApp.Strategies.ClientHealthTest do
use ExUnit.Case, async: true
use Cyclium.Test.StrategyCase
@episode build_test_episode(actor_id: "test_actor", expectation_id: "health_check")
@trigger %Cyclium.Trigger.Manual{source: "test"}
test "init returns valid state" do
assert_valid_init(MyStrategy, @episode, @trigger)
end
test "strategy terminates" do
assert_strategy_terminates(MyStrategy, @episode, @trigger,
max_steps: 20,
handle_step: fn action, state -> default_step_handler(action, state) end
)
end
end
Summary
Functions
Simulate a strategy through the episode loop and assert it terminates
within max_steps. Uses handle_step callback to produce mock results
for each step action.
Assert that strategy.converge/2 returns valid output.
Assert that strategy.handle_result/3 returns a valid response.
Assert that strategy.init/2 returns {:ok, map()}.
Assert that strategy.next_step/2 returns a valid action shape.
Build a minimal episode context map matching what EpisodeRunner passes.
Build a minimal test episode struct for strategy testing.
Build a minimal step struct for handle_result testing.
Default step handler that returns generic mock results for each action type. Override in tests for strategy-specific behavior.
Functions
Simulate a strategy through the episode loop and assert it terminates
within max_steps. Uses handle_step callback to produce mock results
for each step action.
Options
:max_steps— maximum loop iterations before failing (default: 50):handle_step—(action, state) -> {:result, term()} | :skipcallback to produce mock step results. Defaults todefault_step_handler/2.
Assert that strategy.converge/2 returns valid output.
Assert that strategy.handle_result/3 returns a valid response.
Assert that strategy.init/2 returns {:ok, map()}.
Assert that strategy.next_step/2 returns a valid action shape.
Build a minimal episode context map matching what EpisodeRunner passes.
Build a minimal test episode struct for strategy testing.
Build a minimal step struct for handle_result testing.
Default step handler that returns generic mock results for each action type. Override in tests for strategy-specific behavior.