Skip to content

Commit

Permalink
refactor(robot-server): return the last command if a historical run f…
Browse files Browse the repository at this point in the history
…or get_current_command
  • Loading branch information
mjhuff committed Oct 21, 2024
1 parent 85e625b commit d2778af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
5 changes: 1 addition & 4 deletions robot-server/robot_server/runs/run_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_completed_command(self, run_id: str) -> Optional[CommandPointer]:
"""Get the "last" command, if any.
Expand Down
29 changes: 27 additions & 2 deletions robot-server/tests/runs/test_run_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_completed_command_current_run(
Expand Down

0 comments on commit d2778af

Please sign in to comment.