Shared node changes rebuild the flows whose published copy uses them, not their drafts

This commit is contained in:
2026-10-14 23:34:47 +02:00
parent ef9d9824bb
commit b345587ab9
3 changed files with 35 additions and 4 deletions
+26
View File
@@ -1,9 +1,11 @@
"""Nodes shared across flows: one source, many instances."""
import asyncio
from pathlib import Path
import pytest
from fluksio.flow.controller import FlowController
from fluksio.flow.messages import MessageSpec
from fluksio.flow.schemas import FlowDef, NodeDef
from fluksio.flow.store import FlowStore, LibExists, LibNotFound
@@ -67,6 +69,30 @@ def test_a_second_flow_can_use_the_same_source(store: FlowStore):
assert store.usages("read_temp") == ["cooling.sensor", "heating.sensor"]
def test_a_shared_source_change_rebuilds_only_what_is_published(store: FlowStore):
store.write_flow(a_flow())
store.write_node_source("heating", "sensor", SOURCE)
store.share_node("heating", "sensor", "read_temp")
# Published with the shared node, which the draft has since dropped.
store.publish_flow("heating", store.read_flow("heating", draft=True).version)
store.unshare_node("heating", "sensor")
# Shared in a draft that was never published.
cooling = a_flow("cooling")
cooling.nodes[0].source_ref = "read_temp"
store.write_draft(cooling, 0)
controller = FlowController(store)
rebuilt: list[str] = []
async def reload_flow(name: str) -> None:
rebuilt.append(name)
controller.reload_flow = reload_flow # type: ignore[method-assign]
asyncio.run(controller.reload_lib_users("read_temp"))
assert rebuilt == ["heating"]
def test_a_shared_name_is_not_taken_twice(store: FlowStore):
store.write_flow(a_flow())
store.write_node_source("heating", "sensor", SOURCE)