interplane.Get Omega
Read in your language

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

branch main Branches Tags History

interplane.io / evidence / discoverability-issue7 / qualify.py

61 lines · 3474 bytes Raw Blame History
1#!/usr/bin/env python3
2"""External qualification oracle; not part of the website runtime."""
3from pathlib import Path
4from html.parser import HTMLParser
5import json, subprocess, xml.etree.ElementTree as ET
6root = Path(__file__).resolve().parents[2]
7evidence = Path(__file__).resolve().parent
8dist = root / 'dist'
9facts = json.loads((dist/'facts.json').read_text())
10class Page(HTMLParser):
11 def __init__(self):
12 super().__init__(); self.links=[]; self.scripts=[]; self.canonicals=[]; self.images=[]; self.headings=[]
13 def handle_starttag(self, tag, attrs):
14 a=dict(attrs)
15 if tag=='a': self.links.append(a.get('href',''))
16 if tag=='script': self.scripts.append(a)
17 if tag=='link' and a.get('rel')=='canonical': self.canonicals.append(a['href'])
18 if tag=='img': self.images.append(a)
19 if tag in ('h1','h2','h3','h4','h5','h6'): self.headings.append(int(tag[1]))
20p=Page(); html=(dist/'index.html').read_text(); p.feed(html)
21assert p.scripts==[{'type':'application/ld+json'}]
22assert p.canonicals==['https://interplane.io/']
23assert p.headings.count(1)==1
24assert all(b<=a+1 for a,b in zip(p.headings,p.headings[1:]))
25assert all(x.get('alt','').strip() for x in p.images)
26sitemap=ET.parse(dist/'sitemap.xml').getroot()
27assert [x.text for x in sitemap.findall('{*}url/{*}loc')]==p.canonicals
28assert not sitemap.findall('{*}url/{*}lastmod')
29# Resolve all pinned GitHub source links against the authentic protocol tree once.
30full,sha=facts['pin']['full_name'],facts['pin']['sha']
31r=subprocess.run(['gh','api',f'repos/{full}/git/trees/{sha}?recursive=1'],capture_output=True,text=True)
32assert r.returncode==0,r.stderr
33tree=json.loads(r.stdout); assert not tree.get('truncated')
34paths={x['path'] for x in tree['tree']}
35source_links=[]
36for link in p.links:
37 marker=f'/blob/{sha}/'
38 if marker in link:
39 path=link.split(marker,1)[1]
40 assert path in paths,('broken pinned path',path)
41 source_links.append(link)
42(evidence/'protocol-tree.json').write_text(r.stdout+'\n')
43(evidence/'facts.json').write_text(json.dumps(facts,indent=2)+'\n')
44# Exercise the actual CLI verifier, not a mocked callback.
45index=dist/'index.html'; original=index.read_bytes(); outcomes=[]
46try:
47 candidates=[('valid',html,0),('executable-script',html+'<SCRIPT>alert(1)</SCRIPT>',1),
48 ('wrong-canonical',html.replace('rel="canonical" href="https://interplane.io/"','rel="canonical" href="https://wrong.example/"'),1),
49 ('invalid-json',html.replace('"@context":"https://schema.org"','"@context": INVALID'),1),
50 ('missing-local-link',html.replace('href="facts.json"','href="missing.json"'),1)]
51 for name,text,expected in candidates:
52 index.write_text(text)
53 r=subprocess.run([str(root/'target/debug/site-builder'),'verify',str(dist)],capture_output=True,text=True)
54 assert r.returncode==expected,(name,r.returncode,r.stdout,r.stderr)
55 outcomes.append(dict(case=name,exit=r.returncode,stdout=r.stdout,stderr=r.stderr))
56finally:index.write_bytes(original)
57result=dict(schema='interplane-discoverability-qualification/1',protocol_sha=sha,heading_sequence=p.headings,
58 pinned_source_links=source_links,cli_controls=outcomes,local_only=True,
59 limitation='Single current route; issue6 route expansion, deployed HTTP and organic ranking are not qualified here.')
60(evidence/'qualification.json').write_text(json.dumps(result,indent=2)+'\n')
61print(json.dumps(result,indent=2))