ishou-render 0.1.7

ishou — target-specific renderers for the pleme-io design token set
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
//! Vellum render targets — the stylix base16/base24 schemes + an SVG
//! palette preview, all sourced from the BORN `VellumPalette` tokens.
//!
//! Unlike the legacy `stylix` renderer (which maps the Nord `TokenSet`),
//! these targets construct `VellumPalette::vellum()` internally — the
//! Vellum tokens are not part of the Nord `TokenSet`, they are their
//! own BORN source. The base16/base24 YAML is emitted through
//! `serde_yaml` over an `IndexMap` — TYPED EMISSION, no
//! string-concatenated YAML. The SVG preview is a brand-asset target
//! (one chip per token, in band order).
//!
//! Output (per base16 spec — <https://github.com/chriskempson/base16>):
//!
//! ```yaml
//! system: base16
//! name: Vellum
//! author: pleme-io (ishou)
//! variant: dark
//! slug: vellum
//! palette:
//!   base00: 16140e
//!//! ```
//!
//! Hex values are **lowercase, unprefixed** — stylix passes them through
//! to GTK which expects six-char lowercase hex (no `#`).

use indexmap::IndexMap;
use ishou_tokens::{Rgb, VellumPalette};
use serde::Serialize;

/// Lowercase, unprefixed six-char hex — the stylix/base16 wire format.
fn slot_hex(rgb: Rgb) -> String {
    format!("{:02x}{:02x}{:02x}", rgb.r, rgb.g, rgb.b)
}

/// The base16/base24 scheme object serde_yaml serializes. `palette` is
/// an `IndexMap` so slot order is the authored slot order, not hash
/// order.
#[derive(Serialize)]
struct Scheme {
    system: &'static str,
    name: &'static str,
    author: &'static str,
    variant: &'static str,
    slug: &'static str,
    palette: IndexMap<String, String>,
}

fn scheme(system: &'static str, palette: IndexMap<String, String>) -> Scheme {
    Scheme {
        system,
        name: "Vellum",
        author: "pleme-io (ishou)",
        variant: "dark",
        slug: "vellum",
        palette,
    }
}

const HEADER: &str = "# Generated by ishou-render::vellum — DO NOT EDIT\n\
     # Source of truth: pleme-io/ishou/crates/ishou-tokens/src/vellum.rs\n\
     # Vellum — the fleet theme (warm aged-paper Nord-matte)\n";

/// Render the Vellum **base16** stylix scheme YAML.
///
/// Pure — `VellumPalette::vellum()` is deterministic, so this is too.
/// serde_yaml owns the escaping; the slot order is the canonical order.
#[must_use]
pub fn render_base16() -> String {
    let p = VellumPalette::vellum();
    let mut palette = IndexMap::new();
    for (slot, rgb) in p.base16() {
        palette.insert(slot.to_string(), slot_hex(rgb));
    }
    let body =
        serde_yaml::to_string(&scheme("base16", palette)).expect("Scheme is always serializable");
    format!("{HEADER}{body}")
}

/// Render the Vellum base16 scheme as a **Nix attrset** — the form that
/// costs no import-from-derivation.
///
/// ── ★ WHY THIS EXISTS AND THE YAML DOES NOT SUFFICE ──
/// stylix's `base16.nix` classifies its input with
/// `is-not-parsed = builtins.isAttrs scheme && !(scheme ? "yaml")`. The
/// fleet passed `{ yaml = <derivation>; }`, which sets `is-y2a-args`, so
/// stylix does `readFile <drv>` — an IFD. That forces a BUILD during
/// evaluation, and since the consumers are NixOS nodes the build is a
/// linux one: `nix eval .#nixosConfigurations.<node>` becomes impossible
/// from a Mac. The nixos-gnome-desktop profile's own comment records the
/// cost — the same IFD in the FONTS slot "made ggg's config UNEVALUABLE
/// from a Mac", which is why fonts were moved to a precomputed render and
/// why this is that move's missing twin.
///
/// A literal attrset takes the `is-not-parsed` branch instead: stylix
/// treats it as an already-parsed colour set and never reads a file. No
/// derivation, no build, no platform coupling.
///
/// Emitted through the typed `nix_ast` printer rather than by formatting
/// strings — `format!()` of Nix syntax is banned (theory/NIX-AST.md), and
/// the failure it prevents is silent: an unbalanced brace or a missing
/// semicolon ships as a file that parses to the wrong thing.
#[must_use]
pub fn render_base16_nix() -> String {
    use crate::nix_ast::{AttrEntry, NixFile, attrset, str_};

    let p = VellumPalette::vellum();
    let entries: Vec<AttrEntry> = p
        .base16()
        .into_iter()
        // Hex WITHOUT a leading `#`, matching the YAML this replaces —
        // stylix's own scheme format is bare hex, and a `#` here would be
        // a silent colour change rather than a parse error.
        .map(|(slot, rgb)| AttrEntry::new(slot, str_(slot_hex(rgb))))
        .collect();

    NixFile::new(
        [
            "Generated by ishou-render::vellum — DO NOT EDIT",
            "Source of truth: pleme-io/ishou/crates/ishou-tokens/src/vellum.rs",
            "",
            "Vellum base16 as an ALREADY-PARSED attrset. Consumed as:",
            "  stylix.base16Scheme = import ./rendered/stylix-base16-vellum.nix;",
            "",
            "The `{ yaml = <derivation>; }` form this replaces made stylix",
            "readFile a derivation — an IFD — which forced a linux build during",
            "evaluation and left every NixOS node unevaluable from a Mac.",
        ],
        attrset(entries),
    )
    .render()
}

/// Render the Vellum **base24** stylix scheme YAML (base16 + the
/// real two-tier brights, base10–17).
#[must_use]
pub fn render_base24() -> String {
    let p = VellumPalette::vellum();
    let mut palette = IndexMap::new();
    for (slot, rgb) in p.base24() {
        palette.insert(slot.to_string(), slot_hex(rgb));
    }
    let body =
        serde_yaml::to_string(&scheme("base24", palette)).expect("Scheme is always serializable");
    format!("{HEADER}{body}")
}

/// Render an SVG palette preview — one labelled chip per BORN token, in
/// band order. A brand-asset target for docs / design review.
#[must_use]
pub fn render_svg_palette() -> String {
    let p = VellumPalette::vellum();
    let entries = p.entries();
    let cols = 6usize;
    let chip = 96i32;
    let pad = 12i32;
    let label_h = 22i32;
    let rows = entries.len().div_ceil(cols) as i32;
    let width = cols as i32 * (chip + pad) + pad;
    let height = rows * (chip + label_h + pad) + pad;

    let mut chips = String::new();
    for (i, (name, rgb)) in entries.iter().enumerate() {
        let col = (i % cols) as i32;
        let row = (i / cols) as i32;
        let x = pad + col * (chip + pad);
        let y = pad + row * (chip + label_h + pad);
        let hex = rgb.hex();
        // Pick a readable label colour: light on dark chips, dark on
        // light chips, by computed luminance.
        let lum = 0.2126 * f64::from(rgb.r) + 0.7152 * f64::from(rgb.g) + 0.0722 * f64::from(rgb.b);
        let text_fill = if lum > 140.0 { "#16140E" } else { "#F4EFE2" };
        chips.push_str(&format!(
            "  <rect x=\"{x}\" y=\"{y}\" width=\"{chip}\" height=\"{chip}\" rx=\"8\" fill=\"{hex}\"/>\n  \
             <text x=\"{tx}\" y=\"{ty}\" font-family=\"monospace\" font-size=\"9\" fill=\"{text_fill}\">{hex}</text>\n  \
             <text x=\"{x}\" y=\"{ly}\" font-family=\"monospace\" font-size=\"10\" fill=\"#E2DBC8\">{name}</text>\n",
            tx = x + 6,
            ty = y + chip - 8,
            ly = y + chip + 15,
        ));
    }

    format!(
        "<!-- ishou Vellum palette preview (generated) -->\n\
         <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 {width} {height}\" width=\"{width}\" height=\"{height}\">\n  \
         <rect width=\"{width}\" height=\"{height}\" fill=\"#16140E\"/>\n{chips}</svg>\n"
    )
}

// ─── skim / fzf `--color` string ────────────────────────────────────────────

/// Resolve a Vellum token to its **uppercase** `#RRGGBB` hex — the skim
/// `--color` wire format mirrors the hand-authored `skim-tab::NORD_COLORS`,
/// which uses uppercase hex.
fn tok(p: &VellumPalette, name: &str) -> String {
    p.get(name)
        .unwrap_or_else(|| panic!("vellum token `{name}` missing"))
        .hex()
}

/// Render the skim/fzf `--color=k:v,…` string from the BORN `VellumPalette`.
///
/// Byte-equivalent to the hand-authored `pleme-io/skim-tab::NORD_COLORS`:
/// every colour resolves from a typed token, the `:bold`/`:underlined`
/// attribute suffixes are the picker's fixed UX contract. The role→token
/// map is the single source of truth — change a Vellum token and every
/// picker on the fleet follows.
///
/// Role → token:
/// - `fg`      → `snow1`        (base05, the text fg)
/// - `bg`      → `night0`       (base00, the parchment ground)
/// - `hl`      → `ice_cyan`     (base0C, match highlight) `:bold:underlined`
/// - `fg+`     → `snow3`        (base07, selected-line fg) `:bold`
/// - `bg+`     → `night2`       (the selected-line surface)
/// - `hl+`     → `cyan_bright`  (ANSI-14, selected-match) `:bold:underlined`
/// - `info`    → `shadow0`      (the dim ANSI-8 tier)
/// - `prompt`  → `aurora_green` (base0B, the prompt)
/// - `pointer` → `green_bright` (the cursor/green signature)
/// - `marker`  → `solar_magenta`(base0E, multi-select)
/// - `spinner` → `ice_steel`    (base0D)
/// - `header`  → `ice_steel`    (base0D)
/// - `border`  → `shadow0`      (the dim tier)
/// - `query`   → `snow3`        (base07) `:bold`
#[must_use]
pub fn render_skim() -> String {
    let p = VellumPalette::vellum();
    // (key, token, attr-suffix) — order is the skim-tab authored order.
    let rows: [(&str, &str, &str); 14] = [
        ("fg", "snow1", ""),
        ("bg", "night0", ""),
        ("hl", "ice_cyan", ":bold:underlined"),
        ("fg+", "snow3", ":bold"),
        ("bg+", "night2", ""),
        ("hl+", "cyan_bright", ":bold:underlined"),
        ("info", "shadow0", ""),
        ("prompt", "aurora_green", ""),
        ("pointer", "green_bright", ""),
        ("marker", "solar_magenta", ""),
        ("spinner", "ice_steel", ""),
        ("header", "ice_steel", ""),
        ("border", "shadow0", ""),
        ("query", "snow3", ":bold"),
    ];
    rows.iter()
        .map(|(key, token, attr)| format!("{key}:{}{attr}", tok(&p, token)))
        .collect::<Vec<_>>()
        .join(",")
}

// ─── escriba theme lisp ──────────────────────────────────────────────────────

/// A `(defhighlight …)` row — a group plus the typed token roles it paints.
/// `link` is mutually exclusive with the colour/attr fields (escriba's
/// `HighlightSpec` honours `link` first).
struct HiRow {
    group: &'static str,
    /// fg token name (resolved through `VellumPalette::get`), or `""`.
    fg: &'static str,
    /// bg token name, or `""`.
    bg: &'static str,
    bold: bool,
    italic: bool,
    /// `:link "<group>"` — when set, colour fields are skipped.
    link: &'static str,
}

impl HiRow {
    const fn fg(group: &'static str, fg: &'static str) -> Self {
        Self {
            group,
            fg,
            bg: "",
            bold: false,
            italic: false,
            link: "",
        }
    }
    const fn bg(group: &'static str, bg: &'static str) -> Self {
        Self {
            group,
            fg: "",
            bg,
            bold: false,
            italic: false,
            link: "",
        }
    }
    const fn fg_bg(group: &'static str, fg: &'static str, bg: &'static str) -> Self {
        Self {
            group,
            fg,
            bg,
            bold: false,
            italic: false,
            link: "",
        }
    }
    const fn link(group: &'static str, link: &'static str) -> Self {
        Self {
            group,
            fg: "",
            bg: "",
            bold: false,
            italic: false,
            link,
        }
    }
    const fn b(mut self) -> Self {
        self.bold = true;
        self
    }
    const fn i(mut self) -> Self {
        self.italic = true;
        self
    }
}

/// Lowercase, `#`-prefixed six-char hex — escriba's `defpalette` /
/// `defhighlight` wire format (the hand-authored `vellum.lisp` uses
/// lowercase hex).
fn lc_hex(p: &VellumPalette, name: &str) -> String {
    let h = tok(p, name); // "#RRGGBB" uppercase
    format!("#{}", h[1..].to_ascii_lowercase())
}

/// A typed `(defX :k v …)` line writer — one keyword/value pair per
/// emitted slot, joined with single spaces, wrapped in parens. Keeps the
/// emission off ad-hoc concatenation (TYPED EMISSION).
fn lisp_form(head: &str, kvs: &[(&str, String)]) -> String {
    use std::fmt::Write as _;
    let mut s = String::new();
    write!(s, "({head}").expect("write to String");
    for (k, v) in kvs {
        write!(s, " {k} {v}").expect("write to String");
    }
    s.push(')');
    s
}

/// Render the escriba Vellum theme `*.lisp` — a `(deftheme …)` +
/// `(defpalette …)` + the `(defhighlight …)` forms over escriba's
/// `CANONICAL_GROUPS`, all sourced from the BORN `VellumPalette`.
///
/// Mirrors `pleme-io/escriba/escriba/configs/vellum.lisp` so escriba can
/// later `include` the generated file. Every colour resolves through a
/// typed token; the diff backgrounds use the byte-exact GLASS blend
/// tokens (`*_glass`), so they can never drift from the blend recipes.
#[must_use]
pub fn render_escriba_lisp() -> String {
    use std::fmt::Write as _;
    let p = VellumPalette::vellum();

    let mut out = String::new();
    out.push_str(
        "; escriba — Vellum theme (the fleet default)\n\
         ; Generated by ishou-render::vellum::render_escriba_lisp — DO NOT EDIT\n\
         ; Source of truth: pleme-io/ishou/crates/ishou-tokens/src/vellum.rs\n\
         ; Vellum — warm aged-paper Nord-matte; every hex is a BORN ishou token.\n\n",
    );

    // ─ Theme select ─
    writeln!(
        out,
        "{}",
        lisp_form("deftheme", &[(":preset", "\"vellum\"".to_string())])
    )
    .expect("write");
    out.push('\n');

    // ─ Palette — base16 slots, lowercase hex. base02 carries night2
    //   (the escriba lisp's selected-line surface), NOT the violet
    //   selection blend — matching the hand-authored file. ─
    let palette_kvs: Vec<(&str, String)> = vec![
        (":name", "\"vellum\"".to_string()),
        (":base00", format!("\"{}\"", lc_hex(&p, "night0"))),
        (":base01", format!("\"{}\"", lc_hex(&p, "night1"))),
        (":base02", format!("\"{}\"", lc_hex(&p, "night2"))),
        (":base03", format!("\"{}\"", lc_hex(&p, "shadow1"))),
        (":base04", format!("\"{}\"", lc_hex(&p, "snow0"))),
        (":base05", format!("\"{}\"", lc_hex(&p, "snow1"))),
        (":base06", format!("\"{}\"", lc_hex(&p, "snow2"))),
        (":base07", format!("\"{}\"", lc_hex(&p, "snow3"))),
        (":base08", format!("\"{}\"", lc_hex(&p, "aurora_red"))),
        (":base09", format!("\"{}\"", lc_hex(&p, "ember"))),
        (":base0a", format!("\"{}\"", lc_hex(&p, "first_light"))),
        (":base0b", format!("\"{}\"", lc_hex(&p, "aurora_green"))),
        (":base0c", format!("\"{}\"", lc_hex(&p, "ice_cyan"))),
        (":base0d", format!("\"{}\"", lc_hex(&p, "ice_steel"))),
        (":base0e", format!("\"{}\"", lc_hex(&p, "solar_magenta"))),
        (":base0f", format!("\"{}\"", lc_hex(&p, "dusk_bronze"))),
    ];
    writeln!(out, "{}", lisp_form("defpalette", &palette_kvs)).expect("write");
    out.push('\n');

    // ─ Highlights — group → token-role map. Mirrors the hand-authored
    //   vellum.lisp group set (escriba's CANONICAL_GROUPS + the
    //   tree-sitter overrides). ─
    let rows: &[HiRow] = &[
        // Syntax
        HiRow::fg_bg("Normal", "snow1", "night0"),
        HiRow::fg("Comment", "shadow1").i(),
        HiRow::fg("String", "aurora_green"),
        HiRow::fg("Number", "solar_magenta"),
        HiRow::fg("Boolean", "solar_magenta"),
        HiRow::fg("Function", "ice_steel").b(),
        HiRow::fg("Keyword", "solar_magenta").i(),
        HiRow::fg("Statement", "solar_magenta"),
        HiRow::fg("Conditional", "solar_magenta"),
        HiRow::fg("Repeat", "solar_magenta"),
        HiRow::fg("Operator", "solar_magenta"),
        HiRow::fg("Type", "first_light"),
        HiRow::fg("Structure", "first_light"),
        HiRow::fg("Identifier", "snow1"),
        HiRow::fg("Constant", "ember"),
        HiRow::fg("PreProc", "ember"),
        HiRow::fg("Macro", "ember"),
        HiRow::fg("Special", "first_light"),
        // UI
        HiRow::bg("CursorLine", "night1"),
        HiRow::bg("CursorColumn", "night1"),
        HiRow::fg("LineNr", "shadow1"),
        HiRow::bg("SignColumn", "night0"),
        HiRow::bg("Visual", "night2"),
        HiRow::bg("VisualNOS", "night2"),
        HiRow::fg_bg("Search", "night0", "first_light"),
        HiRow::fg_bg("IncSearch", "night0", "ember").b(),
        HiRow::fg("MatchParen", "ember").b(),
        HiRow::fg_bg("StatusLine", "snow1", "night1"),
        HiRow::fg_bg("StatusLineNC", "shadow1", "night0"),
        HiRow::fg_bg("TabLine", "shadow1", "night0"),
        HiRow::bg("TabLineFill", "night0"),
        HiRow::fg_bg("TabLineSel", "night0", "ice_cyan").b(),
        HiRow::fg("VertSplit", "night3"),
        HiRow::fg_bg("Pmenu", "snow1", "night1"),
        HiRow::fg_bg("PmenuSel", "night0", "ice_cyan").b(),
        HiRow::bg("PmenuSbar", "night1"),
        HiRow::bg("PmenuThumb", "shadow1"),
        HiRow::fg_bg("NormalFloat", "snow1", "night1"),
        HiRow::fg_bg("FloatBorder", "ice_steel", "night1"),
        // Diagnostics
        HiRow::fg("DiagnosticError", "aurora_red").b(),
        HiRow::fg("DiagnosticWarn", "first_light"),
        HiRow::fg("DiagnosticInfo", "ice_cyan"),
        HiRow::fg("DiagnosticHint", "aurora_green"),
        // Git (gitsigns parity) + diff backgrounds (the GLASS blends)
        HiRow::fg("GitSignsAdd", "aurora_green"),
        HiRow::fg("GitSignsChange", "first_light"),
        HiRow::fg("GitSignsDelete", "aurora_red"),
        HiRow::bg("DiffAdd", "green_glass"),
        HiRow::bg("DiffChange", "amber_glass"),
        HiRow::bg("DiffDelete", "red_glass"),
        HiRow::bg("DiffText", "steel_glass"),
        // Tree-sitter semantic overrides
        HiRow::link("@function.call", "Function"),
        HiRow::link("@variable", "Identifier"),
        HiRow::fg("@parameter", "snow1").i(),
        HiRow::fg("@comment.todo", "first_light").b(),
        HiRow::fg("@comment.note", "ice_cyan").b(),
        HiRow::fg("@comment.warning", "ember").b(),
    ];

    for r in rows {
        let mut kvs: Vec<(&str, String)> = vec![(":group", format!("\"{}\"", r.group))];
        if r.link.is_empty() {
            if !r.fg.is_empty() {
                kvs.push((":fg", format!("\"{}\"", lc_hex(&p, r.fg))));
            }
            if !r.bg.is_empty() {
                kvs.push((":bg", format!("\"{}\"", lc_hex(&p, r.bg))));
            }
            if r.bold {
                kvs.push((":bold", "#t".to_string()));
            }
            if r.italic {
                kvs.push((":italic", "#t".to_string()));
            }
        } else {
            kvs.push((":link", format!("\"{}\"", r.link)));
        }
        writeln!(out, "{}", lisp_form("defhighlight", &kvs)).expect("write");
    }

    out
}

#[cfg(test)]
mod tests {

    /// The nix attrset and the YAML scheme are the SAME palette.
    ///
    /// They are two renders of one source, and the whole point of the nix
    /// one is that consumers can switch to it — so a divergence would be a
    /// silent colour change on every fleet desktop, visible to nobody until
    /// someone noticed their terminal looked wrong.
    #[test]
    fn the_nix_render_carries_the_same_palette_as_the_yaml() {
        let yaml = super::render_base16();
        let nixs = super::render_base16_nix();
        for (slot, rgb) in VellumPalette::vellum().base16() {
            let hex = super::slot_hex(rgb);
            assert!(
                yaml.contains(&format!("{slot}: {hex}")),
                "yaml missing {slot}"
            );
            assert!(
                nixs.contains(&format!("{slot} = \"{hex}\";")),
                "nix missing {slot}"
            );
        }
    }

    /// stylix decides how to read a scheme with
    /// `is-not-parsed = builtins.isAttrs scheme && !(scheme ? "yaml")`.
    /// The whole IFD-avoidance rests on this file being a bare attrset with
    /// no `yaml` key — a `yaml = ` anywhere in it would silently restore
    /// the readFile path and the linux build with it.
    #[test]
    fn the_nix_render_is_a_bare_attrset_with_no_yaml_key() {
        let out = super::render_base16_nix();
        let body: String = out.lines().filter(|l| !l.starts_with('#')).collect();
        assert!(
            body.trim_start().starts_with('{'),
            "must be an attrset: {body}"
        );
        assert!(
            !body.contains("yaml"),
            "a `yaml` key would put stylix back on the IFD path"
        );
        // A lambda would make it `import path { … }`, not `import path`.
        assert!(!body.contains(':'), "must not be a function: {body}");
    }
    use super::*;

    #[test]
    fn base16_is_deterministic() {
        assert_eq!(render_base16(), render_base16());
    }

    #[test]
    fn skim_string_is_deterministic() {
        assert_eq!(render_skim(), render_skim());
    }

    #[test]
    fn skim_string_matches_the_authored_vellum_string() {
        // The exact byte sequence `pleme-io/skim-tab::NORD_COLORS` ships
        // (joined with `,` — no trailing newline). Generated from the
        // typed Vellum tokens.
        let expected = "\
fg:#E2DBC8,\
bg:#16140E,\
hl:#94BBB8:bold:underlined,\
fg+:#F4EFE2:bold,\
bg+:#2B2820,\
hl+:#A6CBC8:bold:underlined,\
info:#6E6857,\
prompt:#A9BB8C,\
pointer:#ADD7A3,\
marker:#B8A1B9,\
spinner:#99AABE,\
header:#99AABE,\
border:#6E6857,\
query:#F4EFE2:bold";
        assert_eq!(render_skim(), expected, "skim --color string drifted");
    }

    #[test]
    fn escriba_lisp_is_deterministic() {
        assert_eq!(render_escriba_lisp(), render_escriba_lisp());
    }

    #[test]
    fn escriba_lisp_has_palette_and_key_highlights() {
        let out = render_escriba_lisp();
        // defpalette base00 = night0, lowercase.
        assert!(
            out.contains("(defpalette :name \"vellum\" :base00 \"#16140e\""),
            "defpalette base00 missing/drifted:\n{out}"
        );
        // A handful of canonical groups, exact emitted lines.
        for line in [
            "(defhighlight :group \"Normal\" :fg \"#e2dbc8\" :bg \"#16140e\")",
            "(defhighlight :group \"Comment\" :fg \"#90897b\" :italic #t)",
            "(defhighlight :group \"String\" :fg \"#a9bb8c\")",
            "(defhighlight :group \"Function\" :fg \"#99aabe\" :bold #t)",
            "(defhighlight :group \"DiffAdd\" :bg \"#4d543e\")",
            "(defhighlight :group \"@function.call\" :link \"Function\")",
        ] {
            assert!(out.contains(line), "missing line `{line}`\n{out}");
        }
        // Every CANONICAL group label appears as an emitted group.
        for g in [
            "Normal",
            "Comment",
            "String",
            "Number",
            "Boolean",
            "Function",
            "Keyword",
            "Statement",
            "Type",
            "Constant",
            "Special",
            "Visual",
            "Search",
            "DiagnosticError",
            "GitSignsAdd",
        ] {
            assert!(
                out.contains(&format!(":group \"{g}\"")),
                "missing group {g}\n{out}"
            );
        }
    }

    #[test]
    fn base16_has_all_16_slots_lowercase_unprefixed() {
        let out = render_base16();
        for slot in [
            "base00", "base01", "base02", "base03", "base04", "base05", "base06", "base07",
            "base08", "base09", "base0A", "base0B", "base0C", "base0D", "base0E", "base0F",
        ] {
            assert!(out.contains(slot), "missing {slot}");
        }
        // base00 is night0 (#16140E → 16140e), unprefixed lc.
        assert!(out.contains("16140e"), "base00 night0 missing:\n{out}");
        // No leading `#` on any value (would break GTK theme-gen).
        assert!(!out.contains(": #"), "found prefixed hex:\n{out}");
    }

    #[test]
    fn base16_slots_match_the_born_palette() {
        let p = VellumPalette::vellum();
        let out = render_base16();
        for (slot, rgb) in p.base16() {
            let want = format!("{slot}: {}", slot_hex(rgb));
            assert!(
                out.contains(&want),
                "slot {slot} drifted; want `{want}`\n{out}"
            );
        }
    }

    #[test]
    fn base24_has_the_real_brights() {
        let out = render_base24();
        // base14 = green_bright (#ADD7A3), base12 = red_bright (#D49088).
        assert!(
            out.contains("base14: add7a3"),
            "base14 green_bright:\n{out}"
        );
        assert!(out.contains("base12: d49088"), "base12 red_bright:\n{out}");
        assert!(out.contains("system: base24"), "wrong system tag:\n{out}");
    }

    #[test]
    fn svg_palette_is_deterministic_and_covers_every_token() {
        let a = render_svg_palette();
        assert_eq!(a, render_svg_palette());
        let p = VellumPalette::vellum();
        for (name, _) in p.entries() {
            assert!(a.contains(name), "svg missing token {name}");
        }
    }
}