interplane.io
Source of interplane.io: a Rust generator that renders the page from the protocol repository's public record, deployed hourly from the Spark.
Brought by drakestapleton
interplane.io / evidence / ONBOARDING-L642 / qualify.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Qualify actual generated routes and replay the literal rendered Quick Start. |
| 3 | Run at repository root after cargo build/build-dist. No deployment or model use. |
| 4 | """ |
| 5 | import gzip, hashlib, json, os, re, shutil, signal, subprocess, tempfile |
| 6 | from html.parser import HTMLParser |
| 7 | from pathlib import Path |
| 8 | from typing import Any |
| 9 | ROOT=Path(__file__).resolve().parents[2] |
| 10 | OUT=Path(__file__).resolve().parent |
| 11 | DIST=ROOT/'dist' |
| 12 | BINARY=ROOT/'target/debug/site-builder' |
| 13 | ROUTES=['/','/quick-start/','/concepts/','/adapter/','/conformance/','/status/'] |
| 14 | |
| 15 | def save(name,data): |
| 16 | if isinstance(data,str): data=data.encode() |
| 17 | (OUT/(name+'.gz')).write_bytes(gzip.compress(data,mtime=0)) |
| 18 | return {'file':name+'.gz','raw_sha256':hashlib.sha256(data).hexdigest(),'raw_bytes':len(data)} |
| 19 | def run(args,cwd=ROOT,timeout=180): |
| 20 | proc=subprocess.Popen(args,cwd=cwd,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,start_new_session=True) |
| 21 | try: raw=proc.communicate(timeout=timeout)[0] |
| 22 | except subprocess.TimeoutExpired: |
| 23 | os.killpg(proc.pid,signal.SIGTERM) |
| 24 | try: raw=proc.communicate(timeout=5)[0] |
| 25 | except subprocess.TimeoutExpired: |
| 26 | os.killpg(proc.pid,signal.SIGKILL); raw=proc.communicate()[0] |
| 27 | return 124,raw |
| 28 | return proc.returncode,raw |
| 29 | class Page(HTMLParser): |
| 30 | def __init__(self,text): |
| 31 | super().__init__(convert_charrefs=True) |
| 32 | self.links=[]; self.codes=[]; self.code=None; self.title=False; self.title_text=''; self.meta=[]; self.canonical=[] |
| 33 | self.feed(text) |
| 34 | def handle_starttag(self,tag,attrs): |
| 35 | attrs=dict(attrs) |
| 36 | if tag=='a': self.links.append(attrs.get('href')) |
| 37 | if tag=='meta': self.meta.append(attrs) |
| 38 | if tag=='link' and attrs.get('rel')=='canonical': self.canonical.append(attrs.get('href')) |
| 39 | if tag=='title': self.title=True |
| 40 | if tag=='code': self.code=[attrs,''] |
| 41 | def handle_data(self,data): |
| 42 | if self.title:self.title_text+=data |
| 43 | if self.code is not None:self.code[1]+=data |
| 44 | def handle_endtag(self,tag): |
| 45 | if tag=='title':self.title=False |
| 46 | if tag=='code' and self.code is not None:self.codes.append(self.code);self.code=None |
| 47 | |
| 48 | def main(): |
| 49 | manifest:dict[str,Any]={'source_commit':subprocess.check_output(['git','rev-parse','HEAD'],cwd=ROOT,text=True).strip(), |
| 50 | 'binary_sha256':hashlib.sha256(BINARY.read_bytes()).hexdigest(), |
| 51 | 'facts_sha256':hashlib.sha256((DIST/'facts.json').read_bytes()).hexdigest(), |
| 52 | 'scope':'static site and pinned scripted CPU reference; no deployment, model, GPU or general security qualification'} |
| 53 | shutil.copyfile(DIST/'facts.json',OUT/'facts-snapshot.json') |
| 54 | pages={route:Page((DIST/route.strip('/')/'index.html').read_text()) for route in ROUTES} |
| 55 | for route,p in pages.items(): |
| 56 | assert p.canonical==['https://interplane.io'+route],(route,p.canonical) |
| 57 | assert all(r in p.links for r in ROUTES),(route,p.links) |
| 58 | assert [m for m in p.meta if m.get('name')=='description'],route |
| 59 | assert len({p.title_text for p in pages.values()})==6 |
| 60 | assert len({next(m['content'] for m in p.meta if m.get('name')=='description') for p in pages.values()})==6 |
| 61 | manifest['routes']=ROUTES |
| 62 | with tempfile.TemporaryDirectory(prefix='L642-controls-',dir=os.environ['TMPDIR']) as temp: |
| 63 | dist=Path(temp)/'dist';shutil.copytree(DIST,dist) |
| 64 | rc,raw=run([str(BINARY),'verify',str(dist)]);assert rc==0,raw |
| 65 | controls=[] |
| 66 | for route in ROUTES: |
| 67 | file=dist/route.strip('/')/'index.html';original=file.read_text() |
| 68 | url='https://interplane.io'+route |
| 69 | mutations={ |
| 70 | 'wrong-canonical':original.replace(f'rel="canonical" href="{url}"','rel="canonical" href="https://wrong.example/"'), |
| 71 | 'wrong-title':original.replace('<title>INTERPLANE:','<title>WRONG:'), |
| 72 | 'wrong-json-ld':original.replace('SoftwareSourceCode','FakeSoftware'), |
| 73 | 'duplicate-head-canonical':original.replace('</head>',"<link rel='canonical' href='https://wrong.example/'></head>"), |
| 74 | 'duplicate-body-canonical':original.replace('</body>',"<LINK REL='canonical' HREF='https://wrong.example/'></body>"), |
| 75 | 'duplicate-head-image':original.replace('</head>',"<meta property='og:image' content='https://wrong.example/a.webp'></head>"), |
| 76 | 'duplicate-body-image':original.replace('</body>',"<META PROPERTY='og:image' CONTENT='https://wrong.example/a.webp'></body>"), |
| 77 | 'missing-route-target':original.replace('</body>','<a href="/missing-route/">missing</a></body>'), |
| 78 | 'missing-cross-page-fragment':original.replace('</body>','<a href="/quick-start/#missing-id">missing</a></body>'), |
| 79 | 'parent-traversal':original.replace('</body>','<a href="../facts.json">unsafe</a></body>'), |
| 80 | 'protocol-relative-target':original.replace('</body>','<a href="//wrong.example/">unsafe</a></body>'), |
| 81 | } |
| 82 | for name,changed in mutations.items(): |
| 83 | assert changed!=original,(route,name) |
| 84 | try: |
| 85 | file.write_text(changed);rc,raw=run([str(BINARY),'verify',str(dist)]) |
| 86 | controls.append({'route':route,'control':name,'exit':rc,'diagnostics':raw.decode(errors='replace')}) |
| 87 | assert rc!=0,(route,name,'accepted') |
| 88 | finally:file.write_text(original) |
| 89 | saved=file.with_name('index.saved');file.rename(saved) |
| 90 | try: |
| 91 | rc,raw=run([str(BINARY),'verify',str(dist)]) |
| 92 | controls.append({'route':route,'control':'missing-page','exit':rc,'diagnostics':raw.decode(errors='replace')});assert rc!=0 |
| 93 | finally:saved.rename(file) |
| 94 | rc,raw=run([str(BINARY),'verify',str(dist)]);assert rc==0,raw |
| 95 | manifest['controls']={'count':len(controls),'all_refused':all(c['exit']!=0 for c in controls),'raw':save('controls.json',json.dumps(controls,indent=2)+'\n')} |
| 96 | quick=pages['/quick-start/']; commands=next(text for attrs,text in quick.codes if attrs.get('class')=='language-sh') |
| 97 | expected=quick.codes[1][1] |
| 98 | match=re.search(r'git checkout --detach ([0-9a-f]{40})',commands); assert match |
| 99 | pin=match.group(1) |
| 100 | (OUT/'rendered-quick-start.sh').write_text(commands+'\n') |
| 101 | with tempfile.TemporaryDirectory(prefix='L642-rendered-recipe-',dir=os.environ['TMPDIR']) as temp: |
| 102 | rc,raw=run(['sh','-eu','-c',commands],cwd=Path(temp)) |
| 103 | proof={'exit':rc,'recipe_pin':pin,'expected_final_line':expected,'raw':save('quick-start-replay.log',raw)} |
| 104 | manifest['quick_start']=proof |
| 105 | (OUT/'qualification.json').write_text(json.dumps(manifest,indent=2)+'\n') |
| 106 | assert rc==0,raw.decode(errors='replace') |
| 107 | actual=subprocess.check_output(['git','rev-parse','HEAD'],cwd=Path(temp)/'interplane',text=True).strip();assert actual==pin |
| 108 | proof['checked_out_pin']=actual |
| 109 | lines=raw.decode().strip().splitlines();proof['actual_final_line']=lines[-1];assert lines[-1]==expected,(lines[-1],expected) |
| 110 | rows=re.findall(r'^c[1-4]\s+(web_fetch|send_email|write_file|append_note)\s+(authorized|denied|requires_approval)\s+(True|False)\s*$',raw.decode(),re.M) |
| 111 | assert rows==[('web_fetch','authorized','True'),('send_email','denied','False'),('write_file','denied','False'),('append_note','requires_approval','False')],rows |
| 112 | proof['observed_rows']=rows |
| 113 | (OUT/'qualification.json').write_text(json.dumps(manifest,indent=2)+'\n') |
| 114 | print(json.dumps(manifest,indent=2)) |
| 115 | if __name__=='__main__':main() |