interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / crates / site-builder / src / components / cudaplusplus.rs

709 lines · 33018 bytes Raw Blame History
1//! /cudaplusplus/: CUDA++, the GPU half of Omega, as its own open source
2//! project (aien-dev/CUDApp, Apache-2.0 WITH LLVM-exception).
3//!
4//! The page renders, from `data/cudaplusplus.json`: what CUDA++ is and what
5//! it is for; the path from a program to the chip, each hop lit by whose
6//! code runs there (mine with a receipt, mine in part, mine being built,
7//! firmware as shipped); how I built the path; developer workflows;
8//! and installation and rollback down to the experimental kernel driver.
9//!
10//! The data file is checked at build time: an unknown status word, a PASS
11//! without a receipt under evidence/, an IN PROGRESS row without its ledger
12//! id, a box that does not link to GitHub, a link to a file on a branch
13//! that is not pinned to a full commit, or an em or en dash all fail the
14//! build and the tests.
15
16use std::sync::OnceLock;
17
18use maud::{html, Markup};
19use serde::Deserialize;
20
21use super::boxlink::{foot_labelled, Target};
22
23pub const TITLE: &str = "CUDA++ | AienOS";
24pub const DESCRIPTION: &str = "CUDA++ is the GPU half of Omega, plus scheduling and data movement, on DGX Spark GB10. Its execution path, receipts, developer workflow and installation status.";
25pub const URL: &str = "https://www.aienos.com/cudaplusplus/";
26
27/// The data file, compiled in and published as /cudaplusplus.json.
28pub const RAW: &str = include_str!("../../data/cudaplusplus.json");
29
30/// Status words a hop or row may carry.
31pub const STATUSES: [&str; 4] = ["PASS", "PARTIAL", "IN PROGRESS", "AS SHIPPED"];
32
33#[derive(Debug, Deserialize)]
34#[serde(deny_unknown_fields)]
35pub struct Data {
36 pub source: Source,
37 pub claim: String,
38 pub claim_rest: Vec<String>,
39 pub purpose_title: String,
40 pub purpose: String,
41 pub purpose_link: String,
42 pub source_note: String,
43 pub audit_link: String,
44 pub hops: Vec<Hop>,
45 pub how_lead: String,
46 pub steps: Vec<Card>,
47 pub did_not: Vec<String>,
48 pub did_not_box: String,
49 pub pain_lead: String,
50 pub pains: Vec<Row>,
51 pub swap_lead: String,
52 pub swaps: Vec<Row>,
53}
54
55#[derive(Debug, Deserialize)]
56#[serde(deny_unknown_fields)]
57pub struct Source {
58 pub repo: String,
59 pub readme: String,
60 pub how: String,
61 pub how_branch: String,
62 pub how_commit: String,
63 pub main_commit: String,
64 pub omega_doc: String,
65 pub omega_branch: String,
66 pub omega_commit: String,
67 pub checked: String,
68 pub ledger: String,
69 pub visibility: String,
70 pub owner_ledger: String,
71}
72
73#[derive(Debug, Deserialize)]
74#[serde(deny_unknown_fields)]
75pub struct Hop {
76 pub step: String,
77 pub cuda: String,
78 pub ours: String,
79 pub status: String,
80 pub note: String,
81 #[serde(default)]
82 pub ledger: Option<String>,
83 pub links: Vec<(String, String)>,
84 #[serde(rename = "box")]
85 pub box_: String,
86}
87
88#[derive(Debug, Deserialize)]
89#[serde(deny_unknown_fields)]
90pub struct Card {
91 pub title: String,
92 pub text: String,
93 pub links: Vec<(String, String)>,
94 #[serde(rename = "box")]
95 pub box_: String,
96}
97
98#[derive(Debug, Deserialize)]
99#[serde(deny_unknown_fields)]
100pub struct Row {
101 pub title: String,
102 pub text: String,
103 pub status: String,
104 #[serde(default)]
105 pub ledger: Option<String>,
106 #[serde(default)]
107 pub command: Option<String>,
108 #[serde(default)]
109 pub receipt: Option<String>,
110 pub links: Vec<(String, String)>,
111 #[serde(rename = "box")]
112 pub box_: String,
113}
114
115/// Expands a short link from the data file into a full address.
116/// `cp:` / `cp/:` a file / folder on CUDA++ main; `cp@:` a CUDA++ file at a
117/// full commit; `om@:` an omega file at a full commit; `ax@:` an aienux file
118/// at a full commit; `sc@/:` an aien-sovereign-core folder at a full commit;
119/// `s:` a file of this site on main. A link starting with `/` or `#` stays
120/// on this site. Files on branches are always pinned to a full commit.
121pub fn expand(link: &str) -> Result<String, String> {
122 const MAP: [(&str, &str, bool); 7] = [
123 ("cp/:", "https://interplane.io/drakestapleton/CUDApp/tree/main/", false),
124 ("cp@:", "https://interplane.io/drakestapleton/CUDApp/blob/", true),
125 ("cp:", "https://interplane.io/drakestapleton/CUDApp/blob/main/", false),
126 ("om@:", "https://interplane.io/drakestapleton/omega-mv/blob/", true),
127 ("ax@:", "https://interplane.io/drakestapleton/aienux/blob/", true),
128 ("sc@/:", "https://interplane.io/drakestapleton/aien-sovereign-core-mv/tree/", true),
129 ("s:", "https://interplane.io/drakestapleton/aienos.com/blob/main/", false),
130 ];
131 if link.starts_with('/') || link.starts_with('#') {
132 return Ok(link.to_string());
133 }
134 for (prefix, base, pinned) in MAP {
135 if let Some(rest) = link.strip_prefix(prefix) {
136 if rest.is_empty() || rest.contains("..") || rest.contains(' ') {
137 return Err(format!("bad link {link:?}"));
138 }
139 if pinned {
140 let sha = rest.split('/').next().unwrap_or("");
141 if sha.len() != 40 || !sha.bytes().all(|b| b.is_ascii_hexdigit()) || !rest[40..].starts_with('/') {
142 return Err(format!("a file on a branch must be pinned to a full commit: {link:?}"));
143 }
144 }
145 return Ok(format!("{base}{rest}"));
146 }
147 }
148 Err(format!("unknown link form {link:?}"))
149}
150
151fn gh(link: &str) -> String {
152 let h = expand(link).unwrap_or_else(|e| panic!("data/cudaplusplus.json: {e}"));
153 assert!(h.starts_with(super::boxlink::FORGE), "data/cudaplusplus.json: box link must be on the forge: {link}");
154 h
155}
156
157pub fn parse(raw: &str) -> Result<Data, String> {
158 serde_json::from_str(raw).map_err(|e| format!("data/cudaplusplus.json does not parse: {e}"))
159}
160
161fn check_status(what: &str, status: &str, ledger: &Option<String>, receipt: Option<&str>) -> Result<(), String> {
162 if !STATUSES.contains(&status) {
163 return Err(format!("{what}: unknown status {status:?}"));
164 }
165 if status == "IN PROGRESS" {
166 match ledger {
167 Some(l) if l.starts_with('L') && l[1..].bytes().all(|b| b.is_ascii_digit()) && l.len() > 1 => {}
168 _ => return Err(format!("{what}: IN PROGRESS needs its ledger id")),
169 }
170 }
171 if status == "PASS" {
172 match receipt {
173 Some(r) if r.contains("evidence/") => {}
174 _ => return Err(format!("{what}: PASS needs a receipt under evidence/")),
175 }
176 }
177 Ok(())
178}
179
180pub fn validate(d: &Data) -> Result<(), String> {
181 if RAW.contains('\u{2014}') || RAW.contains('\u{2013}') {
182 return Err("data/cudaplusplus.json has an em or en dash".into());
183 }
184 let mut boxes: Vec<&str> = vec![&d.source.readme, &d.source.how, &d.source.omega_doc, &d.purpose_link, &d.audit_link, &d.did_not_box];
185 let mut links: Vec<&str> = Vec::new();
186 if d.hops.len() < 8 {
187 return Err(format!("the path has {} hops; it runs from the program to the firmware (8)", d.hops.len()));
188 }
189 for h in &d.hops {
190 check_status(&h.step, &h.status, &h.ledger, Some(&h.box_))?;
191 boxes.push(&h.box_);
192 links.extend(h.links.iter().map(|l| l.1.as_str()));
193 }
194 for c in &d.steps {
195 boxes.push(&c.box_);
196 links.extend(c.links.iter().map(|l| l.1.as_str()));
197 }
198 for r in d.pains.iter().chain(d.swaps.iter()) {
199 if r.status == "AS SHIPPED" || r.status == "PARTIAL" {
200 return Err(format!("{}: a pain or swap row is PASS or IN PROGRESS", r.title));
201 }
202 check_status(&r.title, &r.status, &r.ledger, r.receipt.as_deref())?;
203 if r.status == "PASS" && r.command.is_none() {
204 return Err(format!("{}: a fixed row shows the command that proves it", r.title));
205 }
206 boxes.push(&r.box_);
207 if let Some(rc) = &r.receipt {
208 boxes.push(rc);
209 }
210 links.extend(r.links.iter().map(|l| l.1.as_str()));
211 }
212 for b in boxes {
213 let h = expand(b)?;
214 if !h.starts_with(super::boxlink::FORGE) {
215 return Err(format!("box link off the forge: {b}"));
216 }
217 }
218 for l in links {
219 expand(l)?;
220 }
221 if d.source.visibility != "private" && d.source.visibility != "public" {
222 return Err("source.visibility is private or public".into());
223 }
224 Ok(())
225}
226
227pub fn data() -> &'static Data {
228 static DATA: OnceLock<Data> = OnceLock::new();
229 DATA.get_or_init(|| {
230 let d = parse(RAW).unwrap_or_else(|e| panic!("{e}"));
231 validate(&d).unwrap_or_else(|e| panic!("data/cudaplusplus.json: {e}"));
232 d
233 })
234}
235
236fn status_class(s: &str) -> &'static str {
237 match s {
238 "PASS" => "cp-pass",
239 "PARTIAL" => "cp-partial",
240 "IN PROGRESS" => "cp-building",
241 _ => "cp-nvidia",
242 }
243}
244
245fn status_word(s: &str, ledger: &Option<String>) -> String {
246 match (s, ledger) {
247 ("IN PROGRESS", Some(l)) => format!("IN PROGRESS \u{00B7} {l}"),
248 ("AS SHIPPED", _) => "AS SHIPPED".to_string(),
249 _ => s.to_string(),
250 }
251}
252
253fn inline_links(links: &[(String, String)]) -> Markup {
254 html! {
255 @if !links.is_empty() {
256 ul class="om-links" {
257 @for (label, link) in links {
258 @let h = expand(link).unwrap_or_else(|e| panic!("{e}"));
259 li {
260 @if h.starts_with("https://") {
261 a href=(h) target="_blank" rel="noopener noreferrer" { (label) }
262 } @else {
263 a href=(h) { (label) }
264 }
265 }
266 }
267 }
268 }
269 }
270}
271
272/// A receipt in evidence/ is evidence; anything else is the source that
273/// holds the text.
274fn box_foot(link: &str) -> Markup {
275 let h = gh(link);
276 if link.contains("evidence/") {
277 foot_labelled(&h, "Receipt on the forge", Target::Evidence)
278 } else {
279 foot_labelled(&h, "Source on the forge", Target::Source)
280 }
281}
282
283fn ext(href: &str, text: &str) -> Markup {
284 html! { a href=(href) target="_blank" rel="noopener noreferrer" { (text) } }
285}
286
287/// Splits a note into plain text and `https://` links. A trailing period,
288/// comma, semicolon, colon or closing parenthesis stays outside the link.
289fn link_spans(note: &str) -> Vec<(bool, &str)> {
290 let mut out = Vec::new();
291 let mut rest = note;
292 while let Some(start) = rest.find("https://") {
293 if start > 0 {
294 out.push((false, &rest[..start]));
295 }
296 let after = &rest[start..];
297 let bytes = after.as_bytes();
298 let mut end = "https://".len();
299 while end < bytes.len() && !bytes[end].is_ascii_whitespace() && !matches!(bytes[end], b'<' | b'>' | b'"' | b'\'') {
300 end += 1;
301 }
302 let mut href_end = end;
303 while href_end > "https://".len() && matches!(bytes[href_end - 1], b'.' | b',' | b';' | b':' | b')') {
304 href_end -= 1;
305 }
306 out.push((true, &after[..href_end]));
307 rest = &after[href_end..];
308 }
309 if !rest.is_empty() {
310 out.push((false, rest));
311 }
312 out
313}
314
315fn linked_note(note: &str) -> Markup {
316 html! {
317 @for (is_link, text) in link_spans(note) {
318 @if is_link {
319 (ext(text, text))
320 } @else {
321 (text)
322 }
323 }
324 }
325}
326
327fn rows(list: &[Row]) -> Markup {
328 html! {
329 div class="cp-rows" {
330 @for r in list {
331 article class=(format!("cp-row {}", status_class(&r.status))) {
332 div class="cp-row-head" {
333 h3 class="cp-row-title" { (r.title) }
334 span class="cp-pill" { (status_word(&r.status, &r.ledger)) }
335 }
336 p { (r.text) }
337 @if let Some(c) = &r.command {
338 pre class="cp-cmd" { code { (c) } }
339 }
340 (inline_links(&r.links))
341 @match &r.receipt {
342 Some(rc) => { (box_foot(rc)) }
343 None => { (box_foot(&r.box_)) }
344 }
345 }
346 }
347 }
348 }
349}
350
351pub fn render_cudaplusplus_page() -> Markup {
352 let d = data();
353 let ours = d.hops.iter().filter(|h| h.status == "PASS").count();
354 let building = d.hops.iter().filter(|h| h.status == "IN PROGRESS").count();
355 html! {
356 div class="om-page cp-page" {
357 header class="om-hero" {
358 div class="container" {
359 p class="om-kicker" { "CUDA++ \u{00B7} open source, Apache-2.0 with the LLVM exception" }
360 h1 class="om-title" { (d.claim) }
361 @for p in &d.claim_rest {
362 p class="om-lead" { (p) }
363 }
364 div class="om-verdicts" {
365 div class="om-verdict om-verdict-true" {
366 p class="om-verdict-k" { "What it is for" }
367 p class="om-verdict-s" { (d.purpose_title) }
368 p class="cp-purpose" { (d.purpose) }
369 a class="om-verdict-a" href=(gh(&d.purpose_link)) target="_blank" rel="noopener noreferrer" { "Omega docs/OMEGA.md" }
370 }
371 div class="om-verdict om-verdict-not" {
372 p class="om-verdict-k" { "The repository" }
373 p class="om-verdict-s mono" { (ext(&d.source.repo, "aien-dev/CUDApp")) }
374 p class="cp-purpose" { (linked_note(&d.source_note)) }
375 a class="om-verdict-a" href=(gh(&d.audit_link)) target="_blank" rel="noopener noreferrer" { "The audit, docs/AUDIT.md" }
376 }
377 }
378 p class="om-source" {
379 "Written from the CUDA++ "
380 (ext(&gh(&d.source.readme), "README"))
381 " (main at " span class="mono" { (d.source.main_commit) } "), "
382 (ext(&gh(&d.source.how), "docs/HOW_WE_DID_IT.md"))
383 " (branch " span class="mono" { (d.source.how_branch) } " at " span class="mono" { (d.source.how_commit) } ") and Omega's "
384 (ext(&gh(&d.source.omega_doc), "docs/OMEGA.md"))
385 " (branch " span class="mono" { (d.source.omega_branch) } " at " span class="mono" { (d.source.omega_commit) } "), checked " (d.source.checked) ". "
386 "Ledger item " a href=(format!("/now/#{}", d.source.ledger)) { (d.source.ledger) } " tracks this page; "
387 a href=(format!("/now/#{}", d.source.owner_ledger)) { (d.source.owner_ledger) } " owns the repository. "
388 "Work that is not done shows as in progress with its ledger id. The rest of Omega: "
389 a class="omega-link" href="/omega/" { "What Omega is" } ". Data file: "
390 a href="/cudaplusplus.json" { "/cudaplusplus.json" } "."
391 }
392 nav class="om-toc" aria-label="On this page" {
393 a href="#path" { "From your program to the chip" }
394 a href="#how" { "How I did it" }
395 a href="#pain-points" { "Developer workflow" }
396 a href="#swap" { "Installation and rollback" }
397 }
398 }
399 }
400
401 section id="path" class="om-section" {
402 div class="container" {
403 p class="om-kicker" { "1 \u{00B7} From your program to the chip" }
404 h2 class="om-h2" { "The CUDA++ execution path" }
405 p class="om-sub" {
406 "Each step a GPU program goes through, top to bottom, with the work at that layer. The line on the left shows its state: green with a receipt, blue in part, amber being built, grey firmware as shipped. Today "
407 span class="mono" { (ours) } " steps are mine with a receipt and " span class="mono" { (building) } " is being built."
408 }
409 ol class="cp-path" {
410 @for h in &d.hops {
411 li class=(format!("cp-hop {}", status_class(&h.status))) {
412 span class="cp-node" aria-hidden="true" {}
413 div class="cp-hop-body" {
414 p class="cp-step" { (h.step) }
415 p class="cp-cuda" { span class="cp-lane" { "Layer" } " " (h.cuda) }
416 p class="cp-ours" { span class="cp-lane cp-lane-ours" { "Implementation" } " " (h.ours) }
417 (inline_links(&h.links))
418 }
419 div class="cp-hop-status" {
420 span class="cp-pill" { (status_word(&h.status, &h.ledger)) }
421 @if !h.note.is_empty() { span class="cp-note" { (h.note) } }
422 }
423 (box_foot(&h.box_))
424 }
425 }
426 }
427 }
428 }
429
430 section id="how" class="om-section" {
431 div class="container" {
432 p class="om-kicker" { "2 \u{00B7} How I did it" }
433 h2 class="om-h2" { "How I built the path" }
434 p class="om-sub" { (d.how_lead) }
435 div class="cp-steps" {
436 @for c in &d.steps {
437 article class="cp-card" {
438 h3 class="om-gap-title" { (c.title) }
439 p { (c.text) }
440 (inline_links(&c.links))
441 (box_foot(&c.box_))
442 }
443 }
444 }
445 article class="cp-card cp-didnot" {
446 h3 class="om-gap-title" { "Source and hardware boundaries" }
447 ul class="cp-list" {
448 @for t in &d.did_not { li { (t) } }
449 }
450 (box_foot(&d.did_not_box))
451 }
452 }
453 }
454
455 section id="pain-points" class="om-section" {
456 div class="container" {
457 p class="om-kicker" { "3 \u{00B7} Developer workflow" }
458 h2 class="om-h2" { "Each workflow, its status and the command that shows it" }
459 p class="om-sub" { (d.pain_lead) }
460 (rows(&d.pains))
461 }
462 }
463
464 section id="swap" class="om-section" {
465 div class="container" {
466 p class="om-kicker" { "4 \u{00B7} Installation and rollback" }
467 h2 class="om-h2" { "Down to the kernel driver" }
468 p class="om-sub" { (d.swap_lead) }
469 (rows(&d.swaps))
470 }
471 }
472 }
473 }
474}
475
476#[cfg(test)]
477mod tests {
478 use super::*;
479 use crate::components::boxlink::check_boxes;
480
481 #[test]
482 fn data_parses_and_validates() {
483 let d = parse(RAW).unwrap();
484 validate(&d).unwrap();
485 assert!(d.claim.starts_with("CUDA++ is the GPU half of Omega"));
486 assert_eq!(d.steps.len(), 4);
487 }
488
489 #[test]
490 fn repository_is_public() {
491 let d = data();
492 assert_eq!(d.source.visibility, "public");
493 assert_eq!(d.source.repo, "https://interplane.io/drakestapleton/CUDApp");
494 let note = d.source_note.to_ascii_lowercase();
495 assert!(!note.contains("private"), "{}", d.source_note);
496 assert!(!note.contains("safety audit"), "{}", d.source_note);
497 assert!(d.source_note.contains("https://interplane.io/drakestapleton/CUDApp"));
498 assert!(d.source_note.contains("https://interplane.io/drakestapleton/CUDApp/blob/main/docs/AUDIT.md"));
499 assert!(!RAW.contains("private_note"));
500 let s = render_cudaplusplus_page().into_string();
501 assert!(s.contains("<a href=\"https://interplane.io/drakestapleton/CUDApp\" target=\"_blank\" rel=\"noopener noreferrer\">https://interplane.io/drakestapleton/CUDApp</a>."));
502 assert!(s.contains("<a href=\"https://interplane.io/drakestapleton/CUDApp/blob/main/docs/AUDIT.md\" target=\"_blank\" rel=\"noopener noreferrer\">https://interplane.io/drakestapleton/CUDApp/blob/main/docs/AUDIT.md</a>"));
503 assert!(s.contains("Apache-2.0 with the LLVM exception"));
504 assert!(!s.contains("with LLVM exception"));
505 assert!(!s.contains("private until"));
506 assert!(!s.contains("CUDAplusplus"));
507 assert!(!s.contains("AGPL"));
508 }
509
510 #[test]
511 fn page_names_it_with_the_plus_signs() {
512 let s = render_cudaplusplus_page().into_string();
513 assert!(s.contains("<h1 class=\"om-title\">CUDA++ is the GPU half of Omega, plus the motor.</h1>"));
514 assert_eq!(s.matches("<h1").count(), 1);
515 assert!(s.contains("Useful work on a machine I own."));
516 for id in ["path", "how", "pain-points", "swap"] {
517 assert!(s.contains(&format!("id=\"{id}\"")), "{id}");
518 }
519 }
520
521 #[test]
522 fn every_box_links_to_the_forge() {
523 let s = render_cudaplusplus_page().into_string();
524 let n = check_boxes(&s).unwrap();
525 let d = data();
526 assert_eq!(n, d.hops.len() + d.steps.len() + 1 + d.pains.len() + d.swaps.len());
527 assert!(s.contains("https://interplane.io/drakestapleton/CUDApp/blob/62ea5a214d46f36e88cb7b892cecebf1f3e8a172/docs/HOW_WE_DID_IT.md"));
528 assert!(!s.contains("github.com"));
529 }
530
531 #[test]
532 fn pending_work_is_never_shown_as_done() {
533 let d = data();
534 let s = render_cudaplusplus_page().into_string();
535 for r in d.pains.iter().chain(d.swaps.iter()) {
536 if r.status == "IN PROGRESS" {
537 assert!(s.contains(&format!("IN PROGRESS \u{00B7} {}", r.ledger.as_ref().unwrap())));
538 }
539 }
540 let driver = d.hops.iter().find(|h| h.step == "Kernel driver").unwrap();
541 assert_eq!(driver.status, "IN PROGRESS");
542 assert_eq!(driver.ledger.as_deref(), Some("L332"));
543 }
544
545 #[test]
546 fn refusals() {
547 let d = parse(&RAW.replacen("\"status\": \"PARTIAL\"", "\"status\": \"ALMOST\"", 1)).unwrap();
548 assert!(validate(&d).unwrap_err().contains("unknown status"));
549 let mut d = parse(RAW).unwrap();
550 d.pains[0].status = "PASS".into();
551 assert!(validate(&d).unwrap_err().contains("PASS needs a receipt"));
552 let mut d = parse(RAW).unwrap();
553 d.swaps[0].ledger = None;
554 assert!(validate(&d).unwrap_err().contains("ledger id"));
555 let mut d = parse(RAW).unwrap();
556 d.pains[0].status = "PASS".into();
557 d.pains[0].receipt = Some("cp/:evidence/X".into());
558 assert!(validate(&d).unwrap_err().contains("command"));
559 let mut d = parse(RAW).unwrap();
560 d.pains[0].status = "AS SHIPPED".into();
561 assert!(validate(&d).unwrap_err().contains("a pain or swap row"));
562 let mut d = parse(RAW).unwrap();
563 d.pains[0].status = "NVIDIA".into();
564 assert!(validate(&d).unwrap_err().contains("unknown status"));
565 assert!(expand("cp@:docs/how-we-did-it/docs/HOW_WE_DID_IT.md").unwrap_err().contains("pinned"));
566 assert!(expand("om@:89aad7c/docs/OMEGA.md").is_err());
567 assert!(expand("x:foo").is_err());
568 assert!(expand("cp:../x").is_err());
569 }
570
571 #[test]
572 fn no_dashes_and_plain_words() {
573 let s = render_cudaplusplus_page().into_string();
574 assert!(!s.contains('\u{2014}') && !s.contains('\u{2013}'));
575 let lower = s.to_ascii_lowercase();
576 for w in ["revolutionary", "blazing", "cutting-edge", "seamless", "world-class", "powerful", "aienix", "game-chang"] {
577 assert!(!lower.contains(w), "{w}");
578 }
579 assert!(!s.contains("cudaplusplus is") && !s.contains("CUDA plus plus"));
580 }
581
582 /// Words the receipts do not support (Linear P-DRA-20, items 1 to 14).
583 const BANNED: [&str; 7] = ["drop-in", "binary-compatible", "first ever", "replaced cuda", "faster than cuda", "no nvidia software", "works on any nvidia gpu"];
584 const QUALIFIER: &str = "Hardware scope: GB10 only. The NVIDIA open kernel module 580.173.02 and NVIDIA-signed firmware remain in the path.";
585 /// The retired 35B model's speeds; each one carries its date and the words "retired model".
586 const RETIRED_35B: [&str; 4] = ["48.31", "135.1", "22.46", "57.10"];
587
588 fn strings<'a>(v: &'a serde_json::Value, out: &mut Vec<&'a str>) {
589 match v {
590 serde_json::Value::String(s) => out.push(s),
591 serde_json::Value::Array(a) => a.iter().for_each(|x| strings(x, out)),
592 serde_json::Value::Object(o) => o.values().for_each(|x| strings(x, out)),
593 _ => {}
594 }
595 }
596
597 /// Every claim in `texts` that breaks the public-claims rule.
598 fn claim_violations(name: &str, texts: &[&str]) -> Vec<String> {
599 let mut bad = Vec::new();
600 for t in texts {
601 let lower = t.to_ascii_lowercase();
602 for w in BANNED {
603 if lower.contains(w) {
604 bad.push(format!("{name}: {w:?} in {t:?}"));
605 }
606 }
607 for n in RETIRED_35B {
608 if t.contains(n) && !(t.contains("2026-10-21") && t.contains("retired model")) {
609 bad.push(format!("{name}: {n} without 2026-10-21 and \"retired model\" in {t:?}"));
610 }
611 }
612 }
613 bad
614 }
615
616 #[test]
617 fn public_claims_match_the_receipts() {
618 let files = [
619 ("data/cudaplusplus.json", RAW),
620 ("data/omega.json", crate::components::omega::RAW),
621 ("data/models.json", include_str!("../../data/models.json")),
622 ("data/machines.json", include_str!("../../data/machines.json")),
623 ];
624 let mut bad = Vec::new();
625 for (name, raw) in files {
626 let v: serde_json::Value = serde_json::from_str(raw).unwrap();
627 let mut texts = Vec::new();
628 strings(&v, &mut texts);
629 bad.extend(claim_violations(name, &texts));
630 }
631 let seo: Vec<&str> = crate::seo::PAGES.iter().map(|p| p.what).collect();
632 bad.extend(claim_violations("seo::PAGES", &seo));
633 for p in crate::seo::PAGES {
634 bad.extend(crate::components::voice::refresh_claims(p.what).into_iter().map(|b| format!("seo::PAGES {}: {b}", p.path)));
635 }
636 for d in crate::seo::DATA_FILES {
637 bad.extend(crate::components::voice::refresh_claims(d.cadence).into_iter().map(|b| format!("seo::DATA_FILES {}: {b}", d.path)));
638 if d.cadence.eq_ignore_ascii_case("hourly") {
639 bad.push(format!("seo::DATA_FILES {}: cadence \"hourly\"", d.path));
640 }
641 }
642 for (name, raw) in [("om/site/pages.json", include_str!("../../../../om/site/pages.json")), ("om/site/data-files.json", include_str!("../../../../om/site/data-files.json")), ("public/data/agent-repos.json", include_str!("../../../../public/data/agent-repos.json"))] {
643 bad.extend(crate::components::voice::refresh_claims(raw).into_iter().map(|b| format!("{name}: {b}")));
644 if raw.contains("\"cadence\": \"hourly\"") {
645 bad.push(format!("{name}: cadence \"hourly\""));
646 }
647 }
648 assert!(bad.is_empty(), "{bad:#?}");
649 for (name, page) in [("/cudaplusplus/", render_cudaplusplus_page().into_string()), ("/omega/", crate::components::omega::render_omega_page().into_string())] {
650 assert!(page.contains(QUALIFIER), "{name} lacks the hardware-scope qualifier");
651 assert!(claim_violations(name, &[&page]).is_empty(), "{name}: {:#?}", claim_violations(name, &[&page]));
652 }
653 let swap = &data().swaps[0].text;
654 assert!(swap.contains("planned user-space compatibility entry point") && swap.contains("L401"), "{swap}");
655 // /now/: ledger rows stay byte-identical; a withdrawn phrase must carry the note.
656 let at = crate::components::now::parse_utc("2026-11-07T18:00Z").unwrap();
657 let page = crate::components::now::render_ledger(NOW_SAMPLE, at);
658 assert!(crate::components::now::unannotated_withdrawn(&page).is_empty(), "{:#?}", crate::components::now::unannotated_withdrawn(&page));
659 assert!(page.matches(crate::components::now::WITHDRAWN_NOTE).count() >= 4, "every row holding a withdrawn phrase carries the note");
660 let clean = crate::components::now::render_ledger(&NOW_SAMPLE.lines().filter(|l| !l.starts_with("N00") || l.starts_with("N005")).collect::<Vec<_>>().join("\n"), at);
661 assert!(!clean.contains(crate::components::now::WITHDRAWN_NOTE), "a clean row carries no withdrawal note");
662 let ledger = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../public/data/now.tsv");
663 if let Ok(tsv) = std::fs::read_to_string(&ledger) {
664 let page = crate::components::now::render_ledger(&tsv, at);
665 let bad = crate::components::now::unannotated_withdrawn(&page);
666 assert!(bad.is_empty(), "{} : {bad:#?}", ledger.display());
667 }
668 }
669
670 /// Ledger rows holding withdrawn phrases in the item, the note and done-when,
671 /// as an open current card (N001), a folded old row (N002, N003), a settled
672 /// line (N004) and one clean row (N005).
673 const NOW_SAMPLE: &str = "id\topened_utc\towner\tstatus\titem\tdone_when\tevidence\tupdated_utc\n\
674N001\t2026-11-07T17:00Z\tdesk\topen\tShip a drop-in libcuda.so.1\tshim answers\t\t2026-11-07T17:30Z\n\
675N002\t2026-11-01T10:00Z\tdesk\topen\tResearch: kernel census\tFirst ever real run lands\t\t2026-11-01T10:00Z\n\
676N003\t2026-11-01T10:00Z\tdesk\topen\tResearch: encoder\treceipt filed\tstarted | it replaced CUDA here\t2026-11-01T11:00Z\n\
677N004\t2026-11-07T16:00Z\tdesk\tdone\tAgent: speed table\ttable merged\tmerged, Faster than CUDA on one kernel\t2026-11-07T17:00Z\n\
678N005\t2026-11-07T16:00Z\tdesk\topen\tAgent: plain row\tdone\tnothing to withdraw\t2026-11-07T17:00Z\n";
679
680 #[test]
681 fn public_claims_rule_refuses_planted_claims() {
682 for planted in ["A drop-in CUDA.", "It is Binary-Compatible.", "The first ever run.", "It replaced CUDA.", "Faster than CUDA.", "With no NVIDIA software.", "It works on any NVIDIA GPU."] {
683 assert_eq!(claim_violations("planted", &[planted]).len(), 1, "{planted}");
684 }
685 assert_eq!(claim_violations("planted", &["48.31 tokens a second"]).len(), 1);
686 assert_eq!(claim_violations("planted", &["57.10 in total (2026-10-21)"]).len(), 1);
687 assert!(claim_violations("planted", &["135.1 tokens a second (2026-10-21, retired model)"]).is_empty());
688 }
689
690 #[test]
691 fn now_rule_refuses_a_withdrawn_phrase_without_its_note() {
692 let at = crate::components::now::parse_utc("2026-11-07T18:00Z").unwrap();
693 let page = crate::components::now::render_ledger(NOW_SAMPLE, at);
694 let stripped = page.replace(crate::components::now::WITHDRAWN_NOTE, "");
695 assert!(crate::components::now::unannotated_withdrawn(&stripped).len() >= 4, "the rule must refuse rows whose note was removed");
696 let planted = "<li class=\"now-queue-row now-row\" id=\"X1\"><span class=\"now-queue-item\">It works on any NVIDIA GPU</span></li>";
697 assert_eq!(crate::components::now::unannotated_withdrawn(planted).len(), 1);
698 let note = crate::components::now::WITHDRAWN_NOTE;
699 let txt = crate::components::now::unannotated_withdrawn_text;
700 assert_eq!(txt("- L401swap: drop-in libcuda.so.1\n\n- L402next row").len(), 1, "a markdown row without the note is refused");
701 assert!(txt(&format!("- L401swap: drop-in libcuda.so.1{note}agent x\n\n- L402next row")).is_empty());
702 assert_eq!(txt(&format!("- L401swap: drop-in libcuda\n\n- L402next{note}")).len(), 1, "the next row's note does not cover this one");
703 assert_eq!(txt(&format!("L212Drake\n\n### A first ever run\n\n[Ledger line 213 on the forge](x){note}")).len(), 1, "a card note must come before its ledger link");
704 let full = format!("# Sovereign Intelligence\n\n---\n\n# Now\n\nSource: https://www.aienos.com/now/\nPublished: x.\n\n- L401drop-in{note}\n\n---\n\n# Paper\n\nSource: https://www.aienos.com/research/cuda-paper/\n\nIt is not a drop-in implementation.\n");
705 let now = crate::components::now::llms_now_section(&full).expect("llms-full has a /now/ section");
706 assert!(txt(now).is_empty() && !now.contains("Paper"), "the DOI negation is outside the /now/ section");
707 assert_eq!(txt(&full.replace(note, "")).len(), 2, "without the section cut the rule sees both, so the cut is load-bearing");
708 }
709}