Skip to content

Portability Diff Tool

anyinfer.compare_diff: snapshot compare() output for a fixture set, and diff two snapshots structurally. No ranking, scoring, or live provider calls; every function here either calls compare() (itself no-dispatch) or works on plain JSON. See the portability guide for the full walkthrough and the fixture schema.

from anyinfer import compare_diff

anyinfer.compare_diff.load_fixtures

load_fixtures(path: str | Path) -> tuple[Fixture, ...]

Parse and validate a fixture file.

Raises:

Type Description
ConfigError

The file is missing, not valid JSON, declares an unsupported schema_version, or a fixture entry is malformed.

anyinfer.compare_diff.snapshot

snapshot(
    fixtures: Sequence[Fixture], *, client: Client
) -> dict[str, Any]

Run compare() over every fixture and serialize the results.

No new result data model — this only persists TargetComparison.to_dict()'s existing shape, keyed by fixture id and then by target string, so a diff can address any single (fixture, target) pair directly.

Parameters:

Name Type Description Default
fixtures Sequence[Fixture]

Fixtures to snapshot, typically from load_fixtures().

required
client Client

A configured anyinfer.Client — its provider settings determine which targets actually resolve.

required

Returns:

Type Description
dict[str, Any]

A JSON-safe mapping: {"schema_version": ..., "fixtures": {id: {target: {...}}}}.

anyinfer.compare_diff.diff

diff(
    baseline: Mapping[str, Any], current: Mapping[str, Any]
) -> DiffReport

Structurally diff two snapshots produced by snapshot().

Raises:

Type Description
ConfigError

Either mapping is not a valid snapshot document.

anyinfer.compare_diff.diff_targets

diff_targets(
    fixture: Fixture,
    target_a: str,
    target_b: str,
    *,
    client: Client,
) -> DiffReport

The ad hoc, no-baseline-file "should I move from A to B" report.

Runs compare() live for exactly [target_a, target_b] under fixture and diffs the two resulting comparisons directly — the customer-facing portability report.

anyinfer.compare_diff.render_text

render_text(report: DiffReport) -> str

Human-readable rendering of a DiffReport, one line per entry.

anyinfer.compare_diff.Fixture dataclass

Fixture(
    id: str,
    request: GenerationRequest,
    targets: tuple[str, ...],
)

One request to snapshot against one ordered set of targets.

Attributes:

Name Type Description
id str

Stable identifier — the key snapshots and diffs are organized by. Renaming a fixture's id is a breaking change to any baseline snapshot that references it, the same way renaming a test would be.

request GenerationRequest

The request to compare, already resolved to a GenerationRequest.

targets tuple[str, ...]

Target strings to compare request against, in the order results are reported (never reordered — compare()'s own ordering discipline).

anyinfer.compare_diff.DiffReport dataclass

DiffReport(entries: tuple[DiffEntry, ...])

The full result of diffing two snapshots (or two live comparisons).

Attributes:

Name Type Description
entries tuple[DiffEntry, ...]

Every difference found, in a stable order (fixture, then target, then field) — never ranked or filtered by significance.

is_empty property

is_empty: bool

Whether the two snapshots reported were identical.

anyinfer.compare_diff.DiffEntry dataclass

DiffEntry(
    fixture_id: str,
    target: str,
    kind: str,
    field: str,
    before: Any,
    after: Any,
    summary: str,
)

One reported difference between two snapshots.

Attributes:

Name Type Description
fixture_id str

Which fixture this entry belongs to.

target str

Which target this entry belongs to.

kind str

"added" (present only in the newer snapshot), "removed" (present only in the baseline), or "changed" (present in both with a different value).

field str

Dotted path within TargetComparison.to_dict()'s shape, e.g. "structured_mechanism" or "dropped.0.name".

before Any

The baseline value, or None when kind is "added".

after Any

The current value, or None when kind is "removed".

summary str

A plain-language line reusing compare()'s own field vocabulary.

anyinfer.compare_diff.FIXTURE_SCHEMA_VERSION module-attribute

FIXTURE_SCHEMA_VERSION = 1

The fixture file format this module reads and writes. Additive, never breaking: a future version adds fields or fixture kinds, it never repurposes an existing key.