106 lines
3.8 KiB
Python
106 lines
3.8 KiB
Python
"""An Execution's files are on disk as soon as each Deliverable is submitted.
|
|
|
|
Before this they were written only when an Execution ended, so a process that was
|
|
killed, or an Execution left waiting for its user, had nothing to show.
|
|
"""
|
|
|
|
import json
|
|
|
|
from langgraph.checkpoint.memory import InMemorySaver
|
|
|
|
from execution_engine.adk.fake_runtime import FakeAgentRuntime
|
|
from execution_engine.adk.runtime import NoDecider, RoleSpec
|
|
from execution_engine.agent import ExecutionEngine
|
|
from execution_engine.baseline import BaselineError, load_baseline
|
|
from execution_engine.nodes.execution_nodes import _write_outputs
|
|
from execution_engine.nodes.router import Router, Thresholds
|
|
from execution_engine.recorder import InMemoryRecorder
|
|
from execution_engine.states.ledger import Ledger
|
|
from tests.reference_workflow.workflow import (
|
|
DEPENDENCY_GRAPH,
|
|
WORKFLOW,
|
|
sample_submission,
|
|
)
|
|
|
|
ROLES = {
|
|
"orchestrator": RoleSpec("orchestrator", "Unused.", budget=40),
|
|
**{
|
|
spec.specialist: RoleSpec(spec.specialist, "Produce.", budget=15)
|
|
for spec in DEPENDENCY_GRAPH.values()
|
|
},
|
|
}
|
|
|
|
|
|
def folder(tmp_path, execution_id: str):
|
|
return tmp_path / "deliverables" / "cases" / "acme" / "executions" / execution_id
|
|
|
|
|
|
async def test_an_execution_waiting_for_its_user_has_written_what_exists(tmp_path):
|
|
engine = ExecutionEngine(
|
|
workflow=WORKFLOW,
|
|
runtime=FakeAgentRuntime(
|
|
{
|
|
spec.specialist: [[sample_submission(kind)]]
|
|
for kind, spec in DEPENDENCY_GRAPH.items()
|
|
}
|
|
),
|
|
roles=ROLES,
|
|
recorder=InMemoryRecorder(),
|
|
checkpointer=InMemorySaver(),
|
|
output_root=tmp_path,
|
|
orchestrator=Router(NoDecider(), None, Thresholds()),
|
|
)
|
|
|
|
waiting = await engine.start("Ingest", customer_case="acme", execution_id="v1")
|
|
|
|
# It stopped for the first Approval: only the scope has been produced.
|
|
assert waiting.status == "awaiting_user"
|
|
out = folder(tmp_path, "v1")
|
|
manifest = json.loads((out / "execution.json").read_text())
|
|
assert manifest["status"] == "in_progress"
|
|
assert set(manifest["deliverables"]) == {"scope"}
|
|
assert (out / "deliverables" / "scope.md").read_text()
|
|
assert (out / "scope.json").is_file() and (out / "scope.yaml").is_file()
|
|
assert manifest["solution_guide"] is None
|
|
# Unfinished work is never something a Change request can start from.
|
|
try:
|
|
load_baseline(tmp_path, "acme", "v1")
|
|
except BaselineError as refused:
|
|
assert "did not complete (in_progress)" in str(refused)
|
|
else:
|
|
raise AssertionError("an in-progress Execution was accepted as a Baseline")
|
|
|
|
|
|
def test_a_file_an_earlier_write_left_is_removed_with_the_revision(tmp_path):
|
|
state = {
|
|
"execution_id": "v1",
|
|
"customer_case": "acme",
|
|
"workflow_request": "Ingest",
|
|
"deliverables": {
|
|
"deployment_guidance": {
|
|
"content": "guide",
|
|
"attachments": {
|
|
"terraform/main.tf": "one",
|
|
"terraform/queue.tf": "two",
|
|
},
|
|
}
|
|
},
|
|
}
|
|
out = folder(tmp_path, "v1")
|
|
|
|
_write_outputs(tmp_path, state, "in_progress", Ledger(WORKFLOW))
|
|
assert (out / "terraform" / "queue.tf").is_file()
|
|
(out / "notes.txt").write_text("a person's own file")
|
|
|
|
# The Revision folded the queue into main.tf.
|
|
state["deliverables"]["deployment_guidance"]["attachments"] = {
|
|
"terraform/main.tf": "one and two"
|
|
}
|
|
_write_outputs(tmp_path, state, "completed", Ledger(WORKFLOW))
|
|
|
|
assert not (out / "terraform" / "queue.tf").exists()
|
|
assert (out / "terraform" / "main.tf").read_text() == "one and two"
|
|
# Only files this Execution wrote are ever removed.
|
|
assert (out / "notes.txt").is_file()
|
|
assert json.loads((out / "execution.json").read_text())["status"] == "completed"
|