Option C Tools
Loading...
Searching...
No Matches
test_audit_stub.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_audit/test_audit_stub.py
4
5"""
6Purpose
7-------
8FS-539 / FS-501 (stub) regression coverage — :func:`oct.audit.oct_audit.run_audit`
9returns the correct stage + exit code for every ``oc_status.json`` state.
10
11Responsibilities
12----------------
13- Verify compliant project returns stage ``"compliant"`` and exit code 0.
14- Verify bootstrap / migrating / missing states return the correct stage
15 and exit code.
16
17Diagnostics
18-----------
19Domain: AUDIT-TESTS
20 Levels:
21 L2 — test lifecycle
22 L3 — assertion details
23 L4 — deep tracing
24
25Contracts
26---------
27- All operations use ``tmp_path`` as the project root; no real project
28 files are touched.
29"""
30
31from __future__ import annotations
32
33import json
34from pathlib import Path
35
36from oct.audit.oct_audit import AuditResult, run_audit
37from oct.core.option_c_dir import OcStatus, write_oc_status
38
39
40def test_compliant_project(tmp_path: Path):
41 status = OcStatus(
42 stage="compliant",
43 pillars={
44 name: {"enabled": True, "since": "2026-04-17"}
45 for name in ("linter", "diagnostics", "git", "docs", "tests", "scaffold")
46 },
47 migrated_from={},
48 oct_version_at_migration="0.19.0",
49 )
50 write_oc_status(tmp_path, status)
51
52 result = run_audit(tmp_path)
53 assert result.stage == "compliant"
54 assert result.exit_code == 0
55 assert isinstance(result, AuditResult)
56
57
58def test_migrating_project(tmp_path: Path):
59 status = OcStatus(
60 stage="migrating",
61 pillars={"linter": {"enabled": True, "since": "2026-04-17"}},
62 migrated_from={"octrc": ".octrc.json"},
63 oct_version_at_migration="0.19.0",
64 )
65 write_oc_status(tmp_path, status)
66
67 result = run_audit(tmp_path)
68 assert result.stage == "migrating"
69 assert result.exit_code == 1
70 assert result.migrated_from["octrc"] == ".octrc.json"
71
72
73def test_bootstrap_project(tmp_path: Path):
74 status = OcStatus(
75 stage="bootstrap",
76 pillars={},
77 migrated_from={},
78 oct_version_at_migration="0.19.0",
79 )
80 write_oc_status(tmp_path, status)
81
82 result = run_audit(tmp_path)
83 assert result.stage == "bootstrap"
84 assert result.exit_code == 2
85
86
87def test_unmigrated_project(tmp_path: Path):
88 result = run_audit(tmp_path)
89 assert result.stage is None
90 assert result.exit_code == 3
91
92
93def test_corrupt_status_file(tmp_path: Path):
94 (tmp_path / ".option_c").mkdir()
95 (tmp_path / ".option_c" / "oc_status.json").write_text(
96 "{ not json", encoding="utf-8",
97 )
98 result = run_audit(tmp_path)
99 assert result.stage is None
100 assert result.exit_code == 3
test_migrating_project(Path tmp_path)
test_corrupt_status_file(Path tmp_path)
test_compliant_project(Path tmp_path)
test_unmigrated_project(Path tmp_path)
test_bootstrap_project(Path tmp_path)