78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
import io
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from gyxx_flow.acceptance import build_acceptance_report, parse_plan_checklist
|
|
from gyxx_flow.cli import EXIT_ACCEPTANCE_INCOMPLETE, main
|
|
from gyxx_flow.core.config import Settings
|
|
from gyxx_flow.diagnostics import run_doctor
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def test_doctor_checks_interpreter_cli_config_paths_and_write_permission(tmp_path: Path) -> None:
|
|
settings = Settings(project_root=PROJECT_ROOT, data_root=tmp_path / "portable-data")
|
|
|
|
report = run_doctor(settings)
|
|
|
|
assert {check.name for check in report.checks} == {
|
|
"python",
|
|
"cli",
|
|
"project_root",
|
|
"catalog",
|
|
"data_root",
|
|
"data_root_write",
|
|
}
|
|
assert report.is_healthy is True
|
|
assert not (settings.data_root / ".gyxx-doctor-probe").exists()
|
|
|
|
|
|
def test_plan_parser_returns_stable_item_ids_and_completion(tmp_path: Path) -> None:
|
|
plan = tmp_path / "plan.md"
|
|
plan.write_text(
|
|
"- [x] P0.1 complete\n- [ ] P0.2 pending\n- [X] P1.1 complete too\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
items = parse_plan_checklist(plan)
|
|
|
|
assert [(item.item_id, item.completed) for item in items] == [
|
|
("P0.1", True),
|
|
("P0.2", False),
|
|
("P1.1", True),
|
|
]
|
|
|
|
|
|
def test_acceptance_report_is_machine_readable_and_tracks_real_evidence() -> None:
|
|
settings = Settings(project_root=PROJECT_ROOT, data_root=PROJECT_ROOT / "var")
|
|
|
|
report = build_acceptance_report(settings)
|
|
payload = report.as_dict()
|
|
|
|
assert payload["schema_version"] == 1
|
|
assert payload["summary"]["total"] > payload["summary"]["completed"]
|
|
assert payload["checks"]["catalog_21_tasks"] is True
|
|
assert payload["checks"]["baseline_21_tasks"] is True
|
|
assert payload["checks"]["secret_scan_clean"] is True
|
|
assert report.is_complete is False
|
|
|
|
|
|
def test_cli_doctor_and_acceptance_status_return_truthful_exit_codes(tmp_path: Path) -> None:
|
|
settings = Settings(project_root=PROJECT_ROOT, data_root=tmp_path / "data")
|
|
doctor_output = io.StringIO()
|
|
acceptance_output = io.StringIO()
|
|
|
|
assert main(["doctor", "--json"], settings=settings, stdout=doctor_output) == 0
|
|
assert json.loads(doctor_output.getvalue())["is_healthy"] is True
|
|
|
|
exit_code = main(
|
|
["acceptance", "status", "--json"],
|
|
settings=Settings(project_root=PROJECT_ROOT, data_root=PROJECT_ROOT / "var"),
|
|
stdout=acceptance_output,
|
|
)
|
|
assert exit_code == EXIT_ACCEPTANCE_INCOMPLETE
|
|
assert json.loads(acceptance_output.getvalue())["is_complete"] is False
|
|
|