fix: make Langflow-synced flows visible (lfx volume perms, pull dedup)

This commit is contained in:
Jonas Miederer 2026-09-25 08:19:42 +02:00
parent 1326cece42
commit 95a1c1afb7
12 changed files with 5460 additions and 3859 deletions

View file

@ -37,3 +37,30 @@ def test_iter_flow_files_only_top_level_json(tmp_path):
sub.mkdir()
(sub / "c.json").write_text("{}")
assert export.iter_flow_files(tmp_path) == [tmp_path / "a.json"]
def test_find_reuse_path_matches_identical_content_first(tmp_path):
doc = {"name": "Simple Rule", "data": {"nodes": [], "edges": []}}
other = tmp_path / "other-name.json"
other.write_text(export.canonical_bytes(doc).decode())
path, identical = export.find_reuse_path(tmp_path, dict(doc))
assert (path, identical) == (other, True)
def test_find_reuse_path_matches_same_name(tmp_path):
old = {"name": "Simple Rule", "data": {"nodes": [], "edges": []}, "extra": 1}
(tmp_path / "simple_rule.json").write_text(json.dumps(old))
new = {"name": "Simple Rule", "data": {"nodes": [], "edges": []}}
path, identical = export.find_reuse_path(tmp_path, new)
assert (path, identical) == (tmp_path / "simple_rule.json", False)
def test_find_reuse_path_no_match_and_missing_dir(tmp_path):
(tmp_path / "a.json").write_text(json.dumps({"name": "Other"}))
assert export.find_reuse_path(tmp_path, {"name": "Neu"}) == (None, False)
assert export.find_reuse_path(tmp_path / "gibts-nicht", {"name": "Neu"}) == (None, False)
def test_find_reuse_path_skips_unreadable_files(tmp_path):
(tmp_path / "kaputt.json").write_text("{kein json")
assert export.find_reuse_path(tmp_path, {"name": "Neu"}) == (None, False)

View file

@ -176,6 +176,31 @@ async def test_sync_endpoint_pulls_from_langflow_then_syncs(
assert body["skipped"] == ["gehaltserh-hung"]
async def test_sync_endpoint_pull_reuses_same_named_file(
client, lfx_server, tmp_path, monkeypatch, login, override_langflow
):
"""A pulled flow seeded from simple_rule.json updates it in place
instead of duplicating it as simple-rule.json (slug drift)."""
await login()
monkeypatch.setattr(settings, "flows_dir", str(tmp_path))
_seed_dir(tmp_path) # fixture shape, name "simple_rule"
langflow_id = "44444444-5555-4666-8777-888888888888"
override_langflow(
flows=[{"id": langflow_id, "name": "simple_rule"}],
docs={langflow_id: _langflow_doc("simple_rule", langflow_id)},
)
response = await client.post("/api/flows/sync")
assert response.status_code == 200, response.text
body = response.json()
assert body["pulled"] == ["simple_rule"]
assert body["added"] == ["simple_rule"]
assert body["errors"] == {}
assert not (tmp_path / "simple-rule.json").exists()
response = await client.post("/api/flows/sync")
assert response.json()["skipped"] == ["simple_rule"]
async def test_sync_endpoint_pull_error_continues(
client, lfx_server, tmp_path, monkeypatch, login, override_langflow
):