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
+16 -13
View File
@@ -8,7 +8,8 @@ import pytest
from fluksio.flow.controller import FlowController
from fluksio.flow.messages import MessageSpec
from fluksio.flow.schemas import FlowDef, FlowOrigin, NodeDef
from fluksio.flow.store import FlowStore, StaleVersion
from fluksio.flow.store import ISSUED_ID, FlowStore, StaleVersion
from tests.utils.stores import created
SOURCE = "def process():\n return {}\n"
EDITED = "def process():\n return {'temp': 1}\n"
@@ -28,7 +29,7 @@ def a_flow(title: str = "") -> FlowDef:
def test_a_draft_is_invisible_to_the_engine(store: FlowStore):
store.write_draft(a_flow(), 0)
created(store, a_flow())
assert store.has_draft("heating")
assert store.list_flows() == ["heating"] # the editor sees it
@@ -36,7 +37,7 @@ def test_a_draft_is_invisible_to_the_engine(store: FlowStore):
def test_the_version_counter_advances_per_save(store: FlowStore):
first = store.write_draft(a_flow(), 0)
first = created(store, a_flow())
assert first.version == 1
second = store.write_draft(a_flow(title="Warm"), first.version)
@@ -44,14 +45,14 @@ def test_the_version_counter_advances_per_save(store: FlowStore):
def test_resaving_identical_content_neither_bumps_nor_commits(store: FlowStore):
stored = store.write_draft(a_flow(), 0)
stored = created(store, a_flow())
again = store.write_draft(a_flow(), stored.version)
assert again.version == stored.version
def test_a_stale_write_is_refused(store: FlowStore):
store.write_draft(a_flow(), 0)
created(store, a_flow())
store.write_draft(a_flow(title="Mine"), 1)
# A second client still holding version 1 must not overwrite version 2.
@@ -61,7 +62,7 @@ def test_a_stale_write_is_refused(store: FlowStore):
def test_publishing_promotes_the_draft_and_its_sources(store: FlowStore):
stored = store.write_draft(a_flow(title="Warm"), 0)
stored = created(store, a_flow(title="Warm"))
store.write_node_source("heating", "sensor", EDITED, draft=True)
published = store.publish_flow("heating", stored.version)
@@ -74,7 +75,7 @@ def test_publishing_promotes_the_draft_and_its_sources(store: FlowStore):
def test_publishing_a_stale_draft_is_refused(store: FlowStore):
store.write_draft(a_flow(), 0)
created(store, a_flow())
with pytest.raises(StaleVersion):
store.publish_flow("heating", 99)
@@ -150,7 +151,7 @@ def test_a_worker_on_a_node_without_code_is_reported(store: FlowStore):
def test_a_node_being_written_in_the_editor_is_not_reported(store: FlowStore):
"""A draft legitimately has no published body yet — that is what a draft is."""
store.write_draft(a_flow(), 0)
created(store, a_flow())
controller = FlowController(store)
assert controller.preview("heating").issues == []
@@ -175,12 +176,14 @@ def test_a_duplicate_is_a_local_draft_of_what_the_editor_shows(store: FlowStore)
copy = store.duplicate_flow("heating")
assert (copy.name, copy.title, copy.version) == ("heating_copy", "Warm (copy)", 1)
# An id of its own, which its key is not.
assert ISSUED_ID.fullmatch(copy.id)
assert copy.origin is None
assert copy.nodes[1].requires[0].name == "heating_copy.temp"
assert store.has_draft("heating_copy") and not store.is_published("heating_copy")
assert store.read_node_source("heating_copy", "sensor", draft=True) == EDITED
assert not (store.root / "heating_copy" / "runtime.json").exists()
assert store.has_draft(copy.id) and not store.is_published(copy.id)
assert store.read_node_source(copy.id, "sensor", draft=True) == EDITED
assert not (store.root / copy.id / "runtime.json").exists()
assert store.duplicate_flow("heating").name == "heating_copy_2"
store.publish_flow("heating_copy", copy.version)
assert store.read_node_source("heating_copy", "sensor") == EDITED
store.publish_flow(copy.id, copy.version)
assert store.read_node_source(copy.id, "sensor") == EDITED