Files
orchestration_engine/tests/execution/test_file_arguments.py

79 lines
2.6 KiB
Python

"""Files cross tool calls as a list of {path, content}: models rewrite object keys."""
import pytest
from execution_engine.adk.runtime import FILES_SCHEMA, Submitted, files_from_argument
from execution_engine.tools.execution import specialist_tools
from tests.reference_workflow.local import TerraformRunner, local_tools
from tests.reference_workflow.workflow import WORKFLOW, 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(
WORKFLOW, 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(
WORKFLOW, 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"}