Some checks failed
check agents / check (push) Failing after 13s
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>
111 lines
4.4 KiB
Python
111 lines
4.4 KiB
Python
"""A whole Execution through the hooks: the workflow route, the conversation route, a
|
|
Revision, and a fresh engine for every request, as if each landed on another pod."""
|
|
|
|
import pytest
|
|
|
|
import app.business_logic as hooks
|
|
from app.assembly import assemble
|
|
from app.core.deliverables import DEPENDENCY_GRAPH, DeliverableKind, PhaseId
|
|
from app.engine.fake_runtime import sample_submission
|
|
|
|
SPECIALISTS = {spec.specialist: kind for kind, spec in DEPENDENCY_GRAPH.items()}
|
|
|
|
|
|
class Samples:
|
|
"""Every Specialist submits the sample through its real tools."""
|
|
|
|
def __init__(self):
|
|
self.runs: list[str] = []
|
|
|
|
async def run(self, role, task, tools):
|
|
by_name = {tool.name: tool for tool in tools}
|
|
if "write_reply" in by_name:
|
|
return (await by_name["write_reply"].handler(text="A summary.")).outcome
|
|
self.runs.append(role.name)
|
|
kind = SPECIALISTS[role.name]
|
|
call = sample_submission(kind)
|
|
submit = by_name["submit_deliverable"]
|
|
result = await submit.handler(**call.args)
|
|
if result.outcome is None and "This review runs once" in result.message:
|
|
result = await submit.handler(**call.args)
|
|
assert result.outcome is not None, result.message
|
|
return result.outcome
|
|
|
|
|
|
@pytest.fixture
|
|
def fresh(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("EXECUTION_STORAGE_ROOT", str(tmp_path))
|
|
samples = Samples()
|
|
return samples, lambda: assemble("gcp", samples, use_scope=False, confirm_drafts=False)
|
|
|
|
|
|
async def workflow(fresh, phase, **more):
|
|
return await hooks.turn({"phase": phase.value, "conversation_id": "w1", "message": "Ingest webhooks", **more}, engine=fresh[1]())
|
|
|
|
|
|
async def test_a_workflow_runs_each_phase_in_its_own_step(fresh):
|
|
for phase in PhaseId:
|
|
reply = await workflow(fresh, phase)
|
|
assert reply["status"] == "phase_complete", reply
|
|
assert reply["phase"] == phase.value and phase.value in reply["reply"]
|
|
assert set(fresh[0].runs) == set(SPECIALISTS)
|
|
last = await hooks.turn({"phase": "complete", "conversation_id": "w1"}, engine=fresh[1]())
|
|
assert last["status"] == "completed"
|
|
|
|
|
|
async def test_a_reviewers_comments_revise_the_phase(fresh):
|
|
await workflow(fresh, PhaseId.SCOPING)
|
|
await workflow(fresh, PhaseId.REQUIREMENTS_DISCOVERY)
|
|
before = len(fresh[0].runs)
|
|
reply = await workflow(fresh, PhaseId.REQUIREMENTS_DISCOVERY, hitl_feedback="requirements: add a second region")
|
|
assert reply["status"] == "phase_complete"
|
|
assert len(fresh[0].runs) > before
|
|
|
|
|
|
async def test_a_conversation_runs_to_the_guide(fresh):
|
|
async def say(text):
|
|
return await hooks.turn({"message": text, "conversation_id": "c1"}, engine=fresh[1]())
|
|
|
|
reply = await say("Ingest webhooks")
|
|
for _ in PhaseId:
|
|
assert reply["status"] == "awaiting_approval", reply
|
|
reply = await say("approve")
|
|
assert reply["status"] == "completed"
|
|
|
|
|
|
async def test_a_sentence_never_approves(fresh):
|
|
async def say(text):
|
|
return await hooks.turn({"message": text, "conversation_id": "c2"}, engine=fresh[1]())
|
|
|
|
first = await say("Ingest webhooks")
|
|
second = await say("I would approve this if it had two regions")
|
|
assert second["status"] == "awaiting_approval"
|
|
assert "scoping" in first["reply"] and "scoping" in second["reply"]
|
|
|
|
|
|
def test_a_reply_that_did_not_come_from_a_turn_is_refused():
|
|
assert hooks.post_process({"status": "completed", "reply": "Done!"})["status"] == "failed"
|
|
|
|
|
|
def test_only_a_plain_approval_approves():
|
|
prompt = {"approval": {"phase": "scoping"}}
|
|
assert hooks._spoken_reply(prompt, "Approved.") == {"approval": {"phase": "scoping", "decision": "approve"}}
|
|
assert hooks._spoken_reply(prompt, "not approved") == {"reply": "not approved"}
|
|
|
|
|
|
@pytest.mark.parametrize("provider", ["azure", "aws"])
|
|
async def test_a_conversation_keeps_its_cloud_after_the_first_message(provider, fresh, monkeypatch):
|
|
built = []
|
|
real = hooks.assemble
|
|
|
|
def recording(name, *args, **kwargs):
|
|
built.append(name)
|
|
return real(name, fresh[0], use_scope=False, confirm_drafts=False)
|
|
|
|
monkeypatch.setattr(hooks, "assemble", recording)
|
|
first = await hooks.turn({"message": "Ingest webhooks", "conversation_id": "c9", "cloud_provider": provider})
|
|
await hooks.turn({"message": "approve", "conversation_id": "c9"})
|
|
|
|
assert first["status"] == "awaiting_approval", first
|
|
assert built == [provider, provider]
|