Skip to main content

classifier_conformance

Function classifier_conformance 

Source
pub async fn classifier_conformance(classifier: &dyn Classifier)
Expand description

Asserts the Classifier trait contract against a classifier whose transport is already scripted to answer classifier_conformance_questions about classifier_conformance_state. The suite makes exactly one ask call — script that one request and no other.

Asserted, each panic naming the rule it caught:

  1. the answer map’s keys are exactly the asked question ids;
  2. each answer’s value variant matches its question’s kind;
  3. a choice’s chosen label, a noul’s verdict label, and (where the value names one) a score’s level are labels the question offered;
  4. every key of probabilities is an offered label and every value is finite within 0.0..=1.0 — keys may omit labels (a top-1 provider is legal), they may never invent one;
  5. confidence is finite within 0.0..=1.0 and agrees with the probability the same answer reports for its own chosen label, within an explicit tolerance — the invariant that keeps an adapter from reporting a confidence its own distribution contradicts;
  6. profile().max_state_chars is above zero, and truncate of an over-limit state returns something no longer than the limit.

What the suite deliberately does not assert: that confidence means the same number on two adapters. Calibration is not portable — a 0.8 from a purpose-trained classifier and a 0.8 elicited from a general language model are different numbers — so no assertion here compares confidence values between adapters, and a threshold tuned against one stays per-adapter (see cratefield_core::Calibration).

ⓘ
// In the adapter's own test, after scripting its transport:
classifier_conformance(&adapter).await;

§Panics

Panics naming the broken rule when the contract is violated, and when the scripted ask fails.