flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
test_no_env_knobs.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""QUALITY_PLAN decision D3 guard: no environment variable in `src/` may change a result.
3
4Package E (2026-09-08) turned every numerics-changing / algorithm-selecting `PECLET_FLOW_*` read
5into a solver setter or deleted it with the ablation it served. What is still allowed to be read
6from the environment is instrumentation only -- `*_DEBUG`, `*_VERBOSE`, `*_PROFILE*`, `*_TIMEOUT`,
7`GPU_AWARE_MPI` -- because none of it touches an arithmetic path. This test fails if a new
8`getenv` appears in `src/` outside that allow-list, which is the whole point: the next knob has to
9be a setter.
10"""
11import pathlib
12import re
13import sys
14
15ALLOWED = re.compile(r"_DEBUG(_[A-Z0-9_]+)?$|_VERBOSE$|_PROFILE|_TIMEOUT$|^GPU_AWARE_MPI$")
16GETENV = re.compile(r'getenv\‍(\s*"([A-Za-z0-9_]+)"')
17
18SRC = pathlib.Path(__file__).resolve().parents[2] / "src"
19
20
22 offenders = []
23 for path in sorted(SRC.rglob("*")):
24 if path.suffix not in (".hpp", ".cpp", ".h"):
25 continue
26 for lineno, line in enumerate(path.read_text().splitlines(), 1):
27 for name in GETENV.findall(line):
28 if not ALLOWED.search(name):
29 offenders.append(f"{path.relative_to(SRC.parent)}:{lineno}: {name}")
30 assert not offenders, (
31 "environment variables that can change a result found in src/ (QUALITY_PLAN D3 -- make it "
32 "a setter):\n " + "\n ".join(offenders)
33 )
34
35
36if __name__ == "__main__":
37 try:
39 except AssertionError as e:
40 print(e)
41 sys.exit(1)
42 print("no numerics-changing environment reads in src/ [OK]")