"""``regulatory_node/template.py`` 中的请求/响应/依赖模型校验。""" import pytest from pydantic import ValidationError from kilostar.core.individual.regulatory_node.template import ( MessageRequest, MessageResponse, RegulatoryNodeDeps, ) def test_message_request_valid_for_client_platform(): req = MessageRequest( platform="client", user_name="alice", platform_id=None, message="hi", ) assert req.platform == "client" assert req.platform_id is None def test_message_request_valid_for_onebot_platform(): req = MessageRequest( platform="onebot", user_name="alice", platform_id="group:1", message="hi", ) assert req.platform == "onebot" def test_message_request_rejects_unknown_platform(): with pytest.raises(ValidationError): MessageRequest( platform="qq", # type: ignore[arg-type] user_name="alice", platform_id="x", message="hi", ) def test_message_response_requires_reply_message(): with pytest.raises(ValidationError): MessageResponse( platform="client", platform_id="x", ) # type: ignore[call-arg] def test_message_response_full_round_trip(): res = MessageResponse( platform="client", platform_id="anonymous", reply_message="hello", ) dumped = res.model_dump() assert dumped["reply_message"] == "hello" assert dumped["platform"] == "client" def test_regulatory_node_deps_defaults(): deps = RegulatoryNodeDeps(platform="client", user_name="alice", time="now") assert deps.retry_count == 0 assert deps.error_history == ""