From 07ecbaab3ab04770fd5756876b9a57dcad2a2298 Mon Sep 17 00:00:00 2001 From: stroblme Date: Fri, 16 Oct 2026 09:22:57 +0200 Subject: [PATCH] Duplicate flow: references to its own messages under its own name follow the copy --- backend/fluksio/flow/store.py | 2 ++ backend/tests/flow/test_drafts.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/fluksio/flow/store.py b/backend/fluksio/flow/store.py index 0e4aaca..006af18 100644 --- a/backend/fluksio/flow/store.py +++ b/backend/fluksio/flow/store.py @@ -699,6 +699,8 @@ class FlowStore: "origin": None, } ) + # Its own messages named with its own name are the copy's now. + self._retarget(copy, f"{name}.", f"{new_name}.") path = self._draft_file(new_name) path.parent.mkdir(parents=True) path.write_text(copy.model_dump_json(indent=2) + "\n") diff --git a/backend/tests/flow/test_drafts.py b/backend/tests/flow/test_drafts.py index 182ef47..03d7d58 100644 --- a/backend/tests/flow/test_drafts.py +++ b/backend/tests/flow/test_drafts.py @@ -184,7 +184,9 @@ def test_renaming_carries_the_draft_and_repoints_other_drafts(store: FlowStore): def test_a_duplicate_is_a_local_draft_of_what_the_editor_shows(store: FlowStore): - store.write_flow(a_flow(title="Warm").model_copy(update={"origin": FlowOrigin()})) + flow = a_flow(title="Warm").model_copy(update={"origin": FlowOrigin()}) + flow.nodes.append(NodeDef(id="reader", requires=[MessageSpec(name="heating.temp")])) + store.write_flow(flow) store.write_node_source("heating", "sensor", SOURCE) store.write_node_source("heating", "sensor", EDITED, draft=True) store.write_enabled("heating", False) @@ -193,6 +195,7 @@ def test_a_duplicate_is_a_local_draft_of_what_the_editor_shows(store: FlowStore) assert (copy.name, copy.title, copy.version) == ("heating_copy", "Warm (copy)", 1) 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()