courant-dev 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- courant/__init__.py +26 -0
- courant/case/__init__.py +0 -0
- courant/case/_foam_reader.py +269 -0
- courant/case/config.py +134 -0
- courant/case/mesh.py +135 -0
- courant/case/reads.py +90 -0
- courant/case/schemes.py +99 -0
- courant/case/solvers.py +170 -0
- courant/cli/__init__.py +0 -0
- courant/cli/commands/__init__.py +6 -0
- courant/cli/commands/audit.py +40 -0
- courant/cli/commands/convergence.py +68 -0
- courant/cli/commands/ctest.py +76 -0
- courant/cli/commands/doctor.py +162 -0
- courant/cli/commands/gate.py +88 -0
- courant/cli/commands/live.py +73 -0
- courant/cli/commands/mcp.py +57 -0
- courant/cli/commands/preflight.py +36 -0
- courant/cli/commands/spec.py +231 -0
- courant/cli/commands/tour.py +122 -0
- courant/cli/commands/update.py +213 -0
- courant/cli/commands/verify.py +222 -0
- courant/cli/config.py +244 -0
- courant/cli/guard.py +69 -0
- courant/cli/main.py +130 -0
- courant/cli/tail.py +351 -0
- courant/config.py +155 -0
- courant/converge/__init__.py +57 -0
- courant/converge/assess.py +823 -0
- courant/converge/exact.py +112 -0
- courant/converge/render.py +182 -0
- courant/converge/scale.py +87 -0
- courant/converge/sentences.py +82 -0
- courant/converge/series.py +413 -0
- courant/converge/steady.py +261 -0
- courant/converge/tables.py +1019 -0
- courant/converge/transient.py +314 -0
- courant/ctest/__init__.py +6 -0
- courant/ctest/build.py +82 -0
- courant/ctest/data/judge-v0.labels.jsonl +31 -0
- courant/ctest/data/judge-v0.tasks.jsonl.gz +0 -0
- courant/ctest/judges/__init__.py +27 -0
- courant/ctest/judges/constant.py +18 -0
- courant/ctest/judges/courant.py +23 -0
- courant/ctest/judges/llm.py +166 -0
- courant/ctest/run.py +74 -0
- courant/ctest/schema.py +46 -0
- courant/ctest/score.py +91 -0
- courant/ctest/splits.py +20 -0
- courant/data/__init__.py +46 -0
- courant/data/certification.json +1 -0
- courant/data/certified_codes.json +18 -0
- courant/data/demo/icoFoam_cavity__cfl_blowup.case.json +68 -0
- courant/data/demo/icoFoam_cavity__cfl_blowup.log.gz +0 -0
- courant/data/demo/icoFoam_cavity__healthy.case.json +68 -0
- courant/data/demo/icoFoam_cavity__healthy.log.gz +0 -0
- courant/data/demo/icoFoam_cavity__transport_units.case.json +68 -0
- courant/data/demo/icoFoam_cavity__transport_units.log.gz +0 -0
- courant/data/demo/pitzDaily_fixed_budget.tar.gz +0 -0
- courant/data/schemas/audit.1.json +129 -0
- courant/data/schemas/cache.1.json +77 -0
- courant/data/schemas/convergence.1.json +112 -0
- courant/data/schemas/error-rates.1.json +53 -0
- courant/data/schemas/preflight.1.json +250 -0
- courant/data/schemas/record.1.json +155 -0
- courant/data/schemas/release-signature.1.json +39 -0
- courant/data/schemas/spec.1.json +258 -0
- courant/data/schemas/support.1.json +80 -0
- courant/data/schemas/verdict.1.json +716 -0
- courant/data/schemas/verdict.2.json +752 -0
- courant/diagnosis/__init__.py +0 -0
- courant/diagnosis/bundle.py +168 -0
- courant/diagnosis/checkers.py +919 -0
- courant/diagnosis/deterministic.py +110 -0
- courant/diagnosis/findings.py +107 -0
- courant/diagnosis/kb.py +188 -0
- courant/diagnosis/kb_data.py +253 -0
- courant/diagnosis/llm.py +299 -0
- courant/diagnosis/redact.py +425 -0
- courant/diagnosis/schema.py +83 -0
- courant/events/__init__.py +35 -0
- courant/events/core.py +194 -0
- courant/events/diverged.py +55 -0
- courant/gate/__init__.py +1 -0
- courant/gate/config.py +150 -0
- courant/gate/run.py +295 -0
- courant/live/__init__.py +16 -0
- courant/live/engine.py +155 -0
- courant/live/watch.py +164 -0
- courant/llm/__init__.py +59 -0
- courant/llm/allowlist.py +60 -0
- courant/llm/anthropic.py +137 -0
- courant/llm/budget.py +491 -0
- courant/llm/door.py +1071 -0
- courant/llm/errors.py +105 -0
- courant/llm/openrouter.py +118 -0
- courant/llm/policy.py +268 -0
- courant/llm/transport.py +48 -0
- courant/mcp/__init__.py +7 -0
- courant/mcp/server.py +113 -0
- courant/mcp/tools.py +177 -0
- courant/record/__init__.py +22 -0
- courant/record/filter.py +99 -0
- courant/record/record.py +149 -0
- courant/release.py +205 -0
- courant/signing.py +99 -0
- courant/spec/__init__.py +31 -0
- courant/spec/check.py +353 -0
- courant/spec/deck.py +455 -0
- courant/spec/extract.py +181 -0
- courant/spec/impossible.py +197 -0
- courant/spec/model.py +194 -0
- courant/taxonomy.py +219 -0
- courant/verification/__init__.py +30 -0
- courant/verification/_fluid_reader.py +228 -0
- courant/verification/bounding.py +84 -0
- courant/verification/checks.py +369 -0
- courant/verification/convergence.py +257 -0
- courant/verification/fields.py +38 -0
- courant/verification/grade.py +101 -0
- courant/verification/suite.py +30 -0
- courant/verify/__init__.py +37 -0
- courant/verify/about.py +100 -0
- courant/verify/audit.py +209 -0
- courant/verify/batch.py +141 -0
- courant/verify/cache.py +329 -0
- courant/verify/checks.py +37 -0
- courant/verify/html.py +330 -0
- courant/verify/ingest.py +115 -0
- courant/verify/junit.py +48 -0
- courant/verify/outcome.py +74 -0
- courant/verify/pack.py +106 -0
- courant/verify/pipeline.py +396 -0
- courant/verify/policy.py +167 -0
- courant/verify/preflight.py +166 -0
- courant/verify/render.py +174 -0
- courant/verify/schema.py +398 -0
- courant/verify/sentences.py +137 -0
- courant/verify/support.py +142 -0
- courant/verify/verdict2.py +235 -0
- courant/watcher/__init__.py +13 -0
- courant/watcher/anomaly.py +244 -0
- courant/watcher/exitcode.py +23 -0
- courant/watcher/parser.py +435 -0
- courant/watcher/watcher.py +49 -0
- courant_dev-0.5.0.dist-info/METADATA +146 -0
- courant_dev-0.5.0.dist-info/RECORD +152 -0
- courant_dev-0.5.0.dist-info/WHEEL +5 -0
- courant_dev-0.5.0.dist-info/entry_points.txt +3 -0
- courant_dev-0.5.0.dist-info/licenses/LICENSE +202 -0
- courant_dev-0.5.0.dist-info/licenses/NOTICE +4 -0
- courant_dev-0.5.0.dist-info/top_level.txt +1 -0
courant/verify/checks.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Checks behind `--checks next` (TRD GATE-13).
|
|
2
|
+
|
|
3
|
+
A new check ships here first: its findings are left out of every verdict unless the run is
|
|
4
|
+
verified with `--checks next`, and a verdict that ran them says so (`tool.checks: "next"`). After
|
|
5
|
+
one minor release it is promoted: its id leaves `NEXT` and it is on by default, and the release's
|
|
6
|
+
changelog counts the verdicts it turned on the corpus (`scripts/release.py`, GATE-13).
|
|
7
|
+
|
|
8
|
+
`NEXT` maps a finding id (`courant.diagnosis.checkers`) to the version it shipped in. Today no
|
|
9
|
+
check is behind the flag.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
MODES = ("default", "next")
|
|
15
|
+
|
|
16
|
+
#: {finding id: the version it shipped in behind `--checks next`}.
|
|
17
|
+
NEXT: dict[str, str] = {}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def enabled(finding_id: str, mode: str = "default") -> bool:
|
|
21
|
+
"""Whether a finding enters the verdict under this mode."""
|
|
22
|
+
if mode not in MODES:
|
|
23
|
+
raise ValueError(f"--checks is one of {', '.join(MODES)}, not {mode!r}")
|
|
24
|
+
return mode == "next" or finding_id not in NEXT
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def only_enabled(finding_set, mode: str = "default"):
|
|
28
|
+
"""The findings that enter the verdict under this mode, in their order."""
|
|
29
|
+
from courant.diagnosis.findings import FindingSet
|
|
30
|
+
|
|
31
|
+
if mode == "next" or not NEXT:
|
|
32
|
+
enabled("", mode) # still refuse an unknown mode
|
|
33
|
+
return finding_set
|
|
34
|
+
return FindingSet([f for f in finding_set if enabled(f.id, mode)])
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
__all__ = ["MODES", "NEXT", "enabled", "only_enabled"]
|
courant/verify/html.py
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"""The HTML evidence report: one self-contained file a manager can open (TRD REP-6).
|
|
2
|
+
|
|
3
|
+
The page loads nothing from the network, has inline CSS and SVG, runs no JavaScript, and its
|
|
4
|
+
bytes depend only on the verdict, the inputs and the packaged error rates. It has no timestamp
|
|
5
|
+
and no absolute path. Every number printed as text is in the verdict JSON (REP-2), except the
|
|
6
|
+
error rates in the footer, which are read from the packaged results (GATE-12). The charts are drawn from the
|
|
7
|
+
log and the monitor files the verdict lists among its inputs, and are captioned as such.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import math
|
|
13
|
+
from html import escape
|
|
14
|
+
|
|
15
|
+
from courant.verify import about
|
|
16
|
+
from courant.verify.verdict2 import AnyVerdict, VerdictV2
|
|
17
|
+
|
|
18
|
+
W, H = 760, 220
|
|
19
|
+
PAD_L, PAD_R, PAD_T, PAD_B = 84, 14, 14, 30
|
|
20
|
+
MAX_POINTS = 800
|
|
21
|
+
PALETTE = ("var(--s1)", "var(--s2)", "var(--s3)", "var(--s4)", "var(--s5)", "var(--s6)")
|
|
22
|
+
#: SVG dash patterns, one per series beside its colour (WCAG 1.4.1: not colour alone). The
|
|
23
|
+
#: first is solid. The legend swatch draws the same pattern.
|
|
24
|
+
DASHES = ((), (7, 3), (1.5, 3), (7, 3, 1.5, 3), (3, 3), (11, 4))
|
|
25
|
+
|
|
26
|
+
CSS = """
|
|
27
|
+
:root{--bg:#fbfbfa;--fg:#1d1f21;--muted:#5f6368;--line:#e3e3e0;--card:#ffffff;
|
|
28
|
+
--ok:#1f7a4d;--bad:#b42318;--warn:#a15c07;--s1:#2f6fb3;--s2:#c4472f;--s3:#2f8f5b;
|
|
29
|
+
--s4:#8a5cb5;--s5:#a87a0a;--s6:#4a4a4a;--shade:rgba(47,111,179,.08);--on-fill:#ffffff}
|
|
30
|
+
@media (prefers-color-scheme:dark){:root{--bg:#141516;--fg:#e8e8e6;--muted:#a3a5a8;
|
|
31
|
+
--line:#2c2e30;--card:#1b1c1e;--ok:#4cc38a;--bad:#ff6b5c;--warn:#f0a43a;--s1:#6ea8fe;
|
|
32
|
+
--s2:#ff8a73;--s3:#5fd39a;--s4:#c39bf0;--s5:#e8c25a;--s6:#bdbdbd;--shade:rgba(110,168,254,.10);
|
|
33
|
+
--on-fill:#141516}}
|
|
34
|
+
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--fg);
|
|
35
|
+
font:15px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
36
|
+
main{max-width:860px;margin:0 auto;padding:28px 16px 56px}
|
|
37
|
+
h1{font-size:22px;margin:0 0 4px}h2{font-size:16px;margin:28px 0 10px;letter-spacing:.02em}
|
|
38
|
+
.meta{color:var(--muted);font-size:13px}.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
39
|
+
.badge{display:inline-block;padding:4px 10px;border-radius:6px;font-weight:600;font-size:14px;
|
|
40
|
+
color:var(--on-fill);margin-right:8px}.TRUSTWORTHY{background:var(--ok)}.NOT_TRUSTWORTHY{background:var(--bad)}
|
|
41
|
+
.NOT_ASSESSABLE{background:var(--warn)}.card{background:var(--card);border:1px solid var(--line);
|
|
42
|
+
border-radius:10px;padding:14px 16px;margin:10px 0}table{border-collapse:collapse;width:100%;font-size:13px}
|
|
43
|
+
th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line);vertical-align:top}
|
|
44
|
+
th{color:var(--muted);font-weight:600}td.num{font-family:ui-monospace,Menlo,monospace;white-space:nowrap}
|
|
45
|
+
.scroll{overflow-x:auto}svg{width:100%;height:auto;display:block}svg text{fill:var(--muted);font-size:11px}
|
|
46
|
+
.axis{stroke:var(--muted)}.cap{color:var(--muted);font-size:12px;margin-top:4px}ul{margin:6px 0;padding-left:20px}
|
|
47
|
+
.legend span{display:inline-block;margin-right:12px;font-size:12px;color:var(--muted)}
|
|
48
|
+
.legend i{display:inline-block;width:24px;height:3px;margin-right:6px;vertical-align:middle}
|
|
49
|
+
footer{max-width:860px;margin:0 auto;padding:0 16px 40px;color:var(--muted);font-size:12px}
|
|
50
|
+
.sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;
|
|
51
|
+
clip:rect(0 0 0 0);white-space:nowrap;border:0}
|
|
52
|
+
:focus-visible{outline:3px solid var(--s1);outline-offset:2px}
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _f(x: float) -> str:
|
|
57
|
+
return f"{x:.1f}"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _table(label: str, headers: tuple[str, ...], rows: list[str]) -> str:
|
|
61
|
+
"""A data table a keyboard and a screen reader can use (WCAG 1.3.1, 2.1.1, 4.1.2).
|
|
62
|
+
|
|
63
|
+
The scrolling region is focusable and named, the table has a caption, and every column has
|
|
64
|
+
a header cell with its scope.
|
|
65
|
+
"""
|
|
66
|
+
head = "".join(f'<th scope="col">{escape(h)}</th>' for h in headers)
|
|
67
|
+
return (f'<div class="scroll" role="region" tabindex="0" aria-label="{escape(label)}">'
|
|
68
|
+
f'<table><caption class="sr">{escape(label)}</caption><thead><tr>{head}</tr></thead>'
|
|
69
|
+
f'<tbody>{"".join(rows)}</tbody></table></div>')
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _swatch(index: int) -> str:
|
|
73
|
+
"""The legend's sample of a series: its colour, drawn with its dash pattern."""
|
|
74
|
+
colour = PALETTE[index % len(PALETTE)]
|
|
75
|
+
dash = DASHES[index % len(DASHES)]
|
|
76
|
+
if not dash:
|
|
77
|
+
return f'<i aria-hidden="true" style="background:{colour}"></i>'
|
|
78
|
+
pattern = list(dash) if len(dash) % 2 == 0 else list(dash) * 2
|
|
79
|
+
stops, pos = [], 0.0
|
|
80
|
+
for k, seg in enumerate(pattern):
|
|
81
|
+
c = colour if k % 2 == 0 else "transparent"
|
|
82
|
+
stops.append(f"{c} {pos:g}px {pos + seg:g}px")
|
|
83
|
+
pos += seg
|
|
84
|
+
return (f'<i aria-hidden="true" style="background:repeating-linear-gradient(90deg,'
|
|
85
|
+
f'{",".join(stops)})"></i>')
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _decimate(points: list[tuple[float, float]]) -> list[tuple[float, float]]:
|
|
89
|
+
if len(points) <= MAX_POINTS:
|
|
90
|
+
return points
|
|
91
|
+
stride = -(-len(points) // MAX_POINTS)
|
|
92
|
+
out = points[::stride]
|
|
93
|
+
if out[-1] != points[-1]:
|
|
94
|
+
out.append(points[-1])
|
|
95
|
+
return out
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _chart(series: dict[str, list[tuple[float, float]]], *, log_y: bool, title: str, cid: str,
|
|
99
|
+
marker: float | None = None, marker_label: str = "", skip_start: float = 0.0) -> str:
|
|
100
|
+
"""One SVG line chart. Coordinates are rounded to 0.1 px, so the bytes are stable.
|
|
101
|
+
|
|
102
|
+
`title` names the chart and `cid` makes its ids unique on the page. The chart has a title and
|
|
103
|
+
a description a screen reader announces, and each series has its own dash pattern as well as
|
|
104
|
+
its colour (WCAG 1.1.1, 1.4.1).
|
|
105
|
+
"""
|
|
106
|
+
clean: dict[str, list[tuple[float, float]]] = {}
|
|
107
|
+
for name, pts in series.items():
|
|
108
|
+
keep = [(x, (math.log10(y) if log_y else y)) for x, y in pts
|
|
109
|
+
if math.isfinite(y) and (y > 0 or not log_y)]
|
|
110
|
+
if keep:
|
|
111
|
+
clean[name] = _decimate(keep)
|
|
112
|
+
if not clean:
|
|
113
|
+
return ""
|
|
114
|
+
xs = [p[0] for pts in clean.values() for p in pts]
|
|
115
|
+
x0, x1 = min(xs), max(xs)
|
|
116
|
+
# The y-range ignores the opening `skip_start` of the run (a first-iteration value can be
|
|
117
|
+
# orders away from the answer and flatten everything after it). Points outside it are
|
|
118
|
+
# clipped to the frame rather than dropped.
|
|
119
|
+
cut = x0 + (x1 - x0) * skip_start
|
|
120
|
+
ys = [p[1] for pts in clean.values() for p in pts if p[0] >= cut] or \
|
|
121
|
+
[p[1] for pts in clean.values() for p in pts]
|
|
122
|
+
y0, y1 = min(ys), max(ys)
|
|
123
|
+
if x1 == x0:
|
|
124
|
+
x1 = x0 + 1.0
|
|
125
|
+
if y1 == y0:
|
|
126
|
+
y0, y1 = y0 - 1.0, y1 + 1.0
|
|
127
|
+
pw, ph = W - PAD_L - PAD_R, H - PAD_T - PAD_B
|
|
128
|
+
|
|
129
|
+
def sx(x: float) -> float:
|
|
130
|
+
return PAD_L + (x - x0) / (x1 - x0) * pw
|
|
131
|
+
|
|
132
|
+
def sy(y: float) -> float:
|
|
133
|
+
return PAD_T + (1.0 - (min(max(y, y0), y1) - y0) / (y1 - y0)) * ph
|
|
134
|
+
|
|
135
|
+
names = sorted(clean)
|
|
136
|
+
marked = marker is not None and x0 <= marker <= x1
|
|
137
|
+
desc = (f"Line chart of {len(names)} series ({', '.join(names)}) against step, from step "
|
|
138
|
+
f"{round(x0):,} to step {round(x1):,}"
|
|
139
|
+
+ ("; the vertical axis is the base-10 logarithm of the value" if log_y else "")
|
|
140
|
+
+ (f"; the answer stopped changing at step {round(marker):,}" if marked else "") + ".")
|
|
141
|
+
parts = [f'<svg viewBox="0 0 {W} {H}" role="img" aria-labelledby="{cid}-t {cid}-d">',
|
|
142
|
+
f'<title id="{cid}-t">{escape(title)}</title>',
|
|
143
|
+
f'<desc id="{cid}-d">{escape(desc)}</desc>']
|
|
144
|
+
parts.append(f'<line class="axis" x1="{PAD_L}" y1="{PAD_T + ph}" x2="{PAD_L + pw}" y2="{PAD_T + ph}"/>')
|
|
145
|
+
parts.append(f'<line class="axis" x1="{PAD_L}" y1="{PAD_T}" x2="{PAD_L}" y2="{PAD_T + ph}"/>')
|
|
146
|
+
if marker is not None and x0 <= marker <= x1:
|
|
147
|
+
mx = sx(marker)
|
|
148
|
+
parts.append(f'<rect x="{_f(mx)}" y="{PAD_T}" width="{_f(PAD_L + pw - mx)}" height="{ph}" '
|
|
149
|
+
f'fill="var(--shade)"/>')
|
|
150
|
+
parts.append(f'<line x1="{_f(mx)}" y1="{PAD_T}" x2="{_f(mx)}" y2="{PAD_T + ph}" '
|
|
151
|
+
f'stroke="var(--s1)" stroke-dasharray="4 3"/>')
|
|
152
|
+
parts.append(f'<text x="{_f(mx + 4)}" y="{PAD_T + 12}">{escape(marker_label)}</text>')
|
|
153
|
+
for k in range(5):
|
|
154
|
+
yv = y0 + (y1 - y0) * k / 4
|
|
155
|
+
label = f"1e{yv:.1f}" if log_y else f"{yv:.3g}"
|
|
156
|
+
parts.append(f'<text x="{PAD_L - 6}" y="{_f(sy(yv) + 4)}" text-anchor="end">{label}</text>')
|
|
157
|
+
for k in range(5):
|
|
158
|
+
xv = x0 + (x1 - x0) * k / 4
|
|
159
|
+
xl = f"{round(xv):,}" if x1 - x0 >= 20 else f"{xv:.3g}" # steps are whole numbers
|
|
160
|
+
parts.append(f'<text x="{_f(sx(xv))}" y="{H - 10}" text-anchor="middle">{xl}</text>')
|
|
161
|
+
for i, (name, pts) in enumerate(sorted(clean.items())):
|
|
162
|
+
d = " ".join(f"{_f(sx(x))},{_f(sy(y))}" for x, y in pts)
|
|
163
|
+
dash = DASHES[i % len(DASHES)]
|
|
164
|
+
dash_attr = f' stroke-dasharray="{" ".join(f"{x:g}" for x in dash)}"' if dash else ""
|
|
165
|
+
parts.append(f'<polyline fill="none" stroke="{PALETTE[i % len(PALETTE)]}" stroke-width="1.6"'
|
|
166
|
+
f'{dash_attr} points="{d}"/>')
|
|
167
|
+
parts.append("</svg>")
|
|
168
|
+
legend = "".join(f"<span>{_swatch(i)}{escape(n)}</span>" for i, n in enumerate(names))
|
|
169
|
+
return f'<div class="legend">{legend}</div>' + "".join(parts)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _series_from_inputs(inputs) -> tuple[dict, dict, dict, int | None, str | None]:
|
|
173
|
+
"""Residuals, Courant number and the binding monitor's series, from the run's own files."""
|
|
174
|
+
from courant.events.core import EventKind
|
|
175
|
+
from courant.watcher.exitcode import infer_exit_code
|
|
176
|
+
from courant.watcher.parser import LogParser
|
|
177
|
+
|
|
178
|
+
code = inputs.exit_code if inputs.exit_code is not None else infer_exit_code(inputs.log_text)
|
|
179
|
+
events = LogParser(run_id=inputs.run_id).parse_text(inputs.log_text, return_code=code)
|
|
180
|
+
res: dict[str, list] = {}
|
|
181
|
+
co: dict[str, list] = {}
|
|
182
|
+
step = 0
|
|
183
|
+
for e in events:
|
|
184
|
+
if e.kind is not EventKind.RESIDUAL:
|
|
185
|
+
continue
|
|
186
|
+
step = step + 1
|
|
187
|
+
for name, v in e.payload.initial_residuals.items():
|
|
188
|
+
res.setdefault(name, []).append((float(step), v))
|
|
189
|
+
if e.payload.courant_max is not None:
|
|
190
|
+
co.setdefault("Courant max", []).append((float(step), e.payload.courant_max))
|
|
191
|
+
mon: dict[str, list] = {}
|
|
192
|
+
stop, binding = None, None
|
|
193
|
+
if inputs.case_dir:
|
|
194
|
+
from courant.converge.series import assess_case
|
|
195
|
+
|
|
196
|
+
conv = assess_case(inputs.case_dir, log_text=inputs.log_text, events=events)
|
|
197
|
+
binding = conv.data.get("binding_monitor")
|
|
198
|
+
stop = conv.data.get("converged_at_step")
|
|
199
|
+
rows = conv.data.get("monitors") or {}
|
|
200
|
+
from courant.converge.series import discover
|
|
201
|
+
from pathlib import Path
|
|
202
|
+
|
|
203
|
+
found = {m.id: m for m in discover(Path(inputs.case_dir)).monitors}
|
|
204
|
+
chosen = [binding] if binding else [k for k, v in sorted(rows.items())
|
|
205
|
+
if v.get("counts")][:1]
|
|
206
|
+
for mid in chosen:
|
|
207
|
+
m = found.get(mid)
|
|
208
|
+
if m is not None:
|
|
209
|
+
steps = rows[mid].get("first_step")
|
|
210
|
+
mon[mid] = [(float(i + (steps or 1)), v) for i, v in enumerate(m.values)]
|
|
211
|
+
return res, co, mon, stop, binding
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
#: The version 2 badges (GATE-3). Appended, so a `--schema 1` page keeps version 1's bytes.
|
|
215
|
+
CSS_V2 = (CSS.rstrip("\n") + "\n.accept{background:var(--ok)}.reject{background:var(--bad)}"
|
|
216
|
+
".insufficient{background:var(--warn)}\n")
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def render_html(v: AnyVerdict, inputs=None) -> str:
|
|
220
|
+
v2 = isinstance(v, VerdictV2)
|
|
221
|
+
title = f"Courant · {v.run.id}"
|
|
222
|
+
out = ["<!doctype html>", '<html lang="en">', "<head>", '<meta charset="utf-8">',
|
|
223
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">',
|
|
224
|
+
f"<title>{escape(title)}</title>", f"<style>{CSS_V2 if v2 else CSS}</style>", "</head>",
|
|
225
|
+
"<body>", "<main>"]
|
|
226
|
+
out.append(f"<h1>Verification: {escape(v.run.id)}</h1>")
|
|
227
|
+
out.append(f'<div class="meta">{escape(v.run.solver or "solver unknown")} · '
|
|
228
|
+
f'{escape(v.tool.name)} {escape(v.tool.version)} · schema '
|
|
229
|
+
f'<span class="mono">{escape(v.schema_)}</span></div>')
|
|
230
|
+
out.append(f'<div class="card"><span class="badge {v.verdict}">{v.verdict.replace("_", " ")}</span>'
|
|
231
|
+
f'rule <span class="mono">{escape(v.rule)}</span> · grade '
|
|
232
|
+
f'<b>{escape(v.grade or "—")}</b>'
|
|
233
|
+
+ (f' · basis <span class="mono">{escape(v.basis)}</span>' if v2 else "")
|
|
234
|
+
+ "</div>")
|
|
235
|
+
accepted = v.verdict in ("TRUSTWORTHY", "accept")
|
|
236
|
+
head = "Notes" if accepted else "Why"
|
|
237
|
+
out.append(f"<h2>{head}</h2>")
|
|
238
|
+
if v.reasons:
|
|
239
|
+
rows = [f'<tr><td class="mono">{escape(r.code)}</td><td>{escape(r.severity)}</td>'
|
|
240
|
+
f"<td>{escape(r.summary)}</td><td class=\"mono\">{escape(r.input)}</td>"
|
|
241
|
+
f"<td>{escape(r.method)}</td><td class=\"num\">{escape(r.value or '—')}</td>"
|
|
242
|
+
f"<td class=\"num\">{escape(r.threshold or '—')}</td></tr>" for r in v.reasons]
|
|
243
|
+
out.append(_table(f"{head}: the reasons the checks raised",
|
|
244
|
+
("Code", "Severity", "Finding", "Read", "Method", "Value", "Threshold"),
|
|
245
|
+
rows))
|
|
246
|
+
else:
|
|
247
|
+
out.append("<p>No reason was raised.</p>")
|
|
248
|
+
if v.probable_causes and not accepted:
|
|
249
|
+
out.append("<h2>Probable causes</h2><ol>")
|
|
250
|
+
out += [f'<li><span class="mono">{escape(c.code)}</span> — {escape(c.name)}</li>'
|
|
251
|
+
for c in v.probable_causes]
|
|
252
|
+
out.append("</ol>")
|
|
253
|
+
if v.next_action:
|
|
254
|
+
out.append(f"<h2>Next action</h2><p>{escape(v.next_action)}</p>")
|
|
255
|
+
|
|
256
|
+
res, co, mon, stop, binding = ({}, {}, {}, None, None)
|
|
257
|
+
if inputs is not None:
|
|
258
|
+
res, co, mon, stop, binding = _series_from_inputs(inputs)
|
|
259
|
+
c = v.convergence
|
|
260
|
+
if c is not None and c.monitors_found:
|
|
261
|
+
out.append("<h2>Convergence</h2>")
|
|
262
|
+
line = f"<b>{escape(c.status)}</b> · {escape(c.regime or 'regime unknown')}"
|
|
263
|
+
if c.converged_at_step is not None:
|
|
264
|
+
line = line + (f" · the answer stopped changing at step {c.converged_at_step:,} "
|
|
265
|
+
f"(<span class=\"mono\">{escape(c.binding_monitor or '')}</span>)")
|
|
266
|
+
out.append(f'<div class="card">{line}')
|
|
267
|
+
if c.wasted_steps is not None:
|
|
268
|
+
pct = f" ({100 * float(c.wasted_fraction):.1f}%)" if c.wasted_fraction else ""
|
|
269
|
+
out.append(f"<br>{c.wasted_steps:,} of {c.steps_total:,} steps{pct} came after it"
|
|
270
|
+
+ (f"; {escape(c.wasted_wall_clock_s)} s wall clock" if c.wasted_wall_clock_s else "")
|
|
271
|
+
+ (f"; {escape(c.wasted_core_hours)} core-hours" if c.wasted_core_hours else ""))
|
|
272
|
+
if c.messages:
|
|
273
|
+
out.append("<ul>" + "".join(f"<li>{escape(m)}</li>" for m in c.messages) + "</ul>")
|
|
274
|
+
out.append('<div class="cap">Reported beside the verdict, not in it: policy rule VER-5.4b '
|
|
275
|
+
"is off.</div></div>")
|
|
276
|
+
if mon:
|
|
277
|
+
out.append(_chart(mon, log_y=False, title="The binding monitor against step",
|
|
278
|
+
cid="chart-monitor", marker=float(stop) if stop else None,
|
|
279
|
+
marker_label="stopped changing" if stop else "", skip_start=0.02))
|
|
280
|
+
out.append('<div class="cap">The binding monitor, drawn from its postProcessing file. '
|
|
281
|
+
"Shaded: steps after the answer stopped changing. The vertical range "
|
|
282
|
+
"leaves out the first 2% of the run.</div>")
|
|
283
|
+
k = v.conformance
|
|
284
|
+
if k is not None:
|
|
285
|
+
conforming = sum(1 for i in k.items if i.conforms)
|
|
286
|
+
out.append("<h2>Conformance to the task specification</h2>")
|
|
287
|
+
out.append(f'<div class="card">{conforming} of {len(k.items)} specified values match the '
|
|
288
|
+
f'case · spec <span class="mono">{escape(k.spec_sha256[:12])}</span>'
|
|
289
|
+
+ (f' (locked <span class="mono">{escape(k.locked_sha256[:12])}</span>)'
|
|
290
|
+
if k.locked_sha256 else "")
|
|
291
|
+
+ (f"<br>{escape(k.task)}" if k.task else "") + "</div>")
|
|
292
|
+
rows = []
|
|
293
|
+
for i in k.items:
|
|
294
|
+
result = ("matches" if i.conforms else "<b>does not match</b>" if i.conforms is False
|
|
295
|
+
else f"not checked: {escape(i.note or '')}")
|
|
296
|
+
rows.append(f"<tr><td>{escape(i.name)}</td><td class=\"num\">{escape(i.specified or '—')}</td>"
|
|
297
|
+
f"<td class=\"num\">{escape(i.found or '—')}</td><td>{escape(i.tolerance)}</td>"
|
|
298
|
+
f"<td class=\"mono\">{escape(i.file)}</td><td>{result}</td></tr>")
|
|
299
|
+
out.append(_table("Specified values against the case",
|
|
300
|
+
("Value", "Specified", "In the case", "Tolerance", "Read", "Result"), rows))
|
|
301
|
+
if res:
|
|
302
|
+
out.append("<h2>Residuals</h2>")
|
|
303
|
+
out.append(_chart(res, log_y=True, title="Initial residuals against step",
|
|
304
|
+
cid="chart-residuals"))
|
|
305
|
+
out.append('<div class="cap">Initial residual per field and step, drawn from the solver log '
|
|
306
|
+
"(log scale).</div>")
|
|
307
|
+
if co:
|
|
308
|
+
out.append("<h2>Courant number</h2>")
|
|
309
|
+
out.append(_chart(co, log_y=False, title="Maximum Courant number against step",
|
|
310
|
+
cid="chart-courant"))
|
|
311
|
+
out.append('<div class="cap">Maximum Courant number per step, drawn from the solver log.</div>')
|
|
312
|
+
if v.not_assessed:
|
|
313
|
+
out.append("<h2>Not checked</h2><ul>")
|
|
314
|
+
out += [f"<li>{escape(s)}</li>" for s in v.not_assessed]
|
|
315
|
+
out.append("</ul>")
|
|
316
|
+
out.append("<h2>Inputs</h2>")
|
|
317
|
+
out.append(_table("Input files with their sizes and SHA-256", ("File", "Bytes", "SHA-256"),
|
|
318
|
+
[f'<tr><td class="mono">{escape(f.path)}</td><td class="num">{f.bytes:,}</td>'
|
|
319
|
+
f'<td class="mono">{escape(f.sha256)}</td></tr>' for f in v.run.inputs]))
|
|
320
|
+
s = v.stats
|
|
321
|
+
out.append("</main>")
|
|
322
|
+
out.append(f"<footer>Parsed {s.events:,} events and {s.residual_steps:,} residual steps. "
|
|
323
|
+
"Every number in the text above is in this run's verdict JSON, apart from the error "
|
|
324
|
+
"rates at the end of this line; the charts are drawn "
|
|
325
|
+
"from the input files listed, whose SHA-256 is shown. Courant is read-only: it did "
|
|
326
|
+
"not edit the case or run a solver. Generated by "
|
|
327
|
+
f"{escape(v.tool.name)} {escape(v.tool.version)}. "
|
|
328
|
+
f"{escape(about.footer())}</footer>")
|
|
329
|
+
out += ["</body>", "</html>", ""]
|
|
330
|
+
return "\n".join(out)
|
courant/verify/ingest.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Gather what the verifier reads, before anything is parsed (TRD VER-3).
|
|
2
|
+
|
|
3
|
+
Three sources: a case directory, a log file, or a log with a corpus sidecar
|
|
4
|
+
(`*.case.json`, the format of `certification/corpus/`). The ingest reads and
|
|
5
|
+
hashes files. It never writes, runs a process, or opens a socket (INV-5).
|
|
6
|
+
|
|
7
|
+
For a case directory the manifest is what the readers read (VER-14): each reader
|
|
8
|
+
notes its files at the line that reads them (`courant.case.reads`), and the
|
|
9
|
+
manifest hashes exactly those. Nothing here guesses which files matter.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import gzip
|
|
15
|
+
import json
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from courant.verify.schema import InputError, InputFile, RunInputs, manifest
|
|
19
|
+
|
|
20
|
+
__all__ = ["InputError", "from_case_dir", "from_log", "from_path", "with_spec"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _read_text(path: Path) -> str:
|
|
24
|
+
if path.suffix == ".gz":
|
|
25
|
+
with gzip.open(path, "rt", encoding="utf-8", errors="replace") as fh:
|
|
26
|
+
return fh.read()
|
|
27
|
+
return path.read_text(encoding="utf-8", errors="replace")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def from_log(log_path: str | Path, case_json: str | Path | None = None) -> RunInputs:
|
|
31
|
+
log_path = Path(log_path)
|
|
32
|
+
if not log_path.is_file():
|
|
33
|
+
raise InputError(f"no such log file: {log_path}")
|
|
34
|
+
text = _read_text(log_path)
|
|
35
|
+
inputs = [InputFile.of(log_path, log_path.name)]
|
|
36
|
+
meta: dict = {}
|
|
37
|
+
if case_json is not None:
|
|
38
|
+
case_json = Path(case_json)
|
|
39
|
+
if not case_json.is_file():
|
|
40
|
+
raise InputError(f"no such case sidecar: {case_json}")
|
|
41
|
+
try:
|
|
42
|
+
meta = json.loads(case_json.read_text())
|
|
43
|
+
except json.JSONDecodeError as exc:
|
|
44
|
+
raise InputError(f"{case_json.name} is not valid JSON: {exc}") from exc
|
|
45
|
+
inputs.append(InputFile.of(case_json, case_json.name))
|
|
46
|
+
stem = log_path.name.removesuffix(".gz").removesuffix(".log")
|
|
47
|
+
return RunInputs(
|
|
48
|
+
run_id=meta.get("scenario_id") or stem,
|
|
49
|
+
log_text=text, log_name=log_path.name,
|
|
50
|
+
config_view=meta.get("config"), mesh_view=meta.get("mesh"),
|
|
51
|
+
inputs=tuple(sorted(inputs, key=lambda f: f.path)),
|
|
52
|
+
source="corpus" if case_json else "log",
|
|
53
|
+
solver_hint=meta.get("solver"),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def from_case_dir(case_dir: str | Path) -> RunInputs:
|
|
58
|
+
from courant.case.mesh import read_mesh_quality
|
|
59
|
+
from courant.case.reads import note, recording
|
|
60
|
+
from courant.cli.tail import find_log, utility_logs
|
|
61
|
+
|
|
62
|
+
case_dir = Path(case_dir)
|
|
63
|
+
if not case_dir.is_dir():
|
|
64
|
+
raise InputError(f"no such case directory: {case_dir}")
|
|
65
|
+
with recording(case_dir) as reads:
|
|
66
|
+
log = find_log(case_dir) # notes every log it ranked
|
|
67
|
+
if log is None:
|
|
68
|
+
utilities = utility_logs(case_dir)
|
|
69
|
+
only = (f"; only utility logs ({', '.join(utilities)}), which are not the run's "
|
|
70
|
+
f"output. Pass the solver's log file instead" if utilities else "")
|
|
71
|
+
raise InputError(f"no solver log (log.<solver>) found in {case_dir}{only}")
|
|
72
|
+
log = Path(log)
|
|
73
|
+
text = _read_text(log)
|
|
74
|
+
note(log) # hashed once, with the rest
|
|
75
|
+
|
|
76
|
+
config_view = None
|
|
77
|
+
try:
|
|
78
|
+
from courant.case.config import CaseConfig
|
|
79
|
+
|
|
80
|
+
config_view = CaseConfig.from_foam(str(case_dir)).model_dump(mode="json")
|
|
81
|
+
except Exception: # noqa: BLE001
|
|
82
|
+
config_view = None # recorded as not assessed
|
|
83
|
+
mesh = read_mesh_quality(str(case_dir)) # notes the checkMesh log it parsed
|
|
84
|
+
|
|
85
|
+
return RunInputs(
|
|
86
|
+
run_id=case_dir.name, log_text=text, log_name=log.name,
|
|
87
|
+
config_view=config_view,
|
|
88
|
+
mesh_view=mesh.model_dump(mode="json") if mesh is not None else None,
|
|
89
|
+
inputs=manifest(case_dir, reads.paths()),
|
|
90
|
+
source="case_dir", case_dir=str(case_dir.resolve()),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def from_path(path: str | Path, case_json: str | Path | None = None) -> RunInputs:
|
|
95
|
+
path = Path(path)
|
|
96
|
+
return from_case_dir(path) if path.is_dir() else from_log(path, case_json)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def with_spec(inputs: RunInputs, spec_path: str | Path,
|
|
100
|
+
locked_sha256: str | None = None) -> RunInputs:
|
|
101
|
+
"""The same inputs, plus the task specification the run was asked to satisfy.
|
|
102
|
+
|
|
103
|
+
`locked_sha256` is the hash the specification was locked at before the run; a file that
|
|
104
|
+
no longer matches it makes the verdict NOT_ASSESSABLE (PRD 2.0 P2-SPEC-3).
|
|
105
|
+
"""
|
|
106
|
+
from courant.spec import SpecError, load_spec
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
spec, sha = load_spec(spec_path)
|
|
110
|
+
except SpecError as exc:
|
|
111
|
+
raise InputError(str(exc)) from exc
|
|
112
|
+
locked = locked_sha256.strip().lower() if locked_sha256 else None
|
|
113
|
+
return inputs.model_copy(update={
|
|
114
|
+
"spec": spec.model_dump(mode="json", by_alias=True),
|
|
115
|
+
"spec_sha256": sha, "spec_locked_sha256": locked})
|
courant/verify/junit.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""JUnit XML for batch verification, so any CI system shows each run as a test (TRD REP-7).
|
|
2
|
+
|
|
3
|
+
One `testcase` per run, in the order `verify_all` returns them, which is sorted paths:
|
|
4
|
+
- `reject` (NOT_TRUSTWORTHY in version 1) is a `failure`, carrying its first reason;
|
|
5
|
+
- `insufficient` (NOT_ASSESSABLE) is `skipped`;
|
|
6
|
+
- an input error is an `error`.
|
|
7
|
+
Each verdict is written in its own schema's words, so `--schema 1` keeps version 1's bytes.
|
|
8
|
+
|
|
9
|
+
There are no timestamps and no durations, so the bytes depend only on the verdicts.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from xml.sax.saxutils import escape, quoteattr
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def render_junit(results, root: str | Path) -> str:
|
|
19
|
+
root = Path(root)
|
|
20
|
+
cases, fails, errors, skipped = [], 0, 0, 0
|
|
21
|
+
for target, verdict, err in results:
|
|
22
|
+
name = str(target.relative_to(root)) if target.is_relative_to(root) else str(target)
|
|
23
|
+
head = f' <testcase classname="courant.verify" name={quoteattr(name)}'
|
|
24
|
+
if err:
|
|
25
|
+
errors = errors + 1
|
|
26
|
+
cases.append(f'{head}>\n <error type="InputError" message={quoteattr(err)}/>\n </testcase>')
|
|
27
|
+
elif verdict.verdict in ("NOT_TRUSTWORTHY", "reject"):
|
|
28
|
+
fails = fails + 1
|
|
29
|
+
first = verdict.reasons[0] if verdict.reasons else None
|
|
30
|
+
msg = f"{first.code}: {first.summary}" if first else verdict.rule
|
|
31
|
+
body = "\n".join(f"{r.code} [{r.severity}] {r.summary} (read {r.input}; {r.method})"
|
|
32
|
+
for r in verdict.reasons)
|
|
33
|
+
cases.append(f'{head}>\n <failure type="{verdict.verdict}" message={quoteattr(msg)}>'
|
|
34
|
+
f"{escape(f'rule {verdict.rule}, grade {verdict.grade or chr(8212)}' + chr(10) + body)}"
|
|
35
|
+
f"</failure>\n </testcase>")
|
|
36
|
+
elif verdict.verdict in ("NOT_ASSESSABLE", "insufficient"):
|
|
37
|
+
skipped = skipped + 1
|
|
38
|
+
why = verdict.not_assessed[0] if verdict.not_assessed else verdict.rule
|
|
39
|
+
cases.append(f'{head}>\n <skipped message={quoteattr(verdict.verdict + ": " + why)}/>\n </testcase>')
|
|
40
|
+
else:
|
|
41
|
+
cases.append(f"{head}/>")
|
|
42
|
+
n = len(cases)
|
|
43
|
+
attrs = f'tests="{n}" failures="{fails}" errors="{errors}" skipped="{skipped}"'
|
|
44
|
+
return ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
|
45
|
+
f'<testsuites name="courant verify" {attrs}>\n'
|
|
46
|
+
f' <testsuite name="courant verify" {attrs}>\n'
|
|
47
|
+
+ "\n".join(cases) + ("\n" if cases else "")
|
|
48
|
+
+ " </testsuite>\n</testsuites>\n")
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""What a verdict means for a check that must pass or fail (TRD GATE-7, ARC-13).
|
|
2
|
+
|
|
3
|
+
The gate decides a verdict; a CI check, the Action, needs one more answer: does this run fail
|
|
4
|
+
the check. That answer is a reading of the verdict, so it lives beside the verdict's own code
|
|
5
|
+
(ARC-13: other modules read a verdict through helpers here, and decide nothing).
|
|
6
|
+
|
|
7
|
+
It is a policy, not an outcome. An agent run's outcome (SB-11: `valid_conformant`,
|
|
8
|
+
`nonconformant`, ..., with `silent_error` and `unverified_success`) has one definition,
|
|
9
|
+
`courant.verify.schema.outcome_of`; nothing here names one. A CI run has no producer's claim and
|
|
10
|
+
no re-solve, and the check passes an `accept` judged without a specification, which SB-11 scores
|
|
11
|
+
`insufficient`; so the check reads the verdict, as GATE-7 says, and not the outcome.
|
|
12
|
+
|
|
13
|
+
`fail_on`:
|
|
14
|
+
|
|
15
|
+
- `not-accept` (the default): anything but `accept` fails the check;
|
|
16
|
+
- `reject`: `insufficient` passes, and the summary says so on every run it applies to.
|
|
17
|
+
|
|
18
|
+
Whatever `fail_on` says, a run whose verdict is void because of the specification fails the
|
|
19
|
+
check: an `insufficient` that means "the specification was changed after it was locked" is
|
|
20
|
+
not the same as one that means "the log is too short to judge", and a check that let the first
|
|
21
|
+
through would let a specification be edited until the run fits it.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from collections.abc import Iterable
|
|
27
|
+
|
|
28
|
+
from courant.verify import policy
|
|
29
|
+
|
|
30
|
+
FAIL_ON = ("not-accept", "reject")
|
|
31
|
+
|
|
32
|
+
#: The specification problems GATE-4 names that are not a hash mismatch: VER-5.9 (a named value
|
|
33
|
+
#: could not be read), VER-5.11 (invalid), VER-5.12 (an extracted specification does not match
|
|
34
|
+
#: the confirmed one) and VER-5.13 (a role the case does not resolve). A hash mismatch (VER-5.8)
|
|
35
|
+
#: is `policy.spec_void`, the one definition of it.
|
|
36
|
+
SPEC_INTEGRITY_RULES = frozenset({"VER-5.9", "VER-5.11", "VER-5.12", "VER-5.13"})
|
|
37
|
+
#: The closed vocabulary's names (GATE-4) for the same four.
|
|
38
|
+
SPEC_INTEGRITY_CODES = frozenset({
|
|
39
|
+
"spec_value_unreadable", "spec_invalid", "spec_extracted_mismatch", "spec_role_unresolved"})
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def spec_integrity(verdict) -> bool:
|
|
43
|
+
"""Whether the verdict turned on the specification's integrity, not on the run."""
|
|
44
|
+
if verdict.conformance is not None and policy.spec_void(verdict.conformance):
|
|
45
|
+
return True
|
|
46
|
+
if verdict.rule in SPEC_INTEGRITY_RULES:
|
|
47
|
+
return True
|
|
48
|
+
return any(r.code.removeprefix("insufficient.") in SPEC_INTEGRITY_CODES
|
|
49
|
+
for r in verdict.reasons)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def check_fails(verdict, fail_on: str = "not-accept") -> bool:
|
|
53
|
+
"""Whether `verdict` fails a check set to `fail_on`."""
|
|
54
|
+
if fail_on not in FAIL_ON:
|
|
55
|
+
raise ValueError(f"fail-on must be one of {', '.join(FAIL_ON)}, not {fail_on!r}")
|
|
56
|
+
if spec_integrity(verdict):
|
|
57
|
+
return True
|
|
58
|
+
if verdict.verdict == "accept":
|
|
59
|
+
return False
|
|
60
|
+
if verdict.verdict == "reject":
|
|
61
|
+
return True
|
|
62
|
+
return fail_on == "not-accept" # insufficient
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def first_reason(verdict) -> tuple[str, str] | None:
|
|
66
|
+
"""(code, sentence) of the verdict's first reason, or None when it gives none."""
|
|
67
|
+
return (verdict.reasons[0].code, verdict.reasons[0].summary) if verdict.reasons else None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def tally(verdicts: Iterable) -> dict[str, int]:
|
|
71
|
+
out = {"accept": 0, "reject": 0, "insufficient": 0}
|
|
72
|
+
for v in verdicts:
|
|
73
|
+
out[v.verdict] += 1
|
|
74
|
+
return out
|