-
Notifications
You must be signed in to change notification settings - Fork 183
fix(robot-server, api): Standardize command slice behavior #18203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1000,8 +1000,8 @@ def test_get_slice_default_cursor_failed_command() -> None: | |
result = subject.get_slice(cursor=None, length=3, include_fixit_commands=True) | ||
|
||
assert result == CommandSlice( | ||
commands=[command_3, command_4], | ||
cursor=2, | ||
commands=[command_2, command_3, command_4], | ||
cursor=1, | ||
total_length=4, | ||
) | ||
|
||
|
@@ -1022,14 +1022,14 @@ def test_get_slice_default_cursor_running() -> None: | |
result = subject.get_slice(cursor=None, length=2, include_fixit_commands=True) | ||
|
||
assert result == CommandSlice( | ||
commands=[command_3, command_4], | ||
cursor=2, | ||
commands=[command_2, command_3], | ||
cursor=1, | ||
total_length=5, | ||
) | ||
|
||
|
||
def test_get_slice_without_fixit() -> None: | ||
"""It should select a cursor based on the running command, if present.""" | ||
"""It should filter out fixit commands when requested.""" | ||
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") | ||
|
@@ -1071,3 +1071,44 @@ def test_get_slice_without_fixit() -> None: | |
cursor=0, | ||
total_length=5, | ||
) | ||
|
||
|
||
def test_get_slice_large_length() -> None: | ||
"""It should handle cases where length is larger than available commands.""" | ||
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") | ||
|
||
subject = get_command_view( | ||
commands=[command_1, command_2, command_3], | ||
running_command_id="command-id-3", | ||
) | ||
|
||
result = subject.get_slice(cursor=None, length=10, include_fixit_commands=True) | ||
|
||
assert result == CommandSlice( | ||
commands=[command_1, command_2, command_3], | ||
cursor=0, | ||
total_length=3, | ||
) | ||
|
||
|
||
def test_get_slice_explicit_cursor_with_length() -> None: | ||
"""It should use the cursor as the start position when explicitly provided.""" | ||
command_1 = create_succeeded_command(command_id="command-id-1") | ||
command_2 = create_succeeded_command(command_id="command-id-2") | ||
command_3 = create_succeeded_command(command_id="command-id-3") | ||
command_4 = create_succeeded_command(command_id="command-id-4") | ||
command_5 = create_succeeded_command(command_id="command-id-5") | ||
|
||
subject = get_command_view( | ||
commands=[command_1, command_2, command_3, command_4, command_5], | ||
) | ||
|
||
result = subject.get_slice(cursor=1, length=3, include_fixit_commands=True) | ||
|
||
assert result == CommandSlice( | ||
commands=[command_2, command_3, command_4], | ||
cursor=1, | ||
total_length=5, | ||
) | ||
Comment on lines
+1074
to
+1114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the new tests! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we wanted to do this for a while but we avoided it bc the logic was different? I dont remember why @SyntaxColoring do you remember?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is fundamentally different, at least from my testing and reading, but I've been wrong on at least a couple occasions 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the implementation again and it does seem correct. I remember wanting to do this change but there was a difference I cannot remember :-) if this was tested then should be fine.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change I am seeing is in case the last command is a failed command and the queue is empty.
We use the failed_command prop for this case, where with get_current() we loop through the command list to get the last command executed -> they will probably be the same value. also, we are looping though command ids while using get_current and queued commands in the old slice. I think this change is fine though bc the results should be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool cool, thank you for double checking!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing that was always holding me back was the behavioral changes revealed in the test diffs here. It wasn't clear to me that those changes were safe to make, with respect to client expectations. If you've audited the client and it all looks good to you, then yeah, this is great!