fix: harden authoring contract inventory

This commit is contained in:
lda
2026-08-14 16:10:37 +07:00 Verified
parent 22510e0681
commit 1625fc3d7e
4 changed files with 234 additions and 19 deletions
+103
View File
@@ -8,6 +8,7 @@ import pytest
from pydantic import BaseModel, Field, TypeAdapter, ValidationError
from tests.wf_mcp.test_support import echo_tool
from tests.wf_mcp.workflow_surface.conftest import echo_artifact
from wf_api.draft_authoring import RouteSource, WorkflowDraftAuthoringApi
from wf_api.draft_updates import CapabilityStepUpdate
from wf_api.drafts import WorkflowDraftApi
@@ -174,6 +175,108 @@ async def test_inspect_draft_authoring_contract_projects_selected_capability(
assert selected["outcomes"] == ["ok"]
@pytest.mark.asyncio
async def test_inspect_draft_authoring_contract_tolerates_invalid_workflow_schema(
tmp_path: Path,
) -> None:
draft_api, _service, authoring = _draft_api(
FileWorkflowArtifactStore(tmp_path / "authoring_contract_invalid_schema"),
register_echo=True,
)
draft = _echo_draft()
draft["input_schema"] = {"type": 7}
draft["state_schema"] = {
"type": "object",
"properties": {"echoed": {"type": "string"}},
}
await draft_api.create_draft_workspace(workspace_id="authoring", draft=draft)
api = WorkflowApi(authoring.context)
inventory = await api.inspect_draft_authoring_contract(
workspace_id="authoring",
revision=1,
selected_step_id="echo",
)
assert inventory["readable_sources"]
assert all(
option["origin"] != "workflow_input" for option in inventory["readable_sources"]
)
assert {option["path"] for option in inventory["state_targets"]} == {"state.echoed"}
assert {option["path"] for option in inventory["workflow_output_targets"]} == {
"output.echoed"
}
assert any("input_schema" in warning for warning in inventory["warnings"])
@pytest.mark.asyncio
async def test_inspect_draft_authoring_contract_resolves_saved_wrapper_capability(
tmp_path: Path,
) -> None:
artifact_store = FileWorkflowArtifactStore(tmp_path / "authoring_contract_wrapper")
artifact_store.save_artifact(
echo_artifact().model_copy(update={"id": "echo_wrapper", "kind": "wrapper"})
)
draft_api, _service, authoring = _draft_api(artifact_store)
draft = _echo_draft()
draft["steps"]["echo"]["use"] = "workflow.echo_wrapper.v1"
draft["state_schema"] = {
"type": "object",
"properties": {"echoed": {"type": "string"}},
}
await draft_api.create_draft_workspace(workspace_id="authoring", draft=draft)
api = WorkflowApi(authoring.context)
inventory = await api.inspect_draft_authoring_contract(
workspace_id="authoring",
revision=1,
selected_step_id="echo",
)
assert [step["step_id"] for step in inventory["entry_steps"]] == ["echo"]
assert {option["path"] for option in inventory["step_input_targets"]} == {
"step_input.text"
}
assert {option["path"] for option in inventory["step_output_sources"]} == {
"step_output.echoed"
}
assert inventory["entry_steps"][0]["outcomes"] == ["completed"]
@pytest.mark.asyncio
async def test_inspect_draft_authoring_contract_preserves_empty_capability_schemas(
tmp_path: Path,
) -> None:
draft_api, service, authoring = _draft_api(
FileWorkflowArtifactStore(tmp_path / "authoring_contract_empty_schema")
)
service.register_connection(
ConnectionConfig(id="demo.personal", server="demo", account="personal")
)
service.register_specs(
"demo.personal",
replace(echo_tool, input_schema_contract={}, output_schema_contract={}),
)
draft = _echo_draft()
draft["state_schema"] = {
"type": "object",
"properties": {"echoed": {"type": "string"}},
}
await draft_api.create_draft_workspace(workspace_id="authoring", draft=draft)
api = WorkflowApi(authoring.context)
inventory = await api.inspect_draft_authoring_contract(
workspace_id="authoring",
revision=1,
selected_step_id="echo",
)
assert inventory["entry_steps"][0]["input_targets"] == []
assert inventory["entry_steps"][0]["output_sources"] == []
assert inventory["step_input_targets"] == []
assert inventory["step_output_sources"] == []
@pytest.mark.asyncio
async def test_inspect_draft_authoring_contract_rejects_unknown_selected_step(
tmp_path: Path,