"""Tests for T01 — markidocx inspect and markidocx test CLI commands (FR-806, FR-810).""" from __future__ import annotations import json import textwrap from pathlib import Path import pytest SIMPLE_MANIFEST = textwrap.dedent("""\ project: name: "Test Document" feature_level: level1 family: article sources: - path: doc.md output: dir: ./dist """) SIMPLE_MARKDOWN = textwrap.dedent("""\ # Hello A paragraph. """) @pytest.fixture() def tmp_project(tmp_path: Path) -> Path: (tmp_path / "doc.md").write_text(SIMPLE_MARKDOWN, encoding="utf-8") (tmp_path / "manifest.yaml").write_text(SIMPLE_MANIFEST, encoding="utf-8") (tmp_path / "dist").mkdir() return tmp_path # --------------------------------------------------------------------------- # inspect command # --------------------------------------------------------------------------- class TestInspectCommand: def test_inspect_human_readable(self, tmp_project: Path) -> None: from typer.testing import CliRunner from markidocx.cli import app runner = CliRunner() result = runner.invoke(app, ["inspect", str(tmp_project / "manifest.yaml")]) assert result.exit_code == 0 assert "Test Document" in result.output assert "article" in result.output assert "level1" in result.output def test_inspect_json_output(self, tmp_project: Path) -> None: from typer.testing import CliRunner from markidocx.cli import app runner = CliRunner() result = runner.invoke(app, ["inspect", str(tmp_project / "manifest.yaml"), "--json"]) assert result.exit_code == 0 data = json.loads(result.output.strip()) assert data["status"] == "ok" assert data["project"] == "Test Document" assert data["family"] == "article" assert data["feature_level"] == "level1" assert isinstance(data["sources"], list) assert isinstance(data["level3"], dict) def test_inspect_invalid_manifest(self, tmp_path: Path) -> None: from typer.testing import CliRunner from markidocx.cli import app bad = tmp_path / "bad.yaml" bad.write_text("not: valid: manifest", encoding="utf-8") runner = CliRunner() result = runner.invoke(app, ["inspect", str(bad)]) assert result.exit_code == 1 def test_inspect_json_invalid_manifest(self, tmp_path: Path) -> None: from typer.testing import CliRunner from markidocx.cli import app bad = tmp_path / "bad.yaml" bad.write_text("not: valid: manifest", encoding="utf-8") runner = CliRunner() result = runner.invoke(app, ["inspect", str(bad), "--json"]) data = json.loads(result.output.strip()) assert data["status"] == "error" # --------------------------------------------------------------------------- # test command # --------------------------------------------------------------------------- class TestRunTestsCommand: def test_run_tests_passes(self, tmp_project: Path) -> None: from typer.testing import CliRunner from markidocx.cli import app runner = CliRunner() result = runner.invoke(app, ["test", str(tmp_project / "manifest.yaml")]) # Command exists and runs assert result.exit_code in (0, 1) assert "run_id" in result.output or "passed" in result.output or "failed" in result.output def test_run_tests_json_output(self, tmp_project: Path) -> None: from typer.testing import CliRunner from markidocx.cli import app runner = CliRunner() result = runner.invoke(app, ["test", str(tmp_project / "manifest.yaml"), "--json"]) data = json.loads(result.output.strip()) assert "status" in data assert "classification" in data assert "steps" in data def test_run_tests_exit_code_reflects_result(self, tmp_project: Path) -> None: from typer.testing import CliRunner from markidocx.cli import app runner = CliRunner() result = runner.invoke(app, ["test", str(tmp_project / "manifest.yaml"), "--json"]) data = json.loads(result.output.strip()) expected_exit = 0 if data["status"] == "ok" else 1 assert result.exit_code == expected_exit