refactor: move mcp auth record ownership

This commit is contained in:
lda
2026-06-06 15:01:39 +07:00 Verified
parent 0028528269
commit a28ca5434a
150 changed files with 557 additions and 549 deletions
@@ -12,12 +12,16 @@ async def test_rpc_lists_auth_records(tmp_path) -> None:
config = BrokerConfig(store_root=tmp_path / "store", connections=[])
server = build_workflow_server_from_config(config)
FileStore(tmp_path / "store").save_auth(
AuthRecord(connection_id="github.work", scheme="bearer", payload={"token": "secret"})
AuthRecord(
connection_id="github.work", scheme="bearer", payload={"token": "secret"}
)
)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(transport=transport, base_url="http://test") as http_client:
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as http_client:
client = RpcWorkflowApiClient(url="http://test/rpc", http_client=http_client)
payload = await client.list_auth_records()
@@ -35,12 +39,16 @@ async def test_rpc_inspects_auth_record(tmp_path) -> None:
config = BrokerConfig(store_root=tmp_path / "store", connections=[])
server = build_workflow_server_from_config(config)
FileStore(tmp_path / "store").save_auth(
AuthRecord(connection_id="github.work", scheme="bearer", payload={"token": "secret"})
AuthRecord(
connection_id="github.work", scheme="bearer", payload={"token": "secret"}
)
)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(transport=transport, base_url="http://test") as http_client:
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as http_client:
client = RpcWorkflowApiClient(url="http://test/rpc", http_client=http_client)
payload = await client.inspect_auth_record("github.work")
+7 -21
View File
@@ -25,9 +25,7 @@ async def test_rpc_health_and_capability_methods(tmp_path) -> 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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
health_response = await client.get("/healthz")
health = await _rpc(client, "workflow.health", {})
listed = await _rpc(
@@ -55,9 +53,7 @@ async def test_rpc_unknown_method_returns_json_rpc_error(tmp_path) -> 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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(client, "workflow.nope", {})
assert payload["error"]["code"] == -32601
@@ -68,9 +64,7 @@ async def test_rpc_app_mounts_configured_rpc_path(tmp_path) -> None:
server = build_local_static_workflow_server(tmp_path / "store")
app = create_rpc_app(server, rpc_path="/workflow-rpc")
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
response = await client.post(
"/workflow-rpc",
json={
@@ -89,9 +83,7 @@ async def test_rpc_draft_artifact_deployment_lifecycle(tmp_path) -> 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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
draft_ws = await _rpc(
client,
"workflow.drafts.create_from_capability",
@@ -222,9 +214,7 @@ async def test_rpc_artifact_and_deployment_catalog_methods(tmp_path) -> None:
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
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,
@@ -254,9 +244,7 @@ async def test_rpc_draft_workspace_methods(tmp_path) -> 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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
created = await _rpc(
client,
"workflow.draft_workspaces.create_from_capability",
@@ -382,9 +370,7 @@ async def test_rpc_runs_deployment_and_reads_bounded_trace(tmp_path) -> None:
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
run = await _rpc(
client,
"workflow.runs.start",
+8 -3
View File
@@ -179,7 +179,9 @@ def test_rpc_server_cli_rejects_mcp_config_with_store_root(tmp_path) -> None:
assert "--mcp-config cannot be combined with --store-root" in result.output
def test_rpc_server_cli_mcp_config_builds_registry_capable_server(monkeypatch, tmp_path) -> None:
def test_rpc_server_cli_mcp_config_builds_registry_capable_server(
monkeypatch, tmp_path
) -> None:
config_path = tmp_path / "wf_mcp.config.json"
config_path.write_text(
json.dumps(
@@ -213,7 +215,9 @@ def test_rpc_server_cli_mcp_config_builds_registry_capable_server(monkeypatch, t
assert captured["port"] == 8765
def test_rpc_server_cli_mcp_config_with_config_uses_transport_settings(monkeypatch, tmp_path) -> None:
def test_rpc_server_cli_mcp_config_with_config_uses_transport_settings(
monkeypatch, tmp_path
) -> None:
mcp_config_path = tmp_path / "wf_mcp.config.json"
mcp_config_path.write_text(
json.dumps(
@@ -329,9 +333,10 @@ def test_rpc_server_cli_config_with_mcp_source_uses_mcp_builder(
encoding="utf-8",
)
from wf_transport_rpc_http.cli import app
from typer.testing import CliRunner
from wf_transport_rpc_http.cli import app
result = CliRunner().invoke(app, ["--config", str(config_path)])
assert result.exit_code == 0, result.output
+2 -6
View File
@@ -70,9 +70,7 @@ async def test_rpc_workflow_client_lists_and_inspects_capabilities(tmp_path) ->
http_client=http_client,
)
listed = await client.list_capabilities(source_id="wf.std", limit=5)
inspected = await client.inspect_capability(
qualified_name="wf.std.constant"
)
inspected = await client.inspect_capability(qualified_name="wf.std.constant")
assert listed["capabilities"]
assert {capability["source_id"] for capability in listed["capabilities"]} == {
@@ -219,9 +217,7 @@ async def test_rpc_workflow_client_lists_and_inspects_artifacts(tmp_path) -> Non
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
)
inspected = await client.inspect_artifact(artifact_id="client_art", version=1)
assert listed["nodes"]
assert inspected["id"] == "client_art"
@@ -140,9 +140,7 @@ async def test_mcp_backed_rpc_reports_connections_and_events(tmp_path) -> None:
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as http_client:
connections = await _rpc(
http_client, "workflow.admin.connections.list", {}
)
connections = await _rpc(http_client, "workflow.admin.connections.list", {})
assert connections["result"]["connections"][0]["id"] == "demo.default"
@@ -225,9 +223,7 @@ async def test_mcp_backed_rpc_can_be_built_from_neutral_workflow_config(
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as http_client:
connections = await _rpc(
http_client, "workflow.admin.connections.list", {}
)
connections = await _rpc(http_client, "workflow.admin.connections.list", {})
assert connections["result"]["connections"][0]["id"] == "demo.default"
@@ -104,9 +104,7 @@ async def test_rpc_source_registry_list_unavailable_on_local_static(tmp_path) ->
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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client, "workflow.admin.source_registry.list", {"limit": 10}
)
@@ -115,13 +113,13 @@ async def test_rpc_source_registry_list_unavailable_on_local_static(tmp_path) ->
assert payload["error"]["data"]["code"] == "source_registry_unavailable"
async def test_rpc_source_registry_inspect_unavailable_on_local_static(tmp_path) -> None:
async def test_rpc_source_registry_inspect_unavailable_on_local_static(
tmp_path,
) -> 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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.inspect",
@@ -141,9 +139,7 @@ async def test_rpc_source_registry_methods_return_registry_payloads(tmp_path) ->
)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
listed = await _rpc(
client, "workflow.admin.source_registry.list", {"limit": 10}
)
@@ -166,9 +162,7 @@ async def test_rpc_source_registry_add_unavailable_on_local_static(tmp_path) ->
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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.add",
@@ -183,9 +177,7 @@ async def test_rpc_source_registry_update_unavailable_on_local_static(tmp_path)
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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.update",
@@ -200,9 +192,7 @@ async def test_rpc_source_registry_enable_unavailable_on_local_static(tmp_path)
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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.enable",
@@ -213,13 +203,13 @@ async def test_rpc_source_registry_enable_unavailable_on_local_static(tmp_path)
assert payload["error"]["data"]["code"] == "source_registry_unavailable"
async def test_rpc_source_registry_disable_unavailable_on_local_static(tmp_path) -> None:
async def test_rpc_source_registry_disable_unavailable_on_local_static(
tmp_path,
) -> 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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.disable",
@@ -234,9 +224,7 @@ async def test_rpc_source_registry_remove_unavailable_on_local_static(tmp_path)
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:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.remove",
@@ -254,9 +242,7 @@ async def test_rpc_source_registry_add_returns_entry(tmp_path) -> None:
server = _server_with_mutation_provider(tmp_path)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.add",
@@ -272,9 +258,7 @@ async def test_rpc_source_registry_update_returns_entry(tmp_path) -> None:
server = _server_with_mutation_provider(tmp_path)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.update",
@@ -298,9 +282,7 @@ async def test_rpc_source_registry_enable_returns_entry(tmp_path) -> None:
)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.enable",
@@ -315,9 +297,7 @@ async def test_rpc_source_registry_disable_returns_entry(tmp_path) -> None:
server = _server_with_mutation_provider(tmp_path)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.disable",
@@ -332,9 +312,7 @@ async def test_rpc_source_registry_remove_returns_removed(tmp_path) -> None:
server = _server_with_mutation_provider(tmp_path)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.remove",
@@ -353,9 +331,7 @@ async def test_rpc_source_registry_add_missing_entry_raises_error(tmp_path) -> N
server = _server_with_mutation_provider(tmp_path)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.add",
@@ -369,9 +345,7 @@ async def test_rpc_source_registry_update_missing_source_raises_error(tmp_path)
server = _server_with_mutation_provider(tmp_path)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.update",
@@ -385,9 +359,7 @@ async def test_rpc_source_registry_remove_missing_source_raises_error(tmp_path)
server = _server_with_mutation_provider(tmp_path)
app = create_rpc_app(server)
transport = httpx.ASGITransport(app=app)
async with httpx.AsyncClient(
transport=transport, base_url="http://test"
) as client:
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
payload = await _rpc(
client,
"workflow.admin.source_registry.remove",