Skip to main content

max / makenotwork

45.8 KB · 1096 lines History Blame Raw
1 //! Every staged screen's residual, derived at build time and compiled.
2 //!
3 //! <!-- wiki: quasi-overview -->
4 //!
5 //! A residual is a screen's markup with the request taken out of it: literals
6 //! where the renderer decided, and a hole, a branch or a loop where a request
7 //! does. Serving a screen from one is walking it and writing values into the
8 //! gaps, so no `Node` is built and nothing is rendered.
9 //!
10 //! # Why this is generated rather than derived at startup
11 //!
12 //! A residual is produced by rendering, so a build script cannot make one: it
13 //! would have to link the crate it is building. The two honest answers were to
14 //! derive at boot into a `LazyLock`, or to generate. Generating won on three
15 //! counts and Max ruled it (quasicoherent `793d99dd`, 2026-09-07):
16 //!
17 //! - **The artifact is readable and diffable.** A screen's markup is in the
18 //! repo, in `residuals/compiled.rs`, where a change to it shows up in a diff
19 //! rather than in a running process.
20 //! - **Nothing happens at boot, and nothing can fail there.** `derive` panics
21 //! loudly when a screen's branches do not nest, deliberately. At startup that
22 //! is a boot failure; here it is a failed test.
23 //! - **What ships is compiled.** The generated file is a `static` built from
24 //! literals, so the strings are in read-only data and the tree that holds them
25 //! is built by rustc. A `LazyLock` would still allocate on first use.
26 //!
27 //! # The staleness that is easy to miss
28 //!
29 //! A residual goes stale for two reasons and only one of them is visible. A
30 //! screen changing shows up in the diff beside it. **quasi-webview changing
31 //! does not**: the residual is that renderer's own output, and under the tree's
32 //! `[patch]` block an edit in another repo silently leaves every committed
33 //! residual one version behind, with no file here modified.
34 //!
35 //! So the check is a test rather than a pre-commit hook. [`generate`] is run by
36 //! `cargo test` against the renderer actually linked, and its result is compared
37 //! with what is committed. Regenerate with:
38 //!
39 //! ```sh
40 //! cargo run --bin export-residuals
41 //! ```
42
43 mod compiled;
44
45 pub use compiled::*;
46
47 use quasi_router::Node;
48 use quasi_router::stage::{Plan, Residual};
49 use quasi_webview::Webview;
50
51 /// One screen that serves from a residual: the `static` it gets, and the staged
52 /// twin a derivation calls.
53 type Staged = (&'static str, fn(&Plan) -> Node);
54
55 /// Every screen on the seam.
56 ///
57 /// A list rather than a registry the screens add themselves to. A screen
58 /// reaches the serving path by being named here, which is one place to read to
59 /// know what is on the seam and what is still building a tree, and the
60 /// alternative was a macro nobody can grep.
61 fn roster() -> Vec<Staged> {
62 vec![
63 ("POLICY", |plan| {
64 Node::Region(super::policy::page_region_staged(plan))
65 }),
66 ("TEAM", |plan| {
67 Node::Region(super::team::page_region_staged(plan))
68 }),
69 ("USE_CASES", |plan| {
70 Node::Region(super::use_cases::page_region_staged(plan))
71 }),
72 ("FAN_PLUS", |plan| {
73 Node::Region(super::fan_plus::page_region_staged(plan))
74 }),
75 ("COLLECTIONS", |plan| {
76 Node::Region(super::collections::page_region_staged(plan))
77 }),
78 ("EXPORT_PORTAL", |plan| {
79 Node::Region(super::export_portal::page_region_staged(plan))
80 }),
81 ("GIT_REPOS", |plan| {
82 Node::Region(super::git_repos::page_region_staged(plan))
83 }),
84 // One module, two screens: the library tab and the settings section are
85 // the same table under different chrome, so each gets its own residual.
86 ("FORUMS_LIBRARY", |plan| {
87 super::forum_memberships::library_pane_staged(plan)
88 }),
89 ("FORUMS_SETTINGS", |plan| {
90 super::forum_memberships::settings_pane_staged(plan)
91 }),
92 ("BUYER_CONTACTS", |plan| {
93 super::buyer_contacts::pane_staged(plan)
94 }),
95 ("LIBRARY_CONTACTS", |plan| {
96 super::library_contacts::pane_staged(plan)
97 }),
98 ("PAYOUT_SUMMARY", |plan| {
99 super::payout_summary::card_staged(plan)
100 }),
101 ("CREATORS", |plan| {
102 Node::Region(super::creators::page_region_staged(plan))
103 }),
104 ("SSH_KEYS", |plan| super::ssh_keys::pane_staged(plan)),
105 ("GIT_EXPLORE", |plan| {
106 Node::Region(super::git_explore::page_region_staged(plan))
107 }),
108 ("FEED", |plan| {
109 Node::Region(super::feeds::page_region_staged(plan))
110 }),
111 ("USER_ANALYTICS", |plan| {
112 super::user_analytics::pane_staged(plan)
113 }),
114 ]
115 }
116
117 /// A settled screen's markup, borrowed rather than built.
118 ///
119 /// The `body` half of [`super::served_document_mount`] for a screen that reads
120 /// nothing. A `Cow::Borrowed` of the compiled literal: no allocation, no walk,
121 /// no `Node`, and the same `&'static str` for every reader on every request.
122 ///
123 /// # Panics
124 ///
125 /// When the residual has a hole, a branch or a loop in it, which means the
126 /// screen started reading the request and wants the filler instead. It cannot
127 /// happen behind a mount that compiles, because
128 /// `tests::a_settled_screen_is_one_literal` fails first.
129 #[must_use]
130 pub fn settled(residual: &'static Residual) -> std::borrow::Cow<'static, str> {
131 std::borrow::Cow::Borrowed(
132 residual
133 .settled()
134 .expect("a settled screen's residual is one literal"),
135 )
136 }
137
138 /// The residual of one staged screen, derived by rendering it now.
139 ///
140 /// The reference the committed file is checked against, and what the generator
141 /// writes. Both call this, so a generated residual and a freshly derived one
142 /// cannot be produced two different ways.
143 #[must_use]
144 pub fn derive(shape: fn(&Plan) -> Node) -> Residual {
145 quasi_webview::stage::derive(&Webview::new(), shape)
146 }
147
148 /// The whole generated module, as Rust source.
149 #[must_use]
150 pub fn generate() -> String {
151 let mut out = String::from(
152 "//! Generated by `cargo run --bin export-residuals`. Do not edit.\n\
153 //!\n\
154 //! Every staged screen's markup with the request taken out of it, as a\n\
155 //! `static` the compiler builds. See the module above this one for why\n\
156 //! this is generated rather than derived at startup, and for the test\n\
157 //! that fails when it is stale.\n\n\
158 // Not formatted, because the staleness test compares this file with what\n\
159 // `generate` produces, byte for byte. `cargo fmt` rewrapping a `static`\n\
160 // here would fail that test against markup nobody had changed, and the\n\
161 // obvious repair -- regenerate, then format -- puts it straight back.\n\
162 // Nothing reads this file for pleasure; the markup in it is one line per\n\
163 // screen whatever the layout.\n\
164 #![cfg_attr(rustfmt, rustfmt::skip)]\n\n",
165 );
166 for (name, shape) in roster() {
167 out.push_str(&derive(shape).as_rust(name));
168 out.push('\n');
169 }
170 out
171 }
172
173 #[cfg(test)]
174 mod tests {
175 use super::*;
176
177 /// The committed file says what this renderer says today.
178 ///
179 /// The whole staleness check, and it covers the case a diff cannot: a
180 /// quasi-webview change in another repo alters what `derive` produces
181 /// without touching a byte here.
182 #[test]
183 fn every_committed_residual_matches_a_fresh_one() {
184 let committed = include_str!("residuals/compiled.rs");
185
186 assert_eq!(
187 committed,
188 generate(),
189 "the committed residuals are stale: run `cargo run --bin export-residuals`",
190 );
191 }
192
193 /// One screen on the seam, and the two ways to produce its markup.
194 ///
195 /// A table for [`roster`]'s reason: the checks below hold of every settled
196 /// screen and not of `/policy` in particular, so a screen joins them by
197 /// adding a row rather than by somebody copying two tests and renaming the
198 /// halves they remembered to.
199 struct Settled {
200 /// What the address is, for a failure to name.
201 path: &'static str,
202 /// The compiled residual.
203 residual: &'static Residual,
204 /// The whole document, which is what the region has to appear inside.
205 screen: fn() -> quasi_router::Screen,
206 /// The region on its own, rendered the ordinary way.
207 region: fn() -> Node,
208 }
209
210 /// Every screen whose residual settles to one literal.
211 ///
212 /// Named for what it returns rather than `settled`, which is the helper in
213 /// the module above and would be shadowed by this under `use super::*`.
214 ///
215 /// Not every entry in [`roster`] belongs here: a screen that reads a request
216 /// has holes, and `settled` answers `None` for it. Those are checked by
217 /// filling instead.
218 fn one_literal_screens() -> Vec<Settled> {
219 vec![
220 Settled {
221 path: crate::quasi::policy::PATH,
222 residual: &POLICY,
223 screen: crate::quasi::policy::page_screen,
224 region: || Node::Region(crate::quasi::policy::page_region()),
225 },
226 Settled {
227 path: crate::quasi::team::PATH,
228 residual: &TEAM,
229 screen: crate::quasi::team::page_screen,
230 region: || Node::Region(crate::quasi::team::page_region()),
231 },
232 ]
233 }
234
235 /// A settled screen's residual is one `Op::Lit` and nothing else.
236 ///
237 /// Phase 2's sharp test (`60047dc0`), which moved here when it turned out
238 /// to be a pipeline property rather than a vocabulary one. These screens
239 /// hold no operator and reach no value a request brings: their copy is in
240 /// `content/` and read at macro time, and every shape they include is
241 /// `#[constant]`, so each is evaluated once while the residual is derived
242 /// rather than once per request.
243 ///
244 /// A hole, a branch or a loop appearing here means something about a page
245 /// started depending on the request, which is a real change and worth
246 /// failing on.
247 #[test]
248 fn a_settled_screen_is_one_literal() {
249 for screen in one_literal_screens() {
250 let ops = screen.residual.ops();
251
252 assert_eq!(ops.len(), 1, "{}: {ops:?}", screen.path);
253 assert!(
254 matches!(ops[0], quasi_router::stage::Op::Lit(_)),
255 "{}: {ops:?}",
256 screen.path,
257 );
258 }
259 }
260
261 /// The residual is the document's own bytes, not a lookalike.
262 ///
263 /// The property the serving path rests on. A residual is derived from a
264 /// *fragment* render of the region, and a document renders its regions
265 /// through a different entry point; if the two disagreed by so much as an
266 /// attribute, serving from the residual would quietly ship different markup
267 /// than the page has always had. So the fragment has to appear in the
268 /// document verbatim, and this is what says it does.
269 #[test]
270 fn what_a_residual_holds_appears_in_its_document_verbatim() {
271 use quasi_axum::Serves as _;
272
273 for screen in one_literal_screens() {
274 let document = Webview::new().screen(&(screen.screen)());
275 let body = screen
276 .residual
277 .settled()
278 .expect("a settled screen's residual is one literal");
279
280 assert!(document.contains(body), "{}: {document}", screen.path);
281 }
282 }
283
284 /// Filling the residual gives back what the renderer gives.
285 ///
286 /// The acceptance test the task asked for, and it is an equality rather
287 /// than a diff: what the seam must not lose is the markup itself, so the
288 /// check is that the two paths agree byte for byte on a screen that has
289 /// nothing varying in it.
290 #[test]
291 fn a_residual_serves_what_the_renderer_serves() {
292 use quasi_axum::Serves as _;
293
294 for screen in one_literal_screens() {
295 let rendered = Webview::new().fragment(&(screen.region)());
296
297 assert_eq!(
298 screen
299 .residual
300 .settled()
301 .expect("a settled screen's residual is one literal"),
302 rendered,
303 "{}",
304 screen.path,
305 );
306 }
307 }
308
309 /// A holed screen's residual fills to what the renderer builds.
310 ///
311 /// `/use-cases` is the first screen on the seam that does not fold to a
312 /// literal, and this is the check the settled ones cannot have: it is the
313 /// filler that is being tested, not a borrow. Nine holes, one per card's
314 /// tier line, and the equality is byte for byte against the tree the screen
315 /// has always built.
316 ///
317 /// Two price sets rather than one, and that is the point. Filling with the
318 /// defaults would pass against a residual that had baked one request's
319 /// prices into its literals, which is the exact failure the seam could
320 /// have. Prices nothing else in the tree uses cannot be baked.
321 #[test]
322 fn the_use_cases_residual_fills_to_what_the_renderer_builds() {
323 use quasi_axum::Serves as _;
324
325 for prices in [crate::tier_prices::TierPrices::default(), odd_prices()] {
326 let filled = crate::quasi::use_cases::page_region_serve(&USE_CASES, &prices);
327 let rendered = Webview::new()
328 .fragment(&Node::Region(crate::quasi::use_cases::page_region(&prices)));
329
330 assert_eq!(filled, rendered);
331 }
332 }
333
334 /// The nine holes are holes, and the rest of the page is not.
335 ///
336 /// What says the split landed where the module header claims. A tenth hole
337 /// means something else on the page started reading the request; a loop or
338 /// a branch means the copy stopped being read at macro time, which is the
339 /// regression `98fbee62` exists to prevent and which no rendering test
340 /// would notice.
341 #[test]
342 fn the_use_cases_residual_is_nine_holes_and_literals() {
343 use quasi_router::stage::Op;
344
345 let ops = USE_CASES.ops();
346 let holes = ops
347 .iter()
348 .filter(|op| matches!(op, Op::Hole { .. }))
349 .count();
350
351 assert_eq!(holes, 9, "one per card's tier line: {ops:?}");
352 assert!(
353 ops.iter()
354 .all(|op| matches!(op, Op::Lit(_) | Op::Hole { .. })),
355 "a branch or a loop reached the residual: {ops:?}",
356 );
357 }
358
359 /// Prices no default and no assumptions file would produce.
360 ///
361 /// The storage envelopes are set as well as the fees, and `/creators` is
362 /// why. A cell holding one piece of text says so on its container with
363 /// `cell-value`, and an empty string is not one piece of text but no
364 /// content at all -- so an empty cell and a filled one are two shapes, and
365 /// a residual holds one. `TierPrices::default()` leaves every envelope
366 /// empty; nothing serving this page does, because they are read from the
367 /// assumptions file at boot and the validator refuses a missing one.
368 ///
369 /// The rule that generalises, and it is the one the converted screens
370 /// already follow: **a hole that can be empty is guarded**, because empty
371 /// is a different shape rather than a shorter value. `/c/{username}/{slug}`
372 /// says `unless loaded.description().is_empty()` for exactly this reason.
373 fn odd_prices() -> crate::tier_prices::TierPrices {
374 crate::tier_prices::TierPrices {
375 basic_std: 4321,
376 small_files_std: 5678,
377 big_files_std: 8765,
378 everything_std: 9876,
379 basic_total: "3GB".to_owned(),
380 small_files_total: "40GB".to_owned(),
381 big_files_total: "700GB".to_owned(),
382 everything_total: "9TB".to_owned(),
383 ..Default::default()
384 }
385 }
386
387 /// The envelopes a served page actually carries.
388 ///
389 /// `TierPrices::default()` is a test artefact: every envelope is the empty
390 /// string, which no request produces. See [`odd_prices`].
391 fn stated_prices() -> crate::tier_prices::TierPrices {
392 crate::tier_prices::TierPrices {
393 basic_total: "1GB".to_owned(),
394 small_files_total: "20GB".to_owned(),
395 big_files_total: "500GB".to_owned(),
396 everything_total: "5TB".to_owned(),
397 ..Default::default()
398 }
399 }
400
401 /// A branching screen's residual fills to what the renderer builds, on
402 /// every branch.
403 ///
404 /// `/fan-plus` is the first residual on the seam that carries branches: it
405 /// asks four questions about the reader and holds the markup of every
406 /// answer, so one filled render proves nothing. What is checked is every
407 /// combination of the three standings and both banner states, each against
408 /// the tree the screen has always built.
409 ///
410 /// This is the test that would have caught the span overlap the derivation
411 /// panicked on (quasi-webview `stage::placed`): two guarded siblings whose
412 /// markup shares a boundary can be located on top of each other, and a
413 /// residual built on that serves one branch's markup inside another's.
414 #[test]
415 fn the_fan_plus_residual_fills_to_what_the_renderer_builds_on_every_branch() {
416 use crate::quasi::fan_plus::{Standing, page_region, page_region_serve};
417 use quasi_axum::Serves as _;
418
419 let standings = [
420 Standing::Visitor,
421 Standing::Unsubscribed,
422 Standing::Member { period_end: None },
423 Standing::Member {
424 period_end: Some("March 3, 2027".to_owned()),
425 },
426 ];
427
428 for standing in &standings {
429 for just_subscribed in [false, true] {
430 let filled = page_region_serve(&FAN_PLUS, standing, just_subscribed);
431 let rendered =
432 Webview::new().fragment(&Node::Region(page_region(standing, just_subscribed)));
433
434 assert_eq!(filled, rendered, "just_subscribed={just_subscribed}");
435 }
436 }
437 }
438
439 /// The branches a reader never sees are still in the compiled markup.
440 ///
441 /// The property that makes the seam worth having on a screen like this: all
442 /// three readers get a compiled page, so nothing is rendered per request for
443 /// the sake of the two answers this reader did not give. A literal going
444 /// missing here means a branch stopped being derived, which the equality
445 /// above would still pass if both paths lost it together.
446 #[test]
447 fn the_fan_plus_residual_holds_every_reader_s_markup() {
448 let compiled = format!("{:?}", FAN_PLUS.ops());
449
450 for words in [
451 "Fan+ membership is active",
452 "Support the platform",
453 "Join Fan+",
454 "Create an account",
455 "now a Fan+ member",
456 ] {
457 assert!(compiled.contains(words), "{words} is not in the residual");
458 }
459 }
460
461 /// A looping screen's residual fills to what the renderer builds.
462 ///
463 /// `/c/{username}/{slug}` is the first residual on the seam that carries a
464 /// **loop**: its items table is one compiled row body walked once per item,
465 /// rather than a row's markup rendered per item. Filled at three lengths so
466 /// a residual that had baked one request's row count into its literals
467 /// fails: nought exercises the empty state, one the body once, and three
468 /// the body repeated.
469 ///
470 /// Both visibilities as well, because the private banner is a branch and an
471 /// equality on the public page alone would pass against a residual that had
472 /// lost it.
473 #[test]
474 fn the_collections_residual_fills_to_what_the_renderer_builds() {
475 use quasi_axum::Serves as _;
476
477 for items in [0, 1, 3] {
478 for is_public in [true, false] {
479 let loaded = crate::quasi::collections::sample(items, is_public);
480 let filled = crate::quasi::collections::page_region_serve(&COLLECTIONS, &loaded);
481 let rendered = Webview::new().fragment(&Node::Region(
482 crate::quasi::collections::page_region(&loaded),
483 ));
484
485 assert_eq!(filled, rendered, "items={items} is_public={is_public}");
486 }
487 }
488 }
489
490 /// The row body is compiled once, not once per item the derivation saw.
491 ///
492 /// What says the loop is a loop. A residual derived from a one-row render
493 /// and stored flat would still fill correctly at one item and lose rows at
494 /// three, which the equality above catches; this catches the other half,
495 /// that the table's markup is in the residual at all rather than being
496 /// rebuilt per request.
497 #[test]
498 fn the_collections_residual_holds_its_row_body_once() {
499 use quasi_router::stage::Op;
500
501 fn loops(ops: &[Op]) -> usize {
502 ops.iter()
503 .map(|op| match op {
504 Op::Loop(body) => 1 + loops(body),
505 Op::Branch(body) => loops(body),
506 _ => 0,
507 })
508 .sum()
509 }
510
511 assert_eq!(loops(COLLECTIONS.ops()), 1, "one loop, over the items");
512 assert!(
513 format!("{:?}", COLLECTIONS.ops()).contains("Creator"),
514 "the table's headings are compiled, not built per request",
515 );
516 }
517
518 /// The export portal's residual fills to what the renderer builds.
519 ///
520 /// The first gated document on the seam, and the one whose copy moved out
521 /// of a `const` in the same pass: the five direct cards are read at macro
522 /// time and fold into literals, and what is left varying is whether this
523 /// reader has files at all. Both answers, and two size lines under the
524 /// yes, since the size is a hole and filling with one value would pass
525 /// against a residual that had baked it in.
526 #[test]
527 fn the_export_portal_residual_fills_to_what_the_renderer_builds() {
528 use crate::quasi::export_portal::Page;
529 use quasi_axum::Serves as _;
530
531 let pages = [
532 Page {
533 has_content: false,
534 content_size: "No files".to_owned(),
535 },
536 Page {
537 has_content: true,
538 content_size: "1.4 GB + audio/cover files".to_owned(),
539 },
540 Page {
541 has_content: true,
542 content_size: "17 KB".to_owned(),
543 },
544 ];
545
546 for page in &pages {
547 let filled = crate::quasi::export_portal::page_region_serve(&EXPORT_PORTAL, page);
548 let rendered = Webview::new().fragment(&Node::Region(
549 crate::quasi::export_portal::page_region(page),
550 ));
551
552 assert_eq!(filled, rendered, "has_content={}", page.has_content);
553 }
554 }
555
556 /// The five direct exports are compiled, not rebuilt per request.
557 ///
558 /// What says the copy move landed. Each card's route is in the residual's
559 /// literals; a loop appearing here would mean the cards went back to being
560 /// read through a path the macro cannot evaluate.
561 #[test]
562 fn the_export_portal_residual_holds_its_five_cards() {
563 use quasi_router::stage::Op;
564
565 let compiled = format!("{:?}", EXPORT_PORTAL.ops());
566 for route in [
567 "/api/export/projects",
568 "/api/export/sales",
569 "/api/export/splits",
570 "/api/export/purchases",
571 "/api/export/followers",
572 ] {
573 assert!(compiled.contains(route), "{route} is not in the residual");
574 }
575
576 fn loops(ops: &[Op]) -> usize {
577 ops.iter()
578 .map(|op| match op {
579 Op::Loop(body) => 1 + loops(body),
580 Op::Branch(body) => loops(body),
581 _ => 0,
582 })
583 .sum()
584 }
585 assert_eq!(loops(EXPORT_PORTAL.ops()), 0, "the cards are unrolled");
586 }
587
588 /// The repository listing's residual fills to what the renderer builds.
589 ///
590 /// `/git/{owner}` is the first residual holding a **token**: a repository's
591 /// visibility is a `Tag`, which has no sentinel of its own, so the tag is
592 /// built with one in it and the residual carries the tag's markup as a
593 /// literal around a hole (quasi-declare's structured slots).
594 ///
595 /// Four shapes, and the two axes are independent. Owner and visitor differ
596 /// by a whole column as well as by the badges, and empty and populated by
597 /// which of the two branches is placed at all.
598 #[test]
599 fn the_git_repos_residual_fills_to_what_the_renderer_builds() {
600 use quasi_axum::Serves as _;
601
602 for count in [0, 1, 3] {
603 for is_owner in [true, false] {
604 let loaded = crate::quasi::git_repos::sample(count, is_owner);
605 let filled = crate::quasi::git_repos::page_region_serve(&GIT_REPOS, &loaded);
606 let rendered = Webview::new()
607 .fragment(&Node::Region(crate::quasi::git_repos::page_region(&loaded)));
608
609 assert_eq!(filled, rendered, "count={count} is_owner={is_owner}");
610 }
611 }
612 }
613
614 /// The badge's markup is compiled and only its word is a hole.
615 ///
616 /// What says the structured slot landed. A `Tag` staged as a value fails to
617 /// compile; a `Tag` staged through leaves `class="tag"` in the residual's
618 /// literals with the visibility word written in per row. Finding the markup
619 /// here is finding that the second thing happened.
620 #[test]
621 fn the_git_repos_residual_compiles_its_badges() {
622 let compiled = format!("{:?}", GIT_REPOS.ops());
623
624 assert!(
625 compiled.contains("badge"),
626 "the badge markup is not compiled",
627 );
628 assert!(
629 !compiled.contains("private"),
630 "a visibility word was baked into a literal",
631 );
632 }
633
634 /// Both forum panes fill to what the renderer builds.
635 ///
636 /// The first panel screens on the seam, and the first module with two of
637 /// them: the library tab and the settings section draw the same table under
638 /// different chrome, so each has a residual and both are checked here.
639 ///
640 /// Empty and populated, and with the upstream configured and not. The base
641 /// address is a hole inside the sentence's markdown -- the link's own
642 /// destination -- so an empty one is the shape that would show a residual
643 /// with the address baked into a literal.
644 #[test]
645 fn both_forum_residuals_fill_to_what_the_renderer_builds() {
646 use crate::quasi::forum_memberships::{
647 library_pane, library_pane_serve, sample, settings_pane, settings_pane_serve,
648 };
649 use quasi_axum::Serves as _;
650
651 let none: Vec<_> = Vec::new();
652 let some = vec![
653 sample("rust", "moderator"),
654 sample("audio", "member"),
655 sample("film", "member"),
656 ];
657
658 for memberships in [&none, &some] {
659 for base in ["https://mt.example.com", ""] {
660 assert_eq!(
661 library_pane_serve(&FORUMS_LIBRARY, memberships, base),
662 Webview::new().fragment(&library_pane(memberships, base)),
663 "library: {} memberships, base {base:?}",
664 memberships.len(),
665 );
666 assert_eq!(
667 settings_pane_serve(&FORUMS_SETTINGS, memberships, base),
668 Webview::new().fragment(&settings_pane(memberships, base)),
669 "settings: {} memberships, base {base:?}",
670 memberships.len(),
671 );
672 }
673 }
674 }
675
676 /// The two contact panes fill to what the renderer builds.
677 ///
678 /// Both are tables behind guards, and the library's is two of them: buyers
679 /// and shared-with, each with its own heading and its own empty state, and
680 /// a third state where neither is placed and one line says so. Every
681 /// combination is filled, because a residual that had lost one table's
682 /// branch would still pass on the shapes where that table is absent.
683 #[test]
684 fn the_contact_residuals_fill_to_what_the_renderer_builds() {
685 use quasi_axum::Serves as _;
686
687 for count in [0, 1, 3] {
688 let buyers: Vec<_> = (0..count)
689 .map(|n| crate::quasi::buyer_contacts::sample(&format!("buyer{n}")))
690 .collect();
691 assert_eq!(
692 crate::quasi::buyer_contacts::pane_serve(&BUYER_CONTACTS, &buyers),
693 Webview::new().fragment(&crate::quasi::buyer_contacts::pane(&buyers)),
694 "buyer contacts, {count} buyers",
695 );
696 }
697
698 for buyers in [0, 2] {
699 for shared in [0, 2] {
700 let held: Vec<_> = (0..buyers)
701 .map(|n| crate::quasi::library_contacts::sample_buyer(&format!("buyer{n}")))
702 .collect();
703 let with: Vec<_> = (0..shared)
704 .map(|n| {
705 crate::quasi::library_contacts::sample_creator(
706 &format!("{n}"),
707 &format!("creator{n}"),
708 &format!("Creator {n}"),
709 )
710 })
711 .collect();
712
713 assert_eq!(
714 crate::quasi::library_contacts::pane_serve(&LIBRARY_CONTACTS, &held, &with),
715 Webview::new().fragment(&crate::quasi::library_contacts::pane(&held, &with)),
716 "library contacts, {buyers} buyers and {shared} shared",
717 );
718 }
719 }
720 }
721
722 /// The SSH keys pane fills to what the renderer builds.
723 ///
724 /// The first residual holding a **select whose options mark themselves**,
725 /// which is what quasicoherent `c32bb877` added and what this screen was
726 /// blocked on. A picker used to say which option was marked once, at the
727 /// field, as a value makeover-webview compared against each option -- and a
728 /// residual holds one compiled body per loop, so "exactly one row differs"
729 /// was not something the body could carry. Filled here with each theme
730 /// marked in turn and with none, because a residual that had baked one
731 /// row's mark would still pass on the shape where that row is the marked
732 /// one.
733 ///
734 /// Two tables behind guards as well, each with its own empty state, so the
735 /// counts are crossed the way the contact panes' are.
736 #[test]
737 fn the_ssh_keys_residual_fills_to_what_the_renderer_builds() {
738 use crate::quasi::ssh_keys::{pane, pane_serve, sample_key, sample_token};
739 use quasi_axum::Serves as _;
740
741 let installed = crate::theming::console_theme_options(None);
742 assert!(
743 installed.len() > 1,
744 "the picker needs more than one option to be worth filling"
745 );
746
747 for key_count in [0, 2] {
748 for token_count in [0, 2] {
749 let keys: Vec<_> = (0..key_count)
750 .map(|n| sample_key(&format!("k{n}"), &format!("SHA256:{n}")))
751 .collect();
752 let tokens: Vec<_> = (0..token_count)
753 .map(|n| sample_token(&format!("t{n}"), &format!("token{n}")))
754 .collect();
755
756 // Every theme marked in turn, and then a list with none marked:
757 // an account whose stored theme is no longer installed.
758 let none_marked: Vec<_> = installed
759 .iter()
760 .map(|theme| crate::theming::ThemeOption {
761 id: theme.id.clone(),
762 name: theme.name.clone(),
763 selected: false,
764 })
765 .collect();
766 let cases = installed
767 .iter()
768 .map(|theme| crate::theming::console_theme_options(Some(&theme.id)))
769 .chain(std::iter::once(none_marked));
770
771 for themes in cases {
772 let marked = themes.iter().position(|theme| theme.selected);
773 assert_eq!(
774 pane_serve(&SSH_KEYS, "max", &keys, &tokens, &themes),
775 Webview::new().fragment(&pane("max", &keys, &tokens, &themes)),
776 "ssh keys, {key_count} keys, {token_count} tokens, theme {marked:?}",
777 );
778 }
779 }
780 }
781 }
782
783 /// The analytics tab fills to what the renderer builds, at every shape.
784 ///
785 /// The last screen to join the seam, and the one that needed a new member
786 /// to do it (quasicoherent `7d6ad166`). Its revenue chart was a ceded
787 /// region: the handler drew the markup and the renderer looked it up WHILE
788 /// it rendered, so a residual derived from a bare `Webview` held the empty
789 /// container and nothing at serve time could get inside it.
790 ///
791 /// Described, the chart is an axis and a run of bars, and what makes it
792 /// compilable is that no renderer divides. The axis is a hole beside the
793 /// loop and each magnitude is a hole inside it; a width worked out from the
794 /// two would have left no stand-in to find and baked one reader's chart
795 /// into the template. `quasi_router::stage::number_at` states the rule and
796 /// `quasi-bench`'s `charted` proves the member against it.
797 ///
798 /// Four things vary here and each drops a different branch:
799 ///
800 /// - **The chart**, present and absent, against its own empty state.
801 /// - **The stat cards**, which are three guarded figures -- no delta, a
802 /// toned rise, a toned fall -- so a fill that only saw one would pass on
803 /// a residual that had baked it.
804 /// - **The comparison**, whose heading and table share a guard on there
805 /// being more than one project.
806 /// - **The totals**, against their own empty state.
807 ///
808 /// The range chips are crossed too, and they are the reason `latched` had
809 /// to become guardable: which chip is held down is a fact a request brings,
810 /// a `bool` has no stand-in, and a loop body cannot carry "exactly one of
811 /// these differs" as a value. Said as a guard it is a clean deletion --
812 /// `class="chip latched"` against `class="chip"` -- so it derives as a
813 /// branch inside the loop. That is `Choice::chosen`'s answer on the other
814 /// control; `quasi_declare::symbolic::PLACED` is where it is allowed.
815 #[test]
816 fn the_analytics_residual_fills_to_what_the_renderer_builds() {
817 use crate::quasi::user_analytics::{pane, pane_serve, sample};
818 use quasi_axum::Serves as _;
819
820 // Every combination a card's delta can take, including the mixed strip
821 // that draws two of the three guarded figures at once.
822 let strips: &[&[Option<bool>]] = &[
823 &[],
824 &[None],
825 &[Some(true)],
826 &[Some(false)],
827 &[None, Some(true), Some(false)],
828 ];
829
830 for bars in [0, 1, 5] {
831 // One project is not a comparison, which is what that guard says,
832 // so the three counts are the shapes it has.
833 for projects in [0, 1, 3] {
834 for totals in [0, 2] {
835 for deltas in strips {
836 let read = sample(bars, projects, totals, deltas);
837 assert_eq!(
838 pane_serve(&USER_ANALYTICS, &read),
839 Webview::new().fragment(&pane(&read)),
840 "analytics, {bars} bars, {projects} projects, \
841 {totals} totals, {} cards",
842 deltas.len(),
843 );
844 }
845 }
846 }
847 }
848 }
849
850 /// The git listing fills to what the renderer builds, at every page shape.
851 ///
852 /// The first residual holding a **described pager** (quasicoherent
853 /// `cbb63155`). A pager used to be a `Rest` the screen supplied whole,
854 /// which has no sentinel, so a paged screen could not reach the seam at
855 /// all. Said as a description it is a `Rest` settled by its own body, one
856 /// guard per direction, and everything it carries is a number or an
857 /// address.
858 ///
859 /// Four page shapes, because a pager has four and each drops a different
860 /// branch: the first page, a middle one, the last, and the single page that
861 /// draws no pager. Crossed against an empty listing and a signed-out
862 /// reader, which are the region's other two guards.
863 #[test]
864 fn the_git_listing_residual_fills_to_what_the_renderer_builds() {
865 use crate::quasi::git_explore::{loaded, page_region, page_region_serve};
866 use quasi_axum::Serves as _;
867
868 for (page, has_more) in [(1, true), (2, true), (3, false), (1, false)] {
869 for count in [0, 3] {
870 for signed_in in [true, false] {
871 let held = loaded(count, page, has_more, signed_in);
872 assert_eq!(
873 page_region_serve(&GIT_EXPLORE, &held),
874 Webview::new().fragment(&Node::Region(page_region(&held))),
875 "page {page}, has_more {has_more}, {count} repos, signed in {signed_in}",
876 );
877 }
878 }
879 }
880 }
881
882 /// The feed fills to what the renderer builds, at every page shape.
883 ///
884 /// The first residual holding **arms**, and both kinds of them
885 /// (quasicoherent `cbb63155`). The numbered strip marks the page a reader
886 /// is on by drawing a readout where every other page is a control, and the
887 /// price cell is a badge for a free item and text for a priced one. Neither
888 /// is markup that is there or is not, so neither is a branch: they are two
889 /// markups at one position, which is what `Op::Arms` holds.
890 ///
891 /// Crossed over every page of a four-page set, both mixes of free and
892 /// priced, and the empty feed that draws no table at all.
893 #[test]
894 fn the_feed_residual_fills_to_what_the_renderer_builds() {
895 use crate::quasi::feeds::{Page, page_region, page_region_serve};
896 use quasi_axum::Serves as _;
897
898 let items = crate::quasi::feeds::sample_items();
899 let range: Vec<u32> = (1..=4).collect();
900
901 for current in 1..=4 {
902 for held in [items.as_slice(), &[]] {
903 let page = Page {
904 items: held,
905 total_items: 80,
906 current_page: current,
907 total_pages: 4,
908 pagination_range: &range,
909 showing_start: 1,
910 showing_end: 20,
911 };
912 assert_eq!(
913 page_region_serve(&FEED, &page),
914 Webview::new().fragment(&Node::Region(page_region(&page))),
915 "page {current} of 4, {} items",
916 held.len(),
917 );
918 }
919 }
920
921 // And a single page, which draws no pager at all.
922 let page = Page {
923 items: &items,
924 total_items: 2,
925 current_page: 1,
926 total_pages: 1,
927 pagination_range: &[],
928 showing_start: 1,
929 showing_end: 2,
930 };
931 assert_eq!(
932 page_region_serve(&FEED, &page),
933 Webview::new().fragment(&Node::Region(page_region(&page))),
934 "one page",
935 );
936 }
937
938 /// The payout card fills to what the renderer builds.
939 ///
940 /// The first residual holding a **figure strip**, which is the other half
941 /// of what staging a structured slot buys: a `Figure` has no sentinel, so
942 /// the strip's markup is compiled and each number is a hole. Filled with a
943 /// balance and without one, and with payouts enabled and not, because the
944 /// card's three guards read those two facts between them.
945 #[test]
946 fn the_payout_residual_fills_to_what_the_renderer_builds() {
947 use crate::quasi::payout_summary::{card, card_serve, sample};
948 use quasi_axum::Serves as _;
949
950 let balance = sample();
951 for held in [Some(&balance), None] {
952 for payouts_enabled in [true, false] {
953 assert_eq!(
954 card_serve(&PAYOUT_SUMMARY, held, payouts_enabled),
955 Webview::new().fragment(&card(held, payouts_enabled)),
956 "balance={} payouts_enabled={payouts_enabled}",
957 held.is_some(),
958 );
959 }
960 }
961 }
962
963 /// The creators page fills to what the renderer builds.
964 ///
965 /// Three readers and two price sets. The standing decides which call to
966 /// action is placed, which is the branch, and the prices fill the tier
967 /// table's eight figures. Prices nothing else in the tree uses, for
968 /// `/use-cases`' reason: filling with the defaults would pass against a
969 /// residual that had baked one request's numbers into its literals.
970 #[test]
971 fn the_creators_residual_fills_to_what_the_renderer_builds() {
972 use crate::quasi::creators::{Standing, page_region, page_region_serve};
973 use quasi_axum::Serves as _;
974
975 for standing in [Standing::Visitor, Standing::Reader, Standing::Creator] {
976 for prices in [stated_prices(), odd_prices()] {
977 for total in [0, 7] {
978 assert_eq!(
979 page_region_serve(&CREATORS, &standing, total, &prices),
980 Webview::new()
981 .fragment(&Node::Region(page_region(&standing, total, &prices))),
982 "total={total}",
983 );
984 }
985 }
986 }
987 }
988
989 /// The four tier rows are compiled, not rebuilt per request.
990 ///
991 /// What says the copy move landed. The rows come out of
992 /// `content/creators.toml` and are unrolled at macro time, so each tier's
993 /// name and what it is for are literals here and only its two figures are
994 /// holes. A loop appearing would mean they went back to being read through
995 /// a path the macro cannot evaluate.
996 #[test]
997 fn the_creators_residual_unrolls_its_tier_table() {
998 use quasi_router::stage::Op;
999
1000 let compiled = format!("{:?}", CREATORS.ops());
1001 for tier in ["Basic", "Small Files", "Big Files", "Everything"] {
1002 assert!(compiled.contains(tier), "{tier} is not in the residual");
1003 }
1004
1005 fn loops(ops: &[Op]) -> usize {
1006 ops.iter()
1007 .map(|op| match op {
1008 Op::Loop(body) => 1 + loops(body),
1009 Op::Branch(body) => loops(body),
1010 _ => 0,
1011 })
1012 .sum()
1013 }
1014 assert_eq!(loops(CREATORS.ops()), 0, "the tiers are unrolled");
1015 }
1016
1017 /// Every described screen is on the seam or is named as not being.
1018 ///
1019 /// The gap, stated in code rather than only in a task. Thirteen of the
1020 /// seventeen addresses `quasi::mod` mounts serve from a generated template;
1021 /// the four that do not are here with the reason, and each has a task
1022 /// against quasicoherent holding the design.
1023 ///
1024 /// A screen that reaches the seam and is not taken off this list fails
1025 /// here, and so does one that leaves it. That is the point: a count nobody
1026 /// updates is a count nobody believes.
1027 #[test]
1028 fn every_described_screen_is_on_the_seam_or_says_why_not() {
1029 use crate::quasi::{DOCUMENT_PATHS, PATHS, PUBLIC_DOCUMENT_PATHS};
1030
1031 /// The addresses still served by building a `Node` per request.
1032 ///
1033 /// **Empty, and that is the point.** Every described screen serves from
1034 /// a generated template. The last one off it was
1035 /// `/dashboard/tabs/analytics`, whose revenue chart was a ceded region
1036 /// the renderer looked up while it rendered; ruled 2026-09-08, the
1037 /// chart was described rather than compiled around, and the screen
1038 /// joined. quasicoherent `7d6ad166`.
1039 ///
1040 /// The list stays rather than going, because what it is for is a screen
1041 /// that CANNOT join saying so out loud. An empty one is the claim that
1042 /// none is in that position today.
1043 const OFF_THE_SEAM: &[&str] = &[];
1044
1045 let described = PATHS.len() + DOCUMENT_PATHS.len() + PUBLIC_DOCUMENT_PATHS.len();
1046
1047 assert_eq!(
1048 described,
1049 roster().len() + OFF_THE_SEAM.len(),
1050 "{} described screens, {} on the seam, {} named as off it",
1051 described,
1052 roster().len(),
1053 OFF_THE_SEAM.len(),
1054 );
1055
1056 // Each named address is one this server actually mounts, so a screen
1057 // renamed out from under the list fails rather than excusing nothing.
1058 for path in OFF_THE_SEAM {
1059 assert!(
1060 PATHS.contains(path)
1061 || DOCUMENT_PATHS.contains(path)
1062 || PUBLIC_DOCUMENT_PATHS.contains(path),
1063 "{path} is named as off the seam and is not a described address",
1064 );
1065 }
1066 }
1067
1068 /// Every screen the roster names is checked above.
1069 ///
1070 /// The gap this closes is the one a table opens: a screen added to
1071 /// [`roster`] and not checked anywhere is generated, compiled, served and
1072 /// never compared against the renderer, and nothing else here would say so.
1073 ///
1074 /// `HOLED` is the count of screens checked by a filler of their own rather
1075 /// than by [`one_literal_screens`], and it is written out rather than
1076 /// derived so that adding a screen to the roster and forgetting its check
1077 /// fails here. A screen that has holes cannot join the settled table, so
1078 /// the two counts have to be kept by hand or not at all.
1079 #[test]
1080 fn every_screen_on_the_seam_is_checked() {
1081 /// Screens with their own filling test: `/use-cases`, `/fan-plus`,
1082 /// `/c/{username}/{slug}`, `/dashboard/export`, `/git/{owner}`, and the
1083 /// two forum panes, the two contact panes, the payout card,
1084 /// `/creators`, `/dashboard/tabs/ssh-keys`, `/git`, `/feed` and
1085 /// `/dashboard/tabs/analytics`.
1086 const HOLED: usize = 15;
1087
1088 assert_eq!(
1089 roster().len(),
1090 one_literal_screens().len() + HOLED,
1091 "a screen on the seam is not checked: give it a row in \
1092 `one_literal_screens`, or a filling test and a bump to HOLED",
1093 );
1094 }
1095 }
1096