Option C Tools
Loading...
Searching...
No Matches
test_profile_matrix_optional.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_git/test_profile_matrix_optional.py
4
5"""
6Purpose
7-------
8OI-531 regression coverage — the ``"optional"`` tier in
9:data:`oct.git.policy.PROFILE_MATRIX` must be truly non-blocking:
10the check runs and its failures are reported, but the CLI exit code
11stays at 0 for that tier alone.
12
13Before OI-531 the policy layer treated ``"optional"`` identically to
14``"blocking"`` at [oct/oct/git/policy.py:381](oct/oct/git/policy.py#L381),
15which meant ``oct git commit`` under the compact profile would exit 4
16on any test failure. The user confirmed the intended semantics: compact
17should flag test failures but let the commit through.
18
19Responsibilities
20----------------
21- ``compact`` profile + test failures → exit code 0.
22- ``strict`` profile + test failures → exit code 4 (still blocking).
23- :data:`PROFILE_MATRIX` docstring documents all three tier values.
24
25Diagnostics
26-----------
27Domain: GIT-TESTS
28Levels:
29 L2 — test lifecycle
30 L3 — assertion details
31 L4 — deep tracing
32
33Contracts
34---------
35- Tests use in-memory mock objects; no subprocess or filesystem writes.
36"""
37
38from __future__ import annotations
39
40from types import SimpleNamespace
41
42from oct.git import policy
43from oct.git.policy import PROFILE_MATRIX, apply_profile_policy
44
45
46def _gate_result(**overrides) -> SimpleNamespace:
47 defaults = dict(
48 lint_violations=0,
49 format_violations=0,
50 secrets_findings=[],
51 test_failures=0,
52 )
53 defaults.update(overrides)
54 return SimpleNamespace(**defaults)
55
56
58 assert PROFILE_MATRIX["compact"]["tests"] == "optional"
59 result = _gate_result(test_failures=5)
60
61 assert apply_profile_policy("compact", result) == 0
62
63
65 assert PROFILE_MATRIX["strict"]["tests"] == "blocking"
66 result = _gate_result(test_failures=1)
67
68 assert apply_profile_policy("strict", result) == 4
69
70
72 # The PROFILE_MATRIX module-level docstring must spell out every
73 # legal tier value so future contributors know what "optional"
74 # actually means.
75 src = policy.__doc__ or ""
76 source_text = __import__("inspect").getsource(policy)
77 for tier in ("blocking", "optional", "skip"):
78 assert tier in source_text