Files
microsoft--agent-framework/python/packages/tools/tests/test_shell_result.py
T
wehub-resource-sync db620d33df
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:25 +08:00

78 lines
2.1 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
from agent_framework_tools.shell import ShellResult
def _make(
*,
stdout: str = "",
stderr: str = "",
exit_code: int = 0,
truncated: bool = False,
timed_out: bool = False,
) -> ShellResult:
return ShellResult(
stdout=stdout,
stderr=stderr,
exit_code=exit_code,
duration_ms=1,
truncated=truncated,
timed_out=timed_out,
)
def test_format_stdout_only() -> None:
text = _make(stdout="hello").format_for_model()
assert text == "hello\nexit_code: 0"
def test_format_stdout_truncated_appends_marker() -> None:
text = _make(stdout="part", truncated=True).format_for_model()
assert "[output truncated]" in text
assert text.startswith("part")
def test_format_stderr_only_truncated_marker() -> None:
text = _make(stderr="boom", truncated=True, exit_code=1).format_for_model()
assert "[output truncated]" in text
assert "stderr: boom" in text
def test_format_truncated_with_empty_streams() -> None:
text = _make(truncated=True).format_for_model()
assert "[output truncated]" in text
assert "exit_code: 0" in text
def test_format_stderr_prefixed() -> None:
text = _make(stderr="boom", exit_code=1).format_for_model()
assert "stderr: boom" in text
assert "exit_code: 1" in text
def test_format_timed_out_marker() -> None:
text = _make(timed_out=True, exit_code=124).format_for_model()
assert "[command timed out]" in text
assert "exit_code: 124" in text
def test_format_empty_streams_still_reports_exit_code() -> None:
text = _make().format_for_model()
assert text == "exit_code: 0"
def test_format_combines_all_signals_in_order() -> None:
text = _make(
stdout="out",
stderr="err",
exit_code=2,
truncated=True,
timed_out=True,
).format_for_model()
lines = text.split("\n")
assert lines[0] == "out"
assert lines[1] == "stderr: err"
assert lines[2] == "[output truncated]"
assert lines[3] == "[command timed out]"
assert lines[4] == "exit_code: 2"