//! `quantum-conformance/fabric/expected.json` is what the browser leg of the //! fabric's WebGPU member holds a page to (`browser_webgpu.mjs`). This holds //! the file to the crate: it must be exactly the four certificates of the //! fabric's pinned corpora (both gatesets; random-v1 and fabric-v1 with their //! seeds, sizes and wide circuits; the corpus digests the CPU computes) and //! the two implementation ids, so that editing the file alone cannot weaken //! the leg, for instance by giving fabric-v1 random-v1's digest and so never //! running a circuit wider than one tile. A missing or unreadable file fails. //! //! The file lives outside this package, so this test is excluded from it. use std::path::Path; use serde_json::{Value, json}; use wai_quantum::quantum::Gateset; use wai_quantum::quantum_fabric::{Corpus, FABRIC_DEFAULT, apply_kernel, lanes, wgsl}; fn hex(b: &[u8]) -> String { b.iter().map(|x| format!("{x:02x}")).collect() } #[test] fn the_browser_legs_pins_are_the_crates() { let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../quantum-conformance/fabric/expected.json"); let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); let file: Value = serde_json::from_str(&text).unwrap_or_else(|e| panic!("{}: {e}", path.display())); let Corpus::Fabric { seed, cases, wide } = FABRIC_DEFAULT else { panic!("FABRIC_DEFAULT is a fabric corpus") }; let random = Corpus::Random { seed, cases }; let mut certificates = Vec::new(); for (corpus, wide) in [(random, 0), (FABRIC_DEFAULT, wide)] { for (number, gs) in [(1, Gateset::V1), (2, Gateset::V2)] { let cert = lanes::certify_corpus(gs, "local/test", corpus); certificates.push(json!({ "gateset": number, "kernel": apply_kernel(gs), "corpus": corpus.name(), "seed": seed, "cases": cases, "wide": wide, "cases_compared": cert.cases, "corpus_hex": hex(&cert.corpus), })); } } let want = json!({ "implementation": wgsl::implementation_id(), "tile_implementation": wgsl::tile_implementation_id(), "certificates": certificates, }); assert_eq!(file, want, "{} is not the crate's pins; the crate's are:\n{}", path.display(), serde_json::to_string_pretty(&want).unwrap()); // The four digests are the pinned ones, and fabric-v1's are not random-v1's. let digests: Vec<&str> = file["certificates"].as_array().unwrap().iter().map(|c| c["corpus_hex"].as_str().unwrap()).collect(); assert_eq!( digests, [ "d18454c639acfd9c7b66450f4ded1aac4ab46cc10a7bedbcf4958a96e204fb36", "3dbde276c1095bf827faec71d5980e050f8a55a5ba7d97cd3bbdaec3f43a13b2", "41c726a0ac80f7defef92e15ecf893bdb7a3076b5e7f670fa0b7142e5c033df7", "9a84b55af68f1a8b07390b234cf562dd8d85cef3185a697ab85690c8790a7809", ] ); }