A task that already has sub_tasks refuses re-distribution 🟥

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-07 12:04:05 +00:00
parent 9031c16ba7
commit dade7a3a5f

View file

@ -83,6 +83,37 @@ def api(db_engine: Engine) -> Api:
return harness
def _trigger(api: Api, task: Task, scenario_ids: list[int]) -> Any:
return api.client.post(
"/v1/modelling/trigger-run",
json={
"task_id": str(task.id),
"portfolio_id": PORTFOLIO_ID,
"scenario_ids": scenario_ids,
"filters": {},
},
)
def test_trigger_run_rejects_a_task_that_already_has_subtasks(api: Api) -> None:
"""A blind retry or double-submit must not double the fan-out (ADR-0055):
the app checks the task's progress instead of re-POSTing."""
# arrange — a task that has already been distributed
task = api.seed_task()
scenario = api.seed_scenario()
api.seed_property()
assert _trigger(api, task, [scenario]).status_code == 202
already_sent = len(api.sent_bodies)
# act
response = _trigger(api, task, [scenario])
# assert — refused, nothing new created or sent
assert response.status_code == 409
assert len(api.sent_bodies) == already_sent
assert len(api.subtasks_for(task)) == 1
def test_trigger_run_fans_out_one_subtask_and_message_per_scenario_batch(
api: Api,
) -> None: