feat: type source discovery results
This commit is contained in:
@@ -243,6 +243,28 @@ def test_diagnose_source_uses_provider() -> None:
|
||||
assert payload["auth"]["record_present"] is True
|
||||
|
||||
|
||||
class _ExtendedDiagnostics:
|
||||
def diagnose_source(self, source_id: str) -> dict[str, object]:
|
||||
return {
|
||||
"source_id": source_id,
|
||||
"status": "degraded",
|
||||
"diagnostics": [],
|
||||
"provider_latency_ms": 12,
|
||||
}
|
||||
|
||||
|
||||
def test_diagnose_source_preserves_provider_extensions() -> None:
|
||||
payload = asyncio.run(
|
||||
_api_with_diagnostics(
|
||||
_source("demo.personal"),
|
||||
diagnostics=_ExtendedDiagnostics(),
|
||||
).diagnose_source(source_id="demo.personal")
|
||||
)
|
||||
|
||||
assert payload["status"] == "degraded"
|
||||
assert dict(payload)["provider_latency_ms"] == 12
|
||||
|
||||
|
||||
def test_diagnose_source_without_provider_returns_basic_status() -> None:
|
||||
payload = asyncio.run(
|
||||
_api_with_diagnostics(_source("demo.personal")).diagnose_source(
|
||||
|
||||
@@ -163,6 +163,36 @@ async def test_rpc_health_and_capability_methods(tmp_path) -> None:
|
||||
assert called["result"]["output"] == {"value": "hello direct rpc"}
|
||||
|
||||
|
||||
async def test_rpc_source_discovery_preserves_inventory_contracts(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:
|
||||
listed = await _rpc(client, "workflow.sources.list", {"limit": 10})
|
||||
inspected = await _rpc(
|
||||
client,
|
||||
"workflow.sources.inspect",
|
||||
{"source_id": "wf.std"},
|
||||
)
|
||||
diagnosed = await _rpc(
|
||||
client,
|
||||
"workflow.sources.diagnose",
|
||||
{"source_id": "wf.std"},
|
||||
)
|
||||
|
||||
source = next(row for row in listed["result"]["sources"] if row["id"] == "wf.std")
|
||||
assert source["kind"] == "system"
|
||||
assert source["preview"]["node_specs"]
|
||||
inventory = inspected["result"]["capabilities"]
|
||||
assert inventory["node_spec_details"][0]["input_schema"]["type"] == "object"
|
||||
assert inventory["reducer_details"][0]["ref"] == {
|
||||
"source": "wf.std",
|
||||
"capability_key": "add",
|
||||
}
|
||||
assert diagnosed["result"]["source_id"] == "wf.std"
|
||||
assert diagnosed["result"]["status"] == "unknown"
|
||||
|
||||
|
||||
async def test_rpc_capability_methods_preserve_saved_wrapper_fields(tmp_path) -> None:
|
||||
server = build_local_static_workflow_server(tmp_path / "store")
|
||||
await server.api.create_artifact_from_plan(
|
||||
|
||||
@@ -117,6 +117,58 @@ def test_openrpc_exposes_typed_capability_call_result(
|
||||
)
|
||||
|
||||
|
||||
def test_openrpc_exposes_typed_source_list_result(
|
||||
openrpc_document: dict[str, Any],
|
||||
) -> None:
|
||||
_assert_result_component(
|
||||
openrpc_document,
|
||||
method_name="workflow.sources.list",
|
||||
component_name="ListSourcesResult",
|
||||
properties={"sources", "next_cursor", "total"},
|
||||
)
|
||||
sources = openrpc_document["components"]["schemas"]["ListSourcesResult"][
|
||||
"properties"
|
||||
]["sources"]
|
||||
assert sources["items"] == {"$ref": "#/components/schemas/SourceStatusPayload"}
|
||||
assert set(
|
||||
openrpc_document["components"]["schemas"]["ListSourcesResult"]["required"]
|
||||
) == {"sources", "next_cursor", "total"}
|
||||
|
||||
|
||||
def test_openrpc_exposes_typed_source_inspect_result(
|
||||
openrpc_document: dict[str, Any],
|
||||
) -> None:
|
||||
_assert_result_component(
|
||||
openrpc_document,
|
||||
method_name="workflow.sources.inspect",
|
||||
component_name="InspectSourceResult",
|
||||
properties={"id", "kind", "capabilities"},
|
||||
)
|
||||
inspected = openrpc_document["components"]["schemas"]["InspectSourceResult"]
|
||||
assert inspected["properties"]["capabilities"] == {
|
||||
"$ref": "#/components/schemas/SourceCapabilityInventoryPayload"
|
||||
}
|
||||
assert inspected["properties"]["diagnostics"]["anyOf"][:2] == [
|
||||
{"$ref": "#/components/schemas/SourceDiagnosisResult"},
|
||||
{"$ref": "#/components/schemas/SourceDiagnosticsUnavailablePayload"},
|
||||
]
|
||||
assert {"id", "kind", "capabilities"} <= set(inspected["required"])
|
||||
|
||||
|
||||
def test_openrpc_exposes_typed_source_diagnosis_result(
|
||||
openrpc_document: dict[str, Any],
|
||||
) -> None:
|
||||
_assert_result_component(
|
||||
openrpc_document,
|
||||
method_name="workflow.sources.diagnose",
|
||||
component_name="SourceDiagnosisResult",
|
||||
properties={"source_id", "status", "diagnostics"},
|
||||
)
|
||||
diagnosed = openrpc_document["components"]["schemas"]["SourceDiagnosisResult"]
|
||||
assert set(diagnosed["required"]) == {"source_id", "status", "diagnostics"}
|
||||
assert diagnosed["additionalProperties"] is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method_name", "component_name", "properties"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user