Skip to main content

caixa_core/
dep.rs

1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4/// A single dependency declaration in a `caixa.lisp` manifest.
5///
6/// **Store model = Git, like Zig.** There is no central registry; a caixa is
7/// just a Git repo with a `caixa.lisp` at its root. When `:fonte` is omitted,
8/// the resolver falls back to `github:<default-org>/<nome>` (org defaults to
9/// `pleme-io`, override via `~/.config/caixa/config.yaml`).
10///
11/// ```lisp
12/// ;; Shorthand — resolves to github:pleme-io/caixa-teia (or your default org):
13/// (:nome "caixa-teia" :versao "^0.1")
14///
15/// ;; Explicit git source:
16/// (:nome "caixa-teia"
17///  :versao "^0.1"
18///  :fonte (:tipo git :repo "github:pleme-io/caixa-teia" :tag "v0.1.0"))
19///
20/// ;; Arbitrary git URL (not limited to GitHub):
21/// (:nome "private-caixa"
22///  :versao "*"
23///  :fonte (:tipo git :repo "ssh://git@git.example/team/priv-caixa.git" :branch "main"))
24///
25/// ;; Local path (dev only; not publishable):
26/// (:nome "caixa-teia"
27///  :versao "0.1.0"
28///  :fonte (:tipo path :caminho "../caixa-teia"))
29/// ```
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
31#[serde(rename_all = "camelCase")]
32pub struct Dep {
33    /// Caixa name — must match the target caixa's `:nome`.
34    pub nome: String,
35
36    /// Semver constraint string (`"^0.1"`, `"~0.1.2"`, `"0.1.0"`, `"*"`).
37    pub versao: String,
38
39    /// Where to fetch the caixa from. Defaults to the feira registry.
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub fonte: Option<DepSource>,
42
43    /// If true, a missing `:fonte` is not a build failure.
44    #[serde(default, skip_serializing_if = "is_false")]
45    pub opcional: bool,
46
47    /// Feature flags to enable on the target caixa.
48    #[serde(default, skip_serializing_if = "Vec::is_empty")]
49    pub caracteristicas: Vec<String>,
50}
51
52/// Where a dep is fetched from. Tagged via `:tipo` in Lisp.
53///
54/// Only two shapes — Git and local Path. No central registry variant: a caixa
55/// is just a Git repo. Omitting `:fonte` means *"use the default resolver
56/// convention"*, which is `github:<default-org>/<nome>`; the resolver fills
57/// that in when computing the lacre.
58///
59/// The [`gen_platform::IsVariant`] derive emits per-arm arm-discriminator
60/// predicates — [`Self::is_git`], [`Self::is_path`] — so every downstream
61/// consumer that only needs the arm-discriminator projection (not the
62/// borrowed field value) reaches for one typed dispatch on the substrate
63/// primitive rather than a hand-rolled `matches!(s, DepSource::X { .. })`
64/// literal. Extends the closed-set-typed-enum discipline the sibling
65/// caixa-core enums ([`crate::CaixaKind`], [`crate::CaixaDialeto`],
66/// [`crate::supervisor::RestartStrategy`], [`crate::supervisor::RestartPolicy`],
67/// [`crate::upgrade::UpgradeInstruction`], [`crate::aplicacao::PlacementStrategy`],
68/// [`crate::aplicacao::RateLimitUnit`], [`crate::aplicacao::WitTarget`],
69/// [`crate::render::PathShapeViolation`], [`DepList`]) and the sibling
70/// out-of-crate enums (caixa-arch's `InvariantKind` + `ArchVerdict`,
71/// caixa-lint's `Severity` + `FixSafety`, caixa-provedor's
72/// `FerriteRuntime`, caixa-theme's `Semantic`, caixa-flux's `GitRefSpec`,
73/// caixa-ast's `NodeKind` + `TriviaKind`) already carry onto the
74/// two-arm `:fonte` dep-source axis — the 17th closed-set typed enum
75/// on the caixa surface, and the first on the outer-`Dep` `:fonte`-slot
76/// axis every git-fetching consumer runs after the outer `:fonte` slot
77/// resolves to a shape.
78#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, gen_platform::IsVariant)]
79#[serde(tag = "tipo", rename_all = "lowercase")]
80pub enum DepSource {
81    /// Clone from Git. One of `:tag`, `:rev`, or `:branch` may be set.
82    /// `repo` can be a `github:org/repo` shorthand, a full `https://…` URL,
83    /// or any git-ssh URL.
84    Git {
85        repo: String,
86        #[serde(default, skip_serializing_if = "Option::is_none")]
87        tag: Option<String>,
88        #[serde(default, skip_serializing_if = "Option::is_none")]
89        rev: Option<String>,
90        #[serde(default, skip_serializing_if = "Option::is_none")]
91        branch: Option<String>,
92    },
93    /// Local filesystem path — dev only; cannot be published.
94    Path { caminho: String },
95}
96
97impl DepSource {
98    /// Build a registry-shorthand git source (`github:<org>/<nome>`).
99    ///
100    /// This is the resolver-side fallback for `dep.fonte: None`, not an
101    /// author-surface value — it carries no pin (`:tag`/`:rev`/`:branch`
102    /// all `None`) and is therefore rejected by [`Self::validate`]. The
103    /// resolver fills the pin in at fetch time from the resolved commit;
104    /// authors never serialize this shape as a `Dep::fonte` value.
105    #[must_use]
106    pub fn default_github(org: &str, nome: &str) -> Self {
107        Self::Git {
108            repo: format!("github:{org}/{nome}"),
109            tag: None,
110            rev: None,
111            branch: None,
112        }
113    }
114
115    /// Substrate-canonical per-`:fonte` sole-set git-pin scalar accessor
116    /// every consumer that reads "which single git ref does this source
117    /// resolve to?" keys off — returns the author-declared `:tag` /
118    /// `:rev` / `:branch` byte-string verbatim as an `Option<&str>`,
119    /// borrowed from the typed slot's own `Option<String>` storage; `None`
120    /// on [`Self::Path`] (a path source carries no git-ref) and on a
121    /// [`Self::Git`] variant whose `tag`, `rev`, and `branch` are all
122    /// `None` (the [`Self::default_github`] shorthand shape the resolver
123    /// materializes when the author omits `:fonte` — rejected by
124    /// [`Self::validate`], but the accessor's return is defined on this
125    /// arm too so pre-validate consumers reach for the same typed dispatch
126    /// as post-validate ones).
127    ///
128    /// **Precedence: rev > tag > branch.** The canonical precedence every
129    /// per-`:fonte` git-ref consumer already applies: caixa-resolver's
130    /// per-fetch `git checkout <ref>` reads through the same
131    /// `rev.or(tag).or(branch)` cascade at caixa-resolver/src/resolve.rs,
132    /// and caixa-crd's `dep_into_ref` `CaixaSource.git_ref` fill reads
133    /// through the same cascade at caixa-crd/src/conversion.rs. The
134    /// [`Self::validate`] gate enforces "exactly one pin set" — under
135    /// that invariant every accepted [`Self::Git`] carries exactly one
136    /// non-`None` pin and the precedence is unobservable, but the
137    /// precedence remains defined for pre-validate consumers (the
138    /// resolver's `MissingPin` diagnostic path, the caixa-crd
139    /// round-trip's default `"main"` fallback the author never sees a
140    /// diagnostic on) and defense-in-depth for a hypothetical future
141    /// state where multiple pins survive the gate. The precedence is
142    /// **rev before tag** because `:rev` (a git commit OID) is the
143    /// reproducibility-strongest identifier — an OID resolves to exactly
144    /// one commit regardless of which refname points at it, whereas
145    /// `:tag` and `:branch` are refnames the remote can silently move
146    /// (a tag re-push, a branch head advance); the resolver's freeze
147    /// step at fetch time promotes the resolved commit to `:rev` for
148    /// exactly this reason. **Tag before branch** because `:tag` is
149    /// conventionally immutable (a release tag) whereas `:branch` is
150    /// conventionally mutable (a tracking ref) — a caixa carrying both
151    /// a release tag and a tracking branch reads as "prefer the release
152    /// pin, fall through to the tracking pin only if the release is
153    /// missing". The cascade order also matches the byte-order every
154    /// per-`:tag`/`:rev`/`:branch` diagnostic tuple this crate emits
155    /// (`(":tag", tag), (":rev", rev), (":branch", branch)` — see
156    /// [`Self::validate`]'s `pins` array).
157    ///
158    /// Prior to this lift the "sole set pin" projection sat twice in the
159    /// workspace — inline at caixa-resolver's `fetch_git` (`let gitref =
160    /// rev.or(tag).or(branch).ok_or_else(|| ResolveError::MissingPin
161    /// { … })?;`) and at caixa-crd's `dep_into_ref`
162    /// (`git_ref: rev.clone().or(tag.clone()).or(branch.clone())
163    /// .unwrap_or_else(|| "main".to_string())`) — two open-coded copies
164    /// of the same precedence cascade with no compile-time link back to
165    /// the typed slot. A future extension of the pin axis to a richer
166    /// author surface (a `:commit` pin peer of `:rev` once the substrate
167    /// grows a signed-commit-verification pin, a `:ref` pin the M4
168    /// substrate operator resolves per-cluster ahead of fetch, a
169    /// promotion of the plain `Option<String>` pins to a typed
170    /// `GitPin::{Rev(Oid), Tag(RefName), Branch(RefName)}` newtype
171    /// once the sibling [`crate::render::is_git_oid`] /
172    /// [`crate::render::is_git_ref_name`] gates land as typed
173    /// constructors) would have had to be threaded through both
174    /// open-coded copies in lockstep or the resolver's `git checkout`
175    /// target would silently disagree with the CRD's `git_ref` fill —
176    /// an author's `(:fonte (:tipo git :repo "…" :rev "deadbeef" :tag
177    /// "v1"))` would ship with the resolver checking out `deadbeef`
178    /// while the CRD round-trip re-emitted a Dep pointing at `v1`, one
179    /// lacre closure disagreeing with the emitted K8s CR the operator
180    /// reads. Lifting the resolution to a typed method on the substrate
181    /// primitive means both downstream consumers reach for exactly one
182    /// typed dispatch — the resolver's accept-set migrates as a unit on
183    /// any future pin-axis addition.
184    ///
185    /// Peer of the sibling outer-`Dep` [`Dep::fonte`] (d65d1bf)
186    /// `Option<&DepSource>` composite-reference accessor on the outer-
187    /// `Dep` `:fonte`-slot axis — extended one nesting level down onto
188    /// the per-[`Self::Git`]-variant sole-set-pin projection axis every
189    /// git-fetching consumer runs after the outer `:fonte` slot resolves
190    /// to a [`Self::Git`] shape. Same "one typed dispatch on the
191    /// substrate primitive, thin projections at each consumer" discipline
192    /// the outer accessor family already carries.
193    #[must_use]
194    pub fn sole_pin(&self) -> Option<&str> {
195        match self {
196            Self::Git {
197                tag, rev, branch, ..
198            } => rev.as_deref().or(tag.as_deref()).or(branch.as_deref()),
199            Self::Path { .. } => None,
200        }
201    }
202
203    /// Validate the `:fonte` value-shape: every author-surface
204    /// `:fonte (:tipo git …)` must carry a non-empty `:repo` and
205    /// exactly one of `:tag` / `:rev` / `:branch` set to a non-empty
206    /// value; every `:fonte (:tipo path …)` must carry a non-empty
207    /// `:caminho`.
208    ///
209    /// Called from [`Dep::validate`] with the dep's `:nome` so every
210    /// diagnostic carries the offending entry verbatim — same
211    /// self-locating shape the `:deps :versao` (2420c44),
212    /// `:membros :versao` (9888b13), `:children :versao` (b38ff3a),
213    /// `:placement :clusters` (6cbb900), and `:membros :caixa`
214    /// (3f9d7a0) gates already expose.
215    ///
216    /// Until this gate landed `:fonte` was the only `:deps`-related
217    /// typed surface still untyped past `Caixa::from_lisp`:
218    /// - Empty `:repo` (`(:tipo git :repo "" :tag "v1")`) silently
219    ///   passed parse and surfaced as a git-clone failure at
220    ///   lacre-resolve time, far from the source caixa.lisp.
221    /// - A bare `(:tipo git :repo "…")` with no `:tag`/`:rev`/`:branch`
222    ///   passed parse and surfaced as the resolver's
223    ///   [`ResolveError::MissingPin`](../../caixa-resolver/src/resolve.rs)
224    ///   at fetch time, again far from the source caixa.lisp; lifting
225    ///   to validate-time gives the author the same diagnostic at the
226    ///   edit site.
227    /// - `(:tipo git :repo "…" :tag "v1" :branch "main")` — multiple
228    ///   pins set — passed parse and the resolver silently picked
229    ///   `:rev > :tag > :branch`, ignoring the other pins with no
230    ///   diagnostic; the author had no way to know their `:branch`
231    ///   was dropped. This is the canonical "pin drift" footgun.
232    /// - An empty pin value (`(:tipo git :repo "…" :tag "")`) silently
233    ///   passed parse and surfaced as `git checkout ""` at fetch time.
234    /// - Empty `:caminho` (`(:tipo path :caminho "")`) silently passed
235    ///   parse and surfaced as
236    ///   [`ResolveError::MissingPath`](../../caixa-resolver/src/resolve.rs)
237    ///   with `path: PathBuf("")` — not actionable.
238    ///
239    /// Each rejected shape maps to a typed
240    /// [`DepError::Fonte*`] variant that names the offending
241    /// dep's `:nome` and the specific axis, so the author can grep
242    /// their caixa.lisp for the `:nome "<nome>"` block and fix it in
243    /// one edit.
244    pub fn validate(&self, nome: &str) -> Result<(), DepError> {
245        match self {
246            Self::Git {
247                repo,
248                tag,
249                rev,
250                branch,
251            } => {
252                if repo.is_empty() {
253                    return Err(DepError::FonteRepoEmpty {
254                        nome: nome.to_string(),
255                    });
256                }
257                // The `:repo` value flows verbatim into the caixa-resolver's
258                // `git clone <repo>` subprocess invocation. Until this gate
259                // landed `:repo` was the last untyped `:fonte`-related axis
260                // past the empty arm: a malformed-but-non-empty repo URL
261                // (`":repo "github:p/x ""` trailing space, paste-from-doc;
262                // `":repo "-upload-pack=evil""` leading `-` — the canonical
263                // CLI-argument-injection vector at the `git clone` boundary;
264                // `":repo "pleme-io/caixa-teia""` missing scheme — `git clone`
265                // reads as a relative filesystem path rather than the
266                // GitHub-shorthand expansion; `":repo "github:p/x\n""`
267                // embedded newline; `":repo "github:café/x""` raw non-ASCII)
268                // silently passed validate and the failure surfaced at
269                // lacre-resolve time with a porcelain-quoting-confused error
270                // far from the source caixa.lisp. The lifted predicate makes
271                // the git-porcelain-URL intersection-floor a substrate-level
272                // invariant at validate time, peer with the three pin axes
273                // (`:tag` + `:branch` via [`crate::render::is_git_ref_name`],
274                // e70d213; `:rev` via [`crate::render::is_git_oid`], be07fd5)
275                // — every `:fonte (:tipo git …)` past validate is now
276                // structurally accept-shaped on every axis the resolver
277                // consumes (the `:repo` URL the `git clone` invokes against,
278                // the `:tag`/`:branch` refname `git fetch`/`git checkout`
279                // accepts, the `:rev` commit OID the lacre's content-
280                // addressing equality probe resolves), closing the
281                // `:fonte` slot's value-shape trajectory end-to-end.
282                if let Err(reason) = crate::render::is_git_repo_url(repo) {
283                    return Err(DepError::FonteRepoShape {
284                        nome: nome.to_string(),
285                        repo: repo.clone(),
286                        reason,
287                    });
288                }
289                let pins: [(&'static str, Option<&String>); 3] = [
290                    (":tag", tag.as_ref()),
291                    (":rev", rev.as_ref()),
292                    (":branch", branch.as_ref()),
293                ];
294                let set: Vec<&'static str> =
295                    pins.iter().filter_map(|(n, v)| v.map(|_| *n)).collect();
296                match set.len() {
297                    0 => {
298                        return Err(DepError::FontePinMissing {
299                            nome: nome.to_string(),
300                        });
301                    }
302                    1 => {
303                        for (pin, value) in pins {
304                            if value.is_some_and(String::is_empty) {
305                                return Err(DepError::FontePinEmpty {
306                                    nome: nome.to_string(),
307                                    pin: pin.to_string(),
308                                });
309                            }
310                        }
311                    }
312                    _ => {
313                        return Err(DepError::FontePinAmbiguous {
314                            nome: nome.to_string(),
315                            pins: set.join(", "),
316                        });
317                    }
318                }
319                // Per-pin value-shape gate. The refname-shaped axes
320                // (`:tag` + `:branch`) route through
321                // [`crate::render::is_git_ref_name`]; the hex-OID-shaped
322                // `:rev` axis routes through
323                // [`crate::render::is_git_oid`]. The two predicates
324                // partition the `:fonte` pin axes structurally — refname
325                // vs. hex commit — so a cross-axis mis-slot (the
326                // canonical "I conflated `:rev` and `:branch`" footgun:
327                // `:rev "main"` defeating the reproducibility contract,
328                // `:tag "deadbeef…"` mis-slotting a SHA into the
329                // refname-shaped axis) lands at the offending axis's
330                // predicate, not at lacre-resolve `git fetch` /
331                // `git checkout` time. Their valid sets intersect at
332                // the empty set: every refname is rejected by
333                // `is_git_oid`, every OID is rejected by
334                // `is_git_ref_name`, structurally.
335                //
336                // Until this gate landed `:tag` / `:branch` were the
337                // refname-shaped axes still untyped past the empty-pin
338                // arm: a malformed-but-non-empty refname
339                // (`:tag "v0.1.0 "` trailing space — the canonical
340                // paste-from-doc footgun; `:tag "v0.1.0.lock"` colliding
341                // with git's atomic-rename guard suffix; `:tag "../escape"`
342                // path-traversal via consecutive dots; `:branch "main "`
343                // trailing space; `:branch "feature/foo bar"` embedded
344                // space; `:branch "@"` the literal HEAD alias;
345                // `:branch "refs/heads/main"` the fully-qualified ref
346                // copied from `git show-ref` output that resolves to
347                // a literal ref named `refs/heads/refs/heads/main` on
348                // disk) silently passed validate; the `:rev` axis was
349                // the last `:fonte`-related axis still untyped past the
350                // empty-pin arm: a malformed-but-non-empty hex-OID
351                // (`:rev "main"` conflating with `:branch` — the
352                // reproducibility-contract leak; `:rev "v0.1.0"`
353                // conflating with `:tag` — the same mis-slot on the
354                // refname/OID boundary; `:rev "c0ffee"` an abbreviated
355                // 6-char prefix that's ambiguous across repo history;
356                // `:rev "DEADBEEF…"` an uppercase OID that round-trips
357                // inconsistently against `git rev-parse HEAD`'s
358                // lowercase emission) silently passed validate and the
359                // failure surfaced at lacre-resolve `git fetch` /
360                // `git checkout` time with a quoting-confused error
361                // far from the source caixa.lisp, with no field naming
362                // which `:deps` entry carried the typo. Lifting both
363                // gates to caixa-build time matches the value-shape
364                // trajectory the peer typed axes already follow
365                // (c4213a4 typed WitContract endpoint/subject/slot;
366                // eb3456d :entrada :paths; c7d05ec :entrada :host;
367                // 4f0390b :contratos :endpoint; 6226bf4 :contratos :wit;
368                // 63e18a0 :contratos :subject; 2f4316e :contratos
369                // :slot; e70d213 :fonte :tag + :branch) — the typed
370                // slot's valid set matches its downstream consumer's
371                // accepted set (here, the git porcelain's refname /
372                // commit-OID grammars at `git fetch` / `git checkout`
373                // time), structurally. Same diagnostic shape every
374                // per-axis value-shape lift already exposes
375                // (`*Invalid { axis, reason }`); the `value:` field
376                // carries the offending refname / OID verbatim so the
377                // author can grep their caixa.lisp for the
378                // `:tag "<value>"` / `:branch "<value>"` /
379                // `:rev "<value>"` literal and fix it in one edit.
380                for (pin, value) in [(":tag", tag.as_ref()), (":branch", branch.as_ref())] {
381                    if let Some(v) = value
382                        && let Err(reason) = crate::render::is_git_ref_name(v)
383                    {
384                        return Err(DepError::FontePinShape {
385                            nome: nome.to_string(),
386                            pin: pin.to_string(),
387                            value: v.clone(),
388                            reason,
389                        });
390                    }
391                }
392                if let Some(v) = rev.as_ref()
393                    && let Err(reason) = crate::render::is_git_oid(v)
394                {
395                    return Err(DepError::FontePinShape {
396                        nome: nome.to_string(),
397                        pin: ":rev".to_string(),
398                        value: v.clone(),
399                        reason,
400                    });
401                }
402                Ok(())
403            }
404            Self::Path { caminho } => Self::validate_caminho(nome, caminho),
405        }
406    }
407
408    /// Reproducibility + path-API gate on the `:fonte (:tipo path …)`
409    /// `:caminho` axis. Walks the leading-byte cascade closed by the
410    /// b94fd83 (`/`), a5c248e (`~`), and f4efe9c (`$`) arms; the
411    /// orthogonal embedded-control-byte arm (d624c8d) covering
412    /// `0x00..=0x1F` plus `0x7F` anywhere in the value; and the
413    /// embedded-`\` Windows-path-separator arm closing the
414    /// cross-host-OS-separator divergence vector on the same
415    /// THEORY.md §V.2 render-determinism axis.
416    ///
417    /// Extracted from [`Self::validate`]'s `Self::Path` arm because the
418    /// per-arm cascade now spans nine diagnostic shapes — every new
419    /// `:caminho` arm (a future `&` / `;` / `|` shell-metachar arm,
420    /// a future glob-metachar `*` / `?` arm) lands here rather than
421    /// re-inflating `Self::validate`. The
422    /// function stays a thin per-arm linear walk for one reason: each
423    /// arm's diagnostic carries a distinct typed [`DepError`] variant
424    /// rather than a parser-shaped `reason` string, so collapsing the
425    /// cascade onto a generic [`crate::render`] predicate would regress
426    /// the per-arm self-locating diagnostic that `feira lint` consumers
427    /// depend on. The wrapped predicate trajectory ([`crate::render::is_dns_1123_label`],
428    /// [`crate::render::is_git_repo_url`], etc.) lives on the
429    /// reason-string-shaped axes; the `:caminho` axis keeps its
430    /// per-arm variant shape.
431    #[allow(
432        clippy::too_many_lines,
433        reason = "the per-arm cascade is structurally flat by design — every \
434                  `:caminho` arm carries its own typed [`DepError`] variant + \
435                  per-arm Why comment, so collapsing the cascade onto a generic \
436                  [`crate::render`] predicate would regress the per-arm self-locating \
437                  diagnostic the `feira lint` consumer surface depends on"
438    )]
439    fn validate_caminho(nome: &str, caminho: &str) -> Result<(), DepError> {
440        if caminho.is_empty() {
441            return Err(DepError::FonteCaminhoEmpty {
442                nome: nome.to_string(),
443            });
444        }
445        // Reproducibility gate on the `:fonte (:tipo path …)`
446        // `:caminho` axis. The lacre pipeline embeds the value
447        // verbatim in its per-dep content-address
448        // (`conteudo: format!("path:{caminho}")`,
449        // caixa-resolver/src/resolve.rs:189) and that string
450        // folds into the BLAKE3 closure the lacre keys every
451        // downstream consumer (the substrate's reproducibility
452        // contract, CAIXA-SDLC §III.2 — the lacre is the
453        // build's content-addressed identity, peer of the Nix
454        // store path) against. Until this gate landed an
455        // absolute `:caminho` (`/home/me/work/caixa-teia` — the
456        // canonical "I dragged the folder out of Finder into
457        // my editor" footgun; `/Users/alice/dev/caixa-teia` on
458        // the macOS path-layout peer; the
459        // `${WORKSPACE}/caixa-teia` shell-expanded literal
460        // pasted from a CI manifest) silently passed validate
461        // and the failure surfaced *as a successful build with
462        // a divergent lacre*: the BLAKE3 closure on Alice's
463        // workstation differed from the closure on Bob's
464        // workstation, two CI runners with different
465        // `${HOME}` layouts emitted two distinct
466        // content-addresses for the byte-identical caixa, and
467        // the substrate's "the lacre is the build's identity"
468        // contract silently broke far from the source
469        // caixa.lisp — the most insidious failure mode the
470        // typed slot can carry (no error surfaces; the
471        // divergence is invisible until two machines compare
472        // lacres). The same THEORY.md §V.2 render-determinism
473        // discipline `is_sandboxed_relative_path` already
474        // applies on the M2 typed path-slots
475        // (`:behavior :on-*`, `:upgrade-from :state-change
476        // :script`, `:bibliotecas`, `:exe`, `:servicos`), here
477        // narrowed to the absolute-vs-relative axis only:
478        // `:fonte :caminho`'s canonical author-surface form is
479        // the `..`-traversing sibling-workspace path
480        // (`"../caixa-teia"`, the in-tree dev-dep frame), so a
481        // full `is_sandboxed_relative_path` lift would
482        // structurally reject every legitimate path-fonte
483        // dep. The narrower
484        // `std::path::Path::is_absolute` cut admits the
485        // sibling-workspace form while still rejecting the
486        // host-layout-leaking absolute shape — the
487        // reproducibility contract bites at exactly the
488        // absolute boundary, and that's the axis the
489        // substrate-level invariant is meant to hold. Same
490        // diagnostic shape every per-axis value-shape lift on
491        // the surrounding [`DepError::Fonte*`] cluster carries
492        // (the offending `:nome` + offending `:caminho`
493        // quoted verbatim so the author can grep their
494        // caixa.lisp for the `:caminho "<value>"` literal and
495        // fix it in one edit). The empty arm strictly
496        // precedes this arm so the blank-string footgun
497        // surfaces the more self-locating
498        // `FonteCaminhoEmpty` diagnostic (the empty string
499        // is not absolute under `Path::new("").is_absolute()`
500        // so the precedence is a no-op at value level — the
501        // pin matters only at the diagnostic-shape level if
502        // a future codec round-trip ever produces an empty
503        // string that probes as absolute).
504        if std::path::Path::new(caminho).is_absolute() {
505            return Err(DepError::FonteCaminhoAbsolute {
506                nome: nome.to_string(),
507                caminho: caminho.to_string(),
508            });
509        }
510        // Reproducibility gate's tilde-expansion arm. The b94fd83
511        // `FonteCaminhoAbsolute` closes the leading-`/`
512        // host-layout-leak; a `:caminho "~/work/caixa-teia"` (the
513        // canonical paste-from-shell-prompt / paste-from-`cd ~`-
514        // doc footgun) silently passed both the empty arm and
515        // the absolute arm because `Path::new("~").is_absolute()`
516        // returns `false` — `~` is a shell-expansion convention,
517        // not a POSIX path component, so `std::path::Path` treats
518        // it as a literal directory-name segment. The lacre
519        // pipeline then embedded the value verbatim
520        // (`conteudo: format!("path:~/work/caixa-teia")`) and the
521        // failure mode forked per consumer:
522        //
523        //   - The caixa-resolver's `Path` arm folds `:caminho`
524        //     through `Path::new(caminho).join(<file>)` without
525        //     `~`-expansion, so the build looked for a literal
526        //     `./~/work/caixa-teia` subdirectory and failed at
527        //     resolve time with a `No such file or directory`
528        //     error far from the source caixa.lisp (the lacre
529        //     itself, though, was already byte-identical across
530        //     machines — every machine emitted the same
531        //     `path:~/work/caixa-teia` content-address).
532        //   - A future caixa-resolver pass that *does* expand `~`
533        //     (the canonical shell-convention idiom every
534        //     resolver eventually reaches for once an author
535        //     reports the literal-`~`-directory bug) would re-
536        //     introduce the host-layout-leak the b94fd83 absolute
537        //     gate closes: Alice's `~` expands to `/home/alice`,
538        //     Bob's to `/home/bob`, two CI runners with different
539        //     `$HOME` layouts resolve to two distinct paths for
540        //     the byte-identical caixa, and the substrate's
541        //     "the lacre is the build's identity" contract
542        //     silently breaks far from the source caixa.lisp.
543        //
544        // Closing the gate at `DepSource::validate` (here at the
545        // canonical caixa-build-time boundary, peer with the
546        // absolute arm above) refuses both failure modes
547        // structurally: the typed accepted set excludes every
548        // `~`-prefixed authoring shape, so the resolver is
549        // free to grow `~`-expansion (or any other convention-
550        // expansion the substrate adopts) without re-opening
551        // the host-layout-leak at the typed boundary. Same
552        // diagnostic shape every per-axis value-shape gate on
553        // the surrounding [`DepError::Fonte*`] cluster carries
554        // (the offending `:nome` + offending `:caminho` quoted
555        // verbatim so the author can grep their caixa.lisp for
556        // the `:caminho "<value>"` literal and fix it in one
557        // edit).
558        //
559        // The cascade preserves narrower-diagnostic-first
560        // ordering: `FonteCaminhoEmpty` → `FonteCaminhoAbsolute`
561        // → `FonteCaminhoTildeExpansion`. The empty arm
562        // structurally precedes both (the bytes "" / "~" don't
563        // overlap), and the absolute arm structurally precedes
564        // the tilde arm (an absolute path can't start with `~`
565        // since absolute paths start with `/`; the bytes "/" /
566        // "~" don't overlap either). Both arms are
567        // value-disjoint, so the precedence is a no-op at value
568        // level — the pin matters only at the diagnostic-shape
569        // level if a future codec round-trip ever produces a
570        // value that probes as both absolute and tilde-prefixed.
571        if caminho.starts_with('~') {
572            return Err(DepError::FonteCaminhoTildeExpansion {
573                nome: nome.to_string(),
574                caminho: caminho.to_string(),
575            });
576        }
577        // Reproducibility gate's shell-variable-expansion arm.
578        // The b94fd83 `FonteCaminhoAbsolute` closes the leading-`/`
579        // host-layout-leak; the a5c248e `FonteCaminhoTildeExpansion`
580        // closes the leading-`~` shell-home-expansion shape; the
581        // leading-`$` is the sibling shell-variable-expansion shape
582        // — same host-layout-leaking semantic, different syntactic
583        // surface. A `:caminho "$HOME/work/caixa-teia"` (the
584        // canonical paste-from-`echo $HOME`-doc footgun) and the
585        // `${VAR}`-braced variant (`"${WORKSPACE}/caixa-teia"` —
586        // the canonical paste-from-CI-manifest footgun every
587        // GitHub Actions / GitLab CI / Drone manifest carries)
588        // silently passed every prior arm because
589        // `Path::is_absolute` returns false on `$` (the `$` is a
590        // shell convention, not a POSIX path component, so
591        // `std::path::Path` treats it as a literal directory-name
592        // segment) and the tilde arm's `starts_with('~')` doesn't
593        // fire.
594        //
595        // Same per-consumer failure-fork the tilde arm closes:
596        //
597        //   - The caixa-resolver's `Path` arm folds `:caminho`
598        //     through `Path::new(caminho).join(<file>)` without
599        //     `$`-expansion, so the build looks for a literal
600        //     `./$HOME/work/caixa-teia` subdirectory and fails at
601        //     resolve time with a `No such file or directory`
602        //     error far from the source caixa.lisp.
603        //   - A future caixa-resolver pass that *does* expand
604        //     `$VAR` (the shell-convention idiom every resolver
605        //     eventually reaches for once an author reports the
606        //     literal-`$HOME`-directory bug, especially for CI's
607        //     `${WORKSPACE}` idiom) would re-introduce the host-
608        //     layout-leak the b94fd83 absolute gate closes:
609        //     Alice's `$HOME` expands to `/home/alice`, Bob's to
610        //     `/home/bob`, two CI runners with different
611        //     `${WORKSPACE}` layouts resolve to two distinct
612        //     paths for the byte-identical caixa, and the
613        //     substrate's "the lacre is the build's identity"
614        //     contract silently breaks far from the source
615        //     caixa.lisp.
616        //
617        // Closing the gate at `DepSource::validate` (here at the
618        // canonical caixa-build-time boundary, peer with the
619        // absolute + tilde arms above) refuses both failure modes
620        // structurally. Same diagnostic shape every per-axis
621        // value-shape gate on the surrounding [`DepError::Fonte*`]
622        // cluster carries (the offending `:nome` + offending
623        // `:caminho` quoted verbatim).
624        //
625        // The cascade preserves narrower-diagnostic-first ordering:
626        // `FonteCaminhoEmpty` → `FonteCaminhoAbsolute` →
627        // `FonteCaminhoTildeExpansion` → `FonteCaminhoVarExpansion`.
628        // The empty arm structurally precedes all three subsequent
629        // arms; the absolute arm structurally precedes both the
630        // tilde and the var arms (absolute paths start with `/`,
631        // the bytes `/` / `~` / `$` don't overlap at the leading
632        // position); the tilde arm structurally precedes the var
633        // arm (`~` and `$` don't overlap at the leading position).
634        // Every pair is value-disjoint, so the precedence is a
635        // no-op at value level — the pin matters only at the
636        // diagnostic-shape level if a future codec round-trip ever
637        // produces a probe-as-both value.
638        //
639        // The gate covers every leading-`$` shape: the canonical
640        // `"$HOME/work/caixa-teia"` (POSIX shell), the braced
641        // `"${HOME}/work/caixa-teia"` (POSIX shell braces), the
642        // CI-manifest idiom `"${WORKSPACE}/caixa-teia"` (the
643        // GitHub Actions / GitLab CI / Drone paste footgun), the
644        // XDG idiom `"$XDG_CONFIG_HOME/caixa"`, and the bare `$`
645        // (degenerate "I meant `$HOME` and forgot the rest"). All
646        // shapes route through the same `caminho.starts_with('$')`
647        // byte check.
648        if caminho.starts_with('$') {
649            return Err(DepError::FonteCaminhoVarExpansion {
650                nome: nome.to_string(),
651                caminho: caminho.to_string(),
652            });
653        }
654        // Reproducibility gate's leading-space arm. The b94fd83 / a5c248e /
655        // f4efe9c arms closed the leading-byte host-layout-leak shapes
656        // (`/` / `~` / `$`); the embedded-control-byte arm below closes
657        // every byte in `0x00..=0x1F` plus `0x7F` (which already includes
658        // tab `0x09`, LF `0x0A`, CR `0x0D` — every ASCII whitespace
659        // *except* the ASCII space byte `0x20`). The bare ASCII space at
660        // the leading position is the orthogonal paste-from-aligned-doc
661        // shape that silently passed every prior arm: `Path::is_absolute`
662        // returns false on `" ../caixa-teia"` (the leading byte is `0x20`
663        // not `0x2F`), `0x20` is not `~` / `$` / `\` / a control byte, and
664        // the value's last byte is not `/`, so the canonical
665        // paste-from-aligned-`caixa.lisp`-doc footgun (every `:fonte`
666        // form in a multi-entry `:deps` block sits at the same column —
667        // an author selecting `"<sp><sp><sp>../caixa-teia"` and pasting
668        // it from the rendered alignment into a fresh entry preserves the
669        // leading whitespace verbatim) silently rendered as a path with
670        // a leading-space directory component the resolver folds through
671        // `Path::join` looking for a literal `./ ../caixa-teia`
672        // subdirectory that fails at resolve time with a non-self-
673        // locating `No such file or directory` error.
674        //
675        // The lacre pipeline's reproducibility contract bites
676        // strictly at this byte: `path:" ../caixa-teia"` and
677        // `path:"../caixa-teia"` yield distinct BLAKE3 closures
678        // (`conteudo: format!("path:{caminho}")`,
679        // caixa-resolver/src/resolve.rs:189) for the byte-divergent /
680        // semantic-identical caixa, and the substrate's "the lacre is
681        // the build's identity" contract (CAIXA-SDLC §III.2) silently
682        // breaks across two workstations whose authors differ only in
683        // paste-from-aligned-doc whitespace habits — the most insidious
684        // failure mode the typed slot can carry (no error surfaces; the
685        // divergence is invisible until two machines compare lacres).
686        //
687        // The arm fires AFTER the absolute / tilde / var leading-byte
688        // arms (each names the more self-locating shell-convention
689        // diagnostic on values that probe as that arm's leading-byte
690        // sentinel followed by a leading space — e.g.
691        // `:caminho "/  /foo"` surfaces `FonteCaminhoAbsolute` because
692        // the leading byte is `/`, not space) and BEFORE the
693        // embedded-control-byte arm (a leading-space value with an
694        // embedded control byte surfaces the broader leading-space
695        // diagnostic because the cascade walks leading-byte arms first
696        // — peer with how `FonteCaminhoAbsolute` precedes
697        // `FonteCaminhoControlChar` on `"/etc/passwd\n"`).
698        //
699        // The peer single-token-shaped axes already reject leading
700        // whitespace on the same paste-from-aligned-doc contract:
701        // [`crate::render::is_git_repo_url`] rejects leading whitespace
702        // on `:fonte :repo`, [`crate::render::is_git_ref_name`] rejects
703        // leading whitespace on `:fonte :tag`/`:branch`,
704        // [`crate::render::is_chart_description_shape`] rejects leading
705        // whitespace on `:descricao`,
706        // [`crate::render::is_spdx_expression_shape`] rejects leading
707        // whitespace on `:licenca`. Closing the same byte on
708        // `:fonte :caminho` makes the substrate-wide "no leading ASCII
709        // space anywhere in a typed string slot" invariant structurally
710        // consistent across every value-shape-gated typed surface (the
711        // `:caminho` axis was the last typed string surface still
712        // admitting a leading space byte).
713        if caminho.starts_with(' ') {
714            return Err(DepError::FonteCaminhoLeadingWhitespace {
715                nome: nome.to_string(),
716                caminho: caminho.to_string(),
717            });
718        }
719        // Reproducibility gate's leading-`-` CLI-argument-injection arm.
720        // The b94fd83 + a5c248e + f4efe9c + LeadingWhitespace arms closed
721        // the four prior leading-byte shapes (`/` / `~` / `$` / space);
722        // this arm closes the orthogonal leading-`-` axis on the same
723        // subprocess-argument-boundary the peer `is_git_repo_url` arm
724        // (render.rs:2037, `-upload-pack=…` on `:fonte :repo`) and
725        // `is_git_ref_name` arm (render.rs:1381, 5a28454, `-stable` on
726        // `:fonte :tag` / `:branch`) already reject.
727        //
728        // The lacre pipeline embeds `:caminho` verbatim in its per-dep
729        // content-address (`conteudo: format!("path:{caminho}")`,
730        // caixa-resolver/src/resolve.rs:189) and the resolver folds the
731        // value through `Path::join` looking for a literal `./{caminho}`
732        // subdirectory. Every downstream subprocess that consumes the
733        // resolved path — a `git -C {caminho} <verb>` invocation, a
734        // future `feira tofu` `terraform -chdir={caminho}` shell-out, a
735        // future operator-side `nix build --path {caminho}` spawn, an
736        // `xargs` / `find {caminho}` / `stat {caminho}` /
737        // `rm -rf {caminho}` cleanup — reinterprets a leading-`-` value
738        // as a CLI flag rather than a positional path when the
739        // subprocess invocation does not carry a `--` argument-list
740        // terminator between the flag block and the path argument. The
741        // canonical footguns:
742        //
743        //   - `:caminho "-rf"` — bare short-flag paste (`rm -rf` /
744        //     `find -rf` reinterpretation; the byte the peer
745        //     `FonteCaminhoShellSemicolon` arm's `; rm -rf build`
746        //     example paste-idiom carries as its first token).
747        //   - `:caminho "-C"` — `git -C` config-injection paste
748        //     (`git -C -C` reinterprets the second `-C` as another
749        //     `--change-directory` flag rather than the path
750        //     argument; the canonical `git -C <path>` porcelain
751        //     idiom every multi-repo workspace tool carries).
752        //   - `:caminho "--upload-pack=cat /etc/passwd"` — the
753        //     canonical long-flag CLI-arg-injection vector at every
754        //     git porcelain entry point (`git clone`, `git fetch`,
755        //     `git ls-remote`) that consumes a path or URL
756        //     argument; peer with `is_git_repo_url`'s leading-`-`
757        //     arm (render.rs:2037) on the sibling `:fonte :repo`
758        //     axis, which the arm's diagnostic explicitly cites.
759        //   - `:caminho "--config=…"` / `:caminho "-c"` — git-config
760        //     override paste-idiom (paste-from-`git -c foo=bar`
761        //     shell-history footgun that reinterprets the value as
762        //     a `[foo] bar` config injection on every git porcelain
763        //     entry point).
764        //
765        // POSIX `std::path::Path` treats a leading `-` as a literal
766        // filename byte, so the resolver folds `-rf` through `Path::join`
767        // and looks for a literal `./-rf` subdirectory — the failure
768        // surfaces at resolve time with a non-self-locating `No such
769        // file or directory` error far from the source caixa.lisp, and
770        // the value rides through the lacre content-address into every
771        // downstream shell-spawned subprocess. On any consumer that
772        // shells out without the `--` terminator (the common case at
773        // every porcelain entry-point) the reinterpretation is silent
774        // and the failure mode is arbitrary-argument-injection.
775        //
776        // The arm fires AFTER the absolute / tilde / var / leading-space
777        // leading-byte arms (each names the more self-locating shell-
778        // convention diagnostic on values that probe as that arm's
779        // leading-byte sentinel — the byte sets are pairwise disjoint at
780        // the leading position, so the precedence pin is a no-op at
781        // value level, but the ordering keeps every leading-byte arm's
782        // diagnostic-shape stable) and BEFORE the embedded-control-byte
783        // arm (a leading-`-` value with an embedded control byte
784        // surfaces the narrower leading-`-` diagnostic because the
785        // cascade walks leading-byte arms first — peer with how
786        // `FonteCaminhoAbsolute` precedes `FonteCaminhoControlChar` on
787        // `"/etc/passwd\n"`, and how `FonteCaminhoLeadingWhitespace`
788        // precedes `FonteCaminhoControlChar` on `" ../foo\n"`).
789        //
790        // The peer single-token-shaped axes already reject leading `-`
791        // on the same CLI-arg-injection contract:
792        // [`crate::render::is_git_repo_url`] rejects it on `:fonte :repo`
793        // (render.rs:2037), [`crate::render::is_git_ref_name`] rejects
794        // it on `:fonte :tag` / `:fonte :branch` (render.rs:1381,
795        // 5a28454), [`crate::render::is_dns_1123_label`] rejects it on
796        // every DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros
797        // :caixa`, `:children :caixa`, `:deps :nome`, cluster names),
798        // [`crate::render::is_cargo_feature_name`] rejects it on
799        // `:caracteristicas`, and the feira `init` / `add <nome>`
800        // positional gate (868c191) rejects it on the CLI positional
801        // itself. Closing the same byte on `:fonte :caminho` makes the
802        // substrate-wide "no leading `-` anywhere in a typed single-
803        // token string slot routed through a subprocess argument"
804        // invariant structurally consistent across every value-shape-
805        // gated typed surface (the `:caminho` axis was the last typed
806        // string surface still admitting a leading `-` byte).
807        if caminho.starts_with('-') {
808            return Err(DepError::FonteCaminhoLeadingHyphen {
809                nome: nome.to_string(),
810                caminho: caminho.to_string(),
811            });
812        }
813        // Reproducibility gate's embedded-control-byte arm. The
814        // b94fd83 + a5c248e + f4efe9c arms closed the three
815        // leading-byte host-layout-leak shapes (`/` / `~` / `$`);
816        // this arm closes the orthogonal embedded-control-byte
817        // axis — any ASCII control byte (`0x00..=0x1F` plus
818        // `0x7F` DEL) appearing anywhere in `:caminho`. Same
819        // shape every peer single-token-typed-slot value-shape
820        // predicate the surrounding [`crate::render`] cluster
821        // gates against (the lifted `is_git_repo_url` arm on
822        // `:fonte :repo`, the `is_git_ref_name` arm on
823        // `:tag`/`:branch`, the `is_chart_description_shape` /
824        // `is_chart_maintainer_name_shape` /
825        // `is_chart_keyword_shape` arms on the
826        // Helm-chart-shaped axes); now consistent on the
827        // `:caminho` axis too.
828        //
829        // Until this gate landed any embedded control byte
830        // silently passed validate, the lacre pipeline embedded
831        // the value verbatim in its per-dep content-address
832        // (`conteudo: format!("path:{caminho}")`,
833        // caixa-resolver/src/resolve.rs:189), and the failure
834        // forked per byte and per consumer:
835        //
836        //   - NUL (`0x00`) the canonical "POSIX paths cannot
837        //     contain a NUL byte" shape: every `std::fs` syscall
838        //     routes the path through `CString::new`, which
839        //     fails with `NulError` on the first NUL byte; the
840        //     build would surface a `NulError` at resolve time
841        //     far from the source caixa.lisp.
842        //   - LF (`0x0A`) / CR (`0x0D`) the canonical paste-from-
843        //     multiline-doc footgun: a `:caminho
844        //     "../caixa-teia\nrm -rf /"` value (paste landed mid-
845        //     `:caminho` block from a multi-line code-fence)
846        //     silently round-trips through `Path::join` but the
847        //     embedded newline class is a sibling of the CRLF-at-
848        //     subprocess-argument injection vector
849        //     `is_git_repo_url` already closes on `:repo`.
850        //   - Tab (`0x09`) the canonical paste-from-aligned-table
851        //     footgun: the tab is invisible in most editors, and
852        //     the lacre embeds the value verbatim so two
853        //     paste-from-distinct-tables yield divergent lacres
854        //     across host editors that strip vs preserve tabs.
855        //   - DEL (`0x7F`) + every other `0x00..=0x1F` byte: the
856        //     paste-from-binary-blob shape every peer single-
857        //     token-shaped slot rejects under the same
858        //     `b < 0x20 || b == 0x7F` predicate.
859        //
860        // Mirrors the cascade discipline every prior `:caminho`
861        // arm establishes: `FonteCaminhoEmpty` →
862        // `FonteCaminhoAbsolute` → `FonteCaminhoTildeExpansion`
863        // → `FonteCaminhoVarExpansion` →
864        // `FonteCaminhoLeadingWhitespace` →
865        // `FonteCaminhoLeadingHyphen` → `FonteCaminhoControlChar`.
866        // The six leading-byte arms structurally precede the
867        // embedded-byte arm because the leading-byte shapes are
868        // the more self-locating diagnostic on values that probe
869        // as both (e.g. `:caminho "/etc/passwd\n"` surfaces the
870        // narrower `FonteCaminhoAbsolute` rather than the broader
871        // embedded-control-byte arm); the precedence pin matters
872        // at the diagnostic-shape level even though the empty /
873        // absolute / tilde / var arms are value-disjoint from a
874        // bare control byte (which would itself be a leading
875        // byte under the empty / absolute / tilde / var arms'
876        // leading-position semantics, but those arms guard the
877        // specific shell-convention characters `/` / `~` / `$`
878        // — a leading `0x01` byte falls through to this arm).
879        for &b in caminho.as_bytes() {
880            if b < 0x20 || b == 0x7F {
881                return Err(DepError::FonteCaminhoControlChar {
882                    nome: nome.to_string(),
883                    caminho: caminho.to_string(),
884                    byte: b,
885                });
886            }
887        }
888        // Reproducibility gate's Windows-path-separator arm. The four
889        // leading-byte arms (`/` / `~` / `$`) and the embedded-
890        // control-byte arm close the host-layout-leaking + paste-from-
891        // multiline-doc shapes; the leading-`\` / embedded-`\` byte is
892        // the orthogonal cross-host-OS-separator shape — same render-
893        // determinism axis, different semantic mechanism. POSIX
894        // [`std::path::Path`] treats `\` (0x5C) as a literal byte
895        // inside a single path component (so `..\caixa-teia` is one
896        // directory named literally `..\caixa-teia`, sibling of `.`
897        // and `..`); Windows [`std::path::Path`] treats `\` as a
898        // primary path separator equal to `/` (so `..\caixa-teia` is
899        // the parent's sibling directory `caixa-teia`). The lacre
900        // pipeline embeds the value verbatim in its per-dep content-
901        // address (`conteudo: format!("path:{caminho}")`, caixa-
902        // resolver/src/resolve.rs:189), so byte-identical caixa.lisp
903        // values resolve to two distinct directories across runner
904        // OSes — the same THEORY.md §V.2 render-determinism contract
905        // the absolute / tilde / var arms protect, here against the
906        // cross-host-OS-separator divergence vector. Even on POSIX-
907        // only resolvers (the canonical pleme-io substrate posture),
908        // a `..\caixa-teia` (the Windows-Explorer "copy as path" /
909        // PowerShell `Get-Location` paste-idiom footgun) silently
910        // passes every prior arm because `Path::is_absolute` returns
911        // false on `..` and `\` is neither a leading-byte sentinel
912        // nor a control byte, then the resolver folds the value
913        // through `Path::new(caminho).join(<file>)` looking for a
914        // literal `./..\caixa-teia` subdirectory and fails at
915        // resolve time with a non-self-locating `No such file or
916        // directory` error far from the source caixa.lisp.
917        //
918        // The peer single-token-shaped axes on the same git-CLI /
919        // path-CLI consumer cluster already reject `\` under the same
920        // Windows-path-leak banner: [`crate::render::is_git_ref_name`]
921        // line 1441 (`"must not contain \\ … the canonical Windows-
922        // path-leak footgun; use / for hierarchical refs"`) gates
923        // `:fonte :tag` / `:fonte :branch` against the same byte,
924        // and [`crate::render::is_gateway_api_http_path`] line 506
925        // includes `\` in the eleven-byte RFC-3986-reserved rejection
926        // set on `:entrada :paths`. Closing the same byte on `:fonte
927        // :caminho` makes the substrate-wide "no Windows path
928        // separator anywhere in a typed string slot" invariant
929        // structurally consistent across every path-shaped typed
930        // surface (the `:caminho` axis was the last typed string
931        // surface still admitting `\`).
932        //
933        // The arm fires AFTER the control-char arm because the
934        // control-char diagnostic is the more self-locating axis on
935        // values that probe as both (`"..\caixa\0teia"` carries both
936        // a `\` and a NUL — NUL is the load-bearing POSIX-syscall-
937        // rejected byte, so `FonteCaminhoControlChar` wins). Same
938        // narrower-diagnostic-first cascade discipline every prior
939        // arm establishes. A pure-`\` value
940        // (`"..\caixa-teia"` with no control bytes) falls through
941        // every prior arm and lands here.
942        for &b in caminho.as_bytes() {
943            if b == b'\\' {
944                return Err(DepError::FonteCaminhoBackslash {
945                    nome: nome.to_string(),
946                    caminho: caminho.to_string(),
947                });
948            }
949        }
950        // Reproducibility gate's shell-redirection arm. The 3a4e1d7 backslash
951        // arm closes the cross-host-OS-separator vector; `<` (`0x3C`) and `>`
952        // (`0x3E`) are the orthogonal shell-redirection sentinels — same
953        // paste-from-shell-prompt footgun class, different syntactic surface.
954        // POSIX `std::path::Path` treats `<` / `>` as literal bytes inside a
955        // single path component (so `../caixa-teia>output` is one directory
956        // named literally `../caixa-teia>output`, sibling of `.` and `..`),
957        // but every interactive shell (bash / zsh / fish / nushell) lexes
958        // `<` / `>` as input / output redirection operators — a `:caminho
959        // "../caixa-teia>build.log"` (the canonical "I pasted a shell
960        // pipeline that wrote build output and forgot to trim the redirect"
961        // footgun) or `:caminho "../<input.lisp"` (the symmetric input-
962        // redirection paste idiom) silently passes every prior arm because
963        // `Path::is_absolute` returns false, `<` / `>` are neither leading-
964        // byte sentinels nor control bytes nor `\`, and the value's last byte
965        // isn't `/`. The resolver folds the value through
966        // `Path::new(caminho).join(<file>)` looking for a literal
967        // `./..\caixa-teia>build.log` subdirectory and fails at resolve time
968        // with a non-self-locating `No such file or directory` error far
969        // from the source caixa.lisp.
970        //
971        // The lacre pipeline embeds the value verbatim in its per-dep
972        // content-address (`conteudo: format!("path:{caminho}")`,
973        // caixa-resolver/src/resolve.rs:189), so a `<` / `>` byte lands in
974        // the BLAKE3 closure and rides downstream as part of the build's
975        // identity. The bytes carry a second class of hazard the prior
976        // separator-shaped arms don't: every typed-string slot whose value
977        // ever flows verbatim into a shell-spawned subprocess (the caixa-
978        // resolver's `git clone` invocation, a future `feira tofu` shell-
979        // out, a future operator-side `nix flake check` spawn) is the
980        // canonical CRLF-at-subprocess-argument / shell-metachar injection
981        // surface that every peer single-token-shaped typed slot already
982        // closes. The peer path-shaped axis `[crate::render::is_gateway_api_http_path]`
983        // (caixa-core/src/render.rs:506) rejects `<` / `>` as part of its
984        // eleven-byte RFC-3986-reserved set on `:entrada :paths`, and the
985        // peer git-ref-shaped axis `[crate::render::is_git_ref_name]` rejects
986        // `<` / `>` on `:fonte :tag` / `:fonte :branch` under the same
987        // shell-metachar-injection banner. The `:caminho` axis was the last
988        // typed string surface still admitting these two bytes; this arm
989        // closes the gap so the substrate-wide "no shell-redirection
990        // metacharacter anywhere in a typed string slot" invariant is now
991        // structurally consistent across every path-shaped typed surface.
992        //
993        // The arm fires AFTER the control-char arm + backslash arm because
994        // both prior arms carry more self-locating diagnostics on values
995        // that probe as both (`"..\foo<bar"` carries both `\` and `<` — the
996        // cross-OS-separator divergence is the load-bearing axis, so the
997        // backslash arm wins; `"../foo\n<bar"` carries both LF and `<` —
998        // the POSIX-syscall-rejected byte is the load-bearing axis, so the
999        // control-char arm wins). The arm fires BEFORE the trailing-`/` arm
1000        // because the embedded redirection byte is the more semantic-
1001        // locating axis on probe-as-both values (`"../foo</"` ends in `/`
1002        // but the load-bearing diagnostic is the embedded `<` shell-
1003        // redirection — the trailing `/` is the secondary observation, and
1004        // an author who removes the `<` is likely to also tab-strip the
1005        // trailing separator).
1006        for &b in caminho.as_bytes() {
1007            if b == b'<' || b == b'>' {
1008                return Err(DepError::FonteCaminhoShellRedirection {
1009                    nome: nome.to_string(),
1010                    caminho: caminho.to_string(),
1011                    byte: b,
1012                });
1013            }
1014        }
1015        // Reproducibility gate's shell-pipe arm. The e457141 shell-redirection
1016        // arm closes the `<` / `>` input/output redirection sentinels; `|`
1017        // (`0x7C`) is the orthogonal shell-pipe sentinel — same paste-from-
1018        // shell-prompt footgun class, different syntactic surface. POSIX
1019        // `std::path::Path` treats `|` as a literal path-component byte (so
1020        // `../caixa-teia|tee` is one directory named literally
1021        // `../caixa-teia|tee`, sibling of `.` and `..`), but every interactive
1022        // shell (bash / zsh / fish / nushell) lexes `|` as the pipe operator
1023        // — a `:caminho "../caixa-teia | grep foo"` (the canonical "I copied a
1024        // `ls ../caixa-teia | grep` line out of a shell-history block and
1025        // forgot to trim the pipeline tail" footgun) or `:caminho
1026        // "../foo||bar"` (the symmetric "I copied a `cmd-a || cmd-b` short-
1027        // circuit OR line" idiom) silently passes every prior arm because
1028        // `Path::is_absolute` returns false on `..`, `|` is neither a leading-
1029        // byte sentinel nor a control byte nor `\` nor `<` / `>`, and the
1030        // value's last byte isn't `/`. The resolver folds the value through
1031        // `Path::new(caminho).join(<file>)` looking for a literal
1032        // `./../caixa-teia | grep foo` subdirectory and fails at resolve time
1033        // with a non-self-locating `No such file or directory` error far
1034        // from the source caixa.lisp.
1035        //
1036        // The lacre pipeline embeds the value verbatim in its per-dep
1037        // content-address (`conteudo: format!("path:{caminho}")`,
1038        // caixa-resolver/src/resolve.rs:189), so a `|` byte lands in the
1039        // BLAKE3 closure and rides downstream as part of the build's identity
1040        // into every shell-spawned subprocess (the caixa-resolver's `git
1041        // clone` invocation, a future `feira tofu` shell-out, a future
1042        // operator-side `nix flake check` spawn) as the canonical CRLF-at-
1043        // subprocess-argument / shell-metachar injection surface every peer
1044        // single-token-shaped typed slot already closes. The peer path-shaped
1045        // axis [`crate::render::is_gateway_api_http_path`]
1046        // (caixa-core/src/render.rs:506) rejects `|` as part of its eleven-
1047        // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1048        // axis was the last typed path-string surface still admitting this
1049        // byte; this arm closes the gap so the substrate-wide "no shell-
1050        // composition metacharacter anywhere in a typed string slot that
1051        // flows verbatim into a shell-spawned subprocess" invariant extends
1052        // from shell-redirection (`<` / `>`) to shell-pipe (`|`) on the
1053        // `:caminho` axis.
1054        //
1055        // The arm fires AFTER the shell-redirection arm because the prior
1056        // arm's two-byte `byte: u8` payload is the more self-locating axis on
1057        // values that probe as both (`"../caixa-teia<input|tee"` carries both
1058        // `<` and `|` — the input-redirection-paste idiom is the load-bearing
1059        // root-cause edit, so `FonteCaminhoShellRedirection` wins; same
1060        // cascade discipline every prior `:caminho` arm establishes). The arm
1061        // fires BEFORE the trailing-`/` arm because the embedded pipe byte is
1062        // the more semantic-locating axis on probe-as-both values
1063        // (`"../foo|tee/"` ends in `/` but the load-bearing diagnostic is the
1064        // embedded `|` shell-pipe — the trailing `/` is the secondary
1065        // observation, and an author who removes the `|` is likely to also
1066        // tab-strip the trailing separator).
1067        for &b in caminho.as_bytes() {
1068            if b == b'|' {
1069                return Err(DepError::FonteCaminhoShellPipe {
1070                    nome: nome.to_string(),
1071                    caminho: caminho.to_string(),
1072                });
1073            }
1074        }
1075        // Reproducibility gate's shell-command-separator arm. The 124106f
1076        // shell-pipe arm closes the `|` byte; `;` (`0x3B`) is the orthogonal
1077        // shell-command-separator sentinel — same paste-from-shell-prompt
1078        // footgun class, different syntactic surface. POSIX `std::path::Path`
1079        // treats `;` as a literal path-component byte (so
1080        // `../caixa-teia;rm -rf /` is one directory named literally
1081        // `../caixa-teia;rm -rf /`, sibling of `.` and `..`), but every
1082        // interactive shell (bash / zsh / fish / nushell) lexes `;` as the
1083        // sequential-command terminator that fires the next command
1084        // regardless of the prior command's exit status — a `:caminho
1085        // "../caixa-teia; rm -rf build"` (the canonical "I pasted a shell
1086        // one-liner that chained a cleanup tail after the directory name"
1087        // footgun) or `:caminho "../foo;;bar"` (the symmetric "I copied a
1088        // POSIX `case` arm's `;;` terminator into the middle of a path"
1089        // idiom) silently passes every prior arm because `Path::is_absolute`
1090        // returns false on `..`, `;` is neither a leading-byte sentinel nor a
1091        // control byte nor `\` nor `<` / `>` nor `|`, and the value's last
1092        // byte isn't `/`. The resolver folds the value through
1093        // `Path::new(caminho).join(<file>)` looking for a literal
1094        // `./../caixa-teia; rm -rf build` subdirectory and fails at resolve
1095        // time with a non-self-locating `No such file or directory` error far
1096        // from the source caixa.lisp.
1097        //
1098        // The lacre pipeline embeds the value verbatim in its per-dep
1099        // content-address (`conteudo: format!("path:{caminho}")`,
1100        // caixa-resolver/src/resolve.rs:189), so a `;` byte lands in the
1101        // BLAKE3 closure and rides downstream as part of the build's identity
1102        // into every shell-spawned subprocess (the caixa-resolver's `git
1103        // clone` invocation, a future `feira tofu` shell-out, a future
1104        // operator-side `nix flake check` spawn) as the canonical
1105        // shell-metachar injection surface every peer single-token-shaped
1106        // typed slot already closes. The peer path-shaped axis
1107        // [`crate::render::is_gateway_api_http_path`]
1108        // (caixa-core/src/render.rs:506) rejects `;` as part of its eleven-
1109        // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1110        // axis was the last typed path-string surface still admitting this
1111        // byte; this arm closes the gap so the substrate-wide "no shell-
1112        // composition metacharacter anywhere in a typed string slot that
1113        // flows verbatim into a shell-spawned subprocess" invariant extends
1114        // from shell-pipe (`|`) to shell-command-separator (`;`) on the
1115        // `:caminho` axis.
1116        //
1117        // The arm fires AFTER the shell-pipe arm because the prior arm's
1118        // canonical-cmd-a-|-cmd-b shape is the more common shell-history
1119        // paste idiom on values that probe as both (`"../caixa-teia | tee;
1120        // rm"` carries both `|` and `;` — the pipeline-tail paste is the
1121        // load-bearing root-cause edit, so `FonteCaminhoShellPipe` wins; same
1122        // cascade discipline every prior `:caminho` arm establishes). The arm
1123        // fires BEFORE the trailing-`/` arm because the embedded
1124        // command-separator byte is the more semantic-locating axis on
1125        // probe-as-both values (`"../foo;rm/"` ends in `/` but the
1126        // load-bearing diagnostic is the embedded `;` shell-command-
1127        // separator — the trailing `/` is the secondary observation, and an
1128        // author who removes the `;` is likely to also tab-strip the trailing
1129        // separator).
1130        for &b in caminho.as_bytes() {
1131            if b == b';' {
1132                return Err(DepError::FonteCaminhoShellSemicolon {
1133                    nome: nome.to_string(),
1134                    caminho: caminho.to_string(),
1135                });
1136            }
1137        }
1138        // Reproducibility gate's shell-background / logical-AND arm. The
1139        // 05c358e shell-command-separator arm closes the `;` byte; `&`
1140        // (`0x26`) is the orthogonal shell-background / list-AND sentinel
1141        // — same paste-from-shell-prompt footgun class, different
1142        // syntactic surface. POSIX `std::path::Path` treats `&` as a
1143        // literal path-component byte (so `../caixa-teia & sleep 1` is
1144        // one directory named literally `../caixa-teia & sleep 1`,
1145        // sibling of `.` and `..`), but every interactive shell
1146        // (bash / zsh / fish / nushell) lexes `&` two ways:
1147        //
1148        //   - Single `&` as the background-task terminator that detaches
1149        //     the prior command into the background and returns control
1150        //     to the prompt immediately (the canonical `cmd &` idiom
1151        //     every long-running pipeline uses);
1152        //   - Double `&&` as the logical-AND list operator that fires
1153        //     the next command only if the prior command succeeded (the
1154        //     canonical `make && make install` idiom every build script
1155        //     carries).
1156        //
1157        // A `:caminho "../caixa-teia & sleep 1"` (the canonical "I
1158        // pasted a `cd path & sleep 1` background-launch into the
1159        // `:caminho` slot" footgun) or `:caminho "../caixa-teia && make"`
1160        // (the symmetric "I copied a `cd path && make` build chain"
1161        // idiom) silently passes every prior arm because
1162        // `Path::is_absolute` returns false on `..`, `&` is neither a
1163        // leading-byte sentinel nor a control byte nor `\` nor
1164        // `<` / `>` nor `|` nor `;`, and the value's last byte isn't `/`.
1165        // The resolver folds the value through
1166        // `Path::new(caminho).join(<file>)` looking for a literal
1167        // `./../caixa-teia & sleep 1` subdirectory and fails at resolve
1168        // time with a non-self-locating `No such file or directory`
1169        // error far from the source caixa.lisp.
1170        //
1171        // The lacre pipeline embeds the value verbatim in its per-dep
1172        // content-address (`conteudo: format!("path:{caminho}")`,
1173        // caixa-resolver/src/resolve.rs:189), so an `&` byte lands in
1174        // the BLAKE3 closure and rides downstream as part of the build's
1175        // identity into every shell-spawned subprocess (the
1176        // caixa-resolver's `git clone` invocation, a future `feira tofu`
1177        // shell-out, a future operator-side `nix flake check` spawn) as
1178        // the canonical shell-metachar injection surface every peer
1179        // single-token-shaped typed slot already closes. The peer
1180        // path-shaped axis [`crate::render::is_gateway_api_http_path`]
1181        // (caixa-core/src/render.rs:506) rejects `&` as part of its
1182        // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1183        // `:caminho` axis was the last typed path-string surface still
1184        // admitting this byte; this arm closes the gap so the
1185        // substrate-wide "no shell-composition metacharacter anywhere
1186        // in a typed string slot that flows verbatim into a
1187        // shell-spawned subprocess" invariant extends from
1188        // shell-command-separator (`;`) to shell-background /
1189        // logical-AND (`&`) on the `:caminho` axis.
1190        //
1191        // The arm fires AFTER the shell-command-separator arm because
1192        // the prior arm's `cmd-a; cmd-b` shape is the more common
1193        // shell-history paste idiom on values that probe as both
1194        // (`"../caixa-teia; rm & sleep"` carries both `;` and `&` — the
1195        // command-separator-tail paste is the load-bearing root-cause
1196        // edit, so `FonteCaminhoShellSemicolon` wins; same cascade
1197        // discipline every prior `:caminho` arm establishes). The arm
1198        // fires BEFORE the trailing-`/` arm because the embedded
1199        // background / list-AND byte is the more semantic-locating axis
1200        // on probe-as-both values (`"../foo&bar/"` ends in `/` but the
1201        // load-bearing diagnostic is the embedded `&` shell-background
1202        // / logical-AND metachar — the trailing `/` is the secondary
1203        // observation, and an author who removes the `&` is likely to
1204        // also tab-strip the trailing separator).
1205        for &b in caminho.as_bytes() {
1206            if b == b'&' {
1207                return Err(DepError::FonteCaminhoShellBackground {
1208                    nome: nome.to_string(),
1209                    caminho: caminho.to_string(),
1210                });
1211            }
1212        }
1213        // Reproducibility gate's shell-command-substitution arm. The
1214        // e12e4f3 shell-background / logical-AND arm closes the `&`
1215        // byte; the backtick (`0x60`) is the orthogonal POSIX legacy
1216        // command-substitution sentinel — every POSIX shell (sh /
1217        // bash / zsh / dash / ksh / fish / nushell) lexes the byte as
1218        // the canonical legacy wrapper that runs the enclosed command
1219        // and substitutes its standard-output verbatim into the
1220        // surrounding word (a `whoami` wrapped in backticks expands
1221        // to the current user's name; a `cat /etc/passwd` wrapped in
1222        // backticks expands to the file's contents — the canonical
1223        // CWE-78 shell-command-injection vector every shell-side
1224        // hardening guide enumerates first). POSIX
1225        // `std::path::Path` treats backtick as a literal path-
1226        // component byte (so `../caixa-teia/<backtick>whoami<backtick>`
1227        // is one directory named literally that, sibling of `.` and
1228        // `..`).
1229        //
1230        // A `:caminho "../caixa-teia/<backtick>whoami<backtick>"` (the
1231        // canonical "I pasted a shell one-liner carrying a backticked
1232        // `whoami` command-substitution expansion into the `:caminho`
1233        // slot" footgun) or `:caminho "<backtick>pwd<backtick>/caixa-
1234        // teia"` (the symmetric "I copied a `<backtick>pwd<backtick>/
1235        // path` working-directory expansion") silently passes every
1236        // prior arm because `Path::is_absolute` returns false on
1237        // `..`, the backtick byte is neither a leading-byte sentinel
1238        // (the f4efe9c `FonteCaminhoVarExpansion` arm catches the
1239        // modern `$()` form at leading position only; backtick is
1240        // the orthogonal legacy form) nor a control byte nor `\` nor
1241        // `<` / `>` nor `|` nor `;` nor `&`, and the value's last
1242        // byte isn't `/`. The resolver folds the value through
1243        // `Path::new(caminho).join(<file>)` looking for a literal
1244        // subdirectory whose name embeds the backticked token and
1245        // fails at resolve time with a non-self-locating `No such
1246        // file or directory` error far from the source caixa.lisp.
1247        //
1248        // The lacre pipeline embeds the value verbatim in its per-
1249        // dep content-address (`conteudo: format!("path:{caminho}")`,
1250        // caixa-resolver/src/resolve.rs:189), so a backtick byte
1251        // lands in the BLAKE3 closure and rides downstream as part
1252        // of the build's identity into every shell-spawned
1253        // subprocess (the caixa-resolver's `git clone` invocation, a
1254        // future `feira tofu` shell-out, a future operator-side
1255        // `nix flake check` spawn) as the canonical shell-metachar
1256        // injection surface every peer single-token-shaped typed
1257        // slot already closes. The peer path-shaped axis
1258        // [`crate::render::is_gateway_api_http_path`]
1259        // (caixa-core/src/render.rs:506) rejects backtick as part of
1260        // its eleven-byte RFC-3986-reserved set on `:entrada
1261        // :paths`. The `:caminho` axis was the last typed path-
1262        // string surface still admitting this byte; this arm closes
1263        // the gap so the substrate-wide "no shell-composition
1264        // metacharacter anywhere in a typed string slot that flows
1265        // verbatim into a shell-spawned subprocess" invariant
1266        // extends from shell-background / logical-AND (`&`) to
1267        // shell-command-substitution (backtick) on the `:caminho`
1268        // axis.
1269        //
1270        // The arm fires AFTER the shell-background arm because the
1271        // prior arm's `cmd & sleep` shape is the more common shell-
1272        // history paste idiom on values that probe as both (a
1273        // `"../caixa-teia & <backtick>whoami<backtick>"` carries
1274        // both `&` and a backtick — the background-launch tail is
1275        // the load-bearing root-cause edit, so
1276        // `FonteCaminhoShellBackground` wins; same cascade
1277        // discipline every prior `:caminho` arm establishes). The
1278        // arm fires BEFORE the trailing-`/` arm because the
1279        // embedded command-substitution byte is the more semantic-
1280        // locating axis on probe-as-both values (a
1281        // `"../<backtick>whoami<backtick>/"` ends in `/` but the
1282        // load-bearing diagnostic is the embedded backtick shell-
1283        // command-substitution metachar — the trailing `/` is the
1284        // secondary observation, and an author who removes the
1285        // backtick is likely to also tab-strip the trailing
1286        // separator).
1287        for &b in caminho.as_bytes() {
1288            if b == b'`' {
1289                return Err(DepError::FonteCaminhoShellCommandSubstitution {
1290                    nome: nome.to_string(),
1291                    caminho: caminho.to_string(),
1292                });
1293            }
1294        }
1295        // Reproducibility gate's shell-glob arm. The c4d62b3 shell-command-
1296        // substitution arm closes the backtick byte; `*` (`0x2A`) and `?`
1297        // (`0x3F`) are the orthogonal POSIX glob-expansion sentinels — same
1298        // paste-from-shell-prompt footgun class, different syntactic surface.
1299        // Every POSIX shell (sh / bash / zsh / dash / ksh / fish / nushell)
1300        // lexes `*` and `?` as pathname-expansion wildcards: `*` matches any
1301        // sequence of characters in a path component (including the empty
1302        // sequence), `?` matches exactly one character. POSIX
1303        // `std::path::Path` treats both bytes as literal path-component bytes
1304        // (so `../caixa-teia/*.lisp` is one directory named literally
1305        // `../caixa-teia/*.lisp`, sibling of `.` and `..`).
1306        //
1307        // A `:caminho "../caixa-teia/*"` (the canonical "I pasted a
1308        // `ls ../caixa-teia/*` shell-listing one-liner into the `:caminho`
1309        // slot" footgun) or `:caminho "../foo?"` (the symmetric "I copied a
1310        // `rm foo?` single-char-wildcard removal idiom") silently passes
1311        // every prior arm because `Path::is_absolute` returns false on `..`,
1312        // `*` / `?` are neither leading-byte sentinels nor control bytes nor
1313        // `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick, and the
1314        // value's last byte isn't `/`. The resolver folds the value through
1315        // `Path::new(caminho).join(<file>)` looking for a literal
1316        // `./../caixa-teia/*` subdirectory and fails at resolve time with a
1317        // non-self-locating `No such file or directory` error far from the
1318        // source caixa.lisp.
1319        //
1320        // The lacre pipeline embeds the value verbatim in its per-dep
1321        // content-address (`conteudo: format!("path:{caminho}")`,
1322        // caixa-resolver/src/resolve.rs:189), so a `*` or `?` byte lands in
1323        // the BLAKE3 closure and rides downstream as part of the build's
1324        // identity into every shell-spawned subprocess (the caixa-resolver's
1325        // `git clone` invocation, a future `feira tofu` shell-out, a future
1326        // operator-side `nix flake check` spawn) as the canonical
1327        // shell-metachar / pathname-expansion surface every peer
1328        // single-token-shaped typed slot already closes. The peer path-shaped
1329        // axis [`crate::render::is_gateway_api_http_path`]
1330        // (caixa-core/src/render.rs:506) rejects `*` and `?` as part of its
1331        // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1332        // `:caminho` axis was the last typed path-string surface still
1333        // admitting these two bytes; this arm closes the gap so the
1334        // substrate-wide "no shell-composition / glob-expansion
1335        // metacharacter anywhere in a typed string slot that flows verbatim
1336        // into a shell-spawned subprocess" invariant extends from
1337        // shell-command-substitution (backtick) to glob-expansion
1338        // (`*` / `?`) on the `:caminho` axis.
1339        //
1340        // The arm fires AFTER the backtick arm because the prior arm's
1341        // CWE-78 shell-command-injection vector is the load-bearing
1342        // diagnostic on values that probe as both (a `"../`whoami`/*"`
1343        // carries both backtick and `*` — the command-substitution paste
1344        // is the load-bearing root-cause edit, so
1345        // `FonteCaminhoShellCommandSubstitution` wins; same cascade
1346        // discipline every prior `:caminho` arm establishes). The arm
1347        // fires BEFORE the trailing-`/` arm because the embedded glob
1348        // byte is the more semantic-locating axis on probe-as-both values
1349        // (`"../foo*/"` ends in `/` but the load-bearing diagnostic is the
1350        // embedded `*` glob metachar — the trailing `/` is the secondary
1351        // observation, and an author who removes the `*` is likely to
1352        // also tab-strip the trailing separator).
1353        for &b in caminho.as_bytes() {
1354            if b == b'*' || b == b'?' {
1355                return Err(DepError::FonteCaminhoShellGlob {
1356                    nome: nome.to_string(),
1357                    caminho: caminho.to_string(),
1358                    byte: b,
1359                });
1360            }
1361        }
1362        // Reproducibility gate's shell-subshell-grouping arm. The cf9034b
1363        // shell-glob arm closes the `*` / `?` pathname-expansion sentinels;
1364        // `(` (`0x28`) and `)` (`0x29`) are the orthogonal POSIX subshell-
1365        // grouping sentinels — same paste-from-shell-prompt footgun class,
1366        // different syntactic surface. Every POSIX shell (sh / bash / zsh /
1367        // dash / ksh / fish / nushell) lexes the parenthesis pair as the
1368        // subshell-grouping operator: `(<cmd>)` runs `<cmd>` in a child
1369        // shell with a fresh environment scope (the canonical sandboxing
1370        // idiom every shell-history `(cd <path> && <cmd>)` one-liner uses
1371        // to scope a `cd` to one subshell without disturbing the parent's
1372        // working directory), and `$(<cmd>)` is the modern Bourne
1373        // command-substitution shape the upstream f4efe9c
1374        // `FonteCaminhoVarExpansion` arm closes the leading `$` byte of —
1375        // the closing `)` byte completes that substitution shape and must
1376        // be refused on the same axis (peer with the
1377        // [`crate::render::is_git_repo_url`] 3b99147 arm that closes the
1378        // same byte-pair on the sibling `:fonte :repo` axis under the
1379        // same shell-subshell-grouping + RFC-3986-sub-delims banner).
1380        // POSIX `std::path::Path` treats both bytes as literal path-
1381        // component bytes (so `../caixa-teia/(date)` is one directory
1382        // named literally `../caixa-teia/(date)`, sibling of `.` and
1383        // `..`).
1384        //
1385        // A `:caminho "../caixa-teia/$(date)/build"` (the canonical "I
1386        // pasted a `cd ../caixa-teia/$(date)/build` shell-history one-
1387        // liner whose modern command-substitution expansion lands the
1388        // current date as a subdirectory name" footgun) or `:caminho
1389        // "../(cd foo && pwd)/caixa-teia"` (the symmetric "I copied a
1390        // `(cd foo && pwd)` subshell-grouping working-directory probe
1391        // idiom") silently passes every prior arm because
1392        // `Path::is_absolute` returns false on `..`, `(` / `)` are
1393        // neither leading-byte sentinels nor control bytes nor `\` nor
1394        // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` / `?`,
1395        // and the value's last byte isn't `/`. The resolver folds the
1396        // value through `Path::new(caminho).join(<file>)` looking for a
1397        // literal `./../caixa-teia/$(date)/build` subdirectory and fails
1398        // at resolve time with a non-self-locating `No such file or
1399        // directory` error far from the source caixa.lisp.
1400        //
1401        // The lacre pipeline embeds the value verbatim in its per-dep
1402        // content-address (`conteudo: format!("path:{caminho}")`,
1403        // caixa-resolver/src/resolve.rs:189), so a `(` or `)` byte lands
1404        // in the BLAKE3 closure and rides downstream as part of the
1405        // build's identity into every shell-spawned subprocess (the
1406        // caixa-resolver's `git clone` invocation, a future `feira tofu`
1407        // shell-out, a future operator-side `nix flake check` spawn) as
1408        // the canonical shell-metachar / subshell-grouping surface every
1409        // peer single-token-shaped typed slot already closes. The peer
1410        // git-source axis [`crate::render::is_git_repo_url`] (3b99147)
1411        // rejects the same byte pair on `:fonte :repo` under the same
1412        // shell-subshell-grouping / RFC-3986-sub-delims banner. The
1413        // `:caminho` axis was the last typed path-string surface still
1414        // admitting these two bytes;
1415        // this arm closes the gap so the substrate-wide "no shell-
1416        // composition metacharacter anywhere in a typed string slot that
1417        // flows verbatim into a shell-spawned subprocess" invariant
1418        // extends from shell-glob (`*` / `?`) to shell-subshell-grouping
1419        // (`(` / `)`) on the `:caminho` axis. Together with the f4efe9c
1420        // leading-`$` arm, the typed `:caminho` accepted set now
1421        // structurally excludes the entire modern Bourne
1422        // command-substitution surface — leading `$` closes the
1423        // leading byte of every `$(<cmd>)` shape, this arm closes the
1424        // trailing `)` boundary.
1425        //
1426        // The arm fires AFTER the shell-glob arm because the prior arm's
1427        // `*` / `?` pathname-expansion shape is the more common shell-
1428        // history paste idiom on values that probe as both
1429        // (`"../caixa-teia/*(date)"` carries both `*` and `(` — the
1430        // glob-paste-tail is the load-bearing root-cause edit, so
1431        // `FonteCaminhoShellGlob` wins; same cascade discipline every
1432        // prior `:caminho` arm establishes). The arm fires BEFORE the
1433        // trailing-`/` arm because the embedded subshell-grouping byte
1434        // is the more semantic-locating axis on probe-as-both values
1435        // (`"../foo(date)/"` ends in `/` but the load-bearing diagnostic
1436        // is the embedded `(` shell-subshell-grouping metachar — the
1437        // trailing `/` is the secondary observation, and an author who
1438        // removes the `(` is likely to also tab-strip the trailing
1439        // separator).
1440        for &b in caminho.as_bytes() {
1441            if b == b'(' || b == b')' {
1442                return Err(DepError::FonteCaminhoShellSubshellGrouping {
1443                    nome: nome.to_string(),
1444                    caminho: caminho.to_string(),
1445                    byte: b,
1446                });
1447            }
1448        }
1449        // Reproducibility gate's shell-brace-expansion arm. The 0633c91
1450        // shell-subshell-grouping arm closes `(` / `)`; `{` (`0x7b`) and
1451        // `}` (`0x7d`) are the orthogonal shell-brace-expansion /
1452        // URI-Template-placeholder byte pair — same paste-from-shell-
1453        // prompt + paste-from-templated-doc footgun class, different
1454        // syntactic surface. Every POSIX-derived shell that implements
1455        // brace expansion (bash / zsh / ksh / fish; the canonical
1456        // `mkdir -p ../{caixa-teia,caixa-helm,caixa-flux}` /
1457        // `cp file{,.bak}` idiom every shell-history block carries)
1458        // expands `{a,b,c}` to the cross-product of its comma-separated
1459        // members and `{1..10}` to the integer range; RFC 6570 reserves
1460        // the matched pair for URI Template placeholders (the canonical
1461        // `https://{host}/{org}/{repo}` substitution shape every
1462        // OpenAPI / Swagger / Postman / GitHub Octokit client /
1463        // Helm chart-URL fragment / Mustache `{{org}}` doubled-brace
1464        // form carries), and Tera / Jinja2 / Handlebars / Go html/template
1465        // every IaC tool (Helm, Kustomize, Terraform's `${var}` cousin
1466        // shape) emit. POSIX `std::path::Path` treats both bytes as
1467        // literal path-component bytes (so `../{caixa-teia,caixa-helm}`
1468        // is one directory named literally `../{caixa-teia,caixa-helm}`,
1469        // sibling of `.` and `..`).
1470        //
1471        // A `:caminho "../{caixa-teia,caixa-helm}/build"` (the canonical
1472        // "I pasted a `cd ../{caixa-teia,caixa-helm}` shell brace-
1473        // expansion one-liner that fans across two siblings" footgun)
1474        // or `:caminho "../{{org}}/caixa-teia"` (the symmetric "I copied
1475        // a `{{org}}` Mustache / Helm template placeholder out of a
1476        // README quick-start and forgot to substitute") silently passes
1477        // every prior arm because `Path::is_absolute` returns false on
1478        // `..`, `{` / `}` are neither leading-byte sentinels nor control
1479        // bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor
1480        // backtick nor `*` / `?` nor `(` / `)`, and the value's last
1481        // byte isn't `/`. The resolver folds the value through
1482        // `Path::new(caminho).join(<file>)` looking for a literal
1483        // `./../{caixa-teia,caixa-helm}/build` subdirectory and fails
1484        // at resolve time with a non-self-locating `No such file or
1485        // directory` error far from the source caixa.lisp.
1486        //
1487        // The lacre pipeline embeds the value verbatim in its per-dep
1488        // content-address (`conteudo: format!("path:{caminho}")`,
1489        // caixa-resolver/src/resolve.rs:189), so a `{` or `}` byte
1490        // lands in the BLAKE3 closure and rides downstream as part of
1491        // the build's identity into every shell-spawned subprocess
1492        // (the caixa-resolver's `git clone` invocation, a future
1493        // `feira tofu` shell-out, a future operator-side `nix flake
1494        // check` spawn) as the canonical shell-metachar / brace-
1495        // expansion surface every peer single-token-shaped typed
1496        // slot already closes. The peer git-source axis
1497        // [`crate::render::is_git_repo_url`] (42d8f9d — the URI Template
1498        // placeholder arm) rejects the same byte pair on `:fonte :repo`
1499        // under the same RFC-3986-'delims' / RFC-6570-URI-Template /
1500        // shell-brace-expansion banner. The `:caminho` axis was the last
1501        // typed path-string surface still admitting these two bytes;
1502        // this arm closes the gap so the substrate-wide "no shell-
1503        // composition metacharacter anywhere in a typed string slot
1504        // that flows verbatim into a shell-spawned subprocess"
1505        // invariant extends from shell-subshell-grouping (`(` / `)`)
1506        // to shell-brace-expansion (`{` / `}`) on the `:caminho` axis,
1507        // and the typed `:caminho` accepted set now also structurally
1508        // excludes the URI Template / templating-engine placeholder
1509        // surface that would silently round-trip through any
1510        // downstream IaC templating-engine layer.
1511        //
1512        // The arm fires AFTER the shell-subshell-grouping arm because
1513        // the prior arm's `(` / `)` shape is the more semantic-locating
1514        // axis on values that probe as both (`"../{cd foo}(date)"`
1515        // carries both `{` and `(` — the parenthesis-pair is the
1516        // load-bearing modern-Bourne-command-substitution surface the
1517        // prior arm closes; same cascade discipline every prior
1518        // `:caminho` arm establishes). The arm fires BEFORE the
1519        // trailing-`/` arm because the embedded brace-expansion byte
1520        // is the more semantic-locating axis on probe-as-both values
1521        // (`"../{caixa-teia,caixa-helm}/"` ends in `/` but the
1522        // load-bearing diagnostic is the embedded `{` brace-expansion
1523        // metachar — the trailing `/` is the secondary observation,
1524        // and an author who removes the `{` is likely to also tab-
1525        // strip the trailing separator).
1526        for &b in caminho.as_bytes() {
1527            if b == b'{' || b == b'}' {
1528                return Err(DepError::FonteCaminhoShellBraceExpansion {
1529                    nome: nome.to_string(),
1530                    caminho: caminho.to_string(),
1531                    byte: b,
1532                });
1533            }
1534        }
1535        // Reproducibility gate's shell-bracket-expansion arm. The 598b770
1536        // shell-brace-expansion arm closes `{` / `}`; `[` (`0x5b`) and
1537        // `]` (`0x5d`) are the orthogonal POSIX glob-character-class /
1538        // shell-`test`-builtin byte pair — same paste-from-shell-prompt
1539        // footgun class, different syntactic surface. Every POSIX shell
1540        // (sh / bash / zsh / dash / ksh / fish / nushell) lexes the
1541        // bracket pair as the glob character-class operator: `[abc]`
1542        // matches one of `a`, `b`, `c`; `[a-z]` matches any lowercase
1543        // ASCII letter; `[^x]` negates (the canonical
1544        // `ls *.[ch]` C-source-file glob and the `cd ../[a-z]*`
1545        // lowercase-sibling glob every shell-history block carries —
1546        // the orthogonal axis to the cf9034b `*` / `?` shell-glob arm
1547        // closing the unbounded pathname-expansion sentinels). The
1548        // bracket pair additionally carries the POSIX `test` /
1549        // `[` builtin command (`[ -d ../caixa-teia ] && cd ...` —
1550        // the canonical idiom every shell-script conditional uses) and
1551        // bash's `[[ ... ]]` extended-test grammar. Beyond shell, the
1552        // bracket pair is the TOML inline-array delimiter
1553        // (`features = ["a", "b"]` — the canonical paste-from-Cargo-
1554        // manifest cross-idiom-leak vector), the YAML flow-sequence
1555        // delimiter (`paths: [/a, /b]` — the canonical paste-from-
1556        // values.yaml cross-idiom leak), the JSON array delimiter,
1557        // and the POSIX-ERE / PCRE bracket-expression / character-
1558        // class anchor (the canonical paste-from-regex-doc shape).
1559        // POSIX `std::path::Path` treats both bytes as literal path-
1560        // component bytes (so `../[caixa-teia]` is one directory
1561        // named literally `../[caixa-teia]`, sibling of `.` and
1562        // `..`).
1563        //
1564        // A `:caminho "../caixa-[a-z]/build"` (the canonical "I
1565        // pasted a `cd ../caixa-[a-z]/build` glob-character-class
1566        // one-liner that matches every lowercase-sibling-suffix
1567        // sibling directory" footgun), `:caminho "../[caixa-teia]/
1568        // build"` (the symmetric "I pasted a TOML inline-array /
1569        // YAML flow-sequence shape out of an aligned manifest"
1570        // idiom), or `:caminho "../caixa-[ch]"` (the canonical
1571        // `*.[ch]` C-source character-class paste-from-shell-history
1572        // shape) silently passes every prior arm because
1573        // `Path::is_absolute` returns false on `..`, `[` / `]` are
1574        // neither leading-byte sentinels nor control bytes nor `\`
1575        // nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1576        // `*` / `?` nor `(` / `)` nor `{` / `}`, and the value's
1577        // last byte isn't `/`. The resolver folds the value through
1578        // `Path::new(caminho).join(<file>)` looking for a literal
1579        // `./../caixa-[a-z]/build` subdirectory and fails at resolve
1580        // time with a non-self-locating `No such file or directory`
1581        // error far from the source caixa.lisp.
1582        //
1583        // The lacre pipeline embeds the value verbatim in its per-dep
1584        // content-address (`conteudo: format!("path:{caminho}")`,
1585        // caixa-resolver/src/resolve.rs:189), so a `[` or `]` byte
1586        // lands in the BLAKE3 closure and rides downstream as part of
1587        // the build's identity into every shell-spawned subprocess
1588        // (the caixa-resolver's `git clone` invocation, a future
1589        // `feira tofu` shell-out, a future operator-side `nix flake
1590        // check` spawn) as the canonical shell-metachar / glob-
1591        // character-class / TOML-array surface every peer single-
1592        // token-shaped typed slot already closes. The `:caminho` axis
1593        // was the last typed path-string surface still admitting
1594        // these two bytes; this arm closes the gap so the substrate-
1595        // wide "no shell-composition metacharacter anywhere in a
1596        // typed string slot that flows verbatim into a shell-spawned
1597        // subprocess" invariant extends from shell-brace-expansion
1598        // (`{` / `}`) to shell-bracket-expansion (`[` / `]`) on the
1599        // `:caminho` axis. Together with the cf9034b `*` / `?` arm,
1600        // the typed `:caminho` accepted set now structurally excludes
1601        // the entire POSIX pathname-expansion / glob surface —
1602        // unbounded glob (`*` / `?`) AND bounded character-class
1603        // (`[abc]` / `[a-z]`).
1604        //
1605        // The arm fires AFTER the shell-brace-expansion arm because
1606        // the prior arm's `{` / `}` shape is the more semantic-
1607        // locating axis on values that probe as both
1608        // (`"../{a,b}[ch]"` carries both `{` and `[` — the brace-
1609        // expansion fan is the load-bearing root-cause edit, so
1610        // `FonteCaminhoShellBraceExpansion` wins; same cascade
1611        // discipline every prior `:caminho` arm establishes). The arm
1612        // fires BEFORE the trailing-`/` arm because the embedded
1613        // bracket-expansion byte is the more semantic-locating axis
1614        // on probe-as-both values (`"../[a-z]/"` ends in `/` but the
1615        // load-bearing diagnostic is the embedded `[` glob-character-
1616        // class metachar — the trailing `/` is the secondary
1617        // observation, and an author who removes the `[` is likely
1618        // to also tab-strip the trailing separator).
1619        for &b in caminho.as_bytes() {
1620            if b == b'[' || b == b']' {
1621                return Err(DepError::FonteCaminhoShellBracketExpansion {
1622                    nome: nome.to_string(),
1623                    caminho: caminho.to_string(),
1624                    byte: b,
1625                });
1626            }
1627        }
1628        // Reproducibility gate's shell-quote-grouping arm. The 986963b
1629        // shell-bracket-expansion arm closes `[` / `]`; `'` (`0x27`) and
1630        // `"` (`0x22`) are the orthogonal POSIX shell-string-literal
1631        // delimiter pair — same paste-from-shell-prompt footgun class,
1632        // different syntactic surface. Every POSIX shell (sh / bash /
1633        // zsh / dash / ksh / fish / nushell) lexes the pair as the
1634        // string-literal quoting operator: `'…'` is the strong
1635        // (no-expansion) single-quoted string and `"…"` is the weak
1636        // (variable-/command-substitution-preserving) double-quoted
1637        // string — the canonical `cd '../caixa-teia'` shell-history
1638        // idiom every path-with-embedded-whitespace paste block carries,
1639        // and the symmetric `git clone "$REPO"` weak-quoted CI-manifest
1640        // shape. Beyond shell, the two bytes carry the JSON string-literal
1641        // delimiter (`"key": "value"` — the canonical paste-from-JSON-
1642        // config cross-idiom-leak vector), the YAML double-quoted +
1643        // single-quoted flow-scalar delimiters (`path: "../caixa-teia"`
1644        // — the canonical paste-from-values.yaml / paste-from-K8s-YAML-
1645        // manifest cross-idiom leak), the TOML basic + literal string
1646        // delimiters (`path = "../caixa-teia"` — the canonical paste-
1647        // from-Cargo-manifest cross-idiom-leak vector), the tatara-lisp
1648        // string-literal delimiter itself (`(:caminho "../caixa-teia")`
1649        // — the canonical "I copied the entire `:caminho "..."` slot
1650        // rather than just the string body" author-surface footgun),
1651        // and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which
1652        // excludes both bytes from the `unreserved / pct-encoded /
1653        // sub-delims / ":" / "@"` `pchar` production. POSIX
1654        // `std::path::Path` treats both bytes as literal path-component
1655        // bytes (so `../"caixa-teia"` is one directory named literally
1656        // `../"caixa-teia"`, sibling of `.` and `..`).
1657        //
1658        // A `:caminho "'../caixa-teia'"` (the canonical "I pasted a
1659        // `cd '../caixa-teia'` shell-history one-liner whose strong-
1660        // quoting preserved the sibling-workspace path verbatim across
1661        // the whitespace paste boundary" footgun), `:caminho
1662        // "\"../caixa-teia\""` (the symmetric weak-quoted paste-from-
1663        // JSON / paste-from-YAML flow-scalar / paste-from-TOML basic-
1664        // string / paste-from-tatara-lisp string-literal cross-idiom-
1665        // leak shape), or `:caminho "../\"caixa-teia\""` (the embedded-
1666        // quote "I pasted a JSON key-value pair fragment into the
1667        // middle of the path" idiom) silently passes every prior arm
1668        // because `Path::is_absolute` returns false on `..` / `'` /
1669        // `"`, `'` / `"` are neither leading-byte sentinels nor
1670        // control bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&`
1671        // nor backtick nor `*` / `?` nor `(` / `)` nor `{` / `}` nor
1672        // `[` / `]`, and the value's last byte isn't `/`. The resolver
1673        // folds the value through `Path::new(caminho).join(<file>)`
1674        // looking for a literal `./'../caixa-teia'` subdirectory and
1675        // fails at resolve time with a non-self-locating `No such file
1676        // or directory` error far from the source caixa.lisp.
1677        //
1678        // The lacre pipeline embeds the value verbatim in its per-dep
1679        // content-address (`conteudo: format!("path:{caminho}")`,
1680        // caixa-resolver/src/resolve.rs:189), so a `'` or `"` byte
1681        // lands in the BLAKE3 closure and rides downstream as part of
1682        // the build's identity into every shell-spawned subprocess
1683        // (the caixa-resolver's `git clone` invocation, a future
1684        // `feira tofu` shell-out, a future operator-side `nix flake
1685        // check` spawn) as the canonical shell-metachar / string-
1686        // literal-delimiter surface every peer single-token-shaped
1687        // typed slot already closes. The peer `:fonte :repo` axis
1688        // closes both bytes under the same shell-quote-grouping /
1689        // RFC-3986-sub-delims banner (e7a109f `'` shell-single-quote
1690        // + 4267d8b `"` shell-double-quote on `is_git_repo_url`). The
1691        // `:caminho` axis was the last typed path-string surface
1692        // still admitting these two bytes; this arm closes the gap
1693        // so the substrate-wide "no shell-composition metacharacter
1694        // anywhere in a typed string slot that flows verbatim into a
1695        // shell-spawned subprocess" invariant extends from shell-
1696        // bracket-expansion (`[` / `]`) to shell-quote-grouping (`'`
1697        // / `"`) on the `:caminho` axis. Together with the peer
1698        // JSON / YAML / TOML string-literal delimiters closing at
1699        // this arm and the 598b770 `{` / `}` brace-expansion arm
1700        // closing the templating-engine-placeholder boundary, the
1701        // typed `:caminho` accepted set now structurally excludes
1702        // the entire cross-config-DSL string-literal / templating
1703        // paste-from-aligned-manifest cross-idiom-leak surface that
1704        // would silently round-trip through any downstream JSON /
1705        // YAML / TOML / HCL / tatara-lisp parsing layer.
1706        //
1707        // The arm fires AFTER the shell-bracket-expansion arm because
1708        // the prior arm's `[` / `]` shape is the more semantic-
1709        // locating axis on values that probe as both (`"../[a-z]'x'"`
1710        // carries both `[` and `'` — the glob-character-class
1711        // expansion is the load-bearing root-cause edit, so
1712        // `FonteCaminhoShellBracketExpansion` wins; same cascade
1713        // discipline every prior `:caminho` arm establishes). The arm
1714        // fires BEFORE the trailing-`/` arm because the embedded
1715        // quote-grouping byte is the more semantic-locating axis on
1716        // probe-as-both values (`"../'caixa-teia'/"` ends in `/` but
1717        // the load-bearing diagnostic is the embedded `'` shell-
1718        // string-literal metachar — the trailing `/` is the secondary
1719        // observation, and an author who removes the `'` is likely to
1720        // also tab-strip the trailing separator).
1721        for &b in caminho.as_bytes() {
1722            if b == b'\'' || b == b'"' {
1723                return Err(DepError::FonteCaminhoShellQuoteGrouping {
1724                    nome: nome.to_string(),
1725                    caminho: caminho.to_string(),
1726                    byte: b,
1727                });
1728            }
1729        }
1730        // Reproducibility gate's shell-comment / URL-fragment / YAML-comment arm.
1731        // The d14cbc5 shell-quote-grouping arm closes `'` / `"`; `#` (`0x23`) is
1732        // the orthogonal "byte at which four distinct downstream parsers all
1733        // truncate the value at the first occurrence" surface, and no prior arm
1734        // has covered it on the `:caminho` axis. Every POSIX shell (sh / bash /
1735        // zsh / dash / ksh / fish / nushell) lexes an unquoted `#` at the head
1736        // of a word (or after unquoted whitespace) as the comment-lead: from
1737        // that byte to the end of the physical line is a comment discarded
1738        // before command parsing (`cd ../caixa-teia  # legacy sibling` — the
1739        // canonical paste-from-shell-history-with-trailing-annotation shape
1740        // every operator-notebook and CI-manifest carries; POSIX.1-2017 §2.3
1741        // Token Recognition step 6). YAML 1.2 §6.6 makes `#` the comment lead
1742        // at any position preceded by whitespace or at line-start (`path:
1743        // ../caixa-teia  # pin` — the canonical paste-from-values.yaml /
1744        // paste-from-K8s-manifest cross-idiom-leak shape). tatara-lisp itself
1745        // treats `;` as the comment-lead but a growing number of consumer
1746        // config-DSL layers (HCL, Terraform, Nix flake attributes, .env
1747        // dotenv-style files, gitconfig / .gitignore, ini / TOML) use `#` as
1748        // the comment-lead too — the pair extends the cross-config-DSL
1749        // paste-idiom surface the d14cbc5 quote-grouping arm and the 598b770
1750        // brace-expansion arm already cover on adjacent axes. RFC 3986 §3.5
1751        // reserves `#` as the URL fragment-identifier delimiter (the canonical
1752        // paste-from-browser-address-bar `github.com/foo/bar#readme` /
1753        // `github.com/foo/bar#L42` permalink shape, and the symmetric
1754        // Nix-flake-ref cross-idiom leak `github:foo/bar#packageName` where
1755        // `#` selects a flake output — the same axis the peer
1756        // [`crate::render::is_git_repo_url`] closes on the `:fonte :repo`
1757        // surface at a68f818 with the same downstream-drops-the-tail
1758        // rationale).
1759        //
1760        // POSIX `std::path::Path` treats `#` as a literal path-component byte,
1761        // so a `:caminho "../caixa-teia # legacy sibling"` (the canonical
1762        // paste-from-shell-history-with-trailing-annotation footgun),
1763        // `:caminho "../caixa-teia  # pin"` (the symmetric YAML flow-scalar
1764        // paste-with-trailing-comment shape), or `:caminho "../caixa-teia
1765        // #readme"` (the URL fragment paste-from-browser-address-bar shape)
1766        // silently passes every prior arm because `Path::is_absolute` returns
1767        // false on `..`, `#` is neither a leading-byte sentinel nor a control
1768        // byte nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1769        // `*` / `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` / `"`,
1770        // and the value's last byte isn't `/`. The resolver folds the value
1771        // through `Path::new(caminho).join(<file>)` looking for a literal
1772        // subdirectory named `../caixa-teia # legacy sibling` and fails at
1773        // resolve time with a non-self-locating `No such file or directory`
1774        // error far from the source caixa.lisp — while every downstream
1775        // shell / YAML / URL parser silently truncates the value at the `#`
1776        // byte to `../caixa-teia`, so a `feira tofu` shell-out to a
1777        // `cd '{caminho}'` command line and a `nix flake check` invocation on
1778        // an emitted YAML `path:` scalar disagree with the resolver on which
1779        // directory the value names. Two workstations whose downstream
1780        // shell / YAML / URL parsing layers differ in unquoted-`#`
1781        // recognition emit divergent build artifacts for the byte-identical
1782        // caixa.lisp value.
1783        //
1784        // The lacre pipeline embeds the value verbatim in its per-dep
1785        // content-address (`conteudo: format!("path:{caminho}")`,
1786        // caixa-resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1787        // closure and rides downstream as part of the build's identity into
1788        // every shell-spawned subprocess (the caixa-resolver's `git clone`
1789        // invocation, a future `feira tofu` shell-out, a future operator-side
1790        // `nix flake check` spawn) as the canonical shell-metachar /
1791        // comment-lead / URL-fragment-delimiter surface every peer
1792        // single-token-shaped typed slot already closes. The peer `:fonte
1793        // :repo` axis closes the byte under the URL-fragment-identifier
1794        // banner (a68f818 `#` on `is_git_repo_url`); the `:caminho` axis was
1795        // the last typed path-string surface still admitting the byte. This
1796        // arm closes the gap so the substrate-wide "no shell-composition
1797        // metacharacter / comment-lead / URL-fragment-delimiter anywhere in a
1798        // typed string slot that flows verbatim into a shell-spawned
1799        // subprocess or downstream YAML / URL parser" invariant extends from
1800        // shell-quote-grouping (`'` / `"`) to shell-comment / URL-fragment
1801        // (`#`) on the `:caminho` axis. Together with the peer JSON / YAML /
1802        // TOML string-literal delimiters the d14cbc5 quote-grouping arm
1803        // closes and the 598b770 `{` / `}` brace-expansion arm closes on the
1804        // templating-engine-placeholder boundary, the typed `:caminho`
1805        // accepted set now structurally excludes the entire
1806        // paste-with-trailing-annotation / paste-from-URL-permalink /
1807        // paste-from-YAML-comment cross-idiom-leak surface that would
1808        // silently round-trip through any downstream shell / YAML / URL /
1809        // dotenv / gitconfig / HCL parsing layer to a different value than
1810        // the resolver's `Path::join` sees.
1811        //
1812        // The arm fires AFTER the shell-quote-grouping arm because the prior
1813        // arm's `'` / `"` shape is the more semantic-locating axis on values
1814        // that probe as both (`"../'x'#pin"` carries both `'` and `#` — the
1815        // shell-string-literal-delimiter is the load-bearing root-cause edit,
1816        // so `FonteCaminhoShellQuoteGrouping` wins; same cascade discipline
1817        // every prior `:caminho` arm establishes). The arm fires BEFORE the
1818        // trailing-`/` arm because the embedded comment-lead / fragment-
1819        // delimiter byte is the more semantic-locating axis on probe-as-both
1820        // values (`"../caixa-teia#pin/"` ends in `/` but the load-bearing
1821        // diagnostic is the embedded `#` — the trailing `/` is the secondary
1822        // observation, and an author who removes the `#pin` fragment is
1823        // likely to also tab-strip the trailing separator).
1824        for &b in caminho.as_bytes() {
1825            if b == b'#' {
1826                return Err(DepError::FonteCaminhoShellComment {
1827                    nome: nome.to_string(),
1828                    caminho: caminho.to_string(),
1829                    byte: b,
1830                });
1831            }
1832        }
1833        // Reproducibility gate's URL-percent-encoding-escape arm. The 6622063
1834        // shell-comment arm closes the `#` URL-fragment-identifier byte; `%`
1835        // (`0x25`) is the orthogonal RFC 3986 §2.1 URL percent-encoding-escape
1836        // byte — the mandatory encoding mechanism for every byte outside the
1837        // `unreserved` alphanumeric / `-` / `.` / `_` / `~` set, and `%`
1838        // itself must be percent-encoded as `%25` to appear literally inside
1839        // a URL value. The byte carries three distinct render-determinism
1840        // hazards on the `:caminho` axis, no prior arm has covered it, and
1841        // the peer `:fonte :repo` axis (a323db8 `%` on `is_git_repo_url`)
1842        // already closes the same byte under the same URL-percent-encoding
1843        // banner — the `:caminho` axis was the last typed path-string surface
1844        // still admitting the byte.
1845        //
1846        // First, the paste-from-browser-address-bar percent-encoded-space
1847        // footgun: an author copies `../caixa%20teia` out of a URL-encoded
1848        // README hyperlink / a browser address bar / a percent-encoded
1849        // permalink expecting `%20` to decode to a literal space at the
1850        // filesystem layer. POSIX `std::path::Path` treats the byte as a
1851        // literal path-component byte, so `Path::join` looks for a literal
1852        // `./../caixa%20teia` subdirectory and fails at resolve time with a
1853        // non-self-locating `No such file or directory` error far from the
1854        // source caixa.lisp — while the author's mental model was
1855        // `../caixa teia`, the decoded shape. Two authors whose only
1856        // difference is percent-encoding presence resolve to two distinct
1857        // BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`)
1858        // for what they intended as the byte-identical sibling-workspace
1859        // dep. The lacre pipeline embeds the value verbatim in its per-dep
1860        // content-address (`conteudo: format!("path:{caminho}")`,
1861        // caixa-resolver/src/resolve.rs:189), so the divergence rides
1862        // downstream into the BLAKE3 closure and locks the substrate's
1863        // "the lacre is the build's identity" contract (CAIXA-SDLC §III.2)
1864        // to the wrong encoding — the same THEORY.md §V.2 render-
1865        // determinism vector every prior `:caminho` arm protects.
1866        //
1867        // Second, the printf-format-specifier lead footgun: `%` is the C /
1868        // POSIX printf format-directive lead-in (`%s`, `%d`, `%02x`, the
1869        // canonical `printf "path=%s\n" ../caixa-teia` invocation every
1870        // shell-diagnostic one-liner carries) and the printf builtin is
1871        // wired into every POSIX shell (bash / zsh / dash / ksh / busybox
1872        // ash) as the format-string lead. A `:caminho "../caixa-%s-teia"`
1873        // value flowing into any future `feira` verb that shells out with a
1874        // printf-formatted path template silently gets reinterpreted as a
1875        // format-directive rather than a literal byte — the canonical
1876        // CWE-134 format-string-injection vector.
1877        //
1878        // Third, the bash-job-control-specifier lead footgun: bash / zsh /
1879        // ksh reserve `%N` at word-start as the job-control specifier —
1880        // `%1` names "job 1", `%%` names "the current job", `%foo` names
1881        // "the most recent job whose command started with `foo`". A future
1882        // `feira` verb that invokes `kill %1` on a caminho-scoped
1883        // subprocess would silently redirect the signal to a wrong target.
1884        //
1885        // Beyond the three shell-side hazards, `%` is a first-class parser
1886        // byte in three cross-config-DSL layers the substrate's paste-idiom
1887        // surface routinely crosses: YAML 1.2 §6.8.1 lexes `%` at
1888        // line-start as the directive lead (`%YAML 1.2` / `%TAG` — a
1889        // `:caminho "%YAML/1.2/../caixa-teia"` paste from a top-of-doc
1890        // YAML directive block silently trips the YAML directive parser on
1891        // any downstream emitted YAML manifest); Prometheus / Grafana
1892        // template syntax uses `%(var)s` as the substitution lead; and Nix
1893        // interpolation uses `${var}` (not `%`) but Envsubst /
1894        // Kubernetes / OpenShift template layers use `%VAR%` as the
1895        // Windows-shell env-var-reference lead — the paste-from-`.bat` /
1896        // paste-from-PowerShell-`%env:PATH%` cross-idiom leak.
1897        //
1898        // The three malformed-`%HH` classes documented on the peer
1899        // `is_git_repo_url` `%` arm (a323db8) apply here too:
1900        //
1901        //   - The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
1902        //     where `%` isn't followed by two hex digits) — every WHATWG-
1903        //     conformant URL parser rejects the value at parse time per
1904        //     RFC 3986 §2.1, but the byte rides into the lacre before
1905        //     the resolver subprocess crosses the URL-parser boundary.
1906        //   - The over-encoded path-separator shape (`"../caixa%2Fteia"`
1907        //     intending the `%2F` as the URL encoding of `/`) locks a
1908        //     `path:../caixa%2Fteia` BLAKE3 closure that diverges from
1909        //     the byte-identical `path:../caixa/teia` form.
1910        //   - The double-encoded shape (`"../caixa%2520teia"` — the `%25`
1911        //     already itself an encoded `%`, so the intent was likely a
1912        //     literal `%20` that survived one round-trip through a
1913        //     URL-encoder that shouldn't have run) locks a triply-
1914        //     divergent closure across the encoded / once-decoded /
1915        //     twice-decoded chain.
1916        //
1917        // POSIX `std::path::Path` treats the byte as a literal path-
1918        // component byte, so a `:caminho "../caixa%20teia"` (the canonical
1919        // paste-from-browser-address-bar percent-encoded-space footgun),
1920        // `:caminho "%YAML/../caixa-teia"` (the symmetric paste-from-YAML-
1921        // directive-block cross-idiom leak), or `:caminho
1922        // "../caixa-%s-teia"` (the printf-format-specifier paste-from-
1923        // shell-diagnostic-one-liner shape) silently passes every prior arm
1924        // because `Path::is_absolute` returns false on `..`, `%` is neither
1925        // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
1926        // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
1927        // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`, and the
1928        // value's last byte isn't `/`. The resolver folds the value through
1929        // `Path::new(caminho).join(<file>)` looking for a literal
1930        // subdirectory named `../caixa%20teia` and fails at resolve time
1931        // with a non-self-locating `No such file or directory` error far
1932        // from the source caixa.lisp — while every downstream URL parser /
1933        // shell printf builtin / YAML directive parser silently
1934        // reinterprets the byte to a different value than the resolver's
1935        // `Path::join` sees. Two workstations whose downstream URL / shell
1936        // / YAML layers differ in `%HH` recognition emit divergent build
1937        // artifacts for the byte-identical caixa.lisp value.
1938        //
1939        // The lacre pipeline embeds the value verbatim in its per-dep
1940        // content-address (`conteudo: format!("path:{caminho}")`, caixa-
1941        // resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1942        // closure and rides into every shell-spawned subprocess (the
1943        // resolver's `git clone`, a future `feira tofu` shell-out, a
1944        // future operator-side `nix flake check` spawn) as the canonical
1945        // URL-percent-encoding-escape / printf-format-specifier / bash-
1946        // job-control-specifier surface every peer single-token-shaped
1947        // typed slot already closes. This arm closes the gap so the
1948        // substrate-wide "no URL-percent-encoding-escape / printf-format-
1949        // specifier / job-control-specifier / YAML-directive-lead byte
1950        // anywhere in a typed string slot that flows verbatim into a
1951        // shell-spawned subprocess or downstream URL / printf / YAML
1952        // parser" invariant extends from shell-comment / URL-fragment
1953        // (`#` — 6622063) to URL-percent-encoding-escape (`%`) on the
1954        // `:caminho` axis.
1955        //
1956        // The arm fires AFTER the shell-comment arm because the prior
1957        // arm's `#` shape is the more semantic-locating axis on values
1958        // that probe as both (`"../caixa%20teia#pin"` carries both `%`
1959        // and `#` — the URL-fragment-identifier is the load-bearing
1960        // downstream-truncation edit, so `FonteCaminhoShellComment` wins;
1961        // same cascade discipline every prior `:caminho` arm establishes).
1962        // The arm fires BEFORE the trailing-`/` arm because the embedded
1963        // percent-encoding-escape byte is the more semantic-locating axis
1964        // on probe-as-both values (`"../caixa%20teia/"` ends in `/` but
1965        // the load-bearing diagnostic is the embedded `%` percent-
1966        // encoding-escape — the trailing `/` is the secondary observation,
1967        // and an author who decodes the `%20` to a literal space is
1968        // likely to also tab-strip the trailing separator).
1969        for &b in caminho.as_bytes() {
1970            if b == b'%' {
1971                return Err(DepError::FonteCaminhoUrlPercentEncoding {
1972                    nome: nome.to_string(),
1973                    caminho: caminho.to_string(),
1974                    byte: b,
1975                });
1976            }
1977        }
1978        // Reproducibility gate's embedded-`$` shell-variable-expansion /
1979        // command-substitution / arithmetic-expansion arm. The f4efe9c
1980        // leading-`$` arm at line 540 routes `caminho.starts_with('$')`
1981        // through `FonteCaminhoVarExpansion` under the leading-byte-
1982        // sentinel host-layout-leak banner (peer with the b94fd83
1983        // absolute / a5c248e tilde leading-byte arms), but the arm
1984        // fires only at position 0 — a `:caminho "../foo$HOME/bar"`
1985        // (embedded `$HOME` in a nested path segment — the canonical
1986        // paste-from-`ls ../foo$HOME/bar`-shell-one-liner footgun where
1987        // an author copies a partially-substituted shell one-liner and
1988        // the leading segment is a literal `../foo` while the mid
1989        // segment carries the un-substituted `$HOME` template), a
1990        // `:caminho "../foo${WORKSPACE}/bar"` (the symmetric braced-CI-
1991        // manifest paste-from-`.gitlab-ci.yml` / paste-from-GitHub-
1992        // Actions-workflow shape), a `:caminho "../foo$(whoami)/bar"`
1993        // (the paste-from-shell-prompt command-substitution idiom), or
1994        // a `:caminho "../foo$((1+2))/bar"` (the arithmetic-expansion
1995        // idiom) silently passes every prior arm because
1996        // `Path::is_absolute` returns false on `..`, `$` is neither a
1997        // leading-byte sentinel (the f4efe9c arm fires only at position
1998        // 0) nor a control byte nor `\` nor `<` / `>` nor `|` nor `;`
1999        // nor `&` nor backtick nor `*` / `?` nor `(` / `)` nor `{` /
2000        // `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%`, and the
2001        // value's last byte isn't `/`. Note that `$(...)` command-
2002        // substitution and `$((...))` arithmetic-expansion each carry
2003        // an embedded `(` byte that the 0633c91 shell-subshell-grouping
2004        // arm catches structurally at the earlier `(` position — but
2005        // an author who reaches for the sh-brace-substitution
2006        // `${VAR}` or the bare `$VAR` shape carries only the `$` byte,
2007        // which no prior arm covers. This arm closes the last
2008        // positional gap on the `$` byte on the `:caminho` axis so
2009        // every position — leading (`FonteCaminhoVarExpansion`) and
2010        // embedded (`FonteCaminhoShellVariableExpansion`) — is
2011        // structurally rejected.
2012        //
2013        // Every POSIX shell (sh / bash / zsh / dash / ksh / busybox
2014        // ash / fish / nushell) lexes `$` as the variable-expansion /
2015        // command-substitution / arithmetic-expansion operator per
2016        // POSIX.1-2017 §2.6 (Word Expansions): `$<name>` (Parameter
2017        // Expansion) expands a named variable, `${<name>}` (Parameter
2018        // Expansion braced form) does the same with an explicit token
2019        // boundary, `$(<cmd>)` (Command Substitution modern form,
2020        // `` `<cmd>` `` legacy form which the c370458 backtick arm
2021        // already closes) runs a subshell and substitutes its stdout,
2022        // and `$((<expr>))` (Arithmetic Expansion) evaluates an
2023        // arithmetic expression. Every form is a host-layout /
2024        // environment-state / shell-subprocess-side-effect leak when
2025        // the byte lands in a value the resolver passes to a shell-
2026        // spawned subprocess. Beyond the POSIX shell layer, `$` is
2027        // the Nix `${var}` string-interpolation lead (the paste-from-
2028        // `flake.nix` / paste-from-`.nix`-attribute cross-idiom leak
2029        // where an author copies `"${pkgs.hello}/bin/hello"` out of a
2030        // nix expression), the Make `$(var)` / `$@` / `$<` automatic-
2031        // variable lead (the paste-from-`Makefile` shape), the
2032        // JavaScript / TypeScript template-literal `${expr}` interp
2033        // lead (the paste-from-JS-template-string idiom in a
2034        // multi-lang-monorepo where a `path` attribute gets copied out
2035        // of a `package.json` script or a Vite config), the envsubst /
2036        // Kubernetes / OpenShift template `${VAR}` interp lead (the
2037        // paste-from-Helm-values / paste-from-K8s-manifest cross-idiom
2038        // leak), the PHP variable lead (`$_GET`, `$_ENV` — the paste-
2039        // from-`.php`-config footgun), the Perl scalar-variable lead
2040        // (`$foo`), the SASS / SCSS variable lead (`$primary-color`),
2041        // and the SQL bind-parameter lead in PostgreSQL / SQLite
2042        // (`$1`, `$2` — the paste-from-`.sql`-migration idiom). The
2043        // cross-idiom paste-footgun surface is broader than any single
2044        // shell layer — `$` is a first-class parser byte in nearly
2045        // every config / templating / build-system DSL the substrate's
2046        // paste-idiom surface routinely crosses. The peer `:fonte
2047        // :repo` axis closes the byte under the shell-variable-
2048        // expansion / URL-sub-delim banner (b9d187c `$` on
2049        // `is_git_repo_url`), the peer `:fonte :tag` / `:fonte :branch`
2050        // axes close `$` as part of `is_git_ref_name`'s printable-
2051        // ASCII-restricted grammar (`git check-ref-format` rejects the
2052        // byte outright), and the peer `:entrada :paths` axis closes
2053        // `$` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-
2054        // reserved set. The `:caminho` axis was the last typed path-
2055        // string surface still admitting `$` at positions other than 0.
2056        //
2057        // POSIX `std::path::Path` treats `$` as a literal path-
2058        // component byte, so `:caminho "../foo$HOME/bar"` silently
2059        // routes through `Path::new(caminho).join(<file>)` looking for
2060        // a literal `./{caminho}` subdirectory that fails at resolve
2061        // time with a non-self-locating `No such file or directory`
2062        // error far from the source caixa.lisp. But every downstream
2063        // shell / envsubst / Nix / Make / K8s-template parser silently
2064        // reinterprets the byte to a different value than the
2065        // resolver's `Path::join` sees — so a `feira tofu` shell-out
2066        // to a `cd '{caminho}'` command line, a `nix flake check`
2067        // invocation on an emitted YAML `path:` scalar folded through
2068        // envsubst, or a `helm template` invocation with a
2069        // `values.yaml` `path: {caminho}` embedded in a `{{`-quoted
2070        // template all disagree with the resolver on which directory
2071        // the value names. Two workstations whose downstream shell /
2072        // envsubst / Nix / Make / K8s-template parsing layers differ
2073        // in `$VAR` recognition (or, worse, expand the byte against
2074        // divergent environments — Alice's `$HOME=/home/alice`, Bob's
2075        // `$HOME=/home/bob`) emit divergent build artifacts for the
2076        // byte-identical caixa.lisp value. Even in the case where the
2077        // resolver strictly does NOT expand `$VAR` (the current
2078        // implementation) the divergence still bites at the lacre-
2079        // identity axis: the lacre pipeline embeds the value verbatim
2080        // in its per-dep content-address (`conteudo:
2081        // format!("path:{caminho}")`, caixa-resolver/src/resolve.rs:189),
2082        // so `path:../foo$HOME/bar` locks a BLAKE3 closure distinct
2083        // from the byte-identical-semantic `path:../foo/home/alice/bar`
2084        // one author would have produced by substituting the literal
2085        // value at author time, defeating the THEORY.md §V.2 render-
2086        // determinism contract on the same axis every prior `:caminho`
2087        // arm protects.
2088        //
2089        // Beyond the render-determinism / host-layout-leak vectors,
2090        // `$` at any position in a value flowing verbatim into a
2091        // shell-spawned subprocess is the canonical CWE-78 shell-
2092        // command-injection surface every peer single-token-shaped
2093        // typed slot already closes. A `:caminho "../foo$(whoami)/bar"`
2094        // that rides into a future `feira tofu` shell-out as `cd
2095        // '../foo$(whoami)/bar'` gets substituted by the shell at
2096        // subprocess-argument-expansion time even inside single quotes
2097        // in fewer positions than one might expect (the substitution
2098        // fires only outside single-quoting per POSIX §2.2.2, but
2099        // eval-style wrappers and `sh -c` layers that route the value
2100        // through re-parsing round-trip the substitution — the same
2101        // vector the c370458 backtick arm closes at the sibling
2102        // command-substitution-legacy-form surface). Every future
2103        // `feira` verb that shells out with a `caminho`-formatted
2104        // subprocess argument silently inherits this substitution
2105        // vector unless the typed slot's accepted set structurally
2106        // excludes the byte.
2107        //
2108        // Frontier inspiration: OTP's `gen_server` return-value grammar
2109        // rejects mid-tuple shell-metachar bytes by construction —
2110        // `{noreply, State}` never carries a raw `$` because the
2111        // Erlang term type system has no notion of "string that gets
2112        // shelled out"; caixa's typed slots inherit the same
2113        // structural discipline (types-are-theorems, the compounding
2114        // mandate's leverage-point-1) by refusing values that would
2115        // silently reinterpret at any downstream layer. Peer with
2116        // Unison's content-addressed code (no ambient environment —
2117        // every reference is a hash, no `$VAR` substitution possible)
2118        // and Pony's capabilities (a path capability that carries a
2119        // `$` would be ill-typed at the reference layer).
2120        //
2121        // The arm fires AFTER the URL-percent-encoding-escape arm (the
2122        // e3558fa `%` arm) because a value carrying both `%` and `$`
2123        // (`"../foo%20$HOME/bar"` — the canonical "I pasted a percent-
2124        // encoded space next to a `$HOME` template") surfaces the
2125        // narrower URL-encoding diagnostic first — the paste-from-
2126        // browser-address-bar shape is the load-bearing self-locating
2127        // edit on every probe-as-both value; same cascade discipline
2128        // every prior `:caminho` arm establishes (a323db8 %  before
2129        // this arm, this arm before trailing-`/`). The arm fires
2130        // BEFORE the trailing-`/` arm because the embedded shell-
2131        // variable-expansion byte is the more semantic-locating axis
2132        // on probe-as-both values (`"../foo$HOME/bar/"` ends in `/`
2133        // but the load-bearing diagnostic is the embedded `$` — the
2134        // trailing `/` is the secondary observation, and an author
2135        // who substitutes the `$HOME` template with a literal value is
2136        // likely to also tab-strip the trailing separator).
2137        for &b in caminho.as_bytes() {
2138            if b == b'$' {
2139                return Err(DepError::FonteCaminhoShellVariableExpansion {
2140                    nome: nome.to_string(),
2141                    caminho: caminho.to_string(),
2142                    byte: b,
2143                });
2144            }
2145        }
2146        // Reproducibility gate's shell-history-expansion / RFC-3986-sub-delims
2147        // arm. The immediate-predecessor `$` embedded arm closes the shell-
2148        // variable-expansion / command-substitution byte; `!` (`0x21`) is the
2149        // orthogonal POSIX shell-history-expansion sentinel every interactive
2150        // shell with history enabled (bash / ksh / zsh's `bashcompat` /
2151        // csh / tcsh) lexes as the history-expansion prefix: `!command`
2152        // re-runs the most recent history entry beginning with `command`,
2153        // `!!` re-runs the prior command verbatim, `!$` substitutes the
2154        // last word of the prior command, `!:N` substitutes the Nth word,
2155        // `^old^new` rewrites the prior command's `old` to `new` (the
2156        // canonical set of `set -o histexpand` operators bash's default
2157        // interactive session enables). Beyond the shell-history layer,
2158        // RFC 3986 §2.2 lists `!` in the `sub-delims` set (the URL grammar
2159        // admits the byte inside a path segment, but every WHATWG-conformant
2160        // special-scheme URL parser percent-encodes it inside a query
2161        // component via the 'special-query percent-encode set' the peer
2162        // `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte
2163        // is also the C / C++ / Rust / JavaScript / Python bang-operator
2164        // (logical-negation prefix — the paste-from-source-code idiom where
2165        // an author copies `!path.exists()` out of a Rust snippet and the
2166        // trailing punctuation crosses the string-literal boundary); the
2167        // canonical English-typography emphasis / exclamation mark (the
2168        // paste-from-prose enthusiasm-form idiom where an author writes
2169        // `:caminho "../caixa-teia!"` expecting the substrate to coerce it
2170        // to a kebab-case slug); and the Nix flake-ref import-attribute
2171        // `import ./foo.nix { … }` sibling operator surface.
2172        //
2173        // POSIX `std::path::Path` treats `!` as a literal path-component
2174        // byte, so a `:caminho "../caixa-teia!sudo"` (the canonical paste-
2175        // from-shell-history footgun where the author copies a `cd
2176        // ../caixa-teia && !sudo make install` one-liner from a quick-
2177        // start README and the trailing `!sudo` rides in verbatim as a
2178        // history-expansion reference), a `:caminho "../foo!!/bar"` (the
2179        // `!!` repeat-prior-command paste idiom), a `:caminho
2180        // "../caixa-teia!"` (the English-typography enthusiasm-form
2181        // paste-from-prose footgun), or a `:caminho "../foo!$"` (the
2182        // last-word-substitution shape) silently pass every prior arm
2183        // because `Path::is_absolute` returns false on `..`, `!` is neither
2184        // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
2185        // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
2186        // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%` nor `$`,
2187        // and the value's last byte isn't `/`. The resolver folds the value
2188        // through `Path::new(caminho).join(<file>)` looking for a literal
2189        // `./../caixa-teia!sudo` subdirectory and fails at resolve time
2190        // with a non-self-locating `No such file or directory` error far
2191        // from the source caixa.lisp — while every downstream interactive
2192        // shell with `set -o histexpand` reinterprets the byte as the
2193        // history-expansion prefix, and the failure mode forks per
2194        // consumer: a `feira tofu` shell-out to a `cd '{caminho}'` command
2195        // line executed under `bash -i` (the operator-notebook interactive
2196        // shell) substitutes the `!sudo` reference to the most recent
2197        // history entry starting with `sudo`, silently invoking whatever
2198        // privileged command that entry named.
2199        //
2200        // The lacre pipeline embeds the value verbatim in its per-dep
2201        // content-address (`conteudo: format!("path:{caminho}")`,
2202        // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2203        // BLAKE3 closure and rides into every shell-spawned subprocess
2204        // (the resolver's `git clone`, a future `feira tofu` shell-out,
2205        // a future operator-side `nix flake check` spawn) as the
2206        // canonical shell-history-expansion / RFC-3986-sub-delims surface
2207        // every peer single-token-shaped typed slot already closes. The
2208        // peer `:fonte :repo` axis closes the byte under the same shell-
2209        // history-expansion / RFC-3986-sub-delims banner (7d53c68 `!` on
2210        // `is_git_repo_url`); the `:caminho` axis was the last typed
2211        // path-string surface still admitting the byte. This arm closes
2212        // the gap so the substrate-wide "no shell-composition
2213        // metacharacter / history-expansion sentinel anywhere in a typed
2214        // string slot that flows verbatim into a shell-spawned subprocess"
2215        // invariant extends from shell-variable-expansion (`$`) to shell-
2216        // history-expansion (`!`) on the `:caminho` axis. Together with
2217        // the peer c370458 backtick command-substitution-legacy-form arm
2218        // and the b9d187c-`$`-embedded-variable-expansion arm on the
2219        // sibling `:repo` axis, the typed `:caminho` accepted set now
2220        // structurally excludes every byte the POSIX shell §2.6 Word
2221        // Expansions section, §2.3 Token Recognition step 6, and every
2222        // history-expansion / brace-expansion / pathname-expansion /
2223        // parameter-expansion / command-substitution / arithmetic-
2224        // expansion operator lexes as a first-class parser byte.
2225        //
2226        // Frontier inspiration: Unison's content-addressed code (no
2227        // ambient environment — every reference is a hash, no `!<num>`
2228        // history-index substitution possible; the caixa substrate's
2229        // lacre discipline arrives at the same guarantee by refusing
2230        // bytes at manifest-parse time that would reinterpret against
2231        // ambient shell history state); Pony's capabilities (a path
2232        // capability that carries a `!` would be ill-typed at the
2233        // reference layer).
2234        //
2235        // The arm fires AFTER the shell-variable-expansion arm because a
2236        // value carrying both `$` and `!` (`"../foo$HOME/bar!sudo"` — the
2237        // canonical "I pasted a `$HOME`-templated path adjacent to a
2238        // trailing `!sudo` history-expansion") surfaces the narrower
2239        // shell-variable-expansion diagnostic first — the paste-from-CI-
2240        // manifest-with-`$VAR`-template shape is the load-bearing self-
2241        // locating edit on every probe-as-both value; same cascade
2242        // discipline every prior `:caminho` arm establishes. The arm
2243        // fires BEFORE the trailing-`/` arm because the embedded shell-
2244        // history-expansion byte is the more semantic-locating axis on
2245        // probe-as-both values (`"../foo!sudo/"` ends in `/` but the
2246        // load-bearing diagnostic is the embedded `!` — the trailing `/`
2247        // is the secondary observation, and an author who removes the
2248        // `!sudo` history reference is likely to also tab-strip the
2249        // trailing separator).
2250        for &b in caminho.as_bytes() {
2251            if b == b'!' {
2252                return Err(DepError::FonteCaminhoShellHistoryExpansion {
2253                    nome: nome.to_string(),
2254                    caminho: caminho.to_string(),
2255                    byte: b,
2256                });
2257            }
2258        }
2259        // Reproducibility gate's shell-history-substitution / RFC-3986-unwise
2260        // / regex-anchor arm. The immediate-predecessor `!` arm closes the
2261        // POSIX `!command` / `!!` / `!$` history-expansion prefix; `^`
2262        // (`0x5E`) is the paired-operator half of the same bash-reference
2263        // §9.3 histexpand feature — the `^old^new^` "quick substitution"
2264        // form (POSIX bash rewrites the prior command's `old` string to
2265        // `new` and re-executes it, the canonical typo-correction one-
2266        // liner idiom `git clone <bad-url>` → `^bad^good` that pastes the
2267        // trailing substitution fragment verbatim into a `:caminho` value
2268        // when the author trims only the leading `git clone` prefix). The
2269        // peer `:fonte :repo` axis closes the byte under the same
2270        // shell-history-substitution / RFC-3986-unwise banner (49e142f `^`
2271        // on `is_git_repo_url`); the `:caminho` axis was the last typed
2272        // path-string surface still admitting the byte after 6a04767
2273        // landed the `!` arm.
2274        //
2275        // Beyond bash history-substitution, `^` carries five distinct
2276        // downstream-reinterpretation surfaces the typed slot's accepted
2277        // set must structurally exclude:
2278        //
2279        // 1. **RFC 3986 §2 'unwise' set** — the four-byte cross-transport
2280        //    layer set (`{`, `}`, `|`, `\`) plus `^` every URL parser is
2281        //    required to percent-encode-or-refuse at the wire boundary.
2282        //    The WHATWG URL spec's 'fragment percent-encode set' maps
2283        //    `^` → `%5E` at the query / fragment component transition;
2284        //    libcurl silently percent-encodes the byte on the wire, so a
2285        //    `:caminho "../foo^bar"` value the resolver's `Path::join`
2286        //    sees as a literal `./../foo^bar` subdirectory diverges from
2287        //    the byte-transformed `%5E` shape any downstream `feira tofu`
2288        //    curl-invocation or artifact-registry-fetch would emit — the
2289        //    canonical wire-boundary divergence vector the peer
2290        //    `{`, `}`, `|`, `\` `:caminho` arms already close (
2291        //    `FonteCaminhoShellBraceExpansion` at 598b770,
2292        //    `FonteCaminhoShellPipe` at the pipe arm,
2293        //    `FonteCaminhoBackslash` at the backslash arm).
2294        // 2. **Regex character-class negation prefix `[^abc]`** — the
2295        //    canonical paste-from-doc-regex-pipeline footgun where an
2296        //    author copies a `grep '[^abc]'` idiom from a docs quick-
2297        //    listing and the character-class negation byte rides in
2298        //    verbatim.
2299        // 3. **Bitwise XOR operator** in C / C++ / Rust / Python /
2300        //    JavaScript / Nix / Go — the paste-from-source-code idiom
2301        //    where an author copies an `x ^ y`-shaped expression out of
2302        //    a source snippet and the operator crosses the string-
2303        //    literal boundary.
2304        // 4. **Windows `cmd.exe` escape metacharacter** — the byte
2305        //    escapes the next character in a `cmd.exe` batch context (a
2306        //    peer of the backslash arm's Windows-separator-leak vector).
2307        //    A `:caminho "..^&whoami"` cross-platform paste-from-batch-
2308        //    file footgun reinterprets at every `cmd.exe`-spawned
2309        //    subprocess (the resolver's future Windows-runner shell-out,
2310        //    the operator's WinRM path, a future PowerShell-embedded
2311        //    invocation).
2312        // 5. **LaTeX / Markdown / BibTeX superscript operator** — the
2313        //    paste-from-typeset-doc footgun where a mathematical
2314        //    superscript notation (`x^2` / `M^T`) leaks from prose.
2315        //
2316        // POSIX `std::path::Path` treats `^` as a literal path-component
2317        // byte, so `:caminho "../foo^bar/baz"` (embedded quick-
2318        // substitution), `:caminho "../foo^"` (trailing history-
2319        // substitution-open shape), `:caminho "../[^a-z]/foo"` (regex-
2320        // negation-prefix paste from a grep pipeline; note the `[` / `]`
2321        // arm at 986963b fires first on this shape), or `:caminho
2322        // "../x^y"` (XOR-expression paste-from-source) all silently pass
2323        // every prior arm (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` /
2324        // backtick / `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'`
2325        // / `"` / `#` / `%` / `$` / `!`) and route through
2326        // `Path::new(caminho).join(<file>)` looking for a literal
2327        // `./{caminho}` subdirectory that fails at resolve time with a
2328        // non-self-locating `No such file or directory` error far from
2329        // the source caixa.lisp — while every downstream shell / curl /
2330        // regex / `cmd.exe` layer reinterprets the byte to its own
2331        // semantic.
2332        //
2333        // The lacre pipeline embeds the value verbatim in its per-dep
2334        // content-address (`conteudo: format!("path:{caminho}")`,
2335        // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2336        // BLAKE3 closure and rides into every shell-spawned subprocess
2337        // (the resolver's `git clone`, a future `feira tofu` shell-out,
2338        // a future operator-side `nix flake check` spawn) as the
2339        // canonical shell-history-substitution / RFC-3986-unwise /
2340        // regex-negation surface every peer single-token-shaped typed
2341        // slot already closes. This arm together with the immediate-
2342        // predecessor `!` arm (6a04767) closes the full `set -o
2343        // histexpand` operator surface on the `:caminho` axis — the
2344        // `!command` / `!!` / `!$` prefix form via `!`, the `^old^new^`
2345        // quick-substitution form via `^` — so the substrate-wide "no
2346        // shell-history operator anywhere in a typed string slot that
2347        // flows verbatim into a shell-spawned subprocess" invariant
2348        // extends from the `!` prefix half to the `^` quick-substitution
2349        // half. Every peer bash-history operator now fails at manifest-
2350        // parse time with a self-locating diagnostic naming the offending
2351        // caixa.lisp rather than at resolve-time as a `Path::join`-
2352        // derived `No such file or directory` (harmless but non-self-
2353        // locating) or worse riding into a downstream `bash -i` context
2354        // that reinterprets the byte-pair against ambient history state.
2355        //
2356        // Frontier inspiration: bash reference §9.3 HISTORY EXPANSION
2357        // "Quick substitution. Repeat the previous command, replacing
2358        // string1 with string2." + RFC 3986 §2 'unwise' set
2359        // ("characters that gateways and other transport agents are
2360        // known to sometimes modify") + Pony's capabilities (a path
2361        // capability that carries a `^` would be ill-typed at the
2362        // reference layer, matching the same structural discipline the
2363        // sibling `!` history-expansion arm inherits from Unison's
2364        // content-addressed no-ambient-history discipline).
2365        //
2366        // The arm fires AFTER the shell-history-expansion `!` arm because
2367        // a value carrying both `!` and `^` (`"../foo!sudo^bad^good"` —
2368        // the canonical "I pasted a `!sudo` history-reference next to a
2369        // `^bad^good` quick-substitution") surfaces the narrower prefix-
2370        // form `!` diagnostic first — the `!` form is the load-bearing
2371        // self-locating edit on every probe-as-both value (an author who
2372        // removes the `!sudo` reference is likely to also strip the
2373        // paired `^` substitution fragment); same cascade discipline
2374        // every prior `:caminho` arm establishes. The arm fires BEFORE
2375        // the trailing-`/` arm because the embedded shell-history-
2376        // substitution byte is the more semantic-locating axis on
2377        // probe-as-both values (`"../foo^bar/"` ends in `/` but the
2378        // load-bearing diagnostic is the embedded `^` — the trailing `/`
2379        // is the secondary observation, and an author who removes the
2380        // `^bar` substitution fragment is likely to also tab-strip the
2381        // trailing separator).
2382        for &b in caminho.as_bytes() {
2383            if b == b'^' {
2384                return Err(DepError::FonteCaminhoShellHistorySubstitution {
2385                    nome: nome.to_string(),
2386                    caminho: caminho.to_string(),
2387                    byte: b,
2388                });
2389            }
2390        }
2391        // Reproducibility gate's trailing-`/` arm. The b94fd83 absolute arm
2392        // closes the leading-`/` host-layout-leak; the embedded-control-byte
2393        // arm closes any byte-in-the-`0x00..=0x1F` / `0x7F` range; the
2394        // backslash arm closes the cross-host-OS-separator vector. The
2395        // trailing-`/` is the orthogonal shell-tab-completion-on-a-directory
2396        // footgun — `Path::join("../caixa-teia")` and
2397        // `Path::join("../caixa-teia/")` resolve to the same directory
2398        // (POSIX path-component-walk treats trailing `/` as a no-op for
2399        // directory targets, which `:caminho` always names — the sibling-
2400        // workspace dep root is structurally a directory). The lacre
2401        // pipeline embeds the value verbatim in its per-dep content-address
2402        // (`conteudo: format!("path:{caminho}")`,
2403        // caixa-resolver/src/resolve.rs:189), so byte-identical caixa
2404        // semantic-meaning yields two distinct BLAKE3 closures depending on
2405        // whether the author shell-tab-completed the path (every interactive
2406        // shell appends `/` on tab-completing a directory, idiomatic in
2407        // bash / zsh / fish / nushell), pasted from `pwd` (which on most
2408        // shells emits without trailing `/`, but `realpath -e -m` on a
2409        // directory with trailing `/` preserves it), or copied a Cargo
2410        // `path = "../caixa-teia/"` entry from cross-substrate documentation
2411        // (Cargo accepts both shapes and folds them the same way). Two
2412        // workstations whose authors differ only in tab-completion habits
2413        // emit byte-divergent lacres for the byte-identical-semantic caixa,
2414        // and the substrate's "the lacre is the build's identity" contract
2415        // (CAIXA-SDLC §III.2) silently breaks far from the source caixa.lisp.
2416        //
2417        // Same THEORY.md §V.2 render-determinism axis every prior `:caminho`
2418        // arm protects, here against the trailing-separator divergence
2419        // vector: every typed slot's accepted set excludes byte-divergent
2420        // values that round-trip to the same downstream semantic. The peer
2421        // path-shaped axes already reject trailing separators on the same
2422        // contract: [`crate::render::is_gateway_api_http_path`] gates
2423        // `:entrada :paths` against any non-canonical normalization, and
2424        // [`crate::render::is_sandboxed_relative_path`] gates the M2 typed
2425        // path-slots (`:behavior :on-*`, `:upgrade-from :state-change
2426        // :script`, `:bibliotecas`, `:exe`, `:servicos`) against shapes
2427        // whose canonical form would re-introduce determinism divergence.
2428        //
2429        // The arm fires last in the cascade because every prior arm carries
2430        // a more self-locating diagnostic on values that probe as both
2431        // (e.g. `:caminho "../foo/\0/"` ends in `/` but the load-bearing
2432        // diagnostic is the NUL byte's POSIX-syscall-rejection — the
2433        // control-char arm wins; `:caminho "/etc/passwd/"` ends in `/` but
2434        // the load-bearing diagnostic is the absolute host-layout-leak —
2435        // the absolute arm wins; `:caminho "..\caixa-teia/"` ends in `/`
2436        // but the load-bearing diagnostic is the Windows-separator cross-
2437        // OS divergence — the backslash arm wins). The arm covers every
2438        // shape where the last byte is `/` regardless of length, including
2439        // the degenerate single-`/` (which the absolute arm catches first)
2440        // and the consecutive-`//` (where every prior arm passes on the
2441        // bytes other than the trailing `/`).
2442        if caminho.as_bytes().last() == Some(&b'/') {
2443            return Err(DepError::FonteCaminhoTrailingSlash {
2444                nome: nome.to_string(),
2445                caminho: caminho.to_string(),
2446            });
2447        }
2448        Ok(())
2449    }
2450}
2451
2452impl Dep {
2453    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:nome` scalar
2454    /// accessor every consumer of the dep-graph identity axis keys off —
2455    /// returns the author-declared `:nome` byte-string verbatim as a
2456    /// `&str`, borrowed from the typed slot's own [`String`] storage.
2457    ///
2458    /// The `:deps :nome` / `:deps-dev :nome` slot carries the DNS-1123
2459    /// label that names the target caixa (validated by [`Self::validate`]
2460    /// through the shared [`crate::render::is_dns_1123_label`] predicate,
2461    /// same accept-set the peer caixa-identifier axes carry — top-level
2462    /// [`crate::Caixa::nome`], per-`:membros` [`crate::Membro::nome`],
2463    /// per-`:children` [`crate::supervisor::ChildSpec::nome`]). Every
2464    /// downstream consumer that fans on the dep's name-identity keys off
2465    /// this scalar: the [`crate::Caixa::validate_deps`] per-list
2466    /// [`crate::render::insert_first_seen`] dedup key + the paired
2467    /// [`DepError::DuplicateNome`] carrier the walk raises on collision,
2468    /// the cross-list [`validate_no_self_dep`] parent-name equality gate
2469    /// on both `:deps` and `:deps-dev` traversals, the `caixa-resolver`
2470    /// pipeline's `HashSet<String>` seen-set the closure walker gates
2471    /// requeueing off (`caixa-resolver/src/resolve.rs:55`), the resolver's
2472    /// per-transitive-target requeue path (`resolve.rs:63,66`), the
2473    /// [`crate::DepSource::default_github`]-shaped resolver-side shorthand
2474    /// fill-in that folds `:nome` into the fetched-git-URL (`resolve.rs:147`),
2475    /// every `caixa-resolver` `ResolveError::MissingPath` /
2476    /// `ResolveError::MissingPin` carrier that names the offending dep
2477    /// (`resolve.rs:177,206`), each resolved
2478    /// `caixa-lacre::LacreEntry` `nome:` field the closure hash keys off
2479    /// (`resolve.rs:108,113`), and the peer `feira lock` stub-resolver's
2480    /// `LacreEntry` emitter (`caixa-feira/src/cmd/lock.rs:59,61,64`).
2481    ///
2482    /// Prior to this lift the `.nome` byte-string was read inline at every
2483    /// production site — the [`crate::Caixa::validate_deps`] paired
2484    /// `dep.nome.as_str()` / `dep.nome.clone()` accesses on both `:deps`
2485    /// and `:deps-dev` traversals, the [`validate_no_self_dep`] pair of
2486    /// parent-equality checks, and every caixa-resolver / caixa-feira
2487    /// site enumerated above — open-coded field-accesses that expressed
2488    /// no compile-time link back to the typed slot. A future extension of
2489    /// the `:deps :nome` axis to a richer author surface (a per-scope
2490    /// alias table the resolver folds through the `~/.config/caixa/config.yaml`
2491    /// entry the [`crate::dep::Dep`] docstring already acknowledges, a
2492    /// namespace-qualified rewrite the future M4 lacre-federation layer
2493    /// applies per-cluster, a promotion of the plain [`String`] byte-string
2494    /// to a richer scoped-identifier newtype once cross-registry federation
2495    /// lands) would have had to be threaded through every open-coded copy
2496    /// in lockstep or two consumers would silently disagree on which caixa
2497    /// a given dep resolves to — the [`crate::Caixa::validate_deps`] dedup
2498    /// set treating the name as `"caixa-teia"` while the caixa-resolver
2499    /// closure walker treated it as `"tenant-a/caixa-teia"` would silently
2500    /// split the [`DepError::DuplicateNome`] refusal from the resolver's
2501    /// requeue-suppression seen-set, one build-time diagnostic
2502    /// disagreeing with the run-time closure the substrate's lacre
2503    /// pipeline actually materializes. Lifting the resolution rule to a
2504    /// typed method on the substrate primitive means every downstream
2505    /// consumer of the caixa's per-`:deps` identity surface reaches for
2506    /// exactly one typed dispatch — the resolver's accept-set migrates as
2507    /// a unit on any future axis addition.
2508    ///
2509    /// First accessor on the outer `Dep` type — opens the outer-`Dep`
2510    /// `&str`-return required-scalar projection pattern the sibling
2511    /// per-`Dep` `:versao` future lift folds on. Peer of the sibling
2512    /// per-`:membros` [`crate::Membro::nome`] (4a32abf) /
2513    /// per-`:children` [`crate::supervisor::ChildSpec::nome`] (dfb4a81)
2514    /// / top-level [`crate::Caixa::nome`] (e6b7d97) caixa-identity scalar
2515    /// accessors — same "one typed dispatch on the substrate primitive,
2516    /// thin projections at each consumer" discipline extended onto the
2517    /// third named-caixa-referencing axis (`:deps` / `:deps-dev`), the
2518    /// remaining unlifted caixa-name-referencing accessor family in the
2519    /// substrate. Named `nome()` to match the tatara-lisp author-surface
2520    /// term the field's docstring already reaches for ("Caixa name — must
2521    /// match the target caixa's `:nome`") and the peer caixa-identity
2522    /// accessor family the substrate already carries.
2523    #[must_use]
2524    pub const fn nome(&self) -> &str {
2525        self.nome.as_str()
2526    }
2527
2528    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:versao`
2529    /// Cargo-shaped semver-requirement scalar accessor every consumer of
2530    /// the dep-graph version-pin axis keys off — returns the author-
2531    /// declared `:versao` requirement byte-string verbatim as a `&str`,
2532    /// borrowed from the typed slot's own [`String`] storage.
2533    ///
2534    /// The `:deps :versao` / `:deps-dev :versao` slot carries the
2535    /// Cargo-shaped semver requirement string (`"^0.1"`, `"~0.1.2"`,
2536    /// `"0.1.0"`, `"*"`) the shared [`crate::version::parse_requirement`]
2537    /// entry-point consumes — same accept-set the peer requirement-
2538    /// carrying axes carry (per-`:membros`
2539    /// [`crate::Membro::versao_requirement`], per-`:children`
2540    /// [`crate::supervisor::ChildSpec::versao_requirement`]), validated
2541    /// through the shared
2542    /// [`crate::render::require_valid_versao_requirement`] cascade in
2543    /// [`Self::validate`]. Every downstream consumer that fans on the
2544    /// dep's version-pin keys off this scalar: the [`Self::validate`]
2545    /// `require_valid_versao_requirement` gate + the paired
2546    /// [`DepError::VersaoInvalid`] carrier the cascade raises on
2547    /// requirement-shape rejection, the `feira lock` stub-resolver's
2548    /// `format!("{}@{}", dep.nome(), dep.versao_requirement())`
2549    /// `conteudo` hash-input interpolation and the paired
2550    /// `LacreEntry.versao:` `String`-carry fill (`caixa-feira/src/cmd/lock.rs`),
2551    /// and the peer `feira lock` end-to-end fixture in `caixa-feira/tests/feira_e2e.rs`.
2552    ///
2553    /// Prior to this lift the `.versao` byte-string was read inline at
2554    /// every production site — the [`Self::validate`] paired
2555    /// `&self.versao` requirement-gate reference and `self.versao.clone()`
2556    /// error-body carrier, the `caixa-feira/src/cmd/lock.rs` paired
2557    /// `format!("{}@{}", dep.nome(), dep.versao)` `conteudo` interpolation
2558    /// and `versao: dep.versao.clone()` `LacreEntry` fill, and the
2559    /// `caixa-feira/tests/feira_e2e.rs` end-to-end fixture's pair of the
2560    /// same shapes — open-coded field-accesses that expressed no
2561    /// compile-time link back to the typed slot. A future extension of
2562    /// the `:deps :versao` axis to a richer author surface (a per-scope
2563    /// version-lock overlay the resolver folds through the
2564    /// `~/.config/caixa/config.yaml` entry the [`crate::dep::Dep`]
2565    /// docstring already acknowledges, a per-cluster canary-version
2566    /// overlay per MESH-COMPOSITION §III.2, a promotion of the plain
2567    /// [`String`] requirement to a richer parsed-`VersionReq` newtype
2568    /// once cross-registry federation lands) would have had to be
2569    /// threaded through every open-coded copy in lockstep or two
2570    /// consumers would silently disagree on which release constraint a
2571    /// given dep resolves to — the [`Self::validate`] requirement-gate
2572    /// call reading `"^0.1"` while the `feira lock` stub-resolver's
2573    /// `conteudo` hash-input read `"tenant-a-pin/^0.1"` would silently
2574    /// split the [`DepError::VersaoInvalid`] refusal from the lacre's
2575    /// content-addressed hash the substrate's fetch pipeline actually
2576    /// materializes, one build-time diagnostic disagreeing with the
2577    /// run-time closure. Lifting the resolution rule to a typed method
2578    /// on the substrate primitive means every downstream consumer of
2579    /// the caixa's per-`:deps` version-pin surface reaches for exactly
2580    /// one typed dispatch — the resolver's accept-set migrates as a
2581    /// unit on any future axis addition.
2582    ///
2583    /// Second accessor on the outer `Dep` type — folds on the outer-
2584    /// `Dep` `&str`-return required-scalar projection pattern the
2585    /// sibling per-`Dep` [`Self::nome`] (eba2cde) accessor opened. Peer
2586    /// of the per-`:membros` [`crate::Membro::versao_requirement`]
2587    /// (a40b0e3) / per-`:children`
2588    /// [`crate::supervisor::ChildSpec::versao_requirement`] (7844f4e
2589    /// family) member/child version-pin accessors — the three
2590    /// requirement-carrying axes (`Dep::versao_requirement` on the
2591    /// per-caixa dep-graph edge, `Membro::versao_requirement` on the M3
2592    /// Aplicacao side, `ChildSpec::versao_requirement` on the M2
2593    /// Supervisor side) now share one accessor discipline for the
2594    /// shared substrate concept "another caixa referenced by a
2595    /// Cargo-shaped semver requirement". The pair
2596    /// `(nome(), versao_requirement())` jointly projects the
2597    /// `(nome, versao)` field pair every dep-graph consumer that fans
2598    /// on per-dep identity + version pin keys off. Named
2599    /// `versao_requirement()` rather than `versao()` because the field's
2600    /// storage-side `.versao` label is already the author-surface term
2601    /// (`:versao`); the accessor's name carries the semantic role — the
2602    /// semver *requirement* string the shared
2603    /// [`crate::version::parse_requirement`] entry-point consumes — so a
2604    /// raw field access and a typed dispatch read differently at every
2605    /// consumer site. Matches the peer
2606    /// [`crate::Membro::versao_requirement`] /
2607    /// [`crate::supervisor::ChildSpec::versao_requirement`] naming
2608    /// discipline verbatim.
2609    #[must_use]
2610    pub const fn versao_requirement(&self) -> &str {
2611        self.versao.as_str()
2612    }
2613
2614    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:fonte`
2615    /// Zig-store-model per-dep source-tuple optional-composite-reference
2616    /// accessor every consumer of the dep-graph fetch-source axis keys
2617    /// off — returns the author-declared `:fonte` typed [`DepSource`]
2618    /// verbatim as an `Option<&DepSource>` borrowed from the typed slot's
2619    /// own `Option<DepSource>` storage, with `None` naming the "author
2620    /// omitted `:fonte`" shorthand every resolver-side default-fill
2621    /// (`caixa-feira/src/cmd/lock.rs`'s stub, `caixa-resolver/src/resolve.rs`'s
2622    /// canonical fetcher, per the [`DepSource::default_github`] fallback
2623    /// the [`Dep::fonte`] field docstring already documents) treats as
2624    /// the "resolve through the configured default host / org
2625    /// (`github:<default-org>/<nome>`)" partition.
2626    ///
2627    /// The `:deps :fonte` / `:deps-dev :fonte` slot carries the two-
2628    /// arm typed [`DepSource`] the `Zig-style git-only store model` the
2629    /// enclosing [`Dep`] docstring names — `DepSource::Git { repo, tag,
2630    /// rev, branch }` for the git-clone arm every published caixa
2631    /// resolves through, `DepSource::Path { caminho }` for the dev-only
2632    /// local-filesystem arm every unpublishable in-tree checkout
2633    /// resolves through. Every downstream consumer that fans on the
2634    /// dep's fetch-source keys off this accessor: [`Self::validate`]'s
2635    /// per-`:fonte` [`DepSource::validate`] delegation (which raises
2636    /// the empty-`:repo` / missing-pin / multiple-pin / empty-`:caminho`
2637    /// diagnostics through the [`DepError::Fonte*`] carrier family
2638    /// naming the offending `Dep::nome`), the caixa-crd conversion
2639    /// crate's `dep_into_ref` two-arm projection into the `CaixaSource`
2640    /// `{repo, git_ref}` pair the K8s-CR side consumes
2641    /// (`caixa-crd/src/conversion.rs`), and — through the paired
2642    /// resolver-side default-fill's `Option::unwrap_or_else` — every
2643    /// `caixa-feira` / `caixa-resolver` fetch site that requires a
2644    /// concrete `DepSource` at run time.
2645    ///
2646    /// Prior to this lift the `.fonte` typed slot was read inline at
2647    /// every production site — the [`Self::validate`]
2648    /// `if let Some(ref fonte) = self.fonte` bracket the per-`:fonte`
2649    /// gate delegates through, the caixa-crd `dep_into_ref`
2650    /// `d.fonte.as_ref().and_then(...)` two-arm `CaixaSource` projector,
2651    /// the resolver-side `caixa-feira/src/cmd/lock.rs` / `caixa-resolver/src/resolve.rs`
2652    /// `dep.fonte.clone().unwrap_or_else(...)` default-fill pair — open-
2653    /// coded field-accesses that expressed no compile-time link back to
2654    /// the typed slot. A future extension of the `:deps :fonte` axis
2655    /// to a richer author surface (a per-scope source-override table
2656    /// the resolver folds through the `~/.config/caixa/config.yaml`
2657    /// entry the [`Dep`] docstring already acknowledges, a per-org
2658    /// mirror-fallback list the future M4 lacre-federation resolver
2659    /// consults ahead of the `default_github` fallback, a promotion of
2660    /// the plain `Option<DepSource>` to a richer
2661    /// `{primary, mirrors, integrity}` triple once cross-registry
2662    /// federation lands, a per-dep `sri:sha256-…` integrity slot the
2663    /// M4 lacre gate binds against ahead of the git-fetch) would have
2664    /// had to be threaded through every open-coded copy in lockstep or
2665    /// two consumers would silently disagree on which fetch source a
2666    /// given dep resolves to — the [`Self::validate`] per-`:fonte`
2667    /// gate reading the author-declared source while the caixa-crd
2668    /// projector read a per-scope-override-resolved source would
2669    /// silently split the build-time refusal from the CR the
2670    /// substrate's admission pipeline actually materializes, one
2671    /// build-time diagnostic disagreeing with the run-time closure.
2672    /// Lifting the resolution rule to a typed method on the substrate
2673    /// primitive means every downstream consumer of the caixa's per-
2674    /// `:deps` fetch-source surface reaches for exactly one typed
2675    /// dispatch — the resolver's accept-set migrates as a unit on any
2676    /// future axis addition.
2677    ///
2678    /// First outer-`Dep` `Option<&Composite>`-return composite-reference
2679    /// accessor — opens the outer-`Dep` `Option<&Composite>` composite-
2680    /// reference projection pattern the sibling per-`Dep` `:opcional`
2681    /// (`Option<Copy>` — the plain-bool axis) / `:caracteristicas`
2682    /// (`&[String]` — the feature-flag list) future outer scalar / slice
2683    /// lifts fold on. Peer of the outer-top-level [`crate::Caixa`]
2684    /// `Option<&Composite>` composite-reference sub-family the
2685    /// [`crate::Caixa::limits`] (b2bd9d7) / [`crate::Caixa::behavior`]
2686    /// (35d8b52) / [`crate::Caixa::politicas`] (5d23d29) /
2687    /// [`crate::Caixa::placement`] (4fb8074) / [`crate::Caixa::entrada`]
2688    /// (e4128e4) accessors already close on the outer [`crate::Caixa`]
2689    /// altitude, and of the outer M3 mesh-slot [`crate::AplicacaoSpec`]
2690    /// altitude the sibling [`crate::AplicacaoSpec::entrada`] (d32111c)
2691    /// accessor already carries — extends that "one typed dispatch on
2692    /// the substrate primitive, thin projections at each consumer"
2693    /// discipline onto the third outer typed-slot altitude that carries
2694    /// an `Option<Composite>` axis (`Dep`, the outer per-dep-list-entry
2695    /// slot). Returns `Option<&DepSource>` (not the owning composite by
2696    /// copy or clone) because every downstream consumer of the fonte
2697    /// composite treats it as a read-only per-arm dispatch source — the
2698    /// reference-view is the narrowest borrow that supports every
2699    /// present + roadmapped consumer (per-arm match projection at the
2700    /// caixa-crd `CaixaSource` two-arm emitter, presence-probe early
2701    /// return on the "author-omitted `:fonte` ⇒ resolver-side
2702    /// `default_github` fill applies" partition every resolver
2703    /// consults, `.cloned()`-on-demand for the two resolver-side
2704    /// default-fill call sites that require an owned `DepSource` for
2705    /// `Option::unwrap_or_else`) without cloning the composite through
2706    /// every consumer's fast path. The `Option` half of the return-type
2707    /// preserves the load-bearing "author-omitted `:fonte` ⇒ resolver-
2708    /// side default applies" partition (not a default composite the
2709    /// downstream must reject on emptiness) — the accessor projects the
2710    /// raw `Option<DepSource>` slot's presence bit through the
2711    /// reference-return unchanged. Named `fonte()` to match the storage
2712    /// field's name verbatim and the tatara-lisp author-surface term
2713    /// (`:fonte`) the field's own docstring already carries.
2714    #[must_use]
2715    pub fn fonte(&self) -> Option<&DepSource> {
2716        self.fonte.as_ref()
2717    }
2718
2719    /// Substrate-canonical per-`:deps` / `:deps-dev` entry
2720    /// `:caracteristicas` Cargo-shaped feature-toggle-set slice accessor
2721    /// every consumer of the dep-graph feature-flag axis keys off —
2722    /// returns the author-declared `:caracteristicas` feature-name list
2723    /// verbatim as a `&[String]` slice-view over the same backing buffer
2724    /// the raw `self.caracteristicas.as_slice()` field access borrows
2725    /// from. Empty-list-carrying (`:caracteristicas` is a default-empty
2726    /// axis every `Dep` supplies with `Vec::new()` when the author omits
2727    /// the slot; the [`crate::Caixa::from_lisp`] derive folds an omitted
2728    /// `:caracteristicas` through `#[serde(default)]` to `Vec::new()`,
2729    /// so a `Dep` past parse definitionally carries a `Vec<String>` slot
2730    /// — possibly empty — and the returned `&[String]` degenerates to
2731    /// an empty slice on that arm without any silent `None` collapse).
2732    ///
2733    /// The `:deps :caracteristicas` / `:deps-dev :caracteristicas` slot
2734    /// carries the set-shaped feature-toggle list the substrate walks
2735    /// through the [`Self::validate_caracteristicas`] per-entry shape +
2736    /// duplicate cascade — same Cargo `[dependencies.<dep>.features]`
2737    /// accept-set (per-entry Cargo-feature-name grammar via the shared
2738    /// [`crate::render::is_cargo_feature_name`] predicate, cross-entry
2739    /// uniqueness via the shared [`crate::render::insert_first_seen`]
2740    /// walk, empty-first / value-shape-second / duplicate-third
2741    /// precedence via the peer per-axis two-arm cascade discipline every
2742    /// substrate-blessed Vec-keyed-by-name slot already follows).
2743    /// Every downstream consumer that fans on the dep's feature-toggle
2744    /// keys off this accessor: [`Self::validate_caracteristicas`]'s
2745    /// per-entry linear walk that gates each feature-name byte-string
2746    /// through the empty / value-shape / duplicate arms (raising the
2747    /// [`DepError::CaracteristicaEmpty`] / [`DepError::CaracteristicaInvalid`]
2748    /// / [`DepError::CaracteristicaDuplicate`] carrier family naming the
2749    /// offending `Dep::nome`), and every future
2750    /// per-`Caixa`-manifest / caixa-resolver / caixa-crd feature-toggle-
2751    /// facing consumer the CAIXA-SDLC §I roadmap acknowledges (the
2752    /// future caixa-resolver per-dep feature-projection walk that folds
2753    /// the toggle set into the resolved [`crate::Caixa`]'s activated
2754    /// [`crate::render::CARGO_FEATURE_NAME_MAX_LEN`]-bounded feature
2755    /// closure ahead of the lacre hash, the future caixa-crd per-`spec.deps`
2756    /// features slice the K8s-CR admission gate consumes, the future
2757    /// per-cluster feature-overlay the M4 lacre-federation resolver
2758    /// composes ahead of the substrate-wide feature-name accept-set).
2759    ///
2760    /// Prior to this lift the `.caracteristicas` byte-string list was
2761    /// read inline at the [`Self::validate_caracteristicas`] `for c in
2762    /// &self.caracteristicas` walk — the only in-crate consumer of the
2763    /// raw field beyond the per-`Dep` constructor pair
2764    /// ([`Self::simple`] / [`Self::git`]) and the paired serde
2765    /// round-trip / per-test fixture-mutation paths — an open-coded
2766    /// field-access that expressed no compile-time link back to the
2767    /// typed slot. A future extension of the `:caracteristicas` axis to
2768    /// a richer author surface (a per-scope feature-overlay the resolver
2769    /// folds through the `~/.config/caixa/config.yaml` entry the
2770    /// [`Dep`] docstring already acknowledges, a per-cluster feature-
2771    /// activation overlay the future M4 lacre-federation layer applies
2772    /// per-CR, a promotion of the plain `Vec<String>` byte-string list
2773    /// to a richer parsed-feature-set newtype once the Cargo-shaped
2774    /// namespaced-dep `dep/feat` syntax the value-shape gate's
2775    /// docstring anticipates lands) would have had to be threaded
2776    /// through every open-coded copy in lockstep or two consumers
2777    /// would silently disagree on which feature closure a given dep
2778    /// activates — the [`Self::validate_caracteristicas`] gate walking
2779    /// the author-declared list while a downstream caixa-resolver
2780    /// consumer walked a per-scope-override-resolved list would
2781    /// silently split the build-time refusal from the lacre closure
2782    /// the substrate's fetch pipeline actually materializes, one
2783    /// build-time diagnostic disagreeing with the run-time closure.
2784    /// Lifting the resolution rule to a typed method on the substrate
2785    /// primitive means every downstream consumer of the caixa's per-
2786    /// `:deps` feature-toggle surface reaches for exactly one typed
2787    /// dispatch — the resolver's accept-set migrates as a unit on any
2788    /// future axis addition.
2789    ///
2790    /// First outer-`Dep` `&[T]`-return slice accessor — opens the
2791    /// outer-`Dep` `&[String]` slice projection pattern the sibling
2792    /// per-`Dep` `:opcional` (`bool` — the plain-`Copy`-scalar axis)
2793    /// future outer scalar lift folds on and closes the outer-`Dep`
2794    /// slot-family the sibling [`Self::nome`] (eba2cde) /
2795    /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2796    /// accessors already open, leaving the `:opcional` `Copy`-scalar arm
2797    /// as the sole remaining unlifted outer-`Dep` slot. Peer of the
2798    /// outer top-level [`crate::Caixa`] `&[String]`-return foreign-code-
2799    /// slot sub-family ([`crate::Caixa::bibliotecas`] 8a36c23,
2800    /// [`crate::Caixa::exe`] 65d9527, [`crate::Caixa::servicos`]
2801    /// 611f78b) and the outer top-level [`crate::Caixa`] universal-axis
2802    /// text-tag family ([`crate::Caixa::autores`] b5d813f,
2803    /// [`crate::Caixa::etiquetas`] 78c7d3c) that already carry the
2804    /// `&[String]` slice-projection discipline on the outer-`Caixa`
2805    /// altitude — extends the "one typed dispatch on the substrate
2806    /// primitive, thin projections at each consumer" discipline onto the
2807    /// outer per-dep-list-entry [`Dep`] altitude's set-shaped byte-
2808    /// string list slot. Returns `&[String]` (not `&Vec<String>`)
2809    /// because every downstream consumer of the feature-toggle list
2810    /// treats it as a read-only sequence — the slice-view is the
2811    /// narrowest borrow that supports every present + roadmapped
2812    /// consumer (`.iter()`, `.len()`, `.is_empty()`) without leaking
2813    /// the backing `Vec`'s grow/push/reserve surface no consumer of
2814    /// the typed view reaches for (the storage-side `Vec` remains
2815    /// reachable through the `pub caracteristicas` field for the
2816    /// mutation-carrying serde round-trip and per-test fixture-mutation
2817    /// paths). Named `caracteristicas()` to match the storage field's
2818    /// name verbatim and the tatara-lisp author-surface term
2819    /// (`:caracteristicas`) the field's own docstring already carries.
2820    #[must_use]
2821    pub fn caracteristicas(&self) -> &[String] {
2822        self.caracteristicas.as_slice()
2823    }
2824
2825    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:opcional`
2826    /// missing-source-tolerance flag scalar accessor every consumer of
2827    /// the dep-graph opt-in-fetch axis keys off — returns the author-
2828    /// declared `:opcional` `bool` verbatim, `Copy`-projected from the
2829    /// typed slot's own `bool` storage (no borrow of `&self` past the
2830    /// call; the `Copy`-return arm matches the peer
2831    /// [`crate::Caixa::max_restarts`] (eba5211) `Option<u32>` `Copy`-
2832    /// projected sibling discipline the outer flat-spread family
2833    /// already carries). Default-`false` (`#[serde(default,
2834    /// skip_serializing_if = "is_false")]` on the storage slot, so a
2835    /// `Dep` past parse definitionally carries a `bool` — `false` when
2836    /// the author omits `:opcional` — and the returned value degenerates
2837    /// to `false` on that arm without any silent `None` collapse).
2838    ///
2839    /// The `:deps :opcional` / `:deps-dev :opcional` slot carries the
2840    /// per-entry "if this dep's `:fonte` cannot be resolved, treat the
2841    /// missing-source arm as a soft-fail rather than a build refusal"
2842    /// bit — the same Cargo-shaped `[dependencies.<dep>.optional = true]`
2843    /// accept-set (an opcional dep whose `:fonte` fails to resolve is
2844    /// dropped from the resolved dep-graph rather than tripping the
2845    /// build-refusal edge that a mandatory `:opcional false` entry
2846    /// would). Every downstream consumer that fans on the dep's
2847    /// missing-source-tolerance keys off this accessor: the future
2848    /// caixa-resolver's per-`:fonte` resolve-fail arm (drop-vs-error
2849    /// dispatch on the opcional bit ahead of the lacre closure
2850    /// materialization), the future caixa-crd per-`spec.deps`
2851    /// `optional` boolean the K8s-CR admission gate consumes on the
2852    /// per-dep partition, and the future feira / caixa-resolver /
2853    /// caixa-crd feature-projection walk that folds the opcional bit
2854    /// into the resolved feature-closure the future M4 lacre-federation
2855    /// layer emits.
2856    ///
2857    /// Prior to this lift the `.opcional` `bool` slot was read inline
2858    /// at the sole in-crate consumer site — the tests-module
2859    /// `registry_dep_is_minimal` fixture's `assert!(!d.opcional)` gate
2860    /// pinning the [`Self::simple`] constructor's default-`false` fill
2861    /// (the only in-crate read of the raw field beyond the per-`Dep`
2862    /// constructor pair [`Self::simple`] / [`Self::git`] and the paired
2863    /// serde round-trip / per-test fixture-mutation paths) — an open-
2864    /// coded field-access that expressed no compile-time link back to
2865    /// the typed slot. A future extension of the `:opcional` axis to a
2866    /// richer author surface (a per-scope opcional-override the resolver
2867    /// folds through the `~/.config/caixa/config.yaml` entry the [`Dep`]
2868    /// docstring already acknowledges, a per-cluster opcional-override
2869    /// the future M4 lacre-federation layer applies per-CR, a promotion
2870    /// of the plain `bool` to a richer `OpcionalPolicy { drop, warn,
2871    /// error }` tri-state once the CAIXA-SDLC §II opcional-policy
2872    /// roadmap lands) would have had to be threaded through every open-
2873    /// coded copy in lockstep or two consumers would silently disagree
2874    /// on which missing-source arm a given dep resolves to — the
2875    /// [`Self::simple`] constructor's default-`false` fill reading
2876    /// verbatim while a downstream caixa-resolver consumer read a per-
2877    /// scope-override-resolved bit would silently split the build-time
2878    /// arm from the lacre closure the substrate's fetch pipeline
2879    /// actually materializes, one build-time diagnostic disagreeing
2880    /// with the run-time closure. Lifting the resolution rule to a
2881    /// typed method on the substrate primitive means every downstream
2882    /// consumer of the caixa's per-`:deps` opcional-tolerance surface
2883    /// reaches for exactly one typed dispatch — the resolver's accept-
2884    /// set migrates as a unit on any future axis addition.
2885    ///
2886    /// Fifth and final outer-`Dep` accessor — closes the outer-`Dep`
2887    /// slot-family the sibling per-`Dep` [`Self::nome`] (eba2cde) /
2888    /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2889    /// / [`Self::caracteristicas`] (9197944) accessors opened, so every
2890    /// outer-`Dep` slot (`:nome`, `:versao`, `:fonte`, `:opcional`,
2891    /// `:caracteristicas`) now routes through exactly one typed
2892    /// dispatch on the substrate primitive. First outer-`Dep`
2893    /// `bool`-return / plain-`Copy`-scalar accessor — opens the
2894    /// outer-`Dep` `Copy`-scalar projection pattern that folds on the
2895    /// peer outer-top-level [`crate::Caixa`] `Option<Copy>`
2896    /// flat-spread sub-family ([`crate::Caixa::max_restarts`] eba5211,
2897    /// [`crate::Caixa::estrategia`] ed04d3c) the outer-`Caixa` altitude
2898    /// already carries — extends the "one typed dispatch on the
2899    /// substrate primitive, thin projections at each consumer"
2900    /// discipline onto the outer per-dep-list-entry [`Dep`] altitude's
2901    /// bool-shaped missing-source-tolerance slot. Returns `bool` by
2902    /// `Copy` (not by `&bool` reference) because `bool` is `Copy` and
2903    /// every downstream consumer treats it as a plain discriminant
2904    /// value — the by-value return is the narrowest return-shape that
2905    /// supports every present + roadmapped consumer (`.then(…)` early
2906    /// return on the resolver-side drop-vs-error partition, direct
2907    /// bool composition with a per-scope-override projector, plain
2908    /// `if dep.opcional() { … }` early return at every future admission
2909    /// gate) without leaking the storage field's `bool`-in-`&self`
2910    /// lifetime the by-value return elides. Marked `pub const fn` so
2911    /// the accessor is `const`-callable — same discipline the peer
2912    /// [`crate::Caixa::max_restarts`] `Option<u32>` `Copy`-return
2913    /// accessor carries. Named `opcional()` to match the storage
2914    /// field's name verbatim and the tatara-lisp author-surface term
2915    /// (`:opcional`) the field's own docstring already carries.
2916    #[must_use]
2917    pub const fn opcional(&self) -> bool {
2918        self.opcional
2919    }
2920
2921    /// Build a minimal registry-sourced dep.
2922    #[must_use]
2923    pub fn simple(nome: impl Into<String>, versao: impl Into<String>) -> Self {
2924        Self {
2925            nome: nome.into(),
2926            versao: versao.into(),
2927            fonte: None,
2928            opcional: false,
2929            caracteristicas: Vec::new(),
2930        }
2931    }
2932
2933    /// Build a Git-sourced dep (tag-based).
2934    #[must_use]
2935    pub fn git(
2936        nome: impl Into<String>,
2937        versao: impl Into<String>,
2938        repo: impl Into<String>,
2939        tag: impl Into<String>,
2940    ) -> Self {
2941        Self {
2942            nome: nome.into(),
2943            versao: versao.into(),
2944            fonte: Some(DepSource::Git {
2945                repo: repo.into(),
2946                tag: Some(tag.into()),
2947                rev: None,
2948                branch: None,
2949            }),
2950            opcional: false,
2951            caracteristicas: Vec::new(),
2952        }
2953    }
2954
2955    /// Reject dependency entries whose `:nome` or `:versao` are empty,
2956    /// whose `:nome` is non-empty but not a valid DNS-1123 label,
2957    /// or whose `:versao` is non-empty but not a valid Cargo-shaped
2958    /// semver requirement.
2959    ///
2960    /// The author surface for `:deps :versao` (and `:deps-dev :versao`)
2961    /// is the same Cargo-shaped requirement string `:membros :versao`
2962    /// (validated at [`crate::AplicacaoSpec::validate`] since 9888b13)
2963    /// and `:children :versao` (validated at
2964    /// [`crate::SupervisorSpec::validate`] since b38ff3a) carry — and
2965    /// the lacre pipeline resolves all three axes through the same
2966    /// [`crate::parse_requirement`] entry-point. Until 2420c44 landed
2967    /// `:deps :versao` was the last `:versao` axis untyped past
2968    /// `Caixa::from_lisp`: a malformed-but-non-empty requirement
2969    /// (`"^bad-version"`, `"^^0.1"`, the canonical git-tag-shape-
2970    /// leaking-into-:versao `"v0.1"` typo, the accidental
2971    /// `"not-a-req"`) silently passed parse and the `semver::Error`
2972    /// surfaced at lacre-resolve time, far from the source
2973    /// caixa.lisp, with no field naming which `:deps` entry carried
2974    /// the typo. The diagnostic [`DepError::VersaoInvalid`] carries
2975    /// the offending entry's `:nome` + the offending `:versao`
2976    /// verbatim + the parser's own wording in `reason`, so the
2977    /// author's grep target is unambiguous.
2978    ///
2979    /// The author surface for `:deps :nome` is the same DNS-1123 label
2980    /// the peer caixa-identifier axes carry — top-level Caixa `:nome`
2981    /// (validated at [`crate::Caixa::validate_nome`] since 6c992f8),
2982    /// `:membros :caixa` (validated at
2983    /// [`crate::AplicacaoSpec::validate_membros`] since 3f9d7a0),
2984    /// `:children :caixa` (validated at
2985    /// [`crate::SupervisorSpec::validate`] since 31bfa43). A `:deps
2986    /// :nome` value flows verbatim through the lacre pipeline as the
2987    /// target caixa's `:nome` (which the gate at the *target* side now
2988    /// rejects if non-DNS-1123) and lands as the rendered caixa's
2989    /// `lareira-<nome>` Helm chart name segment, the per-dep
2990    /// `LABEL_PROGRAM` label value, and the `caixa-resolver`'s
2991    /// `~/.cache/caixa/<org>/<nome>` checkout-directory leaf. Until
2992    /// this gate landed `:deps :nome` was the fourth and last
2993    /// DNS-1123-shaped caixa-identifier axis still untyped past
2994    /// `Caixa::from_lisp`: a syntactically wrong dep name (`"Caixa-
2995    /// Teia"` uppercase — the canonical "I copied the README header"
2996    /// typo; `"caixa_teia"` underscore — the Go module / Python
2997    /// identifier leak; `"caixa-teia."` trailing dot — the FQDN
2998    /// confusion; `"-caixa-teia"` leading hyphen; a 64-byte slug)
2999    /// silently passed parse and surfaced at lacre-resolve time when
3000    /// the resolved target caixa's `:nome` failed *its* DNS-1123 gate
3001    /// — far from the source `:deps` entry, with a diagnostic naming
3002    /// the *target's* `:nome` rather than the dep entry that referenced
3003    /// it. Mirroring the 3f9d7a0 / 31bfa43 / 6c992f8 trajectory through
3004    /// the lifted [`crate::render::is_dns_1123_label`] predicate (the
3005    /// "before its third occurrence" PRIME DIRECTIVE boundary, THEORY.md
3006    /// §I.3.5): every `Dep::nome` past validate is DNS-1123-label-shaped,
3007    /// so every downstream consumer (caixa-resolver's lacre fetch,
3008    /// caixa-helm's `lareira-<nome>` chart name, the future M4 per-dep
3009    /// fan-out emitter) reaches for the name knowing the value is
3010    /// apiserver-valid without re-validating.
3011    ///
3012    /// Empty checks fire first (narrower diagnostic), parse last —
3013    /// same ordering discipline as
3014    /// [`crate::AplicacaoSpec::validate_membros`] and
3015    /// [`crate::SupervisorSpec::validate`]. `parse_requirement("")`
3016    /// returns `Ok(VersionReq::STAR)`, so the empty-`:versao` arm is
3017    /// structurally necessary even with the parse arm in place. The
3018    /// `:nome` shape gate runs after the `:nome` empty gate and before
3019    /// the `:versao` checks so a one-entry caixa.lisp with both wrong
3020    /// sees the name-side diagnostic first (the name is the
3021    /// self-locating axis — without it, the parse diagnostic can't
3022    /// quote `:nome "<bad>"`).
3023    pub fn validate(&self) -> Result<(), DepError> {
3024        if self.nome.is_empty() {
3025            return Err(DepError::NomeEmpty);
3026        }
3027        if let Err(reason) = crate::render::is_dns_1123_label(&self.nome) {
3028            return Err(DepError::NomeInvalid {
3029                nome: self.nome.clone(),
3030                reason,
3031            });
3032        }
3033        // Delegate the empty-first + `parse_requirement` cascade to the
3034        // shared [`crate::render::require_valid_versao_requirement`]
3035        // helper — same two-arm shape the peer
3036        // [`crate::AplicacaoSpec::validate_membros`] on `:membros
3037        // :versao` and [`crate::SupervisorSpec::validate`] on `:children
3038        // :versao` route through, so drift between the three axes'
3039        // accepted requirement sets is structurally impossible and the
3040        // parse-side no-op the empty-first arm closes (semver's empty
3041        // parse yields an implicit `*`) lives in exactly one predicate.
3042        crate::render::require_valid_versao_requirement(
3043            self.versao_requirement(),
3044            || DepError::VersaoEmpty {
3045                nome: self.nome.clone(),
3046            },
3047            |reason| DepError::VersaoInvalid {
3048                nome: self.nome.clone(),
3049                versao: self.versao_requirement().to_string(),
3050                reason,
3051            },
3052        )?;
3053        if let Some(fonte) = self.fonte() {
3054            fonte.validate(&self.nome)?;
3055        }
3056        self.validate_caracteristicas()?;
3057        Ok(())
3058    }
3059
3060    /// Reject per-entry `:caracteristicas` (feature-flag) values that
3061    /// are operationally meaningless. The `:caracteristicas` slot is
3062    /// a set of feature toggles to enable on the target caixa — same
3063    /// shape as Cargo's `[dependencies.<dep>.features]` list — and
3064    /// two structural footguns close here:
3065    ///
3066    ///   - empty-string entry (`(:caracteristicas (""))`): the future
3067    ///     caixa-resolver lacre pipeline would consume the empty
3068    ///     identifier as a no-op feature enable, silently dropping the
3069    ///     author's intent far from the source `caixa.lisp`;
3070    ///   - duplicate entry within one dep (`(:caracteristicas ("http"
3071    ///     "http"))`): the feature-toggle slot is set-shaped (enabling
3072    ///     a feature twice has no additional semantic — there is no
3073    ///     `feature × 2`), so two entries naming the same feature are
3074    ///     a silent miscount, the same set-not-multiset distinction
3075    ///     every peer Vec-keyed-by-name axis already closes
3076    ///     ([`crate::SupervisorError::DuplicateChildCaixa`] on
3077    ///     `:children :caixa`, [`crate::AplicacaoError::MembroDuplicate`]
3078    ///     on `:membros :caixa`, [`crate::AplicacaoError::ContratoDuplicate`]
3079    ///     on `:contratos`, [`crate::AplicacaoError::PlacementClusterDuplicate`]
3080    ///     on `:placement :clusters`, [`crate::AplicacaoError::EntradaPathDuplicate`]
3081    ///     on `:entrada :paths`, [`crate::UpgradeError::DuplicateFrom`]
3082    ///     on `:upgrade-from :from`, [`crate::UpgradeError::DuplicateLoadModule`]
3083    ///     / [`crate::UpgradeError::DuplicateStateChange`] /
3084    ///     [`crate::UpgradeError::DuplicateCleanup`] on the within-
3085    ///     entry `:upgrade-from` axes, and [`DepError::DuplicateNome`]
3086    ///     on the cross-entry `:deps`/`:deps-dev` `:nome` axis the
3087    ///     immediate-predecessor 359fba5 closed).
3088    ///
3089    /// Same linear-walk + `HashSet` + first-collision diagnostic shape
3090    /// every peer set-not-multiset gate uses; the empty arm fires
3091    /// before the duplicate arm so an entry with both an empty feature
3092    /// *and* a duplicate of some later feature surfaces the empty-
3093    /// shape diagnostic first (the empty-feature axis is the
3094    /// more-actionable defect since the missing-name renders the
3095    /// duplicate-key arm ambiguous: two `""` entries would both report
3096    /// `caracteristica: ""` with no way to distinguish the offending
3097    /// site). Empty-first cascade discipline mirrors every peer per-
3098    /// entry shape + duplicate gate
3099    /// (`SupervisorSpec::validate`'s `EmptyChildName` before
3100    /// `DuplicateChildCaixa`; `validate_membros`'s `MembroCaixaEmpty`
3101    /// before `MembroDuplicate`).
3102    ///
3103    /// The per-entry value-shape gate (Cargo-feature-name grammar via
3104    /// the lifted [`crate::render::is_cargo_feature_name`] predicate)
3105    /// fires between the empty arm and the duplicate arm — the
3106    /// canonical per-entry-shape-before-cross-entry-uniqueness
3107    /// precedence every peer two-arm + value-shape gate establishes
3108    /// ([`crate::SupervisorSpec::validate`]'s `EmptyChildName` →
3109    /// `ChildCaixaInvalid` → `DuplicateChildCaixa`,
3110    /// [`crate::AplicacaoSpec::validate_membros`]'s `MembroCaixaEmpty`
3111    /// → `MembroCaixaInvalid` → `MembroDuplicate`, [`Dep::validate`]'s
3112    /// `NomeEmpty` → `NomeInvalid` → cross-list `DuplicateNome`).
3113    /// Until the value-shape arm landed `:caracteristicas` accepted
3114    /// every non-empty distinct string — a structurally invalid
3115    /// feature name (`"http feature"` whitespace, `"+http"` the
3116    /// canonical paste-from-`+optional-feature` doc activation-form
3117    /// footgun, `"-flag"` leading hyphen, `".feat"` leading dot,
3118    /// `"http/json"` Cargo's `dep/feat` namespaced-dep syntax that
3119    /// only applies inside list-grammar contexts, `"http,json"`
3120    /// list-separator-belongs-to-the-list-grammar miscomprehension,
3121    /// `"café"` un-percent-encoded non-ASCII silently round-tripping
3122    /// inconsistently across NFC/NFD normalization, the 65-byte
3123    /// paste-from-binary slug) silently passed validate and the
3124    /// failure surfaced at `cargo metadata` time as the
3125    /// `restricted_names::validate_feature_name` parser's rejection,
3126    /// far from the source `caixa.lisp`, with no field naming which
3127    /// `:deps` entry's `:caracteristicas` carried the typo. The
3128    /// lifted predicate makes the Cargo-feature-name-grammar
3129    /// intersection-floor a substrate-level invariant at validate
3130    /// time — same trajectory as the eight peer
3131    /// [`crate::render`] value-shape predicates each typed surface
3132    /// downstream of a structured grammar already follows
3133    /// ([`is_dns_1123_label`](crate::render::is_dns_1123_label),
3134    /// [`is_gateway_api_http_path`](crate::render::is_gateway_api_http_path),
3135    /// [`is_wit_world_ref`](crate::render::is_wit_world_ref),
3136    /// [`is_nats_subject`](crate::render::is_nats_subject),
3137    /// [`is_wasi_keyvalue_slot`](crate::render::is_wasi_keyvalue_slot),
3138    /// [`is_git_ref_name`](crate::render::is_git_ref_name),
3139    /// [`is_git_oid`](crate::render::is_git_oid),
3140    /// [`is_git_repo_url`](crate::render::is_git_repo_url)).
3141    fn validate_caracteristicas(&self) -> Result<(), DepError> {
3142        let mut seen = std::collections::HashSet::new();
3143        for c in self.caracteristicas() {
3144            if c.is_empty() {
3145                return Err(DepError::CaracteristicaEmpty {
3146                    nome: self.nome.clone(),
3147                });
3148            }
3149            if let Err(reason) = crate::render::is_cargo_feature_name(c) {
3150                return Err(DepError::CaracteristicaInvalid {
3151                    nome: self.nome.clone(),
3152                    caracteristica: c.clone(),
3153                    reason,
3154                });
3155            }
3156            crate::render::insert_first_seen(&mut seen, c.as_str(), || {
3157                DepError::CaracteristicaDuplicate {
3158                    nome: self.nome.clone(),
3159                    caracteristica: c.clone(),
3160                }
3161            })?;
3162        }
3163        Ok(())
3164    }
3165}
3166
3167/// Cross-slot coherence gate on the dep-graph axis: no `:deps` or
3168/// `:deps-dev` entry may name the caixa's own `:nome`.
3169///
3170/// A caixa that lists itself as a dep is a degenerate self-edge in the
3171/// lacre closure's dep-graph — the closure is a DAG rooted at the
3172/// caixa's `:nome`, and the caixa-resolver's lacre pipeline traverses
3173/// every `:deps` / `:deps-dev` entry's target by name. A self-dep
3174/// hands the resolver a node that is its own parent: a one-node cycle
3175/// it either rejects mid-traversal far from the source `caixa.lisp`
3176/// (the resolver detecting infinite recursion on the closure walk) or,
3177/// worse, recurses on until it exhausts its stack. Because every
3178/// `:nome` is a globally-unique substrate identity (DNS-1123 label +
3179/// lacre closure root), a dep entry whose `:nome` equals the caixa's
3180/// own `:nome` *is* the caixa itself, not a coincidentally-named peer.
3181///
3182/// Lives outside [`Caixa::validate_deps`] because the dep-list view
3183/// carries the entries but not the parent `:nome`; mirrors the
3184/// cross-slot self-edge gates [`crate::supervisor::validate_no_self_supervision`]
3185/// (ad4abf1) on the `:children :caixa` axis and
3186/// [`crate::aplicacao::validate_no_self_membership`] on the
3187/// `:membros :caixa` axis — the same "an edge from a graph node to
3188/// itself is structurally not a tree/graph edge" discipline, here on
3189/// the third typed-name-graph axis (the dep closure; the supervision
3190/// tree and the Aplicacao membership set were the prior two).
3191///
3192/// Walks `:deps` first then `:deps-dev` so the diagnostic for a caixa
3193/// that self-references on both axes surfaces the `:deps` arm first —
3194/// the load-bearing axis the lacre closure resolves at every build,
3195/// peer with the canonical [`Caixa::validate_deps`] walk order
3196/// (`:deps` → `:deps-dev`).
3197///
3198/// Carries the offending list tag (`":deps"` or `":deps-dev"`)
3199/// verbatim into the diagnostic so the author can grep their
3200/// `caixa.lisp` for the offending block in one edit — same
3201/// `list: &'static str` shape [`DepError::DuplicateNome`] (359fba5)
3202/// uses on the cross-list duplicate-name axis.
3203///
3204/// `Code paths` (`:bibliotecas` / `:exe` / `:servicos`) are the
3205/// substrate-blessed shape for referencing the caixa's *own* code, so
3206/// the diagnostic names them as the corrective surface — every
3207/// legitimate "I want to use code from this caixa" authoring intent
3208/// routes through one of those three slots, not a self-dep.
3209pub fn validate_no_self_dep(
3210    deps: &[Dep],
3211    deps_dev: &[Dep],
3212    parent_nome: &str,
3213) -> Result<(), DepError> {
3214    for dep in deps {
3215        if dep.nome() == parent_nome {
3216            return Err(DepError::DepIsSelf {
3217                nome: parent_nome.to_string(),
3218                list: crate::render::DEP_AUTHOR_KEY_DEPS,
3219            });
3220        }
3221    }
3222    for dep in deps_dev {
3223        if dep.nome() == parent_nome {
3224            return Err(DepError::DepIsSelf {
3225                nome: parent_nome.to_string(),
3226                list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3227            });
3228        }
3229    }
3230    Ok(())
3231}
3232
3233/// Closed-set typed enum for the two dep-list author-surface axes every
3234/// top-level [`crate::Caixa`] carries — the runtime-closure `:deps` slot
3235/// (`Prod`) and the dev-only-closure `:deps-dev` slot (`Dev`). Every
3236/// substrate consumer that dispatches on "which of the two dep-lists"
3237/// (the `feira add` mutation head, the future per-cluster dev-closure-
3238/// audit overlay the M4 CR materializer resolves per-CR, the future
3239/// `caixa app graph` per-list dep summary, every future
3240/// `Caixa::push_dep` / `Caixa::deps_by_list` typed-method dispatch a
3241/// caller reaches for) reads through this enum rather than through a
3242/// bare `&'static str` — the closed-set is expressed at the type layer,
3243/// so a future third dep-list axis (a `:deps-build` build-only closure
3244/// once the substrate grows cross-artifact heterogeneous dep-graphs,
3245/// per CAIXA-SDLC §I) is one variant plus one arm per method and the
3246/// compiler enforces exhaustiveness on every consumer's `match` arms.
3247///
3248/// The wire byte-string [`Self::as_str`] returns is the same author-
3249/// surface tag the sibling [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3250/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry — the
3251/// [`DepError::DuplicateNome`] / [`DepError::DepIsSelf`] `list:
3252/// &'static str` payload family the substrate already emits routes
3253/// through the same source of truth (an author reading a
3254/// [`DepError::DuplicateNome`] refusal can grep their `caixa.lisp`
3255/// for the offending `:deps` / `:deps-dev` block in one edit whether
3256/// the diagnostic came from a `Caixa::validate_deps` walk or a
3257/// `Caixa::push_dep` mutation).
3258///
3259/// Same "closed-set typed-enum discriminator with canonical
3260/// projections per axis" discipline the sibling closed-set typed enums
3261/// on the caixa typed surface carry
3262/// ([`crate::aplicacao::PlacementStrategy`] cc8f749,
3263/// [`crate::aplicacao::RateLimitUnit`] 6bce03d,
3264/// [`crate::supervisor::RestartStrategy`],
3265/// [`crate::supervisor::RestartPolicy`],
3266/// [`crate::upgrade::UpgradeInstruction`], [`crate::CaixaKind`])
3267/// — extended onto the outer-`Caixa` two-list dep-graph axis, the
3268/// substrate's last unlifted closed-set-shaped `&'static str`-carrying
3269/// axis on the top-level manifest surface.
3270#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
3271pub enum DepList {
3272    /// Runtime-closure `:deps` axis — the load-bearing dep-list the
3273    /// lacre closure resolves at every build. Wire-format
3274    /// [`crate::render::DEP_AUTHOR_KEY_DEPS`].
3275    Prod,
3276    /// Dev-only-closure `:deps-dev` axis — Cargo's `[dev-dependencies]`
3277    /// table's dev-time-only visibility contract per CAIXA-SDLC §I.
3278    /// Wire-format [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`].
3279    Dev,
3280}
3281
3282impl DepList {
3283    /// Exhaustive iteration surface for every consumer that reads the
3284    /// full closed-set (the future M4 admission webhook's per-list
3285    /// summary rejection body, any future round-trip pin harness). A
3286    /// future variant addition extends this slice as a single edit and
3287    /// every consumer picks up the new entry by construction — the
3288    /// compiler-checked exhaustiveness on the sibling method `match`
3289    /// arms is the build-time guarantee that no arm forgets to grow.
3290    pub const ALL: &'static [Self] = &[Self::Prod, Self::Dev];
3291
3292    /// Canonical author-surface tag every substrate consumer that
3293    /// names the offending dep-list in a diagnostic reaches for —
3294    /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] for [`Self::Prod`] and
3295    /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] for [`Self::Dev`],
3296    /// the same `&'static str` payload the sibling
3297    /// [`DepError::DuplicateNome`] and [`DepError::DepIsSelf`] variants
3298    /// already carry. Routing every dep-list diagnostic through the
3299    /// closed-set enum's `as_str` closes the last `&'static str`-shape
3300    /// literal-carry axis on the two-list dep-graph surface — a
3301    /// future kebab-case rebrand (`":deps"` → `":packages"`) or a
3302    /// wire-format promotion (a distinct diagnostic form for the
3303    /// `Dev` arm) reaches every consumer through one edit on the
3304    /// canonical constant, not a coordinated rewrite across the
3305    /// substrate's dep-graph consumers.
3306    #[must_use]
3307    pub const fn as_str(self) -> &'static str {
3308        match self {
3309            Self::Prod => crate::render::DEP_AUTHOR_KEY_DEPS,
3310            Self::Dev => crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3311        }
3312    }
3313
3314    /// Substrate-canonical reverse projection on the two-list dep-graph
3315    /// axis — parses the author-surface wire tag back to the typed
3316    /// variant, or `None` when `s` is outside the closed-set arm-string
3317    /// set [`Self::as_str`] emits. Dispatches on the same lifted
3318    /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3319    /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants the
3320    /// [`Self::as_str`] emitter walks, so the parse and emit halves of
3321    /// the round-trip migrate through one caixa-core edit on any future
3322    /// list-axis addition.
3323    ///
3324    /// Prior to this lift the substrate carried only the forward
3325    /// `Self → &str` projection on the two-list dep-graph axis (the
3326    /// [`Self::as_str`] emitter, the [`std::fmt::Display`] impl routed
3327    /// through it, the two [`DepError::DuplicateNome`] /
3328    /// [`DepError::DepIsSelf`] variants that carry the wire tag verbatim
3329    /// as a `&'static str` `list:` field). Every future consumer that
3330    /// wanted to promote the wire tag back to the typed enum (a future
3331    /// `feira dep --list <deps|deps-dev>` CLI arg-parse that binds the
3332    /// wire form into the typed enum before dispatching to
3333    /// [`crate::Caixa::deps_of`] / [`crate::Caixa::push_dep`], the M4
3334    /// `mesh.pleme.io/v1alpha1/Caixa` CR materializer's admission-time
3335    /// wire re-parse of the per-list diagnostic body, a future
3336    /// [`DepError`] widening that promotes the two `list: &'static str`
3337    /// fields to a typed `list: DepList` carry so downstream consumers
3338    /// dispatch on the enum rather than string-comparing the wire
3339    /// scalar) would have had to re-inline a two-arm `match s { ":deps"
3340    /// => …, ":deps-dev" => …, _ => … }` cascade that expressed no
3341    /// compile-time link back to the typed [`DepList`] enum. A future
3342    /// variant addition (a `:build-dep` or `:test-dep` third list once
3343    /// the substrate grows Cargo-style split-graphs, a `:tool-dep` for
3344    /// build-time-only tooling per the peer Cargo `[build-dependencies]`
3345    /// / `[target.<cfg>.dev-dependencies]` future admission surface)
3346    /// would silently split the wire byte-string the emitter walks from
3347    /// the parser's arm-set — the round-trip would carry the new list
3348    /// through the forward projection but land on the fallback silently
3349    /// at every non-updated reverse parser, far from the arm-addition
3350    /// commit that caused the drift. Lifting the resolver to a typed
3351    /// method on the substrate primitive closes the drift footgun by
3352    /// construction: the parser's accept-set is the same set the
3353    /// [`Self::as_str`] emitter walks (routed through the same lifted
3354    /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3355    /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] consts), so both halves
3356    /// of the round-trip migrate through one caixa-core edit on any
3357    /// future list-axis addition.
3358    ///
3359    /// Same closed-set-reverse-projection discipline the sibling
3360    /// [`crate::CaixaKind::from_wire`] (2aa6d23) /
3361    /// [`crate::supervisor::RestartStrategy::from_wire`] (4eec29c) /
3362    /// [`crate::supervisor::RestartPolicy::from_wire`] (dd32ccf) /
3363    /// [`crate::aplicacao::PlacementStrategy::from_wire`] (18c7342) /
3364    /// [`crate::aplicacao::RateLimitUnit::from_suffix`] typed enums
3365    /// carry on the peer wire-side `str → Self` axes — extended onto
3366    /// the two-list dep-graph closed-set axis, the sixth substrate-side
3367    /// closed-set typed enum on the caixa surface to converge on the
3368    /// two-way `str ↔ Self` round-trip. Method-named `from_wire` (not
3369    /// `from_str`) to match the peer shapes verbatim and side-step the
3370    /// derived [`std::str::FromStr`] impls the sibling
3371    /// [`gen_platform::FromStrKind`]-carrying axes install on their
3372    /// kebab-case dispatcher-catalog identity. Returns `Option<Self>`
3373    /// (rather than `Result<Self, _>`) to match the peer shapes: the
3374    /// caller picks the diagnostic form appropriate for its use site —
3375    /// a future `feira dep --list …` arg-parse that surfaces
3376    /// `unknown list: <arg>` at the CLI builds one on top by iterating
3377    /// [`Self::ALL`], while the future M4 admission-webhook's rejection
3378    /// path folds `None` onto its per-CR structured refusal body.
3379    #[must_use]
3380    pub fn from_wire(s: &str) -> Option<Self> {
3381        match s {
3382            crate::render::DEP_AUTHOR_KEY_DEPS => Some(Self::Prod),
3383            crate::render::DEP_AUTHOR_KEY_DEPS_DEV => Some(Self::Dev),
3384            _ => None,
3385        }
3386    }
3387}
3388
3389/// Route [`std::fmt::Display`] through [`DepList::as_str`], so every
3390/// consumer that formats the axis as user-facing text (a future
3391/// `feira app graph` per-list summary, a future M4 admission-webhook
3392/// rejection body naming the offending list, this crate's own
3393/// [`DepError`] `#[error(...)]` templates when they widen to carry a
3394/// typed [`DepList`]) lands on the same author-surface tag the
3395/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3396/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry. Same
3397/// as-str-through-Display convergence discipline the sibling
3398/// [`crate::aplicacao::PlacementStrategy`],
3399/// [`crate::aplicacao::RateLimitUnit`],
3400/// [`crate::supervisor::RestartStrategy`],
3401/// [`crate::supervisor::RestartPolicy`], and [`crate::CaixaKind`]
3402/// closed-set typed enums carry.
3403impl std::fmt::Display for DepList {
3404    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3405        f.write_str(self.as_str())
3406    }
3407}
3408
3409/// Errors raised by [`Dep::validate`].
3410///
3411/// Mirrors the per-axis error families the other `:versao`-carrying
3412/// typed surfaces expose
3413/// ([`crate::AplicacaoError::MembroVersaoEmpty`] /
3414/// [`crate::AplicacaoError::MembroVersaoInvalid`],
3415/// [`crate::SupervisorError::EmptyChildVersion`] /
3416/// [`crate::SupervisorError::ChildVersaoInvalid`]) so a future top-
3417/// level `CaixaError` (M4) sums these without reshaping the diagnostic.
3418#[derive(Debug, Error, PartialEq, Eq)]
3419pub enum DepError {
3420    #[error(
3421        ":deps entry has empty :nome (every dep must name a target caixa; \
3422         omit the entry instead of carrying an empty name)"
3423    )]
3424    NomeEmpty,
3425    #[error(
3426        ":deps entry :nome {nome:?} is not a valid DNS-1123 label: {reason} \
3427         (the value flows verbatim as the target caixa's `:nome`, the rendered \
3428         `lareira-<nome>` Helm chart name segment, the `LABEL_PROGRAM` label \
3429         value, and the resolver's checkout-directory leaf — each apiserver-side \
3430         schema rejects non-DNS-1123 names at admission time; use a lowercase \
3431         RFC 1123 label like `\"caixa-teia\"` or `\"pleme-mesh\"`, 1..=63 bytes, \
3432         pattern `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)"
3433    )]
3434    NomeInvalid { nome: String, reason: String },
3435    #[error(
3436        ":deps entry {nome:?} has empty :versao (every dep must pin a semver \
3437         constraint that resolves through the lacre pipeline)"
3438    )]
3439    VersaoEmpty { nome: String },
3440    #[error(
3441        ":deps entry {nome:?} :versao {versao:?} is not a valid semver \
3442         requirement: {reason} (use Cargo-shaped forms like `\"^0.1\"`, \
3443         `\"~0.1.2\"`, `\"0.1.0\"`, or `\"*\"` — the same shape `:membros :versao` \
3444         and `:children :versao` carry; the lacre pipeline resolves all three \
3445         through the same parser)"
3446    )]
3447    VersaoInvalid {
3448        nome: String,
3449        versao: String,
3450        reason: String,
3451    },
3452    #[error(
3453        ":deps entry {nome:?} :fonte (:tipo git …) has empty :repo \
3454         (every git source must name a repo — use a `github:org/repo` \
3455         shorthand, an `https://…` URL, or an ssh-git URL; omit the \
3456         entire :fonte block to fall back to the default-host resolver \
3457         convention)"
3458    )]
3459    FonteRepoEmpty { nome: String },
3460    #[error(
3461        ":deps entry {nome:?} :fonte (:tipo git …) :repo {repo:?} has \
3462         invalid value-shape: {reason} (the value flows verbatim into the \
3463         caixa-resolver's `git clone <repo>` subprocess invocation; every \
3464         documented form carries a `:` separator and no whitespace / \
3465         control / non-ASCII bytes — use a `github:org/repo` shorthand, \
3466         an `https://host/path` / `ssh://[user@]host/path` / \
3467         `git://host/path` / `file:///path` URL, or the `git@host:path` \
3468         scp-style SSH form)"
3469    )]
3470    FonteRepoShape {
3471        nome: String,
3472        repo: String,
3473        reason: String,
3474    },
3475    #[error(
3476        ":deps entry {nome:?} :fonte (:tipo git …) has no pin set \
3477         (set exactly one of :tag, :rev, or :branch so the resolver \
3478         can pick a reproducible commit; omit the entire :fonte block \
3479         to fall back to the default-host resolver convention, which \
3480         resolves the latest tag matching :versao)"
3481    )]
3482    FontePinMissing { nome: String },
3483    #[error(
3484        ":deps entry {nome:?} :fonte (:tipo git …) has multiple pins \
3485         set ({pins}); exactly one of :tag, :rev, or :branch must be \
3486         set so the resolver's checkout target is unambiguous (the \
3487         resolver's silent precedence is :rev > :tag > :branch — if \
3488         you intended one specifically, drop the others)"
3489    )]
3490    FontePinAmbiguous { nome: String, pins: String },
3491    #[error(
3492        ":deps entry {nome:?} :fonte (:tipo git …) has empty {pin} \
3493         (a set pin must name a non-empty git ref; drop the {pin} key \
3494         entirely to fall through to another pin axis)"
3495    )]
3496    FontePinEmpty { nome: String, pin: String },
3497    #[error(
3498        ":deps entry {nome:?} :fonte (:tipo git …) {pin} {value:?} has invalid \
3499         value-shape: {reason} (the git porcelain enforces the same shape at \
3500         `git fetch` / `git checkout` time on every pin; use a leaf refname \
3501         like `\"v0.1.0\"` for `:tag` or `\"main\"` / `\"feature/foo\"` for \
3502         `:branch`, or a full 40/64 lowercase-hex commit OID for `:rev` — \
3503         drop any `refs/heads/` or `refs/tags/` prefix the caixa-resolver \
3504         prepends at clone time, and avoid abbreviated SHAs which are \
3505         ambiguous across repository history)"
3506    )]
3507    FontePinShape {
3508        nome: String,
3509        pin: String,
3510        value: String,
3511        reason: String,
3512    },
3513    #[error(
3514        ":deps entry {nome:?} :fonte (:tipo path …) has empty :caminho \
3515         (every path source must name a non-empty filesystem path; \
3516         omit the entire :fonte block to fall back to the default-host \
3517         resolver convention)"
3518    )]
3519    FonteCaminhoEmpty { nome: String },
3520    #[error(
3521        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} is \
3522         absolute (the lacre pipeline embeds the value verbatim in its \
3523         per-dep content-address `path:{caminho}` at \
3524         caixa-resolver/src/resolve.rs:189, so an absolute path makes the \
3525         BLAKE3 closure differ across machines — defeating the \
3526         reproducibility contract that's load-bearing for CSE; express \
3527         the path relative to the caixa.lisp location, e.g. \
3528         \"../caixa-teia\" for a sibling workspace dep)"
3529    )]
3530    FonteCaminhoAbsolute { nome: String, caminho: String },
3531    #[error(
3532        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3533         with `~` (the leading-tilde is a shell-expansion convention, not a \
3534         POSIX path component — `Path::is_absolute` returns false on it, so \
3535         the b94fd83 absolute-path gate doesn't catch it, but the lacre \
3536         pipeline embeds the value verbatim in its per-dep content-address \
3537         `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3538         caixa-resolver folds it through `Path::join` without `~`-expansion, \
3539         so the build looks for a literal `./{caminho}` subdirectory and \
3540         fails at resolve time far from the source caixa.lisp; even worse, a \
3541         future caixa-resolver pass that *does* expand `~` would silently \
3542         re-open the host-layout-leak the b94fd83 absolute gate closes — \
3543         Alice's `~` resolves to `/home/alice`, Bob's to `/home/bob`, two CI \
3544         runners with different `$HOME` layouts resolve to two distinct paths \
3545         for the byte-identical caixa, defeating the THEORY.md §V.2 render-\
3546         determinism contract; express the path relative to the caixa.lisp \
3547         location, e.g. \"../caixa-teia\" for a sibling workspace dep, or \
3548         spell out the full relative path explicitly if a workstation-rooted \
3549         dep is genuinely intended)"
3550    )]
3551    FonteCaminhoTildeExpansion { nome: String, caminho: String },
3552    #[error(
3553        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3554         with `$` (the leading-`$` is a shell-variable-expansion convention, \
3555         not a POSIX path component — `Path::is_absolute` returns false on it \
3556         and the a5c248e tilde gate doesn't catch it, but the lacre pipeline \
3557         embeds the value verbatim in its per-dep content-address \
3558         `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3559         caixa-resolver folds it through `Path::join` without `$`-expansion, \
3560         so the build looks for a literal `./{caminho}` subdirectory and \
3561         fails at resolve time far from the source caixa.lisp; even worse, a \
3562         future caixa-resolver pass that *does* expand `$VAR` (the canonical \
3563         shell-convention idiom that CI's `${{WORKSPACE}}` paste-idiom \
3564         invites) would silently re-open the host-layout-leak the b94fd83 \
3565         absolute gate closes — Alice's `$HOME` resolves to `/home/alice`, \
3566         Bob's to `/home/bob`, two CI runners with different `${{WORKSPACE}}` \
3567         layouts resolve to two distinct paths for the byte-identical caixa, \
3568         defeating the THEORY.md §V.2 render-determinism contract; express \
3569         the path relative to the caixa.lisp location, e.g. \"../caixa-teia\" \
3570         for a sibling workspace dep, or spell out the full relative path \
3571         explicitly if a workstation-rooted dep is genuinely intended)"
3572    )]
3573    FonteCaminhoVarExpansion { nome: String, caminho: String },
3574    #[error(
3575        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3576         with a space (the leading ASCII space `0x20` is the orthogonal \
3577         paste-from-aligned-doc footgun that silently passes \
3578         `Path::is_absolute` and every prior leading-byte arm — \
3579         `\" ../caixa-teia\"` resolves via `Path::join` to a literal \
3580         `./ ../caixa-teia` subdirectory the resolver fails to find at \
3581         resolve time with a non-self-locating `No such file or directory` \
3582         error far from the source caixa.lisp; the lacre pipeline embeds \
3583         the value verbatim in its per-dep content-address `path:{caminho}` \
3584         at caixa-resolver/src/resolve.rs:189, so byte-divergent / \
3585         semantic-identical caixa values (` ../caixa-teia` vs \
3586         `../caixa-teia`) yield two distinct BLAKE3 closures across two \
3587         workstations whose authors differ only in paste-from-aligned- \
3588         caixa.lisp-doc whitespace habits — the most insidious failure \
3589         mode the typed slot can carry (no error surfaces; the divergence \
3590         is invisible until two machines compare lacres), defeating the \
3591         THEORY.md §V.2 render-determinism contract. The canonical \
3592         paste-from-aligned-`:deps`-block footgun (every `:fonte` form in \
3593         a multi-entry `:deps` block sits at the same column — an author \
3594         selecting `\"<sp><sp><sp>../caixa-teia\"` and pasting it from \
3595         the rendered alignment into a fresh entry preserves the leading \
3596         whitespace verbatim); peer `:fonte :repo` axis already rejects \
3597         leading whitespace via `is_git_repo_url`, `:fonte :tag` / \
3598         `:fonte :branch` via `is_git_ref_name`, `:descricao` via \
3599         `is_chart_description_shape`, `:licenca` via \
3600         `is_spdx_expression_shape`. Drop the leading space; express the \
3601         path as a bare relative single-token like \"../caixa-teia\")"
3602    )]
3603    FonteCaminhoLeadingWhitespace { nome: String, caminho: String },
3604    #[error(
3605        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3606         with `-` (the canonical CLI-argument-injection footgun on the \
3607         `:caminho` axis — the lacre pipeline embeds the value verbatim in \
3608         its per-dep content-address `path:{caminho}` at \
3609         caixa-resolver/src/resolve.rs:189 and the caixa-resolver folds it \
3610         through `Path::join` looking for a literal `./{caminho}` \
3611         subdirectory. Every downstream subprocess that consumes the resolved \
3612         path — `git -C {caminho} <verb>`, `terraform -chdir={caminho}`, \
3613         `nix build --path {caminho}`, `find {caminho}`, `stat {caminho}`, \
3614         `cp -r {caminho} …`, `rm -rf {caminho}` — reinterprets a leading-`-` \
3615         value as a CLI flag rather than a positional path when the invocation \
3616         does not carry a `--` argument-list terminator between the flag block \
3617         and the path (the common case at every porcelain entry point). The \
3618         canonical footguns: `:caminho \"-rf\"` (bare short-flag paste), \
3619         `:caminho \"-C\"` (`git -C -C` config-injection paste), \
3620         `:caminho \"--upload-pack=cat /etc/passwd\"` (the canonical long-flag \
3621         CLI-arg-injection vector at every git porcelain entry point that \
3622         consumes a path or URL argument, peer with is_git_repo_url's \
3623         leading-`-` arm on the sibling `:fonte :repo` axis), \
3624         `:caminho \"--config=…\"` (`git -c foo=bar` config-override paste). \
3625         POSIX `std::path::Path` treats a leading `-` as a literal filename \
3626         byte so the resolver folds `\"-rf\"` through `Path::join` and looks \
3627         for a literal `./-rf` subdirectory that fails at resolve time with a \
3628         non-self-locating `No such file or directory` error far from the \
3629         source caixa.lisp — but on any downstream shell-out without `--` the \
3630         reinterpretation is silent and the failure mode is arbitrary-\
3631         argument-injection. Peer arms: `is_git_repo_url` (render.rs:2037) \
3632         rejects leading `-` on `:fonte :repo` for `git clone <repo>` CLI-\
3633         arg-injection; `is_git_ref_name` (render.rs:1381, 5a28454) rejects \
3634         leading `-` on `:fonte :tag` / `:branch` for `git checkout <ref>` \
3635         CLI-arg-injection; `is_dns_1123_label` rejects leading `-` on every \
3636         DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros :caixa`, \
3637         `:children :caixa`, `:deps :nome`, cluster names); \
3638         `is_cargo_feature_name` rejects leading `-` on `:caracteristicas`; \
3639         the feira `init` / `add <nome>` positional gate (868c191) rejects \
3640         leading `-` on the CLI positional itself. Express the path as a bare \
3641         relative single-token like \"../caixa-teia\" — the sibling-workspace \
3642         directory name carries no leading-hyphen semantic, and `./` / `../` \
3643         prefixes structurally partition the leading-byte set to safe values.)"
3644    )]
3645    FonteCaminhoLeadingHyphen { nome: String, caminho: String },
3646    #[error(
3647        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains \
3648         ASCII control byte 0x{byte:02x} (POSIX paths reject NUL `0x00` outright — \
3649         every `std::fs` syscall routes the path through `CString::new` which \
3650         fails with `NulError` at resolve time; the lacre pipeline embeds the \
3651         value verbatim in its per-dep content-address `path:{caminho}` at \
3652         caixa-resolver/src/resolve.rs:189 so a control byte anywhere in the \
3653         value lands in the BLAKE3 closure and breaks the THEORY.md §V.2 render-\
3654         determinism contract — the canonical paste-from-multiline-doc \
3655         (`\\n`/`\\r`), paste-from-aligned-table (`\\t`), or paste-from-binary-\
3656         blob (`0x00`-DEL) footgun every peer single-token-shaped axis \
3657         (`:fonte :repo`, `:fonte :tag`/`:branch`, the Helm chart-string axes) \
3658         already gates against. Express the path as a relative single-line ASCII \
3659         string, e.g. \"../caixa-teia\" for a sibling workspace dep)"
3660    )]
3661    FonteCaminhoControlChar {
3662        nome: String,
3663        caminho: String,
3664        byte: u8,
3665    },
3666    #[error(
3667        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains `\\` \
3668         (POSIX `std::path::Path` treats `\\` as a literal byte inside a single path \
3669         component, so `..\\caixa-teia` is one directory named literally `..\\caixa-teia` — \
3670         not the parent's sibling — and the caixa-resolver folds the value through \
3671         `Path::join` looking for a literal `./{caminho}` subdirectory that fails at \
3672         resolve time with a non-self-locating `No such file or directory` error far \
3673         from the source caixa.lisp; Windows `std::path::Path` treats `\\` as a \
3674         primary path separator equal to `/`, so byte-identical caixa.lisp values \
3675         resolve to two distinct directories across runner OSes — the lacre pipeline \
3676         embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3677         caixa-resolver/src/resolve.rs:189, defeating the THEORY.md §V.2 render-\
3678         determinism contract via the cross-host-OS-separator divergence vector. The \
3679         canonical Windows-Explorer `Copy as path` / PowerShell `Get-Location` \
3680         paste-idiom footgun; peer `:fonte :tag` / `:fonte :branch` axis already \
3681         rejects `\\` via `is_git_ref_name` for the same Windows-path-leak reason, \
3682         and `:entrada :paths` rejects `\\` via `is_gateway_api_http_path`'s eleven-\
3683         byte RFC-3986-reserved set. Express the path with `/` as the separator, e.g. \
3684         \"../caixa-teia\" for a sibling workspace dep)"
3685    )]
3686    FonteCaminhoBackslash { nome: String, caminho: String },
3687    #[error(
3688        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3689         redirection metacharacter 0x{byte:02x} `{ch}` (every interactive shell — bash / \
3690         zsh / fish / nushell — lexes `<` and `>` as input / output redirection \
3691         operators, so `:caminho \"../caixa-teia>build.log\"` is the canonical \
3692         paste-from-shell-pipeline footgun where an author copies a `command > log` \
3693         tail without trimming the redirect; POSIX `std::path::Path` treats both bytes \
3694         as literal path-component bytes, so the resolver folds the value through \
3695         `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3696         subdirectory and fails at resolve time with a non-self-locating `No such \
3697         file or directory` error far from the source caixa.lisp. The lacre pipeline \
3698         embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3699         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure \
3700         and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3701         future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3702         canonical CRLF-at-subprocess-argument / shell-metachar injection surface every \
3703         peer single-token-shaped typed slot already closes. The peer `:fonte :tag` / \
3704         `:fonte :branch` axis already rejects `<` / `>` via `is_git_ref_name`, and \
3705         `:entrada :paths` rejects them via `is_gateway_api_http_path`'s eleven-byte \
3706         RFC-3986-reserved set. Express the path as a bare relative single-token like \
3707         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3708         redirection semantic.",
3709        ch = *byte as char
3710    )]
3711    FonteCaminhoShellRedirection {
3712        nome: String,
3713        caminho: String,
3714        byte: u8,
3715    },
3716    #[error(
3717        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-pipe \
3718         metacharacter `|` (every interactive shell — bash / zsh / fish / nushell — lexes \
3719         `|` as the pipe operator that wires one command's stdout to the next command's \
3720         stdin, so `:caminho \"../caixa-teia | grep foo\"` is the canonical paste-from-\
3721         shell-history footgun where an author copies a `ls ../caixa-teia | grep` line \
3722         without trimming the pipeline tail, and `:caminho \"../foo||bar\"` is the \
3723         symmetric `cmd-a || cmd-b` short-circuit-OR paste shape; POSIX `std::path::Path` \
3724         treats `|` as a literal path-component byte, so the resolver folds the value \
3725         through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3726         subdirectory and fails at resolve time with a non-self-locating `No such file or \
3727         directory` error far from the source caixa.lisp. The lacre pipeline embeds the \
3728         value verbatim in its per-dep content-address `path:{caminho}` at caixa-resolver/\
3729         src/resolve.rs:189, so the byte lands in the BLAKE3 closure and rides into every \
3730         shell-spawned subprocess (the resolver's `git clone`, a future `feira tofu` \
3731         shell-out, a future operator-side `nix` spawn) as the canonical CRLF-at-\
3732         subprocess-argument / shell-metachar injection surface every peer single-token-\
3733         shaped typed slot already closes. The peer `:entrada :paths` axis rejects `|` \
3734         via `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3735         path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3736         workspace directory name carries no shell-pipe semantic."
3737    )]
3738    FonteCaminhoShellPipe { nome: String, caminho: String },
3739    #[error(
3740        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3741         command-separator metacharacter `;` (every interactive shell — bash / zsh / fish \
3742         / nushell — lexes `;` as the sequential-command terminator that fires the next \
3743         command regardless of the prior command's exit status, so `:caminho \
3744         \"../caixa-teia; rm -rf build\"` is the canonical paste-from-shell-one-liner \
3745         footgun where an author copies a `cd path; do-thing` chain without trimming \
3746         the cleanup tail, and `:caminho \"../foo;;bar\"` is the symmetric POSIX `case` \
3747         arm `;;` terminator paste shape; POSIX `std::path::Path` treats `;` as a \
3748         literal path-component byte, so the resolver folds the value through \
3749         `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3750         subdirectory and fails at resolve time with a non-self-locating `No such file \
3751         or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3752         the value verbatim in its per-dep content-address `path:{caminho}` at \
3753         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3754         rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3755         future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3756         canonical shell-metachar injection surface every peer single-token-shaped \
3757         typed slot already closes. The peer `:entrada :paths` axis rejects `;` via \
3758         `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3759         path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3760         workspace directory name carries no shell-command-separator semantic."
3761    )]
3762    FonteCaminhoShellSemicolon { nome: String, caminho: String },
3763    #[error(
3764        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3765         background / list-AND metacharacter `&` (every interactive shell — bash / zsh \
3766         / fish / nushell — lexes `&` two ways: single `&` as the background-task \
3767         terminator detaching the prior command and returning control immediately to \
3768         the prompt, double `&&` as the logical-AND list operator firing the next \
3769         command only if the prior succeeded; POSIX `std::path::Path` treats it as a \
3770         literal byte. The canonical paste-from-shell-prompt footgun is a `cd path & \
3771         sleep 1` background-launch one-liner or a `cd path && make install` build-\
3772         chain idiom selected whole into the `:caminho` slot — the prior `;` arm at \
3773         05c358e closed the sequential-command-separator vector, this arm closes the \
3774         orthogonal background-task / logical-AND vector on the same paste-from-shell-\
3775         prompt class. The lacre pipeline embeds the value verbatim in its per-dep \
3776         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3777         byte lands in the BLAKE3 closure and rides into every shell-spawned \
3778         subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3779         future operator-side `nix` spawn) as the canonical shell-metachar injection \
3780         surface every peer single-token-shaped typed slot already closes. The peer \
3781         `:entrada :paths` axis rejects `&` via `is_gateway_api_http_path`'s eleven-\
3782         byte RFC-3986-reserved set. Express the path as a bare relative single-token \
3783         like \"../caixa-teia\" — the sibling-workspace directory name carries no \
3784         shell-background / logical-AND semantic."
3785    )]
3786    FonteCaminhoShellBackground { nome: String, caminho: String },
3787    #[error(
3788        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3789         command-substitution metacharacter `` ` `` (every POSIX shell — sh / bash / zsh / \
3790         dash / ksh / fish / nushell — lexes the byte as the legacy command-substitution \
3791         wrapper that runs the enclosed command and substitutes its standard-output \
3792         verbatim into the surrounding word, so a backticked `whoami` expands to the \
3793         current user's name and a backticked `cat /etc/passwd` expands to the file's \
3794         contents — the canonical CWE-78 shell-command-injection vector; POSIX \
3795         `std::path::Path` treats the byte as a literal path-component byte. The canonical \
3796         paste-from-shell-prompt footgun is a `cd ../path/<backtick>whoami<backtick>` legacy substitution \
3797         one-liner or a `cd <backtick>pwd<backtick>/path` working-directory expansion idiom selected whole \
3798         into the `:caminho` slot — the prior `&` arm at e12e4f3 closed the shell-\
3799         background / logical-AND vector, this arm closes the orthogonal command-\
3800         substitution vector on the same paste-from-shell-prompt class (the modern `$()` \
3801         form is gated at leading position by the f4efe9c `FonteCaminhoVarExpansion` arm; \
3802         the legacy backtick form is the orthogonal axis). The lacre pipeline embeds the \
3803         value verbatim in its per-dep content-address `path:{caminho}` at \
3804         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3805         rides into every shell-spawned subprocess (the resolver's `git clone`, a future \
3806         `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3807         shell-metachar injection surface every peer single-token-shaped typed slot \
3808         already closes. The peer `:entrada :paths` axis rejects the byte via \
3809         `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the path \
3810         as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3811         directory name carries no shell-command-substitution semantic."
3812    )]
3813    FonteCaminhoShellCommandSubstitution { nome: String, caminho: String },
3814    #[error(
3815        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3816         glob / pathname-expansion metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — \
3817         sh / bash / zsh / dash / ksh / fish / nushell — lexes `*` and `?` as pathname-\
3818         expansion wildcards: `*` matches any sequence of characters in a path component \
3819         and `?` matches exactly one character, so a `:caminho \"../caixa-teia/*\"` is the \
3820         canonical paste-from-shell-listing footgun where an author copies a \
3821         `ls ../caixa-teia/*` listing without trimming the wildcard, and `:caminho \
3822         \"../foo?\"` is the symmetric single-char-wildcard paste shape; POSIX \
3823         `std::path::Path` treats both bytes as literal path-component bytes, so the \
3824         resolver folds the value through `Path::new(caminho).join(<file>)` looking for \
3825         a literal `./{caminho}` subdirectory and fails at resolve time with a non-self-\
3826         locating `No such file or directory` error far from the source caixa.lisp. The \
3827         lacre pipeline embeds the value verbatim in its per-dep content-address \
3828         `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the \
3829         BLAKE3 closure and rides into every shell-spawned subprocess (the resolver's \
3830         `git clone`, a future `feira tofu` shell-out, a future operator-side `nix` \
3831         spawn) as the canonical shell-metachar / glob-expansion surface every peer \
3832         single-token-shaped typed slot already closes. The peer `:entrada :paths` axis \
3833         rejects `*` and `?` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-\
3834         reserved set. Express the path as a bare relative single-token like \
3835         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-glob \
3836         / pathname-expansion semantic.",
3837        ch = *byte as char
3838    )]
3839    FonteCaminhoShellGlob {
3840        nome: String,
3841        caminho: String,
3842        byte: u8,
3843    },
3844    #[error(
3845        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3846         subshell-grouping metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / \
3847         zsh / dash / ksh / fish / nushell — lexes `(` and `)` as the subshell-grouping \
3848         operator: `(<cmd>)` runs `<cmd>` in a child shell with a fresh environment scope \
3849         (the canonical `(cd <path> && <cmd>)` shell-history one-liner scopes a `cd` to one \
3850         subshell without disturbing the parent's working directory), and `$(<cmd>)` is the \
3851         modern Bourne command-substitution shape the leading-`$` `FonteCaminhoVarExpansion` \
3852         arm closes the leading byte of — together the two arms now structurally exclude the \
3853         entire `$(<cmd>)` substitution surface from the typed `:caminho` accepted set. \
3854         POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3855         `:caminho \"../caixa-teia/$(date)/build\"` (the canonical paste-from-shell-history \
3856         modern-command-substitution footgun) or `:caminho \"../(cd foo && pwd)/caixa-teia\"` \
3857         (the symmetric subshell-grouping working-directory-probe paste idiom) silently passes \
3858         every prior arm and the resolver folds the value through `Path::new(caminho).join(\
3859         <file>)` looking for a literal subdirectory and fails at resolve time with a non-\
3860         self-locating `No such file or directory` error far from the source caixa.lisp. The \
3861         lacre pipeline embeds the value verbatim in its per-dep content-address `path:\
3862         {caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 \
3863         closure and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3864         future `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3865         shell-metachar / subshell-grouping surface every peer single-token-shaped typed slot \
3866         already closes. The peer `:fonte :repo` axis (3b99147) closes the same byte under the \
3867         same shell-subshell-grouping / RFC-3986-sub-delims banner on `is_git_repo_url`, \
3868         together with the leading-`$` `FonteCaminhoVarExpansion` arm closing the leading byte \
3869         of every `$(<cmd>)` shape. Express the path as a bare relative single-token \
3870         like \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3871         subshell-grouping semantic.",
3872        ch = *byte as char
3873    )]
3874    FonteCaminhoShellSubshellGrouping {
3875        nome: String,
3876        caminho: String,
3877        byte: u8,
3878    },
3879    #[error(
3880        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3881         brace-expansion / URI-Template placeholder metacharacter 0x{byte:02x} `{ch}` \
3882         (every POSIX-derived brace-expanding shell — bash / zsh / ksh / fish — lexes `{{` / \
3883         `}}` as the brace-expansion operator: `{{a,b,c}}` expands to the cross-product of \
3884         comma-separated members and `{{1..10}}` expands to the integer range — the \
3885         canonical `mkdir -p ../{{caixa-teia,caixa-helm,caixa-flux}}` / `cp file{{,.bak}}` \
3886         idiom every shell-history block carries; RFC 6570 reserves the matched pair for \
3887         URI Template placeholders (the canonical `https://{{host}}/{{org}}/{{repo}}` \
3888         substitution shape every OpenAPI / Swagger / Postman / GitHub Octokit client \
3889         library / Helm chart-URL fragment carries) and the Mustache / Handlebars / \
3890         Tera / Jinja2 / Go html/template doubled-brace substitution form every IaC \
3891         templating engine (Helm, Kustomize, Terraform's `${{var}}` cousin) emits. POSIX \
3892         `std::path::Path` treats the byte as a literal path-component byte, so a \
3893         `:caminho \"../{{caixa-teia,caixa-helm}}/build\"` (the canonical paste-from-\
3894         shell-history brace-expansion fan-across-siblings footgun) or `:caminho \"../{{{{org}}}}/\
3895         caixa-teia\"` (the symmetric paste-from-templated-doc URI-Template placeholder \
3896         idiom every README quick-start / OpenAPI spec / Helm chart `home:` field carries) \
3897         silently passes every prior arm and the resolver folds the value through \
3898         `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3899         resolve time with a non-self-locating `No such file or directory` error far from \
3900         the source caixa.lisp. The lacre pipeline embeds the value verbatim in its \
3901         per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
3902         so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
3903         subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3904         future operator-side `nix` spawn) as the canonical shell-metachar / brace-\
3905         expansion / URI-Template-placeholder surface every peer single-token-shaped \
3906         typed slot already closes. The peer `:fonte :repo` axis (42d8f9d) closes the \
3907         same byte pair on `is_git_repo_url` under the same RFC-3986-'delims' / \
3908         RFC-6570-URI-Template / shell-brace-expansion banner. Express the path as a \
3909         bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3910         directory name carries no shell-brace-expansion / URI-Template-placeholder \
3911         semantic; if two siblings actually need pinning, author two separate `:deps` \
3912         entries rather than one brace-expanded `:caminho` value.",
3913        ch = *byte as char
3914    )]
3915    FonteCaminhoShellBraceExpansion {
3916        nome: String,
3917        caminho: String,
3918        byte: u8,
3919    },
3920    #[error(
3921        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3922         bracket-expansion / POSIX glob-character-class / shell-`test`-builtin metacharacter \
3923         0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / nushell \
3924         — lexes the bracket pair as the glob character-class operator: `[abc]` matches one of \
3925         `a` / `b` / `c`, `[a-z]` matches any lowercase ASCII letter, `[^x]` negates — the \
3926         canonical `ls *.[ch]` C-source-file glob and `cd ../caixa-[a-z]*` lowercase-sibling \
3927         glob every shell-history block carries; the bracket pair additionally carries the \
3928         POSIX `test` / `[` builtin command (`[ -d ../caixa-teia ] && cd ...` every shell-\
3929         script conditional uses) and bash's `[[ ... ]]` extended-test grammar; beyond shell \
3930         the pair is the TOML inline-array delimiter (`features = [\"a\", \"b\"]` — the \
3931         canonical paste-from-Cargo-manifest cross-idiom-leak vector), the YAML flow-sequence \
3932         delimiter (`paths: [/a, /b]` — the canonical paste-from-values.yaml cross-idiom \
3933         leak), the JSON array delimiter, and the POSIX-ERE / PCRE bracket-expression anchor. \
3934         POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3935         `:caminho \"../caixa-[a-z]/build\"` (the canonical paste-from-shell-history glob-\
3936         character-class fan-across-siblings footgun) or `:caminho \"../[caixa-teia]/build\"` \
3937         (the symmetric paste-from-TOML-array / paste-from-YAML-flow-sequence cross-idiom \
3938         leak) silently passes every prior arm and the resolver folds the value through \
3939         `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3940         resolve time with a non-self-locating `No such file or directory` error far from \
3941         the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3942         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3943         lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3944         resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3945         `nix` spawn) as the canonical shell-metachar / glob-character-class / TOML-array \
3946         surface every peer single-token-shaped typed slot already closes. Express the path \
3947         as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3948         directory name carries no shell-bracket-expansion / glob-character-class / array-\
3949         literal semantic; if a family of sibling caixas actually needs pinning, author \
3950         separate `:deps` entries rather than one character-class-expanded `:caminho` value.",
3951        ch = *byte as char
3952    )]
3953    FonteCaminhoShellBracketExpansion {
3954        nome: String,
3955        caminho: String,
3956        byte: u8,
3957    },
3958    #[error(
3959        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3960         quote-grouping / cross-config-DSL string-literal-delimiter metacharacter \
3961         0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3962         nushell — lexes `'` as the strong string-literal delimiter (`'…'` — no expansion) \
3963         and `\"` as the weak string-literal delimiter (`\"…\"` — variable- / command-\
3964         substitution-preserving); the canonical `cd '../caixa-teia'` shell-history idiom \
3965         every path-with-embedded-whitespace paste block carries and the symmetric \
3966         `git clone \"$REPO\"` weak-quoted CI-manifest shape both leak the pair verbatim. \
3967         Beyond shell the pair is the JSON string-literal delimiter (`\"key\": \"value\"` — \
3968         the canonical paste-from-JSON-config cross-idiom-leak vector), the YAML double- \
3969         and single-quoted flow-scalar delimiter (`path: \"../caixa-teia\"` — the canonical \
3970         paste-from-values.yaml / paste-from-K8s-YAML-manifest cross-idiom leak), the TOML \
3971         basic and literal string delimiter (`path = \"../caixa-teia\"` — the canonical \
3972         paste-from-Cargo-manifest cross-idiom leak), the tatara-lisp string-literal \
3973         delimiter itself (`(:caminho \"../caixa-teia\")` — the canonical \"I copied the \
3974         entire `:caminho \"...\"` slot rather than just the string body\" author-surface \
3975         footgun), and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which excludes \
3976         both bytes from the `pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"` \
3977         production. POSIX `std::path::Path` treats the byte as a literal path-component \
3978         byte, so a `:caminho \"'../caixa-teia'\"` (the canonical paste-from-shell-history \
3979         strong-quoted sibling-workspace path footgun) or `:caminho \"\\\"../caixa-teia\\\"\"` \
3980         (the symmetric weak-quoted paste-from-JSON / paste-from-YAML flow-scalar / paste-\
3981         from-TOML basic-string / paste-from-tatara-lisp string-literal cross-idiom-leak \
3982         shape) silently passes every prior arm and the resolver folds the value through \
3983         `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3984         resolve time with a non-self-locating `No such file or directory` error far from \
3985         the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3986         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3987         lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3988         resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3989         `nix` spawn) as the canonical shell-metachar / string-literal-delimiter surface \
3990         every peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
3991         axis closes both bytes under the same shell-quote-grouping / RFC-3986-sub-delims \
3992         banner (e7a109f `'` shell-single-quote + 4267d8b `\"` shell-double-quote on \
3993         `is_git_repo_url`). Express the path as a bare relative single-token like \
3994         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-quote-\
3995         grouping / string-literal-delimiter semantic; strip the outer quote pair from the \
3996         paste (the tatara-lisp `:caminho \"...\"` slot already carries the string-literal \
3997         quoting on the outer syntactic layer, so an inner quote pair would nest and \
3998         desugar to a broken layer).",
3999        ch = *byte as char
4000    )]
4001    FonteCaminhoShellQuoteGrouping {
4002        nome: String,
4003        caminho: String,
4004        byte: u8,
4005    },
4006    #[error(
4007        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4008         comment / URL-fragment-identifier / YAML-comment cross-config-DSL metacharacter \
4009         0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
4010         nushell — lexes an unquoted `#` at the head of a word or after unquoted \
4011         whitespace as the comment-lead per POSIX.1-2017 §2.3 Token Recognition step 6, \
4012         discarding the byte and everything after it to the end of the physical line \
4013         before command parsing (`cd ../caixa-teia  # legacy sibling` — the canonical \
4014         paste-from-shell-history-with-trailing-annotation shape every operator-notebook \
4015         and CI-manifest carries); YAML 1.2 §6.6 makes `#` the comment-lead at any \
4016         position preceded by whitespace or at line-start (`path: ../caixa-teia  # pin` \
4017         — the canonical paste-from-values.yaml / paste-from-K8s-manifest cross-idiom-\
4018         leak); RFC 3986 §3.5 reserves `#` as the URL fragment-identifier delimiter (the \
4019         canonical paste-from-browser-address-bar `github.com/foo/bar#readme` / \
4020         `github.com/foo/bar#L42` permalink shape, and the symmetric Nix-flake-ref \
4021         cross-idiom leak `github:foo/bar#packageName` where `#` selects a flake \
4022         output); the same cross-config-DSL surface extends to HCL / Terraform / Nix \
4023         flake attributes / dotenv `.env` / gitconfig / .gitignore / ini / TOML where \
4024         `#` is likewise the comment-lead. POSIX `std::path::Path` treats the byte as a \
4025         literal path-component byte, so a `:caminho \"../caixa-teia # legacy sibling\"` \
4026         (the canonical paste-from-shell-history-with-trailing-annotation footgun), \
4027         `:caminho \"../caixa-teia  # pin\"` (the symmetric YAML flow-scalar paste-with-\
4028         trailing-comment shape), or `:caminho \"../caixa-teia#readme\"` (the URL \
4029         fragment paste-from-browser-address-bar shape) silently passes every prior arm \
4030         and the resolver folds the value through `Path::new(caminho).join(<file>)` \
4031         looking for a literal subdirectory named `../caixa-teia # legacy sibling` and \
4032         fails at resolve time with a non-self-locating `No such file or directory` \
4033         error far from the source caixa.lisp — while every downstream shell / YAML / \
4034         URL parser silently truncates the value at the `#` byte to `../caixa-teia`, so \
4035         a `feira tofu` shell-out and a `nix flake check` on an emitted YAML `path:` \
4036         scalar disagree with the resolver on which directory the value names. The \
4037         lacre pipeline embeds the value verbatim in its per-dep content-address \
4038         `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in \
4039         the BLAKE3 closure and rides into every shell-spawned subprocess (the \
4040         resolver's `git clone`, a future `feira tofu` shell-out, a future operator-\
4041         side `nix` spawn) as the canonical shell-metachar / comment-lead / URL-\
4042         fragment-delimiter surface every peer single-token-shaped typed slot already \
4043         closes. The peer `:fonte :repo` axis closes the byte under the same URL-\
4044         fragment-identifier banner (a68f818 `#` on `is_git_repo_url`). Express the \
4045         path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
4046         workspace directory name carries no shell-comment / URL-fragment / YAML-\
4047         comment semantic; move any trailing annotation to a tatara-lisp `;`-comment \
4048         on the surrounding form (`;; legacy sibling` above the `(:caminho ...)` slot) \
4049         and drop any `#fragment` tail entirely (fragment identifiers select \
4050         renderings, not directories, and `:caminho` names a directory).",
4051        ch = *byte as char
4052    )]
4053    FonteCaminhoShellComment {
4054        nome: String,
4055        caminho: String,
4056        byte: u8,
4057    },
4058    #[error(
4059        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains URL-\
4060         percent-encoding-escape / printf-format-specifier / bash-job-control-specifier \
4061         / YAML-directive-lead metacharacter 0x{byte:02x} `{ch}` (RFC 3986 §2.1 reserves \
4062         `%` as the URL percent-encoding-escape — `%HH` is the mandatory encoding \
4063         mechanism for every byte outside the `unreserved` alphanumeric / `-` / `.` / \
4064         `_` / `~` set, and `%` itself must be percent-encoded as `%25` to appear \
4065         literally inside a URL value. The canonical paste-from-browser-address-bar \
4066         percent-encoded-space footgun (an author copies `../caixa%20teia` out of a URL-\
4067         encoded README hyperlink / browser address bar / percent-encoded permalink \
4068         expecting `%20` to decode to a literal space at the filesystem layer) locks two \
4069         distinct BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`) for \
4070         what the author intended as the byte-identical sibling-workspace dep. POSIX \
4071         `std::path::Path` treats the byte as a literal path-component byte, so \
4072         `Path::join` looks for a literal `./{caminho}` subdirectory and fails at \
4073         resolve time with a non-self-locating `No such file or directory` error far \
4074         from the source caixa.lisp — while every downstream URL parser / shell printf \
4075         builtin / YAML directive parser silently reinterprets the byte to a different \
4076         value than the resolver's `Path::join` sees. Beyond the URL-encoding hazard, \
4077         `%` is the C / POSIX printf format-directive lead-in (`%s`, `%d`, `%02x` — \
4078         wired into every POSIX shell's `printf` builtin, the canonical CWE-134 format-\
4079         string-injection vector); the bash / zsh / ksh job-control-specifier lead-in \
4080         (`%1` names \"job 1\", `%%` names \"the current job\", `%foo` names \"the most \
4081         recent job whose command started with `foo`\" — a future `kill %1` invocation \
4082         silently redirects the signal to a wrong target); the YAML 1.2 §6.8.1 \
4083         directive lead-in (`%YAML 1.2` / `%TAG` — the paste-from-top-of-doc YAML \
4084         directive block cross-idiom leak); and the Windows-shell env-var-reference \
4085         lead-in (`%PATH%` — the paste-from-`.bat` / paste-from-PowerShell-`%env:PATH%` \
4086         cross-idiom leak). The lacre pipeline embeds the value verbatim in its per-dep \
4087         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
4088         byte lands in the BLAKE3 closure and rides into every shell-spawned subprocess \
4089         (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4090         operator-side `nix` spawn) as the canonical URL-percent-encoding-escape / \
4091         printf-format-specifier / job-control-specifier surface every peer single-\
4092         token-shaped typed slot already closes. The peer `:fonte :repo` axis closes \
4093         the byte under the same URL-percent-encoding-escape banner (a323db8 `%` on \
4094         `is_git_repo_url`). Express the path as a bare relative single-token like \
4095         \"../caixa-teia\" — the sibling-workspace directory name carries no URL-\
4096         percent-encoding-escape / format-specifier / job-control semantic; substitute \
4097         any `%20` percent-encoded-space with a literal space then reject the whole \
4098         value at the leading-whitespace / embedded-`?` arm on the same axis (a caixa \
4099         directory name never carries an embedded space in practice); drop any \
4100         `%2F`-encoded path separator in favor of a literal `/`; and drop any leading \
4101         `%YAML` / `%PATH%` cross-idiom-leak prefix entirely.",
4102        ch = *byte as char
4103    )]
4104    FonteCaminhoUrlPercentEncoding {
4105        nome: String,
4106        caminho: String,
4107        byte: u8,
4108    },
4109    #[error(
4110        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4111         variable-expansion / command-substitution / arithmetic-expansion / cross-config-\
4112         DSL-interpolation metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / \
4113         bash / zsh / dash / ksh / busybox ash / fish / nushell — lexes `$` per \
4114         POSIX.1-2017 §2.6 as the variable-expansion `$<name>` / braced-form `${{<name>}}` \
4115         / command-substitution `$(<cmd>)` / arithmetic-expansion `$((<expr>))` operator; \
4116         Nix uses `${{var}}` as the string-interpolation lead, Make uses `$(var)` / `$@` \
4117         / `$<` for variables and automatic-variables, JavaScript / TypeScript template \
4118         literals use `${{expr}}` for interpolation, envsubst / Kubernetes / OpenShift \
4119         templates use `${{VAR}}` for env-var-reference, PHP uses `$_GET` / `$_ENV` for \
4120         superglobals, Perl uses `$foo` for scalars, SASS / SCSS uses `$primary-color` \
4121         for variables, and PostgreSQL / SQLite use `$1` / `$2` for bind parameters — \
4122         the byte is a first-class parser byte in nearly every config / templating / \
4123         build-system DSL the substrate's paste-idiom surface routinely crosses. POSIX \
4124         `std::path::Path` treats the byte as a literal path-component byte, so the \
4125         canonical paste-from-shell-one-liner `:caminho \"../foo$HOME/bar\"` / paste-\
4126         from-CI-manifest `:caminho \"../foo${{WORKSPACE}}/bar\"` / paste-from-shell-\
4127         prompt `:caminho \"../foo$(whoami)/bar\"` footguns silently pass every prior \
4128         cascade arm (`$` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / \
4129         `?` / `(` / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%`) and route \
4130         through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4131         subdirectory that fails at resolve time with a non-self-locating `No such file \
4132         or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4133         the value verbatim in its per-dep content-address `path:{caminho}` at \
4134         caixa-resolver/src/resolve.rs:189, so byte-identical caixa.lisp values differing \
4135         only in whether the author substituted `$HOME` / `${{WORKSPACE}}` at author \
4136         time lock to two distinct BLAKE3 closures across two workstations whose \
4137         downstream envsubst / Nix / Make / K8s-template layers differ in `$VAR` \
4138         recognition — defeating the THEORY.md §V.2 render-determinism contract on the \
4139         same axis every prior `:caminho` arm protects. Beyond the determinism vector, \
4140         `$` at any position in a value flowing verbatim into a shell-spawned subprocess \
4141         is the canonical CWE-78 shell-command-injection surface every peer single-\
4142         token-shaped typed slot already closes: peer `:fonte :repo` axis rejects `$` \
4143         under the shell-variable-expansion / URL-sub-delim banner via `is_git_repo_url` \
4144         (b9d187c), peer `:fonte :tag` / `:fonte :branch` axes reject `$` as part of \
4145         `is_git_ref_name`'s printable-ASCII-restricted grammar (`git check-ref-format` \
4146         rejects the byte outright), and peer `:entrada :paths` axis rejects `$` via \
4147         `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. The leading-`$` \
4148         position on the same axis routes through `FonteCaminhoVarExpansion` at the \
4149         f4efe9c leading-byte arm; this arm closes the last positional gap on the byte \
4150         so every position — leading and embedded — is structurally rejected. Substitute \
4151         the `$VAR` / `${{VAR}}` / `$(cmd)` template with the literal value at author \
4152         time, or express the path as a bare relative single-token like \
4153         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
4154         variable-expansion / command-substitution / arithmetic-expansion semantic.",
4155        ch = *byte as char
4156    )]
4157    FonteCaminhoShellVariableExpansion {
4158        nome: String,
4159        caminho: String,
4160        byte: u8,
4161    },
4162    #[error(
4163        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4164         history-expansion / RFC-3986-sub-delims / bang-operator metacharacter 0x{byte:02x} \
4165         `{ch}` (every interactive POSIX shell with history enabled — bash / ksh / zsh's \
4166         `bashcompat` / csh / tcsh — lexes `!` as the history-expansion prefix per bash \
4167         reference §9.3: `!command` re-runs the most recent history entry beginning with \
4168         `command`, `!!` re-runs the prior command verbatim, `!$` substitutes the last \
4169         word of the prior command, `!:N` substitutes the Nth word of the prior command, \
4170         and the substitution fires at every history-expansion-enabled shell context — \
4171         `set -o histexpand` is bash's default for interactive sessions and the layer \
4172         every `feira tofu` / `git clone` / `nix flake check` subprocess-argument \
4173         invocation crosses when spawned under `bash -i`. Beyond shell history, RFC 3986 \
4174         §2.2 lists `!` in the `sub-delims` set (the URL grammar admits the byte inside \
4175         a path segment, but every WHATWG-conformant special-scheme URL parser percent-\
4176         encodes it inside a query component via the 'special-query percent-encode set' \
4177         the peer `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte is \
4178         also the C / C++ / Rust / JavaScript / Python bang-operator (logical-negation \
4179         prefix — the paste-from-source-code idiom where an author copies \
4180         `!path.exists()` out of a Rust snippet and the trailing punctuation crosses \
4181         the string-literal boundary); the canonical English-typography emphasis / \
4182         exclamation mark (the paste-from-prose enthusiasm-form idiom where an author \
4183         writes `:caminho \"../caixa-teia!\"` expecting the substrate to coerce it to a \
4184         kebab-case slug); and the Nix flake-ref attribute-selection operator surface. \
4185         POSIX `std::path::Path` treats `!` as a literal path-component byte, so the \
4186         canonical paste-from-shell-history footgun `:caminho \"../caixa-teia!sudo\"` \
4187         (an author copies a `cd ../caixa-teia && !sudo make install` one-liner from a \
4188         quick-start README and the trailing `!sudo` rides in verbatim as a history-\
4189         expansion reference), the symmetric `:caminho \"../foo!!/bar\"` (the `!!` \
4190         repeat-prior-command paste idiom), the English-typography `:caminho \
4191         \"../caixa-teia!\"` (paste-from-prose enthusiasm-form), and the last-word-\
4192         substitution `:caminho \"../foo!$\"` shape silently pass every prior cascade \
4193         arm (`!` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` \
4194         / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$`) and route \
4195         through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4196         subdirectory that fails at resolve time with a non-self-locating `No such file \
4197         or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4198         the value verbatim in its per-dep content-address `path:{caminho}` at \
4199         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
4200         rides into every shell-spawned subprocess (the resolver's `git clone`, a \
4201         future `feira tofu` shell-out, a future operator-side `nix flake check` spawn) \
4202         as the canonical shell-history-expansion / RFC-3986-sub-delims surface every \
4203         peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4204         axis closes the byte under the same shell-history-expansion / RFC-3986-sub-\
4205         delims banner (7d53c68 `!` on `is_git_repo_url`). Express the path as a bare \
4206         relative single-token like \"../caixa-teia\" — the sibling-workspace directory \
4207         name carries no shell-history-expansion / bang-operator semantic; drop any \
4208         `!sudo` / `!!` / `!$` history-expansion trailing paste-from-shell-history \
4209         idiom; and drop any trailing English-typography exclamation mark that pasted \
4210         from prose.",
4211        ch = *byte as char
4212    )]
4213    FonteCaminhoShellHistoryExpansion {
4214        nome: String,
4215        caminho: String,
4216        byte: u8,
4217    },
4218    #[error(
4219        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4220         history-substitution / RFC-3986-'unwise' / regex-negation metacharacter 0x{byte:02x} \
4221         `{ch}` (POSIX bash's `set -o histexpand` mode — the default for every interactive \
4222         session and every `bash -i` subprocess-argument context `feira tofu` / `git clone` / \
4223         `nix flake check` cross — lexes `^old^new^` per bash reference §9.3 as the 'quick \
4224         substitution' history operator that rewrites the prior command's `old` string to \
4225         `new` and re-executes it verbatim, the canonical typo-correction one-liner idiom \
4226         (`git clone <bad-url>` → `^bad^good` typo-fix-and-rerun the paste-from-shell-\
4227         history author trims only the leading `git clone` prefix from). RFC 3986 §2 lists \
4228         `^` in the 'unwise' set every URL parser is required to percent-encode-or-refuse at \
4229         the wire boundary, and the WHATWG URL spec's 'fragment percent-encode set' maps \
4230         `^` → `%5E` at the query / fragment component transition, so `Path::join` on the \
4231         literal value diverges from every downstream `feira tofu` curl-invocation / \
4232         artifact-registry-fetch that percent-encodes the byte before the wire. `^` is also \
4233         the regex character-class negation prefix (`[^abc]`), the bitwise XOR operator in \
4234         C / C++ / Rust / Python / JavaScript / Nix / Go, the Windows `cmd.exe` escape \
4235         metacharacter, and the LaTeX / Markdown / BibTeX superscript operator. POSIX \
4236         `std::path::Path` treats `^` as a literal path-component byte, so \
4237         `:caminho \"../foo^bar/baz\"` (embedded quick-substitution), `:caminho \
4238         \"../foo^\"` (trailing history-substitution-open shape), or `:caminho \"../x^y\"` \
4239         (XOR-expression paste-from-source) silently pass every prior cascade arm (`^` \
4240         isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` / `)` / `{{` \
4241         / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$` / `!`) and route through \
4242         `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` subdirectory \
4243         that fails at resolve time with a non-self-locating `No such file or directory` \
4244         error far from the source caixa.lisp. The lacre pipeline embeds the value verbatim \
4245         in its per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
4246         so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
4247         subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4248         operator-side `nix flake check` spawn) as the canonical shell-history-substitution \
4249         / RFC-3986-unwise surface every peer single-token-shaped typed slot already closes. \
4250         The peer `:fonte :repo` axis closes the byte under the same shell-history-\
4251         substitution / RFC-3986-unwise banner (49e142f `^` on `is_git_repo_url`). Together \
4252         with the immediate-predecessor `!` arm (6a04767) this arm closes the full `set -o \
4253         histexpand` operator surface on the `:caminho` axis — the `!command` / `!!` / `!$` \
4254         prefix form via `!`, the `^old^new^` quick-substitution form via `^`. Express the \
4255         path as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
4256         directory name carries no shell-history-substitution / regex-negation / XOR-operator \
4257         semantic; drop any `^old^new` history-substitution paste-from-shell-history idiom; \
4258         drop any trailing `^` history-substitution-open fragment.",
4259        ch = *byte as char
4260    )]
4261    FonteCaminhoShellHistorySubstitution {
4262        nome: String,
4263        caminho: String,
4264        byte: u8,
4265    },
4266    #[error(
4267        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} has a trailing \
4268         `/` (the resolver's `Path::join` resolves `\"../caixa-teia\"` and \
4269         `\"../caixa-teia/\"` to the same directory, but the lacre pipeline embeds the \
4270         value verbatim in its per-dep content-address `path:{caminho}` at \
4271         caixa-resolver/src/resolve.rs:189, so two authors whose only difference is \
4272         shell tab-completion emit byte-divergent BLAKE3 closures for the same caixa — \
4273         defeating the THEORY.md §V.2 render-determinism contract via the trailing-\
4274         separator vector (the canonical paste-from-shell-tab-completion + paste-from-\
4275         `pwd`-with-`/`-suffix footgun, and the canonical Cargo-style `path = \
4276         \"../caixa-teia/\"` paste-from-Cargo-manifest cross-idiom leak). Drop the \
4277         trailing `/`; every `:caminho` value names a sibling-workspace directory \
4278         already, so the trailing separator carries no information. Use \
4279         `\"../caixa-teia\"` rather than `\"../caixa-teia/\"`)"
4280    )]
4281    FonteCaminhoTrailingSlash { nome: String, caminho: String },
4282    #[error(
4283        "{list} carries duplicate entry :nome {nome:?} — every dep list keys its \
4284         entries by caixa name (Cargo's [dependencies] / [dev-dependencies] tables \
4285         apply the same set-not-multiset discipline; one package per table), and \
4286         two entries naming the same caixa carry two version constraints / source \
4287         pins / feature sets for one identity. The caixa-resolver's lacre pipeline \
4288         consumes the list as a `HashMap`-keyed-by-`:nome` lookup: the second entry \
4289         silently overwrites the first at the resolver-side `concrete_versao` step, \
4290         and the dropped entry's pin / features never reach the closure — far from \
4291         the source caixa.lisp, with no field naming which `:deps` entry was the \
4292         silent loser. If two version constraints are genuinely needed (the rare \
4293         multi-version closure case the lacre pipeline doesn't yet support), the \
4294         author surface is two distinct caixa names (e.g. a `caixa-teia-v01` / \
4295         `caixa-teia-v02` aliased pair); within one list, one entry per caixa name."
4296    )]
4297    DuplicateNome { nome: String, list: &'static str },
4298    #[error(
4299        ":deps entry {nome:?} has empty :caracteristicas entry — every feature flag must \
4300         name a non-empty identifier on the target caixa (Cargo's [dependencies.<dep>.features] \
4301         applies the same per-entry non-empty discipline). An empty feature flag reaches the \
4302         caixa-resolver's lacre pipeline as a no-op feature enable, silently dropping the \
4303         author's intent far from the source caixa.lisp; drop the empty entry, or replace it \
4304         with the canonical kebab-case feature name the target caixa declares."
4305    )]
4306    CaracteristicaEmpty { nome: String },
4307    #[error(
4308        ":deps entry {nome:?} :caracteristicas entry {caracteristica:?} is not a valid Cargo \
4309         feature name: {reason} (the value flows verbatim into Cargo's \
4310         [dependencies.<dep>.features] list and Cargo's `restricted_names::validate_feature_name` \
4311         parser enforces the same shape at `cargo metadata` time; use a single-token \
4312         identifier like `\"http\"`, `\"derive\"`, or `\"runtime-tokio\"` — kebab-case ASCII \
4313         alphanumeric with `-`, `_`, `+`, or `.` as continuation characters, starting with \
4314         an ASCII alphanumeric or `_`)"
4315    )]
4316    CaracteristicaInvalid {
4317        nome: String,
4318        caracteristica: String,
4319        reason: String,
4320    },
4321    #[error(
4322        ":deps entry {nome:?} :caracteristicas carries duplicate feature {caracteristica:?} — \
4323         every feature-flag list keys its entries by name (Cargo's \
4324         [dependencies.<dep>.features] applies the same set-not-multiset discipline; one entry \
4325         per feature per dep), and two entries naming the same feature are a redundant \
4326         set-membership declaration for one identity (the feature-toggle slot is set-shaped; \
4327         enabling a feature twice has no additional semantic). The caixa-resolver's lacre \
4328         pipeline consumes the list as a set-shaped feature toggle — the resolver enables the \
4329         feature once regardless of declaration count, so the duplicate's pin / position never \
4330         reaches the closure with no field naming the silent loser. One entry per feature per \
4331         dep; if two distinct features are intended, name each verbatim."
4332    )]
4333    CaracteristicaDuplicate {
4334        nome: String,
4335        caracteristica: String,
4336    },
4337    #[error(
4338        "{list} entry :nome {nome:?} names the caixa itself — a caixa cannot depend \
4339         on itself (the lacre closure's dep-graph traversal is rooted at the caixa's \
4340         :nome, and a self-dep would be a one-node cycle the caixa-resolver either \
4341         rejects mid-traversal far from the source caixa.lisp or recurses on until \
4342         it exhausts its stack). Every :nome is globally-unique substrate identity, \
4343         so a :deps / :deps-dev entry whose :nome equals the parent caixa's :nome \
4344         *is* the parent itself, not a coincidentally-named peer. Drop the \
4345         self-referential dep entry — to reference code from this caixa, use \
4346         :bibliotecas / :exe / :servicos (the substrate-blessed shape for \
4347         referencing the caixa's own code surface) instead."
4348    )]
4349    DepIsSelf { nome: String, list: &'static str },
4350}
4351
4352#[allow(clippy::trivially_copy_pass_by_ref)]
4353fn is_false(b: &bool) -> bool {
4354    !*b
4355}
4356
4357#[cfg(test)]
4358mod tests {
4359    use super::*;
4360
4361    #[test]
4362    fn registry_dep_is_minimal() {
4363        let d = Dep::simple("caixa-teia", "^0.1");
4364        assert_eq!(d.nome, "caixa-teia");
4365        assert_eq!(d.versao, "^0.1");
4366        assert!(d.fonte.is_none());
4367        assert!(!d.opcional());
4368        assert!(d.caracteristicas().is_empty());
4369    }
4370
4371    #[test]
4372    fn dep_string_scalar_accessor_pair_is_const_fn() {
4373        // Fail-before-pass-after pin on [`Dep::nome`] +
4374        // [`Dep::versao_requirement`]'s `const`-eval-surface posture.
4375        // Each accessor projects the per-`:deps` / per-`:deps-dev`
4376        // entry's [`String`] storage through the `pub const fn`
4377        // [`String::as_str`] (const-stable since Rust 1.87, well
4378        // within the workspace MSRV) — any future accidental
4379        // downgrade to non-`const` fails the corresponding
4380        // `<name>_via_const_fn` wrapper at caixa-core build time with
4381        // E0015 (`cannot call non-const method`), strictly stronger
4382        // than a runtime `assert!`. Sibling of the peer
4383        // per-M2/M3/universal-axis `String → &str` scalar-accessor
4384        // family pins on the sibling `const`-eval-surface passes
4385        // ([`crate::Caixa::nome`] / [`crate::Caixa::versao`] at the
4386        // top-level manifest, [`crate::CaixaVersion::as_str`] at the
4387        // typed-newtype wrapper, [`crate::aplicacao::Membro::nome`] /
4388        // [`crate::aplicacao::Membro::versao_requirement`] at the M3
4389        // membership axis, [`crate::aplicacao::Entrada::hostname`] /
4390        // [`crate::aplicacao::Entrada::destination`] at the M3
4391        // ingress axis, [`crate::supervisor::ChildSpec::nome`] /
4392        // [`crate::supervisor::ChildSpec::versao_requirement`] at the
4393        // M2 supervisor-tree axis,
4394        // [`crate::upgrade::UpgradeFromEntry::prior_versao`] at the
4395        // M2 upgrade axis, and the per-`:contratos`
4396        // [`crate::aplicacao::WitContract::source`] /
4397        // [`crate::aplicacao::WitContract::destination`] /
4398        // [`crate::aplicacao::WitContract::world_ref`] trio the
4399        // sibling pin at 279823b already anchors).
4400        const fn nome_via_const_fn(d: &Dep) -> &str {
4401            d.nome()
4402        }
4403        const fn versao_via_const_fn(d: &Dep) -> &str {
4404            d.versao_requirement()
4405        }
4406        for (nome, versao) in [
4407            ("caixa-teia", "^0.1"),
4408            ("caixa-mesh", "~0.2.3"),
4409            ("caixa-helm", "*"),
4410        ] {
4411            let d = Dep::simple(nome, versao);
4412            assert_eq!(nome_via_const_fn(&d), d.nome());
4413            assert_eq!(versao_via_const_fn(&d), d.versao_requirement());
4414            assert_eq!(d.nome(), nome);
4415            assert_eq!(d.versao_requirement(), versao);
4416        }
4417    }
4418
4419    #[test]
4420    fn git_dep_carries_tag() {
4421        let d = Dep::git("t", "*", "github:o/r", "v1");
4422        match d.fonte {
4423            Some(DepSource::Git {
4424                ref repo, ref tag, ..
4425            }) => {
4426                assert_eq!(repo, "github:o/r");
4427                assert_eq!(tag.as_deref(), Some("v1"));
4428            }
4429            _ => panic!("expected Git source"),
4430        }
4431    }
4432
4433    #[test]
4434    fn validate_accepts_simple_dep() {
4435        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
4436    }
4437
4438    #[test]
4439    fn validate_rejects_empty_nome() {
4440        // The fail-before-pass-after pin for `:nome ""`: the empty-name
4441        // arm fires first so the per-entry parse-side diagnostic doesn't
4442        // emit a useless `nome: ""` reference.
4443        let mut d = Dep::simple("placeholder", "^0.1");
4444        d.nome = String::new();
4445        assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4446    }
4447
4448    #[test]
4449    fn validate_rejects_empty_versao() {
4450        // `parse_requirement("")` returns `Ok(VersionReq::STAR)` (the
4451        // semver crate accepts the empty string as a wildcard match),
4452        // so the empty-`:versao` arm is structurally necessary even
4453        // with the parse arm in place — mirrors `MembroVersaoEmpty` /
4454        // `EmptyChildVersion` ordering on the other two `:versao` axes.
4455        let mut d = Dep::simple("caixa-teia", "ignored");
4456        d.versao = String::new();
4457        let err = d.validate().unwrap_err();
4458        assert!(
4459            matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4460            "got {err:?}"
4461        );
4462    }
4463
4464    // ── value-shape: DNS-1123 label on :deps :nome ────────────────────────
4465
4466    #[test]
4467    fn validate_rejects_nome_with_uppercase() {
4468        // The fail-before-pass-after pin: a non-empty but uppercase
4469        // `:nome` silently passed `validate()` on every pre-gate
4470        // codebase because the prior shape only refused the empty
4471        // string. The DNS-1123 violation surfaced far downstream at
4472        // lacre-resolve time when the *target* caixa's `:nome` failed
4473        // its own gate — far from the `:deps` entry, with a diagnostic
4474        // naming the target rather than the dep entry that referenced
4475        // it. Same fail-before-pass-after fixture pinned for
4476        // `:membros :caixa` (3f9d7a0), `:children :caixa` (31bfa43),
4477        // and Caixa `:nome` (6c992f8).
4478        let d = Dep::simple("Caixa-Teia", "^0.1");
4479        let err = d.validate().unwrap_err();
4480        assert!(
4481            matches!(
4482                err,
4483                DepError::NomeInvalid { ref nome, ref reason }
4484                    if nome == "Caixa-Teia" && reason.contains("uppercase")
4485            ),
4486            "got {err:?}"
4487        );
4488    }
4489
4490    #[test]
4491    fn validate_rejects_nome_with_underscore() {
4492        // RFC 1123 allows `[a-z0-9-]` only; underscore is the canonical
4493        // "I'm thinking of Go module names / Python identifiers" leak.
4494        // Same fixture pinned for the peer caixa-identifier axes.
4495        let d = Dep::simple("caixa_teia", "^0.1");
4496        let err = d.validate().unwrap_err();
4497        assert!(
4498            matches!(
4499                err,
4500                DepError::NomeInvalid { ref nome, ref reason }
4501                    if nome == "caixa_teia" && reason.contains('_')
4502            ),
4503            "got {err:?}"
4504        );
4505    }
4506
4507    #[test]
4508    fn validate_rejects_nome_with_dot() {
4509        // A `:deps :nome` is a single DNS-1123 *label*, not a
4510        // subdomain — dots are rejected. The `"caixa.teia"` shape is
4511        // the canonical "I confused the dep name with the FQDN /
4512        // namespace" footgun, distinct from the legitimate
4513        // `:fonte :repo "github:org/caixa-teia"` axis.
4514        let d = Dep::simple("caixa.teia", "^0.1");
4515        let err = d.validate().unwrap_err();
4516        assert!(
4517            matches!(
4518                err,
4519                DepError::NomeInvalid { ref nome, ref reason }
4520                    if nome == "caixa.teia" && reason.contains('.')
4521            ),
4522            "got {err:?}"
4523        );
4524    }
4525
4526    #[test]
4527    fn validate_rejects_nome_with_leading_hyphen() {
4528        // RFC 1123 requires alphanumeric at both label boundaries.
4529        // Pinned in parity with the peer DNS-1123 fixtures.
4530        let d = Dep::simple("-caixa-teia", "^0.1");
4531        let err = d.validate().unwrap_err();
4532        assert!(
4533            matches!(
4534                err,
4535                DepError::NomeInvalid { ref nome, ref reason }
4536                    if nome == "-caixa-teia" && reason.contains("alphanumeric")
4537            ),
4538            "got {err:?}"
4539        );
4540    }
4541
4542    #[test]
4543    fn validate_rejects_nome_with_trailing_hyphen() {
4544        let d = Dep::simple("caixa-teia-", "^0.1");
4545        let err = d.validate().unwrap_err();
4546        assert!(
4547            matches!(
4548                err,
4549                DepError::NomeInvalid { ref nome, ref reason }
4550                    if nome == "caixa-teia-" && reason.contains("alphanumeric")
4551            ),
4552            "got {err:?}"
4553        );
4554    }
4555
4556    #[test]
4557    fn validate_rejects_nome_with_slash() {
4558        // The canonical "I copied the GitHub repo path into `:nome`
4559        // instead of `:fonte :repo`" typo. A `/` in the name leaks the
4560        // lacre-side `:repositorio` shape (`pleme-io/caixa-teia`) into
4561        // the local-name slot. Same fixture pinned for `:membros
4562        // :caixa` (3f9d7a0).
4563        let d = Dep::simple("pleme-io/caixa-teia", "^0.1");
4564        let err = d.validate().unwrap_err();
4565        assert!(
4566            matches!(
4567                err,
4568                DepError::NomeInvalid { ref nome, ref reason }
4569                    if nome == "pleme-io/caixa-teia" && reason.contains('/')
4570            ),
4571            "got {err:?}"
4572        );
4573    }
4574
4575    #[test]
4576    fn validate_rejects_nome_too_long() {
4577        // 64-byte label — one over the RFC 1035 / RFC 1123 label cap.
4578        // Built from a valid character set so the length-bound
4579        // diagnostic surfaces before any per-character check (the
4580        // order pin parallel to the per-character predicates inside
4581        // [`crate::render::is_dns_1123_label`]).
4582        let long = "a".repeat(64);
4583        let d = Dep::simple(&long, "^0.1");
4584        let err = d.validate().unwrap_err();
4585        assert!(
4586            matches!(
4587                err,
4588                DepError::NomeInvalid { ref nome, ref reason }
4589                    if nome.len() == 64 && reason.contains("max length of 63")
4590            ),
4591            "got {err:?}"
4592        );
4593    }
4594
4595    #[test]
4596    fn validate_accepts_canonical_nome_labels() {
4597        // Positive-control sweep — every form the K8s apiserver
4598        // accepts as a DNS-1123 label must round-trip through
4599        // validate. Covers a hyphen-bearing label, a numeric-suffix
4600        // label, a leading-digit label, a single-character label, and
4601        // a 63-byte (exactly the cap) label — the same fixture set
4602        // the peer `:membros :caixa` / `:children :caixa` positive
4603        // controls pin.
4604        for nome in [
4605            "caixa-teia",
4606            "caixa-resolver2",
4607            "2nd-tier-cache",
4608            "x",
4609            "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0",
4610        ] {
4611            Dep::simple(nome, "^0.1")
4612                .validate()
4613                .unwrap_or_else(|e| panic!("canonical label {nome:?} must validate, got {e:?}"));
4614        }
4615    }
4616
4617    #[test]
4618    fn nome_empty_takes_precedence_over_nome_invalid() {
4619        // Ordering pin: `NomeEmpty` is the more self-locating
4620        // diagnostic on `""` and must lead — `is_dns_1123_label` is
4621        // only reached after the empty-check fires at the call site.
4622        // Mirrors `membro_caixa_empty_takes_precedence_over_invalid`
4623        // (3f9d7a0) on the peer caixa-identifier axis.
4624        let mut d = Dep::simple("placeholder", "^0.1");
4625        d.nome = String::new();
4626        assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4627    }
4628
4629    #[test]
4630    fn nome_invalid_fires_before_versao_empty() {
4631        // Ordering pin: a malformed `:nome` fires before any `:versao`
4632        // axis check on the *same* entry — the per-entry shape gates
4633        // run top-to-bottom (nome empty → nome shape → versao empty →
4634        // versao parse → fonte shape), so a one-entry caixa.lisp with
4635        // both wrong sees the name-side diagnostic first (the name is
4636        // the self-locating axis — without a valid name, the parse
4637        // diagnostic can't quote `:nome "<bad>"`). Same ordering
4638        // discipline as `membro_caixa_invalid_fires_before_versao_check`
4639        // (3f9d7a0).
4640        let mut d = Dep::simple("Caixa-Teia", "^0.1");
4641        d.versao = String::new();
4642        let err = d.validate().unwrap_err();
4643        assert!(
4644            matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4645            "got {err:?}"
4646        );
4647    }
4648
4649    #[test]
4650    fn nome_invalid_fires_before_versao_invalid() {
4651        // Ordering pin: a malformed `:nome` fires before the `:versao`
4652        // parse-side check on the *same* entry. Pin separately from
4653        // the empty-versao ordering so a future re-ordering surfaces
4654        // here, parallel to the b0c8389 / c4213a4 trajectory.
4655        let d = Dep::simple("Caixa-Teia", "^^0.1");
4656        let err = d.validate().unwrap_err();
4657        assert!(
4658            matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4659            "got {err:?}"
4660        );
4661    }
4662
4663    #[test]
4664    fn nome_invalid_fires_before_fonte_invalid() {
4665        // Ordering pin: a malformed `:nome` fires before the `:fonte`
4666        // shape check on the *same* entry. The `:fonte` diagnostic
4667        // names the offending dep's `:nome` verbatim (via
4668        // `DepSource::validate(&self.nome)`), so a non-self-locating
4669        // name would taint the downstream diagnostic too — the gate
4670        // ordering keeps both diagnostics individually self-locating.
4671        let mut d = Dep::simple("Caixa-Teia", "^0.1");
4672        d.fonte = Some(DepSource::Git {
4673            repo: String::new(),
4674            tag: None,
4675            rev: None,
4676            branch: None,
4677        });
4678        let err = d.validate().unwrap_err();
4679        assert!(
4680            matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4681            "got {err:?}"
4682        );
4683    }
4684
4685    #[test]
4686    fn nome_invalid_diagnostic_carries_offending_name() {
4687        // The diagnostic-shape pin: the error names the offending
4688        // `:nome` value verbatim so the author can grep their
4689        // caixa.lisp without re-running the build, and carries a
4690        // non-empty `reason` from `is_dns_1123_label` so the
4691        // predicate's own wording flows through to the diagnostic.
4692        // Same shape as `MembroCaixaInvalid` (3f9d7a0),
4693        // `ChildCaixaInvalid` (31bfa43), `ManifestError::NomeInvalid`
4694        // (6c992f8) — the four DNS-1123 caixa-identifier axes now
4695        // share a structurally-equivalent diagnostic family.
4696        let d = Dep::simple("Caixa_Teia", "^0.1");
4697        let err = d.validate().unwrap_err();
4698        let DepError::NomeInvalid { nome, reason } = err else {
4699            panic!("expected NomeInvalid, got other variant");
4700        };
4701        assert_eq!(nome, "Caixa_Teia");
4702        assert!(
4703            !reason.is_empty(),
4704            "NomeInvalid `reason` must carry the predicate's wording verbatim"
4705        );
4706    }
4707
4708    #[test]
4709    fn validate_rejects_invalid_versao_requirement() {
4710        // The fail-before-pass-after pin: a non-empty but malformed
4711        // requirement (`"^bad-version"`) silently passed every pre-gate
4712        // codebase because `:deps :versao` wasn't validated. The parse
4713        // failure surfaced far downstream at lacre-resolve time with a
4714        // `semver::Error` that didn't name which `:deps` entry carried
4715        // the typo. The new gate moves the check to caixa-build time
4716        // at the source caixa.lisp.
4717        let d = Dep::simple("caixa-teia", "^bad-version");
4718        let err = d.validate().unwrap_err();
4719        assert!(
4720            matches!(
4721                err,
4722                DepError::VersaoInvalid { ref nome, ref versao, .. }
4723                    if nome == "caixa-teia" && versao == "^bad-version"
4724            ),
4725            "got {err:?}"
4726        );
4727    }
4728
4729    #[test]
4730    fn validate_rejects_versao_with_double_caret_typo() {
4731        // `"^^0.1"` is the canonical doubled-caret typo — looks like a
4732        // Cargo-shaped requirement on first glance but fails the parser
4733        // because semver doesn't accept stacked operators. Pin this
4734        // adjacent-shape footgun explicitly so a future relaxation that
4735        // accepts "looks-canonical-but-isn't" forms surfaces here, in
4736        // parity with the `:membros` / `:children` fixtures.
4737        let d = Dep::simple("caixa-teia", "^^0.1");
4738        let err = d.validate().unwrap_err();
4739        assert!(
4740            matches!(
4741                err,
4742                DepError::VersaoInvalid { ref nome, ref versao, .. }
4743                    if nome == "caixa-teia" && versao == "^^0.1"
4744            ),
4745            "got {err:?}"
4746        );
4747    }
4748
4749    #[test]
4750    fn validate_rejects_versao_with_v_prefixed_tag() {
4751        // `"v0.1"` is the canonical "git-tag-shape leaking into the
4752        // semver requirement slot" typo — an author copies the
4753        // publish-side git-tag string verbatim into `:versao`, but
4754        // Cargo's semver parser rejects the leading `v`. Same fixture
4755        // pinned for `:membros :versao` (9888b13) and `:children
4756        // :versao` (b38ff3a). (Bare `x`-glob shorthands like `^0.1.x`
4757        // are *accepted* by the semver crate as an `*` wildcard on the
4758        // patch axis — they're a Cargo-side valid shape, not a typo.)
4759        let d = Dep::simple("caixa-teia", "v0.1");
4760        let err = d.validate().unwrap_err();
4761        assert!(
4762            matches!(
4763                err,
4764                DepError::VersaoInvalid { ref nome, ref versao, .. }
4765                    if nome == "caixa-teia" && versao == "v0.1"
4766            ),
4767            "got {err:?}"
4768        );
4769    }
4770
4771    #[test]
4772    fn validate_accepts_canonical_versao_forms() {
4773        // The five Cargo-shaped requirement forms `:membros :versao`
4774        // and `:children :versao` already accept via
4775        // `crate::parse_requirement` must pass the deps gate without
4776        // re-validating at the resolver layer. Pin every leg so a
4777        // future tightening of the canonical set surfaces here as a
4778        // test failure.
4779        for form in [
4780            "^0.1",      // caret — minor-range pin (the most common shape)
4781            "~0.1.2",    // tilde — patch-range pin
4782            "0.1.0",     // exact — single-version pin
4783            "*",         // wildcard — explicitly any-version
4784            ">=0.1, <2", // multi-range — comma-separated comparators
4785        ] {
4786            Dep::simple("caixa-teia", form)
4787                .validate()
4788                .unwrap_or_else(|e| panic!("canonical form {form:?} must validate, got {e:?}"));
4789        }
4790    }
4791
4792    #[test]
4793    fn versao_empty_takes_precedence_over_invalid() {
4794        // Order pin: the existing `VersaoEmpty` diagnostic (which
4795        // doesn't try to parse) fires before the new `VersaoInvalid`
4796        // parse-side diagnostic, so an empty `:versao` keeps its
4797        // narrower error message — `parse_requirement("")` would
4798        // otherwise return `Ok(STAR)` and silently pass, but the empty
4799        // arm catches it first.
4800        let mut d = Dep::simple("caixa-teia", "ignored");
4801        d.versao = String::new();
4802        let err = d.validate().unwrap_err();
4803        assert!(
4804            matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4805            "got {err:?}"
4806        );
4807    }
4808
4809    #[test]
4810    fn nome_empty_takes_precedence_over_versao_invalid() {
4811        // Order pin: even when `:versao` is malformed and would raise
4812        // its own diagnostic, `:nome ""` fires first because the
4813        // per-entry parse diagnostic needs a non-empty name to be
4814        // self-locating. Mirrors the
4815        // `membros_validation_runs_before_contratos_membership_check`
4816        // ordering on the typed-graph layer.
4817        let mut d = Dep::simple("placeholder", "^bad");
4818        d.nome = String::new();
4819        let err = d.validate().unwrap_err();
4820        assert_eq!(err, DepError::NomeEmpty);
4821    }
4822
4823    #[test]
4824    fn versao_invalid_diagnostic_carries_offending_versao() {
4825        // The diagnostic-shape pin: the error names the offending
4826        // `:versao` value verbatim so the author can grep their
4827        // caixa.lisp without re-running the build, and carries a
4828        // non-empty `reason` from `semver::VersionReq::parse` so the
4829        // parser's own wording flows through to the diagnostic.
4830        let d = Dep::simple("caixa-teia", "not-a-req");
4831        let err = d.validate().unwrap_err();
4832        let DepError::VersaoInvalid {
4833            nome,
4834            versao,
4835            reason,
4836        } = err
4837        else {
4838            panic!("expected VersaoInvalid, got other variant");
4839        };
4840        assert_eq!(nome, "caixa-teia");
4841        assert_eq!(versao, "not-a-req");
4842        assert!(
4843            !reason.is_empty(),
4844            "VersaoInvalid `reason` must carry the parser's wording verbatim"
4845        );
4846    }
4847
4848    // -- :fonte value-shape gate ------------------------------------------
4849
4850    fn dep_with_fonte(fonte: DepSource) -> Dep {
4851        let mut d = Dep::simple("caixa-teia", "^0.1");
4852        d.fonte = Some(fonte);
4853        d
4854    }
4855
4856    #[test]
4857    fn validate_accepts_git_fonte_with_tag() {
4858        // The positive-control pin on the canonical git source — exactly
4859        // one of :tag/:rev/:branch set, non-empty :repo. Mirrors the
4860        // shape every existing caixa-resolver integration test uses.
4861        let d = dep_with_fonte(DepSource::Git {
4862            repo: "github:pleme-io/caixa-teia".into(),
4863            tag: Some("v0.1.0".into()),
4864            rev: None,
4865            branch: None,
4866        });
4867        d.validate().unwrap();
4868    }
4869
4870    #[test]
4871    fn validate_accepts_git_fonte_with_rev() {
4872        // Each of the three pin axes is independently a valid single-pin
4873        // shape; pin the :rev arm so a future relaxation that only
4874        // accepts :tag surfaces here. The value is a full 40-hex SHA-1
4875        // OID — the canonical `git rev-parse HEAD` emission shape the
4876        // `crate::render::is_git_oid` value-shape gate now requires;
4877        // abbreviated OIDs are ambiguous across repo history and
4878        // rejected at this gate (pinned separately by
4879        // `validate_rejects_git_fonte_with_rev_abbreviated_prefix`).
4880        let d = dep_with_fonte(DepSource::Git {
4881            repo: "github:pleme-io/caixa-teia".into(),
4882            tag: None,
4883            rev: Some("c0ffee0123abcdef0123456789abcdef01234567".into()),
4884            branch: None,
4885        });
4886        d.validate().unwrap();
4887    }
4888
4889    #[test]
4890    fn validate_accepts_git_fonte_with_branch() {
4891        // The :branch arm is the third valid single-pin shape — pinned
4892        // separately so the gate-accepts-all-three-pin-axes contract is
4893        // a build-error to relax.
4894        let d = dep_with_fonte(DepSource::Git {
4895            repo: "github:pleme-io/caixa-teia".into(),
4896            tag: None,
4897            rev: None,
4898            branch: Some("main".into()),
4899        });
4900        d.validate().unwrap();
4901    }
4902
4903    #[test]
4904    fn validate_accepts_path_fonte() {
4905        // The positive-control pin on the path source — non-empty
4906        // :caminho, no pin axes (paths have no commit identity). Pinned
4907        // so a future "paths must also pin a rev" tightening surfaces
4908        // here as a structural decision, not a silent break.
4909        let d = dep_with_fonte(DepSource::Path {
4910            caminho: "../caixa-teia".into(),
4911        });
4912        d.validate().unwrap();
4913    }
4914
4915    #[test]
4916    fn validate_rejects_git_fonte_with_empty_repo() {
4917        // The fail-before-pass-after pin for `(:tipo git :repo "" :tag
4918        // "v1")`: the empty-repo shape silently passed every pre-gate
4919        // codebase because `:fonte` wasn't validated. The git-clone
4920        // failure surfaced far downstream at lacre-resolve time with no
4921        // field naming which `:deps` entry carried the typo. The new
4922        // gate moves the check to caixa-build time at the source
4923        // caixa.lisp.
4924        let d = dep_with_fonte(DepSource::Git {
4925            repo: String::new(),
4926            tag: Some("v0.1.0".into()),
4927            rev: None,
4928            branch: None,
4929        });
4930        let err = d.validate().unwrap_err();
4931        assert!(
4932            matches!(err, DepError::FonteRepoEmpty { ref nome } if nome == "caixa-teia"),
4933            "got {err:?}"
4934        );
4935    }
4936
4937    // -- :repo value-shape gate -------------------------------------------
4938    //
4939    // The `:fonte (:tipo git :repo …)` value flows verbatim into the
4940    // caixa-resolver's `git clone <repo>` subprocess. The pre-gate
4941    // codebase admitted any non-empty string; the new
4942    // [`crate::render::is_git_repo_url`] predicate gates the git-porcelain
4943    // URL intersection-floor at validate time, peer with the three pin
4944    // axes (`:tag` + `:branch` via `is_git_ref_name`, `:rev` via
4945    // `is_git_oid`). Every test in this section is a fail-before /
4946    // pass-after pin on a specific authoring footgun.
4947
4948    #[test]
4949    fn validate_rejects_git_fonte_with_repo_carrying_trailing_space() {
4950        // The canonical paste-from-doc footgun on `:repo` — an author
4951        // copies `"github:pleme-io/caixa-teia "` (trailing space) out of
4952        // a doc paragraph. Until this gate landed the empty-repo arm
4953        // passed (the string isn't empty), the resolver issued
4954        // `git clone 'github:pleme-io/caixa-teia '`, and the failure
4955        // surfaced at clone time with a quoting-confused error far from
4956        // the source caixa.lisp. Same paste-from-doc footgun the
4957        // `:tag "v0.1.0 "` gate (e70d213) closes on the peer refname
4958        // axis — now closed on the `:repo` URL axis too.
4959        let d = dep_with_fonte(DepSource::Git {
4960            repo: "github:pleme-io/caixa-teia ".into(),
4961            tag: Some("v0.1.0".into()),
4962            rev: None,
4963            branch: None,
4964        });
4965        let err = d.validate().unwrap_err();
4966        let DepError::FonteRepoShape { nome, repo, reason } = err else {
4967            panic!("expected FonteRepoShape, got other variant");
4968        };
4969        assert_eq!(nome, "caixa-teia");
4970        assert_eq!(repo, "github:pleme-io/caixa-teia ");
4971        assert!(
4972            reason.contains("whitespace"),
4973            "reason must surface the whitespace arm, got {reason:?}"
4974        );
4975    }
4976
4977    #[test]
4978    fn validate_rejects_git_fonte_with_repo_starting_with_dash() {
4979        // The canonical CLI-argument-injection footgun at the `git clone`
4980        // subprocess boundary — `:repo "-upload-pack=evil"` makes git's
4981        // argv parser read the value as a CLI flag, escaping the
4982        // subprocess argument boundary. The `--` separator workaround
4983        // does not fix the typed slot's accepted set; the gate rejects
4984        // the shape upstream at validate time so the resolver never
4985        // invokes a `git clone -…` subprocess.
4986        let d = dep_with_fonte(DepSource::Git {
4987            repo: "-upload-pack=evil".into(),
4988            tag: Some("v0.1.0".into()),
4989            rev: None,
4990            branch: None,
4991        });
4992        let err = d.validate().unwrap_err();
4993        let DepError::FonteRepoShape { repo, reason, .. } = err else {
4994            panic!("expected FonteRepoShape, got other variant");
4995        };
4996        assert_eq!(repo, "-upload-pack=evil");
4997        assert!(
4998            reason.contains("must not start with `-`"),
4999            "reason must surface the leading-`-` arm, got {reason:?}"
5000        );
5001    }
5002
5003    #[test]
5004    fn validate_rejects_git_fonte_with_repo_carrying_embedded_newline() {
5005        // The canonical paste-from-multiline-doc footgun — a `:repo`
5006        // string with an embedded `\n` silently breaks git's URL parser
5007        // and is a class of CRLF-injection at the subprocess-argument
5008        // boundary. Caught by the control-char arm (0x0A < 0x20).
5009        let d = dep_with_fonte(DepSource::Git {
5010            repo: "github:pleme-io/caixa-teia\nrm -rf /".into(),
5011            tag: Some("v0.1.0".into()),
5012            rev: None,
5013            branch: None,
5014        });
5015        let err = d.validate().unwrap_err();
5016        let DepError::FonteRepoShape { reason, .. } = err else {
5017            panic!("expected FonteRepoShape, got other variant");
5018        };
5019        assert!(
5020            reason.contains("control character"),
5021            "reason must surface the control-char arm, got {reason:?}"
5022        );
5023    }
5024
5025    #[test]
5026    fn validate_rejects_git_fonte_with_repo_carrying_tab() {
5027        // Tab is the sibling whitespace footgun (the canonical
5028        // copy-from-aligned-table paste); pinned separately from the
5029        // space arm so a future relaxation that only catches one
5030        // surfaces here.
5031        let d = dep_with_fonte(DepSource::Git {
5032            repo: "github:pleme-io/caixa-teia\t".into(),
5033            tag: Some("v0.1.0".into()),
5034            rev: None,
5035            branch: None,
5036        });
5037        let err = d.validate().unwrap_err();
5038        assert!(
5039            matches!(
5040                err,
5041                DepError::FonteRepoShape { ref reason, .. }
5042                    if reason.contains("whitespace")
5043            ),
5044            "got {err:?}"
5045        );
5046    }
5047
5048    #[test]
5049    fn validate_rejects_git_fonte_with_repo_carrying_non_ascii() {
5050        // IDN hosts must be pre-encoded as Punycode (`xn--…`) — raw
5051        // non-ASCII silently breaks at git's URL parser and round-trips
5052        // inconsistently across NFC/NFD normalization on APFS /
5053        // case-folding filesystems. Same intersection-floor
5054        // [`is_git_ref_name`] enforces on the refname axes.
5055        let d = dep_with_fonte(DepSource::Git {
5056            repo: "https://github.com/pleme-io/café".into(),
5057            tag: Some("v0.1.0".into()),
5058            rev: None,
5059            branch: None,
5060        });
5061        let err = d.validate().unwrap_err();
5062        assert!(
5063            matches!(
5064                err,
5065                DepError::FonteRepoShape { ref reason, .. }
5066                    if reason.contains("non-ASCII")
5067            ),
5068            "got {err:?}"
5069        );
5070    }
5071
5072    #[test]
5073    fn validate_rejects_git_fonte_with_repo_carrying_fragment_anchor() {
5074        // The fail-before-pass-after pin for the canonical paste-from-
5075        // browser-address-bar footgun on `:repo`: an author copies a
5076        // GitHub permalink to a README anchor / line-permalink and
5077        // forgets to trim the `#fragment` tail. Until this arm landed
5078        // `:repo "https://github.com/pleme-io/caixa-teia#readme"`
5079        // silently passed every prior arm (no whitespace, no control
5080        // chars, no non-ASCII, contains a `:`, doesn't start with `-`
5081        // or `:`), libcurl's URL parser stripped the `#readme` tail
5082        // before opening the HTTPS transport, and the lacre embedded
5083        // the value verbatim in its per-dep BLAKE3 closure — two
5084        // authors whose values differ only in their fragment anchor
5085        // (`#readme` vs `#L42`) resolve to the byte-identical upstream
5086        // `git clone` but lock to two distinct lacres, defeating the
5087        // THEORY.md §V.2 render-determinism contract. Same value-shape
5088        // axis-floor every peer typed surface enforces; peer `:fonte
5089        // :tag` / `:fonte :branch` already reject the byte-class through
5090        // `is_git_ref_name`'s alphabet (refs are leaf identifiers, no
5091        // URL grammar admitted) and `:entrada :paths` rejects `#` as
5092        // part of `is_gateway_api_http_path`'s RFC-3986-reserved set.
5093        let d = dep_with_fonte(DepSource::Git {
5094            repo: "https://github.com/pleme-io/caixa-teia#readme".into(),
5095            tag: Some("v0.1.0".into()),
5096            rev: None,
5097            branch: None,
5098        });
5099        let err = d.validate().unwrap_err();
5100        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5101            panic!("expected FonteRepoShape, got other variant");
5102        };
5103        assert_eq!(nome, "caixa-teia");
5104        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia#readme");
5105        assert!(
5106            reason.contains("must not contain `#`"),
5107            "reason must surface the fragment-`#` arm, got {reason:?}"
5108        );
5109        assert!(
5110            reason.contains("fragment"),
5111            "reason must name the URL fragment grammar, got {reason:?}"
5112        );
5113    }
5114
5115    #[test]
5116    fn validate_rejects_git_fonte_with_repo_carrying_flake_ref_fragment() {
5117        // The symmetric paste-from-Nix-flake-ref footgun — an author
5118        // confuses the Nix flake-reference idiom (`github:foo/
5119        // bar#packageName`, where `#packageName` selects a flake
5120        // output) with the bare git `:repo` shape. The pleme-io
5121        // substrate authors compose flakes downstream of caixa
5122        // (caixa-flake renders a flake.nix), so the cross-idiom leak
5123        // is the canonical near-miss: the author writes the
5124        // flake-ref shape into a git `:repo` slot. Pinned separately
5125        // from the HTTPS-anchor arm so a future relaxation that
5126        // narrows to one URL scheme surfaces here.
5127        let d = dep_with_fonte(DepSource::Git {
5128            repo: "github:pleme-io/caixa-teia#caixa-teia".into(),
5129            tag: Some("v0.1.0".into()),
5130            rev: None,
5131            branch: None,
5132        });
5133        let err = d.validate().unwrap_err();
5134        let DepError::FonteRepoShape { reason, .. } = err else {
5135            panic!("expected FonteRepoShape, got other variant");
5136        };
5137        assert!(
5138            reason.contains("must not contain `#`"),
5139            "reason must surface the fragment-`#` arm, got {reason:?}"
5140        );
5141        assert!(
5142            reason.contains("Nix flake"),
5143            "reason must name the Nix-flake-ref cross-idiom footgun, got {reason:?}"
5144        );
5145    }
5146
5147    #[test]
5148    fn validate_rejects_git_fonte_with_repo_carrying_query_string() {
5149        // The fail-before-pass-after pin for the canonical paste-from-
5150        // browser-address-bar footgun on `:repo` (peer with the
5151        // a68f818 fragment-`#` arm on the same axis). An author
5152        // copies a GitHub tab deep-link out of the address bar and
5153        // forgets to trim the `?tab=…` query tail. Until this arm
5154        // landed `:repo "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"`
5155        // silently passed every prior arm (no whitespace, no control
5156        // chars, no non-ASCII, no `#` fragment, contains a `:`,
5157        // doesn't start with `-` or `:`); GitHub silently ignored
5158        // the `?query` tail and served the same repo regardless;
5159        // the lacre embedded the value verbatim in its per-dep
5160        // BLAKE3 closure — two authors whose values differ only in
5161        // their query tail (`?tab=readme-ov-file` vs `?ref=main` vs
5162        // `?utm_source=twitter`) resolve to the byte-identical
5163        // upstream `git clone` but lock to two distinct lacres,
5164        // defeating the THEORY.md §V.2 render-determinism contract
5165        // on the same axis the `#` fragment arm closes. Same value-
5166        // shape axis-floor every peer typed surface enforces; peer
5167        // `:fonte :tag` / `:fonte :branch` already reject the byte-
5168        // class through `is_git_ref_name`'s alphabet (refspec glob
5169        // wildcards, caixa-core/src/render.rs:1426) and `:entrada
5170        // :paths` rejects `?` as the query separator in
5171        // `is_gateway_api_http_path` (caixa-core/src/render.rs:473).
5172        let d = dep_with_fonte(DepSource::Git {
5173            repo: "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file".into(),
5174            tag: Some("v0.1.0".into()),
5175            rev: None,
5176            branch: None,
5177        });
5178        let err = d.validate().unwrap_err();
5179        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5180            panic!("expected FonteRepoShape, got other variant");
5181        };
5182        assert_eq!(nome, "caixa-teia");
5183        assert_eq!(
5184            repo,
5185            "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"
5186        );
5187        assert!(
5188            reason.contains("must not contain `?`"),
5189            "reason must surface the query-`?` arm, got {reason:?}"
5190        );
5191        assert!(
5192            reason.contains("query"),
5193            "reason must name the URL query grammar, got {reason:?}"
5194        );
5195    }
5196
5197    #[test]
5198    fn validate_rejects_git_fonte_with_repo_carrying_utm_tracker() {
5199        // The symmetric paste-from-social-share footgun — an author
5200        // copies a repo URL out of a Slack unfurl / Twitter share /
5201        // newsletter link / Discord embed and forgets to trim the
5202        // `?utm_source=…` / `?utm_medium=…` / `?utm_campaign=…`
5203        // campaign-tracker tail. Every major social-share / unfurl /
5204        // newsletter platform appends these UTM parameters; the
5205        // canonical near-miss on the `:repo` axis. Pinned separately
5206        // from the GitHub-tab-deep-link arm so a future relaxation
5207        // that narrows to one query-parameter class surfaces here.
5208        let d = dep_with_fonte(DepSource::Git {
5209            repo: "https://github.com/pleme-io/caixa-teia?utm_source=twitter&utm_campaign=launch"
5210                .into(),
5211            tag: Some("v0.1.0".into()),
5212            rev: None,
5213            branch: None,
5214        });
5215        let err = d.validate().unwrap_err();
5216        let DepError::FonteRepoShape { reason, .. } = err else {
5217            panic!("expected FonteRepoShape, got other variant");
5218        };
5219        assert!(
5220            reason.contains("must not contain `?`"),
5221            "reason must surface the query-`?` arm, got {reason:?}"
5222        );
5223        assert!(
5224            reason.contains("campaign-tracker"),
5225            "reason must name the campaign-tracker paste footgun, got {reason:?}"
5226        );
5227    }
5228
5229    #[test]
5230    fn fonte_repo_fragment_fires_before_query_when_fragment_first() {
5231        // Cascade pin: the fragment-`#` arm and the query-`?` arm are
5232        // both per-byte arms inside the same `for &b in s.as_bytes()`
5233        // loop, so the byte that appears first in the value's byte
5234        // order wins. A `:repo "https://github.com/p/x#readme?ref=main"`
5235        // (fragment before query — unusual URL-grammar but value-
5236        // disjoint at byte level) carries both `#` and `?`; the `#`
5237        // byte appears first, so the fragment-`#` arm fires, surfacing
5238        // the more self-locating diagnostic on the byte the author
5239        // pasted earliest in the URL. Mirrors the peer cascade
5240        // discipline `fonte_repo_control_char_fires_before_fragment`
5241        // pins on the prior `:repo` byte-class arm.
5242        let d = dep_with_fonte(DepSource::Git {
5243            repo: "https://github.com/pleme-io/caixa-teia#readme?ref=main".into(),
5244            tag: Some("v0.1.0".into()),
5245            rev: None,
5246            branch: None,
5247        });
5248        let err = d.validate().unwrap_err();
5249        let DepError::FonteRepoShape { reason, .. } = err else {
5250            panic!("expected FonteRepoShape, got other variant");
5251        };
5252        assert!(
5253            reason.contains("must not contain `#`"),
5254            "reason must surface the fragment-`#` arm (fires before query-`?` when \
5255             `#` byte appears first in value), got {reason:?}"
5256        );
5257    }
5258
5259    #[test]
5260    fn fonte_repo_control_char_fires_before_fragment() {
5261        // Cascade pin: the control-char arm structurally precedes the
5262        // fragment-`#` arm. A value like `"github:p/x\n#readme"` probes
5263        // positive on both arms (contains LF and `#`), but the narrower
5264        // POSIX-syscall-rejected / CRLF-injection-class diagnostic
5265        // (`control character`) wins so the author sees the more
5266        // self-locating arm first. Mirrors the peer cascade discipline
5267        // every prior `:repo` byte-class arm establishes.
5268        let d = dep_with_fonte(DepSource::Git {
5269            repo: "github:pleme-io/caixa-teia\n#readme".into(),
5270            tag: Some("v0.1.0".into()),
5271            rev: None,
5272            branch: None,
5273        });
5274        let err = d.validate().unwrap_err();
5275        let DepError::FonteRepoShape { reason, .. } = err else {
5276            panic!("expected FonteRepoShape, got other variant");
5277        };
5278        assert!(
5279            reason.contains("control character"),
5280            "reason must surface the control-char arm, got {reason:?}"
5281        );
5282    }
5283
5284    #[test]
5285    fn validate_rejects_git_fonte_with_repo_carrying_embedded_backslash() {
5286        // The fail-before-pass-after pin for the canonical Windows-
5287        // file-path-confusion footgun on `:repo` (peer with the 3a4e1d7
5288        // backslash arm on the sibling `:caminho` path-fonte axis).
5289        // An author pastes a Windows Explorer address-bar / PowerShell
5290        // `Get-Location` output into a `file://` URL slot, producing
5291        // `file:///C:\Users\me\caixa-teia`. Until this arm landed the
5292        // value silently passed every prior arm (no whitespace, no
5293        // control chars, no non-ASCII, no `#`, no `?`, doesn't start
5294        // with `-` or `:`); libcurl's URL parser silently translates
5295        // `\` → `/` on some platforms and refuses it on others, so
5296        // the byte rides verbatim into the lacre's per-dep content-
5297        // address but is silently rewritten / rejected at the wire —
5298        // two authors whose `:repo` values differ only in backslash-
5299        // vs-forward-slash (`file:///C:\path` vs `file:///C:/path`)
5300        // resolve to the byte-identical local clone but lock to two
5301        // distinct BLAKE3 closures, defeating the THEORY.md §V.2
5302        // render-determinism contract on the same axis the `#`
5303        // fragment and `?` query arms close. Same value-shape axis-
5304        // floor every peer typed surface enforces; the `:caminho`
5305        // 3a4e1d7 arm closes the same byte on the path-fonte axis.
5306        let d = dep_with_fonte(DepSource::Git {
5307            repo: "file:///C:\\Users\\me\\caixa-teia".into(),
5308            tag: Some("v0.1.0".into()),
5309            rev: None,
5310            branch: None,
5311        });
5312        let err = d.validate().unwrap_err();
5313        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5314            panic!("expected FonteRepoShape, got other variant");
5315        };
5316        assert_eq!(nome, "caixa-teia");
5317        assert_eq!(repo, "file:///C:\\Users\\me\\caixa-teia");
5318        assert!(
5319            reason.contains("must not contain `\\`"),
5320            "reason must surface the backslash-`\\` arm, got {reason:?}"
5321        );
5322        assert!(
5323            reason.contains("Windows"),
5324            "reason must name the Windows-path-confusion footgun, got {reason:?}"
5325        );
5326    }
5327
5328    #[test]
5329    fn validate_rejects_git_fonte_with_repo_carrying_mangled_https_backslashes() {
5330        // The symmetric Win32-shell-mangled-slashes footgun — an author
5331        // copies `https://github.com/foo/bar` into a Win32 shell that
5332        // rewrites every `/` to `\` (the canonical `cmd.exe` path-
5333        // separator-coercion bug), pastes the result into a `:repo`
5334        // slot, and produces `https:\\github.com\foo\bar`. Pinned
5335        // separately from the `file://` Explorer-paste arm so a future
5336        // relaxation that narrows to one URL scheme surfaces here.
5337        let d = dep_with_fonte(DepSource::Git {
5338            repo: "https:\\\\github.com\\pleme-io\\caixa-teia".into(),
5339            tag: Some("v0.1.0".into()),
5340            rev: None,
5341            branch: None,
5342        });
5343        let err = d.validate().unwrap_err();
5344        let DepError::FonteRepoShape { reason, .. } = err else {
5345            panic!("expected FonteRepoShape, got other variant");
5346        };
5347        assert!(
5348            reason.contains("must not contain `\\`"),
5349            "reason must surface the backslash-`\\` arm, got {reason:?}"
5350        );
5351        assert!(
5352            reason.contains("path separator") || reason.contains("path-segment separator"),
5353            "reason must name the URL path-segment separator grammar, got {reason:?}"
5354        );
5355    }
5356
5357    #[test]
5358    fn fonte_repo_fragment_fires_before_backslash_when_fragment_first() {
5359        // Cascade pin: the fragment-`#` arm and the backslash-`\` arm
5360        // are both per-byte arms inside the same `for &b in s.as_bytes()`
5361        // loop, so the byte that appears first in the value's byte order
5362        // wins. A `:repo "https://github.com/p/x#readme\\foo"` carries
5363        // both `#` and `\`; the `#` byte appears first, so the fragment-
5364        // `#` arm fires, surfacing the more self-locating diagnostic on
5365        // the byte the author pasted earliest in the URL. Mirrors the
5366        // peer cascade discipline `fonte_repo_fragment_fires_before_query_when_fragment_first`
5367        // pins on the prior `:repo` byte-class arm.
5368        let d = dep_with_fonte(DepSource::Git {
5369            repo: "https://github.com/pleme-io/caixa-teia#readme\\foo".into(),
5370            tag: Some("v0.1.0".into()),
5371            rev: None,
5372            branch: None,
5373        });
5374        let err = d.validate().unwrap_err();
5375        let DepError::FonteRepoShape { reason, .. } = err else {
5376            panic!("expected FonteRepoShape, got other variant");
5377        };
5378        assert!(
5379            reason.contains("must not contain `#`"),
5380            "reason must surface the fragment-`#` arm (fires before backslash-`\\` when \
5381             `#` byte appears first in value), got {reason:?}"
5382        );
5383    }
5384
5385    #[test]
5386    fn validate_rejects_git_fonte_with_repo_carrying_uri_template_placeholder() {
5387        // The fail-before-pass-after pin for the canonical URI Template
5388        // (RFC 6570) placeholder footgun on `:repo`. An author copies a
5389        // README quick-start snippet / OpenAPI `servers:` URL / Helm
5390        // chart `home:` template that carries unresolved
5391        // `{org}` / `{repo}` placeholders and pastes the raw template
5392        // into the `:repo` slot, expecting the substrate to resolve the
5393        // placeholder downstream. Until this arm landed the value
5394        // silently passed every prior arm (no whitespace, no control
5395        // chars, no non-ASCII, no `#`, no `?`, no `\`, doesn't start
5396        // with `-` or `:`); libcurl percent-encodes `{` / `}` to `%7B`
5397        // / `%7D` on the wire, so the byte rides verbatim into the
5398        // lacre's per-dep content-address but round-trips inconsistently
5399        // between the lacre's per-dep content-address and the
5400        // resolver's `git clone <repo>` invocation, defeating the
5401        // THEORY.md §V.2 render-determinism contract on the same axis
5402        // the `#` fragment, `?` query, and `\` backslash arms close;
5403        // every git porcelain entry-point additionally fetches a
5404        // nonexistent literal-`{placeholder}`-named path far from the
5405        // source caixa.lisp.
5406        let d = dep_with_fonte(DepSource::Git {
5407            repo: "https://github.com/{org}/caixa-teia".into(),
5408            tag: Some("v0.1.0".into()),
5409            rev: None,
5410            branch: None,
5411        });
5412        let err = d.validate().unwrap_err();
5413        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5414            panic!("expected FonteRepoShape, got other variant");
5415        };
5416        assert_eq!(nome, "caixa-teia");
5417        assert_eq!(repo, "https://github.com/{org}/caixa-teia");
5418        assert!(
5419            reason.contains("must not contain `{`"),
5420            "reason must surface the open-brace `{{` arm, got {reason:?}"
5421        );
5422        assert!(
5423            reason.contains("URI Template") || reason.contains("RFC 6570"),
5424            "reason must name the RFC 6570 URI Template grammar, got {reason:?}"
5425        );
5426    }
5427
5428    #[test]
5429    fn validate_rejects_git_fonte_with_repo_carrying_handlebars_doubled_brace() {
5430        // The symmetric Mustache / Handlebars doubled-brace
5431        // substitution-form footgun every CI / IaC templating engine
5432        // (Argo Workflows, Jinja2, Liquid, Vue / Angular interpolation,
5433        // GitHub Actions `${{ … }}` even though Actions uses `${{`) /
5434        // chart README quick-start snippet emits. Pinned separately
5435        // from the single-`{` `{org}` arm so a future relaxation that
5436        // narrows to one substitution-form surfaces here.
5437        let d = dep_with_fonte(DepSource::Git {
5438            repo: "https://github.com/{{org}}/caixa-teia".into(),
5439            tag: Some("v0.1.0".into()),
5440            rev: None,
5441            branch: None,
5442        });
5443        let err = d.validate().unwrap_err();
5444        let DepError::FonteRepoShape { reason, .. } = err else {
5445            panic!("expected FonteRepoShape, got other variant");
5446        };
5447        assert!(
5448            reason.contains("must not contain `{`"),
5449            "reason must surface the open-brace `{{` arm, got {reason:?}"
5450        );
5451    }
5452
5453    #[test]
5454    fn validate_rejects_git_fonte_with_repo_carrying_closing_brace_only() {
5455        // Asymmetric `}`-only shape — covers the closing-brace-by-
5456        // itself footgun (an author truncated `{org}/{repo}` mid-edit
5457        // and left a trailing `}` from the prior template fragment,
5458        // or pasted a value that included a closing brace from a
5459        // surrounding shell context). Pinned to ensure the predicate
5460        // refuses each brace independently rather than only when both
5461        // appear — a future regression that ANDs the two byte tests
5462        // surfaces here.
5463        let d = dep_with_fonte(DepSource::Git {
5464            repo: "https://github.com/pleme-io/caixa-teia}".into(),
5465            tag: Some("v0.1.0".into()),
5466            rev: None,
5467            branch: None,
5468        });
5469        let err = d.validate().unwrap_err();
5470        let DepError::FonteRepoShape { reason, .. } = err else {
5471            panic!("expected FonteRepoShape, got other variant");
5472        };
5473        assert!(
5474            reason.contains("must not contain `}`"),
5475            "reason must surface the close-brace `}}` arm, got {reason:?}"
5476        );
5477    }
5478
5479    #[test]
5480    fn fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first() {
5481        // Cascade pin: the fragment-`#` arm and the template-`{` /
5482        // `}` arm are both per-byte arms inside the same
5483        // `for &b in s.as_bytes()` loop, so the byte that appears
5484        // first in the value's byte order wins. A `:repo
5485        // "https://github.com/p/x#readme{org}"` carries both `#` and
5486        // `{`; the `#` byte appears first, so the fragment-`#` arm
5487        // fires, surfacing the more self-locating diagnostic on the
5488        // byte the author pasted earliest in the URL. Mirrors the
5489        // peer cascade discipline `fonte_repo_fragment_fires_before_backslash_when_fragment_first`
5490        // pins on the prior `:repo` byte-class arm.
5491        let d = dep_with_fonte(DepSource::Git {
5492            repo: "https://github.com/pleme-io/caixa-teia#readme{org}".into(),
5493            tag: Some("v0.1.0".into()),
5494            rev: None,
5495            branch: None,
5496        });
5497        let err = d.validate().unwrap_err();
5498        let DepError::FonteRepoShape { reason, .. } = err else {
5499            panic!("expected FonteRepoShape, got other variant");
5500        };
5501        assert!(
5502            reason.contains("must not contain `#`"),
5503            "reason must surface the fragment-`#` arm (fires before template-`{{` when \
5504             `#` byte appears first in value), got {reason:?}"
5505        );
5506    }
5507
5508    #[test]
5509    fn validate_rejects_git_fonte_with_repo_carrying_output_redirection() {
5510        // The fail-before-pass-after pin for the canonical
5511        // shell-output-redirection footgun on `:repo`: an author
5512        // pastes a shell-pipeline tail (`git clone <repo> > build.log`
5513        // / `… >output.txt`) into the `:repo` slot without trimming
5514        // the redirect. Until this arm landed the value silently
5515        // passed every prior arm (no whitespace, no control chars,
5516        // no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, doesn't
5517        // start with `-` or `:`); RFC 3986 §2 lists `<` / `>` in the
5518        // 'delims' / 'unwise' set and the WHATWG URL spec's fragment
5519        // percent-encode set maps `>` → `%3E` on the wire, so the
5520        // byte rides verbatim into the lacre's per-dep BLAKE3 closure
5521        // but is silently rewritten or rejected at libcurl's URL-
5522        // parser layer — two authors whose values differ only in
5523        // their redirect tail (`>build.log` vs nothing) resolve to
5524        // the byte-identical upstream `git clone` but lock to two
5525        // distinct lacres, defeating the THEORY.md §V.2 render-
5526        // determinism contract. Peer with the `:caminho` axis's
5527        // `FonteCaminhoShellRedirection` arm (e457141) on the sibling
5528        // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5529        // byte RFC-3986-reserved set on `:entrada :paths`.
5530        let d = dep_with_fonte(DepSource::Git {
5531            repo: "https://github.com/pleme-io/caixa-teia>build.log".into(),
5532            tag: Some("v0.1.0".into()),
5533            rev: None,
5534            branch: None,
5535        });
5536        let err = d.validate().unwrap_err();
5537        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5538            panic!("expected FonteRepoShape, got other variant");
5539        };
5540        assert_eq!(nome, "caixa-teia");
5541        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia>build.log");
5542        assert!(
5543            reason.contains("must not contain `>`"),
5544            "reason must surface the output-redirection `>` arm, got {reason:?}"
5545        );
5546        assert!(
5547            reason.contains("redirection") || reason.contains("'delims'"),
5548            "reason must name the shell-redirection / RFC-3986-unwise rationale, got {reason:?}"
5549        );
5550    }
5551
5552    #[test]
5553    fn validate_rejects_git_fonte_with_repo_carrying_input_redirection() {
5554        // The symmetric shell-input-redirection footgun — an author
5555        // pastes a shell-pipeline head (`git clone <input.url` /
5556        // `cat <README.md`) into the `:repo` slot. Pinned separately
5557        // from the `>`-output arm so a future relaxation that only
5558        // catches one of the two redirect bytes surfaces here. Peer
5559        // with the `:caminho` axis's `FonteCaminhoShellRedirection`
5560        // arm which closes both `<` and `>` under the same banner.
5561        let d = dep_with_fonte(DepSource::Git {
5562            repo: "https://github.com/pleme-io/caixa-teia<input.url".into(),
5563            tag: Some("v0.1.0".into()),
5564            rev: None,
5565            branch: None,
5566        });
5567        let err = d.validate().unwrap_err();
5568        let DepError::FonteRepoShape { reason, .. } = err else {
5569            panic!("expected FonteRepoShape, got other variant");
5570        };
5571        assert!(
5572            reason.contains("must not contain `<`"),
5573            "reason must surface the input-redirection `<` arm, got {reason:?}"
5574        );
5575        assert!(
5576            reason.contains("RFC 3986") || reason.contains("'unwise'"),
5577            "reason must name the RFC 3986 'unwise' grammar, got {reason:?}"
5578        );
5579    }
5580
5581    #[test]
5582    fn validate_rejects_git_fonte_with_repo_carrying_backtick_command_substitution() {
5583        // The fail-before-pass-after pin for the canonical
5584        // paste-from-shell-prompt-with-backticked-substitution footgun
5585        // on `:repo` (peer with the c4d62b3 backtick arm on the sibling
5586        // `:caminho` path-fonte axis). An author pastes a URL whose
5587        // segment carries a backticked command-substitution wrapper
5588        // (`` `whoami` ``, `` `git config user.name` ``, `` `pwd` ``)
5589        // from a doc / README quick-start snippet that expected the
5590        // substrate to substitute the value downstream. Until this arm
5591        // landed the value silently passed every prior arm (no
5592        // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5593        // no `\`, no `{`/`}`, no `<`/`>`, doesn't start with `-` or
5594        // `:`); RFC 3986 §2 lists the backtick byte in the 'delims' /
5595        // 'unwise' set and the WHATWG URL spec's fragment percent-
5596        // encode set maps `` ` `` → `%60` on the wire, so the byte
5597        // rides verbatim into the lacre's per-dep BLAKE3 closure but
5598        // is silently rewritten or rejected at libcurl's URL-parser
5599        // layer — two authors whose values differ only in their
5600        // backtick wrapper (`` `whoami` `` vs nothing) resolve to the
5601        // byte-identical upstream `git clone` but lock to two distinct
5602        // lacres, defeating the THEORY.md §V.2 render-determinism
5603        // contract. Peer with the `:caminho` axis's
5604        // `FonteCaminhoShellCommandSubstitution` arm (c4d62b3) on the
5605        // sibling path-fonte axis, and `is_gateway_api_http_path`'s
5606        // eleven-byte RFC-3986-reserved set on `:entrada :paths`.
5607        let d = dep_with_fonte(DepSource::Git {
5608            repo: "https://github.com/pleme-io/`whoami`/caixa-teia".into(),
5609            tag: Some("v0.1.0".into()),
5610            rev: None,
5611            branch: None,
5612        });
5613        let err = d.validate().unwrap_err();
5614        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5615            panic!("expected FonteRepoShape, got other variant");
5616        };
5617        assert_eq!(nome, "caixa-teia");
5618        assert_eq!(repo, "https://github.com/pleme-io/`whoami`/caixa-teia");
5619        assert!(
5620            reason.contains("must not contain `` ` ``"),
5621            "reason must surface the backtick command-substitution arm, got {reason:?}"
5622        );
5623        assert!(
5624            reason.contains("command-substitution") || reason.contains("'unwise'"),
5625            "reason must name the shell-command-substitution / RFC-3986-unwise rationale, \
5626             got {reason:?}"
5627        );
5628    }
5629
5630    #[test]
5631    fn fonte_repo_fragment_fires_before_backtick_when_fragment_first() {
5632        // Cascade pin: the fragment-`#` arm and the backtick command-
5633        // substitution arm are both per-byte arms inside the same
5634        // `for &b in s.as_bytes()` loop, so the byte that appears first
5635        // in the value's byte order wins. A `:repo
5636        // "https://github.com/p/x#readme/`whoami`"` carries both `#`
5637        // and backtick; the `#` byte appears first, so the fragment-
5638        // `#` arm fires, surfacing the more self-locating diagnostic
5639        // on the byte the author pasted earliest in the URL. Mirrors
5640        // the peer cascade discipline
5641        // `fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first`
5642        // pins on the prior `:repo` byte-class arm.
5643        let d = dep_with_fonte(DepSource::Git {
5644            repo: "https://github.com/pleme-io/caixa-teia#readme/`whoami`".into(),
5645            tag: Some("v0.1.0".into()),
5646            rev: None,
5647            branch: None,
5648        });
5649        let err = d.validate().unwrap_err();
5650        let DepError::FonteRepoShape { reason, .. } = err else {
5651            panic!("expected FonteRepoShape, got other variant");
5652        };
5653        assert!(
5654            reason.contains("must not contain `#`"),
5655            "reason must surface the fragment-`#` arm (fires before backtick when `#` byte \
5656             appears first in value), got {reason:?}"
5657        );
5658    }
5659
5660    #[test]
5661    fn fonte_repo_shell_redirection_fires_before_backtick_when_redirection_first() {
5662        // Cascade pin: the shell-redirection `<` / `>` arm and the
5663        // backtick command-substitution arm are both per-byte arms
5664        // inside the same `for &b in s.as_bytes()` loop, so the byte
5665        // that appears first in the value's byte order wins. A `:repo
5666        // "https://github.com/p/x>build.log/`whoami`"` carries both
5667        // `>` and backtick; the `>` byte appears first, so the
5668        // shell-redirection arm fires, surfacing the more self-
5669        // locating diagnostic on the byte the author pasted earliest
5670        // in the URL. Pins the natural-order cascade so a future
5671        // reorder of the per-byte arms surfaces here.
5672        let d = dep_with_fonte(DepSource::Git {
5673            repo: "https://github.com/pleme-io/caixa-teia>build.log/`whoami`".into(),
5674            tag: Some("v0.1.0".into()),
5675            rev: None,
5676            branch: None,
5677        });
5678        let err = d.validate().unwrap_err();
5679        let DepError::FonteRepoShape { reason, .. } = err else {
5680            panic!("expected FonteRepoShape, got other variant");
5681        };
5682        assert!(
5683            reason.contains("must not contain `>`"),
5684            "reason must surface the shell-redirection `>` arm (fires before backtick when \
5685             `>` byte appears first in value), got {reason:?}"
5686        );
5687    }
5688
5689    #[test]
5690    fn fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first() {
5691        // Cascade pin: the fragment-`#` arm and the shell-redirection
5692        // `<` / `>` arm are both per-byte arms inside the same
5693        // `for &b in s.as_bytes()` loop, so the byte that appears
5694        // first in the value's byte order wins. A `:repo
5695        // "https://github.com/p/x#readme>build.log"` carries both
5696        // `#` and `>`; the `#` byte appears first, so the fragment-
5697        // `#` arm fires, surfacing the more self-locating diagnostic
5698        // on the byte the author pasted earliest in the URL. Mirrors
5699        // the peer cascade discipline
5700        // `fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first`
5701        // pins on the prior `:repo` byte-class arm.
5702        let d = dep_with_fonte(DepSource::Git {
5703            repo: "https://github.com/pleme-io/caixa-teia#readme>build.log".into(),
5704            tag: Some("v0.1.0".into()),
5705            rev: None,
5706            branch: None,
5707        });
5708        let err = d.validate().unwrap_err();
5709        let DepError::FonteRepoShape { reason, .. } = err else {
5710            panic!("expected FonteRepoShape, got other variant");
5711        };
5712        assert!(
5713            reason.contains("must not contain `#`"),
5714            "reason must surface the fragment-`#` arm (fires before shell-redirection `>` when \
5715             `#` byte appears first in value), got {reason:?}"
5716        );
5717    }
5718
5719    #[test]
5720    fn validate_rejects_git_fonte_with_repo_carrying_shell_pipe() {
5721        // The fail-before-pass-after pin for the canonical
5722        // paste-from-shell-prompt-with-piped-pipeline footgun on
5723        // `:repo` (peer with the 124106f pipe arm on the sibling
5724        // `:caminho` path-fonte axis). An author pastes a shell
5725        // pipeline (`git clone <url> | tee build.log`,
5726        // `git ls-remote <url> | head`) into the `:repo` slot,
5727        // forgetting to trim the `| <consumer>` tail. Until this arm
5728        // landed the value silently passed every prior arm (no
5729        // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5730        // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, doesn't start
5731        // with `-` or `:`); RFC 3986 §2 lists the pipe byte in the
5732        // 'unwise' set and the WHATWG URL spec's fragment percent-
5733        // encode set maps `|` → `%7C` on the wire, so the byte rides
5734        // verbatim into the lacre's per-dep BLAKE3 closure but is
5735        // silently rewritten or rejected at libcurl's URL-parser
5736        // layer — two authors whose values differ only in their pipe
5737        // tail (`|tee build.log` vs nothing) resolve to the byte-
5738        // identical upstream `git clone` but lock to two distinct
5739        // lacres, defeating the THEORY.md §V.2 render-determinism
5740        // contract. Peer with the `:caminho` axis's
5741        // `FonteCaminhoShellPipe` arm (124106f) on the sibling path-
5742        // fonte axis, and `is_gateway_api_http_path`'s eleven-byte
5743        // RFC-3986-reserved set on `:entrada :paths`.
5744        let d = dep_with_fonte(DepSource::Git {
5745            repo: "https://github.com/pleme-io/caixa-teia|tee build.log".into(),
5746            tag: Some("v0.1.0".into()),
5747            rev: None,
5748            branch: None,
5749        });
5750        let err = d.validate().unwrap_err();
5751        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5752            panic!("expected FonteRepoShape, got other variant");
5753        };
5754        assert_eq!(nome, "caixa-teia");
5755        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia|tee build.log");
5756        assert!(
5757            reason.contains("must not contain `|`"),
5758            "reason must surface the shell-pipe arm, got {reason:?}"
5759        );
5760        assert!(
5761            reason.contains("pipe") || reason.contains("'unwise'"),
5762            "reason must name the shell-pipe / RFC-3986-unwise rationale, got {reason:?}"
5763        );
5764    }
5765
5766    #[test]
5767    fn fonte_repo_fragment_fires_before_pipe_when_fragment_first() {
5768        // Cascade pin: the fragment-`#` arm and the pipe arm are both
5769        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5770        // so the byte that appears first in the value's byte order
5771        // wins. A `:repo "https://github.com/p/x#readme|tee"` carries
5772        // both `#` and `|`; the `#` byte appears first, so the
5773        // fragment-`#` arm fires, surfacing the more self-locating
5774        // diagnostic on the byte the author pasted earliest in the
5775        // URL. Mirrors the peer cascade discipline
5776        // `fonte_repo_fragment_fires_before_backtick_when_fragment_first`
5777        // pins on the prior `:repo` byte-class arm.
5778        let d = dep_with_fonte(DepSource::Git {
5779            repo: "https://github.com/pleme-io/caixa-teia#readme|tee".into(),
5780            tag: Some("v0.1.0".into()),
5781            rev: None,
5782            branch: None,
5783        });
5784        let err = d.validate().unwrap_err();
5785        let DepError::FonteRepoShape { reason, .. } = err else {
5786            panic!("expected FonteRepoShape, got other variant");
5787        };
5788        assert!(
5789            reason.contains("must not contain `#`"),
5790            "reason must surface the fragment-`#` arm (fires before pipe when `#` byte \
5791             appears first in value), got {reason:?}"
5792        );
5793    }
5794
5795    #[test]
5796    fn fonte_repo_backtick_fires_before_pipe_when_backtick_first() {
5797        // Cascade pin: the backtick arm and the pipe arm are both per-
5798        // byte arms inside the same `for &b in s.as_bytes()` loop, so
5799        // the byte that appears first in the value's byte order wins.
5800        // A `:repo "https://github.com/p/x/`whoami`|tee"` carries both
5801        // `` ` `` and `|`; the backtick byte appears first, so the
5802        // backtick arm fires, surfacing the more self-locating
5803        // diagnostic on the byte the author pasted earliest in the
5804        // URL. Pins the natural-order cascade so a future reorder of
5805        // the per-byte arms surfaces here.
5806        let d = dep_with_fonte(DepSource::Git {
5807            repo: "https://github.com/pleme-io/caixa-teia/`whoami`|tee".into(),
5808            tag: Some("v0.1.0".into()),
5809            rev: None,
5810            branch: None,
5811        });
5812        let err = d.validate().unwrap_err();
5813        let DepError::FonteRepoShape { reason, .. } = err else {
5814            panic!("expected FonteRepoShape, got other variant");
5815        };
5816        assert!(
5817            reason.contains("must not contain `` ` ``"),
5818            "reason must surface the backtick arm (fires before pipe when `` ` `` byte \
5819             appears first in value), got {reason:?}"
5820        );
5821    }
5822
5823    #[test]
5824    fn validate_rejects_git_fonte_with_repo_carrying_shell_command_separator() {
5825        // The fail-before-pass-after pin for the canonical
5826        // paste-from-shell-prompt-with-sequential-command-tail footgun
5827        // on `:repo` (peer with the 05c358e `;` arm on the sibling
5828        // `:caminho` path-fonte axis). An author pastes a shell
5829        // one-liner that chained a cleanup tail after the URL
5830        // (`git clone <url>; rm -rf build`, `git ls-remote <url>;
5831        // echo done`) into the `:repo` slot, forgetting to trim the
5832        // `; <cmd>` tail. Until this arm landed the value silently
5833        // passed every prior `is_git_repo_url` arm (no whitespace, no
5834        // control chars, no non-ASCII, no `#`, no `?`, no `\`, no
5835        // `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, doesn't start with
5836        // `-` or `:`); RFC 3986 §2 lists `;` in the 'sub-delims' /
5837        // reserved set and the WHATWG URL spec's fragment percent-
5838        // encode set maps `;` → `%3B` on the wire, so the byte rides
5839        // verbatim into the lacre's per-dep BLAKE3 closure but is
5840        // silently rewritten at libcurl's URL-parser layer — two
5841        // authors whose values differ only in their sequential-command
5842        // tail (`; rm -rf build` vs nothing) resolve to the byte-
5843        // identical upstream `git clone` but lock to two distinct
5844        // lacres, defeating the THEORY.md §V.2 render-determinism
5845        // contract. Peer with the `:caminho` axis's
5846        // `FonteCaminhoShellSemicolon` arm (05c358e) on the sibling
5847        // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5848        // byte RFC-3986-reserved set on `:entrada :paths`.
5849        let d = dep_with_fonte(DepSource::Git {
5850            repo: "https://github.com/pleme-io/caixa-teia; rm -rf build".into(),
5851            tag: Some("v0.1.0".into()),
5852            rev: None,
5853            branch: None,
5854        });
5855        let err = d.validate().unwrap_err();
5856        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5857            panic!("expected FonteRepoShape, got other variant");
5858        };
5859        assert_eq!(nome, "caixa-teia");
5860        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia; rm -rf build");
5861        assert!(
5862            reason.contains("must not contain `;`"),
5863            "reason must surface the shell-command-separator arm, got {reason:?}"
5864        );
5865        assert!(
5866            reason.contains("sequential-command") || reason.contains("'sub-delims'"),
5867            "reason must name the shell-command-separator / RFC-3986-sub-delims \
5868             rationale, got {reason:?}"
5869        );
5870    }
5871
5872    #[test]
5873    fn fonte_repo_fragment_fires_before_semicolon_when_fragment_first() {
5874        // Cascade pin: the fragment-`#` arm and the semicolon arm are
5875        // both per-byte arms inside the same `for &b in s.as_bytes()`
5876        // loop, so the byte that appears first in the value's byte
5877        // order wins. A `:repo "https://github.com/p/x#readme; rm"`
5878        // carries both `#` and `;`; the `#` byte appears first, so the
5879        // fragment-`#` arm fires, surfacing the more self-locating
5880        // diagnostic on the byte the author pasted earliest in the URL.
5881        // Mirrors the peer cascade discipline
5882        // `fonte_repo_fragment_fires_before_pipe_when_fragment_first`
5883        // pins on the prior `:repo` byte-class arm.
5884        let d = dep_with_fonte(DepSource::Git {
5885            repo: "https://github.com/pleme-io/caixa-teia#readme; rm".into(),
5886            tag: Some("v0.1.0".into()),
5887            rev: None,
5888            branch: None,
5889        });
5890        let err = d.validate().unwrap_err();
5891        let DepError::FonteRepoShape { reason, .. } = err else {
5892            panic!("expected FonteRepoShape, got other variant");
5893        };
5894        assert!(
5895            reason.contains("must not contain `#`"),
5896            "reason must surface the fragment-`#` arm (fires before semicolon when `#` \
5897             byte appears first in value), got {reason:?}"
5898        );
5899    }
5900
5901    #[test]
5902    fn fonte_repo_pipe_fires_before_semicolon_when_pipe_first() {
5903        // Cascade pin: the pipe arm and the semicolon arm are both
5904        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5905        // so the byte that appears first in the value's byte order
5906        // wins. A `:repo "https://github.com/p/x|tee; rm"` carries
5907        // both `|` and `;`; the `|` byte appears first, so the
5908        // pipe arm fires, surfacing the more self-locating diagnostic
5909        // on the byte the author pasted earliest in the URL. Pins the
5910        // natural-order cascade so a future reorder of the per-byte
5911        // arms surfaces here.
5912        let d = dep_with_fonte(DepSource::Git {
5913            repo: "https://github.com/pleme-io/caixa-teia|tee; rm".into(),
5914            tag: Some("v0.1.0".into()),
5915            rev: None,
5916            branch: None,
5917        });
5918        let err = d.validate().unwrap_err();
5919        let DepError::FonteRepoShape { reason, .. } = err else {
5920            panic!("expected FonteRepoShape, got other variant");
5921        };
5922        assert!(
5923            reason.contains("must not contain `|`"),
5924            "reason must surface the pipe arm (fires before semicolon when `|` byte \
5925             appears first in value), got {reason:?}"
5926        );
5927    }
5928
5929    #[test]
5930    fn validate_rejects_git_fonte_with_repo_carrying_shell_background() {
5931        // The fail-before-pass-after pin for the canonical
5932        // paste-from-shell-prompt-with-background-launch-tail footgun
5933        // on `:repo` (peer with the e12e4f3 `&` arm on the sibling
5934        // `:caminho` path-fonte axis). An author pastes a shell one-
5935        // liner that detached the clone into the background
5936        // (`git clone <url> & sleep 1`, `git clone <url> && cd …`)
5937        // into the `:repo` slot, forgetting to trim the `& <cmd>` /
5938        // `&& <cmd>` tail. Until this arm landed the value silently
5939        // passed every prior `is_git_repo_url` arm (no whitespace,
5940        // no control chars, no non-ASCII, no `#`, no `?`, no `\`,
5941        // no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
5942        // doesn't start with `-` or `:`); RFC 3986 §2 lists `&` in
5943        // the 'sub-delims' / reserved set and the WHATWG URL spec's
5944        // fragment percent-encode set maps `&` → `%26` on the wire,
5945        // so the byte rides verbatim into the lacre's per-dep
5946        // BLAKE3 closure but is silently rewritten at libcurl's
5947        // URL-parser layer — two authors whose values differ only
5948        // in their background-launch tail (`& sleep 1` vs nothing)
5949        // resolve to the byte-identical upstream `git clone` but
5950        // lock to two distinct lacres, defeating the THEORY.md
5951        // §V.2 render-determinism contract. Peer with the
5952        // `:caminho` axis's `FonteCaminhoShellBackground` arm
5953        // (e12e4f3) on the sibling path-fonte axis, and
5954        // `is_gateway_api_http_path`'s eleven-byte RFC-3986-
5955        // reserved set on `:entrada :paths`.
5956        let d = dep_with_fonte(DepSource::Git {
5957            repo: "https://github.com/pleme-io/caixa-teia&sleep".into(),
5958            tag: Some("v0.1.0".into()),
5959            rev: None,
5960            branch: None,
5961        });
5962        let err = d.validate().unwrap_err();
5963        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5964            panic!("expected FonteRepoShape, got other variant");
5965        };
5966        assert_eq!(nome, "caixa-teia");
5967        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia&sleep");
5968        assert!(
5969            reason.contains("must not contain `&`"),
5970            "reason must surface the shell-background / logical-AND arm, got {reason:?}"
5971        );
5972        assert!(
5973            reason.contains("background-task") || reason.contains("'sub-delims'"),
5974            "reason must name the shell-background / RFC-3986-sub-delims rationale, \
5975             got {reason:?}"
5976        );
5977    }
5978
5979    #[test]
5980    fn validate_rejects_git_fonte_with_repo_carrying_logical_and() {
5981        // The fail-before-pass-after pin for the symmetric `&&`
5982        // logical-AND build-chain paste footgun: an author pastes
5983        // a `git clone <url> && cd <repo>` build-chain one-liner
5984        // and forgets to trim the `&& <cmd>` tail. The `&&` shape
5985        // is the same `&` byte twice in a row; the per-byte arm
5986        // fires on the first `&` it sees. Pinned separately from
5987        // the single-`&` background-launch shape so a future
5988        // diagnostic-surface change that special-cased the
5989        // doubled-byte form surfaces here.
5990        let d = dep_with_fonte(DepSource::Git {
5991            repo: "github:pleme-io/caixa-teia&&echo".into(),
5992            tag: Some("v0.1.0".into()),
5993            rev: None,
5994            branch: None,
5995        });
5996        let err = d.validate().unwrap_err();
5997        let DepError::FonteRepoShape { reason, .. } = err else {
5998            panic!("expected FonteRepoShape, got other variant");
5999        };
6000        assert!(
6001            reason.contains("must not contain `&`"),
6002            "reason must surface the shell-background / logical-AND arm on the doubled-`&&` \
6003             shape too, got {reason:?}"
6004        );
6005    }
6006
6007    #[test]
6008    fn fonte_repo_fragment_fires_before_background_when_fragment_first() {
6009        // Cascade pin: the fragment-`#` arm and the background-`&`
6010        // arm are both per-byte arms inside the same `for &b in
6011        // s.as_bytes()` loop, so the byte that appears first in the
6012        // value's byte order wins. A `:repo
6013        // "https://github.com/p/x#readme & sleep"` carries both `#`
6014        // and `&`; the `#` byte appears first, so the fragment-`#`
6015        // arm fires, surfacing the more self-locating diagnostic on
6016        // the byte the author pasted earliest in the URL. Mirrors
6017        // the peer cascade discipline
6018        // `fonte_repo_fragment_fires_before_semicolon_when_fragment_first`
6019        // on the prior `:repo` byte-class arm.
6020        let d = dep_with_fonte(DepSource::Git {
6021            repo: "https://github.com/pleme-io/caixa-teia#readme&sleep".into(),
6022            tag: Some("v0.1.0".into()),
6023            rev: None,
6024            branch: None,
6025        });
6026        let err = d.validate().unwrap_err();
6027        let DepError::FonteRepoShape { reason, .. } = err else {
6028            panic!("expected FonteRepoShape, got other variant");
6029        };
6030        assert!(
6031            reason.contains("must not contain `#`"),
6032            "reason must surface the fragment-`#` arm (fires before background-`&` when `#` \
6033             byte appears first in value), got {reason:?}"
6034        );
6035    }
6036
6037    #[test]
6038    fn fonte_repo_semicolon_fires_before_background_when_semicolon_first() {
6039        // Cascade pin: the semicolon arm and the background-`&` arm
6040        // are both per-byte arms inside the same `for &b in
6041        // s.as_bytes()` loop, so the byte that appears first in the
6042        // value's byte order wins. A `:repo
6043        // "https://github.com/p/x; rm & sleep"` carries both `;` and
6044        // `&`; the `;` byte appears first, so the semicolon arm
6045        // fires, surfacing the more self-locating diagnostic on the
6046        // byte the author pasted earliest in the URL. Pins the
6047        // natural-order cascade so a future reorder of the per-byte
6048        // arms surfaces here.
6049        let d = dep_with_fonte(DepSource::Git {
6050            repo: "https://github.com/pleme-io/caixa-teia;rm&sleep".into(),
6051            tag: Some("v0.1.0".into()),
6052            rev: None,
6053            branch: None,
6054        });
6055        let err = d.validate().unwrap_err();
6056        let DepError::FonteRepoShape { reason, .. } = err else {
6057            panic!("expected FonteRepoShape, got other variant");
6058        };
6059        assert!(
6060            reason.contains("must not contain `;`"),
6061            "reason must surface the semicolon arm (fires before background-`&` when `;` \
6062             byte appears first in value), got {reason:?}"
6063        );
6064    }
6065
6066    #[test]
6067    fn validate_rejects_git_fonte_with_repo_carrying_shell_variable_expansion() {
6068        // The fail-before-pass-after pin for the canonical
6069        // paste-from-shell-prompt-with-unsubstituted-variable footgun
6070        // on `:repo` (peer with the f4efe9c `$` arm on the sibling
6071        // `:caminho` path-fonte axis). An author pastes a shell one-
6072        // liner that referenced an environment variable
6073        // (`git clone https://github.com/$ORG/x`, `git clone
6074        // github:$USER/repo`) into the `:repo` slot, forgetting to
6075        // substitute the literal value at author time. Until this arm
6076        // landed the value silently passed every prior
6077        // `is_git_repo_url` arm (no whitespace, no control chars, no
6078        // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6079        // no `` ` ``, no `|`, no `;`, no `&`, doesn't start with `-`
6080        // or `:`); RFC 3986 §2 lists `$` in the 'sub-delims' /
6081        // reserved set and the WHATWG URL spec's fragment percent-
6082        // encode set maps `$` → `%24` on the wire, so the byte rides
6083        // verbatim into the lacre's per-dep BLAKE3 closure but is
6084        // silently rewritten at libcurl's URL-parser layer — two
6085        // authors whose values differ only in their `$VAR` /
6086        // `${VAR}` / `$(cmd)` expansion tail resolve to the byte-
6087        // identical upstream `git clone` but lock to two distinct
6088        // lacres, defeating the THEORY.md §V.2 render-determinism
6089        // contract. Beyond determinism, the value is a structural
6090        // host-layout leak: two authors with the same `:repo` slot
6091        // but different `$ORG` / `$HOME` / `$WORKSPACE` resolve
6092        // different upstreams. Peer with the `:caminho` axis's
6093        // `FonteCaminhoVarExpansion` arm (f4efe9c) on the sibling
6094        // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
6095        // byte RFC-3986-reserved set on `:entrada :paths`.
6096        let d = dep_with_fonte(DepSource::Git {
6097            repo: "https://github.com/$ORG/caixa-teia".into(),
6098            tag: Some("v0.1.0".into()),
6099            rev: None,
6100            branch: None,
6101        });
6102        let err = d.validate().unwrap_err();
6103        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6104            panic!("expected FonteRepoShape, got other variant");
6105        };
6106        assert_eq!(nome, "caixa-teia");
6107        assert_eq!(repo, "https://github.com/$ORG/caixa-teia");
6108        assert!(
6109            reason.contains("must not contain `$`"),
6110            "reason must surface the shell-variable-expansion arm, got {reason:?}"
6111        );
6112        assert!(
6113            reason.contains("variable-expansion") || reason.contains("'sub-delims'"),
6114            "reason must name the shell-variable-expansion / RFC-3986-sub-delims \
6115             rationale, got {reason:?}"
6116        );
6117    }
6118
6119    #[test]
6120    fn validate_rejects_git_fonte_with_repo_carrying_braced_variable_expansion() {
6121        // The fail-before-pass-after pin for the symmetric POSIX-
6122        // shell braced `${VAR}` expansion paste footgun: an author
6123        // pastes a CI-manifest line `git clone
6124        // https://github.com/${WORKSPACE}/x` (the canonical GitHub
6125        // Actions / GitLab CI / Drone shape) and forgets to
6126        // substitute the literal value. The `${...}` shape is the
6127        // same `$` byte at the leading position of the expansion;
6128        // the per-byte arm fires on the `$`. Pinned separately from
6129        // the bare-`$VAR` shape so a future diagnostic-surface
6130        // change that special-cased the braced form surfaces here.
6131        let d = dep_with_fonte(DepSource::Git {
6132            repo: "https://github.com/${WORKSPACE}/caixa-teia".into(),
6133            tag: Some("v0.1.0".into()),
6134            rev: None,
6135            branch: None,
6136        });
6137        let err = d.validate().unwrap_err();
6138        let DepError::FonteRepoShape { reason, .. } = err else {
6139            panic!("expected FonteRepoShape, got other variant");
6140        };
6141        assert!(
6142            reason.contains("must not contain `$`"),
6143            "reason must surface the shell-variable-expansion arm on the braced `${{...}}` \
6144             shape too, got {reason:?}"
6145        );
6146    }
6147
6148    #[test]
6149    fn fonte_repo_fragment_fires_before_var_expansion_when_fragment_first() {
6150        // Cascade pin: the fragment-`#` arm and the var-expansion-`$`
6151        // arm are both per-byte arms inside the same `for &b in
6152        // s.as_bytes()` loop, so the byte that appears first in the
6153        // value's byte order wins. A `:repo
6154        // "https://github.com/p/x#readme$HOME"` carries both `#` and
6155        // `$`; the `#` byte appears first, so the fragment-`#` arm
6156        // fires, surfacing the more self-locating diagnostic on the
6157        // byte the author pasted earliest in the URL. Mirrors the
6158        // peer cascade discipline
6159        // `fonte_repo_fragment_fires_before_background_when_fragment_first`
6160        // on the prior `:repo` byte-class arm.
6161        let d = dep_with_fonte(DepSource::Git {
6162            repo: "https://github.com/pleme-io/caixa-teia#readme$HOME".into(),
6163            tag: Some("v0.1.0".into()),
6164            rev: None,
6165            branch: None,
6166        });
6167        let err = d.validate().unwrap_err();
6168        let DepError::FonteRepoShape { reason, .. } = err else {
6169            panic!("expected FonteRepoShape, got other variant");
6170        };
6171        assert!(
6172            reason.contains("must not contain `#`"),
6173            "reason must surface the fragment-`#` arm (fires before var-expansion-`$` when \
6174             `#` byte appears first in value), got {reason:?}"
6175        );
6176    }
6177
6178    #[test]
6179    fn fonte_repo_background_fires_before_var_expansion_when_background_first() {
6180        // Cascade pin: the background-`&` arm and the
6181        // var-expansion-`$` arm are both per-byte arms inside the
6182        // same `for &b in s.as_bytes()` loop, so the byte that
6183        // appears first in the value's byte order wins. A `:repo
6184        // "https://github.com/p/x&sleep$HOME"` carries both `&` and
6185        // `$`; the `&` byte appears first, so the background arm
6186        // fires, surfacing the more self-locating diagnostic on the
6187        // byte the author pasted earliest in the URL. Pins the
6188        // natural-order cascade so a future reorder of the per-byte
6189        // arms surfaces here — `$` is the most recent byte-class arm,
6190        // so the cascade-pin sweep extends to cover every immediately
6191        // prior byte arm (`#`, `&`) firing first when ordered ahead
6192        // of `$` in the value.
6193        let d = dep_with_fonte(DepSource::Git {
6194            repo: "https://github.com/pleme-io/caixa-teia&sleep$HOME".into(),
6195            tag: Some("v0.1.0".into()),
6196            rev: None,
6197            branch: None,
6198        });
6199        let err = d.validate().unwrap_err();
6200        let DepError::FonteRepoShape { reason, .. } = err else {
6201            panic!("expected FonteRepoShape, got other variant");
6202        };
6203        assert!(
6204            reason.contains("must not contain `&`"),
6205            "reason must surface the background-`&` arm (fires before var-expansion-`$` when \
6206             `&` byte appears first in value), got {reason:?}"
6207        );
6208    }
6209
6210    #[test]
6211    fn validate_rejects_git_fonte_with_repo_carrying_shell_glob_wildcard() {
6212        // The fail-before-pass-after pin for the canonical
6213        // paste-from-shell-prompt glob footgun on `:repo` (peer with
6214        // the cf9034b `*` / `?` arm on the sibling `:caminho`
6215        // path-fonte axis). An author pastes a shell one-liner that
6216        // referenced a glob expansion (`ls
6217        // github.com/pleme-io/caixa-*`, `git clone
6218        // github:pleme-io/caixa-*`) into the `:repo` slot, forgetting
6219        // to substitute the literal repo name. Until this arm landed
6220        // the `*` byte silently passed every prior `is_git_repo_url`
6221        // arm (no whitespace, no control chars, no non-ASCII, no `#`,
6222        // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`,
6223        // no `;`, no `&`, no `$`, doesn't start with `-` or `:`); RFC
6224        // 3986 §2 lists `*` in the 'sub-delims' / reserved set and
6225        // the WHATWG URL spec's special-query percent-encode set maps
6226        // `*` → `%2A` on the wire, so the byte rides verbatim into
6227        // the lacre's per-dep BLAKE3 closure but is silently
6228        // rewritten at libcurl's URL-parser layer — two authors
6229        // whose values differ only in their asterisk presence
6230        // resolve to the byte-identical upstream `git clone` but
6231        // lock to two distinct lacres, defeating the THEORY.md §V.2
6232        // render-determinism contract. Peer with the `:caminho`
6233        // axis's `FonteCaminhoShellGlob` arm (cf9034b) on the
6234        // sibling path-fonte axis, and the `is_git_ref_name`
6235        // refspec-wildcard cascade on the `:fonte :tag` / `:branch`
6236        // axes.
6237        let d = dep_with_fonte(DepSource::Git {
6238            repo: "https://github.com/pleme-io/caixa-*".into(),
6239            tag: Some("v0.1.0".into()),
6240            rev: None,
6241            branch: None,
6242        });
6243        let err = d.validate().unwrap_err();
6244        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6245            panic!("expected FonteRepoShape, got other variant");
6246        };
6247        assert_eq!(nome, "caixa-teia");
6248        assert_eq!(repo, "https://github.com/pleme-io/caixa-*");
6249        assert!(
6250            reason.contains("must not contain `*`"),
6251            "reason must surface the shell-glob arm, got {reason:?}"
6252        );
6253        assert!(
6254            reason.contains("pathname-expansion") || reason.contains("'sub-delims'"),
6255            "reason must name the shell-glob / pathname-expansion / \
6256             RFC-3986-sub-delims rationale, got {reason:?}"
6257        );
6258    }
6259
6260    #[test]
6261    fn validate_rejects_git_fonte_with_repo_carrying_recursive_shell_glob() {
6262        // The fail-before-pass-after pin for the symmetric bash
6263        // `globstar` recursive-glob paste footgun: an author pastes
6264        // a `ls github.com/pleme-io/**/x` (the canonical
6265        // `globstar`-shopt-enabled recursive-listing tail) into the
6266        // `:repo` slot. The `**` shape is two `*` bytes adjacent;
6267        // the per-byte arm fires on the first `*`. Pinned
6268        // separately from the single-`*` shape so a future
6269        // diagnostic-surface change that special-cased the
6270        // double-`*` form surfaces here.
6271        let d = dep_with_fonte(DepSource::Git {
6272            repo: "https://github.com/pleme-io/**/caixa-teia".into(),
6273            tag: Some("v0.1.0".into()),
6274            rev: None,
6275            branch: None,
6276        });
6277        let err = d.validate().unwrap_err();
6278        let DepError::FonteRepoShape { reason, .. } = err else {
6279            panic!("expected FonteRepoShape, got other variant");
6280        };
6281        assert!(
6282            reason.contains("must not contain `*`"),
6283            "reason must surface the shell-glob arm on the `**` recursive-glob shape too, \
6284             got {reason:?}"
6285        );
6286    }
6287
6288    #[test]
6289    fn fonte_repo_fragment_fires_before_glob_when_fragment_first() {
6290        // Cascade pin: the fragment-`#` arm and the glob-`*` arm are
6291        // both per-byte arms inside the same `for &b in s.as_bytes()`
6292        // loop, so the byte that appears first in the value's byte
6293        // order wins. A `:repo
6294        // "https://github.com/p/x#readme*tail"` carries both `#` and
6295        // `*`; the `#` byte appears first, so the fragment-`#` arm
6296        // fires, surfacing the more self-locating diagnostic on the
6297        // byte the author pasted earliest in the URL. Mirrors the
6298        // peer cascade discipline
6299        // `fonte_repo_fragment_fires_before_var_expansion_when_fragment_first`
6300        // on the prior `:repo` byte-class arm.
6301        let d = dep_with_fonte(DepSource::Git {
6302            repo: "https://github.com/pleme-io/caixa-teia#readme*tail".into(),
6303            tag: Some("v0.1.0".into()),
6304            rev: None,
6305            branch: None,
6306        });
6307        let err = d.validate().unwrap_err();
6308        let DepError::FonteRepoShape { reason, .. } = err else {
6309            panic!("expected FonteRepoShape, got other variant");
6310        };
6311        assert!(
6312            reason.contains("must not contain `#`"),
6313            "reason must surface the fragment-`#` arm (fires before glob-`*` when `#` byte \
6314             appears first in value), got {reason:?}"
6315        );
6316    }
6317
6318    #[test]
6319    fn fonte_repo_var_expansion_fires_before_glob_when_var_expansion_first() {
6320        // Cascade pin: the var-expansion-`$` arm and the glob-`*`
6321        // arm are both per-byte arms inside the same `for &b in
6322        // s.as_bytes()` loop, so the byte that appears first in the
6323        // value's byte order wins. A `:repo
6324        // "https://github.com/p/$ORG-*"` carries both `$` and `*`;
6325        // the `$` byte appears first, so the var-expansion arm
6326        // fires, surfacing the more self-locating diagnostic on the
6327        // byte the author pasted earliest in the URL. Pins the
6328        // natural-order cascade so a future reorder of the per-byte
6329        // arms surfaces here — `*` is the most recent byte-class
6330        // arm, so the cascade-pin sweep extends to cover the
6331        // immediately prior `$` byte arm firing first when ordered
6332        // ahead of `*` in the value.
6333        let d = dep_with_fonte(DepSource::Git {
6334            repo: "https://github.com/pleme-io/$ORG-caixa-*".into(),
6335            tag: Some("v0.1.0".into()),
6336            rev: None,
6337            branch: None,
6338        });
6339        let err = d.validate().unwrap_err();
6340        let DepError::FonteRepoShape { reason, .. } = err else {
6341            panic!("expected FonteRepoShape, got other variant");
6342        };
6343        assert!(
6344            reason.contains("must not contain `$`"),
6345            "reason must surface the var-expansion-`$` arm (fires before glob-`*` when `$` \
6346             byte appears first in value), got {reason:?}"
6347        );
6348    }
6349
6350    #[test]
6351    fn validate_rejects_git_fonte_with_repo_carrying_subshell_open_paren() {
6352        // The fail-before-pass-after pin for the canonical paste-from-
6353        // shell-prompt subshell-grouping footgun on `:repo`. An author
6354        // pastes a doc / README snippet carrying a regex-alternation
6355        // grouping shape (`https://github.com/(foo|bar)/repo`) or a
6356        // dynamic-config-substitution wrapper (`$(<cmd>)`) into the
6357        // `:repo` slot, forgetting to substitute one literal org name.
6358        // Until this arm landed the `(` byte silently passed every
6359        // prior `is_git_repo_url` arm (no whitespace, no control
6360        // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6361        // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no
6362        // `*`, doesn't start with `-` or `:`); RFC 3986 §2 lists `(`
6363        // / `)` in the 'sub-delims' / reserved set, and the WHATWG
6364        // URL spec's special-query percent-encode set maps `(` →
6365        // `%28` and `)` → `%29` on the wire, so the byte rides
6366        // verbatim into the lacre's per-dep BLAKE3 closure but is
6367        // silently rewritten at libcurl's URL-parser layer —
6368        // defeating the THEORY.md §V.2 render-determinism contract on
6369        // the same axis the prior twelve byte-class arms close.
6370        let d = dep_with_fonte(DepSource::Git {
6371            repo: "https://github.com/(foo|bar)/caixa-teia".into(),
6372            tag: Some("v0.1.0".into()),
6373            rev: None,
6374            branch: None,
6375        });
6376        let err = d.validate().unwrap_err();
6377        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6378            panic!("expected FonteRepoShape, got other variant");
6379        };
6380        assert_eq!(nome, "caixa-teia");
6381        assert_eq!(repo, "https://github.com/(foo|bar)/caixa-teia");
6382        assert!(
6383            reason.contains("must not contain `(`"),
6384            "reason must surface the subshell-open-paren arm, got {reason:?}"
6385        );
6386        assert!(
6387            reason.contains("subshell-grouping") || reason.contains("'sub-delims'"),
6388            "reason must name the shell-subshell-grouping / RFC-3986-sub-delims rationale, \
6389             got {reason:?}"
6390        );
6391    }
6392
6393    #[test]
6394    fn validate_rejects_git_fonte_with_repo_carrying_subshell_close_paren() {
6395        // The symmetric arm pin on the closing `)` byte: an author
6396        // pastes a `$(date)` command-substitution wrapper or a
6397        // regex-alternation `(foo|bar)` tail into the `:repo` slot.
6398        // Pinned separately from the opening `(` shape so a future
6399        // diagnostic-surface change that only checked one boundary
6400        // surfaces here. The `(` byte appears earlier in the
6401        // canonical regex / subshell wrapper so the per-byte loop
6402        // fires on `(` first; this test exercises a `:repo` value
6403        // carrying only the closing `)` byte (no opening paren) so
6404        // the `)` arm fires directly — pinning the byte-class arm
6405        // independent of order.
6406        let d = dep_with_fonte(DepSource::Git {
6407            repo: "github:pleme-io/caixa-teia)tail".into(),
6408            tag: Some("v0.1.0".into()),
6409            rev: None,
6410            branch: None,
6411        });
6412        let err = d.validate().unwrap_err();
6413        let DepError::FonteRepoShape { reason, .. } = err else {
6414            panic!("expected FonteRepoShape, got other variant");
6415        };
6416        assert!(
6417            reason.contains("must not contain `)`"),
6418            "reason must surface the subshell-close-paren arm on the bare `)` shape, \
6419             got {reason:?}"
6420        );
6421    }
6422
6423    #[test]
6424    fn fonte_repo_fragment_fires_before_subshell_when_fragment_first() {
6425        // Cascade pin: the fragment-`#` arm and the subshell-`(` arm
6426        // are both per-byte arms inside the same `for &b in
6427        // s.as_bytes()` loop, so the byte that appears first in the
6428        // value's byte order wins. A `:repo
6429        // "https://github.com/p/x#readme(tail)"` carries both `#` and
6430        // `(`; the `#` byte appears first, so the fragment-`#` arm
6431        // fires, surfacing the more self-locating diagnostic on the
6432        // byte the author pasted earliest in the URL. Mirrors the
6433        // peer cascade discipline
6434        // `fonte_repo_fragment_fires_before_glob_when_fragment_first`
6435        // on the prior `:repo` byte-class arm.
6436        let d = dep_with_fonte(DepSource::Git {
6437            repo: "https://github.com/pleme-io/caixa-teia#readme(tail)".into(),
6438            tag: Some("v0.1.0".into()),
6439            rev: None,
6440            branch: None,
6441        });
6442        let err = d.validate().unwrap_err();
6443        let DepError::FonteRepoShape { reason, .. } = err else {
6444            panic!("expected FonteRepoShape, got other variant");
6445        };
6446        assert!(
6447            reason.contains("must not contain `#`"),
6448            "reason must surface the fragment-`#` arm (fires before subshell-`(` when `#` \
6449             byte appears first in value), got {reason:?}"
6450        );
6451    }
6452
6453    #[test]
6454    fn fonte_repo_glob_fires_before_subshell_when_glob_first() {
6455        // Cascade pin: the glob-`*` arm (the immediate-predecessor
6456        // byte-class arm, 3902a9a) and the subshell-`(` arm are both
6457        // per-byte arms inside the same `for &b in s.as_bytes()`
6458        // loop, so the byte that appears first in the value's byte
6459        // order wins. A `:repo
6460        // "https://github.com/p/x-*-(date)"` carries both `*` and
6461        // `(`; the `*` byte appears first, so the glob arm fires,
6462        // surfacing the more self-locating diagnostic on the byte
6463        // the author pasted earliest in the URL. Pins the natural-
6464        // order cascade so a future reorder of the per-byte arms
6465        // surfaces here — `(` is the most recent byte-class arm,
6466        // so the cascade-pin sweep extends to cover the immediately
6467        // prior `*` byte arm firing first when ordered ahead of `(`
6468        // in the value.
6469        let d = dep_with_fonte(DepSource::Git {
6470            repo: "https://github.com/pleme-io/caixa-teia-*-(date)".into(),
6471            tag: Some("v0.1.0".into()),
6472            rev: None,
6473            branch: None,
6474        });
6475        let err = d.validate().unwrap_err();
6476        let DepError::FonteRepoShape { reason, .. } = err else {
6477            panic!("expected FonteRepoShape, got other variant");
6478        };
6479        assert!(
6480            reason.contains("must not contain `*`"),
6481            "reason must surface the glob-`*` arm (fires before subshell-`(` when `*` byte \
6482             appears first in value), got {reason:?}"
6483        );
6484    }
6485
6486    #[test]
6487    fn validate_rejects_git_fonte_with_repo_carrying_shell_double_quote() {
6488        // The fail-before-pass-after pin for the canonical paste-from-
6489        // doc-shell-quoting footgun on `:repo`. An author copies a
6490        // README quick-start snippet (`$ git clone "https://github.com/
6491        // foo/bar"`) and keeps the surrounding double-quote bytes when
6492        // pasting into the `:repo` slot — the doc wraps the URL in
6493        // double quotes so the shell doesn't re-lex metachars inside,
6494        // but the typed slot is itself a byte-level string parser, not
6495        // a shell context, so the quote bytes ride into the value
6496        // verbatim. Until this arm landed the `"` byte silently passed
6497        // every prior `is_git_repo_url` arm (no whitespace, no control
6498        // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6499        // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`,
6500        // no `(`/`)`, doesn't start with `-` or `:`); RFC 3986 §2 lists
6501        // `"` in the strict four-byte 'delims' subset (with `<`, `>`,
6502        // `` ` ``) every URL parser is required to refuse or percent-
6503        // encode, and the WHATWG URL spec's 'C0 control percent-encode
6504        // set' maps `"` → `%22` on the wire, so the byte rides verbatim
6505        // into the lacre's per-dep BLAKE3 closure but is silently
6506        // rewritten at libcurl's URL-parser layer, defeating the
6507        // THEORY.md §V.2 render-determinism contract.
6508        let d = dep_with_fonte(DepSource::Git {
6509            repo: "\"https://github.com/pleme-io/caixa-teia\"".into(),
6510            tag: Some("v0.1.0".into()),
6511            rev: None,
6512            branch: None,
6513        });
6514        let err = d.validate().unwrap_err();
6515        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6516            panic!("expected FonteRepoShape, got other variant");
6517        };
6518        assert_eq!(nome, "caixa-teia");
6519        assert_eq!(repo, "\"https://github.com/pleme-io/caixa-teia\"");
6520        assert!(
6521            reason.contains("must not contain `\"`"),
6522            "reason must surface the shell-double-quote arm, got {reason:?}"
6523        );
6524        assert!(
6525            reason.contains("double-quote") || reason.contains("'delims'"),
6526            "reason must name the shell-double-quote / RFC-3986-delims rationale, \
6527             got {reason:?}"
6528        );
6529    }
6530
6531    #[test]
6532    fn validate_rejects_git_fonte_with_repo_carrying_stray_trailing_double_quote() {
6533        // The symmetric stray-quote tail pin: an author pastes only a
6534        // closing `"` from a shell-history line like `git clone
6535        // "https://github.com/foo/bar" && cd …` (the trim went too
6536        // far in one direction but not the other) into the `:repo`
6537        // slot. Pinned separately from the wrapped-quote shape so a
6538        // future diagnostic-surface change that only checked one
6539        // boundary (only leading, only trailing, only paired) surfaces
6540        // here — the per-byte arm fires anywhere `"` appears.
6541        let d = dep_with_fonte(DepSource::Git {
6542            repo: "github:pleme-io/caixa-teia\"".into(),
6543            tag: Some("v0.1.0".into()),
6544            rev: None,
6545            branch: None,
6546        });
6547        let err = d.validate().unwrap_err();
6548        let DepError::FonteRepoShape { reason, .. } = err else {
6549            panic!("expected FonteRepoShape, got other variant");
6550        };
6551        assert!(
6552            reason.contains("must not contain `\"`"),
6553            "reason must surface the shell-double-quote arm on the trailing-`\"` shape, \
6554             got {reason:?}"
6555        );
6556    }
6557
6558    #[test]
6559    fn fonte_repo_fragment_fires_before_double_quote_when_fragment_first() {
6560        // Cascade pin: the fragment-`#` arm and the double-quote arm
6561        // are both per-byte arms inside the same `for &b in
6562        // s.as_bytes()` loop, so the byte that appears first in the
6563        // value's byte order wins. A `:repo
6564        // "https://github.com/p/x#readme\"tail"` carries both `#` and
6565        // `"`; the `#` byte appears first, so the fragment-`#` arm
6566        // fires, surfacing the more self-locating diagnostic on the
6567        // byte the author pasted earliest in the URL.
6568        let d = dep_with_fonte(DepSource::Git {
6569            repo: "https://github.com/pleme-io/caixa-teia#readme\"tail".into(),
6570            tag: Some("v0.1.0".into()),
6571            rev: None,
6572            branch: None,
6573        });
6574        let err = d.validate().unwrap_err();
6575        let DepError::FonteRepoShape { reason, .. } = err else {
6576            panic!("expected FonteRepoShape, got other variant");
6577        };
6578        assert!(
6579            reason.contains("must not contain `#`"),
6580            "reason must surface the fragment-`#` arm (fires before double-quote when `#` \
6581             byte appears first in value), got {reason:?}"
6582        );
6583    }
6584
6585    #[test]
6586    fn fonte_repo_subshell_fires_before_double_quote_when_subshell_first() {
6587        // Cascade pin: the subshell-`(` arm (the immediate-predecessor
6588        // byte-class arm, 3b99147) and the double-quote arm are both
6589        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6590        // so the byte that appears first in the value's byte order
6591        // wins. A `:repo "github:p/x(date)\"tail"` carries both `(`
6592        // and `"`; the `(` byte appears first, so the subshell arm
6593        // fires, surfacing the more self-locating diagnostic on the
6594        // byte the author pasted earliest in the URL. Pins the natural-
6595        // order cascade so a future reorder of the per-byte arms
6596        // surfaces here — `"` is the most recent byte-class arm, so
6597        // the cascade-pin sweep extends to cover the immediately prior
6598        // `(` byte arm firing first when ordered ahead of `"` in the
6599        // value.
6600        let d = dep_with_fonte(DepSource::Git {
6601            repo: "github:pleme-io/caixa-teia(date)\"tail".into(),
6602            tag: Some("v0.1.0".into()),
6603            rev: None,
6604            branch: None,
6605        });
6606        let err = d.validate().unwrap_err();
6607        let DepError::FonteRepoShape { reason, .. } = err else {
6608            panic!("expected FonteRepoShape, got other variant");
6609        };
6610        assert!(
6611            reason.contains("must not contain `(`"),
6612            "reason must surface the subshell-`(` arm (fires before double-quote when `(` \
6613             byte appears first in value), got {reason:?}"
6614        );
6615    }
6616
6617    #[test]
6618    fn validate_rejects_git_fonte_with_repo_carrying_shell_single_quote() {
6619        // The fail-before-pass-after pin for the canonical paste-from-
6620        // doc-strong-quoting footgun on `:repo`. An author copies a
6621        // security-conscious README quick-start snippet (`$ git clone
6622        // 'https://github.com/foo/bar'`) and keeps the surrounding
6623        // single-quote bytes when pasting into the `:repo` slot — the
6624        // doc strong-quotes the URL so the shell suppresses every form
6625        // of expansion on the bytes inside (no `$`, no backtick, no
6626        // glob, no word-splitting), but the typed slot is itself a
6627        // byte-level string parser, not a shell context, so the quote
6628        // bytes ride into the value verbatim. Until this arm landed the
6629        // `'` byte silently passed every prior `is_git_repo_url` arm
6630        // (no whitespace, no control chars, no non-ASCII, no `#`, no
6631        // `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no
6632        // `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`, doesn't start
6633        // with `-` or `:`); RFC 3986 §2.2 lists `'` in the 'sub-delims'
6634        // set, peer with the `\"` 'delims' double-quote arm and the
6635        // partner ASCII shell-string-delimiter byte every byte-level
6636        // string parser sharing a value-shape with a shell argument
6637        // must refuse on a URL-shaped slot.
6638        let d = dep_with_fonte(DepSource::Git {
6639            repo: "'https://github.com/pleme-io/caixa-teia'".into(),
6640            tag: Some("v0.1.0".into()),
6641            rev: None,
6642            branch: None,
6643        });
6644        let err = d.validate().unwrap_err();
6645        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6646            panic!("expected FonteRepoShape, got other variant");
6647        };
6648        assert_eq!(nome, "caixa-teia");
6649        assert_eq!(repo, "'https://github.com/pleme-io/caixa-teia'");
6650        assert!(
6651            reason.contains("must not contain `'`"),
6652            "reason must surface the shell-single-quote arm, got {reason:?}"
6653        );
6654        assert!(
6655            reason.contains("single-quote") || reason.contains("strong-quote"),
6656            "reason must name the shell-single-quote / strong-quote rationale, \
6657             got {reason:?}"
6658        );
6659    }
6660
6661    #[test]
6662    fn validate_rejects_git_fonte_with_repo_carrying_english_apostrophe() {
6663        // The symmetric English-typography pin: an author writes
6664        // `:repo "github:p/repo's-fork"` (the possessive-form paste-
6665        // from-prose idiom every README / commit-message / chat-thread
6666        // reference to a repo carries) expecting the substrate to
6667        // coerce it to a kebab-case slug — but the byte rides into the
6668        // lacre verbatim. Pinned separately from the wrapped-quote
6669        // shape so a future diagnostic-surface change that only checked
6670        // the boundary positions (only leading, only trailing, only
6671        // paired) surfaces here — the per-byte arm fires anywhere `'`
6672        // appears in the value.
6673        let d = dep_with_fonte(DepSource::Git {
6674            repo: "github:pleme-io/repo's-fork".into(),
6675            tag: Some("v0.1.0".into()),
6676            rev: None,
6677            branch: None,
6678        });
6679        let err = d.validate().unwrap_err();
6680        let DepError::FonteRepoShape { reason, .. } = err else {
6681            panic!("expected FonteRepoShape, got other variant");
6682        };
6683        assert!(
6684            reason.contains("must not contain `'`"),
6685            "reason must surface the shell-single-quote arm on the mid-string \
6686             apostrophe shape, got {reason:?}"
6687        );
6688    }
6689
6690    #[test]
6691    fn fonte_repo_fragment_fires_before_single_quote_when_fragment_first() {
6692        // Cascade pin: the fragment-`#` arm and the single-quote arm
6693        // are both per-byte arms inside the same `for &b in
6694        // s.as_bytes()` loop, so the byte that appears first in the
6695        // value's byte order wins. A `:repo
6696        // "https://github.com/p/x#readme'tail"` carries both `#` and
6697        // `'`; the `#` byte appears first, so the fragment-`#` arm
6698        // fires, surfacing the more self-locating diagnostic on the
6699        // byte the author pasted earliest in the URL.
6700        let d = dep_with_fonte(DepSource::Git {
6701            repo: "https://github.com/pleme-io/caixa-teia#readme'tail".into(),
6702            tag: Some("v0.1.0".into()),
6703            rev: None,
6704            branch: None,
6705        });
6706        let err = d.validate().unwrap_err();
6707        let DepError::FonteRepoShape { reason, .. } = err else {
6708            panic!("expected FonteRepoShape, got other variant");
6709        };
6710        assert!(
6711            reason.contains("must not contain `#`"),
6712            "reason must surface the fragment-`#` arm (fires before single-quote when `#` \
6713             byte appears first in value), got {reason:?}"
6714        );
6715    }
6716
6717    #[test]
6718    fn fonte_repo_double_quote_fires_before_single_quote_when_double_quote_first() {
6719        // Cascade pin: the double-quote-`"` arm (the immediate-predecessor
6720        // byte-class arm, 4267d8b) and the single-quote arm are both
6721        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6722        // so the byte that appears first in the value's byte order
6723        // wins. A `:repo "github:p/x\"mid'tail"` carries both `"` and
6724        // `'`; the `"` byte appears first, so the double-quote arm
6725        // fires, surfacing the more self-locating diagnostic on the
6726        // byte the author pasted earliest in the URL. Pins the natural-
6727        // order cascade so a future reorder of the per-byte arms
6728        // surfaces here — `'` is the most recent byte-class arm, so
6729        // the cascade-pin sweep extends to cover the immediately prior
6730        // `"` byte arm firing first when ordered ahead of `'` in the
6731        // value.
6732        let d = dep_with_fonte(DepSource::Git {
6733            repo: "github:pleme-io/caixa-teia\"mid'tail".into(),
6734            tag: Some("v0.1.0".into()),
6735            rev: None,
6736            branch: None,
6737        });
6738        let err = d.validate().unwrap_err();
6739        let DepError::FonteRepoShape { reason, .. } = err else {
6740            panic!("expected FonteRepoShape, got other variant");
6741        };
6742        assert!(
6743            reason.contains("must not contain `\"`"),
6744            "reason must surface the double-quote arm (fires before single-quote when `\"` \
6745             byte appears first in value), got {reason:?}"
6746        );
6747    }
6748
6749    #[test]
6750    fn validate_rejects_git_fonte_with_repo_carrying_shell_history_expansion() {
6751        // The fail-before-pass-after pin for the canonical paste-from-
6752        // shell-history footgun on `:repo`. An author copies a `git
6753        // clone <url>!sudo make install` one-liner from a README's
6754        // quick-start snippet, intending the trailing `!sudo` as a
6755        // shell-history-expansion reference but the typed slot is itself
6756        // a byte-level string parser, not a shell context, so the byte
6757        // rides into the value verbatim. Until this arm landed the `!`
6758        // byte silently passed every prior `is_git_repo_url` arm (no
6759        // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
6760        // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6761        // no `&`, no `$`, no `*`, no `(`/`)`, no `"`, no `'`, doesn't
6762        // start with `-` or `:`); bash with the default `histexpand`
6763        // mode rewrites `!command` to the most recent history entry
6764        // beginning with `command`, the canonical RCE-class injection
6765        // vector when the byte rides into a shell argument.
6766        let d = dep_with_fonte(DepSource::Git {
6767            repo: "https://github.com/pleme-io/caixa-teia!sudo".into(),
6768            tag: Some("v0.1.0".into()),
6769            rev: None,
6770            branch: None,
6771        });
6772        let err = d.validate().unwrap_err();
6773        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6774            panic!("expected FonteRepoShape, got other variant");
6775        };
6776        assert_eq!(nome, "caixa-teia");
6777        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia!sudo");
6778        assert!(
6779            reason.contains("must not contain `!`"),
6780            "reason must surface the shell-history-expansion arm, got {reason:?}"
6781        );
6782        assert!(
6783            reason.contains("history-expansion") || reason.contains("bang"),
6784            "reason must name the shell-history-expansion / bang rationale, got {reason:?}"
6785        );
6786    }
6787
6788    #[test]
6789    fn validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference() {
6790        // The symmetric `!!` repeat-prior-command pin: an author paste-
6791        // trims a `git clone <url>` retry idiom from shell history that
6792        // expands to the previous command via `!!`. Pinned separately
6793        // from the wrapped `!command` shape so a future diagnostic-
6794        // surface change that only checked the leading or paired-bang
6795        // position surfaces here — the per-byte arm fires anywhere `!`
6796        // appears in the value.
6797        let d = dep_with_fonte(DepSource::Git {
6798            repo: "github:pleme-io/caixa-teia!!".into(),
6799            tag: Some("v0.1.0".into()),
6800            rev: None,
6801            branch: None,
6802        });
6803        let err = d.validate().unwrap_err();
6804        let DepError::FonteRepoShape { reason, .. } = err else {
6805            panic!("expected FonteRepoShape, got other variant");
6806        };
6807        assert!(
6808            reason.contains("must not contain `!`"),
6809            "reason must surface the shell-history-expansion arm on the trailing-`!!` shape, \
6810             got {reason:?}"
6811        );
6812    }
6813
6814    #[test]
6815    fn fonte_repo_fragment_fires_before_bang_when_fragment_first() {
6816        // Cascade pin: the fragment-`#` arm and the bang arm are both
6817        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6818        // so the byte that appears first in the value's byte order
6819        // wins. A `:repo "https://github.com/p/x#readme!tail"` carries
6820        // both `#` and `!`; the `#` byte appears first, so the
6821        // fragment-`#` arm fires, surfacing the more self-locating
6822        // diagnostic on the byte the author pasted earliest in the URL.
6823        let d = dep_with_fonte(DepSource::Git {
6824            repo: "https://github.com/pleme-io/caixa-teia#readme!tail".into(),
6825            tag: Some("v0.1.0".into()),
6826            rev: None,
6827            branch: None,
6828        });
6829        let err = d.validate().unwrap_err();
6830        let DepError::FonteRepoShape { reason, .. } = err else {
6831            panic!("expected FonteRepoShape, got other variant");
6832        };
6833        assert!(
6834            reason.contains("must not contain `#`"),
6835            "reason must surface the fragment-`#` arm (fires before bang when `#` byte \
6836             appears first in value), got {reason:?}"
6837        );
6838    }
6839
6840    #[test]
6841    fn fonte_repo_single_quote_fires_before_bang_when_single_quote_first() {
6842        // Cascade pin: the single-quote-`'` arm (the immediate-predecessor
6843        // byte-class arm, e7a109f) and the bang arm are both per-byte
6844        // arms inside the same `for &b in s.as_bytes()` loop, so the
6845        // byte that appears first in the value's byte order wins. A
6846        // `:repo "github:p/x'mid!tail"` carries both `'` and `!`; the
6847        // `'` byte appears first, so the single-quote arm fires,
6848        // surfacing the more self-locating diagnostic on the byte the
6849        // author pasted earliest in the URL. Pins the natural-order
6850        // cascade so a future reorder of the per-byte arms surfaces
6851        // here — `!` is the most recent byte-class arm, so the
6852        // cascade-pin sweep extends to cover the immediately prior `'`
6853        // byte arm firing first when ordered ahead of `!` in the value.
6854        let d = dep_with_fonte(DepSource::Git {
6855            repo: "github:pleme-io/caixa-teia'mid!tail".into(),
6856            tag: Some("v0.1.0".into()),
6857            rev: None,
6858            branch: None,
6859        });
6860        let err = d.validate().unwrap_err();
6861        let DepError::FonteRepoShape { reason, .. } = err else {
6862            panic!("expected FonteRepoShape, got other variant");
6863        };
6864        assert!(
6865            reason.contains("must not contain `'`"),
6866            "reason must surface the single-quote arm (fires before bang when `'` byte \
6867             appears first in value), got {reason:?}"
6868        );
6869    }
6870
6871    #[test]
6872    fn validate_rejects_git_fonte_with_repo_carrying_list_separator_comma() {
6873        // The fail-before-pass-after pin for the canonical
6874        // list-separator-belongs-to-list-grammar footgun on `:repo`.
6875        // An author copies a `git clone <a>, <b>, <c>` paste-from-CSV
6876        // one-liner from a multi-repo bootstrap doc, intending the
6877        // comma to separate multiple repo entries but the typed
6878        // `:repo` slot names *one* repo (the list-separator belongs
6879        // to the `:deps` list grammar, not to the value). Until this
6880        // arm landed the `,` byte silently passed every prior
6881        // `is_git_repo_url` arm (no whitespace, no control chars, no
6882        // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6883        // no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`, no
6884        // `(`/`)`, no `"`, no `'`, no `!`, doesn't start with `-` or
6885        // `:`); the byte rode into the lacre's per-dep content-
6886        // address and the resolver's `git clone <repo>` subprocess
6887        // invocation, where no host's repo registry resolved the
6888        // comma-bearing slug.
6889        let d = dep_with_fonte(DepSource::Git {
6890            repo: "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira".into(),
6891            tag: Some("v0.1.0".into()),
6892            rev: None,
6893            branch: None,
6894        });
6895        let err = d.validate().unwrap_err();
6896        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6897            panic!("expected FonteRepoShape, got other variant");
6898        };
6899        assert_eq!(nome, "caixa-teia");
6900        assert_eq!(
6901            repo,
6902            "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira"
6903        );
6904        assert!(
6905            reason.contains("must not contain `,`"),
6906            "reason must surface the list-separator-comma arm, got {reason:?}"
6907        );
6908        assert!(
6909            reason.contains("list-separator") || reason.contains("sub-delims"),
6910            "reason must name the list-separator / RFC-3986-sub-delims rationale, \
6911             got {reason:?}"
6912        );
6913    }
6914
6915    #[test]
6916    fn validate_rejects_git_fonte_with_repo_carrying_trailing_comma() {
6917        // The symmetric trailing-`,` paste-from-prose pin: an author
6918        // writes `:repo "github:pleme-io/caixa-feira,"` (the trailing
6919        // comma every README-prose list-of-projects sentence carries,
6920        // mistakenly retained when the slug is pasted mid-sentence)
6921        // expecting the substrate to coerce it to a kebab-case slug.
6922        // Pinned separately from the wrapped mid-token shape so a
6923        // future diagnostic-surface change that only checked the
6924        // leading or paired-comma position surfaces here — the
6925        // per-byte arm fires anywhere `,` appears in the value.
6926        let d = dep_with_fonte(DepSource::Git {
6927            repo: "github:pleme-io/caixa-feira,".into(),
6928            tag: Some("v0.1.0".into()),
6929            rev: None,
6930            branch: None,
6931        });
6932        let err = d.validate().unwrap_err();
6933        let DepError::FonteRepoShape { reason, .. } = err else {
6934            panic!("expected FonteRepoShape, got other variant");
6935        };
6936        assert!(
6937            reason.contains("must not contain `,`"),
6938            "reason must surface the list-separator-comma arm on the trailing-`,` shape, \
6939             got {reason:?}"
6940        );
6941    }
6942
6943    #[test]
6944    fn fonte_repo_fragment_fires_before_comma_when_fragment_first() {
6945        // Cascade pin: the fragment-`#` arm and the comma arm are
6946        // both per-byte arms inside the same `for &b in s.as_bytes()`
6947        // loop, so the byte that appears first in the value's byte
6948        // order wins. A `:repo "https://github.com/p/x#readme,tail"`
6949        // carries both `#` and `,`; the `#` byte appears first, so
6950        // the fragment-`#` arm fires, surfacing the more self-
6951        // locating diagnostic on the byte the author pasted earliest
6952        // in the URL.
6953        let d = dep_with_fonte(DepSource::Git {
6954            repo: "https://github.com/pleme-io/caixa-teia#readme,tail".into(),
6955            tag: Some("v0.1.0".into()),
6956            rev: None,
6957            branch: None,
6958        });
6959        let err = d.validate().unwrap_err();
6960        let DepError::FonteRepoShape { reason, .. } = err else {
6961            panic!("expected FonteRepoShape, got other variant");
6962        };
6963        assert!(
6964            reason.contains("must not contain `#`"),
6965            "reason must surface the fragment-`#` arm (fires before comma when `#` byte \
6966             appears first in value), got {reason:?}"
6967        );
6968    }
6969
6970    #[test]
6971    fn fonte_repo_bang_fires_before_comma_when_bang_first() {
6972        // Cascade pin: the bang-`!` arm (the immediate-predecessor
6973        // byte-class arm, 7d53c68) and the comma arm are both
6974        // per-byte arms inside the same `for &b in s.as_bytes()`
6975        // loop, so the byte that appears first in the value's byte
6976        // order wins. A `:repo "github:p/x!mid,tail"` carries both
6977        // `!` and `,`; the `!` byte appears first, so the bang arm
6978        // fires, surfacing the more self-locating diagnostic on the
6979        // byte the author pasted earliest in the URL. Pins the
6980        // natural-order cascade so a future reorder of the per-byte
6981        // arms surfaces here — `,` is the most recent byte-class
6982        // arm, so the cascade-pin sweep extends to cover the
6983        // immediately prior `!` byte arm firing first when ordered
6984        // ahead of `,` in the value.
6985        let d = dep_with_fonte(DepSource::Git {
6986            repo: "github:pleme-io/caixa-teia!mid,tail".into(),
6987            tag: Some("v0.1.0".into()),
6988            rev: None,
6989            branch: None,
6990        });
6991        let err = d.validate().unwrap_err();
6992        let DepError::FonteRepoShape { reason, .. } = err else {
6993            panic!("expected FonteRepoShape, got other variant");
6994        };
6995        assert!(
6996            reason.contains("must not contain `!`"),
6997            "reason must surface the bang arm (fires before comma when `!` byte \
6998             appears first in value), got {reason:?}"
6999        );
7000    }
7001
7002    #[test]
7003    fn validate_rejects_git_fonte_with_repo_carrying_shell_env_var_assignment() {
7004        // The fail-before-pass-after pin for the canonical
7005        // shell-env-var-assignment-belongs-to-shell-grammar footgun
7006        // on `:repo`. An author copies
7007        // `GIT_TERMINAL_PROMPT=0 git clone <url>` (or
7008        // `GIT_SSL_NO_VERIFY=1 git clone <url>`, `HTTPS_PROXY=…
7009        // git clone <url>`, etc. — the canonical
7010        // git-troubleshooting README idiom for a one-shot env-var
7011        // scoped to the `git clone` invocation) from a shell-prompt
7012        // one-liner, intending the `KEY=VALUE` prefix as a shell-
7013        // grammar env-var assignment but the typed `:repo` slot is
7014        // a value parser, not a shell context, so the bytes ride
7015        // into the value verbatim. Until this arm landed the `=`
7016        // byte silently passed every prior `is_git_repo_url` arm
7017        // (no whitespace, no control chars, no non-ASCII, no `#`,
7018        // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no
7019        // `|`, no `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`,
7020        // no `'`, no `!`, no `,`, doesn't start with `-` or `:`);
7021        // the byte rode into the lacre's per-dep content-address
7022        // and the resolver's `git clone <repo>` subprocess
7023        // invocation, where the upstream host's git porcelain
7024        // fetched a literal `GIT_TERMINAL_PROMPT=0 https://…`-shaped
7025        // path that no host's repo registry resolves.
7026        let d = dep_with_fonte(DepSource::Git {
7027            repo: "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia".into(),
7028            tag: Some("v0.1.0".into()),
7029            rev: None,
7030            branch: None,
7031        });
7032        let err = d.validate().unwrap_err();
7033        let DepError::FonteRepoShape { nome, repo, reason } = err else {
7034            panic!("expected FonteRepoShape, got other variant");
7035        };
7036        assert_eq!(nome, "caixa-teia");
7037        assert_eq!(
7038            repo,
7039            "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia"
7040        );
7041        // The `=` byte at position 19 of `GIT_TERMINAL_PROMPT=0 …`
7042        // appears before the ` ` byte at position 21, so the `=`
7043        // arm fires (not the whitespace arm) — both arms guard
7044        // the slot, but the per-byte for-loop scans left-to-right
7045        // and the first matching byte wins.
7046        assert!(
7047            reason.contains("must not contain `=`"),
7048            "reason must surface the equals-`=` arm on the env-var-assignment \
7049             paste shape, got {reason:?}"
7050        );
7051        assert!(
7052            reason.contains("env-var-assignment") || reason.contains("KEY=VALUE"),
7053            "reason must name the shell-env-var-assignment rationale, got {reason:?}"
7054        );
7055    }
7056
7057    #[test]
7058    fn validate_rejects_git_fonte_with_repo_carrying_gitconfig_url_key_prefix() {
7059        // The symmetric paste-from-gitconfig pin: an author copies
7060        // `url=https://github.com/p/x` from `git config --get-all
7061        // remote.origin.url` output, a `.gitconfig` `[remote
7062        // "origin"] url = https://…` ini-stanza paste, or a
7063        // `git config remote.origin.url <value>` doc snippet,
7064        // intending the `url=` prefix as the ini-key but the typed
7065        // `:repo` slot is a URL value parser, not a gitconfig
7066        // grammar. With no leading whitespace and no earlier-arm
7067        // bytes in the value, the `=` arm itself fires (rather
7068        // than cascading to the whitespace arm as in the env-var
7069        // paste shape). Pinned separately so a future diagnostic-
7070        // surface change that only checked the whitespace-leading
7071        // shape surfaces here — the per-byte arm fires anywhere
7072        // `=` appears in the value.
7073        let d = dep_with_fonte(DepSource::Git {
7074            repo: "url=https://github.com/pleme-io/caixa-feira".into(),
7075            tag: Some("v0.1.0".into()),
7076            rev: None,
7077            branch: None,
7078        });
7079        let err = d.validate().unwrap_err();
7080        let DepError::FonteRepoShape { reason, .. } = err else {
7081            panic!("expected FonteRepoShape, got other variant");
7082        };
7083        assert!(
7084            reason.contains("must not contain `=`"),
7085            "reason must surface the equals-`=` arm on the `url=…` gitconfig \
7086             paste shape, got {reason:?}"
7087        );
7088        assert!(
7089            reason.contains("key-value-separator") || reason.contains("sub-delims"),
7090            "reason must name the key-value-separator / RFC-3986-sub-delims \
7091             rationale, got {reason:?}"
7092        );
7093    }
7094
7095    #[test]
7096    fn fonte_repo_fragment_fires_before_equals_when_fragment_first() {
7097        // Cascade pin: the fragment-`#` arm and the `=` arm are
7098        // both per-byte arms inside the same `for &b in s.as_bytes()`
7099        // loop, so the byte that appears first in the value's byte
7100        // order wins. A `:repo "https://github.com/p/x#readme=tail"`
7101        // carries both `#` and `=`; the `#` byte appears first, so
7102        // the fragment-`#` arm fires, surfacing the more self-
7103        // locating diagnostic on the byte the author pasted earliest
7104        // in the URL.
7105        let d = dep_with_fonte(DepSource::Git {
7106            repo: "https://github.com/pleme-io/caixa-teia#readme=tail".into(),
7107            tag: Some("v0.1.0".into()),
7108            rev: None,
7109            branch: None,
7110        });
7111        let err = d.validate().unwrap_err();
7112        let DepError::FonteRepoShape { reason, .. } = err else {
7113            panic!("expected FonteRepoShape, got other variant");
7114        };
7115        assert!(
7116            reason.contains("must not contain `#`"),
7117            "reason must surface the fragment-`#` arm (fires before equals when \
7118             `#` byte appears first in value), got {reason:?}"
7119        );
7120    }
7121
7122    #[test]
7123    fn fonte_repo_comma_fires_before_equals_when_comma_first() {
7124        // Cascade pin: the comma-`,` arm (the immediate-predecessor
7125        // byte-class arm, 775b80e) and the `=` arm are both per-byte
7126        // arms inside the same `for &b in s.as_bytes()` loop, so
7127        // the byte that appears first in the value's byte order
7128        // wins. A `:repo "github:p/x,mid=tail"` carries both `,`
7129        // and `=`; the `,` byte appears first, so the comma arm
7130        // fires, surfacing the more self-locating diagnostic on
7131        // the byte the author pasted earliest in the URL. Pins the
7132        // natural-order cascade so a future reorder of the per-byte
7133        // arms surfaces here — `=` is the most recent byte-class
7134        // arm, so the cascade-pin sweep extends to cover the
7135        // immediately prior `,` byte arm firing first when ordered
7136        // ahead of `=` in the value.
7137        let d = dep_with_fonte(DepSource::Git {
7138            repo: "github:pleme-io/caixa-teia,mid=tail".into(),
7139            tag: Some("v0.1.0".into()),
7140            rev: None,
7141            branch: None,
7142        });
7143        let err = d.validate().unwrap_err();
7144        let DepError::FonteRepoShape { reason, .. } = err else {
7145            panic!("expected FonteRepoShape, got other variant");
7146        };
7147        assert!(
7148            reason.contains("must not contain `,`"),
7149            "reason must surface the comma arm (fires before equals when `,` byte \
7150             appears first in value), got {reason:?}"
7151        );
7152    }
7153
7154    #[test]
7155    fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_space() {
7156        // The fail-before-pass-after pin for the canonical paste-from-
7157        // browser-address-bar percent-encoded-space footgun on `:repo`.
7158        // An author copies `https://github.com/p/x%20test` from a
7159        // browser address bar (or a percent-encoded README hyperlink,
7160        // or a `curl --data-urlencode` shell-pipeline output)
7161        // intending `%20` as the URL encoding of a literal space; the
7162        // typed `:repo` slot already rejects the literal space byte
7163        // (the whitespace arm at the top of `is_git_repo_url`), so an
7164        // author trying to express "I really meant a space" reaches
7165        // for percent-encoding. Until this arm landed the `%` byte
7166        // silently passed every prior `is_git_repo_url` arm and rode
7167        // verbatim into the lacre's per-dep content-address — but
7168        // libcurl re-percent-encodes `%` to `%25` on the wire (since
7169        // `%` is reserved as the escape-sequence lead-in), so the
7170        // wire request becomes `https://github.com/p/x%2520test`, a
7171        // path the lacre's content-address never names. The classic
7172        // render-determinism violation on the encoding-mechanism axis
7173        // itself.
7174        let d = dep_with_fonte(DepSource::Git {
7175            repo: "https://github.com/pleme-io/caixa-teia%20test".into(),
7176            tag: Some("v0.1.0".into()),
7177            rev: None,
7178            branch: None,
7179        });
7180        let err = d.validate().unwrap_err();
7181        let DepError::FonteRepoShape { nome, repo, reason } = err else {
7182            panic!("expected FonteRepoShape, got other variant");
7183        };
7184        assert_eq!(nome, "caixa-teia");
7185        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia%20test");
7186        assert!(
7187            reason.contains("must not contain `%`"),
7188            "reason must surface the percent-`%` arm on the percent-encoded-space \
7189             paste shape, got {reason:?}"
7190        );
7191        assert!(
7192            reason.contains("percent-encoding") || reason.contains("%25"),
7193            "reason must name the percent-encoding / `%25` re-encoding rationale, \
7194             got {reason:?}"
7195        );
7196    }
7197
7198    #[test]
7199    fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_slash() {
7200        // The symmetric over-encoded-path-separator pin: an author
7201        // writes `:repo "https://github.com/p%2Fx"` intending the
7202        // `%2F` as the URL encoding of `/` (the canonical
7203        // paste-from-OpenAPI-spec / paste-from-percent-encoded-template
7204        // footgun every API client library and OAuth redirect-URI
7205        // documentation surfaces — the `/` is the URL-path-separator
7206        // and some templates percent-encode it to escape interpretation
7207        // as a path separator). The GitHub Smart-HTTP transport
7208        // resolves the URL's path-segment grammar before the
7209        // percent-decoding pass, so the value identifies a different
7210        // resource on the wire than the literal-`/` form the lacre's
7211        // content-address must agree with — two authors whose `:repo`
7212        // values differ only in their `/` vs `%2F` presence lock to
7213        // two distinct BLAKE3 closures for the byte-identical upstream
7214        // `git clone`. Pinned separately so a future diagnostic
7215        // surface that only catches the `%20` shape surfaces here too.
7216        let d = dep_with_fonte(DepSource::Git {
7217            repo: "https://github.com/pleme-io%2Fcaixa-teia".into(),
7218            tag: Some("v0.1.0".into()),
7219            rev: None,
7220            branch: None,
7221        });
7222        let err = d.validate().unwrap_err();
7223        let DepError::FonteRepoShape { reason, .. } = err else {
7224            panic!("expected FonteRepoShape, got other variant");
7225        };
7226        assert!(
7227            reason.contains("must not contain `%`"),
7228            "reason must surface the percent-`%` arm on the over-encoded-path \
7229             shape, got {reason:?}"
7230        );
7231        assert!(
7232            reason.contains("render-determinism") || reason.contains("BLAKE3"),
7233            "reason must name the render-determinism / BLAKE3-closure rationale, \
7234             got {reason:?}"
7235        );
7236    }
7237
7238    #[test]
7239    fn fonte_repo_fragment_fires_before_percent_when_fragment_first() {
7240        // Cascade pin: the fragment-`#` arm and the `%` arm are both
7241        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7242        // so the byte that appears first in the value's byte order
7243        // wins. A `:repo "https://github.com/p/x#sec%20tail"` carries
7244        // both `#` and `%`; the `#` byte appears first, so the
7245        // fragment-`#` arm fires, surfacing the more self-locating
7246        // diagnostic on the byte the author pasted earliest in the URL.
7247        let d = dep_with_fonte(DepSource::Git {
7248            repo: "https://github.com/pleme-io/caixa-teia#sec%20tail".into(),
7249            tag: Some("v0.1.0".into()),
7250            rev: None,
7251            branch: None,
7252        });
7253        let err = d.validate().unwrap_err();
7254        let DepError::FonteRepoShape { reason, .. } = err else {
7255            panic!("expected FonteRepoShape, got other variant");
7256        };
7257        assert!(
7258            reason.contains("must not contain `#`"),
7259            "reason must surface the fragment-`#` arm (fires before percent when \
7260             `#` byte appears first in value), got {reason:?}"
7261        );
7262    }
7263
7264    #[test]
7265    fn fonte_repo_equals_fires_before_percent_when_equals_first() {
7266        // Cascade pin: the equals-`=` arm (the immediate-predecessor
7267        // byte-class arm, acf99af) and the `%` arm are both per-byte
7268        // arms inside the same `for &b in s.as_bytes()` loop, so the
7269        // byte that appears first in the value's byte order wins.
7270        // A `:repo "github:p/x=mid%20tail"` carries both `=` and `%`;
7271        // the `=` byte appears first, so the equals arm fires,
7272        // surfacing the more self-locating diagnostic on the byte the
7273        // author pasted earliest in the URL. Pins the natural-order
7274        // cascade so a future reorder of the per-byte arms surfaces
7275        // here — `%` is the most recent byte-class arm, so the
7276        // cascade-pin sweep extends to cover the immediately prior
7277        // `=` byte arm firing first when ordered ahead of `%` in the
7278        // value.
7279        let d = dep_with_fonte(DepSource::Git {
7280            repo: "github:pleme-io/caixa-teia=mid%20tail".into(),
7281            tag: Some("v0.1.0".into()),
7282            rev: None,
7283            branch: None,
7284        });
7285        let err = d.validate().unwrap_err();
7286        let DepError::FonteRepoShape { reason, .. } = err else {
7287            panic!("expected FonteRepoShape, got other variant");
7288        };
7289        assert!(
7290            reason.contains("must not contain `=`"),
7291            "reason must surface the equals arm (fires before percent when `=` byte \
7292             appears first in value), got {reason:?}"
7293        );
7294    }
7295
7296    #[test]
7297    fn validate_rejects_git_fonte_with_repo_carrying_caret_history_substitution() {
7298        // The fail-before-pass-after pin for the canonical paste-from-
7299        // shell-history footgun on `:repo`. An author copies a
7300        // `git clone <url>` line from their terminal followed by a
7301        // bash / ksh / zsh `^typo^fix^` quick-edit-and-rerun shell-
7302        // history shorthand (the `^old^new^` form re-runs the prior
7303        // history entry with the first `old` substituted by `new`,
7304        // bash's default behavior on interactive sessions with
7305        // `set -o histexpand`), forgetting to trim the trailing
7306        // `^...^...` shell-history fragment from the URL value. The
7307        // `^` byte sits in the RFC 3986 §2 'unwise' set (peer with
7308        // `{`, `}`, `|`, `\\` — the strictest of the §2 reserved
7309        // classes), the WHATWG URL spec's 'fragment percent-encode
7310        // set' maps `^` → `%5E` on the wire, so the byte rides
7311        // verbatim into the lacre's per-dep content-address but
7312        // libcurl re-encodes it to `%5E` at `git clone` time — the
7313        // classic render-determinism violation on the same axis the
7314        // peer `%`, `=`, `,`, `!`, `'`, `"`, `(`, `)`, `*`, `$`,
7315        // `&`, `;`, `|`, backtick, `<`, `>`, `{`, `}`, `\\`, `?`,
7316        // `#` arms close.
7317        let d = dep_with_fonte(DepSource::Git {
7318            repo: "https://github.com/pleme-io/caixa-teia^typo^fix".into(),
7319            tag: Some("v0.1.0".into()),
7320            rev: None,
7321            branch: None,
7322        });
7323        let err = d.validate().unwrap_err();
7324        let DepError::FonteRepoShape { nome, repo, reason } = err else {
7325            panic!("expected FonteRepoShape, got other variant");
7326        };
7327        assert_eq!(nome, "caixa-teia");
7328        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia^typo^fix");
7329        assert!(
7330            reason.contains("must not contain `^`"),
7331            "reason must surface the caret-`^` arm on the paste-from-shell-history \
7332             shape, got {reason:?}"
7333        );
7334        assert!(
7335            reason.contains("history-substitution") || reason.contains("%5E"),
7336            "reason must name the shell-history-substitution / `%5E` wire-encoding \
7337             rationale, got {reason:?}"
7338        );
7339    }
7340
7341    #[test]
7342    fn validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor() {
7343        // The symmetric paste-from-doc-grep-pipeline footgun: an
7344        // author writes `:repo "github:p/^archived"` after copying a
7345        // `grep '^archived'` regex-anchor / negation idiom from a
7346        // doc / README quick-listing snippet, expecting the substrate
7347        // to coerce it to a literal repo name. The byte rides
7348        // verbatim into the lacre's per-dep content-address and
7349        // diverges from the byte-identical literal `archived` form
7350        // every other author authored — the canonical render-
7351        // determinism violation pin on the second footgun shape the
7352        // caret-`^` arm closes.
7353        let d = dep_with_fonte(DepSource::Git {
7354            repo: "github:pleme-io/^archived".into(),
7355            tag: Some("v0.1.0".into()),
7356            rev: None,
7357            branch: None,
7358        });
7359        let err = d.validate().unwrap_err();
7360        let DepError::FonteRepoShape { reason, .. } = err else {
7361            panic!("expected FonteRepoShape, got other variant");
7362        };
7363        assert!(
7364            reason.contains("must not contain `^`"),
7365            "reason must surface the caret-`^` arm on the regex-anchor shape, \
7366             got {reason:?}"
7367        );
7368        assert!(
7369            reason.contains("render-determinism") || reason.contains("BLAKE3"),
7370            "reason must name the render-determinism / BLAKE3-closure rationale, \
7371             got {reason:?}"
7372        );
7373    }
7374
7375    #[test]
7376    fn fonte_repo_percent_fires_before_caret_when_percent_first() {
7377        // Cascade pin: the `%` arm (the immediate-predecessor byte-
7378        // class arm, a323db8) and the `^` arm are both per-byte arms
7379        // inside the same `for &b in s.as_bytes()` loop, so the byte
7380        // that appears first in the value's byte order wins. A
7381        // `:repo "https://github.com/p/x%20mid^tail"` carries both
7382        // `%` and `^`; the `%` byte appears first, so the percent
7383        // arm fires, surfacing the more self-locating diagnostic on
7384        // the byte the author pasted earliest in the URL. Pins the
7385        // natural-order cascade so a future reorder of the per-byte
7386        // arms surfaces here — `^` is the most recent byte-class arm,
7387        // so the cascade-pin sweep extends to cover the immediately
7388        // prior `%` byte arm firing first when ordered ahead of `^`
7389        // in the value.
7390        let d = dep_with_fonte(DepSource::Git {
7391            repo: "https://github.com/pleme-io/caixa-teia%20mid^tail".into(),
7392            tag: Some("v0.1.0".into()),
7393            rev: None,
7394            branch: None,
7395        });
7396        let err = d.validate().unwrap_err();
7397        let DepError::FonteRepoShape { reason, .. } = err else {
7398            panic!("expected FonteRepoShape, got other variant");
7399        };
7400        assert!(
7401            reason.contains("must not contain `%`"),
7402            "reason must surface the percent arm (fires before caret when `%` byte \
7403             appears first in value), got {reason:?}"
7404        );
7405    }
7406
7407    #[test]
7408    fn validate_rejects_git_fonte_with_repo_missing_colon_separator() {
7409        // The "I dropped the scheme" footgun — `:repo "pleme-io/caixa-teia"`
7410        // (no `github:` prefix, no scheme). Every documented form
7411        // carries a `:` (`github:`, `https://`, `ssh://`, `git://`,
7412        // `file://`, or `git@host:path`); a bare `org/repo` is
7413        // ambiguous (`git clone` reads as a relative filesystem path
7414        // rather than the GitHub-shorthand expansion the author
7415        // probably intended) and the gate rejects the shape upstream.
7416        let d = dep_with_fonte(DepSource::Git {
7417            repo: "pleme-io/caixa-teia".into(),
7418            tag: Some("v0.1.0".into()),
7419            rev: None,
7420            branch: None,
7421        });
7422        let err = d.validate().unwrap_err();
7423        let DepError::FonteRepoShape { reason, .. } = err else {
7424            panic!("expected FonteRepoShape, got other variant");
7425        };
7426        assert!(
7427            reason.contains("must contain a `:`"),
7428            "reason must surface the missing-`:` arm, got {reason:?}"
7429        );
7430        assert!(
7431            reason.contains("github:"),
7432            "reason must name the canonical `github:` shorthand prefix, got {reason:?}"
7433        );
7434    }
7435
7436    #[test]
7437    fn validate_rejects_git_fonte_with_repo_leading_colon() {
7438        // The "empty scheme" footgun — `:repo ":foo"` has a zero-length
7439        // scheme that no git porcelain entry-point accepts. Pinned
7440        // separately from the missing-`:` arm because a value with a
7441        // leading `:` does technically contain a `:` separator; the
7442        // shape gate rejects on a dedicated arm so the diagnostic
7443        // names the specific footgun.
7444        let d = dep_with_fonte(DepSource::Git {
7445            repo: ":pleme-io/caixa-teia".into(),
7446            tag: Some("v0.1.0".into()),
7447            rev: None,
7448            branch: None,
7449        });
7450        let err = d.validate().unwrap_err();
7451        let DepError::FonteRepoShape { reason, .. } = err else {
7452            panic!("expected FonteRepoShape, got other variant");
7453        };
7454        assert!(
7455            reason.contains("must not start with `:`"),
7456            "reason must surface the leading-`:` arm, got {reason:?}"
7457        );
7458    }
7459
7460    #[test]
7461    fn validate_rejects_git_fonte_with_repo_too_long() {
7462        // The cap arm — a `:repo` value longer than
7463        // [`crate::render::GIT_REPO_URL_MAX_LEN`] (2048) bytes is
7464        // structurally untenable on every realistic landing site (the
7465        // resolver's `git clone` invocation, the future M4 CR
7466        // materializer's per-dep `repo:` axis); a value of that length
7467        // is almost certainly a paste-from-binary slug.
7468        let too_long = format!(
7469            "github:pleme-io/{}",
7470            "x".repeat(crate::render::GIT_REPO_URL_MAX_LEN)
7471        );
7472        let d = dep_with_fonte(DepSource::Git {
7473            repo: too_long.clone(),
7474            tag: Some("v0.1.0".into()),
7475            rev: None,
7476            branch: None,
7477        });
7478        let err = d.validate().unwrap_err();
7479        let DepError::FonteRepoShape { reason, .. } = err else {
7480            panic!("expected FonteRepoShape, got other variant");
7481        };
7482        assert!(
7483            reason.contains("2048"),
7484            "reason must name the cap, got {reason:?}"
7485        );
7486    }
7487
7488    #[test]
7489    fn validate_accepts_canonical_git_fonte_repo_shapes() {
7490        // The positive-control sweep: every documented author shape on
7491        // the `:fonte :repo` axis ([`crate::DepSource::Git`] doc comment)
7492        // must pass the value-shape gate. Pinned so a future tightening
7493        // (e.g. forbidding `http://` in favor of `https://`-only) surfaces
7494        // here as a structural decision. Each form is exercised with the
7495        // same canonical `:tag` pin so only the `:repo` axis varies.
7496        for repo in [
7497            // The pleme-io registry-shorthand convention — `github:org/repo`.
7498            "github:pleme-io/caixa-teia",
7499            // Other host-aliased shorthands (the resolver's pluggable
7500            // host-prefix table).
7501            "gitlab:pleme-io/caixa-teia",
7502            "codeberg:pleme-io/caixa-teia",
7503            "sourcehut:~pleme-io/caixa-teia",
7504            // Full HTTPS URL with and without `.git` suffix.
7505            "https://github.com/pleme-io/caixa-teia",
7506            "https://github.com/pleme-io/caixa-teia.git",
7507            // HTTP (rare; dev / mirror).
7508            "http://example.com/pleme-io/caixa-teia.git",
7509            // SSH URL.
7510            "ssh://git@github.com/pleme-io/caixa-teia.git",
7511            "ssh://git@git.example.com:2222/pleme-io/caixa-teia.git",
7512            // Scp-style SSH — the canonical `git@host:path` short form.
7513            "git@github.com:pleme-io/caixa-teia.git",
7514            "git@git.example.com:team/private.git",
7515            // Anonymous git protocol.
7516            "git://git.example.com/pleme-io/caixa-teia.git",
7517            // Local file URL (dev path).
7518            "file:///tmp/caixa-teia",
7519        ] {
7520            let d = dep_with_fonte(DepSource::Git {
7521                repo: repo.into(),
7522                tag: Some("v0.1.0".into()),
7523                rev: None,
7524                branch: None,
7525            });
7526            d.validate()
7527                .unwrap_or_else(|e| panic!("canonical repo {repo:?} must validate, got {e:?}"));
7528        }
7529    }
7530
7531    #[test]
7532    fn fonte_repo_empty_takes_precedence_over_shape() {
7533        // Order pin: the existing `FonteRepoEmpty` diagnostic (narrower
7534        // diagnostic; doesn't try to parse the URL shape) fires before
7535        // the new `FonteRepoShape` per-axis gate, so an empty `:repo`
7536        // keeps its narrower error message. Mirrors
7537        // `fonte_repo_empty_fires_before_pin_missing` (already pinned)
7538        // on the ordering layer.
7539        let d = dep_with_fonte(DepSource::Git {
7540            repo: String::new(),
7541            tag: Some("v0.1.0".into()),
7542            rev: None,
7543            branch: None,
7544        });
7545        let err = d.validate().unwrap_err();
7546        assert!(
7547            matches!(err, DepError::FonteRepoEmpty { .. }),
7548            "got {err:?}"
7549        );
7550    }
7551
7552    #[test]
7553    fn fonte_repo_shape_fires_before_pin_missing() {
7554        // Order pin: a malformed `:repo` value on a dep with no pin set
7555        // surfaces the `:repo` shape diagnostic (the more self-locating
7556        // axis — the `:repo` is the load-bearing identity of the source;
7557        // a missing pin is downstream from "do we even know the repo")
7558        // rather than collapsing onto the pin-missing diagnostic. The
7559        // shape gate runs inline before the pin enumeration in
7560        // `DepSource::validate`.
7561        let d = dep_with_fonte(DepSource::Git {
7562            repo: "pleme-io/caixa-teia".into(), // missing `:` separator
7563            tag: None,
7564            rev: None,
7565            branch: None,
7566        });
7567        let err = d.validate().unwrap_err();
7568        assert!(
7569            matches!(err, DepError::FonteRepoShape { .. }),
7570            "got {err:?}"
7571        );
7572    }
7573
7574    #[test]
7575    fn fonte_repo_shape_diagnostic_carries_offending_repo_verbatim() {
7576        // The diagnostic-shape pin: the error names the offending
7577        // `:repo` value verbatim plus a non-empty parser-shaped `reason`
7578        // so the author can grep their caixa.lisp without re-running
7579        // the build. Mirrors the diagnostic-shape sweep on every prior
7580        // value-shape gate (3f9d7a0, 6cbb900, c7d05ec, e70d213, be07fd5).
7581        let d = dep_with_fonte(DepSource::Git {
7582            repo: "pleme-io/caixa-teia".into(),
7583            tag: Some("v0.1.0".into()),
7584            rev: None,
7585            branch: None,
7586        });
7587        let err = d.validate().unwrap_err();
7588        let DepError::FonteRepoShape { nome, repo, reason } = err else {
7589            panic!("expected FonteRepoShape, got other variant");
7590        };
7591        assert_eq!(nome, "caixa-teia");
7592        assert_eq!(repo, "pleme-io/caixa-teia");
7593        assert!(
7594            !reason.is_empty(),
7595            "FonteRepoShape `reason` must carry the predicate's wording verbatim"
7596        );
7597    }
7598
7599    #[test]
7600    fn validate_rejects_git_fonte_with_no_pin() {
7601        // The fail-before-pass-after pin for the canonical
7602        // `(:tipo git :repo "github:pleme-io/x")` shape with no
7603        // :tag/:rev/:branch — until this gate landed the resolver's
7604        // ResolveError::MissingPin surfaced at fetch time, far from the
7605        // source caixa.lisp. The new gate moves the check to validate
7606        // time and names the offending dep.
7607        let d = dep_with_fonte(DepSource::Git {
7608            repo: "github:pleme-io/caixa-teia".into(),
7609            tag: None,
7610            rev: None,
7611            branch: None,
7612        });
7613        let err = d.validate().unwrap_err();
7614        assert!(
7615            matches!(err, DepError::FontePinMissing { ref nome } if nome == "caixa-teia"),
7616            "got {err:?}"
7617        );
7618    }
7619
7620    #[test]
7621    fn validate_rejects_git_fonte_with_ambiguous_tag_and_branch() {
7622        // The canonical "pin drift" footgun: an author writes
7623        // `:tag "v1"` and later adds `:branch "main"` without removing
7624        // the :tag, and the resolver silently picks :tag (precedence
7625        // :rev > :tag > :branch). The :branch was dropped with no
7626        // diagnostic. The gate now rejects multi-pin shapes so the
7627        // author makes the precedence explicit at the source.
7628        let d = dep_with_fonte(DepSource::Git {
7629            repo: "github:pleme-io/caixa-teia".into(),
7630            tag: Some("v0.1.0".into()),
7631            rev: None,
7632            branch: Some("main".into()),
7633        });
7634        let err = d.validate().unwrap_err();
7635        let DepError::FontePinAmbiguous { nome, pins } = err else {
7636            panic!("expected FontePinAmbiguous");
7637        };
7638        assert_eq!(nome, "caixa-teia");
7639        assert!(pins.contains(":tag"));
7640        assert!(pins.contains(":branch"));
7641        assert!(!pins.contains(":rev"));
7642    }
7643
7644    #[test]
7645    fn validate_rejects_git_fonte_with_ambiguous_tag_and_rev() {
7646        // Sibling arm of the pin-drift footgun: :tag + :rev set
7647        // simultaneously. Pinned separately so a future relaxation
7648        // that only catches the (:tag, :branch) pair surfaces here.
7649        let d = dep_with_fonte(DepSource::Git {
7650            repo: "github:pleme-io/caixa-teia".into(),
7651            tag: Some("v0.1.0".into()),
7652            rev: Some("c0ffee".into()),
7653            branch: None,
7654        });
7655        let err = d.validate().unwrap_err();
7656        let DepError::FontePinAmbiguous { nome, pins } = err else {
7657            panic!("expected FontePinAmbiguous");
7658        };
7659        assert_eq!(nome, "caixa-teia");
7660        assert!(pins.contains(":tag"));
7661        assert!(pins.contains(":rev"));
7662    }
7663
7664    #[test]
7665    fn validate_rejects_git_fonte_with_all_three_pins() {
7666        // The maximal ambiguity case — every pin axis set. Pinned so a
7667        // future relaxation that only catches pairs surfaces here. The
7668        // diagnostic must enumerate every offending axis so the author
7669        // sees the full set, not just the first match.
7670        let d = dep_with_fonte(DepSource::Git {
7671            repo: "github:pleme-io/caixa-teia".into(),
7672            tag: Some("v0.1.0".into()),
7673            rev: Some("c0ffee".into()),
7674            branch: Some("main".into()),
7675        });
7676        let err = d.validate().unwrap_err();
7677        let DepError::FontePinAmbiguous { nome, pins } = err else {
7678            panic!("expected FontePinAmbiguous");
7679        };
7680        assert_eq!(nome, "caixa-teia");
7681        assert!(pins.contains(":tag"));
7682        assert!(pins.contains(":rev"));
7683        assert!(pins.contains(":branch"));
7684    }
7685
7686    #[test]
7687    fn validate_rejects_git_fonte_with_empty_tag_pin() {
7688        // The empty-pin arm: exactly one pin axis is `Some(_)`, but its
7689        // inner string is empty. Distinct from FontePinMissing (where
7690        // every axis is None) — pinned separately so a future
7691        // tightening collapsing them surfaces here as a structural
7692        // decision.
7693        let d = dep_with_fonte(DepSource::Git {
7694            repo: "github:pleme-io/caixa-teia".into(),
7695            tag: Some(String::new()),
7696            rev: None,
7697            branch: None,
7698        });
7699        let err = d.validate().unwrap_err();
7700        let DepError::FontePinEmpty { nome, pin } = err else {
7701            panic!("expected FontePinEmpty");
7702        };
7703        assert_eq!(nome, "caixa-teia");
7704        assert_eq!(pin, ":tag");
7705    }
7706
7707    #[test]
7708    fn validate_rejects_git_fonte_with_empty_rev_pin() {
7709        // Sibling arm — the empty-pin diagnostic names which axis
7710        // carries the empty value, so the author's grep target is
7711        // unambiguous.
7712        let d = dep_with_fonte(DepSource::Git {
7713            repo: "github:pleme-io/caixa-teia".into(),
7714            tag: None,
7715            rev: Some(String::new()),
7716            branch: None,
7717        });
7718        let err = d.validate().unwrap_err();
7719        let DepError::FontePinEmpty { nome, pin } = err else {
7720            panic!("expected FontePinEmpty");
7721        };
7722        assert_eq!(nome, "caixa-teia");
7723        assert_eq!(pin, ":rev");
7724    }
7725
7726    #[test]
7727    fn validate_rejects_path_fonte_with_empty_caminho() {
7728        // The fail-before-pass-after pin for `(:tipo path :caminho "")`:
7729        // until this gate landed the resolver's
7730        // ResolveError::MissingPath surfaced with `path: PathBuf("")` at
7731        // fetch time — not actionable. The new gate moves the check to
7732        // validate time and names the offending dep.
7733        let d = dep_with_fonte(DepSource::Path {
7734            caminho: String::new(),
7735        });
7736        let err = d.validate().unwrap_err();
7737        assert!(
7738            matches!(err, DepError::FonteCaminhoEmpty { ref nome } if nome == "caixa-teia"),
7739            "got {err:?}"
7740        );
7741    }
7742
7743    #[test]
7744    fn validate_rejects_path_fonte_with_absolute_caminho() {
7745        // The fail-before-pass-after pin for the absolute-`:caminho`
7746        // shape: `(:tipo path :caminho "/home/me/work/caixa-teia")`.
7747        // Until this gate landed an absolute `:caminho` silently
7748        // passed validate; the lacre pipeline embedded the
7749        // host-specific filesystem path verbatim in its
7750        // content-address (`conteudo: format!("path:{caminho}")`,
7751        // caixa-resolver/src/resolve.rs:189), so the BLAKE3 closure
7752        // differed per machine — the build succeeded but two CI
7753        // runners with different `${HOME}` layouts emitted two
7754        // distinct lacres for the byte-identical caixa, silently
7755        // breaking the THEORY.md §V.2 render-determinism contract
7756        // far from the source caixa.lisp. The new gate moves the
7757        // check to validate time and names the offending dep +
7758        // caminho verbatim.
7759        let d = dep_with_fonte(DepSource::Path {
7760            caminho: "/home/me/work/caixa-teia".into(),
7761        });
7762        let err = d.validate().unwrap_err();
7763        let DepError::FonteCaminhoAbsolute { nome, caminho } = err else {
7764            panic!("expected FonteCaminhoAbsolute, got other variant");
7765        };
7766        assert_eq!(nome, "caixa-teia");
7767        assert_eq!(caminho, "/home/me/work/caixa-teia");
7768    }
7769
7770    #[test]
7771    fn validate_accepts_path_fonte_with_parent_escape_caminho() {
7772        // The canonical sibling-workspace dep form
7773        // (`:caminho "../caixa-teia"`) remains accepted. The
7774        // absolute-path gate above is specifically narrower than the
7775        // shared [`crate::render::is_sandboxed_relative_path`]
7776        // predicate (which additionally forbids `..` traversal): a
7777        // local-path dep's canonical author surface is the in-tree
7778        // sibling-workspace path, so a full sandboxed-relative-path
7779        // lift would structurally reject every legitimate path-fonte
7780        // dep. Pinned so a future tightening to the full predicate
7781        // surfaces here as a structural decision, not a silent break.
7782        let d = dep_with_fonte(DepSource::Path {
7783            caminho: "../caixa-teia".into(),
7784        });
7785        d.validate().unwrap();
7786    }
7787
7788    #[test]
7789    fn validate_accepts_path_fonte_with_deeply_nested_relative_caminho() {
7790        // A multi-segment relative `:caminho`
7791        // (`"vendor/forks/caixa-teia"`) remains accepted — the
7792        // absolute-path gate brackets the host-layout-leaking shape
7793        // at the leading-`/` boundary only; every relative shape past
7794        // the empty arm continues to pass. Pinned alongside the
7795        // `..`-traversal positive control so a future tightening
7796        // surfaces the full set of legitimate relative forms here
7797        // rather than at a downstream consumer.
7798        let d = dep_with_fonte(DepSource::Path {
7799            caminho: "vendor/forks/caixa-teia".into(),
7800        });
7801        d.validate().unwrap();
7802    }
7803
7804    #[test]
7805    fn validate_rejects_path_fonte_with_tilde_prefix_caminho() {
7806        // The fail-before-pass-after pin for the tilde-expansion
7807        // `:caminho` shape: `(:tipo path :caminho "~/work/caixa-teia")`.
7808        // Until this gate landed the b94fd83 absolute arm let `~/foo`
7809        // through (`Path::is_absolute` returns false on a leading `~`
7810        // — the tilde is a shell-expansion convention, not a POSIX
7811        // path component), so the lacre embedded the value verbatim
7812        // and the resolver folded it through `Path::join` without
7813        // expansion, looking for a literal `./~/work/caixa-teia`
7814        // subdirectory and failing at resolve time with a
7815        // `No such file or directory` error far from the source
7816        // caixa.lisp. The new gate moves the check to validate time
7817        // and names the offending dep + caminho verbatim.
7818        let d = dep_with_fonte(DepSource::Path {
7819            caminho: "~/work/caixa-teia".into(),
7820        });
7821        let err = d.validate().unwrap_err();
7822        let DepError::FonteCaminhoTildeExpansion { nome, caminho } = err else {
7823            panic!("expected FonteCaminhoTildeExpansion, got {err:?}");
7824        };
7825        assert_eq!(nome, "caixa-teia");
7826        assert_eq!(caminho, "~/work/caixa-teia");
7827    }
7828
7829    #[test]
7830    fn validate_rejects_path_fonte_with_bare_tilde_caminho() {
7831        // The bare `~` form (canonical "I meant `$HOME` and forgot
7832        // the rest"): both the leading-tilde arm catches it and the
7833        // canonical-user-tilde shell idiom (`~alice/dev/caixa-teia`)
7834        // sweeps through the same arm. Pinned both to ensure the
7835        // gate doesn't narrow to `~/` only.
7836        for s in ["~", "~alice/dev/caixa-teia", "~/", "~root/work"] {
7837            let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7838            let err = d.validate().unwrap_err();
7839            assert!(
7840                matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7841                "{s:?} → {err:?}",
7842            );
7843        }
7844    }
7845
7846    #[test]
7847    fn validate_accepts_path_fonte_with_mid_path_tilde_caminho() {
7848        // The leading-`~` is the canonical shell-expansion footgun —
7849        // a tilde mid-path (`"../foo~bar/caixa-teia"` — the canonical
7850        // backup-file-suffix idiom) is a legitimate POSIX path byte
7851        // with no shell-expansion semantic at the leading position.
7852        // Pinned so the gate doesn't widen to a full no-tilde-anywhere
7853        // sweep that would break every legitimate-shape backup-file
7854        // path.
7855        let d = dep_with_fonte(DepSource::Path {
7856            caminho: "../foo~bar/caixa-teia".into(),
7857        });
7858        d.validate().unwrap();
7859    }
7860
7861    #[test]
7862    fn fonte_caminho_empty_fires_before_tilde_expansion() {
7863        // Cascade pin: the empty arm structurally precedes the
7864        // tilde arm (the bytes `""` and `"~"` don't overlap), but the
7865        // pin establishes the precedence at the diagnostic-shape
7866        // level should a future codec round-trip ever produce a
7867        // probe-as-both value. Mirrors the peer
7868        // `fonte_repo_empty_fires_before_pin_missing` cascade
7869        // discipline.
7870        let d = dep_with_fonte(DepSource::Path {
7871            caminho: String::new(),
7872        });
7873        let err = d.validate().unwrap_err();
7874        assert!(
7875            matches!(err, DepError::FonteCaminhoEmpty { .. }),
7876            "got {err:?}",
7877        );
7878    }
7879
7880    #[test]
7881    fn fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho() {
7882        // Diagnostic-shape pin (peer with
7883        // `validate_rejects_path_fonte_with_absolute_caminho`'s
7884        // payload assertion): the error's Display surfaces both the
7885        // offending `:nome` and the offending `:caminho` verbatim
7886        // so a `feira lint` run can render the diagnostic without
7887        // re-parsing.
7888        let d = dep_with_fonte(DepSource::Path {
7889            caminho: "~alice/dev/caixa-teia".into(),
7890        });
7891        let rendered = d.validate().unwrap_err().to_string();
7892        assert!(
7893            rendered.contains("caixa-teia"),
7894            "diagnostic must name the offending dep: {rendered}",
7895        );
7896        assert!(
7897            rendered.contains("~alice/dev/caixa-teia"),
7898            "diagnostic must quote the offending caminho: {rendered}",
7899        );
7900        assert!(
7901            rendered.contains('~'),
7902            "diagnostic must reference the tilde footgun: {rendered}",
7903        );
7904    }
7905
7906    #[test]
7907    fn validate_rejects_path_fonte_with_dollar_prefix_caminho() {
7908        // The fail-before-pass-after pin for the shell-variable-
7909        // expansion `:caminho` shape: `(:tipo path :caminho
7910        // "$HOME/work/caixa-teia")`. Until this gate landed the
7911        // b94fd83 absolute arm + the a5c248e tilde arm both let
7912        // `$HOME/foo` through (`Path::is_absolute` returns false on
7913        // a leading `$` — the `$` is a shell convention, not a POSIX
7914        // path component; `starts_with('~')` returns false too), so
7915        // the lacre embedded the value verbatim and the resolver
7916        // folded it through `Path::join` without `$`-expansion,
7917        // looking for a literal `./$HOME/work/caixa-teia`
7918        // subdirectory and failing at resolve time with a
7919        // `No such file or directory` error far from the source
7920        // caixa.lisp. The new gate moves the check to validate time
7921        // and names the offending dep + caminho verbatim.
7922        let d = dep_with_fonte(DepSource::Path {
7923            caminho: "$HOME/work/caixa-teia".into(),
7924        });
7925        let err = d.validate().unwrap_err();
7926        let DepError::FonteCaminhoVarExpansion { nome, caminho } = err else {
7927            panic!("expected FonteCaminhoVarExpansion, got {err:?}");
7928        };
7929        assert_eq!(nome, "caixa-teia");
7930        assert_eq!(caminho, "$HOME/work/caixa-teia");
7931    }
7932
7933    #[test]
7934    fn validate_rejects_path_fonte_with_dollar_brace_prefix_caminho() {
7935        // Sweep over every leading-`$` shape: the `${VAR}`-braced
7936        // form (canonical "paste-from-CI-manifest" footgun every
7937        // GitHub Actions / GitLab CI / Drone manifest carries on
7938        // `${WORKSPACE}`), the XDG idiom (`$XDG_CONFIG_HOME/caixa`,
7939        // canonical "I'm referencing a per-user config dir"),
7940        // and the bare `$` (canonical "I meant `$HOME` and forgot
7941        // the rest"). All shapes route through the same gate's
7942        // byte check. Pinned so the gate doesn't narrow to a
7943        // single shape (e.g. `$HOME/` only).
7944        for s in [
7945            "${HOME}/work/caixa-teia",
7946            "${WORKSPACE}/caixa-teia",
7947            "$XDG_CONFIG_HOME/caixa",
7948            "$",
7949        ] {
7950            let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7951            let err = d.validate().unwrap_err();
7952            assert!(
7953                matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
7954                "{s:?} → {err:?}",
7955            );
7956        }
7957    }
7958
7959    #[test]
7960    fn validate_rejects_path_fonte_with_mid_path_dollar_caminho() {
7961        // The `$` byte is the canonical shell-variable-expansion /
7962        // command-substitution / arithmetic-expansion sentinel and
7963        // is rejected at *every* position on the `:caminho` axis: the
7964        // leading arm surfaces `FonteCaminhoVarExpansion`, the
7965        // embedded arm surfaces `FonteCaminhoShellVariableExpansion`
7966        // (6620f39). Pinned so a future arm doesn't narrow the gate
7967        // back to the leading position and re-open the paste-from-
7968        // shell-one-liner `"../foo$HOME/bar"` / paste-from-CI-
7969        // manifest `"../foo${WORKSPACE}/bar"` / paste-from-shell-
7970        // prompt `"../foo$(whoami)/bar"` cross-idiom-leak surface on
7971        // the lacre content-address (`path:{caminho}`,
7972        // caixa-resolver/src/resolve.rs:189).
7973        let d = dep_with_fonte(DepSource::Path {
7974            caminho: "../foo$bar/caixa-teia".into(),
7975        });
7976        let err = d.validate().unwrap_err();
7977        assert!(
7978            matches!(
7979                err,
7980                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
7981            ),
7982            "got {err:?}",
7983        );
7984    }
7985
7986    #[test]
7987    fn fonte_caminho_tilde_fires_before_var_expansion() {
7988        // Cascade pin: the tilde arm structurally precedes the var
7989        // arm (the bytes `~` and `$` don't overlap at the leading
7990        // position), but the pin establishes the precedence at the
7991        // diagnostic-shape level should a future codec round-trip
7992        // ever produce a probe-as-both value. Mirrors the peer
7993        // `fonte_caminho_empty_fires_before_tilde_expansion` cascade
7994        // discipline on the immediate-predecessor arm.
7995        let d = dep_with_fonte(DepSource::Path {
7996            caminho: "~/work/caixa-teia".into(),
7997        });
7998        let err = d.validate().unwrap_err();
7999        assert!(
8000            matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
8001            "got {err:?}",
8002        );
8003    }
8004
8005    #[test]
8006    fn fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho() {
8007        // Diagnostic-shape pin (peer with
8008        // `fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho`'s
8009        // payload assertion on the immediate-predecessor arm): the
8010        // error's Display surfaces both the offending `:nome` and
8011        // the offending `:caminho` verbatim plus the `$` footgun
8012        // character itself so a `feira lint` run can render the
8013        // diagnostic without re-parsing.
8014        let d = dep_with_fonte(DepSource::Path {
8015            caminho: "${WORKSPACE}/caixa-teia".into(),
8016        });
8017        let rendered = d.validate().unwrap_err().to_string();
8018        assert!(
8019            rendered.contains("caixa-teia"),
8020            "diagnostic must name the offending dep: {rendered}",
8021        );
8022        assert!(
8023            rendered.contains("${WORKSPACE}/caixa-teia"),
8024            "diagnostic must quote the offending caminho: {rendered}",
8025        );
8026        assert!(
8027            rendered.contains('$'),
8028            "diagnostic must reference the dollar footgun: {rendered}",
8029        );
8030    }
8031
8032    #[test]
8033    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_nul() {
8034        // The fail-before-pass-after pin for the load-bearing NUL byte:
8035        // POSIX paths cannot contain `0x00` (every `std::fs` syscall
8036        // routes the path through `CString::new` which fails with
8037        // `NulError`); until this gate landed a `:caminho
8038        // "../caixa\0teia"` silently passed validate, the lacre
8039        // pipeline embedded the value verbatim, and the failure
8040        // surfaced at the resolver's `Path::join` → `CString::new`
8041        // boundary with a non-self-locating `NulError` far from the
8042        // source caixa.lisp. The new gate moves the check to validate
8043        // time and names the offending dep + caminho + offending byte
8044        // verbatim.
8045        let d = dep_with_fonte(DepSource::Path {
8046            caminho: "../caixa\0teia".into(),
8047        });
8048        let err = d.validate().unwrap_err();
8049        let DepError::FonteCaminhoControlChar {
8050            nome,
8051            caminho,
8052            byte,
8053        } = err
8054        else {
8055            panic!("expected FonteCaminhoControlChar, got {err:?}");
8056        };
8057        assert_eq!(nome, "caixa-teia");
8058        assert_eq!(caminho, "../caixa\0teia");
8059        assert_eq!(byte, 0x00);
8060    }
8061
8062    #[test]
8063    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_newline() {
8064        // The canonical paste-from-multiline-doc footgun on `:caminho`
8065        // — author copies `"../caixa-teia\n"` (trailing newline) out
8066        // of a multi-line code-fence or, worse, a `:caminho
8067        // "../caixa-teia\nrm -rf /"` value (CRLF-at-subprocess-argument
8068        // injection sibling on the path axis the `is_git_repo_url`
8069        // control-char arm already closes on `:repo`). Pinned
8070        // separately from the NUL arm so a future relaxation that
8071        // catches one but not the other surfaces here.
8072        let d = dep_with_fonte(DepSource::Path {
8073            caminho: "../caixa-teia\n".into(),
8074        });
8075        let err = d.validate().unwrap_err();
8076        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8077            panic!("expected FonteCaminhoControlChar, got {err:?}");
8078        };
8079        assert_eq!(byte, 0x0A);
8080    }
8081
8082    #[test]
8083    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_carriage_return() {
8084        // The CRLF sibling of the LF arm — Windows-line-ending
8085        // paste-from-multiline-doc on a `\r\n`-terminated buffer
8086        // leaves a stray `\r` mid-string after the LF strip. Pinned
8087        // separately from the LF arm so a future relaxation that
8088        // only catches LF surfaces here.
8089        let d = dep_with_fonte(DepSource::Path {
8090            caminho: "../caixa-teia\r".into(),
8091        });
8092        let err = d.validate().unwrap_err();
8093        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8094            panic!("expected FonteCaminhoControlChar, got {err:?}");
8095        };
8096        assert_eq!(byte, 0x0D);
8097    }
8098
8099    #[test]
8100    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_tab() {
8101        // The canonical paste-from-aligned-table footgun — a `\t`
8102        // mid-`:caminho` is invisible in most editors but rides
8103        // through the lacre's content-address verbatim, so two
8104        // paste-from-distinct-tables (one editor strips tabs, one
8105        // preserves them) yield divergent lacres for the byte-
8106        // identical-looking caixa. Pinned separately from the
8107        // whitespace-shaped LF/CR arms so a future relaxation that
8108        // narrows to line-terminator-only surfaces here.
8109        let d = dep_with_fonte(DepSource::Path {
8110            caminho: "../caixa\tteia".into(),
8111        });
8112        let err = d.validate().unwrap_err();
8113        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8114            panic!("expected FonteCaminhoControlChar, got {err:?}");
8115        };
8116        assert_eq!(byte, 0x09);
8117    }
8118
8119    #[test]
8120    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_del() {
8121        // The DEL byte (`0x7F`) closes the upper-end paste-from-
8122        // binary-blob footgun — the gate's contract is `b < 0x20 ||
8123        // b == 0x7F`, matching the `is_git_repo_url` /
8124        // `is_git_ref_name` predicates' control-char arms. Pinned
8125        // separately from the lower-range arms so a future narrowing
8126        // to `< 0x20` only surfaces here.
8127        let d = dep_with_fonte(DepSource::Path {
8128            caminho: "../caixa\x7fteia".into(),
8129        });
8130        let err = d.validate().unwrap_err();
8131        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8132            panic!("expected FonteCaminhoControlChar, got {err:?}");
8133        };
8134        assert_eq!(byte, 0x7F);
8135    }
8136
8137    #[test]
8138    fn validate_accepts_path_fonte_with_caminho_carrying_high_bit_utf8() {
8139        // The control-byte arm targets `0x00..=0x1F` + `0x7F` only —
8140        // high-bit / non-ASCII UTF-8 bytes are not gated. POSIX paths
8141        // are opaque byte sequences and UTF-8 multi-byte sequences
8142        // are a legitimate filename shape (the `café-teia/foo` idiom).
8143        // Pinned so the gate doesn't widen to a full ASCII-only sweep
8144        // that would break every legitimate-shape UTF-8 path.
8145        let d = dep_with_fonte(DepSource::Path {
8146            caminho: "../café-teia/foo".into(),
8147        });
8148        d.validate().unwrap();
8149    }
8150
8151    #[test]
8152    fn fonte_caminho_var_fires_before_control_char() {
8153        // Cascade pin: the var-expansion arm structurally precedes the
8154        // control-char arm. A value like `"$\n"` probes positive on
8155        // both arms (`starts_with('$')` and contains LF), but the
8156        // narrower leading-byte diagnostic (`FonteCaminhoVarExpansion`)
8157        // wins so the author sees the more self-locating shell-
8158        // expansion arm first. Mirrors the
8159        // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8160        // discipline on the immediate-predecessor arm.
8161        let d = dep_with_fonte(DepSource::Path {
8162            caminho: "$HOME\n".into(),
8163        });
8164        let err = d.validate().unwrap_err();
8165        assert!(
8166            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8167            "got {err:?}",
8168        );
8169    }
8170
8171    #[test]
8172    fn validate_rejects_path_fonte_with_leading_space_caminho() {
8173        // The fail-before-pass-after pin for the leading ASCII space
8174        // `:caminho` shape: `(:tipo path :caminho " ../caixa-teia")`.
8175        // Until this gate landed the b94fd83 absolute arm + the a5c248e
8176        // tilde arm + the f4efe9c var arm + the d624c8d control-byte arm
8177        // all let `" ../caixa-teia"` through: `Path::is_absolute` returns
8178        // false on a leading space (the leading byte is `0x20`, not `0x2F`),
8179        // `starts_with('~')` / `starts_with('$')` return false, and `0x20`
8180        // is not in the `0x00..=0x1F` plus `0x7F` control-byte set (the
8181        // four ASCII whitespace bytes `0x09` tab, `0x0A` LF, `0x0D` CR
8182        // are caught, but the most common whitespace `0x20` space is
8183        // not). The lacre embedded the value verbatim and the resolver
8184        // folded it through `Path::join` looking for a literal `./ ../
8185        // caixa-teia` subdirectory and failing at resolve time with a
8186        // non-self-locating `No such file or directory` error far from
8187        // the source caixa.lisp. The new gate moves the check to
8188        // validate time and names the offending dep + caminho verbatim.
8189        let d = dep_with_fonte(DepSource::Path {
8190            caminho: " ../caixa-teia".into(),
8191        });
8192        let err = d.validate().unwrap_err();
8193        let DepError::FonteCaminhoLeadingWhitespace { nome, caminho } = err else {
8194            panic!("expected FonteCaminhoLeadingWhitespace, got {err:?}");
8195        };
8196        assert_eq!(nome, "caixa-teia");
8197        assert_eq!(caminho, " ../caixa-teia");
8198    }
8199
8200    #[test]
8201    fn validate_rejects_path_fonte_with_multiple_leading_spaces_caminho() {
8202        // The aligned-doc paste footgun sweep: more than one leading
8203        // space (`"   ../caixa-teia"` — the canonical "I selected the
8204        // aligned column from a four-`:fonte`-entry `:deps` block"
8205        // paste) routes through the same gate's `starts_with(' ')`
8206        // byte check. Pinned so the gate doesn't narrow to a
8207        // single-space prefix.
8208        let d = dep_with_fonte(DepSource::Path {
8209            caminho: "   ../caixa-teia".into(),
8210        });
8211        let err = d.validate().unwrap_err();
8212        assert!(
8213            matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8214            "got {err:?}",
8215        );
8216    }
8217
8218    #[test]
8219    fn validate_accepts_path_fonte_with_mid_path_space_caminho() {
8220        // The leading-space is the canonical paste-from-aligned-doc
8221        // footgun — a space mid-path (`"../my dir/caixa-teia"` — the
8222        // canonical "I have a directory with a space in its name"
8223        // idiom; ASCII `0x20` is a valid POSIX filename byte) is a
8224        // legitimate path with no whitespace-leak semantic at the
8225        // non-leading position. Pinned so the gate doesn't widen to a
8226        // full no-space-anywhere sweep that would break every
8227        // legitimate-shape space-in-filename path.
8228        let d = dep_with_fonte(DepSource::Path {
8229            caminho: "../my dir/caixa-teia".into(),
8230        });
8231        d.validate().unwrap();
8232    }
8233
8234    #[test]
8235    fn fonte_caminho_var_fires_before_leading_whitespace() {
8236        // Cascade pin: the var-expansion arm structurally precedes the
8237        // leading-whitespace arm. A value like `"$ "` would probe positive
8238        // on var (`starts_with('$')`) but the leading-byte arms walk
8239        // left-to-right so the var arm fires on the leading `$` before
8240        // the leading-whitespace arm probes. Mirrors the
8241        // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8242        // discipline on the immediate-predecessor arms.
8243        let d = dep_with_fonte(DepSource::Path {
8244            caminho: "$VAR".into(),
8245        });
8246        let err = d.validate().unwrap_err();
8247        assert!(
8248            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8249            "got {err:?}",
8250        );
8251    }
8252
8253    #[test]
8254    fn fonte_caminho_leading_whitespace_fires_before_control_char() {
8255        // Cascade pin: the leading-whitespace arm structurally precedes
8256        // the control-char arm. A value like `" ../foo\n"` probes
8257        // positive on both (starts with space AND contains LF), but
8258        // the narrower leading-byte diagnostic
8259        // (`FonteCaminhoLeadingWhitespace`) wins so the author sees the
8260        // more self-locating paste-from-aligned-doc arm first. Mirrors
8261        // the `fonte_caminho_var_fires_before_control_char` cascade
8262        // discipline on the immediate-predecessor arm.
8263        let d = dep_with_fonte(DepSource::Path {
8264            caminho: " ../foo\n".into(),
8265        });
8266        let err = d.validate().unwrap_err();
8267        assert!(
8268            matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8269            "got {err:?}",
8270        );
8271    }
8272
8273    #[test]
8274    fn fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho() {
8275        // Diagnostic-shape pin (peer with
8276        // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8277        // payload assertion on the immediate-predecessor arm): the
8278        // error's Display surfaces both the offending `:nome` and the
8279        // offending `:caminho` verbatim, so a `feira lint` run can
8280        // render the diagnostic without re-parsing and the author can
8281        // grep their caixa.lisp for `:caminho "<value>"` and fix it in
8282        // one edit.
8283        let d = dep_with_fonte(DepSource::Path {
8284            caminho: " ../caixa-teia".into(),
8285        });
8286        let rendered = d.validate().unwrap_err().to_string();
8287        assert!(
8288            rendered.contains("caixa-teia"),
8289            "diagnostic must name the offending dep: {rendered}",
8290        );
8291        assert!(
8292            rendered.contains(" ../caixa-teia"),
8293            "diagnostic must quote the offending caminho: {rendered}",
8294        );
8295        assert!(
8296            rendered.contains("space"),
8297            "diagnostic must name the space footgun: {rendered}",
8298        );
8299    }
8300
8301    #[test]
8302    fn fonte_caminho_absolute_fires_before_control_char() {
8303        // Cascade pin on the sibling leading-byte arm: a leading `/`
8304        // value with embedded control byte (`"/etc/passwd\n"`) routes
8305        // through `FonteCaminhoAbsolute` not `FonteCaminhoControlChar`
8306        // — the host-layout-leak diagnostic is the load-bearing axis,
8307        // the control byte is the secondary observation. Same precedence
8308        // logic on every prior leading-byte arm.
8309        let d = dep_with_fonte(DepSource::Path {
8310            caminho: "/etc/passwd\n".into(),
8311        });
8312        let err = d.validate().unwrap_err();
8313        assert!(
8314            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8315            "got {err:?}",
8316        );
8317    }
8318
8319    #[test]
8320    fn validate_rejects_path_fonte_with_leading_hyphen_caminho() {
8321        // The fail-before-pass-after pin for the leading-`-` CLI-arg-
8322        // injection `:caminho` shape sweep. Until this gate landed
8323        // every prior leading-byte arm passed a leading-`-` value
8324        // through: `Path::is_absolute` returns false on `-` (the
8325        // leading byte is `0x2D`, not `0x2F`), `starts_with('~')` /
8326        // `starts_with('$')` / `starts_with(' ')` all return false,
8327        // and `0x2D` sits outside the control-byte set. The lacre
8328        // embedded the value verbatim and the resolver folded it
8329        // through `Path::join` looking for a literal `./-rf` /
8330        // `./-C` / `./--upload-pack=…` subdirectory; the failure at
8331        // `Path::join` time is non-self-locating but harmless, while
8332        // the failure at every downstream `git -C {caminho}` /
8333        // `terraform -chdir={caminho}` / `find {caminho}` shell-out
8334        // is arbitrary-CLI-arg-injection because none of those
8335        // porcelains carry a `--` argument-list terminator between
8336        // the flag block and the path argument. The new arm moves the
8337        // rejection to `Caixa::from_lisp` boundary time and names
8338        // the offending dep + caminho verbatim.
8339        //
8340        // Sweep spans the canonical CLI-arg-injection shapes matching
8341        // the peer sweep on the sibling `is_git_ref_name` /
8342        // `is_git_repo_url` axes: short-flag `-rf` (the `rm -rf` /
8343        // `find -rf` reinterpretation vector), `-C` (the `git -C`
8344        // change-directory-config-injection paste), long-flag
8345        // `--upload-pack=cat /etc/passwd` (the canonical
8346        // arbitrary-command-execution vector on every git porcelain
8347        // entry point), git-config-injection `--config=core.merge=ours`,
8348        // and the degenerate single-byte `-` value.
8349        for caminho in [
8350            "-rf",
8351            "-C",
8352            "--upload-pack=cat /etc/passwd",
8353            "--config=core.merge=ours",
8354            "-",
8355        ] {
8356            let d = dep_with_fonte(DepSource::Path {
8357                caminho: caminho.into(),
8358            });
8359            let err = d.validate().unwrap_err();
8360            let DepError::FonteCaminhoLeadingHyphen { nome, caminho: got } = err else {
8361                panic!("expected FonteCaminhoLeadingHyphen for {caminho:?}, got {err:?}");
8362            };
8363            assert_eq!(nome, "caixa-teia");
8364            assert_eq!(got, caminho);
8365        }
8366    }
8367
8368    #[test]
8369    fn validate_accepts_path_fonte_with_mid_path_hyphen_caminho() {
8370        // The leading-`-` is the canonical CLI-arg-injection footgun
8371        // — a `-` anywhere else in the path (`"../caixa-teia"` — the
8372        // canonical kebab-separator-between-alphanumeric-segments
8373        // shape every DNS-1123-shaped caixa name carries; `"../-hidden"`
8374        // — a mid-path segment starting with `-`, still a legitimate
8375        // POSIX filename byte at that non-leading position because the
8376        // subprocess reads the whole `{caminho}` value as one positional
8377        // argument, so only the very first byte of the composite path
8378        // string is at the CLI-arg-injection boundary) is a legitimate
8379        // path with no CLI-flag-reinterpretation semantic at the non-
8380        // leading position of the top-level value. Pinned so the gate
8381        // doesn't widen to a full no-`-`-anywhere sweep that would
8382        // break every legitimate-shape kebab-in-filename path (i.e.
8383        // essentially every sibling-workspace caixa dep).
8384        for caminho in [
8385            "../caixa-teia",
8386            "../caixa-teia/-hidden",
8387            "./my-lib",
8388            "../foo-bar/baz",
8389        ] {
8390            let d = dep_with_fonte(DepSource::Path {
8391                caminho: caminho.into(),
8392            });
8393            d.validate()
8394                .unwrap_or_else(|e| panic!("mid-path `-` caminho {caminho:?} must pass: {e:?}"));
8395        }
8396    }
8397
8398    #[test]
8399    fn fonte_caminho_leading_whitespace_fires_before_leading_hyphen() {
8400        // Cascade pin: the leading-whitespace arm structurally precedes
8401        // the leading-hyphen arm. A value like `" -rf"` probes positive
8402        // on both (leading space AND, one byte in, a `-` — though the
8403        // leading-hyphen arm probes only the very first byte so it
8404        // wouldn't fire on this value; the pin instead documents the
8405        // arm order on the more common "leading space then a hyphen"
8406        // paste-from-aligned-doc paste-flag-shell-one-liner idiom).
8407        // The narrower leading-space diagnostic (the paste-from-aligned-
8408        // doc footgun) wins so the author sees the more self-locating
8409        // whitespace arm first. Mirrors the
8410        // `fonte_caminho_var_fires_before_leading_whitespace` cascade
8411        // discipline on the immediate-predecessor arm.
8412        let d = dep_with_fonte(DepSource::Path {
8413            caminho: " -rf".into(),
8414        });
8415        let err = d.validate().unwrap_err();
8416        assert!(
8417            matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8418            "got {err:?}",
8419        );
8420    }
8421
8422    #[test]
8423    fn fonte_caminho_leading_hyphen_fires_before_control_char() {
8424        // Cascade pin: the leading-hyphen arm structurally precedes
8425        // the control-char arm. A value like `"-rf\n"` probes positive
8426        // on both (starts with `-` AND contains LF), but the narrower
8427        // leading-byte diagnostic (`FonteCaminhoLeadingHyphen`) wins so
8428        // the author sees the more self-locating CLI-arg-injection arm
8429        // first. Mirrors the
8430        // `fonte_caminho_leading_whitespace_fires_before_control_char`
8431        // cascade discipline on the immediate-predecessor arm.
8432        let d = dep_with_fonte(DepSource::Path {
8433            caminho: "-rf\n".into(),
8434        });
8435        let err = d.validate().unwrap_err();
8436        assert!(
8437            matches!(err, DepError::FonteCaminhoLeadingHyphen { .. }),
8438            "got {err:?}",
8439        );
8440    }
8441
8442    #[test]
8443    fn fonte_caminho_leading_hyphen_diagnostic_carries_offending_dep_and_caminho() {
8444        // Diagnostic-shape pin (peer with
8445        // `fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho`'s
8446        // payload assertion on the immediate-predecessor arm): the
8447        // error's Display surfaces both the offending `:nome` and the
8448        // offending `:caminho` verbatim plus the CLI-argument-injection
8449        // vocabulary, so a `feira lint` run can render the diagnostic
8450        // without re-parsing and the author can grep their caixa.lisp
8451        // for `:caminho "<value>"` and fix it in one edit.
8452        let d = dep_with_fonte(DepSource::Path {
8453            caminho: "--upload-pack=cat /etc/passwd".into(),
8454        });
8455        let rendered = d.validate().unwrap_err().to_string();
8456        assert!(
8457            rendered.contains("caixa-teia"),
8458            "diagnostic must name the offending dep: {rendered}",
8459        );
8460        assert!(
8461            rendered.contains("--upload-pack=cat /etc/passwd"),
8462            "diagnostic must quote the offending caminho: {rendered}",
8463        );
8464        assert!(
8465            rendered.contains("CLI-argument-injection"),
8466            "diagnostic must name the CLI-argument-injection vector: {rendered}",
8467        );
8468        assert!(
8469            rendered.contains("`-`"),
8470            "diagnostic must name the offending byte: {rendered}",
8471        );
8472    }
8473
8474    #[test]
8475    fn fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte() {
8476        // Diagnostic-shape pin (peer with
8477        // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8478        // payload assertion on the immediate-predecessor arm): the
8479        // error's Display surfaces the offending `:nome`, the
8480        // offending `:caminho` verbatim, and the offending byte in
8481        // hex form (`0x09` for tab) so a `feira lint` run can render
8482        // the diagnostic without re-parsing.
8483        let d = dep_with_fonte(DepSource::Path {
8484            caminho: "../caixa\tteia".into(),
8485        });
8486        let rendered = d.validate().unwrap_err().to_string();
8487        assert!(
8488            rendered.contains("caixa-teia"),
8489            "diagnostic must name the offending dep: {rendered}",
8490        );
8491        assert!(
8492            rendered.contains("../caixa\tteia"),
8493            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8494        );
8495        assert!(
8496            rendered.contains("0x09"),
8497            "diagnostic must name the offending byte in hex: {rendered:?}",
8498        );
8499    }
8500
8501    #[test]
8502    fn validate_rejects_path_fonte_with_caminho_carrying_backslash() {
8503        // The fail-before-pass-after pin for the canonical Windows-
8504        // path-separator paste footgun: an author who pastes a path
8505        // from Windows-Explorer's `Copy as path`, PowerShell's
8506        // `Get-Location`, or any CMD/Cygwin/MSYS shell prompt
8507        // produces `..\caixa-teia`-shape values that silently passed
8508        // every prior arm (`Path::is_absolute("..\\caixa-teia")` is
8509        // false; `\` is neither a leading-byte sentinel nor a
8510        // control byte). On POSIX resolvers the value rides through
8511        // `Path::join` as a literal directory name and fails at
8512        // resolve time with `No such file or directory`; on Windows
8513        // resolvers the value resolves to the parent's sibling — two
8514        // distinct directories for the byte-identical caixa.lisp.
8515        // The new arm moves the rejection to validate time and names
8516        // the offending dep + caminho verbatim.
8517        let d = dep_with_fonte(DepSource::Path {
8518            caminho: "..\\caixa-teia".into(),
8519        });
8520        let err = d.validate().unwrap_err();
8521        let DepError::FonteCaminhoBackslash { nome, caminho } = err else {
8522            panic!("expected FonteCaminhoBackslash, got {err:?}");
8523        };
8524        assert_eq!(nome, "caixa-teia");
8525        assert_eq!(caminho, "..\\caixa-teia");
8526    }
8527
8528    #[test]
8529    fn validate_rejects_path_fonte_with_caminho_carrying_windows_drive_letter() {
8530        // The Windows drive-letter paste shape (`C:\work\caixa-teia`
8531        // out of Explorer / `cd`-and-`pwd`-on-Windows). On POSIX
8532        // hosts `Path::is_absolute("C:\\work\\caixa-teia")` returns
8533        // false (POSIX absolute paths start with `/`, drive letters
8534        // are not a POSIX concept), so the b94fd83 absolute arm
8535        // doesn't fire; the value contains `\` bytes that this arm
8536        // now catches with the more self-locating Windows-path-
8537        // separator diagnostic. Pinned separately from the bare
8538        // `..\caixa-teia` shape so a future arm that targets only
8539        // leading-`..\` doesn't regress the drive-letter coverage.
8540        let d = dep_with_fonte(DepSource::Path {
8541            caminho: "C:\\work\\caixa-teia".into(),
8542        });
8543        let err = d.validate().unwrap_err();
8544        assert!(
8545            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8546            "got {err:?}",
8547        );
8548    }
8549
8550    #[test]
8551    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backslash() {
8552        // The trailing-`\` shape (`..\caixa-teia\` — the canonical
8553        // PowerShell tab-completion-on-a-directory append). Pinned
8554        // separately from the embedded-`\` shape so the gate's
8555        // contract is "any `\` anywhere", not "any `\` not at end".
8556        let d = dep_with_fonte(DepSource::Path {
8557            caminho: "..\\caixa-teia\\".into(),
8558        });
8559        let err = d.validate().unwrap_err();
8560        assert!(
8561            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8562            "got {err:?}",
8563        );
8564    }
8565
8566    #[test]
8567    fn validate_accepts_path_fonte_with_caminho_carrying_legitimate_forward_slash() {
8568        // The positive-control pin: the gate targets `\` only,
8569        // never `/`. The canonical relative POSIX path
8570        // (`../caixa-teia/foo/bar`) must continue to validate cleanly
8571        // so legitimate nested-directory deps aren't broken. Pinned
8572        // so the gate doesn't accidentally widen to a "no path
8573        // separators at all" sweep.
8574        let d = dep_with_fonte(DepSource::Path {
8575            caminho: "../caixa-teia/foo/bar".into(),
8576        });
8577        d.validate().unwrap();
8578    }
8579
8580    #[test]
8581    fn fonte_caminho_control_char_fires_before_backslash() {
8582        // Cascade pin: the control-char arm structurally precedes the
8583        // backslash arm. A value like `"..\caixa\0teia"` probes
8584        // positive on both (`\` byte + NUL byte), but the control-
8585        // char diagnostic wins so the author sees the more self-
8586        // locating POSIX-syscall-rejected-byte diagnostic first
8587        // (NUL outright breaks `CString::new` at every `std::fs`
8588        // syscall boundary; the `\` divergence is the cross-OS-
8589        // separator axis). Mirrors the
8590        // `fonte_caminho_var_fires_before_control_char` cascade
8591        // discipline on the immediate-predecessor arm.
8592        let d = dep_with_fonte(DepSource::Path {
8593            caminho: "..\\caixa\0teia".into(),
8594        });
8595        let err = d.validate().unwrap_err();
8596        assert!(
8597            matches!(err, DepError::FonteCaminhoControlChar { .. }),
8598            "got {err:?}",
8599        );
8600    }
8601
8602    #[test]
8603    fn fonte_caminho_absolute_fires_before_backslash() {
8604        // Cascade pin on the load-bearing leading-byte arm: a leading
8605        // `/` value with embedded `\` (`/etc/passwd\foo`) routes
8606        // through `FonteCaminhoAbsolute` not `FonteCaminhoBackslash`
8607        // — the host-layout-leak diagnostic is the load-bearing
8608        // axis, the `\` byte is the secondary observation. Same
8609        // precedence logic as every prior leading-byte arm.
8610        let d = dep_with_fonte(DepSource::Path {
8611            caminho: "/etc/passwd\\foo".into(),
8612        });
8613        let err = d.validate().unwrap_err();
8614        assert!(
8615            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8616            "got {err:?}",
8617        );
8618    }
8619
8620    #[test]
8621    fn fonte_caminho_var_fires_before_backslash() {
8622        // Cascade pin on the var-expansion arm: a leading-`$` value
8623        // with embedded `\` (`$WORKSPACE\caixa-teia` — the canonical
8624        // PowerShell-env-var paste-from-CI-manifest footgun) routes
8625        // through `FonteCaminhoVarExpansion` not `FonteCaminhoBackslash`.
8626        // The shell-expansion diagnostic is the more self-locating
8627        // axis since both the leading `$` and the embedded `\`
8628        // are Windows-shell artifacts but the `$` is the root-cause
8629        // surface (an author who removes the `$` is likely to leave
8630        // the `\` too).
8631        let d = dep_with_fonte(DepSource::Path {
8632            caminho: "$WORKSPACE\\caixa-teia".into(),
8633        });
8634        let err = d.validate().unwrap_err();
8635        assert!(
8636            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8637            "got {err:?}",
8638        );
8639    }
8640
8641    #[test]
8642    fn fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho() {
8643        // Diagnostic-shape pin (peer with the prior
8644        // `fonte_caminho_*_diagnostic_carries_*` payload assertions
8645        // on every preceding arm): the error's Display surfaces the
8646        // offending `:nome` and the offending `:caminho` verbatim
8647        // so a `feira lint` run can render the diagnostic without
8648        // re-parsing.
8649        let d = dep_with_fonte(DepSource::Path {
8650            caminho: "..\\caixa-teia".into(),
8651        });
8652        let rendered = d.validate().unwrap_err().to_string();
8653        assert!(
8654            rendered.contains("caixa-teia"),
8655            "diagnostic must name the offending dep: {rendered}",
8656        );
8657        assert!(
8658            rendered.contains("..\\caixa-teia"),
8659            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8660        );
8661        assert!(
8662            rendered.contains('\\'),
8663            "diagnostic must reference the backslash footgun: {rendered:?}",
8664        );
8665    }
8666
8667    #[test]
8668    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_slash() {
8669        // The fail-before-pass-after pin for the canonical trailing-`/`
8670        // paste footgun: an author who shell-tab-completes a sibling
8671        // directory (every interactive shell — bash/zsh/fish/nushell —
8672        // appends `/` on tab-completing a directory) produces
8673        // `"../caixa-teia/"`-shape values that silently passed every
8674        // prior arm (the leading byte is `.`, no control bytes, no
8675        // backslash). `Path::join` resolves both shapes to the same
8676        // directory at the resolver, but the lacre embeds the value
8677        // verbatim and the BLAKE3 closures diverge across two
8678        // workstations whose authors differ only in tab-completion
8679        // habits.
8680        let d = dep_with_fonte(DepSource::Path {
8681            caminho: "../caixa-teia/".into(),
8682        });
8683        let err = d.validate().unwrap_err();
8684        let DepError::FonteCaminhoTrailingSlash { nome, caminho } = err else {
8685            panic!("expected FonteCaminhoTrailingSlash, got {err:?}");
8686        };
8687        assert_eq!(nome, "caixa-teia");
8688        assert_eq!(caminho, "../caixa-teia/");
8689    }
8690
8691    #[test]
8692    fn validate_rejects_path_fonte_with_caminho_carrying_bare_dot_slash() {
8693        // The `"./"` shape (the canonical "I meant the caixa.lisp's own
8694        // directory and tab-completed it" footgun). Pinned separately
8695        // from the canonical `"../caixa-teia/"` shape so the gate's
8696        // contract is "any trailing `/`", not "trailing `/` after a leaf
8697        // name".
8698        let d = dep_with_fonte(DepSource::Path {
8699            caminho: "./".into(),
8700        });
8701        let err = d.validate().unwrap_err();
8702        assert!(
8703            matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8704            "got {err:?}",
8705        );
8706    }
8707
8708    #[test]
8709    fn validate_rejects_path_fonte_with_caminho_carrying_consecutive_trailing_slashes() {
8710        // The `"foo//"` shape (the canonical "I pasted from a CI manifest
8711        // that double-templated `${VAR}/` over an already-`/`-suffixed
8712        // path" footgun). The gate fires on the last byte being `/`
8713        // regardless of how many `/` precede it; the arm contract is
8714        // "the value ends with `/`", structurally.
8715        let d = dep_with_fonte(DepSource::Path {
8716            caminho: "../caixa-teia//".into(),
8717        });
8718        let err = d.validate().unwrap_err();
8719        assert!(
8720            matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8721            "got {err:?}",
8722        );
8723    }
8724
8725    #[test]
8726    fn validate_rejects_path_fonte_with_caminho_carrying_dotdot_trailing_slash() {
8727        // The `"../"` shape (the canonical "I want the parent" tab-
8728        // completion footgun on a bare `..` path). Pinned separately so
8729        // the gate doesn't accidentally narrow to "trailing `/` only on
8730        // multi-segment paths".
8731        let d = dep_with_fonte(DepSource::Path {
8732            caminho: "../".into(),
8733        });
8734        let err = d.validate().unwrap_err();
8735        assert!(
8736            matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8737            "got {err:?}",
8738        );
8739    }
8740
8741    #[test]
8742    fn validate_accepts_path_fonte_with_caminho_carrying_internal_slashes() {
8743        // The positive-control pin: the gate targets the trailing byte
8744        // only, never internal `/` separators. The canonical nested
8745        // relative POSIX path (`"../caixa-teia/foo/bar"`) must continue
8746        // to validate cleanly so legitimate deeply-nested deps aren't
8747        // broken. Pinned so the gate doesn't accidentally widen to a
8748        // "no `/` separators anywhere" sweep that would defeat the
8749        // entire path-fonte author surface.
8750        let d = dep_with_fonte(DepSource::Path {
8751            caminho: "../caixa-teia/foo/bar".into(),
8752        });
8753        d.validate().unwrap();
8754    }
8755
8756    #[test]
8757    fn validate_accepts_path_fonte_with_caminho_carrying_bare_dot() {
8758        // The positive-control pin on the degenerate single-`.` shape
8759        // (the canonical "the caixa.lisp's own directory" idiom). The
8760        // gate fires on the trailing byte being `/`, not on the path
8761        // being short, so `"."` (one byte, not `/`) must continue to
8762        // validate cleanly.
8763        let d = dep_with_fonte(DepSource::Path {
8764            caminho: ".".into(),
8765        });
8766        d.validate().unwrap();
8767    }
8768
8769    #[test]
8770    fn fonte_caminho_control_char_fires_before_trailing_slash() {
8771        // Cascade pin: the control-char arm structurally precedes the
8772        // trailing-slash arm. A value like `"../foo\n/"` ends in `/`
8773        // but the embedded LF (`0x0A`) is the load-bearing diagnostic
8774        // (control bytes are the paste-from-multiline-doc footgun the
8775        // d624c8d arm already closes). Mirrors the
8776        // `fonte_caminho_control_char_fires_before_backslash` cascade
8777        // discipline on the immediate-predecessor arm.
8778        let d = dep_with_fonte(DepSource::Path {
8779            caminho: "../foo\n/".into(),
8780        });
8781        let err = d.validate().unwrap_err();
8782        assert!(
8783            matches!(err, DepError::FonteCaminhoControlChar { .. }),
8784            "got {err:?}",
8785        );
8786    }
8787
8788    #[test]
8789    fn fonte_caminho_backslash_fires_before_trailing_slash() {
8790        // Cascade pin on the backslash arm: a value like `"..\foo/"`
8791        // ends in `/` but the embedded `\` is the load-bearing
8792        // diagnostic (the cross-host-OS-separator divergence vector
8793        // the 3a4e1d7 arm closes). Same precedence logic as the prior
8794        // narrower-diagnostic-first cascade.
8795        let d = dep_with_fonte(DepSource::Path {
8796            caminho: "..\\caixa-teia/".into(),
8797        });
8798        let err = d.validate().unwrap_err();
8799        assert!(
8800            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8801            "got {err:?}",
8802        );
8803    }
8804
8805    #[test]
8806    fn fonte_caminho_absolute_fires_before_trailing_slash() {
8807        // Cascade pin on the load-bearing leading-byte arm: a leading
8808        // `/` value with a trailing `/` (`"/etc/passwd/"`) routes
8809        // through `FonteCaminhoAbsolute` not `FonteCaminhoTrailingSlash`
8810        // — the host-layout-leak diagnostic is the load-bearing axis,
8811        // the trailing `/` is the secondary observation. Same
8812        // precedence logic as every prior leading-byte arm.
8813        let d = dep_with_fonte(DepSource::Path {
8814            caminho: "/etc/passwd/".into(),
8815        });
8816        let err = d.validate().unwrap_err();
8817        assert!(
8818            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8819            "got {err:?}",
8820        );
8821    }
8822
8823    #[test]
8824    fn fonte_caminho_trailing_slash_diagnostic_carries_offending_dep_and_caminho() {
8825        // Diagnostic-shape pin (peer with the prior
8826        // `fonte_caminho_*_diagnostic_carries_*` payload assertions on
8827        // every preceding arm): the error's Display surfaces the
8828        // offending `:nome` and the offending `:caminho` verbatim so a
8829        // `feira lint` run can render the diagnostic without re-parsing.
8830        let d = dep_with_fonte(DepSource::Path {
8831            caminho: "../caixa-teia/".into(),
8832        });
8833        let rendered = d.validate().unwrap_err().to_string();
8834        assert!(
8835            rendered.contains("caixa-teia"),
8836            "diagnostic must name the offending dep: {rendered}",
8837        );
8838        assert!(
8839            rendered.contains("../caixa-teia/"),
8840            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8841        );
8842        assert!(
8843            rendered.contains("trailing"),
8844            "diagnostic must reference the trailing-slash footgun: {rendered:?}",
8845        );
8846    }
8847
8848    // -- :caminho shell-redirection metacharacter arm -----------------------
8849
8850    #[test]
8851    fn validate_rejects_path_fonte_with_caminho_carrying_gt_redirection() {
8852        // The fail-before-pass-after pin for the canonical output-redirection
8853        // paste footgun: an author copies a shell pipeline tail
8854        // (`"../caixa-teia>build.log"` — the canonical "I selected the whole
8855        // line including the `> build.log` redirect" idiom) and silently
8856        // passed every prior arm (`Path::is_absolute` false on `..`, no
8857        // control bytes, no backslash, doesn't end in `/`). The lacre
8858        // embedded the value verbatim, the resolver folded it through
8859        // `Path::join` looking for a literal `./../caixa-teia>build.log`
8860        // subdirectory, and the failure surfaced at resolve time with a
8861        // non-self-locating `No such file or directory` error. The new arm
8862        // moves the rejection to validate time and names the offending dep
8863        // + caminho + byte verbatim.
8864        let d = dep_with_fonte(DepSource::Path {
8865            caminho: "../caixa-teia>build.log".into(),
8866        });
8867        let err = d.validate().unwrap_err();
8868        let DepError::FonteCaminhoShellRedirection {
8869            nome,
8870            caminho,
8871            byte,
8872        } = err
8873        else {
8874            panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8875        };
8876        assert_eq!(nome, "caixa-teia");
8877        assert_eq!(caminho, "../caixa-teia>build.log");
8878        assert_eq!(byte, b'>');
8879    }
8880
8881    #[test]
8882    fn validate_rejects_path_fonte_with_caminho_carrying_lt_redirection() {
8883        // The symmetric input-redirection paste shape
8884        // (`"../caixa-teia<input.lisp"` — the canonical "I copied a
8885        // `command < input.lisp` line from a tatara-lisp REPL log"
8886        // idiom). Pinned separately from the `>` shape so the gate's
8887        // contract is "any `<` or `>` anywhere", not single-byte coverage.
8888        let d = dep_with_fonte(DepSource::Path {
8889            caminho: "../caixa-teia<input.lisp".into(),
8890        });
8891        let err = d.validate().unwrap_err();
8892        let DepError::FonteCaminhoShellRedirection { byte, .. } = err else {
8893            panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8894        };
8895        assert_eq!(byte, b'<');
8896    }
8897
8898    #[test]
8899    fn validate_rejects_path_fonte_with_caminho_carrying_leading_gt_redirection() {
8900        // Leading-position `>` shape (`">../caixa-teia"` — the degenerate
8901        // "I forgot the source side of the redirect" idiom). Pinned
8902        // separately from the embedded-byte shapes so the gate covers
8903        // every position, not only mid-path.
8904        let d = dep_with_fonte(DepSource::Path {
8905            caminho: ">../caixa-teia".into(),
8906        });
8907        let err = d.validate().unwrap_err();
8908        assert!(
8909            matches!(
8910                err,
8911                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8912            ),
8913            "got {err:?}",
8914        );
8915    }
8916
8917    #[test]
8918    fn validate_rejects_path_fonte_with_caminho_carrying_double_gt_append() {
8919        // The bash append-redirection shape (`"../caixa-teia>>build.log"` —
8920        // the canonical "I copied a `>>` append redirect" idiom). The arm
8921        // fires on the first `>` encountered; pinned so a future arm that
8922        // tries to distinguish `>` from `>>` doesn't break the broader
8923        // contract.
8924        let d = dep_with_fonte(DepSource::Path {
8925            caminho: "../caixa-teia>>build.log".into(),
8926        });
8927        let err = d.validate().unwrap_err();
8928        assert!(
8929            matches!(
8930                err,
8931                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8932            ),
8933            "got {err:?}",
8934        );
8935    }
8936
8937    #[test]
8938    fn validate_accepts_path_fonte_with_caminho_carrying_no_redirection() {
8939        // The positive-control pin: the gate targets only `<` / `>`,
8940        // never adjacent printable ASCII or POSIX-valid bytes. The
8941        // canonical relative POSIX path (`"../caixa-teia"`) and a
8942        // nested deeply-pathed variant (`"../caixa-teia/foo/bar"`) must
8943        // continue to validate cleanly so the gate doesn't widen to a
8944        // "no printable punctuation anywhere" sweep that would defeat
8945        // the entire path-fonte author surface.
8946        let d = dep_with_fonte(DepSource::Path {
8947            caminho: "../caixa-teia/foo/bar".into(),
8948        });
8949        d.validate().unwrap();
8950    }
8951
8952    #[test]
8953    fn fonte_caminho_backslash_fires_before_shell_redirection() {
8954        // Cascade pin on the immediate-predecessor arm: a value carrying
8955        // both `\` and `<` / `>` (`"..\caixa-teia>build.log"` — the
8956        // canonical "I pasted a Windows-shell command with output
8957        // redirect" footgun) routes through `FonteCaminhoBackslash` not
8958        // `FonteCaminhoShellRedirection`. The cross-host-OS-separator
8959        // divergence is the load-bearing axis (an author who removes
8960        // the `\` is the root-cause edit; the `>` falls away in the
8961        // same edit since it's downstream of the Windows-shell
8962        // convention).
8963        let d = dep_with_fonte(DepSource::Path {
8964            caminho: "..\\caixa-teia>build.log".into(),
8965        });
8966        let err = d.validate().unwrap_err();
8967        assert!(
8968            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8969            "got {err:?}",
8970        );
8971    }
8972
8973    #[test]
8974    fn fonte_caminho_control_char_fires_before_shell_redirection() {
8975        // Cascade pin on the embedded-control-byte arm: a value carrying
8976        // both a control byte and `<` / `>` (`"../foo\n>bar"` — the
8977        // canonical paste-from-multiline-doc footgun where a newline
8978        // landed mid-caminho) routes through `FonteCaminhoControlChar`
8979        // not `FonteCaminhoShellRedirection`. The POSIX-syscall-
8980        // rejected-byte / NUL-`CString::new`-fail diagnostic is the
8981        // load-bearing axis on every value that probes positive for
8982        // both — mirrors the cascade discipline on every prior arm.
8983        let d = dep_with_fonte(DepSource::Path {
8984            caminho: "../foo\n>bar".into(),
8985        });
8986        let err = d.validate().unwrap_err();
8987        assert!(
8988            matches!(err, DepError::FonteCaminhoControlChar { .. }),
8989            "got {err:?}",
8990        );
8991    }
8992
8993    #[test]
8994    fn fonte_caminho_absolute_fires_before_shell_redirection() {
8995        // Cascade pin on the load-bearing leading-byte arm: a leading
8996        // `/` value with embedded `<` / `>` (`"/etc/passwd>out"`)
8997        // routes through `FonteCaminhoAbsolute` not
8998        // `FonteCaminhoShellRedirection` — the host-layout-leak
8999        // diagnostic is the load-bearing axis, the `>` byte is the
9000        // secondary observation. Same precedence logic as every prior
9001        // leading-byte arm.
9002        let d = dep_with_fonte(DepSource::Path {
9003            caminho: "/etc/passwd>out".into(),
9004        });
9005        let err = d.validate().unwrap_err();
9006        assert!(
9007            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9008            "got {err:?}",
9009        );
9010    }
9011
9012    #[test]
9013    fn fonte_caminho_shell_redirection_fires_before_trailing_slash() {
9014        // Cascade pin on the immediate-successor arm: a value carrying
9015        // both `<` / `>` and a trailing `/` (`"../foo></"` — the
9016        // canonical "I tab-completed a path that already had a
9017        // redirect" footgun) routes through `FonteCaminhoShellRedirection`
9018        // not `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9019        // the more semantic-locating axis (an author who removes the
9020        // `<` / `>` typically also drops the trailing separator since
9021        // both are paste-from-shell artifacts).
9022        let d = dep_with_fonte(DepSource::Path {
9023            caminho: "../foo></".into(),
9024        });
9025        let err = d.validate().unwrap_err();
9026        assert!(
9027            matches!(
9028                err,
9029                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9030            ),
9031            "got {err:?}",
9032        );
9033    }
9034
9035    #[test]
9036    fn fonte_caminho_shell_redirection_diagnostic_carries_offending_dep_caminho_byte() {
9037        // Diagnostic-shape pin (peer with
9038        // `fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte`'s
9039        // payload assertion on the closest peer arm that also carries a
9040        // `byte` field): the error's Display surfaces the offending
9041        // `:nome`, the offending `:caminho` verbatim, and the offending
9042        // byte in hex (`0x3c` for `<`, `0x3e` for `>`) so a `feira lint`
9043        // run can render the diagnostic without re-parsing.
9044        let d = dep_with_fonte(DepSource::Path {
9045            caminho: "../caixa-teia>build.log".into(),
9046        });
9047        let rendered = d.validate().unwrap_err().to_string();
9048        assert!(
9049            rendered.contains("caixa-teia"),
9050            "diagnostic must name the offending dep: {rendered}",
9051        );
9052        assert!(
9053            rendered.contains("../caixa-teia>build.log"),
9054            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9055        );
9056        assert!(
9057            rendered.contains("0x3e"),
9058            "diagnostic must name the offending byte in hex: {rendered:?}",
9059        );
9060        assert!(
9061            rendered.contains("redirection"),
9062            "diagnostic must name the shell-redirection footgun: {rendered:?}",
9063        );
9064    }
9065
9066    // -- :caminho shell-pipe metacharacter arm ----------------------------
9067
9068    #[test]
9069    fn validate_rejects_path_fonte_with_caminho_carrying_pipe() {
9070        // The fail-before-pass-after pin for the canonical shell-pipe
9071        // paste footgun: an author copies a shell-history line
9072        // (`"../caixa-teia | grep foo"` — the canonical "I selected
9073        // the whole `ls dir | grep` line out of zsh history") and
9074        // silently passed every prior arm (`Path::is_absolute` false
9075        // on `..`, no control bytes, no backslash, no `<` / `>`,
9076        // doesn't end in `/`). The lacre embedded the value verbatim,
9077        // the resolver folded it through `Path::join` looking for a
9078        // literal `./../caixa-teia | grep foo` subdirectory, and the
9079        // failure surfaced at resolve time with a non-self-locating
9080        // `No such file or directory` error. The new arm moves the
9081        // rejection to validate time and names the offending dep +
9082        // caminho verbatim.
9083        let d = dep_with_fonte(DepSource::Path {
9084            caminho: "../caixa-teia | grep foo".into(),
9085        });
9086        let err = d.validate().unwrap_err();
9087        let DepError::FonteCaminhoShellPipe { nome, caminho } = err else {
9088            panic!("expected FonteCaminhoShellPipe, got {err:?}");
9089        };
9090        assert_eq!(nome, "caixa-teia");
9091        assert_eq!(caminho, "../caixa-teia | grep foo");
9092    }
9093
9094    #[test]
9095    fn validate_rejects_path_fonte_with_caminho_carrying_leading_pipe() {
9096        // Leading-position `|` shape (`"|../caixa-teia"` — the
9097        // degenerate "I forgot the source side of the pipe" idiom).
9098        // Pinned separately from the embedded-byte shape so the gate
9099        // covers every position, not only mid-path.
9100        let d = dep_with_fonte(DepSource::Path {
9101            caminho: "|../caixa-teia".into(),
9102        });
9103        let err = d.validate().unwrap_err();
9104        assert!(
9105            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9106            "got {err:?}",
9107        );
9108    }
9109
9110    #[test]
9111    fn validate_rejects_path_fonte_with_caminho_carrying_double_pipe_or() {
9112        // The bash short-circuit-OR shape (`"../caixa-teia||fallback"`
9113        // — the canonical "I copied a `cmd-a || cmd-b` fallback line"
9114        // idiom). The arm fires on the first `|` encountered; pinned
9115        // so a future arm that tries to distinguish `|` from `||`
9116        // doesn't break the broader contract.
9117        let d = dep_with_fonte(DepSource::Path {
9118            caminho: "../caixa-teia||fallback".into(),
9119        });
9120        let err = d.validate().unwrap_err();
9121        assert!(
9122            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9123            "got {err:?}",
9124        );
9125    }
9126
9127    #[test]
9128    fn validate_accepts_path_fonte_with_caminho_carrying_no_pipe() {
9129        // The positive-control pin: the gate targets only `|`, never
9130        // adjacent printable ASCII or POSIX-valid bytes. The canonical
9131        // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9132        // pathed variant with adjacent printable punctuation
9133        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9134        // cleanly so the gate doesn't widen to a "no printable
9135        // punctuation anywhere" sweep that would defeat the entire
9136        // path-fonte author surface.
9137        let d = dep_with_fonte(DepSource::Path {
9138            caminho: "../caixa-teia/sub-dir.v2".into(),
9139        });
9140        d.validate().unwrap();
9141    }
9142
9143    #[test]
9144    fn fonte_caminho_shell_redirection_fires_before_shell_pipe() {
9145        // Cascade pin on the immediate-predecessor arm: a value carrying
9146        // both `<` / `>` and `|` (`"../caixa-teia<input|tee"` — the
9147        // canonical "I pasted a `cmd < input | tee` pipeline tail"
9148        // footgun) routes through `FonteCaminhoShellRedirection` not
9149        // `FonteCaminhoShellPipe`. The input/output redirection
9150        // metachar carries the more self-locating `byte: u8` payload
9151        // (it names which of `<` or `>` triggered), so the prior arm
9152        // wins on every probe-as-both value — same cascade discipline
9153        // every prior `:caminho` arm establishes.
9154        let d = dep_with_fonte(DepSource::Path {
9155            caminho: "../caixa-teia<input|tee".into(),
9156        });
9157        let err = d.validate().unwrap_err();
9158        assert!(
9159            matches!(
9160                err,
9161                DepError::FonteCaminhoShellRedirection { byte: b'<', .. }
9162            ),
9163            "got {err:?}",
9164        );
9165    }
9166
9167    #[test]
9168    fn fonte_caminho_backslash_fires_before_shell_pipe() {
9169        // Cascade pin on the upstream backslash arm: a value carrying
9170        // both `\` and `|` (`"..\caixa-teia|tee"` — the canonical
9171        // "I pasted a Windows-shell command with pipe to tee"
9172        // footgun) routes through `FonteCaminhoBackslash` not
9173        // `FonteCaminhoShellPipe`. The cross-host-OS-separator
9174        // divergence is the load-bearing axis on every probe-as-both
9175        // value (an author who removes the `\` is the root-cause edit;
9176        // the `|` falls away in the same edit since it's downstream of
9177        // the Windows-shell convention).
9178        let d = dep_with_fonte(DepSource::Path {
9179            caminho: "..\\caixa-teia|tee".into(),
9180        });
9181        let err = d.validate().unwrap_err();
9182        assert!(
9183            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9184            "got {err:?}",
9185        );
9186    }
9187
9188    #[test]
9189    fn fonte_caminho_control_char_fires_before_shell_pipe() {
9190        // Cascade pin on the embedded-control-byte arm: a value
9191        // carrying both a control byte and `|` (`"../foo\n|bar"` —
9192        // the canonical paste-from-multiline-doc footgun where a
9193        // newline landed mid-caminho) routes through
9194        // `FonteCaminhoControlChar` not `FonteCaminhoShellPipe`. The
9195        // POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9196        // diagnostic is the load-bearing axis on every value that
9197        // probes positive for both — mirrors the cascade discipline
9198        // on every prior arm.
9199        let d = dep_with_fonte(DepSource::Path {
9200            caminho: "../foo\n|bar".into(),
9201        });
9202        let err = d.validate().unwrap_err();
9203        assert!(
9204            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9205            "got {err:?}",
9206        );
9207    }
9208
9209    #[test]
9210    fn fonte_caminho_absolute_fires_before_shell_pipe() {
9211        // Cascade pin on the load-bearing leading-byte arm: a leading
9212        // `/` value with embedded `|` (`"/etc/passwd|tee"`) routes
9213        // through `FonteCaminhoAbsolute` not `FonteCaminhoShellPipe`
9214        // — the host-layout-leak diagnostic is the load-bearing axis,
9215        // the `|` byte is the secondary observation. Same precedence
9216        // logic as every prior leading-byte arm.
9217        let d = dep_with_fonte(DepSource::Path {
9218            caminho: "/etc/passwd|tee".into(),
9219        });
9220        let err = d.validate().unwrap_err();
9221        assert!(
9222            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9223            "got {err:?}",
9224        );
9225    }
9226
9227    #[test]
9228    fn fonte_caminho_shell_pipe_fires_before_trailing_slash() {
9229        // Cascade pin on the immediate-successor arm: a value carrying
9230        // both `|` and a trailing `/` (`"../foo|tee/"` — the canonical
9231        // "I tab-completed a path that already had a pipeline tail"
9232        // footgun) routes through `FonteCaminhoShellPipe` not
9233        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9234        // the more semantic-locating axis (an author who removes the
9235        // `|` typically also drops the trailing separator since both
9236        // are paste-from-shell artifacts).
9237        let d = dep_with_fonte(DepSource::Path {
9238            caminho: "../foo|tee/".into(),
9239        });
9240        let err = d.validate().unwrap_err();
9241        assert!(
9242            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9243            "got {err:?}",
9244        );
9245    }
9246
9247    #[test]
9248    fn fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho() {
9249        // Diagnostic-shape pin (peer with
9250        // `fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho`
9251        // on the closest single-byte peer arm): the error's Display
9252        // surfaces the offending `:nome` and the offending `:caminho`
9253        // verbatim, and names the shell-pipe footgun explicitly so a
9254        // `feira lint` run can render the diagnostic without
9255        // re-parsing.
9256        let d = dep_with_fonte(DepSource::Path {
9257            caminho: "../caixa-teia | grep foo".into(),
9258        });
9259        let rendered = d.validate().unwrap_err().to_string();
9260        assert!(
9261            rendered.contains("caixa-teia"),
9262            "diagnostic must name the offending dep: {rendered}",
9263        );
9264        assert!(
9265            rendered.contains("../caixa-teia | grep foo"),
9266            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9267        );
9268        assert!(
9269            rendered.contains('|'),
9270            "diagnostic must reference the pipe footgun: {rendered:?}",
9271        );
9272        assert!(
9273            rendered.contains("pipe"),
9274            "diagnostic must name the shell-pipe footgun: {rendered:?}",
9275        );
9276    }
9277
9278    // -- :caminho shell-command-separator metacharacter arm ---------------
9279
9280    #[test]
9281    fn validate_rejects_path_fonte_with_caminho_carrying_semicolon() {
9282        // The fail-before-pass-after pin for the canonical shell-command-
9283        // separator paste footgun: an author copies a shell one-liner
9284        // (`"../caixa-teia; rm -rf build"` — the canonical "I selected the
9285        // whole `cd path; do-thing` chain out of a shell-history block")
9286        // and silently passed every prior arm (`Path::is_absolute` false
9287        // on `..`, no control bytes, no backslash, no `<` / `>`, no `|`,
9288        // doesn't end in `/`). The lacre embedded the value verbatim, the
9289        // resolver folded it through `Path::join` looking for a literal
9290        // `./../caixa-teia; rm -rf build` subdirectory, and the failure
9291        // surfaced at resolve time with a non-self-locating `No such file
9292        // or directory` error. The new arm moves the rejection to validate
9293        // time and names the offending dep + caminho verbatim.
9294        let d = dep_with_fonte(DepSource::Path {
9295            caminho: "../caixa-teia; rm -rf build".into(),
9296        });
9297        let err = d.validate().unwrap_err();
9298        let DepError::FonteCaminhoShellSemicolon { nome, caminho } = err else {
9299            panic!("expected FonteCaminhoShellSemicolon, got {err:?}");
9300        };
9301        assert_eq!(nome, "caixa-teia");
9302        assert_eq!(caminho, "../caixa-teia; rm -rf build");
9303    }
9304
9305    #[test]
9306    fn validate_rejects_path_fonte_with_caminho_carrying_leading_semicolon() {
9307        // Leading-position `;` shape (`";../caixa-teia"` — the degenerate
9308        // "I forgot the prior command side of the separator" idiom).
9309        // Pinned separately from the embedded-byte shape so the gate
9310        // covers every position, not only mid-path.
9311        let d = dep_with_fonte(DepSource::Path {
9312            caminho: ";../caixa-teia".into(),
9313        });
9314        let err = d.validate().unwrap_err();
9315        assert!(
9316            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9317            "got {err:?}",
9318        );
9319    }
9320
9321    #[test]
9322    fn validate_rejects_path_fonte_with_caminho_carrying_double_semicolon() {
9323        // The POSIX `case` arm `;;` terminator shape
9324        // (`"../caixa-teia;;next"` — the canonical "I copied a `case`
9325        // arm tail" idiom). The arm fires on the first `;` encountered;
9326        // pinned so a future arm that tries to distinguish `;` from `;;`
9327        // doesn't break the broader contract.
9328        let d = dep_with_fonte(DepSource::Path {
9329            caminho: "../caixa-teia;;next".into(),
9330        });
9331        let err = d.validate().unwrap_err();
9332        assert!(
9333            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9334            "got {err:?}",
9335        );
9336    }
9337
9338    #[test]
9339    fn validate_accepts_path_fonte_with_caminho_carrying_no_semicolon() {
9340        // The positive-control pin: the gate targets only `;`, never
9341        // adjacent printable ASCII or POSIX-valid bytes. The canonical
9342        // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9343        // pathed variant with adjacent printable punctuation
9344        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9345        // cleanly so the gate doesn't widen to a "no printable
9346        // punctuation anywhere" sweep that would defeat the entire
9347        // path-fonte author surface.
9348        let d = dep_with_fonte(DepSource::Path {
9349            caminho: "../caixa-teia/sub-dir.v2".into(),
9350        });
9351        d.validate().unwrap();
9352    }
9353
9354    #[test]
9355    fn fonte_caminho_shell_pipe_fires_before_shell_semicolon() {
9356        // Cascade pin on the immediate-predecessor arm: a value carrying
9357        // both `|` and `;` (`"../caixa-teia | tee; rm"` — the canonical
9358        // "I pasted a `cmd | tee; cleanup` chain" footgun) routes through
9359        // `FonteCaminhoShellPipe` not `FonteCaminhoShellSemicolon`. The
9360        // pipeline-tail paste is the load-bearing root-cause edit on
9361        // every probe-as-both value (an author who removes the `|`
9362        // typically also drops the trailing `; cleanup` since both are
9363        // the same paste-from-shell-history artifact) — same cascade
9364        // discipline every prior `:caminho` arm establishes.
9365        let d = dep_with_fonte(DepSource::Path {
9366            caminho: "../caixa-teia | tee; rm".into(),
9367        });
9368        let err = d.validate().unwrap_err();
9369        assert!(
9370            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9371            "got {err:?}",
9372        );
9373    }
9374
9375    #[test]
9376    fn fonte_caminho_shell_redirection_fires_before_shell_semicolon() {
9377        // Cascade pin on the upstream shell-redirection arm: a value
9378        // carrying both `<` / `>` and `;` (`"../caixa-teia>log; rm"` —
9379        // the canonical "I pasted a `cmd > log; cleanup` chain"
9380        // footgun) routes through `FonteCaminhoShellRedirection` not
9381        // `FonteCaminhoShellSemicolon`. The input/output redirection
9382        // metachar carries the more self-locating `byte: u8` payload
9383        // (it names which of `<` or `>` triggered), so the prior arm
9384        // wins on every probe-as-both value.
9385        let d = dep_with_fonte(DepSource::Path {
9386            caminho: "../caixa-teia>log; rm".into(),
9387        });
9388        let err = d.validate().unwrap_err();
9389        assert!(
9390            matches!(
9391                err,
9392                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9393            ),
9394            "got {err:?}",
9395        );
9396    }
9397
9398    #[test]
9399    fn fonte_caminho_backslash_fires_before_shell_semicolon() {
9400        // Cascade pin on the upstream backslash arm: a value carrying
9401        // both `\` and `;` (`"..\caixa-teia;rm"` — the canonical "I
9402        // pasted a Windows-shell `cd ..\path; cleanup` chain") routes
9403        // through `FonteCaminhoBackslash` not `FonteCaminhoShellSemicolon`.
9404        // The cross-host-OS-separator divergence is the load-bearing axis
9405        // on every probe-as-both value (an author who removes the `\` is
9406        // the root-cause edit; the `;` falls away in the same edit since
9407        // it's downstream of the Windows-shell convention).
9408        let d = dep_with_fonte(DepSource::Path {
9409            caminho: "..\\caixa-teia;rm".into(),
9410        });
9411        let err = d.validate().unwrap_err();
9412        assert!(
9413            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9414            "got {err:?}",
9415        );
9416    }
9417
9418    #[test]
9419    fn fonte_caminho_control_char_fires_before_shell_semicolon() {
9420        // Cascade pin on the embedded-control-byte arm: a value carrying
9421        // both a control byte and `;` (`"../foo\n;bar"` — the canonical
9422        // paste-from-multiline-doc footgun where a newline landed mid-
9423        // caminho) routes through `FonteCaminhoControlChar` not
9424        // `FonteCaminhoShellSemicolon`. The POSIX-syscall-rejected-byte
9425        // / NUL-`CString::new`-fail diagnostic is the load-bearing axis
9426        // on every value that probes positive for both — mirrors the
9427        // cascade discipline on every prior arm.
9428        let d = dep_with_fonte(DepSource::Path {
9429            caminho: "../foo\n;bar".into(),
9430        });
9431        let err = d.validate().unwrap_err();
9432        assert!(
9433            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9434            "got {err:?}",
9435        );
9436    }
9437
9438    #[test]
9439    fn fonte_caminho_absolute_fires_before_shell_semicolon() {
9440        // Cascade pin on the load-bearing leading-byte arm: a leading
9441        // `/` value with embedded `;` (`"/etc/passwd;rm"`) routes
9442        // through `FonteCaminhoAbsolute` not `FonteCaminhoShellSemicolon`
9443        // — the host-layout-leak diagnostic is the load-bearing axis,
9444        // the `;` byte is the secondary observation. Same precedence
9445        // logic as every prior leading-byte arm.
9446        let d = dep_with_fonte(DepSource::Path {
9447            caminho: "/etc/passwd;rm".into(),
9448        });
9449        let err = d.validate().unwrap_err();
9450        assert!(
9451            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9452            "got {err:?}",
9453        );
9454    }
9455
9456    #[test]
9457    fn fonte_caminho_shell_semicolon_fires_before_trailing_slash() {
9458        // Cascade pin on the immediate-successor arm: a value carrying
9459        // both `;` and a trailing `/` (`"../foo;rm/"` — the canonical
9460        // "I tab-completed a path that already had a `; cleanup` tail"
9461        // footgun) routes through `FonteCaminhoShellSemicolon` not
9462        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9463        // the more semantic-locating axis (an author who removes the
9464        // `;` typically also drops the trailing separator since both
9465        // are paste-from-shell artifacts).
9466        let d = dep_with_fonte(DepSource::Path {
9467            caminho: "../foo;rm/".into(),
9468        });
9469        let err = d.validate().unwrap_err();
9470        assert!(
9471            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9472            "got {err:?}",
9473        );
9474    }
9475
9476    #[test]
9477    fn fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho() {
9478        // Diagnostic-shape pin (peer with
9479        // `fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho`
9480        // on the closest single-byte peer arm): the error's Display
9481        // surfaces the offending `:nome` and the offending `:caminho`
9482        // verbatim, and names the shell-command-separator footgun
9483        // explicitly so a `feira lint` run can render the diagnostic
9484        // without re-parsing.
9485        let d = dep_with_fonte(DepSource::Path {
9486            caminho: "../caixa-teia; rm -rf build".into(),
9487        });
9488        let rendered = d.validate().unwrap_err().to_string();
9489        assert!(
9490            rendered.contains("caixa-teia"),
9491            "diagnostic must name the offending dep: {rendered}",
9492        );
9493        assert!(
9494            rendered.contains("../caixa-teia; rm -rf build"),
9495            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9496        );
9497        assert!(
9498            rendered.contains(';'),
9499            "diagnostic must reference the semicolon footgun: {rendered:?}",
9500        );
9501        assert!(
9502            rendered.contains("command-separator"),
9503            "diagnostic must name the shell-command-separator footgun: {rendered:?}",
9504        );
9505    }
9506
9507    #[test]
9508    fn validate_rejects_path_fonte_with_caminho_carrying_ampersand() {
9509        // The fail-before-pass-after pin for the canonical shell-
9510        // background-task paste footgun: an author copies a shell one-
9511        // liner (`"../caixa-teia & sleep 1"` — the canonical "I selected
9512        // the whole `cd path & sleep 1` background-launch out of a
9513        // shell-history block") and silently passed every prior arm
9514        // (`Path::is_absolute` false on `..`, no control bytes, no
9515        // backslash, no `<` / `>`, no `|`, no `;`, doesn't end in `/`).
9516        // The lacre embedded the value verbatim, the resolver folded it
9517        // through `Path::join` looking for a literal `./../caixa-teia &
9518        // sleep 1` subdirectory, and the failure surfaced at resolve
9519        // time with a non-self-locating `No such file or directory`
9520        // error. The new arm moves the rejection to validate time and
9521        // names the offending dep + caminho verbatim.
9522        let d = dep_with_fonte(DepSource::Path {
9523            caminho: "../caixa-teia & sleep 1".into(),
9524        });
9525        let err = d.validate().unwrap_err();
9526        let DepError::FonteCaminhoShellBackground { nome, caminho } = err else {
9527            panic!("expected FonteCaminhoShellBackground, got {err:?}");
9528        };
9529        assert_eq!(nome, "caixa-teia");
9530        assert_eq!(caminho, "../caixa-teia & sleep 1");
9531    }
9532
9533    #[test]
9534    fn validate_rejects_path_fonte_with_caminho_carrying_leading_ampersand() {
9535        // Leading-position `&` shape (`"&../caixa-teia"` — the
9536        // degenerate "I forgot the prior command side of the
9537        // background terminator" idiom). Pinned separately from the
9538        // embedded-byte shape so the gate covers every position, not
9539        // only mid-path.
9540        let d = dep_with_fonte(DepSource::Path {
9541            caminho: "&../caixa-teia".into(),
9542        });
9543        let err = d.validate().unwrap_err();
9544        assert!(
9545            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9546            "got {err:?}",
9547        );
9548    }
9549
9550    #[test]
9551    fn validate_rejects_path_fonte_with_caminho_carrying_double_ampersand() {
9552        // The logical-AND `&&` shape (`"../caixa-teia && make"` — the
9553        // canonical "I copied a `cd path && make` build chain" idiom
9554        // every Makefile / shell-script wraps). The arm fires on the
9555        // first `&` encountered; pinned so a future arm that tries to
9556        // distinguish `&` from `&&` doesn't break the broader contract.
9557        let d = dep_with_fonte(DepSource::Path {
9558            caminho: "../caixa-teia && make".into(),
9559        });
9560        let err = d.validate().unwrap_err();
9561        assert!(
9562            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9563            "got {err:?}",
9564        );
9565    }
9566
9567    #[test]
9568    fn validate_accepts_path_fonte_with_caminho_carrying_no_ampersand() {
9569        // The positive-control pin: the gate targets only `&`, never
9570        // adjacent printable ASCII or POSIX-valid bytes. The canonical
9571        // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9572        // pathed variant with adjacent printable punctuation
9573        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9574        // cleanly so the gate doesn't widen to a "no printable
9575        // punctuation anywhere" sweep that would defeat the entire
9576        // path-fonte author surface.
9577        let d = dep_with_fonte(DepSource::Path {
9578            caminho: "../caixa-teia/sub-dir.v2".into(),
9579        });
9580        d.validate().unwrap();
9581    }
9582
9583    #[test]
9584    fn fonte_caminho_shell_semicolon_fires_before_shell_background() {
9585        // Cascade pin on the immediate-predecessor arm: a value carrying
9586        // both `;` and `&` (`"../caixa-teia; rm & sleep"` — the
9587        // canonical "I pasted a `cmd; cleanup & sleep` chain" footgun)
9588        // routes through `FonteCaminhoShellSemicolon` not
9589        // `FonteCaminhoShellBackground`. The sequential-command-
9590        // separator paste is the more common shell-history paste idiom
9591        // on every probe-as-both value (an author who removes the `;`
9592        // typically also drops the trailing `& sleep` since both are
9593        // paste-from-shell-history artifacts) — same cascade discipline
9594        // every prior `:caminho` arm establishes.
9595        let d = dep_with_fonte(DepSource::Path {
9596            caminho: "../caixa-teia; rm & sleep".into(),
9597        });
9598        let err = d.validate().unwrap_err();
9599        assert!(
9600            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9601            "got {err:?}",
9602        );
9603    }
9604
9605    #[test]
9606    fn fonte_caminho_shell_pipe_fires_before_shell_background() {
9607        // Cascade pin on the upstream shell-pipe arm: a value carrying
9608        // both `|` and `&` (`"../caixa-teia | tee & sleep"` — the
9609        // canonical "I pasted a `cmd | tee & sleep` background-pipeline
9610        // chain" footgun) routes through `FonteCaminhoShellPipe` not
9611        // `FonteCaminhoShellBackground`. The pipeline-tail paste is the
9612        // load-bearing root-cause edit on every probe-as-both value.
9613        let d = dep_with_fonte(DepSource::Path {
9614            caminho: "../caixa-teia | tee & sleep".into(),
9615        });
9616        let err = d.validate().unwrap_err();
9617        assert!(
9618            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9619            "got {err:?}",
9620        );
9621    }
9622
9623    #[test]
9624    fn fonte_caminho_shell_redirection_fires_before_shell_background() {
9625        // Cascade pin on the upstream shell-redirection arm: a value
9626        // carrying both `>` and `&` (`"../caixa-teia>log & sleep"` —
9627        // the canonical "I pasted a `cmd > log & sleep` background-
9628        // redirect chain" footgun) routes through
9629        // `FonteCaminhoShellRedirection` not
9630        // `FonteCaminhoShellBackground`. The input/output redirection
9631        // metachar carries the more self-locating `byte: u8` payload
9632        // (it names which of `<` or `>` triggered), so the prior arm
9633        // wins on every probe-as-both value.
9634        let d = dep_with_fonte(DepSource::Path {
9635            caminho: "../caixa-teia>log & sleep".into(),
9636        });
9637        let err = d.validate().unwrap_err();
9638        assert!(
9639            matches!(
9640                err,
9641                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9642            ),
9643            "got {err:?}",
9644        );
9645    }
9646
9647    #[test]
9648    fn fonte_caminho_backslash_fires_before_shell_background() {
9649        // Cascade pin on the upstream backslash arm: a value carrying
9650        // both `\` and `&` (`"..\caixa-teia & sleep"` — the canonical
9651        // "I pasted a Windows-shell `cd ..\path & sleep` background-
9652        // launch chain") routes through `FonteCaminhoBackslash` not
9653        // `FonteCaminhoShellBackground`. The cross-host-OS-separator
9654        // divergence is the load-bearing axis on every probe-as-both
9655        // value (an author who removes the `\` is the root-cause edit;
9656        // the `&` falls away in the same edit since it's downstream of
9657        // the Windows-shell convention).
9658        let d = dep_with_fonte(DepSource::Path {
9659            caminho: "..\\caixa-teia & sleep".into(),
9660        });
9661        let err = d.validate().unwrap_err();
9662        assert!(
9663            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9664            "got {err:?}",
9665        );
9666    }
9667
9668    #[test]
9669    fn fonte_caminho_control_char_fires_before_shell_background() {
9670        // Cascade pin on the embedded-control-byte arm: a value
9671        // carrying both a control byte and `&` (`"../foo\n&sleep"` —
9672        // the canonical paste-from-multiline-doc footgun where a
9673        // newline landed mid-caminho) routes through
9674        // `FonteCaminhoControlChar` not `FonteCaminhoShellBackground`.
9675        // The POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9676        // diagnostic is the load-bearing axis on every value that
9677        // probes positive for both — mirrors the cascade discipline on
9678        // every prior arm.
9679        let d = dep_with_fonte(DepSource::Path {
9680            caminho: "../foo\n&sleep".into(),
9681        });
9682        let err = d.validate().unwrap_err();
9683        assert!(
9684            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9685            "got {err:?}",
9686        );
9687    }
9688
9689    #[test]
9690    fn fonte_caminho_absolute_fires_before_shell_background() {
9691        // Cascade pin on the load-bearing leading-byte arm: a leading
9692        // `/` value with embedded `&` (`"/etc/passwd & sleep"`) routes
9693        // through `FonteCaminhoAbsolute` not
9694        // `FonteCaminhoShellBackground` — the host-layout-leak
9695        // diagnostic is the load-bearing axis, the `&` byte is the
9696        // secondary observation. Same precedence logic as every prior
9697        // leading-byte arm.
9698        let d = dep_with_fonte(DepSource::Path {
9699            caminho: "/etc/passwd & sleep".into(),
9700        });
9701        let err = d.validate().unwrap_err();
9702        assert!(
9703            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9704            "got {err:?}",
9705        );
9706    }
9707
9708    #[test]
9709    fn fonte_caminho_shell_background_fires_before_trailing_slash() {
9710        // Cascade pin on the immediate-successor arm: a value carrying
9711        // both `&` and a trailing `/` (`"../foo&sleep/"` — the
9712        // canonical "I tab-completed a path that already had a `&
9713        // sleep` background-launch tail" footgun) routes through
9714        // `FonteCaminhoShellBackground` not `FonteCaminhoTrailingSlash`.
9715        // The embedded shell-metachar is the more semantic-locating
9716        // axis (an author who removes the `&` typically also drops
9717        // the trailing separator since both are paste-from-shell
9718        // artifacts).
9719        let d = dep_with_fonte(DepSource::Path {
9720            caminho: "../foo&sleep/".into(),
9721        });
9722        let err = d.validate().unwrap_err();
9723        assert!(
9724            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9725            "got {err:?}",
9726        );
9727    }
9728
9729    #[test]
9730    fn fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho() {
9731        // Diagnostic-shape pin (peer with
9732        // `fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho`
9733        // on the closest single-byte peer arm): the error's Display
9734        // surfaces the offending `:nome` and the offending `:caminho`
9735        // verbatim, and names the shell-background / logical-AND
9736        // footgun explicitly so a `feira lint` run can render the
9737        // diagnostic without re-parsing.
9738        let d = dep_with_fonte(DepSource::Path {
9739            caminho: "../caixa-teia & sleep 1".into(),
9740        });
9741        let rendered = d.validate().unwrap_err().to_string();
9742        assert!(
9743            rendered.contains("caixa-teia"),
9744            "diagnostic must name the offending dep: {rendered}",
9745        );
9746        assert!(
9747            rendered.contains("../caixa-teia & sleep 1"),
9748            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9749        );
9750        assert!(
9751            rendered.contains('&'),
9752            "diagnostic must reference the ampersand footgun: {rendered:?}",
9753        );
9754        assert!(
9755            rendered.contains("background") || rendered.contains("list-AND"),
9756            "diagnostic must name the shell-background / logical-AND footgun: {rendered:?}",
9757        );
9758    }
9759
9760    #[test]
9761    fn validate_rejects_path_fonte_with_caminho_carrying_backtick() {
9762        // The fail-before-pass-after pin for the canonical shell-
9763        // command-substitution paste footgun: an author copies a
9764        // POSIX legacy backticked one-liner (`"../caixa-teia/`whoami`"`
9765        // — the canonical "I pasted a path that included a `pwd`
9766        // / `whoami` / `date` legacy command-substitution expansion
9767        // out of a shell-history block") and silently passed every
9768        // prior arm (`Path::is_absolute` false on `..`, no control
9769        // bytes, no `\`, no `<` / `>`, no `|`, no `;`, no `&`, doesn't
9770        // end in `/`). The lacre embedded the value verbatim, the
9771        // resolver folded it through `Path::join` looking for a
9772        // literal `./../caixa-teia/`whoami`` subdirectory, and the
9773        // failure surfaced at resolve time with a non-self-locating
9774        // `No such file or directory` error. The new arm moves the
9775        // rejection to validate time and names the offending dep +
9776        // caminho verbatim.
9777        let d = dep_with_fonte(DepSource::Path {
9778            caminho: "../caixa-teia/`whoami`".into(),
9779        });
9780        let err = d.validate().unwrap_err();
9781        let DepError::FonteCaminhoShellCommandSubstitution { nome, caminho } = err else {
9782            panic!("expected FonteCaminhoShellCommandSubstitution, got {err:?}");
9783        };
9784        assert_eq!(nome, "caixa-teia");
9785        assert_eq!(caminho, "../caixa-teia/`whoami`");
9786    }
9787
9788    #[test]
9789    fn validate_rejects_path_fonte_with_caminho_carrying_leading_backtick() {
9790        // Leading-position backtick shape (``"`pwd`/caixa-teia"`` —
9791        // the canonical `<backtick>pwd<backtick>/path` working-
9792        // directory expansion shape every shell-side path-composition
9793        // idiom carries). Pinned separately from the embedded-byte
9794        // shape so the gate covers every position, not only mid-path.
9795        let d = dep_with_fonte(DepSource::Path {
9796            caminho: "`pwd`/caixa-teia".into(),
9797        });
9798        let err = d.validate().unwrap_err();
9799        assert!(
9800            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9801            "got {err:?}",
9802        );
9803    }
9804
9805    #[test]
9806    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backtick() {
9807        // Trailing-position backtick shape (`"../caixa-teia`"` — the
9808        // degenerate "I selected an unbalanced backtick out of a
9809        // shell-history block" idiom that probes for the cascade's
9810        // last-byte handling). The trailing-`/` arm fires only on
9811        // last-byte `/`; an unbalanced trailing backtick must route
9812        // through this arm regardless of position.
9813        let d = dep_with_fonte(DepSource::Path {
9814            caminho: "../caixa-teia`".into(),
9815        });
9816        let err = d.validate().unwrap_err();
9817        assert!(
9818            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9819            "got {err:?}",
9820        );
9821    }
9822
9823    #[test]
9824    fn validate_rejects_path_fonte_with_caminho_carrying_balanced_backtick_pair() {
9825        // The canonical balanced-pair shape (``"../<backtick>cat
9826        // /etc/passwd<backtick>"`` — the canonical CWE-78 shell-
9827        // command-injection paste idiom every shell-side hardening
9828        // guide enumerates first). The arm fires on the first
9829        // backtick encountered; pinned so a future arm that tries to
9830        // distinguish the opening from the closing byte doesn't break
9831        // the broader contract.
9832        let d = dep_with_fonte(DepSource::Path {
9833            caminho: "../`cat /etc/passwd`".into(),
9834        });
9835        let err = d.validate().unwrap_err();
9836        assert!(
9837            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9838            "got {err:?}",
9839        );
9840    }
9841
9842    #[test]
9843    fn validate_accepts_path_fonte_with_caminho_carrying_no_backtick() {
9844        // The positive-control pin: the gate targets only the
9845        // backtick byte, never adjacent printable ASCII or POSIX-
9846        // valid bytes. The canonical relative POSIX path
9847        // (`"../caixa-teia"`) and a nested deeply-pathed variant with
9848        // adjacent printable punctuation
9849        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9850        // cleanly so the gate doesn't widen to a "no printable
9851        // punctuation anywhere" sweep that would defeat the entire
9852        // path-fonte author surface.
9853        let d = dep_with_fonte(DepSource::Path {
9854            caminho: "../caixa-teia/sub-dir.v2".into(),
9855        });
9856        d.validate().unwrap();
9857    }
9858
9859    #[test]
9860    fn fonte_caminho_shell_background_fires_before_shell_command_substitution() {
9861        // Cascade pin on the immediate-predecessor arm: a value
9862        // carrying both `&` and a backtick (``"../caixa-teia &
9863        // <backtick>sleep 1<backtick>"`` — the canonical "I pasted a
9864        // `cmd & <backtick>sleep N<backtick>` background-launch +
9865        // command-substitution chain" footgun) routes through
9866        // `FonteCaminhoShellBackground` not
9867        // `FonteCaminhoShellCommandSubstitution`. The background-
9868        // launch tail is the more common shell-history paste idiom
9869        // on every probe-as-both value — same cascade discipline
9870        // every prior `:caminho` arm establishes.
9871        let d = dep_with_fonte(DepSource::Path {
9872            caminho: "../caixa-teia & `sleep 1`".into(),
9873        });
9874        let err = d.validate().unwrap_err();
9875        assert!(
9876            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9877            "got {err:?}",
9878        );
9879    }
9880
9881    #[test]
9882    fn fonte_caminho_shell_semicolon_fires_before_shell_command_substitution() {
9883        // Cascade pin on the upstream shell-semicolon arm: a value
9884        // carrying both `;` and a backtick (``"../caixa-teia;
9885        // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9886        // `cmd; <backtick>follow-up<backtick>` sequential-chain
9887        // footgun) routes through `FonteCaminhoShellSemicolon` not
9888        // `FonteCaminhoShellCommandSubstitution`. The sequential-
9889        // command-separator paste is the load-bearing root-cause
9890        // edit on every probe-as-both value.
9891        let d = dep_with_fonte(DepSource::Path {
9892            caminho: "../caixa-teia; `whoami`".into(),
9893        });
9894        let err = d.validate().unwrap_err();
9895        assert!(
9896            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9897            "got {err:?}",
9898        );
9899    }
9900
9901    #[test]
9902    fn fonte_caminho_shell_pipe_fires_before_shell_command_substitution() {
9903        // Cascade pin on the upstream shell-pipe arm: a value
9904        // carrying both `|` and a backtick (``"../caixa-teia |
9905        // <backtick>tee log<backtick>"`` — the canonical pipeline-to-
9906        // command-substitution paste idiom) routes through
9907        // `FonteCaminhoShellPipe` not
9908        // `FonteCaminhoShellCommandSubstitution`. The pipeline-tail
9909        // paste is the load-bearing root-cause edit on every
9910        // probe-as-both value.
9911        let d = dep_with_fonte(DepSource::Path {
9912            caminho: "../caixa-teia | `tee log`".into(),
9913        });
9914        let err = d.validate().unwrap_err();
9915        assert!(
9916            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9917            "got {err:?}",
9918        );
9919    }
9920
9921    #[test]
9922    fn fonte_caminho_shell_redirection_fires_before_shell_command_substitution() {
9923        // Cascade pin on the upstream shell-redirection arm: a value
9924        // carrying both `>` and a backtick (``"../caixa-teia>log
9925        // <backtick>date<backtick>"`` — the canonical "I pasted a
9926        // `cmd > log <backtick>date<backtick>` redirect-plus-
9927        // substitution chain" footgun) routes through
9928        // `FonteCaminhoShellRedirection` not
9929        // `FonteCaminhoShellCommandSubstitution`. The input/output
9930        // redirection metachar carries the more self-locating `byte`
9931        // payload (it names which of `<` or `>` triggered), so the
9932        // prior arm wins on every probe-as-both value.
9933        let d = dep_with_fonte(DepSource::Path {
9934            caminho: "../caixa-teia>log `date`".into(),
9935        });
9936        let err = d.validate().unwrap_err();
9937        assert!(
9938            matches!(
9939                err,
9940                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9941            ),
9942            "got {err:?}",
9943        );
9944    }
9945
9946    #[test]
9947    fn fonte_caminho_backslash_fires_before_shell_command_substitution() {
9948        // Cascade pin on the upstream backslash arm: a value
9949        // carrying both `\` and a backtick (``"..\caixa-teia
9950        // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9951        // Windows-shell `cd ..\path <backtick>whoami<backtick>`
9952        // chain") routes through `FonteCaminhoBackslash` not
9953        // `FonteCaminhoShellCommandSubstitution`. The cross-host-OS-
9954        // separator divergence is the load-bearing axis on every
9955        // probe-as-both value (an author who removes the `\` is the
9956        // root-cause edit; the backtick falls away in the same edit
9957        // since it's downstream of the Windows-shell convention).
9958        let d = dep_with_fonte(DepSource::Path {
9959            caminho: "..\\caixa-teia `whoami`".into(),
9960        });
9961        let err = d.validate().unwrap_err();
9962        assert!(
9963            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9964            "got {err:?}",
9965        );
9966    }
9967
9968    #[test]
9969    fn fonte_caminho_control_char_fires_before_shell_command_substitution() {
9970        // Cascade pin on the embedded-control-byte arm: a value
9971        // carrying both a control byte and a backtick (`"../foo\n
9972        // `whoami`"` — the canonical paste-from-multiline-doc
9973        // footgun where a newline landed mid-caminho between two
9974        // paste fragments) routes through `FonteCaminhoControlChar`
9975        // not `FonteCaminhoShellCommandSubstitution`. The POSIX-
9976        // syscall-rejected-byte / NUL-`CString::new`-fail diagnostic
9977        // is the load-bearing axis on every value that probes
9978        // positive for both — mirrors the cascade discipline on
9979        // every prior arm.
9980        let d = dep_with_fonte(DepSource::Path {
9981            caminho: "../foo\n`whoami`".into(),
9982        });
9983        let err = d.validate().unwrap_err();
9984        assert!(
9985            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9986            "got {err:?}",
9987        );
9988    }
9989
9990    #[test]
9991    fn fonte_caminho_absolute_fires_before_shell_command_substitution() {
9992        // Cascade pin on the load-bearing leading-byte arm: a
9993        // leading `/` value with embedded backtick (``"/etc/passwd
9994        // <backtick>whoami<backtick>"``) routes through
9995        // `FonteCaminhoAbsolute` not
9996        // `FonteCaminhoShellCommandSubstitution` — the host-layout-
9997        // leak diagnostic is the load-bearing axis, the backtick
9998        // byte is the secondary observation. Same precedence logic
9999        // as every prior leading-byte arm.
10000        let d = dep_with_fonte(DepSource::Path {
10001            caminho: "/etc/passwd `whoami`".into(),
10002        });
10003        let err = d.validate().unwrap_err();
10004        assert!(
10005            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10006            "got {err:?}",
10007        );
10008    }
10009
10010    #[test]
10011    fn fonte_caminho_shell_command_substitution_fires_before_trailing_slash() {
10012        // Cascade pin on the immediate-successor arm: a value
10013        // carrying both a backtick and a trailing `/`
10014        // (``"../`whoami`/"`` — the canonical "I tab-completed a
10015        // path that already had a backticked `whoami` substitution
10016        // tail" footgun) routes through
10017        // `FonteCaminhoShellCommandSubstitution` not
10018        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
10019        // is the more semantic-locating axis (an author who removes
10020        // the backtick typically also drops the trailing separator
10021        // since both are paste-from-shell artifacts).
10022        let d = dep_with_fonte(DepSource::Path {
10023            caminho: "../`whoami`/".into(),
10024        });
10025        let err = d.validate().unwrap_err();
10026        assert!(
10027            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10028            "got {err:?}",
10029        );
10030    }
10031
10032    #[test]
10033    fn fonte_caminho_shell_command_substitution_diagnostic_carries_offending_dep_and_caminho() {
10034        // Diagnostic-shape pin (peer with
10035        // `fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho`
10036        // on the closest single-byte peer arm): the error's Display
10037        // surfaces the offending `:nome` and the offending `:caminho`
10038        // verbatim, and names the shell-command-substitution footgun
10039        // explicitly so a `feira lint` run can render the diagnostic
10040        // without re-parsing.
10041        let d = dep_with_fonte(DepSource::Path {
10042            caminho: "../caixa-teia/`whoami`".into(),
10043        });
10044        let rendered = d.validate().unwrap_err().to_string();
10045        assert!(
10046            rendered.contains("caixa-teia"),
10047            "diagnostic must name the offending dep: {rendered}",
10048        );
10049        assert!(
10050            rendered.contains("../caixa-teia/`whoami`"),
10051            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10052        );
10053        assert!(
10054            rendered.contains('`'),
10055            "diagnostic must reference the backtick footgun: {rendered:?}",
10056        );
10057        assert!(
10058            rendered.contains("command-substitution"),
10059            "diagnostic must name the shell-command-substitution footgun: {rendered:?}",
10060        );
10061    }
10062
10063    #[test]
10064    fn validate_rejects_path_fonte_with_caminho_carrying_star_glob() {
10065        // The fail-before-pass-after pin for the canonical pathname-
10066        // expansion paste footgun: an author copies an `ls
10067        // ../caixa-teia/*` shell-listing tail into the `:caminho`
10068        // slot and silently passes every prior arm
10069        // (`Path::is_absolute` false on `..`, no control bytes, no
10070        // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick,
10071        // doesn't end in `/`). The lacre embedded the value
10072        // verbatim, the resolver folded it through `Path::join`
10073        // looking for a literal `./../caixa-teia/*` subdirectory,
10074        // and the failure surfaced at resolve time with a non-self-
10075        // locating `No such file or directory` error. The new arm
10076        // moves the rejection to validate time and names the
10077        // offending dep + caminho + byte verbatim.
10078        let d = dep_with_fonte(DepSource::Path {
10079            caminho: "../caixa-teia/*".into(),
10080        });
10081        let err = d.validate().unwrap_err();
10082        let DepError::FonteCaminhoShellGlob {
10083            nome,
10084            caminho,
10085            byte,
10086        } = err
10087        else {
10088            panic!("expected FonteCaminhoShellGlob, got {err:?}");
10089        };
10090        assert_eq!(nome, "caixa-teia");
10091        assert_eq!(caminho, "../caixa-teia/*");
10092        assert_eq!(byte, b'*');
10093    }
10094
10095    #[test]
10096    fn validate_rejects_path_fonte_with_caminho_carrying_question_glob() {
10097        // The symmetric single-char-wildcard paste shape
10098        // (`"../foo?"` — the canonical "I copied a `rm foo?` line
10099        // out of shell history" idiom). Pinned separately from the
10100        // `*` shape so the gate's contract is "any `*` or `?`
10101        // anywhere", not single-byte coverage.
10102        let d = dep_with_fonte(DepSource::Path {
10103            caminho: "../foo?".into(),
10104        });
10105        let err = d.validate().unwrap_err();
10106        let DepError::FonteCaminhoShellGlob { byte, .. } = err else {
10107            panic!("expected FonteCaminhoShellGlob, got {err:?}");
10108        };
10109        assert_eq!(byte, b'?');
10110    }
10111
10112    #[test]
10113    fn validate_rejects_path_fonte_with_caminho_carrying_leading_star_glob() {
10114        // Leading-position `*` shape (`"*/caixa-teia"` — the
10115        // degenerate "I selected only the wildcard prefix out of a
10116        // shell-glob expression" idiom). Pinned separately from the
10117        // embedded-byte shapes so the gate covers every position,
10118        // not only mid-path.
10119        let d = dep_with_fonte(DepSource::Path {
10120            caminho: "*/caixa-teia".into(),
10121        });
10122        let err = d.validate().unwrap_err();
10123        assert!(
10124            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10125            "got {err:?}",
10126        );
10127    }
10128
10129    #[test]
10130    fn validate_rejects_path_fonte_with_caminho_carrying_double_star_recursive_glob() {
10131        // The bash/zsh `globstar` recursive-glob shape
10132        // (`"../caixa-teia/**/foo"` — the canonical "I copied a
10133        // `find ../caixa-teia/**/foo` recursive expansion" idiom).
10134        // The arm fires on the first `*` encountered; pinned so a
10135        // future arm that tries to distinguish single `*` from
10136        // double `**` doesn't break the broader contract.
10137        let d = dep_with_fonte(DepSource::Path {
10138            caminho: "../caixa-teia/**/foo".into(),
10139        });
10140        let err = d.validate().unwrap_err();
10141        assert!(
10142            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10143            "got {err:?}",
10144        );
10145    }
10146
10147    #[test]
10148    fn validate_rejects_path_fonte_with_caminho_carrying_dotted_extension_glob() {
10149        // The canonical extension-glob shape (`"../caixa-teia/*.lisp"`
10150        // — the "I selected `*.lisp` to mean every Lisp source file
10151        // in the dep root" footgun the prior arms structurally
10152        // cannot catch since `.` is a POSIX-valid path-component
10153        // byte). Pinned so the gate's contract covers the most
10154        // idiomatic glob-paste shape every author meets first.
10155        let d = dep_with_fonte(DepSource::Path {
10156            caminho: "../caixa-teia/*.lisp".into(),
10157        });
10158        let err = d.validate().unwrap_err();
10159        assert!(
10160            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10161            "got {err:?}",
10162        );
10163    }
10164
10165    #[test]
10166    fn validate_accepts_path_fonte_with_caminho_carrying_no_glob() {
10167        // The positive-control pin: the gate targets only `*` /
10168        // `?`, never adjacent printable ASCII or POSIX-valid bytes.
10169        // The canonical relative POSIX path (`"../caixa-teia"`) and
10170        // a nested deeply-pathed variant with adjacent printable
10171        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
10172        // to validate cleanly so the gate doesn't widen to a "no
10173        // printable punctuation anywhere" sweep that would defeat
10174        // the entire path-fonte author surface.
10175        let d = dep_with_fonte(DepSource::Path {
10176            caminho: "../caixa-teia/sub-dir.v2".into(),
10177        });
10178        d.validate().unwrap();
10179    }
10180
10181    #[test]
10182    fn fonte_caminho_shell_command_substitution_fires_before_shell_glob() {
10183        // Cascade pin on the immediate-predecessor arm: a value
10184        // carrying both a backtick and `*` (``"../`whoami`/*"`` —
10185        // the canonical "I pasted a `cd <backtick>whoami<backtick>/*`
10186        // command-substitution + glob chain") routes through
10187        // `FonteCaminhoShellCommandSubstitution` not
10188        // `FonteCaminhoShellGlob`. The CWE-78 shell-command-
10189        // injection vector is the load-bearing root-cause edit on
10190        // every probe-as-both value — same cascade discipline every
10191        // prior `:caminho` arm establishes.
10192        let d = dep_with_fonte(DepSource::Path {
10193            caminho: "../`whoami`/*".into(),
10194        });
10195        let err = d.validate().unwrap_err();
10196        assert!(
10197            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10198            "got {err:?}",
10199        );
10200    }
10201
10202    #[test]
10203    fn fonte_caminho_shell_background_fires_before_shell_glob() {
10204        // Cascade pin on the upstream shell-background arm: a value
10205        // carrying both `&` and `*` (`"../caixa-teia & ls /*"` — the
10206        // canonical "I pasted a `cmd & ls /*` background + glob
10207        // chain" footgun) routes through `FonteCaminhoShellBackground`
10208        // not `FonteCaminhoShellGlob`. The background-launch tail is
10209        // the load-bearing root-cause edit on every probe-as-both
10210        // value.
10211        let d = dep_with_fonte(DepSource::Path {
10212            caminho: "../caixa-teia & ls /*".into(),
10213        });
10214        let err = d.validate().unwrap_err();
10215        assert!(
10216            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10217            "got {err:?}",
10218        );
10219    }
10220
10221    #[test]
10222    fn fonte_caminho_shell_semicolon_fires_before_shell_glob() {
10223        // Cascade pin on the upstream shell-semicolon arm: a value
10224        // carrying both `;` and `*` (`"../caixa-teia; rm *"` — the
10225        // canonical sequential-cleanup + glob paste idiom) routes
10226        // through `FonteCaminhoShellSemicolon` not
10227        // `FonteCaminhoShellGlob`. The sequential-command-separator
10228        // paste is the load-bearing root-cause edit on every
10229        // probe-as-both value.
10230        let d = dep_with_fonte(DepSource::Path {
10231            caminho: "../caixa-teia; rm *".into(),
10232        });
10233        let err = d.validate().unwrap_err();
10234        assert!(
10235            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10236            "got {err:?}",
10237        );
10238    }
10239
10240    #[test]
10241    fn fonte_caminho_shell_pipe_fires_before_shell_glob() {
10242        // Cascade pin on the upstream shell-pipe arm: a value
10243        // carrying both `|` and `*` (`"../caixa-teia | ls *"` — the
10244        // canonical pipeline-to-glob paste idiom) routes through
10245        // `FonteCaminhoShellPipe` not `FonteCaminhoShellGlob`. The
10246        // pipeline-tail paste is the load-bearing root-cause edit
10247        // on every probe-as-both value.
10248        let d = dep_with_fonte(DepSource::Path {
10249            caminho: "../caixa-teia | ls *".into(),
10250        });
10251        let err = d.validate().unwrap_err();
10252        assert!(
10253            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10254            "got {err:?}",
10255        );
10256    }
10257
10258    #[test]
10259    fn fonte_caminho_shell_redirection_fires_before_shell_glob() {
10260        // Cascade pin on the upstream shell-redirection arm: a value
10261        // carrying both `>` and `*` (`"../caixa-teia>log *"` — the
10262        // canonical "I pasted a `cmd > log *` redirect-plus-glob
10263        // chain" footgun) routes through
10264        // `FonteCaminhoShellRedirection` not `FonteCaminhoShellGlob`.
10265        // The input/output redirection metachar carries the more
10266        // self-locating `byte` payload (it names which of `<` or `>`
10267        // triggered), so the prior arm wins on every probe-as-both
10268        // value.
10269        let d = dep_with_fonte(DepSource::Path {
10270            caminho: "../caixa-teia>log *".into(),
10271        });
10272        let err = d.validate().unwrap_err();
10273        assert!(
10274            matches!(
10275                err,
10276                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10277            ),
10278            "got {err:?}",
10279        );
10280    }
10281
10282    #[test]
10283    fn fonte_caminho_backslash_fires_before_shell_glob() {
10284        // Cascade pin on the upstream backslash arm: a value
10285        // carrying both `\` and `*` (`"..\caixa-teia\*"` — the
10286        // canonical "I pasted a Windows-shell `cd ..\path\*` glob
10287        // expression" footgun) routes through
10288        // `FonteCaminhoBackslash` not `FonteCaminhoShellGlob`. The
10289        // cross-host-OS-separator divergence is the load-bearing
10290        // axis on every probe-as-both value (an author who removes
10291        // the `\` is the root-cause edit; the `*` falls away in the
10292        // same edit since it's downstream of the Windows-shell
10293        // convention).
10294        let d = dep_with_fonte(DepSource::Path {
10295            caminho: "..\\caixa-teia\\*".into(),
10296        });
10297        let err = d.validate().unwrap_err();
10298        assert!(
10299            matches!(err, DepError::FonteCaminhoBackslash { .. }),
10300            "got {err:?}",
10301        );
10302    }
10303
10304    #[test]
10305    fn fonte_caminho_control_char_fires_before_shell_glob() {
10306        // Cascade pin on the embedded-control-byte arm: a value
10307        // carrying both a control byte and `*` (`"../foo\n*"` — the
10308        // canonical paste-from-multiline-doc footgun where a
10309        // newline landed mid-caminho between two paste fragments)
10310        // routes through `FonteCaminhoControlChar` not
10311        // `FonteCaminhoShellGlob`. The POSIX-syscall-rejected-byte /
10312        // NUL-`CString::new`-fail diagnostic is the load-bearing
10313        // axis on every value that probes positive for both —
10314        // mirrors the cascade discipline on every prior arm.
10315        let d = dep_with_fonte(DepSource::Path {
10316            caminho: "../foo\n*".into(),
10317        });
10318        let err = d.validate().unwrap_err();
10319        assert!(
10320            matches!(err, DepError::FonteCaminhoControlChar { .. }),
10321            "got {err:?}",
10322        );
10323    }
10324
10325    #[test]
10326    fn fonte_caminho_absolute_fires_before_shell_glob() {
10327        // Cascade pin on the load-bearing leading-byte arm: a
10328        // leading `/` value with embedded `*` (`"/etc/*"`) routes
10329        // through `FonteCaminhoAbsolute` not `FonteCaminhoShellGlob`
10330        // — the host-layout-leak diagnostic is the load-bearing
10331        // axis, the glob byte is the secondary observation. Same
10332        // precedence logic as every prior leading-byte arm.
10333        let d = dep_with_fonte(DepSource::Path {
10334            caminho: "/etc/*".into(),
10335        });
10336        let err = d.validate().unwrap_err();
10337        assert!(
10338            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10339            "got {err:?}",
10340        );
10341    }
10342
10343    #[test]
10344    fn fonte_caminho_shell_glob_fires_before_trailing_slash() {
10345        // Cascade pin on the immediate-successor arm: a value
10346        // carrying both `*` and a trailing `/` (`"../foo*/"` — the
10347        // canonical "I tab-completed a path that already had a
10348        // glob-expansion tail" footgun) routes through
10349        // `FonteCaminhoShellGlob` not `FonteCaminhoTrailingSlash`.
10350        // The embedded shell-metachar is the more semantic-locating
10351        // axis (an author who removes the `*` typically also drops
10352        // the trailing separator since both are paste-from-shell
10353        // artifacts).
10354        let d = dep_with_fonte(DepSource::Path {
10355            caminho: "../foo*/".into(),
10356        });
10357        let err = d.validate().unwrap_err();
10358        assert!(
10359            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10360            "got {err:?}",
10361        );
10362    }
10363
10364    #[test]
10365    fn fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte() {
10366        // Diagnostic-shape pin (peer with
10367        // `fonte_caminho_shell_redirection_diagnostic_*` on the
10368        // closest two-byte peer arm): the error's Display surfaces
10369        // the offending `:nome`, the offending `:caminho` verbatim,
10370        // the offending byte's hex / character form, and names the
10371        // shell-glob / pathname-expansion footgun explicitly so a
10372        // `feira lint` run can render the diagnostic without
10373        // re-parsing.
10374        let d = dep_with_fonte(DepSource::Path {
10375            caminho: "../caixa-teia/*.lisp".into(),
10376        });
10377        let rendered = d.validate().unwrap_err().to_string();
10378        assert!(
10379            rendered.contains("caixa-teia"),
10380            "diagnostic must name the offending dep: {rendered}",
10381        );
10382        assert!(
10383            rendered.contains("../caixa-teia/*.lisp"),
10384            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10385        );
10386        assert!(
10387            rendered.contains("0x2a"),
10388            "diagnostic must surface the offending byte hex: {rendered:?}",
10389        );
10390        assert!(
10391            rendered.contains("glob"),
10392            "diagnostic must name the shell-glob footgun: {rendered:?}",
10393        );
10394        assert!(
10395            rendered.contains("pathname-expansion"),
10396            "diagnostic must reference the POSIX pathname-expansion vocabulary: {rendered:?}",
10397        );
10398    }
10399
10400    #[test]
10401    fn validate_rejects_path_fonte_with_caminho_carrying_modern_command_substitution() {
10402        // The fail-before-pass-after pin for the canonical modern-Bourne
10403        // command-substitution paste footgun: an author copies a
10404        // `cd ../caixa-teia/$(date)/build` shell-history one-liner whose
10405        // `$(<cmd>)` expansion would land the current date as a
10406        // subdirectory name and silently passed every prior arm
10407        // (`Path::is_absolute` false on `..`, no control bytes, no `\`,
10408        // no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no `*` /
10409        // `?`, doesn't end in `/`; the leading-`$` f4efe9c
10410        // `FonteCaminhoVarExpansion` arm doesn't fire because the `$`
10411        // sits mid-path). The lacre embedded the value verbatim, the
10412        // resolver folded it through `Path::join` looking for a literal
10413        // `./../caixa-teia/$(date)/build` subdirectory, and the failure
10414        // surfaced at resolve time with a non-self-locating `No such
10415        // file or directory` error. The new arm moves the rejection to
10416        // validate time and names the offending dep + caminho + byte
10417        // verbatim. The arm fires on the first `(` encountered (the
10418        // opening byte of `$(date)`).
10419        let d = dep_with_fonte(DepSource::Path {
10420            caminho: "../caixa-teia/$(date)/build".into(),
10421        });
10422        let err = d.validate().unwrap_err();
10423        let DepError::FonteCaminhoShellSubshellGrouping {
10424            nome,
10425            caminho,
10426            byte,
10427        } = err
10428        else {
10429            panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10430        };
10431        assert_eq!(nome, "caixa-teia");
10432        assert_eq!(caminho, "../caixa-teia/$(date)/build");
10433        assert_eq!(byte, b'(');
10434    }
10435
10436    #[test]
10437    fn validate_rejects_path_fonte_with_caminho_carrying_close_paren() {
10438        // The symmetric close-paren paste shape (`"../caixa-teia)"` —
10439        // the degenerate "I selected an unbalanced closing paren out of
10440        // a shell-history block" idiom that probes for the cascade's
10441        // last-byte handling on a value carrying only the closing byte).
10442        // Pinned separately from the open-paren shape so the gate's
10443        // contract is "any `(` or `)` anywhere", not single-byte
10444        // coverage. Mirrors the peer `validate_rejects_path_fonte_with_\
10445        // caminho_carrying_question_glob` shape on the immediate-
10446        // predecessor `FonteCaminhoShellGlob` arm.
10447        let d = dep_with_fonte(DepSource::Path {
10448            caminho: "../caixa-teia)".into(),
10449        });
10450        let err = d.validate().unwrap_err();
10451        let DepError::FonteCaminhoShellSubshellGrouping { byte, .. } = err else {
10452            panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10453        };
10454        assert_eq!(byte, b')');
10455    }
10456
10457    #[test]
10458    fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_paren() {
10459        // Leading-position `(` shape (`"(cd foo)/caixa-teia"` — the
10460        // canonical "I selected a `(cd foo)` subshell-grouping prefix
10461        // out of a `(cd foo) && cmd` shell-history one-liner" idiom).
10462        // Pinned separately from the embedded-byte shape so the gate
10463        // covers every position, not only mid-path.
10464        let d = dep_with_fonte(DepSource::Path {
10465            caminho: "(cd foo)/caixa-teia".into(),
10466        });
10467        let err = d.validate().unwrap_err();
10468        assert!(
10469            matches!(
10470                err,
10471                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10472            ),
10473            "got {err:?}",
10474        );
10475    }
10476
10477    #[test]
10478    fn validate_rejects_path_fonte_with_caminho_carrying_balanced_subshell_grouping_pair() {
10479        // The canonical balanced-pair shape (`"../(pwd)/caixa-teia"`
10480        // — the canonical "I copied a `(pwd)` working-directory-probe
10481        // subshell-grouping idiom every shell-history block carries"
10482        // footgun). The value carries no other cascade-preceding
10483        // shell metachar (`&` / `;` / `|` / `<` / `>` / backtick /
10484        // `*` / `?`) so the arm fires on the first `(` encountered;
10485        // pinned so a future arm that tries to distinguish the
10486        // opening from the closing byte doesn't break the broader
10487        // contract. Mirrors the peer
10488        // `validate_rejects_path_fonte_with_caminho_carrying_balanced_\
10489        // backtick_pair` shape on the upstream `FonteCaminhoShell\
10490        // CommandSubstitution` arm.
10491        let d = dep_with_fonte(DepSource::Path {
10492            caminho: "../(pwd)/caixa-teia".into(),
10493        });
10494        let err = d.validate().unwrap_err();
10495        assert!(
10496            matches!(
10497                err,
10498                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10499            ),
10500            "got {err:?}",
10501        );
10502    }
10503
10504    #[test]
10505    fn validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping() {
10506        // The positive-control pin: the gate targets only `(` / `)`,
10507        // never adjacent printable ASCII or POSIX-valid bytes. The
10508        // canonical relative POSIX path (`"../caixa-teia"`) and a
10509        // nested deeply-pathed variant with adjacent printable
10510        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10511        // validate cleanly so the gate doesn't widen to a "no printable
10512        // punctuation anywhere" sweep that would defeat the entire
10513        // path-fonte author surface.
10514        let d = dep_with_fonte(DepSource::Path {
10515            caminho: "../caixa-teia/sub-dir.v2".into(),
10516        });
10517        d.validate().unwrap();
10518    }
10519
10520    #[test]
10521    fn fonte_caminho_shell_glob_fires_before_shell_subshell_grouping() {
10522        // Cascade pin on the immediate-predecessor arm: a value
10523        // carrying both `*` and `(` (`"../caixa-teia/*(date)"` — the
10524        // canonical "I pasted a glob expansion followed by a
10525        // subshell-grouping tail" footgun) routes through
10526        // `FonteCaminhoShellGlob` not
10527        // `FonteCaminhoShellSubshellGrouping`. The pathname-expansion
10528        // shape is the more common shell-history paste idiom on every
10529        // probe-as-both value — same cascade discipline every prior
10530        // `:caminho` arm establishes.
10531        let d = dep_with_fonte(DepSource::Path {
10532            caminho: "../caixa-teia/*(date)".into(),
10533        });
10534        let err = d.validate().unwrap_err();
10535        assert!(
10536            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10537            "got {err:?}",
10538        );
10539    }
10540
10541    #[test]
10542    fn fonte_caminho_shell_command_substitution_fires_before_shell_subshell_grouping() {
10543        // Cascade pin on the upstream shell-command-substitution arm: a
10544        // value carrying both a backtick and `(` (``"../`whoami`/$(date)"``
10545        // — the canonical "I pasted a legacy-backtick + modern-paren
10546        // command-substitution chain" footgun) routes through
10547        // `FonteCaminhoShellCommandSubstitution` not
10548        // `FonteCaminhoShellSubshellGrouping`. The CWE-78 shell-
10549        // command-injection vector is the load-bearing root-cause edit
10550        // on every probe-as-both value.
10551        let d = dep_with_fonte(DepSource::Path {
10552            caminho: "../`whoami`/$(date)".into(),
10553        });
10554        let err = d.validate().unwrap_err();
10555        assert!(
10556            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10557            "got {err:?}",
10558        );
10559    }
10560
10561    #[test]
10562    fn fonte_caminho_shell_background_fires_before_shell_subshell_grouping() {
10563        // Cascade pin on the upstream shell-background arm: a value
10564        // carrying both `&` and `(` (`"../caixa-teia & (cd foo)"` —
10565        // the canonical "I pasted a `cmd & (cd foo)` background-launch
10566        // + subshell-grouping chain" footgun) routes through
10567        // `FonteCaminhoShellBackground` not
10568        // `FonteCaminhoShellSubshellGrouping`. The background-launch
10569        // tail is the load-bearing root-cause edit on every probe-as-
10570        // both value.
10571        let d = dep_with_fonte(DepSource::Path {
10572            caminho: "../caixa-teia & (cd foo)".into(),
10573        });
10574        let err = d.validate().unwrap_err();
10575        assert!(
10576            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10577            "got {err:?}",
10578        );
10579    }
10580
10581    #[test]
10582    fn fonte_caminho_shell_semicolon_fires_before_shell_subshell_grouping() {
10583        // Cascade pin on the upstream shell-semicolon arm: a value
10584        // carrying both `;` and `(` (`"../caixa-teia; (cd foo)"` —
10585        // the canonical sequential-cleanup + subshell-grouping paste
10586        // idiom) routes through `FonteCaminhoShellSemicolon` not
10587        // `FonteCaminhoShellSubshellGrouping`. The sequential-command-
10588        // separator paste is the load-bearing root-cause edit on
10589        // every probe-as-both value.
10590        let d = dep_with_fonte(DepSource::Path {
10591            caminho: "../caixa-teia; (cd foo)".into(),
10592        });
10593        let err = d.validate().unwrap_err();
10594        assert!(
10595            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10596            "got {err:?}",
10597        );
10598    }
10599
10600    #[test]
10601    fn fonte_caminho_shell_pipe_fires_before_shell_subshell_grouping() {
10602        // Cascade pin on the upstream shell-pipe arm: a value carrying
10603        // both `|` and `(` (`"../caixa-teia | (tee log)"` — the
10604        // canonical pipeline-to-subshell-grouping paste idiom) routes
10605        // through `FonteCaminhoShellPipe` not
10606        // `FonteCaminhoShellSubshellGrouping`. The pipeline-tail paste
10607        // is the load-bearing root-cause edit on every probe-as-both
10608        // value.
10609        let d = dep_with_fonte(DepSource::Path {
10610            caminho: "../caixa-teia | (tee log)".into(),
10611        });
10612        let err = d.validate().unwrap_err();
10613        assert!(
10614            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10615            "got {err:?}",
10616        );
10617    }
10618
10619    #[test]
10620    fn fonte_caminho_shell_redirection_fires_before_shell_subshell_grouping() {
10621        // Cascade pin on the upstream shell-redirection arm: a value
10622        // carrying both `>` and `(` (`"../caixa-teia>log (cd foo)"` —
10623        // the canonical "I pasted a `cmd > log (cd foo)` redirect-
10624        // plus-subshell-grouping chain" footgun) routes through
10625        // `FonteCaminhoShellRedirection` not
10626        // `FonteCaminhoShellSubshellGrouping`. The input/output
10627        // redirection metachar carries the more self-locating `byte`
10628        // payload (it names which of `<` or `>` triggered), so the
10629        // prior arm wins on every probe-as-both value.
10630        let d = dep_with_fonte(DepSource::Path {
10631            caminho: "../caixa-teia>log (cd foo)".into(),
10632        });
10633        let err = d.validate().unwrap_err();
10634        assert!(
10635            matches!(
10636                err,
10637                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10638            ),
10639            "got {err:?}",
10640        );
10641    }
10642
10643    #[test]
10644    fn fonte_caminho_backslash_fires_before_shell_subshell_grouping() {
10645        // Cascade pin on the upstream backslash arm: a value carrying
10646        // both `\` and `(` (`"..\caixa-teia\(cd foo)"` — the canonical
10647        // "I pasted a Windows-shell `cd ..\path\(cmd)` chain") routes
10648        // through `FonteCaminhoBackslash` not
10649        // `FonteCaminhoShellSubshellGrouping`. The cross-host-OS-
10650        // separator divergence is the load-bearing axis on every
10651        // probe-as-both value (an author who removes the `\` is the
10652        // root-cause edit; the `(` falls away in the same edit since
10653        // it's downstream of the Windows-shell convention).
10654        let d = dep_with_fonte(DepSource::Path {
10655            caminho: "..\\caixa-teia\\(cd foo)".into(),
10656        });
10657        let err = d.validate().unwrap_err();
10658        assert!(
10659            matches!(err, DepError::FonteCaminhoBackslash { .. }),
10660            "got {err:?}",
10661        );
10662    }
10663
10664    #[test]
10665    fn fonte_caminho_control_char_fires_before_shell_subshell_grouping() {
10666        // Cascade pin on the embedded-control-byte arm: a value
10667        // carrying both a control byte and `(` (`"../foo\n(cd bar)"` —
10668        // the canonical paste-from-multiline-doc footgun where a
10669        // newline landed mid-caminho between two paste fragments)
10670        // routes through `FonteCaminhoControlChar` not
10671        // `FonteCaminhoShellSubshellGrouping`. The POSIX-syscall-
10672        // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10673        // load-bearing axis on every value that probes positive for
10674        // both — mirrors the cascade discipline on every prior arm.
10675        let d = dep_with_fonte(DepSource::Path {
10676            caminho: "../foo\n(cd bar)".into(),
10677        });
10678        let err = d.validate().unwrap_err();
10679        assert!(
10680            matches!(err, DepError::FonteCaminhoControlChar { .. }),
10681            "got {err:?}",
10682        );
10683    }
10684
10685    #[test]
10686    fn fonte_caminho_absolute_fires_before_shell_subshell_grouping() {
10687        // Cascade pin on the load-bearing leading-byte arm: a leading
10688        // `/` value with embedded `(` (`"/etc/(cd foo)"`) routes
10689        // through `FonteCaminhoAbsolute` not
10690        // `FonteCaminhoShellSubshellGrouping` — the host-layout-leak
10691        // diagnostic is the load-bearing axis, the subshell-grouping
10692        // byte is the secondary observation. Same precedence logic as
10693        // every prior leading-byte arm.
10694        let d = dep_with_fonte(DepSource::Path {
10695            caminho: "/etc/(cd foo)".into(),
10696        });
10697        let err = d.validate().unwrap_err();
10698        assert!(
10699            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10700            "got {err:?}",
10701        );
10702    }
10703
10704    #[test]
10705    fn fonte_caminho_var_expansion_fires_before_shell_subshell_grouping() {
10706        // Cascade pin on the upstream leading-`$` var-expansion arm: a
10707        // value carrying both a leading `$` and a `(` (`"$(date)/\
10708        // caixa-teia"` — the canonical "I pasted a `$(date)` modern-
10709        // command-substitution at the head of a sibling-workspace
10710        // path" footgun) routes through `FonteCaminhoVarExpansion` not
10711        // `FonteCaminhoShellSubshellGrouping`. The leading-byte
10712        // shell-variable-expansion is the more self-locating diagnostic
10713        // on values that probe as both — same load-bearing-leading-
10714        // byte cascade discipline every prior `:caminho` arm
10715        // establishes. Closing both halves of `$(<cmd>)` structurally
10716        // (leading `$` here, trailing `)` on the new arm) excludes the
10717        // entire modern Bourne command-substitution surface from the
10718        // typed `:caminho` accepted set; the cascade preserves the
10719        // narrower leading-byte diagnostic on values that probe both
10720        // halves at the canonical leading position.
10721        let d = dep_with_fonte(DepSource::Path {
10722            caminho: "$(date)/caixa-teia".into(),
10723        });
10724        let err = d.validate().unwrap_err();
10725        assert!(
10726            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
10727            "got {err:?}",
10728        );
10729    }
10730
10731    #[test]
10732    fn fonte_caminho_shell_subshell_grouping_fires_before_trailing_slash() {
10733        // Cascade pin on the immediate-successor arm: a value carrying
10734        // both `(` and a trailing `/` (`"../(cd foo)/"` — the canonical
10735        // "I tab-completed a path that already had a subshell-grouping
10736        // expansion tail" footgun) routes through
10737        // `FonteCaminhoShellSubshellGrouping` not
10738        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
10739        // the more semantic-locating axis (an author who removes the
10740        // `(` typically also drops the trailing separator since both
10741        // are paste-from-shell artifacts).
10742        let d = dep_with_fonte(DepSource::Path {
10743            caminho: "../(cd foo)/".into(),
10744        });
10745        let err = d.validate().unwrap_err();
10746        assert!(
10747            matches!(
10748                err,
10749                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10750            ),
10751            "got {err:?}",
10752        );
10753    }
10754
10755    #[test]
10756    fn fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
10757        // Diagnostic-shape pin (peer with
10758        // `fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte`
10759        // on the closest two-byte peer arm): the error's Display
10760        // surfaces the offending `:nome`, the offending `:caminho`
10761        // verbatim, the offending byte's hex / character form, and
10762        // names the shell-subshell-grouping footgun explicitly so a
10763        // `feira lint` run can render the diagnostic without re-
10764        // parsing.
10765        let d = dep_with_fonte(DepSource::Path {
10766            caminho: "../caixa-teia/$(date)/build".into(),
10767        });
10768        let rendered = d.validate().unwrap_err().to_string();
10769        assert!(
10770            rendered.contains("caixa-teia"),
10771            "diagnostic must name the offending dep: {rendered}",
10772        );
10773        assert!(
10774            rendered.contains("../caixa-teia/$(date)/build"),
10775            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10776        );
10777        assert!(
10778            rendered.contains("0x28"),
10779            "diagnostic must surface the offending byte hex: {rendered:?}",
10780        );
10781        assert!(
10782            rendered.contains("subshell-grouping"),
10783            "diagnostic must name the shell-subshell-grouping footgun: {rendered:?}",
10784        );
10785        assert!(
10786            rendered.contains("command-substitution"),
10787            "diagnostic must reference the `$(<cmd>)` command-substitution vocabulary: \
10788             {rendered:?}",
10789        );
10790    }
10791
10792    // ── shell-brace-expansion / URI-Template-placeholder arm ───────────
10793    //
10794    // Peer with the prior `FonteCaminhoShellSubshellGrouping` (`(` /
10795    // `)`) byte-pair arm: the same per-byte cascade with the same
10796    // self-locating `byte: u8` diagnostic on the orthogonal `{` /
10797    // `}` brace-expansion / URI-Template placeholder axis. The peer
10798    // [`crate::render::is_git_repo_url`] (42d8f9d) closes the same
10799    // byte pair on the sibling `:fonte :repo` axis under the same
10800    // banner.
10801
10802    #[test]
10803    fn validate_rejects_path_fonte_with_caminho_carrying_brace_expansion_fan_across_siblings() {
10804        // The fail-before-pass-after pin for the canonical paste-from-
10805        // shell-history brace-expansion footgun: an author copies a
10806        // `cd ../{caixa-teia,caixa-helm}/build` shell-history one-
10807        // liner whose `{a,b}` brace expansion fans across two siblings
10808        // and silently passed every prior arm (`Path::is_absolute`
10809        // false on `..`, no control bytes, no `\`, no `<` / `>`, no
10810        // `|`, no `;`, no `&`, no backtick, no `*` / `?`, no `(` /
10811        // `)`, doesn't end in `/`; the leading-`$` f4efe9c
10812        // `FonteCaminhoVarExpansion` arm doesn't fire because the
10813        // value starts with `..` not `$`). The lacre embedded the
10814        // value verbatim, the resolver folded it through `Path::join`
10815        // looking for a literal `./../{caixa-teia,caixa-helm}/build`
10816        // subdirectory, and the failure surfaced at resolve time with
10817        // a non-self-locating `No such file or directory` error. The
10818        // new arm moves the rejection to validate time and names the
10819        // offending dep + caminho + byte verbatim. The arm fires on
10820        // the first `{` encountered.
10821        let d = dep_with_fonte(DepSource::Path {
10822            caminho: "../{caixa-teia,caixa-helm}/build".into(),
10823        });
10824        let err = d.validate().unwrap_err();
10825        let DepError::FonteCaminhoShellBraceExpansion {
10826            nome,
10827            caminho,
10828            byte,
10829        } = err
10830        else {
10831            panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10832        };
10833        assert_eq!(nome, "caixa-teia");
10834        assert_eq!(caminho, "../{caixa-teia,caixa-helm}/build");
10835        assert_eq!(byte, b'{');
10836    }
10837
10838    #[test]
10839    fn validate_rejects_path_fonte_with_caminho_carrying_close_brace() {
10840        // The symmetric close-brace paste shape (`"../caixa-teia}"` —
10841        // the degenerate "I selected an unbalanced closing brace out
10842        // of a shell-history block" idiom that probes for the
10843        // cascade's last-byte handling on a value carrying only the
10844        // closing byte). Pinned separately from the open-brace shape
10845        // so the gate's contract is "any `{` or `}` anywhere", not
10846        // single-byte coverage. Mirrors the peer
10847        // `validate_rejects_path_fonte_with_caminho_carrying_close_paren`
10848        // shape on the immediate-predecessor `FonteCaminhoShellSubshellGrouping`
10849        // arm.
10850        let d = dep_with_fonte(DepSource::Path {
10851            caminho: "../caixa-teia}".into(),
10852        });
10853        let err = d.validate().unwrap_err();
10854        let DepError::FonteCaminhoShellBraceExpansion { byte, .. } = err else {
10855            panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10856        };
10857        assert_eq!(byte, b'}');
10858    }
10859
10860    #[test]
10861    fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_brace() {
10862        // Leading-position `{` shape (`"{caixa-teia,caixa-helm}/build"`
10863        // — the canonical "I selected a `{a,b}` brace-expansion prefix
10864        // out of a shell-history one-liner" idiom). Pinned separately
10865        // from the embedded-byte shape so the gate covers every
10866        // position, not only mid-path.
10867        let d = dep_with_fonte(DepSource::Path {
10868            caminho: "{caixa-teia,caixa-helm}/build".into(),
10869        });
10870        let err = d.validate().unwrap_err();
10871        assert!(
10872            matches!(
10873                err,
10874                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10875            ),
10876            "got {err:?}",
10877        );
10878    }
10879
10880    #[test]
10881    fn validate_rejects_path_fonte_with_caminho_carrying_uri_template_placeholder() {
10882        // The canonical URI-Template / Mustache / Helm doubled-brace
10883        // placeholder shape (`"../{{org}}/caixa-teia"` — the canonical
10884        // "I copied a `https://github.com/{{org}}/caixa-teia` README
10885        // quick-start / OpenAPI spec / Helm chart `home:` template
10886        // and forgot to substitute the placeholder" footgun). The arm
10887        // fires on the first `{` encountered; pinned so the gate's
10888        // coverage extends from the bare-brace shell-history shape to
10889        // the doubled-brace URI-Template / templating-engine shape.
10890        // Mirrors the peer 42d8f9d `is_git_repo_url` arm on the
10891        // sibling `:fonte :repo` axis.
10892        let d = dep_with_fonte(DepSource::Path {
10893            caminho: "../{{org}}/caixa-teia".into(),
10894        });
10895        let err = d.validate().unwrap_err();
10896        assert!(
10897            matches!(
10898                err,
10899                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10900            ),
10901            "got {err:?}",
10902        );
10903    }
10904
10905    #[test]
10906    fn validate_rejects_path_fonte_with_caminho_carrying_brace_range_expansion() {
10907        // The canonical bash brace-range-expansion shape (`"../caixa-
10908        // v{1..10}"` — the `{1..10}` sequence expansion every bash /
10909        // zsh `for i in {1..10}; do …; done` idiom uses, the symmetric
10910        // sequence-range form to the `{a,b,c}` comma-separated form).
10911        // The arm fires on the first `{` encountered; pinned so the
10912        // gate's coverage extends from the comma-separated form to
10913        // the integer-range form.
10914        let d = dep_with_fonte(DepSource::Path {
10915            caminho: "../caixa-v{1..10}".into(),
10916        });
10917        let err = d.validate().unwrap_err();
10918        assert!(
10919            matches!(
10920                err,
10921                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10922            ),
10923            "got {err:?}",
10924        );
10925    }
10926
10927    #[test]
10928    fn validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion() {
10929        // The positive-control pin: the gate targets only `{` / `}`,
10930        // never adjacent printable ASCII or POSIX-valid bytes. The
10931        // canonical relative POSIX path (`"../caixa-teia"`) and a
10932        // nested deeply-pathed variant with adjacent printable
10933        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10934        // validate cleanly so the gate doesn't widen to a "no
10935        // printable punctuation anywhere" sweep that would defeat
10936        // the entire path-fonte author surface. Peer with
10937        // `validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping`
10938        // on the immediate-predecessor arm.
10939        let d = dep_with_fonte(DepSource::Path {
10940            caminho: "../caixa-teia/sub-dir.v2".into(),
10941        });
10942        d.validate().unwrap();
10943    }
10944
10945    #[test]
10946    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_brace_expansion() {
10947        // Cascade pin on the immediate-predecessor arm: a value
10948        // carrying both `(` and `{` (`"../(cd foo)/{a,b}"` — the
10949        // canonical "I pasted a subshell-grouping followed by a
10950        // brace-expansion tail" footgun) routes through
10951        // `FonteCaminhoShellSubshellGrouping` not
10952        // `FonteCaminhoShellBraceExpansion`. The subshell-grouping
10953        // shape is the more semantic-locating axis on every probe-
10954        // as-both value because it closes both halves of the modern
10955        // Bourne `$(<cmd>)` command-substitution surface — same
10956        // cascade discipline every prior `:caminho` arm establishes.
10957        let d = dep_with_fonte(DepSource::Path {
10958            caminho: "../(cd foo)/{a,b}".into(),
10959        });
10960        let err = d.validate().unwrap_err();
10961        assert!(
10962            matches!(
10963                err,
10964                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10965            ),
10966            "got {err:?}",
10967        );
10968    }
10969
10970    #[test]
10971    fn fonte_caminho_shell_glob_fires_before_shell_brace_expansion() {
10972        // Cascade pin on the upstream shell-glob arm: a value carrying
10973        // both `*` and `{` (`"../caixa-teia/*{a,b}"` — the canonical
10974        // "I pasted a glob expansion followed by a brace-expansion
10975        // tail" footgun) routes through `FonteCaminhoShellGlob` not
10976        // `FonteCaminhoShellBraceExpansion`. The pathname-expansion
10977        // shape is the load-bearing root-cause edit on every
10978        // probe-as-both value.
10979        let d = dep_with_fonte(DepSource::Path {
10980            caminho: "../caixa-teia/*{a,b}".into(),
10981        });
10982        let err = d.validate().unwrap_err();
10983        assert!(
10984            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10985            "got {err:?}",
10986        );
10987    }
10988
10989    #[test]
10990    fn fonte_caminho_shell_command_substitution_fires_before_shell_brace_expansion() {
10991        // Cascade pin on the upstream shell-command-substitution arm:
10992        // a value carrying both a backtick and `{` (``"../`whoami`/{a,b}"``
10993        // — the canonical "I pasted a legacy-backtick command-
10994        // substitution followed by a brace-expansion fan-out" footgun)
10995        // routes through `FonteCaminhoShellCommandSubstitution` not
10996        // `FonteCaminhoShellBraceExpansion`. The CWE-78 shell-
10997        // command-injection vector is the load-bearing root-cause
10998        // edit on every probe-as-both value.
10999        let d = dep_with_fonte(DepSource::Path {
11000            caminho: "../`whoami`/{a,b}".into(),
11001        });
11002        let err = d.validate().unwrap_err();
11003        assert!(
11004            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11005            "got {err:?}",
11006        );
11007    }
11008
11009    #[test]
11010    fn fonte_caminho_shell_background_fires_before_shell_brace_expansion() {
11011        // Cascade pin on the upstream shell-background arm: a value
11012        // carrying both `&` and `{` (`"../caixa-teia & {a,b}"` — the
11013        // canonical "I pasted a `cmd & {fork-fan}` background-launch
11014        // + brace-expansion chain" footgun) routes through
11015        // `FonteCaminhoShellBackground` not
11016        // `FonteCaminhoShellBraceExpansion`. The background-launch
11017        // tail is the load-bearing root-cause edit on every
11018        // probe-as-both value.
11019        let d = dep_with_fonte(DepSource::Path {
11020            caminho: "../caixa-teia & {a,b}".into(),
11021        });
11022        let err = d.validate().unwrap_err();
11023        assert!(
11024            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11025            "got {err:?}",
11026        );
11027    }
11028
11029    #[test]
11030    fn fonte_caminho_shell_semicolon_fires_before_shell_brace_expansion() {
11031        // Cascade pin on the upstream shell-semicolon arm: a value
11032        // carrying both `;` and `{` (`"../caixa-teia; {a,b}"` — the
11033        // canonical sequential-cleanup + brace-expansion paste
11034        // idiom) routes through `FonteCaminhoShellSemicolon` not
11035        // `FonteCaminhoShellBraceExpansion`. The sequential-command-
11036        // separator paste is the load-bearing root-cause edit on
11037        // every probe-as-both value.
11038        let d = dep_with_fonte(DepSource::Path {
11039            caminho: "../caixa-teia; {a,b}".into(),
11040        });
11041        let err = d.validate().unwrap_err();
11042        assert!(
11043            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11044            "got {err:?}",
11045        );
11046    }
11047
11048    #[test]
11049    fn fonte_caminho_shell_pipe_fires_before_shell_brace_expansion() {
11050        // Cascade pin on the upstream shell-pipe arm: a value
11051        // carrying both `|` and `{` (`"../caixa-teia | {tee,cat}"`
11052        // — the canonical pipeline-to-brace-expansion paste idiom)
11053        // routes through `FonteCaminhoShellPipe` not
11054        // `FonteCaminhoShellBraceExpansion`. The pipeline-tail paste
11055        // is the load-bearing root-cause edit on every probe-as-
11056        // both value.
11057        let d = dep_with_fonte(DepSource::Path {
11058            caminho: "../caixa-teia | {tee,cat}".into(),
11059        });
11060        let err = d.validate().unwrap_err();
11061        assert!(
11062            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11063            "got {err:?}",
11064        );
11065    }
11066
11067    #[test]
11068    fn fonte_caminho_shell_redirection_fires_before_shell_brace_expansion() {
11069        // Cascade pin on the upstream shell-redirection arm: a value
11070        // carrying both `>` and `{` (`"../caixa-teia>log {a,b}"` —
11071        // the canonical "I pasted a `cmd > log {a,b}` redirect-
11072        // plus-brace-expansion chain" footgun) routes through
11073        // `FonteCaminhoShellRedirection` not
11074        // `FonteCaminhoShellBraceExpansion`. The input/output
11075        // redirection metachar carries the more self-locating
11076        // `byte` payload, so the prior arm wins on every probe-
11077        // as-both value.
11078        let d = dep_with_fonte(DepSource::Path {
11079            caminho: "../caixa-teia>log {a,b}".into(),
11080        });
11081        let err = d.validate().unwrap_err();
11082        assert!(
11083            matches!(
11084                err,
11085                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11086            ),
11087            "got {err:?}",
11088        );
11089    }
11090
11091    #[test]
11092    fn fonte_caminho_backslash_fires_before_shell_brace_expansion() {
11093        // Cascade pin on the upstream backslash arm: a value
11094        // carrying both `\` and `{` (`"..\caixa-teia\{a,b}"` — the
11095        // canonical "I pasted a Windows-shell `cd ..\path\{a,b}`
11096        // chain") routes through `FonteCaminhoBackslash` not
11097        // `FonteCaminhoShellBraceExpansion`. The cross-host-OS-
11098        // separator divergence is the load-bearing axis on every
11099        // probe-as-both value.
11100        let d = dep_with_fonte(DepSource::Path {
11101            caminho: "..\\caixa-teia\\{a,b}".into(),
11102        });
11103        let err = d.validate().unwrap_err();
11104        assert!(
11105            matches!(err, DepError::FonteCaminhoBackslash { .. }),
11106            "got {err:?}",
11107        );
11108    }
11109
11110    #[test]
11111    fn fonte_caminho_control_char_fires_before_shell_brace_expansion() {
11112        // Cascade pin on the embedded-control-byte arm: a value
11113        // carrying both a control byte and `{` (`"../foo\n{a,b}"` —
11114        // the canonical paste-from-multiline-doc footgun where a
11115        // newline landed mid-caminho between two paste fragments)
11116        // routes through `FonteCaminhoControlChar` not
11117        // `FonteCaminhoShellBraceExpansion`. The POSIX-syscall-
11118        // rejected-byte / NUL-`CString::new`-fail diagnostic is the
11119        // load-bearing axis on every value that probes positive for
11120        // both — mirrors the cascade discipline on every prior arm.
11121        let d = dep_with_fonte(DepSource::Path {
11122            caminho: "../foo\n{a,b}".into(),
11123        });
11124        let err = d.validate().unwrap_err();
11125        assert!(
11126            matches!(err, DepError::FonteCaminhoControlChar { .. }),
11127            "got {err:?}",
11128        );
11129    }
11130
11131    #[test]
11132    fn fonte_caminho_absolute_fires_before_shell_brace_expansion() {
11133        // Cascade pin on the load-bearing leading-byte arm: a
11134        // leading `/` value with embedded `{` (`"/etc/{a,b}"`)
11135        // routes through `FonteCaminhoAbsolute` not
11136        // `FonteCaminhoShellBraceExpansion` — the host-layout-leak
11137        // diagnostic is the load-bearing axis, the brace-expansion
11138        // byte is the secondary observation. Same precedence logic
11139        // as every prior leading-byte arm.
11140        let d = dep_with_fonte(DepSource::Path {
11141            caminho: "/etc/{a,b}".into(),
11142        });
11143        let err = d.validate().unwrap_err();
11144        assert!(
11145            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11146            "got {err:?}",
11147        );
11148    }
11149
11150    #[test]
11151    fn fonte_caminho_var_expansion_fires_before_shell_brace_expansion() {
11152        // Cascade pin on the upstream leading-`$` var-expansion
11153        // arm: a value carrying both a leading `$` and a `{`
11154        // (`"${ORG}/caixa-teia"` — the canonical "I pasted a
11155        // `${ORG}` shell-variable + curly-brace expansion at the
11156        // head of a sibling-workspace path" footgun) routes through
11157        // `FonteCaminhoVarExpansion` not
11158        // `FonteCaminhoShellBraceExpansion`. The leading-byte
11159        // shell-variable-expansion is the more self-locating
11160        // diagnostic on values that probe as both — same
11161        // load-bearing-leading-byte cascade discipline every prior
11162        // `:caminho` arm establishes.
11163        let d = dep_with_fonte(DepSource::Path {
11164            caminho: "${ORG}/caixa-teia".into(),
11165        });
11166        let err = d.validate().unwrap_err();
11167        assert!(
11168            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11169            "got {err:?}",
11170        );
11171    }
11172
11173    #[test]
11174    fn fonte_caminho_shell_brace_expansion_fires_before_trailing_slash() {
11175        // Cascade pin on the immediate-successor arm: a value
11176        // carrying both `{` and a trailing `/`
11177        // (`"../{caixa-teia,caixa-helm}/"` — the canonical "I
11178        // tab-completed a path that already had a brace-expansion
11179        // expansion tail" footgun) routes through
11180        // `FonteCaminhoShellBraceExpansion` not
11181        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11182        // is the more semantic-locating axis (an author who removes
11183        // the `{` typically also drops the trailing separator since
11184        // both are paste-from-shell artifacts).
11185        let d = dep_with_fonte(DepSource::Path {
11186            caminho: "../{caixa-teia,caixa-helm}/".into(),
11187        });
11188        let err = d.validate().unwrap_err();
11189        assert!(
11190            matches!(
11191                err,
11192                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11193            ),
11194            "got {err:?}",
11195        );
11196    }
11197
11198    #[test]
11199    fn fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11200        // Diagnostic-shape pin (peer with
11201        // `fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
11202        // on the closest two-byte peer arm): the error's Display
11203        // surfaces the offending `:nome`, the offending `:caminho`
11204        // verbatim, the offending byte's hex / character form, and
11205        // names the shell-brace-expansion / URI-Template footgun
11206        // explicitly so a `feira lint` run can render the diagnostic
11207        // without re-parsing.
11208        let d = dep_with_fonte(DepSource::Path {
11209            caminho: "../{caixa-teia,caixa-helm}/build".into(),
11210        });
11211        let rendered = d.validate().unwrap_err().to_string();
11212        assert!(
11213            rendered.contains("caixa-teia"),
11214            "diagnostic must name the offending dep: {rendered}",
11215        );
11216        assert!(
11217            rendered.contains("../{caixa-teia,caixa-helm}/build"),
11218            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11219        );
11220        assert!(
11221            rendered.contains("0x7b"),
11222            "diagnostic must surface the offending byte hex: {rendered:?}",
11223        );
11224        assert!(
11225            rendered.contains("brace-expansion"),
11226            "diagnostic must name the shell-brace-expansion footgun: {rendered:?}",
11227        );
11228        assert!(
11229            rendered.contains("URI Template"),
11230            "diagnostic must reference the RFC-6570 URI-Template-placeholder vocabulary: \
11231             {rendered:?}",
11232        );
11233    }
11234
11235    #[test]
11236    fn validate_rejects_path_fonte_with_caminho_carrying_bracket_glob_character_class() {
11237        // The canonical paste-from-shell-history bracket-glob /
11238        // character-class footgun: an author copies a
11239        // `cd ../caixa-[a-z]/build` shell-history one-liner whose
11240        // `[a-z]` POSIX glob character-class matches every lowercase-
11241        // ASCII-suffix sibling caixa directory and silently passed
11242        // every prior arm (`Path::is_absolute` false on `..`, no
11243        // control bytes, no `\`, no `<` / `>`, no `|`, no `;`, no
11244        // `&`, no backtick, no `*` / `?`, no `(` / `)`, no `{` /
11245        // `}`, doesn't end in `/`; the leading-`$` f4efe9c
11246        // `FonteCaminhoVarExpansion` arm doesn't fire because the
11247        // value starts with `..` not `$`). The lacre embedded the
11248        // value verbatim, the resolver folded it through
11249        // `Path::join` looking for a literal `./../caixa-[a-z]/
11250        // build` subdirectory, and the failure surfaced at resolve
11251        // time with a non-self-locating `No such file or directory`
11252        // error. The new arm moves the rejection to validate time
11253        // and names the offending dep + caminho + byte verbatim.
11254        // The arm fires on the first `[` encountered.
11255        let d = dep_with_fonte(DepSource::Path {
11256            caminho: "../caixa-[a-z]/build".into(),
11257        });
11258        let err = d.validate().unwrap_err();
11259        let DepError::FonteCaminhoShellBracketExpansion {
11260            nome,
11261            caminho,
11262            byte,
11263        } = err
11264        else {
11265            panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11266        };
11267        assert_eq!(nome, "caixa-teia");
11268        assert_eq!(caminho, "../caixa-[a-z]/build");
11269        assert_eq!(byte, b'[');
11270    }
11271
11272    #[test]
11273    fn validate_rejects_path_fonte_with_caminho_carrying_close_bracket() {
11274        // The symmetric close-bracket paste shape (`"../caixa-teia]"`
11275        // — the degenerate "I selected an unbalanced closing bracket
11276        // out of a glob character-class block" idiom that probes for
11277        // the cascade's last-byte handling on a value carrying only
11278        // the closing byte). Pinned separately from the open-bracket
11279        // shape so the gate's contract is "any `[` or `]` anywhere",
11280        // not single-byte coverage. Mirrors the peer
11281        // `validate_rejects_path_fonte_with_caminho_carrying_close_brace`
11282        // shape on the immediate-predecessor
11283        // `FonteCaminhoShellBraceExpansion` arm.
11284        let d = dep_with_fonte(DepSource::Path {
11285            caminho: "../caixa-teia]".into(),
11286        });
11287        let err = d.validate().unwrap_err();
11288        let DepError::FonteCaminhoShellBracketExpansion { byte, .. } = err else {
11289            panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11290        };
11291        assert_eq!(byte, b']');
11292    }
11293
11294    #[test]
11295    fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_bracket() {
11296        // Leading-position `[` shape (`"[caixa-teia]/build"` — the
11297        // canonical "I selected a `[caixa-teia]` TOML-table-header /
11298        // glob-character-class prefix out of an aligned config /
11299        // shell-history one-liner" idiom). Pinned separately from
11300        // the embedded-byte shape so the gate covers every position,
11301        // not only mid-path.
11302        let d = dep_with_fonte(DepSource::Path {
11303            caminho: "[caixa-teia]/build".into(),
11304        });
11305        let err = d.validate().unwrap_err();
11306        assert!(
11307            matches!(
11308                err,
11309                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11310            ),
11311            "got {err:?}",
11312        );
11313    }
11314
11315    #[test]
11316    fn validate_rejects_path_fonte_with_caminho_carrying_toml_inline_array() {
11317        // The canonical TOML inline-array / YAML flow-sequence
11318        // paste shape (`"../[\"a\", \"b\"]/caixa-teia"` — the
11319        // canonical "I copied a `features = [\"a\", \"b\"]` TOML
11320        // inline-array out of a sibling-Cargo manifest" cross-idiom
11321        // leak; the symmetric YAML flow-sequence form `paths: [/a,
11322        // /b]` paste-from-values.yaml shape carries the same
11323        // bracket pair). The arm fires on the first `[` encountered;
11324        // pinned so the gate's coverage extends from the bare-
11325        // bracket glob-character-class shape to the TOML / YAML /
11326        // JSON array-literal shape.
11327        let d = dep_with_fonte(DepSource::Path {
11328            caminho: "../[\"a\", \"b\"]/caixa-teia".into(),
11329        });
11330        let err = d.validate().unwrap_err();
11331        assert!(
11332            matches!(
11333                err,
11334                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11335            ),
11336            "got {err:?}",
11337        );
11338    }
11339
11340    #[test]
11341    fn validate_rejects_path_fonte_with_caminho_carrying_shell_test_builtin() {
11342        // The canonical POSIX `test` / `[` builtin command paste
11343        // shape (`"../[ -d caixa-teia ]"` — the `[ <expr> ]` shell-
11344        // script conditional every paste-from-shell-script idiom
11345        // carries; bash's `[[ <expr> ]]` extended-test grammar
11346        // would surface the same byte pair). The arm fires on the
11347        // first `[` encountered; pinned so the gate's coverage
11348        // extends from the embedded-glob-character-class shape to
11349        // the leading-`test`-builtin / extended-test form.
11350        let d = dep_with_fonte(DepSource::Path {
11351            caminho: "../[ -d caixa-teia ]".into(),
11352        });
11353        let err = d.validate().unwrap_err();
11354        assert!(
11355            matches!(
11356                err,
11357                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11358            ),
11359            "got {err:?}",
11360        );
11361    }
11362
11363    #[test]
11364    fn validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion() {
11365        // The positive-control pin: the gate targets only `[` /
11366        // `]`, never adjacent printable ASCII or POSIX-valid bytes.
11367        // The canonical relative POSIX path (`"../caixa-teia"`) and
11368        // a nested deeply-pathed variant with adjacent printable
11369        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11370        // to validate cleanly so the gate doesn't widen to a "no
11371        // printable punctuation anywhere" sweep that would defeat
11372        // the entire path-fonte author surface. Peer with
11373        // `validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion`
11374        // on the immediate-predecessor arm.
11375        let d = dep_with_fonte(DepSource::Path {
11376            caminho: "../caixa-teia/sub-dir.v2".into(),
11377        });
11378        d.validate().unwrap();
11379    }
11380
11381    #[test]
11382    fn fonte_caminho_shell_brace_expansion_fires_before_shell_bracket_expansion() {
11383        // Cascade pin on the immediate-predecessor arm: a value
11384        // carrying both `{` and `[` (`"../{a,b}[ch]"` — the
11385        // canonical "I pasted a brace-expansion fan followed by a
11386        // glob-character-class tail" footgun) routes through
11387        // `FonteCaminhoShellBraceExpansion` not
11388        // `FonteCaminhoShellBracketExpansion`. The brace-expansion
11389        // fan is the load-bearing root-cause edit on every
11390        // probe-as-both value because the bracket-class tail
11391        // typically rides on a prior brace-expansion expansion;
11392        // same cascade discipline every prior `:caminho` arm
11393        // establishes.
11394        let d = dep_with_fonte(DepSource::Path {
11395            caminho: "../{a,b}[ch]".into(),
11396        });
11397        let err = d.validate().unwrap_err();
11398        assert!(
11399            matches!(
11400                err,
11401                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11402            ),
11403            "got {err:?}",
11404        );
11405    }
11406
11407    #[test]
11408    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_bracket_expansion() {
11409        // Cascade pin on the upstream shell-subshell-grouping arm:
11410        // a value carrying both `(` and `[` (`"../(cd foo)/[ch]"` —
11411        // the canonical "I pasted a subshell-grouping followed by
11412        // a glob-character-class tail" footgun) routes through
11413        // `FonteCaminhoShellSubshellGrouping` not
11414        // `FonteCaminhoShellBracketExpansion`. The modern Bourne
11415        // `$(<cmd>)` command-substitution boundary is the load-
11416        // bearing axis on every probe-as-both value.
11417        let d = dep_with_fonte(DepSource::Path {
11418            caminho: "../(cd foo)/[ch]".into(),
11419        });
11420        let err = d.validate().unwrap_err();
11421        assert!(
11422            matches!(
11423                err,
11424                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11425            ),
11426            "got {err:?}",
11427        );
11428    }
11429
11430    #[test]
11431    fn fonte_caminho_shell_glob_fires_before_shell_bracket_expansion() {
11432        // Cascade pin on the upstream shell-glob arm: a value
11433        // carrying both `*` and `[` (`"../caixa-teia/*[ch]"` — the
11434        // canonical "I pasted a `*.[ch]` C-source-file glob whose
11435        // unbounded `*` precedes the bracket character-class"
11436        // footgun) routes through `FonteCaminhoShellGlob` not
11437        // `FonteCaminhoShellBracketExpansion`. The unbounded
11438        // pathname-expansion sentinel is the load-bearing root-
11439        // cause edit on every probe-as-both value — the unbounded
11440        // `*` carries the more aggressive expansion vector than
11441        // the bounded `[ch]` class, so the prior arm wins.
11442        let d = dep_with_fonte(DepSource::Path {
11443            caminho: "../caixa-teia/*[ch]".into(),
11444        });
11445        let err = d.validate().unwrap_err();
11446        assert!(
11447            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11448            "got {err:?}",
11449        );
11450    }
11451
11452    #[test]
11453    fn fonte_caminho_shell_command_substitution_fires_before_shell_bracket_expansion() {
11454        // Cascade pin on the upstream shell-command-substitution
11455        // arm: a value carrying both a backtick and `[`
11456        // (``"../`whoami`/[ch]"`` — the canonical "I pasted a
11457        // legacy-backtick command-substitution followed by a
11458        // glob-character-class tail" footgun) routes through
11459        // `FonteCaminhoShellCommandSubstitution` not
11460        // `FonteCaminhoShellBracketExpansion`. The CWE-78 shell-
11461        // command-injection vector is the load-bearing root-cause
11462        // edit on every probe-as-both value.
11463        let d = dep_with_fonte(DepSource::Path {
11464            caminho: "../`whoami`/[ch]".into(),
11465        });
11466        let err = d.validate().unwrap_err();
11467        assert!(
11468            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11469            "got {err:?}",
11470        );
11471    }
11472
11473    #[test]
11474    fn fonte_caminho_shell_background_fires_before_shell_bracket_expansion() {
11475        // Cascade pin on the upstream shell-background arm: a
11476        // value carrying both `&` and `[` (`"../caixa-teia & [ch]"`
11477        // — the canonical "I pasted a `cmd & [glob]` background-
11478        // launch + bracket-class chain" footgun) routes through
11479        // `FonteCaminhoShellBackground` not
11480        // `FonteCaminhoShellBracketExpansion`. The background-
11481        // launch tail is the load-bearing root-cause edit on
11482        // every probe-as-both value.
11483        let d = dep_with_fonte(DepSource::Path {
11484            caminho: "../caixa-teia & [ch]".into(),
11485        });
11486        let err = d.validate().unwrap_err();
11487        assert!(
11488            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11489            "got {err:?}",
11490        );
11491    }
11492
11493    #[test]
11494    fn fonte_caminho_shell_semicolon_fires_before_shell_bracket_expansion() {
11495        // Cascade pin on the upstream shell-semicolon arm: a value
11496        // carrying both `;` and `[` (`"../caixa-teia; [ch]"` — the
11497        // canonical sequential-cleanup + bracket-class paste
11498        // idiom) routes through `FonteCaminhoShellSemicolon` not
11499        // `FonteCaminhoShellBracketExpansion`. The sequential-
11500        // command-separator paste is the load-bearing root-cause
11501        // edit on every probe-as-both value.
11502        let d = dep_with_fonte(DepSource::Path {
11503            caminho: "../caixa-teia; [ch]".into(),
11504        });
11505        let err = d.validate().unwrap_err();
11506        assert!(
11507            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11508            "got {err:?}",
11509        );
11510    }
11511
11512    #[test]
11513    fn fonte_caminho_shell_pipe_fires_before_shell_bracket_expansion() {
11514        // Cascade pin on the upstream shell-pipe arm: a value
11515        // carrying both `|` and `[` (`"../caixa-teia | [tee]"` —
11516        // the canonical pipeline-to-bracket-class paste idiom)
11517        // routes through `FonteCaminhoShellPipe` not
11518        // `FonteCaminhoShellBracketExpansion`. The pipeline-tail
11519        // paste is the load-bearing root-cause edit on every
11520        // probe-as-both value.
11521        let d = dep_with_fonte(DepSource::Path {
11522            caminho: "../caixa-teia | [tee]".into(),
11523        });
11524        let err = d.validate().unwrap_err();
11525        assert!(
11526            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11527            "got {err:?}",
11528        );
11529    }
11530
11531    #[test]
11532    fn fonte_caminho_shell_redirection_fires_before_shell_bracket_expansion() {
11533        // Cascade pin on the upstream shell-redirection arm: a
11534        // value carrying both `>` and `[` (`"../caixa-teia>log
11535        // [ch]"` — the canonical "I pasted a `cmd > log [glob]`
11536        // redirect-plus-bracket chain" footgun) routes through
11537        // `FonteCaminhoShellRedirection` not
11538        // `FonteCaminhoShellBracketExpansion`. The input/output
11539        // redirection metachar carries the more self-locating
11540        // `byte` payload, so the prior arm wins on every
11541        // probe-as-both value.
11542        let d = dep_with_fonte(DepSource::Path {
11543            caminho: "../caixa-teia>log [ch]".into(),
11544        });
11545        let err = d.validate().unwrap_err();
11546        assert!(
11547            matches!(
11548                err,
11549                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11550            ),
11551            "got {err:?}",
11552        );
11553    }
11554
11555    #[test]
11556    fn fonte_caminho_backslash_fires_before_shell_bracket_expansion() {
11557        // Cascade pin on the upstream backslash arm: a value
11558        // carrying both `\` and `[` (`"..\caixa-teia\[ch]"` — the
11559        // canonical "I pasted a Windows-shell `cd ..\path\[glob]`
11560        // chain") routes through `FonteCaminhoBackslash` not
11561        // `FonteCaminhoShellBracketExpansion`. The cross-host-OS-
11562        // separator divergence is the load-bearing axis on every
11563        // probe-as-both value.
11564        let d = dep_with_fonte(DepSource::Path {
11565            caminho: "..\\caixa-teia\\[ch]".into(),
11566        });
11567        let err = d.validate().unwrap_err();
11568        assert!(
11569            matches!(err, DepError::FonteCaminhoBackslash { .. }),
11570            "got {err:?}",
11571        );
11572    }
11573
11574    #[test]
11575    fn fonte_caminho_control_char_fires_before_shell_bracket_expansion() {
11576        // Cascade pin on the embedded-control-byte arm: a value
11577        // carrying both a control byte and `[` (`"../foo\n[ch]"` —
11578        // the canonical paste-from-multiline-doc footgun where a
11579        // newline landed mid-caminho between two paste fragments)
11580        // routes through `FonteCaminhoControlChar` not
11581        // `FonteCaminhoShellBracketExpansion`. The POSIX-syscall-
11582        // rejected-byte / NUL-`CString::new`-fail diagnostic is
11583        // the load-bearing axis on every value that probes
11584        // positive for both — mirrors the cascade discipline on
11585        // every prior arm.
11586        let d = dep_with_fonte(DepSource::Path {
11587            caminho: "../foo\n[ch]".into(),
11588        });
11589        let err = d.validate().unwrap_err();
11590        assert!(
11591            matches!(err, DepError::FonteCaminhoControlChar { .. }),
11592            "got {err:?}",
11593        );
11594    }
11595
11596    #[test]
11597    fn fonte_caminho_absolute_fires_before_shell_bracket_expansion() {
11598        // Cascade pin on the load-bearing leading-byte arm: a
11599        // leading `/` value with embedded `[` (`"/etc/[ch]"`)
11600        // routes through `FonteCaminhoAbsolute` not
11601        // `FonteCaminhoShellBracketExpansion` — the host-layout-
11602        // leak diagnostic is the load-bearing axis, the bracket-
11603        // expansion byte is the secondary observation. Same
11604        // precedence logic as every prior leading-byte arm.
11605        let d = dep_with_fonte(DepSource::Path {
11606            caminho: "/etc/[ch]".into(),
11607        });
11608        let err = d.validate().unwrap_err();
11609        assert!(
11610            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11611            "got {err:?}",
11612        );
11613    }
11614
11615    #[test]
11616    fn fonte_caminho_var_expansion_fires_before_shell_bracket_expansion() {
11617        // Cascade pin on the upstream leading-`$` var-expansion
11618        // arm: a value carrying both a leading `$` and a `[`
11619        // (`"$DIR/[ch]"` — the canonical "I pasted a `$DIR` shell-
11620        // variable + bracket-class at the head of a sibling-
11621        // workspace path" footgun) routes through
11622        // `FonteCaminhoVarExpansion` not
11623        // `FonteCaminhoShellBracketExpansion`. The leading-byte
11624        // shell-variable-expansion is the more self-locating
11625        // diagnostic on values that probe as both — same
11626        // load-bearing-leading-byte cascade discipline every
11627        // prior `:caminho` arm establishes.
11628        let d = dep_with_fonte(DepSource::Path {
11629            caminho: "$DIR/[ch]".into(),
11630        });
11631        let err = d.validate().unwrap_err();
11632        assert!(
11633            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11634            "got {err:?}",
11635        );
11636    }
11637
11638    #[test]
11639    fn fonte_caminho_shell_bracket_expansion_fires_before_trailing_slash() {
11640        // Cascade pin on the immediate-successor arm: a value
11641        // carrying both `[` and a trailing `/` (`"../[a-z]/"` —
11642        // the canonical "I tab-completed a path that already had
11643        // a bracket-glob-character-class expansion tail" footgun)
11644        // routes through `FonteCaminhoShellBracketExpansion` not
11645        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11646        // is the more semantic-locating axis (an author who
11647        // removes the `[` typically also drops the trailing
11648        // separator since both are paste-from-shell artifacts).
11649        let d = dep_with_fonte(DepSource::Path {
11650            caminho: "../[a-z]/".into(),
11651        });
11652        let err = d.validate().unwrap_err();
11653        assert!(
11654            matches!(
11655                err,
11656                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11657            ),
11658            "got {err:?}",
11659        );
11660    }
11661
11662    #[test]
11663    fn fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11664        // Diagnostic-shape pin (peer with
11665        // `fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11666        // on the closest two-byte peer arm): the error's Display
11667        // surfaces the offending `:nome`, the offending `:caminho`
11668        // verbatim, the offending byte's hex / character form, and
11669        // names the shell-bracket-expansion / glob-character-class
11670        // footgun explicitly so a `feira lint` run can render the
11671        // diagnostic without re-parsing.
11672        let d = dep_with_fonte(DepSource::Path {
11673            caminho: "../caixa-[a-z]/build".into(),
11674        });
11675        let rendered = d.validate().unwrap_err().to_string();
11676        assert!(
11677            rendered.contains("caixa-teia"),
11678            "diagnostic must name the offending dep: {rendered}",
11679        );
11680        assert!(
11681            rendered.contains("../caixa-[a-z]/build"),
11682            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11683        );
11684        assert!(
11685            rendered.contains("0x5b"),
11686            "diagnostic must surface the offending byte hex: {rendered:?}",
11687        );
11688        assert!(
11689            rendered.contains("bracket-expansion"),
11690            "diagnostic must name the shell-bracket-expansion footgun: {rendered:?}",
11691        );
11692        assert!(
11693            rendered.contains("glob-character-class"),
11694            "diagnostic must reference the POSIX glob-character-class vocabulary: \
11695             {rendered:?}",
11696        );
11697    }
11698
11699    #[test]
11700    fn validate_rejects_path_fonte_with_caminho_carrying_single_quote_grouping() {
11701        // The canonical paste-from-shell-history strong-quoted
11702        // sibling-workspace-path footgun: an author copies a
11703        // `cd '../caixa-teia'` shell-history one-liner whose strong-
11704        // quoting preserved the path across a whitespace paste
11705        // boundary and silently passed every prior arm
11706        // (`Path::is_absolute` false on `'..`, no control bytes, no
11707        // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no
11708        // `*` / `?`, no `(` / `)`, no `{` / `}`, no `[` / `]`,
11709        // doesn't end in `/`; the leading-`$` f4efe9c
11710        // `FonteCaminhoVarExpansion` arm doesn't fire because the
11711        // value starts with `'` not `$`). The lacre embedded the
11712        // value verbatim, the resolver folded it through
11713        // `Path::join` looking for a literal `./'../caixa-teia'`
11714        // subdirectory, and the failure surfaced at resolve time
11715        // with a non-self-locating `No such file or directory`
11716        // error. The new arm moves the rejection to validate time
11717        // and names the offending dep + caminho + byte verbatim.
11718        // The arm fires on the first `'` encountered.
11719        let d = dep_with_fonte(DepSource::Path {
11720            caminho: "'../caixa-teia'".into(),
11721        });
11722        let err = d.validate().unwrap_err();
11723        let DepError::FonteCaminhoShellQuoteGrouping {
11724            nome,
11725            caminho,
11726            byte,
11727        } = err
11728        else {
11729            panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11730        };
11731        assert_eq!(nome, "caixa-teia");
11732        assert_eq!(caminho, "'../caixa-teia'");
11733        assert_eq!(byte, b'\'');
11734    }
11735
11736    #[test]
11737    fn validate_rejects_path_fonte_with_caminho_carrying_double_quote_grouping() {
11738        // The symmetric weak-quoted paste shape (`"\"../caixa-teia\""`
11739        // — the canonical paste-from-JSON-config / paste-from-YAML-
11740        // flow-scalar / paste-from-TOML-basic-string / paste-from-
11741        // tatara-lisp-string-literal cross-idiom leak). Pinned
11742        // separately from the single-quote shape so the gate's
11743        // contract is "any `'` or `\"` anywhere", not single-byte
11744        // coverage. Mirrors the peer
11745        // `validate_rejects_path_fonte_with_caminho_carrying_close_bracket`
11746        // shape on the immediate-predecessor
11747        // `FonteCaminhoShellBracketExpansion` arm.
11748        let d = dep_with_fonte(DepSource::Path {
11749            caminho: "\"../caixa-teia\"".into(),
11750        });
11751        let err = d.validate().unwrap_err();
11752        let DepError::FonteCaminhoShellQuoteGrouping { byte, .. } = err else {
11753            panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11754        };
11755        assert_eq!(byte, b'"');
11756    }
11757
11758    #[test]
11759    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_double_quote() {
11760        // Embedded-position `"` shape (`"../\"caixa-teia\""` — the
11761        // canonical "I pasted a JSON key-value pair fragment into
11762        // the middle of the path" idiom). Pinned separately from
11763        // the leading-byte shape so the gate covers every position,
11764        // not only leading.
11765        let d = dep_with_fonte(DepSource::Path {
11766            caminho: "../\"caixa-teia\"".into(),
11767        });
11768        let err = d.validate().unwrap_err();
11769        assert!(
11770            matches!(
11771                err,
11772                DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11773            ),
11774            "got {err:?}",
11775        );
11776    }
11777
11778    #[test]
11779    fn validate_rejects_path_fonte_with_caminho_carrying_yaml_flow_scalar_paste() {
11780        // The canonical YAML double-quoted flow-scalar cross-idiom
11781        // leak shape (`"path: \"../caixa-teia\""` — the "I copied a
11782        // `path: \"...\"` YAML flow-scalar entry out of an aligned
11783        // values.yaml / K8s manifest and dropped it verbatim into
11784        // the `:caminho` slot including the `path: ` key prefix"
11785        // paste-idiom). The arm fires on the first `"` encountered;
11786        // pinned so the gate's coverage extends from the bare-quote
11787        // paste shape to the aligned-YAML-manifest cross-idiom-leak
11788        // shape.
11789        let d = dep_with_fonte(DepSource::Path {
11790            caminho: "path: \"../caixa-teia\"".into(),
11791        });
11792        let err = d.validate().unwrap_err();
11793        assert!(
11794            matches!(
11795                err,
11796                DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11797            ),
11798            "got {err:?}",
11799        );
11800    }
11801
11802    #[test]
11803    fn validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping() {
11804        // The positive-control pin: the gate targets only `'` /
11805        // `"`, never adjacent printable ASCII or POSIX-valid bytes.
11806        // The canonical relative POSIX path (`"../caixa-teia"`) and
11807        // a nested deeply-pathed variant with adjacent printable
11808        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11809        // to validate cleanly so the gate doesn't widen to a "no
11810        // printable punctuation anywhere" sweep that would defeat
11811        // the entire path-fonte author surface. Peer with
11812        // `validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion`
11813        // on the immediate-predecessor arm.
11814        let d = dep_with_fonte(DepSource::Path {
11815            caminho: "../caixa-teia/sub-dir.v2".into(),
11816        });
11817        d.validate().unwrap();
11818    }
11819
11820    #[test]
11821    fn fonte_caminho_shell_bracket_expansion_fires_before_shell_quote_grouping() {
11822        // Cascade pin on the immediate-predecessor arm: a value
11823        // carrying both `[` and `'` (`"../[a-z]'x'"` — the canonical
11824        // "I pasted a glob-character-class followed by a strong-
11825        // quoted literal tail" footgun) routes through
11826        // `FonteCaminhoShellBracketExpansion` not
11827        // `FonteCaminhoShellQuoteGrouping`. The glob-character-class
11828        // expansion is the load-bearing root-cause edit on every
11829        // probe-as-both value; same cascade discipline every prior
11830        // `:caminho` arm establishes.
11831        let d = dep_with_fonte(DepSource::Path {
11832            caminho: "../[a-z]'x'".into(),
11833        });
11834        let err = d.validate().unwrap_err();
11835        assert!(
11836            matches!(
11837                err,
11838                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11839            ),
11840            "got {err:?}",
11841        );
11842    }
11843
11844    #[test]
11845    fn fonte_caminho_shell_brace_expansion_fires_before_shell_quote_grouping() {
11846        // Cascade pin on the upstream shell-brace-expansion arm: a
11847        // value carrying both `{` and `'` (`"../{a,b}'x'"` — the
11848        // canonical "I pasted a brace-expansion fan followed by a
11849        // strong-quoted literal tail" footgun) routes through
11850        // `FonteCaminhoShellBraceExpansion` not
11851        // `FonteCaminhoShellQuoteGrouping`. The brace-expansion fan
11852        // is the load-bearing root-cause edit on every probe-as-
11853        // both value.
11854        let d = dep_with_fonte(DepSource::Path {
11855            caminho: "../{a,b}'x'".into(),
11856        });
11857        let err = d.validate().unwrap_err();
11858        assert!(
11859            matches!(
11860                err,
11861                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11862            ),
11863            "got {err:?}",
11864        );
11865    }
11866
11867    #[test]
11868    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_quote_grouping() {
11869        // Cascade pin on the upstream shell-subshell-grouping arm:
11870        // a value carrying both `(` and `'` (`"../(cd foo)/'x'"` —
11871        // the canonical "I pasted a subshell-grouping followed by
11872        // a strong-quoted literal tail" footgun) routes through
11873        // `FonteCaminhoShellSubshellGrouping` not
11874        // `FonteCaminhoShellQuoteGrouping`. The modern Bourne
11875        // `$(<cmd>)` command-substitution boundary is the load-
11876        // bearing axis on every probe-as-both value.
11877        let d = dep_with_fonte(DepSource::Path {
11878            caminho: "../(cd foo)/'x'".into(),
11879        });
11880        let err = d.validate().unwrap_err();
11881        assert!(
11882            matches!(
11883                err,
11884                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11885            ),
11886            "got {err:?}",
11887        );
11888    }
11889
11890    #[test]
11891    fn fonte_caminho_shell_glob_fires_before_shell_quote_grouping() {
11892        // Cascade pin on the upstream shell-glob arm: a value
11893        // carrying both `*` and `'` (`"../caixa-teia/*'x'"` — the
11894        // canonical "I pasted a `*` unbounded pathname-expansion
11895        // followed by a strong-quoted literal tail" footgun) routes
11896        // through `FonteCaminhoShellGlob` not
11897        // `FonteCaminhoShellQuoteGrouping`. The unbounded pathname-
11898        // expansion sentinel is the load-bearing root-cause edit
11899        // on every probe-as-both value.
11900        let d = dep_with_fonte(DepSource::Path {
11901            caminho: "../caixa-teia/*'x'".into(),
11902        });
11903        let err = d.validate().unwrap_err();
11904        assert!(
11905            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11906            "got {err:?}",
11907        );
11908    }
11909
11910    #[test]
11911    fn fonte_caminho_shell_command_substitution_fires_before_shell_quote_grouping() {
11912        // Cascade pin on the upstream shell-command-substitution
11913        // arm: a value carrying both a backtick and `'`
11914        // (``"../`whoami`/'x'"`` — the canonical "I pasted a
11915        // legacy-backtick command-substitution followed by a
11916        // strong-quoted literal tail" footgun) routes through
11917        // `FonteCaminhoShellCommandSubstitution` not
11918        // `FonteCaminhoShellQuoteGrouping`. The CWE-78 shell-
11919        // command-injection vector is the load-bearing root-cause
11920        // edit on every probe-as-both value.
11921        let d = dep_with_fonte(DepSource::Path {
11922            caminho: "../`whoami`/'x'".into(),
11923        });
11924        let err = d.validate().unwrap_err();
11925        assert!(
11926            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11927            "got {err:?}",
11928        );
11929    }
11930
11931    #[test]
11932    fn fonte_caminho_shell_background_fires_before_shell_quote_grouping() {
11933        // Cascade pin on the upstream shell-background arm: a value
11934        // carrying both `&` and `'` (`"../caixa-teia & 'x'"` — the
11935        // canonical "I pasted a `cmd & 'literal'` background-launch
11936        // + quote chain" footgun) routes through
11937        // `FonteCaminhoShellBackground` not
11938        // `FonteCaminhoShellQuoteGrouping`. The background-launch
11939        // tail is the load-bearing root-cause edit on every
11940        // probe-as-both value.
11941        let d = dep_with_fonte(DepSource::Path {
11942            caminho: "../caixa-teia & 'x'".into(),
11943        });
11944        let err = d.validate().unwrap_err();
11945        assert!(
11946            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11947            "got {err:?}",
11948        );
11949    }
11950
11951    #[test]
11952    fn fonte_caminho_shell_semicolon_fires_before_shell_quote_grouping() {
11953        // Cascade pin on the upstream shell-semicolon arm: a value
11954        // carrying both `;` and `'` (`"../caixa-teia; 'x'"` — the
11955        // canonical sequential-cleanup + quote paste idiom) routes
11956        // through `FonteCaminhoShellSemicolon` not
11957        // `FonteCaminhoShellQuoteGrouping`. The sequential-command-
11958        // separator paste is the load-bearing root-cause edit on
11959        // every probe-as-both value.
11960        let d = dep_with_fonte(DepSource::Path {
11961            caminho: "../caixa-teia; 'x'".into(),
11962        });
11963        let err = d.validate().unwrap_err();
11964        assert!(
11965            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11966            "got {err:?}",
11967        );
11968    }
11969
11970    #[test]
11971    fn fonte_caminho_shell_pipe_fires_before_shell_quote_grouping() {
11972        // Cascade pin on the upstream shell-pipe arm: a value
11973        // carrying both `|` and `'` (`"../caixa-teia | 'x'"` — the
11974        // canonical pipeline-to-quoted-literal paste idiom) routes
11975        // through `FonteCaminhoShellPipe` not
11976        // `FonteCaminhoShellQuoteGrouping`. The pipeline-tail paste
11977        // is the load-bearing root-cause edit on every probe-as-
11978        // both value.
11979        let d = dep_with_fonte(DepSource::Path {
11980            caminho: "../caixa-teia | 'x'".into(),
11981        });
11982        let err = d.validate().unwrap_err();
11983        assert!(
11984            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11985            "got {err:?}",
11986        );
11987    }
11988
11989    #[test]
11990    fn fonte_caminho_shell_redirection_fires_before_shell_quote_grouping() {
11991        // Cascade pin on the upstream shell-redirection arm: a
11992        // value carrying both `>` and `'` (`"../caixa-teia>log 'x'"`
11993        // — the canonical "I pasted a `cmd > log 'literal'`
11994        // redirect-plus-quote chain" footgun) routes through
11995        // `FonteCaminhoShellRedirection` not
11996        // `FonteCaminhoShellQuoteGrouping`. The input/output
11997        // redirection metachar carries the more self-locating
11998        // `byte` payload, so the prior arm wins on every probe-as-
11999        // both value.
12000        let d = dep_with_fonte(DepSource::Path {
12001            caminho: "../caixa-teia>log 'x'".into(),
12002        });
12003        let err = d.validate().unwrap_err();
12004        assert!(
12005            matches!(
12006                err,
12007                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12008            ),
12009            "got {err:?}",
12010        );
12011    }
12012
12013    #[test]
12014    fn fonte_caminho_backslash_fires_before_shell_quote_grouping() {
12015        // Cascade pin on the upstream backslash arm: a value
12016        // carrying both `\` and `'` (`"..\caixa-teia\'x'"` — the
12017        // canonical "I pasted a Windows-shell `cd ..\path\'literal'`
12018        // chain" footgun) routes through `FonteCaminhoBackslash`
12019        // not `FonteCaminhoShellQuoteGrouping`. The cross-host-OS-
12020        // separator divergence is the load-bearing axis on every
12021        // probe-as-both value.
12022        let d = dep_with_fonte(DepSource::Path {
12023            caminho: "..\\caixa-teia\\'x'".into(),
12024        });
12025        let err = d.validate().unwrap_err();
12026        assert!(
12027            matches!(err, DepError::FonteCaminhoBackslash { .. }),
12028            "got {err:?}",
12029        );
12030    }
12031
12032    #[test]
12033    fn fonte_caminho_control_char_fires_before_shell_quote_grouping() {
12034        // Cascade pin on the embedded-control-byte arm: a value
12035        // carrying both a control byte and `'` (`"../foo\n'x'"` —
12036        // the canonical paste-from-multiline-doc footgun where a
12037        // newline landed mid-caminho between two paste fragments)
12038        // routes through `FonteCaminhoControlChar` not
12039        // `FonteCaminhoShellQuoteGrouping`. The POSIX-syscall-
12040        // rejected-byte / NUL-`CString::new`-fail diagnostic is
12041        // the load-bearing axis on every value that probes
12042        // positive for both — mirrors the cascade discipline on
12043        // every prior arm.
12044        let d = dep_with_fonte(DepSource::Path {
12045            caminho: "../foo\n'x'".into(),
12046        });
12047        let err = d.validate().unwrap_err();
12048        assert!(
12049            matches!(err, DepError::FonteCaminhoControlChar { .. }),
12050            "got {err:?}",
12051        );
12052    }
12053
12054    #[test]
12055    fn fonte_caminho_absolute_fires_before_shell_quote_grouping() {
12056        // Cascade pin on the load-bearing leading-byte arm: a
12057        // leading `/` value with embedded `'` (`"/etc/'x'"`) routes
12058        // through `FonteCaminhoAbsolute` not
12059        // `FonteCaminhoShellQuoteGrouping` — the host-layout-leak
12060        // diagnostic is the load-bearing axis, the quote byte is
12061        // the secondary observation. Same precedence logic as every
12062        // prior leading-byte arm.
12063        let d = dep_with_fonte(DepSource::Path {
12064            caminho: "/etc/'x'".into(),
12065        });
12066        let err = d.validate().unwrap_err();
12067        assert!(
12068            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12069            "got {err:?}",
12070        );
12071    }
12072
12073    #[test]
12074    fn fonte_caminho_var_expansion_fires_before_shell_quote_grouping() {
12075        // Cascade pin on the upstream leading-`$` var-expansion
12076        // arm: a value carrying both a leading `$` and a `'`
12077        // (`"$DIR/'x'"` — the canonical "I pasted a `$DIR` shell-
12078        // variable + quoted literal at the head of a sibling-
12079        // workspace path" footgun) routes through
12080        // `FonteCaminhoVarExpansion` not
12081        // `FonteCaminhoShellQuoteGrouping`. The leading-byte
12082        // shell-variable-expansion is the more self-locating
12083        // diagnostic on values that probe as both — same
12084        // load-bearing-leading-byte cascade discipline every
12085        // prior `:caminho` arm establishes.
12086        let d = dep_with_fonte(DepSource::Path {
12087            caminho: "$DIR/'x'".into(),
12088        });
12089        let err = d.validate().unwrap_err();
12090        assert!(
12091            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12092            "got {err:?}",
12093        );
12094    }
12095
12096    #[test]
12097    fn fonte_caminho_shell_quote_grouping_fires_before_trailing_slash() {
12098        // Cascade pin on the immediate-successor arm: a value
12099        // carrying both `'` and a trailing `/` (`"../'caixa-teia'/"`
12100        // — the canonical "I tab-completed a path whose strong-
12101        // quoted body already carried the quoting from a shell-
12102        // history paste" footgun) routes through
12103        // `FonteCaminhoShellQuoteGrouping` not
12104        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
12105        // is the more semantic-locating axis (an author who removes
12106        // the `'` typically also drops the trailing separator since
12107        // both are paste-from-shell artifacts).
12108        let d = dep_with_fonte(DepSource::Path {
12109            caminho: "../'caixa-teia'/".into(),
12110        });
12111        let err = d.validate().unwrap_err();
12112        assert!(
12113            matches!(
12114                err,
12115                DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12116            ),
12117            "got {err:?}",
12118        );
12119    }
12120
12121    #[test]
12122    fn fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
12123        // Diagnostic-shape pin (peer with
12124        // `fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
12125        // on the closest two-byte peer arm): the error's Display
12126        // surfaces the offending `:nome`, the offending `:caminho`
12127        // verbatim, the offending byte's hex / character form, and
12128        // names the shell-quote-grouping / cross-config-DSL-string-
12129        // literal-delimiter footgun explicitly so a `feira lint`
12130        // run can render the diagnostic without re-parsing.
12131        let d = dep_with_fonte(DepSource::Path {
12132            caminho: "'../caixa-teia'".into(),
12133        });
12134        let rendered = d.validate().unwrap_err().to_string();
12135        assert!(
12136            rendered.contains("caixa-teia"),
12137            "diagnostic must name the offending dep: {rendered}",
12138        );
12139        assert!(
12140            rendered.contains("'../caixa-teia'"),
12141            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12142        );
12143        assert!(
12144            rendered.contains("0x27"),
12145            "diagnostic must surface the offending byte hex: {rendered:?}",
12146        );
12147        assert!(
12148            rendered.contains("quote-grouping"),
12149            "diagnostic must name the shell-quote-grouping footgun: {rendered:?}",
12150        );
12151        assert!(
12152            rendered.contains("string-literal"),
12153            "diagnostic must reference the cross-config-DSL string-literal-delimiter \
12154             vocabulary: {rendered:?}",
12155        );
12156    }
12157
12158    #[test]
12159    fn validate_rejects_path_fonte_with_caminho_carrying_shell_comment_lead() {
12160        // The canonical paste-from-shell-history-with-trailing-
12161        // annotation footgun: an author pastes a `cd ../caixa-teia
12162        // # legacy sibling` shell-history one-liner whose unquoted `#`
12163        // comment-lead separates the path from an inline annotation.
12164        // The POSIX shell trims the annotation to `../caixa-teia`
12165        // (POSIX.1-2017 §2.3 Token Recognition step 6), but
12166        // `Path::is_absolute` returns false on `..`, `#` is neither
12167        // a leading-byte sentinel nor a control byte nor `\` nor
12168        // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` /
12169        // `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` /
12170        // `"`, and the value's last byte isn't `/` — so the value
12171        // silently passed every prior arm. The resolver folded the
12172        // value through `Path::join` looking for a literal
12173        // `./../caixa-teia # legacy sibling` subdirectory and the
12174        // failure surfaced at resolve time with a non-self-locating
12175        // `No such file or directory` error. The new arm moves the
12176        // rejection to validate time and names the offending dep +
12177        // caminho + byte verbatim.
12178        let d = dep_with_fonte(DepSource::Path {
12179            caminho: "../caixa-teia # legacy sibling".into(),
12180        });
12181        let err = d.validate().unwrap_err();
12182        let DepError::FonteCaminhoShellComment {
12183            nome,
12184            caminho,
12185            byte,
12186        } = err
12187        else {
12188            panic!("expected FonteCaminhoShellComment, got {err:?}");
12189        };
12190        assert_eq!(nome, "caixa-teia");
12191        assert_eq!(caminho, "../caixa-teia # legacy sibling");
12192        assert_eq!(byte, b'#');
12193    }
12194
12195    #[test]
12196    fn validate_rejects_path_fonte_with_caminho_carrying_yaml_comment_paste() {
12197        // The symmetric YAML flow-scalar / values.yaml / K8s-manifest
12198        // cross-idiom-leak shape (`"../caixa-teia  # pin"` — the
12199        // canonical "I copied a `path: ../caixa-teia  # pin` YAML
12200        // scalar-plus-comment entry out of an aligned values.yaml and
12201        // dropped it verbatim into the `:caminho` slot" paste-idiom).
12202        // Pinned separately from the shell-history shape so the
12203        // gate's coverage extends from the single-space `#` shape to
12204        // the YAML-canonical double-space `  #` shape. YAML 1.2 §6.6
12205        // requires the `#` to be preceded by whitespace to lex as a
12206        // comment (bare `foo#bar` is a single scalar); the double-
12207        // space paste from an aligned manifest is the canonical
12208        // shape.
12209        let d = dep_with_fonte(DepSource::Path {
12210            caminho: "../caixa-teia  # pin".into(),
12211        });
12212        let err = d.validate().unwrap_err();
12213        assert!(
12214            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12215            "got {err:?}",
12216        );
12217    }
12218
12219    #[test]
12220    fn validate_rejects_path_fonte_with_caminho_carrying_url_fragment_anchor() {
12221        // The URL-fragment-identifier paste shape
12222        // (`"../caixa-teia#readme"` — the canonical
12223        // paste-from-browser-address-bar permalink shape where the
12224        // browser preserved the `#anchor` tail on the copy). Pinned
12225        // separately from the whitespace-separated shell / YAML
12226        // comment shapes so the gate covers the unpadded RFC 3986
12227        // §3.5 fragment-delimiter position too, not only positions
12228        // preceded by unquoted whitespace. Peer with the immediate-
12229        // sibling `is_git_repo_url` arm on the `:fonte :repo` axis
12230        // (a68f818) which closes the same byte under the same URL-
12231        // fragment-identifier banner.
12232        let d = dep_with_fonte(DepSource::Path {
12233            caminho: "../caixa-teia#readme".into(),
12234        });
12235        let err = d.validate().unwrap_err();
12236        assert!(
12237            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12238            "got {err:?}",
12239        );
12240    }
12241
12242    #[test]
12243    fn validate_rejects_path_fonte_with_caminho_carrying_leading_shell_comment() {
12244        // Leading-position `#` shape (`"#../caixa-teia"` — the
12245        // "I copied a shell-comment-out entry from a commented-out
12246        // dep row" footgun). Pinned separately from the embedded
12247        // shapes so the gate covers every position, not only
12248        // whitespace-preceded / mid-value.
12249        let d = dep_with_fonte(DepSource::Path {
12250            caminho: "#../caixa-teia".into(),
12251        });
12252        let err = d.validate().unwrap_err();
12253        assert!(
12254            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12255            "got {err:?}",
12256        );
12257    }
12258
12259    #[test]
12260    fn validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment() {
12261        // The positive-control pin: the gate targets only `#`,
12262        // never adjacent printable ASCII or POSIX-valid bytes. The
12263        // canonical relative POSIX path (`"../caixa-teia"`) and a
12264        // nested deeply-pathed variant with adjacent printable
12265        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12266        // to validate cleanly so the gate doesn't widen to a "no
12267        // printable punctuation anywhere" sweep that would defeat
12268        // the entire path-fonte author surface. Peer with
12269        // `validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping`
12270        // on the immediate-predecessor arm.
12271        let d = dep_with_fonte(DepSource::Path {
12272            caminho: "../caixa-teia/sub-dir.v2".into(),
12273        });
12274        d.validate().unwrap();
12275    }
12276
12277    #[test]
12278    fn fonte_caminho_shell_quote_grouping_fires_before_shell_comment() {
12279        // Cascade pin on the immediate-predecessor arm: a value
12280        // carrying both `'` and `#` (`"../'x'#pin"` — the canonical
12281        // "I pasted a strong-quoted literal followed by a URL-
12282        // fragment permalink tail" footgun) routes through
12283        // `FonteCaminhoShellQuoteGrouping` not
12284        // `FonteCaminhoShellComment`. The shell-string-literal-
12285        // delimiter is the load-bearing root-cause edit on every
12286        // probe-as-both value; same cascade discipline every prior
12287        // `:caminho` arm establishes.
12288        let d = dep_with_fonte(DepSource::Path {
12289            caminho: "../'x'#pin".into(),
12290        });
12291        let err = d.validate().unwrap_err();
12292        assert!(
12293            matches!(
12294                err,
12295                DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12296            ),
12297            "got {err:?}",
12298        );
12299    }
12300
12301    #[test]
12302    fn fonte_caminho_shell_bracket_expansion_fires_before_shell_comment() {
12303        // Cascade pin on the upstream shell-bracket-expansion arm:
12304        // a value carrying both `[` and `#` (`"../[a-z]#pin"` — the
12305        // canonical "I pasted a glob-character-class followed by a
12306        // URL-fragment tail" footgun) routes through
12307        // `FonteCaminhoShellBracketExpansion` not
12308        // `FonteCaminhoShellComment`. The glob-character-class
12309        // expansion is the load-bearing root-cause edit on every
12310        // probe-as-both value.
12311        let d = dep_with_fonte(DepSource::Path {
12312            caminho: "../[a-z]#pin".into(),
12313        });
12314        let err = d.validate().unwrap_err();
12315        assert!(
12316            matches!(
12317                err,
12318                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12319            ),
12320            "got {err:?}",
12321        );
12322    }
12323
12324    #[test]
12325    fn fonte_caminho_shell_brace_expansion_fires_before_shell_comment() {
12326        // Cascade pin on the upstream shell-brace-expansion arm: a
12327        // value carrying both `{` and `#` (`"../{a,b}#pin"` — the
12328        // canonical "I pasted a brace-expansion fan followed by a
12329        // URL-fragment tail" footgun) routes through
12330        // `FonteCaminhoShellBraceExpansion` not
12331        // `FonteCaminhoShellComment`. The brace-expansion fan is the
12332        // load-bearing root-cause edit on every probe-as-both value.
12333        let d = dep_with_fonte(DepSource::Path {
12334            caminho: "../{a,b}#pin".into(),
12335        });
12336        let err = d.validate().unwrap_err();
12337        assert!(
12338            matches!(
12339                err,
12340                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12341            ),
12342            "got {err:?}",
12343        );
12344    }
12345
12346    #[test]
12347    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_comment() {
12348        // Cascade pin on the upstream shell-subshell-grouping arm:
12349        // a value carrying both `(` and `#` (`"../(cd foo)#pin"` —
12350        // the canonical "I pasted a subshell-grouping followed by a
12351        // URL-fragment tail" footgun) routes through
12352        // `FonteCaminhoShellSubshellGrouping` not
12353        // `FonteCaminhoShellComment`. The modern Bourne `$(<cmd>)`
12354        // command-substitution boundary is the load-bearing axis on
12355        // every probe-as-both value.
12356        let d = dep_with_fonte(DepSource::Path {
12357            caminho: "../(cd foo)#pin".into(),
12358        });
12359        let err = d.validate().unwrap_err();
12360        assert!(
12361            matches!(
12362                err,
12363                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12364            ),
12365            "got {err:?}",
12366        );
12367    }
12368
12369    #[test]
12370    fn fonte_caminho_shell_glob_fires_before_shell_comment() {
12371        // Cascade pin on the upstream shell-glob arm: a value
12372        // carrying both `*` and `#` (`"../caixa-teia/*#pin"` — the
12373        // canonical "I pasted a `*` unbounded pathname-expansion
12374        // followed by a URL-fragment tail" footgun) routes through
12375        // `FonteCaminhoShellGlob` not `FonteCaminhoShellComment`.
12376        // The unbounded pathname-expansion sentinel is the load-
12377        // bearing root-cause edit on every probe-as-both value.
12378        let d = dep_with_fonte(DepSource::Path {
12379            caminho: "../caixa-teia/*#pin".into(),
12380        });
12381        let err = d.validate().unwrap_err();
12382        assert!(
12383            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12384            "got {err:?}",
12385        );
12386    }
12387
12388    #[test]
12389    fn fonte_caminho_shell_command_substitution_fires_before_shell_comment() {
12390        // Cascade pin on the upstream shell-command-substitution
12391        // arm: a value carrying both a backtick and `#`
12392        // (``"../`whoami`#pin"`` — the canonical "I pasted a
12393        // legacy-backtick command-substitution followed by a URL-
12394        // fragment tail" footgun) routes through
12395        // `FonteCaminhoShellCommandSubstitution` not
12396        // `FonteCaminhoShellComment`. The CWE-78 shell-command-
12397        // injection vector is the load-bearing root-cause edit on
12398        // every probe-as-both value.
12399        let d = dep_with_fonte(DepSource::Path {
12400            caminho: "../`whoami`#pin".into(),
12401        });
12402        let err = d.validate().unwrap_err();
12403        assert!(
12404            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12405            "got {err:?}",
12406        );
12407    }
12408
12409    #[test]
12410    fn fonte_caminho_shell_background_fires_before_shell_comment() {
12411        // Cascade pin on the upstream shell-background arm: a value
12412        // carrying both `&` and `#` (`"../caixa-teia&pin#tail"` —
12413        // the canonical "I pasted a `cmd &` background-launch
12414        // followed by a URL-fragment tail" footgun) routes through
12415        // `FonteCaminhoShellBackground` not
12416        // `FonteCaminhoShellComment`. The background-launch tail is
12417        // the load-bearing root-cause edit on every probe-as-both
12418        // value.
12419        let d = dep_with_fonte(DepSource::Path {
12420            caminho: "../caixa-teia&pin#tail".into(),
12421        });
12422        let err = d.validate().unwrap_err();
12423        assert!(
12424            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12425            "got {err:?}",
12426        );
12427    }
12428
12429    #[test]
12430    fn fonte_caminho_shell_semicolon_fires_before_shell_comment() {
12431        // Cascade pin on the upstream shell-semicolon arm: a value
12432        // carrying both `;` and `#` (`"../caixa-teia;pin#tail"` —
12433        // the canonical sequential-cleanup + URL-fragment paste
12434        // idiom) routes through `FonteCaminhoShellSemicolon` not
12435        // `FonteCaminhoShellComment`. The sequential-command-
12436        // separator paste is the load-bearing root-cause edit on
12437        // every probe-as-both value.
12438        let d = dep_with_fonte(DepSource::Path {
12439            caminho: "../caixa-teia;pin#tail".into(),
12440        });
12441        let err = d.validate().unwrap_err();
12442        assert!(
12443            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12444            "got {err:?}",
12445        );
12446    }
12447
12448    #[test]
12449    fn fonte_caminho_shell_pipe_fires_before_shell_comment() {
12450        // Cascade pin on the upstream shell-pipe arm: a value
12451        // carrying both `|` and `#` (`"../caixa-teia|pin#tail"` —
12452        // the canonical pipeline-to-URL-fragment paste idiom) routes
12453        // through `FonteCaminhoShellPipe` not
12454        // `FonteCaminhoShellComment`. The pipeline-tail paste is
12455        // the load-bearing root-cause edit on every probe-as-both
12456        // value.
12457        let d = dep_with_fonte(DepSource::Path {
12458            caminho: "../caixa-teia|pin#tail".into(),
12459        });
12460        let err = d.validate().unwrap_err();
12461        assert!(
12462            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12463            "got {err:?}",
12464        );
12465    }
12466
12467    #[test]
12468    fn fonte_caminho_shell_redirection_fires_before_shell_comment() {
12469        // Cascade pin on the upstream shell-redirection arm: a
12470        // value carrying both `>` and `#` (`"../caixa-teia>log#pin"`
12471        // — the canonical "I pasted a `cmd > log` redirect followed
12472        // by a URL-fragment tail" footgun) routes through
12473        // `FonteCaminhoShellRedirection` not
12474        // `FonteCaminhoShellComment`. The input/output redirection
12475        // metachar carries the more self-locating `byte` payload,
12476        // so the prior arm wins on every probe-as-both value.
12477        let d = dep_with_fonte(DepSource::Path {
12478            caminho: "../caixa-teia>log#pin".into(),
12479        });
12480        let err = d.validate().unwrap_err();
12481        assert!(
12482            matches!(
12483                err,
12484                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12485            ),
12486            "got {err:?}",
12487        );
12488    }
12489
12490    #[test]
12491    fn fonte_caminho_backslash_fires_before_shell_comment() {
12492        // Cascade pin on the upstream backslash arm: a value
12493        // carrying both `\` and `#` (`"..\caixa-teia#pin"` — the
12494        // canonical "I pasted a Windows-shell path followed by a
12495        // URL-fragment tail" footgun) routes through
12496        // `FonteCaminhoBackslash` not `FonteCaminhoShellComment`.
12497        // The cross-host-OS-separator divergence is the load-
12498        // bearing axis on every probe-as-both value.
12499        let d = dep_with_fonte(DepSource::Path {
12500            caminho: "..\\caixa-teia#pin".into(),
12501        });
12502        let err = d.validate().unwrap_err();
12503        assert!(
12504            matches!(err, DepError::FonteCaminhoBackslash { .. }),
12505            "got {err:?}",
12506        );
12507    }
12508
12509    #[test]
12510    fn fonte_caminho_control_char_fires_before_shell_comment() {
12511        // Cascade pin on the embedded-control-byte arm: a value
12512        // carrying both a control byte and `#` (`"../foo\n#pin"` —
12513        // the canonical paste-from-multiline-doc footgun where a
12514        // newline landed mid-caminho between the path and an
12515        // annotation) routes through `FonteCaminhoControlChar` not
12516        // `FonteCaminhoShellComment`. The POSIX-syscall-rejected-
12517        // byte diagnostic is the load-bearing axis on every value
12518        // that probes positive for both — mirrors the cascade
12519        // discipline on every prior arm.
12520        let d = dep_with_fonte(DepSource::Path {
12521            caminho: "../foo\n#pin".into(),
12522        });
12523        let err = d.validate().unwrap_err();
12524        assert!(
12525            matches!(err, DepError::FonteCaminhoControlChar { .. }),
12526            "got {err:?}",
12527        );
12528    }
12529
12530    #[test]
12531    fn fonte_caminho_absolute_fires_before_shell_comment() {
12532        // Cascade pin on the load-bearing leading-byte arm: a
12533        // leading `/` value with embedded `#` (`"/etc/foo#pin"`)
12534        // routes through `FonteCaminhoAbsolute` not
12535        // `FonteCaminhoShellComment` — the host-layout-leak
12536        // diagnostic is the load-bearing axis, the fragment byte is
12537        // the secondary observation. Same precedence logic as every
12538        // prior leading-byte arm.
12539        let d = dep_with_fonte(DepSource::Path {
12540            caminho: "/etc/foo#pin".into(),
12541        });
12542        let err = d.validate().unwrap_err();
12543        assert!(
12544            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12545            "got {err:?}",
12546        );
12547    }
12548
12549    #[test]
12550    fn fonte_caminho_var_expansion_fires_before_shell_comment() {
12551        // Cascade pin on the upstream leading-`$` var-expansion
12552        // arm: a value carrying both a leading `$` and a `#`
12553        // (`"$DIR/foo#pin"` — the canonical "I pasted a `$DIR`
12554        // shell-variable at the head of a sibling-workspace path
12555        // followed by a URL-fragment tail" footgun) routes through
12556        // `FonteCaminhoVarExpansion` not `FonteCaminhoShellComment`.
12557        // The leading-byte shell-variable-expansion is the more
12558        // self-locating diagnostic on values that probe as both.
12559        let d = dep_with_fonte(DepSource::Path {
12560            caminho: "$DIR/foo#pin".into(),
12561        });
12562        let err = d.validate().unwrap_err();
12563        assert!(
12564            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12565            "got {err:?}",
12566        );
12567    }
12568
12569    #[test]
12570    fn fonte_caminho_shell_comment_fires_before_trailing_slash() {
12571        // Cascade pin on the immediate-successor arm: a value
12572        // carrying both `#` and a trailing `/`
12573        // (`"../caixa-teia#pin/"` — the canonical "I tab-completed
12574        // a URL-fragment-carrying path" footgun) routes through
12575        // `FonteCaminhoShellComment` not
12576        // `FonteCaminhoTrailingSlash`. The embedded fragment /
12577        // comment-lead byte is the more semantic-locating axis (an
12578        // author who removes the `#pin` fragment typically also
12579        // drops the trailing separator since both are paste-from-
12580        // URL / paste-from-shell-tab-completion artifacts).
12581        let d = dep_with_fonte(DepSource::Path {
12582            caminho: "../caixa-teia#pin/".into(),
12583        });
12584        let err = d.validate().unwrap_err();
12585        assert!(
12586            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. },),
12587            "got {err:?}",
12588        );
12589    }
12590
12591    #[test]
12592    fn fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte() {
12593        // Diagnostic-shape pin (peer with
12594        // `fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
12595        // on the immediate-predecessor arm): the error's Display
12596        // surfaces the offending `:nome`, the offending `:caminho`
12597        // verbatim, the offending byte's hex / character form, and
12598        // names the shell-comment / URL-fragment-identifier /
12599        // YAML-comment cross-config-DSL footgun explicitly so a
12600        // `feira lint` run can render the diagnostic without
12601        // re-parsing.
12602        let d = dep_with_fonte(DepSource::Path {
12603            caminho: "../caixa-teia#readme".into(),
12604        });
12605        let rendered = d.validate().unwrap_err().to_string();
12606        assert!(
12607            rendered.contains("caixa-teia"),
12608            "diagnostic must name the offending dep: {rendered}",
12609        );
12610        assert!(
12611            rendered.contains("../caixa-teia#readme"),
12612            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12613        );
12614        assert!(
12615            rendered.contains("0x23"),
12616            "diagnostic must surface the offending byte hex: {rendered:?}",
12617        );
12618        assert!(
12619            rendered.contains("shell-comment") || rendered.contains("comment-lead"),
12620            "diagnostic must name the shell-comment footgun: {rendered:?}",
12621        );
12622        assert!(
12623            rendered.contains("fragment") || rendered.contains("URL-fragment"),
12624            "diagnostic must reference the URL-fragment-identifier vocabulary: \
12625             {rendered:?}",
12626        );
12627    }
12628
12629    #[test]
12630    fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_space() {
12631        // The canonical paste-from-browser-address-bar percent-
12632        // encoded-space footgun: an author copies `../caixa%20teia`
12633        // out of a URL-encoded README hyperlink / browser address
12634        // bar / percent-encoded permalink expecting `%20` to decode
12635        // to a literal space at the filesystem layer. POSIX
12636        // `std::path::Path` treats `%` as a literal path-component
12637        // byte, so `Path::join` looks for a literal
12638        // `./../caixa%20teia` subdirectory. `Path::is_absolute`
12639        // returns false on `..`, `%` is neither a leading-byte
12640        // sentinel nor a control byte nor `\` nor `<` / `>` nor
12641        // `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` /
12642        // `)` nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`,
12643        // and the value's last byte isn't `/` — so the value
12644        // silently passed every prior arm. The new arm moves the
12645        // rejection to validate time and names the offending dep +
12646        // caminho + byte verbatim.
12647        let d = dep_with_fonte(DepSource::Path {
12648            caminho: "../caixa%20teia".into(),
12649        });
12650        let err = d.validate().unwrap_err();
12651        let DepError::FonteCaminhoUrlPercentEncoding {
12652            nome,
12653            caminho,
12654            byte,
12655        } = err
12656        else {
12657            panic!("expected FonteCaminhoUrlPercentEncoding, got {err:?}");
12658        };
12659        assert_eq!(nome, "caixa-teia");
12660        assert_eq!(caminho, "../caixa%20teia");
12661        assert_eq!(byte, b'%');
12662    }
12663
12664    #[test]
12665    fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_slash() {
12666        // The over-encoded path-separator shape (`"../caixa%2Fteia"`
12667        // intending the `%2F` as the URL encoding of `/`) locks a
12668        // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
12669        // the byte-identical `path:../caixa/teia` form. Pinned
12670        // separately from the space-encoded shape so the gate's
12671        // coverage extends past the single canonical `%20` example
12672        // to any two-hex-digit percent-encoded sequence.
12673        let d = dep_with_fonte(DepSource::Path {
12674            caminho: "../caixa%2Fteia".into(),
12675        });
12676        let err = d.validate().unwrap_err();
12677        assert!(
12678            matches!(
12679                err,
12680                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12681            ),
12682            "got {err:?}",
12683        );
12684    }
12685
12686    #[test]
12687    fn validate_rejects_path_fonte_with_caminho_carrying_lone_percent() {
12688        // The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
12689        // where `%` isn't followed by two hex digits) — every
12690        // WHATWG-conformant URL parser rejects the value at parse
12691        // time per RFC 3986 §2.1, but the byte would silently ride
12692        // into the lacre before the resolver subprocess crosses the
12693        // URL-parser boundary. Pinned separately from the well-
12694        // formed `%HH` shapes so the gate covers every percent-
12695        // occurrence, not only strictly-conformant escapes.
12696        let d = dep_with_fonte(DepSource::Path {
12697            caminho: "../caixa-teia%foo".into(),
12698        });
12699        let err = d.validate().unwrap_err();
12700        assert!(
12701            matches!(
12702                err,
12703                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12704            ),
12705            "got {err:?}",
12706        );
12707    }
12708
12709    #[test]
12710    fn validate_rejects_path_fonte_with_caminho_carrying_leading_yaml_directive() {
12711        // The YAML-directive-lead paste shape (`"%YAML/../caixa-teia"`
12712        // — the canonical paste-from-top-of-doc YAML directive
12713        // block cross-idiom leak per YAML 1.2 §6.8.1). Pinned
12714        // separately from embedded shapes so the gate covers the
12715        // leading-position `%` too, not only mid-value occurrences.
12716        let d = dep_with_fonte(DepSource::Path {
12717            caminho: "%YAML/../caixa-teia".into(),
12718        });
12719        let err = d.validate().unwrap_err();
12720        assert!(
12721            matches!(
12722                err,
12723                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12724            ),
12725            "got {err:?}",
12726        );
12727    }
12728
12729    #[test]
12730    fn validate_rejects_path_fonte_with_caminho_carrying_printf_format_specifier() {
12731        // The printf-format-specifier paste shape
12732        // (`"../caixa-%s-teia"` — the canonical paste-from-shell-
12733        // diagnostic-one-liner `printf "path=%s\n" ...` idiom, CWE-
12734        // 134 format-string-injection vector). Pinned separately
12735        // from the URL-encoding shapes so the gate's rationale
12736        // extends past the RFC 3986 axis to the C / POSIX printf
12737        // format-directive-lead axis.
12738        let d = dep_with_fonte(DepSource::Path {
12739            caminho: "../caixa-%s-teia".into(),
12740        });
12741        let err = d.validate().unwrap_err();
12742        assert!(
12743            matches!(
12744                err,
12745                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12746            ),
12747            "got {err:?}",
12748        );
12749    }
12750
12751    #[test]
12752    fn validate_accepts_path_fonte_with_caminho_carrying_no_percent() {
12753        // The positive-control pin: the gate targets only `%`,
12754        // never adjacent printable ASCII or POSIX-valid bytes. The
12755        // canonical relative POSIX path (`"../caixa-teia"`) and a
12756        // nested deeply-pathed variant with adjacent printable
12757        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12758        // to validate cleanly so the gate doesn't widen to a "no
12759        // printable punctuation anywhere" sweep that would defeat
12760        // the entire path-fonte author surface. Peer with
12761        // `validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment`
12762        // on the immediate-predecessor arm.
12763        let d = dep_with_fonte(DepSource::Path {
12764            caminho: "../caixa-teia/sub-dir.v2".into(),
12765        });
12766        d.validate().unwrap();
12767    }
12768
12769    #[test]
12770    fn fonte_caminho_shell_comment_fires_before_url_percent_encoding() {
12771        // Cascade pin on the immediate-predecessor arm: a value
12772        // carrying both `#` and `%` (`"../caixa-teia#pin%20"` — the
12773        // canonical "I pasted a URL-fragment permalink followed by a
12774        // percent-encoded space tail" footgun) routes through
12775        // `FonteCaminhoShellComment` not
12776        // `FonteCaminhoUrlPercentEncoding`. The URL-fragment-
12777        // identifier is the load-bearing downstream-truncation edit
12778        // on every probe-as-both value; same cascade discipline
12779        // every prior `:caminho` arm establishes.
12780        let d = dep_with_fonte(DepSource::Path {
12781            caminho: "../caixa-teia#pin%20".into(),
12782        });
12783        let err = d.validate().unwrap_err();
12784        assert!(
12785            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12786            "got {err:?}",
12787        );
12788    }
12789
12790    #[test]
12791    fn fonte_caminho_shell_quote_grouping_fires_before_url_percent_encoding() {
12792        // Cascade pin on the upstream shell-quote-grouping arm: a
12793        // value carrying both `'` and `%` (`"../'x'%20teia"` — the
12794        // canonical "I pasted a strong-quoted literal followed by
12795        // a percent-encoded space" footgun) routes through
12796        // `FonteCaminhoShellQuoteGrouping` not
12797        // `FonteCaminhoUrlPercentEncoding`. The shell-string-
12798        // literal-delimiter is the load-bearing root-cause edit on
12799        // every probe-as-both value.
12800        let d = dep_with_fonte(DepSource::Path {
12801            caminho: "../'x'%20teia".into(),
12802        });
12803        let err = d.validate().unwrap_err();
12804        assert!(
12805            matches!(
12806                err,
12807                DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12808            ),
12809            "got {err:?}",
12810        );
12811    }
12812
12813    #[test]
12814    fn fonte_caminho_backslash_fires_before_url_percent_encoding() {
12815        // Cascade pin on the upstream backslash arm: a value
12816        // carrying both `\` and `%` (`"..\\caixa%20teia"` — the
12817        // canonical "I pasted a Windows-shell path followed by a
12818        // percent-encoded space" footgun) routes through
12819        // `FonteCaminhoBackslash` not
12820        // `FonteCaminhoUrlPercentEncoding`. The cross-host-OS-
12821        // separator divergence is the load-bearing root-cause edit
12822        // on every probe-as-both value.
12823        let d = dep_with_fonte(DepSource::Path {
12824            caminho: "..\\caixa%20teia".into(),
12825        });
12826        let err = d.validate().unwrap_err();
12827        assert!(
12828            matches!(err, DepError::FonteCaminhoBackslash { .. }),
12829            "got {err:?}",
12830        );
12831    }
12832
12833    #[test]
12834    fn fonte_caminho_control_char_fires_before_url_percent_encoding() {
12835        // Cascade pin on the upstream control-char arm: a value
12836        // carrying both a NUL byte and `%` (`"../caixa\0%20teia"` —
12837        // the canonical "I pasted a paste-from-binary-blob path
12838        // followed by a percent-encoded space" footgun) routes
12839        // through `FonteCaminhoControlChar` not
12840        // `FonteCaminhoUrlPercentEncoding`. The POSIX-syscall-
12841        // rejected byte is the load-bearing root-cause edit on
12842        // every probe-as-both value.
12843        let d = dep_with_fonte(DepSource::Path {
12844            caminho: "../caixa\0%20teia".into(),
12845        });
12846        let err = d.validate().unwrap_err();
12847        assert!(
12848            matches!(err, DepError::FonteCaminhoControlChar { byte: 0x00, .. },),
12849            "got {err:?}",
12850        );
12851    }
12852
12853    #[test]
12854    fn fonte_caminho_absolute_fires_before_url_percent_encoding() {
12855        // Cascade pin on the upstream absolute-path arm: a value
12856        // that's both absolute and carries `%` (`"/etc/passwd%20"`
12857        // — the canonical "I pasted an absolute path with a
12858        // percent-encoded space tail" footgun) routes through
12859        // `FonteCaminhoAbsolute` not
12860        // `FonteCaminhoUrlPercentEncoding`. The host-layout-leak is
12861        // the load-bearing root-cause edit on every probe-as-both
12862        // value.
12863        let d = dep_with_fonte(DepSource::Path {
12864            caminho: "/etc/passwd%20".into(),
12865        });
12866        let err = d.validate().unwrap_err();
12867        assert!(
12868            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12869            "got {err:?}",
12870        );
12871    }
12872
12873    #[test]
12874    fn fonte_caminho_var_expansion_fires_before_url_percent_encoding() {
12875        // Cascade pin on the upstream var-expansion arm: a value
12876        // starting with `$` and carrying `%` (`"$HOME/caixa%20teia"`
12877        // — the canonical "I pasted a `$HOME`-rooted path with a
12878        // percent-encoded space" footgun) routes through
12879        // `FonteCaminhoVarExpansion` not
12880        // `FonteCaminhoUrlPercentEncoding`. The shell-variable-
12881        // expansion is the load-bearing root-cause edit on every
12882        // probe-as-both value.
12883        let d = dep_with_fonte(DepSource::Path {
12884            caminho: "$HOME/caixa%20teia".into(),
12885        });
12886        let err = d.validate().unwrap_err();
12887        assert!(
12888            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12889            "got {err:?}",
12890        );
12891    }
12892
12893    #[test]
12894    fn fonte_caminho_url_percent_encoding_fires_before_trailing_slash() {
12895        // Cascade pin on the immediate-successor arm: a value
12896        // carrying both `%` and a trailing `/`
12897        // (`"../caixa%20teia/"` — the canonical "I tab-completed a
12898        // percent-encoded-space-carrying path" footgun) routes
12899        // through `FonteCaminhoUrlPercentEncoding` not
12900        // `FonteCaminhoTrailingSlash`. The embedded percent-
12901        // encoding-escape byte is the more semantic-locating axis
12902        // (an author who decodes the `%20` to a literal space is
12903        // likely to also tab-strip the trailing separator since
12904        // both are paste-from-URL / paste-from-shell-tab-completion
12905        // artifacts).
12906        let d = dep_with_fonte(DepSource::Path {
12907            caminho: "../caixa%20teia/".into(),
12908        });
12909        let err = d.validate().unwrap_err();
12910        assert!(
12911            matches!(
12912                err,
12913                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12914            ),
12915            "got {err:?}",
12916        );
12917    }
12918
12919    #[test]
12920    fn fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte() {
12921        // Diagnostic-shape pin (peer with
12922        // `fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte`
12923        // on the immediate-predecessor arm): the error's Display
12924        // surfaces the offending `:nome`, the offending `:caminho`
12925        // verbatim, the offending byte's hex / character form, and
12926        // names the URL-percent-encoding-escape / printf-format-
12927        // specifier footgun explicitly so a `feira lint` run can
12928        // render the diagnostic without re-parsing.
12929        let d = dep_with_fonte(DepSource::Path {
12930            caminho: "../caixa%20teia".into(),
12931        });
12932        let rendered = d.validate().unwrap_err().to_string();
12933        assert!(
12934            rendered.contains("caixa-teia"),
12935            "diagnostic must name the offending dep: {rendered}",
12936        );
12937        assert!(
12938            rendered.contains("../caixa%20teia"),
12939            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12940        );
12941        assert!(
12942            rendered.contains("0x25"),
12943            "diagnostic must surface the offending byte hex: {rendered:?}",
12944        );
12945        assert!(
12946            rendered.contains("percent-encoding") || rendered.contains("percent-encoded"),
12947            "diagnostic must name the URL-percent-encoding-escape footgun: {rendered:?}",
12948        );
12949        assert!(
12950            rendered.contains("printf") || rendered.contains("format-specifier"),
12951            "diagnostic must reference the printf-format-specifier vocabulary: \
12952             {rendered:?}",
12953        );
12954    }
12955
12956    #[test]
12957    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_var_expansion() {
12958        // The canonical embedded-`$` shell-variable-expansion paste
12959        // shape (`"../foo$HOME/bar"` — an author copies a partially-
12960        // substituted shell one-liner where the leading segment is a
12961        // literal `../foo` while the mid segment carries the un-
12962        // substituted `$HOME` template). The leading-`$` position is
12963        // already gated by the f4efe9c leading-byte arm which routes
12964        // through `FonteCaminhoVarExpansion`; this arm closes the
12965        // last positional gap on `$` — every position on the axis is
12966        // structurally rejected.
12967        let d = dep_with_fonte(DepSource::Path {
12968            caminho: "../foo$HOME/bar".into(),
12969        });
12970        let err = d.validate().unwrap_err();
12971        let DepError::FonteCaminhoShellVariableExpansion {
12972            nome,
12973            caminho,
12974            byte,
12975        } = err
12976        else {
12977            panic!("expected FonteCaminhoShellVariableExpansion, got {err:?}");
12978        };
12979        assert_eq!(nome, "caixa-teia");
12980        assert_eq!(caminho, "../foo$HOME/bar");
12981        assert_eq!(byte, b'$');
12982    }
12983
12984    #[test]
12985    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_braced_var_expansion() {
12986        // The symmetric braced-CI-manifest paste shape
12987        // (`"../foo${WORKSPACE}/bar"` — the canonical paste-from-
12988        // GitHub-Actions-workflow / paste-from-`.gitlab-ci.yml`
12989        // footgun). Pinned separately from the bare-`$VAR` shape so
12990        // the gate covers both POSIX shell §2.6 Parameter Expansion
12991        // syntactic forms, not only the unbraced variant. The
12992        // embedded `{` byte in `${...}` is also caught by the 598b770
12993        // shell-brace-expansion arm but that arm fires earlier in
12994        // the cascade — the `$` arm's coverage extends to `${...}`
12995        // structurally, so the diagnostic asserted here is the
12996        // brace-expansion one (which is a valid outcome; the point
12997        // of the pin is that the value never survives validation).
12998        let d = dep_with_fonte(DepSource::Path {
12999            caminho: "../foo${WORKSPACE}/bar".into(),
13000        });
13001        let err = d.validate().unwrap_err();
13002        assert!(
13003            matches!(
13004                err,
13005                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. }
13006                    | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13007            ),
13008            "got {err:?}",
13009        );
13010    }
13011
13012    #[test]
13013    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_command_substitution() {
13014        // The paste-from-shell-prompt command-substitution idiom
13015        // (`"../foo$(whoami)/bar"`). Pinned separately from the bare-
13016        // `$VAR` shape so the gate's rationale extends to POSIX shell
13017        // §2.6.3 Command Substitution (the modern `$(<cmd>)` form; the
13018        // legacy `` `<cmd>` `` form is already closed by the c370458
13019        // backtick arm). The embedded `(` byte in `$(...)` is also
13020        // caught structurally by the 0633c91 shell-subshell-grouping
13021        // arm which fires earlier in the cascade — the diagnostic
13022        // asserted here is either outcome, since both structurally
13023        // reject the value; the point of the pin is that the value
13024        // never survives validation.
13025        let d = dep_with_fonte(DepSource::Path {
13026            caminho: "../foo$(whoami)/bar".into(),
13027        });
13028        let err = d.validate().unwrap_err();
13029        assert!(
13030            matches!(
13031                err,
13032                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. }
13033                    | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13034            ),
13035            "got {err:?}",
13036        );
13037    }
13038
13039    #[test]
13040    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_positional_parameter() {
13041        // The paste-from-`Makefile` / paste-from-SQL-migration bare-
13042        // `$1` positional-parameter shape (`"../foo$1/bar"` — a Make
13043        // automatic-variable `$1` or a PostgreSQL bind-parameter `$1`
13044        // idiom copied into a caminho template). None of the prior
13045        // shell-metachar arms cover this shape (`1` is a bare digit;
13046        // no `(` / `{` / letter follows the `$`), so the arm is the
13047        // sole gate on the shape.
13048        let d = dep_with_fonte(DepSource::Path {
13049            caminho: "../foo$1/bar".into(),
13050        });
13051        let err = d.validate().unwrap_err();
13052        assert!(
13053            matches!(
13054                err,
13055                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13056            ),
13057            "got {err:?}",
13058        );
13059    }
13060
13061    #[test]
13062    fn validate_accepts_path_fonte_with_caminho_carrying_no_dollar() {
13063        // The positive-control pin (peer with
13064        // `validate_accepts_path_fonte_with_caminho_carrying_no_percent`
13065        // on the immediate-predecessor arm): the gate targets only
13066        // `$`, never adjacent printable ASCII or POSIX-valid bytes.
13067        // A relative POSIX path carrying dashes / dots / slashes /
13068        // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13069        // validate cleanly so the gate doesn't widen to a "no
13070        // printable punctuation anywhere" sweep that would defeat
13071        // the entire path-fonte author surface.
13072        let d = dep_with_fonte(DepSource::Path {
13073            caminho: "../caixa-teia/sub-dir.v2".into(),
13074        });
13075        d.validate().unwrap();
13076    }
13077
13078    #[test]
13079    fn fonte_caminho_var_expansion_fires_before_shell_variable_expansion() {
13080        // Cascade pin on the leading-`$` sibling arm at line 540: a
13081        // value starting with `$` and carrying an embedded `$` too
13082        // (`"$HOME/foo$WORKSPACE/bar"` — the canonical "I pasted a
13083        // fully-templated CI path with two un-substituted variables")
13084        // routes through `FonteCaminhoVarExpansion` not
13085        // `FonteCaminhoShellVariableExpansion`. The leading-byte
13086        // host-layout-leak is the load-bearing self-locating axis
13087        // (the leading position dominates the semantic-locating
13088        // rationale on every probe-as-both value); the embedded
13089        // arm's positional-agnostic sweep catches only values whose
13090        // leading byte doesn't route through the earlier leading-
13091        // byte arms.
13092        let d = dep_with_fonte(DepSource::Path {
13093            caminho: "$HOME/foo$WORKSPACE/bar".into(),
13094        });
13095        let err = d.validate().unwrap_err();
13096        assert!(
13097            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
13098            "got {err:?}",
13099        );
13100    }
13101
13102    #[test]
13103    fn fonte_caminho_url_percent_encoding_fires_before_shell_variable_expansion() {
13104        // Cascade pin on the immediate-predecessor arm: a value
13105        // carrying both `%` and embedded `$` (`"../foo%20$HOME/bar"`
13106        // — the canonical "I pasted a percent-encoded space adjacent
13107        // to a `$HOME` template") routes through
13108        // `FonteCaminhoUrlPercentEncoding` not
13109        // `FonteCaminhoShellVariableExpansion`. The URL-percent-
13110        // encoding-escape byte is the more semantic-locating axis
13111        // (the paste-from-browser-address-bar shape is the load-
13112        // bearing self-locating edit); same cascade discipline every
13113        // prior `:caminho` arm establishes.
13114        let d = dep_with_fonte(DepSource::Path {
13115            caminho: "../foo%20$HOME/bar".into(),
13116        });
13117        let err = d.validate().unwrap_err();
13118        assert!(
13119            matches!(
13120                err,
13121                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13122            ),
13123            "got {err:?}",
13124        );
13125    }
13126
13127    #[test]
13128    fn fonte_caminho_shell_variable_expansion_fires_before_trailing_slash() {
13129        // Cascade pin on the immediate-successor arm: a value
13130        // carrying both embedded `$` and a trailing `/`
13131        // (`"../foo$HOME/bar/"` — the canonical "I tab-completed a
13132        // `$HOME`-template-carrying path") routes through
13133        // `FonteCaminhoShellVariableExpansion` not
13134        // `FonteCaminhoTrailingSlash`. The embedded shell-variable-
13135        // expansion byte is the more semantic-locating axis on
13136        // probe-as-both values (an author who substitutes the
13137        // `$HOME` template with a literal value is likely to also
13138        // tab-strip the trailing separator).
13139        let d = dep_with_fonte(DepSource::Path {
13140            caminho: "../foo$HOME/bar/".into(),
13141        });
13142        let err = d.validate().unwrap_err();
13143        assert!(
13144            matches!(
13145                err,
13146                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13147            ),
13148            "got {err:?}",
13149        );
13150    }
13151
13152    #[test]
13153    fn fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13154        // Diagnostic-shape pin (peer with
13155        // `fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte`
13156        // on the immediate-predecessor arm): the error's Display
13157        // surfaces the offending `:nome`, the offending `:caminho`
13158        // verbatim, the offending byte's hex / character form, and
13159        // names the shell-variable-expansion / command-substitution
13160        // footgun explicitly so a `feira lint` run can render the
13161        // diagnostic without re-parsing.
13162        let d = dep_with_fonte(DepSource::Path {
13163            caminho: "../foo$HOME/bar".into(),
13164        });
13165        let rendered = d.validate().unwrap_err().to_string();
13166        assert!(
13167            rendered.contains("caixa-teia"),
13168            "diagnostic must name the offending dep: {rendered}",
13169        );
13170        assert!(
13171            rendered.contains("../foo$HOME/bar"),
13172            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13173        );
13174        assert!(
13175            rendered.contains("0x24"),
13176            "diagnostic must surface the offending byte hex: {rendered:?}",
13177        );
13178        assert!(
13179            rendered.contains("variable-expansion") || rendered.contains("variable expansion"),
13180            "diagnostic must name the shell-variable-expansion footgun: {rendered:?}",
13181        );
13182        assert!(
13183            rendered.contains("command-substitution") || rendered.contains("command substitution"),
13184            "diagnostic must reference the command-substitution vocabulary: {rendered:?}",
13185        );
13186    }
13187
13188    #[test]
13189    fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_expansion() {
13190        // The fail-before-pass-after pin for the canonical paste-from-
13191        // shell-history footgun on `:caminho`. An author copies a `cd
13192        // ../caixa-teia && !sudo make install` one-liner from a quick-
13193        // start README, intending the trailing `!sudo` as a shell-
13194        // history-expansion reference but the typed slot is itself a
13195        // byte-level string parser, not a shell context, so the byte
13196        // rides into the value verbatim. Until this arm landed the `!`
13197        // byte silently passed every prior `:caminho` cascade arm
13198        // (`!` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick /
13199        // `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` /
13200        // `#` / `%` / `$`); bash with the default `histexpand` mode
13201        // rewrites `!command` to the most recent history entry
13202        // beginning with `command`, the canonical RCE-class injection
13203        // vector when the byte rides into a shell argument executed
13204        // under `bash -i` (the operator-notebook interactive shell).
13205        let d = dep_with_fonte(DepSource::Path {
13206            caminho: "../caixa-teia!sudo".into(),
13207        });
13208        let err = d.validate().unwrap_err();
13209        let DepError::FonteCaminhoShellHistoryExpansion {
13210            nome,
13211            caminho,
13212            byte,
13213        } = err
13214        else {
13215            panic!("expected FonteCaminhoShellHistoryExpansion, got {err:?}");
13216        };
13217        assert_eq!(nome, "caixa-teia");
13218        assert_eq!(caminho, "../caixa-teia!sudo");
13219        assert_eq!(byte, b'!');
13220    }
13221
13222    #[test]
13223    fn validate_rejects_path_fonte_with_caminho_carrying_double_bang_history_reference() {
13224        // The symmetric `!!` repeat-prior-command paste idiom (peer with
13225        // `validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference`
13226        // on `is_git_repo_url`). Pinned separately from the wrapped
13227        // `!command` shape so a future diagnostic-surface change that
13228        // only checked the leading or paired-bang position surfaces
13229        // here — the per-byte arm fires anywhere `!` appears in the
13230        // value, including at consecutive positions in the middle.
13231        let d = dep_with_fonte(DepSource::Path {
13232            caminho: "../foo!!/bar".into(),
13233        });
13234        let err = d.validate().unwrap_err();
13235        assert!(
13236            matches!(
13237                err,
13238                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13239            ),
13240            "got {err:?}",
13241        );
13242    }
13243
13244    #[test]
13245    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_enthusiasm_bang() {
13246        // The English-typography enthusiasm-form paste-from-prose
13247        // idiom: an author writes `:caminho "../caixa-teia!"`
13248        // expecting the substrate to coerce it to a kebab-case slug.
13249        // Pinned separately from the `!<word>` shell-history shape so
13250        // the gate's rationale extends to the paste-from-prose surface
13251        // (the same rationale the peer `is_git_repo_url` bang arm at
13252        // 7d53c68 covers). None of the prior shell-metachar arms cover
13253        // this shape (no `!<word>` reference and no `!!` repeat), so
13254        // the arm is the sole gate on the shape.
13255        let d = dep_with_fonte(DepSource::Path {
13256            caminho: "../caixa-teia!".into(),
13257        });
13258        let err = d.validate().unwrap_err();
13259        assert!(
13260            matches!(
13261                err,
13262                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13263            ),
13264            "got {err:?}",
13265        );
13266    }
13267
13268    #[test]
13269    fn validate_accepts_path_fonte_with_caminho_carrying_no_bang() {
13270        // The positive-control pin (peer with
13271        // `validate_accepts_path_fonte_with_caminho_carrying_no_dollar`
13272        // on the immediate-predecessor arm): the gate targets only
13273        // `!`, never adjacent printable ASCII or POSIX-valid bytes.
13274        // A relative POSIX path carrying dashes / dots / slashes /
13275        // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13276        // validate cleanly so the gate doesn't widen to a "no
13277        // printable punctuation anywhere" sweep that would defeat
13278        // the entire path-fonte author surface.
13279        let d = dep_with_fonte(DepSource::Path {
13280            caminho: "../caixa-teia/sub-dir.v2".into(),
13281        });
13282        d.validate().unwrap();
13283    }
13284
13285    #[test]
13286    fn fonte_caminho_shell_variable_expansion_fires_before_shell_history_expansion() {
13287        // Cascade pin on the immediate-predecessor arm: a value
13288        // carrying both embedded `$` and `!` (`"../foo$HOME/bar!sudo"`
13289        // — the canonical "I pasted a `$HOME`-templated path adjacent
13290        // to a trailing `!sudo` history-expansion") routes through
13291        // `FonteCaminhoShellVariableExpansion` not
13292        // `FonteCaminhoShellHistoryExpansion`. The shell-variable-
13293        // expansion byte is the more semantic-locating axis on
13294        // probe-as-both values (the paste-from-CI-manifest-with-`$VAR`-
13295        // template shape is the load-bearing self-locating edit);
13296        // same cascade discipline every prior `:caminho` arm
13297        // establishes.
13298        let d = dep_with_fonte(DepSource::Path {
13299            caminho: "../foo$HOME/bar!sudo".into(),
13300        });
13301        let err = d.validate().unwrap_err();
13302        assert!(
13303            matches!(
13304                err,
13305                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13306            ),
13307            "got {err:?}",
13308        );
13309    }
13310
13311    #[test]
13312    fn fonte_caminho_shell_history_expansion_fires_before_trailing_slash() {
13313        // Cascade pin on the immediate-successor arm: a value carrying
13314        // both embedded `!` and a trailing `/` (`"../caixa-teia!sudo/"`
13315        // — the canonical "I tab-completed a `!sudo`-carrying path")
13316        // routes through `FonteCaminhoShellHistoryExpansion` not
13317        // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13318        // expansion byte is the more semantic-locating axis on probe-
13319        // as-both values (an author who removes the `!sudo` history
13320        // reference is likely to also tab-strip the trailing separator).
13321        let d = dep_with_fonte(DepSource::Path {
13322            caminho: "../caixa-teia!sudo/".into(),
13323        });
13324        let err = d.validate().unwrap_err();
13325        assert!(
13326            matches!(
13327                err,
13328                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13329            ),
13330            "got {err:?}",
13331        );
13332    }
13333
13334    #[test]
13335    fn fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13336        // Diagnostic-shape pin (peer with
13337        // `fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13338        // on the immediate-predecessor arm): the error's Display
13339        // surfaces the offending `:nome`, the offending `:caminho`
13340        // verbatim, the offending byte's hex / character form, and
13341        // names the shell-history-expansion / bang-operator footgun
13342        // explicitly so a `feira lint` run can render the diagnostic
13343        // without re-parsing.
13344        let d = dep_with_fonte(DepSource::Path {
13345            caminho: "../caixa-teia!sudo".into(),
13346        });
13347        let rendered = d.validate().unwrap_err().to_string();
13348        assert!(
13349            rendered.contains("caixa-teia"),
13350            "diagnostic must name the offending dep: {rendered}",
13351        );
13352        assert!(
13353            rendered.contains("../caixa-teia!sudo"),
13354            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13355        );
13356        assert!(
13357            rendered.contains("0x21"),
13358            "diagnostic must surface the offending byte hex: {rendered:?}",
13359        );
13360        assert!(
13361            rendered.contains("history-expansion") || rendered.contains("history expansion"),
13362            "diagnostic must name the shell-history-expansion footgun: {rendered:?}",
13363        );
13364        assert!(
13365            rendered.contains("bang"),
13366            "diagnostic must reference the bang-operator vocabulary: {rendered:?}",
13367        );
13368    }
13369
13370    #[test]
13371    fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_substitution() {
13372        // The fail-before-pass-after pin for the canonical paste-from-
13373        // shell-history-quick-substitution footgun on `:caminho`. An
13374        // author copies a `git clone <bad-url>` line from their terminal,
13375        // corrects it via bash's `^bad^good` quick-substitution history
13376        // operator (bash reference §9.3, `set -o histexpand` mode's
13377        // default for interactive sessions), and pastes the trailing
13378        // `^bad^good` substitution fragment into a `:caminho` value
13379        // without trimming the leading `git clone` prefix — the byte
13380        // rides into the manifest verbatim. Until this arm landed the
13381        // `^` byte silently passed every prior `:caminho` cascade arm
13382        // (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick / `*`
13383        // / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` / `#` /
13384        // `%` / `$` / `!`); bash with the default `histexpand` mode
13385        // rewrites the prior command's `bad` string to `good` and re-
13386        // executes it, the paired-operator half of the `set -o
13387        // histexpand` feature the peer `!` arm already closes the prefix
13388        // half of. The peer `is_git_repo_url` axis rejects the byte at
13389        // 49e142f under the same shell-history-substitution / RFC-3986-
13390        // unwise banner.
13391        let d = dep_with_fonte(DepSource::Path {
13392            caminho: "../foo^bad^good".into(),
13393        });
13394        let err = d.validate().unwrap_err();
13395        let DepError::FonteCaminhoShellHistorySubstitution {
13396            nome,
13397            caminho,
13398            byte,
13399        } = err
13400        else {
13401            panic!("expected FonteCaminhoShellHistorySubstitution, got {err:?}");
13402        };
13403        assert_eq!(nome, "caixa-teia");
13404        assert_eq!(caminho, "../foo^bad^good");
13405        assert_eq!(byte, b'^');
13406    }
13407
13408    #[test]
13409    fn validate_rejects_path_fonte_with_caminho_carrying_regex_negation_anchor() {
13410        // The symmetric paste-from-doc-grep-pipeline footgun (peer with
13411        // `validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor`
13412        // on `is_git_repo_url`). An author copies a `grep '^archived'`
13413        // regex-anchor / negation idiom from a doc snippet and the byte
13414        // rides in verbatim. Pinned separately from the `^old^new^`
13415        // quick-substitution shape so a future diagnostic-surface change
13416        // that only checked the paired-caret history-substitution
13417        // position surfaces here — the per-byte arm fires anywhere `^`
13418        // appears in the value, including at a solitary leading-of-
13419        // segment position.
13420        let d = dep_with_fonte(DepSource::Path {
13421            caminho: "../foo/^archived".into(),
13422        });
13423        let err = d.validate().unwrap_err();
13424        assert!(
13425            matches!(
13426                err,
13427                DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13428            ),
13429            "got {err:?}",
13430        );
13431    }
13432
13433    #[test]
13434    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_history_substitution_open() {
13435        // The trailing-`^` history-substitution-open shape — an author
13436        // starts typing a `^bad^good` quick-substitution but pastes only
13437        // the leading `^` sentinel before context-switching (a bash-
13438        // reference §9.3 valid histexpand prefix on its own — even a
13439        // solitary `^` on the prior command's whole re-execution shape).
13440        // Pinned separately from the `^old^new^` full-form and the leading-
13441        // of-segment `^archived` regex-anchor shape so the gate's
13442        // rationale extends to the paste-from-shell-history-with-only-
13443        // the-first-byte-selected surface. None of the prior shell-
13444        // metachar arms cover this shape.
13445        let d = dep_with_fonte(DepSource::Path {
13446            caminho: "../caixa-teia^".into(),
13447        });
13448        let err = d.validate().unwrap_err();
13449        assert!(
13450            matches!(
13451                err,
13452                DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13453            ),
13454            "got {err:?}",
13455        );
13456    }
13457
13458    #[test]
13459    fn validate_accepts_path_fonte_with_caminho_carrying_no_caret() {
13460        // The positive-control pin (peer with
13461        // `validate_accepts_path_fonte_with_caminho_carrying_no_bang`
13462        // on the immediate-predecessor arm): the gate targets only
13463        // `^`, never adjacent printable ASCII or POSIX-valid bytes.
13464        // A relative POSIX path carrying dashes / dots / slashes /
13465        // digits / underscore (`"../caixa-teia/sub_v2.rc"`) must
13466        // continue to validate cleanly so the gate doesn't widen to
13467        // a "no printable punctuation anywhere" sweep that would
13468        // defeat the entire path-fonte author surface.
13469        let d = dep_with_fonte(DepSource::Path {
13470            caminho: "../caixa-teia/sub_v2.rc".into(),
13471        });
13472        d.validate().unwrap();
13473    }
13474
13475    #[test]
13476    fn fonte_caminho_shell_history_expansion_fires_before_shell_history_substitution() {
13477        // Cascade pin on the immediate-predecessor arm: a value carrying
13478        // both embedded `!` and `^` (`"../foo!sudo^bad^good"` — the
13479        // canonical "I pasted a `!sudo` history-reference next to a
13480        // `^bad^good` quick-substitution") routes through
13481        // `FonteCaminhoShellHistoryExpansion` not
13482        // `FonteCaminhoShellHistorySubstitution`. The `!` prefix form is
13483        // the more semantic-locating axis on probe-as-both values (an
13484        // author who removes the `!sudo` reference is likely to also
13485        // strip the paired `^` substitution fragment); same cascade
13486        // discipline every prior `:caminho` arm establishes.
13487        let d = dep_with_fonte(DepSource::Path {
13488            caminho: "../foo!sudo^bad^good".into(),
13489        });
13490        let err = d.validate().unwrap_err();
13491        assert!(
13492            matches!(
13493                err,
13494                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13495            ),
13496            "got {err:?}",
13497        );
13498    }
13499
13500    #[test]
13501    fn fonte_caminho_shell_history_substitution_fires_before_trailing_slash() {
13502        // Cascade pin on the immediate-successor arm: a value carrying
13503        // both embedded `^` and a trailing `/` (`"../foo^bad^good/"` —
13504        // the canonical "I tab-completed a `^bad^good`-carrying path")
13505        // routes through `FonteCaminhoShellHistorySubstitution` not
13506        // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13507        // substitution byte is the more semantic-locating axis on probe-
13508        // as-both values (an author who removes the `^bad^good`
13509        // substitution fragment is likely to also tab-strip the trailing
13510        // separator).
13511        let d = dep_with_fonte(DepSource::Path {
13512            caminho: "../foo^bad^good/".into(),
13513        });
13514        let err = d.validate().unwrap_err();
13515        assert!(
13516            matches!(
13517                err,
13518                DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13519            ),
13520            "got {err:?}",
13521        );
13522    }
13523
13524    #[test]
13525    fn fonte_caminho_shell_history_substitution_diagnostic_carries_offending_dep_caminho_and_byte()
13526    {
13527        // Diagnostic-shape pin (peer with
13528        // `fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13529        // on the immediate-predecessor arm): the error's Display
13530        // surfaces the offending `:nome`, the offending `:caminho`
13531        // verbatim, the offending byte's hex form, and names the
13532        // shell-history-substitution / RFC-3986-'unwise' / regex-
13533        // negation footgun explicitly so a `feira lint` run can render
13534        // the diagnostic without re-parsing.
13535        let d = dep_with_fonte(DepSource::Path {
13536            caminho: "../foo^bad^good".into(),
13537        });
13538        let rendered = d.validate().unwrap_err().to_string();
13539        assert!(
13540            rendered.contains("caixa-teia"),
13541            "diagnostic must name the offending dep: {rendered}",
13542        );
13543        assert!(
13544            rendered.contains("../foo^bad^good"),
13545            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13546        );
13547        assert!(
13548            rendered.contains("0x5e") || rendered.contains("0x5E"),
13549            "diagnostic must surface the offending byte hex: {rendered:?}",
13550        );
13551        assert!(
13552            rendered.contains("history-substitution") || rendered.contains("history substitution"),
13553            "diagnostic must name the shell-history-substitution footgun: {rendered:?}",
13554        );
13555        assert!(
13556            rendered.contains("unwise"),
13557            "diagnostic must reference the RFC-3986 'unwise' set vocabulary: {rendered:?}",
13558        );
13559    }
13560
13561    #[test]
13562    fn fonte_repo_empty_fires_before_pin_missing() {
13563        // Order pin: empty `:repo` is the more self-locating diagnostic
13564        // (every git source needs a repo; the pin discussion is
13565        // secondary), so it fires before the pin-missing arm even when
13566        // both are violated. Mirrors the
13567        // `nome_empty_takes_precedence_over_versao_invalid` ordering
13568        // discipline on the per-entry layer.
13569        let d = dep_with_fonte(DepSource::Git {
13570            repo: String::new(),
13571            tag: None,
13572            rev: None,
13573            branch: None,
13574        });
13575        let err = d.validate().unwrap_err();
13576        assert!(
13577            matches!(err, DepError::FonteRepoEmpty { .. }),
13578            "got {err:?}"
13579        );
13580    }
13581
13582    #[test]
13583    fn fonte_pin_missing_fires_before_pin_empty() {
13584        // Order pin: a fully-None pin set is structurally distinct from
13585        // a Some(empty) pin — the first surfaces as FontePinMissing
13586        // (no axis chosen), the second as FontePinEmpty (axis chosen
13587        // but value blank). Pin the disjoint relationship so a future
13588        // unification collapses to one variant only as a structural
13589        // decision.
13590        let d = dep_with_fonte(DepSource::Git {
13591            repo: "github:pleme-io/caixa-teia".into(),
13592            tag: None,
13593            rev: None,
13594            branch: None,
13595        });
13596        assert!(matches!(
13597            d.validate().unwrap_err(),
13598            DepError::FontePinMissing { .. }
13599        ));
13600    }
13601
13602    #[test]
13603    fn nome_empty_takes_precedence_over_fonte_invalid() {
13604        // Order pin: a per-entry diagnostic without a non-empty :nome
13605        // can't be self-locating, so :nome "" fires first even when
13606        // :fonte is also malformed. Mirrors
13607        // `nome_empty_takes_precedence_over_versao_invalid` on the
13608        // adjacent axis.
13609        let mut d = dep_with_fonte(DepSource::Git {
13610            repo: String::new(),
13611            tag: None,
13612            rev: None,
13613            branch: None,
13614        });
13615        d.nome = String::new();
13616        assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
13617    }
13618
13619    #[test]
13620    fn versao_invalid_takes_precedence_over_fonte_invalid() {
13621        // Order pin: the :versao parse-side diagnostic is narrower than
13622        // the :fonte shape diagnostic — a malformed :versao always names
13623        // the parser's reason, which is more actionable than the
13624        // :fonte gate's "the pins are wrong" wording. Pin the ordering
13625        // so a re-ordering surfaces here.
13626        let mut d = dep_with_fonte(DepSource::Git {
13627            repo: String::new(),
13628            tag: None,
13629            rev: None,
13630            branch: None,
13631        });
13632        d.versao = "v0.1".into();
13633        let err = d.validate().unwrap_err();
13634        assert!(
13635            matches!(err, DepError::VersaoInvalid { ref nome, .. } if nome == "caixa-teia"),
13636            "got {err:?}"
13637        );
13638    }
13639
13640    #[test]
13641    fn fonte_invalid_diagnostic_carries_offending_nome() {
13642        // The diagnostic-shape pin: every :fonte error variant names
13643        // the offending dep's :nome verbatim, so the author can grep
13644        // caixa.lisp for the `:nome "<n>"` block and fix it in one
13645        // edit. Cover all seven variants so a future variant addition
13646        // forces a parallel diagnostic-shape decision.
13647        for (case, fonte) in [
13648            (
13649                "repo-empty",
13650                DepSource::Git {
13651                    repo: String::new(),
13652                    tag: Some("v1".into()),
13653                    rev: None,
13654                    branch: None,
13655                },
13656            ),
13657            (
13658                "repo-shape",
13659                DepSource::Git {
13660                    repo: "github:p/x ".into(),
13661                    tag: Some("v1".into()),
13662                    rev: None,
13663                    branch: None,
13664                },
13665            ),
13666            (
13667                "pin-missing",
13668                DepSource::Git {
13669                    repo: "github:p/x".into(),
13670                    tag: None,
13671                    rev: None,
13672                    branch: None,
13673                },
13674            ),
13675            (
13676                "pin-ambiguous",
13677                DepSource::Git {
13678                    repo: "github:p/x".into(),
13679                    tag: Some("v1".into()),
13680                    rev: None,
13681                    branch: Some("main".into()),
13682                },
13683            ),
13684            (
13685                "pin-empty",
13686                DepSource::Git {
13687                    repo: "github:p/x".into(),
13688                    tag: Some(String::new()),
13689                    rev: None,
13690                    branch: None,
13691                },
13692            ),
13693            (
13694                "caminho-empty",
13695                DepSource::Path {
13696                    caminho: String::new(),
13697                },
13698            ),
13699            (
13700                "caminho-absolute",
13701                DepSource::Path {
13702                    caminho: "/home/me/work/caixa-teia".into(),
13703                },
13704            ),
13705        ] {
13706            let d = dep_with_fonte(fonte);
13707            let msg = d
13708                .validate()
13709                .expect_err(&format!("{case}: expected fonte error"))
13710                .to_string();
13711            assert!(
13712                msg.contains("\"caixa-teia\""),
13713                "{case}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
13714            );
13715        }
13716    }
13717
13718    // -- :tag / :branch value-shape gate ----------------------------------
13719
13720    #[test]
13721    fn validate_rejects_git_fonte_with_tag_carrying_trailing_space() {
13722        // The canonical paste-from-doc footgun on `:tag` — author
13723        // copies `"v0.1.0 "` (trailing space) out of a release-notes
13724        // paragraph. Until this gate landed the empty-pin arm passed
13725        // (the string isn't empty), the resolver issued
13726        // `git fetch <remote> tag 'v0.1.0 '`, and the failure
13727        // surfaced at clone time with a quoting-confused git error
13728        // far from the source caixa.lisp. The new gate moves the
13729        // check to caixa-build time and names the offending dep +
13730        // pin + value verbatim.
13731        let d = dep_with_fonte(DepSource::Git {
13732            repo: "github:pleme-io/caixa-teia".into(),
13733            tag: Some("v0.1.0 ".into()),
13734            rev: None,
13735            branch: None,
13736        });
13737        let err = d.validate().unwrap_err();
13738        let DepError::FontePinShape {
13739            nome,
13740            pin,
13741            value,
13742            reason,
13743        } = err
13744        else {
13745            panic!("expected FontePinShape, got other variant");
13746        };
13747        assert_eq!(nome, "caixa-teia");
13748        assert_eq!(pin, ":tag");
13749        assert_eq!(value, "v0.1.0 ");
13750        assert!(
13751            reason.contains("whitespace"),
13752            "reason must surface the whitespace arm, got {reason:?}"
13753        );
13754    }
13755
13756    #[test]
13757    fn validate_rejects_git_fonte_with_tag_carrying_lock_suffix() {
13758        // The `.lock` suffix is git's atomic-rename guard for
13759        // in-flight ref updates — a refname ending in `.lock` is
13760        // unwritable on disk. Pinned separately from the whitespace
13761        // arm so a future relaxation that admits one but not the
13762        // other surfaces here.
13763        let d = dep_with_fonte(DepSource::Git {
13764            repo: "github:pleme-io/caixa-teia".into(),
13765            tag: Some("v0.1.0.lock".into()),
13766            rev: None,
13767            branch: None,
13768        });
13769        let err = d.validate().unwrap_err();
13770        let DepError::FontePinShape {
13771            pin, value, reason, ..
13772        } = err
13773        else {
13774            panic!("expected FontePinShape, got other variant");
13775        };
13776        assert_eq!(pin, ":tag");
13777        assert_eq!(value, "v0.1.0.lock");
13778        assert!(
13779            reason.contains(".lock"),
13780            "reason must surface the .lock arm, got {reason:?}"
13781        );
13782    }
13783
13784    #[test]
13785    fn validate_rejects_git_fonte_with_branch_carrying_embedded_space() {
13786        // The canonical "branch name with spaces" footgun (`feature
13787        // foo`, `release branch`) — git's refname parser rejects raw
13788        // whitespace, and the failure surfaces at `git checkout
13789        // 'feature foo'` time with a quoting-confused error far from
13790        // the source caixa.lisp. Pinned on the `:branch` axis so the
13791        // gate-applies-to-both-:tag-and-:branch contract is a build-
13792        // error to relax.
13793        let d = dep_with_fonte(DepSource::Git {
13794            repo: "github:pleme-io/caixa-teia".into(),
13795            tag: None,
13796            rev: None,
13797            branch: Some("feature/foo bar".into()),
13798        });
13799        let err = d.validate().unwrap_err();
13800        let DepError::FontePinShape {
13801            pin, value, reason, ..
13802        } = err
13803        else {
13804            panic!("expected FontePinShape, got other variant");
13805        };
13806        assert_eq!(pin, ":branch");
13807        assert_eq!(value, "feature/foo bar");
13808        assert!(
13809            reason.contains("whitespace"),
13810            "reason must surface the whitespace arm, got {reason:?}"
13811        );
13812    }
13813
13814    #[test]
13815    fn validate_rejects_git_fonte_with_branch_carrying_qualified_prefix() {
13816        // The `refs/heads/main` shape — the canonical "I copied the
13817        // fully-qualified ref out of `git show-ref` instead of the
13818        // leaf" footgun. The caixa-resolver prepends `refs/heads/`
13819        // at clone time, so this resolves to a literal ref named
13820        // `refs/heads/refs/heads/main` on disk; the silent double-
13821        // prefix is the load-bearing reason to gate at validate.
13822        // The diagnostic must enumerate the leaf the author probably
13823        // meant (`"main"`) so the fix is one edit.
13824        let d = dep_with_fonte(DepSource::Git {
13825            repo: "github:pleme-io/caixa-teia".into(),
13826            tag: None,
13827            rev: None,
13828            branch: Some("refs/heads/main".into()),
13829        });
13830        let err = d.validate().unwrap_err();
13831        let DepError::FontePinShape {
13832            pin, value, reason, ..
13833        } = err
13834        else {
13835            panic!("expected FontePinShape, got other variant");
13836        };
13837        assert_eq!(pin, ":branch");
13838        assert_eq!(value, "refs/heads/main");
13839        assert!(
13840            reason.contains("fully-qualified"),
13841            "reason must surface the qualified-prefix arm, got {reason:?}"
13842        );
13843        assert!(
13844            reason.contains("\"main\""),
13845            "reason must quote the leaf the author probably meant, got {reason:?}"
13846        );
13847    }
13848
13849    #[test]
13850    fn validate_rejects_git_fonte_with_tag_carrying_qualified_prefix() {
13851        // Sibling arm of the qualified-prefix gate on the `:tag`
13852        // axis (`refs/tags/v0.1.0` — same `git show-ref` output-leak
13853        // footgun). Pinned separately so a future relaxation that
13854        // only catches the `:branch` arm surfaces here.
13855        let d = dep_with_fonte(DepSource::Git {
13856            repo: "github:pleme-io/caixa-teia".into(),
13857            tag: Some("refs/tags/v0.1.0".into()),
13858            rev: None,
13859            branch: None,
13860        });
13861        let err = d.validate().unwrap_err();
13862        let DepError::FontePinShape {
13863            pin, value, reason, ..
13864        } = err
13865        else {
13866            panic!("expected FontePinShape, got other variant");
13867        };
13868        assert_eq!(pin, ":tag");
13869        assert_eq!(value, "refs/tags/v0.1.0");
13870        assert!(
13871            reason.contains("fully-qualified"),
13872            "reason must surface the qualified-prefix arm, got {reason:?}"
13873        );
13874        assert!(
13875            reason.contains("\"v0.1.0\""),
13876            "reason must quote the leaf the author probably meant, got {reason:?}"
13877        );
13878    }
13879
13880    #[test]
13881    fn validate_rejects_git_fonte_with_branch_named_at() {
13882        // The bare `@` is git's alias for `HEAD`; a `:branch "@"` is
13883        // unsourceable. Pinned so a future relaxation that admits
13884        // any single-character refname surfaces here.
13885        let d = dep_with_fonte(DepSource::Git {
13886            repo: "github:pleme-io/caixa-teia".into(),
13887            tag: None,
13888            rev: None,
13889            branch: Some("@".into()),
13890        });
13891        let err = d.validate().unwrap_err();
13892        let DepError::FontePinShape { pin, value, .. } = err else {
13893            panic!("expected FontePinShape, got other variant");
13894        };
13895        assert_eq!(pin, ":branch");
13896        assert_eq!(value, "@");
13897    }
13898
13899    #[test]
13900    fn validate_rejects_git_fonte_with_tag_carrying_double_dot() {
13901        // Git's `<rev1>..<rev2>` range grammar reserves `..` —
13902        // a `:tag "../escape"` (path-traversal-shaped slug) silently
13903        // passes parse and surfaces as a refname-parse error or, on
13904        // older git, a literal `../escape` checkout that escapes the
13905        // refs/ directory tree. Pinned separately from the
13906        // qualified-prefix arm so a future relaxation that catches
13907        // one but not the other surfaces here.
13908        let d = dep_with_fonte(DepSource::Git {
13909            repo: "github:pleme-io/caixa-teia".into(),
13910            tag: Some("../escape".into()),
13911            rev: None,
13912            branch: None,
13913        });
13914        let err = d.validate().unwrap_err();
13915        let DepError::FontePinShape { pin, value, .. } = err else {
13916            panic!("expected FontePinShape, got other variant");
13917        };
13918        assert_eq!(pin, ":tag");
13919        assert_eq!(value, "../escape");
13920    }
13921
13922    #[test]
13923    fn validate_accepts_git_fonte_with_hierarchical_branch() {
13924        // The positive-control pin: hierarchical refnames with one or
13925        // more `/` separators (the `feature/foo` / `user/jdoe/feat`
13926        // canonical idiom) round-trip through the gate. Pinned
13927        // separately from the leaf-`"main"` positive control so a
13928        // future tightening that rejects all multi-component refnames
13929        // surfaces here.
13930        let d = dep_with_fonte(DepSource::Git {
13931            repo: "github:pleme-io/caixa-teia".into(),
13932            tag: None,
13933            rev: None,
13934            branch: Some("feature/checkout-rewrite".into()),
13935        });
13936        d.validate().unwrap();
13937    }
13938
13939    #[test]
13940    fn validate_accepts_git_fonte_with_prerelease_tag() {
13941        // The positive-control pin: semver pre-release shape
13942        // (`v0.1.0-alpha.1`) — the in-component dot is allowed
13943        // (only consecutive `..` and trailing `.` are rejected), the
13944        // mid-component hyphen is allowed. Pinned separately from
13945        // the bare-`"v0.1.0"` positive control so a future tightening
13946        // that rejects pre-release tags surfaces here.
13947        let d = dep_with_fonte(DepSource::Git {
13948            repo: "github:pleme-io/caixa-teia".into(),
13949            tag: Some("v0.1.0-alpha.1".into()),
13950            rev: None,
13951            branch: None,
13952        });
13953        d.validate().unwrap();
13954    }
13955
13956    #[test]
13957    fn validate_rejects_git_fonte_with_rev_carrying_refname_unfriendly_value() {
13958        // The `:rev` axis is routed through `crate::render::is_git_oid`
13959        // (a SHA's character set is `[0-9a-f]`, not a refname's), so a
13960        // value with refname-shape punctuation (here, a `:` mid-string
13961        // — would be a refname violation under `is_git_ref_name` too)
13962        // is rejected at the OID-shape gate. The two predicates
13963        // partition the `:fonte` pin axes structurally: an `:rev` value
13964        // that's a valid refname (`:rev "main"`, `:rev "v0.1.0"`) is
13965        // *still* rejected here because every refname character outside
13966        // `[0-9a-f]` fails the OID gate. Same shape as
13967        // `fonte_pin_shape_diagnostic_carries_offending_nome_pin_value`
13968        // on the refname-shaped axes — the diagnostic names the
13969        // offending dep + pin + value verbatim. The flip-from-accept
13970        // case the prior `:tag`/`:branch` gate left as a "future axis"
13971        // (e70d213) — now landed.
13972        let d = dep_with_fonte(DepSource::Git {
13973            repo: "github:pleme-io/caixa-teia".into(),
13974            tag: None,
13975            rev: Some("c0ffee:notarefname".into()),
13976            branch: None,
13977        });
13978        let err = d.validate().unwrap_err();
13979        let DepError::FontePinShape {
13980            nome,
13981            pin,
13982            value,
13983            reason,
13984        } = err
13985        else {
13986            panic!("expected FontePinShape, got other variant");
13987        };
13988        assert_eq!(nome, "caixa-teia");
13989        assert_eq!(pin, ":rev");
13990        assert_eq!(value, "c0ffee:notarefname");
13991        assert!(
13992            !reason.is_empty(),
13993            "FontePinShape `reason` must carry the predicate's wording verbatim"
13994        );
13995    }
13996
13997    #[test]
13998    fn validate_accepts_git_fonte_with_rev_full_sha1() {
13999        // The positive-control pin on the SHA-1 OID width: exactly 40
14000        // lowercase hex characters — the canonical `git rev-parse HEAD`
14001        // emission on a SHA-1-hashed repository (the default on every
14002        // pre-2.42 git and the canonical pleme-io substrate hash).
14003        // Pinned separately from the SHA-256 positive control so a
14004        // future tightening that only admits one width surfaces here.
14005        let d = dep_with_fonte(DepSource::Git {
14006            repo: "github:pleme-io/caixa-teia".into(),
14007            tag: None,
14008            rev: Some("0123456789abcdef0123456789abcdef01234567".into()),
14009            branch: None,
14010        });
14011        d.validate().unwrap();
14012    }
14013
14014    #[test]
14015    fn validate_accepts_git_fonte_with_rev_full_sha256() {
14016        // The positive-control pin on the SHA-256 OID width: exactly
14017        // 64 lowercase hex characters — `git`'s
14018        // `extensions.objectFormat = sha256` emission (GA since Git
14019        // 2.42 / Oct 2023). The substrate admits either canonical
14020        // width so an `:rev` authored against a SHA-256-hashed
14021        // upstream round-trips through the gate without per-repo
14022        // configuration. Pinned separately from the SHA-1 positive
14023        // control so a future tightening that drops one width surfaces
14024        // here as a structural decision.
14025        let d = dep_with_fonte(DepSource::Git {
14026            repo: "github:pleme-io/caixa-teia".into(),
14027            tag: None,
14028            rev: Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into()),
14029            branch: None,
14030        });
14031        d.validate().unwrap();
14032    }
14033
14034    #[test]
14035    fn validate_rejects_git_fonte_with_rev_abbreviated_prefix() {
14036        // The canonical `git log --short` / `git rev-parse --short HEAD`
14037        // paste-from-release-notes footgun: a 7-char prefix (git's
14038        // default `core.abbrev`) silently passes string emptiness
14039        // checks and resolves to one commit today, but becomes ambiguous
14040        // tomorrow as the repo grows. Until this gate landed the empty-
14041        // pin arm passed (the string isn't empty) and the resolver
14042        // accepted the prefix through git's separate prefix-lookup pass
14043        // — defeating the reproducibility contract `:rev` carries vs.
14044        // `:tag` / `:branch`. The new gate moves the check to caixa-
14045        // build time and names the offending dep + pin + value verbatim.
14046        let d = dep_with_fonte(DepSource::Git {
14047            repo: "github:pleme-io/caixa-teia".into(),
14048            tag: None,
14049            rev: Some("c0ffee0".into()),
14050            branch: None,
14051        });
14052        let err = d.validate().unwrap_err();
14053        let DepError::FontePinShape {
14054            pin, value, reason, ..
14055        } = err
14056        else {
14057            panic!("expected FontePinShape, got other variant");
14058        };
14059        assert_eq!(pin, ":rev");
14060        assert_eq!(value, "c0ffee0");
14061        assert!(
14062            reason.contains("abbreviated") || reason.contains("ambiguous"),
14063            "reason must surface the abbreviation arm, got {reason:?}"
14064        );
14065    }
14066
14067    #[test]
14068    fn validate_rejects_git_fonte_with_rev_uppercase_hex() {
14069        // The canonical "I pasted the SHA in uppercase" footgun: `git
14070        // porcelain` emits OIDs lowercase exclusively, so an uppercase-
14071        // bearing `:rev` round-trips inconsistently across the
14072        // resolver's `git fetch <remote> <:rev>` ↔ `git rev-parse HEAD`
14073        // equality-check pipeline and fails the lacre's content-
14074        // addressing probe with a confusing case-only diff. Pinned
14075        // separately from the non-hex arm so a future relaxation that
14076        // admits one but not the other surfaces here.
14077        let d = dep_with_fonte(DepSource::Git {
14078            repo: "github:pleme-io/caixa-teia".into(),
14079            tag: None,
14080            rev: Some("DEADBEEFCAFEBABE0123456789ABCDEF01234567".into()),
14081            branch: None,
14082        });
14083        let err = d.validate().unwrap_err();
14084        let DepError::FontePinShape {
14085            pin, value, reason, ..
14086        } = err
14087        else {
14088            panic!("expected FontePinShape, got other variant");
14089        };
14090        assert_eq!(pin, ":rev");
14091        assert_eq!(value, "DEADBEEFCAFEBABE0123456789ABCDEF01234567");
14092        assert!(
14093            reason.contains("uppercase"),
14094            "reason must surface the uppercase arm, got {reason:?}"
14095        );
14096    }
14097
14098    #[test]
14099    fn validate_rejects_git_fonte_with_rev_refname_value() {
14100        // The cross-axis mis-slot footgun: `:rev "main"` — the author
14101        // conflated `:rev` (hex commit ID, immutable) and `:branch`
14102        // (mutable ref pointing at whatever HEAD is today). Until this
14103        // gate landed the resolver silently dispatched on the value
14104        // shape ("`main` doesn't look like a SHA, fall back to
14105        // refname"), defeating the `:rev` reproducibility contract.
14106        // The new gate rejects every non-hex value on the `:rev` axis,
14107        // so the `:rev`/`:branch` boundary is structurally enforced —
14108        // a refname in the `:rev` slot is a build error, not a
14109        // resolver-time silent reinterpretation.
14110        let d = dep_with_fonte(DepSource::Git {
14111            repo: "github:pleme-io/caixa-teia".into(),
14112            tag: None,
14113            rev: Some("main".into()),
14114            branch: None,
14115        });
14116        let err = d.validate().unwrap_err();
14117        let DepError::FontePinShape {
14118            pin, value, reason, ..
14119        } = err
14120        else {
14121            panic!("expected FontePinShape, got other variant");
14122        };
14123        assert_eq!(pin, ":rev");
14124        assert_eq!(value, "main");
14125        // 4 chars `main` fails the length arm before the character arm,
14126        // so the diagnostic surfaces the abbreviation wording (same
14127        // path the `c0ffee0` 7-char fixture lands on); the structural
14128        // assertion is just that the `:rev "main"` value is rejected.
14129        assert!(
14130            !reason.is_empty(),
14131            "FontePinShape reason must be non-empty for refname-shaped :rev"
14132        );
14133    }
14134
14135    #[test]
14136    fn validate_rejects_git_fonte_with_rev_tag_shaped_value() {
14137        // Sibling cross-axis mis-slot: `:rev "v0.1.0"` — the author
14138        // conflated `:rev` and `:tag`. Pinned separately from the
14139        // `:rev "main"` (`:branch` mis-slot) arm so a future relaxation
14140        // that catches one but not the other surfaces here. The
14141        // length arm fires first (6 chars ≠ 40 ≠ 64); the structural
14142        // assertion is just that the cross-axis mis-slot is a build
14143        // error, regardless of which sub-arm surfaces the diagnostic
14144        // (`is_git_oid` rejects at the first violation; longer
14145        // tag-shape values would hit the non-hex arm instead).
14146        let d = dep_with_fonte(DepSource::Git {
14147            repo: "github:pleme-io/caixa-teia".into(),
14148            tag: None,
14149            rev: Some("v0.1.0".into()),
14150            branch: None,
14151        });
14152        let err = d.validate().unwrap_err();
14153        let DepError::FontePinShape {
14154            pin, value, reason, ..
14155        } = err
14156        else {
14157            panic!("expected FontePinShape, got other variant");
14158        };
14159        assert_eq!(pin, ":rev");
14160        assert_eq!(value, "v0.1.0");
14161        assert!(
14162            !reason.is_empty(),
14163            "FontePinShape reason must be non-empty for tag-shaped :rev"
14164        );
14165    }
14166
14167    #[test]
14168    fn validate_rejects_git_fonte_with_rev_too_long() {
14169        // Boundary case on the upper end: 41 hex chars — one past the
14170        // SHA-1 width, well below the SHA-256 width. Pin so a future
14171        // relaxation that admits "long enough to be a SHA" without
14172        // matching either canonical width surfaces here. The diagnostic
14173        // names the offending length verbatim so the author's grep
14174        // target is unambiguous (either trim one char or paste the
14175        // full SHA-256).
14176        let too_long: String = "0".repeat(41);
14177        let d = dep_with_fonte(DepSource::Git {
14178            repo: "github:pleme-io/caixa-teia".into(),
14179            tag: None,
14180            rev: Some(too_long.clone()),
14181            branch: None,
14182        });
14183        let err = d.validate().unwrap_err();
14184        let DepError::FontePinShape {
14185            pin, value, reason, ..
14186        } = err
14187        else {
14188            panic!("expected FontePinShape, got other variant");
14189        };
14190        assert_eq!(pin, ":rev");
14191        assert_eq!(value, too_long);
14192        assert!(
14193            reason.contains("41"),
14194            "reason must surface the offending length verbatim, got {reason:?}"
14195        );
14196    }
14197
14198    #[test]
14199    fn validate_rejects_git_fonte_with_rev_carrying_whitespace() {
14200        // The canonical paste-from-doc footgun on `:rev` — author
14201        // copies `"deadbeefcafe…0123 "` (trailing space) out of a
14202        // commit-message paragraph. Until this gate landed the empty-
14203        // pin arm passed (the string isn't empty), the resolver issued
14204        // `git fetch <remote> 'deadbeef… '` and the failure surfaced at
14205        // clone time with a quoting-confused git error far from the
14206        // source caixa.lisp. The new gate moves the check to caixa-
14207        // build time. Length is 41 (40 hex + space) so the length arm
14208        // fires first — pinned separately from the pure-length arm to
14209        // ensure the diagnostic surfaces *some* parser wording, not
14210        // silently pass through.
14211        let with_space = "0123456789abcdef0123456789abcdef01234567 ".to_string();
14212        let d = dep_with_fonte(DepSource::Git {
14213            repo: "github:pleme-io/caixa-teia".into(),
14214            tag: None,
14215            rev: Some(with_space.clone()),
14216            branch: None,
14217        });
14218        let err = d.validate().unwrap_err();
14219        let DepError::FontePinShape {
14220            pin, value, reason, ..
14221        } = err
14222        else {
14223            panic!("expected FontePinShape, got other variant");
14224        };
14225        assert_eq!(pin, ":rev");
14226        assert_eq!(value, with_space);
14227        assert!(
14228            !reason.is_empty(),
14229            "FontePinShape reason must be non-empty for whitespace-bearing :rev"
14230        );
14231    }
14232
14233    #[test]
14234    fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value_for_rev() {
14235        // Diagnostic-shape pin on the `:rev` axis: every FontePinShape
14236        // variant on this axis names the offending dep's `:nome` + the
14237        // `:rev` axis + the offending value verbatim, so the author's
14238        // grep target is the literal `:rev "<value>"` block in
14239        // caixa.lisp. Sibling of the `fonte_pin_shape_diagnostic_
14240        // carries_offending_nome_pin_value` test on the refname-shaped
14241        // (`:tag` / `:branch`) axes.
14242        let d = dep_with_fonte(DepSource::Git {
14243            repo: "github:p/x".into(),
14244            tag: None,
14245            rev: Some("not-a-sha".into()),
14246            branch: None,
14247        });
14248        let msg = d
14249            .validate()
14250            .expect_err(":rev: expected FontePinShape")
14251            .to_string();
14252        assert!(
14253            msg.contains("\"caixa-teia\""),
14254            ":rev: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14255        );
14256        assert!(
14257            msg.contains(":rev"),
14258            ":rev: diagnostic must name the offending pin axis, got {msg:?}"
14259        );
14260        assert!(
14261            msg.contains("not-a-sha"),
14262            ":rev: diagnostic must quote the offending value verbatim, got {msg:?}"
14263        );
14264    }
14265
14266    #[test]
14267    fn fonte_pin_empty_fires_before_pin_shape() {
14268        // Order pin: a `Some("")` `:tag` is the more self-locating
14269        // diagnostic (the author chose an axis but left it blank;
14270        // grep is unambiguous), so it fires before the shape gate
14271        // even when both arms would match. Pinned so a future
14272        // reordering surfaces here. Mirrors the
14273        // `fonte_repo_empty_fires_before_pin_missing` ordering
14274        // discipline on the peer per-axis arms.
14275        let d = dep_with_fonte(DepSource::Git {
14276            repo: "github:pleme-io/caixa-teia".into(),
14277            tag: Some(String::new()),
14278            rev: None,
14279            branch: None,
14280        });
14281        assert!(matches!(
14282            d.validate().unwrap_err(),
14283            DepError::FontePinEmpty { ref pin, .. } if pin == ":tag"
14284        ));
14285    }
14286
14287    #[test]
14288    fn fonte_pin_shape_fires_after_repo_empty() {
14289        // Order pin: `:repo ""` is the more self-locating axis
14290        // (every git source needs a repo; the per-pin shape gate is
14291        // secondary), so the repo-empty arm fires before the
14292        // per-pin shape arm even when both are violated. Pinned so
14293        // a future reordering surfaces here. Mirrors
14294        // `fonte_repo_empty_fires_before_pin_missing` on the
14295        // adjacent axis pair.
14296        let d = dep_with_fonte(DepSource::Git {
14297            repo: String::new(),
14298            tag: Some("v0.1.0 ".into()),
14299            rev: None,
14300            branch: None,
14301        });
14302        assert!(matches!(
14303            d.validate().unwrap_err(),
14304            DepError::FonteRepoEmpty { .. }
14305        ));
14306    }
14307
14308    #[test]
14309    fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value() {
14310        // Diagnostic-shape pin across both refname-shaped axes
14311        // (`:tag` + `:branch`): every `FontePinShape` variant names
14312        // the offending dep's `:nome` + the offending pin axis + the
14313        // offending value verbatim, so the author's grep target is
14314        // unambiguous (the literal `:tag "<value>"` / `:branch
14315        // "<value>"` lands in caixa.lisp with quotes). Cover both
14316        // pin axes so a future variant addition forces a parallel
14317        // diagnostic-shape decision.
14318        for (pin_label, fonte) in [
14319            (
14320                ":tag",
14321                DepSource::Git {
14322                    repo: "github:p/x".into(),
14323                    tag: Some("v0.1.0~1".into()),
14324                    rev: None,
14325                    branch: None,
14326                },
14327            ),
14328            (
14329                ":branch",
14330                DepSource::Git {
14331                    repo: "github:p/x".into(),
14332                    tag: None,
14333                    rev: None,
14334                    branch: Some("feature/foo*".into()),
14335                },
14336            ),
14337        ] {
14338            let d = dep_with_fonte(fonte);
14339            let msg = d
14340                .validate()
14341                .expect_err(&format!("{pin_label}: expected FontePinShape"))
14342                .to_string();
14343            assert!(
14344                msg.contains("\"caixa-teia\""),
14345                "{pin_label}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14346            );
14347            assert!(
14348                msg.contains(pin_label),
14349                "{pin_label}: diagnostic must name the offending pin axis, got {msg:?}"
14350            );
14351        }
14352    }
14353
14354    #[test]
14355    fn git_source_json_round_trip() {
14356        let src = DepSource::Git {
14357            repo: "github:pleme-io/caixa-teia".into(),
14358            tag: Some("v0.1.0".into()),
14359            rev: None,
14360            branch: None,
14361        };
14362        let s = serde_json::to_string(&src).unwrap();
14363        assert!(s.contains(&format!(
14364            r#""{tipo}":"{git}""#,
14365            tipo = crate::render::DEP_SOURCE_KEY_TIPO,
14366            git = crate::render::DEP_SOURCE_TIPO_GIT,
14367        )));
14368        assert!(s.contains(r#""repo":"github:pleme-io/caixa-teia""#));
14369        assert!(s.contains(r#""tag":"v0.1.0""#));
14370        assert!(!s.contains("rev"));
14371        assert!(!s.contains("branch"));
14372        let round: DepSource = serde_json::from_str(&s).unwrap();
14373        assert_eq!(round, src);
14374    }
14375
14376    // ── DEP_SOURCE_{KEY_TIPO,TIPO_GIT,TIPO_PATH} drift-detection ────────
14377    //
14378    // The `#[serde(tag = "tipo", rename_all = "lowercase")]` derive
14379    // attribute on [`DepSource`] pins three load-bearing byte-sequences
14380    // that flow into every serialized `Dep.fonte` block: the outer
14381    // discriminator-key `"tipo"` the `tag = "tipo"` attribute names, and
14382    // the two admitted variant-tag values `"git"` / `"path"` the
14383    // `rename_all = "lowercase"` attribute pins as the discriminator's
14384    // closed-set arms. The three pin tests below round-trip a
14385    // fully-populated variant of each arm through
14386    // [`serde_json::to_value`] and assert each canonical byte-sequence
14387    // appears at its axis — pins a hypothetical future
14388    // `tag = "type"` / `tag = "source_type"` typo, a `rename_all`
14389    // rebrand (`"UPPERCASE"` / `"snake_case"` / `"kebab-case"`), or a
14390    // Rust-side variant rename (`Git` → `Repository`, `Path` → `Local`)
14391    // at build time rather than at fetch time when the resolver's
14392    // `Dep.fonte` dispatch silently fails to match on the drifted
14393    // discriminator. Same "serialize-and-check" discipline the peer
14394    // `M2_LIMITS_KEY_*`, `M2_BEHAVIOR_KEY_ON_*`, `SUPERVISOR_KEY_*`,
14395    // and `MEMBRO_KEY_*` drift-detection pins carry — extended here
14396    // to the last `#[serde(tag = ..., rename_all = ...)]` discriminator
14397    // family in caixa-core lacking a lifted peer.
14398
14399    #[test]
14400    fn dep_source_git_serde_keys_match_lifted_dep_source_key_consts() {
14401        // Fail-before-pass-after: a future `tag = "type"` at the derive
14402        // attribute would serialize under `"type":"git"`, and this test
14403        // would trip because `"tipo"` no longer appears at the emitted
14404        // discriminator key. A future `rename_all = "kebab-case"` /
14405        // `"snake_case"` (both no-ops on `Git` since it lacks internal
14406        // word boundaries) is caught by the sibling
14407        // `dep_source_path_serde_keys_match_lifted_dep_source_key_consts`
14408        // pin below (Path has no internal boundary either but the pair
14409        // catches any per-arm inconsistency). A future variant rename
14410        // `Git` → `Repository` would emit `"tipo":"repository"` and
14411        // trip this pin.
14412        let src = DepSource::Git {
14413            repo: "github:pleme-io/caixa-teia".into(),
14414            tag: Some("v0.1.0".into()),
14415            rev: None,
14416            branch: None,
14417        };
14418        let json = serde_json::to_value(&src).unwrap();
14419        let obj = json.as_object().expect("Git serializes as a JSON object");
14420        assert_eq!(
14421            obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14422                .and_then(serde_json::Value::as_str),
14423            Some(crate::render::DEP_SOURCE_TIPO_GIT),
14424            "DepSource::Git must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14425             with value DEP_SOURCE_TIPO_GIT — attribute drift or variant rename \
14426             detected in {json}"
14427        );
14428    }
14429
14430    #[test]
14431    fn dep_source_path_serde_keys_match_lifted_dep_source_key_consts() {
14432        // Fail-before-pass-after: a future variant rename `Path` →
14433        // `Local` / `Filesystem` would emit `"tipo":"local"` and trip
14434        // this pin. A per-consumer disambiguation as the `defcaixa`
14435        // macro stabilizes ("caminho" → "path" for English-uniformity)
14436        // is scoped to the inner field key, not the discriminator; this
14437        // pin is orthogonal to that and catches only the outer
14438        // discriminator drift.
14439        let src = DepSource::Path {
14440            caminho: "../caixa-teia".into(),
14441        };
14442        let json = serde_json::to_value(&src).unwrap();
14443        let obj = json.as_object().expect("Path serializes as a JSON object");
14444        assert_eq!(
14445            obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14446                .and_then(serde_json::Value::as_str),
14447            Some(crate::render::DEP_SOURCE_TIPO_PATH),
14448            "DepSource::Path must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14449             with value DEP_SOURCE_TIPO_PATH — attribute drift or variant rename \
14450             detected in {json}"
14451        );
14452    }
14453
14454    #[test]
14455    fn dep_source_key_consts_are_pairwise_distinct() {
14456        // Cross-axis collapse detector: a hypothetical future edit that
14457        // accidentally set two of the three consts to the same byte
14458        // (`DEP_SOURCE_TIPO_GIT = "path"` typo matching a peer arm) would
14459        // pass every per-arm serialize pin above but silently collapse
14460        // the discriminator's closed-set arms onto one another; this pin
14461        // catches the collapse at build time.
14462        assert_ne!(
14463            crate::render::DEP_SOURCE_KEY_TIPO,
14464            crate::render::DEP_SOURCE_TIPO_GIT,
14465        );
14466        assert_ne!(
14467            crate::render::DEP_SOURCE_KEY_TIPO,
14468            crate::render::DEP_SOURCE_TIPO_PATH,
14469        );
14470        assert_ne!(
14471            crate::render::DEP_SOURCE_TIPO_GIT,
14472            crate::render::DEP_SOURCE_TIPO_PATH,
14473        );
14474    }
14475
14476    #[test]
14477    fn dep_source_tipo_variant_consts_are_ascii_lowercase_shape() {
14478        // Shape pin against `rename_all` drift: the two variant-tag
14479        // consts must be ASCII-lowercase-only to match the
14480        // `rename_all = "lowercase"` attribute the derive uses; a future
14481        // rebrand to `"UPPERCASE"` / `"PascalCase"` at the attribute
14482        // would emit `"GIT"` / `"Git"` instead and trip this pin.
14483        for (label, s) in [
14484            ("DEP_SOURCE_TIPO_GIT", crate::render::DEP_SOURCE_TIPO_GIT),
14485            ("DEP_SOURCE_TIPO_PATH", crate::render::DEP_SOURCE_TIPO_PATH),
14486        ] {
14487            assert!(!s.is_empty(), "{label} must not be empty");
14488            assert!(
14489                s.bytes().all(|b| b.is_ascii_lowercase()),
14490                "{label} must be ASCII-lowercase-only (matching \
14491                 rename_all = \"lowercase\"), got {s:?}",
14492            );
14493        }
14494    }
14495
14496    // ── per-entry :caracteristicas set-not-multiset gate ────────────
14497    //
14498    // Every Vec-keyed-by-name authoring surface on the typed Caixa
14499    // surface that identifies its entries by a name field now uniformly
14500    // closes the set-not-multiset discipline at build time (cite
14501    // `validate_caracteristicas`'s peer-axis enumeration). The
14502    // `:caracteristicas` axis is per-`Dep`: the feature-toggle slot is
14503    // set-shaped (a feature is either enabled or not — there is no
14504    // `feature × 2` semantic), so two entries naming the same feature
14505    // are a redundant declaration the caixa-resolver's lacre pipeline
14506    // would silently dedup at resolve time. The empty-feature arm
14507    // closes the parallel "operationally-meaningless value" axis on
14508    // the same slot. Same linear-walk + `HashSet` + first-collision
14509    // shape every peer set gate uses; same empty-first cascade every
14510    // peer per-entry shape + duplicate gate uses (the empty-feature
14511    // axis is the more-actionable defect since two `""` entries would
14512    // both report `caracteristica: ""` under a duplicate-first
14513    // ordering, with no way to distinguish the offending site).
14514
14515    fn dep_with_features(features: &[&str]) -> Dep {
14516        Dep {
14517            nome: "caixa-teia".into(),
14518            versao: "^0.1".into(),
14519            fonte: None,
14520            opcional: false,
14521            caracteristicas: features.iter().map(|s| (*s).into()).collect(),
14522        }
14523    }
14524
14525    #[test]
14526    fn validate_rejects_empty_caracteristica() {
14527        // Fail-before-pass-after pin: every pre-gate codebase accepted
14528        // `(:caracteristicas (""))` cleanly (the `Vec<String>` field
14529        // imposed no per-entry shape contract), the dep validated, and
14530        // the empty feature would have reached the future caixa-resolver
14531        // lacre pipeline as a no-op feature enable — silently dropping
14532        // the author's intent far from the source `caixa.lisp`. The new
14533        // gate surfaces the structural defect at the typed-validate
14534        // surface with a self-locating diagnostic naming the offending
14535        // dep's `:nome`.
14536        let d = dep_with_features(&[""]);
14537        assert!(
14538            matches!(d.validate().unwrap_err(), DepError::CaracteristicaEmpty { ref nome } if nome == "caixa-teia"),
14539            "expected CaracteristicaEmpty, got {:?}",
14540            d.validate(),
14541        );
14542    }
14543
14544    #[test]
14545    fn validate_rejects_duplicate_caracteristica() {
14546        // Fail-before-pass-after pin on the set-not-multiset arm: the
14547        // feature-toggle slot is set-shaped, so `(:caracteristicas
14548        // ("http" "http"))` is a redundant declaration the lacre
14549        // pipeline dedupes silently at resolve time. The diagnostic
14550        // names the offending dep + the colliding feature verbatim so
14551        // the author can grep their caixa.lisp for `:caracteristicas`
14552        // and fix it in one edit. First-collision determinism is
14553        // pinned separately below.
14554        let d = dep_with_features(&["http", "http"]);
14555        assert!(
14556            matches!(
14557                d.validate().unwrap_err(),
14558                DepError::CaracteristicaDuplicate { ref nome, ref caracteristica }
14559                    if nome == "caixa-teia" && caracteristica == "http"
14560            ),
14561            "expected CaracteristicaDuplicate, got {:?}",
14562            d.validate(),
14563        );
14564    }
14565
14566    #[test]
14567    fn validate_accepts_distinct_caracteristicas() {
14568        // The canonical authoring shape — every feature distinct — must
14569        // remain a clean pass (positive control sweep). Covers the
14570        // canonical kebab-case feature names a target caixa typically
14571        // declares.
14572        dep_with_features(&["http", "json", "tls"])
14573            .validate()
14574            .unwrap();
14575    }
14576
14577    #[test]
14578    fn validate_accepts_single_caracteristica() {
14579        // Single-element list is the minimum non-empty shape; passes
14580        // the gate as the identity of the duplicate check (no second
14581        // entry to collide with).
14582        dep_with_features(&["http"]).validate().unwrap();
14583    }
14584
14585    #[test]
14586    fn validate_accepts_empty_caracteristicas_list() {
14587        // The bare-dep authoring shape (`Dep::simple` / `Dep::git`)
14588        // produces `caracteristicas: Vec::new()`; the empty list is
14589        // the gate's empty-set identity and passes vacuously. Pin
14590        // this so a future tightening that requires ≥1 feature
14591        // surfaces here as a test failure rather than a silent
14592        // contract narrowing.
14593        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14594        assert!(dep_with_features(&[]).validate().is_ok());
14595    }
14596
14597    #[test]
14598    fn validate_caracteristica_empty_fires_before_duplicate() {
14599        // Empty-first cascade: an entry with an empty feature *and*
14600        // duplicate entries surfaces the empty diagnostic first. The
14601        // empty-feature axis is the more-actionable defect since
14602        // `caracteristica: ""` is unambiguous; under duplicate-first
14603        // ordering the diagnostic could report the empty string from
14604        // either of two empty entries with no way to distinguish.
14605        // Mirrors the peer empty-before-duplicate ordering
14606        // discipline every per-entry shape + duplicate gate establishes
14607        // (`SupervisorSpec::validate`'s `EmptyChildName` arm before
14608        // `DuplicateChildCaixa`, `validate_membros`'s
14609        // `MembroCaixaEmpty` arm before `MembroDuplicate`).
14610        let d = dep_with_features(&["", "http", "http"]);
14611        assert!(matches!(
14612            d.validate().unwrap_err(),
14613            DepError::CaracteristicaEmpty { .. }
14614        ));
14615    }
14616
14617    #[test]
14618    fn validate_caracteristica_duplicate_first_collision_determinism() {
14619        // Three matching entries: the second occurrence surfaces the
14620        // diagnostic (the second is the first *collision* — the first
14621        // entry is the establishing one, not a duplicate). Mirrors
14622        // every peer first-collision posture
14623        // (`SupervisorError::DuplicateChildCaixa` reports the second
14624        // collision, `AplicacaoError::MembroDuplicate` reports the
14625        // second, `DepError::DuplicateNome` reports the second).
14626        // Pinning this so a future shortcut that flips to last-
14627        // collision (or non-deterministic) surfaces here.
14628        let d = dep_with_features(&["http", "http", "http"]);
14629        assert!(matches!(
14630            d.validate().unwrap_err(),
14631            DepError::CaracteristicaDuplicate { ref caracteristica, .. } if caracteristica == "http"
14632        ));
14633    }
14634
14635    #[test]
14636    fn validate_per_entry_shape_fires_before_caracteristicas() {
14637        // Per-entry shape precedence: a dep with a malformed `:nome`
14638        // (uppercase) AND duplicate `:caracteristicas` surfaces the
14639        // narrower `NomeInvalid` diagnostic first, not the set-gate
14640        // diagnostic. The `:nome` is the self-locating axis (every
14641        // diagnostic from the caracteristicas gate quotes the
14642        // offending dep's `:nome` to anchor the grep target —
14643        // surfacing the malformed name first keeps that anchor
14644        // valid). Same precedence shape every peer per-entry-shape
14645        // arm establishes against its peer set-gate
14646        // (`validate_deps_per_entry_validate_fires_before_duplicate_in_deps`
14647        // on the cross-entry `:nome` axis).
14648        let d = Dep {
14649            nome: "Caixa-Teia".into(), // uppercase — DNS-1123 violation
14650            versao: "^0.1".into(),
14651            fonte: None,
14652            opcional: false,
14653            caracteristicas: vec!["http".into(), "http".into()],
14654        };
14655        assert!(matches!(
14656            d.validate().unwrap_err(),
14657            DepError::NomeInvalid { .. }
14658        ));
14659    }
14660
14661    // ── per-entry :caracteristicas value-shape gate ──────────────────
14662    //
14663    // Until this gate landed `:caracteristicas` only refused the empty
14664    // string and cross-entry duplicates: a non-empty distinct but
14665    // structurally invalid feature name silently passed validate and the
14666    // failure surfaced at `cargo metadata` time as Cargo's
14667    // `restricted_names::validate_feature_name` parser rejection, far from
14668    // the source `caixa.lisp` with no field naming which `:deps` entry's
14669    // `:caracteristicas` carried the typo. The lifted predicate makes the
14670    // Cargo-feature-name-grammar intersection-floor a substrate-level
14671    // invariant at validate time. Same trajectory as the eight peer
14672    // value-shape predicates each typed surface downstream of a structured
14673    // grammar already follows.
14674
14675    #[test]
14676    fn validate_rejects_caracteristica_with_leading_plus() {
14677        // Fail-before-pass-after pin on the canonical Cargo
14678        // `+<feature>` activation-form-in-feature-name-slot footgun.
14679        // Cargo's `[dependencies.<dep>.features]` list grammar accepts
14680        // `+optional-feature` as an enablement of a previously-disabled
14681        // feature; pasting that activation form into `:caracteristicas`
14682        // (which names the feature itself) silently passed pre-gate and
14683        // failed at `cargo metadata` parse time.
14684        let d = dep_with_features(&["+http"]);
14685        let err = d.validate().unwrap_err();
14686        assert!(
14687            matches!(
14688                err,
14689                DepError::CaracteristicaInvalid { ref nome, ref caracteristica, .. }
14690                    if nome == "caixa-teia" && caracteristica == "+http"
14691            ),
14692            "expected CaracteristicaInvalid, got {err:?}"
14693        );
14694    }
14695
14696    #[test]
14697    fn validate_rejects_caracteristica_with_leading_hyphen() {
14698        // Fail-before-pass-after pin on the leading-hyphen footgun. `-`
14699        // is a legitimate continuation character (kebab-case feature
14700        // names like `runtime-tokio` pass) but Cargo rejects it at the
14701        // start; the structural defect — and its CLI-argument-injection
14702        // adjacency at any downstream Cargo subprocess invocation — is
14703        // closed at validate time, not at `cargo metadata` time.
14704        let d = dep_with_features(&["-json"]);
14705        let err = d.validate().unwrap_err();
14706        assert!(
14707            matches!(
14708                err,
14709                DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "-json"
14710            ),
14711            "expected CaracteristicaInvalid, got {err:?}"
14712        );
14713    }
14714
14715    #[test]
14716    fn validate_rejects_caracteristica_with_leading_dot() {
14717        // Fail-before-pass-after pin on the leading-dot footgun. `.` is
14718        // a legitimate continuation character (version-suffix shapes
14719        // like `feat.v2` pass) but the leading-dot form is the
14720        // canonical dotted-version-suffix-as-feature-name confusion.
14721        let d = dep_with_features(&[".feat"]);
14722        let err = d.validate().unwrap_err();
14723        assert!(matches!(
14724            err,
14725            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == ".feat"
14726        ));
14727    }
14728
14729    #[test]
14730    fn validate_rejects_caracteristica_with_whitespace() {
14731        // Fail-before-pass-after pin on the embedded-whitespace footgun:
14732        // a feature name with a space inside is structurally a multi-
14733        // token blob (the canonical paste-from-doc footgun, or an
14734        // accidental `"http server"` where the author meant
14735        // `"http-server"`).
14736        let d = dep_with_features(&["http feature"]);
14737        let err = d.validate().unwrap_err();
14738        assert!(matches!(
14739            err,
14740            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http feature"
14741        ));
14742    }
14743
14744    #[test]
14745    fn validate_rejects_caracteristica_with_comma() {
14746        // Fail-before-pass-after pin on the embedded-comma footgun:
14747        // the list-separator-belongs-to-the-list-grammar
14748        // miscomprehension where the author writes
14749        // `:caracteristicas ("http,json")` intending two features but
14750        // the `Vec<String>` field consumes the bare token as one entry.
14751        let d = dep_with_features(&["http,json"]);
14752        let err = d.validate().unwrap_err();
14753        assert!(matches!(
14754            err,
14755            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http,json"
14756        ));
14757    }
14758
14759    #[test]
14760    fn validate_rejects_caracteristica_with_slash() {
14761        // Fail-before-pass-after pin on the embedded-slash footgun:
14762        // Cargo's `dep/feat` namespaced-dep syntax applies inside
14763        // `[dependencies.<dep>.features]` list entries that already
14764        // name the parent dep (so the syntax says "enable feature
14765        // `feat` on a transitive dep `dep`"); `:caracteristicas` is
14766        // per-dep already (a sibling slot on the `Dep` itself), so the
14767        // segment separator within an entry must be `-`, `_`, `+`,
14768        // or `.`. The diagnostic remediation points at the canonical
14769        // Cargo namespaced-dep discipline.
14770        let d = dep_with_features(&["http/json"]);
14771        let err = d.validate().unwrap_err();
14772        assert!(matches!(
14773            err,
14774            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http/json"
14775        ));
14776    }
14777
14778    #[test]
14779    fn validate_rejects_caracteristica_with_non_ascii() {
14780        // Fail-before-pass-after pin on the un-percent-encoded non-ASCII
14781        // byte footgun: NFC-vs-NFD normalization across filesystems
14782        // silently rewrites the feature-key, breaking the lacre's
14783        // content-addressing invariant. Pinned at a canonical
14784        // smart-quote-paste shape (`café`) where the raw `é` byte is the
14785        // documented APFS round-trip break.
14786        let d = dep_with_features(&["caf\u{e9}"]);
14787        let err = d.validate().unwrap_err();
14788        assert!(matches!(
14789            err,
14790            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "caf\u{e9}"
14791        ));
14792    }
14793
14794    #[test]
14795    fn validate_rejects_caracteristica_with_control_character() {
14796        // Fail-before-pass-after pin on the embedded-control-character
14797        // footgun: a CR/LF or any 0x00..0x1F / 0x7F byte landing in a
14798        // feature name is the canonical paste-from-multiline-doc
14799        // footgun the predicate's reason wording specifically calls out.
14800        let d = dep_with_features(&["http\njson"]);
14801        let err = d.validate().unwrap_err();
14802        assert!(matches!(err, DepError::CaracteristicaInvalid { .. }));
14803    }
14804
14805    #[test]
14806    fn validate_accepts_canonical_caracteristicas_shapes() {
14807        // Positive control sweep: every canonical Cargo feature name
14808        // shape the pleme-io ecosystem uses must still pass. Mirrors
14809        // the substrate-side `cargo_feature_name_accepts_canonical_forms`
14810        // sweep — drift between either landing site and the predicate's
14811        // accepted set is a build error visible at this pair of tests,
14812        // not a per-renderer "this passed validate but failed at
14813        // cargo metadata time" surprise on the next acceptance.
14814        for s in [
14815            "http",
14816            "json",
14817            "derive",
14818            "serde_json",
14819            "runtime-tokio",
14820            "tokio.full",
14821            "v0.1",
14822            "http+json",
14823            "_internal",
14824            "__private",
14825            "default",
14826            "rt-multi-thread",
14827            "feat.v2",
14828        ] {
14829            let d = dep_with_features(&[s]);
14830            d.validate().unwrap_or_else(|e| {
14831                panic!("canonical Cargo feature name {s:?} must pass validate: {e:?}")
14832            });
14833        }
14834    }
14835
14836    #[test]
14837    fn validate_caracteristica_empty_fires_before_invalid() {
14838        // Cascade precedence pin: an entry list with both an empty
14839        // feature AND an invalid-shape feature surfaces the
14840        // `CaracteristicaEmpty` arm first (the empty value carries no
14841        // self-locating data — `caracteristica: ""` is the diagnostic
14842        // with no way to anchor a grep target — so closing the empty
14843        // axis first preserves the per-entry-shape diagnostic's
14844        // self-locating discipline). Same empty-first cascade every
14845        // peer per-entry shape gate establishes
14846        // (`SupervisorSpec::validate`'s `EmptyChildName` before
14847        // `ChildCaixaInvalid`, `validate_membros`'s `MembroCaixaEmpty`
14848        // before `MembroCaixaInvalid`).
14849        let d = dep_with_features(&["", "+http"]);
14850        assert!(matches!(
14851            d.validate().unwrap_err(),
14852            DepError::CaracteristicaEmpty { .. }
14853        ));
14854    }
14855
14856    #[test]
14857    fn validate_caracteristica_invalid_fires_before_duplicate() {
14858        // Per-entry-shape precedence pin: an entry list with the same
14859        // invalid feature shape declared twice surfaces the
14860        // `CaracteristicaInvalid` diagnostic on the first entry, not
14861        // the `CaracteristicaDuplicate` on the second collision. The
14862        // per-entry shape gate fires before the cross-entry set gate
14863        // — same precedence shape every peer two-arm-plus-set gate
14864        // establishes (`SupervisorSpec::validate`'s
14865        // `ChildCaixaInvalid` before `DuplicateChildCaixa`,
14866        // `validate_membros`'s `MembroCaixaInvalid` before
14867        // `MembroDuplicate`, `Dep::validate`'s `NomeInvalid` before
14868        // cross-list `DuplicateNome`).
14869        let d = dep_with_features(&["+http", "+http"]);
14870        assert!(matches!(
14871            d.validate().unwrap_err(),
14872            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "+http"
14873        ));
14874    }
14875
14876    #[test]
14877    fn validate_rejects_caracteristica_at_65_byte_boundary() {
14878        // Boundary pin on the 64-byte cap — both the boundary-accepting
14879        // case and the boundary-exceeding case in one place, so a
14880        // future cap shift surfaces both arms simultaneously, mirroring
14881        // the peer `cargo_feature_name_rejects_at_65_byte_boundary`
14882        // predicate-level pin at the dep-axis landing site.
14883        let max_ok = "a".repeat(64);
14884        dep_with_features(&[&max_ok])
14885            .validate()
14886            .unwrap_or_else(|e| panic!("64-byte feature name must pass: {e:?}"));
14887        let too_long = "a".repeat(65);
14888        let d = dep_with_features(&[&too_long]);
14889        assert!(matches!(
14890            d.validate().unwrap_err(),
14891            DepError::CaracteristicaInvalid { .. }
14892        ));
14893    }
14894
14895    // ── self-dep cross-slot gate ─────────────────────────────────────
14896
14897    #[test]
14898    fn validate_no_self_dep_rejects_self_in_deps() {
14899        // A caixa whose `:deps` lists its own `:nome` is a one-node
14900        // cycle in the lacre closure's dep-graph traversal — rejected,
14901        // naming the parent and the offending list tag.
14902        let deps = vec![
14903            Dep::simple("caixa-teia", "^0.1"),
14904            Dep::simple("orquestra", "^0.1"),
14905        ];
14906        let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
14907        assert!(
14908            matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14909            "got {err:?}"
14910        );
14911    }
14912
14913    #[test]
14914    fn validate_no_self_dep_rejects_self_in_deps_dev() {
14915        // Same gate on the `:deps-dev` axis — neither dep list is a
14916        // second-class citizen on the self-edge invariant.
14917        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14918        let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
14919        assert!(
14920            matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14921            "got {err:?}"
14922        );
14923    }
14924
14925    #[test]
14926    fn validate_no_self_dep_deps_fires_before_deps_dev() {
14927        // Walk order pin: a caixa that self-references on both lists
14928        // surfaces the `:deps` arm first — the load-bearing axis the
14929        // lacre closure resolves at every build. Mirrors the canonical
14930        // [`Caixa::validate_deps`] cascade (`:deps` → `:deps-dev`).
14931        let deps = vec![Dep::simple("orquestra", "^0.1")];
14932        let deps_dev = vec![Dep::simple("orquestra", "^0.2")];
14933        let err = validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap_err();
14934        assert!(
14935            matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14936            "got {err:?}"
14937        );
14938    }
14939
14940    #[test]
14941    fn validate_no_self_dep_accepts_distinct_names() {
14942        // Positive control: every dep names a distinct caixa. The
14943        // canonical author surface — peer of
14944        // [`validate_no_self_supervision_accepts_distinct_children`].
14945        let deps = vec![
14946            Dep::simple("caixa-teia", "^0.1"),
14947            Dep::simple("caixa-arch", "^0.1"),
14948        ];
14949        let deps_dev = vec![Dep::simple("caixa-test", "^0.1")];
14950        validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap();
14951    }
14952
14953    #[test]
14954    fn validate_no_self_dep_empty_lists_pass() {
14955        // A caixa with no declared deps has nothing to self-reference —
14956        // the gate is vacuously satisfied. Peer of
14957        // [`validate_no_self_supervision_empty_children_is_ok`].
14958        validate_no_self_dep(&[], &[], "orquestra").unwrap();
14959    }
14960
14961    #[test]
14962    fn validate_no_self_dep_diagnostic_carries_offending_list_and_nome() {
14963        // Diagnostic-shape pin (peer with
14964        // [`validate_no_self_supervision`]'s diagnostic): the error's
14965        // Display surfaces both the offending list tag and the
14966        // parent's `:nome` verbatim, so the author can grep their
14967        // caixa.lisp for the offending block in one edit. Names
14968        // `:bibliotecas` / `:exe` / `:servicos` as the corrective
14969        // surface — every legitimate "I want to use code from this
14970        // caixa" intent routes through one of those three slots.
14971        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14972        let rendered = validate_no_self_dep(&[], &deps_dev, "orquestra")
14973            .unwrap_err()
14974            .to_string();
14975        assert!(
14976            rendered.contains(crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14977            "diagnostic must name the offending list tag: {rendered}",
14978        );
14979        assert!(
14980            rendered.contains("orquestra"),
14981            "diagnostic must quote the parent caixa name: {rendered}",
14982        );
14983        assert!(
14984            rendered.contains(":bibliotecas"),
14985            "diagnostic must point at the corrective code-surface slot: {rendered}",
14986        );
14987    }
14988
14989    #[test]
14990    fn validate_no_self_dep_accepts_coincidental_substring_match() {
14991        // Identity is exact-string equality, not substring — a dep
14992        // named `"orquestra-helper"` is a distinct caixa even when the
14993        // parent is `"orquestra"`. Pin the exact-match discipline so a
14994        // future relaxation that uses `contains` surfaces here, peer
14995        // with the supervision-tree and Aplicacao-membership gates
14996        // which all use exact-string equality on the typed identity.
14997        let deps = vec![Dep::simple("orquestra-helper", "^0.1")];
14998        validate_no_self_dep(&deps, &[], "orquestra").unwrap();
14999    }
15000
15001    // ── drift-detection: DEP_AUTHOR_KEY_{DEPS,DEPS_DEV} pin ─────────────
15002
15003    #[test]
15004    fn dep_author_key_consts_pin_canonical_kebab_case_labels() {
15005        // Scalar-value pin: the two author-facing kebab-case labels the
15006        // `(defcaixa … :deps ((…)) :deps-dev ((…)))` surface admits on
15007        // the two-list dep-graph slot axis, one arm per typed slot.
15008        // Mirrors the peer scalar-value pin the sibling
15009        // [`crate::M2_AUTHOR_KEY_LIMITS`] /
15010        // [`crate::M2_AUTHOR_KEY_BEHAVIOR`] /
15011        // [`crate::M2_AUTHOR_KEY_UPGRADE_FROM`] (f49c8b0) M2 top-level
15012        // author-labels, [`crate::M3_AUTHOR_KEY_MEMBROS`] etc.
15013        // (882f498) M3 top-level author-labels, and
15014        // [`crate::SUPERVISOR_AUTHOR_KEY_ESTRATEGIA`] etc. (be40492)
15015        // Supervisor top-level author-labels carry, so every kind-scoped
15016        // typed-slot-family axis routes through one canonical per-arm
15017        // declaration.
15018        //
15019        // A future rebrand (`:deps` → `:dependencies` matching Cargo's
15020        // verbatim key, `:deps-dev` → `:dev-dependencies` matching the
15021        // same, `:deps` / `:deps-dev` → `:runtime-deps` / `:dev-deps`
15022        // for symmetry) lands as an edit to exactly one const, and
15023        // every consumer that reaches for the label picks it up at
15024        // build time rather than at runtime as a downstream mismatch on
15025        // a `DepError::DuplicateNome { list: … }` diagnostic far from
15026        // the rename's commit.
15027        assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS, ":deps");
15028        assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS_DEV, ":deps-dev");
15029    }
15030
15031    #[test]
15032    fn dep_author_key_consts_are_pairwise_distinct() {
15033        // Distinct-labels pin: the two `:deps` / `:deps-dev` labels
15034        // must not collapse onto one byte-string. A future copy-paste
15035        // slip that renamed both consts to the same value (or a rebrand
15036        // that dropped the `-dev` suffix from one but not the other)
15037        // would leave every `DepError::DuplicateNome { list: … }`
15038        // diagnostic naming an unattributable list — the linter would
15039        // route the author to the wrong caixa.lisp block, or the
15040        // cross-list precedence gate
15041        // (`validate_deps_duplicate_in_deps_fires_before_duplicate_in_deps_dev`)
15042        // would surface a `:deps`-tagged diagnostic on a `:deps-dev`
15043        // duplicate. Peer of the sibling
15044        // `m2_author_key_consts_are_pairwise_distinct`-shape gates the
15045        // other top-level kind-scoped slot-family axes carry
15046        // (implicitly held by their different byte-values today).
15047        assert_ne!(
15048            crate::render::DEP_AUTHOR_KEY_DEPS,
15049            crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15050            "DEP_AUTHOR_KEY_{{DEPS,DEPS_DEV}} consts must be pairwise-distinct \
15051             so a `DepError::DuplicateNome {{ list: … }}` diagnostic \
15052             self-locates the offending block in the author's caixa.lisp",
15053        );
15054    }
15055
15056    #[test]
15057    fn validate_no_self_dep_routes_through_lifted_dep_author_key_consts() {
15058        // Production-through-const pin: the two per-arm list tags
15059        // [`validate_no_self_dep`] threads onto the `list:` field of a
15060        // returned [`DepError::DepIsSelf`] route through the lifted
15061        // [`crate::DEP_AUTHOR_KEY_DEPS`] /
15062        // [`crate::DEP_AUTHOR_KEY_DEPS_DEV`] consts. A future drift at
15063        // the walker (a rename that reaches one arm but not the const,
15064        // or vice versa) surfaces here at build time rather than at
15065        // runtime as a `feira lint` diagnostic naming the wrong list
15066        // tag. Mirror of the peer
15067        // [`crate::Caixa::declared_servico_slots`] production tagger
15068        // pin (f49c8b0) on the sibling M2 top-level slot axis, extended
15069        // onto the two-list dep-graph gate.
15070        let deps = vec![Dep::simple("orquestra", "^0.1")];
15071        let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15072        let DepError::DepIsSelf { list, .. } = err else {
15073            panic!("expected DepIsSelf from :deps walk");
15074        };
15075        assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS);
15076
15077        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15078        let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15079        let DepError::DepIsSelf { list, .. } = err else {
15080            panic!("expected DepIsSelf from :deps-dev walk");
15081        };
15082        assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS_DEV);
15083    }
15084
15085    // ── Dep::nome accessor pins ───────────────────────────────────────
15086    //
15087    // Three coherence pins on the lifted `Dep::nome` accessor: byte-equal
15088    // projection over the plain-shorthand / explicit-git / explicit-path
15089    // fixture triad the [`Dep`] docstring lists (so the accessor's
15090    // accept-set is exercised across every author-surface `:fonte`
15091    // shape); by-borrow pointer identity so the projection stays
15092    // zero-copy at every consumer site; and validate-composition through
15093    // the [`validate_no_self_dep`] cross-slot gate reading its
15094    // parent-name equality check through the lifted accessor rather than
15095    // the raw field.
15096
15097    #[test]
15098    fn dep_nome_returns_declared_nome_across_fonte_shapes() {
15099        // Plain-shorthand form (`:fonte None`).
15100        assert_eq!(Dep::simple("caixa-teia", "^0.1").nome(), "caixa-teia");
15101        // Explicit git-source form with a tag pin — same accessor path.
15102        assert_eq!(
15103            Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").nome(),
15104            "caixa-teia",
15105        );
15106        // Explicit path-source form.
15107        assert_eq!(
15108            Dep {
15109                nome: "caixa-teia".to_string(),
15110                versao: "0.1.0".to_string(),
15111                fonte: Some(DepSource::Path {
15112                    caminho: "../caixa-teia".to_string(),
15113                }),
15114                opcional: false,
15115                caracteristicas: Vec::new(),
15116            }
15117            .nome(),
15118            "caixa-teia",
15119        );
15120        // The empty-string `:nome` sentinel (which [`Dep::validate`]
15121        // refuses through the [`DepError::NomeEmpty`] arm) still round-
15122        // trips as an empty `&str` through the accessor — the accessor is
15123        // a projection, not a gate; the gate is [`Dep::validate`].
15124        assert_eq!(Dep::simple("", "^0.1").nome(), "");
15125    }
15126
15127    #[test]
15128    fn dep_nome_is_by_borrow_pointer_identity() {
15129        // Zero-copy pin: the accessor must borrow into the field's own
15130        // storage, not clone. If a future rewrite regresses to
15131        // `self.nome.clone().leak()` or an owned-buffer shape, the two
15132        // pointers diverge and this pin fails at build time.
15133        let d = Dep::simple("caixa-teia", "^0.1");
15134        assert!(std::ptr::eq(d.nome().as_ptr(), d.nome.as_ptr()));
15135    }
15136
15137    // ── Dep::versao_requirement accessor pins ─────────────────────────
15138    //
15139    // Three coherence pins on the lifted `Dep::versao_requirement`
15140    // accessor: byte-equal projection over the plain-shorthand /
15141    // explicit-git / explicit-path fixture triad the [`Dep`] docstring
15142    // lists plus the empty-sentinel that round-trips as `""` (the accessor
15143    // is a projection, not a gate; the gate is [`Dep::validate`]); by-
15144    // borrow pointer identity so the projection stays zero-copy at every
15145    // consumer site; and validate-composition through the
15146    // [`crate::render::require_valid_versao_requirement`] cascade reading
15147    // its requirement-shape check through the lifted accessor rather than
15148    // the raw field.
15149    #[test]
15150    fn dep_versao_requirement_returns_declared_versao_across_fonte_shapes() {
15151        // Plain-shorthand form (`:fonte None`).
15152        assert_eq!(
15153            Dep::simple("caixa-teia", "^0.1").versao_requirement(),
15154            "^0.1",
15155        );
15156        // Explicit git-source form with a tag pin — same accessor path.
15157        assert_eq!(
15158            Dep::git(
15159                "caixa-teia",
15160                "~0.1.2",
15161                "github:pleme-io/caixa-teia",
15162                "v0.1.0"
15163            )
15164            .versao_requirement(),
15165            "~0.1.2",
15166        );
15167        // Explicit path-source form.
15168        assert_eq!(
15169            Dep {
15170                nome: "caixa-teia".to_string(),
15171                versao: "0.1.0".to_string(),
15172                fonte: Some(DepSource::Path {
15173                    caminho: "../caixa-teia".to_string(),
15174                }),
15175                opcional: false,
15176                caracteristicas: Vec::new(),
15177            }
15178            .versao_requirement(),
15179            "0.1.0",
15180        );
15181        // The wildcard requirement (`"*"`) — the shorthand
15182        // `parse_requirement` accepts as `VersionReq::STAR` — round-trips
15183        // verbatim through the accessor as `"*"`, same byte-shape the
15184        // author wrote.
15185        assert_eq!(Dep::simple("caixa-teia", "*").versao_requirement(), "*");
15186        // The empty-string `:versao` sentinel (which [`Dep::validate`]
15187        // refuses through the [`DepError::VersaoEmpty`] arm) still round-
15188        // trips as an empty `&str` through the accessor — the accessor is
15189        // a projection, not a gate; the gate is [`Dep::validate`]. Peer
15190        // of the sibling [`Dep::nome`] empty-sentinel round-trip pin.
15191        assert_eq!(Dep::simple("caixa-teia", "").versao_requirement(), "");
15192    }
15193
15194    #[test]
15195    fn dep_versao_requirement_is_by_borrow_pointer_identity() {
15196        // Zero-copy pin: the accessor must borrow into the field's own
15197        // storage, not clone. If a future rewrite regresses to
15198        // `self.versao.clone().leak()` or an owned-buffer shape, the two
15199        // pointers diverge and this pin fails at build time. Peer of the
15200        // sibling [`Dep::nome`] pointer-identity pin — same by-borrow
15201        // discipline extended onto the requirement-carrying axis.
15202        let d = Dep::simple("caixa-teia", "^0.1");
15203        assert!(std::ptr::eq(
15204            d.versao_requirement().as_ptr(),
15205            d.versao.as_ptr(),
15206        ));
15207    }
15208
15209    #[test]
15210    fn dep_validate_reads_requirement_through_accessor() {
15211        // Composition pin: the [`Dep::validate`]
15212        // [`crate::render::require_valid_versao_requirement`] cascade
15213        // consumes the requirement string through the lifted accessor —
15214        // both the requirement-gate input and the
15215        // [`DepError::VersaoInvalid`] error-body carrier route through
15216        // `self.versao_requirement()`. A valid requirement passes
15217        // (positive control); a malformed-but-non-empty requirement fails
15218        // and the diagnostic quotes the offending byte-string verbatim
15219        // (same shape the accessor projects), so a future regression that
15220        // detoured the requirement carrier through a different byte-
15221        // string (say the parsed `VersionReq`'s `Display`, or a
15222        // normalized rewrite) would surface here at build time. The
15223        // empty-`:versao` arm fires the [`DepError::VersaoEmpty`] variant
15224        // ahead of the parse arm, pinning the empty-first cascade the
15225        // accessor's `""` sentinel round-trip acknowledges.
15226        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15227        let err = Dep::simple("caixa-teia", "v0.1").validate().unwrap_err();
15228        assert!(
15229            matches!(
15230                &err,
15231                DepError::VersaoInvalid {
15232                    nome,
15233                    versao,
15234                    ..
15235                } if nome == "caixa-teia" && versao == "v0.1",
15236            ),
15237            "expected VersaoInvalid quoting the accessor-projected requirement, got {err:?}",
15238        );
15239        let err = Dep::simple("caixa-teia", "").validate().unwrap_err();
15240        assert!(
15241            matches!(
15242                &err,
15243                DepError::VersaoEmpty { nome } if nome == "caixa-teia",
15244            ),
15245            "expected VersaoEmpty from the empty-first arm, got {err:?}",
15246        );
15247    }
15248
15249    // ── Dep::fonte accessor pins ──────────────────────────────────────
15250    //
15251    // Three coherence pins on the lifted `Dep::fonte` accessor: byte-
15252    // equal projection over the plain-shorthand (`:fonte None`) /
15253    // explicit-git-tag / explicit-path fixture triad the [`Dep`]
15254    // docstring lists (so the accessor's accept-set is exercised across
15255    // every author-surface `:fonte` shape and both `DepSource` variants);
15256    // pointer identity so the borrowed reference points into the field's
15257    // own `Option<DepSource>` storage (not a cloned side-buffer); and
15258    // validate-composition through the [`Dep::validate`] gate reading
15259    // its per-`:fonte` [`DepSource::validate`] delegation through the
15260    // lifted accessor rather than the raw `if let Some(ref fonte) =
15261    // self.fonte` bracket.
15262
15263    #[test]
15264    fn dep_fonte_returns_declared_source_across_shapes() {
15265        // Plain-shorthand form — `:fonte` omitted, accessor projects
15266        // the `None` partition the resolver-side default-fill treats
15267        // as "resolve through `github:<default-org>/<nome>`".
15268        assert!(Dep::simple("caixa-teia", "^0.1").fonte().is_none());
15269        // Explicit git-source form with a tag pin — same accessor path.
15270        let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15271        match git.fonte() {
15272            Some(DepSource::Git {
15273                repo,
15274                tag,
15275                rev,
15276                branch,
15277            }) => {
15278                assert_eq!(repo, "github:pleme-io/caixa-teia");
15279                assert_eq!(tag.as_deref(), Some("v0.1.0"));
15280                assert!(rev.is_none());
15281                assert!(branch.is_none());
15282            }
15283            other => panic!("expected explicit git :fonte, got {other:?}"),
15284        }
15285        // Explicit path-source form — the dev-only local-filesystem
15286        // arm the [`Dep`] docstring's third fixture carries.
15287        let path = Dep {
15288            nome: "caixa-teia".to_string(),
15289            versao: "0.1.0".to_string(),
15290            fonte: Some(DepSource::Path {
15291                caminho: "../caixa-teia".to_string(),
15292            }),
15293            opcional: false,
15294            caracteristicas: Vec::new(),
15295        };
15296        match path.fonte() {
15297            Some(DepSource::Path { caminho }) => {
15298                assert_eq!(caminho, "../caixa-teia");
15299            }
15300            other => panic!("expected explicit path :fonte, got {other:?}"),
15301        }
15302    }
15303
15304    #[test]
15305    fn dep_fonte_is_by_borrow_pointer_identity() {
15306        // Zero-copy pin: the accessor must borrow into the field's own
15307        // `Option<DepSource>` storage, not clone into a side buffer. If
15308        // a future rewrite regresses to `self.fonte.clone()` or an
15309        // owned-buffer shape, the two pointers diverge and this pin
15310        // fails at build time. Peer of the sibling per-`Dep` [`Dep::nome`]
15311        // (eba2cde) / [`Dep::versao_requirement`] (05529b1) pointer-
15312        // identity pins — same by-borrow discipline extended onto the
15313        // outer-`Dep` `Option<&Composite>` composite-reference axis.
15314        let d = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15315        let accessed = d.fonte().expect("git :fonte present") as *const DepSource;
15316        let raw = d.fonte.as_ref().expect("git :fonte present") as *const DepSource;
15317        assert!(std::ptr::eq(accessed, raw));
15318    }
15319
15320    #[test]
15321    fn dep_validate_reads_fonte_through_accessor() {
15322        // Composition pin: [`Dep::validate`]'s per-`:fonte`
15323        // [`DepSource::validate`] delegation consumes the typed slot
15324        // through the lifted accessor — an author-omitted `:fonte`
15325        // still passes the outer gate (positive control), an explicit
15326        // well-formed git source with exactly one pin passes, and a
15327        // malformed git source (empty `:repo`) surfaces the
15328        // [`DepError::FonteRepoEmpty`] variant quoting the offending
15329        // dep's `:nome` verbatim so a future regression that detoured
15330        // the `:fonte` delegation through a different path (say a
15331        // per-scope override projector) would surface here at build
15332        // time. Peer of the sibling
15333        // `dep_validate_reads_requirement_through_accessor` composition
15334        // pin on the `:versao` axis.
15335        // Positive control 1: no `:fonte` at all.
15336        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15337        // Positive control 2: well-formed git source.
15338        Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15339            .validate()
15340            .unwrap();
15341        // Negative control: empty `:repo` — the accessor still returns
15342        // `Some(&DepSource::Git { repo: "", … })` and the delegated
15343        // `DepSource::validate` gate raises the typed carrier.
15344        let bad = Dep {
15345            nome: "caixa-teia".to_string(),
15346            versao: "^0.1".to_string(),
15347            fonte: Some(DepSource::Git {
15348                repo: String::new(),
15349                tag: Some("v0.1.0".to_string()),
15350                rev: None,
15351                branch: None,
15352            }),
15353            opcional: false,
15354            caracteristicas: Vec::new(),
15355        };
15356        let err = bad.validate().unwrap_err();
15357        assert!(
15358            matches!(
15359                &err,
15360                DepError::FonteRepoEmpty { nome } if nome == "caixa-teia",
15361            ),
15362            "expected FonteRepoEmpty from the accessor-routed :fonte gate, got {err:?}",
15363        );
15364    }
15365
15366    #[test]
15367    fn validate_no_self_dep_reads_parent_equality_through_accessor() {
15368        // Composition pin: the cross-slot [`validate_no_self_dep`] gate
15369        // rejects a `:deps` entry whose `:nome` equals the parent caixa's
15370        // own `:nome` through the lifted accessor rather than the raw
15371        // field. Fails-before-passes-after: with the accessor lifted the
15372        // gate reads its equality check through `dep.nome() ==
15373        // parent_nome` on both the `:deps` and `:deps-dev` traversals, so
15374        // the diagnostic still names the offending list tag as expected.
15375        let deps = vec![Dep::simple("orquestra", "^0.1")];
15376        let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15377        assert!(matches!(
15378            err,
15379            DepError::DepIsSelf {
15380                ref nome,
15381                list,
15382            } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS,
15383        ));
15384        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15385        let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15386        assert!(matches!(
15387            err,
15388            DepError::DepIsSelf {
15389                ref nome,
15390                list,
15391            } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15392        ));
15393        // A non-matching `:nome` passes through the accessor gate.
15394        let deps = vec![Dep::simple("caixa-teia", "^0.1")];
15395        validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15396    }
15397
15398    // ── Dep::caracteristicas accessor pins ────────────────────────────
15399    //
15400    // Three coherence pins on the lifted `Dep::caracteristicas` accessor:
15401    // byte-equal projection over the default-empty / single-entry /
15402    // multi-entry fixture triad (so the accessor's accept-set is
15403    // exercised across every author-surface `:caracteristicas` shape,
15404    // matching the peer sibling family's fixture-triad discipline); by-
15405    // borrow pointer identity so the projection stays zero-copy at every
15406    // consumer site; and validate-composition through the
15407    // [`Dep::validate_caracteristicas`] gate reading its per-entry
15408    // linear walk through the lifted accessor rather than the raw
15409    // `for c in &self.caracteristicas` bracket.
15410
15411    #[test]
15412    fn dep_caracteristicas_returns_declared_features_across_shapes() {
15413        // Default-empty form — the [`Dep::simple`] constructor's
15414        // `Vec::new()` fill; the accessor projects the empty slice
15415        // verbatim (no `None` collapse).
15416        assert!(
15417            Dep::simple("caixa-teia", "^0.1")
15418                .caracteristicas()
15419                .is_empty(),
15420        );
15421        // Single-entry form — the canonical Cargo-shaped one-feature
15422        // enable ([`crate::render::is_cargo_feature_name`] accepts the
15423        // `"http"` byte-string as a valid feature name).
15424        let one = Dep {
15425            nome: "caixa-teia".to_string(),
15426            versao: "^0.1".to_string(),
15427            fonte: None,
15428            opcional: false,
15429            caracteristicas: vec!["http".to_string()],
15430        };
15431        assert_eq!(one.caracteristicas(), &["http".to_string()]);
15432        // Multi-entry form — the substrate's set-shaped multi-feature
15433        // enable, exercising the accessor over a length-two slice with
15434        // no duplicate collapse.
15435        let two = Dep {
15436            nome: "caixa-teia".to_string(),
15437            versao: "^0.1".to_string(),
15438            fonte: None,
15439            opcional: false,
15440            caracteristicas: vec!["http".to_string(), "json".to_string()],
15441        };
15442        assert_eq!(
15443            two.caracteristicas(),
15444            &["http".to_string(), "json".to_string()],
15445        );
15446    }
15447
15448    #[test]
15449    fn dep_caracteristicas_is_by_borrow_pointer_identity() {
15450        // Zero-copy pin: the accessor must borrow into the field's own
15451        // `Vec<String>` storage, not clone into a side buffer. If a
15452        // future rewrite regresses to `self.caracteristicas.clone()` or
15453        // an owned-buffer shape, the two pointers diverge and this pin
15454        // fails at build time. Peer of the sibling per-`Dep`
15455        // [`Dep::nome`] (eba2cde) / [`Dep::versao_requirement`] (05529b1)
15456        // / [`Dep::fonte`] (d65d1bf) pointer-identity pins — same by-
15457        // borrow discipline extended onto the outer-`Dep` `&[String]`
15458        // slice-projection axis.
15459        let d = Dep {
15460            nome: "caixa-teia".to_string(),
15461            versao: "^0.1".to_string(),
15462            fonte: None,
15463            opcional: false,
15464            caracteristicas: vec!["http".to_string(), "json".to_string()],
15465        };
15466        assert!(std::ptr::eq(
15467            d.caracteristicas().as_ptr(),
15468            d.caracteristicas.as_ptr(),
15469        ));
15470    }
15471
15472    #[test]
15473    fn dep_validate_reads_caracteristicas_through_accessor() {
15474        // Composition pin: [`Dep::validate_caracteristicas`]'s per-entry
15475        // linear walk consumes the feature-toggle list through the
15476        // lifted accessor — a well-formed `:caracteristicas` set passes
15477        // (positive control), an empty-string entry surfaces the
15478        // [`DepError::CaracteristicaEmpty`] variant quoting the offending
15479        // `Dep::nome`, and a within-list duplicate surfaces the
15480        // [`DepError::CaracteristicaDuplicate`] variant so a future
15481        // regression that detoured the walk through a different byte-
15482        // string list (say a per-scope override projector) would surface
15483        // here at build time. Peer of the sibling
15484        // `dep_validate_reads_fonte_through_accessor` /
15485        // `dep_validate_reads_requirement_through_accessor` composition
15486        // pins on the `:fonte` / `:versao` axes.
15487        // Positive control: two distinct well-formed feature names pass.
15488        Dep {
15489            nome: "caixa-teia".to_string(),
15490            versao: "^0.1".to_string(),
15491            fonte: None,
15492            opcional: false,
15493            caracteristicas: vec!["http".to_string(), "json".to_string()],
15494        }
15495        .validate()
15496        .unwrap();
15497        // Negative control 1: empty-string feature-name entry — the
15498        // accessor still returns `&[""]` and the walk raises the typed
15499        // empty-first carrier.
15500        let err = Dep {
15501            nome: "caixa-teia".to_string(),
15502            versao: "^0.1".to_string(),
15503            fonte: None,
15504            opcional: false,
15505            caracteristicas: vec![String::new()],
15506        }
15507        .validate()
15508        .unwrap_err();
15509        assert!(
15510            matches!(
15511                &err,
15512                DepError::CaracteristicaEmpty { nome } if nome == "caixa-teia",
15513            ),
15514            "expected CaracteristicaEmpty from the accessor-routed walk, got {err:?}",
15515        );
15516        // Negative control 2: within-list duplicate — the accessor's
15517        // slice view carries both entries, and the walk's dedup arm
15518        // raises the typed duplicate carrier quoting the offending
15519        // feature name verbatim.
15520        let err = Dep {
15521            nome: "caixa-teia".to_string(),
15522            versao: "^0.1".to_string(),
15523            fonte: None,
15524            opcional: false,
15525            caracteristicas: vec!["http".to_string(), "http".to_string()],
15526        }
15527        .validate()
15528        .unwrap_err();
15529        assert!(
15530            matches!(
15531                &err,
15532                DepError::CaracteristicaDuplicate {
15533                    nome,
15534                    caracteristica,
15535                } if nome == "caixa-teia" && caracteristica == "http",
15536            ),
15537            "expected CaracteristicaDuplicate from the accessor-routed dedup, got {err:?}",
15538        );
15539    }
15540
15541    // ── Dep::opcional accessor pins ───────────────────────────────────
15542    //
15543    // Two coherence pins on the lifted `Dep::opcional` accessor: byte-
15544    // equal projection over the default-`false` / explicit-`true`
15545    // fixture pair across the plain-shorthand (`:fonte None`) / explicit-
15546    // git-tag / explicit-path fixture triad the [`Dep`] docstring lists,
15547    // exercising the accessor's accept-set over every author-surface
15548    // `:fonte` shape × every author-surface `:opcional` shape; and by-
15549    // `Copy` idempotency so the projection stays value-return (no
15550    // silent detour to a fresh `&bool` borrow that would introduce a
15551    // lifetime on the return type the plain-`Copy`-scalar axis's `bool`
15552    // shape elides). No composition pin — `:opcional` does not
15553    // participate in [`Dep::validate`] (an opcional dep with any bool
15554    // value is validate-accepted; the missing-source arm is a resolver-
15555    // side runtime dispatch, not a build-time refusal), so the axis
15556    // reduces to the value-shape + `Copy` pin pair the peer
15557    // [`crate::Caixa::max_restarts`] / [`crate::Caixa::estrategia`]
15558    // outer-`Option<Copy>` accessor pins already carry.
15559
15560    #[test]
15561    fn dep_opcional_returns_declared_opcional_across_fonte_shapes() {
15562        // Default-`false` form via the [`Dep::simple`] constructor —
15563        // the accessor projects the `false` bit the default-fill sets.
15564        assert!(!Dep::simple("caixa-teia", "^0.1").opcional());
15565        // Default-`false` form via the [`Dep::git`] constructor — same
15566        // default fill; the accessor projects `false` regardless of the
15567        // `:fonte` arm.
15568        assert!(!Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").opcional(),);
15569        // Explicit-`true` form × plain-shorthand `:fonte` — the
15570        // canonical author-surface "this dep may be missing" shape.
15571        let plain_true = Dep {
15572            nome: "caixa-teia".to_string(),
15573            versao: "^0.1".to_string(),
15574            fonte: None,
15575            opcional: true,
15576            caracteristicas: Vec::new(),
15577        };
15578        assert!(plain_true.opcional());
15579        // Explicit-`true` form × explicit git-source — the accessor
15580        // projects the bit verbatim regardless of the `:fonte` arm.
15581        let git_true = Dep {
15582            nome: "caixa-teia".to_string(),
15583            versao: "^0.1".to_string(),
15584            fonte: Some(DepSource::Git {
15585                repo: "github:pleme-io/caixa-teia".to_string(),
15586                tag: Some("v0.1.0".to_string()),
15587                rev: None,
15588                branch: None,
15589            }),
15590            opcional: true,
15591            caracteristicas: Vec::new(),
15592        };
15593        assert!(git_true.opcional());
15594        // Explicit-`true` form × explicit path-source — the dev-only
15595        // local-filesystem arm the [`Dep`] docstring's third fixture
15596        // carries.
15597        let path_true = Dep {
15598            nome: "caixa-teia".to_string(),
15599            versao: "0.1.0".to_string(),
15600            fonte: Some(DepSource::Path {
15601                caminho: "../caixa-teia".to_string(),
15602            }),
15603            opcional: true,
15604            caracteristicas: Vec::new(),
15605        };
15606        assert!(path_true.opcional());
15607    }
15608
15609    #[test]
15610    fn dep_opcional_projects_bool_by_copy() {
15611        // The by-`Copy` pin: [`Dep::opcional`] returns `bool` by value
15612        // (`bool: Copy`) — the accessor does not borrow `&self` past
15613        // the call (no lifetime on the return type), and calling the
15614        // accessor twice on the same [`Dep`] must yield discriminant-
15615        // equal values (idempotent, no side effects on `&self`). Peer
15616        // of the sibling outer-`Caixa` `Option<Copy>` by-`Copy`
15617        // `max_restarts_projects_option_by_copy` (eba5211) /
15618        // `estrategia_projects_option_by_copy` (ed04d3c) pins on the
15619        // outer-`Caixa` altitude — extended here to the outer-`Dep`
15620        // altitude's plain-`Copy` `bool` axis. The `Copy` discipline
15621        // replaces the pointer-equality claim the sibling per-`Dep`
15622        // by-borrow pins (`dep_nome_is_by_borrow_pointer_identity`
15623        // eba2cde, `dep_versao_requirement_is_by_borrow_pointer_identity`
15624        // 05529b1, `dep_fonte_is_by_borrow_pointer_identity` d65d1bf,
15625        // `dep_caracteristicas_is_by_borrow_pointer_identity` 9197944)
15626        // carry (a fresh `Copy` of a `Copy` discriminant is definitionally
15627        // the same discriminant, so the axis reduces to discriminant
15628        // equality).
15629        //
15630        // Pins against a future silent detour that returned a fresh
15631        // `&bool` reference (which would type-check but silently
15632        // introduce a borrow of `&self` past the call, collapsing the
15633        // load-bearing "no lifetime on the return type" `Copy`
15634        // projection the plain-`Copy`-scalar axis's `bool` shape
15635        // carries) or a stale-read side effect that flipped the outer
15636        // discriminant on successive calls.
15637        for opcional in [false, true] {
15638            let d = Dep {
15639                nome: "caixa-teia".to_string(),
15640                versao: "^0.1".to_string(),
15641                fonte: None,
15642                opcional,
15643                caracteristicas: Vec::new(),
15644            };
15645            let first = d.opcional();
15646            let second = d.opcional();
15647            assert_eq!(
15648                first, second,
15649                "Dep::opcional must be idempotent — two successive calls \
15650                 on the same &self must return the same bool",
15651            );
15652            assert_eq!(
15653                first, opcional,
15654                "Dep::opcional must return :opcional verbatim by Copy — \
15655                 got {first}, expected {opcional}",
15656            );
15657            assert_eq!(
15658                d.opcional(),
15659                d.opcional,
15660                "Dep::opcional accessor and self.opcional field access \
15661                 must byte-equal — a bit-flip drift would silently split \
15662                 the paired resolver-side drop-vs-error dispatch from \
15663                 the storage-side default-fill the [`Dep::simple`] / \
15664                 [`Dep::git`] constructor pair carries",
15665            );
15666        }
15667    }
15668
15669    // ── DepSource::sole_pin — sole-set git-pin accessor ─────────────────
15670
15671    #[test]
15672    fn sole_pin_returns_none_for_path_source() {
15673        // A path source carries no git-ref, so `sole_pin()` returns
15674        // `None` structurally — the sibling arm every git-fetching
15675        // consumer partitions off before reaching for a git-ref. Pins
15676        // the Path-arm branch of the accessor against a future silent
15677        // detour that treats a `Self::Path` as an unpinned-git source
15678        // and returns the wrong "no pin" signal (e.g. the empty string,
15679        // or a hard-coded `Some("HEAD")` matching the caixa-crd
15680        // path-arm `git_ref` fill).
15681        let s = DepSource::Path {
15682            caminho: "../local-caixa".to_string(),
15683        };
15684        assert_eq!(s.sole_pin(), None);
15685    }
15686
15687    #[test]
15688    fn sole_pin_returns_none_for_unpinned_git_source() {
15689        // The [`DepSource::default_github`] shorthand shape carries no
15690        // pin — every `tag`/`rev`/`branch` is `None`, and `sole_pin()`
15691        // returns `None`. This is the shape caixa-resolver's `fetch_dep`
15692        // materializes when the author omits `:fonte` entirely, then
15693        // hands to `fetch_git` which raises `ResolveError::MissingPin`
15694        // on the `None` arm — the accessor's return matches the arm
15695        // the resolver's diagnostic keys off.
15696        let s = DepSource::default_github("pleme-io", "caixa-teia");
15697        assert_eq!(s.sole_pin(), None);
15698    }
15699
15700    #[test]
15701    fn sole_pin_returns_rev_when_only_rev_is_set() {
15702        let s = DepSource::Git {
15703            repo: "github:o/x".into(),
15704            tag: None,
15705            rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15706            branch: None,
15707        };
15708        assert_eq!(
15709            s.sole_pin(),
15710            Some("deadbeefcafebabe1234567890abcdef12345678")
15711        );
15712    }
15713
15714    #[test]
15715    fn sole_pin_returns_tag_when_only_tag_is_set() {
15716        let s = DepSource::Git {
15717            repo: "github:o/x".into(),
15718            tag: Some("v0.1.0".into()),
15719            rev: None,
15720            branch: None,
15721        };
15722        assert_eq!(s.sole_pin(), Some("v0.1.0"));
15723    }
15724
15725    #[test]
15726    fn sole_pin_returns_branch_when_only_branch_is_set() {
15727        let s = DepSource::Git {
15728            repo: "github:o/x".into(),
15729            tag: None,
15730            rev: None,
15731            branch: Some("main".into()),
15732        };
15733        assert_eq!(s.sole_pin(), Some("main"));
15734    }
15735
15736    #[test]
15737    fn sole_pin_precedence_rev_beats_tag_and_branch() {
15738        // Precedence: rev > tag > branch. Validate() rejects
15739        // multiple-pin shapes, but the accessor's precedence is defined
15740        // for pre-validate consumers (the resolver's `MissingPin`
15741        // diagnostic path, the caixa-crd round-trip's default `"main"`
15742        // fallback) and as defense-in-depth if the gate is ever
15743        // bypassed. Pins the same precedence caixa-resolver's
15744        // `fetch_git` and caixa-crd's `dep_into_ref` already apply
15745        // inline.
15746        let s = DepSource::Git {
15747            repo: "github:o/x".into(),
15748            tag: Some("v1".into()),
15749            rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15750            branch: Some("main".into()),
15751        };
15752        assert_eq!(
15753            s.sole_pin(),
15754            Some("deadbeefcafebabe1234567890abcdef12345678")
15755        );
15756    }
15757
15758    #[test]
15759    fn sole_pin_precedence_tag_beats_branch_when_no_rev() {
15760        let s = DepSource::Git {
15761            repo: "github:o/x".into(),
15762            tag: Some("v1".into()),
15763            rev: None,
15764            branch: Some("main".into()),
15765        };
15766        assert_eq!(s.sole_pin(), Some("v1"));
15767    }
15768
15769    #[test]
15770    fn sole_pin_byte_equals_inline_rev_or_tag_or_branch_cascade() {
15771        // Fail-before-pass-after byte-parity pin: the substrate accessor
15772        // must return byte-identical to the inline
15773        // `rev.as_deref().or(tag.as_deref()).or(branch.as_deref())`
15774        // cascade both caixa-resolver's `fetch_git` and caixa-crd's
15775        // `dep_into_ref` open-coded pre-lift. Trips at caixa-core build
15776        // time if the accessor's precedence silently drifts from the
15777        // consumer-side cascade — the exact drift this lift converges
15778        // to one substrate primitive to close structurally.
15779        //
15780        // Iterates through the 2^3 = 8 combinations of (tag, rev,
15781        // branch) each-either-`None`-or-`Some`, so every arm of the
15782        // precedence cascade lands under the pin. `validate()` refuses
15783        // the 4 multi-pin combinations, but the accessor's return is
15784        // defined on all 8.
15785        let vals = [Some("R".to_string()), None];
15786        for tag in &vals {
15787            for rev in &vals {
15788                for branch in &vals {
15789                    let s = DepSource::Git {
15790                        repo: "github:o/x".into(),
15791                        tag: tag.clone(),
15792                        rev: rev.clone(),
15793                        branch: branch.clone(),
15794                    };
15795                    // The exact inline cascade the two pre-lift
15796                    // consumer sites hand-rolled, byte-for-byte.
15797                    let expected = rev.as_deref().or(tag.as_deref()).or(branch.as_deref());
15798                    assert_eq!(
15799                        s.sole_pin(),
15800                        expected,
15801                        "sole_pin() must byte-equal \
15802                         rev.or(tag).or(branch) for \
15803                         (tag={tag:?}, rev={rev:?}, branch={branch:?}) — \
15804                         a drift would silently split caixa-resolver's \
15805                         fetch_git checkout target from caixa-crd's \
15806                         dep_into_ref git_ref fill",
15807                    );
15808                }
15809            }
15810        }
15811    }
15812}
15813
15814#[cfg(test)]
15815mod dep_source_is_variant_tests {
15816    use super::*;
15817
15818    fn all_variants() -> Vec<(DepSource, &'static str)> {
15819        vec![
15820            (
15821                DepSource::Git {
15822                    repo: "github:pleme-io/caixa-teia".into(),
15823                    tag: Some("v0.1.0".into()),
15824                    rev: None,
15825                    branch: None,
15826                },
15827                "Git",
15828            ),
15829            (
15830                DepSource::Path {
15831                    caminho: "../caixa-teia".into(),
15832                },
15833                "Path",
15834            ),
15835        ]
15836    }
15837
15838    fn predicate_row(s: &DepSource) -> [bool; 2] {
15839        [s.is_git(), s.is_path()]
15840    }
15841
15842    // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
15843    // derive-generated per-arm predicate partition — for every variant
15844    // in `all_variants()`, the observed 2-slot predicate row must equal
15845    // a one-hot row with the `true` at exactly the same index as the
15846    // variant's declaration order. Expected rows are generated live
15847    // from the enumeration rather than transcribed by hand, so a
15848    // copy-paste flip that reroutes one arm through the wrong predicate
15849    // lane trips at the identity-diagonal assertion the way every peer
15850    // sibling [`DepList`] / [`crate::CaixaKind`] / [`crate::CaixaDialeto`]
15851    // / [`crate::supervisor::RestartStrategy`] / [`crate::supervisor::RestartPolicy`]
15852    // / [`crate::upgrade::UpgradeInstruction`] /
15853    // [`crate::aplicacao::PlacementStrategy`] /
15854    // [`crate::aplicacao::RateLimitUnit`] /
15855    // [`crate::aplicacao::WitTarget`] /
15856    // [`crate::render::PathShapeViolation`] partition pin already does.
15857    #[test]
15858    fn dep_source_is_variant_predicates_partition_the_arm_set() {
15859        let variants = all_variants();
15860        for (idx, (variant, name)) in variants.iter().enumerate() {
15861            let observed = predicate_row(variant);
15862            let mut expected = [false; 2];
15863            expected[idx] = true;
15864            assert_eq!(
15865                observed, expected,
15866                "DepSource::{name} at declaration-order slot {idx} must \
15867                 satisfy exactly one is_* predicate (its own); observed \
15868                 row must equal the one-hot expected row — a drift \
15869                 would silently reroute one `:fonte`-arm consumer \
15870                 through the wrong predicate lane"
15871            );
15872        }
15873    }
15874
15875    // Byte-parity pin on the two field-agnostic `matches!` shapes the
15876    // per-arm arm-discriminator predicates replace at any future
15877    // consumer site (a `:fonte`-shape-only lint rule that flags path
15878    // deps outside dev-caixas via `dep.fonte().is_some_and(DepSource::is_path)`,
15879    // a future admission-webhook that rejects `:fonte` shapes outside
15880    // the `is_git()` accept-set, a caixa-lacre indexing pass that
15881    // dispatches on `s.is_git()` without extracting `repo` / `caminho`).
15882    // Refuses a future accidental split between the derived predicate
15883    // and its `matches!` shape — a hand-rolled shadow impl that
15884    // overrides one path, an accidental rebrand that leaves one
15885    // consumer on the raw `matches!` form — on the two load-bearing
15886    // `:fonte`-arm-discriminator axes every downstream substrate
15887    // consumer of the dep-source axis keys off.
15888    #[test]
15889    fn dep_source_is_git_and_is_path_byte_equal_matches_shape() {
15890        for (variant, name) in all_variants() {
15891            let via_matches_git = matches!(variant, DepSource::Git { .. });
15892            let via_predicate_git = variant.is_git();
15893            assert_eq!(
15894                via_predicate_git, via_matches_git,
15895                "DepSource::{name}.is_git() must byte-equal \
15896                 matches!(_, DepSource::Git {{ .. }}) — otherwise a \
15897                 future converged consumer site would silently \
15898                 disagree with its pre-lift shape"
15899            );
15900            let via_matches_path = matches!(variant, DepSource::Path { .. });
15901            let via_predicate_path = variant.is_path();
15902            assert_eq!(
15903                via_predicate_path, via_matches_path,
15904                "DepSource::{name}.is_path() must byte-equal \
15905                 matches!(_, DepSource::Path {{ .. }}) — otherwise a \
15906                 future converged consumer site would silently \
15907                 disagree with its pre-lift shape"
15908            );
15909        }
15910    }
15911
15912    // Cross-pin against every constructor path that materializes a
15913    // [`DepSource`] shape today (the [`DepSource::default_github`]
15914    // resolver-side fallback that materializes an unpinned
15915    // `github:<org>/<nome>` git shorthand, the [`Dep::git`] author-
15916    // surface constructor that materializes a pinned `:tag`-carrying
15917    // `DepSource::Git`, a hand-rolled `DepSource::Path` the dev-mode
15918    // fixture family builds inline). Every constructor's return must
15919    // satisfy the arm-discriminator predicate the constructor's
15920    // variant name matches — a future constructor addition (an
15921    // in-tree registry-fetch pin, a `DepSource::Feira` variant the
15922    // enclosing docstring already names as a trajectory item) surfaces
15923    // as a build-time failure that names the offending drift when its
15924    // return arm doesn't route through the paired predicate.
15925    #[test]
15926    fn dep_source_constructors_route_through_paired_is_variant_predicate() {
15927        let via_default_github = DepSource::default_github("pleme-io", "caixa-teia");
15928        assert!(
15929            via_default_github.is_git(),
15930            "DepSource::default_github must materialize a Git-arm shape — \
15931             a future constructor that routed through a non-Git arm \
15932             (a registry-fetch pin, a `DepSource::Feira` promotion) \
15933             would silently split the resolver's unpinned-shorthand \
15934             materializer from the sole_pin() precedence cascade"
15935        );
15936        assert!(
15937            !via_default_github.is_path(),
15938            "DepSource::default_github must NOT materialize a Path-arm \
15939             shape — the paired negation pin"
15940        );
15941
15942        let via_dep_git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15943            .fonte
15944            .expect("Dep::git materializes a Some(fonte)");
15945        assert!(
15946            via_dep_git.is_git(),
15947            "Dep::git's `:fonte` materialization must land on the Git \
15948             arm — the author-surface pinned-git constructor's return \
15949             must route through the paired predicate"
15950        );
15951        assert!(!via_dep_git.is_path(), "paired negation pin");
15952
15953        let via_path = DepSource::Path {
15954            caminho: "../caixa-teia".into(),
15955        };
15956        assert!(
15957            via_path.is_path(),
15958            "the dev-mode Path-arm materialization must satisfy is_path()"
15959        );
15960        assert!(!via_path.is_git(), "paired negation pin");
15961    }
15962}