Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienos.com/blob/main/scripts/test-home-floor.py # aienos.com Source of www.aienos.com, served from my own hardware Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienos.com / scripts / test-home-floor.py` 277 lines ยท 17239 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Independent output oracle for the home floor. Python is verification only. 3 Usage: python3 scripts/test-home-floor.py dist [baseline-dist] 4 The built-in negative controls must refuse a private or disconnected preview 5 and the old boxed layout, whose live floor covered about 60% of the screen. 6 The geometry check serves dist on 127.0.0.1 and asks headless Chrome 7 (CHROME, default google-chrome, as scripts/test-site-browser.mjs) for the 8 live floor's computed box at each screen size. 9 """ 10 from functools import partial 11 from html.parser import HTMLParser 12 from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer 13 from pathlib import Path 14 import json 15 import os 16 import re 17 import signal 18 import subprocess 19 import sys 20 import tempfile 21 import threading 22 23 24 class Document(HTMLParser): 25 def __init__(self, source): 26 super().__init__(convert_charrefs=True) 27 self.tags = [] 28 self.ids = [] 29 self.text = [] 30 self.skip = 0 31 self.feed(source) 32 33 def handle_starttag(self, tag, attrs): 34 attrs = dict(attrs) 35 self.tags.append((tag, attrs)) 36 if 'id' in attrs: 37 self.ids.append(attrs['id']) 38 if tag in ('script', 'style'): 39 self.skip += 1 40 41 def handle_endtag(self, tag): 42 if tag in ('script', 'style'): 43 self.skip -= 1 44 45 def handle_data(self, data): 46 if not self.skip and data.strip(): 47 self.text.append(' '.join(data.split())) 48 49 50 def check(source): 51 doc = Document(source) 52 clients = [a.get('src') for t, a in doc.tags if t == 'script' and a.get('src', '').startswith('/js/site.js')] 53 assert len(clients) == 1 and clients[0].startswith('/js/site.js?v=') and not clients[0].endswith('='), 'root must bypass the cached pre-floor client' 54 assert "') 152 153 154 def measure(out, mutate=None): 155 """Return {"WxH": box} for SIZES, as computed by headless Chrome. 156 Chrome runs in real time, not virtual time: under a virtual-time budget 157 the client's requestAnimationFrame callbacks sometimes never ran, so the 158 probe timed out with frames still waiting (2026-11-09, 3 of 5 runs). The 159 probe posts its measurement back and Chrome is stopped once it arrives.""" 160 probe = ('
' 161 + ''.join(f'' for w, h in SIZES) 162 + f'').encode() 163 posted, arrived = [], threading.Event() 164 165 class Handler(SimpleHTTPRequestHandler): 166 def log_message(self, *_): 167 pass 168 169 def send_body(self, body): 170 self.send_response(200) 171 self.send_header('Content-Type', 'text/html; charset=utf-8') 172 self.send_header('Content-Length', str(len(body))) 173 self.end_headers() 174 self.wfile.write(body) 175 176 def do_GET(self): 177 path = self.path.split('?')[0] 178 if path == PROBE: 179 return self.send_body(probe) 180 if path in ('/', '/index.html') and mutate: 181 return self.send_body(mutate((out / 'index.html').read_text()).encode()) 182 return super().do_GET() 183 184 def do_POST(self): 185 if self.path != DONE: 186 return self.send_error(404) 187 posted.append(self.rfile.read(int(self.headers['Content-Length'])).decode()) 188 self.send_body(b'') 189 arrived.set() 190 191 server = ThreadingHTTPServer(('127.0.0.1', 0), partial(Handler, directory=str(out))) 192 threading.Thread(target=server.serve_forever, daemon=True).start() 193 try: 194 with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as profile: 195 chrome = subprocess.Popen([os.environ.get('CHROME', 'google-chrome'), '--headless=new', '--disable-gpu', 196 '--disable-software-rasterizer', '--no-first-run', '--no-default-browser-check', 197 '--disable-extensions', '--disable-background-networking', '--disable-component-update', 198 '--disable-sync', '--metrics-recording-only', f'--user-data-dir={profile}', 199 '--window-size=1600,1000', '--remote-debugging-port=0', 200 f'http://127.0.0.1:{server.server_address[1]}{PROBE}'], 201 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True) 202 try: 203 arrived.wait(120) 204 finally: 205 os.killpg(chrome.pid, signal.SIGTERM) 206 chrome.wait(30) 207 finally: 208 server.shutdown() 209 assert posted, 'probe produced no measurement within 120 s' 210 boxes = json.loads(posted[0]) 211 assert sorted(boxes) == sorted(f'{w}x{h}' for w, h in SIZES), 'every size measured' 212 return boxes 213 214 215 def check_share(boxes): 216 for size, box in boxes.items(): 217 assert box['live'], f'{size}: live floor not activated with its public shell' 218 assert box['share'] >= MIN_SHARE, f'{size}: live floor covers {box["share"]:.1%} of the screen, under {MIN_SHARE:.0%}' 219 220 221 out = Path(sys.argv[1]) 222 source = (out / 'index.html').read_text() 223 doc = check(source) 224 for old, new in [('data-mode="public"', 'data-mode="private"'), ('href="/now/"', 'href="/wrong/"'), ('src="/js/site.js?v=floor-paint-1"', 'src="/js/site.js"')]: 225 assert old in source, 'negative control target exists' 226 try: 227 check(source.replace(old, new, 1)) 228 except AssertionError: 229 pass 230 else: 231 raise AssertionError('negative control accepted') 232 boxes = measure(out) 233 for size, box in boxes.items(): 234 print(f'floor {size}: {box["share"]:.1%} of the screen, frame {box["width"]:.0f}x{box["height"]:.0f} at y={box["top"]:.0f}, nav {box["nav"]}, document {box["doc"]}px') 235 check_share(boxes) 236 phone = boxes['390x844'] 237 assert phone['doc'] < 4000, f'phone homepage is {phone["doc"]}px tall, over 4000' 238 for size, box in boxes.items(): 239 assert box['overflow'] <= 0, f'{size}: horizontal scroll of {box["overflow"]}px' 240 assert not box['small'], f'{size}: tap targets under 44px: {box["small"]}' 241 assert not phone['tiny'], f'390x844: body text under 16px on phone: {phone["tiny"]}' 242 assert phone['h1lines'] == 1 and phone['beside'], f'390x844: heading must be one line beside the factory button, got {phone["h1lines"]} lines' 243 for size, box in boxes.items(): 244 if size != '390x844': 245 assert box['follow'] <= 420, f'{size}: follow block is {box["follow"]:.0f}px tall, over 420' 246 record = Document((out / 'record/index.html').read_text()) 247 for i in ('machines', 'speed', 'loop-title'): 248 assert i in record.ids, f'/record/ is missing #{i}' 249 assert source.count('') == 1, 'old-layout negative control target exists' 250 old_boxes = measure(out, lambda s: s.replace('', OLD_LAYOUT + '')) 251 print('old layout control: ' + ', '.join(f'{size} {box["share"]:.1%}' for size, box in old_boxes.items())) 252 try: 253 check_share(old_boxes) 254 except AssertionError: 255 pass 256 else: 257 raise AssertionError('negative control accepted the old boxed layout') 258 classic = Document((out / 'classic/index.html').read_text()) 259 assert [a.get('src') for t, a in classic.tags if t == 'script' and a.get('src', '').startswith('/js/site.js')] == ['/js/site.js'], 'classic keeps its existing client URL' 260 if len(sys.argv) > 2: 261 baseline = Path(sys.argv[2]) 262 old = Document((baseline / 'index.html').read_text()) 263 # Pass two moved these Follow cluster lines into the nine cards, which name 264 # the same destinations; any other retired text still fails. 265 retired = set(PASS2_RETIRED) 266 assert retired <= set(old.text), 'retired text list names only real baseline text' 267 # Every old visible text item remains, on the homepage or moved to /record/. 268 # Classic content and anchors stay unchanged across build timestamps. 269 for item in old.text: 270 assert item in retired or item in doc.text or item in record.text, f'existing text removed: {item[:70]}' 271 for i in old.ids: 272 assert i in doc.ids or i in record.ids, f'existing anchor removed: #{i}' 273 classic = Document((out / 'classic/index.html').read_text()) 274 old_classic = Document((baseline / 'classic/index.html').read_text()) 275 assert classic.text == old_classic.text and classic.ids == old_classic.ids, 'classic content or anchors changed' 276 print(f'HOME-FLOOR PASS: public engine and stream, section order, fallback, one heading, floor at least {MIN_SHARE:.0%} of the screen at ' 277 + ', '.join(f'{w}x{h}' for w, h in SIZES) + ', phone under 4000px, one-line phone heading, follow at most 420px on desktop, nine follow cards, no GitHub, no sideways scroll, 44px targets, 16px text, record holds the moved content, negative controls')