From 12e972cc9ffff3f4623ffaee329996d2adad325c Mon Sep 17 00:00:00 2001 From: lola Date: Thu, 23 Oct 2025 11:29:56 -0700 Subject: [PATCH] verify invariants are checked after actions in try-interrupt --- tests/syntax/test_dynamics.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/syntax/test_dynamics.py b/tests/syntax/test_dynamics.py index 7db1ce2a1..7df462523 100644 --- a/tests/syntax/test_dynamics.py +++ b/tests/syntax/test_dynamics.py @@ -1777,6 +1777,27 @@ def test_interrupt_except_else(): assert tuple(actions) == (1, 2, 3, 1, 1, 5, None) +def test_interrupt_invariant_after_actions(): + scenario = compileScenic( + """ + behavior Foo(): + invariant: ego.bar == 0 + try: + for i in range(3): + take 1 + interrupt when simulation().currentTime == 1: + take 2 + ego.bar = 1 + except InvariantViolation: + ego.bar = 0 + take 4 + ego = new Object with bar 0, with behavior Foo + """ + ) + actions = sampleEgoActions(scenario, maxSteps=4) + assert tuple(actions) == (1, 2, 4, None) + + # Nesting