8FS-504 regression coverage — ``oct health`` must surface a prominent
9top-of-report banner when the operator runs the dashboard from outside
10a virtual environment. The banner is what upgrades "naked Python" from
11an easily-missed per-section ``[WARN]`` into something the operator
12cannot overlook before reading the rest of the report.
14The banner uses ``!`` as the rule character (70 columns) and carries
15the literal string "WARNING: not running inside a virtual environment.".
25- ``venv.active == False`` → banner rendered.
26- ``venv.active == True`` → banner absent (per-section [OK] still there).
27- Banner never appears in JSON output (machine-readable path unchanged).
30from __future__
import annotations
34from contextlib
import redirect_stdout
41_BANNER_TEXT =
"WARNING: not running inside a virtual environment."
45 """Smallest ``report`` dict that satisfies ``_print_terminal_report``."""
48 "oct_version":
"0.17.0",
49 "timestamp":
"2026-04-16T00:00:00",
55 "compliance_pct": 100.0,
59 "fixable": {
"total": 0},
60 "docs": {
"total_present": 0,
"total_required": 0,
"files": []},
61 "tests": {
"status":
"skip",
"summary":
""},
63 "installed":
True,
"compatible":
True,
"version":
"0.0.0",
"message":
"",
66 "active": venv_active,
67 "venv_found": venv_active,
68 "own_venv": venv_active,
69 "status":
"OK" if venv_active
else "WARN",
70 "message":
"Project .venv active" if venv_active
else "No venv active.",
79 with redirect_stdout(buf):
80 _print_terminal_report(report, verbose=
False)
85 """FS-504: banner appears once and lands above the per-section summary."""
87 assert _BANNER_TEXT
in out
88 banner_pos = out.index(_BANNER_TEXT)
90 assert banner_pos < out.index(
"Virtual Env:")
92 assert out.count(_BANNER_TEXT) == 1
96 """FS-504: active venv → no banner; [OK] status still visible."""
98 assert _BANNER_TEXT
not in out
99 assert "Virtual Env:" in out
104 """FS-504: JSON output is machine-readable — never gains a banner."""
106 captured = capsys.readouterr().out
107 parsed = json.loads(captured)
108 assert parsed[
"venv"][
"active"]
is False
109 assert _BANNER_TEXT
not in captured
113 """FS-504: banner body mentions the exact ``python -m venv .venv`` remedy."""
115 assert "python -m venv .venv" in out
test_banner_copy_instructs_venv_creation()
test_banner_absent_in_json_output(pytest.CaptureFixture capsys)
test_banner_absent_when_venv_active()
test_banner_renders_when_venv_inactive()
dict _minimal_report(*, bool venv_active)