Files

64 lines
1.7 KiB
Python

"""Subprocess-level integration tests for CLI consolidate.py verifying normative exit codes."""
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
CLI_PATH = (
Path(__file__).resolve().parent.parent.parent.parent
/ "src"
/ "runtime"
/ "cli"
/ "consolidate.py"
)
def test_cli_subprocess_invalid_schema_exit_code_1(tmp_path: Path):
"""Passing an invalid article JSON (missing url/title/etc) exits with code 1."""
bad_article = tmp_path / "bad_art.json"
bad_article.write_text(json.dumps({"invalid": "payload"}), encoding="utf-8")
ecp_file = Path("examples/sample_ecp_snapshot.json")
config_file = Path("runtime_config.local.json")
res = subprocess.run(
[
sys.executable,
str(CLI_PATH),
"--config",
str(config_file),
"--article",
str(bad_article),
"--ecp",
str(ecp_file),
],
capture_output=True,
text=True,
)
assert res.returncode == 1
def test_cli_subprocess_missing_config_exit_code_2(tmp_path: Path):
"""Passing a nonexistent config file exits with code 2 (preflight/config error)."""
article_file = Path("examples/sample_article_valid.json")
ecp_file = Path("examples/sample_ecp_snapshot.json")
res = subprocess.run(
[
sys.executable,
str(CLI_PATH),
"--config",
"nonexistent_config_123.json",
"--article",
str(article_file),
"--ecp",
str(ecp_file),
],
capture_output=True,
text=True,
)
assert res.returncode == 2