from __future__ import annotations from stewardship.cli import main def test_validate_exit_codes(make_repo, negative_repo): good = make_repo("positive/infra-lxd") assert main(["validate", "--repo", str(good), "--output", "json"]) == 0 bad = negative_repo("secret-field") assert main(["validate", "--repo", str(bad), "--output", "json"]) == 1 def test_missing_repository_returns_exit_3(tmp_path): missing = tmp_path / "does-not-exist" assert main(["validate", "--repo", str(missing), "--output", "json"]) == 3 def test_context_strict_truncation_returns_exit_4(make_repo): repo = make_repo("positive/infra-lxd") code = main( [ "context", "--repo", str(repo), "--intent", "container.deploy", "--materialize", "--budget-bytes", "1", "--strict", "--output", "json", ] ) assert code == 4 def test_init_apply_without_hash_returns_exit_2(tmp_path): code = main(["init", "--repo", str(tmp_path), "--apply", "--output", "json"]) assert code == 2 def test_kdb_prints_the_table_on_stdout_and_findings_on_stderr(make_repo, capsys): """Piping stdout must give clean Markdown, so findings may not land in it.""" repo = make_repo("positive/infra-lxd") assert main(["kdb", "--repo", str(repo)]) == 0 out = capsys.readouterr().out assert out.startswith("## ") assert "| Topic | Intents | Documents | Facts in data |" in out assert "### Documents" in out def test_kdb_json_is_an_envelope_like_every_other_command(make_repo, capsys): import json repo = make_repo("positive/infra-lxd") assert main(["kdb", "--repo", str(repo), "--output", "json"]) == 0 envelope = json.loads(capsys.readouterr().out) assert envelope["command"] == "kdb" assert envelope["outcome"] == "success" assert envelope["data"]["schema"] == "stewardship/knowledge-overview@0.1" def test_kdb_without_a_knowledge_base_warns_and_returns_exit_3(make_repo, capsys): repo = make_repo("positive/infra-lxd") (repo / "kdb" / "kdb.yaml").unlink() assert main(["kdb", "--repo", str(repo)]) == 3 assert "KNOWLEDGE_ENTRYPOINT_MISSING" in capsys.readouterr().err