Repository navigation
Commit 1f3b66b
test: add runtime event-stream invariant checker plugin for unit tests
Add InvariantPlugin in tests/unittests/_invariants.py and wire it by default into TestInMemoryRunner and InMemoryRunner in tests/unittests/testing_utils.py and tests/unittests/workflow/testing_utils.py (with check_invariants: bool = True opt-out).
Active invariants checked at the end of every runner turn:
- call_has_single_response: every non-partial FunctionCall with an id has 1 matching FunctionResponse (or 0..1 while paused on an LRO / HITL / confirmation / credential request or suspended parent NodeTool sub-branch).
- response_author_matches_call: every FunctionResponse is authored by the calling agent, 'user', or a descendant sub-branch.
- response_branch_descends_from_call: every FunctionResponse branch equals or descends from its FunctionCall branch.
- no_duplicate_response_ids: no two effective FunctionResponses for the same call instance share an id.
- no_events_after_cancel: no event is emitted for (author, branch) after an end_of_agent event within the same turn unless re-entered via agent transfer or loop state advancement.
- invocation_id_consistent: every event in the stream carries the active invocation_id.
Also deep-copy LlmResponse objects yielded by MockModel so parallel agents sharing a response fixture list do not mutate FunctionCall IDs in place across branches.
Co-authored-by: Shangjie Chen <[email protected]>
PiperOrigin-RevId: 9933848031 parent 71c4fd7 commit 1f3b66b
6 files changed
Lines changed: 1056 additions & 8 deletions
0 commit comments