8OI-534 / FS-513 — ``oct diag validate-config --strict`` promotes
9WARNING-level issues to failures and returns exit code 2 so CI can
10distinguish a strict-mode config audit failure from the generic exit 1
11used by the non-strict path (reserved for ERROR-level schema problems).
13The tests use a temporary ``oc_diagnostics/debug_config.json`` layout so
14we never touch the real project config.
18- Verify non-strict mode: ERROR exits 1, WARNING exits 0.
19- Verify strict mode: both ERROR and WARNING exit 2, clean exits 0.
26 L3 — assertion details
31- Non-strict: ERROR → exit 1, WARNING → exit 0.
32- Strict: ERROR → exit 2, WARNING → exit 2, clean → exit 0.
35from __future__
import annotations
39from pathlib
import Path
42from click.testing
import CliRunner
48 """Drop a debug_config.json at ``<root>/oc_diagnostics/`` and return it.
50 ``find_project_root`` anchors on ``.octrc.json`` with ``root_marker``
51 set — use that rather than simulating the full ``docs/tests/...``
52 layout so the fixture stays lean.
54 cfg_dir = project_root /
"oc_diagnostics"
55 cfg_dir.mkdir(parents=
True, exist_ok=
True)
56 cfg = cfg_dir /
"debug_config.json"
57 cfg.write_text(json.dumps(payload, indent=2), encoding=
"utf-8")
58 (project_root /
".octrc.json").write_text(
59 json.dumps({
"root_marker":
True}), encoding=
"utf-8",
65 """Run ``oct diag validate-config ...`` with cwd pinned to ``cwd``."""
70 return runner.invoke(cli, [
"diag",
"validate-config", *args])
76 """OI-534: a fully-valid config exits 0 regardless of --strict."""
78 "_schema_version":
"2.0",
79 "DEBUG_LEVELS": {
"GENERAL": {
"level": 2,
"color":
"default"}},
80 "global_settings": {
"output_mode":
"both",
"mode":
"dev"},
82 for args
in ([], [
"--strict"]):
83 result =
_invoke(tmp_path, *args)
84 assert result.exit_code == 0, (args, result.output)
88 """OI-534: WARNING issues alone exit 0 when --strict is absent."""
90 _write_config(tmp_path, {
"domains": {
"GENERAL": {
"level": 2}}})
92 assert result.exit_code == 0, result.output
93 assert "WARNING" in result.output
97 """OI-534: --strict promotes WARNING to exit 2."""
98 _write_config(tmp_path, {
"domains": {
"GENERAL": {
"level": 2}}})
99 result =
_invoke(tmp_path,
"--strict")
100 assert result.exit_code == 2, result.output
101 assert "WARNING" in result.output
105 """OI-534: non-strict ERROR → exit 1 (preserves legacy behaviour)."""
108 "_schema_version":
"2.0",
109 "DEBUG_LEVELS": {
"GENERAL": {
"level": 99,
"color":
"default"}},
110 "global_settings": {
"output_mode":
"both",
"mode":
"dev"},
113 assert result.exit_code == 1, result.output
114 assert "ERROR" in result.output
118 """OI-534: --strict upgrades ERROR exit from 1 to 2."""
120 "_schema_version":
"2.0",
121 "DEBUG_LEVELS": {
"GENERAL": {
"level": 99,
"color":
"default"}},
122 "global_settings": {
"output_mode":
"both",
"mode":
"dev"},
124 result =
_invoke(tmp_path,
"--strict")
125 assert result.exit_code == 2, result.output
126 assert "ERROR" in result.output
Path _write_config(Path project_root, dict payload)
test_error_config_exits_two_with_strict(Path tmp_path)
test_warning_only_config_fails_with_strict(Path tmp_path)
test_warning_only_config_passes_without_strict(Path tmp_path)
_invoke(Path cwd, *str args)
test_clean_config_exits_zero_in_both_modes(Path tmp_path)
test_error_config_exits_one_without_strict(Path tmp_path)