Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ def _parse_contents_from_anthropic(
)
)
for bash_file_content in content_block.content.content:
contents.append(
shell_outputs.append(
Content.from_hosted_file(
file_id=bash_file_content.file_id,
raw_representation=bash_file_content,
Expand Down
30 changes: 30 additions & 0 deletions python/packages/anthropic/tests/test_anthropic_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4251,3 +4251,33 @@ def test_option_translations_single_stop_string_becomes_list() -> None:
options = {"stop": ["END", "STOP"]}
_apply_option_translations(options)
assert options == {"stop_sequences": ["END", "STOP"]}


def test_parse_bash_execution_result_with_files(
mock_anthropic_client: MagicMock,
) -> None:
"""Bash result files stay nested in the shell tool result outputs (#9342)."""
client = create_test_anthropic_client(mock_anthropic_client)

mock_file = MagicMock()
mock_file.file_id = "file_456"

mock_content = MagicMock()
mock_content.stdout = "Output text"
mock_content.stderr = None
mock_content.return_code = 0
mock_content.content = [mock_file]

mock_block = MagicMock()
mock_block.type = "bash_code_execution_tool_result"
mock_block.tool_use_id = "call_bash4"
mock_block.content = mock_content

result = client._parse_contents_from_anthropic([mock_block])

assert len(result) == 1
assert result[0].type == "shell_tool_result"
assert result[0].outputs is not None
hosted_files = [output for output in result[0].outputs if output.type == "hosted_file"]
assert len(hosted_files) == 1
assert hosted_files[0].file_id == "file_456"
Loading