diff --git a/robot-server/robot_server/runs/run_data_manager.py b/robot-server/robot_server/runs/run_data_manager.py index b0eab39bcf2..b12fa931f1f 100644 --- a/robot-server/robot_server/runs/run_data_manager.py +++ b/robot-server/robot_server/runs/run_data_manager.py @@ -456,10 +456,7 @@ def get_current_command(self, run_id: str) -> Optional[CommandPointer]: if self._run_orchestrator_store.current_run_id == run_id: return self._run_orchestrator_store.get_current_command() else: - # todo(mm, 2024-05-20): - # For historical runs to behave consistently with the current run, - # this should be the most recently completed command, not `None`. - return None + return self._get_historical_run_last_command(run_id=run_id) def get_last_command(self, run_id: str) -> Optional[CommandPointer]: """Get the "last" command, if any. diff --git a/robot-server/tests/runs/test_run_data_manager.py b/robot-server/tests/runs/test_run_data_manager.py index 75fa95b36f6..38137aefcca 100644 --- a/robot-server/tests/runs/test_run_data_manager.py +++ b/robot-server/tests/runs/test_run_data_manager.py @@ -1004,12 +1004,37 @@ def test_get_current_command_not_current_run( subject: RunDataManager, mock_run_store: RunStore, mock_run_orchestrator_store: RunOrchestratorStore, + run_command: commands.Command, ) -> None: - """Should return None because the run is not current.""" + """Should get the last command from the run store for a historical run.""" + last_command_slice = commands.WaitForResume( + id="command-id-1", + key="command-key", + createdAt=datetime(year=2021, month=1, day=1), + status=commands.CommandStatus.SUCCEEDED, + params=commands.WaitForResumeParams(message="Hello"), + ) + + expected_last_command = CommandPointer( + command_id="command-id-1", + command_key="command-key", + created_at=datetime(year=2021, month=1, day=1), + index=0, + ) + + command_slice = CommandSlice( + commands=[last_command_slice], cursor=1, total_length=1 + ) + decoy.when(mock_run_orchestrator_store.current_run_id).then_return("not-run-id") + decoy.when( + mock_run_store.get_commands_slice( + run_id="run-id", cursor=None, length=1, include_fixit_commands=True + ) + ).then_return(command_slice) result = subject.get_current_command("run-id") - assert result is None + assert result == expected_last_command def test_get_last_command_current_run(