diff --git a/api/src/opentrons/protocol_engine/state/command_history.py b/api/src/opentrons/protocol_engine/state/command_history.py index 185492a71c8..e5469282e65 100644 --- a/api/src/opentrons/protocol_engine/state/command_history.py +++ b/api/src/opentrons/protocol_engine/state/command_history.py @@ -119,14 +119,6 @@ def get_filtered_command_ids( } return list(filtered_command.keys()) - def get_filtered_queue_ids(self, all_commands: bool) -> list[str]: - print(list(self.get_fixit_queue_ids())) - return [ - i - for i in self._all_command_ids - if i not in list(self.get_fixit_queue_ids()) - ] - def get_all_ids(self) -> List[str]: """Get all command IDs.""" return self._all_command_ids diff --git a/api/tests/opentrons/protocol_engine/state/test_command_history.py b/api/tests/opentrons/protocol_engine/state/test_command_history.py index d3abf69678d..ed992ab2510 100644 --- a/api/tests/opentrons/protocol_engine/state/test_command_history.py +++ b/api/tests/opentrons/protocol_engine/state/test_command_history.py @@ -13,10 +13,14 @@ def create_queued_command_entry( - command_id: str = "command-id", index: int = 0 + command_id: str = "command-id", + intent: CommandIntent = CommandIntent.PROTOCOL, + index: int = 0, ) -> CommandEntry: """Create a command entry for a queued command.""" - return CommandEntry(create_queued_command(command_id=command_id), index) + return CommandEntry( + create_queued_command(command_id=command_id, intent=intent), index + ) def create_fixit_command_entry( @@ -94,17 +98,6 @@ def test_get_all_commands(command_history: CommandHistory) -> None: ] -def test_get_all_filtered_commands(command_history: CommandHistory) -> None: - """It should return a list of all commapnds.""" - assert command_history.get_filtered_queue_ids(all_commands=False) == [] - command_entry_1 = create_queued_command_entry() - command_entry_2 = create_queued_command_entry(index=1) - command_history._add("0", command_entry_1) - command_history._add("1", command_entry_2) - command_history._add_to_fixit_queue("1") - assert command_history.get_filtered_queue_ids(all_commands=False) == ["0"] - - def test_get_all_ids(command_history: CommandHistory) -> None: """It should return a list of all command IDs.""" assert command_history.get_all_ids() == [] @@ -273,3 +266,63 @@ def test_remove_id_from_setup_queue(command_history: CommandHistory) -> None: command_history._add_to_setup_queue("1") command_history._remove_setup_queue_id("0") assert command_history.get_setup_queue_ids() == OrderedSet(["1"]) + + +def test_get_filtered_commands(command_history: CommandHistory) -> None: + """It should return a list of all commands without fixit commands.""" + assert list(command_history.get_filtered_command_ids()) == [] + command_entry_1 = create_queued_command(command_id="0") + command_entry_2 = create_queued_command(command_id="1") + fixit_command_entry_1 = create_queued_command( + intent=CommandIntent.FIXIT, command_id="fixit-1" + ) + command_history.append_queued_command(command_entry_1) + command_history.append_queued_command(command_entry_2) + command_history.append_queued_command(fixit_command_entry_1) + assert list(command_history.get_filtered_command_ids()) == ["0", "1"] + + +def test_get_all_filtered_commands(command_history: CommandHistory) -> None: + """It should return a list of all commands without fixit commands.""" + assert ( + list( + command_history.get_filtered_command_ids( + command_intents=[ + CommandIntent.FIXIT, + CommandIntent.PROTOCOL, + CommandIntent.SETUP, + ] + ) + ) + == [] + ) + command_entry_1 = create_queued_command_entry() + command_entry_2 = create_queued_command_entry(index=1, intent=CommandIntent.SETUP) + fixit_command_entry_1 = create_queued_command_entry(intent=CommandIntent.FIXIT) + command_history._add("0", command_entry_1) + command_history._add("1", command_entry_2) + command_history._add("fixit-1", fixit_command_entry_1) + assert list( + command_history.get_filtered_command_ids( + command_intents=[ + CommandIntent.FIXIT, + CommandIntent.PROTOCOL, + CommandIntent.SETUP, + ] + ) + ) == ["0", "1", "fixit-1"] + + +def test_get_slice_with_filtered_list(command_history: CommandHistory) -> None: + """It should return a slice of filtered commands.""" + assert command_history.get_slice(0, 2) == [] + command_entry_1 = create_queued_command_entry() + command_entry_2 = create_queued_command_entry(index=1) + command_entry_3 = create_queued_command_entry(index=2) + command_history._add("0", command_entry_1) + command_history._add("1", command_entry_2) + command_history._add("2", command_entry_3) + filtered_list = ["0", "1"] + assert command_history.get_slice(1, 3, command_ids=filtered_list) == [ + command_entry_2.command, + ] diff --git a/api/tests/opentrons/protocol_engine/state/test_command_view_old.py b/api/tests/opentrons/protocol_engine/state/test_command_view_old.py index 9db20307dab..8ce199b5f49 100644 --- a/api/tests/opentrons/protocol_engine/state/test_command_view_old.py +++ b/api/tests/opentrons/protocol_engine/state/test_command_view_old.py @@ -1040,3 +1040,48 @@ def test_get_errors_slice() -> None: cursor=0, total_length=4, ) + + +def test_get_slice_without_fixit() -> None: + """It should select a cursor based on the running command, if present.""" + command_1 = create_succeeded_command(command_id="command-id-1") + command_2 = create_succeeded_command(command_id="command-id-2") + command_3 = create_running_command(command_id="command-id-3") + command_4 = create_queued_command(command_id="command-id-4") + command_5 = create_queued_command(command_id="command-id-5") + command_6 = create_queued_command( + command_id="fixit-id-1", intent=cmd.CommandIntent.FIXIT + ) + command_7 = create_queued_command( + command_id="fixit-id-2", intent=cmd.CommandIntent.FIXIT + ) + + subject = get_command_view( + commands=[ + command_1, + command_2, + command_3, + command_4, + command_5, + command_6, + command_7, + ], + queued_command_ids=[ + "command-id-1", + "command-id-2", + "command-id-3", + "command-id-4", + "command-id-5", + "fixit-id-1", + "fixit-id-2", + ], + queued_fixit_command_ids=["fixit-id-1", "fixit-id-2"], + ) + + result = subject.get_slice(cursor=None, length=7, include_fixit_commands=False) + + assert result == CommandSlice( + commands=[command_1, command_2, command_3, command_4, command_5], + cursor=0, + total_length=5, + ) diff --git a/robot-server/tests/runs/router/test_commands_router.py b/robot-server/tests/runs/router/test_commands_router.py index 8f19c79d3f9..e7045fe6287 100644 --- a/robot-server/tests/runs/router/test_commands_router.py +++ b/robot-server/tests/runs/router/test_commands_router.py @@ -354,7 +354,7 @@ async def test_get_run_commands( run_data_manager=mock_run_data_manager, cursor=None, pageLength=42, - includeFixitCommands=True + includeFixitCommands=True, ) assert result.content.data == [ @@ -421,7 +421,7 @@ async def test_get_run_commands_empty( run_data_manager=mock_run_data_manager, cursor=21, pageLength=42, - includeFixitCommands=True + includeFixitCommands=True, ) assert result.content.data == [] @@ -440,7 +440,8 @@ async def test_get_run_commands_not_found( decoy.when( mock_run_data_manager.get_commands_slice( run_id="run-id", cursor=21, length=42, include_fixit_commands=True - ) ).then_raise(not_found_error) + ) + ).then_raise(not_found_error) with pytest.raises(ApiError) as exc_info: await get_run_commands( @@ -448,7 +449,7 @@ async def test_get_run_commands_not_found( run_data_manager=mock_run_data_manager, cursor=21, pageLength=42, - includeFixitCommands=True + includeFixitCommands=True, ) assert exc_info.value.status_code == 404