Files
Insider/backend/tests/test_answer_eval.py
T
adminandClaude Opus 5.5 4c6e77017e Ground cited answers: few-shot refusal, a verifier, graph expansion, an eval
Brings in tobayah/legal-memory's RAG findings (Apache-2.0, CREDITS.md):
- the answer prompt is data (app/ai/prompts/answer.json, PL + EN) with two
  worked examples, the second a REFUSAL although the right act is present;
- services/grounding.verify drops every sentence that cites nothing, a
  passage out of range, an art./section/ust. number, date or act number its
  CITED passage does not hold (invented vs miscited after searching the whole
  context), or whose lemmatised words its passage does not support; nothing
  left = refused; a `verification` block goes to REST and MCP;
- retrieval adds up to INSIDER_ANSWER_GRAPH_EXPAND articles one hop away in
  legal_ref, only while RankPrior.active() (the rank_prior guard);
- tests/answer_eval.py: a misbehaving fake generator per failure mode, plus
  real questions for --live runs; infra-matrix test in bare and full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 00:40:41 +02:00

27 lines
996 B
Python

"""The offline part of `tests/answer_eval.py`: every misbehaving generator is caught."""
from __future__ import annotations
import pytest
from answer_eval import load, run_fake, run_real
@pytest.mark.parametrize("case", [c["name"] for c in load()["fake"]])
def test_the_verifier_catches_each_misbehaviour(case):
row = next(r for r in run_fake() if r["name"] == case)
assert row["ok"], (row["got"], row["expect"], row["flagged"])
def test_every_fake_prompt_carries_the_refusal_example():
for r in run_fake():
system, _user = r["prompt"]
assert system.count("BRAK_PODSTAW") >= 2
def test_the_full_box_widens_the_context_through_the_graph():
pytest.importorskip("tantivy")
pytest.importorskip("numpy")
rows = run_real()
assert all(r["graph_added"] > 0 for r in rows), rows
# the one question this fixture's retrieval answers today; the others are reported
assert next(r for r in rows if "najmu okazjonalnego" in r["q"])["context_ok"], rows