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/crates/site-builder/src/components/speed.rs # 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 / crates / site-builder / src / components / speed.rs` 118 lines ยท 6304 bytes Raw Blame History 1 //! AienSpeed: the live inference speed test as one self-contained browser 2 //! component. `om/allen-page/speed-js.om` generates `public/js/aien-speed.js` 3 //! (run `sh om/allen-page/speed-check.sh`), and `public/assets/aien-speed.css` 4 //! styles it under `.aien-speed`. A page mounts it with 5 //! `window.AienSpeed.mount(el, options)`; no route serves it yet. These tests 6 //! only read the committed bytes. 7 8 #[cfg(test)] 9 mod tests { 10 use sha2::{Digest, Sha256}; 11 12 const SCRIPT: &str = include_str!("../../../../public/js/aien-speed.js"); 13 const STYLE: &str = include_str!("../../../../public/assets/aien-speed.css"); 14 15 #[test] 16 fn the_script_matches_its_omega_generated_sha256() { 17 let sidecar = include_str!("../../../../om/allen-page/aien-speed.js.sha256"); 18 let want = sidecar.split_whitespace().next().expect("sidecar holds a digest"); 19 assert_eq!(want.len(), 64, "a sidecar must hold one sha256 digest"); 20 let got = format!("{:x}", Sha256::digest(SCRIPT.as_bytes())); 21 assert_eq!(got, want, "aien-speed.js is generated, never hand-edited; run: sh om/allen-page/speed-check.sh"); 22 } 23 24 #[test] 25 fn the_script_builds_text_only_and_reaches_only_its_routes() { 26 for banned in [ 27 "innerHTML", "outerHTML", "insertAdjacentHTML", "document.write", "createContextualFragment", 28 "sessionStorage", "document.cookie", "eval(", "new Function", "XMLHttpRequest", "WebSocket", 29 "EventSource", "sendBeacon", "importScripts", " = SCRIPT.match_indices("fetch(").map(|(i, _)| &SCRIPT[i + 6..]).collect(); 35 assert_eq!(fetches.len(), 3); 36 for (call, route) in fetches.iter().zip(["mine.routes.info", "mine.routes.verify", "mine.routes.infer"]) { 37 assert!(call.starts_with(route), "fetch must take a route constant, found {}", &call[..40.min(call.len())]); 38 } 39 assert!(SCRIPT.contains("routes: { infer: `${options.api}/infer`, verify: `${options.api}/infer-verify`, info: `${options.api}/infer-info` },")); 40 assert!(SCRIPT.contains("api: '/aien/api',")); 41 // Local storage holds only the run history, under the history key. 42 assert_eq!(SCRIPT.matches("localStorage").count(), 3); 43 for call in ["localStorage.getItem(lab.options.historyKey)", "localStorage.setItem(lab.options.historyKey,", "localStorage.removeItem(lab.options.historyKey)"] { 44 assert_eq!(SCRIPT.matches(call).count(), 1, "{call}"); 45 } 46 // The one global it defines. 47 assert_eq!(SCRIPT.matches("window.AienSpeed = Object.freeze({ mount, unmount });").count(), 1); 48 for (i, _) in SCRIPT.match_indices("window.") { 49 let rest = &SCRIPT[i + 7..]; 50 assert!(rest.starts_with("AienSpeed") || rest.starts_with("devicePixelRatio"), "unexpected window use: {}", &rest[..30.min(rest.len())]); 51 } 52 assert!(SCRIPT.starts_with("(() => {\n 'use strict';\n") && SCRIPT.ends_with("})();\n")); 53 } 54 55 #[test] 56 fn the_copy_follows_the_site_voice() { 57 for text in [SCRIPT, STYLE] { 58 assert!(!text.contains('\u{2013}') && !text.contains('\u{2014}'), "no en or em dashes"); 59 for word in text.split(|c: char| !c.is_ascii_alphabetic()) { 60 assert!(!matches!(word.to_ascii_lowercase().as_str(), "we" | "us" | "our" | "ours" | "ourselves"), "first person singular only: {word}"); 61 assert_ne!(word, "Allen", "the visible name is Aien"); 62 } 63 } 64 assert!(SCRIPT.contains("Same presets and the same measurement code as this page, against any OpenAI-compatible server.")); 65 assert!(SCRIPT.contains("const OWN_COMMAND = 'cd aienos.com && python3 scripts/allen/allen_infer.py bench http://127.0.0.1:8000 --model ';")); 66 assert!(SCRIPT.contains("From a copy of the aienos.com repository, which is moving to Interplane (downloads are not open yet).")); 67 assert!(!SCRIPT.contains("rad clone") && !SCRIPT.contains("rad:z"), "no Radicle command"); 68 assert!(SCRIPT.contains("'Verified: produced by this gateway'")); 69 assert!(SCRIPT.contains("'Not verified: this link was edited or is from another server'")); 70 assert!(SCRIPT.contains("const OFFLINE_TEXT = 'The model is offline right now. The speed test is back when it is.';")); 71 assert!(SCRIPT.contains("if (info.server_ok === false) {"), "infer-info server_ok false shows the offline state"); 72 } 73 74 #[test] 75 fn the_style_is_scoped_and_loads_nothing() { 76 for banned in ["url(", "@import", "#"] { 77 assert!(!STYLE.contains(banned), "aien-speed.css must not contain {banned}"); 78 } 79 let mut depth = 0usize; 80 let mut selector = String::new(); 81 let mut comment = false; 82 let bytes = STYLE.as_bytes(); 83 let mut i = 0; 84 while i < bytes.len() { 85 let c = bytes[i] as char; 86 if comment { 87 if c == '*' && bytes.get(i + 1) == Some(&b'/') { 88 comment = false; 89 i += 1; 90 } 91 } else if c == '/' && bytes.get(i + 1) == Some(&b'*') { 92 comment = true; 93 i += 1; 94 } else if c == '{' { 95 let head = selector.trim(); 96 if !head.starts_with("@media") { 97 for part in head.split(',') { 98 assert!(part.trim().starts_with(".aien-speed"), "unscoped selector: {}", part.trim()); 99 } 100 } 101 depth += 1; 102 selector.clear(); 103 } else if c == '}' { 104 depth -= 1; 105 selector.clear(); 106 } else if c == ';' { 107 selector.clear(); 108 } else { 109 selector.push(c); 110 } 111 i += 1; 112 } 113 assert_eq!(depth, 0); 114 for prop in ["--speed-fg:", "--speed-muted:", "--speed-accent:", "--speed-glass:"] { 115 assert!(STYLE.contains(prop), "{prop} is a host override point"); 116 } 117 } 118 }