Clients take a flow's id or key: one resolver in the SDK, id first, explicit id:/key:, a warning for reads and a refusal for changes when a name means two flows, deleted flows found by their last key; sync creates by POST, retries a create race through the drift checks and reports the id; MCP gets create_flow and resolves every flow argument with the caller's token; displays show flow_name; an engine from before ids is named as such

This commit is contained in:
2026-11-02 19:39:14 +01:00
parent fd637e0f1e
commit 53916d869b
20 changed files with 816 additions and 147 deletions
+71 -1
View File
@@ -3,7 +3,26 @@
import httpx
import pytest
from fluksio.sdk import SyncError
from fluksio.sdk.client import WAIT_TOLERANCE, ApiError, Client, RunHandle
from fluksio.sdk.resolve import Unresolved
#: What the engine lists: `train` under an issued id, and the grandfathered
#: `heating`, now keyed `warmth`, whose old key a later flow took.
LISTED = [
{"id": "f_train000", "name": "train"},
{"id": "heating", "name": "warmth"},
{"id": "f_heat0000", "name": "heating"},
]
def listing(request):
"""The engine's answer to the lookups a flow argument costs, else None."""
if request.url.path == "/api/v1/flows/":
return httpx.Response(200, json={"data": LISTED, "count": len(LISTED)})
if request.url.path == "/api/v1/runs/overview":
return httpx.Response(200, json=[])
return None
def a_client(handler, monkeypatch, **kwargs):
@@ -65,6 +84,9 @@ def test_submit_carries_one_key_across_its_retries(monkeypatch):
bodies = []
def handler(request):
if listed := listing(request):
return listed
assert request.url.path == "/api/v1/runs/flows/f_train000"
bodies.append(httpx.Response(200, content=request.content).json())
if len(bodies) < 3:
raise httpx.ConnectError("no route", request=request)
@@ -81,6 +103,8 @@ def test_a_sweep_keys_every_entry(monkeypatch):
seen = {}
def handler(request):
if listed := listing(request):
return listed
body = httpx.Response(200, content=request.content).json()
seen["runs"] = body["runs"]
return httpx.Response(202, json=[{"id": "r1"}, {"id": "r2"}])
@@ -137,6 +161,8 @@ def test_an_export_is_read_as_rows(monkeypatch):
seen = {}
def handler(request):
if listed := listing(request):
return listed
seen.update(request.url.params)
return httpx.Response(
200,
@@ -149,7 +175,8 @@ def test_an_export_is_read_as_rows(monkeypatch):
assert seen["format"] == "jsonl"
assert seen["ids"] == "r1,r2"
assert seen["flow"] == "train"
# The key, resolved: the API takes the id and only the id.
assert seen["flow"] == "f_train000"
assert seen["status"] == "ok"
assert [row["step"] for row in rows] == [0, 1]
@@ -201,3 +228,46 @@ def test_a_name_cannot_climb_out_of_its_route(monkeypatch):
"/api/v1/flows/%2E%2E/nodes/%2E%2E%2Fx/source",
"/api/v1/runs/%2E%2E",
]
def test_a_flow_argument_goes_through_the_resolver(monkeypatch):
"""A read of a name two flows answer to warns; a run of it is refused."""
asked = []
def handler(request):
if listed := listing(request):
return listed
asked.append(
f"{request.method} {request.url.path}?{request.url.query.decode()}"
)
return httpx.Response(200, json=[])
client = a_client(handler, monkeypatch)
with pytest.warns(UserWarning, match="Pass key:heating for the other"):
client.runs(flow="heating")
with pytest.raises(Unresolved, match="Pass id:heating or key:heating"):
client.submit("heating")
client.runs(flow="key:heating")
assert asked == [
"GET /api/v1/runs?limit=20&flow=heating",
"GET /api/v1/runs?limit=20&flow=f_heat0000",
]
def test_an_engine_from_before_ids_is_named_as_such(monkeypatch):
"""It lists flows without ids and has no route to create one by."""
def handler(request):
if request.method == "POST":
return httpx.Response(405, json={"detail": "Method Not Allowed"})
return httpx.Response(200, json={"data": [{"name": "train"}], "count": 1})
client = a_client(handler, monkeypatch)
for call in (
lambda: client.runs(flow="train"),
lambda: client.find_flow("train"),
lambda: client.create_flow({"name": "train"}),
):
with pytest.raises(SyncError, match="older than flow ids"):
call()