refactor(cli): remove obsolete workflow commands
This commit is contained in:
@@ -16,13 +16,48 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from typer.main import get_command
|
||||
|
||||
from tht.cli import app
|
||||
|
||||
_ROOT = Path(__file__).resolve().parent.parent.parent
|
||||
_GATE = _ROOT / ".pi" / "extensions" / "tht-gate.js"
|
||||
_THT = Path(sys.executable).parent / "tht"
|
||||
|
||||
# The command groups the gate drives. Anything else in an array literal is data, not a CLI call.
|
||||
_GROUPS = {"phase", "session", "cte", "decision", "memory", "search", "schema", "vector"}
|
||||
_GROUPS = {"phase", "session", "cte", "decision", "memory", "search", "schema", "sql", "vector"}
|
||||
|
||||
# Python's workflow CLI is also a contract for its non-gate consumers. Keep this
|
||||
# list literal rather than deriving it from the current tree: a deleted live
|
||||
# command must fail this test before a container or preprocessing job reaches it.
|
||||
_LIVE_CONSUMER_COMMANDS = {
|
||||
"Pi skill": {
|
||||
("cte", "info"), ("cte", "save"), ("cte", "test"),
|
||||
("datamart", "generate"), ("memory", "promote"),
|
||||
("memory", "save-one"), ("memory", "search"),
|
||||
("memory", "solved-index"), ("memory", "solved-search"),
|
||||
("phase", "advance"), ("phase", "reopen"),
|
||||
("schema", "introspect"), ("schema", "render"),
|
||||
("search", "find"), ("search", "pack"),
|
||||
("session", "check"), ("session", "documents"),
|
||||
("session", "finalize"), ("session", "show"),
|
||||
("sql", "preview"), ("sql", "set-final"), ("sql", "validate"),
|
||||
},
|
||||
"backend ThtRunner": {
|
||||
("db", "ping"), ("ollama", "ensure"), ("search", "pack"),
|
||||
("session", "archive"), ("session", "close"), ("session", "delete"),
|
||||
("session", "documents"), ("session", "fail"), ("session", "list"),
|
||||
("session", "new"), ("session", "reopen"), ("session", "set-group"),
|
||||
("session", "set-name"), ("session", "show"), ("session", "unarchive"),
|
||||
("session", "preferences", "get"), ("session", "preferences", "set"),
|
||||
("sql", "export"), ("sql", "preview"),
|
||||
},
|
||||
"workspace preprocessing": {
|
||||
("preprocess", "dwh"), ("preprocess", "evidence"),
|
||||
("schema", "check"), ("schema", "suggest-fks"), ("vector", "index-schema"),
|
||||
},
|
||||
"deployment smoke": {("config", "check"), ("db", "ping")},
|
||||
}
|
||||
|
||||
# Flags that are framework/JS artifacts, never real CLI options (skip from the check).
|
||||
_SKIP_FLAGS: set[str] = set()
|
||||
@@ -53,6 +88,30 @@ def test_gate_invokes_at_least_the_known_commands():
|
||||
assert ("cte", "plan") in pairs
|
||||
assert ("session", "set-question") in pairs
|
||||
assert ("decision", "add") in pairs
|
||||
assert ("sql", "set-final") in pairs
|
||||
|
||||
|
||||
def _leaf_paths(command, prefix: tuple[str, ...] = ()) -> set[tuple[str, ...]]:
|
||||
children = getattr(command, "commands", {})
|
||||
if not children:
|
||||
return {prefix} if prefix else set()
|
||||
paths: set[tuple[str, ...]] = set()
|
||||
for name, child in children.items():
|
||||
paths.update(_leaf_paths(child, prefix + (name,)))
|
||||
return paths
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("consumer", "path"),
|
||||
[
|
||||
(consumer, path)
|
||||
for consumer, paths in _LIVE_CONSUMER_COMMANDS.items()
|
||||
for path in sorted(paths)
|
||||
],
|
||||
)
|
||||
def test_live_workflow_consumers_keep_their_command_paths(consumer: str, path: tuple[str, ...]):
|
||||
"""Live Pi, backend, preprocessing, and smoke paths must remain callable."""
|
||||
assert path in _leaf_paths(get_command(app)), f"{consumer} requires `tht {' '.join(path)}`"
|
||||
|
||||
|
||||
@pytest.mark.skipif(not _THT.exists(), reason="tht CLI not installed in this venv")
|
||||
@@ -60,7 +119,7 @@ def test_gate_invokes_at_least_the_known_commands():
|
||||
def test_gate_call_site_matches_cli(group: str, sub: str, flags: list[str], raw: str):
|
||||
res = subprocess.run(
|
||||
[str(_THT), group, sub, "--help"],
|
||||
capture_output=True, text=True, cwd=str(_ROOT),
|
||||
capture_output=True, check=False, text=True, cwd=str(_ROOT),
|
||||
)
|
||||
assert res.returncode == 0, (
|
||||
f"gate calls `tht {group} {sub}` but it does not exist in the CLI.\n"
|
||||
|
||||
Reference in New Issue
Block a user