forked from ChelseaKR/perimeter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_standards_conformance.py
More file actions
149 lines (115 loc) · 5.26 KB
/
Copy pathtest_standards_conformance.py
File metadata and controls
149 lines (115 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""The standards pin and the conformance table have to be read by something.
DOC-01 wants `.standards-version` to name a released tag. DOC-11 wants the README's
Standards Conformance table to carry all fifteen standards, each with a non-empty state.
Both are AUTO-GATEs, which means a file sitting in the repository is not enough: a pin
nothing parses is decoration, and decoration is the failure mode this repository spent
2026-08-15 removing. These tests are the reader. They run inside `make verify`, so they
run in CI, and they fail when the pin drifts to a branch, when a standard is dropped from
the table, or when a row is left blank.
What they cannot check is whether a state is *true*. `tests/test_provenance.py` is the
model for the parts that can be checked mechanically; the rest is a review obligation and
is named as one here rather than implied to be automatic.
"""
from __future__ import annotations
import re
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
PIN = ROOT / ".standards-version"
README = (ROOT / "README.md").read_text(encoding="utf-8")
RELEASED_TAG = re.compile(r"^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$")
STANDARDS = (
"Code Quality",
"Security & Supply-Chain",
"CI/CD",
"Observability",
"Accessibility",
"Internationalization",
"AI Evaluation",
"Quality & Metrics",
"Documentation",
"Release & Versioning",
"Responsible-Tech Framework",
"Performance",
"Incident Response",
"Data Governance",
"AI Development Measurement",
)
# The verdict has to be the first thing in the cell, and it has to be one of these
# forms. The punctuation is not decoration: the portfolio's conformance reader accepts
# a verdict only when the character straight after `Applies` is whitespace, `:`, `(`,
# `-` or an em dash, so `Applies.` and `Applies, not met.` were unreadable to it and
# this table's fifteen honest rows scored as one invalid state. Keep any new form
# inside that grammar.
STATES = (
"Applies:",
"Applies (not met)",
"Applies (Tier",
"Applies (L",
"N/A (",
)
def pin() -> str:
return PIN.read_text(encoding="utf-8").strip()
def conformance_rows() -> dict[str, str]:
"""The table under `## Standards conformance`, as {standard: state}."""
section = README.split("## Standards conformance", 1)
assert len(section) == 2, (
"README has no '## Standards conformance' section (DOC-11)"
)
body = section[1].split("\n## ", 1)[0]
rows: dict[str, str] = {}
for line in body.splitlines():
if not line.startswith("|"):
continue
cells = [cell.strip() for cell in line.strip("|").split("|")]
if (
len(cells) != 2
or cells[0] in {"Standard", ""}
or set(cells[0]) <= {"-", ":"}
):
continue
rows[cells[0]] = cells[1]
return rows
# --- DOC-01: the pin ----------------------------------------------------------------
def test_the_standards_pin_exists() -> None:
assert PIN.is_file(), ".standards-version is missing (DOC-01)"
def test_the_standards_pin_names_a_released_tag() -> None:
"""Never `main`, never a `heads/` ref: a moving pin is not a pin."""
value = pin()
assert RELEASED_TAG.match(value), (
f".standards-version is {value!r}; DOC-01 wants a vMAJOR.MINOR.PATCH tag"
)
assert value != "main"
assert not value.startswith(("heads/", "refs/"))
def test_the_readme_cites_the_pinned_version() -> None:
"""If the pin moves and the table still names the old one, one of them is lying."""
assert f"`{pin()}`" in README, (
f"README does not cite the pinned standards version {pin()!r}"
)
# --- DOC-11: the conformance table --------------------------------------------------
@pytest.mark.parametrize("standard", STANDARDS)
def test_every_standard_has_a_row(standard: str) -> None:
assert standard in conformance_rows(), (
f"'{standard}' is missing from the Standards Conformance table (DOC-11)"
)
@pytest.mark.parametrize("standard", STANDARDS)
def test_no_row_is_blank(standard: str) -> None:
state = conformance_rows().get(standard, "")
assert state.strip(), f"'{standard}' has a blank state (DOC-11)"
@pytest.mark.parametrize("standard", STANDARDS)
def test_every_state_opens_with_a_recognised_verdict(standard: str) -> None:
"""A gap has to be recorded as a gap. Prose that avoids saying which is not a state."""
state = conformance_rows().get(standard, "")
assert state.startswith(STATES), (
f"'{standard}' opens with {state[:40]!r}; expected one of {STATES}"
)
def test_the_table_carries_no_standard_this_portfolio_does_not_have() -> None:
unknown = set(conformance_rows()) - set(STANDARDS)
assert not unknown, f"unrecognised standards in the table: {sorted(unknown)}"
def test_the_table_says_the_applicability_manifest_has_no_entry_for_this_repo() -> None:
"""FIX-02. Remove this test on the day the manifest entry exists, not before.
The scoping above was derived from each standard's own applicability section rather
than read from the registry, and a reader is owed that caveat while it is true.
"""
section = README.split("## Standards conformance", 1)[1].split("\n## ", 1)[0]
assert "applicability manifest has no entry" in section