"""Check that the served drawings encode the certified runs, then build the Lean certificates and record axioms. The theorem does not cover the browser's canvas drawing. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception """ import argparse import importlib.util import json import re import subprocess import sys from collections import Counter from pathlib import Path HERE = Path(__file__).resolve().parent GRAPHICS = HERE.parent DIST = HERE.parents[1] / 'dist' KERNEL_ONLY = ['Growth.Run.reached', 'Growth.tiny_valid', 'Growth.notTight_rejected', 'Growth.overBudget_rejected', 'Growth.heldTwice_rejected', 'Growth.overlong_rejected', 'Growth.misplacedMeeting_rejected', 'Growth.offSlot_rejected'] KINDS = {'laK7-n': 'points', 'laK7-r': 'origins', 'laK7-g': 'crossings', 'laK7-e': 'branches', 'laK7-b': 'meetings'} def classes(cls, prefix): found = re.findall(prefix + r'(\d+)', cls) return int(found[0]) if found else None def parse_markup(html): """Multisets of drawn dots (point, start, tone, fade) and link halves (segment, start, span, fade) per kind.""" drawn = {kind: Counter() for kind in KINDS.values()} for cls, d in re.findall(r' 2 * d: segment = (pts[v], along(pts[v], pts[y], d, weight[(v, y)], end2)) drawn[['crossings', 'branches', 'meetings'][kind]][(segment, d // pace, end2 // (2 * pace) - d // pace, fade(t))] += 1 return drawn def network(data): """Every point ends held by a tree whose wave met another's.""" final = {} for v, t, _, _ in data['claims']: final[v] = t return len(final) == len(data['points']) and all(data['trees'][t][3] is not None for t in final.values()) def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--source-only', action='store_true', help='Check the render sources and Lean project without the built pages; print the report without replacing it.') args = parser.parse_args() spec = importlib.util.spec_from_file_location('home_art_source', GRAPHICS / 'build-home-art.py') module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) report = {'scope': 'certified runs and their served drawings; no proof of canvas pixels', 'runs': {}, 'lean': {}} for name, run in module.RUNS.items(): data = json.loads((HERE / 'runs' / f'run-{name}.json').read_text()) assert module.lean_source(name, data) == (HERE / 'Growth' / f'Run{name.upper()}.lean').read_text(), (name, 'JSON data differs from Lean certificate input') tones = {i: p[2] for i, p in enumerate(module.field(module.random.Random(7000 + run)))} exp = expected(data, tones, module.along) assert parse_markup((GRAPHICS / 'components' / f'home-art-{name}.html').read_text()) == exp, (name, 'component differs from certified data') assert network(data), (name, 'final field is not one connected network') if not args.source_only: page = 'index.html' if name == 'a' else f'index-{name}.html' html = (DIST / page).read_text() assert '