Flows and dashboards are created by POST under an issued or superuser-pinned id; PUT only updates; deleted flows leave a tombstone with their key; the controller stores by id and runs by key, hooks live under /hooks/<flow id>; a key with state or queued work behind it is refused until cleared

This commit is contained in:
2026-11-02 17:41:23 +01:00
parent fae85f5ecb
commit 08a6376836
63 changed files with 2832 additions and 936 deletions
+25 -15
View File
@@ -38,6 +38,13 @@ def api(client: TestClient, superuser_token_headers: dict[str, str]) -> Client:
return Client(http=client, token=superuser_token_headers["Authorization"][7:])
def flow_id(api: Client, key: str) -> str:
"""The id sync stored the flow with key *key* under."""
found = api.find_flow(key)
assert found is not None, key
return str(found["id"])
def commits() -> int:
"""How many commits the flow store has made."""
from fluksio.flow.store import FlowStore
@@ -62,14 +69,14 @@ def test_sync_stores_a_runnable_flow_with_its_origin(api, flows):
assert [r.flow for r in reports] == ["train"]
assert reports[0].created and reports[0].published
stored = api.get_flow("train")
stored = api.get_flow(flow_id(api, "train"))
definition = stored["definition"]
assert definition["origin"]["commit"] == "a1b2c3d4"
assert [n["id"] for n in definition["nodes"]] == ["prepare", "fit", "evaluate"]
assert not stored["has_draft"]
# The store holds a complete definition, and the bodies say where the real
# code is rather than being a copy of it.
source = api.get_source("train", "fit")
source = api.get_source(definition["id"], "fit")
assert source.startswith(MARKER)
assert "from myresearch.train import fit" in source
@@ -79,7 +86,7 @@ def test_a_flow_read_by_another_process_syncs_as_the_flow_does(api, flows):
carried = Declared(flows["train"].declaration())
sync([carried], api, origin=ORIGIN)
stored = api.get_flow("train")["definition"]
stored = api.get_flow(flow_id(api, "train"))["definition"]
assert stored["origin"]["declared_in"] == "myresearch/pipeline.py"
# Nothing differs from what the flow itself would have stored.
@@ -90,7 +97,8 @@ def test_a_node_carries_the_modules_its_code_reaches(api, flows):
"""The shim names one function; the cache has to key on what it calls."""
sync([flows["train"]], api, origin=ORIGIN)
nodes = {n["id"]: n for n in api.get_flow("train")["definition"]["nodes"]}
definition = api.get_flow(flow_id(api, "train"))["definition"]
nodes = {n["id"]: n for n in definition["nodes"]}
files = nodes["fit"]["code_files"]
# The module the function is in, and the package whose `__init__` runs on
@@ -156,14 +164,15 @@ def test_a_second_sync_changes_nothing_and_commits_nothing(api, flows):
def test_sync_refuses_to_overwrite_a_canvas_edit(api, flows):
sync([flows["train"]], api, origin=ORIGIN)
api.put_source("train", "evaluate", "def process(weights):\n return {}\n")
train = flow_id(api, "train")
api.put_source(train, "evaluate", "def process(weights):\n return {}\n")
with pytest.raises(SyncError, match="edited on the canvas"):
sync([flows["train"]], api, origin=ORIGIN)
reports = sync([flows["train"]], api, origin=ORIGIN, force=True)
assert "evaluate" in reports[0].changed
assert api.get_source("train", "evaluate").startswith(MARKER)
assert api.get_source(train, "evaluate").startswith(MARKER)
def test_an_interrupted_sync_finishes_on_the_next_one(api, flows):
@@ -177,23 +186,23 @@ def test_an_interrupted_sync_finishes_on_the_next_one(api, flows):
target = flows["train"]
target.name = "resumed"
try:
# Exactly what the document PUT leaves behind before any body is written.
api.put_flow(target.document(ORIGIN) | {"version": 1})
assert api.get_source_entry("resumed", "fit")["missing"]
# Exactly what creating the document leaves before any body is written.
resumed = api.create_flow(target.document(ORIGIN))["definition"]["id"]
assert api.get_source_entry(resumed, "fit")["missing"]
reports = sync([target], api, origin=ORIGIN)
assert "fit" in reports[0].changed
assert api.get_source("resumed", "fit").startswith(MARKER)
assert not api.get_source_entry("resumed", "fit")["missing"]
assert not api.get_flow("resumed")["has_draft"]
assert api.get_source(resumed, "fit").startswith(MARKER)
assert not api.get_source_entry(resumed, "fit")["missing"]
assert not api.get_flow(resumed)["has_draft"]
finally:
target.name = "train"
def test_sync_refuses_a_flow_it_did_not_create(api, flows):
api.put_flow({"name": "drawn", "version": 1, "nodes": [], "mode": "batch"})
api.publish("drawn", 1)
drawn = api.create_flow({"name": "drawn", "nodes": [], "mode": "batch"})
api.publish(drawn["definition"]["id"], 1)
theirs = flows["train"]
theirs.name = "drawn"
@@ -207,7 +216,8 @@ def test_sync_refuses_a_flow_it_did_not_create(api, flows):
def test_use_stores_the_rewiring_it_was_given(api, flows):
sync([flows["finetune"]], api, origin=ORIGIN)
nodes = {n["id"]: n for n in api.get_flow("finetune")["definition"]["nodes"]}
definition = api.get_flow(flow_id(api, "finetune"))["definition"]
nodes = {n["id"]: n for n in definition["nodes"]}
assert [p["name"] for p in nodes["fit"]["requires"]] == ["augmented", "lr"]
assert nodes["fit"]["params"] == {"epochs": 3}