Skip to main content

caixa_core/
dialeto.rs

1//! `defcaixa` is spoken by two unrelated declarations. This module makes that
2//! a **typed fact** instead of an anonymous parse failure.
3//!
4//! # The finding
5//!
6//! Measured 2026-07-31 over the pleme-io org checkout (270 `caixa.lisp` /
7//! `*.caixa.lisp` files found with `rg --no-ignore`; a bare `rg` from the org
8//! root returns 0, which is how this stayed invisible), the corpus splits into
9//! two schemas that share zero required slots:
10//!
11//! * [`CaixaDialeto::Pacote`] — this crate's [`crate::Caixa`]. `:nome
12//!   :versao :kind :deps :bibliotecas :exe :servicos` + the supervisor/mesh
13//!   slots. It declares a **tatara-lisp package**: the thing `feira` resolves,
14//!   builds, links and publishes.
15//! * [`CaixaDialeto::Molde`] — `:name :kind :ecosystem :package {…} :workflows
16//!   […] :ci-config {…} :files […]`. It declares a **repo's generated
17//!   surface**: which foreign ecosystem (rust / go / python / …), that
18//!   ecosystem's own package metadata, the CI shims to emit, and byte-captured
19//!   file bodies. Read by `pleme-doc-gen`, never by `feira`.
20//!
21//! `:package`, `:ecosystem`, `:supports` and `:profile` have no counterpart in
22//! [`crate::Caixa`] at all — the theory doc's own D4 note records the same
23//! thing: those manifests "are authored against a schema that does not exist in
24//! Rust". They are not two spellings of one declaration. They are two domains
25//! that collided on one word, because *caixa* names a box and both are boxes.
26//!
27//! # Why this is not a bug report about broken files
28//!
29//! The Molde-dialect files are not malformed. They are correct inputs to their
30//! own consumer, and nothing in the shipped `feira` reads them, so nothing is
31//! failing today. The hazard is **latent and certain**: any new declarative
32//! surface written against "a `.caixa.lisp` is a [`crate::Caixa`]" meets a
33//! corpus where that is false for the large majority of files, and gets a flat
34//! unknown-keyword rejection that reads as "this manifest is broken" rather
35//! than "this manifest is not yours".
36//!
37//! # What this module does about it
38//!
39//! [`classify`] is total: every `(defcaixa …)` form lands in exactly one
40//! [`CaixaDialeto`], including [`CaixaDialeto::Desconhecido`] for one that
41//! matches neither. [`crate::Caixa::from_lisp`] runs it first, so a foreign
42//! dialect is [`crate::ManifestError::DialetoEstrangeiro`] — an error that
43//! names the dialect it found and the consumer that speaks it — rather than an
44//! unknown-kwarg error indistinguishable from a typo.
45//!
46//! Tier-honest: this is **parse-time rejection with a named cause**, not
47//! unrepresentability. A caller that ignores the `Err` still gets nothing
48//! useful; what it can no longer do is mistake "wrong dialect" for "bad file".
49
50use tatara_lisp::{Atom, Sexp};
51
52/// Which `(defcaixa …)` declaration a source speaks.
53///
54/// The [`gen_platform::IsVariant`] derive emits per-arm arm-discriminator
55/// predicates (`is_pacote` / `is_molde` / `is_molde_posicional` /
56/// `is_desconhecido`) as substrate-side typed dispatches on the closed
57/// four-arm dialect-classification discriminator. Peer of the sibling
58/// closed-set fieldless typed enums' [`crate::CaixaKind`] /
59/// [`crate::supervisor::RestartStrategy`] /
60/// [`crate::supervisor::RestartPolicy`] /
61/// [`crate::aplicacao::PlacementStrategy`] /
62/// [`crate::aplicacao::RateLimitUnit`] /
63/// [`crate::dep::DepList`] `IsVariant` derives on the sibling
64/// closed-set typed-enum discriminator axes.
65///
66/// The pre-lift `is_molde_family` predicate hand-rolled its own
67/// `matches!(self, Self::Molde | Self::MoldePosicional)` two-arm literal
68/// with no compile-time link back to the closed set — post-lift it routes
69/// through `self.is_molde() || self.is_molde_posicional()` so a future
70/// arm rename (e.g. `Molde → MoldeKW` under an M4 vocabulary shift) trips
71/// exhaustively at every derive-generated predicate site rather than
72/// leaving the hand-rolled `matches!` silently drifting.
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
74pub enum CaixaDialeto {
75    /// This crate's [`crate::Caixa`] — a tatara-lisp package manifest.
76    /// Keyword-argument form headed by `:nome`.
77    Pacote,
78    /// `pleme-doc-gen`'s repo-surface declaration, keyword-argument form
79    /// headed by `:name` (plus `:ecosystem` / `:package`).
80    Molde,
81    /// The same declaration as [`Self::Molde`], written with the package name
82    /// as a bare positional symbol — `(defcaixa todoku-go :kind :Biblioteca
83    /// :ecosystem :go …)`. `pleme-doc-gen`'s parser reads the first token
84    /// after the head as the name, so this is one arity of one declaration,
85    /// not a third schema.
86    MoldePosicional,
87    /// A `(defcaixa …)` form matching neither. Kept as a variant rather than
88    /// an error so [`classify`] is total and a census can COUNT the residue —
89    /// a classifier that threw here would report "0 unknown" by construction.
90    Desconhecido,
91}
92
93impl CaixaDialeto {
94    /// Exhaustive iteration surface for every consumer that walks the
95    /// closed four-arm [`CaixaDialeto`] discriminator set — the
96    /// [`feira dialeto`](../../caixa_feira/cmd/dialeto/index.html)
97    /// census counter's per-arm accept-set, a future
98    /// `feira dialeto --list-dialects` CLI listing of the accepted
99    /// classifications, a future M4 `mesh.pleme.io/v1alpha1/Manifesto`
100    /// CR materializer's admission-webhook rejection body naming the
101    /// accepted-dialect set, any future census-report shape probe that
102    /// sweeps every arm to compute per-arm coverage. A future arm
103    /// addition (a fifth dialect the [`crate::dialeto`] module doc's
104    /// "third dialect" hazard actualises — the module explicitly frames
105    /// its purpose as "what stops a third dialect appearing", and this
106    /// slice is the substrate-side answer: the arm-set is one edit and
107    /// every consumer picks up the new entry by construction) extends
108    /// this slice as one edit and every downstream consumer picks up
109    /// the new entry through the shared iteration; the compiler-checked
110    /// exhaustiveness on the sibling method `match` arms
111    /// ([`Self::palavra_canonica`] / [`Self::consumidor`] /
112    /// [`Self::descricao`] / [`std::fmt::Display`]) is the build-time
113    /// guarantee that no arm forgets to grow.
114    ///
115    /// Peer of the sibling closed-set typed enums'
116    /// [`crate::CaixaKind::ALL`] (6b1f4fb) /
117    /// [`crate::aplicacao::PlacementStrategy::ALL`] (18c7342) /
118    /// [`crate::aplicacao::RateLimitUnit::ALL`] (6bce03d) /
119    /// [`crate::dep::DepList::ALL`] (45ee563) /
120    /// [`crate::supervisor::RestartStrategy::ALL`] (4eec29c) /
121    /// [`crate::supervisor::RestartPolicy::ALL`] (dd32ccf)
122    /// exhaustive-iteration surfaces — the seventh closed-set typed
123    /// enum on the caixa surface to converge onto the same
124    /// one-canonical-arm-list-per-enum discipline, and the first
125    /// dialect-classification axis (as distinct from an OTP-shape M2
126    /// slot or an M3 mesh slot) to reach it. Order matches variant
127    /// declaration order verbatim (`Pacote` → `Molde` →
128    /// `MoldePosicional` → `Desconhecido`) so the slice is the
129    /// canonical ordering every listing / rendering consumer defers to.
130    pub const ALL: &'static [Self] = &[
131        Self::Pacote,
132        Self::Molde,
133        Self::MoldePosicional,
134        Self::Desconhecido,
135    ];
136
137    /// Substrate-canonical `PascalCase` variant-name byte-string every consumer
138    /// that formats the dialect as census-facing text lands on. Returns the
139    /// per-arm `PascalCase` name of the variant (`"Pacote"` / `"Molde"` /
140    /// `"MoldePosicional"` / `"Desconhecido"`) — the one canonical
141    /// byte-string the paired [`std::fmt::Display`] impl routes through so
142    /// every downstream consumer (the `feira dialeto` census counter output
143    /// line, a future `feira dialeto --list-dialects` CLI enumeration, a
144    /// future M4 `mesh.pleme.io/v1alpha1/Manifesto` CR materializer's
145    /// admission-webhook rejection body naming the accepted-dialect set)
146    /// reaches for the same substrate primitive rather than the pre-lift
147    /// hand-rolled four-arm literal-string match every [`std::fmt::Display`]
148    /// call previously routed through in place.
149    ///
150    /// Peer of the sibling closed-set typed enums'
151    /// [`crate::CaixaKind::as_str`] / [`crate::supervisor::RestartStrategy::as_str`]
152    /// / [`crate::supervisor::RestartPolicy::as_str`] /
153    /// [`crate::aplicacao::PlacementStrategy::as_str`] /
154    /// [`crate::dep::DepList::as_str`] projections on the sibling closed-set
155    /// typed-enum discriminator axes — the seventh (and last unlifted)
156    /// closed-set fieldless typed enum on the caixa surface to converge
157    /// onto the same one-canonical-byte-string-per-arm-through-`as_str`
158    /// discipline the six siblings already carry. Unlike [`crate::CaixaKind`]
159    /// (which carries two axes: `as_str` returning lowercase Portuguese
160    /// diagnostic form vs `wire_name` returning `PascalCase` tatara-lisp
161    /// author-surface bytes), [`CaixaDialeto`] is an internal
162    /// classification with no wire surface — the `PascalCase` variant name
163    /// is the census-facing form every consumer reads, so `as_str`
164    /// suffices without a paired `wire_name` axis.
165    #[must_use]
166    pub const fn as_str(self) -> &'static str {
167        match self {
168            Self::Pacote => "Pacote",
169            Self::Molde => "Molde",
170            Self::MoldePosicional => "MoldePosicional",
171            Self::Desconhecido => "Desconhecido",
172        }
173    }
174
175    /// Substrate-canonical reverse projection on the [`CaixaDialeto`]
176    /// closed-set dialect-classification axis — parses the `PascalCase`
177    /// variant-name byte-string back to the typed variant, or `None` when
178    /// `s` is outside the closed-set arm-string set [`Self::as_str`]
179    /// emits. Walks the same four `"Pacote"` / `"Molde"` /
180    /// `"MoldePosicional"` / `"Desconhecido"` byte-strings the sibling
181    /// [`Self::as_str`] emitter returns, so the parse and emit halves of
182    /// the round-trip migrate through one caixa-core edit on any future
183    /// arm addition (the module doc's "third dialect" hazard actualising
184    /// as a fifth arm) — the compiler-checked exhaustiveness on
185    /// [`Self::as_str`]'s `match self` arms and the round-trip pin
186    /// [`tests::caixa_dialeto_round_trips_through_as_str_and_from_wire`]
187    /// together lock the two halves mutually.
188    ///
189    /// Prior to this lift the substrate carried only the forward
190    /// `Self → &str` projection on the dialect-classification axis (the
191    /// [`Self::as_str`] emitter, the [`std::fmt::Display`] impl routed
192    /// through it, the [`AsRef<str>`] impl routed through it) — every
193    /// future consumer that wanted to promote the census-facing text back
194    /// to the typed enum (a future `feira dialeto --filter
195    /// <Pacote|Molde|MoldePosicional|Desconhecido>` CLI arg-parse that
196    /// binds the wire form into the typed enum before dispatching to the
197    /// per-arm counter, a future M4 `mesh.pleme.io/v1alpha1/Manifesto`
198    /// CR materializer's admission-time re-parse of the per-dialect
199    /// audit body, a future audit-report re-loader that binds a prior
200    /// [`Self::as_str`] output back to the typed enum for cross-run
201    /// comparison) would have had to re-inline a four-arm `match s`
202    /// cascade that expressed no compile-time link back to the typed
203    /// [`CaixaDialeto`] enum.
204    ///
205    /// Same closed-set-reverse-projection discipline the sibling
206    /// [`crate::CaixaKind::from_wire`] (2aa6d23) /
207    /// [`crate::supervisor::RestartStrategy::from_wire`] (4eec29c) /
208    /// [`crate::supervisor::RestartPolicy::from_wire`] (dd32ccf) /
209    /// [`crate::aplicacao::PlacementStrategy::from_wire`] (18c7342) /
210    /// [`crate::dep::DepList::from_wire`] (45ee563) typed enums carry on
211    /// the peer wire-side `str → Self` axes — extends the family onto
212    /// the seventh closed-set fieldless typed enum on the caixa surface
213    /// (the dialect-classification axis), matching the same
214    /// two-way `str ↔ Self` round-trip every sibling closed-set enum
215    /// already carries. Method-named `from_wire` (not `from_str`) to
216    /// match the peer shapes verbatim and side-step the derived
217    /// [`std::str::FromStr`] impls the sibling
218    /// [`gen_platform::FromStrKind`]-carrying axes install on their
219    /// kebab-case dispatcher-catalog identity. Returns `Option<Self>`
220    /// (rather than `Result<Self, _>`) to match the peer shapes: the
221    /// caller picks the diagnostic form appropriate for its use site.
222    #[must_use]
223    pub fn from_wire(s: &str) -> Option<Self> {
224        match s {
225            "Pacote" => Some(Self::Pacote),
226            "Molde" => Some(Self::Molde),
227            "MoldePosicional" => Some(Self::MoldePosicional),
228            "Desconhecido" => Some(Self::Desconhecido),
229            _ => None,
230        }
231    }
232
233    /// The keyword an author should write for this dialect, once the
234    /// migration named in [`Self::consumidor`] completes.
235    #[must_use]
236    pub const fn palavra_canonica(self) -> &'static str {
237        match self {
238            Self::Pacote => "defcaixa",
239            Self::Molde | Self::MoldePosicional => "defmolde",
240            Self::Desconhecido => "?",
241        }
242    }
243
244    /// Who reads this dialect.
245    #[must_use]
246    pub const fn consumidor(self) -> &'static str {
247        match self {
248            Self::Pacote => "caixa-core / feira",
249            Self::Molde | Self::MoldePosicional => "pleme-doc-gen",
250            Self::Desconhecido => "nobody known",
251        }
252    }
253
254    /// A one-line description for a census row or an error message.
255    #[must_use]
256    pub const fn descricao(self) -> &'static str {
257        match self {
258            Self::Pacote => "tatara-lisp package manifest (:nome :versao :kind :deps …)",
259            Self::Molde => "repo-surface declaration (:name :ecosystem :package {…} …)",
260            Self::MoldePosicional => {
261                "repo-surface declaration, positional name (defcaixa <nome> :kind …)"
262            }
263            Self::Desconhecido => "unrecognised — matches no known defcaixa schema",
264        }
265    }
266
267    /// True when this arm belongs to the `defmolde` declaration family —
268    /// the two-arity closure of [`Self::Molde`] and [`Self::MoldePosicional`]
269    /// under the shared `defmolde` head keyword the sibling
270    /// [`Self::palavra_canonica`] projection already collapses onto
271    /// `"defmolde"` for both arms (and the sibling [`Self::consumidor`]
272    /// projection collapses onto `"pleme-doc-gen"` for the same two arms).
273    /// False on [`Self::Pacote`] (the sibling `defcaixa` tatara-lisp
274    /// package manifest, [`Self::palavra_canonica`] `→ "defcaixa"`) and
275    /// on [`Self::Desconhecido`] (the residue that names no known
276    /// declaration, [`Self::palavra_canonica`] `→ "?"`).
277    ///
278    /// The [`Self::Molde`] / [`Self::MoldePosicional`] split is one
279    /// declaration written two ways ([`Self::MoldePosicional`]'s
280    /// variant-declaration docstring at [`Self::MoldePosicional`] frames
281    /// it exactly: "the same declaration as [`Self::Molde`], written with
282    /// the package name as a bare positional symbol … this is one arity
283    /// of one declaration, not a third schema"). Every downstream gate
284    /// that keys off "does this dialect belong to the `defmolde` family"
285    /// (as distinct from the four-arm-per-arm census-counter axis the
286    /// sibling `feira dialeto` verb already fans on separately at
287    /// `caixa-feira/src/cmd/dialeto.rs:110-127`) previously hand-rolled
288    /// the two-arm collapse inline as `matches!(d, CaixaDialeto::Molde |
289    /// CaixaDialeto::MoldePosicional)` — a compile-time-anonymous
290    /// two-arm literal set with no link back to the [`CaixaDialeto`]
291    /// variant declaration nor to the sibling
292    /// [`Self::palavra_canonica`] / [`Self::consumidor`] projections
293    /// that already carry the same two-arm collapse under the shared
294    /// `defmolde` / `pleme-doc-gen` axis. The `feira dialeto` verb's
295    /// [`caixa-feira/src/cmd/dialeto.rs`] carried the same
296    /// `matches!` twice — once in the `--strict-palavra` gate that
297    /// refuses a repo-surface declaration still written as
298    /// `(defcaixa …)`, once in the wrong-declaration-under-`caixa.lisp`
299    /// gate that refuses a repo-surface declaration under the filename
300    /// `feira` loads as a package manifest — with no compile-time link
301    /// between the two hand-rolled arm sets. A future arm addition (the
302    /// module doc's "third dialect" hazard actualises as a fifth arm
303    /// [`CaixaDialeto`] that belongs to the `defmolde` declaration
304    /// family — a third arity variant, an alias-declaration family
305    /// pleme-doc-gen sharpens as its schema evolves) would silently
306    /// split the two hand-rolled `matches!` arm-sets from each other
307    /// and from the paired [`Self::palavra_canonica`] projection: one
308    /// call site picks up the new arm, one does not, and the disagreement
309    /// surfaces far from the arm-addition commit as a `feira dialeto`
310    /// consumer reporting a repo-surface declaration under one gate but
311    /// not the other. Routing every "belongs to the `defmolde` family"
312    /// predicate through this one substrate primitive closes the axis:
313    /// a future arm addition lands one match arm here (a compile-time
314    /// exhaustiveness error otherwise), not a coordinated per-`matches!`
315    /// rewrite across every caller.
316    ///
317    /// Peer of the sibling [`crate::CaixaKind::requires_lib`] (0421c22)
318    /// per-arm-set predicate on the [`crate::CaixaKind`] closed-set
319    /// discriminator's "kind requires a `lib/` surface" axis — extends
320    /// the same "one canonical typed predicate per per-arm-set gate,
321    /// one dispatch on the substrate primitive" discipline onto the
322    /// [`CaixaDialeto`] closed-set discriminator's "belongs to the
323    /// `defmolde` declaration family" axis. The dialect-classification
324    /// axis's second per-arm-set predicate (first being the implicit
325    /// palavra_canonica-through-consumidor-through-descricao arm-set
326    /// collapse already carried on the sibling projections) — the first
327    /// explicitly-typed per-arm-set predicate on the axis, matching the
328    /// discipline the sibling M2 [`crate::CaixaKind`] closed-set
329    /// discriminator already carries with `requires_lib`.
330    ///
331    /// Three consumers now route through this one typed dispatch: the
332    /// [`caixa-feira`](../../caixa_feira/cmd/dialeto/index.html) verb's
333    /// `--strict-palavra` gate (refusing a repo-surface declaration
334    /// still written as `(defcaixa …)`), the same verb's wrong-
335    /// declaration-under-`caixa.lisp` gate (refusing a repo-surface
336    /// declaration under the filename `feira` loads as a package
337    /// manifest), and [`crate::Caixa::from_lisp`]'s foreign-dialect
338    /// gate (raising [`crate::ManifestError::DialetoEstrangeiro`] before
339    /// the derive's `parse_kwargs_strict` walk on any `defmolde`-family
340    /// classification — the pre-lift hand-rolled three-arm
341    /// `match { Pacote => {}, Desconhecido => {}, foreign => Err(…) }`
342    /// literal whose `foreign =>` wildcard silently absorbed anything
343    /// non-Pacote-non-Desconhecido, now the third external consumer of
344    /// the `defmolde`-family partition).
345    #[must_use]
346    pub const fn is_molde_family(self) -> bool {
347        // Routed through the derive-generated per-arm predicates
348        // [`Self::is_molde`] + [`Self::is_molde_posicional`] so the
349        // two-arm collapse links compile-time back to the closed-set
350        // typed dispatch every peer arm-set predicate on the caixa
351        // surface (e.g. [`crate::CaixaKind::requires_lib`] on the
352        // sibling `:kind` axis) now carries. Byte-equivalent to the
353        // pre-lift `matches!(self, Self::Molde | Self::MoldePosicional)`
354        // form (the derived `is_*` predicates each expand to the same
355        // `matches!(self, Self::X)` shape by construction), but a
356        // future arm rename or IsVariant `#[is_variant(name = "…")]`
357        // override lands at exactly one dispatch on the substrate
358        // primitive rather than a hand-rolled two-arm literal.
359        self.is_molde() || self.is_molde_posicional()
360    }
361}
362
363/// [`std::fmt::Display`] routed through [`CaixaDialeto::as_str`], so the
364/// pretty-printed byte-string every consumer that formats the dialect as
365/// user-facing / census text lands on (the `feira dialeto` per-manifest
366/// `--list` row, the `feira dialeto` census summary line's per-arm
367/// counters, a future M4 admission-webhook's rejection body naming the
368/// accepted-dialect set) reaches for the same `PascalCase` per-arm
369/// byte-string the [`CaixaDialeto::as_str`] helper returns.
370///
371/// Prior to this lift the [`std::fmt::Display`] impl hand-rolled its own
372/// four-arm literal-string match — the one hand-rolled per-arm dispatch
373/// on the closed [`CaixaDialeto`] discriminator that had NO substrate
374/// primitive accessor to defer to (the sibling [`CaixaDialeto::palavra_canonica`] /
375/// [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`] projections
376/// carry distinct byte-shapes per axis, so none of them could serve as
377/// the Display source). A future variant addition (a fifth dialect the
378/// module doc's "third dialect" hazard actualises) would land one arm at
379/// the enum and per-arm returns at the paired accessors, but a hand-rolled
380/// [`std::fmt::Display`] match would silently drop the new arm to compile-
381/// fail-at-the-match-arm-site rather than through the shared substrate
382/// primitive. Routing [`std::fmt::Display`] through [`CaixaDialeto::as_str`]
383/// closes the last unlifted per-arm `PascalCase`-name projection on the
384/// caixa surface — the seventh (and last unlifted) closed-set fieldless
385/// typed enum on the caixa surface to converge onto the same
386/// `Display`-through-`as_str` discipline the six siblings
387/// ([`crate::CaixaKind`] / [`crate::supervisor::RestartStrategy`] /
388/// [`crate::supervisor::RestartPolicy`] /
389/// [`crate::aplicacao::PlacementStrategy`] / [`crate::aplicacao::RateLimitUnit`]
390/// / [`crate::dep::DepList`]) already carry.
391impl std::fmt::Display for CaixaDialeto {
392    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
393        f.write_str(self.as_str())
394    }
395}
396
397/// Substrate-canonical [`AsRef<str>`] projection on the [`CaixaDialeto`]
398/// closed-set fieldless typed dialect-classification enum — routes through
399/// the same [`CaixaDialeto::as_str`] `pub const fn` scalar accessor the
400/// paired [`std::fmt::Display`] impl already delegates through, so any
401/// future consumer that binds a [`CaixaDialeto`] through the standard-
402/// library `impl AsRef<str>` bound (a [`std::process::Command::arg`]
403/// shell-out that composes the canonical `PascalCase` variant-name into a
404/// `feira dialeto --strict-palavra <Pacote|Molde|MoldePosicional|Desconhecido>`
405/// diagnostic overlay, a `tracing::field::Value::Str`-arm structured-log
406/// recorder on the [`crate::Caixa::from_lisp`] foreign-dialect
407/// [`crate::ManifestError::DialetoEstrangeiro`] refusal path, a
408/// [`std::collections::HashMap`] lookup keyed on the canonical name
409/// through `map.get::<str>(dialeto.as_ref())` on a future M4 admission-
410/// webhook's per-dialect rejection-body composition table) reaches the
411/// paired `"Pacote"` / `"Molde"` / `"MoldePosicional"` / `"Desconhecido"`
412/// byte-string through one substrate-primitive dispatch rather than an
413/// open-coded `.as_str()` re-inlining at every wire-up.
414///
415/// Same "route the trait impl through the substrate-primitive accessor"
416/// discipline the sibling [`crate::CaixaVersion`] [`AsRef<str>`] impl
417/// (16d5c7e), the paired M2 [`crate::supervisor::RestartStrategy`]
418/// [`AsRef<str>`] impl (63eb1a4), the paired M2
419/// [`crate::supervisor::RestartPolicy`] [`AsRef<str>`] impl (419ea81),
420/// the M3 [`crate::aplicacao::PlacementStrategy`] [`AsRef<str>`] impl
421/// (d86edd2), the M3 [`crate::aplicacao::RateLimitUnit`] [`AsRef<str>`]
422/// impl (d8136db), and the top-level [`crate::CaixaKind`] [`AsRef<str>`]
423/// impl (cd2091f) carry — extends the substrate primitive's
424/// [`AsRef<str>`] projection axis onto the seventh closed-set typed enum
425/// on the caixa surface: the dialect-classification axis previously
426/// carried [`fmt::Display`]-through-`as_str` but not yet the paired
427/// [`AsRef<str>`] impl, so a downstream consumer that bound the enum
428/// through the standard-library `AsRef<str>` trait had to reach the
429/// canonical byte-string through an open-coded `.as_str()` call rather
430/// than the trait-idiomatic `.as_ref()` the peer closed-set typed enums
431/// already admit.
432///
433/// Pinned load-bearing by
434/// [`tests::caixa_dialeto_as_ref_str_routes_through_as_str_accessor`]
435/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
436/// closed set) and
437/// [`tests::caixa_dialeto_as_ref_str_routes_through_display_via_shared_accessor`]
438/// (three-path convergence: `AsRef<str>` + `Display` + `as_str` all
439/// resolve to the same byte-string per arm) — any future silent detour
440/// that routes the impl through a divergent projection (a per-arm inline
441/// `match self { CaixaDialeto::Pacote => "Pacote", … }` re-inlining that
442/// opens a compile-time link to the un-lifted arm-literal, a swap onto
443/// the second-axis [`CaixaDialeto::palavra_canonica`] /
444/// [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`] accessors
445/// that carry distinct byte-shapes per axis) trips at caixa-core test
446/// time under `assert_eq!` rather than at a downstream
447/// `impl AsRef<str>`-bound consumer's silent split.
448impl AsRef<str> for CaixaDialeto {
449    fn as_ref(&self) -> &str {
450        self.as_str()
451    }
452}
453
454/// Trait-idiomatic reverse projection on the [`CaixaDialeto`] closed-set
455/// dialect-classification typed enum — routes byte-for-byte through the
456/// paired substrate-primitive [`CaixaDialeto::from_wire`] `Option<Self>`
457/// accessor so every future consumer that binds a `PascalCase` variant-
458/// name byte-string through the standard-library `.try_into()` /
459/// [`TryFrom`] axis (a future `feira dialeto --filter
460/// <Pacote|Molde|MoldePosicional|Desconhecido>` CLI arg-parse that
461/// composes into `let d: CaixaDialeto = s.try_into()?`, a future audit-
462/// report re-loader binding a prior [`CaixaDialeto::as_str`] output
463/// through `CaixaDialeto::try_from(&s)?`, a generic
464/// `<T: TryFrom<&str>>`-bound loader over any of the substrate's closed-
465/// set typed enums) reaches the same four-arm accept-set the sibling
466/// [`CaixaDialeto::from_wire`] parses through and the sibling
467/// [`CaixaDialeto::as_str`] emits, rather than an open-coded per-arm
468/// `match s { "Pacote" => …, … }` cascade whose arm-set has no
469/// compile-time link back to the substrate primitive.
470///
471/// Complements the pre-existing forward-projection triple
472/// ([`std::fmt::Display`], [`AsRef<str>`], [`CaixaDialeto::as_str`]) with
473/// the paired trait-idiomatic reverse-projection axis: Rust-side
474/// newtype/typed-enum convention pairs [`AsRef<str>`] with either
475/// [`std::str::FromStr`] or [`TryFrom<&str>`] on the same primitive so a
476/// caller who can project *out to* a `&str` can also project *in from*
477/// one. The [`TryFrom<&str>`] axis is deliberately chosen over
478/// [`std::str::FromStr`] to sidestep the `clippy::should_implement_trait`
479/// lint that the sibling method-named `from_wire` would trigger under a
480/// `FromStr` impl (the same design tradeoff the peer
481/// [`crate::CaixaKind`] `TryFrom<&str>` impl (3c83606) and the peer
482/// [`crate::provedor::ferrite::FerriteRuntime::from_wire`] block note)
483/// — this impl closes the trait-idiomatic reverse axis without disturbing
484/// the method-named `from_wire` shape every sibling closed-set typed
485/// enum on the substrate already carries.
486///
487/// `type Error = ()` matches the sibling [`CaixaDialeto::from_wire`]'s
488/// `Option<Self>` return-shape's deliberate deferral of error typing:
489/// the caller picks the diagnostic form appropriate for its use site
490/// (a future `feira dialeto --filter` arg-parse composes its own per-verb
491/// "unknown dialect: <arg> — accepted: {…}" message enumerating
492/// [`CaixaDialeto::ALL`], a future admission-webhook rejection body
493/// wraps the `Err(())` outcome with the accepted-set enumeration for
494/// operator diagnostics, a `Result::map_err` at the call site lifts the
495/// unit-error to a per-verb error type). Same shape the peer
496/// [`crate::CaixaKind`] `TryFrom<&str>` impl (3c83606) and the peer
497/// [`FerriteRuntime::from_wire`] doc block motivate on the sibling
498/// closed-set typed enums' reverse projections.
499///
500/// The paired [`TryFrom<&str>`] impl reaches the same four-arm accept-
501/// set the [`CaixaDialeto::from_wire`] resolver dispatches through, so
502/// any future arm addition (the module doc's "third dialect" hazard
503/// actualises as a fifth arm belonging to the `defmolde` family or a
504/// wholly new declaration) grows the trait-idiomatic axis by
505/// construction — one caixa-core edit on [`CaixaDialeto::from_wire`]
506/// extends both the method-named reverse projection every existing
507/// consumer keys off and the trait-idiomatic reverse projection this
508/// impl exposes, without a coordinated rewrite across every future
509/// `TryFrom<&str>`-bound consumer's arm-set.
510///
511/// Pinned load-bearing by
512/// [`tests::caixa_dialeto_try_from_str_routes_through_from_wire_accessor`]
513/// (byte-parity pin against [`CaixaDialeto::from_wire`] across the four-
514/// arm accept-set) and
515/// [`tests::caixa_dialeto_try_from_str_rejects_unknown_byte_strings`]
516/// (rejection witness against silent accept-set widening).
517impl TryFrom<&str> for CaixaDialeto {
518    type Error = ();
519
520    fn try_from(s: &str) -> Result<Self, Self::Error> {
521        Self::from_wire(s).ok_or(())
522    }
523}
524
525/// Trait-idiomatic forward projection on the [`CaixaDialeto`] closed-set
526/// dialect-classification typed enum — routes byte-for-byte through the
527/// sibling substrate-primitive [`CaixaDialeto::as_str`] `pub const fn`
528/// accessor so every future consumer that needs `&'static str` lifetime
529/// bytes on the dialect-classification axis (a
530/// `tracing::field::valuable::Value::Str` recording where the `Str` arm's
531/// typing demands `&'static str`, a
532/// `Cow::Borrowed::<'static, str>(dialeto.into())` composer on the future
533/// M4 admission-webhook rejection body where the `Cow<'static, str>`
534/// typing rules out the sibling [`AsRef<str>`] borrowed return, a generic
535/// `<T: Into<&'static str>>`-bound serializer or error formatter that
536/// requires the `'static` bound) reaches the same four `"Pacote"` /
537/// `"Molde"` / `"MoldePosicional"` / `"Desconhecido"` byte-strings the
538/// sibling [`CaixaDialeto::as_str`] emitter returns, rather than an
539/// open-coded per-arm literal cascade whose arm-set has no compile-time
540/// link back to the substrate primitive.
541///
542/// Return type is `&'static str` by construction — every
543/// [`CaixaDialeto::as_str`] arm resolves to a compile-time `pub const fn`
544/// return of a `&'static str` literal, so the trait's return-type promise
545/// is upheld structurally without a `String::leak()` cast or a per-arm
546/// inline literal.
547///
548/// Complements the pre-existing reverse-projection axis pair
549/// ([`TryFrom<&str>`] above + method-named [`CaixaDialeto::from_wire`])
550/// with the trait-idiomatic forward-projection axis: Rust-side
551/// newtype/typed-enum convention pairs [`TryFrom<&str>`] with the mirror-
552/// image [`From<Self> for &'static str`] on the same primitive so a
553/// caller who can project *in from* a `&str` can also project *out to*
554/// one under a `'static`-lifetime bound. The
555/// [`AsRef<str>`] impl already carries the same emit-set on the borrowed
556/// return path; this impl closes the trait-idiomatic axis pair with the
557/// stricter `&'static str` lifetime the sibling `AsRef<str>` cannot
558/// promise (its return borrows from `&self`, not from the
559/// [`CaixaDialeto::as_str`] `pub const fn`'s static-string result).
560///
561/// Same "route the trait impl through the substrate-primitive accessor"
562/// discipline the sibling [`crate::supervisor::RestartStrategy`]
563/// `From<Self> for &'static str` impl (523157d — first-mover on this
564/// forward-projection family), [`crate::supervisor::RestartPolicy`]
565/// `From<Self> for &'static str` impl (9fb37d0 — second peer, closing
566/// the M2 OTP-shape sibling pair), and [`crate::CaixaKind`]
567/// `From<Self> for &'static str` impl (edb827b — third peer, opening
568/// the campaign onto the top-level caixa surface) carry — extends the
569/// substrate primitive's trait-idiomatic forward-projection axis onto
570/// the fourth closed-set fieldless typed enum on the caixa surface: the
571/// dialect-classification axis, previously carrying the paired
572/// [`std::fmt::Display`] / [`AsRef<str>`] / [`CaixaDialeto::as_str`] /
573/// [`TryFrom<&str>`] / [`CaixaDialeto::from_wire`] forward+reverse
574/// projections but not yet the trait-idiomatic forward projection with
575/// the `&'static str` lifetime bound.
576///
577/// Unlike the peer [`crate::CaixaKind`] impl (which carries a two-axis
578/// split between the lowercase Portuguese `as_str` diagnostic axis and
579/// the `PascalCase` `wire_name` author-surface axis, so the trait's
580/// round-trip witness must cross through the wire axis rather than
581/// composing the two trait impls directly), [`CaixaDialeto`] is an
582/// internal classification whose [`CaixaDialeto::as_str`] output and
583/// [`CaixaDialeto::from_wire`] input share the same `PascalCase`
584/// vocabulary by construction — the trait-idiomatic axis pair
585/// ([`From<Self> for &'static str`] + [`TryFrom<&str> for Self`])
586/// therefore round-trips directly, without an intermediate wire-vocab
587/// hop.
588///
589/// The paired [`CaixaDialeto::as_str`] accessor's four-arm emit-set is
590/// the single source of truth — every future arm addition (the module
591/// doc's "third dialect" hazard actualises as a fifth arm belonging to
592/// the `defmolde` family or a wholly new declaration) grows the trait-
593/// idiomatic forward axis by construction: one caixa-core edit on
594/// [`CaixaDialeto::as_str`] extends every one of the sibling forward-
595/// projection paths ([`std::fmt::Display`], [`AsRef<str>`],
596/// [`CaixaDialeto::as_str`] itself, and this
597/// [`From<Self> for &'static str`]) without a coordinated rewrite across
598/// every future `Into<&'static str>`-bound consumer's arm-set. This lift
599/// closes the fourth peer on the trait-idiomatic forward-projection
600/// campaign the recently-landed peer commits opened; the remaining ten
601/// closed-set typed enums on the caixa substrate surface
602/// (`PlacementStrategy`, `WitShape`, `RateLimitUnit`,
603/// `PathShapeViolation`, `InvariantKind`, `ArchVerdict`, `Severity`,
604/// `FixSafety`, `Semantic`, `FerriteRuntime`) are the future targets
605/// of this campaign.
606///
607/// Pinned load-bearing by
608/// [`tests::caixa_dialeto_from_into_static_str_routes_through_as_str_accessor`]
609/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
610/// emit-set, plus a `const`-context materialization witness for the
611/// `&'static str` lifetime promise, plus a paired `.into()` shape
612/// assertion covering the blanket-derived `Into<&'static str>` shape)
613/// and
614/// [`tests::caixa_dialeto_from_into_static_str_and_as_str_partition_the_emit_set`]
615/// (partition pin asserting `<&'static str as From<CaixaDialeto>>::from`
616/// and [`CaixaDialeto::as_str`] agree on every arm, plus a two-way
617/// direct round-trip witness through the paired trait-idiomatic
618/// [`TryFrom<&str>`] axis that closes the two-way `Self ↔ &'static str`
619/// round-trip on the trait-idiomatic axis pair without the wire-vocab
620/// intermediate the peer [`crate::CaixaKind`] axis pair requires).
621impl From<CaixaDialeto> for &'static str {
622    fn from(dialeto: CaixaDialeto) -> &'static str {
623        dialeto.as_str()
624    }
625}
626
627/// Trait-idiomatic *forward* projection on [`CaixaDialeto`] from a
628/// *borrowed* input onto the `&'static str` axis — the borrowed-input
629/// companion to the paired owned-input [`From<CaixaDialeto> for &'static
630/// str`] impl immediately above. Routes byte-for-byte through the same
631/// substrate-primitive [`CaixaDialeto::as_str`] `pub const fn` accessor so
632/// every consumer that binds a `&CaixaDialeto` through the standard-
633/// library `.into()` / [`From<&Self> for &'static str`] axis (a
634/// `CaixaDialeto::ALL.iter().map(<&'static str>::from).collect::<Vec<_>>()`
635/// per-arm accept-set materializer — whose iterator over
636/// `&'static [CaixaDialeto]` yields `&CaixaDialeto`, not `CaixaDialeto`,
637/// so the owned-input [`From<CaixaDialeto>`] axis alone forces every call
638/// site through an explicit `.copied()` / dereference / [`Copy`]-bound
639/// restatement rather than the direct trait-idiomatic projection; a
640/// future generic `<T: Copy + for<'a> Into<&'static str>>`-bound
641/// diagnostic column that walks the `iter().map(Into::into)` shape
642/// verbatim over any of the substrate's closed-set typed enums; the
643/// future M4 admission-webhook rejection body composer's per-dialect
644/// accepted-set enumeration built from an iterated
645/// `CaixaDialeto::ALL.iter().map(|d| d.into())` pipe rather than a
646/// per-arm `match d { … }` cascade; a
647/// `HashMap::<&'static str, CaixaDialeto>::from_iter(
648///     CaixaDialeto::ALL.iter().map(|d| (d.into(), *d)))`-style
649/// per-dialect reverse-lookup table the sibling [`TryFrom<&str>`] impl
650/// cannot compose without this borrowed-input axis in place) reaches the
651/// same four `"Pacote"` / `"Molde"` / `"MoldePosicional"` /
652/// `"Desconhecido"` byte-strings the paired owned-input
653/// [`From<CaixaDialeto> for &'static str`], the sibling
654/// [`std::fmt::Display`], [`AsRef<str>`], and [`CaixaDialeto::as_str`]
655/// surfaces already return.
656///
657/// Third peer on the substrate-wide trait-idiomatic *borrowed-input*
658/// forward-projection family opened on
659/// [`crate::dep::DepList`] (64aa742) and extended onto
660/// [`crate::CaixaKind`] (5ab993a). Rust's `From` trait does not
661/// auto-derive the `From<&Self>` sibling from a `From<Self>` impl (the
662/// blanket `impl<T, U> From<&T> for U where T: Copy, U: From<T>` does
663/// not exist in `core`), so every closed-set typed enum that carries
664/// the owned-input axis but not the borrowed-input axis forces every
665/// borrowed-input call site through a `.copied()` /
666/// `<&'static str>::from(*dialeto)` / `dialeto.as_str()` detour whose
667/// type bounds have no compile-time link to the substrate primitive.
668///
669/// Unlike the peer [`crate::CaixaKind`] impl (which carries a two-axis
670/// split between the lowercase Portuguese `as_str` diagnostic axis and
671/// the `PascalCase` `wire_name` author-surface axis, so a `.into()`
672/// pipe over `CaixaKind::ALL` yields the diagnostic vocabulary rather
673/// than the wire vocabulary), [`CaixaDialeto`]'s [`CaixaDialeto::as_str`]
674/// and [`CaixaDialeto::from_wire`] share the same `PascalCase`
675/// vocabulary by construction — the borrowed-input projection this impl
676/// exposes therefore composes directly with the sibling
677/// [`TryFrom<&str>`] axis to build reverse-lookup tables without the
678/// wire-vocab intermediate hop the peer axis pair requires.
679///
680/// Pinned load-bearing by
681/// [`tests::caixa_dialeto_from_borrowed_into_static_str_routes_through_as_str_accessor`]
682/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
683/// emit-set via a borrowed input, plus a `const`-context materialization
684/// witness for the `&'static str` lifetime promise, plus a blanket
685/// `.into()` shape assertion) and
686/// [`tests::caixa_dialeto_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
687/// (cross-axis partition pin against the paired owned-input
688/// [`From<CaixaDialeto> for &'static str`] impl, plus a
689/// `.iter().map(Into::into)` pipe witness over [`CaixaDialeto::ALL`]
690/// that materializes the four-arm accept-set through the borrowed-input
691/// axis alone, plus a direct round-trip witness through the paired
692/// trait-idiomatic [`TryFrom<&str>`] axis that closes the two-way
693/// `&Self → &'static str → Self` round-trip on the borrowed-input axis
694/// without the wire-vocab intermediate the peer [`crate::CaixaKind`]
695/// axis pair requires).
696impl From<&CaixaDialeto> for &'static str {
697    fn from(dialeto: &CaixaDialeto) -> &'static str {
698        dialeto.as_str()
699    }
700}
701
702/// Trait-idiomatic *forward* projection on [`CaixaDialeto`] from an *owned*
703/// input onto the owned-[`String`] axis — routes byte-for-byte through the
704/// substrate-primitive [`CaixaDialeto::as_str`] `pub const fn` accessor so
705/// every consumer that binds a [`CaixaDialeto`] through the standard-library
706/// `.into()` / [`From<Self> for String`] (equivalently [`Into<String>`]) axis
707/// reaches the same four `"Pacote"` / `"Molde"` / `"MoldePosicional"` /
708/// `"Desconhecido"` byte-strings the paired owned-input
709/// [`From<CaixaDialeto> for &'static str`], the borrowed-input
710/// [`From<&CaixaDialeto> for &'static str`], the sibling [`std::fmt::Display`],
711/// [`AsRef<str>`], and [`CaixaDialeto::as_str`] surfaces already return.
712///
713/// Extends the trait-idiomatic *owned-[`String`]* forward-projection family
714/// (opened on [`crate::supervisor::RestartStrategy`] — 7baa18a — the first-
715/// mover on the M2 OTP-shape sibling-restart-strategy axis, extended onto
716/// [`crate::supervisor::RestartPolicy`] — 7851725 — the second-of-two-in-M2
717/// per-child restart-decision axis, then onto [`crate::CaixaKind`] — 231a18c
718/// — the structurally most fundamental closed-set fieldless typed enum on
719/// the caixa surface) onto the fourth peer: the dialect-classification axis
720/// [`CaixaDialeto`] carries. Rust's standard library does not carry a blanket
721/// `impl<T: AsRef<str>> From<T> for String` (nor an
722/// `impl<T: fmt::Display> From<T> for String`), so every closed-set typed
723/// enum that carries the paired `AsRef<str>` / `Display` /
724/// `From<Self> for &'static str` triple but not the owned-[`String`] axis
725/// forces every owned-string call site through a `.to_string()` /
726/// `.as_str().to_owned()` / `String::from(dialeto.as_str())` detour whose
727/// type bounds have no compile-time link to the substrate primitive.
728///
729/// Unlike the peer [`crate::CaixaKind`] enum (which carries a two-axis split
730/// between the lowercase Portuguese [`crate::CaixaKind::as_str`] diagnostic
731/// axis and the `PascalCase` [`crate::CaixaKind::wire_name`] author-surface
732/// axis, so the owned-[`String`] forward emit and the reverse
733/// [`TryFrom<&str>`] parse land on disjoint vocabularies and the round-trip
734/// crosses through [`crate::CaixaKind::wire_name`] as the reverse-axis
735/// vocabulary rather than composing the owned-[`String`] emit directly),
736/// [`CaixaDialeto`]'s [`CaixaDialeto::as_str`] emit and
737/// [`CaixaDialeto::from_wire`] parse share the same `PascalCase` vocabulary
738/// by construction (there is no wire/diagnostic axis split on this enum —
739/// it is an internal classification with no wire surface), so the
740/// owned-[`String`] forward projection this impl exposes composes directly
741/// with the sibling [`TryFrom<&str>`] axis on the owned-[`String`]'s
742/// [`String::as_str`] borrow, byte-identically to the peer
743/// [`crate::supervisor::RestartStrategy`] /
744/// [`crate::supervisor::RestartPolicy`] owned-[`String`] axis pairs
745/// (whose forward emit and reverse parse also share one `PascalCase`
746/// vocabulary by construction).
747///
748/// The remaining ten closed-set typed enums on the caixa substrate surface
749/// (`DepList`, `PlacementStrategy`, `WitShape`, `RateLimitUnit`,
750/// `PathShapeViolation`, `InvariantKind`, `ArchVerdict`, `Severity`,
751/// `FixSafety`, `Semantic`, `FerriteRuntime`) are the future targets of
752/// this campaign — each carries the same paired `AsRef<str>` / `Display` /
753/// `From<Self> for &'static str` / `From<&Self> for &'static str` quadruple
754/// that this owned-[`String`] axis extends onto.
755///
756/// Pinned load-bearing by
757/// [`tests::caixa_dialeto_from_into_owned_string_routes_through_as_str_accessor`]
758/// (byte-parity pin against [`CaixaDialeto::as_str`] across the four-arm
759/// emit-set, plus a blanket `.into::<String>()` shape witness) and
760/// [`tests::caixa_dialeto_from_into_owned_string_and_static_str_agree_on_every_arm`]
761/// (cross-axis partition pin against the paired owned-input
762/// [`From<CaixaDialeto> for &'static str`] impl and the sibling
763/// [`ToString::to_string`] surface routed through [`std::fmt::Display`],
764/// plus a `.iter().copied().map(String::from)` pipe witness over
765/// [`CaixaDialeto::ALL`], plus a direct round-trip witness through
766/// [`TryFrom<&str>`] on the owned-[`String`]'s [`String::as_str`] borrow
767/// that closes the two-way `Self → String → Self` round-trip on the
768/// trait-idiomatic owned-[`String`] forward + reverse axis pair without
769/// the wire-vocab intermediate hop the peer [`crate::CaixaKind`] axis pair
770/// requires).
771impl From<CaixaDialeto> for String {
772    fn from(dialeto: CaixaDialeto) -> String {
773        dialeto.as_str().to_owned()
774    }
775}
776
777/// Trait-idiomatic *borrowed-input, owned-`String` output* forward
778/// projection on the dialect-classification [`CaixaDialeto`] closed-set
779/// typed enum — the fourth (and closing) corner of the
780/// `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
781/// projection family on this enum, mirror of the peer M2 OTP-shape
782/// [`From<&crate::supervisor::RestartStrategy> for String`] (579385f) /
783/// [`From<&crate::supervisor::RestartPolicy> for String`] (8465740),
784/// the two-list dep-graph [`From<&crate::dep::DepList> for String`]
785/// (e0cb617), and the top-level [`From<&crate::CaixaKind> for String`]
786/// (e76436d) that opened and extended the corner off the M2 OTP-shape
787/// sibling axis pair onto the sibling closed-set fieldless typed enum
788/// peers. Routes byte-for-byte through the substrate-primitive
789/// [`CaixaDialeto::as_str`] `pub const fn` accessor (via
790/// [`str::to_owned`]) so every consumer that holds a borrowed
791/// [`&CaixaDialeto`] and needs an owned [`String`] — a future
792/// `serde_json::Value::String(String::from(&dialeto))` structured-
793/// payload composer over a borrowed field, a future `Iterator::map`
794/// over `&[CaixaDialeto]` that projects to owned keys through
795/// `.iter().map(String::from)` (whose iterator yields `&CaixaDialeto`,
796/// not `CaixaDialeto`, so the owned-input
797/// [`From<CaixaDialeto> for String`] axis alone forces every call site
798/// through an explicit `.copied()` / spurious [`Copy`] deref restatement
799/// rather than the direct trait-idiomatic projection), a future
800/// `HashMap::<String, CaixaDialeto>::from_iter` that keys off a
801/// borrowed-iteration axis where dereferencing the dialect would force
802/// an unnecessary [`Copy`] at every step, the future
803/// `feira dialeto --list-dialects` CLI enumeration that walks
804/// [`CaixaDialeto::ALL`] through the borrowed-iteration axis by
805/// construction, the future M4
806/// `mesh.pleme.io/v1alpha1/Manifesto` CR materializer's admission-
807/// webhook rejection body composer that names the accepted-dialect
808/// set through an iterated `.iter().map(String::from).collect()`
809/// pipe rather than a per-arm cascade — reaches the same four
810/// `"Pacote"` / `"Molde"` / `"MoldePosicional"` / `"Desconhecido"`
811/// byte-strings the paired [`std::fmt::Display`], [`AsRef<str>`],
812/// [`CaixaDialeto::as_str`], and the three other trait-idiomatic
813/// forward-projection impls ([`From<CaixaDialeto> for &'static str`],
814/// [`From<&CaixaDialeto> for &'static str`],
815/// [`From<CaixaDialeto> for String`]) already return.
816///
817/// Fifth peer on the substrate-wide trait-idiomatic *borrowed-input,
818/// owned-`String` output* forward-projection family opened on
819/// [`crate::supervisor::RestartStrategy`] (579385f), closed on the M2
820/// OTP-shape sibling axis pair by
821/// [`crate::supervisor::RestartPolicy`] (8465740), extended onto the
822/// two-list dep-graph peer by [`crate::dep::DepList`] (e0cb617) and
823/// onto the top-level [`crate::CaixaKind`] (e76436d) — extends the
824/// `{Self, &Self} × {&'static str, String}` 2×2 projection corner off
825/// the top-level `:kind` axis onto the dialect-classification axis
826/// (the fourth closed-set fieldless typed enum on the caixa surface;
827/// second peer outside the M2 OTP-shape sibling pair to reach the
828/// 2×2-completion corner). Rust's standard library does not carry a
829/// blanket `impl<T: AsRef<str>> From<&T> for String` (nor an
830/// `impl<T: fmt::Display> From<&T> for String`), so every closed-set
831/// typed enum that carries the paired `AsRef<str>` / `Display` /
832/// `From<Self> for &'static str` / `From<&Self> for &'static str` /
833/// `From<Self> for String` quintuple but not the borrowed-input
834/// owned-[`String`] axis forces every borrowed-input owned-string call
835/// site through a `dialeto.as_str().to_owned()` /
836/// `String::from(*dialeto)` (with a spurious [`Copy`]) /
837/// `dialeto.to_string()` (through [`std::fmt::Display`]) detour whose
838/// type bounds have no compile-time link to the substrate primitive.
839///
840/// Same as the peer [`crate::supervisor::RestartStrategy`] /
841/// [`crate::supervisor::RestartPolicy`] / [`crate::dep::DepList`]
842/// borrowed-input owned-[`String`] axis pairs (whose forward emit and
843/// reverse parse share one vocabulary by construction — `PascalCase`
844/// on the M2 OTP-shape peers, the lifted
845/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
846/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] consts on the two-list
847/// dep-graph peer) and unlike the peer [`crate::CaixaKind`] pair
848/// (whose forward emit lands on the lowercase Portuguese
849/// diagnostic vocabulary while the reverse parse lands on the
850/// `PascalCase` wire vocabulary, forcing the round-trip through an
851/// intermediate [`crate::CaixaKind::wire_name`] hop), [`CaixaDialeto`]
852/// is an internal classification with no wire surface — the
853/// [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`] parse
854/// share the same `PascalCase` vocabulary by construction (there is
855/// no wire/diagnostic axis split on this enum), so the borrowed-
856/// input owned-[`String`] projection this impl exposes composes
857/// directly with the paired trait-idiomatic reverse [`TryFrom<&str>`]
858/// axis on the owned-[`String`]'s [`String::as_str`] borrow — no
859/// intermediate wire-vocab hop required.
860///
861/// The remaining nine closed-set typed enums on the caixa substrate
862/// surface (`PlacementStrategy`, `WitShape`, `RateLimitUnit`,
863/// `PathShapeViolation`, `InvariantKind`, `ArchVerdict`, `Severity`,
864/// `FixSafety`, `Semantic`, `FerriteRuntime`) are the future targets
865/// of this 2×2-completion campaign — each carries the same paired
866/// quintuple that this borrowed-input owned-[`String`] axis extends
867/// onto.
868///
869/// Pinned load-bearing by
870/// [`tests::caixa_dialeto_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
871/// (byte-parity pin against [`CaixaDialeto::as_str`] across the
872/// four-arm emit-set through the borrowed-input surface) and
873/// [`tests::caixa_dialeto_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
874/// (cross-axis partition pin against the paired owned-input owned-
875/// [`String`] [`From<CaixaDialeto> for String`] impl, the paired
876/// borrowed-input owned-[`&'static str`]
877/// [`From<&CaixaDialeto> for &'static str`] impl, the paired owned-
878/// input owned-[`&'static str`] [`From<CaixaDialeto> for &'static str`]
879/// impl, and the sibling [`ToString::to_string`] surface routed
880/// through [`std::fmt::Display`], plus a `.iter().map(String::from)`
881/// pipe witness over [`CaixaDialeto::ALL`] (whose iterator yields
882/// `&CaixaDialeto` by construction, so the borrowed-input owned-
883/// [`String`] axis is what routes the pipe through the substrate-
884/// primitive [`CaixaDialeto::as_str`] accessor without a spurious
885/// [`Copy`] deref), plus a direct round-trip witness through
886/// [`TryFrom<&str>`] on the owned-[`String`]'s [`String::as_str`]
887/// borrow that closes the two-way `&Self → String → Self` round-trip
888/// on the trait-idiomatic borrowed-input owned-[`String`] forward +
889/// reverse axis pair — no intermediate wire-vocab hop like the peer
890/// [`crate::CaixaKind`] axis pair requires).
891impl From<&CaixaDialeto> for String {
892    fn from(dialeto: &CaixaDialeto) -> String {
893        dialeto.as_str().to_owned()
894    }
895}
896
897/// Trait-idiomatic *owned-input, [`std::borrow::Cow<'static, str>`]
898/// output* forward projection on the dialect-classification
899/// [`CaixaDialeto`] closed-set typed enum — routes byte-for-byte
900/// through the substrate-primitive [`CaixaDialeto::as_str`]
901/// `pub const fn` accessor (via [`std::borrow::Cow::Borrowed`]) so
902/// every consumer that binds a [`CaixaDialeto`] through the
903/// standard-library `.into()` /
904/// [`From<Self> for std::borrow::Cow<'static, str>`] (equivalently
905/// [`Into<std::borrow::Cow<'static, str>>`]) axis — a future
906/// `axum::response::IntoResponse` body composer whose typing folds a
907/// per-arm rejection line into a [`std::borrow::Cow<'static, str>`]
908/// boundary, a future M4 `mesh.pleme.io/v1alpha1/Manifesto` CR
909/// materializer's admission-webhook rejection body composer whose
910/// typing rules out the sibling [`AsRef<str>`] borrowed return and
911/// the sibling [`From<Self> for &'static str`] axis's non-
912/// [`std::borrow::Cow`]-parameterized shape, a future substrate-wide
913/// per-arm diagnostic surface that folds either the zero-alloc
914/// [`std::borrow::Cow::Borrowed`] arm (for the closed-set arms whose
915/// byte-string is build-time-lifted) or the [`std::borrow::Cow::Owned`]
916/// arm (for a caller that mutates the projection) through one uniform
917/// trait dispatch, a future generic
918/// `<T: Into<std::borrow::Cow<'static, str>>>`-bound emitter on a
919/// per-dialect structured-log or admission-webhook rejection body —
920/// reaches the same four `"Pacote"` / `"Molde"` / `"MoldePosicional"` /
921/// `"Desconhecido"` byte-strings the paired [`std::fmt::Display`],
922/// [`AsRef<str>`], [`CaixaDialeto::as_str`], and the four
923/// `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
924/// forward-projection corners
925/// ([`From<CaixaDialeto> for &'static str`],
926/// [`From<&CaixaDialeto> for &'static str`],
927/// [`From<CaixaDialeto> for String`],
928/// [`From<&CaixaDialeto> for String`]) already return, rather than an
929/// open-coded per-call-site
930/// `std::borrow::Cow::Borrowed(dialeto.as_str())` /
931/// `std::borrow::Cow::Owned(dialeto.to_string())` /
932/// `String::from(dialeto).into()` composition whose type bounds have
933/// no compile-time link back to the substrate primitive.
934///
935/// Deliberately returns [`std::borrow::Cow::Borrowed`] rather than
936/// [`std::borrow::Cow::Owned`] — the substrate-primitive
937/// [`CaixaDialeto::as_str`] accessor's return carries the
938/// `&'static str` lifetime by construction (each `match` arm resolves
939/// to a `pub const &'static str` literal with static lifetime), so the
940/// zero-alloc borrowed arm is the type-correct projection with no
941/// runtime allocation. The paired [`std::borrow::Cow::Owned`] arm
942/// stays reachable at the call site through the existing
943/// [`From<CaixaDialeto> for String`] axis composed with
944/// [`std::borrow::Cow::from`] on the resulting owned [`String`] — a
945/// caller who chose to mutate the projection lands on the owned arm
946/// by their own composition, not by the substrate-primitive
947/// projection silently allocating on their behalf.
948///
949/// Same as the sibling [`crate::CaixaKind`] /
950/// [`crate::supervisor::RestartStrategy`] /
951/// [`crate::supervisor::RestartPolicy`] /
952/// [`crate::aplicacao::WitShape`] /
953/// [`crate::aplicacao::PlacementStrategy`] /
954/// [`crate::aplicacao::RateLimitUnit`] /
955/// [`crate::dep::DepList`] peers on the substrate-wide trait-idiomatic
956/// [`std::borrow::Cow<'static, str>`] forward-projection campaign,
957/// unlike the peer [`crate::CaixaKind`] pair (whose forward emit
958/// lands on the lowercase Portuguese diagnostic vocabulary while the
959/// reverse parse lands on the `PascalCase` wire vocabulary, forcing
960/// the round-trip through an intermediate
961/// [`crate::CaixaKind::wire_name`] hop), [`CaixaDialeto`] is an
962/// internal classification with no wire surface — the
963/// [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
964/// parse share the same `PascalCase` vocabulary by construction (no
965/// wire/diagnostic axis split on this enum), so the
966/// [`std::borrow::Cow<'static, str>`] projection this impl exposes
967/// composes directly with the paired trait-idiomatic reverse
968/// [`TryFrom<&str>`] axis on the projection's
969/// [`std::borrow::Cow::as_ref`] borrow — no intermediate wire-vocab
970/// hop required.
971///
972/// Eighth peer on the substrate-wide trait-idiomatic
973/// [`std::borrow::Cow<'static, str>`] forward-projection family
974/// opened on the top-level [`crate::CaixaKind`] by 99c1735 (extended
975/// off the closed `{Self, &Self} × {&'static str, String}` 2×2
976/// corner closed on the last outside-caixa-core enum peer by
977/// 29f8af3), closed on the `{Self, &Self}` input-shape corner on
978/// [`crate::CaixaKind`] by d45c409, extended onto the M2 OTP-shape
979/// tier by 7dd28b3 / 9b3e4b3 (opens/closes on
980/// [`crate::supervisor::RestartStrategy`]) and 0612398 / ee577fd
981/// (opens/closes on [`crate::supervisor::RestartPolicy`], closing the
982/// M2 OTP-shape tier), extended onto the M3 mesh-shape tier by
983/// 8634dec / 25690ef (opens/closes on [`crate::aplicacao::WitShape`])
984/// and eee504d / afdf0f4 (opens/closes on
985/// [`crate::aplicacao::PlacementStrategy`]) and 1d59925 (closes M3
986/// mesh-shape tier on [`crate::aplicacao::RateLimitUnit`]), extended
987/// onto the outside-M3 caixa-core tier by 6858bac / 702cdf4
988/// (opens/closes on [`crate::dep::DepList`]) — extends the axis onto
989/// the dialect-classification [`CaixaDialeto`] closed-set fieldless
990/// typed enum (the second outside-M3 caixa-core peer, and the sole
991/// remaining internal-classification enum on the caixa-core surface).
992/// Rust's standard library does not carry a blanket
993/// `impl<T: AsRef<str>> From<T> for std::borrow::Cow<'static, str>`
994/// (nor an `impl<T: fmt::Display> From<T> for
995/// std::borrow::Cow<'static, str>`), so every closed-set fieldless
996/// typed enum peer on the substrate that carries the paired
997/// [`AsRef<str>`] / [`std::fmt::Display`] /
998/// [`From<Self> for &'static str`] / [`From<&Self> for &'static str`]
999/// / [`From<Self> for String`] / [`From<&Self> for String`] sextet but
1000/// not the [`std::borrow::Cow<'static, str>`] axis forces every
1001/// [`std::borrow::Cow<'static, str>`]-parameterized call site through
1002/// a `std::borrow::Cow::Borrowed(dialeto.as_str())` /
1003/// `std::borrow::Cow::Owned(dialeto.to_string())` /
1004/// `String::from(dialeto).into()` detour whose type bounds have no
1005/// compile-time link to the substrate primitive.
1006///
1007/// The remaining outside-`caixa-core` closed-set fieldless typed
1008/// enum peers on the substrate surface (`PathShapeViolation`,
1009/// `InvariantKind`, `ArchVerdict`, `Severity`, `FixSafety`,
1010/// `Semantic`, `FerriteRuntime`) are the future targets of this
1011/// campaign — each carries the same paired sextet that this axis
1012/// extends onto.
1013///
1014/// Pinned load-bearing by
1015/// [`tests::caixa_dialeto_from_into_static_cow_str_routes_through_as_str_accessor`]
1016/// (byte-parity pin against [`CaixaDialeto::as_str`] across the
1017/// four-arm emit-set through the [`std::borrow::Cow<'static, str>`]
1018/// surface, plus a [`std::borrow::Cow::Borrowed`] discriminator
1019/// witness that the projection lands on the zero-alloc arm rather
1020/// than silently allocating through [`std::borrow::Cow::Owned`],
1021/// plus a blanket-derived [`Into<std::borrow::Cow<'static, str>>`]
1022/// shape witness that also lands on [`std::borrow::Cow::Borrowed`])
1023/// and
1024/// [`tests::caixa_dialeto_from_into_static_cow_str_agrees_with_paired_axes_on_every_arm`]
1025/// (cross-axis partition pin against the paired owned-input
1026/// [`From<CaixaDialeto> for &'static str`] and
1027/// [`From<CaixaDialeto> for String`] forward-projection corners plus
1028/// the sibling [`ToString::to_string`]-through-[`std::fmt::Display`]
1029/// surface, plus a `.iter().copied().map(std::borrow::Cow::from)`
1030/// pipe witness over [`CaixaDialeto::ALL`] whose zero-alloc
1031/// [`std::borrow::Cow::Borrowed`] outcome is load-bearing on every
1032/// arm, plus a direct round-trip witness through [`TryFrom<&str>`]
1033/// on the projection's [`std::borrow::Cow::as_ref`] borrow that
1034/// closes the two-way `Self → Cow<'static, str> → Self` round-trip
1035/// on the trait-idiomatic [`std::borrow::Cow<'static, str>`]
1036/// forward + reverse axis pair without the wire-vocab intermediate
1037/// hop the peer [`crate::CaixaKind`] axis pair requires).
1038impl From<CaixaDialeto> for std::borrow::Cow<'static, str> {
1039    fn from(dialeto: CaixaDialeto) -> std::borrow::Cow<'static, str> {
1040        std::borrow::Cow::Borrowed(dialeto.as_str())
1041    }
1042}
1043
1044/// Trait-idiomatic *borrowed-input, [`std::borrow::Cow<'static, str>`]
1045/// output* forward projection on the dialect-classification
1046/// [`CaixaDialeto`] closed-set typed enum — the borrowed-input companion
1047/// to the paired owned-input [`From<CaixaDialeto> for
1048/// std::borrow::Cow<'static, str>`] impl immediately above (8322511).
1049/// Routes byte-for-byte through the same substrate-primitive
1050/// [`CaixaDialeto::as_str`] `pub const fn` accessor (via
1051/// [`std::borrow::Cow::Borrowed`]) so every consumer that holds a
1052/// [`&CaixaDialeto`] and needs a [`std::borrow::Cow<'static, str>`] — a
1053/// `CaixaDialeto::ALL.iter().map(std::borrow::Cow::from).collect::<Vec<_>>()`
1054/// per-arm accept-set materializer whose iterator over
1055/// `&'static [CaixaDialeto]` yields `&CaixaDialeto` (not
1056/// [`CaixaDialeto`], so the paired owned-input
1057/// [`From<CaixaDialeto> for std::borrow::Cow<'static, str>`] axis alone
1058/// forces every call site through an explicit `.copied()` / dereference
1059/// / [`Copy`]-bound restatement rather than the direct trait-idiomatic
1060/// projection), a future generic
1061/// `<T: for<'a> Into<std::borrow::Cow<'static, str>>>`-bound emitter on
1062/// a per-dialect diagnostic column that walks the
1063/// `iter().map(Into::into)` shape verbatim, the future M4
1064/// `mesh.pleme.io/v1alpha1/Manifesto` CR admission-webhook rejection
1065/// body that composes the accepted-dialect enumeration from an iterated
1066/// `CaixaDialeto::ALL.iter().map(|d| d.into())` pipe rather than a
1067/// per-arm `match d { … }` cascade — reaches the same four `"Pacote"` /
1068/// `"Molde"` / `"MoldePosicional"` / `"Desconhecido"` byte-strings the
1069/// paired [`std::fmt::Display`], [`AsRef<str>`], [`CaixaDialeto::as_str`],
1070/// the four `{Self, &Self} × {&'static str, String}` 2×2 trait-idiomatic
1071/// forward-projection corners, and the paired owned-input
1072/// [`From<CaixaDialeto> for std::borrow::Cow<'static, str>`] impl
1073/// already return.
1074///
1075/// Deliberately returns [`std::borrow::Cow::Borrowed`] rather than
1076/// [`std::borrow::Cow::Owned`] — the substrate-primitive
1077/// [`CaixaDialeto::as_str`] accessor's return carries the `&'static str`
1078/// lifetime by construction (each `match` arm resolves to a `pub const
1079/// &'static str` literal), so the zero-alloc borrowed arm is the
1080/// type-correct projection with no runtime allocation on the
1081/// borrowed-input surface just as on the paired owned-input surface.
1082///
1083/// Closes the `{Self, &Self}` input-shape corner on the second
1084/// outside-M3 caixa-core peer of the substrate-wide
1085/// [`std::borrow::Cow<'static, str>`] forward-projection campaign,
1086/// opened one commit prior (8322511) on the paired owned-input impl.
1087/// Rust's standard library does not carry a blanket
1088/// `impl<T: AsRef<str>> From<&T> for std::borrow::Cow<'static, str>`
1089/// (nor an `impl<T: fmt::Display> From<&T> for
1090/// std::borrow::Cow<'static, str>`, nor a `Copy`-based
1091/// `impl<T: Copy, U: From<T>> From<&T> for U`), so every closed-set
1092/// fieldless typed enum peer on the substrate that carries the paired
1093/// owned-input [`Cow<'static, str>`] axis but not the borrowed-input
1094/// axis forces every borrowed-input [`Cow<'static, str>`]-parameterized
1095/// call site through a spurious [`Copy`] deref
1096/// (`std::borrow::Cow::from(*dialeto)`) or a
1097/// `std::borrow::Cow::Borrowed(dialeto.as_str())` open-code whose type
1098/// bounds have no compile-time link to the substrate primitive.
1099///
1100/// Matches the closure discipline afdf0f4 landed on the M3-mesh-shape
1101/// [`crate::aplicacao::PlacementStrategy`] axis one commit after eee504d,
1102/// 25690ef on [`crate::aplicacao::WitShape`] one commit after 8634dec,
1103/// d45c409 on the top-level [`crate::CaixaKind`] one commit after
1104/// 99c1735, 9b3e4b3 / ee577fd on the M2 OTP-shape
1105/// [`crate::supervisor::RestartStrategy`] /
1106/// [`crate::supervisor::RestartPolicy`] sibling peers one commit after
1107/// 7dd28b3 / 0612398, and 702cdf4 on the two-list dep-graph
1108/// [`crate::dep::DepList`] axis one commit after 6858bac. The remaining
1109/// outside-M3 caixa-core peer ([`crate::render::PathShapeViolation`])
1110/// and the outside-`caixa-core` peers (`InvariantKind`, `ArchVerdict`,
1111/// `Severity`, `FixSafety`, `Semantic`, `FerriteRuntime`) are the
1112/// remaining future targets on the axis.
1113///
1114/// Unlike the peer [`crate::CaixaKind`] pair (whose forward emit lands
1115/// on the lowercase Portuguese diagnostic vocabulary while the reverse
1116/// parse lands on the `PascalCase` wire vocabulary, forcing the
1117/// round-trip through an intermediate [`crate::CaixaKind::wire_name`]
1118/// hop), [`CaixaDialeto`] is an internal classification with no wire
1119/// surface — the [`CaixaDialeto::as_str`] emit and
1120/// [`CaixaDialeto::from_wire`] parse share the same `PascalCase`
1121/// vocabulary by construction (no wire/diagnostic axis split on this
1122/// enum), so the borrowed-input [`std::borrow::Cow<'static, str>`]
1123/// projection this impl exposes composes directly with the paired
1124/// trait-idiomatic reverse [`TryFrom<&str>`] axis on the projection's
1125/// [`std::borrow::Cow::as_ref`] borrow — no intermediate wire-vocab hop
1126/// required.
1127///
1128/// Pinned load-bearing by
1129/// [`tests::caixa_dialeto_from_borrowed_into_static_cow_str_routes_through_as_str_accessor`]
1130/// (byte-parity + zero-alloc [`std::borrow::Cow::Borrowed`]-arm pin
1131/// against [`CaixaDialeto::as_str`] across the four-arm
1132/// [`CaixaDialeto::ALL`] through the borrowed-input surface, plus a
1133/// blanket-derived [`Into<std::borrow::Cow<'static, str>>`] shape
1134/// witness that also lands on [`std::borrow::Cow::Borrowed`]) and
1135/// [`tests::caixa_dialeto_from_borrowed_into_static_cow_str_agrees_with_paired_axes_on_every_arm`]
1136/// (cross-axis partition pin against the paired owned-input
1137/// [`From<CaixaDialeto> for std::borrow::Cow<'static, str>`], the paired
1138/// borrowed-input owned-`&'static str`
1139/// [`From<&CaixaDialeto> for &'static str`], and the paired
1140/// borrowed-input owned-`String` [`From<&CaixaDialeto> for String`]
1141/// impls plus [`ToString::to_string`]-through-[`std::fmt::Display`], a
1142/// `.iter().map(std::borrow::Cow::from)` pipe witness over
1143/// [`CaixaDialeto::ALL`] — whose iterator yields `&CaixaDialeto` by
1144/// construction, so the borrowed-input axis is what routes the pipe
1145/// without a spurious [`Copy`] deref and every collected element
1146/// satisfies the zero-alloc [`std::borrow::Cow::Borrowed`]-arm
1147/// predicate — plus a direct round-trip witness through
1148/// [`TryFrom<&str>`] on the projection's [`std::borrow::Cow::as_ref`]
1149/// borrow that closes the two-way `&Self → Cow<'static, str> → Self`
1150/// round-trip on the borrowed-input axis without the wire-vocab
1151/// intermediate hop the peer [`crate::CaixaKind`] axis pair requires).
1152impl From<&CaixaDialeto> for std::borrow::Cow<'static, str> {
1153    fn from(dialeto: &CaixaDialeto) -> std::borrow::Cow<'static, str> {
1154        std::borrow::Cow::Borrowed(dialeto.as_str())
1155    }
1156}
1157
1158/// A source that is not a `(defcaixa …)` / `(defmolde …)` form at all.
1159#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
1160pub enum DialetoError {
1161    #[error("source has no top-level form")]
1162    Vazio,
1163    #[error("top-level form is not a list — a manifest is `(defcaixa …)`")]
1164    NaoEhLista,
1165    #[error(
1166        "top-level form is headed by `{encontrado}`, not `defcaixa` or `defmolde` \
1167         (a manifest's first form must be the declaration itself)"
1168    )]
1169    CabecaErrada { encontrado: String },
1170    #[error("manifest does not parse as tatara-lisp: {0}")]
1171    Leitura(String),
1172}
1173
1174impl DialetoError {
1175    /// Construct a [`DialetoError::CabecaErrada`] naming the offending
1176    /// head symbol found at the top-level form.
1177    ///
1178    /// Substrate primitive every [`classify_form`] wrong-head fallthrough
1179    /// wire-up site now routes through, folding the pre-lift uniform
1180    /// three-line `Self::CabecaErrada { encontrado: <head>.to_string() }`
1181    /// one-field struct-literal onto one substrate primitive matching the
1182    /// peer `LimitsError::unknown_byte_unit(unit: &str)` /
1183    /// `LimitsError::unknown_duration_unit(unit: &str)`
1184    /// (`limits_codec_unit_only_ctors!` — 29fac09) single-slot
1185    /// discipline on the sibling one-field `{ <field>: String }` envelope
1186    /// axis, and matching the peer `ManifestError::code_path_empty` /
1187    /// `BehaviorError::empty_path` / `UpgradeError::duplicate_from` /
1188    /// `AplicacaoError::placement_cluster_duplicate` (94dabc8 / 0e33b37 /
1189    /// 7e52aec / 92b1c92) single-slot inherent-ctor discipline every
1190    /// sibling `{ <field>: <T> }` error-envelope variant on caixa-core's
1191    /// error surface now carries.
1192    ///
1193    /// The one open-coded wire-up site — `classify_form`'s wrong-head
1194    /// fallthrough arm on the `head: &str` binding read from the
1195    /// top-level form via [`tatara_lisp::Sexp::as_symbol`] — opened the
1196    /// identical three-line
1197    /// `Self::CabecaErrada { encontrado: <head>.to_string() }` block
1198    /// against the codec-scoped `<head>: &str` binding. Now routes
1199    /// through `DialetoError::cabeca_errada(head)`, byte-equal to the
1200    /// pre-lift struct-literal on the same `&str` fixture, so any future
1201    /// widening of the diagnostic shape (e.g. carrying the source-file
1202    /// path alongside the head symbol, carrying the head symbol's
1203    /// position offset for an authoring-surface caret pointer) lands at
1204    /// exactly one dispatch on the substrate primitive rather than re-
1205    /// inlining the struct-literal at every wrong-head fallthrough
1206    /// consumer.
1207    #[must_use]
1208    pub fn cabeca_errada(encontrado: &str) -> Self {
1209        Self::CabecaErrada {
1210            encontrado: encontrado.to_string(),
1211        }
1212    }
1213
1214    /// Construct a [`DialetoError::Leitura`] carrying the offending
1215    /// tatara-lisp reader-error message `reason` verbatim in the
1216    /// variant's tuple-newtype payload.
1217    ///
1218    /// Substrate primitive every [`classify`] tatara-lisp-reader
1219    /// map-err wire-up site now routes through, folding the pre-lift
1220    /// uniform `Self::Leitura(<into-String-expr>)` tuple-newtype
1221    /// construction onto one substrate primitive matching the peer
1222    /// `LimitsError::empty_byte_size` / `LimitsError::empty_duration`
1223    /// (7a4b003 / 319216c) `(String)` single-slot tuple-newtype
1224    /// discipline on the sibling
1225    /// [`crate::limits::LimitsError`] envelope's empty-shape axis of
1226    /// the paired codec-magnitude family. Peer to the sibling
1227    /// [`DialetoError::cabeca_errada`] ctor on the same envelope's
1228    /// wrong-head axis but on the tatara-lisp-reader axis rather than
1229    /// the classifier-fallthrough axis. Closes the last un-lifted
1230    /// variant on [`DialetoError`] — every one of the sole wire-up
1231    /// sites (the [`classify`] tatara-lisp-reader `.map_err(|e|
1232    /// Self::Leitura(e.to_string()))` arm) opened the identical
1233    /// `DialetoError::Leitura(<into-String-expr>)` block against the
1234    /// codec-scoped `String` (`e.to_string()`) binding, so the fold
1235    /// routes the site through one dispatch on a uniform
1236    /// `impl Into<String>` param, byte-equal to the pre-lift
1237    /// tuple-newtype construction on the same argument.
1238    ///
1239    /// The `impl Into<String>` bound covers both wire-up shapes on
1240    /// [`classify`] — a `String` binding (`e.to_string()` on the
1241    /// [`tatara_lisp::Error`]-carrying `e` binding) and a `&str`
1242    /// binding (a future admission-webhook consumer probing a
1243    /// caller-scoped `&'static str` fixture, a future
1244    /// `feira lint --tatara-reader-round-trip` verb sweeping every
1245    /// `tatara_lisp::read` return through the same shape gate) —
1246    /// without forcing the caller to spell the conversion at the
1247    /// wire-up site. Same shape the peer
1248    /// [`crate::limits::LimitsError::empty_byte_size`] /
1249    /// [`crate::limits::LimitsError::empty_duration`] /
1250    /// [`crate::limits::LimitsError::bad_millicores`] /
1251    /// [`crate::limits::LimitsError::bad_byte_magnitude`] /
1252    /// [`crate::limits::LimitsError::bad_duration_magnitude`] folds
1253    /// carry on the peer bad-magnitude and empty-shape axes of the
1254    /// same paired `(String)` tuple-newtype codec-magnitude family.
1255    /// `#[must_use]` fires a compile warning at any wire-up that
1256    /// mistakenly discards the constructed error.
1257    ///
1258    /// Every future consumer that wants to construct this variant
1259    /// outside [`classify`] (a deferred `feira lint --tatara-reader-
1260    /// round-trip` per-caixa admission verb probing each authored
1261    /// manifest against the tatara-lisp-reader shape gate, an M4
1262    /// typed `mesh.pleme.io/v1alpha1/Servico` CR materializer's
1263    /// per-manifest admission validator re-checking one edited
1264    /// `caixa.lisp` against the reader floor, a per-`caixa.lisp`
1265    /// value-shape pre-emitter probing each declared manifest ahead
1266    /// of the operator's admit-cycle) now reaches the variant
1267    /// through one call rather than re-inlining the tuple-newtype
1268    /// block in lockstep with the pre-existing wire-up.
1269    #[must_use]
1270    pub fn leitura(reason: impl Into<String>) -> Self {
1271        Self::Leitura(reason.into())
1272    }
1273}
1274
1275/// Classify a manifest source without committing to either schema.
1276///
1277/// Deliberately reads only the head symbol and the set of top-level keywords —
1278/// enough to route, never enough to half-parse. A classifier that started
1279/// validating would grow into a third parser, which is the shape of the problem
1280/// it exists to name.
1281///
1282/// # Errors
1283/// [`DialetoError`] when the source is not a manifest declaration at all.
1284pub fn classify(src: &str) -> Result<CaixaDialeto, DialetoError> {
1285    let forms = tatara_lisp::read(src).map_err(|e| DialetoError::leitura(e.to_string()))?;
1286    let first = forms.first().ok_or(DialetoError::Vazio)?;
1287    classify_form(first)
1288}
1289
1290/// [`classify`] over an already-read form.
1291///
1292/// # Errors
1293/// [`DialetoError`] when the form is not a manifest declaration.
1294pub fn classify_form(form: &Sexp) -> Result<CaixaDialeto, DialetoError> {
1295    let list = form.as_list().ok_or(DialetoError::NaoEhLista)?;
1296    let head = list
1297        .first()
1298        .and_then(Sexp::as_symbol)
1299        .ok_or(DialetoError::NaoEhLista)?;
1300
1301    match head {
1302        // `defmolde` is unambiguous by construction — it exists precisely so a
1303        // consumer never has to infer which declaration it holds. Both arities
1304        // are the same declaration; the positional one keeps its own variant
1305        // only so a census can report the split.
1306        "defmolde" => {
1307            return Ok(if starts_with_positional_name(&list[1..]) {
1308                CaixaDialeto::MoldePosicional
1309            } else {
1310                CaixaDialeto::Molde
1311            });
1312        }
1313        "defcaixa" => {}
1314        other => {
1315            return Err(DialetoError::cabeca_errada(other));
1316        }
1317    }
1318
1319    let args = &list[1..];
1320
1321    // `(defcaixa <symbol> :kind … :ecosystem …)`. Only the Molde dialect has a
1322    // positional arity; `Caixa` is keyword-only, so a leading bare symbol
1323    // settles it without looking further.
1324    if starts_with_positional_name(args) {
1325        return Ok(CaixaDialeto::MoldePosicional);
1326    }
1327
1328    let keys = top_level_keywords(args);
1329    let has = |k: &str| keys.iter().any(|s| s == k);
1330
1331    // Order matters, and it is not arbitrary: `:nome` and `:name` are the two
1332    // required head slots and no file in the measured corpus carries both.
1333    // Checking them FIRST means the decision rests on the one slot each schema
1334    // makes mandatory, rather than on optional evidence like `:ecosystem`.
1335    if has("nome") {
1336        return Ok(CaixaDialeto::Pacote);
1337    }
1338    if has("name") || has("ecosystem") || has("package") {
1339        return Ok(CaixaDialeto::Molde);
1340    }
1341    Ok(CaixaDialeto::Desconhecido)
1342}
1343
1344/// True when the first argument is a bare symbol rather than a keyword — the
1345/// positional-name arity.
1346fn starts_with_positional_name(args: &[Sexp]) -> bool {
1347    matches!(args.first(), Some(Sexp::Atom(Atom::Symbol(_))))
1348}
1349
1350/// The top-level keyword names (without the leading `:`) of a kwarg list.
1351///
1352/// Steps in pairs so a keyword appearing as a VALUE — `:kind :Biblioteca`, or a
1353/// nested `(:nome "dep" :versao "^0.1")` inside `:deps` — is never counted as a
1354/// top-level slot. A naive scan for `:nome` anywhere in the source classifies
1355/// every Molde manifest with a `:deps` list as a Pacote.
1356fn top_level_keywords(args: &[Sexp]) -> Vec<String> {
1357    let mut out = Vec::new();
1358    let mut i = 0;
1359    while i < args.len() {
1360        if let Sexp::Atom(Atom::Keyword(k)) = &args[i] {
1361            out.push(k.clone());
1362            i += 2;
1363        } else {
1364            i += 1;
1365        }
1366    }
1367    out
1368}
1369
1370#[cfg(test)]
1371mod tests {
1372    use super::*;
1373
1374    const PACOTE: &str = r#"
1375      (defcaixa
1376        :nome   "checkout"
1377        :versao "0.1.0"
1378        :kind   Servico
1379        :deps   ((:nome "caixa-teia" :versao "^0.1")))
1380    "#;
1381
1382    const MOLDE: &str = r#"
1383      (defcaixa
1384        :name "base64"
1385        :kind :Biblioteca
1386        :ecosystem :rust-single-crate
1387        :package {:name "base64" :version "0.22.1"}
1388        :workflows [:auto-release])
1389    "#;
1390
1391    const MOLDE_POSICIONAL: &str = r#"
1392      (defcaixa todoku-go
1393        :kind :Biblioteca
1394        :ecosystem :go
1395        :package {:name "todoku-go" :version "0.3.0"})
1396    "#;
1397
1398    #[test]
1399    fn the_package_dialect_is_recognised() {
1400        assert_eq!(classify(PACOTE), Ok(CaixaDialeto::Pacote));
1401    }
1402
1403    #[test]
1404    fn the_repo_surface_dialect_is_recognised() {
1405        assert_eq!(classify(MOLDE), Ok(CaixaDialeto::Molde));
1406    }
1407
1408    #[test]
1409    fn the_positional_arity_is_recognised() {
1410        assert_eq!(
1411            classify(MOLDE_POSICIONAL),
1412            Ok(CaixaDialeto::MoldePosicional)
1413        );
1414    }
1415
1416    #[test]
1417    fn defmolde_classifies_without_inference() {
1418        // The whole point of the new keyword: no schema sniffing required.
1419        let src = r#"(defmolde :name "x" :kind :Biblioteca :ecosystem :go)"#;
1420        assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1421        let pos = r"(defmolde todoku-go :kind :Biblioteca :ecosystem :go)";
1422        assert_eq!(classify(pos), Ok(CaixaDialeto::MoldePosicional));
1423    }
1424
1425    #[test]
1426    fn a_nested_nome_does_not_make_a_repo_surface_look_like_a_package() {
1427        // The exact failure a substring scan produces: `:deps ((:nome …))`
1428        // contains `:nome`, but not as a top-level slot.
1429        let src = r#"
1430          (defcaixa
1431            :name "x"
1432            :ecosystem :rust-single-crate
1433            :deps ((:nome "inner" :versao "^0.1")))
1434        "#;
1435        assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1436    }
1437
1438    #[test]
1439    fn a_keyword_in_value_position_is_not_a_slot() {
1440        // `:kind :Biblioteca` — the value is itself a keyword. Stepping one at
1441        // a time would read `:Biblioteca` as a top-level slot.
1442        let src = r#"(defcaixa :kind :Biblioteca :name "x")"#;
1443        assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1444    }
1445
1446    #[test]
1447    fn an_unrecognised_defcaixa_is_reported_not_guessed() {
1448        let src = r#"(defcaixa :licenca "MIT")"#;
1449        assert_eq!(classify(src), Ok(CaixaDialeto::Desconhecido));
1450    }
1451
1452    #[test]
1453    fn a_form_that_is_not_a_manifest_is_an_error_not_a_dialect() {
1454        assert_eq!(
1455            classify("(defflake :nome \"x\")"),
1456            Err(DialetoError::cabeca_errada("defflake"))
1457        );
1458        assert_eq!(classify(""), Err(DialetoError::Vazio));
1459    }
1460
1461    #[test]
1462    fn every_dialect_names_its_consumer_and_its_canonical_keyword() {
1463        // Guards the routing table itself: a new variant added without an arm
1464        // here is a compile error in the match, and a variant that claims
1465        // `defcaixa` while being read by pleme-doc-gen would re-open the
1466        // collision this module closes. Sweeps [`CaixaDialeto::ALL`] rather
1467        // than the pre-lift open-coded four-arm literal list — a future arm
1468        // addition extends the slice as one edit and this pin picks it up
1469        // by construction.
1470        for &d in CaixaDialeto::ALL {
1471            assert!(!d.descricao().is_empty(), "{d}");
1472            assert!(!d.consumidor().is_empty(), "{d}");
1473        }
1474        assert_eq!(CaixaDialeto::Pacote.palavra_canonica(), "defcaixa");
1475        assert_eq!(CaixaDialeto::Molde.palavra_canonica(), "defmolde");
1476        assert_ne!(
1477            CaixaDialeto::Pacote.palavra_canonica(),
1478            CaixaDialeto::Molde.palavra_canonica(),
1479            "the two dialects must not share a canonical keyword — that IS the defect"
1480        );
1481    }
1482
1483    #[test]
1484    fn caixa_dialeto_all_enumerates_every_variant_exactly_once() {
1485        // Three-legged exhaustiveness pin, peer of the sibling
1486        // `caixa_kind_all_enumerates_every_variant_exactly_once`
1487        // (caixa-core/src/kind.rs) /
1488        // `restart_strategy_all_enumerates_every_variant_exactly_once`
1489        // (caixa-core/src/supervisor.rs) shape.
1490        //
1491        // 1. arm-count invariant: `ALL.len()` matches the declared arm
1492        //    count (four — a fifth arm added without extending `ALL`
1493        //    fails this pin at caixa-core test time);
1494        // 2. pairwise-distinctness invariant: every variant appears at
1495        //    most once in the slice (a duplicate arm would silently
1496        //    double-count in the census consumer, so the pin rejects
1497        //    duplicates outright);
1498        // 3. coverage invariant: every literal `CaixaDialeto::X` is in
1499        //    the slice (the compiler-checked exhaustiveness on the peer
1500        //    per-arm `match self` in the accessors keeps the enum arm
1501        //    set and the `ALL` slice mutually aligned).
1502        assert_eq!(
1503            CaixaDialeto::ALL.len(),
1504            4,
1505            "ALL must list every arm exactly once; a fifth arm added \
1506             without extending ALL fails this pin — extend ALL alongside \
1507             the new variant"
1508        );
1509
1510        let mut seen: Vec<CaixaDialeto> = Vec::new();
1511        for &d in CaixaDialeto::ALL {
1512            assert!(
1513                !seen.contains(&d),
1514                "ALL contains a duplicate arm: {d}. Every variant appears \
1515                 exactly once — a duplicate would double-count in every \
1516                 iteration consumer"
1517            );
1518            seen.push(d);
1519        }
1520
1521        // Coverage: exhaustively assert every literal variant is somewhere
1522        // in the slice. Written as an exhaustive `match` so a future arm
1523        // addition fails to compile here (missing match arm) until the
1524        // corresponding `assert` is added — the compiler enforces the pin's
1525        // completeness rather than a hand-maintained variant list.
1526        for variant in [
1527            CaixaDialeto::Pacote,
1528            CaixaDialeto::Molde,
1529            CaixaDialeto::MoldePosicional,
1530            CaixaDialeto::Desconhecido,
1531        ] {
1532            let coverage_probe = match variant {
1533                CaixaDialeto::Pacote
1534                | CaixaDialeto::Molde
1535                | CaixaDialeto::MoldePosicional
1536                | CaixaDialeto::Desconhecido => variant,
1537            };
1538            assert!(
1539                CaixaDialeto::ALL.contains(&coverage_probe),
1540                "ALL is missing variant {coverage_probe} — extend the slice"
1541            );
1542        }
1543    }
1544
1545    #[test]
1546    fn caixa_dialeto_all_is_const_and_matches_iteration_count() {
1547        // Pins the const-ness of the slice at const-fold time. A future
1548        // change that promoted `ALL` to a non-const initializer (a lazy-
1549        // static, a runtime-computed Vec) would fail to compile here —
1550        // the pin locks in the compile-time-known iteration surface
1551        // every consumer builds against. Peer of the sibling
1552        // `caixa_kind_all_is_const_and_matches_iteration_count` (kind.rs)
1553        // / `restart_strategy_all_is_const_and_matches_iteration_count`
1554        // (supervisor.rs) shape.
1555        const ALL: &[CaixaDialeto] = CaixaDialeto::ALL;
1556        assert_eq!(ALL.len(), CaixaDialeto::ALL.len());
1557        // Sweep the iterator without collapsing to `.len()` so a future
1558        // change to `ALL`'s carrier that decouples `.len()` from the
1559        // iteration count (a lazy-computed shape, an alias `impl Iterator`
1560        // return, a wrapper newtype) still passes here iff the two agree
1561        // arm-for-arm; the `#[allow]` opts this local pin out of the
1562        // clippy `iter_count` collapse that would defeat the intent.
1563        #[allow(clippy::iter_count)]
1564        let iterated = ALL.iter().count();
1565        assert_eq!(iterated, CaixaDialeto::ALL.len());
1566    }
1567
1568    #[test]
1569    fn caixa_dialeto_all_covers_every_variant_by_display_probe() {
1570        // Fanning `Display` over the slice sweeps the paired accessors
1571        // ([`CaixaDialeto::palavra_canonica`] / [`CaixaDialeto::consumidor`]
1572        // / [`CaixaDialeto::descricao`]) at every arm — every returned
1573        // byte-string is non-empty (the accessors' contract). A future
1574        // arm added without extending its per-arm `match self` return
1575        // would compile-fail at the accessor call inside the loop;
1576        // together with the `ALL.len() == 4` pin above, this locks the
1577        // accessor arm-set and the `ALL` slice mutually.
1578        for &d in CaixaDialeto::ALL {
1579            let display_form = d.to_string();
1580            assert!(
1581                !display_form.is_empty(),
1582                "Display must render a non-empty byte-string for every \
1583                 arm; empty: {d:?}"
1584            );
1585            // Consumidor / descricao / palavra-canonica must each surface
1586            // a non-empty scalar; every downstream diagnostic consumer
1587            // reaches through these accessors.
1588            assert!(!d.palavra_canonica().is_empty(), "{d}");
1589            assert!(!d.consumidor().is_empty(), "{d}");
1590            assert!(!d.descricao().is_empty(), "{d}");
1591        }
1592    }
1593
1594    #[test]
1595    fn caixa_dialeto_as_str_returns_pascal_case_variant_name() {
1596        // Fail-before-pass-after per-arm shape pin: the four
1597        // [`CaixaDialeto::as_str`] arms must return the canonical
1598        // `PascalCase` byte-string that names the variant. Pre-lift this
1599        // byte-string existed only inside the hand-rolled Display impl's
1600        // four-arm literal-string match — every consumer that wanted the
1601        // `PascalCase` name reached through `format!("{d}")`'s allocation
1602        // path. Pinning the four arms explicitly here refuses a future
1603        // regression that ever reroutes an arm to a distinct spelling
1604        // (`"pacote"` lowercase, `"MoldePositional"` English rebrand,
1605        // `"Unknown"` for `Desconhecido`) — the census output and the
1606        // typed accessor would silently disagree until a downstream
1607        // consumer surfaced the drift at census time. Peer of the sibling
1608        // [`crate::supervisor::tests::restart_strategy_variants_serialize_to_lifted_scalar_values`]
1609        // / `placement_strategy_variants_serialize_to_lifted_scalar_values`
1610        // / `caixa_kind_as_str_returns_lifted_peer_const` shape on the
1611        // sibling closed-set typed-enum discriminator axes — the seventh
1612        // (and last unlifted) closed-set typed enum on the caixa surface
1613        // to converge onto the same per-arm-shape-pin discipline.
1614        for (variant, expected) in [
1615            (CaixaDialeto::Pacote, "Pacote"),
1616            (CaixaDialeto::Molde, "Molde"),
1617            (CaixaDialeto::MoldePosicional, "MoldePosicional"),
1618            (CaixaDialeto::Desconhecido, "Desconhecido"),
1619        ] {
1620            assert_eq!(
1621                variant.as_str(),
1622                expected,
1623                "CaixaDialeto::{variant:?}.as_str() must return the \
1624                 canonical `PascalCase` variant-name byte-string; drift here \
1625                 splits the census-facing text from the substrate \
1626                 primitive every downstream consumer will read"
1627            );
1628        }
1629    }
1630
1631    #[test]
1632    fn caixa_dialeto_display_routes_through_as_str_helper() {
1633        // Fail-before-pass-after convergence pin: for every arm in
1634        // [`CaixaDialeto::ALL`], the [`std::fmt::Display`] rendered form
1635        // must byte-equal [`CaixaDialeto::as_str`]'s return value. Pre-
1636        // lift these two paths were structurally independent — the
1637        // Display impl hand-rolled its own four-arm literal-string
1638        // match with no compile-time link back to any substrate accessor
1639        // — so a future variant rename could land at `Display` without
1640        // touching a paired accessor (or vice versa), silently splitting
1641        // the two paths on the renamed arm. Pinning the byte-equality
1642        // here makes any such split a caixa-core build-time failure at
1643        // this test rather than surfacing far from the rename commit as
1644        // a downstream census consumer emitting one spelling while the
1645        // typed accessor returned another. Peer of the sibling
1646        // [`crate::kind::tests::caixa_kind_display_routes_through_as_str_helper`]
1647        // (which pins the same convergence on the [`crate::CaixaKind`]
1648        // closed-set axis) — extends the discipline onto the seventh
1649        // (and last unlifted) closed-set fieldless typed enum on the
1650        // caixa surface.
1651        for &variant in CaixaDialeto::ALL {
1652            assert_eq!(
1653                variant.to_string(),
1654                variant.as_str(),
1655                "CaixaDialeto::{variant:?} Display must route through \
1656                 CaixaDialeto::as_str (single source of truth: the \
1657                 lifted per-arm `PascalCase` variant-name byte-string)"
1658            );
1659        }
1660    }
1661
1662    #[test]
1663    fn caixa_dialeto_as_ref_str_routes_through_as_str_accessor() {
1664        // Fail-before-pass-after byte-parity pin on the lifted
1665        // `impl AsRef<str> for CaixaDialeto` — asserts the standard-
1666        // library trait impl and the substrate-primitive
1667        // [`CaixaDialeto::as_str`] `pub const fn` accessor resolve to
1668        // the same `&str` per instance across the four-arm closed set,
1669        // so any future silent detour that routes the impl through a
1670        // divergent projection (a per-arm inline
1671        // `match self { CaixaDialeto::Pacote => "Pacote", … }` re-inlining
1672        // that opens a compile-time link to the un-lifted arm-literal,
1673        // a swap onto the second-axis
1674        // [`CaixaDialeto::palavra_canonica`] /
1675        // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
1676        // accessors that carry distinct byte-shapes per axis) trips at
1677        // caixa-core test time under `PartialEq` rather than at a
1678        // downstream `impl AsRef<str>`-bound consumer's silent split.
1679        // Sweeps every one of the four arms [`CaixaDialeto::ALL`]
1680        // carries so no arm's projection is covered only by the sibling
1681        // `Display` path. Peer of the sibling
1682        // `rate_limit_unit_as_ref_str_routes_through_as_suffix_accessor`
1683        // (d8136db) on the M3 `:politicas :rate-limit` closed-set typed
1684        // enum, and the peer
1685        // [`crate::kind::tests::caixa_kind_as_ref_str_routes_through_as_str_accessor`]
1686        // (cd2091f) pin on the top-level closed-set typed
1687        // discriminator — the pins together close the substrate
1688        // primitive's `AsRef<str>` projection axis onto the seventh
1689        // closed-set fieldless typed enum on the caixa surface.
1690        for &variant in CaixaDialeto::ALL {
1691            assert_eq!(
1692                <CaixaDialeto as AsRef<str>>::as_ref(&variant),
1693                variant.as_str(),
1694                "AsRef<str> impl on CaixaDialeto::{variant:?} must \
1695                 byte-equal CaixaDialeto::as_str on the same instance \
1696                 — divergence signals a silent detour off the \
1697                 substrate-primitive accessor"
1698            );
1699        }
1700    }
1701
1702    #[test]
1703    fn caixa_dialeto_as_ref_str_routes_through_display_via_shared_accessor() {
1704        // Fail-before-pass-after byte-parity pin on the three-path
1705        // convergence discipline the [`CaixaDialeto`] closed-set
1706        // dialect-classification enum now carries on the `&str`-
1707        // projection axis: `<CaixaDialeto as AsRef<str>>::as_ref(&v)`
1708        // (the newly lifted impl), `format!("{v}")` (the pre-existing
1709        // [`fmt::Display`] impl), and `v.as_str()` (the substrate-
1710        // primitive `pub const fn` accessor both trait impls delegate
1711        // through) must resolve to the same byte-string on every
1712        // instance across the four-arm closed set. Refuses any future
1713        // divergence between the two trait impls (a stray
1714        // [`fmt::Display::fmt`] rewrite that hand-rolls the arms
1715        // rather than delegating through the shared accessor; a
1716        // hypothetical `AsRef<str>` rewrite that inlines a per-arm
1717        // literal cascade) that would silently split the two
1718        // projection paths of the same closed-set typed enum. Mirrors
1719        // the sibling three-path-convergence discipline the peer
1720        // [`crate::aplicacao::RateLimitUnit`] typed enum carries
1721        // (`rate_limit_unit_as_ref_str_routes_through_display_via_shared_accessor`,
1722        // d8136db), the peer [`crate::CaixaKind`] triple
1723        // (`caixa_kind_as_ref_str_routes_through_display_via_shared_accessor`,
1724        // cd2091f), and the [`crate::CaixaVersion`] typed newtype
1725        // triple (`caixa_version_as_ref_str_routes_through_display_via_shared_accessor`,
1726        // 16d5c7e).
1727        for &variant in CaixaDialeto::ALL {
1728            let via_as_ref: &str = <CaixaDialeto as AsRef<str>>::as_ref(&variant);
1729            let via_display: String = format!("{variant}");
1730            let via_accessor: &str = variant.as_str();
1731            assert_eq!(via_as_ref, via_accessor);
1732            assert_eq!(via_display, via_accessor);
1733            assert_eq!(via_as_ref, via_display.as_str());
1734        }
1735    }
1736
1737    #[test]
1738    fn caixa_dialeto_is_molde_family_returns_true_on_molde_and_positional_arms() {
1739        // Fail-before-pass-after per-arm shape pin on the two `defmolde`
1740        // declaration-family arms: [`CaixaDialeto::is_molde_family`] must
1741        // return `true` for [`CaixaDialeto::Molde`] and
1742        // [`CaixaDialeto::MoldePosicional`] — the two-arity closure of
1743        // one declaration ([`CaixaDialeto::MoldePosicional`]'s docstring:
1744        // "same declaration as [`Self::Molde`], written with the package
1745        // name as a bare positional symbol … one arity of one
1746        // declaration, not a third schema"). A future accidental flip that
1747        // reversed a per-arm arm's return without touching the paired
1748        // false-arm pin would silently open the substrate primitive to
1749        // false-positive on either arm — the `feira dialeto` verb's
1750        // `--strict-palavra` gate would then silently accept
1751        // repo-surface declarations under `(defcaixa …)` on one arm and
1752        // reject them on the other. Pinning the two true arms explicitly
1753        // here refuses that split at caixa-core build time.
1754        assert!(
1755            CaixaDialeto::Molde.is_molde_family(),
1756            "CaixaDialeto::Molde.is_molde_family() must return true — \
1757             Molde is the primary `defmolde` arm"
1758        );
1759        assert!(
1760            CaixaDialeto::MoldePosicional.is_molde_family(),
1761            "CaixaDialeto::MoldePosicional.is_molde_family() must return \
1762             true — MoldePosicional is the positional-arity form of the \
1763             same `defmolde` declaration Molde carries"
1764        );
1765    }
1766
1767    #[test]
1768    fn caixa_dialeto_is_molde_family_returns_false_on_pacote_and_desconhecido_arms() {
1769        // Fail-before-pass-after per-arm shape pin on the two non-`defmolde`
1770        // arms: [`CaixaDialeto::is_molde_family`] must return `false` for
1771        // [`CaixaDialeto::Pacote`] (the sibling `defcaixa` tatara-lisp
1772        // package manifest, `palavra_canonica → "defcaixa"`) and for
1773        // [`CaixaDialeto::Desconhecido`] (the residue that names no
1774        // known declaration, `palavra_canonica → "?"`). Pinning the two
1775        // false arms explicitly here refuses a future accidental flip
1776        // that let the predicate widen to include either arm — the
1777        // `feira dialeto` verb's `--strict-palavra` gate would then
1778        // spuriously refuse every `(defcaixa …)` package manifest as if
1779        // it were a repo-surface declaration.
1780        assert!(
1781            !CaixaDialeto::Pacote.is_molde_family(),
1782            "CaixaDialeto::Pacote.is_molde_family() must return false — \
1783             Pacote is the `defcaixa` tatara-lisp package manifest, not \
1784             the `defmolde` repo-surface declaration"
1785        );
1786        assert!(
1787            !CaixaDialeto::Desconhecido.is_molde_family(),
1788            "CaixaDialeto::Desconhecido.is_molde_family() must return \
1789             false — the residue arm names no known declaration; it is \
1790             not silently promoted into the `defmolde` family"
1791        );
1792    }
1793
1794    #[test]
1795    fn caixa_dialeto_is_molde_family_agrees_with_palavra_canonica_defmolde_projection() {
1796        // Load-bearing pin: for every arm in [`CaixaDialeto::ALL`], the
1797        // typed [`CaixaDialeto::is_molde_family`] predicate must agree
1798        // byte-for-byte with the paired [`CaixaDialeto::palavra_canonica`]
1799        // projection's `== "defmolde"` classifier — i.e. the two paths
1800        // partition the four-arm discriminator set into the same
1801        // `{Molde, MoldePosicional}` and `{Pacote, Desconhecido}` halves.
1802        // Pre-lift the sibling [`CaixaDialeto::palavra_canonica`] projection
1803        // (which returns `"defmolde"` for `Molde | MoldePosicional`,
1804        // `"defcaixa"` for `Pacote`, `"?"` for `Desconhecido`) was the
1805        // only substrate-side surface carrying the two-arm collapse; the
1806        // hand-rolled `matches!(d, CaixaDialeto::Molde |
1807        // CaixaDialeto::MoldePosicional)` sites in the `feira dialeto`
1808        // verb expressed no compile-time link back to it. A future arm
1809        // addition — the module doc's "third dialect" hazard actualises
1810        // as a fifth arm belonging to the `defmolde` family — would land
1811        // one match arm at [`Self::palavra_canonica`]'s `defmolde` return
1812        // (extending the sibling projection) but silently split the
1813        // hand-rolled two-arm `matches!` predicate sites if the new arm's
1814        // `is_molde_family` return were forgotten. Pinning byte-equality
1815        // between the two paths here makes any such split a caixa-core
1816        // build-time failure at this test rather than surfacing far from
1817        // the arm-addition commit as a downstream `--strict-palavra` /
1818        // `caixa.lisp`-holds-wrong-declaration gate silently ignoring the
1819        // new arm.
1820        for &d in CaixaDialeto::ALL {
1821            let via_palavra_canonica = d.palavra_canonica() == "defmolde";
1822            let via_is_molde_family = d.is_molde_family();
1823            assert_eq!(
1824                via_is_molde_family, via_palavra_canonica,
1825                "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
1826                 must agree with CaixaDialeto::{d:?}.palavra_canonica() == \
1827                 \"defmolde\" ({via_palavra_canonica}) — a split between the \
1828                 typed predicate and the sibling keyword projection would let \
1829                 a future arm addition land at one path and drift at the other, \
1830                 which is exactly the drift this pin refuses"
1831            );
1832        }
1833    }
1834
1835    #[test]
1836    fn caixa_dialeto_is_molde_family_is_const_fn() {
1837        // Const-context pin: [`CaixaDialeto::is_molde_family`] must remain
1838        // `const fn` (its match is a fieldless-arm literal-pattern
1839        // discriminator, so no non-const operation exists on the resolution
1840        // path). Downstream consumers reaching for the predicate from a
1841        // `const` context (a future substrate-wide const-fold-driven audit
1842        // table that materializes per-arm gate-membership at build time,
1843        // a per-arm CR-admission-webhook gate registration in a `const`
1844        // context) rely on the const-ness. A future accidental downgrade
1845        // to non-`const` (an added runtime helper reachable only from a
1846        // non-`const` context) trips at caixa-core build time rather than
1847        // surfacing as a downstream `const`-context regression far from
1848        // the predicate declaration. Peer of the sibling
1849        // [`caixa_dialeto_as_str_is_const_fn`] pin on the paired
1850        // [`CaixaDialeto::as_str`] byte-string axis.
1851        const ARMS: [(CaixaDialeto, bool); 4] = [
1852            (CaixaDialeto::Pacote, CaixaDialeto::Pacote.is_molde_family()),
1853            (CaixaDialeto::Molde, CaixaDialeto::Molde.is_molde_family()),
1854            (
1855                CaixaDialeto::MoldePosicional,
1856                CaixaDialeto::MoldePosicional.is_molde_family(),
1857            ),
1858            (
1859                CaixaDialeto::Desconhecido,
1860                CaixaDialeto::Desconhecido.is_molde_family(),
1861            ),
1862        ];
1863        // Materialize the const-fold-evaluated table into a runtime slice
1864        // assertion — carries the same `bool = const fn call` shape a raw
1865        // `assert!(const_bool)` would, without tripping the
1866        // `assertions_on_constants` clippy lint that a per-arm
1867        // `assert!(CONST)` on a `const bool` triggers when the arm-count
1868        // is enumerated flat rather than compared as a whole-table shape.
1869        assert_eq!(
1870            ARMS,
1871            [
1872                (CaixaDialeto::Pacote, false),
1873                (CaixaDialeto::Molde, true),
1874                (CaixaDialeto::MoldePosicional, true),
1875                (CaixaDialeto::Desconhecido, false),
1876            ],
1877            "CaixaDialeto::is_molde_family() must evaluate in const context \
1878             for every arm and land on the {{false, true, true, false}} \
1879             partition — a future accidental downgrade to non-`const` \
1880             would trip the const-context array-initializer here"
1881        );
1882    }
1883
1884    #[test]
1885    fn caixa_dialeto_as_str_is_const_fn() {
1886        // Const-context pin: [`CaixaDialeto::as_str`] must remain
1887        // `const fn` (its match arms return `pub const` byte-strings, so
1888        // no non-const operation exists on the resolution path).
1889        // Downstream consumers reaching for the accessor from a `const`
1890        // context (a future substrate-wide const-fold-driven audit table
1891        // that materializes every dialect's census label at build time,
1892        // a per-arm CR-admission-webhook message registration in a
1893        // `const` gate) rely on the const-ness. A future accidental
1894        // downgrade to non-`const` (an added runtime helper reachable
1895        // only from a non-`const` context, a manual hand-rolled `impl`
1896        // that shadows this method) trips at caixa-core build time
1897        // rather than surfacing as a downstream `const`-context
1898        // regression far from the accessor declaration. Peer of the
1899        // sibling [`crate::kind::tests::caixa_kind_wire_name_is_const_fn`]
1900        // pin on the paired [`crate::CaixaKind`] byte-string axis.
1901        const PACOTE: &str = CaixaDialeto::Pacote.as_str();
1902        const MOLDE: &str = CaixaDialeto::Molde.as_str();
1903        const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
1904        const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
1905        assert_eq!(PACOTE, "Pacote");
1906        assert_eq!(MOLDE, "Molde");
1907        assert_eq!(MOLDE_POSICIONAL, "MoldePosicional");
1908        assert_eq!(DESCONHECIDO, "Desconhecido");
1909    }
1910
1911    #[test]
1912    fn caixa_dialeto_is_variant_predicates_partition_the_arm_set() {
1913        // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
1914        // derive: for each of the four variants at [`CaixaDialeto::ALL`]`[idx]`
1915        // the observed four-slot predicate row must equal a one-hot row
1916        // with the `true` at exactly `idx`. Pre-derive the closed four-arm
1917        // dialect-classification partition lived only inside the paired
1918        // per-arm projections' four-arm match resolvers ([`Self::as_str`] /
1919        // [`Self::palavra_canonica`] / [`Self::consumidor`] /
1920        // [`Self::descricao`]) plus the two-arm [`Self::is_molde_family`]
1921        // hand-rolled `matches!` (now routed through the derived
1922        // predicates); a future rebrand (an accidental
1923        // `#[is_variant(name = "…")]` drift, a manual hand-rolled `impl`
1924        // that shadows the derive-generated method, an arm rename that
1925        // reroutes one arm through the wrong predicate lane) trips this
1926        // pin at caixa-core build time rather than surfacing far from the
1927        // derive declaration as a downstream [`Self::is_molde_family`]
1928        // consumer accepting the wrong arm-set. The expected row is
1929        // generated live from the [`Self::ALL`] declaration order rather
1930        // than transcribed by hand so a copy-paste flip reroutes at the
1931        // identity-diagonal assertion.
1932        //
1933        // Peer of the sibling
1934        // [`crate::kind::tests::caixa_kind_is_variant_predicates_partition_the_arm_set`]
1935        // / [`crate::supervisor::tests::restart_strategy_is_variant_predicates_partition_the_arm_set`]
1936        // / [`crate::aplicacao::tests::placement_strategy_is_variant_predicates_partition_the_arm_set`]
1937        // / [`crate::upgrade::tests::upgrade_instruction_is_variant_predicates_partition_the_arm_set`]
1938        // pins on the sibling closed-set typed-enum discriminator axes.
1939        for (idx, &variant) in CaixaDialeto::ALL.iter().enumerate() {
1940            let observed = [
1941                variant.is_pacote(),
1942                variant.is_molde(),
1943                variant.is_molde_posicional(),
1944                variant.is_desconhecido(),
1945            ];
1946            let mut expected = [false; 4];
1947            expected[idx] = true;
1948            assert_eq!(
1949                observed, expected,
1950                "CaixaDialeto::{variant:?} at ALL[{idx}] is_* predicates \
1951                 must fire only on their own arm lane (identity diagonal); \
1952                 got {observed:?}",
1953            );
1954        }
1955    }
1956
1957    #[test]
1958    fn caixa_dialeto_is_variant_predicates_are_const_fn() {
1959        // The [`gen_platform::IsVariant`] derive emits `const fn`
1960        // predicates on the peer [`crate::CaixaKind`] +
1961        // [`crate::upgrade::UpgradeInstruction`] +
1962        // [`crate::supervisor::RestartStrategy`] +
1963        // [`crate::supervisor::RestartPolicy`] +
1964        // [`crate::aplicacao::PlacementStrategy`] +
1965        // [`crate::aplicacao::RateLimitUnit`] +
1966        // [`crate::dep::DepList`] closed-set typed enums — pin the same
1967        // posture on [`CaixaDialeto`] so a future accidental downgrade
1968        // to non-`const` (an added runtime helper reachable only from a
1969        // non-`const` context, a manual hand-rolled `impl` that shadows
1970        // the derive-generated method) trips at caixa-core build time
1971        // rather than surfacing as a downstream `const`-context
1972        // regression far from the derive declaration.
1973        // Use `const { assert!(…) }` (peer of the sibling
1974        // [`crate::render::PathShapeViolation`] +
1975        // [`crate::aplicacao::RateLimitUnit`] +
1976        // [`caixa_theme::style::Semantic`] const-fn pins) so the
1977        // const-context evaluation trips at const-fold time without
1978        // opening a per-`const bool` `assertions_on_constants` clippy
1979        // debt row this crate does not carry today for `dialeto.rs`.
1980        const { assert!(CaixaDialeto::Pacote.is_pacote()) };
1981        const { assert!(CaixaDialeto::Molde.is_molde()) };
1982        const { assert!(CaixaDialeto::MoldePosicional.is_molde_posicional()) };
1983        const { assert!(CaixaDialeto::Desconhecido.is_desconhecido()) };
1984    }
1985
1986    #[test]
1987    fn caixa_dialeto_from_wire_accepts_every_as_str_output() {
1988        // Fail-before-pass-after per-arm accept pin on the newly lifted
1989        // [`CaixaDialeto::from_wire`] reverse projection: every arm in
1990        // [`CaixaDialeto::ALL`] must parse back through `from_wire` when
1991        // fed its own [`CaixaDialeto::as_str`] output, landing on
1992        // `Some(same_variant)` — a regression that hand-rolled either
1993        // side's per-arm match without threading through the shared
1994        // four-string closed set would silently disagree on any future
1995        // arm rename and this pin flags it at caixa-core build time.
1996        // Peer of the sibling
1997        // [`crate::kind::tests::caixa_kind_wire_round_trips_through_from_wire`]
1998        // (2aa6d23) /
1999        // `placement_strategy_from_wire_accepts_every_lifted_constant`
2000        // (18c7342) /
2001        // `dep_list_round_trips_through_as_str_and_from_wire` (45ee563)
2002        // shape on the sibling closed-set typed-enum reverse-projection
2003        // axes.
2004        for &variant in CaixaDialeto::ALL {
2005            let wire = variant.as_str();
2006            let parsed = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
2007                panic!(
2008                    "CaixaDialeto::from_wire({wire:?}) must accept every \
2009                     CaixaDialeto::as_str output — got None for the \
2010                     wire byte-string of {variant:?}"
2011                )
2012            });
2013            assert_eq!(
2014                parsed, variant,
2015                "CaixaDialeto::from_wire(CaixaDialeto::{variant:?}.as_str()) \
2016                 must return CaixaDialeto::{variant:?} — the (as_str, \
2017                 from_wire) pair must form a total round-trip on the \
2018                 closed four-arm CaixaDialeto arm-set"
2019            );
2020        }
2021    }
2022
2023    #[test]
2024    fn caixa_dialeto_from_wire_rejects_unknown_byte_strings() {
2025        // Rejection pin on the parser's accept-set: any string outside
2026        // the four-arm [`CaixaDialeto::as_str`] output set must return
2027        // `None`. A future accidental widening of the accept-set (a
2028        // case-insensitive match that accepts `"pacote"` on the wire
2029        // axis, a hand-rolled Levenshtein-forgiving arm-lookup that
2030        // admits `"Pacotee"` typos, a silent acceptance of the sibling
2031        // [`Self::palavra_canonica`] `"defcaixa"` / `"defmolde"`
2032        // byte-shapes on this axis) would silently drift the parser's
2033        // accept-set from the emitter's — a downstream audit-report
2034        // re-loader that bound a prior audit's [`Self::as_str`] output
2035        // back to the typed enum through this parser would then bind a
2036        // malformed byte-string to a plausibly-wrong typed arm the
2037        // caller does not route through any fallback, silently
2038        // misclassifying the reloaded row. Also rejects the sibling
2039        // [`Self::palavra_canonica`] (`"defcaixa"` / `"defmolde"`) and
2040        // the sibling [`Self::consumidor`] (`"caixa-core / feira"`,
2041        // `"pleme-doc-gen"`, `"nobody known"`) byte-shapes, which are
2042        // the substrate's *distinct-axis* projections on the same enum
2043        // — the two-axis split the sibling
2044        // [`Self::palavra_canonica`] / [`Self::consumidor`] /
2045        // [`Self::descricao`] docstrings explicitly frame forbids
2046        // accepting one axis's byte-shapes as parseable on the other
2047        // axis. Peer of the sibling
2048        // [`crate::kind::tests::caixa_kind_from_wire_rejects_unknown_byte_strings`]
2049        // (2aa6d23) /
2050        // `placement_strategy_from_wire_rejects_unknown_byte_strings`
2051        // (18c7342) /
2052        // `dep_list_from_wire_returns_none_on_unknown_wire_scalar`
2053        // (45ee563) rejection pins on the sibling closed-set typed-enum
2054        // reverse-projection axes.
2055        for bad in [
2056            "",
2057            " ",
2058            "pacote",
2059            "PACOTE",
2060            "molde",
2061            "MoldePositional",
2062            "desconhecido",
2063            "Unknown",
2064            "defcaixa",
2065            "defmolde",
2066            "?",
2067            "caixa-core / feira",
2068            "pleme-doc-gen",
2069            "nobody known",
2070            "Pacote ",
2071            " Pacote",
2072        ] {
2073            assert!(
2074                CaixaDialeto::from_wire(bad).is_none(),
2075                "CaixaDialeto::from_wire({bad:?}) must return None — the \
2076                 parser's accept-set is exactly the four CaixaDialeto::as_str \
2077                 outputs; a widening would silently split the parser's \
2078                 accept-set from the emitter's arm-set"
2079            );
2080        }
2081    }
2082
2083    #[test]
2084    fn cabeca_errada_ctor_matches_struct_literal_wrap() {
2085        // Fail-before-pass-after byte-identity pin: the lifted
2086        // [`DialetoError::cabeca_errada`] ctor MUST land on the exact
2087        // same struct-literal shape the pre-lift open-coded wire-up
2088        // block wrote by hand — `DialetoError::CabecaErrada {
2089        // encontrado: <head>.to_string() }`. A future accidental
2090        // divergence (`.into()` swap, per-arm constant substitution, an
2091        // added default field, an `.to_ascii_lowercase()` normalization
2092        // silently injected into the ctor body, a rebrand of the
2093        // `encontrado` field carrying a distinct byte-shape) trips this
2094        // pin at caixa-core build time rather than surfacing far from
2095        // the ctor declaration as a downstream `classify_form`
2096        // wrong-head consumer emitting one diagnostic shape while a
2097        // hand-written test peer opens another. Peer of the sibling
2098        // `unknown_byte_unit_ctor_matches_struct_literal_wrap`
2099        // (limits.rs; 29fac09) / `duplicate_from_ctor_matches_struct_
2100        // literal_wrap` (upgrade.rs; 7e52aec) shape on the sibling
2101        // single-slot `{ <field>: String }` envelope constructors.
2102        assert_eq!(
2103            DialetoError::cabeca_errada("defflake"),
2104            DialetoError::CabecaErrada {
2105                encontrado: "defflake".to_string(),
2106            },
2107            "DialetoError::cabeca_errada must byte-equal the pre-lift \
2108             open-coded struct-literal — a drift here means the ctor \
2109             stopped being a substrate primitive for the wrong-head \
2110             fallthrough site"
2111        );
2112    }
2113
2114    #[test]
2115    fn cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs() {
2116        // Fail-before-pass-after boundary-sweep pin: the lifted
2117        // [`DialetoError::cabeca_errada`] ctor MUST route its
2118        // `encontrado: &str` argument verbatim into the
2119        // [`DialetoError::CabecaErrada`] `encontrado: String` field
2120        // for every boundary-covering `&str` input — empty string, a
2121        // canonical `defcaixa`-adjacent head, a non-ASCII head, a
2122        // whitespace-carrying head, a Unicode-full-width head. Any
2123        // wrapper-side truncation, silent `.trim()`, accidental
2124        // `.to_ascii_lowercase()` normalization, or `.into()` divergence
2125        // on the ctor body surfaces here as a byte-mismatch against the
2126        // input rather than at a downstream
2127        // [`DialetoError::to_string()`] diagnostic-shape drift at a
2128        // wrong-head fallthrough consumer far from the ctor declaration.
2129        // Peer of the sibling `limits_codec_unit_only_ctors_route_unit_
2130        // verbatim_across_every_variant` (limits.rs; 29fac09) shape on
2131        // the sibling single-slot `{ <field>: String }` envelope
2132        // boundary-sweep discipline.
2133        for encontrado in [
2134            "",
2135            "defflake",
2136            "def-molde",
2137            "defcaixa ",
2138            " defcaixa",
2139            "μdefcaixa",
2140            "\u{00A0}defcaixa",
2141            "\u{3000}defcaixa",
2142            "def\u{2028}caixa",
2143        ] {
2144            let via_ctor = DialetoError::cabeca_errada(encontrado);
2145            let via_literal = DialetoError::CabecaErrada {
2146                encontrado: encontrado.to_string(),
2147            };
2148            assert_eq!(
2149                via_ctor, via_literal,
2150                "DialetoError::cabeca_errada({encontrado:?}) must byte- \
2151                 equal the open-coded struct-literal on the same input — \
2152                 a drift here would let the ctor silently normalize / \
2153                 truncate the head symbol before it reached the \
2154                 CabecaErrada envelope"
2155            );
2156            let DialetoError::CabecaErrada { encontrado: routed } = via_ctor else {
2157                panic!(
2158                    "DialetoError::cabeca_errada must construct the \
2159                     CabecaErrada arm — got a different variant on \
2160                     input {encontrado:?}"
2161                );
2162            };
2163            assert_eq!(
2164                routed, encontrado,
2165                "DialetoError::cabeca_errada must route the input \
2166                 {encontrado:?} verbatim into the encontrado field — \
2167                 any wrapper-side truncation / normalization surfaces \
2168                 here rather than at a downstream diagnostic shape drift"
2169            );
2170        }
2171    }
2172
2173    #[test]
2174    fn classify_form_wrong_head_routes_through_cabeca_errada_ctor() {
2175        // Fail-before-pass-after routing pin: [`classify`]'s wrong-head
2176        // fallthrough site MUST construct its `Err(DialetoError::…)`
2177        // through the substrate-primitive [`DialetoError::cabeca_errada`]
2178        // ctor rather than through an open-coded struct-literal. Pre-
2179        // lift the wire-up hand-rolled a three-line
2180        // `Self::CabecaErrada { encontrado: other.to_string() }` block
2181        // with no compile-time link back to the substrate primitive; a
2182        // future accidental rebrand of the ctor body (an added
2183        // `.trim()` on `encontrado`, a per-arm constant prefix like
2184        // `"unknown-head:"`, a widening of the field into a
2185        // `(String, usize)` tuple carrying a caret offset) would then
2186        // silently split the two paths — the ctor consumers pick up
2187        // the new shape, the open-coded wire-up does not. Pinning
2188        // byte-equality between the observed `Err` and the ctor-
2189        // constructed `Err` refuses that split at caixa-core build
2190        // time rather than surfacing far from the wire-up commit as a
2191        // downstream diagnostic-consumer split.
2192        for head in ["defflake", "deffoobar", "defcaixaz", "let", "defmoldez"] {
2193            let src = format!("({head} :nome \"x\")");
2194            let observed = classify(&src);
2195            let via_ctor = Err(DialetoError::cabeca_errada(head));
2196            assert_eq!(
2197                observed, via_ctor,
2198                "classify({src:?}) must return the same Err shape as \
2199                 DialetoError::cabeca_errada({head:?}) — a drift here \
2200                 means the wire-up de-lifted its wrong-head fallthrough \
2201                 arm off the substrate primitive"
2202            );
2203        }
2204    }
2205
2206    #[test]
2207    fn leitura_ctor_matches_tuple_literal_wrap_on_str_binding() {
2208        // Fail-before-pass-after byte-identity pin: the lifted
2209        // [`DialetoError::leitura`] ctor MUST land on the exact same
2210        // tuple-newtype wrap the pre-lift open-coded wire-up block wrote by
2211        // hand — `DialetoError::Leitura(<into-String-expr>)`. A future
2212        // accidental divergence (an added `.trim()` on the reader reason,
2213        // a per-arm constant prefix like `"tatara-lisp:"`, a widening of
2214        // the tuple carrying a caret offset, a rebrand of the payload
2215        // carrying a distinct byte-shape) trips this pin at caixa-core
2216        // build time rather than surfacing far from the ctor declaration
2217        // as a downstream [`classify`] tatara-lisp-reader consumer
2218        // emitting one diagnostic shape while a hand-written test peer
2219        // opens another. Peer of the sibling
2220        // `cabeca_errada_ctor_matches_struct_literal_wrap` pin above on
2221        // the same [`DialetoError`] envelope's wrong-head axis, and of
2222        // the peer `LimitsError::empty_byte_size` /
2223        // `LimitsError::empty_duration` (7a4b003 / 319216c) shape on the
2224        // sibling `(String)` single-slot tuple-newtype envelope
2225        // constructors.
2226        let reason: &str = "unclosed paren at 1:12";
2227        assert_eq!(
2228            DialetoError::leitura(reason),
2229            DialetoError::Leitura(reason.to_string()),
2230            "DialetoError::leitura must byte-equal the pre-lift open-coded \
2231             tuple-newtype wrap — a drift here means the ctor stopped \
2232             being a substrate primitive for the tatara-lisp-reader \
2233             fallthrough site"
2234        );
2235    }
2236
2237    #[test]
2238    fn leitura_ctor_matches_tuple_literal_wrap_on_string_binding() {
2239        // Fail-before-pass-after byte-identity pin on the `String` wire-up
2240        // shape: the lifted [`DialetoError::leitura`] ctor MUST land on
2241        // the same tuple-newtype wrap when the caller passes an owned
2242        // `String` (the actual [`classify`] wire-up shape — `e.to_string()`
2243        // on a [`tatara_lisp::Error`]-carrying binding). Pins that the
2244        // `impl Into<String>` param covers the owned-`String` path with no
2245        // silent double-allocation or intermediate `&str` reslicing. Peer
2246        // of the sibling `_on_str_binding` pin above — together they close
2247        // the `impl Into<String>` bound's two authored wire-up shapes on
2248        // the ctor's substrate primitive.
2249        let reason: String = String::from("read: unexpected EOF at 3:1");
2250        let via_ctor = DialetoError::leitura(reason.clone());
2251        let via_literal = DialetoError::Leitura(reason.clone());
2252        assert_eq!(
2253            via_ctor, via_literal,
2254            "DialetoError::leitura must byte-equal the pre-lift open-coded \
2255             tuple-newtype wrap on the same owned-String fixture — a drift \
2256             here would let the ctor silently reshape the reader reason \
2257             before it reached the Leitura envelope"
2258        );
2259        let DialetoError::Leitura(routed) = via_ctor else {
2260            panic!(
2261                "DialetoError::leitura must construct the Leitura arm — \
2262                 got a different variant on input {reason:?}"
2263            );
2264        };
2265        assert_eq!(
2266            routed, reason,
2267            "DialetoError::leitura must route the input {reason:?} \
2268             verbatim into the tuple-newtype payload — any wrapper-side \
2269             truncation / normalization surfaces here rather than at a \
2270             downstream diagnostic shape drift"
2271        );
2272    }
2273
2274    #[test]
2275    fn leitura_routes_reason_verbatim_across_boundary_inputs() {
2276        // Fail-before-pass-after boundary-sweep pin: the lifted
2277        // [`DialetoError::leitura`] ctor MUST route its
2278        // `reason: impl Into<String>` argument verbatim into the
2279        // [`DialetoError::Leitura`] tuple-newtype `String` payload for
2280        // every boundary-covering input — empty string, a canonical
2281        // tatara-lisp reader error, a non-ASCII reason, a
2282        // whitespace-carrying reason, a Unicode-full-width reason. Any
2283        // wrapper-side truncation, silent `.trim()`, accidental
2284        // `.to_ascii_lowercase()` normalization, or `.into()` divergence
2285        // on the ctor body surfaces here as a byte-mismatch against the
2286        // input rather than at a downstream [`DialetoError::to_string()`]
2287        // diagnostic-shape drift at a tatara-lisp-reader fallthrough
2288        // consumer far from the ctor declaration. Peer of the sibling
2289        // `cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs`
2290        // pin above on the same [`DialetoError`] envelope's wrong-head
2291        // axis.
2292        for reason in [
2293            "",
2294            "unclosed paren at 1:12",
2295            "unexpected token ')'",
2296            "read: eof",
2297            " leading whitespace",
2298            "trailing whitespace ",
2299            "μnicode reason",
2300            "\u{00A0}NBSP-prefixed reason",
2301            "\u{3000}ideographic-space reason",
2302            "reason\u{2028}with-line-separator",
2303        ] {
2304            let via_ctor = DialetoError::leitura(reason);
2305            let via_literal = DialetoError::Leitura(reason.to_string());
2306            assert_eq!(
2307                via_ctor, via_literal,
2308                "DialetoError::leitura({reason:?}) must byte-equal the \
2309                 open-coded tuple-newtype wrap on the same input — a \
2310                 drift here would let the ctor silently normalize / \
2311                 truncate the reader reason before it reached the \
2312                 Leitura envelope"
2313            );
2314            let DialetoError::Leitura(routed) = via_ctor else {
2315                panic!(
2316                    "DialetoError::leitura must construct the Leitura \
2317                     arm — got a different variant on input {reason:?}"
2318                );
2319            };
2320            assert_eq!(
2321                routed, reason,
2322                "DialetoError::leitura must route the input {reason:?} \
2323                 verbatim into the tuple-newtype payload — any \
2324                 wrapper-side truncation / normalization surfaces here \
2325                 rather than at a downstream diagnostic shape drift"
2326            );
2327        }
2328    }
2329
2330    #[test]
2331    fn classify_reader_error_routes_through_leitura_ctor() {
2332        // Fail-before-pass-after routing pin: [`classify`]'s
2333        // tatara-lisp-reader map-err site MUST construct its
2334        // `Err(DialetoError::…)` through the substrate-primitive
2335        // [`DialetoError::leitura`] ctor rather than through an
2336        // open-coded tuple-newtype wrap. Pre-lift the wire-up hand-rolled
2337        // a `Self::Leitura(e.to_string())` block with no compile-time
2338        // link back to the substrate primitive; a future accidental
2339        // rebrand of the ctor body (an added `.trim()` on the reader
2340        // reason, a per-arm constant prefix like `"tatara-lisp:"`, a
2341        // widening of the payload into a `(String, usize)` tuple
2342        // carrying a caret offset) would then silently split the two
2343        // paths — the ctor consumers pick up the new shape, the
2344        // open-coded wire-up does not. Pinning byte-equality between
2345        // the observed `Err` and the ctor-constructed `Err` refuses
2346        // that split at caixa-core build time rather than surfacing far
2347        // from the wire-up commit as a downstream diagnostic-consumer
2348        // split. Peer of the sibling
2349        // `classify_form_wrong_head_routes_through_cabeca_errada_ctor`
2350        // pin above on the same [`DialetoError`] envelope's wrong-head
2351        // fallthrough axis.
2352        //
2353        // The malformed sources below each name a distinct
2354        // tatara-lisp-reader failure shape (unclosed paren, stray close
2355        // paren, unterminated string), so together they sweep the
2356        // reader's rejection surface rather than pinning against one
2357        // specific error message the reader upstream is free to reword.
2358        for src in [
2359            "(defcaixa :nome \"x\"",
2360            "defcaixa :nome \"x\")",
2361            "(defcaixa :nome \"unterminated",
2362        ] {
2363            let observed = classify(src);
2364            let Err(DialetoError::Leitura(reason)) = observed.clone() else {
2365                panic!(
2366                    "classify({src:?}) must return the Leitura arm — got \
2367                     {observed:?}"
2368                );
2369            };
2370            let via_ctor: Result<CaixaDialeto, DialetoError> =
2371                Err(DialetoError::leitura(reason.clone()));
2372            assert_eq!(
2373                observed, via_ctor,
2374                "classify({src:?}) must return the same Err shape as \
2375                 DialetoError::leitura({reason:?}) — a drift here means \
2376                 the wire-up de-lifted its tatara-lisp-reader fallthrough \
2377                 arm off the substrate primitive"
2378            );
2379        }
2380    }
2381
2382    #[test]
2383    fn caixa_dialeto_try_from_str_routes_through_from_wire_accessor() {
2384        // Fail-before-pass-after byte-parity pin on the lifted
2385        // `impl TryFrom<&str> for CaixaDialeto`: for every arm in
2386        // [`CaixaDialeto::ALL`], the `.try_into()` / `TryFrom::try_from`
2387        // path must resolve to the same variant the sibling
2388        // [`CaixaDialeto::from_wire`] resolver returns on the same
2389        // [`CaixaDialeto::as_str`] wire byte-string input. Pins the
2390        // three-path convergence discipline the [`CaixaDialeto`] closed-
2391        // set typed enum now carries on the `str → Self` reverse-
2392        // projection axis: `<CaixaDialeto as TryFrom<&str>>::try_from(s)`
2393        // (the newly lifted trait-idiomatic reverse projection),
2394        // `CaixaDialeto::from_wire(s)` (the substrate-primitive method-
2395        // named `Option<Self>` accessor the trait impl delegates through),
2396        // and the round-trip identity `variant.as_str() → variant`
2397        // (the four-arm closed accept-set shared between the emitter and
2398        // both reverse-projection consumers) must resolve to the same
2399        // typed [`CaixaDialeto`] discriminator on every arm.
2400        //
2401        // A future silent detour that routes the impl through a
2402        // divergent projection (a per-arm inline
2403        // `match s { "Pacote" => …, … }` re-inlining that opens a
2404        // compile-time link to the un-lifted arm-literal, a swap onto
2405        // the second-axis [`CaixaDialeto::palavra_canonica`] /
2406        // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
2407        // accessors that carry distinct byte-shapes per axis, an accept-
2408        // set widening that silently accepts one axis's byte-shapes as
2409        // parseable on the other axis) trips at caixa-core test time
2410        // under `assert_eq!` rather than at a downstream
2411        // `TryFrom<&str>`-bound consumer's silent split. Peer of the
2412        // sibling
2413        // [`crate::kind::tests::caixa_kind_try_from_str_routes_through_from_wire_accessor`]
2414        // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
2415        // discriminator's reverse-projection axis — extends the trait-
2416        // idiomatic reverse-projection axis onto the seventh closed-set
2417        // fieldless typed enum on the caixa surface (the second one to
2418        // carry the paired `TryFrom<&str>` impl).
2419        for &variant in CaixaDialeto::ALL {
2420            let wire = variant.as_str();
2421            let via_try_from: CaixaDialeto = <CaixaDialeto as TryFrom<&str>>::try_from(wire)
2422                .unwrap_or_else(|()| {
2423                    panic!(
2424                        "CaixaDialeto::try_from({wire:?}) must accept every \
2425                         CaixaDialeto::as_str output — got Err(()) for the \
2426                         wire byte-string of {variant:?}"
2427                    )
2428                });
2429            let via_from_wire: CaixaDialeto = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
2430                panic!(
2431                    "CaixaDialeto::from_wire({wire:?}) must accept every \
2432                     CaixaDialeto::as_str output — got None for the wire \
2433                     byte-string of {variant:?}"
2434                )
2435            });
2436            assert_eq!(
2437                via_try_from, variant,
2438                "CaixaDialeto::try_from(CaixaDialeto::{variant:?}.as_str()) \
2439                 must return CaixaDialeto::{variant:?} — the trait-idiomatic \
2440                 reverse projection must land on the same arm the method-named \
2441                 from_wire resolver does",
2442            );
2443            assert_eq!(
2444                via_try_from, via_from_wire,
2445                "CaixaDialeto::try_from({wire:?}) ({via_try_from:?}) must \
2446                 byte-equal CaixaDialeto::from_wire({wire:?}) ({via_from_wire:?}) \
2447                 on the same input — divergence signals a silent detour off the \
2448                 shared substrate-primitive resolver",
2449            );
2450            assert_eq!(
2451                <CaixaDialeto as TryFrom<&str>>::try_from(wire).ok(),
2452                CaixaDialeto::from_wire(wire),
2453                "the Result::ok() projection of TryFrom<&str> must byte-equal \
2454                 the sibling from_wire Option<Self> output on {wire:?} — the \
2455                 two accessors must share the same accept-set and typed \
2456                 outcome per arm",
2457            );
2458        }
2459    }
2460
2461    #[test]
2462    fn caixa_dialeto_try_from_str_rejects_unknown_byte_strings() {
2463        // Rejection witness on the trait-idiomatic reverse-projection
2464        // axis: any string outside the four-arm [`CaixaDialeto::as_str`]
2465        // output set must resolve to `Err(())` through the lifted
2466        // [`impl TryFrom<&str> for CaixaDialeto`]. A future accidental
2467        // widening of the accept-set (a case-insensitive match that
2468        // accepts `"pacote"` on the wire axis, a hand-rolled Levenshtein-
2469        // forgiving arm-lookup that admits `"Pacotee"` typos, a silent
2470        // acceptance of the sibling [`CaixaDialeto::palavra_canonica`]
2471        // `"defcaixa"` / `"defmolde"` byte-shapes on this axis, a swap
2472        // onto the [`CaixaDialeto::consumidor`] `"pleme-doc-gen"` /
2473        // `"caixa-core / feira"` / `"nobody known"` byte-shapes) would
2474        // silently drift the trait-idiomatic parser's accept-set from
2475        // the sibling [`CaixaDialeto::from_wire`] resolver's — a
2476        // downstream `TryFrom<&str>`-bound consumer binding a malformed
2477        // byte-string through this impl would then bind a plausibly-
2478        // wrong typed arm the caller does not route through any fallback,
2479        // silently misclassifying the reloaded row.
2480        //
2481        // Sweeps the same rejection set the sibling
2482        // [`caixa_dialeto_from_wire_rejects_unknown_byte_strings`] pin
2483        // walks (the shared `from_wire` resolver both accessors delegate
2484        // through) so the trait-idiomatic axis and the method-named axis
2485        // stay locked to the same accept-set by construction. Peer of the
2486        // sibling
2487        // [`crate::kind::tests::caixa_kind_try_from_str_rejects_unknown_byte_strings`]
2488        // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
2489        // discriminator's trait-idiomatic reverse-projection axis.
2490        for bad in [
2491            "",
2492            " ",
2493            "pacote",
2494            "PACOTE",
2495            "molde",
2496            "MoldePositional",
2497            "desconhecido",
2498            "Unknown",
2499            "defcaixa",
2500            "defmolde",
2501            "?",
2502            "caixa-core / feira",
2503            "pleme-doc-gen",
2504            "nobody known",
2505            "Pacote ",
2506            " Pacote",
2507        ] {
2508            assert_eq!(
2509                <CaixaDialeto as TryFrom<&str>>::try_from(bad),
2510                Err(()),
2511                "CaixaDialeto::try_from({bad:?}) must return Err(()) — the \
2512                 trait-idiomatic parser's accept-set is exactly the four \
2513                 CaixaDialeto::as_str outputs; a widening would silently \
2514                 split the trait-idiomatic reverse-projection axis from the \
2515                 sibling from_wire resolver's arm-set"
2516            );
2517        }
2518    }
2519
2520    #[test]
2521    fn caixa_dialeto_from_into_static_str_routes_through_as_str_accessor() {
2522        // Fail-before-pass-after byte-parity pin on the newly lifted
2523        // `impl From<CaixaDialeto> for &'static str` — asserts the
2524        // standard-library trait impl and the substrate-primitive
2525        // [`CaixaDialeto::as_str`] `pub const fn` accessor resolve to
2526        // the same four-arm emit-set across every arm the exhaustive
2527        // [`CaixaDialeto::ALL`] slice enumerates. Any future silent
2528        // detour that routes the trait impl through a divergent
2529        // projection (a per-arm inline `match dialeto { Pacote =>
2530        // "Pacote", … }` re-inlining that opens a compile-time link to
2531        // the un-lifted arm-literal, an accidental swap onto the second-
2532        // axis [`CaixaDialeto::palavra_canonica`] /
2533        // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
2534        // accessors that carry distinct byte-shapes per axis) trips at
2535        // caixa-core test time under `assert_eq!` rather than at a
2536        // downstream `impl Into<&'static str>`-bound consumer's silent
2537        // split. Sweeps every one of the four arms [`CaixaDialeto::ALL`]
2538        // carries so no arm's projection is covered only by the sibling
2539        // method-named `as_str` / [`std::fmt::Display`] / [`AsRef<str>`]
2540        // paths. Materializes the `<&'static str as
2541        // From<CaixaDialeto>>::from` output in a `const`-shape binding
2542        // to make the `'static` lifetime promise a build-time invariant
2543        // — a future accidental downgrade of any of the four arms'
2544        // returned literals to a non-`&'static str` (a `String::leak()`-
2545        // produced return, a `Box::leak`-cast, an intermediate lifetime-
2546        // erasing helper) trips at caixa-core build time rather than at
2547        // a downstream `'static`-bound consumer. Peer of the sibling
2548        // [`crate::supervisor::tests::restart_strategy_from_into_static_str_routes_through_as_str_accessor`]
2549        // (523157d) /
2550        // [`crate::supervisor::tests::restart_policy_from_into_static_str_routes_through_as_str_accessor`]
2551        // (9fb37d0) /
2552        // [`crate::kind::tests::caixa_kind_from_into_static_str_routes_through_as_str_accessor`]
2553        // (edb827b) pins on the sibling closed-set typed-enum forward-
2554        // projection axes — extends the trait-idiomatic forward-
2555        // projection axis onto the fourth closed-set fieldless typed
2556        // enum on the caixa surface (the dialect-classification axis,
2557        // second-of-two closed-set typed enums in caixa-core outside
2558        // the OTP-shape M2 slot).
2559        const PACOTE: &str = CaixaDialeto::Pacote.as_str();
2560        const MOLDE: &str = CaixaDialeto::Molde.as_str();
2561        const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
2562        const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
2563        for &variant in CaixaDialeto::ALL {
2564            let via_trait: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2565            let via_method: &'static str = variant.as_str();
2566            assert_eq!(
2567                via_trait, via_method,
2568                "From<CaixaDialeto> for &'static str impl must round-trip \
2569                 CaixaDialeto::{variant:?} to the same `PascalCase` byte-string \
2570                 CaixaDialeto::as_str returns — divergence signals a silent \
2571                 detour off the substrate-primitive accessor"
2572            );
2573            let via_into: &'static str = variant.into();
2574            assert_eq!(
2575                via_into, via_method,
2576                "Into<&'static str>::into on CaixaDialeto::{variant:?} must \
2577                 byte-equal CaixaDialeto::as_str on the same input — the \
2578                 blanket-derived Into shape must resolve to the same as_str \
2579                 dispatch as the explicit From impl"
2580            );
2581        }
2582        assert_eq!(
2583            [PACOTE, MOLDE, MOLDE_POSICIONAL, DESCONHECIDO],
2584            ["Pacote", "Molde", "MoldePosicional", "Desconhecido"],
2585            "const-context CaixaDialeto::as_str must resolve to the four \
2586             `PascalCase` variant-name byte-strings — a future accidental \
2587             downgrade of any arm to a non-const or non-static byte-string \
2588             breaks the `&'static str`-lifetime promise the paired \
2589             From<CaixaDialeto> for &'static str impl carries by \
2590             construction"
2591        );
2592    }
2593
2594    #[test]
2595    fn caixa_dialeto_from_into_static_str_and_as_str_partition_the_emit_set() {
2596        // Cross-axis partition pin: the paired trait-idiomatic
2597        // `From<CaixaDialeto> for &'static str` forward projection and
2598        // the method-named [`CaixaDialeto::as_str`] forward projection
2599        // must resolve identically on *every* arm, not just the ones
2600        // named in the primary byte-parity pin above. Sweeps every
2601        // [`CaixaDialeto::ALL`] arm and asserts the trait's `From::from`
2602        // output byte-equals the method-named accessor's return-value on
2603        // each, locking the two forward-projection paths together by
2604        // construction so any future detour (a stray `From` special-case
2605        // that lands on a divergent per-arm literal outside the paired
2606        // `as_str` dispatch, a hypothetical rebrand touching one axis
2607        // without the other) trips at caixa-core test time. Peer of the
2608        // sibling forward-projection partition pins
2609        // [`crate::supervisor::tests::restart_strategy_from_into_static_str_and_as_str_partition_the_emit_set`]
2610        // (523157d) /
2611        // [`crate::supervisor::tests::restart_policy_from_into_static_str_and_as_str_partition_the_emit_set`]
2612        // (9fb37d0) /
2613        // [`crate::kind::tests::caixa_kind_from_into_static_str_and_as_str_partition_the_emit_set`]
2614        // (edb827b) — extends the round-trip discipline onto the fourth
2615        // closed-set typed enum on the caixa surface, closing the two-way
2616        // `Self ↔ &'static str` round-trip on the trait-idiomatic pair
2617        // (`From<Self> for &'static str` + `TryFrom<&str> for Self`) as
2618        // well as the pre-existing method-named pair (`as_str` +
2619        // `from_wire`).
2620        for &variant in CaixaDialeto::ALL {
2621            let via_trait: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2622            let via_method: &'static str = variant.as_str();
2623            assert_eq!(
2624                via_trait, via_method,
2625                "From<CaixaDialeto> for &'static str and \
2626                 CaixaDialeto::as_str must resolve identically on \
2627                 CaixaDialeto::{variant:?} — divergence signals the \
2628                 two forward-projection paths have drifted onto different \
2629                 emit-sets"
2630            );
2631        }
2632        // Round-trip witness: every arm's forward `From` output re-parses
2633        // through the paired trait-idiomatic reverse `TryFrom<&str>` back
2634        // to the original variant. Closes the two-way `CaixaDialeto ↔
2635        // &'static str` round-trip on the trait-idiomatic axis pair
2636        // directly (no wire-vocab intermediate the peer [`CaixaKind`]
2637        // axis pair requires — the emit-side [`CaixaDialeto::as_str`]
2638        // and the parse-side [`CaixaDialeto::from_wire`] share the same
2639        // `PascalCase` byte-string vocabulary by construction), mirroring
2640        // the pre-existing method-named `as_str` + `from_wire` round-trip
2641        // on the substrate-primitive axis pair.
2642        for &variant in CaixaDialeto::ALL {
2643            let emitted: &'static str = variant.into();
2644            let re_parsed: Result<CaixaDialeto, ()> =
2645                <CaixaDialeto as TryFrom<&str>>::try_from(emitted);
2646            assert_eq!(
2647                re_parsed,
2648                Ok(variant),
2649                "trait-idiomatic axis pair must round-trip \
2650                 CaixaDialeto::{variant:?} through `.into::<&'static \
2651                 str>()` and back through `TryFrom<&str>` — a break signals \
2652                 the forward-emit and reverse-parse axes have drifted onto \
2653                 different vocabularies"
2654            );
2655        }
2656    }
2657
2658    #[test]
2659    fn caixa_dialeto_is_molde_family_routes_through_is_variant_derived_predicates() {
2660        // Byte-parity pin on the post-lift [`CaixaDialeto::is_molde_family`]
2661        // convergence: for every arm in [`CaixaDialeto::ALL`], the typed
2662        // predicate must byte-equal the direct
2663        // `self.is_molde() || self.is_molde_posicional()` composition of
2664        // the two derived per-arm predicates. Pre-lift the predicate
2665        // hand-rolled `matches!(self, Self::Molde | Self::MoldePosicional)`
2666        // with no compile-time link back to the closed-set typed dispatch;
2667        // post-lift it routes through the derived predicates so a future
2668        // arm rename or `#[is_variant(name = "…")]` override lands at
2669        // exactly one dispatch on the substrate primitive. Pinning the
2670        // byte-equality here refuses a future accidental split between
2671        // the composed predicate and the paired derived predicates
2672        // (a hand-rolled shadow `impl` that overrides one path but not
2673        // the other, an accidental rebrand of `is_molde_family`'s body
2674        // back to the pre-lift `matches!` form) at caixa-core build time.
2675        for &d in CaixaDialeto::ALL {
2676            let via_derived = d.is_molde() || d.is_molde_posicional();
2677            let via_is_molde_family = d.is_molde_family();
2678            assert_eq!(
2679                via_is_molde_family, via_derived,
2680                "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
2681                 must byte-equal the composed derived predicates \
2682                 is_molde() || is_molde_posicional() ({via_derived}) — a \
2683                 split between the composed predicate and its derived \
2684                 building blocks would let a future arm rename land at one \
2685                 path and drift at the other, which is exactly the drift \
2686                 the IsVariant lift refuses"
2687            );
2688        }
2689    }
2690
2691    #[test]
2692    fn caixa_dialeto_from_borrowed_into_static_str_routes_through_as_str_accessor() {
2693        // Fail-before-pass-after byte-parity pin on the newly lifted
2694        // `impl From<&CaixaDialeto> for &'static str` — asserts the
2695        // borrowed-input standard-library trait impl and the substrate-
2696        // primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
2697        // resolve to the same four-arm emit-set across every arm the
2698        // exhaustive [`CaixaDialeto::ALL`] slice enumerates. Rust's
2699        // `From` trait does not auto-derive the borrowed-input sibling
2700        // from a paired owned-input impl (no `impl<T, U> From<&T> for U
2701        // where T: Copy, U: From<T>` blanket in `core`), so the
2702        // borrowed-input axis is a distinct trait-idiomatic surface that
2703        // a `.iter().map(Into::into)` shape over [`CaixaDialeto::ALL`]
2704        // (whose iterator yields `&CaixaDialeto`, not `CaixaDialeto`)
2705        // reaches through this impl and no other — the paired owned-
2706        // input [`From<CaixaDialeto>`] impl requires an explicit
2707        // `.copied()` / dereference before the trait fires.
2708        // Materializes the `<&'static str as From<&CaixaDialeto>>::from`
2709        // output in a `const`-shape binding to make the `'static`
2710        // lifetime promise a build-time invariant — a future accidental
2711        // downgrade of any of the four arms' returned literals to a
2712        // non-`&'static str` trips at caixa-core build time rather than
2713        // at a downstream `'static`-bound consumer. Peer of the sibling
2714        // [`crate::dep::tests::dep_list_from_borrowed_into_static_str_routes_through_as_str_accessor`]
2715        // (64aa742) /
2716        // [`crate::kind::tests::caixa_kind_from_borrowed_into_static_str_routes_through_as_str_accessor`]
2717        // (5ab993a) pins on the sibling closed-set typed-enum borrowed-
2718        // input forward-projection axes — extends the borrowed-input
2719        // axis discipline onto the third peer on the substrate-wide
2720        // campaign, the dialect-classification axis.
2721        const PACOTE: &str = CaixaDialeto::Pacote.as_str();
2722        const MOLDE: &str = CaixaDialeto::Molde.as_str();
2723        const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
2724        const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
2725        for variant in CaixaDialeto::ALL {
2726            let via_trait: &'static str = <&'static str as From<&CaixaDialeto>>::from(variant);
2727            let via_method: &'static str = variant.as_str();
2728            assert_eq!(
2729                via_trait, via_method,
2730                "From<&CaixaDialeto> for &'static str impl must round-trip \
2731                 &CaixaDialeto::{variant:?} to the same `PascalCase` byte-\
2732                 string CaixaDialeto::as_str returns — divergence signals a \
2733                 silent detour off the substrate-primitive accessor"
2734            );
2735            let via_into: &'static str = variant.into();
2736            assert_eq!(
2737                via_into, via_method,
2738                "Into<&'static str>::into on &CaixaDialeto::{variant:?} must \
2739                 byte-equal CaixaDialeto::as_str on the same input — the \
2740                 blanket-derived Into shape must resolve to the same as_str \
2741                 dispatch as the explicit From impl"
2742            );
2743        }
2744        assert_eq!(
2745            [PACOTE, MOLDE, MOLDE_POSICIONAL, DESCONHECIDO],
2746            ["Pacote", "Molde", "MoldePosicional", "Desconhecido"],
2747            "const-context CaixaDialeto::as_str must resolve to the four \
2748             `PascalCase` variant-name byte-strings — the borrowed-input \
2749             From<&CaixaDialeto> for &'static str impl inherits its \
2750             `'static` lifetime promise from the same accessor the owned-\
2751             input sibling routes through"
2752        );
2753    }
2754
2755    #[test]
2756    fn caixa_dialeto_from_owned_and_borrowed_into_static_str_agree_on_every_arm() {
2757        // Cross-axis partition pin: the paired trait-idiomatic
2758        // owned-input `From<CaixaDialeto> for &'static str` and
2759        // borrowed-input `From<&CaixaDialeto> for &'static str` (this
2760        // lift) forward projections must resolve identically on every
2761        // arm, locking the two input-shape paths together so any future
2762        // detour trips at caixa-core test time. Then a witness that a
2763        // `.iter().map(Into::into)` pipe over [`CaixaDialeto::ALL`]
2764        // (whose iterator yields `&CaixaDialeto`) materializes the four-
2765        // arm accept-set through the borrowed-input axis alone — the
2766        // exact shape a future M4 admission-webhook rejection body
2767        // composer, a future substrate-wide per-arm diagnostic column,
2768        // or a `HashMap::<&'static str, CaixaDialeto>::from_iter(
2769        //     CaixaDialeto::ALL.iter().map(|d| (d.into(), *d)))`-style
2770        // per-dialect lookup reaches through — closing the two-way
2771        // owned/borrowed input-shape symmetry on the forward-projection
2772        // trait-idiomatic axis. Peer of the sibling
2773        // [`crate::dep::tests::dep_list_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
2774        // (64aa742) /
2775        // [`crate::kind::tests::caixa_kind_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
2776        // (5ab993a) partition pins — extends the borrowed-input axis
2777        // discipline onto the third peer on the substrate-wide campaign.
2778        for &variant in CaixaDialeto::ALL {
2779            let owned: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2780            let borrowed: &'static str = <&'static str as From<&CaixaDialeto>>::from(&variant);
2781            assert_eq!(
2782                owned, borrowed,
2783                "From<CaixaDialeto> and From<&CaixaDialeto> for &'static str \
2784                 must resolve identically on CaixaDialeto::{variant:?} — \
2785                 divergence signals the owned-input and borrowed-input \
2786                 forward-projection paths have drifted onto different \
2787                 emit-sets"
2788            );
2789        }
2790        let via_iter: Vec<&'static str> = CaixaDialeto::ALL.iter().map(Into::into).collect();
2791        let via_method: Vec<&'static str> = CaixaDialeto::ALL.iter().map(|d| d.as_str()).collect();
2792        assert_eq!(
2793            via_iter, via_method,
2794            "`.iter().map(Into::into)` over CaixaDialeto::ALL must byte-\
2795             equal `.iter().map(|d| d.as_str())` on every arm — the \
2796             borrowed-input `From<&CaixaDialeto> for &'static str` axis \
2797             is what makes the `.iter().map(Into::into)` shape route \
2798             through the substrate-primitive `CaixaDialeto::as_str` \
2799             accessor rather than through a per-call-site `.copied()` / \
2800             dereference detour"
2801        );
2802        // Direct round-trip witness on the borrowed-input axis: every
2803        // arm's borrowed `From` output re-parses through the paired
2804        // trait-idiomatic reverse `TryFrom<&str>` back to the original
2805        // variant. Unlike the peer [`crate::CaixaKind`] axis pair
2806        // (whose forward `From<Self> for &'static str` emits the
2807        // lowercase Portuguese `as_str` diagnostic vocabulary while
2808        // the reverse `TryFrom<&str>` parses the `PascalCase`
2809        // `wire_name` author-surface vocabulary, forcing the round-trip
2810        // through an intermediate wire-vocab hop), [`CaixaDialeto`]'s
2811        // [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
2812        // parse share the same `PascalCase` vocabulary by construction,
2813        // so the borrowed-input forward axis and the reverse axis
2814        // compose directly.
2815        for &variant in CaixaDialeto::ALL {
2816            let borrowed: &'static str = <&'static str as From<&CaixaDialeto>>::from(&variant);
2817            let re_parsed: Result<CaixaDialeto, ()> =
2818                <CaixaDialeto as TryFrom<&str>>::try_from(borrowed);
2819            assert_eq!(
2820                re_parsed,
2821                Ok(variant),
2822                "trait-idiomatic borrowed-input round-trip must project \
2823                 &CaixaDialeto::{variant:?} through \
2824                 `<&'static str>::from(&variant)` and back through \
2825                 `TryFrom<&str>` — a break signals the borrowed-input \
2826                 forward-emit axis and the reverse-parse axis have \
2827                 drifted onto different vocabularies"
2828            );
2829        }
2830    }
2831
2832    #[test]
2833    fn caixa_dialeto_from_into_owned_string_routes_through_as_str_accessor() {
2834        // Fail-before-pass-after byte-parity pin on the newly lifted
2835        // `impl From<CaixaDialeto> for String` — asserts the owned-`String`
2836        // -returning standard-library trait impl and the substrate-
2837        // primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
2838        // resolve to the same four-arm emit-set across every arm the
2839        // exhaustive [`CaixaDialeto::ALL`] slice enumerates. Rust's
2840        // standard library does not carry a blanket
2841        // `impl<T: AsRef<str>> From<T> for String` (nor an
2842        // `impl<T: fmt::Display> From<T> for String`), so the
2843        // owned-`String` forward-projection axis is a distinct trait-
2844        // idiomatic surface that a `let key: String = dialeto.into();`-
2845        // shaped call site reaches through this impl and no other — the
2846        // paired sibling `From<CaixaDialeto> for &'static str` impl
2847        // forces every owned-`String` call site through an explicit
2848        // `.to_owned()` / `String::from` restatement. Peer of the
2849        // first-mover
2850        // [`crate::supervisor::tests::restart_strategy_from_into_owned_string_routes_through_as_str_accessor`]
2851        // (7baa18a), the second-peer
2852        // [`crate::supervisor::tests::restart_policy_from_into_owned_string_routes_through_as_str_accessor`]
2853        // (7851725), and the third-peer
2854        // [`crate::kind::tests::caixa_kind_from_into_owned_string_routes_through_as_str_accessor`]
2855        // (231a18c) — extends the trait-idiomatic owned-`String`
2856        // forward-projection axis onto the fourth closed-set fieldless
2857        // typed enum on the caixa surface (the dialect-classification
2858        // axis, second peer outside the M2 OTP-shape sibling axis).
2859        for &variant in CaixaDialeto::ALL {
2860            let via_trait: String = <String as From<CaixaDialeto>>::from(variant);
2861            let via_method: &'static str = variant.as_str();
2862            assert_eq!(
2863                via_trait.as_str(),
2864                via_method,
2865                "From<CaixaDialeto> for String impl must round-trip \
2866                 CaixaDialeto::{variant:?} to the same `PascalCase` \
2867                 arm-string CaixaDialeto::as_str returns — divergence \
2868                 signals a silent detour off the substrate-primitive \
2869                 accessor"
2870            );
2871            let via_into: String = variant.into();
2872            assert_eq!(
2873                via_into.as_str(),
2874                via_method,
2875                "Into<String>::into on CaixaDialeto::{variant:?} must \
2876                 byte-equal CaixaDialeto::as_str on the same input — the \
2877                 blanket-derived Into shape must resolve to the same \
2878                 as_str dispatch as the explicit From impl"
2879            );
2880        }
2881    }
2882
2883    #[test]
2884    fn caixa_dialeto_from_into_owned_string_and_static_str_agree_on_every_arm() {
2885        // Cross-axis partition pin: the paired trait-idiomatic
2886        // owned-`String` `From<CaixaDialeto> for String` (this lift) and
2887        // owned-`&'static str` `From<CaixaDialeto> for &'static str`
2888        // (c189a6f) forward projections must resolve identically on
2889        // every arm, locking the two return-type-shape paths together
2890        // so any future detour trips at caixa-core test time. Also
2891        // byte-parity witness against the sibling
2892        // [`ToString::to_string`] surface routed through
2893        // [`std::fmt::Display`] — the three owned-heap-string paths
2894        // (`.into::<String>()`, `String::from`, `.to_string()`) must
2895        // resolve identically on every arm so a future consumer that
2896        // picks any of the three lands on the same four-arm
2897        // `PascalCase` accept-set. Then a `.iter().copied()
2898        // .map(String::from)` pipe witness over [`CaixaDialeto::ALL`]
2899        // that materializes the four-arm accept-set through the
2900        // owned-`String` axis alone — the exact shape a future M4
2901        // admission-webhook rejection body composer or a
2902        // `HashMap::<String, CaixaDialeto>::from_iter(
2903        //     CaixaDialeto::ALL.iter().copied().map(|d| (d.into(), d)))`-
2904        // style owned-key per-dialect lookup reaches through — closing
2905        // the owned-`String` forward-projection axis's iterator-pipe
2906        // shape. Then a direct round-trip witness through the paired
2907        // trait-idiomatic reverse [`TryFrom<&str>`] axis on the
2908        // owned-`String`'s [`String::as_str`] borrow that closes the
2909        // two-way `Self → String → Self` round-trip on the trait-
2910        // idiomatic owned-`String` forward + reverse axis pair.
2911        //
2912        // Unlike the peer [`crate::CaixaKind`] axis pair (whose forward
2913        // `From` emit lands on the lowercase Portuguese `as_str`
2914        // diagnostic vocabulary while the reverse `TryFrom<&str>` parses
2915        // the `PascalCase` `wire_name` author-surface vocabulary,
2916        // forcing the round-trip through an intermediate
2917        // [`crate::CaixaKind::wire_name`] hop), [`CaixaDialeto`]'s
2918        // [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
2919        // parse share the same `PascalCase` vocabulary by construction
2920        // (there is no wire/diagnostic axis split on this enum), so
2921        // the owned-`String` forward axis and the reverse axis compose
2922        // directly — matching the peer
2923        // [`crate::supervisor::RestartStrategy`] /
2924        // [`crate::supervisor::RestartPolicy`] owned-`String` axis
2925        // pairs (whose forward emit and reverse parse also share one
2926        // `PascalCase` vocabulary by construction).
2927        for &variant in CaixaDialeto::ALL {
2928            let owned_string: String = <String as From<CaixaDialeto>>::from(variant);
2929            let owned_static: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2930            assert_eq!(
2931                owned_string.as_str(),
2932                owned_static,
2933                "From<CaixaDialeto> for String and From<CaixaDialeto> for \
2934                 &'static str must resolve identically on \
2935                 CaixaDialeto::{variant:?} — divergence signals the \
2936                 owned-`String` and owned-`&'static str` forward-\
2937                 projection return-type-shape paths have drifted onto \
2938                 different emit-sets"
2939            );
2940            let via_to_string: String = variant.to_string();
2941            assert_eq!(
2942                owned_string, via_to_string,
2943                "From<CaixaDialeto> for String must byte-equal \
2944                 CaixaDialeto::to_string on CaixaDialeto::{variant:?} — \
2945                 divergence signals the trait-idiomatic owned-`String` \
2946                 forward-projection axis and the ToString-through-\
2947                 Display axis have drifted onto different emit-sets"
2948            );
2949        }
2950        let via_iter: Vec<String> = CaixaDialeto::ALL
2951            .iter()
2952            .copied()
2953            .map(String::from)
2954            .collect();
2955        let via_method: Vec<String> = CaixaDialeto::ALL
2956            .iter()
2957            .map(|d| d.as_str().to_owned())
2958            .collect();
2959        assert_eq!(
2960            via_iter, via_method,
2961            "`.iter().copied().map(String::from)` over CaixaDialeto::ALL \
2962             must byte-equal `.iter().map(|d| d.as_str().to_owned())` on \
2963             every arm — the owned-`String` `From<CaixaDialeto> for \
2964             String` axis is what makes the `String::from` composition \
2965             route through the substrate-primitive `CaixaDialeto::as_str` \
2966             accessor rather than through a per-call-site `.to_owned()` / \
2967             `String::from(dialeto.as_str())` detour"
2968        );
2969        for &variant in CaixaDialeto::ALL {
2970            let emitted: String = variant.into();
2971            let re_parsed: Result<CaixaDialeto, ()> =
2972                <CaixaDialeto as TryFrom<&str>>::try_from(emitted.as_str());
2973            assert_eq!(
2974                re_parsed,
2975                Ok(variant),
2976                "trait-idiomatic owned-`String` forward-projection + \
2977                 reverse-projection axis pair must round-trip \
2978                 CaixaDialeto::{variant:?} through `.into::<String>()` \
2979                 and back through `TryFrom<&str>` on the owned-`String`'s \
2980                 String::as_str borrow — a break signals the owned-\
2981                 `String` forward-emit and reverse-parse axes have \
2982                 drifted onto different vocabularies (unlike the peer \
2983                 CaixaKind axis pair, CaixaDialeto's forward emit and \
2984                 reverse parse share one PascalCase vocabulary by \
2985                 construction, so the round-trip composes directly)"
2986            );
2987        }
2988    }
2989
2990    #[test]
2991    fn caixa_dialeto_from_into_borrowed_owned_string_routes_through_as_str_accessor() {
2992        // Fail-before-pass-after byte-parity pin on the newly lifted
2993        // `impl From<&CaixaDialeto> for String` — asserts the borrowed-
2994        // input owned-`String`-returning standard-library trait impl and
2995        // the substrate-primitive [`super::CaixaDialeto::as_str`]
2996        // `pub const fn` accessor resolve to the same four-arm emit-set
2997        // across every arm the exhaustive [`super::CaixaDialeto::ALL`]
2998        // slice enumerates. Rust's standard library does not carry a
2999        // blanket `impl<T: AsRef<str>> From<&T> for String` (nor an
3000        // `impl<T: fmt::Display> From<&T> for String`), so the
3001        // borrowed-input owned-`String` forward-projection axis is a
3002        // distinct trait-idiomatic surface that a
3003        // `let key: String = (&dialeto).into();`-shaped call site
3004        // reaches through this impl and no other — the paired sibling
3005        // `From<CaixaDialeto> for String` impl forces every borrowed-
3006        // input call site through an explicit `Copy` deref
3007        // (`String::from(*dialeto)`) or an `.as_str().to_owned()` /
3008        // `.to_string()` detour. Peer of the first-mover
3009        // [`crate::supervisor::tests::restart_strategy_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3010        // (579385f), the second-peer
3011        // [`crate::supervisor::tests::restart_policy_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3012        // (8465740), the third-peer
3013        // [`crate::dep::tests::dep_list_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3014        // (e0cb617), and the fourth-peer
3015        // [`crate::kind::tests::caixa_kind_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
3016        // (e76436d) — extends the trait-idiomatic borrowed-input owned-
3017        // `String` forward-projection axis onto the fourth closed-set
3018        // fieldless typed enum on the caixa surface (the dialect-
3019        // classification axis, second peer outside the M2 OTP-shape
3020        // sibling axis to reach the 2×2-completion corner).
3021        for &variant in CaixaDialeto::ALL {
3022            let via_trait: String = <String as From<&CaixaDialeto>>::from(&variant);
3023            let via_method: &'static str = variant.as_str();
3024            assert_eq!(
3025                via_trait.as_str(),
3026                via_method,
3027                "From<&CaixaDialeto> for String impl must round-trip \
3028                 &CaixaDialeto::{variant:?} to the same `PascalCase` \
3029                 arm-string CaixaDialeto::as_str returns — divergence \
3030                 signals a silent detour off the substrate-primitive \
3031                 accessor"
3032            );
3033            let via_into: String = (&variant).into();
3034            assert_eq!(
3035                via_into.as_str(),
3036                via_method,
3037                "Into<String>::into on &CaixaDialeto::{variant:?} must \
3038                 byte-equal CaixaDialeto::as_str on the same input — \
3039                 the blanket-derived Into shape must resolve to the \
3040                 same as_str dispatch as the explicit From impl"
3041            );
3042        }
3043    }
3044
3045    #[test]
3046    fn caixa_dialeto_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm() {
3047        // Cross-axis partition pin: the newly lifted trait-idiomatic
3048        // borrowed-input owned-`String` `From<&CaixaDialeto> for String`
3049        // (this lift), the paired owned-input owned-`String`
3050        // `From<CaixaDialeto> for String` (88942cd), the paired
3051        // borrowed-input owned-`&'static str`
3052        // `From<&CaixaDialeto> for &'static str` (807b0b5), and the
3053        // paired owned-input owned-`&'static str`
3054        // `From<CaixaDialeto> for &'static str` (c189a6f) — every corner
3055        // of the `{Self, &Self} × {&'static str, String}` 2×2 trait-
3056        // idiomatic projection family — must resolve identically on
3057        // every arm, locking the four return-shape × input-shape paths
3058        // together so any future detour trips at caixa-core test time.
3059        // Also byte-parity witness against the sibling
3060        // [`ToString::to_string`] surface routed through
3061        // [`std::fmt::Display`] and a direct round-trip witness through
3062        // the paired trait-idiomatic reverse [`TryFrom<&str>`] axis on
3063        // the owned-`String`'s [`String::as_str`] borrow that closes
3064        // the two-way `&Self → String → Self` round-trip on the trait-
3065        // idiomatic borrowed-input owned-`String` forward + reverse
3066        // axis pair. Peer of the first-mover
3067        // [`crate::supervisor::tests::restart_strategy_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3068        // (579385f), the second-peer
3069        // [`crate::supervisor::tests::restart_policy_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3070        // (8465740), the third-peer
3071        // [`crate::dep::tests::dep_list_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3072        // (e0cb617), and the fourth-peer
3073        // [`crate::kind::tests::caixa_kind_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
3074        // (e76436d) — closes the whole `{Self, &Self} × {&'static str,
3075        // String}` 2×2 projection corner on the fifth substrate-wide
3076        // closed-set fieldless typed enum peer (the dialect-
3077        // classification axis, second peer outside the M2 OTP-shape
3078        // sibling pair).
3079        //
3080        // Unlike the peer [`crate::CaixaKind`] axis pair (whose forward
3081        // `From` emit lands on the lowercase Portuguese `as_str`
3082        // diagnostic vocabulary while the reverse `TryFrom<&str>`
3083        // parses the `PascalCase` `wire_name` author-surface vocabulary,
3084        // forcing the round-trip through an intermediate
3085        // [`crate::CaixaKind::wire_name`] hop), [`super::CaixaDialeto`]'s
3086        // [`super::CaixaDialeto::as_str`] emit and
3087        // [`super::CaixaDialeto::from_wire`] parse share the same
3088        // `PascalCase` vocabulary by construction (there is no
3089        // wire/diagnostic axis split on this enum), so the borrowed-
3090        // input owned-`String` forward axis and the reverse axis compose
3091        // directly — matching the peer
3092        // [`crate::supervisor::RestartStrategy`] /
3093        // [`crate::supervisor::RestartPolicy`] / [`crate::dep::DepList`]
3094        // borrowed-input owned-`String` axis pairs.
3095        for &dialeto in CaixaDialeto::ALL {
3096            let borrowed_string: String = <String as From<&CaixaDialeto>>::from(&dialeto);
3097            let owned_string: String = <String as From<CaixaDialeto>>::from(dialeto);
3098            let borrowed_static: &'static str =
3099                <&'static str as From<&CaixaDialeto>>::from(&dialeto);
3100            let owned_static: &'static str = <&'static str as From<CaixaDialeto>>::from(dialeto);
3101            assert_eq!(
3102                borrowed_string, owned_string,
3103                "From<&CaixaDialeto> for String and From<CaixaDialeto> \
3104                 for String must resolve identically on \
3105                 CaixaDialeto::{dialeto:?} — divergence signals the \
3106                 borrowed-input and owned-input owned-`String` forward-\
3107                 projection input-shape paths have drifted onto \
3108                 different emit-sets"
3109            );
3110            assert_eq!(
3111                borrowed_string.as_str(),
3112                borrowed_static,
3113                "From<&CaixaDialeto> for String and From<&CaixaDialeto> \
3114                 for &'static str must resolve identically on \
3115                 CaixaDialeto::{dialeto:?} — divergence signals the \
3116                 borrowed-input `&'static str` and owned-`String` \
3117                 return-shape paths have drifted onto different \
3118                 emit-sets"
3119            );
3120            assert_eq!(
3121                borrowed_string.as_str(),
3122                owned_static,
3123                "From<&CaixaDialeto> for String and From<CaixaDialeto> \
3124                 for &'static str must resolve identically on \
3125                 CaixaDialeto::{dialeto:?} — divergence signals a break \
3126                 in the diagonal corner of the {{Self, &Self}} × \
3127                 {{&'static str, String}} 2×2 trait-idiomatic \
3128                 projection family"
3129            );
3130            let via_to_string: String = dialeto.to_string();
3131            assert_eq!(
3132                borrowed_string, via_to_string,
3133                "From<&CaixaDialeto> for String must byte-equal \
3134                 CaixaDialeto::to_string on CaixaDialeto::{dialeto:?} — \
3135                 divergence signals the trait-idiomatic borrowed-input \
3136                 owned-`String` forward-projection axis and the \
3137                 ToString-through-Display axis have drifted onto \
3138                 different emit-sets"
3139            );
3140        }
3141        let via_iter: Vec<String> = CaixaDialeto::ALL.iter().map(String::from).collect();
3142        let via_method: Vec<String> = CaixaDialeto::ALL
3143            .iter()
3144            .map(|d| d.as_str().to_owned())
3145            .collect();
3146        assert_eq!(
3147            via_iter, via_method,
3148            "`.iter().map(String::from)` over CaixaDialeto::ALL — a \
3149             call site whose iteration axis holds `&CaixaDialeto` by \
3150             construction — must byte-equal `.iter().map(|d| \
3151             d.as_str().to_owned())` on every arm — the borrowed-input \
3152             owned-`String` `From<&CaixaDialeto> for String` axis is \
3153             what makes the `String::from` composition route through \
3154             the substrate-primitive `CaixaDialeto::as_str` accessor \
3155             without a spurious `Copy` deref (which would only be \
3156             reachable through the owned-input `From<CaixaDialeto> for \
3157             String` axis by first calling `.copied()` on the iterator)"
3158        );
3159        for &variant in CaixaDialeto::ALL {
3160            let emitted: String = (&variant).into();
3161            let re_parsed: Result<CaixaDialeto, ()> =
3162                <CaixaDialeto as TryFrom<&str>>::try_from(emitted.as_str());
3163            assert_eq!(
3164                re_parsed,
3165                Ok(variant),
3166                "trait-idiomatic borrowed-input owned-`String` \
3167                 forward-projection + reverse-projection axis pair \
3168                 must round-trip &CaixaDialeto::{variant:?} through \
3169                 `.into::<String>()` on the borrowed-input surface and \
3170                 back through `TryFrom<&str>` on the owned-`String`'s \
3171                 String::as_str borrow — a break signals the \
3172                 borrowed-input owned-`String` forward-emit and \
3173                 reverse-parse axes have drifted onto different \
3174                 vocabularies (unlike the peer CaixaKind axis pair, \
3175                 CaixaDialeto's forward emit and reverse parse share \
3176                 one PascalCase vocabulary by construction, so the \
3177                 round-trip composes directly)"
3178            );
3179        }
3180    }
3181
3182    #[test]
3183    fn caixa_dialeto_from_into_static_cow_str_routes_through_as_str_accessor() {
3184        // Fail-before-pass-after byte-parity pin on the newly lifted
3185        // `impl From<CaixaDialeto> for std::borrow::Cow<'static, str>`
3186        // — asserts the standard-library trait impl and the
3187        // substrate-primitive [`super::CaixaDialeto::as_str`]
3188        // `pub const fn` accessor resolve to the same four-arm
3189        // emit-set across every arm the exhaustive
3190        // [`super::CaixaDialeto::ALL`] slice enumerates. Rust's
3191        // standard library does not carry a blanket
3192        // `impl<T: AsRef<str>> From<T> for std::borrow::Cow<'static,
3193        // str>` (nor an `impl<T: fmt::Display> From<T> for
3194        // std::borrow::Cow<'static, str>`), so the
3195        // [`std::borrow::Cow<'static, str>`] forward-projection axis
3196        // is a distinct trait-idiomatic surface that a
3197        // `let key: std::borrow::Cow<'static, str> = dialeto.into();`-
3198        // shaped call site reaches through this impl and no other —
3199        // the paired sibling `From<CaixaDialeto> for &'static str`
3200        // and `From<CaixaDialeto> for String` impls force every
3201        // [`std::borrow::Cow<'static, str>`]-parameterized call site
3202        // through a `std::borrow::Cow::Borrowed(dialeto.as_str())` /
3203        // `std::borrow::Cow::Owned(dialeto.to_string())` /
3204        // `String::from(dialeto).into()` composition whose type
3205        // bounds have no compile-time link back to the substrate
3206        // primitive.
3207        //
3208        // Also asserts the projection lands on the zero-alloc
3209        // [`std::borrow::Cow::Borrowed`] arm (not the
3210        // [`std::borrow::Cow::Owned`] arm) — the substrate-primitive
3211        // [`super::CaixaDialeto::as_str`] accessor's `&'static str`
3212        // return lifetime by construction makes the borrowed arm the
3213        // type-correct projection with no runtime allocation. Any
3214        // future silent detour that routes the impl through the
3215        // owned arm (an accidental
3216        // `std::borrow::Cow::Owned(dialeto.to_string())` rewrite that
3217        // would allocate on every call site where the `&'static str`
3218        // return of [`super::CaixaDialeto::as_str`] makes the
3219        // zero-alloc borrowed projection type-correct) trips at
3220        // caixa-core test time under the
3221        // [`std::borrow::Cow::Borrowed`] discriminator witness rather
3222        // than at a downstream
3223        // [`std::borrow::Cow<'static, str>`]-bound consumer's silent
3224        // allocation.
3225        //
3226        // Second peer on the outside-M3 caixa-core tier of the
3227        // substrate-wide trait-idiomatic
3228        // [`std::borrow::Cow<'static, str>`] forward-projection
3229        // family — extends the axis off the two-list dep-graph
3230        // [`crate::dep::DepList`] pair (6858bac / 702cdf4) that
3231        // opened + closed the tier onto the dialect-classification
3232        // [`super::CaixaDialeto`] enum (the sole remaining
3233        // internal-classification peer on the caixa-core surface).
3234        // Every future closed-set fieldless typed enum peer on the
3235        // substrate is a future target of the campaign.
3236        for &variant in CaixaDialeto::ALL {
3237            let via_trait: std::borrow::Cow<'static, str> =
3238                <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3239            let via_method: &'static str = variant.as_str();
3240            assert_eq!(
3241                via_trait.as_ref(),
3242                via_method,
3243                "From<CaixaDialeto> for Cow<'static, str> impl must \
3244                 round-trip CaixaDialeto::{variant:?} to the same \
3245                 PascalCase byte-string CaixaDialeto::as_str returns \
3246                 — divergence signals a silent detour off the \
3247                 substrate-primitive accessor"
3248            );
3249            assert!(
3250                matches!(via_trait, std::borrow::Cow::Borrowed(_)),
3251                "From<CaixaDialeto> for Cow<'static, str> impl must \
3252                 land on the zero-alloc Cow::Borrowed arm on \
3253                 CaixaDialeto::{variant:?} — a Cow::Owned outcome \
3254                 signals the projection has silently allocated where \
3255                 the substrate-primitive CaixaDialeto::as_str \
3256                 `&'static str` return makes the borrowed arm the \
3257                 type-correct projection"
3258            );
3259            let via_into: std::borrow::Cow<'static, str> = variant.into();
3260            assert_eq!(
3261                via_into.as_ref(),
3262                via_method,
3263                "Into<Cow<'static, str>>::into on \
3264                 CaixaDialeto::{variant:?} must byte-equal \
3265                 CaixaDialeto::as_str on the same input — the \
3266                 blanket-derived Into shape must resolve to the same \
3267                 as_str dispatch as the explicit From impl"
3268            );
3269            assert!(
3270                matches!(via_into, std::borrow::Cow::Borrowed(_)),
3271                "Into<Cow<'static, str>>::into on \
3272                 CaixaDialeto::{variant:?} must land on the zero-alloc \
3273                 Cow::Borrowed arm — the blanket-derived Into shape \
3274                 must resolve to the same Cow::Borrowed dispatch as \
3275                 the explicit From impl"
3276            );
3277        }
3278    }
3279
3280    #[test]
3281    fn caixa_dialeto_from_into_static_cow_str_agrees_with_paired_axes_on_every_arm() {
3282        // Cross-axis partition pin: the newly lifted trait-idiomatic
3283        // `From<CaixaDialeto> for std::borrow::Cow<'static, str>`
3284        // (this lift), the paired owned-input
3285        // `From<CaixaDialeto> for &'static str`, and the paired
3286        // owned-input `From<CaixaDialeto> for String` forward
3287        // projections must resolve identically on every arm, locking
3288        // the three return-shape paths together by construction so
3289        // any future detour trips at caixa-core test time. Also
3290        // byte-parity witness against the sibling
3291        // [`ToString::to_string`] surface routed through
3292        // [`std::fmt::Display`] — every owned-heap-string path (the
3293        // [`std::borrow::Cow::Owned`] promotion of this axis's
3294        // `.into_owned()`, `From<CaixaDialeto> for String`, and
3295        // `.to_string()`) resolves to the same PascalCase byte-string
3296        // per arm.
3297        //
3298        // Then a `.iter().copied().map(std::borrow::Cow::from)` pipe
3299        // witness over [`super::CaixaDialeto::ALL`] that materializes
3300        // the four-arm accept-set through the
3301        // [`std::borrow::Cow<'static, str>`] axis alone — the exact
3302        // shape a future `axum::response::IntoResponse` per-arm
3303        // rejection-body composer, a future M4
3304        // `mesh.pleme.io/v1alpha1/Manifesto` CR materializer's
3305        // admission-webhook per-arm rejection-reason emitter whose
3306        // typing rules out the sibling [`AsRef<str>`] borrowed
3307        // return, or a future substrate-wide per-arm diagnostic
3308        // surface that binds through a
3309        // [`std::borrow::Cow<'static, str>`] boundary reaches through
3310        // — closing the composable-projection axis on the dialect-
3311        // classification closed-set fieldless typed enum peer. The
3312        // pipe witness also pins the zero-alloc discipline: every
3313        // element in the collected vector satisfies the
3314        // [`std::borrow::Cow::Borrowed`] arm predicate, so a future
3315        // accidental silent-allocation regression on the pipe's
3316        // iteration axis is a caixa-core-test-time failure.
3317        //
3318        // Then a direct round-trip witness through
3319        // [`TryFrom<&str>`] on the projection's
3320        // [`std::borrow::Cow::as_ref`] borrow — unlike the peer
3321        // [`crate::CaixaKind`] axis pair (whose forward emit lands
3322        // on the lowercase Portuguese diagnostic vocabulary while
3323        // the reverse parse lands on the `PascalCase` wire
3324        // vocabulary, forcing the round-trip through an intermediate
3325        // [`crate::CaixaKind::wire_name`] hop),
3326        // [`super::CaixaDialeto`]'s forward emit and reverse parse
3327        // share one `PascalCase` vocabulary by construction, so the
3328        // [`std::borrow::Cow<'static, str>`] projection composes
3329        // directly with the trait-idiomatic reverse [`TryFrom<&str>`]
3330        // axis without the wire-vocab intermediate hop.
3331        for &variant in CaixaDialeto::ALL {
3332            let via_cow: std::borrow::Cow<'static, str> =
3333                <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3334            let via_static: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
3335            let via_string: String = <String as From<CaixaDialeto>>::from(variant);
3336            assert_eq!(
3337                via_cow.as_ref(),
3338                via_static,
3339                "From<CaixaDialeto> for Cow<'static, str> and \
3340                 From<CaixaDialeto> for &'static str must resolve \
3341                 identically on CaixaDialeto::{variant:?} — \
3342                 divergence signals the Cow<'static, str> and \
3343                 &'static str return-shape paths have drifted onto \
3344                 different emit-sets"
3345            );
3346            assert_eq!(
3347                via_cow.as_ref(),
3348                via_string.as_str(),
3349                "From<CaixaDialeto> for Cow<'static, str> and \
3350                 From<CaixaDialeto> for String must resolve \
3351                 identically on CaixaDialeto::{variant:?} — \
3352                 divergence signals the Cow<'static, str> and String \
3353                 return-shape paths have drifted onto different \
3354                 emit-sets"
3355            );
3356            let via_to_string: String = variant.to_string();
3357            assert_eq!(
3358                via_cow.as_ref(),
3359                via_to_string.as_str(),
3360                "From<CaixaDialeto> for Cow<'static, str> must \
3361                 byte-equal CaixaDialeto::to_string on \
3362                 CaixaDialeto::{variant:?} — divergence signals the \
3363                 trait-idiomatic Cow<'static, str> forward-projection \
3364                 axis and the ToString-through-Display axis have \
3365                 drifted onto different emit-sets"
3366            );
3367        }
3368        let via_iter: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3369            .iter()
3370            .copied()
3371            .map(std::borrow::Cow::from)
3372            .collect();
3373        let via_method: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3374            .iter()
3375            .map(|d| std::borrow::Cow::Borrowed(d.as_str()))
3376            .collect();
3377        assert_eq!(
3378            via_iter, via_method,
3379            "`.iter().copied().map(Cow::from)` over \
3380             CaixaDialeto::ALL must byte-equal `.iter().map(|d| \
3381             Cow::Borrowed(d.as_str()))` on every arm — the \
3382             trait-idiomatic `From<CaixaDialeto> for Cow<'static, \
3383             str>` axis is what makes the `Cow::from` composition \
3384             route through the substrate-primitive \
3385             CaixaDialeto::as_str accessor rather than a per-call-\
3386             site open-code"
3387        );
3388        for cow in &via_iter {
3389            assert!(
3390                matches!(cow, std::borrow::Cow::Borrowed(_)),
3391                "`.iter().copied().map(Cow::from)` over \
3392                 CaixaDialeto::ALL must land on the zero-alloc \
3393                 Cow::Borrowed arm on every element — a Cow::Owned \
3394                 outcome signals the pipe has silently allocated \
3395                 where the substrate-primitive \
3396                 CaixaDialeto::as_str `&'static str` return makes \
3397                 the borrowed arm the type-correct projection"
3398            );
3399        }
3400        for &variant in CaixaDialeto::ALL {
3401            let via_cow: std::borrow::Cow<'static, str> =
3402                <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3403            let re_parsed: Result<CaixaDialeto, ()> =
3404                <CaixaDialeto as TryFrom<&str>>::try_from(via_cow.as_ref());
3405            assert_eq!(
3406                re_parsed,
3407                Ok(variant),
3408                "trait-idiomatic Cow<'static, str> forward-projection \
3409                 + reverse-projection axis pair must round-trip \
3410                 CaixaDialeto::{variant:?} through `.into::<Cow<\
3411                 'static, str>>()` on the owned-input surface and \
3412                 back through `TryFrom<&str>` on the projection's \
3413                 Cow::as_ref borrow — a break signals the \
3414                 Cow<'static, str> forward-emit and reverse-parse \
3415                 axes have drifted onto different vocabularies \
3416                 (unlike the peer CaixaKind axis pair, CaixaDialeto's \
3417                 forward emit and reverse parse share one PascalCase \
3418                 vocabulary by construction, so the round-trip \
3419                 composes directly)"
3420            );
3421        }
3422    }
3423
3424    #[test]
3425    fn caixa_dialeto_from_borrowed_into_static_cow_str_routes_through_as_str_accessor() {
3426        // Fail-before-pass-after byte-parity pin on the newly lifted
3427        // `impl From<&CaixaDialeto> for std::borrow::Cow<'static,
3428        // str>` — asserts the borrowed-input standard-library trait
3429        // impl and the substrate-primitive
3430        // [`super::CaixaDialeto::as_str`] `pub const fn` accessor
3431        // resolve to the same four-arm PascalCase emit-set across
3432        // every arm the exhaustive [`super::CaixaDialeto::ALL`] slice
3433        // enumerates. Rust's standard library does not carry a blanket
3434        // `impl<T: AsRef<str>> From<&T> for Cow<'static, str>` (nor a
3435        // `Copy`-based `impl<T: Copy, U: From<T>> From<&T> for U`), so
3436        // the borrowed-input `Cow<'static, str>` forward-projection
3437        // axis is a distinct trait-idiomatic surface that a
3438        // `let key: Cow<'static, str> = (&dialeto).into();`-shaped
3439        // call site or a `CaixaDialeto::ALL.iter().map(Cow::from)`-
3440        // shaped pipe reaches through this impl and no other — the
3441        // paired owned-input `From<CaixaDialeto> for Cow<'static, str>`
3442        // impl (8322511) forces every borrowed-input call site
3443        // through an explicit `Copy` deref (`Cow::from(*dialeto)`) or
3444        // a `Cow::Borrowed(dialeto.as_str())` open-code whose type
3445        // bounds have no compile-time link back to the substrate
3446        // primitive.
3447        //
3448        // Also asserts the projection lands on the zero-alloc
3449        // [`std::borrow::Cow::Borrowed`] arm (not the
3450        // [`std::borrow::Cow::Owned`] arm) — the substrate-primitive
3451        // [`super::CaixaDialeto::as_str`] accessor's `&'static str`
3452        // return lifetime by construction makes the borrowed arm the
3453        // type-correct projection with no runtime allocation on the
3454        // borrowed-input surface just as on the paired owned-input
3455        // surface.
3456        //
3457        // Closes the `{Self, &Self}` input-shape corner on the
3458        // outside-M3 caixa-core dialect-classification
3459        // [`Cow<'static, str>`] axis on the second outside-M3
3460        // caixa-core closed-set fieldless typed enum peer on the
3461        // caixa surface, exactly as 702cdf4 closed it on the first
3462        // outside-M3 caixa-core peer ([`crate::dep::DepList`]) one
3463        // commit after the owning half (6858bac) landed, as afdf0f4
3464        // closed it on the second M3-mesh-primitive peer
3465        // ([`crate::aplicacao::PlacementStrategy`]) one commit after
3466        // the owning half (eee504d) landed, as 25690ef closed it on
3467        // the first M3-mesh-primitive peer
3468        // ([`crate::aplicacao::WitShape`]) one commit after the
3469        // owning half (8634dec) landed, as d45c409 closed it on the
3470        // top-level [`crate::CaixaKind`] one commit after the owning
3471        // half (99c1735) landed, and as 9b3e4b3 / ee577fd closed it
3472        // on the M2 OTP-shape [`crate::supervisor::RestartStrategy`]
3473        // / [`crate::supervisor::RestartPolicy`] sibling peers one
3474        // commit after (7dd28b3 / 0612398) landed.
3475        for &variant in CaixaDialeto::ALL {
3476            let via_trait: std::borrow::Cow<'static, str> =
3477                <std::borrow::Cow<'static, str> as From<&CaixaDialeto>>::from(&variant);
3478            let via_method: &'static str = variant.as_str();
3479            assert_eq!(
3480                via_trait.as_ref(),
3481                via_method,
3482                "From<&CaixaDialeto> for Cow<'static, str> impl must \
3483                 round-trip &CaixaDialeto::{variant:?} to the same \
3484                 PascalCase byte-string CaixaDialeto::as_str returns \
3485                 — divergence signals a silent detour off the \
3486                 substrate-primitive accessor"
3487            );
3488            assert!(
3489                matches!(via_trait, std::borrow::Cow::Borrowed(_)),
3490                "From<&CaixaDialeto> for Cow<'static, str> impl must \
3491                 land on the zero-alloc Cow::Borrowed arm on \
3492                 &CaixaDialeto::{variant:?} — a Cow::Owned outcome \
3493                 signals the projection has silently allocated where \
3494                 the substrate-primitive CaixaDialeto::as_str \
3495                 `&'static str` return makes the borrowed arm the \
3496                 type-correct projection"
3497            );
3498            let via_into: std::borrow::Cow<'static, str> = (&variant).into();
3499            assert_eq!(
3500                via_into.as_ref(),
3501                via_method,
3502                "Into<Cow<'static, str>>::into on \
3503                 &CaixaDialeto::{variant:?} must byte-equal \
3504                 CaixaDialeto::as_str on the same input — the \
3505                 blanket-derived Into shape on the borrowed-input \
3506                 surface must resolve to the same as_str dispatch as \
3507                 the explicit From impl"
3508            );
3509            assert!(
3510                matches!(via_into, std::borrow::Cow::Borrowed(_)),
3511                "Into<Cow<'static, str>>::into on \
3512                 &CaixaDialeto::{variant:?} must land on the \
3513                 zero-alloc Cow::Borrowed arm — the blanket-derived \
3514                 Into shape on the borrowed-input surface must \
3515                 resolve to the same Cow::Borrowed dispatch as the \
3516                 explicit From impl"
3517            );
3518        }
3519    }
3520
3521    #[test]
3522    #[allow(
3523        clippy::too_many_lines,
3524        reason = "cross-axis partition pin folds four return-shape paths \
3525                  (borrowed-input Cow<'static, str>, owned-input Cow<'static, str>, \
3526                  borrowed-input &'static str, borrowed-input String) plus the \
3527                  ToString-through-Display witness plus a `.iter().map(Cow::from)` \
3528                  pipe witness with zero-alloc discriminator plus a direct \
3529                  round-trip witness through TryFrom<&str> over four typed \
3530                  variants; the linear per-axis repetition is exactly what the \
3531                  fold is pinning — a helper would hide the shape it locks"
3532    )]
3533    fn caixa_dialeto_from_borrowed_into_static_cow_str_agrees_with_paired_axes_on_every_arm() {
3534        // Cross-axis partition pin: the newly lifted trait-idiomatic
3535        // borrowed-input `From<&CaixaDialeto> for
3536        // std::borrow::Cow<'static, str>` (this lift), the paired
3537        // owned-input `From<CaixaDialeto> for
3538        // std::borrow::Cow<'static, str>`, the paired borrowed-input
3539        // `From<&CaixaDialeto> for &'static str`, and the paired
3540        // borrowed-input `From<&CaixaDialeto> for String` forward
3541        // projections must resolve identically on every arm, locking
3542        // the four return-shape paths together by construction so any
3543        // future detour trips at caixa-core test time. Also
3544        // byte-parity witness against the sibling
3545        // [`ToString::to_string`] surface routed through
3546        // [`std::fmt::Display`].
3547        //
3548        // Then a `.iter().map(std::borrow::Cow::from)` pipe witness
3549        // over [`super::CaixaDialeto::ALL`] — whose iterator yields
3550        // `&CaixaDialeto` by construction, so the borrowed-input
3551        // [`std::borrow::Cow<'static, str>`] axis is what routes the
3552        // pipe through the substrate-primitive
3553        // [`super::CaixaDialeto::as_str`] accessor with the zero-alloc
3554        // [`std::borrow::Cow::Borrowed`] arm and without a spurious
3555        // [`Copy`] deref. Every collected element satisfies the
3556        // [`std::borrow::Cow::Borrowed`]-arm predicate so a future
3557        // accidental silent-allocation regression on the pipe's
3558        // iteration axis is a caixa-core-test-time failure.
3559        //
3560        // Then a direct round-trip witness through [`TryFrom<&str>`]
3561        // on the projection's [`std::borrow::Cow::as_ref`] borrow —
3562        // unlike the peer [`crate::CaixaKind`] axis pair (whose
3563        // forward emit lands on the lowercase Portuguese diagnostic
3564        // vocabulary while the reverse parse lands on the
3565        // `PascalCase` wire vocabulary, forcing the round-trip
3566        // through an intermediate [`crate::CaixaKind::wire_name`]
3567        // hop), [`super::CaixaDialeto`]'s forward emit and reverse
3568        // parse share one `PascalCase` vocabulary by construction, so
3569        // the borrowed-input [`std::borrow::Cow<'static, str>`]
3570        // projection composes directly with the trait-idiomatic
3571        // reverse [`TryFrom<&str>`] axis without the wire-vocab
3572        // intermediate hop.
3573        for &variant in CaixaDialeto::ALL {
3574            let via_borrowed_cow: std::borrow::Cow<'static, str> =
3575                <std::borrow::Cow<'static, str> as From<&CaixaDialeto>>::from(&variant);
3576            let via_owned_cow: std::borrow::Cow<'static, str> =
3577                <std::borrow::Cow<'static, str> as From<CaixaDialeto>>::from(variant);
3578            let via_borrowed_static: &'static str =
3579                <&'static str as From<&CaixaDialeto>>::from(&variant);
3580            let via_borrowed_string: String = <String as From<&CaixaDialeto>>::from(&variant);
3581            assert_eq!(
3582                via_borrowed_cow.as_ref(),
3583                via_owned_cow.as_ref(),
3584                "From<&CaixaDialeto> for Cow<'static, str> and \
3585                 From<CaixaDialeto> for Cow<'static, str> must \
3586                 resolve identically on CaixaDialeto::{variant:?} — \
3587                 divergence signals the borrowed-input and \
3588                 owned-input Cow<'static, str> return-shape paths \
3589                 have drifted onto different emit-sets"
3590            );
3591            assert_eq!(
3592                via_borrowed_cow.as_ref(),
3593                via_borrowed_static,
3594                "From<&CaixaDialeto> for Cow<'static, str> and \
3595                 From<&CaixaDialeto> for &'static str must resolve \
3596                 identically on CaixaDialeto::{variant:?} — \
3597                 divergence signals the borrowed-input Cow<'static, \
3598                 str> and borrowed-input &'static str return-shape \
3599                 paths have drifted onto different emit-sets"
3600            );
3601            assert_eq!(
3602                via_borrowed_cow.as_ref(),
3603                via_borrowed_string.as_str(),
3604                "From<&CaixaDialeto> for Cow<'static, str> and \
3605                 From<&CaixaDialeto> for String must resolve \
3606                 identically on CaixaDialeto::{variant:?} — \
3607                 divergence signals the borrowed-input Cow<'static, \
3608                 str> and borrowed-input String return-shape paths \
3609                 have drifted onto different emit-sets"
3610            );
3611            let via_to_string: String = variant.to_string();
3612            assert_eq!(
3613                via_borrowed_cow.as_ref(),
3614                via_to_string.as_str(),
3615                "From<&CaixaDialeto> for Cow<'static, str> must \
3616                 byte-equal CaixaDialeto::to_string on \
3617                 CaixaDialeto::{variant:?} — divergence signals the \
3618                 borrowed-input Cow<'static, str> forward-projection \
3619                 axis and the ToString-through-Display axis have \
3620                 drifted onto different emit-sets"
3621            );
3622        }
3623        let via_iter: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3624            .iter()
3625            .map(std::borrow::Cow::from)
3626            .collect();
3627        let via_method: Vec<std::borrow::Cow<'static, str>> = CaixaDialeto::ALL
3628            .iter()
3629            .map(|d| std::borrow::Cow::Borrowed(d.as_str()))
3630            .collect();
3631        assert_eq!(
3632            via_iter, via_method,
3633            "`.iter().map(Cow::from)` over CaixaDialeto::ALL must \
3634             byte-equal `.iter().map(|d| Cow::Borrowed(d.as_str()))` \
3635             on every arm — the trait-idiomatic `From<&CaixaDialeto> \
3636             for Cow<'static, str>` axis is what makes the \
3637             `Cow::from` composition on the borrowed-iteration axis \
3638             route through the substrate-primitive \
3639             CaixaDialeto::as_str accessor without a spurious Copy \
3640             deref"
3641        );
3642        for cow in &via_iter {
3643            assert!(
3644                matches!(cow, std::borrow::Cow::Borrowed(_)),
3645                "`.iter().map(Cow::from)` over CaixaDialeto::ALL \
3646                 must land on the zero-alloc Cow::Borrowed arm on \
3647                 every element — a Cow::Owned outcome signals the \
3648                 borrowed-iteration pipe has silently allocated \
3649                 where the substrate-primitive CaixaDialeto::as_str \
3650                 `&'static str` return makes the borrowed arm the \
3651                 type-correct projection"
3652            );
3653        }
3654        for &variant in CaixaDialeto::ALL {
3655            let via_cow: std::borrow::Cow<'static, str> =
3656                <std::borrow::Cow<'static, str> as From<&CaixaDialeto>>::from(&variant);
3657            let re_parsed: Result<CaixaDialeto, ()> =
3658                <CaixaDialeto as TryFrom<&str>>::try_from(via_cow.as_ref());
3659            assert_eq!(
3660                re_parsed,
3661                Ok(variant),
3662                "trait-idiomatic borrowed-input Cow<'static, str> \
3663                 forward-projection + reverse-projection axis pair \
3664                 must round-trip &CaixaDialeto::{variant:?} through \
3665                 `.into::<Cow<'static, str>>()` on the borrowed-input \
3666                 surface and back through `TryFrom<&str>` on the \
3667                 projection's Cow::as_ref borrow — a break signals \
3668                 the borrowed-input Cow<'static, str> forward-emit \
3669                 and reverse-parse axes have drifted onto different \
3670                 vocabularies (unlike the peer CaixaKind axis pair, \
3671                 CaixaDialeto's forward emit and reverse parse share \
3672                 one PascalCase vocabulary by construction, so the \
3673                 round-trip composes directly)"
3674            );
3675        }
3676    }
3677}