Use sandbox client for builder validation
All checks were successful
build / build (push) Successful in 14s

This commit is contained in:
robert
2026-06-06 20:24:38 -03:00
parent 5d03074fa4
commit 137f84be6a
11 changed files with 92 additions and 29 deletions

View File

@@ -47,7 +47,7 @@ class TemplateInitTests(unittest.TestCase):
self.assertIn("skills=skill_sources or None", files["agent.py"])
self.assertIn("ctx.llm", files["agent.py"])
self.assertIn("ctx.workspace_backend()", files["agent.py"])
self.assertIn("create_deep_agent", files["agent.py"])
self.assertIn("create_a2a_deep_agent", files["agent.py"])
self.assertIn("name: research-agent", files["a2a.yaml"])
self.assertIn("entrypoint: agent:ResearchAgent", files["a2a.yaml"])
self.assertNotIn("{{ frontend_block }}", files["a2a.yaml"])
@@ -272,6 +272,35 @@ class TemplateInitTests(unittest.TestCase):
self.assertIn("manifest_json must be a JSON object", result["error"])
def test_test_agent_in_sandbox_uses_attached_sandbox_client(self) -> None:
workspace = _FakeWorkspace()
prefix = "agents/demo-agent/"
workspace.write_bytes(prefix + "agent.py", b"print('ok')\n")
workspace.write_bytes(prefix + "a2a.yaml", b"name: demo-agent\n")
workspace.write_bytes(prefix + "requirements.txt", b"")
sandbox = _FakeSandbox()
tools = build_tools(
ToolContext(
bucket="bucket",
settings=_settings(),
workspace=workspace,
sandbox=sandbox,
grant_token="grant-token",
)
)
test_tool = _tool_by_name(tools, "test_agent_in_sandbox")
_FakeAsyncClient.posts = []
with patch("agent_builder.tools.httpx.AsyncClient", _FakeAsyncClient):
result = json.loads(
asyncio.run(test_tool.ainvoke({"name": "demo-agent"}))
)
self.assertEqual(result["exit_code"], 0)
self.assertEqual(len(sandbox.calls), 1)
self.assertEqual(sandbox.calls[0]["workspace"], "bucket")
self.assertEqual(_FakeAsyncClient.posts, [])
def test_cp_deploy_tarball_posts_agent_dsl(self) -> None:
workspace = _FakeWorkspace()
prefix = "agents/demo-agent/"
@@ -529,6 +558,21 @@ class _FakeWorkspace:
self.objects.pop(key, None)
class _FakeExecResult:
exit_code = 0
stdout = "--- card ---\n{}"
stderr = ""
class _FakeSandbox:
def __init__(self) -> None:
self.calls: list[dict[str, object]] = []
async def run_shell(self, script: str, **kwargs: object) -> _FakeExecResult:
self.calls.append({"script": script, **kwargs})
return _FakeExecResult()
def _tool_by_name(tools: list[object], name: str) -> object:
for tool in tools:
if getattr(tool, "name", None) == name: