Files

66 lines
2.3 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""Verify a running living-server (AGENTS.md "Verify live"). Any red step
halts with a non-zero exit. Stdlib only.
Steps: health probe, metrics scrape, index load with the 360px markup checks,
then GET the first 10 matrix routes (2xx/3xx; 401 for /auth/me by design).
The 360px check is on markup and CSS (viewport meta, collapsing nav rule),
not on a rendered browser.
"""
import re
import sys
import urllib.error
import urllib.request
BASE = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:8080"
TIMEOUT = 15
red = []
def get(path):
req = urllib.request.Request(BASE + path, headers={"User-Agent": "verify-deploy/1"})
try:
with urllib.request.urlopen(req, timeout=TIMEOUT) as r:
return r.status, r.read().decode("utf-8", "replace")
except urllib.error.HTTPError as e:
return e.code, e.read().decode("utf-8", "replace")
except Exception as e: # connection refused, timeout
return 0, str(e)
def step(name, ok, detail=""):
print(f"{'ok ' if ok else 'RED '} {name}{(': ' + detail) if detail else ''}")
if not ok:
red.append(name)
code, body = get("/health")
step("health probe", code == 200 and '"status":"ok"' in body.replace(" ", ""), f"{code} {body[:60]}")
code, body = get("/metrics")
lines = [l for l in body.splitlines() if l and not l.startswith("#")]
step("metrics scrape", code == 200 and len(lines) > 0 and all(len(l.split()) >= 2 for l in lines[:20]),
f"{code}, {len(lines)} samples")
code, index = get("/")
step("index loads", code == 200 and "<table" in index, str(code))
step("360px viewport meta", "width=device-width" in index and "initial-scale=1" in index)
c2, css = get("/static/app.css")
step("narrow nav collapses", c2 == 200 and ".nav-narrow" in css and "min-width" in css)
hrefs = re.findall(r"<td><a href=\"([^\"]+)\">", index)
top = [h for h in hrefs if h.startswith("/")][:10]
step("matrix has routes", len(top) >= 10, f"{len(top)} found")
for route in top:
code, _ = get(route)
ok = 200 <= code < 400 or (route.startswith("/auth/me") and code == 401)
step(f"route {route}", ok, str(code))
code, body = get("/google/status")
print(f"info google: {code} {body[:120]}")
if red:
print(f"\nVERIFY FAILED: {len(red)} red step(s): {', '.join(red)}")
sys.exit(1)
print("\nVERIFY OK")