Skip to content

Pin today's TransformerDetector output with golden fixtures #128

Closed

Description

@hslev

Parent: #127 · Epic: #126 · Blocked by: none
Work on branch 127-record-golden-fixtures-*; commit the changes and close the ticket.

Problem

The detectors epic rebuilds TransformerDetector on top of EncoderDetector. Nothing records today's predict* output, so no later adapter can prove it keeps today's shape. This ticket also adds the golden-file helper the other 01* tickets reuse.

Current behavior

  • lettucedetect/detectors/transformer.py:449 predict, :489 predict_prompt, :528 predict_prompt_batch return token dicts or span dicts depending on output_format.
  • Passage grouping: transformer.py:84 _group_passages_into_chunks; aggregation across groups: :341 _predict_chunked.
  • Typed spans come from lettucedetect/detectors/taxonomy_head.py:96 type_spans, attached in transformer.py:69-82.
  • Existing tests build a stub model with the local tokenizer: tests/test_inference_pytest.py, tests/conftest.py (local_wordpiece_tokenizer).

Steps

  1. Add tests/golden.py: assert_golden(name, data) compares data with tests/fixtures/golden/<name>.json and fails on any difference. With UPDATE_GOLDEN=1 it rewrites the file instead.
  2. Add tests/test_golden_transformer_pytest.py. Copy the stub-model and tokenizer fixtures from test_inference_pytest.py (copy the fixtures, not the patching).
  3. Record predict, predict_prompt and predict_prompt_batch, each in "tokens" and "spans" format, on two or three small inputs.
  4. Include one context that needs more than one passage group, and one run with spans typed by a stub typer.
  5. Check the JSON files in.

Acceptance criteria

  • tests/golden.py exists; a changed output makes the test fail with a readable diff.
  • Checked-in JSON covers the three methods × two formats, the multi-group case and the stub-typer case.
  • Tests are network-free and need no API key.
  • No production code and no existing test changes.

Start here

uv run --extra dev pytest tests/test_inference_pytest.py -q

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agent

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions