Repository navigation
test: record golden fixtures for today's detector API (#127) - #182
Merged
hslev merged 4 commits intoNov 5, 2026
Merged
Conversation
Add tests/golden.py (assert_golden, UPDATE_GOLDEN=1 to rewrite, readable unified diff, floats rounded to 6 places) and record predict, predict_prompt and predict_prompt_batch in "tokens" and "spans" format on a stub model with the local tokenizer, plus a multi-group context and spans typed by a stub typer. Recorded as-is: "tokens" output ends with the trailing [SEP], and the multi-group path flags a token at prob >= 0.5 while the single-group path uses argmax. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Record predict, predict_prompt and predict_prompt_batch in "tokens" and "spans" format through a fake LLMClient: the judge with defaults, zero_shot, include_reasoning, each include_taxonomy form (True, list, flat dict, nested dict), verify, and native mode with and without include_reasoning. Also record today's behaviour in the cases the epic changes (llm_defect_*): a reply without hallucination_list, an unparseable reply, an item that is not found in the answer, and spans without confidence. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…130) Record "tokens", "spans" and "detailed" output of predict, predict_prompt and predict_prompt_batch through a fake fact checker, a triplet matched only by the single-word fallback (confidence 0.7), and the merge defect where a merged span's text is shorter than its offsets (rag_merge_overlap_text_shorter_than_offsets_*, for the fix PR to update). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ior (#131) Record the class make_detector returns for "transformer", "llm" and "rag_fact_checker" and the error for an unknown method; assert and record that HallucinationDetector.predict, predict_prompt and predict_prompt_batch return what the detector alone returns (transformer, LLM, RAG); and pin the CacheManager file after set/delete calls, the _hash strings, and the judge, native and verify keys LLMDetector writes for fixed prompts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Characterization ("golden") tests that pin today's output of every public detector entry point the detectors epic (#126) rebuilds or deprecates, so each later adapter can prove it keeps today's shape. Tests and fixtures only: no production code and no existing test changed.
One commit per sub-ticket (#128, #129, #130, #131). Recordings include today's defects (
llm_defect_*,rag_merge_overlap_text_shorter_than_offsets_*); the PR that fixes one updates its fixture as an intended change.Notes for review:
assert_goldenrounds floats to 6 places on both sides, so cross-platform softmax noise cannot flake the suite.[SEP]; atprob == 0.5the single-group path (argmax) and multi-group path (>= 0.5) disagree;LLMDetectordefaults to"spans"while the facade defaults to"tokens".cache_llm_detector_keys(and invalidates users' caches): re-record on purpose.Related issue
Closes #127, #128, #129, #130, #131. Parent: #126.
Base is
stateless_core, notmain, so GitHub will not close these automatically; close them by hand after the merge.Type of change
Testing
Before: the new tests do not exist and a changed detector output goes unnoticed. After, a changed output fails with a diff. Each recording was checked by temporarily changing a production constant (
transformer.py>= 0.5,llm.py_SUPPORTED_TOKEN_PROB,rag_fact_checker.py0.7,cache.py"||"); the matching golden tests failed, then the change was reverted.ruff format --check lettucedetect/ lettucedetect_api/ tests/(74 files already formatted)ruff check lettucedetect/ lettucedetect_api/ tests/ --extend-exclude lettucedetect/integrations/(all checks passed)HF_HUB_OFFLINE=1 OPENAI_API_KEY='' uv run --extra dev pytest(265 passed, run withHF_HUB_OFFLINE=1and noOPENAI_API_KEY)Checklist
Rights & sign-off (required)
distributed under the repository's MIT license
(see CONTRIBUTING).
Merge Danger
Door: two-way. Test-only; reverting removes the files.
Blast Radius: tests. Every later detector change that alters recorded output now fails until its fixture is updated (
UPDATE_GOLDEN=1).