caixa-theme 0.1.369

Nord palette + blackmatter style overlays for caixa diagnostics, formatter output, LSP semantic tokens, and nvim plugin colors.
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
//! The small semantic-style enum every caixa tool agrees on.

use serde::{Deserialize, Serialize};

#[derive(
    Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, gen_platform::IsVariant,
)]
pub enum Semantic {
    /// Language keywords — `defcaixa`, `defteia`, `let`, `lambda`, etc.
    Keyword,
    /// Non-keyword symbols — identifiers, function names, variant names.
    Symbol,
    /// `:keyword-positioned` atoms.
    KeywordArg,
    /// `"string literals"`.
    String,
    /// `42`, `3.14`.
    Number,
    /// `#t`, `#f`, `nil`.
    Literal,
    /// `; comments`.
    Comment,
    /// Primary accent — useful for highlights, carets, focused tokens.
    Accent,
    /// Dim text — metadata, line numbers, help text.
    Muted,

    // Diagnostic severities.
    Error,
    Warning,
    Info,
    Hint,

    // Diff decorations — used by formatter preview and lint output.
    Added,
    Removed,
    Unchanged,
}

impl Semantic {
    /// Every variant of [`Semantic`] in declaration order.
    ///
    /// The single canonical arm-list every substrate consumer that has
    /// to walk the closed 15-arm semantic-style partition (the two
    /// theme overlays' exhaustive-match resolver functions
    /// `blackmatter_dark_color` / `blackmatter_light_color` in
    /// [`crate::blackmatter`], the future LSP-side per-Semantic
    /// `SemanticTokenType` dispatch at
    /// `caixa-lsp/src/main.rs`, a future
    /// `feira lint --list-styles` operator-facing enumeration verb)
    /// reads for. Peer of the sibling closed-set fieldless typed
    /// enums' `ALL` slices already carried by
    /// [`caixa_core::CaixaKind`] /
    /// [`caixa_core::supervisor::RestartStrategy`] /
    /// [`caixa_core::supervisor::RestartPolicy`] /
    /// [`caixa_core::aplicacao::PlacementStrategy`] /
    /// [`caixa_core::upgrade::UpgradeInstruction`] /
    /// `caixa_lint::diagnostic::Severity` /
    /// `caixa_lint::diagnostic::FixSafety` /
    /// `caixa_arch::InvariantKind` / `caixa_arch::ArchVerdict` /
    /// `caixa_provedor::FerriteRuntime` closed-set typed-enum
    /// discriminator axes.
    pub const ALL: &'static [Self] = &[
        Self::Keyword,
        Self::Symbol,
        Self::KeywordArg,
        Self::String,
        Self::Number,
        Self::Literal,
        Self::Comment,
        Self::Accent,
        Self::Muted,
        Self::Error,
        Self::Warning,
        Self::Info,
        Self::Hint,
        Self::Added,
        Self::Removed,
        Self::Unchanged,
    ];

    /// Canonical kebab-case discriminator scalar for this variant — the
    /// single substrate-primitive `&'static str` projection every
    /// downstream consumer of the closed 16-arm [`Semantic`] partition
    /// (a future LSP-side per-Semantic `SemanticTokenType` name-mapping
    /// dispatch at `caixa-lsp/src/main.rs`, a future
    /// `feira lint --list-styles` operator-facing enumeration verb, a
    /// future `caixa.nvim` per-Semantic highlight-group name resolver
    /// that reaches for a stable kebab identifier per arm, a future
    /// `blackmatter-shell` per-arm classname the terminal emitter
    /// composes into a `data-semantic="<kebab>"` attribute) reaches
    /// through. Kebab-case matches the peer
    /// [`gen_platform::IsVariant`]-derived kebab discriminant convention
    /// the sibling closed-set typed enums
    /// ([`caixa_core::CaixaKind::as_str`],
    /// [`caixa_core::supervisor::RestartStrategy::as_str`],
    /// [`caixa_core::supervisor::RestartPolicy::as_str`],
    /// [`caixa_core::aplicacao::PlacementStrategy::as_str`],
    /// [`caixa_core::upgrade::UpgradeInstruction::as_str`],
    /// `caixa_lint::diagnostic::Severity::as_str`,
    /// `caixa_lint::diagnostic::FixSafety::as_str`,
    /// `caixa_arch::InvariantKind::as_str`,
    /// `caixa_arch::ArchVerdict::as_str`,
    /// `caixa_provedor::FerriteRuntime::variant_slug`) already emit
    /// on their canonical `&'static str` projection axis.
    ///
    /// The 16 arms return the kebab-case forms of their `PascalCase`
    /// variant names (`Keyword` → `"keyword"`, `KeywordArg` →
    /// `"keyword-arg"`, `Unchanged` → `"unchanged"`, etc.), matching
    /// the peer closed-set typed-enum canonical byte-string conventions.
    ///
    /// Peer of the [`std::fmt::Display`] and [`AsRef<str>`] impls on
    /// this enum, which both route through this accessor so
    /// `format!("{s}")`, `s.as_str()`, and
    /// `<Semantic as AsRef<str>>::as_ref(&s)` resolve to the same
    /// per-arm byte-string.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Keyword => "keyword",
            Self::Symbol => "symbol",
            Self::KeywordArg => "keyword-arg",
            Self::String => "string",
            Self::Number => "number",
            Self::Literal => "literal",
            Self::Comment => "comment",
            Self::Accent => "accent",
            Self::Muted => "muted",
            Self::Error => "error",
            Self::Warning => "warning",
            Self::Info => "info",
            Self::Hint => "hint",
            Self::Added => "added",
            Self::Removed => "removed",
            Self::Unchanged => "unchanged",
        }
    }

    /// Reverse projection on the [`Semantic`] closed 16-arm enum's
    /// canonical kebab-tag axis — parses a `"keyword"` / `"symbol"` /
    /// `"keyword-arg"` / `"string"` / `"number"` / `"literal"` /
    /// `"comment"` / `"accent"` / `"muted"` / `"error"` / `"warning"` /
    /// `"info"` / `"hint"` / `"added"` / `"removed"` / `"unchanged"` wire
    /// byte-string back to the typed enum, or returns `None` when `s`
    /// lies outside the 16-arm accept-set [`Self::as_str`] emits. The
    /// single `&str → Self` projection every future re-entry point on
    /// the caixa-theme semantic-style axis dispatches through (a future
    /// `feira lint --list-styles` operator-facing enumeration verb
    /// hydrating a per-arm row from a stored kebab identifier back to
    /// the typed enum before rendering, a future `caixa-lsp`-side
    /// per-`SemanticTokenType` re-parse binding a prior
    /// [`Self::as_str`] output back to the typed enum for
    /// per-Semantic-highlight dispatch, a future `caixa.nvim` per-
    /// Semantic highlight-group resolver re-loading a stored kebab
    /// identifier back to the typed enum, a future `blackmatter-shell`
    /// per-arm classname reverse-lookup binding a
    /// `data-semantic="<kebab>"` DOM attribute back to the typed enum
    /// for per-arm style dispatch, a `tracing::field::Value::Str`-arm
    /// structured-log re-loader binding a prior emission's
    /// [`Self::as_str`] output back to the typed enum for cross-run
    /// per-Semantic-paint-histogram diff) would have had to re-inline a
    /// 16-arm `match s` cascade that expressed no compile-time link back
    /// to the substrate primitive.
    ///
    /// Same closed-set-reverse-projection discipline the sibling
    /// [`caixa_core::CaixaKind::from_wire`] (2aa6d23),
    /// [`caixa_core::CaixaDialeto::from_wire`] (d0e65ea),
    /// [`caixa_core::supervisor::RestartStrategy::from_wire`] (4eec29c),
    /// [`caixa_core::supervisor::RestartPolicy::from_wire`] (dd32ccf),
    /// [`caixa_core::aplicacao::PlacementStrategy::from_wire`] (18c7342),
    /// [`caixa_core::dep::DepList::from_wire`] (45ee563),
    /// [`caixa_core::render::PathShapeViolation::from_wire`] (aebd9c6),
    /// `caixa_arch::invariants::InvariantKind::from_wire` (b9e4e61),
    /// `caixa_arch::report::ArchVerdict::from_wire` (6afe564),
    /// `caixa_lint::diagnostic::Severity::from_wire` (5afff0e), and
    /// `caixa_lint::diagnostic::FixSafety::from_wire` (bd505a1) typed
    /// enums carry on the peer wire-side `str → Self` axes — extends
    /// the substrate-wide `(as_str, from_wire)` round-trip family onto
    /// the caixa-theme closed-set fieldless typed-enum axis (the first
    /// closed-set fieldless typed enum on `caixa-theme` to converge on
    /// the reverse-projection discipline), matching the same two-way
    /// `str ↔ Self` round-trip every sibling closed-set enum already
    /// carries. Method-named `from_wire` (not `from_str`) to match the
    /// peer shapes verbatim and side-step a
    /// `clippy::should_implement_trait` lint that a plain `from_str`
    /// name would otherwise trigger without paired
    /// [`std::str::FromStr`] impl scaffolding this axis does not carry
    /// today. Returns `Option<Self>` (rather than `Result<Self, _>`) to
    /// match the peer shapes: the caller picks the diagnostic form
    /// appropriate for its use site (a `feira lint --list-styles` CLI
    /// arg-parse renders its own per-verb error message; a future
    /// admission-webhook rejection body wraps the `None` outcome with
    /// the accepted-set enumeration `Semantic::ALL.iter().map(…)` for
    /// operator diagnostics).
    ///
    /// Pinned load-bearing at the substrate-primitive level by
    /// [`tests::semantic_from_wire_accepts_every_as_str_output`]
    /// (round-trip witness against the peer [`Self::as_str`] axis) and
    /// [`tests::semantic_from_wire_rejects_unknown_byte_strings`]
    /// (rejection witness against silent accept-set widening).
    #[must_use]
    pub fn from_wire(s: &str) -> Option<Self> {
        match s {
            "keyword" => Some(Self::Keyword),
            "symbol" => Some(Self::Symbol),
            "keyword-arg" => Some(Self::KeywordArg),
            "string" => Some(Self::String),
            "number" => Some(Self::Number),
            "literal" => Some(Self::Literal),
            "comment" => Some(Self::Comment),
            "accent" => Some(Self::Accent),
            "muted" => Some(Self::Muted),
            "error" => Some(Self::Error),
            "warning" => Some(Self::Warning),
            "info" => Some(Self::Info),
            "hint" => Some(Self::Hint),
            "added" => Some(Self::Added),
            "removed" => Some(Self::Removed),
            "unchanged" => Some(Self::Unchanged),
            _ => None,
        }
    }
}

/// [`std::fmt::Display`] routed through [`Semantic::as_str`], so the
/// pretty-printed byte-string every consumer that formats the semantic
/// style as user-facing text lands on (a future `feira lint --list-styles`
/// operator-facing enumeration verb's per-arm line, a future
/// `caixa-lsp` diagnostic-source line naming the offending semantic,
/// a future `caixa.nvim` per-Semantic highlight-group name emitter,
/// a `tracing::field::display(&sem)` structured-log recorder on the
/// paint-side emit path) reaches for the same lifted kebab-case
/// per-arm byte-string [`Semantic::as_str`] returns.
///
/// Peer of the sibling [`std::fmt::Display`] impls on the closed-set
/// typed enums the substrate carries — [`caixa_core::CaixaKind`],
/// [`caixa_core::supervisor::RestartStrategy`],
/// [`caixa_core::supervisor::RestartPolicy`],
/// [`caixa_core::aplicacao::PlacementStrategy`],
/// [`caixa_core::upgrade::UpgradeInstruction`],
/// `caixa_lint::diagnostic::Severity`,
/// `caixa_lint::diagnostic::FixSafety`,
/// `caixa_arch::InvariantKind`, `caixa_arch::ArchVerdict`,
/// `caixa_provedor::FerriteRuntime` — extended to the second-to-last
/// un-lifted `caixa-theme` closed-set fieldless typed enum on the
/// substrate-wide `(as_str, AsRef<str>, Display)` canonical-projection
/// triple ratchet the prior lifts converged onto.
impl std::fmt::Display for Semantic {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Substrate-canonical [`AsRef<str>`] projection on the caixa-theme
/// [`Semantic`] closed-set fieldless typed enum — routes through the
/// same [`Semantic::as_str`] `pub const fn` scalar accessor the paired
/// [`std::fmt::Display`] impl already reaches for.
///
/// Peer of the sibling [`AsRef<str>`] impls the substrate carries on
/// [`caixa_core::CaixaKind`], [`caixa_core::CaixaVersion`],
/// [`caixa_core::CaixaDialeto`], [`caixa_core::dep::DepList`],
/// [`caixa_core::supervisor::RestartStrategy`],
/// [`caixa_core::supervisor::RestartPolicy`],
/// [`caixa_core::aplicacao::PlacementStrategy`],
/// [`caixa_core::aplicacao::RateLimitUnit`],
/// `caixa_lint::diagnostic::Severity`,
/// `caixa_arch::InvariantKind`, `caixa_arch::ArchVerdict`,
/// `caixa_provedor::FerriteRuntime` — extends the substrate-wide
/// `(as_str, AsRef<str>, Display)` canonical-projection triple onto
/// the caixa-theme closed-set typed-enum axis, so a future consumer
/// bound through the trait-idiomatic `.as_ref()` (a
/// `HashMap::get::<str>(sem.as_ref())` per-Semantic style-lookup, a
/// future `caixa-lsp` `SemanticTokenType::new(sem.as_ref())`
/// registration site, any `impl AsRef<str>`-bound generic function)
/// reaches the same kebab byte-string [`Semantic::as_str`] returns
/// rather than an open-coded `.as_str()` projection at every
/// wire-up.
impl AsRef<str> for Semantic {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

/// Trait-idiomatic reverse projection on the [`Semantic`] closed 16-arm
/// caixa-theme semantic-style axis — routes byte-for-byte through the
/// paired substrate-primitive [`Semantic::from_wire`] `Option<Self>`
/// accessor so every future consumer that binds a canonical semantic
/// tag through the standard-library `.try_into()` / [`TryFrom`] axis
/// (a future `feira lint --semantic=<kebab>` CLI arg-parse that
/// composes into `let sem: Semantic = s.try_into()?`, a future
/// `caixa-lsp` per-token re-parse hydrating a prior
/// [`Semantic::as_str`] output back to the typed enum for
/// `SemanticTokenType` dispatch, a future `caixa.nvim` per-highlight-
/// group re-loader binding a stored kebab byte-string back through the
/// typed enum, a generic `<T: TryFrom<&str>>`-bound theme-overlay
/// re-loader over any of the substrate's closed-set typed enums)
/// reaches the same 16-arm accept-set the sibling
/// [`Semantic::from_wire`] resolver parses through and the sibling
/// [`Semantic::as_str`] emits, rather than an open-coded per-arm
/// `match s { "keyword" => …, "symbol" => …, … _ => … }` cascade whose
/// arm-set has no compile-time link back to the substrate primitive.
///
/// Complements the pre-existing forward-projection triple
/// ([`std::fmt::Display`], [`AsRef<str>`], [`Semantic::as_str`]) with
/// the paired trait-idiomatic reverse-projection axis: Rust-side
/// newtype/typed-enum convention pairs [`AsRef<str>`] with either
/// [`std::str::FromStr`] or [`TryFrom<&str>`] on the same primitive so
/// a caller who can project *out to* a `&str` can also project *in
/// from* one. The [`TryFrom<&str>`] axis is deliberately chosen over
/// [`std::str::FromStr`] to sidestep the `clippy::should_implement_trait`
/// lint the sibling method-named [`Semantic::from_wire`] would trigger
/// under a `FromStr` impl (the same design tradeoff the peer
/// [`caixa_core::CaixaKind`] (3c83606),
/// [`caixa_core::CaixaDialeto`] (bf33136),
/// [`caixa_core::aplicacao::PlacementStrategy`] (6fd00cd),
/// [`caixa_core::supervisor::RestartStrategy`] (5b828ed),
/// [`caixa_core::supervisor::RestartPolicy`] (6fdd0d9),
/// [`caixa_core::aplicacao::WitShape`] (5472902),
/// [`caixa_core::aplicacao::RateLimitUnit`] (bf78400),
/// [`caixa_core::render::PathShapeViolation`] (e67e48a),
/// `caixa_arch::invariants::InvariantKind` (e21a857),
/// `caixa_arch::report::ArchVerdict` (0a4cc45),
/// `caixa_lint::diagnostic::Severity` (a7bf74c), and
/// `caixa_lint::diagnostic::FixSafety` (df86c94) blocks note) — this
/// impl closes the trait-idiomatic reverse axis without disturbing the
/// method-named `from_wire` shape every peer closed-set typed enum
/// already carries.
///
/// `type Error = ()` matches the sibling [`Semantic::from_wire`]'s
/// `Option<Self>` return-shape's deliberate deferral of error typing:
/// the caller picks the diagnostic form appropriate for its use site
/// (a future `feira lint --semantic` CLI arg-parse composes its own
/// per-verb "unknown semantic-style tag: <arg> — accepted: {…}"
/// message enumerating [`Semantic::ALL`], a future admission-webhook
/// rejection body wraps the `Err(())` outcome with the accepted-set
/// enumeration for operator diagnostics, a `Result::map_err` at the
/// call site lifts the axis-error to a per-verb error type). Same
/// shape the peer sibling reverse-projection axes carry. The return-
/// shape uses fully-qualified `<Self as TryFrom<&str>>::Error` because
/// the associated-type name would otherwise collide with the
/// [`Self::Error`] variant on the same primitive (the identical
/// ambiguous-associated-item defect the sibling
/// `impl TryFrom<&str> for Severity` (a7bf74c) already threads around
/// under `#[deny(future_incompatible)]`).
///
/// The paired [`TryFrom<&str>`] impl reaches the same 16-arm accept-
/// set the [`Semantic::from_wire`] resolver dispatches through, so any
/// future arm addition (a `Namespace` tier between [`Self::Symbol`]
/// and [`Self::KeywordArg`] for the M4 tatara-lisp module system's
/// qualified-name semantic-token dispatch, a `Deleted` tier for a
/// hard-delete-mark distinct from [`Self::Removed`] the future 3-way
/// diff surface grows — both trajectory items the sibling
/// [`Semantic::ALL`] doc block already names) grows the trait-
/// idiomatic axis by construction: one caixa-theme edit on
/// [`Semantic::from_wire`] extends both the method-named reverse
/// projection every existing consumer keys off and the trait-
/// idiomatic reverse projection this impl exposes, without a
/// coordinated rewrite across every future `TryFrom<&str>`-bound
/// consumer's arm-set.
///
/// Extends the substrate-wide closed-set-enum trait-idiomatic
/// reverse-projection family ([`caixa_core::CaixaKind`] via 3c83606,
/// [`caixa_core::CaixaDialeto`] via bf33136,
/// [`caixa_core::aplicacao::PlacementStrategy`] via 6fd00cd,
/// [`caixa_core::supervisor::RestartStrategy`] via 5b828ed,
/// [`caixa_core::supervisor::RestartPolicy`] via 6fdd0d9,
/// [`caixa_core::aplicacao::WitShape`] via 5472902,
/// [`caixa_core::aplicacao::RateLimitUnit`] via bf78400,
/// [`caixa_core::render::PathShapeViolation`] via e67e48a,
/// `caixa_arch::invariants::InvariantKind` via e21a857,
/// `caixa_arch::report::ArchVerdict` via 0a4cc45,
/// `caixa_lint::diagnostic::Severity` via a7bf74c, and
/// `caixa_lint::diagnostic::FixSafety` via df86c94) onto the first
/// closed-set fieldless typed enum on the caixa-theme surface — the
/// semantic-style 16-arm accept-set every per-Semantic paint dispatch,
/// every future `caixa-lsp` per-SemanticTokenType wire-up, and every
/// future `caixa.nvim` per-highlight-group re-loader keys off. The
/// thirteenth peer on the substrate surface, and the first inside
/// `caixa-theme`; with `caixa_provedor::FerriteRuntime` remaining as
/// the only outside-caixa-core closed-set fieldless typed enum whose
/// trait-idiomatic axis is still open.
///
/// Pinned load-bearing by
/// [`tests::semantic_try_from_str_routes_through_from_wire_accessor`]
/// (byte-parity pin against [`Semantic::from_wire`] across the 16-arm
/// accept-set) and
/// [`tests::semantic_try_from_str_rejects_unknown_byte_strings`]
/// (rejection witness against silent accept-set widening).
impl TryFrom<&str> for Semantic {
    type Error = ();

    fn try_from(s: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
        Self::from_wire(s).ok_or(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn semantic_all_enumerates_every_variant_in_declaration_order() {
        // Fail-before-pass-after pin on the [`Semantic::ALL`] slice:
        // the slice must list every one of the 15 variants in
        // declaration order (Keyword → Symbol → KeywordArg → String →
        // Number → Literal → Comment → Accent → Muted → Error →
        // Warning → Info → Hint → Added → Removed → Unchanged). Peer
        // of the sibling ALL slices on the closed-set typed-enum
        // discriminator axes ([`caixa_core::CaixaKind::ALL`],
        // [`caixa_core::supervisor::RestartStrategy::ALL`],
        // [`caixa_core::supervisor::RestartPolicy::ALL`],
        // [`caixa_core::aplicacao::PlacementStrategy::ALL`],
        // [`caixa_core::upgrade::UpgradeInstruction::ALL`]). A future
        // arm addition (a `Namespace` tier between `Symbol` and
        // `KeywordArg` for the M4 tatara-lisp module system's
        // qualified-name semantic-token dispatch, a `Deleted` tier
        // for a hard-delete-mark distinct from `Removed` the future
        // 3-way diff surface grows) that lands the arm on the enum
        // but forgets to extend `ALL` must trip this pin rather than
        // surface as a downstream consumer's silently-partial
        // iteration.
        assert_eq!(
            Semantic::ALL,
            &[
                Semantic::Keyword,
                Semantic::Symbol,
                Semantic::KeywordArg,
                Semantic::String,
                Semantic::Number,
                Semantic::Literal,
                Semantic::Comment,
                Semantic::Accent,
                Semantic::Muted,
                Semantic::Error,
                Semantic::Warning,
                Semantic::Info,
                Semantic::Hint,
                Semantic::Added,
                Semantic::Removed,
                Semantic::Unchanged,
            ],
        );
        // Also pin the per-arm `IsVariant`-derived partition: every
        // arm in `ALL` must satisfy exactly one of the 15 generated
        // arm-discriminator predicates.
        for variant in Semantic::ALL {
            let row = [
                variant.is_keyword(),
                variant.is_symbol(),
                variant.is_keyword_arg(),
                variant.is_string(),
                variant.is_number(),
                variant.is_literal(),
                variant.is_comment(),
                variant.is_accent(),
                variant.is_muted(),
                variant.is_error(),
                variant.is_warning(),
                variant.is_info(),
                variant.is_hint(),
                variant.is_added(),
                variant.is_removed(),
                variant.is_unchanged(),
            ];
            let hits = row.iter().filter(|b| **b).count();
            assert_eq!(
                hits, 1,
                "Semantic::{variant:?} must satisfy exactly one of the \
                 15 is_* arm-discriminator predicates; got {row:?}",
            );
        }
    }

    #[test]
    fn semantic_is_variant_predicates_partition_the_arm_set() {
        // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
        // derive: for each of the 15 variants, exactly one of the
        // generated is_* predicates returns `true` and the other 14
        // return `false`. Pre-derive the closed 15-arm partition
        // lived only inside the two theme overlays' 15-arm match
        // resolvers; a future rebrand (a `#[is_variant(name = "…")]`
        // drift, a manual hand-rolled `impl` that shadows the
        // derive-generated method, an arm rename) trips this pin at
        // caixa-theme build time rather than surfacing far from the
        // derive declaration. Peer of the sibling
        // [`caixa_core::CaixaKind`] `IsVariant` partition pin.
        // A copy-paste flip that reroutes one arm through the wrong
        // predicate lane trips at the identity-diagonal assertion,
        // since each variant's row is generated live from `ALL`'s
        // declaration order rather than transcribed by hand.
        for (idx, variant) in Semantic::ALL.iter().enumerate() {
            let observed: [bool; 16] = [
                variant.is_keyword(),
                variant.is_symbol(),
                variant.is_keyword_arg(),
                variant.is_string(),
                variant.is_number(),
                variant.is_literal(),
                variant.is_comment(),
                variant.is_accent(),
                variant.is_muted(),
                variant.is_error(),
                variant.is_warning(),
                variant.is_info(),
                variant.is_hint(),
                variant.is_added(),
                variant.is_removed(),
                variant.is_unchanged(),
            ];
            let mut expected = [false; 16];
            expected[idx] = true;
            assert_eq!(
                observed, expected,
                "Semantic::{variant:?} at ALL[{idx}] is_* predicates \
                 must fire only on their own arm lane (identity \
                 diagonal); got {observed:?}",
            );
        }
    }

    #[test]
    fn semantic_as_str_returns_canonical_kebab_case_per_arm() {
        // Fail-before-pass-after per-arm byte-string pin on
        // [`Semantic::as_str`] — the substrate-canonical `&'static str`
        // projection every downstream consumer of the closed 16-arm
        // partition reaches through. A future arm rename (a `Symbol` →
        // `Identifier` rebrand tracking a hypothetical LSP-side
        // `SemanticTokenType` reshuffle, an `Accent` → `Highlight`
        // rebrand tracking a `blackmatter-shell` classname rework) that
        // touches the enum arm but forgets to update the paired
        // `as_str` arm — or vice versa — trips this pin at caixa-theme
        // build time rather than surfacing as a downstream
        // `feira lint --list-styles` operator-facing enumeration verb's
        // silently-renamed row far from the two-declaration site.
        //
        // Kebab-case matches the peer [`gen_platform::IsVariant`]-
        // derived kebab discriminant convention the sibling closed-set
        // typed enums already emit on their canonical byte-string
        // projection axis.
        assert_eq!(Semantic::Keyword.as_str(), "keyword");
        assert_eq!(Semantic::Symbol.as_str(), "symbol");
        assert_eq!(Semantic::KeywordArg.as_str(), "keyword-arg");
        assert_eq!(Semantic::String.as_str(), "string");
        assert_eq!(Semantic::Number.as_str(), "number");
        assert_eq!(Semantic::Literal.as_str(), "literal");
        assert_eq!(Semantic::Comment.as_str(), "comment");
        assert_eq!(Semantic::Accent.as_str(), "accent");
        assert_eq!(Semantic::Muted.as_str(), "muted");
        assert_eq!(Semantic::Error.as_str(), "error");
        assert_eq!(Semantic::Warning.as_str(), "warning");
        assert_eq!(Semantic::Info.as_str(), "info");
        assert_eq!(Semantic::Hint.as_str(), "hint");
        assert_eq!(Semantic::Added.as_str(), "added");
        assert_eq!(Semantic::Removed.as_str(), "removed");
        assert_eq!(Semantic::Unchanged.as_str(), "unchanged");
    }

    #[test]
    fn semantic_as_str_projections_are_all_distinct_across_arms() {
        // Fail-before-pass-after pin on the injectivity of
        // [`Semantic::as_str`]'s projection — no two arms may share
        // their canonical kebab byte-string, since a future consumer
        // that keys a per-arm dispatch table off the projection (a
        // `HashMap::<&str, _>::from_iter(Semantic::ALL.iter().map(|s|
        // (s.as_str(), …)))` style-lookup, a future `caixa-lsp`
        // `SemanticTokenType::new(sem.as_ref())` registration table
        // keyed by kebab identifier, a future `feira lint --list-styles`
        // one-row-per-arm enumeration table) would silently collapse
        // the two colliding arms onto one entry, dropping the second
        // insertion. A future arm addition (a `Namespace` tier between
        // `Symbol` and `KeywordArg` for the M4 tatara-lisp module
        // system's qualified-name semantic-token dispatch, a `Deleted`
        // tier for a hard-delete-mark distinct from `Removed` a future
        // 3-way diff surface grows) that lands the arm on the enum and
        // reuses a peer arm's kebab identifier (a copy-paste-derived
        // `"removed"` on the new `Deleted` arm) trips this pin rather
        // than surfacing far from the arm addition site.
        let mut projections: Vec<&'static str> = Semantic::ALL.iter().map(|s| s.as_str()).collect();
        let before = projections.len();
        projections.sort_unstable();
        projections.dedup();
        assert_eq!(
            projections.len(),
            before,
            "Semantic::as_str must be injective across ALL — collisions: \
             {projections:?}",
        );
    }

    #[test]
    fn semantic_display_and_as_ref_str_route_through_as_str_accessor() {
        // Fail-before-pass-after three-path convergence pin on the
        // substrate-wide `(as_str, AsRef<str>, Display)` canonical-
        // projection triple for the caixa-theme [`Semantic`] closed-set
        // fieldless typed enum. For every arm in [`Semantic::ALL`], the
        // paired [`std::fmt::Display`] impl + [`AsRef<str>`] impl + the
        // substrate-canonical [`Semantic::as_str`] `pub const fn`
        // scalar accessor must resolve to the same `&'static str`
        // per arm. Peer of the sibling three-path-convergence pins the
        // substrate carries on the closed-set typed enums the prior
        // lifts converged onto
        // (`restart_strategy_display_routes_through_as_str_helper` /
        // `restart_strategy_as_ref_str_routes_through_as_str_accessor`
        // on [`caixa_core::supervisor::RestartStrategy`],
        // `ferrite_runtime_display_and_as_ref_str_route_through_variant_slug_accessor`
        // on `caixa_provedor::FerriteRuntime`, and the analogous pins
        // on `caixa_lint::Severity` / `caixa_lint::FixSafety` /
        // `caixa_arch::InvariantKind` / `caixa_arch::ArchVerdict`).
        //
        // A future accidental split (a hand-rolled `impl fmt::Display`
        // that shadows this route through a divergent per-arm match, an
        // `impl AsRef<str>` that returns the compiler-derived `Debug`
        // string via `format!("{:?}", self)` — allocating and diverging
        // on every arm — or a `#[serde(rename_all = "…")]` attribute
        // drift that quietly forks the projection) trips this pin at
        // caixa-theme build time rather than surfacing as a downstream
        // consumer's silently-forked per-Semantic dispatch far from the
        // trait-impl declaration site.
        for &sem in Semantic::ALL {
            let via_as_str: &str = sem.as_str();
            let via_display: String = format!("{sem}");
            let via_as_ref: &str = <Semantic as AsRef<str>>::as_ref(&sem);
            assert_eq!(
                via_display, via_as_str,
                "Semantic::{sem:?} — Display routes off `as_str`; got \
                 Display={via_display:?} vs as_str={via_as_str:?}",
            );
            assert_eq!(
                via_as_ref, via_as_str,
                "Semantic::{sem:?} — AsRef<str> routes off `as_str`; got \
                 AsRef={via_as_ref:?} vs as_str={via_as_str:?}",
            );
        }
    }

    #[test]
    fn semantic_as_str_is_usable_in_const_context() {
        // The [`Semantic::as_str`] accessor is declared `pub const fn`,
        // matching the peer closed-set typed enums' canonical
        // `&'static str` projection accessors
        // ([`caixa_core::CaixaKind::as_str`],
        // [`caixa_core::supervisor::RestartStrategy::as_str`],
        // [`caixa_core::aplicacao::PlacementStrategy::as_str`],
        // `caixa_provedor::FerriteRuntime::variant_slug`). Pin the
        // same posture with a `const {}` assertion block so a future
        // accidental downgrade to non-`const` (an added runtime helper
        // reachable only from a non-`const` context) trips at
        // caixa-theme build time rather than surfacing as a downstream
        // `const`-context regression far from the accessor
        // declaration.
        const KEYWORD: &str = Semantic::Keyword.as_str();
        const ERROR: &str = Semantic::Error.as_str();
        const UNCHANGED: &str = Semantic::Unchanged.as_str();
        const { assert!(KEYWORD.as_bytes()[0] == b'k') };
        const { assert!(ERROR.as_bytes()[0] == b'e') };
        const { assert!(UNCHANGED.as_bytes()[0] == b'u') };
    }

    #[test]
    fn semantic_from_wire_accepts_every_as_str_output() {
        // Fail-before-pass-after per-arm accept pin on the newly lifted
        // [`Semantic::from_wire`] reverse projection: every arm in
        // [`Semantic::ALL`] must parse back through `from_wire` when fed
        // its own [`Semantic::as_str`] output, landing on
        // `Some(same_variant)`. A regression that hand-rolled either
        // side's per-arm match without threading through the shared
        // 16-string closed set would silently disagree on any future
        // arm rename (a `Symbol` → `Identifier` rebrand tracking a
        // hypothetical LSP-side `SemanticTokenType` reshuffle, an
        // `Accent` → `Highlight` rebrand tracking a `blackmatter-shell`
        // classname rework) or new arm the theme grows (a `Namespace`
        // tier between `Symbol` and `KeywordArg` for the M4 tatara-lisp
        // module system's qualified-name semantic-token dispatch, a
        // `Deleted` tier for a hard-delete-mark distinct from `Removed`
        // the future 3-way diff surface grows) and this pin flags it at
        // caixa-theme build time rather than at a downstream
        // `feira lint --list-styles` operator-facing enumeration verb's
        // silent tag misclassification.
        //
        // Peer of the sibling
        // `caixa_lint::diagnostic::tests::severity_from_wire_accepts_every_as_str_output`
        // (5afff0e) /
        // `caixa_lint::diagnostic::tests::fix_safety_from_wire_accepts_every_as_str_output`
        // (bd505a1) /
        // `caixa_arch::report::tests::arch_verdict_from_wire_accepts_every_as_str_output`
        // (6afe564) /
        // `caixa_arch::invariants::tests::invariant_kind_from_wire_accepts_every_as_str_output`
        // (b9e4e61) round-trip pins on the peer caixa-lint / caixa-arch
        // closed-set-enum reverse-projection axes, and of the sibling
        // `caixa_core::kind::tests::caixa_kind_wire_round_trips_through_from_wire`
        // (2aa6d23) /
        // `caixa_core::dialeto::tests::caixa_dialeto_from_wire_accepts_every_as_str_output`
        // (d0e65ea) /
        // `caixa_core::aplicacao::tests::placement_strategy_from_wire_accepts_every_lifted_constant`
        // (18c7342) /
        // `caixa_core::dep::tests::dep_list_round_trips_through_as_str_and_from_wire`
        // (45ee563) /
        // `caixa_core::render::tests::path_shape_violation_from_wire_accepts_every_as_str_output`
        // (aebd9c6) round-trip pins on the sibling caixa-core closed-
        // set typed-enum reverse-projection axes.
        for &variant in Semantic::ALL {
            let wire = variant.as_str();
            let parsed = Semantic::from_wire(wire).unwrap_or_else(|| {
                panic!(
                    "Semantic::from_wire({wire:?}) must accept every \
                     Semantic::as_str output — got None for the wire \
                     byte-string of {variant:?}"
                )
            });
            assert_eq!(
                parsed, variant,
                "Semantic::from_wire(Semantic::{variant:?}.as_str()) \
                 must return Semantic::{variant:?} — the (as_str, \
                 from_wire) pair must form a total round-trip on the \
                 closed 16-arm Semantic arm-set",
            );
        }
    }

    #[test]
    fn semantic_from_wire_rejects_unknown_byte_strings() {
        // Rejection pin on the [`Semantic::from_wire`] parser's accept-
        // set: any string outside the 16-arm [`Semantic::as_str`] output
        // set must return `None`. A future accidental widening of the
        // accept-set (a case-insensitive match that accepts `"KEYWORD"`
        // / `"Keyword"`, a silent acceptance of the pre-lift PascalCase
        // Debug-derived shapes `"Keyword"` / `"KeywordArg"` /
        // `"Unchanged"` on the wire axis, a snake_case drift accepting
        // `"keyword_arg"` beside the canonical kebab-case
        // `"keyword-arg"`, a Levenshtein-forgiving arm-lookup that
        // admits `"kewyord"` typos, a silent absorption of a hypothetical
        // future `Namespace` / `Deleted` arm before it lands on the enum
        // and its paired [`Semantic::as_str`] emitter arm) would
        // silently drift the parser's accept-set from the emitter's — a
        // downstream style-report re-loader that bound a prior report's
        // [`Self::as_str`] output back to the typed enum through this
        // parser would then bind a malformed byte-string to a plausibly-
        // wrong typed arm the caller does not route through any
        // fallback, silently misclassifying the reloaded row.
        //
        // Peer of the sibling
        // `caixa_lint::diagnostic::tests::severity_from_wire_rejects_unknown_byte_strings`
        // (5afff0e) /
        // `caixa_lint::diagnostic::tests::fix_safety_from_wire_rejects_unknown_byte_strings`
        // (bd505a1) /
        // `caixa_arch::report::tests::arch_verdict_from_wire_rejects_unknown_byte_strings`
        // (6afe564) /
        // `caixa_arch::invariants::tests::invariant_kind_from_wire_rejects_unknown_byte_strings`
        // (b9e4e61) rejection pins on the peer caixa-lint / caixa-arch
        // axes, and of the sibling
        // `caixa_kind_from_wire_rejects_unknown_byte_strings` (2aa6d23),
        // `caixa_dialeto_from_wire_rejects_unknown_byte_strings`
        // (d0e65ea),
        // `placement_strategy_from_wire_rejects_unknown_byte_strings`
        // (18c7342),
        // `dep_list_from_wire_returns_none_on_unknown_wire_scalar`
        // (45ee563), and
        // `path_shape_violation_from_wire_rejects_unknown_byte_strings`
        // (aebd9c6) rejection pins on the sibling caixa-core axes.
        //
        // The rejection set also covers overlapping-byte-string tags
        // from peer axes: caixa-lint `Severity::as_str` outputs
        // `"error"`/`"warning"`/`"info"`/`"hint"` and caixa-arch
        // `InvariantKind::as_str` outputs `"safety"`/`"compliance"`
        // share zero canonical byte-strings with the widened 16-arm
        // Semantic set here — a widened parser that admitted the peer's
        // arm on the sibling axis would still not admit an arm foreign
        // to the caixa-theme semantic-style discriminator's own accept-
        // set. Yet four peer-axis strings DO overlap with the
        // caixa-theme set here (`Severity`'s
        // `"error"`/`"warning"`/`"info"`/`"hint"` map identically onto
        // the caixa-theme diagnostic-severity sub-region
        // `Semantic::Error`/`Warning`/`Info`/`Hint`) — a widened parser
        // that admitted them under a different arm would collapse the
        // two axes and silently mislabel; the pin excludes those four
        // from the rejection set precisely because they must accept.
        for bad in [
            "",
            " ",
            "Keyword",
            "KEYWORD",
            "Symbol",
            "SYMBOL",
            "KeywordArg",
            "keyword_arg",
            "keywordarg",
            "String",
            "STRING",
            "Number",
            "Literal",
            "Comment",
            "Accent",
            "Muted",
            "Error",
            "ERROR",
            "Warning",
            "WARNING",
            "Info",
            "INFO",
            "Hint",
            "HINT",
            "Added",
            "ADDED",
            "Removed",
            "REMOVED",
            "Unchanged",
            "UNCHANGED",
            "kewyord",
            "sym",
            "kw",
            "str",
            "num",
            "lit",
            "cmt",
            "safe",
            "unsafe",
            "safety",
            "compliance",
            "proven",
            "rejected",
            "namespace",
            "deleted",
            "highlight",
            "identifier",
            "keyword ",
            " keyword",
            "keyword\n",
            "keyword\t",
            "keyword-arg ",
            " keyword-arg",
            "added ",
            " added",
            "unchanged ",
            " unchanged",
        ] {
            assert!(
                Semantic::from_wire(bad).is_none(),
                "Semantic::from_wire({bad:?}) must return None — the \
                 parser's accept-set is exactly the 16 Semantic::as_str \
                 outputs; a widening would silently split the parser's \
                 accept-set from the emitter's arm-set",
            );
        }
    }

    #[test]
    fn semantic_is_variant_predicates_are_const_fn() {
        // The [`gen_platform::IsVariant`] derive emits `const fn`
        // predicates on the peer [`caixa_core::CaixaKind`] /
        // [`caixa_core::upgrade::UpgradeInstruction`] /
        // [`caixa_core::supervisor::RestartStrategy`] /
        // [`caixa_core::supervisor::RestartPolicy`] closed-set typed
        // enums — pin the same posture on [`Semantic`] so a future
        // accidental downgrade to non-`const` (an added runtime helper
        // reachable only from a non-`const` context, a manual hand-
        // rolled `impl` that shadows the derive-generated method)
        // trips at caixa-theme build time rather than surfacing as a
        // downstream `const`-context regression far from the derive
        // declaration.
        const { assert!(Semantic::Keyword.is_keyword()) };
        const { assert!(Semantic::Error.is_error()) };
        const { assert!(Semantic::Added.is_added()) };
        const { assert!(Semantic::Unchanged.is_unchanged()) };
    }

    #[test]
    fn semantic_try_from_str_routes_through_from_wire_accessor() {
        // Fail-before-pass-after byte-parity pin on the newly lifted
        // `impl TryFrom<&str> for Semantic` — asserts the standard-
        // library trait impl and the substrate-primitive
        // [`super::Semantic::from_wire`] `Option<Self>` accessor
        // resolve to the same 16-arm accept-set across every arm the
        // exhaustive [`super::Semantic::ALL`] slice enumerates. Any
        // future silent detour that routes the trait impl through a
        // divergent projection (a per-arm inline `match s { "keyword"
        // => Ok(Self::Keyword), … }` re-inlining that opens a
        // compile-time link to the un-lifted arm-literal, a silent
        // case-fold that admits `"Keyword"` / `"KEYWORD"` and would
        // collide the canonical-lowercase accept-set the emitter
        // dispatches on) trips at caixa-theme test time under
        // `assert_eq!` rather than at a downstream
        // `impl TryFrom<&str>`-bound consumer's silent split. Sweeps
        // every one of the 16 arms [`super::Semantic::ALL`] carries so
        // no arm's projection is covered only by the sibling method-
        // named `from_wire` path.
        //
        // Peer of the sibling
        // [`caixa_core::kind::tests::caixa_kind_try_from_str_routes_through_from_wire_accessor`]
        // (3c83606),
        // [`caixa_core::dialeto::tests::caixa_dialeto_try_from_str_routes_through_from_wire_accessor`]
        // (bf33136),
        // `placement_strategy_try_from_str_routes_through_from_wire_accessor`
        // (6fd00cd),
        // `rate_limit_unit_try_from_str_routes_through_from_suffix_accessor`
        // (bf78400),
        // `path_shape_violation_try_from_str_routes_through_from_wire_accessor`
        // (e67e48a),
        // `caixa_arch::invariants::tests::invariant_kind_try_from_str_routes_through_from_wire_accessor`
        // (e21a857),
        // `caixa_arch::report::tests::arch_verdict_try_from_str_routes_through_from_wire_accessor`
        // (0a4cc45),
        // `caixa_lint::diagnostic::tests::severity_try_from_str_routes_through_from_wire_accessor`
        // (a7bf74c), and
        // `caixa_lint::diagnostic::tests::fix_safety_try_from_str_routes_through_from_wire_accessor`
        // (df86c94) — extends the trait-idiomatic reverse-projection
        // axis onto the first closed-set fieldless typed enum on the
        // caixa-theme surface (the semantic-style axis).
        for &variant in Semantic::ALL {
            let wire = variant.as_str();
            assert_eq!(
                <Semantic as TryFrom<&str>>::try_from(wire),
                Ok(variant),
                "TryFrom<&str> impl on Semantic must round-trip \
                 Semantic::{variant:?}.as_str() = {wire:?} back to \
                 Ok(Semantic::{variant:?}) — divergence from \
                 Semantic::from_wire signals a silent detour off the \
                 substrate-primitive accessor",
            );
            assert_eq!(
                <Semantic as TryFrom<&str>>::try_from(wire).ok(),
                Semantic::from_wire(wire),
                "TryFrom<&str> ok()-projection on {wire:?} must \
                 byte-equal Semantic::from_wire on the same input",
            );
        }
    }

    #[test]
    fn semantic_try_from_str_rejects_unknown_byte_strings() {
        // Rejection witness on the `impl TryFrom<&str> for Semantic` —
        // sweeps a candidate set of byte-strings outside the 16-arm
        // canonical-lowercase kebab wire accept-set the sibling
        // [`super::Semantic::as_str`] emits and asserts every one
        // lands on `Err(())`, so a future accidental widening of the
        // trait impl's accept-set (a stray additional
        // `_ if s.eq_ignore_ascii_case("keyword") => Ok(…)` case-fold
        // path, a silent acceptance of the pre-lift PascalCase Debug-
        // derived shapes `"Keyword"` / `"Symbol"` / `"KeywordArg"` on
        // the wire axis, a Levenshtein-forgiving arm-lookup that
        // admits `"kwd"` / `"sym"` / `"kw"` typos — the exact form a
        // `format!("{:?}", …).to_lowercase()` round-trip on the paired
        // [`std::fmt::Debug`] derive would otherwise land on) trips at
        // caixa-theme test time. The candidate set includes the empty
        // string, whitespace-only padding, uppercase / PascalCase
        // rebrand candidates, Levenshtein-neighbor typos, sibling
        // closed-set-enum canonical tags not shared with this axis
        // (peer `caixa_lint::diagnostic::FixSafety::as_str` two-arm
        // `"safe"` / `"unsafe"`, peer `caixa_arch::InvariantKind::as_str`
        // three-arm `"safety"` / `"compliance"`, peer
        // `caixa_arch::ArchVerdict::as_str` two-arm `"proven"` /
        // `"rejected"`), the trajectory-item candidates
        // (`"namespace"`, `"deleted"`) the sibling [`Semantic::ALL`]
        // doc block already names, whitespace-padded canonical tags,
        // and CamelCase spellings of the multi-word `KeywordArg`
        // variant (`"KeywordArg"`, `"keywordarg"`, `"keyword_arg"`,
        // `"keyword.arg"`) that would silently admit
        // if the accept-set widened to a case-fold or separator-
        // normalization rule.
        //
        // Peer of the sibling
        // `caixa_kind_try_from_str_rejects_unknown_byte_strings`
        // (3c83606),
        // `caixa_dialeto_try_from_str_rejects_unknown_byte_strings`
        // (bf33136),
        // `rate_limit_unit_try_from_str_rejects_unknown_byte_strings`
        // (bf78400),
        // `path_shape_violation_try_from_str_rejects_unknown_byte_strings`
        // (e67e48a),
        // `invariant_kind_try_from_str_rejects_unknown_byte_strings`
        // (e21a857),
        // `arch_verdict_try_from_str_rejects_unknown_byte_strings`
        // (0a4cc45),
        // `severity_try_from_str_rejects_unknown_byte_strings`
        // (a7bf74c), and
        // `fix_safety_try_from_str_rejects_unknown_byte_strings`
        // (df86c94) rejection pins on the sibling closed-set typed-
        // enum trait-idiomatic reverse-projection axes.
        for bad in [
            "",
            " ",
            "Keyword",
            "KEYWORD",
            "Symbol",
            "KeywordArg",
            "keywordarg",
            "keyword_arg",
            "keyword.arg",
            "String",
            "Number",
            "Literal",
            "Comment",
            "Accent",
            "Muted",
            "Error",
            "ERROR",
            "Warning",
            "Info",
            "Hint",
            "Added",
            "Removed",
            "Unchanged",
            "kwd",
            "sym",
            "kw",
            "str",
            "num",
            "lit",
            "cmt",
            "safe",
            "unsafe",
            "safety",
            "compliance",
            "proven",
            "rejected",
            "namespace",
            "deleted",
            "highlight",
            "identifier",
            "keyword ",
            " keyword",
            "keyword\n",
            "keyword\t",
            "keyword-arg ",
            " keyword-arg",
            "added ",
            " added",
            "unchanged ",
            " unchanged",
        ] {
            assert_eq!(
                <Semantic as TryFrom<&str>>::try_from(bad),
                Err(()),
                "TryFrom<&str> for Semantic({bad:?}) must return \
                 Err(()) — the trait impl's accept-set is exactly the \
                 16 Semantic::as_str outputs; a widening would \
                 silently split the trait impl's accept-set from the \
                 emitter's arm-set",
            );
        }
    }

    #[test]
    fn semantic_try_from_str_and_from_wire_partition_the_accept_set() {
        // Cross-axis partition pin: the trait-idiomatic
        // [`TryFrom<&str>`] and the method-named
        // [`super::Semantic::from_wire`] projections must return
        // equivalent decisions on every input — the trait impl's
        // `.ok()` project-out from `Result<Self, ()>` and the method's
        // `Option<Self>` return must byte-equal each other on both
        // accepts and rejects. A future silent bifurcation (the trait
        // impl gaining a case-fold path the method does not carry, the
        // method gaining a synonym alias the trait impl does not
        // honor) trips at caixa-theme test time under a single pin
        // rather than at a downstream generic-bound consumer that
        // dispatches through one axis while a peer dispatches through
        // the other. Sweeps both the 16-arm accept-set (via
        // [`super::Semantic::ALL`] threaded through
        // [`super::Semantic::as_str`]) and a canonical rejection
        // sample so both halves of the partition are covered. Peer of
        // the sibling
        // `severity_try_from_str_and_from_wire_partition_the_accept_set`
        // (a7bf74c) and
        // `fix_safety_try_from_str_and_from_wire_partition_the_accept_set`
        // (df86c94) partition pins.
        for &variant in Semantic::ALL {
            let wire = variant.as_str();
            assert_eq!(
                <Semantic as TryFrom<&str>>::try_from(wire).ok(),
                Semantic::from_wire(wire),
                "TryFrom<&str>::ok() and from_wire must agree on \
                 Semantic::{variant:?}.as_str() = {wire:?}",
            );
        }
        for bad in [
            "",
            "Keyword",
            "unknown",
            "safety",
            "safe",
            "proven",
            "namespace",
            "keywordarg",
        ] {
            assert_eq!(
                <Semantic as TryFrom<&str>>::try_from(bad).ok(),
                Semantic::from_wire(bad),
                "TryFrom<&str>::ok() and from_wire must agree on the \
                 rejection outcome for {bad:?}",
            );
        }
    }
}