LlmCall.Media.Conformance (llm_call v0.1.0)

Copy Markdown View Source

Fixture-based assertions for media codec authors.

Test support, not a runtime dependency. Every function returns :ok or raises an ExUnit.AssertionError naming the failed expectation.

test "my media codec conforms" do
  Conformance.assert_info(MyCodec)
  Conformance.assert_submit_path(MyCodec, request, "/v1/my-images")
end

Summary

Functions

Checks that capabilities/2 and validate_request/2 agree.

Asserts the shape of any encoded request: a map body, a map query, a list of headers, and no credential header.

Asserts well-formed info/0 metadata (see LlmCall.Conformance).

Checks one LlmCall.Operation against the state-machine invariants.

Asserts that decode_operation/2 applies the capture_raw policy to Operation.raw.

Functions

assert_capabilities(codec, request, config)

@spec assert_capabilities(module(), LlmCall.Media.Request.t(), LlmCall.Config.t()) ::
  :ok

assert_capability_consistency(codec, base_request, config)

@spec assert_capability_consistency(
  module(),
  LlmCall.Media.Request.t(),
  LlmCall.Config.t()
) :: :ok

Checks that capabilities/2 and validate_request/2 agree.

Every declared size, aspect_ratio, duration_s, and max_n must be accepted, and an undeclared non-nil value must be a validation error. The same holds for the seed and negative_prompt flags and for max_references.

assert_capture_raw(codec, provider_payload)

@spec assert_capture_raw(module(), LlmCall.wire_value()) :: :ok

assert_encoded_request(encoded, label)

@spec assert_encoded_request(LlmCall.EncodedRequest.t(), String.t()) :: :ok

Asserts the shape of any encoded request: a map body, a map query, a list of headers, and no credential header.

assert_operation/1 runs this over Operation.next, so a poll or asset-fetch request cannot smuggle an authorization header past the submit check.

assert_info(codec)

@spec assert_info(module()) :: :ok

Asserts well-formed info/0 metadata (see LlmCall.Conformance).

assert_operation(operation)

@spec assert_operation(LlmCall.Operation.t()) :: :ok

Checks one LlmCall.Operation against the state-machine invariants.

A state a codec can return must satisfy: :queued/:in_progress poll with no result; :completed never polls, always has a result, and an :asset fetch names its media type; :failed carries an error and nothing else. id is a non-empty string or nil, progress is an integer in 0..100 or nil, and raw is a map or nil.

assert_operation_capture_raw(codec, provider_payload, base_config \\ %Config{})

@spec assert_operation_capture_raw(module(), LlmCall.wire_value(), LlmCall.Config.t()) ::
  :ok

Asserts that decode_operation/2 applies the capture_raw policy to Operation.raw.

The operation payload is the provider's job body, so :none must drop it and :response/:all must keep it, matching decode_submit/2. Error.raw is intentionally unconditional: an error keeps the payload it came from.

assert_submit_path(codec, request, expected_path)

@spec assert_submit_path(module(), LlmCall.Media.Request.t(), String.t()) :: :ok

assert_sync_rejects_operation(codec)

@spec assert_sync_rejects_operation(module()) :: :ok