From c56dc8d7065d2d89bda333b17c37ecc8ed8ba56f Mon Sep 17 00:00:00 2001 From: Max Marrone Date: Mon, 20 May 2024 12:04:10 -0400 Subject: [PATCH] Return current recovery target ID from StateView. --- api/src/opentrons/protocol_engine/state/commands.py | 6 +++++- .../protocol_engine/state/test_command_state.py | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/api/src/opentrons/protocol_engine/state/commands.py b/api/src/opentrons/protocol_engine/state/commands.py index bc6ba7fed6e..9cb7118fc87 100644 --- a/api/src/opentrons/protocol_engine/state/commands.py +++ b/api/src/opentrons/protocol_engine/state/commands.py @@ -751,9 +751,13 @@ def get_all_commands_final(self) -> bool: return no_command_running and no_command_to_execute + def get_recovery_target_id(self) -> Optional[str]: + """Return the ID of the command currently undergoing error recovery, if any.""" + return self._state.recovery_target_command_id + def get_recovery_in_progress_for_command(self, command_id: str) -> bool: """Return whether the given command failed and its error recovery is in progress.""" - return self._state.recovery_target_command_id == command_id + return self.get_recovery_target_id() == command_id def raise_fatal_command_error(self) -> None: """Raise the run's fatal command error, if there was one, as an exception. diff --git a/api/tests/opentrons/protocol_engine/state/test_command_state.py b/api/tests/opentrons/protocol_engine/state/test_command_state.py index 742abf3e6e9..339d97b901a 100644 --- a/api/tests/opentrons/protocol_engine/state/test_command_state.py +++ b/api/tests/opentrons/protocol_engine/state/test_command_state.py @@ -356,8 +356,8 @@ def test_error_recovery_type_tracking() -> None: assert view.get_error_recovery_type("c2") == ErrorRecoveryType.FAIL_RUN -def test_get_recovery_in_progress_for_command() -> None: - """It should return whether error recovery is in progress for the given command.""" +def test_recovery_target_tracking() -> None: + """It should keep track of the command currently undergoing error recovery.""" subject = CommandStore(config=_make_config(), is_door_open=False) subject_view = CommandView(subject.state) @@ -382,12 +382,14 @@ def test_get_recovery_in_progress_for_command() -> None: subject.handle_action(fail_1) # c1 failed recoverably and we're currently recovering from it. + assert subject_view.get_recovery_target_id() == "c1" assert subject_view.get_recovery_in_progress_for_command("c1") resume_from_1_recovery = actions.ResumeFromRecoveryAction() subject.handle_action(resume_from_1_recovery) # c1 failed recoverably, but we've already completed its recovery. + assert subject_view.get_recovery_target_id() is None assert not subject_view.get_recovery_in_progress_for_command("c1") queue_2 = actions.QueueCommandAction( @@ -411,6 +413,7 @@ def test_get_recovery_in_progress_for_command() -> None: subject.handle_action(fail_2) # c2 failed recoverably and we're currently recovering from it. + assert subject_view.get_recovery_target_id() == "c2" assert subject_view.get_recovery_in_progress_for_command("c2") # ...and that means we're *not* currently recovering from c1, # even though it failed recoverably before. @@ -439,7 +442,8 @@ def test_get_recovery_in_progress_for_command() -> None: subject.handle_action(fail_3) # c3 failed, but not recoverably. - assert not subject_view.get_recovery_in_progress_for_command("c2") + assert subject_view.get_recovery_target_id() is None + assert not subject_view.get_recovery_in_progress_for_command("c3") def test_final_state_after_estop() -> None: