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#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
59#[serde(tag = "tipo", rename_all = "lowercase")]
60pub enum DepSource {
61    /// Clone from Git. One of `:tag`, `:rev`, or `:branch` may be set.
62    /// `repo` can be a `github:org/repo` shorthand, a full `https://…` URL,
63    /// or any git-ssh URL.
64    Git {
65        repo: String,
66        #[serde(default, skip_serializing_if = "Option::is_none")]
67        tag: Option<String>,
68        #[serde(default, skip_serializing_if = "Option::is_none")]
69        rev: Option<String>,
70        #[serde(default, skip_serializing_if = "Option::is_none")]
71        branch: Option<String>,
72    },
73    /// Local filesystem path — dev only; cannot be published.
74    Path { caminho: String },
75}
76
77impl DepSource {
78    /// Build a registry-shorthand git source (`github:<org>/<nome>`).
79    ///
80    /// This is the resolver-side fallback for `dep.fonte: None`, not an
81    /// author-surface value — it carries no pin (`:tag`/`:rev`/`:branch`
82    /// all `None`) and is therefore rejected by [`Self::validate`]. The
83    /// resolver fills the pin in at fetch time from the resolved commit;
84    /// authors never serialize this shape as a `Dep::fonte` value.
85    #[must_use]
86    pub fn default_github(org: &str, nome: &str) -> Self {
87        Self::Git {
88            repo: format!("github:{org}/{nome}"),
89            tag: None,
90            rev: None,
91            branch: None,
92        }
93    }
94
95    /// Substrate-canonical per-`:fonte` sole-set git-pin scalar accessor
96    /// every consumer that reads "which single git ref does this source
97    /// resolve to?" keys off — returns the author-declared `:tag` /
98    /// `:rev` / `:branch` byte-string verbatim as an `Option<&str>`,
99    /// borrowed from the typed slot's own `Option<String>` storage; `None`
100    /// on [`Self::Path`] (a path source carries no git-ref) and on a
101    /// [`Self::Git`] variant whose `tag`, `rev`, and `branch` are all
102    /// `None` (the [`Self::default_github`] shorthand shape the resolver
103    /// materializes when the author omits `:fonte` — rejected by
104    /// [`Self::validate`], but the accessor's return is defined on this
105    /// arm too so pre-validate consumers reach for the same typed dispatch
106    /// as post-validate ones).
107    ///
108    /// **Precedence: rev > tag > branch.** The canonical precedence every
109    /// per-`:fonte` git-ref consumer already applies: caixa-resolver's
110    /// per-fetch `git checkout <ref>` reads through the same
111    /// `rev.or(tag).or(branch)` cascade at caixa-resolver/src/resolve.rs,
112    /// and caixa-crd's `dep_into_ref` `CaixaSource.git_ref` fill reads
113    /// through the same cascade at caixa-crd/src/conversion.rs. The
114    /// [`Self::validate`] gate enforces "exactly one pin set" — under
115    /// that invariant every accepted [`Self::Git`] carries exactly one
116    /// non-`None` pin and the precedence is unobservable, but the
117    /// precedence remains defined for pre-validate consumers (the
118    /// resolver's `MissingPin` diagnostic path, the caixa-crd
119    /// round-trip's default `"main"` fallback the author never sees a
120    /// diagnostic on) and defense-in-depth for a hypothetical future
121    /// state where multiple pins survive the gate. The precedence is
122    /// **rev before tag** because `:rev` (a git commit OID) is the
123    /// reproducibility-strongest identifier — an OID resolves to exactly
124    /// one commit regardless of which refname points at it, whereas
125    /// `:tag` and `:branch` are refnames the remote can silently move
126    /// (a tag re-push, a branch head advance); the resolver's freeze
127    /// step at fetch time promotes the resolved commit to `:rev` for
128    /// exactly this reason. **Tag before branch** because `:tag` is
129    /// conventionally immutable (a release tag) whereas `:branch` is
130    /// conventionally mutable (a tracking ref) — a caixa carrying both
131    /// a release tag and a tracking branch reads as "prefer the release
132    /// pin, fall through to the tracking pin only if the release is
133    /// missing". The cascade order also matches the byte-order every
134    /// per-`:tag`/`:rev`/`:branch` diagnostic tuple this crate emits
135    /// (`(":tag", tag), (":rev", rev), (":branch", branch)` — see
136    /// [`Self::validate`]'s `pins` array).
137    ///
138    /// Prior to this lift the "sole set pin" projection sat twice in the
139    /// workspace — inline at caixa-resolver's `fetch_git` (`let gitref =
140    /// rev.or(tag).or(branch).ok_or_else(|| ResolveError::MissingPin
141    /// { … })?;`) and at caixa-crd's `dep_into_ref`
142    /// (`git_ref: rev.clone().or(tag.clone()).or(branch.clone())
143    /// .unwrap_or_else(|| "main".to_string())`) — two open-coded copies
144    /// of the same precedence cascade with no compile-time link back to
145    /// the typed slot. A future extension of the pin axis to a richer
146    /// author surface (a `:commit` pin peer of `:rev` once the substrate
147    /// grows a signed-commit-verification pin, a `:ref` pin the M4
148    /// substrate operator resolves per-cluster ahead of fetch, a
149    /// promotion of the plain `Option<String>` pins to a typed
150    /// `GitPin::{Rev(Oid), Tag(RefName), Branch(RefName)}` newtype
151    /// once the sibling [`crate::render::is_git_oid`] /
152    /// [`crate::render::is_git_ref_name`] gates land as typed
153    /// constructors) would have had to be threaded through both
154    /// open-coded copies in lockstep or the resolver's `git checkout`
155    /// target would silently disagree with the CRD's `git_ref` fill —
156    /// an author's `(:fonte (:tipo git :repo "…" :rev "deadbeef" :tag
157    /// "v1"))` would ship with the resolver checking out `deadbeef`
158    /// while the CRD round-trip re-emitted a Dep pointing at `v1`, one
159    /// lacre closure disagreeing with the emitted K8s CR the operator
160    /// reads. Lifting the resolution to a typed method on the substrate
161    /// primitive means both downstream consumers reach for exactly one
162    /// typed dispatch — the resolver's accept-set migrates as a unit on
163    /// any future pin-axis addition.
164    ///
165    /// Peer of the sibling outer-`Dep` [`Dep::fonte`] (d65d1bf)
166    /// `Option<&DepSource>` composite-reference accessor on the outer-
167    /// `Dep` `:fonte`-slot axis — extended one nesting level down onto
168    /// the per-[`Self::Git`]-variant sole-set-pin projection axis every
169    /// git-fetching consumer runs after the outer `:fonte` slot resolves
170    /// to a [`Self::Git`] shape. Same "one typed dispatch on the
171    /// substrate primitive, thin projections at each consumer" discipline
172    /// the outer accessor family already carries.
173    #[must_use]
174    pub fn sole_pin(&self) -> Option<&str> {
175        match self {
176            Self::Git {
177                tag, rev, branch, ..
178            } => rev.as_deref().or(tag.as_deref()).or(branch.as_deref()),
179            Self::Path { .. } => None,
180        }
181    }
182
183    /// Validate the `:fonte` value-shape: every author-surface
184    /// `:fonte (:tipo git …)` must carry a non-empty `:repo` and
185    /// exactly one of `:tag` / `:rev` / `:branch` set to a non-empty
186    /// value; every `:fonte (:tipo path …)` must carry a non-empty
187    /// `:caminho`.
188    ///
189    /// Called from [`Dep::validate`] with the dep's `:nome` so every
190    /// diagnostic carries the offending entry verbatim — same
191    /// self-locating shape the `:deps :versao` (2420c44),
192    /// `:membros :versao` (9888b13), `:children :versao` (b38ff3a),
193    /// `:placement :clusters` (6cbb900), and `:membros :caixa`
194    /// (3f9d7a0) gates already expose.
195    ///
196    /// Until this gate landed `:fonte` was the only `:deps`-related
197    /// typed surface still untyped past `Caixa::from_lisp`:
198    /// - Empty `:repo` (`(:tipo git :repo "" :tag "v1")`) silently
199    ///   passed parse and surfaced as a git-clone failure at
200    ///   lacre-resolve time, far from the source caixa.lisp.
201    /// - A bare `(:tipo git :repo "…")` with no `:tag`/`:rev`/`:branch`
202    ///   passed parse and surfaced as the resolver's
203    ///   [`ResolveError::MissingPin`](../../caixa-resolver/src/resolve.rs)
204    ///   at fetch time, again far from the source caixa.lisp; lifting
205    ///   to validate-time gives the author the same diagnostic at the
206    ///   edit site.
207    /// - `(:tipo git :repo "…" :tag "v1" :branch "main")` — multiple
208    ///   pins set — passed parse and the resolver silently picked
209    ///   `:rev > :tag > :branch`, ignoring the other pins with no
210    ///   diagnostic; the author had no way to know their `:branch`
211    ///   was dropped. This is the canonical "pin drift" footgun.
212    /// - An empty pin value (`(:tipo git :repo "…" :tag "")`) silently
213    ///   passed parse and surfaced as `git checkout ""` at fetch time.
214    /// - Empty `:caminho` (`(:tipo path :caminho "")`) silently passed
215    ///   parse and surfaced as
216    ///   [`ResolveError::MissingPath`](../../caixa-resolver/src/resolve.rs)
217    ///   with `path: PathBuf("")` — not actionable.
218    ///
219    /// Each rejected shape maps to a typed
220    /// [`DepError::Fonte*`] variant that names the offending
221    /// dep's `:nome` and the specific axis, so the author can grep
222    /// their caixa.lisp for the `:nome "<nome>"` block and fix it in
223    /// one edit.
224    pub fn validate(&self, nome: &str) -> Result<(), DepError> {
225        match self {
226            Self::Git {
227                repo,
228                tag,
229                rev,
230                branch,
231            } => {
232                if repo.is_empty() {
233                    return Err(DepError::FonteRepoEmpty {
234                        nome: nome.to_string(),
235                    });
236                }
237                // The `:repo` value flows verbatim into the caixa-resolver's
238                // `git clone <repo>` subprocess invocation. Until this gate
239                // landed `:repo` was the last untyped `:fonte`-related axis
240                // past the empty arm: a malformed-but-non-empty repo URL
241                // (`":repo "github:p/x ""` trailing space, paste-from-doc;
242                // `":repo "-upload-pack=evil""` leading `-` — the canonical
243                // CLI-argument-injection vector at the `git clone` boundary;
244                // `":repo "pleme-io/caixa-teia""` missing scheme — `git clone`
245                // reads as a relative filesystem path rather than the
246                // GitHub-shorthand expansion; `":repo "github:p/x\n""`
247                // embedded newline; `":repo "github:café/x""` raw non-ASCII)
248                // silently passed validate and the failure surfaced at
249                // lacre-resolve time with a porcelain-quoting-confused error
250                // far from the source caixa.lisp. The lifted predicate makes
251                // the git-porcelain-URL intersection-floor a substrate-level
252                // invariant at validate time, peer with the three pin axes
253                // (`:tag` + `:branch` via [`crate::render::is_git_ref_name`],
254                // e70d213; `:rev` via [`crate::render::is_git_oid`], be07fd5)
255                // — every `:fonte (:tipo git …)` past validate is now
256                // structurally accept-shaped on every axis the resolver
257                // consumes (the `:repo` URL the `git clone` invokes against,
258                // the `:tag`/`:branch` refname `git fetch`/`git checkout`
259                // accepts, the `:rev` commit OID the lacre's content-
260                // addressing equality probe resolves), closing the
261                // `:fonte` slot's value-shape trajectory end-to-end.
262                if let Err(reason) = crate::render::is_git_repo_url(repo) {
263                    return Err(DepError::FonteRepoShape {
264                        nome: nome.to_string(),
265                        repo: repo.clone(),
266                        reason,
267                    });
268                }
269                let pins: [(&'static str, Option<&String>); 3] = [
270                    (":tag", tag.as_ref()),
271                    (":rev", rev.as_ref()),
272                    (":branch", branch.as_ref()),
273                ];
274                let set: Vec<&'static str> =
275                    pins.iter().filter_map(|(n, v)| v.map(|_| *n)).collect();
276                match set.len() {
277                    0 => {
278                        return Err(DepError::FontePinMissing {
279                            nome: nome.to_string(),
280                        });
281                    }
282                    1 => {
283                        for (pin, value) in pins {
284                            if value.is_some_and(String::is_empty) {
285                                return Err(DepError::FontePinEmpty {
286                                    nome: nome.to_string(),
287                                    pin: pin.to_string(),
288                                });
289                            }
290                        }
291                    }
292                    _ => {
293                        return Err(DepError::FontePinAmbiguous {
294                            nome: nome.to_string(),
295                            pins: set.join(", "),
296                        });
297                    }
298                }
299                // Per-pin value-shape gate. The refname-shaped axes
300                // (`:tag` + `:branch`) route through
301                // [`crate::render::is_git_ref_name`]; the hex-OID-shaped
302                // `:rev` axis routes through
303                // [`crate::render::is_git_oid`]. The two predicates
304                // partition the `:fonte` pin axes structurally — refname
305                // vs. hex commit — so a cross-axis mis-slot (the
306                // canonical "I conflated `:rev` and `:branch`" footgun:
307                // `:rev "main"` defeating the reproducibility contract,
308                // `:tag "deadbeef…"` mis-slotting a SHA into the
309                // refname-shaped axis) lands at the offending axis's
310                // predicate, not at lacre-resolve `git fetch` /
311                // `git checkout` time. Their valid sets intersect at
312                // the empty set: every refname is rejected by
313                // `is_git_oid`, every OID is rejected by
314                // `is_git_ref_name`, structurally.
315                //
316                // Until this gate landed `:tag` / `:branch` were the
317                // refname-shaped axes still untyped past the empty-pin
318                // arm: a malformed-but-non-empty refname
319                // (`:tag "v0.1.0 "` trailing space — the canonical
320                // paste-from-doc footgun; `:tag "v0.1.0.lock"` colliding
321                // with git's atomic-rename guard suffix; `:tag "../escape"`
322                // path-traversal via consecutive dots; `:branch "main "`
323                // trailing space; `:branch "feature/foo bar"` embedded
324                // space; `:branch "@"` the literal HEAD alias;
325                // `:branch "refs/heads/main"` the fully-qualified ref
326                // copied from `git show-ref` output that resolves to
327                // a literal ref named `refs/heads/refs/heads/main` on
328                // disk) silently passed validate; the `:rev` axis was
329                // the last `:fonte`-related axis still untyped past the
330                // empty-pin arm: a malformed-but-non-empty hex-OID
331                // (`:rev "main"` conflating with `:branch` — the
332                // reproducibility-contract leak; `:rev "v0.1.0"`
333                // conflating with `:tag` — the same mis-slot on the
334                // refname/OID boundary; `:rev "c0ffee"` an abbreviated
335                // 6-char prefix that's ambiguous across repo history;
336                // `:rev "DEADBEEF…"` an uppercase OID that round-trips
337                // inconsistently against `git rev-parse HEAD`'s
338                // lowercase emission) silently passed validate and the
339                // failure surfaced at lacre-resolve `git fetch` /
340                // `git checkout` time with a quoting-confused error
341                // far from the source caixa.lisp, with no field naming
342                // which `:deps` entry carried the typo. Lifting both
343                // gates to caixa-build time matches the value-shape
344                // trajectory the peer typed axes already follow
345                // (c4213a4 typed WitContract endpoint/subject/slot;
346                // eb3456d :entrada :paths; c7d05ec :entrada :host;
347                // 4f0390b :contratos :endpoint; 6226bf4 :contratos :wit;
348                // 63e18a0 :contratos :subject; 2f4316e :contratos
349                // :slot; e70d213 :fonte :tag + :branch) — the typed
350                // slot's valid set matches its downstream consumer's
351                // accepted set (here, the git porcelain's refname /
352                // commit-OID grammars at `git fetch` / `git checkout`
353                // time), structurally. Same diagnostic shape every
354                // per-axis value-shape lift already exposes
355                // (`*Invalid { axis, reason }`); the `value:` field
356                // carries the offending refname / OID verbatim so the
357                // author can grep their caixa.lisp for the
358                // `:tag "<value>"` / `:branch "<value>"` /
359                // `:rev "<value>"` literal and fix it in one edit.
360                for (pin, value) in [(":tag", tag.as_ref()), (":branch", branch.as_ref())] {
361                    if let Some(v) = value
362                        && let Err(reason) = crate::render::is_git_ref_name(v)
363                    {
364                        return Err(DepError::FontePinShape {
365                            nome: nome.to_string(),
366                            pin: pin.to_string(),
367                            value: v.clone(),
368                            reason,
369                        });
370                    }
371                }
372                if let Some(v) = rev.as_ref()
373                    && let Err(reason) = crate::render::is_git_oid(v)
374                {
375                    return Err(DepError::FontePinShape {
376                        nome: nome.to_string(),
377                        pin: ":rev".to_string(),
378                        value: v.clone(),
379                        reason,
380                    });
381                }
382                Ok(())
383            }
384            Self::Path { caminho } => Self::validate_caminho(nome, caminho),
385        }
386    }
387
388    /// Reproducibility + path-API gate on the `:fonte (:tipo path …)`
389    /// `:caminho` axis. Walks the leading-byte cascade closed by the
390    /// b94fd83 (`/`), a5c248e (`~`), and f4efe9c (`$`) arms; the
391    /// orthogonal embedded-control-byte arm (d624c8d) covering
392    /// `0x00..=0x1F` plus `0x7F` anywhere in the value; and the
393    /// embedded-`\` Windows-path-separator arm closing the
394    /// cross-host-OS-separator divergence vector on the same
395    /// THEORY.md §V.2 render-determinism axis.
396    ///
397    /// Extracted from [`Self::validate`]'s `Self::Path` arm because the
398    /// per-arm cascade now spans nine diagnostic shapes — every new
399    /// `:caminho` arm (a future `&` / `;` / `|` shell-metachar arm,
400    /// a future glob-metachar `*` / `?` arm) lands here rather than
401    /// re-inflating `Self::validate`. The
402    /// function stays a thin per-arm linear walk for one reason: each
403    /// arm's diagnostic carries a distinct typed [`DepError`] variant
404    /// rather than a parser-shaped `reason` string, so collapsing the
405    /// cascade onto a generic [`crate::render`] predicate would regress
406    /// the per-arm self-locating diagnostic that `feira lint` consumers
407    /// depend on. The wrapped predicate trajectory ([`crate::render::is_dns_1123_label`],
408    /// [`crate::render::is_git_repo_url`], etc.) lives on the
409    /// reason-string-shaped axes; the `:caminho` axis keeps its
410    /// per-arm variant shape.
411    #[allow(
412        clippy::too_many_lines,
413        reason = "the per-arm cascade is structurally flat by design — every \
414                  `:caminho` arm carries its own typed [`DepError`] variant + \
415                  per-arm Why comment, so collapsing the cascade onto a generic \
416                  [`crate::render`] predicate would regress the per-arm self-locating \
417                  diagnostic the `feira lint` consumer surface depends on"
418    )]
419    fn validate_caminho(nome: &str, caminho: &str) -> Result<(), DepError> {
420        if caminho.is_empty() {
421            return Err(DepError::FonteCaminhoEmpty {
422                nome: nome.to_string(),
423            });
424        }
425        // Reproducibility gate on the `:fonte (:tipo path …)`
426        // `:caminho` axis. The lacre pipeline embeds the value
427        // verbatim in its per-dep content-address
428        // (`conteudo: format!("path:{caminho}")`,
429        // caixa-resolver/src/resolve.rs:189) and that string
430        // folds into the BLAKE3 closure the lacre keys every
431        // downstream consumer (the substrate's reproducibility
432        // contract, CAIXA-SDLC §III.2 — the lacre is the
433        // build's content-addressed identity, peer of the Nix
434        // store path) against. Until this gate landed an
435        // absolute `:caminho` (`/home/me/work/caixa-teia` — the
436        // canonical "I dragged the folder out of Finder into
437        // my editor" footgun; `/Users/alice/dev/caixa-teia` on
438        // the macOS path-layout peer; the
439        // `${WORKSPACE}/caixa-teia` shell-expanded literal
440        // pasted from a CI manifest) silently passed validate
441        // and the failure surfaced *as a successful build with
442        // a divergent lacre*: the BLAKE3 closure on Alice's
443        // workstation differed from the closure on Bob's
444        // workstation, two CI runners with different
445        // `${HOME}` layouts emitted two distinct
446        // content-addresses for the byte-identical caixa, and
447        // the substrate's "the lacre is the build's identity"
448        // contract silently broke far from the source
449        // caixa.lisp — the most insidious failure mode the
450        // typed slot can carry (no error surfaces; the
451        // divergence is invisible until two machines compare
452        // lacres). The same THEORY.md §V.2 render-determinism
453        // discipline `is_sandboxed_relative_path` already
454        // applies on the M2 typed path-slots
455        // (`:behavior :on-*`, `:upgrade-from :state-change
456        // :script`, `:bibliotecas`, `:exe`, `:servicos`), here
457        // narrowed to the absolute-vs-relative axis only:
458        // `:fonte :caminho`'s canonical author-surface form is
459        // the `..`-traversing sibling-workspace path
460        // (`"../caixa-teia"`, the in-tree dev-dep frame), so a
461        // full `is_sandboxed_relative_path` lift would
462        // structurally reject every legitimate path-fonte
463        // dep. The narrower
464        // `std::path::Path::is_absolute` cut admits the
465        // sibling-workspace form while still rejecting the
466        // host-layout-leaking absolute shape — the
467        // reproducibility contract bites at exactly the
468        // absolute boundary, and that's the axis the
469        // substrate-level invariant is meant to hold. Same
470        // diagnostic shape every per-axis value-shape lift on
471        // the surrounding [`DepError::Fonte*`] cluster carries
472        // (the offending `:nome` + offending `:caminho`
473        // quoted verbatim so the author can grep their
474        // caixa.lisp for the `:caminho "<value>"` literal and
475        // fix it in one edit). The empty arm strictly
476        // precedes this arm so the blank-string footgun
477        // surfaces the more self-locating
478        // `FonteCaminhoEmpty` diagnostic (the empty string
479        // is not absolute under `Path::new("").is_absolute()`
480        // so the precedence is a no-op at value level — the
481        // pin matters only at the diagnostic-shape level if
482        // a future codec round-trip ever produces an empty
483        // string that probes as absolute).
484        if std::path::Path::new(caminho).is_absolute() {
485            return Err(DepError::FonteCaminhoAbsolute {
486                nome: nome.to_string(),
487                caminho: caminho.to_string(),
488            });
489        }
490        // Reproducibility gate's tilde-expansion arm. The b94fd83
491        // `FonteCaminhoAbsolute` closes the leading-`/`
492        // host-layout-leak; a `:caminho "~/work/caixa-teia"` (the
493        // canonical paste-from-shell-prompt / paste-from-`cd ~`-
494        // doc footgun) silently passed both the empty arm and
495        // the absolute arm because `Path::new("~").is_absolute()`
496        // returns `false` — `~` is a shell-expansion convention,
497        // not a POSIX path component, so `std::path::Path` treats
498        // it as a literal directory-name segment. The lacre
499        // pipeline then embedded the value verbatim
500        // (`conteudo: format!("path:~/work/caixa-teia")`) and the
501        // failure mode forked per consumer:
502        //
503        //   - The caixa-resolver's `Path` arm folds `:caminho`
504        //     through `Path::new(caminho).join(<file>)` without
505        //     `~`-expansion, so the build looked for a literal
506        //     `./~/work/caixa-teia` subdirectory and failed at
507        //     resolve time with a `No such file or directory`
508        //     error far from the source caixa.lisp (the lacre
509        //     itself, though, was already byte-identical across
510        //     machines — every machine emitted the same
511        //     `path:~/work/caixa-teia` content-address).
512        //   - A future caixa-resolver pass that *does* expand `~`
513        //     (the canonical shell-convention idiom every
514        //     resolver eventually reaches for once an author
515        //     reports the literal-`~`-directory bug) would re-
516        //     introduce the host-layout-leak the b94fd83 absolute
517        //     gate closes: Alice's `~` expands to `/home/alice`,
518        //     Bob's to `/home/bob`, two CI runners with different
519        //     `$HOME` layouts resolve to two distinct paths for
520        //     the byte-identical caixa, and the substrate's
521        //     "the lacre is the build's identity" contract
522        //     silently breaks far from the source caixa.lisp.
523        //
524        // Closing the gate at `DepSource::validate` (here at the
525        // canonical caixa-build-time boundary, peer with the
526        // absolute arm above) refuses both failure modes
527        // structurally: the typed accepted set excludes every
528        // `~`-prefixed authoring shape, so the resolver is
529        // free to grow `~`-expansion (or any other convention-
530        // expansion the substrate adopts) without re-opening
531        // the host-layout-leak at the typed boundary. Same
532        // diagnostic shape every per-axis value-shape gate on
533        // the surrounding [`DepError::Fonte*`] cluster carries
534        // (the offending `:nome` + offending `:caminho` quoted
535        // verbatim so the author can grep their caixa.lisp for
536        // the `:caminho "<value>"` literal and fix it in one
537        // edit).
538        //
539        // The cascade preserves narrower-diagnostic-first
540        // ordering: `FonteCaminhoEmpty` → `FonteCaminhoAbsolute`
541        // → `FonteCaminhoTildeExpansion`. The empty arm
542        // structurally precedes both (the bytes "" / "~" don't
543        // overlap), and the absolute arm structurally precedes
544        // the tilde arm (an absolute path can't start with `~`
545        // since absolute paths start with `/`; the bytes "/" /
546        // "~" don't overlap either). Both arms are
547        // value-disjoint, so the precedence is a no-op at value
548        // level — the pin matters only at the diagnostic-shape
549        // level if a future codec round-trip ever produces a
550        // value that probes as both absolute and tilde-prefixed.
551        if caminho.starts_with('~') {
552            return Err(DepError::FonteCaminhoTildeExpansion {
553                nome: nome.to_string(),
554                caminho: caminho.to_string(),
555            });
556        }
557        // Reproducibility gate's shell-variable-expansion arm.
558        // The b94fd83 `FonteCaminhoAbsolute` closes the leading-`/`
559        // host-layout-leak; the a5c248e `FonteCaminhoTildeExpansion`
560        // closes the leading-`~` shell-home-expansion shape; the
561        // leading-`$` is the sibling shell-variable-expansion shape
562        // — same host-layout-leaking semantic, different syntactic
563        // surface. A `:caminho "$HOME/work/caixa-teia"` (the
564        // canonical paste-from-`echo $HOME`-doc footgun) and the
565        // `${VAR}`-braced variant (`"${WORKSPACE}/caixa-teia"` —
566        // the canonical paste-from-CI-manifest footgun every
567        // GitHub Actions / GitLab CI / Drone manifest carries)
568        // silently passed every prior arm because
569        // `Path::is_absolute` returns false on `$` (the `$` is a
570        // shell convention, not a POSIX path component, so
571        // `std::path::Path` treats it as a literal directory-name
572        // segment) and the tilde arm's `starts_with('~')` doesn't
573        // fire.
574        //
575        // Same per-consumer failure-fork the tilde arm closes:
576        //
577        //   - The caixa-resolver's `Path` arm folds `:caminho`
578        //     through `Path::new(caminho).join(<file>)` without
579        //     `$`-expansion, so the build looks for a literal
580        //     `./$HOME/work/caixa-teia` subdirectory and fails at
581        //     resolve time with a `No such file or directory`
582        //     error far from the source caixa.lisp.
583        //   - A future caixa-resolver pass that *does* expand
584        //     `$VAR` (the shell-convention idiom every resolver
585        //     eventually reaches for once an author reports the
586        //     literal-`$HOME`-directory bug, especially for CI's
587        //     `${WORKSPACE}` idiom) would re-introduce the host-
588        //     layout-leak the b94fd83 absolute gate closes:
589        //     Alice's `$HOME` expands to `/home/alice`, Bob's to
590        //     `/home/bob`, two CI runners with different
591        //     `${WORKSPACE}` layouts resolve to two distinct
592        //     paths for the byte-identical caixa, and the
593        //     substrate's "the lacre is the build's identity"
594        //     contract silently breaks far from the source
595        //     caixa.lisp.
596        //
597        // Closing the gate at `DepSource::validate` (here at the
598        // canonical caixa-build-time boundary, peer with the
599        // absolute + tilde arms above) refuses both failure modes
600        // structurally. Same diagnostic shape every per-axis
601        // value-shape gate on the surrounding [`DepError::Fonte*`]
602        // cluster carries (the offending `:nome` + offending
603        // `:caminho` quoted verbatim).
604        //
605        // The cascade preserves narrower-diagnostic-first ordering:
606        // `FonteCaminhoEmpty` → `FonteCaminhoAbsolute` →
607        // `FonteCaminhoTildeExpansion` → `FonteCaminhoVarExpansion`.
608        // The empty arm structurally precedes all three subsequent
609        // arms; the absolute arm structurally precedes both the
610        // tilde and the var arms (absolute paths start with `/`,
611        // the bytes `/` / `~` / `$` don't overlap at the leading
612        // position); the tilde arm structurally precedes the var
613        // arm (`~` and `$` don't overlap at the leading position).
614        // Every pair is value-disjoint, so the precedence is a
615        // no-op at value level — the pin matters only at the
616        // diagnostic-shape level if a future codec round-trip ever
617        // produces a probe-as-both value.
618        //
619        // The gate covers every leading-`$` shape: the canonical
620        // `"$HOME/work/caixa-teia"` (POSIX shell), the braced
621        // `"${HOME}/work/caixa-teia"` (POSIX shell braces), the
622        // CI-manifest idiom `"${WORKSPACE}/caixa-teia"` (the
623        // GitHub Actions / GitLab CI / Drone paste footgun), the
624        // XDG idiom `"$XDG_CONFIG_HOME/caixa"`, and the bare `$`
625        // (degenerate "I meant `$HOME` and forgot the rest"). All
626        // shapes route through the same `caminho.starts_with('$')`
627        // byte check.
628        if caminho.starts_with('$') {
629            return Err(DepError::FonteCaminhoVarExpansion {
630                nome: nome.to_string(),
631                caminho: caminho.to_string(),
632            });
633        }
634        // Reproducibility gate's leading-space arm. The b94fd83 / a5c248e /
635        // f4efe9c arms closed the leading-byte host-layout-leak shapes
636        // (`/` / `~` / `$`); the embedded-control-byte arm below closes
637        // every byte in `0x00..=0x1F` plus `0x7F` (which already includes
638        // tab `0x09`, LF `0x0A`, CR `0x0D` — every ASCII whitespace
639        // *except* the ASCII space byte `0x20`). The bare ASCII space at
640        // the leading position is the orthogonal paste-from-aligned-doc
641        // shape that silently passed every prior arm: `Path::is_absolute`
642        // returns false on `" ../caixa-teia"` (the leading byte is `0x20`
643        // not `0x2F`), `0x20` is not `~` / `$` / `\` / a control byte, and
644        // the value's last byte is not `/`, so the canonical
645        // paste-from-aligned-`caixa.lisp`-doc footgun (every `:fonte`
646        // form in a multi-entry `:deps` block sits at the same column —
647        // an author selecting `"<sp><sp><sp>../caixa-teia"` and pasting
648        // it from the rendered alignment into a fresh entry preserves the
649        // leading whitespace verbatim) silently rendered as a path with
650        // a leading-space directory component the resolver folds through
651        // `Path::join` looking for a literal `./ ../caixa-teia`
652        // subdirectory that fails at resolve time with a non-self-
653        // locating `No such file or directory` error.
654        //
655        // The lacre pipeline's reproducibility contract bites
656        // strictly at this byte: `path:" ../caixa-teia"` and
657        // `path:"../caixa-teia"` yield distinct BLAKE3 closures
658        // (`conteudo: format!("path:{caminho}")`,
659        // caixa-resolver/src/resolve.rs:189) for the byte-divergent /
660        // semantic-identical caixa, and the substrate's "the lacre is
661        // the build's identity" contract (CAIXA-SDLC §III.2) silently
662        // breaks across two workstations whose authors differ only in
663        // paste-from-aligned-doc whitespace habits — the most insidious
664        // failure mode the typed slot can carry (no error surfaces; the
665        // divergence is invisible until two machines compare lacres).
666        //
667        // The arm fires AFTER the absolute / tilde / var leading-byte
668        // arms (each names the more self-locating shell-convention
669        // diagnostic on values that probe as that arm's leading-byte
670        // sentinel followed by a leading space — e.g.
671        // `:caminho "/  /foo"` surfaces `FonteCaminhoAbsolute` because
672        // the leading byte is `/`, not space) and BEFORE the
673        // embedded-control-byte arm (a leading-space value with an
674        // embedded control byte surfaces the broader leading-space
675        // diagnostic because the cascade walks leading-byte arms first
676        // — peer with how `FonteCaminhoAbsolute` precedes
677        // `FonteCaminhoControlChar` on `"/etc/passwd\n"`).
678        //
679        // The peer single-token-shaped axes already reject leading
680        // whitespace on the same paste-from-aligned-doc contract:
681        // [`crate::render::is_git_repo_url`] rejects leading whitespace
682        // on `:fonte :repo`, [`crate::render::is_git_ref_name`] rejects
683        // leading whitespace on `:fonte :tag`/`:branch`,
684        // [`crate::render::is_chart_description_shape`] rejects leading
685        // whitespace on `:descricao`,
686        // [`crate::render::is_spdx_expression_shape`] rejects leading
687        // whitespace on `:licenca`. Closing the same byte on
688        // `:fonte :caminho` makes the substrate-wide "no leading ASCII
689        // space anywhere in a typed string slot" invariant structurally
690        // consistent across every value-shape-gated typed surface (the
691        // `:caminho` axis was the last typed string surface still
692        // admitting a leading space byte).
693        if caminho.starts_with(' ') {
694            return Err(DepError::FonteCaminhoLeadingWhitespace {
695                nome: nome.to_string(),
696                caminho: caminho.to_string(),
697            });
698        }
699        // Reproducibility gate's leading-`-` CLI-argument-injection arm.
700        // The b94fd83 + a5c248e + f4efe9c + LeadingWhitespace arms closed
701        // the four prior leading-byte shapes (`/` / `~` / `$` / space);
702        // this arm closes the orthogonal leading-`-` axis on the same
703        // subprocess-argument-boundary the peer `is_git_repo_url` arm
704        // (render.rs:2037, `-upload-pack=…` on `:fonte :repo`) and
705        // `is_git_ref_name` arm (render.rs:1381, 5a28454, `-stable` on
706        // `:fonte :tag` / `:branch`) already reject.
707        //
708        // The lacre pipeline embeds `:caminho` verbatim in its per-dep
709        // content-address (`conteudo: format!("path:{caminho}")`,
710        // caixa-resolver/src/resolve.rs:189) and the resolver folds the
711        // value through `Path::join` looking for a literal `./{caminho}`
712        // subdirectory. Every downstream subprocess that consumes the
713        // resolved path — a `git -C {caminho} <verb>` invocation, a
714        // future `feira tofu` `terraform -chdir={caminho}` shell-out, a
715        // future operator-side `nix build --path {caminho}` spawn, an
716        // `xargs` / `find {caminho}` / `stat {caminho}` /
717        // `rm -rf {caminho}` cleanup — reinterprets a leading-`-` value
718        // as a CLI flag rather than a positional path when the
719        // subprocess invocation does not carry a `--` argument-list
720        // terminator between the flag block and the path argument. The
721        // canonical footguns:
722        //
723        //   - `:caminho "-rf"` — bare short-flag paste (`rm -rf` /
724        //     `find -rf` reinterpretation; the byte the peer
725        //     `FonteCaminhoShellSemicolon` arm's `; rm -rf build`
726        //     example paste-idiom carries as its first token).
727        //   - `:caminho "-C"` — `git -C` config-injection paste
728        //     (`git -C -C` reinterprets the second `-C` as another
729        //     `--change-directory` flag rather than the path
730        //     argument; the canonical `git -C <path>` porcelain
731        //     idiom every multi-repo workspace tool carries).
732        //   - `:caminho "--upload-pack=cat /etc/passwd"` — the
733        //     canonical long-flag CLI-arg-injection vector at every
734        //     git porcelain entry point (`git clone`, `git fetch`,
735        //     `git ls-remote`) that consumes a path or URL
736        //     argument; peer with `is_git_repo_url`'s leading-`-`
737        //     arm (render.rs:2037) on the sibling `:fonte :repo`
738        //     axis, which the arm's diagnostic explicitly cites.
739        //   - `:caminho "--config=…"` / `:caminho "-c"` — git-config
740        //     override paste-idiom (paste-from-`git -c foo=bar`
741        //     shell-history footgun that reinterprets the value as
742        //     a `[foo] bar` config injection on every git porcelain
743        //     entry point).
744        //
745        // POSIX `std::path::Path` treats a leading `-` as a literal
746        // filename byte, so the resolver folds `-rf` through `Path::join`
747        // and looks for a literal `./-rf` subdirectory — the failure
748        // surfaces at resolve time with a non-self-locating `No such
749        // file or directory` error far from the source caixa.lisp, and
750        // the value rides through the lacre content-address into every
751        // downstream shell-spawned subprocess. On any consumer that
752        // shells out without the `--` terminator (the common case at
753        // every porcelain entry-point) the reinterpretation is silent
754        // and the failure mode is arbitrary-argument-injection.
755        //
756        // The arm fires AFTER the absolute / tilde / var / leading-space
757        // leading-byte arms (each names the more self-locating shell-
758        // convention diagnostic on values that probe as that arm's
759        // leading-byte sentinel — the byte sets are pairwise disjoint at
760        // the leading position, so the precedence pin is a no-op at
761        // value level, but the ordering keeps every leading-byte arm's
762        // diagnostic-shape stable) and BEFORE the embedded-control-byte
763        // arm (a leading-`-` value with an embedded control byte
764        // surfaces the narrower leading-`-` diagnostic because the
765        // cascade walks leading-byte arms first — peer with how
766        // `FonteCaminhoAbsolute` precedes `FonteCaminhoControlChar` on
767        // `"/etc/passwd\n"`, and how `FonteCaminhoLeadingWhitespace`
768        // precedes `FonteCaminhoControlChar` on `" ../foo\n"`).
769        //
770        // The peer single-token-shaped axes already reject leading `-`
771        // on the same CLI-arg-injection contract:
772        // [`crate::render::is_git_repo_url`] rejects it on `:fonte :repo`
773        // (render.rs:2037), [`crate::render::is_git_ref_name`] rejects
774        // it on `:fonte :tag` / `:fonte :branch` (render.rs:1381,
775        // 5a28454), [`crate::render::is_dns_1123_label`] rejects it on
776        // every DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros
777        // :caixa`, `:children :caixa`, `:deps :nome`, cluster names),
778        // [`crate::render::is_cargo_feature_name`] rejects it on
779        // `:caracteristicas`, and the feira `init` / `add <nome>`
780        // positional gate (868c191) rejects it on the CLI positional
781        // itself. Closing the same byte on `:fonte :caminho` makes the
782        // substrate-wide "no leading `-` anywhere in a typed single-
783        // token string slot routed through a subprocess argument"
784        // invariant structurally consistent across every value-shape-
785        // gated typed surface (the `:caminho` axis was the last typed
786        // string surface still admitting a leading `-` byte).
787        if caminho.starts_with('-') {
788            return Err(DepError::FonteCaminhoLeadingHyphen {
789                nome: nome.to_string(),
790                caminho: caminho.to_string(),
791            });
792        }
793        // Reproducibility gate's embedded-control-byte arm. The
794        // b94fd83 + a5c248e + f4efe9c arms closed the three
795        // leading-byte host-layout-leak shapes (`/` / `~` / `$`);
796        // this arm closes the orthogonal embedded-control-byte
797        // axis — any ASCII control byte (`0x00..=0x1F` plus
798        // `0x7F` DEL) appearing anywhere in `:caminho`. Same
799        // shape every peer single-token-typed-slot value-shape
800        // predicate the surrounding [`crate::render`] cluster
801        // gates against (the lifted `is_git_repo_url` arm on
802        // `:fonte :repo`, the `is_git_ref_name` arm on
803        // `:tag`/`:branch`, the `is_chart_description_shape` /
804        // `is_chart_maintainer_name_shape` /
805        // `is_chart_keyword_shape` arms on the
806        // Helm-chart-shaped axes); now consistent on the
807        // `:caminho` axis too.
808        //
809        // Until this gate landed any embedded control byte
810        // silently passed validate, the lacre pipeline embedded
811        // the value verbatim in its per-dep content-address
812        // (`conteudo: format!("path:{caminho}")`,
813        // caixa-resolver/src/resolve.rs:189), and the failure
814        // forked per byte and per consumer:
815        //
816        //   - NUL (`0x00`) the canonical "POSIX paths cannot
817        //     contain a NUL byte" shape: every `std::fs` syscall
818        //     routes the path through `CString::new`, which
819        //     fails with `NulError` on the first NUL byte; the
820        //     build would surface a `NulError` at resolve time
821        //     far from the source caixa.lisp.
822        //   - LF (`0x0A`) / CR (`0x0D`) the canonical paste-from-
823        //     multiline-doc footgun: a `:caminho
824        //     "../caixa-teia\nrm -rf /"` value (paste landed mid-
825        //     `:caminho` block from a multi-line code-fence)
826        //     silently round-trips through `Path::join` but the
827        //     embedded newline class is a sibling of the CRLF-at-
828        //     subprocess-argument injection vector
829        //     `is_git_repo_url` already closes on `:repo`.
830        //   - Tab (`0x09`) the canonical paste-from-aligned-table
831        //     footgun: the tab is invisible in most editors, and
832        //     the lacre embeds the value verbatim so two
833        //     paste-from-distinct-tables yield divergent lacres
834        //     across host editors that strip vs preserve tabs.
835        //   - DEL (`0x7F`) + every other `0x00..=0x1F` byte: the
836        //     paste-from-binary-blob shape every peer single-
837        //     token-shaped slot rejects under the same
838        //     `b < 0x20 || b == 0x7F` predicate.
839        //
840        // Mirrors the cascade discipline every prior `:caminho`
841        // arm establishes: `FonteCaminhoEmpty` →
842        // `FonteCaminhoAbsolute` → `FonteCaminhoTildeExpansion`
843        // → `FonteCaminhoVarExpansion` →
844        // `FonteCaminhoLeadingWhitespace` →
845        // `FonteCaminhoLeadingHyphen` → `FonteCaminhoControlChar`.
846        // The six leading-byte arms structurally precede the
847        // embedded-byte arm because the leading-byte shapes are
848        // the more self-locating diagnostic on values that probe
849        // as both (e.g. `:caminho "/etc/passwd\n"` surfaces the
850        // narrower `FonteCaminhoAbsolute` rather than the broader
851        // embedded-control-byte arm); the precedence pin matters
852        // at the diagnostic-shape level even though the empty /
853        // absolute / tilde / var arms are value-disjoint from a
854        // bare control byte (which would itself be a leading
855        // byte under the empty / absolute / tilde / var arms'
856        // leading-position semantics, but those arms guard the
857        // specific shell-convention characters `/` / `~` / `$`
858        // — a leading `0x01` byte falls through to this arm).
859        for &b in caminho.as_bytes() {
860            if b < 0x20 || b == 0x7F {
861                return Err(DepError::FonteCaminhoControlChar {
862                    nome: nome.to_string(),
863                    caminho: caminho.to_string(),
864                    byte: b,
865                });
866            }
867        }
868        // Reproducibility gate's Windows-path-separator arm. The four
869        // leading-byte arms (`/` / `~` / `$`) and the embedded-
870        // control-byte arm close the host-layout-leaking + paste-from-
871        // multiline-doc shapes; the leading-`\` / embedded-`\` byte is
872        // the orthogonal cross-host-OS-separator shape — same render-
873        // determinism axis, different semantic mechanism. POSIX
874        // [`std::path::Path`] treats `\` (0x5C) as a literal byte
875        // inside a single path component (so `..\caixa-teia` is one
876        // directory named literally `..\caixa-teia`, sibling of `.`
877        // and `..`); Windows [`std::path::Path`] treats `\` as a
878        // primary path separator equal to `/` (so `..\caixa-teia` is
879        // the parent's sibling directory `caixa-teia`). The lacre
880        // pipeline embeds the value verbatim in its per-dep content-
881        // address (`conteudo: format!("path:{caminho}")`, caixa-
882        // resolver/src/resolve.rs:189), so byte-identical caixa.lisp
883        // values resolve to two distinct directories across runner
884        // OSes — the same THEORY.md §V.2 render-determinism contract
885        // the absolute / tilde / var arms protect, here against the
886        // cross-host-OS-separator divergence vector. Even on POSIX-
887        // only resolvers (the canonical pleme-io substrate posture),
888        // a `..\caixa-teia` (the Windows-Explorer "copy as path" /
889        // PowerShell `Get-Location` paste-idiom footgun) silently
890        // passes every prior arm because `Path::is_absolute` returns
891        // false on `..` and `\` is neither a leading-byte sentinel
892        // nor a control byte, then the resolver folds the value
893        // through `Path::new(caminho).join(<file>)` looking for a
894        // literal `./..\caixa-teia` subdirectory and fails at
895        // resolve time with a non-self-locating `No such file or
896        // directory` error far from the source caixa.lisp.
897        //
898        // The peer single-token-shaped axes on the same git-CLI /
899        // path-CLI consumer cluster already reject `\` under the same
900        // Windows-path-leak banner: [`crate::render::is_git_ref_name`]
901        // line 1441 (`"must not contain \\ … the canonical Windows-
902        // path-leak footgun; use / for hierarchical refs"`) gates
903        // `:fonte :tag` / `:fonte :branch` against the same byte,
904        // and [`crate::render::is_gateway_api_http_path`] line 506
905        // includes `\` in the eleven-byte RFC-3986-reserved rejection
906        // set on `:entrada :paths`. Closing the same byte on `:fonte
907        // :caminho` makes the substrate-wide "no Windows path
908        // separator anywhere in a typed string slot" invariant
909        // structurally consistent across every path-shaped typed
910        // surface (the `:caminho` axis was the last typed string
911        // surface still admitting `\`).
912        //
913        // The arm fires AFTER the control-char arm because the
914        // control-char diagnostic is the more self-locating axis on
915        // values that probe as both (`"..\caixa\0teia"` carries both
916        // a `\` and a NUL — NUL is the load-bearing POSIX-syscall-
917        // rejected byte, so `FonteCaminhoControlChar` wins). Same
918        // narrower-diagnostic-first cascade discipline every prior
919        // arm establishes. A pure-`\` value
920        // (`"..\caixa-teia"` with no control bytes) falls through
921        // every prior arm and lands here.
922        for &b in caminho.as_bytes() {
923            if b == b'\\' {
924                return Err(DepError::FonteCaminhoBackslash {
925                    nome: nome.to_string(),
926                    caminho: caminho.to_string(),
927                });
928            }
929        }
930        // Reproducibility gate's shell-redirection arm. The 3a4e1d7 backslash
931        // arm closes the cross-host-OS-separator vector; `<` (`0x3C`) and `>`
932        // (`0x3E`) are the orthogonal shell-redirection sentinels — same
933        // paste-from-shell-prompt footgun class, different syntactic surface.
934        // POSIX `std::path::Path` treats `<` / `>` as literal bytes inside a
935        // single path component (so `../caixa-teia>output` is one directory
936        // named literally `../caixa-teia>output`, sibling of `.` and `..`),
937        // but every interactive shell (bash / zsh / fish / nushell) lexes
938        // `<` / `>` as input / output redirection operators — a `:caminho
939        // "../caixa-teia>build.log"` (the canonical "I pasted a shell
940        // pipeline that wrote build output and forgot to trim the redirect"
941        // footgun) or `:caminho "../<input.lisp"` (the symmetric input-
942        // redirection paste idiom) silently passes every prior arm because
943        // `Path::is_absolute` returns false, `<` / `>` are neither leading-
944        // byte sentinels nor control bytes nor `\`, and the value's last byte
945        // isn't `/`. The resolver folds the value through
946        // `Path::new(caminho).join(<file>)` looking for a literal
947        // `./..\caixa-teia>build.log` subdirectory and fails at resolve time
948        // with a non-self-locating `No such file or directory` error far
949        // from the source caixa.lisp.
950        //
951        // The lacre pipeline embeds the value verbatim in its per-dep
952        // content-address (`conteudo: format!("path:{caminho}")`,
953        // caixa-resolver/src/resolve.rs:189), so a `<` / `>` byte lands in
954        // the BLAKE3 closure and rides downstream as part of the build's
955        // identity. The bytes carry a second class of hazard the prior
956        // separator-shaped arms don't: every typed-string slot whose value
957        // ever flows verbatim into a shell-spawned subprocess (the caixa-
958        // resolver's `git clone` invocation, a future `feira tofu` shell-
959        // out, a future operator-side `nix flake check` spawn) is the
960        // canonical CRLF-at-subprocess-argument / shell-metachar injection
961        // surface that every peer single-token-shaped typed slot already
962        // closes. The peer path-shaped axis `[crate::render::is_gateway_api_http_path]`
963        // (caixa-core/src/render.rs:506) rejects `<` / `>` as part of its
964        // eleven-byte RFC-3986-reserved set on `:entrada :paths`, and the
965        // peer git-ref-shaped axis `[crate::render::is_git_ref_name]` rejects
966        // `<` / `>` on `:fonte :tag` / `:fonte :branch` under the same
967        // shell-metachar-injection banner. The `:caminho` axis was the last
968        // typed string surface still admitting these two bytes; this arm
969        // closes the gap so the substrate-wide "no shell-redirection
970        // metacharacter anywhere in a typed string slot" invariant is now
971        // structurally consistent across every path-shaped typed surface.
972        //
973        // The arm fires AFTER the control-char arm + backslash arm because
974        // both prior arms carry more self-locating diagnostics on values
975        // that probe as both (`"..\foo<bar"` carries both `\` and `<` — the
976        // cross-OS-separator divergence is the load-bearing axis, so the
977        // backslash arm wins; `"../foo\n<bar"` carries both LF and `<` —
978        // the POSIX-syscall-rejected byte is the load-bearing axis, so the
979        // control-char arm wins). The arm fires BEFORE the trailing-`/` arm
980        // because the embedded redirection byte is the more semantic-
981        // locating axis on probe-as-both values (`"../foo</"` ends in `/`
982        // but the load-bearing diagnostic is the embedded `<` shell-
983        // redirection — the trailing `/` is the secondary observation, and
984        // an author who removes the `<` is likely to also tab-strip the
985        // trailing separator).
986        for &b in caminho.as_bytes() {
987            if b == b'<' || b == b'>' {
988                return Err(DepError::FonteCaminhoShellRedirection {
989                    nome: nome.to_string(),
990                    caminho: caminho.to_string(),
991                    byte: b,
992                });
993            }
994        }
995        // Reproducibility gate's shell-pipe arm. The e457141 shell-redirection
996        // arm closes the `<` / `>` input/output redirection sentinels; `|`
997        // (`0x7C`) is the orthogonal shell-pipe sentinel — same paste-from-
998        // shell-prompt footgun class, different syntactic surface. POSIX
999        // `std::path::Path` treats `|` as a literal path-component byte (so
1000        // `../caixa-teia|tee` is one directory named literally
1001        // `../caixa-teia|tee`, sibling of `.` and `..`), but every interactive
1002        // shell (bash / zsh / fish / nushell) lexes `|` as the pipe operator
1003        // — a `:caminho "../caixa-teia | grep foo"` (the canonical "I copied a
1004        // `ls ../caixa-teia | grep` line out of a shell-history block and
1005        // forgot to trim the pipeline tail" footgun) or `:caminho
1006        // "../foo||bar"` (the symmetric "I copied a `cmd-a || cmd-b` short-
1007        // circuit OR line" idiom) silently passes every prior arm because
1008        // `Path::is_absolute` returns false on `..`, `|` is neither a leading-
1009        // byte sentinel nor a control byte nor `\` nor `<` / `>`, and the
1010        // value's last byte isn't `/`. The resolver folds the value through
1011        // `Path::new(caminho).join(<file>)` looking for a literal
1012        // `./../caixa-teia | grep foo` subdirectory and fails at resolve time
1013        // with a non-self-locating `No such file or directory` error far
1014        // from the source caixa.lisp.
1015        //
1016        // The lacre pipeline embeds the value verbatim in its per-dep
1017        // content-address (`conteudo: format!("path:{caminho}")`,
1018        // caixa-resolver/src/resolve.rs:189), so a `|` byte lands in the
1019        // BLAKE3 closure and rides downstream as part of the build's identity
1020        // into every shell-spawned subprocess (the caixa-resolver's `git
1021        // clone` invocation, a future `feira tofu` shell-out, a future
1022        // operator-side `nix flake check` spawn) as the canonical CRLF-at-
1023        // subprocess-argument / shell-metachar injection surface every peer
1024        // single-token-shaped typed slot already closes. The peer path-shaped
1025        // axis [`crate::render::is_gateway_api_http_path`]
1026        // (caixa-core/src/render.rs:506) rejects `|` as part of its eleven-
1027        // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1028        // axis was the last typed path-string surface still admitting this
1029        // byte; this arm closes the gap so the substrate-wide "no shell-
1030        // composition metacharacter anywhere in a typed string slot that
1031        // flows verbatim into a shell-spawned subprocess" invariant extends
1032        // from shell-redirection (`<` / `>`) to shell-pipe (`|`) on the
1033        // `:caminho` axis.
1034        //
1035        // The arm fires AFTER the shell-redirection arm because the prior
1036        // arm's two-byte `byte: u8` payload is the more self-locating axis on
1037        // values that probe as both (`"../caixa-teia<input|tee"` carries both
1038        // `<` and `|` — the input-redirection-paste idiom is the load-bearing
1039        // root-cause edit, so `FonteCaminhoShellRedirection` wins; same
1040        // cascade discipline every prior `:caminho` arm establishes). The arm
1041        // fires BEFORE the trailing-`/` arm because the embedded pipe byte is
1042        // the more semantic-locating axis on probe-as-both values
1043        // (`"../foo|tee/"` ends in `/` but the load-bearing diagnostic is the
1044        // embedded `|` shell-pipe — the trailing `/` is the secondary
1045        // observation, and an author who removes the `|` is likely to also
1046        // tab-strip the trailing separator).
1047        for &b in caminho.as_bytes() {
1048            if b == b'|' {
1049                return Err(DepError::FonteCaminhoShellPipe {
1050                    nome: nome.to_string(),
1051                    caminho: caminho.to_string(),
1052                });
1053            }
1054        }
1055        // Reproducibility gate's shell-command-separator arm. The 124106f
1056        // shell-pipe arm closes the `|` byte; `;` (`0x3B`) is the orthogonal
1057        // shell-command-separator sentinel — same paste-from-shell-prompt
1058        // footgun class, different syntactic surface. POSIX `std::path::Path`
1059        // treats `;` as a literal path-component byte (so
1060        // `../caixa-teia;rm -rf /` is one directory named literally
1061        // `../caixa-teia;rm -rf /`, sibling of `.` and `..`), but every
1062        // interactive shell (bash / zsh / fish / nushell) lexes `;` as the
1063        // sequential-command terminator that fires the next command
1064        // regardless of the prior command's exit status — a `:caminho
1065        // "../caixa-teia; rm -rf build"` (the canonical "I pasted a shell
1066        // one-liner that chained a cleanup tail after the directory name"
1067        // footgun) or `:caminho "../foo;;bar"` (the symmetric "I copied a
1068        // POSIX `case` arm's `;;` terminator into the middle of a path"
1069        // idiom) silently passes every prior arm because `Path::is_absolute`
1070        // returns false on `..`, `;` is neither a leading-byte sentinel nor a
1071        // control byte nor `\` nor `<` / `>` nor `|`, and the value's last
1072        // byte isn't `/`. The resolver folds the value through
1073        // `Path::new(caminho).join(<file>)` looking for a literal
1074        // `./../caixa-teia; rm -rf build` subdirectory and fails at resolve
1075        // time with a non-self-locating `No such file or directory` error far
1076        // from the source caixa.lisp.
1077        //
1078        // The lacre pipeline embeds the value verbatim in its per-dep
1079        // content-address (`conteudo: format!("path:{caminho}")`,
1080        // caixa-resolver/src/resolve.rs:189), so a `;` byte lands in the
1081        // BLAKE3 closure and rides downstream as part of the build's identity
1082        // into every shell-spawned subprocess (the caixa-resolver's `git
1083        // clone` invocation, a future `feira tofu` shell-out, a future
1084        // operator-side `nix flake check` spawn) as the canonical
1085        // shell-metachar injection surface every peer single-token-shaped
1086        // typed slot already closes. The peer path-shaped axis
1087        // [`crate::render::is_gateway_api_http_path`]
1088        // (caixa-core/src/render.rs:506) rejects `;` as part of its eleven-
1089        // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1090        // axis was the last typed path-string surface still admitting this
1091        // byte; this arm closes the gap so the substrate-wide "no shell-
1092        // composition metacharacter anywhere in a typed string slot that
1093        // flows verbatim into a shell-spawned subprocess" invariant extends
1094        // from shell-pipe (`|`) to shell-command-separator (`;`) on the
1095        // `:caminho` axis.
1096        //
1097        // The arm fires AFTER the shell-pipe arm because the prior arm's
1098        // canonical-cmd-a-|-cmd-b shape is the more common shell-history
1099        // paste idiom on values that probe as both (`"../caixa-teia | tee;
1100        // rm"` carries both `|` and `;` — the pipeline-tail paste is the
1101        // load-bearing root-cause edit, so `FonteCaminhoShellPipe` wins; same
1102        // cascade discipline every prior `:caminho` arm establishes). The arm
1103        // fires BEFORE the trailing-`/` arm because the embedded
1104        // command-separator byte is the more semantic-locating axis on
1105        // probe-as-both values (`"../foo;rm/"` ends in `/` but the
1106        // load-bearing diagnostic is the embedded `;` shell-command-
1107        // separator — the trailing `/` is the secondary observation, and an
1108        // author who removes the `;` is likely to also tab-strip the trailing
1109        // separator).
1110        for &b in caminho.as_bytes() {
1111            if b == b';' {
1112                return Err(DepError::FonteCaminhoShellSemicolon {
1113                    nome: nome.to_string(),
1114                    caminho: caminho.to_string(),
1115                });
1116            }
1117        }
1118        // Reproducibility gate's shell-background / logical-AND arm. The
1119        // 05c358e shell-command-separator arm closes the `;` byte; `&`
1120        // (`0x26`) is the orthogonal shell-background / list-AND sentinel
1121        // — same paste-from-shell-prompt footgun class, different
1122        // syntactic surface. POSIX `std::path::Path` treats `&` as a
1123        // literal path-component byte (so `../caixa-teia & sleep 1` is
1124        // one directory named literally `../caixa-teia & sleep 1`,
1125        // sibling of `.` and `..`), but every interactive shell
1126        // (bash / zsh / fish / nushell) lexes `&` two ways:
1127        //
1128        //   - Single `&` as the background-task terminator that detaches
1129        //     the prior command into the background and returns control
1130        //     to the prompt immediately (the canonical `cmd &` idiom
1131        //     every long-running pipeline uses);
1132        //   - Double `&&` as the logical-AND list operator that fires
1133        //     the next command only if the prior command succeeded (the
1134        //     canonical `make && make install` idiom every build script
1135        //     carries).
1136        //
1137        // A `:caminho "../caixa-teia & sleep 1"` (the canonical "I
1138        // pasted a `cd path & sleep 1` background-launch into the
1139        // `:caminho` slot" footgun) or `:caminho "../caixa-teia && make"`
1140        // (the symmetric "I copied a `cd path && make` build chain"
1141        // idiom) silently passes every prior arm because
1142        // `Path::is_absolute` returns false on `..`, `&` is neither a
1143        // leading-byte sentinel nor a control byte nor `\` nor
1144        // `<` / `>` nor `|` nor `;`, and the value's last byte isn't `/`.
1145        // The resolver folds the value through
1146        // `Path::new(caminho).join(<file>)` looking for a literal
1147        // `./../caixa-teia & sleep 1` subdirectory and fails at resolve
1148        // time with a non-self-locating `No such file or directory`
1149        // error far from the source caixa.lisp.
1150        //
1151        // The lacre pipeline embeds the value verbatim in its per-dep
1152        // content-address (`conteudo: format!("path:{caminho}")`,
1153        // caixa-resolver/src/resolve.rs:189), so an `&` byte lands in
1154        // the BLAKE3 closure and rides downstream as part of the build's
1155        // identity into every shell-spawned subprocess (the
1156        // caixa-resolver's `git clone` invocation, a future `feira tofu`
1157        // shell-out, a future operator-side `nix flake check` spawn) as
1158        // the canonical shell-metachar injection surface every peer
1159        // single-token-shaped typed slot already closes. The peer
1160        // path-shaped axis [`crate::render::is_gateway_api_http_path`]
1161        // (caixa-core/src/render.rs:506) rejects `&` as part of its
1162        // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1163        // `:caminho` axis was the last typed path-string surface still
1164        // admitting this byte; this arm closes the gap so the
1165        // substrate-wide "no shell-composition metacharacter anywhere
1166        // in a typed string slot that flows verbatim into a
1167        // shell-spawned subprocess" invariant extends from
1168        // shell-command-separator (`;`) to shell-background /
1169        // logical-AND (`&`) on the `:caminho` axis.
1170        //
1171        // The arm fires AFTER the shell-command-separator arm because
1172        // the prior arm's `cmd-a; cmd-b` shape is the more common
1173        // shell-history paste idiom on values that probe as both
1174        // (`"../caixa-teia; rm & sleep"` carries both `;` and `&` — the
1175        // command-separator-tail paste is the load-bearing root-cause
1176        // edit, so `FonteCaminhoShellSemicolon` wins; same cascade
1177        // discipline every prior `:caminho` arm establishes). The arm
1178        // fires BEFORE the trailing-`/` arm because the embedded
1179        // background / list-AND byte is the more semantic-locating axis
1180        // on probe-as-both values (`"../foo&bar/"` ends in `/` but the
1181        // load-bearing diagnostic is the embedded `&` shell-background
1182        // / logical-AND metachar — the trailing `/` is the secondary
1183        // observation, and an author who removes the `&` is likely to
1184        // also tab-strip the trailing separator).
1185        for &b in caminho.as_bytes() {
1186            if b == b'&' {
1187                return Err(DepError::FonteCaminhoShellBackground {
1188                    nome: nome.to_string(),
1189                    caminho: caminho.to_string(),
1190                });
1191            }
1192        }
1193        // Reproducibility gate's shell-command-substitution arm. The
1194        // e12e4f3 shell-background / logical-AND arm closes the `&`
1195        // byte; the backtick (`0x60`) is the orthogonal POSIX legacy
1196        // command-substitution sentinel — every POSIX shell (sh /
1197        // bash / zsh / dash / ksh / fish / nushell) lexes the byte as
1198        // the canonical legacy wrapper that runs the enclosed command
1199        // and substitutes its standard-output verbatim into the
1200        // surrounding word (a `whoami` wrapped in backticks expands
1201        // to the current user's name; a `cat /etc/passwd` wrapped in
1202        // backticks expands to the file's contents — the canonical
1203        // CWE-78 shell-command-injection vector every shell-side
1204        // hardening guide enumerates first). POSIX
1205        // `std::path::Path` treats backtick as a literal path-
1206        // component byte (so `../caixa-teia/<backtick>whoami<backtick>`
1207        // is one directory named literally that, sibling of `.` and
1208        // `..`).
1209        //
1210        // A `:caminho "../caixa-teia/<backtick>whoami<backtick>"` (the
1211        // canonical "I pasted a shell one-liner carrying a backticked
1212        // `whoami` command-substitution expansion into the `:caminho`
1213        // slot" footgun) or `:caminho "<backtick>pwd<backtick>/caixa-
1214        // teia"` (the symmetric "I copied a `<backtick>pwd<backtick>/
1215        // path` working-directory expansion") silently passes every
1216        // prior arm because `Path::is_absolute` returns false on
1217        // `..`, the backtick byte is neither a leading-byte sentinel
1218        // (the f4efe9c `FonteCaminhoVarExpansion` arm catches the
1219        // modern `$()` form at leading position only; backtick is
1220        // the orthogonal legacy form) nor a control byte nor `\` nor
1221        // `<` / `>` nor `|` nor `;` nor `&`, and the value's last
1222        // byte isn't `/`. The resolver folds the value through
1223        // `Path::new(caminho).join(<file>)` looking for a literal
1224        // subdirectory whose name embeds the backticked token and
1225        // fails at resolve time with a non-self-locating `No such
1226        // file or directory` error far from the source caixa.lisp.
1227        //
1228        // The lacre pipeline embeds the value verbatim in its per-
1229        // dep content-address (`conteudo: format!("path:{caminho}")`,
1230        // caixa-resolver/src/resolve.rs:189), so a backtick byte
1231        // lands in the BLAKE3 closure and rides downstream as part
1232        // of the build's identity into every shell-spawned
1233        // subprocess (the caixa-resolver's `git clone` invocation, a
1234        // future `feira tofu` shell-out, a future operator-side
1235        // `nix flake check` spawn) as the canonical shell-metachar
1236        // injection surface every peer single-token-shaped typed
1237        // slot already closes. The peer path-shaped axis
1238        // [`crate::render::is_gateway_api_http_path`]
1239        // (caixa-core/src/render.rs:506) rejects backtick as part of
1240        // its eleven-byte RFC-3986-reserved set on `:entrada
1241        // :paths`. The `:caminho` axis was the last typed path-
1242        // string surface still admitting this byte; this arm closes
1243        // the gap so the substrate-wide "no shell-composition
1244        // metacharacter anywhere in a typed string slot that flows
1245        // verbatim into a shell-spawned subprocess" invariant
1246        // extends from shell-background / logical-AND (`&`) to
1247        // shell-command-substitution (backtick) on the `:caminho`
1248        // axis.
1249        //
1250        // The arm fires AFTER the shell-background arm because the
1251        // prior arm's `cmd & sleep` shape is the more common shell-
1252        // history paste idiom on values that probe as both (a
1253        // `"../caixa-teia & <backtick>whoami<backtick>"` carries
1254        // both `&` and a backtick — the background-launch tail is
1255        // the load-bearing root-cause edit, so
1256        // `FonteCaminhoShellBackground` wins; same cascade
1257        // discipline every prior `:caminho` arm establishes). The
1258        // arm fires BEFORE the trailing-`/` arm because the
1259        // embedded command-substitution byte is the more semantic-
1260        // locating axis on probe-as-both values (a
1261        // `"../<backtick>whoami<backtick>/"` ends in `/` but the
1262        // load-bearing diagnostic is the embedded backtick shell-
1263        // command-substitution metachar — the trailing `/` is the
1264        // secondary observation, and an author who removes the
1265        // backtick is likely to also tab-strip the trailing
1266        // separator).
1267        for &b in caminho.as_bytes() {
1268            if b == b'`' {
1269                return Err(DepError::FonteCaminhoShellCommandSubstitution {
1270                    nome: nome.to_string(),
1271                    caminho: caminho.to_string(),
1272                });
1273            }
1274        }
1275        // Reproducibility gate's shell-glob arm. The c4d62b3 shell-command-
1276        // substitution arm closes the backtick byte; `*` (`0x2A`) and `?`
1277        // (`0x3F`) are the orthogonal POSIX glob-expansion sentinels — same
1278        // paste-from-shell-prompt footgun class, different syntactic surface.
1279        // Every POSIX shell (sh / bash / zsh / dash / ksh / fish / nushell)
1280        // lexes `*` and `?` as pathname-expansion wildcards: `*` matches any
1281        // sequence of characters in a path component (including the empty
1282        // sequence), `?` matches exactly one character. POSIX
1283        // `std::path::Path` treats both bytes as literal path-component bytes
1284        // (so `../caixa-teia/*.lisp` is one directory named literally
1285        // `../caixa-teia/*.lisp`, sibling of `.` and `..`).
1286        //
1287        // A `:caminho "../caixa-teia/*"` (the canonical "I pasted a
1288        // `ls ../caixa-teia/*` shell-listing one-liner into the `:caminho`
1289        // slot" footgun) or `:caminho "../foo?"` (the symmetric "I copied a
1290        // `rm foo?` single-char-wildcard removal idiom") silently passes
1291        // every prior arm because `Path::is_absolute` returns false on `..`,
1292        // `*` / `?` are neither leading-byte sentinels nor control bytes nor
1293        // `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick, and the
1294        // value's last byte isn't `/`. The resolver folds the value through
1295        // `Path::new(caminho).join(<file>)` looking for a literal
1296        // `./../caixa-teia/*` subdirectory and fails at resolve time with a
1297        // non-self-locating `No such file or directory` error far from the
1298        // source caixa.lisp.
1299        //
1300        // The lacre pipeline embeds the value verbatim in its per-dep
1301        // content-address (`conteudo: format!("path:{caminho}")`,
1302        // caixa-resolver/src/resolve.rs:189), so a `*` or `?` byte lands in
1303        // the BLAKE3 closure and rides downstream as part of the build's
1304        // identity into every shell-spawned subprocess (the caixa-resolver's
1305        // `git clone` invocation, a future `feira tofu` shell-out, a future
1306        // operator-side `nix flake check` spawn) as the canonical
1307        // shell-metachar / pathname-expansion surface every peer
1308        // single-token-shaped typed slot already closes. The peer path-shaped
1309        // axis [`crate::render::is_gateway_api_http_path`]
1310        // (caixa-core/src/render.rs:506) rejects `*` and `?` as part of its
1311        // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1312        // `:caminho` axis was the last typed path-string surface still
1313        // admitting these two bytes; this arm closes the gap so the
1314        // substrate-wide "no shell-composition / glob-expansion
1315        // metacharacter anywhere in a typed string slot that flows verbatim
1316        // into a shell-spawned subprocess" invariant extends from
1317        // shell-command-substitution (backtick) to glob-expansion
1318        // (`*` / `?`) on the `:caminho` axis.
1319        //
1320        // The arm fires AFTER the backtick arm because the prior arm's
1321        // CWE-78 shell-command-injection vector is the load-bearing
1322        // diagnostic on values that probe as both (a `"../`whoami`/*"`
1323        // carries both backtick and `*` — the command-substitution paste
1324        // is the load-bearing root-cause edit, so
1325        // `FonteCaminhoShellCommandSubstitution` wins; same cascade
1326        // discipline every prior `:caminho` arm establishes). The arm
1327        // fires BEFORE the trailing-`/` arm because the embedded glob
1328        // byte is the more semantic-locating axis on probe-as-both values
1329        // (`"../foo*/"` ends in `/` but the load-bearing diagnostic is the
1330        // embedded `*` glob metachar — the trailing `/` is the secondary
1331        // observation, and an author who removes the `*` is likely to
1332        // also tab-strip the trailing separator).
1333        for &b in caminho.as_bytes() {
1334            if b == b'*' || b == b'?' {
1335                return Err(DepError::FonteCaminhoShellGlob {
1336                    nome: nome.to_string(),
1337                    caminho: caminho.to_string(),
1338                    byte: b,
1339                });
1340            }
1341        }
1342        // Reproducibility gate's shell-subshell-grouping arm. The cf9034b
1343        // shell-glob arm closes the `*` / `?` pathname-expansion sentinels;
1344        // `(` (`0x28`) and `)` (`0x29`) are the orthogonal POSIX subshell-
1345        // grouping sentinels — same paste-from-shell-prompt footgun class,
1346        // different syntactic surface. Every POSIX shell (sh / bash / zsh /
1347        // dash / ksh / fish / nushell) lexes the parenthesis pair as the
1348        // subshell-grouping operator: `(<cmd>)` runs `<cmd>` in a child
1349        // shell with a fresh environment scope (the canonical sandboxing
1350        // idiom every shell-history `(cd <path> && <cmd>)` one-liner uses
1351        // to scope a `cd` to one subshell without disturbing the parent's
1352        // working directory), and `$(<cmd>)` is the modern Bourne
1353        // command-substitution shape the upstream f4efe9c
1354        // `FonteCaminhoVarExpansion` arm closes the leading `$` byte of —
1355        // the closing `)` byte completes that substitution shape and must
1356        // be refused on the same axis (peer with the
1357        // [`crate::render::is_git_repo_url`] 3b99147 arm that closes the
1358        // same byte-pair on the sibling `:fonte :repo` axis under the
1359        // same shell-subshell-grouping + RFC-3986-sub-delims banner).
1360        // POSIX `std::path::Path` treats both bytes as literal path-
1361        // component bytes (so `../caixa-teia/(date)` is one directory
1362        // named literally `../caixa-teia/(date)`, sibling of `.` and
1363        // `..`).
1364        //
1365        // A `:caminho "../caixa-teia/$(date)/build"` (the canonical "I
1366        // pasted a `cd ../caixa-teia/$(date)/build` shell-history one-
1367        // liner whose modern command-substitution expansion lands the
1368        // current date as a subdirectory name" footgun) or `:caminho
1369        // "../(cd foo && pwd)/caixa-teia"` (the symmetric "I copied a
1370        // `(cd foo && pwd)` subshell-grouping working-directory probe
1371        // idiom") silently passes every prior arm because
1372        // `Path::is_absolute` returns false on `..`, `(` / `)` are
1373        // neither leading-byte sentinels nor control bytes nor `\` nor
1374        // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` / `?`,
1375        // and the value's last byte isn't `/`. The resolver folds the
1376        // value through `Path::new(caminho).join(<file>)` looking for a
1377        // literal `./../caixa-teia/$(date)/build` subdirectory and fails
1378        // at resolve time with a non-self-locating `No such file or
1379        // directory` error far from the source caixa.lisp.
1380        //
1381        // The lacre pipeline embeds the value verbatim in its per-dep
1382        // content-address (`conteudo: format!("path:{caminho}")`,
1383        // caixa-resolver/src/resolve.rs:189), so a `(` or `)` byte lands
1384        // in the BLAKE3 closure and rides downstream as part of the
1385        // build's identity into every shell-spawned subprocess (the
1386        // caixa-resolver's `git clone` invocation, a future `feira tofu`
1387        // shell-out, a future operator-side `nix flake check` spawn) as
1388        // the canonical shell-metachar / subshell-grouping surface every
1389        // peer single-token-shaped typed slot already closes. The peer
1390        // git-source axis [`crate::render::is_git_repo_url`] (3b99147)
1391        // rejects the same byte pair on `:fonte :repo` under the same
1392        // shell-subshell-grouping / RFC-3986-sub-delims banner. The
1393        // `:caminho` axis was the last typed path-string surface still
1394        // admitting these two bytes;
1395        // this arm closes the gap so the substrate-wide "no shell-
1396        // composition metacharacter anywhere in a typed string slot that
1397        // flows verbatim into a shell-spawned subprocess" invariant
1398        // extends from shell-glob (`*` / `?`) to shell-subshell-grouping
1399        // (`(` / `)`) on the `:caminho` axis. Together with the f4efe9c
1400        // leading-`$` arm, the typed `:caminho` accepted set now
1401        // structurally excludes the entire modern Bourne
1402        // command-substitution surface — leading `$` closes the
1403        // leading byte of every `$(<cmd>)` shape, this arm closes the
1404        // trailing `)` boundary.
1405        //
1406        // The arm fires AFTER the shell-glob arm because the prior arm's
1407        // `*` / `?` pathname-expansion shape is the more common shell-
1408        // history paste idiom on values that probe as both
1409        // (`"../caixa-teia/*(date)"` carries both `*` and `(` — the
1410        // glob-paste-tail is the load-bearing root-cause edit, so
1411        // `FonteCaminhoShellGlob` wins; same cascade discipline every
1412        // prior `:caminho` arm establishes). The arm fires BEFORE the
1413        // trailing-`/` arm because the embedded subshell-grouping byte
1414        // is the more semantic-locating axis on probe-as-both values
1415        // (`"../foo(date)/"` ends in `/` but the load-bearing diagnostic
1416        // is the embedded `(` shell-subshell-grouping metachar — the
1417        // trailing `/` is the secondary observation, and an author who
1418        // removes the `(` is likely to also tab-strip the trailing
1419        // separator).
1420        for &b in caminho.as_bytes() {
1421            if b == b'(' || b == b')' {
1422                return Err(DepError::FonteCaminhoShellSubshellGrouping {
1423                    nome: nome.to_string(),
1424                    caminho: caminho.to_string(),
1425                    byte: b,
1426                });
1427            }
1428        }
1429        // Reproducibility gate's shell-brace-expansion arm. The 0633c91
1430        // shell-subshell-grouping arm closes `(` / `)`; `{` (`0x7b`) and
1431        // `}` (`0x7d`) are the orthogonal shell-brace-expansion /
1432        // URI-Template-placeholder byte pair — same paste-from-shell-
1433        // prompt + paste-from-templated-doc footgun class, different
1434        // syntactic surface. Every POSIX-derived shell that implements
1435        // brace expansion (bash / zsh / ksh / fish; the canonical
1436        // `mkdir -p ../{caixa-teia,caixa-helm,caixa-flux}` /
1437        // `cp file{,.bak}` idiom every shell-history block carries)
1438        // expands `{a,b,c}` to the cross-product of its comma-separated
1439        // members and `{1..10}` to the integer range; RFC 6570 reserves
1440        // the matched pair for URI Template placeholders (the canonical
1441        // `https://{host}/{org}/{repo}` substitution shape every
1442        // OpenAPI / Swagger / Postman / GitHub Octokit client /
1443        // Helm chart-URL fragment / Mustache `{{org}}` doubled-brace
1444        // form carries), and Tera / Jinja2 / Handlebars / Go html/template
1445        // every IaC tool (Helm, Kustomize, Terraform's `${var}` cousin
1446        // shape) emit. POSIX `std::path::Path` treats both bytes as
1447        // literal path-component bytes (so `../{caixa-teia,caixa-helm}`
1448        // is one directory named literally `../{caixa-teia,caixa-helm}`,
1449        // sibling of `.` and `..`).
1450        //
1451        // A `:caminho "../{caixa-teia,caixa-helm}/build"` (the canonical
1452        // "I pasted a `cd ../{caixa-teia,caixa-helm}` shell brace-
1453        // expansion one-liner that fans across two siblings" footgun)
1454        // or `:caminho "../{{org}}/caixa-teia"` (the symmetric "I copied
1455        // a `{{org}}` Mustache / Helm template placeholder out of a
1456        // README quick-start and forgot to substitute") silently passes
1457        // every prior arm because `Path::is_absolute` returns false on
1458        // `..`, `{` / `}` are neither leading-byte sentinels nor control
1459        // bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor
1460        // backtick nor `*` / `?` nor `(` / `)`, and the value's last
1461        // byte isn't `/`. The resolver folds the value through
1462        // `Path::new(caminho).join(<file>)` looking for a literal
1463        // `./../{caixa-teia,caixa-helm}/build` subdirectory and fails
1464        // at resolve time with a non-self-locating `No such file or
1465        // directory` error far from the source caixa.lisp.
1466        //
1467        // The lacre pipeline embeds the value verbatim in its per-dep
1468        // content-address (`conteudo: format!("path:{caminho}")`,
1469        // caixa-resolver/src/resolve.rs:189), so a `{` or `}` byte
1470        // lands in the BLAKE3 closure and rides downstream as part of
1471        // the build's identity into every shell-spawned subprocess
1472        // (the caixa-resolver's `git clone` invocation, a future
1473        // `feira tofu` shell-out, a future operator-side `nix flake
1474        // check` spawn) as the canonical shell-metachar / brace-
1475        // expansion surface every peer single-token-shaped typed
1476        // slot already closes. The peer git-source axis
1477        // [`crate::render::is_git_repo_url`] (42d8f9d — the URI Template
1478        // placeholder arm) rejects the same byte pair on `:fonte :repo`
1479        // under the same RFC-3986-'delims' / RFC-6570-URI-Template /
1480        // shell-brace-expansion banner. The `:caminho` axis was the last
1481        // typed path-string surface still admitting these two bytes;
1482        // this arm closes the gap so the substrate-wide "no shell-
1483        // composition metacharacter anywhere in a typed string slot
1484        // that flows verbatim into a shell-spawned subprocess"
1485        // invariant extends from shell-subshell-grouping (`(` / `)`)
1486        // to shell-brace-expansion (`{` / `}`) on the `:caminho` axis,
1487        // and the typed `:caminho` accepted set now also structurally
1488        // excludes the URI Template / templating-engine placeholder
1489        // surface that would silently round-trip through any
1490        // downstream IaC templating-engine layer.
1491        //
1492        // The arm fires AFTER the shell-subshell-grouping arm because
1493        // the prior arm's `(` / `)` shape is the more semantic-locating
1494        // axis on values that probe as both (`"../{cd foo}(date)"`
1495        // carries both `{` and `(` — the parenthesis-pair is the
1496        // load-bearing modern-Bourne-command-substitution surface the
1497        // prior arm closes; same cascade discipline every prior
1498        // `:caminho` arm establishes). The arm fires BEFORE the
1499        // trailing-`/` arm because the embedded brace-expansion byte
1500        // is the more semantic-locating axis on probe-as-both values
1501        // (`"../{caixa-teia,caixa-helm}/"` ends in `/` but the
1502        // load-bearing diagnostic is the embedded `{` brace-expansion
1503        // metachar — the trailing `/` is the secondary observation,
1504        // and an author who removes the `{` is likely to also tab-
1505        // strip the trailing separator).
1506        for &b in caminho.as_bytes() {
1507            if b == b'{' || b == b'}' {
1508                return Err(DepError::FonteCaminhoShellBraceExpansion {
1509                    nome: nome.to_string(),
1510                    caminho: caminho.to_string(),
1511                    byte: b,
1512                });
1513            }
1514        }
1515        // Reproducibility gate's shell-bracket-expansion arm. The 598b770
1516        // shell-brace-expansion arm closes `{` / `}`; `[` (`0x5b`) and
1517        // `]` (`0x5d`) are the orthogonal POSIX glob-character-class /
1518        // shell-`test`-builtin byte pair — same paste-from-shell-prompt
1519        // footgun class, different syntactic surface. Every POSIX shell
1520        // (sh / bash / zsh / dash / ksh / fish / nushell) lexes the
1521        // bracket pair as the glob character-class operator: `[abc]`
1522        // matches one of `a`, `b`, `c`; `[a-z]` matches any lowercase
1523        // ASCII letter; `[^x]` negates (the canonical
1524        // `ls *.[ch]` C-source-file glob and the `cd ../[a-z]*`
1525        // lowercase-sibling glob every shell-history block carries —
1526        // the orthogonal axis to the cf9034b `*` / `?` shell-glob arm
1527        // closing the unbounded pathname-expansion sentinels). The
1528        // bracket pair additionally carries the POSIX `test` /
1529        // `[` builtin command (`[ -d ../caixa-teia ] && cd ...` —
1530        // the canonical idiom every shell-script conditional uses) and
1531        // bash's `[[ ... ]]` extended-test grammar. Beyond shell, the
1532        // bracket pair is the TOML inline-array delimiter
1533        // (`features = ["a", "b"]` — the canonical paste-from-Cargo-
1534        // manifest cross-idiom-leak vector), the YAML flow-sequence
1535        // delimiter (`paths: [/a, /b]` — the canonical paste-from-
1536        // values.yaml cross-idiom leak), the JSON array delimiter,
1537        // and the POSIX-ERE / PCRE bracket-expression / character-
1538        // class anchor (the canonical paste-from-regex-doc shape).
1539        // POSIX `std::path::Path` treats both bytes as literal path-
1540        // component bytes (so `../[caixa-teia]` is one directory
1541        // named literally `../[caixa-teia]`, sibling of `.` and
1542        // `..`).
1543        //
1544        // A `:caminho "../caixa-[a-z]/build"` (the canonical "I
1545        // pasted a `cd ../caixa-[a-z]/build` glob-character-class
1546        // one-liner that matches every lowercase-sibling-suffix
1547        // sibling directory" footgun), `:caminho "../[caixa-teia]/
1548        // build"` (the symmetric "I pasted a TOML inline-array /
1549        // YAML flow-sequence shape out of an aligned manifest"
1550        // idiom), or `:caminho "../caixa-[ch]"` (the canonical
1551        // `*.[ch]` C-source character-class paste-from-shell-history
1552        // shape) silently passes every prior arm because
1553        // `Path::is_absolute` returns false on `..`, `[` / `]` are
1554        // neither leading-byte sentinels nor control bytes nor `\`
1555        // nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1556        // `*` / `?` nor `(` / `)` nor `{` / `}`, and the value's
1557        // last byte isn't `/`. The resolver folds the value through
1558        // `Path::new(caminho).join(<file>)` looking for a literal
1559        // `./../caixa-[a-z]/build` subdirectory and fails at resolve
1560        // time with a non-self-locating `No such file or directory`
1561        // error far from the source caixa.lisp.
1562        //
1563        // The lacre pipeline embeds the value verbatim in its per-dep
1564        // content-address (`conteudo: format!("path:{caminho}")`,
1565        // caixa-resolver/src/resolve.rs:189), so a `[` or `]` byte
1566        // lands in the BLAKE3 closure and rides downstream as part of
1567        // the build's identity into every shell-spawned subprocess
1568        // (the caixa-resolver's `git clone` invocation, a future
1569        // `feira tofu` shell-out, a future operator-side `nix flake
1570        // check` spawn) as the canonical shell-metachar / glob-
1571        // character-class / TOML-array surface every peer single-
1572        // token-shaped typed slot already closes. The `:caminho` axis
1573        // was the last typed path-string surface still admitting
1574        // these two bytes; this arm closes the gap so the substrate-
1575        // wide "no shell-composition metacharacter anywhere in a
1576        // typed string slot that flows verbatim into a shell-spawned
1577        // subprocess" invariant extends from shell-brace-expansion
1578        // (`{` / `}`) to shell-bracket-expansion (`[` / `]`) on the
1579        // `:caminho` axis. Together with the cf9034b `*` / `?` arm,
1580        // the typed `:caminho` accepted set now structurally excludes
1581        // the entire POSIX pathname-expansion / glob surface —
1582        // unbounded glob (`*` / `?`) AND bounded character-class
1583        // (`[abc]` / `[a-z]`).
1584        //
1585        // The arm fires AFTER the shell-brace-expansion arm because
1586        // the prior arm's `{` / `}` shape is the more semantic-
1587        // locating axis on values that probe as both
1588        // (`"../{a,b}[ch]"` carries both `{` and `[` — the brace-
1589        // expansion fan is the load-bearing root-cause edit, so
1590        // `FonteCaminhoShellBraceExpansion` wins; same cascade
1591        // discipline every prior `:caminho` arm establishes). The arm
1592        // fires BEFORE the trailing-`/` arm because the embedded
1593        // bracket-expansion byte is the more semantic-locating axis
1594        // on probe-as-both values (`"../[a-z]/"` ends in `/` but the
1595        // load-bearing diagnostic is the embedded `[` glob-character-
1596        // class metachar — the trailing `/` is the secondary
1597        // observation, and an author who removes the `[` is likely
1598        // to also tab-strip the trailing separator).
1599        for &b in caminho.as_bytes() {
1600            if b == b'[' || b == b']' {
1601                return Err(DepError::FonteCaminhoShellBracketExpansion {
1602                    nome: nome.to_string(),
1603                    caminho: caminho.to_string(),
1604                    byte: b,
1605                });
1606            }
1607        }
1608        // Reproducibility gate's shell-quote-grouping arm. The 986963b
1609        // shell-bracket-expansion arm closes `[` / `]`; `'` (`0x27`) and
1610        // `"` (`0x22`) are the orthogonal POSIX shell-string-literal
1611        // delimiter pair — same paste-from-shell-prompt footgun class,
1612        // different syntactic surface. Every POSIX shell (sh / bash /
1613        // zsh / dash / ksh / fish / nushell) lexes the pair as the
1614        // string-literal quoting operator: `'…'` is the strong
1615        // (no-expansion) single-quoted string and `"…"` is the weak
1616        // (variable-/command-substitution-preserving) double-quoted
1617        // string — the canonical `cd '../caixa-teia'` shell-history
1618        // idiom every path-with-embedded-whitespace paste block carries,
1619        // and the symmetric `git clone "$REPO"` weak-quoted CI-manifest
1620        // shape. Beyond shell, the two bytes carry the JSON string-literal
1621        // delimiter (`"key": "value"` — the canonical paste-from-JSON-
1622        // config cross-idiom-leak vector), the YAML double-quoted +
1623        // single-quoted flow-scalar delimiters (`path: "../caixa-teia"`
1624        // — the canonical paste-from-values.yaml / paste-from-K8s-YAML-
1625        // manifest cross-idiom leak), the TOML basic + literal string
1626        // delimiters (`path = "../caixa-teia"` — the canonical paste-
1627        // from-Cargo-manifest cross-idiom-leak vector), the tatara-lisp
1628        // string-literal delimiter itself (`(:caminho "../caixa-teia")`
1629        // — the canonical "I copied the entire `:caminho "..."` slot
1630        // rather than just the string body" author-surface footgun),
1631        // and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which
1632        // excludes both bytes from the `unreserved / pct-encoded /
1633        // sub-delims / ":" / "@"` `pchar` production. POSIX
1634        // `std::path::Path` treats both bytes as literal path-component
1635        // bytes (so `../"caixa-teia"` is one directory named literally
1636        // `../"caixa-teia"`, sibling of `.` and `..`).
1637        //
1638        // A `:caminho "'../caixa-teia'"` (the canonical "I pasted a
1639        // `cd '../caixa-teia'` shell-history one-liner whose strong-
1640        // quoting preserved the sibling-workspace path verbatim across
1641        // the whitespace paste boundary" footgun), `:caminho
1642        // "\"../caixa-teia\""` (the symmetric weak-quoted paste-from-
1643        // JSON / paste-from-YAML flow-scalar / paste-from-TOML basic-
1644        // string / paste-from-tatara-lisp string-literal cross-idiom-
1645        // leak shape), or `:caminho "../\"caixa-teia\""` (the embedded-
1646        // quote "I pasted a JSON key-value pair fragment into the
1647        // middle of the path" idiom) silently passes every prior arm
1648        // because `Path::is_absolute` returns false on `..` / `'` /
1649        // `"`, `'` / `"` are neither leading-byte sentinels nor
1650        // control bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&`
1651        // nor backtick nor `*` / `?` nor `(` / `)` nor `{` / `}` nor
1652        // `[` / `]`, and the value's last byte isn't `/`. The resolver
1653        // folds the value through `Path::new(caminho).join(<file>)`
1654        // looking for a literal `./'../caixa-teia'` subdirectory and
1655        // fails at resolve time with a non-self-locating `No such file
1656        // or directory` error far from the source caixa.lisp.
1657        //
1658        // The lacre pipeline embeds the value verbatim in its per-dep
1659        // content-address (`conteudo: format!("path:{caminho}")`,
1660        // caixa-resolver/src/resolve.rs:189), so a `'` or `"` byte
1661        // lands in the BLAKE3 closure and rides downstream as part of
1662        // the build's identity into every shell-spawned subprocess
1663        // (the caixa-resolver's `git clone` invocation, a future
1664        // `feira tofu` shell-out, a future operator-side `nix flake
1665        // check` spawn) as the canonical shell-metachar / string-
1666        // literal-delimiter surface every peer single-token-shaped
1667        // typed slot already closes. The peer `:fonte :repo` axis
1668        // closes both bytes under the same shell-quote-grouping /
1669        // RFC-3986-sub-delims banner (e7a109f `'` shell-single-quote
1670        // + 4267d8b `"` shell-double-quote on `is_git_repo_url`). The
1671        // `:caminho` axis was the last typed path-string surface
1672        // still admitting these two bytes; this arm closes the gap
1673        // so the substrate-wide "no shell-composition metacharacter
1674        // anywhere in a typed string slot that flows verbatim into a
1675        // shell-spawned subprocess" invariant extends from shell-
1676        // bracket-expansion (`[` / `]`) to shell-quote-grouping (`'`
1677        // / `"`) on the `:caminho` axis. Together with the peer
1678        // JSON / YAML / TOML string-literal delimiters closing at
1679        // this arm and the 598b770 `{` / `}` brace-expansion arm
1680        // closing the templating-engine-placeholder boundary, the
1681        // typed `:caminho` accepted set now structurally excludes
1682        // the entire cross-config-DSL string-literal / templating
1683        // paste-from-aligned-manifest cross-idiom-leak surface that
1684        // would silently round-trip through any downstream JSON /
1685        // YAML / TOML / HCL / tatara-lisp parsing layer.
1686        //
1687        // The arm fires AFTER the shell-bracket-expansion arm because
1688        // the prior arm's `[` / `]` shape is the more semantic-
1689        // locating axis on values that probe as both (`"../[a-z]'x'"`
1690        // carries both `[` and `'` — the glob-character-class
1691        // expansion is the load-bearing root-cause edit, so
1692        // `FonteCaminhoShellBracketExpansion` wins; same cascade
1693        // discipline every prior `:caminho` arm establishes). The arm
1694        // fires BEFORE the trailing-`/` arm because the embedded
1695        // quote-grouping byte is the more semantic-locating axis on
1696        // probe-as-both values (`"../'caixa-teia'/"` ends in `/` but
1697        // the load-bearing diagnostic is the embedded `'` shell-
1698        // string-literal metachar — the trailing `/` is the secondary
1699        // observation, and an author who removes the `'` is likely to
1700        // also tab-strip the trailing separator).
1701        for &b in caminho.as_bytes() {
1702            if b == b'\'' || b == b'"' {
1703                return Err(DepError::FonteCaminhoShellQuoteGrouping {
1704                    nome: nome.to_string(),
1705                    caminho: caminho.to_string(),
1706                    byte: b,
1707                });
1708            }
1709        }
1710        // Reproducibility gate's shell-comment / URL-fragment / YAML-comment arm.
1711        // The d14cbc5 shell-quote-grouping arm closes `'` / `"`; `#` (`0x23`) is
1712        // the orthogonal "byte at which four distinct downstream parsers all
1713        // truncate the value at the first occurrence" surface, and no prior arm
1714        // has covered it on the `:caminho` axis. Every POSIX shell (sh / bash /
1715        // zsh / dash / ksh / fish / nushell) lexes an unquoted `#` at the head
1716        // of a word (or after unquoted whitespace) as the comment-lead: from
1717        // that byte to the end of the physical line is a comment discarded
1718        // before command parsing (`cd ../caixa-teia  # legacy sibling` — the
1719        // canonical paste-from-shell-history-with-trailing-annotation shape
1720        // every operator-notebook and CI-manifest carries; POSIX.1-2017 §2.3
1721        // Token Recognition step 6). YAML 1.2 §6.6 makes `#` the comment lead
1722        // at any position preceded by whitespace or at line-start (`path:
1723        // ../caixa-teia  # pin` — the canonical paste-from-values.yaml /
1724        // paste-from-K8s-manifest cross-idiom-leak shape). tatara-lisp itself
1725        // treats `;` as the comment-lead but a growing number of consumer
1726        // config-DSL layers (HCL, Terraform, Nix flake attributes, .env
1727        // dotenv-style files, gitconfig / .gitignore, ini / TOML) use `#` as
1728        // the comment-lead too — the pair extends the cross-config-DSL
1729        // paste-idiom surface the d14cbc5 quote-grouping arm and the 598b770
1730        // brace-expansion arm already cover on adjacent axes. RFC 3986 §3.5
1731        // reserves `#` as the URL fragment-identifier delimiter (the canonical
1732        // paste-from-browser-address-bar `github.com/foo/bar#readme` /
1733        // `github.com/foo/bar#L42` permalink shape, and the symmetric
1734        // Nix-flake-ref cross-idiom leak `github:foo/bar#packageName` where
1735        // `#` selects a flake output — the same axis the peer
1736        // [`crate::render::is_git_repo_url`] closes on the `:fonte :repo`
1737        // surface at a68f818 with the same downstream-drops-the-tail
1738        // rationale).
1739        //
1740        // POSIX `std::path::Path` treats `#` as a literal path-component byte,
1741        // so a `:caminho "../caixa-teia # legacy sibling"` (the canonical
1742        // paste-from-shell-history-with-trailing-annotation footgun),
1743        // `:caminho "../caixa-teia  # pin"` (the symmetric YAML flow-scalar
1744        // paste-with-trailing-comment shape), or `:caminho "../caixa-teia
1745        // #readme"` (the URL fragment paste-from-browser-address-bar shape)
1746        // silently passes every prior arm because `Path::is_absolute` returns
1747        // false on `..`, `#` is neither a leading-byte sentinel nor a control
1748        // byte nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1749        // `*` / `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` / `"`,
1750        // and the value's last byte isn't `/`. The resolver folds the value
1751        // through `Path::new(caminho).join(<file>)` looking for a literal
1752        // subdirectory named `../caixa-teia # legacy sibling` and fails at
1753        // resolve time with a non-self-locating `No such file or directory`
1754        // error far from the source caixa.lisp — while every downstream
1755        // shell / YAML / URL parser silently truncates the value at the `#`
1756        // byte to `../caixa-teia`, so a `feira tofu` shell-out to a
1757        // `cd '{caminho}'` command line and a `nix flake check` invocation on
1758        // an emitted YAML `path:` scalar disagree with the resolver on which
1759        // directory the value names. Two workstations whose downstream
1760        // shell / YAML / URL parsing layers differ in unquoted-`#`
1761        // recognition emit divergent build artifacts for the byte-identical
1762        // caixa.lisp value.
1763        //
1764        // The lacre pipeline embeds the value verbatim in its per-dep
1765        // content-address (`conteudo: format!("path:{caminho}")`,
1766        // caixa-resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1767        // closure and rides downstream as part of the build's identity into
1768        // every shell-spawned subprocess (the caixa-resolver's `git clone`
1769        // invocation, a future `feira tofu` shell-out, a future operator-side
1770        // `nix flake check` spawn) as the canonical shell-metachar /
1771        // comment-lead / URL-fragment-delimiter surface every peer
1772        // single-token-shaped typed slot already closes. The peer `:fonte
1773        // :repo` axis closes the byte under the URL-fragment-identifier
1774        // banner (a68f818 `#` on `is_git_repo_url`); the `:caminho` axis was
1775        // the last typed path-string surface still admitting the byte. This
1776        // arm closes the gap so the substrate-wide "no shell-composition
1777        // metacharacter / comment-lead / URL-fragment-delimiter anywhere in a
1778        // typed string slot that flows verbatim into a shell-spawned
1779        // subprocess or downstream YAML / URL parser" invariant extends from
1780        // shell-quote-grouping (`'` / `"`) to shell-comment / URL-fragment
1781        // (`#`) on the `:caminho` axis. Together with the peer JSON / YAML /
1782        // TOML string-literal delimiters the d14cbc5 quote-grouping arm
1783        // closes and the 598b770 `{` / `}` brace-expansion arm closes on the
1784        // templating-engine-placeholder boundary, the typed `:caminho`
1785        // accepted set now structurally excludes the entire
1786        // paste-with-trailing-annotation / paste-from-URL-permalink /
1787        // paste-from-YAML-comment cross-idiom-leak surface that would
1788        // silently round-trip through any downstream shell / YAML / URL /
1789        // dotenv / gitconfig / HCL parsing layer to a different value than
1790        // the resolver's `Path::join` sees.
1791        //
1792        // The arm fires AFTER the shell-quote-grouping arm because the prior
1793        // arm's `'` / `"` shape is the more semantic-locating axis on values
1794        // that probe as both (`"../'x'#pin"` carries both `'` and `#` — the
1795        // shell-string-literal-delimiter is the load-bearing root-cause edit,
1796        // so `FonteCaminhoShellQuoteGrouping` wins; same cascade discipline
1797        // every prior `:caminho` arm establishes). The arm fires BEFORE the
1798        // trailing-`/` arm because the embedded comment-lead / fragment-
1799        // delimiter byte is the more semantic-locating axis on probe-as-both
1800        // values (`"../caixa-teia#pin/"` ends in `/` but the load-bearing
1801        // diagnostic is the embedded `#` — the trailing `/` is the secondary
1802        // observation, and an author who removes the `#pin` fragment is
1803        // likely to also tab-strip the trailing separator).
1804        for &b in caminho.as_bytes() {
1805            if b == b'#' {
1806                return Err(DepError::FonteCaminhoShellComment {
1807                    nome: nome.to_string(),
1808                    caminho: caminho.to_string(),
1809                    byte: b,
1810                });
1811            }
1812        }
1813        // Reproducibility gate's URL-percent-encoding-escape arm. The 6622063
1814        // shell-comment arm closes the `#` URL-fragment-identifier byte; `%`
1815        // (`0x25`) is the orthogonal RFC 3986 §2.1 URL percent-encoding-escape
1816        // byte — the mandatory encoding mechanism for every byte outside the
1817        // `unreserved` alphanumeric / `-` / `.` / `_` / `~` set, and `%`
1818        // itself must be percent-encoded as `%25` to appear literally inside
1819        // a URL value. The byte carries three distinct render-determinism
1820        // hazards on the `:caminho` axis, no prior arm has covered it, and
1821        // the peer `:fonte :repo` axis (a323db8 `%` on `is_git_repo_url`)
1822        // already closes the same byte under the same URL-percent-encoding
1823        // banner — the `:caminho` axis was the last typed path-string surface
1824        // still admitting the byte.
1825        //
1826        // First, the paste-from-browser-address-bar percent-encoded-space
1827        // footgun: an author copies `../caixa%20teia` out of a URL-encoded
1828        // README hyperlink / a browser address bar / a percent-encoded
1829        // permalink expecting `%20` to decode to a literal space at the
1830        // filesystem layer. POSIX `std::path::Path` treats the byte as a
1831        // literal path-component byte, so `Path::join` looks for a literal
1832        // `./../caixa%20teia` subdirectory and fails at resolve time with a
1833        // non-self-locating `No such file or directory` error far from the
1834        // source caixa.lisp — while the author's mental model was
1835        // `../caixa teia`, the decoded shape. Two authors whose only
1836        // difference is percent-encoding presence resolve to two distinct
1837        // BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`)
1838        // for what they intended as the byte-identical sibling-workspace
1839        // dep. The lacre pipeline embeds the value verbatim in its per-dep
1840        // content-address (`conteudo: format!("path:{caminho}")`,
1841        // caixa-resolver/src/resolve.rs:189), so the divergence rides
1842        // downstream into the BLAKE3 closure and locks the substrate's
1843        // "the lacre is the build's identity" contract (CAIXA-SDLC §III.2)
1844        // to the wrong encoding — the same THEORY.md §V.2 render-
1845        // determinism vector every prior `:caminho` arm protects.
1846        //
1847        // Second, the printf-format-specifier lead footgun: `%` is the C /
1848        // POSIX printf format-directive lead-in (`%s`, `%d`, `%02x`, the
1849        // canonical `printf "path=%s\n" ../caixa-teia` invocation every
1850        // shell-diagnostic one-liner carries) and the printf builtin is
1851        // wired into every POSIX shell (bash / zsh / dash / ksh / busybox
1852        // ash) as the format-string lead. A `:caminho "../caixa-%s-teia"`
1853        // value flowing into any future `feira` verb that shells out with a
1854        // printf-formatted path template silently gets reinterpreted as a
1855        // format-directive rather than a literal byte — the canonical
1856        // CWE-134 format-string-injection vector.
1857        //
1858        // Third, the bash-job-control-specifier lead footgun: bash / zsh /
1859        // ksh reserve `%N` at word-start as the job-control specifier —
1860        // `%1` names "job 1", `%%` names "the current job", `%foo` names
1861        // "the most recent job whose command started with `foo`". A future
1862        // `feira` verb that invokes `kill %1` on a caminho-scoped
1863        // subprocess would silently redirect the signal to a wrong target.
1864        //
1865        // Beyond the three shell-side hazards, `%` is a first-class parser
1866        // byte in three cross-config-DSL layers the substrate's paste-idiom
1867        // surface routinely crosses: YAML 1.2 §6.8.1 lexes `%` at
1868        // line-start as the directive lead (`%YAML 1.2` / `%TAG` — a
1869        // `:caminho "%YAML/1.2/../caixa-teia"` paste from a top-of-doc
1870        // YAML directive block silently trips the YAML directive parser on
1871        // any downstream emitted YAML manifest); Prometheus / Grafana
1872        // template syntax uses `%(var)s` as the substitution lead; and Nix
1873        // interpolation uses `${var}` (not `%`) but Envsubst /
1874        // Kubernetes / OpenShift template layers use `%VAR%` as the
1875        // Windows-shell env-var-reference lead — the paste-from-`.bat` /
1876        // paste-from-PowerShell-`%env:PATH%` cross-idiom leak.
1877        //
1878        // The three malformed-`%HH` classes documented on the peer
1879        // `is_git_repo_url` `%` arm (a323db8) apply here too:
1880        //
1881        //   - The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
1882        //     where `%` isn't followed by two hex digits) — every WHATWG-
1883        //     conformant URL parser rejects the value at parse time per
1884        //     RFC 3986 §2.1, but the byte rides into the lacre before
1885        //     the resolver subprocess crosses the URL-parser boundary.
1886        //   - The over-encoded path-separator shape (`"../caixa%2Fteia"`
1887        //     intending the `%2F` as the URL encoding of `/`) locks a
1888        //     `path:../caixa%2Fteia` BLAKE3 closure that diverges from
1889        //     the byte-identical `path:../caixa/teia` form.
1890        //   - The double-encoded shape (`"../caixa%2520teia"` — the `%25`
1891        //     already itself an encoded `%`, so the intent was likely a
1892        //     literal `%20` that survived one round-trip through a
1893        //     URL-encoder that shouldn't have run) locks a triply-
1894        //     divergent closure across the encoded / once-decoded /
1895        //     twice-decoded chain.
1896        //
1897        // POSIX `std::path::Path` treats the byte as a literal path-
1898        // component byte, so a `:caminho "../caixa%20teia"` (the canonical
1899        // paste-from-browser-address-bar percent-encoded-space footgun),
1900        // `:caminho "%YAML/../caixa-teia"` (the symmetric paste-from-YAML-
1901        // directive-block cross-idiom leak), or `:caminho
1902        // "../caixa-%s-teia"` (the printf-format-specifier paste-from-
1903        // shell-diagnostic-one-liner shape) silently passes every prior arm
1904        // because `Path::is_absolute` returns false on `..`, `%` is neither
1905        // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
1906        // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
1907        // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`, and the
1908        // value's last byte isn't `/`. The resolver folds the value through
1909        // `Path::new(caminho).join(<file>)` looking for a literal
1910        // subdirectory named `../caixa%20teia` and fails at resolve time
1911        // with a non-self-locating `No such file or directory` error far
1912        // from the source caixa.lisp — while every downstream URL parser /
1913        // shell printf builtin / YAML directive parser silently
1914        // reinterprets the byte to a different value than the resolver's
1915        // `Path::join` sees. Two workstations whose downstream URL / shell
1916        // / YAML layers differ in `%HH` recognition emit divergent build
1917        // artifacts for the byte-identical caixa.lisp value.
1918        //
1919        // The lacre pipeline embeds the value verbatim in its per-dep
1920        // content-address (`conteudo: format!("path:{caminho}")`, caixa-
1921        // resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1922        // closure and rides into every shell-spawned subprocess (the
1923        // resolver's `git clone`, a future `feira tofu` shell-out, a
1924        // future operator-side `nix flake check` spawn) as the canonical
1925        // URL-percent-encoding-escape / printf-format-specifier / bash-
1926        // job-control-specifier surface every peer single-token-shaped
1927        // typed slot already closes. This arm closes the gap so the
1928        // substrate-wide "no URL-percent-encoding-escape / printf-format-
1929        // specifier / job-control-specifier / YAML-directive-lead byte
1930        // anywhere in a typed string slot that flows verbatim into a
1931        // shell-spawned subprocess or downstream URL / printf / YAML
1932        // parser" invariant extends from shell-comment / URL-fragment
1933        // (`#` — 6622063) to URL-percent-encoding-escape (`%`) on the
1934        // `:caminho` axis.
1935        //
1936        // The arm fires AFTER the shell-comment arm because the prior
1937        // arm's `#` shape is the more semantic-locating axis on values
1938        // that probe as both (`"../caixa%20teia#pin"` carries both `%`
1939        // and `#` — the URL-fragment-identifier is the load-bearing
1940        // downstream-truncation edit, so `FonteCaminhoShellComment` wins;
1941        // same cascade discipline every prior `:caminho` arm establishes).
1942        // The arm fires BEFORE the trailing-`/` arm because the embedded
1943        // percent-encoding-escape byte is the more semantic-locating axis
1944        // on probe-as-both values (`"../caixa%20teia/"` ends in `/` but
1945        // the load-bearing diagnostic is the embedded `%` percent-
1946        // encoding-escape — the trailing `/` is the secondary observation,
1947        // and an author who decodes the `%20` to a literal space is
1948        // likely to also tab-strip the trailing separator).
1949        for &b in caminho.as_bytes() {
1950            if b == b'%' {
1951                return Err(DepError::FonteCaminhoUrlPercentEncoding {
1952                    nome: nome.to_string(),
1953                    caminho: caminho.to_string(),
1954                    byte: b,
1955                });
1956            }
1957        }
1958        // Reproducibility gate's embedded-`$` shell-variable-expansion /
1959        // command-substitution / arithmetic-expansion arm. The f4efe9c
1960        // leading-`$` arm at line 540 routes `caminho.starts_with('$')`
1961        // through `FonteCaminhoVarExpansion` under the leading-byte-
1962        // sentinel host-layout-leak banner (peer with the b94fd83
1963        // absolute / a5c248e tilde leading-byte arms), but the arm
1964        // fires only at position 0 — a `:caminho "../foo$HOME/bar"`
1965        // (embedded `$HOME` in a nested path segment — the canonical
1966        // paste-from-`ls ../foo$HOME/bar`-shell-one-liner footgun where
1967        // an author copies a partially-substituted shell one-liner and
1968        // the leading segment is a literal `../foo` while the mid
1969        // segment carries the un-substituted `$HOME` template), a
1970        // `:caminho "../foo${WORKSPACE}/bar"` (the symmetric braced-CI-
1971        // manifest paste-from-`.gitlab-ci.yml` / paste-from-GitHub-
1972        // Actions-workflow shape), a `:caminho "../foo$(whoami)/bar"`
1973        // (the paste-from-shell-prompt command-substitution idiom), or
1974        // a `:caminho "../foo$((1+2))/bar"` (the arithmetic-expansion
1975        // idiom) silently passes every prior arm because
1976        // `Path::is_absolute` returns false on `..`, `$` is neither a
1977        // leading-byte sentinel (the f4efe9c arm fires only at position
1978        // 0) nor a control byte nor `\` nor `<` / `>` nor `|` nor `;`
1979        // nor `&` nor backtick nor `*` / `?` nor `(` / `)` nor `{` /
1980        // `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%`, and the
1981        // value's last byte isn't `/`. Note that `$(...)` command-
1982        // substitution and `$((...))` arithmetic-expansion each carry
1983        // an embedded `(` byte that the 0633c91 shell-subshell-grouping
1984        // arm catches structurally at the earlier `(` position — but
1985        // an author who reaches for the sh-brace-substitution
1986        // `${VAR}` or the bare `$VAR` shape carries only the `$` byte,
1987        // which no prior arm covers. This arm closes the last
1988        // positional gap on the `$` byte on the `:caminho` axis so
1989        // every position — leading (`FonteCaminhoVarExpansion`) and
1990        // embedded (`FonteCaminhoShellVariableExpansion`) — is
1991        // structurally rejected.
1992        //
1993        // Every POSIX shell (sh / bash / zsh / dash / ksh / busybox
1994        // ash / fish / nushell) lexes `$` as the variable-expansion /
1995        // command-substitution / arithmetic-expansion operator per
1996        // POSIX.1-2017 §2.6 (Word Expansions): `$<name>` (Parameter
1997        // Expansion) expands a named variable, `${<name>}` (Parameter
1998        // Expansion braced form) does the same with an explicit token
1999        // boundary, `$(<cmd>)` (Command Substitution modern form,
2000        // `` `<cmd>` `` legacy form which the c370458 backtick arm
2001        // already closes) runs a subshell and substitutes its stdout,
2002        // and `$((<expr>))` (Arithmetic Expansion) evaluates an
2003        // arithmetic expression. Every form is a host-layout /
2004        // environment-state / shell-subprocess-side-effect leak when
2005        // the byte lands in a value the resolver passes to a shell-
2006        // spawned subprocess. Beyond the POSIX shell layer, `$` is
2007        // the Nix `${var}` string-interpolation lead (the paste-from-
2008        // `flake.nix` / paste-from-`.nix`-attribute cross-idiom leak
2009        // where an author copies `"${pkgs.hello}/bin/hello"` out of a
2010        // nix expression), the Make `$(var)` / `$@` / `$<` automatic-
2011        // variable lead (the paste-from-`Makefile` shape), the
2012        // JavaScript / TypeScript template-literal `${expr}` interp
2013        // lead (the paste-from-JS-template-string idiom in a
2014        // multi-lang-monorepo where a `path` attribute gets copied out
2015        // of a `package.json` script or a Vite config), the envsubst /
2016        // Kubernetes / OpenShift template `${VAR}` interp lead (the
2017        // paste-from-Helm-values / paste-from-K8s-manifest cross-idiom
2018        // leak), the PHP variable lead (`$_GET`, `$_ENV` — the paste-
2019        // from-`.php`-config footgun), the Perl scalar-variable lead
2020        // (`$foo`), the SASS / SCSS variable lead (`$primary-color`),
2021        // and the SQL bind-parameter lead in PostgreSQL / SQLite
2022        // (`$1`, `$2` — the paste-from-`.sql`-migration idiom). The
2023        // cross-idiom paste-footgun surface is broader than any single
2024        // shell layer — `$` is a first-class parser byte in nearly
2025        // every config / templating / build-system DSL the substrate's
2026        // paste-idiom surface routinely crosses. The peer `:fonte
2027        // :repo` axis closes the byte under the shell-variable-
2028        // expansion / URL-sub-delim banner (b9d187c `$` on
2029        // `is_git_repo_url`), the peer `:fonte :tag` / `:fonte :branch`
2030        // axes close `$` as part of `is_git_ref_name`'s printable-
2031        // ASCII-restricted grammar (`git check-ref-format` rejects the
2032        // byte outright), and the peer `:entrada :paths` axis closes
2033        // `$` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-
2034        // reserved set. The `:caminho` axis was the last typed path-
2035        // string surface still admitting `$` at positions other than 0.
2036        //
2037        // POSIX `std::path::Path` treats `$` as a literal path-
2038        // component byte, so `:caminho "../foo$HOME/bar"` silently
2039        // routes through `Path::new(caminho).join(<file>)` looking for
2040        // a literal `./{caminho}` subdirectory that fails at resolve
2041        // time with a non-self-locating `No such file or directory`
2042        // error far from the source caixa.lisp. But every downstream
2043        // shell / envsubst / Nix / Make / K8s-template parser silently
2044        // reinterprets the byte to a different value than the
2045        // resolver's `Path::join` sees — so a `feira tofu` shell-out
2046        // to a `cd '{caminho}'` command line, a `nix flake check`
2047        // invocation on an emitted YAML `path:` scalar folded through
2048        // envsubst, or a `helm template` invocation with a
2049        // `values.yaml` `path: {caminho}` embedded in a `{{`-quoted
2050        // template all disagree with the resolver on which directory
2051        // the value names. Two workstations whose downstream shell /
2052        // envsubst / Nix / Make / K8s-template parsing layers differ
2053        // in `$VAR` recognition (or, worse, expand the byte against
2054        // divergent environments — Alice's `$HOME=/home/alice`, Bob's
2055        // `$HOME=/home/bob`) emit divergent build artifacts for the
2056        // byte-identical caixa.lisp value. Even in the case where the
2057        // resolver strictly does NOT expand `$VAR` (the current
2058        // implementation) the divergence still bites at the lacre-
2059        // identity axis: the lacre pipeline embeds the value verbatim
2060        // in its per-dep content-address (`conteudo:
2061        // format!("path:{caminho}")`, caixa-resolver/src/resolve.rs:189),
2062        // so `path:../foo$HOME/bar` locks a BLAKE3 closure distinct
2063        // from the byte-identical-semantic `path:../foo/home/alice/bar`
2064        // one author would have produced by substituting the literal
2065        // value at author time, defeating the THEORY.md §V.2 render-
2066        // determinism contract on the same axis every prior `:caminho`
2067        // arm protects.
2068        //
2069        // Beyond the render-determinism / host-layout-leak vectors,
2070        // `$` at any position in a value flowing verbatim into a
2071        // shell-spawned subprocess is the canonical CWE-78 shell-
2072        // command-injection surface every peer single-token-shaped
2073        // typed slot already closes. A `:caminho "../foo$(whoami)/bar"`
2074        // that rides into a future `feira tofu` shell-out as `cd
2075        // '../foo$(whoami)/bar'` gets substituted by the shell at
2076        // subprocess-argument-expansion time even inside single quotes
2077        // in fewer positions than one might expect (the substitution
2078        // fires only outside single-quoting per POSIX §2.2.2, but
2079        // eval-style wrappers and `sh -c` layers that route the value
2080        // through re-parsing round-trip the substitution — the same
2081        // vector the c370458 backtick arm closes at the sibling
2082        // command-substitution-legacy-form surface). Every future
2083        // `feira` verb that shells out with a `caminho`-formatted
2084        // subprocess argument silently inherits this substitution
2085        // vector unless the typed slot's accepted set structurally
2086        // excludes the byte.
2087        //
2088        // Frontier inspiration: OTP's `gen_server` return-value grammar
2089        // rejects mid-tuple shell-metachar bytes by construction —
2090        // `{noreply, State}` never carries a raw `$` because the
2091        // Erlang term type system has no notion of "string that gets
2092        // shelled out"; caixa's typed slots inherit the same
2093        // structural discipline (types-are-theorems, the compounding
2094        // mandate's leverage-point-1) by refusing values that would
2095        // silently reinterpret at any downstream layer. Peer with
2096        // Unison's content-addressed code (no ambient environment —
2097        // every reference is a hash, no `$VAR` substitution possible)
2098        // and Pony's capabilities (a path capability that carries a
2099        // `$` would be ill-typed at the reference layer).
2100        //
2101        // The arm fires AFTER the URL-percent-encoding-escape arm (the
2102        // e3558fa `%` arm) because a value carrying both `%` and `$`
2103        // (`"../foo%20$HOME/bar"` — the canonical "I pasted a percent-
2104        // encoded space next to a `$HOME` template") surfaces the
2105        // narrower URL-encoding diagnostic first — the paste-from-
2106        // browser-address-bar shape is the load-bearing self-locating
2107        // edit on every probe-as-both value; same cascade discipline
2108        // every prior `:caminho` arm establishes (a323db8 %  before
2109        // this arm, this arm before trailing-`/`). The arm fires
2110        // BEFORE the trailing-`/` arm because the embedded shell-
2111        // variable-expansion byte is the more semantic-locating axis
2112        // on probe-as-both values (`"../foo$HOME/bar/"` ends in `/`
2113        // but the load-bearing diagnostic is the embedded `$` — the
2114        // trailing `/` is the secondary observation, and an author
2115        // who substitutes the `$HOME` template with a literal value is
2116        // likely to also tab-strip the trailing separator).
2117        for &b in caminho.as_bytes() {
2118            if b == b'$' {
2119                return Err(DepError::FonteCaminhoShellVariableExpansion {
2120                    nome: nome.to_string(),
2121                    caminho: caminho.to_string(),
2122                    byte: b,
2123                });
2124            }
2125        }
2126        // Reproducibility gate's shell-history-expansion / RFC-3986-sub-delims
2127        // arm. The immediate-predecessor `$` embedded arm closes the shell-
2128        // variable-expansion / command-substitution byte; `!` (`0x21`) is the
2129        // orthogonal POSIX shell-history-expansion sentinel every interactive
2130        // shell with history enabled (bash / ksh / zsh's `bashcompat` /
2131        // csh / tcsh) lexes as the history-expansion prefix: `!command`
2132        // re-runs the most recent history entry beginning with `command`,
2133        // `!!` re-runs the prior command verbatim, `!$` substitutes the
2134        // last word of the prior command, `!:N` substitutes the Nth word,
2135        // `^old^new` rewrites the prior command's `old` to `new` (the
2136        // canonical set of `set -o histexpand` operators bash's default
2137        // interactive session enables). Beyond the shell-history layer,
2138        // RFC 3986 §2.2 lists `!` in the `sub-delims` set (the URL grammar
2139        // admits the byte inside a path segment, but every WHATWG-conformant
2140        // special-scheme URL parser percent-encodes it inside a query
2141        // component via the 'special-query percent-encode set' the peer
2142        // `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte
2143        // is also the C / C++ / Rust / JavaScript / Python bang-operator
2144        // (logical-negation prefix — the paste-from-source-code idiom where
2145        // an author copies `!path.exists()` out of a Rust snippet and the
2146        // trailing punctuation crosses the string-literal boundary); the
2147        // canonical English-typography emphasis / exclamation mark (the
2148        // paste-from-prose enthusiasm-form idiom where an author writes
2149        // `:caminho "../caixa-teia!"` expecting the substrate to coerce it
2150        // to a kebab-case slug); and the Nix flake-ref import-attribute
2151        // `import ./foo.nix { … }` sibling operator surface.
2152        //
2153        // POSIX `std::path::Path` treats `!` as a literal path-component
2154        // byte, so a `:caminho "../caixa-teia!sudo"` (the canonical paste-
2155        // from-shell-history footgun where the author copies a `cd
2156        // ../caixa-teia && !sudo make install` one-liner from a quick-
2157        // start README and the trailing `!sudo` rides in verbatim as a
2158        // history-expansion reference), a `:caminho "../foo!!/bar"` (the
2159        // `!!` repeat-prior-command paste idiom), a `:caminho
2160        // "../caixa-teia!"` (the English-typography enthusiasm-form
2161        // paste-from-prose footgun), or a `:caminho "../foo!$"` (the
2162        // last-word-substitution shape) silently pass every prior arm
2163        // because `Path::is_absolute` returns false on `..`, `!` is neither
2164        // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
2165        // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
2166        // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%` nor `$`,
2167        // and the value's last byte isn't `/`. The resolver folds the value
2168        // through `Path::new(caminho).join(<file>)` looking for a literal
2169        // `./../caixa-teia!sudo` subdirectory and fails at resolve time
2170        // with a non-self-locating `No such file or directory` error far
2171        // from the source caixa.lisp — while every downstream interactive
2172        // shell with `set -o histexpand` reinterprets the byte as the
2173        // history-expansion prefix, and the failure mode forks per
2174        // consumer: a `feira tofu` shell-out to a `cd '{caminho}'` command
2175        // line executed under `bash -i` (the operator-notebook interactive
2176        // shell) substitutes the `!sudo` reference to the most recent
2177        // history entry starting with `sudo`, silently invoking whatever
2178        // privileged command that entry named.
2179        //
2180        // The lacre pipeline embeds the value verbatim in its per-dep
2181        // content-address (`conteudo: format!("path:{caminho}")`,
2182        // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2183        // BLAKE3 closure and rides into every shell-spawned subprocess
2184        // (the resolver's `git clone`, a future `feira tofu` shell-out,
2185        // a future operator-side `nix flake check` spawn) as the
2186        // canonical shell-history-expansion / RFC-3986-sub-delims surface
2187        // every peer single-token-shaped typed slot already closes. The
2188        // peer `:fonte :repo` axis closes the byte under the same shell-
2189        // history-expansion / RFC-3986-sub-delims banner (7d53c68 `!` on
2190        // `is_git_repo_url`); the `:caminho` axis was the last typed
2191        // path-string surface still admitting the byte. This arm closes
2192        // the gap so the substrate-wide "no shell-composition
2193        // metacharacter / history-expansion sentinel anywhere in a typed
2194        // string slot that flows verbatim into a shell-spawned subprocess"
2195        // invariant extends from shell-variable-expansion (`$`) to shell-
2196        // history-expansion (`!`) on the `:caminho` axis. Together with
2197        // the peer c370458 backtick command-substitution-legacy-form arm
2198        // and the b9d187c-`$`-embedded-variable-expansion arm on the
2199        // sibling `:repo` axis, the typed `:caminho` accepted set now
2200        // structurally excludes every byte the POSIX shell §2.6 Word
2201        // Expansions section, §2.3 Token Recognition step 6, and every
2202        // history-expansion / brace-expansion / pathname-expansion /
2203        // parameter-expansion / command-substitution / arithmetic-
2204        // expansion operator lexes as a first-class parser byte.
2205        //
2206        // Frontier inspiration: Unison's content-addressed code (no
2207        // ambient environment — every reference is a hash, no `!<num>`
2208        // history-index substitution possible; the caixa substrate's
2209        // lacre discipline arrives at the same guarantee by refusing
2210        // bytes at manifest-parse time that would reinterpret against
2211        // ambient shell history state); Pony's capabilities (a path
2212        // capability that carries a `!` would be ill-typed at the
2213        // reference layer).
2214        //
2215        // The arm fires AFTER the shell-variable-expansion arm because a
2216        // value carrying both `$` and `!` (`"../foo$HOME/bar!sudo"` — the
2217        // canonical "I pasted a `$HOME`-templated path adjacent to a
2218        // trailing `!sudo` history-expansion") surfaces the narrower
2219        // shell-variable-expansion diagnostic first — the paste-from-CI-
2220        // manifest-with-`$VAR`-template shape is the load-bearing self-
2221        // locating edit on every probe-as-both value; same cascade
2222        // discipline every prior `:caminho` arm establishes. The arm
2223        // fires BEFORE the trailing-`/` arm because the embedded shell-
2224        // history-expansion byte is the more semantic-locating axis on
2225        // probe-as-both values (`"../foo!sudo/"` ends in `/` but the
2226        // load-bearing diagnostic is the embedded `!` — the trailing `/`
2227        // is the secondary observation, and an author who removes the
2228        // `!sudo` history reference is likely to also tab-strip the
2229        // trailing separator).
2230        for &b in caminho.as_bytes() {
2231            if b == b'!' {
2232                return Err(DepError::FonteCaminhoShellHistoryExpansion {
2233                    nome: nome.to_string(),
2234                    caminho: caminho.to_string(),
2235                    byte: b,
2236                });
2237            }
2238        }
2239        // Reproducibility gate's shell-history-substitution / RFC-3986-unwise
2240        // / regex-anchor arm. The immediate-predecessor `!` arm closes the
2241        // POSIX `!command` / `!!` / `!$` history-expansion prefix; `^`
2242        // (`0x5E`) is the paired-operator half of the same bash-reference
2243        // §9.3 histexpand feature — the `^old^new^` "quick substitution"
2244        // form (POSIX bash rewrites the prior command's `old` string to
2245        // `new` and re-executes it, the canonical typo-correction one-
2246        // liner idiom `git clone <bad-url>` → `^bad^good` that pastes the
2247        // trailing substitution fragment verbatim into a `:caminho` value
2248        // when the author trims only the leading `git clone` prefix). The
2249        // peer `:fonte :repo` axis closes the byte under the same
2250        // shell-history-substitution / RFC-3986-unwise banner (49e142f `^`
2251        // on `is_git_repo_url`); the `:caminho` axis was the last typed
2252        // path-string surface still admitting the byte after 6a04767
2253        // landed the `!` arm.
2254        //
2255        // Beyond bash history-substitution, `^` carries five distinct
2256        // downstream-reinterpretation surfaces the typed slot's accepted
2257        // set must structurally exclude:
2258        //
2259        // 1. **RFC 3986 §2 'unwise' set** — the four-byte cross-transport
2260        //    layer set (`{`, `}`, `|`, `\`) plus `^` every URL parser is
2261        //    required to percent-encode-or-refuse at the wire boundary.
2262        //    The WHATWG URL spec's 'fragment percent-encode set' maps
2263        //    `^` → `%5E` at the query / fragment component transition;
2264        //    libcurl silently percent-encodes the byte on the wire, so a
2265        //    `:caminho "../foo^bar"` value the resolver's `Path::join`
2266        //    sees as a literal `./../foo^bar` subdirectory diverges from
2267        //    the byte-transformed `%5E` shape any downstream `feira tofu`
2268        //    curl-invocation or artifact-registry-fetch would emit — the
2269        //    canonical wire-boundary divergence vector the peer
2270        //    `{`, `}`, `|`, `\` `:caminho` arms already close (
2271        //    `FonteCaminhoShellBraceExpansion` at 598b770,
2272        //    `FonteCaminhoShellPipe` at the pipe arm,
2273        //    `FonteCaminhoBackslash` at the backslash arm).
2274        // 2. **Regex character-class negation prefix `[^abc]`** — the
2275        //    canonical paste-from-doc-regex-pipeline footgun where an
2276        //    author copies a `grep '[^abc]'` idiom from a docs quick-
2277        //    listing and the character-class negation byte rides in
2278        //    verbatim.
2279        // 3. **Bitwise XOR operator** in C / C++ / Rust / Python /
2280        //    JavaScript / Nix / Go — the paste-from-source-code idiom
2281        //    where an author copies an `x ^ y`-shaped expression out of
2282        //    a source snippet and the operator crosses the string-
2283        //    literal boundary.
2284        // 4. **Windows `cmd.exe` escape metacharacter** — the byte
2285        //    escapes the next character in a `cmd.exe` batch context (a
2286        //    peer of the backslash arm's Windows-separator-leak vector).
2287        //    A `:caminho "..^&whoami"` cross-platform paste-from-batch-
2288        //    file footgun reinterprets at every `cmd.exe`-spawned
2289        //    subprocess (the resolver's future Windows-runner shell-out,
2290        //    the operator's WinRM path, a future PowerShell-embedded
2291        //    invocation).
2292        // 5. **LaTeX / Markdown / BibTeX superscript operator** — the
2293        //    paste-from-typeset-doc footgun where a mathematical
2294        //    superscript notation (`x^2` / `M^T`) leaks from prose.
2295        //
2296        // POSIX `std::path::Path` treats `^` as a literal path-component
2297        // byte, so `:caminho "../foo^bar/baz"` (embedded quick-
2298        // substitution), `:caminho "../foo^"` (trailing history-
2299        // substitution-open shape), `:caminho "../[^a-z]/foo"` (regex-
2300        // negation-prefix paste from a grep pipeline; note the `[` / `]`
2301        // arm at 986963b fires first on this shape), or `:caminho
2302        // "../x^y"` (XOR-expression paste-from-source) all silently pass
2303        // every prior arm (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` /
2304        // backtick / `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'`
2305        // / `"` / `#` / `%` / `$` / `!`) and route through
2306        // `Path::new(caminho).join(<file>)` looking for a literal
2307        // `./{caminho}` subdirectory that fails at resolve time with a
2308        // non-self-locating `No such file or directory` error far from
2309        // the source caixa.lisp — while every downstream shell / curl /
2310        // regex / `cmd.exe` layer reinterprets the byte to its own
2311        // semantic.
2312        //
2313        // The lacre pipeline embeds the value verbatim in its per-dep
2314        // content-address (`conteudo: format!("path:{caminho}")`,
2315        // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2316        // BLAKE3 closure and rides into every shell-spawned subprocess
2317        // (the resolver's `git clone`, a future `feira tofu` shell-out,
2318        // a future operator-side `nix flake check` spawn) as the
2319        // canonical shell-history-substitution / RFC-3986-unwise /
2320        // regex-negation surface every peer single-token-shaped typed
2321        // slot already closes. This arm together with the immediate-
2322        // predecessor `!` arm (6a04767) closes the full `set -o
2323        // histexpand` operator surface on the `:caminho` axis — the
2324        // `!command` / `!!` / `!$` prefix form via `!`, the `^old^new^`
2325        // quick-substitution form via `^` — so the substrate-wide "no
2326        // shell-history operator anywhere in a typed string slot that
2327        // flows verbatim into a shell-spawned subprocess" invariant
2328        // extends from the `!` prefix half to the `^` quick-substitution
2329        // half. Every peer bash-history operator now fails at manifest-
2330        // parse time with a self-locating diagnostic naming the offending
2331        // caixa.lisp rather than at resolve-time as a `Path::join`-
2332        // derived `No such file or directory` (harmless but non-self-
2333        // locating) or worse riding into a downstream `bash -i` context
2334        // that reinterprets the byte-pair against ambient history state.
2335        //
2336        // Frontier inspiration: bash reference §9.3 HISTORY EXPANSION
2337        // "Quick substitution. Repeat the previous command, replacing
2338        // string1 with string2." + RFC 3986 §2 'unwise' set
2339        // ("characters that gateways and other transport agents are
2340        // known to sometimes modify") + Pony's capabilities (a path
2341        // capability that carries a `^` would be ill-typed at the
2342        // reference layer, matching the same structural discipline the
2343        // sibling `!` history-expansion arm inherits from Unison's
2344        // content-addressed no-ambient-history discipline).
2345        //
2346        // The arm fires AFTER the shell-history-expansion `!` arm because
2347        // a value carrying both `!` and `^` (`"../foo!sudo^bad^good"` —
2348        // the canonical "I pasted a `!sudo` history-reference next to a
2349        // `^bad^good` quick-substitution") surfaces the narrower prefix-
2350        // form `!` diagnostic first — the `!` form is the load-bearing
2351        // self-locating edit on every probe-as-both value (an author who
2352        // removes the `!sudo` reference is likely to also strip the
2353        // paired `^` substitution fragment); same cascade discipline
2354        // every prior `:caminho` arm establishes. The arm fires BEFORE
2355        // the trailing-`/` arm because the embedded shell-history-
2356        // substitution byte is the more semantic-locating axis on
2357        // probe-as-both values (`"../foo^bar/"` ends in `/` but the
2358        // load-bearing diagnostic is the embedded `^` — the trailing `/`
2359        // is the secondary observation, and an author who removes the
2360        // `^bar` substitution fragment is likely to also tab-strip the
2361        // trailing separator).
2362        for &b in caminho.as_bytes() {
2363            if b == b'^' {
2364                return Err(DepError::FonteCaminhoShellHistorySubstitution {
2365                    nome: nome.to_string(),
2366                    caminho: caminho.to_string(),
2367                    byte: b,
2368                });
2369            }
2370        }
2371        // Reproducibility gate's trailing-`/` arm. The b94fd83 absolute arm
2372        // closes the leading-`/` host-layout-leak; the embedded-control-byte
2373        // arm closes any byte-in-the-`0x00..=0x1F` / `0x7F` range; the
2374        // backslash arm closes the cross-host-OS-separator vector. The
2375        // trailing-`/` is the orthogonal shell-tab-completion-on-a-directory
2376        // footgun — `Path::join("../caixa-teia")` and
2377        // `Path::join("../caixa-teia/")` resolve to the same directory
2378        // (POSIX path-component-walk treats trailing `/` as a no-op for
2379        // directory targets, which `:caminho` always names — the sibling-
2380        // workspace dep root is structurally a directory). The lacre
2381        // pipeline embeds the value verbatim in its per-dep content-address
2382        // (`conteudo: format!("path:{caminho}")`,
2383        // caixa-resolver/src/resolve.rs:189), so byte-identical caixa
2384        // semantic-meaning yields two distinct BLAKE3 closures depending on
2385        // whether the author shell-tab-completed the path (every interactive
2386        // shell appends `/` on tab-completing a directory, idiomatic in
2387        // bash / zsh / fish / nushell), pasted from `pwd` (which on most
2388        // shells emits without trailing `/`, but `realpath -e -m` on a
2389        // directory with trailing `/` preserves it), or copied a Cargo
2390        // `path = "../caixa-teia/"` entry from cross-substrate documentation
2391        // (Cargo accepts both shapes and folds them the same way). Two
2392        // workstations whose authors differ only in tab-completion habits
2393        // emit byte-divergent lacres for the byte-identical-semantic caixa,
2394        // and the substrate's "the lacre is the build's identity" contract
2395        // (CAIXA-SDLC §III.2) silently breaks far from the source caixa.lisp.
2396        //
2397        // Same THEORY.md §V.2 render-determinism axis every prior `:caminho`
2398        // arm protects, here against the trailing-separator divergence
2399        // vector: every typed slot's accepted set excludes byte-divergent
2400        // values that round-trip to the same downstream semantic. The peer
2401        // path-shaped axes already reject trailing separators on the same
2402        // contract: [`crate::render::is_gateway_api_http_path`] gates
2403        // `:entrada :paths` against any non-canonical normalization, and
2404        // [`crate::render::is_sandboxed_relative_path`] gates the M2 typed
2405        // path-slots (`:behavior :on-*`, `:upgrade-from :state-change
2406        // :script`, `:bibliotecas`, `:exe`, `:servicos`) against shapes
2407        // whose canonical form would re-introduce determinism divergence.
2408        //
2409        // The arm fires last in the cascade because every prior arm carries
2410        // a more self-locating diagnostic on values that probe as both
2411        // (e.g. `:caminho "../foo/\0/"` ends in `/` but the load-bearing
2412        // diagnostic is the NUL byte's POSIX-syscall-rejection — the
2413        // control-char arm wins; `:caminho "/etc/passwd/"` ends in `/` but
2414        // the load-bearing diagnostic is the absolute host-layout-leak —
2415        // the absolute arm wins; `:caminho "..\caixa-teia/"` ends in `/`
2416        // but the load-bearing diagnostic is the Windows-separator cross-
2417        // OS divergence — the backslash arm wins). The arm covers every
2418        // shape where the last byte is `/` regardless of length, including
2419        // the degenerate single-`/` (which the absolute arm catches first)
2420        // and the consecutive-`//` (where every prior arm passes on the
2421        // bytes other than the trailing `/`).
2422        if caminho.as_bytes().last() == Some(&b'/') {
2423            return Err(DepError::FonteCaminhoTrailingSlash {
2424                nome: nome.to_string(),
2425                caminho: caminho.to_string(),
2426            });
2427        }
2428        Ok(())
2429    }
2430}
2431
2432impl Dep {
2433    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:nome` scalar
2434    /// accessor every consumer of the dep-graph identity axis keys off —
2435    /// returns the author-declared `:nome` byte-string verbatim as a
2436    /// `&str`, borrowed from the typed slot's own [`String`] storage.
2437    ///
2438    /// The `:deps :nome` / `:deps-dev :nome` slot carries the DNS-1123
2439    /// label that names the target caixa (validated by [`Self::validate`]
2440    /// through the shared [`crate::render::is_dns_1123_label`] predicate,
2441    /// same accept-set the peer caixa-identifier axes carry — top-level
2442    /// [`crate::Caixa::nome`], per-`:membros` [`crate::Membro::nome`],
2443    /// per-`:children` [`crate::supervisor::ChildSpec::nome`]). Every
2444    /// downstream consumer that fans on the dep's name-identity keys off
2445    /// this scalar: the [`crate::Caixa::validate_deps`] per-list
2446    /// [`crate::render::insert_first_seen`] dedup key + the paired
2447    /// [`DepError::DuplicateNome`] carrier the walk raises on collision,
2448    /// the cross-list [`validate_no_self_dep`] parent-name equality gate
2449    /// on both `:deps` and `:deps-dev` traversals, the `caixa-resolver`
2450    /// pipeline's `HashSet<String>` seen-set the closure walker gates
2451    /// requeueing off (`caixa-resolver/src/resolve.rs:55`), the resolver's
2452    /// per-transitive-target requeue path (`resolve.rs:63,66`), the
2453    /// [`crate::DepSource::default_github`]-shaped resolver-side shorthand
2454    /// fill-in that folds `:nome` into the fetched-git-URL (`resolve.rs:147`),
2455    /// every `caixa-resolver` `ResolveError::MissingPath` /
2456    /// `ResolveError::MissingPin` carrier that names the offending dep
2457    /// (`resolve.rs:177,206`), each resolved
2458    /// `caixa-lacre::LacreEntry` `nome:` field the closure hash keys off
2459    /// (`resolve.rs:108,113`), and the peer `feira lock` stub-resolver's
2460    /// `LacreEntry` emitter (`caixa-feira/src/cmd/lock.rs:59,61,64`).
2461    ///
2462    /// Prior to this lift the `.nome` byte-string was read inline at every
2463    /// production site — the [`crate::Caixa::validate_deps`] paired
2464    /// `dep.nome.as_str()` / `dep.nome.clone()` accesses on both `:deps`
2465    /// and `:deps-dev` traversals, the [`validate_no_self_dep`] pair of
2466    /// parent-equality checks, and every caixa-resolver / caixa-feira
2467    /// site enumerated above — open-coded field-accesses that expressed
2468    /// no compile-time link back to the typed slot. A future extension of
2469    /// the `:deps :nome` axis to a richer author surface (a per-scope
2470    /// alias table the resolver folds through the `~/.config/caixa/config.yaml`
2471    /// entry the [`crate::dep::Dep`] docstring already acknowledges, a
2472    /// namespace-qualified rewrite the future M4 lacre-federation layer
2473    /// applies per-cluster, a promotion of the plain [`String`] byte-string
2474    /// to a richer scoped-identifier newtype once cross-registry federation
2475    /// lands) would have had to be threaded through every open-coded copy
2476    /// in lockstep or two consumers would silently disagree on which caixa
2477    /// a given dep resolves to — the [`crate::Caixa::validate_deps`] dedup
2478    /// set treating the name as `"caixa-teia"` while the caixa-resolver
2479    /// closure walker treated it as `"tenant-a/caixa-teia"` would silently
2480    /// split the [`DepError::DuplicateNome`] refusal from the resolver's
2481    /// requeue-suppression seen-set, one build-time diagnostic
2482    /// disagreeing with the run-time closure the substrate's lacre
2483    /// pipeline actually materializes. Lifting the resolution rule to a
2484    /// typed method on the substrate primitive means every downstream
2485    /// consumer of the caixa's per-`:deps` identity surface reaches for
2486    /// exactly one typed dispatch — the resolver's accept-set migrates as
2487    /// a unit on any future axis addition.
2488    ///
2489    /// First accessor on the outer `Dep` type — opens the outer-`Dep`
2490    /// `&str`-return required-scalar projection pattern the sibling
2491    /// per-`Dep` `:versao` future lift folds on. Peer of the sibling
2492    /// per-`:membros` [`crate::Membro::nome`] (4a32abf) /
2493    /// per-`:children` [`crate::supervisor::ChildSpec::nome`] (dfb4a81)
2494    /// / top-level [`crate::Caixa::nome`] (e6b7d97) caixa-identity scalar
2495    /// accessors — same "one typed dispatch on the substrate primitive,
2496    /// thin projections at each consumer" discipline extended onto the
2497    /// third named-caixa-referencing axis (`:deps` / `:deps-dev`), the
2498    /// remaining unlifted caixa-name-referencing accessor family in the
2499    /// substrate. Named `nome()` to match the tatara-lisp author-surface
2500    /// term the field's docstring already reaches for ("Caixa name — must
2501    /// match the target caixa's `:nome`") and the peer caixa-identity
2502    /// accessor family the substrate already carries.
2503    #[must_use]
2504    pub fn nome(&self) -> &str {
2505        self.nome.as_str()
2506    }
2507
2508    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:versao`
2509    /// Cargo-shaped semver-requirement scalar accessor every consumer of
2510    /// the dep-graph version-pin axis keys off — returns the author-
2511    /// declared `:versao` requirement byte-string verbatim as a `&str`,
2512    /// borrowed from the typed slot's own [`String`] storage.
2513    ///
2514    /// The `:deps :versao` / `:deps-dev :versao` slot carries the
2515    /// Cargo-shaped semver requirement string (`"^0.1"`, `"~0.1.2"`,
2516    /// `"0.1.0"`, `"*"`) the shared [`crate::version::parse_requirement`]
2517    /// entry-point consumes — same accept-set the peer requirement-
2518    /// carrying axes carry (per-`:membros`
2519    /// [`crate::Membro::versao_requirement`], per-`:children`
2520    /// [`crate::supervisor::ChildSpec::versao_requirement`]), validated
2521    /// through the shared
2522    /// [`crate::render::require_valid_versao_requirement`] cascade in
2523    /// [`Self::validate`]. Every downstream consumer that fans on the
2524    /// dep's version-pin keys off this scalar: the [`Self::validate`]
2525    /// `require_valid_versao_requirement` gate + the paired
2526    /// [`DepError::VersaoInvalid`] carrier the cascade raises on
2527    /// requirement-shape rejection, the `feira lock` stub-resolver's
2528    /// `format!("{}@{}", dep.nome(), dep.versao_requirement())`
2529    /// `conteudo` hash-input interpolation and the paired
2530    /// `LacreEntry.versao:` `String`-carry fill (`caixa-feira/src/cmd/lock.rs`),
2531    /// and the peer `feira lock` end-to-end fixture in `caixa-feira/tests/feira_e2e.rs`.
2532    ///
2533    /// Prior to this lift the `.versao` byte-string was read inline at
2534    /// every production site — the [`Self::validate`] paired
2535    /// `&self.versao` requirement-gate reference and `self.versao.clone()`
2536    /// error-body carrier, the `caixa-feira/src/cmd/lock.rs` paired
2537    /// `format!("{}@{}", dep.nome(), dep.versao)` `conteudo` interpolation
2538    /// and `versao: dep.versao.clone()` `LacreEntry` fill, and the
2539    /// `caixa-feira/tests/feira_e2e.rs` end-to-end fixture's pair of the
2540    /// same shapes — open-coded field-accesses that expressed no
2541    /// compile-time link back to the typed slot. A future extension of
2542    /// the `:deps :versao` axis to a richer author surface (a per-scope
2543    /// version-lock overlay the resolver folds through the
2544    /// `~/.config/caixa/config.yaml` entry the [`crate::dep::Dep`]
2545    /// docstring already acknowledges, a per-cluster canary-version
2546    /// overlay per MESH-COMPOSITION §III.2, a promotion of the plain
2547    /// [`String`] requirement to a richer parsed-`VersionReq` newtype
2548    /// once cross-registry federation lands) would have had to be
2549    /// threaded through every open-coded copy in lockstep or two
2550    /// consumers would silently disagree on which release constraint a
2551    /// given dep resolves to — the [`Self::validate`] requirement-gate
2552    /// call reading `"^0.1"` while the `feira lock` stub-resolver's
2553    /// `conteudo` hash-input read `"tenant-a-pin/^0.1"` would silently
2554    /// split the [`DepError::VersaoInvalid`] refusal from the lacre's
2555    /// content-addressed hash the substrate's fetch pipeline actually
2556    /// materializes, one build-time diagnostic disagreeing with the
2557    /// run-time closure. Lifting the resolution rule to a typed method
2558    /// on the substrate primitive means every downstream consumer of
2559    /// the caixa's per-`:deps` version-pin surface reaches for exactly
2560    /// one typed dispatch — the resolver's accept-set migrates as a
2561    /// unit on any future axis addition.
2562    ///
2563    /// Second accessor on the outer `Dep` type — folds on the outer-
2564    /// `Dep` `&str`-return required-scalar projection pattern the
2565    /// sibling per-`Dep` [`Self::nome`] (eba2cde) accessor opened. Peer
2566    /// of the per-`:membros` [`crate::Membro::versao_requirement`]
2567    /// (a40b0e3) / per-`:children`
2568    /// [`crate::supervisor::ChildSpec::versao_requirement`] (7844f4e
2569    /// family) member/child version-pin accessors — the three
2570    /// requirement-carrying axes (`Dep::versao_requirement` on the
2571    /// per-caixa dep-graph edge, `Membro::versao_requirement` on the M3
2572    /// Aplicacao side, `ChildSpec::versao_requirement` on the M2
2573    /// Supervisor side) now share one accessor discipline for the
2574    /// shared substrate concept "another caixa referenced by a
2575    /// Cargo-shaped semver requirement". The pair
2576    /// `(nome(), versao_requirement())` jointly projects the
2577    /// `(nome, versao)` field pair every dep-graph consumer that fans
2578    /// on per-dep identity + version pin keys off. Named
2579    /// `versao_requirement()` rather than `versao()` because the field's
2580    /// storage-side `.versao` label is already the author-surface term
2581    /// (`:versao`); the accessor's name carries the semantic role — the
2582    /// semver *requirement* string the shared
2583    /// [`crate::version::parse_requirement`] entry-point consumes — so a
2584    /// raw field access and a typed dispatch read differently at every
2585    /// consumer site. Matches the peer
2586    /// [`crate::Membro::versao_requirement`] /
2587    /// [`crate::supervisor::ChildSpec::versao_requirement`] naming
2588    /// discipline verbatim.
2589    #[must_use]
2590    pub fn versao_requirement(&self) -> &str {
2591        self.versao.as_str()
2592    }
2593
2594    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:fonte`
2595    /// Zig-store-model per-dep source-tuple optional-composite-reference
2596    /// accessor every consumer of the dep-graph fetch-source axis keys
2597    /// off — returns the author-declared `:fonte` typed [`DepSource`]
2598    /// verbatim as an `Option<&DepSource>` borrowed from the typed slot's
2599    /// own `Option<DepSource>` storage, with `None` naming the "author
2600    /// omitted `:fonte`" shorthand every resolver-side default-fill
2601    /// (`caixa-feira/src/cmd/lock.rs`'s stub, `caixa-resolver/src/resolve.rs`'s
2602    /// canonical fetcher, per the [`DepSource::default_github`] fallback
2603    /// the [`Dep::fonte`] field docstring already documents) treats as
2604    /// the "resolve through the configured default host / org
2605    /// (`github:<default-org>/<nome>`)" partition.
2606    ///
2607    /// The `:deps :fonte` / `:deps-dev :fonte` slot carries the two-
2608    /// arm typed [`DepSource`] the `Zig-style git-only store model` the
2609    /// enclosing [`Dep`] docstring names — `DepSource::Git { repo, tag,
2610    /// rev, branch }` for the git-clone arm every published caixa
2611    /// resolves through, `DepSource::Path { caminho }` for the dev-only
2612    /// local-filesystem arm every unpublishable in-tree checkout
2613    /// resolves through. Every downstream consumer that fans on the
2614    /// dep's fetch-source keys off this accessor: [`Self::validate`]'s
2615    /// per-`:fonte` [`DepSource::validate`] delegation (which raises
2616    /// the empty-`:repo` / missing-pin / multiple-pin / empty-`:caminho`
2617    /// diagnostics through the [`DepError::Fonte*`] carrier family
2618    /// naming the offending `Dep::nome`), the caixa-crd conversion
2619    /// crate's `dep_into_ref` two-arm projection into the `CaixaSource`
2620    /// `{repo, git_ref}` pair the K8s-CR side consumes
2621    /// (`caixa-crd/src/conversion.rs`), and — through the paired
2622    /// resolver-side default-fill's `Option::unwrap_or_else` — every
2623    /// `caixa-feira` / `caixa-resolver` fetch site that requires a
2624    /// concrete `DepSource` at run time.
2625    ///
2626    /// Prior to this lift the `.fonte` typed slot was read inline at
2627    /// every production site — the [`Self::validate`]
2628    /// `if let Some(ref fonte) = self.fonte` bracket the per-`:fonte`
2629    /// gate delegates through, the caixa-crd `dep_into_ref`
2630    /// `d.fonte.as_ref().and_then(...)` two-arm `CaixaSource` projector,
2631    /// the resolver-side `caixa-feira/src/cmd/lock.rs` / `caixa-resolver/src/resolve.rs`
2632    /// `dep.fonte.clone().unwrap_or_else(...)` default-fill pair — open-
2633    /// coded field-accesses that expressed no compile-time link back to
2634    /// the typed slot. A future extension of the `:deps :fonte` axis
2635    /// to a richer author surface (a per-scope source-override table
2636    /// the resolver folds through the `~/.config/caixa/config.yaml`
2637    /// entry the [`Dep`] docstring already acknowledges, a per-org
2638    /// mirror-fallback list the future M4 lacre-federation resolver
2639    /// consults ahead of the `default_github` fallback, a promotion of
2640    /// the plain `Option<DepSource>` to a richer
2641    /// `{primary, mirrors, integrity}` triple once cross-registry
2642    /// federation lands, a per-dep `sri:sha256-…` integrity slot the
2643    /// M4 lacre gate binds against ahead of the git-fetch) would have
2644    /// had to be threaded through every open-coded copy in lockstep or
2645    /// two consumers would silently disagree on which fetch source a
2646    /// given dep resolves to — the [`Self::validate`] per-`:fonte`
2647    /// gate reading the author-declared source while the caixa-crd
2648    /// projector read a per-scope-override-resolved source would
2649    /// silently split the build-time refusal from the CR the
2650    /// substrate's admission pipeline actually materializes, one
2651    /// build-time diagnostic disagreeing with the run-time closure.
2652    /// Lifting the resolution rule to a typed method on the substrate
2653    /// primitive means every downstream consumer of the caixa's per-
2654    /// `:deps` fetch-source surface reaches for exactly one typed
2655    /// dispatch — the resolver's accept-set migrates as a unit on any
2656    /// future axis addition.
2657    ///
2658    /// First outer-`Dep` `Option<&Composite>`-return composite-reference
2659    /// accessor — opens the outer-`Dep` `Option<&Composite>` composite-
2660    /// reference projection pattern the sibling per-`Dep` `:opcional`
2661    /// (`Option<Copy>` — the plain-bool axis) / `:caracteristicas`
2662    /// (`&[String]` — the feature-flag list) future outer scalar / slice
2663    /// lifts fold on. Peer of the outer-top-level [`crate::Caixa`]
2664    /// `Option<&Composite>` composite-reference sub-family the
2665    /// [`crate::Caixa::limits`] (b2bd9d7) / [`crate::Caixa::behavior`]
2666    /// (35d8b52) / [`crate::Caixa::politicas`] (5d23d29) /
2667    /// [`crate::Caixa::placement`] (4fb8074) / [`crate::Caixa::entrada`]
2668    /// (e4128e4) accessors already close on the outer [`crate::Caixa`]
2669    /// altitude, and of the outer M3 mesh-slot [`crate::AplicacaoSpec`]
2670    /// altitude the sibling [`crate::AplicacaoSpec::entrada`] (d32111c)
2671    /// accessor already carries — extends that "one typed dispatch on
2672    /// the substrate primitive, thin projections at each consumer"
2673    /// discipline onto the third outer typed-slot altitude that carries
2674    /// an `Option<Composite>` axis (`Dep`, the outer per-dep-list-entry
2675    /// slot). Returns `Option<&DepSource>` (not the owning composite by
2676    /// copy or clone) because every downstream consumer of the fonte
2677    /// composite treats it as a read-only per-arm dispatch source — the
2678    /// reference-view is the narrowest borrow that supports every
2679    /// present + roadmapped consumer (per-arm match projection at the
2680    /// caixa-crd `CaixaSource` two-arm emitter, presence-probe early
2681    /// return on the "author-omitted `:fonte` ⇒ resolver-side
2682    /// `default_github` fill applies" partition every resolver
2683    /// consults, `.cloned()`-on-demand for the two resolver-side
2684    /// default-fill call sites that require an owned `DepSource` for
2685    /// `Option::unwrap_or_else`) without cloning the composite through
2686    /// every consumer's fast path. The `Option` half of the return-type
2687    /// preserves the load-bearing "author-omitted `:fonte` ⇒ resolver-
2688    /// side default applies" partition (not a default composite the
2689    /// downstream must reject on emptiness) — the accessor projects the
2690    /// raw `Option<DepSource>` slot's presence bit through the
2691    /// reference-return unchanged. Named `fonte()` to match the storage
2692    /// field's name verbatim and the tatara-lisp author-surface term
2693    /// (`:fonte`) the field's own docstring already carries.
2694    #[must_use]
2695    pub fn fonte(&self) -> Option<&DepSource> {
2696        self.fonte.as_ref()
2697    }
2698
2699    /// Substrate-canonical per-`:deps` / `:deps-dev` entry
2700    /// `:caracteristicas` Cargo-shaped feature-toggle-set slice accessor
2701    /// every consumer of the dep-graph feature-flag axis keys off —
2702    /// returns the author-declared `:caracteristicas` feature-name list
2703    /// verbatim as a `&[String]` slice-view over the same backing buffer
2704    /// the raw `self.caracteristicas.as_slice()` field access borrows
2705    /// from. Empty-list-carrying (`:caracteristicas` is a default-empty
2706    /// axis every `Dep` supplies with `Vec::new()` when the author omits
2707    /// the slot; the [`crate::Caixa::from_lisp`] derive folds an omitted
2708    /// `:caracteristicas` through `#[serde(default)]` to `Vec::new()`,
2709    /// so a `Dep` past parse definitionally carries a `Vec<String>` slot
2710    /// — possibly empty — and the returned `&[String]` degenerates to
2711    /// an empty slice on that arm without any silent `None` collapse).
2712    ///
2713    /// The `:deps :caracteristicas` / `:deps-dev :caracteristicas` slot
2714    /// carries the set-shaped feature-toggle list the substrate walks
2715    /// through the [`Self::validate_caracteristicas`] per-entry shape +
2716    /// duplicate cascade — same Cargo `[dependencies.<dep>.features]`
2717    /// accept-set (per-entry Cargo-feature-name grammar via the shared
2718    /// [`crate::render::is_cargo_feature_name`] predicate, cross-entry
2719    /// uniqueness via the shared [`crate::render::insert_first_seen`]
2720    /// walk, empty-first / value-shape-second / duplicate-third
2721    /// precedence via the peer per-axis two-arm cascade discipline every
2722    /// substrate-blessed Vec-keyed-by-name slot already follows).
2723    /// Every downstream consumer that fans on the dep's feature-toggle
2724    /// keys off this accessor: [`Self::validate_caracteristicas`]'s
2725    /// per-entry linear walk that gates each feature-name byte-string
2726    /// through the empty / value-shape / duplicate arms (raising the
2727    /// [`DepError::CaracteristicaEmpty`] / [`DepError::CaracteristicaInvalid`]
2728    /// / [`DepError::CaracteristicaDuplicate`] carrier family naming the
2729    /// offending `Dep::nome`), and every future
2730    /// per-`Caixa`-manifest / caixa-resolver / caixa-crd feature-toggle-
2731    /// facing consumer the CAIXA-SDLC §I roadmap acknowledges (the
2732    /// future caixa-resolver per-dep feature-projection walk that folds
2733    /// the toggle set into the resolved [`crate::Caixa`]'s activated
2734    /// [`crate::render::CARGO_FEATURE_NAME_MAX_LEN`]-bounded feature
2735    /// closure ahead of the lacre hash, the future caixa-crd per-`spec.deps`
2736    /// features slice the K8s-CR admission gate consumes, the future
2737    /// per-cluster feature-overlay the M4 lacre-federation resolver
2738    /// composes ahead of the substrate-wide feature-name accept-set).
2739    ///
2740    /// Prior to this lift the `.caracteristicas` byte-string list was
2741    /// read inline at the [`Self::validate_caracteristicas`] `for c in
2742    /// &self.caracteristicas` walk — the only in-crate consumer of the
2743    /// raw field beyond the per-`Dep` constructor pair
2744    /// ([`Self::simple`] / [`Self::git`]) and the paired serde
2745    /// round-trip / per-test fixture-mutation paths — an open-coded
2746    /// field-access that expressed no compile-time link back to the
2747    /// typed slot. A future extension of the `:caracteristicas` axis to
2748    /// a richer author surface (a per-scope feature-overlay the resolver
2749    /// folds through the `~/.config/caixa/config.yaml` entry the
2750    /// [`Dep`] docstring already acknowledges, a per-cluster feature-
2751    /// activation overlay the future M4 lacre-federation layer applies
2752    /// per-CR, a promotion of the plain `Vec<String>` byte-string list
2753    /// to a richer parsed-feature-set newtype once the Cargo-shaped
2754    /// namespaced-dep `dep/feat` syntax the value-shape gate's
2755    /// docstring anticipates lands) would have had to be threaded
2756    /// through every open-coded copy in lockstep or two consumers
2757    /// would silently disagree on which feature closure a given dep
2758    /// activates — the [`Self::validate_caracteristicas`] gate walking
2759    /// the author-declared list while a downstream caixa-resolver
2760    /// consumer walked a per-scope-override-resolved list would
2761    /// silently split the build-time refusal from the lacre closure
2762    /// the substrate's fetch pipeline actually materializes, one
2763    /// build-time diagnostic disagreeing with the run-time closure.
2764    /// Lifting the resolution rule to a typed method on the substrate
2765    /// primitive means every downstream consumer of the caixa's per-
2766    /// `:deps` feature-toggle surface reaches for exactly one typed
2767    /// dispatch — the resolver's accept-set migrates as a unit on any
2768    /// future axis addition.
2769    ///
2770    /// First outer-`Dep` `&[T]`-return slice accessor — opens the
2771    /// outer-`Dep` `&[String]` slice projection pattern the sibling
2772    /// per-`Dep` `:opcional` (`bool` — the plain-`Copy`-scalar axis)
2773    /// future outer scalar lift folds on and closes the outer-`Dep`
2774    /// slot-family the sibling [`Self::nome`] (eba2cde) /
2775    /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2776    /// accessors already open, leaving the `:opcional` `Copy`-scalar arm
2777    /// as the sole remaining unlifted outer-`Dep` slot. Peer of the
2778    /// outer top-level [`crate::Caixa`] `&[String]`-return foreign-code-
2779    /// slot sub-family ([`crate::Caixa::bibliotecas`] 8a36c23,
2780    /// [`crate::Caixa::exe`] 65d9527, [`crate::Caixa::servicos`]
2781    /// 611f78b) and the outer top-level [`crate::Caixa`] universal-axis
2782    /// text-tag family ([`crate::Caixa::autores`] b5d813f,
2783    /// [`crate::Caixa::etiquetas`] 78c7d3c) that already carry the
2784    /// `&[String]` slice-projection discipline on the outer-`Caixa`
2785    /// altitude — extends the "one typed dispatch on the substrate
2786    /// primitive, thin projections at each consumer" discipline onto the
2787    /// outer per-dep-list-entry [`Dep`] altitude's set-shaped byte-
2788    /// string list slot. Returns `&[String]` (not `&Vec<String>`)
2789    /// because every downstream consumer of the feature-toggle list
2790    /// treats it as a read-only sequence — the slice-view is the
2791    /// narrowest borrow that supports every present + roadmapped
2792    /// consumer (`.iter()`, `.len()`, `.is_empty()`) without leaking
2793    /// the backing `Vec`'s grow/push/reserve surface no consumer of
2794    /// the typed view reaches for (the storage-side `Vec` remains
2795    /// reachable through the `pub caracteristicas` field for the
2796    /// mutation-carrying serde round-trip and per-test fixture-mutation
2797    /// paths). Named `caracteristicas()` to match the storage field's
2798    /// name verbatim and the tatara-lisp author-surface term
2799    /// (`:caracteristicas`) the field's own docstring already carries.
2800    #[must_use]
2801    pub fn caracteristicas(&self) -> &[String] {
2802        self.caracteristicas.as_slice()
2803    }
2804
2805    /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:opcional`
2806    /// missing-source-tolerance flag scalar accessor every consumer of
2807    /// the dep-graph opt-in-fetch axis keys off — returns the author-
2808    /// declared `:opcional` `bool` verbatim, `Copy`-projected from the
2809    /// typed slot's own `bool` storage (no borrow of `&self` past the
2810    /// call; the `Copy`-return arm matches the peer
2811    /// [`crate::Caixa::max_restarts`] (eba5211) `Option<u32>` `Copy`-
2812    /// projected sibling discipline the outer flat-spread family
2813    /// already carries). Default-`false` (`#[serde(default,
2814    /// skip_serializing_if = "is_false")]` on the storage slot, so a
2815    /// `Dep` past parse definitionally carries a `bool` — `false` when
2816    /// the author omits `:opcional` — and the returned value degenerates
2817    /// to `false` on that arm without any silent `None` collapse).
2818    ///
2819    /// The `:deps :opcional` / `:deps-dev :opcional` slot carries the
2820    /// per-entry "if this dep's `:fonte` cannot be resolved, treat the
2821    /// missing-source arm as a soft-fail rather than a build refusal"
2822    /// bit — the same Cargo-shaped `[dependencies.<dep>.optional = true]`
2823    /// accept-set (an opcional dep whose `:fonte` fails to resolve is
2824    /// dropped from the resolved dep-graph rather than tripping the
2825    /// build-refusal edge that a mandatory `:opcional false` entry
2826    /// would). Every downstream consumer that fans on the dep's
2827    /// missing-source-tolerance keys off this accessor: the future
2828    /// caixa-resolver's per-`:fonte` resolve-fail arm (drop-vs-error
2829    /// dispatch on the opcional bit ahead of the lacre closure
2830    /// materialization), the future caixa-crd per-`spec.deps`
2831    /// `optional` boolean the K8s-CR admission gate consumes on the
2832    /// per-dep partition, and the future feira / caixa-resolver /
2833    /// caixa-crd feature-projection walk that folds the opcional bit
2834    /// into the resolved feature-closure the future M4 lacre-federation
2835    /// layer emits.
2836    ///
2837    /// Prior to this lift the `.opcional` `bool` slot was read inline
2838    /// at the sole in-crate consumer site — the tests-module
2839    /// `registry_dep_is_minimal` fixture's `assert!(!d.opcional)` gate
2840    /// pinning the [`Self::simple`] constructor's default-`false` fill
2841    /// (the only in-crate read of the raw field beyond the per-`Dep`
2842    /// constructor pair [`Self::simple`] / [`Self::git`] and the paired
2843    /// serde round-trip / per-test fixture-mutation paths) — an open-
2844    /// coded field-access that expressed no compile-time link back to
2845    /// the typed slot. A future extension of the `:opcional` axis to a
2846    /// richer author surface (a per-scope opcional-override the resolver
2847    /// folds through the `~/.config/caixa/config.yaml` entry the [`Dep`]
2848    /// docstring already acknowledges, a per-cluster opcional-override
2849    /// the future M4 lacre-federation layer applies per-CR, a promotion
2850    /// of the plain `bool` to a richer `OpcionalPolicy { drop, warn,
2851    /// error }` tri-state once the CAIXA-SDLC §II opcional-policy
2852    /// roadmap lands) would have had to be threaded through every open-
2853    /// coded copy in lockstep or two consumers would silently disagree
2854    /// on which missing-source arm a given dep resolves to — the
2855    /// [`Self::simple`] constructor's default-`false` fill reading
2856    /// verbatim while a downstream caixa-resolver consumer read a per-
2857    /// scope-override-resolved bit would silently split the build-time
2858    /// arm from the lacre closure the substrate's fetch pipeline
2859    /// actually materializes, one build-time diagnostic disagreeing
2860    /// with the run-time closure. Lifting the resolution rule to a
2861    /// typed method on the substrate primitive means every downstream
2862    /// consumer of the caixa's per-`:deps` opcional-tolerance surface
2863    /// reaches for exactly one typed dispatch — the resolver's accept-
2864    /// set migrates as a unit on any future axis addition.
2865    ///
2866    /// Fifth and final outer-`Dep` accessor — closes the outer-`Dep`
2867    /// slot-family the sibling per-`Dep` [`Self::nome`] (eba2cde) /
2868    /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2869    /// / [`Self::caracteristicas`] (9197944) accessors opened, so every
2870    /// outer-`Dep` slot (`:nome`, `:versao`, `:fonte`, `:opcional`,
2871    /// `:caracteristicas`) now routes through exactly one typed
2872    /// dispatch on the substrate primitive. First outer-`Dep`
2873    /// `bool`-return / plain-`Copy`-scalar accessor — opens the
2874    /// outer-`Dep` `Copy`-scalar projection pattern that folds on the
2875    /// peer outer-top-level [`crate::Caixa`] `Option<Copy>`
2876    /// flat-spread sub-family ([`crate::Caixa::max_restarts`] eba5211,
2877    /// [`crate::Caixa::estrategia`] ed04d3c) the outer-`Caixa` altitude
2878    /// already carries — extends the "one typed dispatch on the
2879    /// substrate primitive, thin projections at each consumer"
2880    /// discipline onto the outer per-dep-list-entry [`Dep`] altitude's
2881    /// bool-shaped missing-source-tolerance slot. Returns `bool` by
2882    /// `Copy` (not by `&bool` reference) because `bool` is `Copy` and
2883    /// every downstream consumer treats it as a plain discriminant
2884    /// value — the by-value return is the narrowest return-shape that
2885    /// supports every present + roadmapped consumer (`.then(…)` early
2886    /// return on the resolver-side drop-vs-error partition, direct
2887    /// bool composition with a per-scope-override projector, plain
2888    /// `if dep.opcional() { … }` early return at every future admission
2889    /// gate) without leaking the storage field's `bool`-in-`&self`
2890    /// lifetime the by-value return elides. Marked `pub const fn` so
2891    /// the accessor is `const`-callable — same discipline the peer
2892    /// [`crate::Caixa::max_restarts`] `Option<u32>` `Copy`-return
2893    /// accessor carries. Named `opcional()` to match the storage
2894    /// field's name verbatim and the tatara-lisp author-surface term
2895    /// (`:opcional`) the field's own docstring already carries.
2896    #[must_use]
2897    pub const fn opcional(&self) -> bool {
2898        self.opcional
2899    }
2900
2901    /// Build a minimal registry-sourced dep.
2902    #[must_use]
2903    pub fn simple(nome: impl Into<String>, versao: impl Into<String>) -> Self {
2904        Self {
2905            nome: nome.into(),
2906            versao: versao.into(),
2907            fonte: None,
2908            opcional: false,
2909            caracteristicas: Vec::new(),
2910        }
2911    }
2912
2913    /// Build a Git-sourced dep (tag-based).
2914    #[must_use]
2915    pub fn git(
2916        nome: impl Into<String>,
2917        versao: impl Into<String>,
2918        repo: impl Into<String>,
2919        tag: impl Into<String>,
2920    ) -> Self {
2921        Self {
2922            nome: nome.into(),
2923            versao: versao.into(),
2924            fonte: Some(DepSource::Git {
2925                repo: repo.into(),
2926                tag: Some(tag.into()),
2927                rev: None,
2928                branch: None,
2929            }),
2930            opcional: false,
2931            caracteristicas: Vec::new(),
2932        }
2933    }
2934
2935    /// Reject dependency entries whose `:nome` or `:versao` are empty,
2936    /// whose `:nome` is non-empty but not a valid DNS-1123 label,
2937    /// or whose `:versao` is non-empty but not a valid Cargo-shaped
2938    /// semver requirement.
2939    ///
2940    /// The author surface for `:deps :versao` (and `:deps-dev :versao`)
2941    /// is the same Cargo-shaped requirement string `:membros :versao`
2942    /// (validated at [`crate::AplicacaoSpec::validate`] since 9888b13)
2943    /// and `:children :versao` (validated at
2944    /// [`crate::SupervisorSpec::validate`] since b38ff3a) carry — and
2945    /// the lacre pipeline resolves all three axes through the same
2946    /// [`crate::parse_requirement`] entry-point. Until 2420c44 landed
2947    /// `:deps :versao` was the last `:versao` axis untyped past
2948    /// `Caixa::from_lisp`: a malformed-but-non-empty requirement
2949    /// (`"^bad-version"`, `"^^0.1"`, the canonical git-tag-shape-
2950    /// leaking-into-:versao `"v0.1"` typo, the accidental
2951    /// `"not-a-req"`) silently passed parse and the `semver::Error`
2952    /// surfaced at lacre-resolve time, far from the source
2953    /// caixa.lisp, with no field naming which `:deps` entry carried
2954    /// the typo. The diagnostic [`DepError::VersaoInvalid`] carries
2955    /// the offending entry's `:nome` + the offending `:versao`
2956    /// verbatim + the parser's own wording in `reason`, so the
2957    /// author's grep target is unambiguous.
2958    ///
2959    /// The author surface for `:deps :nome` is the same DNS-1123 label
2960    /// the peer caixa-identifier axes carry — top-level Caixa `:nome`
2961    /// (validated at [`crate::Caixa::validate_nome`] since 6c992f8),
2962    /// `:membros :caixa` (validated at
2963    /// [`crate::AplicacaoSpec::validate_membros`] since 3f9d7a0),
2964    /// `:children :caixa` (validated at
2965    /// [`crate::SupervisorSpec::validate`] since 31bfa43). A `:deps
2966    /// :nome` value flows verbatim through the lacre pipeline as the
2967    /// target caixa's `:nome` (which the gate at the *target* side now
2968    /// rejects if non-DNS-1123) and lands as the rendered caixa's
2969    /// `lareira-<nome>` Helm chart name segment, the per-dep
2970    /// `LABEL_PROGRAM` label value, and the `caixa-resolver`'s
2971    /// `~/.cache/caixa/<org>/<nome>` checkout-directory leaf. Until
2972    /// this gate landed `:deps :nome` was the fourth and last
2973    /// DNS-1123-shaped caixa-identifier axis still untyped past
2974    /// `Caixa::from_lisp`: a syntactically wrong dep name (`"Caixa-
2975    /// Teia"` uppercase — the canonical "I copied the README header"
2976    /// typo; `"caixa_teia"` underscore — the Go module / Python
2977    /// identifier leak; `"caixa-teia."` trailing dot — the FQDN
2978    /// confusion; `"-caixa-teia"` leading hyphen; a 64-byte slug)
2979    /// silently passed parse and surfaced at lacre-resolve time when
2980    /// the resolved target caixa's `:nome` failed *its* DNS-1123 gate
2981    /// — far from the source `:deps` entry, with a diagnostic naming
2982    /// the *target's* `:nome` rather than the dep entry that referenced
2983    /// it. Mirroring the 3f9d7a0 / 31bfa43 / 6c992f8 trajectory through
2984    /// the lifted [`crate::render::is_dns_1123_label`] predicate (the
2985    /// "before its third occurrence" PRIME DIRECTIVE boundary, THEORY.md
2986    /// §I.3.5): every `Dep::nome` past validate is DNS-1123-label-shaped,
2987    /// so every downstream consumer (caixa-resolver's lacre fetch,
2988    /// caixa-helm's `lareira-<nome>` chart name, the future M4 per-dep
2989    /// fan-out emitter) reaches for the name knowing the value is
2990    /// apiserver-valid without re-validating.
2991    ///
2992    /// Empty checks fire first (narrower diagnostic), parse last —
2993    /// same ordering discipline as
2994    /// [`crate::AplicacaoSpec::validate_membros`] and
2995    /// [`crate::SupervisorSpec::validate`]. `parse_requirement("")`
2996    /// returns `Ok(VersionReq::STAR)`, so the empty-`:versao` arm is
2997    /// structurally necessary even with the parse arm in place. The
2998    /// `:nome` shape gate runs after the `:nome` empty gate and before
2999    /// the `:versao` checks so a one-entry caixa.lisp with both wrong
3000    /// sees the name-side diagnostic first (the name is the
3001    /// self-locating axis — without it, the parse diagnostic can't
3002    /// quote `:nome "<bad>"`).
3003    pub fn validate(&self) -> Result<(), DepError> {
3004        if self.nome.is_empty() {
3005            return Err(DepError::NomeEmpty);
3006        }
3007        if let Err(reason) = crate::render::is_dns_1123_label(&self.nome) {
3008            return Err(DepError::NomeInvalid {
3009                nome: self.nome.clone(),
3010                reason,
3011            });
3012        }
3013        // Delegate the empty-first + `parse_requirement` cascade to the
3014        // shared [`crate::render::require_valid_versao_requirement`]
3015        // helper — same two-arm shape the peer
3016        // [`crate::AplicacaoSpec::validate_membros`] on `:membros
3017        // :versao` and [`crate::SupervisorSpec::validate`] on `:children
3018        // :versao` route through, so drift between the three axes'
3019        // accepted requirement sets is structurally impossible and the
3020        // parse-side no-op the empty-first arm closes (semver's empty
3021        // parse yields an implicit `*`) lives in exactly one predicate.
3022        crate::render::require_valid_versao_requirement(
3023            self.versao_requirement(),
3024            || DepError::VersaoEmpty {
3025                nome: self.nome.clone(),
3026            },
3027            |reason| DepError::VersaoInvalid {
3028                nome: self.nome.clone(),
3029                versao: self.versao_requirement().to_string(),
3030                reason,
3031            },
3032        )?;
3033        if let Some(fonte) = self.fonte() {
3034            fonte.validate(&self.nome)?;
3035        }
3036        self.validate_caracteristicas()?;
3037        Ok(())
3038    }
3039
3040    /// Reject per-entry `:caracteristicas` (feature-flag) values that
3041    /// are operationally meaningless. The `:caracteristicas` slot is
3042    /// a set of feature toggles to enable on the target caixa — same
3043    /// shape as Cargo's `[dependencies.<dep>.features]` list — and
3044    /// two structural footguns close here:
3045    ///
3046    ///   - empty-string entry (`(:caracteristicas (""))`): the future
3047    ///     caixa-resolver lacre pipeline would consume the empty
3048    ///     identifier as a no-op feature enable, silently dropping the
3049    ///     author's intent far from the source `caixa.lisp`;
3050    ///   - duplicate entry within one dep (`(:caracteristicas ("http"
3051    ///     "http"))`): the feature-toggle slot is set-shaped (enabling
3052    ///     a feature twice has no additional semantic — there is no
3053    ///     `feature × 2`), so two entries naming the same feature are
3054    ///     a silent miscount, the same set-not-multiset distinction
3055    ///     every peer Vec-keyed-by-name axis already closes
3056    ///     ([`crate::SupervisorError::DuplicateChildCaixa`] on
3057    ///     `:children :caixa`, [`crate::AplicacaoError::MembroDuplicate`]
3058    ///     on `:membros :caixa`, [`crate::AplicacaoError::ContratoDuplicate`]
3059    ///     on `:contratos`, [`crate::AplicacaoError::PlacementClusterDuplicate`]
3060    ///     on `:placement :clusters`, [`crate::AplicacaoError::EntradaPathDuplicate`]
3061    ///     on `:entrada :paths`, [`crate::UpgradeError::DuplicateFrom`]
3062    ///     on `:upgrade-from :from`, [`crate::UpgradeError::DuplicateLoadModule`]
3063    ///     / [`crate::UpgradeError::DuplicateStateChange`] /
3064    ///     [`crate::UpgradeError::DuplicateCleanup`] on the within-
3065    ///     entry `:upgrade-from` axes, and [`DepError::DuplicateNome`]
3066    ///     on the cross-entry `:deps`/`:deps-dev` `:nome` axis the
3067    ///     immediate-predecessor 359fba5 closed).
3068    ///
3069    /// Same linear-walk + `HashSet` + first-collision diagnostic shape
3070    /// every peer set-not-multiset gate uses; the empty arm fires
3071    /// before the duplicate arm so an entry with both an empty feature
3072    /// *and* a duplicate of some later feature surfaces the empty-
3073    /// shape diagnostic first (the empty-feature axis is the
3074    /// more-actionable defect since the missing-name renders the
3075    /// duplicate-key arm ambiguous: two `""` entries would both report
3076    /// `caracteristica: ""` with no way to distinguish the offending
3077    /// site). Empty-first cascade discipline mirrors every peer per-
3078    /// entry shape + duplicate gate
3079    /// (`SupervisorSpec::validate`'s `EmptyChildName` before
3080    /// `DuplicateChildCaixa`; `validate_membros`'s `MembroCaixaEmpty`
3081    /// before `MembroDuplicate`).
3082    ///
3083    /// The per-entry value-shape gate (Cargo-feature-name grammar via
3084    /// the lifted [`crate::render::is_cargo_feature_name`] predicate)
3085    /// fires between the empty arm and the duplicate arm — the
3086    /// canonical per-entry-shape-before-cross-entry-uniqueness
3087    /// precedence every peer two-arm + value-shape gate establishes
3088    /// ([`crate::SupervisorSpec::validate`]'s `EmptyChildName` →
3089    /// `ChildCaixaInvalid` → `DuplicateChildCaixa`,
3090    /// [`crate::AplicacaoSpec::validate_membros`]'s `MembroCaixaEmpty`
3091    /// → `MembroCaixaInvalid` → `MembroDuplicate`, [`Dep::validate`]'s
3092    /// `NomeEmpty` → `NomeInvalid` → cross-list `DuplicateNome`).
3093    /// Until the value-shape arm landed `:caracteristicas` accepted
3094    /// every non-empty distinct string — a structurally invalid
3095    /// feature name (`"http feature"` whitespace, `"+http"` the
3096    /// canonical paste-from-`+optional-feature` doc activation-form
3097    /// footgun, `"-flag"` leading hyphen, `".feat"` leading dot,
3098    /// `"http/json"` Cargo's `dep/feat` namespaced-dep syntax that
3099    /// only applies inside list-grammar contexts, `"http,json"`
3100    /// list-separator-belongs-to-the-list-grammar miscomprehension,
3101    /// `"café"` un-percent-encoded non-ASCII silently round-tripping
3102    /// inconsistently across NFC/NFD normalization, the 65-byte
3103    /// paste-from-binary slug) silently passed validate and the
3104    /// failure surfaced at `cargo metadata` time as the
3105    /// `restricted_names::validate_feature_name` parser's rejection,
3106    /// far from the source `caixa.lisp`, with no field naming which
3107    /// `:deps` entry's `:caracteristicas` carried the typo. The
3108    /// lifted predicate makes the Cargo-feature-name-grammar
3109    /// intersection-floor a substrate-level invariant at validate
3110    /// time — same trajectory as the eight peer
3111    /// [`crate::render`] value-shape predicates each typed surface
3112    /// downstream of a structured grammar already follows
3113    /// ([`is_dns_1123_label`](crate::render::is_dns_1123_label),
3114    /// [`is_gateway_api_http_path`](crate::render::is_gateway_api_http_path),
3115    /// [`is_wit_world_ref`](crate::render::is_wit_world_ref),
3116    /// [`is_nats_subject`](crate::render::is_nats_subject),
3117    /// [`is_wasi_keyvalue_slot`](crate::render::is_wasi_keyvalue_slot),
3118    /// [`is_git_ref_name`](crate::render::is_git_ref_name),
3119    /// [`is_git_oid`](crate::render::is_git_oid),
3120    /// [`is_git_repo_url`](crate::render::is_git_repo_url)).
3121    fn validate_caracteristicas(&self) -> Result<(), DepError> {
3122        let mut seen = std::collections::HashSet::new();
3123        for c in self.caracteristicas() {
3124            if c.is_empty() {
3125                return Err(DepError::CaracteristicaEmpty {
3126                    nome: self.nome.clone(),
3127                });
3128            }
3129            if let Err(reason) = crate::render::is_cargo_feature_name(c) {
3130                return Err(DepError::CaracteristicaInvalid {
3131                    nome: self.nome.clone(),
3132                    caracteristica: c.clone(),
3133                    reason,
3134                });
3135            }
3136            crate::render::insert_first_seen(&mut seen, c.as_str(), || {
3137                DepError::CaracteristicaDuplicate {
3138                    nome: self.nome.clone(),
3139                    caracteristica: c.clone(),
3140                }
3141            })?;
3142        }
3143        Ok(())
3144    }
3145}
3146
3147/// Cross-slot coherence gate on the dep-graph axis: no `:deps` or
3148/// `:deps-dev` entry may name the caixa's own `:nome`.
3149///
3150/// A caixa that lists itself as a dep is a degenerate self-edge in the
3151/// lacre closure's dep-graph — the closure is a DAG rooted at the
3152/// caixa's `:nome`, and the caixa-resolver's lacre pipeline traverses
3153/// every `:deps` / `:deps-dev` entry's target by name. A self-dep
3154/// hands the resolver a node that is its own parent: a one-node cycle
3155/// it either rejects mid-traversal far from the source `caixa.lisp`
3156/// (the resolver detecting infinite recursion on the closure walk) or,
3157/// worse, recurses on until it exhausts its stack. Because every
3158/// `:nome` is a globally-unique substrate identity (DNS-1123 label +
3159/// lacre closure root), a dep entry whose `:nome` equals the caixa's
3160/// own `:nome` *is* the caixa itself, not a coincidentally-named peer.
3161///
3162/// Lives outside [`Caixa::validate_deps`] because the dep-list view
3163/// carries the entries but not the parent `:nome`; mirrors the
3164/// cross-slot self-edge gates [`crate::supervisor::validate_no_self_supervision`]
3165/// (ad4abf1) on the `:children :caixa` axis and
3166/// [`crate::aplicacao::validate_no_self_membership`] on the
3167/// `:membros :caixa` axis — the same "an edge from a graph node to
3168/// itself is structurally not a tree/graph edge" discipline, here on
3169/// the third typed-name-graph axis (the dep closure; the supervision
3170/// tree and the Aplicacao membership set were the prior two).
3171///
3172/// Walks `:deps` first then `:deps-dev` so the diagnostic for a caixa
3173/// that self-references on both axes surfaces the `:deps` arm first —
3174/// the load-bearing axis the lacre closure resolves at every build,
3175/// peer with the canonical [`Caixa::validate_deps`] walk order
3176/// (`:deps` → `:deps-dev`).
3177///
3178/// Carries the offending list tag (`":deps"` or `":deps-dev"`)
3179/// verbatim into the diagnostic so the author can grep their
3180/// `caixa.lisp` for the offending block in one edit — same
3181/// `list: &'static str` shape [`DepError::DuplicateNome`] (359fba5)
3182/// uses on the cross-list duplicate-name axis.
3183///
3184/// `Code paths` (`:bibliotecas` / `:exe` / `:servicos`) are the
3185/// substrate-blessed shape for referencing the caixa's *own* code, so
3186/// the diagnostic names them as the corrective surface — every
3187/// legitimate "I want to use code from this caixa" authoring intent
3188/// routes through one of those three slots, not a self-dep.
3189pub fn validate_no_self_dep(
3190    deps: &[Dep],
3191    deps_dev: &[Dep],
3192    parent_nome: &str,
3193) -> Result<(), DepError> {
3194    for dep in deps {
3195        if dep.nome() == parent_nome {
3196            return Err(DepError::DepIsSelf {
3197                nome: parent_nome.to_string(),
3198                list: crate::render::DEP_AUTHOR_KEY_DEPS,
3199            });
3200        }
3201    }
3202    for dep in deps_dev {
3203        if dep.nome() == parent_nome {
3204            return Err(DepError::DepIsSelf {
3205                nome: parent_nome.to_string(),
3206                list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3207            });
3208        }
3209    }
3210    Ok(())
3211}
3212
3213/// Closed-set typed enum for the two dep-list author-surface axes every
3214/// top-level [`crate::Caixa`] carries — the runtime-closure `:deps` slot
3215/// (`Prod`) and the dev-only-closure `:deps-dev` slot (`Dev`). Every
3216/// substrate consumer that dispatches on "which of the two dep-lists"
3217/// (the `feira add` mutation head, the future per-cluster dev-closure-
3218/// audit overlay the M4 CR materializer resolves per-CR, the future
3219/// `caixa app graph` per-list dep summary, every future
3220/// `Caixa::push_dep` / `Caixa::deps_by_list` typed-method dispatch a
3221/// caller reaches for) reads through this enum rather than through a
3222/// bare `&'static str` — the closed-set is expressed at the type layer,
3223/// so a future third dep-list axis (a `:deps-build` build-only closure
3224/// once the substrate grows cross-artifact heterogeneous dep-graphs,
3225/// per CAIXA-SDLC §I) is one variant plus one arm per method and the
3226/// compiler enforces exhaustiveness on every consumer's `match` arms.
3227///
3228/// The wire byte-string [`Self::as_str`] returns is the same author-
3229/// surface tag the sibling [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3230/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry — the
3231/// [`DepError::DuplicateNome`] / [`DepError::DepIsSelf`] `list:
3232/// &'static str` payload family the substrate already emits routes
3233/// through the same source of truth (an author reading a
3234/// [`DepError::DuplicateNome`] refusal can grep their `caixa.lisp`
3235/// for the offending `:deps` / `:deps-dev` block in one edit whether
3236/// the diagnostic came from a `Caixa::validate_deps` walk or a
3237/// `Caixa::push_dep` mutation).
3238///
3239/// Same "closed-set typed-enum discriminator with canonical
3240/// projections per axis" discipline the sibling closed-set typed enums
3241/// on the caixa typed surface carry
3242/// ([`crate::aplicacao::PlacementStrategy`] cc8f749,
3243/// [`crate::aplicacao::RateLimitUnit`] 6bce03d,
3244/// [`crate::supervisor::RestartStrategy`],
3245/// [`crate::supervisor::RestartPolicy`],
3246/// [`crate::upgrade::UpgradeInstruction`], [`crate::CaixaKind`])
3247/// — extended onto the outer-`Caixa` two-list dep-graph axis, the
3248/// substrate's last unlifted closed-set-shaped `&'static str`-carrying
3249/// axis on the top-level manifest surface.
3250#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
3251pub enum DepList {
3252    /// Runtime-closure `:deps` axis — the load-bearing dep-list the
3253    /// lacre closure resolves at every build. Wire-format
3254    /// [`crate::render::DEP_AUTHOR_KEY_DEPS`].
3255    Prod,
3256    /// Dev-only-closure `:deps-dev` axis — Cargo's `[dev-dependencies]`
3257    /// table's dev-time-only visibility contract per CAIXA-SDLC §I.
3258    /// Wire-format [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`].
3259    Dev,
3260}
3261
3262impl DepList {
3263    /// Exhaustive iteration surface for every consumer that reads the
3264    /// full closed-set (the future M4 admission webhook's per-list
3265    /// summary rejection body, any future round-trip pin harness). A
3266    /// future variant addition extends this slice as a single edit and
3267    /// every consumer picks up the new entry by construction — the
3268    /// compiler-checked exhaustiveness on the sibling method `match`
3269    /// arms is the build-time guarantee that no arm forgets to grow.
3270    pub const ALL: &'static [Self] = &[Self::Prod, Self::Dev];
3271
3272    /// Canonical author-surface tag every substrate consumer that
3273    /// names the offending dep-list in a diagnostic reaches for —
3274    /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] for [`Self::Prod`] and
3275    /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] for [`Self::Dev`],
3276    /// the same `&'static str` payload the sibling
3277    /// [`DepError::DuplicateNome`] and [`DepError::DepIsSelf`] variants
3278    /// already carry. Routing every dep-list diagnostic through the
3279    /// closed-set enum's `as_str` closes the last `&'static str`-shape
3280    /// literal-carry axis on the two-list dep-graph surface — a
3281    /// future kebab-case rebrand (`":deps"` → `":packages"`) or a
3282    /// wire-format promotion (a distinct diagnostic form for the
3283    /// `Dev` arm) reaches every consumer through one edit on the
3284    /// canonical constant, not a coordinated rewrite across the
3285    /// substrate's dep-graph consumers.
3286    #[must_use]
3287    pub const fn as_str(self) -> &'static str {
3288        match self {
3289            Self::Prod => crate::render::DEP_AUTHOR_KEY_DEPS,
3290            Self::Dev => crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3291        }
3292    }
3293}
3294
3295/// Route [`std::fmt::Display`] through [`DepList::as_str`], so every
3296/// consumer that formats the axis as user-facing text (a future
3297/// `feira app graph` per-list summary, a future M4 admission-webhook
3298/// rejection body naming the offending list, this crate's own
3299/// [`DepError`] `#[error(...)]` templates when they widen to carry a
3300/// typed [`DepList`]) lands on the same author-surface tag the
3301/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3302/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry. Same
3303/// as-str-through-Display convergence discipline the sibling
3304/// [`crate::aplicacao::PlacementStrategy`],
3305/// [`crate::aplicacao::RateLimitUnit`],
3306/// [`crate::supervisor::RestartStrategy`],
3307/// [`crate::supervisor::RestartPolicy`], and [`crate::CaixaKind`]
3308/// closed-set typed enums carry.
3309impl std::fmt::Display for DepList {
3310    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3311        f.write_str(self.as_str())
3312    }
3313}
3314
3315/// Errors raised by [`Dep::validate`].
3316///
3317/// Mirrors the per-axis error families the other `:versao`-carrying
3318/// typed surfaces expose
3319/// ([`crate::AplicacaoError::MembroVersaoEmpty`] /
3320/// [`crate::AplicacaoError::MembroVersaoInvalid`],
3321/// [`crate::SupervisorError::EmptyChildVersion`] /
3322/// [`crate::SupervisorError::ChildVersaoInvalid`]) so a future top-
3323/// level `CaixaError` (M4) sums these without reshaping the diagnostic.
3324#[derive(Debug, Error, PartialEq, Eq)]
3325pub enum DepError {
3326    #[error(
3327        ":deps entry has empty :nome (every dep must name a target caixa; \
3328         omit the entry instead of carrying an empty name)"
3329    )]
3330    NomeEmpty,
3331    #[error(
3332        ":deps entry :nome {nome:?} is not a valid DNS-1123 label: {reason} \
3333         (the value flows verbatim as the target caixa's `:nome`, the rendered \
3334         `lareira-<nome>` Helm chart name segment, the `LABEL_PROGRAM` label \
3335         value, and the resolver's checkout-directory leaf — each apiserver-side \
3336         schema rejects non-DNS-1123 names at admission time; use a lowercase \
3337         RFC 1123 label like `\"caixa-teia\"` or `\"pleme-mesh\"`, 1..=63 bytes, \
3338         pattern `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)"
3339    )]
3340    NomeInvalid { nome: String, reason: String },
3341    #[error(
3342        ":deps entry {nome:?} has empty :versao (every dep must pin a semver \
3343         constraint that resolves through the lacre pipeline)"
3344    )]
3345    VersaoEmpty { nome: String },
3346    #[error(
3347        ":deps entry {nome:?} :versao {versao:?} is not a valid semver \
3348         requirement: {reason} (use Cargo-shaped forms like `\"^0.1\"`, \
3349         `\"~0.1.2\"`, `\"0.1.0\"`, or `\"*\"` — the same shape `:membros :versao` \
3350         and `:children :versao` carry; the lacre pipeline resolves all three \
3351         through the same parser)"
3352    )]
3353    VersaoInvalid {
3354        nome: String,
3355        versao: String,
3356        reason: String,
3357    },
3358    #[error(
3359        ":deps entry {nome:?} :fonte (:tipo git …) has empty :repo \
3360         (every git source must name a repo — use a `github:org/repo` \
3361         shorthand, an `https://…` URL, or an ssh-git URL; omit the \
3362         entire :fonte block to fall back to the default-host resolver \
3363         convention)"
3364    )]
3365    FonteRepoEmpty { nome: String },
3366    #[error(
3367        ":deps entry {nome:?} :fonte (:tipo git …) :repo {repo:?} has \
3368         invalid value-shape: {reason} (the value flows verbatim into the \
3369         caixa-resolver's `git clone <repo>` subprocess invocation; every \
3370         documented form carries a `:` separator and no whitespace / \
3371         control / non-ASCII bytes — use a `github:org/repo` shorthand, \
3372         an `https://host/path` / `ssh://[user@]host/path` / \
3373         `git://host/path` / `file:///path` URL, or the `git@host:path` \
3374         scp-style SSH form)"
3375    )]
3376    FonteRepoShape {
3377        nome: String,
3378        repo: String,
3379        reason: String,
3380    },
3381    #[error(
3382        ":deps entry {nome:?} :fonte (:tipo git …) has no pin set \
3383         (set exactly one of :tag, :rev, or :branch so the resolver \
3384         can pick a reproducible commit; omit the entire :fonte block \
3385         to fall back to the default-host resolver convention, which \
3386         resolves the latest tag matching :versao)"
3387    )]
3388    FontePinMissing { nome: String },
3389    #[error(
3390        ":deps entry {nome:?} :fonte (:tipo git …) has multiple pins \
3391         set ({pins}); exactly one of :tag, :rev, or :branch must be \
3392         set so the resolver's checkout target is unambiguous (the \
3393         resolver's silent precedence is :rev > :tag > :branch — if \
3394         you intended one specifically, drop the others)"
3395    )]
3396    FontePinAmbiguous { nome: String, pins: String },
3397    #[error(
3398        ":deps entry {nome:?} :fonte (:tipo git …) has empty {pin} \
3399         (a set pin must name a non-empty git ref; drop the {pin} key \
3400         entirely to fall through to another pin axis)"
3401    )]
3402    FontePinEmpty { nome: String, pin: String },
3403    #[error(
3404        ":deps entry {nome:?} :fonte (:tipo git …) {pin} {value:?} has invalid \
3405         value-shape: {reason} (the git porcelain enforces the same shape at \
3406         `git fetch` / `git checkout` time on every pin; use a leaf refname \
3407         like `\"v0.1.0\"` for `:tag` or `\"main\"` / `\"feature/foo\"` for \
3408         `:branch`, or a full 40/64 lowercase-hex commit OID for `:rev` — \
3409         drop any `refs/heads/` or `refs/tags/` prefix the caixa-resolver \
3410         prepends at clone time, and avoid abbreviated SHAs which are \
3411         ambiguous across repository history)"
3412    )]
3413    FontePinShape {
3414        nome: String,
3415        pin: String,
3416        value: String,
3417        reason: String,
3418    },
3419    #[error(
3420        ":deps entry {nome:?} :fonte (:tipo path …) has empty :caminho \
3421         (every path source must name a non-empty filesystem path; \
3422         omit the entire :fonte block to fall back to the default-host \
3423         resolver convention)"
3424    )]
3425    FonteCaminhoEmpty { nome: String },
3426    #[error(
3427        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} is \
3428         absolute (the lacre pipeline embeds the value verbatim in its \
3429         per-dep content-address `path:{caminho}` at \
3430         caixa-resolver/src/resolve.rs:189, so an absolute path makes the \
3431         BLAKE3 closure differ across machines — defeating the \
3432         reproducibility contract that's load-bearing for CSE; express \
3433         the path relative to the caixa.lisp location, e.g. \
3434         \"../caixa-teia\" for a sibling workspace dep)"
3435    )]
3436    FonteCaminhoAbsolute { nome: String, caminho: String },
3437    #[error(
3438        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3439         with `~` (the leading-tilde is a shell-expansion convention, not a \
3440         POSIX path component — `Path::is_absolute` returns false on it, so \
3441         the b94fd83 absolute-path gate doesn't catch it, but the lacre \
3442         pipeline embeds the value verbatim in its per-dep content-address \
3443         `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3444         caixa-resolver folds it through `Path::join` without `~`-expansion, \
3445         so the build looks for a literal `./{caminho}` subdirectory and \
3446         fails at resolve time far from the source caixa.lisp; even worse, a \
3447         future caixa-resolver pass that *does* expand `~` would silently \
3448         re-open the host-layout-leak the b94fd83 absolute gate closes — \
3449         Alice's `~` resolves to `/home/alice`, Bob's to `/home/bob`, two CI \
3450         runners with different `$HOME` layouts resolve to two distinct paths \
3451         for the byte-identical caixa, defeating the THEORY.md §V.2 render-\
3452         determinism contract; express the path relative to the caixa.lisp \
3453         location, e.g. \"../caixa-teia\" for a sibling workspace dep, or \
3454         spell out the full relative path explicitly if a workstation-rooted \
3455         dep is genuinely intended)"
3456    )]
3457    FonteCaminhoTildeExpansion { nome: String, caminho: String },
3458    #[error(
3459        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3460         with `$` (the leading-`$` is a shell-variable-expansion convention, \
3461         not a POSIX path component — `Path::is_absolute` returns false on it \
3462         and the a5c248e tilde gate doesn't catch it, but the lacre pipeline \
3463         embeds the value verbatim in its per-dep content-address \
3464         `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3465         caixa-resolver folds it through `Path::join` without `$`-expansion, \
3466         so the build looks for a literal `./{caminho}` subdirectory and \
3467         fails at resolve time far from the source caixa.lisp; even worse, a \
3468         future caixa-resolver pass that *does* expand `$VAR` (the canonical \
3469         shell-convention idiom that CI's `${{WORKSPACE}}` paste-idiom \
3470         invites) would silently re-open the host-layout-leak the b94fd83 \
3471         absolute gate closes — Alice's `$HOME` resolves to `/home/alice`, \
3472         Bob's to `/home/bob`, two CI runners with different `${{WORKSPACE}}` \
3473         layouts resolve to two distinct paths for the byte-identical caixa, \
3474         defeating the THEORY.md §V.2 render-determinism contract; express \
3475         the path relative to the caixa.lisp location, e.g. \"../caixa-teia\" \
3476         for a sibling workspace dep, or spell out the full relative path \
3477         explicitly if a workstation-rooted dep is genuinely intended)"
3478    )]
3479    FonteCaminhoVarExpansion { nome: String, caminho: String },
3480    #[error(
3481        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3482         with a space (the leading ASCII space `0x20` is the orthogonal \
3483         paste-from-aligned-doc footgun that silently passes \
3484         `Path::is_absolute` and every prior leading-byte arm — \
3485         `\" ../caixa-teia\"` resolves via `Path::join` to a literal \
3486         `./ ../caixa-teia` subdirectory the resolver fails to find at \
3487         resolve time with a non-self-locating `No such file or directory` \
3488         error far from the source caixa.lisp; the lacre pipeline embeds \
3489         the value verbatim in its per-dep content-address `path:{caminho}` \
3490         at caixa-resolver/src/resolve.rs:189, so byte-divergent / \
3491         semantic-identical caixa values (` ../caixa-teia` vs \
3492         `../caixa-teia`) yield two distinct BLAKE3 closures across two \
3493         workstations whose authors differ only in paste-from-aligned- \
3494         caixa.lisp-doc whitespace habits — the most insidious failure \
3495         mode the typed slot can carry (no error surfaces; the divergence \
3496         is invisible until two machines compare lacres), defeating the \
3497         THEORY.md §V.2 render-determinism contract. The canonical \
3498         paste-from-aligned-`:deps`-block footgun (every `:fonte` form in \
3499         a multi-entry `:deps` block sits at the same column — an author \
3500         selecting `\"<sp><sp><sp>../caixa-teia\"` and pasting it from \
3501         the rendered alignment into a fresh entry preserves the leading \
3502         whitespace verbatim); peer `:fonte :repo` axis already rejects \
3503         leading whitespace via `is_git_repo_url`, `:fonte :tag` / \
3504         `:fonte :branch` via `is_git_ref_name`, `:descricao` via \
3505         `is_chart_description_shape`, `:licenca` via \
3506         `is_spdx_expression_shape`. Drop the leading space; express the \
3507         path as a bare relative single-token like \"../caixa-teia\")"
3508    )]
3509    FonteCaminhoLeadingWhitespace { nome: String, caminho: String },
3510    #[error(
3511        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3512         with `-` (the canonical CLI-argument-injection footgun on the \
3513         `:caminho` axis — the lacre pipeline embeds the value verbatim in \
3514         its per-dep content-address `path:{caminho}` at \
3515         caixa-resolver/src/resolve.rs:189 and the caixa-resolver folds it \
3516         through `Path::join` looking for a literal `./{caminho}` \
3517         subdirectory. Every downstream subprocess that consumes the resolved \
3518         path — `git -C {caminho} <verb>`, `terraform -chdir={caminho}`, \
3519         `nix build --path {caminho}`, `find {caminho}`, `stat {caminho}`, \
3520         `cp -r {caminho} …`, `rm -rf {caminho}` — reinterprets a leading-`-` \
3521         value as a CLI flag rather than a positional path when the invocation \
3522         does not carry a `--` argument-list terminator between the flag block \
3523         and the path (the common case at every porcelain entry point). The \
3524         canonical footguns: `:caminho \"-rf\"` (bare short-flag paste), \
3525         `:caminho \"-C\"` (`git -C -C` config-injection paste), \
3526         `:caminho \"--upload-pack=cat /etc/passwd\"` (the canonical long-flag \
3527         CLI-arg-injection vector at every git porcelain entry point that \
3528         consumes a path or URL argument, peer with is_git_repo_url's \
3529         leading-`-` arm on the sibling `:fonte :repo` axis), \
3530         `:caminho \"--config=…\"` (`git -c foo=bar` config-override paste). \
3531         POSIX `std::path::Path` treats a leading `-` as a literal filename \
3532         byte so the resolver folds `\"-rf\"` through `Path::join` and looks \
3533         for a literal `./-rf` subdirectory that fails at resolve time with a \
3534         non-self-locating `No such file or directory` error far from the \
3535         source caixa.lisp — but on any downstream shell-out without `--` the \
3536         reinterpretation is silent and the failure mode is arbitrary-\
3537         argument-injection. Peer arms: `is_git_repo_url` (render.rs:2037) \
3538         rejects leading `-` on `:fonte :repo` for `git clone <repo>` CLI-\
3539         arg-injection; `is_git_ref_name` (render.rs:1381, 5a28454) rejects \
3540         leading `-` on `:fonte :tag` / `:branch` for `git checkout <ref>` \
3541         CLI-arg-injection; `is_dns_1123_label` rejects leading `-` on every \
3542         DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros :caixa`, \
3543         `:children :caixa`, `:deps :nome`, cluster names); \
3544         `is_cargo_feature_name` rejects leading `-` on `:caracteristicas`; \
3545         the feira `init` / `add <nome>` positional gate (868c191) rejects \
3546         leading `-` on the CLI positional itself. Express the path as a bare \
3547         relative single-token like \"../caixa-teia\" — the sibling-workspace \
3548         directory name carries no leading-hyphen semantic, and `./` / `../` \
3549         prefixes structurally partition the leading-byte set to safe values.)"
3550    )]
3551    FonteCaminhoLeadingHyphen { nome: String, caminho: String },
3552    #[error(
3553        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains \
3554         ASCII control byte 0x{byte:02x} (POSIX paths reject NUL `0x00` outright — \
3555         every `std::fs` syscall routes the path through `CString::new` which \
3556         fails with `NulError` at resolve time; the lacre pipeline embeds the \
3557         value verbatim in its per-dep content-address `path:{caminho}` at \
3558         caixa-resolver/src/resolve.rs:189 so a control byte anywhere in the \
3559         value lands in the BLAKE3 closure and breaks the THEORY.md §V.2 render-\
3560         determinism contract — the canonical paste-from-multiline-doc \
3561         (`\\n`/`\\r`), paste-from-aligned-table (`\\t`), or paste-from-binary-\
3562         blob (`0x00`-DEL) footgun every peer single-token-shaped axis \
3563         (`:fonte :repo`, `:fonte :tag`/`:branch`, the Helm chart-string axes) \
3564         already gates against. Express the path as a relative single-line ASCII \
3565         string, e.g. \"../caixa-teia\" for a sibling workspace dep)"
3566    )]
3567    FonteCaminhoControlChar {
3568        nome: String,
3569        caminho: String,
3570        byte: u8,
3571    },
3572    #[error(
3573        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains `\\` \
3574         (POSIX `std::path::Path` treats `\\` as a literal byte inside a single path \
3575         component, so `..\\caixa-teia` is one directory named literally `..\\caixa-teia` — \
3576         not the parent's sibling — and the caixa-resolver folds the value through \
3577         `Path::join` looking for a literal `./{caminho}` subdirectory that fails at \
3578         resolve time with a non-self-locating `No such file or directory` error far \
3579         from the source caixa.lisp; Windows `std::path::Path` treats `\\` as a \
3580         primary path separator equal to `/`, so byte-identical caixa.lisp values \
3581         resolve to two distinct directories across runner OSes — the lacre pipeline \
3582         embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3583         caixa-resolver/src/resolve.rs:189, defeating the THEORY.md §V.2 render-\
3584         determinism contract via the cross-host-OS-separator divergence vector. The \
3585         canonical Windows-Explorer `Copy as path` / PowerShell `Get-Location` \
3586         paste-idiom footgun; peer `:fonte :tag` / `:fonte :branch` axis already \
3587         rejects `\\` via `is_git_ref_name` for the same Windows-path-leak reason, \
3588         and `:entrada :paths` rejects `\\` via `is_gateway_api_http_path`'s eleven-\
3589         byte RFC-3986-reserved set. Express the path with `/` as the separator, e.g. \
3590         \"../caixa-teia\" for a sibling workspace dep)"
3591    )]
3592    FonteCaminhoBackslash { nome: String, caminho: String },
3593    #[error(
3594        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3595         redirection metacharacter 0x{byte:02x} `{ch}` (every interactive shell — bash / \
3596         zsh / fish / nushell — lexes `<` and `>` as input / output redirection \
3597         operators, so `:caminho \"../caixa-teia>build.log\"` is the canonical \
3598         paste-from-shell-pipeline footgun where an author copies a `command > log` \
3599         tail without trimming the redirect; POSIX `std::path::Path` treats both bytes \
3600         as literal path-component bytes, so the resolver folds the value through \
3601         `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3602         subdirectory and fails at resolve time with a non-self-locating `No such \
3603         file or directory` error far from the source caixa.lisp. The lacre pipeline \
3604         embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3605         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure \
3606         and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3607         future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3608         canonical CRLF-at-subprocess-argument / shell-metachar injection surface every \
3609         peer single-token-shaped typed slot already closes. The peer `:fonte :tag` / \
3610         `:fonte :branch` axis already rejects `<` / `>` via `is_git_ref_name`, and \
3611         `:entrada :paths` rejects them via `is_gateway_api_http_path`'s eleven-byte \
3612         RFC-3986-reserved set. Express the path as a bare relative single-token like \
3613         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3614         redirection semantic.",
3615        ch = *byte as char
3616    )]
3617    FonteCaminhoShellRedirection {
3618        nome: String,
3619        caminho: String,
3620        byte: u8,
3621    },
3622    #[error(
3623        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-pipe \
3624         metacharacter `|` (every interactive shell — bash / zsh / fish / nushell — lexes \
3625         `|` as the pipe operator that wires one command's stdout to the next command's \
3626         stdin, so `:caminho \"../caixa-teia | grep foo\"` is the canonical paste-from-\
3627         shell-history footgun where an author copies a `ls ../caixa-teia | grep` line \
3628         without trimming the pipeline tail, and `:caminho \"../foo||bar\"` is the \
3629         symmetric `cmd-a || cmd-b` short-circuit-OR paste shape; POSIX `std::path::Path` \
3630         treats `|` as a literal path-component byte, so the resolver folds the value \
3631         through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3632         subdirectory and fails at resolve time with a non-self-locating `No such file or \
3633         directory` error far from the source caixa.lisp. The lacre pipeline embeds the \
3634         value verbatim in its per-dep content-address `path:{caminho}` at caixa-resolver/\
3635         src/resolve.rs:189, so the byte lands in the BLAKE3 closure and rides into every \
3636         shell-spawned subprocess (the resolver's `git clone`, a future `feira tofu` \
3637         shell-out, a future operator-side `nix` spawn) as the canonical CRLF-at-\
3638         subprocess-argument / shell-metachar injection surface every peer single-token-\
3639         shaped typed slot already closes. The peer `:entrada :paths` axis rejects `|` \
3640         via `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3641         path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3642         workspace directory name carries no shell-pipe semantic."
3643    )]
3644    FonteCaminhoShellPipe { nome: String, caminho: String },
3645    #[error(
3646        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3647         command-separator metacharacter `;` (every interactive shell — bash / zsh / fish \
3648         / nushell — lexes `;` as the sequential-command terminator that fires the next \
3649         command regardless of the prior command's exit status, so `:caminho \
3650         \"../caixa-teia; rm -rf build\"` is the canonical paste-from-shell-one-liner \
3651         footgun where an author copies a `cd path; do-thing` chain without trimming \
3652         the cleanup tail, and `:caminho \"../foo;;bar\"` is the symmetric POSIX `case` \
3653         arm `;;` terminator paste shape; POSIX `std::path::Path` treats `;` as a \
3654         literal path-component byte, so the resolver folds the value through \
3655         `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3656         subdirectory and fails at resolve time with a non-self-locating `No such file \
3657         or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3658         the value verbatim in its per-dep content-address `path:{caminho}` at \
3659         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3660         rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3661         future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3662         canonical shell-metachar injection surface every peer single-token-shaped \
3663         typed slot already closes. The peer `:entrada :paths` axis rejects `;` via \
3664         `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3665         path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3666         workspace directory name carries no shell-command-separator semantic."
3667    )]
3668    FonteCaminhoShellSemicolon { nome: String, caminho: String },
3669    #[error(
3670        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3671         background / list-AND metacharacter `&` (every interactive shell — bash / zsh \
3672         / fish / nushell — lexes `&` two ways: single `&` as the background-task \
3673         terminator detaching the prior command and returning control immediately to \
3674         the prompt, double `&&` as the logical-AND list operator firing the next \
3675         command only if the prior succeeded; POSIX `std::path::Path` treats it as a \
3676         literal byte. The canonical paste-from-shell-prompt footgun is a `cd path & \
3677         sleep 1` background-launch one-liner or a `cd path && make install` build-\
3678         chain idiom selected whole into the `:caminho` slot — the prior `;` arm at \
3679         05c358e closed the sequential-command-separator vector, this arm closes the \
3680         orthogonal background-task / logical-AND vector on the same paste-from-shell-\
3681         prompt class. The lacre pipeline embeds the value verbatim in its per-dep \
3682         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3683         byte lands in the BLAKE3 closure and rides into every shell-spawned \
3684         subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3685         future operator-side `nix` spawn) as the canonical shell-metachar injection \
3686         surface every peer single-token-shaped typed slot already closes. The peer \
3687         `:entrada :paths` axis rejects `&` via `is_gateway_api_http_path`'s eleven-\
3688         byte RFC-3986-reserved set. Express the path as a bare relative single-token \
3689         like \"../caixa-teia\" — the sibling-workspace directory name carries no \
3690         shell-background / logical-AND semantic."
3691    )]
3692    FonteCaminhoShellBackground { nome: String, caminho: String },
3693    #[error(
3694        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3695         command-substitution metacharacter `` ` `` (every POSIX shell — sh / bash / zsh / \
3696         dash / ksh / fish / nushell — lexes the byte as the legacy command-substitution \
3697         wrapper that runs the enclosed command and substitutes its standard-output \
3698         verbatim into the surrounding word, so a backticked `whoami` expands to the \
3699         current user's name and a backticked `cat /etc/passwd` expands to the file's \
3700         contents — the canonical CWE-78 shell-command-injection vector; POSIX \
3701         `std::path::Path` treats the byte as a literal path-component byte. The canonical \
3702         paste-from-shell-prompt footgun is a `cd ../path/<backtick>whoami<backtick>` legacy substitution \
3703         one-liner or a `cd <backtick>pwd<backtick>/path` working-directory expansion idiom selected whole \
3704         into the `:caminho` slot — the prior `&` arm at e12e4f3 closed the shell-\
3705         background / logical-AND vector, this arm closes the orthogonal command-\
3706         substitution vector on the same paste-from-shell-prompt class (the modern `$()` \
3707         form is gated at leading position by the f4efe9c `FonteCaminhoVarExpansion` arm; \
3708         the legacy backtick form is the orthogonal axis). The lacre pipeline embeds the \
3709         value verbatim in its per-dep content-address `path:{caminho}` at \
3710         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3711         rides into every shell-spawned subprocess (the resolver's `git clone`, a future \
3712         `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3713         shell-metachar injection surface every peer single-token-shaped typed slot \
3714         already closes. The peer `:entrada :paths` axis rejects the byte via \
3715         `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the path \
3716         as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3717         directory name carries no shell-command-substitution semantic."
3718    )]
3719    FonteCaminhoShellCommandSubstitution { nome: String, caminho: String },
3720    #[error(
3721        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3722         glob / pathname-expansion metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — \
3723         sh / bash / zsh / dash / ksh / fish / nushell — lexes `*` and `?` as pathname-\
3724         expansion wildcards: `*` matches any sequence of characters in a path component \
3725         and `?` matches exactly one character, so a `:caminho \"../caixa-teia/*\"` is the \
3726         canonical paste-from-shell-listing footgun where an author copies a \
3727         `ls ../caixa-teia/*` listing without trimming the wildcard, and `:caminho \
3728         \"../foo?\"` is the symmetric single-char-wildcard paste shape; POSIX \
3729         `std::path::Path` treats both bytes as literal path-component bytes, so the \
3730         resolver folds the value through `Path::new(caminho).join(<file>)` looking for \
3731         a literal `./{caminho}` subdirectory and fails at resolve time with a non-self-\
3732         locating `No such file or directory` error far from the source caixa.lisp. The \
3733         lacre pipeline embeds the value verbatim in its per-dep content-address \
3734         `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the \
3735         BLAKE3 closure and rides into every shell-spawned subprocess (the resolver's \
3736         `git clone`, a future `feira tofu` shell-out, a future operator-side `nix` \
3737         spawn) as the canonical shell-metachar / glob-expansion surface every peer \
3738         single-token-shaped typed slot already closes. The peer `:entrada :paths` axis \
3739         rejects `*` and `?` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-\
3740         reserved set. Express the path as a bare relative single-token like \
3741         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-glob \
3742         / pathname-expansion semantic.",
3743        ch = *byte as char
3744    )]
3745    FonteCaminhoShellGlob {
3746        nome: String,
3747        caminho: String,
3748        byte: u8,
3749    },
3750    #[error(
3751        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3752         subshell-grouping metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / \
3753         zsh / dash / ksh / fish / nushell — lexes `(` and `)` as the subshell-grouping \
3754         operator: `(<cmd>)` runs `<cmd>` in a child shell with a fresh environment scope \
3755         (the canonical `(cd <path> && <cmd>)` shell-history one-liner scopes a `cd` to one \
3756         subshell without disturbing the parent's working directory), and `$(<cmd>)` is the \
3757         modern Bourne command-substitution shape the leading-`$` `FonteCaminhoVarExpansion` \
3758         arm closes the leading byte of — together the two arms now structurally exclude the \
3759         entire `$(<cmd>)` substitution surface from the typed `:caminho` accepted set. \
3760         POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3761         `:caminho \"../caixa-teia/$(date)/build\"` (the canonical paste-from-shell-history \
3762         modern-command-substitution footgun) or `:caminho \"../(cd foo && pwd)/caixa-teia\"` \
3763         (the symmetric subshell-grouping working-directory-probe paste idiom) silently passes \
3764         every prior arm and the resolver folds the value through `Path::new(caminho).join(\
3765         <file>)` looking for a literal subdirectory and fails at resolve time with a non-\
3766         self-locating `No such file or directory` error far from the source caixa.lisp. The \
3767         lacre pipeline embeds the value verbatim in its per-dep content-address `path:\
3768         {caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 \
3769         closure and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3770         future `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3771         shell-metachar / subshell-grouping surface every peer single-token-shaped typed slot \
3772         already closes. The peer `:fonte :repo` axis (3b99147) closes the same byte under the \
3773         same shell-subshell-grouping / RFC-3986-sub-delims banner on `is_git_repo_url`, \
3774         together with the leading-`$` `FonteCaminhoVarExpansion` arm closing the leading byte \
3775         of every `$(<cmd>)` shape. Express the path as a bare relative single-token \
3776         like \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3777         subshell-grouping semantic.",
3778        ch = *byte as char
3779    )]
3780    FonteCaminhoShellSubshellGrouping {
3781        nome: String,
3782        caminho: String,
3783        byte: u8,
3784    },
3785    #[error(
3786        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3787         brace-expansion / URI-Template placeholder metacharacter 0x{byte:02x} `{ch}` \
3788         (every POSIX-derived brace-expanding shell — bash / zsh / ksh / fish — lexes `{{` / \
3789         `}}` as the brace-expansion operator: `{{a,b,c}}` expands to the cross-product of \
3790         comma-separated members and `{{1..10}}` expands to the integer range — the \
3791         canonical `mkdir -p ../{{caixa-teia,caixa-helm,caixa-flux}}` / `cp file{{,.bak}}` \
3792         idiom every shell-history block carries; RFC 6570 reserves the matched pair for \
3793         URI Template placeholders (the canonical `https://{{host}}/{{org}}/{{repo}}` \
3794         substitution shape every OpenAPI / Swagger / Postman / GitHub Octokit client \
3795         library / Helm chart-URL fragment carries) and the Mustache / Handlebars / \
3796         Tera / Jinja2 / Go html/template doubled-brace substitution form every IaC \
3797         templating engine (Helm, Kustomize, Terraform's `${{var}}` cousin) emits. POSIX \
3798         `std::path::Path` treats the byte as a literal path-component byte, so a \
3799         `:caminho \"../{{caixa-teia,caixa-helm}}/build\"` (the canonical paste-from-\
3800         shell-history brace-expansion fan-across-siblings footgun) or `:caminho \"../{{{{org}}}}/\
3801         caixa-teia\"` (the symmetric paste-from-templated-doc URI-Template placeholder \
3802         idiom every README quick-start / OpenAPI spec / Helm chart `home:` field carries) \
3803         silently passes every prior arm and the resolver folds the value through \
3804         `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3805         resolve time with a non-self-locating `No such file or directory` error far from \
3806         the source caixa.lisp. The lacre pipeline embeds the value verbatim in its \
3807         per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
3808         so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
3809         subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3810         future operator-side `nix` spawn) as the canonical shell-metachar / brace-\
3811         expansion / URI-Template-placeholder surface every peer single-token-shaped \
3812         typed slot already closes. The peer `:fonte :repo` axis (42d8f9d) closes the \
3813         same byte pair on `is_git_repo_url` under the same RFC-3986-'delims' / \
3814         RFC-6570-URI-Template / shell-brace-expansion banner. Express the path as a \
3815         bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3816         directory name carries no shell-brace-expansion / URI-Template-placeholder \
3817         semantic; if two siblings actually need pinning, author two separate `:deps` \
3818         entries rather than one brace-expanded `:caminho` value.",
3819        ch = *byte as char
3820    )]
3821    FonteCaminhoShellBraceExpansion {
3822        nome: String,
3823        caminho: String,
3824        byte: u8,
3825    },
3826    #[error(
3827        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3828         bracket-expansion / POSIX glob-character-class / shell-`test`-builtin metacharacter \
3829         0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / nushell \
3830         — lexes the bracket pair as the glob character-class operator: `[abc]` matches one of \
3831         `a` / `b` / `c`, `[a-z]` matches any lowercase ASCII letter, `[^x]` negates — the \
3832         canonical `ls *.[ch]` C-source-file glob and `cd ../caixa-[a-z]*` lowercase-sibling \
3833         glob every shell-history block carries; the bracket pair additionally carries the \
3834         POSIX `test` / `[` builtin command (`[ -d ../caixa-teia ] && cd ...` every shell-\
3835         script conditional uses) and bash's `[[ ... ]]` extended-test grammar; beyond shell \
3836         the pair is the TOML inline-array delimiter (`features = [\"a\", \"b\"]` — the \
3837         canonical paste-from-Cargo-manifest cross-idiom-leak vector), the YAML flow-sequence \
3838         delimiter (`paths: [/a, /b]` — the canonical paste-from-values.yaml cross-idiom \
3839         leak), the JSON array delimiter, and the POSIX-ERE / PCRE bracket-expression anchor. \
3840         POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3841         `:caminho \"../caixa-[a-z]/build\"` (the canonical paste-from-shell-history glob-\
3842         character-class fan-across-siblings footgun) or `:caminho \"../[caixa-teia]/build\"` \
3843         (the symmetric paste-from-TOML-array / paste-from-YAML-flow-sequence cross-idiom \
3844         leak) silently passes every prior arm and the resolver folds the value through \
3845         `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3846         resolve time with a non-self-locating `No such file or directory` error far from \
3847         the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3848         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3849         lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3850         resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3851         `nix` spawn) as the canonical shell-metachar / glob-character-class / TOML-array \
3852         surface every peer single-token-shaped typed slot already closes. Express the path \
3853         as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3854         directory name carries no shell-bracket-expansion / glob-character-class / array-\
3855         literal semantic; if a family of sibling caixas actually needs pinning, author \
3856         separate `:deps` entries rather than one character-class-expanded `:caminho` value.",
3857        ch = *byte as char
3858    )]
3859    FonteCaminhoShellBracketExpansion {
3860        nome: String,
3861        caminho: String,
3862        byte: u8,
3863    },
3864    #[error(
3865        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3866         quote-grouping / cross-config-DSL string-literal-delimiter metacharacter \
3867         0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3868         nushell — lexes `'` as the strong string-literal delimiter (`'…'` — no expansion) \
3869         and `\"` as the weak string-literal delimiter (`\"…\"` — variable- / command-\
3870         substitution-preserving); the canonical `cd '../caixa-teia'` shell-history idiom \
3871         every path-with-embedded-whitespace paste block carries and the symmetric \
3872         `git clone \"$REPO\"` weak-quoted CI-manifest shape both leak the pair verbatim. \
3873         Beyond shell the pair is the JSON string-literal delimiter (`\"key\": \"value\"` — \
3874         the canonical paste-from-JSON-config cross-idiom-leak vector), the YAML double- \
3875         and single-quoted flow-scalar delimiter (`path: \"../caixa-teia\"` — the canonical \
3876         paste-from-values.yaml / paste-from-K8s-YAML-manifest cross-idiom leak), the TOML \
3877         basic and literal string delimiter (`path = \"../caixa-teia\"` — the canonical \
3878         paste-from-Cargo-manifest cross-idiom leak), the tatara-lisp string-literal \
3879         delimiter itself (`(:caminho \"../caixa-teia\")` — the canonical \"I copied the \
3880         entire `:caminho \"...\"` slot rather than just the string body\" author-surface \
3881         footgun), and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which excludes \
3882         both bytes from the `pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"` \
3883         production. POSIX `std::path::Path` treats the byte as a literal path-component \
3884         byte, so a `:caminho \"'../caixa-teia'\"` (the canonical paste-from-shell-history \
3885         strong-quoted sibling-workspace path footgun) or `:caminho \"\\\"../caixa-teia\\\"\"` \
3886         (the symmetric weak-quoted paste-from-JSON / paste-from-YAML flow-scalar / paste-\
3887         from-TOML basic-string / paste-from-tatara-lisp string-literal cross-idiom-leak \
3888         shape) silently passes every prior arm and the resolver folds the value through \
3889         `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3890         resolve time with a non-self-locating `No such file or directory` error far from \
3891         the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3892         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3893         lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3894         resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3895         `nix` spawn) as the canonical shell-metachar / string-literal-delimiter surface \
3896         every peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
3897         axis closes both bytes under the same shell-quote-grouping / RFC-3986-sub-delims \
3898         banner (e7a109f `'` shell-single-quote + 4267d8b `\"` shell-double-quote on \
3899         `is_git_repo_url`). Express the path as a bare relative single-token like \
3900         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-quote-\
3901         grouping / string-literal-delimiter semantic; strip the outer quote pair from the \
3902         paste (the tatara-lisp `:caminho \"...\"` slot already carries the string-literal \
3903         quoting on the outer syntactic layer, so an inner quote pair would nest and \
3904         desugar to a broken layer).",
3905        ch = *byte as char
3906    )]
3907    FonteCaminhoShellQuoteGrouping {
3908        nome: String,
3909        caminho: String,
3910        byte: u8,
3911    },
3912    #[error(
3913        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3914         comment / URL-fragment-identifier / YAML-comment cross-config-DSL metacharacter \
3915         0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3916         nushell — lexes an unquoted `#` at the head of a word or after unquoted \
3917         whitespace as the comment-lead per POSIX.1-2017 §2.3 Token Recognition step 6, \
3918         discarding the byte and everything after it to the end of the physical line \
3919         before command parsing (`cd ../caixa-teia  # legacy sibling` — the canonical \
3920         paste-from-shell-history-with-trailing-annotation shape every operator-notebook \
3921         and CI-manifest carries); YAML 1.2 §6.6 makes `#` the comment-lead at any \
3922         position preceded by whitespace or at line-start (`path: ../caixa-teia  # pin` \
3923         — the canonical paste-from-values.yaml / paste-from-K8s-manifest cross-idiom-\
3924         leak); RFC 3986 §3.5 reserves `#` as the URL fragment-identifier delimiter (the \
3925         canonical paste-from-browser-address-bar `github.com/foo/bar#readme` / \
3926         `github.com/foo/bar#L42` permalink shape, and the symmetric Nix-flake-ref \
3927         cross-idiom leak `github:foo/bar#packageName` where `#` selects a flake \
3928         output); the same cross-config-DSL surface extends to HCL / Terraform / Nix \
3929         flake attributes / dotenv `.env` / gitconfig / .gitignore / ini / TOML where \
3930         `#` is likewise the comment-lead. POSIX `std::path::Path` treats the byte as a \
3931         literal path-component byte, so a `:caminho \"../caixa-teia # legacy sibling\"` \
3932         (the canonical paste-from-shell-history-with-trailing-annotation footgun), \
3933         `:caminho \"../caixa-teia  # pin\"` (the symmetric YAML flow-scalar paste-with-\
3934         trailing-comment shape), or `:caminho \"../caixa-teia#readme\"` (the URL \
3935         fragment paste-from-browser-address-bar shape) silently passes every prior arm \
3936         and the resolver folds the value through `Path::new(caminho).join(<file>)` \
3937         looking for a literal subdirectory named `../caixa-teia # legacy sibling` and \
3938         fails at resolve time with a non-self-locating `No such file or directory` \
3939         error far from the source caixa.lisp — while every downstream shell / YAML / \
3940         URL parser silently truncates the value at the `#` byte to `../caixa-teia`, so \
3941         a `feira tofu` shell-out and a `nix flake check` on an emitted YAML `path:` \
3942         scalar disagree with the resolver on which directory the value names. The \
3943         lacre pipeline embeds the value verbatim in its per-dep content-address \
3944         `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in \
3945         the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3946         resolver's `git clone`, a future `feira tofu` shell-out, a future operator-\
3947         side `nix` spawn) as the canonical shell-metachar / comment-lead / URL-\
3948         fragment-delimiter surface every peer single-token-shaped typed slot already \
3949         closes. The peer `:fonte :repo` axis closes the byte under the same URL-\
3950         fragment-identifier banner (a68f818 `#` on `is_git_repo_url`). Express the \
3951         path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3952         workspace directory name carries no shell-comment / URL-fragment / YAML-\
3953         comment semantic; move any trailing annotation to a tatara-lisp `;`-comment \
3954         on the surrounding form (`;; legacy sibling` above the `(:caminho ...)` slot) \
3955         and drop any `#fragment` tail entirely (fragment identifiers select \
3956         renderings, not directories, and `:caminho` names a directory).",
3957        ch = *byte as char
3958    )]
3959    FonteCaminhoShellComment {
3960        nome: String,
3961        caminho: String,
3962        byte: u8,
3963    },
3964    #[error(
3965        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains URL-\
3966         percent-encoding-escape / printf-format-specifier / bash-job-control-specifier \
3967         / YAML-directive-lead metacharacter 0x{byte:02x} `{ch}` (RFC 3986 §2.1 reserves \
3968         `%` as the URL percent-encoding-escape — `%HH` is the mandatory encoding \
3969         mechanism for every byte outside the `unreserved` alphanumeric / `-` / `.` / \
3970         `_` / `~` set, and `%` itself must be percent-encoded as `%25` to appear \
3971         literally inside a URL value. The canonical paste-from-browser-address-bar \
3972         percent-encoded-space footgun (an author copies `../caixa%20teia` out of a URL-\
3973         encoded README hyperlink / browser address bar / percent-encoded permalink \
3974         expecting `%20` to decode to a literal space at the filesystem layer) locks two \
3975         distinct BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`) for \
3976         what the author intended as the byte-identical sibling-workspace dep. POSIX \
3977         `std::path::Path` treats the byte as a literal path-component byte, so \
3978         `Path::join` looks for a literal `./{caminho}` subdirectory and fails at \
3979         resolve time with a non-self-locating `No such file or directory` error far \
3980         from the source caixa.lisp — while every downstream URL parser / shell printf \
3981         builtin / YAML directive parser silently reinterprets the byte to a different \
3982         value than the resolver's `Path::join` sees. Beyond the URL-encoding hazard, \
3983         `%` is the C / POSIX printf format-directive lead-in (`%s`, `%d`, `%02x` — \
3984         wired into every POSIX shell's `printf` builtin, the canonical CWE-134 format-\
3985         string-injection vector); the bash / zsh / ksh job-control-specifier lead-in \
3986         (`%1` names \"job 1\", `%%` names \"the current job\", `%foo` names \"the most \
3987         recent job whose command started with `foo`\" — a future `kill %1` invocation \
3988         silently redirects the signal to a wrong target); the YAML 1.2 §6.8.1 \
3989         directive lead-in (`%YAML 1.2` / `%TAG` — the paste-from-top-of-doc YAML \
3990         directive block cross-idiom leak); and the Windows-shell env-var-reference \
3991         lead-in (`%PATH%` — the paste-from-`.bat` / paste-from-PowerShell-`%env:PATH%` \
3992         cross-idiom leak). The lacre pipeline embeds the value verbatim in its per-dep \
3993         content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3994         byte lands in the BLAKE3 closure and rides into every shell-spawned subprocess \
3995         (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
3996         operator-side `nix` spawn) as the canonical URL-percent-encoding-escape / \
3997         printf-format-specifier / job-control-specifier surface every peer single-\
3998         token-shaped typed slot already closes. The peer `:fonte :repo` axis closes \
3999         the byte under the same URL-percent-encoding-escape banner (a323db8 `%` on \
4000         `is_git_repo_url`). Express the path as a bare relative single-token like \
4001         \"../caixa-teia\" — the sibling-workspace directory name carries no URL-\
4002         percent-encoding-escape / format-specifier / job-control semantic; substitute \
4003         any `%20` percent-encoded-space with a literal space then reject the whole \
4004         value at the leading-whitespace / embedded-`?` arm on the same axis (a caixa \
4005         directory name never carries an embedded space in practice); drop any \
4006         `%2F`-encoded path separator in favor of a literal `/`; and drop any leading \
4007         `%YAML` / `%PATH%` cross-idiom-leak prefix entirely.",
4008        ch = *byte as char
4009    )]
4010    FonteCaminhoUrlPercentEncoding {
4011        nome: String,
4012        caminho: String,
4013        byte: u8,
4014    },
4015    #[error(
4016        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4017         variable-expansion / command-substitution / arithmetic-expansion / cross-config-\
4018         DSL-interpolation metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / \
4019         bash / zsh / dash / ksh / busybox ash / fish / nushell — lexes `$` per \
4020         POSIX.1-2017 §2.6 as the variable-expansion `$<name>` / braced-form `${{<name>}}` \
4021         / command-substitution `$(<cmd>)` / arithmetic-expansion `$((<expr>))` operator; \
4022         Nix uses `${{var}}` as the string-interpolation lead, Make uses `$(var)` / `$@` \
4023         / `$<` for variables and automatic-variables, JavaScript / TypeScript template \
4024         literals use `${{expr}}` for interpolation, envsubst / Kubernetes / OpenShift \
4025         templates use `${{VAR}}` for env-var-reference, PHP uses `$_GET` / `$_ENV` for \
4026         superglobals, Perl uses `$foo` for scalars, SASS / SCSS uses `$primary-color` \
4027         for variables, and PostgreSQL / SQLite use `$1` / `$2` for bind parameters — \
4028         the byte is a first-class parser byte in nearly every config / templating / \
4029         build-system DSL the substrate's paste-idiom surface routinely crosses. POSIX \
4030         `std::path::Path` treats the byte as a literal path-component byte, so the \
4031         canonical paste-from-shell-one-liner `:caminho \"../foo$HOME/bar\"` / paste-\
4032         from-CI-manifest `:caminho \"../foo${{WORKSPACE}}/bar\"` / paste-from-shell-\
4033         prompt `:caminho \"../foo$(whoami)/bar\"` footguns silently pass every prior \
4034         cascade arm (`$` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / \
4035         `?` / `(` / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%`) and route \
4036         through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4037         subdirectory that fails at resolve time with a non-self-locating `No such file \
4038         or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4039         the value verbatim in its per-dep content-address `path:{caminho}` at \
4040         caixa-resolver/src/resolve.rs:189, so byte-identical caixa.lisp values differing \
4041         only in whether the author substituted `$HOME` / `${{WORKSPACE}}` at author \
4042         time lock to two distinct BLAKE3 closures across two workstations whose \
4043         downstream envsubst / Nix / Make / K8s-template layers differ in `$VAR` \
4044         recognition — defeating the THEORY.md §V.2 render-determinism contract on the \
4045         same axis every prior `:caminho` arm protects. Beyond the determinism vector, \
4046         `$` at any position in a value flowing verbatim into a shell-spawned subprocess \
4047         is the canonical CWE-78 shell-command-injection surface every peer single-\
4048         token-shaped typed slot already closes: peer `:fonte :repo` axis rejects `$` \
4049         under the shell-variable-expansion / URL-sub-delim banner via `is_git_repo_url` \
4050         (b9d187c), peer `:fonte :tag` / `:fonte :branch` axes reject `$` as part of \
4051         `is_git_ref_name`'s printable-ASCII-restricted grammar (`git check-ref-format` \
4052         rejects the byte outright), and peer `:entrada :paths` axis rejects `$` via \
4053         `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. The leading-`$` \
4054         position on the same axis routes through `FonteCaminhoVarExpansion` at the \
4055         f4efe9c leading-byte arm; this arm closes the last positional gap on the byte \
4056         so every position — leading and embedded — is structurally rejected. Substitute \
4057         the `$VAR` / `${{VAR}}` / `$(cmd)` template with the literal value at author \
4058         time, or express the path as a bare relative single-token like \
4059         \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
4060         variable-expansion / command-substitution / arithmetic-expansion semantic.",
4061        ch = *byte as char
4062    )]
4063    FonteCaminhoShellVariableExpansion {
4064        nome: String,
4065        caminho: String,
4066        byte: u8,
4067    },
4068    #[error(
4069        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4070         history-expansion / RFC-3986-sub-delims / bang-operator metacharacter 0x{byte:02x} \
4071         `{ch}` (every interactive POSIX shell with history enabled — bash / ksh / zsh's \
4072         `bashcompat` / csh / tcsh — lexes `!` as the history-expansion prefix per bash \
4073         reference §9.3: `!command` re-runs the most recent history entry beginning with \
4074         `command`, `!!` re-runs the prior command verbatim, `!$` substitutes the last \
4075         word of the prior command, `!:N` substitutes the Nth word of the prior command, \
4076         and the substitution fires at every history-expansion-enabled shell context — \
4077         `set -o histexpand` is bash's default for interactive sessions and the layer \
4078         every `feira tofu` / `git clone` / `nix flake check` subprocess-argument \
4079         invocation crosses when spawned under `bash -i`. Beyond shell history, RFC 3986 \
4080         §2.2 lists `!` in the `sub-delims` set (the URL grammar admits the byte inside \
4081         a path segment, but every WHATWG-conformant special-scheme URL parser percent-\
4082         encodes it inside a query component via the 'special-query percent-encode set' \
4083         the peer `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte is \
4084         also the C / C++ / Rust / JavaScript / Python bang-operator (logical-negation \
4085         prefix — the paste-from-source-code idiom where an author copies \
4086         `!path.exists()` out of a Rust snippet and the trailing punctuation crosses \
4087         the string-literal boundary); the canonical English-typography emphasis / \
4088         exclamation mark (the paste-from-prose enthusiasm-form idiom where an author \
4089         writes `:caminho \"../caixa-teia!\"` expecting the substrate to coerce it to a \
4090         kebab-case slug); and the Nix flake-ref attribute-selection operator surface. \
4091         POSIX `std::path::Path` treats `!` as a literal path-component byte, so the \
4092         canonical paste-from-shell-history footgun `:caminho \"../caixa-teia!sudo\"` \
4093         (an author copies a `cd ../caixa-teia && !sudo make install` one-liner from a \
4094         quick-start README and the trailing `!sudo` rides in verbatim as a history-\
4095         expansion reference), the symmetric `:caminho \"../foo!!/bar\"` (the `!!` \
4096         repeat-prior-command paste idiom), the English-typography `:caminho \
4097         \"../caixa-teia!\"` (paste-from-prose enthusiasm-form), and the last-word-\
4098         substitution `:caminho \"../foo!$\"` shape silently pass every prior cascade \
4099         arm (`!` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` \
4100         / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$`) and route \
4101         through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4102         subdirectory that fails at resolve time with a non-self-locating `No such file \
4103         or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4104         the value verbatim in its per-dep content-address `path:{caminho}` at \
4105         caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
4106         rides into every shell-spawned subprocess (the resolver's `git clone`, a \
4107         future `feira tofu` shell-out, a future operator-side `nix flake check` spawn) \
4108         as the canonical shell-history-expansion / RFC-3986-sub-delims surface every \
4109         peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4110         axis closes the byte under the same shell-history-expansion / RFC-3986-sub-\
4111         delims banner (7d53c68 `!` on `is_git_repo_url`). Express the path as a bare \
4112         relative single-token like \"../caixa-teia\" — the sibling-workspace directory \
4113         name carries no shell-history-expansion / bang-operator semantic; drop any \
4114         `!sudo` / `!!` / `!$` history-expansion trailing paste-from-shell-history \
4115         idiom; and drop any trailing English-typography exclamation mark that pasted \
4116         from prose.",
4117        ch = *byte as char
4118    )]
4119    FonteCaminhoShellHistoryExpansion {
4120        nome: String,
4121        caminho: String,
4122        byte: u8,
4123    },
4124    #[error(
4125        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4126         history-substitution / RFC-3986-'unwise' / regex-negation metacharacter 0x{byte:02x} \
4127         `{ch}` (POSIX bash's `set -o histexpand` mode — the default for every interactive \
4128         session and every `bash -i` subprocess-argument context `feira tofu` / `git clone` / \
4129         `nix flake check` cross — lexes `^old^new^` per bash reference §9.3 as the 'quick \
4130         substitution' history operator that rewrites the prior command's `old` string to \
4131         `new` and re-executes it verbatim, the canonical typo-correction one-liner idiom \
4132         (`git clone <bad-url>` → `^bad^good` typo-fix-and-rerun the paste-from-shell-\
4133         history author trims only the leading `git clone` prefix from). RFC 3986 §2 lists \
4134         `^` in the 'unwise' set every URL parser is required to percent-encode-or-refuse at \
4135         the wire boundary, and the WHATWG URL spec's 'fragment percent-encode set' maps \
4136         `^` → `%5E` at the query / fragment component transition, so `Path::join` on the \
4137         literal value diverges from every downstream `feira tofu` curl-invocation / \
4138         artifact-registry-fetch that percent-encodes the byte before the wire. `^` is also \
4139         the regex character-class negation prefix (`[^abc]`), the bitwise XOR operator in \
4140         C / C++ / Rust / Python / JavaScript / Nix / Go, the Windows `cmd.exe` escape \
4141         metacharacter, and the LaTeX / Markdown / BibTeX superscript operator. POSIX \
4142         `std::path::Path` treats `^` as a literal path-component byte, so \
4143         `:caminho \"../foo^bar/baz\"` (embedded quick-substitution), `:caminho \
4144         \"../foo^\"` (trailing history-substitution-open shape), or `:caminho \"../x^y\"` \
4145         (XOR-expression paste-from-source) silently pass every prior cascade arm (`^` \
4146         isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` / `)` / `{{` \
4147         / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$` / `!`) and route through \
4148         `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` subdirectory \
4149         that fails at resolve time with a non-self-locating `No such file or directory` \
4150         error far from the source caixa.lisp. The lacre pipeline embeds the value verbatim \
4151         in its per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
4152         so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
4153         subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4154         operator-side `nix flake check` spawn) as the canonical shell-history-substitution \
4155         / RFC-3986-unwise surface every peer single-token-shaped typed slot already closes. \
4156         The peer `:fonte :repo` axis closes the byte under the same shell-history-\
4157         substitution / RFC-3986-unwise banner (49e142f `^` on `is_git_repo_url`). Together \
4158         with the immediate-predecessor `!` arm (6a04767) this arm closes the full `set -o \
4159         histexpand` operator surface on the `:caminho` axis — the `!command` / `!!` / `!$` \
4160         prefix form via `!`, the `^old^new^` quick-substitution form via `^`. Express the \
4161         path as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
4162         directory name carries no shell-history-substitution / regex-negation / XOR-operator \
4163         semantic; drop any `^old^new` history-substitution paste-from-shell-history idiom; \
4164         drop any trailing `^` history-substitution-open fragment.",
4165        ch = *byte as char
4166    )]
4167    FonteCaminhoShellHistorySubstitution {
4168        nome: String,
4169        caminho: String,
4170        byte: u8,
4171    },
4172    #[error(
4173        ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} has a trailing \
4174         `/` (the resolver's `Path::join` resolves `\"../caixa-teia\"` and \
4175         `\"../caixa-teia/\"` to the same directory, but the lacre pipeline embeds the \
4176         value verbatim in its per-dep content-address `path:{caminho}` at \
4177         caixa-resolver/src/resolve.rs:189, so two authors whose only difference is \
4178         shell tab-completion emit byte-divergent BLAKE3 closures for the same caixa — \
4179         defeating the THEORY.md §V.2 render-determinism contract via the trailing-\
4180         separator vector (the canonical paste-from-shell-tab-completion + paste-from-\
4181         `pwd`-with-`/`-suffix footgun, and the canonical Cargo-style `path = \
4182         \"../caixa-teia/\"` paste-from-Cargo-manifest cross-idiom leak). Drop the \
4183         trailing `/`; every `:caminho` value names a sibling-workspace directory \
4184         already, so the trailing separator carries no information. Use \
4185         `\"../caixa-teia\"` rather than `\"../caixa-teia/\"`)"
4186    )]
4187    FonteCaminhoTrailingSlash { nome: String, caminho: String },
4188    #[error(
4189        "{list} carries duplicate entry :nome {nome:?} — every dep list keys its \
4190         entries by caixa name (Cargo's [dependencies] / [dev-dependencies] tables \
4191         apply the same set-not-multiset discipline; one package per table), and \
4192         two entries naming the same caixa carry two version constraints / source \
4193         pins / feature sets for one identity. The caixa-resolver's lacre pipeline \
4194         consumes the list as a `HashMap`-keyed-by-`:nome` lookup: the second entry \
4195         silently overwrites the first at the resolver-side `concrete_versao` step, \
4196         and the dropped entry's pin / features never reach the closure — far from \
4197         the source caixa.lisp, with no field naming which `:deps` entry was the \
4198         silent loser. If two version constraints are genuinely needed (the rare \
4199         multi-version closure case the lacre pipeline doesn't yet support), the \
4200         author surface is two distinct caixa names (e.g. a `caixa-teia-v01` / \
4201         `caixa-teia-v02` aliased pair); within one list, one entry per caixa name."
4202    )]
4203    DuplicateNome { nome: String, list: &'static str },
4204    #[error(
4205        ":deps entry {nome:?} has empty :caracteristicas entry — every feature flag must \
4206         name a non-empty identifier on the target caixa (Cargo's [dependencies.<dep>.features] \
4207         applies the same per-entry non-empty discipline). An empty feature flag reaches the \
4208         caixa-resolver's lacre pipeline as a no-op feature enable, silently dropping the \
4209         author's intent far from the source caixa.lisp; drop the empty entry, or replace it \
4210         with the canonical kebab-case feature name the target caixa declares."
4211    )]
4212    CaracteristicaEmpty { nome: String },
4213    #[error(
4214        ":deps entry {nome:?} :caracteristicas entry {caracteristica:?} is not a valid Cargo \
4215         feature name: {reason} (the value flows verbatim into Cargo's \
4216         [dependencies.<dep>.features] list and Cargo's `restricted_names::validate_feature_name` \
4217         parser enforces the same shape at `cargo metadata` time; use a single-token \
4218         identifier like `\"http\"`, `\"derive\"`, or `\"runtime-tokio\"` — kebab-case ASCII \
4219         alphanumeric with `-`, `_`, `+`, or `.` as continuation characters, starting with \
4220         an ASCII alphanumeric or `_`)"
4221    )]
4222    CaracteristicaInvalid {
4223        nome: String,
4224        caracteristica: String,
4225        reason: String,
4226    },
4227    #[error(
4228        ":deps entry {nome:?} :caracteristicas carries duplicate feature {caracteristica:?} — \
4229         every feature-flag list keys its entries by name (Cargo's \
4230         [dependencies.<dep>.features] applies the same set-not-multiset discipline; one entry \
4231         per feature per dep), and two entries naming the same feature are a redundant \
4232         set-membership declaration for one identity (the feature-toggle slot is set-shaped; \
4233         enabling a feature twice has no additional semantic). The caixa-resolver's lacre \
4234         pipeline consumes the list as a set-shaped feature toggle — the resolver enables the \
4235         feature once regardless of declaration count, so the duplicate's pin / position never \
4236         reaches the closure with no field naming the silent loser. One entry per feature per \
4237         dep; if two distinct features are intended, name each verbatim."
4238    )]
4239    CaracteristicaDuplicate {
4240        nome: String,
4241        caracteristica: String,
4242    },
4243    #[error(
4244        "{list} entry :nome {nome:?} names the caixa itself — a caixa cannot depend \
4245         on itself (the lacre closure's dep-graph traversal is rooted at the caixa's \
4246         :nome, and a self-dep would be a one-node cycle the caixa-resolver either \
4247         rejects mid-traversal far from the source caixa.lisp or recurses on until \
4248         it exhausts its stack). Every :nome is globally-unique substrate identity, \
4249         so a :deps / :deps-dev entry whose :nome equals the parent caixa's :nome \
4250         *is* the parent itself, not a coincidentally-named peer. Drop the \
4251         self-referential dep entry — to reference code from this caixa, use \
4252         :bibliotecas / :exe / :servicos (the substrate-blessed shape for \
4253         referencing the caixa's own code surface) instead."
4254    )]
4255    DepIsSelf { nome: String, list: &'static str },
4256}
4257
4258#[allow(clippy::trivially_copy_pass_by_ref)]
4259fn is_false(b: &bool) -> bool {
4260    !*b
4261}
4262
4263#[cfg(test)]
4264mod tests {
4265    use super::*;
4266
4267    #[test]
4268    fn registry_dep_is_minimal() {
4269        let d = Dep::simple("caixa-teia", "^0.1");
4270        assert_eq!(d.nome, "caixa-teia");
4271        assert_eq!(d.versao, "^0.1");
4272        assert!(d.fonte.is_none());
4273        assert!(!d.opcional());
4274        assert!(d.caracteristicas().is_empty());
4275    }
4276
4277    #[test]
4278    fn git_dep_carries_tag() {
4279        let d = Dep::git("t", "*", "github:o/r", "v1");
4280        match d.fonte {
4281            Some(DepSource::Git {
4282                ref repo, ref tag, ..
4283            }) => {
4284                assert_eq!(repo, "github:o/r");
4285                assert_eq!(tag.as_deref(), Some("v1"));
4286            }
4287            _ => panic!("expected Git source"),
4288        }
4289    }
4290
4291    #[test]
4292    fn validate_accepts_simple_dep() {
4293        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
4294    }
4295
4296    #[test]
4297    fn validate_rejects_empty_nome() {
4298        // The fail-before-pass-after pin for `:nome ""`: the empty-name
4299        // arm fires first so the per-entry parse-side diagnostic doesn't
4300        // emit a useless `nome: ""` reference.
4301        let mut d = Dep::simple("placeholder", "^0.1");
4302        d.nome = String::new();
4303        assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4304    }
4305
4306    #[test]
4307    fn validate_rejects_empty_versao() {
4308        // `parse_requirement("")` returns `Ok(VersionReq::STAR)` (the
4309        // semver crate accepts the empty string as a wildcard match),
4310        // so the empty-`:versao` arm is structurally necessary even
4311        // with the parse arm in place — mirrors `MembroVersaoEmpty` /
4312        // `EmptyChildVersion` ordering on the other two `:versao` axes.
4313        let mut d = Dep::simple("caixa-teia", "ignored");
4314        d.versao = String::new();
4315        let err = d.validate().unwrap_err();
4316        assert!(
4317            matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4318            "got {err:?}"
4319        );
4320    }
4321
4322    // ── value-shape: DNS-1123 label on :deps :nome ────────────────────────
4323
4324    #[test]
4325    fn validate_rejects_nome_with_uppercase() {
4326        // The fail-before-pass-after pin: a non-empty but uppercase
4327        // `:nome` silently passed `validate()` on every pre-gate
4328        // codebase because the prior shape only refused the empty
4329        // string. The DNS-1123 violation surfaced far downstream at
4330        // lacre-resolve time when the *target* caixa's `:nome` failed
4331        // its own gate — far from the `:deps` entry, with a diagnostic
4332        // naming the target rather than the dep entry that referenced
4333        // it. Same fail-before-pass-after fixture pinned for
4334        // `:membros :caixa` (3f9d7a0), `:children :caixa` (31bfa43),
4335        // and Caixa `:nome` (6c992f8).
4336        let d = Dep::simple("Caixa-Teia", "^0.1");
4337        let err = d.validate().unwrap_err();
4338        assert!(
4339            matches!(
4340                err,
4341                DepError::NomeInvalid { ref nome, ref reason }
4342                    if nome == "Caixa-Teia" && reason.contains("uppercase")
4343            ),
4344            "got {err:?}"
4345        );
4346    }
4347
4348    #[test]
4349    fn validate_rejects_nome_with_underscore() {
4350        // RFC 1123 allows `[a-z0-9-]` only; underscore is the canonical
4351        // "I'm thinking of Go module names / Python identifiers" leak.
4352        // Same fixture pinned for the peer caixa-identifier axes.
4353        let d = Dep::simple("caixa_teia", "^0.1");
4354        let err = d.validate().unwrap_err();
4355        assert!(
4356            matches!(
4357                err,
4358                DepError::NomeInvalid { ref nome, ref reason }
4359                    if nome == "caixa_teia" && reason.contains('_')
4360            ),
4361            "got {err:?}"
4362        );
4363    }
4364
4365    #[test]
4366    fn validate_rejects_nome_with_dot() {
4367        // A `:deps :nome` is a single DNS-1123 *label*, not a
4368        // subdomain — dots are rejected. The `"caixa.teia"` shape is
4369        // the canonical "I confused the dep name with the FQDN /
4370        // namespace" footgun, distinct from the legitimate
4371        // `:fonte :repo "github:org/caixa-teia"` axis.
4372        let d = Dep::simple("caixa.teia", "^0.1");
4373        let err = d.validate().unwrap_err();
4374        assert!(
4375            matches!(
4376                err,
4377                DepError::NomeInvalid { ref nome, ref reason }
4378                    if nome == "caixa.teia" && reason.contains('.')
4379            ),
4380            "got {err:?}"
4381        );
4382    }
4383
4384    #[test]
4385    fn validate_rejects_nome_with_leading_hyphen() {
4386        // RFC 1123 requires alphanumeric at both label boundaries.
4387        // Pinned in parity with the peer DNS-1123 fixtures.
4388        let d = Dep::simple("-caixa-teia", "^0.1");
4389        let err = d.validate().unwrap_err();
4390        assert!(
4391            matches!(
4392                err,
4393                DepError::NomeInvalid { ref nome, ref reason }
4394                    if nome == "-caixa-teia" && reason.contains("alphanumeric")
4395            ),
4396            "got {err:?}"
4397        );
4398    }
4399
4400    #[test]
4401    fn validate_rejects_nome_with_trailing_hyphen() {
4402        let d = Dep::simple("caixa-teia-", "^0.1");
4403        let err = d.validate().unwrap_err();
4404        assert!(
4405            matches!(
4406                err,
4407                DepError::NomeInvalid { ref nome, ref reason }
4408                    if nome == "caixa-teia-" && reason.contains("alphanumeric")
4409            ),
4410            "got {err:?}"
4411        );
4412    }
4413
4414    #[test]
4415    fn validate_rejects_nome_with_slash() {
4416        // The canonical "I copied the GitHub repo path into `:nome`
4417        // instead of `:fonte :repo`" typo. A `/` in the name leaks the
4418        // lacre-side `:repositorio` shape (`pleme-io/caixa-teia`) into
4419        // the local-name slot. Same fixture pinned for `:membros
4420        // :caixa` (3f9d7a0).
4421        let d = Dep::simple("pleme-io/caixa-teia", "^0.1");
4422        let err = d.validate().unwrap_err();
4423        assert!(
4424            matches!(
4425                err,
4426                DepError::NomeInvalid { ref nome, ref reason }
4427                    if nome == "pleme-io/caixa-teia" && reason.contains('/')
4428            ),
4429            "got {err:?}"
4430        );
4431    }
4432
4433    #[test]
4434    fn validate_rejects_nome_too_long() {
4435        // 64-byte label — one over the RFC 1035 / RFC 1123 label cap.
4436        // Built from a valid character set so the length-bound
4437        // diagnostic surfaces before any per-character check (the
4438        // order pin parallel to the per-character predicates inside
4439        // [`crate::render::is_dns_1123_label`]).
4440        let long = "a".repeat(64);
4441        let d = Dep::simple(&long, "^0.1");
4442        let err = d.validate().unwrap_err();
4443        assert!(
4444            matches!(
4445                err,
4446                DepError::NomeInvalid { ref nome, ref reason }
4447                    if nome.len() == 64 && reason.contains("max length of 63")
4448            ),
4449            "got {err:?}"
4450        );
4451    }
4452
4453    #[test]
4454    fn validate_accepts_canonical_nome_labels() {
4455        // Positive-control sweep — every form the K8s apiserver
4456        // accepts as a DNS-1123 label must round-trip through
4457        // validate. Covers a hyphen-bearing label, a numeric-suffix
4458        // label, a leading-digit label, a single-character label, and
4459        // a 63-byte (exactly the cap) label — the same fixture set
4460        // the peer `:membros :caixa` / `:children :caixa` positive
4461        // controls pin.
4462        for nome in [
4463            "caixa-teia",
4464            "caixa-resolver2",
4465            "2nd-tier-cache",
4466            "x",
4467            "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0",
4468        ] {
4469            Dep::simple(nome, "^0.1")
4470                .validate()
4471                .unwrap_or_else(|e| panic!("canonical label {nome:?} must validate, got {e:?}"));
4472        }
4473    }
4474
4475    #[test]
4476    fn nome_empty_takes_precedence_over_nome_invalid() {
4477        // Ordering pin: `NomeEmpty` is the more self-locating
4478        // diagnostic on `""` and must lead — `is_dns_1123_label` is
4479        // only reached after the empty-check fires at the call site.
4480        // Mirrors `membro_caixa_empty_takes_precedence_over_invalid`
4481        // (3f9d7a0) on the peer caixa-identifier axis.
4482        let mut d = Dep::simple("placeholder", "^0.1");
4483        d.nome = String::new();
4484        assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4485    }
4486
4487    #[test]
4488    fn nome_invalid_fires_before_versao_empty() {
4489        // Ordering pin: a malformed `:nome` fires before any `:versao`
4490        // axis check on the *same* entry — the per-entry shape gates
4491        // run top-to-bottom (nome empty → nome shape → versao empty →
4492        // versao parse → fonte shape), so a one-entry caixa.lisp with
4493        // both wrong sees the name-side diagnostic first (the name is
4494        // the self-locating axis — without a valid name, the parse
4495        // diagnostic can't quote `:nome "<bad>"`). Same ordering
4496        // discipline as `membro_caixa_invalid_fires_before_versao_check`
4497        // (3f9d7a0).
4498        let mut d = Dep::simple("Caixa-Teia", "^0.1");
4499        d.versao = String::new();
4500        let err = d.validate().unwrap_err();
4501        assert!(
4502            matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4503            "got {err:?}"
4504        );
4505    }
4506
4507    #[test]
4508    fn nome_invalid_fires_before_versao_invalid() {
4509        // Ordering pin: a malformed `:nome` fires before the `:versao`
4510        // parse-side check on the *same* entry. Pin separately from
4511        // the empty-versao ordering so a future re-ordering surfaces
4512        // here, parallel to the b0c8389 / c4213a4 trajectory.
4513        let d = Dep::simple("Caixa-Teia", "^^0.1");
4514        let err = d.validate().unwrap_err();
4515        assert!(
4516            matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4517            "got {err:?}"
4518        );
4519    }
4520
4521    #[test]
4522    fn nome_invalid_fires_before_fonte_invalid() {
4523        // Ordering pin: a malformed `:nome` fires before the `:fonte`
4524        // shape check on the *same* entry. The `:fonte` diagnostic
4525        // names the offending dep's `:nome` verbatim (via
4526        // `DepSource::validate(&self.nome)`), so a non-self-locating
4527        // name would taint the downstream diagnostic too — the gate
4528        // ordering keeps both diagnostics individually self-locating.
4529        let mut d = Dep::simple("Caixa-Teia", "^0.1");
4530        d.fonte = Some(DepSource::Git {
4531            repo: String::new(),
4532            tag: None,
4533            rev: None,
4534            branch: None,
4535        });
4536        let err = d.validate().unwrap_err();
4537        assert!(
4538            matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4539            "got {err:?}"
4540        );
4541    }
4542
4543    #[test]
4544    fn nome_invalid_diagnostic_carries_offending_name() {
4545        // The diagnostic-shape pin: the error names the offending
4546        // `:nome` value verbatim so the author can grep their
4547        // caixa.lisp without re-running the build, and carries a
4548        // non-empty `reason` from `is_dns_1123_label` so the
4549        // predicate's own wording flows through to the diagnostic.
4550        // Same shape as `MembroCaixaInvalid` (3f9d7a0),
4551        // `ChildCaixaInvalid` (31bfa43), `ManifestError::NomeInvalid`
4552        // (6c992f8) — the four DNS-1123 caixa-identifier axes now
4553        // share a structurally-equivalent diagnostic family.
4554        let d = Dep::simple("Caixa_Teia", "^0.1");
4555        let err = d.validate().unwrap_err();
4556        let DepError::NomeInvalid { nome, reason } = err else {
4557            panic!("expected NomeInvalid, got other variant");
4558        };
4559        assert_eq!(nome, "Caixa_Teia");
4560        assert!(
4561            !reason.is_empty(),
4562            "NomeInvalid `reason` must carry the predicate's wording verbatim"
4563        );
4564    }
4565
4566    #[test]
4567    fn validate_rejects_invalid_versao_requirement() {
4568        // The fail-before-pass-after pin: a non-empty but malformed
4569        // requirement (`"^bad-version"`) silently passed every pre-gate
4570        // codebase because `:deps :versao` wasn't validated. The parse
4571        // failure surfaced far downstream at lacre-resolve time with a
4572        // `semver::Error` that didn't name which `:deps` entry carried
4573        // the typo. The new gate moves the check to caixa-build time
4574        // at the source caixa.lisp.
4575        let d = Dep::simple("caixa-teia", "^bad-version");
4576        let err = d.validate().unwrap_err();
4577        assert!(
4578            matches!(
4579                err,
4580                DepError::VersaoInvalid { ref nome, ref versao, .. }
4581                    if nome == "caixa-teia" && versao == "^bad-version"
4582            ),
4583            "got {err:?}"
4584        );
4585    }
4586
4587    #[test]
4588    fn validate_rejects_versao_with_double_caret_typo() {
4589        // `"^^0.1"` is the canonical doubled-caret typo — looks like a
4590        // Cargo-shaped requirement on first glance but fails the parser
4591        // because semver doesn't accept stacked operators. Pin this
4592        // adjacent-shape footgun explicitly so a future relaxation that
4593        // accepts "looks-canonical-but-isn't" forms surfaces here, in
4594        // parity with the `:membros` / `:children` fixtures.
4595        let d = Dep::simple("caixa-teia", "^^0.1");
4596        let err = d.validate().unwrap_err();
4597        assert!(
4598            matches!(
4599                err,
4600                DepError::VersaoInvalid { ref nome, ref versao, .. }
4601                    if nome == "caixa-teia" && versao == "^^0.1"
4602            ),
4603            "got {err:?}"
4604        );
4605    }
4606
4607    #[test]
4608    fn validate_rejects_versao_with_v_prefixed_tag() {
4609        // `"v0.1"` is the canonical "git-tag-shape leaking into the
4610        // semver requirement slot" typo — an author copies the
4611        // publish-side git-tag string verbatim into `:versao`, but
4612        // Cargo's semver parser rejects the leading `v`. Same fixture
4613        // pinned for `:membros :versao` (9888b13) and `:children
4614        // :versao` (b38ff3a). (Bare `x`-glob shorthands like `^0.1.x`
4615        // are *accepted* by the semver crate as an `*` wildcard on the
4616        // patch axis — they're a Cargo-side valid shape, not a typo.)
4617        let d = Dep::simple("caixa-teia", "v0.1");
4618        let err = d.validate().unwrap_err();
4619        assert!(
4620            matches!(
4621                err,
4622                DepError::VersaoInvalid { ref nome, ref versao, .. }
4623                    if nome == "caixa-teia" && versao == "v0.1"
4624            ),
4625            "got {err:?}"
4626        );
4627    }
4628
4629    #[test]
4630    fn validate_accepts_canonical_versao_forms() {
4631        // The five Cargo-shaped requirement forms `:membros :versao`
4632        // and `:children :versao` already accept via
4633        // `crate::parse_requirement` must pass the deps gate without
4634        // re-validating at the resolver layer. Pin every leg so a
4635        // future tightening of the canonical set surfaces here as a
4636        // test failure.
4637        for form in [
4638            "^0.1",      // caret — minor-range pin (the most common shape)
4639            "~0.1.2",    // tilde — patch-range pin
4640            "0.1.0",     // exact — single-version pin
4641            "*",         // wildcard — explicitly any-version
4642            ">=0.1, <2", // multi-range — comma-separated comparators
4643        ] {
4644            Dep::simple("caixa-teia", form)
4645                .validate()
4646                .unwrap_or_else(|e| panic!("canonical form {form:?} must validate, got {e:?}"));
4647        }
4648    }
4649
4650    #[test]
4651    fn versao_empty_takes_precedence_over_invalid() {
4652        // Order pin: the existing `VersaoEmpty` diagnostic (which
4653        // doesn't try to parse) fires before the new `VersaoInvalid`
4654        // parse-side diagnostic, so an empty `:versao` keeps its
4655        // narrower error message — `parse_requirement("")` would
4656        // otherwise return `Ok(STAR)` and silently pass, but the empty
4657        // arm catches it first.
4658        let mut d = Dep::simple("caixa-teia", "ignored");
4659        d.versao = String::new();
4660        let err = d.validate().unwrap_err();
4661        assert!(
4662            matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4663            "got {err:?}"
4664        );
4665    }
4666
4667    #[test]
4668    fn nome_empty_takes_precedence_over_versao_invalid() {
4669        // Order pin: even when `:versao` is malformed and would raise
4670        // its own diagnostic, `:nome ""` fires first because the
4671        // per-entry parse diagnostic needs a non-empty name to be
4672        // self-locating. Mirrors the
4673        // `membros_validation_runs_before_contratos_membership_check`
4674        // ordering on the typed-graph layer.
4675        let mut d = Dep::simple("placeholder", "^bad");
4676        d.nome = String::new();
4677        let err = d.validate().unwrap_err();
4678        assert_eq!(err, DepError::NomeEmpty);
4679    }
4680
4681    #[test]
4682    fn versao_invalid_diagnostic_carries_offending_versao() {
4683        // The diagnostic-shape pin: the error names the offending
4684        // `:versao` value verbatim so the author can grep their
4685        // caixa.lisp without re-running the build, and carries a
4686        // non-empty `reason` from `semver::VersionReq::parse` so the
4687        // parser's own wording flows through to the diagnostic.
4688        let d = Dep::simple("caixa-teia", "not-a-req");
4689        let err = d.validate().unwrap_err();
4690        let DepError::VersaoInvalid {
4691            nome,
4692            versao,
4693            reason,
4694        } = err
4695        else {
4696            panic!("expected VersaoInvalid, got other variant");
4697        };
4698        assert_eq!(nome, "caixa-teia");
4699        assert_eq!(versao, "not-a-req");
4700        assert!(
4701            !reason.is_empty(),
4702            "VersaoInvalid `reason` must carry the parser's wording verbatim"
4703        );
4704    }
4705
4706    // -- :fonte value-shape gate ------------------------------------------
4707
4708    fn dep_with_fonte(fonte: DepSource) -> Dep {
4709        let mut d = Dep::simple("caixa-teia", "^0.1");
4710        d.fonte = Some(fonte);
4711        d
4712    }
4713
4714    #[test]
4715    fn validate_accepts_git_fonte_with_tag() {
4716        // The positive-control pin on the canonical git source — exactly
4717        // one of :tag/:rev/:branch set, non-empty :repo. Mirrors the
4718        // shape every existing caixa-resolver integration test uses.
4719        let d = dep_with_fonte(DepSource::Git {
4720            repo: "github:pleme-io/caixa-teia".into(),
4721            tag: Some("v0.1.0".into()),
4722            rev: None,
4723            branch: None,
4724        });
4725        d.validate().unwrap();
4726    }
4727
4728    #[test]
4729    fn validate_accepts_git_fonte_with_rev() {
4730        // Each of the three pin axes is independently a valid single-pin
4731        // shape; pin the :rev arm so a future relaxation that only
4732        // accepts :tag surfaces here. The value is a full 40-hex SHA-1
4733        // OID — the canonical `git rev-parse HEAD` emission shape the
4734        // `crate::render::is_git_oid` value-shape gate now requires;
4735        // abbreviated OIDs are ambiguous across repo history and
4736        // rejected at this gate (pinned separately by
4737        // `validate_rejects_git_fonte_with_rev_abbreviated_prefix`).
4738        let d = dep_with_fonte(DepSource::Git {
4739            repo: "github:pleme-io/caixa-teia".into(),
4740            tag: None,
4741            rev: Some("c0ffee0123abcdef0123456789abcdef01234567".into()),
4742            branch: None,
4743        });
4744        d.validate().unwrap();
4745    }
4746
4747    #[test]
4748    fn validate_accepts_git_fonte_with_branch() {
4749        // The :branch arm is the third valid single-pin shape — pinned
4750        // separately so the gate-accepts-all-three-pin-axes contract is
4751        // a build-error to relax.
4752        let d = dep_with_fonte(DepSource::Git {
4753            repo: "github:pleme-io/caixa-teia".into(),
4754            tag: None,
4755            rev: None,
4756            branch: Some("main".into()),
4757        });
4758        d.validate().unwrap();
4759    }
4760
4761    #[test]
4762    fn validate_accepts_path_fonte() {
4763        // The positive-control pin on the path source — non-empty
4764        // :caminho, no pin axes (paths have no commit identity). Pinned
4765        // so a future "paths must also pin a rev" tightening surfaces
4766        // here as a structural decision, not a silent break.
4767        let d = dep_with_fonte(DepSource::Path {
4768            caminho: "../caixa-teia".into(),
4769        });
4770        d.validate().unwrap();
4771    }
4772
4773    #[test]
4774    fn validate_rejects_git_fonte_with_empty_repo() {
4775        // The fail-before-pass-after pin for `(:tipo git :repo "" :tag
4776        // "v1")`: the empty-repo shape silently passed every pre-gate
4777        // codebase because `:fonte` wasn't validated. The git-clone
4778        // failure surfaced far downstream at lacre-resolve time with no
4779        // field naming which `:deps` entry carried the typo. The new
4780        // gate moves the check to caixa-build time at the source
4781        // caixa.lisp.
4782        let d = dep_with_fonte(DepSource::Git {
4783            repo: String::new(),
4784            tag: Some("v0.1.0".into()),
4785            rev: None,
4786            branch: None,
4787        });
4788        let err = d.validate().unwrap_err();
4789        assert!(
4790            matches!(err, DepError::FonteRepoEmpty { ref nome } if nome == "caixa-teia"),
4791            "got {err:?}"
4792        );
4793    }
4794
4795    // -- :repo value-shape gate -------------------------------------------
4796    //
4797    // The `:fonte (:tipo git :repo …)` value flows verbatim into the
4798    // caixa-resolver's `git clone <repo>` subprocess. The pre-gate
4799    // codebase admitted any non-empty string; the new
4800    // [`crate::render::is_git_repo_url`] predicate gates the git-porcelain
4801    // URL intersection-floor at validate time, peer with the three pin
4802    // axes (`:tag` + `:branch` via `is_git_ref_name`, `:rev` via
4803    // `is_git_oid`). Every test in this section is a fail-before /
4804    // pass-after pin on a specific authoring footgun.
4805
4806    #[test]
4807    fn validate_rejects_git_fonte_with_repo_carrying_trailing_space() {
4808        // The canonical paste-from-doc footgun on `:repo` — an author
4809        // copies `"github:pleme-io/caixa-teia "` (trailing space) out of
4810        // a doc paragraph. Until this gate landed the empty-repo arm
4811        // passed (the string isn't empty), the resolver issued
4812        // `git clone 'github:pleme-io/caixa-teia '`, and the failure
4813        // surfaced at clone time with a quoting-confused error far from
4814        // the source caixa.lisp. Same paste-from-doc footgun the
4815        // `:tag "v0.1.0 "` gate (e70d213) closes on the peer refname
4816        // axis — now closed on the `:repo` URL axis too.
4817        let d = dep_with_fonte(DepSource::Git {
4818            repo: "github:pleme-io/caixa-teia ".into(),
4819            tag: Some("v0.1.0".into()),
4820            rev: None,
4821            branch: None,
4822        });
4823        let err = d.validate().unwrap_err();
4824        let DepError::FonteRepoShape { nome, repo, reason } = err else {
4825            panic!("expected FonteRepoShape, got other variant");
4826        };
4827        assert_eq!(nome, "caixa-teia");
4828        assert_eq!(repo, "github:pleme-io/caixa-teia ");
4829        assert!(
4830            reason.contains("whitespace"),
4831            "reason must surface the whitespace arm, got {reason:?}"
4832        );
4833    }
4834
4835    #[test]
4836    fn validate_rejects_git_fonte_with_repo_starting_with_dash() {
4837        // The canonical CLI-argument-injection footgun at the `git clone`
4838        // subprocess boundary — `:repo "-upload-pack=evil"` makes git's
4839        // argv parser read the value as a CLI flag, escaping the
4840        // subprocess argument boundary. The `--` separator workaround
4841        // does not fix the typed slot's accepted set; the gate rejects
4842        // the shape upstream at validate time so the resolver never
4843        // invokes a `git clone -…` subprocess.
4844        let d = dep_with_fonte(DepSource::Git {
4845            repo: "-upload-pack=evil".into(),
4846            tag: Some("v0.1.0".into()),
4847            rev: None,
4848            branch: None,
4849        });
4850        let err = d.validate().unwrap_err();
4851        let DepError::FonteRepoShape { repo, reason, .. } = err else {
4852            panic!("expected FonteRepoShape, got other variant");
4853        };
4854        assert_eq!(repo, "-upload-pack=evil");
4855        assert!(
4856            reason.contains("must not start with `-`"),
4857            "reason must surface the leading-`-` arm, got {reason:?}"
4858        );
4859    }
4860
4861    #[test]
4862    fn validate_rejects_git_fonte_with_repo_carrying_embedded_newline() {
4863        // The canonical paste-from-multiline-doc footgun — a `:repo`
4864        // string with an embedded `\n` silently breaks git's URL parser
4865        // and is a class of CRLF-injection at the subprocess-argument
4866        // boundary. Caught by the control-char arm (0x0A < 0x20).
4867        let d = dep_with_fonte(DepSource::Git {
4868            repo: "github:pleme-io/caixa-teia\nrm -rf /".into(),
4869            tag: Some("v0.1.0".into()),
4870            rev: None,
4871            branch: None,
4872        });
4873        let err = d.validate().unwrap_err();
4874        let DepError::FonteRepoShape { reason, .. } = err else {
4875            panic!("expected FonteRepoShape, got other variant");
4876        };
4877        assert!(
4878            reason.contains("control character"),
4879            "reason must surface the control-char arm, got {reason:?}"
4880        );
4881    }
4882
4883    #[test]
4884    fn validate_rejects_git_fonte_with_repo_carrying_tab() {
4885        // Tab is the sibling whitespace footgun (the canonical
4886        // copy-from-aligned-table paste); pinned separately from the
4887        // space arm so a future relaxation that only catches one
4888        // surfaces here.
4889        let d = dep_with_fonte(DepSource::Git {
4890            repo: "github:pleme-io/caixa-teia\t".into(),
4891            tag: Some("v0.1.0".into()),
4892            rev: None,
4893            branch: None,
4894        });
4895        let err = d.validate().unwrap_err();
4896        assert!(
4897            matches!(
4898                err,
4899                DepError::FonteRepoShape { ref reason, .. }
4900                    if reason.contains("whitespace")
4901            ),
4902            "got {err:?}"
4903        );
4904    }
4905
4906    #[test]
4907    fn validate_rejects_git_fonte_with_repo_carrying_non_ascii() {
4908        // IDN hosts must be pre-encoded as Punycode (`xn--…`) — raw
4909        // non-ASCII silently breaks at git's URL parser and round-trips
4910        // inconsistently across NFC/NFD normalization on APFS /
4911        // case-folding filesystems. Same intersection-floor
4912        // [`is_git_ref_name`] enforces on the refname axes.
4913        let d = dep_with_fonte(DepSource::Git {
4914            repo: "https://github.com/pleme-io/café".into(),
4915            tag: Some("v0.1.0".into()),
4916            rev: None,
4917            branch: None,
4918        });
4919        let err = d.validate().unwrap_err();
4920        assert!(
4921            matches!(
4922                err,
4923                DepError::FonteRepoShape { ref reason, .. }
4924                    if reason.contains("non-ASCII")
4925            ),
4926            "got {err:?}"
4927        );
4928    }
4929
4930    #[test]
4931    fn validate_rejects_git_fonte_with_repo_carrying_fragment_anchor() {
4932        // The fail-before-pass-after pin for the canonical paste-from-
4933        // browser-address-bar footgun on `:repo`: an author copies a
4934        // GitHub permalink to a README anchor / line-permalink and
4935        // forgets to trim the `#fragment` tail. Until this arm landed
4936        // `:repo "https://github.com/pleme-io/caixa-teia#readme"`
4937        // silently passed every prior arm (no whitespace, no control
4938        // chars, no non-ASCII, contains a `:`, doesn't start with `-`
4939        // or `:`), libcurl's URL parser stripped the `#readme` tail
4940        // before opening the HTTPS transport, and the lacre embedded
4941        // the value verbatim in its per-dep BLAKE3 closure — two
4942        // authors whose values differ only in their fragment anchor
4943        // (`#readme` vs `#L42`) resolve to the byte-identical upstream
4944        // `git clone` but lock to two distinct lacres, defeating the
4945        // THEORY.md §V.2 render-determinism contract. Same value-shape
4946        // axis-floor every peer typed surface enforces; peer `:fonte
4947        // :tag` / `:fonte :branch` already reject the byte-class through
4948        // `is_git_ref_name`'s alphabet (refs are leaf identifiers, no
4949        // URL grammar admitted) and `:entrada :paths` rejects `#` as
4950        // part of `is_gateway_api_http_path`'s RFC-3986-reserved set.
4951        let d = dep_with_fonte(DepSource::Git {
4952            repo: "https://github.com/pleme-io/caixa-teia#readme".into(),
4953            tag: Some("v0.1.0".into()),
4954            rev: None,
4955            branch: None,
4956        });
4957        let err = d.validate().unwrap_err();
4958        let DepError::FonteRepoShape { nome, repo, reason } = err else {
4959            panic!("expected FonteRepoShape, got other variant");
4960        };
4961        assert_eq!(nome, "caixa-teia");
4962        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia#readme");
4963        assert!(
4964            reason.contains("must not contain `#`"),
4965            "reason must surface the fragment-`#` arm, got {reason:?}"
4966        );
4967        assert!(
4968            reason.contains("fragment"),
4969            "reason must name the URL fragment grammar, got {reason:?}"
4970        );
4971    }
4972
4973    #[test]
4974    fn validate_rejects_git_fonte_with_repo_carrying_flake_ref_fragment() {
4975        // The symmetric paste-from-Nix-flake-ref footgun — an author
4976        // confuses the Nix flake-reference idiom (`github:foo/
4977        // bar#packageName`, where `#packageName` selects a flake
4978        // output) with the bare git `:repo` shape. The pleme-io
4979        // substrate authors compose flakes downstream of caixa
4980        // (caixa-flake renders a flake.nix), so the cross-idiom leak
4981        // is the canonical near-miss: the author writes the
4982        // flake-ref shape into a git `:repo` slot. Pinned separately
4983        // from the HTTPS-anchor arm so a future relaxation that
4984        // narrows to one URL scheme surfaces here.
4985        let d = dep_with_fonte(DepSource::Git {
4986            repo: "github:pleme-io/caixa-teia#caixa-teia".into(),
4987            tag: Some("v0.1.0".into()),
4988            rev: None,
4989            branch: None,
4990        });
4991        let err = d.validate().unwrap_err();
4992        let DepError::FonteRepoShape { reason, .. } = err else {
4993            panic!("expected FonteRepoShape, got other variant");
4994        };
4995        assert!(
4996            reason.contains("must not contain `#`"),
4997            "reason must surface the fragment-`#` arm, got {reason:?}"
4998        );
4999        assert!(
5000            reason.contains("Nix flake"),
5001            "reason must name the Nix-flake-ref cross-idiom footgun, got {reason:?}"
5002        );
5003    }
5004
5005    #[test]
5006    fn validate_rejects_git_fonte_with_repo_carrying_query_string() {
5007        // The fail-before-pass-after pin for the canonical paste-from-
5008        // browser-address-bar footgun on `:repo` (peer with the
5009        // a68f818 fragment-`#` arm on the same axis). An author
5010        // copies a GitHub tab deep-link out of the address bar and
5011        // forgets to trim the `?tab=…` query tail. Until this arm
5012        // landed `:repo "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"`
5013        // silently passed every prior arm (no whitespace, no control
5014        // chars, no non-ASCII, no `#` fragment, contains a `:`,
5015        // doesn't start with `-` or `:`); GitHub silently ignored
5016        // the `?query` tail and served the same repo regardless;
5017        // the lacre embedded the value verbatim in its per-dep
5018        // BLAKE3 closure — two authors whose values differ only in
5019        // their query tail (`?tab=readme-ov-file` vs `?ref=main` vs
5020        // `?utm_source=twitter`) resolve to the byte-identical
5021        // upstream `git clone` but lock to two distinct lacres,
5022        // defeating the THEORY.md §V.2 render-determinism contract
5023        // on the same axis the `#` fragment arm closes. Same value-
5024        // shape axis-floor every peer typed surface enforces; peer
5025        // `:fonte :tag` / `:fonte :branch` already reject the byte-
5026        // class through `is_git_ref_name`'s alphabet (refspec glob
5027        // wildcards, caixa-core/src/render.rs:1426) and `:entrada
5028        // :paths` rejects `?` as the query separator in
5029        // `is_gateway_api_http_path` (caixa-core/src/render.rs:473).
5030        let d = dep_with_fonte(DepSource::Git {
5031            repo: "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file".into(),
5032            tag: Some("v0.1.0".into()),
5033            rev: None,
5034            branch: None,
5035        });
5036        let err = d.validate().unwrap_err();
5037        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5038            panic!("expected FonteRepoShape, got other variant");
5039        };
5040        assert_eq!(nome, "caixa-teia");
5041        assert_eq!(
5042            repo,
5043            "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"
5044        );
5045        assert!(
5046            reason.contains("must not contain `?`"),
5047            "reason must surface the query-`?` arm, got {reason:?}"
5048        );
5049        assert!(
5050            reason.contains("query"),
5051            "reason must name the URL query grammar, got {reason:?}"
5052        );
5053    }
5054
5055    #[test]
5056    fn validate_rejects_git_fonte_with_repo_carrying_utm_tracker() {
5057        // The symmetric paste-from-social-share footgun — an author
5058        // copies a repo URL out of a Slack unfurl / Twitter share /
5059        // newsletter link / Discord embed and forgets to trim the
5060        // `?utm_source=…` / `?utm_medium=…` / `?utm_campaign=…`
5061        // campaign-tracker tail. Every major social-share / unfurl /
5062        // newsletter platform appends these UTM parameters; the
5063        // canonical near-miss on the `:repo` axis. Pinned separately
5064        // from the GitHub-tab-deep-link arm so a future relaxation
5065        // that narrows to one query-parameter class surfaces here.
5066        let d = dep_with_fonte(DepSource::Git {
5067            repo: "https://github.com/pleme-io/caixa-teia?utm_source=twitter&utm_campaign=launch"
5068                .into(),
5069            tag: Some("v0.1.0".into()),
5070            rev: None,
5071            branch: None,
5072        });
5073        let err = d.validate().unwrap_err();
5074        let DepError::FonteRepoShape { reason, .. } = err else {
5075            panic!("expected FonteRepoShape, got other variant");
5076        };
5077        assert!(
5078            reason.contains("must not contain `?`"),
5079            "reason must surface the query-`?` arm, got {reason:?}"
5080        );
5081        assert!(
5082            reason.contains("campaign-tracker"),
5083            "reason must name the campaign-tracker paste footgun, got {reason:?}"
5084        );
5085    }
5086
5087    #[test]
5088    fn fonte_repo_fragment_fires_before_query_when_fragment_first() {
5089        // Cascade pin: the fragment-`#` arm and the query-`?` arm are
5090        // both per-byte arms inside the same `for &b in s.as_bytes()`
5091        // loop, so the byte that appears first in the value's byte
5092        // order wins. A `:repo "https://github.com/p/x#readme?ref=main"`
5093        // (fragment before query — unusual URL-grammar but value-
5094        // disjoint at byte level) carries both `#` and `?`; the `#`
5095        // byte appears first, so the fragment-`#` arm fires, surfacing
5096        // the more self-locating diagnostic on the byte the author
5097        // pasted earliest in the URL. Mirrors the peer cascade
5098        // discipline `fonte_repo_control_char_fires_before_fragment`
5099        // pins on the prior `:repo` byte-class arm.
5100        let d = dep_with_fonte(DepSource::Git {
5101            repo: "https://github.com/pleme-io/caixa-teia#readme?ref=main".into(),
5102            tag: Some("v0.1.0".into()),
5103            rev: None,
5104            branch: None,
5105        });
5106        let err = d.validate().unwrap_err();
5107        let DepError::FonteRepoShape { reason, .. } = err else {
5108            panic!("expected FonteRepoShape, got other variant");
5109        };
5110        assert!(
5111            reason.contains("must not contain `#`"),
5112            "reason must surface the fragment-`#` arm (fires before query-`?` when \
5113             `#` byte appears first in value), got {reason:?}"
5114        );
5115    }
5116
5117    #[test]
5118    fn fonte_repo_control_char_fires_before_fragment() {
5119        // Cascade pin: the control-char arm structurally precedes the
5120        // fragment-`#` arm. A value like `"github:p/x\n#readme"` probes
5121        // positive on both arms (contains LF and `#`), but the narrower
5122        // POSIX-syscall-rejected / CRLF-injection-class diagnostic
5123        // (`control character`) wins so the author sees the more
5124        // self-locating arm first. Mirrors the peer cascade discipline
5125        // every prior `:repo` byte-class arm establishes.
5126        let d = dep_with_fonte(DepSource::Git {
5127            repo: "github:pleme-io/caixa-teia\n#readme".into(),
5128            tag: Some("v0.1.0".into()),
5129            rev: None,
5130            branch: None,
5131        });
5132        let err = d.validate().unwrap_err();
5133        let DepError::FonteRepoShape { reason, .. } = err else {
5134            panic!("expected FonteRepoShape, got other variant");
5135        };
5136        assert!(
5137            reason.contains("control character"),
5138            "reason must surface the control-char arm, got {reason:?}"
5139        );
5140    }
5141
5142    #[test]
5143    fn validate_rejects_git_fonte_with_repo_carrying_embedded_backslash() {
5144        // The fail-before-pass-after pin for the canonical Windows-
5145        // file-path-confusion footgun on `:repo` (peer with the 3a4e1d7
5146        // backslash arm on the sibling `:caminho` path-fonte axis).
5147        // An author pastes a Windows Explorer address-bar / PowerShell
5148        // `Get-Location` output into a `file://` URL slot, producing
5149        // `file:///C:\Users\me\caixa-teia`. Until this arm landed the
5150        // value silently passed every prior arm (no whitespace, no
5151        // control chars, no non-ASCII, no `#`, no `?`, doesn't start
5152        // with `-` or `:`); libcurl's URL parser silently translates
5153        // `\` → `/` on some platforms and refuses it on others, so
5154        // the byte rides verbatim into the lacre's per-dep content-
5155        // address but is silently rewritten / rejected at the wire —
5156        // two authors whose `:repo` values differ only in backslash-
5157        // vs-forward-slash (`file:///C:\path` vs `file:///C:/path`)
5158        // resolve to the byte-identical local clone but lock to two
5159        // distinct BLAKE3 closures, defeating the THEORY.md §V.2
5160        // render-determinism contract on the same axis the `#`
5161        // fragment and `?` query arms close. Same value-shape axis-
5162        // floor every peer typed surface enforces; the `:caminho`
5163        // 3a4e1d7 arm closes the same byte on the path-fonte axis.
5164        let d = dep_with_fonte(DepSource::Git {
5165            repo: "file:///C:\\Users\\me\\caixa-teia".into(),
5166            tag: Some("v0.1.0".into()),
5167            rev: None,
5168            branch: None,
5169        });
5170        let err = d.validate().unwrap_err();
5171        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5172            panic!("expected FonteRepoShape, got other variant");
5173        };
5174        assert_eq!(nome, "caixa-teia");
5175        assert_eq!(repo, "file:///C:\\Users\\me\\caixa-teia");
5176        assert!(
5177            reason.contains("must not contain `\\`"),
5178            "reason must surface the backslash-`\\` arm, got {reason:?}"
5179        );
5180        assert!(
5181            reason.contains("Windows"),
5182            "reason must name the Windows-path-confusion footgun, got {reason:?}"
5183        );
5184    }
5185
5186    #[test]
5187    fn validate_rejects_git_fonte_with_repo_carrying_mangled_https_backslashes() {
5188        // The symmetric Win32-shell-mangled-slashes footgun — an author
5189        // copies `https://github.com/foo/bar` into a Win32 shell that
5190        // rewrites every `/` to `\` (the canonical `cmd.exe` path-
5191        // separator-coercion bug), pastes the result into a `:repo`
5192        // slot, and produces `https:\\github.com\foo\bar`. Pinned
5193        // separately from the `file://` Explorer-paste arm so a future
5194        // relaxation that narrows to one URL scheme surfaces here.
5195        let d = dep_with_fonte(DepSource::Git {
5196            repo: "https:\\\\github.com\\pleme-io\\caixa-teia".into(),
5197            tag: Some("v0.1.0".into()),
5198            rev: None,
5199            branch: None,
5200        });
5201        let err = d.validate().unwrap_err();
5202        let DepError::FonteRepoShape { reason, .. } = err else {
5203            panic!("expected FonteRepoShape, got other variant");
5204        };
5205        assert!(
5206            reason.contains("must not contain `\\`"),
5207            "reason must surface the backslash-`\\` arm, got {reason:?}"
5208        );
5209        assert!(
5210            reason.contains("path separator") || reason.contains("path-segment separator"),
5211            "reason must name the URL path-segment separator grammar, got {reason:?}"
5212        );
5213    }
5214
5215    #[test]
5216    fn fonte_repo_fragment_fires_before_backslash_when_fragment_first() {
5217        // Cascade pin: the fragment-`#` arm and the backslash-`\` arm
5218        // are both per-byte arms inside the same `for &b in s.as_bytes()`
5219        // loop, so the byte that appears first in the value's byte order
5220        // wins. A `:repo "https://github.com/p/x#readme\\foo"` carries
5221        // both `#` and `\`; the `#` byte appears first, so the fragment-
5222        // `#` arm fires, surfacing the more self-locating diagnostic on
5223        // the byte the author pasted earliest in the URL. Mirrors the
5224        // peer cascade discipline `fonte_repo_fragment_fires_before_query_when_fragment_first`
5225        // pins on the prior `:repo` byte-class arm.
5226        let d = dep_with_fonte(DepSource::Git {
5227            repo: "https://github.com/pleme-io/caixa-teia#readme\\foo".into(),
5228            tag: Some("v0.1.0".into()),
5229            rev: None,
5230            branch: None,
5231        });
5232        let err = d.validate().unwrap_err();
5233        let DepError::FonteRepoShape { reason, .. } = err else {
5234            panic!("expected FonteRepoShape, got other variant");
5235        };
5236        assert!(
5237            reason.contains("must not contain `#`"),
5238            "reason must surface the fragment-`#` arm (fires before backslash-`\\` when \
5239             `#` byte appears first in value), got {reason:?}"
5240        );
5241    }
5242
5243    #[test]
5244    fn validate_rejects_git_fonte_with_repo_carrying_uri_template_placeholder() {
5245        // The fail-before-pass-after pin for the canonical URI Template
5246        // (RFC 6570) placeholder footgun on `:repo`. An author copies a
5247        // README quick-start snippet / OpenAPI `servers:` URL / Helm
5248        // chart `home:` template that carries unresolved
5249        // `{org}` / `{repo}` placeholders and pastes the raw template
5250        // into the `:repo` slot, expecting the substrate to resolve the
5251        // placeholder downstream. Until this arm landed the value
5252        // silently passed every prior arm (no whitespace, no control
5253        // chars, no non-ASCII, no `#`, no `?`, no `\`, doesn't start
5254        // with `-` or `:`); libcurl percent-encodes `{` / `}` to `%7B`
5255        // / `%7D` on the wire, so the byte rides verbatim into the
5256        // lacre's per-dep content-address but round-trips inconsistently
5257        // between the lacre's per-dep content-address and the
5258        // resolver's `git clone <repo>` invocation, defeating the
5259        // THEORY.md §V.2 render-determinism contract on the same axis
5260        // the `#` fragment, `?` query, and `\` backslash arms close;
5261        // every git porcelain entry-point additionally fetches a
5262        // nonexistent literal-`{placeholder}`-named path far from the
5263        // source caixa.lisp.
5264        let d = dep_with_fonte(DepSource::Git {
5265            repo: "https://github.com/{org}/caixa-teia".into(),
5266            tag: Some("v0.1.0".into()),
5267            rev: None,
5268            branch: None,
5269        });
5270        let err = d.validate().unwrap_err();
5271        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5272            panic!("expected FonteRepoShape, got other variant");
5273        };
5274        assert_eq!(nome, "caixa-teia");
5275        assert_eq!(repo, "https://github.com/{org}/caixa-teia");
5276        assert!(
5277            reason.contains("must not contain `{`"),
5278            "reason must surface the open-brace `{{` arm, got {reason:?}"
5279        );
5280        assert!(
5281            reason.contains("URI Template") || reason.contains("RFC 6570"),
5282            "reason must name the RFC 6570 URI Template grammar, got {reason:?}"
5283        );
5284    }
5285
5286    #[test]
5287    fn validate_rejects_git_fonte_with_repo_carrying_handlebars_doubled_brace() {
5288        // The symmetric Mustache / Handlebars doubled-brace
5289        // substitution-form footgun every CI / IaC templating engine
5290        // (Argo Workflows, Jinja2, Liquid, Vue / Angular interpolation,
5291        // GitHub Actions `${{ … }}` even though Actions uses `${{`) /
5292        // chart README quick-start snippet emits. Pinned separately
5293        // from the single-`{` `{org}` arm so a future relaxation that
5294        // narrows to one substitution-form surfaces here.
5295        let d = dep_with_fonte(DepSource::Git {
5296            repo: "https://github.com/{{org}}/caixa-teia".into(),
5297            tag: Some("v0.1.0".into()),
5298            rev: None,
5299            branch: None,
5300        });
5301        let err = d.validate().unwrap_err();
5302        let DepError::FonteRepoShape { reason, .. } = err else {
5303            panic!("expected FonteRepoShape, got other variant");
5304        };
5305        assert!(
5306            reason.contains("must not contain `{`"),
5307            "reason must surface the open-brace `{{` arm, got {reason:?}"
5308        );
5309    }
5310
5311    #[test]
5312    fn validate_rejects_git_fonte_with_repo_carrying_closing_brace_only() {
5313        // Asymmetric `}`-only shape — covers the closing-brace-by-
5314        // itself footgun (an author truncated `{org}/{repo}` mid-edit
5315        // and left a trailing `}` from the prior template fragment,
5316        // or pasted a value that included a closing brace from a
5317        // surrounding shell context). Pinned to ensure the predicate
5318        // refuses each brace independently rather than only when both
5319        // appear — a future regression that ANDs the two byte tests
5320        // surfaces here.
5321        let d = dep_with_fonte(DepSource::Git {
5322            repo: "https://github.com/pleme-io/caixa-teia}".into(),
5323            tag: Some("v0.1.0".into()),
5324            rev: None,
5325            branch: None,
5326        });
5327        let err = d.validate().unwrap_err();
5328        let DepError::FonteRepoShape { reason, .. } = err else {
5329            panic!("expected FonteRepoShape, got other variant");
5330        };
5331        assert!(
5332            reason.contains("must not contain `}`"),
5333            "reason must surface the close-brace `}}` arm, got {reason:?}"
5334        );
5335    }
5336
5337    #[test]
5338    fn fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first() {
5339        // Cascade pin: the fragment-`#` arm and the template-`{` /
5340        // `}` arm are both per-byte arms inside the same
5341        // `for &b in s.as_bytes()` loop, so the byte that appears
5342        // first in the value's byte order wins. A `:repo
5343        // "https://github.com/p/x#readme{org}"` carries both `#` and
5344        // `{`; the `#` byte appears first, so the fragment-`#` arm
5345        // fires, surfacing the more self-locating diagnostic on the
5346        // byte the author pasted earliest in the URL. Mirrors the
5347        // peer cascade discipline `fonte_repo_fragment_fires_before_backslash_when_fragment_first`
5348        // pins on the prior `:repo` byte-class arm.
5349        let d = dep_with_fonte(DepSource::Git {
5350            repo: "https://github.com/pleme-io/caixa-teia#readme{org}".into(),
5351            tag: Some("v0.1.0".into()),
5352            rev: None,
5353            branch: None,
5354        });
5355        let err = d.validate().unwrap_err();
5356        let DepError::FonteRepoShape { reason, .. } = err else {
5357            panic!("expected FonteRepoShape, got other variant");
5358        };
5359        assert!(
5360            reason.contains("must not contain `#`"),
5361            "reason must surface the fragment-`#` arm (fires before template-`{{` when \
5362             `#` byte appears first in value), got {reason:?}"
5363        );
5364    }
5365
5366    #[test]
5367    fn validate_rejects_git_fonte_with_repo_carrying_output_redirection() {
5368        // The fail-before-pass-after pin for the canonical
5369        // shell-output-redirection footgun on `:repo`: an author
5370        // pastes a shell-pipeline tail (`git clone <repo> > build.log`
5371        // / `… >output.txt`) into the `:repo` slot without trimming
5372        // the redirect. Until this arm landed the value silently
5373        // passed every prior arm (no whitespace, no control chars,
5374        // no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, doesn't
5375        // start with `-` or `:`); RFC 3986 §2 lists `<` / `>` in the
5376        // 'delims' / 'unwise' set and the WHATWG URL spec's fragment
5377        // percent-encode set maps `>` → `%3E` on the wire, so the
5378        // byte rides verbatim into the lacre's per-dep BLAKE3 closure
5379        // but is silently rewritten or rejected at libcurl's URL-
5380        // parser layer — two authors whose values differ only in
5381        // their redirect tail (`>build.log` vs nothing) resolve to
5382        // the byte-identical upstream `git clone` but lock to two
5383        // distinct lacres, defeating the THEORY.md §V.2 render-
5384        // determinism contract. Peer with the `:caminho` axis's
5385        // `FonteCaminhoShellRedirection` arm (e457141) on the sibling
5386        // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5387        // byte RFC-3986-reserved set on `:entrada :paths`.
5388        let d = dep_with_fonte(DepSource::Git {
5389            repo: "https://github.com/pleme-io/caixa-teia>build.log".into(),
5390            tag: Some("v0.1.0".into()),
5391            rev: None,
5392            branch: None,
5393        });
5394        let err = d.validate().unwrap_err();
5395        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5396            panic!("expected FonteRepoShape, got other variant");
5397        };
5398        assert_eq!(nome, "caixa-teia");
5399        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia>build.log");
5400        assert!(
5401            reason.contains("must not contain `>`"),
5402            "reason must surface the output-redirection `>` arm, got {reason:?}"
5403        );
5404        assert!(
5405            reason.contains("redirection") || reason.contains("'delims'"),
5406            "reason must name the shell-redirection / RFC-3986-unwise rationale, got {reason:?}"
5407        );
5408    }
5409
5410    #[test]
5411    fn validate_rejects_git_fonte_with_repo_carrying_input_redirection() {
5412        // The symmetric shell-input-redirection footgun — an author
5413        // pastes a shell-pipeline head (`git clone <input.url` /
5414        // `cat <README.md`) into the `:repo` slot. Pinned separately
5415        // from the `>`-output arm so a future relaxation that only
5416        // catches one of the two redirect bytes surfaces here. Peer
5417        // with the `:caminho` axis's `FonteCaminhoShellRedirection`
5418        // arm which closes both `<` and `>` under the same banner.
5419        let d = dep_with_fonte(DepSource::Git {
5420            repo: "https://github.com/pleme-io/caixa-teia<input.url".into(),
5421            tag: Some("v0.1.0".into()),
5422            rev: None,
5423            branch: None,
5424        });
5425        let err = d.validate().unwrap_err();
5426        let DepError::FonteRepoShape { reason, .. } = err else {
5427            panic!("expected FonteRepoShape, got other variant");
5428        };
5429        assert!(
5430            reason.contains("must not contain `<`"),
5431            "reason must surface the input-redirection `<` arm, got {reason:?}"
5432        );
5433        assert!(
5434            reason.contains("RFC 3986") || reason.contains("'unwise'"),
5435            "reason must name the RFC 3986 'unwise' grammar, got {reason:?}"
5436        );
5437    }
5438
5439    #[test]
5440    fn validate_rejects_git_fonte_with_repo_carrying_backtick_command_substitution() {
5441        // The fail-before-pass-after pin for the canonical
5442        // paste-from-shell-prompt-with-backticked-substitution footgun
5443        // on `:repo` (peer with the c4d62b3 backtick arm on the sibling
5444        // `:caminho` path-fonte axis). An author pastes a URL whose
5445        // segment carries a backticked command-substitution wrapper
5446        // (`` `whoami` ``, `` `git config user.name` ``, `` `pwd` ``)
5447        // from a doc / README quick-start snippet that expected the
5448        // substrate to substitute the value downstream. Until this arm
5449        // landed the value silently passed every prior arm (no
5450        // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5451        // no `\`, no `{`/`}`, no `<`/`>`, doesn't start with `-` or
5452        // `:`); RFC 3986 §2 lists the backtick byte in the 'delims' /
5453        // 'unwise' set and the WHATWG URL spec's fragment percent-
5454        // encode set maps `` ` `` → `%60` on the wire, so the byte
5455        // rides verbatim into the lacre's per-dep BLAKE3 closure but
5456        // is silently rewritten or rejected at libcurl's URL-parser
5457        // layer — two authors whose values differ only in their
5458        // backtick wrapper (`` `whoami` `` vs nothing) resolve to the
5459        // byte-identical upstream `git clone` but lock to two distinct
5460        // lacres, defeating the THEORY.md §V.2 render-determinism
5461        // contract. Peer with the `:caminho` axis's
5462        // `FonteCaminhoShellCommandSubstitution` arm (c4d62b3) on the
5463        // sibling path-fonte axis, and `is_gateway_api_http_path`'s
5464        // eleven-byte RFC-3986-reserved set on `:entrada :paths`.
5465        let d = dep_with_fonte(DepSource::Git {
5466            repo: "https://github.com/pleme-io/`whoami`/caixa-teia".into(),
5467            tag: Some("v0.1.0".into()),
5468            rev: None,
5469            branch: None,
5470        });
5471        let err = d.validate().unwrap_err();
5472        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5473            panic!("expected FonteRepoShape, got other variant");
5474        };
5475        assert_eq!(nome, "caixa-teia");
5476        assert_eq!(repo, "https://github.com/pleme-io/`whoami`/caixa-teia");
5477        assert!(
5478            reason.contains("must not contain `` ` ``"),
5479            "reason must surface the backtick command-substitution arm, got {reason:?}"
5480        );
5481        assert!(
5482            reason.contains("command-substitution") || reason.contains("'unwise'"),
5483            "reason must name the shell-command-substitution / RFC-3986-unwise rationale, \
5484             got {reason:?}"
5485        );
5486    }
5487
5488    #[test]
5489    fn fonte_repo_fragment_fires_before_backtick_when_fragment_first() {
5490        // Cascade pin: the fragment-`#` arm and the backtick command-
5491        // substitution arm are both per-byte arms inside the same
5492        // `for &b in s.as_bytes()` loop, so the byte that appears first
5493        // in the value's byte order wins. A `:repo
5494        // "https://github.com/p/x#readme/`whoami`"` carries both `#`
5495        // and backtick; the `#` byte appears first, so the fragment-
5496        // `#` arm fires, surfacing the more self-locating diagnostic
5497        // on the byte the author pasted earliest in the URL. Mirrors
5498        // the peer cascade discipline
5499        // `fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first`
5500        // pins on the prior `:repo` byte-class arm.
5501        let d = dep_with_fonte(DepSource::Git {
5502            repo: "https://github.com/pleme-io/caixa-teia#readme/`whoami`".into(),
5503            tag: Some("v0.1.0".into()),
5504            rev: None,
5505            branch: None,
5506        });
5507        let err = d.validate().unwrap_err();
5508        let DepError::FonteRepoShape { reason, .. } = err else {
5509            panic!("expected FonteRepoShape, got other variant");
5510        };
5511        assert!(
5512            reason.contains("must not contain `#`"),
5513            "reason must surface the fragment-`#` arm (fires before backtick when `#` byte \
5514             appears first in value), got {reason:?}"
5515        );
5516    }
5517
5518    #[test]
5519    fn fonte_repo_shell_redirection_fires_before_backtick_when_redirection_first() {
5520        // Cascade pin: the shell-redirection `<` / `>` arm and the
5521        // backtick command-substitution arm are both per-byte arms
5522        // inside the same `for &b in s.as_bytes()` loop, so the byte
5523        // that appears first in the value's byte order wins. A `:repo
5524        // "https://github.com/p/x>build.log/`whoami`"` carries both
5525        // `>` and backtick; the `>` byte appears first, so the
5526        // shell-redirection arm fires, surfacing the more self-
5527        // locating diagnostic on the byte the author pasted earliest
5528        // in the URL. Pins the natural-order cascade so a future
5529        // reorder of the per-byte arms surfaces here.
5530        let d = dep_with_fonte(DepSource::Git {
5531            repo: "https://github.com/pleme-io/caixa-teia>build.log/`whoami`".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 { reason, .. } = err else {
5538            panic!("expected FonteRepoShape, got other variant");
5539        };
5540        assert!(
5541            reason.contains("must not contain `>`"),
5542            "reason must surface the shell-redirection `>` arm (fires before backtick when \
5543             `>` byte appears first in value), got {reason:?}"
5544        );
5545    }
5546
5547    #[test]
5548    fn fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first() {
5549        // Cascade pin: the fragment-`#` arm and the shell-redirection
5550        // `<` / `>` arm are both per-byte arms inside the same
5551        // `for &b in s.as_bytes()` loop, so the byte that appears
5552        // first in the value's byte order wins. A `:repo
5553        // "https://github.com/p/x#readme>build.log"` carries both
5554        // `#` and `>`; the `#` byte appears first, so the fragment-
5555        // `#` arm fires, surfacing the more self-locating diagnostic
5556        // on the byte the author pasted earliest in the URL. Mirrors
5557        // the peer cascade discipline
5558        // `fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first`
5559        // pins on the prior `:repo` byte-class arm.
5560        let d = dep_with_fonte(DepSource::Git {
5561            repo: "https://github.com/pleme-io/caixa-teia#readme>build.log".into(),
5562            tag: Some("v0.1.0".into()),
5563            rev: None,
5564            branch: None,
5565        });
5566        let err = d.validate().unwrap_err();
5567        let DepError::FonteRepoShape { reason, .. } = err else {
5568            panic!("expected FonteRepoShape, got other variant");
5569        };
5570        assert!(
5571            reason.contains("must not contain `#`"),
5572            "reason must surface the fragment-`#` arm (fires before shell-redirection `>` when \
5573             `#` byte appears first in value), got {reason:?}"
5574        );
5575    }
5576
5577    #[test]
5578    fn validate_rejects_git_fonte_with_repo_carrying_shell_pipe() {
5579        // The fail-before-pass-after pin for the canonical
5580        // paste-from-shell-prompt-with-piped-pipeline footgun on
5581        // `:repo` (peer with the 124106f pipe arm on the sibling
5582        // `:caminho` path-fonte axis). An author pastes a shell
5583        // pipeline (`git clone <url> | tee build.log`,
5584        // `git ls-remote <url> | head`) into the `:repo` slot,
5585        // forgetting to trim the `| <consumer>` tail. Until this arm
5586        // landed the value silently passed every prior arm (no
5587        // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5588        // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, doesn't start
5589        // with `-` or `:`); RFC 3986 §2 lists the pipe byte in the
5590        // 'unwise' set and the WHATWG URL spec's fragment percent-
5591        // encode set maps `|` → `%7C` on the wire, so the byte rides
5592        // verbatim into the lacre's per-dep BLAKE3 closure but is
5593        // silently rewritten or rejected at libcurl's URL-parser
5594        // layer — two authors whose values differ only in their pipe
5595        // tail (`|tee build.log` vs nothing) resolve to the byte-
5596        // identical upstream `git clone` but lock to two distinct
5597        // lacres, defeating the THEORY.md §V.2 render-determinism
5598        // contract. Peer with the `:caminho` axis's
5599        // `FonteCaminhoShellPipe` arm (124106f) on the sibling path-
5600        // fonte axis, and `is_gateway_api_http_path`'s eleven-byte
5601        // RFC-3986-reserved set on `:entrada :paths`.
5602        let d = dep_with_fonte(DepSource::Git {
5603            repo: "https://github.com/pleme-io/caixa-teia|tee build.log".into(),
5604            tag: Some("v0.1.0".into()),
5605            rev: None,
5606            branch: None,
5607        });
5608        let err = d.validate().unwrap_err();
5609        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5610            panic!("expected FonteRepoShape, got other variant");
5611        };
5612        assert_eq!(nome, "caixa-teia");
5613        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia|tee build.log");
5614        assert!(
5615            reason.contains("must not contain `|`"),
5616            "reason must surface the shell-pipe arm, got {reason:?}"
5617        );
5618        assert!(
5619            reason.contains("pipe") || reason.contains("'unwise'"),
5620            "reason must name the shell-pipe / RFC-3986-unwise rationale, got {reason:?}"
5621        );
5622    }
5623
5624    #[test]
5625    fn fonte_repo_fragment_fires_before_pipe_when_fragment_first() {
5626        // Cascade pin: the fragment-`#` arm and the pipe arm are both
5627        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5628        // so the byte that appears first in the value's byte order
5629        // wins. A `:repo "https://github.com/p/x#readme|tee"` carries
5630        // both `#` and `|`; the `#` byte appears first, so the
5631        // fragment-`#` arm fires, surfacing the more self-locating
5632        // diagnostic on the byte the author pasted earliest in the
5633        // URL. Mirrors the peer cascade discipline
5634        // `fonte_repo_fragment_fires_before_backtick_when_fragment_first`
5635        // pins on the prior `:repo` byte-class arm.
5636        let d = dep_with_fonte(DepSource::Git {
5637            repo: "https://github.com/pleme-io/caixa-teia#readme|tee".into(),
5638            tag: Some("v0.1.0".into()),
5639            rev: None,
5640            branch: None,
5641        });
5642        let err = d.validate().unwrap_err();
5643        let DepError::FonteRepoShape { reason, .. } = err else {
5644            panic!("expected FonteRepoShape, got other variant");
5645        };
5646        assert!(
5647            reason.contains("must not contain `#`"),
5648            "reason must surface the fragment-`#` arm (fires before pipe when `#` byte \
5649             appears first in value), got {reason:?}"
5650        );
5651    }
5652
5653    #[test]
5654    fn fonte_repo_backtick_fires_before_pipe_when_backtick_first() {
5655        // Cascade pin: the backtick arm and the pipe arm are both per-
5656        // byte arms inside the same `for &b in s.as_bytes()` loop, so
5657        // the byte that appears first in the value's byte order wins.
5658        // A `:repo "https://github.com/p/x/`whoami`|tee"` carries both
5659        // `` ` `` and `|`; the backtick byte appears first, so the
5660        // backtick arm fires, surfacing the more self-locating
5661        // diagnostic on the byte the author pasted earliest in the
5662        // URL. Pins the natural-order cascade so a future reorder of
5663        // the per-byte arms surfaces here.
5664        let d = dep_with_fonte(DepSource::Git {
5665            repo: "https://github.com/pleme-io/caixa-teia/`whoami`|tee".into(),
5666            tag: Some("v0.1.0".into()),
5667            rev: None,
5668            branch: None,
5669        });
5670        let err = d.validate().unwrap_err();
5671        let DepError::FonteRepoShape { reason, .. } = err else {
5672            panic!("expected FonteRepoShape, got other variant");
5673        };
5674        assert!(
5675            reason.contains("must not contain `` ` ``"),
5676            "reason must surface the backtick arm (fires before pipe when `` ` `` byte \
5677             appears first in value), got {reason:?}"
5678        );
5679    }
5680
5681    #[test]
5682    fn validate_rejects_git_fonte_with_repo_carrying_shell_command_separator() {
5683        // The fail-before-pass-after pin for the canonical
5684        // paste-from-shell-prompt-with-sequential-command-tail footgun
5685        // on `:repo` (peer with the 05c358e `;` arm on the sibling
5686        // `:caminho` path-fonte axis). An author pastes a shell
5687        // one-liner that chained a cleanup tail after the URL
5688        // (`git clone <url>; rm -rf build`, `git ls-remote <url>;
5689        // echo done`) into the `:repo` slot, forgetting to trim the
5690        // `; <cmd>` tail. Until this arm landed the value silently
5691        // passed every prior `is_git_repo_url` arm (no whitespace, no
5692        // control chars, no non-ASCII, no `#`, no `?`, no `\`, no
5693        // `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, doesn't start with
5694        // `-` or `:`); RFC 3986 §2 lists `;` in the 'sub-delims' /
5695        // reserved set and the WHATWG URL spec's fragment percent-
5696        // encode set maps `;` → `%3B` on the wire, so the byte rides
5697        // verbatim into the lacre's per-dep BLAKE3 closure but is
5698        // silently rewritten at libcurl's URL-parser layer — two
5699        // authors whose values differ only in their sequential-command
5700        // tail (`; rm -rf build` vs nothing) resolve to the byte-
5701        // identical upstream `git clone` but lock to two distinct
5702        // lacres, defeating the THEORY.md §V.2 render-determinism
5703        // contract. Peer with the `:caminho` axis's
5704        // `FonteCaminhoShellSemicolon` arm (05c358e) on the sibling
5705        // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5706        // byte RFC-3986-reserved set on `:entrada :paths`.
5707        let d = dep_with_fonte(DepSource::Git {
5708            repo: "https://github.com/pleme-io/caixa-teia; rm -rf build".into(),
5709            tag: Some("v0.1.0".into()),
5710            rev: None,
5711            branch: None,
5712        });
5713        let err = d.validate().unwrap_err();
5714        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5715            panic!("expected FonteRepoShape, got other variant");
5716        };
5717        assert_eq!(nome, "caixa-teia");
5718        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia; rm -rf build");
5719        assert!(
5720            reason.contains("must not contain `;`"),
5721            "reason must surface the shell-command-separator arm, got {reason:?}"
5722        );
5723        assert!(
5724            reason.contains("sequential-command") || reason.contains("'sub-delims'"),
5725            "reason must name the shell-command-separator / RFC-3986-sub-delims \
5726             rationale, got {reason:?}"
5727        );
5728    }
5729
5730    #[test]
5731    fn fonte_repo_fragment_fires_before_semicolon_when_fragment_first() {
5732        // Cascade pin: the fragment-`#` arm and the semicolon arm are
5733        // both per-byte arms inside the same `for &b in s.as_bytes()`
5734        // loop, so the byte that appears first in the value's byte
5735        // order wins. A `:repo "https://github.com/p/x#readme; rm"`
5736        // carries both `#` and `;`; the `#` byte appears first, so the
5737        // fragment-`#` arm fires, surfacing the more self-locating
5738        // diagnostic on the byte the author pasted earliest in the URL.
5739        // Mirrors the peer cascade discipline
5740        // `fonte_repo_fragment_fires_before_pipe_when_fragment_first`
5741        // pins on the prior `:repo` byte-class arm.
5742        let d = dep_with_fonte(DepSource::Git {
5743            repo: "https://github.com/pleme-io/caixa-teia#readme; rm".into(),
5744            tag: Some("v0.1.0".into()),
5745            rev: None,
5746            branch: None,
5747        });
5748        let err = d.validate().unwrap_err();
5749        let DepError::FonteRepoShape { reason, .. } = err else {
5750            panic!("expected FonteRepoShape, got other variant");
5751        };
5752        assert!(
5753            reason.contains("must not contain `#`"),
5754            "reason must surface the fragment-`#` arm (fires before semicolon when `#` \
5755             byte appears first in value), got {reason:?}"
5756        );
5757    }
5758
5759    #[test]
5760    fn fonte_repo_pipe_fires_before_semicolon_when_pipe_first() {
5761        // Cascade pin: the pipe arm and the semicolon arm are both
5762        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5763        // so the byte that appears first in the value's byte order
5764        // wins. A `:repo "https://github.com/p/x|tee; rm"` carries
5765        // both `|` and `;`; the `|` byte appears first, so the
5766        // pipe arm fires, surfacing the more self-locating diagnostic
5767        // on the byte the author pasted earliest in the URL. Pins the
5768        // natural-order cascade so a future reorder of the per-byte
5769        // arms surfaces here.
5770        let d = dep_with_fonte(DepSource::Git {
5771            repo: "https://github.com/pleme-io/caixa-teia|tee; rm".into(),
5772            tag: Some("v0.1.0".into()),
5773            rev: None,
5774            branch: None,
5775        });
5776        let err = d.validate().unwrap_err();
5777        let DepError::FonteRepoShape { reason, .. } = err else {
5778            panic!("expected FonteRepoShape, got other variant");
5779        };
5780        assert!(
5781            reason.contains("must not contain `|`"),
5782            "reason must surface the pipe arm (fires before semicolon when `|` byte \
5783             appears first in value), got {reason:?}"
5784        );
5785    }
5786
5787    #[test]
5788    fn validate_rejects_git_fonte_with_repo_carrying_shell_background() {
5789        // The fail-before-pass-after pin for the canonical
5790        // paste-from-shell-prompt-with-background-launch-tail footgun
5791        // on `:repo` (peer with the e12e4f3 `&` arm on the sibling
5792        // `:caminho` path-fonte axis). An author pastes a shell one-
5793        // liner that detached the clone into the background
5794        // (`git clone <url> & sleep 1`, `git clone <url> && cd …`)
5795        // into the `:repo` slot, forgetting to trim the `& <cmd>` /
5796        // `&& <cmd>` tail. Until this arm landed the value silently
5797        // passed every prior `is_git_repo_url` arm (no whitespace,
5798        // no control chars, no non-ASCII, no `#`, no `?`, no `\`,
5799        // no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
5800        // doesn't start with `-` or `:`); RFC 3986 §2 lists `&` in
5801        // the 'sub-delims' / reserved set and the WHATWG URL spec's
5802        // fragment percent-encode set maps `&` → `%26` on the wire,
5803        // so the byte rides verbatim into the lacre's per-dep
5804        // BLAKE3 closure but is silently rewritten at libcurl's
5805        // URL-parser layer — two authors whose values differ only
5806        // in their background-launch tail (`& sleep 1` vs nothing)
5807        // resolve to the byte-identical upstream `git clone` but
5808        // lock to two distinct lacres, defeating the THEORY.md
5809        // §V.2 render-determinism contract. Peer with the
5810        // `:caminho` axis's `FonteCaminhoShellBackground` arm
5811        // (e12e4f3) on the sibling path-fonte axis, and
5812        // `is_gateway_api_http_path`'s eleven-byte RFC-3986-
5813        // reserved set on `:entrada :paths`.
5814        let d = dep_with_fonte(DepSource::Git {
5815            repo: "https://github.com/pleme-io/caixa-teia&sleep".into(),
5816            tag: Some("v0.1.0".into()),
5817            rev: None,
5818            branch: None,
5819        });
5820        let err = d.validate().unwrap_err();
5821        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5822            panic!("expected FonteRepoShape, got other variant");
5823        };
5824        assert_eq!(nome, "caixa-teia");
5825        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia&sleep");
5826        assert!(
5827            reason.contains("must not contain `&`"),
5828            "reason must surface the shell-background / logical-AND arm, got {reason:?}"
5829        );
5830        assert!(
5831            reason.contains("background-task") || reason.contains("'sub-delims'"),
5832            "reason must name the shell-background / RFC-3986-sub-delims rationale, \
5833             got {reason:?}"
5834        );
5835    }
5836
5837    #[test]
5838    fn validate_rejects_git_fonte_with_repo_carrying_logical_and() {
5839        // The fail-before-pass-after pin for the symmetric `&&`
5840        // logical-AND build-chain paste footgun: an author pastes
5841        // a `git clone <url> && cd <repo>` build-chain one-liner
5842        // and forgets to trim the `&& <cmd>` tail. The `&&` shape
5843        // is the same `&` byte twice in a row; the per-byte arm
5844        // fires on the first `&` it sees. Pinned separately from
5845        // the single-`&` background-launch shape so a future
5846        // diagnostic-surface change that special-cased the
5847        // doubled-byte form surfaces here.
5848        let d = dep_with_fonte(DepSource::Git {
5849            repo: "github:pleme-io/caixa-teia&&echo".into(),
5850            tag: Some("v0.1.0".into()),
5851            rev: None,
5852            branch: None,
5853        });
5854        let err = d.validate().unwrap_err();
5855        let DepError::FonteRepoShape { reason, .. } = err else {
5856            panic!("expected FonteRepoShape, got other variant");
5857        };
5858        assert!(
5859            reason.contains("must not contain `&`"),
5860            "reason must surface the shell-background / logical-AND arm on the doubled-`&&` \
5861             shape too, got {reason:?}"
5862        );
5863    }
5864
5865    #[test]
5866    fn fonte_repo_fragment_fires_before_background_when_fragment_first() {
5867        // Cascade pin: the fragment-`#` arm and the background-`&`
5868        // arm are both per-byte arms inside the same `for &b in
5869        // s.as_bytes()` loop, so the byte that appears first in the
5870        // value's byte order wins. A `:repo
5871        // "https://github.com/p/x#readme & sleep"` carries both `#`
5872        // and `&`; the `#` byte appears first, so the fragment-`#`
5873        // arm fires, surfacing the more self-locating diagnostic on
5874        // the byte the author pasted earliest in the URL. Mirrors
5875        // the peer cascade discipline
5876        // `fonte_repo_fragment_fires_before_semicolon_when_fragment_first`
5877        // on the prior `:repo` byte-class arm.
5878        let d = dep_with_fonte(DepSource::Git {
5879            repo: "https://github.com/pleme-io/caixa-teia#readme&sleep".into(),
5880            tag: Some("v0.1.0".into()),
5881            rev: None,
5882            branch: None,
5883        });
5884        let err = d.validate().unwrap_err();
5885        let DepError::FonteRepoShape { reason, .. } = err else {
5886            panic!("expected FonteRepoShape, got other variant");
5887        };
5888        assert!(
5889            reason.contains("must not contain `#`"),
5890            "reason must surface the fragment-`#` arm (fires before background-`&` when `#` \
5891             byte appears first in value), got {reason:?}"
5892        );
5893    }
5894
5895    #[test]
5896    fn fonte_repo_semicolon_fires_before_background_when_semicolon_first() {
5897        // Cascade pin: the semicolon arm and the background-`&` arm
5898        // are both per-byte arms inside the same `for &b in
5899        // s.as_bytes()` loop, so the byte that appears first in the
5900        // value's byte order wins. A `:repo
5901        // "https://github.com/p/x; rm & sleep"` carries both `;` and
5902        // `&`; the `;` byte appears first, so the semicolon arm
5903        // fires, surfacing the more self-locating diagnostic on the
5904        // byte the author pasted earliest in the URL. Pins the
5905        // natural-order cascade so a future reorder of the per-byte
5906        // arms surfaces here.
5907        let d = dep_with_fonte(DepSource::Git {
5908            repo: "https://github.com/pleme-io/caixa-teia;rm&sleep".into(),
5909            tag: Some("v0.1.0".into()),
5910            rev: None,
5911            branch: None,
5912        });
5913        let err = d.validate().unwrap_err();
5914        let DepError::FonteRepoShape { reason, .. } = err else {
5915            panic!("expected FonteRepoShape, got other variant");
5916        };
5917        assert!(
5918            reason.contains("must not contain `;`"),
5919            "reason must surface the semicolon arm (fires before background-`&` when `;` \
5920             byte appears first in value), got {reason:?}"
5921        );
5922    }
5923
5924    #[test]
5925    fn validate_rejects_git_fonte_with_repo_carrying_shell_variable_expansion() {
5926        // The fail-before-pass-after pin for the canonical
5927        // paste-from-shell-prompt-with-unsubstituted-variable footgun
5928        // on `:repo` (peer with the f4efe9c `$` arm on the sibling
5929        // `:caminho` path-fonte axis). An author pastes a shell one-
5930        // liner that referenced an environment variable
5931        // (`git clone https://github.com/$ORG/x`, `git clone
5932        // github:$USER/repo`) into the `:repo` slot, forgetting to
5933        // substitute the literal value at author time. Until this arm
5934        // landed the value silently passed every prior
5935        // `is_git_repo_url` arm (no whitespace, no control chars, no
5936        // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
5937        // no `` ` ``, no `|`, no `;`, no `&`, doesn't start with `-`
5938        // or `:`); RFC 3986 §2 lists `$` in the 'sub-delims' /
5939        // reserved set and the WHATWG URL spec's fragment percent-
5940        // encode set maps `$` → `%24` on the wire, so the byte rides
5941        // verbatim into the lacre's per-dep BLAKE3 closure but is
5942        // silently rewritten at libcurl's URL-parser layer — two
5943        // authors whose values differ only in their `$VAR` /
5944        // `${VAR}` / `$(cmd)` expansion tail resolve to the byte-
5945        // identical upstream `git clone` but lock to two distinct
5946        // lacres, defeating the THEORY.md §V.2 render-determinism
5947        // contract. Beyond determinism, the value is a structural
5948        // host-layout leak: two authors with the same `:repo` slot
5949        // but different `$ORG` / `$HOME` / `$WORKSPACE` resolve
5950        // different upstreams. Peer with the `:caminho` axis's
5951        // `FonteCaminhoVarExpansion` arm (f4efe9c) on the sibling
5952        // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5953        // byte RFC-3986-reserved set on `:entrada :paths`.
5954        let d = dep_with_fonte(DepSource::Git {
5955            repo: "https://github.com/$ORG/caixa-teia".into(),
5956            tag: Some("v0.1.0".into()),
5957            rev: None,
5958            branch: None,
5959        });
5960        let err = d.validate().unwrap_err();
5961        let DepError::FonteRepoShape { nome, repo, reason } = err else {
5962            panic!("expected FonteRepoShape, got other variant");
5963        };
5964        assert_eq!(nome, "caixa-teia");
5965        assert_eq!(repo, "https://github.com/$ORG/caixa-teia");
5966        assert!(
5967            reason.contains("must not contain `$`"),
5968            "reason must surface the shell-variable-expansion arm, got {reason:?}"
5969        );
5970        assert!(
5971            reason.contains("variable-expansion") || reason.contains("'sub-delims'"),
5972            "reason must name the shell-variable-expansion / RFC-3986-sub-delims \
5973             rationale, got {reason:?}"
5974        );
5975    }
5976
5977    #[test]
5978    fn validate_rejects_git_fonte_with_repo_carrying_braced_variable_expansion() {
5979        // The fail-before-pass-after pin for the symmetric POSIX-
5980        // shell braced `${VAR}` expansion paste footgun: an author
5981        // pastes a CI-manifest line `git clone
5982        // https://github.com/${WORKSPACE}/x` (the canonical GitHub
5983        // Actions / GitLab CI / Drone shape) and forgets to
5984        // substitute the literal value. The `${...}` shape is the
5985        // same `$` byte at the leading position of the expansion;
5986        // the per-byte arm fires on the `$`. Pinned separately from
5987        // the bare-`$VAR` shape so a future diagnostic-surface
5988        // change that special-cased the braced form surfaces here.
5989        let d = dep_with_fonte(DepSource::Git {
5990            repo: "https://github.com/${WORKSPACE}/caixa-teia".into(),
5991            tag: Some("v0.1.0".into()),
5992            rev: None,
5993            branch: None,
5994        });
5995        let err = d.validate().unwrap_err();
5996        let DepError::FonteRepoShape { reason, .. } = err else {
5997            panic!("expected FonteRepoShape, got other variant");
5998        };
5999        assert!(
6000            reason.contains("must not contain `$`"),
6001            "reason must surface the shell-variable-expansion arm on the braced `${{...}}` \
6002             shape too, got {reason:?}"
6003        );
6004    }
6005
6006    #[test]
6007    fn fonte_repo_fragment_fires_before_var_expansion_when_fragment_first() {
6008        // Cascade pin: the fragment-`#` arm and the var-expansion-`$`
6009        // arm are both per-byte arms inside the same `for &b in
6010        // s.as_bytes()` loop, so the byte that appears first in the
6011        // value's byte order wins. A `:repo
6012        // "https://github.com/p/x#readme$HOME"` carries both `#` and
6013        // `$`; the `#` byte appears first, so the fragment-`#` arm
6014        // fires, surfacing the more self-locating diagnostic on the
6015        // byte the author pasted earliest in the URL. Mirrors the
6016        // peer cascade discipline
6017        // `fonte_repo_fragment_fires_before_background_when_fragment_first`
6018        // on the prior `:repo` byte-class arm.
6019        let d = dep_with_fonte(DepSource::Git {
6020            repo: "https://github.com/pleme-io/caixa-teia#readme$HOME".into(),
6021            tag: Some("v0.1.0".into()),
6022            rev: None,
6023            branch: None,
6024        });
6025        let err = d.validate().unwrap_err();
6026        let DepError::FonteRepoShape { reason, .. } = err else {
6027            panic!("expected FonteRepoShape, got other variant");
6028        };
6029        assert!(
6030            reason.contains("must not contain `#`"),
6031            "reason must surface the fragment-`#` arm (fires before var-expansion-`$` when \
6032             `#` byte appears first in value), got {reason:?}"
6033        );
6034    }
6035
6036    #[test]
6037    fn fonte_repo_background_fires_before_var_expansion_when_background_first() {
6038        // Cascade pin: the background-`&` arm and the
6039        // var-expansion-`$` arm are both per-byte arms inside the
6040        // same `for &b in s.as_bytes()` loop, so the byte that
6041        // appears first in the value's byte order wins. A `:repo
6042        // "https://github.com/p/x&sleep$HOME"` carries both `&` and
6043        // `$`; the `&` byte appears first, so the background arm
6044        // fires, surfacing the more self-locating diagnostic on the
6045        // byte the author pasted earliest in the URL. Pins the
6046        // natural-order cascade so a future reorder of the per-byte
6047        // arms surfaces here — `$` is the most recent byte-class arm,
6048        // so the cascade-pin sweep extends to cover every immediately
6049        // prior byte arm (`#`, `&`) firing first when ordered ahead
6050        // of `$` in the value.
6051        let d = dep_with_fonte(DepSource::Git {
6052            repo: "https://github.com/pleme-io/caixa-teia&sleep$HOME".into(),
6053            tag: Some("v0.1.0".into()),
6054            rev: None,
6055            branch: None,
6056        });
6057        let err = d.validate().unwrap_err();
6058        let DepError::FonteRepoShape { reason, .. } = err else {
6059            panic!("expected FonteRepoShape, got other variant");
6060        };
6061        assert!(
6062            reason.contains("must not contain `&`"),
6063            "reason must surface the background-`&` arm (fires before var-expansion-`$` when \
6064             `&` byte appears first in value), got {reason:?}"
6065        );
6066    }
6067
6068    #[test]
6069    fn validate_rejects_git_fonte_with_repo_carrying_shell_glob_wildcard() {
6070        // The fail-before-pass-after pin for the canonical
6071        // paste-from-shell-prompt glob footgun on `:repo` (peer with
6072        // the cf9034b `*` / `?` arm on the sibling `:caminho`
6073        // path-fonte axis). An author pastes a shell one-liner that
6074        // referenced a glob expansion (`ls
6075        // github.com/pleme-io/caixa-*`, `git clone
6076        // github:pleme-io/caixa-*`) into the `:repo` slot, forgetting
6077        // to substitute the literal repo name. Until this arm landed
6078        // the `*` byte silently passed every prior `is_git_repo_url`
6079        // arm (no whitespace, no control chars, no non-ASCII, no `#`,
6080        // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`,
6081        // no `;`, no `&`, no `$`, doesn't start with `-` or `:`); RFC
6082        // 3986 §2 lists `*` in the 'sub-delims' / reserved set and
6083        // the WHATWG URL spec's special-query percent-encode set maps
6084        // `*` → `%2A` on the wire, so the byte rides verbatim into
6085        // the lacre's per-dep BLAKE3 closure but is silently
6086        // rewritten at libcurl's URL-parser layer — two authors
6087        // whose values differ only in their asterisk presence
6088        // resolve to the byte-identical upstream `git clone` but
6089        // lock to two distinct lacres, defeating the THEORY.md §V.2
6090        // render-determinism contract. Peer with the `:caminho`
6091        // axis's `FonteCaminhoShellGlob` arm (cf9034b) on the
6092        // sibling path-fonte axis, and the `is_git_ref_name`
6093        // refspec-wildcard cascade on the `:fonte :tag` / `:branch`
6094        // axes.
6095        let d = dep_with_fonte(DepSource::Git {
6096            repo: "https://github.com/pleme-io/caixa-*".into(),
6097            tag: Some("v0.1.0".into()),
6098            rev: None,
6099            branch: None,
6100        });
6101        let err = d.validate().unwrap_err();
6102        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6103            panic!("expected FonteRepoShape, got other variant");
6104        };
6105        assert_eq!(nome, "caixa-teia");
6106        assert_eq!(repo, "https://github.com/pleme-io/caixa-*");
6107        assert!(
6108            reason.contains("must not contain `*`"),
6109            "reason must surface the shell-glob arm, got {reason:?}"
6110        );
6111        assert!(
6112            reason.contains("pathname-expansion") || reason.contains("'sub-delims'"),
6113            "reason must name the shell-glob / pathname-expansion / \
6114             RFC-3986-sub-delims rationale, got {reason:?}"
6115        );
6116    }
6117
6118    #[test]
6119    fn validate_rejects_git_fonte_with_repo_carrying_recursive_shell_glob() {
6120        // The fail-before-pass-after pin for the symmetric bash
6121        // `globstar` recursive-glob paste footgun: an author pastes
6122        // a `ls github.com/pleme-io/**/x` (the canonical
6123        // `globstar`-shopt-enabled recursive-listing tail) into the
6124        // `:repo` slot. The `**` shape is two `*` bytes adjacent;
6125        // the per-byte arm fires on the first `*`. Pinned
6126        // separately from the single-`*` shape so a future
6127        // diagnostic-surface change that special-cased the
6128        // double-`*` form surfaces here.
6129        let d = dep_with_fonte(DepSource::Git {
6130            repo: "https://github.com/pleme-io/**/caixa-teia".into(),
6131            tag: Some("v0.1.0".into()),
6132            rev: None,
6133            branch: None,
6134        });
6135        let err = d.validate().unwrap_err();
6136        let DepError::FonteRepoShape { reason, .. } = err else {
6137            panic!("expected FonteRepoShape, got other variant");
6138        };
6139        assert!(
6140            reason.contains("must not contain `*`"),
6141            "reason must surface the shell-glob arm on the `**` recursive-glob shape too, \
6142             got {reason:?}"
6143        );
6144    }
6145
6146    #[test]
6147    fn fonte_repo_fragment_fires_before_glob_when_fragment_first() {
6148        // Cascade pin: the fragment-`#` arm and the glob-`*` arm are
6149        // both per-byte arms inside the same `for &b in s.as_bytes()`
6150        // loop, so the byte that appears first in the value's byte
6151        // order wins. A `:repo
6152        // "https://github.com/p/x#readme*tail"` carries both `#` and
6153        // `*`; the `#` byte appears first, so the fragment-`#` arm
6154        // fires, surfacing the more self-locating diagnostic on the
6155        // byte the author pasted earliest in the URL. Mirrors the
6156        // peer cascade discipline
6157        // `fonte_repo_fragment_fires_before_var_expansion_when_fragment_first`
6158        // on the prior `:repo` byte-class arm.
6159        let d = dep_with_fonte(DepSource::Git {
6160            repo: "https://github.com/pleme-io/caixa-teia#readme*tail".into(),
6161            tag: Some("v0.1.0".into()),
6162            rev: None,
6163            branch: None,
6164        });
6165        let err = d.validate().unwrap_err();
6166        let DepError::FonteRepoShape { reason, .. } = err else {
6167            panic!("expected FonteRepoShape, got other variant");
6168        };
6169        assert!(
6170            reason.contains("must not contain `#`"),
6171            "reason must surface the fragment-`#` arm (fires before glob-`*` when `#` byte \
6172             appears first in value), got {reason:?}"
6173        );
6174    }
6175
6176    #[test]
6177    fn fonte_repo_var_expansion_fires_before_glob_when_var_expansion_first() {
6178        // Cascade pin: the var-expansion-`$` arm and the glob-`*`
6179        // arm are both per-byte arms inside the same `for &b in
6180        // s.as_bytes()` loop, so the byte that appears first in the
6181        // value's byte order wins. A `:repo
6182        // "https://github.com/p/$ORG-*"` carries both `$` and `*`;
6183        // the `$` byte appears first, so the var-expansion arm
6184        // fires, surfacing the more self-locating diagnostic on the
6185        // byte the author pasted earliest in the URL. Pins the
6186        // natural-order cascade so a future reorder of the per-byte
6187        // arms surfaces here — `*` is the most recent byte-class
6188        // arm, so the cascade-pin sweep extends to cover the
6189        // immediately prior `$` byte arm firing first when ordered
6190        // ahead of `*` in the value.
6191        let d = dep_with_fonte(DepSource::Git {
6192            repo: "https://github.com/pleme-io/$ORG-caixa-*".into(),
6193            tag: Some("v0.1.0".into()),
6194            rev: None,
6195            branch: None,
6196        });
6197        let err = d.validate().unwrap_err();
6198        let DepError::FonteRepoShape { reason, .. } = err else {
6199            panic!("expected FonteRepoShape, got other variant");
6200        };
6201        assert!(
6202            reason.contains("must not contain `$`"),
6203            "reason must surface the var-expansion-`$` arm (fires before glob-`*` when `$` \
6204             byte appears first in value), got {reason:?}"
6205        );
6206    }
6207
6208    #[test]
6209    fn validate_rejects_git_fonte_with_repo_carrying_subshell_open_paren() {
6210        // The fail-before-pass-after pin for the canonical paste-from-
6211        // shell-prompt subshell-grouping footgun on `:repo`. An author
6212        // pastes a doc / README snippet carrying a regex-alternation
6213        // grouping shape (`https://github.com/(foo|bar)/repo`) or a
6214        // dynamic-config-substitution wrapper (`$(<cmd>)`) into the
6215        // `:repo` slot, forgetting to substitute one literal org name.
6216        // Until this arm landed the `(` byte silently passed every
6217        // prior `is_git_repo_url` arm (no whitespace, no control
6218        // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6219        // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no
6220        // `*`, doesn't start with `-` or `:`); RFC 3986 §2 lists `(`
6221        // / `)` in the 'sub-delims' / reserved set, and the WHATWG
6222        // URL spec's special-query percent-encode set maps `(` →
6223        // `%28` and `)` → `%29` on the wire, so the byte rides
6224        // verbatim into the lacre's per-dep BLAKE3 closure but is
6225        // silently rewritten at libcurl's URL-parser layer —
6226        // defeating the THEORY.md §V.2 render-determinism contract on
6227        // the same axis the prior twelve byte-class arms close.
6228        let d = dep_with_fonte(DepSource::Git {
6229            repo: "https://github.com/(foo|bar)/caixa-teia".into(),
6230            tag: Some("v0.1.0".into()),
6231            rev: None,
6232            branch: None,
6233        });
6234        let err = d.validate().unwrap_err();
6235        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6236            panic!("expected FonteRepoShape, got other variant");
6237        };
6238        assert_eq!(nome, "caixa-teia");
6239        assert_eq!(repo, "https://github.com/(foo|bar)/caixa-teia");
6240        assert!(
6241            reason.contains("must not contain `(`"),
6242            "reason must surface the subshell-open-paren arm, got {reason:?}"
6243        );
6244        assert!(
6245            reason.contains("subshell-grouping") || reason.contains("'sub-delims'"),
6246            "reason must name the shell-subshell-grouping / RFC-3986-sub-delims rationale, \
6247             got {reason:?}"
6248        );
6249    }
6250
6251    #[test]
6252    fn validate_rejects_git_fonte_with_repo_carrying_subshell_close_paren() {
6253        // The symmetric arm pin on the closing `)` byte: an author
6254        // pastes a `$(date)` command-substitution wrapper or a
6255        // regex-alternation `(foo|bar)` tail into the `:repo` slot.
6256        // Pinned separately from the opening `(` shape so a future
6257        // diagnostic-surface change that only checked one boundary
6258        // surfaces here. The `(` byte appears earlier in the
6259        // canonical regex / subshell wrapper so the per-byte loop
6260        // fires on `(` first; this test exercises a `:repo` value
6261        // carrying only the closing `)` byte (no opening paren) so
6262        // the `)` arm fires directly — pinning the byte-class arm
6263        // independent of order.
6264        let d = dep_with_fonte(DepSource::Git {
6265            repo: "github:pleme-io/caixa-teia)tail".into(),
6266            tag: Some("v0.1.0".into()),
6267            rev: None,
6268            branch: None,
6269        });
6270        let err = d.validate().unwrap_err();
6271        let DepError::FonteRepoShape { reason, .. } = err else {
6272            panic!("expected FonteRepoShape, got other variant");
6273        };
6274        assert!(
6275            reason.contains("must not contain `)`"),
6276            "reason must surface the subshell-close-paren arm on the bare `)` shape, \
6277             got {reason:?}"
6278        );
6279    }
6280
6281    #[test]
6282    fn fonte_repo_fragment_fires_before_subshell_when_fragment_first() {
6283        // Cascade pin: the fragment-`#` arm and the subshell-`(` arm
6284        // are both per-byte arms inside the same `for &b in
6285        // s.as_bytes()` loop, so the byte that appears first in the
6286        // value's byte order wins. A `:repo
6287        // "https://github.com/p/x#readme(tail)"` carries both `#` and
6288        // `(`; the `#` byte appears first, so the fragment-`#` arm
6289        // fires, surfacing the more self-locating diagnostic on the
6290        // byte the author pasted earliest in the URL. Mirrors the
6291        // peer cascade discipline
6292        // `fonte_repo_fragment_fires_before_glob_when_fragment_first`
6293        // on the prior `:repo` byte-class arm.
6294        let d = dep_with_fonte(DepSource::Git {
6295            repo: "https://github.com/pleme-io/caixa-teia#readme(tail)".into(),
6296            tag: Some("v0.1.0".into()),
6297            rev: None,
6298            branch: None,
6299        });
6300        let err = d.validate().unwrap_err();
6301        let DepError::FonteRepoShape { reason, .. } = err else {
6302            panic!("expected FonteRepoShape, got other variant");
6303        };
6304        assert!(
6305            reason.contains("must not contain `#`"),
6306            "reason must surface the fragment-`#` arm (fires before subshell-`(` when `#` \
6307             byte appears first in value), got {reason:?}"
6308        );
6309    }
6310
6311    #[test]
6312    fn fonte_repo_glob_fires_before_subshell_when_glob_first() {
6313        // Cascade pin: the glob-`*` arm (the immediate-predecessor
6314        // byte-class arm, 3902a9a) and the subshell-`(` arm are both
6315        // per-byte arms inside the same `for &b in s.as_bytes()`
6316        // loop, so the byte that appears first in the value's byte
6317        // order wins. A `:repo
6318        // "https://github.com/p/x-*-(date)"` carries both `*` and
6319        // `(`; the `*` byte appears first, so the glob arm fires,
6320        // surfacing the more self-locating diagnostic on the byte
6321        // the author pasted earliest in the URL. Pins the natural-
6322        // order cascade so a future reorder of the per-byte arms
6323        // surfaces here — `(` is the most recent byte-class arm,
6324        // so the cascade-pin sweep extends to cover the immediately
6325        // prior `*` byte arm firing first when ordered ahead of `(`
6326        // in the value.
6327        let d = dep_with_fonte(DepSource::Git {
6328            repo: "https://github.com/pleme-io/caixa-teia-*-(date)".into(),
6329            tag: Some("v0.1.0".into()),
6330            rev: None,
6331            branch: None,
6332        });
6333        let err = d.validate().unwrap_err();
6334        let DepError::FonteRepoShape { reason, .. } = err else {
6335            panic!("expected FonteRepoShape, got other variant");
6336        };
6337        assert!(
6338            reason.contains("must not contain `*`"),
6339            "reason must surface the glob-`*` arm (fires before subshell-`(` when `*` byte \
6340             appears first in value), got {reason:?}"
6341        );
6342    }
6343
6344    #[test]
6345    fn validate_rejects_git_fonte_with_repo_carrying_shell_double_quote() {
6346        // The fail-before-pass-after pin for the canonical paste-from-
6347        // doc-shell-quoting footgun on `:repo`. An author copies a
6348        // README quick-start snippet (`$ git clone "https://github.com/
6349        // foo/bar"`) and keeps the surrounding double-quote bytes when
6350        // pasting into the `:repo` slot — the doc wraps the URL in
6351        // double quotes so the shell doesn't re-lex metachars inside,
6352        // but the typed slot is itself a byte-level string parser, not
6353        // a shell context, so the quote bytes ride into the value
6354        // verbatim. Until this arm landed the `"` byte silently passed
6355        // every prior `is_git_repo_url` arm (no whitespace, no control
6356        // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6357        // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`,
6358        // no `(`/`)`, doesn't start with `-` or `:`); RFC 3986 §2 lists
6359        // `"` in the strict four-byte 'delims' subset (with `<`, `>`,
6360        // `` ` ``) every URL parser is required to refuse or percent-
6361        // encode, and the WHATWG URL spec's 'C0 control percent-encode
6362        // set' maps `"` → `%22` on the wire, so the byte rides verbatim
6363        // into the lacre's per-dep BLAKE3 closure but is silently
6364        // rewritten at libcurl's URL-parser layer, defeating the
6365        // THEORY.md §V.2 render-determinism contract.
6366        let d = dep_with_fonte(DepSource::Git {
6367            repo: "\"https://github.com/pleme-io/caixa-teia\"".into(),
6368            tag: Some("v0.1.0".into()),
6369            rev: None,
6370            branch: None,
6371        });
6372        let err = d.validate().unwrap_err();
6373        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6374            panic!("expected FonteRepoShape, got other variant");
6375        };
6376        assert_eq!(nome, "caixa-teia");
6377        assert_eq!(repo, "\"https://github.com/pleme-io/caixa-teia\"");
6378        assert!(
6379            reason.contains("must not contain `\"`"),
6380            "reason must surface the shell-double-quote arm, got {reason:?}"
6381        );
6382        assert!(
6383            reason.contains("double-quote") || reason.contains("'delims'"),
6384            "reason must name the shell-double-quote / RFC-3986-delims rationale, \
6385             got {reason:?}"
6386        );
6387    }
6388
6389    #[test]
6390    fn validate_rejects_git_fonte_with_repo_carrying_stray_trailing_double_quote() {
6391        // The symmetric stray-quote tail pin: an author pastes only a
6392        // closing `"` from a shell-history line like `git clone
6393        // "https://github.com/foo/bar" && cd …` (the trim went too
6394        // far in one direction but not the other) into the `:repo`
6395        // slot. Pinned separately from the wrapped-quote shape so a
6396        // future diagnostic-surface change that only checked one
6397        // boundary (only leading, only trailing, only paired) surfaces
6398        // here — the per-byte arm fires anywhere `"` appears.
6399        let d = dep_with_fonte(DepSource::Git {
6400            repo: "github:pleme-io/caixa-teia\"".into(),
6401            tag: Some("v0.1.0".into()),
6402            rev: None,
6403            branch: None,
6404        });
6405        let err = d.validate().unwrap_err();
6406        let DepError::FonteRepoShape { reason, .. } = err else {
6407            panic!("expected FonteRepoShape, got other variant");
6408        };
6409        assert!(
6410            reason.contains("must not contain `\"`"),
6411            "reason must surface the shell-double-quote arm on the trailing-`\"` shape, \
6412             got {reason:?}"
6413        );
6414    }
6415
6416    #[test]
6417    fn fonte_repo_fragment_fires_before_double_quote_when_fragment_first() {
6418        // Cascade pin: the fragment-`#` arm and the double-quote arm
6419        // are both per-byte arms inside the same `for &b in
6420        // s.as_bytes()` loop, so the byte that appears first in the
6421        // value's byte order wins. A `:repo
6422        // "https://github.com/p/x#readme\"tail"` carries both `#` and
6423        // `"`; the `#` byte appears first, so the fragment-`#` arm
6424        // fires, surfacing the more self-locating diagnostic on the
6425        // byte the author pasted earliest in the URL.
6426        let d = dep_with_fonte(DepSource::Git {
6427            repo: "https://github.com/pleme-io/caixa-teia#readme\"tail".into(),
6428            tag: Some("v0.1.0".into()),
6429            rev: None,
6430            branch: None,
6431        });
6432        let err = d.validate().unwrap_err();
6433        let DepError::FonteRepoShape { reason, .. } = err else {
6434            panic!("expected FonteRepoShape, got other variant");
6435        };
6436        assert!(
6437            reason.contains("must not contain `#`"),
6438            "reason must surface the fragment-`#` arm (fires before double-quote when `#` \
6439             byte appears first in value), got {reason:?}"
6440        );
6441    }
6442
6443    #[test]
6444    fn fonte_repo_subshell_fires_before_double_quote_when_subshell_first() {
6445        // Cascade pin: the subshell-`(` arm (the immediate-predecessor
6446        // byte-class arm, 3b99147) and the double-quote arm are both
6447        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6448        // so the byte that appears first in the value's byte order
6449        // wins. A `:repo "github:p/x(date)\"tail"` carries both `(`
6450        // and `"`; the `(` byte appears first, so the subshell arm
6451        // fires, surfacing the more self-locating diagnostic on the
6452        // byte the author pasted earliest in the URL. Pins the natural-
6453        // order cascade so a future reorder of the per-byte arms
6454        // surfaces here — `"` is the most recent byte-class arm, so
6455        // the cascade-pin sweep extends to cover the immediately prior
6456        // `(` byte arm firing first when ordered ahead of `"` in the
6457        // value.
6458        let d = dep_with_fonte(DepSource::Git {
6459            repo: "github:pleme-io/caixa-teia(date)\"tail".into(),
6460            tag: Some("v0.1.0".into()),
6461            rev: None,
6462            branch: None,
6463        });
6464        let err = d.validate().unwrap_err();
6465        let DepError::FonteRepoShape { reason, .. } = err else {
6466            panic!("expected FonteRepoShape, got other variant");
6467        };
6468        assert!(
6469            reason.contains("must not contain `(`"),
6470            "reason must surface the subshell-`(` arm (fires before double-quote when `(` \
6471             byte appears first in value), got {reason:?}"
6472        );
6473    }
6474
6475    #[test]
6476    fn validate_rejects_git_fonte_with_repo_carrying_shell_single_quote() {
6477        // The fail-before-pass-after pin for the canonical paste-from-
6478        // doc-strong-quoting footgun on `:repo`. An author copies a
6479        // security-conscious README quick-start snippet (`$ git clone
6480        // 'https://github.com/foo/bar'`) and keeps the surrounding
6481        // single-quote bytes when pasting into the `:repo` slot — the
6482        // doc strong-quotes the URL so the shell suppresses every form
6483        // of expansion on the bytes inside (no `$`, no backtick, no
6484        // glob, no word-splitting), but the typed slot is itself a
6485        // byte-level string parser, not a shell context, so the quote
6486        // bytes ride into the value verbatim. Until this arm landed the
6487        // `'` byte silently passed every prior `is_git_repo_url` arm
6488        // (no whitespace, no control chars, no non-ASCII, no `#`, no
6489        // `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no
6490        // `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`, doesn't start
6491        // with `-` or `:`); RFC 3986 §2.2 lists `'` in the 'sub-delims'
6492        // set, peer with the `\"` 'delims' double-quote arm and the
6493        // partner ASCII shell-string-delimiter byte every byte-level
6494        // string parser sharing a value-shape with a shell argument
6495        // must refuse on a URL-shaped slot.
6496        let d = dep_with_fonte(DepSource::Git {
6497            repo: "'https://github.com/pleme-io/caixa-teia'".into(),
6498            tag: Some("v0.1.0".into()),
6499            rev: None,
6500            branch: None,
6501        });
6502        let err = d.validate().unwrap_err();
6503        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6504            panic!("expected FonteRepoShape, got other variant");
6505        };
6506        assert_eq!(nome, "caixa-teia");
6507        assert_eq!(repo, "'https://github.com/pleme-io/caixa-teia'");
6508        assert!(
6509            reason.contains("must not contain `'`"),
6510            "reason must surface the shell-single-quote arm, got {reason:?}"
6511        );
6512        assert!(
6513            reason.contains("single-quote") || reason.contains("strong-quote"),
6514            "reason must name the shell-single-quote / strong-quote rationale, \
6515             got {reason:?}"
6516        );
6517    }
6518
6519    #[test]
6520    fn validate_rejects_git_fonte_with_repo_carrying_english_apostrophe() {
6521        // The symmetric English-typography pin: an author writes
6522        // `:repo "github:p/repo's-fork"` (the possessive-form paste-
6523        // from-prose idiom every README / commit-message / chat-thread
6524        // reference to a repo carries) expecting the substrate to
6525        // coerce it to a kebab-case slug — but the byte rides into the
6526        // lacre verbatim. Pinned separately from the wrapped-quote
6527        // shape so a future diagnostic-surface change that only checked
6528        // the boundary positions (only leading, only trailing, only
6529        // paired) surfaces here — the per-byte arm fires anywhere `'`
6530        // appears in the value.
6531        let d = dep_with_fonte(DepSource::Git {
6532            repo: "github:pleme-io/repo's-fork".into(),
6533            tag: Some("v0.1.0".into()),
6534            rev: None,
6535            branch: None,
6536        });
6537        let err = d.validate().unwrap_err();
6538        let DepError::FonteRepoShape { reason, .. } = err else {
6539            panic!("expected FonteRepoShape, got other variant");
6540        };
6541        assert!(
6542            reason.contains("must not contain `'`"),
6543            "reason must surface the shell-single-quote arm on the mid-string \
6544             apostrophe shape, got {reason:?}"
6545        );
6546    }
6547
6548    #[test]
6549    fn fonte_repo_fragment_fires_before_single_quote_when_fragment_first() {
6550        // Cascade pin: the fragment-`#` arm and the single-quote arm
6551        // are both per-byte arms inside the same `for &b in
6552        // s.as_bytes()` loop, so the byte that appears first in the
6553        // value's byte order wins. A `:repo
6554        // "https://github.com/p/x#readme'tail"` carries both `#` and
6555        // `'`; the `#` byte appears first, so the fragment-`#` arm
6556        // fires, surfacing the more self-locating diagnostic on the
6557        // byte the author pasted earliest in the URL.
6558        let d = dep_with_fonte(DepSource::Git {
6559            repo: "https://github.com/pleme-io/caixa-teia#readme'tail".into(),
6560            tag: Some("v0.1.0".into()),
6561            rev: None,
6562            branch: None,
6563        });
6564        let err = d.validate().unwrap_err();
6565        let DepError::FonteRepoShape { reason, .. } = err else {
6566            panic!("expected FonteRepoShape, got other variant");
6567        };
6568        assert!(
6569            reason.contains("must not contain `#`"),
6570            "reason must surface the fragment-`#` arm (fires before single-quote when `#` \
6571             byte appears first in value), got {reason:?}"
6572        );
6573    }
6574
6575    #[test]
6576    fn fonte_repo_double_quote_fires_before_single_quote_when_double_quote_first() {
6577        // Cascade pin: the double-quote-`"` arm (the immediate-predecessor
6578        // byte-class arm, 4267d8b) and the single-quote arm are both
6579        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6580        // so the byte that appears first in the value's byte order
6581        // wins. A `:repo "github:p/x\"mid'tail"` carries both `"` and
6582        // `'`; the `"` byte appears first, so the double-quote arm
6583        // fires, surfacing the more self-locating diagnostic on the
6584        // byte the author pasted earliest in the URL. Pins the natural-
6585        // order cascade so a future reorder of the per-byte arms
6586        // surfaces here — `'` is the most recent byte-class arm, so
6587        // the cascade-pin sweep extends to cover the immediately prior
6588        // `"` byte arm firing first when ordered ahead of `'` in the
6589        // value.
6590        let d = dep_with_fonte(DepSource::Git {
6591            repo: "github:pleme-io/caixa-teia\"mid'tail".into(),
6592            tag: Some("v0.1.0".into()),
6593            rev: None,
6594            branch: None,
6595        });
6596        let err = d.validate().unwrap_err();
6597        let DepError::FonteRepoShape { reason, .. } = err else {
6598            panic!("expected FonteRepoShape, got other variant");
6599        };
6600        assert!(
6601            reason.contains("must not contain `\"`"),
6602            "reason must surface the double-quote arm (fires before single-quote when `\"` \
6603             byte appears first in value), got {reason:?}"
6604        );
6605    }
6606
6607    #[test]
6608    fn validate_rejects_git_fonte_with_repo_carrying_shell_history_expansion() {
6609        // The fail-before-pass-after pin for the canonical paste-from-
6610        // shell-history footgun on `:repo`. An author copies a `git
6611        // clone <url>!sudo make install` one-liner from a README's
6612        // quick-start snippet, intending the trailing `!sudo` as a
6613        // shell-history-expansion reference but the typed slot is itself
6614        // a byte-level string parser, not a shell context, so the byte
6615        // rides into the value verbatim. Until this arm landed the `!`
6616        // byte silently passed every prior `is_git_repo_url` arm (no
6617        // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
6618        // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6619        // no `&`, no `$`, no `*`, no `(`/`)`, no `"`, no `'`, doesn't
6620        // start with `-` or `:`); bash with the default `histexpand`
6621        // mode rewrites `!command` to the most recent history entry
6622        // beginning with `command`, the canonical RCE-class injection
6623        // vector when the byte rides into a shell argument.
6624        let d = dep_with_fonte(DepSource::Git {
6625            repo: "https://github.com/pleme-io/caixa-teia!sudo".into(),
6626            tag: Some("v0.1.0".into()),
6627            rev: None,
6628            branch: None,
6629        });
6630        let err = d.validate().unwrap_err();
6631        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6632            panic!("expected FonteRepoShape, got other variant");
6633        };
6634        assert_eq!(nome, "caixa-teia");
6635        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia!sudo");
6636        assert!(
6637            reason.contains("must not contain `!`"),
6638            "reason must surface the shell-history-expansion arm, got {reason:?}"
6639        );
6640        assert!(
6641            reason.contains("history-expansion") || reason.contains("bang"),
6642            "reason must name the shell-history-expansion / bang rationale, got {reason:?}"
6643        );
6644    }
6645
6646    #[test]
6647    fn validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference() {
6648        // The symmetric `!!` repeat-prior-command pin: an author paste-
6649        // trims a `git clone <url>` retry idiom from shell history that
6650        // expands to the previous command via `!!`. Pinned separately
6651        // from the wrapped `!command` shape so a future diagnostic-
6652        // surface change that only checked the leading or paired-bang
6653        // position surfaces here — the per-byte arm fires anywhere `!`
6654        // appears in the value.
6655        let d = dep_with_fonte(DepSource::Git {
6656            repo: "github:pleme-io/caixa-teia!!".into(),
6657            tag: Some("v0.1.0".into()),
6658            rev: None,
6659            branch: None,
6660        });
6661        let err = d.validate().unwrap_err();
6662        let DepError::FonteRepoShape { reason, .. } = err else {
6663            panic!("expected FonteRepoShape, got other variant");
6664        };
6665        assert!(
6666            reason.contains("must not contain `!`"),
6667            "reason must surface the shell-history-expansion arm on the trailing-`!!` shape, \
6668             got {reason:?}"
6669        );
6670    }
6671
6672    #[test]
6673    fn fonte_repo_fragment_fires_before_bang_when_fragment_first() {
6674        // Cascade pin: the fragment-`#` arm and the bang arm are both
6675        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6676        // so the byte that appears first in the value's byte order
6677        // wins. A `:repo "https://github.com/p/x#readme!tail"` carries
6678        // both `#` and `!`; the `#` byte appears first, so the
6679        // fragment-`#` arm fires, surfacing the more self-locating
6680        // diagnostic on the byte the author pasted earliest in the URL.
6681        let d = dep_with_fonte(DepSource::Git {
6682            repo: "https://github.com/pleme-io/caixa-teia#readme!tail".into(),
6683            tag: Some("v0.1.0".into()),
6684            rev: None,
6685            branch: None,
6686        });
6687        let err = d.validate().unwrap_err();
6688        let DepError::FonteRepoShape { reason, .. } = err else {
6689            panic!("expected FonteRepoShape, got other variant");
6690        };
6691        assert!(
6692            reason.contains("must not contain `#`"),
6693            "reason must surface the fragment-`#` arm (fires before bang when `#` byte \
6694             appears first in value), got {reason:?}"
6695        );
6696    }
6697
6698    #[test]
6699    fn fonte_repo_single_quote_fires_before_bang_when_single_quote_first() {
6700        // Cascade pin: the single-quote-`'` arm (the immediate-predecessor
6701        // byte-class arm, e7a109f) and the bang arm are both per-byte
6702        // arms inside the same `for &b in s.as_bytes()` loop, so the
6703        // byte that appears first in the value's byte order wins. A
6704        // `:repo "github:p/x'mid!tail"` carries both `'` and `!`; the
6705        // `'` byte appears first, so the single-quote arm fires,
6706        // surfacing the more self-locating diagnostic on the byte the
6707        // author pasted earliest in the URL. Pins the natural-order
6708        // cascade so a future reorder of the per-byte arms surfaces
6709        // here — `!` is the most recent byte-class arm, so the
6710        // cascade-pin sweep extends to cover the immediately prior `'`
6711        // byte arm firing first when ordered ahead of `!` in the value.
6712        let d = dep_with_fonte(DepSource::Git {
6713            repo: "github:pleme-io/caixa-teia'mid!tail".into(),
6714            tag: Some("v0.1.0".into()),
6715            rev: None,
6716            branch: None,
6717        });
6718        let err = d.validate().unwrap_err();
6719        let DepError::FonteRepoShape { reason, .. } = err else {
6720            panic!("expected FonteRepoShape, got other variant");
6721        };
6722        assert!(
6723            reason.contains("must not contain `'`"),
6724            "reason must surface the single-quote arm (fires before bang when `'` byte \
6725             appears first in value), got {reason:?}"
6726        );
6727    }
6728
6729    #[test]
6730    fn validate_rejects_git_fonte_with_repo_carrying_list_separator_comma() {
6731        // The fail-before-pass-after pin for the canonical
6732        // list-separator-belongs-to-list-grammar footgun on `:repo`.
6733        // An author copies a `git clone <a>, <b>, <c>` paste-from-CSV
6734        // one-liner from a multi-repo bootstrap doc, intending the
6735        // comma to separate multiple repo entries but the typed
6736        // `:repo` slot names *one* repo (the list-separator belongs
6737        // to the `:deps` list grammar, not to the value). Until this
6738        // arm landed the `,` byte silently passed every prior
6739        // `is_git_repo_url` arm (no whitespace, no control chars, no
6740        // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6741        // no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`, no
6742        // `(`/`)`, no `"`, no `'`, no `!`, doesn't start with `-` or
6743        // `:`); the byte rode into the lacre's per-dep content-
6744        // address and the resolver's `git clone <repo>` subprocess
6745        // invocation, where no host's repo registry resolved the
6746        // comma-bearing slug.
6747        let d = dep_with_fonte(DepSource::Git {
6748            repo: "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira".into(),
6749            tag: Some("v0.1.0".into()),
6750            rev: None,
6751            branch: None,
6752        });
6753        let err = d.validate().unwrap_err();
6754        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6755            panic!("expected FonteRepoShape, got other variant");
6756        };
6757        assert_eq!(nome, "caixa-teia");
6758        assert_eq!(
6759            repo,
6760            "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira"
6761        );
6762        assert!(
6763            reason.contains("must not contain `,`"),
6764            "reason must surface the list-separator-comma arm, got {reason:?}"
6765        );
6766        assert!(
6767            reason.contains("list-separator") || reason.contains("sub-delims"),
6768            "reason must name the list-separator / RFC-3986-sub-delims rationale, \
6769             got {reason:?}"
6770        );
6771    }
6772
6773    #[test]
6774    fn validate_rejects_git_fonte_with_repo_carrying_trailing_comma() {
6775        // The symmetric trailing-`,` paste-from-prose pin: an author
6776        // writes `:repo "github:pleme-io/caixa-feira,"` (the trailing
6777        // comma every README-prose list-of-projects sentence carries,
6778        // mistakenly retained when the slug is pasted mid-sentence)
6779        // expecting the substrate to coerce it to a kebab-case slug.
6780        // Pinned separately from the wrapped mid-token shape so a
6781        // future diagnostic-surface change that only checked the
6782        // leading or paired-comma position surfaces here — the
6783        // per-byte arm fires anywhere `,` appears in the value.
6784        let d = dep_with_fonte(DepSource::Git {
6785            repo: "github:pleme-io/caixa-feira,".into(),
6786            tag: Some("v0.1.0".into()),
6787            rev: None,
6788            branch: None,
6789        });
6790        let err = d.validate().unwrap_err();
6791        let DepError::FonteRepoShape { reason, .. } = err else {
6792            panic!("expected FonteRepoShape, got other variant");
6793        };
6794        assert!(
6795            reason.contains("must not contain `,`"),
6796            "reason must surface the list-separator-comma arm on the trailing-`,` shape, \
6797             got {reason:?}"
6798        );
6799    }
6800
6801    #[test]
6802    fn fonte_repo_fragment_fires_before_comma_when_fragment_first() {
6803        // Cascade pin: the fragment-`#` arm and the comma arm are
6804        // both per-byte arms inside the same `for &b in s.as_bytes()`
6805        // loop, so the byte that appears first in the value's byte
6806        // order wins. A `:repo "https://github.com/p/x#readme,tail"`
6807        // carries both `#` and `,`; the `#` byte appears first, so
6808        // the fragment-`#` arm fires, surfacing the more self-
6809        // locating diagnostic on the byte the author pasted earliest
6810        // in the URL.
6811        let d = dep_with_fonte(DepSource::Git {
6812            repo: "https://github.com/pleme-io/caixa-teia#readme,tail".into(),
6813            tag: Some("v0.1.0".into()),
6814            rev: None,
6815            branch: None,
6816        });
6817        let err = d.validate().unwrap_err();
6818        let DepError::FonteRepoShape { reason, .. } = err else {
6819            panic!("expected FonteRepoShape, got other variant");
6820        };
6821        assert!(
6822            reason.contains("must not contain `#`"),
6823            "reason must surface the fragment-`#` arm (fires before comma when `#` byte \
6824             appears first in value), got {reason:?}"
6825        );
6826    }
6827
6828    #[test]
6829    fn fonte_repo_bang_fires_before_comma_when_bang_first() {
6830        // Cascade pin: the bang-`!` arm (the immediate-predecessor
6831        // byte-class arm, 7d53c68) and the comma arm are both
6832        // per-byte arms inside the same `for &b in s.as_bytes()`
6833        // loop, so the byte that appears first in the value's byte
6834        // order wins. A `:repo "github:p/x!mid,tail"` carries both
6835        // `!` and `,`; the `!` byte appears first, so the bang arm
6836        // fires, surfacing the more self-locating diagnostic on the
6837        // byte the author pasted earliest in the URL. Pins the
6838        // natural-order cascade so a future reorder of the per-byte
6839        // arms surfaces here — `,` is the most recent byte-class
6840        // arm, so the cascade-pin sweep extends to cover the
6841        // immediately prior `!` byte arm firing first when ordered
6842        // ahead of `,` in the value.
6843        let d = dep_with_fonte(DepSource::Git {
6844            repo: "github:pleme-io/caixa-teia!mid,tail".into(),
6845            tag: Some("v0.1.0".into()),
6846            rev: None,
6847            branch: None,
6848        });
6849        let err = d.validate().unwrap_err();
6850        let DepError::FonteRepoShape { reason, .. } = err else {
6851            panic!("expected FonteRepoShape, got other variant");
6852        };
6853        assert!(
6854            reason.contains("must not contain `!`"),
6855            "reason must surface the bang arm (fires before comma when `!` byte \
6856             appears first in value), got {reason:?}"
6857        );
6858    }
6859
6860    #[test]
6861    fn validate_rejects_git_fonte_with_repo_carrying_shell_env_var_assignment() {
6862        // The fail-before-pass-after pin for the canonical
6863        // shell-env-var-assignment-belongs-to-shell-grammar footgun
6864        // on `:repo`. An author copies
6865        // `GIT_TERMINAL_PROMPT=0 git clone <url>` (or
6866        // `GIT_SSL_NO_VERIFY=1 git clone <url>`, `HTTPS_PROXY=…
6867        // git clone <url>`, etc. — the canonical
6868        // git-troubleshooting README idiom for a one-shot env-var
6869        // scoped to the `git clone` invocation) from a shell-prompt
6870        // one-liner, intending the `KEY=VALUE` prefix as a shell-
6871        // grammar env-var assignment but the typed `:repo` slot is
6872        // a value parser, not a shell context, so the bytes ride
6873        // into the value verbatim. Until this arm landed the `=`
6874        // byte silently passed every prior `is_git_repo_url` arm
6875        // (no whitespace, no control chars, no non-ASCII, no `#`,
6876        // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no
6877        // `|`, no `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`,
6878        // no `'`, no `!`, no `,`, doesn't start with `-` or `:`);
6879        // the byte rode into the lacre's per-dep content-address
6880        // and the resolver's `git clone <repo>` subprocess
6881        // invocation, where the upstream host's git porcelain
6882        // fetched a literal `GIT_TERMINAL_PROMPT=0 https://…`-shaped
6883        // path that no host's repo registry resolves.
6884        let d = dep_with_fonte(DepSource::Git {
6885            repo: "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia".into(),
6886            tag: Some("v0.1.0".into()),
6887            rev: None,
6888            branch: None,
6889        });
6890        let err = d.validate().unwrap_err();
6891        let DepError::FonteRepoShape { nome, repo, reason } = err else {
6892            panic!("expected FonteRepoShape, got other variant");
6893        };
6894        assert_eq!(nome, "caixa-teia");
6895        assert_eq!(
6896            repo,
6897            "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia"
6898        );
6899        // The `=` byte at position 19 of `GIT_TERMINAL_PROMPT=0 …`
6900        // appears before the ` ` byte at position 21, so the `=`
6901        // arm fires (not the whitespace arm) — both arms guard
6902        // the slot, but the per-byte for-loop scans left-to-right
6903        // and the first matching byte wins.
6904        assert!(
6905            reason.contains("must not contain `=`"),
6906            "reason must surface the equals-`=` arm on the env-var-assignment \
6907             paste shape, got {reason:?}"
6908        );
6909        assert!(
6910            reason.contains("env-var-assignment") || reason.contains("KEY=VALUE"),
6911            "reason must name the shell-env-var-assignment rationale, got {reason:?}"
6912        );
6913    }
6914
6915    #[test]
6916    fn validate_rejects_git_fonte_with_repo_carrying_gitconfig_url_key_prefix() {
6917        // The symmetric paste-from-gitconfig pin: an author copies
6918        // `url=https://github.com/p/x` from `git config --get-all
6919        // remote.origin.url` output, a `.gitconfig` `[remote
6920        // "origin"] url = https://…` ini-stanza paste, or a
6921        // `git config remote.origin.url <value>` doc snippet,
6922        // intending the `url=` prefix as the ini-key but the typed
6923        // `:repo` slot is a URL value parser, not a gitconfig
6924        // grammar. With no leading whitespace and no earlier-arm
6925        // bytes in the value, the `=` arm itself fires (rather
6926        // than cascading to the whitespace arm as in the env-var
6927        // paste shape). Pinned separately so a future diagnostic-
6928        // surface change that only checked the whitespace-leading
6929        // shape surfaces here — the per-byte arm fires anywhere
6930        // `=` appears in the value.
6931        let d = dep_with_fonte(DepSource::Git {
6932            repo: "url=https://github.com/pleme-io/caixa-feira".into(),
6933            tag: Some("v0.1.0".into()),
6934            rev: None,
6935            branch: None,
6936        });
6937        let err = d.validate().unwrap_err();
6938        let DepError::FonteRepoShape { reason, .. } = err else {
6939            panic!("expected FonteRepoShape, got other variant");
6940        };
6941        assert!(
6942            reason.contains("must not contain `=`"),
6943            "reason must surface the equals-`=` arm on the `url=…` gitconfig \
6944             paste shape, got {reason:?}"
6945        );
6946        assert!(
6947            reason.contains("key-value-separator") || reason.contains("sub-delims"),
6948            "reason must name the key-value-separator / RFC-3986-sub-delims \
6949             rationale, got {reason:?}"
6950        );
6951    }
6952
6953    #[test]
6954    fn fonte_repo_fragment_fires_before_equals_when_fragment_first() {
6955        // Cascade pin: the fragment-`#` arm and the `=` arm are
6956        // both per-byte arms inside the same `for &b in s.as_bytes()`
6957        // loop, so the byte that appears first in the value's byte
6958        // order wins. A `:repo "https://github.com/p/x#readme=tail"`
6959        // carries both `#` and `=`; the `#` byte appears first, so
6960        // the fragment-`#` arm fires, surfacing the more self-
6961        // locating diagnostic on the byte the author pasted earliest
6962        // in the URL.
6963        let d = dep_with_fonte(DepSource::Git {
6964            repo: "https://github.com/pleme-io/caixa-teia#readme=tail".into(),
6965            tag: Some("v0.1.0".into()),
6966            rev: None,
6967            branch: None,
6968        });
6969        let err = d.validate().unwrap_err();
6970        let DepError::FonteRepoShape { reason, .. } = err else {
6971            panic!("expected FonteRepoShape, got other variant");
6972        };
6973        assert!(
6974            reason.contains("must not contain `#`"),
6975            "reason must surface the fragment-`#` arm (fires before equals when \
6976             `#` byte appears first in value), got {reason:?}"
6977        );
6978    }
6979
6980    #[test]
6981    fn fonte_repo_comma_fires_before_equals_when_comma_first() {
6982        // Cascade pin: the comma-`,` arm (the immediate-predecessor
6983        // byte-class arm, 775b80e) and the `=` arm are both per-byte
6984        // arms inside the same `for &b in s.as_bytes()` loop, so
6985        // the byte that appears first in the value's byte order
6986        // wins. A `:repo "github:p/x,mid=tail"` carries both `,`
6987        // and `=`; the `,` byte appears first, so the comma arm
6988        // fires, surfacing the more self-locating diagnostic on
6989        // the byte the author pasted earliest in the URL. Pins the
6990        // natural-order cascade so a future reorder of the per-byte
6991        // arms surfaces here — `=` is the most recent byte-class
6992        // arm, so the cascade-pin sweep extends to cover the
6993        // immediately prior `,` byte arm firing first when ordered
6994        // ahead of `=` in the value.
6995        let d = dep_with_fonte(DepSource::Git {
6996            repo: "github:pleme-io/caixa-teia,mid=tail".into(),
6997            tag: Some("v0.1.0".into()),
6998            rev: None,
6999            branch: None,
7000        });
7001        let err = d.validate().unwrap_err();
7002        let DepError::FonteRepoShape { reason, .. } = err else {
7003            panic!("expected FonteRepoShape, got other variant");
7004        };
7005        assert!(
7006            reason.contains("must not contain `,`"),
7007            "reason must surface the comma arm (fires before equals when `,` byte \
7008             appears first in value), got {reason:?}"
7009        );
7010    }
7011
7012    #[test]
7013    fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_space() {
7014        // The fail-before-pass-after pin for the canonical paste-from-
7015        // browser-address-bar percent-encoded-space footgun on `:repo`.
7016        // An author copies `https://github.com/p/x%20test` from a
7017        // browser address bar (or a percent-encoded README hyperlink,
7018        // or a `curl --data-urlencode` shell-pipeline output)
7019        // intending `%20` as the URL encoding of a literal space; the
7020        // typed `:repo` slot already rejects the literal space byte
7021        // (the whitespace arm at the top of `is_git_repo_url`), so an
7022        // author trying to express "I really meant a space" reaches
7023        // for percent-encoding. Until this arm landed the `%` byte
7024        // silently passed every prior `is_git_repo_url` arm and rode
7025        // verbatim into the lacre's per-dep content-address — but
7026        // libcurl re-percent-encodes `%` to `%25` on the wire (since
7027        // `%` is reserved as the escape-sequence lead-in), so the
7028        // wire request becomes `https://github.com/p/x%2520test`, a
7029        // path the lacre's content-address never names. The classic
7030        // render-determinism violation on the encoding-mechanism axis
7031        // itself.
7032        let d = dep_with_fonte(DepSource::Git {
7033            repo: "https://github.com/pleme-io/caixa-teia%20test".into(),
7034            tag: Some("v0.1.0".into()),
7035            rev: None,
7036            branch: None,
7037        });
7038        let err = d.validate().unwrap_err();
7039        let DepError::FonteRepoShape { nome, repo, reason } = err else {
7040            panic!("expected FonteRepoShape, got other variant");
7041        };
7042        assert_eq!(nome, "caixa-teia");
7043        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia%20test");
7044        assert!(
7045            reason.contains("must not contain `%`"),
7046            "reason must surface the percent-`%` arm on the percent-encoded-space \
7047             paste shape, got {reason:?}"
7048        );
7049        assert!(
7050            reason.contains("percent-encoding") || reason.contains("%25"),
7051            "reason must name the percent-encoding / `%25` re-encoding rationale, \
7052             got {reason:?}"
7053        );
7054    }
7055
7056    #[test]
7057    fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_slash() {
7058        // The symmetric over-encoded-path-separator pin: an author
7059        // writes `:repo "https://github.com/p%2Fx"` intending the
7060        // `%2F` as the URL encoding of `/` (the canonical
7061        // paste-from-OpenAPI-spec / paste-from-percent-encoded-template
7062        // footgun every API client library and OAuth redirect-URI
7063        // documentation surfaces — the `/` is the URL-path-separator
7064        // and some templates percent-encode it to escape interpretation
7065        // as a path separator). The GitHub Smart-HTTP transport
7066        // resolves the URL's path-segment grammar before the
7067        // percent-decoding pass, so the value identifies a different
7068        // resource on the wire than the literal-`/` form the lacre's
7069        // content-address must agree with — two authors whose `:repo`
7070        // values differ only in their `/` vs `%2F` presence lock to
7071        // two distinct BLAKE3 closures for the byte-identical upstream
7072        // `git clone`. Pinned separately so a future diagnostic
7073        // surface that only catches the `%20` shape surfaces here too.
7074        let d = dep_with_fonte(DepSource::Git {
7075            repo: "https://github.com/pleme-io%2Fcaixa-teia".into(),
7076            tag: Some("v0.1.0".into()),
7077            rev: None,
7078            branch: None,
7079        });
7080        let err = d.validate().unwrap_err();
7081        let DepError::FonteRepoShape { reason, .. } = err else {
7082            panic!("expected FonteRepoShape, got other variant");
7083        };
7084        assert!(
7085            reason.contains("must not contain `%`"),
7086            "reason must surface the percent-`%` arm on the over-encoded-path \
7087             shape, got {reason:?}"
7088        );
7089        assert!(
7090            reason.contains("render-determinism") || reason.contains("BLAKE3"),
7091            "reason must name the render-determinism / BLAKE3-closure rationale, \
7092             got {reason:?}"
7093        );
7094    }
7095
7096    #[test]
7097    fn fonte_repo_fragment_fires_before_percent_when_fragment_first() {
7098        // Cascade pin: the fragment-`#` arm and the `%` arm are both
7099        // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7100        // so the byte that appears first in the value's byte order
7101        // wins. A `:repo "https://github.com/p/x#sec%20tail"` carries
7102        // both `#` and `%`; the `#` byte appears first, so the
7103        // fragment-`#` arm fires, surfacing the more self-locating
7104        // diagnostic on the byte the author pasted earliest in the URL.
7105        let d = dep_with_fonte(DepSource::Git {
7106            repo: "https://github.com/pleme-io/caixa-teia#sec%20tail".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 percent when \
7118             `#` byte appears first in value), got {reason:?}"
7119        );
7120    }
7121
7122    #[test]
7123    fn fonte_repo_equals_fires_before_percent_when_equals_first() {
7124        // Cascade pin: the equals-`=` arm (the immediate-predecessor
7125        // byte-class arm, acf99af) and the `%` arm are both per-byte
7126        // arms inside the same `for &b in s.as_bytes()` loop, so the
7127        // byte that appears first in the value's byte order wins.
7128        // A `:repo "github:p/x=mid%20tail"` carries both `=` and `%`;
7129        // the `=` byte appears first, so the equals arm fires,
7130        // surfacing the more self-locating diagnostic on the byte the
7131        // author pasted earliest in the URL. Pins the natural-order
7132        // cascade so a future reorder of the per-byte arms surfaces
7133        // here — `%` is the most recent byte-class arm, so the
7134        // cascade-pin sweep extends to cover the immediately prior
7135        // `=` byte arm firing first when ordered ahead of `%` in the
7136        // value.
7137        let d = dep_with_fonte(DepSource::Git {
7138            repo: "github:pleme-io/caixa-teia=mid%20tail".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 equals arm (fires before percent when `=` byte \
7150             appears first in value), got {reason:?}"
7151        );
7152    }
7153
7154    #[test]
7155    fn validate_rejects_git_fonte_with_repo_carrying_caret_history_substitution() {
7156        // The fail-before-pass-after pin for the canonical paste-from-
7157        // shell-history footgun on `:repo`. An author copies a
7158        // `git clone <url>` line from their terminal followed by a
7159        // bash / ksh / zsh `^typo^fix^` quick-edit-and-rerun shell-
7160        // history shorthand (the `^old^new^` form re-runs the prior
7161        // history entry with the first `old` substituted by `new`,
7162        // bash's default behavior on interactive sessions with
7163        // `set -o histexpand`), forgetting to trim the trailing
7164        // `^...^...` shell-history fragment from the URL value. The
7165        // `^` byte sits in the RFC 3986 §2 'unwise' set (peer with
7166        // `{`, `}`, `|`, `\\` — the strictest of the §2 reserved
7167        // classes), the WHATWG URL spec's 'fragment percent-encode
7168        // set' maps `^` → `%5E` on the wire, so the byte rides
7169        // verbatim into the lacre's per-dep content-address but
7170        // libcurl re-encodes it to `%5E` at `git clone` time — the
7171        // classic render-determinism violation on the same axis the
7172        // peer `%`, `=`, `,`, `!`, `'`, `"`, `(`, `)`, `*`, `$`,
7173        // `&`, `;`, `|`, backtick, `<`, `>`, `{`, `}`, `\\`, `?`,
7174        // `#` arms close.
7175        let d = dep_with_fonte(DepSource::Git {
7176            repo: "https://github.com/pleme-io/caixa-teia^typo^fix".into(),
7177            tag: Some("v0.1.0".into()),
7178            rev: None,
7179            branch: None,
7180        });
7181        let err = d.validate().unwrap_err();
7182        let DepError::FonteRepoShape { nome, repo, reason } = err else {
7183            panic!("expected FonteRepoShape, got other variant");
7184        };
7185        assert_eq!(nome, "caixa-teia");
7186        assert_eq!(repo, "https://github.com/pleme-io/caixa-teia^typo^fix");
7187        assert!(
7188            reason.contains("must not contain `^`"),
7189            "reason must surface the caret-`^` arm on the paste-from-shell-history \
7190             shape, got {reason:?}"
7191        );
7192        assert!(
7193            reason.contains("history-substitution") || reason.contains("%5E"),
7194            "reason must name the shell-history-substitution / `%5E` wire-encoding \
7195             rationale, got {reason:?}"
7196        );
7197    }
7198
7199    #[test]
7200    fn validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor() {
7201        // The symmetric paste-from-doc-grep-pipeline footgun: an
7202        // author writes `:repo "github:p/^archived"` after copying a
7203        // `grep '^archived'` regex-anchor / negation idiom from a
7204        // doc / README quick-listing snippet, expecting the substrate
7205        // to coerce it to a literal repo name. The byte rides
7206        // verbatim into the lacre's per-dep content-address and
7207        // diverges from the byte-identical literal `archived` form
7208        // every other author authored — the canonical render-
7209        // determinism violation pin on the second footgun shape the
7210        // caret-`^` arm closes.
7211        let d = dep_with_fonte(DepSource::Git {
7212            repo: "github:pleme-io/^archived".into(),
7213            tag: Some("v0.1.0".into()),
7214            rev: None,
7215            branch: None,
7216        });
7217        let err = d.validate().unwrap_err();
7218        let DepError::FonteRepoShape { reason, .. } = err else {
7219            panic!("expected FonteRepoShape, got other variant");
7220        };
7221        assert!(
7222            reason.contains("must not contain `^`"),
7223            "reason must surface the caret-`^` arm on the regex-anchor shape, \
7224             got {reason:?}"
7225        );
7226        assert!(
7227            reason.contains("render-determinism") || reason.contains("BLAKE3"),
7228            "reason must name the render-determinism / BLAKE3-closure rationale, \
7229             got {reason:?}"
7230        );
7231    }
7232
7233    #[test]
7234    fn fonte_repo_percent_fires_before_caret_when_percent_first() {
7235        // Cascade pin: the `%` arm (the immediate-predecessor byte-
7236        // class arm, a323db8) and the `^` arm are both per-byte arms
7237        // inside the same `for &b in s.as_bytes()` loop, so the byte
7238        // that appears first in the value's byte order wins. A
7239        // `:repo "https://github.com/p/x%20mid^tail"` carries both
7240        // `%` and `^`; the `%` byte appears first, so the percent
7241        // arm fires, surfacing the more self-locating diagnostic on
7242        // the byte the author pasted earliest in the URL. Pins the
7243        // natural-order cascade so a future reorder of the per-byte
7244        // arms surfaces here — `^` is the most recent byte-class arm,
7245        // so the cascade-pin sweep extends to cover the immediately
7246        // prior `%` byte arm firing first when ordered ahead of `^`
7247        // in the value.
7248        let d = dep_with_fonte(DepSource::Git {
7249            repo: "https://github.com/pleme-io/caixa-teia%20mid^tail".into(),
7250            tag: Some("v0.1.0".into()),
7251            rev: None,
7252            branch: None,
7253        });
7254        let err = d.validate().unwrap_err();
7255        let DepError::FonteRepoShape { reason, .. } = err else {
7256            panic!("expected FonteRepoShape, got other variant");
7257        };
7258        assert!(
7259            reason.contains("must not contain `%`"),
7260            "reason must surface the percent arm (fires before caret when `%` byte \
7261             appears first in value), got {reason:?}"
7262        );
7263    }
7264
7265    #[test]
7266    fn validate_rejects_git_fonte_with_repo_missing_colon_separator() {
7267        // The "I dropped the scheme" footgun — `:repo "pleme-io/caixa-teia"`
7268        // (no `github:` prefix, no scheme). Every documented form
7269        // carries a `:` (`github:`, `https://`, `ssh://`, `git://`,
7270        // `file://`, or `git@host:path`); a bare `org/repo` is
7271        // ambiguous (`git clone` reads as a relative filesystem path
7272        // rather than the GitHub-shorthand expansion the author
7273        // probably intended) and the gate rejects the shape upstream.
7274        let d = dep_with_fonte(DepSource::Git {
7275            repo: "pleme-io/caixa-teia".into(),
7276            tag: Some("v0.1.0".into()),
7277            rev: None,
7278            branch: None,
7279        });
7280        let err = d.validate().unwrap_err();
7281        let DepError::FonteRepoShape { reason, .. } = err else {
7282            panic!("expected FonteRepoShape, got other variant");
7283        };
7284        assert!(
7285            reason.contains("must contain a `:`"),
7286            "reason must surface the missing-`:` arm, got {reason:?}"
7287        );
7288        assert!(
7289            reason.contains("github:"),
7290            "reason must name the canonical `github:` shorthand prefix, got {reason:?}"
7291        );
7292    }
7293
7294    #[test]
7295    fn validate_rejects_git_fonte_with_repo_leading_colon() {
7296        // The "empty scheme" footgun — `:repo ":foo"` has a zero-length
7297        // scheme that no git porcelain entry-point accepts. Pinned
7298        // separately from the missing-`:` arm because a value with a
7299        // leading `:` does technically contain a `:` separator; the
7300        // shape gate rejects on a dedicated arm so the diagnostic
7301        // names the specific footgun.
7302        let d = dep_with_fonte(DepSource::Git {
7303            repo: ":pleme-io/caixa-teia".into(),
7304            tag: Some("v0.1.0".into()),
7305            rev: None,
7306            branch: None,
7307        });
7308        let err = d.validate().unwrap_err();
7309        let DepError::FonteRepoShape { reason, .. } = err else {
7310            panic!("expected FonteRepoShape, got other variant");
7311        };
7312        assert!(
7313            reason.contains("must not start with `:`"),
7314            "reason must surface the leading-`:` arm, got {reason:?}"
7315        );
7316    }
7317
7318    #[test]
7319    fn validate_rejects_git_fonte_with_repo_too_long() {
7320        // The cap arm — a `:repo` value longer than
7321        // [`crate::render::GIT_REPO_URL_MAX_LEN`] (2048) bytes is
7322        // structurally untenable on every realistic landing site (the
7323        // resolver's `git clone` invocation, the future M4 CR
7324        // materializer's per-dep `repo:` axis); a value of that length
7325        // is almost certainly a paste-from-binary slug.
7326        let too_long = format!(
7327            "github:pleme-io/{}",
7328            "x".repeat(crate::render::GIT_REPO_URL_MAX_LEN)
7329        );
7330        let d = dep_with_fonte(DepSource::Git {
7331            repo: too_long.clone(),
7332            tag: Some("v0.1.0".into()),
7333            rev: None,
7334            branch: None,
7335        });
7336        let err = d.validate().unwrap_err();
7337        let DepError::FonteRepoShape { reason, .. } = err else {
7338            panic!("expected FonteRepoShape, got other variant");
7339        };
7340        assert!(
7341            reason.contains("2048"),
7342            "reason must name the cap, got {reason:?}"
7343        );
7344    }
7345
7346    #[test]
7347    fn validate_accepts_canonical_git_fonte_repo_shapes() {
7348        // The positive-control sweep: every documented author shape on
7349        // the `:fonte :repo` axis ([`crate::DepSource::Git`] doc comment)
7350        // must pass the value-shape gate. Pinned so a future tightening
7351        // (e.g. forbidding `http://` in favor of `https://`-only) surfaces
7352        // here as a structural decision. Each form is exercised with the
7353        // same canonical `:tag` pin so only the `:repo` axis varies.
7354        for repo in [
7355            // The pleme-io registry-shorthand convention — `github:org/repo`.
7356            "github:pleme-io/caixa-teia",
7357            // Other host-aliased shorthands (the resolver's pluggable
7358            // host-prefix table).
7359            "gitlab:pleme-io/caixa-teia",
7360            "codeberg:pleme-io/caixa-teia",
7361            "sourcehut:~pleme-io/caixa-teia",
7362            // Full HTTPS URL with and without `.git` suffix.
7363            "https://github.com/pleme-io/caixa-teia",
7364            "https://github.com/pleme-io/caixa-teia.git",
7365            // HTTP (rare; dev / mirror).
7366            "http://example.com/pleme-io/caixa-teia.git",
7367            // SSH URL.
7368            "ssh://git@github.com/pleme-io/caixa-teia.git",
7369            "ssh://git@git.example.com:2222/pleme-io/caixa-teia.git",
7370            // Scp-style SSH — the canonical `git@host:path` short form.
7371            "git@github.com:pleme-io/caixa-teia.git",
7372            "git@git.example.com:team/private.git",
7373            // Anonymous git protocol.
7374            "git://git.example.com/pleme-io/caixa-teia.git",
7375            // Local file URL (dev path).
7376            "file:///tmp/caixa-teia",
7377        ] {
7378            let d = dep_with_fonte(DepSource::Git {
7379                repo: repo.into(),
7380                tag: Some("v0.1.0".into()),
7381                rev: None,
7382                branch: None,
7383            });
7384            d.validate()
7385                .unwrap_or_else(|e| panic!("canonical repo {repo:?} must validate, got {e:?}"));
7386        }
7387    }
7388
7389    #[test]
7390    fn fonte_repo_empty_takes_precedence_over_shape() {
7391        // Order pin: the existing `FonteRepoEmpty` diagnostic (narrower
7392        // diagnostic; doesn't try to parse the URL shape) fires before
7393        // the new `FonteRepoShape` per-axis gate, so an empty `:repo`
7394        // keeps its narrower error message. Mirrors
7395        // `fonte_repo_empty_fires_before_pin_missing` (already pinned)
7396        // on the ordering layer.
7397        let d = dep_with_fonte(DepSource::Git {
7398            repo: String::new(),
7399            tag: Some("v0.1.0".into()),
7400            rev: None,
7401            branch: None,
7402        });
7403        let err = d.validate().unwrap_err();
7404        assert!(
7405            matches!(err, DepError::FonteRepoEmpty { .. }),
7406            "got {err:?}"
7407        );
7408    }
7409
7410    #[test]
7411    fn fonte_repo_shape_fires_before_pin_missing() {
7412        // Order pin: a malformed `:repo` value on a dep with no pin set
7413        // surfaces the `:repo` shape diagnostic (the more self-locating
7414        // axis — the `:repo` is the load-bearing identity of the source;
7415        // a missing pin is downstream from "do we even know the repo")
7416        // rather than collapsing onto the pin-missing diagnostic. The
7417        // shape gate runs inline before the pin enumeration in
7418        // `DepSource::validate`.
7419        let d = dep_with_fonte(DepSource::Git {
7420            repo: "pleme-io/caixa-teia".into(), // missing `:` separator
7421            tag: None,
7422            rev: None,
7423            branch: None,
7424        });
7425        let err = d.validate().unwrap_err();
7426        assert!(
7427            matches!(err, DepError::FonteRepoShape { .. }),
7428            "got {err:?}"
7429        );
7430    }
7431
7432    #[test]
7433    fn fonte_repo_shape_diagnostic_carries_offending_repo_verbatim() {
7434        // The diagnostic-shape pin: the error names the offending
7435        // `:repo` value verbatim plus a non-empty parser-shaped `reason`
7436        // so the author can grep their caixa.lisp without re-running
7437        // the build. Mirrors the diagnostic-shape sweep on every prior
7438        // value-shape gate (3f9d7a0, 6cbb900, c7d05ec, e70d213, be07fd5).
7439        let d = dep_with_fonte(DepSource::Git {
7440            repo: "pleme-io/caixa-teia".into(),
7441            tag: Some("v0.1.0".into()),
7442            rev: None,
7443            branch: None,
7444        });
7445        let err = d.validate().unwrap_err();
7446        let DepError::FonteRepoShape { nome, repo, reason } = err else {
7447            panic!("expected FonteRepoShape, got other variant");
7448        };
7449        assert_eq!(nome, "caixa-teia");
7450        assert_eq!(repo, "pleme-io/caixa-teia");
7451        assert!(
7452            !reason.is_empty(),
7453            "FonteRepoShape `reason` must carry the predicate's wording verbatim"
7454        );
7455    }
7456
7457    #[test]
7458    fn validate_rejects_git_fonte_with_no_pin() {
7459        // The fail-before-pass-after pin for the canonical
7460        // `(:tipo git :repo "github:pleme-io/x")` shape with no
7461        // :tag/:rev/:branch — until this gate landed the resolver's
7462        // ResolveError::MissingPin surfaced at fetch time, far from the
7463        // source caixa.lisp. The new gate moves the check to validate
7464        // time and names the offending dep.
7465        let d = dep_with_fonte(DepSource::Git {
7466            repo: "github:pleme-io/caixa-teia".into(),
7467            tag: None,
7468            rev: None,
7469            branch: None,
7470        });
7471        let err = d.validate().unwrap_err();
7472        assert!(
7473            matches!(err, DepError::FontePinMissing { ref nome } if nome == "caixa-teia"),
7474            "got {err:?}"
7475        );
7476    }
7477
7478    #[test]
7479    fn validate_rejects_git_fonte_with_ambiguous_tag_and_branch() {
7480        // The canonical "pin drift" footgun: an author writes
7481        // `:tag "v1"` and later adds `:branch "main"` without removing
7482        // the :tag, and the resolver silently picks :tag (precedence
7483        // :rev > :tag > :branch). The :branch was dropped with no
7484        // diagnostic. The gate now rejects multi-pin shapes so the
7485        // author makes the precedence explicit at the source.
7486        let d = dep_with_fonte(DepSource::Git {
7487            repo: "github:pleme-io/caixa-teia".into(),
7488            tag: Some("v0.1.0".into()),
7489            rev: None,
7490            branch: Some("main".into()),
7491        });
7492        let err = d.validate().unwrap_err();
7493        let DepError::FontePinAmbiguous { nome, pins } = err else {
7494            panic!("expected FontePinAmbiguous");
7495        };
7496        assert_eq!(nome, "caixa-teia");
7497        assert!(pins.contains(":tag"));
7498        assert!(pins.contains(":branch"));
7499        assert!(!pins.contains(":rev"));
7500    }
7501
7502    #[test]
7503    fn validate_rejects_git_fonte_with_ambiguous_tag_and_rev() {
7504        // Sibling arm of the pin-drift footgun: :tag + :rev set
7505        // simultaneously. Pinned separately so a future relaxation
7506        // that only catches the (:tag, :branch) pair surfaces here.
7507        let d = dep_with_fonte(DepSource::Git {
7508            repo: "github:pleme-io/caixa-teia".into(),
7509            tag: Some("v0.1.0".into()),
7510            rev: Some("c0ffee".into()),
7511            branch: None,
7512        });
7513        let err = d.validate().unwrap_err();
7514        let DepError::FontePinAmbiguous { nome, pins } = err else {
7515            panic!("expected FontePinAmbiguous");
7516        };
7517        assert_eq!(nome, "caixa-teia");
7518        assert!(pins.contains(":tag"));
7519        assert!(pins.contains(":rev"));
7520    }
7521
7522    #[test]
7523    fn validate_rejects_git_fonte_with_all_three_pins() {
7524        // The maximal ambiguity case — every pin axis set. Pinned so a
7525        // future relaxation that only catches pairs surfaces here. The
7526        // diagnostic must enumerate every offending axis so the author
7527        // sees the full set, not just the first match.
7528        let d = dep_with_fonte(DepSource::Git {
7529            repo: "github:pleme-io/caixa-teia".into(),
7530            tag: Some("v0.1.0".into()),
7531            rev: Some("c0ffee".into()),
7532            branch: Some("main".into()),
7533        });
7534        let err = d.validate().unwrap_err();
7535        let DepError::FontePinAmbiguous { nome, pins } = err else {
7536            panic!("expected FontePinAmbiguous");
7537        };
7538        assert_eq!(nome, "caixa-teia");
7539        assert!(pins.contains(":tag"));
7540        assert!(pins.contains(":rev"));
7541        assert!(pins.contains(":branch"));
7542    }
7543
7544    #[test]
7545    fn validate_rejects_git_fonte_with_empty_tag_pin() {
7546        // The empty-pin arm: exactly one pin axis is `Some(_)`, but its
7547        // inner string is empty. Distinct from FontePinMissing (where
7548        // every axis is None) — pinned separately so a future
7549        // tightening collapsing them surfaces here as a structural
7550        // decision.
7551        let d = dep_with_fonte(DepSource::Git {
7552            repo: "github:pleme-io/caixa-teia".into(),
7553            tag: Some(String::new()),
7554            rev: None,
7555            branch: None,
7556        });
7557        let err = d.validate().unwrap_err();
7558        let DepError::FontePinEmpty { nome, pin } = err else {
7559            panic!("expected FontePinEmpty");
7560        };
7561        assert_eq!(nome, "caixa-teia");
7562        assert_eq!(pin, ":tag");
7563    }
7564
7565    #[test]
7566    fn validate_rejects_git_fonte_with_empty_rev_pin() {
7567        // Sibling arm — the empty-pin diagnostic names which axis
7568        // carries the empty value, so the author's grep target is
7569        // unambiguous.
7570        let d = dep_with_fonte(DepSource::Git {
7571            repo: "github:pleme-io/caixa-teia".into(),
7572            tag: None,
7573            rev: Some(String::new()),
7574            branch: None,
7575        });
7576        let err = d.validate().unwrap_err();
7577        let DepError::FontePinEmpty { nome, pin } = err else {
7578            panic!("expected FontePinEmpty");
7579        };
7580        assert_eq!(nome, "caixa-teia");
7581        assert_eq!(pin, ":rev");
7582    }
7583
7584    #[test]
7585    fn validate_rejects_path_fonte_with_empty_caminho() {
7586        // The fail-before-pass-after pin for `(:tipo path :caminho "")`:
7587        // until this gate landed the resolver's
7588        // ResolveError::MissingPath surfaced with `path: PathBuf("")` at
7589        // fetch time — not actionable. The new gate moves the check to
7590        // validate time and names the offending dep.
7591        let d = dep_with_fonte(DepSource::Path {
7592            caminho: String::new(),
7593        });
7594        let err = d.validate().unwrap_err();
7595        assert!(
7596            matches!(err, DepError::FonteCaminhoEmpty { ref nome } if nome == "caixa-teia"),
7597            "got {err:?}"
7598        );
7599    }
7600
7601    #[test]
7602    fn validate_rejects_path_fonte_with_absolute_caminho() {
7603        // The fail-before-pass-after pin for the absolute-`:caminho`
7604        // shape: `(:tipo path :caminho "/home/me/work/caixa-teia")`.
7605        // Until this gate landed an absolute `:caminho` silently
7606        // passed validate; the lacre pipeline embedded the
7607        // host-specific filesystem path verbatim in its
7608        // content-address (`conteudo: format!("path:{caminho}")`,
7609        // caixa-resolver/src/resolve.rs:189), so the BLAKE3 closure
7610        // differed per machine — the build succeeded but two CI
7611        // runners with different `${HOME}` layouts emitted two
7612        // distinct lacres for the byte-identical caixa, silently
7613        // breaking the THEORY.md §V.2 render-determinism contract
7614        // far from the source caixa.lisp. The new gate moves the
7615        // check to validate time and names the offending dep +
7616        // caminho verbatim.
7617        let d = dep_with_fonte(DepSource::Path {
7618            caminho: "/home/me/work/caixa-teia".into(),
7619        });
7620        let err = d.validate().unwrap_err();
7621        let DepError::FonteCaminhoAbsolute { nome, caminho } = err else {
7622            panic!("expected FonteCaminhoAbsolute, got other variant");
7623        };
7624        assert_eq!(nome, "caixa-teia");
7625        assert_eq!(caminho, "/home/me/work/caixa-teia");
7626    }
7627
7628    #[test]
7629    fn validate_accepts_path_fonte_with_parent_escape_caminho() {
7630        // The canonical sibling-workspace dep form
7631        // (`:caminho "../caixa-teia"`) remains accepted. The
7632        // absolute-path gate above is specifically narrower than the
7633        // shared [`crate::render::is_sandboxed_relative_path`]
7634        // predicate (which additionally forbids `..` traversal): a
7635        // local-path dep's canonical author surface is the in-tree
7636        // sibling-workspace path, so a full sandboxed-relative-path
7637        // lift would structurally reject every legitimate path-fonte
7638        // dep. Pinned so a future tightening to the full predicate
7639        // surfaces here as a structural decision, not a silent break.
7640        let d = dep_with_fonte(DepSource::Path {
7641            caminho: "../caixa-teia".into(),
7642        });
7643        d.validate().unwrap();
7644    }
7645
7646    #[test]
7647    fn validate_accepts_path_fonte_with_deeply_nested_relative_caminho() {
7648        // A multi-segment relative `:caminho`
7649        // (`"vendor/forks/caixa-teia"`) remains accepted — the
7650        // absolute-path gate brackets the host-layout-leaking shape
7651        // at the leading-`/` boundary only; every relative shape past
7652        // the empty arm continues to pass. Pinned alongside the
7653        // `..`-traversal positive control so a future tightening
7654        // surfaces the full set of legitimate relative forms here
7655        // rather than at a downstream consumer.
7656        let d = dep_with_fonte(DepSource::Path {
7657            caminho: "vendor/forks/caixa-teia".into(),
7658        });
7659        d.validate().unwrap();
7660    }
7661
7662    #[test]
7663    fn validate_rejects_path_fonte_with_tilde_prefix_caminho() {
7664        // The fail-before-pass-after pin for the tilde-expansion
7665        // `:caminho` shape: `(:tipo path :caminho "~/work/caixa-teia")`.
7666        // Until this gate landed the b94fd83 absolute arm let `~/foo`
7667        // through (`Path::is_absolute` returns false on a leading `~`
7668        // — the tilde is a shell-expansion convention, not a POSIX
7669        // path component), so the lacre embedded the value verbatim
7670        // and the resolver folded it through `Path::join` without
7671        // expansion, looking for a literal `./~/work/caixa-teia`
7672        // subdirectory and failing at resolve time with a
7673        // `No such file or directory` error far from the source
7674        // caixa.lisp. The new gate moves the check to validate time
7675        // and names the offending dep + caminho verbatim.
7676        let d = dep_with_fonte(DepSource::Path {
7677            caminho: "~/work/caixa-teia".into(),
7678        });
7679        let err = d.validate().unwrap_err();
7680        let DepError::FonteCaminhoTildeExpansion { nome, caminho } = err else {
7681            panic!("expected FonteCaminhoTildeExpansion, got {err:?}");
7682        };
7683        assert_eq!(nome, "caixa-teia");
7684        assert_eq!(caminho, "~/work/caixa-teia");
7685    }
7686
7687    #[test]
7688    fn validate_rejects_path_fonte_with_bare_tilde_caminho() {
7689        // The bare `~` form (canonical "I meant `$HOME` and forgot
7690        // the rest"): both the leading-tilde arm catches it and the
7691        // canonical-user-tilde shell idiom (`~alice/dev/caixa-teia`)
7692        // sweeps through the same arm. Pinned both to ensure the
7693        // gate doesn't narrow to `~/` only.
7694        for s in ["~", "~alice/dev/caixa-teia", "~/", "~root/work"] {
7695            let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7696            let err = d.validate().unwrap_err();
7697            assert!(
7698                matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7699                "{s:?} → {err:?}",
7700            );
7701        }
7702    }
7703
7704    #[test]
7705    fn validate_accepts_path_fonte_with_mid_path_tilde_caminho() {
7706        // The leading-`~` is the canonical shell-expansion footgun —
7707        // a tilde mid-path (`"../foo~bar/caixa-teia"` — the canonical
7708        // backup-file-suffix idiom) is a legitimate POSIX path byte
7709        // with no shell-expansion semantic at the leading position.
7710        // Pinned so the gate doesn't widen to a full no-tilde-anywhere
7711        // sweep that would break every legitimate-shape backup-file
7712        // path.
7713        let d = dep_with_fonte(DepSource::Path {
7714            caminho: "../foo~bar/caixa-teia".into(),
7715        });
7716        d.validate().unwrap();
7717    }
7718
7719    #[test]
7720    fn fonte_caminho_empty_fires_before_tilde_expansion() {
7721        // Cascade pin: the empty arm structurally precedes the
7722        // tilde arm (the bytes `""` and `"~"` don't overlap), but the
7723        // pin establishes the precedence at the diagnostic-shape
7724        // level should a future codec round-trip ever produce a
7725        // probe-as-both value. Mirrors the peer
7726        // `fonte_repo_empty_fires_before_pin_missing` cascade
7727        // discipline.
7728        let d = dep_with_fonte(DepSource::Path {
7729            caminho: String::new(),
7730        });
7731        let err = d.validate().unwrap_err();
7732        assert!(
7733            matches!(err, DepError::FonteCaminhoEmpty { .. }),
7734            "got {err:?}",
7735        );
7736    }
7737
7738    #[test]
7739    fn fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho() {
7740        // Diagnostic-shape pin (peer with
7741        // `validate_rejects_path_fonte_with_absolute_caminho`'s
7742        // payload assertion): the error's Display surfaces both the
7743        // offending `:nome` and the offending `:caminho` verbatim
7744        // so a `feira lint` run can render the diagnostic without
7745        // re-parsing.
7746        let d = dep_with_fonte(DepSource::Path {
7747            caminho: "~alice/dev/caixa-teia".into(),
7748        });
7749        let rendered = d.validate().unwrap_err().to_string();
7750        assert!(
7751            rendered.contains("caixa-teia"),
7752            "diagnostic must name the offending dep: {rendered}",
7753        );
7754        assert!(
7755            rendered.contains("~alice/dev/caixa-teia"),
7756            "diagnostic must quote the offending caminho: {rendered}",
7757        );
7758        assert!(
7759            rendered.contains('~'),
7760            "diagnostic must reference the tilde footgun: {rendered}",
7761        );
7762    }
7763
7764    #[test]
7765    fn validate_rejects_path_fonte_with_dollar_prefix_caminho() {
7766        // The fail-before-pass-after pin for the shell-variable-
7767        // expansion `:caminho` shape: `(:tipo path :caminho
7768        // "$HOME/work/caixa-teia")`. Until this gate landed the
7769        // b94fd83 absolute arm + the a5c248e tilde arm both let
7770        // `$HOME/foo` through (`Path::is_absolute` returns false on
7771        // a leading `$` — the `$` is a shell convention, not a POSIX
7772        // path component; `starts_with('~')` returns false too), so
7773        // the lacre embedded the value verbatim and the resolver
7774        // folded it through `Path::join` without `$`-expansion,
7775        // looking for a literal `./$HOME/work/caixa-teia`
7776        // subdirectory and failing at resolve time with a
7777        // `No such file or directory` error far from the source
7778        // caixa.lisp. The new gate moves the check to validate time
7779        // and names the offending dep + caminho verbatim.
7780        let d = dep_with_fonte(DepSource::Path {
7781            caminho: "$HOME/work/caixa-teia".into(),
7782        });
7783        let err = d.validate().unwrap_err();
7784        let DepError::FonteCaminhoVarExpansion { nome, caminho } = err else {
7785            panic!("expected FonteCaminhoVarExpansion, got {err:?}");
7786        };
7787        assert_eq!(nome, "caixa-teia");
7788        assert_eq!(caminho, "$HOME/work/caixa-teia");
7789    }
7790
7791    #[test]
7792    fn validate_rejects_path_fonte_with_dollar_brace_prefix_caminho() {
7793        // Sweep over every leading-`$` shape: the `${VAR}`-braced
7794        // form (canonical "paste-from-CI-manifest" footgun every
7795        // GitHub Actions / GitLab CI / Drone manifest carries on
7796        // `${WORKSPACE}`), the XDG idiom (`$XDG_CONFIG_HOME/caixa`,
7797        // canonical "I'm referencing a per-user config dir"),
7798        // and the bare `$` (canonical "I meant `$HOME` and forgot
7799        // the rest"). All shapes route through the same gate's
7800        // byte check. Pinned so the gate doesn't narrow to a
7801        // single shape (e.g. `$HOME/` only).
7802        for s in [
7803            "${HOME}/work/caixa-teia",
7804            "${WORKSPACE}/caixa-teia",
7805            "$XDG_CONFIG_HOME/caixa",
7806            "$",
7807        ] {
7808            let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7809            let err = d.validate().unwrap_err();
7810            assert!(
7811                matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
7812                "{s:?} → {err:?}",
7813            );
7814        }
7815    }
7816
7817    #[test]
7818    fn validate_rejects_path_fonte_with_mid_path_dollar_caminho() {
7819        // The `$` byte is the canonical shell-variable-expansion /
7820        // command-substitution / arithmetic-expansion sentinel and
7821        // is rejected at *every* position on the `:caminho` axis: the
7822        // leading arm surfaces `FonteCaminhoVarExpansion`, the
7823        // embedded arm surfaces `FonteCaminhoShellVariableExpansion`
7824        // (6620f39). Pinned so a future arm doesn't narrow the gate
7825        // back to the leading position and re-open the paste-from-
7826        // shell-one-liner `"../foo$HOME/bar"` / paste-from-CI-
7827        // manifest `"../foo${WORKSPACE}/bar"` / paste-from-shell-
7828        // prompt `"../foo$(whoami)/bar"` cross-idiom-leak surface on
7829        // the lacre content-address (`path:{caminho}`,
7830        // caixa-resolver/src/resolve.rs:189).
7831        let d = dep_with_fonte(DepSource::Path {
7832            caminho: "../foo$bar/caixa-teia".into(),
7833        });
7834        let err = d.validate().unwrap_err();
7835        assert!(
7836            matches!(
7837                err,
7838                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
7839            ),
7840            "got {err:?}",
7841        );
7842    }
7843
7844    #[test]
7845    fn fonte_caminho_tilde_fires_before_var_expansion() {
7846        // Cascade pin: the tilde arm structurally precedes the var
7847        // arm (the bytes `~` and `$` don't overlap at the leading
7848        // position), but the pin establishes the precedence at the
7849        // diagnostic-shape level should a future codec round-trip
7850        // ever produce a probe-as-both value. Mirrors the peer
7851        // `fonte_caminho_empty_fires_before_tilde_expansion` cascade
7852        // discipline on the immediate-predecessor arm.
7853        let d = dep_with_fonte(DepSource::Path {
7854            caminho: "~/work/caixa-teia".into(),
7855        });
7856        let err = d.validate().unwrap_err();
7857        assert!(
7858            matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7859            "got {err:?}",
7860        );
7861    }
7862
7863    #[test]
7864    fn fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho() {
7865        // Diagnostic-shape pin (peer with
7866        // `fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho`'s
7867        // payload assertion on the immediate-predecessor arm): the
7868        // error's Display surfaces both the offending `:nome` and
7869        // the offending `:caminho` verbatim plus the `$` footgun
7870        // character itself so a `feira lint` run can render the
7871        // diagnostic without re-parsing.
7872        let d = dep_with_fonte(DepSource::Path {
7873            caminho: "${WORKSPACE}/caixa-teia".into(),
7874        });
7875        let rendered = d.validate().unwrap_err().to_string();
7876        assert!(
7877            rendered.contains("caixa-teia"),
7878            "diagnostic must name the offending dep: {rendered}",
7879        );
7880        assert!(
7881            rendered.contains("${WORKSPACE}/caixa-teia"),
7882            "diagnostic must quote the offending caminho: {rendered}",
7883        );
7884        assert!(
7885            rendered.contains('$'),
7886            "diagnostic must reference the dollar footgun: {rendered}",
7887        );
7888    }
7889
7890    #[test]
7891    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_nul() {
7892        // The fail-before-pass-after pin for the load-bearing NUL byte:
7893        // POSIX paths cannot contain `0x00` (every `std::fs` syscall
7894        // routes the path through `CString::new` which fails with
7895        // `NulError`); until this gate landed a `:caminho
7896        // "../caixa\0teia"` silently passed validate, the lacre
7897        // pipeline embedded the value verbatim, and the failure
7898        // surfaced at the resolver's `Path::join` → `CString::new`
7899        // boundary with a non-self-locating `NulError` far from the
7900        // source caixa.lisp. The new gate moves the check to validate
7901        // time and names the offending dep + caminho + offending byte
7902        // verbatim.
7903        let d = dep_with_fonte(DepSource::Path {
7904            caminho: "../caixa\0teia".into(),
7905        });
7906        let err = d.validate().unwrap_err();
7907        let DepError::FonteCaminhoControlChar {
7908            nome,
7909            caminho,
7910            byte,
7911        } = err
7912        else {
7913            panic!("expected FonteCaminhoControlChar, got {err:?}");
7914        };
7915        assert_eq!(nome, "caixa-teia");
7916        assert_eq!(caminho, "../caixa\0teia");
7917        assert_eq!(byte, 0x00);
7918    }
7919
7920    #[test]
7921    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_newline() {
7922        // The canonical paste-from-multiline-doc footgun on `:caminho`
7923        // — author copies `"../caixa-teia\n"` (trailing newline) out
7924        // of a multi-line code-fence or, worse, a `:caminho
7925        // "../caixa-teia\nrm -rf /"` value (CRLF-at-subprocess-argument
7926        // injection sibling on the path axis the `is_git_repo_url`
7927        // control-char arm already closes on `:repo`). Pinned
7928        // separately from the NUL arm so a future relaxation that
7929        // catches one but not the other surfaces here.
7930        let d = dep_with_fonte(DepSource::Path {
7931            caminho: "../caixa-teia\n".into(),
7932        });
7933        let err = d.validate().unwrap_err();
7934        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7935            panic!("expected FonteCaminhoControlChar, got {err:?}");
7936        };
7937        assert_eq!(byte, 0x0A);
7938    }
7939
7940    #[test]
7941    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_carriage_return() {
7942        // The CRLF sibling of the LF arm — Windows-line-ending
7943        // paste-from-multiline-doc on a `\r\n`-terminated buffer
7944        // leaves a stray `\r` mid-string after the LF strip. Pinned
7945        // separately from the LF arm so a future relaxation that
7946        // only catches LF surfaces here.
7947        let d = dep_with_fonte(DepSource::Path {
7948            caminho: "../caixa-teia\r".into(),
7949        });
7950        let err = d.validate().unwrap_err();
7951        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7952            panic!("expected FonteCaminhoControlChar, got {err:?}");
7953        };
7954        assert_eq!(byte, 0x0D);
7955    }
7956
7957    #[test]
7958    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_tab() {
7959        // The canonical paste-from-aligned-table footgun — a `\t`
7960        // mid-`:caminho` is invisible in most editors but rides
7961        // through the lacre's content-address verbatim, so two
7962        // paste-from-distinct-tables (one editor strips tabs, one
7963        // preserves them) yield divergent lacres for the byte-
7964        // identical-looking caixa. Pinned separately from the
7965        // whitespace-shaped LF/CR arms so a future relaxation that
7966        // narrows to line-terminator-only surfaces here.
7967        let d = dep_with_fonte(DepSource::Path {
7968            caminho: "../caixa\tteia".into(),
7969        });
7970        let err = d.validate().unwrap_err();
7971        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7972            panic!("expected FonteCaminhoControlChar, got {err:?}");
7973        };
7974        assert_eq!(byte, 0x09);
7975    }
7976
7977    #[test]
7978    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_del() {
7979        // The DEL byte (`0x7F`) closes the upper-end paste-from-
7980        // binary-blob footgun — the gate's contract is `b < 0x20 ||
7981        // b == 0x7F`, matching the `is_git_repo_url` /
7982        // `is_git_ref_name` predicates' control-char arms. Pinned
7983        // separately from the lower-range arms so a future narrowing
7984        // to `< 0x20` only surfaces here.
7985        let d = dep_with_fonte(DepSource::Path {
7986            caminho: "../caixa\x7fteia".into(),
7987        });
7988        let err = d.validate().unwrap_err();
7989        let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7990            panic!("expected FonteCaminhoControlChar, got {err:?}");
7991        };
7992        assert_eq!(byte, 0x7F);
7993    }
7994
7995    #[test]
7996    fn validate_accepts_path_fonte_with_caminho_carrying_high_bit_utf8() {
7997        // The control-byte arm targets `0x00..=0x1F` + `0x7F` only —
7998        // high-bit / non-ASCII UTF-8 bytes are not gated. POSIX paths
7999        // are opaque byte sequences and UTF-8 multi-byte sequences
8000        // are a legitimate filename shape (the `café-teia/foo` idiom).
8001        // Pinned so the gate doesn't widen to a full ASCII-only sweep
8002        // that would break every legitimate-shape UTF-8 path.
8003        let d = dep_with_fonte(DepSource::Path {
8004            caminho: "../café-teia/foo".into(),
8005        });
8006        d.validate().unwrap();
8007    }
8008
8009    #[test]
8010    fn fonte_caminho_var_fires_before_control_char() {
8011        // Cascade pin: the var-expansion arm structurally precedes the
8012        // control-char arm. A value like `"$\n"` probes positive on
8013        // both arms (`starts_with('$')` and contains LF), but the
8014        // narrower leading-byte diagnostic (`FonteCaminhoVarExpansion`)
8015        // wins so the author sees the more self-locating shell-
8016        // expansion arm first. Mirrors the
8017        // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8018        // discipline on the immediate-predecessor arm.
8019        let d = dep_with_fonte(DepSource::Path {
8020            caminho: "$HOME\n".into(),
8021        });
8022        let err = d.validate().unwrap_err();
8023        assert!(
8024            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8025            "got {err:?}",
8026        );
8027    }
8028
8029    #[test]
8030    fn validate_rejects_path_fonte_with_leading_space_caminho() {
8031        // The fail-before-pass-after pin for the leading ASCII space
8032        // `:caminho` shape: `(:tipo path :caminho " ../caixa-teia")`.
8033        // Until this gate landed the b94fd83 absolute arm + the a5c248e
8034        // tilde arm + the f4efe9c var arm + the d624c8d control-byte arm
8035        // all let `" ../caixa-teia"` through: `Path::is_absolute` returns
8036        // false on a leading space (the leading byte is `0x20`, not `0x2F`),
8037        // `starts_with('~')` / `starts_with('$')` return false, and `0x20`
8038        // is not in the `0x00..=0x1F` plus `0x7F` control-byte set (the
8039        // four ASCII whitespace bytes `0x09` tab, `0x0A` LF, `0x0D` CR
8040        // are caught, but the most common whitespace `0x20` space is
8041        // not). The lacre embedded the value verbatim and the resolver
8042        // folded it through `Path::join` looking for a literal `./ ../
8043        // caixa-teia` subdirectory and failing at resolve time with a
8044        // non-self-locating `No such file or directory` error far from
8045        // the source caixa.lisp. The new gate moves the check to
8046        // validate time and names the offending dep + caminho verbatim.
8047        let d = dep_with_fonte(DepSource::Path {
8048            caminho: " ../caixa-teia".into(),
8049        });
8050        let err = d.validate().unwrap_err();
8051        let DepError::FonteCaminhoLeadingWhitespace { nome, caminho } = err else {
8052            panic!("expected FonteCaminhoLeadingWhitespace, got {err:?}");
8053        };
8054        assert_eq!(nome, "caixa-teia");
8055        assert_eq!(caminho, " ../caixa-teia");
8056    }
8057
8058    #[test]
8059    fn validate_rejects_path_fonte_with_multiple_leading_spaces_caminho() {
8060        // The aligned-doc paste footgun sweep: more than one leading
8061        // space (`"   ../caixa-teia"` — the canonical "I selected the
8062        // aligned column from a four-`:fonte`-entry `:deps` block"
8063        // paste) routes through the same gate's `starts_with(' ')`
8064        // byte check. Pinned so the gate doesn't narrow to a
8065        // single-space prefix.
8066        let d = dep_with_fonte(DepSource::Path {
8067            caminho: "   ../caixa-teia".into(),
8068        });
8069        let err = d.validate().unwrap_err();
8070        assert!(
8071            matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8072            "got {err:?}",
8073        );
8074    }
8075
8076    #[test]
8077    fn validate_accepts_path_fonte_with_mid_path_space_caminho() {
8078        // The leading-space is the canonical paste-from-aligned-doc
8079        // footgun — a space mid-path (`"../my dir/caixa-teia"` — the
8080        // canonical "I have a directory with a space in its name"
8081        // idiom; ASCII `0x20` is a valid POSIX filename byte) is a
8082        // legitimate path with no whitespace-leak semantic at the
8083        // non-leading position. Pinned so the gate doesn't widen to a
8084        // full no-space-anywhere sweep that would break every
8085        // legitimate-shape space-in-filename path.
8086        let d = dep_with_fonte(DepSource::Path {
8087            caminho: "../my dir/caixa-teia".into(),
8088        });
8089        d.validate().unwrap();
8090    }
8091
8092    #[test]
8093    fn fonte_caminho_var_fires_before_leading_whitespace() {
8094        // Cascade pin: the var-expansion arm structurally precedes the
8095        // leading-whitespace arm. A value like `"$ "` would probe positive
8096        // on var (`starts_with('$')`) but the leading-byte arms walk
8097        // left-to-right so the var arm fires on the leading `$` before
8098        // the leading-whitespace arm probes. Mirrors the
8099        // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8100        // discipline on the immediate-predecessor arms.
8101        let d = dep_with_fonte(DepSource::Path {
8102            caminho: "$VAR".into(),
8103        });
8104        let err = d.validate().unwrap_err();
8105        assert!(
8106            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8107            "got {err:?}",
8108        );
8109    }
8110
8111    #[test]
8112    fn fonte_caminho_leading_whitespace_fires_before_control_char() {
8113        // Cascade pin: the leading-whitespace arm structurally precedes
8114        // the control-char arm. A value like `" ../foo\n"` probes
8115        // positive on both (starts with space AND contains LF), but
8116        // the narrower leading-byte diagnostic
8117        // (`FonteCaminhoLeadingWhitespace`) wins so the author sees the
8118        // more self-locating paste-from-aligned-doc arm first. Mirrors
8119        // the `fonte_caminho_var_fires_before_control_char` cascade
8120        // discipline on the immediate-predecessor arm.
8121        let d = dep_with_fonte(DepSource::Path {
8122            caminho: " ../foo\n".into(),
8123        });
8124        let err = d.validate().unwrap_err();
8125        assert!(
8126            matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8127            "got {err:?}",
8128        );
8129    }
8130
8131    #[test]
8132    fn fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho() {
8133        // Diagnostic-shape pin (peer with
8134        // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8135        // payload assertion on the immediate-predecessor arm): the
8136        // error's Display surfaces both the offending `:nome` and the
8137        // offending `:caminho` verbatim, so a `feira lint` run can
8138        // render the diagnostic without re-parsing and the author can
8139        // grep their caixa.lisp for `:caminho "<value>"` and fix it in
8140        // one edit.
8141        let d = dep_with_fonte(DepSource::Path {
8142            caminho: " ../caixa-teia".into(),
8143        });
8144        let rendered = d.validate().unwrap_err().to_string();
8145        assert!(
8146            rendered.contains("caixa-teia"),
8147            "diagnostic must name the offending dep: {rendered}",
8148        );
8149        assert!(
8150            rendered.contains(" ../caixa-teia"),
8151            "diagnostic must quote the offending caminho: {rendered}",
8152        );
8153        assert!(
8154            rendered.contains("space"),
8155            "diagnostic must name the space footgun: {rendered}",
8156        );
8157    }
8158
8159    #[test]
8160    fn fonte_caminho_absolute_fires_before_control_char() {
8161        // Cascade pin on the sibling leading-byte arm: a leading `/`
8162        // value with embedded control byte (`"/etc/passwd\n"`) routes
8163        // through `FonteCaminhoAbsolute` not `FonteCaminhoControlChar`
8164        // — the host-layout-leak diagnostic is the load-bearing axis,
8165        // the control byte is the secondary observation. Same precedence
8166        // logic on every prior leading-byte arm.
8167        let d = dep_with_fonte(DepSource::Path {
8168            caminho: "/etc/passwd\n".into(),
8169        });
8170        let err = d.validate().unwrap_err();
8171        assert!(
8172            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8173            "got {err:?}",
8174        );
8175    }
8176
8177    #[test]
8178    fn validate_rejects_path_fonte_with_leading_hyphen_caminho() {
8179        // The fail-before-pass-after pin for the leading-`-` CLI-arg-
8180        // injection `:caminho` shape sweep. Until this gate landed
8181        // every prior leading-byte arm passed a leading-`-` value
8182        // through: `Path::is_absolute` returns false on `-` (the
8183        // leading byte is `0x2D`, not `0x2F`), `starts_with('~')` /
8184        // `starts_with('$')` / `starts_with(' ')` all return false,
8185        // and `0x2D` sits outside the control-byte set. The lacre
8186        // embedded the value verbatim and the resolver folded it
8187        // through `Path::join` looking for a literal `./-rf` /
8188        // `./-C` / `./--upload-pack=…` subdirectory; the failure at
8189        // `Path::join` time is non-self-locating but harmless, while
8190        // the failure at every downstream `git -C {caminho}` /
8191        // `terraform -chdir={caminho}` / `find {caminho}` shell-out
8192        // is arbitrary-CLI-arg-injection because none of those
8193        // porcelains carry a `--` argument-list terminator between
8194        // the flag block and the path argument. The new arm moves the
8195        // rejection to `Caixa::from_lisp` boundary time and names
8196        // the offending dep + caminho verbatim.
8197        //
8198        // Sweep spans the canonical CLI-arg-injection shapes matching
8199        // the peer sweep on the sibling `is_git_ref_name` /
8200        // `is_git_repo_url` axes: short-flag `-rf` (the `rm -rf` /
8201        // `find -rf` reinterpretation vector), `-C` (the `git -C`
8202        // change-directory-config-injection paste), long-flag
8203        // `--upload-pack=cat /etc/passwd` (the canonical
8204        // arbitrary-command-execution vector on every git porcelain
8205        // entry point), git-config-injection `--config=core.merge=ours`,
8206        // and the degenerate single-byte `-` value.
8207        for caminho in [
8208            "-rf",
8209            "-C",
8210            "--upload-pack=cat /etc/passwd",
8211            "--config=core.merge=ours",
8212            "-",
8213        ] {
8214            let d = dep_with_fonte(DepSource::Path {
8215                caminho: caminho.into(),
8216            });
8217            let err = d.validate().unwrap_err();
8218            let DepError::FonteCaminhoLeadingHyphen { nome, caminho: got } = err else {
8219                panic!("expected FonteCaminhoLeadingHyphen for {caminho:?}, got {err:?}");
8220            };
8221            assert_eq!(nome, "caixa-teia");
8222            assert_eq!(got, caminho);
8223        }
8224    }
8225
8226    #[test]
8227    fn validate_accepts_path_fonte_with_mid_path_hyphen_caminho() {
8228        // The leading-`-` is the canonical CLI-arg-injection footgun
8229        // — a `-` anywhere else in the path (`"../caixa-teia"` — the
8230        // canonical kebab-separator-between-alphanumeric-segments
8231        // shape every DNS-1123-shaped caixa name carries; `"../-hidden"`
8232        // — a mid-path segment starting with `-`, still a legitimate
8233        // POSIX filename byte at that non-leading position because the
8234        // subprocess reads the whole `{caminho}` value as one positional
8235        // argument, so only the very first byte of the composite path
8236        // string is at the CLI-arg-injection boundary) is a legitimate
8237        // path with no CLI-flag-reinterpretation semantic at the non-
8238        // leading position of the top-level value. Pinned so the gate
8239        // doesn't widen to a full no-`-`-anywhere sweep that would
8240        // break every legitimate-shape kebab-in-filename path (i.e.
8241        // essentially every sibling-workspace caixa dep).
8242        for caminho in [
8243            "../caixa-teia",
8244            "../caixa-teia/-hidden",
8245            "./my-lib",
8246            "../foo-bar/baz",
8247        ] {
8248            let d = dep_with_fonte(DepSource::Path {
8249                caminho: caminho.into(),
8250            });
8251            d.validate()
8252                .unwrap_or_else(|e| panic!("mid-path `-` caminho {caminho:?} must pass: {e:?}"));
8253        }
8254    }
8255
8256    #[test]
8257    fn fonte_caminho_leading_whitespace_fires_before_leading_hyphen() {
8258        // Cascade pin: the leading-whitespace arm structurally precedes
8259        // the leading-hyphen arm. A value like `" -rf"` probes positive
8260        // on both (leading space AND, one byte in, a `-` — though the
8261        // leading-hyphen arm probes only the very first byte so it
8262        // wouldn't fire on this value; the pin instead documents the
8263        // arm order on the more common "leading space then a hyphen"
8264        // paste-from-aligned-doc paste-flag-shell-one-liner idiom).
8265        // The narrower leading-space diagnostic (the paste-from-aligned-
8266        // doc footgun) wins so the author sees the more self-locating
8267        // whitespace arm first. Mirrors the
8268        // `fonte_caminho_var_fires_before_leading_whitespace` cascade
8269        // discipline on the immediate-predecessor arm.
8270        let d = dep_with_fonte(DepSource::Path {
8271            caminho: " -rf".into(),
8272        });
8273        let err = d.validate().unwrap_err();
8274        assert!(
8275            matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8276            "got {err:?}",
8277        );
8278    }
8279
8280    #[test]
8281    fn fonte_caminho_leading_hyphen_fires_before_control_char() {
8282        // Cascade pin: the leading-hyphen arm structurally precedes
8283        // the control-char arm. A value like `"-rf\n"` probes positive
8284        // on both (starts with `-` AND contains LF), but the narrower
8285        // leading-byte diagnostic (`FonteCaminhoLeadingHyphen`) wins so
8286        // the author sees the more self-locating CLI-arg-injection arm
8287        // first. Mirrors the
8288        // `fonte_caminho_leading_whitespace_fires_before_control_char`
8289        // cascade discipline on the immediate-predecessor arm.
8290        let d = dep_with_fonte(DepSource::Path {
8291            caminho: "-rf\n".into(),
8292        });
8293        let err = d.validate().unwrap_err();
8294        assert!(
8295            matches!(err, DepError::FonteCaminhoLeadingHyphen { .. }),
8296            "got {err:?}",
8297        );
8298    }
8299
8300    #[test]
8301    fn fonte_caminho_leading_hyphen_diagnostic_carries_offending_dep_and_caminho() {
8302        // Diagnostic-shape pin (peer with
8303        // `fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho`'s
8304        // payload assertion on the immediate-predecessor arm): the
8305        // error's Display surfaces both the offending `:nome` and the
8306        // offending `:caminho` verbatim plus the CLI-argument-injection
8307        // vocabulary, so a `feira lint` run can render the diagnostic
8308        // without re-parsing and the author can grep their caixa.lisp
8309        // for `:caminho "<value>"` and fix it in one edit.
8310        let d = dep_with_fonte(DepSource::Path {
8311            caminho: "--upload-pack=cat /etc/passwd".into(),
8312        });
8313        let rendered = d.validate().unwrap_err().to_string();
8314        assert!(
8315            rendered.contains("caixa-teia"),
8316            "diagnostic must name the offending dep: {rendered}",
8317        );
8318        assert!(
8319            rendered.contains("--upload-pack=cat /etc/passwd"),
8320            "diagnostic must quote the offending caminho: {rendered}",
8321        );
8322        assert!(
8323            rendered.contains("CLI-argument-injection"),
8324            "diagnostic must name the CLI-argument-injection vector: {rendered}",
8325        );
8326        assert!(
8327            rendered.contains("`-`"),
8328            "diagnostic must name the offending byte: {rendered}",
8329        );
8330    }
8331
8332    #[test]
8333    fn fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte() {
8334        // Diagnostic-shape pin (peer with
8335        // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8336        // payload assertion on the immediate-predecessor arm): the
8337        // error's Display surfaces the offending `:nome`, the
8338        // offending `:caminho` verbatim, and the offending byte in
8339        // hex form (`0x09` for tab) so a `feira lint` run can render
8340        // the diagnostic without re-parsing.
8341        let d = dep_with_fonte(DepSource::Path {
8342            caminho: "../caixa\tteia".into(),
8343        });
8344        let rendered = d.validate().unwrap_err().to_string();
8345        assert!(
8346            rendered.contains("caixa-teia"),
8347            "diagnostic must name the offending dep: {rendered}",
8348        );
8349        assert!(
8350            rendered.contains("../caixa\tteia"),
8351            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8352        );
8353        assert!(
8354            rendered.contains("0x09"),
8355            "diagnostic must name the offending byte in hex: {rendered:?}",
8356        );
8357    }
8358
8359    #[test]
8360    fn validate_rejects_path_fonte_with_caminho_carrying_backslash() {
8361        // The fail-before-pass-after pin for the canonical Windows-
8362        // path-separator paste footgun: an author who pastes a path
8363        // from Windows-Explorer's `Copy as path`, PowerShell's
8364        // `Get-Location`, or any CMD/Cygwin/MSYS shell prompt
8365        // produces `..\caixa-teia`-shape values that silently passed
8366        // every prior arm (`Path::is_absolute("..\\caixa-teia")` is
8367        // false; `\` is neither a leading-byte sentinel nor a
8368        // control byte). On POSIX resolvers the value rides through
8369        // `Path::join` as a literal directory name and fails at
8370        // resolve time with `No such file or directory`; on Windows
8371        // resolvers the value resolves to the parent's sibling — two
8372        // distinct directories for the byte-identical caixa.lisp.
8373        // The new arm moves the rejection to validate time and names
8374        // the offending dep + caminho verbatim.
8375        let d = dep_with_fonte(DepSource::Path {
8376            caminho: "..\\caixa-teia".into(),
8377        });
8378        let err = d.validate().unwrap_err();
8379        let DepError::FonteCaminhoBackslash { nome, caminho } = err else {
8380            panic!("expected FonteCaminhoBackslash, got {err:?}");
8381        };
8382        assert_eq!(nome, "caixa-teia");
8383        assert_eq!(caminho, "..\\caixa-teia");
8384    }
8385
8386    #[test]
8387    fn validate_rejects_path_fonte_with_caminho_carrying_windows_drive_letter() {
8388        // The Windows drive-letter paste shape (`C:\work\caixa-teia`
8389        // out of Explorer / `cd`-and-`pwd`-on-Windows). On POSIX
8390        // hosts `Path::is_absolute("C:\\work\\caixa-teia")` returns
8391        // false (POSIX absolute paths start with `/`, drive letters
8392        // are not a POSIX concept), so the b94fd83 absolute arm
8393        // doesn't fire; the value contains `\` bytes that this arm
8394        // now catches with the more self-locating Windows-path-
8395        // separator diagnostic. Pinned separately from the bare
8396        // `..\caixa-teia` shape so a future arm that targets only
8397        // leading-`..\` doesn't regress the drive-letter coverage.
8398        let d = dep_with_fonte(DepSource::Path {
8399            caminho: "C:\\work\\caixa-teia".into(),
8400        });
8401        let err = d.validate().unwrap_err();
8402        assert!(
8403            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8404            "got {err:?}",
8405        );
8406    }
8407
8408    #[test]
8409    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backslash() {
8410        // The trailing-`\` shape (`..\caixa-teia\` — the canonical
8411        // PowerShell tab-completion-on-a-directory append). Pinned
8412        // separately from the embedded-`\` shape so the gate's
8413        // contract is "any `\` anywhere", not "any `\` not at end".
8414        let d = dep_with_fonte(DepSource::Path {
8415            caminho: "..\\caixa-teia\\".into(),
8416        });
8417        let err = d.validate().unwrap_err();
8418        assert!(
8419            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8420            "got {err:?}",
8421        );
8422    }
8423
8424    #[test]
8425    fn validate_accepts_path_fonte_with_caminho_carrying_legitimate_forward_slash() {
8426        // The positive-control pin: the gate targets `\` only,
8427        // never `/`. The canonical relative POSIX path
8428        // (`../caixa-teia/foo/bar`) must continue to validate cleanly
8429        // so legitimate nested-directory deps aren't broken. Pinned
8430        // so the gate doesn't accidentally widen to a "no path
8431        // separators at all" sweep.
8432        let d = dep_with_fonte(DepSource::Path {
8433            caminho: "../caixa-teia/foo/bar".into(),
8434        });
8435        d.validate().unwrap();
8436    }
8437
8438    #[test]
8439    fn fonte_caminho_control_char_fires_before_backslash() {
8440        // Cascade pin: the control-char arm structurally precedes the
8441        // backslash arm. A value like `"..\caixa\0teia"` probes
8442        // positive on both (`\` byte + NUL byte), but the control-
8443        // char diagnostic wins so the author sees the more self-
8444        // locating POSIX-syscall-rejected-byte diagnostic first
8445        // (NUL outright breaks `CString::new` at every `std::fs`
8446        // syscall boundary; the `\` divergence is the cross-OS-
8447        // separator axis). Mirrors the
8448        // `fonte_caminho_var_fires_before_control_char` cascade
8449        // discipline on the immediate-predecessor arm.
8450        let d = dep_with_fonte(DepSource::Path {
8451            caminho: "..\\caixa\0teia".into(),
8452        });
8453        let err = d.validate().unwrap_err();
8454        assert!(
8455            matches!(err, DepError::FonteCaminhoControlChar { .. }),
8456            "got {err:?}",
8457        );
8458    }
8459
8460    #[test]
8461    fn fonte_caminho_absolute_fires_before_backslash() {
8462        // Cascade pin on the load-bearing leading-byte arm: a leading
8463        // `/` value with embedded `\` (`/etc/passwd\foo`) routes
8464        // through `FonteCaminhoAbsolute` not `FonteCaminhoBackslash`
8465        // — the host-layout-leak diagnostic is the load-bearing
8466        // axis, the `\` byte is the secondary observation. Same
8467        // precedence logic as every prior leading-byte arm.
8468        let d = dep_with_fonte(DepSource::Path {
8469            caminho: "/etc/passwd\\foo".into(),
8470        });
8471        let err = d.validate().unwrap_err();
8472        assert!(
8473            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8474            "got {err:?}",
8475        );
8476    }
8477
8478    #[test]
8479    fn fonte_caminho_var_fires_before_backslash() {
8480        // Cascade pin on the var-expansion arm: a leading-`$` value
8481        // with embedded `\` (`$WORKSPACE\caixa-teia` — the canonical
8482        // PowerShell-env-var paste-from-CI-manifest footgun) routes
8483        // through `FonteCaminhoVarExpansion` not `FonteCaminhoBackslash`.
8484        // The shell-expansion diagnostic is the more self-locating
8485        // axis since both the leading `$` and the embedded `\`
8486        // are Windows-shell artifacts but the `$` is the root-cause
8487        // surface (an author who removes the `$` is likely to leave
8488        // the `\` too).
8489        let d = dep_with_fonte(DepSource::Path {
8490            caminho: "$WORKSPACE\\caixa-teia".into(),
8491        });
8492        let err = d.validate().unwrap_err();
8493        assert!(
8494            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8495            "got {err:?}",
8496        );
8497    }
8498
8499    #[test]
8500    fn fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho() {
8501        // Diagnostic-shape pin (peer with the prior
8502        // `fonte_caminho_*_diagnostic_carries_*` payload assertions
8503        // on every preceding arm): the error's Display surfaces the
8504        // offending `:nome` and the offending `:caminho` verbatim
8505        // so a `feira lint` run can render the diagnostic without
8506        // re-parsing.
8507        let d = dep_with_fonte(DepSource::Path {
8508            caminho: "..\\caixa-teia".into(),
8509        });
8510        let rendered = d.validate().unwrap_err().to_string();
8511        assert!(
8512            rendered.contains("caixa-teia"),
8513            "diagnostic must name the offending dep: {rendered}",
8514        );
8515        assert!(
8516            rendered.contains("..\\caixa-teia"),
8517            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8518        );
8519        assert!(
8520            rendered.contains('\\'),
8521            "diagnostic must reference the backslash footgun: {rendered:?}",
8522        );
8523    }
8524
8525    #[test]
8526    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_slash() {
8527        // The fail-before-pass-after pin for the canonical trailing-`/`
8528        // paste footgun: an author who shell-tab-completes a sibling
8529        // directory (every interactive shell — bash/zsh/fish/nushell —
8530        // appends `/` on tab-completing a directory) produces
8531        // `"../caixa-teia/"`-shape values that silently passed every
8532        // prior arm (the leading byte is `.`, no control bytes, no
8533        // backslash). `Path::join` resolves both shapes to the same
8534        // directory at the resolver, but the lacre embeds the value
8535        // verbatim and the BLAKE3 closures diverge across two
8536        // workstations whose authors differ only in tab-completion
8537        // habits.
8538        let d = dep_with_fonte(DepSource::Path {
8539            caminho: "../caixa-teia/".into(),
8540        });
8541        let err = d.validate().unwrap_err();
8542        let DepError::FonteCaminhoTrailingSlash { nome, caminho } = err else {
8543            panic!("expected FonteCaminhoTrailingSlash, got {err:?}");
8544        };
8545        assert_eq!(nome, "caixa-teia");
8546        assert_eq!(caminho, "../caixa-teia/");
8547    }
8548
8549    #[test]
8550    fn validate_rejects_path_fonte_with_caminho_carrying_bare_dot_slash() {
8551        // The `"./"` shape (the canonical "I meant the caixa.lisp's own
8552        // directory and tab-completed it" footgun). Pinned separately
8553        // from the canonical `"../caixa-teia/"` shape so the gate's
8554        // contract is "any trailing `/`", not "trailing `/` after a leaf
8555        // name".
8556        let d = dep_with_fonte(DepSource::Path {
8557            caminho: "./".into(),
8558        });
8559        let err = d.validate().unwrap_err();
8560        assert!(
8561            matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8562            "got {err:?}",
8563        );
8564    }
8565
8566    #[test]
8567    fn validate_rejects_path_fonte_with_caminho_carrying_consecutive_trailing_slashes() {
8568        // The `"foo//"` shape (the canonical "I pasted from a CI manifest
8569        // that double-templated `${VAR}/` over an already-`/`-suffixed
8570        // path" footgun). The gate fires on the last byte being `/`
8571        // regardless of how many `/` precede it; the arm contract is
8572        // "the value ends with `/`", structurally.
8573        let d = dep_with_fonte(DepSource::Path {
8574            caminho: "../caixa-teia//".into(),
8575        });
8576        let err = d.validate().unwrap_err();
8577        assert!(
8578            matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8579            "got {err:?}",
8580        );
8581    }
8582
8583    #[test]
8584    fn validate_rejects_path_fonte_with_caminho_carrying_dotdot_trailing_slash() {
8585        // The `"../"` shape (the canonical "I want the parent" tab-
8586        // completion footgun on a bare `..` path). Pinned separately so
8587        // the gate doesn't accidentally narrow to "trailing `/` only on
8588        // multi-segment paths".
8589        let d = dep_with_fonte(DepSource::Path {
8590            caminho: "../".into(),
8591        });
8592        let err = d.validate().unwrap_err();
8593        assert!(
8594            matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8595            "got {err:?}",
8596        );
8597    }
8598
8599    #[test]
8600    fn validate_accepts_path_fonte_with_caminho_carrying_internal_slashes() {
8601        // The positive-control pin: the gate targets the trailing byte
8602        // only, never internal `/` separators. The canonical nested
8603        // relative POSIX path (`"../caixa-teia/foo/bar"`) must continue
8604        // to validate cleanly so legitimate deeply-nested deps aren't
8605        // broken. Pinned so the gate doesn't accidentally widen to a
8606        // "no `/` separators anywhere" sweep that would defeat the
8607        // entire path-fonte author surface.
8608        let d = dep_with_fonte(DepSource::Path {
8609            caminho: "../caixa-teia/foo/bar".into(),
8610        });
8611        d.validate().unwrap();
8612    }
8613
8614    #[test]
8615    fn validate_accepts_path_fonte_with_caminho_carrying_bare_dot() {
8616        // The positive-control pin on the degenerate single-`.` shape
8617        // (the canonical "the caixa.lisp's own directory" idiom). The
8618        // gate fires on the trailing byte being `/`, not on the path
8619        // being short, so `"."` (one byte, not `/`) must continue to
8620        // validate cleanly.
8621        let d = dep_with_fonte(DepSource::Path {
8622            caminho: ".".into(),
8623        });
8624        d.validate().unwrap();
8625    }
8626
8627    #[test]
8628    fn fonte_caminho_control_char_fires_before_trailing_slash() {
8629        // Cascade pin: the control-char arm structurally precedes the
8630        // trailing-slash arm. A value like `"../foo\n/"` ends in `/`
8631        // but the embedded LF (`0x0A`) is the load-bearing diagnostic
8632        // (control bytes are the paste-from-multiline-doc footgun the
8633        // d624c8d arm already closes). Mirrors the
8634        // `fonte_caminho_control_char_fires_before_backslash` cascade
8635        // discipline on the immediate-predecessor arm.
8636        let d = dep_with_fonte(DepSource::Path {
8637            caminho: "../foo\n/".into(),
8638        });
8639        let err = d.validate().unwrap_err();
8640        assert!(
8641            matches!(err, DepError::FonteCaminhoControlChar { .. }),
8642            "got {err:?}",
8643        );
8644    }
8645
8646    #[test]
8647    fn fonte_caminho_backslash_fires_before_trailing_slash() {
8648        // Cascade pin on the backslash arm: a value like `"..\foo/"`
8649        // ends in `/` but the embedded `\` is the load-bearing
8650        // diagnostic (the cross-host-OS-separator divergence vector
8651        // the 3a4e1d7 arm closes). Same precedence logic as the prior
8652        // narrower-diagnostic-first cascade.
8653        let d = dep_with_fonte(DepSource::Path {
8654            caminho: "..\\caixa-teia/".into(),
8655        });
8656        let err = d.validate().unwrap_err();
8657        assert!(
8658            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8659            "got {err:?}",
8660        );
8661    }
8662
8663    #[test]
8664    fn fonte_caminho_absolute_fires_before_trailing_slash() {
8665        // Cascade pin on the load-bearing leading-byte arm: a leading
8666        // `/` value with a trailing `/` (`"/etc/passwd/"`) routes
8667        // through `FonteCaminhoAbsolute` not `FonteCaminhoTrailingSlash`
8668        // — the host-layout-leak diagnostic is the load-bearing axis,
8669        // the trailing `/` is the secondary observation. Same
8670        // precedence logic as every prior leading-byte arm.
8671        let d = dep_with_fonte(DepSource::Path {
8672            caminho: "/etc/passwd/".into(),
8673        });
8674        let err = d.validate().unwrap_err();
8675        assert!(
8676            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8677            "got {err:?}",
8678        );
8679    }
8680
8681    #[test]
8682    fn fonte_caminho_trailing_slash_diagnostic_carries_offending_dep_and_caminho() {
8683        // Diagnostic-shape pin (peer with the prior
8684        // `fonte_caminho_*_diagnostic_carries_*` payload assertions on
8685        // every preceding arm): the error's Display surfaces the
8686        // offending `:nome` and the offending `:caminho` verbatim so a
8687        // `feira lint` run can render the diagnostic without re-parsing.
8688        let d = dep_with_fonte(DepSource::Path {
8689            caminho: "../caixa-teia/".into(),
8690        });
8691        let rendered = d.validate().unwrap_err().to_string();
8692        assert!(
8693            rendered.contains("caixa-teia"),
8694            "diagnostic must name the offending dep: {rendered}",
8695        );
8696        assert!(
8697            rendered.contains("../caixa-teia/"),
8698            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8699        );
8700        assert!(
8701            rendered.contains("trailing"),
8702            "diagnostic must reference the trailing-slash footgun: {rendered:?}",
8703        );
8704    }
8705
8706    // -- :caminho shell-redirection metacharacter arm -----------------------
8707
8708    #[test]
8709    fn validate_rejects_path_fonte_with_caminho_carrying_gt_redirection() {
8710        // The fail-before-pass-after pin for the canonical output-redirection
8711        // paste footgun: an author copies a shell pipeline tail
8712        // (`"../caixa-teia>build.log"` — the canonical "I selected the whole
8713        // line including the `> build.log` redirect" idiom) and silently
8714        // passed every prior arm (`Path::is_absolute` false on `..`, no
8715        // control bytes, no backslash, doesn't end in `/`). The lacre
8716        // embedded the value verbatim, the resolver folded it through
8717        // `Path::join` looking for a literal `./../caixa-teia>build.log`
8718        // subdirectory, and the failure surfaced at resolve time with a
8719        // non-self-locating `No such file or directory` error. The new arm
8720        // moves the rejection to validate time and names the offending dep
8721        // + caminho + byte verbatim.
8722        let d = dep_with_fonte(DepSource::Path {
8723            caminho: "../caixa-teia>build.log".into(),
8724        });
8725        let err = d.validate().unwrap_err();
8726        let DepError::FonteCaminhoShellRedirection {
8727            nome,
8728            caminho,
8729            byte,
8730        } = err
8731        else {
8732            panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8733        };
8734        assert_eq!(nome, "caixa-teia");
8735        assert_eq!(caminho, "../caixa-teia>build.log");
8736        assert_eq!(byte, b'>');
8737    }
8738
8739    #[test]
8740    fn validate_rejects_path_fonte_with_caminho_carrying_lt_redirection() {
8741        // The symmetric input-redirection paste shape
8742        // (`"../caixa-teia<input.lisp"` — the canonical "I copied a
8743        // `command < input.lisp` line from a tatara-lisp REPL log"
8744        // idiom). Pinned separately from the `>` shape so the gate's
8745        // contract is "any `<` or `>` anywhere", not single-byte coverage.
8746        let d = dep_with_fonte(DepSource::Path {
8747            caminho: "../caixa-teia<input.lisp".into(),
8748        });
8749        let err = d.validate().unwrap_err();
8750        let DepError::FonteCaminhoShellRedirection { byte, .. } = err else {
8751            panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8752        };
8753        assert_eq!(byte, b'<');
8754    }
8755
8756    #[test]
8757    fn validate_rejects_path_fonte_with_caminho_carrying_leading_gt_redirection() {
8758        // Leading-position `>` shape (`">../caixa-teia"` — the degenerate
8759        // "I forgot the source side of the redirect" idiom). Pinned
8760        // separately from the embedded-byte shapes so the gate covers
8761        // every position, not only mid-path.
8762        let d = dep_with_fonte(DepSource::Path {
8763            caminho: ">../caixa-teia".into(),
8764        });
8765        let err = d.validate().unwrap_err();
8766        assert!(
8767            matches!(
8768                err,
8769                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8770            ),
8771            "got {err:?}",
8772        );
8773    }
8774
8775    #[test]
8776    fn validate_rejects_path_fonte_with_caminho_carrying_double_gt_append() {
8777        // The bash append-redirection shape (`"../caixa-teia>>build.log"` —
8778        // the canonical "I copied a `>>` append redirect" idiom). The arm
8779        // fires on the first `>` encountered; pinned so a future arm that
8780        // tries to distinguish `>` from `>>` doesn't break the broader
8781        // contract.
8782        let d = dep_with_fonte(DepSource::Path {
8783            caminho: "../caixa-teia>>build.log".into(),
8784        });
8785        let err = d.validate().unwrap_err();
8786        assert!(
8787            matches!(
8788                err,
8789                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8790            ),
8791            "got {err:?}",
8792        );
8793    }
8794
8795    #[test]
8796    fn validate_accepts_path_fonte_with_caminho_carrying_no_redirection() {
8797        // The positive-control pin: the gate targets only `<` / `>`,
8798        // never adjacent printable ASCII or POSIX-valid bytes. The
8799        // canonical relative POSIX path (`"../caixa-teia"`) and a
8800        // nested deeply-pathed variant (`"../caixa-teia/foo/bar"`) must
8801        // continue to validate cleanly so the gate doesn't widen to a
8802        // "no printable punctuation anywhere" sweep that would defeat
8803        // the entire path-fonte author surface.
8804        let d = dep_with_fonte(DepSource::Path {
8805            caminho: "../caixa-teia/foo/bar".into(),
8806        });
8807        d.validate().unwrap();
8808    }
8809
8810    #[test]
8811    fn fonte_caminho_backslash_fires_before_shell_redirection() {
8812        // Cascade pin on the immediate-predecessor arm: a value carrying
8813        // both `\` and `<` / `>` (`"..\caixa-teia>build.log"` — the
8814        // canonical "I pasted a Windows-shell command with output
8815        // redirect" footgun) routes through `FonteCaminhoBackslash` not
8816        // `FonteCaminhoShellRedirection`. The cross-host-OS-separator
8817        // divergence is the load-bearing axis (an author who removes
8818        // the `\` is the root-cause edit; the `>` falls away in the
8819        // same edit since it's downstream of the Windows-shell
8820        // convention).
8821        let d = dep_with_fonte(DepSource::Path {
8822            caminho: "..\\caixa-teia>build.log".into(),
8823        });
8824        let err = d.validate().unwrap_err();
8825        assert!(
8826            matches!(err, DepError::FonteCaminhoBackslash { .. }),
8827            "got {err:?}",
8828        );
8829    }
8830
8831    #[test]
8832    fn fonte_caminho_control_char_fires_before_shell_redirection() {
8833        // Cascade pin on the embedded-control-byte arm: a value carrying
8834        // both a control byte and `<` / `>` (`"../foo\n>bar"` — the
8835        // canonical paste-from-multiline-doc footgun where a newline
8836        // landed mid-caminho) routes through `FonteCaminhoControlChar`
8837        // not `FonteCaminhoShellRedirection`. The POSIX-syscall-
8838        // rejected-byte / NUL-`CString::new`-fail diagnostic is the
8839        // load-bearing axis on every value that probes positive for
8840        // both — mirrors the cascade discipline on every prior arm.
8841        let d = dep_with_fonte(DepSource::Path {
8842            caminho: "../foo\n>bar".into(),
8843        });
8844        let err = d.validate().unwrap_err();
8845        assert!(
8846            matches!(err, DepError::FonteCaminhoControlChar { .. }),
8847            "got {err:?}",
8848        );
8849    }
8850
8851    #[test]
8852    fn fonte_caminho_absolute_fires_before_shell_redirection() {
8853        // Cascade pin on the load-bearing leading-byte arm: a leading
8854        // `/` value with embedded `<` / `>` (`"/etc/passwd>out"`)
8855        // routes through `FonteCaminhoAbsolute` not
8856        // `FonteCaminhoShellRedirection` — the host-layout-leak
8857        // diagnostic is the load-bearing axis, the `>` byte is the
8858        // secondary observation. Same precedence logic as every prior
8859        // leading-byte arm.
8860        let d = dep_with_fonte(DepSource::Path {
8861            caminho: "/etc/passwd>out".into(),
8862        });
8863        let err = d.validate().unwrap_err();
8864        assert!(
8865            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8866            "got {err:?}",
8867        );
8868    }
8869
8870    #[test]
8871    fn fonte_caminho_shell_redirection_fires_before_trailing_slash() {
8872        // Cascade pin on the immediate-successor arm: a value carrying
8873        // both `<` / `>` and a trailing `/` (`"../foo></"` — the
8874        // canonical "I tab-completed a path that already had a
8875        // redirect" footgun) routes through `FonteCaminhoShellRedirection`
8876        // not `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
8877        // the more semantic-locating axis (an author who removes the
8878        // `<` / `>` typically also drops the trailing separator since
8879        // both are paste-from-shell artifacts).
8880        let d = dep_with_fonte(DepSource::Path {
8881            caminho: "../foo></".into(),
8882        });
8883        let err = d.validate().unwrap_err();
8884        assert!(
8885            matches!(
8886                err,
8887                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8888            ),
8889            "got {err:?}",
8890        );
8891    }
8892
8893    #[test]
8894    fn fonte_caminho_shell_redirection_diagnostic_carries_offending_dep_caminho_byte() {
8895        // Diagnostic-shape pin (peer with
8896        // `fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte`'s
8897        // payload assertion on the closest peer arm that also carries a
8898        // `byte` field): the error's Display surfaces the offending
8899        // `:nome`, the offending `:caminho` verbatim, and the offending
8900        // byte in hex (`0x3c` for `<`, `0x3e` for `>`) so a `feira lint`
8901        // run can render the diagnostic without re-parsing.
8902        let d = dep_with_fonte(DepSource::Path {
8903            caminho: "../caixa-teia>build.log".into(),
8904        });
8905        let rendered = d.validate().unwrap_err().to_string();
8906        assert!(
8907            rendered.contains("caixa-teia"),
8908            "diagnostic must name the offending dep: {rendered}",
8909        );
8910        assert!(
8911            rendered.contains("../caixa-teia>build.log"),
8912            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8913        );
8914        assert!(
8915            rendered.contains("0x3e"),
8916            "diagnostic must name the offending byte in hex: {rendered:?}",
8917        );
8918        assert!(
8919            rendered.contains("redirection"),
8920            "diagnostic must name the shell-redirection footgun: {rendered:?}",
8921        );
8922    }
8923
8924    // -- :caminho shell-pipe metacharacter arm ----------------------------
8925
8926    #[test]
8927    fn validate_rejects_path_fonte_with_caminho_carrying_pipe() {
8928        // The fail-before-pass-after pin for the canonical shell-pipe
8929        // paste footgun: an author copies a shell-history line
8930        // (`"../caixa-teia | grep foo"` — the canonical "I selected
8931        // the whole `ls dir | grep` line out of zsh history") and
8932        // silently passed every prior arm (`Path::is_absolute` false
8933        // on `..`, no control bytes, no backslash, no `<` / `>`,
8934        // doesn't end in `/`). The lacre embedded the value verbatim,
8935        // the resolver folded it through `Path::join` looking for a
8936        // literal `./../caixa-teia | grep foo` subdirectory, and the
8937        // failure surfaced at resolve time with a non-self-locating
8938        // `No such file or directory` error. The new arm moves the
8939        // rejection to validate time and names the offending dep +
8940        // caminho verbatim.
8941        let d = dep_with_fonte(DepSource::Path {
8942            caminho: "../caixa-teia | grep foo".into(),
8943        });
8944        let err = d.validate().unwrap_err();
8945        let DepError::FonteCaminhoShellPipe { nome, caminho } = err else {
8946            panic!("expected FonteCaminhoShellPipe, got {err:?}");
8947        };
8948        assert_eq!(nome, "caixa-teia");
8949        assert_eq!(caminho, "../caixa-teia | grep foo");
8950    }
8951
8952    #[test]
8953    fn validate_rejects_path_fonte_with_caminho_carrying_leading_pipe() {
8954        // Leading-position `|` shape (`"|../caixa-teia"` — the
8955        // degenerate "I forgot the source side of the pipe" idiom).
8956        // Pinned separately from the embedded-byte shape so the gate
8957        // covers every position, not only mid-path.
8958        let d = dep_with_fonte(DepSource::Path {
8959            caminho: "|../caixa-teia".into(),
8960        });
8961        let err = d.validate().unwrap_err();
8962        assert!(
8963            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
8964            "got {err:?}",
8965        );
8966    }
8967
8968    #[test]
8969    fn validate_rejects_path_fonte_with_caminho_carrying_double_pipe_or() {
8970        // The bash short-circuit-OR shape (`"../caixa-teia||fallback"`
8971        // — the canonical "I copied a `cmd-a || cmd-b` fallback line"
8972        // idiom). The arm fires on the first `|` encountered; pinned
8973        // so a future arm that tries to distinguish `|` from `||`
8974        // doesn't break the broader contract.
8975        let d = dep_with_fonte(DepSource::Path {
8976            caminho: "../caixa-teia||fallback".into(),
8977        });
8978        let err = d.validate().unwrap_err();
8979        assert!(
8980            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
8981            "got {err:?}",
8982        );
8983    }
8984
8985    #[test]
8986    fn validate_accepts_path_fonte_with_caminho_carrying_no_pipe() {
8987        // The positive-control pin: the gate targets only `|`, never
8988        // adjacent printable ASCII or POSIX-valid bytes. The canonical
8989        // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
8990        // pathed variant with adjacent printable punctuation
8991        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
8992        // cleanly so the gate doesn't widen to a "no printable
8993        // punctuation anywhere" sweep that would defeat the entire
8994        // path-fonte author surface.
8995        let d = dep_with_fonte(DepSource::Path {
8996            caminho: "../caixa-teia/sub-dir.v2".into(),
8997        });
8998        d.validate().unwrap();
8999    }
9000
9001    #[test]
9002    fn fonte_caminho_shell_redirection_fires_before_shell_pipe() {
9003        // Cascade pin on the immediate-predecessor arm: a value carrying
9004        // both `<` / `>` and `|` (`"../caixa-teia<input|tee"` — the
9005        // canonical "I pasted a `cmd < input | tee` pipeline tail"
9006        // footgun) routes through `FonteCaminhoShellRedirection` not
9007        // `FonteCaminhoShellPipe`. The input/output redirection
9008        // metachar carries the more self-locating `byte: u8` payload
9009        // (it names which of `<` or `>` triggered), so the prior arm
9010        // wins on every probe-as-both value — same cascade discipline
9011        // every prior `:caminho` arm establishes.
9012        let d = dep_with_fonte(DepSource::Path {
9013            caminho: "../caixa-teia<input|tee".into(),
9014        });
9015        let err = d.validate().unwrap_err();
9016        assert!(
9017            matches!(
9018                err,
9019                DepError::FonteCaminhoShellRedirection { byte: b'<', .. }
9020            ),
9021            "got {err:?}",
9022        );
9023    }
9024
9025    #[test]
9026    fn fonte_caminho_backslash_fires_before_shell_pipe() {
9027        // Cascade pin on the upstream backslash arm: a value carrying
9028        // both `\` and `|` (`"..\caixa-teia|tee"` — the canonical
9029        // "I pasted a Windows-shell command with pipe to tee"
9030        // footgun) routes through `FonteCaminhoBackslash` not
9031        // `FonteCaminhoShellPipe`. The cross-host-OS-separator
9032        // divergence is the load-bearing axis on every probe-as-both
9033        // value (an author who removes the `\` is the root-cause edit;
9034        // the `|` falls away in the same edit since it's downstream of
9035        // the Windows-shell convention).
9036        let d = dep_with_fonte(DepSource::Path {
9037            caminho: "..\\caixa-teia|tee".into(),
9038        });
9039        let err = d.validate().unwrap_err();
9040        assert!(
9041            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9042            "got {err:?}",
9043        );
9044    }
9045
9046    #[test]
9047    fn fonte_caminho_control_char_fires_before_shell_pipe() {
9048        // Cascade pin on the embedded-control-byte arm: a value
9049        // carrying both a control byte and `|` (`"../foo\n|bar"` —
9050        // the canonical paste-from-multiline-doc footgun where a
9051        // newline landed mid-caminho) routes through
9052        // `FonteCaminhoControlChar` not `FonteCaminhoShellPipe`. The
9053        // POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9054        // diagnostic is the load-bearing axis on every value that
9055        // probes positive for both — mirrors the cascade discipline
9056        // on every prior arm.
9057        let d = dep_with_fonte(DepSource::Path {
9058            caminho: "../foo\n|bar".into(),
9059        });
9060        let err = d.validate().unwrap_err();
9061        assert!(
9062            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9063            "got {err:?}",
9064        );
9065    }
9066
9067    #[test]
9068    fn fonte_caminho_absolute_fires_before_shell_pipe() {
9069        // Cascade pin on the load-bearing leading-byte arm: a leading
9070        // `/` value with embedded `|` (`"/etc/passwd|tee"`) routes
9071        // through `FonteCaminhoAbsolute` not `FonteCaminhoShellPipe`
9072        // — the host-layout-leak diagnostic is the load-bearing axis,
9073        // the `|` byte is the secondary observation. Same precedence
9074        // logic as every prior leading-byte arm.
9075        let d = dep_with_fonte(DepSource::Path {
9076            caminho: "/etc/passwd|tee".into(),
9077        });
9078        let err = d.validate().unwrap_err();
9079        assert!(
9080            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9081            "got {err:?}",
9082        );
9083    }
9084
9085    #[test]
9086    fn fonte_caminho_shell_pipe_fires_before_trailing_slash() {
9087        // Cascade pin on the immediate-successor arm: a value carrying
9088        // both `|` and a trailing `/` (`"../foo|tee/"` — the canonical
9089        // "I tab-completed a path that already had a pipeline tail"
9090        // footgun) routes through `FonteCaminhoShellPipe` not
9091        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9092        // the more semantic-locating axis (an author who removes the
9093        // `|` typically also drops the trailing separator since both
9094        // are paste-from-shell artifacts).
9095        let d = dep_with_fonte(DepSource::Path {
9096            caminho: "../foo|tee/".into(),
9097        });
9098        let err = d.validate().unwrap_err();
9099        assert!(
9100            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9101            "got {err:?}",
9102        );
9103    }
9104
9105    #[test]
9106    fn fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho() {
9107        // Diagnostic-shape pin (peer with
9108        // `fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho`
9109        // on the closest single-byte peer arm): the error's Display
9110        // surfaces the offending `:nome` and the offending `:caminho`
9111        // verbatim, and names the shell-pipe footgun explicitly so a
9112        // `feira lint` run can render the diagnostic without
9113        // re-parsing.
9114        let d = dep_with_fonte(DepSource::Path {
9115            caminho: "../caixa-teia | grep foo".into(),
9116        });
9117        let rendered = d.validate().unwrap_err().to_string();
9118        assert!(
9119            rendered.contains("caixa-teia"),
9120            "diagnostic must name the offending dep: {rendered}",
9121        );
9122        assert!(
9123            rendered.contains("../caixa-teia | grep foo"),
9124            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9125        );
9126        assert!(
9127            rendered.contains('|'),
9128            "diagnostic must reference the pipe footgun: {rendered:?}",
9129        );
9130        assert!(
9131            rendered.contains("pipe"),
9132            "diagnostic must name the shell-pipe footgun: {rendered:?}",
9133        );
9134    }
9135
9136    // -- :caminho shell-command-separator metacharacter arm ---------------
9137
9138    #[test]
9139    fn validate_rejects_path_fonte_with_caminho_carrying_semicolon() {
9140        // The fail-before-pass-after pin for the canonical shell-command-
9141        // separator paste footgun: an author copies a shell one-liner
9142        // (`"../caixa-teia; rm -rf build"` — the canonical "I selected the
9143        // whole `cd path; do-thing` chain out of a shell-history block")
9144        // and silently passed every prior arm (`Path::is_absolute` false
9145        // on `..`, no control bytes, no backslash, no `<` / `>`, no `|`,
9146        // doesn't end in `/`). The lacre embedded the value verbatim, the
9147        // resolver folded it through `Path::join` looking for a literal
9148        // `./../caixa-teia; rm -rf build` subdirectory, and the failure
9149        // surfaced at resolve time with a non-self-locating `No such file
9150        // or directory` error. The new arm moves the rejection to validate
9151        // time and names the offending dep + caminho verbatim.
9152        let d = dep_with_fonte(DepSource::Path {
9153            caminho: "../caixa-teia; rm -rf build".into(),
9154        });
9155        let err = d.validate().unwrap_err();
9156        let DepError::FonteCaminhoShellSemicolon { nome, caminho } = err else {
9157            panic!("expected FonteCaminhoShellSemicolon, got {err:?}");
9158        };
9159        assert_eq!(nome, "caixa-teia");
9160        assert_eq!(caminho, "../caixa-teia; rm -rf build");
9161    }
9162
9163    #[test]
9164    fn validate_rejects_path_fonte_with_caminho_carrying_leading_semicolon() {
9165        // Leading-position `;` shape (`";../caixa-teia"` — the degenerate
9166        // "I forgot the prior command side of the separator" idiom).
9167        // Pinned separately from the embedded-byte shape so the gate
9168        // covers every position, not only mid-path.
9169        let d = dep_with_fonte(DepSource::Path {
9170            caminho: ";../caixa-teia".into(),
9171        });
9172        let err = d.validate().unwrap_err();
9173        assert!(
9174            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9175            "got {err:?}",
9176        );
9177    }
9178
9179    #[test]
9180    fn validate_rejects_path_fonte_with_caminho_carrying_double_semicolon() {
9181        // The POSIX `case` arm `;;` terminator shape
9182        // (`"../caixa-teia;;next"` — the canonical "I copied a `case`
9183        // arm tail" idiom). The arm fires on the first `;` encountered;
9184        // pinned so a future arm that tries to distinguish `;` from `;;`
9185        // doesn't break the broader contract.
9186        let d = dep_with_fonte(DepSource::Path {
9187            caminho: "../caixa-teia;;next".into(),
9188        });
9189        let err = d.validate().unwrap_err();
9190        assert!(
9191            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9192            "got {err:?}",
9193        );
9194    }
9195
9196    #[test]
9197    fn validate_accepts_path_fonte_with_caminho_carrying_no_semicolon() {
9198        // The positive-control pin: the gate targets only `;`, never
9199        // adjacent printable ASCII or POSIX-valid bytes. The canonical
9200        // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9201        // pathed variant with adjacent printable punctuation
9202        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9203        // cleanly so the gate doesn't widen to a "no printable
9204        // punctuation anywhere" sweep that would defeat the entire
9205        // path-fonte author surface.
9206        let d = dep_with_fonte(DepSource::Path {
9207            caminho: "../caixa-teia/sub-dir.v2".into(),
9208        });
9209        d.validate().unwrap();
9210    }
9211
9212    #[test]
9213    fn fonte_caminho_shell_pipe_fires_before_shell_semicolon() {
9214        // Cascade pin on the immediate-predecessor arm: a value carrying
9215        // both `|` and `;` (`"../caixa-teia | tee; rm"` — the canonical
9216        // "I pasted a `cmd | tee; cleanup` chain" footgun) routes through
9217        // `FonteCaminhoShellPipe` not `FonteCaminhoShellSemicolon`. The
9218        // pipeline-tail paste is the load-bearing root-cause edit on
9219        // every probe-as-both value (an author who removes the `|`
9220        // typically also drops the trailing `; cleanup` since both are
9221        // the same paste-from-shell-history artifact) — same cascade
9222        // discipline every prior `:caminho` arm establishes.
9223        let d = dep_with_fonte(DepSource::Path {
9224            caminho: "../caixa-teia | tee; rm".into(),
9225        });
9226        let err = d.validate().unwrap_err();
9227        assert!(
9228            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9229            "got {err:?}",
9230        );
9231    }
9232
9233    #[test]
9234    fn fonte_caminho_shell_redirection_fires_before_shell_semicolon() {
9235        // Cascade pin on the upstream shell-redirection arm: a value
9236        // carrying both `<` / `>` and `;` (`"../caixa-teia>log; rm"` —
9237        // the canonical "I pasted a `cmd > log; cleanup` chain"
9238        // footgun) routes through `FonteCaminhoShellRedirection` not
9239        // `FonteCaminhoShellSemicolon`. The input/output redirection
9240        // metachar carries the more self-locating `byte: u8` payload
9241        // (it names which of `<` or `>` triggered), so the prior arm
9242        // wins on every probe-as-both value.
9243        let d = dep_with_fonte(DepSource::Path {
9244            caminho: "../caixa-teia>log; rm".into(),
9245        });
9246        let err = d.validate().unwrap_err();
9247        assert!(
9248            matches!(
9249                err,
9250                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9251            ),
9252            "got {err:?}",
9253        );
9254    }
9255
9256    #[test]
9257    fn fonte_caminho_backslash_fires_before_shell_semicolon() {
9258        // Cascade pin on the upstream backslash arm: a value carrying
9259        // both `\` and `;` (`"..\caixa-teia;rm"` — the canonical "I
9260        // pasted a Windows-shell `cd ..\path; cleanup` chain") routes
9261        // through `FonteCaminhoBackslash` not `FonteCaminhoShellSemicolon`.
9262        // The cross-host-OS-separator divergence is the load-bearing axis
9263        // on every probe-as-both value (an author who removes the `\` is
9264        // the root-cause edit; the `;` falls away in the same edit since
9265        // it's downstream of the Windows-shell convention).
9266        let d = dep_with_fonte(DepSource::Path {
9267            caminho: "..\\caixa-teia;rm".into(),
9268        });
9269        let err = d.validate().unwrap_err();
9270        assert!(
9271            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9272            "got {err:?}",
9273        );
9274    }
9275
9276    #[test]
9277    fn fonte_caminho_control_char_fires_before_shell_semicolon() {
9278        // Cascade pin on the embedded-control-byte arm: a value carrying
9279        // both a control byte and `;` (`"../foo\n;bar"` — the canonical
9280        // paste-from-multiline-doc footgun where a newline landed mid-
9281        // caminho) routes through `FonteCaminhoControlChar` not
9282        // `FonteCaminhoShellSemicolon`. The POSIX-syscall-rejected-byte
9283        // / NUL-`CString::new`-fail diagnostic is the load-bearing axis
9284        // on every value that probes positive for both — mirrors the
9285        // cascade discipline on every prior arm.
9286        let d = dep_with_fonte(DepSource::Path {
9287            caminho: "../foo\n;bar".into(),
9288        });
9289        let err = d.validate().unwrap_err();
9290        assert!(
9291            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9292            "got {err:?}",
9293        );
9294    }
9295
9296    #[test]
9297    fn fonte_caminho_absolute_fires_before_shell_semicolon() {
9298        // Cascade pin on the load-bearing leading-byte arm: a leading
9299        // `/` value with embedded `;` (`"/etc/passwd;rm"`) routes
9300        // through `FonteCaminhoAbsolute` not `FonteCaminhoShellSemicolon`
9301        // — the host-layout-leak diagnostic is the load-bearing axis,
9302        // the `;` byte is the secondary observation. Same precedence
9303        // logic as every prior leading-byte arm.
9304        let d = dep_with_fonte(DepSource::Path {
9305            caminho: "/etc/passwd;rm".into(),
9306        });
9307        let err = d.validate().unwrap_err();
9308        assert!(
9309            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9310            "got {err:?}",
9311        );
9312    }
9313
9314    #[test]
9315    fn fonte_caminho_shell_semicolon_fires_before_trailing_slash() {
9316        // Cascade pin on the immediate-successor arm: a value carrying
9317        // both `;` and a trailing `/` (`"../foo;rm/"` — the canonical
9318        // "I tab-completed a path that already had a `; cleanup` tail"
9319        // footgun) routes through `FonteCaminhoShellSemicolon` not
9320        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9321        // the more semantic-locating axis (an author who removes the
9322        // `;` typically also drops the trailing separator since both
9323        // are paste-from-shell artifacts).
9324        let d = dep_with_fonte(DepSource::Path {
9325            caminho: "../foo;rm/".into(),
9326        });
9327        let err = d.validate().unwrap_err();
9328        assert!(
9329            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9330            "got {err:?}",
9331        );
9332    }
9333
9334    #[test]
9335    fn fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho() {
9336        // Diagnostic-shape pin (peer with
9337        // `fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho`
9338        // on the closest single-byte peer arm): the error's Display
9339        // surfaces the offending `:nome` and the offending `:caminho`
9340        // verbatim, and names the shell-command-separator footgun
9341        // explicitly so a `feira lint` run can render the diagnostic
9342        // without re-parsing.
9343        let d = dep_with_fonte(DepSource::Path {
9344            caminho: "../caixa-teia; rm -rf build".into(),
9345        });
9346        let rendered = d.validate().unwrap_err().to_string();
9347        assert!(
9348            rendered.contains("caixa-teia"),
9349            "diagnostic must name the offending dep: {rendered}",
9350        );
9351        assert!(
9352            rendered.contains("../caixa-teia; rm -rf build"),
9353            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9354        );
9355        assert!(
9356            rendered.contains(';'),
9357            "diagnostic must reference the semicolon footgun: {rendered:?}",
9358        );
9359        assert!(
9360            rendered.contains("command-separator"),
9361            "diagnostic must name the shell-command-separator footgun: {rendered:?}",
9362        );
9363    }
9364
9365    #[test]
9366    fn validate_rejects_path_fonte_with_caminho_carrying_ampersand() {
9367        // The fail-before-pass-after pin for the canonical shell-
9368        // background-task paste footgun: an author copies a shell one-
9369        // liner (`"../caixa-teia & sleep 1"` — the canonical "I selected
9370        // the whole `cd path & sleep 1` background-launch out of a
9371        // shell-history block") and silently passed every prior arm
9372        // (`Path::is_absolute` false on `..`, no control bytes, no
9373        // backslash, no `<` / `>`, no `|`, no `;`, doesn't end in `/`).
9374        // The lacre embedded the value verbatim, the resolver folded it
9375        // through `Path::join` looking for a literal `./../caixa-teia &
9376        // sleep 1` subdirectory, and the failure surfaced at resolve
9377        // time with a non-self-locating `No such file or directory`
9378        // error. The new arm moves the rejection to validate time and
9379        // names the offending dep + caminho verbatim.
9380        let d = dep_with_fonte(DepSource::Path {
9381            caminho: "../caixa-teia & sleep 1".into(),
9382        });
9383        let err = d.validate().unwrap_err();
9384        let DepError::FonteCaminhoShellBackground { nome, caminho } = err else {
9385            panic!("expected FonteCaminhoShellBackground, got {err:?}");
9386        };
9387        assert_eq!(nome, "caixa-teia");
9388        assert_eq!(caminho, "../caixa-teia & sleep 1");
9389    }
9390
9391    #[test]
9392    fn validate_rejects_path_fonte_with_caminho_carrying_leading_ampersand() {
9393        // Leading-position `&` shape (`"&../caixa-teia"` — the
9394        // degenerate "I forgot the prior command side of the
9395        // background terminator" idiom). Pinned separately from the
9396        // embedded-byte shape so the gate covers every position, not
9397        // only mid-path.
9398        let d = dep_with_fonte(DepSource::Path {
9399            caminho: "&../caixa-teia".into(),
9400        });
9401        let err = d.validate().unwrap_err();
9402        assert!(
9403            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9404            "got {err:?}",
9405        );
9406    }
9407
9408    #[test]
9409    fn validate_rejects_path_fonte_with_caminho_carrying_double_ampersand() {
9410        // The logical-AND `&&` shape (`"../caixa-teia && make"` — the
9411        // canonical "I copied a `cd path && make` build chain" idiom
9412        // every Makefile / shell-script wraps). The arm fires on the
9413        // first `&` encountered; pinned so a future arm that tries to
9414        // distinguish `&` from `&&` doesn't break the broader contract.
9415        let d = dep_with_fonte(DepSource::Path {
9416            caminho: "../caixa-teia && make".into(),
9417        });
9418        let err = d.validate().unwrap_err();
9419        assert!(
9420            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9421            "got {err:?}",
9422        );
9423    }
9424
9425    #[test]
9426    fn validate_accepts_path_fonte_with_caminho_carrying_no_ampersand() {
9427        // The positive-control pin: the gate targets only `&`, never
9428        // adjacent printable ASCII or POSIX-valid bytes. The canonical
9429        // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9430        // pathed variant with adjacent printable punctuation
9431        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9432        // cleanly so the gate doesn't widen to a "no printable
9433        // punctuation anywhere" sweep that would defeat the entire
9434        // path-fonte author surface.
9435        let d = dep_with_fonte(DepSource::Path {
9436            caminho: "../caixa-teia/sub-dir.v2".into(),
9437        });
9438        d.validate().unwrap();
9439    }
9440
9441    #[test]
9442    fn fonte_caminho_shell_semicolon_fires_before_shell_background() {
9443        // Cascade pin on the immediate-predecessor arm: a value carrying
9444        // both `;` and `&` (`"../caixa-teia; rm & sleep"` — the
9445        // canonical "I pasted a `cmd; cleanup & sleep` chain" footgun)
9446        // routes through `FonteCaminhoShellSemicolon` not
9447        // `FonteCaminhoShellBackground`. The sequential-command-
9448        // separator paste is the more common shell-history paste idiom
9449        // on every probe-as-both value (an author who removes the `;`
9450        // typically also drops the trailing `& sleep` since both are
9451        // paste-from-shell-history artifacts) — same cascade discipline
9452        // every prior `:caminho` arm establishes.
9453        let d = dep_with_fonte(DepSource::Path {
9454            caminho: "../caixa-teia; rm & sleep".into(),
9455        });
9456        let err = d.validate().unwrap_err();
9457        assert!(
9458            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9459            "got {err:?}",
9460        );
9461    }
9462
9463    #[test]
9464    fn fonte_caminho_shell_pipe_fires_before_shell_background() {
9465        // Cascade pin on the upstream shell-pipe arm: a value carrying
9466        // both `|` and `&` (`"../caixa-teia | tee & sleep"` — the
9467        // canonical "I pasted a `cmd | tee & sleep` background-pipeline
9468        // chain" footgun) routes through `FonteCaminhoShellPipe` not
9469        // `FonteCaminhoShellBackground`. The pipeline-tail paste is the
9470        // load-bearing root-cause edit on every probe-as-both value.
9471        let d = dep_with_fonte(DepSource::Path {
9472            caminho: "../caixa-teia | tee & sleep".into(),
9473        });
9474        let err = d.validate().unwrap_err();
9475        assert!(
9476            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9477            "got {err:?}",
9478        );
9479    }
9480
9481    #[test]
9482    fn fonte_caminho_shell_redirection_fires_before_shell_background() {
9483        // Cascade pin on the upstream shell-redirection arm: a value
9484        // carrying both `>` and `&` (`"../caixa-teia>log & sleep"` —
9485        // the canonical "I pasted a `cmd > log & sleep` background-
9486        // redirect chain" footgun) routes through
9487        // `FonteCaminhoShellRedirection` not
9488        // `FonteCaminhoShellBackground`. The input/output redirection
9489        // metachar carries the more self-locating `byte: u8` payload
9490        // (it names which of `<` or `>` triggered), so the prior arm
9491        // wins on every probe-as-both value.
9492        let d = dep_with_fonte(DepSource::Path {
9493            caminho: "../caixa-teia>log & sleep".into(),
9494        });
9495        let err = d.validate().unwrap_err();
9496        assert!(
9497            matches!(
9498                err,
9499                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9500            ),
9501            "got {err:?}",
9502        );
9503    }
9504
9505    #[test]
9506    fn fonte_caminho_backslash_fires_before_shell_background() {
9507        // Cascade pin on the upstream backslash arm: a value carrying
9508        // both `\` and `&` (`"..\caixa-teia & sleep"` — the canonical
9509        // "I pasted a Windows-shell `cd ..\path & sleep` background-
9510        // launch chain") routes through `FonteCaminhoBackslash` not
9511        // `FonteCaminhoShellBackground`. The cross-host-OS-separator
9512        // divergence is the load-bearing axis on every probe-as-both
9513        // value (an author who removes the `\` is the root-cause edit;
9514        // the `&` falls away in the same edit since it's downstream of
9515        // the Windows-shell convention).
9516        let d = dep_with_fonte(DepSource::Path {
9517            caminho: "..\\caixa-teia & sleep".into(),
9518        });
9519        let err = d.validate().unwrap_err();
9520        assert!(
9521            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9522            "got {err:?}",
9523        );
9524    }
9525
9526    #[test]
9527    fn fonte_caminho_control_char_fires_before_shell_background() {
9528        // Cascade pin on the embedded-control-byte arm: a value
9529        // carrying both a control byte and `&` (`"../foo\n&sleep"` —
9530        // the canonical paste-from-multiline-doc footgun where a
9531        // newline landed mid-caminho) routes through
9532        // `FonteCaminhoControlChar` not `FonteCaminhoShellBackground`.
9533        // The POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9534        // diagnostic is the load-bearing axis on every value that
9535        // probes positive for both — mirrors the cascade discipline on
9536        // every prior arm.
9537        let d = dep_with_fonte(DepSource::Path {
9538            caminho: "../foo\n&sleep".into(),
9539        });
9540        let err = d.validate().unwrap_err();
9541        assert!(
9542            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9543            "got {err:?}",
9544        );
9545    }
9546
9547    #[test]
9548    fn fonte_caminho_absolute_fires_before_shell_background() {
9549        // Cascade pin on the load-bearing leading-byte arm: a leading
9550        // `/` value with embedded `&` (`"/etc/passwd & sleep"`) routes
9551        // through `FonteCaminhoAbsolute` not
9552        // `FonteCaminhoShellBackground` — the host-layout-leak
9553        // diagnostic is the load-bearing axis, the `&` byte is the
9554        // secondary observation. Same precedence logic as every prior
9555        // leading-byte arm.
9556        let d = dep_with_fonte(DepSource::Path {
9557            caminho: "/etc/passwd & sleep".into(),
9558        });
9559        let err = d.validate().unwrap_err();
9560        assert!(
9561            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9562            "got {err:?}",
9563        );
9564    }
9565
9566    #[test]
9567    fn fonte_caminho_shell_background_fires_before_trailing_slash() {
9568        // Cascade pin on the immediate-successor arm: a value carrying
9569        // both `&` and a trailing `/` (`"../foo&sleep/"` — the
9570        // canonical "I tab-completed a path that already had a `&
9571        // sleep` background-launch tail" footgun) routes through
9572        // `FonteCaminhoShellBackground` not `FonteCaminhoTrailingSlash`.
9573        // The embedded shell-metachar is the more semantic-locating
9574        // axis (an author who removes the `&` typically also drops
9575        // the trailing separator since both are paste-from-shell
9576        // artifacts).
9577        let d = dep_with_fonte(DepSource::Path {
9578            caminho: "../foo&sleep/".into(),
9579        });
9580        let err = d.validate().unwrap_err();
9581        assert!(
9582            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9583            "got {err:?}",
9584        );
9585    }
9586
9587    #[test]
9588    fn fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho() {
9589        // Diagnostic-shape pin (peer with
9590        // `fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho`
9591        // on the closest single-byte peer arm): the error's Display
9592        // surfaces the offending `:nome` and the offending `:caminho`
9593        // verbatim, and names the shell-background / logical-AND
9594        // footgun explicitly so a `feira lint` run can render the
9595        // diagnostic without re-parsing.
9596        let d = dep_with_fonte(DepSource::Path {
9597            caminho: "../caixa-teia & sleep 1".into(),
9598        });
9599        let rendered = d.validate().unwrap_err().to_string();
9600        assert!(
9601            rendered.contains("caixa-teia"),
9602            "diagnostic must name the offending dep: {rendered}",
9603        );
9604        assert!(
9605            rendered.contains("../caixa-teia & sleep 1"),
9606            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9607        );
9608        assert!(
9609            rendered.contains('&'),
9610            "diagnostic must reference the ampersand footgun: {rendered:?}",
9611        );
9612        assert!(
9613            rendered.contains("background") || rendered.contains("list-AND"),
9614            "diagnostic must name the shell-background / logical-AND footgun: {rendered:?}",
9615        );
9616    }
9617
9618    #[test]
9619    fn validate_rejects_path_fonte_with_caminho_carrying_backtick() {
9620        // The fail-before-pass-after pin for the canonical shell-
9621        // command-substitution paste footgun: an author copies a
9622        // POSIX legacy backticked one-liner (`"../caixa-teia/`whoami`"`
9623        // — the canonical "I pasted a path that included a `pwd`
9624        // / `whoami` / `date` legacy command-substitution expansion
9625        // out of a shell-history block") and silently passed every
9626        // prior arm (`Path::is_absolute` false on `..`, no control
9627        // bytes, no `\`, no `<` / `>`, no `|`, no `;`, no `&`, doesn't
9628        // end in `/`). The lacre embedded the value verbatim, the
9629        // resolver folded it through `Path::join` looking for a
9630        // literal `./../caixa-teia/`whoami`` subdirectory, and the
9631        // failure surfaced at resolve time with a non-self-locating
9632        // `No such file or directory` error. The new arm moves the
9633        // rejection to validate time and names the offending dep +
9634        // caminho verbatim.
9635        let d = dep_with_fonte(DepSource::Path {
9636            caminho: "../caixa-teia/`whoami`".into(),
9637        });
9638        let err = d.validate().unwrap_err();
9639        let DepError::FonteCaminhoShellCommandSubstitution { nome, caminho } = err else {
9640            panic!("expected FonteCaminhoShellCommandSubstitution, got {err:?}");
9641        };
9642        assert_eq!(nome, "caixa-teia");
9643        assert_eq!(caminho, "../caixa-teia/`whoami`");
9644    }
9645
9646    #[test]
9647    fn validate_rejects_path_fonte_with_caminho_carrying_leading_backtick() {
9648        // Leading-position backtick shape (``"`pwd`/caixa-teia"`` —
9649        // the canonical `<backtick>pwd<backtick>/path` working-
9650        // directory expansion shape every shell-side path-composition
9651        // idiom carries). Pinned separately from the embedded-byte
9652        // shape so the gate covers every position, not only mid-path.
9653        let d = dep_with_fonte(DepSource::Path {
9654            caminho: "`pwd`/caixa-teia".into(),
9655        });
9656        let err = d.validate().unwrap_err();
9657        assert!(
9658            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9659            "got {err:?}",
9660        );
9661    }
9662
9663    #[test]
9664    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backtick() {
9665        // Trailing-position backtick shape (`"../caixa-teia`"` — the
9666        // degenerate "I selected an unbalanced backtick out of a
9667        // shell-history block" idiom that probes for the cascade's
9668        // last-byte handling). The trailing-`/` arm fires only on
9669        // last-byte `/`; an unbalanced trailing backtick must route
9670        // through this arm regardless of position.
9671        let d = dep_with_fonte(DepSource::Path {
9672            caminho: "../caixa-teia`".into(),
9673        });
9674        let err = d.validate().unwrap_err();
9675        assert!(
9676            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9677            "got {err:?}",
9678        );
9679    }
9680
9681    #[test]
9682    fn validate_rejects_path_fonte_with_caminho_carrying_balanced_backtick_pair() {
9683        // The canonical balanced-pair shape (``"../<backtick>cat
9684        // /etc/passwd<backtick>"`` — the canonical CWE-78 shell-
9685        // command-injection paste idiom every shell-side hardening
9686        // guide enumerates first). The arm fires on the first
9687        // backtick encountered; pinned so a future arm that tries to
9688        // distinguish the opening from the closing byte doesn't break
9689        // the broader contract.
9690        let d = dep_with_fonte(DepSource::Path {
9691            caminho: "../`cat /etc/passwd`".into(),
9692        });
9693        let err = d.validate().unwrap_err();
9694        assert!(
9695            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9696            "got {err:?}",
9697        );
9698    }
9699
9700    #[test]
9701    fn validate_accepts_path_fonte_with_caminho_carrying_no_backtick() {
9702        // The positive-control pin: the gate targets only the
9703        // backtick byte, never adjacent printable ASCII or POSIX-
9704        // valid bytes. The canonical relative POSIX path
9705        // (`"../caixa-teia"`) and a nested deeply-pathed variant with
9706        // adjacent printable punctuation
9707        // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9708        // cleanly so the gate doesn't widen to a "no printable
9709        // punctuation anywhere" sweep that would defeat the entire
9710        // path-fonte author surface.
9711        let d = dep_with_fonte(DepSource::Path {
9712            caminho: "../caixa-teia/sub-dir.v2".into(),
9713        });
9714        d.validate().unwrap();
9715    }
9716
9717    #[test]
9718    fn fonte_caminho_shell_background_fires_before_shell_command_substitution() {
9719        // Cascade pin on the immediate-predecessor arm: a value
9720        // carrying both `&` and a backtick (``"../caixa-teia &
9721        // <backtick>sleep 1<backtick>"`` — the canonical "I pasted a
9722        // `cmd & <backtick>sleep N<backtick>` background-launch +
9723        // command-substitution chain" footgun) routes through
9724        // `FonteCaminhoShellBackground` not
9725        // `FonteCaminhoShellCommandSubstitution`. The background-
9726        // launch tail is the more common shell-history paste idiom
9727        // on every probe-as-both value — same cascade discipline
9728        // every prior `:caminho` arm establishes.
9729        let d = dep_with_fonte(DepSource::Path {
9730            caminho: "../caixa-teia & `sleep 1`".into(),
9731        });
9732        let err = d.validate().unwrap_err();
9733        assert!(
9734            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9735            "got {err:?}",
9736        );
9737    }
9738
9739    #[test]
9740    fn fonte_caminho_shell_semicolon_fires_before_shell_command_substitution() {
9741        // Cascade pin on the upstream shell-semicolon arm: a value
9742        // carrying both `;` and a backtick (``"../caixa-teia;
9743        // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9744        // `cmd; <backtick>follow-up<backtick>` sequential-chain
9745        // footgun) routes through `FonteCaminhoShellSemicolon` not
9746        // `FonteCaminhoShellCommandSubstitution`. The sequential-
9747        // command-separator paste is the load-bearing root-cause
9748        // edit on every probe-as-both value.
9749        let d = dep_with_fonte(DepSource::Path {
9750            caminho: "../caixa-teia; `whoami`".into(),
9751        });
9752        let err = d.validate().unwrap_err();
9753        assert!(
9754            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9755            "got {err:?}",
9756        );
9757    }
9758
9759    #[test]
9760    fn fonte_caminho_shell_pipe_fires_before_shell_command_substitution() {
9761        // Cascade pin on the upstream shell-pipe arm: a value
9762        // carrying both `|` and a backtick (``"../caixa-teia |
9763        // <backtick>tee log<backtick>"`` — the canonical pipeline-to-
9764        // command-substitution paste idiom) routes through
9765        // `FonteCaminhoShellPipe` not
9766        // `FonteCaminhoShellCommandSubstitution`. The pipeline-tail
9767        // paste is the load-bearing root-cause edit on every
9768        // probe-as-both value.
9769        let d = dep_with_fonte(DepSource::Path {
9770            caminho: "../caixa-teia | `tee log`".into(),
9771        });
9772        let err = d.validate().unwrap_err();
9773        assert!(
9774            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9775            "got {err:?}",
9776        );
9777    }
9778
9779    #[test]
9780    fn fonte_caminho_shell_redirection_fires_before_shell_command_substitution() {
9781        // Cascade pin on the upstream shell-redirection arm: a value
9782        // carrying both `>` and a backtick (``"../caixa-teia>log
9783        // <backtick>date<backtick>"`` — the canonical "I pasted a
9784        // `cmd > log <backtick>date<backtick>` redirect-plus-
9785        // substitution chain" footgun) routes through
9786        // `FonteCaminhoShellRedirection` not
9787        // `FonteCaminhoShellCommandSubstitution`. The input/output
9788        // redirection metachar carries the more self-locating `byte`
9789        // payload (it names which of `<` or `>` triggered), so the
9790        // prior arm wins on every probe-as-both value.
9791        let d = dep_with_fonte(DepSource::Path {
9792            caminho: "../caixa-teia>log `date`".into(),
9793        });
9794        let err = d.validate().unwrap_err();
9795        assert!(
9796            matches!(
9797                err,
9798                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9799            ),
9800            "got {err:?}",
9801        );
9802    }
9803
9804    #[test]
9805    fn fonte_caminho_backslash_fires_before_shell_command_substitution() {
9806        // Cascade pin on the upstream backslash arm: a value
9807        // carrying both `\` and a backtick (``"..\caixa-teia
9808        // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9809        // Windows-shell `cd ..\path <backtick>whoami<backtick>`
9810        // chain") routes through `FonteCaminhoBackslash` not
9811        // `FonteCaminhoShellCommandSubstitution`. The cross-host-OS-
9812        // separator divergence is the load-bearing axis on every
9813        // probe-as-both value (an author who removes the `\` is the
9814        // root-cause edit; the backtick falls away in the same edit
9815        // since it's downstream of the Windows-shell convention).
9816        let d = dep_with_fonte(DepSource::Path {
9817            caminho: "..\\caixa-teia `whoami`".into(),
9818        });
9819        let err = d.validate().unwrap_err();
9820        assert!(
9821            matches!(err, DepError::FonteCaminhoBackslash { .. }),
9822            "got {err:?}",
9823        );
9824    }
9825
9826    #[test]
9827    fn fonte_caminho_control_char_fires_before_shell_command_substitution() {
9828        // Cascade pin on the embedded-control-byte arm: a value
9829        // carrying both a control byte and a backtick (`"../foo\n
9830        // `whoami`"` — the canonical paste-from-multiline-doc
9831        // footgun where a newline landed mid-caminho between two
9832        // paste fragments) routes through `FonteCaminhoControlChar`
9833        // not `FonteCaminhoShellCommandSubstitution`. The POSIX-
9834        // syscall-rejected-byte / NUL-`CString::new`-fail diagnostic
9835        // is the load-bearing axis on every value that probes
9836        // positive for both — mirrors the cascade discipline on
9837        // every prior arm.
9838        let d = dep_with_fonte(DepSource::Path {
9839            caminho: "../foo\n`whoami`".into(),
9840        });
9841        let err = d.validate().unwrap_err();
9842        assert!(
9843            matches!(err, DepError::FonteCaminhoControlChar { .. }),
9844            "got {err:?}",
9845        );
9846    }
9847
9848    #[test]
9849    fn fonte_caminho_absolute_fires_before_shell_command_substitution() {
9850        // Cascade pin on the load-bearing leading-byte arm: a
9851        // leading `/` value with embedded backtick (``"/etc/passwd
9852        // <backtick>whoami<backtick>"``) routes through
9853        // `FonteCaminhoAbsolute` not
9854        // `FonteCaminhoShellCommandSubstitution` — the host-layout-
9855        // leak diagnostic is the load-bearing axis, the backtick
9856        // byte is the secondary observation. Same precedence logic
9857        // as every prior leading-byte arm.
9858        let d = dep_with_fonte(DepSource::Path {
9859            caminho: "/etc/passwd `whoami`".into(),
9860        });
9861        let err = d.validate().unwrap_err();
9862        assert!(
9863            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9864            "got {err:?}",
9865        );
9866    }
9867
9868    #[test]
9869    fn fonte_caminho_shell_command_substitution_fires_before_trailing_slash() {
9870        // Cascade pin on the immediate-successor arm: a value
9871        // carrying both a backtick and a trailing `/`
9872        // (``"../`whoami`/"`` — the canonical "I tab-completed a
9873        // path that already had a backticked `whoami` substitution
9874        // tail" footgun) routes through
9875        // `FonteCaminhoShellCommandSubstitution` not
9876        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
9877        // is the more semantic-locating axis (an author who removes
9878        // the backtick typically also drops the trailing separator
9879        // since both are paste-from-shell artifacts).
9880        let d = dep_with_fonte(DepSource::Path {
9881            caminho: "../`whoami`/".into(),
9882        });
9883        let err = d.validate().unwrap_err();
9884        assert!(
9885            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9886            "got {err:?}",
9887        );
9888    }
9889
9890    #[test]
9891    fn fonte_caminho_shell_command_substitution_diagnostic_carries_offending_dep_and_caminho() {
9892        // Diagnostic-shape pin (peer with
9893        // `fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho`
9894        // on the closest single-byte peer arm): the error's Display
9895        // surfaces the offending `:nome` and the offending `:caminho`
9896        // verbatim, and names the shell-command-substitution footgun
9897        // explicitly so a `feira lint` run can render the diagnostic
9898        // without re-parsing.
9899        let d = dep_with_fonte(DepSource::Path {
9900            caminho: "../caixa-teia/`whoami`".into(),
9901        });
9902        let rendered = d.validate().unwrap_err().to_string();
9903        assert!(
9904            rendered.contains("caixa-teia"),
9905            "diagnostic must name the offending dep: {rendered}",
9906        );
9907        assert!(
9908            rendered.contains("../caixa-teia/`whoami`"),
9909            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9910        );
9911        assert!(
9912            rendered.contains('`'),
9913            "diagnostic must reference the backtick footgun: {rendered:?}",
9914        );
9915        assert!(
9916            rendered.contains("command-substitution"),
9917            "diagnostic must name the shell-command-substitution footgun: {rendered:?}",
9918        );
9919    }
9920
9921    #[test]
9922    fn validate_rejects_path_fonte_with_caminho_carrying_star_glob() {
9923        // The fail-before-pass-after pin for the canonical pathname-
9924        // expansion paste footgun: an author copies an `ls
9925        // ../caixa-teia/*` shell-listing tail into the `:caminho`
9926        // slot and silently passes every prior arm
9927        // (`Path::is_absolute` false on `..`, no control bytes, no
9928        // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick,
9929        // doesn't end in `/`). The lacre embedded the value
9930        // verbatim, the resolver folded it through `Path::join`
9931        // looking for a literal `./../caixa-teia/*` subdirectory,
9932        // and the failure surfaced at resolve time with a non-self-
9933        // locating `No such file or directory` error. The new arm
9934        // moves the rejection to validate time and names the
9935        // offending dep + caminho + byte verbatim.
9936        let d = dep_with_fonte(DepSource::Path {
9937            caminho: "../caixa-teia/*".into(),
9938        });
9939        let err = d.validate().unwrap_err();
9940        let DepError::FonteCaminhoShellGlob {
9941            nome,
9942            caminho,
9943            byte,
9944        } = err
9945        else {
9946            panic!("expected FonteCaminhoShellGlob, got {err:?}");
9947        };
9948        assert_eq!(nome, "caixa-teia");
9949        assert_eq!(caminho, "../caixa-teia/*");
9950        assert_eq!(byte, b'*');
9951    }
9952
9953    #[test]
9954    fn validate_rejects_path_fonte_with_caminho_carrying_question_glob() {
9955        // The symmetric single-char-wildcard paste shape
9956        // (`"../foo?"` — the canonical "I copied a `rm foo?` line
9957        // out of shell history" idiom). Pinned separately from the
9958        // `*` shape so the gate's contract is "any `*` or `?`
9959        // anywhere", not single-byte coverage.
9960        let d = dep_with_fonte(DepSource::Path {
9961            caminho: "../foo?".into(),
9962        });
9963        let err = d.validate().unwrap_err();
9964        let DepError::FonteCaminhoShellGlob { byte, .. } = err else {
9965            panic!("expected FonteCaminhoShellGlob, got {err:?}");
9966        };
9967        assert_eq!(byte, b'?');
9968    }
9969
9970    #[test]
9971    fn validate_rejects_path_fonte_with_caminho_carrying_leading_star_glob() {
9972        // Leading-position `*` shape (`"*/caixa-teia"` — the
9973        // degenerate "I selected only the wildcard prefix out of a
9974        // shell-glob expression" idiom). Pinned separately from the
9975        // embedded-byte shapes so the gate covers every position,
9976        // not only mid-path.
9977        let d = dep_with_fonte(DepSource::Path {
9978            caminho: "*/caixa-teia".into(),
9979        });
9980        let err = d.validate().unwrap_err();
9981        assert!(
9982            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
9983            "got {err:?}",
9984        );
9985    }
9986
9987    #[test]
9988    fn validate_rejects_path_fonte_with_caminho_carrying_double_star_recursive_glob() {
9989        // The bash/zsh `globstar` recursive-glob shape
9990        // (`"../caixa-teia/**/foo"` — the canonical "I copied a
9991        // `find ../caixa-teia/**/foo` recursive expansion" idiom).
9992        // The arm fires on the first `*` encountered; pinned so a
9993        // future arm that tries to distinguish single `*` from
9994        // double `**` doesn't break the broader contract.
9995        let d = dep_with_fonte(DepSource::Path {
9996            caminho: "../caixa-teia/**/foo".into(),
9997        });
9998        let err = d.validate().unwrap_err();
9999        assert!(
10000            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10001            "got {err:?}",
10002        );
10003    }
10004
10005    #[test]
10006    fn validate_rejects_path_fonte_with_caminho_carrying_dotted_extension_glob() {
10007        // The canonical extension-glob shape (`"../caixa-teia/*.lisp"`
10008        // — the "I selected `*.lisp` to mean every Lisp source file
10009        // in the dep root" footgun the prior arms structurally
10010        // cannot catch since `.` is a POSIX-valid path-component
10011        // byte). Pinned so the gate's contract covers the most
10012        // idiomatic glob-paste shape every author meets first.
10013        let d = dep_with_fonte(DepSource::Path {
10014            caminho: "../caixa-teia/*.lisp".into(),
10015        });
10016        let err = d.validate().unwrap_err();
10017        assert!(
10018            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10019            "got {err:?}",
10020        );
10021    }
10022
10023    #[test]
10024    fn validate_accepts_path_fonte_with_caminho_carrying_no_glob() {
10025        // The positive-control pin: the gate targets only `*` /
10026        // `?`, never adjacent printable ASCII or POSIX-valid bytes.
10027        // The canonical relative POSIX path (`"../caixa-teia"`) and
10028        // a nested deeply-pathed variant with adjacent printable
10029        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
10030        // to validate cleanly so the gate doesn't widen to a "no
10031        // printable punctuation anywhere" sweep that would defeat
10032        // the entire path-fonte author surface.
10033        let d = dep_with_fonte(DepSource::Path {
10034            caminho: "../caixa-teia/sub-dir.v2".into(),
10035        });
10036        d.validate().unwrap();
10037    }
10038
10039    #[test]
10040    fn fonte_caminho_shell_command_substitution_fires_before_shell_glob() {
10041        // Cascade pin on the immediate-predecessor arm: a value
10042        // carrying both a backtick and `*` (``"../`whoami`/*"`` —
10043        // the canonical "I pasted a `cd <backtick>whoami<backtick>/*`
10044        // command-substitution + glob chain") routes through
10045        // `FonteCaminhoShellCommandSubstitution` not
10046        // `FonteCaminhoShellGlob`. The CWE-78 shell-command-
10047        // injection vector is the load-bearing root-cause edit on
10048        // every probe-as-both value — same cascade discipline every
10049        // prior `:caminho` arm establishes.
10050        let d = dep_with_fonte(DepSource::Path {
10051            caminho: "../`whoami`/*".into(),
10052        });
10053        let err = d.validate().unwrap_err();
10054        assert!(
10055            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10056            "got {err:?}",
10057        );
10058    }
10059
10060    #[test]
10061    fn fonte_caminho_shell_background_fires_before_shell_glob() {
10062        // Cascade pin on the upstream shell-background arm: a value
10063        // carrying both `&` and `*` (`"../caixa-teia & ls /*"` — the
10064        // canonical "I pasted a `cmd & ls /*` background + glob
10065        // chain" footgun) routes through `FonteCaminhoShellBackground`
10066        // not `FonteCaminhoShellGlob`. The background-launch tail is
10067        // the load-bearing root-cause edit on every probe-as-both
10068        // value.
10069        let d = dep_with_fonte(DepSource::Path {
10070            caminho: "../caixa-teia & ls /*".into(),
10071        });
10072        let err = d.validate().unwrap_err();
10073        assert!(
10074            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10075            "got {err:?}",
10076        );
10077    }
10078
10079    #[test]
10080    fn fonte_caminho_shell_semicolon_fires_before_shell_glob() {
10081        // Cascade pin on the upstream shell-semicolon arm: a value
10082        // carrying both `;` and `*` (`"../caixa-teia; rm *"` — the
10083        // canonical sequential-cleanup + glob paste idiom) routes
10084        // through `FonteCaminhoShellSemicolon` not
10085        // `FonteCaminhoShellGlob`. The sequential-command-separator
10086        // paste is the load-bearing root-cause edit on every
10087        // probe-as-both value.
10088        let d = dep_with_fonte(DepSource::Path {
10089            caminho: "../caixa-teia; rm *".into(),
10090        });
10091        let err = d.validate().unwrap_err();
10092        assert!(
10093            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10094            "got {err:?}",
10095        );
10096    }
10097
10098    #[test]
10099    fn fonte_caminho_shell_pipe_fires_before_shell_glob() {
10100        // Cascade pin on the upstream shell-pipe arm: a value
10101        // carrying both `|` and `*` (`"../caixa-teia | ls *"` — the
10102        // canonical pipeline-to-glob paste idiom) routes through
10103        // `FonteCaminhoShellPipe` not `FonteCaminhoShellGlob`. The
10104        // pipeline-tail paste is the load-bearing root-cause edit
10105        // on every probe-as-both value.
10106        let d = dep_with_fonte(DepSource::Path {
10107            caminho: "../caixa-teia | ls *".into(),
10108        });
10109        let err = d.validate().unwrap_err();
10110        assert!(
10111            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10112            "got {err:?}",
10113        );
10114    }
10115
10116    #[test]
10117    fn fonte_caminho_shell_redirection_fires_before_shell_glob() {
10118        // Cascade pin on the upstream shell-redirection arm: a value
10119        // carrying both `>` and `*` (`"../caixa-teia>log *"` — the
10120        // canonical "I pasted a `cmd > log *` redirect-plus-glob
10121        // chain" footgun) routes through
10122        // `FonteCaminhoShellRedirection` not `FonteCaminhoShellGlob`.
10123        // The input/output redirection metachar carries the more
10124        // self-locating `byte` payload (it names which of `<` or `>`
10125        // triggered), so the prior arm wins on every probe-as-both
10126        // value.
10127        let d = dep_with_fonte(DepSource::Path {
10128            caminho: "../caixa-teia>log *".into(),
10129        });
10130        let err = d.validate().unwrap_err();
10131        assert!(
10132            matches!(
10133                err,
10134                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10135            ),
10136            "got {err:?}",
10137        );
10138    }
10139
10140    #[test]
10141    fn fonte_caminho_backslash_fires_before_shell_glob() {
10142        // Cascade pin on the upstream backslash arm: a value
10143        // carrying both `\` and `*` (`"..\caixa-teia\*"` — the
10144        // canonical "I pasted a Windows-shell `cd ..\path\*` glob
10145        // expression" footgun) routes through
10146        // `FonteCaminhoBackslash` not `FonteCaminhoShellGlob`. The
10147        // cross-host-OS-separator divergence is the load-bearing
10148        // axis on every probe-as-both value (an author who removes
10149        // the `\` is the root-cause edit; the `*` falls away in the
10150        // same edit since it's downstream of the Windows-shell
10151        // convention).
10152        let d = dep_with_fonte(DepSource::Path {
10153            caminho: "..\\caixa-teia\\*".into(),
10154        });
10155        let err = d.validate().unwrap_err();
10156        assert!(
10157            matches!(err, DepError::FonteCaminhoBackslash { .. }),
10158            "got {err:?}",
10159        );
10160    }
10161
10162    #[test]
10163    fn fonte_caminho_control_char_fires_before_shell_glob() {
10164        // Cascade pin on the embedded-control-byte arm: a value
10165        // carrying both a control byte and `*` (`"../foo\n*"` — the
10166        // canonical paste-from-multiline-doc footgun where a
10167        // newline landed mid-caminho between two paste fragments)
10168        // routes through `FonteCaminhoControlChar` not
10169        // `FonteCaminhoShellGlob`. The POSIX-syscall-rejected-byte /
10170        // NUL-`CString::new`-fail diagnostic is the load-bearing
10171        // axis on every value that probes positive for both —
10172        // mirrors the cascade discipline on every prior arm.
10173        let d = dep_with_fonte(DepSource::Path {
10174            caminho: "../foo\n*".into(),
10175        });
10176        let err = d.validate().unwrap_err();
10177        assert!(
10178            matches!(err, DepError::FonteCaminhoControlChar { .. }),
10179            "got {err:?}",
10180        );
10181    }
10182
10183    #[test]
10184    fn fonte_caminho_absolute_fires_before_shell_glob() {
10185        // Cascade pin on the load-bearing leading-byte arm: a
10186        // leading `/` value with embedded `*` (`"/etc/*"`) routes
10187        // through `FonteCaminhoAbsolute` not `FonteCaminhoShellGlob`
10188        // — the host-layout-leak diagnostic is the load-bearing
10189        // axis, the glob byte is the secondary observation. Same
10190        // precedence logic as every prior leading-byte arm.
10191        let d = dep_with_fonte(DepSource::Path {
10192            caminho: "/etc/*".into(),
10193        });
10194        let err = d.validate().unwrap_err();
10195        assert!(
10196            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10197            "got {err:?}",
10198        );
10199    }
10200
10201    #[test]
10202    fn fonte_caminho_shell_glob_fires_before_trailing_slash() {
10203        // Cascade pin on the immediate-successor arm: a value
10204        // carrying both `*` and a trailing `/` (`"../foo*/"` — the
10205        // canonical "I tab-completed a path that already had a
10206        // glob-expansion tail" footgun) routes through
10207        // `FonteCaminhoShellGlob` not `FonteCaminhoTrailingSlash`.
10208        // The embedded shell-metachar is the more semantic-locating
10209        // axis (an author who removes the `*` typically also drops
10210        // the trailing separator since both are paste-from-shell
10211        // artifacts).
10212        let d = dep_with_fonte(DepSource::Path {
10213            caminho: "../foo*/".into(),
10214        });
10215        let err = d.validate().unwrap_err();
10216        assert!(
10217            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10218            "got {err:?}",
10219        );
10220    }
10221
10222    #[test]
10223    fn fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte() {
10224        // Diagnostic-shape pin (peer with
10225        // `fonte_caminho_shell_redirection_diagnostic_*` on the
10226        // closest two-byte peer arm): the error's Display surfaces
10227        // the offending `:nome`, the offending `:caminho` verbatim,
10228        // the offending byte's hex / character form, and names the
10229        // shell-glob / pathname-expansion footgun explicitly so a
10230        // `feira lint` run can render the diagnostic without
10231        // re-parsing.
10232        let d = dep_with_fonte(DepSource::Path {
10233            caminho: "../caixa-teia/*.lisp".into(),
10234        });
10235        let rendered = d.validate().unwrap_err().to_string();
10236        assert!(
10237            rendered.contains("caixa-teia"),
10238            "diagnostic must name the offending dep: {rendered}",
10239        );
10240        assert!(
10241            rendered.contains("../caixa-teia/*.lisp"),
10242            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10243        );
10244        assert!(
10245            rendered.contains("0x2a"),
10246            "diagnostic must surface the offending byte hex: {rendered:?}",
10247        );
10248        assert!(
10249            rendered.contains("glob"),
10250            "diagnostic must name the shell-glob footgun: {rendered:?}",
10251        );
10252        assert!(
10253            rendered.contains("pathname-expansion"),
10254            "diagnostic must reference the POSIX pathname-expansion vocabulary: {rendered:?}",
10255        );
10256    }
10257
10258    #[test]
10259    fn validate_rejects_path_fonte_with_caminho_carrying_modern_command_substitution() {
10260        // The fail-before-pass-after pin for the canonical modern-Bourne
10261        // command-substitution paste footgun: an author copies a
10262        // `cd ../caixa-teia/$(date)/build` shell-history one-liner whose
10263        // `$(<cmd>)` expansion would land the current date as a
10264        // subdirectory name and silently passed every prior arm
10265        // (`Path::is_absolute` false on `..`, no control bytes, no `\`,
10266        // no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no `*` /
10267        // `?`, doesn't end in `/`; the leading-`$` f4efe9c
10268        // `FonteCaminhoVarExpansion` arm doesn't fire because the `$`
10269        // sits mid-path). The lacre embedded the value verbatim, the
10270        // resolver folded it through `Path::join` looking for a literal
10271        // `./../caixa-teia/$(date)/build` subdirectory, and the failure
10272        // surfaced at resolve time with a non-self-locating `No such
10273        // file or directory` error. The new arm moves the rejection to
10274        // validate time and names the offending dep + caminho + byte
10275        // verbatim. The arm fires on the first `(` encountered (the
10276        // opening byte of `$(date)`).
10277        let d = dep_with_fonte(DepSource::Path {
10278            caminho: "../caixa-teia/$(date)/build".into(),
10279        });
10280        let err = d.validate().unwrap_err();
10281        let DepError::FonteCaminhoShellSubshellGrouping {
10282            nome,
10283            caminho,
10284            byte,
10285        } = err
10286        else {
10287            panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10288        };
10289        assert_eq!(nome, "caixa-teia");
10290        assert_eq!(caminho, "../caixa-teia/$(date)/build");
10291        assert_eq!(byte, b'(');
10292    }
10293
10294    #[test]
10295    fn validate_rejects_path_fonte_with_caminho_carrying_close_paren() {
10296        // The symmetric close-paren paste shape (`"../caixa-teia)"` —
10297        // the degenerate "I selected an unbalanced closing paren out of
10298        // a shell-history block" idiom that probes for the cascade's
10299        // last-byte handling on a value carrying only the closing byte).
10300        // Pinned separately from the open-paren shape so the gate's
10301        // contract is "any `(` or `)` anywhere", not single-byte
10302        // coverage. Mirrors the peer `validate_rejects_path_fonte_with_\
10303        // caminho_carrying_question_glob` shape on the immediate-
10304        // predecessor `FonteCaminhoShellGlob` arm.
10305        let d = dep_with_fonte(DepSource::Path {
10306            caminho: "../caixa-teia)".into(),
10307        });
10308        let err = d.validate().unwrap_err();
10309        let DepError::FonteCaminhoShellSubshellGrouping { byte, .. } = err else {
10310            panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10311        };
10312        assert_eq!(byte, b')');
10313    }
10314
10315    #[test]
10316    fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_paren() {
10317        // Leading-position `(` shape (`"(cd foo)/caixa-teia"` — the
10318        // canonical "I selected a `(cd foo)` subshell-grouping prefix
10319        // out of a `(cd foo) && cmd` shell-history one-liner" idiom).
10320        // Pinned separately from the embedded-byte shape so the gate
10321        // covers every position, not only mid-path.
10322        let d = dep_with_fonte(DepSource::Path {
10323            caminho: "(cd foo)/caixa-teia".into(),
10324        });
10325        let err = d.validate().unwrap_err();
10326        assert!(
10327            matches!(
10328                err,
10329                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10330            ),
10331            "got {err:?}",
10332        );
10333    }
10334
10335    #[test]
10336    fn validate_rejects_path_fonte_with_caminho_carrying_balanced_subshell_grouping_pair() {
10337        // The canonical balanced-pair shape (`"../(pwd)/caixa-teia"`
10338        // — the canonical "I copied a `(pwd)` working-directory-probe
10339        // subshell-grouping idiom every shell-history block carries"
10340        // footgun). The value carries no other cascade-preceding
10341        // shell metachar (`&` / `;` / `|` / `<` / `>` / backtick /
10342        // `*` / `?`) so the arm fires on the first `(` encountered;
10343        // pinned so a future arm that tries to distinguish the
10344        // opening from the closing byte doesn't break the broader
10345        // contract. Mirrors the peer
10346        // `validate_rejects_path_fonte_with_caminho_carrying_balanced_\
10347        // backtick_pair` shape on the upstream `FonteCaminhoShell\
10348        // CommandSubstitution` arm.
10349        let d = dep_with_fonte(DepSource::Path {
10350            caminho: "../(pwd)/caixa-teia".into(),
10351        });
10352        let err = d.validate().unwrap_err();
10353        assert!(
10354            matches!(
10355                err,
10356                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10357            ),
10358            "got {err:?}",
10359        );
10360    }
10361
10362    #[test]
10363    fn validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping() {
10364        // The positive-control pin: the gate targets only `(` / `)`,
10365        // never adjacent printable ASCII or POSIX-valid bytes. The
10366        // canonical relative POSIX path (`"../caixa-teia"`) and a
10367        // nested deeply-pathed variant with adjacent printable
10368        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10369        // validate cleanly so the gate doesn't widen to a "no printable
10370        // punctuation anywhere" sweep that would defeat the entire
10371        // path-fonte author surface.
10372        let d = dep_with_fonte(DepSource::Path {
10373            caminho: "../caixa-teia/sub-dir.v2".into(),
10374        });
10375        d.validate().unwrap();
10376    }
10377
10378    #[test]
10379    fn fonte_caminho_shell_glob_fires_before_shell_subshell_grouping() {
10380        // Cascade pin on the immediate-predecessor arm: a value
10381        // carrying both `*` and `(` (`"../caixa-teia/*(date)"` — the
10382        // canonical "I pasted a glob expansion followed by a
10383        // subshell-grouping tail" footgun) routes through
10384        // `FonteCaminhoShellGlob` not
10385        // `FonteCaminhoShellSubshellGrouping`. The pathname-expansion
10386        // shape is the more common shell-history paste idiom on every
10387        // probe-as-both value — same cascade discipline every prior
10388        // `:caminho` arm establishes.
10389        let d = dep_with_fonte(DepSource::Path {
10390            caminho: "../caixa-teia/*(date)".into(),
10391        });
10392        let err = d.validate().unwrap_err();
10393        assert!(
10394            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10395            "got {err:?}",
10396        );
10397    }
10398
10399    #[test]
10400    fn fonte_caminho_shell_command_substitution_fires_before_shell_subshell_grouping() {
10401        // Cascade pin on the upstream shell-command-substitution arm: a
10402        // value carrying both a backtick and `(` (``"../`whoami`/$(date)"``
10403        // — the canonical "I pasted a legacy-backtick + modern-paren
10404        // command-substitution chain" footgun) routes through
10405        // `FonteCaminhoShellCommandSubstitution` not
10406        // `FonteCaminhoShellSubshellGrouping`. The CWE-78 shell-
10407        // command-injection vector is the load-bearing root-cause edit
10408        // on every probe-as-both value.
10409        let d = dep_with_fonte(DepSource::Path {
10410            caminho: "../`whoami`/$(date)".into(),
10411        });
10412        let err = d.validate().unwrap_err();
10413        assert!(
10414            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10415            "got {err:?}",
10416        );
10417    }
10418
10419    #[test]
10420    fn fonte_caminho_shell_background_fires_before_shell_subshell_grouping() {
10421        // Cascade pin on the upstream shell-background arm: a value
10422        // carrying both `&` and `(` (`"../caixa-teia & (cd foo)"` —
10423        // the canonical "I pasted a `cmd & (cd foo)` background-launch
10424        // + subshell-grouping chain" footgun) routes through
10425        // `FonteCaminhoShellBackground` not
10426        // `FonteCaminhoShellSubshellGrouping`. The background-launch
10427        // tail is the load-bearing root-cause edit on every probe-as-
10428        // both value.
10429        let d = dep_with_fonte(DepSource::Path {
10430            caminho: "../caixa-teia & (cd foo)".into(),
10431        });
10432        let err = d.validate().unwrap_err();
10433        assert!(
10434            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10435            "got {err:?}",
10436        );
10437    }
10438
10439    #[test]
10440    fn fonte_caminho_shell_semicolon_fires_before_shell_subshell_grouping() {
10441        // Cascade pin on the upstream shell-semicolon arm: a value
10442        // carrying both `;` and `(` (`"../caixa-teia; (cd foo)"` —
10443        // the canonical sequential-cleanup + subshell-grouping paste
10444        // idiom) routes through `FonteCaminhoShellSemicolon` not
10445        // `FonteCaminhoShellSubshellGrouping`. The sequential-command-
10446        // separator paste is the load-bearing root-cause edit on
10447        // every probe-as-both value.
10448        let d = dep_with_fonte(DepSource::Path {
10449            caminho: "../caixa-teia; (cd foo)".into(),
10450        });
10451        let err = d.validate().unwrap_err();
10452        assert!(
10453            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10454            "got {err:?}",
10455        );
10456    }
10457
10458    #[test]
10459    fn fonte_caminho_shell_pipe_fires_before_shell_subshell_grouping() {
10460        // Cascade pin on the upstream shell-pipe arm: a value carrying
10461        // both `|` and `(` (`"../caixa-teia | (tee log)"` — the
10462        // canonical pipeline-to-subshell-grouping paste idiom) routes
10463        // through `FonteCaminhoShellPipe` not
10464        // `FonteCaminhoShellSubshellGrouping`. The pipeline-tail paste
10465        // is the load-bearing root-cause edit on every probe-as-both
10466        // value.
10467        let d = dep_with_fonte(DepSource::Path {
10468            caminho: "../caixa-teia | (tee log)".into(),
10469        });
10470        let err = d.validate().unwrap_err();
10471        assert!(
10472            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10473            "got {err:?}",
10474        );
10475    }
10476
10477    #[test]
10478    fn fonte_caminho_shell_redirection_fires_before_shell_subshell_grouping() {
10479        // Cascade pin on the upstream shell-redirection arm: a value
10480        // carrying both `>` and `(` (`"../caixa-teia>log (cd foo)"` —
10481        // the canonical "I pasted a `cmd > log (cd foo)` redirect-
10482        // plus-subshell-grouping chain" footgun) routes through
10483        // `FonteCaminhoShellRedirection` not
10484        // `FonteCaminhoShellSubshellGrouping`. The input/output
10485        // redirection metachar carries the more self-locating `byte`
10486        // payload (it names which of `<` or `>` triggered), so the
10487        // prior arm wins on every probe-as-both value.
10488        let d = dep_with_fonte(DepSource::Path {
10489            caminho: "../caixa-teia>log (cd foo)".into(),
10490        });
10491        let err = d.validate().unwrap_err();
10492        assert!(
10493            matches!(
10494                err,
10495                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10496            ),
10497            "got {err:?}",
10498        );
10499    }
10500
10501    #[test]
10502    fn fonte_caminho_backslash_fires_before_shell_subshell_grouping() {
10503        // Cascade pin on the upstream backslash arm: a value carrying
10504        // both `\` and `(` (`"..\caixa-teia\(cd foo)"` — the canonical
10505        // "I pasted a Windows-shell `cd ..\path\(cmd)` chain") routes
10506        // through `FonteCaminhoBackslash` not
10507        // `FonteCaminhoShellSubshellGrouping`. The cross-host-OS-
10508        // separator divergence is the load-bearing axis on every
10509        // probe-as-both value (an author who removes the `\` is the
10510        // root-cause edit; the `(` falls away in the same edit since
10511        // it's downstream of the Windows-shell convention).
10512        let d = dep_with_fonte(DepSource::Path {
10513            caminho: "..\\caixa-teia\\(cd foo)".into(),
10514        });
10515        let err = d.validate().unwrap_err();
10516        assert!(
10517            matches!(err, DepError::FonteCaminhoBackslash { .. }),
10518            "got {err:?}",
10519        );
10520    }
10521
10522    #[test]
10523    fn fonte_caminho_control_char_fires_before_shell_subshell_grouping() {
10524        // Cascade pin on the embedded-control-byte arm: a value
10525        // carrying both a control byte and `(` (`"../foo\n(cd bar)"` —
10526        // the canonical paste-from-multiline-doc footgun where a
10527        // newline landed mid-caminho between two paste fragments)
10528        // routes through `FonteCaminhoControlChar` not
10529        // `FonteCaminhoShellSubshellGrouping`. The POSIX-syscall-
10530        // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10531        // load-bearing axis on every value that probes positive for
10532        // both — mirrors the cascade discipline on every prior arm.
10533        let d = dep_with_fonte(DepSource::Path {
10534            caminho: "../foo\n(cd bar)".into(),
10535        });
10536        let err = d.validate().unwrap_err();
10537        assert!(
10538            matches!(err, DepError::FonteCaminhoControlChar { .. }),
10539            "got {err:?}",
10540        );
10541    }
10542
10543    #[test]
10544    fn fonte_caminho_absolute_fires_before_shell_subshell_grouping() {
10545        // Cascade pin on the load-bearing leading-byte arm: a leading
10546        // `/` value with embedded `(` (`"/etc/(cd foo)"`) routes
10547        // through `FonteCaminhoAbsolute` not
10548        // `FonteCaminhoShellSubshellGrouping` — the host-layout-leak
10549        // diagnostic is the load-bearing axis, the subshell-grouping
10550        // byte is the secondary observation. Same precedence logic as
10551        // every prior leading-byte arm.
10552        let d = dep_with_fonte(DepSource::Path {
10553            caminho: "/etc/(cd foo)".into(),
10554        });
10555        let err = d.validate().unwrap_err();
10556        assert!(
10557            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10558            "got {err:?}",
10559        );
10560    }
10561
10562    #[test]
10563    fn fonte_caminho_var_expansion_fires_before_shell_subshell_grouping() {
10564        // Cascade pin on the upstream leading-`$` var-expansion arm: a
10565        // value carrying both a leading `$` and a `(` (`"$(date)/\
10566        // caixa-teia"` — the canonical "I pasted a `$(date)` modern-
10567        // command-substitution at the head of a sibling-workspace
10568        // path" footgun) routes through `FonteCaminhoVarExpansion` not
10569        // `FonteCaminhoShellSubshellGrouping`. The leading-byte
10570        // shell-variable-expansion is the more self-locating diagnostic
10571        // on values that probe as both — same load-bearing-leading-
10572        // byte cascade discipline every prior `:caminho` arm
10573        // establishes. Closing both halves of `$(<cmd>)` structurally
10574        // (leading `$` here, trailing `)` on the new arm) excludes the
10575        // entire modern Bourne command-substitution surface from the
10576        // typed `:caminho` accepted set; the cascade preserves the
10577        // narrower leading-byte diagnostic on values that probe both
10578        // halves at the canonical leading position.
10579        let d = dep_with_fonte(DepSource::Path {
10580            caminho: "$(date)/caixa-teia".into(),
10581        });
10582        let err = d.validate().unwrap_err();
10583        assert!(
10584            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
10585            "got {err:?}",
10586        );
10587    }
10588
10589    #[test]
10590    fn fonte_caminho_shell_subshell_grouping_fires_before_trailing_slash() {
10591        // Cascade pin on the immediate-successor arm: a value carrying
10592        // both `(` and a trailing `/` (`"../(cd foo)/"` — the canonical
10593        // "I tab-completed a path that already had a subshell-grouping
10594        // expansion tail" footgun) routes through
10595        // `FonteCaminhoShellSubshellGrouping` not
10596        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
10597        // the more semantic-locating axis (an author who removes the
10598        // `(` typically also drops the trailing separator since both
10599        // are paste-from-shell artifacts).
10600        let d = dep_with_fonte(DepSource::Path {
10601            caminho: "../(cd foo)/".into(),
10602        });
10603        let err = d.validate().unwrap_err();
10604        assert!(
10605            matches!(
10606                err,
10607                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10608            ),
10609            "got {err:?}",
10610        );
10611    }
10612
10613    #[test]
10614    fn fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
10615        // Diagnostic-shape pin (peer with
10616        // `fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte`
10617        // on the closest two-byte peer arm): the error's Display
10618        // surfaces the offending `:nome`, the offending `:caminho`
10619        // verbatim, the offending byte's hex / character form, and
10620        // names the shell-subshell-grouping footgun explicitly so a
10621        // `feira lint` run can render the diagnostic without re-
10622        // parsing.
10623        let d = dep_with_fonte(DepSource::Path {
10624            caminho: "../caixa-teia/$(date)/build".into(),
10625        });
10626        let rendered = d.validate().unwrap_err().to_string();
10627        assert!(
10628            rendered.contains("caixa-teia"),
10629            "diagnostic must name the offending dep: {rendered}",
10630        );
10631        assert!(
10632            rendered.contains("../caixa-teia/$(date)/build"),
10633            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10634        );
10635        assert!(
10636            rendered.contains("0x28"),
10637            "diagnostic must surface the offending byte hex: {rendered:?}",
10638        );
10639        assert!(
10640            rendered.contains("subshell-grouping"),
10641            "diagnostic must name the shell-subshell-grouping footgun: {rendered:?}",
10642        );
10643        assert!(
10644            rendered.contains("command-substitution"),
10645            "diagnostic must reference the `$(<cmd>)` command-substitution vocabulary: \
10646             {rendered:?}",
10647        );
10648    }
10649
10650    // ── shell-brace-expansion / URI-Template-placeholder arm ───────────
10651    //
10652    // Peer with the prior `FonteCaminhoShellSubshellGrouping` (`(` /
10653    // `)`) byte-pair arm: the same per-byte cascade with the same
10654    // self-locating `byte: u8` diagnostic on the orthogonal `{` /
10655    // `}` brace-expansion / URI-Template placeholder axis. The peer
10656    // [`crate::render::is_git_repo_url`] (42d8f9d) closes the same
10657    // byte pair on the sibling `:fonte :repo` axis under the same
10658    // banner.
10659
10660    #[test]
10661    fn validate_rejects_path_fonte_with_caminho_carrying_brace_expansion_fan_across_siblings() {
10662        // The fail-before-pass-after pin for the canonical paste-from-
10663        // shell-history brace-expansion footgun: an author copies a
10664        // `cd ../{caixa-teia,caixa-helm}/build` shell-history one-
10665        // liner whose `{a,b}` brace expansion fans across two siblings
10666        // and silently passed every prior arm (`Path::is_absolute`
10667        // false on `..`, no control bytes, no `\`, no `<` / `>`, no
10668        // `|`, no `;`, no `&`, no backtick, no `*` / `?`, no `(` /
10669        // `)`, doesn't end in `/`; the leading-`$` f4efe9c
10670        // `FonteCaminhoVarExpansion` arm doesn't fire because the
10671        // value starts with `..` not `$`). The lacre embedded the
10672        // value verbatim, the resolver folded it through `Path::join`
10673        // looking for a literal `./../{caixa-teia,caixa-helm}/build`
10674        // subdirectory, and the failure surfaced at resolve time with
10675        // a non-self-locating `No such file or directory` error. The
10676        // new arm moves the rejection to validate time and names the
10677        // offending dep + caminho + byte verbatim. The arm fires on
10678        // the first `{` encountered.
10679        let d = dep_with_fonte(DepSource::Path {
10680            caminho: "../{caixa-teia,caixa-helm}/build".into(),
10681        });
10682        let err = d.validate().unwrap_err();
10683        let DepError::FonteCaminhoShellBraceExpansion {
10684            nome,
10685            caminho,
10686            byte,
10687        } = err
10688        else {
10689            panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10690        };
10691        assert_eq!(nome, "caixa-teia");
10692        assert_eq!(caminho, "../{caixa-teia,caixa-helm}/build");
10693        assert_eq!(byte, b'{');
10694    }
10695
10696    #[test]
10697    fn validate_rejects_path_fonte_with_caminho_carrying_close_brace() {
10698        // The symmetric close-brace paste shape (`"../caixa-teia}"` —
10699        // the degenerate "I selected an unbalanced closing brace out
10700        // of a shell-history block" idiom that probes for the
10701        // cascade's last-byte handling on a value carrying only the
10702        // closing byte). Pinned separately from the open-brace shape
10703        // so the gate's contract is "any `{` or `}` anywhere", not
10704        // single-byte coverage. Mirrors the peer
10705        // `validate_rejects_path_fonte_with_caminho_carrying_close_paren`
10706        // shape on the immediate-predecessor `FonteCaminhoShellSubshellGrouping`
10707        // arm.
10708        let d = dep_with_fonte(DepSource::Path {
10709            caminho: "../caixa-teia}".into(),
10710        });
10711        let err = d.validate().unwrap_err();
10712        let DepError::FonteCaminhoShellBraceExpansion { byte, .. } = err else {
10713            panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10714        };
10715        assert_eq!(byte, b'}');
10716    }
10717
10718    #[test]
10719    fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_brace() {
10720        // Leading-position `{` shape (`"{caixa-teia,caixa-helm}/build"`
10721        // — the canonical "I selected a `{a,b}` brace-expansion prefix
10722        // out of a shell-history one-liner" idiom). Pinned separately
10723        // from the embedded-byte shape so the gate covers every
10724        // position, not only mid-path.
10725        let d = dep_with_fonte(DepSource::Path {
10726            caminho: "{caixa-teia,caixa-helm}/build".into(),
10727        });
10728        let err = d.validate().unwrap_err();
10729        assert!(
10730            matches!(
10731                err,
10732                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10733            ),
10734            "got {err:?}",
10735        );
10736    }
10737
10738    #[test]
10739    fn validate_rejects_path_fonte_with_caminho_carrying_uri_template_placeholder() {
10740        // The canonical URI-Template / Mustache / Helm doubled-brace
10741        // placeholder shape (`"../{{org}}/caixa-teia"` — the canonical
10742        // "I copied a `https://github.com/{{org}}/caixa-teia` README
10743        // quick-start / OpenAPI spec / Helm chart `home:` template
10744        // and forgot to substitute the placeholder" footgun). The arm
10745        // fires on the first `{` encountered; pinned so the gate's
10746        // coverage extends from the bare-brace shell-history shape to
10747        // the doubled-brace URI-Template / templating-engine shape.
10748        // Mirrors the peer 42d8f9d `is_git_repo_url` arm on the
10749        // sibling `:fonte :repo` axis.
10750        let d = dep_with_fonte(DepSource::Path {
10751            caminho: "../{{org}}/caixa-teia".into(),
10752        });
10753        let err = d.validate().unwrap_err();
10754        assert!(
10755            matches!(
10756                err,
10757                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10758            ),
10759            "got {err:?}",
10760        );
10761    }
10762
10763    #[test]
10764    fn validate_rejects_path_fonte_with_caminho_carrying_brace_range_expansion() {
10765        // The canonical bash brace-range-expansion shape (`"../caixa-
10766        // v{1..10}"` — the `{1..10}` sequence expansion every bash /
10767        // zsh `for i in {1..10}; do …; done` idiom uses, the symmetric
10768        // sequence-range form to the `{a,b,c}` comma-separated form).
10769        // The arm fires on the first `{` encountered; pinned so the
10770        // gate's coverage extends from the comma-separated form to
10771        // the integer-range form.
10772        let d = dep_with_fonte(DepSource::Path {
10773            caminho: "../caixa-v{1..10}".into(),
10774        });
10775        let err = d.validate().unwrap_err();
10776        assert!(
10777            matches!(
10778                err,
10779                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10780            ),
10781            "got {err:?}",
10782        );
10783    }
10784
10785    #[test]
10786    fn validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion() {
10787        // The positive-control pin: the gate targets only `{` / `}`,
10788        // never adjacent printable ASCII or POSIX-valid bytes. The
10789        // canonical relative POSIX path (`"../caixa-teia"`) and a
10790        // nested deeply-pathed variant with adjacent printable
10791        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10792        // validate cleanly so the gate doesn't widen to a "no
10793        // printable punctuation anywhere" sweep that would defeat
10794        // the entire path-fonte author surface. Peer with
10795        // `validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping`
10796        // on the immediate-predecessor arm.
10797        let d = dep_with_fonte(DepSource::Path {
10798            caminho: "../caixa-teia/sub-dir.v2".into(),
10799        });
10800        d.validate().unwrap();
10801    }
10802
10803    #[test]
10804    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_brace_expansion() {
10805        // Cascade pin on the immediate-predecessor arm: a value
10806        // carrying both `(` and `{` (`"../(cd foo)/{a,b}"` — the
10807        // canonical "I pasted a subshell-grouping followed by a
10808        // brace-expansion tail" footgun) routes through
10809        // `FonteCaminhoShellSubshellGrouping` not
10810        // `FonteCaminhoShellBraceExpansion`. The subshell-grouping
10811        // shape is the more semantic-locating axis on every probe-
10812        // as-both value because it closes both halves of the modern
10813        // Bourne `$(<cmd>)` command-substitution surface — same
10814        // cascade discipline every prior `:caminho` arm establishes.
10815        let d = dep_with_fonte(DepSource::Path {
10816            caminho: "../(cd foo)/{a,b}".into(),
10817        });
10818        let err = d.validate().unwrap_err();
10819        assert!(
10820            matches!(
10821                err,
10822                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10823            ),
10824            "got {err:?}",
10825        );
10826    }
10827
10828    #[test]
10829    fn fonte_caminho_shell_glob_fires_before_shell_brace_expansion() {
10830        // Cascade pin on the upstream shell-glob arm: a value carrying
10831        // both `*` and `{` (`"../caixa-teia/*{a,b}"` — the canonical
10832        // "I pasted a glob expansion followed by a brace-expansion
10833        // tail" footgun) routes through `FonteCaminhoShellGlob` not
10834        // `FonteCaminhoShellBraceExpansion`. The pathname-expansion
10835        // shape is the load-bearing root-cause edit on every
10836        // probe-as-both value.
10837        let d = dep_with_fonte(DepSource::Path {
10838            caminho: "../caixa-teia/*{a,b}".into(),
10839        });
10840        let err = d.validate().unwrap_err();
10841        assert!(
10842            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10843            "got {err:?}",
10844        );
10845    }
10846
10847    #[test]
10848    fn fonte_caminho_shell_command_substitution_fires_before_shell_brace_expansion() {
10849        // Cascade pin on the upstream shell-command-substitution arm:
10850        // a value carrying both a backtick and `{` (``"../`whoami`/{a,b}"``
10851        // — the canonical "I pasted a legacy-backtick command-
10852        // substitution followed by a brace-expansion fan-out" footgun)
10853        // routes through `FonteCaminhoShellCommandSubstitution` not
10854        // `FonteCaminhoShellBraceExpansion`. The CWE-78 shell-
10855        // command-injection vector is the load-bearing root-cause
10856        // edit on every probe-as-both value.
10857        let d = dep_with_fonte(DepSource::Path {
10858            caminho: "../`whoami`/{a,b}".into(),
10859        });
10860        let err = d.validate().unwrap_err();
10861        assert!(
10862            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10863            "got {err:?}",
10864        );
10865    }
10866
10867    #[test]
10868    fn fonte_caminho_shell_background_fires_before_shell_brace_expansion() {
10869        // Cascade pin on the upstream shell-background arm: a value
10870        // carrying both `&` and `{` (`"../caixa-teia & {a,b}"` — the
10871        // canonical "I pasted a `cmd & {fork-fan}` background-launch
10872        // + brace-expansion chain" footgun) routes through
10873        // `FonteCaminhoShellBackground` not
10874        // `FonteCaminhoShellBraceExpansion`. The background-launch
10875        // tail is the load-bearing root-cause edit on every
10876        // probe-as-both value.
10877        let d = dep_with_fonte(DepSource::Path {
10878            caminho: "../caixa-teia & {a,b}".into(),
10879        });
10880        let err = d.validate().unwrap_err();
10881        assert!(
10882            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10883            "got {err:?}",
10884        );
10885    }
10886
10887    #[test]
10888    fn fonte_caminho_shell_semicolon_fires_before_shell_brace_expansion() {
10889        // Cascade pin on the upstream shell-semicolon arm: a value
10890        // carrying both `;` and `{` (`"../caixa-teia; {a,b}"` — the
10891        // canonical sequential-cleanup + brace-expansion paste
10892        // idiom) routes through `FonteCaminhoShellSemicolon` not
10893        // `FonteCaminhoShellBraceExpansion`. The sequential-command-
10894        // separator paste is the load-bearing root-cause edit on
10895        // every probe-as-both value.
10896        let d = dep_with_fonte(DepSource::Path {
10897            caminho: "../caixa-teia; {a,b}".into(),
10898        });
10899        let err = d.validate().unwrap_err();
10900        assert!(
10901            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10902            "got {err:?}",
10903        );
10904    }
10905
10906    #[test]
10907    fn fonte_caminho_shell_pipe_fires_before_shell_brace_expansion() {
10908        // Cascade pin on the upstream shell-pipe arm: a value
10909        // carrying both `|` and `{` (`"../caixa-teia | {tee,cat}"`
10910        // — the canonical pipeline-to-brace-expansion paste idiom)
10911        // routes through `FonteCaminhoShellPipe` not
10912        // `FonteCaminhoShellBraceExpansion`. The pipeline-tail paste
10913        // is the load-bearing root-cause edit on every probe-as-
10914        // both value.
10915        let d = dep_with_fonte(DepSource::Path {
10916            caminho: "../caixa-teia | {tee,cat}".into(),
10917        });
10918        let err = d.validate().unwrap_err();
10919        assert!(
10920            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10921            "got {err:?}",
10922        );
10923    }
10924
10925    #[test]
10926    fn fonte_caminho_shell_redirection_fires_before_shell_brace_expansion() {
10927        // Cascade pin on the upstream shell-redirection arm: a value
10928        // carrying both `>` and `{` (`"../caixa-teia>log {a,b}"` —
10929        // the canonical "I pasted a `cmd > log {a,b}` redirect-
10930        // plus-brace-expansion chain" footgun) routes through
10931        // `FonteCaminhoShellRedirection` not
10932        // `FonteCaminhoShellBraceExpansion`. The input/output
10933        // redirection metachar carries the more self-locating
10934        // `byte` payload, so the prior arm wins on every probe-
10935        // as-both value.
10936        let d = dep_with_fonte(DepSource::Path {
10937            caminho: "../caixa-teia>log {a,b}".into(),
10938        });
10939        let err = d.validate().unwrap_err();
10940        assert!(
10941            matches!(
10942                err,
10943                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10944            ),
10945            "got {err:?}",
10946        );
10947    }
10948
10949    #[test]
10950    fn fonte_caminho_backslash_fires_before_shell_brace_expansion() {
10951        // Cascade pin on the upstream backslash arm: a value
10952        // carrying both `\` and `{` (`"..\caixa-teia\{a,b}"` — the
10953        // canonical "I pasted a Windows-shell `cd ..\path\{a,b}`
10954        // chain") routes through `FonteCaminhoBackslash` not
10955        // `FonteCaminhoShellBraceExpansion`. The cross-host-OS-
10956        // separator divergence is the load-bearing axis on every
10957        // probe-as-both value.
10958        let d = dep_with_fonte(DepSource::Path {
10959            caminho: "..\\caixa-teia\\{a,b}".into(),
10960        });
10961        let err = d.validate().unwrap_err();
10962        assert!(
10963            matches!(err, DepError::FonteCaminhoBackslash { .. }),
10964            "got {err:?}",
10965        );
10966    }
10967
10968    #[test]
10969    fn fonte_caminho_control_char_fires_before_shell_brace_expansion() {
10970        // Cascade pin on the embedded-control-byte arm: a value
10971        // carrying both a control byte and `{` (`"../foo\n{a,b}"` —
10972        // the canonical paste-from-multiline-doc footgun where a
10973        // newline landed mid-caminho between two paste fragments)
10974        // routes through `FonteCaminhoControlChar` not
10975        // `FonteCaminhoShellBraceExpansion`. The POSIX-syscall-
10976        // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10977        // load-bearing axis on every value that probes positive for
10978        // both — mirrors the cascade discipline on every prior arm.
10979        let d = dep_with_fonte(DepSource::Path {
10980            caminho: "../foo\n{a,b}".into(),
10981        });
10982        let err = d.validate().unwrap_err();
10983        assert!(
10984            matches!(err, DepError::FonteCaminhoControlChar { .. }),
10985            "got {err:?}",
10986        );
10987    }
10988
10989    #[test]
10990    fn fonte_caminho_absolute_fires_before_shell_brace_expansion() {
10991        // Cascade pin on the load-bearing leading-byte arm: a
10992        // leading `/` value with embedded `{` (`"/etc/{a,b}"`)
10993        // routes through `FonteCaminhoAbsolute` not
10994        // `FonteCaminhoShellBraceExpansion` — the host-layout-leak
10995        // diagnostic is the load-bearing axis, the brace-expansion
10996        // byte is the secondary observation. Same precedence logic
10997        // as every prior leading-byte arm.
10998        let d = dep_with_fonte(DepSource::Path {
10999            caminho: "/etc/{a,b}".into(),
11000        });
11001        let err = d.validate().unwrap_err();
11002        assert!(
11003            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11004            "got {err:?}",
11005        );
11006    }
11007
11008    #[test]
11009    fn fonte_caminho_var_expansion_fires_before_shell_brace_expansion() {
11010        // Cascade pin on the upstream leading-`$` var-expansion
11011        // arm: a value carrying both a leading `$` and a `{`
11012        // (`"${ORG}/caixa-teia"` — the canonical "I pasted a
11013        // `${ORG}` shell-variable + curly-brace expansion at the
11014        // head of a sibling-workspace path" footgun) routes through
11015        // `FonteCaminhoVarExpansion` not
11016        // `FonteCaminhoShellBraceExpansion`. The leading-byte
11017        // shell-variable-expansion is the more self-locating
11018        // diagnostic on values that probe as both — same
11019        // load-bearing-leading-byte cascade discipline every prior
11020        // `:caminho` arm establishes.
11021        let d = dep_with_fonte(DepSource::Path {
11022            caminho: "${ORG}/caixa-teia".into(),
11023        });
11024        let err = d.validate().unwrap_err();
11025        assert!(
11026            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11027            "got {err:?}",
11028        );
11029    }
11030
11031    #[test]
11032    fn fonte_caminho_shell_brace_expansion_fires_before_trailing_slash() {
11033        // Cascade pin on the immediate-successor arm: a value
11034        // carrying both `{` and a trailing `/`
11035        // (`"../{caixa-teia,caixa-helm}/"` — the canonical "I
11036        // tab-completed a path that already had a brace-expansion
11037        // expansion tail" footgun) routes through
11038        // `FonteCaminhoShellBraceExpansion` not
11039        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11040        // is the more semantic-locating axis (an author who removes
11041        // the `{` typically also drops the trailing separator since
11042        // both are paste-from-shell artifacts).
11043        let d = dep_with_fonte(DepSource::Path {
11044            caminho: "../{caixa-teia,caixa-helm}/".into(),
11045        });
11046        let err = d.validate().unwrap_err();
11047        assert!(
11048            matches!(
11049                err,
11050                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11051            ),
11052            "got {err:?}",
11053        );
11054    }
11055
11056    #[test]
11057    fn fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11058        // Diagnostic-shape pin (peer with
11059        // `fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
11060        // on the closest two-byte peer arm): the error's Display
11061        // surfaces the offending `:nome`, the offending `:caminho`
11062        // verbatim, the offending byte's hex / character form, and
11063        // names the shell-brace-expansion / URI-Template footgun
11064        // explicitly so a `feira lint` run can render the diagnostic
11065        // without re-parsing.
11066        let d = dep_with_fonte(DepSource::Path {
11067            caminho: "../{caixa-teia,caixa-helm}/build".into(),
11068        });
11069        let rendered = d.validate().unwrap_err().to_string();
11070        assert!(
11071            rendered.contains("caixa-teia"),
11072            "diagnostic must name the offending dep: {rendered}",
11073        );
11074        assert!(
11075            rendered.contains("../{caixa-teia,caixa-helm}/build"),
11076            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11077        );
11078        assert!(
11079            rendered.contains("0x7b"),
11080            "diagnostic must surface the offending byte hex: {rendered:?}",
11081        );
11082        assert!(
11083            rendered.contains("brace-expansion"),
11084            "diagnostic must name the shell-brace-expansion footgun: {rendered:?}",
11085        );
11086        assert!(
11087            rendered.contains("URI Template"),
11088            "diagnostic must reference the RFC-6570 URI-Template-placeholder vocabulary: \
11089             {rendered:?}",
11090        );
11091    }
11092
11093    #[test]
11094    fn validate_rejects_path_fonte_with_caminho_carrying_bracket_glob_character_class() {
11095        // The canonical paste-from-shell-history bracket-glob /
11096        // character-class footgun: an author copies a
11097        // `cd ../caixa-[a-z]/build` shell-history one-liner whose
11098        // `[a-z]` POSIX glob character-class matches every lowercase-
11099        // ASCII-suffix sibling caixa directory and silently passed
11100        // every prior arm (`Path::is_absolute` false on `..`, no
11101        // control bytes, no `\`, no `<` / `>`, no `|`, no `;`, no
11102        // `&`, no backtick, no `*` / `?`, no `(` / `)`, no `{` /
11103        // `}`, doesn't end in `/`; the leading-`$` f4efe9c
11104        // `FonteCaminhoVarExpansion` arm doesn't fire because the
11105        // value starts with `..` not `$`). The lacre embedded the
11106        // value verbatim, the resolver folded it through
11107        // `Path::join` looking for a literal `./../caixa-[a-z]/
11108        // build` subdirectory, and the failure surfaced at resolve
11109        // time with a non-self-locating `No such file or directory`
11110        // error. The new arm moves the rejection to validate time
11111        // and names the offending dep + caminho + byte verbatim.
11112        // The arm fires on the first `[` encountered.
11113        let d = dep_with_fonte(DepSource::Path {
11114            caminho: "../caixa-[a-z]/build".into(),
11115        });
11116        let err = d.validate().unwrap_err();
11117        let DepError::FonteCaminhoShellBracketExpansion {
11118            nome,
11119            caminho,
11120            byte,
11121        } = err
11122        else {
11123            panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11124        };
11125        assert_eq!(nome, "caixa-teia");
11126        assert_eq!(caminho, "../caixa-[a-z]/build");
11127        assert_eq!(byte, b'[');
11128    }
11129
11130    #[test]
11131    fn validate_rejects_path_fonte_with_caminho_carrying_close_bracket() {
11132        // The symmetric close-bracket paste shape (`"../caixa-teia]"`
11133        // — the degenerate "I selected an unbalanced closing bracket
11134        // out of a glob character-class block" idiom that probes for
11135        // the cascade's last-byte handling on a value carrying only
11136        // the closing byte). Pinned separately from the open-bracket
11137        // shape so the gate's contract is "any `[` or `]` anywhere",
11138        // not single-byte coverage. Mirrors the peer
11139        // `validate_rejects_path_fonte_with_caminho_carrying_close_brace`
11140        // shape on the immediate-predecessor
11141        // `FonteCaminhoShellBraceExpansion` arm.
11142        let d = dep_with_fonte(DepSource::Path {
11143            caminho: "../caixa-teia]".into(),
11144        });
11145        let err = d.validate().unwrap_err();
11146        let DepError::FonteCaminhoShellBracketExpansion { byte, .. } = err else {
11147            panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11148        };
11149        assert_eq!(byte, b']');
11150    }
11151
11152    #[test]
11153    fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_bracket() {
11154        // Leading-position `[` shape (`"[caixa-teia]/build"` — the
11155        // canonical "I selected a `[caixa-teia]` TOML-table-header /
11156        // glob-character-class prefix out of an aligned config /
11157        // shell-history one-liner" idiom). Pinned separately from
11158        // the embedded-byte shape so the gate covers every position,
11159        // not only mid-path.
11160        let d = dep_with_fonte(DepSource::Path {
11161            caminho: "[caixa-teia]/build".into(),
11162        });
11163        let err = d.validate().unwrap_err();
11164        assert!(
11165            matches!(
11166                err,
11167                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11168            ),
11169            "got {err:?}",
11170        );
11171    }
11172
11173    #[test]
11174    fn validate_rejects_path_fonte_with_caminho_carrying_toml_inline_array() {
11175        // The canonical TOML inline-array / YAML flow-sequence
11176        // paste shape (`"../[\"a\", \"b\"]/caixa-teia"` — the
11177        // canonical "I copied a `features = [\"a\", \"b\"]` TOML
11178        // inline-array out of a sibling-Cargo manifest" cross-idiom
11179        // leak; the symmetric YAML flow-sequence form `paths: [/a,
11180        // /b]` paste-from-values.yaml shape carries the same
11181        // bracket pair). The arm fires on the first `[` encountered;
11182        // pinned so the gate's coverage extends from the bare-
11183        // bracket glob-character-class shape to the TOML / YAML /
11184        // JSON array-literal shape.
11185        let d = dep_with_fonte(DepSource::Path {
11186            caminho: "../[\"a\", \"b\"]/caixa-teia".into(),
11187        });
11188        let err = d.validate().unwrap_err();
11189        assert!(
11190            matches!(
11191                err,
11192                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11193            ),
11194            "got {err:?}",
11195        );
11196    }
11197
11198    #[test]
11199    fn validate_rejects_path_fonte_with_caminho_carrying_shell_test_builtin() {
11200        // The canonical POSIX `test` / `[` builtin command paste
11201        // shape (`"../[ -d caixa-teia ]"` — the `[ <expr> ]` shell-
11202        // script conditional every paste-from-shell-script idiom
11203        // carries; bash's `[[ <expr> ]]` extended-test grammar
11204        // would surface the same byte pair). The arm fires on the
11205        // first `[` encountered; pinned so the gate's coverage
11206        // extends from the embedded-glob-character-class shape to
11207        // the leading-`test`-builtin / extended-test form.
11208        let d = dep_with_fonte(DepSource::Path {
11209            caminho: "../[ -d caixa-teia ]".into(),
11210        });
11211        let err = d.validate().unwrap_err();
11212        assert!(
11213            matches!(
11214                err,
11215                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11216            ),
11217            "got {err:?}",
11218        );
11219    }
11220
11221    #[test]
11222    fn validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion() {
11223        // The positive-control pin: the gate targets only `[` /
11224        // `]`, never adjacent printable ASCII or POSIX-valid bytes.
11225        // The canonical relative POSIX path (`"../caixa-teia"`) and
11226        // a nested deeply-pathed variant with adjacent printable
11227        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11228        // to validate cleanly so the gate doesn't widen to a "no
11229        // printable punctuation anywhere" sweep that would defeat
11230        // the entire path-fonte author surface. Peer with
11231        // `validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion`
11232        // on the immediate-predecessor arm.
11233        let d = dep_with_fonte(DepSource::Path {
11234            caminho: "../caixa-teia/sub-dir.v2".into(),
11235        });
11236        d.validate().unwrap();
11237    }
11238
11239    #[test]
11240    fn fonte_caminho_shell_brace_expansion_fires_before_shell_bracket_expansion() {
11241        // Cascade pin on the immediate-predecessor arm: a value
11242        // carrying both `{` and `[` (`"../{a,b}[ch]"` — the
11243        // canonical "I pasted a brace-expansion fan followed by a
11244        // glob-character-class tail" footgun) routes through
11245        // `FonteCaminhoShellBraceExpansion` not
11246        // `FonteCaminhoShellBracketExpansion`. The brace-expansion
11247        // fan is the load-bearing root-cause edit on every
11248        // probe-as-both value because the bracket-class tail
11249        // typically rides on a prior brace-expansion expansion;
11250        // same cascade discipline every prior `:caminho` arm
11251        // establishes.
11252        let d = dep_with_fonte(DepSource::Path {
11253            caminho: "../{a,b}[ch]".into(),
11254        });
11255        let err = d.validate().unwrap_err();
11256        assert!(
11257            matches!(
11258                err,
11259                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11260            ),
11261            "got {err:?}",
11262        );
11263    }
11264
11265    #[test]
11266    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_bracket_expansion() {
11267        // Cascade pin on the upstream shell-subshell-grouping arm:
11268        // a value carrying both `(` and `[` (`"../(cd foo)/[ch]"` —
11269        // the canonical "I pasted a subshell-grouping followed by
11270        // a glob-character-class tail" footgun) routes through
11271        // `FonteCaminhoShellSubshellGrouping` not
11272        // `FonteCaminhoShellBracketExpansion`. The modern Bourne
11273        // `$(<cmd>)` command-substitution boundary is the load-
11274        // bearing axis on every probe-as-both value.
11275        let d = dep_with_fonte(DepSource::Path {
11276            caminho: "../(cd foo)/[ch]".into(),
11277        });
11278        let err = d.validate().unwrap_err();
11279        assert!(
11280            matches!(
11281                err,
11282                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11283            ),
11284            "got {err:?}",
11285        );
11286    }
11287
11288    #[test]
11289    fn fonte_caminho_shell_glob_fires_before_shell_bracket_expansion() {
11290        // Cascade pin on the upstream shell-glob arm: a value
11291        // carrying both `*` and `[` (`"../caixa-teia/*[ch]"` — the
11292        // canonical "I pasted a `*.[ch]` C-source-file glob whose
11293        // unbounded `*` precedes the bracket character-class"
11294        // footgun) routes through `FonteCaminhoShellGlob` not
11295        // `FonteCaminhoShellBracketExpansion`. The unbounded
11296        // pathname-expansion sentinel is the load-bearing root-
11297        // cause edit on every probe-as-both value — the unbounded
11298        // `*` carries the more aggressive expansion vector than
11299        // the bounded `[ch]` class, so the prior arm wins.
11300        let d = dep_with_fonte(DepSource::Path {
11301            caminho: "../caixa-teia/*[ch]".into(),
11302        });
11303        let err = d.validate().unwrap_err();
11304        assert!(
11305            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11306            "got {err:?}",
11307        );
11308    }
11309
11310    #[test]
11311    fn fonte_caminho_shell_command_substitution_fires_before_shell_bracket_expansion() {
11312        // Cascade pin on the upstream shell-command-substitution
11313        // arm: a value carrying both a backtick and `[`
11314        // (``"../`whoami`/[ch]"`` — the canonical "I pasted a
11315        // legacy-backtick command-substitution followed by a
11316        // glob-character-class tail" footgun) routes through
11317        // `FonteCaminhoShellCommandSubstitution` not
11318        // `FonteCaminhoShellBracketExpansion`. The CWE-78 shell-
11319        // command-injection vector is the load-bearing root-cause
11320        // edit on every probe-as-both value.
11321        let d = dep_with_fonte(DepSource::Path {
11322            caminho: "../`whoami`/[ch]".into(),
11323        });
11324        let err = d.validate().unwrap_err();
11325        assert!(
11326            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11327            "got {err:?}",
11328        );
11329    }
11330
11331    #[test]
11332    fn fonte_caminho_shell_background_fires_before_shell_bracket_expansion() {
11333        // Cascade pin on the upstream shell-background arm: a
11334        // value carrying both `&` and `[` (`"../caixa-teia & [ch]"`
11335        // — the canonical "I pasted a `cmd & [glob]` background-
11336        // launch + bracket-class chain" footgun) routes through
11337        // `FonteCaminhoShellBackground` not
11338        // `FonteCaminhoShellBracketExpansion`. The background-
11339        // launch tail is the load-bearing root-cause edit on
11340        // every probe-as-both value.
11341        let d = dep_with_fonte(DepSource::Path {
11342            caminho: "../caixa-teia & [ch]".into(),
11343        });
11344        let err = d.validate().unwrap_err();
11345        assert!(
11346            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11347            "got {err:?}",
11348        );
11349    }
11350
11351    #[test]
11352    fn fonte_caminho_shell_semicolon_fires_before_shell_bracket_expansion() {
11353        // Cascade pin on the upstream shell-semicolon arm: a value
11354        // carrying both `;` and `[` (`"../caixa-teia; [ch]"` — the
11355        // canonical sequential-cleanup + bracket-class paste
11356        // idiom) routes through `FonteCaminhoShellSemicolon` not
11357        // `FonteCaminhoShellBracketExpansion`. The sequential-
11358        // command-separator paste is the load-bearing root-cause
11359        // edit on every probe-as-both value.
11360        let d = dep_with_fonte(DepSource::Path {
11361            caminho: "../caixa-teia; [ch]".into(),
11362        });
11363        let err = d.validate().unwrap_err();
11364        assert!(
11365            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11366            "got {err:?}",
11367        );
11368    }
11369
11370    #[test]
11371    fn fonte_caminho_shell_pipe_fires_before_shell_bracket_expansion() {
11372        // Cascade pin on the upstream shell-pipe arm: a value
11373        // carrying both `|` and `[` (`"../caixa-teia | [tee]"` —
11374        // the canonical pipeline-to-bracket-class paste idiom)
11375        // routes through `FonteCaminhoShellPipe` not
11376        // `FonteCaminhoShellBracketExpansion`. The pipeline-tail
11377        // paste is the load-bearing root-cause edit on every
11378        // probe-as-both value.
11379        let d = dep_with_fonte(DepSource::Path {
11380            caminho: "../caixa-teia | [tee]".into(),
11381        });
11382        let err = d.validate().unwrap_err();
11383        assert!(
11384            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11385            "got {err:?}",
11386        );
11387    }
11388
11389    #[test]
11390    fn fonte_caminho_shell_redirection_fires_before_shell_bracket_expansion() {
11391        // Cascade pin on the upstream shell-redirection arm: a
11392        // value carrying both `>` and `[` (`"../caixa-teia>log
11393        // [ch]"` — the canonical "I pasted a `cmd > log [glob]`
11394        // redirect-plus-bracket chain" footgun) routes through
11395        // `FonteCaminhoShellRedirection` not
11396        // `FonteCaminhoShellBracketExpansion`. The input/output
11397        // redirection metachar carries the more self-locating
11398        // `byte` payload, so the prior arm wins on every
11399        // probe-as-both value.
11400        let d = dep_with_fonte(DepSource::Path {
11401            caminho: "../caixa-teia>log [ch]".into(),
11402        });
11403        let err = d.validate().unwrap_err();
11404        assert!(
11405            matches!(
11406                err,
11407                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11408            ),
11409            "got {err:?}",
11410        );
11411    }
11412
11413    #[test]
11414    fn fonte_caminho_backslash_fires_before_shell_bracket_expansion() {
11415        // Cascade pin on the upstream backslash arm: a value
11416        // carrying both `\` and `[` (`"..\caixa-teia\[ch]"` — the
11417        // canonical "I pasted a Windows-shell `cd ..\path\[glob]`
11418        // chain") routes through `FonteCaminhoBackslash` not
11419        // `FonteCaminhoShellBracketExpansion`. The cross-host-OS-
11420        // separator divergence is the load-bearing axis on every
11421        // probe-as-both value.
11422        let d = dep_with_fonte(DepSource::Path {
11423            caminho: "..\\caixa-teia\\[ch]".into(),
11424        });
11425        let err = d.validate().unwrap_err();
11426        assert!(
11427            matches!(err, DepError::FonteCaminhoBackslash { .. }),
11428            "got {err:?}",
11429        );
11430    }
11431
11432    #[test]
11433    fn fonte_caminho_control_char_fires_before_shell_bracket_expansion() {
11434        // Cascade pin on the embedded-control-byte arm: a value
11435        // carrying both a control byte and `[` (`"../foo\n[ch]"` —
11436        // the canonical paste-from-multiline-doc footgun where a
11437        // newline landed mid-caminho between two paste fragments)
11438        // routes through `FonteCaminhoControlChar` not
11439        // `FonteCaminhoShellBracketExpansion`. The POSIX-syscall-
11440        // rejected-byte / NUL-`CString::new`-fail diagnostic is
11441        // the load-bearing axis on every value that probes
11442        // positive for both — mirrors the cascade discipline on
11443        // every prior arm.
11444        let d = dep_with_fonte(DepSource::Path {
11445            caminho: "../foo\n[ch]".into(),
11446        });
11447        let err = d.validate().unwrap_err();
11448        assert!(
11449            matches!(err, DepError::FonteCaminhoControlChar { .. }),
11450            "got {err:?}",
11451        );
11452    }
11453
11454    #[test]
11455    fn fonte_caminho_absolute_fires_before_shell_bracket_expansion() {
11456        // Cascade pin on the load-bearing leading-byte arm: a
11457        // leading `/` value with embedded `[` (`"/etc/[ch]"`)
11458        // routes through `FonteCaminhoAbsolute` not
11459        // `FonteCaminhoShellBracketExpansion` — the host-layout-
11460        // leak diagnostic is the load-bearing axis, the bracket-
11461        // expansion byte is the secondary observation. Same
11462        // precedence logic as every prior leading-byte arm.
11463        let d = dep_with_fonte(DepSource::Path {
11464            caminho: "/etc/[ch]".into(),
11465        });
11466        let err = d.validate().unwrap_err();
11467        assert!(
11468            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11469            "got {err:?}",
11470        );
11471    }
11472
11473    #[test]
11474    fn fonte_caminho_var_expansion_fires_before_shell_bracket_expansion() {
11475        // Cascade pin on the upstream leading-`$` var-expansion
11476        // arm: a value carrying both a leading `$` and a `[`
11477        // (`"$DIR/[ch]"` — the canonical "I pasted a `$DIR` shell-
11478        // variable + bracket-class at the head of a sibling-
11479        // workspace path" footgun) routes through
11480        // `FonteCaminhoVarExpansion` not
11481        // `FonteCaminhoShellBracketExpansion`. The leading-byte
11482        // shell-variable-expansion is the more self-locating
11483        // diagnostic on values that probe as both — same
11484        // load-bearing-leading-byte cascade discipline every
11485        // prior `:caminho` arm establishes.
11486        let d = dep_with_fonte(DepSource::Path {
11487            caminho: "$DIR/[ch]".into(),
11488        });
11489        let err = d.validate().unwrap_err();
11490        assert!(
11491            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11492            "got {err:?}",
11493        );
11494    }
11495
11496    #[test]
11497    fn fonte_caminho_shell_bracket_expansion_fires_before_trailing_slash() {
11498        // Cascade pin on the immediate-successor arm: a value
11499        // carrying both `[` and a trailing `/` (`"../[a-z]/"` —
11500        // the canonical "I tab-completed a path that already had
11501        // a bracket-glob-character-class expansion tail" footgun)
11502        // routes through `FonteCaminhoShellBracketExpansion` not
11503        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11504        // is the more semantic-locating axis (an author who
11505        // removes the `[` typically also drops the trailing
11506        // separator since both are paste-from-shell artifacts).
11507        let d = dep_with_fonte(DepSource::Path {
11508            caminho: "../[a-z]/".into(),
11509        });
11510        let err = d.validate().unwrap_err();
11511        assert!(
11512            matches!(
11513                err,
11514                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11515            ),
11516            "got {err:?}",
11517        );
11518    }
11519
11520    #[test]
11521    fn fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11522        // Diagnostic-shape pin (peer with
11523        // `fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11524        // on the closest two-byte peer arm): the error's Display
11525        // surfaces the offending `:nome`, the offending `:caminho`
11526        // verbatim, the offending byte's hex / character form, and
11527        // names the shell-bracket-expansion / glob-character-class
11528        // footgun explicitly so a `feira lint` run can render the
11529        // diagnostic without re-parsing.
11530        let d = dep_with_fonte(DepSource::Path {
11531            caminho: "../caixa-[a-z]/build".into(),
11532        });
11533        let rendered = d.validate().unwrap_err().to_string();
11534        assert!(
11535            rendered.contains("caixa-teia"),
11536            "diagnostic must name the offending dep: {rendered}",
11537        );
11538        assert!(
11539            rendered.contains("../caixa-[a-z]/build"),
11540            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11541        );
11542        assert!(
11543            rendered.contains("0x5b"),
11544            "diagnostic must surface the offending byte hex: {rendered:?}",
11545        );
11546        assert!(
11547            rendered.contains("bracket-expansion"),
11548            "diagnostic must name the shell-bracket-expansion footgun: {rendered:?}",
11549        );
11550        assert!(
11551            rendered.contains("glob-character-class"),
11552            "diagnostic must reference the POSIX glob-character-class vocabulary: \
11553             {rendered:?}",
11554        );
11555    }
11556
11557    #[test]
11558    fn validate_rejects_path_fonte_with_caminho_carrying_single_quote_grouping() {
11559        // The canonical paste-from-shell-history strong-quoted
11560        // sibling-workspace-path footgun: an author copies a
11561        // `cd '../caixa-teia'` shell-history one-liner whose strong-
11562        // quoting preserved the path across a whitespace paste
11563        // boundary and silently passed every prior arm
11564        // (`Path::is_absolute` false on `'..`, no control bytes, no
11565        // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no
11566        // `*` / `?`, no `(` / `)`, no `{` / `}`, no `[` / `]`,
11567        // doesn't end in `/`; the leading-`$` f4efe9c
11568        // `FonteCaminhoVarExpansion` arm doesn't fire because the
11569        // value starts with `'` not `$`). The lacre embedded the
11570        // value verbatim, the resolver folded it through
11571        // `Path::join` looking for a literal `./'../caixa-teia'`
11572        // subdirectory, and the failure surfaced at resolve time
11573        // with a non-self-locating `No such file or directory`
11574        // error. The new arm moves the rejection to validate time
11575        // and names the offending dep + caminho + byte verbatim.
11576        // The arm fires on the first `'` encountered.
11577        let d = dep_with_fonte(DepSource::Path {
11578            caminho: "'../caixa-teia'".into(),
11579        });
11580        let err = d.validate().unwrap_err();
11581        let DepError::FonteCaminhoShellQuoteGrouping {
11582            nome,
11583            caminho,
11584            byte,
11585        } = err
11586        else {
11587            panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11588        };
11589        assert_eq!(nome, "caixa-teia");
11590        assert_eq!(caminho, "'../caixa-teia'");
11591        assert_eq!(byte, b'\'');
11592    }
11593
11594    #[test]
11595    fn validate_rejects_path_fonte_with_caminho_carrying_double_quote_grouping() {
11596        // The symmetric weak-quoted paste shape (`"\"../caixa-teia\""`
11597        // — the canonical paste-from-JSON-config / paste-from-YAML-
11598        // flow-scalar / paste-from-TOML-basic-string / paste-from-
11599        // tatara-lisp-string-literal cross-idiom leak). Pinned
11600        // separately from the single-quote shape so the gate's
11601        // contract is "any `'` or `\"` anywhere", not single-byte
11602        // coverage. Mirrors the peer
11603        // `validate_rejects_path_fonte_with_caminho_carrying_close_bracket`
11604        // shape on the immediate-predecessor
11605        // `FonteCaminhoShellBracketExpansion` arm.
11606        let d = dep_with_fonte(DepSource::Path {
11607            caminho: "\"../caixa-teia\"".into(),
11608        });
11609        let err = d.validate().unwrap_err();
11610        let DepError::FonteCaminhoShellQuoteGrouping { byte, .. } = err else {
11611            panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11612        };
11613        assert_eq!(byte, b'"');
11614    }
11615
11616    #[test]
11617    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_double_quote() {
11618        // Embedded-position `"` shape (`"../\"caixa-teia\""` — the
11619        // canonical "I pasted a JSON key-value pair fragment into
11620        // the middle of the path" idiom). Pinned separately from
11621        // the leading-byte shape so the gate covers every position,
11622        // not only leading.
11623        let d = dep_with_fonte(DepSource::Path {
11624            caminho: "../\"caixa-teia\"".into(),
11625        });
11626        let err = d.validate().unwrap_err();
11627        assert!(
11628            matches!(
11629                err,
11630                DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11631            ),
11632            "got {err:?}",
11633        );
11634    }
11635
11636    #[test]
11637    fn validate_rejects_path_fonte_with_caminho_carrying_yaml_flow_scalar_paste() {
11638        // The canonical YAML double-quoted flow-scalar cross-idiom
11639        // leak shape (`"path: \"../caixa-teia\""` — the "I copied a
11640        // `path: \"...\"` YAML flow-scalar entry out of an aligned
11641        // values.yaml / K8s manifest and dropped it verbatim into
11642        // the `:caminho` slot including the `path: ` key prefix"
11643        // paste-idiom). The arm fires on the first `"` encountered;
11644        // pinned so the gate's coverage extends from the bare-quote
11645        // paste shape to the aligned-YAML-manifest cross-idiom-leak
11646        // shape.
11647        let d = dep_with_fonte(DepSource::Path {
11648            caminho: "path: \"../caixa-teia\"".into(),
11649        });
11650        let err = d.validate().unwrap_err();
11651        assert!(
11652            matches!(
11653                err,
11654                DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11655            ),
11656            "got {err:?}",
11657        );
11658    }
11659
11660    #[test]
11661    fn validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping() {
11662        // The positive-control pin: the gate targets only `'` /
11663        // `"`, never adjacent printable ASCII or POSIX-valid bytes.
11664        // The canonical relative POSIX path (`"../caixa-teia"`) and
11665        // a nested deeply-pathed variant with adjacent printable
11666        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11667        // to validate cleanly so the gate doesn't widen to a "no
11668        // printable punctuation anywhere" sweep that would defeat
11669        // the entire path-fonte author surface. Peer with
11670        // `validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion`
11671        // on the immediate-predecessor arm.
11672        let d = dep_with_fonte(DepSource::Path {
11673            caminho: "../caixa-teia/sub-dir.v2".into(),
11674        });
11675        d.validate().unwrap();
11676    }
11677
11678    #[test]
11679    fn fonte_caminho_shell_bracket_expansion_fires_before_shell_quote_grouping() {
11680        // Cascade pin on the immediate-predecessor arm: a value
11681        // carrying both `[` and `'` (`"../[a-z]'x'"` — the canonical
11682        // "I pasted a glob-character-class followed by a strong-
11683        // quoted literal tail" footgun) routes through
11684        // `FonteCaminhoShellBracketExpansion` not
11685        // `FonteCaminhoShellQuoteGrouping`. The glob-character-class
11686        // expansion is the load-bearing root-cause edit on every
11687        // probe-as-both value; same cascade discipline every prior
11688        // `:caminho` arm establishes.
11689        let d = dep_with_fonte(DepSource::Path {
11690            caminho: "../[a-z]'x'".into(),
11691        });
11692        let err = d.validate().unwrap_err();
11693        assert!(
11694            matches!(
11695                err,
11696                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11697            ),
11698            "got {err:?}",
11699        );
11700    }
11701
11702    #[test]
11703    fn fonte_caminho_shell_brace_expansion_fires_before_shell_quote_grouping() {
11704        // Cascade pin on the upstream shell-brace-expansion arm: a
11705        // value carrying both `{` and `'` (`"../{a,b}'x'"` — the
11706        // canonical "I pasted a brace-expansion fan followed by a
11707        // strong-quoted literal tail" footgun) routes through
11708        // `FonteCaminhoShellBraceExpansion` not
11709        // `FonteCaminhoShellQuoteGrouping`. The brace-expansion fan
11710        // is the load-bearing root-cause edit on every probe-as-
11711        // both value.
11712        let d = dep_with_fonte(DepSource::Path {
11713            caminho: "../{a,b}'x'".into(),
11714        });
11715        let err = d.validate().unwrap_err();
11716        assert!(
11717            matches!(
11718                err,
11719                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11720            ),
11721            "got {err:?}",
11722        );
11723    }
11724
11725    #[test]
11726    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_quote_grouping() {
11727        // Cascade pin on the upstream shell-subshell-grouping arm:
11728        // a value carrying both `(` and `'` (`"../(cd foo)/'x'"` —
11729        // the canonical "I pasted a subshell-grouping followed by
11730        // a strong-quoted literal tail" footgun) routes through
11731        // `FonteCaminhoShellSubshellGrouping` not
11732        // `FonteCaminhoShellQuoteGrouping`. The modern Bourne
11733        // `$(<cmd>)` command-substitution boundary is the load-
11734        // bearing axis on every probe-as-both value.
11735        let d = dep_with_fonte(DepSource::Path {
11736            caminho: "../(cd foo)/'x'".into(),
11737        });
11738        let err = d.validate().unwrap_err();
11739        assert!(
11740            matches!(
11741                err,
11742                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11743            ),
11744            "got {err:?}",
11745        );
11746    }
11747
11748    #[test]
11749    fn fonte_caminho_shell_glob_fires_before_shell_quote_grouping() {
11750        // Cascade pin on the upstream shell-glob arm: a value
11751        // carrying both `*` and `'` (`"../caixa-teia/*'x'"` — the
11752        // canonical "I pasted a `*` unbounded pathname-expansion
11753        // followed by a strong-quoted literal tail" footgun) routes
11754        // through `FonteCaminhoShellGlob` not
11755        // `FonteCaminhoShellQuoteGrouping`. The unbounded pathname-
11756        // expansion sentinel is the load-bearing root-cause edit
11757        // on every probe-as-both value.
11758        let d = dep_with_fonte(DepSource::Path {
11759            caminho: "../caixa-teia/*'x'".into(),
11760        });
11761        let err = d.validate().unwrap_err();
11762        assert!(
11763            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11764            "got {err:?}",
11765        );
11766    }
11767
11768    #[test]
11769    fn fonte_caminho_shell_command_substitution_fires_before_shell_quote_grouping() {
11770        // Cascade pin on the upstream shell-command-substitution
11771        // arm: a value carrying both a backtick and `'`
11772        // (``"../`whoami`/'x'"`` — the canonical "I pasted a
11773        // legacy-backtick command-substitution followed by a
11774        // strong-quoted literal tail" footgun) routes through
11775        // `FonteCaminhoShellCommandSubstitution` not
11776        // `FonteCaminhoShellQuoteGrouping`. The CWE-78 shell-
11777        // command-injection vector is the load-bearing root-cause
11778        // edit on every probe-as-both value.
11779        let d = dep_with_fonte(DepSource::Path {
11780            caminho: "../`whoami`/'x'".into(),
11781        });
11782        let err = d.validate().unwrap_err();
11783        assert!(
11784            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11785            "got {err:?}",
11786        );
11787    }
11788
11789    #[test]
11790    fn fonte_caminho_shell_background_fires_before_shell_quote_grouping() {
11791        // Cascade pin on the upstream shell-background arm: a value
11792        // carrying both `&` and `'` (`"../caixa-teia & 'x'"` — the
11793        // canonical "I pasted a `cmd & 'literal'` background-launch
11794        // + quote chain" footgun) routes through
11795        // `FonteCaminhoShellBackground` not
11796        // `FonteCaminhoShellQuoteGrouping`. The background-launch
11797        // tail is the load-bearing root-cause edit on every
11798        // probe-as-both value.
11799        let d = dep_with_fonte(DepSource::Path {
11800            caminho: "../caixa-teia & 'x'".into(),
11801        });
11802        let err = d.validate().unwrap_err();
11803        assert!(
11804            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11805            "got {err:?}",
11806        );
11807    }
11808
11809    #[test]
11810    fn fonte_caminho_shell_semicolon_fires_before_shell_quote_grouping() {
11811        // Cascade pin on the upstream shell-semicolon arm: a value
11812        // carrying both `;` and `'` (`"../caixa-teia; 'x'"` — the
11813        // canonical sequential-cleanup + quote paste idiom) routes
11814        // through `FonteCaminhoShellSemicolon` not
11815        // `FonteCaminhoShellQuoteGrouping`. The sequential-command-
11816        // separator paste is the load-bearing root-cause edit on
11817        // every probe-as-both value.
11818        let d = dep_with_fonte(DepSource::Path {
11819            caminho: "../caixa-teia; 'x'".into(),
11820        });
11821        let err = d.validate().unwrap_err();
11822        assert!(
11823            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11824            "got {err:?}",
11825        );
11826    }
11827
11828    #[test]
11829    fn fonte_caminho_shell_pipe_fires_before_shell_quote_grouping() {
11830        // Cascade pin on the upstream shell-pipe arm: a value
11831        // carrying both `|` and `'` (`"../caixa-teia | 'x'"` — the
11832        // canonical pipeline-to-quoted-literal paste idiom) routes
11833        // through `FonteCaminhoShellPipe` not
11834        // `FonteCaminhoShellQuoteGrouping`. The pipeline-tail paste
11835        // is the load-bearing root-cause edit on every probe-as-
11836        // both value.
11837        let d = dep_with_fonte(DepSource::Path {
11838            caminho: "../caixa-teia | 'x'".into(),
11839        });
11840        let err = d.validate().unwrap_err();
11841        assert!(
11842            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11843            "got {err:?}",
11844        );
11845    }
11846
11847    #[test]
11848    fn fonte_caminho_shell_redirection_fires_before_shell_quote_grouping() {
11849        // Cascade pin on the upstream shell-redirection arm: a
11850        // value carrying both `>` and `'` (`"../caixa-teia>log 'x'"`
11851        // — the canonical "I pasted a `cmd > log 'literal'`
11852        // redirect-plus-quote chain" footgun) routes through
11853        // `FonteCaminhoShellRedirection` not
11854        // `FonteCaminhoShellQuoteGrouping`. The input/output
11855        // redirection metachar carries the more self-locating
11856        // `byte` payload, so the prior arm wins on every probe-as-
11857        // both value.
11858        let d = dep_with_fonte(DepSource::Path {
11859            caminho: "../caixa-teia>log 'x'".into(),
11860        });
11861        let err = d.validate().unwrap_err();
11862        assert!(
11863            matches!(
11864                err,
11865                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11866            ),
11867            "got {err:?}",
11868        );
11869    }
11870
11871    #[test]
11872    fn fonte_caminho_backslash_fires_before_shell_quote_grouping() {
11873        // Cascade pin on the upstream backslash arm: a value
11874        // carrying both `\` and `'` (`"..\caixa-teia\'x'"` — the
11875        // canonical "I pasted a Windows-shell `cd ..\path\'literal'`
11876        // chain" footgun) routes through `FonteCaminhoBackslash`
11877        // not `FonteCaminhoShellQuoteGrouping`. The cross-host-OS-
11878        // separator divergence is the load-bearing axis on every
11879        // probe-as-both value.
11880        let d = dep_with_fonte(DepSource::Path {
11881            caminho: "..\\caixa-teia\\'x'".into(),
11882        });
11883        let err = d.validate().unwrap_err();
11884        assert!(
11885            matches!(err, DepError::FonteCaminhoBackslash { .. }),
11886            "got {err:?}",
11887        );
11888    }
11889
11890    #[test]
11891    fn fonte_caminho_control_char_fires_before_shell_quote_grouping() {
11892        // Cascade pin on the embedded-control-byte arm: a value
11893        // carrying both a control byte and `'` (`"../foo\n'x'"` —
11894        // the canonical paste-from-multiline-doc footgun where a
11895        // newline landed mid-caminho between two paste fragments)
11896        // routes through `FonteCaminhoControlChar` not
11897        // `FonteCaminhoShellQuoteGrouping`. The POSIX-syscall-
11898        // rejected-byte / NUL-`CString::new`-fail diagnostic is
11899        // the load-bearing axis on every value that probes
11900        // positive for both — mirrors the cascade discipline on
11901        // every prior arm.
11902        let d = dep_with_fonte(DepSource::Path {
11903            caminho: "../foo\n'x'".into(),
11904        });
11905        let err = d.validate().unwrap_err();
11906        assert!(
11907            matches!(err, DepError::FonteCaminhoControlChar { .. }),
11908            "got {err:?}",
11909        );
11910    }
11911
11912    #[test]
11913    fn fonte_caminho_absolute_fires_before_shell_quote_grouping() {
11914        // Cascade pin on the load-bearing leading-byte arm: a
11915        // leading `/` value with embedded `'` (`"/etc/'x'"`) routes
11916        // through `FonteCaminhoAbsolute` not
11917        // `FonteCaminhoShellQuoteGrouping` — the host-layout-leak
11918        // diagnostic is the load-bearing axis, the quote byte is
11919        // the secondary observation. Same precedence logic as every
11920        // prior leading-byte arm.
11921        let d = dep_with_fonte(DepSource::Path {
11922            caminho: "/etc/'x'".into(),
11923        });
11924        let err = d.validate().unwrap_err();
11925        assert!(
11926            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11927            "got {err:?}",
11928        );
11929    }
11930
11931    #[test]
11932    fn fonte_caminho_var_expansion_fires_before_shell_quote_grouping() {
11933        // Cascade pin on the upstream leading-`$` var-expansion
11934        // arm: a value carrying both a leading `$` and a `'`
11935        // (`"$DIR/'x'"` — the canonical "I pasted a `$DIR` shell-
11936        // variable + quoted literal at the head of a sibling-
11937        // workspace path" footgun) routes through
11938        // `FonteCaminhoVarExpansion` not
11939        // `FonteCaminhoShellQuoteGrouping`. The leading-byte
11940        // shell-variable-expansion is the more self-locating
11941        // diagnostic on values that probe as both — same
11942        // load-bearing-leading-byte cascade discipline every
11943        // prior `:caminho` arm establishes.
11944        let d = dep_with_fonte(DepSource::Path {
11945            caminho: "$DIR/'x'".into(),
11946        });
11947        let err = d.validate().unwrap_err();
11948        assert!(
11949            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11950            "got {err:?}",
11951        );
11952    }
11953
11954    #[test]
11955    fn fonte_caminho_shell_quote_grouping_fires_before_trailing_slash() {
11956        // Cascade pin on the immediate-successor arm: a value
11957        // carrying both `'` and a trailing `/` (`"../'caixa-teia'/"`
11958        // — the canonical "I tab-completed a path whose strong-
11959        // quoted body already carried the quoting from a shell-
11960        // history paste" footgun) routes through
11961        // `FonteCaminhoShellQuoteGrouping` not
11962        // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11963        // is the more semantic-locating axis (an author who removes
11964        // the `'` typically also drops the trailing separator since
11965        // both are paste-from-shell artifacts).
11966        let d = dep_with_fonte(DepSource::Path {
11967            caminho: "../'caixa-teia'/".into(),
11968        });
11969        let err = d.validate().unwrap_err();
11970        assert!(
11971            matches!(
11972                err,
11973                DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
11974            ),
11975            "got {err:?}",
11976        );
11977    }
11978
11979    #[test]
11980    fn fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
11981        // Diagnostic-shape pin (peer with
11982        // `fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11983        // on the closest two-byte peer arm): the error's Display
11984        // surfaces the offending `:nome`, the offending `:caminho`
11985        // verbatim, the offending byte's hex / character form, and
11986        // names the shell-quote-grouping / cross-config-DSL-string-
11987        // literal-delimiter footgun explicitly so a `feira lint`
11988        // run can render the diagnostic without re-parsing.
11989        let d = dep_with_fonte(DepSource::Path {
11990            caminho: "'../caixa-teia'".into(),
11991        });
11992        let rendered = d.validate().unwrap_err().to_string();
11993        assert!(
11994            rendered.contains("caixa-teia"),
11995            "diagnostic must name the offending dep: {rendered}",
11996        );
11997        assert!(
11998            rendered.contains("'../caixa-teia'"),
11999            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12000        );
12001        assert!(
12002            rendered.contains("0x27"),
12003            "diagnostic must surface the offending byte hex: {rendered:?}",
12004        );
12005        assert!(
12006            rendered.contains("quote-grouping"),
12007            "diagnostic must name the shell-quote-grouping footgun: {rendered:?}",
12008        );
12009        assert!(
12010            rendered.contains("string-literal"),
12011            "diagnostic must reference the cross-config-DSL string-literal-delimiter \
12012             vocabulary: {rendered:?}",
12013        );
12014    }
12015
12016    #[test]
12017    fn validate_rejects_path_fonte_with_caminho_carrying_shell_comment_lead() {
12018        // The canonical paste-from-shell-history-with-trailing-
12019        // annotation footgun: an author pastes a `cd ../caixa-teia
12020        // # legacy sibling` shell-history one-liner whose unquoted `#`
12021        // comment-lead separates the path from an inline annotation.
12022        // The POSIX shell trims the annotation to `../caixa-teia`
12023        // (POSIX.1-2017 §2.3 Token Recognition step 6), but
12024        // `Path::is_absolute` returns false on `..`, `#` is neither
12025        // a leading-byte sentinel nor a control byte nor `\` nor
12026        // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` /
12027        // `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` /
12028        // `"`, and the value's last byte isn't `/` — so the value
12029        // silently passed every prior arm. The resolver folded the
12030        // value through `Path::join` looking for a literal
12031        // `./../caixa-teia # legacy sibling` subdirectory and the
12032        // failure surfaced at resolve time with a non-self-locating
12033        // `No such file or directory` error. The new arm moves the
12034        // rejection to validate time and names the offending dep +
12035        // caminho + byte verbatim.
12036        let d = dep_with_fonte(DepSource::Path {
12037            caminho: "../caixa-teia # legacy sibling".into(),
12038        });
12039        let err = d.validate().unwrap_err();
12040        let DepError::FonteCaminhoShellComment {
12041            nome,
12042            caminho,
12043            byte,
12044        } = err
12045        else {
12046            panic!("expected FonteCaminhoShellComment, got {err:?}");
12047        };
12048        assert_eq!(nome, "caixa-teia");
12049        assert_eq!(caminho, "../caixa-teia # legacy sibling");
12050        assert_eq!(byte, b'#');
12051    }
12052
12053    #[test]
12054    fn validate_rejects_path_fonte_with_caminho_carrying_yaml_comment_paste() {
12055        // The symmetric YAML flow-scalar / values.yaml / K8s-manifest
12056        // cross-idiom-leak shape (`"../caixa-teia  # pin"` — the
12057        // canonical "I copied a `path: ../caixa-teia  # pin` YAML
12058        // scalar-plus-comment entry out of an aligned values.yaml and
12059        // dropped it verbatim into the `:caminho` slot" paste-idiom).
12060        // Pinned separately from the shell-history shape so the
12061        // gate's coverage extends from the single-space `#` shape to
12062        // the YAML-canonical double-space `  #` shape. YAML 1.2 §6.6
12063        // requires the `#` to be preceded by whitespace to lex as a
12064        // comment (bare `foo#bar` is a single scalar); the double-
12065        // space paste from an aligned manifest is the canonical
12066        // shape.
12067        let d = dep_with_fonte(DepSource::Path {
12068            caminho: "../caixa-teia  # pin".into(),
12069        });
12070        let err = d.validate().unwrap_err();
12071        assert!(
12072            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12073            "got {err:?}",
12074        );
12075    }
12076
12077    #[test]
12078    fn validate_rejects_path_fonte_with_caminho_carrying_url_fragment_anchor() {
12079        // The URL-fragment-identifier paste shape
12080        // (`"../caixa-teia#readme"` — the canonical
12081        // paste-from-browser-address-bar permalink shape where the
12082        // browser preserved the `#anchor` tail on the copy). Pinned
12083        // separately from the whitespace-separated shell / YAML
12084        // comment shapes so the gate covers the unpadded RFC 3986
12085        // §3.5 fragment-delimiter position too, not only positions
12086        // preceded by unquoted whitespace. Peer with the immediate-
12087        // sibling `is_git_repo_url` arm on the `:fonte :repo` axis
12088        // (a68f818) which closes the same byte under the same URL-
12089        // fragment-identifier banner.
12090        let d = dep_with_fonte(DepSource::Path {
12091            caminho: "../caixa-teia#readme".into(),
12092        });
12093        let err = d.validate().unwrap_err();
12094        assert!(
12095            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12096            "got {err:?}",
12097        );
12098    }
12099
12100    #[test]
12101    fn validate_rejects_path_fonte_with_caminho_carrying_leading_shell_comment() {
12102        // Leading-position `#` shape (`"#../caixa-teia"` — the
12103        // "I copied a shell-comment-out entry from a commented-out
12104        // dep row" footgun). Pinned separately from the embedded
12105        // shapes so the gate covers every position, not only
12106        // whitespace-preceded / mid-value.
12107        let d = dep_with_fonte(DepSource::Path {
12108            caminho: "#../caixa-teia".into(),
12109        });
12110        let err = d.validate().unwrap_err();
12111        assert!(
12112            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12113            "got {err:?}",
12114        );
12115    }
12116
12117    #[test]
12118    fn validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment() {
12119        // The positive-control pin: the gate targets only `#`,
12120        // never adjacent printable ASCII or POSIX-valid bytes. The
12121        // canonical relative POSIX path (`"../caixa-teia"`) and a
12122        // nested deeply-pathed variant with adjacent printable
12123        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12124        // to validate cleanly so the gate doesn't widen to a "no
12125        // printable punctuation anywhere" sweep that would defeat
12126        // the entire path-fonte author surface. Peer with
12127        // `validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping`
12128        // on the immediate-predecessor arm.
12129        let d = dep_with_fonte(DepSource::Path {
12130            caminho: "../caixa-teia/sub-dir.v2".into(),
12131        });
12132        d.validate().unwrap();
12133    }
12134
12135    #[test]
12136    fn fonte_caminho_shell_quote_grouping_fires_before_shell_comment() {
12137        // Cascade pin on the immediate-predecessor arm: a value
12138        // carrying both `'` and `#` (`"../'x'#pin"` — the canonical
12139        // "I pasted a strong-quoted literal followed by a URL-
12140        // fragment permalink tail" footgun) routes through
12141        // `FonteCaminhoShellQuoteGrouping` not
12142        // `FonteCaminhoShellComment`. The shell-string-literal-
12143        // delimiter is the load-bearing root-cause edit on every
12144        // probe-as-both value; same cascade discipline every prior
12145        // `:caminho` arm establishes.
12146        let d = dep_with_fonte(DepSource::Path {
12147            caminho: "../'x'#pin".into(),
12148        });
12149        let err = d.validate().unwrap_err();
12150        assert!(
12151            matches!(
12152                err,
12153                DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12154            ),
12155            "got {err:?}",
12156        );
12157    }
12158
12159    #[test]
12160    fn fonte_caminho_shell_bracket_expansion_fires_before_shell_comment() {
12161        // Cascade pin on the upstream shell-bracket-expansion arm:
12162        // a value carrying both `[` and `#` (`"../[a-z]#pin"` — the
12163        // canonical "I pasted a glob-character-class followed by a
12164        // URL-fragment tail" footgun) routes through
12165        // `FonteCaminhoShellBracketExpansion` not
12166        // `FonteCaminhoShellComment`. The glob-character-class
12167        // expansion is the load-bearing root-cause edit on every
12168        // probe-as-both value.
12169        let d = dep_with_fonte(DepSource::Path {
12170            caminho: "../[a-z]#pin".into(),
12171        });
12172        let err = d.validate().unwrap_err();
12173        assert!(
12174            matches!(
12175                err,
12176                DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12177            ),
12178            "got {err:?}",
12179        );
12180    }
12181
12182    #[test]
12183    fn fonte_caminho_shell_brace_expansion_fires_before_shell_comment() {
12184        // Cascade pin on the upstream shell-brace-expansion arm: a
12185        // value carrying both `{` and `#` (`"../{a,b}#pin"` — the
12186        // canonical "I pasted a brace-expansion fan followed by a
12187        // URL-fragment tail" footgun) routes through
12188        // `FonteCaminhoShellBraceExpansion` not
12189        // `FonteCaminhoShellComment`. The brace-expansion fan is the
12190        // load-bearing root-cause edit on every probe-as-both value.
12191        let d = dep_with_fonte(DepSource::Path {
12192            caminho: "../{a,b}#pin".into(),
12193        });
12194        let err = d.validate().unwrap_err();
12195        assert!(
12196            matches!(
12197                err,
12198                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12199            ),
12200            "got {err:?}",
12201        );
12202    }
12203
12204    #[test]
12205    fn fonte_caminho_shell_subshell_grouping_fires_before_shell_comment() {
12206        // Cascade pin on the upstream shell-subshell-grouping arm:
12207        // a value carrying both `(` and `#` (`"../(cd foo)#pin"` —
12208        // the canonical "I pasted a subshell-grouping followed by a
12209        // URL-fragment tail" footgun) routes through
12210        // `FonteCaminhoShellSubshellGrouping` not
12211        // `FonteCaminhoShellComment`. The modern Bourne `$(<cmd>)`
12212        // command-substitution boundary is the load-bearing axis on
12213        // every probe-as-both value.
12214        let d = dep_with_fonte(DepSource::Path {
12215            caminho: "../(cd foo)#pin".into(),
12216        });
12217        let err = d.validate().unwrap_err();
12218        assert!(
12219            matches!(
12220                err,
12221                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12222            ),
12223            "got {err:?}",
12224        );
12225    }
12226
12227    #[test]
12228    fn fonte_caminho_shell_glob_fires_before_shell_comment() {
12229        // Cascade pin on the upstream shell-glob arm: a value
12230        // carrying both `*` and `#` (`"../caixa-teia/*#pin"` — the
12231        // canonical "I pasted a `*` unbounded pathname-expansion
12232        // followed by a URL-fragment tail" footgun) routes through
12233        // `FonteCaminhoShellGlob` not `FonteCaminhoShellComment`.
12234        // The unbounded pathname-expansion sentinel is the load-
12235        // bearing root-cause edit on every probe-as-both value.
12236        let d = dep_with_fonte(DepSource::Path {
12237            caminho: "../caixa-teia/*#pin".into(),
12238        });
12239        let err = d.validate().unwrap_err();
12240        assert!(
12241            matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12242            "got {err:?}",
12243        );
12244    }
12245
12246    #[test]
12247    fn fonte_caminho_shell_command_substitution_fires_before_shell_comment() {
12248        // Cascade pin on the upstream shell-command-substitution
12249        // arm: a value carrying both a backtick and `#`
12250        // (``"../`whoami`#pin"`` — the canonical "I pasted a
12251        // legacy-backtick command-substitution followed by a URL-
12252        // fragment tail" footgun) routes through
12253        // `FonteCaminhoShellCommandSubstitution` not
12254        // `FonteCaminhoShellComment`. The CWE-78 shell-command-
12255        // injection vector is the load-bearing root-cause edit on
12256        // every probe-as-both value.
12257        let d = dep_with_fonte(DepSource::Path {
12258            caminho: "../`whoami`#pin".into(),
12259        });
12260        let err = d.validate().unwrap_err();
12261        assert!(
12262            matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12263            "got {err:?}",
12264        );
12265    }
12266
12267    #[test]
12268    fn fonte_caminho_shell_background_fires_before_shell_comment() {
12269        // Cascade pin on the upstream shell-background arm: a value
12270        // carrying both `&` and `#` (`"../caixa-teia&pin#tail"` —
12271        // the canonical "I pasted a `cmd &` background-launch
12272        // followed by a URL-fragment tail" footgun) routes through
12273        // `FonteCaminhoShellBackground` not
12274        // `FonteCaminhoShellComment`. The background-launch tail is
12275        // the load-bearing root-cause edit on every probe-as-both
12276        // value.
12277        let d = dep_with_fonte(DepSource::Path {
12278            caminho: "../caixa-teia&pin#tail".into(),
12279        });
12280        let err = d.validate().unwrap_err();
12281        assert!(
12282            matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12283            "got {err:?}",
12284        );
12285    }
12286
12287    #[test]
12288    fn fonte_caminho_shell_semicolon_fires_before_shell_comment() {
12289        // Cascade pin on the upstream shell-semicolon arm: a value
12290        // carrying both `;` and `#` (`"../caixa-teia;pin#tail"` —
12291        // the canonical sequential-cleanup + URL-fragment paste
12292        // idiom) routes through `FonteCaminhoShellSemicolon` not
12293        // `FonteCaminhoShellComment`. The sequential-command-
12294        // separator paste is the load-bearing root-cause edit on
12295        // every probe-as-both value.
12296        let d = dep_with_fonte(DepSource::Path {
12297            caminho: "../caixa-teia;pin#tail".into(),
12298        });
12299        let err = d.validate().unwrap_err();
12300        assert!(
12301            matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12302            "got {err:?}",
12303        );
12304    }
12305
12306    #[test]
12307    fn fonte_caminho_shell_pipe_fires_before_shell_comment() {
12308        // Cascade pin on the upstream shell-pipe arm: a value
12309        // carrying both `|` and `#` (`"../caixa-teia|pin#tail"` —
12310        // the canonical pipeline-to-URL-fragment paste idiom) routes
12311        // through `FonteCaminhoShellPipe` not
12312        // `FonteCaminhoShellComment`. The pipeline-tail paste is
12313        // the load-bearing root-cause edit on every probe-as-both
12314        // value.
12315        let d = dep_with_fonte(DepSource::Path {
12316            caminho: "../caixa-teia|pin#tail".into(),
12317        });
12318        let err = d.validate().unwrap_err();
12319        assert!(
12320            matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12321            "got {err:?}",
12322        );
12323    }
12324
12325    #[test]
12326    fn fonte_caminho_shell_redirection_fires_before_shell_comment() {
12327        // Cascade pin on the upstream shell-redirection arm: a
12328        // value carrying both `>` and `#` (`"../caixa-teia>log#pin"`
12329        // — the canonical "I pasted a `cmd > log` redirect followed
12330        // by a URL-fragment tail" footgun) routes through
12331        // `FonteCaminhoShellRedirection` not
12332        // `FonteCaminhoShellComment`. The input/output redirection
12333        // metachar carries the more self-locating `byte` payload,
12334        // so the prior arm wins on every probe-as-both value.
12335        let d = dep_with_fonte(DepSource::Path {
12336            caminho: "../caixa-teia>log#pin".into(),
12337        });
12338        let err = d.validate().unwrap_err();
12339        assert!(
12340            matches!(
12341                err,
12342                DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12343            ),
12344            "got {err:?}",
12345        );
12346    }
12347
12348    #[test]
12349    fn fonte_caminho_backslash_fires_before_shell_comment() {
12350        // Cascade pin on the upstream backslash arm: a value
12351        // carrying both `\` and `#` (`"..\caixa-teia#pin"` — the
12352        // canonical "I pasted a Windows-shell path followed by a
12353        // URL-fragment tail" footgun) routes through
12354        // `FonteCaminhoBackslash` not `FonteCaminhoShellComment`.
12355        // The cross-host-OS-separator divergence is the load-
12356        // bearing axis on every probe-as-both value.
12357        let d = dep_with_fonte(DepSource::Path {
12358            caminho: "..\\caixa-teia#pin".into(),
12359        });
12360        let err = d.validate().unwrap_err();
12361        assert!(
12362            matches!(err, DepError::FonteCaminhoBackslash { .. }),
12363            "got {err:?}",
12364        );
12365    }
12366
12367    #[test]
12368    fn fonte_caminho_control_char_fires_before_shell_comment() {
12369        // Cascade pin on the embedded-control-byte arm: a value
12370        // carrying both a control byte and `#` (`"../foo\n#pin"` —
12371        // the canonical paste-from-multiline-doc footgun where a
12372        // newline landed mid-caminho between the path and an
12373        // annotation) routes through `FonteCaminhoControlChar` not
12374        // `FonteCaminhoShellComment`. The POSIX-syscall-rejected-
12375        // byte diagnostic is the load-bearing axis on every value
12376        // that probes positive for both — mirrors the cascade
12377        // discipline on every prior arm.
12378        let d = dep_with_fonte(DepSource::Path {
12379            caminho: "../foo\n#pin".into(),
12380        });
12381        let err = d.validate().unwrap_err();
12382        assert!(
12383            matches!(err, DepError::FonteCaminhoControlChar { .. }),
12384            "got {err:?}",
12385        );
12386    }
12387
12388    #[test]
12389    fn fonte_caminho_absolute_fires_before_shell_comment() {
12390        // Cascade pin on the load-bearing leading-byte arm: a
12391        // leading `/` value with embedded `#` (`"/etc/foo#pin"`)
12392        // routes through `FonteCaminhoAbsolute` not
12393        // `FonteCaminhoShellComment` — the host-layout-leak
12394        // diagnostic is the load-bearing axis, the fragment byte is
12395        // the secondary observation. Same precedence logic as every
12396        // prior leading-byte arm.
12397        let d = dep_with_fonte(DepSource::Path {
12398            caminho: "/etc/foo#pin".into(),
12399        });
12400        let err = d.validate().unwrap_err();
12401        assert!(
12402            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12403            "got {err:?}",
12404        );
12405    }
12406
12407    #[test]
12408    fn fonte_caminho_var_expansion_fires_before_shell_comment() {
12409        // Cascade pin on the upstream leading-`$` var-expansion
12410        // arm: a value carrying both a leading `$` and a `#`
12411        // (`"$DIR/foo#pin"` — the canonical "I pasted a `$DIR`
12412        // shell-variable at the head of a sibling-workspace path
12413        // followed by a URL-fragment tail" footgun) routes through
12414        // `FonteCaminhoVarExpansion` not `FonteCaminhoShellComment`.
12415        // The leading-byte shell-variable-expansion is the more
12416        // self-locating diagnostic on values that probe as both.
12417        let d = dep_with_fonte(DepSource::Path {
12418            caminho: "$DIR/foo#pin".into(),
12419        });
12420        let err = d.validate().unwrap_err();
12421        assert!(
12422            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12423            "got {err:?}",
12424        );
12425    }
12426
12427    #[test]
12428    fn fonte_caminho_shell_comment_fires_before_trailing_slash() {
12429        // Cascade pin on the immediate-successor arm: a value
12430        // carrying both `#` and a trailing `/`
12431        // (`"../caixa-teia#pin/"` — the canonical "I tab-completed
12432        // a URL-fragment-carrying path" footgun) routes through
12433        // `FonteCaminhoShellComment` not
12434        // `FonteCaminhoTrailingSlash`. The embedded fragment /
12435        // comment-lead byte is the more semantic-locating axis (an
12436        // author who removes the `#pin` fragment typically also
12437        // drops the trailing separator since both are paste-from-
12438        // URL / paste-from-shell-tab-completion artifacts).
12439        let d = dep_with_fonte(DepSource::Path {
12440            caminho: "../caixa-teia#pin/".into(),
12441        });
12442        let err = d.validate().unwrap_err();
12443        assert!(
12444            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. },),
12445            "got {err:?}",
12446        );
12447    }
12448
12449    #[test]
12450    fn fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte() {
12451        // Diagnostic-shape pin (peer with
12452        // `fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
12453        // on the immediate-predecessor arm): the error's Display
12454        // surfaces the offending `:nome`, the offending `:caminho`
12455        // verbatim, the offending byte's hex / character form, and
12456        // names the shell-comment / URL-fragment-identifier /
12457        // YAML-comment cross-config-DSL footgun explicitly so a
12458        // `feira lint` run can render the diagnostic without
12459        // re-parsing.
12460        let d = dep_with_fonte(DepSource::Path {
12461            caminho: "../caixa-teia#readme".into(),
12462        });
12463        let rendered = d.validate().unwrap_err().to_string();
12464        assert!(
12465            rendered.contains("caixa-teia"),
12466            "diagnostic must name the offending dep: {rendered}",
12467        );
12468        assert!(
12469            rendered.contains("../caixa-teia#readme"),
12470            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12471        );
12472        assert!(
12473            rendered.contains("0x23"),
12474            "diagnostic must surface the offending byte hex: {rendered:?}",
12475        );
12476        assert!(
12477            rendered.contains("shell-comment") || rendered.contains("comment-lead"),
12478            "diagnostic must name the shell-comment footgun: {rendered:?}",
12479        );
12480        assert!(
12481            rendered.contains("fragment") || rendered.contains("URL-fragment"),
12482            "diagnostic must reference the URL-fragment-identifier vocabulary: \
12483             {rendered:?}",
12484        );
12485    }
12486
12487    #[test]
12488    fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_space() {
12489        // The canonical paste-from-browser-address-bar percent-
12490        // encoded-space footgun: an author copies `../caixa%20teia`
12491        // out of a URL-encoded README hyperlink / browser address
12492        // bar / percent-encoded permalink expecting `%20` to decode
12493        // to a literal space at the filesystem layer. POSIX
12494        // `std::path::Path` treats `%` as a literal path-component
12495        // byte, so `Path::join` looks for a literal
12496        // `./../caixa%20teia` subdirectory. `Path::is_absolute`
12497        // returns false on `..`, `%` is neither a leading-byte
12498        // sentinel nor a control byte nor `\` nor `<` / `>` nor
12499        // `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` /
12500        // `)` nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`,
12501        // and the value's last byte isn't `/` — so the value
12502        // silently passed every prior arm. The new arm moves the
12503        // rejection to validate time and names the offending dep +
12504        // caminho + byte verbatim.
12505        let d = dep_with_fonte(DepSource::Path {
12506            caminho: "../caixa%20teia".into(),
12507        });
12508        let err = d.validate().unwrap_err();
12509        let DepError::FonteCaminhoUrlPercentEncoding {
12510            nome,
12511            caminho,
12512            byte,
12513        } = err
12514        else {
12515            panic!("expected FonteCaminhoUrlPercentEncoding, got {err:?}");
12516        };
12517        assert_eq!(nome, "caixa-teia");
12518        assert_eq!(caminho, "../caixa%20teia");
12519        assert_eq!(byte, b'%');
12520    }
12521
12522    #[test]
12523    fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_slash() {
12524        // The over-encoded path-separator shape (`"../caixa%2Fteia"`
12525        // intending the `%2F` as the URL encoding of `/`) locks a
12526        // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
12527        // the byte-identical `path:../caixa/teia` form. Pinned
12528        // separately from the space-encoded shape so the gate's
12529        // coverage extends past the single canonical `%20` example
12530        // to any two-hex-digit percent-encoded sequence.
12531        let d = dep_with_fonte(DepSource::Path {
12532            caminho: "../caixa%2Fteia".into(),
12533        });
12534        let err = d.validate().unwrap_err();
12535        assert!(
12536            matches!(
12537                err,
12538                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12539            ),
12540            "got {err:?}",
12541        );
12542    }
12543
12544    #[test]
12545    fn validate_rejects_path_fonte_with_caminho_carrying_lone_percent() {
12546        // The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
12547        // where `%` isn't followed by two hex digits) — every
12548        // WHATWG-conformant URL parser rejects the value at parse
12549        // time per RFC 3986 §2.1, but the byte would silently ride
12550        // into the lacre before the resolver subprocess crosses the
12551        // URL-parser boundary. Pinned separately from the well-
12552        // formed `%HH` shapes so the gate covers every percent-
12553        // occurrence, not only strictly-conformant escapes.
12554        let d = dep_with_fonte(DepSource::Path {
12555            caminho: "../caixa-teia%foo".into(),
12556        });
12557        let err = d.validate().unwrap_err();
12558        assert!(
12559            matches!(
12560                err,
12561                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12562            ),
12563            "got {err:?}",
12564        );
12565    }
12566
12567    #[test]
12568    fn validate_rejects_path_fonte_with_caminho_carrying_leading_yaml_directive() {
12569        // The YAML-directive-lead paste shape (`"%YAML/../caixa-teia"`
12570        // — the canonical paste-from-top-of-doc YAML directive
12571        // block cross-idiom leak per YAML 1.2 §6.8.1). Pinned
12572        // separately from embedded shapes so the gate covers the
12573        // leading-position `%` too, not only mid-value occurrences.
12574        let d = dep_with_fonte(DepSource::Path {
12575            caminho: "%YAML/../caixa-teia".into(),
12576        });
12577        let err = d.validate().unwrap_err();
12578        assert!(
12579            matches!(
12580                err,
12581                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12582            ),
12583            "got {err:?}",
12584        );
12585    }
12586
12587    #[test]
12588    fn validate_rejects_path_fonte_with_caminho_carrying_printf_format_specifier() {
12589        // The printf-format-specifier paste shape
12590        // (`"../caixa-%s-teia"` — the canonical paste-from-shell-
12591        // diagnostic-one-liner `printf "path=%s\n" ...` idiom, CWE-
12592        // 134 format-string-injection vector). Pinned separately
12593        // from the URL-encoding shapes so the gate's rationale
12594        // extends past the RFC 3986 axis to the C / POSIX printf
12595        // format-directive-lead axis.
12596        let d = dep_with_fonte(DepSource::Path {
12597            caminho: "../caixa-%s-teia".into(),
12598        });
12599        let err = d.validate().unwrap_err();
12600        assert!(
12601            matches!(
12602                err,
12603                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12604            ),
12605            "got {err:?}",
12606        );
12607    }
12608
12609    #[test]
12610    fn validate_accepts_path_fonte_with_caminho_carrying_no_percent() {
12611        // The positive-control pin: the gate targets only `%`,
12612        // never adjacent printable ASCII or POSIX-valid bytes. The
12613        // canonical relative POSIX path (`"../caixa-teia"`) and a
12614        // nested deeply-pathed variant with adjacent printable
12615        // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12616        // to validate cleanly so the gate doesn't widen to a "no
12617        // printable punctuation anywhere" sweep that would defeat
12618        // the entire path-fonte author surface. Peer with
12619        // `validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment`
12620        // on the immediate-predecessor arm.
12621        let d = dep_with_fonte(DepSource::Path {
12622            caminho: "../caixa-teia/sub-dir.v2".into(),
12623        });
12624        d.validate().unwrap();
12625    }
12626
12627    #[test]
12628    fn fonte_caminho_shell_comment_fires_before_url_percent_encoding() {
12629        // Cascade pin on the immediate-predecessor arm: a value
12630        // carrying both `#` and `%` (`"../caixa-teia#pin%20"` — the
12631        // canonical "I pasted a URL-fragment permalink followed by a
12632        // percent-encoded space tail" footgun) routes through
12633        // `FonteCaminhoShellComment` not
12634        // `FonteCaminhoUrlPercentEncoding`. The URL-fragment-
12635        // identifier is the load-bearing downstream-truncation edit
12636        // on every probe-as-both value; same cascade discipline
12637        // every prior `:caminho` arm establishes.
12638        let d = dep_with_fonte(DepSource::Path {
12639            caminho: "../caixa-teia#pin%20".into(),
12640        });
12641        let err = d.validate().unwrap_err();
12642        assert!(
12643            matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12644            "got {err:?}",
12645        );
12646    }
12647
12648    #[test]
12649    fn fonte_caminho_shell_quote_grouping_fires_before_url_percent_encoding() {
12650        // Cascade pin on the upstream shell-quote-grouping arm: a
12651        // value carrying both `'` and `%` (`"../'x'%20teia"` — the
12652        // canonical "I pasted a strong-quoted literal followed by
12653        // a percent-encoded space" footgun) routes through
12654        // `FonteCaminhoShellQuoteGrouping` not
12655        // `FonteCaminhoUrlPercentEncoding`. The shell-string-
12656        // literal-delimiter is the load-bearing root-cause edit on
12657        // every probe-as-both value.
12658        let d = dep_with_fonte(DepSource::Path {
12659            caminho: "../'x'%20teia".into(),
12660        });
12661        let err = d.validate().unwrap_err();
12662        assert!(
12663            matches!(
12664                err,
12665                DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12666            ),
12667            "got {err:?}",
12668        );
12669    }
12670
12671    #[test]
12672    fn fonte_caminho_backslash_fires_before_url_percent_encoding() {
12673        // Cascade pin on the upstream backslash arm: a value
12674        // carrying both `\` and `%` (`"..\\caixa%20teia"` — the
12675        // canonical "I pasted a Windows-shell path followed by a
12676        // percent-encoded space" footgun) routes through
12677        // `FonteCaminhoBackslash` not
12678        // `FonteCaminhoUrlPercentEncoding`. The cross-host-OS-
12679        // separator divergence is the load-bearing root-cause edit
12680        // on every probe-as-both value.
12681        let d = dep_with_fonte(DepSource::Path {
12682            caminho: "..\\caixa%20teia".into(),
12683        });
12684        let err = d.validate().unwrap_err();
12685        assert!(
12686            matches!(err, DepError::FonteCaminhoBackslash { .. }),
12687            "got {err:?}",
12688        );
12689    }
12690
12691    #[test]
12692    fn fonte_caminho_control_char_fires_before_url_percent_encoding() {
12693        // Cascade pin on the upstream control-char arm: a value
12694        // carrying both a NUL byte and `%` (`"../caixa\0%20teia"` —
12695        // the canonical "I pasted a paste-from-binary-blob path
12696        // followed by a percent-encoded space" footgun) routes
12697        // through `FonteCaminhoControlChar` not
12698        // `FonteCaminhoUrlPercentEncoding`. The POSIX-syscall-
12699        // rejected byte is the load-bearing root-cause edit on
12700        // every probe-as-both value.
12701        let d = dep_with_fonte(DepSource::Path {
12702            caminho: "../caixa\0%20teia".into(),
12703        });
12704        let err = d.validate().unwrap_err();
12705        assert!(
12706            matches!(err, DepError::FonteCaminhoControlChar { byte: 0x00, .. },),
12707            "got {err:?}",
12708        );
12709    }
12710
12711    #[test]
12712    fn fonte_caminho_absolute_fires_before_url_percent_encoding() {
12713        // Cascade pin on the upstream absolute-path arm: a value
12714        // that's both absolute and carries `%` (`"/etc/passwd%20"`
12715        // — the canonical "I pasted an absolute path with a
12716        // percent-encoded space tail" footgun) routes through
12717        // `FonteCaminhoAbsolute` not
12718        // `FonteCaminhoUrlPercentEncoding`. The host-layout-leak is
12719        // the load-bearing root-cause edit on every probe-as-both
12720        // value.
12721        let d = dep_with_fonte(DepSource::Path {
12722            caminho: "/etc/passwd%20".into(),
12723        });
12724        let err = d.validate().unwrap_err();
12725        assert!(
12726            matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12727            "got {err:?}",
12728        );
12729    }
12730
12731    #[test]
12732    fn fonte_caminho_var_expansion_fires_before_url_percent_encoding() {
12733        // Cascade pin on the upstream var-expansion arm: a value
12734        // starting with `$` and carrying `%` (`"$HOME/caixa%20teia"`
12735        // — the canonical "I pasted a `$HOME`-rooted path with a
12736        // percent-encoded space" footgun) routes through
12737        // `FonteCaminhoVarExpansion` not
12738        // `FonteCaminhoUrlPercentEncoding`. The shell-variable-
12739        // expansion is the load-bearing root-cause edit on every
12740        // probe-as-both value.
12741        let d = dep_with_fonte(DepSource::Path {
12742            caminho: "$HOME/caixa%20teia".into(),
12743        });
12744        let err = d.validate().unwrap_err();
12745        assert!(
12746            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12747            "got {err:?}",
12748        );
12749    }
12750
12751    #[test]
12752    fn fonte_caminho_url_percent_encoding_fires_before_trailing_slash() {
12753        // Cascade pin on the immediate-successor arm: a value
12754        // carrying both `%` and a trailing `/`
12755        // (`"../caixa%20teia/"` — the canonical "I tab-completed a
12756        // percent-encoded-space-carrying path" footgun) routes
12757        // through `FonteCaminhoUrlPercentEncoding` not
12758        // `FonteCaminhoTrailingSlash`. The embedded percent-
12759        // encoding-escape byte is the more semantic-locating axis
12760        // (an author who decodes the `%20` to a literal space is
12761        // likely to also tab-strip the trailing separator since
12762        // both are paste-from-URL / paste-from-shell-tab-completion
12763        // artifacts).
12764        let d = dep_with_fonte(DepSource::Path {
12765            caminho: "../caixa%20teia/".into(),
12766        });
12767        let err = d.validate().unwrap_err();
12768        assert!(
12769            matches!(
12770                err,
12771                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12772            ),
12773            "got {err:?}",
12774        );
12775    }
12776
12777    #[test]
12778    fn fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte() {
12779        // Diagnostic-shape pin (peer with
12780        // `fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte`
12781        // on the immediate-predecessor arm): the error's Display
12782        // surfaces the offending `:nome`, the offending `:caminho`
12783        // verbatim, the offending byte's hex / character form, and
12784        // names the URL-percent-encoding-escape / printf-format-
12785        // specifier footgun explicitly so a `feira lint` run can
12786        // render the diagnostic without re-parsing.
12787        let d = dep_with_fonte(DepSource::Path {
12788            caminho: "../caixa%20teia".into(),
12789        });
12790        let rendered = d.validate().unwrap_err().to_string();
12791        assert!(
12792            rendered.contains("caixa-teia"),
12793            "diagnostic must name the offending dep: {rendered}",
12794        );
12795        assert!(
12796            rendered.contains("../caixa%20teia"),
12797            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12798        );
12799        assert!(
12800            rendered.contains("0x25"),
12801            "diagnostic must surface the offending byte hex: {rendered:?}",
12802        );
12803        assert!(
12804            rendered.contains("percent-encoding") || rendered.contains("percent-encoded"),
12805            "diagnostic must name the URL-percent-encoding-escape footgun: {rendered:?}",
12806        );
12807        assert!(
12808            rendered.contains("printf") || rendered.contains("format-specifier"),
12809            "diagnostic must reference the printf-format-specifier vocabulary: \
12810             {rendered:?}",
12811        );
12812    }
12813
12814    #[test]
12815    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_var_expansion() {
12816        // The canonical embedded-`$` shell-variable-expansion paste
12817        // shape (`"../foo$HOME/bar"` — an author copies a partially-
12818        // substituted shell one-liner where the leading segment is a
12819        // literal `../foo` while the mid segment carries the un-
12820        // substituted `$HOME` template). The leading-`$` position is
12821        // already gated by the f4efe9c leading-byte arm which routes
12822        // through `FonteCaminhoVarExpansion`; this arm closes the
12823        // last positional gap on `$` — every position on the axis is
12824        // structurally rejected.
12825        let d = dep_with_fonte(DepSource::Path {
12826            caminho: "../foo$HOME/bar".into(),
12827        });
12828        let err = d.validate().unwrap_err();
12829        let DepError::FonteCaminhoShellVariableExpansion {
12830            nome,
12831            caminho,
12832            byte,
12833        } = err
12834        else {
12835            panic!("expected FonteCaminhoShellVariableExpansion, got {err:?}");
12836        };
12837        assert_eq!(nome, "caixa-teia");
12838        assert_eq!(caminho, "../foo$HOME/bar");
12839        assert_eq!(byte, b'$');
12840    }
12841
12842    #[test]
12843    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_braced_var_expansion() {
12844        // The symmetric braced-CI-manifest paste shape
12845        // (`"../foo${WORKSPACE}/bar"` — the canonical paste-from-
12846        // GitHub-Actions-workflow / paste-from-`.gitlab-ci.yml`
12847        // footgun). Pinned separately from the bare-`$VAR` shape so
12848        // the gate covers both POSIX shell §2.6 Parameter Expansion
12849        // syntactic forms, not only the unbraced variant. The
12850        // embedded `{` byte in `${...}` is also caught by the 598b770
12851        // shell-brace-expansion arm but that arm fires earlier in
12852        // the cascade — the `$` arm's coverage extends to `${...}`
12853        // structurally, so the diagnostic asserted here is the
12854        // brace-expansion one (which is a valid outcome; the point
12855        // of the pin is that the value never survives validation).
12856        let d = dep_with_fonte(DepSource::Path {
12857            caminho: "../foo${WORKSPACE}/bar".into(),
12858        });
12859        let err = d.validate().unwrap_err();
12860        assert!(
12861            matches!(
12862                err,
12863                DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. }
12864                    | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12865            ),
12866            "got {err:?}",
12867        );
12868    }
12869
12870    #[test]
12871    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_command_substitution() {
12872        // The paste-from-shell-prompt command-substitution idiom
12873        // (`"../foo$(whoami)/bar"`). Pinned separately from the bare-
12874        // `$VAR` shape so the gate's rationale extends to POSIX shell
12875        // §2.6.3 Command Substitution (the modern `$(<cmd>)` form; the
12876        // legacy `` `<cmd>` `` form is already closed by the c370458
12877        // backtick arm). The embedded `(` byte in `$(...)` is also
12878        // caught structurally by the 0633c91 shell-subshell-grouping
12879        // arm which fires earlier in the cascade — the diagnostic
12880        // asserted here is either outcome, since both structurally
12881        // reject the value; the point of the pin is that the value
12882        // never survives validation.
12883        let d = dep_with_fonte(DepSource::Path {
12884            caminho: "../foo$(whoami)/bar".into(),
12885        });
12886        let err = d.validate().unwrap_err();
12887        assert!(
12888            matches!(
12889                err,
12890                DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. }
12891                    | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12892            ),
12893            "got {err:?}",
12894        );
12895    }
12896
12897    #[test]
12898    fn validate_rejects_path_fonte_with_caminho_carrying_embedded_positional_parameter() {
12899        // The paste-from-`Makefile` / paste-from-SQL-migration bare-
12900        // `$1` positional-parameter shape (`"../foo$1/bar"` — a Make
12901        // automatic-variable `$1` or a PostgreSQL bind-parameter `$1`
12902        // idiom copied into a caminho template). None of the prior
12903        // shell-metachar arms cover this shape (`1` is a bare digit;
12904        // no `(` / `{` / letter follows the `$`), so the arm is the
12905        // sole gate on the shape.
12906        let d = dep_with_fonte(DepSource::Path {
12907            caminho: "../foo$1/bar".into(),
12908        });
12909        let err = d.validate().unwrap_err();
12910        assert!(
12911            matches!(
12912                err,
12913                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12914            ),
12915            "got {err:?}",
12916        );
12917    }
12918
12919    #[test]
12920    fn validate_accepts_path_fonte_with_caminho_carrying_no_dollar() {
12921        // The positive-control pin (peer with
12922        // `validate_accepts_path_fonte_with_caminho_carrying_no_percent`
12923        // on the immediate-predecessor arm): the gate targets only
12924        // `$`, never adjacent printable ASCII or POSIX-valid bytes.
12925        // A relative POSIX path carrying dashes / dots / slashes /
12926        // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
12927        // validate cleanly so the gate doesn't widen to a "no
12928        // printable punctuation anywhere" sweep that would defeat
12929        // the entire path-fonte author surface.
12930        let d = dep_with_fonte(DepSource::Path {
12931            caminho: "../caixa-teia/sub-dir.v2".into(),
12932        });
12933        d.validate().unwrap();
12934    }
12935
12936    #[test]
12937    fn fonte_caminho_var_expansion_fires_before_shell_variable_expansion() {
12938        // Cascade pin on the leading-`$` sibling arm at line 540: a
12939        // value starting with `$` and carrying an embedded `$` too
12940        // (`"$HOME/foo$WORKSPACE/bar"` — the canonical "I pasted a
12941        // fully-templated CI path with two un-substituted variables")
12942        // routes through `FonteCaminhoVarExpansion` not
12943        // `FonteCaminhoShellVariableExpansion`. The leading-byte
12944        // host-layout-leak is the load-bearing self-locating axis
12945        // (the leading position dominates the semantic-locating
12946        // rationale on every probe-as-both value); the embedded
12947        // arm's positional-agnostic sweep catches only values whose
12948        // leading byte doesn't route through the earlier leading-
12949        // byte arms.
12950        let d = dep_with_fonte(DepSource::Path {
12951            caminho: "$HOME/foo$WORKSPACE/bar".into(),
12952        });
12953        let err = d.validate().unwrap_err();
12954        assert!(
12955            matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12956            "got {err:?}",
12957        );
12958    }
12959
12960    #[test]
12961    fn fonte_caminho_url_percent_encoding_fires_before_shell_variable_expansion() {
12962        // Cascade pin on the immediate-predecessor arm: a value
12963        // carrying both `%` and embedded `$` (`"../foo%20$HOME/bar"`
12964        // — the canonical "I pasted a percent-encoded space adjacent
12965        // to a `$HOME` template") routes through
12966        // `FonteCaminhoUrlPercentEncoding` not
12967        // `FonteCaminhoShellVariableExpansion`. The URL-percent-
12968        // encoding-escape byte is the more semantic-locating axis
12969        // (the paste-from-browser-address-bar shape is the load-
12970        // bearing self-locating edit); same cascade discipline every
12971        // prior `:caminho` arm establishes.
12972        let d = dep_with_fonte(DepSource::Path {
12973            caminho: "../foo%20$HOME/bar".into(),
12974        });
12975        let err = d.validate().unwrap_err();
12976        assert!(
12977            matches!(
12978                err,
12979                DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12980            ),
12981            "got {err:?}",
12982        );
12983    }
12984
12985    #[test]
12986    fn fonte_caminho_shell_variable_expansion_fires_before_trailing_slash() {
12987        // Cascade pin on the immediate-successor arm: a value
12988        // carrying both embedded `$` and a trailing `/`
12989        // (`"../foo$HOME/bar/"` — the canonical "I tab-completed a
12990        // `$HOME`-template-carrying path") routes through
12991        // `FonteCaminhoShellVariableExpansion` not
12992        // `FonteCaminhoTrailingSlash`. The embedded shell-variable-
12993        // expansion byte is the more semantic-locating axis on
12994        // probe-as-both values (an author who substitutes the
12995        // `$HOME` template with a literal value is likely to also
12996        // tab-strip the trailing separator).
12997        let d = dep_with_fonte(DepSource::Path {
12998            caminho: "../foo$HOME/bar/".into(),
12999        });
13000        let err = d.validate().unwrap_err();
13001        assert!(
13002            matches!(
13003                err,
13004                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13005            ),
13006            "got {err:?}",
13007        );
13008    }
13009
13010    #[test]
13011    fn fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13012        // Diagnostic-shape pin (peer with
13013        // `fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte`
13014        // on the immediate-predecessor arm): the error's Display
13015        // surfaces the offending `:nome`, the offending `:caminho`
13016        // verbatim, the offending byte's hex / character form, and
13017        // names the shell-variable-expansion / command-substitution
13018        // footgun explicitly so a `feira lint` run can render the
13019        // diagnostic without re-parsing.
13020        let d = dep_with_fonte(DepSource::Path {
13021            caminho: "../foo$HOME/bar".into(),
13022        });
13023        let rendered = d.validate().unwrap_err().to_string();
13024        assert!(
13025            rendered.contains("caixa-teia"),
13026            "diagnostic must name the offending dep: {rendered}",
13027        );
13028        assert!(
13029            rendered.contains("../foo$HOME/bar"),
13030            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13031        );
13032        assert!(
13033            rendered.contains("0x24"),
13034            "diagnostic must surface the offending byte hex: {rendered:?}",
13035        );
13036        assert!(
13037            rendered.contains("variable-expansion") || rendered.contains("variable expansion"),
13038            "diagnostic must name the shell-variable-expansion footgun: {rendered:?}",
13039        );
13040        assert!(
13041            rendered.contains("command-substitution") || rendered.contains("command substitution"),
13042            "diagnostic must reference the command-substitution vocabulary: {rendered:?}",
13043        );
13044    }
13045
13046    #[test]
13047    fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_expansion() {
13048        // The fail-before-pass-after pin for the canonical paste-from-
13049        // shell-history footgun on `:caminho`. An author copies a `cd
13050        // ../caixa-teia && !sudo make install` one-liner from a quick-
13051        // start README, intending the trailing `!sudo` as a shell-
13052        // history-expansion reference but the typed slot is itself a
13053        // byte-level string parser, not a shell context, so the byte
13054        // rides into the value verbatim. Until this arm landed the `!`
13055        // byte silently passed every prior `:caminho` cascade arm
13056        // (`!` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick /
13057        // `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` /
13058        // `#` / `%` / `$`); bash with the default `histexpand` mode
13059        // rewrites `!command` to the most recent history entry
13060        // beginning with `command`, the canonical RCE-class injection
13061        // vector when the byte rides into a shell argument executed
13062        // under `bash -i` (the operator-notebook interactive shell).
13063        let d = dep_with_fonte(DepSource::Path {
13064            caminho: "../caixa-teia!sudo".into(),
13065        });
13066        let err = d.validate().unwrap_err();
13067        let DepError::FonteCaminhoShellHistoryExpansion {
13068            nome,
13069            caminho,
13070            byte,
13071        } = err
13072        else {
13073            panic!("expected FonteCaminhoShellHistoryExpansion, got {err:?}");
13074        };
13075        assert_eq!(nome, "caixa-teia");
13076        assert_eq!(caminho, "../caixa-teia!sudo");
13077        assert_eq!(byte, b'!');
13078    }
13079
13080    #[test]
13081    fn validate_rejects_path_fonte_with_caminho_carrying_double_bang_history_reference() {
13082        // The symmetric `!!` repeat-prior-command paste idiom (peer with
13083        // `validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference`
13084        // on `is_git_repo_url`). Pinned separately from the wrapped
13085        // `!command` shape so a future diagnostic-surface change that
13086        // only checked the leading or paired-bang position surfaces
13087        // here — the per-byte arm fires anywhere `!` appears in the
13088        // value, including at consecutive positions in the middle.
13089        let d = dep_with_fonte(DepSource::Path {
13090            caminho: "../foo!!/bar".into(),
13091        });
13092        let err = d.validate().unwrap_err();
13093        assert!(
13094            matches!(
13095                err,
13096                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13097            ),
13098            "got {err:?}",
13099        );
13100    }
13101
13102    #[test]
13103    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_enthusiasm_bang() {
13104        // The English-typography enthusiasm-form paste-from-prose
13105        // idiom: an author writes `:caminho "../caixa-teia!"`
13106        // expecting the substrate to coerce it to a kebab-case slug.
13107        // Pinned separately from the `!<word>` shell-history shape so
13108        // the gate's rationale extends to the paste-from-prose surface
13109        // (the same rationale the peer `is_git_repo_url` bang arm at
13110        // 7d53c68 covers). None of the prior shell-metachar arms cover
13111        // this shape (no `!<word>` reference and no `!!` repeat), so
13112        // the arm is the sole gate on the shape.
13113        let d = dep_with_fonte(DepSource::Path {
13114            caminho: "../caixa-teia!".into(),
13115        });
13116        let err = d.validate().unwrap_err();
13117        assert!(
13118            matches!(
13119                err,
13120                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13121            ),
13122            "got {err:?}",
13123        );
13124    }
13125
13126    #[test]
13127    fn validate_accepts_path_fonte_with_caminho_carrying_no_bang() {
13128        // The positive-control pin (peer with
13129        // `validate_accepts_path_fonte_with_caminho_carrying_no_dollar`
13130        // on the immediate-predecessor arm): the gate targets only
13131        // `!`, never adjacent printable ASCII or POSIX-valid bytes.
13132        // A relative POSIX path carrying dashes / dots / slashes /
13133        // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13134        // validate cleanly so the gate doesn't widen to a "no
13135        // printable punctuation anywhere" sweep that would defeat
13136        // the entire path-fonte author surface.
13137        let d = dep_with_fonte(DepSource::Path {
13138            caminho: "../caixa-teia/sub-dir.v2".into(),
13139        });
13140        d.validate().unwrap();
13141    }
13142
13143    #[test]
13144    fn fonte_caminho_shell_variable_expansion_fires_before_shell_history_expansion() {
13145        // Cascade pin on the immediate-predecessor arm: a value
13146        // carrying both embedded `$` and `!` (`"../foo$HOME/bar!sudo"`
13147        // — the canonical "I pasted a `$HOME`-templated path adjacent
13148        // to a trailing `!sudo` history-expansion") routes through
13149        // `FonteCaminhoShellVariableExpansion` not
13150        // `FonteCaminhoShellHistoryExpansion`. The shell-variable-
13151        // expansion byte is the more semantic-locating axis on
13152        // probe-as-both values (the paste-from-CI-manifest-with-`$VAR`-
13153        // template shape is the load-bearing self-locating edit);
13154        // same cascade discipline every prior `:caminho` arm
13155        // establishes.
13156        let d = dep_with_fonte(DepSource::Path {
13157            caminho: "../foo$HOME/bar!sudo".into(),
13158        });
13159        let err = d.validate().unwrap_err();
13160        assert!(
13161            matches!(
13162                err,
13163                DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13164            ),
13165            "got {err:?}",
13166        );
13167    }
13168
13169    #[test]
13170    fn fonte_caminho_shell_history_expansion_fires_before_trailing_slash() {
13171        // Cascade pin on the immediate-successor arm: a value carrying
13172        // both embedded `!` and a trailing `/` (`"../caixa-teia!sudo/"`
13173        // — the canonical "I tab-completed a `!sudo`-carrying path")
13174        // routes through `FonteCaminhoShellHistoryExpansion` not
13175        // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13176        // expansion byte is the more semantic-locating axis on probe-
13177        // as-both values (an author who removes the `!sudo` history
13178        // reference is likely to also tab-strip the trailing separator).
13179        let d = dep_with_fonte(DepSource::Path {
13180            caminho: "../caixa-teia!sudo/".into(),
13181        });
13182        let err = d.validate().unwrap_err();
13183        assert!(
13184            matches!(
13185                err,
13186                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13187            ),
13188            "got {err:?}",
13189        );
13190    }
13191
13192    #[test]
13193    fn fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13194        // Diagnostic-shape pin (peer with
13195        // `fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13196        // on the immediate-predecessor arm): the error's Display
13197        // surfaces the offending `:nome`, the offending `:caminho`
13198        // verbatim, the offending byte's hex / character form, and
13199        // names the shell-history-expansion / bang-operator footgun
13200        // explicitly so a `feira lint` run can render the diagnostic
13201        // without re-parsing.
13202        let d = dep_with_fonte(DepSource::Path {
13203            caminho: "../caixa-teia!sudo".into(),
13204        });
13205        let rendered = d.validate().unwrap_err().to_string();
13206        assert!(
13207            rendered.contains("caixa-teia"),
13208            "diagnostic must name the offending dep: {rendered}",
13209        );
13210        assert!(
13211            rendered.contains("../caixa-teia!sudo"),
13212            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13213        );
13214        assert!(
13215            rendered.contains("0x21"),
13216            "diagnostic must surface the offending byte hex: {rendered:?}",
13217        );
13218        assert!(
13219            rendered.contains("history-expansion") || rendered.contains("history expansion"),
13220            "diagnostic must name the shell-history-expansion footgun: {rendered:?}",
13221        );
13222        assert!(
13223            rendered.contains("bang"),
13224            "diagnostic must reference the bang-operator vocabulary: {rendered:?}",
13225        );
13226    }
13227
13228    #[test]
13229    fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_substitution() {
13230        // The fail-before-pass-after pin for the canonical paste-from-
13231        // shell-history-quick-substitution footgun on `:caminho`. An
13232        // author copies a `git clone <bad-url>` line from their terminal,
13233        // corrects it via bash's `^bad^good` quick-substitution history
13234        // operator (bash reference §9.3, `set -o histexpand` mode's
13235        // default for interactive sessions), and pastes the trailing
13236        // `^bad^good` substitution fragment into a `:caminho` value
13237        // without trimming the leading `git clone` prefix — the byte
13238        // rides into the manifest verbatim. Until this arm landed the
13239        // `^` byte silently passed every prior `:caminho` cascade arm
13240        // (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick / `*`
13241        // / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` / `#` /
13242        // `%` / `$` / `!`); bash with the default `histexpand` mode
13243        // rewrites the prior command's `bad` string to `good` and re-
13244        // executes it, the paired-operator half of the `set -o
13245        // histexpand` feature the peer `!` arm already closes the prefix
13246        // half of. The peer `is_git_repo_url` axis rejects the byte at
13247        // 49e142f under the same shell-history-substitution / RFC-3986-
13248        // unwise banner.
13249        let d = dep_with_fonte(DepSource::Path {
13250            caminho: "../foo^bad^good".into(),
13251        });
13252        let err = d.validate().unwrap_err();
13253        let DepError::FonteCaminhoShellHistorySubstitution {
13254            nome,
13255            caminho,
13256            byte,
13257        } = err
13258        else {
13259            panic!("expected FonteCaminhoShellHistorySubstitution, got {err:?}");
13260        };
13261        assert_eq!(nome, "caixa-teia");
13262        assert_eq!(caminho, "../foo^bad^good");
13263        assert_eq!(byte, b'^');
13264    }
13265
13266    #[test]
13267    fn validate_rejects_path_fonte_with_caminho_carrying_regex_negation_anchor() {
13268        // The symmetric paste-from-doc-grep-pipeline footgun (peer with
13269        // `validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor`
13270        // on `is_git_repo_url`). An author copies a `grep '^archived'`
13271        // regex-anchor / negation idiom from a doc snippet and the byte
13272        // rides in verbatim. Pinned separately from the `^old^new^`
13273        // quick-substitution shape so a future diagnostic-surface change
13274        // that only checked the paired-caret history-substitution
13275        // position surfaces here — the per-byte arm fires anywhere `^`
13276        // appears in the value, including at a solitary leading-of-
13277        // segment position.
13278        let d = dep_with_fonte(DepSource::Path {
13279            caminho: "../foo/^archived".into(),
13280        });
13281        let err = d.validate().unwrap_err();
13282        assert!(
13283            matches!(
13284                err,
13285                DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13286            ),
13287            "got {err:?}",
13288        );
13289    }
13290
13291    #[test]
13292    fn validate_rejects_path_fonte_with_caminho_carrying_trailing_history_substitution_open() {
13293        // The trailing-`^` history-substitution-open shape — an author
13294        // starts typing a `^bad^good` quick-substitution but pastes only
13295        // the leading `^` sentinel before context-switching (a bash-
13296        // reference §9.3 valid histexpand prefix on its own — even a
13297        // solitary `^` on the prior command's whole re-execution shape).
13298        // Pinned separately from the `^old^new^` full-form and the leading-
13299        // of-segment `^archived` regex-anchor shape so the gate's
13300        // rationale extends to the paste-from-shell-history-with-only-
13301        // the-first-byte-selected surface. None of the prior shell-
13302        // metachar arms cover this shape.
13303        let d = dep_with_fonte(DepSource::Path {
13304            caminho: "../caixa-teia^".into(),
13305        });
13306        let err = d.validate().unwrap_err();
13307        assert!(
13308            matches!(
13309                err,
13310                DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13311            ),
13312            "got {err:?}",
13313        );
13314    }
13315
13316    #[test]
13317    fn validate_accepts_path_fonte_with_caminho_carrying_no_caret() {
13318        // The positive-control pin (peer with
13319        // `validate_accepts_path_fonte_with_caminho_carrying_no_bang`
13320        // on the immediate-predecessor arm): the gate targets only
13321        // `^`, never adjacent printable ASCII or POSIX-valid bytes.
13322        // A relative POSIX path carrying dashes / dots / slashes /
13323        // digits / underscore (`"../caixa-teia/sub_v2.rc"`) must
13324        // continue to validate cleanly so the gate doesn't widen to
13325        // a "no printable punctuation anywhere" sweep that would
13326        // defeat the entire path-fonte author surface.
13327        let d = dep_with_fonte(DepSource::Path {
13328            caminho: "../caixa-teia/sub_v2.rc".into(),
13329        });
13330        d.validate().unwrap();
13331    }
13332
13333    #[test]
13334    fn fonte_caminho_shell_history_expansion_fires_before_shell_history_substitution() {
13335        // Cascade pin on the immediate-predecessor arm: a value carrying
13336        // both embedded `!` and `^` (`"../foo!sudo^bad^good"` — the
13337        // canonical "I pasted a `!sudo` history-reference next to a
13338        // `^bad^good` quick-substitution") routes through
13339        // `FonteCaminhoShellHistoryExpansion` not
13340        // `FonteCaminhoShellHistorySubstitution`. The `!` prefix form is
13341        // the more semantic-locating axis on probe-as-both values (an
13342        // author who removes the `!sudo` reference is likely to also
13343        // strip the paired `^` substitution fragment); same cascade
13344        // discipline every prior `:caminho` arm establishes.
13345        let d = dep_with_fonte(DepSource::Path {
13346            caminho: "../foo!sudo^bad^good".into(),
13347        });
13348        let err = d.validate().unwrap_err();
13349        assert!(
13350            matches!(
13351                err,
13352                DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13353            ),
13354            "got {err:?}",
13355        );
13356    }
13357
13358    #[test]
13359    fn fonte_caminho_shell_history_substitution_fires_before_trailing_slash() {
13360        // Cascade pin on the immediate-successor arm: a value carrying
13361        // both embedded `^` and a trailing `/` (`"../foo^bad^good/"` —
13362        // the canonical "I tab-completed a `^bad^good`-carrying path")
13363        // routes through `FonteCaminhoShellHistorySubstitution` not
13364        // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13365        // substitution byte is the more semantic-locating axis on probe-
13366        // as-both values (an author who removes the `^bad^good`
13367        // substitution fragment is likely to also tab-strip the trailing
13368        // separator).
13369        let d = dep_with_fonte(DepSource::Path {
13370            caminho: "../foo^bad^good/".into(),
13371        });
13372        let err = d.validate().unwrap_err();
13373        assert!(
13374            matches!(
13375                err,
13376                DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13377            ),
13378            "got {err:?}",
13379        );
13380    }
13381
13382    #[test]
13383    fn fonte_caminho_shell_history_substitution_diagnostic_carries_offending_dep_caminho_and_byte()
13384    {
13385        // Diagnostic-shape pin (peer with
13386        // `fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13387        // on the immediate-predecessor arm): the error's Display
13388        // surfaces the offending `:nome`, the offending `:caminho`
13389        // verbatim, the offending byte's hex form, and names the
13390        // shell-history-substitution / RFC-3986-'unwise' / regex-
13391        // negation footgun explicitly so a `feira lint` run can render
13392        // the diagnostic without re-parsing.
13393        let d = dep_with_fonte(DepSource::Path {
13394            caminho: "../foo^bad^good".into(),
13395        });
13396        let rendered = d.validate().unwrap_err().to_string();
13397        assert!(
13398            rendered.contains("caixa-teia"),
13399            "diagnostic must name the offending dep: {rendered}",
13400        );
13401        assert!(
13402            rendered.contains("../foo^bad^good"),
13403            "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13404        );
13405        assert!(
13406            rendered.contains("0x5e") || rendered.contains("0x5E"),
13407            "diagnostic must surface the offending byte hex: {rendered:?}",
13408        );
13409        assert!(
13410            rendered.contains("history-substitution") || rendered.contains("history substitution"),
13411            "diagnostic must name the shell-history-substitution footgun: {rendered:?}",
13412        );
13413        assert!(
13414            rendered.contains("unwise"),
13415            "diagnostic must reference the RFC-3986 'unwise' set vocabulary: {rendered:?}",
13416        );
13417    }
13418
13419    #[test]
13420    fn fonte_repo_empty_fires_before_pin_missing() {
13421        // Order pin: empty `:repo` is the more self-locating diagnostic
13422        // (every git source needs a repo; the pin discussion is
13423        // secondary), so it fires before the pin-missing arm even when
13424        // both are violated. Mirrors the
13425        // `nome_empty_takes_precedence_over_versao_invalid` ordering
13426        // discipline on the per-entry layer.
13427        let d = dep_with_fonte(DepSource::Git {
13428            repo: String::new(),
13429            tag: None,
13430            rev: None,
13431            branch: None,
13432        });
13433        let err = d.validate().unwrap_err();
13434        assert!(
13435            matches!(err, DepError::FonteRepoEmpty { .. }),
13436            "got {err:?}"
13437        );
13438    }
13439
13440    #[test]
13441    fn fonte_pin_missing_fires_before_pin_empty() {
13442        // Order pin: a fully-None pin set is structurally distinct from
13443        // a Some(empty) pin — the first surfaces as FontePinMissing
13444        // (no axis chosen), the second as FontePinEmpty (axis chosen
13445        // but value blank). Pin the disjoint relationship so a future
13446        // unification collapses to one variant only as a structural
13447        // decision.
13448        let d = dep_with_fonte(DepSource::Git {
13449            repo: "github:pleme-io/caixa-teia".into(),
13450            tag: None,
13451            rev: None,
13452            branch: None,
13453        });
13454        assert!(matches!(
13455            d.validate().unwrap_err(),
13456            DepError::FontePinMissing { .. }
13457        ));
13458    }
13459
13460    #[test]
13461    fn nome_empty_takes_precedence_over_fonte_invalid() {
13462        // Order pin: a per-entry diagnostic without a non-empty :nome
13463        // can't be self-locating, so :nome "" fires first even when
13464        // :fonte is also malformed. Mirrors
13465        // `nome_empty_takes_precedence_over_versao_invalid` on the
13466        // adjacent axis.
13467        let mut d = dep_with_fonte(DepSource::Git {
13468            repo: String::new(),
13469            tag: None,
13470            rev: None,
13471            branch: None,
13472        });
13473        d.nome = String::new();
13474        assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
13475    }
13476
13477    #[test]
13478    fn versao_invalid_takes_precedence_over_fonte_invalid() {
13479        // Order pin: the :versao parse-side diagnostic is narrower than
13480        // the :fonte shape diagnostic — a malformed :versao always names
13481        // the parser's reason, which is more actionable than the
13482        // :fonte gate's "the pins are wrong" wording. Pin the ordering
13483        // so a re-ordering surfaces here.
13484        let mut d = dep_with_fonte(DepSource::Git {
13485            repo: String::new(),
13486            tag: None,
13487            rev: None,
13488            branch: None,
13489        });
13490        d.versao = "v0.1".into();
13491        let err = d.validate().unwrap_err();
13492        assert!(
13493            matches!(err, DepError::VersaoInvalid { ref nome, .. } if nome == "caixa-teia"),
13494            "got {err:?}"
13495        );
13496    }
13497
13498    #[test]
13499    fn fonte_invalid_diagnostic_carries_offending_nome() {
13500        // The diagnostic-shape pin: every :fonte error variant names
13501        // the offending dep's :nome verbatim, so the author can grep
13502        // caixa.lisp for the `:nome "<n>"` block and fix it in one
13503        // edit. Cover all seven variants so a future variant addition
13504        // forces a parallel diagnostic-shape decision.
13505        for (case, fonte) in [
13506            (
13507                "repo-empty",
13508                DepSource::Git {
13509                    repo: String::new(),
13510                    tag: Some("v1".into()),
13511                    rev: None,
13512                    branch: None,
13513                },
13514            ),
13515            (
13516                "repo-shape",
13517                DepSource::Git {
13518                    repo: "github:p/x ".into(),
13519                    tag: Some("v1".into()),
13520                    rev: None,
13521                    branch: None,
13522                },
13523            ),
13524            (
13525                "pin-missing",
13526                DepSource::Git {
13527                    repo: "github:p/x".into(),
13528                    tag: None,
13529                    rev: None,
13530                    branch: None,
13531                },
13532            ),
13533            (
13534                "pin-ambiguous",
13535                DepSource::Git {
13536                    repo: "github:p/x".into(),
13537                    tag: Some("v1".into()),
13538                    rev: None,
13539                    branch: Some("main".into()),
13540                },
13541            ),
13542            (
13543                "pin-empty",
13544                DepSource::Git {
13545                    repo: "github:p/x".into(),
13546                    tag: Some(String::new()),
13547                    rev: None,
13548                    branch: None,
13549                },
13550            ),
13551            (
13552                "caminho-empty",
13553                DepSource::Path {
13554                    caminho: String::new(),
13555                },
13556            ),
13557            (
13558                "caminho-absolute",
13559                DepSource::Path {
13560                    caminho: "/home/me/work/caixa-teia".into(),
13561                },
13562            ),
13563        ] {
13564            let d = dep_with_fonte(fonte);
13565            let msg = d
13566                .validate()
13567                .expect_err(&format!("{case}: expected fonte error"))
13568                .to_string();
13569            assert!(
13570                msg.contains("\"caixa-teia\""),
13571                "{case}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
13572            );
13573        }
13574    }
13575
13576    // -- :tag / :branch value-shape gate ----------------------------------
13577
13578    #[test]
13579    fn validate_rejects_git_fonte_with_tag_carrying_trailing_space() {
13580        // The canonical paste-from-doc footgun on `:tag` — author
13581        // copies `"v0.1.0 "` (trailing space) out of a release-notes
13582        // paragraph. Until this gate landed the empty-pin arm passed
13583        // (the string isn't empty), the resolver issued
13584        // `git fetch <remote> tag 'v0.1.0 '`, and the failure
13585        // surfaced at clone time with a quoting-confused git error
13586        // far from the source caixa.lisp. The new gate moves the
13587        // check to caixa-build time and names the offending dep +
13588        // pin + value verbatim.
13589        let d = dep_with_fonte(DepSource::Git {
13590            repo: "github:pleme-io/caixa-teia".into(),
13591            tag: Some("v0.1.0 ".into()),
13592            rev: None,
13593            branch: None,
13594        });
13595        let err = d.validate().unwrap_err();
13596        let DepError::FontePinShape {
13597            nome,
13598            pin,
13599            value,
13600            reason,
13601        } = err
13602        else {
13603            panic!("expected FontePinShape, got other variant");
13604        };
13605        assert_eq!(nome, "caixa-teia");
13606        assert_eq!(pin, ":tag");
13607        assert_eq!(value, "v0.1.0 ");
13608        assert!(
13609            reason.contains("whitespace"),
13610            "reason must surface the whitespace arm, got {reason:?}"
13611        );
13612    }
13613
13614    #[test]
13615    fn validate_rejects_git_fonte_with_tag_carrying_lock_suffix() {
13616        // The `.lock` suffix is git's atomic-rename guard for
13617        // in-flight ref updates — a refname ending in `.lock` is
13618        // unwritable on disk. Pinned separately from the whitespace
13619        // arm so a future relaxation that admits one but not the
13620        // other surfaces here.
13621        let d = dep_with_fonte(DepSource::Git {
13622            repo: "github:pleme-io/caixa-teia".into(),
13623            tag: Some("v0.1.0.lock".into()),
13624            rev: None,
13625            branch: None,
13626        });
13627        let err = d.validate().unwrap_err();
13628        let DepError::FontePinShape {
13629            pin, value, reason, ..
13630        } = err
13631        else {
13632            panic!("expected FontePinShape, got other variant");
13633        };
13634        assert_eq!(pin, ":tag");
13635        assert_eq!(value, "v0.1.0.lock");
13636        assert!(
13637            reason.contains(".lock"),
13638            "reason must surface the .lock arm, got {reason:?}"
13639        );
13640    }
13641
13642    #[test]
13643    fn validate_rejects_git_fonte_with_branch_carrying_embedded_space() {
13644        // The canonical "branch name with spaces" footgun (`feature
13645        // foo`, `release branch`) — git's refname parser rejects raw
13646        // whitespace, and the failure surfaces at `git checkout
13647        // 'feature foo'` time with a quoting-confused error far from
13648        // the source caixa.lisp. Pinned on the `:branch` axis so the
13649        // gate-applies-to-both-:tag-and-:branch contract is a build-
13650        // error to relax.
13651        let d = dep_with_fonte(DepSource::Git {
13652            repo: "github:pleme-io/caixa-teia".into(),
13653            tag: None,
13654            rev: None,
13655            branch: Some("feature/foo bar".into()),
13656        });
13657        let err = d.validate().unwrap_err();
13658        let DepError::FontePinShape {
13659            pin, value, reason, ..
13660        } = err
13661        else {
13662            panic!("expected FontePinShape, got other variant");
13663        };
13664        assert_eq!(pin, ":branch");
13665        assert_eq!(value, "feature/foo bar");
13666        assert!(
13667            reason.contains("whitespace"),
13668            "reason must surface the whitespace arm, got {reason:?}"
13669        );
13670    }
13671
13672    #[test]
13673    fn validate_rejects_git_fonte_with_branch_carrying_qualified_prefix() {
13674        // The `refs/heads/main` shape — the canonical "I copied the
13675        // fully-qualified ref out of `git show-ref` instead of the
13676        // leaf" footgun. The caixa-resolver prepends `refs/heads/`
13677        // at clone time, so this resolves to a literal ref named
13678        // `refs/heads/refs/heads/main` on disk; the silent double-
13679        // prefix is the load-bearing reason to gate at validate.
13680        // The diagnostic must enumerate the leaf the author probably
13681        // meant (`"main"`) so the fix is one edit.
13682        let d = dep_with_fonte(DepSource::Git {
13683            repo: "github:pleme-io/caixa-teia".into(),
13684            tag: None,
13685            rev: None,
13686            branch: Some("refs/heads/main".into()),
13687        });
13688        let err = d.validate().unwrap_err();
13689        let DepError::FontePinShape {
13690            pin, value, reason, ..
13691        } = err
13692        else {
13693            panic!("expected FontePinShape, got other variant");
13694        };
13695        assert_eq!(pin, ":branch");
13696        assert_eq!(value, "refs/heads/main");
13697        assert!(
13698            reason.contains("fully-qualified"),
13699            "reason must surface the qualified-prefix arm, got {reason:?}"
13700        );
13701        assert!(
13702            reason.contains("\"main\""),
13703            "reason must quote the leaf the author probably meant, got {reason:?}"
13704        );
13705    }
13706
13707    #[test]
13708    fn validate_rejects_git_fonte_with_tag_carrying_qualified_prefix() {
13709        // Sibling arm of the qualified-prefix gate on the `:tag`
13710        // axis (`refs/tags/v0.1.0` — same `git show-ref` output-leak
13711        // footgun). Pinned separately so a future relaxation that
13712        // only catches the `:branch` arm surfaces here.
13713        let d = dep_with_fonte(DepSource::Git {
13714            repo: "github:pleme-io/caixa-teia".into(),
13715            tag: Some("refs/tags/v0.1.0".into()),
13716            rev: None,
13717            branch: None,
13718        });
13719        let err = d.validate().unwrap_err();
13720        let DepError::FontePinShape {
13721            pin, value, reason, ..
13722        } = err
13723        else {
13724            panic!("expected FontePinShape, got other variant");
13725        };
13726        assert_eq!(pin, ":tag");
13727        assert_eq!(value, "refs/tags/v0.1.0");
13728        assert!(
13729            reason.contains("fully-qualified"),
13730            "reason must surface the qualified-prefix arm, got {reason:?}"
13731        );
13732        assert!(
13733            reason.contains("\"v0.1.0\""),
13734            "reason must quote the leaf the author probably meant, got {reason:?}"
13735        );
13736    }
13737
13738    #[test]
13739    fn validate_rejects_git_fonte_with_branch_named_at() {
13740        // The bare `@` is git's alias for `HEAD`; a `:branch "@"` is
13741        // unsourceable. Pinned so a future relaxation that admits
13742        // any single-character refname surfaces here.
13743        let d = dep_with_fonte(DepSource::Git {
13744            repo: "github:pleme-io/caixa-teia".into(),
13745            tag: None,
13746            rev: None,
13747            branch: Some("@".into()),
13748        });
13749        let err = d.validate().unwrap_err();
13750        let DepError::FontePinShape { pin, value, .. } = err else {
13751            panic!("expected FontePinShape, got other variant");
13752        };
13753        assert_eq!(pin, ":branch");
13754        assert_eq!(value, "@");
13755    }
13756
13757    #[test]
13758    fn validate_rejects_git_fonte_with_tag_carrying_double_dot() {
13759        // Git's `<rev1>..<rev2>` range grammar reserves `..` —
13760        // a `:tag "../escape"` (path-traversal-shaped slug) silently
13761        // passes parse and surfaces as a refname-parse error or, on
13762        // older git, a literal `../escape` checkout that escapes the
13763        // refs/ directory tree. Pinned separately from the
13764        // qualified-prefix arm so a future relaxation that catches
13765        // one but not the other surfaces here.
13766        let d = dep_with_fonte(DepSource::Git {
13767            repo: "github:pleme-io/caixa-teia".into(),
13768            tag: Some("../escape".into()),
13769            rev: None,
13770            branch: None,
13771        });
13772        let err = d.validate().unwrap_err();
13773        let DepError::FontePinShape { pin, value, .. } = err else {
13774            panic!("expected FontePinShape, got other variant");
13775        };
13776        assert_eq!(pin, ":tag");
13777        assert_eq!(value, "../escape");
13778    }
13779
13780    #[test]
13781    fn validate_accepts_git_fonte_with_hierarchical_branch() {
13782        // The positive-control pin: hierarchical refnames with one or
13783        // more `/` separators (the `feature/foo` / `user/jdoe/feat`
13784        // canonical idiom) round-trip through the gate. Pinned
13785        // separately from the leaf-`"main"` positive control so a
13786        // future tightening that rejects all multi-component refnames
13787        // surfaces here.
13788        let d = dep_with_fonte(DepSource::Git {
13789            repo: "github:pleme-io/caixa-teia".into(),
13790            tag: None,
13791            rev: None,
13792            branch: Some("feature/checkout-rewrite".into()),
13793        });
13794        d.validate().unwrap();
13795    }
13796
13797    #[test]
13798    fn validate_accepts_git_fonte_with_prerelease_tag() {
13799        // The positive-control pin: semver pre-release shape
13800        // (`v0.1.0-alpha.1`) — the in-component dot is allowed
13801        // (only consecutive `..` and trailing `.` are rejected), the
13802        // mid-component hyphen is allowed. Pinned separately from
13803        // the bare-`"v0.1.0"` positive control so a future tightening
13804        // that rejects pre-release tags surfaces here.
13805        let d = dep_with_fonte(DepSource::Git {
13806            repo: "github:pleme-io/caixa-teia".into(),
13807            tag: Some("v0.1.0-alpha.1".into()),
13808            rev: None,
13809            branch: None,
13810        });
13811        d.validate().unwrap();
13812    }
13813
13814    #[test]
13815    fn validate_rejects_git_fonte_with_rev_carrying_refname_unfriendly_value() {
13816        // The `:rev` axis is routed through `crate::render::is_git_oid`
13817        // (a SHA's character set is `[0-9a-f]`, not a refname's), so a
13818        // value with refname-shape punctuation (here, a `:` mid-string
13819        // — would be a refname violation under `is_git_ref_name` too)
13820        // is rejected at the OID-shape gate. The two predicates
13821        // partition the `:fonte` pin axes structurally: an `:rev` value
13822        // that's a valid refname (`:rev "main"`, `:rev "v0.1.0"`) is
13823        // *still* rejected here because every refname character outside
13824        // `[0-9a-f]` fails the OID gate. Same shape as
13825        // `fonte_pin_shape_diagnostic_carries_offending_nome_pin_value`
13826        // on the refname-shaped axes — the diagnostic names the
13827        // offending dep + pin + value verbatim. The flip-from-accept
13828        // case the prior `:tag`/`:branch` gate left as a "future axis"
13829        // (e70d213) — now landed.
13830        let d = dep_with_fonte(DepSource::Git {
13831            repo: "github:pleme-io/caixa-teia".into(),
13832            tag: None,
13833            rev: Some("c0ffee:notarefname".into()),
13834            branch: None,
13835        });
13836        let err = d.validate().unwrap_err();
13837        let DepError::FontePinShape {
13838            nome,
13839            pin,
13840            value,
13841            reason,
13842        } = err
13843        else {
13844            panic!("expected FontePinShape, got other variant");
13845        };
13846        assert_eq!(nome, "caixa-teia");
13847        assert_eq!(pin, ":rev");
13848        assert_eq!(value, "c0ffee:notarefname");
13849        assert!(
13850            !reason.is_empty(),
13851            "FontePinShape `reason` must carry the predicate's wording verbatim"
13852        );
13853    }
13854
13855    #[test]
13856    fn validate_accepts_git_fonte_with_rev_full_sha1() {
13857        // The positive-control pin on the SHA-1 OID width: exactly 40
13858        // lowercase hex characters — the canonical `git rev-parse HEAD`
13859        // emission on a SHA-1-hashed repository (the default on every
13860        // pre-2.42 git and the canonical pleme-io substrate hash).
13861        // Pinned separately from the SHA-256 positive control so a
13862        // future tightening that only admits one width surfaces here.
13863        let d = dep_with_fonte(DepSource::Git {
13864            repo: "github:pleme-io/caixa-teia".into(),
13865            tag: None,
13866            rev: Some("0123456789abcdef0123456789abcdef01234567".into()),
13867            branch: None,
13868        });
13869        d.validate().unwrap();
13870    }
13871
13872    #[test]
13873    fn validate_accepts_git_fonte_with_rev_full_sha256() {
13874        // The positive-control pin on the SHA-256 OID width: exactly
13875        // 64 lowercase hex characters — `git`'s
13876        // `extensions.objectFormat = sha256` emission (GA since Git
13877        // 2.42 / Oct 2023). The substrate admits either canonical
13878        // width so an `:rev` authored against a SHA-256-hashed
13879        // upstream round-trips through the gate without per-repo
13880        // configuration. Pinned separately from the SHA-1 positive
13881        // control so a future tightening that drops one width surfaces
13882        // here as a structural decision.
13883        let d = dep_with_fonte(DepSource::Git {
13884            repo: "github:pleme-io/caixa-teia".into(),
13885            tag: None,
13886            rev: Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into()),
13887            branch: None,
13888        });
13889        d.validate().unwrap();
13890    }
13891
13892    #[test]
13893    fn validate_rejects_git_fonte_with_rev_abbreviated_prefix() {
13894        // The canonical `git log --short` / `git rev-parse --short HEAD`
13895        // paste-from-release-notes footgun: a 7-char prefix (git's
13896        // default `core.abbrev`) silently passes string emptiness
13897        // checks and resolves to one commit today, but becomes ambiguous
13898        // tomorrow as the repo grows. Until this gate landed the empty-
13899        // pin arm passed (the string isn't empty) and the resolver
13900        // accepted the prefix through git's separate prefix-lookup pass
13901        // — defeating the reproducibility contract `:rev` carries vs.
13902        // `:tag` / `:branch`. The new gate moves the check to caixa-
13903        // build time and names the offending dep + pin + value verbatim.
13904        let d = dep_with_fonte(DepSource::Git {
13905            repo: "github:pleme-io/caixa-teia".into(),
13906            tag: None,
13907            rev: Some("c0ffee0".into()),
13908            branch: None,
13909        });
13910        let err = d.validate().unwrap_err();
13911        let DepError::FontePinShape {
13912            pin, value, reason, ..
13913        } = err
13914        else {
13915            panic!("expected FontePinShape, got other variant");
13916        };
13917        assert_eq!(pin, ":rev");
13918        assert_eq!(value, "c0ffee0");
13919        assert!(
13920            reason.contains("abbreviated") || reason.contains("ambiguous"),
13921            "reason must surface the abbreviation arm, got {reason:?}"
13922        );
13923    }
13924
13925    #[test]
13926    fn validate_rejects_git_fonte_with_rev_uppercase_hex() {
13927        // The canonical "I pasted the SHA in uppercase" footgun: `git
13928        // porcelain` emits OIDs lowercase exclusively, so an uppercase-
13929        // bearing `:rev` round-trips inconsistently across the
13930        // resolver's `git fetch <remote> <:rev>` ↔ `git rev-parse HEAD`
13931        // equality-check pipeline and fails the lacre's content-
13932        // addressing probe with a confusing case-only diff. Pinned
13933        // separately from the non-hex arm so a future relaxation that
13934        // admits one but not the other surfaces here.
13935        let d = dep_with_fonte(DepSource::Git {
13936            repo: "github:pleme-io/caixa-teia".into(),
13937            tag: None,
13938            rev: Some("DEADBEEFCAFEBABE0123456789ABCDEF01234567".into()),
13939            branch: None,
13940        });
13941        let err = d.validate().unwrap_err();
13942        let DepError::FontePinShape {
13943            pin, value, reason, ..
13944        } = err
13945        else {
13946            panic!("expected FontePinShape, got other variant");
13947        };
13948        assert_eq!(pin, ":rev");
13949        assert_eq!(value, "DEADBEEFCAFEBABE0123456789ABCDEF01234567");
13950        assert!(
13951            reason.contains("uppercase"),
13952            "reason must surface the uppercase arm, got {reason:?}"
13953        );
13954    }
13955
13956    #[test]
13957    fn validate_rejects_git_fonte_with_rev_refname_value() {
13958        // The cross-axis mis-slot footgun: `:rev "main"` — the author
13959        // conflated `:rev` (hex commit ID, immutable) and `:branch`
13960        // (mutable ref pointing at whatever HEAD is today). Until this
13961        // gate landed the resolver silently dispatched on the value
13962        // shape ("`main` doesn't look like a SHA, fall back to
13963        // refname"), defeating the `:rev` reproducibility contract.
13964        // The new gate rejects every non-hex value on the `:rev` axis,
13965        // so the `:rev`/`:branch` boundary is structurally enforced —
13966        // a refname in the `:rev` slot is a build error, not a
13967        // resolver-time silent reinterpretation.
13968        let d = dep_with_fonte(DepSource::Git {
13969            repo: "github:pleme-io/caixa-teia".into(),
13970            tag: None,
13971            rev: Some("main".into()),
13972            branch: None,
13973        });
13974        let err = d.validate().unwrap_err();
13975        let DepError::FontePinShape {
13976            pin, value, reason, ..
13977        } = err
13978        else {
13979            panic!("expected FontePinShape, got other variant");
13980        };
13981        assert_eq!(pin, ":rev");
13982        assert_eq!(value, "main");
13983        // 4 chars `main` fails the length arm before the character arm,
13984        // so the diagnostic surfaces the abbreviation wording (same
13985        // path the `c0ffee0` 7-char fixture lands on); the structural
13986        // assertion is just that the `:rev "main"` value is rejected.
13987        assert!(
13988            !reason.is_empty(),
13989            "FontePinShape reason must be non-empty for refname-shaped :rev"
13990        );
13991    }
13992
13993    #[test]
13994    fn validate_rejects_git_fonte_with_rev_tag_shaped_value() {
13995        // Sibling cross-axis mis-slot: `:rev "v0.1.0"` — the author
13996        // conflated `:rev` and `:tag`. Pinned separately from the
13997        // `:rev "main"` (`:branch` mis-slot) arm so a future relaxation
13998        // that catches one but not the other surfaces here. The
13999        // length arm fires first (6 chars ≠ 40 ≠ 64); the structural
14000        // assertion is just that the cross-axis mis-slot is a build
14001        // error, regardless of which sub-arm surfaces the diagnostic
14002        // (`is_git_oid` rejects at the first violation; longer
14003        // tag-shape values would hit the non-hex arm instead).
14004        let d = dep_with_fonte(DepSource::Git {
14005            repo: "github:pleme-io/caixa-teia".into(),
14006            tag: None,
14007            rev: Some("v0.1.0".into()),
14008            branch: None,
14009        });
14010        let err = d.validate().unwrap_err();
14011        let DepError::FontePinShape {
14012            pin, value, reason, ..
14013        } = err
14014        else {
14015            panic!("expected FontePinShape, got other variant");
14016        };
14017        assert_eq!(pin, ":rev");
14018        assert_eq!(value, "v0.1.0");
14019        assert!(
14020            !reason.is_empty(),
14021            "FontePinShape reason must be non-empty for tag-shaped :rev"
14022        );
14023    }
14024
14025    #[test]
14026    fn validate_rejects_git_fonte_with_rev_too_long() {
14027        // Boundary case on the upper end: 41 hex chars — one past the
14028        // SHA-1 width, well below the SHA-256 width. Pin so a future
14029        // relaxation that admits "long enough to be a SHA" without
14030        // matching either canonical width surfaces here. The diagnostic
14031        // names the offending length verbatim so the author's grep
14032        // target is unambiguous (either trim one char or paste the
14033        // full SHA-256).
14034        let too_long: String = "0".repeat(41);
14035        let d = dep_with_fonte(DepSource::Git {
14036            repo: "github:pleme-io/caixa-teia".into(),
14037            tag: None,
14038            rev: Some(too_long.clone()),
14039            branch: None,
14040        });
14041        let err = d.validate().unwrap_err();
14042        let DepError::FontePinShape {
14043            pin, value, reason, ..
14044        } = err
14045        else {
14046            panic!("expected FontePinShape, got other variant");
14047        };
14048        assert_eq!(pin, ":rev");
14049        assert_eq!(value, too_long);
14050        assert!(
14051            reason.contains("41"),
14052            "reason must surface the offending length verbatim, got {reason:?}"
14053        );
14054    }
14055
14056    #[test]
14057    fn validate_rejects_git_fonte_with_rev_carrying_whitespace() {
14058        // The canonical paste-from-doc footgun on `:rev` — author
14059        // copies `"deadbeefcafe…0123 "` (trailing space) out of a
14060        // commit-message paragraph. Until this gate landed the empty-
14061        // pin arm passed (the string isn't empty), the resolver issued
14062        // `git fetch <remote> 'deadbeef… '` and the failure surfaced at
14063        // clone time with a quoting-confused git error far from the
14064        // source caixa.lisp. The new gate moves the check to caixa-
14065        // build time. Length is 41 (40 hex + space) so the length arm
14066        // fires first — pinned separately from the pure-length arm to
14067        // ensure the diagnostic surfaces *some* parser wording, not
14068        // silently pass through.
14069        let with_space = "0123456789abcdef0123456789abcdef01234567 ".to_string();
14070        let d = dep_with_fonte(DepSource::Git {
14071            repo: "github:pleme-io/caixa-teia".into(),
14072            tag: None,
14073            rev: Some(with_space.clone()),
14074            branch: None,
14075        });
14076        let err = d.validate().unwrap_err();
14077        let DepError::FontePinShape {
14078            pin, value, reason, ..
14079        } = err
14080        else {
14081            panic!("expected FontePinShape, got other variant");
14082        };
14083        assert_eq!(pin, ":rev");
14084        assert_eq!(value, with_space);
14085        assert!(
14086            !reason.is_empty(),
14087            "FontePinShape reason must be non-empty for whitespace-bearing :rev"
14088        );
14089    }
14090
14091    #[test]
14092    fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value_for_rev() {
14093        // Diagnostic-shape pin on the `:rev` axis: every FontePinShape
14094        // variant on this axis names the offending dep's `:nome` + the
14095        // `:rev` axis + the offending value verbatim, so the author's
14096        // grep target is the literal `:rev "<value>"` block in
14097        // caixa.lisp. Sibling of the `fonte_pin_shape_diagnostic_
14098        // carries_offending_nome_pin_value` test on the refname-shaped
14099        // (`:tag` / `:branch`) axes.
14100        let d = dep_with_fonte(DepSource::Git {
14101            repo: "github:p/x".into(),
14102            tag: None,
14103            rev: Some("not-a-sha".into()),
14104            branch: None,
14105        });
14106        let msg = d
14107            .validate()
14108            .expect_err(":rev: expected FontePinShape")
14109            .to_string();
14110        assert!(
14111            msg.contains("\"caixa-teia\""),
14112            ":rev: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14113        );
14114        assert!(
14115            msg.contains(":rev"),
14116            ":rev: diagnostic must name the offending pin axis, got {msg:?}"
14117        );
14118        assert!(
14119            msg.contains("not-a-sha"),
14120            ":rev: diagnostic must quote the offending value verbatim, got {msg:?}"
14121        );
14122    }
14123
14124    #[test]
14125    fn fonte_pin_empty_fires_before_pin_shape() {
14126        // Order pin: a `Some("")` `:tag` is the more self-locating
14127        // diagnostic (the author chose an axis but left it blank;
14128        // grep is unambiguous), so it fires before the shape gate
14129        // even when both arms would match. Pinned so a future
14130        // reordering surfaces here. Mirrors the
14131        // `fonte_repo_empty_fires_before_pin_missing` ordering
14132        // discipline on the peer per-axis arms.
14133        let d = dep_with_fonte(DepSource::Git {
14134            repo: "github:pleme-io/caixa-teia".into(),
14135            tag: Some(String::new()),
14136            rev: None,
14137            branch: None,
14138        });
14139        assert!(matches!(
14140            d.validate().unwrap_err(),
14141            DepError::FontePinEmpty { ref pin, .. } if pin == ":tag"
14142        ));
14143    }
14144
14145    #[test]
14146    fn fonte_pin_shape_fires_after_repo_empty() {
14147        // Order pin: `:repo ""` is the more self-locating axis
14148        // (every git source needs a repo; the per-pin shape gate is
14149        // secondary), so the repo-empty arm fires before the
14150        // per-pin shape arm even when both are violated. Pinned so
14151        // a future reordering surfaces here. Mirrors
14152        // `fonte_repo_empty_fires_before_pin_missing` on the
14153        // adjacent axis pair.
14154        let d = dep_with_fonte(DepSource::Git {
14155            repo: String::new(),
14156            tag: Some("v0.1.0 ".into()),
14157            rev: None,
14158            branch: None,
14159        });
14160        assert!(matches!(
14161            d.validate().unwrap_err(),
14162            DepError::FonteRepoEmpty { .. }
14163        ));
14164    }
14165
14166    #[test]
14167    fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value() {
14168        // Diagnostic-shape pin across both refname-shaped axes
14169        // (`:tag` + `:branch`): every `FontePinShape` variant names
14170        // the offending dep's `:nome` + the offending pin axis + the
14171        // offending value verbatim, so the author's grep target is
14172        // unambiguous (the literal `:tag "<value>"` / `:branch
14173        // "<value>"` lands in caixa.lisp with quotes). Cover both
14174        // pin axes so a future variant addition forces a parallel
14175        // diagnostic-shape decision.
14176        for (pin_label, fonte) in [
14177            (
14178                ":tag",
14179                DepSource::Git {
14180                    repo: "github:p/x".into(),
14181                    tag: Some("v0.1.0~1".into()),
14182                    rev: None,
14183                    branch: None,
14184                },
14185            ),
14186            (
14187                ":branch",
14188                DepSource::Git {
14189                    repo: "github:p/x".into(),
14190                    tag: None,
14191                    rev: None,
14192                    branch: Some("feature/foo*".into()),
14193                },
14194            ),
14195        ] {
14196            let d = dep_with_fonte(fonte);
14197            let msg = d
14198                .validate()
14199                .expect_err(&format!("{pin_label}: expected FontePinShape"))
14200                .to_string();
14201            assert!(
14202                msg.contains("\"caixa-teia\""),
14203                "{pin_label}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14204            );
14205            assert!(
14206                msg.contains(pin_label),
14207                "{pin_label}: diagnostic must name the offending pin axis, got {msg:?}"
14208            );
14209        }
14210    }
14211
14212    #[test]
14213    fn git_source_json_round_trip() {
14214        let src = DepSource::Git {
14215            repo: "github:pleme-io/caixa-teia".into(),
14216            tag: Some("v0.1.0".into()),
14217            rev: None,
14218            branch: None,
14219        };
14220        let s = serde_json::to_string(&src).unwrap();
14221        assert!(s.contains(&format!(
14222            r#""{tipo}":"{git}""#,
14223            tipo = crate::render::DEP_SOURCE_KEY_TIPO,
14224            git = crate::render::DEP_SOURCE_TIPO_GIT,
14225        )));
14226        assert!(s.contains(r#""repo":"github:pleme-io/caixa-teia""#));
14227        assert!(s.contains(r#""tag":"v0.1.0""#));
14228        assert!(!s.contains("rev"));
14229        assert!(!s.contains("branch"));
14230        let round: DepSource = serde_json::from_str(&s).unwrap();
14231        assert_eq!(round, src);
14232    }
14233
14234    // ── DEP_SOURCE_{KEY_TIPO,TIPO_GIT,TIPO_PATH} drift-detection ────────
14235    //
14236    // The `#[serde(tag = "tipo", rename_all = "lowercase")]` derive
14237    // attribute on [`DepSource`] pins three load-bearing byte-sequences
14238    // that flow into every serialized `Dep.fonte` block: the outer
14239    // discriminator-key `"tipo"` the `tag = "tipo"` attribute names, and
14240    // the two admitted variant-tag values `"git"` / `"path"` the
14241    // `rename_all = "lowercase"` attribute pins as the discriminator's
14242    // closed-set arms. The three pin tests below round-trip a
14243    // fully-populated variant of each arm through
14244    // [`serde_json::to_value`] and assert each canonical byte-sequence
14245    // appears at its axis — pins a hypothetical future
14246    // `tag = "type"` / `tag = "source_type"` typo, a `rename_all`
14247    // rebrand (`"UPPERCASE"` / `"snake_case"` / `"kebab-case"`), or a
14248    // Rust-side variant rename (`Git` → `Repository`, `Path` → `Local`)
14249    // at build time rather than at fetch time when the resolver's
14250    // `Dep.fonte` dispatch silently fails to match on the drifted
14251    // discriminator. Same "serialize-and-check" discipline the peer
14252    // `M2_LIMITS_KEY_*`, `M2_BEHAVIOR_KEY_ON_*`, `SUPERVISOR_KEY_*`,
14253    // and `MEMBRO_KEY_*` drift-detection pins carry — extended here
14254    // to the last `#[serde(tag = ..., rename_all = ...)]` discriminator
14255    // family in caixa-core lacking a lifted peer.
14256
14257    #[test]
14258    fn dep_source_git_serde_keys_match_lifted_dep_source_key_consts() {
14259        // Fail-before-pass-after: a future `tag = "type"` at the derive
14260        // attribute would serialize under `"type":"git"`, and this test
14261        // would trip because `"tipo"` no longer appears at the emitted
14262        // discriminator key. A future `rename_all = "kebab-case"` /
14263        // `"snake_case"` (both no-ops on `Git` since it lacks internal
14264        // word boundaries) is caught by the sibling
14265        // `dep_source_path_serde_keys_match_lifted_dep_source_key_consts`
14266        // pin below (Path has no internal boundary either but the pair
14267        // catches any per-arm inconsistency). A future variant rename
14268        // `Git` → `Repository` would emit `"tipo":"repository"` and
14269        // trip this pin.
14270        let src = DepSource::Git {
14271            repo: "github:pleme-io/caixa-teia".into(),
14272            tag: Some("v0.1.0".into()),
14273            rev: None,
14274            branch: None,
14275        };
14276        let json = serde_json::to_value(&src).unwrap();
14277        let obj = json.as_object().expect("Git serializes as a JSON object");
14278        assert_eq!(
14279            obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14280                .and_then(serde_json::Value::as_str),
14281            Some(crate::render::DEP_SOURCE_TIPO_GIT),
14282            "DepSource::Git must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14283             with value DEP_SOURCE_TIPO_GIT — attribute drift or variant rename \
14284             detected in {json}"
14285        );
14286    }
14287
14288    #[test]
14289    fn dep_source_path_serde_keys_match_lifted_dep_source_key_consts() {
14290        // Fail-before-pass-after: a future variant rename `Path` →
14291        // `Local` / `Filesystem` would emit `"tipo":"local"` and trip
14292        // this pin. A per-consumer disambiguation as the `defcaixa`
14293        // macro stabilizes ("caminho" → "path" for English-uniformity)
14294        // is scoped to the inner field key, not the discriminator; this
14295        // pin is orthogonal to that and catches only the outer
14296        // discriminator drift.
14297        let src = DepSource::Path {
14298            caminho: "../caixa-teia".into(),
14299        };
14300        let json = serde_json::to_value(&src).unwrap();
14301        let obj = json.as_object().expect("Path serializes as a JSON object");
14302        assert_eq!(
14303            obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14304                .and_then(serde_json::Value::as_str),
14305            Some(crate::render::DEP_SOURCE_TIPO_PATH),
14306            "DepSource::Path must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14307             with value DEP_SOURCE_TIPO_PATH — attribute drift or variant rename \
14308             detected in {json}"
14309        );
14310    }
14311
14312    #[test]
14313    fn dep_source_key_consts_are_pairwise_distinct() {
14314        // Cross-axis collapse detector: a hypothetical future edit that
14315        // accidentally set two of the three consts to the same byte
14316        // (`DEP_SOURCE_TIPO_GIT = "path"` typo matching a peer arm) would
14317        // pass every per-arm serialize pin above but silently collapse
14318        // the discriminator's closed-set arms onto one another; this pin
14319        // catches the collapse at build time.
14320        assert_ne!(
14321            crate::render::DEP_SOURCE_KEY_TIPO,
14322            crate::render::DEP_SOURCE_TIPO_GIT,
14323        );
14324        assert_ne!(
14325            crate::render::DEP_SOURCE_KEY_TIPO,
14326            crate::render::DEP_SOURCE_TIPO_PATH,
14327        );
14328        assert_ne!(
14329            crate::render::DEP_SOURCE_TIPO_GIT,
14330            crate::render::DEP_SOURCE_TIPO_PATH,
14331        );
14332    }
14333
14334    #[test]
14335    fn dep_source_tipo_variant_consts_are_ascii_lowercase_shape() {
14336        // Shape pin against `rename_all` drift: the two variant-tag
14337        // consts must be ASCII-lowercase-only to match the
14338        // `rename_all = "lowercase"` attribute the derive uses; a future
14339        // rebrand to `"UPPERCASE"` / `"PascalCase"` at the attribute
14340        // would emit `"GIT"` / `"Git"` instead and trip this pin.
14341        for (label, s) in [
14342            ("DEP_SOURCE_TIPO_GIT", crate::render::DEP_SOURCE_TIPO_GIT),
14343            ("DEP_SOURCE_TIPO_PATH", crate::render::DEP_SOURCE_TIPO_PATH),
14344        ] {
14345            assert!(!s.is_empty(), "{label} must not be empty");
14346            assert!(
14347                s.bytes().all(|b| b.is_ascii_lowercase()),
14348                "{label} must be ASCII-lowercase-only (matching \
14349                 rename_all = \"lowercase\"), got {s:?}",
14350            );
14351        }
14352    }
14353
14354    // ── per-entry :caracteristicas set-not-multiset gate ────────────
14355    //
14356    // Every Vec-keyed-by-name authoring surface on the typed Caixa
14357    // surface that identifies its entries by a name field now uniformly
14358    // closes the set-not-multiset discipline at build time (cite
14359    // `validate_caracteristicas`'s peer-axis enumeration). The
14360    // `:caracteristicas` axis is per-`Dep`: the feature-toggle slot is
14361    // set-shaped (a feature is either enabled or not — there is no
14362    // `feature × 2` semantic), so two entries naming the same feature
14363    // are a redundant declaration the caixa-resolver's lacre pipeline
14364    // would silently dedup at resolve time. The empty-feature arm
14365    // closes the parallel "operationally-meaningless value" axis on
14366    // the same slot. Same linear-walk + `HashSet` + first-collision
14367    // shape every peer set gate uses; same empty-first cascade every
14368    // peer per-entry shape + duplicate gate uses (the empty-feature
14369    // axis is the more-actionable defect since two `""` entries would
14370    // both report `caracteristica: ""` under a duplicate-first
14371    // ordering, with no way to distinguish the offending site).
14372
14373    fn dep_with_features(features: &[&str]) -> Dep {
14374        Dep {
14375            nome: "caixa-teia".into(),
14376            versao: "^0.1".into(),
14377            fonte: None,
14378            opcional: false,
14379            caracteristicas: features.iter().map(|s| (*s).into()).collect(),
14380        }
14381    }
14382
14383    #[test]
14384    fn validate_rejects_empty_caracteristica() {
14385        // Fail-before-pass-after pin: every pre-gate codebase accepted
14386        // `(:caracteristicas (""))` cleanly (the `Vec<String>` field
14387        // imposed no per-entry shape contract), the dep validated, and
14388        // the empty feature would have reached the future caixa-resolver
14389        // lacre pipeline as a no-op feature enable — silently dropping
14390        // the author's intent far from the source `caixa.lisp`. The new
14391        // gate surfaces the structural defect at the typed-validate
14392        // surface with a self-locating diagnostic naming the offending
14393        // dep's `:nome`.
14394        let d = dep_with_features(&[""]);
14395        assert!(
14396            matches!(d.validate().unwrap_err(), DepError::CaracteristicaEmpty { ref nome } if nome == "caixa-teia"),
14397            "expected CaracteristicaEmpty, got {:?}",
14398            d.validate(),
14399        );
14400    }
14401
14402    #[test]
14403    fn validate_rejects_duplicate_caracteristica() {
14404        // Fail-before-pass-after pin on the set-not-multiset arm: the
14405        // feature-toggle slot is set-shaped, so `(:caracteristicas
14406        // ("http" "http"))` is a redundant declaration the lacre
14407        // pipeline dedupes silently at resolve time. The diagnostic
14408        // names the offending dep + the colliding feature verbatim so
14409        // the author can grep their caixa.lisp for `:caracteristicas`
14410        // and fix it in one edit. First-collision determinism is
14411        // pinned separately below.
14412        let d = dep_with_features(&["http", "http"]);
14413        assert!(
14414            matches!(
14415                d.validate().unwrap_err(),
14416                DepError::CaracteristicaDuplicate { ref nome, ref caracteristica }
14417                    if nome == "caixa-teia" && caracteristica == "http"
14418            ),
14419            "expected CaracteristicaDuplicate, got {:?}",
14420            d.validate(),
14421        );
14422    }
14423
14424    #[test]
14425    fn validate_accepts_distinct_caracteristicas() {
14426        // The canonical authoring shape — every feature distinct — must
14427        // remain a clean pass (positive control sweep). Covers the
14428        // canonical kebab-case feature names a target caixa typically
14429        // declares.
14430        dep_with_features(&["http", "json", "tls"])
14431            .validate()
14432            .unwrap();
14433    }
14434
14435    #[test]
14436    fn validate_accepts_single_caracteristica() {
14437        // Single-element list is the minimum non-empty shape; passes
14438        // the gate as the identity of the duplicate check (no second
14439        // entry to collide with).
14440        dep_with_features(&["http"]).validate().unwrap();
14441    }
14442
14443    #[test]
14444    fn validate_accepts_empty_caracteristicas_list() {
14445        // The bare-dep authoring shape (`Dep::simple` / `Dep::git`)
14446        // produces `caracteristicas: Vec::new()`; the empty list is
14447        // the gate's empty-set identity and passes vacuously. Pin
14448        // this so a future tightening that requires ≥1 feature
14449        // surfaces here as a test failure rather than a silent
14450        // contract narrowing.
14451        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14452        assert!(dep_with_features(&[]).validate().is_ok());
14453    }
14454
14455    #[test]
14456    fn validate_caracteristica_empty_fires_before_duplicate() {
14457        // Empty-first cascade: an entry with an empty feature *and*
14458        // duplicate entries surfaces the empty diagnostic first. The
14459        // empty-feature axis is the more-actionable defect since
14460        // `caracteristica: ""` is unambiguous; under duplicate-first
14461        // ordering the diagnostic could report the empty string from
14462        // either of two empty entries with no way to distinguish.
14463        // Mirrors the peer empty-before-duplicate ordering
14464        // discipline every per-entry shape + duplicate gate establishes
14465        // (`SupervisorSpec::validate`'s `EmptyChildName` arm before
14466        // `DuplicateChildCaixa`, `validate_membros`'s
14467        // `MembroCaixaEmpty` arm before `MembroDuplicate`).
14468        let d = dep_with_features(&["", "http", "http"]);
14469        assert!(matches!(
14470            d.validate().unwrap_err(),
14471            DepError::CaracteristicaEmpty { .. }
14472        ));
14473    }
14474
14475    #[test]
14476    fn validate_caracteristica_duplicate_first_collision_determinism() {
14477        // Three matching entries: the second occurrence surfaces the
14478        // diagnostic (the second is the first *collision* — the first
14479        // entry is the establishing one, not a duplicate). Mirrors
14480        // every peer first-collision posture
14481        // (`SupervisorError::DuplicateChildCaixa` reports the second
14482        // collision, `AplicacaoError::MembroDuplicate` reports the
14483        // second, `DepError::DuplicateNome` reports the second).
14484        // Pinning this so a future shortcut that flips to last-
14485        // collision (or non-deterministic) surfaces here.
14486        let d = dep_with_features(&["http", "http", "http"]);
14487        assert!(matches!(
14488            d.validate().unwrap_err(),
14489            DepError::CaracteristicaDuplicate { ref caracteristica, .. } if caracteristica == "http"
14490        ));
14491    }
14492
14493    #[test]
14494    fn validate_per_entry_shape_fires_before_caracteristicas() {
14495        // Per-entry shape precedence: a dep with a malformed `:nome`
14496        // (uppercase) AND duplicate `:caracteristicas` surfaces the
14497        // narrower `NomeInvalid` diagnostic first, not the set-gate
14498        // diagnostic. The `:nome` is the self-locating axis (every
14499        // diagnostic from the caracteristicas gate quotes the
14500        // offending dep's `:nome` to anchor the grep target —
14501        // surfacing the malformed name first keeps that anchor
14502        // valid). Same precedence shape every peer per-entry-shape
14503        // arm establishes against its peer set-gate
14504        // (`validate_deps_per_entry_validate_fires_before_duplicate_in_deps`
14505        // on the cross-entry `:nome` axis).
14506        let d = Dep {
14507            nome: "Caixa-Teia".into(), // uppercase — DNS-1123 violation
14508            versao: "^0.1".into(),
14509            fonte: None,
14510            opcional: false,
14511            caracteristicas: vec!["http".into(), "http".into()],
14512        };
14513        assert!(matches!(
14514            d.validate().unwrap_err(),
14515            DepError::NomeInvalid { .. }
14516        ));
14517    }
14518
14519    // ── per-entry :caracteristicas value-shape gate ──────────────────
14520    //
14521    // Until this gate landed `:caracteristicas` only refused the empty
14522    // string and cross-entry duplicates: a non-empty distinct but
14523    // structurally invalid feature name silently passed validate and the
14524    // failure surfaced at `cargo metadata` time as Cargo's
14525    // `restricted_names::validate_feature_name` parser rejection, far from
14526    // the source `caixa.lisp` with no field naming which `:deps` entry's
14527    // `:caracteristicas` carried the typo. The lifted predicate makes the
14528    // Cargo-feature-name-grammar intersection-floor a substrate-level
14529    // invariant at validate time. Same trajectory as the eight peer
14530    // value-shape predicates each typed surface downstream of a structured
14531    // grammar already follows.
14532
14533    #[test]
14534    fn validate_rejects_caracteristica_with_leading_plus() {
14535        // Fail-before-pass-after pin on the canonical Cargo
14536        // `+<feature>` activation-form-in-feature-name-slot footgun.
14537        // Cargo's `[dependencies.<dep>.features]` list grammar accepts
14538        // `+optional-feature` as an enablement of a previously-disabled
14539        // feature; pasting that activation form into `:caracteristicas`
14540        // (which names the feature itself) silently passed pre-gate and
14541        // failed at `cargo metadata` parse time.
14542        let d = dep_with_features(&["+http"]);
14543        let err = d.validate().unwrap_err();
14544        assert!(
14545            matches!(
14546                err,
14547                DepError::CaracteristicaInvalid { ref nome, ref caracteristica, .. }
14548                    if nome == "caixa-teia" && caracteristica == "+http"
14549            ),
14550            "expected CaracteristicaInvalid, got {err:?}"
14551        );
14552    }
14553
14554    #[test]
14555    fn validate_rejects_caracteristica_with_leading_hyphen() {
14556        // Fail-before-pass-after pin on the leading-hyphen footgun. `-`
14557        // is a legitimate continuation character (kebab-case feature
14558        // names like `runtime-tokio` pass) but Cargo rejects it at the
14559        // start; the structural defect — and its CLI-argument-injection
14560        // adjacency at any downstream Cargo subprocess invocation — is
14561        // closed at validate time, not at `cargo metadata` time.
14562        let d = dep_with_features(&["-json"]);
14563        let err = d.validate().unwrap_err();
14564        assert!(
14565            matches!(
14566                err,
14567                DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "-json"
14568            ),
14569            "expected CaracteristicaInvalid, got {err:?}"
14570        );
14571    }
14572
14573    #[test]
14574    fn validate_rejects_caracteristica_with_leading_dot() {
14575        // Fail-before-pass-after pin on the leading-dot footgun. `.` is
14576        // a legitimate continuation character (version-suffix shapes
14577        // like `feat.v2` pass) but the leading-dot form is the
14578        // canonical dotted-version-suffix-as-feature-name confusion.
14579        let d = dep_with_features(&[".feat"]);
14580        let err = d.validate().unwrap_err();
14581        assert!(matches!(
14582            err,
14583            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == ".feat"
14584        ));
14585    }
14586
14587    #[test]
14588    fn validate_rejects_caracteristica_with_whitespace() {
14589        // Fail-before-pass-after pin on the embedded-whitespace footgun:
14590        // a feature name with a space inside is structurally a multi-
14591        // token blob (the canonical paste-from-doc footgun, or an
14592        // accidental `"http server"` where the author meant
14593        // `"http-server"`).
14594        let d = dep_with_features(&["http feature"]);
14595        let err = d.validate().unwrap_err();
14596        assert!(matches!(
14597            err,
14598            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http feature"
14599        ));
14600    }
14601
14602    #[test]
14603    fn validate_rejects_caracteristica_with_comma() {
14604        // Fail-before-pass-after pin on the embedded-comma footgun:
14605        // the list-separator-belongs-to-the-list-grammar
14606        // miscomprehension where the author writes
14607        // `:caracteristicas ("http,json")` intending two features but
14608        // the `Vec<String>` field consumes the bare token as one entry.
14609        let d = dep_with_features(&["http,json"]);
14610        let err = d.validate().unwrap_err();
14611        assert!(matches!(
14612            err,
14613            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http,json"
14614        ));
14615    }
14616
14617    #[test]
14618    fn validate_rejects_caracteristica_with_slash() {
14619        // Fail-before-pass-after pin on the embedded-slash footgun:
14620        // Cargo's `dep/feat` namespaced-dep syntax applies inside
14621        // `[dependencies.<dep>.features]` list entries that already
14622        // name the parent dep (so the syntax says "enable feature
14623        // `feat` on a transitive dep `dep`"); `:caracteristicas` is
14624        // per-dep already (a sibling slot on the `Dep` itself), so the
14625        // segment separator within an entry must be `-`, `_`, `+`,
14626        // or `.`. The diagnostic remediation points at the canonical
14627        // Cargo namespaced-dep discipline.
14628        let d = dep_with_features(&["http/json"]);
14629        let err = d.validate().unwrap_err();
14630        assert!(matches!(
14631            err,
14632            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http/json"
14633        ));
14634    }
14635
14636    #[test]
14637    fn validate_rejects_caracteristica_with_non_ascii() {
14638        // Fail-before-pass-after pin on the un-percent-encoded non-ASCII
14639        // byte footgun: NFC-vs-NFD normalization across filesystems
14640        // silently rewrites the feature-key, breaking the lacre's
14641        // content-addressing invariant. Pinned at a canonical
14642        // smart-quote-paste shape (`café`) where the raw `é` byte is the
14643        // documented APFS round-trip break.
14644        let d = dep_with_features(&["caf\u{e9}"]);
14645        let err = d.validate().unwrap_err();
14646        assert!(matches!(
14647            err,
14648            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "caf\u{e9}"
14649        ));
14650    }
14651
14652    #[test]
14653    fn validate_rejects_caracteristica_with_control_character() {
14654        // Fail-before-pass-after pin on the embedded-control-character
14655        // footgun: a CR/LF or any 0x00..0x1F / 0x7F byte landing in a
14656        // feature name is the canonical paste-from-multiline-doc
14657        // footgun the predicate's reason wording specifically calls out.
14658        let d = dep_with_features(&["http\njson"]);
14659        let err = d.validate().unwrap_err();
14660        assert!(matches!(err, DepError::CaracteristicaInvalid { .. }));
14661    }
14662
14663    #[test]
14664    fn validate_accepts_canonical_caracteristicas_shapes() {
14665        // Positive control sweep: every canonical Cargo feature name
14666        // shape the pleme-io ecosystem uses must still pass. Mirrors
14667        // the substrate-side `cargo_feature_name_accepts_canonical_forms`
14668        // sweep — drift between either landing site and the predicate's
14669        // accepted set is a build error visible at this pair of tests,
14670        // not a per-renderer "this passed validate but failed at
14671        // cargo metadata time" surprise on the next acceptance.
14672        for s in [
14673            "http",
14674            "json",
14675            "derive",
14676            "serde_json",
14677            "runtime-tokio",
14678            "tokio.full",
14679            "v0.1",
14680            "http+json",
14681            "_internal",
14682            "__private",
14683            "default",
14684            "rt-multi-thread",
14685            "feat.v2",
14686        ] {
14687            let d = dep_with_features(&[s]);
14688            d.validate().unwrap_or_else(|e| {
14689                panic!("canonical Cargo feature name {s:?} must pass validate: {e:?}")
14690            });
14691        }
14692    }
14693
14694    #[test]
14695    fn validate_caracteristica_empty_fires_before_invalid() {
14696        // Cascade precedence pin: an entry list with both an empty
14697        // feature AND an invalid-shape feature surfaces the
14698        // `CaracteristicaEmpty` arm first (the empty value carries no
14699        // self-locating data — `caracteristica: ""` is the diagnostic
14700        // with no way to anchor a grep target — so closing the empty
14701        // axis first preserves the per-entry-shape diagnostic's
14702        // self-locating discipline). Same empty-first cascade every
14703        // peer per-entry shape gate establishes
14704        // (`SupervisorSpec::validate`'s `EmptyChildName` before
14705        // `ChildCaixaInvalid`, `validate_membros`'s `MembroCaixaEmpty`
14706        // before `MembroCaixaInvalid`).
14707        let d = dep_with_features(&["", "+http"]);
14708        assert!(matches!(
14709            d.validate().unwrap_err(),
14710            DepError::CaracteristicaEmpty { .. }
14711        ));
14712    }
14713
14714    #[test]
14715    fn validate_caracteristica_invalid_fires_before_duplicate() {
14716        // Per-entry-shape precedence pin: an entry list with the same
14717        // invalid feature shape declared twice surfaces the
14718        // `CaracteristicaInvalid` diagnostic on the first entry, not
14719        // the `CaracteristicaDuplicate` on the second collision. The
14720        // per-entry shape gate fires before the cross-entry set gate
14721        // — same precedence shape every peer two-arm-plus-set gate
14722        // establishes (`SupervisorSpec::validate`'s
14723        // `ChildCaixaInvalid` before `DuplicateChildCaixa`,
14724        // `validate_membros`'s `MembroCaixaInvalid` before
14725        // `MembroDuplicate`, `Dep::validate`'s `NomeInvalid` before
14726        // cross-list `DuplicateNome`).
14727        let d = dep_with_features(&["+http", "+http"]);
14728        assert!(matches!(
14729            d.validate().unwrap_err(),
14730            DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "+http"
14731        ));
14732    }
14733
14734    #[test]
14735    fn validate_rejects_caracteristica_at_65_byte_boundary() {
14736        // Boundary pin on the 64-byte cap — both the boundary-accepting
14737        // case and the boundary-exceeding case in one place, so a
14738        // future cap shift surfaces both arms simultaneously, mirroring
14739        // the peer `cargo_feature_name_rejects_at_65_byte_boundary`
14740        // predicate-level pin at the dep-axis landing site.
14741        let max_ok = "a".repeat(64);
14742        dep_with_features(&[&max_ok])
14743            .validate()
14744            .unwrap_or_else(|e| panic!("64-byte feature name must pass: {e:?}"));
14745        let too_long = "a".repeat(65);
14746        let d = dep_with_features(&[&too_long]);
14747        assert!(matches!(
14748            d.validate().unwrap_err(),
14749            DepError::CaracteristicaInvalid { .. }
14750        ));
14751    }
14752
14753    // ── self-dep cross-slot gate ─────────────────────────────────────
14754
14755    #[test]
14756    fn validate_no_self_dep_rejects_self_in_deps() {
14757        // A caixa whose `:deps` lists its own `:nome` is a one-node
14758        // cycle in the lacre closure's dep-graph traversal — rejected,
14759        // naming the parent and the offending list tag.
14760        let deps = vec![
14761            Dep::simple("caixa-teia", "^0.1"),
14762            Dep::simple("orquestra", "^0.1"),
14763        ];
14764        let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
14765        assert!(
14766            matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14767            "got {err:?}"
14768        );
14769    }
14770
14771    #[test]
14772    fn validate_no_self_dep_rejects_self_in_deps_dev() {
14773        // Same gate on the `:deps-dev` axis — neither dep list is a
14774        // second-class citizen on the self-edge invariant.
14775        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14776        let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
14777        assert!(
14778            matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14779            "got {err:?}"
14780        );
14781    }
14782
14783    #[test]
14784    fn validate_no_self_dep_deps_fires_before_deps_dev() {
14785        // Walk order pin: a caixa that self-references on both lists
14786        // surfaces the `:deps` arm first — the load-bearing axis the
14787        // lacre closure resolves at every build. Mirrors the canonical
14788        // [`Caixa::validate_deps`] cascade (`:deps` → `:deps-dev`).
14789        let deps = vec![Dep::simple("orquestra", "^0.1")];
14790        let deps_dev = vec![Dep::simple("orquestra", "^0.2")];
14791        let err = validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap_err();
14792        assert!(
14793            matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14794            "got {err:?}"
14795        );
14796    }
14797
14798    #[test]
14799    fn validate_no_self_dep_accepts_distinct_names() {
14800        // Positive control: every dep names a distinct caixa. The
14801        // canonical author surface — peer of
14802        // [`validate_no_self_supervision_accepts_distinct_children`].
14803        let deps = vec![
14804            Dep::simple("caixa-teia", "^0.1"),
14805            Dep::simple("caixa-arch", "^0.1"),
14806        ];
14807        let deps_dev = vec![Dep::simple("caixa-test", "^0.1")];
14808        validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap();
14809    }
14810
14811    #[test]
14812    fn validate_no_self_dep_empty_lists_pass() {
14813        // A caixa with no declared deps has nothing to self-reference —
14814        // the gate is vacuously satisfied. Peer of
14815        // [`validate_no_self_supervision_empty_children_is_ok`].
14816        validate_no_self_dep(&[], &[], "orquestra").unwrap();
14817    }
14818
14819    #[test]
14820    fn validate_no_self_dep_diagnostic_carries_offending_list_and_nome() {
14821        // Diagnostic-shape pin (peer with
14822        // [`validate_no_self_supervision`]'s diagnostic): the error's
14823        // Display surfaces both the offending list tag and the
14824        // parent's `:nome` verbatim, so the author can grep their
14825        // caixa.lisp for the offending block in one edit. Names
14826        // `:bibliotecas` / `:exe` / `:servicos` as the corrective
14827        // surface — every legitimate "I want to use code from this
14828        // caixa" intent routes through one of those three slots.
14829        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14830        let rendered = validate_no_self_dep(&[], &deps_dev, "orquestra")
14831            .unwrap_err()
14832            .to_string();
14833        assert!(
14834            rendered.contains(crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14835            "diagnostic must name the offending list tag: {rendered}",
14836        );
14837        assert!(
14838            rendered.contains("orquestra"),
14839            "diagnostic must quote the parent caixa name: {rendered}",
14840        );
14841        assert!(
14842            rendered.contains(":bibliotecas"),
14843            "diagnostic must point at the corrective code-surface slot: {rendered}",
14844        );
14845    }
14846
14847    #[test]
14848    fn validate_no_self_dep_accepts_coincidental_substring_match() {
14849        // Identity is exact-string equality, not substring — a dep
14850        // named `"orquestra-helper"` is a distinct caixa even when the
14851        // parent is `"orquestra"`. Pin the exact-match discipline so a
14852        // future relaxation that uses `contains` surfaces here, peer
14853        // with the supervision-tree and Aplicacao-membership gates
14854        // which all use exact-string equality on the typed identity.
14855        let deps = vec![Dep::simple("orquestra-helper", "^0.1")];
14856        validate_no_self_dep(&deps, &[], "orquestra").unwrap();
14857    }
14858
14859    // ── drift-detection: DEP_AUTHOR_KEY_{DEPS,DEPS_DEV} pin ─────────────
14860
14861    #[test]
14862    fn dep_author_key_consts_pin_canonical_kebab_case_labels() {
14863        // Scalar-value pin: the two author-facing kebab-case labels the
14864        // `(defcaixa … :deps ((…)) :deps-dev ((…)))` surface admits on
14865        // the two-list dep-graph slot axis, one arm per typed slot.
14866        // Mirrors the peer scalar-value pin the sibling
14867        // [`crate::M2_AUTHOR_KEY_LIMITS`] /
14868        // [`crate::M2_AUTHOR_KEY_BEHAVIOR`] /
14869        // [`crate::M2_AUTHOR_KEY_UPGRADE_FROM`] (f49c8b0) M2 top-level
14870        // author-labels, [`crate::M3_AUTHOR_KEY_MEMBROS`] etc.
14871        // (882f498) M3 top-level author-labels, and
14872        // [`crate::SUPERVISOR_AUTHOR_KEY_ESTRATEGIA`] etc. (be40492)
14873        // Supervisor top-level author-labels carry, so every kind-scoped
14874        // typed-slot-family axis routes through one canonical per-arm
14875        // declaration.
14876        //
14877        // A future rebrand (`:deps` → `:dependencies` matching Cargo's
14878        // verbatim key, `:deps-dev` → `:dev-dependencies` matching the
14879        // same, `:deps` / `:deps-dev` → `:runtime-deps` / `:dev-deps`
14880        // for symmetry) lands as an edit to exactly one const, and
14881        // every consumer that reaches for the label picks it up at
14882        // build time rather than at runtime as a downstream mismatch on
14883        // a `DepError::DuplicateNome { list: … }` diagnostic far from
14884        // the rename's commit.
14885        assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS, ":deps");
14886        assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS_DEV, ":deps-dev");
14887    }
14888
14889    #[test]
14890    fn dep_author_key_consts_are_pairwise_distinct() {
14891        // Distinct-labels pin: the two `:deps` / `:deps-dev` labels
14892        // must not collapse onto one byte-string. A future copy-paste
14893        // slip that renamed both consts to the same value (or a rebrand
14894        // that dropped the `-dev` suffix from one but not the other)
14895        // would leave every `DepError::DuplicateNome { list: … }`
14896        // diagnostic naming an unattributable list — the linter would
14897        // route the author to the wrong caixa.lisp block, or the
14898        // cross-list precedence gate
14899        // (`validate_deps_duplicate_in_deps_fires_before_duplicate_in_deps_dev`)
14900        // would surface a `:deps`-tagged diagnostic on a `:deps-dev`
14901        // duplicate. Peer of the sibling
14902        // `m2_author_key_consts_are_pairwise_distinct`-shape gates the
14903        // other top-level kind-scoped slot-family axes carry
14904        // (implicitly held by their different byte-values today).
14905        assert_ne!(
14906            crate::render::DEP_AUTHOR_KEY_DEPS,
14907            crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
14908            "DEP_AUTHOR_KEY_{{DEPS,DEPS_DEV}} consts must be pairwise-distinct \
14909             so a `DepError::DuplicateNome {{ list: … }}` diagnostic \
14910             self-locates the offending block in the author's caixa.lisp",
14911        );
14912    }
14913
14914    #[test]
14915    fn validate_no_self_dep_routes_through_lifted_dep_author_key_consts() {
14916        // Production-through-const pin: the two per-arm list tags
14917        // [`validate_no_self_dep`] threads onto the `list:` field of a
14918        // returned [`DepError::DepIsSelf`] route through the lifted
14919        // [`crate::DEP_AUTHOR_KEY_DEPS`] /
14920        // [`crate::DEP_AUTHOR_KEY_DEPS_DEV`] consts. A future drift at
14921        // the walker (a rename that reaches one arm but not the const,
14922        // or vice versa) surfaces here at build time rather than at
14923        // runtime as a `feira lint` diagnostic naming the wrong list
14924        // tag. Mirror of the peer
14925        // [`crate::Caixa::declared_servico_slots`] production tagger
14926        // pin (f49c8b0) on the sibling M2 top-level slot axis, extended
14927        // onto the two-list dep-graph gate.
14928        let deps = vec![Dep::simple("orquestra", "^0.1")];
14929        let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
14930        let DepError::DepIsSelf { list, .. } = err else {
14931            panic!("expected DepIsSelf from :deps walk");
14932        };
14933        assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS);
14934
14935        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14936        let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
14937        let DepError::DepIsSelf { list, .. } = err else {
14938            panic!("expected DepIsSelf from :deps-dev walk");
14939        };
14940        assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS_DEV);
14941    }
14942
14943    // ── Dep::nome accessor pins ───────────────────────────────────────
14944    //
14945    // Three coherence pins on the lifted `Dep::nome` accessor: byte-equal
14946    // projection over the plain-shorthand / explicit-git / explicit-path
14947    // fixture triad the [`Dep`] docstring lists (so the accessor's
14948    // accept-set is exercised across every author-surface `:fonte`
14949    // shape); by-borrow pointer identity so the projection stays
14950    // zero-copy at every consumer site; and validate-composition through
14951    // the [`validate_no_self_dep`] cross-slot gate reading its
14952    // parent-name equality check through the lifted accessor rather than
14953    // the raw field.
14954
14955    #[test]
14956    fn dep_nome_returns_declared_nome_across_fonte_shapes() {
14957        // Plain-shorthand form (`:fonte None`).
14958        assert_eq!(Dep::simple("caixa-teia", "^0.1").nome(), "caixa-teia");
14959        // Explicit git-source form with a tag pin — same accessor path.
14960        assert_eq!(
14961            Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").nome(),
14962            "caixa-teia",
14963        );
14964        // Explicit path-source form.
14965        assert_eq!(
14966            Dep {
14967                nome: "caixa-teia".to_string(),
14968                versao: "0.1.0".to_string(),
14969                fonte: Some(DepSource::Path {
14970                    caminho: "../caixa-teia".to_string(),
14971                }),
14972                opcional: false,
14973                caracteristicas: Vec::new(),
14974            }
14975            .nome(),
14976            "caixa-teia",
14977        );
14978        // The empty-string `:nome` sentinel (which [`Dep::validate`]
14979        // refuses through the [`DepError::NomeEmpty`] arm) still round-
14980        // trips as an empty `&str` through the accessor — the accessor is
14981        // a projection, not a gate; the gate is [`Dep::validate`].
14982        assert_eq!(Dep::simple("", "^0.1").nome(), "");
14983    }
14984
14985    #[test]
14986    fn dep_nome_is_by_borrow_pointer_identity() {
14987        // Zero-copy pin: the accessor must borrow into the field's own
14988        // storage, not clone. If a future rewrite regresses to
14989        // `self.nome.clone().leak()` or an owned-buffer shape, the two
14990        // pointers diverge and this pin fails at build time.
14991        let d = Dep::simple("caixa-teia", "^0.1");
14992        assert!(std::ptr::eq(d.nome().as_ptr(), d.nome.as_ptr()));
14993    }
14994
14995    // ── Dep::versao_requirement accessor pins ─────────────────────────
14996    //
14997    // Three coherence pins on the lifted `Dep::versao_requirement`
14998    // accessor: byte-equal projection over the plain-shorthand /
14999    // explicit-git / explicit-path fixture triad the [`Dep`] docstring
15000    // lists plus the empty-sentinel that round-trips as `""` (the accessor
15001    // is a projection, not a gate; the gate is [`Dep::validate`]); by-
15002    // borrow pointer identity so the projection stays zero-copy at every
15003    // consumer site; and validate-composition through the
15004    // [`crate::render::require_valid_versao_requirement`] cascade reading
15005    // its requirement-shape check through the lifted accessor rather than
15006    // the raw field.
15007    #[test]
15008    fn dep_versao_requirement_returns_declared_versao_across_fonte_shapes() {
15009        // Plain-shorthand form (`:fonte None`).
15010        assert_eq!(
15011            Dep::simple("caixa-teia", "^0.1").versao_requirement(),
15012            "^0.1",
15013        );
15014        // Explicit git-source form with a tag pin — same accessor path.
15015        assert_eq!(
15016            Dep::git(
15017                "caixa-teia",
15018                "~0.1.2",
15019                "github:pleme-io/caixa-teia",
15020                "v0.1.0"
15021            )
15022            .versao_requirement(),
15023            "~0.1.2",
15024        );
15025        // Explicit path-source form.
15026        assert_eq!(
15027            Dep {
15028                nome: "caixa-teia".to_string(),
15029                versao: "0.1.0".to_string(),
15030                fonte: Some(DepSource::Path {
15031                    caminho: "../caixa-teia".to_string(),
15032                }),
15033                opcional: false,
15034                caracteristicas: Vec::new(),
15035            }
15036            .versao_requirement(),
15037            "0.1.0",
15038        );
15039        // The wildcard requirement (`"*"`) — the shorthand
15040        // `parse_requirement` accepts as `VersionReq::STAR` — round-trips
15041        // verbatim through the accessor as `"*"`, same byte-shape the
15042        // author wrote.
15043        assert_eq!(Dep::simple("caixa-teia", "*").versao_requirement(), "*");
15044        // The empty-string `:versao` sentinel (which [`Dep::validate`]
15045        // refuses through the [`DepError::VersaoEmpty`] arm) still round-
15046        // trips as an empty `&str` through the accessor — the accessor is
15047        // a projection, not a gate; the gate is [`Dep::validate`]. Peer
15048        // of the sibling [`Dep::nome`] empty-sentinel round-trip pin.
15049        assert_eq!(Dep::simple("caixa-teia", "").versao_requirement(), "");
15050    }
15051
15052    #[test]
15053    fn dep_versao_requirement_is_by_borrow_pointer_identity() {
15054        // Zero-copy pin: the accessor must borrow into the field's own
15055        // storage, not clone. If a future rewrite regresses to
15056        // `self.versao.clone().leak()` or an owned-buffer shape, the two
15057        // pointers diverge and this pin fails at build time. Peer of the
15058        // sibling [`Dep::nome`] pointer-identity pin — same by-borrow
15059        // discipline extended onto the requirement-carrying axis.
15060        let d = Dep::simple("caixa-teia", "^0.1");
15061        assert!(std::ptr::eq(
15062            d.versao_requirement().as_ptr(),
15063            d.versao.as_ptr(),
15064        ));
15065    }
15066
15067    #[test]
15068    fn dep_validate_reads_requirement_through_accessor() {
15069        // Composition pin: the [`Dep::validate`]
15070        // [`crate::render::require_valid_versao_requirement`] cascade
15071        // consumes the requirement string through the lifted accessor —
15072        // both the requirement-gate input and the
15073        // [`DepError::VersaoInvalid`] error-body carrier route through
15074        // `self.versao_requirement()`. A valid requirement passes
15075        // (positive control); a malformed-but-non-empty requirement fails
15076        // and the diagnostic quotes the offending byte-string verbatim
15077        // (same shape the accessor projects), so a future regression that
15078        // detoured the requirement carrier through a different byte-
15079        // string (say the parsed `VersionReq`'s `Display`, or a
15080        // normalized rewrite) would surface here at build time. The
15081        // empty-`:versao` arm fires the [`DepError::VersaoEmpty`] variant
15082        // ahead of the parse arm, pinning the empty-first cascade the
15083        // accessor's `""` sentinel round-trip acknowledges.
15084        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15085        let err = Dep::simple("caixa-teia", "v0.1").validate().unwrap_err();
15086        assert!(
15087            matches!(
15088                &err,
15089                DepError::VersaoInvalid {
15090                    nome,
15091                    versao,
15092                    ..
15093                } if nome == "caixa-teia" && versao == "v0.1",
15094            ),
15095            "expected VersaoInvalid quoting the accessor-projected requirement, got {err:?}",
15096        );
15097        let err = Dep::simple("caixa-teia", "").validate().unwrap_err();
15098        assert!(
15099            matches!(
15100                &err,
15101                DepError::VersaoEmpty { nome } if nome == "caixa-teia",
15102            ),
15103            "expected VersaoEmpty from the empty-first arm, got {err:?}",
15104        );
15105    }
15106
15107    // ── Dep::fonte accessor pins ──────────────────────────────────────
15108    //
15109    // Three coherence pins on the lifted `Dep::fonte` accessor: byte-
15110    // equal projection over the plain-shorthand (`:fonte None`) /
15111    // explicit-git-tag / explicit-path fixture triad the [`Dep`]
15112    // docstring lists (so the accessor's accept-set is exercised across
15113    // every author-surface `:fonte` shape and both `DepSource` variants);
15114    // pointer identity so the borrowed reference points into the field's
15115    // own `Option<DepSource>` storage (not a cloned side-buffer); and
15116    // validate-composition through the [`Dep::validate`] gate reading
15117    // its per-`:fonte` [`DepSource::validate`] delegation through the
15118    // lifted accessor rather than the raw `if let Some(ref fonte) =
15119    // self.fonte` bracket.
15120
15121    #[test]
15122    fn dep_fonte_returns_declared_source_across_shapes() {
15123        // Plain-shorthand form — `:fonte` omitted, accessor projects
15124        // the `None` partition the resolver-side default-fill treats
15125        // as "resolve through `github:<default-org>/<nome>`".
15126        assert!(Dep::simple("caixa-teia", "^0.1").fonte().is_none());
15127        // Explicit git-source form with a tag pin — same accessor path.
15128        let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15129        match git.fonte() {
15130            Some(DepSource::Git {
15131                repo,
15132                tag,
15133                rev,
15134                branch,
15135            }) => {
15136                assert_eq!(repo, "github:pleme-io/caixa-teia");
15137                assert_eq!(tag.as_deref(), Some("v0.1.0"));
15138                assert!(rev.is_none());
15139                assert!(branch.is_none());
15140            }
15141            other => panic!("expected explicit git :fonte, got {other:?}"),
15142        }
15143        // Explicit path-source form — the dev-only local-filesystem
15144        // arm the [`Dep`] docstring's third fixture carries.
15145        let path = Dep {
15146            nome: "caixa-teia".to_string(),
15147            versao: "0.1.0".to_string(),
15148            fonte: Some(DepSource::Path {
15149                caminho: "../caixa-teia".to_string(),
15150            }),
15151            opcional: false,
15152            caracteristicas: Vec::new(),
15153        };
15154        match path.fonte() {
15155            Some(DepSource::Path { caminho }) => {
15156                assert_eq!(caminho, "../caixa-teia");
15157            }
15158            other => panic!("expected explicit path :fonte, got {other:?}"),
15159        }
15160    }
15161
15162    #[test]
15163    fn dep_fonte_is_by_borrow_pointer_identity() {
15164        // Zero-copy pin: the accessor must borrow into the field's own
15165        // `Option<DepSource>` storage, not clone into a side buffer. If
15166        // a future rewrite regresses to `self.fonte.clone()` or an
15167        // owned-buffer shape, the two pointers diverge and this pin
15168        // fails at build time. Peer of the sibling per-`Dep` [`Dep::nome`]
15169        // (eba2cde) / [`Dep::versao_requirement`] (05529b1) pointer-
15170        // identity pins — same by-borrow discipline extended onto the
15171        // outer-`Dep` `Option<&Composite>` composite-reference axis.
15172        let d = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15173        let accessed = d.fonte().expect("git :fonte present") as *const DepSource;
15174        let raw = d.fonte.as_ref().expect("git :fonte present") as *const DepSource;
15175        assert!(std::ptr::eq(accessed, raw));
15176    }
15177
15178    #[test]
15179    fn dep_validate_reads_fonte_through_accessor() {
15180        // Composition pin: [`Dep::validate`]'s per-`:fonte`
15181        // [`DepSource::validate`] delegation consumes the typed slot
15182        // through the lifted accessor — an author-omitted `:fonte`
15183        // still passes the outer gate (positive control), an explicit
15184        // well-formed git source with exactly one pin passes, and a
15185        // malformed git source (empty `:repo`) surfaces the
15186        // [`DepError::FonteRepoEmpty`] variant quoting the offending
15187        // dep's `:nome` verbatim so a future regression that detoured
15188        // the `:fonte` delegation through a different path (say a
15189        // per-scope override projector) would surface here at build
15190        // time. Peer of the sibling
15191        // `dep_validate_reads_requirement_through_accessor` composition
15192        // pin on the `:versao` axis.
15193        // Positive control 1: no `:fonte` at all.
15194        Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15195        // Positive control 2: well-formed git source.
15196        Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15197            .validate()
15198            .unwrap();
15199        // Negative control: empty `:repo` — the accessor still returns
15200        // `Some(&DepSource::Git { repo: "", … })` and the delegated
15201        // `DepSource::validate` gate raises the typed carrier.
15202        let bad = Dep {
15203            nome: "caixa-teia".to_string(),
15204            versao: "^0.1".to_string(),
15205            fonte: Some(DepSource::Git {
15206                repo: String::new(),
15207                tag: Some("v0.1.0".to_string()),
15208                rev: None,
15209                branch: None,
15210            }),
15211            opcional: false,
15212            caracteristicas: Vec::new(),
15213        };
15214        let err = bad.validate().unwrap_err();
15215        assert!(
15216            matches!(
15217                &err,
15218                DepError::FonteRepoEmpty { nome } if nome == "caixa-teia",
15219            ),
15220            "expected FonteRepoEmpty from the accessor-routed :fonte gate, got {err:?}",
15221        );
15222    }
15223
15224    #[test]
15225    fn validate_no_self_dep_reads_parent_equality_through_accessor() {
15226        // Composition pin: the cross-slot [`validate_no_self_dep`] gate
15227        // rejects a `:deps` entry whose `:nome` equals the parent caixa's
15228        // own `:nome` through the lifted accessor rather than the raw
15229        // field. Fails-before-passes-after: with the accessor lifted the
15230        // gate reads its equality check through `dep.nome() ==
15231        // parent_nome` on both the `:deps` and `:deps-dev` traversals, so
15232        // the diagnostic still names the offending list tag as expected.
15233        let deps = vec![Dep::simple("orquestra", "^0.1")];
15234        let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15235        assert!(matches!(
15236            err,
15237            DepError::DepIsSelf {
15238                ref nome,
15239                list,
15240            } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS,
15241        ));
15242        let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15243        let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15244        assert!(matches!(
15245            err,
15246            DepError::DepIsSelf {
15247                ref nome,
15248                list,
15249            } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15250        ));
15251        // A non-matching `:nome` passes through the accessor gate.
15252        let deps = vec![Dep::simple("caixa-teia", "^0.1")];
15253        validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15254    }
15255
15256    // ── Dep::caracteristicas accessor pins ────────────────────────────
15257    //
15258    // Three coherence pins on the lifted `Dep::caracteristicas` accessor:
15259    // byte-equal projection over the default-empty / single-entry /
15260    // multi-entry fixture triad (so the accessor's accept-set is
15261    // exercised across every author-surface `:caracteristicas` shape,
15262    // matching the peer sibling family's fixture-triad discipline); by-
15263    // borrow pointer identity so the projection stays zero-copy at every
15264    // consumer site; and validate-composition through the
15265    // [`Dep::validate_caracteristicas`] gate reading its per-entry
15266    // linear walk through the lifted accessor rather than the raw
15267    // `for c in &self.caracteristicas` bracket.
15268
15269    #[test]
15270    fn dep_caracteristicas_returns_declared_features_across_shapes() {
15271        // Default-empty form — the [`Dep::simple`] constructor's
15272        // `Vec::new()` fill; the accessor projects the empty slice
15273        // verbatim (no `None` collapse).
15274        assert!(
15275            Dep::simple("caixa-teia", "^0.1")
15276                .caracteristicas()
15277                .is_empty(),
15278        );
15279        // Single-entry form — the canonical Cargo-shaped one-feature
15280        // enable ([`crate::render::is_cargo_feature_name`] accepts the
15281        // `"http"` byte-string as a valid feature name).
15282        let one = Dep {
15283            nome: "caixa-teia".to_string(),
15284            versao: "^0.1".to_string(),
15285            fonte: None,
15286            opcional: false,
15287            caracteristicas: vec!["http".to_string()],
15288        };
15289        assert_eq!(one.caracteristicas(), &["http".to_string()]);
15290        // Multi-entry form — the substrate's set-shaped multi-feature
15291        // enable, exercising the accessor over a length-two slice with
15292        // no duplicate collapse.
15293        let two = Dep {
15294            nome: "caixa-teia".to_string(),
15295            versao: "^0.1".to_string(),
15296            fonte: None,
15297            opcional: false,
15298            caracteristicas: vec!["http".to_string(), "json".to_string()],
15299        };
15300        assert_eq!(
15301            two.caracteristicas(),
15302            &["http".to_string(), "json".to_string()],
15303        );
15304    }
15305
15306    #[test]
15307    fn dep_caracteristicas_is_by_borrow_pointer_identity() {
15308        // Zero-copy pin: the accessor must borrow into the field's own
15309        // `Vec<String>` storage, not clone into a side buffer. If a
15310        // future rewrite regresses to `self.caracteristicas.clone()` or
15311        // an owned-buffer shape, the two pointers diverge and this pin
15312        // fails at build time. Peer of the sibling per-`Dep`
15313        // [`Dep::nome`] (eba2cde) / [`Dep::versao_requirement`] (05529b1)
15314        // / [`Dep::fonte`] (d65d1bf) pointer-identity pins — same by-
15315        // borrow discipline extended onto the outer-`Dep` `&[String]`
15316        // slice-projection axis.
15317        let d = Dep {
15318            nome: "caixa-teia".to_string(),
15319            versao: "^0.1".to_string(),
15320            fonte: None,
15321            opcional: false,
15322            caracteristicas: vec!["http".to_string(), "json".to_string()],
15323        };
15324        assert!(std::ptr::eq(
15325            d.caracteristicas().as_ptr(),
15326            d.caracteristicas.as_ptr(),
15327        ));
15328    }
15329
15330    #[test]
15331    fn dep_validate_reads_caracteristicas_through_accessor() {
15332        // Composition pin: [`Dep::validate_caracteristicas`]'s per-entry
15333        // linear walk consumes the feature-toggle list through the
15334        // lifted accessor — a well-formed `:caracteristicas` set passes
15335        // (positive control), an empty-string entry surfaces the
15336        // [`DepError::CaracteristicaEmpty`] variant quoting the offending
15337        // `Dep::nome`, and a within-list duplicate surfaces the
15338        // [`DepError::CaracteristicaDuplicate`] variant so a future
15339        // regression that detoured the walk through a different byte-
15340        // string list (say a per-scope override projector) would surface
15341        // here at build time. Peer of the sibling
15342        // `dep_validate_reads_fonte_through_accessor` /
15343        // `dep_validate_reads_requirement_through_accessor` composition
15344        // pins on the `:fonte` / `:versao` axes.
15345        // Positive control: two distinct well-formed feature names pass.
15346        Dep {
15347            nome: "caixa-teia".to_string(),
15348            versao: "^0.1".to_string(),
15349            fonte: None,
15350            opcional: false,
15351            caracteristicas: vec!["http".to_string(), "json".to_string()],
15352        }
15353        .validate()
15354        .unwrap();
15355        // Negative control 1: empty-string feature-name entry — the
15356        // accessor still returns `&[""]` and the walk raises the typed
15357        // empty-first carrier.
15358        let err = Dep {
15359            nome: "caixa-teia".to_string(),
15360            versao: "^0.1".to_string(),
15361            fonte: None,
15362            opcional: false,
15363            caracteristicas: vec![String::new()],
15364        }
15365        .validate()
15366        .unwrap_err();
15367        assert!(
15368            matches!(
15369                &err,
15370                DepError::CaracteristicaEmpty { nome } if nome == "caixa-teia",
15371            ),
15372            "expected CaracteristicaEmpty from the accessor-routed walk, got {err:?}",
15373        );
15374        // Negative control 2: within-list duplicate — the accessor's
15375        // slice view carries both entries, and the walk's dedup arm
15376        // raises the typed duplicate carrier quoting the offending
15377        // feature name verbatim.
15378        let err = Dep {
15379            nome: "caixa-teia".to_string(),
15380            versao: "^0.1".to_string(),
15381            fonte: None,
15382            opcional: false,
15383            caracteristicas: vec!["http".to_string(), "http".to_string()],
15384        }
15385        .validate()
15386        .unwrap_err();
15387        assert!(
15388            matches!(
15389                &err,
15390                DepError::CaracteristicaDuplicate {
15391                    nome,
15392                    caracteristica,
15393                } if nome == "caixa-teia" && caracteristica == "http",
15394            ),
15395            "expected CaracteristicaDuplicate from the accessor-routed dedup, got {err:?}",
15396        );
15397    }
15398
15399    // ── Dep::opcional accessor pins ───────────────────────────────────
15400    //
15401    // Two coherence pins on the lifted `Dep::opcional` accessor: byte-
15402    // equal projection over the default-`false` / explicit-`true`
15403    // fixture pair across the plain-shorthand (`:fonte None`) / explicit-
15404    // git-tag / explicit-path fixture triad the [`Dep`] docstring lists,
15405    // exercising the accessor's accept-set over every author-surface
15406    // `:fonte` shape × every author-surface `:opcional` shape; and by-
15407    // `Copy` idempotency so the projection stays value-return (no
15408    // silent detour to a fresh `&bool` borrow that would introduce a
15409    // lifetime on the return type the plain-`Copy`-scalar axis's `bool`
15410    // shape elides). No composition pin — `:opcional` does not
15411    // participate in [`Dep::validate`] (an opcional dep with any bool
15412    // value is validate-accepted; the missing-source arm is a resolver-
15413    // side runtime dispatch, not a build-time refusal), so the axis
15414    // reduces to the value-shape + `Copy` pin pair the peer
15415    // [`crate::Caixa::max_restarts`] / [`crate::Caixa::estrategia`]
15416    // outer-`Option<Copy>` accessor pins already carry.
15417
15418    #[test]
15419    fn dep_opcional_returns_declared_opcional_across_fonte_shapes() {
15420        // Default-`false` form via the [`Dep::simple`] constructor —
15421        // the accessor projects the `false` bit the default-fill sets.
15422        assert!(!Dep::simple("caixa-teia", "^0.1").opcional());
15423        // Default-`false` form via the [`Dep::git`] constructor — same
15424        // default fill; the accessor projects `false` regardless of the
15425        // `:fonte` arm.
15426        assert!(!Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").opcional(),);
15427        // Explicit-`true` form × plain-shorthand `:fonte` — the
15428        // canonical author-surface "this dep may be missing" shape.
15429        let plain_true = Dep {
15430            nome: "caixa-teia".to_string(),
15431            versao: "^0.1".to_string(),
15432            fonte: None,
15433            opcional: true,
15434            caracteristicas: Vec::new(),
15435        };
15436        assert!(plain_true.opcional());
15437        // Explicit-`true` form × explicit git-source — the accessor
15438        // projects the bit verbatim regardless of the `:fonte` arm.
15439        let git_true = Dep {
15440            nome: "caixa-teia".to_string(),
15441            versao: "^0.1".to_string(),
15442            fonte: Some(DepSource::Git {
15443                repo: "github:pleme-io/caixa-teia".to_string(),
15444                tag: Some("v0.1.0".to_string()),
15445                rev: None,
15446                branch: None,
15447            }),
15448            opcional: true,
15449            caracteristicas: Vec::new(),
15450        };
15451        assert!(git_true.opcional());
15452        // Explicit-`true` form × explicit path-source — the dev-only
15453        // local-filesystem arm the [`Dep`] docstring's third fixture
15454        // carries.
15455        let path_true = Dep {
15456            nome: "caixa-teia".to_string(),
15457            versao: "0.1.0".to_string(),
15458            fonte: Some(DepSource::Path {
15459                caminho: "../caixa-teia".to_string(),
15460            }),
15461            opcional: true,
15462            caracteristicas: Vec::new(),
15463        };
15464        assert!(path_true.opcional());
15465    }
15466
15467    #[test]
15468    fn dep_opcional_projects_bool_by_copy() {
15469        // The by-`Copy` pin: [`Dep::opcional`] returns `bool` by value
15470        // (`bool: Copy`) — the accessor does not borrow `&self` past
15471        // the call (no lifetime on the return type), and calling the
15472        // accessor twice on the same [`Dep`] must yield discriminant-
15473        // equal values (idempotent, no side effects on `&self`). Peer
15474        // of the sibling outer-`Caixa` `Option<Copy>` by-`Copy`
15475        // `max_restarts_projects_option_by_copy` (eba5211) /
15476        // `estrategia_projects_option_by_copy` (ed04d3c) pins on the
15477        // outer-`Caixa` altitude — extended here to the outer-`Dep`
15478        // altitude's plain-`Copy` `bool` axis. The `Copy` discipline
15479        // replaces the pointer-equality claim the sibling per-`Dep`
15480        // by-borrow pins (`dep_nome_is_by_borrow_pointer_identity`
15481        // eba2cde, `dep_versao_requirement_is_by_borrow_pointer_identity`
15482        // 05529b1, `dep_fonte_is_by_borrow_pointer_identity` d65d1bf,
15483        // `dep_caracteristicas_is_by_borrow_pointer_identity` 9197944)
15484        // carry (a fresh `Copy` of a `Copy` discriminant is definitionally
15485        // the same discriminant, so the axis reduces to discriminant
15486        // equality).
15487        //
15488        // Pins against a future silent detour that returned a fresh
15489        // `&bool` reference (which would type-check but silently
15490        // introduce a borrow of `&self` past the call, collapsing the
15491        // load-bearing "no lifetime on the return type" `Copy`
15492        // projection the plain-`Copy`-scalar axis's `bool` shape
15493        // carries) or a stale-read side effect that flipped the outer
15494        // discriminant on successive calls.
15495        for opcional in [false, true] {
15496            let d = Dep {
15497                nome: "caixa-teia".to_string(),
15498                versao: "^0.1".to_string(),
15499                fonte: None,
15500                opcional,
15501                caracteristicas: Vec::new(),
15502            };
15503            let first = d.opcional();
15504            let second = d.opcional();
15505            assert_eq!(
15506                first, second,
15507                "Dep::opcional must be idempotent — two successive calls \
15508                 on the same &self must return the same bool",
15509            );
15510            assert_eq!(
15511                first, opcional,
15512                "Dep::opcional must return :opcional verbatim by Copy — \
15513                 got {first}, expected {opcional}",
15514            );
15515            assert_eq!(
15516                d.opcional(),
15517                d.opcional,
15518                "Dep::opcional accessor and self.opcional field access \
15519                 must byte-equal — a bit-flip drift would silently split \
15520                 the paired resolver-side drop-vs-error dispatch from \
15521                 the storage-side default-fill the [`Dep::simple`] / \
15522                 [`Dep::git`] constructor pair carries",
15523            );
15524        }
15525    }
15526
15527    // ── DepSource::sole_pin — sole-set git-pin accessor ─────────────────
15528
15529    #[test]
15530    fn sole_pin_returns_none_for_path_source() {
15531        // A path source carries no git-ref, so `sole_pin()` returns
15532        // `None` structurally — the sibling arm every git-fetching
15533        // consumer partitions off before reaching for a git-ref. Pins
15534        // the Path-arm branch of the accessor against a future silent
15535        // detour that treats a `Self::Path` as an unpinned-git source
15536        // and returns the wrong "no pin" signal (e.g. the empty string,
15537        // or a hard-coded `Some("HEAD")` matching the caixa-crd
15538        // path-arm `git_ref` fill).
15539        let s = DepSource::Path {
15540            caminho: "../local-caixa".to_string(),
15541        };
15542        assert_eq!(s.sole_pin(), None);
15543    }
15544
15545    #[test]
15546    fn sole_pin_returns_none_for_unpinned_git_source() {
15547        // The [`DepSource::default_github`] shorthand shape carries no
15548        // pin — every `tag`/`rev`/`branch` is `None`, and `sole_pin()`
15549        // returns `None`. This is the shape caixa-resolver's `fetch_dep`
15550        // materializes when the author omits `:fonte` entirely, then
15551        // hands to `fetch_git` which raises `ResolveError::MissingPin`
15552        // on the `None` arm — the accessor's return matches the arm
15553        // the resolver's diagnostic keys off.
15554        let s = DepSource::default_github("pleme-io", "caixa-teia");
15555        assert_eq!(s.sole_pin(), None);
15556    }
15557
15558    #[test]
15559    fn sole_pin_returns_rev_when_only_rev_is_set() {
15560        let s = DepSource::Git {
15561            repo: "github:o/x".into(),
15562            tag: None,
15563            rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15564            branch: None,
15565        };
15566        assert_eq!(
15567            s.sole_pin(),
15568            Some("deadbeefcafebabe1234567890abcdef12345678")
15569        );
15570    }
15571
15572    #[test]
15573    fn sole_pin_returns_tag_when_only_tag_is_set() {
15574        let s = DepSource::Git {
15575            repo: "github:o/x".into(),
15576            tag: Some("v0.1.0".into()),
15577            rev: None,
15578            branch: None,
15579        };
15580        assert_eq!(s.sole_pin(), Some("v0.1.0"));
15581    }
15582
15583    #[test]
15584    fn sole_pin_returns_branch_when_only_branch_is_set() {
15585        let s = DepSource::Git {
15586            repo: "github:o/x".into(),
15587            tag: None,
15588            rev: None,
15589            branch: Some("main".into()),
15590        };
15591        assert_eq!(s.sole_pin(), Some("main"));
15592    }
15593
15594    #[test]
15595    fn sole_pin_precedence_rev_beats_tag_and_branch() {
15596        // Precedence: rev > tag > branch. Validate() rejects
15597        // multiple-pin shapes, but the accessor's precedence is defined
15598        // for pre-validate consumers (the resolver's `MissingPin`
15599        // diagnostic path, the caixa-crd round-trip's default `"main"`
15600        // fallback) and as defense-in-depth if the gate is ever
15601        // bypassed. Pins the same precedence caixa-resolver's
15602        // `fetch_git` and caixa-crd's `dep_into_ref` already apply
15603        // inline.
15604        let s = DepSource::Git {
15605            repo: "github:o/x".into(),
15606            tag: Some("v1".into()),
15607            rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15608            branch: Some("main".into()),
15609        };
15610        assert_eq!(
15611            s.sole_pin(),
15612            Some("deadbeefcafebabe1234567890abcdef12345678")
15613        );
15614    }
15615
15616    #[test]
15617    fn sole_pin_precedence_tag_beats_branch_when_no_rev() {
15618        let s = DepSource::Git {
15619            repo: "github:o/x".into(),
15620            tag: Some("v1".into()),
15621            rev: None,
15622            branch: Some("main".into()),
15623        };
15624        assert_eq!(s.sole_pin(), Some("v1"));
15625    }
15626
15627    #[test]
15628    fn sole_pin_byte_equals_inline_rev_or_tag_or_branch_cascade() {
15629        // Fail-before-pass-after byte-parity pin: the substrate accessor
15630        // must return byte-identical to the inline
15631        // `rev.as_deref().or(tag.as_deref()).or(branch.as_deref())`
15632        // cascade both caixa-resolver's `fetch_git` and caixa-crd's
15633        // `dep_into_ref` open-coded pre-lift. Trips at caixa-core build
15634        // time if the accessor's precedence silently drifts from the
15635        // consumer-side cascade — the exact drift this lift converges
15636        // to one substrate primitive to close structurally.
15637        //
15638        // Iterates through the 2^3 = 8 combinations of (tag, rev,
15639        // branch) each-either-`None`-or-`Some`, so every arm of the
15640        // precedence cascade lands under the pin. `validate()` refuses
15641        // the 4 multi-pin combinations, but the accessor's return is
15642        // defined on all 8.
15643        let vals = [Some("R".to_string()), None];
15644        for tag in &vals {
15645            for rev in &vals {
15646                for branch in &vals {
15647                    let s = DepSource::Git {
15648                        repo: "github:o/x".into(),
15649                        tag: tag.clone(),
15650                        rev: rev.clone(),
15651                        branch: branch.clone(),
15652                    };
15653                    // The exact inline cascade the two pre-lift
15654                    // consumer sites hand-rolled, byte-for-byte.
15655                    let expected = rev.as_deref().or(tag.as_deref()).or(branch.as_deref());
15656                    assert_eq!(
15657                        s.sole_pin(),
15658                        expected,
15659                        "sole_pin() must byte-equal \
15660                         rev.or(tag).or(branch) for \
15661                         (tag={tag:?}, rev={rev:?}, branch={branch:?}) — \
15662                         a drift would silently split caixa-resolver's \
15663                         fetch_git checkout target from caixa-crd's \
15664                         dep_into_ref git_ref fill",
15665                    );
15666                }
15667            }
15668        }
15669    }
15670}