aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / scripts / test-home-floor.py
| 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 "<style data-home-floor>" in source, "styles available before first paint" |
| 55 | sheets = [a.get('href', '') for t, a in doc.tags if t == 'link' and 'stylesheet' in a.get('rel', '').split()] |
| 56 | assert not [h for h in sheets if 'floor' in h], f"no extra blocking stylesheets for the floor: {[h for h in sheets if 'floor' in h]}" |
| 57 | assert sheets == HOME_SHEETS, f"render-blocking stylesheets on / must be exactly {HOME_SHEETS}, got {sheets}" |
| 58 | assert source.index('<style>') < source.index('<style data-home-floor>'), 'shared styles inline, ahead of the floor style' |
| 59 | assert doc.ids.index('factory-floor') < doc.ids.index('home-allen') < doc.ids.index('go-deeper') < doc.ids.index('follow'), 'section order' |
| 60 | assert 'loop-title' not in doc.ids and 'machines' not in doc.ids, 'the record lives on /record/, not the homepage' |
| 61 | frame, = [a for t, a in doc.tags if t == 'iframe' and a.get('id') == 'factory-floor-frame'] |
| 62 | assert frame['loading'] == 'lazy' and frame.get('title'), 'independent, named preview' |
| 63 | assert 'srcdoc' not in frame and 'src' not in frame and 'hidden' in frame, 'preview must remain inert in the initial document' |
| 64 | assert 'factory-floor-wait' in doc.ids, 'static first-paint overview required' |
| 65 | inside = Document(frame['data-floor-srcdoc']) |
| 66 | assert any(t == 'html' and a.get('data-mode') == 'public' for t, a in inside.tags), 'public mode required' |
| 67 | assert any(t == 'base' and a.get('href') == '/now/' for t, a in inside.tags), 'same public stream base required' |
| 68 | assert [a.get('src') for t, a in inside.tags if t == 'script'] == ['/now/bay-status.js', '/now/factory.js', '/now/senses.js', '/now/usage-corner.js', '/now/rescue.js', '/now/workers.js', '/now/operator.js'], 'one existing floor engine and its explicit public presentation modules' |
| 69 | assert frame['data-floor-srcdoc'].index('<base ') < frame['data-floor-srcdoc'].index('<link '), 'base before resource discovery' |
| 70 | assert all(a.get('src', a.get('href', '/now/')).startswith('/now/') for t, a in inside.tags if t in ('link', 'script', 'img')), 'absolute public asset paths' |
| 71 | assert not set(inside.ids) & {'talkOpen', 'comms', 'dTalk', 'logins'}, 'private UI forbidden' |
| 72 | assert 'home-floor-frame,.home-floor-note{display:none}' in source, 'no-JS preview hidden' |
| 73 | assert 'The moving floor needs JavaScript.' in source, 'explicit static fallback' |
| 74 | assert any(t == 'a' and a.get('href') == '/now/' for t, a in doc.tags), 'factory entry link' |
| 75 | assert sum(t == 'h1' for t, _ in doc.tags) == 1, 'one parent heading' |
| 76 | assert all(not a.get('src', '').startswith(('http:', 'https:', '//')) for t, a in doc.tags if t == 'script'), 'no outside scripts' |
| 77 | assert 'github' not in source.lower(), 'the homepage names no GitHub host' |
| 78 | follow = source[source.index('id="follow"'):] |
| 79 | follow = Document(follow[:follow.index('</section>')]) |
| 80 | assert [a.get('href') for t, a in follow.tags if t == 'a'][:9] == FOLLOW, 'follow block holds the nine cards in order' |
| 81 | assert not any('source-link' in a.get('class', '') for t, a in doc.tags), 'no separate source box' |
| 82 | return doc |
| 83 | |
| 84 | |
| 85 | FOLLOW = ['/alpha/', '/learn/', '/hive/', '/now/', '/progress/', 'https://x.com/drakestapleton', 'mailto:drake@aienos.com', '/contact/', 'https://interplane.io/explore'] |
| 86 | # Drake 2026-11-09, pass two: the old Follow prose and link labels retired from |
| 87 | # the homepage; the cards above link the same places and /classic/ keeps them. |
| 88 | PASS2_RETIRED = ['Follow me on X', 'Follow the work.', |
| 89 | 'Watch the repositories, read the receipts, open an issue. Release artifacts and installation instructions are on', |
| 90 | 'the Alpha page', '; source, qualification and deployment are separate states.', |
| 91 | 'Learning to code with AI? You are welcome here.', 'Start with a practical working method', ', then', |
| 92 | 'watch my agents and me in Hive', ': the instructions, the models, the corrections, and the work as it happens.', |
| 93 | 'GitHub: aien-dev', 'Aien core tree', 'Now: what is being done today', 'Project progress', 'Want to reach me?', |
| 94 | 'Follow me on X, @drakestapleton', ', email', ', or read', 'where I am and how to reach me'] |
| 95 | |
| 96 | |
| 97 | # Render-blocking stylesheets on / (bay 7 F2, 2026-11-10; AienosPerf 2026-11-11): one palette file, the site |
| 98 | # palette plus the floor's tokens (raw colours live only in token files); the shared sheets ride inline in one |
| 99 | # <style> before the floor's own. Adding a stylesheet to / must change this list. |
| 100 | HOME_SHEETS = ['/assets/home-tokens.css'] |
| 101 | |
| 102 | # Drake 2026-11-09: the factory is the main attraction, at least 80% of the screen. |
| 103 | SIZES = [(1440, 900), (1280, 800), (1024, 768), (390, 844)] |
| 104 | MIN_SHARE = 0.80 |
| 105 | PROBE = '/__home-floor-probe__.html' |
| 106 | DONE = '/__home-floor-probe-done__' |
| 107 | # Each size is a same-origin iframe, so the homepage sees exactly that viewport |
| 108 | # and its own media queries. The probe waits for the deferred client to show |
| 109 | # the live floor, then records the part of its border box inside the first |
| 110 | # screen, the whole viewport (scrollbar included) being the denominator. |
| 111 | PROBE_SCRIPT = """ |
| 112 | const seen = {}; |
| 113 | function look(f) { |
| 114 | const d = f.contentDocument, w = f.contentWindow; |
| 115 | const e = d && d.getElementById('factory-floor-frame'); |
| 116 | if (!e || e.hidden || w.scrollY !== 0) return false; |
| 117 | const r = e.getBoundingClientRect(), vw = w.innerWidth, vh = w.innerHeight; |
| 118 | const x = Math.max(0, Math.min(r.right, vw) - Math.max(r.left, 0)); |
| 119 | const y = Math.max(0, Math.min(r.bottom, vh) - Math.max(r.top, 0)); |
| 120 | const head = d.querySelector('.aien-header, body > header'); |
| 121 | const small = [...d.querySelectorAll('.home-floor a, .home-floor button, .home-strip a, .home-deeper a, .home-allen a')] |
| 122 | .filter(a => a.offsetParent && a.getBoundingClientRect().height < 44).map(a => a.textContent.trim().slice(0, 40)); |
| 123 | const h1 = d.querySelector('.home-floor h1'), enter = d.querySelector('.home-floor-enter'); |
| 124 | const hr = h1.getBoundingClientRect(), er = enter.getBoundingClientRect(); |
| 125 | const follow = d.getElementById('follow'); |
| 126 | const tiny = [...d.querySelectorAll('.home-deeper span, .home-allen p, .home-floor-note')] |
| 127 | .filter(p => p.offsetParent && parseFloat(w.getComputedStyle(p).fontSize) < 16).map(p => p.textContent.trim().slice(0, 40)); |
| 128 | seen[f.dataset.size] = { vw, vh, left: r.left, top: r.top, width: r.width, height: r.height, |
| 129 | share: x * y / (vw * vh), nav: head ? head.getBoundingClientRect().height : null, |
| 130 | live: e.hasAttribute('srcdoc') && !e.hasAttribute('src'), |
| 131 | doc: d.documentElement.scrollHeight, overflow: d.documentElement.scrollWidth - d.documentElement.clientWidth, |
| 132 | small, tiny, h1lines: Math.round(hr.height / parseFloat(w.getComputedStyle(h1).lineHeight)), |
| 133 | beside: er.left >= hr.right && er.top < hr.bottom && er.bottom > hr.top, follow: follow.getBoundingClientRect().height }; |
| 134 | return true; |
| 135 | } |
| 136 | const frames = [...document.querySelectorAll('iframe')]; |
| 137 | (function tick() { |
| 138 | if (frames.filter(f => !(f.dataset.size in seen) && !look(f)).length) setTimeout(tick, 50); |
| 139 | else fetch(DONE, { method: 'POST', body: JSON.stringify(seen) }); |
| 140 | })(); |
| 141 | """ |
| 142 | # The released 152e3b0 geometry: a boxed floor inside the page container, |
| 143 | # a 64px two-line head and a frame of clamp(380px, 62vw, 680px), 1080px on phones. |
| 144 | OLD_LAYOUT = ('<style data-old-floor>.home-floor{margin-inline:0!important;padding:var(--space-6) 0 var(--space-4)!important}' |
| 145 | '.home-floor-stage{display:block!important;height:auto!important}' |
| 146 | '.home-floor-head{margin:0 0 var(--space-4)!important;padding:0!important;max-width:none!important;flex-wrap:wrap}.home-floor-head>div{display:block!important}' |
| 147 | '.home-floor h1{font-size:36px!important;line-height:40px!important}.home-floor-kicker{margin:0 0 var(--space-2)!important}' |
| 148 | '.home-floor-enter{min-height:44px!important}' |
| 149 | '.home-floor-frame{height:clamp(380px,62vw,680px)!important;border:1px solid var(--border)!important;border-radius:var(--radius-2xl)!important}' |
| 150 | '@media(max-width:600px){.home-floor-frame{height:1080px!important}.home-floor-enter{width:100%}.home-floor-head>div{display:block!important}' |
| 151 | '.home-floor h1{font-size:28px!important;line-height:32px!important}.home-floor-kicker{font-size:12px!important}}</style>') |
| 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 = ('<!doctype html><meta charset="utf-8"><body style="margin:0">' |
| 161 | + ''.join(f'<iframe data-size="{w}x{h}" src="/" style="display:block;border:0;width:{w}px;height:{h}px"></iframe>' for w, h in SIZES) |
| 162 | + f'<script>const DONE = {json.dumps(DONE)};' + PROBE_SCRIPT + '</script>').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('</head>') == 1, 'old-layout negative control target exists' |
| 250 | old_boxes = measure(out, lambda s: s.replace('</head>', OLD_LAYOUT + '</head>')) |
| 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') |