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 /// The keyword an author should write for this dialect, once the
176 /// migration named in [`Self::consumidor`] completes.
177 #[must_use]
178 pub const fn palavra_canonica(self) -> &'static str {
179 match self {
180 Self::Pacote => "defcaixa",
181 Self::Molde | Self::MoldePosicional => "defmolde",
182 Self::Desconhecido => "?",
183 }
184 }
185
186 /// Who reads this dialect.
187 #[must_use]
188 pub const fn consumidor(self) -> &'static str {
189 match self {
190 Self::Pacote => "caixa-core / feira",
191 Self::Molde | Self::MoldePosicional => "pleme-doc-gen",
192 Self::Desconhecido => "nobody known",
193 }
194 }
195
196 /// A one-line description for a census row or an error message.
197 #[must_use]
198 pub const fn descricao(self) -> &'static str {
199 match self {
200 Self::Pacote => "tatara-lisp package manifest (:nome :versao :kind :deps …)",
201 Self::Molde => "repo-surface declaration (:name :ecosystem :package {…} …)",
202 Self::MoldePosicional => {
203 "repo-surface declaration, positional name (defcaixa <nome> :kind …)"
204 }
205 Self::Desconhecido => "unrecognised — matches no known defcaixa schema",
206 }
207 }
208
209 /// True when this arm belongs to the `defmolde` declaration family —
210 /// the two-arity closure of [`Self::Molde`] and [`Self::MoldePosicional`]
211 /// under the shared `defmolde` head keyword the sibling
212 /// [`Self::palavra_canonica`] projection already collapses onto
213 /// `"defmolde"` for both arms (and the sibling [`Self::consumidor`]
214 /// projection collapses onto `"pleme-doc-gen"` for the same two arms).
215 /// False on [`Self::Pacote`] (the sibling `defcaixa` tatara-lisp
216 /// package manifest, [`Self::palavra_canonica`] `→ "defcaixa"`) and
217 /// on [`Self::Desconhecido`] (the residue that names no known
218 /// declaration, [`Self::palavra_canonica`] `→ "?"`).
219 ///
220 /// The [`Self::Molde`] / [`Self::MoldePosicional`] split is one
221 /// declaration written two ways ([`Self::MoldePosicional`]'s
222 /// variant-declaration docstring at [`Self::MoldePosicional`] frames
223 /// it exactly: "the same declaration as [`Self::Molde`], written with
224 /// the package name as a bare positional symbol … this is one arity
225 /// of one declaration, not a third schema"). Every downstream gate
226 /// that keys off "does this dialect belong to the `defmolde` family"
227 /// (as distinct from the four-arm-per-arm census-counter axis the
228 /// sibling `feira dialeto` verb already fans on separately at
229 /// `caixa-feira/src/cmd/dialeto.rs:110-127`) previously hand-rolled
230 /// the two-arm collapse inline as `matches!(d, CaixaDialeto::Molde |
231 /// CaixaDialeto::MoldePosicional)` — a compile-time-anonymous
232 /// two-arm literal set with no link back to the [`CaixaDialeto`]
233 /// variant declaration nor to the sibling
234 /// [`Self::palavra_canonica`] / [`Self::consumidor`] projections
235 /// that already carry the same two-arm collapse under the shared
236 /// `defmolde` / `pleme-doc-gen` axis. The `feira dialeto` verb's
237 /// [`caixa-feira/src/cmd/dialeto.rs`] carried the same
238 /// `matches!` twice — once in the `--strict-palavra` gate that
239 /// refuses a repo-surface declaration still written as
240 /// `(defcaixa …)`, once in the wrong-declaration-under-`caixa.lisp`
241 /// gate that refuses a repo-surface declaration under the filename
242 /// `feira` loads as a package manifest — with no compile-time link
243 /// between the two hand-rolled arm sets. A future arm addition (the
244 /// module doc's "third dialect" hazard actualises as a fifth arm
245 /// [`CaixaDialeto`] that belongs to the `defmolde` declaration
246 /// family — a third arity variant, an alias-declaration family
247 /// pleme-doc-gen sharpens as its schema evolves) would silently
248 /// split the two hand-rolled `matches!` arm-sets from each other
249 /// and from the paired [`Self::palavra_canonica`] projection: one
250 /// call site picks up the new arm, one does not, and the disagreement
251 /// surfaces far from the arm-addition commit as a `feira dialeto`
252 /// consumer reporting a repo-surface declaration under one gate but
253 /// not the other. Routing every "belongs to the `defmolde` family"
254 /// predicate through this one substrate primitive closes the axis:
255 /// a future arm addition lands one match arm here (a compile-time
256 /// exhaustiveness error otherwise), not a coordinated per-`matches!`
257 /// rewrite across every caller.
258 ///
259 /// Peer of the sibling [`crate::CaixaKind::requires_lib`] (0421c22)
260 /// per-arm-set predicate on the [`crate::CaixaKind`] closed-set
261 /// discriminator's "kind requires a `lib/` surface" axis — extends
262 /// the same "one canonical typed predicate per per-arm-set gate,
263 /// one dispatch on the substrate primitive" discipline onto the
264 /// [`CaixaDialeto`] closed-set discriminator's "belongs to the
265 /// `defmolde` declaration family" axis. The dialect-classification
266 /// axis's second per-arm-set predicate (first being the implicit
267 /// palavra_canonica-through-consumidor-through-descricao arm-set
268 /// collapse already carried on the sibling projections) — the first
269 /// explicitly-typed per-arm-set predicate on the axis, matching the
270 /// discipline the sibling M2 [`crate::CaixaKind`] closed-set
271 /// discriminator already carries with `requires_lib`.
272 ///
273 /// Three consumers now route through this one typed dispatch: the
274 /// [`caixa-feira`](../../caixa_feira/cmd/dialeto/index.html) verb's
275 /// `--strict-palavra` gate (refusing a repo-surface declaration
276 /// still written as `(defcaixa …)`), the same verb's wrong-
277 /// declaration-under-`caixa.lisp` gate (refusing a repo-surface
278 /// declaration under the filename `feira` loads as a package
279 /// manifest), and [`crate::Caixa::from_lisp`]'s foreign-dialect
280 /// gate (raising [`crate::ManifestError::DialetoEstrangeiro`] before
281 /// the derive's `parse_kwargs_strict` walk on any `defmolde`-family
282 /// classification — the pre-lift hand-rolled three-arm
283 /// `match { Pacote => {}, Desconhecido => {}, foreign => Err(…) }`
284 /// literal whose `foreign =>` wildcard silently absorbed anything
285 /// non-Pacote-non-Desconhecido, now the third external consumer of
286 /// the `defmolde`-family partition).
287 #[must_use]
288 pub const fn is_molde_family(self) -> bool {
289 // Routed through the derive-generated per-arm predicates
290 // [`Self::is_molde`] + [`Self::is_molde_posicional`] so the
291 // two-arm collapse links compile-time back to the closed-set
292 // typed dispatch every peer arm-set predicate on the caixa
293 // surface (e.g. [`crate::CaixaKind::requires_lib`] on the
294 // sibling `:kind` axis) now carries. Byte-equivalent to the
295 // pre-lift `matches!(self, Self::Molde | Self::MoldePosicional)`
296 // form (the derived `is_*` predicates each expand to the same
297 // `matches!(self, Self::X)` shape by construction), but a
298 // future arm rename or IsVariant `#[is_variant(name = "…")]`
299 // override lands at exactly one dispatch on the substrate
300 // primitive rather than a hand-rolled two-arm literal.
301 self.is_molde() || self.is_molde_posicional()
302 }
303}
304
305/// [`std::fmt::Display`] routed through [`CaixaDialeto::as_str`], so the
306/// pretty-printed byte-string every consumer that formats the dialect as
307/// user-facing / census text lands on (the `feira dialeto` per-manifest
308/// `--list` row, the `feira dialeto` census summary line's per-arm
309/// counters, a future M4 admission-webhook's rejection body naming the
310/// accepted-dialect set) reaches for the same `PascalCase` per-arm
311/// byte-string the [`CaixaDialeto::as_str`] helper returns.
312///
313/// Prior to this lift the [`std::fmt::Display`] impl hand-rolled its own
314/// four-arm literal-string match — the one hand-rolled per-arm dispatch
315/// on the closed [`CaixaDialeto`] discriminator that had NO substrate
316/// primitive accessor to defer to (the sibling [`CaixaDialeto::palavra_canonica`] /
317/// [`CaixaDialeto::consumidor`] / [`CaixaDialeto::descricao`] projections
318/// carry distinct byte-shapes per axis, so none of them could serve as
319/// the Display source). A future variant addition (a fifth dialect the
320/// module doc's "third dialect" hazard actualises) would land one arm at
321/// the enum and per-arm returns at the paired accessors, but a hand-rolled
322/// [`std::fmt::Display`] match would silently drop the new arm to compile-
323/// fail-at-the-match-arm-site rather than through the shared substrate
324/// primitive. Routing [`std::fmt::Display`] through [`CaixaDialeto::as_str`]
325/// closes the last unlifted per-arm `PascalCase`-name projection on the
326/// caixa surface — the seventh (and last unlifted) closed-set fieldless
327/// typed enum on the caixa surface to converge onto the same
328/// `Display`-through-`as_str` discipline the six siblings
329/// ([`crate::CaixaKind`] / [`crate::supervisor::RestartStrategy`] /
330/// [`crate::supervisor::RestartPolicy`] /
331/// [`crate::aplicacao::PlacementStrategy`] / [`crate::aplicacao::RateLimitUnit`]
332/// / [`crate::dep::DepList`]) already carry.
333impl std::fmt::Display for CaixaDialeto {
334 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
335 f.write_str(self.as_str())
336 }
337}
338
339/// A source that is not a `(defcaixa …)` / `(defmolde …)` form at all.
340#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
341pub enum DialetoError {
342 #[error("source has no top-level form")]
343 Vazio,
344 #[error("top-level form is not a list — a manifest is `(defcaixa …)`")]
345 NaoEhLista,
346 #[error(
347 "top-level form is headed by `{encontrado}`, not `defcaixa` or `defmolde` \
348 (a manifest's first form must be the declaration itself)"
349 )]
350 CabecaErrada { encontrado: String },
351 #[error("manifest does not parse as tatara-lisp: {0}")]
352 Leitura(String),
353}
354
355/// Classify a manifest source without committing to either schema.
356///
357/// Deliberately reads only the head symbol and the set of top-level keywords —
358/// enough to route, never enough to half-parse. A classifier that started
359/// validating would grow into a third parser, which is the shape of the problem
360/// it exists to name.
361///
362/// # Errors
363/// [`DialetoError`] when the source is not a manifest declaration at all.
364pub fn classify(src: &str) -> Result<CaixaDialeto, DialetoError> {
365 let forms = tatara_lisp::read(src).map_err(|e| DialetoError::Leitura(e.to_string()))?;
366 let first = forms.first().ok_or(DialetoError::Vazio)?;
367 classify_form(first)
368}
369
370/// [`classify`] over an already-read form.
371///
372/// # Errors
373/// [`DialetoError`] when the form is not a manifest declaration.
374pub fn classify_form(form: &Sexp) -> Result<CaixaDialeto, DialetoError> {
375 let list = form.as_list().ok_or(DialetoError::NaoEhLista)?;
376 let head = list
377 .first()
378 .and_then(Sexp::as_symbol)
379 .ok_or(DialetoError::NaoEhLista)?;
380
381 match head {
382 // `defmolde` is unambiguous by construction — it exists precisely so a
383 // consumer never has to infer which declaration it holds. Both arities
384 // are the same declaration; the positional one keeps its own variant
385 // only so a census can report the split.
386 "defmolde" => {
387 return Ok(if starts_with_positional_name(&list[1..]) {
388 CaixaDialeto::MoldePosicional
389 } else {
390 CaixaDialeto::Molde
391 });
392 }
393 "defcaixa" => {}
394 other => {
395 return Err(DialetoError::CabecaErrada {
396 encontrado: other.to_string(),
397 });
398 }
399 }
400
401 let args = &list[1..];
402
403 // `(defcaixa <symbol> :kind … :ecosystem …)`. Only the Molde dialect has a
404 // positional arity; `Caixa` is keyword-only, so a leading bare symbol
405 // settles it without looking further.
406 if starts_with_positional_name(args) {
407 return Ok(CaixaDialeto::MoldePosicional);
408 }
409
410 let keys = top_level_keywords(args);
411 let has = |k: &str| keys.iter().any(|s| s == k);
412
413 // Order matters, and it is not arbitrary: `:nome` and `:name` are the two
414 // required head slots and no file in the measured corpus carries both.
415 // Checking them FIRST means the decision rests on the one slot each schema
416 // makes mandatory, rather than on optional evidence like `:ecosystem`.
417 if has("nome") {
418 return Ok(CaixaDialeto::Pacote);
419 }
420 if has("name") || has("ecosystem") || has("package") {
421 return Ok(CaixaDialeto::Molde);
422 }
423 Ok(CaixaDialeto::Desconhecido)
424}
425
426/// True when the first argument is a bare symbol rather than a keyword — the
427/// positional-name arity.
428fn starts_with_positional_name(args: &[Sexp]) -> bool {
429 matches!(args.first(), Some(Sexp::Atom(Atom::Symbol(_))))
430}
431
432/// The top-level keyword names (without the leading `:`) of a kwarg list.
433///
434/// Steps in pairs so a keyword appearing as a VALUE — `:kind :Biblioteca`, or a
435/// nested `(:nome "dep" :versao "^0.1")` inside `:deps` — is never counted as a
436/// top-level slot. A naive scan for `:nome` anywhere in the source classifies
437/// every Molde manifest with a `:deps` list as a Pacote.
438fn top_level_keywords(args: &[Sexp]) -> Vec<String> {
439 let mut out = Vec::new();
440 let mut i = 0;
441 while i < args.len() {
442 if let Sexp::Atom(Atom::Keyword(k)) = &args[i] {
443 out.push(k.clone());
444 i += 2;
445 } else {
446 i += 1;
447 }
448 }
449 out
450}
451
452#[cfg(test)]
453mod tests {
454 use super::*;
455
456 const PACOTE: &str = r#"
457 (defcaixa
458 :nome "checkout"
459 :versao "0.1.0"
460 :kind Servico
461 :deps ((:nome "caixa-teia" :versao "^0.1")))
462 "#;
463
464 const MOLDE: &str = r#"
465 (defcaixa
466 :name "base64"
467 :kind :Biblioteca
468 :ecosystem :rust-single-crate
469 :package {:name "base64" :version "0.22.1"}
470 :workflows [:auto-release])
471 "#;
472
473 const MOLDE_POSICIONAL: &str = r#"
474 (defcaixa todoku-go
475 :kind :Biblioteca
476 :ecosystem :go
477 :package {:name "todoku-go" :version "0.3.0"})
478 "#;
479
480 #[test]
481 fn the_package_dialect_is_recognised() {
482 assert_eq!(classify(PACOTE), Ok(CaixaDialeto::Pacote));
483 }
484
485 #[test]
486 fn the_repo_surface_dialect_is_recognised() {
487 assert_eq!(classify(MOLDE), Ok(CaixaDialeto::Molde));
488 }
489
490 #[test]
491 fn the_positional_arity_is_recognised() {
492 assert_eq!(
493 classify(MOLDE_POSICIONAL),
494 Ok(CaixaDialeto::MoldePosicional)
495 );
496 }
497
498 #[test]
499 fn defmolde_classifies_without_inference() {
500 // The whole point of the new keyword: no schema sniffing required.
501 let src = r#"(defmolde :name "x" :kind :Biblioteca :ecosystem :go)"#;
502 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
503 let pos = r"(defmolde todoku-go :kind :Biblioteca :ecosystem :go)";
504 assert_eq!(classify(pos), Ok(CaixaDialeto::MoldePosicional));
505 }
506
507 #[test]
508 fn a_nested_nome_does_not_make_a_repo_surface_look_like_a_package() {
509 // The exact failure a substring scan produces: `:deps ((:nome …))`
510 // contains `:nome`, but not as a top-level slot.
511 let src = r#"
512 (defcaixa
513 :name "x"
514 :ecosystem :rust-single-crate
515 :deps ((:nome "inner" :versao "^0.1")))
516 "#;
517 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
518 }
519
520 #[test]
521 fn a_keyword_in_value_position_is_not_a_slot() {
522 // `:kind :Biblioteca` — the value is itself a keyword. Stepping one at
523 // a time would read `:Biblioteca` as a top-level slot.
524 let src = r#"(defcaixa :kind :Biblioteca :name "x")"#;
525 assert_eq!(classify(src), Ok(CaixaDialeto::Molde));
526 }
527
528 #[test]
529 fn an_unrecognised_defcaixa_is_reported_not_guessed() {
530 let src = r#"(defcaixa :licenca "MIT")"#;
531 assert_eq!(classify(src), Ok(CaixaDialeto::Desconhecido));
532 }
533
534 #[test]
535 fn a_form_that_is_not_a_manifest_is_an_error_not_a_dialect() {
536 assert_eq!(
537 classify("(defflake :nome \"x\")"),
538 Err(DialetoError::CabecaErrada {
539 encontrado: "defflake".into()
540 })
541 );
542 assert_eq!(classify(""), Err(DialetoError::Vazio));
543 }
544
545 #[test]
546 fn every_dialect_names_its_consumer_and_its_canonical_keyword() {
547 // Guards the routing table itself: a new variant added without an arm
548 // here is a compile error in the match, and a variant that claims
549 // `defcaixa` while being read by pleme-doc-gen would re-open the
550 // collision this module closes. Sweeps [`CaixaDialeto::ALL`] rather
551 // than the pre-lift open-coded four-arm literal list — a future arm
552 // addition extends the slice as one edit and this pin picks it up
553 // by construction.
554 for &d in CaixaDialeto::ALL {
555 assert!(!d.descricao().is_empty(), "{d}");
556 assert!(!d.consumidor().is_empty(), "{d}");
557 }
558 assert_eq!(CaixaDialeto::Pacote.palavra_canonica(), "defcaixa");
559 assert_eq!(CaixaDialeto::Molde.palavra_canonica(), "defmolde");
560 assert_ne!(
561 CaixaDialeto::Pacote.palavra_canonica(),
562 CaixaDialeto::Molde.palavra_canonica(),
563 "the two dialects must not share a canonical keyword — that IS the defect"
564 );
565 }
566
567 #[test]
568 fn caixa_dialeto_all_enumerates_every_variant_exactly_once() {
569 // Three-legged exhaustiveness pin, peer of the sibling
570 // `caixa_kind_all_enumerates_every_variant_exactly_once`
571 // (caixa-core/src/kind.rs) /
572 // `restart_strategy_all_enumerates_every_variant_exactly_once`
573 // (caixa-core/src/supervisor.rs) shape.
574 //
575 // 1. arm-count invariant: `ALL.len()` matches the declared arm
576 // count (four — a fifth arm added without extending `ALL`
577 // fails this pin at caixa-core test time);
578 // 2. pairwise-distinctness invariant: every variant appears at
579 // most once in the slice (a duplicate arm would silently
580 // double-count in the census consumer, so the pin rejects
581 // duplicates outright);
582 // 3. coverage invariant: every literal `CaixaDialeto::X` is in
583 // the slice (the compiler-checked exhaustiveness on the peer
584 // per-arm `match self` in the accessors keeps the enum arm
585 // set and the `ALL` slice mutually aligned).
586 assert_eq!(
587 CaixaDialeto::ALL.len(),
588 4,
589 "ALL must list every arm exactly once; a fifth arm added \
590 without extending ALL fails this pin — extend ALL alongside \
591 the new variant"
592 );
593
594 let mut seen: Vec<CaixaDialeto> = Vec::new();
595 for &d in CaixaDialeto::ALL {
596 assert!(
597 !seen.contains(&d),
598 "ALL contains a duplicate arm: {d}. Every variant appears \
599 exactly once — a duplicate would double-count in every \
600 iteration consumer"
601 );
602 seen.push(d);
603 }
604
605 // Coverage: exhaustively assert every literal variant is somewhere
606 // in the slice. Written as an exhaustive `match` so a future arm
607 // addition fails to compile here (missing match arm) until the
608 // corresponding `assert` is added — the compiler enforces the pin's
609 // completeness rather than a hand-maintained variant list.
610 for variant in [
611 CaixaDialeto::Pacote,
612 CaixaDialeto::Molde,
613 CaixaDialeto::MoldePosicional,
614 CaixaDialeto::Desconhecido,
615 ] {
616 let coverage_probe = match variant {
617 CaixaDialeto::Pacote
618 | CaixaDialeto::Molde
619 | CaixaDialeto::MoldePosicional
620 | CaixaDialeto::Desconhecido => variant,
621 };
622 assert!(
623 CaixaDialeto::ALL.contains(&coverage_probe),
624 "ALL is missing variant {coverage_probe} — extend the slice"
625 );
626 }
627 }
628
629 #[test]
630 fn caixa_dialeto_all_is_const_and_matches_iteration_count() {
631 // Pins the const-ness of the slice at const-fold time. A future
632 // change that promoted `ALL` to a non-const initializer (a lazy-
633 // static, a runtime-computed Vec) would fail to compile here —
634 // the pin locks in the compile-time-known iteration surface
635 // every consumer builds against. Peer of the sibling
636 // `caixa_kind_all_is_const_and_matches_iteration_count` (kind.rs)
637 // / `restart_strategy_all_is_const_and_matches_iteration_count`
638 // (supervisor.rs) shape.
639 const ALL: &[CaixaDialeto] = CaixaDialeto::ALL;
640 assert_eq!(ALL.len(), CaixaDialeto::ALL.len());
641 // Sweep the iterator without collapsing to `.len()` so a future
642 // change to `ALL`'s carrier that decouples `.len()` from the
643 // iteration count (a lazy-computed shape, an alias `impl Iterator`
644 // return, a wrapper newtype) still passes here iff the two agree
645 // arm-for-arm; the `#[allow]` opts this local pin out of the
646 // clippy `iter_count` collapse that would defeat the intent.
647 #[allow(clippy::iter_count)]
648 let iterated = ALL.iter().count();
649 assert_eq!(iterated, CaixaDialeto::ALL.len());
650 }
651
652 #[test]
653 fn caixa_dialeto_all_covers_every_variant_by_display_probe() {
654 // Fanning `Display` over the slice sweeps the paired accessors
655 // ([`CaixaDialeto::palavra_canonica`] / [`CaixaDialeto::consumidor`]
656 // / [`CaixaDialeto::descricao`]) at every arm — every returned
657 // byte-string is non-empty (the accessors' contract). A future
658 // arm added without extending its per-arm `match self` return
659 // would compile-fail at the accessor call inside the loop;
660 // together with the `ALL.len() == 4` pin above, this locks the
661 // accessor arm-set and the `ALL` slice mutually.
662 for &d in CaixaDialeto::ALL {
663 let display_form = d.to_string();
664 assert!(
665 !display_form.is_empty(),
666 "Display must render a non-empty byte-string for every \
667 arm; empty: {d:?}"
668 );
669 // Consumidor / descricao / palavra-canonica must each surface
670 // a non-empty scalar; every downstream diagnostic consumer
671 // reaches through these accessors.
672 assert!(!d.palavra_canonica().is_empty(), "{d}");
673 assert!(!d.consumidor().is_empty(), "{d}");
674 assert!(!d.descricao().is_empty(), "{d}");
675 }
676 }
677
678 #[test]
679 fn caixa_dialeto_as_str_returns_pascal_case_variant_name() {
680 // Fail-before-pass-after per-arm shape pin: the four
681 // [`CaixaDialeto::as_str`] arms must return the canonical
682 // `PascalCase` byte-string that names the variant. Pre-lift this
683 // byte-string existed only inside the hand-rolled Display impl's
684 // four-arm literal-string match — every consumer that wanted the
685 // `PascalCase` name reached through `format!("{d}")`'s allocation
686 // path. Pinning the four arms explicitly here refuses a future
687 // regression that ever reroutes an arm to a distinct spelling
688 // (`"pacote"` lowercase, `"MoldePositional"` English rebrand,
689 // `"Unknown"` for `Desconhecido`) — the census output and the
690 // typed accessor would silently disagree until a downstream
691 // consumer surfaced the drift at census time. Peer of the sibling
692 // [`crate::supervisor::tests::restart_strategy_variants_serialize_to_lifted_scalar_values`]
693 // / `placement_strategy_variants_serialize_to_lifted_scalar_values`
694 // / `caixa_kind_as_str_returns_lifted_peer_const` shape on the
695 // sibling closed-set typed-enum discriminator axes — the seventh
696 // (and last unlifted) closed-set typed enum on the caixa surface
697 // to converge onto the same per-arm-shape-pin discipline.
698 for (variant, expected) in [
699 (CaixaDialeto::Pacote, "Pacote"),
700 (CaixaDialeto::Molde, "Molde"),
701 (CaixaDialeto::MoldePosicional, "MoldePosicional"),
702 (CaixaDialeto::Desconhecido, "Desconhecido"),
703 ] {
704 assert_eq!(
705 variant.as_str(),
706 expected,
707 "CaixaDialeto::{variant:?}.as_str() must return the \
708 canonical `PascalCase` variant-name byte-string; drift here \
709 splits the census-facing text from the substrate \
710 primitive every downstream consumer will read"
711 );
712 }
713 }
714
715 #[test]
716 fn caixa_dialeto_display_routes_through_as_str_helper() {
717 // Fail-before-pass-after convergence pin: for every arm in
718 // [`CaixaDialeto::ALL`], the [`std::fmt::Display`] rendered form
719 // must byte-equal [`CaixaDialeto::as_str`]'s return value. Pre-
720 // lift these two paths were structurally independent — the
721 // Display impl hand-rolled its own four-arm literal-string
722 // match with no compile-time link back to any substrate accessor
723 // — so a future variant rename could land at `Display` without
724 // touching a paired accessor (or vice versa), silently splitting
725 // the two paths on the renamed arm. Pinning the byte-equality
726 // here makes any such split a caixa-core build-time failure at
727 // this test rather than surfacing far from the rename commit as
728 // a downstream census consumer emitting one spelling while the
729 // typed accessor returned another. Peer of the sibling
730 // [`crate::kind::tests::caixa_kind_display_routes_through_as_str_helper`]
731 // (which pins the same convergence on the [`crate::CaixaKind`]
732 // closed-set axis) — extends the discipline onto the seventh
733 // (and last unlifted) closed-set fieldless typed enum on the
734 // caixa surface.
735 for &variant in CaixaDialeto::ALL {
736 assert_eq!(
737 variant.to_string(),
738 variant.as_str(),
739 "CaixaDialeto::{variant:?} Display must route through \
740 CaixaDialeto::as_str (single source of truth: the \
741 lifted per-arm `PascalCase` variant-name byte-string)"
742 );
743 }
744 }
745
746 #[test]
747 fn caixa_dialeto_is_molde_family_returns_true_on_molde_and_positional_arms() {
748 // Fail-before-pass-after per-arm shape pin on the two `defmolde`
749 // declaration-family arms: [`CaixaDialeto::is_molde_family`] must
750 // return `true` for [`CaixaDialeto::Molde`] and
751 // [`CaixaDialeto::MoldePosicional`] — the two-arity closure of
752 // one declaration ([`CaixaDialeto::MoldePosicional`]'s docstring:
753 // "same declaration as [`Self::Molde`], written with the package
754 // name as a bare positional symbol … one arity of one
755 // declaration, not a third schema"). A future accidental flip that
756 // reversed a per-arm arm's return without touching the paired
757 // false-arm pin would silently open the substrate primitive to
758 // false-positive on either arm — the `feira dialeto` verb's
759 // `--strict-palavra` gate would then silently accept
760 // repo-surface declarations under `(defcaixa …)` on one arm and
761 // reject them on the other. Pinning the two true arms explicitly
762 // here refuses that split at caixa-core build time.
763 assert!(
764 CaixaDialeto::Molde.is_molde_family(),
765 "CaixaDialeto::Molde.is_molde_family() must return true — \
766 Molde is the primary `defmolde` arm"
767 );
768 assert!(
769 CaixaDialeto::MoldePosicional.is_molde_family(),
770 "CaixaDialeto::MoldePosicional.is_molde_family() must return \
771 true — MoldePosicional is the positional-arity form of the \
772 same `defmolde` declaration Molde carries"
773 );
774 }
775
776 #[test]
777 fn caixa_dialeto_is_molde_family_returns_false_on_pacote_and_desconhecido_arms() {
778 // Fail-before-pass-after per-arm shape pin on the two non-`defmolde`
779 // arms: [`CaixaDialeto::is_molde_family`] must return `false` for
780 // [`CaixaDialeto::Pacote`] (the sibling `defcaixa` tatara-lisp
781 // package manifest, `palavra_canonica → "defcaixa"`) and for
782 // [`CaixaDialeto::Desconhecido`] (the residue that names no
783 // known declaration, `palavra_canonica → "?"`). Pinning the two
784 // false arms explicitly here refuses a future accidental flip
785 // that let the predicate widen to include either arm — the
786 // `feira dialeto` verb's `--strict-palavra` gate would then
787 // spuriously refuse every `(defcaixa …)` package manifest as if
788 // it were a repo-surface declaration.
789 assert!(
790 !CaixaDialeto::Pacote.is_molde_family(),
791 "CaixaDialeto::Pacote.is_molde_family() must return false — \
792 Pacote is the `defcaixa` tatara-lisp package manifest, not \
793 the `defmolde` repo-surface declaration"
794 );
795 assert!(
796 !CaixaDialeto::Desconhecido.is_molde_family(),
797 "CaixaDialeto::Desconhecido.is_molde_family() must return \
798 false — the residue arm names no known declaration; it is \
799 not silently promoted into the `defmolde` family"
800 );
801 }
802
803 #[test]
804 fn caixa_dialeto_is_molde_family_agrees_with_palavra_canonica_defmolde_projection() {
805 // Load-bearing pin: for every arm in [`CaixaDialeto::ALL`], the
806 // typed [`CaixaDialeto::is_molde_family`] predicate must agree
807 // byte-for-byte with the paired [`CaixaDialeto::palavra_canonica`]
808 // projection's `== "defmolde"` classifier — i.e. the two paths
809 // partition the four-arm discriminator set into the same
810 // `{Molde, MoldePosicional}` and `{Pacote, Desconhecido}` halves.
811 // Pre-lift the sibling [`CaixaDialeto::palavra_canonica`] projection
812 // (which returns `"defmolde"` for `Molde | MoldePosicional`,
813 // `"defcaixa"` for `Pacote`, `"?"` for `Desconhecido`) was the
814 // only substrate-side surface carrying the two-arm collapse; the
815 // hand-rolled `matches!(d, CaixaDialeto::Molde |
816 // CaixaDialeto::MoldePosicional)` sites in the `feira dialeto`
817 // verb expressed no compile-time link back to it. A future arm
818 // addition — the module doc's "third dialect" hazard actualises
819 // as a fifth arm belonging to the `defmolde` family — would land
820 // one match arm at [`Self::palavra_canonica`]'s `defmolde` return
821 // (extending the sibling projection) but silently split the
822 // hand-rolled two-arm `matches!` predicate sites if the new arm's
823 // `is_molde_family` return were forgotten. Pinning byte-equality
824 // between the two paths here makes any such split a caixa-core
825 // build-time failure at this test rather than surfacing far from
826 // the arm-addition commit as a downstream `--strict-palavra` /
827 // `caixa.lisp`-holds-wrong-declaration gate silently ignoring the
828 // new arm.
829 for &d in CaixaDialeto::ALL {
830 let via_palavra_canonica = d.palavra_canonica() == "defmolde";
831 let via_is_molde_family = d.is_molde_family();
832 assert_eq!(
833 via_is_molde_family, via_palavra_canonica,
834 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
835 must agree with CaixaDialeto::{d:?}.palavra_canonica() == \
836 \"defmolde\" ({via_palavra_canonica}) — a split between the \
837 typed predicate and the sibling keyword projection would let \
838 a future arm addition land at one path and drift at the other, \
839 which is exactly the drift this pin refuses"
840 );
841 }
842 }
843
844 #[test]
845 fn caixa_dialeto_is_molde_family_is_const_fn() {
846 // Const-context pin: [`CaixaDialeto::is_molde_family`] must remain
847 // `const fn` (its match is a fieldless-arm literal-pattern
848 // discriminator, so no non-const operation exists on the resolution
849 // path). Downstream consumers reaching for the predicate from a
850 // `const` context (a future substrate-wide const-fold-driven audit
851 // table that materializes per-arm gate-membership at build time,
852 // a per-arm CR-admission-webhook gate registration in a `const`
853 // context) rely on the const-ness. A future accidental downgrade
854 // to non-`const` (an added runtime helper reachable only from a
855 // non-`const` context) trips at caixa-core build time rather than
856 // surfacing as a downstream `const`-context regression far from
857 // the predicate declaration. Peer of the sibling
858 // [`caixa_dialeto_as_str_is_const_fn`] pin on the paired
859 // [`CaixaDialeto::as_str`] byte-string axis.
860 const ARMS: [(CaixaDialeto, bool); 4] = [
861 (CaixaDialeto::Pacote, CaixaDialeto::Pacote.is_molde_family()),
862 (CaixaDialeto::Molde, CaixaDialeto::Molde.is_molde_family()),
863 (
864 CaixaDialeto::MoldePosicional,
865 CaixaDialeto::MoldePosicional.is_molde_family(),
866 ),
867 (
868 CaixaDialeto::Desconhecido,
869 CaixaDialeto::Desconhecido.is_molde_family(),
870 ),
871 ];
872 // Materialize the const-fold-evaluated table into a runtime slice
873 // assertion — carries the same `bool = const fn call` shape a raw
874 // `assert!(const_bool)` would, without tripping the
875 // `assertions_on_constants` clippy lint that a per-arm
876 // `assert!(CONST)` on a `const bool` triggers when the arm-count
877 // is enumerated flat rather than compared as a whole-table shape.
878 assert_eq!(
879 ARMS,
880 [
881 (CaixaDialeto::Pacote, false),
882 (CaixaDialeto::Molde, true),
883 (CaixaDialeto::MoldePosicional, true),
884 (CaixaDialeto::Desconhecido, false),
885 ],
886 "CaixaDialeto::is_molde_family() must evaluate in const context \
887 for every arm and land on the {{false, true, true, false}} \
888 partition — a future accidental downgrade to non-`const` \
889 would trip the const-context array-initializer here"
890 );
891 }
892
893 #[test]
894 fn caixa_dialeto_as_str_is_const_fn() {
895 // Const-context pin: [`CaixaDialeto::as_str`] must remain
896 // `const fn` (its match arms return `pub const` byte-strings, so
897 // no non-const operation exists on the resolution path).
898 // Downstream consumers reaching for the accessor from a `const`
899 // context (a future substrate-wide const-fold-driven audit table
900 // that materializes every dialect's census label at build time,
901 // a per-arm CR-admission-webhook message registration in a
902 // `const` gate) rely on the const-ness. A future accidental
903 // downgrade to non-`const` (an added runtime helper reachable
904 // only from a non-`const` context, a manual hand-rolled `impl`
905 // that shadows this method) trips at caixa-core build time
906 // rather than surfacing as a downstream `const`-context
907 // regression far from the accessor declaration. Peer of the
908 // sibling [`crate::kind::tests::caixa_kind_wire_name_is_const_fn`]
909 // pin on the paired [`crate::CaixaKind`] byte-string axis.
910 const PACOTE: &str = CaixaDialeto::Pacote.as_str();
911 const MOLDE: &str = CaixaDialeto::Molde.as_str();
912 const MOLDE_POSICIONAL: &str = CaixaDialeto::MoldePosicional.as_str();
913 const DESCONHECIDO: &str = CaixaDialeto::Desconhecido.as_str();
914 assert_eq!(PACOTE, "Pacote");
915 assert_eq!(MOLDE, "Molde");
916 assert_eq!(MOLDE_POSICIONAL, "MoldePosicional");
917 assert_eq!(DESCONHECIDO, "Desconhecido");
918 }
919
920 #[test]
921 fn caixa_dialeto_is_variant_predicates_partition_the_arm_set() {
922 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
923 // derive: for each of the four variants at [`CaixaDialeto::ALL`]`[idx]`
924 // the observed four-slot predicate row must equal a one-hot row
925 // with the `true` at exactly `idx`. Pre-derive the closed four-arm
926 // dialect-classification partition lived only inside the paired
927 // per-arm projections' four-arm match resolvers ([`Self::as_str`] /
928 // [`Self::palavra_canonica`] / [`Self::consumidor`] /
929 // [`Self::descricao`]) plus the two-arm [`Self::is_molde_family`]
930 // hand-rolled `matches!` (now routed through the derived
931 // predicates); a future rebrand (an accidental
932 // `#[is_variant(name = "…")]` drift, a manual hand-rolled `impl`
933 // that shadows the derive-generated method, an arm rename that
934 // reroutes one arm through the wrong predicate lane) trips this
935 // pin at caixa-core build time rather than surfacing far from the
936 // derive declaration as a downstream [`Self::is_molde_family`]
937 // consumer accepting the wrong arm-set. The expected row is
938 // generated live from the [`Self::ALL`] declaration order rather
939 // than transcribed by hand so a copy-paste flip reroutes at the
940 // identity-diagonal assertion.
941 //
942 // Peer of the sibling
943 // [`crate::kind::tests::caixa_kind_is_variant_predicates_partition_the_arm_set`]
944 // / [`crate::supervisor::tests::restart_strategy_is_variant_predicates_partition_the_arm_set`]
945 // / [`crate::aplicacao::tests::placement_strategy_is_variant_predicates_partition_the_arm_set`]
946 // / [`crate::upgrade::tests::upgrade_instruction_is_variant_predicates_partition_the_arm_set`]
947 // pins on the sibling closed-set typed-enum discriminator axes.
948 for (idx, &variant) in CaixaDialeto::ALL.iter().enumerate() {
949 let observed = [
950 variant.is_pacote(),
951 variant.is_molde(),
952 variant.is_molde_posicional(),
953 variant.is_desconhecido(),
954 ];
955 let mut expected = [false; 4];
956 expected[idx] = true;
957 assert_eq!(
958 observed, expected,
959 "CaixaDialeto::{variant:?} at ALL[{idx}] is_* predicates \
960 must fire only on their own arm lane (identity diagonal); \
961 got {observed:?}",
962 );
963 }
964 }
965
966 #[test]
967 fn caixa_dialeto_is_variant_predicates_are_const_fn() {
968 // The [`gen_platform::IsVariant`] derive emits `const fn`
969 // predicates on the peer [`crate::CaixaKind`] +
970 // [`crate::upgrade::UpgradeInstruction`] +
971 // [`crate::supervisor::RestartStrategy`] +
972 // [`crate::supervisor::RestartPolicy`] +
973 // [`crate::aplicacao::PlacementStrategy`] +
974 // [`crate::aplicacao::RateLimitUnit`] +
975 // [`crate::dep::DepList`] closed-set typed enums — pin the same
976 // posture on [`CaixaDialeto`] so a future accidental downgrade
977 // to non-`const` (an added runtime helper reachable only from a
978 // non-`const` context, a manual hand-rolled `impl` that shadows
979 // the derive-generated method) trips at caixa-core build time
980 // rather than surfacing as a downstream `const`-context
981 // regression far from the derive declaration.
982 // Use `const { assert!(…) }` (peer of the sibling
983 // [`crate::render::PathShapeViolation`] +
984 // [`crate::aplicacao::RateLimitUnit`] +
985 // [`caixa_theme::style::Semantic`] const-fn pins) so the
986 // const-context evaluation trips at const-fold time without
987 // opening a per-`const bool` `assertions_on_constants` clippy
988 // debt row this crate does not carry today for `dialeto.rs`.
989 const { assert!(CaixaDialeto::Pacote.is_pacote()) };
990 const { assert!(CaixaDialeto::Molde.is_molde()) };
991 const { assert!(CaixaDialeto::MoldePosicional.is_molde_posicional()) };
992 const { assert!(CaixaDialeto::Desconhecido.is_desconhecido()) };
993 }
994
995 #[test]
996 fn caixa_dialeto_is_molde_family_routes_through_is_variant_derived_predicates() {
997 // Byte-parity pin on the post-lift [`CaixaDialeto::is_molde_family`]
998 // convergence: for every arm in [`CaixaDialeto::ALL`], the typed
999 // predicate must byte-equal the direct
1000 // `self.is_molde() || self.is_molde_posicional()` composition of
1001 // the two derived per-arm predicates. Pre-lift the predicate
1002 // hand-rolled `matches!(self, Self::Molde | Self::MoldePosicional)`
1003 // with no compile-time link back to the closed-set typed dispatch;
1004 // post-lift it routes through the derived predicates so a future
1005 // arm rename or `#[is_variant(name = "…")]` override lands at
1006 // exactly one dispatch on the substrate primitive. Pinning the
1007 // byte-equality here refuses a future accidental split between
1008 // the composed predicate and the paired derived predicates
1009 // (a hand-rolled shadow `impl` that overrides one path but not
1010 // the other, an accidental rebrand of `is_molde_family`'s body
1011 // back to the pre-lift `matches!` form) at caixa-core build time.
1012 for &d in CaixaDialeto::ALL {
1013 let via_derived = d.is_molde() || d.is_molde_posicional();
1014 let via_is_molde_family = d.is_molde_family();
1015 assert_eq!(
1016 via_is_molde_family, via_derived,
1017 "CaixaDialeto::{d:?}.is_molde_family() ({via_is_molde_family}) \
1018 must byte-equal the composed derived predicates \
1019 is_molde() || is_molde_posicional() ({via_derived}) — a \
1020 split between the composed predicate and its derived \
1021 building blocks would let a future arm rename land at one \
1022 path and drift at the other, which is exactly the drift \
1023 the IsVariant lift refuses"
1024 );
1025 }
1026 }
1027}