Skip to content

Pin make_detector, HallucinationDetector and CacheManager behavior #131

Closed

Description

@hslev

Parent: #127 · Epic: #126 · Blocked by: #128 (only for tests/golden.py); builds on #129, #130 fixtures
Work on branch 127-record-golden-fixtures-*; commit the changes and close the ticket.

Problem

The factory, the HallucinationDetector facade and CacheManager all change in later tickets. The cache key strings in particular must stay byte-identical when model_version is None, so they have to be recorded.

Current behavior

  • lettucedetect/detectors/factory.py:10 make_detector builds "transformer", "llm" or "rag_fact_checker" and raises ValueError for anything else (:28-32).
  • lettucedetect/detectors/cache.py:12 CacheManager: constructor creates the directory (:17), set and delete rewrite the file with write_text (:39, :46), _hash is SHA-256 of parts joined by || (:28).
  • The three keys LLMDetector builds: judge llm.py:408, native :468 (extra part "native"), verify :506 (extra part "verify").
  • HallucinationDetector lives in lettucedetect/models/.

Steps

  1. Add tests/test_golden_factory_cache_pytest.py.
  2. Record that make_detector returns the right class for each method (fakes in place of loading) and the error message for an unknown method.
  3. Record HallucinationDetector.predict, predict_prompt and predict_prompt_batch equal to the underlying detector's output.
  4. Record the CacheManager JSON file after a few set and delete calls.
  5. Record the three key strings from _hash for fixed prompts (judge, native, verify).

Acceptance criteria

  • Checked-in JSON for each item above.
  • Network-free; no production code and no existing test changes.

Start here

uv run --extra dev pytest tests/test_factory_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