Skip to main content

nmbrs_workload/report/
vocab.rs

1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! Single source of truth for the report grammar's lexical
5//! vocabulary — directives, their CLI flag mapping, and the
6//! valid value space for each.
7//!
8//! See [SRD-64 §4.3](../../../../docs/SRD/64_report_cli.md)
9//! for the design intent. This module is consumed by:
10//!
11//! - the YAML parser in [`super`] (validates `to`
12//!   destinations against [`DESTINATION_NAMES`]),
13//! - `nmbrs::report_cmd` (builds [`super::ReportItem`] from CLI
14//!   flags by walking [`directives_for`]),
15//! - `nmbrs::completion::report_node` (offers per-flag
16//!   value providers from [`ValueProvider`]),
17//! - `super::ReportItem::to_yaml_directive_string` (the
18//!   round-trip emitter — uses canonical directive ordering
19//!   from [`directives_for`]).
20//!
21//! Adding a new directive means adding an entry to one of
22//! the per-kind tables in this module. The parser, CLI,
23//! completion, and emitter all pick it up automatically.
24//!
25//! ## Closed sets
26//!
27//! Directives whose value space is a closed set ship the
28//! enumeration here. Tab completion offers exactly these
29//! values; the parser rejects anything else.
30//!
31//! ## Open sets
32//!
33//! Directives whose value space depends on the active
34//! session db (metric names, observed label keys / values)
35//! ship one of the `Db*` tags ([`ValueProvider::DbMetricNames`],
36//! [`ValueProvider::DbLabelKeys`],
37//! [`ValueProvider::DbLabelKeyValuePairs`]). Completion plumbing in
38//! `nmbrs::completion` resolves these against the active
39//! session at tab time. The parser does not validate
40//! open-set values — they're free-form strings until the
41//! renderer queries the db.
42
43use super::Kind;
44
45/// Enumeration of value-space kinds for one directive's
46/// argument. Drives both completion suggestions and
47/// (for closed sets) parser-side validation.
48#[derive(Debug, Clone, PartialEq, Eq)]
49pub enum ValueProvider {
50    /// Free text — no completion, no validation.
51    /// Examples: `--label`, `--xlabel`, `--ylabel`.
52    Text,
53    /// Closed set of strings. Completion offers exactly
54    /// these; the parser rejects anything else.
55    Closed(&'static [&'static str]),
56    /// Numeric value (`f32` / `u32`). Completion offers
57    /// no suggestions; parser asserts numeric.
58    Number,
59    /// Hex color (`#RRGGBB` / `#RRGGBBAA`). Completion
60    /// offers no suggestions; parser asserts the shape.
61    HexColor,
62    /// File-system path (with `*.yaml` / `*.yml` filter
63    /// for workload paths). Completion plumbing decides.
64    Path { glob: &'static str },
65    /// Metric names from the active session db.
66    /// Completion queries the db at tab time.
67    DbMetricNames,
68    /// Distinct label keys observed in the active session
69    /// db. Completion queries the db at tab time.
70    DbLabelKeys,
71    /// `key=value` pairs where `key` completes from
72    /// [`Self::DbLabelKeys`] and `value` completes from the
73    /// distinct values observed for that key. Multi-valued
74    /// (comma-separated). Used for `--where`.
75    DbLabelKeyValuePairs,
76    /// Strict-JSON object literal. No completion.
77    /// Used for `--series` sub-blocks.
78    Json,
79}
80
81/// One directive: its CLI flag, its YAML directive name, the
82/// kinds it applies to, and the value-space it consumes.
83///
84/// `cli_flag` is always `--<name>`. `yaml_directive` is the
85/// keyword the YAML parser recognises; for some directives
86/// the YAML form is `<name> <value>` (no `=`) and for others
87/// it's `<name>=<value>`. [`yaml_form`](Directive::yaml_form) captures that.
88#[derive(Debug, Clone, PartialEq, Eq)]
89pub struct Directive {
90    /// CLI long flag (e.g. `--over`, `--palette`).
91    pub cli_flag: &'static str,
92    /// YAML directive keyword (e.g. `over`, `palette`).
93    pub yaml_directive: &'static str,
94    /// Whether the YAML form uses `=` or whitespace
95    /// between keyword and value.
96    pub yaml_form: YamlForm,
97    /// Kinds the directive applies to. Per-item
98    /// declarations on a non-applicable kind warn at parse
99    /// time (SRD-46 §"Style and metadata directives").
100    pub applies_to: KindMask,
101    /// Where the directive's value lands in the AST.
102    pub target: DirectiveTarget,
103    /// Value-space for completion + parser validation.
104    pub value: ValueProvider,
105    /// Whether the flag may appear more than once in one
106    /// command-line invocation (e.g. `--series` is
107    /// repeatable; `--label` is not).
108    pub repeatable: bool,
109}
110
111/// `<keyword> <value>` (whitespace-separated) vs
112/// `<keyword>=<value>` (assignment). The parser accepts
113/// both for some directives by historical accident; this
114/// type captures the **canonical** form the round-trip
115/// emitter uses.
116#[derive(Debug, Clone, Copy, PartialEq, Eq)]
117pub enum YamlForm {
118    /// `over cycle`, `by profile`, `where dataset=example`,
119    /// `label "Demo"`, `as plot_demo`.
120    Whitespace,
121    /// `palette=wong`, `agg=mean`, `width=4`, `xscale=log`.
122    Equals,
123}
124
125/// Where a directive's value lives in the parsed AST. The
126/// CLI builder uses this to decide which field to populate;
127/// the round-trip emitter walks targets in canonical order.
128#[derive(Debug, Clone, Copy, PartialEq, Eq)]
129pub enum DirectiveTarget {
130    /// `ReportItem::label`.
131    ItemLabel,
132    /// `ReportItem::as_stem`.
133    ItemAsStem,
134    /// One of the [`super::Style`] scalar fields, named by
135    /// `yaml_directive`.
136    StyleField,
137    /// `ReportItem::style.series` (one entry per `--series`).
138    StyleSeries,
139    /// [`super::Style::destinations`] — the output routing set
140    /// (`to stdout, sessiondir`). Rides the style cascade so a
141    /// `defaults:` mapping can route a whole report or group at
142    /// once, but it is routing, not cosmetics.
143    Destinations,
144    /// `ReportItem::body` line — the renderer-consumed
145    /// directives (`over`, `by`, `where`, `agg`, `xlabel`,
146    /// `ylabel`, `xscale`, `yscale`, `metric`).
147    Body,
148}
149
150/// Bitmask of [`Kind`] applicability. A directive may apply
151/// to one kind, several, or all.
152#[derive(Debug, Clone, Copy, PartialEq, Eq)]
153pub struct KindMask(pub u8);
154
155impl KindMask {
156    pub const PLOT: KindMask = KindMask(1 << 0);
157    pub const TABLE: KindMask = KindMask(1 << 1);
158    pub const TEXT: KindMask = KindMask(1 << 2);
159    pub const FILE: KindMask = KindMask(1 << 3);
160    pub const DETAILS: KindMask = KindMask(1 << 4);
161
162    /// `Plot ∪ Table` — the figure kinds.
163    pub const FIGURES: KindMask = KindMask(0b00011);
164    /// Every kind.
165    pub const ALL: KindMask = KindMask(0b11111);
166
167    pub const fn contains(self, kind: Kind) -> bool {
168        (self.0 & kind_bit(kind)) != 0
169    }
170
171    pub const fn or(self, other: KindMask) -> KindMask {
172        KindMask(self.0 | other.0)
173    }
174}
175
176const fn kind_bit(kind: Kind) -> u8 {
177    match kind {
178        Kind::Plot => 1 << 0,
179        Kind::Table => 1 << 1,
180        Kind::Text => 1 << 2,
181        Kind::File => 1 << 3,
182        Kind::Details => 1 << 4,
183    }
184}
185
186// ---------------------------------------------------------------------------
187// Closed-set vocabularies
188// ---------------------------------------------------------------------------
189
190/// Aggregation function names accepted by `--agg` /
191/// `agg=<fn>`.
192pub const AGG_FNS: &[&str] = &["mean", "min", "max", "p50", "p99", "sum", "count"];
193
194/// Palette names. Numeric indices (`0`..`7`) are also
195/// accepted by the parser; completion only offers the
196/// named forms — numeric indices are a discoverability
197/// dead-end.
198pub const PALETTE_NAMES: &[&str] = &[
199    "wong",
200    "cividis_5",
201    "ibm",
202    "tol_bright",
203    "tol_high_contrast",
204    "tol_light",
205    "tol_muted",
206    "viridis_5",
207];
208
209/// Line-dash styles.
210pub const LINE_STYLES: &[&str] = &["solid", "dashed", "dotted", "dashdot", "none"];
211
212/// Marker shapes. `auto` cycles a distinct shape per series
213/// (literature-style); the rest are explicit shapes.
214pub const MARKER_SHAPES: &[&str] = &[
215    "auto", "none", "circle", "square", "triangle", "diamond", "plus", "cross",
216];
217
218/// Axis scale modes.
219/// Axis-scale mode keywords accepted by `xscale=` / `yscale=`.
220///
221/// - `linear` — default linear axis, range derived from data.
222/// - `log` — logarithmic axis (base 10). Data ≤ 0 becomes a
223///   plot error. Tick marks land on decade boundaries
224///   automatically.
225/// - `dec` — linear axis but the range is *snapped* to the
226///   nearest decade boundary on each side (powers of 10),
227///   producing tick marks at "round" decimal values.
228/// - `bin` — linear axis snapped to power-of-2 boundaries
229///   (1, 2, 4, 8, 16, …). Useful for plots whose x-axis is a
230///   `limit=` or `concurrency=` swept by doubling.
231pub const AXIS_SCALES: &[&str] = &["linear", "log", "dec", "bin"];
232
233/// SRD-46 output destinations — where a rendered item is
234/// delivered (`to stdout, sessiondir`).
235///
236/// - `sessiondir` — the session directory: the standalone
237///   artifact plus the markdown upsert into `summary.md` (or
238///   the item's `file` target). The default when nothing is
239///   declared, so a run's report is always durable.
240/// - `stdout` / `stderr` — the console form on that stream.
241///   NEVER implied: end-of-run rendering writes to a terminal
242///   only when the workload asks, because stdout is a
243///   workload's op output and a report carries wall-clock
244///   values that make it non-reproducible.
245/// - `none` — render nothing. Suppresses the item without
246///   deleting its declaration.
247pub const DESTINATION_NAMES: &[&str] = &["sessiondir", "stdout", "stderr", "none"];
248
249// ---------------------------------------------------------------------------
250// The directive table — one entry per CLI flag / YAML
251// directive pair. Adding a new directive starts here.
252// ---------------------------------------------------------------------------
253
254/// All directives, in canonical declaration order. The
255/// round-trip emitter walks this in order, picking out
256/// entries applicable to the item's kind.
257///
258/// Ordering matters for the emitter — directives appear in
259/// this order in the emitted YAML so `parse → emit → parse`
260/// is identity. Roughly: identity (label / as) → style →
261/// data shape (over / by / where / agg) → axis (x* / y*) →
262/// per-series sub-blocks.
263pub const ALL_DIRECTIVES: &[Directive] = &[
264    // ── Item identity ────────────────────────────────────
265    Directive {
266        cli_flag: "--label",
267        yaml_directive: "label",
268        yaml_form: YamlForm::Whitespace,
269        applies_to: KindMask::ALL,
270        target: DirectiveTarget::ItemLabel,
271        value: ValueProvider::Text,
272        repeatable: false,
273    },
274    Directive {
275        cli_flag: "--as",
276        yaml_directive: "as",
277        yaml_form: YamlForm::Whitespace,
278        applies_to: KindMask::FIGURES,
279        target: DirectiveTarget::ItemAsStem,
280        value: ValueProvider::Text,
281        repeatable: false,
282    },
283    // ── Output routing ───────────────────────────────────
284    // `to <dest>[, <dest>…]` — where a rendered item is
285    // delivered. One directive carrying the whole comma list
286    // (not repeatable) so the declaration reads as a set and
287    // an inner scope REPLACES an outer one rather than
288    // accumulating destinations the operator can't take back.
289    Directive {
290        cli_flag: "--to",
291        yaml_directive: "to",
292        yaml_form: YamlForm::Whitespace,
293        applies_to: KindMask::ALL,
294        target: DirectiveTarget::Destinations,
295        value: ValueProvider::Closed(DESTINATION_NAMES),
296        repeatable: false,
297    },
298    // ── Style / cosmetics ────────────────────────────────
299    Directive {
300        cli_flag: "--palette",
301        yaml_directive: "palette",
302        yaml_form: YamlForm::Equals,
303        applies_to: KindMask::FIGURES,
304        target: DirectiveTarget::StyleField,
305        value: ValueProvider::Closed(PALETTE_NAMES),
306        repeatable: false,
307    },
308    Directive {
309        cli_flag: "--line",
310        yaml_directive: "line",
311        yaml_form: YamlForm::Equals,
312        applies_to: KindMask::PLOT,
313        target: DirectiveTarget::StyleField,
314        value: ValueProvider::Closed(LINE_STYLES),
315        repeatable: false,
316    },
317    Directive {
318        cli_flag: "--width",
319        yaml_directive: "width",
320        yaml_form: YamlForm::Equals,
321        applies_to: KindMask::PLOT,
322        target: DirectiveTarget::StyleField,
323        value: ValueProvider::Number,
324        repeatable: false,
325    },
326    Directive {
327        cli_flag: "--scale",
328        yaml_directive: "scale",
329        yaml_form: YamlForm::Equals,
330        applies_to: KindMask::PLOT,
331        target: DirectiveTarget::StyleField,
332        value: ValueProvider::Number,
333        repeatable: false,
334    },
335    Directive {
336        cli_flag: "--marker",
337        yaml_directive: "marker",
338        yaml_form: YamlForm::Equals,
339        applies_to: KindMask::PLOT,
340        target: DirectiveTarget::StyleField,
341        value: ValueProvider::Closed(MARKER_SHAPES),
342        repeatable: false,
343    },
344    Directive {
345        cli_flag: "--size",
346        yaml_directive: "size",
347        yaml_form: YamlForm::Equals,
348        applies_to: KindMask::PLOT,
349        target: DirectiveTarget::StyleField,
350        value: ValueProvider::Number,
351        repeatable: false,
352    },
353    Directive {
354        cli_flag: "--color",
355        yaml_directive: "color",
356        yaml_form: YamlForm::Equals,
357        applies_to: KindMask::FIGURES,
358        target: DirectiveTarget::StyleField,
359        value: ValueProvider::HexColor,
360        repeatable: false,
361    },
362    Directive {
363        cli_flag: "--figure-width",
364        yaml_directive: "figure_width",
365        yaml_form: YamlForm::Equals,
366        applies_to: KindMask::FIGURES,
367        target: DirectiveTarget::StyleField,
368        value: ValueProvider::Number,
369        repeatable: false,
370    },
371    Directive {
372        cli_flag: "--figure-height",
373        yaml_directive: "figure_height",
374        yaml_form: YamlForm::Equals,
375        applies_to: KindMask::FIGURES,
376        target: DirectiveTarget::StyleField,
377        value: ValueProvider::Number,
378        repeatable: false,
379    },
380    // ── Data shape (body directives) ─────────────────────
381    Directive {
382        cli_flag: "--metric",
383        yaml_directive: "metric",
384        yaml_form: YamlForm::Whitespace,
385        applies_to: KindMask::FIGURES,
386        target: DirectiveTarget::Body,
387        value: ValueProvider::DbMetricNames,
388        repeatable: false,
389    },
390    Directive {
391        cli_flag: "--over",
392        yaml_directive: "over",
393        yaml_form: YamlForm::Whitespace,
394        applies_to: KindMask::FIGURES,
395        target: DirectiveTarget::Body,
396        value: ValueProvider::DbLabelKeys,
397        repeatable: false,
398    },
399    Directive {
400        cli_flag: "--by",
401        yaml_directive: "by",
402        yaml_form: YamlForm::Whitespace,
403        applies_to: KindMask::FIGURES,
404        target: DirectiveTarget::Body,
405        value: ValueProvider::DbLabelKeys,
406        repeatable: false,
407    },
408    Directive {
409        cli_flag: "--where",
410        yaml_directive: "where",
411        yaml_form: YamlForm::Whitespace,
412        applies_to: KindMask::FIGURES,
413        target: DirectiveTarget::Body,
414        value: ValueProvider::DbLabelKeyValuePairs,
415        repeatable: false,
416    },
417    Directive {
418        cli_flag: "--agg",
419        yaml_directive: "agg",
420        yaml_form: YamlForm::Equals,
421        applies_to: KindMask::FIGURES,
422        target: DirectiveTarget::Body,
423        value: ValueProvider::Closed(AGG_FNS),
424        repeatable: false,
425    },
426    // ── Axis labels / scales (plot only) ─────────────────
427    Directive {
428        cli_flag: "--xlabel",
429        yaml_directive: "xlabel",
430        yaml_form: YamlForm::Equals,
431        applies_to: KindMask::PLOT,
432        target: DirectiveTarget::Body,
433        value: ValueProvider::Text,
434        repeatable: false,
435    },
436    Directive {
437        cli_flag: "--ylabel",
438        yaml_directive: "ylabel",
439        yaml_form: YamlForm::Equals,
440        applies_to: KindMask::PLOT,
441        target: DirectiveTarget::Body,
442        value: ValueProvider::Text,
443        repeatable: false,
444    },
445    Directive {
446        cli_flag: "--x-scale",
447        yaml_directive: "x-scale",
448        yaml_form: YamlForm::Equals,
449        applies_to: KindMask::PLOT,
450        target: DirectiveTarget::Body,
451        value: ValueProvider::Closed(AXIS_SCALES),
452        repeatable: false,
453    },
454    Directive {
455        cli_flag: "--y-scale",
456        yaml_directive: "y-scale",
457        yaml_form: YamlForm::Equals,
458        applies_to: KindMask::PLOT,
459        target: DirectiveTarget::Body,
460        value: ValueProvider::Closed(AXIS_SCALES),
461        repeatable: false,
462    },
463    // ── Per-series style override (repeatable) ───────────
464    //
465    // `style <key>=<value>:<directives>` overrides scalar
466    // style fields (line / width / marker / size / color /
467    // palette) for the series whose discriminator matches
468    // `<key>=<value>`. Series-partition selection is no
469    // longer a plot directive — `query: avg(…) by (k, profile)`
470    // with `x: <one-of-those>` is the canonical declaration,
471    // and the renderer auto-derives partition labels from the
472    // result-set labels minus the X axis. That makes "what
473    // dimensions split the series" a property of the
474    // MetricsQL aggregation surface rather than something the
475    // plot grammar duplicates.
476    Directive {
477        cli_flag: "--style",
478        yaml_directive: "style",
479        yaml_form: YamlForm::Whitespace,
480        applies_to: KindMask::FIGURES,
481        target: DirectiveTarget::StyleSeries,
482        value: ValueProvider::Json,
483        repeatable: true,
484    },
485];
486
487/// Directives applicable to one [`Kind`], in canonical
488/// emit order. Filters [`ALL_DIRECTIVES`] by
489/// [`Directive::applies_to`].
490pub fn directives_for(kind: Kind) -> impl Iterator<Item = &'static Directive> {
491    ALL_DIRECTIVES
492        .iter()
493        .filter(move |d| d.applies_to.contains(kind))
494}
495
496/// Look up the directive for a given CLI flag (without
497/// the leading `--`). Returns `None` for unknown flags.
498pub fn directive_by_cli_flag(flag: &str) -> Option<&'static Directive> {
499    ALL_DIRECTIVES.iter().find(|d| {
500        // Accept both `--foo` and `foo` for ergonomics.
501        d.cli_flag == flag
502            || d.cli_flag
503                .strip_prefix("--")
504                .is_some_and(|stripped| stripped == flag)
505    })
506}
507
508/// Look up the directive for a given YAML directive
509/// keyword. Returns `None` for unknown keywords.
510pub fn directive_by_yaml_keyword(keyword: &str) -> Option<&'static Directive> {
511    ALL_DIRECTIVES.iter().find(|d| d.yaml_directive == keyword)
512}
513
514/// All CLI flags applicable to one kind, suitable for
515/// passing to `StrictNode::leaf_with_flags`. Stable
516/// order, matches [`ALL_DIRECTIVES`].
517pub fn cli_flags_for(kind: Kind) -> Vec<&'static str> {
518    directives_for(kind).map(|d| d.cli_flag).collect()
519}
520
521#[cfg(test)]
522mod tests {
523    use super::*;
524
525    #[test]
526    fn every_directive_has_a_unique_cli_flag() {
527        let mut seen: std::collections::HashSet<&str> = std::collections::HashSet::new();
528        for d in ALL_DIRECTIVES {
529            assert!(
530                seen.insert(d.cli_flag),
531                "duplicate cli_flag '{}'",
532                d.cli_flag
533            );
534        }
535    }
536
537    #[test]
538    fn every_directive_has_a_unique_yaml_keyword() {
539        let mut seen: std::collections::HashSet<&str> = std::collections::HashSet::new();
540        for d in ALL_DIRECTIVES {
541            assert!(
542                seen.insert(d.yaml_directive),
543                "duplicate yaml_directive '{}'",
544                d.yaml_directive
545            );
546        }
547    }
548
549    #[test]
550    fn every_cli_flag_starts_with_double_dash() {
551        for d in ALL_DIRECTIVES {
552            assert!(
553                d.cli_flag.starts_with("--"),
554                "cli_flag '{}' missing -- prefix",
555                d.cli_flag
556            );
557        }
558    }
559
560    #[test]
561    fn directives_for_plot_includes_axis_directives() {
562        let plot: Vec<&str> = directives_for(Kind::Plot).map(|d| d.cli_flag).collect();
563        assert!(plot.contains(&"--xlabel"));
564        assert!(plot.contains(&"--ylabel"));
565        assert!(plot.contains(&"--x-scale"));
566        assert!(plot.contains(&"--y-scale"));
567        assert!(plot.contains(&"--marker"));
568        assert!(plot.contains(&"--line"));
569    }
570
571    #[test]
572    fn directives_for_table_excludes_axis_and_marker_directives() {
573        let table: Vec<&str> = directives_for(Kind::Table).map(|d| d.cli_flag).collect();
574        assert!(!table.contains(&"--xlabel"));
575        assert!(!table.contains(&"--ylabel"));
576        assert!(!table.contains(&"--x-scale"));
577        assert!(!table.contains(&"--y-scale"));
578        assert!(!table.contains(&"--marker"));
579        assert!(!table.contains(&"--line"));
580        assert!(!table.contains(&"--width"));
581        assert!(!table.contains(&"--size"));
582    }
583
584    #[test]
585    fn directives_for_figures_share_data_shape_flags() {
586        // over / by / where / agg / metric apply to both
587        // plot and table — the data-shape group.
588        for kind in [Kind::Plot, Kind::Table] {
589            let flags: Vec<&str> = directives_for(kind).map(|d| d.cli_flag).collect();
590            for required in ["--over", "--by", "--where", "--agg", "--metric"] {
591                assert!(
592                    flags.contains(&required),
593                    "{kind:?} missing data-shape flag {required}"
594                );
595            }
596        }
597    }
598
599    #[test]
600    fn directives_for_text_excludes_figure_directives() {
601        let text: Vec<&str> = directives_for(Kind::Text).map(|d| d.cli_flag).collect();
602        assert!(!text.contains(&"--over"));
603        assert!(!text.contains(&"--metric"));
604        assert!(!text.contains(&"--agg"));
605        // But `--label` should apply (text items can carry
606        // a heading title).
607        assert!(text.contains(&"--label"));
608    }
609
610    #[test]
611    fn directive_by_cli_flag_round_trips() {
612        for d in ALL_DIRECTIVES {
613            let found = directive_by_cli_flag(d.cli_flag)
614                .unwrap_or_else(|| panic!("missing {}", d.cli_flag));
615            assert_eq!(found, d);
616            // Stripped form (`foo` vs `--foo`) also resolves.
617            let stripped = d.cli_flag.trim_start_matches("--");
618            let found_stripped = directive_by_cli_flag(stripped)
619                .unwrap_or_else(|| panic!("missing stripped {}", stripped));
620            assert_eq!(found_stripped, d);
621        }
622    }
623
624    #[test]
625    fn directive_by_yaml_keyword_round_trips() {
626        for d in ALL_DIRECTIVES {
627            assert_eq!(directive_by_yaml_keyword(d.yaml_directive), Some(d));
628        }
629        assert_eq!(directive_by_yaml_keyword("nonexistent"), None);
630    }
631
632    #[test]
633    fn closed_sets_are_non_empty_and_sorted_or_explicit() {
634        // PALETTE_NAMES is sorted alphabetically (per
635        // SRD-46 §"Palettes" — stable indexing rule).
636        let mut sorted = PALETTE_NAMES.to_vec();
637        sorted.sort();
638        // PALETTE_NAMES first lists the default `wong`,
639        // then alphabetic — verify the alphabetic suffix.
640        // The SRD explicitly notes "sorted alphabetically
641        // for stable indexing"; we keep `wong` in slot 0
642        // because it's the documented default. The numeric
643        // index = enumerated position.
644        assert!(!PALETTE_NAMES.is_empty());
645        for set in [AGG_FNS, LINE_STYLES, MARKER_SHAPES, AXIS_SCALES] {
646            assert!(!set.is_empty());
647        }
648    }
649
650    #[test]
651    fn style_is_repeatable_other_directives_are_not() {
652        let style = directive_by_cli_flag("--style").unwrap();
653        assert!(style.repeatable, "--style must be repeatable");
654        for d in ALL_DIRECTIVES {
655            if d.cli_flag != "--style" {
656                assert!(!d.repeatable, "{} should not be repeatable", d.cli_flag);
657            }
658        }
659    }
660
661    #[test]
662    fn kind_mask_figures_covers_plot_and_table_only() {
663        let m = KindMask::FIGURES;
664        assert!(m.contains(Kind::Plot));
665        assert!(m.contains(Kind::Table));
666        assert!(!m.contains(Kind::Text));
667        assert!(!m.contains(Kind::File));
668        assert!(!m.contains(Kind::Details));
669    }
670}