diff --git a/api-client/src/runs/types.ts b/api-client/src/runs/types.ts index a2314e96492..d274152d578 100644 --- a/api-client/src/runs/types.ts +++ b/api-client/src/runs/types.ts @@ -98,7 +98,7 @@ export interface RunsLinks { } export interface RunCommandLink { - last: CommandLinkNoMeta + lastCompleted: CommandLinkNoMeta } export interface CommandLinkNoMeta { diff --git a/robot-server/robot_server/runs/router/base_router.py b/robot-server/robot_server/runs/router/base_router.py index 1a3cdb2ff90..788ca44aa1c 100644 --- a/robot-server/robot_server/runs/router/base_router.py +++ b/robot-server/robot_server/runs/router/base_router.py @@ -132,7 +132,7 @@ class AllRunsLinks(BaseModel): class CurrentStateLinks(BaseModel): """Links returned with the current state of a run.""" - last: Optional[CommandLinkNoMeta] = Field( + lastCompleted: Optional[CommandLinkNoMeta] = Field( None, description="Path to the last completed command when current state was reported, if any.", ) @@ -597,7 +597,7 @@ async def get_current_state( raise RunStopped(detail=str(e)).as_error(status.HTTP_409_CONFLICT) links = CurrentStateLinks.construct( - last=CommandLinkNoMeta.construct( + lastCompleted=CommandLinkNoMeta.construct( id=last_completed_command.command_id, href=f"/runs/{runId}/commands/{last_completed_command.command_id}", ) diff --git a/robot-server/robot_server/runs/run_data_manager.py b/robot-server/robot_server/runs/run_data_manager.py index f111ca07a3f..d30f5c33979 100644 --- a/robot-server/robot_server/runs/run_data_manager.py +++ b/robot-server/robot_server/runs/run_data_manager.py @@ -578,7 +578,7 @@ def _get_historical_run_last_command(self, run_id: str) -> Optional[CommandPoint command_id=command.id, command_key=command.key, created_at=command.createdAt, - index=command_slice.total_length - 1, + index=command_slice.cursor, ) if command else None diff --git a/robot-server/tests/runs/router/test_base_router.py b/robot-server/tests/runs/router/test_base_router.py index f92022350d1..894950343e4 100644 --- a/robot-server/tests/runs/router/test_base_router.py +++ b/robot-server/tests/runs/router/test_base_router.py @@ -903,7 +903,7 @@ async def test_get_current_state_success( } ) assert result.content.links == CurrentStateLinks( - last=CommandLinkNoMeta( + lastCompleted=CommandLinkNoMeta( href="/runs/test-run-id/commands/last-command-id", id="last-command-id", ) diff --git a/robot-server/tests/runs/test_run_data_manager.py b/robot-server/tests/runs/test_run_data_manager.py index e874f461ca5..5e4aed1f3e2 100644 --- a/robot-server/tests/runs/test_run_data_manager.py +++ b/robot-server/tests/runs/test_run_data_manager.py @@ -1023,7 +1023,7 @@ def test_get_current_command_not_current_run( ) command_slice = CommandSlice( - commands=[last_command_slice], cursor=1, total_length=1 + commands=[last_command_slice], cursor=0, total_length=1 ) decoy.when(mock_run_orchestrator_store.current_run_id).then_return("not-run-id") @@ -1049,7 +1049,7 @@ def test_get_last_completed_command_current_run( command_id=run_command.id, command_key=run_command.key, created_at=run_command.createdAt, - index=5, + index=1, ) decoy.when(mock_run_orchestrator_store.current_run_id).then_return(run_id) @@ -1084,7 +1084,7 @@ def test_get_last_completed_command_not_current_run( command_id="command-id-1", command_key="command-key", created_at=datetime(year=2021, month=1, day=1), - index=0, + index=1, ) decoy.when(mock_run_orchestrator_store.current_run_id).then_return(