awprove 0.1.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.
- awprove/__init__.py +30 -0
- awprove/_doctor.py +201 -0
- awprove/assertions.py +74 -0
- awprove/cli.py +119 -0
- awprove/fixtures.py +94 -0
- awprove/observation.py +45 -0
- awprove/pin.py +103 -0
- awprove/proofs/example-anon.yaml +22 -0
- awprove/report.py +57 -0
- awprove/runner.py +336 -0
- awprove/spec.py +313 -0
- awprove-0.1.0.dist-info/METADATA +117 -0
- awprove-0.1.0.dist-info/RECORD +17 -0
- awprove-0.1.0.dist-info/WHEEL +5 -0
- awprove-0.1.0.dist-info/entry_points.txt +2 -0
- awprove-0.1.0.dist-info/licenses/LICENSE +202 -0
- awprove-0.1.0.dist-info/top_level.txt +1 -0
awprove/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""awprove — Aither World Prove.
|
|
2
|
+
|
|
3
|
+
Drive a page as the real user, check what actually rendered, and get a test that
|
|
4
|
+
goes red if it ever stops being true.
|
|
5
|
+
|
|
6
|
+
The loop this session ran by hand, generalized: a *proof* is a journey (acts on a
|
|
7
|
+
real browser) plus the truths that must hold on the rendered page — the failures an
|
|
8
|
+
HTTP 200 hides, like a lock screen shown to a signed-in user or an empty knowledge
|
|
9
|
+
base. `run` drives any AitherBrowser-shaped service and judges the result; `pin`
|
|
10
|
+
emits a self-testing gate so the truth can't silently regress.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from .assertions import AssertionResult, evaluate, evaluate_all
|
|
16
|
+
from .fixtures import break_assertion, passing_observation
|
|
17
|
+
from .observation import Observation
|
|
18
|
+
from .pin import gate_name, synthesize_gate
|
|
19
|
+
from .report import ProofReport
|
|
20
|
+
from .runner import judge, run
|
|
21
|
+
from .spec import Assertion, Proof, ProofError, Step, load_proof
|
|
22
|
+
|
|
23
|
+
__version__ = "0.1.0"
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"Assertion", "AssertionResult", "Observation", "Proof", "ProofError",
|
|
27
|
+
"ProofReport", "Step", "break_assertion", "evaluate", "evaluate_all",
|
|
28
|
+
"gate_name", "judge", "load_proof", "passing_observation", "run",
|
|
29
|
+
"synthesize_gate", "__version__",
|
|
30
|
+
]
|
awprove/_doctor.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Stack-aware `doctor` for awprove.
|
|
2
|
+
|
|
3
|
+
GENERATED BY gen_aw_doctor.py -- DO NOT EDIT.
|
|
4
|
+
Regenerate it with the generator named above; a hand-edit here is reverted by
|
|
5
|
+
the next run and fails the parity gate.
|
|
6
|
+
|
|
7
|
+
Why a doctor exists at all: the aw* bricks are designed to COMPOSE, so the
|
|
8
|
+
interesting failures live BETWEEN them. "awprove is installed" is not the useful
|
|
9
|
+
fact -- "awprove is installed and the thing it pairs with is not" is. This reports
|
|
10
|
+
the whole stack, not just itself.
|
|
11
|
+
|
|
12
|
+
stdlib only, on purpose: a diagnostic that cannot run because a dependency is
|
|
13
|
+
missing is worthless precisely when you need it.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import importlib.util
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
#: Frozen from the Aither World registry at generation time. A shipped
|
|
23
|
+
#: package cannot read the registry, and a doctor that guessed at the family
|
|
24
|
+
#: would go stale in silence. Regenerate to update.
|
|
25
|
+
SELF = 'awprove'
|
|
26
|
+
FAMILY = [
|
|
27
|
+
'awask', 'awavatar', 'awbac', 'awbrain', 'awbrowse', 'awcams', 'awclassify', 'awdecide',
|
|
28
|
+
'awdeck', 'awdelphi', 'awdit', 'awembed', 'awevolve', 'awfind', 'awflow', 'awfocus', 'awgit',
|
|
29
|
+
'awgraph', 'awgym', 'awiam', 'awkno', 'awm', 'awmail', 'awmine', 'awnboard', 'awnest', 'awnet',
|
|
30
|
+
'awplay', 'awpool', 'awpredict', 'awprism', 'awreason', 'awrecover', 'awrecurse', 'awrelay',
|
|
31
|
+
'awrena', 'awrepl', 'awreport', 'awresearch', 'awrise', 'awrouter', 'awrtifact', 'awrun',
|
|
32
|
+
'awscope', 'awscreen', 'awseal', 'awsettings', 'awshare', 'awsprite', 'awstorage', 'awsuite',
|
|
33
|
+
'awswarm', 'awtax', 'awtoll', 'awtunnel', 'awvision', 'awvoice', 'awwall', 'gawbbonet',
|
|
34
|
+
]
|
|
35
|
+
PAIRS_WITH = ['awbrowse', 'adk', 'awscreen', 'awvision']
|
|
36
|
+
|
|
37
|
+
#: This brick's OWN config, read out of its source at generation time.
|
|
38
|
+
#: ENV_REQUIRED is `os.environ["X"]` -- absent, that is a KeyError the moment
|
|
39
|
+
#: the line runs. ENV_OPTIONAL is `os.getenv("X")`, which returns None and lets
|
|
40
|
+
#: the caller cope. Only this brick's namespace is listed: reporting the
|
|
41
|
+
#: platform-wide vars it also touches would be noise, and a doctor that floods
|
|
42
|
+
#: gets ignored.
|
|
43
|
+
ENV_REQUIRED = []
|
|
44
|
+
ENV_OPTIONAL = [
|
|
45
|
+
'AWPROVE_BROWSER_CA', 'AWPROVE_BROWSER_HEADERS', 'AWPROVE_BROWSER_INSECURE',
|
|
46
|
+
'AWPROVE_BROWSER_URL', 'AWPROVE_VISION_URL',
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _installed(mod: str) -> "str | None":
|
|
51
|
+
"""Version if importable, else None. Never raises -- a broken sibling must
|
|
52
|
+
not take the diagnostic down with it."""
|
|
53
|
+
try:
|
|
54
|
+
if importlib.util.find_spec(mod) is None:
|
|
55
|
+
return None
|
|
56
|
+
except (ImportError, ValueError):
|
|
57
|
+
return None
|
|
58
|
+
try:
|
|
59
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
60
|
+
try:
|
|
61
|
+
return version(mod)
|
|
62
|
+
except PackageNotFoundError:
|
|
63
|
+
return "installed"
|
|
64
|
+
except Exception:
|
|
65
|
+
return "installed"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def report(out=None) -> int:
|
|
69
|
+
"""Print the stack picture. 0 = this brick and its pairs are present."""
|
|
70
|
+
out = out or sys.stdout
|
|
71
|
+
print(f"{SELF} doctor", file=out)
|
|
72
|
+
|
|
73
|
+
mine = _installed(SELF)
|
|
74
|
+
print(f" self {SELF} {mine or 'NOT IMPORTABLE'}", file=out)
|
|
75
|
+
shim = shutil.which(SELF)
|
|
76
|
+
print(f" command {shim or 'not on PATH'}", file=out)
|
|
77
|
+
|
|
78
|
+
# The stack. Siblings this brick pairs with are called out separately,
|
|
79
|
+
# because a missing pair is a REASON, while a missing unrelated brick is
|
|
80
|
+
# just a fact about your machine.
|
|
81
|
+
missing_pairs, present = [], []
|
|
82
|
+
for name in FAMILY:
|
|
83
|
+
v = _installed(name)
|
|
84
|
+
if v:
|
|
85
|
+
present.append(name)
|
|
86
|
+
elif name in PAIRS_WITH:
|
|
87
|
+
missing_pairs.append(name)
|
|
88
|
+
print(f" stack {len(present)}/{len(FAMILY)} aw* packages installed",
|
|
89
|
+
file=out)
|
|
90
|
+
if present:
|
|
91
|
+
print(f" {' '.join(sorted(present))}", file=out)
|
|
92
|
+
|
|
93
|
+
missing_req = [v for v in ENV_REQUIRED if not os.environ.get(v)]
|
|
94
|
+
if ENV_REQUIRED or ENV_OPTIONAL:
|
|
95
|
+
have = sum(1 for v in ENV_REQUIRED + ENV_OPTIONAL if os.environ.get(v))
|
|
96
|
+
total = len(ENV_REQUIRED) + len(ENV_OPTIONAL)
|
|
97
|
+
print(f" config {have}/{total} of this brick's own vars set", file=out)
|
|
98
|
+
if missing_req:
|
|
99
|
+
# Not a preference. os.environ[...] raises the moment it runs.
|
|
100
|
+
print(f" MISSING REQUIRED: {' '.join(missing_req)}", file=out)
|
|
101
|
+
|
|
102
|
+
local = _local_checks()
|
|
103
|
+
for line in local:
|
|
104
|
+
print(f" {line}", file=out)
|
|
105
|
+
problems, unjudged = _local_verdict()
|
|
106
|
+
|
|
107
|
+
if mine is None:
|
|
108
|
+
print(f"\nverdict: {SELF} itself is not importable. Reinstall it before "
|
|
109
|
+
f"anything else here means much.", file=out)
|
|
110
|
+
return 1
|
|
111
|
+
if missing_req:
|
|
112
|
+
print(f"\nverdict: {SELF} is missing required config "
|
|
113
|
+
f"({', '.join(missing_req)}). Those are read with os.environ[...], "
|
|
114
|
+
f"so the code path that needs them raises rather than degrades.",
|
|
115
|
+
file=out)
|
|
116
|
+
return 1
|
|
117
|
+
# A measured NO outranks a missing optional pair: awrise printed
|
|
118
|
+
# "nothing wakes run-due" and still exited 0 because the missing-pairs
|
|
119
|
+
# branch returned first (measured 2026-09-20).
|
|
120
|
+
if problems:
|
|
121
|
+
for p in problems:
|
|
122
|
+
print(f"\nverdict: {p}", file=out)
|
|
123
|
+
return 1
|
|
124
|
+
if unjudged:
|
|
125
|
+
for u in unjudged:
|
|
126
|
+
print(f"\nverdict: UNJUDGED -- could not judge: {u}", file=out)
|
|
127
|
+
return 2
|
|
128
|
+
if missing_pairs:
|
|
129
|
+
print(f"\nverdict: {SELF} works, but pairs with "
|
|
130
|
+
f"{', '.join(sorted(missing_pairs))} which "
|
|
131
|
+
f"{'is' if len(missing_pairs) == 1 else 'are'} not installed. "
|
|
132
|
+
f"That is a capability you are missing, not an error.", file=out)
|
|
133
|
+
return 0
|
|
134
|
+
print(f"\nverdict: {SELF} and everything it pairs with are present.", file=out)
|
|
135
|
+
return 0
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _local_verdict() -> tuple:
|
|
139
|
+
"""The brick's OWN verdict, folded into the exit code.
|
|
140
|
+
|
|
141
|
+
Without this the local lines are DECORATION. Measured 2026-09-20: awrise
|
|
142
|
+
printed "hostclock NOT INSTALLED -- nothing wakes run-due" and "last tick
|
|
143
|
+
never", then exited 0 -- teaching an operator that a doctor exit code
|
|
144
|
+
carries no information. A brick opts in with `_doctor_local_verdict()`
|
|
145
|
+
returning (problems, unjudged); a brick without one is unaffected.
|
|
146
|
+
"""
|
|
147
|
+
try:
|
|
148
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
149
|
+
problems, unjudged = mod._doctor_local_verdict()
|
|
150
|
+
except Exception: # noqa: BLE001
|
|
151
|
+
return [], []
|
|
152
|
+
return list(problems or []), list(unjudged or [])
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _local_checks() -> "list[str]":
|
|
156
|
+
"""Per-brick checks, if this package defines them.
|
|
157
|
+
|
|
158
|
+
Kept as a HOOK rather than generated guesses: the generator knows the family
|
|
159
|
+
from the registry, but it does not know what awprove needs at runtime, and a
|
|
160
|
+
doctor that invented config requirements would be confidently wrong. A
|
|
161
|
+
package supplies `_doctor_local()` returning display lines; absent, the
|
|
162
|
+
stack picture above still stands on its own.
|
|
163
|
+
"""
|
|
164
|
+
try:
|
|
165
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
166
|
+
except Exception:
|
|
167
|
+
return []
|
|
168
|
+
try:
|
|
169
|
+
return list(mod._doctor_local())
|
|
170
|
+
except Exception as exc: # noqa: BLE001
|
|
171
|
+
return [f"local checks raised {type(exc).__name__}: {exc}"]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def main(argv: "list[str] | None" = None) -> int:
|
|
175
|
+
# --self-test delegates to a SIBLING module when one exists.
|
|
176
|
+
#
|
|
177
|
+
# This file is generated and a fresh run replaces it, so a self-test
|
|
178
|
+
# written HERE is deleted by the next regeneration. awdelphi learned that
|
|
179
|
+
# the expensive way: 125 lines exercising four real failure paths --
|
|
180
|
+
# convergence, roster anonymization, resume, gateway-down -- lived in this
|
|
181
|
+
# file and were destroyed by a routine regeneration, silently, leaving a
|
|
182
|
+
# --self-test flag that reported PASS while asserting nothing.
|
|
183
|
+
#
|
|
184
|
+
# So the seam is a separate module the generator never writes. A package
|
|
185
|
+
# with real machinery to prove puts it in _selftest.py; everything else
|
|
186
|
+
# keeps the honest answer below rather than a self-test that only ever
|
|
187
|
+
# passes.
|
|
188
|
+
argv = list(argv if argv is not None else __import__("sys").argv[1:])
|
|
189
|
+
if "--self-test" in argv:
|
|
190
|
+
try:
|
|
191
|
+
from . import _selftest as _st
|
|
192
|
+
except Exception:
|
|
193
|
+
print("no _selftest module: this doctor reports the stack, and has",
|
|
194
|
+
"no machinery of its own to prove")
|
|
195
|
+
return 0
|
|
196
|
+
return int(_st.run())
|
|
197
|
+
return report()
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
if __name__ == "__main__":
|
|
201
|
+
raise SystemExit(main())
|
awprove/assertions.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Evaluate one assertion against one Observation. Pure functions, no browser.
|
|
2
|
+
|
|
3
|
+
This module is the load-bearing seam of the whole product. Because an assertion is a
|
|
4
|
+
pure function of an Observation, the exact predicate that gates production can be run
|
|
5
|
+
against a FABRICATED Observation — a "good" one and a "broken" one — with no browser,
|
|
6
|
+
no network and no flake. That is what makes an awprove gate self-testable: the engine
|
|
7
|
+
can prove it goes red on a broken page without ever rendering one.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
|
|
15
|
+
from .observation import Observation
|
|
16
|
+
from .spec import Assertion
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class AssertionResult:
|
|
21
|
+
id: str
|
|
22
|
+
ok: bool
|
|
23
|
+
describe: str
|
|
24
|
+
detail: str
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _contains(haystack: str, needle: str, is_regex: bool) -> bool:
|
|
28
|
+
if is_regex:
|
|
29
|
+
return re.search(needle, haystack) is not None
|
|
30
|
+
return needle in haystack
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def evaluate(assertion: Assertion, obs: Observation) -> AssertionResult:
|
|
34
|
+
"""Every supplied predicate must hold. The FIRST failing one names the reason,
|
|
35
|
+
so a red gate says 'the lock screen text was present' rather than just 'failed'."""
|
|
36
|
+
|
|
37
|
+
a = assertion
|
|
38
|
+
fails: list[str] = []
|
|
39
|
+
|
|
40
|
+
if a.dom_present and not _contains(obs.text, a.dom_present, a.regex):
|
|
41
|
+
fails.append(f"expected text {a.dom_present!r} was NOT on the page")
|
|
42
|
+
if a.dom_absent and _contains(obs.text, a.dom_absent, a.regex):
|
|
43
|
+
fails.append(f"text {a.dom_absent!r} that must be absent WAS on the page")
|
|
44
|
+
if a.url_matches and not re.search(a.url_matches, obs.url):
|
|
45
|
+
fails.append(f"final url {obs.url!r} did not match /{a.url_matches}/")
|
|
46
|
+
if a.eval_true:
|
|
47
|
+
# The runner records the JS result under the expression text. A missing
|
|
48
|
+
# result is a FAILURE, never a pass: an unevaluated probe proves nothing.
|
|
49
|
+
if a.eval_true not in obs.eval_results:
|
|
50
|
+
fails.append(f"eval {a.eval_true!r} was never evaluated (no result)")
|
|
51
|
+
elif not obs.eval_results[a.eval_true]:
|
|
52
|
+
fails.append(f"eval {a.eval_true!r} was falsey ({obs.eval_results[a.eval_true]!r})")
|
|
53
|
+
if a.vision_question:
|
|
54
|
+
ans = obs.vision_results.get(a.vision_question, "").strip().lower()
|
|
55
|
+
if not ans:
|
|
56
|
+
fails.append(f"vision question was never asked: {a.vision_question!r}")
|
|
57
|
+
elif not ans.startswith(a.vision_expect):
|
|
58
|
+
fails.append(
|
|
59
|
+
f"vision answered {ans!r}, expected it to start with {a.vision_expect!r}"
|
|
60
|
+
)
|
|
61
|
+
if a.network_ok:
|
|
62
|
+
status = obs.status_for(a.network_ok)
|
|
63
|
+
if status is None:
|
|
64
|
+
fails.append(f"no network call to {a.network_ok!r} was seen")
|
|
65
|
+
elif status >= 400:
|
|
66
|
+
fails.append(f"call to {a.network_ok!r} returned {status}")
|
|
67
|
+
|
|
68
|
+
ok = not fails
|
|
69
|
+
detail = "held" if ok else "; ".join(fails)
|
|
70
|
+
return AssertionResult(id=a.id, ok=ok, describe=a.describe, detail=detail)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def evaluate_all(assertions: list[Assertion], obs: Observation) -> list[AssertionResult]:
|
|
74
|
+
return [evaluate(a, obs) for a in assertions]
|
awprove/cli.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""awprove CLI: run a proof live, or pin it as a self-testing gate.
|
|
2
|
+
|
|
3
|
+
awprove run proofs/app-operational.yaml # drive + judge, exit 0/1/2
|
|
4
|
+
awprove pin proofs/app-operational.yaml [--out DIR]
|
|
5
|
+
awprove check proofs/app-operational.yaml # offline: proof is well-formed
|
|
6
|
+
# AND every assertion can fail
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from .fixtures import break_assertion, passing_observation
|
|
17
|
+
from .pin import gate_name, synthesize_gate
|
|
18
|
+
from .runner import _resolve_verify, http_vision, judge, run
|
|
19
|
+
from .spec import ProofError, load_proof
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _cmd_run(args) -> int:
|
|
23
|
+
proof = load_proof(args.proof)
|
|
24
|
+
hdrs: dict[str, str] = {}
|
|
25
|
+
for kv in (args.header or []):
|
|
26
|
+
if "=" in kv:
|
|
27
|
+
k, v = kv.split("=", 1)
|
|
28
|
+
hdrs[k.strip()] = v.strip()
|
|
29
|
+
vision = None
|
|
30
|
+
if args.vision_url:
|
|
31
|
+
env = dict(os.environ)
|
|
32
|
+
vision = http_vision(args.vision_url, verify=_resolve_verify(env))
|
|
33
|
+
report = run(
|
|
34
|
+
proof, browser_url=args.browser_url,
|
|
35
|
+
screenshot_dir=args.screenshots, headers=hdrs or None, vision=vision,
|
|
36
|
+
)
|
|
37
|
+
print(report.to_json() if args.json else report.summarize())
|
|
38
|
+
return report.exit_code()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _cmd_pin(args) -> int:
|
|
42
|
+
proof = load_proof(args.proof)
|
|
43
|
+
out_dir = Path(args.out)
|
|
44
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
45
|
+
ppath = Path(args.proof).resolve()
|
|
46
|
+
src = synthesize_gate(proof, ppath, proof_rel=str(ppath))
|
|
47
|
+
dest = out_dir / gate_name(proof)
|
|
48
|
+
dest.write_text(src, encoding="utf-8", newline="\n")
|
|
49
|
+
print(f"pinned {proof.name!r} -> {dest}")
|
|
50
|
+
print(" register it: add a gate_lanes.yaml entry (lane: fleet-live) and run")
|
|
51
|
+
print(f" its --self-test in CI. Prove it now: python {dest} --self-test")
|
|
52
|
+
return 0
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _cmd_check(args) -> int:
|
|
56
|
+
"""Offline: the proof loads, and every assertion provably can fail. No browser."""
|
|
57
|
+
proof = load_proof(args.proof)
|
|
58
|
+
good = passing_observation(proof)
|
|
59
|
+
if not judge(proof, good).passed:
|
|
60
|
+
print(f"CHECK FAIL: {proof.name}: the fabricated passing page did not pass")
|
|
61
|
+
return 1
|
|
62
|
+
for a in proof.assertions:
|
|
63
|
+
rep = judge(proof, break_assertion(good, a))
|
|
64
|
+
if rep.passed or not any((not r.ok) and r.id == a.id for r in rep.results):
|
|
65
|
+
print(f"CHECK FAIL: {proof.name}: assertion {a.id!r} cannot be shown to fail")
|
|
66
|
+
return 1
|
|
67
|
+
print(f"CHECK OK: {proof.name}: {len(proof.assertions)} assertion(s), each can fail")
|
|
68
|
+
return 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def main(argv=None) -> int:
|
|
72
|
+
# GENERATED doctor intercept (gen_aw_doctor.py) -- do not edit
|
|
73
|
+
_dv = locals().get("argv")
|
|
74
|
+
if (_dv if _dv is not None else __import__("sys").argv[1:])[:1] == ["doctor"]:
|
|
75
|
+
from ._doctor import report
|
|
76
|
+
return report()
|
|
77
|
+
# GENERATED repo-state intercept (gen_aw_doctor.py) -- do not edit
|
|
78
|
+
try:
|
|
79
|
+
from awgit import state as _aw_state
|
|
80
|
+
except Exception:
|
|
81
|
+
_aw_state = None
|
|
82
|
+
if _aw_state is not None:
|
|
83
|
+
_sv = locals().get("argv")
|
|
84
|
+
if _aw_state.cli_banner(_sv if _sv is not None else __import__("sys").argv[1:]):
|
|
85
|
+
return 0
|
|
86
|
+
ap = argparse.ArgumentParser(prog="awprove", description=__doc__)
|
|
87
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
88
|
+
|
|
89
|
+
r = sub.add_parser("run", help="drive the journey and judge the render")
|
|
90
|
+
r.add_argument("proof")
|
|
91
|
+
r.add_argument("--json", action="store_true")
|
|
92
|
+
r.add_argument("--browser-url", default=None)
|
|
93
|
+
r.add_argument("--screenshots", default=None, help="dir for evidence screenshots")
|
|
94
|
+
r.add_argument("--header", action="append",
|
|
95
|
+
help="k=v caller header for the browser service (e.g. X-User-Id=david); repeatable")
|
|
96
|
+
r.add_argument("--vision-url", default=os.getenv("AWPROVE_VISION_URL") or None,
|
|
97
|
+
help="AitherVision-shaped endpoint (POST image+prompt) that answers a "
|
|
98
|
+
"proof's vision assertions; default $AWPROVE_VISION_URL")
|
|
99
|
+
r.set_defaults(fn=_cmd_run)
|
|
100
|
+
|
|
101
|
+
p = sub.add_parser("pin", help="emit a self-testing gate that pins this proof")
|
|
102
|
+
p.add_argument("proof")
|
|
103
|
+
p.add_argument("--out", default=".", help="directory to write the gate into")
|
|
104
|
+
p.set_defaults(fn=_cmd_pin)
|
|
105
|
+
|
|
106
|
+
c = sub.add_parser("check", help="offline: proof is well-formed and every assertion can fail")
|
|
107
|
+
c.add_argument("proof")
|
|
108
|
+
c.set_defaults(fn=_cmd_check)
|
|
109
|
+
|
|
110
|
+
args = ap.parse_args(argv)
|
|
111
|
+
try:
|
|
112
|
+
return args.fn(args)
|
|
113
|
+
except ProofError as exc:
|
|
114
|
+
sys.stderr.write(f"awprove: {exc}\n")
|
|
115
|
+
return 2
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
raise SystemExit(main())
|
awprove/fixtures.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Fabricate a page that PASSES a proof and pages that each BREAK one assertion.
|
|
2
|
+
|
|
3
|
+
This is what makes an awprove gate self-testable. A generated gate's `--self-test`
|
|
4
|
+
does not need a browser: it asks this module for a synthetic Observation that
|
|
5
|
+
satisfies the proof, confirms the verdict is PASS, then for each assertion asks for
|
|
6
|
+
a variant that breaks exactly that assertion and confirms the verdict flips to FAIL
|
|
7
|
+
naming that assertion. If any of those flips does not happen, the gate cannot detect
|
|
8
|
+
that failure — and a gate that cannot go red is not a gate.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import copy
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
from .observation import Observation
|
|
17
|
+
from .spec import Assertion, Proof
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class UnsynthesizableProofError(ValueError):
|
|
21
|
+
"""The proof's predicates contradict each other, so no single passing page
|
|
22
|
+
exists (e.g. one assertion requires text that another forbids). Loud, never a
|
|
23
|
+
silent 'self-test skipped'."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _literal_of(pattern: str) -> str:
|
|
27
|
+
"""A best-effort literal that a regex would match — strip anchors and the
|
|
28
|
+
common metacharacters. Good enough for the path/host patterns proofs use;
|
|
29
|
+
verified against the real regex before it is trusted."""
|
|
30
|
+
lit = re.sub(r"[\\^$.*+?()\[\]{}|]", "", pattern)
|
|
31
|
+
return lit or "x"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def passing_observation(proof: Proof) -> Observation:
|
|
35
|
+
"""One synthetic page on which every assertion in the proof holds."""
|
|
36
|
+
present = [a.dom_present for a in proof.assertions if a.dom_present]
|
|
37
|
+
text = " | ".join(present) + " | awprove-fixture-filler"
|
|
38
|
+
for a in proof.assertions:
|
|
39
|
+
if a.dom_absent:
|
|
40
|
+
hit = re.search(a.dom_absent, text) if a.regex else (a.dom_absent in text)
|
|
41
|
+
if hit:
|
|
42
|
+
raise UnsynthesizableProofError(
|
|
43
|
+
f"assertion {a.id!r} forbids text {a.dom_absent!r} that another "
|
|
44
|
+
"assertion requires — the proof contradicts itself"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
url = proof.base.rstrip("/")
|
|
48
|
+
for a in proof.assertions:
|
|
49
|
+
if a.url_matches and not re.search(a.url_matches, url):
|
|
50
|
+
candidate = f"{proof.base.rstrip('/')}/{_literal_of(a.url_matches)}"
|
|
51
|
+
if re.search(a.url_matches, candidate):
|
|
52
|
+
url = candidate
|
|
53
|
+
else:
|
|
54
|
+
raise UnsynthesizableProofError(
|
|
55
|
+
f"cannot synthesize a url matching /{a.url_matches}/ for {a.id!r}"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
eval_results = {a.eval_true: True for a in proof.assertions if a.eval_true}
|
|
59
|
+
vision_results = {
|
|
60
|
+
a.vision_question: a.vision_expect
|
|
61
|
+
for a in proof.assertions if a.vision_question
|
|
62
|
+
}
|
|
63
|
+
network = [
|
|
64
|
+
{"url": f"{proof.base.rstrip('/')}/{a.network_ok.lstrip('/')}", "status": 200}
|
|
65
|
+
for a in proof.assertions if a.network_ok
|
|
66
|
+
]
|
|
67
|
+
return Observation(
|
|
68
|
+
url=url, title=f"{proof.name} (fixture)", text=text,
|
|
69
|
+
eval_results=eval_results, vision_results=vision_results, network=network,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def break_assertion(base: Observation, assertion: Assertion) -> Observation:
|
|
74
|
+
"""A copy of `base` mutated so exactly `assertion` fails. Breaks the assertion's
|
|
75
|
+
first predicate — one failing predicate is enough to make the assertion fail, and
|
|
76
|
+
the gate self-test only needs to prove the verdict can flip."""
|
|
77
|
+
obs = copy.deepcopy(base)
|
|
78
|
+
a = assertion
|
|
79
|
+
if a.dom_present:
|
|
80
|
+
obs.text = obs.text.replace(a.dom_present, "")
|
|
81
|
+
elif a.dom_absent:
|
|
82
|
+
obs.text = obs.text + " " + a.dom_absent
|
|
83
|
+
elif a.eval_true:
|
|
84
|
+
obs.eval_results[a.eval_true] = False
|
|
85
|
+
elif a.network_ok:
|
|
86
|
+
obs.network = [
|
|
87
|
+
{**c, "status": 503} if a.network_ok in str(c.get("url", "")) else c
|
|
88
|
+
for c in obs.network
|
|
89
|
+
]
|
|
90
|
+
elif a.vision_question:
|
|
91
|
+
obs.vision_results[a.vision_question] = "no" if a.vision_expect != "no" else "yes"
|
|
92
|
+
elif a.url_matches:
|
|
93
|
+
obs.url = "about:blank"
|
|
94
|
+
return obs
|
awprove/observation.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""What a real user's page actually looked like at a moment in a journey.
|
|
2
|
+
|
|
3
|
+
An Observation is the ONE thing every assertion is evaluated against, and it is a
|
|
4
|
+
plain data record with no browser attached. That separation is the whole design:
|
|
5
|
+
the runner produces an Observation by driving a live surface, but an assertion is a
|
|
6
|
+
*pure function* of an Observation, so the exact check that gates production can be
|
|
7
|
+
exercised offline against a fabricated Observation — which is how this engine proves
|
|
8
|
+
it can fail without a browser (the `--self-test` discipline, applied to the tool that
|
|
9
|
+
generates the tests).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class Observation:
|
|
19
|
+
"""A snapshot of the rendered page a real user would be looking at.
|
|
20
|
+
|
|
21
|
+
`text` is the visible innerText (what the human reads), NOT the raw DOM — an
|
|
22
|
+
HTTP 200 that renders "Sign in" to a signed-in user is a failure only
|
|
23
|
+
visible here, never in the status code.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
url: str = ""
|
|
27
|
+
title: str = ""
|
|
28
|
+
text: str = ""
|
|
29
|
+
# Results the runner recorded live for the assertion's own probes, keyed by the
|
|
30
|
+
# probe's source string. Offline fixtures provide these directly so a `eval_true`
|
|
31
|
+
# or `vision` assertion is still deterministically checkable without a browser.
|
|
32
|
+
eval_results: dict[str, object] = field(default_factory=dict)
|
|
33
|
+
vision_results: dict[str, str] = field(default_factory=dict)
|
|
34
|
+
# Network calls the page made during the step, as {url, status} — lets an
|
|
35
|
+
# assertion fail on "the panel fetched /api/chat and got 401" even when the page
|
|
36
|
+
# renders fine.
|
|
37
|
+
network: list[dict] = field(default_factory=list)
|
|
38
|
+
|
|
39
|
+
def status_for(self, url_substr: str) -> int | None:
|
|
40
|
+
"""The status of the last network call whose URL contains `url_substr`."""
|
|
41
|
+
hit = None
|
|
42
|
+
for call in self.network:
|
|
43
|
+
if url_substr in str(call.get("url", "")):
|
|
44
|
+
hit = call
|
|
45
|
+
return int(hit["status"]) if hit and "status" in hit else None
|
awprove/pin.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Synthesize a check_*.py gate from a proof — the 'pin it so it can't regress' half.
|
|
2
|
+
|
|
3
|
+
`awprove pin <proof.yaml>` emits a self-contained gate that (a) runs the proof live
|
|
4
|
+
and exits 0/1/2, and (b) carries a `--self-test` that proves it can go red, using the
|
|
5
|
+
fabricated pass/break pages from `fixtures.py` — no browser needed for the self-test.
|
|
6
|
+
The emitted gate is the AitherOS gate contract exactly: exit 0 clean, 1 violation,
|
|
7
|
+
2 could-not-judge (DEAD), and `--self-test` that fails if the check cannot fail.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from .spec import Proof
|
|
15
|
+
|
|
16
|
+
_TEMPLATE = '''#!/usr/bin/env python3
|
|
17
|
+
"""GENERATED by `awprove pin` from {proof_path}. Do not hand-edit — re-pin instead.
|
|
18
|
+
|
|
19
|
+
Gate for the awprove proof {name!r}: drive {base} as the real user and assert what
|
|
20
|
+
actually renders. Exit 0 clean, 1 a violation, 2 could-not-judge (browser
|
|
21
|
+
unreachable / journey did not run) — 'I could not look' is never a pass.
|
|
22
|
+
|
|
23
|
+
python {gate_name} [--json] [--browser-url URL] [--self-test]
|
|
24
|
+
|
|
25
|
+
The --self-test needs no browser: it fabricates a passing page and, for each
|
|
26
|
+
assertion, a page that breaks exactly that assertion, and proves the verdict flips.
|
|
27
|
+
"""
|
|
28
|
+
import argparse
|
|
29
|
+
import sys
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
from awprove.spec import load_proof
|
|
34
|
+
from awprove.runner import run, judge
|
|
35
|
+
from awprove.fixtures import passing_observation, break_assertion
|
|
36
|
+
except ImportError:
|
|
37
|
+
sys.stderr.write("awprove is not installed: pip install -e AitherOS/packages/awprove\\n")
|
|
38
|
+
sys.exit(2)
|
|
39
|
+
|
|
40
|
+
PROOF_PATH = Path(__file__).resolve().parent / {proof_rel!r}
|
|
41
|
+
if not PROOF_PATH.exists():
|
|
42
|
+
PROOF_PATH = Path({proof_abs!r})
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _self_test() -> int:
|
|
46
|
+
proof = load_proof(PROOF_PATH)
|
|
47
|
+
good = passing_observation(proof)
|
|
48
|
+
if not judge(proof, good).passed:
|
|
49
|
+
print("SELF-TEST FAIL: the fabricated passing page did not pass")
|
|
50
|
+
return 1
|
|
51
|
+
for a in proof.assertions:
|
|
52
|
+
bad = break_assertion(good, a)
|
|
53
|
+
rep = judge(proof, bad)
|
|
54
|
+
if rep.passed:
|
|
55
|
+
print(f"SELF-TEST FAIL: breaking {{a.id}} did not make the verdict FAIL")
|
|
56
|
+
return 1
|
|
57
|
+
if not any((not r.ok) and r.id == a.id for r in rep.results):
|
|
58
|
+
print(f"SELF-TEST FAIL: breaking {{a.id}} failed a DIFFERENT assertion")
|
|
59
|
+
return 1
|
|
60
|
+
print(f"SELF-TEST OK: {{len(proof.assertions)}} assertion(s) each provably can fail")
|
|
61
|
+
return 0
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def main() -> int:
|
|
65
|
+
ap = argparse.ArgumentParser()
|
|
66
|
+
ap.add_argument("--json", action="store_true")
|
|
67
|
+
ap.add_argument("--browser-url", default=None)
|
|
68
|
+
ap.add_argument("--self-test", action="store_true")
|
|
69
|
+
args = ap.parse_args()
|
|
70
|
+
if args.self_test:
|
|
71
|
+
return _self_test()
|
|
72
|
+
proof = load_proof(PROOF_PATH)
|
|
73
|
+
report = run(proof, browser_url=args.browser_url)
|
|
74
|
+
print(report.to_json() if args.json else report.summarize())
|
|
75
|
+
return report.exit_code()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
raise SystemExit(main())
|
|
80
|
+
'''
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def gate_name(proof: Proof) -> str:
|
|
84
|
+
return f"check_awprove_{proof.slug}.py"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def synthesize_gate(proof: Proof, proof_path: str | Path, proof_rel: str | None = None) -> str:
|
|
88
|
+
"""Return the source of the gate that pins this proof.
|
|
89
|
+
|
|
90
|
+
`proof_rel` is the proof path relative to where the gate will live (so the gate
|
|
91
|
+
finds its proof after both are committed); falls back to the absolute path.
|
|
92
|
+
"""
|
|
93
|
+
ppath = Path(proof_path)
|
|
94
|
+
# POSIX paths in the emitted source: a Windows path in a docstring (C:\A...)
|
|
95
|
+
# is an invalid escape sequence and makes the GENERATED gate warn on every parse.
|
|
96
|
+
return _TEMPLATE.format(
|
|
97
|
+
proof_path=ppath.as_posix(),
|
|
98
|
+
proof_abs=ppath.resolve().as_posix(),
|
|
99
|
+
proof_rel=(proof_rel or ppath.name),
|
|
100
|
+
name=proof.name,
|
|
101
|
+
base=proof.base,
|
|
102
|
+
gate_name=gate_name(proof),
|
|
103
|
+
)
|