draft: ergonomic workflow building for LLM
This commit is contained in:
@@ -59,6 +59,10 @@ def test_server_exposes_upstream_admin_and_workflow_tools() -> None:
|
||||
assert "wf.workflow.list_capabilities" in names
|
||||
assert "wf.workflow.inspect_capability" in names
|
||||
assert "wf.workflow.call_capability" in names
|
||||
assert "wf.workflow.validate_draft" in names
|
||||
assert "wf.workflow.compile_draft" in names
|
||||
assert "wf.workflow.create_artifact_from_draft" in names
|
||||
assert "wf.workflow.patch_draft" in names
|
||||
assert "wf.workflow.run_deployment" in names
|
||||
|
||||
echo_result = await client.call_tool(
|
||||
@@ -80,8 +84,7 @@ def test_server_exposes_upstream_admin_and_workflow_tools() -> None:
|
||||
assert _structured(capability_result)["outcome"] == "ok"
|
||||
assert _structured(capability_result)["output"] == {"value": "hello"}
|
||||
source_ids = {
|
||||
source["id"]
|
||||
for source in _structured(sources_result)["sources"]
|
||||
source["id"] for source in _structured(sources_result)["sources"]
|
||||
}
|
||||
assert "wf.admin" in source_ids
|
||||
assert "wf.docs" in source_ids
|
||||
@@ -152,6 +155,8 @@ def test_server_search_mode_pins_stable_control_and_workflow_tools() -> None:
|
||||
assert "wf.admin.list_proxy_tools" in names
|
||||
assert "wf.admin.get_proxy_tool" in names
|
||||
assert "wf.workflow.list_artifacts" in names
|
||||
assert "wf.workflow.validate_draft" in names
|
||||
assert "wf.workflow.create_artifact_from_draft" in names
|
||||
assert "wf.workflow.call_capability" in names
|
||||
assert "wf.workflow.inspect_artifact" in names
|
||||
assert "wf.workflow.list_deployments" in names
|
||||
@@ -206,6 +211,39 @@ def test_create_artifact_from_plan_exposes_plan_as_plain_object() -> None:
|
||||
asyncio.run(run_proxy())
|
||||
|
||||
|
||||
def test_draft_tools_expose_plain_object_and_patch_array_schemas() -> None:
|
||||
config = BrokerConfig(
|
||||
store_root=local_temp_root() / "unified_draft_schema_store",
|
||||
connections=[],
|
||||
)
|
||||
|
||||
async def run_proxy() -> None:
|
||||
client = create_server_client(config, admin_tools=False)
|
||||
async with client:
|
||||
tools = await client.list_tools()
|
||||
by_name = {tool.name: tool for tool in tools}
|
||||
|
||||
validate_schema = by_name["wf.workflow.validate_draft"].inputSchema
|
||||
validate_draft_schema = validate_schema["properties"]["draft"]
|
||||
create_schema = by_name[
|
||||
"wf.workflow.create_artifact_from_draft"
|
||||
].inputSchema
|
||||
create_draft_schema = create_schema["properties"]["draft"]
|
||||
patch_schema = by_name["wf.workflow.patch_draft"].inputSchema
|
||||
patch_draft_schema = patch_schema["properties"]["draft"]
|
||||
patch_patch_schema = patch_schema["properties"]["patch"]
|
||||
|
||||
assert validate_draft_schema["type"] == "object"
|
||||
assert validate_draft_schema.get("additionalProperties") is True
|
||||
assert create_draft_schema["type"] == "object"
|
||||
assert create_draft_schema.get("additionalProperties") is True
|
||||
assert patch_draft_schema["type"] == "object"
|
||||
assert patch_patch_schema["type"] == "array"
|
||||
assert "$defs" not in patch_patch_schema
|
||||
|
||||
asyncio.run(run_proxy())
|
||||
|
||||
|
||||
def test_server_exposes_platform_documentation_resources() -> None:
|
||||
config = BrokerConfig(
|
||||
store_root=local_temp_root() / "unified_docs_resource_store",
|
||||
@@ -306,8 +344,7 @@ def test_server_reload_syncs_service_connection_source_enabled_state() -> None:
|
||||
{"source_id": "fixture.personal"},
|
||||
)
|
||||
names = [
|
||||
capability["name"]
|
||||
for capability in _structured(after)["capabilities"]
|
||||
capability["name"] for capability in _structured(after)["capabilities"]
|
||||
]
|
||||
assert "fixture.personal.echo_tool" in names
|
||||
|
||||
|
||||
@@ -210,6 +210,115 @@ def test_workflow_surface_creates_artifact_with_logical_node_refs() -> None:
|
||||
assert artifact.required_capabilities["demo.echo_tool"].logical_source == "demo"
|
||||
|
||||
|
||||
def test_workflow_surface_validates_draft_without_saving() -> None:
|
||||
artifact_store = FileWorkflowArtifactStore(
|
||||
local_temp_root() / "surface_draft_validate"
|
||||
)
|
||||
handlers = _handlers(artifact_store)
|
||||
|
||||
payload = asyncio.run(handlers.validate_draft(draft=_echo_draft()))
|
||||
|
||||
assert payload["status"] == "valid"
|
||||
assert payload["diagnostics"] == []
|
||||
assert payload["compiled_plan"]["nodes"][0]["type"] == "node"
|
||||
assert artifact_store.list_artifacts() == []
|
||||
|
||||
|
||||
def test_workflow_surface_creates_artifact_from_draft_with_binding_suggestions() -> (
|
||||
None
|
||||
):
|
||||
artifact_store = FileWorkflowArtifactStore(
|
||||
local_temp_root() / "surface_draft_create"
|
||||
)
|
||||
service = WfMcpService(
|
||||
store=FileStore(local_temp_root() / "surface_draft_create_mcp"),
|
||||
artifact_store=artifact_store,
|
||||
)
|
||||
service.register_connection(
|
||||
ConnectionConfig(id="demo.personal", server="demo", account="personal")
|
||||
)
|
||||
service.register_specs("demo.personal", echo_tool)
|
||||
handlers = WorkflowSurfaceHandlers(service)
|
||||
draft = _echo_draft()
|
||||
draft["steps"][0]["capability"] = "demo.personal.echo_tool"
|
||||
|
||||
payload = asyncio.run(
|
||||
handlers.create_artifact_from_draft(
|
||||
artifact_id="draft_echo",
|
||||
version=1,
|
||||
title="Draft Echo",
|
||||
draft=draft,
|
||||
outcomes=("completed",),
|
||||
source_bindings={"demo": "demo.personal"},
|
||||
)
|
||||
)
|
||||
artifact = artifact_store.get_artifact("draft_echo", 1)
|
||||
|
||||
assert payload["saved"] is True
|
||||
assert payload["required_logical_sources"] == ["demo", "wf.std"]
|
||||
assert payload["suggested_bindings"]["wf.std"] == "wf.std"
|
||||
assert artifact.plan["nodes"][0]["node"] == "demo.echo_tool"
|
||||
assert artifact.required_capabilities["demo.echo_tool"].logical_source == "demo"
|
||||
|
||||
|
||||
def test_workflow_surface_draft_artifact_requires_std_self_binding() -> None:
|
||||
artifact_store = FileWorkflowArtifactStore(
|
||||
local_temp_root() / "surface_draft_missing_std"
|
||||
)
|
||||
handlers = _handlers(artifact_store)
|
||||
|
||||
asyncio.run(
|
||||
handlers.create_artifact_from_draft(
|
||||
artifact_id="draft_echo_missing_std",
|
||||
version=1,
|
||||
title="Draft Echo Missing Std",
|
||||
draft=_echo_draft(),
|
||||
outcomes=("completed",),
|
||||
source_bindings={"demo": "demo.personal"},
|
||||
)
|
||||
)
|
||||
artifact_store.save_deployment(
|
||||
WorkflowDeployment(
|
||||
id="draft_echo_missing_std.personal",
|
||||
artifact_id="draft_echo_missing_std",
|
||||
artifact_version=1,
|
||||
bindings={"demo": "demo.personal"},
|
||||
)
|
||||
)
|
||||
|
||||
payload = asyncio.run(
|
||||
handlers.validate_deployment(deployment_id="draft_echo_missing_std.personal")
|
||||
)
|
||||
|
||||
assert payload["status"] == "unrunnable"
|
||||
assert payload["diagnostics"][0]["code"] == "binding_missing"
|
||||
assert payload["diagnostics"][0]["logical_ref"] == "wf.std.replace"
|
||||
|
||||
|
||||
def test_workflow_surface_patches_draft_without_saving() -> None:
|
||||
artifact_store = FileWorkflowArtifactStore(
|
||||
local_temp_root() / "surface_draft_patch"
|
||||
)
|
||||
handlers = _handlers(artifact_store)
|
||||
|
||||
payload = asyncio.run(
|
||||
handlers.patch_draft(
|
||||
draft=_echo_draft(),
|
||||
patch=[
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/steps/0/in/input.text",
|
||||
"value": "message",
|
||||
}
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
assert payload["status"] == "valid"
|
||||
assert payload["draft"]["steps"][0]["in"]["input.text"] == "message"
|
||||
assert artifact_store.list_artifacts() == []
|
||||
|
||||
|
||||
def test_raw_workflow_plan_uses_core_step_and_edge_models() -> None:
|
||||
plan = RawWorkflowPlan.model_validate(_echo_artifact().plan)
|
||||
|
||||
@@ -595,6 +704,34 @@ def _echo_artifact() -> WorkflowArtifact:
|
||||
)
|
||||
|
||||
|
||||
def _echo_draft() -> dict[str, Any]:
|
||||
return {
|
||||
"name": "echo",
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {"text": {"type": "string"}},
|
||||
"required": ["text"],
|
||||
},
|
||||
"state_schema": {"fields": {"echoed": {"type": "string"}}},
|
||||
"output_schema": {
|
||||
"type": "object",
|
||||
"properties": {"echoed": {"type": "string"}},
|
||||
"required": ["echoed"],
|
||||
},
|
||||
"start": "echo",
|
||||
"steps": [
|
||||
{
|
||||
"id": "echo",
|
||||
"kind": "use",
|
||||
"capability": "demo.personal.echo_tool",
|
||||
"in": {"input.text": "text"},
|
||||
"out": {"echoed": "state.echoed"},
|
||||
}
|
||||
],
|
||||
"edges": [{"from": "echo", "outcome": "ok", "to": "__end__"}],
|
||||
}
|
||||
|
||||
|
||||
def _logical_echo_artifact() -> WorkflowArtifact:
|
||||
artifact = _echo_artifact()
|
||||
plan = dict(artifact.plan)
|
||||
|
||||
Reference in New Issue
Block a user