| """Tests for :mod:`frame.timed_automata.nl2formalmodel.document_ir_validate`.""" |
|
|
| from __future__ import annotations |
|
|
| from frame.timed_automata.nl2formalmodel.ir import ( |
| ActorIR, |
| DocumentIR, |
| EventIR, |
| LifecycleIR, |
| StateIR, |
| TransitionIR, |
| ) |
| from frame.timed_automata.nl2formalmodel.document_ir_validate import ( |
| DocumentIrValidatorAgent, |
| validate_document_ir, |
| ) |
|
|
|
|
| def test_empty_lifecycles_errors(): |
| ir = DocumentIR() |
| errs = validate_document_ir(ir, include_compilation_hints=False) |
| assert any("no lifecycles" in e for e in errs) |
|
|
|
|
| def _simple_lifecycle(owner_actor_id: str = "owner1") -> LifecycleIR: |
| return LifecycleIR( |
| id="p1", |
| name="Process1", |
| owner_actor=owner_actor_id, |
| states=[ |
| StateIR(id="S0", name="S0", is_initial=True, is_terminal=False), |
| StateIR(id="S1", name="S1", is_initial=False, is_terminal=True), |
| ], |
| transitions=[ |
| TransitionIR(id="t1", from_state="S0", to_state="S1"), |
| ], |
| ) |
|
|
|
|
| def test_minimal_ir_ok_without_compilation_hints(): |
| ir = DocumentIR( |
| actors=[ActorIR(id="owner1", name="Owner")], |
| lifecycles=[_simple_lifecycle()], |
| ) |
| errs = validate_document_ir(ir, include_compilation_hints=False) |
| assert errs == [] |
|
|
|
|
| def test_unknown_transition_endpoint(): |
| lc = _simple_lifecycle() |
| lc.transitions[0].to_state = "Nope" |
| ir = DocumentIR( |
| actors=[ActorIR(id="owner1", name="Owner")], |
| lifecycles=[lc], |
| ) |
| errs = validate_document_ir(ir, include_compilation_hints=False) |
| assert any("unknown to_state" in e for e in errs) |
|
|
|
|
| def test_sync_event_requires_send_and_receive(): |
| ir = DocumentIR( |
| actors=[ |
| ActorIR(id="alice", name="Alice"), |
| ActorIR(id="bob", name="Bob"), |
| ], |
| events=[ |
| EventIR( |
| id="ev_ping", |
| name="ping", |
| initiator="alice", |
| receivers=["bob"], |
| is_sync=True, |
| channel_name="ping", |
| ), |
| ], |
| lifecycles=[_simple_lifecycle(owner_actor_id="alice")], |
| ) |
| errs = validate_document_ir(ir, include_compilation_hints=False) |
| assert any("no transition with suggested_sync_role=send" in e for e in errs) |
| assert any("no transition with suggested_sync_role=receive" in e for e in errs) |
|
|
|
|
| def test_validator_agent_ok_property(): |
| ir = DocumentIR( |
| actors=[ActorIR(id="owner1", name="Owner")], |
| lifecycles=[_simple_lifecycle()], |
| ) |
| rep = DocumentIrValidatorAgent(include_compilation_hints=False).validate(ir) |
| assert rep.ok |
| assert rep.errors == [] |
|
|