//! Every staged screen's residual, derived at build time and compiled. //! //! //! //! A residual is a screen's markup with the request taken out of it: literals //! where the renderer decided, and a hole, a branch or a loop where a request //! does. Serving a screen from one is walking it and writing values into the //! gaps, so no `Node` is built and nothing is rendered. //! //! # Why this is generated rather than derived at startup //! //! A residual is produced by rendering, so a build script cannot make one: it //! would have to link the crate it is building. The two honest answers were to //! derive at boot into a `LazyLock`, or to generate. Generating won on three //! counts and Max ruled it (quasicoherent `793d99dd`, 2026-09-07): //! //! - **The artifact is readable and diffable.** A screen's markup is in the //! repo, in `residuals/compiled.rs`, where a change to it shows up in a diff //! rather than in a running process. //! - **Nothing happens at boot, and nothing can fail there.** `derive` panics //! loudly when a screen's branches do not nest, deliberately. At startup that //! is a boot failure; here it is a failed test. //! - **What ships is compiled.** The generated file is a `static` built from //! literals, so the strings are in read-only data and the tree that holds them //! is built by rustc. A `LazyLock` would still allocate on first use. //! //! # The staleness that is easy to miss //! //! A residual goes stale for two reasons and only one of them is visible. A //! screen changing shows up in the diff beside it. **quasi-webview changing //! does not**: the residual is that renderer's own output, and under the tree's //! `[patch]` block an edit in another repo silently leaves every committed //! residual one version behind, with no file here modified. //! //! So the check is a test rather than a pre-commit hook. [`generate`] is run by //! `cargo test` against the renderer actually linked, and its result is compared //! with what is committed. Regenerate with: //! //! ```sh //! cargo run --bin export-residuals //! ``` mod compiled; pub use compiled::*; use quasi_router::Node; use quasi_router::stage::{Plan, Residual}; use quasi_webview::Webview; /// One screen that serves from a residual: the `static` it gets, and the staged /// twin a derivation calls. type Staged = (&'static str, fn(&Plan) -> Node); /// Every screen on the seam. /// /// A list rather than a registry the screens add themselves to. A screen /// reaches the serving path by being named here, which is one place to read to /// know what is on the seam and what is still building a tree, and the /// alternative was a macro nobody can grep. fn roster() -> Vec { vec![ ("POLICY", |plan| { Node::Region(super::policy::page_region_staged(plan)) }), ("TEAM", |plan| { Node::Region(super::team::page_region_staged(plan)) }), ("USE_CASES", |plan| { Node::Region(super::use_cases::page_region_staged(plan)) }), ("FAN_PLUS", |plan| { Node::Region(super::fan_plus::page_region_staged(plan)) }), ("COLLECTIONS", |plan| { Node::Region(super::collections::page_region_staged(plan)) }), ("EXPORT_PORTAL", |plan| { Node::Region(super::export_portal::page_region_staged(plan)) }), ("GIT_REPOS", |plan| { Node::Region(super::git_repos::page_region_staged(plan)) }), // One module, two screens: the library tab and the settings section are // the same table under different chrome, so each gets its own residual. ("FORUMS_LIBRARY", |plan| { super::forum_memberships::library_pane_staged(plan) }), ("FORUMS_SETTINGS", |plan| { super::forum_memberships::settings_pane_staged(plan) }), ("BUYER_CONTACTS", |plan| { super::buyer_contacts::pane_staged(plan) }), ("LIBRARY_CONTACTS", |plan| { super::library_contacts::pane_staged(plan) }), ("PAYOUT_SUMMARY", |plan| { super::payout_summary::card_staged(plan) }), ("CREATORS", |plan| { Node::Region(super::creators::page_region_staged(plan)) }), ("SSH_KEYS", |plan| super::ssh_keys::pane_staged(plan)), ("GIT_EXPLORE", |plan| { Node::Region(super::git_explore::page_region_staged(plan)) }), ("FEED", |plan| { Node::Region(super::feeds::page_region_staged(plan)) }), ("USER_ANALYTICS", |plan| { super::user_analytics::pane_staged(plan) }), ] } /// A settled screen's markup, borrowed rather than built. /// /// The `body` half of [`super::served_document_mount`] for a screen that reads /// nothing. A `Cow::Borrowed` of the compiled literal: no allocation, no walk, /// no `Node`, and the same `&'static str` for every reader on every request. /// /// # Panics /// /// When the residual has a hole, a branch or a loop in it, which means the /// screen started reading the request and wants the filler instead. It cannot /// happen behind a mount that compiles, because /// `tests::a_settled_screen_is_one_literal` fails first. #[must_use] pub fn settled(residual: &'static Residual) -> std::borrow::Cow<'static, str> { std::borrow::Cow::Borrowed( residual .settled() .expect("a settled screen's residual is one literal"), ) } /// The residual of one staged screen, derived by rendering it now. /// /// The reference the committed file is checked against, and what the generator /// writes. Both call this, so a generated residual and a freshly derived one /// cannot be produced two different ways. #[must_use] pub fn derive(shape: fn(&Plan) -> Node) -> Residual { quasi_webview::stage::derive(&Webview::new(), shape) } /// The whole generated module, as Rust source. #[must_use] pub fn generate() -> String { let mut out = String::from( "//! Generated by `cargo run --bin export-residuals`. Do not edit.\n\ //!\n\ //! Every staged screen's markup with the request taken out of it, as a\n\ //! `static` the compiler builds. See the module above this one for why\n\ //! this is generated rather than derived at startup, and for the test\n\ //! that fails when it is stale.\n\n\ // Not formatted, because the staleness test compares this file with what\n\ // `generate` produces, byte for byte. `cargo fmt` rewrapping a `static`\n\ // here would fail that test against markup nobody had changed, and the\n\ // obvious repair -- regenerate, then format -- puts it straight back.\n\ // Nothing reads this file for pleasure; the markup in it is one line per\n\ // screen whatever the layout.\n\ #![cfg_attr(rustfmt, rustfmt::skip)]\n\n", ); for (name, shape) in roster() { out.push_str(&derive(shape).as_rust(name)); out.push('\n'); } out } #[cfg(test)] mod tests { use super::*; /// The committed file says what this renderer says today. /// /// The whole staleness check, and it covers the case a diff cannot: a /// quasi-webview change in another repo alters what `derive` produces /// without touching a byte here. #[test] fn every_committed_residual_matches_a_fresh_one() { let committed = include_str!("residuals/compiled.rs"); assert_eq!( committed, generate(), "the committed residuals are stale: run `cargo run --bin export-residuals`", ); } /// One screen on the seam, and the two ways to produce its markup. /// /// A table for [`roster`]'s reason: the checks below hold of every settled /// screen and not of `/policy` in particular, so a screen joins them by /// adding a row rather than by somebody copying two tests and renaming the /// halves they remembered to. struct Settled { /// What the address is, for a failure to name. path: &'static str, /// The compiled residual. residual: &'static Residual, /// The whole document, which is what the region has to appear inside. screen: fn() -> quasi_router::Screen, /// The region on its own, rendered the ordinary way. region: fn() -> Node, } /// Every screen whose residual settles to one literal. /// /// Named for what it returns rather than `settled`, which is the helper in /// the module above and would be shadowed by this under `use super::*`. /// /// Not every entry in [`roster`] belongs here: a screen that reads a request /// has holes, and `settled` answers `None` for it. Those are checked by /// filling instead. fn one_literal_screens() -> Vec { vec![ Settled { path: crate::quasi::policy::PATH, residual: &POLICY, screen: crate::quasi::policy::page_screen, region: || Node::Region(crate::quasi::policy::page_region()), }, Settled { path: crate::quasi::team::PATH, residual: &TEAM, screen: crate::quasi::team::page_screen, region: || Node::Region(crate::quasi::team::page_region()), }, ] } /// A settled screen's residual is one `Op::Lit` and nothing else. /// /// Phase 2's sharp test (`60047dc0`), which moved here when it turned out /// to be a pipeline property rather than a vocabulary one. These screens /// hold no operator and reach no value a request brings: their copy is in /// `content/` and read at macro time, and every shape they include is /// `#[constant]`, so each is evaluated once while the residual is derived /// rather than once per request. /// /// A hole, a branch or a loop appearing here means something about a page /// started depending on the request, which is a real change and worth /// failing on. #[test] fn a_settled_screen_is_one_literal() { for screen in one_literal_screens() { let ops = screen.residual.ops(); assert_eq!(ops.len(), 1, "{}: {ops:?}", screen.path); assert!( matches!(ops[0], quasi_router::stage::Op::Lit(_)), "{}: {ops:?}", screen.path, ); } } /// The residual is the document's own bytes, not a lookalike. /// /// The property the serving path rests on. A residual is derived from a /// *fragment* render of the region, and a document renders its regions /// through a different entry point; if the two disagreed by so much as an /// attribute, serving from the residual would quietly ship different markup /// than the page has always had. So the fragment has to appear in the /// document verbatim, and this is what says it does. #[test] fn what_a_residual_holds_appears_in_its_document_verbatim() { use quasi_axum::Serves as _; for screen in one_literal_screens() { let document = Webview::new().screen(&(screen.screen)()); let body = screen .residual .settled() .expect("a settled screen's residual is one literal"); assert!(document.contains(body), "{}: {document}", screen.path); } } /// Filling the residual gives back what the renderer gives. /// /// The acceptance test the task asked for, and it is an equality rather /// than a diff: what the seam must not lose is the markup itself, so the /// check is that the two paths agree byte for byte on a screen that has /// nothing varying in it. #[test] fn a_residual_serves_what_the_renderer_serves() { use quasi_axum::Serves as _; for screen in one_literal_screens() { let rendered = Webview::new().fragment(&(screen.region)()); assert_eq!( screen .residual .settled() .expect("a settled screen's residual is one literal"), rendered, "{}", screen.path, ); } } /// A holed screen's residual fills to what the renderer builds. /// /// `/use-cases` is the first screen on the seam that does not fold to a /// literal, and this is the check the settled ones cannot have: it is the /// filler that is being tested, not a borrow. Nine holes, one per card's /// tier line, and the equality is byte for byte against the tree the screen /// has always built. /// /// Two price sets rather than one, and that is the point. Filling with the /// defaults would pass against a residual that had baked one request's /// prices into its literals, which is the exact failure the seam could /// have. Prices nothing else in the tree uses cannot be baked. #[test] fn the_use_cases_residual_fills_to_what_the_renderer_builds() { use quasi_axum::Serves as _; for prices in [crate::tier_prices::TierPrices::default(), odd_prices()] { let filled = crate::quasi::use_cases::page_region_serve(&USE_CASES, &prices); let rendered = Webview::new() .fragment(&Node::Region(crate::quasi::use_cases::page_region(&prices))); assert_eq!(filled, rendered); } } /// The nine holes are holes, and the rest of the page is not. /// /// What says the split landed where the module header claims. A tenth hole /// means something else on the page started reading the request; a loop or /// a branch means the copy stopped being read at macro time, which is the /// regression `98fbee62` exists to prevent and which no rendering test /// would notice. #[test] fn the_use_cases_residual_is_nine_holes_and_literals() { use quasi_router::stage::Op; let ops = USE_CASES.ops(); let holes = ops .iter() .filter(|op| matches!(op, Op::Hole { .. })) .count(); assert_eq!(holes, 9, "one per card's tier line: {ops:?}"); assert!( ops.iter() .all(|op| matches!(op, Op::Lit(_) | Op::Hole { .. })), "a branch or a loop reached the residual: {ops:?}", ); } /// Prices no default and no assumptions file would produce. /// /// The storage envelopes are set as well as the fees, and `/creators` is /// why. A cell holding one piece of text says so on its container with /// `cell-value`, and an empty string is not one piece of text but no /// content at all -- so an empty cell and a filled one are two shapes, and /// a residual holds one. `TierPrices::default()` leaves every envelope /// empty; nothing serving this page does, because they are read from the /// assumptions file at boot and the validator refuses a missing one. /// /// The rule that generalises, and it is the one the converted screens /// already follow: **a hole that can be empty is guarded**, because empty /// is a different shape rather than a shorter value. `/c/{username}/{slug}` /// says `unless loaded.description().is_empty()` for exactly this reason. fn odd_prices() -> crate::tier_prices::TierPrices { crate::tier_prices::TierPrices { basic_std: 4321, small_files_std: 5678, big_files_std: 8765, everything_std: 9876, basic_total: "3GB".to_owned(), small_files_total: "40GB".to_owned(), big_files_total: "700GB".to_owned(), everything_total: "9TB".to_owned(), ..Default::default() } } /// The envelopes a served page actually carries. /// /// `TierPrices::default()` is a test artefact: every envelope is the empty /// string, which no request produces. See [`odd_prices`]. fn stated_prices() -> crate::tier_prices::TierPrices { crate::tier_prices::TierPrices { basic_total: "1GB".to_owned(), small_files_total: "20GB".to_owned(), big_files_total: "500GB".to_owned(), everything_total: "5TB".to_owned(), ..Default::default() } } /// A branching screen's residual fills to what the renderer builds, on /// every branch. /// /// `/fan-plus` is the first residual on the seam that carries branches: it /// asks four questions about the reader and holds the markup of every /// answer, so one filled render proves nothing. What is checked is every /// combination of the three standings and both banner states, each against /// the tree the screen has always built. /// /// This is the test that would have caught the span overlap the derivation /// panicked on (quasi-webview `stage::placed`): two guarded siblings whose /// markup shares a boundary can be located on top of each other, and a /// residual built on that serves one branch's markup inside another's. #[test] fn the_fan_plus_residual_fills_to_what_the_renderer_builds_on_every_branch() { use crate::quasi::fan_plus::{Standing, page_region, page_region_serve}; use quasi_axum::Serves as _; let standings = [ Standing::Visitor, Standing::Unsubscribed, Standing::Member { period_end: None }, Standing::Member { period_end: Some("March 3, 2027".to_owned()), }, ]; for standing in &standings { for just_subscribed in [false, true] { let filled = page_region_serve(&FAN_PLUS, standing, just_subscribed); let rendered = Webview::new().fragment(&Node::Region(page_region(standing, just_subscribed))); assert_eq!(filled, rendered, "just_subscribed={just_subscribed}"); } } } /// The branches a reader never sees are still in the compiled markup. /// /// The property that makes the seam worth having on a screen like this: all /// three readers get a compiled page, so nothing is rendered per request for /// the sake of the two answers this reader did not give. A literal going /// missing here means a branch stopped being derived, which the equality /// above would still pass if both paths lost it together. #[test] fn the_fan_plus_residual_holds_every_reader_s_markup() { let compiled = format!("{:?}", FAN_PLUS.ops()); for words in [ "Fan+ membership is active", "Support the platform", "Join Fan+", "Create an account", "now a Fan+ member", ] { assert!(compiled.contains(words), "{words} is not in the residual"); } } /// A looping screen's residual fills to what the renderer builds. /// /// `/c/{username}/{slug}` is the first residual on the seam that carries a /// **loop**: its items table is one compiled row body walked once per item, /// rather than a row's markup rendered per item. Filled at three lengths so /// a residual that had baked one request's row count into its literals /// fails: nought exercises the empty state, one the body once, and three /// the body repeated. /// /// Both visibilities as well, because the private banner is a branch and an /// equality on the public page alone would pass against a residual that had /// lost it. #[test] fn the_collections_residual_fills_to_what_the_renderer_builds() { use quasi_axum::Serves as _; for items in [0, 1, 3] { for is_public in [true, false] { let loaded = crate::quasi::collections::sample(items, is_public); let filled = crate::quasi::collections::page_region_serve(&COLLECTIONS, &loaded); let rendered = Webview::new().fragment(&Node::Region( crate::quasi::collections::page_region(&loaded), )); assert_eq!(filled, rendered, "items={items} is_public={is_public}"); } } } /// The row body is compiled once, not once per item the derivation saw. /// /// What says the loop is a loop. A residual derived from a one-row render /// and stored flat would still fill correctly at one item and lose rows at /// three, which the equality above catches; this catches the other half, /// that the table's markup is in the residual at all rather than being /// rebuilt per request. #[test] fn the_collections_residual_holds_its_row_body_once() { use quasi_router::stage::Op; fn loops(ops: &[Op]) -> usize { ops.iter() .map(|op| match op { Op::Loop(body) => 1 + loops(body), Op::Branch(body) => loops(body), _ => 0, }) .sum() } assert_eq!(loops(COLLECTIONS.ops()), 1, "one loop, over the items"); assert!( format!("{:?}", COLLECTIONS.ops()).contains("Creator"), "the table's headings are compiled, not built per request", ); } /// The export portal's residual fills to what the renderer builds. /// /// The first gated document on the seam, and the one whose copy moved out /// of a `const` in the same pass: the five direct cards are read at macro /// time and fold into literals, and what is left varying is whether this /// reader has files at all. Both answers, and two size lines under the /// yes, since the size is a hole and filling with one value would pass /// against a residual that had baked it in. #[test] fn the_export_portal_residual_fills_to_what_the_renderer_builds() { use crate::quasi::export_portal::Page; use quasi_axum::Serves as _; let pages = [ Page { has_content: false, content_size: "No files".to_owned(), }, Page { has_content: true, content_size: "1.4 GB + audio/cover files".to_owned(), }, Page { has_content: true, content_size: "17 KB".to_owned(), }, ]; for page in &pages { let filled = crate::quasi::export_portal::page_region_serve(&EXPORT_PORTAL, page); let rendered = Webview::new().fragment(&Node::Region( crate::quasi::export_portal::page_region(page), )); assert_eq!(filled, rendered, "has_content={}", page.has_content); } } /// The five direct exports are compiled, not rebuilt per request. /// /// What says the copy move landed. Each card's route is in the residual's /// literals; a loop appearing here would mean the cards went back to being /// read through a path the macro cannot evaluate. #[test] fn the_export_portal_residual_holds_its_five_cards() { use quasi_router::stage::Op; let compiled = format!("{:?}", EXPORT_PORTAL.ops()); for route in [ "/api/export/projects", "/api/export/sales", "/api/export/splits", "/api/export/purchases", "/api/export/followers", ] { assert!(compiled.contains(route), "{route} is not in the residual"); } fn loops(ops: &[Op]) -> usize { ops.iter() .map(|op| match op { Op::Loop(body) => 1 + loops(body), Op::Branch(body) => loops(body), _ => 0, }) .sum() } assert_eq!(loops(EXPORT_PORTAL.ops()), 0, "the cards are unrolled"); } /// The repository listing's residual fills to what the renderer builds. /// /// `/git/{owner}` is the first residual holding a **token**: a repository's /// visibility is a `Tag`, which has no sentinel of its own, so the tag is /// built with one in it and the residual carries the tag's markup as a /// literal around a hole (quasi-declare's structured slots). /// /// Four shapes, and the two axes are independent. Owner and visitor differ /// by a whole column as well as by the badges, and empty and populated by /// which of the two branches is placed at all. #[test] fn the_git_repos_residual_fills_to_what_the_renderer_builds() { use quasi_axum::Serves as _; for count in [0, 1, 3] { for is_owner in [true, false] { let loaded = crate::quasi::git_repos::sample(count, is_owner); let filled = crate::quasi::git_repos::page_region_serve(&GIT_REPOS, &loaded); let rendered = Webview::new() .fragment(&Node::Region(crate::quasi::git_repos::page_region(&loaded))); assert_eq!(filled, rendered, "count={count} is_owner={is_owner}"); } } } /// The badge's markup is compiled and only its word is a hole. /// /// What says the structured slot landed. A `Tag` staged as a value fails to /// compile; a `Tag` staged through leaves `class="tag"` in the residual's /// literals with the visibility word written in per row. Finding the markup /// here is finding that the second thing happened. #[test] fn the_git_repos_residual_compiles_its_badges() { let compiled = format!("{:?}", GIT_REPOS.ops()); assert!( compiled.contains("badge"), "the badge markup is not compiled", ); assert!( !compiled.contains("private"), "a visibility word was baked into a literal", ); } /// Both forum panes fill to what the renderer builds. /// /// The first panel screens on the seam, and the first module with two of /// them: the library tab and the settings section draw the same table under /// different chrome, so each has a residual and both are checked here. /// /// Empty and populated, and with the upstream configured and not. The base /// address is a hole inside the sentence's markdown -- the link's own /// destination -- so an empty one is the shape that would show a residual /// with the address baked into a literal. #[test] fn both_forum_residuals_fill_to_what_the_renderer_builds() { use crate::quasi::forum_memberships::{ library_pane, library_pane_serve, sample, settings_pane, settings_pane_serve, }; use quasi_axum::Serves as _; let none: Vec<_> = Vec::new(); let some = vec![ sample("rust", "moderator"), sample("audio", "member"), sample("film", "member"), ]; for memberships in [&none, &some] { for base in ["https://mt.example.com", ""] { assert_eq!( library_pane_serve(&FORUMS_LIBRARY, memberships, base), Webview::new().fragment(&library_pane(memberships, base)), "library: {} memberships, base {base:?}", memberships.len(), ); assert_eq!( settings_pane_serve(&FORUMS_SETTINGS, memberships, base), Webview::new().fragment(&settings_pane(memberships, base)), "settings: {} memberships, base {base:?}", memberships.len(), ); } } } /// The two contact panes fill to what the renderer builds. /// /// Both are tables behind guards, and the library's is two of them: buyers /// and shared-with, each with its own heading and its own empty state, and /// a third state where neither is placed and one line says so. Every /// combination is filled, because a residual that had lost one table's /// branch would still pass on the shapes where that table is absent. #[test] fn the_contact_residuals_fill_to_what_the_renderer_builds() { use quasi_axum::Serves as _; for count in [0, 1, 3] { let buyers: Vec<_> = (0..count) .map(|n| crate::quasi::buyer_contacts::sample(&format!("buyer{n}"))) .collect(); assert_eq!( crate::quasi::buyer_contacts::pane_serve(&BUYER_CONTACTS, &buyers), Webview::new().fragment(&crate::quasi::buyer_contacts::pane(&buyers)), "buyer contacts, {count} buyers", ); } for buyers in [0, 2] { for shared in [0, 2] { let held: Vec<_> = (0..buyers) .map(|n| crate::quasi::library_contacts::sample_buyer(&format!("buyer{n}"))) .collect(); let with: Vec<_> = (0..shared) .map(|n| { crate::quasi::library_contacts::sample_creator( &format!("{n}"), &format!("creator{n}"), &format!("Creator {n}"), ) }) .collect(); assert_eq!( crate::quasi::library_contacts::pane_serve(&LIBRARY_CONTACTS, &held, &with), Webview::new().fragment(&crate::quasi::library_contacts::pane(&held, &with)), "library contacts, {buyers} buyers and {shared} shared", ); } } } /// The SSH keys pane fills to what the renderer builds. /// /// The first residual holding a **select whose options mark themselves**, /// which is what quasicoherent `c32bb877` added and what this screen was /// blocked on. A picker used to say which option was marked once, at the /// field, as a value makeover-webview compared against each option -- and a /// residual holds one compiled body per loop, so "exactly one row differs" /// was not something the body could carry. Filled here with each theme /// marked in turn and with none, because a residual that had baked one /// row's mark would still pass on the shape where that row is the marked /// one. /// /// Two tables behind guards as well, each with its own empty state, so the /// counts are crossed the way the contact panes' are. #[test] fn the_ssh_keys_residual_fills_to_what_the_renderer_builds() { use crate::quasi::ssh_keys::{pane, pane_serve, sample_key, sample_token}; use quasi_axum::Serves as _; let installed = crate::theming::console_theme_options(None); assert!( installed.len() > 1, "the picker needs more than one option to be worth filling" ); for key_count in [0, 2] { for token_count in [0, 2] { let keys: Vec<_> = (0..key_count) .map(|n| sample_key(&format!("k{n}"), &format!("SHA256:{n}"))) .collect(); let tokens: Vec<_> = (0..token_count) .map(|n| sample_token(&format!("t{n}"), &format!("token{n}"))) .collect(); // Every theme marked in turn, and then a list with none marked: // an account whose stored theme is no longer installed. let none_marked: Vec<_> = installed .iter() .map(|theme| crate::theming::ThemeOption { id: theme.id.clone(), name: theme.name.clone(), selected: false, }) .collect(); let cases = installed .iter() .map(|theme| crate::theming::console_theme_options(Some(&theme.id))) .chain(std::iter::once(none_marked)); for themes in cases { let marked = themes.iter().position(|theme| theme.selected); assert_eq!( pane_serve(&SSH_KEYS, "max", &keys, &tokens, &themes), Webview::new().fragment(&pane("max", &keys, &tokens, &themes)), "ssh keys, {key_count} keys, {token_count} tokens, theme {marked:?}", ); } } } } /// The analytics tab fills to what the renderer builds, at every shape. /// /// The last screen to join the seam, and the one that needed a new member /// to do it (quasicoherent `7d6ad166`). Its revenue chart was a ceded /// region: the handler drew the markup and the renderer looked it up WHILE /// it rendered, so a residual derived from a bare `Webview` held the empty /// container and nothing at serve time could get inside it. /// /// Described, the chart is an axis and a run of bars, and what makes it /// compilable is that no renderer divides. The axis is a hole beside the /// loop and each magnitude is a hole inside it; a width worked out from the /// two would have left no stand-in to find and baked one reader's chart /// into the template. `quasi_router::stage::number_at` states the rule and /// `quasi-bench`'s `charted` proves the member against it. /// /// Four things vary here and each drops a different branch: /// /// - **The chart**, present and absent, against its own empty state. /// - **The stat cards**, which are three guarded figures -- no delta, a /// toned rise, a toned fall -- so a fill that only saw one would pass on /// a residual that had baked it. /// - **The comparison**, whose heading and table share a guard on there /// being more than one project. /// - **The totals**, against their own empty state. /// /// The range chips are crossed too, and they are the reason `latched` had /// to become guardable: which chip is held down is a fact a request brings, /// a `bool` has no stand-in, and a loop body cannot carry "exactly one of /// these differs" as a value. Said as a guard it is a clean deletion -- /// `class="chip latched"` against `class="chip"` -- so it derives as a /// branch inside the loop. That is `Choice::chosen`'s answer on the other /// control; `quasi_declare::symbolic::PLACED` is where it is allowed. #[test] fn the_analytics_residual_fills_to_what_the_renderer_builds() { use crate::quasi::user_analytics::{pane, pane_serve, sample}; use quasi_axum::Serves as _; // Every combination a card's delta can take, including the mixed strip // that draws two of the three guarded figures at once. let strips: &[&[Option]] = &[ &[], &[None], &[Some(true)], &[Some(false)], &[None, Some(true), Some(false)], ]; for bars in [0, 1, 5] { // One project is not a comparison, which is what that guard says, // so the three counts are the shapes it has. for projects in [0, 1, 3] { for totals in [0, 2] { for deltas in strips { let read = sample(bars, projects, totals, deltas); assert_eq!( pane_serve(&USER_ANALYTICS, &read), Webview::new().fragment(&pane(&read)), "analytics, {bars} bars, {projects} projects, \ {totals} totals, {} cards", deltas.len(), ); } } } } } /// The git listing fills to what the renderer builds, at every page shape. /// /// The first residual holding a **described pager** (quasicoherent /// `cbb63155`). A pager used to be a `Rest` the screen supplied whole, /// which has no sentinel, so a paged screen could not reach the seam at /// all. Said as a description it is a `Rest` settled by its own body, one /// guard per direction, and everything it carries is a number or an /// address. /// /// Four page shapes, because a pager has four and each drops a different /// branch: the first page, a middle one, the last, and the single page that /// draws no pager. Crossed against an empty listing and a signed-out /// reader, which are the region's other two guards. #[test] fn the_git_listing_residual_fills_to_what_the_renderer_builds() { use crate::quasi::git_explore::{loaded, page_region, page_region_serve}; use quasi_axum::Serves as _; for (page, has_more) in [(1, true), (2, true), (3, false), (1, false)] { for count in [0, 3] { for signed_in in [true, false] { let held = loaded(count, page, has_more, signed_in); assert_eq!( page_region_serve(&GIT_EXPLORE, &held), Webview::new().fragment(&Node::Region(page_region(&held))), "page {page}, has_more {has_more}, {count} repos, signed in {signed_in}", ); } } } } /// The feed fills to what the renderer builds, at every page shape. /// /// The first residual holding **arms**, and both kinds of them /// (quasicoherent `cbb63155`). The numbered strip marks the page a reader /// is on by drawing a readout where every other page is a control, and the /// price cell is a badge for a free item and text for a priced one. Neither /// is markup that is there or is not, so neither is a branch: they are two /// markups at one position, which is what `Op::Arms` holds. /// /// Crossed over every page of a four-page set, both mixes of free and /// priced, and the empty feed that draws no table at all. #[test] fn the_feed_residual_fills_to_what_the_renderer_builds() { use crate::quasi::feeds::{Page, page_region, page_region_serve}; use quasi_axum::Serves as _; let items = crate::quasi::feeds::sample_items(); let range: Vec = (1..=4).collect(); for current in 1..=4 { for held in [items.as_slice(), &[]] { let page = Page { items: held, total_items: 80, current_page: current, total_pages: 4, pagination_range: &range, showing_start: 1, showing_end: 20, }; assert_eq!( page_region_serve(&FEED, &page), Webview::new().fragment(&Node::Region(page_region(&page))), "page {current} of 4, {} items", held.len(), ); } } // And a single page, which draws no pager at all. let page = Page { items: &items, total_items: 2, current_page: 1, total_pages: 1, pagination_range: &[], showing_start: 1, showing_end: 2, }; assert_eq!( page_region_serve(&FEED, &page), Webview::new().fragment(&Node::Region(page_region(&page))), "one page", ); } /// The payout card fills to what the renderer builds. /// /// The first residual holding a **figure strip**, which is the other half /// of what staging a structured slot buys: a `Figure` has no sentinel, so /// the strip's markup is compiled and each number is a hole. Filled with a /// balance and without one, and with payouts enabled and not, because the /// card's three guards read those two facts between them. #[test] fn the_payout_residual_fills_to_what_the_renderer_builds() { use crate::quasi::payout_summary::{card, card_serve, sample}; use quasi_axum::Serves as _; let balance = sample(); for held in [Some(&balance), None] { for payouts_enabled in [true, false] { assert_eq!( card_serve(&PAYOUT_SUMMARY, held, payouts_enabled), Webview::new().fragment(&card(held, payouts_enabled)), "balance={} payouts_enabled={payouts_enabled}", held.is_some(), ); } } } /// The creators page fills to what the renderer builds. /// /// Three readers and two price sets. The standing decides which call to /// action is placed, which is the branch, and the prices fill the tier /// table's eight figures. Prices nothing else in the tree uses, for /// `/use-cases`' reason: filling with the defaults would pass against a /// residual that had baked one request's numbers into its literals. #[test] fn the_creators_residual_fills_to_what_the_renderer_builds() { use crate::quasi::creators::{Standing, page_region, page_region_serve}; use quasi_axum::Serves as _; for standing in [Standing::Visitor, Standing::Reader, Standing::Creator] { for prices in [stated_prices(), odd_prices()] { for total in [0, 7] { assert_eq!( page_region_serve(&CREATORS, &standing, total, &prices), Webview::new() .fragment(&Node::Region(page_region(&standing, total, &prices))), "total={total}", ); } } } } /// The four tier rows are compiled, not rebuilt per request. /// /// What says the copy move landed. The rows come out of /// `content/creators.toml` and are unrolled at macro time, so each tier's /// name and what it is for are literals here and only its two figures are /// holes. A loop appearing would mean they went back to being read through /// a path the macro cannot evaluate. #[test] fn the_creators_residual_unrolls_its_tier_table() { use quasi_router::stage::Op; let compiled = format!("{:?}", CREATORS.ops()); for tier in ["Basic", "Small Files", "Big Files", "Everything"] { assert!(compiled.contains(tier), "{tier} is not in the residual"); } fn loops(ops: &[Op]) -> usize { ops.iter() .map(|op| match op { Op::Loop(body) => 1 + loops(body), Op::Branch(body) => loops(body), _ => 0, }) .sum() } assert_eq!(loops(CREATORS.ops()), 0, "the tiers are unrolled"); } /// Every described screen is on the seam or is named as not being. /// /// The gap, stated in code rather than only in a task. Thirteen of the /// seventeen addresses `quasi::mod` mounts serve from a generated template; /// the four that do not are here with the reason, and each has a task /// against quasicoherent holding the design. /// /// A screen that reaches the seam and is not taken off this list fails /// here, and so does one that leaves it. That is the point: a count nobody /// updates is a count nobody believes. #[test] fn every_described_screen_is_on_the_seam_or_says_why_not() { use crate::quasi::{DOCUMENT_PATHS, PATHS, PUBLIC_DOCUMENT_PATHS}; /// The addresses still served by building a `Node` per request. /// /// **Empty, and that is the point.** Every described screen serves from /// a generated template. The last one off it was /// `/dashboard/tabs/analytics`, whose revenue chart was a ceded region /// the renderer looked up while it rendered; ruled 2026-09-08, the /// chart was described rather than compiled around, and the screen /// joined. quasicoherent `7d6ad166`. /// /// The list stays rather than going, because what it is for is a screen /// that CANNOT join saying so out loud. An empty one is the claim that /// none is in that position today. const OFF_THE_SEAM: &[&str] = &[]; let described = PATHS.len() + DOCUMENT_PATHS.len() + PUBLIC_DOCUMENT_PATHS.len(); assert_eq!( described, roster().len() + OFF_THE_SEAM.len(), "{} described screens, {} on the seam, {} named as off it", described, roster().len(), OFF_THE_SEAM.len(), ); // Each named address is one this server actually mounts, so a screen // renamed out from under the list fails rather than excusing nothing. for path in OFF_THE_SEAM { assert!( PATHS.contains(path) || DOCUMENT_PATHS.contains(path) || PUBLIC_DOCUMENT_PATHS.contains(path), "{path} is named as off the seam and is not a described address", ); } } /// Every screen the roster names is checked above. /// /// The gap this closes is the one a table opens: a screen added to /// [`roster`] and not checked anywhere is generated, compiled, served and /// never compared against the renderer, and nothing else here would say so. /// /// `HOLED` is the count of screens checked by a filler of their own rather /// than by [`one_literal_screens`], and it is written out rather than /// derived so that adding a screen to the roster and forgetting its check /// fails here. A screen that has holes cannot join the settled table, so /// the two counts have to be kept by hand or not at all. #[test] fn every_screen_on_the_seam_is_checked() { /// Screens with their own filling test: `/use-cases`, `/fan-plus`, /// `/c/{username}/{slug}`, `/dashboard/export`, `/git/{owner}`, and the /// two forum panes, the two contact panes, the payout card, /// `/creators`, `/dashboard/tabs/ssh-keys`, `/git`, `/feed` and /// `/dashboard/tabs/analytics`. const HOLED: usize = 15; assert_eq!( roster().len(), one_literal_screens().len() + HOLED, "a screen on the seam is not checked: give it a row in \ `one_literal_screens`, or a filling test and a bump to HOLED", ); } }