Test running a command in the background.
()
| 66 | |
| 67 | @pytest.mark.asyncio |
| 68 | async def test_background_command(): |
| 69 | """Test running a command in the background.""" |
| 70 | print("\n=== Testing Background Command ===") |
| 71 | |
| 72 | bash_tool = BashTool() |
| 73 | result = await bash_tool.execute( |
| 74 | command="for i in 1 2 3; do echo 'Line '$i; sleep 0.5; done", run_in_background=True |
| 75 | ) |
| 76 | |
| 77 | assert result.success |
| 78 | assert result.bash_id is not None |
| 79 | assert "Background command started" in result.stdout |
| 80 | |
| 81 | bash_id = result.bash_id |
| 82 | print(f"Background command started with ID: {bash_id}") |
| 83 | |
| 84 | # Wait a bit for output |
| 85 | await asyncio.sleep(1) |
| 86 | |
| 87 | # Check output |
| 88 | bash_output_tool = BashOutputTool() |
| 89 | output_result = await bash_output_tool.execute(bash_id=bash_id) |
| 90 | |
| 91 | assert output_result.success |
| 92 | print(f"Output:\n{output_result.content}") |
| 93 | |
| 94 | # Clean up - terminate the background process |
| 95 | bash_kill_tool = BashKillTool() |
| 96 | kill_result = await bash_kill_tool.execute(bash_id=bash_id) |
| 97 | assert kill_result.success |
| 98 | print("Background process terminated") |
| 99 | |
| 100 | |
| 101 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected