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/// A source that is not a `(defcaixa …)` / `(defmolde …)` form at all.
898#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
899pub enum DialetoError {
900 #[error("source has no top-level form")]
901 Vazio,
902 #[error("top-level form is not a list — a manifest is `(defcaixa …)`")]
903 NaoEhLista,
904 #[error(
905 "top-level form is headed by `{encontrado}`, not `defcaixa` or `defmolde` \
906 (a manifest's first form must be the declaration itself)"
907 )]
908 CabecaErrada { encontrado: String },
909 #[error("manifest does not parse as tatara-lisp: {0}")]
910 Leitura(String),
911}
912
913impl DialetoError {
914 /// Construct a [`DialetoError::CabecaErrada`] naming the offending
915 /// head symbol found at the top-level form.
916 ///
917 /// Substrate primitive every [`classify_form`] wrong-head fallthrough
918 /// wire-up site now routes through, folding the pre-lift uniform
919 /// three-line `Self::CabecaErrada { encontrado: <head>.to_string() }`
920 /// one-field struct-literal onto one substrate primitive matching the
921 /// peer `LimitsError::unknown_byte_unit(unit: &str)` /
922 /// `LimitsError::unknown_duration_unit(unit: &str)`
923 /// (`limits_codec_unit_only_ctors!` — 29fac09) single-slot
924 /// discipline on the sibling one-field `{ <field>: String }` envelope
925 /// axis, and matching the peer `ManifestError::code_path_empty` /
926 /// `BehaviorError::empty_path` / `UpgradeError::duplicate_from` /
927 /// `AplicacaoError::placement_cluster_duplicate` (94dabc8 / 0e33b37 /
928 /// 7e52aec / 92b1c92) single-slot inherent-ctor discipline every
929 /// sibling `{ <field>: <T> }` error-envelope variant on caixa-core's
930 /// error surface now carries.
931 ///
932 /// The one open-coded wire-up site — `classify_form`'s wrong-head
933 /// fallthrough arm on the `head: &str` binding read from the
934 /// top-level form via [`tatara_lisp::Sexp::as_symbol`] — opened the
935 /// identical three-line
936 /// `Self::CabecaErrada { encontrado: <head>.to_string() }` block
937 /// against the codec-scoped `<head>: &str` binding. Now routes
938 /// through `DialetoError::cabeca_errada(head)`, byte-equal to the
939 /// pre-lift struct-literal on the same `&str` fixture, so any future
940 /// widening of the diagnostic shape (e.g. carrying the source-file
941 /// path alongside the head symbol, carrying the head symbol's
942 /// position offset for an authoring-surface caret pointer) lands at
943 /// exactly one dispatch on the substrate primitive rather than re-
944 /// inlining the struct-literal at every wrong-head fallthrough
945 /// consumer.
946 #[must_use]
947 pub fn cabeca_errada(encontrado: &str) -> Self {
948 Self::CabecaErrada {
949 encontrado: encontrado.to_string(),
950 }
951 }
952
953 /// Construct a [`DialetoError::Leitura`] carrying the offending
954 /// tatara-lisp reader-error message `reason` verbatim in the
955 /// variant's tuple-newtype payload.
956 ///
957 /// Substrate primitive every [`classify`] tatara-lisp-reader
958 /// map-err wire-up site now routes through, folding the pre-lift
959 /// uniform `Self::Leitura(<into-String-expr>)` tuple-newtype
960 /// construction onto one substrate primitive matching the peer
961 /// `LimitsError::empty_byte_size` / `LimitsError::empty_duration`
962 /// (7a4b003 / 319216c) `(String)` single-slot tuple-newtype
963 /// discipline on the sibling
964 /// [`crate::limits::LimitsError`] envelope's empty-shape axis of
965 /// the paired codec-magnitude family. Peer to the sibling
966 /// [`DialetoError::cabeca_errada`] ctor on the same envelope's
967 /// wrong-head axis but on the tatara-lisp-reader axis rather than
968 /// the classifier-fallthrough axis. Closes the last un-lifted
969 /// variant on [`DialetoError`] — every one of the sole wire-up
970 /// sites (the [`classify`] tatara-lisp-reader `.map_err(|e|
971 /// Self::Leitura(e.to_string()))` arm) opened the identical
972 /// `DialetoError::Leitura(<into-String-expr>)` block against the
973 /// codec-scoped `String` (`e.to_string()`) binding, so the fold
974 /// routes the site through one dispatch on a uniform
975 /// `impl Into<String>` param, byte-equal to the pre-lift
976 /// tuple-newtype construction on the same argument.
977 ///
978 /// The `impl Into<String>` bound covers both wire-up shapes on
979 /// [`classify`] — a `String` binding (`e.to_string()` on the
980 /// [`tatara_lisp::Error`]-carrying `e` binding) and a `&str`
981 /// binding (a future admission-webhook consumer probing a
982 /// caller-scoped `&'static str` fixture, a future
983 /// `feira lint --tatara-reader-round-trip` verb sweeping every
984 /// `tatara_lisp::read` return through the same shape gate) —
985 /// without forcing the caller to spell the conversion at the
986 /// wire-up site. Same shape the peer
987 /// [`crate::limits::LimitsError::empty_byte_size`] /
988 /// [`crate::limits::LimitsError::empty_duration`] /
989 /// [`crate::limits::LimitsError::bad_millicores`] /
990 /// [`crate::limits::LimitsError::bad_byte_magnitude`] /
991 /// [`crate::limits::LimitsError::bad_duration_magnitude`] folds
992 /// carry on the peer bad-magnitude and empty-shape axes of the
993 /// same paired `(String)` tuple-newtype codec-magnitude family.
994 /// `#[must_use]` fires a compile warning at any wire-up that
995 /// mistakenly discards the constructed error.
996 ///
997 /// Every future consumer that wants to construct this variant
998 /// outside [`classify`] (a deferred `feira lint --tatara-reader-
999 /// round-trip` per-caixa admission verb probing each authored
1000 /// manifest against the tatara-lisp-reader shape gate, an M4
1001 /// typed `mesh.pleme.io/v1alpha1/Servico` CR materializer's
1002 /// per-manifest admission validator re-checking one edited
1003 /// `caixa.lisp` against the reader floor, a per-`caixa.lisp`
1004 /// value-shape pre-emitter probing each declared manifest ahead
1005 /// of the operator's admit-cycle) now reaches the variant
1006 /// through one call rather than re-inlining the tuple-newtype
1007 /// block in lockstep with the pre-existing wire-up.
1008 #[must_use]
1009 pub fn leitura(reason: impl Into<String>) -> Self {
1010 Self::Leitura(reason.into())
1011 }
1012}
1013
1014/// Classify a manifest source without committing to either schema.
1015///
1016/// Deliberately reads only the head symbol and the set of top-level keywords —
1017/// enough to route, never enough to half-parse. A classifier that started
1018/// validating would grow into a third parser, which is the shape of the problem
1019/// it exists to name.
1020///
1021/// # Errors
1022/// [`DialetoError`] when the source is not a manifest declaration at all.
1023pub fn classify(src: &str) -> Result<CaixaDialeto, DialetoError> {
1024 let forms = tatara_lisp::read(src).map_err(|e| DialetoError::leitura(e.to_string()))?;
1025 let first = forms.first().ok_or(DialetoError::Vazio)?;
1026 classify_form(first)
1027}
1028
1029/// [`classify`] over an already-read form.
1030///
1031/// # Errors
1032/// [`DialetoError`] when the form is not a manifest declaration.
1033pub fn classify_form(form: &Sexp) -> Result<CaixaDialeto, DialetoError> {
1034 let list = form.as_list().ok_or(DialetoError::NaoEhLista)?;
1035 let head = list
1036 .first()
1037 .and_then(Sexp::as_symbol)
1038 .ok_or(DialetoError::NaoEhLista)?;
1039
1040 match head {
1041 // `defmolde` is unambiguous by construction — it exists precisely so a
1042 // consumer never has to infer which declaration it holds. Both arities
1043 // are the same declaration; the positional one keeps its own variant
1044 // only so a census can report the split.
1045 "defmolde" => {
1046 return Ok(if starts_with_positional_name(&list[1..]) {
1047 CaixaDialeto::MoldePosicional
1048 } else {
1049 CaixaDialeto::Molde
1050 });
1051 }
1052 "defcaixa" => {}
1053 other => {
1054 return Err(DialetoError::cabeca_errada(other));
1055 }
1056 }
1057
1058 let args = &list[1..];
1059
1060 // `(defcaixa <symbol> :kind … :ecosystem …)`. Only the Molde dialect has a
1061 // positional arity; `Caixa` is keyword-only, so a leading bare symbol
1062 // settles it without looking further.
1063 if starts_with_positional_name(args) {
1064 return Ok(CaixaDialeto::MoldePosicional);
1065 }
1066
1067 let keys = top_level_keywords(args);
1068 let has = |k: &str| keys.iter().any(|s| s == k);
1069
1070 // Order matters, and it is not arbitrary: `:nome` and `:name` are the two
1071 // required head slots and no file in the measured corpus carries both.
1072 // Checking them FIRST means the decision rests on the one slot each schema
1073 // makes mandatory, rather than on optional evidence like `:ecosystem`.
1074 if has("nome") {
1075 return Ok(CaixaDialeto::Pacote);
1076 }
1077 if has("name") || has("ecosystem") || has("package") {
1078 return Ok(CaixaDialeto::Molde);
1079 }
1080 Ok(CaixaDialeto::Desconhecido)
1081}
1082
1083/// True when the first argument is a bare symbol rather than a keyword — the
1084/// positional-name arity.
1085fn starts_with_positional_name(args: &[Sexp]) -> bool {
1086 matches!(args.first(), Some(Sexp::Atom(Atom::Symbol(_))))
1087}
1088
1089/// The top-level keyword names (without the leading `:`) of a kwarg list.
1090///
1091/// Steps in pairs so a keyword appearing as a VALUE — `:kind :Biblioteca`, or a
1092/// nested `(:nome "dep" :versao "^0.1")` inside `:deps` — is never counted as a
1093/// top-level slot. A naive scan for `:nome` anywhere in the source classifies
1094/// every Molde manifest with a `:deps` list as a Pacote.
1095fn top_level_keywords(args: &[Sexp]) -> Vec<String> {
1096 let mut out = Vec::new();
1097 let mut i = 0;
1098 while i < args.len() {
1099 if let Sexp::Atom(Atom::Keyword(k)) = &args[i] {
1100 out.push(k.clone());
1101 i += 2;
1102 } else {
1103 i += 1;
1104 }
1105 }
1106 out
1107}
1108
1109#[cfg(test)]
1110mod tests {
1111 use super::*;
1112
1113 const PACOTE: &str = r#"
1114 (defcaixa
1115 :nome "checkout"
1116 :versao "0.1.0"
1117 :kind Servico
1118 :deps ((:nome "caixa-teia" :versao "^0.1")))
1119 "#;
1120
1121 const MOLDE: &str = r#"
1122 (defcaixa
1123 :name "base64"
1124 :kind :Biblioteca
1125 :ecosystem :rust-single-crate
1126 :package {:name "base64" :version "0.22.1"}
1127 :workflows [:auto-release])
1128 "#;
1129
1130 const MOLDE_POSICIONAL: &str = r#"
1131 (defcaixa todoku-go
1132 :kind :Biblioteca
1133 :ecosystem :go
1134 :package {:name "todoku-go" :version "0.3.0"})
1135 "#;
1136
1137 #[test]
1138 fn the_package_dialect_is_recognised() {
1139 assert_eq!(classify(PACOTE), Ok(CaixaDialeto::Pacote));
1140 }
1141
1142 #[test]
1143 fn the_repo_surface_dialect_is_recognised() {
1144 assert_eq!(classify(MOLDE), Ok(CaixaDialeto::Molde));
1145 }
1146
1147 #[test]
1148 fn the_positional_arity_is_recognised() {
1149 assert_eq!(
1150 classify(MOLDE_POSICIONAL),
1151 Ok(CaixaDialeto::MoldePosicional)
1152 );
1153 }
1154
1155 #[test]
1156 fn defmolde_classifies_without_inference() {
1157 // The whole point of the new keyword: no schema sniffing required.
1158 let src = r#"(defmolde :name "x" :kind :Biblioteca :ecosystem :go)"#;
1159 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1160 let pos = r"(defmolde todoku-go :kind :Biblioteca :ecosystem :go)";
1161 assert_eq!(classify(pos), Ok(CaixaDialeto::MoldePosicional));
1162 }
1163
1164 #[test]
1165 fn a_nested_nome_does_not_make_a_repo_surface_look_like_a_package() {
1166 // The exact failure a substring scan produces: `:deps ((:nome …))`
1167 // contains `:nome`, but not as a top-level slot.
1168 let src = r#"
1169 (defcaixa
1170 :name "x"
1171 :ecosystem :rust-single-crate
1172 :deps ((:nome "inner" :versao "^0.1")))
1173 "#;
1174 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1175 }
1176
1177 #[test]
1178 fn a_keyword_in_value_position_is_not_a_slot() {
1179 // `:kind :Biblioteca` — the value is itself a keyword. Stepping one at
1180 // a time would read `:Biblioteca` as a top-level slot.
1181 let src = r#"(defcaixa :kind :Biblioteca :name "x")"#;
1182 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
1183 }
1184
1185 #[test]
1186 fn an_unrecognised_defcaixa_is_reported_not_guessed() {
1187 let src = r#"(defcaixa :licenca "MIT")"#;
1188 assert_eq!(classify(src), Ok(CaixaDialeto::Desconhecido));
1189 }
1190
1191 #[test]
1192 fn a_form_that_is_not_a_manifest_is_an_error_not_a_dialect() {
1193 assert_eq!(
1194 classify("(defflake :nome \"x\")"),
1195 Err(DialetoError::cabeca_errada("defflake"))
1196 );
1197 assert_eq!(classify(""), Err(DialetoError::Vazio));
1198 }
1199
1200 #[test]
1201 fn every_dialect_names_its_consumer_and_its_canonical_keyword() {
1202 // Guards the routing table itself: a new variant added without an arm
1203 // here is a compile error in the match, and a variant that claims
1204 // `defcaixa` while being read by pleme-doc-gen would re-open the
1205 // collision this module closes. Sweeps [`CaixaDialeto::ALL`] rather
1206 // than the pre-lift open-coded four-arm literal list — a future arm
1207 // addition extends the slice as one edit and this pin picks it up
1208 // by construction.
1209 for &d in CaixaDialeto::ALL {
1210 assert!(!d.descricao().is_empty(), "{d}");
1211 assert!(!d.consumidor().is_empty(), "{d}");
1212 }
1213 assert_eq!(CaixaDialeto::Pacote.palavra_canonica(), "defcaixa");
1214 assert_eq!(CaixaDialeto::Molde.palavra_canonica(), "defmolde");
1215 assert_ne!(
1216 CaixaDialeto::Pacote.palavra_canonica(),
1217 CaixaDialeto::Molde.palavra_canonica(),
1218 "the two dialects must not share a canonical keyword — that IS the defect"
1219 );
1220 }
1221
1222 #[test]
1223 fn caixa_dialeto_all_enumerates_every_variant_exactly_once() {
1224 // Three-legged exhaustiveness pin, peer of the sibling
1225 // `caixa_kind_all_enumerates_every_variant_exactly_once`
1226 // (caixa-core/src/kind.rs) /
1227 // `restart_strategy_all_enumerates_every_variant_exactly_once`
1228 // (caixa-core/src/supervisor.rs) shape.
1229 //
1230 // 1. arm-count invariant: `ALL.len()` matches the declared arm
1231 // count (four — a fifth arm added without extending `ALL`
1232 // fails this pin at caixa-core test time);
1233 // 2. pairwise-distinctness invariant: every variant appears at
1234 // most once in the slice (a duplicate arm would silently
1235 // double-count in the census consumer, so the pin rejects
1236 // duplicates outright);
1237 // 3. coverage invariant: every literal `CaixaDialeto::X` is in
1238 // the slice (the compiler-checked exhaustiveness on the peer
1239 // per-arm `match self` in the accessors keeps the enum arm
1240 // set and the `ALL` slice mutually aligned).
1241 assert_eq!(
1242 CaixaDialeto::ALL.len(),
1243 4,
1244 "ALL must list every arm exactly once; a fifth arm added \
1245 without extending ALL fails this pin — extend ALL alongside \
1246 the new variant"
1247 );
1248
1249 let mut seen: Vec<CaixaDialeto> = Vec::new();
1250 for &d in CaixaDialeto::ALL {
1251 assert!(
1252 !seen.contains(&d),
1253 "ALL contains a duplicate arm: {d}. Every variant appears \
1254 exactly once — a duplicate would double-count in every \
1255 iteration consumer"
1256 );
1257 seen.push(d);
1258 }
1259
1260 // Coverage: exhaustively assert every literal variant is somewhere
1261 // in the slice. Written as an exhaustive `match` so a future arm
1262 // addition fails to compile here (missing match arm) until the
1263 // corresponding `assert` is added — the compiler enforces the pin's
1264 // completeness rather than a hand-maintained variant list.
1265 for variant in [
1266 CaixaDialeto::Pacote,
1267 CaixaDialeto::Molde,
1268 CaixaDialeto::MoldePosicional,
1269 CaixaDialeto::Desconhecido,
1270 ] {
1271 let coverage_probe = match variant {
1272 CaixaDialeto::Pacote
1273 | CaixaDialeto::Molde
1274 | CaixaDialeto::MoldePosicional
1275 | CaixaDialeto::Desconhecido => variant,
1276 };
1277 assert!(
1278 CaixaDialeto::ALL.contains(&coverage_probe),
1279 "ALL is missing variant {coverage_probe} — extend the slice"
1280 );
1281 }
1282 }
1283
1284 #[test]
1285 fn caixa_dialeto_all_is_const_and_matches_iteration_count() {
1286 // Pins the const-ness of the slice at const-fold time. A future
1287 // change that promoted `ALL` to a non-const initializer (a lazy-
1288 // static, a runtime-computed Vec) would fail to compile here —
1289 // the pin locks in the compile-time-known iteration surface
1290 // every consumer builds against. Peer of the sibling
1291 // `caixa_kind_all_is_const_and_matches_iteration_count` (kind.rs)
1292 // / `restart_strategy_all_is_const_and_matches_iteration_count`
1293 // (supervisor.rs) shape.
1294 const ALL: &[CaixaDialeto] = CaixaDialeto::ALL;
1295 assert_eq!(ALL.len(), CaixaDialeto::ALL.len());
1296 // Sweep the iterator without collapsing to `.len()` so a future
1297 // change to `ALL`'s carrier that decouples `.len()` from the
1298 // iteration count (a lazy-computed shape, an alias `impl Iterator`
1299 // return, a wrapper newtype) still passes here iff the two agree
1300 // arm-for-arm; the `#[allow]` opts this local pin out of the
1301 // clippy `iter_count` collapse that would defeat the intent.
1302 #[allow(clippy::iter_count)]
1303 let iterated = ALL.iter().count();
1304 assert_eq!(iterated, CaixaDialeto::ALL.len());
1305 }
1306
1307 #[test]
1308 fn caixa_dialeto_all_covers_every_variant_by_display_probe() {
1309 // Fanning `Display` over the slice sweeps the paired accessors
1310 // ([`CaixaDialeto::palavra_canonica`] / [`CaixaDialeto::consumidor`]
1311 // / [`CaixaDialeto::descricao`]) at every arm — every returned
1312 // byte-string is non-empty (the accessors' contract). A future
1313 // arm added without extending its per-arm `match self` return
1314 // would compile-fail at the accessor call inside the loop;
1315 // together with the `ALL.len() == 4` pin above, this locks the
1316 // accessor arm-set and the `ALL` slice mutually.
1317 for &d in CaixaDialeto::ALL {
1318 let display_form = d.to_string();
1319 assert!(
1320 !display_form.is_empty(),
1321 "Display must render a non-empty byte-string for every \
1322 arm; empty: {d:?}"
1323 );
1324 // Consumidor / descricao / palavra-canonica must each surface
1325 // a non-empty scalar; every downstream diagnostic consumer
1326 // reaches through these accessors.
1327 assert!(!d.palavra_canonica().is_empty(), "{d}");
1328 assert!(!d.consumidor().is_empty(), "{d}");
1329 assert!(!d.descricao().is_empty(), "{d}");
1330 }
1331 }
1332
1333 #[test]
1334 fn caixa_dialeto_as_str_returns_pascal_case_variant_name() {
1335 // Fail-before-pass-after per-arm shape pin: the four
1336 // [`CaixaDialeto::as_str`] arms must return the canonical
1337 // `PascalCase` byte-string that names the variant. Pre-lift this
1338 // byte-string existed only inside the hand-rolled Display impl's
1339 // four-arm literal-string match — every consumer that wanted the
1340 // `PascalCase` name reached through `format!("{d}")`'s allocation
1341 // path. Pinning the four arms explicitly here refuses a future
1342 // regression that ever reroutes an arm to a distinct spelling
1343 // (`"pacote"` lowercase, `"MoldePositional"` English rebrand,
1344 // `"Unknown"` for `Desconhecido`) — the census output and the
1345 // typed accessor would silently disagree until a downstream
1346 // consumer surfaced the drift at census time. Peer of the sibling
1347 // [`crate::supervisor::tests::restart_strategy_variants_serialize_to_lifted_scalar_values`]
1348 // / `placement_strategy_variants_serialize_to_lifted_scalar_values`
1349 // / `caixa_kind_as_str_returns_lifted_peer_const` shape on the
1350 // sibling closed-set typed-enum discriminator axes — the seventh
1351 // (and last unlifted) closed-set typed enum on the caixa surface
1352 // to converge onto the same per-arm-shape-pin discipline.
1353 for (variant, expected) in [
1354 (CaixaDialeto::Pacote, "Pacote"),
1355 (CaixaDialeto::Molde, "Molde"),
1356 (CaixaDialeto::MoldePosicional, "MoldePosicional"),
1357 (CaixaDialeto::Desconhecido, "Desconhecido"),
1358 ] {
1359 assert_eq!(
1360 variant.as_str(),
1361 expected,
1362 "CaixaDialeto::{variant:?}.as_str() must return the \
1363 canonical `PascalCase` variant-name byte-string; drift here \
1364 splits the census-facing text from the substrate \
1365 primitive every downstream consumer will read"
1366 );
1367 }
1368 }
1369
1370 #[test]
1371 fn caixa_dialeto_display_routes_through_as_str_helper() {
1372 // Fail-before-pass-after convergence pin: for every arm in
1373 // [`CaixaDialeto::ALL`], the [`std::fmt::Display`] rendered form
1374 // must byte-equal [`CaixaDialeto::as_str`]'s return value. Pre-
1375 // lift these two paths were structurally independent — the
1376 // Display impl hand-rolled its own four-arm literal-string
1377 // match with no compile-time link back to any substrate accessor
1378 // — so a future variant rename could land at `Display` without
1379 // touching a paired accessor (or vice versa), silently splitting
1380 // the two paths on the renamed arm. Pinning the byte-equality
1381 // here makes any such split a caixa-core build-time failure at
1382 // this test rather than surfacing far from the rename commit as
1383 // a downstream census consumer emitting one spelling while the
1384 // typed accessor returned another. Peer of the sibling
1385 // [`crate::kind::tests::caixa_kind_display_routes_through_as_str_helper`]
1386 // (which pins the same convergence on the [`crate::CaixaKind`]
1387 // closed-set axis) — extends the discipline onto the seventh
1388 // (and last unlifted) closed-set fieldless typed enum on the
1389 // caixa surface.
1390 for &variant in CaixaDialeto::ALL {
1391 assert_eq!(
1392 variant.to_string(),
1393 variant.as_str(),
1394 "CaixaDialeto::{variant:?} Display must route through \
1395 CaixaDialeto::as_str (single source of truth: the \
1396 lifted per-arm `PascalCase` variant-name byte-string)"
1397 );
1398 }
1399 }
1400
1401 #[test]
1402 fn caixa_dialeto_as_ref_str_routes_through_as_str_accessor() {
1403 // Fail-before-pass-after byte-parity pin on the lifted
1404 // `impl AsRef<str> for CaixaDialeto` — asserts the standard-
1405 // library trait impl and the substrate-primitive
1406 // [`CaixaDialeto::as_str`] `pub const fn` accessor resolve to
1407 // the same `&str` per instance across the four-arm closed set,
1408 // so any future silent detour that routes the impl through a
1409 // divergent projection (a per-arm inline
1410 // `match self { CaixaDialeto::Pacote => "Pacote", … }` re-inlining
1411 // that opens a compile-time link to the un-lifted arm-literal,
1412 // a swap onto the second-axis
1413 // [`CaixaDialeto::palavra_canonica`] /
1414 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
1415 // accessors that carry distinct byte-shapes per axis) trips at
1416 // caixa-core test time under `PartialEq` rather than at a
1417 // downstream `impl AsRef<str>`-bound consumer's silent split.
1418 // Sweeps every one of the four arms [`CaixaDialeto::ALL`]
1419 // carries so no arm's projection is covered only by the sibling
1420 // `Display` path. Peer of the sibling
1421 // `rate_limit_unit_as_ref_str_routes_through_as_suffix_accessor`
1422 // (d8136db) on the M3 `:politicas :rate-limit` closed-set typed
1423 // enum, and the peer
1424 // [`crate::kind::tests::caixa_kind_as_ref_str_routes_through_as_str_accessor`]
1425 // (cd2091f) pin on the top-level closed-set typed
1426 // discriminator — the pins together close the substrate
1427 // primitive's `AsRef<str>` projection axis onto the seventh
1428 // closed-set fieldless typed enum on the caixa surface.
1429 for &variant in CaixaDialeto::ALL {
1430 assert_eq!(
1431 <CaixaDialeto as AsRef<str>>::as_ref(&variant),
1432 variant.as_str(),
1433 "AsRef<str> impl on CaixaDialeto::{variant:?} must \
1434 byte-equal CaixaDialeto::as_str on the same instance \
1435 — divergence signals a silent detour off the \
1436 substrate-primitive accessor"
1437 );
1438 }
1439 }
1440
1441 #[test]
1442 fn caixa_dialeto_as_ref_str_routes_through_display_via_shared_accessor() {
1443 // Fail-before-pass-after byte-parity pin on the three-path
1444 // convergence discipline the [`CaixaDialeto`] closed-set
1445 // dialect-classification enum now carries on the `&str`-
1446 // projection axis: `<CaixaDialeto as AsRef<str>>::as_ref(&v)`
1447 // (the newly lifted impl), `format!("{v}")` (the pre-existing
1448 // [`fmt::Display`] impl), and `v.as_str()` (the substrate-
1449 // primitive `pub const fn` accessor both trait impls delegate
1450 // through) must resolve to the same byte-string on every
1451 // instance across the four-arm closed set. Refuses any future
1452 // divergence between the two trait impls (a stray
1453 // [`fmt::Display::fmt`] rewrite that hand-rolls the arms
1454 // rather than delegating through the shared accessor; a
1455 // hypothetical `AsRef<str>` rewrite that inlines a per-arm
1456 // literal cascade) that would silently split the two
1457 // projection paths of the same closed-set typed enum. Mirrors
1458 // the sibling three-path-convergence discipline the peer
1459 // [`crate::aplicacao::RateLimitUnit`] typed enum carries
1460 // (`rate_limit_unit_as_ref_str_routes_through_display_via_shared_accessor`,
1461 // d8136db), the peer [`crate::CaixaKind`] triple
1462 // (`caixa_kind_as_ref_str_routes_through_display_via_shared_accessor`,
1463 // cd2091f), and the [`crate::CaixaVersion`] typed newtype
1464 // triple (`caixa_version_as_ref_str_routes_through_display_via_shared_accessor`,
1465 // 16d5c7e).
1466 for &variant in CaixaDialeto::ALL {
1467 let via_as_ref: &str = <CaixaDialeto as AsRef<str>>::as_ref(&variant);
1468 let via_display: String = format!("{variant}");
1469 let via_accessor: &str = variant.as_str();
1470 assert_eq!(via_as_ref, via_accessor);
1471 assert_eq!(via_display, via_accessor);
1472 assert_eq!(via_as_ref, via_display.as_str());
1473 }
1474 }
1475
1476 #[test]
1477 fn caixa_dialeto_is_molde_family_returns_true_on_molde_and_positional_arms() {
1478 // Fail-before-pass-after per-arm shape pin on the two `defmolde`
1479 // declaration-family arms: [`CaixaDialeto::is_molde_family`] must
1480 // return `true` for [`CaixaDialeto::Molde`] and
1481 // [`CaixaDialeto::MoldePosicional`] — the two-arity closure of
1482 // one declaration ([`CaixaDialeto::MoldePosicional`]'s docstring:
1483 // "same declaration as [`Self::Molde`], written with the package
1484 // name as a bare positional symbol … one arity of one
1485 // declaration, not a third schema"). A future accidental flip that
1486 // reversed a per-arm arm's return without touching the paired
1487 // false-arm pin would silently open the substrate primitive to
1488 // false-positive on either arm — the `feira dialeto` verb's
1489 // `--strict-palavra` gate would then silently accept
1490 // repo-surface declarations under `(defcaixa …)` on one arm and
1491 // reject them on the other. Pinning the two true arms explicitly
1492 // here refuses that split at caixa-core build time.
1493 assert!(
1494 CaixaDialeto::Molde.is_molde_family(),
1495 "CaixaDialeto::Molde.is_molde_family() must return true — \
1496 Molde is the primary `defmolde` arm"
1497 );
1498 assert!(
1499 CaixaDialeto::MoldePosicional.is_molde_family(),
1500 "CaixaDialeto::MoldePosicional.is_molde_family() must return \
1501 true — MoldePosicional is the positional-arity form of the \
1502 same `defmolde` declaration Molde carries"
1503 );
1504 }
1505
1506 #[test]
1507 fn caixa_dialeto_is_molde_family_returns_false_on_pacote_and_desconhecido_arms() {
1508 // Fail-before-pass-after per-arm shape pin on the two non-`defmolde`
1509 // arms: [`CaixaDialeto::is_molde_family`] must return `false` for
1510 // [`CaixaDialeto::Pacote`] (the sibling `defcaixa` tatara-lisp
1511 // package manifest, `palavra_canonica → "defcaixa"`) and for
1512 // [`CaixaDialeto::Desconhecido`] (the residue that names no
1513 // known declaration, `palavra_canonica → "?"`). Pinning the two
1514 // false arms explicitly here refuses a future accidental flip
1515 // that let the predicate widen to include either arm — the
1516 // `feira dialeto` verb's `--strict-palavra` gate would then
1517 // spuriously refuse every `(defcaixa …)` package manifest as if
1518 // it were a repo-surface declaration.
1519 assert!(
1520 !CaixaDialeto::Pacote.is_molde_family(),
1521 "CaixaDialeto::Pacote.is_molde_family() must return false — \
1522 Pacote is the `defcaixa` tatara-lisp package manifest, not \
1523 the `defmolde` repo-surface declaration"
1524 );
1525 assert!(
1526 !CaixaDialeto::Desconhecido.is_molde_family(),
1527 "CaixaDialeto::Desconhecido.is_molde_family() must return \
1528 false — the residue arm names no known declaration; it is \
1529 not silently promoted into the `defmolde` family"
1530 );
1531 }
1532
1533 #[test]
1534 fn caixa_dialeto_is_molde_family_agrees_with_palavra_canonica_defmolde_projection() {
1535 // Load-bearing pin: for every arm in [`CaixaDialeto::ALL`], the
1536 // typed [`CaixaDialeto::is_molde_family`] predicate must agree
1537 // byte-for-byte with the paired [`CaixaDialeto::palavra_canonica`]
1538 // projection's `== "defmolde"` classifier — i.e. the two paths
1539 // partition the four-arm discriminator set into the same
1540 // `{Molde, MoldePosicional}` and `{Pacote, Desconhecido}` halves.
1541 // Pre-lift the sibling [`CaixaDialeto::palavra_canonica`] projection
1542 // (which returns `"defmolde"` for `Molde | MoldePosicional`,
1543 // `"defcaixa"` for `Pacote`, `"?"` for `Desconhecido`) was the
1544 // only substrate-side surface carrying the two-arm collapse; the
1545 // hand-rolled `matches!(d, CaixaDialeto::Molde |
1546 // CaixaDialeto::MoldePosicional)` sites in the `feira dialeto`
1547 // verb expressed no compile-time link back to it. A future arm
1548 // addition — the module doc's "third dialect" hazard actualises
1549 // as a fifth arm belonging to the `defmolde` family — would land
1550 // one match arm at [`Self::palavra_canonica`]'s `defmolde` return
1551 // (extending the sibling projection) but silently split the
1552 // hand-rolled two-arm `matches!` predicate sites if the new arm's
1553 // `is_molde_family` return were forgotten. Pinning byte-equality
1554 // between the two paths here makes any such split a caixa-core
1555 // build-time failure at this test rather than surfacing far from
1556 // the arm-addition commit as a downstream `--strict-palavra` /
1557 // `caixa.lisp`-holds-wrong-declaration gate silently ignoring the
1558 // new arm.
1559 for &d in CaixaDialeto::ALL {
1560 let via_palavra_canonica = d.palavra_canonica() == "defmolde";
1561 let via_is_molde_family = d.is_molde_family();
1562 assert_eq!(
1563 via_is_molde_family, via_palavra_canonica,
1564 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
1565 must agree with CaixaDialeto::{d:?}.palavra_canonica() == \
1566 \"defmolde\" ({via_palavra_canonica}) — a split between the \
1567 typed predicate and the sibling keyword projection would let \
1568 a future arm addition land at one path and drift at the other, \
1569 which is exactly the drift this pin refuses"
1570 );
1571 }
1572 }
1573
1574 #[test]
1575 fn caixa_dialeto_is_molde_family_is_const_fn() {
1576 // Const-context pin: [`CaixaDialeto::is_molde_family`] must remain
1577 // `const fn` (its match is a fieldless-arm literal-pattern
1578 // discriminator, so no non-const operation exists on the resolution
1579 // path). Downstream consumers reaching for the predicate from a
1580 // `const` context (a future substrate-wide const-fold-driven audit
1581 // table that materializes per-arm gate-membership at build time,
1582 // a per-arm CR-admission-webhook gate registration in a `const`
1583 // context) rely on the const-ness. A future accidental downgrade
1584 // to non-`const` (an added runtime helper reachable only from a
1585 // non-`const` context) trips at caixa-core build time rather than
1586 // surfacing as a downstream `const`-context regression far from
1587 // the predicate declaration. Peer of the sibling
1588 // [`caixa_dialeto_as_str_is_const_fn`] pin on the paired
1589 // [`CaixaDialeto::as_str`] byte-string axis.
1590 const ARMS: [(CaixaDialeto, bool); 4] = [
1591 (CaixaDialeto::Pacote, CaixaDialeto::Pacote.is_molde_family()),
1592 (CaixaDialeto::Molde, CaixaDialeto::Molde.is_molde_family()),
1593 (
1594 CaixaDialeto::MoldePosicional,
1595 CaixaDialeto::MoldePosicional.is_molde_family(),
1596 ),
1597 (
1598 CaixaDialeto::Desconhecido,
1599 CaixaDialeto::Desconhecido.is_molde_family(),
1600 ),
1601 ];
1602 // Materialize the const-fold-evaluated table into a runtime slice
1603 // assertion — carries the same `bool = const fn call` shape a raw
1604 // `assert!(const_bool)` would, without tripping the
1605 // `assertions_on_constants` clippy lint that a per-arm
1606 // `assert!(CONST)` on a `const bool` triggers when the arm-count
1607 // is enumerated flat rather than compared as a whole-table shape.
1608 assert_eq!(
1609 ARMS,
1610 [
1611 (CaixaDialeto::Pacote, false),
1612 (CaixaDialeto::Molde, true),
1613 (CaixaDialeto::MoldePosicional, true),
1614 (CaixaDialeto::Desconhecido, false),
1615 ],
1616 "CaixaDialeto::is_molde_family() must evaluate in const context \
1617 for every arm and land on the {{false, true, true, false}} \
1618 partition — a future accidental downgrade to non-`const` \
1619 would trip the const-context array-initializer here"
1620 );
1621 }
1622
1623 #[test]
1624 fn caixa_dialeto_as_str_is_const_fn() {
1625 // Const-context pin: [`CaixaDialeto::as_str`] must remain
1626 // `const fn` (its match arms return `pub const` byte-strings, so
1627 // no non-const operation exists on the resolution path).
1628 // Downstream consumers reaching for the accessor from a `const`
1629 // context (a future substrate-wide const-fold-driven audit table
1630 // that materializes every dialect's census label at build time,
1631 // a per-arm CR-admission-webhook message registration in a
1632 // `const` gate) rely on the const-ness. A future accidental
1633 // downgrade to non-`const` (an added runtime helper reachable
1634 // only from a non-`const` context, a manual hand-rolled `impl`
1635 // that shadows this method) trips at caixa-core build time
1636 // rather than surfacing as a downstream `const`-context
1637 // regression far from the accessor declaration. Peer of the
1638 // sibling [`crate::kind::tests::caixa_kind_wire_name_is_const_fn`]
1639 // pin on the paired [`crate::CaixaKind`] byte-string axis.
1640 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
1641 const MOLDE: &str = CaixaDialeto::Molde.as_str();
1642 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
1643 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
1644 assert_eq!(PACOTE, "Pacote");
1645 assert_eq!(MOLDE, "Molde");
1646 assert_eq!(MOLDE_POSICIONAL, "MoldePosicional");
1647 assert_eq!(DESCONHECIDO, "Desconhecido");
1648 }
1649
1650 #[test]
1651 fn caixa_dialeto_is_variant_predicates_partition_the_arm_set() {
1652 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
1653 // derive: for each of the four variants at [`CaixaDialeto::ALL`]`[idx]`
1654 // the observed four-slot predicate row must equal a one-hot row
1655 // with the `true` at exactly `idx`. Pre-derive the closed four-arm
1656 // dialect-classification partition lived only inside the paired
1657 // per-arm projections' four-arm match resolvers ([`Self::as_str`] /
1658 // [`Self::palavra_canonica`] / [`Self::consumidor`] /
1659 // [`Self::descricao`]) plus the two-arm [`Self::is_molde_family`]
1660 // hand-rolled `matches!` (now routed through the derived
1661 // predicates); a future rebrand (an accidental
1662 // `#[is_variant(name = "…")]` drift, a manual hand-rolled `impl`
1663 // that shadows the derive-generated method, an arm rename that
1664 // reroutes one arm through the wrong predicate lane) trips this
1665 // pin at caixa-core build time rather than surfacing far from the
1666 // derive declaration as a downstream [`Self::is_molde_family`]
1667 // consumer accepting the wrong arm-set. The expected row is
1668 // generated live from the [`Self::ALL`] declaration order rather
1669 // than transcribed by hand so a copy-paste flip reroutes at the
1670 // identity-diagonal assertion.
1671 //
1672 // Peer of the sibling
1673 // [`crate::kind::tests::caixa_kind_is_variant_predicates_partition_the_arm_set`]
1674 // / [`crate::supervisor::tests::restart_strategy_is_variant_predicates_partition_the_arm_set`]
1675 // / [`crate::aplicacao::tests::placement_strategy_is_variant_predicates_partition_the_arm_set`]
1676 // / [`crate::upgrade::tests::upgrade_instruction_is_variant_predicates_partition_the_arm_set`]
1677 // pins on the sibling closed-set typed-enum discriminator axes.
1678 for (idx, &variant) in CaixaDialeto::ALL.iter().enumerate() {
1679 let observed = [
1680 variant.is_pacote(),
1681 variant.is_molde(),
1682 variant.is_molde_posicional(),
1683 variant.is_desconhecido(),
1684 ];
1685 let mut expected = [false; 4];
1686 expected[idx] = true;
1687 assert_eq!(
1688 observed, expected,
1689 "CaixaDialeto::{variant:?} at ALL[{idx}] is_* predicates \
1690 must fire only on their own arm lane (identity diagonal); \
1691 got {observed:?}",
1692 );
1693 }
1694 }
1695
1696 #[test]
1697 fn caixa_dialeto_is_variant_predicates_are_const_fn() {
1698 // The [`gen_platform::IsVariant`] derive emits `const fn`
1699 // predicates on the peer [`crate::CaixaKind`] +
1700 // [`crate::upgrade::UpgradeInstruction`] +
1701 // [`crate::supervisor::RestartStrategy`] +
1702 // [`crate::supervisor::RestartPolicy`] +
1703 // [`crate::aplicacao::PlacementStrategy`] +
1704 // [`crate::aplicacao::RateLimitUnit`] +
1705 // [`crate::dep::DepList`] closed-set typed enums — pin the same
1706 // posture on [`CaixaDialeto`] so a future accidental downgrade
1707 // to non-`const` (an added runtime helper reachable only from a
1708 // non-`const` context, a manual hand-rolled `impl` that shadows
1709 // the derive-generated method) trips at caixa-core build time
1710 // rather than surfacing as a downstream `const`-context
1711 // regression far from the derive declaration.
1712 // Use `const { assert!(…) }` (peer of the sibling
1713 // [`crate::render::PathShapeViolation`] +
1714 // [`crate::aplicacao::RateLimitUnit`] +
1715 // [`caixa_theme::style::Semantic`] const-fn pins) so the
1716 // const-context evaluation trips at const-fold time without
1717 // opening a per-`const bool` `assertions_on_constants` clippy
1718 // debt row this crate does not carry today for `dialeto.rs`.
1719 const { assert!(CaixaDialeto::Pacote.is_pacote()) };
1720 const { assert!(CaixaDialeto::Molde.is_molde()) };
1721 const { assert!(CaixaDialeto::MoldePosicional.is_molde_posicional()) };
1722 const { assert!(CaixaDialeto::Desconhecido.is_desconhecido()) };
1723 }
1724
1725 #[test]
1726 fn caixa_dialeto_from_wire_accepts_every_as_str_output() {
1727 // Fail-before-pass-after per-arm accept pin on the newly lifted
1728 // [`CaixaDialeto::from_wire`] reverse projection: every arm in
1729 // [`CaixaDialeto::ALL`] must parse back through `from_wire` when
1730 // fed its own [`CaixaDialeto::as_str`] output, landing on
1731 // `Some(same_variant)` — a regression that hand-rolled either
1732 // side's per-arm match without threading through the shared
1733 // four-string closed set would silently disagree on any future
1734 // arm rename and this pin flags it at caixa-core build time.
1735 // Peer of the sibling
1736 // [`crate::kind::tests::caixa_kind_wire_round_trips_through_from_wire`]
1737 // (2aa6d23) /
1738 // `placement_strategy_from_wire_accepts_every_lifted_constant`
1739 // (18c7342) /
1740 // `dep_list_round_trips_through_as_str_and_from_wire` (45ee563)
1741 // shape on the sibling closed-set typed-enum reverse-projection
1742 // axes.
1743 for &variant in CaixaDialeto::ALL {
1744 let wire = variant.as_str();
1745 let parsed = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
1746 panic!(
1747 "CaixaDialeto::from_wire({wire:?}) must accept every \
1748 CaixaDialeto::as_str output — got None for the \
1749 wire byte-string of {variant:?}"
1750 )
1751 });
1752 assert_eq!(
1753 parsed, variant,
1754 "CaixaDialeto::from_wire(CaixaDialeto::{variant:?}.as_str()) \
1755 must return CaixaDialeto::{variant:?} — the (as_str, \
1756 from_wire) pair must form a total round-trip on the \
1757 closed four-arm CaixaDialeto arm-set"
1758 );
1759 }
1760 }
1761
1762 #[test]
1763 fn caixa_dialeto_from_wire_rejects_unknown_byte_strings() {
1764 // Rejection pin on the parser's accept-set: any string outside
1765 // the four-arm [`CaixaDialeto::as_str`] output set must return
1766 // `None`. A future accidental widening of the accept-set (a
1767 // case-insensitive match that accepts `"pacote"` on the wire
1768 // axis, a hand-rolled Levenshtein-forgiving arm-lookup that
1769 // admits `"Pacotee"` typos, a silent acceptance of the sibling
1770 // [`Self::palavra_canonica`] `"defcaixa"` / `"defmolde"`
1771 // byte-shapes on this axis) would silently drift the parser's
1772 // accept-set from the emitter's — a downstream audit-report
1773 // re-loader that bound a prior audit's [`Self::as_str`] output
1774 // back to the typed enum through this parser would then bind a
1775 // malformed byte-string to a plausibly-wrong typed arm the
1776 // caller does not route through any fallback, silently
1777 // misclassifying the reloaded row. Also rejects the sibling
1778 // [`Self::palavra_canonica`] (`"defcaixa"` / `"defmolde"`) and
1779 // the sibling [`Self::consumidor`] (`"caixa-core / feira"`,
1780 // `"pleme-doc-gen"`, `"nobody known"`) byte-shapes, which are
1781 // the substrate's *distinct-axis* projections on the same enum
1782 // — the two-axis split the sibling
1783 // [`Self::palavra_canonica`] / [`Self::consumidor`] /
1784 // [`Self::descricao`] docstrings explicitly frame forbids
1785 // accepting one axis's byte-shapes as parseable on the other
1786 // axis. Peer of the sibling
1787 // [`crate::kind::tests::caixa_kind_from_wire_rejects_unknown_byte_strings`]
1788 // (2aa6d23) /
1789 // `placement_strategy_from_wire_rejects_unknown_byte_strings`
1790 // (18c7342) /
1791 // `dep_list_from_wire_returns_none_on_unknown_wire_scalar`
1792 // (45ee563) rejection pins on the sibling closed-set typed-enum
1793 // reverse-projection axes.
1794 for bad in [
1795 "",
1796 " ",
1797 "pacote",
1798 "PACOTE",
1799 "molde",
1800 "MoldePositional",
1801 "desconhecido",
1802 "Unknown",
1803 "defcaixa",
1804 "defmolde",
1805 "?",
1806 "caixa-core / feira",
1807 "pleme-doc-gen",
1808 "nobody known",
1809 "Pacote ",
1810 " Pacote",
1811 ] {
1812 assert!(
1813 CaixaDialeto::from_wire(bad).is_none(),
1814 "CaixaDialeto::from_wire({bad:?}) must return None — the \
1815 parser's accept-set is exactly the four CaixaDialeto::as_str \
1816 outputs; a widening would silently split the parser's \
1817 accept-set from the emitter's arm-set"
1818 );
1819 }
1820 }
1821
1822 #[test]
1823 fn cabeca_errada_ctor_matches_struct_literal_wrap() {
1824 // Fail-before-pass-after byte-identity pin: the lifted
1825 // [`DialetoError::cabeca_errada`] ctor MUST land on the exact
1826 // same struct-literal shape the pre-lift open-coded wire-up
1827 // block wrote by hand — `DialetoError::CabecaErrada {
1828 // encontrado: <head>.to_string() }`. A future accidental
1829 // divergence (`.into()` swap, per-arm constant substitution, an
1830 // added default field, an `.to_ascii_lowercase()` normalization
1831 // silently injected into the ctor body, a rebrand of the
1832 // `encontrado` field carrying a distinct byte-shape) trips this
1833 // pin at caixa-core build time rather than surfacing far from
1834 // the ctor declaration as a downstream `classify_form`
1835 // wrong-head consumer emitting one diagnostic shape while a
1836 // hand-written test peer opens another. Peer of the sibling
1837 // `unknown_byte_unit_ctor_matches_struct_literal_wrap`
1838 // (limits.rs; 29fac09) / `duplicate_from_ctor_matches_struct_
1839 // literal_wrap` (upgrade.rs; 7e52aec) shape on the sibling
1840 // single-slot `{ <field>: String }` envelope constructors.
1841 assert_eq!(
1842 DialetoError::cabeca_errada("defflake"),
1843 DialetoError::CabecaErrada {
1844 encontrado: "defflake".to_string(),
1845 },
1846 "DialetoError::cabeca_errada must byte-equal the pre-lift \
1847 open-coded struct-literal — a drift here means the ctor \
1848 stopped being a substrate primitive for the wrong-head \
1849 fallthrough site"
1850 );
1851 }
1852
1853 #[test]
1854 fn cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs() {
1855 // Fail-before-pass-after boundary-sweep pin: the lifted
1856 // [`DialetoError::cabeca_errada`] ctor MUST route its
1857 // `encontrado: &str` argument verbatim into the
1858 // [`DialetoError::CabecaErrada`] `encontrado: String` field
1859 // for every boundary-covering `&str` input — empty string, a
1860 // canonical `defcaixa`-adjacent head, a non-ASCII head, a
1861 // whitespace-carrying head, a Unicode-full-width head. Any
1862 // wrapper-side truncation, silent `.trim()`, accidental
1863 // `.to_ascii_lowercase()` normalization, or `.into()` divergence
1864 // on the ctor body surfaces here as a byte-mismatch against the
1865 // input rather than at a downstream
1866 // [`DialetoError::to_string()`] diagnostic-shape drift at a
1867 // wrong-head fallthrough consumer far from the ctor declaration.
1868 // Peer of the sibling `limits_codec_unit_only_ctors_route_unit_
1869 // verbatim_across_every_variant` (limits.rs; 29fac09) shape on
1870 // the sibling single-slot `{ <field>: String }` envelope
1871 // boundary-sweep discipline.
1872 for encontrado in [
1873 "",
1874 "defflake",
1875 "def-molde",
1876 "defcaixa ",
1877 " defcaixa",
1878 "μdefcaixa",
1879 "\u{00A0}defcaixa",
1880 "\u{3000}defcaixa",
1881 "def\u{2028}caixa",
1882 ] {
1883 let via_ctor = DialetoError::cabeca_errada(encontrado);
1884 let via_literal = DialetoError::CabecaErrada {
1885 encontrado: encontrado.to_string(),
1886 };
1887 assert_eq!(
1888 via_ctor, via_literal,
1889 "DialetoError::cabeca_errada({encontrado:?}) must byte- \
1890 equal the open-coded struct-literal on the same input — \
1891 a drift here would let the ctor silently normalize / \
1892 truncate the head symbol before it reached the \
1893 CabecaErrada envelope"
1894 );
1895 let DialetoError::CabecaErrada { encontrado: routed } = via_ctor else {
1896 panic!(
1897 "DialetoError::cabeca_errada must construct the \
1898 CabecaErrada arm — got a different variant on \
1899 input {encontrado:?}"
1900 );
1901 };
1902 assert_eq!(
1903 routed, encontrado,
1904 "DialetoError::cabeca_errada must route the input \
1905 {encontrado:?} verbatim into the encontrado field — \
1906 any wrapper-side truncation / normalization surfaces \
1907 here rather than at a downstream diagnostic shape drift"
1908 );
1909 }
1910 }
1911
1912 #[test]
1913 fn classify_form_wrong_head_routes_through_cabeca_errada_ctor() {
1914 // Fail-before-pass-after routing pin: [`classify`]'s wrong-head
1915 // fallthrough site MUST construct its `Err(DialetoError::…)`
1916 // through the substrate-primitive [`DialetoError::cabeca_errada`]
1917 // ctor rather than through an open-coded struct-literal. Pre-
1918 // lift the wire-up hand-rolled a three-line
1919 // `Self::CabecaErrada { encontrado: other.to_string() }` block
1920 // with no compile-time link back to the substrate primitive; a
1921 // future accidental rebrand of the ctor body (an added
1922 // `.trim()` on `encontrado`, a per-arm constant prefix like
1923 // `"unknown-head:"`, a widening of the field into a
1924 // `(String, usize)` tuple carrying a caret offset) would then
1925 // silently split the two paths — the ctor consumers pick up
1926 // the new shape, the open-coded wire-up does not. Pinning
1927 // byte-equality between the observed `Err` and the ctor-
1928 // constructed `Err` refuses that split at caixa-core build
1929 // time rather than surfacing far from the wire-up commit as a
1930 // downstream diagnostic-consumer split.
1931 for head in ["defflake", "deffoobar", "defcaixaz", "let", "defmoldez"] {
1932 let src = format!("({head} :nome \"x\")");
1933 let observed = classify(&src);
1934 let via_ctor = Err(DialetoError::cabeca_errada(head));
1935 assert_eq!(
1936 observed, via_ctor,
1937 "classify({src:?}) must return the same Err shape as \
1938 DialetoError::cabeca_errada({head:?}) — a drift here \
1939 means the wire-up de-lifted its wrong-head fallthrough \
1940 arm off the substrate primitive"
1941 );
1942 }
1943 }
1944
1945 #[test]
1946 fn leitura_ctor_matches_tuple_literal_wrap_on_str_binding() {
1947 // Fail-before-pass-after byte-identity pin: the lifted
1948 // [`DialetoError::leitura`] ctor MUST land on the exact same
1949 // tuple-newtype wrap the pre-lift open-coded wire-up block wrote by
1950 // hand — `DialetoError::Leitura(<into-String-expr>)`. A future
1951 // accidental divergence (an added `.trim()` on the reader reason,
1952 // a per-arm constant prefix like `"tatara-lisp:"`, a widening of
1953 // the tuple carrying a caret offset, a rebrand of the payload
1954 // carrying a distinct byte-shape) trips this pin at caixa-core
1955 // build time rather than surfacing far from the ctor declaration
1956 // as a downstream [`classify`] tatara-lisp-reader consumer
1957 // emitting one diagnostic shape while a hand-written test peer
1958 // opens another. Peer of the sibling
1959 // `cabeca_errada_ctor_matches_struct_literal_wrap` pin above on
1960 // the same [`DialetoError`] envelope's wrong-head axis, and of
1961 // the peer `LimitsError::empty_byte_size` /
1962 // `LimitsError::empty_duration` (7a4b003 / 319216c) shape on the
1963 // sibling `(String)` single-slot tuple-newtype envelope
1964 // constructors.
1965 let reason: &str = "unclosed paren at 1:12";
1966 assert_eq!(
1967 DialetoError::leitura(reason),
1968 DialetoError::Leitura(reason.to_string()),
1969 "DialetoError::leitura must byte-equal the pre-lift open-coded \
1970 tuple-newtype wrap — a drift here means the ctor stopped \
1971 being a substrate primitive for the tatara-lisp-reader \
1972 fallthrough site"
1973 );
1974 }
1975
1976 #[test]
1977 fn leitura_ctor_matches_tuple_literal_wrap_on_string_binding() {
1978 // Fail-before-pass-after byte-identity pin on the `String` wire-up
1979 // shape: the lifted [`DialetoError::leitura`] ctor MUST land on
1980 // the same tuple-newtype wrap when the caller passes an owned
1981 // `String` (the actual [`classify`] wire-up shape — `e.to_string()`
1982 // on a [`tatara_lisp::Error`]-carrying binding). Pins that the
1983 // `impl Into<String>` param covers the owned-`String` path with no
1984 // silent double-allocation or intermediate `&str` reslicing. Peer
1985 // of the sibling `_on_str_binding` pin above — together they close
1986 // the `impl Into<String>` bound's two authored wire-up shapes on
1987 // the ctor's substrate primitive.
1988 let reason: String = String::from("read: unexpected EOF at 3:1");
1989 let via_ctor = DialetoError::leitura(reason.clone());
1990 let via_literal = DialetoError::Leitura(reason.clone());
1991 assert_eq!(
1992 via_ctor, via_literal,
1993 "DialetoError::leitura must byte-equal the pre-lift open-coded \
1994 tuple-newtype wrap on the same owned-String fixture — a drift \
1995 here would let the ctor silently reshape the reader reason \
1996 before it reached the Leitura envelope"
1997 );
1998 let DialetoError::Leitura(routed) = via_ctor else {
1999 panic!(
2000 "DialetoError::leitura must construct the Leitura arm — \
2001 got a different variant on input {reason:?}"
2002 );
2003 };
2004 assert_eq!(
2005 routed, reason,
2006 "DialetoError::leitura must route the input {reason:?} \
2007 verbatim into the tuple-newtype payload — any wrapper-side \
2008 truncation / normalization surfaces here rather than at a \
2009 downstream diagnostic shape drift"
2010 );
2011 }
2012
2013 #[test]
2014 fn leitura_routes_reason_verbatim_across_boundary_inputs() {
2015 // Fail-before-pass-after boundary-sweep pin: the lifted
2016 // [`DialetoError::leitura`] ctor MUST route its
2017 // `reason: impl Into<String>` argument verbatim into the
2018 // [`DialetoError::Leitura`] tuple-newtype `String` payload for
2019 // every boundary-covering input — empty string, a canonical
2020 // tatara-lisp reader error, a non-ASCII reason, a
2021 // whitespace-carrying reason, a Unicode-full-width reason. Any
2022 // wrapper-side truncation, silent `.trim()`, accidental
2023 // `.to_ascii_lowercase()` normalization, or `.into()` divergence
2024 // on the ctor body surfaces here as a byte-mismatch against the
2025 // input rather than at a downstream [`DialetoError::to_string()`]
2026 // diagnostic-shape drift at a tatara-lisp-reader fallthrough
2027 // consumer far from the ctor declaration. Peer of the sibling
2028 // `cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs`
2029 // pin above on the same [`DialetoError`] envelope's wrong-head
2030 // axis.
2031 for reason in [
2032 "",
2033 "unclosed paren at 1:12",
2034 "unexpected token ')'",
2035 "read: eof",
2036 " leading whitespace",
2037 "trailing whitespace ",
2038 "μnicode reason",
2039 "\u{00A0}NBSP-prefixed reason",
2040 "\u{3000}ideographic-space reason",
2041 "reason\u{2028}with-line-separator",
2042 ] {
2043 let via_ctor = DialetoError::leitura(reason);
2044 let via_literal = DialetoError::Leitura(reason.to_string());
2045 assert_eq!(
2046 via_ctor, via_literal,
2047 "DialetoError::leitura({reason:?}) must byte-equal the \
2048 open-coded tuple-newtype wrap on the same input — a \
2049 drift here would let the ctor silently normalize / \
2050 truncate the reader reason before it reached the \
2051 Leitura envelope"
2052 );
2053 let DialetoError::Leitura(routed) = via_ctor else {
2054 panic!(
2055 "DialetoError::leitura must construct the Leitura \
2056 arm — got a different variant on input {reason:?}"
2057 );
2058 };
2059 assert_eq!(
2060 routed, reason,
2061 "DialetoError::leitura must route the input {reason:?} \
2062 verbatim into the tuple-newtype payload — any \
2063 wrapper-side truncation / normalization surfaces here \
2064 rather than at a downstream diagnostic shape drift"
2065 );
2066 }
2067 }
2068
2069 #[test]
2070 fn classify_reader_error_routes_through_leitura_ctor() {
2071 // Fail-before-pass-after routing pin: [`classify`]'s
2072 // tatara-lisp-reader map-err site MUST construct its
2073 // `Err(DialetoError::…)` through the substrate-primitive
2074 // [`DialetoError::leitura`] ctor rather than through an
2075 // open-coded tuple-newtype wrap. Pre-lift the wire-up hand-rolled
2076 // a `Self::Leitura(e.to_string())` block with no compile-time
2077 // link back to the substrate primitive; a future accidental
2078 // rebrand of the ctor body (an added `.trim()` on the reader
2079 // reason, a per-arm constant prefix like `"tatara-lisp:"`, a
2080 // widening of the payload into a `(String, usize)` tuple
2081 // carrying a caret offset) would then silently split the two
2082 // paths — the ctor consumers pick up the new shape, the
2083 // open-coded wire-up does not. Pinning byte-equality between
2084 // the observed `Err` and the ctor-constructed `Err` refuses
2085 // that split at caixa-core build time rather than surfacing far
2086 // from the wire-up commit as a downstream diagnostic-consumer
2087 // split. Peer of the sibling
2088 // `classify_form_wrong_head_routes_through_cabeca_errada_ctor`
2089 // pin above on the same [`DialetoError`] envelope's wrong-head
2090 // fallthrough axis.
2091 //
2092 // The malformed sources below each name a distinct
2093 // tatara-lisp-reader failure shape (unclosed paren, stray close
2094 // paren, unterminated string), so together they sweep the
2095 // reader's rejection surface rather than pinning against one
2096 // specific error message the reader upstream is free to reword.
2097 for src in [
2098 "(defcaixa :nome \"x\"",
2099 "defcaixa :nome \"x\")",
2100 "(defcaixa :nome \"unterminated",
2101 ] {
2102 let observed = classify(src);
2103 let Err(DialetoError::Leitura(reason)) = observed.clone() else {
2104 panic!(
2105 "classify({src:?}) must return the Leitura arm — got \
2106 {observed:?}"
2107 );
2108 };
2109 let via_ctor: Result<CaixaDialeto, DialetoError> =
2110 Err(DialetoError::leitura(reason.clone()));
2111 assert_eq!(
2112 observed, via_ctor,
2113 "classify({src:?}) must return the same Err shape as \
2114 DialetoError::leitura({reason:?}) — a drift here means \
2115 the wire-up de-lifted its tatara-lisp-reader fallthrough \
2116 arm off the substrate primitive"
2117 );
2118 }
2119 }
2120
2121 #[test]
2122 fn caixa_dialeto_try_from_str_routes_through_from_wire_accessor() {
2123 // Fail-before-pass-after byte-parity pin on the lifted
2124 // `impl TryFrom<&str> for CaixaDialeto`: for every arm in
2125 // [`CaixaDialeto::ALL`], the `.try_into()` / `TryFrom::try_from`
2126 // path must resolve to the same variant the sibling
2127 // [`CaixaDialeto::from_wire`] resolver returns on the same
2128 // [`CaixaDialeto::as_str`] wire byte-string input. Pins the
2129 // three-path convergence discipline the [`CaixaDialeto`] closed-
2130 // set typed enum now carries on the `str → Self` reverse-
2131 // projection axis: `<CaixaDialeto as TryFrom<&str>>::try_from(s)`
2132 // (the newly lifted trait-idiomatic reverse projection),
2133 // `CaixaDialeto::from_wire(s)` (the substrate-primitive method-
2134 // named `Option<Self>` accessor the trait impl delegates through),
2135 // and the round-trip identity `variant.as_str() → variant`
2136 // (the four-arm closed accept-set shared between the emitter and
2137 // both reverse-projection consumers) must resolve to the same
2138 // typed [`CaixaDialeto`] discriminator on every arm.
2139 //
2140 // A future silent detour that routes the impl through a
2141 // divergent projection (a per-arm inline
2142 // `match s { "Pacote" => …, … }` re-inlining that opens a
2143 // compile-time link to the un-lifted arm-literal, a swap onto
2144 // the second-axis [`CaixaDialeto::palavra_canonica`] /
2145 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
2146 // accessors that carry distinct byte-shapes per axis, an accept-
2147 // set widening that silently accepts one axis's byte-shapes as
2148 // parseable on the other axis) trips at caixa-core test time
2149 // under `assert_eq!` rather than at a downstream
2150 // `TryFrom<&str>`-bound consumer's silent split. Peer of the
2151 // sibling
2152 // [`crate::kind::tests::caixa_kind_try_from_str_routes_through_from_wire_accessor`]
2153 // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
2154 // discriminator's reverse-projection axis — extends the trait-
2155 // idiomatic reverse-projection axis onto the seventh closed-set
2156 // fieldless typed enum on the caixa surface (the second one to
2157 // carry the paired `TryFrom<&str>` impl).
2158 for &variant in CaixaDialeto::ALL {
2159 let wire = variant.as_str();
2160 let via_try_from: CaixaDialeto = <CaixaDialeto as TryFrom<&str>>::try_from(wire)
2161 .unwrap_or_else(|()| {
2162 panic!(
2163 "CaixaDialeto::try_from({wire:?}) must accept every \
2164 CaixaDialeto::as_str output — got Err(()) for the \
2165 wire byte-string of {variant:?}"
2166 )
2167 });
2168 let via_from_wire: CaixaDialeto = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
2169 panic!(
2170 "CaixaDialeto::from_wire({wire:?}) must accept every \
2171 CaixaDialeto::as_str output — got None for the wire \
2172 byte-string of {variant:?}"
2173 )
2174 });
2175 assert_eq!(
2176 via_try_from, variant,
2177 "CaixaDialeto::try_from(CaixaDialeto::{variant:?}.as_str()) \
2178 must return CaixaDialeto::{variant:?} — the trait-idiomatic \
2179 reverse projection must land on the same arm the method-named \
2180 from_wire resolver does",
2181 );
2182 assert_eq!(
2183 via_try_from, via_from_wire,
2184 "CaixaDialeto::try_from({wire:?}) ({via_try_from:?}) must \
2185 byte-equal CaixaDialeto::from_wire({wire:?}) ({via_from_wire:?}) \
2186 on the same input — divergence signals a silent detour off the \
2187 shared substrate-primitive resolver",
2188 );
2189 assert_eq!(
2190 <CaixaDialeto as TryFrom<&str>>::try_from(wire).ok(),
2191 CaixaDialeto::from_wire(wire),
2192 "the Result::ok() projection of TryFrom<&str> must byte-equal \
2193 the sibling from_wire Option<Self> output on {wire:?} — the \
2194 two accessors must share the same accept-set and typed \
2195 outcome per arm",
2196 );
2197 }
2198 }
2199
2200 #[test]
2201 fn caixa_dialeto_try_from_str_rejects_unknown_byte_strings() {
2202 // Rejection witness on the trait-idiomatic reverse-projection
2203 // axis: any string outside the four-arm [`CaixaDialeto::as_str`]
2204 // output set must resolve to `Err(())` through the lifted
2205 // [`impl TryFrom<&str> for CaixaDialeto`]. A future accidental
2206 // widening of the accept-set (a case-insensitive match that
2207 // accepts `"pacote"` on the wire axis, a hand-rolled Levenshtein-
2208 // forgiving arm-lookup that admits `"Pacotee"` typos, a silent
2209 // acceptance of the sibling [`CaixaDialeto::palavra_canonica`]
2210 // `"defcaixa"` / `"defmolde"` byte-shapes on this axis, a swap
2211 // onto the [`CaixaDialeto::consumidor`] `"pleme-doc-gen"` /
2212 // `"caixa-core / feira"` / `"nobody known"` byte-shapes) would
2213 // silently drift the trait-idiomatic parser's accept-set from
2214 // the sibling [`CaixaDialeto::from_wire`] resolver's — a
2215 // downstream `TryFrom<&str>`-bound consumer binding a malformed
2216 // byte-string through this impl would then bind a plausibly-
2217 // wrong typed arm the caller does not route through any fallback,
2218 // silently misclassifying the reloaded row.
2219 //
2220 // Sweeps the same rejection set the sibling
2221 // [`caixa_dialeto_from_wire_rejects_unknown_byte_strings`] pin
2222 // walks (the shared `from_wire` resolver both accessors delegate
2223 // through) so the trait-idiomatic axis and the method-named axis
2224 // stay locked to the same accept-set by construction. Peer of the
2225 // sibling
2226 // [`crate::kind::tests::caixa_kind_try_from_str_rejects_unknown_byte_strings`]
2227 // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
2228 // discriminator's trait-idiomatic reverse-projection axis.
2229 for bad in [
2230 "",
2231 " ",
2232 "pacote",
2233 "PACOTE",
2234 "molde",
2235 "MoldePositional",
2236 "desconhecido",
2237 "Unknown",
2238 "defcaixa",
2239 "defmolde",
2240 "?",
2241 "caixa-core / feira",
2242 "pleme-doc-gen",
2243 "nobody known",
2244 "Pacote ",
2245 " Pacote",
2246 ] {
2247 assert_eq!(
2248 <CaixaDialeto as TryFrom<&str>>::try_from(bad),
2249 Err(()),
2250 "CaixaDialeto::try_from({bad:?}) must return Err(()) — the \
2251 trait-idiomatic parser's accept-set is exactly the four \
2252 CaixaDialeto::as_str outputs; a widening would silently \
2253 split the trait-idiomatic reverse-projection axis from the \
2254 sibling from_wire resolver's arm-set"
2255 );
2256 }
2257 }
2258
2259 #[test]
2260 fn caixa_dialeto_from_into_static_str_routes_through_as_str_accessor() {
2261 // Fail-before-pass-after byte-parity pin on the newly lifted
2262 // `impl From<CaixaDialeto> for &'static str` — asserts the
2263 // standard-library trait impl and the substrate-primitive
2264 // [`CaixaDialeto::as_str`] `pub const fn` accessor resolve to
2265 // the same four-arm emit-set across every arm the exhaustive
2266 // [`CaixaDialeto::ALL`] slice enumerates. Any future silent
2267 // detour that routes the trait impl through a divergent
2268 // projection (a per-arm inline `match dialeto { Pacote =>
2269 // "Pacote", … }` re-inlining that opens a compile-time link to
2270 // the un-lifted arm-literal, an accidental swap onto the second-
2271 // axis [`CaixaDialeto::palavra_canonica`] /
2272 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
2273 // accessors that carry distinct byte-shapes per axis) trips at
2274 // caixa-core test time under `assert_eq!` rather than at a
2275 // downstream `impl Into<&'static str>`-bound consumer's silent
2276 // split. Sweeps every one of the four arms [`CaixaDialeto::ALL`]
2277 // carries so no arm's projection is covered only by the sibling
2278 // method-named `as_str` / [`std::fmt::Display`] / [`AsRef<str>`]
2279 // paths. Materializes the `<&'static str as
2280 // From<CaixaDialeto>>::from` output in a `const`-shape binding
2281 // to make the `'static` lifetime promise a build-time invariant
2282 // — a future accidental downgrade of any of the four arms'
2283 // returned literals to a non-`&'static str` (a `String::leak()`-
2284 // produced return, a `Box::leak`-cast, an intermediate lifetime-
2285 // erasing helper) trips at caixa-core build time rather than at
2286 // a downstream `'static`-bound consumer. Peer of the sibling
2287 // [`crate::supervisor::tests::restart_strategy_from_into_static_str_routes_through_as_str_accessor`]
2288 // (523157d) /
2289 // [`crate::supervisor::tests::restart_policy_from_into_static_str_routes_through_as_str_accessor`]
2290 // (9fb37d0) /
2291 // [`crate::kind::tests::caixa_kind_from_into_static_str_routes_through_as_str_accessor`]
2292 // (edb827b) pins on the sibling closed-set typed-enum forward-
2293 // projection axes — extends the trait-idiomatic forward-
2294 // projection axis onto the fourth closed-set fieldless typed
2295 // enum on the caixa surface (the dialect-classification axis,
2296 // second-of-two closed-set typed enums in caixa-core outside
2297 // the OTP-shape M2 slot).
2298 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
2299 const MOLDE: &str = CaixaDialeto::Molde.as_str();
2300 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
2301 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
2302 for &variant in CaixaDialeto::ALL {
2303 let via_trait: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2304 let via_method: &'static str = variant.as_str();
2305 assert_eq!(
2306 via_trait, via_method,
2307 "From<CaixaDialeto> for &'static str impl must round-trip \
2308 CaixaDialeto::{variant:?} to the same `PascalCase` byte-string \
2309 CaixaDialeto::as_str returns — divergence signals a silent \
2310 detour off the substrate-primitive accessor"
2311 );
2312 let via_into: &'static str = variant.into();
2313 assert_eq!(
2314 via_into, via_method,
2315 "Into<&'static str>::into on CaixaDialeto::{variant:?} must \
2316 byte-equal CaixaDialeto::as_str on the same input — the \
2317 blanket-derived Into shape must resolve to the same as_str \
2318 dispatch as the explicit From impl"
2319 );
2320 }
2321 assert_eq!(
2322 [PACOTE, MOLDE, MOLDE_POSICIONAL, DESCONHECIDO],
2323 ["Pacote", "Molde", "MoldePosicional", "Desconhecido"],
2324 "const-context CaixaDialeto::as_str must resolve to the four \
2325 `PascalCase` variant-name byte-strings — a future accidental \
2326 downgrade of any arm to a non-const or non-static byte-string \
2327 breaks the `&'static str`-lifetime promise the paired \
2328 From<CaixaDialeto> for &'static str impl carries by \
2329 construction"
2330 );
2331 }
2332
2333 #[test]
2334 fn caixa_dialeto_from_into_static_str_and_as_str_partition_the_emit_set() {
2335 // Cross-axis partition pin: the paired trait-idiomatic
2336 // `From<CaixaDialeto> for &'static str` forward projection and
2337 // the method-named [`CaixaDialeto::as_str`] forward projection
2338 // must resolve identically on *every* arm, not just the ones
2339 // named in the primary byte-parity pin above. Sweeps every
2340 // [`CaixaDialeto::ALL`] arm and asserts the trait's `From::from`
2341 // output byte-equals the method-named accessor's return-value on
2342 // each, locking the two forward-projection paths together by
2343 // construction so any future detour (a stray `From` special-case
2344 // that lands on a divergent per-arm literal outside the paired
2345 // `as_str` dispatch, a hypothetical rebrand touching one axis
2346 // without the other) trips at caixa-core test time. Peer of the
2347 // sibling forward-projection partition pins
2348 // [`crate::supervisor::tests::restart_strategy_from_into_static_str_and_as_str_partition_the_emit_set`]
2349 // (523157d) /
2350 // [`crate::supervisor::tests::restart_policy_from_into_static_str_and_as_str_partition_the_emit_set`]
2351 // (9fb37d0) /
2352 // [`crate::kind::tests::caixa_kind_from_into_static_str_and_as_str_partition_the_emit_set`]
2353 // (edb827b) — extends the round-trip discipline onto the fourth
2354 // closed-set typed enum on the caixa surface, closing the two-way
2355 // `Self ↔ &'static str` round-trip on the trait-idiomatic pair
2356 // (`From<Self> for &'static str` + `TryFrom<&str> for Self`) as
2357 // well as the pre-existing method-named pair (`as_str` +
2358 // `from_wire`).
2359 for &variant in CaixaDialeto::ALL {
2360 let via_trait: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2361 let via_method: &'static str = variant.as_str();
2362 assert_eq!(
2363 via_trait, via_method,
2364 "From<CaixaDialeto> for &'static str and \
2365 CaixaDialeto::as_str must resolve identically on \
2366 CaixaDialeto::{variant:?} — divergence signals the \
2367 two forward-projection paths have drifted onto different \
2368 emit-sets"
2369 );
2370 }
2371 // Round-trip witness: every arm's forward `From` output re-parses
2372 // through the paired trait-idiomatic reverse `TryFrom<&str>` back
2373 // to the original variant. Closes the two-way `CaixaDialeto ↔
2374 // &'static str` round-trip on the trait-idiomatic axis pair
2375 // directly (no wire-vocab intermediate the peer [`CaixaKind`]
2376 // axis pair requires — the emit-side [`CaixaDialeto::as_str`]
2377 // and the parse-side [`CaixaDialeto::from_wire`] share the same
2378 // `PascalCase` byte-string vocabulary by construction), mirroring
2379 // the pre-existing method-named `as_str` + `from_wire` round-trip
2380 // on the substrate-primitive axis pair.
2381 for &variant in CaixaDialeto::ALL {
2382 let emitted: &'static str = variant.into();
2383 let re_parsed: Result<CaixaDialeto, ()> =
2384 <CaixaDialeto as TryFrom<&str>>::try_from(emitted);
2385 assert_eq!(
2386 re_parsed,
2387 Ok(variant),
2388 "trait-idiomatic axis pair must round-trip \
2389 CaixaDialeto::{variant:?} through `.into::<&'static \
2390 str>()` and back through `TryFrom<&str>` — a break signals \
2391 the forward-emit and reverse-parse axes have drifted onto \
2392 different vocabularies"
2393 );
2394 }
2395 }
2396
2397 #[test]
2398 fn caixa_dialeto_is_molde_family_routes_through_is_variant_derived_predicates() {
2399 // Byte-parity pin on the post-lift [`CaixaDialeto::is_molde_family`]
2400 // convergence: for every arm in [`CaixaDialeto::ALL`], the typed
2401 // predicate must byte-equal the direct
2402 // `self.is_molde() || self.is_molde_posicional()` composition of
2403 // the two derived per-arm predicates. Pre-lift the predicate
2404 // hand-rolled `matches!(self, Self::Molde | Self::MoldePosicional)`
2405 // with no compile-time link back to the closed-set typed dispatch;
2406 // post-lift it routes through the derived predicates so a future
2407 // arm rename or `#[is_variant(name = "…")]` override lands at
2408 // exactly one dispatch on the substrate primitive. Pinning the
2409 // byte-equality here refuses a future accidental split between
2410 // the composed predicate and the paired derived predicates
2411 // (a hand-rolled shadow `impl` that overrides one path but not
2412 // the other, an accidental rebrand of `is_molde_family`'s body
2413 // back to the pre-lift `matches!` form) at caixa-core build time.
2414 for &d in CaixaDialeto::ALL {
2415 let via_derived = d.is_molde() || d.is_molde_posicional();
2416 let via_is_molde_family = d.is_molde_family();
2417 assert_eq!(
2418 via_is_molde_family, via_derived,
2419 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
2420 must byte-equal the composed derived predicates \
2421 is_molde() || is_molde_posicional() ({via_derived}) — a \
2422 split between the composed predicate and its derived \
2423 building blocks would let a future arm rename land at one \
2424 path and drift at the other, which is exactly the drift \
2425 the IsVariant lift refuses"
2426 );
2427 }
2428 }
2429
2430 #[test]
2431 fn caixa_dialeto_from_borrowed_into_static_str_routes_through_as_str_accessor() {
2432 // Fail-before-pass-after byte-parity pin on the newly lifted
2433 // `impl From<&CaixaDialeto> for &'static str` — asserts the
2434 // borrowed-input standard-library trait impl and the substrate-
2435 // primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
2436 // resolve to the same four-arm emit-set across every arm the
2437 // exhaustive [`CaixaDialeto::ALL`] slice enumerates. Rust's
2438 // `From` trait does not auto-derive the borrowed-input sibling
2439 // from a paired owned-input impl (no `impl<T, U> From<&T> for U
2440 // where T: Copy, U: From<T>` blanket in `core`), so the
2441 // borrowed-input axis is a distinct trait-idiomatic surface that
2442 // a `.iter().map(Into::into)` shape over [`CaixaDialeto::ALL`]
2443 // (whose iterator yields `&CaixaDialeto`, not `CaixaDialeto`)
2444 // reaches through this impl and no other — the paired owned-
2445 // input [`From<CaixaDialeto>`] impl requires an explicit
2446 // `.copied()` / dereference before the trait fires.
2447 // Materializes the `<&'static str as From<&CaixaDialeto>>::from`
2448 // output in a `const`-shape binding to make the `'static`
2449 // lifetime promise a build-time invariant — a future accidental
2450 // downgrade of any of the four arms' returned literals to a
2451 // non-`&'static str` trips at caixa-core build time rather than
2452 // at a downstream `'static`-bound consumer. Peer of the sibling
2453 // [`crate::dep::tests::dep_list_from_borrowed_into_static_str_routes_through_as_str_accessor`]
2454 // (64aa742) /
2455 // [`crate::kind::tests::caixa_kind_from_borrowed_into_static_str_routes_through_as_str_accessor`]
2456 // (5ab993a) pins on the sibling closed-set typed-enum borrowed-
2457 // input forward-projection axes — extends the borrowed-input
2458 // axis discipline onto the third peer on the substrate-wide
2459 // campaign, the dialect-classification axis.
2460 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
2461 const MOLDE: &str = CaixaDialeto::Molde.as_str();
2462 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
2463 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
2464 for variant in CaixaDialeto::ALL {
2465 let via_trait: &'static str = <&'static str as From<&CaixaDialeto>>::from(variant);
2466 let via_method: &'static str = variant.as_str();
2467 assert_eq!(
2468 via_trait, via_method,
2469 "From<&CaixaDialeto> for &'static str impl must round-trip \
2470 &CaixaDialeto::{variant:?} to the same `PascalCase` byte-\
2471 string CaixaDialeto::as_str returns — divergence signals a \
2472 silent detour off the substrate-primitive accessor"
2473 );
2474 let via_into: &'static str = variant.into();
2475 assert_eq!(
2476 via_into, via_method,
2477 "Into<&'static str>::into on &CaixaDialeto::{variant:?} must \
2478 byte-equal CaixaDialeto::as_str on the same input — the \
2479 blanket-derived Into shape must resolve to the same as_str \
2480 dispatch as the explicit From impl"
2481 );
2482 }
2483 assert_eq!(
2484 [PACOTE, MOLDE, MOLDE_POSICIONAL, DESCONHECIDO],
2485 ["Pacote", "Molde", "MoldePosicional", "Desconhecido"],
2486 "const-context CaixaDialeto::as_str must resolve to the four \
2487 `PascalCase` variant-name byte-strings — the borrowed-input \
2488 From<&CaixaDialeto> for &'static str impl inherits its \
2489 `'static` lifetime promise from the same accessor the owned-\
2490 input sibling routes through"
2491 );
2492 }
2493
2494 #[test]
2495 fn caixa_dialeto_from_owned_and_borrowed_into_static_str_agree_on_every_arm() {
2496 // Cross-axis partition pin: the paired trait-idiomatic
2497 // owned-input `From<CaixaDialeto> for &'static str` and
2498 // borrowed-input `From<&CaixaDialeto> for &'static str` (this
2499 // lift) forward projections must resolve identically on every
2500 // arm, locking the two input-shape paths together so any future
2501 // detour trips at caixa-core test time. Then a witness that a
2502 // `.iter().map(Into::into)` pipe over [`CaixaDialeto::ALL`]
2503 // (whose iterator yields `&CaixaDialeto`) materializes the four-
2504 // arm accept-set through the borrowed-input axis alone — the
2505 // exact shape a future M4 admission-webhook rejection body
2506 // composer, a future substrate-wide per-arm diagnostic column,
2507 // or a `HashMap::<&'static str, CaixaDialeto>::from_iter(
2508 // CaixaDialeto::ALL.iter().map(|d| (d.into(), *d)))`-style
2509 // per-dialect lookup reaches through — closing the two-way
2510 // owned/borrowed input-shape symmetry on the forward-projection
2511 // trait-idiomatic axis. Peer of the sibling
2512 // [`crate::dep::tests::dep_list_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
2513 // (64aa742) /
2514 // [`crate::kind::tests::caixa_kind_from_owned_and_borrowed_into_static_str_agree_on_every_arm`]
2515 // (5ab993a) partition pins — extends the borrowed-input axis
2516 // discipline onto the third peer on the substrate-wide campaign.
2517 for &variant in CaixaDialeto::ALL {
2518 let owned: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2519 let borrowed: &'static str = <&'static str as From<&CaixaDialeto>>::from(&variant);
2520 assert_eq!(
2521 owned, borrowed,
2522 "From<CaixaDialeto> and From<&CaixaDialeto> for &'static str \
2523 must resolve identically on CaixaDialeto::{variant:?} — \
2524 divergence signals the owned-input and borrowed-input \
2525 forward-projection paths have drifted onto different \
2526 emit-sets"
2527 );
2528 }
2529 let via_iter: Vec<&'static str> = CaixaDialeto::ALL.iter().map(Into::into).collect();
2530 let via_method: Vec<&'static str> = CaixaDialeto::ALL.iter().map(|d| d.as_str()).collect();
2531 assert_eq!(
2532 via_iter, via_method,
2533 "`.iter().map(Into::into)` over CaixaDialeto::ALL must byte-\
2534 equal `.iter().map(|d| d.as_str())` on every arm — the \
2535 borrowed-input `From<&CaixaDialeto> for &'static str` axis \
2536 is what makes the `.iter().map(Into::into)` shape route \
2537 through the substrate-primitive `CaixaDialeto::as_str` \
2538 accessor rather than through a per-call-site `.copied()` / \
2539 dereference detour"
2540 );
2541 // Direct round-trip witness on the borrowed-input axis: every
2542 // arm's borrowed `From` output re-parses through the paired
2543 // trait-idiomatic reverse `TryFrom<&str>` back to the original
2544 // variant. Unlike the peer [`crate::CaixaKind`] axis pair
2545 // (whose forward `From<Self> for &'static str` emits the
2546 // lowercase Portuguese `as_str` diagnostic vocabulary while
2547 // the reverse `TryFrom<&str>` parses the `PascalCase`
2548 // `wire_name` author-surface vocabulary, forcing the round-trip
2549 // through an intermediate wire-vocab hop), [`CaixaDialeto`]'s
2550 // [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
2551 // parse share the same `PascalCase` vocabulary by construction,
2552 // so the borrowed-input forward axis and the reverse axis
2553 // compose directly.
2554 for &variant in CaixaDialeto::ALL {
2555 let borrowed: &'static str = <&'static str as From<&CaixaDialeto>>::from(&variant);
2556 let re_parsed: Result<CaixaDialeto, ()> =
2557 <CaixaDialeto as TryFrom<&str>>::try_from(borrowed);
2558 assert_eq!(
2559 re_parsed,
2560 Ok(variant),
2561 "trait-idiomatic borrowed-input round-trip must project \
2562 &CaixaDialeto::{variant:?} through \
2563 `<&'static str>::from(&variant)` and back through \
2564 `TryFrom<&str>` — a break signals the borrowed-input \
2565 forward-emit axis and the reverse-parse axis have \
2566 drifted onto different vocabularies"
2567 );
2568 }
2569 }
2570
2571 #[test]
2572 fn caixa_dialeto_from_into_owned_string_routes_through_as_str_accessor() {
2573 // Fail-before-pass-after byte-parity pin on the newly lifted
2574 // `impl From<CaixaDialeto> for String` — asserts the owned-`String`
2575 // -returning standard-library trait impl and the substrate-
2576 // primitive [`CaixaDialeto::as_str`] `pub const fn` accessor
2577 // resolve to the same four-arm emit-set across every arm the
2578 // exhaustive [`CaixaDialeto::ALL`] slice enumerates. Rust's
2579 // standard library does not carry a blanket
2580 // `impl<T: AsRef<str>> From<T> for String` (nor an
2581 // `impl<T: fmt::Display> From<T> for String`), so the
2582 // owned-`String` forward-projection axis is a distinct trait-
2583 // idiomatic surface that a `let key: String = dialeto.into();`-
2584 // shaped call site reaches through this impl and no other — the
2585 // paired sibling `From<CaixaDialeto> for &'static str` impl
2586 // forces every owned-`String` call site through an explicit
2587 // `.to_owned()` / `String::from` restatement. Peer of the
2588 // first-mover
2589 // [`crate::supervisor::tests::restart_strategy_from_into_owned_string_routes_through_as_str_accessor`]
2590 // (7baa18a), the second-peer
2591 // [`crate::supervisor::tests::restart_policy_from_into_owned_string_routes_through_as_str_accessor`]
2592 // (7851725), and the third-peer
2593 // [`crate::kind::tests::caixa_kind_from_into_owned_string_routes_through_as_str_accessor`]
2594 // (231a18c) — extends the trait-idiomatic owned-`String`
2595 // forward-projection axis onto the fourth closed-set fieldless
2596 // typed enum on the caixa surface (the dialect-classification
2597 // axis, second peer outside the M2 OTP-shape sibling axis).
2598 for &variant in CaixaDialeto::ALL {
2599 let via_trait: String = <String as From<CaixaDialeto>>::from(variant);
2600 let via_method: &'static str = variant.as_str();
2601 assert_eq!(
2602 via_trait.as_str(),
2603 via_method,
2604 "From<CaixaDialeto> for String impl must round-trip \
2605 CaixaDialeto::{variant:?} to the same `PascalCase` \
2606 arm-string CaixaDialeto::as_str returns — divergence \
2607 signals a silent detour off the substrate-primitive \
2608 accessor"
2609 );
2610 let via_into: String = variant.into();
2611 assert_eq!(
2612 via_into.as_str(),
2613 via_method,
2614 "Into<String>::into on CaixaDialeto::{variant:?} must \
2615 byte-equal CaixaDialeto::as_str on the same input — the \
2616 blanket-derived Into shape must resolve to the same \
2617 as_str dispatch as the explicit From impl"
2618 );
2619 }
2620 }
2621
2622 #[test]
2623 fn caixa_dialeto_from_into_owned_string_and_static_str_agree_on_every_arm() {
2624 // Cross-axis partition pin: the paired trait-idiomatic
2625 // owned-`String` `From<CaixaDialeto> for String` (this lift) and
2626 // owned-`&'static str` `From<CaixaDialeto> for &'static str`
2627 // (c189a6f) forward projections must resolve identically on
2628 // every arm, locking the two return-type-shape paths together
2629 // so any future detour trips at caixa-core test time. Also
2630 // byte-parity witness against the sibling
2631 // [`ToString::to_string`] surface routed through
2632 // [`std::fmt::Display`] — the three owned-heap-string paths
2633 // (`.into::<String>()`, `String::from`, `.to_string()`) must
2634 // resolve identically on every arm so a future consumer that
2635 // picks any of the three lands on the same four-arm
2636 // `PascalCase` accept-set. Then a `.iter().copied()
2637 // .map(String::from)` pipe witness over [`CaixaDialeto::ALL`]
2638 // that materializes the four-arm accept-set through the
2639 // owned-`String` axis alone — the exact shape a future M4
2640 // admission-webhook rejection body composer or a
2641 // `HashMap::<String, CaixaDialeto>::from_iter(
2642 // CaixaDialeto::ALL.iter().copied().map(|d| (d.into(), d)))`-
2643 // style owned-key per-dialect lookup reaches through — closing
2644 // the owned-`String` forward-projection axis's iterator-pipe
2645 // shape. Then a direct round-trip witness through the paired
2646 // trait-idiomatic reverse [`TryFrom<&str>`] axis on the
2647 // owned-`String`'s [`String::as_str`] borrow that closes the
2648 // two-way `Self → String → Self` round-trip on the trait-
2649 // idiomatic owned-`String` forward + reverse axis pair.
2650 //
2651 // Unlike the peer [`crate::CaixaKind`] axis pair (whose forward
2652 // `From` emit lands on the lowercase Portuguese `as_str`
2653 // diagnostic vocabulary while the reverse `TryFrom<&str>` parses
2654 // the `PascalCase` `wire_name` author-surface vocabulary,
2655 // forcing the round-trip through an intermediate
2656 // [`crate::CaixaKind::wire_name`] hop), [`CaixaDialeto`]'s
2657 // [`CaixaDialeto::as_str`] emit and [`CaixaDialeto::from_wire`]
2658 // parse share the same `PascalCase` vocabulary by construction
2659 // (there is no wire/diagnostic axis split on this enum), so
2660 // the owned-`String` forward axis and the reverse axis compose
2661 // directly — matching the peer
2662 // [`crate::supervisor::RestartStrategy`] /
2663 // [`crate::supervisor::RestartPolicy`] owned-`String` axis
2664 // pairs (whose forward emit and reverse parse also share one
2665 // `PascalCase` vocabulary by construction).
2666 for &variant in CaixaDialeto::ALL {
2667 let owned_string: String = <String as From<CaixaDialeto>>::from(variant);
2668 let owned_static: &'static str = <&'static str as From<CaixaDialeto>>::from(variant);
2669 assert_eq!(
2670 owned_string.as_str(),
2671 owned_static,
2672 "From<CaixaDialeto> for String and From<CaixaDialeto> for \
2673 &'static str must resolve identically on \
2674 CaixaDialeto::{variant:?} — divergence signals the \
2675 owned-`String` and owned-`&'static str` forward-\
2676 projection return-type-shape paths have drifted onto \
2677 different emit-sets"
2678 );
2679 let via_to_string: String = variant.to_string();
2680 assert_eq!(
2681 owned_string, via_to_string,
2682 "From<CaixaDialeto> for String must byte-equal \
2683 CaixaDialeto::to_string on CaixaDialeto::{variant:?} — \
2684 divergence signals the trait-idiomatic owned-`String` \
2685 forward-projection axis and the ToString-through-\
2686 Display axis have drifted onto different emit-sets"
2687 );
2688 }
2689 let via_iter: Vec<String> = CaixaDialeto::ALL
2690 .iter()
2691 .copied()
2692 .map(String::from)
2693 .collect();
2694 let via_method: Vec<String> = CaixaDialeto::ALL
2695 .iter()
2696 .map(|d| d.as_str().to_owned())
2697 .collect();
2698 assert_eq!(
2699 via_iter, via_method,
2700 "`.iter().copied().map(String::from)` over CaixaDialeto::ALL \
2701 must byte-equal `.iter().map(|d| d.as_str().to_owned())` on \
2702 every arm — the owned-`String` `From<CaixaDialeto> for \
2703 String` axis is what makes the `String::from` composition \
2704 route through the substrate-primitive `CaixaDialeto::as_str` \
2705 accessor rather than through a per-call-site `.to_owned()` / \
2706 `String::from(dialeto.as_str())` detour"
2707 );
2708 for &variant in CaixaDialeto::ALL {
2709 let emitted: String = variant.into();
2710 let re_parsed: Result<CaixaDialeto, ()> =
2711 <CaixaDialeto as TryFrom<&str>>::try_from(emitted.as_str());
2712 assert_eq!(
2713 re_parsed,
2714 Ok(variant),
2715 "trait-idiomatic owned-`String` forward-projection + \
2716 reverse-projection axis pair must round-trip \
2717 CaixaDialeto::{variant:?} through `.into::<String>()` \
2718 and back through `TryFrom<&str>` on the owned-`String`'s \
2719 String::as_str borrow — a break signals the owned-\
2720 `String` forward-emit and reverse-parse axes have \
2721 drifted onto different vocabularies (unlike the peer \
2722 CaixaKind axis pair, CaixaDialeto's forward emit and \
2723 reverse parse share one PascalCase vocabulary by \
2724 construction, so the round-trip composes directly)"
2725 );
2726 }
2727 }
2728
2729 #[test]
2730 fn caixa_dialeto_from_into_borrowed_owned_string_routes_through_as_str_accessor() {
2731 // Fail-before-pass-after byte-parity pin on the newly lifted
2732 // `impl From<&CaixaDialeto> for String` — asserts the borrowed-
2733 // input owned-`String`-returning standard-library trait impl and
2734 // the substrate-primitive [`super::CaixaDialeto::as_str`]
2735 // `pub const fn` accessor resolve to the same four-arm emit-set
2736 // across every arm the exhaustive [`super::CaixaDialeto::ALL`]
2737 // slice enumerates. Rust's standard library does not carry a
2738 // blanket `impl<T: AsRef<str>> From<&T> for String` (nor an
2739 // `impl<T: fmt::Display> From<&T> for String`), so the
2740 // borrowed-input owned-`String` forward-projection axis is a
2741 // distinct trait-idiomatic surface that a
2742 // `let key: String = (&dialeto).into();`-shaped call site
2743 // reaches through this impl and no other — the paired sibling
2744 // `From<CaixaDialeto> for String` impl forces every borrowed-
2745 // input call site through an explicit `Copy` deref
2746 // (`String::from(*dialeto)`) or an `.as_str().to_owned()` /
2747 // `.to_string()` detour. Peer of the first-mover
2748 // [`crate::supervisor::tests::restart_strategy_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
2749 // (579385f), the second-peer
2750 // [`crate::supervisor::tests::restart_policy_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
2751 // (8465740), the third-peer
2752 // [`crate::dep::tests::dep_list_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
2753 // (e0cb617), and the fourth-peer
2754 // [`crate::kind::tests::caixa_kind_from_into_borrowed_owned_string_routes_through_as_str_accessor`]
2755 // (e76436d) — extends the trait-idiomatic borrowed-input owned-
2756 // `String` forward-projection axis onto the fourth closed-set
2757 // fieldless typed enum on the caixa surface (the dialect-
2758 // classification axis, second peer outside the M2 OTP-shape
2759 // sibling axis to reach the 2×2-completion corner).
2760 for &variant in CaixaDialeto::ALL {
2761 let via_trait: String = <String as From<&CaixaDialeto>>::from(&variant);
2762 let via_method: &'static str = variant.as_str();
2763 assert_eq!(
2764 via_trait.as_str(),
2765 via_method,
2766 "From<&CaixaDialeto> for String impl must round-trip \
2767 &CaixaDialeto::{variant:?} to the same `PascalCase` \
2768 arm-string CaixaDialeto::as_str returns — divergence \
2769 signals a silent detour off the substrate-primitive \
2770 accessor"
2771 );
2772 let via_into: String = (&variant).into();
2773 assert_eq!(
2774 via_into.as_str(),
2775 via_method,
2776 "Into<String>::into on &CaixaDialeto::{variant:?} must \
2777 byte-equal CaixaDialeto::as_str on the same input — \
2778 the blanket-derived Into shape must resolve to the \
2779 same as_str dispatch as the explicit From impl"
2780 );
2781 }
2782 }
2783
2784 #[test]
2785 fn caixa_dialeto_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm() {
2786 // Cross-axis partition pin: the newly lifted trait-idiomatic
2787 // borrowed-input owned-`String` `From<&CaixaDialeto> for String`
2788 // (this lift), the paired owned-input owned-`String`
2789 // `From<CaixaDialeto> for String` (88942cd), the paired
2790 // borrowed-input owned-`&'static str`
2791 // `From<&CaixaDialeto> for &'static str` (807b0b5), and the
2792 // paired owned-input owned-`&'static str`
2793 // `From<CaixaDialeto> for &'static str` (c189a6f) — every corner
2794 // of the `{Self, &Self} × {&'static str, String}` 2×2 trait-
2795 // idiomatic projection family — must resolve identically on
2796 // every arm, locking the four return-shape × input-shape paths
2797 // together so any future detour trips at caixa-core test time.
2798 // Also byte-parity witness against the sibling
2799 // [`ToString::to_string`] surface routed through
2800 // [`std::fmt::Display`] and a direct round-trip witness through
2801 // the paired trait-idiomatic reverse [`TryFrom<&str>`] axis on
2802 // the owned-`String`'s [`String::as_str`] borrow that closes
2803 // the two-way `&Self → String → Self` round-trip on the trait-
2804 // idiomatic borrowed-input owned-`String` forward + reverse
2805 // axis pair. Peer of the first-mover
2806 // [`crate::supervisor::tests::restart_strategy_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
2807 // (579385f), the second-peer
2808 // [`crate::supervisor::tests::restart_policy_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
2809 // (8465740), the third-peer
2810 // [`crate::dep::tests::dep_list_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
2811 // (e0cb617), and the fourth-peer
2812 // [`crate::kind::tests::caixa_kind_from_into_borrowed_owned_string_agrees_with_paired_axes_on_every_arm`]
2813 // (e76436d) — closes the whole `{Self, &Self} × {&'static str,
2814 // String}` 2×2 projection corner on the fifth substrate-wide
2815 // closed-set fieldless typed enum peer (the dialect-
2816 // classification axis, second peer outside the M2 OTP-shape
2817 // sibling pair).
2818 //
2819 // Unlike the peer [`crate::CaixaKind`] axis pair (whose forward
2820 // `From` emit lands on the lowercase Portuguese `as_str`
2821 // diagnostic vocabulary while the reverse `TryFrom<&str>`
2822 // parses the `PascalCase` `wire_name` author-surface vocabulary,
2823 // forcing the round-trip through an intermediate
2824 // [`crate::CaixaKind::wire_name`] hop), [`super::CaixaDialeto`]'s
2825 // [`super::CaixaDialeto::as_str`] emit and
2826 // [`super::CaixaDialeto::from_wire`] parse share the same
2827 // `PascalCase` vocabulary by construction (there is no
2828 // wire/diagnostic axis split on this enum), so the borrowed-
2829 // input owned-`String` forward axis and the reverse axis compose
2830 // directly — matching the peer
2831 // [`crate::supervisor::RestartStrategy`] /
2832 // [`crate::supervisor::RestartPolicy`] / [`crate::dep::DepList`]
2833 // borrowed-input owned-`String` axis pairs.
2834 for &dialeto in CaixaDialeto::ALL {
2835 let borrowed_string: String = <String as From<&CaixaDialeto>>::from(&dialeto);
2836 let owned_string: String = <String as From<CaixaDialeto>>::from(dialeto);
2837 let borrowed_static: &'static str =
2838 <&'static str as From<&CaixaDialeto>>::from(&dialeto);
2839 let owned_static: &'static str = <&'static str as From<CaixaDialeto>>::from(dialeto);
2840 assert_eq!(
2841 borrowed_string, owned_string,
2842 "From<&CaixaDialeto> for String and From<CaixaDialeto> \
2843 for String must resolve identically on \
2844 CaixaDialeto::{dialeto:?} — divergence signals the \
2845 borrowed-input and owned-input owned-`String` forward-\
2846 projection input-shape paths have drifted onto \
2847 different emit-sets"
2848 );
2849 assert_eq!(
2850 borrowed_string.as_str(),
2851 borrowed_static,
2852 "From<&CaixaDialeto> for String and From<&CaixaDialeto> \
2853 for &'static str must resolve identically on \
2854 CaixaDialeto::{dialeto:?} — divergence signals the \
2855 borrowed-input `&'static str` and owned-`String` \
2856 return-shape paths have drifted onto different \
2857 emit-sets"
2858 );
2859 assert_eq!(
2860 borrowed_string.as_str(),
2861 owned_static,
2862 "From<&CaixaDialeto> for String and From<CaixaDialeto> \
2863 for &'static str must resolve identically on \
2864 CaixaDialeto::{dialeto:?} — divergence signals a break \
2865 in the diagonal corner of the {{Self, &Self}} × \
2866 {{&'static str, String}} 2×2 trait-idiomatic \
2867 projection family"
2868 );
2869 let via_to_string: String = dialeto.to_string();
2870 assert_eq!(
2871 borrowed_string, via_to_string,
2872 "From<&CaixaDialeto> for String must byte-equal \
2873 CaixaDialeto::to_string on CaixaDialeto::{dialeto:?} — \
2874 divergence signals the trait-idiomatic borrowed-input \
2875 owned-`String` forward-projection axis and the \
2876 ToString-through-Display axis have drifted onto \
2877 different emit-sets"
2878 );
2879 }
2880 let via_iter: Vec<String> = CaixaDialeto::ALL.iter().map(String::from).collect();
2881 let via_method: Vec<String> = CaixaDialeto::ALL
2882 .iter()
2883 .map(|d| d.as_str().to_owned())
2884 .collect();
2885 assert_eq!(
2886 via_iter, via_method,
2887 "`.iter().map(String::from)` over CaixaDialeto::ALL — a \
2888 call site whose iteration axis holds `&CaixaDialeto` by \
2889 construction — must byte-equal `.iter().map(|d| \
2890 d.as_str().to_owned())` on every arm — the borrowed-input \
2891 owned-`String` `From<&CaixaDialeto> for String` axis is \
2892 what makes the `String::from` composition route through \
2893 the substrate-primitive `CaixaDialeto::as_str` accessor \
2894 without a spurious `Copy` deref (which would only be \
2895 reachable through the owned-input `From<CaixaDialeto> for \
2896 String` axis by first calling `.copied()` on the iterator)"
2897 );
2898 for &variant in CaixaDialeto::ALL {
2899 let emitted: String = (&variant).into();
2900 let re_parsed: Result<CaixaDialeto, ()> =
2901 <CaixaDialeto as TryFrom<&str>>::try_from(emitted.as_str());
2902 assert_eq!(
2903 re_parsed,
2904 Ok(variant),
2905 "trait-idiomatic borrowed-input owned-`String` \
2906 forward-projection + reverse-projection axis pair \
2907 must round-trip &CaixaDialeto::{variant:?} through \
2908 `.into::<String>()` on the borrowed-input surface and \
2909 back through `TryFrom<&str>` on the owned-`String`'s \
2910 String::as_str borrow — a break signals the \
2911 borrowed-input owned-`String` forward-emit and \
2912 reverse-parse axes have drifted onto different \
2913 vocabularies (unlike the peer CaixaKind axis pair, \
2914 CaixaDialeto's forward emit and reverse parse share \
2915 one PascalCase vocabulary by construction, so the \
2916 round-trip composes directly)"
2917 );
2918 }
2919 }
2920}