"""The same timestamp matrix as the Frontend and Agent contract tests.""" import pytest from pydantic import ValidationError from app.domain.schemas.answer_ui import AnswerUiBlock from app.domain.schemas.operational_task import TaskSafeChart CASES = [ ("2026-06-14T12:00:00Z", True), ("2026-06-14T12:00:00+08:00", True), ("2026-06-14T12:00:00-03:30", True), ("2024-02-29T23:59:59.123456Z", True), ("2026-06-14T12:00:00+23:59", True), ("2026-06-14T12:00:00." + "1" * 43 + "Z", True), ("2026-06-14 12:00:00+08:00", False), ("2026-W24-7T12:00:00+08:00", False), ("2026-06-14T12:00+08:00", False), ("2026-06-14T12:00:00+0800", False), ("2026-02-30T12:00:00Z", False), ("2026-13-14T12:00:00Z", False), ("2026-06-00T12:00:00Z", False), ("2026-02-29T12:00:00Z", False), ("2026-06-14T24:00:00Z", False), ("2026-06-14T12:00:60Z", False), ("2026-06-14T12:00:00+24:00", False), ("2026-06-14T12:00:00+08:60", False), ("2026-06-14T12:00:00", False), ("2026-06-14T12:00:00z", False), ("0000-06-14T12:00:00Z", False), ("2026-06-14T12:00:00." + "1" * 44 + "Z", False), ] def chart(data, times): return {"title": "压力", "chart_type": "line", "x_data": ["12:00"], "series": [{"name": "测点", "data": data, "sample_times": times}]} def block(value): return {"version": "answer-ui@1", "block_id": "pressure", "fallback_text": "压力数据", "spec": {"root": "chart", "elements": {"chart": {"type": "Chart", "children": [], "props": {**value, "source": "实测"}}}}} @pytest.mark.parametrize("time,accepted", CASES) def test_sample_times_match_on_chart_commands_and_answer_blocks(time, accepted): value = chart([1], [time]) for model, payload in [(TaskSafeChart, value), (AnswerUiBlock, block(value))]: if accepted: model.model_validate(payload) else: with pytest.raises(ValidationError): model.model_validate(payload) @pytest.mark.parametrize("data,times,accepted", [ ([0], [None], True), ([None], [None], True), ([None], ["2026-06-14T12:00:00Z"], False), ([1], [], False), ]) def test_sample_times_keep_zero_null_and_alignment(data, times, accepted): value = chart(data, times) for model, payload in [(TaskSafeChart, value), (AnswerUiBlock, block(value))]: if accepted: model.model_validate(payload) else: with pytest.raises(ValidationError): model.model_validate(payload)