Files
cp1-agents/outcome-pattern/solution_architecture/cp1-solution-architecture-agent/tests/engine/test_file_arguments.py
Jonathan Boniface bc84ee4df6
Some checks failed
check agents / check (push) Failing after 13s
Solution architecture outcome pattern: agent and its MCP servers
The cp1-solution-architecture-agent and the sa-aws/azure/gcp-cloud MCP servers, a separate
stream from the individual and sub-agent patterns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 22:13:25 +00:00

79 lines
2.5 KiB
Python

"""Files cross tool calls as a list of {path, content}: models rewrite object keys."""
import pytest
from app.engine.runtime import FILES_SCHEMA, Submitted, files_from_argument
from app.engine.toolbox import specialist_tools
from app.engine.local import TerraformRunner, local_tools
from app.core.deliverables import DeliverableKind
GUIDANCE = (
"# Deployment prerequisites\n\nx\n\n# Step-by-step deployment instructions\n\ny\n"
)
def test_files_are_offered_as_a_list_of_path_and_content():
assert FILES_SCHEMA["type"] == "array"
assert FILES_SCHEMA["items"]["required"] == ["path", "content"]
def test_file_arguments_accept_lists_and_maps():
as_list = [{"path": "terraform/main.tf", "content": "a"}]
assert files_from_argument(as_list) == {"terraform/main.tf": "a"}
assert files_from_argument({"terraform/main.tf": "a"}) == {"terraform/main.tf": "a"}
assert files_from_argument(None) == {}
with pytest.raises(TypeError):
files_from_argument(["terraform/main.tf"])
async def test_submission_takes_attachments_as_a_list():
submit = specialist_tools(
DeliverableKind.DEPLOYMENT_GUIDANCE, extra=[], allow_cloud_read=False
)[0]
result = await submit.handler(
content=GUIDANCE,
attachments=[
{"path": "terraform/main.tf", "content": "resource {}"},
{"path": "terraform/variables.tf", "content": "variable {}"},
{"path": "implementation.json", "content": "[]"},
],
)
assert result.outcome == Submitted(
GUIDANCE,
{
"terraform/main.tf": "resource {}",
"terraform/variables.tf": "variable {}",
"implementation.json": "[]",
},
)
async def test_malformed_attachments_are_refused_to_the_agent():
submit = specialist_tools(
DeliverableKind.DEPLOYMENT_GUIDANCE, extra=[], allow_cloud_read=False
)[0]
result = await submit.handler(content=GUIDANCE, attachments=["terraform/main.tf"])
assert result.outcome is None
assert result.message.startswith("Refused: attachments")
async def test_terraform_tools_take_files_as_a_list():
received = {}
class Runner(TerraformRunner):
async def validate(self, files):
received.update(files)
return await super().validate({})
(validate,) = local_tools(["terraform_validate"], Runner())
await validate.handler(files=[{"path": "terraform/main.tf", "content": "x"}])
assert validate.parameters["properties"]["files"]["type"] == "array"
assert received == {"terraform/main.tf": "x"}