feat(harness): tht ollama ensure CLI command (hard-fail preflight)
This commit is contained in:
@@ -138,3 +138,44 @@ def test_initial_probe_exception_is_server_error():
|
||||
warm=lambda cfg: None,
|
||||
)
|
||||
assert r["ok"] is False and r["stage"] == "server"
|
||||
|
||||
|
||||
import json as _json
|
||||
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from tht.cli.ollama_cmd import ollama_app
|
||||
from tht.cli import ollama_cmd
|
||||
|
||||
|
||||
def _patch(monkeypatch, result):
|
||||
monkeypatch.setattr(ollama_cmd, "_load_config_or_exit", lambda _c: SimpleNamespace(embeddings=object()))
|
||||
monkeypatch.setattr(ollama_cmd, "ensure_ollama", lambda cfg, **kw: result)
|
||||
|
||||
|
||||
def test_cli_ok_exit_zero_and_json_pristine(monkeypatch):
|
||||
_patch(monkeypatch, {"ok": True, "server": "up", "model": "warmed", "model_name": "m"})
|
||||
res = CliRunner().invoke(ollama_app, ["--json"])
|
||||
assert res.exit_code == 0, res.output
|
||||
assert _json.loads(res.output) == {"ok": True, "server": "up", "model": "warmed", "model_name": "m"}
|
||||
|
||||
|
||||
def test_cli_error_exit_one_and_json_on_stdout(monkeypatch):
|
||||
_patch(monkeypatch, {"ok": False, "stage": "model", "error": "missing"})
|
||||
res = CliRunner().invoke(ollama_app, ["--json"])
|
||||
assert res.exit_code == 1
|
||||
assert _json.loads(res.output) == {"ok": False, "stage": "model", "error": "missing"}
|
||||
|
||||
|
||||
def test_cli_error_human_mode_exit_one(monkeypatch):
|
||||
_patch(monkeypatch, {"ok": False, "stage": "server", "error": "down"})
|
||||
res = CliRunner().invoke(ollama_app, [])
|
||||
assert res.exit_code == 1
|
||||
|
||||
|
||||
def test_cli_registered_on_root_app():
|
||||
from tht.cli import app # the root Typer app
|
||||
runner = CliRunner()
|
||||
res = runner.invoke(app, ["ollama", "--help"])
|
||||
assert res.exit_code == 0
|
||||
assert "ensure" in res.output
|
||||
|
||||
Reference in New Issue
Block a user