refactor: finish declutter - test_flow removal, NOT NULL schema, parametrized tests, smoke harness, docs

This commit is contained in:
Jonas Miederer 2026-10-01 00:11:43 +02:00
parent 696db34c90
commit 92bb3bacba
23 changed files with 552 additions and 1261 deletions

View file

@ -136,73 +136,78 @@ async def test_sync_endpoint_returns_report(
assert response.json()["skipped"] == ["simple_rule"]
async def test_sync_endpoint_pulls_from_langflow_then_syncs(
client, lfx_server, tmp_path, monkeypatch, login, override_langflow
@pytest.mark.parametrize(
("seed", "flow_name", "flow_id", "extra_flows", "extra_docs", "expected_file"),
[
(
None,
"Gehaltserhöhung",
"22222222-3333-4444-8555-666666666666",
[],
{},
"Gehaltserhöhung.json",
),
(
# Seeded from simple_rule.json: updates in place instead of
# duplicating as simple-rule.json (slug drift).
"simple_rule.json",
"simple_rule",
"44444444-5555-4666-8777-888888888888",
[],
{},
"simple_rule.json",
),
(
None,
"Gut",
"33333333-4444-4555-8666-777777777777",
[{"id": "kaputt-id", "name": "Kaputt"}],
{},
"Gut.json",
),
],
ids=["pull-new", "pull-reuse", "pull-error-continues"],
)
async def test_sync_endpoint_pull_matrix(
client,
lfx_server,
tmp_path,
monkeypatch,
login,
override_langflow,
seed,
flow_name,
flow_id,
extra_flows,
extra_docs,
expected_file,
):
await login()
monkeypatch.setattr(settings, "flows_dir", str(tmp_path))
langflow_id = "22222222-3333-4444-8555-666666666666"
if seed is not None:
_seed_dir(tmp_path, seed)
override_langflow(
flows=[{"id": langflow_id, "name": "Gehaltserhöhung"}],
docs={langflow_id: langflow_export_doc("Gehaltserhöhung", langflow_id)},
flows=[{"id": flow_id, "name": flow_name}, *extra_flows],
docs={flow_id: langflow_export_doc(flow_name, flow_id), **extra_docs},
)
response = await client.post("/api/flows/sync")
assert response.status_code == 200, response.text
body = response.json()
assert body["pulled"] == ["Gehaltserhöhung"]
assert body["added"] == ["Gehaltserhöhung"]
assert body["errors"] == {}
assert (tmp_path / "Gehaltserhöhung.json").is_file()
assert body["pulled"] == [flow_name]
assert body["added"] == [flow_name]
assert (tmp_path / expected_file).is_file()
if flow_name == "Gut":
assert "kaputt-id" in body["errors"]
else:
assert body["errors"] == {}
assert not (tmp_path / "simple-rule.json").exists()
# Second pass: same content pulls again but syncs nothing new.
response = await client.post("/api/flows/sync")
assert response.status_code == 200, response.text
body = response.json()
assert body["pulled"] == ["Gehaltserhöhung"]
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_export_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
):
await login()
monkeypatch.setattr(settings, "flows_dir", str(tmp_path))
good_id = "33333333-4444-4555-8666-777777777777"
override_langflow(
flows=[{"id": good_id, "name": "Gut"}, {"id": "kaputt-id", "name": "Kaputt"}],
docs={good_id: langflow_export_doc("Gut", good_id)},
)
response = await client.post("/api/flows/sync")
assert response.status_code == 200, response.text
body = response.json()
assert body["pulled"] == ["Gut"]
assert body["added"] == ["Gut"]
assert "kaputt-id" in body["errors"]
assert body["pulled"] == [flow_name]
assert body["skipped"] == [flow_name]
@pytest.mark.parametrize(