"""Tests for shared LLM response-parsing logic.""" from __future__ import annotations from physcom.llm.parsing import parse_metric_json, parse_verdict from physcom.models.domain import MetricBound def _bounds(): return [ MetricBound("power_density", weight=0.5, norm_min=1, norm_max=2000, unit="W/kg"), MetricBound("safety", weight=0.5, norm_min=0.0, norm_max=1.0, unit="0-1"), ] def test_parse_metric_json_strips_fences(): text = '```json\n{"power_density": 500.0, "safety": 0.7}\n```' result = parse_metric_json(text, _bounds()) assert result == {"power_density": 500.0, "safety": 0.7} def test_parse_metric_json_falls_back_to_range_midpoint_on_invalid(): result = parse_metric_json("not json", _bounds()) assert result == {"power_density": 1000.5, "safety": 0.5} def test_parse_verdict_plausible(): assert parse_verdict("blah blah\nVERDICT: PLAUSIBLE") is True def test_parse_verdict_implausible(): assert parse_verdict("blah blah\nVERDICT: IMPLAUSIBLE") is False