Files
DeepTutor/tests
Leveling 8a85d5eb6e fix(mastery): name the materials a PDF-grounded scope leaves out (#2874)
A Mastery Path objective that selects both a PDF knowledge base and a Markdown
one builds a PDF-only evidence scope: `selected_scope()` skips sources with no
PDF pages. That restriction is deliberate and correct -- questions are verified
against rendered original pages, so a Markdown source cannot take part in that,
and widening the scope would let unverified material count as verified.

What was broken was the reporting. The skip was silent, so a mixed topic looked
fully PDF-grounded, and the two failures a learner could actually hit both
misled:

- `prepare_lesson()` said "This source-grounded path no longer has selected PDF
  materials", which is not what a mixed topic is.
- `bind_questions()` ended at "The selected source does not support this exact
  question and answer key", a per-question verdict that cannot tell the tutor a
  whole selected source sits outside the evidence chain.

The tutor was then pushed to quiz on unread PDF material or retry until the
round budget ran out.

`selected_scope()` now records the label of every source it skips, through an
optional output list. It stays the single place that rule is decided, so nothing
re-derives the predicate and drifts. `describe_skipped()` turns that into a
sentence, appended to the three failures above; `validate_evidence()` passes its
own list through so `bind_questions()` does not scan knowledge bases a second
time for a diagnostic.

Nothing about authorisation changes. A skipped source is still absent from the
scope, still cannot cite, and cannot authorize a question; the tests assert that
directly.

This is the low-risk half of #2859. Actually *supporting* mixed PDF and text
evidence is an evidence-model change -- a third state alongside "PDF-grounded"
and "text-tutoring" -- and should be agreed with a maintainer before anyone
builds it.

Review follow-up
----------------

- `skipped_labels` is now collected per question, not pooled across the batch.
  Questions may belong to different knowledge points, so the shared list let
  one question report materials that were selected only for another. The note
  is rendered per question in `_support_contract()`, kept in a side dict so it
  never leaks into the model payload.
- The singular message read "These selected materials has no PDF pages"; it now
  says "This selected material has ... so it is outside the evidence chain".

Tests
-----

`tests/services/rag/test_mastery_mixed_source_scope.py` covers the skip report,
the silent all-PDF case, the messages, the grammar, the multi-KP case, and the
unchanged security property. Reverting just the per-question collection makes
the multi-KP test fail (`q-pdf` wrongly reports "Beginner guide").

Related suites: `tests/capabilities` plus `test_mastery_source_pages.py` ->
934 passed, 2 skipped. `ruff check` and `ruff format --check` clean.

One bug this work introduced and the suite caught: `validate_evidence()` rebound
its `skipped` parameter to a local list, so callers collected nothing. It is
fixed, with a test pinning the output-parameter contract.
2026-12-02 15:34:21 +08:00
..
2026-11-06 01:56:39 +08:00