Build deterministic Codex outcomes for worker tests without invoking the CLI.
The helpers encode the same JSONL events ObanCodex reads in production, so
tests exercise text/1, structured/1, session_id/1, and usage/1 rather
than relying on a parallel fake result representation.
import ObanCodex.Testing
assert {:ok, result} =
ObanCodex.run(%{"prompt" => "x"}, query_fun: respond("done"))
assert ObanCodex.text(result) == "done"
result = structured_result(%{"outcome" => "blocked"}, session_id: "thread-1")
assert ObanCodex.outcome(result) == "blocked"
assert ObanCodex.session_id(result) == "thread-1"
Summary
Types
A normalized error struct or shorthand error kind.
A result struct or shorthand final-message string.
Functions
Build a normalized pre-result execution error.
Return a query function that always fails before producing a CLI result.
Build a completed non-zero Codex result.
Return a query function that always succeeds.
Build a successful %CodexWrapper.Result{} with realistic JSONL stdout.
Build a result from final-message text plus keyword options.
Return each scripted result/error in sequence, raising after exhaustion.
Build a successful result whose final message is JSON-encoded structured data.
Types
@type failable() :: ObanCodex.Error.t() | atom()
A normalized error struct or shorthand error kind.
@type respondable() :: CodexWrapper.Result.t() | String.t()
A result struct or shorthand final-message string.
Functions
@spec error( atom(), keyword() ) :: ObanCodex.Error.t()
Build a normalized pre-result execution error.
@spec fail(failable()) :: ObanCodex.query_fun()
Return a query function that always fails before producing a CLI result.
@spec failed_result( String.t(), keyword() ) :: CodexWrapper.Result.t()
Build a completed non-zero Codex result.
This models CLI failures such as authentication or invalid config, which the
wrapper returns as %Result{success: false} rather than {:error, reason}.
@spec respond(respondable()) :: ObanCodex.query_fun()
Return a query function that always succeeds.
@spec result(String.t() | keyword()) :: CodexWrapper.Result.t()
Build a successful %CodexWrapper.Result{} with realistic JSONL stdout.
A string is shorthand for the final agent message. Keyword options:
:text/:result— final agent message (:resultis a parity alias):session_id— emitted as thethread_id:usage— map emitted onturn.completed:stderr— raw stderr:events— additional raw event maps inserted beforeturn.completed
@spec result( String.t(), keyword() ) :: CodexWrapper.Result.t()
Build a result from final-message text plus keyword options.
@spec sequence([respondable() | failable()]) :: ObanCodex.query_fun()
Return each scripted result/error in sequence, raising after exhaustion.
Strings become successes, atoms become normalized errors, and prebuilt
%Result{} / %Error{} structs retain their sense.
@spec structured_result( map() | list(), keyword() ) :: CodexWrapper.Result.t()
Build a successful result whose final message is JSON-encoded structured data.