From b03a19dbfd3fbb0ce16cc91e17bc2e69d320090c Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Tue, 31 Dec 2024 14:10:21 -0600 Subject: [PATCH] make `halt`ed robots immediately wake up --- data/scenarios/Testing/00-ORDER.txt | 1 + data/scenarios/Testing/2253-halt-waiting.yaml | 27 +++++++++++++++++++ src/swarm-engine/Swarm/Game/Step/Const.hs | 5 ++-- test/integration/Main.hs | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 data/scenarios/Testing/2253-halt-waiting.yaml diff --git a/data/scenarios/Testing/00-ORDER.txt b/data/scenarios/Testing/00-ORDER.txt index a7f60f0dd..67efafd9f 100644 --- a/data/scenarios/Testing/00-ORDER.txt +++ b/data/scenarios/Testing/00-ORDER.txt @@ -72,3 +72,4 @@ Achievements 2086-structure-palette.yaml 2239-custom-entity.yaml 2240-overridden-entity-capabilities.yaml +2253-halt-waiting.yaml diff --git a/data/scenarios/Testing/2253-halt-waiting.yaml b/data/scenarios/Testing/2253-halt-waiting.yaml new file mode 100644 index 000000000..aab8afc3a --- /dev/null +++ b/data/scenarios/Testing/2253-halt-waiting.yaml @@ -0,0 +1,27 @@ +version: 1 +name: Halt a waiting robot +description: | + Calling `halt` on a waiting robot should make it immediately idle, + so it can e.g. be `reprogram`med +creative: true +objectives: + - goal: + - Get some gold + condition: | + as base { has "gold" }; +robots: + - name: base + dir: north + devices: + - logger +solution: | + r <- build {move; wait 10000}; + wait 2; + halt r; wait 1; reprogram r {create "gold"; give base "gold"} +world: + dsl: | + {grass} + palette: + 'B': [grass, null, base] + map: | + B diff --git a/src/swarm-engine/Swarm/Game/Step/Const.hs b/src/swarm-engine/Swarm/Game/Step/Const.hs index e263527db..b9a188e7b 100644 --- a/src/swarm-engine/Swarm/Game/Step/Const.hs +++ b/src/swarm-engine/Swarm/Game/Step/Const.hs @@ -893,9 +893,10 @@ execConst runChildProg c vs s k = do omni <- isPrivilegedBot case omni || not (target ^. systemRobot) of True -> zoomRobots $ do - -- Cancel its CESK machine, and put it to sleep. + -- Cancel its CESK machine, and wake it up to ensure + -- it can do cleanup + run to completion. robotMap . at targetID . _Just . machine %= cancel - sleepForever targetID + activateRobot targetID return $ mkReturn () False -> throwError $ cmdExn c ["You are not authorized to halt that robot."] _ -> badConst diff --git a/test/integration/Main.hs b/test/integration/Main.hs index 7d1546c09..7230e0c42 100644 --- a/test/integration/Main.hs +++ b/test/integration/Main.hs @@ -507,6 +507,7 @@ testScenarioSolutions rs ui key = assertBool "Error message should mention tank treads but not treads" $ not (any ("- treads" `T.isInfixOf`) msgs) && any ("- tank treads" `T.isInfixOf`) msgs + , testSolution Default "Testing/2253-halt-waiting" ] where -- expectFailIf :: Bool -> String -> TestTree -> TestTree