generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 70
feat: add end to end integration test #30
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
JackYPCOnline
merged 19 commits into
strands-agents:main
from
JackYPCOnline:integration-test
Aug 15, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
74e8464
feat: add end to end integration test
JackYPCOnline 6910700
Merge branch 'strands-agents:main' into integration-test
JackYPCOnline 42656ba
feat: add integration tests for the package
JackYPCOnline f24b8fe
feat: remove old test
JackYPCOnline b4d3cfc
refactor: refactor the test code with patch api instead of monkeypatch
JackYPCOnline 991e70d
feat: add STRANDS_ANTHROPIC_BETA environment variable (#34)
awsarron a4fed3c
Windows: Remove cron tool + document missing tools when on windows (#33)
zastrowm 88c305d
udpate agent system_prompt reference (#35)
Unshure 2eff5dc
chore: explicitly set load_tools_from_directory on Agent initilizatio…
dbschmigelski 68e2c50
Update builder with updates from 0.3.0 SDK (#39)
zastrowm 577e9f0
chore: Remove Preview (#40)
yonib05 ac7d801
deps: bump strangs-agents to v1.0.0 (#41)
jer96 e30a6e9
build(pyproject): update development status classifier (#42)
awsarron 0702a52
Use strands logo that looks good in dark & light mode (#44)
zastrowm 09a19a9
fix: refactor some tests
JackYPCOnline 0dd5163
Merge branch 'strands-agents:main' into integration-test
JackYPCOnline b0c5f7e
fix: refactor tests code
JackYPCOnline c149f5b
fix: make tests more accurate
JackYPCOnline 629e722
fix: remove test_custom_load_from_file to avoiding text based respons…
JackYPCOnline 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
Empty file.
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
Empty file.
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| """Common fixtures for integration tests.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def tmp_file_structure(tmp_path: Path): | ||
| """Creates a temporary directory structure for tool creation and returns paths.""" | ||
| tools_dir = tmp_path / ".strands" / "tools" | ||
| tools_dir.mkdir(parents=True, exist_ok=True) | ||
| return {"tools_dir": tools_dir, "root_dir": tmp_path} |
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import sys | ||
| from unittest import mock | ||
|
|
||
| from strands import Agent | ||
|
|
||
| from strands_agents_builder import strands | ||
|
|
||
|
|
||
| def test_build_agent_from_specification_file(): | ||
| """Test building agent from specification using semantic creation.""" | ||
|
|
||
| # Agent specification content | ||
| spec_content = """Agent Specification: | ||
| - Role: Math Tutor Agent | ||
| - Purpose: Help students with basic arithmetic and algebra | ||
| - Tools needed: calculator, file_read, current_time | ||
| - Create specialized tools for math tutoring | ||
| """ | ||
|
|
||
| # Simulate: cat agent-spec.txt | strands "Build a specialized agent based on these specifications" | ||
| query = f"Build a specialized agent based on these specifications:\n\n{spec_content}" | ||
|
|
||
| with mock.patch.object(sys, "argv", ["strands", query]): | ||
| strands.main() | ||
|
|
||
| # Validate agent | ||
| agent = Agent( | ||
| load_tools_from_directory=True, | ||
| callback_handler=None, | ||
| ) | ||
|
|
||
| # Validate agent was created successfully | ||
| assert agent is not None | ||
|
|
||
| # Validate agent has exactly 3 specified tools | ||
| required_tools = ["calculator", "file_read", "current_time"] | ||
| for tool_name in required_tools: | ||
| assert hasattr(agent.tool, tool_name), f"Agent missing required tool: {tool_name}" | ||
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import sys | ||
| from unittest import mock | ||
|
|
||
| from strands.agent import Agent | ||
|
|
||
| from strands_agents_builder import strands | ||
|
|
||
|
|
||
| @mock.patch("strands_tools.utils.user_input.get_user_input", return_value="y") | ||
| @mock.patch.dict("os.environ", {"STRANDS_TOOL_CONSOLE_MODE": "enabled"}) | ||
| def test_interactive_model_create_tool_then_validate(mock_get_user_input, capsys, tmp_file_structure): | ||
| """ | ||
| Test creating a calculator tool via CLI and validating its functionality. | ||
| """ | ||
| with mock.patch.dict("os.environ", {"STRANDS_TOOLS_DIR": str(tmp_file_structure["tools_dir"])}): | ||
| test_query = "create a tool that can only calculate sum of two number called calculator" | ||
|
|
||
| with mock.patch.object(sys, "argv", ["strands", test_query]): | ||
| strands.main() | ||
|
|
||
| agent = Agent( | ||
| load_tools_from_directory=True, | ||
| ) | ||
|
|
||
| # assert agent has a tool called calculator | ||
| assert hasattr(agent.tool, "calculator"), "Agent should have a 'calculator' tool after creation." | ||
|
|
||
| test_cases = [("what is 1 plus 2?", "3"), ("calculate 5 plus 7", "12")] | ||
|
|
||
| for question, expected in test_cases: | ||
| response = agent(question) | ||
| response_str = str(response).lower() | ||
| assert expected in response_str, f"Expected '{expected}' in response for '{question}', got '{response_str}'" | ||
|
|
||
| # Verify the calculator tool was actually used by checking for toolResults | ||
| calculator_used = any( | ||
JackYPCOnline marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| content.get("toolUse", {}).get("name") == "calculator" | ||
| for message in agent.messages | ||
| for content in message.get("content", []) | ||
| if content.get("toolUse") | ||
| ) | ||
| assert calculator_used, f"Calculator tool should have been used for question: '{question}'" | ||
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from unittest import mock | ||
|
|
||
| from strands_agents_builder import strands | ||
|
|
||
|
|
||
| @mock.patch.object(strands, "get_user_input") | ||
| @mock.patch.dict("os.environ", {"STRANDS_TOOL_CONSOLE_MODE": "enabled"}) | ||
| def test_cli_shell_and_interactive_mode(mock_user_input, capsys): | ||
| """Test interactive mode with a shell command.""" | ||
|
|
||
| user_inputs = ["!echo hello", "exit"] | ||
| mock_user_input.side_effect = user_inputs | ||
|
|
||
| strands.main() | ||
| out = capsys.readouterr().out | ||
|
|
||
| assert "hello" in out, "Expected 'hello' (from echo) in output" | ||
| assert "thank you for using strands" in out.lower(), "Expected exit message" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.