In-memory Scriba.Target for property tests and user-facing test helpers.
Backed by an Agent that holds the commit log, per-stream cursors, and
the in-memory dead-letter list. Records every committed event as
{event_id, stream_id, position} in the order it was applied. Events
whose handler returned :skip are not recorded.
Dead-letter routing: the Pipeline hands the Target a
list of {event, error} tuples for events whose handler returned
{:error, _} or raised. The Test target records them in its in-memory
:dead_letters list, letting property
tests assert dead-letter routing without a Repo.
Usage
{:ok, agent} = Scriba.Target.Test.start_link()
# Wired into a projection's :target spec as
# {Scriba.Target.Test, agent: agent}
Scriba.Target.Test.commits(agent)
# => [{"evt-1", "stream-0", 1}, {"evt-2", "stream-1", 2}, ...]
Scriba.Target.Test.dead_letters(agent)
# => [%{event: %Scriba.Event{...}, error: {:error, :boom}}, ...]
Scriba.Target.Test.stream_positions(agent)
# => %{"stream-0" => 4, "stream-1" => 5}
Scriba.Target.Test.safe_position(agent)
# => 4 (= min across all stream cursors)
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns the recorded {event_id, stream_id, position} tuples in the order
they were committed.
Returns dead-letter entries in the order they were routed. Each entry is
a %{event: %Scriba.Event{}, error: term()} map — the same error
shape the Pipeline passed (an {:error, reason} tuple, or the engine-
internal {:exception, exception, stacktrace} triple).
Clears the commit log, dead-letter list, and per-stream cursors.
Returns the safe replay point: the minimum cursor across all streams. 0 when no streams have committed yet.
Starts an in-memory commit log.
Returns the per-stream cursor map.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec commits(agent()) :: [{String.t(), String.t(), non_neg_integer()}]
Returns the recorded {event_id, stream_id, position} tuples in the order
they were committed.
@spec dead_letters(agent()) :: [dead_letter()]
Returns dead-letter entries in the order they were routed. Each entry is
a %{event: %Scriba.Event{}, error: term()} map — the same error
shape the Pipeline passed (an {:error, reason} tuple, or the engine-
internal {:exception, exception, stacktrace} triple).
@spec reset(agent()) :: :ok
Clears the commit log, dead-letter list, and per-stream cursors.
@spec safe_position(agent()) :: non_neg_integer()
Returns the safe replay point: the minimum cursor across all streams. 0 when no streams have committed yet.
@spec start_link(keyword()) :: Agent.on_start()
Starts an in-memory commit log.
Standard Agent.start_link/2 options are supported (:name, etc).
@spec stream_positions(agent()) :: %{required(String.t()) => non_neg_integer()}
Returns the per-stream cursor map.