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/// A source that is not a `(defcaixa …)` / `(defmolde …)` form at all.
526#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
527pub enum DialetoError {
528 #[error("source has no top-level form")]
529 Vazio,
530 #[error("top-level form is not a list — a manifest is `(defcaixa …)`")]
531 NaoEhLista,
532 #[error(
533 "top-level form is headed by `{encontrado}`, not `defcaixa` or `defmolde` \
534 (a manifest's first form must be the declaration itself)"
535 )]
536 CabecaErrada { encontrado: String },
537 #[error("manifest does not parse as tatara-lisp: {0}")]
538 Leitura(String),
539}
540
541impl DialetoError {
542 /// Construct a [`DialetoError::CabecaErrada`] naming the offending
543 /// head symbol found at the top-level form.
544 ///
545 /// Substrate primitive every [`classify_form`] wrong-head fallthrough
546 /// wire-up site now routes through, folding the pre-lift uniform
547 /// three-line `Self::CabecaErrada { encontrado: <head>.to_string() }`
548 /// one-field struct-literal onto one substrate primitive matching the
549 /// peer `LimitsError::unknown_byte_unit(unit: &str)` /
550 /// `LimitsError::unknown_duration_unit(unit: &str)`
551 /// (`limits_codec_unit_only_ctors!` — 29fac09) single-slot
552 /// discipline on the sibling one-field `{ <field>: String }` envelope
553 /// axis, and matching the peer `ManifestError::code_path_empty` /
554 /// `BehaviorError::empty_path` / `UpgradeError::duplicate_from` /
555 /// `AplicacaoError::placement_cluster_duplicate` (94dabc8 / 0e33b37 /
556 /// 7e52aec / 92b1c92) single-slot inherent-ctor discipline every
557 /// sibling `{ <field>: <T> }` error-envelope variant on caixa-core's
558 /// error surface now carries.
559 ///
560 /// The one open-coded wire-up site — `classify_form`'s wrong-head
561 /// fallthrough arm on the `head: &str` binding read from the
562 /// top-level form via [`tatara_lisp::Sexp::as_symbol`] — opened the
563 /// identical three-line
564 /// `Self::CabecaErrada { encontrado: <head>.to_string() }` block
565 /// against the codec-scoped `<head>: &str` binding. Now routes
566 /// through `DialetoError::cabeca_errada(head)`, byte-equal to the
567 /// pre-lift struct-literal on the same `&str` fixture, so any future
568 /// widening of the diagnostic shape (e.g. carrying the source-file
569 /// path alongside the head symbol, carrying the head symbol's
570 /// position offset for an authoring-surface caret pointer) lands at
571 /// exactly one dispatch on the substrate primitive rather than re-
572 /// inlining the struct-literal at every wrong-head fallthrough
573 /// consumer.
574 #[must_use]
575 pub fn cabeca_errada(encontrado: &str) -> Self {
576 Self::CabecaErrada {
577 encontrado: encontrado.to_string(),
578 }
579 }
580
581 /// Construct a [`DialetoError::Leitura`] carrying the offending
582 /// tatara-lisp reader-error message `reason` verbatim in the
583 /// variant's tuple-newtype payload.
584 ///
585 /// Substrate primitive every [`classify`] tatara-lisp-reader
586 /// map-err wire-up site now routes through, folding the pre-lift
587 /// uniform `Self::Leitura(<into-String-expr>)` tuple-newtype
588 /// construction onto one substrate primitive matching the peer
589 /// `LimitsError::empty_byte_size` / `LimitsError::empty_duration`
590 /// (7a4b003 / 319216c) `(String)` single-slot tuple-newtype
591 /// discipline on the sibling
592 /// [`crate::limits::LimitsError`] envelope's empty-shape axis of
593 /// the paired codec-magnitude family. Peer to the sibling
594 /// [`DialetoError::cabeca_errada`] ctor on the same envelope's
595 /// wrong-head axis but on the tatara-lisp-reader axis rather than
596 /// the classifier-fallthrough axis. Closes the last un-lifted
597 /// variant on [`DialetoError`] — every one of the sole wire-up
598 /// sites (the [`classify`] tatara-lisp-reader `.map_err(|e|
599 /// Self::Leitura(e.to_string()))` arm) opened the identical
600 /// `DialetoError::Leitura(<into-String-expr>)` block against the
601 /// codec-scoped `String` (`e.to_string()`) binding, so the fold
602 /// routes the site through one dispatch on a uniform
603 /// `impl Into<String>` param, byte-equal to the pre-lift
604 /// tuple-newtype construction on the same argument.
605 ///
606 /// The `impl Into<String>` bound covers both wire-up shapes on
607 /// [`classify`] — a `String` binding (`e.to_string()` on the
608 /// [`tatara_lisp::Error`]-carrying `e` binding) and a `&str`
609 /// binding (a future admission-webhook consumer probing a
610 /// caller-scoped `&'static str` fixture, a future
611 /// `feira lint --tatara-reader-round-trip` verb sweeping every
612 /// `tatara_lisp::read` return through the same shape gate) —
613 /// without forcing the caller to spell the conversion at the
614 /// wire-up site. Same shape the peer
615 /// [`crate::limits::LimitsError::empty_byte_size`] /
616 /// [`crate::limits::LimitsError::empty_duration`] /
617 /// [`crate::limits::LimitsError::bad_millicores`] /
618 /// [`crate::limits::LimitsError::bad_byte_magnitude`] /
619 /// [`crate::limits::LimitsError::bad_duration_magnitude`] folds
620 /// carry on the peer bad-magnitude and empty-shape axes of the
621 /// same paired `(String)` tuple-newtype codec-magnitude family.
622 /// `#[must_use]` fires a compile warning at any wire-up that
623 /// mistakenly discards the constructed error.
624 ///
625 /// Every future consumer that wants to construct this variant
626 /// outside [`classify`] (a deferred `feira lint --tatara-reader-
627 /// round-trip` per-caixa admission verb probing each authored
628 /// manifest against the tatara-lisp-reader shape gate, an M4
629 /// typed `mesh.pleme.io/v1alpha1/Servico` CR materializer's
630 /// per-manifest admission validator re-checking one edited
631 /// `caixa.lisp` against the reader floor, a per-`caixa.lisp`
632 /// value-shape pre-emitter probing each declared manifest ahead
633 /// of the operator's admit-cycle) now reaches the variant
634 /// through one call rather than re-inlining the tuple-newtype
635 /// block in lockstep with the pre-existing wire-up.
636 #[must_use]
637 pub fn leitura(reason: impl Into<String>) -> Self {
638 Self::Leitura(reason.into())
639 }
640}
641
642/// Classify a manifest source without committing to either schema.
643///
644/// Deliberately reads only the head symbol and the set of top-level keywords —
645/// enough to route, never enough to half-parse. A classifier that started
646/// validating would grow into a third parser, which is the shape of the problem
647/// it exists to name.
648///
649/// # Errors
650/// [`DialetoError`] when the source is not a manifest declaration at all.
651pub fn classify(src: &str) -> Result<CaixaDialeto, DialetoError> {
652 let forms = tatara_lisp::read(src).map_err(|e| DialetoError::leitura(e.to_string()))?;
653 let first = forms.first().ok_or(DialetoError::Vazio)?;
654 classify_form(first)
655}
656
657/// [`classify`] over an already-read form.
658///
659/// # Errors
660/// [`DialetoError`] when the form is not a manifest declaration.
661pub fn classify_form(form: &Sexp) -> Result<CaixaDialeto, DialetoError> {
662 let list = form.as_list().ok_or(DialetoError::NaoEhLista)?;
663 let head = list
664 .first()
665 .and_then(Sexp::as_symbol)
666 .ok_or(DialetoError::NaoEhLista)?;
667
668 match head {
669 // `defmolde` is unambiguous by construction — it exists precisely so a
670 // consumer never has to infer which declaration it holds. Both arities
671 // are the same declaration; the positional one keeps its own variant
672 // only so a census can report the split.
673 "defmolde" => {
674 return Ok(if starts_with_positional_name(&list[1..]) {
675 CaixaDialeto::MoldePosicional
676 } else {
677 CaixaDialeto::Molde
678 });
679 }
680 "defcaixa" => {}
681 other => {
682 return Err(DialetoError::cabeca_errada(other));
683 }
684 }
685
686 let args = &list[1..];
687
688 // `(defcaixa <symbol> :kind … :ecosystem …)`. Only the Molde dialect has a
689 // positional arity; `Caixa` is keyword-only, so a leading bare symbol
690 // settles it without looking further.
691 if starts_with_positional_name(args) {
692 return Ok(CaixaDialeto::MoldePosicional);
693 }
694
695 let keys = top_level_keywords(args);
696 let has = |k: &str| keys.iter().any(|s| s == k);
697
698 // Order matters, and it is not arbitrary: `:nome` and `:name` are the two
699 // required head slots and no file in the measured corpus carries both.
700 // Checking them FIRST means the decision rests on the one slot each schema
701 // makes mandatory, rather than on optional evidence like `:ecosystem`.
702 if has("nome") {
703 return Ok(CaixaDialeto::Pacote);
704 }
705 if has("name") || has("ecosystem") || has("package") {
706 return Ok(CaixaDialeto::Molde);
707 }
708 Ok(CaixaDialeto::Desconhecido)
709}
710
711/// True when the first argument is a bare symbol rather than a keyword — the
712/// positional-name arity.
713fn starts_with_positional_name(args: &[Sexp]) -> bool {
714 matches!(args.first(), Some(Sexp::Atom(Atom::Symbol(_))))
715}
716
717/// The top-level keyword names (without the leading `:`) of a kwarg list.
718///
719/// Steps in pairs so a keyword appearing as a VALUE — `:kind :Biblioteca`, or a
720/// nested `(:nome "dep" :versao "^0.1")` inside `:deps` — is never counted as a
721/// top-level slot. A naive scan for `:nome` anywhere in the source classifies
722/// every Molde manifest with a `:deps` list as a Pacote.
723fn top_level_keywords(args: &[Sexp]) -> Vec<String> {
724 let mut out = Vec::new();
725 let mut i = 0;
726 while i < args.len() {
727 if let Sexp::Atom(Atom::Keyword(k)) = &args[i] {
728 out.push(k.clone());
729 i += 2;
730 } else {
731 i += 1;
732 }
733 }
734 out
735}
736
737#[cfg(test)]
738mod tests {
739 use super::*;
740
741 const PACOTE: &str = r#"
742 (defcaixa
743 :nome "checkout"
744 :versao "0.1.0"
745 :kind Servico
746 :deps ((:nome "caixa-teia" :versao "^0.1")))
747 "#;
748
749 const MOLDE: &str = r#"
750 (defcaixa
751 :name "base64"
752 :kind :Biblioteca
753 :ecosystem :rust-single-crate
754 :package {:name "base64" :version "0.22.1"}
755 :workflows [:auto-release])
756 "#;
757
758 const MOLDE_POSICIONAL: &str = r#"
759 (defcaixa todoku-go
760 :kind :Biblioteca
761 :ecosystem :go
762 :package {:name "todoku-go" :version "0.3.0"})
763 "#;
764
765 #[test]
766 fn the_package_dialect_is_recognised() {
767 assert_eq!(classify(PACOTE), Ok(CaixaDialeto::Pacote));
768 }
769
770 #[test]
771 fn the_repo_surface_dialect_is_recognised() {
772 assert_eq!(classify(MOLDE), Ok(CaixaDialeto::Molde));
773 }
774
775 #[test]
776 fn the_positional_arity_is_recognised() {
777 assert_eq!(
778 classify(MOLDE_POSICIONAL),
779 Ok(CaixaDialeto::MoldePosicional)
780 );
781 }
782
783 #[test]
784 fn defmolde_classifies_without_inference() {
785 // The whole point of the new keyword: no schema sniffing required.
786 let src = r#"(defmolde :name "x" :kind :Biblioteca :ecosystem :go)"#;
787 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
788 let pos = r"(defmolde todoku-go :kind :Biblioteca :ecosystem :go)";
789 assert_eq!(classify(pos), Ok(CaixaDialeto::MoldePosicional));
790 }
791
792 #[test]
793 fn a_nested_nome_does_not_make_a_repo_surface_look_like_a_package() {
794 // The exact failure a substring scan produces: `:deps ((:nome …))`
795 // contains `:nome`, but not as a top-level slot.
796 let src = r#"
797 (defcaixa
798 :name "x"
799 :ecosystem :rust-single-crate
800 :deps ((:nome "inner" :versao "^0.1")))
801 "#;
802 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
803 }
804
805 #[test]
806 fn a_keyword_in_value_position_is_not_a_slot() {
807 // `:kind :Biblioteca` — the value is itself a keyword. Stepping one at
808 // a time would read `:Biblioteca` as a top-level slot.
809 let src = r#"(defcaixa :kind :Biblioteca :name "x")"#;
810 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
811 }
812
813 #[test]
814 fn an_unrecognised_defcaixa_is_reported_not_guessed() {
815 let src = r#"(defcaixa :licenca "MIT")"#;
816 assert_eq!(classify(src), Ok(CaixaDialeto::Desconhecido));
817 }
818
819 #[test]
820 fn a_form_that_is_not_a_manifest_is_an_error_not_a_dialect() {
821 assert_eq!(
822 classify("(defflake :nome \"x\")"),
823 Err(DialetoError::cabeca_errada("defflake"))
824 );
825 assert_eq!(classify(""), Err(DialetoError::Vazio));
826 }
827
828 #[test]
829 fn every_dialect_names_its_consumer_and_its_canonical_keyword() {
830 // Guards the routing table itself: a new variant added without an arm
831 // here is a compile error in the match, and a variant that claims
832 // `defcaixa` while being read by pleme-doc-gen would re-open the
833 // collision this module closes. Sweeps [`CaixaDialeto::ALL`] rather
834 // than the pre-lift open-coded four-arm literal list — a future arm
835 // addition extends the slice as one edit and this pin picks it up
836 // by construction.
837 for &d in CaixaDialeto::ALL {
838 assert!(!d.descricao().is_empty(), "{d}");
839 assert!(!d.consumidor().is_empty(), "{d}");
840 }
841 assert_eq!(CaixaDialeto::Pacote.palavra_canonica(), "defcaixa");
842 assert_eq!(CaixaDialeto::Molde.palavra_canonica(), "defmolde");
843 assert_ne!(
844 CaixaDialeto::Pacote.palavra_canonica(),
845 CaixaDialeto::Molde.palavra_canonica(),
846 "the two dialects must not share a canonical keyword — that IS the defect"
847 );
848 }
849
850 #[test]
851 fn caixa_dialeto_all_enumerates_every_variant_exactly_once() {
852 // Three-legged exhaustiveness pin, peer of the sibling
853 // `caixa_kind_all_enumerates_every_variant_exactly_once`
854 // (caixa-core/src/kind.rs) /
855 // `restart_strategy_all_enumerates_every_variant_exactly_once`
856 // (caixa-core/src/supervisor.rs) shape.
857 //
858 // 1. arm-count invariant: `ALL.len()` matches the declared arm
859 // count (four — a fifth arm added without extending `ALL`
860 // fails this pin at caixa-core test time);
861 // 2. pairwise-distinctness invariant: every variant appears at
862 // most once in the slice (a duplicate arm would silently
863 // double-count in the census consumer, so the pin rejects
864 // duplicates outright);
865 // 3. coverage invariant: every literal `CaixaDialeto::X` is in
866 // the slice (the compiler-checked exhaustiveness on the peer
867 // per-arm `match self` in the accessors keeps the enum arm
868 // set and the `ALL` slice mutually aligned).
869 assert_eq!(
870 CaixaDialeto::ALL.len(),
871 4,
872 "ALL must list every arm exactly once; a fifth arm added \
873 without extending ALL fails this pin — extend ALL alongside \
874 the new variant"
875 );
876
877 let mut seen: Vec<CaixaDialeto> = Vec::new();
878 for &d in CaixaDialeto::ALL {
879 assert!(
880 !seen.contains(&d),
881 "ALL contains a duplicate arm: {d}. Every variant appears \
882 exactly once — a duplicate would double-count in every \
883 iteration consumer"
884 );
885 seen.push(d);
886 }
887
888 // Coverage: exhaustively assert every literal variant is somewhere
889 // in the slice. Written as an exhaustive `match` so a future arm
890 // addition fails to compile here (missing match arm) until the
891 // corresponding `assert` is added — the compiler enforces the pin's
892 // completeness rather than a hand-maintained variant list.
893 for variant in [
894 CaixaDialeto::Pacote,
895 CaixaDialeto::Molde,
896 CaixaDialeto::MoldePosicional,
897 CaixaDialeto::Desconhecido,
898 ] {
899 let coverage_probe = match variant {
900 CaixaDialeto::Pacote
901 | CaixaDialeto::Molde
902 | CaixaDialeto::MoldePosicional
903 | CaixaDialeto::Desconhecido => variant,
904 };
905 assert!(
906 CaixaDialeto::ALL.contains(&coverage_probe),
907 "ALL is missing variant {coverage_probe} — extend the slice"
908 );
909 }
910 }
911
912 #[test]
913 fn caixa_dialeto_all_is_const_and_matches_iteration_count() {
914 // Pins the const-ness of the slice at const-fold time. A future
915 // change that promoted `ALL` to a non-const initializer (a lazy-
916 // static, a runtime-computed Vec) would fail to compile here —
917 // the pin locks in the compile-time-known iteration surface
918 // every consumer builds against. Peer of the sibling
919 // `caixa_kind_all_is_const_and_matches_iteration_count` (kind.rs)
920 // / `restart_strategy_all_is_const_and_matches_iteration_count`
921 // (supervisor.rs) shape.
922 const ALL: &[CaixaDialeto] = CaixaDialeto::ALL;
923 assert_eq!(ALL.len(), CaixaDialeto::ALL.len());
924 // Sweep the iterator without collapsing to `.len()` so a future
925 // change to `ALL`'s carrier that decouples `.len()` from the
926 // iteration count (a lazy-computed shape, an alias `impl Iterator`
927 // return, a wrapper newtype) still passes here iff the two agree
928 // arm-for-arm; the `#[allow]` opts this local pin out of the
929 // clippy `iter_count` collapse that would defeat the intent.
930 #[allow(clippy::iter_count)]
931 let iterated = ALL.iter().count();
932 assert_eq!(iterated, CaixaDialeto::ALL.len());
933 }
934
935 #[test]
936 fn caixa_dialeto_all_covers_every_variant_by_display_probe() {
937 // Fanning `Display` over the slice sweeps the paired accessors
938 // ([`CaixaDialeto::palavra_canonica`] / [`CaixaDialeto::consumidor`]
939 // / [`CaixaDialeto::descricao`]) at every arm — every returned
940 // byte-string is non-empty (the accessors' contract). A future
941 // arm added without extending its per-arm `match self` return
942 // would compile-fail at the accessor call inside the loop;
943 // together with the `ALL.len() == 4` pin above, this locks the
944 // accessor arm-set and the `ALL` slice mutually.
945 for &d in CaixaDialeto::ALL {
946 let display_form = d.to_string();
947 assert!(
948 !display_form.is_empty(),
949 "Display must render a non-empty byte-string for every \
950 arm; empty: {d:?}"
951 );
952 // Consumidor / descricao / palavra-canonica must each surface
953 // a non-empty scalar; every downstream diagnostic consumer
954 // reaches through these accessors.
955 assert!(!d.palavra_canonica().is_empty(), "{d}");
956 assert!(!d.consumidor().is_empty(), "{d}");
957 assert!(!d.descricao().is_empty(), "{d}");
958 }
959 }
960
961 #[test]
962 fn caixa_dialeto_as_str_returns_pascal_case_variant_name() {
963 // Fail-before-pass-after per-arm shape pin: the four
964 // [`CaixaDialeto::as_str`] arms must return the canonical
965 // `PascalCase` byte-string that names the variant. Pre-lift this
966 // byte-string existed only inside the hand-rolled Display impl's
967 // four-arm literal-string match — every consumer that wanted the
968 // `PascalCase` name reached through `format!("{d}")`'s allocation
969 // path. Pinning the four arms explicitly here refuses a future
970 // regression that ever reroutes an arm to a distinct spelling
971 // (`"pacote"` lowercase, `"MoldePositional"` English rebrand,
972 // `"Unknown"` for `Desconhecido`) — the census output and the
973 // typed accessor would silently disagree until a downstream
974 // consumer surfaced the drift at census time. Peer of the sibling
975 // [`crate::supervisor::tests::restart_strategy_variants_serialize_to_lifted_scalar_values`]
976 // / `placement_strategy_variants_serialize_to_lifted_scalar_values`
977 // / `caixa_kind_as_str_returns_lifted_peer_const` shape on the
978 // sibling closed-set typed-enum discriminator axes — the seventh
979 // (and last unlifted) closed-set typed enum on the caixa surface
980 // to converge onto the same per-arm-shape-pin discipline.
981 for (variant, expected) in [
982 (CaixaDialeto::Pacote, "Pacote"),
983 (CaixaDialeto::Molde, "Molde"),
984 (CaixaDialeto::MoldePosicional, "MoldePosicional"),
985 (CaixaDialeto::Desconhecido, "Desconhecido"),
986 ] {
987 assert_eq!(
988 variant.as_str(),
989 expected,
990 "CaixaDialeto::{variant:?}.as_str() must return the \
991 canonical `PascalCase` variant-name byte-string; drift here \
992 splits the census-facing text from the substrate \
993 primitive every downstream consumer will read"
994 );
995 }
996 }
997
998 #[test]
999 fn caixa_dialeto_display_routes_through_as_str_helper() {
1000 // Fail-before-pass-after convergence pin: for every arm in
1001 // [`CaixaDialeto::ALL`], the [`std::fmt::Display`] rendered form
1002 // must byte-equal [`CaixaDialeto::as_str`]'s return value. Pre-
1003 // lift these two paths were structurally independent — the
1004 // Display impl hand-rolled its own four-arm literal-string
1005 // match with no compile-time link back to any substrate accessor
1006 // — so a future variant rename could land at `Display` without
1007 // touching a paired accessor (or vice versa), silently splitting
1008 // the two paths on the renamed arm. Pinning the byte-equality
1009 // here makes any such split a caixa-core build-time failure at
1010 // this test rather than surfacing far from the rename commit as
1011 // a downstream census consumer emitting one spelling while the
1012 // typed accessor returned another. Peer of the sibling
1013 // [`crate::kind::tests::caixa_kind_display_routes_through_as_str_helper`]
1014 // (which pins the same convergence on the [`crate::CaixaKind`]
1015 // closed-set axis) — extends the discipline onto the seventh
1016 // (and last unlifted) closed-set fieldless typed enum on the
1017 // caixa surface.
1018 for &variant in CaixaDialeto::ALL {
1019 assert_eq!(
1020 variant.to_string(),
1021 variant.as_str(),
1022 "CaixaDialeto::{variant:?} Display must route through \
1023 CaixaDialeto::as_str (single source of truth: the \
1024 lifted per-arm `PascalCase` variant-name byte-string)"
1025 );
1026 }
1027 }
1028
1029 #[test]
1030 fn caixa_dialeto_as_ref_str_routes_through_as_str_accessor() {
1031 // Fail-before-pass-after byte-parity pin on the lifted
1032 // `impl AsRef<str> for CaixaDialeto` — asserts the standard-
1033 // library trait impl and the substrate-primitive
1034 // [`CaixaDialeto::as_str`] `pub const fn` accessor resolve to
1035 // the same `&str` per instance across the four-arm closed set,
1036 // so any future silent detour that routes the impl through a
1037 // divergent projection (a per-arm inline
1038 // `match self { CaixaDialeto::Pacote => "Pacote", … }` re-inlining
1039 // that opens a compile-time link to the un-lifted arm-literal,
1040 // a swap onto the second-axis
1041 // [`CaixaDialeto::palavra_canonica`] /
1042 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
1043 // accessors that carry distinct byte-shapes per axis) trips at
1044 // caixa-core test time under `PartialEq` rather than at a
1045 // downstream `impl AsRef<str>`-bound consumer's silent split.
1046 // Sweeps every one of the four arms [`CaixaDialeto::ALL`]
1047 // carries so no arm's projection is covered only by the sibling
1048 // `Display` path. Peer of the sibling
1049 // `rate_limit_unit_as_ref_str_routes_through_as_suffix_accessor`
1050 // (d8136db) on the M3 `:politicas :rate-limit` closed-set typed
1051 // enum, and the peer
1052 // [`crate::kind::tests::caixa_kind_as_ref_str_routes_through_as_str_accessor`]
1053 // (cd2091f) pin on the top-level closed-set typed
1054 // discriminator — the pins together close the substrate
1055 // primitive's `AsRef<str>` projection axis onto the seventh
1056 // closed-set fieldless typed enum on the caixa surface.
1057 for &variant in CaixaDialeto::ALL {
1058 assert_eq!(
1059 <CaixaDialeto as AsRef<str>>::as_ref(&variant),
1060 variant.as_str(),
1061 "AsRef<str> impl on CaixaDialeto::{variant:?} must \
1062 byte-equal CaixaDialeto::as_str on the same instance \
1063 — divergence signals a silent detour off the \
1064 substrate-primitive accessor"
1065 );
1066 }
1067 }
1068
1069 #[test]
1070 fn caixa_dialeto_as_ref_str_routes_through_display_via_shared_accessor() {
1071 // Fail-before-pass-after byte-parity pin on the three-path
1072 // convergence discipline the [`CaixaDialeto`] closed-set
1073 // dialect-classification enum now carries on the `&str`-
1074 // projection axis: `<CaixaDialeto as AsRef<str>>::as_ref(&v)`
1075 // (the newly lifted impl), `format!("{v}")` (the pre-existing
1076 // [`fmt::Display`] impl), and `v.as_str()` (the substrate-
1077 // primitive `pub const fn` accessor both trait impls delegate
1078 // through) must resolve to the same byte-string on every
1079 // instance across the four-arm closed set. Refuses any future
1080 // divergence between the two trait impls (a stray
1081 // [`fmt::Display::fmt`] rewrite that hand-rolls the arms
1082 // rather than delegating through the shared accessor; a
1083 // hypothetical `AsRef<str>` rewrite that inlines a per-arm
1084 // literal cascade) that would silently split the two
1085 // projection paths of the same closed-set typed enum. Mirrors
1086 // the sibling three-path-convergence discipline the peer
1087 // [`crate::aplicacao::RateLimitUnit`] typed enum carries
1088 // (`rate_limit_unit_as_ref_str_routes_through_display_via_shared_accessor`,
1089 // d8136db), the peer [`crate::CaixaKind`] triple
1090 // (`caixa_kind_as_ref_str_routes_through_display_via_shared_accessor`,
1091 // cd2091f), and the [`crate::CaixaVersion`] typed newtype
1092 // triple (`caixa_version_as_ref_str_routes_through_display_via_shared_accessor`,
1093 // 16d5c7e).
1094 for &variant in CaixaDialeto::ALL {
1095 let via_as_ref: &str = <CaixaDialeto as AsRef<str>>::as_ref(&variant);
1096 let via_display: String = format!("{variant}");
1097 let via_accessor: &str = variant.as_str();
1098 assert_eq!(via_as_ref, via_accessor);
1099 assert_eq!(via_display, via_accessor);
1100 assert_eq!(via_as_ref, via_display.as_str());
1101 }
1102 }
1103
1104 #[test]
1105 fn caixa_dialeto_is_molde_family_returns_true_on_molde_and_positional_arms() {
1106 // Fail-before-pass-after per-arm shape pin on the two `defmolde`
1107 // declaration-family arms: [`CaixaDialeto::is_molde_family`] must
1108 // return `true` for [`CaixaDialeto::Molde`] and
1109 // [`CaixaDialeto::MoldePosicional`] — the two-arity closure of
1110 // one declaration ([`CaixaDialeto::MoldePosicional`]'s docstring:
1111 // "same declaration as [`Self::Molde`], written with the package
1112 // name as a bare positional symbol … one arity of one
1113 // declaration, not a third schema"). A future accidental flip that
1114 // reversed a per-arm arm's return without touching the paired
1115 // false-arm pin would silently open the substrate primitive to
1116 // false-positive on either arm — the `feira dialeto` verb's
1117 // `--strict-palavra` gate would then silently accept
1118 // repo-surface declarations under `(defcaixa …)` on one arm and
1119 // reject them on the other. Pinning the two true arms explicitly
1120 // here refuses that split at caixa-core build time.
1121 assert!(
1122 CaixaDialeto::Molde.is_molde_family(),
1123 "CaixaDialeto::Molde.is_molde_family() must return true — \
1124 Molde is the primary `defmolde` arm"
1125 );
1126 assert!(
1127 CaixaDialeto::MoldePosicional.is_molde_family(),
1128 "CaixaDialeto::MoldePosicional.is_molde_family() must return \
1129 true — MoldePosicional is the positional-arity form of the \
1130 same `defmolde` declaration Molde carries"
1131 );
1132 }
1133
1134 #[test]
1135 fn caixa_dialeto_is_molde_family_returns_false_on_pacote_and_desconhecido_arms() {
1136 // Fail-before-pass-after per-arm shape pin on the two non-`defmolde`
1137 // arms: [`CaixaDialeto::is_molde_family`] must return `false` for
1138 // [`CaixaDialeto::Pacote`] (the sibling `defcaixa` tatara-lisp
1139 // package manifest, `palavra_canonica → "defcaixa"`) and for
1140 // [`CaixaDialeto::Desconhecido`] (the residue that names no
1141 // known declaration, `palavra_canonica → "?"`). Pinning the two
1142 // false arms explicitly here refuses a future accidental flip
1143 // that let the predicate widen to include either arm — the
1144 // `feira dialeto` verb's `--strict-palavra` gate would then
1145 // spuriously refuse every `(defcaixa …)` package manifest as if
1146 // it were a repo-surface declaration.
1147 assert!(
1148 !CaixaDialeto::Pacote.is_molde_family(),
1149 "CaixaDialeto::Pacote.is_molde_family() must return false — \
1150 Pacote is the `defcaixa` tatara-lisp package manifest, not \
1151 the `defmolde` repo-surface declaration"
1152 );
1153 assert!(
1154 !CaixaDialeto::Desconhecido.is_molde_family(),
1155 "CaixaDialeto::Desconhecido.is_molde_family() must return \
1156 false — the residue arm names no known declaration; it is \
1157 not silently promoted into the `defmolde` family"
1158 );
1159 }
1160
1161 #[test]
1162 fn caixa_dialeto_is_molde_family_agrees_with_palavra_canonica_defmolde_projection() {
1163 // Load-bearing pin: for every arm in [`CaixaDialeto::ALL`], the
1164 // typed [`CaixaDialeto::is_molde_family`] predicate must agree
1165 // byte-for-byte with the paired [`CaixaDialeto::palavra_canonica`]
1166 // projection's `== "defmolde"` classifier — i.e. the two paths
1167 // partition the four-arm discriminator set into the same
1168 // `{Molde, MoldePosicional}` and `{Pacote, Desconhecido}` halves.
1169 // Pre-lift the sibling [`CaixaDialeto::palavra_canonica`] projection
1170 // (which returns `"defmolde"` for `Molde | MoldePosicional`,
1171 // `"defcaixa"` for `Pacote`, `"?"` for `Desconhecido`) was the
1172 // only substrate-side surface carrying the two-arm collapse; the
1173 // hand-rolled `matches!(d, CaixaDialeto::Molde |
1174 // CaixaDialeto::MoldePosicional)` sites in the `feira dialeto`
1175 // verb expressed no compile-time link back to it. A future arm
1176 // addition — the module doc's "third dialect" hazard actualises
1177 // as a fifth arm belonging to the `defmolde` family — would land
1178 // one match arm at [`Self::palavra_canonica`]'s `defmolde` return
1179 // (extending the sibling projection) but silently split the
1180 // hand-rolled two-arm `matches!` predicate sites if the new arm's
1181 // `is_molde_family` return were forgotten. Pinning byte-equality
1182 // between the two paths here makes any such split a caixa-core
1183 // build-time failure at this test rather than surfacing far from
1184 // the arm-addition commit as a downstream `--strict-palavra` /
1185 // `caixa.lisp`-holds-wrong-declaration gate silently ignoring the
1186 // new arm.
1187 for &d in CaixaDialeto::ALL {
1188 let via_palavra_canonica = d.palavra_canonica() == "defmolde";
1189 let via_is_molde_family = d.is_molde_family();
1190 assert_eq!(
1191 via_is_molde_family, via_palavra_canonica,
1192 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
1193 must agree with CaixaDialeto::{d:?}.palavra_canonica() == \
1194 \"defmolde\" ({via_palavra_canonica}) — a split between the \
1195 typed predicate and the sibling keyword projection would let \
1196 a future arm addition land at one path and drift at the other, \
1197 which is exactly the drift this pin refuses"
1198 );
1199 }
1200 }
1201
1202 #[test]
1203 fn caixa_dialeto_is_molde_family_is_const_fn() {
1204 // Const-context pin: [`CaixaDialeto::is_molde_family`] must remain
1205 // `const fn` (its match is a fieldless-arm literal-pattern
1206 // discriminator, so no non-const operation exists on the resolution
1207 // path). Downstream consumers reaching for the predicate from a
1208 // `const` context (a future substrate-wide const-fold-driven audit
1209 // table that materializes per-arm gate-membership at build time,
1210 // a per-arm CR-admission-webhook gate registration in a `const`
1211 // context) rely on the const-ness. A future accidental downgrade
1212 // to non-`const` (an added runtime helper reachable only from a
1213 // non-`const` context) trips at caixa-core build time rather than
1214 // surfacing as a downstream `const`-context regression far from
1215 // the predicate declaration. Peer of the sibling
1216 // [`caixa_dialeto_as_str_is_const_fn`] pin on the paired
1217 // [`CaixaDialeto::as_str`] byte-string axis.
1218 const ARMS: [(CaixaDialeto, bool); 4] = [
1219 (CaixaDialeto::Pacote, CaixaDialeto::Pacote.is_molde_family()),
1220 (CaixaDialeto::Molde, CaixaDialeto::Molde.is_molde_family()),
1221 (
1222 CaixaDialeto::MoldePosicional,
1223 CaixaDialeto::MoldePosicional.is_molde_family(),
1224 ),
1225 (
1226 CaixaDialeto::Desconhecido,
1227 CaixaDialeto::Desconhecido.is_molde_family(),
1228 ),
1229 ];
1230 // Materialize the const-fold-evaluated table into a runtime slice
1231 // assertion — carries the same `bool = const fn call` shape a raw
1232 // `assert!(const_bool)` would, without tripping the
1233 // `assertions_on_constants` clippy lint that a per-arm
1234 // `assert!(CONST)` on a `const bool` triggers when the arm-count
1235 // is enumerated flat rather than compared as a whole-table shape.
1236 assert_eq!(
1237 ARMS,
1238 [
1239 (CaixaDialeto::Pacote, false),
1240 (CaixaDialeto::Molde, true),
1241 (CaixaDialeto::MoldePosicional, true),
1242 (CaixaDialeto::Desconhecido, false),
1243 ],
1244 "CaixaDialeto::is_molde_family() must evaluate in const context \
1245 for every arm and land on the {{false, true, true, false}} \
1246 partition — a future accidental downgrade to non-`const` \
1247 would trip the const-context array-initializer here"
1248 );
1249 }
1250
1251 #[test]
1252 fn caixa_dialeto_as_str_is_const_fn() {
1253 // Const-context pin: [`CaixaDialeto::as_str`] must remain
1254 // `const fn` (its match arms return `pub const` byte-strings, so
1255 // no non-const operation exists on the resolution path).
1256 // Downstream consumers reaching for the accessor from a `const`
1257 // context (a future substrate-wide const-fold-driven audit table
1258 // that materializes every dialect's census label at build time,
1259 // a per-arm CR-admission-webhook message registration in a
1260 // `const` gate) rely on the const-ness. A future accidental
1261 // downgrade to non-`const` (an added runtime helper reachable
1262 // only from a non-`const` context, a manual hand-rolled `impl`
1263 // that shadows this method) trips at caixa-core build time
1264 // rather than surfacing as a downstream `const`-context
1265 // regression far from the accessor declaration. Peer of the
1266 // sibling [`crate::kind::tests::caixa_kind_wire_name_is_const_fn`]
1267 // pin on the paired [`crate::CaixaKind`] byte-string axis.
1268 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
1269 const MOLDE: &str = CaixaDialeto::Molde.as_str();
1270 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
1271 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
1272 assert_eq!(PACOTE, "Pacote");
1273 assert_eq!(MOLDE, "Molde");
1274 assert_eq!(MOLDE_POSICIONAL, "MoldePosicional");
1275 assert_eq!(DESCONHECIDO, "Desconhecido");
1276 }
1277
1278 #[test]
1279 fn caixa_dialeto_is_variant_predicates_partition_the_arm_set() {
1280 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
1281 // derive: for each of the four variants at [`CaixaDialeto::ALL`]`[idx]`
1282 // the observed four-slot predicate row must equal a one-hot row
1283 // with the `true` at exactly `idx`. Pre-derive the closed four-arm
1284 // dialect-classification partition lived only inside the paired
1285 // per-arm projections' four-arm match resolvers ([`Self::as_str`] /
1286 // [`Self::palavra_canonica`] / [`Self::consumidor`] /
1287 // [`Self::descricao`]) plus the two-arm [`Self::is_molde_family`]
1288 // hand-rolled `matches!` (now routed through the derived
1289 // predicates); a future rebrand (an accidental
1290 // `#[is_variant(name = "…")]` drift, a manual hand-rolled `impl`
1291 // that shadows the derive-generated method, an arm rename that
1292 // reroutes one arm through the wrong predicate lane) trips this
1293 // pin at caixa-core build time rather than surfacing far from the
1294 // derive declaration as a downstream [`Self::is_molde_family`]
1295 // consumer accepting the wrong arm-set. The expected row is
1296 // generated live from the [`Self::ALL`] declaration order rather
1297 // than transcribed by hand so a copy-paste flip reroutes at the
1298 // identity-diagonal assertion.
1299 //
1300 // Peer of the sibling
1301 // [`crate::kind::tests::caixa_kind_is_variant_predicates_partition_the_arm_set`]
1302 // / [`crate::supervisor::tests::restart_strategy_is_variant_predicates_partition_the_arm_set`]
1303 // / [`crate::aplicacao::tests::placement_strategy_is_variant_predicates_partition_the_arm_set`]
1304 // / [`crate::upgrade::tests::upgrade_instruction_is_variant_predicates_partition_the_arm_set`]
1305 // pins on the sibling closed-set typed-enum discriminator axes.
1306 for (idx, &variant) in CaixaDialeto::ALL.iter().enumerate() {
1307 let observed = [
1308 variant.is_pacote(),
1309 variant.is_molde(),
1310 variant.is_molde_posicional(),
1311 variant.is_desconhecido(),
1312 ];
1313 let mut expected = [false; 4];
1314 expected[idx] = true;
1315 assert_eq!(
1316 observed, expected,
1317 "CaixaDialeto::{variant:?} at ALL[{idx}] is_* predicates \
1318 must fire only on their own arm lane (identity diagonal); \
1319 got {observed:?}",
1320 );
1321 }
1322 }
1323
1324 #[test]
1325 fn caixa_dialeto_is_variant_predicates_are_const_fn() {
1326 // The [`gen_platform::IsVariant`] derive emits `const fn`
1327 // predicates on the peer [`crate::CaixaKind`] +
1328 // [`crate::upgrade::UpgradeInstruction`] +
1329 // [`crate::supervisor::RestartStrategy`] +
1330 // [`crate::supervisor::RestartPolicy`] +
1331 // [`crate::aplicacao::PlacementStrategy`] +
1332 // [`crate::aplicacao::RateLimitUnit`] +
1333 // [`crate::dep::DepList`] closed-set typed enums — pin the same
1334 // posture on [`CaixaDialeto`] so a future accidental downgrade
1335 // to non-`const` (an added runtime helper reachable only from a
1336 // non-`const` context, a manual hand-rolled `impl` that shadows
1337 // the derive-generated method) trips at caixa-core build time
1338 // rather than surfacing as a downstream `const`-context
1339 // regression far from the derive declaration.
1340 // Use `const { assert!(…) }` (peer of the sibling
1341 // [`crate::render::PathShapeViolation`] +
1342 // [`crate::aplicacao::RateLimitUnit`] +
1343 // [`caixa_theme::style::Semantic`] const-fn pins) so the
1344 // const-context evaluation trips at const-fold time without
1345 // opening a per-`const bool` `assertions_on_constants` clippy
1346 // debt row this crate does not carry today for `dialeto.rs`.
1347 const { assert!(CaixaDialeto::Pacote.is_pacote()) };
1348 const { assert!(CaixaDialeto::Molde.is_molde()) };
1349 const { assert!(CaixaDialeto::MoldePosicional.is_molde_posicional()) };
1350 const { assert!(CaixaDialeto::Desconhecido.is_desconhecido()) };
1351 }
1352
1353 #[test]
1354 fn caixa_dialeto_from_wire_accepts_every_as_str_output() {
1355 // Fail-before-pass-after per-arm accept pin on the newly lifted
1356 // [`CaixaDialeto::from_wire`] reverse projection: every arm in
1357 // [`CaixaDialeto::ALL`] must parse back through `from_wire` when
1358 // fed its own [`CaixaDialeto::as_str`] output, landing on
1359 // `Some(same_variant)` — a regression that hand-rolled either
1360 // side's per-arm match without threading through the shared
1361 // four-string closed set would silently disagree on any future
1362 // arm rename and this pin flags it at caixa-core build time.
1363 // Peer of the sibling
1364 // [`crate::kind::tests::caixa_kind_wire_round_trips_through_from_wire`]
1365 // (2aa6d23) /
1366 // `placement_strategy_from_wire_accepts_every_lifted_constant`
1367 // (18c7342) /
1368 // `dep_list_round_trips_through_as_str_and_from_wire` (45ee563)
1369 // shape on the sibling closed-set typed-enum reverse-projection
1370 // axes.
1371 for &variant in CaixaDialeto::ALL {
1372 let wire = variant.as_str();
1373 let parsed = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
1374 panic!(
1375 "CaixaDialeto::from_wire({wire:?}) must accept every \
1376 CaixaDialeto::as_str output — got None for the \
1377 wire byte-string of {variant:?}"
1378 )
1379 });
1380 assert_eq!(
1381 parsed, variant,
1382 "CaixaDialeto::from_wire(CaixaDialeto::{variant:?}.as_str()) \
1383 must return CaixaDialeto::{variant:?} — the (as_str, \
1384 from_wire) pair must form a total round-trip on the \
1385 closed four-arm CaixaDialeto arm-set"
1386 );
1387 }
1388 }
1389
1390 #[test]
1391 fn caixa_dialeto_from_wire_rejects_unknown_byte_strings() {
1392 // Rejection pin on the parser's accept-set: any string outside
1393 // the four-arm [`CaixaDialeto::as_str`] output set must return
1394 // `None`. A future accidental widening of the accept-set (a
1395 // case-insensitive match that accepts `"pacote"` on the wire
1396 // axis, a hand-rolled Levenshtein-forgiving arm-lookup that
1397 // admits `"Pacotee"` typos, a silent acceptance of the sibling
1398 // [`Self::palavra_canonica`] `"defcaixa"` / `"defmolde"`
1399 // byte-shapes on this axis) would silently drift the parser's
1400 // accept-set from the emitter's — a downstream audit-report
1401 // re-loader that bound a prior audit's [`Self::as_str`] output
1402 // back to the typed enum through this parser would then bind a
1403 // malformed byte-string to a plausibly-wrong typed arm the
1404 // caller does not route through any fallback, silently
1405 // misclassifying the reloaded row. Also rejects the sibling
1406 // [`Self::palavra_canonica`] (`"defcaixa"` / `"defmolde"`) and
1407 // the sibling [`Self::consumidor`] (`"caixa-core / feira"`,
1408 // `"pleme-doc-gen"`, `"nobody known"`) byte-shapes, which are
1409 // the substrate's *distinct-axis* projections on the same enum
1410 // — the two-axis split the sibling
1411 // [`Self::palavra_canonica`] / [`Self::consumidor`] /
1412 // [`Self::descricao`] docstrings explicitly frame forbids
1413 // accepting one axis's byte-shapes as parseable on the other
1414 // axis. Peer of the sibling
1415 // [`crate::kind::tests::caixa_kind_from_wire_rejects_unknown_byte_strings`]
1416 // (2aa6d23) /
1417 // `placement_strategy_from_wire_rejects_unknown_byte_strings`
1418 // (18c7342) /
1419 // `dep_list_from_wire_returns_none_on_unknown_wire_scalar`
1420 // (45ee563) rejection pins on the sibling closed-set typed-enum
1421 // reverse-projection axes.
1422 for bad in [
1423 "",
1424 " ",
1425 "pacote",
1426 "PACOTE",
1427 "molde",
1428 "MoldePositional",
1429 "desconhecido",
1430 "Unknown",
1431 "defcaixa",
1432 "defmolde",
1433 "?",
1434 "caixa-core / feira",
1435 "pleme-doc-gen",
1436 "nobody known",
1437 "Pacote ",
1438 " Pacote",
1439 ] {
1440 assert!(
1441 CaixaDialeto::from_wire(bad).is_none(),
1442 "CaixaDialeto::from_wire({bad:?}) must return None — the \
1443 parser's accept-set is exactly the four CaixaDialeto::as_str \
1444 outputs; a widening would silently split the parser's \
1445 accept-set from the emitter's arm-set"
1446 );
1447 }
1448 }
1449
1450 #[test]
1451 fn cabeca_errada_ctor_matches_struct_literal_wrap() {
1452 // Fail-before-pass-after byte-identity pin: the lifted
1453 // [`DialetoError::cabeca_errada`] ctor MUST land on the exact
1454 // same struct-literal shape the pre-lift open-coded wire-up
1455 // block wrote by hand — `DialetoError::CabecaErrada {
1456 // encontrado: <head>.to_string() }`. A future accidental
1457 // divergence (`.into()` swap, per-arm constant substitution, an
1458 // added default field, an `.to_ascii_lowercase()` normalization
1459 // silently injected into the ctor body, a rebrand of the
1460 // `encontrado` field carrying a distinct byte-shape) trips this
1461 // pin at caixa-core build time rather than surfacing far from
1462 // the ctor declaration as a downstream `classify_form`
1463 // wrong-head consumer emitting one diagnostic shape while a
1464 // hand-written test peer opens another. Peer of the sibling
1465 // `unknown_byte_unit_ctor_matches_struct_literal_wrap`
1466 // (limits.rs; 29fac09) / `duplicate_from_ctor_matches_struct_
1467 // literal_wrap` (upgrade.rs; 7e52aec) shape on the sibling
1468 // single-slot `{ <field>: String }` envelope constructors.
1469 assert_eq!(
1470 DialetoError::cabeca_errada("defflake"),
1471 DialetoError::CabecaErrada {
1472 encontrado: "defflake".to_string(),
1473 },
1474 "DialetoError::cabeca_errada must byte-equal the pre-lift \
1475 open-coded struct-literal — a drift here means the ctor \
1476 stopped being a substrate primitive for the wrong-head \
1477 fallthrough site"
1478 );
1479 }
1480
1481 #[test]
1482 fn cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs() {
1483 // Fail-before-pass-after boundary-sweep pin: the lifted
1484 // [`DialetoError::cabeca_errada`] ctor MUST route its
1485 // `encontrado: &str` argument verbatim into the
1486 // [`DialetoError::CabecaErrada`] `encontrado: String` field
1487 // for every boundary-covering `&str` input — empty string, a
1488 // canonical `defcaixa`-adjacent head, a non-ASCII head, a
1489 // whitespace-carrying head, a Unicode-full-width head. Any
1490 // wrapper-side truncation, silent `.trim()`, accidental
1491 // `.to_ascii_lowercase()` normalization, or `.into()` divergence
1492 // on the ctor body surfaces here as a byte-mismatch against the
1493 // input rather than at a downstream
1494 // [`DialetoError::to_string()`] diagnostic-shape drift at a
1495 // wrong-head fallthrough consumer far from the ctor declaration.
1496 // Peer of the sibling `limits_codec_unit_only_ctors_route_unit_
1497 // verbatim_across_every_variant` (limits.rs; 29fac09) shape on
1498 // the sibling single-slot `{ <field>: String }` envelope
1499 // boundary-sweep discipline.
1500 for encontrado in [
1501 "",
1502 "defflake",
1503 "def-molde",
1504 "defcaixa ",
1505 " defcaixa",
1506 "μdefcaixa",
1507 "\u{00A0}defcaixa",
1508 "\u{3000}defcaixa",
1509 "def\u{2028}caixa",
1510 ] {
1511 let via_ctor = DialetoError::cabeca_errada(encontrado);
1512 let via_literal = DialetoError::CabecaErrada {
1513 encontrado: encontrado.to_string(),
1514 };
1515 assert_eq!(
1516 via_ctor, via_literal,
1517 "DialetoError::cabeca_errada({encontrado:?}) must byte- \
1518 equal the open-coded struct-literal on the same input — \
1519 a drift here would let the ctor silently normalize / \
1520 truncate the head symbol before it reached the \
1521 CabecaErrada envelope"
1522 );
1523 let DialetoError::CabecaErrada { encontrado: routed } = via_ctor else {
1524 panic!(
1525 "DialetoError::cabeca_errada must construct the \
1526 CabecaErrada arm — got a different variant on \
1527 input {encontrado:?}"
1528 );
1529 };
1530 assert_eq!(
1531 routed, encontrado,
1532 "DialetoError::cabeca_errada must route the input \
1533 {encontrado:?} verbatim into the encontrado field — \
1534 any wrapper-side truncation / normalization surfaces \
1535 here rather than at a downstream diagnostic shape drift"
1536 );
1537 }
1538 }
1539
1540 #[test]
1541 fn classify_form_wrong_head_routes_through_cabeca_errada_ctor() {
1542 // Fail-before-pass-after routing pin: [`classify`]'s wrong-head
1543 // fallthrough site MUST construct its `Err(DialetoError::…)`
1544 // through the substrate-primitive [`DialetoError::cabeca_errada`]
1545 // ctor rather than through an open-coded struct-literal. Pre-
1546 // lift the wire-up hand-rolled a three-line
1547 // `Self::CabecaErrada { encontrado: other.to_string() }` block
1548 // with no compile-time link back to the substrate primitive; a
1549 // future accidental rebrand of the ctor body (an added
1550 // `.trim()` on `encontrado`, a per-arm constant prefix like
1551 // `"unknown-head:"`, a widening of the field into a
1552 // `(String, usize)` tuple carrying a caret offset) would then
1553 // silently split the two paths — the ctor consumers pick up
1554 // the new shape, the open-coded wire-up does not. Pinning
1555 // byte-equality between the observed `Err` and the ctor-
1556 // constructed `Err` refuses that split at caixa-core build
1557 // time rather than surfacing far from the wire-up commit as a
1558 // downstream diagnostic-consumer split.
1559 for head in ["defflake", "deffoobar", "defcaixaz", "let", "defmoldez"] {
1560 let src = format!("({head} :nome \"x\")");
1561 let observed = classify(&src);
1562 let via_ctor = Err(DialetoError::cabeca_errada(head));
1563 assert_eq!(
1564 observed, via_ctor,
1565 "classify({src:?}) must return the same Err shape as \
1566 DialetoError::cabeca_errada({head:?}) — a drift here \
1567 means the wire-up de-lifted its wrong-head fallthrough \
1568 arm off the substrate primitive"
1569 );
1570 }
1571 }
1572
1573 #[test]
1574 fn leitura_ctor_matches_tuple_literal_wrap_on_str_binding() {
1575 // Fail-before-pass-after byte-identity pin: the lifted
1576 // [`DialetoError::leitura`] ctor MUST land on the exact same
1577 // tuple-newtype wrap the pre-lift open-coded wire-up block wrote by
1578 // hand — `DialetoError::Leitura(<into-String-expr>)`. A future
1579 // accidental divergence (an added `.trim()` on the reader reason,
1580 // a per-arm constant prefix like `"tatara-lisp:"`, a widening of
1581 // the tuple carrying a caret offset, a rebrand of the payload
1582 // carrying a distinct byte-shape) trips this pin at caixa-core
1583 // build time rather than surfacing far from the ctor declaration
1584 // as a downstream [`classify`] tatara-lisp-reader consumer
1585 // emitting one diagnostic shape while a hand-written test peer
1586 // opens another. Peer of the sibling
1587 // `cabeca_errada_ctor_matches_struct_literal_wrap` pin above on
1588 // the same [`DialetoError`] envelope's wrong-head axis, and of
1589 // the peer `LimitsError::empty_byte_size` /
1590 // `LimitsError::empty_duration` (7a4b003 / 319216c) shape on the
1591 // sibling `(String)` single-slot tuple-newtype envelope
1592 // constructors.
1593 let reason: &str = "unclosed paren at 1:12";
1594 assert_eq!(
1595 DialetoError::leitura(reason),
1596 DialetoError::Leitura(reason.to_string()),
1597 "DialetoError::leitura must byte-equal the pre-lift open-coded \
1598 tuple-newtype wrap — a drift here means the ctor stopped \
1599 being a substrate primitive for the tatara-lisp-reader \
1600 fallthrough site"
1601 );
1602 }
1603
1604 #[test]
1605 fn leitura_ctor_matches_tuple_literal_wrap_on_string_binding() {
1606 // Fail-before-pass-after byte-identity pin on the `String` wire-up
1607 // shape: the lifted [`DialetoError::leitura`] ctor MUST land on
1608 // the same tuple-newtype wrap when the caller passes an owned
1609 // `String` (the actual [`classify`] wire-up shape — `e.to_string()`
1610 // on a [`tatara_lisp::Error`]-carrying binding). Pins that the
1611 // `impl Into<String>` param covers the owned-`String` path with no
1612 // silent double-allocation or intermediate `&str` reslicing. Peer
1613 // of the sibling `_on_str_binding` pin above — together they close
1614 // the `impl Into<String>` bound's two authored wire-up shapes on
1615 // the ctor's substrate primitive.
1616 let reason: String = String::from("read: unexpected EOF at 3:1");
1617 let via_ctor = DialetoError::leitura(reason.clone());
1618 let via_literal = DialetoError::Leitura(reason.clone());
1619 assert_eq!(
1620 via_ctor, via_literal,
1621 "DialetoError::leitura must byte-equal the pre-lift open-coded \
1622 tuple-newtype wrap on the same owned-String fixture — a drift \
1623 here would let the ctor silently reshape the reader reason \
1624 before it reached the Leitura envelope"
1625 );
1626 let DialetoError::Leitura(routed) = via_ctor else {
1627 panic!(
1628 "DialetoError::leitura must construct the Leitura arm — \
1629 got a different variant on input {reason:?}"
1630 );
1631 };
1632 assert_eq!(
1633 routed, reason,
1634 "DialetoError::leitura must route the input {reason:?} \
1635 verbatim into the tuple-newtype payload — any wrapper-side \
1636 truncation / normalization surfaces here rather than at a \
1637 downstream diagnostic shape drift"
1638 );
1639 }
1640
1641 #[test]
1642 fn leitura_routes_reason_verbatim_across_boundary_inputs() {
1643 // Fail-before-pass-after boundary-sweep pin: the lifted
1644 // [`DialetoError::leitura`] ctor MUST route its
1645 // `reason: impl Into<String>` argument verbatim into the
1646 // [`DialetoError::Leitura`] tuple-newtype `String` payload for
1647 // every boundary-covering input — empty string, a canonical
1648 // tatara-lisp reader error, a non-ASCII reason, a
1649 // whitespace-carrying reason, a Unicode-full-width reason. Any
1650 // wrapper-side truncation, silent `.trim()`, accidental
1651 // `.to_ascii_lowercase()` normalization, or `.into()` divergence
1652 // on the ctor body surfaces here as a byte-mismatch against the
1653 // input rather than at a downstream [`DialetoError::to_string()`]
1654 // diagnostic-shape drift at a tatara-lisp-reader fallthrough
1655 // consumer far from the ctor declaration. Peer of the sibling
1656 // `cabeca_errada_routes_encontrado_verbatim_across_boundary_inputs`
1657 // pin above on the same [`DialetoError`] envelope's wrong-head
1658 // axis.
1659 for reason in [
1660 "",
1661 "unclosed paren at 1:12",
1662 "unexpected token ')'",
1663 "read: eof",
1664 " leading whitespace",
1665 "trailing whitespace ",
1666 "μnicode reason",
1667 "\u{00A0}NBSP-prefixed reason",
1668 "\u{3000}ideographic-space reason",
1669 "reason\u{2028}with-line-separator",
1670 ] {
1671 let via_ctor = DialetoError::leitura(reason);
1672 let via_literal = DialetoError::Leitura(reason.to_string());
1673 assert_eq!(
1674 via_ctor, via_literal,
1675 "DialetoError::leitura({reason:?}) must byte-equal the \
1676 open-coded tuple-newtype wrap on the same input — a \
1677 drift here would let the ctor silently normalize / \
1678 truncate the reader reason before it reached the \
1679 Leitura envelope"
1680 );
1681 let DialetoError::Leitura(routed) = via_ctor else {
1682 panic!(
1683 "DialetoError::leitura must construct the Leitura \
1684 arm — got a different variant on input {reason:?}"
1685 );
1686 };
1687 assert_eq!(
1688 routed, reason,
1689 "DialetoError::leitura must route the input {reason:?} \
1690 verbatim into the tuple-newtype payload — any \
1691 wrapper-side truncation / normalization surfaces here \
1692 rather than at a downstream diagnostic shape drift"
1693 );
1694 }
1695 }
1696
1697 #[test]
1698 fn classify_reader_error_routes_through_leitura_ctor() {
1699 // Fail-before-pass-after routing pin: [`classify`]'s
1700 // tatara-lisp-reader map-err site MUST construct its
1701 // `Err(DialetoError::…)` through the substrate-primitive
1702 // [`DialetoError::leitura`] ctor rather than through an
1703 // open-coded tuple-newtype wrap. Pre-lift the wire-up hand-rolled
1704 // a `Self::Leitura(e.to_string())` block with no compile-time
1705 // link back to the substrate primitive; a future accidental
1706 // rebrand of the ctor body (an added `.trim()` on the reader
1707 // reason, a per-arm constant prefix like `"tatara-lisp:"`, a
1708 // widening of the payload into a `(String, usize)` tuple
1709 // carrying a caret offset) would then silently split the two
1710 // paths — the ctor consumers pick up the new shape, the
1711 // open-coded wire-up does not. Pinning byte-equality between
1712 // the observed `Err` and the ctor-constructed `Err` refuses
1713 // that split at caixa-core build time rather than surfacing far
1714 // from the wire-up commit as a downstream diagnostic-consumer
1715 // split. Peer of the sibling
1716 // `classify_form_wrong_head_routes_through_cabeca_errada_ctor`
1717 // pin above on the same [`DialetoError`] envelope's wrong-head
1718 // fallthrough axis.
1719 //
1720 // The malformed sources below each name a distinct
1721 // tatara-lisp-reader failure shape (unclosed paren, stray close
1722 // paren, unterminated string), so together they sweep the
1723 // reader's rejection surface rather than pinning against one
1724 // specific error message the reader upstream is free to reword.
1725 for src in [
1726 "(defcaixa :nome \"x\"",
1727 "defcaixa :nome \"x\")",
1728 "(defcaixa :nome \"unterminated",
1729 ] {
1730 let observed = classify(src);
1731 let Err(DialetoError::Leitura(reason)) = observed.clone() else {
1732 panic!(
1733 "classify({src:?}) must return the Leitura arm — got \
1734 {observed:?}"
1735 );
1736 };
1737 let via_ctor: Result<CaixaDialeto, DialetoError> =
1738 Err(DialetoError::leitura(reason.clone()));
1739 assert_eq!(
1740 observed, via_ctor,
1741 "classify({src:?}) must return the same Err shape as \
1742 DialetoError::leitura({reason:?}) — a drift here means \
1743 the wire-up de-lifted its tatara-lisp-reader fallthrough \
1744 arm off the substrate primitive"
1745 );
1746 }
1747 }
1748
1749 #[test]
1750 fn caixa_dialeto_try_from_str_routes_through_from_wire_accessor() {
1751 // Fail-before-pass-after byte-parity pin on the lifted
1752 // `impl TryFrom<&str> for CaixaDialeto`: for every arm in
1753 // [`CaixaDialeto::ALL`], the `.try_into()` / `TryFrom::try_from`
1754 // path must resolve to the same variant the sibling
1755 // [`CaixaDialeto::from_wire`] resolver returns on the same
1756 // [`CaixaDialeto::as_str`] wire byte-string input. Pins the
1757 // three-path convergence discipline the [`CaixaDialeto`] closed-
1758 // set typed enum now carries on the `str → Self` reverse-
1759 // projection axis: `<CaixaDialeto as TryFrom<&str>>::try_from(s)`
1760 // (the newly lifted trait-idiomatic reverse projection),
1761 // `CaixaDialeto::from_wire(s)` (the substrate-primitive method-
1762 // named `Option<Self>` accessor the trait impl delegates through),
1763 // and the round-trip identity `variant.as_str() → variant`
1764 // (the four-arm closed accept-set shared between the emitter and
1765 // both reverse-projection consumers) must resolve to the same
1766 // typed [`CaixaDialeto`] discriminator on every arm.
1767 //
1768 // A future silent detour that routes the impl through a
1769 // divergent projection (a per-arm inline
1770 // `match s { "Pacote" => …, … }` re-inlining that opens a
1771 // compile-time link to the un-lifted arm-literal, a swap onto
1772 // the second-axis [`CaixaDialeto::palavra_canonica`] /
1773 // [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`]
1774 // accessors that carry distinct byte-shapes per axis, an accept-
1775 // set widening that silently accepts one axis's byte-shapes as
1776 // parseable on the other axis) trips at caixa-core test time
1777 // under `assert_eq!` rather than at a downstream
1778 // `TryFrom<&str>`-bound consumer's silent split. Peer of the
1779 // sibling
1780 // [`crate::kind::tests::caixa_kind_try_from_str_routes_through_from_wire_accessor`]
1781 // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
1782 // discriminator's reverse-projection axis — extends the trait-
1783 // idiomatic reverse-projection axis onto the seventh closed-set
1784 // fieldless typed enum on the caixa surface (the second one to
1785 // carry the paired `TryFrom<&str>` impl).
1786 for &variant in CaixaDialeto::ALL {
1787 let wire = variant.as_str();
1788 let via_try_from: CaixaDialeto = <CaixaDialeto as TryFrom<&str>>::try_from(wire)
1789 .unwrap_or_else(|()| {
1790 panic!(
1791 "CaixaDialeto::try_from({wire:?}) must accept every \
1792 CaixaDialeto::as_str output — got Err(()) for the \
1793 wire byte-string of {variant:?}"
1794 )
1795 });
1796 let via_from_wire: CaixaDialeto = CaixaDialeto::from_wire(wire).unwrap_or_else(|| {
1797 panic!(
1798 "CaixaDialeto::from_wire({wire:?}) must accept every \
1799 CaixaDialeto::as_str output — got None for the wire \
1800 byte-string of {variant:?}"
1801 )
1802 });
1803 assert_eq!(
1804 via_try_from, variant,
1805 "CaixaDialeto::try_from(CaixaDialeto::{variant:?}.as_str()) \
1806 must return CaixaDialeto::{variant:?} — the trait-idiomatic \
1807 reverse projection must land on the same arm the method-named \
1808 from_wire resolver does",
1809 );
1810 assert_eq!(
1811 via_try_from, via_from_wire,
1812 "CaixaDialeto::try_from({wire:?}) ({via_try_from:?}) must \
1813 byte-equal CaixaDialeto::from_wire({wire:?}) ({via_from_wire:?}) \
1814 on the same input — divergence signals a silent detour off the \
1815 shared substrate-primitive resolver",
1816 );
1817 assert_eq!(
1818 <CaixaDialeto as TryFrom<&str>>::try_from(wire).ok(),
1819 CaixaDialeto::from_wire(wire),
1820 "the Result::ok() projection of TryFrom<&str> must byte-equal \
1821 the sibling from_wire Option<Self> output on {wire:?} — the \
1822 two accessors must share the same accept-set and typed \
1823 outcome per arm",
1824 );
1825 }
1826 }
1827
1828 #[test]
1829 fn caixa_dialeto_try_from_str_rejects_unknown_byte_strings() {
1830 // Rejection witness on the trait-idiomatic reverse-projection
1831 // axis: any string outside the four-arm [`CaixaDialeto::as_str`]
1832 // output set must resolve to `Err(())` through the lifted
1833 // [`impl TryFrom<&str> for CaixaDialeto`]. A future accidental
1834 // widening of the accept-set (a case-insensitive match that
1835 // accepts `"pacote"` on the wire axis, a hand-rolled Levenshtein-
1836 // forgiving arm-lookup that admits `"Pacotee"` typos, a silent
1837 // acceptance of the sibling [`CaixaDialeto::palavra_canonica`]
1838 // `"defcaixa"` / `"defmolde"` byte-shapes on this axis, a swap
1839 // onto the [`CaixaDialeto::consumidor`] `"pleme-doc-gen"` /
1840 // `"caixa-core / feira"` / `"nobody known"` byte-shapes) would
1841 // silently drift the trait-idiomatic parser's accept-set from
1842 // the sibling [`CaixaDialeto::from_wire`] resolver's — a
1843 // downstream `TryFrom<&str>`-bound consumer binding a malformed
1844 // byte-string through this impl would then bind a plausibly-
1845 // wrong typed arm the caller does not route through any fallback,
1846 // silently misclassifying the reloaded row.
1847 //
1848 // Sweeps the same rejection set the sibling
1849 // [`caixa_dialeto_from_wire_rejects_unknown_byte_strings`] pin
1850 // walks (the shared `from_wire` resolver both accessors delegate
1851 // through) so the trait-idiomatic axis and the method-named axis
1852 // stay locked to the same accept-set by construction. Peer of the
1853 // sibling
1854 // [`crate::kind::tests::caixa_kind_try_from_str_rejects_unknown_byte_strings`]
1855 // (3c83606) on the top-level [`crate::CaixaKind`] closed-set
1856 // discriminator's trait-idiomatic reverse-projection axis.
1857 for bad in [
1858 "",
1859 " ",
1860 "pacote",
1861 "PACOTE",
1862 "molde",
1863 "MoldePositional",
1864 "desconhecido",
1865 "Unknown",
1866 "defcaixa",
1867 "defmolde",
1868 "?",
1869 "caixa-core / feira",
1870 "pleme-doc-gen",
1871 "nobody known",
1872 "Pacote ",
1873 " Pacote",
1874 ] {
1875 assert_eq!(
1876 <CaixaDialeto as TryFrom<&str>>::try_from(bad),
1877 Err(()),
1878 "CaixaDialeto::try_from({bad:?}) must return Err(()) — the \
1879 trait-idiomatic parser's accept-set is exactly the four \
1880 CaixaDialeto::as_str outputs; a widening would silently \
1881 split the trait-idiomatic reverse-projection axis from the \
1882 sibling from_wire resolver's arm-set"
1883 );
1884 }
1885 }
1886
1887 #[test]
1888 fn caixa_dialeto_is_molde_family_routes_through_is_variant_derived_predicates() {
1889 // Byte-parity pin on the post-lift [`CaixaDialeto::is_molde_family`]
1890 // convergence: for every arm in [`CaixaDialeto::ALL`], the typed
1891 // predicate must byte-equal the direct
1892 // `self.is_molde() || self.is_molde_posicional()` composition of
1893 // the two derived per-arm predicates. Pre-lift the predicate
1894 // hand-rolled `matches!(self, Self::Molde | Self::MoldePosicional)`
1895 // with no compile-time link back to the closed-set typed dispatch;
1896 // post-lift it routes through the derived predicates so a future
1897 // arm rename or `#[is_variant(name = "…")]` override lands at
1898 // exactly one dispatch on the substrate primitive. Pinning the
1899 // byte-equality here refuses a future accidental split between
1900 // the composed predicate and the paired derived predicates
1901 // (a hand-rolled shadow `impl` that overrides one path but not
1902 // the other, an accidental rebrand of `is_molde_family`'s body
1903 // back to the pre-lift `matches!` form) at caixa-core build time.
1904 for &d in CaixaDialeto::ALL {
1905 let via_derived = d.is_molde() || d.is_molde_posicional();
1906 let via_is_molde_family = d.is_molde_family();
1907 assert_eq!(
1908 via_is_molde_family, via_derived,
1909 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
1910 must byte-equal the composed derived predicates \
1911 is_molde() || is_molde_posicional() ({via_derived}) — a \
1912 split between the composed predicate and its derived \
1913 building blocks would let a future arm rename land at one \
1914 path and drift at the other, which is exactly the drift \
1915 the IsVariant lift refuses"
1916 );
1917 }
1918 }
1919}