Files
marki-docx/tests/test_cli_evidence.py
Bernd Worsch 9fe64bcd7f feat: WP-0007 — Interface Completeness & Evidence
T01: markidocx inspect (FR-806) and markidocx test (FR-810) CLI commands
T02: markidocx evidence get/list CLI commands (FR-1409, FR-814)
T03: list_styles() / GET /styles / MCP list_styles with real style data (FR-907)
T04: Evidence assembly — EvidenceSet summary via REST and MCP (FR-1406–1408)
T05: LEVEL3 edge-case tests — diagram mutation, renderer version check,
     bibliography duplicate keys / missing refs / special chars (FR-534, FR-538, FR-542)
T06: markidocx template extract + Word-first round-trip regression test (FR-606)

New: differ._compare_diagram_blocks tracks fenced diagram source drift (FR-534)
New: diagrams.check_renderer_version emits warning for outdated renderers (FR-538)
New: bibliography.validate_citations detects duplicate keys and missing entries (FR-542)
New: templates.extract_template / TemplateExtractionResult / list_styles / StyleEntry
New: REST POST /template/extract; MCP extract_template tool

278 tests pass, ruff+mypy clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 19:30:09 +00:00

126 lines
3.9 KiB
Python

"""Tests for T02 — markidocx evidence CLI commands (FR-1409, FR-814)."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
@pytest.fixture()
def store_with_run(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
"""Create an EvidenceStore with one sample run and monkeypatch the default dir."""
from markidocx.evidence import EvidenceStore, ReportContext
ev_dir = tmp_path / "evidence"
store = EvidenceStore(base_dir=ev_dir)
run_id = store.new_run_id()
store.save_report(
run_id,
"build",
{"status": "ok", "warnings": [], "errors": []},
ReportContext(project="test"),
)
_orig_init = EvidenceStore.__init__
def _patched_init(self, base_dir=None):
_orig_init(self, base_dir=ev_dir)
monkeypatch.setattr(EvidenceStore, "__init__", _patched_init)
return store, run_id
class TestEvidenceListCommand:
def test_list_shows_runs(self, store_with_run) -> None:
from typer.testing import CliRunner
from markidocx.cli import app
store, run_id = store_with_run
runner = CliRunner()
result = runner.invoke(app, ["evidence", "list"])
assert result.exit_code == 0
assert run_id in result.output
def test_list_json(self, store_with_run) -> None:
from typer.testing import CliRunner
from markidocx.cli import app
store, run_id = store_with_run
runner = CliRunner()
result = runner.invoke(app, ["evidence", "list", "--json"])
assert result.exit_code == 0
data = json.loads(result.output.strip())
assert "runs" in data
assert run_id in data["runs"]
def test_list_empty_store(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
from markidocx.evidence import EvidenceStore
empty_dir = tmp_path / "empty_evidence"
_orig_init = EvidenceStore.__init__
def _patched_init(self, base_dir=None):
_orig_init(self, base_dir=empty_dir)
monkeypatch.setattr(EvidenceStore, "__init__", _patched_init)
from typer.testing import CliRunner
from markidocx.cli import app
runner = CliRunner()
result = runner.invoke(app, ["evidence", "list"])
assert result.exit_code == 0
class TestEvidenceGetCommand:
def test_get_existing_run(self, store_with_run) -> None:
from typer.testing import CliRunner
from markidocx.cli import app
store, run_id = store_with_run
runner = CliRunner()
result = runner.invoke(app, ["evidence", "get", run_id])
assert result.exit_code == 0
assert run_id in result.output
def test_get_json(self, store_with_run) -> None:
from typer.testing import CliRunner
from markidocx.cli import app
store, run_id = store_with_run
runner = CliRunner()
result = runner.invoke(app, ["evidence", "get", run_id, "--json"])
assert result.exit_code == 0
data = json.loads(result.output.strip())
assert data["run_id"] == run_id
assert "classification" in data
def test_get_not_found(self, store_with_run) -> None:
from typer.testing import CliRunner
from markidocx.cli import app
runner = CliRunner()
result = runner.invoke(app, ["evidence", "get", "no-such-run-id"])
assert result.exit_code == 1
def test_get_output_file(self, store_with_run, tmp_path: Path) -> None:
from typer.testing import CliRunner
from markidocx.cli import app
store, run_id = store_with_run
out_file = tmp_path / "ev.json"
runner = CliRunner()
result = runner.invoke(app, ["evidence", "get", run_id, "--output", str(out_file)])
assert result.exit_code == 0
assert out_file.exists()
data = json.loads(out_file.read_text())
assert data["run_id"] == run_id