Skip to content

osrforge.providers.fixtures

Recorded-fixture providers: replay for tests, recording for the live tooling and evals.

Fixture files are named <tag>.<fingerprint[:12]>.json and carry the artifact schema version, the full fingerprint, the tag, a human-reviewable request digest (system text, text parts, and the JSON Schema verbatim, images as sha256 + size — so fixture diffs are readable in PRs and a replay test can reconstruct the request from the fixture plus its committed page assets), and the full response.

FixtureProvider

FixtureProvider(fixture_dir: Path)

Replays recorded request/response fixtures — zero network, zero cost.

A drop-in ModelProvider: any pipeline entry point runs against it unchanged, which is how the test suite exercises the full conversion without a live service.

Examples:

from pathlib import Path

from osrforge import convert
from osrforge.providers.fixtures import FixtureProvider

provider = FixtureProvider(Path("tests/assets/minimod/fixtures"))
result = convert(pdf_path, workdir_path, provider)  # full pipeline, zero network

Bind to a directory of recorded fixtures.

Parameters:

Name Type Description Default
fixture_dir Path

The directory containing <tag>.<fp12>.json files.

required

fixture_dir instance-attribute

fixture_dir = fixture_dir

generate

generate(request: ModelRequest) -> ModelResponse

Replay the fixture matching the request's fingerprint.

Replayed data is re-validated against the incoming request's schema, so a prompt or schema change against stale fixtures fails as a clear SchemaValidationError, not a silent wrong answer.

Parameters:

Name Type Description Default
request ModelRequest

The request to replay.

required

Returns:

Type Description
ModelResponse

The recorded response.

Raises:

Type Description
FixtureMissError

If no fixture matches the fingerprint.

SchemaValidationError

If the recorded data fails the incoming request's schema.

ProviderError

If the fixture file's schema version is not this package's.

RecordingProvider

RecordingProvider(inner: ModelProvider, fixture_dir: Path)

A pass-through that writes each exchange as a replayable fixture file.

This is how the extraction runner records real fixtures and how evals re-record. Writes are idempotent by fingerprint — re-recording an identical request overwrites its fixture in place.

Wrap a real provider and record its exchanges.

Parameters:

Name Type Description Default
inner ModelProvider

The provider that actually answers.

required
fixture_dir Path

Where fixture files land; created if missing.

required

inner instance-attribute

inner = inner

fixture_dir instance-attribute

fixture_dir = fixture_dir

generate

generate(request: ModelRequest) -> ModelResponse

Generate through the inner provider and persist the exchange.

Parameters:

Name Type Description Default
request ModelRequest

The request to run and record.

required

Returns:

Type Description
ModelResponse

The inner provider's response, unchanged.