"""Shared measurement helpers for the UT evaluators.""" from __future__ import annotations from typing import Any from .contracts import EmptyParams, EvaluatorDefinition, EvaluatorResult, measurement_result def unavailable(metric: str, explanation: str) -> EvaluatorResult: return measurement_result( value=None, metric=metric, unit="check", status="unavailable", explanation=explanation, ) def check(metric: str, value: dict[str, bool], explanation: str) -> EvaluatorResult: return measurement_result( value=value, metric=metric, unit="check", score=float(all(value.values())) if value else 0.0, explanation=explanation, ) def normalize_empty(params: dict[str, Any]) -> EmptyParams: if params: raise ValueError(f"unknown evaluator params: {sorted(params)}") return EmptyParams() def measurement(evaluator_id: str, rule: Any, metric: str) -> EvaluatorDefinition: return EvaluatorDefinition( evaluator_id=evaluator_id, family="execution", result_kind="measurement", expansion="once", rule=rule, scope="skill", metric=metric, unit="check", required_evidence=frozenset({"execution_workspace"}), aggregation="mean", direction="maximize", params_type=EmptyParams, normalize_params=normalize_empty, params_schema={"type": "object", "additionalProperties": False}, )