"""out//report.html: one self-contained page (no script, fake pasture data only, no tokens) with the run's totals, the feature × server matrix, every failing cell with its examples, and the bash scenarios' checks. Written so it can be published as it is.""" import html import json import os import sys from collections import Counter, defaultdict import gen DIRS = ["in", "out", "via", "control", "local"] DIR_LABEL = {"in": "into PrivaPub", "out": "from PrivaPub", "via": "through PrivaPub", "control": "peer to peer", "local": "on its own server"} GROUPS = [("client", "decePub"), ("deliver", "Delivery"), ("confine", "Confinement"), ("see", "Seen by the audience"), ("hide", "Hidden from outsiders"), ("count", "Counts"), ("thread", "Threads"), ("edit", "Edits"), ("delete", "Deletes"), ("graph", "Follows"), ("privacy", "Privacy")] STATUS_ORDER = ["fail", "xpass", "xfail", "pass"] CSS = """ /* layout: one column; a sticky summary, then the matrix in its own horizontal scroller, then failures and scenarios */ :root { --bg: #f6f7f6; --panel: #ffffff; --fg: #1d2421; --muted: #5c6863; --line: #d9dfdc; --pass: #2f7d57; --fail: #c2412d; --xfail: #a77a14; --xpass: #6a4fc0; --none: #e4e9e6; --sans: "IBM Plex Sans", system-ui, sans-serif; --mono: "IBM Plex Mono", ui-monospace, monospace; } @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #121715; --panel: #1a211e; --fg: #e3e9e6; --muted: #98a59f; --line: #2c3632; --pass: #4fb184; --fail: #ec6c57; --xfail: #d6a940; --xpass: #9d86ef; --none: #26302c; color-scheme: dark } } :root[data-theme="dark"] { --bg: #121715; --panel: #1a211e; --fg: #e3e9e6; --muted: #98a59f; --line: #2c3632; --pass: #4fb184; --fail: #ec6c57; --xfail: #d6a940; --xpass: #9d86ef; --none: #26302c; color-scheme: dark } body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--sans); margin: 0; } main { max-width: 1180px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 48px; display: grid; gap: 28px; } h1 { font-size: 1.6rem; margin: 0; text-wrap: balance; } h2 { font-size: 1.15rem; margin: 0 0 10px; text-wrap: balance; } p { margin: 0; max-width: 70ch; color: var(--muted); } .meta { font: 13px var(--mono); color: var(--muted); overflow-wrap: anywhere; } .totals { display: flex; flex-wrap: wrap; gap: 8px 18px; font-variant-numeric: tabular-nums; } .total { display: flex; align-items: baseline; gap: 6px; } .total b { font: 600 1.35rem var(--mono); } .total span { text-transform: uppercase; letter-spacing: .06em; font-size: 12px; color: var(--muted); } .legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); } .legend i, .m { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -1px; } .s-pass { background: var(--pass); } .s-fail { background: var(--fail); } .s-xfail { background: var(--xfail); } .s-xpass { background: var(--xpass); } .s-none { background: var(--none); } .scroll { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; } table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; } th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; } thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); white-space: nowrap; } tbody th { font: 13px var(--mono); white-space: nowrap; } tr.group th { font: 600 12px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: var(--bg); } .cell { display: flex; gap: 3px; flex-wrap: nowrap; } .cell .m { width: 14px; height: 14px; } .fails { display: grid; gap: 10px; } details { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; } details[open] { padding-bottom: 12px; } summary { cursor: pointer; font: 13px var(--mono); overflow-wrap: anywhere; } summary:focus-visible { outline: 2px solid var(--xpass); outline-offset: 2px; } pre { font: 12px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; color: var(--muted); } .tag { font: 12px var(--mono); padding: 1px 6px; border-radius: 3px; color: var(--bg); } """ def cell_marks(cells, feature, observer): parts = [] for d in DIRS: agg = Counter() for key, v in cells.items(): f, origin, obs, direction = key.split("|") if f == feature and obs == observer and direction == d: for s in STATUS_ORDER: agg[s] += v[s] if not agg: continue worst = next(s for s in STATUS_ORDER if agg[s]) title = f"{DIR_LABEL[d]}: " + ", ".join(f"{agg[s]} {s}" for s in STATUS_ORDER if agg[s]) parts.append(f'') return "".join(parts) or '' def render(result, scenarios, title): cells = result["cells"] totals = Counter(result["totals"]) observers = [p for p in gen.HOSTS if any(k.split("|")[2] == p for k in cells)] + \ [o for o in ("*", "decepub") if any(k.split("|")[2] == o for k in cells)] features = sorted({k.split("|")[0] for k in cells}) out = [f"{html.escape(title)}", '', f"", "
"] out.append(f"

{html.escape(title)}

" f"

Every object the town's accounts made, checked on every server it should and should not have reached, " f"through each server's database and API. A cell's squares are the directions it was checked in: " f"into PrivaPub, from PrivaPub, through PrivaPub, peer to peer, and on the author's own server.

" f"
{html.escape(os.path.basename(result['run']))} · checked {html.escape(result['when'])}
") out.append('
' + "".join( f'
{totals.get(s, 0)}{s}
' for s in STATUS_ORDER) + "
") out.append('
pass fail' ' known gap, still failing known gap, now passing' ' not checked
') # the matrix rows = ["feature" + "".join(f"{html.escape(o)}" for o in observers) + ""] for prefix, label in GROUPS: group = [f for f in features if f.split(".")[0] == prefix] if not group: continue rows.append(f'{label}') for f in group: rows.append(f"{html.escape(f)}" + "".join( f'{cell_marks(cells, f, o)}' for o in observers) + "") rows.append("") out.append('

Matrix

' + "".join(rows) + "
") # failures bad = sorted(((k, v) for k, v in cells.items() if v["fail"] or v["xpass"]), key=lambda kv: (-kv[1]["fail"], kv[0])) items = [] for key, v in bad: f, origin, obs, d = key.split("|") status = "fail" if v["fail"] else "xpass" examples = "\n".join(json.dumps(e, ensure_ascii=False, default=str) for e in v["examples"]) items.append(f'
{v[status]}/{v["n"]} {html.escape(f)} · ' f'{html.escape(origin)} → {html.escape(obs)} · {html.escape(DIR_LABEL.get(d, d))}' f"
{html.escape(examples)}
") out.append(f'

Failing cells ({len(bad)})

' + ("".join(items) or "

None.

") + "
") # bash scenarios if scenarios: per = defaultdict(Counter) for s in scenarios: per[s["peer"]][s["status"]] += 1 srows = "".join(f"{html.escape(p)}" + "".join(f"{c.get(s, 0)}" for s in ("pass", "fail", "xfail")) + "" for p, c in per.items()) failed = "".join(f"
  • {html.escape(s['peer'])}: {html.escape(s['check'])} ({s['status']})
  • " for s in scenarios if s["status"] != "pass") out.append('

    Scenarios

    The pasture\'s scripted checks, one peer at a time.

    ' '
    ' f"{srows}
    peerpassfailknown gap
      {failed}
    ") out.append("
    ") return "\n".join(out) def merge(results): """Several runs' results as one: each cell's counts added up (a pair run's cells and the village's meet in one matrix), its examples kept, the runs named together.""" if len(results) == 1: return results[0] cells, totals = {}, Counter() for r in results: totals.update(Counter(r["totals"])) for key, v in r["cells"].items(): cell = cells.setdefault(key, {"n": 0, "pass": 0, "fail": 0, "xfail": 0, "xpass": 0, "examples": []}) for k in ("n", "pass", "fail", "xfail", "xpass"): cell[k] += v.get(k, 0) cell["examples"] = (cell["examples"] + v.get("examples", []))[:3] return {"run": " + ".join(os.path.basename(r["run"]) for r in results), "when": max(r["when"] for r in results), "cells": cells, "totals": dict(totals)} def main(args): import seed names = [a for a in args if not a.startswith("--")] or ["village"] run_dir = seed.run_dir(names[0]) results = [] for name in names: with open(os.path.join(seed.run_dir(name), "results.json")) as f: results.append(json.load(f)) result = merge(results) scenarios = [] path = os.path.join(seed.OUT, "scenarios.jsonl") if os.path.exists(path): with open(path) as f: scenarios = [json.loads(line) for line in f if line.strip()] # decePub's e2e cells (tests/e2e) join the servers' in the same matrix, under the observer "decepub" client = os.path.join(seed.OUT, "client.jsonl") if os.path.exists(client): import check with open(client) as f: lines = [json.loads(line) for line in f if line.strip()] latest = {} for c in lines: latest[(c["cell"], c.get("ref"))] = c # the latest result of each test checks = check.classify(list(latest.values()), check.load_gaps()) for cell, v in check.summarise(checks).items(): result["cells"][cell] = v from collections import Counter totals = Counter(result["totals"]) totals.update(Counter(c["status"] for c in checks)) result["totals"] = totals page = render(result, scenarios, "PrivaPub Town Matrix") target = os.path.join(run_dir, "report.html") with open(target, "w") as f: f.write(page) print(target) return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))