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/// Errors raised by [`Dep::validate`].
3214///
3215/// Mirrors the per-axis error families the other `:versao`-carrying
3216/// typed surfaces expose
3217/// ([`crate::AplicacaoError::MembroVersaoEmpty`] /
3218/// [`crate::AplicacaoError::MembroVersaoInvalid`],
3219/// [`crate::SupervisorError::EmptyChildVersion`] /
3220/// [`crate::SupervisorError::ChildVersaoInvalid`]) so a future top-
3221/// level `CaixaError` (M4) sums these without reshaping the diagnostic.
3222#[derive(Debug, Error, PartialEq, Eq)]
3223pub enum DepError {
3224 #[error(
3225 ":deps entry has empty :nome (every dep must name a target caixa; \
3226 omit the entry instead of carrying an empty name)"
3227 )]
3228 NomeEmpty,
3229 #[error(
3230 ":deps entry :nome {nome:?} is not a valid DNS-1123 label: {reason} \
3231 (the value flows verbatim as the target caixa's `:nome`, the rendered \
3232 `lareira-<nome>` Helm chart name segment, the `LABEL_PROGRAM` label \
3233 value, and the resolver's checkout-directory leaf — each apiserver-side \
3234 schema rejects non-DNS-1123 names at admission time; use a lowercase \
3235 RFC 1123 label like `\"caixa-teia\"` or `\"pleme-mesh\"`, 1..=63 bytes, \
3236 pattern `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)"
3237 )]
3238 NomeInvalid { nome: String, reason: String },
3239 #[error(
3240 ":deps entry {nome:?} has empty :versao (every dep must pin a semver \
3241 constraint that resolves through the lacre pipeline)"
3242 )]
3243 VersaoEmpty { nome: String },
3244 #[error(
3245 ":deps entry {nome:?} :versao {versao:?} is not a valid semver \
3246 requirement: {reason} (use Cargo-shaped forms like `\"^0.1\"`, \
3247 `\"~0.1.2\"`, `\"0.1.0\"`, or `\"*\"` — the same shape `:membros :versao` \
3248 and `:children :versao` carry; the lacre pipeline resolves all three \
3249 through the same parser)"
3250 )]
3251 VersaoInvalid {
3252 nome: String,
3253 versao: String,
3254 reason: String,
3255 },
3256 #[error(
3257 ":deps entry {nome:?} :fonte (:tipo git …) has empty :repo \
3258 (every git source must name a repo — use a `github:org/repo` \
3259 shorthand, an `https://…` URL, or an ssh-git URL; omit the \
3260 entire :fonte block to fall back to the default-host resolver \
3261 convention)"
3262 )]
3263 FonteRepoEmpty { nome: String },
3264 #[error(
3265 ":deps entry {nome:?} :fonte (:tipo git …) :repo {repo:?} has \
3266 invalid value-shape: {reason} (the value flows verbatim into the \
3267 caixa-resolver's `git clone <repo>` subprocess invocation; every \
3268 documented form carries a `:` separator and no whitespace / \
3269 control / non-ASCII bytes — use a `github:org/repo` shorthand, \
3270 an `https://host/path` / `ssh://[user@]host/path` / \
3271 `git://host/path` / `file:///path` URL, or the `git@host:path` \
3272 scp-style SSH form)"
3273 )]
3274 FonteRepoShape {
3275 nome: String,
3276 repo: String,
3277 reason: String,
3278 },
3279 #[error(
3280 ":deps entry {nome:?} :fonte (:tipo git …) has no pin set \
3281 (set exactly one of :tag, :rev, or :branch so the resolver \
3282 can pick a reproducible commit; omit the entire :fonte block \
3283 to fall back to the default-host resolver convention, which \
3284 resolves the latest tag matching :versao)"
3285 )]
3286 FontePinMissing { nome: String },
3287 #[error(
3288 ":deps entry {nome:?} :fonte (:tipo git …) has multiple pins \
3289 set ({pins}); exactly one of :tag, :rev, or :branch must be \
3290 set so the resolver's checkout target is unambiguous (the \
3291 resolver's silent precedence is :rev > :tag > :branch — if \
3292 you intended one specifically, drop the others)"
3293 )]
3294 FontePinAmbiguous { nome: String, pins: String },
3295 #[error(
3296 ":deps entry {nome:?} :fonte (:tipo git …) has empty {pin} \
3297 (a set pin must name a non-empty git ref; drop the {pin} key \
3298 entirely to fall through to another pin axis)"
3299 )]
3300 FontePinEmpty { nome: String, pin: String },
3301 #[error(
3302 ":deps entry {nome:?} :fonte (:tipo git …) {pin} {value:?} has invalid \
3303 value-shape: {reason} (the git porcelain enforces the same shape at \
3304 `git fetch` / `git checkout` time on every pin; use a leaf refname \
3305 like `\"v0.1.0\"` for `:tag` or `\"main\"` / `\"feature/foo\"` for \
3306 `:branch`, or a full 40/64 lowercase-hex commit OID for `:rev` — \
3307 drop any `refs/heads/` or `refs/tags/` prefix the caixa-resolver \
3308 prepends at clone time, and avoid abbreviated SHAs which are \
3309 ambiguous across repository history)"
3310 )]
3311 FontePinShape {
3312 nome: String,
3313 pin: String,
3314 value: String,
3315 reason: String,
3316 },
3317 #[error(
3318 ":deps entry {nome:?} :fonte (:tipo path …) has empty :caminho \
3319 (every path source must name a non-empty filesystem path; \
3320 omit the entire :fonte block to fall back to the default-host \
3321 resolver convention)"
3322 )]
3323 FonteCaminhoEmpty { nome: String },
3324 #[error(
3325 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} is \
3326 absolute (the lacre pipeline embeds the value verbatim in its \
3327 per-dep content-address `path:{caminho}` at \
3328 caixa-resolver/src/resolve.rs:189, so an absolute path makes the \
3329 BLAKE3 closure differ across machines — defeating the \
3330 reproducibility contract that's load-bearing for CSE; express \
3331 the path relative to the caixa.lisp location, e.g. \
3332 \"../caixa-teia\" for a sibling workspace dep)"
3333 )]
3334 FonteCaminhoAbsolute { nome: String, caminho: String },
3335 #[error(
3336 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3337 with `~` (the leading-tilde is a shell-expansion convention, not a \
3338 POSIX path component — `Path::is_absolute` returns false on it, so \
3339 the b94fd83 absolute-path gate doesn't catch it, but the lacre \
3340 pipeline embeds the value verbatim in its per-dep content-address \
3341 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3342 caixa-resolver folds it through `Path::join` without `~`-expansion, \
3343 so the build looks for a literal `./{caminho}` subdirectory and \
3344 fails at resolve time far from the source caixa.lisp; even worse, a \
3345 future caixa-resolver pass that *does* expand `~` would silently \
3346 re-open the host-layout-leak the b94fd83 absolute gate closes — \
3347 Alice's `~` resolves to `/home/alice`, Bob's to `/home/bob`, two CI \
3348 runners with different `$HOME` layouts resolve to two distinct paths \
3349 for the byte-identical caixa, defeating the THEORY.md §V.2 render-\
3350 determinism contract; express the path relative to the caixa.lisp \
3351 location, e.g. \"../caixa-teia\" for a sibling workspace dep, or \
3352 spell out the full relative path explicitly if a workstation-rooted \
3353 dep is genuinely intended)"
3354 )]
3355 FonteCaminhoTildeExpansion { nome: String, caminho: String },
3356 #[error(
3357 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3358 with `$` (the leading-`$` is a shell-variable-expansion convention, \
3359 not a POSIX path component — `Path::is_absolute` returns false on it \
3360 and the a5c248e tilde gate doesn't catch it, but the lacre pipeline \
3361 embeds the value verbatim in its per-dep content-address \
3362 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3363 caixa-resolver folds it through `Path::join` without `$`-expansion, \
3364 so the build looks for a literal `./{caminho}` subdirectory and \
3365 fails at resolve time far from the source caixa.lisp; even worse, a \
3366 future caixa-resolver pass that *does* expand `$VAR` (the canonical \
3367 shell-convention idiom that CI's `${{WORKSPACE}}` paste-idiom \
3368 invites) would silently re-open the host-layout-leak the b94fd83 \
3369 absolute gate closes — Alice's `$HOME` resolves to `/home/alice`, \
3370 Bob's to `/home/bob`, two CI runners with different `${{WORKSPACE}}` \
3371 layouts resolve to two distinct paths for the byte-identical caixa, \
3372 defeating the THEORY.md §V.2 render-determinism contract; express \
3373 the path relative to the caixa.lisp location, e.g. \"../caixa-teia\" \
3374 for a sibling workspace dep, or spell out the full relative path \
3375 explicitly if a workstation-rooted dep is genuinely intended)"
3376 )]
3377 FonteCaminhoVarExpansion { nome: String, caminho: String },
3378 #[error(
3379 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3380 with a space (the leading ASCII space `0x20` is the orthogonal \
3381 paste-from-aligned-doc footgun that silently passes \
3382 `Path::is_absolute` and every prior leading-byte arm — \
3383 `\" ../caixa-teia\"` resolves via `Path::join` to a literal \
3384 `./ ../caixa-teia` subdirectory the resolver fails to find at \
3385 resolve time with a non-self-locating `No such file or directory` \
3386 error far from the source caixa.lisp; the lacre pipeline embeds \
3387 the value verbatim in its per-dep content-address `path:{caminho}` \
3388 at caixa-resolver/src/resolve.rs:189, so byte-divergent / \
3389 semantic-identical caixa values (` ../caixa-teia` vs \
3390 `../caixa-teia`) yield two distinct BLAKE3 closures across two \
3391 workstations whose authors differ only in paste-from-aligned- \
3392 caixa.lisp-doc whitespace habits — the most insidious failure \
3393 mode the typed slot can carry (no error surfaces; the divergence \
3394 is invisible until two machines compare lacres), defeating the \
3395 THEORY.md §V.2 render-determinism contract. The canonical \
3396 paste-from-aligned-`:deps`-block footgun (every `:fonte` form in \
3397 a multi-entry `:deps` block sits at the same column — an author \
3398 selecting `\"<sp><sp><sp>../caixa-teia\"` and pasting it from \
3399 the rendered alignment into a fresh entry preserves the leading \
3400 whitespace verbatim); peer `:fonte :repo` axis already rejects \
3401 leading whitespace via `is_git_repo_url`, `:fonte :tag` / \
3402 `:fonte :branch` via `is_git_ref_name`, `:descricao` via \
3403 `is_chart_description_shape`, `:licenca` via \
3404 `is_spdx_expression_shape`. Drop the leading space; express the \
3405 path as a bare relative single-token like \"../caixa-teia\")"
3406 )]
3407 FonteCaminhoLeadingWhitespace { nome: String, caminho: String },
3408 #[error(
3409 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3410 with `-` (the canonical CLI-argument-injection footgun on the \
3411 `:caminho` axis — the lacre pipeline embeds the value verbatim in \
3412 its per-dep content-address `path:{caminho}` at \
3413 caixa-resolver/src/resolve.rs:189 and the caixa-resolver folds it \
3414 through `Path::join` looking for a literal `./{caminho}` \
3415 subdirectory. Every downstream subprocess that consumes the resolved \
3416 path — `git -C {caminho} <verb>`, `terraform -chdir={caminho}`, \
3417 `nix build --path {caminho}`, `find {caminho}`, `stat {caminho}`, \
3418 `cp -r {caminho} …`, `rm -rf {caminho}` — reinterprets a leading-`-` \
3419 value as a CLI flag rather than a positional path when the invocation \
3420 does not carry a `--` argument-list terminator between the flag block \
3421 and the path (the common case at every porcelain entry point). The \
3422 canonical footguns: `:caminho \"-rf\"` (bare short-flag paste), \
3423 `:caminho \"-C\"` (`git -C -C` config-injection paste), \
3424 `:caminho \"--upload-pack=cat /etc/passwd\"` (the canonical long-flag \
3425 CLI-arg-injection vector at every git porcelain entry point that \
3426 consumes a path or URL argument, peer with is_git_repo_url's \
3427 leading-`-` arm on the sibling `:fonte :repo` axis), \
3428 `:caminho \"--config=…\"` (`git -c foo=bar` config-override paste). \
3429 POSIX `std::path::Path` treats a leading `-` as a literal filename \
3430 byte so the resolver folds `\"-rf\"` through `Path::join` and looks \
3431 for a literal `./-rf` subdirectory that fails at resolve time with a \
3432 non-self-locating `No such file or directory` error far from the \
3433 source caixa.lisp — but on any downstream shell-out without `--` the \
3434 reinterpretation is silent and the failure mode is arbitrary-\
3435 argument-injection. Peer arms: `is_git_repo_url` (render.rs:2037) \
3436 rejects leading `-` on `:fonte :repo` for `git clone <repo>` CLI-\
3437 arg-injection; `is_git_ref_name` (render.rs:1381, 5a28454) rejects \
3438 leading `-` on `:fonte :tag` / `:branch` for `git checkout <ref>` \
3439 CLI-arg-injection; `is_dns_1123_label` rejects leading `-` on every \
3440 DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros :caixa`, \
3441 `:children :caixa`, `:deps :nome`, cluster names); \
3442 `is_cargo_feature_name` rejects leading `-` on `:caracteristicas`; \
3443 the feira `init` / `add <nome>` positional gate (868c191) rejects \
3444 leading `-` on the CLI positional itself. Express the path as a bare \
3445 relative single-token like \"../caixa-teia\" — the sibling-workspace \
3446 directory name carries no leading-hyphen semantic, and `./` / `../` \
3447 prefixes structurally partition the leading-byte set to safe values.)"
3448 )]
3449 FonteCaminhoLeadingHyphen { nome: String, caminho: String },
3450 #[error(
3451 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains \
3452 ASCII control byte 0x{byte:02x} (POSIX paths reject NUL `0x00` outright — \
3453 every `std::fs` syscall routes the path through `CString::new` which \
3454 fails with `NulError` at resolve time; the lacre pipeline embeds the \
3455 value verbatim in its per-dep content-address `path:{caminho}` at \
3456 caixa-resolver/src/resolve.rs:189 so a control byte anywhere in the \
3457 value lands in the BLAKE3 closure and breaks the THEORY.md §V.2 render-\
3458 determinism contract — the canonical paste-from-multiline-doc \
3459 (`\\n`/`\\r`), paste-from-aligned-table (`\\t`), or paste-from-binary-\
3460 blob (`0x00`-DEL) footgun every peer single-token-shaped axis \
3461 (`:fonte :repo`, `:fonte :tag`/`:branch`, the Helm chart-string axes) \
3462 already gates against. Express the path as a relative single-line ASCII \
3463 string, e.g. \"../caixa-teia\" for a sibling workspace dep)"
3464 )]
3465 FonteCaminhoControlChar {
3466 nome: String,
3467 caminho: String,
3468 byte: u8,
3469 },
3470 #[error(
3471 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains `\\` \
3472 (POSIX `std::path::Path` treats `\\` as a literal byte inside a single path \
3473 component, so `..\\caixa-teia` is one directory named literally `..\\caixa-teia` — \
3474 not the parent's sibling — and the caixa-resolver folds the value through \
3475 `Path::join` looking for a literal `./{caminho}` subdirectory that fails at \
3476 resolve time with a non-self-locating `No such file or directory` error far \
3477 from the source caixa.lisp; Windows `std::path::Path` treats `\\` as a \
3478 primary path separator equal to `/`, so byte-identical caixa.lisp values \
3479 resolve to two distinct directories across runner OSes — the lacre pipeline \
3480 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3481 caixa-resolver/src/resolve.rs:189, defeating the THEORY.md §V.2 render-\
3482 determinism contract via the cross-host-OS-separator divergence vector. The \
3483 canonical Windows-Explorer `Copy as path` / PowerShell `Get-Location` \
3484 paste-idiom footgun; peer `:fonte :tag` / `:fonte :branch` axis already \
3485 rejects `\\` via `is_git_ref_name` for the same Windows-path-leak reason, \
3486 and `:entrada :paths` rejects `\\` via `is_gateway_api_http_path`'s eleven-\
3487 byte RFC-3986-reserved set. Express the path with `/` as the separator, e.g. \
3488 \"../caixa-teia\" for a sibling workspace dep)"
3489 )]
3490 FonteCaminhoBackslash { nome: String, caminho: String },
3491 #[error(
3492 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3493 redirection metacharacter 0x{byte:02x} `{ch}` (every interactive shell — bash / \
3494 zsh / fish / nushell — lexes `<` and `>` as input / output redirection \
3495 operators, so `:caminho \"../caixa-teia>build.log\"` is the canonical \
3496 paste-from-shell-pipeline footgun where an author copies a `command > log` \
3497 tail without trimming the redirect; POSIX `std::path::Path` treats both bytes \
3498 as literal path-component bytes, so the resolver folds the value through \
3499 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3500 subdirectory and fails at resolve time with a non-self-locating `No such \
3501 file or directory` error far from the source caixa.lisp. The lacre pipeline \
3502 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3503 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure \
3504 and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3505 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3506 canonical CRLF-at-subprocess-argument / shell-metachar injection surface every \
3507 peer single-token-shaped typed slot already closes. The peer `:fonte :tag` / \
3508 `:fonte :branch` axis already rejects `<` / `>` via `is_git_ref_name`, and \
3509 `:entrada :paths` rejects them via `is_gateway_api_http_path`'s eleven-byte \
3510 RFC-3986-reserved set. Express the path as a bare relative single-token like \
3511 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3512 redirection semantic.",
3513 ch = *byte as char
3514 )]
3515 FonteCaminhoShellRedirection {
3516 nome: String,
3517 caminho: String,
3518 byte: u8,
3519 },
3520 #[error(
3521 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-pipe \
3522 metacharacter `|` (every interactive shell — bash / zsh / fish / nushell — lexes \
3523 `|` as the pipe operator that wires one command's stdout to the next command's \
3524 stdin, so `:caminho \"../caixa-teia | grep foo\"` is the canonical paste-from-\
3525 shell-history footgun where an author copies a `ls ../caixa-teia | grep` line \
3526 without trimming the pipeline tail, and `:caminho \"../foo||bar\"` is the \
3527 symmetric `cmd-a || cmd-b` short-circuit-OR paste shape; POSIX `std::path::Path` \
3528 treats `|` as a literal path-component byte, so the resolver folds the value \
3529 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3530 subdirectory and fails at resolve time with a non-self-locating `No such file or \
3531 directory` error far from the source caixa.lisp. The lacre pipeline embeds the \
3532 value verbatim in its per-dep content-address `path:{caminho}` at caixa-resolver/\
3533 src/resolve.rs:189, so the byte lands in the BLAKE3 closure and rides into every \
3534 shell-spawned subprocess (the resolver's `git clone`, a future `feira tofu` \
3535 shell-out, a future operator-side `nix` spawn) as the canonical CRLF-at-\
3536 subprocess-argument / shell-metachar injection surface every peer single-token-\
3537 shaped typed slot already closes. The peer `:entrada :paths` axis rejects `|` \
3538 via `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3539 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3540 workspace directory name carries no shell-pipe semantic."
3541 )]
3542 FonteCaminhoShellPipe { nome: String, caminho: String },
3543 #[error(
3544 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3545 command-separator metacharacter `;` (every interactive shell — bash / zsh / fish \
3546 / nushell — lexes `;` as the sequential-command terminator that fires the next \
3547 command regardless of the prior command's exit status, so `:caminho \
3548 \"../caixa-teia; rm -rf build\"` is the canonical paste-from-shell-one-liner \
3549 footgun where an author copies a `cd path; do-thing` chain without trimming \
3550 the cleanup tail, and `:caminho \"../foo;;bar\"` is the symmetric POSIX `case` \
3551 arm `;;` terminator paste shape; POSIX `std::path::Path` treats `;` as a \
3552 literal path-component byte, so the resolver folds the value through \
3553 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3554 subdirectory and fails at resolve time with a non-self-locating `No such file \
3555 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3556 the value verbatim in its per-dep content-address `path:{caminho}` at \
3557 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3558 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3559 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3560 canonical shell-metachar injection surface every peer single-token-shaped \
3561 typed slot already closes. The peer `:entrada :paths` axis rejects `;` via \
3562 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3563 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3564 workspace directory name carries no shell-command-separator semantic."
3565 )]
3566 FonteCaminhoShellSemicolon { nome: String, caminho: String },
3567 #[error(
3568 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3569 background / list-AND metacharacter `&` (every interactive shell — bash / zsh \
3570 / fish / nushell — lexes `&` two ways: single `&` as the background-task \
3571 terminator detaching the prior command and returning control immediately to \
3572 the prompt, double `&&` as the logical-AND list operator firing the next \
3573 command only if the prior succeeded; POSIX `std::path::Path` treats it as a \
3574 literal byte. The canonical paste-from-shell-prompt footgun is a `cd path & \
3575 sleep 1` background-launch one-liner or a `cd path && make install` build-\
3576 chain idiom selected whole into the `:caminho` slot — the prior `;` arm at \
3577 05c358e closed the sequential-command-separator vector, this arm closes the \
3578 orthogonal background-task / logical-AND vector on the same paste-from-shell-\
3579 prompt class. The lacre pipeline embeds the value verbatim in its per-dep \
3580 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3581 byte lands in the BLAKE3 closure and rides into every shell-spawned \
3582 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3583 future operator-side `nix` spawn) as the canonical shell-metachar injection \
3584 surface every peer single-token-shaped typed slot already closes. The peer \
3585 `:entrada :paths` axis rejects `&` via `is_gateway_api_http_path`'s eleven-\
3586 byte RFC-3986-reserved set. Express the path as a bare relative single-token \
3587 like \"../caixa-teia\" — the sibling-workspace directory name carries no \
3588 shell-background / logical-AND semantic."
3589 )]
3590 FonteCaminhoShellBackground { nome: String, caminho: String },
3591 #[error(
3592 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3593 command-substitution metacharacter `` ` `` (every POSIX shell — sh / bash / zsh / \
3594 dash / ksh / fish / nushell — lexes the byte as the legacy command-substitution \
3595 wrapper that runs the enclosed command and substitutes its standard-output \
3596 verbatim into the surrounding word, so a backticked `whoami` expands to the \
3597 current user's name and a backticked `cat /etc/passwd` expands to the file's \
3598 contents — the canonical CWE-78 shell-command-injection vector; POSIX \
3599 `std::path::Path` treats the byte as a literal path-component byte. The canonical \
3600 paste-from-shell-prompt footgun is a `cd ../path/<backtick>whoami<backtick>` legacy substitution \
3601 one-liner or a `cd <backtick>pwd<backtick>/path` working-directory expansion idiom selected whole \
3602 into the `:caminho` slot — the prior `&` arm at e12e4f3 closed the shell-\
3603 background / logical-AND vector, this arm closes the orthogonal command-\
3604 substitution vector on the same paste-from-shell-prompt class (the modern `$()` \
3605 form is gated at leading position by the f4efe9c `FonteCaminhoVarExpansion` arm; \
3606 the legacy backtick form is the orthogonal axis). The lacre pipeline embeds the \
3607 value verbatim in its per-dep content-address `path:{caminho}` at \
3608 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3609 rides into every shell-spawned subprocess (the resolver's `git clone`, a future \
3610 `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3611 shell-metachar injection surface every peer single-token-shaped typed slot \
3612 already closes. The peer `:entrada :paths` axis rejects the byte via \
3613 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the path \
3614 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3615 directory name carries no shell-command-substitution semantic."
3616 )]
3617 FonteCaminhoShellCommandSubstitution { nome: String, caminho: String },
3618 #[error(
3619 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3620 glob / pathname-expansion metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — \
3621 sh / bash / zsh / dash / ksh / fish / nushell — lexes `*` and `?` as pathname-\
3622 expansion wildcards: `*` matches any sequence of characters in a path component \
3623 and `?` matches exactly one character, so a `:caminho \"../caixa-teia/*\"` is the \
3624 canonical paste-from-shell-listing footgun where an author copies a \
3625 `ls ../caixa-teia/*` listing without trimming the wildcard, and `:caminho \
3626 \"../foo?\"` is the symmetric single-char-wildcard paste shape; POSIX \
3627 `std::path::Path` treats both bytes as literal path-component bytes, so the \
3628 resolver folds the value through `Path::new(caminho).join(<file>)` looking for \
3629 a literal `./{caminho}` subdirectory and fails at resolve time with a non-self-\
3630 locating `No such file or directory` error far from the source caixa.lisp. The \
3631 lacre pipeline embeds the value verbatim in its per-dep content-address \
3632 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the \
3633 BLAKE3 closure and rides into every shell-spawned subprocess (the resolver's \
3634 `git clone`, a future `feira tofu` shell-out, a future operator-side `nix` \
3635 spawn) as the canonical shell-metachar / glob-expansion surface every peer \
3636 single-token-shaped typed slot already closes. The peer `:entrada :paths` axis \
3637 rejects `*` and `?` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-\
3638 reserved set. Express the path as a bare relative single-token like \
3639 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-glob \
3640 / pathname-expansion semantic.",
3641 ch = *byte as char
3642 )]
3643 FonteCaminhoShellGlob {
3644 nome: String,
3645 caminho: String,
3646 byte: u8,
3647 },
3648 #[error(
3649 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3650 subshell-grouping metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / \
3651 zsh / dash / ksh / fish / nushell — lexes `(` and `)` as the subshell-grouping \
3652 operator: `(<cmd>)` runs `<cmd>` in a child shell with a fresh environment scope \
3653 (the canonical `(cd <path> && <cmd>)` shell-history one-liner scopes a `cd` to one \
3654 subshell without disturbing the parent's working directory), and `$(<cmd>)` is the \
3655 modern Bourne command-substitution shape the leading-`$` `FonteCaminhoVarExpansion` \
3656 arm closes the leading byte of — together the two arms now structurally exclude the \
3657 entire `$(<cmd>)` substitution surface from the typed `:caminho` accepted set. \
3658 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3659 `:caminho \"../caixa-teia/$(date)/build\"` (the canonical paste-from-shell-history \
3660 modern-command-substitution footgun) or `:caminho \"../(cd foo && pwd)/caixa-teia\"` \
3661 (the symmetric subshell-grouping working-directory-probe paste idiom) silently passes \
3662 every prior arm and the resolver folds the value through `Path::new(caminho).join(\
3663 <file>)` looking for a literal subdirectory and fails at resolve time with a non-\
3664 self-locating `No such file or directory` error far from the source caixa.lisp. The \
3665 lacre pipeline embeds the value verbatim in its per-dep content-address `path:\
3666 {caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 \
3667 closure and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3668 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3669 shell-metachar / subshell-grouping surface every peer single-token-shaped typed slot \
3670 already closes. The peer `:fonte :repo` axis (3b99147) closes the same byte under the \
3671 same shell-subshell-grouping / RFC-3986-sub-delims banner on `is_git_repo_url`, \
3672 together with the leading-`$` `FonteCaminhoVarExpansion` arm closing the leading byte \
3673 of every `$(<cmd>)` shape. Express the path as a bare relative single-token \
3674 like \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3675 subshell-grouping semantic.",
3676 ch = *byte as char
3677 )]
3678 FonteCaminhoShellSubshellGrouping {
3679 nome: String,
3680 caminho: String,
3681 byte: u8,
3682 },
3683 #[error(
3684 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3685 brace-expansion / URI-Template placeholder metacharacter 0x{byte:02x} `{ch}` \
3686 (every POSIX-derived brace-expanding shell — bash / zsh / ksh / fish — lexes `{{` / \
3687 `}}` as the brace-expansion operator: `{{a,b,c}}` expands to the cross-product of \
3688 comma-separated members and `{{1..10}}` expands to the integer range — the \
3689 canonical `mkdir -p ../{{caixa-teia,caixa-helm,caixa-flux}}` / `cp file{{,.bak}}` \
3690 idiom every shell-history block carries; RFC 6570 reserves the matched pair for \
3691 URI Template placeholders (the canonical `https://{{host}}/{{org}}/{{repo}}` \
3692 substitution shape every OpenAPI / Swagger / Postman / GitHub Octokit client \
3693 library / Helm chart-URL fragment carries) and the Mustache / Handlebars / \
3694 Tera / Jinja2 / Go html/template doubled-brace substitution form every IaC \
3695 templating engine (Helm, Kustomize, Terraform's `${{var}}` cousin) emits. POSIX \
3696 `std::path::Path` treats the byte as a literal path-component byte, so a \
3697 `:caminho \"../{{caixa-teia,caixa-helm}}/build\"` (the canonical paste-from-\
3698 shell-history brace-expansion fan-across-siblings footgun) or `:caminho \"../{{{{org}}}}/\
3699 caixa-teia\"` (the symmetric paste-from-templated-doc URI-Template placeholder \
3700 idiom every README quick-start / OpenAPI spec / Helm chart `home:` field carries) \
3701 silently passes every prior arm and the resolver folds the value through \
3702 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3703 resolve time with a non-self-locating `No such file or directory` error far from \
3704 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its \
3705 per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
3706 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
3707 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3708 future operator-side `nix` spawn) as the canonical shell-metachar / brace-\
3709 expansion / URI-Template-placeholder surface every peer single-token-shaped \
3710 typed slot already closes. The peer `:fonte :repo` axis (42d8f9d) closes the \
3711 same byte pair on `is_git_repo_url` under the same RFC-3986-'delims' / \
3712 RFC-6570-URI-Template / shell-brace-expansion banner. Express the path as a \
3713 bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3714 directory name carries no shell-brace-expansion / URI-Template-placeholder \
3715 semantic; if two siblings actually need pinning, author two separate `:deps` \
3716 entries rather than one brace-expanded `:caminho` value.",
3717 ch = *byte as char
3718 )]
3719 FonteCaminhoShellBraceExpansion {
3720 nome: String,
3721 caminho: String,
3722 byte: u8,
3723 },
3724 #[error(
3725 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3726 bracket-expansion / POSIX glob-character-class / shell-`test`-builtin metacharacter \
3727 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / nushell \
3728 — lexes the bracket pair as the glob character-class operator: `[abc]` matches one of \
3729 `a` / `b` / `c`, `[a-z]` matches any lowercase ASCII letter, `[^x]` negates — the \
3730 canonical `ls *.[ch]` C-source-file glob and `cd ../caixa-[a-z]*` lowercase-sibling \
3731 glob every shell-history block carries; the bracket pair additionally carries the \
3732 POSIX `test` / `[` builtin command (`[ -d ../caixa-teia ] && cd ...` every shell-\
3733 script conditional uses) and bash's `[[ ... ]]` extended-test grammar; beyond shell \
3734 the pair is the TOML inline-array delimiter (`features = [\"a\", \"b\"]` — the \
3735 canonical paste-from-Cargo-manifest cross-idiom-leak vector), the YAML flow-sequence \
3736 delimiter (`paths: [/a, /b]` — the canonical paste-from-values.yaml cross-idiom \
3737 leak), the JSON array delimiter, and the POSIX-ERE / PCRE bracket-expression anchor. \
3738 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3739 `:caminho \"../caixa-[a-z]/build\"` (the canonical paste-from-shell-history glob-\
3740 character-class fan-across-siblings footgun) or `:caminho \"../[caixa-teia]/build\"` \
3741 (the symmetric paste-from-TOML-array / paste-from-YAML-flow-sequence cross-idiom \
3742 leak) silently passes every prior arm and the resolver folds the value through \
3743 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3744 resolve time with a non-self-locating `No such file or directory` error far from \
3745 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3746 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3747 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3748 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3749 `nix` spawn) as the canonical shell-metachar / glob-character-class / TOML-array \
3750 surface every peer single-token-shaped typed slot already closes. Express the path \
3751 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3752 directory name carries no shell-bracket-expansion / glob-character-class / array-\
3753 literal semantic; if a family of sibling caixas actually needs pinning, author \
3754 separate `:deps` entries rather than one character-class-expanded `:caminho` value.",
3755 ch = *byte as char
3756 )]
3757 FonteCaminhoShellBracketExpansion {
3758 nome: String,
3759 caminho: String,
3760 byte: u8,
3761 },
3762 #[error(
3763 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3764 quote-grouping / cross-config-DSL string-literal-delimiter metacharacter \
3765 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3766 nushell — lexes `'` as the strong string-literal delimiter (`'…'` — no expansion) \
3767 and `\"` as the weak string-literal delimiter (`\"…\"` — variable- / command-\
3768 substitution-preserving); the canonical `cd '../caixa-teia'` shell-history idiom \
3769 every path-with-embedded-whitespace paste block carries and the symmetric \
3770 `git clone \"$REPO\"` weak-quoted CI-manifest shape both leak the pair verbatim. \
3771 Beyond shell the pair is the JSON string-literal delimiter (`\"key\": \"value\"` — \
3772 the canonical paste-from-JSON-config cross-idiom-leak vector), the YAML double- \
3773 and single-quoted flow-scalar delimiter (`path: \"../caixa-teia\"` — the canonical \
3774 paste-from-values.yaml / paste-from-K8s-YAML-manifest cross-idiom leak), the TOML \
3775 basic and literal string delimiter (`path = \"../caixa-teia\"` — the canonical \
3776 paste-from-Cargo-manifest cross-idiom leak), the tatara-lisp string-literal \
3777 delimiter itself (`(:caminho \"../caixa-teia\")` — the canonical \"I copied the \
3778 entire `:caminho \"...\"` slot rather than just the string body\" author-surface \
3779 footgun), and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which excludes \
3780 both bytes from the `pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"` \
3781 production. POSIX `std::path::Path` treats the byte as a literal path-component \
3782 byte, so a `:caminho \"'../caixa-teia'\"` (the canonical paste-from-shell-history \
3783 strong-quoted sibling-workspace path footgun) or `:caminho \"\\\"../caixa-teia\\\"\"` \
3784 (the symmetric weak-quoted paste-from-JSON / paste-from-YAML flow-scalar / paste-\
3785 from-TOML basic-string / paste-from-tatara-lisp string-literal cross-idiom-leak \
3786 shape) silently passes every prior arm and the resolver folds the value through \
3787 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3788 resolve time with a non-self-locating `No such file or directory` error far from \
3789 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3790 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3791 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3792 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3793 `nix` spawn) as the canonical shell-metachar / string-literal-delimiter surface \
3794 every peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
3795 axis closes both bytes under the same shell-quote-grouping / RFC-3986-sub-delims \
3796 banner (e7a109f `'` shell-single-quote + 4267d8b `\"` shell-double-quote on \
3797 `is_git_repo_url`). Express the path as a bare relative single-token like \
3798 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-quote-\
3799 grouping / string-literal-delimiter semantic; strip the outer quote pair from the \
3800 paste (the tatara-lisp `:caminho \"...\"` slot already carries the string-literal \
3801 quoting on the outer syntactic layer, so an inner quote pair would nest and \
3802 desugar to a broken layer).",
3803 ch = *byte as char
3804 )]
3805 FonteCaminhoShellQuoteGrouping {
3806 nome: String,
3807 caminho: String,
3808 byte: u8,
3809 },
3810 #[error(
3811 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3812 comment / URL-fragment-identifier / YAML-comment cross-config-DSL metacharacter \
3813 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3814 nushell — lexes an unquoted `#` at the head of a word or after unquoted \
3815 whitespace as the comment-lead per POSIX.1-2017 §2.3 Token Recognition step 6, \
3816 discarding the byte and everything after it to the end of the physical line \
3817 before command parsing (`cd ../caixa-teia # legacy sibling` — the canonical \
3818 paste-from-shell-history-with-trailing-annotation shape every operator-notebook \
3819 and CI-manifest carries); YAML 1.2 §6.6 makes `#` the comment-lead at any \
3820 position preceded by whitespace or at line-start (`path: ../caixa-teia # pin` \
3821 — the canonical paste-from-values.yaml / paste-from-K8s-manifest cross-idiom-\
3822 leak); RFC 3986 §3.5 reserves `#` as the URL fragment-identifier delimiter (the \
3823 canonical paste-from-browser-address-bar `github.com/foo/bar#readme` / \
3824 `github.com/foo/bar#L42` permalink shape, and the symmetric Nix-flake-ref \
3825 cross-idiom leak `github:foo/bar#packageName` where `#` selects a flake \
3826 output); the same cross-config-DSL surface extends to HCL / Terraform / Nix \
3827 flake attributes / dotenv `.env` / gitconfig / .gitignore / ini / TOML where \
3828 `#` is likewise the comment-lead. POSIX `std::path::Path` treats the byte as a \
3829 literal path-component byte, so a `:caminho \"../caixa-teia # legacy sibling\"` \
3830 (the canonical paste-from-shell-history-with-trailing-annotation footgun), \
3831 `:caminho \"../caixa-teia # pin\"` (the symmetric YAML flow-scalar paste-with-\
3832 trailing-comment shape), or `:caminho \"../caixa-teia#readme\"` (the URL \
3833 fragment paste-from-browser-address-bar shape) silently passes every prior arm \
3834 and the resolver folds the value through `Path::new(caminho).join(<file>)` \
3835 looking for a literal subdirectory named `../caixa-teia # legacy sibling` and \
3836 fails at resolve time with a non-self-locating `No such file or directory` \
3837 error far from the source caixa.lisp — while every downstream shell / YAML / \
3838 URL parser silently truncates the value at the `#` byte to `../caixa-teia`, so \
3839 a `feira tofu` shell-out and a `nix flake check` on an emitted YAML `path:` \
3840 scalar disagree with the resolver on which directory the value names. The \
3841 lacre pipeline embeds the value verbatim in its per-dep content-address \
3842 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in \
3843 the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3844 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-\
3845 side `nix` spawn) as the canonical shell-metachar / comment-lead / URL-\
3846 fragment-delimiter surface every peer single-token-shaped typed slot already \
3847 closes. The peer `:fonte :repo` axis closes the byte under the same URL-\
3848 fragment-identifier banner (a68f818 `#` on `is_git_repo_url`). Express the \
3849 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3850 workspace directory name carries no shell-comment / URL-fragment / YAML-\
3851 comment semantic; move any trailing annotation to a tatara-lisp `;`-comment \
3852 on the surrounding form (`;; legacy sibling` above the `(:caminho ...)` slot) \
3853 and drop any `#fragment` tail entirely (fragment identifiers select \
3854 renderings, not directories, and `:caminho` names a directory).",
3855 ch = *byte as char
3856 )]
3857 FonteCaminhoShellComment {
3858 nome: String,
3859 caminho: String,
3860 byte: u8,
3861 },
3862 #[error(
3863 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains URL-\
3864 percent-encoding-escape / printf-format-specifier / bash-job-control-specifier \
3865 / YAML-directive-lead metacharacter 0x{byte:02x} `{ch}` (RFC 3986 §2.1 reserves \
3866 `%` as the URL percent-encoding-escape — `%HH` is the mandatory encoding \
3867 mechanism for every byte outside the `unreserved` alphanumeric / `-` / `.` / \
3868 `_` / `~` set, and `%` itself must be percent-encoded as `%25` to appear \
3869 literally inside a URL value. The canonical paste-from-browser-address-bar \
3870 percent-encoded-space footgun (an author copies `../caixa%20teia` out of a URL-\
3871 encoded README hyperlink / browser address bar / percent-encoded permalink \
3872 expecting `%20` to decode to a literal space at the filesystem layer) locks two \
3873 distinct BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`) for \
3874 what the author intended as the byte-identical sibling-workspace dep. POSIX \
3875 `std::path::Path` treats the byte as a literal path-component byte, so \
3876 `Path::join` looks for a literal `./{caminho}` subdirectory and fails at \
3877 resolve time with a non-self-locating `No such file or directory` error far \
3878 from the source caixa.lisp — while every downstream URL parser / shell printf \
3879 builtin / YAML directive parser silently reinterprets the byte to a different \
3880 value than the resolver's `Path::join` sees. Beyond the URL-encoding hazard, \
3881 `%` is the C / POSIX printf format-directive lead-in (`%s`, `%d`, `%02x` — \
3882 wired into every POSIX shell's `printf` builtin, the canonical CWE-134 format-\
3883 string-injection vector); the bash / zsh / ksh job-control-specifier lead-in \
3884 (`%1` names \"job 1\", `%%` names \"the current job\", `%foo` names \"the most \
3885 recent job whose command started with `foo`\" — a future `kill %1` invocation \
3886 silently redirects the signal to a wrong target); the YAML 1.2 §6.8.1 \
3887 directive lead-in (`%YAML 1.2` / `%TAG` — the paste-from-top-of-doc YAML \
3888 directive block cross-idiom leak); and the Windows-shell env-var-reference \
3889 lead-in (`%PATH%` — the paste-from-`.bat` / paste-from-PowerShell-`%env:PATH%` \
3890 cross-idiom leak). The lacre pipeline embeds the value verbatim in its per-dep \
3891 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3892 byte lands in the BLAKE3 closure and rides into every shell-spawned subprocess \
3893 (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
3894 operator-side `nix` spawn) as the canonical URL-percent-encoding-escape / \
3895 printf-format-specifier / job-control-specifier surface every peer single-\
3896 token-shaped typed slot already closes. The peer `:fonte :repo` axis closes \
3897 the byte under the same URL-percent-encoding-escape banner (a323db8 `%` on \
3898 `is_git_repo_url`). Express the path as a bare relative single-token like \
3899 \"../caixa-teia\" — the sibling-workspace directory name carries no URL-\
3900 percent-encoding-escape / format-specifier / job-control semantic; substitute \
3901 any `%20` percent-encoded-space with a literal space then reject the whole \
3902 value at the leading-whitespace / embedded-`?` arm on the same axis (a caixa \
3903 directory name never carries an embedded space in practice); drop any \
3904 `%2F`-encoded path separator in favor of a literal `/`; and drop any leading \
3905 `%YAML` / `%PATH%` cross-idiom-leak prefix entirely.",
3906 ch = *byte as char
3907 )]
3908 FonteCaminhoUrlPercentEncoding {
3909 nome: String,
3910 caminho: String,
3911 byte: u8,
3912 },
3913 #[error(
3914 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3915 variable-expansion / command-substitution / arithmetic-expansion / cross-config-\
3916 DSL-interpolation metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / \
3917 bash / zsh / dash / ksh / busybox ash / fish / nushell — lexes `$` per \
3918 POSIX.1-2017 §2.6 as the variable-expansion `$<name>` / braced-form `${{<name>}}` \
3919 / command-substitution `$(<cmd>)` / arithmetic-expansion `$((<expr>))` operator; \
3920 Nix uses `${{var}}` as the string-interpolation lead, Make uses `$(var)` / `$@` \
3921 / `$<` for variables and automatic-variables, JavaScript / TypeScript template \
3922 literals use `${{expr}}` for interpolation, envsubst / Kubernetes / OpenShift \
3923 templates use `${{VAR}}` for env-var-reference, PHP uses `$_GET` / `$_ENV` for \
3924 superglobals, Perl uses `$foo` for scalars, SASS / SCSS uses `$primary-color` \
3925 for variables, and PostgreSQL / SQLite use `$1` / `$2` for bind parameters — \
3926 the byte is a first-class parser byte in nearly every config / templating / \
3927 build-system DSL the substrate's paste-idiom surface routinely crosses. POSIX \
3928 `std::path::Path` treats the byte as a literal path-component byte, so the \
3929 canonical paste-from-shell-one-liner `:caminho \"../foo$HOME/bar\"` / paste-\
3930 from-CI-manifest `:caminho \"../foo${{WORKSPACE}}/bar\"` / paste-from-shell-\
3931 prompt `:caminho \"../foo$(whoami)/bar\"` footguns silently pass every prior \
3932 cascade arm (`$` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / \
3933 `?` / `(` / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%`) and route \
3934 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3935 subdirectory that fails at resolve time with a non-self-locating `No such file \
3936 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3937 the value verbatim in its per-dep content-address `path:{caminho}` at \
3938 caixa-resolver/src/resolve.rs:189, so byte-identical caixa.lisp values differing \
3939 only in whether the author substituted `$HOME` / `${{WORKSPACE}}` at author \
3940 time lock to two distinct BLAKE3 closures across two workstations whose \
3941 downstream envsubst / Nix / Make / K8s-template layers differ in `$VAR` \
3942 recognition — defeating the THEORY.md §V.2 render-determinism contract on the \
3943 same axis every prior `:caminho` arm protects. Beyond the determinism vector, \
3944 `$` at any position in a value flowing verbatim into a shell-spawned subprocess \
3945 is the canonical CWE-78 shell-command-injection surface every peer single-\
3946 token-shaped typed slot already closes: peer `:fonte :repo` axis rejects `$` \
3947 under the shell-variable-expansion / URL-sub-delim banner via `is_git_repo_url` \
3948 (b9d187c), peer `:fonte :tag` / `:fonte :branch` axes reject `$` as part of \
3949 `is_git_ref_name`'s printable-ASCII-restricted grammar (`git check-ref-format` \
3950 rejects the byte outright), and peer `:entrada :paths` axis rejects `$` via \
3951 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. The leading-`$` \
3952 position on the same axis routes through `FonteCaminhoVarExpansion` at the \
3953 f4efe9c leading-byte arm; this arm closes the last positional gap on the byte \
3954 so every position — leading and embedded — is structurally rejected. Substitute \
3955 the `$VAR` / `${{VAR}}` / `$(cmd)` template with the literal value at author \
3956 time, or express the path as a bare relative single-token like \
3957 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3958 variable-expansion / command-substitution / arithmetic-expansion semantic.",
3959 ch = *byte as char
3960 )]
3961 FonteCaminhoShellVariableExpansion {
3962 nome: String,
3963 caminho: String,
3964 byte: u8,
3965 },
3966 #[error(
3967 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3968 history-expansion / RFC-3986-sub-delims / bang-operator metacharacter 0x{byte:02x} \
3969 `{ch}` (every interactive POSIX shell with history enabled — bash / ksh / zsh's \
3970 `bashcompat` / csh / tcsh — lexes `!` as the history-expansion prefix per bash \
3971 reference §9.3: `!command` re-runs the most recent history entry beginning with \
3972 `command`, `!!` re-runs the prior command verbatim, `!$` substitutes the last \
3973 word of the prior command, `!:N` substitutes the Nth word of the prior command, \
3974 and the substitution fires at every history-expansion-enabled shell context — \
3975 `set -o histexpand` is bash's default for interactive sessions and the layer \
3976 every `feira tofu` / `git clone` / `nix flake check` subprocess-argument \
3977 invocation crosses when spawned under `bash -i`. Beyond shell history, RFC 3986 \
3978 §2.2 lists `!` in the `sub-delims` set (the URL grammar admits the byte inside \
3979 a path segment, but every WHATWG-conformant special-scheme URL parser percent-\
3980 encodes it inside a query component via the 'special-query percent-encode set' \
3981 the peer `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte is \
3982 also the C / C++ / Rust / JavaScript / Python bang-operator (logical-negation \
3983 prefix — the paste-from-source-code idiom where an author copies \
3984 `!path.exists()` out of a Rust snippet and the trailing punctuation crosses \
3985 the string-literal boundary); the canonical English-typography emphasis / \
3986 exclamation mark (the paste-from-prose enthusiasm-form idiom where an author \
3987 writes `:caminho \"../caixa-teia!\"` expecting the substrate to coerce it to a \
3988 kebab-case slug); and the Nix flake-ref attribute-selection operator surface. \
3989 POSIX `std::path::Path` treats `!` as a literal path-component byte, so the \
3990 canonical paste-from-shell-history footgun `:caminho \"../caixa-teia!sudo\"` \
3991 (an author copies a `cd ../caixa-teia && !sudo make install` one-liner from a \
3992 quick-start README and the trailing `!sudo` rides in verbatim as a history-\
3993 expansion reference), the symmetric `:caminho \"../foo!!/bar\"` (the `!!` \
3994 repeat-prior-command paste idiom), the English-typography `:caminho \
3995 \"../caixa-teia!\"` (paste-from-prose enthusiasm-form), and the last-word-\
3996 substitution `:caminho \"../foo!$\"` shape silently pass every prior cascade \
3997 arm (`!` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` \
3998 / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$`) and route \
3999 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4000 subdirectory that fails at resolve time with a non-self-locating `No such file \
4001 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4002 the value verbatim in its per-dep content-address `path:{caminho}` at \
4003 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
4004 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
4005 future `feira tofu` shell-out, a future operator-side `nix flake check` spawn) \
4006 as the canonical shell-history-expansion / RFC-3986-sub-delims surface every \
4007 peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4008 axis closes the byte under the same shell-history-expansion / RFC-3986-sub-\
4009 delims banner (7d53c68 `!` on `is_git_repo_url`). Express the path as a bare \
4010 relative single-token like \"../caixa-teia\" — the sibling-workspace directory \
4011 name carries no shell-history-expansion / bang-operator semantic; drop any \
4012 `!sudo` / `!!` / `!$` history-expansion trailing paste-from-shell-history \
4013 idiom; and drop any trailing English-typography exclamation mark that pasted \
4014 from prose.",
4015 ch = *byte as char
4016 )]
4017 FonteCaminhoShellHistoryExpansion {
4018 nome: String,
4019 caminho: String,
4020 byte: u8,
4021 },
4022 #[error(
4023 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4024 history-substitution / RFC-3986-'unwise' / regex-negation metacharacter 0x{byte:02x} \
4025 `{ch}` (POSIX bash's `set -o histexpand` mode — the default for every interactive \
4026 session and every `bash -i` subprocess-argument context `feira tofu` / `git clone` / \
4027 `nix flake check` cross — lexes `^old^new^` per bash reference §9.3 as the 'quick \
4028 substitution' history operator that rewrites the prior command's `old` string to \
4029 `new` and re-executes it verbatim, the canonical typo-correction one-liner idiom \
4030 (`git clone <bad-url>` → `^bad^good` typo-fix-and-rerun the paste-from-shell-\
4031 history author trims only the leading `git clone` prefix from). RFC 3986 §2 lists \
4032 `^` in the 'unwise' set every URL parser is required to percent-encode-or-refuse at \
4033 the wire boundary, and the WHATWG URL spec's 'fragment percent-encode set' maps \
4034 `^` → `%5E` at the query / fragment component transition, so `Path::join` on the \
4035 literal value diverges from every downstream `feira tofu` curl-invocation / \
4036 artifact-registry-fetch that percent-encodes the byte before the wire. `^` is also \
4037 the regex character-class negation prefix (`[^abc]`), the bitwise XOR operator in \
4038 C / C++ / Rust / Python / JavaScript / Nix / Go, the Windows `cmd.exe` escape \
4039 metacharacter, and the LaTeX / Markdown / BibTeX superscript operator. POSIX \
4040 `std::path::Path` treats `^` as a literal path-component byte, so \
4041 `:caminho \"../foo^bar/baz\"` (embedded quick-substitution), `:caminho \
4042 \"../foo^\"` (trailing history-substitution-open shape), or `:caminho \"../x^y\"` \
4043 (XOR-expression paste-from-source) silently pass every prior cascade arm (`^` \
4044 isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` / `)` / `{{` \
4045 / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$` / `!`) and route through \
4046 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` subdirectory \
4047 that fails at resolve time with a non-self-locating `No such file or directory` \
4048 error far from the source caixa.lisp. The lacre pipeline embeds the value verbatim \
4049 in its per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
4050 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
4051 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4052 operator-side `nix flake check` spawn) as the canonical shell-history-substitution \
4053 / RFC-3986-unwise surface every peer single-token-shaped typed slot already closes. \
4054 The peer `:fonte :repo` axis closes the byte under the same shell-history-\
4055 substitution / RFC-3986-unwise banner (49e142f `^` on `is_git_repo_url`). Together \
4056 with the immediate-predecessor `!` arm (6a04767) this arm closes the full `set -o \
4057 histexpand` operator surface on the `:caminho` axis — the `!command` / `!!` / `!$` \
4058 prefix form via `!`, the `^old^new^` quick-substitution form via `^`. Express the \
4059 path as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
4060 directory name carries no shell-history-substitution / regex-negation / XOR-operator \
4061 semantic; drop any `^old^new` history-substitution paste-from-shell-history idiom; \
4062 drop any trailing `^` history-substitution-open fragment.",
4063 ch = *byte as char
4064 )]
4065 FonteCaminhoShellHistorySubstitution {
4066 nome: String,
4067 caminho: String,
4068 byte: u8,
4069 },
4070 #[error(
4071 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} has a trailing \
4072 `/` (the resolver's `Path::join` resolves `\"../caixa-teia\"` and \
4073 `\"../caixa-teia/\"` to the same directory, but the lacre pipeline embeds the \
4074 value verbatim in its per-dep content-address `path:{caminho}` at \
4075 caixa-resolver/src/resolve.rs:189, so two authors whose only difference is \
4076 shell tab-completion emit byte-divergent BLAKE3 closures for the same caixa — \
4077 defeating the THEORY.md §V.2 render-determinism contract via the trailing-\
4078 separator vector (the canonical paste-from-shell-tab-completion + paste-from-\
4079 `pwd`-with-`/`-suffix footgun, and the canonical Cargo-style `path = \
4080 \"../caixa-teia/\"` paste-from-Cargo-manifest cross-idiom leak). Drop the \
4081 trailing `/`; every `:caminho` value names a sibling-workspace directory \
4082 already, so the trailing separator carries no information. Use \
4083 `\"../caixa-teia\"` rather than `\"../caixa-teia/\"`)"
4084 )]
4085 FonteCaminhoTrailingSlash { nome: String, caminho: String },
4086 #[error(
4087 "{list} carries duplicate entry :nome {nome:?} — every dep list keys its \
4088 entries by caixa name (Cargo's [dependencies] / [dev-dependencies] tables \
4089 apply the same set-not-multiset discipline; one package per table), and \
4090 two entries naming the same caixa carry two version constraints / source \
4091 pins / feature sets for one identity. The caixa-resolver's lacre pipeline \
4092 consumes the list as a `HashMap`-keyed-by-`:nome` lookup: the second entry \
4093 silently overwrites the first at the resolver-side `concrete_versao` step, \
4094 and the dropped entry's pin / features never reach the closure — far from \
4095 the source caixa.lisp, with no field naming which `:deps` entry was the \
4096 silent loser. If two version constraints are genuinely needed (the rare \
4097 multi-version closure case the lacre pipeline doesn't yet support), the \
4098 author surface is two distinct caixa names (e.g. a `caixa-teia-v01` / \
4099 `caixa-teia-v02` aliased pair); within one list, one entry per caixa name."
4100 )]
4101 DuplicateNome { nome: String, list: &'static str },
4102 #[error(
4103 ":deps entry {nome:?} has empty :caracteristicas entry — every feature flag must \
4104 name a non-empty identifier on the target caixa (Cargo's [dependencies.<dep>.features] \
4105 applies the same per-entry non-empty discipline). An empty feature flag reaches the \
4106 caixa-resolver's lacre pipeline as a no-op feature enable, silently dropping the \
4107 author's intent far from the source caixa.lisp; drop the empty entry, or replace it \
4108 with the canonical kebab-case feature name the target caixa declares."
4109 )]
4110 CaracteristicaEmpty { nome: String },
4111 #[error(
4112 ":deps entry {nome:?} :caracteristicas entry {caracteristica:?} is not a valid Cargo \
4113 feature name: {reason} (the value flows verbatim into Cargo's \
4114 [dependencies.<dep>.features] list and Cargo's `restricted_names::validate_feature_name` \
4115 parser enforces the same shape at `cargo metadata` time; use a single-token \
4116 identifier like `\"http\"`, `\"derive\"`, or `\"runtime-tokio\"` — kebab-case ASCII \
4117 alphanumeric with `-`, `_`, `+`, or `.` as continuation characters, starting with \
4118 an ASCII alphanumeric or `_`)"
4119 )]
4120 CaracteristicaInvalid {
4121 nome: String,
4122 caracteristica: String,
4123 reason: String,
4124 },
4125 #[error(
4126 ":deps entry {nome:?} :caracteristicas carries duplicate feature {caracteristica:?} — \
4127 every feature-flag list keys its entries by name (Cargo's \
4128 [dependencies.<dep>.features] applies the same set-not-multiset discipline; one entry \
4129 per feature per dep), and two entries naming the same feature are a redundant \
4130 set-membership declaration for one identity (the feature-toggle slot is set-shaped; \
4131 enabling a feature twice has no additional semantic). The caixa-resolver's lacre \
4132 pipeline consumes the list as a set-shaped feature toggle — the resolver enables the \
4133 feature once regardless of declaration count, so the duplicate's pin / position never \
4134 reaches the closure with no field naming the silent loser. One entry per feature per \
4135 dep; if two distinct features are intended, name each verbatim."
4136 )]
4137 CaracteristicaDuplicate {
4138 nome: String,
4139 caracteristica: String,
4140 },
4141 #[error(
4142 "{list} entry :nome {nome:?} names the caixa itself — a caixa cannot depend \
4143 on itself (the lacre closure's dep-graph traversal is rooted at the caixa's \
4144 :nome, and a self-dep would be a one-node cycle the caixa-resolver either \
4145 rejects mid-traversal far from the source caixa.lisp or recurses on until \
4146 it exhausts its stack). Every :nome is globally-unique substrate identity, \
4147 so a :deps / :deps-dev entry whose :nome equals the parent caixa's :nome \
4148 *is* the parent itself, not a coincidentally-named peer. Drop the \
4149 self-referential dep entry — to reference code from this caixa, use \
4150 :bibliotecas / :exe / :servicos (the substrate-blessed shape for \
4151 referencing the caixa's own code surface) instead."
4152 )]
4153 DepIsSelf { nome: String, list: &'static str },
4154}
4155
4156#[allow(clippy::trivially_copy_pass_by_ref)]
4157fn is_false(b: &bool) -> bool {
4158 !*b
4159}
4160
4161#[cfg(test)]
4162mod tests {
4163 use super::*;
4164
4165 #[test]
4166 fn registry_dep_is_minimal() {
4167 let d = Dep::simple("caixa-teia", "^0.1");
4168 assert_eq!(d.nome, "caixa-teia");
4169 assert_eq!(d.versao, "^0.1");
4170 assert!(d.fonte.is_none());
4171 assert!(!d.opcional());
4172 assert!(d.caracteristicas().is_empty());
4173 }
4174
4175 #[test]
4176 fn git_dep_carries_tag() {
4177 let d = Dep::git("t", "*", "github:o/r", "v1");
4178 match d.fonte {
4179 Some(DepSource::Git {
4180 ref repo, ref tag, ..
4181 }) => {
4182 assert_eq!(repo, "github:o/r");
4183 assert_eq!(tag.as_deref(), Some("v1"));
4184 }
4185 _ => panic!("expected Git source"),
4186 }
4187 }
4188
4189 #[test]
4190 fn validate_accepts_simple_dep() {
4191 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
4192 }
4193
4194 #[test]
4195 fn validate_rejects_empty_nome() {
4196 // The fail-before-pass-after pin for `:nome ""`: the empty-name
4197 // arm fires first so the per-entry parse-side diagnostic doesn't
4198 // emit a useless `nome: ""` reference.
4199 let mut d = Dep::simple("placeholder", "^0.1");
4200 d.nome = String::new();
4201 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4202 }
4203
4204 #[test]
4205 fn validate_rejects_empty_versao() {
4206 // `parse_requirement("")` returns `Ok(VersionReq::STAR)` (the
4207 // semver crate accepts the empty string as a wildcard match),
4208 // so the empty-`:versao` arm is structurally necessary even
4209 // with the parse arm in place — mirrors `MembroVersaoEmpty` /
4210 // `EmptyChildVersion` ordering on the other two `:versao` axes.
4211 let mut d = Dep::simple("caixa-teia", "ignored");
4212 d.versao = String::new();
4213 let err = d.validate().unwrap_err();
4214 assert!(
4215 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4216 "got {err:?}"
4217 );
4218 }
4219
4220 // ── value-shape: DNS-1123 label on :deps :nome ────────────────────────
4221
4222 #[test]
4223 fn validate_rejects_nome_with_uppercase() {
4224 // The fail-before-pass-after pin: a non-empty but uppercase
4225 // `:nome` silently passed `validate()` on every pre-gate
4226 // codebase because the prior shape only refused the empty
4227 // string. The DNS-1123 violation surfaced far downstream at
4228 // lacre-resolve time when the *target* caixa's `:nome` failed
4229 // its own gate — far from the `:deps` entry, with a diagnostic
4230 // naming the target rather than the dep entry that referenced
4231 // it. Same fail-before-pass-after fixture pinned for
4232 // `:membros :caixa` (3f9d7a0), `:children :caixa` (31bfa43),
4233 // and Caixa `:nome` (6c992f8).
4234 let d = Dep::simple("Caixa-Teia", "^0.1");
4235 let err = d.validate().unwrap_err();
4236 assert!(
4237 matches!(
4238 err,
4239 DepError::NomeInvalid { ref nome, ref reason }
4240 if nome == "Caixa-Teia" && reason.contains("uppercase")
4241 ),
4242 "got {err:?}"
4243 );
4244 }
4245
4246 #[test]
4247 fn validate_rejects_nome_with_underscore() {
4248 // RFC 1123 allows `[a-z0-9-]` only; underscore is the canonical
4249 // "I'm thinking of Go module names / Python identifiers" leak.
4250 // Same fixture pinned for the peer caixa-identifier axes.
4251 let d = Dep::simple("caixa_teia", "^0.1");
4252 let err = d.validate().unwrap_err();
4253 assert!(
4254 matches!(
4255 err,
4256 DepError::NomeInvalid { ref nome, ref reason }
4257 if nome == "caixa_teia" && reason.contains('_')
4258 ),
4259 "got {err:?}"
4260 );
4261 }
4262
4263 #[test]
4264 fn validate_rejects_nome_with_dot() {
4265 // A `:deps :nome` is a single DNS-1123 *label*, not a
4266 // subdomain — dots are rejected. The `"caixa.teia"` shape is
4267 // the canonical "I confused the dep name with the FQDN /
4268 // namespace" footgun, distinct from the legitimate
4269 // `:fonte :repo "github:org/caixa-teia"` axis.
4270 let d = Dep::simple("caixa.teia", "^0.1");
4271 let err = d.validate().unwrap_err();
4272 assert!(
4273 matches!(
4274 err,
4275 DepError::NomeInvalid { ref nome, ref reason }
4276 if nome == "caixa.teia" && reason.contains('.')
4277 ),
4278 "got {err:?}"
4279 );
4280 }
4281
4282 #[test]
4283 fn validate_rejects_nome_with_leading_hyphen() {
4284 // RFC 1123 requires alphanumeric at both label boundaries.
4285 // Pinned in parity with the peer DNS-1123 fixtures.
4286 let d = Dep::simple("-caixa-teia", "^0.1");
4287 let err = d.validate().unwrap_err();
4288 assert!(
4289 matches!(
4290 err,
4291 DepError::NomeInvalid { ref nome, ref reason }
4292 if nome == "-caixa-teia" && reason.contains("alphanumeric")
4293 ),
4294 "got {err:?}"
4295 );
4296 }
4297
4298 #[test]
4299 fn validate_rejects_nome_with_trailing_hyphen() {
4300 let d = Dep::simple("caixa-teia-", "^0.1");
4301 let err = d.validate().unwrap_err();
4302 assert!(
4303 matches!(
4304 err,
4305 DepError::NomeInvalid { ref nome, ref reason }
4306 if nome == "caixa-teia-" && reason.contains("alphanumeric")
4307 ),
4308 "got {err:?}"
4309 );
4310 }
4311
4312 #[test]
4313 fn validate_rejects_nome_with_slash() {
4314 // The canonical "I copied the GitHub repo path into `:nome`
4315 // instead of `:fonte :repo`" typo. A `/` in the name leaks the
4316 // lacre-side `:repositorio` shape (`pleme-io/caixa-teia`) into
4317 // the local-name slot. Same fixture pinned for `:membros
4318 // :caixa` (3f9d7a0).
4319 let d = Dep::simple("pleme-io/caixa-teia", "^0.1");
4320 let err = d.validate().unwrap_err();
4321 assert!(
4322 matches!(
4323 err,
4324 DepError::NomeInvalid { ref nome, ref reason }
4325 if nome == "pleme-io/caixa-teia" && reason.contains('/')
4326 ),
4327 "got {err:?}"
4328 );
4329 }
4330
4331 #[test]
4332 fn validate_rejects_nome_too_long() {
4333 // 64-byte label — one over the RFC 1035 / RFC 1123 label cap.
4334 // Built from a valid character set so the length-bound
4335 // diagnostic surfaces before any per-character check (the
4336 // order pin parallel to the per-character predicates inside
4337 // [`crate::render::is_dns_1123_label`]).
4338 let long = "a".repeat(64);
4339 let d = Dep::simple(&long, "^0.1");
4340 let err = d.validate().unwrap_err();
4341 assert!(
4342 matches!(
4343 err,
4344 DepError::NomeInvalid { ref nome, ref reason }
4345 if nome.len() == 64 && reason.contains("max length of 63")
4346 ),
4347 "got {err:?}"
4348 );
4349 }
4350
4351 #[test]
4352 fn validate_accepts_canonical_nome_labels() {
4353 // Positive-control sweep — every form the K8s apiserver
4354 // accepts as a DNS-1123 label must round-trip through
4355 // validate. Covers a hyphen-bearing label, a numeric-suffix
4356 // label, a leading-digit label, a single-character label, and
4357 // a 63-byte (exactly the cap) label — the same fixture set
4358 // the peer `:membros :caixa` / `:children :caixa` positive
4359 // controls pin.
4360 for nome in [
4361 "caixa-teia",
4362 "caixa-resolver2",
4363 "2nd-tier-cache",
4364 "x",
4365 "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0",
4366 ] {
4367 Dep::simple(nome, "^0.1")
4368 .validate()
4369 .unwrap_or_else(|e| panic!("canonical label {nome:?} must validate, got {e:?}"));
4370 }
4371 }
4372
4373 #[test]
4374 fn nome_empty_takes_precedence_over_nome_invalid() {
4375 // Ordering pin: `NomeEmpty` is the more self-locating
4376 // diagnostic on `""` and must lead — `is_dns_1123_label` is
4377 // only reached after the empty-check fires at the call site.
4378 // Mirrors `membro_caixa_empty_takes_precedence_over_invalid`
4379 // (3f9d7a0) on the peer caixa-identifier axis.
4380 let mut d = Dep::simple("placeholder", "^0.1");
4381 d.nome = String::new();
4382 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4383 }
4384
4385 #[test]
4386 fn nome_invalid_fires_before_versao_empty() {
4387 // Ordering pin: a malformed `:nome` fires before any `:versao`
4388 // axis check on the *same* entry — the per-entry shape gates
4389 // run top-to-bottom (nome empty → nome shape → versao empty →
4390 // versao parse → fonte shape), so a one-entry caixa.lisp with
4391 // both wrong sees the name-side diagnostic first (the name is
4392 // the self-locating axis — without a valid name, the parse
4393 // diagnostic can't quote `:nome "<bad>"`). Same ordering
4394 // discipline as `membro_caixa_invalid_fires_before_versao_check`
4395 // (3f9d7a0).
4396 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4397 d.versao = String::new();
4398 let err = d.validate().unwrap_err();
4399 assert!(
4400 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4401 "got {err:?}"
4402 );
4403 }
4404
4405 #[test]
4406 fn nome_invalid_fires_before_versao_invalid() {
4407 // Ordering pin: a malformed `:nome` fires before the `:versao`
4408 // parse-side check on the *same* entry. Pin separately from
4409 // the empty-versao ordering so a future re-ordering surfaces
4410 // here, parallel to the b0c8389 / c4213a4 trajectory.
4411 let d = Dep::simple("Caixa-Teia", "^^0.1");
4412 let err = d.validate().unwrap_err();
4413 assert!(
4414 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4415 "got {err:?}"
4416 );
4417 }
4418
4419 #[test]
4420 fn nome_invalid_fires_before_fonte_invalid() {
4421 // Ordering pin: a malformed `:nome` fires before the `:fonte`
4422 // shape check on the *same* entry. The `:fonte` diagnostic
4423 // names the offending dep's `:nome` verbatim (via
4424 // `DepSource::validate(&self.nome)`), so a non-self-locating
4425 // name would taint the downstream diagnostic too — the gate
4426 // ordering keeps both diagnostics individually self-locating.
4427 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4428 d.fonte = Some(DepSource::Git {
4429 repo: String::new(),
4430 tag: None,
4431 rev: None,
4432 branch: None,
4433 });
4434 let err = d.validate().unwrap_err();
4435 assert!(
4436 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4437 "got {err:?}"
4438 );
4439 }
4440
4441 #[test]
4442 fn nome_invalid_diagnostic_carries_offending_name() {
4443 // The diagnostic-shape pin: the error names the offending
4444 // `:nome` value verbatim so the author can grep their
4445 // caixa.lisp without re-running the build, and carries a
4446 // non-empty `reason` from `is_dns_1123_label` so the
4447 // predicate's own wording flows through to the diagnostic.
4448 // Same shape as `MembroCaixaInvalid` (3f9d7a0),
4449 // `ChildCaixaInvalid` (31bfa43), `ManifestError::NomeInvalid`
4450 // (6c992f8) — the four DNS-1123 caixa-identifier axes now
4451 // share a structurally-equivalent diagnostic family.
4452 let d = Dep::simple("Caixa_Teia", "^0.1");
4453 let err = d.validate().unwrap_err();
4454 let DepError::NomeInvalid { nome, reason } = err else {
4455 panic!("expected NomeInvalid, got other variant");
4456 };
4457 assert_eq!(nome, "Caixa_Teia");
4458 assert!(
4459 !reason.is_empty(),
4460 "NomeInvalid `reason` must carry the predicate's wording verbatim"
4461 );
4462 }
4463
4464 #[test]
4465 fn validate_rejects_invalid_versao_requirement() {
4466 // The fail-before-pass-after pin: a non-empty but malformed
4467 // requirement (`"^bad-version"`) silently passed every pre-gate
4468 // codebase because `:deps :versao` wasn't validated. The parse
4469 // failure surfaced far downstream at lacre-resolve time with a
4470 // `semver::Error` that didn't name which `:deps` entry carried
4471 // the typo. The new gate moves the check to caixa-build time
4472 // at the source caixa.lisp.
4473 let d = Dep::simple("caixa-teia", "^bad-version");
4474 let err = d.validate().unwrap_err();
4475 assert!(
4476 matches!(
4477 err,
4478 DepError::VersaoInvalid { ref nome, ref versao, .. }
4479 if nome == "caixa-teia" && versao == "^bad-version"
4480 ),
4481 "got {err:?}"
4482 );
4483 }
4484
4485 #[test]
4486 fn validate_rejects_versao_with_double_caret_typo() {
4487 // `"^^0.1"` is the canonical doubled-caret typo — looks like a
4488 // Cargo-shaped requirement on first glance but fails the parser
4489 // because semver doesn't accept stacked operators. Pin this
4490 // adjacent-shape footgun explicitly so a future relaxation that
4491 // accepts "looks-canonical-but-isn't" forms surfaces here, in
4492 // parity with the `:membros` / `:children` fixtures.
4493 let d = Dep::simple("caixa-teia", "^^0.1");
4494 let err = d.validate().unwrap_err();
4495 assert!(
4496 matches!(
4497 err,
4498 DepError::VersaoInvalid { ref nome, ref versao, .. }
4499 if nome == "caixa-teia" && versao == "^^0.1"
4500 ),
4501 "got {err:?}"
4502 );
4503 }
4504
4505 #[test]
4506 fn validate_rejects_versao_with_v_prefixed_tag() {
4507 // `"v0.1"` is the canonical "git-tag-shape leaking into the
4508 // semver requirement slot" typo — an author copies the
4509 // publish-side git-tag string verbatim into `:versao`, but
4510 // Cargo's semver parser rejects the leading `v`. Same fixture
4511 // pinned for `:membros :versao` (9888b13) and `:children
4512 // :versao` (b38ff3a). (Bare `x`-glob shorthands like `^0.1.x`
4513 // are *accepted* by the semver crate as an `*` wildcard on the
4514 // patch axis — they're a Cargo-side valid shape, not a typo.)
4515 let d = Dep::simple("caixa-teia", "v0.1");
4516 let err = d.validate().unwrap_err();
4517 assert!(
4518 matches!(
4519 err,
4520 DepError::VersaoInvalid { ref nome, ref versao, .. }
4521 if nome == "caixa-teia" && versao == "v0.1"
4522 ),
4523 "got {err:?}"
4524 );
4525 }
4526
4527 #[test]
4528 fn validate_accepts_canonical_versao_forms() {
4529 // The five Cargo-shaped requirement forms `:membros :versao`
4530 // and `:children :versao` already accept via
4531 // `crate::parse_requirement` must pass the deps gate without
4532 // re-validating at the resolver layer. Pin every leg so a
4533 // future tightening of the canonical set surfaces here as a
4534 // test failure.
4535 for form in [
4536 "^0.1", // caret — minor-range pin (the most common shape)
4537 "~0.1.2", // tilde — patch-range pin
4538 "0.1.0", // exact — single-version pin
4539 "*", // wildcard — explicitly any-version
4540 ">=0.1, <2", // multi-range — comma-separated comparators
4541 ] {
4542 Dep::simple("caixa-teia", form)
4543 .validate()
4544 .unwrap_or_else(|e| panic!("canonical form {form:?} must validate, got {e:?}"));
4545 }
4546 }
4547
4548 #[test]
4549 fn versao_empty_takes_precedence_over_invalid() {
4550 // Order pin: the existing `VersaoEmpty` diagnostic (which
4551 // doesn't try to parse) fires before the new `VersaoInvalid`
4552 // parse-side diagnostic, so an empty `:versao` keeps its
4553 // narrower error message — `parse_requirement("")` would
4554 // otherwise return `Ok(STAR)` and silently pass, but the empty
4555 // arm catches it first.
4556 let mut d = Dep::simple("caixa-teia", "ignored");
4557 d.versao = String::new();
4558 let err = d.validate().unwrap_err();
4559 assert!(
4560 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4561 "got {err:?}"
4562 );
4563 }
4564
4565 #[test]
4566 fn nome_empty_takes_precedence_over_versao_invalid() {
4567 // Order pin: even when `:versao` is malformed and would raise
4568 // its own diagnostic, `:nome ""` fires first because the
4569 // per-entry parse diagnostic needs a non-empty name to be
4570 // self-locating. Mirrors the
4571 // `membros_validation_runs_before_contratos_membership_check`
4572 // ordering on the typed-graph layer.
4573 let mut d = Dep::simple("placeholder", "^bad");
4574 d.nome = String::new();
4575 let err = d.validate().unwrap_err();
4576 assert_eq!(err, DepError::NomeEmpty);
4577 }
4578
4579 #[test]
4580 fn versao_invalid_diagnostic_carries_offending_versao() {
4581 // The diagnostic-shape pin: the error names the offending
4582 // `:versao` value verbatim so the author can grep their
4583 // caixa.lisp without re-running the build, and carries a
4584 // non-empty `reason` from `semver::VersionReq::parse` so the
4585 // parser's own wording flows through to the diagnostic.
4586 let d = Dep::simple("caixa-teia", "not-a-req");
4587 let err = d.validate().unwrap_err();
4588 let DepError::VersaoInvalid {
4589 nome,
4590 versao,
4591 reason,
4592 } = err
4593 else {
4594 panic!("expected VersaoInvalid, got other variant");
4595 };
4596 assert_eq!(nome, "caixa-teia");
4597 assert_eq!(versao, "not-a-req");
4598 assert!(
4599 !reason.is_empty(),
4600 "VersaoInvalid `reason` must carry the parser's wording verbatim"
4601 );
4602 }
4603
4604 // -- :fonte value-shape gate ------------------------------------------
4605
4606 fn dep_with_fonte(fonte: DepSource) -> Dep {
4607 let mut d = Dep::simple("caixa-teia", "^0.1");
4608 d.fonte = Some(fonte);
4609 d
4610 }
4611
4612 #[test]
4613 fn validate_accepts_git_fonte_with_tag() {
4614 // The positive-control pin on the canonical git source — exactly
4615 // one of :tag/:rev/:branch set, non-empty :repo. Mirrors the
4616 // shape every existing caixa-resolver integration test uses.
4617 let d = dep_with_fonte(DepSource::Git {
4618 repo: "github:pleme-io/caixa-teia".into(),
4619 tag: Some("v0.1.0".into()),
4620 rev: None,
4621 branch: None,
4622 });
4623 d.validate().unwrap();
4624 }
4625
4626 #[test]
4627 fn validate_accepts_git_fonte_with_rev() {
4628 // Each of the three pin axes is independently a valid single-pin
4629 // shape; pin the :rev arm so a future relaxation that only
4630 // accepts :tag surfaces here. The value is a full 40-hex SHA-1
4631 // OID — the canonical `git rev-parse HEAD` emission shape the
4632 // `crate::render::is_git_oid` value-shape gate now requires;
4633 // abbreviated OIDs are ambiguous across repo history and
4634 // rejected at this gate (pinned separately by
4635 // `validate_rejects_git_fonte_with_rev_abbreviated_prefix`).
4636 let d = dep_with_fonte(DepSource::Git {
4637 repo: "github:pleme-io/caixa-teia".into(),
4638 tag: None,
4639 rev: Some("c0ffee0123abcdef0123456789abcdef01234567".into()),
4640 branch: None,
4641 });
4642 d.validate().unwrap();
4643 }
4644
4645 #[test]
4646 fn validate_accepts_git_fonte_with_branch() {
4647 // The :branch arm is the third valid single-pin shape — pinned
4648 // separately so the gate-accepts-all-three-pin-axes contract is
4649 // a build-error to relax.
4650 let d = dep_with_fonte(DepSource::Git {
4651 repo: "github:pleme-io/caixa-teia".into(),
4652 tag: None,
4653 rev: None,
4654 branch: Some("main".into()),
4655 });
4656 d.validate().unwrap();
4657 }
4658
4659 #[test]
4660 fn validate_accepts_path_fonte() {
4661 // The positive-control pin on the path source — non-empty
4662 // :caminho, no pin axes (paths have no commit identity). Pinned
4663 // so a future "paths must also pin a rev" tightening surfaces
4664 // here as a structural decision, not a silent break.
4665 let d = dep_with_fonte(DepSource::Path {
4666 caminho: "../caixa-teia".into(),
4667 });
4668 d.validate().unwrap();
4669 }
4670
4671 #[test]
4672 fn validate_rejects_git_fonte_with_empty_repo() {
4673 // The fail-before-pass-after pin for `(:tipo git :repo "" :tag
4674 // "v1")`: the empty-repo shape silently passed every pre-gate
4675 // codebase because `:fonte` wasn't validated. The git-clone
4676 // failure surfaced far downstream at lacre-resolve time with no
4677 // field naming which `:deps` entry carried the typo. The new
4678 // gate moves the check to caixa-build time at the source
4679 // caixa.lisp.
4680 let d = dep_with_fonte(DepSource::Git {
4681 repo: String::new(),
4682 tag: Some("v0.1.0".into()),
4683 rev: None,
4684 branch: None,
4685 });
4686 let err = d.validate().unwrap_err();
4687 assert!(
4688 matches!(err, DepError::FonteRepoEmpty { ref nome } if nome == "caixa-teia"),
4689 "got {err:?}"
4690 );
4691 }
4692
4693 // -- :repo value-shape gate -------------------------------------------
4694 //
4695 // The `:fonte (:tipo git :repo …)` value flows verbatim into the
4696 // caixa-resolver's `git clone <repo>` subprocess. The pre-gate
4697 // codebase admitted any non-empty string; the new
4698 // [`crate::render::is_git_repo_url`] predicate gates the git-porcelain
4699 // URL intersection-floor at validate time, peer with the three pin
4700 // axes (`:tag` + `:branch` via `is_git_ref_name`, `:rev` via
4701 // `is_git_oid`). Every test in this section is a fail-before /
4702 // pass-after pin on a specific authoring footgun.
4703
4704 #[test]
4705 fn validate_rejects_git_fonte_with_repo_carrying_trailing_space() {
4706 // The canonical paste-from-doc footgun on `:repo` — an author
4707 // copies `"github:pleme-io/caixa-teia "` (trailing space) out of
4708 // a doc paragraph. Until this gate landed the empty-repo arm
4709 // passed (the string isn't empty), the resolver issued
4710 // `git clone 'github:pleme-io/caixa-teia '`, and the failure
4711 // surfaced at clone time with a quoting-confused error far from
4712 // the source caixa.lisp. Same paste-from-doc footgun the
4713 // `:tag "v0.1.0 "` gate (e70d213) closes on the peer refname
4714 // axis — now closed on the `:repo` URL axis too.
4715 let d = dep_with_fonte(DepSource::Git {
4716 repo: "github:pleme-io/caixa-teia ".into(),
4717 tag: Some("v0.1.0".into()),
4718 rev: None,
4719 branch: None,
4720 });
4721 let err = d.validate().unwrap_err();
4722 let DepError::FonteRepoShape { nome, repo, reason } = err else {
4723 panic!("expected FonteRepoShape, got other variant");
4724 };
4725 assert_eq!(nome, "caixa-teia");
4726 assert_eq!(repo, "github:pleme-io/caixa-teia ");
4727 assert!(
4728 reason.contains("whitespace"),
4729 "reason must surface the whitespace arm, got {reason:?}"
4730 );
4731 }
4732
4733 #[test]
4734 fn validate_rejects_git_fonte_with_repo_starting_with_dash() {
4735 // The canonical CLI-argument-injection footgun at the `git clone`
4736 // subprocess boundary — `:repo "-upload-pack=evil"` makes git's
4737 // argv parser read the value as a CLI flag, escaping the
4738 // subprocess argument boundary. The `--` separator workaround
4739 // does not fix the typed slot's accepted set; the gate rejects
4740 // the shape upstream at validate time so the resolver never
4741 // invokes a `git clone -…` subprocess.
4742 let d = dep_with_fonte(DepSource::Git {
4743 repo: "-upload-pack=evil".into(),
4744 tag: Some("v0.1.0".into()),
4745 rev: None,
4746 branch: None,
4747 });
4748 let err = d.validate().unwrap_err();
4749 let DepError::FonteRepoShape { repo, reason, .. } = err else {
4750 panic!("expected FonteRepoShape, got other variant");
4751 };
4752 assert_eq!(repo, "-upload-pack=evil");
4753 assert!(
4754 reason.contains("must not start with `-`"),
4755 "reason must surface the leading-`-` arm, got {reason:?}"
4756 );
4757 }
4758
4759 #[test]
4760 fn validate_rejects_git_fonte_with_repo_carrying_embedded_newline() {
4761 // The canonical paste-from-multiline-doc footgun — a `:repo`
4762 // string with an embedded `\n` silently breaks git's URL parser
4763 // and is a class of CRLF-injection at the subprocess-argument
4764 // boundary. Caught by the control-char arm (0x0A < 0x20).
4765 let d = dep_with_fonte(DepSource::Git {
4766 repo: "github:pleme-io/caixa-teia\nrm -rf /".into(),
4767 tag: Some("v0.1.0".into()),
4768 rev: None,
4769 branch: None,
4770 });
4771 let err = d.validate().unwrap_err();
4772 let DepError::FonteRepoShape { reason, .. } = err else {
4773 panic!("expected FonteRepoShape, got other variant");
4774 };
4775 assert!(
4776 reason.contains("control character"),
4777 "reason must surface the control-char arm, got {reason:?}"
4778 );
4779 }
4780
4781 #[test]
4782 fn validate_rejects_git_fonte_with_repo_carrying_tab() {
4783 // Tab is the sibling whitespace footgun (the canonical
4784 // copy-from-aligned-table paste); pinned separately from the
4785 // space arm so a future relaxation that only catches one
4786 // surfaces here.
4787 let d = dep_with_fonte(DepSource::Git {
4788 repo: "github:pleme-io/caixa-teia\t".into(),
4789 tag: Some("v0.1.0".into()),
4790 rev: None,
4791 branch: None,
4792 });
4793 let err = d.validate().unwrap_err();
4794 assert!(
4795 matches!(
4796 err,
4797 DepError::FonteRepoShape { ref reason, .. }
4798 if reason.contains("whitespace")
4799 ),
4800 "got {err:?}"
4801 );
4802 }
4803
4804 #[test]
4805 fn validate_rejects_git_fonte_with_repo_carrying_non_ascii() {
4806 // IDN hosts must be pre-encoded as Punycode (`xn--…`) — raw
4807 // non-ASCII silently breaks at git's URL parser and round-trips
4808 // inconsistently across NFC/NFD normalization on APFS /
4809 // case-folding filesystems. Same intersection-floor
4810 // [`is_git_ref_name`] enforces on the refname axes.
4811 let d = dep_with_fonte(DepSource::Git {
4812 repo: "https://github.com/pleme-io/café".into(),
4813 tag: Some("v0.1.0".into()),
4814 rev: None,
4815 branch: None,
4816 });
4817 let err = d.validate().unwrap_err();
4818 assert!(
4819 matches!(
4820 err,
4821 DepError::FonteRepoShape { ref reason, .. }
4822 if reason.contains("non-ASCII")
4823 ),
4824 "got {err:?}"
4825 );
4826 }
4827
4828 #[test]
4829 fn validate_rejects_git_fonte_with_repo_carrying_fragment_anchor() {
4830 // The fail-before-pass-after pin for the canonical paste-from-
4831 // browser-address-bar footgun on `:repo`: an author copies a
4832 // GitHub permalink to a README anchor / line-permalink and
4833 // forgets to trim the `#fragment` tail. Until this arm landed
4834 // `:repo "https://github.com/pleme-io/caixa-teia#readme"`
4835 // silently passed every prior arm (no whitespace, no control
4836 // chars, no non-ASCII, contains a `:`, doesn't start with `-`
4837 // or `:`), libcurl's URL parser stripped the `#readme` tail
4838 // before opening the HTTPS transport, and the lacre embedded
4839 // the value verbatim in its per-dep BLAKE3 closure — two
4840 // authors whose values differ only in their fragment anchor
4841 // (`#readme` vs `#L42`) resolve to the byte-identical upstream
4842 // `git clone` but lock to two distinct lacres, defeating the
4843 // THEORY.md §V.2 render-determinism contract. Same value-shape
4844 // axis-floor every peer typed surface enforces; peer `:fonte
4845 // :tag` / `:fonte :branch` already reject the byte-class through
4846 // `is_git_ref_name`'s alphabet (refs are leaf identifiers, no
4847 // URL grammar admitted) and `:entrada :paths` rejects `#` as
4848 // part of `is_gateway_api_http_path`'s RFC-3986-reserved set.
4849 let d = dep_with_fonte(DepSource::Git {
4850 repo: "https://github.com/pleme-io/caixa-teia#readme".into(),
4851 tag: Some("v0.1.0".into()),
4852 rev: None,
4853 branch: None,
4854 });
4855 let err = d.validate().unwrap_err();
4856 let DepError::FonteRepoShape { nome, repo, reason } = err else {
4857 panic!("expected FonteRepoShape, got other variant");
4858 };
4859 assert_eq!(nome, "caixa-teia");
4860 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia#readme");
4861 assert!(
4862 reason.contains("must not contain `#`"),
4863 "reason must surface the fragment-`#` arm, got {reason:?}"
4864 );
4865 assert!(
4866 reason.contains("fragment"),
4867 "reason must name the URL fragment grammar, got {reason:?}"
4868 );
4869 }
4870
4871 #[test]
4872 fn validate_rejects_git_fonte_with_repo_carrying_flake_ref_fragment() {
4873 // The symmetric paste-from-Nix-flake-ref footgun — an author
4874 // confuses the Nix flake-reference idiom (`github:foo/
4875 // bar#packageName`, where `#packageName` selects a flake
4876 // output) with the bare git `:repo` shape. The pleme-io
4877 // substrate authors compose flakes downstream of caixa
4878 // (caixa-flake renders a flake.nix), so the cross-idiom leak
4879 // is the canonical near-miss: the author writes the
4880 // flake-ref shape into a git `:repo` slot. Pinned separately
4881 // from the HTTPS-anchor arm so a future relaxation that
4882 // narrows to one URL scheme surfaces here.
4883 let d = dep_with_fonte(DepSource::Git {
4884 repo: "github:pleme-io/caixa-teia#caixa-teia".into(),
4885 tag: Some("v0.1.0".into()),
4886 rev: None,
4887 branch: None,
4888 });
4889 let err = d.validate().unwrap_err();
4890 let DepError::FonteRepoShape { reason, .. } = err else {
4891 panic!("expected FonteRepoShape, got other variant");
4892 };
4893 assert!(
4894 reason.contains("must not contain `#`"),
4895 "reason must surface the fragment-`#` arm, got {reason:?}"
4896 );
4897 assert!(
4898 reason.contains("Nix flake"),
4899 "reason must name the Nix-flake-ref cross-idiom footgun, got {reason:?}"
4900 );
4901 }
4902
4903 #[test]
4904 fn validate_rejects_git_fonte_with_repo_carrying_query_string() {
4905 // The fail-before-pass-after pin for the canonical paste-from-
4906 // browser-address-bar footgun on `:repo` (peer with the
4907 // a68f818 fragment-`#` arm on the same axis). An author
4908 // copies a GitHub tab deep-link out of the address bar and
4909 // forgets to trim the `?tab=…` query tail. Until this arm
4910 // landed `:repo "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"`
4911 // silently passed every prior arm (no whitespace, no control
4912 // chars, no non-ASCII, no `#` fragment, contains a `:`,
4913 // doesn't start with `-` or `:`); GitHub silently ignored
4914 // the `?query` tail and served the same repo regardless;
4915 // the lacre embedded the value verbatim in its per-dep
4916 // BLAKE3 closure — two authors whose values differ only in
4917 // their query tail (`?tab=readme-ov-file` vs `?ref=main` vs
4918 // `?utm_source=twitter`) resolve to the byte-identical
4919 // upstream `git clone` but lock to two distinct lacres,
4920 // defeating the THEORY.md §V.2 render-determinism contract
4921 // on the same axis the `#` fragment arm closes. Same value-
4922 // shape axis-floor every peer typed surface enforces; peer
4923 // `:fonte :tag` / `:fonte :branch` already reject the byte-
4924 // class through `is_git_ref_name`'s alphabet (refspec glob
4925 // wildcards, caixa-core/src/render.rs:1426) and `:entrada
4926 // :paths` rejects `?` as the query separator in
4927 // `is_gateway_api_http_path` (caixa-core/src/render.rs:473).
4928 let d = dep_with_fonte(DepSource::Git {
4929 repo: "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file".into(),
4930 tag: Some("v0.1.0".into()),
4931 rev: None,
4932 branch: None,
4933 });
4934 let err = d.validate().unwrap_err();
4935 let DepError::FonteRepoShape { nome, repo, reason } = err else {
4936 panic!("expected FonteRepoShape, got other variant");
4937 };
4938 assert_eq!(nome, "caixa-teia");
4939 assert_eq!(
4940 repo,
4941 "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"
4942 );
4943 assert!(
4944 reason.contains("must not contain `?`"),
4945 "reason must surface the query-`?` arm, got {reason:?}"
4946 );
4947 assert!(
4948 reason.contains("query"),
4949 "reason must name the URL query grammar, got {reason:?}"
4950 );
4951 }
4952
4953 #[test]
4954 fn validate_rejects_git_fonte_with_repo_carrying_utm_tracker() {
4955 // The symmetric paste-from-social-share footgun — an author
4956 // copies a repo URL out of a Slack unfurl / Twitter share /
4957 // newsletter link / Discord embed and forgets to trim the
4958 // `?utm_source=…` / `?utm_medium=…` / `?utm_campaign=…`
4959 // campaign-tracker tail. Every major social-share / unfurl /
4960 // newsletter platform appends these UTM parameters; the
4961 // canonical near-miss on the `:repo` axis. Pinned separately
4962 // from the GitHub-tab-deep-link arm so a future relaxation
4963 // that narrows to one query-parameter class surfaces here.
4964 let d = dep_with_fonte(DepSource::Git {
4965 repo: "https://github.com/pleme-io/caixa-teia?utm_source=twitter&utm_campaign=launch"
4966 .into(),
4967 tag: Some("v0.1.0".into()),
4968 rev: None,
4969 branch: None,
4970 });
4971 let err = d.validate().unwrap_err();
4972 let DepError::FonteRepoShape { reason, .. } = err else {
4973 panic!("expected FonteRepoShape, got other variant");
4974 };
4975 assert!(
4976 reason.contains("must not contain `?`"),
4977 "reason must surface the query-`?` arm, got {reason:?}"
4978 );
4979 assert!(
4980 reason.contains("campaign-tracker"),
4981 "reason must name the campaign-tracker paste footgun, got {reason:?}"
4982 );
4983 }
4984
4985 #[test]
4986 fn fonte_repo_fragment_fires_before_query_when_fragment_first() {
4987 // Cascade pin: the fragment-`#` arm and the query-`?` arm are
4988 // both per-byte arms inside the same `for &b in s.as_bytes()`
4989 // loop, so the byte that appears first in the value's byte
4990 // order wins. A `:repo "https://github.com/p/x#readme?ref=main"`
4991 // (fragment before query — unusual URL-grammar but value-
4992 // disjoint at byte level) carries both `#` and `?`; the `#`
4993 // byte appears first, so the fragment-`#` arm fires, surfacing
4994 // the more self-locating diagnostic on the byte the author
4995 // pasted earliest in the URL. Mirrors the peer cascade
4996 // discipline `fonte_repo_control_char_fires_before_fragment`
4997 // pins on the prior `:repo` byte-class arm.
4998 let d = dep_with_fonte(DepSource::Git {
4999 repo: "https://github.com/pleme-io/caixa-teia#readme?ref=main".into(),
5000 tag: Some("v0.1.0".into()),
5001 rev: None,
5002 branch: None,
5003 });
5004 let err = d.validate().unwrap_err();
5005 let DepError::FonteRepoShape { reason, .. } = err else {
5006 panic!("expected FonteRepoShape, got other variant");
5007 };
5008 assert!(
5009 reason.contains("must not contain `#`"),
5010 "reason must surface the fragment-`#` arm (fires before query-`?` when \
5011 `#` byte appears first in value), got {reason:?}"
5012 );
5013 }
5014
5015 #[test]
5016 fn fonte_repo_control_char_fires_before_fragment() {
5017 // Cascade pin: the control-char arm structurally precedes the
5018 // fragment-`#` arm. A value like `"github:p/x\n#readme"` probes
5019 // positive on both arms (contains LF and `#`), but the narrower
5020 // POSIX-syscall-rejected / CRLF-injection-class diagnostic
5021 // (`control character`) wins so the author sees the more
5022 // self-locating arm first. Mirrors the peer cascade discipline
5023 // every prior `:repo` byte-class arm establishes.
5024 let d = dep_with_fonte(DepSource::Git {
5025 repo: "github:pleme-io/caixa-teia\n#readme".into(),
5026 tag: Some("v0.1.0".into()),
5027 rev: None,
5028 branch: None,
5029 });
5030 let err = d.validate().unwrap_err();
5031 let DepError::FonteRepoShape { reason, .. } = err else {
5032 panic!("expected FonteRepoShape, got other variant");
5033 };
5034 assert!(
5035 reason.contains("control character"),
5036 "reason must surface the control-char arm, got {reason:?}"
5037 );
5038 }
5039
5040 #[test]
5041 fn validate_rejects_git_fonte_with_repo_carrying_embedded_backslash() {
5042 // The fail-before-pass-after pin for the canonical Windows-
5043 // file-path-confusion footgun on `:repo` (peer with the 3a4e1d7
5044 // backslash arm on the sibling `:caminho` path-fonte axis).
5045 // An author pastes a Windows Explorer address-bar / PowerShell
5046 // `Get-Location` output into a `file://` URL slot, producing
5047 // `file:///C:\Users\me\caixa-teia`. Until this arm landed the
5048 // value silently passed every prior arm (no whitespace, no
5049 // control chars, no non-ASCII, no `#`, no `?`, doesn't start
5050 // with `-` or `:`); libcurl's URL parser silently translates
5051 // `\` → `/` on some platforms and refuses it on others, so
5052 // the byte rides verbatim into the lacre's per-dep content-
5053 // address but is silently rewritten / rejected at the wire —
5054 // two authors whose `:repo` values differ only in backslash-
5055 // vs-forward-slash (`file:///C:\path` vs `file:///C:/path`)
5056 // resolve to the byte-identical local clone but lock to two
5057 // distinct BLAKE3 closures, defeating the THEORY.md §V.2
5058 // render-determinism contract on the same axis the `#`
5059 // fragment and `?` query arms close. Same value-shape axis-
5060 // floor every peer typed surface enforces; the `:caminho`
5061 // 3a4e1d7 arm closes the same byte on the path-fonte axis.
5062 let d = dep_with_fonte(DepSource::Git {
5063 repo: "file:///C:\\Users\\me\\caixa-teia".into(),
5064 tag: Some("v0.1.0".into()),
5065 rev: None,
5066 branch: None,
5067 });
5068 let err = d.validate().unwrap_err();
5069 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5070 panic!("expected FonteRepoShape, got other variant");
5071 };
5072 assert_eq!(nome, "caixa-teia");
5073 assert_eq!(repo, "file:///C:\\Users\\me\\caixa-teia");
5074 assert!(
5075 reason.contains("must not contain `\\`"),
5076 "reason must surface the backslash-`\\` arm, got {reason:?}"
5077 );
5078 assert!(
5079 reason.contains("Windows"),
5080 "reason must name the Windows-path-confusion footgun, got {reason:?}"
5081 );
5082 }
5083
5084 #[test]
5085 fn validate_rejects_git_fonte_with_repo_carrying_mangled_https_backslashes() {
5086 // The symmetric Win32-shell-mangled-slashes footgun — an author
5087 // copies `https://github.com/foo/bar` into a Win32 shell that
5088 // rewrites every `/` to `\` (the canonical `cmd.exe` path-
5089 // separator-coercion bug), pastes the result into a `:repo`
5090 // slot, and produces `https:\\github.com\foo\bar`. Pinned
5091 // separately from the `file://` Explorer-paste arm so a future
5092 // relaxation that narrows to one URL scheme surfaces here.
5093 let d = dep_with_fonte(DepSource::Git {
5094 repo: "https:\\\\github.com\\pleme-io\\caixa-teia".into(),
5095 tag: Some("v0.1.0".into()),
5096 rev: None,
5097 branch: None,
5098 });
5099 let err = d.validate().unwrap_err();
5100 let DepError::FonteRepoShape { reason, .. } = err else {
5101 panic!("expected FonteRepoShape, got other variant");
5102 };
5103 assert!(
5104 reason.contains("must not contain `\\`"),
5105 "reason must surface the backslash-`\\` arm, got {reason:?}"
5106 );
5107 assert!(
5108 reason.contains("path separator") || reason.contains("path-segment separator"),
5109 "reason must name the URL path-segment separator grammar, got {reason:?}"
5110 );
5111 }
5112
5113 #[test]
5114 fn fonte_repo_fragment_fires_before_backslash_when_fragment_first() {
5115 // Cascade pin: the fragment-`#` arm and the backslash-`\` arm
5116 // are both per-byte arms inside the same `for &b in s.as_bytes()`
5117 // loop, so the byte that appears first in the value's byte order
5118 // wins. A `:repo "https://github.com/p/x#readme\\foo"` carries
5119 // both `#` and `\`; the `#` byte appears first, so the fragment-
5120 // `#` arm fires, surfacing the more self-locating diagnostic on
5121 // the byte the author pasted earliest in the URL. Mirrors the
5122 // peer cascade discipline `fonte_repo_fragment_fires_before_query_when_fragment_first`
5123 // pins on the prior `:repo` byte-class arm.
5124 let d = dep_with_fonte(DepSource::Git {
5125 repo: "https://github.com/pleme-io/caixa-teia#readme\\foo".into(),
5126 tag: Some("v0.1.0".into()),
5127 rev: None,
5128 branch: None,
5129 });
5130 let err = d.validate().unwrap_err();
5131 let DepError::FonteRepoShape { reason, .. } = err else {
5132 panic!("expected FonteRepoShape, got other variant");
5133 };
5134 assert!(
5135 reason.contains("must not contain `#`"),
5136 "reason must surface the fragment-`#` arm (fires before backslash-`\\` when \
5137 `#` byte appears first in value), got {reason:?}"
5138 );
5139 }
5140
5141 #[test]
5142 fn validate_rejects_git_fonte_with_repo_carrying_uri_template_placeholder() {
5143 // The fail-before-pass-after pin for the canonical URI Template
5144 // (RFC 6570) placeholder footgun on `:repo`. An author copies a
5145 // README quick-start snippet / OpenAPI `servers:` URL / Helm
5146 // chart `home:` template that carries unresolved
5147 // `{org}` / `{repo}` placeholders and pastes the raw template
5148 // into the `:repo` slot, expecting the substrate to resolve the
5149 // placeholder downstream. Until this arm landed the value
5150 // silently passed every prior arm (no whitespace, no control
5151 // chars, no non-ASCII, no `#`, no `?`, no `\`, doesn't start
5152 // with `-` or `:`); libcurl percent-encodes `{` / `}` to `%7B`
5153 // / `%7D` on the wire, so the byte rides verbatim into the
5154 // lacre's per-dep content-address but round-trips inconsistently
5155 // between the lacre's per-dep content-address and the
5156 // resolver's `git clone <repo>` invocation, defeating the
5157 // THEORY.md §V.2 render-determinism contract on the same axis
5158 // the `#` fragment, `?` query, and `\` backslash arms close;
5159 // every git porcelain entry-point additionally fetches a
5160 // nonexistent literal-`{placeholder}`-named path far from the
5161 // source caixa.lisp.
5162 let d = dep_with_fonte(DepSource::Git {
5163 repo: "https://github.com/{org}/caixa-teia".into(),
5164 tag: Some("v0.1.0".into()),
5165 rev: None,
5166 branch: None,
5167 });
5168 let err = d.validate().unwrap_err();
5169 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5170 panic!("expected FonteRepoShape, got other variant");
5171 };
5172 assert_eq!(nome, "caixa-teia");
5173 assert_eq!(repo, "https://github.com/{org}/caixa-teia");
5174 assert!(
5175 reason.contains("must not contain `{`"),
5176 "reason must surface the open-brace `{{` arm, got {reason:?}"
5177 );
5178 assert!(
5179 reason.contains("URI Template") || reason.contains("RFC 6570"),
5180 "reason must name the RFC 6570 URI Template grammar, got {reason:?}"
5181 );
5182 }
5183
5184 #[test]
5185 fn validate_rejects_git_fonte_with_repo_carrying_handlebars_doubled_brace() {
5186 // The symmetric Mustache / Handlebars doubled-brace
5187 // substitution-form footgun every CI / IaC templating engine
5188 // (Argo Workflows, Jinja2, Liquid, Vue / Angular interpolation,
5189 // GitHub Actions `${{ … }}` even though Actions uses `${{`) /
5190 // chart README quick-start snippet emits. Pinned separately
5191 // from the single-`{` `{org}` arm so a future relaxation that
5192 // narrows to one substitution-form surfaces here.
5193 let d = dep_with_fonte(DepSource::Git {
5194 repo: "https://github.com/{{org}}/caixa-teia".into(),
5195 tag: Some("v0.1.0".into()),
5196 rev: None,
5197 branch: None,
5198 });
5199 let err = d.validate().unwrap_err();
5200 let DepError::FonteRepoShape { reason, .. } = err else {
5201 panic!("expected FonteRepoShape, got other variant");
5202 };
5203 assert!(
5204 reason.contains("must not contain `{`"),
5205 "reason must surface the open-brace `{{` arm, got {reason:?}"
5206 );
5207 }
5208
5209 #[test]
5210 fn validate_rejects_git_fonte_with_repo_carrying_closing_brace_only() {
5211 // Asymmetric `}`-only shape — covers the closing-brace-by-
5212 // itself footgun (an author truncated `{org}/{repo}` mid-edit
5213 // and left a trailing `}` from the prior template fragment,
5214 // or pasted a value that included a closing brace from a
5215 // surrounding shell context). Pinned to ensure the predicate
5216 // refuses each brace independently rather than only when both
5217 // appear — a future regression that ANDs the two byte tests
5218 // surfaces here.
5219 let d = dep_with_fonte(DepSource::Git {
5220 repo: "https://github.com/pleme-io/caixa-teia}".into(),
5221 tag: Some("v0.1.0".into()),
5222 rev: None,
5223 branch: None,
5224 });
5225 let err = d.validate().unwrap_err();
5226 let DepError::FonteRepoShape { reason, .. } = err else {
5227 panic!("expected FonteRepoShape, got other variant");
5228 };
5229 assert!(
5230 reason.contains("must not contain `}`"),
5231 "reason must surface the close-brace `}}` arm, got {reason:?}"
5232 );
5233 }
5234
5235 #[test]
5236 fn fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first() {
5237 // Cascade pin: the fragment-`#` arm and the template-`{` /
5238 // `}` arm are both per-byte arms inside the same
5239 // `for &b in s.as_bytes()` loop, so the byte that appears
5240 // first in the value's byte order wins. A `:repo
5241 // "https://github.com/p/x#readme{org}"` carries both `#` and
5242 // `{`; the `#` byte appears first, so the fragment-`#` arm
5243 // fires, surfacing the more self-locating diagnostic on the
5244 // byte the author pasted earliest in the URL. Mirrors the
5245 // peer cascade discipline `fonte_repo_fragment_fires_before_backslash_when_fragment_first`
5246 // pins on the prior `:repo` byte-class arm.
5247 let d = dep_with_fonte(DepSource::Git {
5248 repo: "https://github.com/pleme-io/caixa-teia#readme{org}".into(),
5249 tag: Some("v0.1.0".into()),
5250 rev: None,
5251 branch: None,
5252 });
5253 let err = d.validate().unwrap_err();
5254 let DepError::FonteRepoShape { reason, .. } = err else {
5255 panic!("expected FonteRepoShape, got other variant");
5256 };
5257 assert!(
5258 reason.contains("must not contain `#`"),
5259 "reason must surface the fragment-`#` arm (fires before template-`{{` when \
5260 `#` byte appears first in value), got {reason:?}"
5261 );
5262 }
5263
5264 #[test]
5265 fn validate_rejects_git_fonte_with_repo_carrying_output_redirection() {
5266 // The fail-before-pass-after pin for the canonical
5267 // shell-output-redirection footgun on `:repo`: an author
5268 // pastes a shell-pipeline tail (`git clone <repo> > build.log`
5269 // / `… >output.txt`) into the `:repo` slot without trimming
5270 // the redirect. Until this arm landed the value silently
5271 // passed every prior arm (no whitespace, no control chars,
5272 // no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, doesn't
5273 // start with `-` or `:`); RFC 3986 §2 lists `<` / `>` in the
5274 // 'delims' / 'unwise' set and the WHATWG URL spec's fragment
5275 // percent-encode set maps `>` → `%3E` on the wire, so the
5276 // byte rides verbatim into the lacre's per-dep BLAKE3 closure
5277 // but is silently rewritten or rejected at libcurl's URL-
5278 // parser layer — two authors whose values differ only in
5279 // their redirect tail (`>build.log` vs nothing) resolve to
5280 // the byte-identical upstream `git clone` but lock to two
5281 // distinct lacres, defeating the THEORY.md §V.2 render-
5282 // determinism contract. Peer with the `:caminho` axis's
5283 // `FonteCaminhoShellRedirection` arm (e457141) on the sibling
5284 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5285 // byte RFC-3986-reserved set on `:entrada :paths`.
5286 let d = dep_with_fonte(DepSource::Git {
5287 repo: "https://github.com/pleme-io/caixa-teia>build.log".into(),
5288 tag: Some("v0.1.0".into()),
5289 rev: None,
5290 branch: None,
5291 });
5292 let err = d.validate().unwrap_err();
5293 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5294 panic!("expected FonteRepoShape, got other variant");
5295 };
5296 assert_eq!(nome, "caixa-teia");
5297 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia>build.log");
5298 assert!(
5299 reason.contains("must not contain `>`"),
5300 "reason must surface the output-redirection `>` arm, got {reason:?}"
5301 );
5302 assert!(
5303 reason.contains("redirection") || reason.contains("'delims'"),
5304 "reason must name the shell-redirection / RFC-3986-unwise rationale, got {reason:?}"
5305 );
5306 }
5307
5308 #[test]
5309 fn validate_rejects_git_fonte_with_repo_carrying_input_redirection() {
5310 // The symmetric shell-input-redirection footgun — an author
5311 // pastes a shell-pipeline head (`git clone <input.url` /
5312 // `cat <README.md`) into the `:repo` slot. Pinned separately
5313 // from the `>`-output arm so a future relaxation that only
5314 // catches one of the two redirect bytes surfaces here. Peer
5315 // with the `:caminho` axis's `FonteCaminhoShellRedirection`
5316 // arm which closes both `<` and `>` under the same banner.
5317 let d = dep_with_fonte(DepSource::Git {
5318 repo: "https://github.com/pleme-io/caixa-teia<input.url".into(),
5319 tag: Some("v0.1.0".into()),
5320 rev: None,
5321 branch: None,
5322 });
5323 let err = d.validate().unwrap_err();
5324 let DepError::FonteRepoShape { reason, .. } = err else {
5325 panic!("expected FonteRepoShape, got other variant");
5326 };
5327 assert!(
5328 reason.contains("must not contain `<`"),
5329 "reason must surface the input-redirection `<` arm, got {reason:?}"
5330 );
5331 assert!(
5332 reason.contains("RFC 3986") || reason.contains("'unwise'"),
5333 "reason must name the RFC 3986 'unwise' grammar, got {reason:?}"
5334 );
5335 }
5336
5337 #[test]
5338 fn validate_rejects_git_fonte_with_repo_carrying_backtick_command_substitution() {
5339 // The fail-before-pass-after pin for the canonical
5340 // paste-from-shell-prompt-with-backticked-substitution footgun
5341 // on `:repo` (peer with the c4d62b3 backtick arm on the sibling
5342 // `:caminho` path-fonte axis). An author pastes a URL whose
5343 // segment carries a backticked command-substitution wrapper
5344 // (`` `whoami` ``, `` `git config user.name` ``, `` `pwd` ``)
5345 // from a doc / README quick-start snippet that expected the
5346 // substrate to substitute the value downstream. Until this arm
5347 // landed the value silently passed every prior arm (no
5348 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5349 // no `\`, no `{`/`}`, no `<`/`>`, doesn't start with `-` or
5350 // `:`); RFC 3986 §2 lists the backtick byte in the 'delims' /
5351 // 'unwise' set and the WHATWG URL spec's fragment percent-
5352 // encode set maps `` ` `` → `%60` on the wire, so the byte
5353 // rides verbatim into the lacre's per-dep BLAKE3 closure but
5354 // is silently rewritten or rejected at libcurl's URL-parser
5355 // layer — two authors whose values differ only in their
5356 // backtick wrapper (`` `whoami` `` vs nothing) resolve to the
5357 // byte-identical upstream `git clone` but lock to two distinct
5358 // lacres, defeating the THEORY.md §V.2 render-determinism
5359 // contract. Peer with the `:caminho` axis's
5360 // `FonteCaminhoShellCommandSubstitution` arm (c4d62b3) on the
5361 // sibling path-fonte axis, and `is_gateway_api_http_path`'s
5362 // eleven-byte RFC-3986-reserved set on `:entrada :paths`.
5363 let d = dep_with_fonte(DepSource::Git {
5364 repo: "https://github.com/pleme-io/`whoami`/caixa-teia".into(),
5365 tag: Some("v0.1.0".into()),
5366 rev: None,
5367 branch: None,
5368 });
5369 let err = d.validate().unwrap_err();
5370 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5371 panic!("expected FonteRepoShape, got other variant");
5372 };
5373 assert_eq!(nome, "caixa-teia");
5374 assert_eq!(repo, "https://github.com/pleme-io/`whoami`/caixa-teia");
5375 assert!(
5376 reason.contains("must not contain `` ` ``"),
5377 "reason must surface the backtick command-substitution arm, got {reason:?}"
5378 );
5379 assert!(
5380 reason.contains("command-substitution") || reason.contains("'unwise'"),
5381 "reason must name the shell-command-substitution / RFC-3986-unwise rationale, \
5382 got {reason:?}"
5383 );
5384 }
5385
5386 #[test]
5387 fn fonte_repo_fragment_fires_before_backtick_when_fragment_first() {
5388 // Cascade pin: the fragment-`#` arm and the backtick command-
5389 // substitution arm are both per-byte arms inside the same
5390 // `for &b in s.as_bytes()` loop, so the byte that appears first
5391 // in the value's byte order wins. A `:repo
5392 // "https://github.com/p/x#readme/`whoami`"` carries both `#`
5393 // and backtick; the `#` byte appears first, so the fragment-
5394 // `#` arm fires, surfacing the more self-locating diagnostic
5395 // on the byte the author pasted earliest in the URL. Mirrors
5396 // the peer cascade discipline
5397 // `fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first`
5398 // pins on the prior `:repo` byte-class arm.
5399 let d = dep_with_fonte(DepSource::Git {
5400 repo: "https://github.com/pleme-io/caixa-teia#readme/`whoami`".into(),
5401 tag: Some("v0.1.0".into()),
5402 rev: None,
5403 branch: None,
5404 });
5405 let err = d.validate().unwrap_err();
5406 let DepError::FonteRepoShape { reason, .. } = err else {
5407 panic!("expected FonteRepoShape, got other variant");
5408 };
5409 assert!(
5410 reason.contains("must not contain `#`"),
5411 "reason must surface the fragment-`#` arm (fires before backtick when `#` byte \
5412 appears first in value), got {reason:?}"
5413 );
5414 }
5415
5416 #[test]
5417 fn fonte_repo_shell_redirection_fires_before_backtick_when_redirection_first() {
5418 // Cascade pin: the shell-redirection `<` / `>` arm and the
5419 // backtick command-substitution arm are both per-byte arms
5420 // inside the same `for &b in s.as_bytes()` loop, so the byte
5421 // that appears first in the value's byte order wins. A `:repo
5422 // "https://github.com/p/x>build.log/`whoami`"` carries both
5423 // `>` and backtick; the `>` byte appears first, so the
5424 // shell-redirection arm fires, surfacing the more self-
5425 // locating diagnostic on the byte the author pasted earliest
5426 // in the URL. Pins the natural-order cascade so a future
5427 // reorder of the per-byte arms surfaces here.
5428 let d = dep_with_fonte(DepSource::Git {
5429 repo: "https://github.com/pleme-io/caixa-teia>build.log/`whoami`".into(),
5430 tag: Some("v0.1.0".into()),
5431 rev: None,
5432 branch: None,
5433 });
5434 let err = d.validate().unwrap_err();
5435 let DepError::FonteRepoShape { reason, .. } = err else {
5436 panic!("expected FonteRepoShape, got other variant");
5437 };
5438 assert!(
5439 reason.contains("must not contain `>`"),
5440 "reason must surface the shell-redirection `>` arm (fires before backtick when \
5441 `>` byte appears first in value), got {reason:?}"
5442 );
5443 }
5444
5445 #[test]
5446 fn fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first() {
5447 // Cascade pin: the fragment-`#` arm and the shell-redirection
5448 // `<` / `>` arm are both per-byte arms inside the same
5449 // `for &b in s.as_bytes()` loop, so the byte that appears
5450 // first in the value's byte order wins. A `:repo
5451 // "https://github.com/p/x#readme>build.log"` carries both
5452 // `#` and `>`; the `#` byte appears first, so the fragment-
5453 // `#` arm fires, surfacing the more self-locating diagnostic
5454 // on the byte the author pasted earliest in the URL. Mirrors
5455 // the peer cascade discipline
5456 // `fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first`
5457 // pins on the prior `:repo` byte-class arm.
5458 let d = dep_with_fonte(DepSource::Git {
5459 repo: "https://github.com/pleme-io/caixa-teia#readme>build.log".into(),
5460 tag: Some("v0.1.0".into()),
5461 rev: None,
5462 branch: None,
5463 });
5464 let err = d.validate().unwrap_err();
5465 let DepError::FonteRepoShape { reason, .. } = err else {
5466 panic!("expected FonteRepoShape, got other variant");
5467 };
5468 assert!(
5469 reason.contains("must not contain `#`"),
5470 "reason must surface the fragment-`#` arm (fires before shell-redirection `>` when \
5471 `#` byte appears first in value), got {reason:?}"
5472 );
5473 }
5474
5475 #[test]
5476 fn validate_rejects_git_fonte_with_repo_carrying_shell_pipe() {
5477 // The fail-before-pass-after pin for the canonical
5478 // paste-from-shell-prompt-with-piped-pipeline footgun on
5479 // `:repo` (peer with the 124106f pipe arm on the sibling
5480 // `:caminho` path-fonte axis). An author pastes a shell
5481 // pipeline (`git clone <url> | tee build.log`,
5482 // `git ls-remote <url> | head`) into the `:repo` slot,
5483 // forgetting to trim the `| <consumer>` tail. Until this arm
5484 // landed the value silently passed every prior arm (no
5485 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5486 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, doesn't start
5487 // with `-` or `:`); RFC 3986 §2 lists the pipe byte in the
5488 // 'unwise' set and the WHATWG URL spec's fragment percent-
5489 // encode set maps `|` → `%7C` on the wire, so the byte rides
5490 // verbatim into the lacre's per-dep BLAKE3 closure but is
5491 // silently rewritten or rejected at libcurl's URL-parser
5492 // layer — two authors whose values differ only in their pipe
5493 // tail (`|tee build.log` vs nothing) resolve to the byte-
5494 // identical upstream `git clone` but lock to two distinct
5495 // lacres, defeating the THEORY.md §V.2 render-determinism
5496 // contract. Peer with the `:caminho` axis's
5497 // `FonteCaminhoShellPipe` arm (124106f) on the sibling path-
5498 // fonte axis, and `is_gateway_api_http_path`'s eleven-byte
5499 // RFC-3986-reserved set on `:entrada :paths`.
5500 let d = dep_with_fonte(DepSource::Git {
5501 repo: "https://github.com/pleme-io/caixa-teia|tee build.log".into(),
5502 tag: Some("v0.1.0".into()),
5503 rev: None,
5504 branch: None,
5505 });
5506 let err = d.validate().unwrap_err();
5507 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5508 panic!("expected FonteRepoShape, got other variant");
5509 };
5510 assert_eq!(nome, "caixa-teia");
5511 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia|tee build.log");
5512 assert!(
5513 reason.contains("must not contain `|`"),
5514 "reason must surface the shell-pipe arm, got {reason:?}"
5515 );
5516 assert!(
5517 reason.contains("pipe") || reason.contains("'unwise'"),
5518 "reason must name the shell-pipe / RFC-3986-unwise rationale, got {reason:?}"
5519 );
5520 }
5521
5522 #[test]
5523 fn fonte_repo_fragment_fires_before_pipe_when_fragment_first() {
5524 // Cascade pin: the fragment-`#` arm and the pipe arm are both
5525 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5526 // so the byte that appears first in the value's byte order
5527 // wins. A `:repo "https://github.com/p/x#readme|tee"` carries
5528 // both `#` and `|`; the `#` byte appears first, so the
5529 // fragment-`#` arm fires, surfacing the more self-locating
5530 // diagnostic on the byte the author pasted earliest in the
5531 // URL. Mirrors the peer cascade discipline
5532 // `fonte_repo_fragment_fires_before_backtick_when_fragment_first`
5533 // pins on the prior `:repo` byte-class arm.
5534 let d = dep_with_fonte(DepSource::Git {
5535 repo: "https://github.com/pleme-io/caixa-teia#readme|tee".into(),
5536 tag: Some("v0.1.0".into()),
5537 rev: None,
5538 branch: None,
5539 });
5540 let err = d.validate().unwrap_err();
5541 let DepError::FonteRepoShape { reason, .. } = err else {
5542 panic!("expected FonteRepoShape, got other variant");
5543 };
5544 assert!(
5545 reason.contains("must not contain `#`"),
5546 "reason must surface the fragment-`#` arm (fires before pipe when `#` byte \
5547 appears first in value), got {reason:?}"
5548 );
5549 }
5550
5551 #[test]
5552 fn fonte_repo_backtick_fires_before_pipe_when_backtick_first() {
5553 // Cascade pin: the backtick arm and the pipe arm are both per-
5554 // byte arms inside the same `for &b in s.as_bytes()` loop, so
5555 // the byte that appears first in the value's byte order wins.
5556 // A `:repo "https://github.com/p/x/`whoami`|tee"` carries both
5557 // `` ` `` and `|`; the backtick byte appears first, so the
5558 // backtick arm fires, surfacing the more self-locating
5559 // diagnostic on the byte the author pasted earliest in the
5560 // URL. Pins the natural-order cascade so a future reorder of
5561 // the per-byte arms surfaces here.
5562 let d = dep_with_fonte(DepSource::Git {
5563 repo: "https://github.com/pleme-io/caixa-teia/`whoami`|tee".into(),
5564 tag: Some("v0.1.0".into()),
5565 rev: None,
5566 branch: None,
5567 });
5568 let err = d.validate().unwrap_err();
5569 let DepError::FonteRepoShape { reason, .. } = err else {
5570 panic!("expected FonteRepoShape, got other variant");
5571 };
5572 assert!(
5573 reason.contains("must not contain `` ` ``"),
5574 "reason must surface the backtick arm (fires before pipe when `` ` `` byte \
5575 appears first in value), got {reason:?}"
5576 );
5577 }
5578
5579 #[test]
5580 fn validate_rejects_git_fonte_with_repo_carrying_shell_command_separator() {
5581 // The fail-before-pass-after pin for the canonical
5582 // paste-from-shell-prompt-with-sequential-command-tail footgun
5583 // on `:repo` (peer with the 05c358e `;` arm on the sibling
5584 // `:caminho` path-fonte axis). An author pastes a shell
5585 // one-liner that chained a cleanup tail after the URL
5586 // (`git clone <url>; rm -rf build`, `git ls-remote <url>;
5587 // echo done`) into the `:repo` slot, forgetting to trim the
5588 // `; <cmd>` tail. Until this arm landed the value silently
5589 // passed every prior `is_git_repo_url` arm (no whitespace, no
5590 // control chars, no non-ASCII, no `#`, no `?`, no `\`, no
5591 // `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, doesn't start with
5592 // `-` or `:`); RFC 3986 §2 lists `;` in the 'sub-delims' /
5593 // reserved set and the WHATWG URL spec's fragment percent-
5594 // encode set maps `;` → `%3B` on the wire, so the byte rides
5595 // verbatim into the lacre's per-dep BLAKE3 closure but is
5596 // silently rewritten at libcurl's URL-parser layer — two
5597 // authors whose values differ only in their sequential-command
5598 // tail (`; rm -rf build` vs nothing) resolve to the byte-
5599 // identical upstream `git clone` but lock to two distinct
5600 // lacres, defeating the THEORY.md §V.2 render-determinism
5601 // contract. Peer with the `:caminho` axis's
5602 // `FonteCaminhoShellSemicolon` arm (05c358e) on the sibling
5603 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5604 // byte RFC-3986-reserved set on `:entrada :paths`.
5605 let d = dep_with_fonte(DepSource::Git {
5606 repo: "https://github.com/pleme-io/caixa-teia; rm -rf build".into(),
5607 tag: Some("v0.1.0".into()),
5608 rev: None,
5609 branch: None,
5610 });
5611 let err = d.validate().unwrap_err();
5612 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5613 panic!("expected FonteRepoShape, got other variant");
5614 };
5615 assert_eq!(nome, "caixa-teia");
5616 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia; rm -rf build");
5617 assert!(
5618 reason.contains("must not contain `;`"),
5619 "reason must surface the shell-command-separator arm, got {reason:?}"
5620 );
5621 assert!(
5622 reason.contains("sequential-command") || reason.contains("'sub-delims'"),
5623 "reason must name the shell-command-separator / RFC-3986-sub-delims \
5624 rationale, got {reason:?}"
5625 );
5626 }
5627
5628 #[test]
5629 fn fonte_repo_fragment_fires_before_semicolon_when_fragment_first() {
5630 // Cascade pin: the fragment-`#` arm and the semicolon arm are
5631 // both per-byte arms inside the same `for &b in s.as_bytes()`
5632 // loop, so the byte that appears first in the value's byte
5633 // order wins. A `:repo "https://github.com/p/x#readme; rm"`
5634 // carries both `#` and `;`; the `#` byte appears first, so the
5635 // fragment-`#` arm fires, surfacing the more self-locating
5636 // diagnostic on the byte the author pasted earliest in the URL.
5637 // Mirrors the peer cascade discipline
5638 // `fonte_repo_fragment_fires_before_pipe_when_fragment_first`
5639 // pins on the prior `:repo` byte-class arm.
5640 let d = dep_with_fonte(DepSource::Git {
5641 repo: "https://github.com/pleme-io/caixa-teia#readme; rm".into(),
5642 tag: Some("v0.1.0".into()),
5643 rev: None,
5644 branch: None,
5645 });
5646 let err = d.validate().unwrap_err();
5647 let DepError::FonteRepoShape { reason, .. } = err else {
5648 panic!("expected FonteRepoShape, got other variant");
5649 };
5650 assert!(
5651 reason.contains("must not contain `#`"),
5652 "reason must surface the fragment-`#` arm (fires before semicolon when `#` \
5653 byte appears first in value), got {reason:?}"
5654 );
5655 }
5656
5657 #[test]
5658 fn fonte_repo_pipe_fires_before_semicolon_when_pipe_first() {
5659 // Cascade pin: the pipe arm and the semicolon arm are both
5660 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5661 // so the byte that appears first in the value's byte order
5662 // wins. A `:repo "https://github.com/p/x|tee; rm"` carries
5663 // both `|` and `;`; the `|` byte appears first, so the
5664 // pipe arm fires, surfacing the more self-locating diagnostic
5665 // on the byte the author pasted earliest in the URL. Pins the
5666 // natural-order cascade so a future reorder of the per-byte
5667 // arms surfaces here.
5668 let d = dep_with_fonte(DepSource::Git {
5669 repo: "https://github.com/pleme-io/caixa-teia|tee; rm".into(),
5670 tag: Some("v0.1.0".into()),
5671 rev: None,
5672 branch: None,
5673 });
5674 let err = d.validate().unwrap_err();
5675 let DepError::FonteRepoShape { reason, .. } = err else {
5676 panic!("expected FonteRepoShape, got other variant");
5677 };
5678 assert!(
5679 reason.contains("must not contain `|`"),
5680 "reason must surface the pipe arm (fires before semicolon when `|` byte \
5681 appears first in value), got {reason:?}"
5682 );
5683 }
5684
5685 #[test]
5686 fn validate_rejects_git_fonte_with_repo_carrying_shell_background() {
5687 // The fail-before-pass-after pin for the canonical
5688 // paste-from-shell-prompt-with-background-launch-tail footgun
5689 // on `:repo` (peer with the e12e4f3 `&` arm on the sibling
5690 // `:caminho` path-fonte axis). An author pastes a shell one-
5691 // liner that detached the clone into the background
5692 // (`git clone <url> & sleep 1`, `git clone <url> && cd …`)
5693 // into the `:repo` slot, forgetting to trim the `& <cmd>` /
5694 // `&& <cmd>` tail. Until this arm landed the value silently
5695 // passed every prior `is_git_repo_url` arm (no whitespace,
5696 // no control chars, no non-ASCII, no `#`, no `?`, no `\`,
5697 // no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
5698 // doesn't start with `-` or `:`); RFC 3986 §2 lists `&` in
5699 // the 'sub-delims' / reserved set and the WHATWG URL spec's
5700 // fragment percent-encode set maps `&` → `%26` on the wire,
5701 // so the byte rides verbatim into the lacre's per-dep
5702 // BLAKE3 closure but is silently rewritten at libcurl's
5703 // URL-parser layer — two authors whose values differ only
5704 // in their background-launch tail (`& sleep 1` vs nothing)
5705 // resolve to the byte-identical upstream `git clone` but
5706 // lock to two distinct lacres, defeating the THEORY.md
5707 // §V.2 render-determinism contract. Peer with the
5708 // `:caminho` axis's `FonteCaminhoShellBackground` arm
5709 // (e12e4f3) on the sibling path-fonte axis, and
5710 // `is_gateway_api_http_path`'s eleven-byte RFC-3986-
5711 // reserved set on `:entrada :paths`.
5712 let d = dep_with_fonte(DepSource::Git {
5713 repo: "https://github.com/pleme-io/caixa-teia&sleep".into(),
5714 tag: Some("v0.1.0".into()),
5715 rev: None,
5716 branch: None,
5717 });
5718 let err = d.validate().unwrap_err();
5719 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5720 panic!("expected FonteRepoShape, got other variant");
5721 };
5722 assert_eq!(nome, "caixa-teia");
5723 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia&sleep");
5724 assert!(
5725 reason.contains("must not contain `&`"),
5726 "reason must surface the shell-background / logical-AND arm, got {reason:?}"
5727 );
5728 assert!(
5729 reason.contains("background-task") || reason.contains("'sub-delims'"),
5730 "reason must name the shell-background / RFC-3986-sub-delims rationale, \
5731 got {reason:?}"
5732 );
5733 }
5734
5735 #[test]
5736 fn validate_rejects_git_fonte_with_repo_carrying_logical_and() {
5737 // The fail-before-pass-after pin for the symmetric `&&`
5738 // logical-AND build-chain paste footgun: an author pastes
5739 // a `git clone <url> && cd <repo>` build-chain one-liner
5740 // and forgets to trim the `&& <cmd>` tail. The `&&` shape
5741 // is the same `&` byte twice in a row; the per-byte arm
5742 // fires on the first `&` it sees. Pinned separately from
5743 // the single-`&` background-launch shape so a future
5744 // diagnostic-surface change that special-cased the
5745 // doubled-byte form surfaces here.
5746 let d = dep_with_fonte(DepSource::Git {
5747 repo: "github:pleme-io/caixa-teia&&echo".into(),
5748 tag: Some("v0.1.0".into()),
5749 rev: None,
5750 branch: None,
5751 });
5752 let err = d.validate().unwrap_err();
5753 let DepError::FonteRepoShape { reason, .. } = err else {
5754 panic!("expected FonteRepoShape, got other variant");
5755 };
5756 assert!(
5757 reason.contains("must not contain `&`"),
5758 "reason must surface the shell-background / logical-AND arm on the doubled-`&&` \
5759 shape too, got {reason:?}"
5760 );
5761 }
5762
5763 #[test]
5764 fn fonte_repo_fragment_fires_before_background_when_fragment_first() {
5765 // Cascade pin: the fragment-`#` arm and the background-`&`
5766 // arm are both per-byte arms inside the same `for &b in
5767 // s.as_bytes()` loop, so the byte that appears first in the
5768 // value's byte order wins. A `:repo
5769 // "https://github.com/p/x#readme & sleep"` carries both `#`
5770 // and `&`; the `#` byte appears first, so the fragment-`#`
5771 // arm fires, surfacing the more self-locating diagnostic on
5772 // the byte the author pasted earliest in the URL. Mirrors
5773 // the peer cascade discipline
5774 // `fonte_repo_fragment_fires_before_semicolon_when_fragment_first`
5775 // on the prior `:repo` byte-class arm.
5776 let d = dep_with_fonte(DepSource::Git {
5777 repo: "https://github.com/pleme-io/caixa-teia#readme&sleep".into(),
5778 tag: Some("v0.1.0".into()),
5779 rev: None,
5780 branch: None,
5781 });
5782 let err = d.validate().unwrap_err();
5783 let DepError::FonteRepoShape { reason, .. } = err else {
5784 panic!("expected FonteRepoShape, got other variant");
5785 };
5786 assert!(
5787 reason.contains("must not contain `#`"),
5788 "reason must surface the fragment-`#` arm (fires before background-`&` when `#` \
5789 byte appears first in value), got {reason:?}"
5790 );
5791 }
5792
5793 #[test]
5794 fn fonte_repo_semicolon_fires_before_background_when_semicolon_first() {
5795 // Cascade pin: the semicolon arm and the background-`&` arm
5796 // are both per-byte arms inside the same `for &b in
5797 // s.as_bytes()` loop, so the byte that appears first in the
5798 // value's byte order wins. A `:repo
5799 // "https://github.com/p/x; rm & sleep"` carries both `;` and
5800 // `&`; the `;` byte appears first, so the semicolon arm
5801 // fires, surfacing the more self-locating diagnostic on the
5802 // byte the author pasted earliest in the URL. Pins the
5803 // natural-order cascade so a future reorder of the per-byte
5804 // arms surfaces here.
5805 let d = dep_with_fonte(DepSource::Git {
5806 repo: "https://github.com/pleme-io/caixa-teia;rm&sleep".into(),
5807 tag: Some("v0.1.0".into()),
5808 rev: None,
5809 branch: None,
5810 });
5811 let err = d.validate().unwrap_err();
5812 let DepError::FonteRepoShape { reason, .. } = err else {
5813 panic!("expected FonteRepoShape, got other variant");
5814 };
5815 assert!(
5816 reason.contains("must not contain `;`"),
5817 "reason must surface the semicolon arm (fires before background-`&` when `;` \
5818 byte appears first in value), got {reason:?}"
5819 );
5820 }
5821
5822 #[test]
5823 fn validate_rejects_git_fonte_with_repo_carrying_shell_variable_expansion() {
5824 // The fail-before-pass-after pin for the canonical
5825 // paste-from-shell-prompt-with-unsubstituted-variable footgun
5826 // on `:repo` (peer with the f4efe9c `$` arm on the sibling
5827 // `:caminho` path-fonte axis). An author pastes a shell one-
5828 // liner that referenced an environment variable
5829 // (`git clone https://github.com/$ORG/x`, `git clone
5830 // github:$USER/repo`) into the `:repo` slot, forgetting to
5831 // substitute the literal value at author time. Until this arm
5832 // landed the value silently passed every prior
5833 // `is_git_repo_url` arm (no whitespace, no control chars, no
5834 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
5835 // no `` ` ``, no `|`, no `;`, no `&`, doesn't start with `-`
5836 // or `:`); RFC 3986 §2 lists `$` in the 'sub-delims' /
5837 // reserved set and the WHATWG URL spec's fragment percent-
5838 // encode set maps `$` → `%24` on the wire, so the byte rides
5839 // verbatim into the lacre's per-dep BLAKE3 closure but is
5840 // silently rewritten at libcurl's URL-parser layer — two
5841 // authors whose values differ only in their `$VAR` /
5842 // `${VAR}` / `$(cmd)` expansion tail resolve to the byte-
5843 // identical upstream `git clone` but lock to two distinct
5844 // lacres, defeating the THEORY.md §V.2 render-determinism
5845 // contract. Beyond determinism, the value is a structural
5846 // host-layout leak: two authors with the same `:repo` slot
5847 // but different `$ORG` / `$HOME` / `$WORKSPACE` resolve
5848 // different upstreams. Peer with the `:caminho` axis's
5849 // `FonteCaminhoVarExpansion` arm (f4efe9c) on the sibling
5850 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5851 // byte RFC-3986-reserved set on `:entrada :paths`.
5852 let d = dep_with_fonte(DepSource::Git {
5853 repo: "https://github.com/$ORG/caixa-teia".into(),
5854 tag: Some("v0.1.0".into()),
5855 rev: None,
5856 branch: None,
5857 });
5858 let err = d.validate().unwrap_err();
5859 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5860 panic!("expected FonteRepoShape, got other variant");
5861 };
5862 assert_eq!(nome, "caixa-teia");
5863 assert_eq!(repo, "https://github.com/$ORG/caixa-teia");
5864 assert!(
5865 reason.contains("must not contain `$`"),
5866 "reason must surface the shell-variable-expansion arm, got {reason:?}"
5867 );
5868 assert!(
5869 reason.contains("variable-expansion") || reason.contains("'sub-delims'"),
5870 "reason must name the shell-variable-expansion / RFC-3986-sub-delims \
5871 rationale, got {reason:?}"
5872 );
5873 }
5874
5875 #[test]
5876 fn validate_rejects_git_fonte_with_repo_carrying_braced_variable_expansion() {
5877 // The fail-before-pass-after pin for the symmetric POSIX-
5878 // shell braced `${VAR}` expansion paste footgun: an author
5879 // pastes a CI-manifest line `git clone
5880 // https://github.com/${WORKSPACE}/x` (the canonical GitHub
5881 // Actions / GitLab CI / Drone shape) and forgets to
5882 // substitute the literal value. The `${...}` shape is the
5883 // same `$` byte at the leading position of the expansion;
5884 // the per-byte arm fires on the `$`. Pinned separately from
5885 // the bare-`$VAR` shape so a future diagnostic-surface
5886 // change that special-cased the braced form surfaces here.
5887 let d = dep_with_fonte(DepSource::Git {
5888 repo: "https://github.com/${WORKSPACE}/caixa-teia".into(),
5889 tag: Some("v0.1.0".into()),
5890 rev: None,
5891 branch: None,
5892 });
5893 let err = d.validate().unwrap_err();
5894 let DepError::FonteRepoShape { reason, .. } = err else {
5895 panic!("expected FonteRepoShape, got other variant");
5896 };
5897 assert!(
5898 reason.contains("must not contain `$`"),
5899 "reason must surface the shell-variable-expansion arm on the braced `${{...}}` \
5900 shape too, got {reason:?}"
5901 );
5902 }
5903
5904 #[test]
5905 fn fonte_repo_fragment_fires_before_var_expansion_when_fragment_first() {
5906 // Cascade pin: the fragment-`#` arm and the var-expansion-`$`
5907 // arm are both per-byte arms inside the same `for &b in
5908 // s.as_bytes()` loop, so the byte that appears first in the
5909 // value's byte order wins. A `:repo
5910 // "https://github.com/p/x#readme$HOME"` carries both `#` and
5911 // `$`; the `#` byte appears first, so the fragment-`#` arm
5912 // fires, surfacing the more self-locating diagnostic on the
5913 // byte the author pasted earliest in the URL. Mirrors the
5914 // peer cascade discipline
5915 // `fonte_repo_fragment_fires_before_background_when_fragment_first`
5916 // on the prior `:repo` byte-class arm.
5917 let d = dep_with_fonte(DepSource::Git {
5918 repo: "https://github.com/pleme-io/caixa-teia#readme$HOME".into(),
5919 tag: Some("v0.1.0".into()),
5920 rev: None,
5921 branch: None,
5922 });
5923 let err = d.validate().unwrap_err();
5924 let DepError::FonteRepoShape { reason, .. } = err else {
5925 panic!("expected FonteRepoShape, got other variant");
5926 };
5927 assert!(
5928 reason.contains("must not contain `#`"),
5929 "reason must surface the fragment-`#` arm (fires before var-expansion-`$` when \
5930 `#` byte appears first in value), got {reason:?}"
5931 );
5932 }
5933
5934 #[test]
5935 fn fonte_repo_background_fires_before_var_expansion_when_background_first() {
5936 // Cascade pin: the background-`&` arm and the
5937 // var-expansion-`$` arm are both per-byte arms inside the
5938 // same `for &b in s.as_bytes()` loop, so the byte that
5939 // appears first in the value's byte order wins. A `:repo
5940 // "https://github.com/p/x&sleep$HOME"` carries both `&` and
5941 // `$`; the `&` byte appears first, so the background arm
5942 // fires, surfacing the more self-locating diagnostic on the
5943 // byte the author pasted earliest in the URL. Pins the
5944 // natural-order cascade so a future reorder of the per-byte
5945 // arms surfaces here — `$` is the most recent byte-class arm,
5946 // so the cascade-pin sweep extends to cover every immediately
5947 // prior byte arm (`#`, `&`) firing first when ordered ahead
5948 // of `$` in the value.
5949 let d = dep_with_fonte(DepSource::Git {
5950 repo: "https://github.com/pleme-io/caixa-teia&sleep$HOME".into(),
5951 tag: Some("v0.1.0".into()),
5952 rev: None,
5953 branch: None,
5954 });
5955 let err = d.validate().unwrap_err();
5956 let DepError::FonteRepoShape { reason, .. } = err else {
5957 panic!("expected FonteRepoShape, got other variant");
5958 };
5959 assert!(
5960 reason.contains("must not contain `&`"),
5961 "reason must surface the background-`&` arm (fires before var-expansion-`$` when \
5962 `&` byte appears first in value), got {reason:?}"
5963 );
5964 }
5965
5966 #[test]
5967 fn validate_rejects_git_fonte_with_repo_carrying_shell_glob_wildcard() {
5968 // The fail-before-pass-after pin for the canonical
5969 // paste-from-shell-prompt glob footgun on `:repo` (peer with
5970 // the cf9034b `*` / `?` arm on the sibling `:caminho`
5971 // path-fonte axis). An author pastes a shell one-liner that
5972 // referenced a glob expansion (`ls
5973 // github.com/pleme-io/caixa-*`, `git clone
5974 // github:pleme-io/caixa-*`) into the `:repo` slot, forgetting
5975 // to substitute the literal repo name. Until this arm landed
5976 // the `*` byte silently passed every prior `is_git_repo_url`
5977 // arm (no whitespace, no control chars, no non-ASCII, no `#`,
5978 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`,
5979 // no `;`, no `&`, no `$`, doesn't start with `-` or `:`); RFC
5980 // 3986 §2 lists `*` in the 'sub-delims' / reserved set and
5981 // the WHATWG URL spec's special-query percent-encode set maps
5982 // `*` → `%2A` on the wire, so the byte rides verbatim into
5983 // the lacre's per-dep BLAKE3 closure but is silently
5984 // rewritten at libcurl's URL-parser layer — two authors
5985 // whose values differ only in their asterisk presence
5986 // resolve to the byte-identical upstream `git clone` but
5987 // lock to two distinct lacres, defeating the THEORY.md §V.2
5988 // render-determinism contract. Peer with the `:caminho`
5989 // axis's `FonteCaminhoShellGlob` arm (cf9034b) on the
5990 // sibling path-fonte axis, and the `is_git_ref_name`
5991 // refspec-wildcard cascade on the `:fonte :tag` / `:branch`
5992 // axes.
5993 let d = dep_with_fonte(DepSource::Git {
5994 repo: "https://github.com/pleme-io/caixa-*".into(),
5995 tag: Some("v0.1.0".into()),
5996 rev: None,
5997 branch: None,
5998 });
5999 let err = d.validate().unwrap_err();
6000 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6001 panic!("expected FonteRepoShape, got other variant");
6002 };
6003 assert_eq!(nome, "caixa-teia");
6004 assert_eq!(repo, "https://github.com/pleme-io/caixa-*");
6005 assert!(
6006 reason.contains("must not contain `*`"),
6007 "reason must surface the shell-glob arm, got {reason:?}"
6008 );
6009 assert!(
6010 reason.contains("pathname-expansion") || reason.contains("'sub-delims'"),
6011 "reason must name the shell-glob / pathname-expansion / \
6012 RFC-3986-sub-delims rationale, got {reason:?}"
6013 );
6014 }
6015
6016 #[test]
6017 fn validate_rejects_git_fonte_with_repo_carrying_recursive_shell_glob() {
6018 // The fail-before-pass-after pin for the symmetric bash
6019 // `globstar` recursive-glob paste footgun: an author pastes
6020 // a `ls github.com/pleme-io/**/x` (the canonical
6021 // `globstar`-shopt-enabled recursive-listing tail) into the
6022 // `:repo` slot. The `**` shape is two `*` bytes adjacent;
6023 // the per-byte arm fires on the first `*`. Pinned
6024 // separately from the single-`*` shape so a future
6025 // diagnostic-surface change that special-cased the
6026 // double-`*` form surfaces here.
6027 let d = dep_with_fonte(DepSource::Git {
6028 repo: "https://github.com/pleme-io/**/caixa-teia".into(),
6029 tag: Some("v0.1.0".into()),
6030 rev: None,
6031 branch: None,
6032 });
6033 let err = d.validate().unwrap_err();
6034 let DepError::FonteRepoShape { reason, .. } = err else {
6035 panic!("expected FonteRepoShape, got other variant");
6036 };
6037 assert!(
6038 reason.contains("must not contain `*`"),
6039 "reason must surface the shell-glob arm on the `**` recursive-glob shape too, \
6040 got {reason:?}"
6041 );
6042 }
6043
6044 #[test]
6045 fn fonte_repo_fragment_fires_before_glob_when_fragment_first() {
6046 // Cascade pin: the fragment-`#` arm and the glob-`*` arm are
6047 // both per-byte arms inside the same `for &b in s.as_bytes()`
6048 // loop, so the byte that appears first in the value's byte
6049 // order wins. A `:repo
6050 // "https://github.com/p/x#readme*tail"` carries both `#` and
6051 // `*`; the `#` byte appears first, so the fragment-`#` arm
6052 // fires, surfacing the more self-locating diagnostic on the
6053 // byte the author pasted earliest in the URL. Mirrors the
6054 // peer cascade discipline
6055 // `fonte_repo_fragment_fires_before_var_expansion_when_fragment_first`
6056 // on the prior `:repo` byte-class arm.
6057 let d = dep_with_fonte(DepSource::Git {
6058 repo: "https://github.com/pleme-io/caixa-teia#readme*tail".into(),
6059 tag: Some("v0.1.0".into()),
6060 rev: None,
6061 branch: None,
6062 });
6063 let err = d.validate().unwrap_err();
6064 let DepError::FonteRepoShape { reason, .. } = err else {
6065 panic!("expected FonteRepoShape, got other variant");
6066 };
6067 assert!(
6068 reason.contains("must not contain `#`"),
6069 "reason must surface the fragment-`#` arm (fires before glob-`*` when `#` byte \
6070 appears first in value), got {reason:?}"
6071 );
6072 }
6073
6074 #[test]
6075 fn fonte_repo_var_expansion_fires_before_glob_when_var_expansion_first() {
6076 // Cascade pin: the var-expansion-`$` arm and the glob-`*`
6077 // arm are both per-byte arms inside the same `for &b in
6078 // s.as_bytes()` loop, so the byte that appears first in the
6079 // value's byte order wins. A `:repo
6080 // "https://github.com/p/$ORG-*"` carries both `$` and `*`;
6081 // the `$` byte appears first, so the var-expansion arm
6082 // fires, surfacing the more self-locating diagnostic on the
6083 // byte the author pasted earliest in the URL. Pins the
6084 // natural-order cascade so a future reorder of the per-byte
6085 // arms surfaces here — `*` is the most recent byte-class
6086 // arm, so the cascade-pin sweep extends to cover the
6087 // immediately prior `$` byte arm firing first when ordered
6088 // ahead of `*` in the value.
6089 let d = dep_with_fonte(DepSource::Git {
6090 repo: "https://github.com/pleme-io/$ORG-caixa-*".into(),
6091 tag: Some("v0.1.0".into()),
6092 rev: None,
6093 branch: None,
6094 });
6095 let err = d.validate().unwrap_err();
6096 let DepError::FonteRepoShape { reason, .. } = err else {
6097 panic!("expected FonteRepoShape, got other variant");
6098 };
6099 assert!(
6100 reason.contains("must not contain `$`"),
6101 "reason must surface the var-expansion-`$` arm (fires before glob-`*` when `$` \
6102 byte appears first in value), got {reason:?}"
6103 );
6104 }
6105
6106 #[test]
6107 fn validate_rejects_git_fonte_with_repo_carrying_subshell_open_paren() {
6108 // The fail-before-pass-after pin for the canonical paste-from-
6109 // shell-prompt subshell-grouping footgun on `:repo`. An author
6110 // pastes a doc / README snippet carrying a regex-alternation
6111 // grouping shape (`https://github.com/(foo|bar)/repo`) or a
6112 // dynamic-config-substitution wrapper (`$(<cmd>)`) into the
6113 // `:repo` slot, forgetting to substitute one literal org name.
6114 // Until this arm landed the `(` byte silently passed every
6115 // prior `is_git_repo_url` arm (no whitespace, no control
6116 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6117 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no
6118 // `*`, doesn't start with `-` or `:`); RFC 3986 §2 lists `(`
6119 // / `)` in the 'sub-delims' / reserved set, and the WHATWG
6120 // URL spec's special-query percent-encode set maps `(` →
6121 // `%28` and `)` → `%29` on the wire, so the byte rides
6122 // verbatim into the lacre's per-dep BLAKE3 closure but is
6123 // silently rewritten at libcurl's URL-parser layer —
6124 // defeating the THEORY.md §V.2 render-determinism contract on
6125 // the same axis the prior twelve byte-class arms close.
6126 let d = dep_with_fonte(DepSource::Git {
6127 repo: "https://github.com/(foo|bar)/caixa-teia".into(),
6128 tag: Some("v0.1.0".into()),
6129 rev: None,
6130 branch: None,
6131 });
6132 let err = d.validate().unwrap_err();
6133 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6134 panic!("expected FonteRepoShape, got other variant");
6135 };
6136 assert_eq!(nome, "caixa-teia");
6137 assert_eq!(repo, "https://github.com/(foo|bar)/caixa-teia");
6138 assert!(
6139 reason.contains("must not contain `(`"),
6140 "reason must surface the subshell-open-paren arm, got {reason:?}"
6141 );
6142 assert!(
6143 reason.contains("subshell-grouping") || reason.contains("'sub-delims'"),
6144 "reason must name the shell-subshell-grouping / RFC-3986-sub-delims rationale, \
6145 got {reason:?}"
6146 );
6147 }
6148
6149 #[test]
6150 fn validate_rejects_git_fonte_with_repo_carrying_subshell_close_paren() {
6151 // The symmetric arm pin on the closing `)` byte: an author
6152 // pastes a `$(date)` command-substitution wrapper or a
6153 // regex-alternation `(foo|bar)` tail into the `:repo` slot.
6154 // Pinned separately from the opening `(` shape so a future
6155 // diagnostic-surface change that only checked one boundary
6156 // surfaces here. The `(` byte appears earlier in the
6157 // canonical regex / subshell wrapper so the per-byte loop
6158 // fires on `(` first; this test exercises a `:repo` value
6159 // carrying only the closing `)` byte (no opening paren) so
6160 // the `)` arm fires directly — pinning the byte-class arm
6161 // independent of order.
6162 let d = dep_with_fonte(DepSource::Git {
6163 repo: "github:pleme-io/caixa-teia)tail".into(),
6164 tag: Some("v0.1.0".into()),
6165 rev: None,
6166 branch: None,
6167 });
6168 let err = d.validate().unwrap_err();
6169 let DepError::FonteRepoShape { reason, .. } = err else {
6170 panic!("expected FonteRepoShape, got other variant");
6171 };
6172 assert!(
6173 reason.contains("must not contain `)`"),
6174 "reason must surface the subshell-close-paren arm on the bare `)` shape, \
6175 got {reason:?}"
6176 );
6177 }
6178
6179 #[test]
6180 fn fonte_repo_fragment_fires_before_subshell_when_fragment_first() {
6181 // Cascade pin: the fragment-`#` arm and the subshell-`(` arm
6182 // are both per-byte arms inside the same `for &b in
6183 // s.as_bytes()` loop, so the byte that appears first in the
6184 // value's byte order wins. A `:repo
6185 // "https://github.com/p/x#readme(tail)"` carries both `#` and
6186 // `(`; the `#` byte appears first, so the fragment-`#` arm
6187 // fires, surfacing the more self-locating diagnostic on the
6188 // byte the author pasted earliest in the URL. Mirrors the
6189 // peer cascade discipline
6190 // `fonte_repo_fragment_fires_before_glob_when_fragment_first`
6191 // on the prior `:repo` byte-class arm.
6192 let d = dep_with_fonte(DepSource::Git {
6193 repo: "https://github.com/pleme-io/caixa-teia#readme(tail)".into(),
6194 tag: Some("v0.1.0".into()),
6195 rev: None,
6196 branch: None,
6197 });
6198 let err = d.validate().unwrap_err();
6199 let DepError::FonteRepoShape { reason, .. } = err else {
6200 panic!("expected FonteRepoShape, got other variant");
6201 };
6202 assert!(
6203 reason.contains("must not contain `#`"),
6204 "reason must surface the fragment-`#` arm (fires before subshell-`(` when `#` \
6205 byte appears first in value), got {reason:?}"
6206 );
6207 }
6208
6209 #[test]
6210 fn fonte_repo_glob_fires_before_subshell_when_glob_first() {
6211 // Cascade pin: the glob-`*` arm (the immediate-predecessor
6212 // byte-class arm, 3902a9a) and the subshell-`(` arm are both
6213 // per-byte arms inside the same `for &b in s.as_bytes()`
6214 // loop, so the byte that appears first in the value's byte
6215 // order wins. A `:repo
6216 // "https://github.com/p/x-*-(date)"` carries both `*` and
6217 // `(`; the `*` byte appears first, so the glob arm fires,
6218 // surfacing the more self-locating diagnostic on the byte
6219 // the author pasted earliest in the URL. Pins the natural-
6220 // order cascade so a future reorder of the per-byte arms
6221 // surfaces here — `(` is the most recent byte-class arm,
6222 // so the cascade-pin sweep extends to cover the immediately
6223 // prior `*` byte arm firing first when ordered ahead of `(`
6224 // in the value.
6225 let d = dep_with_fonte(DepSource::Git {
6226 repo: "https://github.com/pleme-io/caixa-teia-*-(date)".into(),
6227 tag: Some("v0.1.0".into()),
6228 rev: None,
6229 branch: None,
6230 });
6231 let err = d.validate().unwrap_err();
6232 let DepError::FonteRepoShape { reason, .. } = err else {
6233 panic!("expected FonteRepoShape, got other variant");
6234 };
6235 assert!(
6236 reason.contains("must not contain `*`"),
6237 "reason must surface the glob-`*` arm (fires before subshell-`(` when `*` byte \
6238 appears first in value), got {reason:?}"
6239 );
6240 }
6241
6242 #[test]
6243 fn validate_rejects_git_fonte_with_repo_carrying_shell_double_quote() {
6244 // The fail-before-pass-after pin for the canonical paste-from-
6245 // doc-shell-quoting footgun on `:repo`. An author copies a
6246 // README quick-start snippet (`$ git clone "https://github.com/
6247 // foo/bar"`) and keeps the surrounding double-quote bytes when
6248 // pasting into the `:repo` slot — the doc wraps the URL in
6249 // double quotes so the shell doesn't re-lex metachars inside,
6250 // but the typed slot is itself a byte-level string parser, not
6251 // a shell context, so the quote bytes ride into the value
6252 // verbatim. Until this arm landed the `"` byte silently passed
6253 // every prior `is_git_repo_url` arm (no whitespace, no control
6254 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6255 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`,
6256 // no `(`/`)`, doesn't start with `-` or `:`); RFC 3986 §2 lists
6257 // `"` in the strict four-byte 'delims' subset (with `<`, `>`,
6258 // `` ` ``) every URL parser is required to refuse or percent-
6259 // encode, and the WHATWG URL spec's 'C0 control percent-encode
6260 // set' maps `"` → `%22` on the wire, so the byte rides verbatim
6261 // into the lacre's per-dep BLAKE3 closure but is silently
6262 // rewritten at libcurl's URL-parser layer, defeating the
6263 // THEORY.md §V.2 render-determinism contract.
6264 let d = dep_with_fonte(DepSource::Git {
6265 repo: "\"https://github.com/pleme-io/caixa-teia\"".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 { nome, repo, reason } = err else {
6272 panic!("expected FonteRepoShape, got other variant");
6273 };
6274 assert_eq!(nome, "caixa-teia");
6275 assert_eq!(repo, "\"https://github.com/pleme-io/caixa-teia\"");
6276 assert!(
6277 reason.contains("must not contain `\"`"),
6278 "reason must surface the shell-double-quote arm, got {reason:?}"
6279 );
6280 assert!(
6281 reason.contains("double-quote") || reason.contains("'delims'"),
6282 "reason must name the shell-double-quote / RFC-3986-delims rationale, \
6283 got {reason:?}"
6284 );
6285 }
6286
6287 #[test]
6288 fn validate_rejects_git_fonte_with_repo_carrying_stray_trailing_double_quote() {
6289 // The symmetric stray-quote tail pin: an author pastes only a
6290 // closing `"` from a shell-history line like `git clone
6291 // "https://github.com/foo/bar" && cd …` (the trim went too
6292 // far in one direction but not the other) into the `:repo`
6293 // slot. Pinned separately from the wrapped-quote shape so a
6294 // future diagnostic-surface change that only checked one
6295 // boundary (only leading, only trailing, only paired) surfaces
6296 // here — the per-byte arm fires anywhere `"` appears.
6297 let d = dep_with_fonte(DepSource::Git {
6298 repo: "github:pleme-io/caixa-teia\"".into(),
6299 tag: Some("v0.1.0".into()),
6300 rev: None,
6301 branch: None,
6302 });
6303 let err = d.validate().unwrap_err();
6304 let DepError::FonteRepoShape { reason, .. } = err else {
6305 panic!("expected FonteRepoShape, got other variant");
6306 };
6307 assert!(
6308 reason.contains("must not contain `\"`"),
6309 "reason must surface the shell-double-quote arm on the trailing-`\"` shape, \
6310 got {reason:?}"
6311 );
6312 }
6313
6314 #[test]
6315 fn fonte_repo_fragment_fires_before_double_quote_when_fragment_first() {
6316 // Cascade pin: the fragment-`#` arm and the double-quote arm
6317 // are both per-byte arms inside the same `for &b in
6318 // s.as_bytes()` loop, so the byte that appears first in the
6319 // value's byte order wins. A `:repo
6320 // "https://github.com/p/x#readme\"tail"` carries both `#` and
6321 // `"`; the `#` byte appears first, so the fragment-`#` arm
6322 // fires, surfacing the more self-locating diagnostic on the
6323 // byte the author pasted earliest in the URL.
6324 let d = dep_with_fonte(DepSource::Git {
6325 repo: "https://github.com/pleme-io/caixa-teia#readme\"tail".into(),
6326 tag: Some("v0.1.0".into()),
6327 rev: None,
6328 branch: None,
6329 });
6330 let err = d.validate().unwrap_err();
6331 let DepError::FonteRepoShape { reason, .. } = err else {
6332 panic!("expected FonteRepoShape, got other variant");
6333 };
6334 assert!(
6335 reason.contains("must not contain `#`"),
6336 "reason must surface the fragment-`#` arm (fires before double-quote when `#` \
6337 byte appears first in value), got {reason:?}"
6338 );
6339 }
6340
6341 #[test]
6342 fn fonte_repo_subshell_fires_before_double_quote_when_subshell_first() {
6343 // Cascade pin: the subshell-`(` arm (the immediate-predecessor
6344 // byte-class arm, 3b99147) and the double-quote arm are both
6345 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6346 // so the byte that appears first in the value's byte order
6347 // wins. A `:repo "github:p/x(date)\"tail"` carries both `(`
6348 // and `"`; the `(` byte appears first, so the subshell arm
6349 // fires, surfacing the more self-locating diagnostic on the
6350 // byte the author pasted earliest in the URL. Pins the natural-
6351 // order cascade so a future reorder of the per-byte arms
6352 // surfaces here — `"` is the most recent byte-class arm, so
6353 // the cascade-pin sweep extends to cover the immediately prior
6354 // `(` byte arm firing first when ordered ahead of `"` in the
6355 // value.
6356 let d = dep_with_fonte(DepSource::Git {
6357 repo: "github:pleme-io/caixa-teia(date)\"tail".into(),
6358 tag: Some("v0.1.0".into()),
6359 rev: None,
6360 branch: None,
6361 });
6362 let err = d.validate().unwrap_err();
6363 let DepError::FonteRepoShape { reason, .. } = err else {
6364 panic!("expected FonteRepoShape, got other variant");
6365 };
6366 assert!(
6367 reason.contains("must not contain `(`"),
6368 "reason must surface the subshell-`(` arm (fires before double-quote when `(` \
6369 byte appears first in value), got {reason:?}"
6370 );
6371 }
6372
6373 #[test]
6374 fn validate_rejects_git_fonte_with_repo_carrying_shell_single_quote() {
6375 // The fail-before-pass-after pin for the canonical paste-from-
6376 // doc-strong-quoting footgun on `:repo`. An author copies a
6377 // security-conscious README quick-start snippet (`$ git clone
6378 // 'https://github.com/foo/bar'`) and keeps the surrounding
6379 // single-quote bytes when pasting into the `:repo` slot — the
6380 // doc strong-quotes the URL so the shell suppresses every form
6381 // of expansion on the bytes inside (no `$`, no backtick, no
6382 // glob, no word-splitting), but the typed slot is itself a
6383 // byte-level string parser, not a shell context, so the quote
6384 // bytes ride into the value verbatim. Until this arm landed the
6385 // `'` byte silently passed every prior `is_git_repo_url` arm
6386 // (no whitespace, no control chars, no non-ASCII, no `#`, no
6387 // `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no
6388 // `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`, doesn't start
6389 // with `-` or `:`); RFC 3986 §2.2 lists `'` in the 'sub-delims'
6390 // set, peer with the `\"` 'delims' double-quote arm and the
6391 // partner ASCII shell-string-delimiter byte every byte-level
6392 // string parser sharing a value-shape with a shell argument
6393 // must refuse on a URL-shaped slot.
6394 let d = dep_with_fonte(DepSource::Git {
6395 repo: "'https://github.com/pleme-io/caixa-teia'".into(),
6396 tag: Some("v0.1.0".into()),
6397 rev: None,
6398 branch: None,
6399 });
6400 let err = d.validate().unwrap_err();
6401 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6402 panic!("expected FonteRepoShape, got other variant");
6403 };
6404 assert_eq!(nome, "caixa-teia");
6405 assert_eq!(repo, "'https://github.com/pleme-io/caixa-teia'");
6406 assert!(
6407 reason.contains("must not contain `'`"),
6408 "reason must surface the shell-single-quote arm, got {reason:?}"
6409 );
6410 assert!(
6411 reason.contains("single-quote") || reason.contains("strong-quote"),
6412 "reason must name the shell-single-quote / strong-quote rationale, \
6413 got {reason:?}"
6414 );
6415 }
6416
6417 #[test]
6418 fn validate_rejects_git_fonte_with_repo_carrying_english_apostrophe() {
6419 // The symmetric English-typography pin: an author writes
6420 // `:repo "github:p/repo's-fork"` (the possessive-form paste-
6421 // from-prose idiom every README / commit-message / chat-thread
6422 // reference to a repo carries) expecting the substrate to
6423 // coerce it to a kebab-case slug — but the byte rides into the
6424 // lacre verbatim. Pinned separately from the wrapped-quote
6425 // shape so a future diagnostic-surface change that only checked
6426 // the boundary positions (only leading, only trailing, only
6427 // paired) surfaces here — the per-byte arm fires anywhere `'`
6428 // appears in the value.
6429 let d = dep_with_fonte(DepSource::Git {
6430 repo: "github:pleme-io/repo's-fork".into(),
6431 tag: Some("v0.1.0".into()),
6432 rev: None,
6433 branch: None,
6434 });
6435 let err = d.validate().unwrap_err();
6436 let DepError::FonteRepoShape { reason, .. } = err else {
6437 panic!("expected FonteRepoShape, got other variant");
6438 };
6439 assert!(
6440 reason.contains("must not contain `'`"),
6441 "reason must surface the shell-single-quote arm on the mid-string \
6442 apostrophe shape, got {reason:?}"
6443 );
6444 }
6445
6446 #[test]
6447 fn fonte_repo_fragment_fires_before_single_quote_when_fragment_first() {
6448 // Cascade pin: the fragment-`#` arm and the single-quote arm
6449 // are both per-byte arms inside the same `for &b in
6450 // s.as_bytes()` loop, so the byte that appears first in the
6451 // value's byte order wins. A `:repo
6452 // "https://github.com/p/x#readme'tail"` carries both `#` and
6453 // `'`; the `#` byte appears first, so the fragment-`#` arm
6454 // fires, surfacing the more self-locating diagnostic on the
6455 // byte the author pasted earliest in the URL.
6456 let d = dep_with_fonte(DepSource::Git {
6457 repo: "https://github.com/pleme-io/caixa-teia#readme'tail".into(),
6458 tag: Some("v0.1.0".into()),
6459 rev: None,
6460 branch: None,
6461 });
6462 let err = d.validate().unwrap_err();
6463 let DepError::FonteRepoShape { reason, .. } = err else {
6464 panic!("expected FonteRepoShape, got other variant");
6465 };
6466 assert!(
6467 reason.contains("must not contain `#`"),
6468 "reason must surface the fragment-`#` arm (fires before single-quote when `#` \
6469 byte appears first in value), got {reason:?}"
6470 );
6471 }
6472
6473 #[test]
6474 fn fonte_repo_double_quote_fires_before_single_quote_when_double_quote_first() {
6475 // Cascade pin: the double-quote-`"` arm (the immediate-predecessor
6476 // byte-class arm, 4267d8b) and the single-quote arm are both
6477 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6478 // so the byte that appears first in the value's byte order
6479 // wins. A `:repo "github:p/x\"mid'tail"` carries both `"` and
6480 // `'`; the `"` byte appears first, so the double-quote arm
6481 // fires, surfacing the more self-locating diagnostic on the
6482 // byte the author pasted earliest in the URL. Pins the natural-
6483 // order cascade so a future reorder of the per-byte arms
6484 // surfaces here — `'` is the most recent byte-class arm, so
6485 // the cascade-pin sweep extends to cover the immediately prior
6486 // `"` byte arm firing first when ordered ahead of `'` in the
6487 // value.
6488 let d = dep_with_fonte(DepSource::Git {
6489 repo: "github:pleme-io/caixa-teia\"mid'tail".into(),
6490 tag: Some("v0.1.0".into()),
6491 rev: None,
6492 branch: None,
6493 });
6494 let err = d.validate().unwrap_err();
6495 let DepError::FonteRepoShape { reason, .. } = err else {
6496 panic!("expected FonteRepoShape, got other variant");
6497 };
6498 assert!(
6499 reason.contains("must not contain `\"`"),
6500 "reason must surface the double-quote arm (fires before single-quote when `\"` \
6501 byte appears first in value), got {reason:?}"
6502 );
6503 }
6504
6505 #[test]
6506 fn validate_rejects_git_fonte_with_repo_carrying_shell_history_expansion() {
6507 // The fail-before-pass-after pin for the canonical paste-from-
6508 // shell-history footgun on `:repo`. An author copies a `git
6509 // clone <url>!sudo make install` one-liner from a README's
6510 // quick-start snippet, intending the trailing `!sudo` as a
6511 // shell-history-expansion reference but the typed slot is itself
6512 // a byte-level string parser, not a shell context, so the byte
6513 // rides into the value verbatim. Until this arm landed the `!`
6514 // byte silently passed every prior `is_git_repo_url` arm (no
6515 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
6516 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6517 // no `&`, no `$`, no `*`, no `(`/`)`, no `"`, no `'`, doesn't
6518 // start with `-` or `:`); bash with the default `histexpand`
6519 // mode rewrites `!command` to the most recent history entry
6520 // beginning with `command`, the canonical RCE-class injection
6521 // vector when the byte rides into a shell argument.
6522 let d = dep_with_fonte(DepSource::Git {
6523 repo: "https://github.com/pleme-io/caixa-teia!sudo".into(),
6524 tag: Some("v0.1.0".into()),
6525 rev: None,
6526 branch: None,
6527 });
6528 let err = d.validate().unwrap_err();
6529 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6530 panic!("expected FonteRepoShape, got other variant");
6531 };
6532 assert_eq!(nome, "caixa-teia");
6533 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia!sudo");
6534 assert!(
6535 reason.contains("must not contain `!`"),
6536 "reason must surface the shell-history-expansion arm, got {reason:?}"
6537 );
6538 assert!(
6539 reason.contains("history-expansion") || reason.contains("bang"),
6540 "reason must name the shell-history-expansion / bang rationale, got {reason:?}"
6541 );
6542 }
6543
6544 #[test]
6545 fn validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference() {
6546 // The symmetric `!!` repeat-prior-command pin: an author paste-
6547 // trims a `git clone <url>` retry idiom from shell history that
6548 // expands to the previous command via `!!`. Pinned separately
6549 // from the wrapped `!command` shape so a future diagnostic-
6550 // surface change that only checked the leading or paired-bang
6551 // position surfaces here — the per-byte arm fires anywhere `!`
6552 // appears in the value.
6553 let d = dep_with_fonte(DepSource::Git {
6554 repo: "github:pleme-io/caixa-teia!!".into(),
6555 tag: Some("v0.1.0".into()),
6556 rev: None,
6557 branch: None,
6558 });
6559 let err = d.validate().unwrap_err();
6560 let DepError::FonteRepoShape { reason, .. } = err else {
6561 panic!("expected FonteRepoShape, got other variant");
6562 };
6563 assert!(
6564 reason.contains("must not contain `!`"),
6565 "reason must surface the shell-history-expansion arm on the trailing-`!!` shape, \
6566 got {reason:?}"
6567 );
6568 }
6569
6570 #[test]
6571 fn fonte_repo_fragment_fires_before_bang_when_fragment_first() {
6572 // Cascade pin: the fragment-`#` arm and the bang arm are both
6573 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6574 // so the byte that appears first in the value's byte order
6575 // wins. A `:repo "https://github.com/p/x#readme!tail"` carries
6576 // both `#` and `!`; the `#` byte appears first, so the
6577 // fragment-`#` arm fires, surfacing the more self-locating
6578 // diagnostic on the byte the author pasted earliest in the URL.
6579 let d = dep_with_fonte(DepSource::Git {
6580 repo: "https://github.com/pleme-io/caixa-teia#readme!tail".into(),
6581 tag: Some("v0.1.0".into()),
6582 rev: None,
6583 branch: None,
6584 });
6585 let err = d.validate().unwrap_err();
6586 let DepError::FonteRepoShape { reason, .. } = err else {
6587 panic!("expected FonteRepoShape, got other variant");
6588 };
6589 assert!(
6590 reason.contains("must not contain `#`"),
6591 "reason must surface the fragment-`#` arm (fires before bang when `#` byte \
6592 appears first in value), got {reason:?}"
6593 );
6594 }
6595
6596 #[test]
6597 fn fonte_repo_single_quote_fires_before_bang_when_single_quote_first() {
6598 // Cascade pin: the single-quote-`'` arm (the immediate-predecessor
6599 // byte-class arm, e7a109f) and the bang arm are both per-byte
6600 // arms inside the same `for &b in s.as_bytes()` loop, so the
6601 // byte that appears first in the value's byte order wins. A
6602 // `:repo "github:p/x'mid!tail"` carries both `'` and `!`; the
6603 // `'` byte appears first, so the single-quote arm fires,
6604 // surfacing the more self-locating diagnostic on the byte the
6605 // author pasted earliest in the URL. Pins the natural-order
6606 // cascade so a future reorder of the per-byte arms surfaces
6607 // here — `!` is the most recent byte-class arm, so the
6608 // cascade-pin sweep extends to cover the immediately prior `'`
6609 // byte arm firing first when ordered ahead of `!` in the value.
6610 let d = dep_with_fonte(DepSource::Git {
6611 repo: "github:pleme-io/caixa-teia'mid!tail".into(),
6612 tag: Some("v0.1.0".into()),
6613 rev: None,
6614 branch: None,
6615 });
6616 let err = d.validate().unwrap_err();
6617 let DepError::FonteRepoShape { reason, .. } = err else {
6618 panic!("expected FonteRepoShape, got other variant");
6619 };
6620 assert!(
6621 reason.contains("must not contain `'`"),
6622 "reason must surface the single-quote arm (fires before bang when `'` byte \
6623 appears first in value), got {reason:?}"
6624 );
6625 }
6626
6627 #[test]
6628 fn validate_rejects_git_fonte_with_repo_carrying_list_separator_comma() {
6629 // The fail-before-pass-after pin for the canonical
6630 // list-separator-belongs-to-list-grammar footgun on `:repo`.
6631 // An author copies a `git clone <a>, <b>, <c>` paste-from-CSV
6632 // one-liner from a multi-repo bootstrap doc, intending the
6633 // comma to separate multiple repo entries but the typed
6634 // `:repo` slot names *one* repo (the list-separator belongs
6635 // to the `:deps` list grammar, not to the value). Until this
6636 // arm landed the `,` byte silently passed every prior
6637 // `is_git_repo_url` arm (no whitespace, no control chars, no
6638 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6639 // no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`, no
6640 // `(`/`)`, no `"`, no `'`, no `!`, doesn't start with `-` or
6641 // `:`); the byte rode into the lacre's per-dep content-
6642 // address and the resolver's `git clone <repo>` subprocess
6643 // invocation, where no host's repo registry resolved the
6644 // comma-bearing slug.
6645 let d = dep_with_fonte(DepSource::Git {
6646 repo: "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira".into(),
6647 tag: Some("v0.1.0".into()),
6648 rev: None,
6649 branch: None,
6650 });
6651 let err = d.validate().unwrap_err();
6652 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6653 panic!("expected FonteRepoShape, got other variant");
6654 };
6655 assert_eq!(nome, "caixa-teia");
6656 assert_eq!(
6657 repo,
6658 "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira"
6659 );
6660 assert!(
6661 reason.contains("must not contain `,`"),
6662 "reason must surface the list-separator-comma arm, got {reason:?}"
6663 );
6664 assert!(
6665 reason.contains("list-separator") || reason.contains("sub-delims"),
6666 "reason must name the list-separator / RFC-3986-sub-delims rationale, \
6667 got {reason:?}"
6668 );
6669 }
6670
6671 #[test]
6672 fn validate_rejects_git_fonte_with_repo_carrying_trailing_comma() {
6673 // The symmetric trailing-`,` paste-from-prose pin: an author
6674 // writes `:repo "github:pleme-io/caixa-feira,"` (the trailing
6675 // comma every README-prose list-of-projects sentence carries,
6676 // mistakenly retained when the slug is pasted mid-sentence)
6677 // expecting the substrate to coerce it to a kebab-case slug.
6678 // Pinned separately from the wrapped mid-token shape so a
6679 // future diagnostic-surface change that only checked the
6680 // leading or paired-comma position surfaces here — the
6681 // per-byte arm fires anywhere `,` appears in the value.
6682 let d = dep_with_fonte(DepSource::Git {
6683 repo: "github:pleme-io/caixa-feira,".into(),
6684 tag: Some("v0.1.0".into()),
6685 rev: None,
6686 branch: None,
6687 });
6688 let err = d.validate().unwrap_err();
6689 let DepError::FonteRepoShape { reason, .. } = err else {
6690 panic!("expected FonteRepoShape, got other variant");
6691 };
6692 assert!(
6693 reason.contains("must not contain `,`"),
6694 "reason must surface the list-separator-comma arm on the trailing-`,` shape, \
6695 got {reason:?}"
6696 );
6697 }
6698
6699 #[test]
6700 fn fonte_repo_fragment_fires_before_comma_when_fragment_first() {
6701 // Cascade pin: the fragment-`#` arm and the comma arm are
6702 // both per-byte arms inside the same `for &b in s.as_bytes()`
6703 // loop, so the byte that appears first in the value's byte
6704 // order wins. A `:repo "https://github.com/p/x#readme,tail"`
6705 // carries both `#` and `,`; the `#` byte appears first, so
6706 // the fragment-`#` arm fires, surfacing the more self-
6707 // locating diagnostic on the byte the author pasted earliest
6708 // in the URL.
6709 let d = dep_with_fonte(DepSource::Git {
6710 repo: "https://github.com/pleme-io/caixa-teia#readme,tail".into(),
6711 tag: Some("v0.1.0".into()),
6712 rev: None,
6713 branch: None,
6714 });
6715 let err = d.validate().unwrap_err();
6716 let DepError::FonteRepoShape { reason, .. } = err else {
6717 panic!("expected FonteRepoShape, got other variant");
6718 };
6719 assert!(
6720 reason.contains("must not contain `#`"),
6721 "reason must surface the fragment-`#` arm (fires before comma when `#` byte \
6722 appears first in value), got {reason:?}"
6723 );
6724 }
6725
6726 #[test]
6727 fn fonte_repo_bang_fires_before_comma_when_bang_first() {
6728 // Cascade pin: the bang-`!` arm (the immediate-predecessor
6729 // byte-class arm, 7d53c68) and the comma arm are both
6730 // per-byte arms inside the same `for &b in s.as_bytes()`
6731 // loop, so the byte that appears first in the value's byte
6732 // order wins. A `:repo "github:p/x!mid,tail"` carries both
6733 // `!` and `,`; the `!` byte appears first, so the bang arm
6734 // fires, surfacing the more self-locating diagnostic on the
6735 // byte the author pasted earliest in the URL. Pins the
6736 // natural-order cascade so a future reorder of the per-byte
6737 // arms surfaces here — `,` is the most recent byte-class
6738 // arm, so the cascade-pin sweep extends to cover the
6739 // immediately prior `!` byte arm firing first when ordered
6740 // ahead of `,` in the value.
6741 let d = dep_with_fonte(DepSource::Git {
6742 repo: "github:pleme-io/caixa-teia!mid,tail".into(),
6743 tag: Some("v0.1.0".into()),
6744 rev: None,
6745 branch: None,
6746 });
6747 let err = d.validate().unwrap_err();
6748 let DepError::FonteRepoShape { reason, .. } = err else {
6749 panic!("expected FonteRepoShape, got other variant");
6750 };
6751 assert!(
6752 reason.contains("must not contain `!`"),
6753 "reason must surface the bang arm (fires before comma when `!` byte \
6754 appears first in value), got {reason:?}"
6755 );
6756 }
6757
6758 #[test]
6759 fn validate_rejects_git_fonte_with_repo_carrying_shell_env_var_assignment() {
6760 // The fail-before-pass-after pin for the canonical
6761 // shell-env-var-assignment-belongs-to-shell-grammar footgun
6762 // on `:repo`. An author copies
6763 // `GIT_TERMINAL_PROMPT=0 git clone <url>` (or
6764 // `GIT_SSL_NO_VERIFY=1 git clone <url>`, `HTTPS_PROXY=…
6765 // git clone <url>`, etc. — the canonical
6766 // git-troubleshooting README idiom for a one-shot env-var
6767 // scoped to the `git clone` invocation) from a shell-prompt
6768 // one-liner, intending the `KEY=VALUE` prefix as a shell-
6769 // grammar env-var assignment but the typed `:repo` slot is
6770 // a value parser, not a shell context, so the bytes ride
6771 // into the value verbatim. Until this arm landed the `=`
6772 // byte silently passed every prior `is_git_repo_url` arm
6773 // (no whitespace, no control chars, no non-ASCII, no `#`,
6774 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no
6775 // `|`, no `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`,
6776 // no `'`, no `!`, no `,`, doesn't start with `-` or `:`);
6777 // the byte rode into the lacre's per-dep content-address
6778 // and the resolver's `git clone <repo>` subprocess
6779 // invocation, where the upstream host's git porcelain
6780 // fetched a literal `GIT_TERMINAL_PROMPT=0 https://…`-shaped
6781 // path that no host's repo registry resolves.
6782 let d = dep_with_fonte(DepSource::Git {
6783 repo: "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia".into(),
6784 tag: Some("v0.1.0".into()),
6785 rev: None,
6786 branch: None,
6787 });
6788 let err = d.validate().unwrap_err();
6789 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6790 panic!("expected FonteRepoShape, got other variant");
6791 };
6792 assert_eq!(nome, "caixa-teia");
6793 assert_eq!(
6794 repo,
6795 "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia"
6796 );
6797 // The `=` byte at position 19 of `GIT_TERMINAL_PROMPT=0 …`
6798 // appears before the ` ` byte at position 21, so the `=`
6799 // arm fires (not the whitespace arm) — both arms guard
6800 // the slot, but the per-byte for-loop scans left-to-right
6801 // and the first matching byte wins.
6802 assert!(
6803 reason.contains("must not contain `=`"),
6804 "reason must surface the equals-`=` arm on the env-var-assignment \
6805 paste shape, got {reason:?}"
6806 );
6807 assert!(
6808 reason.contains("env-var-assignment") || reason.contains("KEY=VALUE"),
6809 "reason must name the shell-env-var-assignment rationale, got {reason:?}"
6810 );
6811 }
6812
6813 #[test]
6814 fn validate_rejects_git_fonte_with_repo_carrying_gitconfig_url_key_prefix() {
6815 // The symmetric paste-from-gitconfig pin: an author copies
6816 // `url=https://github.com/p/x` from `git config --get-all
6817 // remote.origin.url` output, a `.gitconfig` `[remote
6818 // "origin"] url = https://…` ini-stanza paste, or a
6819 // `git config remote.origin.url <value>` doc snippet,
6820 // intending the `url=` prefix as the ini-key but the typed
6821 // `:repo` slot is a URL value parser, not a gitconfig
6822 // grammar. With no leading whitespace and no earlier-arm
6823 // bytes in the value, the `=` arm itself fires (rather
6824 // than cascading to the whitespace arm as in the env-var
6825 // paste shape). Pinned separately so a future diagnostic-
6826 // surface change that only checked the whitespace-leading
6827 // shape surfaces here — the per-byte arm fires anywhere
6828 // `=` appears in the value.
6829 let d = dep_with_fonte(DepSource::Git {
6830 repo: "url=https://github.com/pleme-io/caixa-feira".into(),
6831 tag: Some("v0.1.0".into()),
6832 rev: None,
6833 branch: None,
6834 });
6835 let err = d.validate().unwrap_err();
6836 let DepError::FonteRepoShape { reason, .. } = err else {
6837 panic!("expected FonteRepoShape, got other variant");
6838 };
6839 assert!(
6840 reason.contains("must not contain `=`"),
6841 "reason must surface the equals-`=` arm on the `url=…` gitconfig \
6842 paste shape, got {reason:?}"
6843 );
6844 assert!(
6845 reason.contains("key-value-separator") || reason.contains("sub-delims"),
6846 "reason must name the key-value-separator / RFC-3986-sub-delims \
6847 rationale, got {reason:?}"
6848 );
6849 }
6850
6851 #[test]
6852 fn fonte_repo_fragment_fires_before_equals_when_fragment_first() {
6853 // Cascade pin: the fragment-`#` arm and the `=` arm are
6854 // both per-byte arms inside the same `for &b in s.as_bytes()`
6855 // loop, so the byte that appears first in the value's byte
6856 // order wins. A `:repo "https://github.com/p/x#readme=tail"`
6857 // carries both `#` and `=`; the `#` byte appears first, so
6858 // the fragment-`#` arm fires, surfacing the more self-
6859 // locating diagnostic on the byte the author pasted earliest
6860 // in the URL.
6861 let d = dep_with_fonte(DepSource::Git {
6862 repo: "https://github.com/pleme-io/caixa-teia#readme=tail".into(),
6863 tag: Some("v0.1.0".into()),
6864 rev: None,
6865 branch: None,
6866 });
6867 let err = d.validate().unwrap_err();
6868 let DepError::FonteRepoShape { reason, .. } = err else {
6869 panic!("expected FonteRepoShape, got other variant");
6870 };
6871 assert!(
6872 reason.contains("must not contain `#`"),
6873 "reason must surface the fragment-`#` arm (fires before equals when \
6874 `#` byte appears first in value), got {reason:?}"
6875 );
6876 }
6877
6878 #[test]
6879 fn fonte_repo_comma_fires_before_equals_when_comma_first() {
6880 // Cascade pin: the comma-`,` arm (the immediate-predecessor
6881 // byte-class arm, 775b80e) and the `=` arm are both per-byte
6882 // arms inside the same `for &b in s.as_bytes()` loop, so
6883 // the byte that appears first in the value's byte order
6884 // wins. A `:repo "github:p/x,mid=tail"` carries both `,`
6885 // and `=`; the `,` byte appears first, so the comma arm
6886 // fires, surfacing the more self-locating diagnostic on
6887 // the byte the author pasted earliest in the URL. Pins the
6888 // natural-order cascade so a future reorder of the per-byte
6889 // arms surfaces here — `=` is the most recent byte-class
6890 // arm, so the cascade-pin sweep extends to cover the
6891 // immediately prior `,` byte arm firing first when ordered
6892 // ahead of `=` in the value.
6893 let d = dep_with_fonte(DepSource::Git {
6894 repo: "github:pleme-io/caixa-teia,mid=tail".into(),
6895 tag: Some("v0.1.0".into()),
6896 rev: None,
6897 branch: None,
6898 });
6899 let err = d.validate().unwrap_err();
6900 let DepError::FonteRepoShape { reason, .. } = err else {
6901 panic!("expected FonteRepoShape, got other variant");
6902 };
6903 assert!(
6904 reason.contains("must not contain `,`"),
6905 "reason must surface the comma arm (fires before equals when `,` byte \
6906 appears first in value), got {reason:?}"
6907 );
6908 }
6909
6910 #[test]
6911 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_space() {
6912 // The fail-before-pass-after pin for the canonical paste-from-
6913 // browser-address-bar percent-encoded-space footgun on `:repo`.
6914 // An author copies `https://github.com/p/x%20test` from a
6915 // browser address bar (or a percent-encoded README hyperlink,
6916 // or a `curl --data-urlencode` shell-pipeline output)
6917 // intending `%20` as the URL encoding of a literal space; the
6918 // typed `:repo` slot already rejects the literal space byte
6919 // (the whitespace arm at the top of `is_git_repo_url`), so an
6920 // author trying to express "I really meant a space" reaches
6921 // for percent-encoding. Until this arm landed the `%` byte
6922 // silently passed every prior `is_git_repo_url` arm and rode
6923 // verbatim into the lacre's per-dep content-address — but
6924 // libcurl re-percent-encodes `%` to `%25` on the wire (since
6925 // `%` is reserved as the escape-sequence lead-in), so the
6926 // wire request becomes `https://github.com/p/x%2520test`, a
6927 // path the lacre's content-address never names. The classic
6928 // render-determinism violation on the encoding-mechanism axis
6929 // itself.
6930 let d = dep_with_fonte(DepSource::Git {
6931 repo: "https://github.com/pleme-io/caixa-teia%20test".into(),
6932 tag: Some("v0.1.0".into()),
6933 rev: None,
6934 branch: None,
6935 });
6936 let err = d.validate().unwrap_err();
6937 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6938 panic!("expected FonteRepoShape, got other variant");
6939 };
6940 assert_eq!(nome, "caixa-teia");
6941 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia%20test");
6942 assert!(
6943 reason.contains("must not contain `%`"),
6944 "reason must surface the percent-`%` arm on the percent-encoded-space \
6945 paste shape, got {reason:?}"
6946 );
6947 assert!(
6948 reason.contains("percent-encoding") || reason.contains("%25"),
6949 "reason must name the percent-encoding / `%25` re-encoding rationale, \
6950 got {reason:?}"
6951 );
6952 }
6953
6954 #[test]
6955 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_slash() {
6956 // The symmetric over-encoded-path-separator pin: an author
6957 // writes `:repo "https://github.com/p%2Fx"` intending the
6958 // `%2F` as the URL encoding of `/` (the canonical
6959 // paste-from-OpenAPI-spec / paste-from-percent-encoded-template
6960 // footgun every API client library and OAuth redirect-URI
6961 // documentation surfaces — the `/` is the URL-path-separator
6962 // and some templates percent-encode it to escape interpretation
6963 // as a path separator). The GitHub Smart-HTTP transport
6964 // resolves the URL's path-segment grammar before the
6965 // percent-decoding pass, so the value identifies a different
6966 // resource on the wire than the literal-`/` form the lacre's
6967 // content-address must agree with — two authors whose `:repo`
6968 // values differ only in their `/` vs `%2F` presence lock to
6969 // two distinct BLAKE3 closures for the byte-identical upstream
6970 // `git clone`. Pinned separately so a future diagnostic
6971 // surface that only catches the `%20` shape surfaces here too.
6972 let d = dep_with_fonte(DepSource::Git {
6973 repo: "https://github.com/pleme-io%2Fcaixa-teia".into(),
6974 tag: Some("v0.1.0".into()),
6975 rev: None,
6976 branch: None,
6977 });
6978 let err = d.validate().unwrap_err();
6979 let DepError::FonteRepoShape { reason, .. } = err else {
6980 panic!("expected FonteRepoShape, got other variant");
6981 };
6982 assert!(
6983 reason.contains("must not contain `%`"),
6984 "reason must surface the percent-`%` arm on the over-encoded-path \
6985 shape, got {reason:?}"
6986 );
6987 assert!(
6988 reason.contains("render-determinism") || reason.contains("BLAKE3"),
6989 "reason must name the render-determinism / BLAKE3-closure rationale, \
6990 got {reason:?}"
6991 );
6992 }
6993
6994 #[test]
6995 fn fonte_repo_fragment_fires_before_percent_when_fragment_first() {
6996 // Cascade pin: the fragment-`#` arm and the `%` arm are both
6997 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6998 // so the byte that appears first in the value's byte order
6999 // wins. A `:repo "https://github.com/p/x#sec%20tail"` carries
7000 // both `#` and `%`; the `#` byte appears first, so the
7001 // fragment-`#` arm fires, surfacing the more self-locating
7002 // diagnostic on the byte the author pasted earliest in the URL.
7003 let d = dep_with_fonte(DepSource::Git {
7004 repo: "https://github.com/pleme-io/caixa-teia#sec%20tail".into(),
7005 tag: Some("v0.1.0".into()),
7006 rev: None,
7007 branch: None,
7008 });
7009 let err = d.validate().unwrap_err();
7010 let DepError::FonteRepoShape { reason, .. } = err else {
7011 panic!("expected FonteRepoShape, got other variant");
7012 };
7013 assert!(
7014 reason.contains("must not contain `#`"),
7015 "reason must surface the fragment-`#` arm (fires before percent when \
7016 `#` byte appears first in value), got {reason:?}"
7017 );
7018 }
7019
7020 #[test]
7021 fn fonte_repo_equals_fires_before_percent_when_equals_first() {
7022 // Cascade pin: the equals-`=` arm (the immediate-predecessor
7023 // byte-class arm, acf99af) and the `%` arm are both per-byte
7024 // arms inside the same `for &b in s.as_bytes()` loop, so the
7025 // byte that appears first in the value's byte order wins.
7026 // A `:repo "github:p/x=mid%20tail"` carries both `=` and `%`;
7027 // the `=` byte appears first, so the equals arm fires,
7028 // surfacing the more self-locating diagnostic on the byte the
7029 // author pasted earliest in the URL. Pins the natural-order
7030 // cascade so a future reorder of the per-byte arms surfaces
7031 // here — `%` is the most recent byte-class arm, so the
7032 // cascade-pin sweep extends to cover the immediately prior
7033 // `=` byte arm firing first when ordered ahead of `%` in the
7034 // value.
7035 let d = dep_with_fonte(DepSource::Git {
7036 repo: "github:pleme-io/caixa-teia=mid%20tail".into(),
7037 tag: Some("v0.1.0".into()),
7038 rev: None,
7039 branch: None,
7040 });
7041 let err = d.validate().unwrap_err();
7042 let DepError::FonteRepoShape { reason, .. } = err else {
7043 panic!("expected FonteRepoShape, got other variant");
7044 };
7045 assert!(
7046 reason.contains("must not contain `=`"),
7047 "reason must surface the equals arm (fires before percent when `=` byte \
7048 appears first in value), got {reason:?}"
7049 );
7050 }
7051
7052 #[test]
7053 fn validate_rejects_git_fonte_with_repo_carrying_caret_history_substitution() {
7054 // The fail-before-pass-after pin for the canonical paste-from-
7055 // shell-history footgun on `:repo`. An author copies a
7056 // `git clone <url>` line from their terminal followed by a
7057 // bash / ksh / zsh `^typo^fix^` quick-edit-and-rerun shell-
7058 // history shorthand (the `^old^new^` form re-runs the prior
7059 // history entry with the first `old` substituted by `new`,
7060 // bash's default behavior on interactive sessions with
7061 // `set -o histexpand`), forgetting to trim the trailing
7062 // `^...^...` shell-history fragment from the URL value. The
7063 // `^` byte sits in the RFC 3986 §2 'unwise' set (peer with
7064 // `{`, `}`, `|`, `\\` — the strictest of the §2 reserved
7065 // classes), the WHATWG URL spec's 'fragment percent-encode
7066 // set' maps `^` → `%5E` on the wire, so the byte rides
7067 // verbatim into the lacre's per-dep content-address but
7068 // libcurl re-encodes it to `%5E` at `git clone` time — the
7069 // classic render-determinism violation on the same axis the
7070 // peer `%`, `=`, `,`, `!`, `'`, `"`, `(`, `)`, `*`, `$`,
7071 // `&`, `;`, `|`, backtick, `<`, `>`, `{`, `}`, `\\`, `?`,
7072 // `#` arms close.
7073 let d = dep_with_fonte(DepSource::Git {
7074 repo: "https://github.com/pleme-io/caixa-teia^typo^fix".into(),
7075 tag: Some("v0.1.0".into()),
7076 rev: None,
7077 branch: None,
7078 });
7079 let err = d.validate().unwrap_err();
7080 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7081 panic!("expected FonteRepoShape, got other variant");
7082 };
7083 assert_eq!(nome, "caixa-teia");
7084 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia^typo^fix");
7085 assert!(
7086 reason.contains("must not contain `^`"),
7087 "reason must surface the caret-`^` arm on the paste-from-shell-history \
7088 shape, got {reason:?}"
7089 );
7090 assert!(
7091 reason.contains("history-substitution") || reason.contains("%5E"),
7092 "reason must name the shell-history-substitution / `%5E` wire-encoding \
7093 rationale, got {reason:?}"
7094 );
7095 }
7096
7097 #[test]
7098 fn validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor() {
7099 // The symmetric paste-from-doc-grep-pipeline footgun: an
7100 // author writes `:repo "github:p/^archived"` after copying a
7101 // `grep '^archived'` regex-anchor / negation idiom from a
7102 // doc / README quick-listing snippet, expecting the substrate
7103 // to coerce it to a literal repo name. The byte rides
7104 // verbatim into the lacre's per-dep content-address and
7105 // diverges from the byte-identical literal `archived` form
7106 // every other author authored — the canonical render-
7107 // determinism violation pin on the second footgun shape the
7108 // caret-`^` arm closes.
7109 let d = dep_with_fonte(DepSource::Git {
7110 repo: "github:pleme-io/^archived".into(),
7111 tag: Some("v0.1.0".into()),
7112 rev: None,
7113 branch: None,
7114 });
7115 let err = d.validate().unwrap_err();
7116 let DepError::FonteRepoShape { reason, .. } = err else {
7117 panic!("expected FonteRepoShape, got other variant");
7118 };
7119 assert!(
7120 reason.contains("must not contain `^`"),
7121 "reason must surface the caret-`^` arm on the regex-anchor shape, \
7122 got {reason:?}"
7123 );
7124 assert!(
7125 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7126 "reason must name the render-determinism / BLAKE3-closure rationale, \
7127 got {reason:?}"
7128 );
7129 }
7130
7131 #[test]
7132 fn fonte_repo_percent_fires_before_caret_when_percent_first() {
7133 // Cascade pin: the `%` arm (the immediate-predecessor byte-
7134 // class arm, a323db8) and the `^` arm are both per-byte arms
7135 // inside the same `for &b in s.as_bytes()` loop, so the byte
7136 // that appears first in the value's byte order wins. A
7137 // `:repo "https://github.com/p/x%20mid^tail"` carries both
7138 // `%` and `^`; the `%` byte appears first, so the percent
7139 // arm fires, surfacing the more self-locating diagnostic on
7140 // the byte the author pasted earliest in the URL. Pins the
7141 // natural-order cascade so a future reorder of the per-byte
7142 // arms surfaces here — `^` is the most recent byte-class arm,
7143 // so the cascade-pin sweep extends to cover the immediately
7144 // prior `%` byte arm firing first when ordered ahead of `^`
7145 // in the value.
7146 let d = dep_with_fonte(DepSource::Git {
7147 repo: "https://github.com/pleme-io/caixa-teia%20mid^tail".into(),
7148 tag: Some("v0.1.0".into()),
7149 rev: None,
7150 branch: None,
7151 });
7152 let err = d.validate().unwrap_err();
7153 let DepError::FonteRepoShape { reason, .. } = err else {
7154 panic!("expected FonteRepoShape, got other variant");
7155 };
7156 assert!(
7157 reason.contains("must not contain `%`"),
7158 "reason must surface the percent arm (fires before caret when `%` byte \
7159 appears first in value), got {reason:?}"
7160 );
7161 }
7162
7163 #[test]
7164 fn validate_rejects_git_fonte_with_repo_missing_colon_separator() {
7165 // The "I dropped the scheme" footgun — `:repo "pleme-io/caixa-teia"`
7166 // (no `github:` prefix, no scheme). Every documented form
7167 // carries a `:` (`github:`, `https://`, `ssh://`, `git://`,
7168 // `file://`, or `git@host:path`); a bare `org/repo` is
7169 // ambiguous (`git clone` reads as a relative filesystem path
7170 // rather than the GitHub-shorthand expansion the author
7171 // probably intended) and the gate rejects the shape upstream.
7172 let d = dep_with_fonte(DepSource::Git {
7173 repo: "pleme-io/caixa-teia".into(),
7174 tag: Some("v0.1.0".into()),
7175 rev: None,
7176 branch: None,
7177 });
7178 let err = d.validate().unwrap_err();
7179 let DepError::FonteRepoShape { reason, .. } = err else {
7180 panic!("expected FonteRepoShape, got other variant");
7181 };
7182 assert!(
7183 reason.contains("must contain a `:`"),
7184 "reason must surface the missing-`:` arm, got {reason:?}"
7185 );
7186 assert!(
7187 reason.contains("github:"),
7188 "reason must name the canonical `github:` shorthand prefix, got {reason:?}"
7189 );
7190 }
7191
7192 #[test]
7193 fn validate_rejects_git_fonte_with_repo_leading_colon() {
7194 // The "empty scheme" footgun — `:repo ":foo"` has a zero-length
7195 // scheme that no git porcelain entry-point accepts. Pinned
7196 // separately from the missing-`:` arm because a value with a
7197 // leading `:` does technically contain a `:` separator; the
7198 // shape gate rejects on a dedicated arm so the diagnostic
7199 // names the specific footgun.
7200 let d = dep_with_fonte(DepSource::Git {
7201 repo: ":pleme-io/caixa-teia".into(),
7202 tag: Some("v0.1.0".into()),
7203 rev: None,
7204 branch: None,
7205 });
7206 let err = d.validate().unwrap_err();
7207 let DepError::FonteRepoShape { reason, .. } = err else {
7208 panic!("expected FonteRepoShape, got other variant");
7209 };
7210 assert!(
7211 reason.contains("must not start with `:`"),
7212 "reason must surface the leading-`:` arm, got {reason:?}"
7213 );
7214 }
7215
7216 #[test]
7217 fn validate_rejects_git_fonte_with_repo_too_long() {
7218 // The cap arm — a `:repo` value longer than
7219 // [`crate::render::GIT_REPO_URL_MAX_LEN`] (2048) bytes is
7220 // structurally untenable on every realistic landing site (the
7221 // resolver's `git clone` invocation, the future M4 CR
7222 // materializer's per-dep `repo:` axis); a value of that length
7223 // is almost certainly a paste-from-binary slug.
7224 let too_long = format!(
7225 "github:pleme-io/{}",
7226 "x".repeat(crate::render::GIT_REPO_URL_MAX_LEN)
7227 );
7228 let d = dep_with_fonte(DepSource::Git {
7229 repo: too_long.clone(),
7230 tag: Some("v0.1.0".into()),
7231 rev: None,
7232 branch: None,
7233 });
7234 let err = d.validate().unwrap_err();
7235 let DepError::FonteRepoShape { reason, .. } = err else {
7236 panic!("expected FonteRepoShape, got other variant");
7237 };
7238 assert!(
7239 reason.contains("2048"),
7240 "reason must name the cap, got {reason:?}"
7241 );
7242 }
7243
7244 #[test]
7245 fn validate_accepts_canonical_git_fonte_repo_shapes() {
7246 // The positive-control sweep: every documented author shape on
7247 // the `:fonte :repo` axis ([`crate::DepSource::Git`] doc comment)
7248 // must pass the value-shape gate. Pinned so a future tightening
7249 // (e.g. forbidding `http://` in favor of `https://`-only) surfaces
7250 // here as a structural decision. Each form is exercised with the
7251 // same canonical `:tag` pin so only the `:repo` axis varies.
7252 for repo in [
7253 // The pleme-io registry-shorthand convention — `github:org/repo`.
7254 "github:pleme-io/caixa-teia",
7255 // Other host-aliased shorthands (the resolver's pluggable
7256 // host-prefix table).
7257 "gitlab:pleme-io/caixa-teia",
7258 "codeberg:pleme-io/caixa-teia",
7259 "sourcehut:~pleme-io/caixa-teia",
7260 // Full HTTPS URL with and without `.git` suffix.
7261 "https://github.com/pleme-io/caixa-teia",
7262 "https://github.com/pleme-io/caixa-teia.git",
7263 // HTTP (rare; dev / mirror).
7264 "http://example.com/pleme-io/caixa-teia.git",
7265 // SSH URL.
7266 "ssh://git@github.com/pleme-io/caixa-teia.git",
7267 "ssh://git@git.example.com:2222/pleme-io/caixa-teia.git",
7268 // Scp-style SSH — the canonical `git@host:path` short form.
7269 "git@github.com:pleme-io/caixa-teia.git",
7270 "git@git.example.com:team/private.git",
7271 // Anonymous git protocol.
7272 "git://git.example.com/pleme-io/caixa-teia.git",
7273 // Local file URL (dev path).
7274 "file:///tmp/caixa-teia",
7275 ] {
7276 let d = dep_with_fonte(DepSource::Git {
7277 repo: repo.into(),
7278 tag: Some("v0.1.0".into()),
7279 rev: None,
7280 branch: None,
7281 });
7282 d.validate()
7283 .unwrap_or_else(|e| panic!("canonical repo {repo:?} must validate, got {e:?}"));
7284 }
7285 }
7286
7287 #[test]
7288 fn fonte_repo_empty_takes_precedence_over_shape() {
7289 // Order pin: the existing `FonteRepoEmpty` diagnostic (narrower
7290 // diagnostic; doesn't try to parse the URL shape) fires before
7291 // the new `FonteRepoShape` per-axis gate, so an empty `:repo`
7292 // keeps its narrower error message. Mirrors
7293 // `fonte_repo_empty_fires_before_pin_missing` (already pinned)
7294 // on the ordering layer.
7295 let d = dep_with_fonte(DepSource::Git {
7296 repo: String::new(),
7297 tag: Some("v0.1.0".into()),
7298 rev: None,
7299 branch: None,
7300 });
7301 let err = d.validate().unwrap_err();
7302 assert!(
7303 matches!(err, DepError::FonteRepoEmpty { .. }),
7304 "got {err:?}"
7305 );
7306 }
7307
7308 #[test]
7309 fn fonte_repo_shape_fires_before_pin_missing() {
7310 // Order pin: a malformed `:repo` value on a dep with no pin set
7311 // surfaces the `:repo` shape diagnostic (the more self-locating
7312 // axis — the `:repo` is the load-bearing identity of the source;
7313 // a missing pin is downstream from "do we even know the repo")
7314 // rather than collapsing onto the pin-missing diagnostic. The
7315 // shape gate runs inline before the pin enumeration in
7316 // `DepSource::validate`.
7317 let d = dep_with_fonte(DepSource::Git {
7318 repo: "pleme-io/caixa-teia".into(), // missing `:` separator
7319 tag: None,
7320 rev: None,
7321 branch: None,
7322 });
7323 let err = d.validate().unwrap_err();
7324 assert!(
7325 matches!(err, DepError::FonteRepoShape { .. }),
7326 "got {err:?}"
7327 );
7328 }
7329
7330 #[test]
7331 fn fonte_repo_shape_diagnostic_carries_offending_repo_verbatim() {
7332 // The diagnostic-shape pin: the error names the offending
7333 // `:repo` value verbatim plus a non-empty parser-shaped `reason`
7334 // so the author can grep their caixa.lisp without re-running
7335 // the build. Mirrors the diagnostic-shape sweep on every prior
7336 // value-shape gate (3f9d7a0, 6cbb900, c7d05ec, e70d213, be07fd5).
7337 let d = dep_with_fonte(DepSource::Git {
7338 repo: "pleme-io/caixa-teia".into(),
7339 tag: Some("v0.1.0".into()),
7340 rev: None,
7341 branch: None,
7342 });
7343 let err = d.validate().unwrap_err();
7344 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7345 panic!("expected FonteRepoShape, got other variant");
7346 };
7347 assert_eq!(nome, "caixa-teia");
7348 assert_eq!(repo, "pleme-io/caixa-teia");
7349 assert!(
7350 !reason.is_empty(),
7351 "FonteRepoShape `reason` must carry the predicate's wording verbatim"
7352 );
7353 }
7354
7355 #[test]
7356 fn validate_rejects_git_fonte_with_no_pin() {
7357 // The fail-before-pass-after pin for the canonical
7358 // `(:tipo git :repo "github:pleme-io/x")` shape with no
7359 // :tag/:rev/:branch — until this gate landed the resolver's
7360 // ResolveError::MissingPin surfaced at fetch time, far from the
7361 // source caixa.lisp. The new gate moves the check to validate
7362 // time and names the offending dep.
7363 let d = dep_with_fonte(DepSource::Git {
7364 repo: "github:pleme-io/caixa-teia".into(),
7365 tag: None,
7366 rev: None,
7367 branch: None,
7368 });
7369 let err = d.validate().unwrap_err();
7370 assert!(
7371 matches!(err, DepError::FontePinMissing { ref nome } if nome == "caixa-teia"),
7372 "got {err:?}"
7373 );
7374 }
7375
7376 #[test]
7377 fn validate_rejects_git_fonte_with_ambiguous_tag_and_branch() {
7378 // The canonical "pin drift" footgun: an author writes
7379 // `:tag "v1"` and later adds `:branch "main"` without removing
7380 // the :tag, and the resolver silently picks :tag (precedence
7381 // :rev > :tag > :branch). The :branch was dropped with no
7382 // diagnostic. The gate now rejects multi-pin shapes so the
7383 // author makes the precedence explicit at the source.
7384 let d = dep_with_fonte(DepSource::Git {
7385 repo: "github:pleme-io/caixa-teia".into(),
7386 tag: Some("v0.1.0".into()),
7387 rev: None,
7388 branch: Some("main".into()),
7389 });
7390 let err = d.validate().unwrap_err();
7391 let DepError::FontePinAmbiguous { nome, pins } = err else {
7392 panic!("expected FontePinAmbiguous");
7393 };
7394 assert_eq!(nome, "caixa-teia");
7395 assert!(pins.contains(":tag"));
7396 assert!(pins.contains(":branch"));
7397 assert!(!pins.contains(":rev"));
7398 }
7399
7400 #[test]
7401 fn validate_rejects_git_fonte_with_ambiguous_tag_and_rev() {
7402 // Sibling arm of the pin-drift footgun: :tag + :rev set
7403 // simultaneously. Pinned separately so a future relaxation
7404 // that only catches the (:tag, :branch) pair surfaces here.
7405 let d = dep_with_fonte(DepSource::Git {
7406 repo: "github:pleme-io/caixa-teia".into(),
7407 tag: Some("v0.1.0".into()),
7408 rev: Some("c0ffee".into()),
7409 branch: None,
7410 });
7411 let err = d.validate().unwrap_err();
7412 let DepError::FontePinAmbiguous { nome, pins } = err else {
7413 panic!("expected FontePinAmbiguous");
7414 };
7415 assert_eq!(nome, "caixa-teia");
7416 assert!(pins.contains(":tag"));
7417 assert!(pins.contains(":rev"));
7418 }
7419
7420 #[test]
7421 fn validate_rejects_git_fonte_with_all_three_pins() {
7422 // The maximal ambiguity case — every pin axis set. Pinned so a
7423 // future relaxation that only catches pairs surfaces here. The
7424 // diagnostic must enumerate every offending axis so the author
7425 // sees the full set, not just the first match.
7426 let d = dep_with_fonte(DepSource::Git {
7427 repo: "github:pleme-io/caixa-teia".into(),
7428 tag: Some("v0.1.0".into()),
7429 rev: Some("c0ffee".into()),
7430 branch: Some("main".into()),
7431 });
7432 let err = d.validate().unwrap_err();
7433 let DepError::FontePinAmbiguous { nome, pins } = err else {
7434 panic!("expected FontePinAmbiguous");
7435 };
7436 assert_eq!(nome, "caixa-teia");
7437 assert!(pins.contains(":tag"));
7438 assert!(pins.contains(":rev"));
7439 assert!(pins.contains(":branch"));
7440 }
7441
7442 #[test]
7443 fn validate_rejects_git_fonte_with_empty_tag_pin() {
7444 // The empty-pin arm: exactly one pin axis is `Some(_)`, but its
7445 // inner string is empty. Distinct from FontePinMissing (where
7446 // every axis is None) — pinned separately so a future
7447 // tightening collapsing them surfaces here as a structural
7448 // decision.
7449 let d = dep_with_fonte(DepSource::Git {
7450 repo: "github:pleme-io/caixa-teia".into(),
7451 tag: Some(String::new()),
7452 rev: None,
7453 branch: None,
7454 });
7455 let err = d.validate().unwrap_err();
7456 let DepError::FontePinEmpty { nome, pin } = err else {
7457 panic!("expected FontePinEmpty");
7458 };
7459 assert_eq!(nome, "caixa-teia");
7460 assert_eq!(pin, ":tag");
7461 }
7462
7463 #[test]
7464 fn validate_rejects_git_fonte_with_empty_rev_pin() {
7465 // Sibling arm — the empty-pin diagnostic names which axis
7466 // carries the empty value, so the author's grep target is
7467 // unambiguous.
7468 let d = dep_with_fonte(DepSource::Git {
7469 repo: "github:pleme-io/caixa-teia".into(),
7470 tag: None,
7471 rev: Some(String::new()),
7472 branch: None,
7473 });
7474 let err = d.validate().unwrap_err();
7475 let DepError::FontePinEmpty { nome, pin } = err else {
7476 panic!("expected FontePinEmpty");
7477 };
7478 assert_eq!(nome, "caixa-teia");
7479 assert_eq!(pin, ":rev");
7480 }
7481
7482 #[test]
7483 fn validate_rejects_path_fonte_with_empty_caminho() {
7484 // The fail-before-pass-after pin for `(:tipo path :caminho "")`:
7485 // until this gate landed the resolver's
7486 // ResolveError::MissingPath surfaced with `path: PathBuf("")` at
7487 // fetch time — not actionable. The new gate moves the check to
7488 // validate time and names the offending dep.
7489 let d = dep_with_fonte(DepSource::Path {
7490 caminho: String::new(),
7491 });
7492 let err = d.validate().unwrap_err();
7493 assert!(
7494 matches!(err, DepError::FonteCaminhoEmpty { ref nome } if nome == "caixa-teia"),
7495 "got {err:?}"
7496 );
7497 }
7498
7499 #[test]
7500 fn validate_rejects_path_fonte_with_absolute_caminho() {
7501 // The fail-before-pass-after pin for the absolute-`:caminho`
7502 // shape: `(:tipo path :caminho "/home/me/work/caixa-teia")`.
7503 // Until this gate landed an absolute `:caminho` silently
7504 // passed validate; the lacre pipeline embedded the
7505 // host-specific filesystem path verbatim in its
7506 // content-address (`conteudo: format!("path:{caminho}")`,
7507 // caixa-resolver/src/resolve.rs:189), so the BLAKE3 closure
7508 // differed per machine — the build succeeded but two CI
7509 // runners with different `${HOME}` layouts emitted two
7510 // distinct lacres for the byte-identical caixa, silently
7511 // breaking the THEORY.md §V.2 render-determinism contract
7512 // far from the source caixa.lisp. The new gate moves the
7513 // check to validate time and names the offending dep +
7514 // caminho verbatim.
7515 let d = dep_with_fonte(DepSource::Path {
7516 caminho: "/home/me/work/caixa-teia".into(),
7517 });
7518 let err = d.validate().unwrap_err();
7519 let DepError::FonteCaminhoAbsolute { nome, caminho } = err else {
7520 panic!("expected FonteCaminhoAbsolute, got other variant");
7521 };
7522 assert_eq!(nome, "caixa-teia");
7523 assert_eq!(caminho, "/home/me/work/caixa-teia");
7524 }
7525
7526 #[test]
7527 fn validate_accepts_path_fonte_with_parent_escape_caminho() {
7528 // The canonical sibling-workspace dep form
7529 // (`:caminho "../caixa-teia"`) remains accepted. The
7530 // absolute-path gate above is specifically narrower than the
7531 // shared [`crate::render::is_sandboxed_relative_path`]
7532 // predicate (which additionally forbids `..` traversal): a
7533 // local-path dep's canonical author surface is the in-tree
7534 // sibling-workspace path, so a full sandboxed-relative-path
7535 // lift would structurally reject every legitimate path-fonte
7536 // dep. Pinned so a future tightening to the full predicate
7537 // surfaces here as a structural decision, not a silent break.
7538 let d = dep_with_fonte(DepSource::Path {
7539 caminho: "../caixa-teia".into(),
7540 });
7541 d.validate().unwrap();
7542 }
7543
7544 #[test]
7545 fn validate_accepts_path_fonte_with_deeply_nested_relative_caminho() {
7546 // A multi-segment relative `:caminho`
7547 // (`"vendor/forks/caixa-teia"`) remains accepted — the
7548 // absolute-path gate brackets the host-layout-leaking shape
7549 // at the leading-`/` boundary only; every relative shape past
7550 // the empty arm continues to pass. Pinned alongside the
7551 // `..`-traversal positive control so a future tightening
7552 // surfaces the full set of legitimate relative forms here
7553 // rather than at a downstream consumer.
7554 let d = dep_with_fonte(DepSource::Path {
7555 caminho: "vendor/forks/caixa-teia".into(),
7556 });
7557 d.validate().unwrap();
7558 }
7559
7560 #[test]
7561 fn validate_rejects_path_fonte_with_tilde_prefix_caminho() {
7562 // The fail-before-pass-after pin for the tilde-expansion
7563 // `:caminho` shape: `(:tipo path :caminho "~/work/caixa-teia")`.
7564 // Until this gate landed the b94fd83 absolute arm let `~/foo`
7565 // through (`Path::is_absolute` returns false on a leading `~`
7566 // — the tilde is a shell-expansion convention, not a POSIX
7567 // path component), so the lacre embedded the value verbatim
7568 // and the resolver folded it through `Path::join` without
7569 // expansion, looking for a literal `./~/work/caixa-teia`
7570 // subdirectory and failing at resolve time with a
7571 // `No such file or directory` error far from the source
7572 // caixa.lisp. The new gate moves the check to validate time
7573 // and names the offending dep + caminho verbatim.
7574 let d = dep_with_fonte(DepSource::Path {
7575 caminho: "~/work/caixa-teia".into(),
7576 });
7577 let err = d.validate().unwrap_err();
7578 let DepError::FonteCaminhoTildeExpansion { nome, caminho } = err else {
7579 panic!("expected FonteCaminhoTildeExpansion, got {err:?}");
7580 };
7581 assert_eq!(nome, "caixa-teia");
7582 assert_eq!(caminho, "~/work/caixa-teia");
7583 }
7584
7585 #[test]
7586 fn validate_rejects_path_fonte_with_bare_tilde_caminho() {
7587 // The bare `~` form (canonical "I meant `$HOME` and forgot
7588 // the rest"): both the leading-tilde arm catches it and the
7589 // canonical-user-tilde shell idiom (`~alice/dev/caixa-teia`)
7590 // sweeps through the same arm. Pinned both to ensure the
7591 // gate doesn't narrow to `~/` only.
7592 for s in ["~", "~alice/dev/caixa-teia", "~/", "~root/work"] {
7593 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7594 let err = d.validate().unwrap_err();
7595 assert!(
7596 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7597 "{s:?} → {err:?}",
7598 );
7599 }
7600 }
7601
7602 #[test]
7603 fn validate_accepts_path_fonte_with_mid_path_tilde_caminho() {
7604 // The leading-`~` is the canonical shell-expansion footgun —
7605 // a tilde mid-path (`"../foo~bar/caixa-teia"` — the canonical
7606 // backup-file-suffix idiom) is a legitimate POSIX path byte
7607 // with no shell-expansion semantic at the leading position.
7608 // Pinned so the gate doesn't widen to a full no-tilde-anywhere
7609 // sweep that would break every legitimate-shape backup-file
7610 // path.
7611 let d = dep_with_fonte(DepSource::Path {
7612 caminho: "../foo~bar/caixa-teia".into(),
7613 });
7614 d.validate().unwrap();
7615 }
7616
7617 #[test]
7618 fn fonte_caminho_empty_fires_before_tilde_expansion() {
7619 // Cascade pin: the empty arm structurally precedes the
7620 // tilde arm (the bytes `""` and `"~"` don't overlap), but the
7621 // pin establishes the precedence at the diagnostic-shape
7622 // level should a future codec round-trip ever produce a
7623 // probe-as-both value. Mirrors the peer
7624 // `fonte_repo_empty_fires_before_pin_missing` cascade
7625 // discipline.
7626 let d = dep_with_fonte(DepSource::Path {
7627 caminho: String::new(),
7628 });
7629 let err = d.validate().unwrap_err();
7630 assert!(
7631 matches!(err, DepError::FonteCaminhoEmpty { .. }),
7632 "got {err:?}",
7633 );
7634 }
7635
7636 #[test]
7637 fn fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho() {
7638 // Diagnostic-shape pin (peer with
7639 // `validate_rejects_path_fonte_with_absolute_caminho`'s
7640 // payload assertion): the error's Display surfaces both the
7641 // offending `:nome` and the offending `:caminho` verbatim
7642 // so a `feira lint` run can render the diagnostic without
7643 // re-parsing.
7644 let d = dep_with_fonte(DepSource::Path {
7645 caminho: "~alice/dev/caixa-teia".into(),
7646 });
7647 let rendered = d.validate().unwrap_err().to_string();
7648 assert!(
7649 rendered.contains("caixa-teia"),
7650 "diagnostic must name the offending dep: {rendered}",
7651 );
7652 assert!(
7653 rendered.contains("~alice/dev/caixa-teia"),
7654 "diagnostic must quote the offending caminho: {rendered}",
7655 );
7656 assert!(
7657 rendered.contains('~'),
7658 "diagnostic must reference the tilde footgun: {rendered}",
7659 );
7660 }
7661
7662 #[test]
7663 fn validate_rejects_path_fonte_with_dollar_prefix_caminho() {
7664 // The fail-before-pass-after pin for the shell-variable-
7665 // expansion `:caminho` shape: `(:tipo path :caminho
7666 // "$HOME/work/caixa-teia")`. Until this gate landed the
7667 // b94fd83 absolute arm + the a5c248e tilde arm both let
7668 // `$HOME/foo` through (`Path::is_absolute` returns false on
7669 // a leading `$` — the `$` is a shell convention, not a POSIX
7670 // path component; `starts_with('~')` returns false too), so
7671 // the lacre embedded the value verbatim and the resolver
7672 // folded it through `Path::join` without `$`-expansion,
7673 // looking for a literal `./$HOME/work/caixa-teia`
7674 // subdirectory and failing at resolve time with a
7675 // `No such file or directory` error far from the source
7676 // caixa.lisp. The new gate moves the check to validate time
7677 // and names the offending dep + caminho verbatim.
7678 let d = dep_with_fonte(DepSource::Path {
7679 caminho: "$HOME/work/caixa-teia".into(),
7680 });
7681 let err = d.validate().unwrap_err();
7682 let DepError::FonteCaminhoVarExpansion { nome, caminho } = err else {
7683 panic!("expected FonteCaminhoVarExpansion, got {err:?}");
7684 };
7685 assert_eq!(nome, "caixa-teia");
7686 assert_eq!(caminho, "$HOME/work/caixa-teia");
7687 }
7688
7689 #[test]
7690 fn validate_rejects_path_fonte_with_dollar_brace_prefix_caminho() {
7691 // Sweep over every leading-`$` shape: the `${VAR}`-braced
7692 // form (canonical "paste-from-CI-manifest" footgun every
7693 // GitHub Actions / GitLab CI / Drone manifest carries on
7694 // `${WORKSPACE}`), the XDG idiom (`$XDG_CONFIG_HOME/caixa`,
7695 // canonical "I'm referencing a per-user config dir"),
7696 // and the bare `$` (canonical "I meant `$HOME` and forgot
7697 // the rest"). All shapes route through the same gate's
7698 // byte check. Pinned so the gate doesn't narrow to a
7699 // single shape (e.g. `$HOME/` only).
7700 for s in [
7701 "${HOME}/work/caixa-teia",
7702 "${WORKSPACE}/caixa-teia",
7703 "$XDG_CONFIG_HOME/caixa",
7704 "$",
7705 ] {
7706 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7707 let err = d.validate().unwrap_err();
7708 assert!(
7709 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
7710 "{s:?} → {err:?}",
7711 );
7712 }
7713 }
7714
7715 #[test]
7716 fn validate_rejects_path_fonte_with_mid_path_dollar_caminho() {
7717 // The `$` byte is the canonical shell-variable-expansion /
7718 // command-substitution / arithmetic-expansion sentinel and
7719 // is rejected at *every* position on the `:caminho` axis: the
7720 // leading arm surfaces `FonteCaminhoVarExpansion`, the
7721 // embedded arm surfaces `FonteCaminhoShellVariableExpansion`
7722 // (6620f39). Pinned so a future arm doesn't narrow the gate
7723 // back to the leading position and re-open the paste-from-
7724 // shell-one-liner `"../foo$HOME/bar"` / paste-from-CI-
7725 // manifest `"../foo${WORKSPACE}/bar"` / paste-from-shell-
7726 // prompt `"../foo$(whoami)/bar"` cross-idiom-leak surface on
7727 // the lacre content-address (`path:{caminho}`,
7728 // caixa-resolver/src/resolve.rs:189).
7729 let d = dep_with_fonte(DepSource::Path {
7730 caminho: "../foo$bar/caixa-teia".into(),
7731 });
7732 let err = d.validate().unwrap_err();
7733 assert!(
7734 matches!(
7735 err,
7736 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
7737 ),
7738 "got {err:?}",
7739 );
7740 }
7741
7742 #[test]
7743 fn fonte_caminho_tilde_fires_before_var_expansion() {
7744 // Cascade pin: the tilde arm structurally precedes the var
7745 // arm (the bytes `~` and `$` don't overlap at the leading
7746 // position), but the pin establishes the precedence at the
7747 // diagnostic-shape level should a future codec round-trip
7748 // ever produce a probe-as-both value. Mirrors the peer
7749 // `fonte_caminho_empty_fires_before_tilde_expansion` cascade
7750 // discipline on the immediate-predecessor arm.
7751 let d = dep_with_fonte(DepSource::Path {
7752 caminho: "~/work/caixa-teia".into(),
7753 });
7754 let err = d.validate().unwrap_err();
7755 assert!(
7756 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7757 "got {err:?}",
7758 );
7759 }
7760
7761 #[test]
7762 fn fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho() {
7763 // Diagnostic-shape pin (peer with
7764 // `fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho`'s
7765 // payload assertion on the immediate-predecessor arm): the
7766 // error's Display surfaces both the offending `:nome` and
7767 // the offending `:caminho` verbatim plus the `$` footgun
7768 // character itself so a `feira lint` run can render the
7769 // diagnostic without re-parsing.
7770 let d = dep_with_fonte(DepSource::Path {
7771 caminho: "${WORKSPACE}/caixa-teia".into(),
7772 });
7773 let rendered = d.validate().unwrap_err().to_string();
7774 assert!(
7775 rendered.contains("caixa-teia"),
7776 "diagnostic must name the offending dep: {rendered}",
7777 );
7778 assert!(
7779 rendered.contains("${WORKSPACE}/caixa-teia"),
7780 "diagnostic must quote the offending caminho: {rendered}",
7781 );
7782 assert!(
7783 rendered.contains('$'),
7784 "diagnostic must reference the dollar footgun: {rendered}",
7785 );
7786 }
7787
7788 #[test]
7789 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_nul() {
7790 // The fail-before-pass-after pin for the load-bearing NUL byte:
7791 // POSIX paths cannot contain `0x00` (every `std::fs` syscall
7792 // routes the path through `CString::new` which fails with
7793 // `NulError`); until this gate landed a `:caminho
7794 // "../caixa\0teia"` silently passed validate, the lacre
7795 // pipeline embedded the value verbatim, and the failure
7796 // surfaced at the resolver's `Path::join` → `CString::new`
7797 // boundary with a non-self-locating `NulError` far from the
7798 // source caixa.lisp. The new gate moves the check to validate
7799 // time and names the offending dep + caminho + offending byte
7800 // verbatim.
7801 let d = dep_with_fonte(DepSource::Path {
7802 caminho: "../caixa\0teia".into(),
7803 });
7804 let err = d.validate().unwrap_err();
7805 let DepError::FonteCaminhoControlChar {
7806 nome,
7807 caminho,
7808 byte,
7809 } = err
7810 else {
7811 panic!("expected FonteCaminhoControlChar, got {err:?}");
7812 };
7813 assert_eq!(nome, "caixa-teia");
7814 assert_eq!(caminho, "../caixa\0teia");
7815 assert_eq!(byte, 0x00);
7816 }
7817
7818 #[test]
7819 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_newline() {
7820 // The canonical paste-from-multiline-doc footgun on `:caminho`
7821 // — author copies `"../caixa-teia\n"` (trailing newline) out
7822 // of a multi-line code-fence or, worse, a `:caminho
7823 // "../caixa-teia\nrm -rf /"` value (CRLF-at-subprocess-argument
7824 // injection sibling on the path axis the `is_git_repo_url`
7825 // control-char arm already closes on `:repo`). Pinned
7826 // separately from the NUL arm so a future relaxation that
7827 // catches one but not the other surfaces here.
7828 let d = dep_with_fonte(DepSource::Path {
7829 caminho: "../caixa-teia\n".into(),
7830 });
7831 let err = d.validate().unwrap_err();
7832 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7833 panic!("expected FonteCaminhoControlChar, got {err:?}");
7834 };
7835 assert_eq!(byte, 0x0A);
7836 }
7837
7838 #[test]
7839 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_carriage_return() {
7840 // The CRLF sibling of the LF arm — Windows-line-ending
7841 // paste-from-multiline-doc on a `\r\n`-terminated buffer
7842 // leaves a stray `\r` mid-string after the LF strip. Pinned
7843 // separately from the LF arm so a future relaxation that
7844 // only catches LF surfaces here.
7845 let d = dep_with_fonte(DepSource::Path {
7846 caminho: "../caixa-teia\r".into(),
7847 });
7848 let err = d.validate().unwrap_err();
7849 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7850 panic!("expected FonteCaminhoControlChar, got {err:?}");
7851 };
7852 assert_eq!(byte, 0x0D);
7853 }
7854
7855 #[test]
7856 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_tab() {
7857 // The canonical paste-from-aligned-table footgun — a `\t`
7858 // mid-`:caminho` is invisible in most editors but rides
7859 // through the lacre's content-address verbatim, so two
7860 // paste-from-distinct-tables (one editor strips tabs, one
7861 // preserves them) yield divergent lacres for the byte-
7862 // identical-looking caixa. Pinned separately from the
7863 // whitespace-shaped LF/CR arms so a future relaxation that
7864 // narrows to line-terminator-only surfaces here.
7865 let d = dep_with_fonte(DepSource::Path {
7866 caminho: "../caixa\tteia".into(),
7867 });
7868 let err = d.validate().unwrap_err();
7869 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7870 panic!("expected FonteCaminhoControlChar, got {err:?}");
7871 };
7872 assert_eq!(byte, 0x09);
7873 }
7874
7875 #[test]
7876 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_del() {
7877 // The DEL byte (`0x7F`) closes the upper-end paste-from-
7878 // binary-blob footgun — the gate's contract is `b < 0x20 ||
7879 // b == 0x7F`, matching the `is_git_repo_url` /
7880 // `is_git_ref_name` predicates' control-char arms. Pinned
7881 // separately from the lower-range arms so a future narrowing
7882 // to `< 0x20` only surfaces here.
7883 let d = dep_with_fonte(DepSource::Path {
7884 caminho: "../caixa\x7fteia".into(),
7885 });
7886 let err = d.validate().unwrap_err();
7887 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
7888 panic!("expected FonteCaminhoControlChar, got {err:?}");
7889 };
7890 assert_eq!(byte, 0x7F);
7891 }
7892
7893 #[test]
7894 fn validate_accepts_path_fonte_with_caminho_carrying_high_bit_utf8() {
7895 // The control-byte arm targets `0x00..=0x1F` + `0x7F` only —
7896 // high-bit / non-ASCII UTF-8 bytes are not gated. POSIX paths
7897 // are opaque byte sequences and UTF-8 multi-byte sequences
7898 // are a legitimate filename shape (the `café-teia/foo` idiom).
7899 // Pinned so the gate doesn't widen to a full ASCII-only sweep
7900 // that would break every legitimate-shape UTF-8 path.
7901 let d = dep_with_fonte(DepSource::Path {
7902 caminho: "../café-teia/foo".into(),
7903 });
7904 d.validate().unwrap();
7905 }
7906
7907 #[test]
7908 fn fonte_caminho_var_fires_before_control_char() {
7909 // Cascade pin: the var-expansion arm structurally precedes the
7910 // control-char arm. A value like `"$\n"` probes positive on
7911 // both arms (`starts_with('$')` and contains LF), but the
7912 // narrower leading-byte diagnostic (`FonteCaminhoVarExpansion`)
7913 // wins so the author sees the more self-locating shell-
7914 // expansion arm first. Mirrors the
7915 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
7916 // discipline on the immediate-predecessor arm.
7917 let d = dep_with_fonte(DepSource::Path {
7918 caminho: "$HOME\n".into(),
7919 });
7920 let err = d.validate().unwrap_err();
7921 assert!(
7922 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
7923 "got {err:?}",
7924 );
7925 }
7926
7927 #[test]
7928 fn validate_rejects_path_fonte_with_leading_space_caminho() {
7929 // The fail-before-pass-after pin for the leading ASCII space
7930 // `:caminho` shape: `(:tipo path :caminho " ../caixa-teia")`.
7931 // Until this gate landed the b94fd83 absolute arm + the a5c248e
7932 // tilde arm + the f4efe9c var arm + the d624c8d control-byte arm
7933 // all let `" ../caixa-teia"` through: `Path::is_absolute` returns
7934 // false on a leading space (the leading byte is `0x20`, not `0x2F`),
7935 // `starts_with('~')` / `starts_with('$')` return false, and `0x20`
7936 // is not in the `0x00..=0x1F` plus `0x7F` control-byte set (the
7937 // four ASCII whitespace bytes `0x09` tab, `0x0A` LF, `0x0D` CR
7938 // are caught, but the most common whitespace `0x20` space is
7939 // not). The lacre embedded the value verbatim and the resolver
7940 // folded it through `Path::join` looking for a literal `./ ../
7941 // caixa-teia` subdirectory and failing at resolve time with a
7942 // non-self-locating `No such file or directory` error far from
7943 // the source caixa.lisp. The new gate moves the check to
7944 // validate time and names the offending dep + caminho verbatim.
7945 let d = dep_with_fonte(DepSource::Path {
7946 caminho: " ../caixa-teia".into(),
7947 });
7948 let err = d.validate().unwrap_err();
7949 let DepError::FonteCaminhoLeadingWhitespace { nome, caminho } = err else {
7950 panic!("expected FonteCaminhoLeadingWhitespace, got {err:?}");
7951 };
7952 assert_eq!(nome, "caixa-teia");
7953 assert_eq!(caminho, " ../caixa-teia");
7954 }
7955
7956 #[test]
7957 fn validate_rejects_path_fonte_with_multiple_leading_spaces_caminho() {
7958 // The aligned-doc paste footgun sweep: more than one leading
7959 // space (`" ../caixa-teia"` — the canonical "I selected the
7960 // aligned column from a four-`:fonte`-entry `:deps` block"
7961 // paste) routes through the same gate's `starts_with(' ')`
7962 // byte check. Pinned so the gate doesn't narrow to a
7963 // single-space prefix.
7964 let d = dep_with_fonte(DepSource::Path {
7965 caminho: " ../caixa-teia".into(),
7966 });
7967 let err = d.validate().unwrap_err();
7968 assert!(
7969 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
7970 "got {err:?}",
7971 );
7972 }
7973
7974 #[test]
7975 fn validate_accepts_path_fonte_with_mid_path_space_caminho() {
7976 // The leading-space is the canonical paste-from-aligned-doc
7977 // footgun — a space mid-path (`"../my dir/caixa-teia"` — the
7978 // canonical "I have a directory with a space in its name"
7979 // idiom; ASCII `0x20` is a valid POSIX filename byte) is a
7980 // legitimate path with no whitespace-leak semantic at the
7981 // non-leading position. Pinned so the gate doesn't widen to a
7982 // full no-space-anywhere sweep that would break every
7983 // legitimate-shape space-in-filename path.
7984 let d = dep_with_fonte(DepSource::Path {
7985 caminho: "../my dir/caixa-teia".into(),
7986 });
7987 d.validate().unwrap();
7988 }
7989
7990 #[test]
7991 fn fonte_caminho_var_fires_before_leading_whitespace() {
7992 // Cascade pin: the var-expansion arm structurally precedes the
7993 // leading-whitespace arm. A value like `"$ "` would probe positive
7994 // on var (`starts_with('$')`) but the leading-byte arms walk
7995 // left-to-right so the var arm fires on the leading `$` before
7996 // the leading-whitespace arm probes. Mirrors the
7997 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
7998 // discipline on the immediate-predecessor arms.
7999 let d = dep_with_fonte(DepSource::Path {
8000 caminho: "$VAR".into(),
8001 });
8002 let err = d.validate().unwrap_err();
8003 assert!(
8004 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8005 "got {err:?}",
8006 );
8007 }
8008
8009 #[test]
8010 fn fonte_caminho_leading_whitespace_fires_before_control_char() {
8011 // Cascade pin: the leading-whitespace arm structurally precedes
8012 // the control-char arm. A value like `" ../foo\n"` probes
8013 // positive on both (starts with space AND contains LF), but
8014 // the narrower leading-byte diagnostic
8015 // (`FonteCaminhoLeadingWhitespace`) wins so the author sees the
8016 // more self-locating paste-from-aligned-doc arm first. Mirrors
8017 // the `fonte_caminho_var_fires_before_control_char` cascade
8018 // discipline on the immediate-predecessor arm.
8019 let d = dep_with_fonte(DepSource::Path {
8020 caminho: " ../foo\n".into(),
8021 });
8022 let err = d.validate().unwrap_err();
8023 assert!(
8024 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8025 "got {err:?}",
8026 );
8027 }
8028
8029 #[test]
8030 fn fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho() {
8031 // Diagnostic-shape pin (peer with
8032 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8033 // payload assertion on the immediate-predecessor arm): the
8034 // error's Display surfaces both the offending `:nome` and the
8035 // offending `:caminho` verbatim, so a `feira lint` run can
8036 // render the diagnostic without re-parsing and the author can
8037 // grep their caixa.lisp for `:caminho "<value>"` and fix it in
8038 // one edit.
8039 let d = dep_with_fonte(DepSource::Path {
8040 caminho: " ../caixa-teia".into(),
8041 });
8042 let rendered = d.validate().unwrap_err().to_string();
8043 assert!(
8044 rendered.contains("caixa-teia"),
8045 "diagnostic must name the offending dep: {rendered}",
8046 );
8047 assert!(
8048 rendered.contains(" ../caixa-teia"),
8049 "diagnostic must quote the offending caminho: {rendered}",
8050 );
8051 assert!(
8052 rendered.contains("space"),
8053 "diagnostic must name the space footgun: {rendered}",
8054 );
8055 }
8056
8057 #[test]
8058 fn fonte_caminho_absolute_fires_before_control_char() {
8059 // Cascade pin on the sibling leading-byte arm: a leading `/`
8060 // value with embedded control byte (`"/etc/passwd\n"`) routes
8061 // through `FonteCaminhoAbsolute` not `FonteCaminhoControlChar`
8062 // — the host-layout-leak diagnostic is the load-bearing axis,
8063 // the control byte is the secondary observation. Same precedence
8064 // logic on every prior leading-byte arm.
8065 let d = dep_with_fonte(DepSource::Path {
8066 caminho: "/etc/passwd\n".into(),
8067 });
8068 let err = d.validate().unwrap_err();
8069 assert!(
8070 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8071 "got {err:?}",
8072 );
8073 }
8074
8075 #[test]
8076 fn validate_rejects_path_fonte_with_leading_hyphen_caminho() {
8077 // The fail-before-pass-after pin for the leading-`-` CLI-arg-
8078 // injection `:caminho` shape sweep. Until this gate landed
8079 // every prior leading-byte arm passed a leading-`-` value
8080 // through: `Path::is_absolute` returns false on `-` (the
8081 // leading byte is `0x2D`, not `0x2F`), `starts_with('~')` /
8082 // `starts_with('$')` / `starts_with(' ')` all return false,
8083 // and `0x2D` sits outside the control-byte set. The lacre
8084 // embedded the value verbatim and the resolver folded it
8085 // through `Path::join` looking for a literal `./-rf` /
8086 // `./-C` / `./--upload-pack=…` subdirectory; the failure at
8087 // `Path::join` time is non-self-locating but harmless, while
8088 // the failure at every downstream `git -C {caminho}` /
8089 // `terraform -chdir={caminho}` / `find {caminho}` shell-out
8090 // is arbitrary-CLI-arg-injection because none of those
8091 // porcelains carry a `--` argument-list terminator between
8092 // the flag block and the path argument. The new arm moves the
8093 // rejection to `Caixa::from_lisp` boundary time and names
8094 // the offending dep + caminho verbatim.
8095 //
8096 // Sweep spans the canonical CLI-arg-injection shapes matching
8097 // the peer sweep on the sibling `is_git_ref_name` /
8098 // `is_git_repo_url` axes: short-flag `-rf` (the `rm -rf` /
8099 // `find -rf` reinterpretation vector), `-C` (the `git -C`
8100 // change-directory-config-injection paste), long-flag
8101 // `--upload-pack=cat /etc/passwd` (the canonical
8102 // arbitrary-command-execution vector on every git porcelain
8103 // entry point), git-config-injection `--config=core.merge=ours`,
8104 // and the degenerate single-byte `-` value.
8105 for caminho in [
8106 "-rf",
8107 "-C",
8108 "--upload-pack=cat /etc/passwd",
8109 "--config=core.merge=ours",
8110 "-",
8111 ] {
8112 let d = dep_with_fonte(DepSource::Path {
8113 caminho: caminho.into(),
8114 });
8115 let err = d.validate().unwrap_err();
8116 let DepError::FonteCaminhoLeadingHyphen { nome, caminho: got } = err else {
8117 panic!("expected FonteCaminhoLeadingHyphen for {caminho:?}, got {err:?}");
8118 };
8119 assert_eq!(nome, "caixa-teia");
8120 assert_eq!(got, caminho);
8121 }
8122 }
8123
8124 #[test]
8125 fn validate_accepts_path_fonte_with_mid_path_hyphen_caminho() {
8126 // The leading-`-` is the canonical CLI-arg-injection footgun
8127 // — a `-` anywhere else in the path (`"../caixa-teia"` — the
8128 // canonical kebab-separator-between-alphanumeric-segments
8129 // shape every DNS-1123-shaped caixa name carries; `"../-hidden"`
8130 // — a mid-path segment starting with `-`, still a legitimate
8131 // POSIX filename byte at that non-leading position because the
8132 // subprocess reads the whole `{caminho}` value as one positional
8133 // argument, so only the very first byte of the composite path
8134 // string is at the CLI-arg-injection boundary) is a legitimate
8135 // path with no CLI-flag-reinterpretation semantic at the non-
8136 // leading position of the top-level value. Pinned so the gate
8137 // doesn't widen to a full no-`-`-anywhere sweep that would
8138 // break every legitimate-shape kebab-in-filename path (i.e.
8139 // essentially every sibling-workspace caixa dep).
8140 for caminho in [
8141 "../caixa-teia",
8142 "../caixa-teia/-hidden",
8143 "./my-lib",
8144 "../foo-bar/baz",
8145 ] {
8146 let d = dep_with_fonte(DepSource::Path {
8147 caminho: caminho.into(),
8148 });
8149 d.validate()
8150 .unwrap_or_else(|e| panic!("mid-path `-` caminho {caminho:?} must pass: {e:?}"));
8151 }
8152 }
8153
8154 #[test]
8155 fn fonte_caminho_leading_whitespace_fires_before_leading_hyphen() {
8156 // Cascade pin: the leading-whitespace arm structurally precedes
8157 // the leading-hyphen arm. A value like `" -rf"` probes positive
8158 // on both (leading space AND, one byte in, a `-` — though the
8159 // leading-hyphen arm probes only the very first byte so it
8160 // wouldn't fire on this value; the pin instead documents the
8161 // arm order on the more common "leading space then a hyphen"
8162 // paste-from-aligned-doc paste-flag-shell-one-liner idiom).
8163 // The narrower leading-space diagnostic (the paste-from-aligned-
8164 // doc footgun) wins so the author sees the more self-locating
8165 // whitespace arm first. Mirrors the
8166 // `fonte_caminho_var_fires_before_leading_whitespace` cascade
8167 // discipline on the immediate-predecessor arm.
8168 let d = dep_with_fonte(DepSource::Path {
8169 caminho: " -rf".into(),
8170 });
8171 let err = d.validate().unwrap_err();
8172 assert!(
8173 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8174 "got {err:?}",
8175 );
8176 }
8177
8178 #[test]
8179 fn fonte_caminho_leading_hyphen_fires_before_control_char() {
8180 // Cascade pin: the leading-hyphen arm structurally precedes
8181 // the control-char arm. A value like `"-rf\n"` probes positive
8182 // on both (starts with `-` AND contains LF), but the narrower
8183 // leading-byte diagnostic (`FonteCaminhoLeadingHyphen`) wins so
8184 // the author sees the more self-locating CLI-arg-injection arm
8185 // first. Mirrors the
8186 // `fonte_caminho_leading_whitespace_fires_before_control_char`
8187 // cascade discipline on the immediate-predecessor arm.
8188 let d = dep_with_fonte(DepSource::Path {
8189 caminho: "-rf\n".into(),
8190 });
8191 let err = d.validate().unwrap_err();
8192 assert!(
8193 matches!(err, DepError::FonteCaminhoLeadingHyphen { .. }),
8194 "got {err:?}",
8195 );
8196 }
8197
8198 #[test]
8199 fn fonte_caminho_leading_hyphen_diagnostic_carries_offending_dep_and_caminho() {
8200 // Diagnostic-shape pin (peer with
8201 // `fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho`'s
8202 // payload assertion on the immediate-predecessor arm): the
8203 // error's Display surfaces both the offending `:nome` and the
8204 // offending `:caminho` verbatim plus the CLI-argument-injection
8205 // vocabulary, so a `feira lint` run can render the diagnostic
8206 // without re-parsing and the author can grep their caixa.lisp
8207 // for `:caminho "<value>"` and fix it in one edit.
8208 let d = dep_with_fonte(DepSource::Path {
8209 caminho: "--upload-pack=cat /etc/passwd".into(),
8210 });
8211 let rendered = d.validate().unwrap_err().to_string();
8212 assert!(
8213 rendered.contains("caixa-teia"),
8214 "diagnostic must name the offending dep: {rendered}",
8215 );
8216 assert!(
8217 rendered.contains("--upload-pack=cat /etc/passwd"),
8218 "diagnostic must quote the offending caminho: {rendered}",
8219 );
8220 assert!(
8221 rendered.contains("CLI-argument-injection"),
8222 "diagnostic must name the CLI-argument-injection vector: {rendered}",
8223 );
8224 assert!(
8225 rendered.contains("`-`"),
8226 "diagnostic must name the offending byte: {rendered}",
8227 );
8228 }
8229
8230 #[test]
8231 fn fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte() {
8232 // Diagnostic-shape pin (peer with
8233 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8234 // payload assertion on the immediate-predecessor arm): the
8235 // error's Display surfaces the offending `:nome`, the
8236 // offending `:caminho` verbatim, and the offending byte in
8237 // hex form (`0x09` for tab) so a `feira lint` run can render
8238 // the diagnostic without re-parsing.
8239 let d = dep_with_fonte(DepSource::Path {
8240 caminho: "../caixa\tteia".into(),
8241 });
8242 let rendered = d.validate().unwrap_err().to_string();
8243 assert!(
8244 rendered.contains("caixa-teia"),
8245 "diagnostic must name the offending dep: {rendered}",
8246 );
8247 assert!(
8248 rendered.contains("../caixa\tteia"),
8249 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8250 );
8251 assert!(
8252 rendered.contains("0x09"),
8253 "diagnostic must name the offending byte in hex: {rendered:?}",
8254 );
8255 }
8256
8257 #[test]
8258 fn validate_rejects_path_fonte_with_caminho_carrying_backslash() {
8259 // The fail-before-pass-after pin for the canonical Windows-
8260 // path-separator paste footgun: an author who pastes a path
8261 // from Windows-Explorer's `Copy as path`, PowerShell's
8262 // `Get-Location`, or any CMD/Cygwin/MSYS shell prompt
8263 // produces `..\caixa-teia`-shape values that silently passed
8264 // every prior arm (`Path::is_absolute("..\\caixa-teia")` is
8265 // false; `\` is neither a leading-byte sentinel nor a
8266 // control byte). On POSIX resolvers the value rides through
8267 // `Path::join` as a literal directory name and fails at
8268 // resolve time with `No such file or directory`; on Windows
8269 // resolvers the value resolves to the parent's sibling — two
8270 // distinct directories for the byte-identical caixa.lisp.
8271 // The new arm moves the rejection to validate time and names
8272 // the offending dep + caminho verbatim.
8273 let d = dep_with_fonte(DepSource::Path {
8274 caminho: "..\\caixa-teia".into(),
8275 });
8276 let err = d.validate().unwrap_err();
8277 let DepError::FonteCaminhoBackslash { nome, caminho } = err else {
8278 panic!("expected FonteCaminhoBackslash, got {err:?}");
8279 };
8280 assert_eq!(nome, "caixa-teia");
8281 assert_eq!(caminho, "..\\caixa-teia");
8282 }
8283
8284 #[test]
8285 fn validate_rejects_path_fonte_with_caminho_carrying_windows_drive_letter() {
8286 // The Windows drive-letter paste shape (`C:\work\caixa-teia`
8287 // out of Explorer / `cd`-and-`pwd`-on-Windows). On POSIX
8288 // hosts `Path::is_absolute("C:\\work\\caixa-teia")` returns
8289 // false (POSIX absolute paths start with `/`, drive letters
8290 // are not a POSIX concept), so the b94fd83 absolute arm
8291 // doesn't fire; the value contains `\` bytes that this arm
8292 // now catches with the more self-locating Windows-path-
8293 // separator diagnostic. Pinned separately from the bare
8294 // `..\caixa-teia` shape so a future arm that targets only
8295 // leading-`..\` doesn't regress the drive-letter coverage.
8296 let d = dep_with_fonte(DepSource::Path {
8297 caminho: "C:\\work\\caixa-teia".into(),
8298 });
8299 let err = d.validate().unwrap_err();
8300 assert!(
8301 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8302 "got {err:?}",
8303 );
8304 }
8305
8306 #[test]
8307 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backslash() {
8308 // The trailing-`\` shape (`..\caixa-teia\` — the canonical
8309 // PowerShell tab-completion-on-a-directory append). Pinned
8310 // separately from the embedded-`\` shape so the gate's
8311 // contract is "any `\` anywhere", not "any `\` not at end".
8312 let d = dep_with_fonte(DepSource::Path {
8313 caminho: "..\\caixa-teia\\".into(),
8314 });
8315 let err = d.validate().unwrap_err();
8316 assert!(
8317 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8318 "got {err:?}",
8319 );
8320 }
8321
8322 #[test]
8323 fn validate_accepts_path_fonte_with_caminho_carrying_legitimate_forward_slash() {
8324 // The positive-control pin: the gate targets `\` only,
8325 // never `/`. The canonical relative POSIX path
8326 // (`../caixa-teia/foo/bar`) must continue to validate cleanly
8327 // so legitimate nested-directory deps aren't broken. Pinned
8328 // so the gate doesn't accidentally widen to a "no path
8329 // separators at all" sweep.
8330 let d = dep_with_fonte(DepSource::Path {
8331 caminho: "../caixa-teia/foo/bar".into(),
8332 });
8333 d.validate().unwrap();
8334 }
8335
8336 #[test]
8337 fn fonte_caminho_control_char_fires_before_backslash() {
8338 // Cascade pin: the control-char arm structurally precedes the
8339 // backslash arm. A value like `"..\caixa\0teia"` probes
8340 // positive on both (`\` byte + NUL byte), but the control-
8341 // char diagnostic wins so the author sees the more self-
8342 // locating POSIX-syscall-rejected-byte diagnostic first
8343 // (NUL outright breaks `CString::new` at every `std::fs`
8344 // syscall boundary; the `\` divergence is the cross-OS-
8345 // separator axis). Mirrors the
8346 // `fonte_caminho_var_fires_before_control_char` cascade
8347 // discipline on the immediate-predecessor arm.
8348 let d = dep_with_fonte(DepSource::Path {
8349 caminho: "..\\caixa\0teia".into(),
8350 });
8351 let err = d.validate().unwrap_err();
8352 assert!(
8353 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8354 "got {err:?}",
8355 );
8356 }
8357
8358 #[test]
8359 fn fonte_caminho_absolute_fires_before_backslash() {
8360 // Cascade pin on the load-bearing leading-byte arm: a leading
8361 // `/` value with embedded `\` (`/etc/passwd\foo`) routes
8362 // through `FonteCaminhoAbsolute` not `FonteCaminhoBackslash`
8363 // — the host-layout-leak diagnostic is the load-bearing
8364 // axis, the `\` byte is the secondary observation. Same
8365 // precedence logic as every prior leading-byte arm.
8366 let d = dep_with_fonte(DepSource::Path {
8367 caminho: "/etc/passwd\\foo".into(),
8368 });
8369 let err = d.validate().unwrap_err();
8370 assert!(
8371 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8372 "got {err:?}",
8373 );
8374 }
8375
8376 #[test]
8377 fn fonte_caminho_var_fires_before_backslash() {
8378 // Cascade pin on the var-expansion arm: a leading-`$` value
8379 // with embedded `\` (`$WORKSPACE\caixa-teia` — the canonical
8380 // PowerShell-env-var paste-from-CI-manifest footgun) routes
8381 // through `FonteCaminhoVarExpansion` not `FonteCaminhoBackslash`.
8382 // The shell-expansion diagnostic is the more self-locating
8383 // axis since both the leading `$` and the embedded `\`
8384 // are Windows-shell artifacts but the `$` is the root-cause
8385 // surface (an author who removes the `$` is likely to leave
8386 // the `\` too).
8387 let d = dep_with_fonte(DepSource::Path {
8388 caminho: "$WORKSPACE\\caixa-teia".into(),
8389 });
8390 let err = d.validate().unwrap_err();
8391 assert!(
8392 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8393 "got {err:?}",
8394 );
8395 }
8396
8397 #[test]
8398 fn fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho() {
8399 // Diagnostic-shape pin (peer with the prior
8400 // `fonte_caminho_*_diagnostic_carries_*` payload assertions
8401 // on every preceding arm): the error's Display surfaces the
8402 // offending `:nome` and the offending `:caminho` verbatim
8403 // so a `feira lint` run can render the diagnostic without
8404 // re-parsing.
8405 let d = dep_with_fonte(DepSource::Path {
8406 caminho: "..\\caixa-teia".into(),
8407 });
8408 let rendered = d.validate().unwrap_err().to_string();
8409 assert!(
8410 rendered.contains("caixa-teia"),
8411 "diagnostic must name the offending dep: {rendered}",
8412 );
8413 assert!(
8414 rendered.contains("..\\caixa-teia"),
8415 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8416 );
8417 assert!(
8418 rendered.contains('\\'),
8419 "diagnostic must reference the backslash footgun: {rendered:?}",
8420 );
8421 }
8422
8423 #[test]
8424 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_slash() {
8425 // The fail-before-pass-after pin for the canonical trailing-`/`
8426 // paste footgun: an author who shell-tab-completes a sibling
8427 // directory (every interactive shell — bash/zsh/fish/nushell —
8428 // appends `/` on tab-completing a directory) produces
8429 // `"../caixa-teia/"`-shape values that silently passed every
8430 // prior arm (the leading byte is `.`, no control bytes, no
8431 // backslash). `Path::join` resolves both shapes to the same
8432 // directory at the resolver, but the lacre embeds the value
8433 // verbatim and the BLAKE3 closures diverge across two
8434 // workstations whose authors differ only in tab-completion
8435 // habits.
8436 let d = dep_with_fonte(DepSource::Path {
8437 caminho: "../caixa-teia/".into(),
8438 });
8439 let err = d.validate().unwrap_err();
8440 let DepError::FonteCaminhoTrailingSlash { nome, caminho } = err else {
8441 panic!("expected FonteCaminhoTrailingSlash, got {err:?}");
8442 };
8443 assert_eq!(nome, "caixa-teia");
8444 assert_eq!(caminho, "../caixa-teia/");
8445 }
8446
8447 #[test]
8448 fn validate_rejects_path_fonte_with_caminho_carrying_bare_dot_slash() {
8449 // The `"./"` shape (the canonical "I meant the caixa.lisp's own
8450 // directory and tab-completed it" footgun). Pinned separately
8451 // from the canonical `"../caixa-teia/"` shape so the gate's
8452 // contract is "any trailing `/`", not "trailing `/` after a leaf
8453 // name".
8454 let d = dep_with_fonte(DepSource::Path {
8455 caminho: "./".into(),
8456 });
8457 let err = d.validate().unwrap_err();
8458 assert!(
8459 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8460 "got {err:?}",
8461 );
8462 }
8463
8464 #[test]
8465 fn validate_rejects_path_fonte_with_caminho_carrying_consecutive_trailing_slashes() {
8466 // The `"foo//"` shape (the canonical "I pasted from a CI manifest
8467 // that double-templated `${VAR}/` over an already-`/`-suffixed
8468 // path" footgun). The gate fires on the last byte being `/`
8469 // regardless of how many `/` precede it; the arm contract is
8470 // "the value ends with `/`", structurally.
8471 let d = dep_with_fonte(DepSource::Path {
8472 caminho: "../caixa-teia//".into(),
8473 });
8474 let err = d.validate().unwrap_err();
8475 assert!(
8476 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8477 "got {err:?}",
8478 );
8479 }
8480
8481 #[test]
8482 fn validate_rejects_path_fonte_with_caminho_carrying_dotdot_trailing_slash() {
8483 // The `"../"` shape (the canonical "I want the parent" tab-
8484 // completion footgun on a bare `..` path). Pinned separately so
8485 // the gate doesn't accidentally narrow to "trailing `/` only on
8486 // multi-segment paths".
8487 let d = dep_with_fonte(DepSource::Path {
8488 caminho: "../".into(),
8489 });
8490 let err = d.validate().unwrap_err();
8491 assert!(
8492 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8493 "got {err:?}",
8494 );
8495 }
8496
8497 #[test]
8498 fn validate_accepts_path_fonte_with_caminho_carrying_internal_slashes() {
8499 // The positive-control pin: the gate targets the trailing byte
8500 // only, never internal `/` separators. The canonical nested
8501 // relative POSIX path (`"../caixa-teia/foo/bar"`) must continue
8502 // to validate cleanly so legitimate deeply-nested deps aren't
8503 // broken. Pinned so the gate doesn't accidentally widen to a
8504 // "no `/` separators anywhere" sweep that would defeat the
8505 // entire path-fonte author surface.
8506 let d = dep_with_fonte(DepSource::Path {
8507 caminho: "../caixa-teia/foo/bar".into(),
8508 });
8509 d.validate().unwrap();
8510 }
8511
8512 #[test]
8513 fn validate_accepts_path_fonte_with_caminho_carrying_bare_dot() {
8514 // The positive-control pin on the degenerate single-`.` shape
8515 // (the canonical "the caixa.lisp's own directory" idiom). The
8516 // gate fires on the trailing byte being `/`, not on the path
8517 // being short, so `"."` (one byte, not `/`) must continue to
8518 // validate cleanly.
8519 let d = dep_with_fonte(DepSource::Path {
8520 caminho: ".".into(),
8521 });
8522 d.validate().unwrap();
8523 }
8524
8525 #[test]
8526 fn fonte_caminho_control_char_fires_before_trailing_slash() {
8527 // Cascade pin: the control-char arm structurally precedes the
8528 // trailing-slash arm. A value like `"../foo\n/"` ends in `/`
8529 // but the embedded LF (`0x0A`) is the load-bearing diagnostic
8530 // (control bytes are the paste-from-multiline-doc footgun the
8531 // d624c8d arm already closes). Mirrors the
8532 // `fonte_caminho_control_char_fires_before_backslash` cascade
8533 // discipline on the immediate-predecessor arm.
8534 let d = dep_with_fonte(DepSource::Path {
8535 caminho: "../foo\n/".into(),
8536 });
8537 let err = d.validate().unwrap_err();
8538 assert!(
8539 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8540 "got {err:?}",
8541 );
8542 }
8543
8544 #[test]
8545 fn fonte_caminho_backslash_fires_before_trailing_slash() {
8546 // Cascade pin on the backslash arm: a value like `"..\foo/"`
8547 // ends in `/` but the embedded `\` is the load-bearing
8548 // diagnostic (the cross-host-OS-separator divergence vector
8549 // the 3a4e1d7 arm closes). Same precedence logic as the prior
8550 // narrower-diagnostic-first cascade.
8551 let d = dep_with_fonte(DepSource::Path {
8552 caminho: "..\\caixa-teia/".into(),
8553 });
8554 let err = d.validate().unwrap_err();
8555 assert!(
8556 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8557 "got {err:?}",
8558 );
8559 }
8560
8561 #[test]
8562 fn fonte_caminho_absolute_fires_before_trailing_slash() {
8563 // Cascade pin on the load-bearing leading-byte arm: a leading
8564 // `/` value with a trailing `/` (`"/etc/passwd/"`) routes
8565 // through `FonteCaminhoAbsolute` not `FonteCaminhoTrailingSlash`
8566 // — the host-layout-leak diagnostic is the load-bearing axis,
8567 // the trailing `/` is the secondary observation. Same
8568 // precedence logic as every prior leading-byte arm.
8569 let d = dep_with_fonte(DepSource::Path {
8570 caminho: "/etc/passwd/".into(),
8571 });
8572 let err = d.validate().unwrap_err();
8573 assert!(
8574 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8575 "got {err:?}",
8576 );
8577 }
8578
8579 #[test]
8580 fn fonte_caminho_trailing_slash_diagnostic_carries_offending_dep_and_caminho() {
8581 // Diagnostic-shape pin (peer with the prior
8582 // `fonte_caminho_*_diagnostic_carries_*` payload assertions on
8583 // every preceding arm): the error's Display surfaces the
8584 // offending `:nome` and the offending `:caminho` verbatim so a
8585 // `feira lint` run can render the diagnostic without re-parsing.
8586 let d = dep_with_fonte(DepSource::Path {
8587 caminho: "../caixa-teia/".into(),
8588 });
8589 let rendered = d.validate().unwrap_err().to_string();
8590 assert!(
8591 rendered.contains("caixa-teia"),
8592 "diagnostic must name the offending dep: {rendered}",
8593 );
8594 assert!(
8595 rendered.contains("../caixa-teia/"),
8596 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8597 );
8598 assert!(
8599 rendered.contains("trailing"),
8600 "diagnostic must reference the trailing-slash footgun: {rendered:?}",
8601 );
8602 }
8603
8604 // -- :caminho shell-redirection metacharacter arm -----------------------
8605
8606 #[test]
8607 fn validate_rejects_path_fonte_with_caminho_carrying_gt_redirection() {
8608 // The fail-before-pass-after pin for the canonical output-redirection
8609 // paste footgun: an author copies a shell pipeline tail
8610 // (`"../caixa-teia>build.log"` — the canonical "I selected the whole
8611 // line including the `> build.log` redirect" idiom) and silently
8612 // passed every prior arm (`Path::is_absolute` false on `..`, no
8613 // control bytes, no backslash, doesn't end in `/`). The lacre
8614 // embedded the value verbatim, the resolver folded it through
8615 // `Path::join` looking for a literal `./../caixa-teia>build.log`
8616 // subdirectory, and the failure surfaced at resolve time with a
8617 // non-self-locating `No such file or directory` error. The new arm
8618 // moves the rejection to validate time and names the offending dep
8619 // + caminho + byte verbatim.
8620 let d = dep_with_fonte(DepSource::Path {
8621 caminho: "../caixa-teia>build.log".into(),
8622 });
8623 let err = d.validate().unwrap_err();
8624 let DepError::FonteCaminhoShellRedirection {
8625 nome,
8626 caminho,
8627 byte,
8628 } = err
8629 else {
8630 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8631 };
8632 assert_eq!(nome, "caixa-teia");
8633 assert_eq!(caminho, "../caixa-teia>build.log");
8634 assert_eq!(byte, b'>');
8635 }
8636
8637 #[test]
8638 fn validate_rejects_path_fonte_with_caminho_carrying_lt_redirection() {
8639 // The symmetric input-redirection paste shape
8640 // (`"../caixa-teia<input.lisp"` — the canonical "I copied a
8641 // `command < input.lisp` line from a tatara-lisp REPL log"
8642 // idiom). Pinned separately from the `>` shape so the gate's
8643 // contract is "any `<` or `>` anywhere", not single-byte coverage.
8644 let d = dep_with_fonte(DepSource::Path {
8645 caminho: "../caixa-teia<input.lisp".into(),
8646 });
8647 let err = d.validate().unwrap_err();
8648 let DepError::FonteCaminhoShellRedirection { byte, .. } = err else {
8649 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8650 };
8651 assert_eq!(byte, b'<');
8652 }
8653
8654 #[test]
8655 fn validate_rejects_path_fonte_with_caminho_carrying_leading_gt_redirection() {
8656 // Leading-position `>` shape (`">../caixa-teia"` — the degenerate
8657 // "I forgot the source side of the redirect" idiom). Pinned
8658 // separately from the embedded-byte shapes so the gate covers
8659 // every position, not only mid-path.
8660 let d = dep_with_fonte(DepSource::Path {
8661 caminho: ">../caixa-teia".into(),
8662 });
8663 let err = d.validate().unwrap_err();
8664 assert!(
8665 matches!(
8666 err,
8667 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8668 ),
8669 "got {err:?}",
8670 );
8671 }
8672
8673 #[test]
8674 fn validate_rejects_path_fonte_with_caminho_carrying_double_gt_append() {
8675 // The bash append-redirection shape (`"../caixa-teia>>build.log"` —
8676 // the canonical "I copied a `>>` append redirect" idiom). The arm
8677 // fires on the first `>` encountered; pinned so a future arm that
8678 // tries to distinguish `>` from `>>` doesn't break the broader
8679 // contract.
8680 let d = dep_with_fonte(DepSource::Path {
8681 caminho: "../caixa-teia>>build.log".into(),
8682 });
8683 let err = d.validate().unwrap_err();
8684 assert!(
8685 matches!(
8686 err,
8687 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8688 ),
8689 "got {err:?}",
8690 );
8691 }
8692
8693 #[test]
8694 fn validate_accepts_path_fonte_with_caminho_carrying_no_redirection() {
8695 // The positive-control pin: the gate targets only `<` / `>`,
8696 // never adjacent printable ASCII or POSIX-valid bytes. The
8697 // canonical relative POSIX path (`"../caixa-teia"`) and a
8698 // nested deeply-pathed variant (`"../caixa-teia/foo/bar"`) must
8699 // continue to validate cleanly so the gate doesn't widen to a
8700 // "no printable punctuation anywhere" sweep that would defeat
8701 // the entire path-fonte author surface.
8702 let d = dep_with_fonte(DepSource::Path {
8703 caminho: "../caixa-teia/foo/bar".into(),
8704 });
8705 d.validate().unwrap();
8706 }
8707
8708 #[test]
8709 fn fonte_caminho_backslash_fires_before_shell_redirection() {
8710 // Cascade pin on the immediate-predecessor arm: a value carrying
8711 // both `\` and `<` / `>` (`"..\caixa-teia>build.log"` — the
8712 // canonical "I pasted a Windows-shell command with output
8713 // redirect" footgun) routes through `FonteCaminhoBackslash` not
8714 // `FonteCaminhoShellRedirection`. The cross-host-OS-separator
8715 // divergence is the load-bearing axis (an author who removes
8716 // the `\` is the root-cause edit; the `>` falls away in the
8717 // same edit since it's downstream of the Windows-shell
8718 // convention).
8719 let d = dep_with_fonte(DepSource::Path {
8720 caminho: "..\\caixa-teia>build.log".into(),
8721 });
8722 let err = d.validate().unwrap_err();
8723 assert!(
8724 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8725 "got {err:?}",
8726 );
8727 }
8728
8729 #[test]
8730 fn fonte_caminho_control_char_fires_before_shell_redirection() {
8731 // Cascade pin on the embedded-control-byte arm: a value carrying
8732 // both a control byte and `<` / `>` (`"../foo\n>bar"` — the
8733 // canonical paste-from-multiline-doc footgun where a newline
8734 // landed mid-caminho) routes through `FonteCaminhoControlChar`
8735 // not `FonteCaminhoShellRedirection`. The POSIX-syscall-
8736 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
8737 // load-bearing axis on every value that probes positive for
8738 // both — mirrors the cascade discipline on every prior arm.
8739 let d = dep_with_fonte(DepSource::Path {
8740 caminho: "../foo\n>bar".into(),
8741 });
8742 let err = d.validate().unwrap_err();
8743 assert!(
8744 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8745 "got {err:?}",
8746 );
8747 }
8748
8749 #[test]
8750 fn fonte_caminho_absolute_fires_before_shell_redirection() {
8751 // Cascade pin on the load-bearing leading-byte arm: a leading
8752 // `/` value with embedded `<` / `>` (`"/etc/passwd>out"`)
8753 // routes through `FonteCaminhoAbsolute` not
8754 // `FonteCaminhoShellRedirection` — the host-layout-leak
8755 // diagnostic is the load-bearing axis, the `>` byte is the
8756 // secondary observation. Same precedence logic as every prior
8757 // leading-byte arm.
8758 let d = dep_with_fonte(DepSource::Path {
8759 caminho: "/etc/passwd>out".into(),
8760 });
8761 let err = d.validate().unwrap_err();
8762 assert!(
8763 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8764 "got {err:?}",
8765 );
8766 }
8767
8768 #[test]
8769 fn fonte_caminho_shell_redirection_fires_before_trailing_slash() {
8770 // Cascade pin on the immediate-successor arm: a value carrying
8771 // both `<` / `>` and a trailing `/` (`"../foo></"` — the
8772 // canonical "I tab-completed a path that already had a
8773 // redirect" footgun) routes through `FonteCaminhoShellRedirection`
8774 // not `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
8775 // the more semantic-locating axis (an author who removes the
8776 // `<` / `>` typically also drops the trailing separator since
8777 // both are paste-from-shell artifacts).
8778 let d = dep_with_fonte(DepSource::Path {
8779 caminho: "../foo></".into(),
8780 });
8781 let err = d.validate().unwrap_err();
8782 assert!(
8783 matches!(
8784 err,
8785 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8786 ),
8787 "got {err:?}",
8788 );
8789 }
8790
8791 #[test]
8792 fn fonte_caminho_shell_redirection_diagnostic_carries_offending_dep_caminho_byte() {
8793 // Diagnostic-shape pin (peer with
8794 // `fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte`'s
8795 // payload assertion on the closest peer arm that also carries a
8796 // `byte` field): the error's Display surfaces the offending
8797 // `:nome`, the offending `:caminho` verbatim, and the offending
8798 // byte in hex (`0x3c` for `<`, `0x3e` for `>`) so a `feira lint`
8799 // run can render the diagnostic without re-parsing.
8800 let d = dep_with_fonte(DepSource::Path {
8801 caminho: "../caixa-teia>build.log".into(),
8802 });
8803 let rendered = d.validate().unwrap_err().to_string();
8804 assert!(
8805 rendered.contains("caixa-teia"),
8806 "diagnostic must name the offending dep: {rendered}",
8807 );
8808 assert!(
8809 rendered.contains("../caixa-teia>build.log"),
8810 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8811 );
8812 assert!(
8813 rendered.contains("0x3e"),
8814 "diagnostic must name the offending byte in hex: {rendered:?}",
8815 );
8816 assert!(
8817 rendered.contains("redirection"),
8818 "diagnostic must name the shell-redirection footgun: {rendered:?}",
8819 );
8820 }
8821
8822 // -- :caminho shell-pipe metacharacter arm ----------------------------
8823
8824 #[test]
8825 fn validate_rejects_path_fonte_with_caminho_carrying_pipe() {
8826 // The fail-before-pass-after pin for the canonical shell-pipe
8827 // paste footgun: an author copies a shell-history line
8828 // (`"../caixa-teia | grep foo"` — the canonical "I selected
8829 // the whole `ls dir | grep` line out of zsh history") and
8830 // silently passed every prior arm (`Path::is_absolute` false
8831 // on `..`, no control bytes, no backslash, no `<` / `>`,
8832 // doesn't end in `/`). The lacre embedded the value verbatim,
8833 // the resolver folded it through `Path::join` looking for a
8834 // literal `./../caixa-teia | grep foo` subdirectory, and the
8835 // failure surfaced at resolve time with a non-self-locating
8836 // `No such file or directory` error. The new arm moves the
8837 // rejection to validate time and names the offending dep +
8838 // caminho verbatim.
8839 let d = dep_with_fonte(DepSource::Path {
8840 caminho: "../caixa-teia | grep foo".into(),
8841 });
8842 let err = d.validate().unwrap_err();
8843 let DepError::FonteCaminhoShellPipe { nome, caminho } = err else {
8844 panic!("expected FonteCaminhoShellPipe, got {err:?}");
8845 };
8846 assert_eq!(nome, "caixa-teia");
8847 assert_eq!(caminho, "../caixa-teia | grep foo");
8848 }
8849
8850 #[test]
8851 fn validate_rejects_path_fonte_with_caminho_carrying_leading_pipe() {
8852 // Leading-position `|` shape (`"|../caixa-teia"` — the
8853 // degenerate "I forgot the source side of the pipe" idiom).
8854 // Pinned separately from the embedded-byte shape so the gate
8855 // covers every position, not only mid-path.
8856 let d = dep_with_fonte(DepSource::Path {
8857 caminho: "|../caixa-teia".into(),
8858 });
8859 let err = d.validate().unwrap_err();
8860 assert!(
8861 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
8862 "got {err:?}",
8863 );
8864 }
8865
8866 #[test]
8867 fn validate_rejects_path_fonte_with_caminho_carrying_double_pipe_or() {
8868 // The bash short-circuit-OR shape (`"../caixa-teia||fallback"`
8869 // — the canonical "I copied a `cmd-a || cmd-b` fallback line"
8870 // idiom). The arm fires on the first `|` encountered; pinned
8871 // so a future arm that tries to distinguish `|` from `||`
8872 // doesn't break the broader contract.
8873 let d = dep_with_fonte(DepSource::Path {
8874 caminho: "../caixa-teia||fallback".into(),
8875 });
8876 let err = d.validate().unwrap_err();
8877 assert!(
8878 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
8879 "got {err:?}",
8880 );
8881 }
8882
8883 #[test]
8884 fn validate_accepts_path_fonte_with_caminho_carrying_no_pipe() {
8885 // The positive-control pin: the gate targets only `|`, never
8886 // adjacent printable ASCII or POSIX-valid bytes. The canonical
8887 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
8888 // pathed variant with adjacent printable punctuation
8889 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
8890 // cleanly so the gate doesn't widen to a "no printable
8891 // punctuation anywhere" sweep that would defeat the entire
8892 // path-fonte author surface.
8893 let d = dep_with_fonte(DepSource::Path {
8894 caminho: "../caixa-teia/sub-dir.v2".into(),
8895 });
8896 d.validate().unwrap();
8897 }
8898
8899 #[test]
8900 fn fonte_caminho_shell_redirection_fires_before_shell_pipe() {
8901 // Cascade pin on the immediate-predecessor arm: a value carrying
8902 // both `<` / `>` and `|` (`"../caixa-teia<input|tee"` — the
8903 // canonical "I pasted a `cmd < input | tee` pipeline tail"
8904 // footgun) routes through `FonteCaminhoShellRedirection` not
8905 // `FonteCaminhoShellPipe`. The input/output redirection
8906 // metachar carries the more self-locating `byte: u8` payload
8907 // (it names which of `<` or `>` triggered), so the prior arm
8908 // wins on every probe-as-both value — same cascade discipline
8909 // every prior `:caminho` arm establishes.
8910 let d = dep_with_fonte(DepSource::Path {
8911 caminho: "../caixa-teia<input|tee".into(),
8912 });
8913 let err = d.validate().unwrap_err();
8914 assert!(
8915 matches!(
8916 err,
8917 DepError::FonteCaminhoShellRedirection { byte: b'<', .. }
8918 ),
8919 "got {err:?}",
8920 );
8921 }
8922
8923 #[test]
8924 fn fonte_caminho_backslash_fires_before_shell_pipe() {
8925 // Cascade pin on the upstream backslash arm: a value carrying
8926 // both `\` and `|` (`"..\caixa-teia|tee"` — the canonical
8927 // "I pasted a Windows-shell command with pipe to tee"
8928 // footgun) routes through `FonteCaminhoBackslash` not
8929 // `FonteCaminhoShellPipe`. The cross-host-OS-separator
8930 // divergence is the load-bearing axis on every probe-as-both
8931 // value (an author who removes the `\` is the root-cause edit;
8932 // the `|` falls away in the same edit since it's downstream of
8933 // the Windows-shell convention).
8934 let d = dep_with_fonte(DepSource::Path {
8935 caminho: "..\\caixa-teia|tee".into(),
8936 });
8937 let err = d.validate().unwrap_err();
8938 assert!(
8939 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8940 "got {err:?}",
8941 );
8942 }
8943
8944 #[test]
8945 fn fonte_caminho_control_char_fires_before_shell_pipe() {
8946 // Cascade pin on the embedded-control-byte arm: a value
8947 // carrying both a control byte and `|` (`"../foo\n|bar"` —
8948 // the canonical paste-from-multiline-doc footgun where a
8949 // newline landed mid-caminho) routes through
8950 // `FonteCaminhoControlChar` not `FonteCaminhoShellPipe`. The
8951 // POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
8952 // diagnostic is the load-bearing axis on every value that
8953 // probes positive for both — mirrors the cascade discipline
8954 // on every prior arm.
8955 let d = dep_with_fonte(DepSource::Path {
8956 caminho: "../foo\n|bar".into(),
8957 });
8958 let err = d.validate().unwrap_err();
8959 assert!(
8960 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8961 "got {err:?}",
8962 );
8963 }
8964
8965 #[test]
8966 fn fonte_caminho_absolute_fires_before_shell_pipe() {
8967 // Cascade pin on the load-bearing leading-byte arm: a leading
8968 // `/` value with embedded `|` (`"/etc/passwd|tee"`) routes
8969 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellPipe`
8970 // — the host-layout-leak diagnostic is the load-bearing axis,
8971 // the `|` byte is the secondary observation. Same precedence
8972 // logic as every prior leading-byte arm.
8973 let d = dep_with_fonte(DepSource::Path {
8974 caminho: "/etc/passwd|tee".into(),
8975 });
8976 let err = d.validate().unwrap_err();
8977 assert!(
8978 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8979 "got {err:?}",
8980 );
8981 }
8982
8983 #[test]
8984 fn fonte_caminho_shell_pipe_fires_before_trailing_slash() {
8985 // Cascade pin on the immediate-successor arm: a value carrying
8986 // both `|` and a trailing `/` (`"../foo|tee/"` — the canonical
8987 // "I tab-completed a path that already had a pipeline tail"
8988 // footgun) routes through `FonteCaminhoShellPipe` not
8989 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
8990 // the more semantic-locating axis (an author who removes the
8991 // `|` typically also drops the trailing separator since both
8992 // are paste-from-shell artifacts).
8993 let d = dep_with_fonte(DepSource::Path {
8994 caminho: "../foo|tee/".into(),
8995 });
8996 let err = d.validate().unwrap_err();
8997 assert!(
8998 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
8999 "got {err:?}",
9000 );
9001 }
9002
9003 #[test]
9004 fn fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho() {
9005 // Diagnostic-shape pin (peer with
9006 // `fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho`
9007 // on the closest single-byte peer arm): the error's Display
9008 // surfaces the offending `:nome` and the offending `:caminho`
9009 // verbatim, and names the shell-pipe footgun explicitly so a
9010 // `feira lint` run can render the diagnostic without
9011 // re-parsing.
9012 let d = dep_with_fonte(DepSource::Path {
9013 caminho: "../caixa-teia | grep foo".into(),
9014 });
9015 let rendered = d.validate().unwrap_err().to_string();
9016 assert!(
9017 rendered.contains("caixa-teia"),
9018 "diagnostic must name the offending dep: {rendered}",
9019 );
9020 assert!(
9021 rendered.contains("../caixa-teia | grep foo"),
9022 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9023 );
9024 assert!(
9025 rendered.contains('|'),
9026 "diagnostic must reference the pipe footgun: {rendered:?}",
9027 );
9028 assert!(
9029 rendered.contains("pipe"),
9030 "diagnostic must name the shell-pipe footgun: {rendered:?}",
9031 );
9032 }
9033
9034 // -- :caminho shell-command-separator metacharacter arm ---------------
9035
9036 #[test]
9037 fn validate_rejects_path_fonte_with_caminho_carrying_semicolon() {
9038 // The fail-before-pass-after pin for the canonical shell-command-
9039 // separator paste footgun: an author copies a shell one-liner
9040 // (`"../caixa-teia; rm -rf build"` — the canonical "I selected the
9041 // whole `cd path; do-thing` chain out of a shell-history block")
9042 // and silently passed every prior arm (`Path::is_absolute` false
9043 // on `..`, no control bytes, no backslash, no `<` / `>`, no `|`,
9044 // doesn't end in `/`). The lacre embedded the value verbatim, the
9045 // resolver folded it through `Path::join` looking for a literal
9046 // `./../caixa-teia; rm -rf build` subdirectory, and the failure
9047 // surfaced at resolve time with a non-self-locating `No such file
9048 // or directory` error. The new arm moves the rejection to validate
9049 // time and names the offending dep + caminho verbatim.
9050 let d = dep_with_fonte(DepSource::Path {
9051 caminho: "../caixa-teia; rm -rf build".into(),
9052 });
9053 let err = d.validate().unwrap_err();
9054 let DepError::FonteCaminhoShellSemicolon { nome, caminho } = err else {
9055 panic!("expected FonteCaminhoShellSemicolon, got {err:?}");
9056 };
9057 assert_eq!(nome, "caixa-teia");
9058 assert_eq!(caminho, "../caixa-teia; rm -rf build");
9059 }
9060
9061 #[test]
9062 fn validate_rejects_path_fonte_with_caminho_carrying_leading_semicolon() {
9063 // Leading-position `;` shape (`";../caixa-teia"` — the degenerate
9064 // "I forgot the prior command side of the separator" idiom).
9065 // Pinned separately from the embedded-byte shape so the gate
9066 // covers every position, not only mid-path.
9067 let d = dep_with_fonte(DepSource::Path {
9068 caminho: ";../caixa-teia".into(),
9069 });
9070 let err = d.validate().unwrap_err();
9071 assert!(
9072 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9073 "got {err:?}",
9074 );
9075 }
9076
9077 #[test]
9078 fn validate_rejects_path_fonte_with_caminho_carrying_double_semicolon() {
9079 // The POSIX `case` arm `;;` terminator shape
9080 // (`"../caixa-teia;;next"` — the canonical "I copied a `case`
9081 // arm tail" idiom). The arm fires on the first `;` encountered;
9082 // pinned so a future arm that tries to distinguish `;` from `;;`
9083 // doesn't break the broader contract.
9084 let d = dep_with_fonte(DepSource::Path {
9085 caminho: "../caixa-teia;;next".into(),
9086 });
9087 let err = d.validate().unwrap_err();
9088 assert!(
9089 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9090 "got {err:?}",
9091 );
9092 }
9093
9094 #[test]
9095 fn validate_accepts_path_fonte_with_caminho_carrying_no_semicolon() {
9096 // The positive-control pin: the gate targets only `;`, never
9097 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9098 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9099 // pathed variant with adjacent printable punctuation
9100 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9101 // cleanly so the gate doesn't widen to a "no printable
9102 // punctuation anywhere" sweep that would defeat the entire
9103 // path-fonte author surface.
9104 let d = dep_with_fonte(DepSource::Path {
9105 caminho: "../caixa-teia/sub-dir.v2".into(),
9106 });
9107 d.validate().unwrap();
9108 }
9109
9110 #[test]
9111 fn fonte_caminho_shell_pipe_fires_before_shell_semicolon() {
9112 // Cascade pin on the immediate-predecessor arm: a value carrying
9113 // both `|` and `;` (`"../caixa-teia | tee; rm"` — the canonical
9114 // "I pasted a `cmd | tee; cleanup` chain" footgun) routes through
9115 // `FonteCaminhoShellPipe` not `FonteCaminhoShellSemicolon`. The
9116 // pipeline-tail paste is the load-bearing root-cause edit on
9117 // every probe-as-both value (an author who removes the `|`
9118 // typically also drops the trailing `; cleanup` since both are
9119 // the same paste-from-shell-history artifact) — same cascade
9120 // discipline every prior `:caminho` arm establishes.
9121 let d = dep_with_fonte(DepSource::Path {
9122 caminho: "../caixa-teia | tee; rm".into(),
9123 });
9124 let err = d.validate().unwrap_err();
9125 assert!(
9126 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9127 "got {err:?}",
9128 );
9129 }
9130
9131 #[test]
9132 fn fonte_caminho_shell_redirection_fires_before_shell_semicolon() {
9133 // Cascade pin on the upstream shell-redirection arm: a value
9134 // carrying both `<` / `>` and `;` (`"../caixa-teia>log; rm"` —
9135 // the canonical "I pasted a `cmd > log; cleanup` chain"
9136 // footgun) routes through `FonteCaminhoShellRedirection` not
9137 // `FonteCaminhoShellSemicolon`. The input/output redirection
9138 // metachar carries the more self-locating `byte: u8` payload
9139 // (it names which of `<` or `>` triggered), so the prior arm
9140 // wins on every probe-as-both value.
9141 let d = dep_with_fonte(DepSource::Path {
9142 caminho: "../caixa-teia>log; rm".into(),
9143 });
9144 let err = d.validate().unwrap_err();
9145 assert!(
9146 matches!(
9147 err,
9148 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9149 ),
9150 "got {err:?}",
9151 );
9152 }
9153
9154 #[test]
9155 fn fonte_caminho_backslash_fires_before_shell_semicolon() {
9156 // Cascade pin on the upstream backslash arm: a value carrying
9157 // both `\` and `;` (`"..\caixa-teia;rm"` — the canonical "I
9158 // pasted a Windows-shell `cd ..\path; cleanup` chain") routes
9159 // through `FonteCaminhoBackslash` not `FonteCaminhoShellSemicolon`.
9160 // The cross-host-OS-separator divergence is the load-bearing axis
9161 // on every probe-as-both value (an author who removes the `\` is
9162 // the root-cause edit; the `;` falls away in the same edit since
9163 // it's downstream of the Windows-shell convention).
9164 let d = dep_with_fonte(DepSource::Path {
9165 caminho: "..\\caixa-teia;rm".into(),
9166 });
9167 let err = d.validate().unwrap_err();
9168 assert!(
9169 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9170 "got {err:?}",
9171 );
9172 }
9173
9174 #[test]
9175 fn fonte_caminho_control_char_fires_before_shell_semicolon() {
9176 // Cascade pin on the embedded-control-byte arm: a value carrying
9177 // both a control byte and `;` (`"../foo\n;bar"` — the canonical
9178 // paste-from-multiline-doc footgun where a newline landed mid-
9179 // caminho) routes through `FonteCaminhoControlChar` not
9180 // `FonteCaminhoShellSemicolon`. The POSIX-syscall-rejected-byte
9181 // / NUL-`CString::new`-fail diagnostic is the load-bearing axis
9182 // on every value that probes positive for both — mirrors the
9183 // cascade discipline on every prior arm.
9184 let d = dep_with_fonte(DepSource::Path {
9185 caminho: "../foo\n;bar".into(),
9186 });
9187 let err = d.validate().unwrap_err();
9188 assert!(
9189 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9190 "got {err:?}",
9191 );
9192 }
9193
9194 #[test]
9195 fn fonte_caminho_absolute_fires_before_shell_semicolon() {
9196 // Cascade pin on the load-bearing leading-byte arm: a leading
9197 // `/` value with embedded `;` (`"/etc/passwd;rm"`) routes
9198 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellSemicolon`
9199 // — the host-layout-leak diagnostic is the load-bearing axis,
9200 // the `;` byte is the secondary observation. Same precedence
9201 // logic as every prior leading-byte arm.
9202 let d = dep_with_fonte(DepSource::Path {
9203 caminho: "/etc/passwd;rm".into(),
9204 });
9205 let err = d.validate().unwrap_err();
9206 assert!(
9207 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9208 "got {err:?}",
9209 );
9210 }
9211
9212 #[test]
9213 fn fonte_caminho_shell_semicolon_fires_before_trailing_slash() {
9214 // Cascade pin on the immediate-successor arm: a value carrying
9215 // both `;` and a trailing `/` (`"../foo;rm/"` — the canonical
9216 // "I tab-completed a path that already had a `; cleanup` tail"
9217 // footgun) routes through `FonteCaminhoShellSemicolon` not
9218 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9219 // the more semantic-locating axis (an author who removes the
9220 // `;` typically also drops the trailing separator since both
9221 // are paste-from-shell artifacts).
9222 let d = dep_with_fonte(DepSource::Path {
9223 caminho: "../foo;rm/".into(),
9224 });
9225 let err = d.validate().unwrap_err();
9226 assert!(
9227 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9228 "got {err:?}",
9229 );
9230 }
9231
9232 #[test]
9233 fn fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho() {
9234 // Diagnostic-shape pin (peer with
9235 // `fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho`
9236 // on the closest single-byte peer arm): the error's Display
9237 // surfaces the offending `:nome` and the offending `:caminho`
9238 // verbatim, and names the shell-command-separator footgun
9239 // explicitly so a `feira lint` run can render the diagnostic
9240 // without re-parsing.
9241 let d = dep_with_fonte(DepSource::Path {
9242 caminho: "../caixa-teia; rm -rf build".into(),
9243 });
9244 let rendered = d.validate().unwrap_err().to_string();
9245 assert!(
9246 rendered.contains("caixa-teia"),
9247 "diagnostic must name the offending dep: {rendered}",
9248 );
9249 assert!(
9250 rendered.contains("../caixa-teia; rm -rf build"),
9251 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9252 );
9253 assert!(
9254 rendered.contains(';'),
9255 "diagnostic must reference the semicolon footgun: {rendered:?}",
9256 );
9257 assert!(
9258 rendered.contains("command-separator"),
9259 "diagnostic must name the shell-command-separator footgun: {rendered:?}",
9260 );
9261 }
9262
9263 #[test]
9264 fn validate_rejects_path_fonte_with_caminho_carrying_ampersand() {
9265 // The fail-before-pass-after pin for the canonical shell-
9266 // background-task paste footgun: an author copies a shell one-
9267 // liner (`"../caixa-teia & sleep 1"` — the canonical "I selected
9268 // the whole `cd path & sleep 1` background-launch out of a
9269 // shell-history block") and silently passed every prior arm
9270 // (`Path::is_absolute` false on `..`, no control bytes, no
9271 // backslash, no `<` / `>`, no `|`, no `;`, doesn't end in `/`).
9272 // The lacre embedded the value verbatim, the resolver folded it
9273 // through `Path::join` looking for a literal `./../caixa-teia &
9274 // sleep 1` subdirectory, and the failure surfaced at resolve
9275 // time with a non-self-locating `No such file or directory`
9276 // error. The new arm moves the rejection to validate time and
9277 // names the offending dep + caminho verbatim.
9278 let d = dep_with_fonte(DepSource::Path {
9279 caminho: "../caixa-teia & sleep 1".into(),
9280 });
9281 let err = d.validate().unwrap_err();
9282 let DepError::FonteCaminhoShellBackground { nome, caminho } = err else {
9283 panic!("expected FonteCaminhoShellBackground, got {err:?}");
9284 };
9285 assert_eq!(nome, "caixa-teia");
9286 assert_eq!(caminho, "../caixa-teia & sleep 1");
9287 }
9288
9289 #[test]
9290 fn validate_rejects_path_fonte_with_caminho_carrying_leading_ampersand() {
9291 // Leading-position `&` shape (`"&../caixa-teia"` — the
9292 // degenerate "I forgot the prior command side of the
9293 // background terminator" idiom). Pinned separately from the
9294 // embedded-byte shape so the gate covers every position, not
9295 // only mid-path.
9296 let d = dep_with_fonte(DepSource::Path {
9297 caminho: "&../caixa-teia".into(),
9298 });
9299 let err = d.validate().unwrap_err();
9300 assert!(
9301 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9302 "got {err:?}",
9303 );
9304 }
9305
9306 #[test]
9307 fn validate_rejects_path_fonte_with_caminho_carrying_double_ampersand() {
9308 // The logical-AND `&&` shape (`"../caixa-teia && make"` — the
9309 // canonical "I copied a `cd path && make` build chain" idiom
9310 // every Makefile / shell-script wraps). The arm fires on the
9311 // first `&` encountered; pinned so a future arm that tries to
9312 // distinguish `&` from `&&` doesn't break the broader contract.
9313 let d = dep_with_fonte(DepSource::Path {
9314 caminho: "../caixa-teia && make".into(),
9315 });
9316 let err = d.validate().unwrap_err();
9317 assert!(
9318 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9319 "got {err:?}",
9320 );
9321 }
9322
9323 #[test]
9324 fn validate_accepts_path_fonte_with_caminho_carrying_no_ampersand() {
9325 // The positive-control pin: the gate targets only `&`, never
9326 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9327 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9328 // pathed variant with adjacent printable punctuation
9329 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9330 // cleanly so the gate doesn't widen to a "no printable
9331 // punctuation anywhere" sweep that would defeat the entire
9332 // path-fonte author surface.
9333 let d = dep_with_fonte(DepSource::Path {
9334 caminho: "../caixa-teia/sub-dir.v2".into(),
9335 });
9336 d.validate().unwrap();
9337 }
9338
9339 #[test]
9340 fn fonte_caminho_shell_semicolon_fires_before_shell_background() {
9341 // Cascade pin on the immediate-predecessor arm: a value carrying
9342 // both `;` and `&` (`"../caixa-teia; rm & sleep"` — the
9343 // canonical "I pasted a `cmd; cleanup & sleep` chain" footgun)
9344 // routes through `FonteCaminhoShellSemicolon` not
9345 // `FonteCaminhoShellBackground`. The sequential-command-
9346 // separator paste is the more common shell-history paste idiom
9347 // on every probe-as-both value (an author who removes the `;`
9348 // typically also drops the trailing `& sleep` since both are
9349 // paste-from-shell-history artifacts) — same cascade discipline
9350 // every prior `:caminho` arm establishes.
9351 let d = dep_with_fonte(DepSource::Path {
9352 caminho: "../caixa-teia; rm & sleep".into(),
9353 });
9354 let err = d.validate().unwrap_err();
9355 assert!(
9356 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9357 "got {err:?}",
9358 );
9359 }
9360
9361 #[test]
9362 fn fonte_caminho_shell_pipe_fires_before_shell_background() {
9363 // Cascade pin on the upstream shell-pipe arm: a value carrying
9364 // both `|` and `&` (`"../caixa-teia | tee & sleep"` — the
9365 // canonical "I pasted a `cmd | tee & sleep` background-pipeline
9366 // chain" footgun) routes through `FonteCaminhoShellPipe` not
9367 // `FonteCaminhoShellBackground`. The pipeline-tail paste is the
9368 // load-bearing root-cause edit on every probe-as-both value.
9369 let d = dep_with_fonte(DepSource::Path {
9370 caminho: "../caixa-teia | tee & sleep".into(),
9371 });
9372 let err = d.validate().unwrap_err();
9373 assert!(
9374 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9375 "got {err:?}",
9376 );
9377 }
9378
9379 #[test]
9380 fn fonte_caminho_shell_redirection_fires_before_shell_background() {
9381 // Cascade pin on the upstream shell-redirection arm: a value
9382 // carrying both `>` and `&` (`"../caixa-teia>log & sleep"` —
9383 // the canonical "I pasted a `cmd > log & sleep` background-
9384 // redirect chain" footgun) routes through
9385 // `FonteCaminhoShellRedirection` not
9386 // `FonteCaminhoShellBackground`. The input/output redirection
9387 // metachar carries the more self-locating `byte: u8` payload
9388 // (it names which of `<` or `>` triggered), so the prior arm
9389 // wins on every probe-as-both value.
9390 let d = dep_with_fonte(DepSource::Path {
9391 caminho: "../caixa-teia>log & sleep".into(),
9392 });
9393 let err = d.validate().unwrap_err();
9394 assert!(
9395 matches!(
9396 err,
9397 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9398 ),
9399 "got {err:?}",
9400 );
9401 }
9402
9403 #[test]
9404 fn fonte_caminho_backslash_fires_before_shell_background() {
9405 // Cascade pin on the upstream backslash arm: a value carrying
9406 // both `\` and `&` (`"..\caixa-teia & sleep"` — the canonical
9407 // "I pasted a Windows-shell `cd ..\path & sleep` background-
9408 // launch chain") routes through `FonteCaminhoBackslash` not
9409 // `FonteCaminhoShellBackground`. The cross-host-OS-separator
9410 // divergence is the load-bearing axis on every probe-as-both
9411 // value (an author who removes the `\` is the root-cause edit;
9412 // the `&` falls away in the same edit since it's downstream of
9413 // the Windows-shell convention).
9414 let d = dep_with_fonte(DepSource::Path {
9415 caminho: "..\\caixa-teia & sleep".into(),
9416 });
9417 let err = d.validate().unwrap_err();
9418 assert!(
9419 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9420 "got {err:?}",
9421 );
9422 }
9423
9424 #[test]
9425 fn fonte_caminho_control_char_fires_before_shell_background() {
9426 // Cascade pin on the embedded-control-byte arm: a value
9427 // carrying both a control byte and `&` (`"../foo\n&sleep"` —
9428 // the canonical paste-from-multiline-doc footgun where a
9429 // newline landed mid-caminho) routes through
9430 // `FonteCaminhoControlChar` not `FonteCaminhoShellBackground`.
9431 // The POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9432 // diagnostic is the load-bearing axis on every value that
9433 // probes positive for both — mirrors the cascade discipline on
9434 // every prior arm.
9435 let d = dep_with_fonte(DepSource::Path {
9436 caminho: "../foo\n&sleep".into(),
9437 });
9438 let err = d.validate().unwrap_err();
9439 assert!(
9440 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9441 "got {err:?}",
9442 );
9443 }
9444
9445 #[test]
9446 fn fonte_caminho_absolute_fires_before_shell_background() {
9447 // Cascade pin on the load-bearing leading-byte arm: a leading
9448 // `/` value with embedded `&` (`"/etc/passwd & sleep"`) routes
9449 // through `FonteCaminhoAbsolute` not
9450 // `FonteCaminhoShellBackground` — the host-layout-leak
9451 // diagnostic is the load-bearing axis, the `&` byte is the
9452 // secondary observation. Same precedence logic as every prior
9453 // leading-byte arm.
9454 let d = dep_with_fonte(DepSource::Path {
9455 caminho: "/etc/passwd & sleep".into(),
9456 });
9457 let err = d.validate().unwrap_err();
9458 assert!(
9459 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9460 "got {err:?}",
9461 );
9462 }
9463
9464 #[test]
9465 fn fonte_caminho_shell_background_fires_before_trailing_slash() {
9466 // Cascade pin on the immediate-successor arm: a value carrying
9467 // both `&` and a trailing `/` (`"../foo&sleep/"` — the
9468 // canonical "I tab-completed a path that already had a `&
9469 // sleep` background-launch tail" footgun) routes through
9470 // `FonteCaminhoShellBackground` not `FonteCaminhoTrailingSlash`.
9471 // The embedded shell-metachar is the more semantic-locating
9472 // axis (an author who removes the `&` typically also drops
9473 // the trailing separator since both are paste-from-shell
9474 // artifacts).
9475 let d = dep_with_fonte(DepSource::Path {
9476 caminho: "../foo&sleep/".into(),
9477 });
9478 let err = d.validate().unwrap_err();
9479 assert!(
9480 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9481 "got {err:?}",
9482 );
9483 }
9484
9485 #[test]
9486 fn fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho() {
9487 // Diagnostic-shape pin (peer with
9488 // `fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho`
9489 // on the closest single-byte peer arm): the error's Display
9490 // surfaces the offending `:nome` and the offending `:caminho`
9491 // verbatim, and names the shell-background / logical-AND
9492 // footgun explicitly so a `feira lint` run can render the
9493 // diagnostic without re-parsing.
9494 let d = dep_with_fonte(DepSource::Path {
9495 caminho: "../caixa-teia & sleep 1".into(),
9496 });
9497 let rendered = d.validate().unwrap_err().to_string();
9498 assert!(
9499 rendered.contains("caixa-teia"),
9500 "diagnostic must name the offending dep: {rendered}",
9501 );
9502 assert!(
9503 rendered.contains("../caixa-teia & sleep 1"),
9504 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9505 );
9506 assert!(
9507 rendered.contains('&'),
9508 "diagnostic must reference the ampersand footgun: {rendered:?}",
9509 );
9510 assert!(
9511 rendered.contains("background") || rendered.contains("list-AND"),
9512 "diagnostic must name the shell-background / logical-AND footgun: {rendered:?}",
9513 );
9514 }
9515
9516 #[test]
9517 fn validate_rejects_path_fonte_with_caminho_carrying_backtick() {
9518 // The fail-before-pass-after pin for the canonical shell-
9519 // command-substitution paste footgun: an author copies a
9520 // POSIX legacy backticked one-liner (`"../caixa-teia/`whoami`"`
9521 // — the canonical "I pasted a path that included a `pwd`
9522 // / `whoami` / `date` legacy command-substitution expansion
9523 // out of a shell-history block") and silently passed every
9524 // prior arm (`Path::is_absolute` false on `..`, no control
9525 // bytes, no `\`, no `<` / `>`, no `|`, no `;`, no `&`, doesn't
9526 // end in `/`). The lacre embedded the value verbatim, the
9527 // resolver folded it through `Path::join` looking for a
9528 // literal `./../caixa-teia/`whoami`` subdirectory, and the
9529 // failure surfaced at resolve time with a non-self-locating
9530 // `No such file or directory` error. The new arm moves the
9531 // rejection to validate time and names the offending dep +
9532 // caminho verbatim.
9533 let d = dep_with_fonte(DepSource::Path {
9534 caminho: "../caixa-teia/`whoami`".into(),
9535 });
9536 let err = d.validate().unwrap_err();
9537 let DepError::FonteCaminhoShellCommandSubstitution { nome, caminho } = err else {
9538 panic!("expected FonteCaminhoShellCommandSubstitution, got {err:?}");
9539 };
9540 assert_eq!(nome, "caixa-teia");
9541 assert_eq!(caminho, "../caixa-teia/`whoami`");
9542 }
9543
9544 #[test]
9545 fn validate_rejects_path_fonte_with_caminho_carrying_leading_backtick() {
9546 // Leading-position backtick shape (``"`pwd`/caixa-teia"`` —
9547 // the canonical `<backtick>pwd<backtick>/path` working-
9548 // directory expansion shape every shell-side path-composition
9549 // idiom carries). Pinned separately from the embedded-byte
9550 // shape so the gate covers every position, not only mid-path.
9551 let d = dep_with_fonte(DepSource::Path {
9552 caminho: "`pwd`/caixa-teia".into(),
9553 });
9554 let err = d.validate().unwrap_err();
9555 assert!(
9556 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9557 "got {err:?}",
9558 );
9559 }
9560
9561 #[test]
9562 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backtick() {
9563 // Trailing-position backtick shape (`"../caixa-teia`"` — the
9564 // degenerate "I selected an unbalanced backtick out of a
9565 // shell-history block" idiom that probes for the cascade's
9566 // last-byte handling). The trailing-`/` arm fires only on
9567 // last-byte `/`; an unbalanced trailing backtick must route
9568 // through this arm regardless of position.
9569 let d = dep_with_fonte(DepSource::Path {
9570 caminho: "../caixa-teia`".into(),
9571 });
9572 let err = d.validate().unwrap_err();
9573 assert!(
9574 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9575 "got {err:?}",
9576 );
9577 }
9578
9579 #[test]
9580 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_backtick_pair() {
9581 // The canonical balanced-pair shape (``"../<backtick>cat
9582 // /etc/passwd<backtick>"`` — the canonical CWE-78 shell-
9583 // command-injection paste idiom every shell-side hardening
9584 // guide enumerates first). The arm fires on the first
9585 // backtick encountered; pinned so a future arm that tries to
9586 // distinguish the opening from the closing byte doesn't break
9587 // the broader contract.
9588 let d = dep_with_fonte(DepSource::Path {
9589 caminho: "../`cat /etc/passwd`".into(),
9590 });
9591 let err = d.validate().unwrap_err();
9592 assert!(
9593 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9594 "got {err:?}",
9595 );
9596 }
9597
9598 #[test]
9599 fn validate_accepts_path_fonte_with_caminho_carrying_no_backtick() {
9600 // The positive-control pin: the gate targets only the
9601 // backtick byte, never adjacent printable ASCII or POSIX-
9602 // valid bytes. The canonical relative POSIX path
9603 // (`"../caixa-teia"`) and a nested deeply-pathed variant with
9604 // adjacent printable punctuation
9605 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9606 // cleanly so the gate doesn't widen to a "no printable
9607 // punctuation anywhere" sweep that would defeat the entire
9608 // path-fonte author surface.
9609 let d = dep_with_fonte(DepSource::Path {
9610 caminho: "../caixa-teia/sub-dir.v2".into(),
9611 });
9612 d.validate().unwrap();
9613 }
9614
9615 #[test]
9616 fn fonte_caminho_shell_background_fires_before_shell_command_substitution() {
9617 // Cascade pin on the immediate-predecessor arm: a value
9618 // carrying both `&` and a backtick (``"../caixa-teia &
9619 // <backtick>sleep 1<backtick>"`` — the canonical "I pasted a
9620 // `cmd & <backtick>sleep N<backtick>` background-launch +
9621 // command-substitution chain" footgun) routes through
9622 // `FonteCaminhoShellBackground` not
9623 // `FonteCaminhoShellCommandSubstitution`. The background-
9624 // launch tail is the more common shell-history paste idiom
9625 // on every probe-as-both value — same cascade discipline
9626 // every prior `:caminho` arm establishes.
9627 let d = dep_with_fonte(DepSource::Path {
9628 caminho: "../caixa-teia & `sleep 1`".into(),
9629 });
9630 let err = d.validate().unwrap_err();
9631 assert!(
9632 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9633 "got {err:?}",
9634 );
9635 }
9636
9637 #[test]
9638 fn fonte_caminho_shell_semicolon_fires_before_shell_command_substitution() {
9639 // Cascade pin on the upstream shell-semicolon arm: a value
9640 // carrying both `;` and a backtick (``"../caixa-teia;
9641 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9642 // `cmd; <backtick>follow-up<backtick>` sequential-chain
9643 // footgun) routes through `FonteCaminhoShellSemicolon` not
9644 // `FonteCaminhoShellCommandSubstitution`. The sequential-
9645 // command-separator paste is the load-bearing root-cause
9646 // edit on every probe-as-both value.
9647 let d = dep_with_fonte(DepSource::Path {
9648 caminho: "../caixa-teia; `whoami`".into(),
9649 });
9650 let err = d.validate().unwrap_err();
9651 assert!(
9652 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9653 "got {err:?}",
9654 );
9655 }
9656
9657 #[test]
9658 fn fonte_caminho_shell_pipe_fires_before_shell_command_substitution() {
9659 // Cascade pin on the upstream shell-pipe arm: a value
9660 // carrying both `|` and a backtick (``"../caixa-teia |
9661 // <backtick>tee log<backtick>"`` — the canonical pipeline-to-
9662 // command-substitution paste idiom) routes through
9663 // `FonteCaminhoShellPipe` not
9664 // `FonteCaminhoShellCommandSubstitution`. The pipeline-tail
9665 // paste is the load-bearing root-cause edit on every
9666 // probe-as-both value.
9667 let d = dep_with_fonte(DepSource::Path {
9668 caminho: "../caixa-teia | `tee log`".into(),
9669 });
9670 let err = d.validate().unwrap_err();
9671 assert!(
9672 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9673 "got {err:?}",
9674 );
9675 }
9676
9677 #[test]
9678 fn fonte_caminho_shell_redirection_fires_before_shell_command_substitution() {
9679 // Cascade pin on the upstream shell-redirection arm: a value
9680 // carrying both `>` and a backtick (``"../caixa-teia>log
9681 // <backtick>date<backtick>"`` — the canonical "I pasted a
9682 // `cmd > log <backtick>date<backtick>` redirect-plus-
9683 // substitution chain" footgun) routes through
9684 // `FonteCaminhoShellRedirection` not
9685 // `FonteCaminhoShellCommandSubstitution`. The input/output
9686 // redirection metachar carries the more self-locating `byte`
9687 // payload (it names which of `<` or `>` triggered), so the
9688 // prior arm wins on every probe-as-both value.
9689 let d = dep_with_fonte(DepSource::Path {
9690 caminho: "../caixa-teia>log `date`".into(),
9691 });
9692 let err = d.validate().unwrap_err();
9693 assert!(
9694 matches!(
9695 err,
9696 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9697 ),
9698 "got {err:?}",
9699 );
9700 }
9701
9702 #[test]
9703 fn fonte_caminho_backslash_fires_before_shell_command_substitution() {
9704 // Cascade pin on the upstream backslash arm: a value
9705 // carrying both `\` and a backtick (``"..\caixa-teia
9706 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9707 // Windows-shell `cd ..\path <backtick>whoami<backtick>`
9708 // chain") routes through `FonteCaminhoBackslash` not
9709 // `FonteCaminhoShellCommandSubstitution`. The cross-host-OS-
9710 // separator divergence is the load-bearing axis on every
9711 // probe-as-both value (an author who removes the `\` is the
9712 // root-cause edit; the backtick falls away in the same edit
9713 // since it's downstream of the Windows-shell convention).
9714 let d = dep_with_fonte(DepSource::Path {
9715 caminho: "..\\caixa-teia `whoami`".into(),
9716 });
9717 let err = d.validate().unwrap_err();
9718 assert!(
9719 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9720 "got {err:?}",
9721 );
9722 }
9723
9724 #[test]
9725 fn fonte_caminho_control_char_fires_before_shell_command_substitution() {
9726 // Cascade pin on the embedded-control-byte arm: a value
9727 // carrying both a control byte and a backtick (`"../foo\n
9728 // `whoami`"` — the canonical paste-from-multiline-doc
9729 // footgun where a newline landed mid-caminho between two
9730 // paste fragments) routes through `FonteCaminhoControlChar`
9731 // not `FonteCaminhoShellCommandSubstitution`. The POSIX-
9732 // syscall-rejected-byte / NUL-`CString::new`-fail diagnostic
9733 // is the load-bearing axis on every value that probes
9734 // positive for both — mirrors the cascade discipline on
9735 // every prior arm.
9736 let d = dep_with_fonte(DepSource::Path {
9737 caminho: "../foo\n`whoami`".into(),
9738 });
9739 let err = d.validate().unwrap_err();
9740 assert!(
9741 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9742 "got {err:?}",
9743 );
9744 }
9745
9746 #[test]
9747 fn fonte_caminho_absolute_fires_before_shell_command_substitution() {
9748 // Cascade pin on the load-bearing leading-byte arm: a
9749 // leading `/` value with embedded backtick (``"/etc/passwd
9750 // <backtick>whoami<backtick>"``) routes through
9751 // `FonteCaminhoAbsolute` not
9752 // `FonteCaminhoShellCommandSubstitution` — the host-layout-
9753 // leak diagnostic is the load-bearing axis, the backtick
9754 // byte is the secondary observation. Same precedence logic
9755 // as every prior leading-byte arm.
9756 let d = dep_with_fonte(DepSource::Path {
9757 caminho: "/etc/passwd `whoami`".into(),
9758 });
9759 let err = d.validate().unwrap_err();
9760 assert!(
9761 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9762 "got {err:?}",
9763 );
9764 }
9765
9766 #[test]
9767 fn fonte_caminho_shell_command_substitution_fires_before_trailing_slash() {
9768 // Cascade pin on the immediate-successor arm: a value
9769 // carrying both a backtick and a trailing `/`
9770 // (``"../`whoami`/"`` — the canonical "I tab-completed a
9771 // path that already had a backticked `whoami` substitution
9772 // tail" footgun) routes through
9773 // `FonteCaminhoShellCommandSubstitution` not
9774 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
9775 // is the more semantic-locating axis (an author who removes
9776 // the backtick typically also drops the trailing separator
9777 // since both are paste-from-shell artifacts).
9778 let d = dep_with_fonte(DepSource::Path {
9779 caminho: "../`whoami`/".into(),
9780 });
9781 let err = d.validate().unwrap_err();
9782 assert!(
9783 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9784 "got {err:?}",
9785 );
9786 }
9787
9788 #[test]
9789 fn fonte_caminho_shell_command_substitution_diagnostic_carries_offending_dep_and_caminho() {
9790 // Diagnostic-shape pin (peer with
9791 // `fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho`
9792 // on the closest single-byte peer arm): the error's Display
9793 // surfaces the offending `:nome` and the offending `:caminho`
9794 // verbatim, and names the shell-command-substitution footgun
9795 // explicitly so a `feira lint` run can render the diagnostic
9796 // without re-parsing.
9797 let d = dep_with_fonte(DepSource::Path {
9798 caminho: "../caixa-teia/`whoami`".into(),
9799 });
9800 let rendered = d.validate().unwrap_err().to_string();
9801 assert!(
9802 rendered.contains("caixa-teia"),
9803 "diagnostic must name the offending dep: {rendered}",
9804 );
9805 assert!(
9806 rendered.contains("../caixa-teia/`whoami`"),
9807 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9808 );
9809 assert!(
9810 rendered.contains('`'),
9811 "diagnostic must reference the backtick footgun: {rendered:?}",
9812 );
9813 assert!(
9814 rendered.contains("command-substitution"),
9815 "diagnostic must name the shell-command-substitution footgun: {rendered:?}",
9816 );
9817 }
9818
9819 #[test]
9820 fn validate_rejects_path_fonte_with_caminho_carrying_star_glob() {
9821 // The fail-before-pass-after pin for the canonical pathname-
9822 // expansion paste footgun: an author copies an `ls
9823 // ../caixa-teia/*` shell-listing tail into the `:caminho`
9824 // slot and silently passes every prior arm
9825 // (`Path::is_absolute` false on `..`, no control bytes, no
9826 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick,
9827 // doesn't end in `/`). The lacre embedded the value
9828 // verbatim, the resolver folded it through `Path::join`
9829 // looking for a literal `./../caixa-teia/*` subdirectory,
9830 // and the failure surfaced at resolve time with a non-self-
9831 // locating `No such file or directory` error. The new arm
9832 // moves the rejection to validate time and names the
9833 // offending dep + caminho + byte verbatim.
9834 let d = dep_with_fonte(DepSource::Path {
9835 caminho: "../caixa-teia/*".into(),
9836 });
9837 let err = d.validate().unwrap_err();
9838 let DepError::FonteCaminhoShellGlob {
9839 nome,
9840 caminho,
9841 byte,
9842 } = err
9843 else {
9844 panic!("expected FonteCaminhoShellGlob, got {err:?}");
9845 };
9846 assert_eq!(nome, "caixa-teia");
9847 assert_eq!(caminho, "../caixa-teia/*");
9848 assert_eq!(byte, b'*');
9849 }
9850
9851 #[test]
9852 fn validate_rejects_path_fonte_with_caminho_carrying_question_glob() {
9853 // The symmetric single-char-wildcard paste shape
9854 // (`"../foo?"` — the canonical "I copied a `rm foo?` line
9855 // out of shell history" idiom). Pinned separately from the
9856 // `*` shape so the gate's contract is "any `*` or `?`
9857 // anywhere", not single-byte coverage.
9858 let d = dep_with_fonte(DepSource::Path {
9859 caminho: "../foo?".into(),
9860 });
9861 let err = d.validate().unwrap_err();
9862 let DepError::FonteCaminhoShellGlob { byte, .. } = err else {
9863 panic!("expected FonteCaminhoShellGlob, got {err:?}");
9864 };
9865 assert_eq!(byte, b'?');
9866 }
9867
9868 #[test]
9869 fn validate_rejects_path_fonte_with_caminho_carrying_leading_star_glob() {
9870 // Leading-position `*` shape (`"*/caixa-teia"` — the
9871 // degenerate "I selected only the wildcard prefix out of a
9872 // shell-glob expression" idiom). Pinned separately from the
9873 // embedded-byte shapes so the gate covers every position,
9874 // not only mid-path.
9875 let d = dep_with_fonte(DepSource::Path {
9876 caminho: "*/caixa-teia".into(),
9877 });
9878 let err = d.validate().unwrap_err();
9879 assert!(
9880 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
9881 "got {err:?}",
9882 );
9883 }
9884
9885 #[test]
9886 fn validate_rejects_path_fonte_with_caminho_carrying_double_star_recursive_glob() {
9887 // The bash/zsh `globstar` recursive-glob shape
9888 // (`"../caixa-teia/**/foo"` — the canonical "I copied a
9889 // `find ../caixa-teia/**/foo` recursive expansion" idiom).
9890 // The arm fires on the first `*` encountered; pinned so a
9891 // future arm that tries to distinguish single `*` from
9892 // double `**` doesn't break the broader contract.
9893 let d = dep_with_fonte(DepSource::Path {
9894 caminho: "../caixa-teia/**/foo".into(),
9895 });
9896 let err = d.validate().unwrap_err();
9897 assert!(
9898 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
9899 "got {err:?}",
9900 );
9901 }
9902
9903 #[test]
9904 fn validate_rejects_path_fonte_with_caminho_carrying_dotted_extension_glob() {
9905 // The canonical extension-glob shape (`"../caixa-teia/*.lisp"`
9906 // — the "I selected `*.lisp` to mean every Lisp source file
9907 // in the dep root" footgun the prior arms structurally
9908 // cannot catch since `.` is a POSIX-valid path-component
9909 // byte). Pinned so the gate's contract covers the most
9910 // idiomatic glob-paste shape every author meets first.
9911 let d = dep_with_fonte(DepSource::Path {
9912 caminho: "../caixa-teia/*.lisp".into(),
9913 });
9914 let err = d.validate().unwrap_err();
9915 assert!(
9916 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
9917 "got {err:?}",
9918 );
9919 }
9920
9921 #[test]
9922 fn validate_accepts_path_fonte_with_caminho_carrying_no_glob() {
9923 // The positive-control pin: the gate targets only `*` /
9924 // `?`, never adjacent printable ASCII or POSIX-valid bytes.
9925 // The canonical relative POSIX path (`"../caixa-teia"`) and
9926 // a nested deeply-pathed variant with adjacent printable
9927 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
9928 // to validate cleanly so the gate doesn't widen to a "no
9929 // printable punctuation anywhere" sweep that would defeat
9930 // the entire path-fonte author surface.
9931 let d = dep_with_fonte(DepSource::Path {
9932 caminho: "../caixa-teia/sub-dir.v2".into(),
9933 });
9934 d.validate().unwrap();
9935 }
9936
9937 #[test]
9938 fn fonte_caminho_shell_command_substitution_fires_before_shell_glob() {
9939 // Cascade pin on the immediate-predecessor arm: a value
9940 // carrying both a backtick and `*` (``"../`whoami`/*"`` —
9941 // the canonical "I pasted a `cd <backtick>whoami<backtick>/*`
9942 // command-substitution + glob chain") routes through
9943 // `FonteCaminhoShellCommandSubstitution` not
9944 // `FonteCaminhoShellGlob`. The CWE-78 shell-command-
9945 // injection vector is the load-bearing root-cause edit on
9946 // every probe-as-both value — same cascade discipline every
9947 // prior `:caminho` arm establishes.
9948 let d = dep_with_fonte(DepSource::Path {
9949 caminho: "../`whoami`/*".into(),
9950 });
9951 let err = d.validate().unwrap_err();
9952 assert!(
9953 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9954 "got {err:?}",
9955 );
9956 }
9957
9958 #[test]
9959 fn fonte_caminho_shell_background_fires_before_shell_glob() {
9960 // Cascade pin on the upstream shell-background arm: a value
9961 // carrying both `&` and `*` (`"../caixa-teia & ls /*"` — the
9962 // canonical "I pasted a `cmd & ls /*` background + glob
9963 // chain" footgun) routes through `FonteCaminhoShellBackground`
9964 // not `FonteCaminhoShellGlob`. The background-launch tail is
9965 // the load-bearing root-cause edit on every probe-as-both
9966 // value.
9967 let d = dep_with_fonte(DepSource::Path {
9968 caminho: "../caixa-teia & ls /*".into(),
9969 });
9970 let err = d.validate().unwrap_err();
9971 assert!(
9972 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9973 "got {err:?}",
9974 );
9975 }
9976
9977 #[test]
9978 fn fonte_caminho_shell_semicolon_fires_before_shell_glob() {
9979 // Cascade pin on the upstream shell-semicolon arm: a value
9980 // carrying both `;` and `*` (`"../caixa-teia; rm *"` — the
9981 // canonical sequential-cleanup + glob paste idiom) routes
9982 // through `FonteCaminhoShellSemicolon` not
9983 // `FonteCaminhoShellGlob`. The sequential-command-separator
9984 // paste is the load-bearing root-cause edit on every
9985 // probe-as-both value.
9986 let d = dep_with_fonte(DepSource::Path {
9987 caminho: "../caixa-teia; rm *".into(),
9988 });
9989 let err = d.validate().unwrap_err();
9990 assert!(
9991 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9992 "got {err:?}",
9993 );
9994 }
9995
9996 #[test]
9997 fn fonte_caminho_shell_pipe_fires_before_shell_glob() {
9998 // Cascade pin on the upstream shell-pipe arm: a value
9999 // carrying both `|` and `*` (`"../caixa-teia | ls *"` — the
10000 // canonical pipeline-to-glob paste idiom) routes through
10001 // `FonteCaminhoShellPipe` not `FonteCaminhoShellGlob`. The
10002 // pipeline-tail paste is the load-bearing root-cause edit
10003 // on every probe-as-both value.
10004 let d = dep_with_fonte(DepSource::Path {
10005 caminho: "../caixa-teia | ls *".into(),
10006 });
10007 let err = d.validate().unwrap_err();
10008 assert!(
10009 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10010 "got {err:?}",
10011 );
10012 }
10013
10014 #[test]
10015 fn fonte_caminho_shell_redirection_fires_before_shell_glob() {
10016 // Cascade pin on the upstream shell-redirection arm: a value
10017 // carrying both `>` and `*` (`"../caixa-teia>log *"` — the
10018 // canonical "I pasted a `cmd > log *` redirect-plus-glob
10019 // chain" footgun) routes through
10020 // `FonteCaminhoShellRedirection` not `FonteCaminhoShellGlob`.
10021 // The input/output redirection metachar carries the more
10022 // self-locating `byte` payload (it names which of `<` or `>`
10023 // triggered), so the prior arm wins on every probe-as-both
10024 // value.
10025 let d = dep_with_fonte(DepSource::Path {
10026 caminho: "../caixa-teia>log *".into(),
10027 });
10028 let err = d.validate().unwrap_err();
10029 assert!(
10030 matches!(
10031 err,
10032 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10033 ),
10034 "got {err:?}",
10035 );
10036 }
10037
10038 #[test]
10039 fn fonte_caminho_backslash_fires_before_shell_glob() {
10040 // Cascade pin on the upstream backslash arm: a value
10041 // carrying both `\` and `*` (`"..\caixa-teia\*"` — the
10042 // canonical "I pasted a Windows-shell `cd ..\path\*` glob
10043 // expression" footgun) routes through
10044 // `FonteCaminhoBackslash` not `FonteCaminhoShellGlob`. The
10045 // cross-host-OS-separator divergence is the load-bearing
10046 // axis on every probe-as-both value (an author who removes
10047 // the `\` is the root-cause edit; the `*` falls away in the
10048 // same edit since it's downstream of the Windows-shell
10049 // convention).
10050 let d = dep_with_fonte(DepSource::Path {
10051 caminho: "..\\caixa-teia\\*".into(),
10052 });
10053 let err = d.validate().unwrap_err();
10054 assert!(
10055 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10056 "got {err:?}",
10057 );
10058 }
10059
10060 #[test]
10061 fn fonte_caminho_control_char_fires_before_shell_glob() {
10062 // Cascade pin on the embedded-control-byte arm: a value
10063 // carrying both a control byte and `*` (`"../foo\n*"` — the
10064 // canonical paste-from-multiline-doc footgun where a
10065 // newline landed mid-caminho between two paste fragments)
10066 // routes through `FonteCaminhoControlChar` not
10067 // `FonteCaminhoShellGlob`. The POSIX-syscall-rejected-byte /
10068 // NUL-`CString::new`-fail diagnostic is the load-bearing
10069 // axis on every value that probes positive for both —
10070 // mirrors the cascade discipline on every prior arm.
10071 let d = dep_with_fonte(DepSource::Path {
10072 caminho: "../foo\n*".into(),
10073 });
10074 let err = d.validate().unwrap_err();
10075 assert!(
10076 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10077 "got {err:?}",
10078 );
10079 }
10080
10081 #[test]
10082 fn fonte_caminho_absolute_fires_before_shell_glob() {
10083 // Cascade pin on the load-bearing leading-byte arm: a
10084 // leading `/` value with embedded `*` (`"/etc/*"`) routes
10085 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellGlob`
10086 // — the host-layout-leak diagnostic is the load-bearing
10087 // axis, the glob byte is the secondary observation. Same
10088 // precedence logic as every prior leading-byte arm.
10089 let d = dep_with_fonte(DepSource::Path {
10090 caminho: "/etc/*".into(),
10091 });
10092 let err = d.validate().unwrap_err();
10093 assert!(
10094 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10095 "got {err:?}",
10096 );
10097 }
10098
10099 #[test]
10100 fn fonte_caminho_shell_glob_fires_before_trailing_slash() {
10101 // Cascade pin on the immediate-successor arm: a value
10102 // carrying both `*` and a trailing `/` (`"../foo*/"` — the
10103 // canonical "I tab-completed a path that already had a
10104 // glob-expansion tail" footgun) routes through
10105 // `FonteCaminhoShellGlob` not `FonteCaminhoTrailingSlash`.
10106 // The embedded shell-metachar is the more semantic-locating
10107 // axis (an author who removes the `*` typically also drops
10108 // the trailing separator since both are paste-from-shell
10109 // artifacts).
10110 let d = dep_with_fonte(DepSource::Path {
10111 caminho: "../foo*/".into(),
10112 });
10113 let err = d.validate().unwrap_err();
10114 assert!(
10115 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10116 "got {err:?}",
10117 );
10118 }
10119
10120 #[test]
10121 fn fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte() {
10122 // Diagnostic-shape pin (peer with
10123 // `fonte_caminho_shell_redirection_diagnostic_*` on the
10124 // closest two-byte peer arm): the error's Display surfaces
10125 // the offending `:nome`, the offending `:caminho` verbatim,
10126 // the offending byte's hex / character form, and names the
10127 // shell-glob / pathname-expansion footgun explicitly so a
10128 // `feira lint` run can render the diagnostic without
10129 // re-parsing.
10130 let d = dep_with_fonte(DepSource::Path {
10131 caminho: "../caixa-teia/*.lisp".into(),
10132 });
10133 let rendered = d.validate().unwrap_err().to_string();
10134 assert!(
10135 rendered.contains("caixa-teia"),
10136 "diagnostic must name the offending dep: {rendered}",
10137 );
10138 assert!(
10139 rendered.contains("../caixa-teia/*.lisp"),
10140 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10141 );
10142 assert!(
10143 rendered.contains("0x2a"),
10144 "diagnostic must surface the offending byte hex: {rendered:?}",
10145 );
10146 assert!(
10147 rendered.contains("glob"),
10148 "diagnostic must name the shell-glob footgun: {rendered:?}",
10149 );
10150 assert!(
10151 rendered.contains("pathname-expansion"),
10152 "diagnostic must reference the POSIX pathname-expansion vocabulary: {rendered:?}",
10153 );
10154 }
10155
10156 #[test]
10157 fn validate_rejects_path_fonte_with_caminho_carrying_modern_command_substitution() {
10158 // The fail-before-pass-after pin for the canonical modern-Bourne
10159 // command-substitution paste footgun: an author copies a
10160 // `cd ../caixa-teia/$(date)/build` shell-history one-liner whose
10161 // `$(<cmd>)` expansion would land the current date as a
10162 // subdirectory name and silently passed every prior arm
10163 // (`Path::is_absolute` false on `..`, no control bytes, no `\`,
10164 // no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no `*` /
10165 // `?`, doesn't end in `/`; the leading-`$` f4efe9c
10166 // `FonteCaminhoVarExpansion` arm doesn't fire because the `$`
10167 // sits mid-path). The lacre embedded the value verbatim, the
10168 // resolver folded it through `Path::join` looking for a literal
10169 // `./../caixa-teia/$(date)/build` subdirectory, and the failure
10170 // surfaced at resolve time with a non-self-locating `No such
10171 // file or directory` error. The new arm moves the rejection to
10172 // validate time and names the offending dep + caminho + byte
10173 // verbatim. The arm fires on the first `(` encountered (the
10174 // opening byte of `$(date)`).
10175 let d = dep_with_fonte(DepSource::Path {
10176 caminho: "../caixa-teia/$(date)/build".into(),
10177 });
10178 let err = d.validate().unwrap_err();
10179 let DepError::FonteCaminhoShellSubshellGrouping {
10180 nome,
10181 caminho,
10182 byte,
10183 } = err
10184 else {
10185 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10186 };
10187 assert_eq!(nome, "caixa-teia");
10188 assert_eq!(caminho, "../caixa-teia/$(date)/build");
10189 assert_eq!(byte, b'(');
10190 }
10191
10192 #[test]
10193 fn validate_rejects_path_fonte_with_caminho_carrying_close_paren() {
10194 // The symmetric close-paren paste shape (`"../caixa-teia)"` —
10195 // the degenerate "I selected an unbalanced closing paren out of
10196 // a shell-history block" idiom that probes for the cascade's
10197 // last-byte handling on a value carrying only the closing byte).
10198 // Pinned separately from the open-paren shape so the gate's
10199 // contract is "any `(` or `)` anywhere", not single-byte
10200 // coverage. Mirrors the peer `validate_rejects_path_fonte_with_\
10201 // caminho_carrying_question_glob` shape on the immediate-
10202 // predecessor `FonteCaminhoShellGlob` arm.
10203 let d = dep_with_fonte(DepSource::Path {
10204 caminho: "../caixa-teia)".into(),
10205 });
10206 let err = d.validate().unwrap_err();
10207 let DepError::FonteCaminhoShellSubshellGrouping { byte, .. } = err else {
10208 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10209 };
10210 assert_eq!(byte, b')');
10211 }
10212
10213 #[test]
10214 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_paren() {
10215 // Leading-position `(` shape (`"(cd foo)/caixa-teia"` — the
10216 // canonical "I selected a `(cd foo)` subshell-grouping prefix
10217 // out of a `(cd foo) && cmd` shell-history one-liner" idiom).
10218 // Pinned separately from the embedded-byte shape so the gate
10219 // covers every position, not only mid-path.
10220 let d = dep_with_fonte(DepSource::Path {
10221 caminho: "(cd foo)/caixa-teia".into(),
10222 });
10223 let err = d.validate().unwrap_err();
10224 assert!(
10225 matches!(
10226 err,
10227 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10228 ),
10229 "got {err:?}",
10230 );
10231 }
10232
10233 #[test]
10234 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_subshell_grouping_pair() {
10235 // The canonical balanced-pair shape (`"../(pwd)/caixa-teia"`
10236 // — the canonical "I copied a `(pwd)` working-directory-probe
10237 // subshell-grouping idiom every shell-history block carries"
10238 // footgun). The value carries no other cascade-preceding
10239 // shell metachar (`&` / `;` / `|` / `<` / `>` / backtick /
10240 // `*` / `?`) so the arm fires on the first `(` encountered;
10241 // pinned so a future arm that tries to distinguish the
10242 // opening from the closing byte doesn't break the broader
10243 // contract. Mirrors the peer
10244 // `validate_rejects_path_fonte_with_caminho_carrying_balanced_\
10245 // backtick_pair` shape on the upstream `FonteCaminhoShell\
10246 // CommandSubstitution` arm.
10247 let d = dep_with_fonte(DepSource::Path {
10248 caminho: "../(pwd)/caixa-teia".into(),
10249 });
10250 let err = d.validate().unwrap_err();
10251 assert!(
10252 matches!(
10253 err,
10254 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10255 ),
10256 "got {err:?}",
10257 );
10258 }
10259
10260 #[test]
10261 fn validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping() {
10262 // The positive-control pin: the gate targets only `(` / `)`,
10263 // never adjacent printable ASCII or POSIX-valid bytes. The
10264 // canonical relative POSIX path (`"../caixa-teia"`) and a
10265 // nested deeply-pathed variant with adjacent printable
10266 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10267 // validate cleanly so the gate doesn't widen to a "no printable
10268 // punctuation anywhere" sweep that would defeat the entire
10269 // path-fonte author surface.
10270 let d = dep_with_fonte(DepSource::Path {
10271 caminho: "../caixa-teia/sub-dir.v2".into(),
10272 });
10273 d.validate().unwrap();
10274 }
10275
10276 #[test]
10277 fn fonte_caminho_shell_glob_fires_before_shell_subshell_grouping() {
10278 // Cascade pin on the immediate-predecessor arm: a value
10279 // carrying both `*` and `(` (`"../caixa-teia/*(date)"` — the
10280 // canonical "I pasted a glob expansion followed by a
10281 // subshell-grouping tail" footgun) routes through
10282 // `FonteCaminhoShellGlob` not
10283 // `FonteCaminhoShellSubshellGrouping`. The pathname-expansion
10284 // shape is the more common shell-history paste idiom on every
10285 // probe-as-both value — same cascade discipline every prior
10286 // `:caminho` arm establishes.
10287 let d = dep_with_fonte(DepSource::Path {
10288 caminho: "../caixa-teia/*(date)".into(),
10289 });
10290 let err = d.validate().unwrap_err();
10291 assert!(
10292 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10293 "got {err:?}",
10294 );
10295 }
10296
10297 #[test]
10298 fn fonte_caminho_shell_command_substitution_fires_before_shell_subshell_grouping() {
10299 // Cascade pin on the upstream shell-command-substitution arm: a
10300 // value carrying both a backtick and `(` (``"../`whoami`/$(date)"``
10301 // — the canonical "I pasted a legacy-backtick + modern-paren
10302 // command-substitution chain" footgun) routes through
10303 // `FonteCaminhoShellCommandSubstitution` not
10304 // `FonteCaminhoShellSubshellGrouping`. The CWE-78 shell-
10305 // command-injection vector is the load-bearing root-cause edit
10306 // on every probe-as-both value.
10307 let d = dep_with_fonte(DepSource::Path {
10308 caminho: "../`whoami`/$(date)".into(),
10309 });
10310 let err = d.validate().unwrap_err();
10311 assert!(
10312 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10313 "got {err:?}",
10314 );
10315 }
10316
10317 #[test]
10318 fn fonte_caminho_shell_background_fires_before_shell_subshell_grouping() {
10319 // Cascade pin on the upstream shell-background arm: a value
10320 // carrying both `&` and `(` (`"../caixa-teia & (cd foo)"` —
10321 // the canonical "I pasted a `cmd & (cd foo)` background-launch
10322 // + subshell-grouping chain" footgun) routes through
10323 // `FonteCaminhoShellBackground` not
10324 // `FonteCaminhoShellSubshellGrouping`. The background-launch
10325 // tail is the load-bearing root-cause edit on every probe-as-
10326 // both value.
10327 let d = dep_with_fonte(DepSource::Path {
10328 caminho: "../caixa-teia & (cd foo)".into(),
10329 });
10330 let err = d.validate().unwrap_err();
10331 assert!(
10332 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10333 "got {err:?}",
10334 );
10335 }
10336
10337 #[test]
10338 fn fonte_caminho_shell_semicolon_fires_before_shell_subshell_grouping() {
10339 // Cascade pin on the upstream shell-semicolon arm: a value
10340 // carrying both `;` and `(` (`"../caixa-teia; (cd foo)"` —
10341 // the canonical sequential-cleanup + subshell-grouping paste
10342 // idiom) routes through `FonteCaminhoShellSemicolon` not
10343 // `FonteCaminhoShellSubshellGrouping`. The sequential-command-
10344 // separator paste is the load-bearing root-cause edit on
10345 // every probe-as-both value.
10346 let d = dep_with_fonte(DepSource::Path {
10347 caminho: "../caixa-teia; (cd foo)".into(),
10348 });
10349 let err = d.validate().unwrap_err();
10350 assert!(
10351 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10352 "got {err:?}",
10353 );
10354 }
10355
10356 #[test]
10357 fn fonte_caminho_shell_pipe_fires_before_shell_subshell_grouping() {
10358 // Cascade pin on the upstream shell-pipe arm: a value carrying
10359 // both `|` and `(` (`"../caixa-teia | (tee log)"` — the
10360 // canonical pipeline-to-subshell-grouping paste idiom) routes
10361 // through `FonteCaminhoShellPipe` not
10362 // `FonteCaminhoShellSubshellGrouping`. The pipeline-tail paste
10363 // is the load-bearing root-cause edit on every probe-as-both
10364 // value.
10365 let d = dep_with_fonte(DepSource::Path {
10366 caminho: "../caixa-teia | (tee log)".into(),
10367 });
10368 let err = d.validate().unwrap_err();
10369 assert!(
10370 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10371 "got {err:?}",
10372 );
10373 }
10374
10375 #[test]
10376 fn fonte_caminho_shell_redirection_fires_before_shell_subshell_grouping() {
10377 // Cascade pin on the upstream shell-redirection arm: a value
10378 // carrying both `>` and `(` (`"../caixa-teia>log (cd foo)"` —
10379 // the canonical "I pasted a `cmd > log (cd foo)` redirect-
10380 // plus-subshell-grouping chain" footgun) routes through
10381 // `FonteCaminhoShellRedirection` not
10382 // `FonteCaminhoShellSubshellGrouping`. The input/output
10383 // redirection metachar carries the more self-locating `byte`
10384 // payload (it names which of `<` or `>` triggered), so the
10385 // prior arm wins on every probe-as-both value.
10386 let d = dep_with_fonte(DepSource::Path {
10387 caminho: "../caixa-teia>log (cd foo)".into(),
10388 });
10389 let err = d.validate().unwrap_err();
10390 assert!(
10391 matches!(
10392 err,
10393 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10394 ),
10395 "got {err:?}",
10396 );
10397 }
10398
10399 #[test]
10400 fn fonte_caminho_backslash_fires_before_shell_subshell_grouping() {
10401 // Cascade pin on the upstream backslash arm: a value carrying
10402 // both `\` and `(` (`"..\caixa-teia\(cd foo)"` — the canonical
10403 // "I pasted a Windows-shell `cd ..\path\(cmd)` chain") routes
10404 // through `FonteCaminhoBackslash` not
10405 // `FonteCaminhoShellSubshellGrouping`. The cross-host-OS-
10406 // separator divergence is the load-bearing axis on every
10407 // probe-as-both value (an author who removes the `\` is the
10408 // root-cause edit; the `(` falls away in the same edit since
10409 // it's downstream of the Windows-shell convention).
10410 let d = dep_with_fonte(DepSource::Path {
10411 caminho: "..\\caixa-teia\\(cd foo)".into(),
10412 });
10413 let err = d.validate().unwrap_err();
10414 assert!(
10415 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10416 "got {err:?}",
10417 );
10418 }
10419
10420 #[test]
10421 fn fonte_caminho_control_char_fires_before_shell_subshell_grouping() {
10422 // Cascade pin on the embedded-control-byte arm: a value
10423 // carrying both a control byte and `(` (`"../foo\n(cd bar)"` —
10424 // the canonical paste-from-multiline-doc footgun where a
10425 // newline landed mid-caminho between two paste fragments)
10426 // routes through `FonteCaminhoControlChar` not
10427 // `FonteCaminhoShellSubshellGrouping`. The POSIX-syscall-
10428 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10429 // load-bearing axis on every value that probes positive for
10430 // both — mirrors the cascade discipline on every prior arm.
10431 let d = dep_with_fonte(DepSource::Path {
10432 caminho: "../foo\n(cd bar)".into(),
10433 });
10434 let err = d.validate().unwrap_err();
10435 assert!(
10436 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10437 "got {err:?}",
10438 );
10439 }
10440
10441 #[test]
10442 fn fonte_caminho_absolute_fires_before_shell_subshell_grouping() {
10443 // Cascade pin on the load-bearing leading-byte arm: a leading
10444 // `/` value with embedded `(` (`"/etc/(cd foo)"`) routes
10445 // through `FonteCaminhoAbsolute` not
10446 // `FonteCaminhoShellSubshellGrouping` — the host-layout-leak
10447 // diagnostic is the load-bearing axis, the subshell-grouping
10448 // byte is the secondary observation. Same precedence logic as
10449 // every prior leading-byte arm.
10450 let d = dep_with_fonte(DepSource::Path {
10451 caminho: "/etc/(cd foo)".into(),
10452 });
10453 let err = d.validate().unwrap_err();
10454 assert!(
10455 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10456 "got {err:?}",
10457 );
10458 }
10459
10460 #[test]
10461 fn fonte_caminho_var_expansion_fires_before_shell_subshell_grouping() {
10462 // Cascade pin on the upstream leading-`$` var-expansion arm: a
10463 // value carrying both a leading `$` and a `(` (`"$(date)/\
10464 // caixa-teia"` — the canonical "I pasted a `$(date)` modern-
10465 // command-substitution at the head of a sibling-workspace
10466 // path" footgun) routes through `FonteCaminhoVarExpansion` not
10467 // `FonteCaminhoShellSubshellGrouping`. The leading-byte
10468 // shell-variable-expansion is the more self-locating diagnostic
10469 // on values that probe as both — same load-bearing-leading-
10470 // byte cascade discipline every prior `:caminho` arm
10471 // establishes. Closing both halves of `$(<cmd>)` structurally
10472 // (leading `$` here, trailing `)` on the new arm) excludes the
10473 // entire modern Bourne command-substitution surface from the
10474 // typed `:caminho` accepted set; the cascade preserves the
10475 // narrower leading-byte diagnostic on values that probe both
10476 // halves at the canonical leading position.
10477 let d = dep_with_fonte(DepSource::Path {
10478 caminho: "$(date)/caixa-teia".into(),
10479 });
10480 let err = d.validate().unwrap_err();
10481 assert!(
10482 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
10483 "got {err:?}",
10484 );
10485 }
10486
10487 #[test]
10488 fn fonte_caminho_shell_subshell_grouping_fires_before_trailing_slash() {
10489 // Cascade pin on the immediate-successor arm: a value carrying
10490 // both `(` and a trailing `/` (`"../(cd foo)/"` — the canonical
10491 // "I tab-completed a path that already had a subshell-grouping
10492 // expansion tail" footgun) routes through
10493 // `FonteCaminhoShellSubshellGrouping` not
10494 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
10495 // the more semantic-locating axis (an author who removes the
10496 // `(` typically also drops the trailing separator since both
10497 // are paste-from-shell artifacts).
10498 let d = dep_with_fonte(DepSource::Path {
10499 caminho: "../(cd foo)/".into(),
10500 });
10501 let err = d.validate().unwrap_err();
10502 assert!(
10503 matches!(
10504 err,
10505 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10506 ),
10507 "got {err:?}",
10508 );
10509 }
10510
10511 #[test]
10512 fn fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
10513 // Diagnostic-shape pin (peer with
10514 // `fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte`
10515 // on the closest two-byte peer arm): the error's Display
10516 // surfaces the offending `:nome`, the offending `:caminho`
10517 // verbatim, the offending byte's hex / character form, and
10518 // names the shell-subshell-grouping footgun explicitly so a
10519 // `feira lint` run can render the diagnostic without re-
10520 // parsing.
10521 let d = dep_with_fonte(DepSource::Path {
10522 caminho: "../caixa-teia/$(date)/build".into(),
10523 });
10524 let rendered = d.validate().unwrap_err().to_string();
10525 assert!(
10526 rendered.contains("caixa-teia"),
10527 "diagnostic must name the offending dep: {rendered}",
10528 );
10529 assert!(
10530 rendered.contains("../caixa-teia/$(date)/build"),
10531 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10532 );
10533 assert!(
10534 rendered.contains("0x28"),
10535 "diagnostic must surface the offending byte hex: {rendered:?}",
10536 );
10537 assert!(
10538 rendered.contains("subshell-grouping"),
10539 "diagnostic must name the shell-subshell-grouping footgun: {rendered:?}",
10540 );
10541 assert!(
10542 rendered.contains("command-substitution"),
10543 "diagnostic must reference the `$(<cmd>)` command-substitution vocabulary: \
10544 {rendered:?}",
10545 );
10546 }
10547
10548 // ── shell-brace-expansion / URI-Template-placeholder arm ───────────
10549 //
10550 // Peer with the prior `FonteCaminhoShellSubshellGrouping` (`(` /
10551 // `)`) byte-pair arm: the same per-byte cascade with the same
10552 // self-locating `byte: u8` diagnostic on the orthogonal `{` /
10553 // `}` brace-expansion / URI-Template placeholder axis. The peer
10554 // [`crate::render::is_git_repo_url`] (42d8f9d) closes the same
10555 // byte pair on the sibling `:fonte :repo` axis under the same
10556 // banner.
10557
10558 #[test]
10559 fn validate_rejects_path_fonte_with_caminho_carrying_brace_expansion_fan_across_siblings() {
10560 // The fail-before-pass-after pin for the canonical paste-from-
10561 // shell-history brace-expansion footgun: an author copies a
10562 // `cd ../{caixa-teia,caixa-helm}/build` shell-history one-
10563 // liner whose `{a,b}` brace expansion fans across two siblings
10564 // and silently passed every prior arm (`Path::is_absolute`
10565 // false on `..`, no control bytes, no `\`, no `<` / `>`, no
10566 // `|`, no `;`, no `&`, no backtick, no `*` / `?`, no `(` /
10567 // `)`, doesn't end in `/`; the leading-`$` f4efe9c
10568 // `FonteCaminhoVarExpansion` arm doesn't fire because the
10569 // value starts with `..` not `$`). The lacre embedded the
10570 // value verbatim, the resolver folded it through `Path::join`
10571 // looking for a literal `./../{caixa-teia,caixa-helm}/build`
10572 // subdirectory, and the failure surfaced at resolve time with
10573 // a non-self-locating `No such file or directory` error. The
10574 // new arm moves the rejection to validate time and names the
10575 // offending dep + caminho + byte verbatim. The arm fires on
10576 // the first `{` encountered.
10577 let d = dep_with_fonte(DepSource::Path {
10578 caminho: "../{caixa-teia,caixa-helm}/build".into(),
10579 });
10580 let err = d.validate().unwrap_err();
10581 let DepError::FonteCaminhoShellBraceExpansion {
10582 nome,
10583 caminho,
10584 byte,
10585 } = err
10586 else {
10587 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10588 };
10589 assert_eq!(nome, "caixa-teia");
10590 assert_eq!(caminho, "../{caixa-teia,caixa-helm}/build");
10591 assert_eq!(byte, b'{');
10592 }
10593
10594 #[test]
10595 fn validate_rejects_path_fonte_with_caminho_carrying_close_brace() {
10596 // The symmetric close-brace paste shape (`"../caixa-teia}"` —
10597 // the degenerate "I selected an unbalanced closing brace out
10598 // of a shell-history block" idiom that probes for the
10599 // cascade's last-byte handling on a value carrying only the
10600 // closing byte). Pinned separately from the open-brace shape
10601 // so the gate's contract is "any `{` or `}` anywhere", not
10602 // single-byte coverage. Mirrors the peer
10603 // `validate_rejects_path_fonte_with_caminho_carrying_close_paren`
10604 // shape on the immediate-predecessor `FonteCaminhoShellSubshellGrouping`
10605 // arm.
10606 let d = dep_with_fonte(DepSource::Path {
10607 caminho: "../caixa-teia}".into(),
10608 });
10609 let err = d.validate().unwrap_err();
10610 let DepError::FonteCaminhoShellBraceExpansion { byte, .. } = err else {
10611 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10612 };
10613 assert_eq!(byte, b'}');
10614 }
10615
10616 #[test]
10617 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_brace() {
10618 // Leading-position `{` shape (`"{caixa-teia,caixa-helm}/build"`
10619 // — the canonical "I selected a `{a,b}` brace-expansion prefix
10620 // out of a shell-history one-liner" idiom). Pinned separately
10621 // from the embedded-byte shape so the gate covers every
10622 // position, not only mid-path.
10623 let d = dep_with_fonte(DepSource::Path {
10624 caminho: "{caixa-teia,caixa-helm}/build".into(),
10625 });
10626 let err = d.validate().unwrap_err();
10627 assert!(
10628 matches!(
10629 err,
10630 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10631 ),
10632 "got {err:?}",
10633 );
10634 }
10635
10636 #[test]
10637 fn validate_rejects_path_fonte_with_caminho_carrying_uri_template_placeholder() {
10638 // The canonical URI-Template / Mustache / Helm doubled-brace
10639 // placeholder shape (`"../{{org}}/caixa-teia"` — the canonical
10640 // "I copied a `https://github.com/{{org}}/caixa-teia` README
10641 // quick-start / OpenAPI spec / Helm chart `home:` template
10642 // and forgot to substitute the placeholder" footgun). The arm
10643 // fires on the first `{` encountered; pinned so the gate's
10644 // coverage extends from the bare-brace shell-history shape to
10645 // the doubled-brace URI-Template / templating-engine shape.
10646 // Mirrors the peer 42d8f9d `is_git_repo_url` arm on the
10647 // sibling `:fonte :repo` axis.
10648 let d = dep_with_fonte(DepSource::Path {
10649 caminho: "../{{org}}/caixa-teia".into(),
10650 });
10651 let err = d.validate().unwrap_err();
10652 assert!(
10653 matches!(
10654 err,
10655 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10656 ),
10657 "got {err:?}",
10658 );
10659 }
10660
10661 #[test]
10662 fn validate_rejects_path_fonte_with_caminho_carrying_brace_range_expansion() {
10663 // The canonical bash brace-range-expansion shape (`"../caixa-
10664 // v{1..10}"` — the `{1..10}` sequence expansion every bash /
10665 // zsh `for i in {1..10}; do …; done` idiom uses, the symmetric
10666 // sequence-range form to the `{a,b,c}` comma-separated form).
10667 // The arm fires on the first `{` encountered; pinned so the
10668 // gate's coverage extends from the comma-separated form to
10669 // the integer-range form.
10670 let d = dep_with_fonte(DepSource::Path {
10671 caminho: "../caixa-v{1..10}".into(),
10672 });
10673 let err = d.validate().unwrap_err();
10674 assert!(
10675 matches!(
10676 err,
10677 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10678 ),
10679 "got {err:?}",
10680 );
10681 }
10682
10683 #[test]
10684 fn validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion() {
10685 // The positive-control pin: the gate targets only `{` / `}`,
10686 // never adjacent printable ASCII or POSIX-valid bytes. The
10687 // canonical relative POSIX path (`"../caixa-teia"`) and a
10688 // nested deeply-pathed variant with adjacent printable
10689 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10690 // validate cleanly so the gate doesn't widen to a "no
10691 // printable punctuation anywhere" sweep that would defeat
10692 // the entire path-fonte author surface. Peer with
10693 // `validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping`
10694 // on the immediate-predecessor arm.
10695 let d = dep_with_fonte(DepSource::Path {
10696 caminho: "../caixa-teia/sub-dir.v2".into(),
10697 });
10698 d.validate().unwrap();
10699 }
10700
10701 #[test]
10702 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_brace_expansion() {
10703 // Cascade pin on the immediate-predecessor arm: a value
10704 // carrying both `(` and `{` (`"../(cd foo)/{a,b}"` — the
10705 // canonical "I pasted a subshell-grouping followed by a
10706 // brace-expansion tail" footgun) routes through
10707 // `FonteCaminhoShellSubshellGrouping` not
10708 // `FonteCaminhoShellBraceExpansion`. The subshell-grouping
10709 // shape is the more semantic-locating axis on every probe-
10710 // as-both value because it closes both halves of the modern
10711 // Bourne `$(<cmd>)` command-substitution surface — same
10712 // cascade discipline every prior `:caminho` arm establishes.
10713 let d = dep_with_fonte(DepSource::Path {
10714 caminho: "../(cd foo)/{a,b}".into(),
10715 });
10716 let err = d.validate().unwrap_err();
10717 assert!(
10718 matches!(
10719 err,
10720 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10721 ),
10722 "got {err:?}",
10723 );
10724 }
10725
10726 #[test]
10727 fn fonte_caminho_shell_glob_fires_before_shell_brace_expansion() {
10728 // Cascade pin on the upstream shell-glob arm: a value carrying
10729 // both `*` and `{` (`"../caixa-teia/*{a,b}"` — the canonical
10730 // "I pasted a glob expansion followed by a brace-expansion
10731 // tail" footgun) routes through `FonteCaminhoShellGlob` not
10732 // `FonteCaminhoShellBraceExpansion`. The pathname-expansion
10733 // shape is the load-bearing root-cause edit on every
10734 // probe-as-both value.
10735 let d = dep_with_fonte(DepSource::Path {
10736 caminho: "../caixa-teia/*{a,b}".into(),
10737 });
10738 let err = d.validate().unwrap_err();
10739 assert!(
10740 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10741 "got {err:?}",
10742 );
10743 }
10744
10745 #[test]
10746 fn fonte_caminho_shell_command_substitution_fires_before_shell_brace_expansion() {
10747 // Cascade pin on the upstream shell-command-substitution arm:
10748 // a value carrying both a backtick and `{` (``"../`whoami`/{a,b}"``
10749 // — the canonical "I pasted a legacy-backtick command-
10750 // substitution followed by a brace-expansion fan-out" footgun)
10751 // routes through `FonteCaminhoShellCommandSubstitution` not
10752 // `FonteCaminhoShellBraceExpansion`. The CWE-78 shell-
10753 // command-injection vector is the load-bearing root-cause
10754 // edit on every probe-as-both value.
10755 let d = dep_with_fonte(DepSource::Path {
10756 caminho: "../`whoami`/{a,b}".into(),
10757 });
10758 let err = d.validate().unwrap_err();
10759 assert!(
10760 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10761 "got {err:?}",
10762 );
10763 }
10764
10765 #[test]
10766 fn fonte_caminho_shell_background_fires_before_shell_brace_expansion() {
10767 // Cascade pin on the upstream shell-background arm: a value
10768 // carrying both `&` and `{` (`"../caixa-teia & {a,b}"` — the
10769 // canonical "I pasted a `cmd & {fork-fan}` background-launch
10770 // + brace-expansion chain" footgun) routes through
10771 // `FonteCaminhoShellBackground` not
10772 // `FonteCaminhoShellBraceExpansion`. The background-launch
10773 // tail is the load-bearing root-cause edit on every
10774 // probe-as-both value.
10775 let d = dep_with_fonte(DepSource::Path {
10776 caminho: "../caixa-teia & {a,b}".into(),
10777 });
10778 let err = d.validate().unwrap_err();
10779 assert!(
10780 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10781 "got {err:?}",
10782 );
10783 }
10784
10785 #[test]
10786 fn fonte_caminho_shell_semicolon_fires_before_shell_brace_expansion() {
10787 // Cascade pin on the upstream shell-semicolon arm: a value
10788 // carrying both `;` and `{` (`"../caixa-teia; {a,b}"` — the
10789 // canonical sequential-cleanup + brace-expansion paste
10790 // idiom) routes through `FonteCaminhoShellSemicolon` not
10791 // `FonteCaminhoShellBraceExpansion`. The sequential-command-
10792 // separator paste is the load-bearing root-cause edit on
10793 // every probe-as-both value.
10794 let d = dep_with_fonte(DepSource::Path {
10795 caminho: "../caixa-teia; {a,b}".into(),
10796 });
10797 let err = d.validate().unwrap_err();
10798 assert!(
10799 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10800 "got {err:?}",
10801 );
10802 }
10803
10804 #[test]
10805 fn fonte_caminho_shell_pipe_fires_before_shell_brace_expansion() {
10806 // Cascade pin on the upstream shell-pipe arm: a value
10807 // carrying both `|` and `{` (`"../caixa-teia | {tee,cat}"`
10808 // — the canonical pipeline-to-brace-expansion paste idiom)
10809 // routes through `FonteCaminhoShellPipe` not
10810 // `FonteCaminhoShellBraceExpansion`. The pipeline-tail paste
10811 // is the load-bearing root-cause edit on every probe-as-
10812 // both value.
10813 let d = dep_with_fonte(DepSource::Path {
10814 caminho: "../caixa-teia | {tee,cat}".into(),
10815 });
10816 let err = d.validate().unwrap_err();
10817 assert!(
10818 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10819 "got {err:?}",
10820 );
10821 }
10822
10823 #[test]
10824 fn fonte_caminho_shell_redirection_fires_before_shell_brace_expansion() {
10825 // Cascade pin on the upstream shell-redirection arm: a value
10826 // carrying both `>` and `{` (`"../caixa-teia>log {a,b}"` —
10827 // the canonical "I pasted a `cmd > log {a,b}` redirect-
10828 // plus-brace-expansion chain" footgun) routes through
10829 // `FonteCaminhoShellRedirection` not
10830 // `FonteCaminhoShellBraceExpansion`. The input/output
10831 // redirection metachar carries the more self-locating
10832 // `byte` payload, so the prior arm wins on every probe-
10833 // as-both value.
10834 let d = dep_with_fonte(DepSource::Path {
10835 caminho: "../caixa-teia>log {a,b}".into(),
10836 });
10837 let err = d.validate().unwrap_err();
10838 assert!(
10839 matches!(
10840 err,
10841 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10842 ),
10843 "got {err:?}",
10844 );
10845 }
10846
10847 #[test]
10848 fn fonte_caminho_backslash_fires_before_shell_brace_expansion() {
10849 // Cascade pin on the upstream backslash arm: a value
10850 // carrying both `\` and `{` (`"..\caixa-teia\{a,b}"` — the
10851 // canonical "I pasted a Windows-shell `cd ..\path\{a,b}`
10852 // chain") routes through `FonteCaminhoBackslash` not
10853 // `FonteCaminhoShellBraceExpansion`. The cross-host-OS-
10854 // separator divergence is the load-bearing axis on every
10855 // probe-as-both value.
10856 let d = dep_with_fonte(DepSource::Path {
10857 caminho: "..\\caixa-teia\\{a,b}".into(),
10858 });
10859 let err = d.validate().unwrap_err();
10860 assert!(
10861 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10862 "got {err:?}",
10863 );
10864 }
10865
10866 #[test]
10867 fn fonte_caminho_control_char_fires_before_shell_brace_expansion() {
10868 // Cascade pin on the embedded-control-byte arm: a value
10869 // carrying both a control byte and `{` (`"../foo\n{a,b}"` —
10870 // the canonical paste-from-multiline-doc footgun where a
10871 // newline landed mid-caminho between two paste fragments)
10872 // routes through `FonteCaminhoControlChar` not
10873 // `FonteCaminhoShellBraceExpansion`. The POSIX-syscall-
10874 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10875 // load-bearing axis on every value that probes positive for
10876 // both — mirrors the cascade discipline on every prior arm.
10877 let d = dep_with_fonte(DepSource::Path {
10878 caminho: "../foo\n{a,b}".into(),
10879 });
10880 let err = d.validate().unwrap_err();
10881 assert!(
10882 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10883 "got {err:?}",
10884 );
10885 }
10886
10887 #[test]
10888 fn fonte_caminho_absolute_fires_before_shell_brace_expansion() {
10889 // Cascade pin on the load-bearing leading-byte arm: a
10890 // leading `/` value with embedded `{` (`"/etc/{a,b}"`)
10891 // routes through `FonteCaminhoAbsolute` not
10892 // `FonteCaminhoShellBraceExpansion` — the host-layout-leak
10893 // diagnostic is the load-bearing axis, the brace-expansion
10894 // byte is the secondary observation. Same precedence logic
10895 // as every prior leading-byte arm.
10896 let d = dep_with_fonte(DepSource::Path {
10897 caminho: "/etc/{a,b}".into(),
10898 });
10899 let err = d.validate().unwrap_err();
10900 assert!(
10901 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10902 "got {err:?}",
10903 );
10904 }
10905
10906 #[test]
10907 fn fonte_caminho_var_expansion_fires_before_shell_brace_expansion() {
10908 // Cascade pin on the upstream leading-`$` var-expansion
10909 // arm: a value carrying both a leading `$` and a `{`
10910 // (`"${ORG}/caixa-teia"` — the canonical "I pasted a
10911 // `${ORG}` shell-variable + curly-brace expansion at the
10912 // head of a sibling-workspace path" footgun) routes through
10913 // `FonteCaminhoVarExpansion` not
10914 // `FonteCaminhoShellBraceExpansion`. The leading-byte
10915 // shell-variable-expansion is the more self-locating
10916 // diagnostic on values that probe as both — same
10917 // load-bearing-leading-byte cascade discipline every prior
10918 // `:caminho` arm establishes.
10919 let d = dep_with_fonte(DepSource::Path {
10920 caminho: "${ORG}/caixa-teia".into(),
10921 });
10922 let err = d.validate().unwrap_err();
10923 assert!(
10924 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
10925 "got {err:?}",
10926 );
10927 }
10928
10929 #[test]
10930 fn fonte_caminho_shell_brace_expansion_fires_before_trailing_slash() {
10931 // Cascade pin on the immediate-successor arm: a value
10932 // carrying both `{` and a trailing `/`
10933 // (`"../{caixa-teia,caixa-helm}/"` — the canonical "I
10934 // tab-completed a path that already had a brace-expansion
10935 // expansion tail" footgun) routes through
10936 // `FonteCaminhoShellBraceExpansion` not
10937 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
10938 // is the more semantic-locating axis (an author who removes
10939 // the `{` typically also drops the trailing separator since
10940 // both are paste-from-shell artifacts).
10941 let d = dep_with_fonte(DepSource::Path {
10942 caminho: "../{caixa-teia,caixa-helm}/".into(),
10943 });
10944 let err = d.validate().unwrap_err();
10945 assert!(
10946 matches!(
10947 err,
10948 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10949 ),
10950 "got {err:?}",
10951 );
10952 }
10953
10954 #[test]
10955 fn fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
10956 // Diagnostic-shape pin (peer with
10957 // `fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
10958 // on the closest two-byte peer arm): the error's Display
10959 // surfaces the offending `:nome`, the offending `:caminho`
10960 // verbatim, the offending byte's hex / character form, and
10961 // names the shell-brace-expansion / URI-Template footgun
10962 // explicitly so a `feira lint` run can render the diagnostic
10963 // without re-parsing.
10964 let d = dep_with_fonte(DepSource::Path {
10965 caminho: "../{caixa-teia,caixa-helm}/build".into(),
10966 });
10967 let rendered = d.validate().unwrap_err().to_string();
10968 assert!(
10969 rendered.contains("caixa-teia"),
10970 "diagnostic must name the offending dep: {rendered}",
10971 );
10972 assert!(
10973 rendered.contains("../{caixa-teia,caixa-helm}/build"),
10974 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10975 );
10976 assert!(
10977 rendered.contains("0x7b"),
10978 "diagnostic must surface the offending byte hex: {rendered:?}",
10979 );
10980 assert!(
10981 rendered.contains("brace-expansion"),
10982 "diagnostic must name the shell-brace-expansion footgun: {rendered:?}",
10983 );
10984 assert!(
10985 rendered.contains("URI Template"),
10986 "diagnostic must reference the RFC-6570 URI-Template-placeholder vocabulary: \
10987 {rendered:?}",
10988 );
10989 }
10990
10991 #[test]
10992 fn validate_rejects_path_fonte_with_caminho_carrying_bracket_glob_character_class() {
10993 // The canonical paste-from-shell-history bracket-glob /
10994 // character-class footgun: an author copies a
10995 // `cd ../caixa-[a-z]/build` shell-history one-liner whose
10996 // `[a-z]` POSIX glob character-class matches every lowercase-
10997 // ASCII-suffix sibling caixa directory and silently passed
10998 // every prior arm (`Path::is_absolute` false on `..`, no
10999 // control bytes, no `\`, no `<` / `>`, no `|`, no `;`, no
11000 // `&`, no backtick, no `*` / `?`, no `(` / `)`, no `{` /
11001 // `}`, doesn't end in `/`; the leading-`$` f4efe9c
11002 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11003 // value starts with `..` not `$`). The lacre embedded the
11004 // value verbatim, the resolver folded it through
11005 // `Path::join` looking for a literal `./../caixa-[a-z]/
11006 // build` subdirectory, and the failure surfaced at resolve
11007 // time with a non-self-locating `No such file or directory`
11008 // error. The new arm moves the rejection to validate time
11009 // and names the offending dep + caminho + byte verbatim.
11010 // The arm fires on the first `[` encountered.
11011 let d = dep_with_fonte(DepSource::Path {
11012 caminho: "../caixa-[a-z]/build".into(),
11013 });
11014 let err = d.validate().unwrap_err();
11015 let DepError::FonteCaminhoShellBracketExpansion {
11016 nome,
11017 caminho,
11018 byte,
11019 } = err
11020 else {
11021 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11022 };
11023 assert_eq!(nome, "caixa-teia");
11024 assert_eq!(caminho, "../caixa-[a-z]/build");
11025 assert_eq!(byte, b'[');
11026 }
11027
11028 #[test]
11029 fn validate_rejects_path_fonte_with_caminho_carrying_close_bracket() {
11030 // The symmetric close-bracket paste shape (`"../caixa-teia]"`
11031 // — the degenerate "I selected an unbalanced closing bracket
11032 // out of a glob character-class block" idiom that probes for
11033 // the cascade's last-byte handling on a value carrying only
11034 // the closing byte). Pinned separately from the open-bracket
11035 // shape so the gate's contract is "any `[` or `]` anywhere",
11036 // not single-byte coverage. Mirrors the peer
11037 // `validate_rejects_path_fonte_with_caminho_carrying_close_brace`
11038 // shape on the immediate-predecessor
11039 // `FonteCaminhoShellBraceExpansion` arm.
11040 let d = dep_with_fonte(DepSource::Path {
11041 caminho: "../caixa-teia]".into(),
11042 });
11043 let err = d.validate().unwrap_err();
11044 let DepError::FonteCaminhoShellBracketExpansion { byte, .. } = err else {
11045 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11046 };
11047 assert_eq!(byte, b']');
11048 }
11049
11050 #[test]
11051 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_bracket() {
11052 // Leading-position `[` shape (`"[caixa-teia]/build"` — the
11053 // canonical "I selected a `[caixa-teia]` TOML-table-header /
11054 // glob-character-class prefix out of an aligned config /
11055 // shell-history one-liner" idiom). Pinned separately from
11056 // the embedded-byte shape so the gate covers every position,
11057 // not only mid-path.
11058 let d = dep_with_fonte(DepSource::Path {
11059 caminho: "[caixa-teia]/build".into(),
11060 });
11061 let err = d.validate().unwrap_err();
11062 assert!(
11063 matches!(
11064 err,
11065 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11066 ),
11067 "got {err:?}",
11068 );
11069 }
11070
11071 #[test]
11072 fn validate_rejects_path_fonte_with_caminho_carrying_toml_inline_array() {
11073 // The canonical TOML inline-array / YAML flow-sequence
11074 // paste shape (`"../[\"a\", \"b\"]/caixa-teia"` — the
11075 // canonical "I copied a `features = [\"a\", \"b\"]` TOML
11076 // inline-array out of a sibling-Cargo manifest" cross-idiom
11077 // leak; the symmetric YAML flow-sequence form `paths: [/a,
11078 // /b]` paste-from-values.yaml shape carries the same
11079 // bracket pair). The arm fires on the first `[` encountered;
11080 // pinned so the gate's coverage extends from the bare-
11081 // bracket glob-character-class shape to the TOML / YAML /
11082 // JSON array-literal shape.
11083 let d = dep_with_fonte(DepSource::Path {
11084 caminho: "../[\"a\", \"b\"]/caixa-teia".into(),
11085 });
11086 let err = d.validate().unwrap_err();
11087 assert!(
11088 matches!(
11089 err,
11090 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11091 ),
11092 "got {err:?}",
11093 );
11094 }
11095
11096 #[test]
11097 fn validate_rejects_path_fonte_with_caminho_carrying_shell_test_builtin() {
11098 // The canonical POSIX `test` / `[` builtin command paste
11099 // shape (`"../[ -d caixa-teia ]"` — the `[ <expr> ]` shell-
11100 // script conditional every paste-from-shell-script idiom
11101 // carries; bash's `[[ <expr> ]]` extended-test grammar
11102 // would surface the same byte pair). The arm fires on the
11103 // first `[` encountered; pinned so the gate's coverage
11104 // extends from the embedded-glob-character-class shape to
11105 // the leading-`test`-builtin / extended-test form.
11106 let d = dep_with_fonte(DepSource::Path {
11107 caminho: "../[ -d caixa-teia ]".into(),
11108 });
11109 let err = d.validate().unwrap_err();
11110 assert!(
11111 matches!(
11112 err,
11113 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11114 ),
11115 "got {err:?}",
11116 );
11117 }
11118
11119 #[test]
11120 fn validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion() {
11121 // The positive-control pin: the gate targets only `[` /
11122 // `]`, never adjacent printable ASCII or POSIX-valid bytes.
11123 // The canonical relative POSIX path (`"../caixa-teia"`) and
11124 // a nested deeply-pathed variant with adjacent printable
11125 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11126 // to validate cleanly so the gate doesn't widen to a "no
11127 // printable punctuation anywhere" sweep that would defeat
11128 // the entire path-fonte author surface. Peer with
11129 // `validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion`
11130 // on the immediate-predecessor arm.
11131 let d = dep_with_fonte(DepSource::Path {
11132 caminho: "../caixa-teia/sub-dir.v2".into(),
11133 });
11134 d.validate().unwrap();
11135 }
11136
11137 #[test]
11138 fn fonte_caminho_shell_brace_expansion_fires_before_shell_bracket_expansion() {
11139 // Cascade pin on the immediate-predecessor arm: a value
11140 // carrying both `{` and `[` (`"../{a,b}[ch]"` — the
11141 // canonical "I pasted a brace-expansion fan followed by a
11142 // glob-character-class tail" footgun) routes through
11143 // `FonteCaminhoShellBraceExpansion` not
11144 // `FonteCaminhoShellBracketExpansion`. The brace-expansion
11145 // fan is the load-bearing root-cause edit on every
11146 // probe-as-both value because the bracket-class tail
11147 // typically rides on a prior brace-expansion expansion;
11148 // same cascade discipline every prior `:caminho` arm
11149 // establishes.
11150 let d = dep_with_fonte(DepSource::Path {
11151 caminho: "../{a,b}[ch]".into(),
11152 });
11153 let err = d.validate().unwrap_err();
11154 assert!(
11155 matches!(
11156 err,
11157 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11158 ),
11159 "got {err:?}",
11160 );
11161 }
11162
11163 #[test]
11164 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_bracket_expansion() {
11165 // Cascade pin on the upstream shell-subshell-grouping arm:
11166 // a value carrying both `(` and `[` (`"../(cd foo)/[ch]"` —
11167 // the canonical "I pasted a subshell-grouping followed by
11168 // a glob-character-class tail" footgun) routes through
11169 // `FonteCaminhoShellSubshellGrouping` not
11170 // `FonteCaminhoShellBracketExpansion`. The modern Bourne
11171 // `$(<cmd>)` command-substitution boundary is the load-
11172 // bearing axis on every probe-as-both value.
11173 let d = dep_with_fonte(DepSource::Path {
11174 caminho: "../(cd foo)/[ch]".into(),
11175 });
11176 let err = d.validate().unwrap_err();
11177 assert!(
11178 matches!(
11179 err,
11180 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11181 ),
11182 "got {err:?}",
11183 );
11184 }
11185
11186 #[test]
11187 fn fonte_caminho_shell_glob_fires_before_shell_bracket_expansion() {
11188 // Cascade pin on the upstream shell-glob arm: a value
11189 // carrying both `*` and `[` (`"../caixa-teia/*[ch]"` — the
11190 // canonical "I pasted a `*.[ch]` C-source-file glob whose
11191 // unbounded `*` precedes the bracket character-class"
11192 // footgun) routes through `FonteCaminhoShellGlob` not
11193 // `FonteCaminhoShellBracketExpansion`. The unbounded
11194 // pathname-expansion sentinel is the load-bearing root-
11195 // cause edit on every probe-as-both value — the unbounded
11196 // `*` carries the more aggressive expansion vector than
11197 // the bounded `[ch]` class, so the prior arm wins.
11198 let d = dep_with_fonte(DepSource::Path {
11199 caminho: "../caixa-teia/*[ch]".into(),
11200 });
11201 let err = d.validate().unwrap_err();
11202 assert!(
11203 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11204 "got {err:?}",
11205 );
11206 }
11207
11208 #[test]
11209 fn fonte_caminho_shell_command_substitution_fires_before_shell_bracket_expansion() {
11210 // Cascade pin on the upstream shell-command-substitution
11211 // arm: a value carrying both a backtick and `[`
11212 // (``"../`whoami`/[ch]"`` — the canonical "I pasted a
11213 // legacy-backtick command-substitution followed by a
11214 // glob-character-class tail" footgun) routes through
11215 // `FonteCaminhoShellCommandSubstitution` not
11216 // `FonteCaminhoShellBracketExpansion`. The CWE-78 shell-
11217 // command-injection vector is the load-bearing root-cause
11218 // edit on every probe-as-both value.
11219 let d = dep_with_fonte(DepSource::Path {
11220 caminho: "../`whoami`/[ch]".into(),
11221 });
11222 let err = d.validate().unwrap_err();
11223 assert!(
11224 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11225 "got {err:?}",
11226 );
11227 }
11228
11229 #[test]
11230 fn fonte_caminho_shell_background_fires_before_shell_bracket_expansion() {
11231 // Cascade pin on the upstream shell-background arm: a
11232 // value carrying both `&` and `[` (`"../caixa-teia & [ch]"`
11233 // — the canonical "I pasted a `cmd & [glob]` background-
11234 // launch + bracket-class chain" footgun) routes through
11235 // `FonteCaminhoShellBackground` not
11236 // `FonteCaminhoShellBracketExpansion`. The background-
11237 // launch tail is the load-bearing root-cause edit on
11238 // every probe-as-both value.
11239 let d = dep_with_fonte(DepSource::Path {
11240 caminho: "../caixa-teia & [ch]".into(),
11241 });
11242 let err = d.validate().unwrap_err();
11243 assert!(
11244 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11245 "got {err:?}",
11246 );
11247 }
11248
11249 #[test]
11250 fn fonte_caminho_shell_semicolon_fires_before_shell_bracket_expansion() {
11251 // Cascade pin on the upstream shell-semicolon arm: a value
11252 // carrying both `;` and `[` (`"../caixa-teia; [ch]"` — the
11253 // canonical sequential-cleanup + bracket-class paste
11254 // idiom) routes through `FonteCaminhoShellSemicolon` not
11255 // `FonteCaminhoShellBracketExpansion`. The sequential-
11256 // command-separator paste is the load-bearing root-cause
11257 // edit on every probe-as-both value.
11258 let d = dep_with_fonte(DepSource::Path {
11259 caminho: "../caixa-teia; [ch]".into(),
11260 });
11261 let err = d.validate().unwrap_err();
11262 assert!(
11263 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11264 "got {err:?}",
11265 );
11266 }
11267
11268 #[test]
11269 fn fonte_caminho_shell_pipe_fires_before_shell_bracket_expansion() {
11270 // Cascade pin on the upstream shell-pipe arm: a value
11271 // carrying both `|` and `[` (`"../caixa-teia | [tee]"` —
11272 // the canonical pipeline-to-bracket-class paste idiom)
11273 // routes through `FonteCaminhoShellPipe` not
11274 // `FonteCaminhoShellBracketExpansion`. The pipeline-tail
11275 // paste is the load-bearing root-cause edit on every
11276 // probe-as-both value.
11277 let d = dep_with_fonte(DepSource::Path {
11278 caminho: "../caixa-teia | [tee]".into(),
11279 });
11280 let err = d.validate().unwrap_err();
11281 assert!(
11282 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11283 "got {err:?}",
11284 );
11285 }
11286
11287 #[test]
11288 fn fonte_caminho_shell_redirection_fires_before_shell_bracket_expansion() {
11289 // Cascade pin on the upstream shell-redirection arm: a
11290 // value carrying both `>` and `[` (`"../caixa-teia>log
11291 // [ch]"` — the canonical "I pasted a `cmd > log [glob]`
11292 // redirect-plus-bracket chain" footgun) routes through
11293 // `FonteCaminhoShellRedirection` not
11294 // `FonteCaminhoShellBracketExpansion`. The input/output
11295 // redirection metachar carries the more self-locating
11296 // `byte` payload, so the prior arm wins on every
11297 // probe-as-both value.
11298 let d = dep_with_fonte(DepSource::Path {
11299 caminho: "../caixa-teia>log [ch]".into(),
11300 });
11301 let err = d.validate().unwrap_err();
11302 assert!(
11303 matches!(
11304 err,
11305 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11306 ),
11307 "got {err:?}",
11308 );
11309 }
11310
11311 #[test]
11312 fn fonte_caminho_backslash_fires_before_shell_bracket_expansion() {
11313 // Cascade pin on the upstream backslash arm: a value
11314 // carrying both `\` and `[` (`"..\caixa-teia\[ch]"` — the
11315 // canonical "I pasted a Windows-shell `cd ..\path\[glob]`
11316 // chain") routes through `FonteCaminhoBackslash` not
11317 // `FonteCaminhoShellBracketExpansion`. The cross-host-OS-
11318 // separator divergence is the load-bearing axis on every
11319 // probe-as-both value.
11320 let d = dep_with_fonte(DepSource::Path {
11321 caminho: "..\\caixa-teia\\[ch]".into(),
11322 });
11323 let err = d.validate().unwrap_err();
11324 assert!(
11325 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11326 "got {err:?}",
11327 );
11328 }
11329
11330 #[test]
11331 fn fonte_caminho_control_char_fires_before_shell_bracket_expansion() {
11332 // Cascade pin on the embedded-control-byte arm: a value
11333 // carrying both a control byte and `[` (`"../foo\n[ch]"` —
11334 // the canonical paste-from-multiline-doc footgun where a
11335 // newline landed mid-caminho between two paste fragments)
11336 // routes through `FonteCaminhoControlChar` not
11337 // `FonteCaminhoShellBracketExpansion`. The POSIX-syscall-
11338 // rejected-byte / NUL-`CString::new`-fail diagnostic is
11339 // the load-bearing axis on every value that probes
11340 // positive for both — mirrors the cascade discipline on
11341 // every prior arm.
11342 let d = dep_with_fonte(DepSource::Path {
11343 caminho: "../foo\n[ch]".into(),
11344 });
11345 let err = d.validate().unwrap_err();
11346 assert!(
11347 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11348 "got {err:?}",
11349 );
11350 }
11351
11352 #[test]
11353 fn fonte_caminho_absolute_fires_before_shell_bracket_expansion() {
11354 // Cascade pin on the load-bearing leading-byte arm: a
11355 // leading `/` value with embedded `[` (`"/etc/[ch]"`)
11356 // routes through `FonteCaminhoAbsolute` not
11357 // `FonteCaminhoShellBracketExpansion` — the host-layout-
11358 // leak diagnostic is the load-bearing axis, the bracket-
11359 // expansion byte is the secondary observation. Same
11360 // precedence logic as every prior leading-byte arm.
11361 let d = dep_with_fonte(DepSource::Path {
11362 caminho: "/etc/[ch]".into(),
11363 });
11364 let err = d.validate().unwrap_err();
11365 assert!(
11366 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11367 "got {err:?}",
11368 );
11369 }
11370
11371 #[test]
11372 fn fonte_caminho_var_expansion_fires_before_shell_bracket_expansion() {
11373 // Cascade pin on the upstream leading-`$` var-expansion
11374 // arm: a value carrying both a leading `$` and a `[`
11375 // (`"$DIR/[ch]"` — the canonical "I pasted a `$DIR` shell-
11376 // variable + bracket-class at the head of a sibling-
11377 // workspace path" footgun) routes through
11378 // `FonteCaminhoVarExpansion` not
11379 // `FonteCaminhoShellBracketExpansion`. The leading-byte
11380 // shell-variable-expansion is the more self-locating
11381 // diagnostic on values that probe as both — same
11382 // load-bearing-leading-byte cascade discipline every
11383 // prior `:caminho` arm establishes.
11384 let d = dep_with_fonte(DepSource::Path {
11385 caminho: "$DIR/[ch]".into(),
11386 });
11387 let err = d.validate().unwrap_err();
11388 assert!(
11389 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11390 "got {err:?}",
11391 );
11392 }
11393
11394 #[test]
11395 fn fonte_caminho_shell_bracket_expansion_fires_before_trailing_slash() {
11396 // Cascade pin on the immediate-successor arm: a value
11397 // carrying both `[` and a trailing `/` (`"../[a-z]/"` —
11398 // the canonical "I tab-completed a path that already had
11399 // a bracket-glob-character-class expansion tail" footgun)
11400 // routes through `FonteCaminhoShellBracketExpansion` not
11401 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11402 // is the more semantic-locating axis (an author who
11403 // removes the `[` typically also drops the trailing
11404 // separator since both are paste-from-shell artifacts).
11405 let d = dep_with_fonte(DepSource::Path {
11406 caminho: "../[a-z]/".into(),
11407 });
11408 let err = d.validate().unwrap_err();
11409 assert!(
11410 matches!(
11411 err,
11412 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11413 ),
11414 "got {err:?}",
11415 );
11416 }
11417
11418 #[test]
11419 fn fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11420 // Diagnostic-shape pin (peer with
11421 // `fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11422 // on the closest two-byte peer arm): the error's Display
11423 // surfaces the offending `:nome`, the offending `:caminho`
11424 // verbatim, the offending byte's hex / character form, and
11425 // names the shell-bracket-expansion / glob-character-class
11426 // footgun explicitly so a `feira lint` run can render the
11427 // diagnostic without re-parsing.
11428 let d = dep_with_fonte(DepSource::Path {
11429 caminho: "../caixa-[a-z]/build".into(),
11430 });
11431 let rendered = d.validate().unwrap_err().to_string();
11432 assert!(
11433 rendered.contains("caixa-teia"),
11434 "diagnostic must name the offending dep: {rendered}",
11435 );
11436 assert!(
11437 rendered.contains("../caixa-[a-z]/build"),
11438 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11439 );
11440 assert!(
11441 rendered.contains("0x5b"),
11442 "diagnostic must surface the offending byte hex: {rendered:?}",
11443 );
11444 assert!(
11445 rendered.contains("bracket-expansion"),
11446 "diagnostic must name the shell-bracket-expansion footgun: {rendered:?}",
11447 );
11448 assert!(
11449 rendered.contains("glob-character-class"),
11450 "diagnostic must reference the POSIX glob-character-class vocabulary: \
11451 {rendered:?}",
11452 );
11453 }
11454
11455 #[test]
11456 fn validate_rejects_path_fonte_with_caminho_carrying_single_quote_grouping() {
11457 // The canonical paste-from-shell-history strong-quoted
11458 // sibling-workspace-path footgun: an author copies a
11459 // `cd '../caixa-teia'` shell-history one-liner whose strong-
11460 // quoting preserved the path across a whitespace paste
11461 // boundary and silently passed every prior arm
11462 // (`Path::is_absolute` false on `'..`, no control bytes, no
11463 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no
11464 // `*` / `?`, no `(` / `)`, no `{` / `}`, no `[` / `]`,
11465 // doesn't end in `/`; the leading-`$` f4efe9c
11466 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11467 // value starts with `'` not `$`). The lacre embedded the
11468 // value verbatim, the resolver folded it through
11469 // `Path::join` looking for a literal `./'../caixa-teia'`
11470 // subdirectory, and the failure surfaced at resolve time
11471 // with a non-self-locating `No such file or directory`
11472 // error. The new arm moves the rejection to validate time
11473 // and names the offending dep + caminho + byte verbatim.
11474 // The arm fires on the first `'` encountered.
11475 let d = dep_with_fonte(DepSource::Path {
11476 caminho: "'../caixa-teia'".into(),
11477 });
11478 let err = d.validate().unwrap_err();
11479 let DepError::FonteCaminhoShellQuoteGrouping {
11480 nome,
11481 caminho,
11482 byte,
11483 } = err
11484 else {
11485 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11486 };
11487 assert_eq!(nome, "caixa-teia");
11488 assert_eq!(caminho, "'../caixa-teia'");
11489 assert_eq!(byte, b'\'');
11490 }
11491
11492 #[test]
11493 fn validate_rejects_path_fonte_with_caminho_carrying_double_quote_grouping() {
11494 // The symmetric weak-quoted paste shape (`"\"../caixa-teia\""`
11495 // — the canonical paste-from-JSON-config / paste-from-YAML-
11496 // flow-scalar / paste-from-TOML-basic-string / paste-from-
11497 // tatara-lisp-string-literal cross-idiom leak). Pinned
11498 // separately from the single-quote shape so the gate's
11499 // contract is "any `'` or `\"` anywhere", not single-byte
11500 // coverage. Mirrors the peer
11501 // `validate_rejects_path_fonte_with_caminho_carrying_close_bracket`
11502 // shape on the immediate-predecessor
11503 // `FonteCaminhoShellBracketExpansion` arm.
11504 let d = dep_with_fonte(DepSource::Path {
11505 caminho: "\"../caixa-teia\"".into(),
11506 });
11507 let err = d.validate().unwrap_err();
11508 let DepError::FonteCaminhoShellQuoteGrouping { byte, .. } = err else {
11509 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11510 };
11511 assert_eq!(byte, b'"');
11512 }
11513
11514 #[test]
11515 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_double_quote() {
11516 // Embedded-position `"` shape (`"../\"caixa-teia\""` — the
11517 // canonical "I pasted a JSON key-value pair fragment into
11518 // the middle of the path" idiom). Pinned separately from
11519 // the leading-byte shape so the gate covers every position,
11520 // not only leading.
11521 let d = dep_with_fonte(DepSource::Path {
11522 caminho: "../\"caixa-teia\"".into(),
11523 });
11524 let err = d.validate().unwrap_err();
11525 assert!(
11526 matches!(
11527 err,
11528 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11529 ),
11530 "got {err:?}",
11531 );
11532 }
11533
11534 #[test]
11535 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_flow_scalar_paste() {
11536 // The canonical YAML double-quoted flow-scalar cross-idiom
11537 // leak shape (`"path: \"../caixa-teia\""` — the "I copied a
11538 // `path: \"...\"` YAML flow-scalar entry out of an aligned
11539 // values.yaml / K8s manifest and dropped it verbatim into
11540 // the `:caminho` slot including the `path: ` key prefix"
11541 // paste-idiom). The arm fires on the first `"` encountered;
11542 // pinned so the gate's coverage extends from the bare-quote
11543 // paste shape to the aligned-YAML-manifest cross-idiom-leak
11544 // shape.
11545 let d = dep_with_fonte(DepSource::Path {
11546 caminho: "path: \"../caixa-teia\"".into(),
11547 });
11548 let err = d.validate().unwrap_err();
11549 assert!(
11550 matches!(
11551 err,
11552 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11553 ),
11554 "got {err:?}",
11555 );
11556 }
11557
11558 #[test]
11559 fn validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping() {
11560 // The positive-control pin: the gate targets only `'` /
11561 // `"`, never adjacent printable ASCII or POSIX-valid bytes.
11562 // The canonical relative POSIX path (`"../caixa-teia"`) and
11563 // a nested deeply-pathed variant with adjacent printable
11564 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11565 // to validate cleanly so the gate doesn't widen to a "no
11566 // printable punctuation anywhere" sweep that would defeat
11567 // the entire path-fonte author surface. Peer with
11568 // `validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion`
11569 // on the immediate-predecessor arm.
11570 let d = dep_with_fonte(DepSource::Path {
11571 caminho: "../caixa-teia/sub-dir.v2".into(),
11572 });
11573 d.validate().unwrap();
11574 }
11575
11576 #[test]
11577 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_quote_grouping() {
11578 // Cascade pin on the immediate-predecessor arm: a value
11579 // carrying both `[` and `'` (`"../[a-z]'x'"` — the canonical
11580 // "I pasted a glob-character-class followed by a strong-
11581 // quoted literal tail" footgun) routes through
11582 // `FonteCaminhoShellBracketExpansion` not
11583 // `FonteCaminhoShellQuoteGrouping`. The glob-character-class
11584 // expansion is the load-bearing root-cause edit on every
11585 // probe-as-both value; same cascade discipline every prior
11586 // `:caminho` arm establishes.
11587 let d = dep_with_fonte(DepSource::Path {
11588 caminho: "../[a-z]'x'".into(),
11589 });
11590 let err = d.validate().unwrap_err();
11591 assert!(
11592 matches!(
11593 err,
11594 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11595 ),
11596 "got {err:?}",
11597 );
11598 }
11599
11600 #[test]
11601 fn fonte_caminho_shell_brace_expansion_fires_before_shell_quote_grouping() {
11602 // Cascade pin on the upstream shell-brace-expansion arm: a
11603 // value carrying both `{` and `'` (`"../{a,b}'x'"` — the
11604 // canonical "I pasted a brace-expansion fan followed by a
11605 // strong-quoted literal tail" footgun) routes through
11606 // `FonteCaminhoShellBraceExpansion` not
11607 // `FonteCaminhoShellQuoteGrouping`. The brace-expansion fan
11608 // is the load-bearing root-cause edit on every probe-as-
11609 // both value.
11610 let d = dep_with_fonte(DepSource::Path {
11611 caminho: "../{a,b}'x'".into(),
11612 });
11613 let err = d.validate().unwrap_err();
11614 assert!(
11615 matches!(
11616 err,
11617 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11618 ),
11619 "got {err:?}",
11620 );
11621 }
11622
11623 #[test]
11624 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_quote_grouping() {
11625 // Cascade pin on the upstream shell-subshell-grouping arm:
11626 // a value carrying both `(` and `'` (`"../(cd foo)/'x'"` —
11627 // the canonical "I pasted a subshell-grouping followed by
11628 // a strong-quoted literal tail" footgun) routes through
11629 // `FonteCaminhoShellSubshellGrouping` not
11630 // `FonteCaminhoShellQuoteGrouping`. The modern Bourne
11631 // `$(<cmd>)` command-substitution boundary is the load-
11632 // bearing axis on every probe-as-both value.
11633 let d = dep_with_fonte(DepSource::Path {
11634 caminho: "../(cd foo)/'x'".into(),
11635 });
11636 let err = d.validate().unwrap_err();
11637 assert!(
11638 matches!(
11639 err,
11640 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11641 ),
11642 "got {err:?}",
11643 );
11644 }
11645
11646 #[test]
11647 fn fonte_caminho_shell_glob_fires_before_shell_quote_grouping() {
11648 // Cascade pin on the upstream shell-glob arm: a value
11649 // carrying both `*` and `'` (`"../caixa-teia/*'x'"` — the
11650 // canonical "I pasted a `*` unbounded pathname-expansion
11651 // followed by a strong-quoted literal tail" footgun) routes
11652 // through `FonteCaminhoShellGlob` not
11653 // `FonteCaminhoShellQuoteGrouping`. The unbounded pathname-
11654 // expansion sentinel is the load-bearing root-cause edit
11655 // on every probe-as-both value.
11656 let d = dep_with_fonte(DepSource::Path {
11657 caminho: "../caixa-teia/*'x'".into(),
11658 });
11659 let err = d.validate().unwrap_err();
11660 assert!(
11661 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11662 "got {err:?}",
11663 );
11664 }
11665
11666 #[test]
11667 fn fonte_caminho_shell_command_substitution_fires_before_shell_quote_grouping() {
11668 // Cascade pin on the upstream shell-command-substitution
11669 // arm: a value carrying both a backtick and `'`
11670 // (``"../`whoami`/'x'"`` — the canonical "I pasted a
11671 // legacy-backtick command-substitution followed by a
11672 // strong-quoted literal tail" footgun) routes through
11673 // `FonteCaminhoShellCommandSubstitution` not
11674 // `FonteCaminhoShellQuoteGrouping`. The CWE-78 shell-
11675 // command-injection vector is the load-bearing root-cause
11676 // edit on every probe-as-both value.
11677 let d = dep_with_fonte(DepSource::Path {
11678 caminho: "../`whoami`/'x'".into(),
11679 });
11680 let err = d.validate().unwrap_err();
11681 assert!(
11682 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11683 "got {err:?}",
11684 );
11685 }
11686
11687 #[test]
11688 fn fonte_caminho_shell_background_fires_before_shell_quote_grouping() {
11689 // Cascade pin on the upstream shell-background arm: a value
11690 // carrying both `&` and `'` (`"../caixa-teia & 'x'"` — the
11691 // canonical "I pasted a `cmd & 'literal'` background-launch
11692 // + quote chain" footgun) routes through
11693 // `FonteCaminhoShellBackground` not
11694 // `FonteCaminhoShellQuoteGrouping`. The background-launch
11695 // tail is the load-bearing root-cause edit on every
11696 // probe-as-both value.
11697 let d = dep_with_fonte(DepSource::Path {
11698 caminho: "../caixa-teia & 'x'".into(),
11699 });
11700 let err = d.validate().unwrap_err();
11701 assert!(
11702 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11703 "got {err:?}",
11704 );
11705 }
11706
11707 #[test]
11708 fn fonte_caminho_shell_semicolon_fires_before_shell_quote_grouping() {
11709 // Cascade pin on the upstream shell-semicolon arm: a value
11710 // carrying both `;` and `'` (`"../caixa-teia; 'x'"` — the
11711 // canonical sequential-cleanup + quote paste idiom) routes
11712 // through `FonteCaminhoShellSemicolon` not
11713 // `FonteCaminhoShellQuoteGrouping`. The sequential-command-
11714 // separator paste is the load-bearing root-cause edit on
11715 // every probe-as-both value.
11716 let d = dep_with_fonte(DepSource::Path {
11717 caminho: "../caixa-teia; 'x'".into(),
11718 });
11719 let err = d.validate().unwrap_err();
11720 assert!(
11721 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11722 "got {err:?}",
11723 );
11724 }
11725
11726 #[test]
11727 fn fonte_caminho_shell_pipe_fires_before_shell_quote_grouping() {
11728 // Cascade pin on the upstream shell-pipe arm: a value
11729 // carrying both `|` and `'` (`"../caixa-teia | 'x'"` — the
11730 // canonical pipeline-to-quoted-literal paste idiom) routes
11731 // through `FonteCaminhoShellPipe` not
11732 // `FonteCaminhoShellQuoteGrouping`. The pipeline-tail paste
11733 // is the load-bearing root-cause edit on every probe-as-
11734 // both value.
11735 let d = dep_with_fonte(DepSource::Path {
11736 caminho: "../caixa-teia | 'x'".into(),
11737 });
11738 let err = d.validate().unwrap_err();
11739 assert!(
11740 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11741 "got {err:?}",
11742 );
11743 }
11744
11745 #[test]
11746 fn fonte_caminho_shell_redirection_fires_before_shell_quote_grouping() {
11747 // Cascade pin on the upstream shell-redirection arm: a
11748 // value carrying both `>` and `'` (`"../caixa-teia>log 'x'"`
11749 // — the canonical "I pasted a `cmd > log 'literal'`
11750 // redirect-plus-quote chain" footgun) routes through
11751 // `FonteCaminhoShellRedirection` not
11752 // `FonteCaminhoShellQuoteGrouping`. The input/output
11753 // redirection metachar carries the more self-locating
11754 // `byte` payload, so the prior arm wins on every probe-as-
11755 // both value.
11756 let d = dep_with_fonte(DepSource::Path {
11757 caminho: "../caixa-teia>log 'x'".into(),
11758 });
11759 let err = d.validate().unwrap_err();
11760 assert!(
11761 matches!(
11762 err,
11763 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11764 ),
11765 "got {err:?}",
11766 );
11767 }
11768
11769 #[test]
11770 fn fonte_caminho_backslash_fires_before_shell_quote_grouping() {
11771 // Cascade pin on the upstream backslash arm: a value
11772 // carrying both `\` and `'` (`"..\caixa-teia\'x'"` — the
11773 // canonical "I pasted a Windows-shell `cd ..\path\'literal'`
11774 // chain" footgun) routes through `FonteCaminhoBackslash`
11775 // not `FonteCaminhoShellQuoteGrouping`. The cross-host-OS-
11776 // separator divergence is the load-bearing axis on every
11777 // probe-as-both value.
11778 let d = dep_with_fonte(DepSource::Path {
11779 caminho: "..\\caixa-teia\\'x'".into(),
11780 });
11781 let err = d.validate().unwrap_err();
11782 assert!(
11783 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11784 "got {err:?}",
11785 );
11786 }
11787
11788 #[test]
11789 fn fonte_caminho_control_char_fires_before_shell_quote_grouping() {
11790 // Cascade pin on the embedded-control-byte arm: a value
11791 // carrying both a control byte and `'` (`"../foo\n'x'"` —
11792 // the canonical paste-from-multiline-doc footgun where a
11793 // newline landed mid-caminho between two paste fragments)
11794 // routes through `FonteCaminhoControlChar` not
11795 // `FonteCaminhoShellQuoteGrouping`. The POSIX-syscall-
11796 // rejected-byte / NUL-`CString::new`-fail diagnostic is
11797 // the load-bearing axis on every value that probes
11798 // positive for both — mirrors the cascade discipline on
11799 // every prior arm.
11800 let d = dep_with_fonte(DepSource::Path {
11801 caminho: "../foo\n'x'".into(),
11802 });
11803 let err = d.validate().unwrap_err();
11804 assert!(
11805 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11806 "got {err:?}",
11807 );
11808 }
11809
11810 #[test]
11811 fn fonte_caminho_absolute_fires_before_shell_quote_grouping() {
11812 // Cascade pin on the load-bearing leading-byte arm: a
11813 // leading `/` value with embedded `'` (`"/etc/'x'"`) routes
11814 // through `FonteCaminhoAbsolute` not
11815 // `FonteCaminhoShellQuoteGrouping` — the host-layout-leak
11816 // diagnostic is the load-bearing axis, the quote byte is
11817 // the secondary observation. Same precedence logic as every
11818 // prior leading-byte arm.
11819 let d = dep_with_fonte(DepSource::Path {
11820 caminho: "/etc/'x'".into(),
11821 });
11822 let err = d.validate().unwrap_err();
11823 assert!(
11824 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11825 "got {err:?}",
11826 );
11827 }
11828
11829 #[test]
11830 fn fonte_caminho_var_expansion_fires_before_shell_quote_grouping() {
11831 // Cascade pin on the upstream leading-`$` var-expansion
11832 // arm: a value carrying both a leading `$` and a `'`
11833 // (`"$DIR/'x'"` — the canonical "I pasted a `$DIR` shell-
11834 // variable + quoted literal at the head of a sibling-
11835 // workspace path" footgun) routes through
11836 // `FonteCaminhoVarExpansion` not
11837 // `FonteCaminhoShellQuoteGrouping`. The leading-byte
11838 // shell-variable-expansion is the more self-locating
11839 // diagnostic on values that probe as both — same
11840 // load-bearing-leading-byte cascade discipline every
11841 // prior `:caminho` arm establishes.
11842 let d = dep_with_fonte(DepSource::Path {
11843 caminho: "$DIR/'x'".into(),
11844 });
11845 let err = d.validate().unwrap_err();
11846 assert!(
11847 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11848 "got {err:?}",
11849 );
11850 }
11851
11852 #[test]
11853 fn fonte_caminho_shell_quote_grouping_fires_before_trailing_slash() {
11854 // Cascade pin on the immediate-successor arm: a value
11855 // carrying both `'` and a trailing `/` (`"../'caixa-teia'/"`
11856 // — the canonical "I tab-completed a path whose strong-
11857 // quoted body already carried the quoting from a shell-
11858 // history paste" footgun) routes through
11859 // `FonteCaminhoShellQuoteGrouping` not
11860 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11861 // is the more semantic-locating axis (an author who removes
11862 // the `'` typically also drops the trailing separator since
11863 // both are paste-from-shell artifacts).
11864 let d = dep_with_fonte(DepSource::Path {
11865 caminho: "../'caixa-teia'/".into(),
11866 });
11867 let err = d.validate().unwrap_err();
11868 assert!(
11869 matches!(
11870 err,
11871 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
11872 ),
11873 "got {err:?}",
11874 );
11875 }
11876
11877 #[test]
11878 fn fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
11879 // Diagnostic-shape pin (peer with
11880 // `fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11881 // on the closest two-byte peer arm): the error's Display
11882 // surfaces the offending `:nome`, the offending `:caminho`
11883 // verbatim, the offending byte's hex / character form, and
11884 // names the shell-quote-grouping / cross-config-DSL-string-
11885 // literal-delimiter footgun explicitly so a `feira lint`
11886 // run can render the diagnostic without re-parsing.
11887 let d = dep_with_fonte(DepSource::Path {
11888 caminho: "'../caixa-teia'".into(),
11889 });
11890 let rendered = d.validate().unwrap_err().to_string();
11891 assert!(
11892 rendered.contains("caixa-teia"),
11893 "diagnostic must name the offending dep: {rendered}",
11894 );
11895 assert!(
11896 rendered.contains("'../caixa-teia'"),
11897 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11898 );
11899 assert!(
11900 rendered.contains("0x27"),
11901 "diagnostic must surface the offending byte hex: {rendered:?}",
11902 );
11903 assert!(
11904 rendered.contains("quote-grouping"),
11905 "diagnostic must name the shell-quote-grouping footgun: {rendered:?}",
11906 );
11907 assert!(
11908 rendered.contains("string-literal"),
11909 "diagnostic must reference the cross-config-DSL string-literal-delimiter \
11910 vocabulary: {rendered:?}",
11911 );
11912 }
11913
11914 #[test]
11915 fn validate_rejects_path_fonte_with_caminho_carrying_shell_comment_lead() {
11916 // The canonical paste-from-shell-history-with-trailing-
11917 // annotation footgun: an author pastes a `cd ../caixa-teia
11918 // # legacy sibling` shell-history one-liner whose unquoted `#`
11919 // comment-lead separates the path from an inline annotation.
11920 // The POSIX shell trims the annotation to `../caixa-teia`
11921 // (POSIX.1-2017 §2.3 Token Recognition step 6), but
11922 // `Path::is_absolute` returns false on `..`, `#` is neither
11923 // a leading-byte sentinel nor a control byte nor `\` nor
11924 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` /
11925 // `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` /
11926 // `"`, and the value's last byte isn't `/` — so the value
11927 // silently passed every prior arm. The resolver folded the
11928 // value through `Path::join` looking for a literal
11929 // `./../caixa-teia # legacy sibling` subdirectory and the
11930 // failure surfaced at resolve time with a non-self-locating
11931 // `No such file or directory` error. The new arm moves the
11932 // rejection to validate time and names the offending dep +
11933 // caminho + byte verbatim.
11934 let d = dep_with_fonte(DepSource::Path {
11935 caminho: "../caixa-teia # legacy sibling".into(),
11936 });
11937 let err = d.validate().unwrap_err();
11938 let DepError::FonteCaminhoShellComment {
11939 nome,
11940 caminho,
11941 byte,
11942 } = err
11943 else {
11944 panic!("expected FonteCaminhoShellComment, got {err:?}");
11945 };
11946 assert_eq!(nome, "caixa-teia");
11947 assert_eq!(caminho, "../caixa-teia # legacy sibling");
11948 assert_eq!(byte, b'#');
11949 }
11950
11951 #[test]
11952 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_comment_paste() {
11953 // The symmetric YAML flow-scalar / values.yaml / K8s-manifest
11954 // cross-idiom-leak shape (`"../caixa-teia # pin"` — the
11955 // canonical "I copied a `path: ../caixa-teia # pin` YAML
11956 // scalar-plus-comment entry out of an aligned values.yaml and
11957 // dropped it verbatim into the `:caminho` slot" paste-idiom).
11958 // Pinned separately from the shell-history shape so the
11959 // gate's coverage extends from the single-space `#` shape to
11960 // the YAML-canonical double-space ` #` shape. YAML 1.2 §6.6
11961 // requires the `#` to be preceded by whitespace to lex as a
11962 // comment (bare `foo#bar` is a single scalar); the double-
11963 // space paste from an aligned manifest is the canonical
11964 // shape.
11965 let d = dep_with_fonte(DepSource::Path {
11966 caminho: "../caixa-teia # pin".into(),
11967 });
11968 let err = d.validate().unwrap_err();
11969 assert!(
11970 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
11971 "got {err:?}",
11972 );
11973 }
11974
11975 #[test]
11976 fn validate_rejects_path_fonte_with_caminho_carrying_url_fragment_anchor() {
11977 // The URL-fragment-identifier paste shape
11978 // (`"../caixa-teia#readme"` — the canonical
11979 // paste-from-browser-address-bar permalink shape where the
11980 // browser preserved the `#anchor` tail on the copy). Pinned
11981 // separately from the whitespace-separated shell / YAML
11982 // comment shapes so the gate covers the unpadded RFC 3986
11983 // §3.5 fragment-delimiter position too, not only positions
11984 // preceded by unquoted whitespace. Peer with the immediate-
11985 // sibling `is_git_repo_url` arm on the `:fonte :repo` axis
11986 // (a68f818) which closes the same byte under the same URL-
11987 // fragment-identifier banner.
11988 let d = dep_with_fonte(DepSource::Path {
11989 caminho: "../caixa-teia#readme".into(),
11990 });
11991 let err = d.validate().unwrap_err();
11992 assert!(
11993 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
11994 "got {err:?}",
11995 );
11996 }
11997
11998 #[test]
11999 fn validate_rejects_path_fonte_with_caminho_carrying_leading_shell_comment() {
12000 // Leading-position `#` shape (`"#../caixa-teia"` — the
12001 // "I copied a shell-comment-out entry from a commented-out
12002 // dep row" footgun). Pinned separately from the embedded
12003 // shapes so the gate covers every position, not only
12004 // whitespace-preceded / mid-value.
12005 let d = dep_with_fonte(DepSource::Path {
12006 caminho: "#../caixa-teia".into(),
12007 });
12008 let err = d.validate().unwrap_err();
12009 assert!(
12010 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12011 "got {err:?}",
12012 );
12013 }
12014
12015 #[test]
12016 fn validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment() {
12017 // The positive-control pin: the gate targets only `#`,
12018 // never adjacent printable ASCII or POSIX-valid bytes. The
12019 // canonical relative POSIX path (`"../caixa-teia"`) and a
12020 // nested deeply-pathed variant with adjacent printable
12021 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12022 // to validate cleanly so the gate doesn't widen to a "no
12023 // printable punctuation anywhere" sweep that would defeat
12024 // the entire path-fonte author surface. Peer with
12025 // `validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping`
12026 // on the immediate-predecessor arm.
12027 let d = dep_with_fonte(DepSource::Path {
12028 caminho: "../caixa-teia/sub-dir.v2".into(),
12029 });
12030 d.validate().unwrap();
12031 }
12032
12033 #[test]
12034 fn fonte_caminho_shell_quote_grouping_fires_before_shell_comment() {
12035 // Cascade pin on the immediate-predecessor arm: a value
12036 // carrying both `'` and `#` (`"../'x'#pin"` — the canonical
12037 // "I pasted a strong-quoted literal followed by a URL-
12038 // fragment permalink tail" footgun) routes through
12039 // `FonteCaminhoShellQuoteGrouping` not
12040 // `FonteCaminhoShellComment`. The shell-string-literal-
12041 // delimiter is the load-bearing root-cause edit on every
12042 // probe-as-both value; same cascade discipline every prior
12043 // `:caminho` arm establishes.
12044 let d = dep_with_fonte(DepSource::Path {
12045 caminho: "../'x'#pin".into(),
12046 });
12047 let err = d.validate().unwrap_err();
12048 assert!(
12049 matches!(
12050 err,
12051 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12052 ),
12053 "got {err:?}",
12054 );
12055 }
12056
12057 #[test]
12058 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_comment() {
12059 // Cascade pin on the upstream shell-bracket-expansion arm:
12060 // a value carrying both `[` and `#` (`"../[a-z]#pin"` — the
12061 // canonical "I pasted a glob-character-class followed by a
12062 // URL-fragment tail" footgun) routes through
12063 // `FonteCaminhoShellBracketExpansion` not
12064 // `FonteCaminhoShellComment`. The glob-character-class
12065 // expansion is the load-bearing root-cause edit on every
12066 // probe-as-both value.
12067 let d = dep_with_fonte(DepSource::Path {
12068 caminho: "../[a-z]#pin".into(),
12069 });
12070 let err = d.validate().unwrap_err();
12071 assert!(
12072 matches!(
12073 err,
12074 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12075 ),
12076 "got {err:?}",
12077 );
12078 }
12079
12080 #[test]
12081 fn fonte_caminho_shell_brace_expansion_fires_before_shell_comment() {
12082 // Cascade pin on the upstream shell-brace-expansion arm: a
12083 // value carrying both `{` and `#` (`"../{a,b}#pin"` — the
12084 // canonical "I pasted a brace-expansion fan followed by a
12085 // URL-fragment tail" footgun) routes through
12086 // `FonteCaminhoShellBraceExpansion` not
12087 // `FonteCaminhoShellComment`. The brace-expansion fan is the
12088 // load-bearing root-cause edit on every probe-as-both value.
12089 let d = dep_with_fonte(DepSource::Path {
12090 caminho: "../{a,b}#pin".into(),
12091 });
12092 let err = d.validate().unwrap_err();
12093 assert!(
12094 matches!(
12095 err,
12096 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12097 ),
12098 "got {err:?}",
12099 );
12100 }
12101
12102 #[test]
12103 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_comment() {
12104 // Cascade pin on the upstream shell-subshell-grouping arm:
12105 // a value carrying both `(` and `#` (`"../(cd foo)#pin"` —
12106 // the canonical "I pasted a subshell-grouping followed by a
12107 // URL-fragment tail" footgun) routes through
12108 // `FonteCaminhoShellSubshellGrouping` not
12109 // `FonteCaminhoShellComment`. The modern Bourne `$(<cmd>)`
12110 // command-substitution boundary is the load-bearing axis on
12111 // every probe-as-both value.
12112 let d = dep_with_fonte(DepSource::Path {
12113 caminho: "../(cd foo)#pin".into(),
12114 });
12115 let err = d.validate().unwrap_err();
12116 assert!(
12117 matches!(
12118 err,
12119 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12120 ),
12121 "got {err:?}",
12122 );
12123 }
12124
12125 #[test]
12126 fn fonte_caminho_shell_glob_fires_before_shell_comment() {
12127 // Cascade pin on the upstream shell-glob arm: a value
12128 // carrying both `*` and `#` (`"../caixa-teia/*#pin"` — the
12129 // canonical "I pasted a `*` unbounded pathname-expansion
12130 // followed by a URL-fragment tail" footgun) routes through
12131 // `FonteCaminhoShellGlob` not `FonteCaminhoShellComment`.
12132 // The unbounded pathname-expansion sentinel is the load-
12133 // bearing root-cause edit on every probe-as-both value.
12134 let d = dep_with_fonte(DepSource::Path {
12135 caminho: "../caixa-teia/*#pin".into(),
12136 });
12137 let err = d.validate().unwrap_err();
12138 assert!(
12139 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12140 "got {err:?}",
12141 );
12142 }
12143
12144 #[test]
12145 fn fonte_caminho_shell_command_substitution_fires_before_shell_comment() {
12146 // Cascade pin on the upstream shell-command-substitution
12147 // arm: a value carrying both a backtick and `#`
12148 // (``"../`whoami`#pin"`` — the canonical "I pasted a
12149 // legacy-backtick command-substitution followed by a URL-
12150 // fragment tail" footgun) routes through
12151 // `FonteCaminhoShellCommandSubstitution` not
12152 // `FonteCaminhoShellComment`. The CWE-78 shell-command-
12153 // injection vector is the load-bearing root-cause edit on
12154 // every probe-as-both value.
12155 let d = dep_with_fonte(DepSource::Path {
12156 caminho: "../`whoami`#pin".into(),
12157 });
12158 let err = d.validate().unwrap_err();
12159 assert!(
12160 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12161 "got {err:?}",
12162 );
12163 }
12164
12165 #[test]
12166 fn fonte_caminho_shell_background_fires_before_shell_comment() {
12167 // Cascade pin on the upstream shell-background arm: a value
12168 // carrying both `&` and `#` (`"../caixa-teia&pin#tail"` —
12169 // the canonical "I pasted a `cmd &` background-launch
12170 // followed by a URL-fragment tail" footgun) routes through
12171 // `FonteCaminhoShellBackground` not
12172 // `FonteCaminhoShellComment`. The background-launch tail is
12173 // the load-bearing root-cause edit on every probe-as-both
12174 // value.
12175 let d = dep_with_fonte(DepSource::Path {
12176 caminho: "../caixa-teia&pin#tail".into(),
12177 });
12178 let err = d.validate().unwrap_err();
12179 assert!(
12180 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12181 "got {err:?}",
12182 );
12183 }
12184
12185 #[test]
12186 fn fonte_caminho_shell_semicolon_fires_before_shell_comment() {
12187 // Cascade pin on the upstream shell-semicolon arm: a value
12188 // carrying both `;` and `#` (`"../caixa-teia;pin#tail"` —
12189 // the canonical sequential-cleanup + URL-fragment paste
12190 // idiom) routes through `FonteCaminhoShellSemicolon` not
12191 // `FonteCaminhoShellComment`. The sequential-command-
12192 // separator paste is the load-bearing root-cause edit on
12193 // every probe-as-both value.
12194 let d = dep_with_fonte(DepSource::Path {
12195 caminho: "../caixa-teia;pin#tail".into(),
12196 });
12197 let err = d.validate().unwrap_err();
12198 assert!(
12199 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12200 "got {err:?}",
12201 );
12202 }
12203
12204 #[test]
12205 fn fonte_caminho_shell_pipe_fires_before_shell_comment() {
12206 // Cascade pin on the upstream shell-pipe arm: a value
12207 // carrying both `|` and `#` (`"../caixa-teia|pin#tail"` —
12208 // the canonical pipeline-to-URL-fragment paste idiom) routes
12209 // through `FonteCaminhoShellPipe` not
12210 // `FonteCaminhoShellComment`. The pipeline-tail paste is
12211 // the load-bearing root-cause edit on every probe-as-both
12212 // value.
12213 let d = dep_with_fonte(DepSource::Path {
12214 caminho: "../caixa-teia|pin#tail".into(),
12215 });
12216 let err = d.validate().unwrap_err();
12217 assert!(
12218 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12219 "got {err:?}",
12220 );
12221 }
12222
12223 #[test]
12224 fn fonte_caminho_shell_redirection_fires_before_shell_comment() {
12225 // Cascade pin on the upstream shell-redirection arm: a
12226 // value carrying both `>` and `#` (`"../caixa-teia>log#pin"`
12227 // — the canonical "I pasted a `cmd > log` redirect followed
12228 // by a URL-fragment tail" footgun) routes through
12229 // `FonteCaminhoShellRedirection` not
12230 // `FonteCaminhoShellComment`. The input/output redirection
12231 // metachar carries the more self-locating `byte` payload,
12232 // so the prior arm wins on every probe-as-both value.
12233 let d = dep_with_fonte(DepSource::Path {
12234 caminho: "../caixa-teia>log#pin".into(),
12235 });
12236 let err = d.validate().unwrap_err();
12237 assert!(
12238 matches!(
12239 err,
12240 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12241 ),
12242 "got {err:?}",
12243 );
12244 }
12245
12246 #[test]
12247 fn fonte_caminho_backslash_fires_before_shell_comment() {
12248 // Cascade pin on the upstream backslash arm: a value
12249 // carrying both `\` and `#` (`"..\caixa-teia#pin"` — the
12250 // canonical "I pasted a Windows-shell path followed by a
12251 // URL-fragment tail" footgun) routes through
12252 // `FonteCaminhoBackslash` not `FonteCaminhoShellComment`.
12253 // The cross-host-OS-separator divergence is the load-
12254 // bearing axis on every probe-as-both value.
12255 let d = dep_with_fonte(DepSource::Path {
12256 caminho: "..\\caixa-teia#pin".into(),
12257 });
12258 let err = d.validate().unwrap_err();
12259 assert!(
12260 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12261 "got {err:?}",
12262 );
12263 }
12264
12265 #[test]
12266 fn fonte_caminho_control_char_fires_before_shell_comment() {
12267 // Cascade pin on the embedded-control-byte arm: a value
12268 // carrying both a control byte and `#` (`"../foo\n#pin"` —
12269 // the canonical paste-from-multiline-doc footgun where a
12270 // newline landed mid-caminho between the path and an
12271 // annotation) routes through `FonteCaminhoControlChar` not
12272 // `FonteCaminhoShellComment`. The POSIX-syscall-rejected-
12273 // byte diagnostic is the load-bearing axis on every value
12274 // that probes positive for both — mirrors the cascade
12275 // discipline on every prior arm.
12276 let d = dep_with_fonte(DepSource::Path {
12277 caminho: "../foo\n#pin".into(),
12278 });
12279 let err = d.validate().unwrap_err();
12280 assert!(
12281 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12282 "got {err:?}",
12283 );
12284 }
12285
12286 #[test]
12287 fn fonte_caminho_absolute_fires_before_shell_comment() {
12288 // Cascade pin on the load-bearing leading-byte arm: a
12289 // leading `/` value with embedded `#` (`"/etc/foo#pin"`)
12290 // routes through `FonteCaminhoAbsolute` not
12291 // `FonteCaminhoShellComment` — the host-layout-leak
12292 // diagnostic is the load-bearing axis, the fragment byte is
12293 // the secondary observation. Same precedence logic as every
12294 // prior leading-byte arm.
12295 let d = dep_with_fonte(DepSource::Path {
12296 caminho: "/etc/foo#pin".into(),
12297 });
12298 let err = d.validate().unwrap_err();
12299 assert!(
12300 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12301 "got {err:?}",
12302 );
12303 }
12304
12305 #[test]
12306 fn fonte_caminho_var_expansion_fires_before_shell_comment() {
12307 // Cascade pin on the upstream leading-`$` var-expansion
12308 // arm: a value carrying both a leading `$` and a `#`
12309 // (`"$DIR/foo#pin"` — the canonical "I pasted a `$DIR`
12310 // shell-variable at the head of a sibling-workspace path
12311 // followed by a URL-fragment tail" footgun) routes through
12312 // `FonteCaminhoVarExpansion` not `FonteCaminhoShellComment`.
12313 // The leading-byte shell-variable-expansion is the more
12314 // self-locating diagnostic on values that probe as both.
12315 let d = dep_with_fonte(DepSource::Path {
12316 caminho: "$DIR/foo#pin".into(),
12317 });
12318 let err = d.validate().unwrap_err();
12319 assert!(
12320 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12321 "got {err:?}",
12322 );
12323 }
12324
12325 #[test]
12326 fn fonte_caminho_shell_comment_fires_before_trailing_slash() {
12327 // Cascade pin on the immediate-successor arm: a value
12328 // carrying both `#` and a trailing `/`
12329 // (`"../caixa-teia#pin/"` — the canonical "I tab-completed
12330 // a URL-fragment-carrying path" footgun) routes through
12331 // `FonteCaminhoShellComment` not
12332 // `FonteCaminhoTrailingSlash`. The embedded fragment /
12333 // comment-lead byte is the more semantic-locating axis (an
12334 // author who removes the `#pin` fragment typically also
12335 // drops the trailing separator since both are paste-from-
12336 // URL / paste-from-shell-tab-completion artifacts).
12337 let d = dep_with_fonte(DepSource::Path {
12338 caminho: "../caixa-teia#pin/".into(),
12339 });
12340 let err = d.validate().unwrap_err();
12341 assert!(
12342 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. },),
12343 "got {err:?}",
12344 );
12345 }
12346
12347 #[test]
12348 fn fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte() {
12349 // Diagnostic-shape pin (peer with
12350 // `fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
12351 // on the immediate-predecessor arm): the error's Display
12352 // surfaces the offending `:nome`, the offending `:caminho`
12353 // verbatim, the offending byte's hex / character form, and
12354 // names the shell-comment / URL-fragment-identifier /
12355 // YAML-comment cross-config-DSL footgun explicitly so a
12356 // `feira lint` run can render the diagnostic without
12357 // re-parsing.
12358 let d = dep_with_fonte(DepSource::Path {
12359 caminho: "../caixa-teia#readme".into(),
12360 });
12361 let rendered = d.validate().unwrap_err().to_string();
12362 assert!(
12363 rendered.contains("caixa-teia"),
12364 "diagnostic must name the offending dep: {rendered}",
12365 );
12366 assert!(
12367 rendered.contains("../caixa-teia#readme"),
12368 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12369 );
12370 assert!(
12371 rendered.contains("0x23"),
12372 "diagnostic must surface the offending byte hex: {rendered:?}",
12373 );
12374 assert!(
12375 rendered.contains("shell-comment") || rendered.contains("comment-lead"),
12376 "diagnostic must name the shell-comment footgun: {rendered:?}",
12377 );
12378 assert!(
12379 rendered.contains("fragment") || rendered.contains("URL-fragment"),
12380 "diagnostic must reference the URL-fragment-identifier vocabulary: \
12381 {rendered:?}",
12382 );
12383 }
12384
12385 #[test]
12386 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_space() {
12387 // The canonical paste-from-browser-address-bar percent-
12388 // encoded-space footgun: an author copies `../caixa%20teia`
12389 // out of a URL-encoded README hyperlink / browser address
12390 // bar / percent-encoded permalink expecting `%20` to decode
12391 // to a literal space at the filesystem layer. POSIX
12392 // `std::path::Path` treats `%` as a literal path-component
12393 // byte, so `Path::join` looks for a literal
12394 // `./../caixa%20teia` subdirectory. `Path::is_absolute`
12395 // returns false on `..`, `%` is neither a leading-byte
12396 // sentinel nor a control byte nor `\` nor `<` / `>` nor
12397 // `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` /
12398 // `)` nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`,
12399 // and the value's last byte isn't `/` — so the value
12400 // silently passed every prior arm. The new arm moves the
12401 // rejection to validate time and names the offending dep +
12402 // caminho + byte verbatim.
12403 let d = dep_with_fonte(DepSource::Path {
12404 caminho: "../caixa%20teia".into(),
12405 });
12406 let err = d.validate().unwrap_err();
12407 let DepError::FonteCaminhoUrlPercentEncoding {
12408 nome,
12409 caminho,
12410 byte,
12411 } = err
12412 else {
12413 panic!("expected FonteCaminhoUrlPercentEncoding, got {err:?}");
12414 };
12415 assert_eq!(nome, "caixa-teia");
12416 assert_eq!(caminho, "../caixa%20teia");
12417 assert_eq!(byte, b'%');
12418 }
12419
12420 #[test]
12421 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_slash() {
12422 // The over-encoded path-separator shape (`"../caixa%2Fteia"`
12423 // intending the `%2F` as the URL encoding of `/`) locks a
12424 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
12425 // the byte-identical `path:../caixa/teia` form. Pinned
12426 // separately from the space-encoded shape so the gate's
12427 // coverage extends past the single canonical `%20` example
12428 // to any two-hex-digit percent-encoded sequence.
12429 let d = dep_with_fonte(DepSource::Path {
12430 caminho: "../caixa%2Fteia".into(),
12431 });
12432 let err = d.validate().unwrap_err();
12433 assert!(
12434 matches!(
12435 err,
12436 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12437 ),
12438 "got {err:?}",
12439 );
12440 }
12441
12442 #[test]
12443 fn validate_rejects_path_fonte_with_caminho_carrying_lone_percent() {
12444 // The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
12445 // where `%` isn't followed by two hex digits) — every
12446 // WHATWG-conformant URL parser rejects the value at parse
12447 // time per RFC 3986 §2.1, but the byte would silently ride
12448 // into the lacre before the resolver subprocess crosses the
12449 // URL-parser boundary. Pinned separately from the well-
12450 // formed `%HH` shapes so the gate covers every percent-
12451 // occurrence, not only strictly-conformant escapes.
12452 let d = dep_with_fonte(DepSource::Path {
12453 caminho: "../caixa-teia%foo".into(),
12454 });
12455 let err = d.validate().unwrap_err();
12456 assert!(
12457 matches!(
12458 err,
12459 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12460 ),
12461 "got {err:?}",
12462 );
12463 }
12464
12465 #[test]
12466 fn validate_rejects_path_fonte_with_caminho_carrying_leading_yaml_directive() {
12467 // The YAML-directive-lead paste shape (`"%YAML/../caixa-teia"`
12468 // — the canonical paste-from-top-of-doc YAML directive
12469 // block cross-idiom leak per YAML 1.2 §6.8.1). Pinned
12470 // separately from embedded shapes so the gate covers the
12471 // leading-position `%` too, not only mid-value occurrences.
12472 let d = dep_with_fonte(DepSource::Path {
12473 caminho: "%YAML/../caixa-teia".into(),
12474 });
12475 let err = d.validate().unwrap_err();
12476 assert!(
12477 matches!(
12478 err,
12479 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12480 ),
12481 "got {err:?}",
12482 );
12483 }
12484
12485 #[test]
12486 fn validate_rejects_path_fonte_with_caminho_carrying_printf_format_specifier() {
12487 // The printf-format-specifier paste shape
12488 // (`"../caixa-%s-teia"` — the canonical paste-from-shell-
12489 // diagnostic-one-liner `printf "path=%s\n" ...` idiom, CWE-
12490 // 134 format-string-injection vector). Pinned separately
12491 // from the URL-encoding shapes so the gate's rationale
12492 // extends past the RFC 3986 axis to the C / POSIX printf
12493 // format-directive-lead axis.
12494 let d = dep_with_fonte(DepSource::Path {
12495 caminho: "../caixa-%s-teia".into(),
12496 });
12497 let err = d.validate().unwrap_err();
12498 assert!(
12499 matches!(
12500 err,
12501 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12502 ),
12503 "got {err:?}",
12504 );
12505 }
12506
12507 #[test]
12508 fn validate_accepts_path_fonte_with_caminho_carrying_no_percent() {
12509 // The positive-control pin: the gate targets only `%`,
12510 // never adjacent printable ASCII or POSIX-valid bytes. The
12511 // canonical relative POSIX path (`"../caixa-teia"`) and a
12512 // nested deeply-pathed variant with adjacent printable
12513 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12514 // to validate cleanly so the gate doesn't widen to a "no
12515 // printable punctuation anywhere" sweep that would defeat
12516 // the entire path-fonte author surface. Peer with
12517 // `validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment`
12518 // on the immediate-predecessor arm.
12519 let d = dep_with_fonte(DepSource::Path {
12520 caminho: "../caixa-teia/sub-dir.v2".into(),
12521 });
12522 d.validate().unwrap();
12523 }
12524
12525 #[test]
12526 fn fonte_caminho_shell_comment_fires_before_url_percent_encoding() {
12527 // Cascade pin on the immediate-predecessor arm: a value
12528 // carrying both `#` and `%` (`"../caixa-teia#pin%20"` — the
12529 // canonical "I pasted a URL-fragment permalink followed by a
12530 // percent-encoded space tail" footgun) routes through
12531 // `FonteCaminhoShellComment` not
12532 // `FonteCaminhoUrlPercentEncoding`. The URL-fragment-
12533 // identifier is the load-bearing downstream-truncation edit
12534 // on every probe-as-both value; same cascade discipline
12535 // every prior `:caminho` arm establishes.
12536 let d = dep_with_fonte(DepSource::Path {
12537 caminho: "../caixa-teia#pin%20".into(),
12538 });
12539 let err = d.validate().unwrap_err();
12540 assert!(
12541 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12542 "got {err:?}",
12543 );
12544 }
12545
12546 #[test]
12547 fn fonte_caminho_shell_quote_grouping_fires_before_url_percent_encoding() {
12548 // Cascade pin on the upstream shell-quote-grouping arm: a
12549 // value carrying both `'` and `%` (`"../'x'%20teia"` — the
12550 // canonical "I pasted a strong-quoted literal followed by
12551 // a percent-encoded space" footgun) routes through
12552 // `FonteCaminhoShellQuoteGrouping` not
12553 // `FonteCaminhoUrlPercentEncoding`. The shell-string-
12554 // literal-delimiter is the load-bearing root-cause edit on
12555 // every probe-as-both value.
12556 let d = dep_with_fonte(DepSource::Path {
12557 caminho: "../'x'%20teia".into(),
12558 });
12559 let err = d.validate().unwrap_err();
12560 assert!(
12561 matches!(
12562 err,
12563 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12564 ),
12565 "got {err:?}",
12566 );
12567 }
12568
12569 #[test]
12570 fn fonte_caminho_backslash_fires_before_url_percent_encoding() {
12571 // Cascade pin on the upstream backslash arm: a value
12572 // carrying both `\` and `%` (`"..\\caixa%20teia"` — the
12573 // canonical "I pasted a Windows-shell path followed by a
12574 // percent-encoded space" footgun) routes through
12575 // `FonteCaminhoBackslash` not
12576 // `FonteCaminhoUrlPercentEncoding`. The cross-host-OS-
12577 // separator divergence is the load-bearing root-cause edit
12578 // on every probe-as-both value.
12579 let d = dep_with_fonte(DepSource::Path {
12580 caminho: "..\\caixa%20teia".into(),
12581 });
12582 let err = d.validate().unwrap_err();
12583 assert!(
12584 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12585 "got {err:?}",
12586 );
12587 }
12588
12589 #[test]
12590 fn fonte_caminho_control_char_fires_before_url_percent_encoding() {
12591 // Cascade pin on the upstream control-char arm: a value
12592 // carrying both a NUL byte and `%` (`"../caixa\0%20teia"` —
12593 // the canonical "I pasted a paste-from-binary-blob path
12594 // followed by a percent-encoded space" footgun) routes
12595 // through `FonteCaminhoControlChar` not
12596 // `FonteCaminhoUrlPercentEncoding`. The POSIX-syscall-
12597 // rejected byte is the load-bearing root-cause edit on
12598 // every probe-as-both value.
12599 let d = dep_with_fonte(DepSource::Path {
12600 caminho: "../caixa\0%20teia".into(),
12601 });
12602 let err = d.validate().unwrap_err();
12603 assert!(
12604 matches!(err, DepError::FonteCaminhoControlChar { byte: 0x00, .. },),
12605 "got {err:?}",
12606 );
12607 }
12608
12609 #[test]
12610 fn fonte_caminho_absolute_fires_before_url_percent_encoding() {
12611 // Cascade pin on the upstream absolute-path arm: a value
12612 // that's both absolute and carries `%` (`"/etc/passwd%20"`
12613 // — the canonical "I pasted an absolute path with a
12614 // percent-encoded space tail" footgun) routes through
12615 // `FonteCaminhoAbsolute` not
12616 // `FonteCaminhoUrlPercentEncoding`. The host-layout-leak is
12617 // the load-bearing root-cause edit on every probe-as-both
12618 // value.
12619 let d = dep_with_fonte(DepSource::Path {
12620 caminho: "/etc/passwd%20".into(),
12621 });
12622 let err = d.validate().unwrap_err();
12623 assert!(
12624 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12625 "got {err:?}",
12626 );
12627 }
12628
12629 #[test]
12630 fn fonte_caminho_var_expansion_fires_before_url_percent_encoding() {
12631 // Cascade pin on the upstream var-expansion arm: a value
12632 // starting with `$` and carrying `%` (`"$HOME/caixa%20teia"`
12633 // — the canonical "I pasted a `$HOME`-rooted path with a
12634 // percent-encoded space" footgun) routes through
12635 // `FonteCaminhoVarExpansion` not
12636 // `FonteCaminhoUrlPercentEncoding`. The shell-variable-
12637 // expansion is the load-bearing root-cause edit on every
12638 // probe-as-both value.
12639 let d = dep_with_fonte(DepSource::Path {
12640 caminho: "$HOME/caixa%20teia".into(),
12641 });
12642 let err = d.validate().unwrap_err();
12643 assert!(
12644 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12645 "got {err:?}",
12646 );
12647 }
12648
12649 #[test]
12650 fn fonte_caminho_url_percent_encoding_fires_before_trailing_slash() {
12651 // Cascade pin on the immediate-successor arm: a value
12652 // carrying both `%` and a trailing `/`
12653 // (`"../caixa%20teia/"` — the canonical "I tab-completed a
12654 // percent-encoded-space-carrying path" footgun) routes
12655 // through `FonteCaminhoUrlPercentEncoding` not
12656 // `FonteCaminhoTrailingSlash`. The embedded percent-
12657 // encoding-escape byte is the more semantic-locating axis
12658 // (an author who decodes the `%20` to a literal space is
12659 // likely to also tab-strip the trailing separator since
12660 // both are paste-from-URL / paste-from-shell-tab-completion
12661 // artifacts).
12662 let d = dep_with_fonte(DepSource::Path {
12663 caminho: "../caixa%20teia/".into(),
12664 });
12665 let err = d.validate().unwrap_err();
12666 assert!(
12667 matches!(
12668 err,
12669 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12670 ),
12671 "got {err:?}",
12672 );
12673 }
12674
12675 #[test]
12676 fn fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte() {
12677 // Diagnostic-shape pin (peer with
12678 // `fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte`
12679 // on the immediate-predecessor arm): the error's Display
12680 // surfaces the offending `:nome`, the offending `:caminho`
12681 // verbatim, the offending byte's hex / character form, and
12682 // names the URL-percent-encoding-escape / printf-format-
12683 // specifier footgun explicitly so a `feira lint` run can
12684 // render the diagnostic without re-parsing.
12685 let d = dep_with_fonte(DepSource::Path {
12686 caminho: "../caixa%20teia".into(),
12687 });
12688 let rendered = d.validate().unwrap_err().to_string();
12689 assert!(
12690 rendered.contains("caixa-teia"),
12691 "diagnostic must name the offending dep: {rendered}",
12692 );
12693 assert!(
12694 rendered.contains("../caixa%20teia"),
12695 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12696 );
12697 assert!(
12698 rendered.contains("0x25"),
12699 "diagnostic must surface the offending byte hex: {rendered:?}",
12700 );
12701 assert!(
12702 rendered.contains("percent-encoding") || rendered.contains("percent-encoded"),
12703 "diagnostic must name the URL-percent-encoding-escape footgun: {rendered:?}",
12704 );
12705 assert!(
12706 rendered.contains("printf") || rendered.contains("format-specifier"),
12707 "diagnostic must reference the printf-format-specifier vocabulary: \
12708 {rendered:?}",
12709 );
12710 }
12711
12712 #[test]
12713 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_var_expansion() {
12714 // The canonical embedded-`$` shell-variable-expansion paste
12715 // shape (`"../foo$HOME/bar"` — an author copies a partially-
12716 // substituted shell one-liner where the leading segment is a
12717 // literal `../foo` while the mid segment carries the un-
12718 // substituted `$HOME` template). The leading-`$` position is
12719 // already gated by the f4efe9c leading-byte arm which routes
12720 // through `FonteCaminhoVarExpansion`; this arm closes the
12721 // last positional gap on `$` — every position on the axis is
12722 // structurally rejected.
12723 let d = dep_with_fonte(DepSource::Path {
12724 caminho: "../foo$HOME/bar".into(),
12725 });
12726 let err = d.validate().unwrap_err();
12727 let DepError::FonteCaminhoShellVariableExpansion {
12728 nome,
12729 caminho,
12730 byte,
12731 } = err
12732 else {
12733 panic!("expected FonteCaminhoShellVariableExpansion, got {err:?}");
12734 };
12735 assert_eq!(nome, "caixa-teia");
12736 assert_eq!(caminho, "../foo$HOME/bar");
12737 assert_eq!(byte, b'$');
12738 }
12739
12740 #[test]
12741 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_braced_var_expansion() {
12742 // The symmetric braced-CI-manifest paste shape
12743 // (`"../foo${WORKSPACE}/bar"` — the canonical paste-from-
12744 // GitHub-Actions-workflow / paste-from-`.gitlab-ci.yml`
12745 // footgun). Pinned separately from the bare-`$VAR` shape so
12746 // the gate covers both POSIX shell §2.6 Parameter Expansion
12747 // syntactic forms, not only the unbraced variant. The
12748 // embedded `{` byte in `${...}` is also caught by the 598b770
12749 // shell-brace-expansion arm but that arm fires earlier in
12750 // the cascade — the `$` arm's coverage extends to `${...}`
12751 // structurally, so the diagnostic asserted here is the
12752 // brace-expansion one (which is a valid outcome; the point
12753 // of the pin is that the value never survives validation).
12754 let d = dep_with_fonte(DepSource::Path {
12755 caminho: "../foo${WORKSPACE}/bar".into(),
12756 });
12757 let err = d.validate().unwrap_err();
12758 assert!(
12759 matches!(
12760 err,
12761 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. }
12762 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12763 ),
12764 "got {err:?}",
12765 );
12766 }
12767
12768 #[test]
12769 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_command_substitution() {
12770 // The paste-from-shell-prompt command-substitution idiom
12771 // (`"../foo$(whoami)/bar"`). Pinned separately from the bare-
12772 // `$VAR` shape so the gate's rationale extends to POSIX shell
12773 // §2.6.3 Command Substitution (the modern `$(<cmd>)` form; the
12774 // legacy `` `<cmd>` `` form is already closed by the c370458
12775 // backtick arm). The embedded `(` byte in `$(...)` is also
12776 // caught structurally by the 0633c91 shell-subshell-grouping
12777 // arm which fires earlier in the cascade — the diagnostic
12778 // asserted here is either outcome, since both structurally
12779 // reject the value; the point of the pin is that the value
12780 // never survives validation.
12781 let d = dep_with_fonte(DepSource::Path {
12782 caminho: "../foo$(whoami)/bar".into(),
12783 });
12784 let err = d.validate().unwrap_err();
12785 assert!(
12786 matches!(
12787 err,
12788 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. }
12789 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12790 ),
12791 "got {err:?}",
12792 );
12793 }
12794
12795 #[test]
12796 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_positional_parameter() {
12797 // The paste-from-`Makefile` / paste-from-SQL-migration bare-
12798 // `$1` positional-parameter shape (`"../foo$1/bar"` — a Make
12799 // automatic-variable `$1` or a PostgreSQL bind-parameter `$1`
12800 // idiom copied into a caminho template). None of the prior
12801 // shell-metachar arms cover this shape (`1` is a bare digit;
12802 // no `(` / `{` / letter follows the `$`), so the arm is the
12803 // sole gate on the shape.
12804 let d = dep_with_fonte(DepSource::Path {
12805 caminho: "../foo$1/bar".into(),
12806 });
12807 let err = d.validate().unwrap_err();
12808 assert!(
12809 matches!(
12810 err,
12811 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12812 ),
12813 "got {err:?}",
12814 );
12815 }
12816
12817 #[test]
12818 fn validate_accepts_path_fonte_with_caminho_carrying_no_dollar() {
12819 // The positive-control pin (peer with
12820 // `validate_accepts_path_fonte_with_caminho_carrying_no_percent`
12821 // on the immediate-predecessor arm): the gate targets only
12822 // `$`, never adjacent printable ASCII or POSIX-valid bytes.
12823 // A relative POSIX path carrying dashes / dots / slashes /
12824 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
12825 // validate cleanly so the gate doesn't widen to a "no
12826 // printable punctuation anywhere" sweep that would defeat
12827 // the entire path-fonte author surface.
12828 let d = dep_with_fonte(DepSource::Path {
12829 caminho: "../caixa-teia/sub-dir.v2".into(),
12830 });
12831 d.validate().unwrap();
12832 }
12833
12834 #[test]
12835 fn fonte_caminho_var_expansion_fires_before_shell_variable_expansion() {
12836 // Cascade pin on the leading-`$` sibling arm at line 540: a
12837 // value starting with `$` and carrying an embedded `$` too
12838 // (`"$HOME/foo$WORKSPACE/bar"` — the canonical "I pasted a
12839 // fully-templated CI path with two un-substituted variables")
12840 // routes through `FonteCaminhoVarExpansion` not
12841 // `FonteCaminhoShellVariableExpansion`. The leading-byte
12842 // host-layout-leak is the load-bearing self-locating axis
12843 // (the leading position dominates the semantic-locating
12844 // rationale on every probe-as-both value); the embedded
12845 // arm's positional-agnostic sweep catches only values whose
12846 // leading byte doesn't route through the earlier leading-
12847 // byte arms.
12848 let d = dep_with_fonte(DepSource::Path {
12849 caminho: "$HOME/foo$WORKSPACE/bar".into(),
12850 });
12851 let err = d.validate().unwrap_err();
12852 assert!(
12853 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12854 "got {err:?}",
12855 );
12856 }
12857
12858 #[test]
12859 fn fonte_caminho_url_percent_encoding_fires_before_shell_variable_expansion() {
12860 // Cascade pin on the immediate-predecessor arm: a value
12861 // carrying both `%` and embedded `$` (`"../foo%20$HOME/bar"`
12862 // — the canonical "I pasted a percent-encoded space adjacent
12863 // to a `$HOME` template") routes through
12864 // `FonteCaminhoUrlPercentEncoding` not
12865 // `FonteCaminhoShellVariableExpansion`. The URL-percent-
12866 // encoding-escape byte is the more semantic-locating axis
12867 // (the paste-from-browser-address-bar shape is the load-
12868 // bearing self-locating edit); same cascade discipline every
12869 // prior `:caminho` arm establishes.
12870 let d = dep_with_fonte(DepSource::Path {
12871 caminho: "../foo%20$HOME/bar".into(),
12872 });
12873 let err = d.validate().unwrap_err();
12874 assert!(
12875 matches!(
12876 err,
12877 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12878 ),
12879 "got {err:?}",
12880 );
12881 }
12882
12883 #[test]
12884 fn fonte_caminho_shell_variable_expansion_fires_before_trailing_slash() {
12885 // Cascade pin on the immediate-successor arm: a value
12886 // carrying both embedded `$` and a trailing `/`
12887 // (`"../foo$HOME/bar/"` — the canonical "I tab-completed a
12888 // `$HOME`-template-carrying path") routes through
12889 // `FonteCaminhoShellVariableExpansion` not
12890 // `FonteCaminhoTrailingSlash`. The embedded shell-variable-
12891 // expansion byte is the more semantic-locating axis on
12892 // probe-as-both values (an author who substitutes the
12893 // `$HOME` template with a literal value is likely to also
12894 // tab-strip the trailing separator).
12895 let d = dep_with_fonte(DepSource::Path {
12896 caminho: "../foo$HOME/bar/".into(),
12897 });
12898 let err = d.validate().unwrap_err();
12899 assert!(
12900 matches!(
12901 err,
12902 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12903 ),
12904 "got {err:?}",
12905 );
12906 }
12907
12908 #[test]
12909 fn fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
12910 // Diagnostic-shape pin (peer with
12911 // `fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte`
12912 // on the immediate-predecessor arm): the error's Display
12913 // surfaces the offending `:nome`, the offending `:caminho`
12914 // verbatim, the offending byte's hex / character form, and
12915 // names the shell-variable-expansion / command-substitution
12916 // footgun explicitly so a `feira lint` run can render the
12917 // diagnostic without re-parsing.
12918 let d = dep_with_fonte(DepSource::Path {
12919 caminho: "../foo$HOME/bar".into(),
12920 });
12921 let rendered = d.validate().unwrap_err().to_string();
12922 assert!(
12923 rendered.contains("caixa-teia"),
12924 "diagnostic must name the offending dep: {rendered}",
12925 );
12926 assert!(
12927 rendered.contains("../foo$HOME/bar"),
12928 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12929 );
12930 assert!(
12931 rendered.contains("0x24"),
12932 "diagnostic must surface the offending byte hex: {rendered:?}",
12933 );
12934 assert!(
12935 rendered.contains("variable-expansion") || rendered.contains("variable expansion"),
12936 "diagnostic must name the shell-variable-expansion footgun: {rendered:?}",
12937 );
12938 assert!(
12939 rendered.contains("command-substitution") || rendered.contains("command substitution"),
12940 "diagnostic must reference the command-substitution vocabulary: {rendered:?}",
12941 );
12942 }
12943
12944 #[test]
12945 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_expansion() {
12946 // The fail-before-pass-after pin for the canonical paste-from-
12947 // shell-history footgun on `:caminho`. An author copies a `cd
12948 // ../caixa-teia && !sudo make install` one-liner from a quick-
12949 // start README, intending the trailing `!sudo` as a shell-
12950 // history-expansion reference but the typed slot is itself a
12951 // byte-level string parser, not a shell context, so the byte
12952 // rides into the value verbatim. Until this arm landed the `!`
12953 // byte silently passed every prior `:caminho` cascade arm
12954 // (`!` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick /
12955 // `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` /
12956 // `#` / `%` / `$`); bash with the default `histexpand` mode
12957 // rewrites `!command` to the most recent history entry
12958 // beginning with `command`, the canonical RCE-class injection
12959 // vector when the byte rides into a shell argument executed
12960 // under `bash -i` (the operator-notebook interactive shell).
12961 let d = dep_with_fonte(DepSource::Path {
12962 caminho: "../caixa-teia!sudo".into(),
12963 });
12964 let err = d.validate().unwrap_err();
12965 let DepError::FonteCaminhoShellHistoryExpansion {
12966 nome,
12967 caminho,
12968 byte,
12969 } = err
12970 else {
12971 panic!("expected FonteCaminhoShellHistoryExpansion, got {err:?}");
12972 };
12973 assert_eq!(nome, "caixa-teia");
12974 assert_eq!(caminho, "../caixa-teia!sudo");
12975 assert_eq!(byte, b'!');
12976 }
12977
12978 #[test]
12979 fn validate_rejects_path_fonte_with_caminho_carrying_double_bang_history_reference() {
12980 // The symmetric `!!` repeat-prior-command paste idiom (peer with
12981 // `validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference`
12982 // on `is_git_repo_url`). Pinned separately from the wrapped
12983 // `!command` shape so a future diagnostic-surface change that
12984 // only checked the leading or paired-bang position surfaces
12985 // here — the per-byte arm fires anywhere `!` appears in the
12986 // value, including at consecutive positions in the middle.
12987 let d = dep_with_fonte(DepSource::Path {
12988 caminho: "../foo!!/bar".into(),
12989 });
12990 let err = d.validate().unwrap_err();
12991 assert!(
12992 matches!(
12993 err,
12994 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
12995 ),
12996 "got {err:?}",
12997 );
12998 }
12999
13000 #[test]
13001 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_enthusiasm_bang() {
13002 // The English-typography enthusiasm-form paste-from-prose
13003 // idiom: an author writes `:caminho "../caixa-teia!"`
13004 // expecting the substrate to coerce it to a kebab-case slug.
13005 // Pinned separately from the `!<word>` shell-history shape so
13006 // the gate's rationale extends to the paste-from-prose surface
13007 // (the same rationale the peer `is_git_repo_url` bang arm at
13008 // 7d53c68 covers). None of the prior shell-metachar arms cover
13009 // this shape (no `!<word>` reference and no `!!` repeat), so
13010 // the arm is the sole gate on the shape.
13011 let d = dep_with_fonte(DepSource::Path {
13012 caminho: "../caixa-teia!".into(),
13013 });
13014 let err = d.validate().unwrap_err();
13015 assert!(
13016 matches!(
13017 err,
13018 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13019 ),
13020 "got {err:?}",
13021 );
13022 }
13023
13024 #[test]
13025 fn validate_accepts_path_fonte_with_caminho_carrying_no_bang() {
13026 // The positive-control pin (peer with
13027 // `validate_accepts_path_fonte_with_caminho_carrying_no_dollar`
13028 // on the immediate-predecessor arm): the gate targets only
13029 // `!`, never adjacent printable ASCII or POSIX-valid bytes.
13030 // A relative POSIX path carrying dashes / dots / slashes /
13031 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13032 // validate cleanly so the gate doesn't widen to a "no
13033 // printable punctuation anywhere" sweep that would defeat
13034 // the entire path-fonte author surface.
13035 let d = dep_with_fonte(DepSource::Path {
13036 caminho: "../caixa-teia/sub-dir.v2".into(),
13037 });
13038 d.validate().unwrap();
13039 }
13040
13041 #[test]
13042 fn fonte_caminho_shell_variable_expansion_fires_before_shell_history_expansion() {
13043 // Cascade pin on the immediate-predecessor arm: a value
13044 // carrying both embedded `$` and `!` (`"../foo$HOME/bar!sudo"`
13045 // — the canonical "I pasted a `$HOME`-templated path adjacent
13046 // to a trailing `!sudo` history-expansion") routes through
13047 // `FonteCaminhoShellVariableExpansion` not
13048 // `FonteCaminhoShellHistoryExpansion`. The shell-variable-
13049 // expansion byte is the more semantic-locating axis on
13050 // probe-as-both values (the paste-from-CI-manifest-with-`$VAR`-
13051 // template shape is the load-bearing self-locating edit);
13052 // same cascade discipline every prior `:caminho` arm
13053 // establishes.
13054 let d = dep_with_fonte(DepSource::Path {
13055 caminho: "../foo$HOME/bar!sudo".into(),
13056 });
13057 let err = d.validate().unwrap_err();
13058 assert!(
13059 matches!(
13060 err,
13061 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13062 ),
13063 "got {err:?}",
13064 );
13065 }
13066
13067 #[test]
13068 fn fonte_caminho_shell_history_expansion_fires_before_trailing_slash() {
13069 // Cascade pin on the immediate-successor arm: a value carrying
13070 // both embedded `!` and a trailing `/` (`"../caixa-teia!sudo/"`
13071 // — the canonical "I tab-completed a `!sudo`-carrying path")
13072 // routes through `FonteCaminhoShellHistoryExpansion` not
13073 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13074 // expansion byte is the more semantic-locating axis on probe-
13075 // as-both values (an author who removes the `!sudo` history
13076 // reference is likely to also tab-strip the trailing separator).
13077 let d = dep_with_fonte(DepSource::Path {
13078 caminho: "../caixa-teia!sudo/".into(),
13079 });
13080 let err = d.validate().unwrap_err();
13081 assert!(
13082 matches!(
13083 err,
13084 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13085 ),
13086 "got {err:?}",
13087 );
13088 }
13089
13090 #[test]
13091 fn fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13092 // Diagnostic-shape pin (peer with
13093 // `fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13094 // on the immediate-predecessor arm): the error's Display
13095 // surfaces the offending `:nome`, the offending `:caminho`
13096 // verbatim, the offending byte's hex / character form, and
13097 // names the shell-history-expansion / bang-operator footgun
13098 // explicitly so a `feira lint` run can render the diagnostic
13099 // without re-parsing.
13100 let d = dep_with_fonte(DepSource::Path {
13101 caminho: "../caixa-teia!sudo".into(),
13102 });
13103 let rendered = d.validate().unwrap_err().to_string();
13104 assert!(
13105 rendered.contains("caixa-teia"),
13106 "diagnostic must name the offending dep: {rendered}",
13107 );
13108 assert!(
13109 rendered.contains("../caixa-teia!sudo"),
13110 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13111 );
13112 assert!(
13113 rendered.contains("0x21"),
13114 "diagnostic must surface the offending byte hex: {rendered:?}",
13115 );
13116 assert!(
13117 rendered.contains("history-expansion") || rendered.contains("history expansion"),
13118 "diagnostic must name the shell-history-expansion footgun: {rendered:?}",
13119 );
13120 assert!(
13121 rendered.contains("bang"),
13122 "diagnostic must reference the bang-operator vocabulary: {rendered:?}",
13123 );
13124 }
13125
13126 #[test]
13127 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_substitution() {
13128 // The fail-before-pass-after pin for the canonical paste-from-
13129 // shell-history-quick-substitution footgun on `:caminho`. An
13130 // author copies a `git clone <bad-url>` line from their terminal,
13131 // corrects it via bash's `^bad^good` quick-substitution history
13132 // operator (bash reference §9.3, `set -o histexpand` mode's
13133 // default for interactive sessions), and pastes the trailing
13134 // `^bad^good` substitution fragment into a `:caminho` value
13135 // without trimming the leading `git clone` prefix — the byte
13136 // rides into the manifest verbatim. Until this arm landed the
13137 // `^` byte silently passed every prior `:caminho` cascade arm
13138 // (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick / `*`
13139 // / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` / `#` /
13140 // `%` / `$` / `!`); bash with the default `histexpand` mode
13141 // rewrites the prior command's `bad` string to `good` and re-
13142 // executes it, the paired-operator half of the `set -o
13143 // histexpand` feature the peer `!` arm already closes the prefix
13144 // half of. The peer `is_git_repo_url` axis rejects the byte at
13145 // 49e142f under the same shell-history-substitution / RFC-3986-
13146 // unwise banner.
13147 let d = dep_with_fonte(DepSource::Path {
13148 caminho: "../foo^bad^good".into(),
13149 });
13150 let err = d.validate().unwrap_err();
13151 let DepError::FonteCaminhoShellHistorySubstitution {
13152 nome,
13153 caminho,
13154 byte,
13155 } = err
13156 else {
13157 panic!("expected FonteCaminhoShellHistorySubstitution, got {err:?}");
13158 };
13159 assert_eq!(nome, "caixa-teia");
13160 assert_eq!(caminho, "../foo^bad^good");
13161 assert_eq!(byte, b'^');
13162 }
13163
13164 #[test]
13165 fn validate_rejects_path_fonte_with_caminho_carrying_regex_negation_anchor() {
13166 // The symmetric paste-from-doc-grep-pipeline footgun (peer with
13167 // `validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor`
13168 // on `is_git_repo_url`). An author copies a `grep '^archived'`
13169 // regex-anchor / negation idiom from a doc snippet and the byte
13170 // rides in verbatim. Pinned separately from the `^old^new^`
13171 // quick-substitution shape so a future diagnostic-surface change
13172 // that only checked the paired-caret history-substitution
13173 // position surfaces here — the per-byte arm fires anywhere `^`
13174 // appears in the value, including at a solitary leading-of-
13175 // segment position.
13176 let d = dep_with_fonte(DepSource::Path {
13177 caminho: "../foo/^archived".into(),
13178 });
13179 let err = d.validate().unwrap_err();
13180 assert!(
13181 matches!(
13182 err,
13183 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13184 ),
13185 "got {err:?}",
13186 );
13187 }
13188
13189 #[test]
13190 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_history_substitution_open() {
13191 // The trailing-`^` history-substitution-open shape — an author
13192 // starts typing a `^bad^good` quick-substitution but pastes only
13193 // the leading `^` sentinel before context-switching (a bash-
13194 // reference §9.3 valid histexpand prefix on its own — even a
13195 // solitary `^` on the prior command's whole re-execution shape).
13196 // Pinned separately from the `^old^new^` full-form and the leading-
13197 // of-segment `^archived` regex-anchor shape so the gate's
13198 // rationale extends to the paste-from-shell-history-with-only-
13199 // the-first-byte-selected surface. None of the prior shell-
13200 // metachar arms cover this shape.
13201 let d = dep_with_fonte(DepSource::Path {
13202 caminho: "../caixa-teia^".into(),
13203 });
13204 let err = d.validate().unwrap_err();
13205 assert!(
13206 matches!(
13207 err,
13208 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13209 ),
13210 "got {err:?}",
13211 );
13212 }
13213
13214 #[test]
13215 fn validate_accepts_path_fonte_with_caminho_carrying_no_caret() {
13216 // The positive-control pin (peer with
13217 // `validate_accepts_path_fonte_with_caminho_carrying_no_bang`
13218 // on the immediate-predecessor arm): the gate targets only
13219 // `^`, never adjacent printable ASCII or POSIX-valid bytes.
13220 // A relative POSIX path carrying dashes / dots / slashes /
13221 // digits / underscore (`"../caixa-teia/sub_v2.rc"`) must
13222 // continue to validate cleanly so the gate doesn't widen to
13223 // a "no printable punctuation anywhere" sweep that would
13224 // defeat the entire path-fonte author surface.
13225 let d = dep_with_fonte(DepSource::Path {
13226 caminho: "../caixa-teia/sub_v2.rc".into(),
13227 });
13228 d.validate().unwrap();
13229 }
13230
13231 #[test]
13232 fn fonte_caminho_shell_history_expansion_fires_before_shell_history_substitution() {
13233 // Cascade pin on the immediate-predecessor arm: a value carrying
13234 // both embedded `!` and `^` (`"../foo!sudo^bad^good"` — the
13235 // canonical "I pasted a `!sudo` history-reference next to a
13236 // `^bad^good` quick-substitution") routes through
13237 // `FonteCaminhoShellHistoryExpansion` not
13238 // `FonteCaminhoShellHistorySubstitution`. The `!` prefix form is
13239 // the more semantic-locating axis on probe-as-both values (an
13240 // author who removes the `!sudo` reference is likely to also
13241 // strip the paired `^` substitution fragment); same cascade
13242 // discipline every prior `:caminho` arm establishes.
13243 let d = dep_with_fonte(DepSource::Path {
13244 caminho: "../foo!sudo^bad^good".into(),
13245 });
13246 let err = d.validate().unwrap_err();
13247 assert!(
13248 matches!(
13249 err,
13250 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13251 ),
13252 "got {err:?}",
13253 );
13254 }
13255
13256 #[test]
13257 fn fonte_caminho_shell_history_substitution_fires_before_trailing_slash() {
13258 // Cascade pin on the immediate-successor arm: a value carrying
13259 // both embedded `^` and a trailing `/` (`"../foo^bad^good/"` —
13260 // the canonical "I tab-completed a `^bad^good`-carrying path")
13261 // routes through `FonteCaminhoShellHistorySubstitution` not
13262 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13263 // substitution byte is the more semantic-locating axis on probe-
13264 // as-both values (an author who removes the `^bad^good`
13265 // substitution fragment is likely to also tab-strip the trailing
13266 // separator).
13267 let d = dep_with_fonte(DepSource::Path {
13268 caminho: "../foo^bad^good/".into(),
13269 });
13270 let err = d.validate().unwrap_err();
13271 assert!(
13272 matches!(
13273 err,
13274 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13275 ),
13276 "got {err:?}",
13277 );
13278 }
13279
13280 #[test]
13281 fn fonte_caminho_shell_history_substitution_diagnostic_carries_offending_dep_caminho_and_byte()
13282 {
13283 // Diagnostic-shape pin (peer with
13284 // `fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13285 // on the immediate-predecessor arm): the error's Display
13286 // surfaces the offending `:nome`, the offending `:caminho`
13287 // verbatim, the offending byte's hex form, and names the
13288 // shell-history-substitution / RFC-3986-'unwise' / regex-
13289 // negation footgun explicitly so a `feira lint` run can render
13290 // the diagnostic without re-parsing.
13291 let d = dep_with_fonte(DepSource::Path {
13292 caminho: "../foo^bad^good".into(),
13293 });
13294 let rendered = d.validate().unwrap_err().to_string();
13295 assert!(
13296 rendered.contains("caixa-teia"),
13297 "diagnostic must name the offending dep: {rendered}",
13298 );
13299 assert!(
13300 rendered.contains("../foo^bad^good"),
13301 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13302 );
13303 assert!(
13304 rendered.contains("0x5e") || rendered.contains("0x5E"),
13305 "diagnostic must surface the offending byte hex: {rendered:?}",
13306 );
13307 assert!(
13308 rendered.contains("history-substitution") || rendered.contains("history substitution"),
13309 "diagnostic must name the shell-history-substitution footgun: {rendered:?}",
13310 );
13311 assert!(
13312 rendered.contains("unwise"),
13313 "diagnostic must reference the RFC-3986 'unwise' set vocabulary: {rendered:?}",
13314 );
13315 }
13316
13317 #[test]
13318 fn fonte_repo_empty_fires_before_pin_missing() {
13319 // Order pin: empty `:repo` is the more self-locating diagnostic
13320 // (every git source needs a repo; the pin discussion is
13321 // secondary), so it fires before the pin-missing arm even when
13322 // both are violated. Mirrors the
13323 // `nome_empty_takes_precedence_over_versao_invalid` ordering
13324 // discipline on the per-entry layer.
13325 let d = dep_with_fonte(DepSource::Git {
13326 repo: String::new(),
13327 tag: None,
13328 rev: None,
13329 branch: None,
13330 });
13331 let err = d.validate().unwrap_err();
13332 assert!(
13333 matches!(err, DepError::FonteRepoEmpty { .. }),
13334 "got {err:?}"
13335 );
13336 }
13337
13338 #[test]
13339 fn fonte_pin_missing_fires_before_pin_empty() {
13340 // Order pin: a fully-None pin set is structurally distinct from
13341 // a Some(empty) pin — the first surfaces as FontePinMissing
13342 // (no axis chosen), the second as FontePinEmpty (axis chosen
13343 // but value blank). Pin the disjoint relationship so a future
13344 // unification collapses to one variant only as a structural
13345 // decision.
13346 let d = dep_with_fonte(DepSource::Git {
13347 repo: "github:pleme-io/caixa-teia".into(),
13348 tag: None,
13349 rev: None,
13350 branch: None,
13351 });
13352 assert!(matches!(
13353 d.validate().unwrap_err(),
13354 DepError::FontePinMissing { .. }
13355 ));
13356 }
13357
13358 #[test]
13359 fn nome_empty_takes_precedence_over_fonte_invalid() {
13360 // Order pin: a per-entry diagnostic without a non-empty :nome
13361 // can't be self-locating, so :nome "" fires first even when
13362 // :fonte is also malformed. Mirrors
13363 // `nome_empty_takes_precedence_over_versao_invalid` on the
13364 // adjacent axis.
13365 let mut d = dep_with_fonte(DepSource::Git {
13366 repo: String::new(),
13367 tag: None,
13368 rev: None,
13369 branch: None,
13370 });
13371 d.nome = String::new();
13372 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
13373 }
13374
13375 #[test]
13376 fn versao_invalid_takes_precedence_over_fonte_invalid() {
13377 // Order pin: the :versao parse-side diagnostic is narrower than
13378 // the :fonte shape diagnostic — a malformed :versao always names
13379 // the parser's reason, which is more actionable than the
13380 // :fonte gate's "the pins are wrong" wording. Pin the ordering
13381 // so a re-ordering surfaces here.
13382 let mut d = dep_with_fonte(DepSource::Git {
13383 repo: String::new(),
13384 tag: None,
13385 rev: None,
13386 branch: None,
13387 });
13388 d.versao = "v0.1".into();
13389 let err = d.validate().unwrap_err();
13390 assert!(
13391 matches!(err, DepError::VersaoInvalid { ref nome, .. } if nome == "caixa-teia"),
13392 "got {err:?}"
13393 );
13394 }
13395
13396 #[test]
13397 fn fonte_invalid_diagnostic_carries_offending_nome() {
13398 // The diagnostic-shape pin: every :fonte error variant names
13399 // the offending dep's :nome verbatim, so the author can grep
13400 // caixa.lisp for the `:nome "<n>"` block and fix it in one
13401 // edit. Cover all seven variants so a future variant addition
13402 // forces a parallel diagnostic-shape decision.
13403 for (case, fonte) in [
13404 (
13405 "repo-empty",
13406 DepSource::Git {
13407 repo: String::new(),
13408 tag: Some("v1".into()),
13409 rev: None,
13410 branch: None,
13411 },
13412 ),
13413 (
13414 "repo-shape",
13415 DepSource::Git {
13416 repo: "github:p/x ".into(),
13417 tag: Some("v1".into()),
13418 rev: None,
13419 branch: None,
13420 },
13421 ),
13422 (
13423 "pin-missing",
13424 DepSource::Git {
13425 repo: "github:p/x".into(),
13426 tag: None,
13427 rev: None,
13428 branch: None,
13429 },
13430 ),
13431 (
13432 "pin-ambiguous",
13433 DepSource::Git {
13434 repo: "github:p/x".into(),
13435 tag: Some("v1".into()),
13436 rev: None,
13437 branch: Some("main".into()),
13438 },
13439 ),
13440 (
13441 "pin-empty",
13442 DepSource::Git {
13443 repo: "github:p/x".into(),
13444 tag: Some(String::new()),
13445 rev: None,
13446 branch: None,
13447 },
13448 ),
13449 (
13450 "caminho-empty",
13451 DepSource::Path {
13452 caminho: String::new(),
13453 },
13454 ),
13455 (
13456 "caminho-absolute",
13457 DepSource::Path {
13458 caminho: "/home/me/work/caixa-teia".into(),
13459 },
13460 ),
13461 ] {
13462 let d = dep_with_fonte(fonte);
13463 let msg = d
13464 .validate()
13465 .expect_err(&format!("{case}: expected fonte error"))
13466 .to_string();
13467 assert!(
13468 msg.contains("\"caixa-teia\""),
13469 "{case}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
13470 );
13471 }
13472 }
13473
13474 // -- :tag / :branch value-shape gate ----------------------------------
13475
13476 #[test]
13477 fn validate_rejects_git_fonte_with_tag_carrying_trailing_space() {
13478 // The canonical paste-from-doc footgun on `:tag` — author
13479 // copies `"v0.1.0 "` (trailing space) out of a release-notes
13480 // paragraph. Until this gate landed the empty-pin arm passed
13481 // (the string isn't empty), the resolver issued
13482 // `git fetch <remote> tag 'v0.1.0 '`, and the failure
13483 // surfaced at clone time with a quoting-confused git error
13484 // far from the source caixa.lisp. The new gate moves the
13485 // check to caixa-build time and names the offending dep +
13486 // pin + value verbatim.
13487 let d = dep_with_fonte(DepSource::Git {
13488 repo: "github:pleme-io/caixa-teia".into(),
13489 tag: Some("v0.1.0 ".into()),
13490 rev: None,
13491 branch: None,
13492 });
13493 let err = d.validate().unwrap_err();
13494 let DepError::FontePinShape {
13495 nome,
13496 pin,
13497 value,
13498 reason,
13499 } = err
13500 else {
13501 panic!("expected FontePinShape, got other variant");
13502 };
13503 assert_eq!(nome, "caixa-teia");
13504 assert_eq!(pin, ":tag");
13505 assert_eq!(value, "v0.1.0 ");
13506 assert!(
13507 reason.contains("whitespace"),
13508 "reason must surface the whitespace arm, got {reason:?}"
13509 );
13510 }
13511
13512 #[test]
13513 fn validate_rejects_git_fonte_with_tag_carrying_lock_suffix() {
13514 // The `.lock` suffix is git's atomic-rename guard for
13515 // in-flight ref updates — a refname ending in `.lock` is
13516 // unwritable on disk. Pinned separately from the whitespace
13517 // arm so a future relaxation that admits one but not the
13518 // other surfaces here.
13519 let d = dep_with_fonte(DepSource::Git {
13520 repo: "github:pleme-io/caixa-teia".into(),
13521 tag: Some("v0.1.0.lock".into()),
13522 rev: None,
13523 branch: None,
13524 });
13525 let err = d.validate().unwrap_err();
13526 let DepError::FontePinShape {
13527 pin, value, reason, ..
13528 } = err
13529 else {
13530 panic!("expected FontePinShape, got other variant");
13531 };
13532 assert_eq!(pin, ":tag");
13533 assert_eq!(value, "v0.1.0.lock");
13534 assert!(
13535 reason.contains(".lock"),
13536 "reason must surface the .lock arm, got {reason:?}"
13537 );
13538 }
13539
13540 #[test]
13541 fn validate_rejects_git_fonte_with_branch_carrying_embedded_space() {
13542 // The canonical "branch name with spaces" footgun (`feature
13543 // foo`, `release branch`) — git's refname parser rejects raw
13544 // whitespace, and the failure surfaces at `git checkout
13545 // 'feature foo'` time with a quoting-confused error far from
13546 // the source caixa.lisp. Pinned on the `:branch` axis so the
13547 // gate-applies-to-both-:tag-and-:branch contract is a build-
13548 // error to relax.
13549 let d = dep_with_fonte(DepSource::Git {
13550 repo: "github:pleme-io/caixa-teia".into(),
13551 tag: None,
13552 rev: None,
13553 branch: Some("feature/foo bar".into()),
13554 });
13555 let err = d.validate().unwrap_err();
13556 let DepError::FontePinShape {
13557 pin, value, reason, ..
13558 } = err
13559 else {
13560 panic!("expected FontePinShape, got other variant");
13561 };
13562 assert_eq!(pin, ":branch");
13563 assert_eq!(value, "feature/foo bar");
13564 assert!(
13565 reason.contains("whitespace"),
13566 "reason must surface the whitespace arm, got {reason:?}"
13567 );
13568 }
13569
13570 #[test]
13571 fn validate_rejects_git_fonte_with_branch_carrying_qualified_prefix() {
13572 // The `refs/heads/main` shape — the canonical "I copied the
13573 // fully-qualified ref out of `git show-ref` instead of the
13574 // leaf" footgun. The caixa-resolver prepends `refs/heads/`
13575 // at clone time, so this resolves to a literal ref named
13576 // `refs/heads/refs/heads/main` on disk; the silent double-
13577 // prefix is the load-bearing reason to gate at validate.
13578 // The diagnostic must enumerate the leaf the author probably
13579 // meant (`"main"`) so the fix is one edit.
13580 let d = dep_with_fonte(DepSource::Git {
13581 repo: "github:pleme-io/caixa-teia".into(),
13582 tag: None,
13583 rev: None,
13584 branch: Some("refs/heads/main".into()),
13585 });
13586 let err = d.validate().unwrap_err();
13587 let DepError::FontePinShape {
13588 pin, value, reason, ..
13589 } = err
13590 else {
13591 panic!("expected FontePinShape, got other variant");
13592 };
13593 assert_eq!(pin, ":branch");
13594 assert_eq!(value, "refs/heads/main");
13595 assert!(
13596 reason.contains("fully-qualified"),
13597 "reason must surface the qualified-prefix arm, got {reason:?}"
13598 );
13599 assert!(
13600 reason.contains("\"main\""),
13601 "reason must quote the leaf the author probably meant, got {reason:?}"
13602 );
13603 }
13604
13605 #[test]
13606 fn validate_rejects_git_fonte_with_tag_carrying_qualified_prefix() {
13607 // Sibling arm of the qualified-prefix gate on the `:tag`
13608 // axis (`refs/tags/v0.1.0` — same `git show-ref` output-leak
13609 // footgun). Pinned separately so a future relaxation that
13610 // only catches the `:branch` arm surfaces here.
13611 let d = dep_with_fonte(DepSource::Git {
13612 repo: "github:pleme-io/caixa-teia".into(),
13613 tag: Some("refs/tags/v0.1.0".into()),
13614 rev: None,
13615 branch: None,
13616 });
13617 let err = d.validate().unwrap_err();
13618 let DepError::FontePinShape {
13619 pin, value, reason, ..
13620 } = err
13621 else {
13622 panic!("expected FontePinShape, got other variant");
13623 };
13624 assert_eq!(pin, ":tag");
13625 assert_eq!(value, "refs/tags/v0.1.0");
13626 assert!(
13627 reason.contains("fully-qualified"),
13628 "reason must surface the qualified-prefix arm, got {reason:?}"
13629 );
13630 assert!(
13631 reason.contains("\"v0.1.0\""),
13632 "reason must quote the leaf the author probably meant, got {reason:?}"
13633 );
13634 }
13635
13636 #[test]
13637 fn validate_rejects_git_fonte_with_branch_named_at() {
13638 // The bare `@` is git's alias for `HEAD`; a `:branch "@"` is
13639 // unsourceable. Pinned so a future relaxation that admits
13640 // any single-character refname surfaces here.
13641 let d = dep_with_fonte(DepSource::Git {
13642 repo: "github:pleme-io/caixa-teia".into(),
13643 tag: None,
13644 rev: None,
13645 branch: Some("@".into()),
13646 });
13647 let err = d.validate().unwrap_err();
13648 let DepError::FontePinShape { pin, value, .. } = err else {
13649 panic!("expected FontePinShape, got other variant");
13650 };
13651 assert_eq!(pin, ":branch");
13652 assert_eq!(value, "@");
13653 }
13654
13655 #[test]
13656 fn validate_rejects_git_fonte_with_tag_carrying_double_dot() {
13657 // Git's `<rev1>..<rev2>` range grammar reserves `..` —
13658 // a `:tag "../escape"` (path-traversal-shaped slug) silently
13659 // passes parse and surfaces as a refname-parse error or, on
13660 // older git, a literal `../escape` checkout that escapes the
13661 // refs/ directory tree. Pinned separately from the
13662 // qualified-prefix arm so a future relaxation that catches
13663 // one but not the other surfaces here.
13664 let d = dep_with_fonte(DepSource::Git {
13665 repo: "github:pleme-io/caixa-teia".into(),
13666 tag: Some("../escape".into()),
13667 rev: None,
13668 branch: None,
13669 });
13670 let err = d.validate().unwrap_err();
13671 let DepError::FontePinShape { pin, value, .. } = err else {
13672 panic!("expected FontePinShape, got other variant");
13673 };
13674 assert_eq!(pin, ":tag");
13675 assert_eq!(value, "../escape");
13676 }
13677
13678 #[test]
13679 fn validate_accepts_git_fonte_with_hierarchical_branch() {
13680 // The positive-control pin: hierarchical refnames with one or
13681 // more `/` separators (the `feature/foo` / `user/jdoe/feat`
13682 // canonical idiom) round-trip through the gate. Pinned
13683 // separately from the leaf-`"main"` positive control so a
13684 // future tightening that rejects all multi-component refnames
13685 // surfaces here.
13686 let d = dep_with_fonte(DepSource::Git {
13687 repo: "github:pleme-io/caixa-teia".into(),
13688 tag: None,
13689 rev: None,
13690 branch: Some("feature/checkout-rewrite".into()),
13691 });
13692 d.validate().unwrap();
13693 }
13694
13695 #[test]
13696 fn validate_accepts_git_fonte_with_prerelease_tag() {
13697 // The positive-control pin: semver pre-release shape
13698 // (`v0.1.0-alpha.1`) — the in-component dot is allowed
13699 // (only consecutive `..` and trailing `.` are rejected), the
13700 // mid-component hyphen is allowed. Pinned separately from
13701 // the bare-`"v0.1.0"` positive control so a future tightening
13702 // that rejects pre-release tags surfaces here.
13703 let d = dep_with_fonte(DepSource::Git {
13704 repo: "github:pleme-io/caixa-teia".into(),
13705 tag: Some("v0.1.0-alpha.1".into()),
13706 rev: None,
13707 branch: None,
13708 });
13709 d.validate().unwrap();
13710 }
13711
13712 #[test]
13713 fn validate_rejects_git_fonte_with_rev_carrying_refname_unfriendly_value() {
13714 // The `:rev` axis is routed through `crate::render::is_git_oid`
13715 // (a SHA's character set is `[0-9a-f]`, not a refname's), so a
13716 // value with refname-shape punctuation (here, a `:` mid-string
13717 // — would be a refname violation under `is_git_ref_name` too)
13718 // is rejected at the OID-shape gate. The two predicates
13719 // partition the `:fonte` pin axes structurally: an `:rev` value
13720 // that's a valid refname (`:rev "main"`, `:rev "v0.1.0"`) is
13721 // *still* rejected here because every refname character outside
13722 // `[0-9a-f]` fails the OID gate. Same shape as
13723 // `fonte_pin_shape_diagnostic_carries_offending_nome_pin_value`
13724 // on the refname-shaped axes — the diagnostic names the
13725 // offending dep + pin + value verbatim. The flip-from-accept
13726 // case the prior `:tag`/`:branch` gate left as a "future axis"
13727 // (e70d213) — now landed.
13728 let d = dep_with_fonte(DepSource::Git {
13729 repo: "github:pleme-io/caixa-teia".into(),
13730 tag: None,
13731 rev: Some("c0ffee:notarefname".into()),
13732 branch: None,
13733 });
13734 let err = d.validate().unwrap_err();
13735 let DepError::FontePinShape {
13736 nome,
13737 pin,
13738 value,
13739 reason,
13740 } = err
13741 else {
13742 panic!("expected FontePinShape, got other variant");
13743 };
13744 assert_eq!(nome, "caixa-teia");
13745 assert_eq!(pin, ":rev");
13746 assert_eq!(value, "c0ffee:notarefname");
13747 assert!(
13748 !reason.is_empty(),
13749 "FontePinShape `reason` must carry the predicate's wording verbatim"
13750 );
13751 }
13752
13753 #[test]
13754 fn validate_accepts_git_fonte_with_rev_full_sha1() {
13755 // The positive-control pin on the SHA-1 OID width: exactly 40
13756 // lowercase hex characters — the canonical `git rev-parse HEAD`
13757 // emission on a SHA-1-hashed repository (the default on every
13758 // pre-2.42 git and the canonical pleme-io substrate hash).
13759 // Pinned separately from the SHA-256 positive control so a
13760 // future tightening that only admits one width surfaces here.
13761 let d = dep_with_fonte(DepSource::Git {
13762 repo: "github:pleme-io/caixa-teia".into(),
13763 tag: None,
13764 rev: Some("0123456789abcdef0123456789abcdef01234567".into()),
13765 branch: None,
13766 });
13767 d.validate().unwrap();
13768 }
13769
13770 #[test]
13771 fn validate_accepts_git_fonte_with_rev_full_sha256() {
13772 // The positive-control pin on the SHA-256 OID width: exactly
13773 // 64 lowercase hex characters — `git`'s
13774 // `extensions.objectFormat = sha256` emission (GA since Git
13775 // 2.42 / Oct 2023). The substrate admits either canonical
13776 // width so an `:rev` authored against a SHA-256-hashed
13777 // upstream round-trips through the gate without per-repo
13778 // configuration. Pinned separately from the SHA-1 positive
13779 // control so a future tightening that drops one width surfaces
13780 // here as a structural decision.
13781 let d = dep_with_fonte(DepSource::Git {
13782 repo: "github:pleme-io/caixa-teia".into(),
13783 tag: None,
13784 rev: Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into()),
13785 branch: None,
13786 });
13787 d.validate().unwrap();
13788 }
13789
13790 #[test]
13791 fn validate_rejects_git_fonte_with_rev_abbreviated_prefix() {
13792 // The canonical `git log --short` / `git rev-parse --short HEAD`
13793 // paste-from-release-notes footgun: a 7-char prefix (git's
13794 // default `core.abbrev`) silently passes string emptiness
13795 // checks and resolves to one commit today, but becomes ambiguous
13796 // tomorrow as the repo grows. Until this gate landed the empty-
13797 // pin arm passed (the string isn't empty) and the resolver
13798 // accepted the prefix through git's separate prefix-lookup pass
13799 // — defeating the reproducibility contract `:rev` carries vs.
13800 // `:tag` / `:branch`. The new gate moves the check to caixa-
13801 // build time and names the offending dep + pin + value verbatim.
13802 let d = dep_with_fonte(DepSource::Git {
13803 repo: "github:pleme-io/caixa-teia".into(),
13804 tag: None,
13805 rev: Some("c0ffee0".into()),
13806 branch: None,
13807 });
13808 let err = d.validate().unwrap_err();
13809 let DepError::FontePinShape {
13810 pin, value, reason, ..
13811 } = err
13812 else {
13813 panic!("expected FontePinShape, got other variant");
13814 };
13815 assert_eq!(pin, ":rev");
13816 assert_eq!(value, "c0ffee0");
13817 assert!(
13818 reason.contains("abbreviated") || reason.contains("ambiguous"),
13819 "reason must surface the abbreviation arm, got {reason:?}"
13820 );
13821 }
13822
13823 #[test]
13824 fn validate_rejects_git_fonte_with_rev_uppercase_hex() {
13825 // The canonical "I pasted the SHA in uppercase" footgun: `git
13826 // porcelain` emits OIDs lowercase exclusively, so an uppercase-
13827 // bearing `:rev` round-trips inconsistently across the
13828 // resolver's `git fetch <remote> <:rev>` ↔ `git rev-parse HEAD`
13829 // equality-check pipeline and fails the lacre's content-
13830 // addressing probe with a confusing case-only diff. Pinned
13831 // separately from the non-hex arm so a future relaxation that
13832 // admits one but not the other surfaces here.
13833 let d = dep_with_fonte(DepSource::Git {
13834 repo: "github:pleme-io/caixa-teia".into(),
13835 tag: None,
13836 rev: Some("DEADBEEFCAFEBABE0123456789ABCDEF01234567".into()),
13837 branch: None,
13838 });
13839 let err = d.validate().unwrap_err();
13840 let DepError::FontePinShape {
13841 pin, value, reason, ..
13842 } = err
13843 else {
13844 panic!("expected FontePinShape, got other variant");
13845 };
13846 assert_eq!(pin, ":rev");
13847 assert_eq!(value, "DEADBEEFCAFEBABE0123456789ABCDEF01234567");
13848 assert!(
13849 reason.contains("uppercase"),
13850 "reason must surface the uppercase arm, got {reason:?}"
13851 );
13852 }
13853
13854 #[test]
13855 fn validate_rejects_git_fonte_with_rev_refname_value() {
13856 // The cross-axis mis-slot footgun: `:rev "main"` — the author
13857 // conflated `:rev` (hex commit ID, immutable) and `:branch`
13858 // (mutable ref pointing at whatever HEAD is today). Until this
13859 // gate landed the resolver silently dispatched on the value
13860 // shape ("`main` doesn't look like a SHA, fall back to
13861 // refname"), defeating the `:rev` reproducibility contract.
13862 // The new gate rejects every non-hex value on the `:rev` axis,
13863 // so the `:rev`/`:branch` boundary is structurally enforced —
13864 // a refname in the `:rev` slot is a build error, not a
13865 // resolver-time silent reinterpretation.
13866 let d = dep_with_fonte(DepSource::Git {
13867 repo: "github:pleme-io/caixa-teia".into(),
13868 tag: None,
13869 rev: Some("main".into()),
13870 branch: None,
13871 });
13872 let err = d.validate().unwrap_err();
13873 let DepError::FontePinShape {
13874 pin, value, reason, ..
13875 } = err
13876 else {
13877 panic!("expected FontePinShape, got other variant");
13878 };
13879 assert_eq!(pin, ":rev");
13880 assert_eq!(value, "main");
13881 // 4 chars `main` fails the length arm before the character arm,
13882 // so the diagnostic surfaces the abbreviation wording (same
13883 // path the `c0ffee0` 7-char fixture lands on); the structural
13884 // assertion is just that the `:rev "main"` value is rejected.
13885 assert!(
13886 !reason.is_empty(),
13887 "FontePinShape reason must be non-empty for refname-shaped :rev"
13888 );
13889 }
13890
13891 #[test]
13892 fn validate_rejects_git_fonte_with_rev_tag_shaped_value() {
13893 // Sibling cross-axis mis-slot: `:rev "v0.1.0"` — the author
13894 // conflated `:rev` and `:tag`. Pinned separately from the
13895 // `:rev "main"` (`:branch` mis-slot) arm so a future relaxation
13896 // that catches one but not the other surfaces here. The
13897 // length arm fires first (6 chars ≠ 40 ≠ 64); the structural
13898 // assertion is just that the cross-axis mis-slot is a build
13899 // error, regardless of which sub-arm surfaces the diagnostic
13900 // (`is_git_oid` rejects at the first violation; longer
13901 // tag-shape values would hit the non-hex arm instead).
13902 let d = dep_with_fonte(DepSource::Git {
13903 repo: "github:pleme-io/caixa-teia".into(),
13904 tag: None,
13905 rev: Some("v0.1.0".into()),
13906 branch: None,
13907 });
13908 let err = d.validate().unwrap_err();
13909 let DepError::FontePinShape {
13910 pin, value, reason, ..
13911 } = err
13912 else {
13913 panic!("expected FontePinShape, got other variant");
13914 };
13915 assert_eq!(pin, ":rev");
13916 assert_eq!(value, "v0.1.0");
13917 assert!(
13918 !reason.is_empty(),
13919 "FontePinShape reason must be non-empty for tag-shaped :rev"
13920 );
13921 }
13922
13923 #[test]
13924 fn validate_rejects_git_fonte_with_rev_too_long() {
13925 // Boundary case on the upper end: 41 hex chars — one past the
13926 // SHA-1 width, well below the SHA-256 width. Pin so a future
13927 // relaxation that admits "long enough to be a SHA" without
13928 // matching either canonical width surfaces here. The diagnostic
13929 // names the offending length verbatim so the author's grep
13930 // target is unambiguous (either trim one char or paste the
13931 // full SHA-256).
13932 let too_long: String = "0".repeat(41);
13933 let d = dep_with_fonte(DepSource::Git {
13934 repo: "github:pleme-io/caixa-teia".into(),
13935 tag: None,
13936 rev: Some(too_long.clone()),
13937 branch: None,
13938 });
13939 let err = d.validate().unwrap_err();
13940 let DepError::FontePinShape {
13941 pin, value, reason, ..
13942 } = err
13943 else {
13944 panic!("expected FontePinShape, got other variant");
13945 };
13946 assert_eq!(pin, ":rev");
13947 assert_eq!(value, too_long);
13948 assert!(
13949 reason.contains("41"),
13950 "reason must surface the offending length verbatim, got {reason:?}"
13951 );
13952 }
13953
13954 #[test]
13955 fn validate_rejects_git_fonte_with_rev_carrying_whitespace() {
13956 // The canonical paste-from-doc footgun on `:rev` — author
13957 // copies `"deadbeefcafe…0123 "` (trailing space) out of a
13958 // commit-message paragraph. Until this gate landed the empty-
13959 // pin arm passed (the string isn't empty), the resolver issued
13960 // `git fetch <remote> 'deadbeef… '` and the failure surfaced at
13961 // clone time with a quoting-confused git error far from the
13962 // source caixa.lisp. The new gate moves the check to caixa-
13963 // build time. Length is 41 (40 hex + space) so the length arm
13964 // fires first — pinned separately from the pure-length arm to
13965 // ensure the diagnostic surfaces *some* parser wording, not
13966 // silently pass through.
13967 let with_space = "0123456789abcdef0123456789abcdef01234567 ".to_string();
13968 let d = dep_with_fonte(DepSource::Git {
13969 repo: "github:pleme-io/caixa-teia".into(),
13970 tag: None,
13971 rev: Some(with_space.clone()),
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, with_space);
13983 assert!(
13984 !reason.is_empty(),
13985 "FontePinShape reason must be non-empty for whitespace-bearing :rev"
13986 );
13987 }
13988
13989 #[test]
13990 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value_for_rev() {
13991 // Diagnostic-shape pin on the `:rev` axis: every FontePinShape
13992 // variant on this axis names the offending dep's `:nome` + the
13993 // `:rev` axis + the offending value verbatim, so the author's
13994 // grep target is the literal `:rev "<value>"` block in
13995 // caixa.lisp. Sibling of the `fonte_pin_shape_diagnostic_
13996 // carries_offending_nome_pin_value` test on the refname-shaped
13997 // (`:tag` / `:branch`) axes.
13998 let d = dep_with_fonte(DepSource::Git {
13999 repo: "github:p/x".into(),
14000 tag: None,
14001 rev: Some("not-a-sha".into()),
14002 branch: None,
14003 });
14004 let msg = d
14005 .validate()
14006 .expect_err(":rev: expected FontePinShape")
14007 .to_string();
14008 assert!(
14009 msg.contains("\"caixa-teia\""),
14010 ":rev: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14011 );
14012 assert!(
14013 msg.contains(":rev"),
14014 ":rev: diagnostic must name the offending pin axis, got {msg:?}"
14015 );
14016 assert!(
14017 msg.contains("not-a-sha"),
14018 ":rev: diagnostic must quote the offending value verbatim, got {msg:?}"
14019 );
14020 }
14021
14022 #[test]
14023 fn fonte_pin_empty_fires_before_pin_shape() {
14024 // Order pin: a `Some("")` `:tag` is the more self-locating
14025 // diagnostic (the author chose an axis but left it blank;
14026 // grep is unambiguous), so it fires before the shape gate
14027 // even when both arms would match. Pinned so a future
14028 // reordering surfaces here. Mirrors the
14029 // `fonte_repo_empty_fires_before_pin_missing` ordering
14030 // discipline on the peer per-axis arms.
14031 let d = dep_with_fonte(DepSource::Git {
14032 repo: "github:pleme-io/caixa-teia".into(),
14033 tag: Some(String::new()),
14034 rev: None,
14035 branch: None,
14036 });
14037 assert!(matches!(
14038 d.validate().unwrap_err(),
14039 DepError::FontePinEmpty { ref pin, .. } if pin == ":tag"
14040 ));
14041 }
14042
14043 #[test]
14044 fn fonte_pin_shape_fires_after_repo_empty() {
14045 // Order pin: `:repo ""` is the more self-locating axis
14046 // (every git source needs a repo; the per-pin shape gate is
14047 // secondary), so the repo-empty arm fires before the
14048 // per-pin shape arm even when both are violated. Pinned so
14049 // a future reordering surfaces here. Mirrors
14050 // `fonte_repo_empty_fires_before_pin_missing` on the
14051 // adjacent axis pair.
14052 let d = dep_with_fonte(DepSource::Git {
14053 repo: String::new(),
14054 tag: Some("v0.1.0 ".into()),
14055 rev: None,
14056 branch: None,
14057 });
14058 assert!(matches!(
14059 d.validate().unwrap_err(),
14060 DepError::FonteRepoEmpty { .. }
14061 ));
14062 }
14063
14064 #[test]
14065 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value() {
14066 // Diagnostic-shape pin across both refname-shaped axes
14067 // (`:tag` + `:branch`): every `FontePinShape` variant names
14068 // the offending dep's `:nome` + the offending pin axis + the
14069 // offending value verbatim, so the author's grep target is
14070 // unambiguous (the literal `:tag "<value>"` / `:branch
14071 // "<value>"` lands in caixa.lisp with quotes). Cover both
14072 // pin axes so a future variant addition forces a parallel
14073 // diagnostic-shape decision.
14074 for (pin_label, fonte) in [
14075 (
14076 ":tag",
14077 DepSource::Git {
14078 repo: "github:p/x".into(),
14079 tag: Some("v0.1.0~1".into()),
14080 rev: None,
14081 branch: None,
14082 },
14083 ),
14084 (
14085 ":branch",
14086 DepSource::Git {
14087 repo: "github:p/x".into(),
14088 tag: None,
14089 rev: None,
14090 branch: Some("feature/foo*".into()),
14091 },
14092 ),
14093 ] {
14094 let d = dep_with_fonte(fonte);
14095 let msg = d
14096 .validate()
14097 .expect_err(&format!("{pin_label}: expected FontePinShape"))
14098 .to_string();
14099 assert!(
14100 msg.contains("\"caixa-teia\""),
14101 "{pin_label}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14102 );
14103 assert!(
14104 msg.contains(pin_label),
14105 "{pin_label}: diagnostic must name the offending pin axis, got {msg:?}"
14106 );
14107 }
14108 }
14109
14110 #[test]
14111 fn git_source_json_round_trip() {
14112 let src = DepSource::Git {
14113 repo: "github:pleme-io/caixa-teia".into(),
14114 tag: Some("v0.1.0".into()),
14115 rev: None,
14116 branch: None,
14117 };
14118 let s = serde_json::to_string(&src).unwrap();
14119 assert!(s.contains(&format!(
14120 r#""{tipo}":"{git}""#,
14121 tipo = crate::render::DEP_SOURCE_KEY_TIPO,
14122 git = crate::render::DEP_SOURCE_TIPO_GIT,
14123 )));
14124 assert!(s.contains(r#""repo":"github:pleme-io/caixa-teia""#));
14125 assert!(s.contains(r#""tag":"v0.1.0""#));
14126 assert!(!s.contains("rev"));
14127 assert!(!s.contains("branch"));
14128 let round: DepSource = serde_json::from_str(&s).unwrap();
14129 assert_eq!(round, src);
14130 }
14131
14132 // ── DEP_SOURCE_{KEY_TIPO,TIPO_GIT,TIPO_PATH} drift-detection ────────
14133 //
14134 // The `#[serde(tag = "tipo", rename_all = "lowercase")]` derive
14135 // attribute on [`DepSource`] pins three load-bearing byte-sequences
14136 // that flow into every serialized `Dep.fonte` block: the outer
14137 // discriminator-key `"tipo"` the `tag = "tipo"` attribute names, and
14138 // the two admitted variant-tag values `"git"` / `"path"` the
14139 // `rename_all = "lowercase"` attribute pins as the discriminator's
14140 // closed-set arms. The three pin tests below round-trip a
14141 // fully-populated variant of each arm through
14142 // [`serde_json::to_value`] and assert each canonical byte-sequence
14143 // appears at its axis — pins a hypothetical future
14144 // `tag = "type"` / `tag = "source_type"` typo, a `rename_all`
14145 // rebrand (`"UPPERCASE"` / `"snake_case"` / `"kebab-case"`), or a
14146 // Rust-side variant rename (`Git` → `Repository`, `Path` → `Local`)
14147 // at build time rather than at fetch time when the resolver's
14148 // `Dep.fonte` dispatch silently fails to match on the drifted
14149 // discriminator. Same "serialize-and-check" discipline the peer
14150 // `M2_LIMITS_KEY_*`, `M2_BEHAVIOR_KEY_ON_*`, `SUPERVISOR_KEY_*`,
14151 // and `MEMBRO_KEY_*` drift-detection pins carry — extended here
14152 // to the last `#[serde(tag = ..., rename_all = ...)]` discriminator
14153 // family in caixa-core lacking a lifted peer.
14154
14155 #[test]
14156 fn dep_source_git_serde_keys_match_lifted_dep_source_key_consts() {
14157 // Fail-before-pass-after: a future `tag = "type"` at the derive
14158 // attribute would serialize under `"type":"git"`, and this test
14159 // would trip because `"tipo"` no longer appears at the emitted
14160 // discriminator key. A future `rename_all = "kebab-case"` /
14161 // `"snake_case"` (both no-ops on `Git` since it lacks internal
14162 // word boundaries) is caught by the sibling
14163 // `dep_source_path_serde_keys_match_lifted_dep_source_key_consts`
14164 // pin below (Path has no internal boundary either but the pair
14165 // catches any per-arm inconsistency). A future variant rename
14166 // `Git` → `Repository` would emit `"tipo":"repository"` and
14167 // trip this pin.
14168 let src = DepSource::Git {
14169 repo: "github:pleme-io/caixa-teia".into(),
14170 tag: Some("v0.1.0".into()),
14171 rev: None,
14172 branch: None,
14173 };
14174 let json = serde_json::to_value(&src).unwrap();
14175 let obj = json.as_object().expect("Git serializes as a JSON object");
14176 assert_eq!(
14177 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14178 .and_then(serde_json::Value::as_str),
14179 Some(crate::render::DEP_SOURCE_TIPO_GIT),
14180 "DepSource::Git must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14181 with value DEP_SOURCE_TIPO_GIT — attribute drift or variant rename \
14182 detected in {json}"
14183 );
14184 }
14185
14186 #[test]
14187 fn dep_source_path_serde_keys_match_lifted_dep_source_key_consts() {
14188 // Fail-before-pass-after: a future variant rename `Path` →
14189 // `Local` / `Filesystem` would emit `"tipo":"local"` and trip
14190 // this pin. A per-consumer disambiguation as the `defcaixa`
14191 // macro stabilizes ("caminho" → "path" for English-uniformity)
14192 // is scoped to the inner field key, not the discriminator; this
14193 // pin is orthogonal to that and catches only the outer
14194 // discriminator drift.
14195 let src = DepSource::Path {
14196 caminho: "../caixa-teia".into(),
14197 };
14198 let json = serde_json::to_value(&src).unwrap();
14199 let obj = json.as_object().expect("Path serializes as a JSON object");
14200 assert_eq!(
14201 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14202 .and_then(serde_json::Value::as_str),
14203 Some(crate::render::DEP_SOURCE_TIPO_PATH),
14204 "DepSource::Path must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14205 with value DEP_SOURCE_TIPO_PATH — attribute drift or variant rename \
14206 detected in {json}"
14207 );
14208 }
14209
14210 #[test]
14211 fn dep_source_key_consts_are_pairwise_distinct() {
14212 // Cross-axis collapse detector: a hypothetical future edit that
14213 // accidentally set two of the three consts to the same byte
14214 // (`DEP_SOURCE_TIPO_GIT = "path"` typo matching a peer arm) would
14215 // pass every per-arm serialize pin above but silently collapse
14216 // the discriminator's closed-set arms onto one another; this pin
14217 // catches the collapse at build time.
14218 assert_ne!(
14219 crate::render::DEP_SOURCE_KEY_TIPO,
14220 crate::render::DEP_SOURCE_TIPO_GIT,
14221 );
14222 assert_ne!(
14223 crate::render::DEP_SOURCE_KEY_TIPO,
14224 crate::render::DEP_SOURCE_TIPO_PATH,
14225 );
14226 assert_ne!(
14227 crate::render::DEP_SOURCE_TIPO_GIT,
14228 crate::render::DEP_SOURCE_TIPO_PATH,
14229 );
14230 }
14231
14232 #[test]
14233 fn dep_source_tipo_variant_consts_are_ascii_lowercase_shape() {
14234 // Shape pin against `rename_all` drift: the two variant-tag
14235 // consts must be ASCII-lowercase-only to match the
14236 // `rename_all = "lowercase"` attribute the derive uses; a future
14237 // rebrand to `"UPPERCASE"` / `"PascalCase"` at the attribute
14238 // would emit `"GIT"` / `"Git"` instead and trip this pin.
14239 for (label, s) in [
14240 ("DEP_SOURCE_TIPO_GIT", crate::render::DEP_SOURCE_TIPO_GIT),
14241 ("DEP_SOURCE_TIPO_PATH", crate::render::DEP_SOURCE_TIPO_PATH),
14242 ] {
14243 assert!(!s.is_empty(), "{label} must not be empty");
14244 assert!(
14245 s.bytes().all(|b| b.is_ascii_lowercase()),
14246 "{label} must be ASCII-lowercase-only (matching \
14247 rename_all = \"lowercase\"), got {s:?}",
14248 );
14249 }
14250 }
14251
14252 // ── per-entry :caracteristicas set-not-multiset gate ────────────
14253 //
14254 // Every Vec-keyed-by-name authoring surface on the typed Caixa
14255 // surface that identifies its entries by a name field now uniformly
14256 // closes the set-not-multiset discipline at build time (cite
14257 // `validate_caracteristicas`'s peer-axis enumeration). The
14258 // `:caracteristicas` axis is per-`Dep`: the feature-toggle slot is
14259 // set-shaped (a feature is either enabled or not — there is no
14260 // `feature × 2` semantic), so two entries naming the same feature
14261 // are a redundant declaration the caixa-resolver's lacre pipeline
14262 // would silently dedup at resolve time. The empty-feature arm
14263 // closes the parallel "operationally-meaningless value" axis on
14264 // the same slot. Same linear-walk + `HashSet` + first-collision
14265 // shape every peer set gate uses; same empty-first cascade every
14266 // peer per-entry shape + duplicate gate uses (the empty-feature
14267 // axis is the more-actionable defect since two `""` entries would
14268 // both report `caracteristica: ""` under a duplicate-first
14269 // ordering, with no way to distinguish the offending site).
14270
14271 fn dep_with_features(features: &[&str]) -> Dep {
14272 Dep {
14273 nome: "caixa-teia".into(),
14274 versao: "^0.1".into(),
14275 fonte: None,
14276 opcional: false,
14277 caracteristicas: features.iter().map(|s| (*s).into()).collect(),
14278 }
14279 }
14280
14281 #[test]
14282 fn validate_rejects_empty_caracteristica() {
14283 // Fail-before-pass-after pin: every pre-gate codebase accepted
14284 // `(:caracteristicas (""))` cleanly (the `Vec<String>` field
14285 // imposed no per-entry shape contract), the dep validated, and
14286 // the empty feature would have reached the future caixa-resolver
14287 // lacre pipeline as a no-op feature enable — silently dropping
14288 // the author's intent far from the source `caixa.lisp`. The new
14289 // gate surfaces the structural defect at the typed-validate
14290 // surface with a self-locating diagnostic naming the offending
14291 // dep's `:nome`.
14292 let d = dep_with_features(&[""]);
14293 assert!(
14294 matches!(d.validate().unwrap_err(), DepError::CaracteristicaEmpty { ref nome } if nome == "caixa-teia"),
14295 "expected CaracteristicaEmpty, got {:?}",
14296 d.validate(),
14297 );
14298 }
14299
14300 #[test]
14301 fn validate_rejects_duplicate_caracteristica() {
14302 // Fail-before-pass-after pin on the set-not-multiset arm: the
14303 // feature-toggle slot is set-shaped, so `(:caracteristicas
14304 // ("http" "http"))` is a redundant declaration the lacre
14305 // pipeline dedupes silently at resolve time. The diagnostic
14306 // names the offending dep + the colliding feature verbatim so
14307 // the author can grep their caixa.lisp for `:caracteristicas`
14308 // and fix it in one edit. First-collision determinism is
14309 // pinned separately below.
14310 let d = dep_with_features(&["http", "http"]);
14311 assert!(
14312 matches!(
14313 d.validate().unwrap_err(),
14314 DepError::CaracteristicaDuplicate { ref nome, ref caracteristica }
14315 if nome == "caixa-teia" && caracteristica == "http"
14316 ),
14317 "expected CaracteristicaDuplicate, got {:?}",
14318 d.validate(),
14319 );
14320 }
14321
14322 #[test]
14323 fn validate_accepts_distinct_caracteristicas() {
14324 // The canonical authoring shape — every feature distinct — must
14325 // remain a clean pass (positive control sweep). Covers the
14326 // canonical kebab-case feature names a target caixa typically
14327 // declares.
14328 dep_with_features(&["http", "json", "tls"])
14329 .validate()
14330 .unwrap();
14331 }
14332
14333 #[test]
14334 fn validate_accepts_single_caracteristica() {
14335 // Single-element list is the minimum non-empty shape; passes
14336 // the gate as the identity of the duplicate check (no second
14337 // entry to collide with).
14338 dep_with_features(&["http"]).validate().unwrap();
14339 }
14340
14341 #[test]
14342 fn validate_accepts_empty_caracteristicas_list() {
14343 // The bare-dep authoring shape (`Dep::simple` / `Dep::git`)
14344 // produces `caracteristicas: Vec::new()`; the empty list is
14345 // the gate's empty-set identity and passes vacuously. Pin
14346 // this so a future tightening that requires ≥1 feature
14347 // surfaces here as a test failure rather than a silent
14348 // contract narrowing.
14349 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14350 assert!(dep_with_features(&[]).validate().is_ok());
14351 }
14352
14353 #[test]
14354 fn validate_caracteristica_empty_fires_before_duplicate() {
14355 // Empty-first cascade: an entry with an empty feature *and*
14356 // duplicate entries surfaces the empty diagnostic first. The
14357 // empty-feature axis is the more-actionable defect since
14358 // `caracteristica: ""` is unambiguous; under duplicate-first
14359 // ordering the diagnostic could report the empty string from
14360 // either of two empty entries with no way to distinguish.
14361 // Mirrors the peer empty-before-duplicate ordering
14362 // discipline every per-entry shape + duplicate gate establishes
14363 // (`SupervisorSpec::validate`'s `EmptyChildName` arm before
14364 // `DuplicateChildCaixa`, `validate_membros`'s
14365 // `MembroCaixaEmpty` arm before `MembroDuplicate`).
14366 let d = dep_with_features(&["", "http", "http"]);
14367 assert!(matches!(
14368 d.validate().unwrap_err(),
14369 DepError::CaracteristicaEmpty { .. }
14370 ));
14371 }
14372
14373 #[test]
14374 fn validate_caracteristica_duplicate_first_collision_determinism() {
14375 // Three matching entries: the second occurrence surfaces the
14376 // diagnostic (the second is the first *collision* — the first
14377 // entry is the establishing one, not a duplicate). Mirrors
14378 // every peer first-collision posture
14379 // (`SupervisorError::DuplicateChildCaixa` reports the second
14380 // collision, `AplicacaoError::MembroDuplicate` reports the
14381 // second, `DepError::DuplicateNome` reports the second).
14382 // Pinning this so a future shortcut that flips to last-
14383 // collision (or non-deterministic) surfaces here.
14384 let d = dep_with_features(&["http", "http", "http"]);
14385 assert!(matches!(
14386 d.validate().unwrap_err(),
14387 DepError::CaracteristicaDuplicate { ref caracteristica, .. } if caracteristica == "http"
14388 ));
14389 }
14390
14391 #[test]
14392 fn validate_per_entry_shape_fires_before_caracteristicas() {
14393 // Per-entry shape precedence: a dep with a malformed `:nome`
14394 // (uppercase) AND duplicate `:caracteristicas` surfaces the
14395 // narrower `NomeInvalid` diagnostic first, not the set-gate
14396 // diagnostic. The `:nome` is the self-locating axis (every
14397 // diagnostic from the caracteristicas gate quotes the
14398 // offending dep's `:nome` to anchor the grep target —
14399 // surfacing the malformed name first keeps that anchor
14400 // valid). Same precedence shape every peer per-entry-shape
14401 // arm establishes against its peer set-gate
14402 // (`validate_deps_per_entry_validate_fires_before_duplicate_in_deps`
14403 // on the cross-entry `:nome` axis).
14404 let d = Dep {
14405 nome: "Caixa-Teia".into(), // uppercase — DNS-1123 violation
14406 versao: "^0.1".into(),
14407 fonte: None,
14408 opcional: false,
14409 caracteristicas: vec!["http".into(), "http".into()],
14410 };
14411 assert!(matches!(
14412 d.validate().unwrap_err(),
14413 DepError::NomeInvalid { .. }
14414 ));
14415 }
14416
14417 // ── per-entry :caracteristicas value-shape gate ──────────────────
14418 //
14419 // Until this gate landed `:caracteristicas` only refused the empty
14420 // string and cross-entry duplicates: a non-empty distinct but
14421 // structurally invalid feature name silently passed validate and the
14422 // failure surfaced at `cargo metadata` time as Cargo's
14423 // `restricted_names::validate_feature_name` parser rejection, far from
14424 // the source `caixa.lisp` with no field naming which `:deps` entry's
14425 // `:caracteristicas` carried the typo. The lifted predicate makes the
14426 // Cargo-feature-name-grammar intersection-floor a substrate-level
14427 // invariant at validate time. Same trajectory as the eight peer
14428 // value-shape predicates each typed surface downstream of a structured
14429 // grammar already follows.
14430
14431 #[test]
14432 fn validate_rejects_caracteristica_with_leading_plus() {
14433 // Fail-before-pass-after pin on the canonical Cargo
14434 // `+<feature>` activation-form-in-feature-name-slot footgun.
14435 // Cargo's `[dependencies.<dep>.features]` list grammar accepts
14436 // `+optional-feature` as an enablement of a previously-disabled
14437 // feature; pasting that activation form into `:caracteristicas`
14438 // (which names the feature itself) silently passed pre-gate and
14439 // failed at `cargo metadata` parse time.
14440 let d = dep_with_features(&["+http"]);
14441 let err = d.validate().unwrap_err();
14442 assert!(
14443 matches!(
14444 err,
14445 DepError::CaracteristicaInvalid { ref nome, ref caracteristica, .. }
14446 if nome == "caixa-teia" && caracteristica == "+http"
14447 ),
14448 "expected CaracteristicaInvalid, got {err:?}"
14449 );
14450 }
14451
14452 #[test]
14453 fn validate_rejects_caracteristica_with_leading_hyphen() {
14454 // Fail-before-pass-after pin on the leading-hyphen footgun. `-`
14455 // is a legitimate continuation character (kebab-case feature
14456 // names like `runtime-tokio` pass) but Cargo rejects it at the
14457 // start; the structural defect — and its CLI-argument-injection
14458 // adjacency at any downstream Cargo subprocess invocation — is
14459 // closed at validate time, not at `cargo metadata` time.
14460 let d = dep_with_features(&["-json"]);
14461 let err = d.validate().unwrap_err();
14462 assert!(
14463 matches!(
14464 err,
14465 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "-json"
14466 ),
14467 "expected CaracteristicaInvalid, got {err:?}"
14468 );
14469 }
14470
14471 #[test]
14472 fn validate_rejects_caracteristica_with_leading_dot() {
14473 // Fail-before-pass-after pin on the leading-dot footgun. `.` is
14474 // a legitimate continuation character (version-suffix shapes
14475 // like `feat.v2` pass) but the leading-dot form is the
14476 // canonical dotted-version-suffix-as-feature-name confusion.
14477 let d = dep_with_features(&[".feat"]);
14478 let err = d.validate().unwrap_err();
14479 assert!(matches!(
14480 err,
14481 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == ".feat"
14482 ));
14483 }
14484
14485 #[test]
14486 fn validate_rejects_caracteristica_with_whitespace() {
14487 // Fail-before-pass-after pin on the embedded-whitespace footgun:
14488 // a feature name with a space inside is structurally a multi-
14489 // token blob (the canonical paste-from-doc footgun, or an
14490 // accidental `"http server"` where the author meant
14491 // `"http-server"`).
14492 let d = dep_with_features(&["http feature"]);
14493 let err = d.validate().unwrap_err();
14494 assert!(matches!(
14495 err,
14496 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http feature"
14497 ));
14498 }
14499
14500 #[test]
14501 fn validate_rejects_caracteristica_with_comma() {
14502 // Fail-before-pass-after pin on the embedded-comma footgun:
14503 // the list-separator-belongs-to-the-list-grammar
14504 // miscomprehension where the author writes
14505 // `:caracteristicas ("http,json")` intending two features but
14506 // the `Vec<String>` field consumes the bare token as one entry.
14507 let d = dep_with_features(&["http,json"]);
14508 let err = d.validate().unwrap_err();
14509 assert!(matches!(
14510 err,
14511 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http,json"
14512 ));
14513 }
14514
14515 #[test]
14516 fn validate_rejects_caracteristica_with_slash() {
14517 // Fail-before-pass-after pin on the embedded-slash footgun:
14518 // Cargo's `dep/feat` namespaced-dep syntax applies inside
14519 // `[dependencies.<dep>.features]` list entries that already
14520 // name the parent dep (so the syntax says "enable feature
14521 // `feat` on a transitive dep `dep`"); `:caracteristicas` is
14522 // per-dep already (a sibling slot on the `Dep` itself), so the
14523 // segment separator within an entry must be `-`, `_`, `+`,
14524 // or `.`. The diagnostic remediation points at the canonical
14525 // Cargo namespaced-dep discipline.
14526 let d = dep_with_features(&["http/json"]);
14527 let err = d.validate().unwrap_err();
14528 assert!(matches!(
14529 err,
14530 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http/json"
14531 ));
14532 }
14533
14534 #[test]
14535 fn validate_rejects_caracteristica_with_non_ascii() {
14536 // Fail-before-pass-after pin on the un-percent-encoded non-ASCII
14537 // byte footgun: NFC-vs-NFD normalization across filesystems
14538 // silently rewrites the feature-key, breaking the lacre's
14539 // content-addressing invariant. Pinned at a canonical
14540 // smart-quote-paste shape (`café`) where the raw `é` byte is the
14541 // documented APFS round-trip break.
14542 let d = dep_with_features(&["caf\u{e9}"]);
14543 let err = d.validate().unwrap_err();
14544 assert!(matches!(
14545 err,
14546 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "caf\u{e9}"
14547 ));
14548 }
14549
14550 #[test]
14551 fn validate_rejects_caracteristica_with_control_character() {
14552 // Fail-before-pass-after pin on the embedded-control-character
14553 // footgun: a CR/LF or any 0x00..0x1F / 0x7F byte landing in a
14554 // feature name is the canonical paste-from-multiline-doc
14555 // footgun the predicate's reason wording specifically calls out.
14556 let d = dep_with_features(&["http\njson"]);
14557 let err = d.validate().unwrap_err();
14558 assert!(matches!(err, DepError::CaracteristicaInvalid { .. }));
14559 }
14560
14561 #[test]
14562 fn validate_accepts_canonical_caracteristicas_shapes() {
14563 // Positive control sweep: every canonical Cargo feature name
14564 // shape the pleme-io ecosystem uses must still pass. Mirrors
14565 // the substrate-side `cargo_feature_name_accepts_canonical_forms`
14566 // sweep — drift between either landing site and the predicate's
14567 // accepted set is a build error visible at this pair of tests,
14568 // not a per-renderer "this passed validate but failed at
14569 // cargo metadata time" surprise on the next acceptance.
14570 for s in [
14571 "http",
14572 "json",
14573 "derive",
14574 "serde_json",
14575 "runtime-tokio",
14576 "tokio.full",
14577 "v0.1",
14578 "http+json",
14579 "_internal",
14580 "__private",
14581 "default",
14582 "rt-multi-thread",
14583 "feat.v2",
14584 ] {
14585 let d = dep_with_features(&[s]);
14586 d.validate().unwrap_or_else(|e| {
14587 panic!("canonical Cargo feature name {s:?} must pass validate: {e:?}")
14588 });
14589 }
14590 }
14591
14592 #[test]
14593 fn validate_caracteristica_empty_fires_before_invalid() {
14594 // Cascade precedence pin: an entry list with both an empty
14595 // feature AND an invalid-shape feature surfaces the
14596 // `CaracteristicaEmpty` arm first (the empty value carries no
14597 // self-locating data — `caracteristica: ""` is the diagnostic
14598 // with no way to anchor a grep target — so closing the empty
14599 // axis first preserves the per-entry-shape diagnostic's
14600 // self-locating discipline). Same empty-first cascade every
14601 // peer per-entry shape gate establishes
14602 // (`SupervisorSpec::validate`'s `EmptyChildName` before
14603 // `ChildCaixaInvalid`, `validate_membros`'s `MembroCaixaEmpty`
14604 // before `MembroCaixaInvalid`).
14605 let d = dep_with_features(&["", "+http"]);
14606 assert!(matches!(
14607 d.validate().unwrap_err(),
14608 DepError::CaracteristicaEmpty { .. }
14609 ));
14610 }
14611
14612 #[test]
14613 fn validate_caracteristica_invalid_fires_before_duplicate() {
14614 // Per-entry-shape precedence pin: an entry list with the same
14615 // invalid feature shape declared twice surfaces the
14616 // `CaracteristicaInvalid` diagnostic on the first entry, not
14617 // the `CaracteristicaDuplicate` on the second collision. The
14618 // per-entry shape gate fires before the cross-entry set gate
14619 // — same precedence shape every peer two-arm-plus-set gate
14620 // establishes (`SupervisorSpec::validate`'s
14621 // `ChildCaixaInvalid` before `DuplicateChildCaixa`,
14622 // `validate_membros`'s `MembroCaixaInvalid` before
14623 // `MembroDuplicate`, `Dep::validate`'s `NomeInvalid` before
14624 // cross-list `DuplicateNome`).
14625 let d = dep_with_features(&["+http", "+http"]);
14626 assert!(matches!(
14627 d.validate().unwrap_err(),
14628 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "+http"
14629 ));
14630 }
14631
14632 #[test]
14633 fn validate_rejects_caracteristica_at_65_byte_boundary() {
14634 // Boundary pin on the 64-byte cap — both the boundary-accepting
14635 // case and the boundary-exceeding case in one place, so a
14636 // future cap shift surfaces both arms simultaneously, mirroring
14637 // the peer `cargo_feature_name_rejects_at_65_byte_boundary`
14638 // predicate-level pin at the dep-axis landing site.
14639 let max_ok = "a".repeat(64);
14640 dep_with_features(&[&max_ok])
14641 .validate()
14642 .unwrap_or_else(|e| panic!("64-byte feature name must pass: {e:?}"));
14643 let too_long = "a".repeat(65);
14644 let d = dep_with_features(&[&too_long]);
14645 assert!(matches!(
14646 d.validate().unwrap_err(),
14647 DepError::CaracteristicaInvalid { .. }
14648 ));
14649 }
14650
14651 // ── self-dep cross-slot gate ─────────────────────────────────────
14652
14653 #[test]
14654 fn validate_no_self_dep_rejects_self_in_deps() {
14655 // A caixa whose `:deps` lists its own `:nome` is a one-node
14656 // cycle in the lacre closure's dep-graph traversal — rejected,
14657 // naming the parent and the offending list tag.
14658 let deps = vec![
14659 Dep::simple("caixa-teia", "^0.1"),
14660 Dep::simple("orquestra", "^0.1"),
14661 ];
14662 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
14663 assert!(
14664 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14665 "got {err:?}"
14666 );
14667 }
14668
14669 #[test]
14670 fn validate_no_self_dep_rejects_self_in_deps_dev() {
14671 // Same gate on the `:deps-dev` axis — neither dep list is a
14672 // second-class citizen on the self-edge invariant.
14673 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14674 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
14675 assert!(
14676 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14677 "got {err:?}"
14678 );
14679 }
14680
14681 #[test]
14682 fn validate_no_self_dep_deps_fires_before_deps_dev() {
14683 // Walk order pin: a caixa that self-references on both lists
14684 // surfaces the `:deps` arm first — the load-bearing axis the
14685 // lacre closure resolves at every build. Mirrors the canonical
14686 // [`Caixa::validate_deps`] cascade (`:deps` → `:deps-dev`).
14687 let deps = vec![Dep::simple("orquestra", "^0.1")];
14688 let deps_dev = vec![Dep::simple("orquestra", "^0.2")];
14689 let err = validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap_err();
14690 assert!(
14691 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14692 "got {err:?}"
14693 );
14694 }
14695
14696 #[test]
14697 fn validate_no_self_dep_accepts_distinct_names() {
14698 // Positive control: every dep names a distinct caixa. The
14699 // canonical author surface — peer of
14700 // [`validate_no_self_supervision_accepts_distinct_children`].
14701 let deps = vec![
14702 Dep::simple("caixa-teia", "^0.1"),
14703 Dep::simple("caixa-arch", "^0.1"),
14704 ];
14705 let deps_dev = vec![Dep::simple("caixa-test", "^0.1")];
14706 validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap();
14707 }
14708
14709 #[test]
14710 fn validate_no_self_dep_empty_lists_pass() {
14711 // A caixa with no declared deps has nothing to self-reference —
14712 // the gate is vacuously satisfied. Peer of
14713 // [`validate_no_self_supervision_empty_children_is_ok`].
14714 validate_no_self_dep(&[], &[], "orquestra").unwrap();
14715 }
14716
14717 #[test]
14718 fn validate_no_self_dep_diagnostic_carries_offending_list_and_nome() {
14719 // Diagnostic-shape pin (peer with
14720 // [`validate_no_self_supervision`]'s diagnostic): the error's
14721 // Display surfaces both the offending list tag and the
14722 // parent's `:nome` verbatim, so the author can grep their
14723 // caixa.lisp for the offending block in one edit. Names
14724 // `:bibliotecas` / `:exe` / `:servicos` as the corrective
14725 // surface — every legitimate "I want to use code from this
14726 // caixa" intent routes through one of those three slots.
14727 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14728 let rendered = validate_no_self_dep(&[], &deps_dev, "orquestra")
14729 .unwrap_err()
14730 .to_string();
14731 assert!(
14732 rendered.contains(crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14733 "diagnostic must name the offending list tag: {rendered}",
14734 );
14735 assert!(
14736 rendered.contains("orquestra"),
14737 "diagnostic must quote the parent caixa name: {rendered}",
14738 );
14739 assert!(
14740 rendered.contains(":bibliotecas"),
14741 "diagnostic must point at the corrective code-surface slot: {rendered}",
14742 );
14743 }
14744
14745 #[test]
14746 fn validate_no_self_dep_accepts_coincidental_substring_match() {
14747 // Identity is exact-string equality, not substring — a dep
14748 // named `"orquestra-helper"` is a distinct caixa even when the
14749 // parent is `"orquestra"`. Pin the exact-match discipline so a
14750 // future relaxation that uses `contains` surfaces here, peer
14751 // with the supervision-tree and Aplicacao-membership gates
14752 // which all use exact-string equality on the typed identity.
14753 let deps = vec![Dep::simple("orquestra-helper", "^0.1")];
14754 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
14755 }
14756
14757 // ── drift-detection: DEP_AUTHOR_KEY_{DEPS,DEPS_DEV} pin ─────────────
14758
14759 #[test]
14760 fn dep_author_key_consts_pin_canonical_kebab_case_labels() {
14761 // Scalar-value pin: the two author-facing kebab-case labels the
14762 // `(defcaixa … :deps ((…)) :deps-dev ((…)))` surface admits on
14763 // the two-list dep-graph slot axis, one arm per typed slot.
14764 // Mirrors the peer scalar-value pin the sibling
14765 // [`crate::M2_AUTHOR_KEY_LIMITS`] /
14766 // [`crate::M2_AUTHOR_KEY_BEHAVIOR`] /
14767 // [`crate::M2_AUTHOR_KEY_UPGRADE_FROM`] (f49c8b0) M2 top-level
14768 // author-labels, [`crate::M3_AUTHOR_KEY_MEMBROS`] etc.
14769 // (882f498) M3 top-level author-labels, and
14770 // [`crate::SUPERVISOR_AUTHOR_KEY_ESTRATEGIA`] etc. (be40492)
14771 // Supervisor top-level author-labels carry, so every kind-scoped
14772 // typed-slot-family axis routes through one canonical per-arm
14773 // declaration.
14774 //
14775 // A future rebrand (`:deps` → `:dependencies` matching Cargo's
14776 // verbatim key, `:deps-dev` → `:dev-dependencies` matching the
14777 // same, `:deps` / `:deps-dev` → `:runtime-deps` / `:dev-deps`
14778 // for symmetry) lands as an edit to exactly one const, and
14779 // every consumer that reaches for the label picks it up at
14780 // build time rather than at runtime as a downstream mismatch on
14781 // a `DepError::DuplicateNome { list: … }` diagnostic far from
14782 // the rename's commit.
14783 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS, ":deps");
14784 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS_DEV, ":deps-dev");
14785 }
14786
14787 #[test]
14788 fn dep_author_key_consts_are_pairwise_distinct() {
14789 // Distinct-labels pin: the two `:deps` / `:deps-dev` labels
14790 // must not collapse onto one byte-string. A future copy-paste
14791 // slip that renamed both consts to the same value (or a rebrand
14792 // that dropped the `-dev` suffix from one but not the other)
14793 // would leave every `DepError::DuplicateNome { list: … }`
14794 // diagnostic naming an unattributable list — the linter would
14795 // route the author to the wrong caixa.lisp block, or the
14796 // cross-list precedence gate
14797 // (`validate_deps_duplicate_in_deps_fires_before_duplicate_in_deps_dev`)
14798 // would surface a `:deps`-tagged diagnostic on a `:deps-dev`
14799 // duplicate. Peer of the sibling
14800 // `m2_author_key_consts_are_pairwise_distinct`-shape gates the
14801 // other top-level kind-scoped slot-family axes carry
14802 // (implicitly held by their different byte-values today).
14803 assert_ne!(
14804 crate::render::DEP_AUTHOR_KEY_DEPS,
14805 crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
14806 "DEP_AUTHOR_KEY_{{DEPS,DEPS_DEV}} consts must be pairwise-distinct \
14807 so a `DepError::DuplicateNome {{ list: … }}` diagnostic \
14808 self-locates the offending block in the author's caixa.lisp",
14809 );
14810 }
14811
14812 #[test]
14813 fn validate_no_self_dep_routes_through_lifted_dep_author_key_consts() {
14814 // Production-through-const pin: the two per-arm list tags
14815 // [`validate_no_self_dep`] threads onto the `list:` field of a
14816 // returned [`DepError::DepIsSelf`] route through the lifted
14817 // [`crate::DEP_AUTHOR_KEY_DEPS`] /
14818 // [`crate::DEP_AUTHOR_KEY_DEPS_DEV`] consts. A future drift at
14819 // the walker (a rename that reaches one arm but not the const,
14820 // or vice versa) surfaces here at build time rather than at
14821 // runtime as a `feira lint` diagnostic naming the wrong list
14822 // tag. Mirror of the peer
14823 // [`crate::Caixa::declared_servico_slots`] production tagger
14824 // pin (f49c8b0) on the sibling M2 top-level slot axis, extended
14825 // onto the two-list dep-graph gate.
14826 let deps = vec![Dep::simple("orquestra", "^0.1")];
14827 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
14828 let DepError::DepIsSelf { list, .. } = err else {
14829 panic!("expected DepIsSelf from :deps walk");
14830 };
14831 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS);
14832
14833 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14834 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
14835 let DepError::DepIsSelf { list, .. } = err else {
14836 panic!("expected DepIsSelf from :deps-dev walk");
14837 };
14838 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS_DEV);
14839 }
14840
14841 // ── Dep::nome accessor pins ───────────────────────────────────────
14842 //
14843 // Three coherence pins on the lifted `Dep::nome` accessor: byte-equal
14844 // projection over the plain-shorthand / explicit-git / explicit-path
14845 // fixture triad the [`Dep`] docstring lists (so the accessor's
14846 // accept-set is exercised across every author-surface `:fonte`
14847 // shape); by-borrow pointer identity so the projection stays
14848 // zero-copy at every consumer site; and validate-composition through
14849 // the [`validate_no_self_dep`] cross-slot gate reading its
14850 // parent-name equality check through the lifted accessor rather than
14851 // the raw field.
14852
14853 #[test]
14854 fn dep_nome_returns_declared_nome_across_fonte_shapes() {
14855 // Plain-shorthand form (`:fonte None`).
14856 assert_eq!(Dep::simple("caixa-teia", "^0.1").nome(), "caixa-teia");
14857 // Explicit git-source form with a tag pin — same accessor path.
14858 assert_eq!(
14859 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").nome(),
14860 "caixa-teia",
14861 );
14862 // Explicit path-source form.
14863 assert_eq!(
14864 Dep {
14865 nome: "caixa-teia".to_string(),
14866 versao: "0.1.0".to_string(),
14867 fonte: Some(DepSource::Path {
14868 caminho: "../caixa-teia".to_string(),
14869 }),
14870 opcional: false,
14871 caracteristicas: Vec::new(),
14872 }
14873 .nome(),
14874 "caixa-teia",
14875 );
14876 // The empty-string `:nome` sentinel (which [`Dep::validate`]
14877 // refuses through the [`DepError::NomeEmpty`] arm) still round-
14878 // trips as an empty `&str` through the accessor — the accessor is
14879 // a projection, not a gate; the gate is [`Dep::validate`].
14880 assert_eq!(Dep::simple("", "^0.1").nome(), "");
14881 }
14882
14883 #[test]
14884 fn dep_nome_is_by_borrow_pointer_identity() {
14885 // Zero-copy pin: the accessor must borrow into the field's own
14886 // storage, not clone. If a future rewrite regresses to
14887 // `self.nome.clone().leak()` or an owned-buffer shape, the two
14888 // pointers diverge and this pin fails at build time.
14889 let d = Dep::simple("caixa-teia", "^0.1");
14890 assert!(std::ptr::eq(d.nome().as_ptr(), d.nome.as_ptr()));
14891 }
14892
14893 // ── Dep::versao_requirement accessor pins ─────────────────────────
14894 //
14895 // Three coherence pins on the lifted `Dep::versao_requirement`
14896 // accessor: byte-equal projection over the plain-shorthand /
14897 // explicit-git / explicit-path fixture triad the [`Dep`] docstring
14898 // lists plus the empty-sentinel that round-trips as `""` (the accessor
14899 // is a projection, not a gate; the gate is [`Dep::validate`]); by-
14900 // borrow pointer identity so the projection stays zero-copy at every
14901 // consumer site; and validate-composition through the
14902 // [`crate::render::require_valid_versao_requirement`] cascade reading
14903 // its requirement-shape check through the lifted accessor rather than
14904 // the raw field.
14905 #[test]
14906 fn dep_versao_requirement_returns_declared_versao_across_fonte_shapes() {
14907 // Plain-shorthand form (`:fonte None`).
14908 assert_eq!(
14909 Dep::simple("caixa-teia", "^0.1").versao_requirement(),
14910 "^0.1",
14911 );
14912 // Explicit git-source form with a tag pin — same accessor path.
14913 assert_eq!(
14914 Dep::git(
14915 "caixa-teia",
14916 "~0.1.2",
14917 "github:pleme-io/caixa-teia",
14918 "v0.1.0"
14919 )
14920 .versao_requirement(),
14921 "~0.1.2",
14922 );
14923 // Explicit path-source form.
14924 assert_eq!(
14925 Dep {
14926 nome: "caixa-teia".to_string(),
14927 versao: "0.1.0".to_string(),
14928 fonte: Some(DepSource::Path {
14929 caminho: "../caixa-teia".to_string(),
14930 }),
14931 opcional: false,
14932 caracteristicas: Vec::new(),
14933 }
14934 .versao_requirement(),
14935 "0.1.0",
14936 );
14937 // The wildcard requirement (`"*"`) — the shorthand
14938 // `parse_requirement` accepts as `VersionReq::STAR` — round-trips
14939 // verbatim through the accessor as `"*"`, same byte-shape the
14940 // author wrote.
14941 assert_eq!(Dep::simple("caixa-teia", "*").versao_requirement(), "*");
14942 // The empty-string `:versao` sentinel (which [`Dep::validate`]
14943 // refuses through the [`DepError::VersaoEmpty`] arm) still round-
14944 // trips as an empty `&str` through the accessor — the accessor is
14945 // a projection, not a gate; the gate is [`Dep::validate`]. Peer
14946 // of the sibling [`Dep::nome`] empty-sentinel round-trip pin.
14947 assert_eq!(Dep::simple("caixa-teia", "").versao_requirement(), "");
14948 }
14949
14950 #[test]
14951 fn dep_versao_requirement_is_by_borrow_pointer_identity() {
14952 // Zero-copy pin: the accessor must borrow into the field's own
14953 // storage, not clone. If a future rewrite regresses to
14954 // `self.versao.clone().leak()` or an owned-buffer shape, the two
14955 // pointers diverge and this pin fails at build time. Peer of the
14956 // sibling [`Dep::nome`] pointer-identity pin — same by-borrow
14957 // discipline extended onto the requirement-carrying axis.
14958 let d = Dep::simple("caixa-teia", "^0.1");
14959 assert!(std::ptr::eq(
14960 d.versao_requirement().as_ptr(),
14961 d.versao.as_ptr(),
14962 ));
14963 }
14964
14965 #[test]
14966 fn dep_validate_reads_requirement_through_accessor() {
14967 // Composition pin: the [`Dep::validate`]
14968 // [`crate::render::require_valid_versao_requirement`] cascade
14969 // consumes the requirement string through the lifted accessor —
14970 // both the requirement-gate input and the
14971 // [`DepError::VersaoInvalid`] error-body carrier route through
14972 // `self.versao_requirement()`. A valid requirement passes
14973 // (positive control); a malformed-but-non-empty requirement fails
14974 // and the diagnostic quotes the offending byte-string verbatim
14975 // (same shape the accessor projects), so a future regression that
14976 // detoured the requirement carrier through a different byte-
14977 // string (say the parsed `VersionReq`'s `Display`, or a
14978 // normalized rewrite) would surface here at build time. The
14979 // empty-`:versao` arm fires the [`DepError::VersaoEmpty`] variant
14980 // ahead of the parse arm, pinning the empty-first cascade the
14981 // accessor's `""` sentinel round-trip acknowledges.
14982 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14983 let err = Dep::simple("caixa-teia", "v0.1").validate().unwrap_err();
14984 assert!(
14985 matches!(
14986 &err,
14987 DepError::VersaoInvalid {
14988 nome,
14989 versao,
14990 ..
14991 } if nome == "caixa-teia" && versao == "v0.1",
14992 ),
14993 "expected VersaoInvalid quoting the accessor-projected requirement, got {err:?}",
14994 );
14995 let err = Dep::simple("caixa-teia", "").validate().unwrap_err();
14996 assert!(
14997 matches!(
14998 &err,
14999 DepError::VersaoEmpty { nome } if nome == "caixa-teia",
15000 ),
15001 "expected VersaoEmpty from the empty-first arm, got {err:?}",
15002 );
15003 }
15004
15005 // ── Dep::fonte accessor pins ──────────────────────────────────────
15006 //
15007 // Three coherence pins on the lifted `Dep::fonte` accessor: byte-
15008 // equal projection over the plain-shorthand (`:fonte None`) /
15009 // explicit-git-tag / explicit-path fixture triad the [`Dep`]
15010 // docstring lists (so the accessor's accept-set is exercised across
15011 // every author-surface `:fonte` shape and both `DepSource` variants);
15012 // pointer identity so the borrowed reference points into the field's
15013 // own `Option<DepSource>` storage (not a cloned side-buffer); and
15014 // validate-composition through the [`Dep::validate`] gate reading
15015 // its per-`:fonte` [`DepSource::validate`] delegation through the
15016 // lifted accessor rather than the raw `if let Some(ref fonte) =
15017 // self.fonte` bracket.
15018
15019 #[test]
15020 fn dep_fonte_returns_declared_source_across_shapes() {
15021 // Plain-shorthand form — `:fonte` omitted, accessor projects
15022 // the `None` partition the resolver-side default-fill treats
15023 // as "resolve through `github:<default-org>/<nome>`".
15024 assert!(Dep::simple("caixa-teia", "^0.1").fonte().is_none());
15025 // Explicit git-source form with a tag pin — same accessor path.
15026 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15027 match git.fonte() {
15028 Some(DepSource::Git {
15029 repo,
15030 tag,
15031 rev,
15032 branch,
15033 }) => {
15034 assert_eq!(repo, "github:pleme-io/caixa-teia");
15035 assert_eq!(tag.as_deref(), Some("v0.1.0"));
15036 assert!(rev.is_none());
15037 assert!(branch.is_none());
15038 }
15039 other => panic!("expected explicit git :fonte, got {other:?}"),
15040 }
15041 // Explicit path-source form — the dev-only local-filesystem
15042 // arm the [`Dep`] docstring's third fixture carries.
15043 let path = Dep {
15044 nome: "caixa-teia".to_string(),
15045 versao: "0.1.0".to_string(),
15046 fonte: Some(DepSource::Path {
15047 caminho: "../caixa-teia".to_string(),
15048 }),
15049 opcional: false,
15050 caracteristicas: Vec::new(),
15051 };
15052 match path.fonte() {
15053 Some(DepSource::Path { caminho }) => {
15054 assert_eq!(caminho, "../caixa-teia");
15055 }
15056 other => panic!("expected explicit path :fonte, got {other:?}"),
15057 }
15058 }
15059
15060 #[test]
15061 fn dep_fonte_is_by_borrow_pointer_identity() {
15062 // Zero-copy pin: the accessor must borrow into the field's own
15063 // `Option<DepSource>` storage, not clone into a side buffer. If
15064 // a future rewrite regresses to `self.fonte.clone()` or an
15065 // owned-buffer shape, the two pointers diverge and this pin
15066 // fails at build time. Peer of the sibling per-`Dep` [`Dep::nome`]
15067 // (eba2cde) / [`Dep::versao_requirement`] (05529b1) pointer-
15068 // identity pins — same by-borrow discipline extended onto the
15069 // outer-`Dep` `Option<&Composite>` composite-reference axis.
15070 let d = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15071 let accessed = d.fonte().expect("git :fonte present") as *const DepSource;
15072 let raw = d.fonte.as_ref().expect("git :fonte present") as *const DepSource;
15073 assert!(std::ptr::eq(accessed, raw));
15074 }
15075
15076 #[test]
15077 fn dep_validate_reads_fonte_through_accessor() {
15078 // Composition pin: [`Dep::validate`]'s per-`:fonte`
15079 // [`DepSource::validate`] delegation consumes the typed slot
15080 // through the lifted accessor — an author-omitted `:fonte`
15081 // still passes the outer gate (positive control), an explicit
15082 // well-formed git source with exactly one pin passes, and a
15083 // malformed git source (empty `:repo`) surfaces the
15084 // [`DepError::FonteRepoEmpty`] variant quoting the offending
15085 // dep's `:nome` verbatim so a future regression that detoured
15086 // the `:fonte` delegation through a different path (say a
15087 // per-scope override projector) would surface here at build
15088 // time. Peer of the sibling
15089 // `dep_validate_reads_requirement_through_accessor` composition
15090 // pin on the `:versao` axis.
15091 // Positive control 1: no `:fonte` at all.
15092 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15093 // Positive control 2: well-formed git source.
15094 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15095 .validate()
15096 .unwrap();
15097 // Negative control: empty `:repo` — the accessor still returns
15098 // `Some(&DepSource::Git { repo: "", … })` and the delegated
15099 // `DepSource::validate` gate raises the typed carrier.
15100 let bad = Dep {
15101 nome: "caixa-teia".to_string(),
15102 versao: "^0.1".to_string(),
15103 fonte: Some(DepSource::Git {
15104 repo: String::new(),
15105 tag: Some("v0.1.0".to_string()),
15106 rev: None,
15107 branch: None,
15108 }),
15109 opcional: false,
15110 caracteristicas: Vec::new(),
15111 };
15112 let err = bad.validate().unwrap_err();
15113 assert!(
15114 matches!(
15115 &err,
15116 DepError::FonteRepoEmpty { nome } if nome == "caixa-teia",
15117 ),
15118 "expected FonteRepoEmpty from the accessor-routed :fonte gate, got {err:?}",
15119 );
15120 }
15121
15122 #[test]
15123 fn validate_no_self_dep_reads_parent_equality_through_accessor() {
15124 // Composition pin: the cross-slot [`validate_no_self_dep`] gate
15125 // rejects a `:deps` entry whose `:nome` equals the parent caixa's
15126 // own `:nome` through the lifted accessor rather than the raw
15127 // field. Fails-before-passes-after: with the accessor lifted the
15128 // gate reads its equality check through `dep.nome() ==
15129 // parent_nome` on both the `:deps` and `:deps-dev` traversals, so
15130 // the diagnostic still names the offending list tag as expected.
15131 let deps = vec![Dep::simple("orquestra", "^0.1")];
15132 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15133 assert!(matches!(
15134 err,
15135 DepError::DepIsSelf {
15136 ref nome,
15137 list,
15138 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS,
15139 ));
15140 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15141 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15142 assert!(matches!(
15143 err,
15144 DepError::DepIsSelf {
15145 ref nome,
15146 list,
15147 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15148 ));
15149 // A non-matching `:nome` passes through the accessor gate.
15150 let deps = vec![Dep::simple("caixa-teia", "^0.1")];
15151 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15152 }
15153
15154 // ── Dep::caracteristicas accessor pins ────────────────────────────
15155 //
15156 // Three coherence pins on the lifted `Dep::caracteristicas` accessor:
15157 // byte-equal projection over the default-empty / single-entry /
15158 // multi-entry fixture triad (so the accessor's accept-set is
15159 // exercised across every author-surface `:caracteristicas` shape,
15160 // matching the peer sibling family's fixture-triad discipline); by-
15161 // borrow pointer identity so the projection stays zero-copy at every
15162 // consumer site; and validate-composition through the
15163 // [`Dep::validate_caracteristicas`] gate reading its per-entry
15164 // linear walk through the lifted accessor rather than the raw
15165 // `for c in &self.caracteristicas` bracket.
15166
15167 #[test]
15168 fn dep_caracteristicas_returns_declared_features_across_shapes() {
15169 // Default-empty form — the [`Dep::simple`] constructor's
15170 // `Vec::new()` fill; the accessor projects the empty slice
15171 // verbatim (no `None` collapse).
15172 assert!(
15173 Dep::simple("caixa-teia", "^0.1")
15174 .caracteristicas()
15175 .is_empty(),
15176 );
15177 // Single-entry form — the canonical Cargo-shaped one-feature
15178 // enable ([`crate::render::is_cargo_feature_name`] accepts the
15179 // `"http"` byte-string as a valid feature name).
15180 let one = Dep {
15181 nome: "caixa-teia".to_string(),
15182 versao: "^0.1".to_string(),
15183 fonte: None,
15184 opcional: false,
15185 caracteristicas: vec!["http".to_string()],
15186 };
15187 assert_eq!(one.caracteristicas(), &["http".to_string()]);
15188 // Multi-entry form — the substrate's set-shaped multi-feature
15189 // enable, exercising the accessor over a length-two slice with
15190 // no duplicate collapse.
15191 let two = Dep {
15192 nome: "caixa-teia".to_string(),
15193 versao: "^0.1".to_string(),
15194 fonte: None,
15195 opcional: false,
15196 caracteristicas: vec!["http".to_string(), "json".to_string()],
15197 };
15198 assert_eq!(
15199 two.caracteristicas(),
15200 &["http".to_string(), "json".to_string()],
15201 );
15202 }
15203
15204 #[test]
15205 fn dep_caracteristicas_is_by_borrow_pointer_identity() {
15206 // Zero-copy pin: the accessor must borrow into the field's own
15207 // `Vec<String>` storage, not clone into a side buffer. If a
15208 // future rewrite regresses to `self.caracteristicas.clone()` or
15209 // an owned-buffer shape, the two pointers diverge and this pin
15210 // fails at build time. Peer of the sibling per-`Dep`
15211 // [`Dep::nome`] (eba2cde) / [`Dep::versao_requirement`] (05529b1)
15212 // / [`Dep::fonte`] (d65d1bf) pointer-identity pins — same by-
15213 // borrow discipline extended onto the outer-`Dep` `&[String]`
15214 // slice-projection axis.
15215 let d = Dep {
15216 nome: "caixa-teia".to_string(),
15217 versao: "^0.1".to_string(),
15218 fonte: None,
15219 opcional: false,
15220 caracteristicas: vec!["http".to_string(), "json".to_string()],
15221 };
15222 assert!(std::ptr::eq(
15223 d.caracteristicas().as_ptr(),
15224 d.caracteristicas.as_ptr(),
15225 ));
15226 }
15227
15228 #[test]
15229 fn dep_validate_reads_caracteristicas_through_accessor() {
15230 // Composition pin: [`Dep::validate_caracteristicas`]'s per-entry
15231 // linear walk consumes the feature-toggle list through the
15232 // lifted accessor — a well-formed `:caracteristicas` set passes
15233 // (positive control), an empty-string entry surfaces the
15234 // [`DepError::CaracteristicaEmpty`] variant quoting the offending
15235 // `Dep::nome`, and a within-list duplicate surfaces the
15236 // [`DepError::CaracteristicaDuplicate`] variant so a future
15237 // regression that detoured the walk through a different byte-
15238 // string list (say a per-scope override projector) would surface
15239 // here at build time. Peer of the sibling
15240 // `dep_validate_reads_fonte_through_accessor` /
15241 // `dep_validate_reads_requirement_through_accessor` composition
15242 // pins on the `:fonte` / `:versao` axes.
15243 // Positive control: two distinct well-formed feature names pass.
15244 Dep {
15245 nome: "caixa-teia".to_string(),
15246 versao: "^0.1".to_string(),
15247 fonte: None,
15248 opcional: false,
15249 caracteristicas: vec!["http".to_string(), "json".to_string()],
15250 }
15251 .validate()
15252 .unwrap();
15253 // Negative control 1: empty-string feature-name entry — the
15254 // accessor still returns `&[""]` and the walk raises the typed
15255 // empty-first carrier.
15256 let err = Dep {
15257 nome: "caixa-teia".to_string(),
15258 versao: "^0.1".to_string(),
15259 fonte: None,
15260 opcional: false,
15261 caracteristicas: vec![String::new()],
15262 }
15263 .validate()
15264 .unwrap_err();
15265 assert!(
15266 matches!(
15267 &err,
15268 DepError::CaracteristicaEmpty { nome } if nome == "caixa-teia",
15269 ),
15270 "expected CaracteristicaEmpty from the accessor-routed walk, got {err:?}",
15271 );
15272 // Negative control 2: within-list duplicate — the accessor's
15273 // slice view carries both entries, and the walk's dedup arm
15274 // raises the typed duplicate carrier quoting the offending
15275 // feature name verbatim.
15276 let err = Dep {
15277 nome: "caixa-teia".to_string(),
15278 versao: "^0.1".to_string(),
15279 fonte: None,
15280 opcional: false,
15281 caracteristicas: vec!["http".to_string(), "http".to_string()],
15282 }
15283 .validate()
15284 .unwrap_err();
15285 assert!(
15286 matches!(
15287 &err,
15288 DepError::CaracteristicaDuplicate {
15289 nome,
15290 caracteristica,
15291 } if nome == "caixa-teia" && caracteristica == "http",
15292 ),
15293 "expected CaracteristicaDuplicate from the accessor-routed dedup, got {err:?}",
15294 );
15295 }
15296
15297 // ── Dep::opcional accessor pins ───────────────────────────────────
15298 //
15299 // Two coherence pins on the lifted `Dep::opcional` accessor: byte-
15300 // equal projection over the default-`false` / explicit-`true`
15301 // fixture pair across the plain-shorthand (`:fonte None`) / explicit-
15302 // git-tag / explicit-path fixture triad the [`Dep`] docstring lists,
15303 // exercising the accessor's accept-set over every author-surface
15304 // `:fonte` shape × every author-surface `:opcional` shape; and by-
15305 // `Copy` idempotency so the projection stays value-return (no
15306 // silent detour to a fresh `&bool` borrow that would introduce a
15307 // lifetime on the return type the plain-`Copy`-scalar axis's `bool`
15308 // shape elides). No composition pin — `:opcional` does not
15309 // participate in [`Dep::validate`] (an opcional dep with any bool
15310 // value is validate-accepted; the missing-source arm is a resolver-
15311 // side runtime dispatch, not a build-time refusal), so the axis
15312 // reduces to the value-shape + `Copy` pin pair the peer
15313 // [`crate::Caixa::max_restarts`] / [`crate::Caixa::estrategia`]
15314 // outer-`Option<Copy>` accessor pins already carry.
15315
15316 #[test]
15317 fn dep_opcional_returns_declared_opcional_across_fonte_shapes() {
15318 // Default-`false` form via the [`Dep::simple`] constructor —
15319 // the accessor projects the `false` bit the default-fill sets.
15320 assert!(!Dep::simple("caixa-teia", "^0.1").opcional());
15321 // Default-`false` form via the [`Dep::git`] constructor — same
15322 // default fill; the accessor projects `false` regardless of the
15323 // `:fonte` arm.
15324 assert!(!Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").opcional(),);
15325 // Explicit-`true` form × plain-shorthand `:fonte` — the
15326 // canonical author-surface "this dep may be missing" shape.
15327 let plain_true = Dep {
15328 nome: "caixa-teia".to_string(),
15329 versao: "^0.1".to_string(),
15330 fonte: None,
15331 opcional: true,
15332 caracteristicas: Vec::new(),
15333 };
15334 assert!(plain_true.opcional());
15335 // Explicit-`true` form × explicit git-source — the accessor
15336 // projects the bit verbatim regardless of the `:fonte` arm.
15337 let git_true = Dep {
15338 nome: "caixa-teia".to_string(),
15339 versao: "^0.1".to_string(),
15340 fonte: Some(DepSource::Git {
15341 repo: "github:pleme-io/caixa-teia".to_string(),
15342 tag: Some("v0.1.0".to_string()),
15343 rev: None,
15344 branch: None,
15345 }),
15346 opcional: true,
15347 caracteristicas: Vec::new(),
15348 };
15349 assert!(git_true.opcional());
15350 // Explicit-`true` form × explicit path-source — the dev-only
15351 // local-filesystem arm the [`Dep`] docstring's third fixture
15352 // carries.
15353 let path_true = Dep {
15354 nome: "caixa-teia".to_string(),
15355 versao: "0.1.0".to_string(),
15356 fonte: Some(DepSource::Path {
15357 caminho: "../caixa-teia".to_string(),
15358 }),
15359 opcional: true,
15360 caracteristicas: Vec::new(),
15361 };
15362 assert!(path_true.opcional());
15363 }
15364
15365 #[test]
15366 fn dep_opcional_projects_bool_by_copy() {
15367 // The by-`Copy` pin: [`Dep::opcional`] returns `bool` by value
15368 // (`bool: Copy`) — the accessor does not borrow `&self` past
15369 // the call (no lifetime on the return type), and calling the
15370 // accessor twice on the same [`Dep`] must yield discriminant-
15371 // equal values (idempotent, no side effects on `&self`). Peer
15372 // of the sibling outer-`Caixa` `Option<Copy>` by-`Copy`
15373 // `max_restarts_projects_option_by_copy` (eba5211) /
15374 // `estrategia_projects_option_by_copy` (ed04d3c) pins on the
15375 // outer-`Caixa` altitude — extended here to the outer-`Dep`
15376 // altitude's plain-`Copy` `bool` axis. The `Copy` discipline
15377 // replaces the pointer-equality claim the sibling per-`Dep`
15378 // by-borrow pins (`dep_nome_is_by_borrow_pointer_identity`
15379 // eba2cde, `dep_versao_requirement_is_by_borrow_pointer_identity`
15380 // 05529b1, `dep_fonte_is_by_borrow_pointer_identity` d65d1bf,
15381 // `dep_caracteristicas_is_by_borrow_pointer_identity` 9197944)
15382 // carry (a fresh `Copy` of a `Copy` discriminant is definitionally
15383 // the same discriminant, so the axis reduces to discriminant
15384 // equality).
15385 //
15386 // Pins against a future silent detour that returned a fresh
15387 // `&bool` reference (which would type-check but silently
15388 // introduce a borrow of `&self` past the call, collapsing the
15389 // load-bearing "no lifetime on the return type" `Copy`
15390 // projection the plain-`Copy`-scalar axis's `bool` shape
15391 // carries) or a stale-read side effect that flipped the outer
15392 // discriminant on successive calls.
15393 for opcional in [false, true] {
15394 let d = Dep {
15395 nome: "caixa-teia".to_string(),
15396 versao: "^0.1".to_string(),
15397 fonte: None,
15398 opcional,
15399 caracteristicas: Vec::new(),
15400 };
15401 let first = d.opcional();
15402 let second = d.opcional();
15403 assert_eq!(
15404 first, second,
15405 "Dep::opcional must be idempotent — two successive calls \
15406 on the same &self must return the same bool",
15407 );
15408 assert_eq!(
15409 first, opcional,
15410 "Dep::opcional must return :opcional verbatim by Copy — \
15411 got {first}, expected {opcional}",
15412 );
15413 assert_eq!(
15414 d.opcional(),
15415 d.opcional,
15416 "Dep::opcional accessor and self.opcional field access \
15417 must byte-equal — a bit-flip drift would silently split \
15418 the paired resolver-side drop-vs-error dispatch from \
15419 the storage-side default-fill the [`Dep::simple`] / \
15420 [`Dep::git`] constructor pair carries",
15421 );
15422 }
15423 }
15424
15425 // ── DepSource::sole_pin — sole-set git-pin accessor ─────────────────
15426
15427 #[test]
15428 fn sole_pin_returns_none_for_path_source() {
15429 // A path source carries no git-ref, so `sole_pin()` returns
15430 // `None` structurally — the sibling arm every git-fetching
15431 // consumer partitions off before reaching for a git-ref. Pins
15432 // the Path-arm branch of the accessor against a future silent
15433 // detour that treats a `Self::Path` as an unpinned-git source
15434 // and returns the wrong "no pin" signal (e.g. the empty string,
15435 // or a hard-coded `Some("HEAD")` matching the caixa-crd
15436 // path-arm `git_ref` fill).
15437 let s = DepSource::Path {
15438 caminho: "../local-caixa".to_string(),
15439 };
15440 assert_eq!(s.sole_pin(), None);
15441 }
15442
15443 #[test]
15444 fn sole_pin_returns_none_for_unpinned_git_source() {
15445 // The [`DepSource::default_github`] shorthand shape carries no
15446 // pin — every `tag`/`rev`/`branch` is `None`, and `sole_pin()`
15447 // returns `None`. This is the shape caixa-resolver's `fetch_dep`
15448 // materializes when the author omits `:fonte` entirely, then
15449 // hands to `fetch_git` which raises `ResolveError::MissingPin`
15450 // on the `None` arm — the accessor's return matches the arm
15451 // the resolver's diagnostic keys off.
15452 let s = DepSource::default_github("pleme-io", "caixa-teia");
15453 assert_eq!(s.sole_pin(), None);
15454 }
15455
15456 #[test]
15457 fn sole_pin_returns_rev_when_only_rev_is_set() {
15458 let s = DepSource::Git {
15459 repo: "github:o/x".into(),
15460 tag: None,
15461 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15462 branch: None,
15463 };
15464 assert_eq!(
15465 s.sole_pin(),
15466 Some("deadbeefcafebabe1234567890abcdef12345678")
15467 );
15468 }
15469
15470 #[test]
15471 fn sole_pin_returns_tag_when_only_tag_is_set() {
15472 let s = DepSource::Git {
15473 repo: "github:o/x".into(),
15474 tag: Some("v0.1.0".into()),
15475 rev: None,
15476 branch: None,
15477 };
15478 assert_eq!(s.sole_pin(), Some("v0.1.0"));
15479 }
15480
15481 #[test]
15482 fn sole_pin_returns_branch_when_only_branch_is_set() {
15483 let s = DepSource::Git {
15484 repo: "github:o/x".into(),
15485 tag: None,
15486 rev: None,
15487 branch: Some("main".into()),
15488 };
15489 assert_eq!(s.sole_pin(), Some("main"));
15490 }
15491
15492 #[test]
15493 fn sole_pin_precedence_rev_beats_tag_and_branch() {
15494 // Precedence: rev > tag > branch. Validate() rejects
15495 // multiple-pin shapes, but the accessor's precedence is defined
15496 // for pre-validate consumers (the resolver's `MissingPin`
15497 // diagnostic path, the caixa-crd round-trip's default `"main"`
15498 // fallback) and as defense-in-depth if the gate is ever
15499 // bypassed. Pins the same precedence caixa-resolver's
15500 // `fetch_git` and caixa-crd's `dep_into_ref` already apply
15501 // inline.
15502 let s = DepSource::Git {
15503 repo: "github:o/x".into(),
15504 tag: Some("v1".into()),
15505 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15506 branch: Some("main".into()),
15507 };
15508 assert_eq!(
15509 s.sole_pin(),
15510 Some("deadbeefcafebabe1234567890abcdef12345678")
15511 );
15512 }
15513
15514 #[test]
15515 fn sole_pin_precedence_tag_beats_branch_when_no_rev() {
15516 let s = DepSource::Git {
15517 repo: "github:o/x".into(),
15518 tag: Some("v1".into()),
15519 rev: None,
15520 branch: Some("main".into()),
15521 };
15522 assert_eq!(s.sole_pin(), Some("v1"));
15523 }
15524
15525 #[test]
15526 fn sole_pin_byte_equals_inline_rev_or_tag_or_branch_cascade() {
15527 // Fail-before-pass-after byte-parity pin: the substrate accessor
15528 // must return byte-identical to the inline
15529 // `rev.as_deref().or(tag.as_deref()).or(branch.as_deref())`
15530 // cascade both caixa-resolver's `fetch_git` and caixa-crd's
15531 // `dep_into_ref` open-coded pre-lift. Trips at caixa-core build
15532 // time if the accessor's precedence silently drifts from the
15533 // consumer-side cascade — the exact drift this lift converges
15534 // to one substrate primitive to close structurally.
15535 //
15536 // Iterates through the 2^3 = 8 combinations of (tag, rev,
15537 // branch) each-either-`None`-or-`Some`, so every arm of the
15538 // precedence cascade lands under the pin. `validate()` refuses
15539 // the 4 multi-pin combinations, but the accessor's return is
15540 // defined on all 8.
15541 let vals = [Some("R".to_string()), None];
15542 for tag in &vals {
15543 for rev in &vals {
15544 for branch in &vals {
15545 let s = DepSource::Git {
15546 repo: "github:o/x".into(),
15547 tag: tag.clone(),
15548 rev: rev.clone(),
15549 branch: branch.clone(),
15550 };
15551 // The exact inline cascade the two pre-lift
15552 // consumer sites hand-rolled, byte-for-byte.
15553 let expected = rev.as_deref().or(tag.as_deref()).or(branch.as_deref());
15554 assert_eq!(
15555 s.sole_pin(),
15556 expected,
15557 "sole_pin() must byte-equal \
15558 rev.or(tag).or(branch) for \
15559 (tag={tag:?}, rev={rev:?}, branch={branch:?}) — \
15560 a drift would silently split caixa-resolver's \
15561 fetch_git checkout target from caixa-crd's \
15562 dep_into_ref git_ref fill",
15563 );
15564 }
15565 }
15566 }
15567 }
15568}