feat: add remote workflow lifecycle rpc methods
This commit is contained in:
@@ -211,6 +211,124 @@ def test_rpc_draft_artifact_deployment_lifecycle(tmp_path) -> None:
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_rpc_artifact_and_deployment_catalog_methods(tmp_path) -> None:
|
||||
async def scenario() -> None:
|
||||
server = build_local_static_workflow_server(tmp_path / "store")
|
||||
await server.api.create_artifact_from_plan(
|
||||
artifact_id="rpc_lifecycle",
|
||||
version=1,
|
||||
title="RPC Lifecycle",
|
||||
plan=_constant_plan(),
|
||||
outcomes=["ok"],
|
||||
source_bindings={"wf.std": "wf.std"},
|
||||
)
|
||||
await server.api.save_deployment(
|
||||
{
|
||||
"id": "rpc_lifecycle.default",
|
||||
"artifact_id": "rpc_lifecycle",
|
||||
"artifact_version": 1,
|
||||
"bindings": [{"logical_source": "wf.std", "concrete_source": "wf.std"}],
|
||||
}
|
||||
)
|
||||
|
||||
app = create_rpc_app(server)
|
||||
transport = httpx.ASGITransport(app=app)
|
||||
async with httpx.AsyncClient(
|
||||
transport=transport, base_url="http://test"
|
||||
) as client:
|
||||
listed_artifacts = await _rpc(client, "workflow.artifacts.list", {})
|
||||
inspected_artifact = await _rpc(
|
||||
client,
|
||||
"workflow.artifacts.inspect",
|
||||
{"artifact_id": "rpc_lifecycle", "version": 1},
|
||||
)
|
||||
listed_deployments = await _rpc(client, "workflow.deployments.list", {})
|
||||
inspected_deployment = await _rpc(
|
||||
client,
|
||||
"workflow.deployments.inspect",
|
||||
{"deployment_id": "rpc_lifecycle.default"},
|
||||
)
|
||||
deleted = await _rpc(
|
||||
client,
|
||||
"workflow.deployments.delete",
|
||||
{"deployment_id": "rpc_lifecycle.default"},
|
||||
)
|
||||
|
||||
assert listed_artifacts["result"]["nodes"]
|
||||
assert inspected_artifact["result"]["id"] == "rpc_lifecycle"
|
||||
assert listed_deployments["result"]["deployments"]
|
||||
assert inspected_deployment["result"]["id"] == "rpc_lifecycle.default"
|
||||
assert deleted["result"]["deployment_id"] == "rpc_lifecycle.default"
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_rpc_draft_workspace_methods(tmp_path) -> None:
|
||||
async def scenario() -> None:
|
||||
server = build_local_static_workflow_server(tmp_path / "store")
|
||||
app = create_rpc_app(server)
|
||||
transport = httpx.ASGITransport(app=app)
|
||||
async with httpx.AsyncClient(
|
||||
transport=transport, base_url="http://test"
|
||||
) as client:
|
||||
created = await _rpc(
|
||||
client,
|
||||
"workflow.draft_workspaces.create_from_capability",
|
||||
{
|
||||
"workspace_id": "remote_ws",
|
||||
"capability_name": "wf.std.constant",
|
||||
"name": "remote_constant",
|
||||
"title": "Remote Constant",
|
||||
"input_map": {},
|
||||
"output_map": {"value": "state.result"},
|
||||
},
|
||||
)
|
||||
listed = await _rpc(client, "workflow.draft_workspaces.list", {})
|
||||
fetched = await _rpc(
|
||||
client,
|
||||
"workflow.draft_workspaces.get",
|
||||
{"workspace_id": "remote_ws"},
|
||||
)
|
||||
validated = await _rpc(
|
||||
client,
|
||||
"workflow.draft_workspaces.validate",
|
||||
{"workspace_id": "remote_ws"},
|
||||
)
|
||||
patched = await _rpc(
|
||||
client,
|
||||
"workflow.draft_workspaces.patch",
|
||||
{
|
||||
"workspace_id": "remote_ws",
|
||||
"revision": created["result"]["revision"],
|
||||
"patch": [
|
||||
{"op": "replace", "path": "/name", "value": "remote_renamed"}
|
||||
],
|
||||
},
|
||||
)
|
||||
artifact = await _rpc(
|
||||
client,
|
||||
"workflow.draft_workspaces.create_artifact",
|
||||
{
|
||||
"workspace_id": "remote_ws",
|
||||
"artifact_id": "remote_artifact",
|
||||
"version": 1,
|
||||
"title": "Remote Artifact",
|
||||
"outcomes": ["ok"],
|
||||
"kind": "workflow",
|
||||
"source_bindings": {"wf.std": "wf.std"},
|
||||
},
|
||||
)
|
||||
|
||||
assert created["result"]["workspace_id"] == "remote_ws"
|
||||
assert listed["result"]["workspaces"]
|
||||
assert fetched["result"]["workspace_id"] == "remote_ws"
|
||||
assert validated["result"]["status"] in {"valid", "invalid"}
|
||||
assert patched["result"]["revision"] == created["result"]["revision"] + 1
|
||||
assert artifact["result"]["artifact_id"] == "remote_artifact"
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def _constant_plan() -> RawWorkflowPlan:
|
||||
return RawWorkflowPlan.model_validate(
|
||||
{
|
||||
|
||||
@@ -157,3 +157,128 @@ def test_rpc_workflow_client_raises_for_rpc_error(tmp_path) -> None:
|
||||
assert "missing.capability" in message
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_rpc_workflow_client_lists_and_inspects_artifacts(tmp_path) -> None:
|
||||
async def scenario() -> None:
|
||||
server = build_local_static_workflow_server(tmp_path / "store")
|
||||
await server.api.create_artifact_from_plan(
|
||||
artifact_id="client_art",
|
||||
version=1,
|
||||
title="Client Art",
|
||||
plan=_constant_plan(),
|
||||
outcomes=["ok"],
|
||||
source_bindings={"wf.std": "wf.std"},
|
||||
)
|
||||
app = create_rpc_app(server)
|
||||
transport = httpx.ASGITransport(app=app)
|
||||
async with httpx.AsyncClient(
|
||||
transport=transport, base_url="http://test"
|
||||
) as http_client:
|
||||
client = RpcWorkflowApiClient(
|
||||
url="http://test/rpc", timeout_seconds=5, http_client=http_client
|
||||
)
|
||||
listed = await client.list_artifacts()
|
||||
inspected = await client.inspect_artifact(
|
||||
artifact_id="client_art", version=1
|
||||
)
|
||||
|
||||
assert listed["nodes"]
|
||||
assert inspected["id"] == "client_art"
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_rpc_workflow_client_lists_inspects_validates_and_deletes_deployments(
|
||||
tmp_path,
|
||||
) -> None:
|
||||
async def scenario() -> None:
|
||||
server = build_local_static_workflow_server(tmp_path / "store")
|
||||
await server.api.create_artifact_from_plan(
|
||||
artifact_id="client_deploy_art",
|
||||
version=1,
|
||||
title="Client Deploy Art",
|
||||
plan=_constant_plan(),
|
||||
outcomes=["ok"],
|
||||
source_bindings={"wf.std": "wf.std"},
|
||||
)
|
||||
await server.api.save_deployment(
|
||||
{
|
||||
"id": "client_deploy_art.default",
|
||||
"artifact_id": "client_deploy_art",
|
||||
"artifact_version": 1,
|
||||
"bindings": [{"logical_source": "wf.std", "concrete_source": "wf.std"}],
|
||||
}
|
||||
)
|
||||
app = create_rpc_app(server)
|
||||
transport = httpx.ASGITransport(app=app)
|
||||
async with httpx.AsyncClient(
|
||||
transport=transport, base_url="http://test"
|
||||
) as http_client:
|
||||
client = RpcWorkflowApiClient(
|
||||
url="http://test/rpc", timeout_seconds=5, http_client=http_client
|
||||
)
|
||||
listed = await client.list_deployments()
|
||||
inspected = await client.inspect_deployment(
|
||||
deployment_id="client_deploy_art.default"
|
||||
)
|
||||
validated = await client.validate_deployment(
|
||||
deployment_id="client_deploy_art.default"
|
||||
)
|
||||
deleted = await client.delete_deployment(
|
||||
deployment_id="client_deploy_art.default"
|
||||
)
|
||||
|
||||
assert listed["deployments"]
|
||||
assert inspected["id"] == "client_deploy_art.default"
|
||||
assert validated["status"] == "runnable"
|
||||
assert deleted["deployment_id"] == "client_deploy_art.default"
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
|
||||
def test_rpc_workflow_client_draft_workspace_lifecycle(tmp_path) -> None:
|
||||
async def scenario() -> None:
|
||||
server = build_local_static_workflow_server(tmp_path / "store")
|
||||
app = create_rpc_app(server)
|
||||
transport = httpx.ASGITransport(app=app)
|
||||
async with httpx.AsyncClient(
|
||||
transport=transport, base_url="http://test"
|
||||
) as http_client:
|
||||
client = RpcWorkflowApiClient(
|
||||
url="http://test/rpc", timeout_seconds=5, http_client=http_client
|
||||
)
|
||||
created = await client.create_draft_workspace_from_capability(
|
||||
workspace_id="client_ws",
|
||||
capability_name="wf.std.constant",
|
||||
name="client_constant",
|
||||
title="Client Constant",
|
||||
input_map={},
|
||||
output_map={"value": "state.result"},
|
||||
)
|
||||
listed = await client.list_draft_workspaces()
|
||||
fetched = await client.get_draft_workspace(workspace_id="client_ws")
|
||||
validated = await client.validate_draft_workspace(workspace_id="client_ws")
|
||||
patched = await client.patch_draft_workspace(
|
||||
workspace_id="client_ws",
|
||||
revision=created["revision"],
|
||||
patch=[{"op": "replace", "path": "/name", "value": "client_renamed"}],
|
||||
)
|
||||
artifact = await client.create_artifact_from_workspace(
|
||||
workspace_id="client_ws",
|
||||
artifact_id="client_ws_art",
|
||||
version=1,
|
||||
title="Client WS Art",
|
||||
outcomes=("ok",),
|
||||
kind="workflow",
|
||||
source_bindings={"wf.std": "wf.std"},
|
||||
)
|
||||
|
||||
assert created["workspace_id"] == "client_ws"
|
||||
assert listed["workspaces"]
|
||||
assert fetched["workspace_id"] == "client_ws"
|
||||
assert validated["status"] in {"valid", "invalid"}
|
||||
assert patched["revision"] == created["revision"] + 1
|
||||
assert artifact["artifact_id"] == "client_ws_art"
|
||||
|
||||
asyncio.run(scenario())
|
||||
|
||||
Reference in New Issue
Block a user