test: expose local cli config source composition gap
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import pytest
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
from wf_api import WorkflowApi
|
from wf_api import WorkflowApi
|
||||||
@@ -24,6 +25,58 @@ def _typer_context(obj: object | None) -> typer.Context:
|
|||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
|
def _write_python_source_config(root: Path, *, target: dict[str, object]) -> Path:
|
||||||
|
source_root = root / "source"
|
||||||
|
source_root.mkdir()
|
||||||
|
(source_root / "ops.py").write_text(
|
||||||
|
"""
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from wf_authoring import node
|
||||||
|
|
||||||
|
|
||||||
|
class EchoInput(BaseModel):
|
||||||
|
text: str
|
||||||
|
|
||||||
|
|
||||||
|
class EchoOutput(BaseModel):
|
||||||
|
text: str
|
||||||
|
|
||||||
|
|
||||||
|
@node(name="echo")
|
||||||
|
def echo(payload: EchoInput) -> EchoOutput:
|
||||||
|
return EchoOutput(text=payload.text)
|
||||||
|
|
||||||
|
|
||||||
|
registry = [echo]
|
||||||
|
""".lstrip(),
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
config_path = root / "wf.json"
|
||||||
|
config_path.write_text(
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"client": {"target": target},
|
||||||
|
"server": {
|
||||||
|
"store": {"kind": "filesystem", "root": ".wf_store"},
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"kind": "python",
|
||||||
|
"id": "local.ops",
|
||||||
|
"path": "source",
|
||||||
|
"module": "ops",
|
||||||
|
"registry": "registry",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
return config_path
|
||||||
|
|
||||||
|
|
||||||
def test_cli_typer_state_reads_typed_context_object() -> None:
|
def test_cli_typer_state_reads_typed_context_object() -> None:
|
||||||
ctx = _typer_context(
|
ctx = _typer_context(
|
||||||
CliTyperState(
|
CliTyperState(
|
||||||
@@ -137,3 +190,26 @@ def test_load_cli_context_local_uses_workflow_store_override(
|
|||||||
|
|
||||||
assert context.service is None
|
assert context.service is None
|
||||||
assert captured["store_root"] == (tmp_path / ".workflow").resolve()
|
assert captured["store_root"] == (tmp_path / ".workflow").resolve()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_load_cli_context_local_composes_configured_python_sources(
|
||||||
|
tmp_path: Path,
|
||||||
|
) -> None:
|
||||||
|
config_path = _write_python_source_config(
|
||||||
|
tmp_path,
|
||||||
|
target={
|
||||||
|
"kind": "rpc_http",
|
||||||
|
"url": "http://127.0.0.1:8765/rpc",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
context = load_cli_context(config_path, force_local=True)
|
||||||
|
|
||||||
|
listed = await context.handlers.list_capabilities(
|
||||||
|
source_id="local.ops",
|
||||||
|
limit=100,
|
||||||
|
)
|
||||||
|
assert {
|
||||||
|
capability["name"] for capability in listed["capabilities"]
|
||||||
|
} == {"local.ops.echo"}
|
||||||
|
|||||||
Reference in New Issue
Block a user