wf cli foundation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from wf_cli.app import app
|
||||
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
|
||||
def test_wf_help_lists_lifecycle_groups() -> None:
|
||||
result = runner.invoke(app, ["--help"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "cap" in result.output
|
||||
assert "draft" in result.output
|
||||
assert "artifact" in result.output
|
||||
assert "deploy" in result.output
|
||||
assert "run" in result.output
|
||||
assert "docs" in result.output
|
||||
assert "schema" in result.output
|
||||
assert "explain" in result.output
|
||||
|
||||
|
||||
def test_wf_run_group_help_exists() -> None:
|
||||
result = runner.invoke(app, ["run", "--help"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "Run workflow deployments" in result.output
|
||||
@@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from wf_cli.context import load_cli_context
|
||||
|
||||
from ..wf_mcp.test_support import local_temp_root
|
||||
|
||||
|
||||
def test_load_cli_context_builds_service_and_handlers() -> None:
|
||||
tmp_path = local_temp_root() / "wf_cli_context"
|
||||
tmp_path.mkdir(parents=True, exist_ok=True)
|
||||
config_path = tmp_path / "wf_mcp.config.json"
|
||||
config_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"store_root": ".wf_mcp_store",
|
||||
"connections": [
|
||||
{
|
||||
"id": "demo.personal",
|
||||
"server": "demo",
|
||||
"account": "personal",
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
context = load_cli_context(config_path)
|
||||
|
||||
assert context.config_path == config_path
|
||||
assert context.service.connections.list_all()[0].id == "demo.personal"
|
||||
assert context.handlers.service is context.service
|
||||
@@ -0,0 +1,44 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from wf_cli.io import CliInputError, emit_json, parse_json_input
|
||||
|
||||
|
||||
def test_parse_json_input_reads_inline_json() -> None:
|
||||
payload = parse_json_input(input_json='{"text": "hello"}', input_file=None)
|
||||
|
||||
assert payload["text"] == "hello"
|
||||
|
||||
|
||||
def test_parse_json_input_reads_file(tmp_path) -> None:
|
||||
path = tmp_path / "payload.json"
|
||||
path.write_text('{"text": "from file"}', encoding="utf-8")
|
||||
|
||||
payload = parse_json_input(input_json=None, input_file=path)
|
||||
|
||||
assert payload["text"] == "from file"
|
||||
|
||||
|
||||
def test_parse_json_input_rejects_both_inline_and_file(tmp_path) -> None:
|
||||
path = tmp_path / "payload.json"
|
||||
path.write_text("{}", encoding="utf-8")
|
||||
|
||||
with pytest.raises(CliInputError, match="mutually exclusive"):
|
||||
parse_json_input(input_json="{}", input_file=path)
|
||||
|
||||
|
||||
def test_parse_json_input_rejects_invalid_json() -> None:
|
||||
with pytest.raises(CliInputError, match="invalid JSON"):
|
||||
parse_json_input(input_json="{", input_file=None)
|
||||
|
||||
|
||||
def test_emit_json_writes_pretty_json(capsys) -> None:
|
||||
emit_json({"ok": True, "items": [1]})
|
||||
captured = capsys.readouterr()
|
||||
payload = json.loads(captured.out)
|
||||
|
||||
assert payload["ok"] is True
|
||||
assert payload["items"][0] == 1
|
||||
Reference in New Issue
Block a user