caixa_core/dep.rs
1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4/// A single dependency declaration in a `caixa.lisp` manifest.
5///
6/// **Store model = Git, like Zig.** There is no central registry; a caixa is
7/// just a Git repo with a `caixa.lisp` at its root. When `:fonte` is omitted,
8/// the resolver falls back to `github:<default-org>/<nome>` (org defaults to
9/// `pleme-io`, override via `~/.config/caixa/config.yaml`).
10///
11/// ```lisp
12/// ;; Shorthand — resolves to github:pleme-io/caixa-teia (or your default org):
13/// (:nome "caixa-teia" :versao "^0.1")
14///
15/// ;; Explicit git source:
16/// (:nome "caixa-teia"
17/// :versao "^0.1"
18/// :fonte (:tipo git :repo "github:pleme-io/caixa-teia" :tag "v0.1.0"))
19///
20/// ;; Arbitrary git URL (not limited to GitHub):
21/// (:nome "private-caixa"
22/// :versao "*"
23/// :fonte (:tipo git :repo "ssh://git@git.example/team/priv-caixa.git" :branch "main"))
24///
25/// ;; Local path (dev only; not publishable):
26/// (:nome "caixa-teia"
27/// :versao "0.1.0"
28/// :fonte (:tipo path :caminho "../caixa-teia"))
29/// ```
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
31#[serde(rename_all = "camelCase")]
32pub struct Dep {
33 /// Caixa name — must match the target caixa's `:nome`.
34 pub nome: String,
35
36 /// Semver constraint string (`"^0.1"`, `"~0.1.2"`, `"0.1.0"`, `"*"`).
37 pub versao: String,
38
39 /// Where to fetch the caixa from. Defaults to the feira registry.
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub fonte: Option<DepSource>,
42
43 /// If true, a missing `:fonte` is not a build failure.
44 #[serde(default, skip_serializing_if = "is_false")]
45 pub opcional: bool,
46
47 /// Feature flags to enable on the target caixa.
48 #[serde(default, skip_serializing_if = "Vec::is_empty")]
49 pub caracteristicas: Vec<String>,
50}
51
52/// Where a dep is fetched from. Tagged via `:tipo` in Lisp.
53///
54/// Only two shapes — Git and local Path. No central registry variant: a caixa
55/// is just a Git repo. Omitting `:fonte` means *"use the default resolver
56/// convention"*, which is `github:<default-org>/<nome>`; the resolver fills
57/// that in when computing the lacre.
58///
59/// The [`gen_platform::IsVariant`] derive emits per-arm arm-discriminator
60/// predicates — [`Self::is_git`], [`Self::is_path`] — so every downstream
61/// consumer that only needs the arm-discriminator projection (not the
62/// borrowed field value) reaches for one typed dispatch on the substrate
63/// primitive rather than a hand-rolled `matches!(s, DepSource::X { .. })`
64/// literal. Extends the closed-set-typed-enum discipline the sibling
65/// caixa-core enums ([`crate::CaixaKind`], [`crate::CaixaDialeto`],
66/// [`crate::supervisor::RestartStrategy`], [`crate::supervisor::RestartPolicy`],
67/// [`crate::upgrade::UpgradeInstruction`], [`crate::aplicacao::PlacementStrategy`],
68/// [`crate::aplicacao::RateLimitUnit`], [`crate::aplicacao::WitTarget`],
69/// [`crate::render::PathShapeViolation`], [`DepList`]) and the sibling
70/// out-of-crate enums (caixa-arch's `InvariantKind` + `ArchVerdict`,
71/// caixa-lint's `Severity` + `FixSafety`, caixa-provedor's
72/// `FerriteRuntime`, caixa-theme's `Semantic`, caixa-flux's `GitRefSpec`,
73/// caixa-ast's `NodeKind` + `TriviaKind`) already carry onto the
74/// two-arm `:fonte` dep-source axis — the 17th closed-set typed enum
75/// on the caixa surface, and the first on the outer-`Dep` `:fonte`-slot
76/// axis every git-fetching consumer runs after the outer `:fonte` slot
77/// resolves to a shape.
78#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, gen_platform::IsVariant)]
79#[serde(tag = "tipo", rename_all = "lowercase")]
80pub enum DepSource {
81 /// Clone from Git. One of `:tag`, `:rev`, or `:branch` may be set.
82 /// `repo` can be a `github:org/repo` shorthand, a full `https://…` URL,
83 /// or any git-ssh URL.
84 Git {
85 repo: String,
86 #[serde(default, skip_serializing_if = "Option::is_none")]
87 tag: Option<String>,
88 #[serde(default, skip_serializing_if = "Option::is_none")]
89 rev: Option<String>,
90 #[serde(default, skip_serializing_if = "Option::is_none")]
91 branch: Option<String>,
92 },
93 /// Local filesystem path — dev only; cannot be published.
94 Path { caminho: String },
95}
96
97impl DepSource {
98 /// Build a registry-shorthand git source (`github:<org>/<nome>`).
99 ///
100 /// This is the resolver-side fallback for `dep.fonte: None`, not an
101 /// author-surface value — it carries no pin (`:tag`/`:rev`/`:branch`
102 /// all `None`) and is therefore rejected by [`Self::validate`]. The
103 /// resolver fills the pin in at fetch time from the resolved commit;
104 /// authors never serialize this shape as a `Dep::fonte` value.
105 #[must_use]
106 pub fn default_github(org: &str, nome: &str) -> Self {
107 Self::Git {
108 repo: format!("github:{org}/{nome}"),
109 tag: None,
110 rev: None,
111 branch: None,
112 }
113 }
114
115 /// Substrate-canonical per-`:fonte` sole-set git-pin scalar accessor
116 /// every consumer that reads "which single git ref does this source
117 /// resolve to?" keys off — returns the author-declared `:tag` /
118 /// `:rev` / `:branch` byte-string verbatim as an `Option<&str>`,
119 /// borrowed from the typed slot's own `Option<String>` storage; `None`
120 /// on [`Self::Path`] (a path source carries no git-ref) and on a
121 /// [`Self::Git`] variant whose `tag`, `rev`, and `branch` are all
122 /// `None` (the [`Self::default_github`] shorthand shape the resolver
123 /// materializes when the author omits `:fonte` — rejected by
124 /// [`Self::validate`], but the accessor's return is defined on this
125 /// arm too so pre-validate consumers reach for the same typed dispatch
126 /// as post-validate ones).
127 ///
128 /// **Precedence: rev > tag > branch.** The canonical precedence every
129 /// per-`:fonte` git-ref consumer already applies: caixa-resolver's
130 /// per-fetch `git checkout <ref>` reads through the same
131 /// `rev.or(tag).or(branch)` cascade at caixa-resolver/src/resolve.rs,
132 /// and caixa-crd's `dep_into_ref` `CaixaSource.git_ref` fill reads
133 /// through the same cascade at caixa-crd/src/conversion.rs. The
134 /// [`Self::validate`] gate enforces "exactly one pin set" — under
135 /// that invariant every accepted [`Self::Git`] carries exactly one
136 /// non-`None` pin and the precedence is unobservable, but the
137 /// precedence remains defined for pre-validate consumers (the
138 /// resolver's `MissingPin` diagnostic path, the caixa-crd
139 /// round-trip's default `"main"` fallback the author never sees a
140 /// diagnostic on) and defense-in-depth for a hypothetical future
141 /// state where multiple pins survive the gate. The precedence is
142 /// **rev before tag** because `:rev` (a git commit OID) is the
143 /// reproducibility-strongest identifier — an OID resolves to exactly
144 /// one commit regardless of which refname points at it, whereas
145 /// `:tag` and `:branch` are refnames the remote can silently move
146 /// (a tag re-push, a branch head advance); the resolver's freeze
147 /// step at fetch time promotes the resolved commit to `:rev` for
148 /// exactly this reason. **Tag before branch** because `:tag` is
149 /// conventionally immutable (a release tag) whereas `:branch` is
150 /// conventionally mutable (a tracking ref) — a caixa carrying both
151 /// a release tag and a tracking branch reads as "prefer the release
152 /// pin, fall through to the tracking pin only if the release is
153 /// missing". The cascade order also matches the byte-order every
154 /// per-`:tag`/`:rev`/`:branch` diagnostic tuple this crate emits
155 /// (`(":tag", tag), (":rev", rev), (":branch", branch)` — see
156 /// [`Self::validate`]'s `pins` array).
157 ///
158 /// Prior to this lift the "sole set pin" projection sat twice in the
159 /// workspace — inline at caixa-resolver's `fetch_git` (`let gitref =
160 /// rev.or(tag).or(branch).ok_or_else(|| ResolveError::MissingPin
161 /// { … })?;`) and at caixa-crd's `dep_into_ref`
162 /// (`git_ref: rev.clone().or(tag.clone()).or(branch.clone())
163 /// .unwrap_or_else(|| "main".to_string())`) — two open-coded copies
164 /// of the same precedence cascade with no compile-time link back to
165 /// the typed slot. A future extension of the pin axis to a richer
166 /// author surface (a `:commit` pin peer of `:rev` once the substrate
167 /// grows a signed-commit-verification pin, a `:ref` pin the M4
168 /// substrate operator resolves per-cluster ahead of fetch, a
169 /// promotion of the plain `Option<String>` pins to a typed
170 /// `GitPin::{Rev(Oid), Tag(RefName), Branch(RefName)}` newtype
171 /// once the sibling [`crate::render::is_git_oid`] /
172 /// [`crate::render::is_git_ref_name`] gates land as typed
173 /// constructors) would have had to be threaded through both
174 /// open-coded copies in lockstep or the resolver's `git checkout`
175 /// target would silently disagree with the CRD's `git_ref` fill —
176 /// an author's `(:fonte (:tipo git :repo "…" :rev "deadbeef" :tag
177 /// "v1"))` would ship with the resolver checking out `deadbeef`
178 /// while the CRD round-trip re-emitted a Dep pointing at `v1`, one
179 /// lacre closure disagreeing with the emitted K8s CR the operator
180 /// reads. Lifting the resolution to a typed method on the substrate
181 /// primitive means both downstream consumers reach for exactly one
182 /// typed dispatch — the resolver's accept-set migrates as a unit on
183 /// any future pin-axis addition.
184 ///
185 /// Peer of the sibling outer-`Dep` [`Dep::fonte`] (d65d1bf)
186 /// `Option<&DepSource>` composite-reference accessor on the outer-
187 /// `Dep` `:fonte`-slot axis — extended one nesting level down onto
188 /// the per-[`Self::Git`]-variant sole-set-pin projection axis every
189 /// git-fetching consumer runs after the outer `:fonte` slot resolves
190 /// to a [`Self::Git`] shape. Same "one typed dispatch on the
191 /// substrate primitive, thin projections at each consumer" discipline
192 /// the outer accessor family already carries.
193 #[must_use]
194 pub fn sole_pin(&self) -> Option<&str> {
195 match self {
196 Self::Git {
197 tag, rev, branch, ..
198 } => rev.as_deref().or(tag.as_deref()).or(branch.as_deref()),
199 Self::Path { .. } => None,
200 }
201 }
202
203 /// Validate the `:fonte` value-shape: every author-surface
204 /// `:fonte (:tipo git …)` must carry a non-empty `:repo` and
205 /// exactly one of `:tag` / `:rev` / `:branch` set to a non-empty
206 /// value; every `:fonte (:tipo path …)` must carry a non-empty
207 /// `:caminho`.
208 ///
209 /// Called from [`Dep::validate`] with the dep's `:nome` so every
210 /// diagnostic carries the offending entry verbatim — same
211 /// self-locating shape the `:deps :versao` (2420c44),
212 /// `:membros :versao` (9888b13), `:children :versao` (b38ff3a),
213 /// `:placement :clusters` (6cbb900), and `:membros :caixa`
214 /// (3f9d7a0) gates already expose.
215 ///
216 /// Until this gate landed `:fonte` was the only `:deps`-related
217 /// typed surface still untyped past `Caixa::from_lisp`:
218 /// - Empty `:repo` (`(:tipo git :repo "" :tag "v1")`) silently
219 /// passed parse and surfaced as a git-clone failure at
220 /// lacre-resolve time, far from the source caixa.lisp.
221 /// - A bare `(:tipo git :repo "…")` with no `:tag`/`:rev`/`:branch`
222 /// passed parse and surfaced as the resolver's
223 /// [`ResolveError::MissingPin`](../../caixa-resolver/src/resolve.rs)
224 /// at fetch time, again far from the source caixa.lisp; lifting
225 /// to validate-time gives the author the same diagnostic at the
226 /// edit site.
227 /// - `(:tipo git :repo "…" :tag "v1" :branch "main")` — multiple
228 /// pins set — passed parse and the resolver silently picked
229 /// `:rev > :tag > :branch`, ignoring the other pins with no
230 /// diagnostic; the author had no way to know their `:branch`
231 /// was dropped. This is the canonical "pin drift" footgun.
232 /// - An empty pin value (`(:tipo git :repo "…" :tag "")`) silently
233 /// passed parse and surfaced as `git checkout ""` at fetch time.
234 /// - Empty `:caminho` (`(:tipo path :caminho "")`) silently passed
235 /// parse and surfaced as
236 /// [`ResolveError::MissingPath`](../../caixa-resolver/src/resolve.rs)
237 /// with `path: PathBuf("")` — not actionable.
238 ///
239 /// Each rejected shape maps to a typed
240 /// [`DepError::Fonte*`] variant that names the offending
241 /// dep's `:nome` and the specific axis, so the author can grep
242 /// their caixa.lisp for the `:nome "<nome>"` block and fix it in
243 /// one edit.
244 pub fn validate(&self, nome: &str) -> Result<(), DepError> {
245 match self {
246 Self::Git {
247 repo,
248 tag,
249 rev,
250 branch,
251 } => {
252 if repo.is_empty() {
253 return Err(DepError::FonteRepoEmpty {
254 nome: nome.to_string(),
255 });
256 }
257 // The `:repo` value flows verbatim into the caixa-resolver's
258 // `git clone <repo>` subprocess invocation. Until this gate
259 // landed `:repo` was the last untyped `:fonte`-related axis
260 // past the empty arm: a malformed-but-non-empty repo URL
261 // (`":repo "github:p/x ""` trailing space, paste-from-doc;
262 // `":repo "-upload-pack=evil""` leading `-` — the canonical
263 // CLI-argument-injection vector at the `git clone` boundary;
264 // `":repo "pleme-io/caixa-teia""` missing scheme — `git clone`
265 // reads as a relative filesystem path rather than the
266 // GitHub-shorthand expansion; `":repo "github:p/x\n""`
267 // embedded newline; `":repo "github:café/x""` raw non-ASCII)
268 // silently passed validate and the failure surfaced at
269 // lacre-resolve time with a porcelain-quoting-confused error
270 // far from the source caixa.lisp. The lifted predicate makes
271 // the git-porcelain-URL intersection-floor a substrate-level
272 // invariant at validate time, peer with the three pin axes
273 // (`:tag` + `:branch` via [`crate::render::is_git_ref_name`],
274 // e70d213; `:rev` via [`crate::render::is_git_oid`], be07fd5)
275 // — every `:fonte (:tipo git …)` past validate is now
276 // structurally accept-shaped on every axis the resolver
277 // consumes (the `:repo` URL the `git clone` invokes against,
278 // the `:tag`/`:branch` refname `git fetch`/`git checkout`
279 // accepts, the `:rev` commit OID the lacre's content-
280 // addressing equality probe resolves), closing the
281 // `:fonte` slot's value-shape trajectory end-to-end.
282 if let Err(reason) = crate::render::is_git_repo_url(repo) {
283 return Err(DepError::FonteRepoShape {
284 nome: nome.to_string(),
285 repo: repo.clone(),
286 reason,
287 });
288 }
289 let pins: [(&'static str, Option<&String>); 3] = [
290 (":tag", tag.as_ref()),
291 (":rev", rev.as_ref()),
292 (":branch", branch.as_ref()),
293 ];
294 let set: Vec<&'static str> =
295 pins.iter().filter_map(|(n, v)| v.map(|_| *n)).collect();
296 match set.len() {
297 0 => {
298 return Err(DepError::FontePinMissing {
299 nome: nome.to_string(),
300 });
301 }
302 1 => {
303 for (pin, value) in pins {
304 if value.is_some_and(String::is_empty) {
305 return Err(DepError::FontePinEmpty {
306 nome: nome.to_string(),
307 pin: pin.to_string(),
308 });
309 }
310 }
311 }
312 _ => {
313 return Err(DepError::FontePinAmbiguous {
314 nome: nome.to_string(),
315 pins: set.join(", "),
316 });
317 }
318 }
319 // Per-pin value-shape gate. The refname-shaped axes
320 // (`:tag` + `:branch`) route through
321 // [`crate::render::is_git_ref_name`]; the hex-OID-shaped
322 // `:rev` axis routes through
323 // [`crate::render::is_git_oid`]. The two predicates
324 // partition the `:fonte` pin axes structurally — refname
325 // vs. hex commit — so a cross-axis mis-slot (the
326 // canonical "I conflated `:rev` and `:branch`" footgun:
327 // `:rev "main"` defeating the reproducibility contract,
328 // `:tag "deadbeef…"` mis-slotting a SHA into the
329 // refname-shaped axis) lands at the offending axis's
330 // predicate, not at lacre-resolve `git fetch` /
331 // `git checkout` time. Their valid sets intersect at
332 // the empty set: every refname is rejected by
333 // `is_git_oid`, every OID is rejected by
334 // `is_git_ref_name`, structurally.
335 //
336 // Until this gate landed `:tag` / `:branch` were the
337 // refname-shaped axes still untyped past the empty-pin
338 // arm: a malformed-but-non-empty refname
339 // (`:tag "v0.1.0 "` trailing space — the canonical
340 // paste-from-doc footgun; `:tag "v0.1.0.lock"` colliding
341 // with git's atomic-rename guard suffix; `:tag "../escape"`
342 // path-traversal via consecutive dots; `:branch "main "`
343 // trailing space; `:branch "feature/foo bar"` embedded
344 // space; `:branch "@"` the literal HEAD alias;
345 // `:branch "refs/heads/main"` the fully-qualified ref
346 // copied from `git show-ref` output that resolves to
347 // a literal ref named `refs/heads/refs/heads/main` on
348 // disk) silently passed validate; the `:rev` axis was
349 // the last `:fonte`-related axis still untyped past the
350 // empty-pin arm: a malformed-but-non-empty hex-OID
351 // (`:rev "main"` conflating with `:branch` — the
352 // reproducibility-contract leak; `:rev "v0.1.0"`
353 // conflating with `:tag` — the same mis-slot on the
354 // refname/OID boundary; `:rev "c0ffee"` an abbreviated
355 // 6-char prefix that's ambiguous across repo history;
356 // `:rev "DEADBEEF…"` an uppercase OID that round-trips
357 // inconsistently against `git rev-parse HEAD`'s
358 // lowercase emission) silently passed validate and the
359 // failure surfaced at lacre-resolve `git fetch` /
360 // `git checkout` time with a quoting-confused error
361 // far from the source caixa.lisp, with no field naming
362 // which `:deps` entry carried the typo. Lifting both
363 // gates to caixa-build time matches the value-shape
364 // trajectory the peer typed axes already follow
365 // (c4213a4 typed WitContract endpoint/subject/slot;
366 // eb3456d :entrada :paths; c7d05ec :entrada :host;
367 // 4f0390b :contratos :endpoint; 6226bf4 :contratos :wit;
368 // 63e18a0 :contratos :subject; 2f4316e :contratos
369 // :slot; e70d213 :fonte :tag + :branch) — the typed
370 // slot's valid set matches its downstream consumer's
371 // accepted set (here, the git porcelain's refname /
372 // commit-OID grammars at `git fetch` / `git checkout`
373 // time), structurally. Same diagnostic shape every
374 // per-axis value-shape lift already exposes
375 // (`*Invalid { axis, reason }`); the `value:` field
376 // carries the offending refname / OID verbatim so the
377 // author can grep their caixa.lisp for the
378 // `:tag "<value>"` / `:branch "<value>"` /
379 // `:rev "<value>"` literal and fix it in one edit.
380 for (pin, value) in [(":tag", tag.as_ref()), (":branch", branch.as_ref())] {
381 if let Some(v) = value
382 && let Err(reason) = crate::render::is_git_ref_name(v)
383 {
384 return Err(DepError::FontePinShape {
385 nome: nome.to_string(),
386 pin: pin.to_string(),
387 value: v.clone(),
388 reason,
389 });
390 }
391 }
392 if let Some(v) = rev.as_ref()
393 && let Err(reason) = crate::render::is_git_oid(v)
394 {
395 return Err(DepError::FontePinShape {
396 nome: nome.to_string(),
397 pin: ":rev".to_string(),
398 value: v.clone(),
399 reason,
400 });
401 }
402 Ok(())
403 }
404 Self::Path { caminho } => Self::validate_caminho(nome, caminho),
405 }
406 }
407
408 /// Reproducibility + path-API gate on the `:fonte (:tipo path …)`
409 /// `:caminho` axis. Walks the leading-byte cascade closed by the
410 /// b94fd83 (`/`), a5c248e (`~`), and f4efe9c (`$`) arms; the
411 /// orthogonal embedded-control-byte arm (d624c8d) covering
412 /// `0x00..=0x1F` plus `0x7F` anywhere in the value; and the
413 /// embedded-`\` Windows-path-separator arm closing the
414 /// cross-host-OS-separator divergence vector on the same
415 /// THEORY.md §V.2 render-determinism axis.
416 ///
417 /// Extracted from [`Self::validate`]'s `Self::Path` arm because the
418 /// per-arm cascade now spans nine diagnostic shapes — every new
419 /// `:caminho` arm (a future `&` / `;` / `|` shell-metachar arm,
420 /// a future glob-metachar `*` / `?` arm) lands here rather than
421 /// re-inflating `Self::validate`. The
422 /// function stays a thin per-arm linear walk for one reason: each
423 /// arm's diagnostic carries a distinct typed [`DepError`] variant
424 /// rather than a parser-shaped `reason` string, so collapsing the
425 /// cascade onto a generic [`crate::render`] predicate would regress
426 /// the per-arm self-locating diagnostic that `feira lint` consumers
427 /// depend on. The wrapped predicate trajectory ([`crate::render::is_dns_1123_label`],
428 /// [`crate::render::is_git_repo_url`], etc.) lives on the
429 /// reason-string-shaped axes; the `:caminho` axis keeps its
430 /// per-arm variant shape.
431 #[allow(
432 clippy::too_many_lines,
433 reason = "the per-arm cascade is structurally flat by design — every \
434 `:caminho` arm carries its own typed [`DepError`] variant + \
435 per-arm Why comment, so collapsing the cascade onto a generic \
436 [`crate::render`] predicate would regress the per-arm self-locating \
437 diagnostic the `feira lint` consumer surface depends on"
438 )]
439 fn validate_caminho(nome: &str, caminho: &str) -> Result<(), DepError> {
440 if caminho.is_empty() {
441 return Err(DepError::FonteCaminhoEmpty {
442 nome: nome.to_string(),
443 });
444 }
445 // Reproducibility gate on the `:fonte (:tipo path …)`
446 // `:caminho` axis. The lacre pipeline embeds the value
447 // verbatim in its per-dep content-address
448 // (`conteudo: format!("path:{caminho}")`,
449 // caixa-resolver/src/resolve.rs:189) and that string
450 // folds into the BLAKE3 closure the lacre keys every
451 // downstream consumer (the substrate's reproducibility
452 // contract, CAIXA-SDLC §III.2 — the lacre is the
453 // build's content-addressed identity, peer of the Nix
454 // store path) against. Until this gate landed an
455 // absolute `:caminho` (`/home/me/work/caixa-teia` — the
456 // canonical "I dragged the folder out of Finder into
457 // my editor" footgun; `/Users/alice/dev/caixa-teia` on
458 // the macOS path-layout peer; the
459 // `${WORKSPACE}/caixa-teia` shell-expanded literal
460 // pasted from a CI manifest) silently passed validate
461 // and the failure surfaced *as a successful build with
462 // a divergent lacre*: the BLAKE3 closure on Alice's
463 // workstation differed from the closure on Bob's
464 // workstation, two CI runners with different
465 // `${HOME}` layouts emitted two distinct
466 // content-addresses for the byte-identical caixa, and
467 // the substrate's "the lacre is the build's identity"
468 // contract silently broke far from the source
469 // caixa.lisp — the most insidious failure mode the
470 // typed slot can carry (no error surfaces; the
471 // divergence is invisible until two machines compare
472 // lacres). The same THEORY.md §V.2 render-determinism
473 // discipline `is_sandboxed_relative_path` already
474 // applies on the M2 typed path-slots
475 // (`:behavior :on-*`, `:upgrade-from :state-change
476 // :script`, `:bibliotecas`, `:exe`, `:servicos`), here
477 // narrowed to the absolute-vs-relative axis only:
478 // `:fonte :caminho`'s canonical author-surface form is
479 // the `..`-traversing sibling-workspace path
480 // (`"../caixa-teia"`, the in-tree dev-dep frame), so a
481 // full `is_sandboxed_relative_path` lift would
482 // structurally reject every legitimate path-fonte
483 // dep. The narrower
484 // `std::path::Path::is_absolute` cut admits the
485 // sibling-workspace form while still rejecting the
486 // host-layout-leaking absolute shape — the
487 // reproducibility contract bites at exactly the
488 // absolute boundary, and that's the axis the
489 // substrate-level invariant is meant to hold. Same
490 // diagnostic shape every per-axis value-shape lift on
491 // the surrounding [`DepError::Fonte*`] cluster carries
492 // (the offending `:nome` + offending `:caminho`
493 // quoted verbatim so the author can grep their
494 // caixa.lisp for the `:caminho "<value>"` literal and
495 // fix it in one edit). The empty arm strictly
496 // precedes this arm so the blank-string footgun
497 // surfaces the more self-locating
498 // `FonteCaminhoEmpty` diagnostic (the empty string
499 // is not absolute under `Path::new("").is_absolute()`
500 // so the precedence is a no-op at value level — the
501 // pin matters only at the diagnostic-shape level if
502 // a future codec round-trip ever produces an empty
503 // string that probes as absolute).
504 if std::path::Path::new(caminho).is_absolute() {
505 return Err(DepError::fonte_caminho_absolute(nome, caminho));
506 }
507 // Reproducibility gate's tilde-expansion arm. The b94fd83
508 // `FonteCaminhoAbsolute` closes the leading-`/`
509 // host-layout-leak; a `:caminho "~/work/caixa-teia"` (the
510 // canonical paste-from-shell-prompt / paste-from-`cd ~`-
511 // doc footgun) silently passed both the empty arm and
512 // the absolute arm because `Path::new("~").is_absolute()`
513 // returns `false` — `~` is a shell-expansion convention,
514 // not a POSIX path component, so `std::path::Path` treats
515 // it as a literal directory-name segment. The lacre
516 // pipeline then embedded the value verbatim
517 // (`conteudo: format!("path:~/work/caixa-teia")`) and the
518 // failure mode forked per consumer:
519 //
520 // - The caixa-resolver's `Path` arm folds `:caminho`
521 // through `Path::new(caminho).join(<file>)` without
522 // `~`-expansion, so the build looked for a literal
523 // `./~/work/caixa-teia` subdirectory and failed at
524 // resolve time with a `No such file or directory`
525 // error far from the source caixa.lisp (the lacre
526 // itself, though, was already byte-identical across
527 // machines — every machine emitted the same
528 // `path:~/work/caixa-teia` content-address).
529 // - A future caixa-resolver pass that *does* expand `~`
530 // (the canonical shell-convention idiom every
531 // resolver eventually reaches for once an author
532 // reports the literal-`~`-directory bug) would re-
533 // introduce the host-layout-leak the b94fd83 absolute
534 // gate closes: Alice's `~` expands to `/home/alice`,
535 // Bob's to `/home/bob`, two CI runners with different
536 // `$HOME` layouts resolve to two distinct paths for
537 // the byte-identical caixa, and the substrate's
538 // "the lacre is the build's identity" contract
539 // silently breaks far from the source caixa.lisp.
540 //
541 // Closing the gate at `DepSource::validate` (here at the
542 // canonical caixa-build-time boundary, peer with the
543 // absolute arm above) refuses both failure modes
544 // structurally: the typed accepted set excludes every
545 // `~`-prefixed authoring shape, so the resolver is
546 // free to grow `~`-expansion (or any other convention-
547 // expansion the substrate adopts) without re-opening
548 // the host-layout-leak at the typed boundary. Same
549 // diagnostic shape every per-axis value-shape gate on
550 // the surrounding [`DepError::Fonte*`] cluster carries
551 // (the offending `:nome` + offending `:caminho` quoted
552 // verbatim so the author can grep their caixa.lisp for
553 // the `:caminho "<value>"` literal and fix it in one
554 // edit).
555 //
556 // The cascade preserves narrower-diagnostic-first
557 // ordering: `FonteCaminhoEmpty` → `FonteCaminhoAbsolute`
558 // → `FonteCaminhoTildeExpansion`. The empty arm
559 // structurally precedes both (the bytes "" / "~" don't
560 // overlap), and the absolute arm structurally precedes
561 // the tilde arm (an absolute path can't start with `~`
562 // since absolute paths start with `/`; the bytes "/" /
563 // "~" don't overlap either). Both arms are
564 // value-disjoint, so the precedence is a no-op at value
565 // level — the pin matters only at the diagnostic-shape
566 // level if a future codec round-trip ever produces a
567 // value that probes as both absolute and tilde-prefixed.
568 if caminho.starts_with('~') {
569 return Err(DepError::fonte_caminho_tilde_expansion(nome, caminho));
570 }
571 // Reproducibility gate's shell-variable-expansion arm.
572 // The b94fd83 `FonteCaminhoAbsolute` closes the leading-`/`
573 // host-layout-leak; the a5c248e `FonteCaminhoTildeExpansion`
574 // closes the leading-`~` shell-home-expansion shape; the
575 // leading-`$` is the sibling shell-variable-expansion shape
576 // — same host-layout-leaking semantic, different syntactic
577 // surface. A `:caminho "$HOME/work/caixa-teia"` (the
578 // canonical paste-from-`echo $HOME`-doc footgun) and the
579 // `${VAR}`-braced variant (`"${WORKSPACE}/caixa-teia"` —
580 // the canonical paste-from-CI-manifest footgun every
581 // GitHub Actions / GitLab CI / Drone manifest carries)
582 // silently passed every prior arm because
583 // `Path::is_absolute` returns false on `$` (the `$` is a
584 // shell convention, not a POSIX path component, so
585 // `std::path::Path` treats it as a literal directory-name
586 // segment) and the tilde arm's `starts_with('~')` doesn't
587 // fire.
588 //
589 // Same per-consumer failure-fork the tilde arm closes:
590 //
591 // - The caixa-resolver's `Path` arm folds `:caminho`
592 // through `Path::new(caminho).join(<file>)` without
593 // `$`-expansion, so the build looks for a literal
594 // `./$HOME/work/caixa-teia` subdirectory and fails at
595 // resolve time with a `No such file or directory`
596 // error far from the source caixa.lisp.
597 // - A future caixa-resolver pass that *does* expand
598 // `$VAR` (the shell-convention idiom every resolver
599 // eventually reaches for once an author reports the
600 // literal-`$HOME`-directory bug, especially for CI's
601 // `${WORKSPACE}` idiom) would re-introduce the host-
602 // layout-leak the b94fd83 absolute gate closes:
603 // Alice's `$HOME` expands to `/home/alice`, Bob's to
604 // `/home/bob`, two CI runners with different
605 // `${WORKSPACE}` layouts resolve to two distinct
606 // paths for the byte-identical caixa, and the
607 // substrate's "the lacre is the build's identity"
608 // contract silently breaks far from the source
609 // caixa.lisp.
610 //
611 // Closing the gate at `DepSource::validate` (here at the
612 // canonical caixa-build-time boundary, peer with the
613 // absolute + tilde arms above) refuses both failure modes
614 // structurally. Same diagnostic shape every per-axis
615 // value-shape gate on the surrounding [`DepError::Fonte*`]
616 // cluster carries (the offending `:nome` + offending
617 // `:caminho` quoted verbatim).
618 //
619 // The cascade preserves narrower-diagnostic-first ordering:
620 // `FonteCaminhoEmpty` → `FonteCaminhoAbsolute` →
621 // `FonteCaminhoTildeExpansion` → `FonteCaminhoVarExpansion`.
622 // The empty arm structurally precedes all three subsequent
623 // arms; the absolute arm structurally precedes both the
624 // tilde and the var arms (absolute paths start with `/`,
625 // the bytes `/` / `~` / `$` don't overlap at the leading
626 // position); the tilde arm structurally precedes the var
627 // arm (`~` and `$` don't overlap at the leading position).
628 // Every pair is value-disjoint, so the precedence is a
629 // no-op at value level — the pin matters only at the
630 // diagnostic-shape level if a future codec round-trip ever
631 // produces a probe-as-both value.
632 //
633 // The gate covers every leading-`$` shape: the canonical
634 // `"$HOME/work/caixa-teia"` (POSIX shell), the braced
635 // `"${HOME}/work/caixa-teia"` (POSIX shell braces), the
636 // CI-manifest idiom `"${WORKSPACE}/caixa-teia"` (the
637 // GitHub Actions / GitLab CI / Drone paste footgun), the
638 // XDG idiom `"$XDG_CONFIG_HOME/caixa"`, and the bare `$`
639 // (degenerate "I meant `$HOME` and forgot the rest"). All
640 // shapes route through the same `caminho.starts_with('$')`
641 // byte check.
642 if caminho.starts_with('$') {
643 return Err(DepError::fonte_caminho_var_expansion(nome, caminho));
644 }
645 // Reproducibility gate's leading-space arm. The b94fd83 / a5c248e /
646 // f4efe9c arms closed the leading-byte host-layout-leak shapes
647 // (`/` / `~` / `$`); the embedded-control-byte arm below closes
648 // every byte in `0x00..=0x1F` plus `0x7F` (which already includes
649 // tab `0x09`, LF `0x0A`, CR `0x0D` — every ASCII whitespace
650 // *except* the ASCII space byte `0x20`). The bare ASCII space at
651 // the leading position is the orthogonal paste-from-aligned-doc
652 // shape that silently passed every prior arm: `Path::is_absolute`
653 // returns false on `" ../caixa-teia"` (the leading byte is `0x20`
654 // not `0x2F`), `0x20` is not `~` / `$` / `\` / a control byte, and
655 // the value's last byte is not `/`, so the canonical
656 // paste-from-aligned-`caixa.lisp`-doc footgun (every `:fonte`
657 // form in a multi-entry `:deps` block sits at the same column —
658 // an author selecting `"<sp><sp><sp>../caixa-teia"` and pasting
659 // it from the rendered alignment into a fresh entry preserves the
660 // leading whitespace verbatim) silently rendered as a path with
661 // a leading-space directory component the resolver folds through
662 // `Path::join` looking for a literal `./ ../caixa-teia`
663 // subdirectory that fails at resolve time with a non-self-
664 // locating `No such file or directory` error.
665 //
666 // The lacre pipeline's reproducibility contract bites
667 // strictly at this byte: `path:" ../caixa-teia"` and
668 // `path:"../caixa-teia"` yield distinct BLAKE3 closures
669 // (`conteudo: format!("path:{caminho}")`,
670 // caixa-resolver/src/resolve.rs:189) for the byte-divergent /
671 // semantic-identical caixa, and the substrate's "the lacre is
672 // the build's identity" contract (CAIXA-SDLC §III.2) silently
673 // breaks across two workstations whose authors differ only in
674 // paste-from-aligned-doc whitespace habits — the most insidious
675 // failure mode the typed slot can carry (no error surfaces; the
676 // divergence is invisible until two machines compare lacres).
677 //
678 // The arm fires AFTER the absolute / tilde / var leading-byte
679 // arms (each names the more self-locating shell-convention
680 // diagnostic on values that probe as that arm's leading-byte
681 // sentinel followed by a leading space — e.g.
682 // `:caminho "/ /foo"` surfaces `FonteCaminhoAbsolute` because
683 // the leading byte is `/`, not space) and BEFORE the
684 // embedded-control-byte arm (a leading-space value with an
685 // embedded control byte surfaces the broader leading-space
686 // diagnostic because the cascade walks leading-byte arms first
687 // — peer with how `FonteCaminhoAbsolute` precedes
688 // `FonteCaminhoControlChar` on `"/etc/passwd\n"`).
689 //
690 // The peer single-token-shaped axes already reject leading
691 // whitespace on the same paste-from-aligned-doc contract:
692 // [`crate::render::is_git_repo_url`] rejects leading whitespace
693 // on `:fonte :repo`, [`crate::render::is_git_ref_name`] rejects
694 // leading whitespace on `:fonte :tag`/`:branch`,
695 // [`crate::render::is_chart_description_shape`] rejects leading
696 // whitespace on `:descricao`,
697 // [`crate::render::is_spdx_expression_shape`] rejects leading
698 // whitespace on `:licenca`. Closing the same byte on
699 // `:fonte :caminho` makes the substrate-wide "no leading ASCII
700 // space anywhere in a typed string slot" invariant structurally
701 // consistent across every value-shape-gated typed surface (the
702 // `:caminho` axis was the last typed string surface still
703 // admitting a leading space byte).
704 if caminho.starts_with(' ') {
705 return Err(DepError::fonte_caminho_leading_whitespace(nome, caminho));
706 }
707 // Reproducibility gate's leading-`-` CLI-argument-injection arm.
708 // The b94fd83 + a5c248e + f4efe9c + LeadingWhitespace arms closed
709 // the four prior leading-byte shapes (`/` / `~` / `$` / space);
710 // this arm closes the orthogonal leading-`-` axis on the same
711 // subprocess-argument-boundary the peer `is_git_repo_url` arm
712 // (render.rs:2037, `-upload-pack=…` on `:fonte :repo`) and
713 // `is_git_ref_name` arm (render.rs:1381, 5a28454, `-stable` on
714 // `:fonte :tag` / `:branch`) already reject.
715 //
716 // The lacre pipeline embeds `:caminho` verbatim in its per-dep
717 // content-address (`conteudo: format!("path:{caminho}")`,
718 // caixa-resolver/src/resolve.rs:189) and the resolver folds the
719 // value through `Path::join` looking for a literal `./{caminho}`
720 // subdirectory. Every downstream subprocess that consumes the
721 // resolved path — a `git -C {caminho} <verb>` invocation, a
722 // future `feira tofu` `terraform -chdir={caminho}` shell-out, a
723 // future operator-side `nix build --path {caminho}` spawn, an
724 // `xargs` / `find {caminho}` / `stat {caminho}` /
725 // `rm -rf {caminho}` cleanup — reinterprets a leading-`-` value
726 // as a CLI flag rather than a positional path when the
727 // subprocess invocation does not carry a `--` argument-list
728 // terminator between the flag block and the path argument. The
729 // canonical footguns:
730 //
731 // - `:caminho "-rf"` — bare short-flag paste (`rm -rf` /
732 // `find -rf` reinterpretation; the byte the peer
733 // `FonteCaminhoShellSemicolon` arm's `; rm -rf build`
734 // example paste-idiom carries as its first token).
735 // - `:caminho "-C"` — `git -C` config-injection paste
736 // (`git -C -C` reinterprets the second `-C` as another
737 // `--change-directory` flag rather than the path
738 // argument; the canonical `git -C <path>` porcelain
739 // idiom every multi-repo workspace tool carries).
740 // - `:caminho "--upload-pack=cat /etc/passwd"` — the
741 // canonical long-flag CLI-arg-injection vector at every
742 // git porcelain entry point (`git clone`, `git fetch`,
743 // `git ls-remote`) that consumes a path or URL
744 // argument; peer with `is_git_repo_url`'s leading-`-`
745 // arm (render.rs:2037) on the sibling `:fonte :repo`
746 // axis, which the arm's diagnostic explicitly cites.
747 // - `:caminho "--config=…"` / `:caminho "-c"` — git-config
748 // override paste-idiom (paste-from-`git -c foo=bar`
749 // shell-history footgun that reinterprets the value as
750 // a `[foo] bar` config injection on every git porcelain
751 // entry point).
752 //
753 // POSIX `std::path::Path` treats a leading `-` as a literal
754 // filename byte, so the resolver folds `-rf` through `Path::join`
755 // and looks for a literal `./-rf` subdirectory — the failure
756 // surfaces at resolve time with a non-self-locating `No such
757 // file or directory` error far from the source caixa.lisp, and
758 // the value rides through the lacre content-address into every
759 // downstream shell-spawned subprocess. On any consumer that
760 // shells out without the `--` terminator (the common case at
761 // every porcelain entry-point) the reinterpretation is silent
762 // and the failure mode is arbitrary-argument-injection.
763 //
764 // The arm fires AFTER the absolute / tilde / var / leading-space
765 // leading-byte arms (each names the more self-locating shell-
766 // convention diagnostic on values that probe as that arm's
767 // leading-byte sentinel — the byte sets are pairwise disjoint at
768 // the leading position, so the precedence pin is a no-op at
769 // value level, but the ordering keeps every leading-byte arm's
770 // diagnostic-shape stable) and BEFORE the embedded-control-byte
771 // arm (a leading-`-` value with an embedded control byte
772 // surfaces the narrower leading-`-` diagnostic because the
773 // cascade walks leading-byte arms first — peer with how
774 // `FonteCaminhoAbsolute` precedes `FonteCaminhoControlChar` on
775 // `"/etc/passwd\n"`, and how `FonteCaminhoLeadingWhitespace`
776 // precedes `FonteCaminhoControlChar` on `" ../foo\n"`).
777 //
778 // The peer single-token-shaped axes already reject leading `-`
779 // on the same CLI-arg-injection contract:
780 // [`crate::render::is_git_repo_url`] rejects it on `:fonte :repo`
781 // (render.rs:2037), [`crate::render::is_git_ref_name`] rejects
782 // it on `:fonte :tag` / `:fonte :branch` (render.rs:1381,
783 // 5a28454), [`crate::render::is_dns_1123_label`] rejects it on
784 // every DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros
785 // :caixa`, `:children :caixa`, `:deps :nome`, cluster names),
786 // [`crate::render::is_cargo_feature_name`] rejects it on
787 // `:caracteristicas`, and the feira `init` / `add <nome>`
788 // positional gate (868c191) rejects it on the CLI positional
789 // itself. Closing the same byte on `:fonte :caminho` makes the
790 // substrate-wide "no leading `-` anywhere in a typed single-
791 // token string slot routed through a subprocess argument"
792 // invariant structurally consistent across every value-shape-
793 // gated typed surface (the `:caminho` axis was the last typed
794 // string surface still admitting a leading `-` byte).
795 if caminho.starts_with('-') {
796 return Err(DepError::fonte_caminho_leading_hyphen(nome, caminho));
797 }
798 // Reproducibility gate's embedded-control-byte arm. The
799 // b94fd83 + a5c248e + f4efe9c arms closed the three
800 // leading-byte host-layout-leak shapes (`/` / `~` / `$`);
801 // this arm closes the orthogonal embedded-control-byte
802 // axis — any ASCII control byte (`0x00..=0x1F` plus
803 // `0x7F` DEL) appearing anywhere in `:caminho`. Same
804 // shape every peer single-token-typed-slot value-shape
805 // predicate the surrounding [`crate::render`] cluster
806 // gates against (the lifted `is_git_repo_url` arm on
807 // `:fonte :repo`, the `is_git_ref_name` arm on
808 // `:tag`/`:branch`, the `is_chart_description_shape` /
809 // `is_chart_maintainer_name_shape` /
810 // `is_chart_keyword_shape` arms on the
811 // Helm-chart-shaped axes); now consistent on the
812 // `:caminho` axis too.
813 //
814 // Until this gate landed any embedded control byte
815 // silently passed validate, the lacre pipeline embedded
816 // the value verbatim in its per-dep content-address
817 // (`conteudo: format!("path:{caminho}")`,
818 // caixa-resolver/src/resolve.rs:189), and the failure
819 // forked per byte and per consumer:
820 //
821 // - NUL (`0x00`) the canonical "POSIX paths cannot
822 // contain a NUL byte" shape: every `std::fs` syscall
823 // routes the path through `CString::new`, which
824 // fails with `NulError` on the first NUL byte; the
825 // build would surface a `NulError` at resolve time
826 // far from the source caixa.lisp.
827 // - LF (`0x0A`) / CR (`0x0D`) the canonical paste-from-
828 // multiline-doc footgun: a `:caminho
829 // "../caixa-teia\nrm -rf /"` value (paste landed mid-
830 // `:caminho` block from a multi-line code-fence)
831 // silently round-trips through `Path::join` but the
832 // embedded newline class is a sibling of the CRLF-at-
833 // subprocess-argument injection vector
834 // `is_git_repo_url` already closes on `:repo`.
835 // - Tab (`0x09`) the canonical paste-from-aligned-table
836 // footgun: the tab is invisible in most editors, and
837 // the lacre embeds the value verbatim so two
838 // paste-from-distinct-tables yield divergent lacres
839 // across host editors that strip vs preserve tabs.
840 // - DEL (`0x7F`) + every other `0x00..=0x1F` byte: the
841 // paste-from-binary-blob shape every peer single-
842 // token-shaped slot rejects under the same
843 // `b < 0x20 || b == 0x7F` predicate.
844 //
845 // Mirrors the cascade discipline every prior `:caminho`
846 // arm establishes: `FonteCaminhoEmpty` →
847 // `FonteCaminhoAbsolute` → `FonteCaminhoTildeExpansion`
848 // → `FonteCaminhoVarExpansion` →
849 // `FonteCaminhoLeadingWhitespace` →
850 // `FonteCaminhoLeadingHyphen` → `FonteCaminhoControlChar`.
851 // The six leading-byte arms structurally precede the
852 // embedded-byte arm because the leading-byte shapes are
853 // the more self-locating diagnostic on values that probe
854 // as both (e.g. `:caminho "/etc/passwd\n"` surfaces the
855 // narrower `FonteCaminhoAbsolute` rather than the broader
856 // embedded-control-byte arm); the precedence pin matters
857 // at the diagnostic-shape level even though the empty /
858 // absolute / tilde / var arms are value-disjoint from a
859 // bare control byte (which would itself be a leading
860 // byte under the empty / absolute / tilde / var arms'
861 // leading-position semantics, but those arms guard the
862 // specific shell-convention characters `/` / `~` / `$`
863 // — a leading `0x01` byte falls through to this arm).
864 for &b in caminho.as_bytes() {
865 if b < 0x20 || b == 0x7F {
866 return Err(DepError::FonteCaminhoControlChar {
867 nome: nome.to_string(),
868 caminho: caminho.to_string(),
869 byte: b,
870 });
871 }
872 }
873 // Reproducibility gate's Windows-path-separator arm. The four
874 // leading-byte arms (`/` / `~` / `$`) and the embedded-
875 // control-byte arm close the host-layout-leaking + paste-from-
876 // multiline-doc shapes; the leading-`\` / embedded-`\` byte is
877 // the orthogonal cross-host-OS-separator shape — same render-
878 // determinism axis, different semantic mechanism. POSIX
879 // [`std::path::Path`] treats `\` (0x5C) as a literal byte
880 // inside a single path component (so `..\caixa-teia` is one
881 // directory named literally `..\caixa-teia`, sibling of `.`
882 // and `..`); Windows [`std::path::Path`] treats `\` as a
883 // primary path separator equal to `/` (so `..\caixa-teia` is
884 // the parent's sibling directory `caixa-teia`). The lacre
885 // pipeline embeds the value verbatim in its per-dep content-
886 // address (`conteudo: format!("path:{caminho}")`, caixa-
887 // resolver/src/resolve.rs:189), so byte-identical caixa.lisp
888 // values resolve to two distinct directories across runner
889 // OSes — the same THEORY.md §V.2 render-determinism contract
890 // the absolute / tilde / var arms protect, here against the
891 // cross-host-OS-separator divergence vector. Even on POSIX-
892 // only resolvers (the canonical pleme-io substrate posture),
893 // a `..\caixa-teia` (the Windows-Explorer "copy as path" /
894 // PowerShell `Get-Location` paste-idiom footgun) silently
895 // passes every prior arm because `Path::is_absolute` returns
896 // false on `..` and `\` is neither a leading-byte sentinel
897 // nor a control byte, then the resolver folds the value
898 // through `Path::new(caminho).join(<file>)` looking for a
899 // literal `./..\caixa-teia` subdirectory and fails at
900 // resolve time with a non-self-locating `No such file or
901 // directory` error far from the source caixa.lisp.
902 //
903 // The peer single-token-shaped axes on the same git-CLI /
904 // path-CLI consumer cluster already reject `\` under the same
905 // Windows-path-leak banner: [`crate::render::is_git_ref_name`]
906 // line 1441 (`"must not contain \\ … the canonical Windows-
907 // path-leak footgun; use / for hierarchical refs"`) gates
908 // `:fonte :tag` / `:fonte :branch` against the same byte,
909 // and [`crate::render::is_gateway_api_http_path`] line 506
910 // includes `\` in the eleven-byte RFC-3986-reserved rejection
911 // set on `:entrada :paths`. Closing the same byte on `:fonte
912 // :caminho` makes the substrate-wide "no Windows path
913 // separator anywhere in a typed string slot" invariant
914 // structurally consistent across every path-shaped typed
915 // surface (the `:caminho` axis was the last typed string
916 // surface still admitting `\`).
917 //
918 // The arm fires AFTER the control-char arm because the
919 // control-char diagnostic is the more self-locating axis on
920 // values that probe as both (`"..\caixa\0teia"` carries both
921 // a `\` and a NUL — NUL is the load-bearing POSIX-syscall-
922 // rejected byte, so `FonteCaminhoControlChar` wins). Same
923 // narrower-diagnostic-first cascade discipline every prior
924 // arm establishes. A pure-`\` value
925 // (`"..\caixa-teia"` with no control bytes) falls through
926 // every prior arm and lands here.
927 for &b in caminho.as_bytes() {
928 if b == b'\\' {
929 return Err(DepError::fonte_caminho_backslash(nome, caminho));
930 }
931 }
932 // Reproducibility gate's shell-redirection arm. The 3a4e1d7 backslash
933 // arm closes the cross-host-OS-separator vector; `<` (`0x3C`) and `>`
934 // (`0x3E`) are the orthogonal shell-redirection sentinels — same
935 // paste-from-shell-prompt footgun class, different syntactic surface.
936 // POSIX `std::path::Path` treats `<` / `>` as literal bytes inside a
937 // single path component (so `../caixa-teia>output` is one directory
938 // named literally `../caixa-teia>output`, sibling of `.` and `..`),
939 // but every interactive shell (bash / zsh / fish / nushell) lexes
940 // `<` / `>` as input / output redirection operators — a `:caminho
941 // "../caixa-teia>build.log"` (the canonical "I pasted a shell
942 // pipeline that wrote build output and forgot to trim the redirect"
943 // footgun) or `:caminho "../<input.lisp"` (the symmetric input-
944 // redirection paste idiom) silently passes every prior arm because
945 // `Path::is_absolute` returns false, `<` / `>` are neither leading-
946 // byte sentinels nor control bytes nor `\`, and the value's last byte
947 // isn't `/`. The resolver folds the value through
948 // `Path::new(caminho).join(<file>)` looking for a literal
949 // `./..\caixa-teia>build.log` subdirectory and fails at resolve time
950 // with a non-self-locating `No such file or directory` error far
951 // from the source caixa.lisp.
952 //
953 // The lacre pipeline embeds the value verbatim in its per-dep
954 // content-address (`conteudo: format!("path:{caminho}")`,
955 // caixa-resolver/src/resolve.rs:189), so a `<` / `>` byte lands in
956 // the BLAKE3 closure and rides downstream as part of the build's
957 // identity. The bytes carry a second class of hazard the prior
958 // separator-shaped arms don't: every typed-string slot whose value
959 // ever flows verbatim into a shell-spawned subprocess (the caixa-
960 // resolver's `git clone` invocation, a future `feira tofu` shell-
961 // out, a future operator-side `nix flake check` spawn) is the
962 // canonical CRLF-at-subprocess-argument / shell-metachar injection
963 // surface that every peer single-token-shaped typed slot already
964 // closes. The peer path-shaped axis `[crate::render::is_gateway_api_http_path]`
965 // (caixa-core/src/render.rs:506) rejects `<` / `>` as part of its
966 // eleven-byte RFC-3986-reserved set on `:entrada :paths`, and the
967 // peer git-ref-shaped axis `[crate::render::is_git_ref_name]` rejects
968 // `<` / `>` on `:fonte :tag` / `:fonte :branch` under the same
969 // shell-metachar-injection banner. The `:caminho` axis was the last
970 // typed string surface still admitting these two bytes; this arm
971 // closes the gap so the substrate-wide "no shell-redirection
972 // metacharacter anywhere in a typed string slot" invariant is now
973 // structurally consistent across every path-shaped typed surface.
974 //
975 // The arm fires AFTER the control-char arm + backslash arm because
976 // both prior arms carry more self-locating diagnostics on values
977 // that probe as both (`"..\foo<bar"` carries both `\` and `<` — the
978 // cross-OS-separator divergence is the load-bearing axis, so the
979 // backslash arm wins; `"../foo\n<bar"` carries both LF and `<` —
980 // the POSIX-syscall-rejected byte is the load-bearing axis, so the
981 // control-char arm wins). The arm fires BEFORE the trailing-`/` arm
982 // because the embedded redirection byte is the more semantic-
983 // locating axis on probe-as-both values (`"../foo</"` ends in `/`
984 // but the load-bearing diagnostic is the embedded `<` shell-
985 // redirection — the trailing `/` is the secondary observation, and
986 // an author who removes the `<` is likely to also tab-strip the
987 // trailing separator).
988 for &b in caminho.as_bytes() {
989 if b == b'<' || b == b'>' {
990 return Err(DepError::FonteCaminhoShellRedirection {
991 nome: nome.to_string(),
992 caminho: caminho.to_string(),
993 byte: b,
994 });
995 }
996 }
997 // Reproducibility gate's shell-pipe arm. The e457141 shell-redirection
998 // arm closes the `<` / `>` input/output redirection sentinels; `|`
999 // (`0x7C`) is the orthogonal shell-pipe sentinel — same paste-from-
1000 // shell-prompt footgun class, different syntactic surface. POSIX
1001 // `std::path::Path` treats `|` as a literal path-component byte (so
1002 // `../caixa-teia|tee` is one directory named literally
1003 // `../caixa-teia|tee`, sibling of `.` and `..`), but every interactive
1004 // shell (bash / zsh / fish / nushell) lexes `|` as the pipe operator
1005 // — a `:caminho "../caixa-teia | grep foo"` (the canonical "I copied a
1006 // `ls ../caixa-teia | grep` line out of a shell-history block and
1007 // forgot to trim the pipeline tail" footgun) or `:caminho
1008 // "../foo||bar"` (the symmetric "I copied a `cmd-a || cmd-b` short-
1009 // circuit OR line" idiom) silently passes every prior arm because
1010 // `Path::is_absolute` returns false on `..`, `|` is neither a leading-
1011 // byte sentinel nor a control byte nor `\` nor `<` / `>`, and the
1012 // value's last byte isn't `/`. The resolver folds the value through
1013 // `Path::new(caminho).join(<file>)` looking for a literal
1014 // `./../caixa-teia | grep foo` subdirectory and fails at resolve time
1015 // with a non-self-locating `No such file or directory` error far
1016 // from the source caixa.lisp.
1017 //
1018 // The lacre pipeline embeds the value verbatim in its per-dep
1019 // content-address (`conteudo: format!("path:{caminho}")`,
1020 // caixa-resolver/src/resolve.rs:189), so a `|` byte lands in the
1021 // BLAKE3 closure and rides downstream as part of the build's identity
1022 // into every shell-spawned subprocess (the caixa-resolver's `git
1023 // clone` invocation, a future `feira tofu` shell-out, a future
1024 // operator-side `nix flake check` spawn) as the canonical CRLF-at-
1025 // subprocess-argument / shell-metachar injection surface every peer
1026 // single-token-shaped typed slot already closes. The peer path-shaped
1027 // axis [`crate::render::is_gateway_api_http_path`]
1028 // (caixa-core/src/render.rs:506) rejects `|` as part of its eleven-
1029 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1030 // axis was the last typed path-string surface still admitting this
1031 // byte; this arm closes the gap so the substrate-wide "no shell-
1032 // composition metacharacter anywhere in a typed string slot that
1033 // flows verbatim into a shell-spawned subprocess" invariant extends
1034 // from shell-redirection (`<` / `>`) to shell-pipe (`|`) on the
1035 // `:caminho` axis.
1036 //
1037 // The arm fires AFTER the shell-redirection arm because the prior
1038 // arm's two-byte `byte: u8` payload is the more self-locating axis on
1039 // values that probe as both (`"../caixa-teia<input|tee"` carries both
1040 // `<` and `|` — the input-redirection-paste idiom is the load-bearing
1041 // root-cause edit, so `FonteCaminhoShellRedirection` wins; same
1042 // cascade discipline every prior `:caminho` arm establishes). The arm
1043 // fires BEFORE the trailing-`/` arm because the embedded pipe byte is
1044 // the more semantic-locating axis on probe-as-both values
1045 // (`"../foo|tee/"` ends in `/` but the load-bearing diagnostic is the
1046 // embedded `|` shell-pipe — the trailing `/` is the secondary
1047 // observation, and an author who removes the `|` is likely to also
1048 // tab-strip the trailing separator).
1049 for &b in caminho.as_bytes() {
1050 if b == b'|' {
1051 return Err(DepError::fonte_caminho_shell_pipe(nome, caminho));
1052 }
1053 }
1054 // Reproducibility gate's shell-command-separator arm. The 124106f
1055 // shell-pipe arm closes the `|` byte; `;` (`0x3B`) is the orthogonal
1056 // shell-command-separator sentinel — same paste-from-shell-prompt
1057 // footgun class, different syntactic surface. POSIX `std::path::Path`
1058 // treats `;` as a literal path-component byte (so
1059 // `../caixa-teia;rm -rf /` is one directory named literally
1060 // `../caixa-teia;rm -rf /`, sibling of `.` and `..`), but every
1061 // interactive shell (bash / zsh / fish / nushell) lexes `;` as the
1062 // sequential-command terminator that fires the next command
1063 // regardless of the prior command's exit status — a `:caminho
1064 // "../caixa-teia; rm -rf build"` (the canonical "I pasted a shell
1065 // one-liner that chained a cleanup tail after the directory name"
1066 // footgun) or `:caminho "../foo;;bar"` (the symmetric "I copied a
1067 // POSIX `case` arm's `;;` terminator into the middle of a path"
1068 // idiom) silently passes every prior arm because `Path::is_absolute`
1069 // returns false on `..`, `;` is neither a leading-byte sentinel nor a
1070 // control byte nor `\` nor `<` / `>` nor `|`, and the value's last
1071 // byte isn't `/`. The resolver folds the value through
1072 // `Path::new(caminho).join(<file>)` looking for a literal
1073 // `./../caixa-teia; rm -rf build` subdirectory and fails at resolve
1074 // time with a non-self-locating `No such file or directory` error far
1075 // from the source caixa.lisp.
1076 //
1077 // The lacre pipeline embeds the value verbatim in its per-dep
1078 // content-address (`conteudo: format!("path:{caminho}")`,
1079 // caixa-resolver/src/resolve.rs:189), so a `;` byte lands in the
1080 // BLAKE3 closure and rides downstream as part of the build's identity
1081 // into every shell-spawned subprocess (the caixa-resolver's `git
1082 // clone` invocation, a future `feira tofu` shell-out, a future
1083 // operator-side `nix flake check` spawn) as the canonical
1084 // shell-metachar injection surface every peer single-token-shaped
1085 // typed slot already closes. The peer path-shaped axis
1086 // [`crate::render::is_gateway_api_http_path`]
1087 // (caixa-core/src/render.rs:506) rejects `;` as part of its eleven-
1088 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1089 // axis was the last typed path-string surface still admitting this
1090 // byte; this arm closes the gap so the substrate-wide "no shell-
1091 // composition metacharacter anywhere in a typed string slot that
1092 // flows verbatim into a shell-spawned subprocess" invariant extends
1093 // from shell-pipe (`|`) to shell-command-separator (`;`) on the
1094 // `:caminho` axis.
1095 //
1096 // The arm fires AFTER the shell-pipe arm because the prior arm's
1097 // canonical-cmd-a-|-cmd-b shape is the more common shell-history
1098 // paste idiom on values that probe as both (`"../caixa-teia | tee;
1099 // rm"` carries both `|` and `;` — the pipeline-tail paste is the
1100 // load-bearing root-cause edit, so `FonteCaminhoShellPipe` wins; same
1101 // cascade discipline every prior `:caminho` arm establishes). The arm
1102 // fires BEFORE the trailing-`/` arm because the embedded
1103 // command-separator byte is the more semantic-locating axis on
1104 // probe-as-both values (`"../foo;rm/"` ends in `/` but the
1105 // load-bearing diagnostic is the embedded `;` shell-command-
1106 // separator — the trailing `/` is the secondary observation, and an
1107 // author who removes the `;` is likely to also tab-strip the trailing
1108 // separator).
1109 for &b in caminho.as_bytes() {
1110 if b == b';' {
1111 return Err(DepError::fonte_caminho_shell_semicolon(nome, caminho));
1112 }
1113 }
1114 // Reproducibility gate's shell-background / logical-AND arm. The
1115 // 05c358e shell-command-separator arm closes the `;` byte; `&`
1116 // (`0x26`) is the orthogonal shell-background / list-AND sentinel
1117 // — same paste-from-shell-prompt footgun class, different
1118 // syntactic surface. POSIX `std::path::Path` treats `&` as a
1119 // literal path-component byte (so `../caixa-teia & sleep 1` is
1120 // one directory named literally `../caixa-teia & sleep 1`,
1121 // sibling of `.` and `..`), but every interactive shell
1122 // (bash / zsh / fish / nushell) lexes `&` two ways:
1123 //
1124 // - Single `&` as the background-task terminator that detaches
1125 // the prior command into the background and returns control
1126 // to the prompt immediately (the canonical `cmd &` idiom
1127 // every long-running pipeline uses);
1128 // - Double `&&` as the logical-AND list operator that fires
1129 // the next command only if the prior command succeeded (the
1130 // canonical `make && make install` idiom every build script
1131 // carries).
1132 //
1133 // A `:caminho "../caixa-teia & sleep 1"` (the canonical "I
1134 // pasted a `cd path & sleep 1` background-launch into the
1135 // `:caminho` slot" footgun) or `:caminho "../caixa-teia && make"`
1136 // (the symmetric "I copied a `cd path && make` build chain"
1137 // idiom) silently passes every prior arm because
1138 // `Path::is_absolute` returns false on `..`, `&` is neither a
1139 // leading-byte sentinel nor a control byte nor `\` nor
1140 // `<` / `>` nor `|` nor `;`, and the value's last byte isn't `/`.
1141 // The resolver folds the value through
1142 // `Path::new(caminho).join(<file>)` looking for a literal
1143 // `./../caixa-teia & sleep 1` subdirectory and fails at resolve
1144 // time with a non-self-locating `No such file or directory`
1145 // error far from the source caixa.lisp.
1146 //
1147 // The lacre pipeline embeds the value verbatim in its per-dep
1148 // content-address (`conteudo: format!("path:{caminho}")`,
1149 // caixa-resolver/src/resolve.rs:189), so an `&` byte lands in
1150 // the BLAKE3 closure and rides downstream as part of the build's
1151 // identity into every shell-spawned subprocess (the
1152 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1153 // shell-out, a future operator-side `nix flake check` spawn) as
1154 // the canonical shell-metachar injection surface every peer
1155 // single-token-shaped typed slot already closes. The peer
1156 // path-shaped axis [`crate::render::is_gateway_api_http_path`]
1157 // (caixa-core/src/render.rs:506) rejects `&` as part of its
1158 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1159 // `:caminho` axis was the last typed path-string surface still
1160 // admitting this byte; this arm closes the gap so the
1161 // substrate-wide "no shell-composition metacharacter anywhere
1162 // in a typed string slot that flows verbatim into a
1163 // shell-spawned subprocess" invariant extends from
1164 // shell-command-separator (`;`) to shell-background /
1165 // logical-AND (`&`) on the `:caminho` axis.
1166 //
1167 // The arm fires AFTER the shell-command-separator arm because
1168 // the prior arm's `cmd-a; cmd-b` shape is the more common
1169 // shell-history paste idiom on values that probe as both
1170 // (`"../caixa-teia; rm & sleep"` carries both `;` and `&` — the
1171 // command-separator-tail paste is the load-bearing root-cause
1172 // edit, so `FonteCaminhoShellSemicolon` wins; same cascade
1173 // discipline every prior `:caminho` arm establishes). The arm
1174 // fires BEFORE the trailing-`/` arm because the embedded
1175 // background / list-AND byte is the more semantic-locating axis
1176 // on probe-as-both values (`"../foo&bar/"` ends in `/` but the
1177 // load-bearing diagnostic is the embedded `&` shell-background
1178 // / logical-AND metachar — the trailing `/` is the secondary
1179 // observation, and an author who removes the `&` is likely to
1180 // also tab-strip the trailing separator).
1181 for &b in caminho.as_bytes() {
1182 if b == b'&' {
1183 return Err(DepError::fonte_caminho_shell_background(nome, caminho));
1184 }
1185 }
1186 // Reproducibility gate's shell-command-substitution arm. The
1187 // e12e4f3 shell-background / logical-AND arm closes the `&`
1188 // byte; the backtick (`0x60`) is the orthogonal POSIX legacy
1189 // command-substitution sentinel — every POSIX shell (sh /
1190 // bash / zsh / dash / ksh / fish / nushell) lexes the byte as
1191 // the canonical legacy wrapper that runs the enclosed command
1192 // and substitutes its standard-output verbatim into the
1193 // surrounding word (a `whoami` wrapped in backticks expands
1194 // to the current user's name; a `cat /etc/passwd` wrapped in
1195 // backticks expands to the file's contents — the canonical
1196 // CWE-78 shell-command-injection vector every shell-side
1197 // hardening guide enumerates first). POSIX
1198 // `std::path::Path` treats backtick as a literal path-
1199 // component byte (so `../caixa-teia/<backtick>whoami<backtick>`
1200 // is one directory named literally that, sibling of `.` and
1201 // `..`).
1202 //
1203 // A `:caminho "../caixa-teia/<backtick>whoami<backtick>"` (the
1204 // canonical "I pasted a shell one-liner carrying a backticked
1205 // `whoami` command-substitution expansion into the `:caminho`
1206 // slot" footgun) or `:caminho "<backtick>pwd<backtick>/caixa-
1207 // teia"` (the symmetric "I copied a `<backtick>pwd<backtick>/
1208 // path` working-directory expansion") silently passes every
1209 // prior arm because `Path::is_absolute` returns false on
1210 // `..`, the backtick byte is neither a leading-byte sentinel
1211 // (the f4efe9c `FonteCaminhoVarExpansion` arm catches the
1212 // modern `$()` form at leading position only; backtick is
1213 // the orthogonal legacy form) nor a control byte nor `\` nor
1214 // `<` / `>` nor `|` nor `;` nor `&`, and the value's last
1215 // byte isn't `/`. The resolver folds the value through
1216 // `Path::new(caminho).join(<file>)` looking for a literal
1217 // subdirectory whose name embeds the backticked token and
1218 // fails at resolve time with a non-self-locating `No such
1219 // file or directory` error far from the source caixa.lisp.
1220 //
1221 // The lacre pipeline embeds the value verbatim in its per-
1222 // dep content-address (`conteudo: format!("path:{caminho}")`,
1223 // caixa-resolver/src/resolve.rs:189), so a backtick byte
1224 // lands in the BLAKE3 closure and rides downstream as part
1225 // of the build's identity into every shell-spawned
1226 // subprocess (the caixa-resolver's `git clone` invocation, a
1227 // future `feira tofu` shell-out, a future operator-side
1228 // `nix flake check` spawn) as the canonical shell-metachar
1229 // injection surface every peer single-token-shaped typed
1230 // slot already closes. The peer path-shaped axis
1231 // [`crate::render::is_gateway_api_http_path`]
1232 // (caixa-core/src/render.rs:506) rejects backtick as part of
1233 // its eleven-byte RFC-3986-reserved set on `:entrada
1234 // :paths`. The `:caminho` axis was the last typed path-
1235 // string surface still admitting this byte; this arm closes
1236 // the gap so the substrate-wide "no shell-composition
1237 // metacharacter anywhere in a typed string slot that flows
1238 // verbatim into a shell-spawned subprocess" invariant
1239 // extends from shell-background / logical-AND (`&`) to
1240 // shell-command-substitution (backtick) on the `:caminho`
1241 // axis.
1242 //
1243 // The arm fires AFTER the shell-background arm because the
1244 // prior arm's `cmd & sleep` shape is the more common shell-
1245 // history paste idiom on values that probe as both (a
1246 // `"../caixa-teia & <backtick>whoami<backtick>"` carries
1247 // both `&` and a backtick — the background-launch tail is
1248 // the load-bearing root-cause edit, so
1249 // `FonteCaminhoShellBackground` wins; same cascade
1250 // discipline every prior `:caminho` arm establishes). The
1251 // arm fires BEFORE the trailing-`/` arm because the
1252 // embedded command-substitution byte is the more semantic-
1253 // locating axis on probe-as-both values (a
1254 // `"../<backtick>whoami<backtick>/"` ends in `/` but the
1255 // load-bearing diagnostic is the embedded backtick shell-
1256 // command-substitution metachar — the trailing `/` is the
1257 // secondary observation, and an author who removes the
1258 // backtick is likely to also tab-strip the trailing
1259 // separator).
1260 for &b in caminho.as_bytes() {
1261 if b == b'`' {
1262 return Err(DepError::fonte_caminho_shell_command_substitution(
1263 nome, caminho,
1264 ));
1265 }
1266 }
1267 // Reproducibility gate's shell-glob arm. The c4d62b3 shell-command-
1268 // substitution arm closes the backtick byte; `*` (`0x2A`) and `?`
1269 // (`0x3F`) are the orthogonal POSIX glob-expansion sentinels — same
1270 // paste-from-shell-prompt footgun class, different syntactic surface.
1271 // Every POSIX shell (sh / bash / zsh / dash / ksh / fish / nushell)
1272 // lexes `*` and `?` as pathname-expansion wildcards: `*` matches any
1273 // sequence of characters in a path component (including the empty
1274 // sequence), `?` matches exactly one character. POSIX
1275 // `std::path::Path` treats both bytes as literal path-component bytes
1276 // (so `../caixa-teia/*.lisp` is one directory named literally
1277 // `../caixa-teia/*.lisp`, sibling of `.` and `..`).
1278 //
1279 // A `:caminho "../caixa-teia/*"` (the canonical "I pasted a
1280 // `ls ../caixa-teia/*` shell-listing one-liner into the `:caminho`
1281 // slot" footgun) or `:caminho "../foo?"` (the symmetric "I copied a
1282 // `rm foo?` single-char-wildcard removal idiom") silently passes
1283 // every prior arm because `Path::is_absolute` returns false on `..`,
1284 // `*` / `?` are neither leading-byte sentinels nor control bytes nor
1285 // `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick, and the
1286 // value's last byte isn't `/`. The resolver folds the value through
1287 // `Path::new(caminho).join(<file>)` looking for a literal
1288 // `./../caixa-teia/*` subdirectory and fails at resolve time with a
1289 // non-self-locating `No such file or directory` error far from the
1290 // source caixa.lisp.
1291 //
1292 // The lacre pipeline embeds the value verbatim in its per-dep
1293 // content-address (`conteudo: format!("path:{caminho}")`,
1294 // caixa-resolver/src/resolve.rs:189), so a `*` or `?` byte lands in
1295 // the BLAKE3 closure and rides downstream as part of the build's
1296 // identity into every shell-spawned subprocess (the caixa-resolver's
1297 // `git clone` invocation, a future `feira tofu` shell-out, a future
1298 // operator-side `nix flake check` spawn) as the canonical
1299 // shell-metachar / pathname-expansion surface every peer
1300 // single-token-shaped typed slot already closes. The peer path-shaped
1301 // axis [`crate::render::is_gateway_api_http_path`]
1302 // (caixa-core/src/render.rs:506) rejects `*` and `?` as part of its
1303 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1304 // `:caminho` axis was the last typed path-string surface still
1305 // admitting these two bytes; this arm closes the gap so the
1306 // substrate-wide "no shell-composition / glob-expansion
1307 // metacharacter anywhere in a typed string slot that flows verbatim
1308 // into a shell-spawned subprocess" invariant extends from
1309 // shell-command-substitution (backtick) to glob-expansion
1310 // (`*` / `?`) on the `:caminho` axis.
1311 //
1312 // The arm fires AFTER the backtick arm because the prior arm's
1313 // CWE-78 shell-command-injection vector is the load-bearing
1314 // diagnostic on values that probe as both (a `"../`whoami`/*"`
1315 // carries both backtick and `*` — the command-substitution paste
1316 // is the load-bearing root-cause edit, so
1317 // `FonteCaminhoShellCommandSubstitution` wins; same cascade
1318 // discipline every prior `:caminho` arm establishes). The arm
1319 // fires BEFORE the trailing-`/` arm because the embedded glob
1320 // byte is the more semantic-locating axis on probe-as-both values
1321 // (`"../foo*/"` ends in `/` but the load-bearing diagnostic is the
1322 // embedded `*` glob metachar — the trailing `/` is the secondary
1323 // observation, and an author who removes the `*` is likely to
1324 // also tab-strip the trailing separator).
1325 for &b in caminho.as_bytes() {
1326 if b == b'*' || b == b'?' {
1327 return Err(DepError::FonteCaminhoShellGlob {
1328 nome: nome.to_string(),
1329 caminho: caminho.to_string(),
1330 byte: b,
1331 });
1332 }
1333 }
1334 // Reproducibility gate's shell-subshell-grouping arm. The cf9034b
1335 // shell-glob arm closes the `*` / `?` pathname-expansion sentinels;
1336 // `(` (`0x28`) and `)` (`0x29`) are the orthogonal POSIX subshell-
1337 // grouping sentinels — same paste-from-shell-prompt footgun class,
1338 // different syntactic surface. Every POSIX shell (sh / bash / zsh /
1339 // dash / ksh / fish / nushell) lexes the parenthesis pair as the
1340 // subshell-grouping operator: `(<cmd>)` runs `<cmd>` in a child
1341 // shell with a fresh environment scope (the canonical sandboxing
1342 // idiom every shell-history `(cd <path> && <cmd>)` one-liner uses
1343 // to scope a `cd` to one subshell without disturbing the parent's
1344 // working directory), and `$(<cmd>)` is the modern Bourne
1345 // command-substitution shape the upstream f4efe9c
1346 // `FonteCaminhoVarExpansion` arm closes the leading `$` byte of —
1347 // the closing `)` byte completes that substitution shape and must
1348 // be refused on the same axis (peer with the
1349 // [`crate::render::is_git_repo_url`] 3b99147 arm that closes the
1350 // same byte-pair on the sibling `:fonte :repo` axis under the
1351 // same shell-subshell-grouping + RFC-3986-sub-delims banner).
1352 // POSIX `std::path::Path` treats both bytes as literal path-
1353 // component bytes (so `../caixa-teia/(date)` is one directory
1354 // named literally `../caixa-teia/(date)`, sibling of `.` and
1355 // `..`).
1356 //
1357 // A `:caminho "../caixa-teia/$(date)/build"` (the canonical "I
1358 // pasted a `cd ../caixa-teia/$(date)/build` shell-history one-
1359 // liner whose modern command-substitution expansion lands the
1360 // current date as a subdirectory name" footgun) or `:caminho
1361 // "../(cd foo && pwd)/caixa-teia"` (the symmetric "I copied a
1362 // `(cd foo && pwd)` subshell-grouping working-directory probe
1363 // idiom") silently passes every prior arm because
1364 // `Path::is_absolute` returns false on `..`, `(` / `)` are
1365 // neither leading-byte sentinels nor control bytes nor `\` nor
1366 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` / `?`,
1367 // and the value's last byte isn't `/`. The resolver folds the
1368 // value through `Path::new(caminho).join(<file>)` looking for a
1369 // literal `./../caixa-teia/$(date)/build` subdirectory and fails
1370 // at resolve time with a non-self-locating `No such file or
1371 // directory` error far from the source caixa.lisp.
1372 //
1373 // The lacre pipeline embeds the value verbatim in its per-dep
1374 // content-address (`conteudo: format!("path:{caminho}")`,
1375 // caixa-resolver/src/resolve.rs:189), so a `(` or `)` byte lands
1376 // in the BLAKE3 closure and rides downstream as part of the
1377 // build's identity into every shell-spawned subprocess (the
1378 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1379 // shell-out, a future operator-side `nix flake check` spawn) as
1380 // the canonical shell-metachar / subshell-grouping surface every
1381 // peer single-token-shaped typed slot already closes. The peer
1382 // git-source axis [`crate::render::is_git_repo_url`] (3b99147)
1383 // rejects the same byte pair on `:fonte :repo` under the same
1384 // shell-subshell-grouping / RFC-3986-sub-delims banner. The
1385 // `:caminho` axis was the last typed path-string surface still
1386 // admitting these two bytes;
1387 // this arm closes the gap so the substrate-wide "no shell-
1388 // composition metacharacter anywhere in a typed string slot that
1389 // flows verbatim into a shell-spawned subprocess" invariant
1390 // extends from shell-glob (`*` / `?`) to shell-subshell-grouping
1391 // (`(` / `)`) on the `:caminho` axis. Together with the f4efe9c
1392 // leading-`$` arm, the typed `:caminho` accepted set now
1393 // structurally excludes the entire modern Bourne
1394 // command-substitution surface — leading `$` closes the
1395 // leading byte of every `$(<cmd>)` shape, this arm closes the
1396 // trailing `)` boundary.
1397 //
1398 // The arm fires AFTER the shell-glob arm because the prior arm's
1399 // `*` / `?` pathname-expansion shape is the more common shell-
1400 // history paste idiom on values that probe as both
1401 // (`"../caixa-teia/*(date)"` carries both `*` and `(` — the
1402 // glob-paste-tail is the load-bearing root-cause edit, so
1403 // `FonteCaminhoShellGlob` wins; same cascade discipline every
1404 // prior `:caminho` arm establishes). The arm fires BEFORE the
1405 // trailing-`/` arm because the embedded subshell-grouping byte
1406 // is the more semantic-locating axis on probe-as-both values
1407 // (`"../foo(date)/"` ends in `/` but the load-bearing diagnostic
1408 // is the embedded `(` shell-subshell-grouping metachar — the
1409 // trailing `/` is the secondary observation, and an author who
1410 // removes the `(` is likely to also tab-strip the trailing
1411 // separator).
1412 for &b in caminho.as_bytes() {
1413 if b == b'(' || b == b')' {
1414 return Err(DepError::FonteCaminhoShellSubshellGrouping {
1415 nome: nome.to_string(),
1416 caminho: caminho.to_string(),
1417 byte: b,
1418 });
1419 }
1420 }
1421 // Reproducibility gate's shell-brace-expansion arm. The 0633c91
1422 // shell-subshell-grouping arm closes `(` / `)`; `{` (`0x7b`) and
1423 // `}` (`0x7d`) are the orthogonal shell-brace-expansion /
1424 // URI-Template-placeholder byte pair — same paste-from-shell-
1425 // prompt + paste-from-templated-doc footgun class, different
1426 // syntactic surface. Every POSIX-derived shell that implements
1427 // brace expansion (bash / zsh / ksh / fish; the canonical
1428 // `mkdir -p ../{caixa-teia,caixa-helm,caixa-flux}` /
1429 // `cp file{,.bak}` idiom every shell-history block carries)
1430 // expands `{a,b,c}` to the cross-product of its comma-separated
1431 // members and `{1..10}` to the integer range; RFC 6570 reserves
1432 // the matched pair for URI Template placeholders (the canonical
1433 // `https://{host}/{org}/{repo}` substitution shape every
1434 // OpenAPI / Swagger / Postman / GitHub Octokit client /
1435 // Helm chart-URL fragment / Mustache `{{org}}` doubled-brace
1436 // form carries), and Tera / Jinja2 / Handlebars / Go html/template
1437 // every IaC tool (Helm, Kustomize, Terraform's `${var}` cousin
1438 // shape) emit. POSIX `std::path::Path` treats both bytes as
1439 // literal path-component bytes (so `../{caixa-teia,caixa-helm}`
1440 // is one directory named literally `../{caixa-teia,caixa-helm}`,
1441 // sibling of `.` and `..`).
1442 //
1443 // A `:caminho "../{caixa-teia,caixa-helm}/build"` (the canonical
1444 // "I pasted a `cd ../{caixa-teia,caixa-helm}` shell brace-
1445 // expansion one-liner that fans across two siblings" footgun)
1446 // or `:caminho "../{{org}}/caixa-teia"` (the symmetric "I copied
1447 // a `{{org}}` Mustache / Helm template placeholder out of a
1448 // README quick-start and forgot to substitute") silently passes
1449 // every prior arm because `Path::is_absolute` returns false on
1450 // `..`, `{` / `}` are neither leading-byte sentinels nor control
1451 // bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor
1452 // backtick nor `*` / `?` nor `(` / `)`, and the value's last
1453 // byte isn't `/`. The resolver folds the value through
1454 // `Path::new(caminho).join(<file>)` looking for a literal
1455 // `./../{caixa-teia,caixa-helm}/build` subdirectory and fails
1456 // at resolve time with a non-self-locating `No such file or
1457 // directory` error far from the source caixa.lisp.
1458 //
1459 // The lacre pipeline embeds the value verbatim in its per-dep
1460 // content-address (`conteudo: format!("path:{caminho}")`,
1461 // caixa-resolver/src/resolve.rs:189), so a `{` or `}` byte
1462 // lands in the BLAKE3 closure and rides downstream as part of
1463 // the build's identity into every shell-spawned subprocess
1464 // (the caixa-resolver's `git clone` invocation, a future
1465 // `feira tofu` shell-out, a future operator-side `nix flake
1466 // check` spawn) as the canonical shell-metachar / brace-
1467 // expansion surface every peer single-token-shaped typed
1468 // slot already closes. The peer git-source axis
1469 // [`crate::render::is_git_repo_url`] (42d8f9d — the URI Template
1470 // placeholder arm) rejects the same byte pair on `:fonte :repo`
1471 // under the same RFC-3986-'delims' / RFC-6570-URI-Template /
1472 // shell-brace-expansion banner. The `:caminho` axis was the last
1473 // typed path-string surface still admitting these two bytes;
1474 // this arm closes the gap so the substrate-wide "no shell-
1475 // composition metacharacter anywhere in a typed string slot
1476 // that flows verbatim into a shell-spawned subprocess"
1477 // invariant extends from shell-subshell-grouping (`(` / `)`)
1478 // to shell-brace-expansion (`{` / `}`) on the `:caminho` axis,
1479 // and the typed `:caminho` accepted set now also structurally
1480 // excludes the URI Template / templating-engine placeholder
1481 // surface that would silently round-trip through any
1482 // downstream IaC templating-engine layer.
1483 //
1484 // The arm fires AFTER the shell-subshell-grouping arm because
1485 // the prior arm's `(` / `)` shape is the more semantic-locating
1486 // axis on values that probe as both (`"../{cd foo}(date)"`
1487 // carries both `{` and `(` — the parenthesis-pair is the
1488 // load-bearing modern-Bourne-command-substitution surface the
1489 // prior arm closes; same cascade discipline every prior
1490 // `:caminho` arm establishes). The arm fires BEFORE the
1491 // trailing-`/` arm because the embedded brace-expansion byte
1492 // is the more semantic-locating axis on probe-as-both values
1493 // (`"../{caixa-teia,caixa-helm}/"` ends in `/` but the
1494 // load-bearing diagnostic is the embedded `{` brace-expansion
1495 // metachar — the trailing `/` is the secondary observation,
1496 // and an author who removes the `{` is likely to also tab-
1497 // strip the trailing separator).
1498 for &b in caminho.as_bytes() {
1499 if b == b'{' || b == b'}' {
1500 return Err(DepError::FonteCaminhoShellBraceExpansion {
1501 nome: nome.to_string(),
1502 caminho: caminho.to_string(),
1503 byte: b,
1504 });
1505 }
1506 }
1507 // Reproducibility gate's shell-bracket-expansion arm. The 598b770
1508 // shell-brace-expansion arm closes `{` / `}`; `[` (`0x5b`) and
1509 // `]` (`0x5d`) are the orthogonal POSIX glob-character-class /
1510 // shell-`test`-builtin byte pair — same paste-from-shell-prompt
1511 // footgun class, different syntactic surface. Every POSIX shell
1512 // (sh / bash / zsh / dash / ksh / fish / nushell) lexes the
1513 // bracket pair as the glob character-class operator: `[abc]`
1514 // matches one of `a`, `b`, `c`; `[a-z]` matches any lowercase
1515 // ASCII letter; `[^x]` negates (the canonical
1516 // `ls *.[ch]` C-source-file glob and the `cd ../[a-z]*`
1517 // lowercase-sibling glob every shell-history block carries —
1518 // the orthogonal axis to the cf9034b `*` / `?` shell-glob arm
1519 // closing the unbounded pathname-expansion sentinels). The
1520 // bracket pair additionally carries the POSIX `test` /
1521 // `[` builtin command (`[ -d ../caixa-teia ] && cd ...` —
1522 // the canonical idiom every shell-script conditional uses) and
1523 // bash's `[[ ... ]]` extended-test grammar. Beyond shell, the
1524 // bracket pair is the TOML inline-array delimiter
1525 // (`features = ["a", "b"]` — the canonical paste-from-Cargo-
1526 // manifest cross-idiom-leak vector), the YAML flow-sequence
1527 // delimiter (`paths: [/a, /b]` — the canonical paste-from-
1528 // values.yaml cross-idiom leak), the JSON array delimiter,
1529 // and the POSIX-ERE / PCRE bracket-expression / character-
1530 // class anchor (the canonical paste-from-regex-doc shape).
1531 // POSIX `std::path::Path` treats both bytes as literal path-
1532 // component bytes (so `../[caixa-teia]` is one directory
1533 // named literally `../[caixa-teia]`, sibling of `.` and
1534 // `..`).
1535 //
1536 // A `:caminho "../caixa-[a-z]/build"` (the canonical "I
1537 // pasted a `cd ../caixa-[a-z]/build` glob-character-class
1538 // one-liner that matches every lowercase-sibling-suffix
1539 // sibling directory" footgun), `:caminho "../[caixa-teia]/
1540 // build"` (the symmetric "I pasted a TOML inline-array /
1541 // YAML flow-sequence shape out of an aligned manifest"
1542 // idiom), or `:caminho "../caixa-[ch]"` (the canonical
1543 // `*.[ch]` C-source character-class paste-from-shell-history
1544 // shape) silently passes every prior arm because
1545 // `Path::is_absolute` returns false on `..`, `[` / `]` are
1546 // neither leading-byte sentinels nor control bytes nor `\`
1547 // nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1548 // `*` / `?` nor `(` / `)` nor `{` / `}`, and the value's
1549 // last byte isn't `/`. The resolver folds the value through
1550 // `Path::new(caminho).join(<file>)` looking for a literal
1551 // `./../caixa-[a-z]/build` subdirectory and fails at resolve
1552 // time with a non-self-locating `No such file or directory`
1553 // error far from the source caixa.lisp.
1554 //
1555 // The lacre pipeline embeds the value verbatim in its per-dep
1556 // content-address (`conteudo: format!("path:{caminho}")`,
1557 // caixa-resolver/src/resolve.rs:189), so a `[` or `]` byte
1558 // lands in the BLAKE3 closure and rides downstream as part of
1559 // the build's identity into every shell-spawned subprocess
1560 // (the caixa-resolver's `git clone` invocation, a future
1561 // `feira tofu` shell-out, a future operator-side `nix flake
1562 // check` spawn) as the canonical shell-metachar / glob-
1563 // character-class / TOML-array surface every peer single-
1564 // token-shaped typed slot already closes. The `:caminho` axis
1565 // was the last typed path-string surface still admitting
1566 // these two bytes; this arm closes the gap so the substrate-
1567 // wide "no shell-composition metacharacter anywhere in a
1568 // typed string slot that flows verbatim into a shell-spawned
1569 // subprocess" invariant extends from shell-brace-expansion
1570 // (`{` / `}`) to shell-bracket-expansion (`[` / `]`) on the
1571 // `:caminho` axis. Together with the cf9034b `*` / `?` arm,
1572 // the typed `:caminho` accepted set now structurally excludes
1573 // the entire POSIX pathname-expansion / glob surface —
1574 // unbounded glob (`*` / `?`) AND bounded character-class
1575 // (`[abc]` / `[a-z]`).
1576 //
1577 // The arm fires AFTER the shell-brace-expansion arm because
1578 // the prior arm's `{` / `}` shape is the more semantic-
1579 // locating axis on values that probe as both
1580 // (`"../{a,b}[ch]"` carries both `{` and `[` — the brace-
1581 // expansion fan is the load-bearing root-cause edit, so
1582 // `FonteCaminhoShellBraceExpansion` wins; same cascade
1583 // discipline every prior `:caminho` arm establishes). The arm
1584 // fires BEFORE the trailing-`/` arm because the embedded
1585 // bracket-expansion byte is the more semantic-locating axis
1586 // on probe-as-both values (`"../[a-z]/"` ends in `/` but the
1587 // load-bearing diagnostic is the embedded `[` glob-character-
1588 // class metachar — the trailing `/` is the secondary
1589 // observation, and an author who removes the `[` is likely
1590 // to also tab-strip the trailing separator).
1591 for &b in caminho.as_bytes() {
1592 if b == b'[' || b == b']' {
1593 return Err(DepError::FonteCaminhoShellBracketExpansion {
1594 nome: nome.to_string(),
1595 caminho: caminho.to_string(),
1596 byte: b,
1597 });
1598 }
1599 }
1600 // Reproducibility gate's shell-quote-grouping arm. The 986963b
1601 // shell-bracket-expansion arm closes `[` / `]`; `'` (`0x27`) and
1602 // `"` (`0x22`) are the orthogonal POSIX shell-string-literal
1603 // delimiter pair — same paste-from-shell-prompt footgun class,
1604 // different syntactic surface. Every POSIX shell (sh / bash /
1605 // zsh / dash / ksh / fish / nushell) lexes the pair as the
1606 // string-literal quoting operator: `'…'` is the strong
1607 // (no-expansion) single-quoted string and `"…"` is the weak
1608 // (variable-/command-substitution-preserving) double-quoted
1609 // string — the canonical `cd '../caixa-teia'` shell-history
1610 // idiom every path-with-embedded-whitespace paste block carries,
1611 // and the symmetric `git clone "$REPO"` weak-quoted CI-manifest
1612 // shape. Beyond shell, the two bytes carry the JSON string-literal
1613 // delimiter (`"key": "value"` — the canonical paste-from-JSON-
1614 // config cross-idiom-leak vector), the YAML double-quoted +
1615 // single-quoted flow-scalar delimiters (`path: "../caixa-teia"`
1616 // — the canonical paste-from-values.yaml / paste-from-K8s-YAML-
1617 // manifest cross-idiom leak), the TOML basic + literal string
1618 // delimiters (`path = "../caixa-teia"` — the canonical paste-
1619 // from-Cargo-manifest cross-idiom-leak vector), the tatara-lisp
1620 // string-literal delimiter itself (`(:caminho "../caixa-teia")`
1621 // — the canonical "I copied the entire `:caminho "..."` slot
1622 // rather than just the string body" author-surface footgun),
1623 // and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which
1624 // excludes both bytes from the `unreserved / pct-encoded /
1625 // sub-delims / ":" / "@"` `pchar` production. POSIX
1626 // `std::path::Path` treats both bytes as literal path-component
1627 // bytes (so `../"caixa-teia"` is one directory named literally
1628 // `../"caixa-teia"`, sibling of `.` and `..`).
1629 //
1630 // A `:caminho "'../caixa-teia'"` (the canonical "I pasted a
1631 // `cd '../caixa-teia'` shell-history one-liner whose strong-
1632 // quoting preserved the sibling-workspace path verbatim across
1633 // the whitespace paste boundary" footgun), `:caminho
1634 // "\"../caixa-teia\""` (the symmetric weak-quoted paste-from-
1635 // JSON / paste-from-YAML flow-scalar / paste-from-TOML basic-
1636 // string / paste-from-tatara-lisp string-literal cross-idiom-
1637 // leak shape), or `:caminho "../\"caixa-teia\""` (the embedded-
1638 // quote "I pasted a JSON key-value pair fragment into the
1639 // middle of the path" idiom) silently passes every prior arm
1640 // because `Path::is_absolute` returns false on `..` / `'` /
1641 // `"`, `'` / `"` are neither leading-byte sentinels nor
1642 // control bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&`
1643 // nor backtick nor `*` / `?` nor `(` / `)` nor `{` / `}` nor
1644 // `[` / `]`, and the value's last byte isn't `/`. The resolver
1645 // folds the value through `Path::new(caminho).join(<file>)`
1646 // looking for a literal `./'../caixa-teia'` subdirectory and
1647 // fails at resolve time with a non-self-locating `No such file
1648 // or directory` error far from the source caixa.lisp.
1649 //
1650 // The lacre pipeline embeds the value verbatim in its per-dep
1651 // content-address (`conteudo: format!("path:{caminho}")`,
1652 // caixa-resolver/src/resolve.rs:189), so a `'` or `"` byte
1653 // lands in the BLAKE3 closure and rides downstream as part of
1654 // the build's identity into every shell-spawned subprocess
1655 // (the caixa-resolver's `git clone` invocation, a future
1656 // `feira tofu` shell-out, a future operator-side `nix flake
1657 // check` spawn) as the canonical shell-metachar / string-
1658 // literal-delimiter surface every peer single-token-shaped
1659 // typed slot already closes. The peer `:fonte :repo` axis
1660 // closes both bytes under the same shell-quote-grouping /
1661 // RFC-3986-sub-delims banner (e7a109f `'` shell-single-quote
1662 // + 4267d8b `"` shell-double-quote on `is_git_repo_url`). The
1663 // `:caminho` axis was the last typed path-string surface
1664 // still admitting these two bytes; this arm closes the gap
1665 // so the substrate-wide "no shell-composition metacharacter
1666 // anywhere in a typed string slot that flows verbatim into a
1667 // shell-spawned subprocess" invariant extends from shell-
1668 // bracket-expansion (`[` / `]`) to shell-quote-grouping (`'`
1669 // / `"`) on the `:caminho` axis. Together with the peer
1670 // JSON / YAML / TOML string-literal delimiters closing at
1671 // this arm and the 598b770 `{` / `}` brace-expansion arm
1672 // closing the templating-engine-placeholder boundary, the
1673 // typed `:caminho` accepted set now structurally excludes
1674 // the entire cross-config-DSL string-literal / templating
1675 // paste-from-aligned-manifest cross-idiom-leak surface that
1676 // would silently round-trip through any downstream JSON /
1677 // YAML / TOML / HCL / tatara-lisp parsing layer.
1678 //
1679 // The arm fires AFTER the shell-bracket-expansion arm because
1680 // the prior arm's `[` / `]` shape is the more semantic-
1681 // locating axis on values that probe as both (`"../[a-z]'x'"`
1682 // carries both `[` and `'` — the glob-character-class
1683 // expansion is the load-bearing root-cause edit, so
1684 // `FonteCaminhoShellBracketExpansion` wins; same cascade
1685 // discipline every prior `:caminho` arm establishes). The arm
1686 // fires BEFORE the trailing-`/` arm because the embedded
1687 // quote-grouping byte is the more semantic-locating axis on
1688 // probe-as-both values (`"../'caixa-teia'/"` ends in `/` but
1689 // the load-bearing diagnostic is the embedded `'` shell-
1690 // string-literal metachar — the trailing `/` is the secondary
1691 // observation, and an author who removes the `'` is likely to
1692 // also tab-strip the trailing separator).
1693 for &b in caminho.as_bytes() {
1694 if b == b'\'' || b == b'"' {
1695 return Err(DepError::FonteCaminhoShellQuoteGrouping {
1696 nome: nome.to_string(),
1697 caminho: caminho.to_string(),
1698 byte: b,
1699 });
1700 }
1701 }
1702 // Reproducibility gate's shell-comment / URL-fragment / YAML-comment arm.
1703 // The d14cbc5 shell-quote-grouping arm closes `'` / `"`; `#` (`0x23`) is
1704 // the orthogonal "byte at which four distinct downstream parsers all
1705 // truncate the value at the first occurrence" surface, and no prior arm
1706 // has covered it on the `:caminho` axis. Every POSIX shell (sh / bash /
1707 // zsh / dash / ksh / fish / nushell) lexes an unquoted `#` at the head
1708 // of a word (or after unquoted whitespace) as the comment-lead: from
1709 // that byte to the end of the physical line is a comment discarded
1710 // before command parsing (`cd ../caixa-teia # legacy sibling` — the
1711 // canonical paste-from-shell-history-with-trailing-annotation shape
1712 // every operator-notebook and CI-manifest carries; POSIX.1-2017 §2.3
1713 // Token Recognition step 6). YAML 1.2 §6.6 makes `#` the comment lead
1714 // at any position preceded by whitespace or at line-start (`path:
1715 // ../caixa-teia # pin` — the canonical paste-from-values.yaml /
1716 // paste-from-K8s-manifest cross-idiom-leak shape). tatara-lisp itself
1717 // treats `;` as the comment-lead but a growing number of consumer
1718 // config-DSL layers (HCL, Terraform, Nix flake attributes, .env
1719 // dotenv-style files, gitconfig / .gitignore, ini / TOML) use `#` as
1720 // the comment-lead too — the pair extends the cross-config-DSL
1721 // paste-idiom surface the d14cbc5 quote-grouping arm and the 598b770
1722 // brace-expansion arm already cover on adjacent axes. RFC 3986 §3.5
1723 // reserves `#` as the URL fragment-identifier delimiter (the canonical
1724 // paste-from-browser-address-bar `github.com/foo/bar#readme` /
1725 // `github.com/foo/bar#L42` permalink shape, and the symmetric
1726 // Nix-flake-ref cross-idiom leak `github:foo/bar#packageName` where
1727 // `#` selects a flake output — the same axis the peer
1728 // [`crate::render::is_git_repo_url`] closes on the `:fonte :repo`
1729 // surface at a68f818 with the same downstream-drops-the-tail
1730 // rationale).
1731 //
1732 // POSIX `std::path::Path` treats `#` as a literal path-component byte,
1733 // so a `:caminho "../caixa-teia # legacy sibling"` (the canonical
1734 // paste-from-shell-history-with-trailing-annotation footgun),
1735 // `:caminho "../caixa-teia # pin"` (the symmetric YAML flow-scalar
1736 // paste-with-trailing-comment shape), or `:caminho "../caixa-teia
1737 // #readme"` (the URL fragment paste-from-browser-address-bar shape)
1738 // silently passes every prior arm because `Path::is_absolute` returns
1739 // false on `..`, `#` is neither a leading-byte sentinel nor a control
1740 // byte nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1741 // `*` / `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` / `"`,
1742 // and the value's last byte isn't `/`. The resolver folds the value
1743 // through `Path::new(caminho).join(<file>)` looking for a literal
1744 // subdirectory named `../caixa-teia # legacy sibling` and fails at
1745 // resolve time with a non-self-locating `No such file or directory`
1746 // error far from the source caixa.lisp — while every downstream
1747 // shell / YAML / URL parser silently truncates the value at the `#`
1748 // byte to `../caixa-teia`, so a `feira tofu` shell-out to a
1749 // `cd '{caminho}'` command line and a `nix flake check` invocation on
1750 // an emitted YAML `path:` scalar disagree with the resolver on which
1751 // directory the value names. Two workstations whose downstream
1752 // shell / YAML / URL parsing layers differ in unquoted-`#`
1753 // recognition emit divergent build artifacts for the byte-identical
1754 // caixa.lisp value.
1755 //
1756 // The lacre pipeline embeds the value verbatim in its per-dep
1757 // content-address (`conteudo: format!("path:{caminho}")`,
1758 // caixa-resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1759 // closure and rides downstream as part of the build's identity into
1760 // every shell-spawned subprocess (the caixa-resolver's `git clone`
1761 // invocation, a future `feira tofu` shell-out, a future operator-side
1762 // `nix flake check` spawn) as the canonical shell-metachar /
1763 // comment-lead / URL-fragment-delimiter surface every peer
1764 // single-token-shaped typed slot already closes. The peer `:fonte
1765 // :repo` axis closes the byte under the URL-fragment-identifier
1766 // banner (a68f818 `#` on `is_git_repo_url`); the `:caminho` axis was
1767 // the last typed path-string surface still admitting the byte. This
1768 // arm closes the gap so the substrate-wide "no shell-composition
1769 // metacharacter / comment-lead / URL-fragment-delimiter anywhere in a
1770 // typed string slot that flows verbatim into a shell-spawned
1771 // subprocess or downstream YAML / URL parser" invariant extends from
1772 // shell-quote-grouping (`'` / `"`) to shell-comment / URL-fragment
1773 // (`#`) on the `:caminho` axis. Together with the peer JSON / YAML /
1774 // TOML string-literal delimiters the d14cbc5 quote-grouping arm
1775 // closes and the 598b770 `{` / `}` brace-expansion arm closes on the
1776 // templating-engine-placeholder boundary, the typed `:caminho`
1777 // accepted set now structurally excludes the entire
1778 // paste-with-trailing-annotation / paste-from-URL-permalink /
1779 // paste-from-YAML-comment cross-idiom-leak surface that would
1780 // silently round-trip through any downstream shell / YAML / URL /
1781 // dotenv / gitconfig / HCL parsing layer to a different value than
1782 // the resolver's `Path::join` sees.
1783 //
1784 // The arm fires AFTER the shell-quote-grouping arm because the prior
1785 // arm's `'` / `"` shape is the more semantic-locating axis on values
1786 // that probe as both (`"../'x'#pin"` carries both `'` and `#` — the
1787 // shell-string-literal-delimiter is the load-bearing root-cause edit,
1788 // so `FonteCaminhoShellQuoteGrouping` wins; same cascade discipline
1789 // every prior `:caminho` arm establishes). The arm fires BEFORE the
1790 // trailing-`/` arm because the embedded comment-lead / fragment-
1791 // delimiter byte is the more semantic-locating axis on probe-as-both
1792 // values (`"../caixa-teia#pin/"` ends in `/` but the load-bearing
1793 // diagnostic is the embedded `#` — the trailing `/` is the secondary
1794 // observation, and an author who removes the `#pin` fragment is
1795 // likely to also tab-strip the trailing separator).
1796 for &b in caminho.as_bytes() {
1797 if b == b'#' {
1798 return Err(DepError::FonteCaminhoShellComment {
1799 nome: nome.to_string(),
1800 caminho: caminho.to_string(),
1801 byte: b,
1802 });
1803 }
1804 }
1805 // Reproducibility gate's URL-percent-encoding-escape arm. The 6622063
1806 // shell-comment arm closes the `#` URL-fragment-identifier byte; `%`
1807 // (`0x25`) is the orthogonal RFC 3986 §2.1 URL percent-encoding-escape
1808 // byte — the mandatory encoding mechanism for every byte outside the
1809 // `unreserved` alphanumeric / `-` / `.` / `_` / `~` set, and `%`
1810 // itself must be percent-encoded as `%25` to appear literally inside
1811 // a URL value. The byte carries three distinct render-determinism
1812 // hazards on the `:caminho` axis, no prior arm has covered it, and
1813 // the peer `:fonte :repo` axis (a323db8 `%` on `is_git_repo_url`)
1814 // already closes the same byte under the same URL-percent-encoding
1815 // banner — the `:caminho` axis was the last typed path-string surface
1816 // still admitting the byte.
1817 //
1818 // First, the paste-from-browser-address-bar percent-encoded-space
1819 // footgun: an author copies `../caixa%20teia` out of a URL-encoded
1820 // README hyperlink / a browser address bar / a percent-encoded
1821 // permalink expecting `%20` to decode to a literal space at the
1822 // filesystem layer. POSIX `std::path::Path` treats the byte as a
1823 // literal path-component byte, so `Path::join` looks for a literal
1824 // `./../caixa%20teia` subdirectory and fails at resolve time with a
1825 // non-self-locating `No such file or directory` error far from the
1826 // source caixa.lisp — while the author's mental model was
1827 // `../caixa teia`, the decoded shape. Two authors whose only
1828 // difference is percent-encoding presence resolve to two distinct
1829 // BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`)
1830 // for what they intended as the byte-identical sibling-workspace
1831 // dep. The lacre pipeline embeds the value verbatim in its per-dep
1832 // content-address (`conteudo: format!("path:{caminho}")`,
1833 // caixa-resolver/src/resolve.rs:189), so the divergence rides
1834 // downstream into the BLAKE3 closure and locks the substrate's
1835 // "the lacre is the build's identity" contract (CAIXA-SDLC §III.2)
1836 // to the wrong encoding — the same THEORY.md §V.2 render-
1837 // determinism vector every prior `:caminho` arm protects.
1838 //
1839 // Second, the printf-format-specifier lead footgun: `%` is the C /
1840 // POSIX printf format-directive lead-in (`%s`, `%d`, `%02x`, the
1841 // canonical `printf "path=%s\n" ../caixa-teia` invocation every
1842 // shell-diagnostic one-liner carries) and the printf builtin is
1843 // wired into every POSIX shell (bash / zsh / dash / ksh / busybox
1844 // ash) as the format-string lead. A `:caminho "../caixa-%s-teia"`
1845 // value flowing into any future `feira` verb that shells out with a
1846 // printf-formatted path template silently gets reinterpreted as a
1847 // format-directive rather than a literal byte — the canonical
1848 // CWE-134 format-string-injection vector.
1849 //
1850 // Third, the bash-job-control-specifier lead footgun: bash / zsh /
1851 // ksh reserve `%N` at word-start as the job-control specifier —
1852 // `%1` names "job 1", `%%` names "the current job", `%foo` names
1853 // "the most recent job whose command started with `foo`". A future
1854 // `feira` verb that invokes `kill %1` on a caminho-scoped
1855 // subprocess would silently redirect the signal to a wrong target.
1856 //
1857 // Beyond the three shell-side hazards, `%` is a first-class parser
1858 // byte in three cross-config-DSL layers the substrate's paste-idiom
1859 // surface routinely crosses: YAML 1.2 §6.8.1 lexes `%` at
1860 // line-start as the directive lead (`%YAML 1.2` / `%TAG` — a
1861 // `:caminho "%YAML/1.2/../caixa-teia"` paste from a top-of-doc
1862 // YAML directive block silently trips the YAML directive parser on
1863 // any downstream emitted YAML manifest); Prometheus / Grafana
1864 // template syntax uses `%(var)s` as the substitution lead; and Nix
1865 // interpolation uses `${var}` (not `%`) but Envsubst /
1866 // Kubernetes / OpenShift template layers use `%VAR%` as the
1867 // Windows-shell env-var-reference lead — the paste-from-`.bat` /
1868 // paste-from-PowerShell-`%env:PATH%` cross-idiom leak.
1869 //
1870 // The three malformed-`%HH` classes documented on the peer
1871 // `is_git_repo_url` `%` arm (a323db8) apply here too:
1872 //
1873 // - The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
1874 // where `%` isn't followed by two hex digits) — every WHATWG-
1875 // conformant URL parser rejects the value at parse time per
1876 // RFC 3986 §2.1, but the byte rides into the lacre before
1877 // the resolver subprocess crosses the URL-parser boundary.
1878 // - The over-encoded path-separator shape (`"../caixa%2Fteia"`
1879 // intending the `%2F` as the URL encoding of `/`) locks a
1880 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
1881 // the byte-identical `path:../caixa/teia` form.
1882 // - The double-encoded shape (`"../caixa%2520teia"` — the `%25`
1883 // already itself an encoded `%`, so the intent was likely a
1884 // literal `%20` that survived one round-trip through a
1885 // URL-encoder that shouldn't have run) locks a triply-
1886 // divergent closure across the encoded / once-decoded /
1887 // twice-decoded chain.
1888 //
1889 // POSIX `std::path::Path` treats the byte as a literal path-
1890 // component byte, so a `:caminho "../caixa%20teia"` (the canonical
1891 // paste-from-browser-address-bar percent-encoded-space footgun),
1892 // `:caminho "%YAML/../caixa-teia"` (the symmetric paste-from-YAML-
1893 // directive-block cross-idiom leak), or `:caminho
1894 // "../caixa-%s-teia"` (the printf-format-specifier paste-from-
1895 // shell-diagnostic-one-liner shape) silently passes every prior arm
1896 // because `Path::is_absolute` returns false on `..`, `%` is neither
1897 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
1898 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
1899 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`, and the
1900 // value's last byte isn't `/`. The resolver folds the value through
1901 // `Path::new(caminho).join(<file>)` looking for a literal
1902 // subdirectory named `../caixa%20teia` and fails at resolve time
1903 // with a non-self-locating `No such file or directory` error far
1904 // from the source caixa.lisp — while every downstream URL parser /
1905 // shell printf builtin / YAML directive parser silently
1906 // reinterprets the byte to a different value than the resolver's
1907 // `Path::join` sees. Two workstations whose downstream URL / shell
1908 // / YAML layers differ in `%HH` recognition emit divergent build
1909 // artifacts for the byte-identical caixa.lisp value.
1910 //
1911 // The lacre pipeline embeds the value verbatim in its per-dep
1912 // content-address (`conteudo: format!("path:{caminho}")`, caixa-
1913 // resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1914 // closure and rides into every shell-spawned subprocess (the
1915 // resolver's `git clone`, a future `feira tofu` shell-out, a
1916 // future operator-side `nix flake check` spawn) as the canonical
1917 // URL-percent-encoding-escape / printf-format-specifier / bash-
1918 // job-control-specifier surface every peer single-token-shaped
1919 // typed slot already closes. This arm closes the gap so the
1920 // substrate-wide "no URL-percent-encoding-escape / printf-format-
1921 // specifier / job-control-specifier / YAML-directive-lead byte
1922 // anywhere in a typed string slot that flows verbatim into a
1923 // shell-spawned subprocess or downstream URL / printf / YAML
1924 // parser" invariant extends from shell-comment / URL-fragment
1925 // (`#` — 6622063) to URL-percent-encoding-escape (`%`) on the
1926 // `:caminho` axis.
1927 //
1928 // The arm fires AFTER the shell-comment arm because the prior
1929 // arm's `#` shape is the more semantic-locating axis on values
1930 // that probe as both (`"../caixa%20teia#pin"` carries both `%`
1931 // and `#` — the URL-fragment-identifier is the load-bearing
1932 // downstream-truncation edit, so `FonteCaminhoShellComment` wins;
1933 // same cascade discipline every prior `:caminho` arm establishes).
1934 // The arm fires BEFORE the trailing-`/` arm because the embedded
1935 // percent-encoding-escape byte is the more semantic-locating axis
1936 // on probe-as-both values (`"../caixa%20teia/"` ends in `/` but
1937 // the load-bearing diagnostic is the embedded `%` percent-
1938 // encoding-escape — the trailing `/` is the secondary observation,
1939 // and an author who decodes the `%20` to a literal space is
1940 // likely to also tab-strip the trailing separator).
1941 for &b in caminho.as_bytes() {
1942 if b == b'%' {
1943 return Err(DepError::FonteCaminhoUrlPercentEncoding {
1944 nome: nome.to_string(),
1945 caminho: caminho.to_string(),
1946 byte: b,
1947 });
1948 }
1949 }
1950 // Reproducibility gate's embedded-`$` shell-variable-expansion /
1951 // command-substitution / arithmetic-expansion arm. The f4efe9c
1952 // leading-`$` arm at line 540 routes `caminho.starts_with('$')`
1953 // through `FonteCaminhoVarExpansion` under the leading-byte-
1954 // sentinel host-layout-leak banner (peer with the b94fd83
1955 // absolute / a5c248e tilde leading-byte arms), but the arm
1956 // fires only at position 0 — a `:caminho "../foo$HOME/bar"`
1957 // (embedded `$HOME` in a nested path segment — the canonical
1958 // paste-from-`ls ../foo$HOME/bar`-shell-one-liner footgun where
1959 // an author copies a partially-substituted shell one-liner and
1960 // the leading segment is a literal `../foo` while the mid
1961 // segment carries the un-substituted `$HOME` template), a
1962 // `:caminho "../foo${WORKSPACE}/bar"` (the symmetric braced-CI-
1963 // manifest paste-from-`.gitlab-ci.yml` / paste-from-GitHub-
1964 // Actions-workflow shape), a `:caminho "../foo$(whoami)/bar"`
1965 // (the paste-from-shell-prompt command-substitution idiom), or
1966 // a `:caminho "../foo$((1+2))/bar"` (the arithmetic-expansion
1967 // idiom) silently passes every prior arm because
1968 // `Path::is_absolute` returns false on `..`, `$` is neither a
1969 // leading-byte sentinel (the f4efe9c arm fires only at position
1970 // 0) nor a control byte nor `\` nor `<` / `>` nor `|` nor `;`
1971 // nor `&` nor backtick nor `*` / `?` nor `(` / `)` nor `{` /
1972 // `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%`, and the
1973 // value's last byte isn't `/`. Note that `$(...)` command-
1974 // substitution and `$((...))` arithmetic-expansion each carry
1975 // an embedded `(` byte that the 0633c91 shell-subshell-grouping
1976 // arm catches structurally at the earlier `(` position — but
1977 // an author who reaches for the sh-brace-substitution
1978 // `${VAR}` or the bare `$VAR` shape carries only the `$` byte,
1979 // which no prior arm covers. This arm closes the last
1980 // positional gap on the `$` byte on the `:caminho` axis so
1981 // every position — leading (`FonteCaminhoVarExpansion`) and
1982 // embedded (`FonteCaminhoShellVariableExpansion`) — is
1983 // structurally rejected.
1984 //
1985 // Every POSIX shell (sh / bash / zsh / dash / ksh / busybox
1986 // ash / fish / nushell) lexes `$` as the variable-expansion /
1987 // command-substitution / arithmetic-expansion operator per
1988 // POSIX.1-2017 §2.6 (Word Expansions): `$<name>` (Parameter
1989 // Expansion) expands a named variable, `${<name>}` (Parameter
1990 // Expansion braced form) does the same with an explicit token
1991 // boundary, `$(<cmd>)` (Command Substitution modern form,
1992 // `` `<cmd>` `` legacy form which the c370458 backtick arm
1993 // already closes) runs a subshell and substitutes its stdout,
1994 // and `$((<expr>))` (Arithmetic Expansion) evaluates an
1995 // arithmetic expression. Every form is a host-layout /
1996 // environment-state / shell-subprocess-side-effect leak when
1997 // the byte lands in a value the resolver passes to a shell-
1998 // spawned subprocess. Beyond the POSIX shell layer, `$` is
1999 // the Nix `${var}` string-interpolation lead (the paste-from-
2000 // `flake.nix` / paste-from-`.nix`-attribute cross-idiom leak
2001 // where an author copies `"${pkgs.hello}/bin/hello"` out of a
2002 // nix expression), the Make `$(var)` / `$@` / `$<` automatic-
2003 // variable lead (the paste-from-`Makefile` shape), the
2004 // JavaScript / TypeScript template-literal `${expr}` interp
2005 // lead (the paste-from-JS-template-string idiom in a
2006 // multi-lang-monorepo where a `path` attribute gets copied out
2007 // of a `package.json` script or a Vite config), the envsubst /
2008 // Kubernetes / OpenShift template `${VAR}` interp lead (the
2009 // paste-from-Helm-values / paste-from-K8s-manifest cross-idiom
2010 // leak), the PHP variable lead (`$_GET`, `$_ENV` — the paste-
2011 // from-`.php`-config footgun), the Perl scalar-variable lead
2012 // (`$foo`), the SASS / SCSS variable lead (`$primary-color`),
2013 // and the SQL bind-parameter lead in PostgreSQL / SQLite
2014 // (`$1`, `$2` — the paste-from-`.sql`-migration idiom). The
2015 // cross-idiom paste-footgun surface is broader than any single
2016 // shell layer — `$` is a first-class parser byte in nearly
2017 // every config / templating / build-system DSL the substrate's
2018 // paste-idiom surface routinely crosses. The peer `:fonte
2019 // :repo` axis closes the byte under the shell-variable-
2020 // expansion / URL-sub-delim banner (b9d187c `$` on
2021 // `is_git_repo_url`), the peer `:fonte :tag` / `:fonte :branch`
2022 // axes close `$` as part of `is_git_ref_name`'s printable-
2023 // ASCII-restricted grammar (`git check-ref-format` rejects the
2024 // byte outright), and the peer `:entrada :paths` axis closes
2025 // `$` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-
2026 // reserved set. The `:caminho` axis was the last typed path-
2027 // string surface still admitting `$` at positions other than 0.
2028 //
2029 // POSIX `std::path::Path` treats `$` as a literal path-
2030 // component byte, so `:caminho "../foo$HOME/bar"` silently
2031 // routes through `Path::new(caminho).join(<file>)` looking for
2032 // a literal `./{caminho}` subdirectory that fails at resolve
2033 // time with a non-self-locating `No such file or directory`
2034 // error far from the source caixa.lisp. But every downstream
2035 // shell / envsubst / Nix / Make / K8s-template parser silently
2036 // reinterprets the byte to a different value than the
2037 // resolver's `Path::join` sees — so a `feira tofu` shell-out
2038 // to a `cd '{caminho}'` command line, a `nix flake check`
2039 // invocation on an emitted YAML `path:` scalar folded through
2040 // envsubst, or a `helm template` invocation with a
2041 // `values.yaml` `path: {caminho}` embedded in a `{{`-quoted
2042 // template all disagree with the resolver on which directory
2043 // the value names. Two workstations whose downstream shell /
2044 // envsubst / Nix / Make / K8s-template parsing layers differ
2045 // in `$VAR` recognition (or, worse, expand the byte against
2046 // divergent environments — Alice's `$HOME=/home/alice`, Bob's
2047 // `$HOME=/home/bob`) emit divergent build artifacts for the
2048 // byte-identical caixa.lisp value. Even in the case where the
2049 // resolver strictly does NOT expand `$VAR` (the current
2050 // implementation) the divergence still bites at the lacre-
2051 // identity axis: the lacre pipeline embeds the value verbatim
2052 // in its per-dep content-address (`conteudo:
2053 // format!("path:{caminho}")`, caixa-resolver/src/resolve.rs:189),
2054 // so `path:../foo$HOME/bar` locks a BLAKE3 closure distinct
2055 // from the byte-identical-semantic `path:../foo/home/alice/bar`
2056 // one author would have produced by substituting the literal
2057 // value at author time, defeating the THEORY.md §V.2 render-
2058 // determinism contract on the same axis every prior `:caminho`
2059 // arm protects.
2060 //
2061 // Beyond the render-determinism / host-layout-leak vectors,
2062 // `$` at any position in a value flowing verbatim into a
2063 // shell-spawned subprocess is the canonical CWE-78 shell-
2064 // command-injection surface every peer single-token-shaped
2065 // typed slot already closes. A `:caminho "../foo$(whoami)/bar"`
2066 // that rides into a future `feira tofu` shell-out as `cd
2067 // '../foo$(whoami)/bar'` gets substituted by the shell at
2068 // subprocess-argument-expansion time even inside single quotes
2069 // in fewer positions than one might expect (the substitution
2070 // fires only outside single-quoting per POSIX §2.2.2, but
2071 // eval-style wrappers and `sh -c` layers that route the value
2072 // through re-parsing round-trip the substitution — the same
2073 // vector the c370458 backtick arm closes at the sibling
2074 // command-substitution-legacy-form surface). Every future
2075 // `feira` verb that shells out with a `caminho`-formatted
2076 // subprocess argument silently inherits this substitution
2077 // vector unless the typed slot's accepted set structurally
2078 // excludes the byte.
2079 //
2080 // Frontier inspiration: OTP's `gen_server` return-value grammar
2081 // rejects mid-tuple shell-metachar bytes by construction —
2082 // `{noreply, State}` never carries a raw `$` because the
2083 // Erlang term type system has no notion of "string that gets
2084 // shelled out"; caixa's typed slots inherit the same
2085 // structural discipline (types-are-theorems, the compounding
2086 // mandate's leverage-point-1) by refusing values that would
2087 // silently reinterpret at any downstream layer. Peer with
2088 // Unison's content-addressed code (no ambient environment —
2089 // every reference is a hash, no `$VAR` substitution possible)
2090 // and Pony's capabilities (a path capability that carries a
2091 // `$` would be ill-typed at the reference layer).
2092 //
2093 // The arm fires AFTER the URL-percent-encoding-escape arm (the
2094 // e3558fa `%` arm) because a value carrying both `%` and `$`
2095 // (`"../foo%20$HOME/bar"` — the canonical "I pasted a percent-
2096 // encoded space next to a `$HOME` template") surfaces the
2097 // narrower URL-encoding diagnostic first — the paste-from-
2098 // browser-address-bar shape is the load-bearing self-locating
2099 // edit on every probe-as-both value; same cascade discipline
2100 // every prior `:caminho` arm establishes (a323db8 % before
2101 // this arm, this arm before trailing-`/`). The arm fires
2102 // BEFORE the trailing-`/` arm because the embedded shell-
2103 // variable-expansion byte is the more semantic-locating axis
2104 // on probe-as-both values (`"../foo$HOME/bar/"` ends in `/`
2105 // but the load-bearing diagnostic is the embedded `$` — the
2106 // trailing `/` is the secondary observation, and an author
2107 // who substitutes the `$HOME` template with a literal value is
2108 // likely to also tab-strip the trailing separator).
2109 for &b in caminho.as_bytes() {
2110 if b == b'$' {
2111 return Err(DepError::FonteCaminhoShellVariableExpansion {
2112 nome: nome.to_string(),
2113 caminho: caminho.to_string(),
2114 byte: b,
2115 });
2116 }
2117 }
2118 // Reproducibility gate's shell-history-expansion / RFC-3986-sub-delims
2119 // arm. The immediate-predecessor `$` embedded arm closes the shell-
2120 // variable-expansion / command-substitution byte; `!` (`0x21`) is the
2121 // orthogonal POSIX shell-history-expansion sentinel every interactive
2122 // shell with history enabled (bash / ksh / zsh's `bashcompat` /
2123 // csh / tcsh) lexes as the history-expansion prefix: `!command`
2124 // re-runs the most recent history entry beginning with `command`,
2125 // `!!` re-runs the prior command verbatim, `!$` substitutes the
2126 // last word of the prior command, `!:N` substitutes the Nth word,
2127 // `^old^new` rewrites the prior command's `old` to `new` (the
2128 // canonical set of `set -o histexpand` operators bash's default
2129 // interactive session enables). Beyond the shell-history layer,
2130 // RFC 3986 §2.2 lists `!` in the `sub-delims` set (the URL grammar
2131 // admits the byte inside a path segment, but every WHATWG-conformant
2132 // special-scheme URL parser percent-encodes it inside a query
2133 // component via the 'special-query percent-encode set' the peer
2134 // `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte
2135 // is also the C / C++ / Rust / JavaScript / Python bang-operator
2136 // (logical-negation prefix — the paste-from-source-code idiom where
2137 // an author copies `!path.exists()` out of a Rust snippet and the
2138 // trailing punctuation crosses the string-literal boundary); the
2139 // canonical English-typography emphasis / exclamation mark (the
2140 // paste-from-prose enthusiasm-form idiom where an author writes
2141 // `:caminho "../caixa-teia!"` expecting the substrate to coerce it
2142 // to a kebab-case slug); and the Nix flake-ref import-attribute
2143 // `import ./foo.nix { … }` sibling operator surface.
2144 //
2145 // POSIX `std::path::Path` treats `!` as a literal path-component
2146 // byte, so a `:caminho "../caixa-teia!sudo"` (the canonical paste-
2147 // from-shell-history footgun where the author copies a `cd
2148 // ../caixa-teia && !sudo make install` one-liner from a quick-
2149 // start README and the trailing `!sudo` rides in verbatim as a
2150 // history-expansion reference), a `:caminho "../foo!!/bar"` (the
2151 // `!!` repeat-prior-command paste idiom), a `:caminho
2152 // "../caixa-teia!"` (the English-typography enthusiasm-form
2153 // paste-from-prose footgun), or a `:caminho "../foo!$"` (the
2154 // last-word-substitution shape) silently pass every prior arm
2155 // because `Path::is_absolute` returns false on `..`, `!` is neither
2156 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
2157 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
2158 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%` nor `$`,
2159 // and the value's last byte isn't `/`. The resolver folds the value
2160 // through `Path::new(caminho).join(<file>)` looking for a literal
2161 // `./../caixa-teia!sudo` subdirectory and fails at resolve time
2162 // with a non-self-locating `No such file or directory` error far
2163 // from the source caixa.lisp — while every downstream interactive
2164 // shell with `set -o histexpand` reinterprets the byte as the
2165 // history-expansion prefix, and the failure mode forks per
2166 // consumer: a `feira tofu` shell-out to a `cd '{caminho}'` command
2167 // line executed under `bash -i` (the operator-notebook interactive
2168 // shell) substitutes the `!sudo` reference to the most recent
2169 // history entry starting with `sudo`, silently invoking whatever
2170 // privileged command that entry named.
2171 //
2172 // The lacre pipeline embeds the value verbatim in its per-dep
2173 // content-address (`conteudo: format!("path:{caminho}")`,
2174 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2175 // BLAKE3 closure and rides into every shell-spawned subprocess
2176 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2177 // a future operator-side `nix flake check` spawn) as the
2178 // canonical shell-history-expansion / RFC-3986-sub-delims surface
2179 // every peer single-token-shaped typed slot already closes. The
2180 // peer `:fonte :repo` axis closes the byte under the same shell-
2181 // history-expansion / RFC-3986-sub-delims banner (7d53c68 `!` on
2182 // `is_git_repo_url`); the `:caminho` axis was the last typed
2183 // path-string surface still admitting the byte. This arm closes
2184 // the gap so the substrate-wide "no shell-composition
2185 // metacharacter / history-expansion sentinel anywhere in a typed
2186 // string slot that flows verbatim into a shell-spawned subprocess"
2187 // invariant extends from shell-variable-expansion (`$`) to shell-
2188 // history-expansion (`!`) on the `:caminho` axis. Together with
2189 // the peer c370458 backtick command-substitution-legacy-form arm
2190 // and the b9d187c-`$`-embedded-variable-expansion arm on the
2191 // sibling `:repo` axis, the typed `:caminho` accepted set now
2192 // structurally excludes every byte the POSIX shell §2.6 Word
2193 // Expansions section, §2.3 Token Recognition step 6, and every
2194 // history-expansion / brace-expansion / pathname-expansion /
2195 // parameter-expansion / command-substitution / arithmetic-
2196 // expansion operator lexes as a first-class parser byte.
2197 //
2198 // Frontier inspiration: Unison's content-addressed code (no
2199 // ambient environment — every reference is a hash, no `!<num>`
2200 // history-index substitution possible; the caixa substrate's
2201 // lacre discipline arrives at the same guarantee by refusing
2202 // bytes at manifest-parse time that would reinterpret against
2203 // ambient shell history state); Pony's capabilities (a path
2204 // capability that carries a `!` would be ill-typed at the
2205 // reference layer).
2206 //
2207 // The arm fires AFTER the shell-variable-expansion arm because a
2208 // value carrying both `$` and `!` (`"../foo$HOME/bar!sudo"` — the
2209 // canonical "I pasted a `$HOME`-templated path adjacent to a
2210 // trailing `!sudo` history-expansion") surfaces the narrower
2211 // shell-variable-expansion diagnostic first — the paste-from-CI-
2212 // manifest-with-`$VAR`-template shape is the load-bearing self-
2213 // locating edit on every probe-as-both value; same cascade
2214 // discipline every prior `:caminho` arm establishes. The arm
2215 // fires BEFORE the trailing-`/` arm because the embedded shell-
2216 // history-expansion byte is the more semantic-locating axis on
2217 // probe-as-both values (`"../foo!sudo/"` ends in `/` but the
2218 // load-bearing diagnostic is the embedded `!` — the trailing `/`
2219 // is the secondary observation, and an author who removes the
2220 // `!sudo` history reference is likely to also tab-strip the
2221 // trailing separator).
2222 for &b in caminho.as_bytes() {
2223 if b == b'!' {
2224 return Err(DepError::FonteCaminhoShellHistoryExpansion {
2225 nome: nome.to_string(),
2226 caminho: caminho.to_string(),
2227 byte: b,
2228 });
2229 }
2230 }
2231 // Reproducibility gate's shell-history-substitution / RFC-3986-unwise
2232 // / regex-anchor arm. The immediate-predecessor `!` arm closes the
2233 // POSIX `!command` / `!!` / `!$` history-expansion prefix; `^`
2234 // (`0x5E`) is the paired-operator half of the same bash-reference
2235 // §9.3 histexpand feature — the `^old^new^` "quick substitution"
2236 // form (POSIX bash rewrites the prior command's `old` string to
2237 // `new` and re-executes it, the canonical typo-correction one-
2238 // liner idiom `git clone <bad-url>` → `^bad^good` that pastes the
2239 // trailing substitution fragment verbatim into a `:caminho` value
2240 // when the author trims only the leading `git clone` prefix). The
2241 // peer `:fonte :repo` axis closes the byte under the same
2242 // shell-history-substitution / RFC-3986-unwise banner (49e142f `^`
2243 // on `is_git_repo_url`); the `:caminho` axis was the last typed
2244 // path-string surface still admitting the byte after 6a04767
2245 // landed the `!` arm.
2246 //
2247 // Beyond bash history-substitution, `^` carries five distinct
2248 // downstream-reinterpretation surfaces the typed slot's accepted
2249 // set must structurally exclude:
2250 //
2251 // 1. **RFC 3986 §2 'unwise' set** — the four-byte cross-transport
2252 // layer set (`{`, `}`, `|`, `\`) plus `^` every URL parser is
2253 // required to percent-encode-or-refuse at the wire boundary.
2254 // The WHATWG URL spec's 'fragment percent-encode set' maps
2255 // `^` → `%5E` at the query / fragment component transition;
2256 // libcurl silently percent-encodes the byte on the wire, so a
2257 // `:caminho "../foo^bar"` value the resolver's `Path::join`
2258 // sees as a literal `./../foo^bar` subdirectory diverges from
2259 // the byte-transformed `%5E` shape any downstream `feira tofu`
2260 // curl-invocation or artifact-registry-fetch would emit — the
2261 // canonical wire-boundary divergence vector the peer
2262 // `{`, `}`, `|`, `\` `:caminho` arms already close (
2263 // `FonteCaminhoShellBraceExpansion` at 598b770,
2264 // `FonteCaminhoShellPipe` at the pipe arm,
2265 // `FonteCaminhoBackslash` at the backslash arm).
2266 // 2. **Regex character-class negation prefix `[^abc]`** — the
2267 // canonical paste-from-doc-regex-pipeline footgun where an
2268 // author copies a `grep '[^abc]'` idiom from a docs quick-
2269 // listing and the character-class negation byte rides in
2270 // verbatim.
2271 // 3. **Bitwise XOR operator** in C / C++ / Rust / Python /
2272 // JavaScript / Nix / Go — the paste-from-source-code idiom
2273 // where an author copies an `x ^ y`-shaped expression out of
2274 // a source snippet and the operator crosses the string-
2275 // literal boundary.
2276 // 4. **Windows `cmd.exe` escape metacharacter** — the byte
2277 // escapes the next character in a `cmd.exe` batch context (a
2278 // peer of the backslash arm's Windows-separator-leak vector).
2279 // A `:caminho "..^&whoami"` cross-platform paste-from-batch-
2280 // file footgun reinterprets at every `cmd.exe`-spawned
2281 // subprocess (the resolver's future Windows-runner shell-out,
2282 // the operator's WinRM path, a future PowerShell-embedded
2283 // invocation).
2284 // 5. **LaTeX / Markdown / BibTeX superscript operator** — the
2285 // paste-from-typeset-doc footgun where a mathematical
2286 // superscript notation (`x^2` / `M^T`) leaks from prose.
2287 //
2288 // POSIX `std::path::Path` treats `^` as a literal path-component
2289 // byte, so `:caminho "../foo^bar/baz"` (embedded quick-
2290 // substitution), `:caminho "../foo^"` (trailing history-
2291 // substitution-open shape), `:caminho "../[^a-z]/foo"` (regex-
2292 // negation-prefix paste from a grep pipeline; note the `[` / `]`
2293 // arm at 986963b fires first on this shape), or `:caminho
2294 // "../x^y"` (XOR-expression paste-from-source) all silently pass
2295 // every prior arm (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` /
2296 // backtick / `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'`
2297 // / `"` / `#` / `%` / `$` / `!`) and route through
2298 // `Path::new(caminho).join(<file>)` looking for a literal
2299 // `./{caminho}` subdirectory that fails at resolve time with a
2300 // non-self-locating `No such file or directory` error far from
2301 // the source caixa.lisp — while every downstream shell / curl /
2302 // regex / `cmd.exe` layer reinterprets the byte to its own
2303 // semantic.
2304 //
2305 // The lacre pipeline embeds the value verbatim in its per-dep
2306 // content-address (`conteudo: format!("path:{caminho}")`,
2307 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2308 // BLAKE3 closure and rides into every shell-spawned subprocess
2309 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2310 // a future operator-side `nix flake check` spawn) as the
2311 // canonical shell-history-substitution / RFC-3986-unwise /
2312 // regex-negation surface every peer single-token-shaped typed
2313 // slot already closes. This arm together with the immediate-
2314 // predecessor `!` arm (6a04767) closes the full `set -o
2315 // histexpand` operator surface on the `:caminho` axis — the
2316 // `!command` / `!!` / `!$` prefix form via `!`, the `^old^new^`
2317 // quick-substitution form via `^` — so the substrate-wide "no
2318 // shell-history operator anywhere in a typed string slot that
2319 // flows verbatim into a shell-spawned subprocess" invariant
2320 // extends from the `!` prefix half to the `^` quick-substitution
2321 // half. Every peer bash-history operator now fails at manifest-
2322 // parse time with a self-locating diagnostic naming the offending
2323 // caixa.lisp rather than at resolve-time as a `Path::join`-
2324 // derived `No such file or directory` (harmless but non-self-
2325 // locating) or worse riding into a downstream `bash -i` context
2326 // that reinterprets the byte-pair against ambient history state.
2327 //
2328 // Frontier inspiration: bash reference §9.3 HISTORY EXPANSION
2329 // "Quick substitution. Repeat the previous command, replacing
2330 // string1 with string2." + RFC 3986 §2 'unwise' set
2331 // ("characters that gateways and other transport agents are
2332 // known to sometimes modify") + Pony's capabilities (a path
2333 // capability that carries a `^` would be ill-typed at the
2334 // reference layer, matching the same structural discipline the
2335 // sibling `!` history-expansion arm inherits from Unison's
2336 // content-addressed no-ambient-history discipline).
2337 //
2338 // The arm fires AFTER the shell-history-expansion `!` arm because
2339 // a value carrying both `!` and `^` (`"../foo!sudo^bad^good"` —
2340 // the canonical "I pasted a `!sudo` history-reference next to a
2341 // `^bad^good` quick-substitution") surfaces the narrower prefix-
2342 // form `!` diagnostic first — the `!` form is the load-bearing
2343 // self-locating edit on every probe-as-both value (an author who
2344 // removes the `!sudo` reference is likely to also strip the
2345 // paired `^` substitution fragment); same cascade discipline
2346 // every prior `:caminho` arm establishes. The arm fires BEFORE
2347 // the trailing-`/` arm because the embedded shell-history-
2348 // substitution byte is the more semantic-locating axis on
2349 // probe-as-both values (`"../foo^bar/"` ends in `/` but the
2350 // load-bearing diagnostic is the embedded `^` — the trailing `/`
2351 // is the secondary observation, and an author who removes the
2352 // `^bar` substitution fragment is likely to also tab-strip the
2353 // trailing separator).
2354 for &b in caminho.as_bytes() {
2355 if b == b'^' {
2356 return Err(DepError::FonteCaminhoShellHistorySubstitution {
2357 nome: nome.to_string(),
2358 caminho: caminho.to_string(),
2359 byte: b,
2360 });
2361 }
2362 }
2363 // Reproducibility gate's trailing-`/` arm. The b94fd83 absolute arm
2364 // closes the leading-`/` host-layout-leak; the embedded-control-byte
2365 // arm closes any byte-in-the-`0x00..=0x1F` / `0x7F` range; the
2366 // backslash arm closes the cross-host-OS-separator vector. The
2367 // trailing-`/` is the orthogonal shell-tab-completion-on-a-directory
2368 // footgun — `Path::join("../caixa-teia")` and
2369 // `Path::join("../caixa-teia/")` resolve to the same directory
2370 // (POSIX path-component-walk treats trailing `/` as a no-op for
2371 // directory targets, which `:caminho` always names — the sibling-
2372 // workspace dep root is structurally a directory). The lacre
2373 // pipeline embeds the value verbatim in its per-dep content-address
2374 // (`conteudo: format!("path:{caminho}")`,
2375 // caixa-resolver/src/resolve.rs:189), so byte-identical caixa
2376 // semantic-meaning yields two distinct BLAKE3 closures depending on
2377 // whether the author shell-tab-completed the path (every interactive
2378 // shell appends `/` on tab-completing a directory, idiomatic in
2379 // bash / zsh / fish / nushell), pasted from `pwd` (which on most
2380 // shells emits without trailing `/`, but `realpath -e -m` on a
2381 // directory with trailing `/` preserves it), or copied a Cargo
2382 // `path = "../caixa-teia/"` entry from cross-substrate documentation
2383 // (Cargo accepts both shapes and folds them the same way). Two
2384 // workstations whose authors differ only in tab-completion habits
2385 // emit byte-divergent lacres for the byte-identical-semantic caixa,
2386 // and the substrate's "the lacre is the build's identity" contract
2387 // (CAIXA-SDLC §III.2) silently breaks far from the source caixa.lisp.
2388 //
2389 // Same THEORY.md §V.2 render-determinism axis every prior `:caminho`
2390 // arm protects, here against the trailing-separator divergence
2391 // vector: every typed slot's accepted set excludes byte-divergent
2392 // values that round-trip to the same downstream semantic. The peer
2393 // path-shaped axes already reject trailing separators on the same
2394 // contract: [`crate::render::is_gateway_api_http_path`] gates
2395 // `:entrada :paths` against any non-canonical normalization, and
2396 // [`crate::render::is_sandboxed_relative_path`] gates the M2 typed
2397 // path-slots (`:behavior :on-*`, `:upgrade-from :state-change
2398 // :script`, `:bibliotecas`, `:exe`, `:servicos`) against shapes
2399 // whose canonical form would re-introduce determinism divergence.
2400 //
2401 // The arm fires last in the cascade because every prior arm carries
2402 // a more self-locating diagnostic on values that probe as both
2403 // (e.g. `:caminho "../foo/\0/"` ends in `/` but the load-bearing
2404 // diagnostic is the NUL byte's POSIX-syscall-rejection — the
2405 // control-char arm wins; `:caminho "/etc/passwd/"` ends in `/` but
2406 // the load-bearing diagnostic is the absolute host-layout-leak —
2407 // the absolute arm wins; `:caminho "..\caixa-teia/"` ends in `/`
2408 // but the load-bearing diagnostic is the Windows-separator cross-
2409 // OS divergence — the backslash arm wins). The arm covers every
2410 // shape where the last byte is `/` regardless of length, including
2411 // the degenerate single-`/` (which the absolute arm catches first)
2412 // and the consecutive-`//` (where every prior arm passes on the
2413 // bytes other than the trailing `/`).
2414 if caminho.as_bytes().last() == Some(&b'/') {
2415 return Err(DepError::fonte_caminho_trailing_slash(nome, caminho));
2416 }
2417 Ok(())
2418 }
2419}
2420
2421impl Dep {
2422 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:nome` scalar
2423 /// accessor every consumer of the dep-graph identity axis keys off —
2424 /// returns the author-declared `:nome` byte-string verbatim as a
2425 /// `&str`, borrowed from the typed slot's own [`String`] storage.
2426 ///
2427 /// The `:deps :nome` / `:deps-dev :nome` slot carries the DNS-1123
2428 /// label that names the target caixa (validated by [`Self::validate`]
2429 /// through the shared [`crate::render::is_dns_1123_label`] predicate,
2430 /// same accept-set the peer caixa-identifier axes carry — top-level
2431 /// [`crate::Caixa::nome`], per-`:membros` [`crate::Membro::nome`],
2432 /// per-`:children` [`crate::supervisor::ChildSpec::nome`]). Every
2433 /// downstream consumer that fans on the dep's name-identity keys off
2434 /// this scalar: the [`crate::Caixa::validate_deps`] per-list
2435 /// [`crate::render::insert_first_seen`] dedup key + the paired
2436 /// [`DepError::DuplicateNome`] carrier the walk raises on collision,
2437 /// the cross-list [`validate_no_self_dep`] parent-name equality gate
2438 /// on both `:deps` and `:deps-dev` traversals, the `caixa-resolver`
2439 /// pipeline's `HashSet<String>` seen-set the closure walker gates
2440 /// requeueing off (`caixa-resolver/src/resolve.rs:55`), the resolver's
2441 /// per-transitive-target requeue path (`resolve.rs:63,66`), the
2442 /// [`crate::DepSource::default_github`]-shaped resolver-side shorthand
2443 /// fill-in that folds `:nome` into the fetched-git-URL (`resolve.rs:147`),
2444 /// every `caixa-resolver` `ResolveError::MissingPath` /
2445 /// `ResolveError::MissingPin` carrier that names the offending dep
2446 /// (`resolve.rs:177,206`), each resolved
2447 /// `caixa-lacre::LacreEntry` `nome:` field the closure hash keys off
2448 /// (`resolve.rs:108,113`), and the peer `feira lock` stub-resolver's
2449 /// `LacreEntry` emitter (`caixa-feira/src/cmd/lock.rs:59,61,64`).
2450 ///
2451 /// Prior to this lift the `.nome` byte-string was read inline at every
2452 /// production site — the [`crate::Caixa::validate_deps`] paired
2453 /// `dep.nome.as_str()` / `dep.nome.clone()` accesses on both `:deps`
2454 /// and `:deps-dev` traversals, the [`validate_no_self_dep`] pair of
2455 /// parent-equality checks, and every caixa-resolver / caixa-feira
2456 /// site enumerated above — open-coded field-accesses that expressed
2457 /// no compile-time link back to the typed slot. A future extension of
2458 /// the `:deps :nome` axis to a richer author surface (a per-scope
2459 /// alias table the resolver folds through the `~/.config/caixa/config.yaml`
2460 /// entry the [`crate::dep::Dep`] docstring already acknowledges, a
2461 /// namespace-qualified rewrite the future M4 lacre-federation layer
2462 /// applies per-cluster, a promotion of the plain [`String`] byte-string
2463 /// to a richer scoped-identifier newtype once cross-registry federation
2464 /// lands) would have had to be threaded through every open-coded copy
2465 /// in lockstep or two consumers would silently disagree on which caixa
2466 /// a given dep resolves to — the [`crate::Caixa::validate_deps`] dedup
2467 /// set treating the name as `"caixa-teia"` while the caixa-resolver
2468 /// closure walker treated it as `"tenant-a/caixa-teia"` would silently
2469 /// split the [`DepError::DuplicateNome`] refusal from the resolver's
2470 /// requeue-suppression seen-set, one build-time diagnostic
2471 /// disagreeing with the run-time closure the substrate's lacre
2472 /// pipeline actually materializes. Lifting the resolution rule to a
2473 /// typed method on the substrate primitive means every downstream
2474 /// consumer of the caixa's per-`:deps` identity surface reaches for
2475 /// exactly one typed dispatch — the resolver's accept-set migrates as
2476 /// a unit on any future axis addition.
2477 ///
2478 /// First accessor on the outer `Dep` type — opens the outer-`Dep`
2479 /// `&str`-return required-scalar projection pattern the sibling
2480 /// per-`Dep` `:versao` future lift folds on. Peer of the sibling
2481 /// per-`:membros` [`crate::Membro::nome`] (4a32abf) /
2482 /// per-`:children` [`crate::supervisor::ChildSpec::nome`] (dfb4a81)
2483 /// / top-level [`crate::Caixa::nome`] (e6b7d97) caixa-identity scalar
2484 /// accessors — same "one typed dispatch on the substrate primitive,
2485 /// thin projections at each consumer" discipline extended onto the
2486 /// third named-caixa-referencing axis (`:deps` / `:deps-dev`), the
2487 /// remaining unlifted caixa-name-referencing accessor family in the
2488 /// substrate. Named `nome()` to match the tatara-lisp author-surface
2489 /// term the field's docstring already reaches for ("Caixa name — must
2490 /// match the target caixa's `:nome`") and the peer caixa-identity
2491 /// accessor family the substrate already carries.
2492 #[must_use]
2493 pub const fn nome(&self) -> &str {
2494 self.nome.as_str()
2495 }
2496
2497 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:versao`
2498 /// Cargo-shaped semver-requirement scalar accessor every consumer of
2499 /// the dep-graph version-pin axis keys off — returns the author-
2500 /// declared `:versao` requirement byte-string verbatim as a `&str`,
2501 /// borrowed from the typed slot's own [`String`] storage.
2502 ///
2503 /// The `:deps :versao` / `:deps-dev :versao` slot carries the
2504 /// Cargo-shaped semver requirement string (`"^0.1"`, `"~0.1.2"`,
2505 /// `"0.1.0"`, `"*"`) the shared [`crate::version::parse_requirement`]
2506 /// entry-point consumes — same accept-set the peer requirement-
2507 /// carrying axes carry (per-`:membros`
2508 /// [`crate::Membro::versao_requirement`], per-`:children`
2509 /// [`crate::supervisor::ChildSpec::versao_requirement`]), validated
2510 /// through the shared
2511 /// [`crate::render::require_valid_versao_requirement`] cascade in
2512 /// [`Self::validate`]. Every downstream consumer that fans on the
2513 /// dep's version-pin keys off this scalar: the [`Self::validate`]
2514 /// `require_valid_versao_requirement` gate + the paired
2515 /// [`DepError::VersaoInvalid`] carrier the cascade raises on
2516 /// requirement-shape rejection, the `feira lock` stub-resolver's
2517 /// `format!("{}@{}", dep.nome(), dep.versao_requirement())`
2518 /// `conteudo` hash-input interpolation and the paired
2519 /// `LacreEntry.versao:` `String`-carry fill (`caixa-feira/src/cmd/lock.rs`),
2520 /// and the peer `feira lock` end-to-end fixture in `caixa-feira/tests/feira_e2e.rs`.
2521 ///
2522 /// Prior to this lift the `.versao` byte-string was read inline at
2523 /// every production site — the [`Self::validate`] paired
2524 /// `&self.versao` requirement-gate reference and `self.versao.clone()`
2525 /// error-body carrier, the `caixa-feira/src/cmd/lock.rs` paired
2526 /// `format!("{}@{}", dep.nome(), dep.versao)` `conteudo` interpolation
2527 /// and `versao: dep.versao.clone()` `LacreEntry` fill, and the
2528 /// `caixa-feira/tests/feira_e2e.rs` end-to-end fixture's pair of the
2529 /// same shapes — open-coded field-accesses that expressed no
2530 /// compile-time link back to the typed slot. A future extension of
2531 /// the `:deps :versao` axis to a richer author surface (a per-scope
2532 /// version-lock overlay the resolver folds through the
2533 /// `~/.config/caixa/config.yaml` entry the [`crate::dep::Dep`]
2534 /// docstring already acknowledges, a per-cluster canary-version
2535 /// overlay per MESH-COMPOSITION §III.2, a promotion of the plain
2536 /// [`String`] requirement to a richer parsed-`VersionReq` newtype
2537 /// once cross-registry federation lands) would have had to be
2538 /// threaded through every open-coded copy in lockstep or two
2539 /// consumers would silently disagree on which release constraint a
2540 /// given dep resolves to — the [`Self::validate`] requirement-gate
2541 /// call reading `"^0.1"` while the `feira lock` stub-resolver's
2542 /// `conteudo` hash-input read `"tenant-a-pin/^0.1"` would silently
2543 /// split the [`DepError::VersaoInvalid`] refusal from the lacre's
2544 /// content-addressed hash the substrate's fetch pipeline actually
2545 /// materializes, one build-time diagnostic disagreeing with the
2546 /// run-time closure. Lifting the resolution rule to a typed method
2547 /// on the substrate primitive means every downstream consumer of
2548 /// the caixa's per-`:deps` version-pin surface reaches for exactly
2549 /// one typed dispatch — the resolver's accept-set migrates as a
2550 /// unit on any future axis addition.
2551 ///
2552 /// Second accessor on the outer `Dep` type — folds on the outer-
2553 /// `Dep` `&str`-return required-scalar projection pattern the
2554 /// sibling per-`Dep` [`Self::nome`] (eba2cde) accessor opened. Peer
2555 /// of the per-`:membros` [`crate::Membro::versao_requirement`]
2556 /// (a40b0e3) / per-`:children`
2557 /// [`crate::supervisor::ChildSpec::versao_requirement`] (7844f4e
2558 /// family) member/child version-pin accessors — the three
2559 /// requirement-carrying axes (`Dep::versao_requirement` on the
2560 /// per-caixa dep-graph edge, `Membro::versao_requirement` on the M3
2561 /// Aplicacao side, `ChildSpec::versao_requirement` on the M2
2562 /// Supervisor side) now share one accessor discipline for the
2563 /// shared substrate concept "another caixa referenced by a
2564 /// Cargo-shaped semver requirement". The pair
2565 /// `(nome(), versao_requirement())` jointly projects the
2566 /// `(nome, versao)` field pair every dep-graph consumer that fans
2567 /// on per-dep identity + version pin keys off. Named
2568 /// `versao_requirement()` rather than `versao()` because the field's
2569 /// storage-side `.versao` label is already the author-surface term
2570 /// (`:versao`); the accessor's name carries the semantic role — the
2571 /// semver *requirement* string the shared
2572 /// [`crate::version::parse_requirement`] entry-point consumes — so a
2573 /// raw field access and a typed dispatch read differently at every
2574 /// consumer site. Matches the peer
2575 /// [`crate::Membro::versao_requirement`] /
2576 /// [`crate::supervisor::ChildSpec::versao_requirement`] naming
2577 /// discipline verbatim.
2578 #[must_use]
2579 pub const fn versao_requirement(&self) -> &str {
2580 self.versao.as_str()
2581 }
2582
2583 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:fonte`
2584 /// Zig-store-model per-dep source-tuple optional-composite-reference
2585 /// accessor every consumer of the dep-graph fetch-source axis keys
2586 /// off — returns the author-declared `:fonte` typed [`DepSource`]
2587 /// verbatim as an `Option<&DepSource>` borrowed from the typed slot's
2588 /// own `Option<DepSource>` storage, with `None` naming the "author
2589 /// omitted `:fonte`" shorthand every resolver-side default-fill
2590 /// (`caixa-feira/src/cmd/lock.rs`'s stub, `caixa-resolver/src/resolve.rs`'s
2591 /// canonical fetcher, per the [`DepSource::default_github`] fallback
2592 /// the [`Dep::fonte`] field docstring already documents) treats as
2593 /// the "resolve through the configured default host / org
2594 /// (`github:<default-org>/<nome>`)" partition.
2595 ///
2596 /// The `:deps :fonte` / `:deps-dev :fonte` slot carries the two-
2597 /// arm typed [`DepSource`] the `Zig-style git-only store model` the
2598 /// enclosing [`Dep`] docstring names — `DepSource::Git { repo, tag,
2599 /// rev, branch }` for the git-clone arm every published caixa
2600 /// resolves through, `DepSource::Path { caminho }` for the dev-only
2601 /// local-filesystem arm every unpublishable in-tree checkout
2602 /// resolves through. Every downstream consumer that fans on the
2603 /// dep's fetch-source keys off this accessor: [`Self::validate`]'s
2604 /// per-`:fonte` [`DepSource::validate`] delegation (which raises
2605 /// the empty-`:repo` / missing-pin / multiple-pin / empty-`:caminho`
2606 /// diagnostics through the [`DepError::Fonte*`] carrier family
2607 /// naming the offending `Dep::nome`), the caixa-crd conversion
2608 /// crate's `dep_into_ref` two-arm projection into the `CaixaSource`
2609 /// `{repo, git_ref}` pair the K8s-CR side consumes
2610 /// (`caixa-crd/src/conversion.rs`), and — through the paired
2611 /// resolver-side default-fill's `Option::unwrap_or_else` — every
2612 /// `caixa-feira` / `caixa-resolver` fetch site that requires a
2613 /// concrete `DepSource` at run time.
2614 ///
2615 /// Prior to this lift the `.fonte` typed slot was read inline at
2616 /// every production site — the [`Self::validate`]
2617 /// `if let Some(ref fonte) = self.fonte` bracket the per-`:fonte`
2618 /// gate delegates through, the caixa-crd `dep_into_ref`
2619 /// `d.fonte.as_ref().and_then(...)` two-arm `CaixaSource` projector,
2620 /// the resolver-side `caixa-feira/src/cmd/lock.rs` / `caixa-resolver/src/resolve.rs`
2621 /// `dep.fonte.clone().unwrap_or_else(...)` default-fill pair — open-
2622 /// coded field-accesses that expressed no compile-time link back to
2623 /// the typed slot. A future extension of the `:deps :fonte` axis
2624 /// to a richer author surface (a per-scope source-override table
2625 /// the resolver folds through the `~/.config/caixa/config.yaml`
2626 /// entry the [`Dep`] docstring already acknowledges, a per-org
2627 /// mirror-fallback list the future M4 lacre-federation resolver
2628 /// consults ahead of the `default_github` fallback, a promotion of
2629 /// the plain `Option<DepSource>` to a richer
2630 /// `{primary, mirrors, integrity}` triple once cross-registry
2631 /// federation lands, a per-dep `sri:sha256-…` integrity slot the
2632 /// M4 lacre gate binds against ahead of the git-fetch) would have
2633 /// had to be threaded through every open-coded copy in lockstep or
2634 /// two consumers would silently disagree on which fetch source a
2635 /// given dep resolves to — the [`Self::validate`] per-`:fonte`
2636 /// gate reading the author-declared source while the caixa-crd
2637 /// projector read a per-scope-override-resolved source would
2638 /// silently split the build-time refusal from the CR the
2639 /// substrate's admission pipeline actually materializes, one
2640 /// build-time diagnostic disagreeing with the run-time closure.
2641 /// Lifting the resolution rule to a typed method on the substrate
2642 /// primitive means every downstream consumer of the caixa's per-
2643 /// `:deps` fetch-source surface reaches for exactly one typed
2644 /// dispatch — the resolver's accept-set migrates as a unit on any
2645 /// future axis addition.
2646 ///
2647 /// First outer-`Dep` `Option<&Composite>`-return composite-reference
2648 /// accessor — opens the outer-`Dep` `Option<&Composite>` composite-
2649 /// reference projection pattern the sibling per-`Dep` `:opcional`
2650 /// (`Option<Copy>` — the plain-bool axis) / `:caracteristicas`
2651 /// (`&[String]` — the feature-flag list) future outer scalar / slice
2652 /// lifts fold on. Peer of the outer-top-level [`crate::Caixa`]
2653 /// `Option<&Composite>` composite-reference sub-family the
2654 /// [`crate::Caixa::limits`] (b2bd9d7) / [`crate::Caixa::behavior`]
2655 /// (35d8b52) / [`crate::Caixa::politicas`] (5d23d29) /
2656 /// [`crate::Caixa::placement`] (4fb8074) / [`crate::Caixa::entrada`]
2657 /// (e4128e4) accessors already close on the outer [`crate::Caixa`]
2658 /// altitude, and of the outer M3 mesh-slot [`crate::AplicacaoSpec`]
2659 /// altitude the sibling [`crate::AplicacaoSpec::entrada`] (d32111c)
2660 /// accessor already carries — extends that "one typed dispatch on
2661 /// the substrate primitive, thin projections at each consumer"
2662 /// discipline onto the third outer typed-slot altitude that carries
2663 /// an `Option<Composite>` axis (`Dep`, the outer per-dep-list-entry
2664 /// slot). Returns `Option<&DepSource>` (not the owning composite by
2665 /// copy or clone) because every downstream consumer of the fonte
2666 /// composite treats it as a read-only per-arm dispatch source — the
2667 /// reference-view is the narrowest borrow that supports every
2668 /// present + roadmapped consumer (per-arm match projection at the
2669 /// caixa-crd `CaixaSource` two-arm emitter, presence-probe early
2670 /// return on the "author-omitted `:fonte` ⇒ resolver-side
2671 /// `default_github` fill applies" partition every resolver
2672 /// consults, `.cloned()`-on-demand for the two resolver-side
2673 /// default-fill call sites that require an owned `DepSource` for
2674 /// `Option::unwrap_or_else`) without cloning the composite through
2675 /// every consumer's fast path. The `Option` half of the return-type
2676 /// preserves the load-bearing "author-omitted `:fonte` ⇒ resolver-
2677 /// side default applies" partition (not a default composite the
2678 /// downstream must reject on emptiness) — the accessor projects the
2679 /// raw `Option<DepSource>` slot's presence bit through the
2680 /// reference-return unchanged. Named `fonte()` to match the storage
2681 /// field's name verbatim and the tatara-lisp author-surface term
2682 /// (`:fonte`) the field's own docstring already carries.
2683 ///
2684 /// Declared `pub const fn` — the body projects through
2685 /// `Option::<DepSource>::as_ref`, const-stable since Rust 1.83 and
2686 /// well within the workspace MSRV, so every downstream `const`-
2687 /// context consumer of the per-`Dep` `:fonte` composite-reference
2688 /// accessor reaches through the same typed dispatch on the
2689 /// substrate primitive at const-eval time as at runtime. The
2690 /// paired [`dep_outer_accessor_family_is_const_fn`][pin] pin
2691 /// (a `const fn <name>_via_const_fn(d: &Dep) -> …` wrapper family
2692 /// that forwards through each lifted accessor) locks the posture
2693 /// load-bearing at caixa-core build time — any future accidental
2694 /// downgrade to non-`const` fails the wrapper with E0015
2695 /// (`cannot call non-const method`), strictly stronger than a
2696 /// runtime `assert!` and side-stepping the destructor-in-const
2697 /// restriction the `Dep` fixture's `String` / `Option<DepSource>`
2698 /// / `Vec<String>` carriers rule out. Peer of the sibling per-
2699 /// `WitContract` pre-projection accessor family's `const`-eval-
2700 /// surface pass (279823b) and of the outer-`Caixa` slice-return
2701 /// accessor family's parallel pass (231a968) — same "one canonical
2702 /// dispatch per axis, `const`-eval posture pinned at the substrate
2703 /// primitive, thin projections at each consumer" discipline
2704 /// extended onto the outer per-dep-list-entry [`Dep`] altitude.
2705 ///
2706 /// [pin]: tests::dep_outer_accessor_family_is_const_fn
2707 #[must_use]
2708 pub const fn fonte(&self) -> Option<&DepSource> {
2709 self.fonte.as_ref()
2710 }
2711
2712 /// Substrate-canonical per-`:deps` / `:deps-dev` entry
2713 /// `:caracteristicas` Cargo-shaped feature-toggle-set slice accessor
2714 /// every consumer of the dep-graph feature-flag axis keys off —
2715 /// returns the author-declared `:caracteristicas` feature-name list
2716 /// verbatim as a `&[String]` slice-view over the same backing buffer
2717 /// the raw `self.caracteristicas.as_slice()` field access borrows
2718 /// from. Empty-list-carrying (`:caracteristicas` is a default-empty
2719 /// axis every `Dep` supplies with `Vec::new()` when the author omits
2720 /// the slot; the [`crate::Caixa::from_lisp`] derive folds an omitted
2721 /// `:caracteristicas` through `#[serde(default)]` to `Vec::new()`,
2722 /// so a `Dep` past parse definitionally carries a `Vec<String>` slot
2723 /// — possibly empty — and the returned `&[String]` degenerates to
2724 /// an empty slice on that arm without any silent `None` collapse).
2725 ///
2726 /// The `:deps :caracteristicas` / `:deps-dev :caracteristicas` slot
2727 /// carries the set-shaped feature-toggle list the substrate walks
2728 /// through the [`Self::validate_caracteristicas`] per-entry shape +
2729 /// duplicate cascade — same Cargo `[dependencies.<dep>.features]`
2730 /// accept-set (per-entry Cargo-feature-name grammar via the shared
2731 /// [`crate::render::is_cargo_feature_name`] predicate, cross-entry
2732 /// uniqueness via the shared [`crate::render::insert_first_seen`]
2733 /// walk, empty-first / value-shape-second / duplicate-third
2734 /// precedence via the peer per-axis two-arm cascade discipline every
2735 /// substrate-blessed Vec-keyed-by-name slot already follows).
2736 /// Every downstream consumer that fans on the dep's feature-toggle
2737 /// keys off this accessor: [`Self::validate_caracteristicas`]'s
2738 /// per-entry linear walk that gates each feature-name byte-string
2739 /// through the empty / value-shape / duplicate arms (raising the
2740 /// [`DepError::CaracteristicaEmpty`] / [`DepError::CaracteristicaInvalid`]
2741 /// / [`DepError::CaracteristicaDuplicate`] carrier family naming the
2742 /// offending `Dep::nome`), and every future
2743 /// per-`Caixa`-manifest / caixa-resolver / caixa-crd feature-toggle-
2744 /// facing consumer the CAIXA-SDLC §I roadmap acknowledges (the
2745 /// future caixa-resolver per-dep feature-projection walk that folds
2746 /// the toggle set into the resolved [`crate::Caixa`]'s activated
2747 /// [`crate::render::CARGO_FEATURE_NAME_MAX_LEN`]-bounded feature
2748 /// closure ahead of the lacre hash, the future caixa-crd per-`spec.deps`
2749 /// features slice the K8s-CR admission gate consumes, the future
2750 /// per-cluster feature-overlay the M4 lacre-federation resolver
2751 /// composes ahead of the substrate-wide feature-name accept-set).
2752 ///
2753 /// Prior to this lift the `.caracteristicas` byte-string list was
2754 /// read inline at the [`Self::validate_caracteristicas`] `for c in
2755 /// &self.caracteristicas` walk — the only in-crate consumer of the
2756 /// raw field beyond the per-`Dep` constructor pair
2757 /// ([`Self::simple`] / [`Self::git`]) and the paired serde
2758 /// round-trip / per-test fixture-mutation paths — an open-coded
2759 /// field-access that expressed no compile-time link back to the
2760 /// typed slot. A future extension of the `:caracteristicas` axis to
2761 /// a richer author surface (a per-scope feature-overlay the resolver
2762 /// folds through the `~/.config/caixa/config.yaml` entry the
2763 /// [`Dep`] docstring already acknowledges, a per-cluster feature-
2764 /// activation overlay the future M4 lacre-federation layer applies
2765 /// per-CR, a promotion of the plain `Vec<String>` byte-string list
2766 /// to a richer parsed-feature-set newtype once the Cargo-shaped
2767 /// namespaced-dep `dep/feat` syntax the value-shape gate's
2768 /// docstring anticipates lands) would have had to be threaded
2769 /// through every open-coded copy in lockstep or two consumers
2770 /// would silently disagree on which feature closure a given dep
2771 /// activates — the [`Self::validate_caracteristicas`] gate walking
2772 /// the author-declared list while a downstream caixa-resolver
2773 /// consumer walked a per-scope-override-resolved list would
2774 /// silently split the build-time refusal from the lacre closure
2775 /// the substrate's fetch pipeline actually materializes, one
2776 /// build-time diagnostic disagreeing with the run-time closure.
2777 /// Lifting the resolution rule to a typed method on the substrate
2778 /// primitive means every downstream consumer of the caixa's per-
2779 /// `:deps` feature-toggle surface reaches for exactly one typed
2780 /// dispatch — the resolver's accept-set migrates as a unit on any
2781 /// future axis addition.
2782 ///
2783 /// First outer-`Dep` `&[T]`-return slice accessor — opens the
2784 /// outer-`Dep` `&[String]` slice projection pattern the sibling
2785 /// per-`Dep` `:opcional` (`bool` — the plain-`Copy`-scalar axis)
2786 /// future outer scalar lift folds on and closes the outer-`Dep`
2787 /// slot-family the sibling [`Self::nome`] (eba2cde) /
2788 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2789 /// accessors already open, leaving the `:opcional` `Copy`-scalar arm
2790 /// as the sole remaining unlifted outer-`Dep` slot. Peer of the
2791 /// outer top-level [`crate::Caixa`] `&[String]`-return foreign-code-
2792 /// slot sub-family ([`crate::Caixa::bibliotecas`] 8a36c23,
2793 /// [`crate::Caixa::exe`] 65d9527, [`crate::Caixa::servicos`]
2794 /// 611f78b) and the outer top-level [`crate::Caixa`] universal-axis
2795 /// text-tag family ([`crate::Caixa::autores`] b5d813f,
2796 /// [`crate::Caixa::etiquetas`] 78c7d3c) that already carry the
2797 /// `&[String]` slice-projection discipline on the outer-`Caixa`
2798 /// altitude — extends the "one typed dispatch on the substrate
2799 /// primitive, thin projections at each consumer" discipline onto the
2800 /// outer per-dep-list-entry [`Dep`] altitude's set-shaped byte-
2801 /// string list slot. Returns `&[String]` (not `&Vec<String>`)
2802 /// because every downstream consumer of the feature-toggle list
2803 /// treats it as a read-only sequence — the slice-view is the
2804 /// narrowest borrow that supports every present + roadmapped
2805 /// consumer (`.iter()`, `.len()`, `.is_empty()`) without leaking
2806 /// the backing `Vec`'s grow/push/reserve surface no consumer of
2807 /// the typed view reaches for (the storage-side `Vec` remains
2808 /// reachable through the `pub caracteristicas` field for the
2809 /// mutation-carrying serde round-trip and per-test fixture-mutation
2810 /// paths). Named `caracteristicas()` to match the storage field's
2811 /// name verbatim and the tatara-lisp author-surface term
2812 /// (`:caracteristicas`) the field's own docstring already carries.
2813 ///
2814 /// Declared `pub const fn` — the body projects through
2815 /// `Vec::<String>::as_slice`, const-stable since Rust 1.83 and
2816 /// well within the workspace MSRV, so every downstream `const`-
2817 /// context consumer of the per-`Dep` `:caracteristicas` slice-
2818 /// accessor reaches through the same typed dispatch on the
2819 /// substrate primitive at const-eval time as at runtime. Pinned
2820 /// load-bearing by the paired
2821 /// [`dep_outer_accessor_family_is_const_fn`][pin] wrapper family
2822 /// alongside its sibling [`Self::fonte`] — see [`Self::fonte`] for
2823 /// the full pin-shape rationale.
2824 ///
2825 /// [pin]: tests::dep_outer_accessor_family_is_const_fn
2826 #[must_use]
2827 pub const fn caracteristicas(&self) -> &[String] {
2828 self.caracteristicas.as_slice()
2829 }
2830
2831 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:opcional`
2832 /// missing-source-tolerance flag scalar accessor every consumer of
2833 /// the dep-graph opt-in-fetch axis keys off — returns the author-
2834 /// declared `:opcional` `bool` verbatim, `Copy`-projected from the
2835 /// typed slot's own `bool` storage (no borrow of `&self` past the
2836 /// call; the `Copy`-return arm matches the peer
2837 /// [`crate::Caixa::max_restarts`] (eba5211) `Option<u32>` `Copy`-
2838 /// projected sibling discipline the outer flat-spread family
2839 /// already carries). Default-`false` (`#[serde(default,
2840 /// skip_serializing_if = "is_false")]` on the storage slot, so a
2841 /// `Dep` past parse definitionally carries a `bool` — `false` when
2842 /// the author omits `:opcional` — and the returned value degenerates
2843 /// to `false` on that arm without any silent `None` collapse).
2844 ///
2845 /// The `:deps :opcional` / `:deps-dev :opcional` slot carries the
2846 /// per-entry "if this dep's `:fonte` cannot be resolved, treat the
2847 /// missing-source arm as a soft-fail rather than a build refusal"
2848 /// bit — the same Cargo-shaped `[dependencies.<dep>.optional = true]`
2849 /// accept-set (an opcional dep whose `:fonte` fails to resolve is
2850 /// dropped from the resolved dep-graph rather than tripping the
2851 /// build-refusal edge that a mandatory `:opcional false` entry
2852 /// would). Every downstream consumer that fans on the dep's
2853 /// missing-source-tolerance keys off this accessor: the future
2854 /// caixa-resolver's per-`:fonte` resolve-fail arm (drop-vs-error
2855 /// dispatch on the opcional bit ahead of the lacre closure
2856 /// materialization), the future caixa-crd per-`spec.deps`
2857 /// `optional` boolean the K8s-CR admission gate consumes on the
2858 /// per-dep partition, and the future feira / caixa-resolver /
2859 /// caixa-crd feature-projection walk that folds the opcional bit
2860 /// into the resolved feature-closure the future M4 lacre-federation
2861 /// layer emits.
2862 ///
2863 /// Prior to this lift the `.opcional` `bool` slot was read inline
2864 /// at the sole in-crate consumer site — the tests-module
2865 /// `registry_dep_is_minimal` fixture's `assert!(!d.opcional)` gate
2866 /// pinning the [`Self::simple`] constructor's default-`false` fill
2867 /// (the only in-crate read of the raw field beyond the per-`Dep`
2868 /// constructor pair [`Self::simple`] / [`Self::git`] and the paired
2869 /// serde round-trip / per-test fixture-mutation paths) — an open-
2870 /// coded field-access that expressed no compile-time link back to
2871 /// the typed slot. A future extension of the `:opcional` axis to a
2872 /// richer author surface (a per-scope opcional-override the resolver
2873 /// folds through the `~/.config/caixa/config.yaml` entry the [`Dep`]
2874 /// docstring already acknowledges, a per-cluster opcional-override
2875 /// the future M4 lacre-federation layer applies per-CR, a promotion
2876 /// of the plain `bool` to a richer `OpcionalPolicy { drop, warn,
2877 /// error }` tri-state once the CAIXA-SDLC §II opcional-policy
2878 /// roadmap lands) would have had to be threaded through every open-
2879 /// coded copy in lockstep or two consumers would silently disagree
2880 /// on which missing-source arm a given dep resolves to — the
2881 /// [`Self::simple`] constructor's default-`false` fill reading
2882 /// verbatim while a downstream caixa-resolver consumer read a per-
2883 /// scope-override-resolved bit would silently split the build-time
2884 /// arm from the lacre closure the substrate's fetch pipeline
2885 /// actually materializes, one build-time diagnostic disagreeing
2886 /// with the run-time closure. Lifting the resolution rule to a
2887 /// typed method on the substrate primitive means every downstream
2888 /// consumer of the caixa's per-`:deps` opcional-tolerance surface
2889 /// reaches for exactly one typed dispatch — the resolver's accept-
2890 /// set migrates as a unit on any future axis addition.
2891 ///
2892 /// Fifth and final outer-`Dep` accessor — closes the outer-`Dep`
2893 /// slot-family the sibling per-`Dep` [`Self::nome`] (eba2cde) /
2894 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2895 /// / [`Self::caracteristicas`] (9197944) accessors opened, so every
2896 /// outer-`Dep` slot (`:nome`, `:versao`, `:fonte`, `:opcional`,
2897 /// `:caracteristicas`) now routes through exactly one typed
2898 /// dispatch on the substrate primitive. First outer-`Dep`
2899 /// `bool`-return / plain-`Copy`-scalar accessor — opens the
2900 /// outer-`Dep` `Copy`-scalar projection pattern that folds on the
2901 /// peer outer-top-level [`crate::Caixa`] `Option<Copy>`
2902 /// flat-spread sub-family ([`crate::Caixa::max_restarts`] eba5211,
2903 /// [`crate::Caixa::estrategia`] ed04d3c) the outer-`Caixa` altitude
2904 /// already carries — extends the "one typed dispatch on the
2905 /// substrate primitive, thin projections at each consumer"
2906 /// discipline onto the outer per-dep-list-entry [`Dep`] altitude's
2907 /// bool-shaped missing-source-tolerance slot. Returns `bool` by
2908 /// `Copy` (not by `&bool` reference) because `bool` is `Copy` and
2909 /// every downstream consumer treats it as a plain discriminant
2910 /// value — the by-value return is the narrowest return-shape that
2911 /// supports every present + roadmapped consumer (`.then(…)` early
2912 /// return on the resolver-side drop-vs-error partition, direct
2913 /// bool composition with a per-scope-override projector, plain
2914 /// `if dep.opcional() { … }` early return at every future admission
2915 /// gate) without leaking the storage field's `bool`-in-`&self`
2916 /// lifetime the by-value return elides. Marked `pub const fn` so
2917 /// the accessor is `const`-callable — same discipline the peer
2918 /// [`crate::Caixa::max_restarts`] `Option<u32>` `Copy`-return
2919 /// accessor carries. Named `opcional()` to match the storage
2920 /// field's name verbatim and the tatara-lisp author-surface term
2921 /// (`:opcional`) the field's own docstring already carries.
2922 #[must_use]
2923 pub const fn opcional(&self) -> bool {
2924 self.opcional
2925 }
2926
2927 /// Build a minimal registry-sourced dep.
2928 #[must_use]
2929 pub fn simple(nome: impl Into<String>, versao: impl Into<String>) -> Self {
2930 Self {
2931 nome: nome.into(),
2932 versao: versao.into(),
2933 fonte: None,
2934 opcional: false,
2935 caracteristicas: Vec::new(),
2936 }
2937 }
2938
2939 /// Build a Git-sourced dep (tag-based).
2940 #[must_use]
2941 pub fn git(
2942 nome: impl Into<String>,
2943 versao: impl Into<String>,
2944 repo: impl Into<String>,
2945 tag: impl Into<String>,
2946 ) -> Self {
2947 Self {
2948 nome: nome.into(),
2949 versao: versao.into(),
2950 fonte: Some(DepSource::Git {
2951 repo: repo.into(),
2952 tag: Some(tag.into()),
2953 rev: None,
2954 branch: None,
2955 }),
2956 opcional: false,
2957 caracteristicas: Vec::new(),
2958 }
2959 }
2960
2961 /// Reject dependency entries whose `:nome` or `:versao` are empty,
2962 /// whose `:nome` is non-empty but not a valid DNS-1123 label,
2963 /// or whose `:versao` is non-empty but not a valid Cargo-shaped
2964 /// semver requirement.
2965 ///
2966 /// The author surface for `:deps :versao` (and `:deps-dev :versao`)
2967 /// is the same Cargo-shaped requirement string `:membros :versao`
2968 /// (validated at [`crate::AplicacaoSpec::validate`] since 9888b13)
2969 /// and `:children :versao` (validated at
2970 /// [`crate::SupervisorSpec::validate`] since b38ff3a) carry — and
2971 /// the lacre pipeline resolves all three axes through the same
2972 /// [`crate::parse_requirement`] entry-point. Until 2420c44 landed
2973 /// `:deps :versao` was the last `:versao` axis untyped past
2974 /// `Caixa::from_lisp`: a malformed-but-non-empty requirement
2975 /// (`"^bad-version"`, `"^^0.1"`, the canonical git-tag-shape-
2976 /// leaking-into-:versao `"v0.1"` typo, the accidental
2977 /// `"not-a-req"`) silently passed parse and the `semver::Error`
2978 /// surfaced at lacre-resolve time, far from the source
2979 /// caixa.lisp, with no field naming which `:deps` entry carried
2980 /// the typo. The diagnostic [`DepError::VersaoInvalid`] carries
2981 /// the offending entry's `:nome` + the offending `:versao`
2982 /// verbatim + the parser's own wording in `reason`, so the
2983 /// author's grep target is unambiguous.
2984 ///
2985 /// The author surface for `:deps :nome` is the same DNS-1123 label
2986 /// the peer caixa-identifier axes carry — top-level Caixa `:nome`
2987 /// (validated at [`crate::Caixa::validate_nome`] since 6c992f8),
2988 /// `:membros :caixa` (validated at
2989 /// [`crate::AplicacaoSpec::validate_membros`] since 3f9d7a0),
2990 /// `:children :caixa` (validated at
2991 /// [`crate::SupervisorSpec::validate`] since 31bfa43). A `:deps
2992 /// :nome` value flows verbatim through the lacre pipeline as the
2993 /// target caixa's `:nome` (which the gate at the *target* side now
2994 /// rejects if non-DNS-1123) and lands as the rendered caixa's
2995 /// `lareira-<nome>` Helm chart name segment, the per-dep
2996 /// `LABEL_PROGRAM` label value, and the `caixa-resolver`'s
2997 /// `~/.cache/caixa/<org>/<nome>` checkout-directory leaf. Until
2998 /// this gate landed `:deps :nome` was the fourth and last
2999 /// DNS-1123-shaped caixa-identifier axis still untyped past
3000 /// `Caixa::from_lisp`: a syntactically wrong dep name (`"Caixa-
3001 /// Teia"` uppercase — the canonical "I copied the README header"
3002 /// typo; `"caixa_teia"` underscore — the Go module / Python
3003 /// identifier leak; `"caixa-teia."` trailing dot — the FQDN
3004 /// confusion; `"-caixa-teia"` leading hyphen; a 64-byte slug)
3005 /// silently passed parse and surfaced at lacre-resolve time when
3006 /// the resolved target caixa's `:nome` failed *its* DNS-1123 gate
3007 /// — far from the source `:deps` entry, with a diagnostic naming
3008 /// the *target's* `:nome` rather than the dep entry that referenced
3009 /// it. Mirroring the 3f9d7a0 / 31bfa43 / 6c992f8 trajectory through
3010 /// the lifted [`crate::render::is_dns_1123_label`] predicate (the
3011 /// "before its third occurrence" PRIME DIRECTIVE boundary, THEORY.md
3012 /// §I.3.5): every `Dep::nome` past validate is DNS-1123-label-shaped,
3013 /// so every downstream consumer (caixa-resolver's lacre fetch,
3014 /// caixa-helm's `lareira-<nome>` chart name, the future M4 per-dep
3015 /// fan-out emitter) reaches for the name knowing the value is
3016 /// apiserver-valid without re-validating.
3017 ///
3018 /// Empty checks fire first (narrower diagnostic), parse last —
3019 /// same ordering discipline as
3020 /// [`crate::AplicacaoSpec::validate_membros`] and
3021 /// [`crate::SupervisorSpec::validate`]. `parse_requirement("")`
3022 /// returns `Ok(VersionReq::STAR)`, so the empty-`:versao` arm is
3023 /// structurally necessary even with the parse arm in place. The
3024 /// `:nome` shape gate runs after the `:nome` empty gate and before
3025 /// the `:versao` checks so a one-entry caixa.lisp with both wrong
3026 /// sees the name-side diagnostic first (the name is the
3027 /// self-locating axis — without it, the parse diagnostic can't
3028 /// quote `:nome "<bad>"`).
3029 pub fn validate(&self) -> Result<(), DepError> {
3030 if self.nome.is_empty() {
3031 return Err(DepError::NomeEmpty);
3032 }
3033 if let Err(reason) = crate::render::is_dns_1123_label(&self.nome) {
3034 return Err(DepError::NomeInvalid {
3035 nome: self.nome.clone(),
3036 reason,
3037 });
3038 }
3039 // Delegate the empty-first + `parse_requirement` cascade to the
3040 // shared [`crate::render::require_valid_versao_requirement`]
3041 // helper — same two-arm shape the peer
3042 // [`crate::AplicacaoSpec::validate_membros`] on `:membros
3043 // :versao` and [`crate::SupervisorSpec::validate`] on `:children
3044 // :versao` route through, so drift between the three axes'
3045 // accepted requirement sets is structurally impossible and the
3046 // parse-side no-op the empty-first arm closes (semver's empty
3047 // parse yields an implicit `*`) lives in exactly one predicate.
3048 crate::render::require_valid_versao_requirement(
3049 self.versao_requirement(),
3050 || DepError::VersaoEmpty {
3051 nome: self.nome.clone(),
3052 },
3053 |reason| DepError::VersaoInvalid {
3054 nome: self.nome.clone(),
3055 versao: self.versao_requirement().to_string(),
3056 reason,
3057 },
3058 )?;
3059 if let Some(fonte) = self.fonte() {
3060 fonte.validate(&self.nome)?;
3061 }
3062 self.validate_caracteristicas()?;
3063 Ok(())
3064 }
3065
3066 /// Reject per-entry `:caracteristicas` (feature-flag) values that
3067 /// are operationally meaningless. The `:caracteristicas` slot is
3068 /// a set of feature toggles to enable on the target caixa — same
3069 /// shape as Cargo's `[dependencies.<dep>.features]` list — and
3070 /// two structural footguns close here:
3071 ///
3072 /// - empty-string entry (`(:caracteristicas (""))`): the future
3073 /// caixa-resolver lacre pipeline would consume the empty
3074 /// identifier as a no-op feature enable, silently dropping the
3075 /// author's intent far from the source `caixa.lisp`;
3076 /// - duplicate entry within one dep (`(:caracteristicas ("http"
3077 /// "http"))`): the feature-toggle slot is set-shaped (enabling
3078 /// a feature twice has no additional semantic — there is no
3079 /// `feature × 2`), so two entries naming the same feature are
3080 /// a silent miscount, the same set-not-multiset distinction
3081 /// every peer Vec-keyed-by-name axis already closes
3082 /// ([`crate::SupervisorError::DuplicateChildCaixa`] on
3083 /// `:children :caixa`, [`crate::AplicacaoError::MembroDuplicate`]
3084 /// on `:membros :caixa`, [`crate::AplicacaoError::ContratoDuplicate`]
3085 /// on `:contratos`, [`crate::AplicacaoError::PlacementClusterDuplicate`]
3086 /// on `:placement :clusters`, [`crate::AplicacaoError::EntradaPathDuplicate`]
3087 /// on `:entrada :paths`, [`crate::UpgradeError::DuplicateFrom`]
3088 /// on `:upgrade-from :from`, [`crate::UpgradeError::DuplicateLoadModule`]
3089 /// / [`crate::UpgradeError::DuplicateStateChange`] /
3090 /// [`crate::UpgradeError::DuplicateCleanup`] on the within-
3091 /// entry `:upgrade-from` axes, and [`DepError::DuplicateNome`]
3092 /// on the cross-entry `:deps`/`:deps-dev` `:nome` axis the
3093 /// immediate-predecessor 359fba5 closed).
3094 ///
3095 /// Same linear-walk + `HashSet` + first-collision diagnostic shape
3096 /// every peer set-not-multiset gate uses; the empty arm fires
3097 /// before the duplicate arm so an entry with both an empty feature
3098 /// *and* a duplicate of some later feature surfaces the empty-
3099 /// shape diagnostic first (the empty-feature axis is the
3100 /// more-actionable defect since the missing-name renders the
3101 /// duplicate-key arm ambiguous: two `""` entries would both report
3102 /// `caracteristica: ""` with no way to distinguish the offending
3103 /// site). Empty-first cascade discipline mirrors every peer per-
3104 /// entry shape + duplicate gate
3105 /// (`SupervisorSpec::validate`'s `EmptyChildName` before
3106 /// `DuplicateChildCaixa`; `validate_membros`'s `MembroCaixaEmpty`
3107 /// before `MembroDuplicate`).
3108 ///
3109 /// The per-entry value-shape gate (Cargo-feature-name grammar via
3110 /// the lifted [`crate::render::is_cargo_feature_name`] predicate)
3111 /// fires between the empty arm and the duplicate arm — the
3112 /// canonical per-entry-shape-before-cross-entry-uniqueness
3113 /// precedence every peer two-arm + value-shape gate establishes
3114 /// ([`crate::SupervisorSpec::validate`]'s `EmptyChildName` →
3115 /// `ChildCaixaInvalid` → `DuplicateChildCaixa`,
3116 /// [`crate::AplicacaoSpec::validate_membros`]'s `MembroCaixaEmpty`
3117 /// → `MembroCaixaInvalid` → `MembroDuplicate`, [`Dep::validate`]'s
3118 /// `NomeEmpty` → `NomeInvalid` → cross-list `DuplicateNome`).
3119 /// Until the value-shape arm landed `:caracteristicas` accepted
3120 /// every non-empty distinct string — a structurally invalid
3121 /// feature name (`"http feature"` whitespace, `"+http"` the
3122 /// canonical paste-from-`+optional-feature` doc activation-form
3123 /// footgun, `"-flag"` leading hyphen, `".feat"` leading dot,
3124 /// `"http/json"` Cargo's `dep/feat` namespaced-dep syntax that
3125 /// only applies inside list-grammar contexts, `"http,json"`
3126 /// list-separator-belongs-to-the-list-grammar miscomprehension,
3127 /// `"café"` un-percent-encoded non-ASCII silently round-tripping
3128 /// inconsistently across NFC/NFD normalization, the 65-byte
3129 /// paste-from-binary slug) silently passed validate and the
3130 /// failure surfaced at `cargo metadata` time as the
3131 /// `restricted_names::validate_feature_name` parser's rejection,
3132 /// far from the source `caixa.lisp`, with no field naming which
3133 /// `:deps` entry's `:caracteristicas` carried the typo. The
3134 /// lifted predicate makes the Cargo-feature-name-grammar
3135 /// intersection-floor a substrate-level invariant at validate
3136 /// time — same trajectory as the eight peer
3137 /// [`crate::render`] value-shape predicates each typed surface
3138 /// downstream of a structured grammar already follows
3139 /// ([`is_dns_1123_label`](crate::render::is_dns_1123_label),
3140 /// [`is_gateway_api_http_path`](crate::render::is_gateway_api_http_path),
3141 /// [`is_wit_world_ref`](crate::render::is_wit_world_ref),
3142 /// [`is_nats_subject`](crate::render::is_nats_subject),
3143 /// [`is_wasi_keyvalue_slot`](crate::render::is_wasi_keyvalue_slot),
3144 /// [`is_git_ref_name`](crate::render::is_git_ref_name),
3145 /// [`is_git_oid`](crate::render::is_git_oid),
3146 /// [`is_git_repo_url`](crate::render::is_git_repo_url)).
3147 fn validate_caracteristicas(&self) -> Result<(), DepError> {
3148 let mut seen = std::collections::HashSet::new();
3149 for c in self.caracteristicas() {
3150 if c.is_empty() {
3151 return Err(DepError::CaracteristicaEmpty {
3152 nome: self.nome.clone(),
3153 });
3154 }
3155 if let Err(reason) = crate::render::is_cargo_feature_name(c) {
3156 return Err(DepError::CaracteristicaInvalid {
3157 nome: self.nome.clone(),
3158 caracteristica: c.clone(),
3159 reason,
3160 });
3161 }
3162 crate::render::insert_first_seen(&mut seen, c.as_str(), || {
3163 DepError::CaracteristicaDuplicate {
3164 nome: self.nome.clone(),
3165 caracteristica: c.clone(),
3166 }
3167 })?;
3168 }
3169 Ok(())
3170 }
3171}
3172
3173/// Cross-slot coherence gate on the dep-graph axis: no `:deps` or
3174/// `:deps-dev` entry may name the caixa's own `:nome`.
3175///
3176/// A caixa that lists itself as a dep is a degenerate self-edge in the
3177/// lacre closure's dep-graph — the closure is a DAG rooted at the
3178/// caixa's `:nome`, and the caixa-resolver's lacre pipeline traverses
3179/// every `:deps` / `:deps-dev` entry's target by name. A self-dep
3180/// hands the resolver a node that is its own parent: a one-node cycle
3181/// it either rejects mid-traversal far from the source `caixa.lisp`
3182/// (the resolver detecting infinite recursion on the closure walk) or,
3183/// worse, recurses on until it exhausts its stack. Because every
3184/// `:nome` is a globally-unique substrate identity (DNS-1123 label +
3185/// lacre closure root), a dep entry whose `:nome` equals the caixa's
3186/// own `:nome` *is* the caixa itself, not a coincidentally-named peer.
3187///
3188/// Lives outside [`Caixa::validate_deps`] because the dep-list view
3189/// carries the entries but not the parent `:nome`; mirrors the
3190/// cross-slot self-edge gates [`crate::supervisor::validate_no_self_supervision`]
3191/// (ad4abf1) on the `:children :caixa` axis and
3192/// [`crate::aplicacao::validate_no_self_membership`] on the
3193/// `:membros :caixa` axis — the same "an edge from a graph node to
3194/// itself is structurally not a tree/graph edge" discipline, here on
3195/// the third typed-name-graph axis (the dep closure; the supervision
3196/// tree and the Aplicacao membership set were the prior two).
3197///
3198/// Walks `:deps` first then `:deps-dev` so the diagnostic for a caixa
3199/// that self-references on both axes surfaces the `:deps` arm first —
3200/// the load-bearing axis the lacre closure resolves at every build,
3201/// peer with the canonical [`Caixa::validate_deps`] walk order
3202/// (`:deps` → `:deps-dev`).
3203///
3204/// Carries the offending list tag (`":deps"` or `":deps-dev"`)
3205/// verbatim into the diagnostic so the author can grep their
3206/// `caixa.lisp` for the offending block in one edit — same
3207/// `list: &'static str` shape [`DepError::DuplicateNome`] (359fba5)
3208/// uses on the cross-list duplicate-name axis.
3209///
3210/// `Code paths` (`:bibliotecas` / `:exe` / `:servicos`) are the
3211/// substrate-blessed shape for referencing the caixa's *own* code, so
3212/// the diagnostic names them as the corrective surface — every
3213/// legitimate "I want to use code from this caixa" authoring intent
3214/// routes through one of those three slots, not a self-dep.
3215pub fn validate_no_self_dep(
3216 deps: &[Dep],
3217 deps_dev: &[Dep],
3218 parent_nome: &str,
3219) -> Result<(), DepError> {
3220 for dep in deps {
3221 if dep.nome() == parent_nome {
3222 return Err(DepError::DepIsSelf {
3223 nome: parent_nome.to_string(),
3224 list: crate::render::DEP_AUTHOR_KEY_DEPS,
3225 });
3226 }
3227 }
3228 for dep in deps_dev {
3229 if dep.nome() == parent_nome {
3230 return Err(DepError::DepIsSelf {
3231 nome: parent_nome.to_string(),
3232 list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3233 });
3234 }
3235 }
3236 Ok(())
3237}
3238
3239/// Closed-set typed enum for the two dep-list author-surface axes every
3240/// top-level [`crate::Caixa`] carries — the runtime-closure `:deps` slot
3241/// (`Prod`) and the dev-only-closure `:deps-dev` slot (`Dev`). Every
3242/// substrate consumer that dispatches on "which of the two dep-lists"
3243/// (the `feira add` mutation head, the future per-cluster dev-closure-
3244/// audit overlay the M4 CR materializer resolves per-CR, the future
3245/// `caixa app graph` per-list dep summary, every future
3246/// `Caixa::push_dep` / `Caixa::deps_by_list` typed-method dispatch a
3247/// caller reaches for) reads through this enum rather than through a
3248/// bare `&'static str` — the closed-set is expressed at the type layer,
3249/// so a future third dep-list axis (a `:deps-build` build-only closure
3250/// once the substrate grows cross-artifact heterogeneous dep-graphs,
3251/// per CAIXA-SDLC §I) is one variant plus one arm per method and the
3252/// compiler enforces exhaustiveness on every consumer's `match` arms.
3253///
3254/// The wire byte-string [`Self::as_str`] returns is the same author-
3255/// surface tag the sibling [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3256/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry — the
3257/// [`DepError::DuplicateNome`] / [`DepError::DepIsSelf`] `list:
3258/// &'static str` payload family the substrate already emits routes
3259/// through the same source of truth (an author reading a
3260/// [`DepError::DuplicateNome`] refusal can grep their `caixa.lisp`
3261/// for the offending `:deps` / `:deps-dev` block in one edit whether
3262/// the diagnostic came from a `Caixa::validate_deps` walk or a
3263/// `Caixa::push_dep` mutation).
3264///
3265/// Same "closed-set typed-enum discriminator with canonical
3266/// projections per axis" discipline the sibling closed-set typed enums
3267/// on the caixa typed surface carry
3268/// ([`crate::aplicacao::PlacementStrategy`] cc8f749,
3269/// [`crate::aplicacao::RateLimitUnit`] 6bce03d,
3270/// [`crate::supervisor::RestartStrategy`],
3271/// [`crate::supervisor::RestartPolicy`],
3272/// [`crate::upgrade::UpgradeInstruction`], [`crate::CaixaKind`])
3273/// — extended onto the outer-`Caixa` two-list dep-graph axis, the
3274/// substrate's last unlifted closed-set-shaped `&'static str`-carrying
3275/// axis on the top-level manifest surface.
3276#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
3277pub enum DepList {
3278 /// Runtime-closure `:deps` axis — the load-bearing dep-list the
3279 /// lacre closure resolves at every build. Wire-format
3280 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`].
3281 Prod,
3282 /// Dev-only-closure `:deps-dev` axis — Cargo's `[dev-dependencies]`
3283 /// table's dev-time-only visibility contract per CAIXA-SDLC §I.
3284 /// Wire-format [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`].
3285 Dev,
3286}
3287
3288impl DepList {
3289 /// Exhaustive iteration surface for every consumer that reads the
3290 /// full closed-set (the future M4 admission webhook's per-list
3291 /// summary rejection body, any future round-trip pin harness). A
3292 /// future variant addition extends this slice as a single edit and
3293 /// every consumer picks up the new entry by construction — the
3294 /// compiler-checked exhaustiveness on the sibling method `match`
3295 /// arms is the build-time guarantee that no arm forgets to grow.
3296 pub const ALL: &'static [Self] = &[Self::Prod, Self::Dev];
3297
3298 /// Canonical author-surface tag every substrate consumer that
3299 /// names the offending dep-list in a diagnostic reaches for —
3300 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] for [`Self::Prod`] and
3301 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] for [`Self::Dev`],
3302 /// the same `&'static str` payload the sibling
3303 /// [`DepError::DuplicateNome`] and [`DepError::DepIsSelf`] variants
3304 /// already carry. Routing every dep-list diagnostic through the
3305 /// closed-set enum's `as_str` closes the last `&'static str`-shape
3306 /// literal-carry axis on the two-list dep-graph surface — a
3307 /// future kebab-case rebrand (`":deps"` → `":packages"`) or a
3308 /// wire-format promotion (a distinct diagnostic form for the
3309 /// `Dev` arm) reaches every consumer through one edit on the
3310 /// canonical constant, not a coordinated rewrite across the
3311 /// substrate's dep-graph consumers.
3312 #[must_use]
3313 pub const fn as_str(self) -> &'static str {
3314 match self {
3315 Self::Prod => crate::render::DEP_AUTHOR_KEY_DEPS,
3316 Self::Dev => crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3317 }
3318 }
3319
3320 /// Substrate-canonical reverse projection on the two-list dep-graph
3321 /// axis — parses the author-surface wire tag back to the typed
3322 /// variant, or `None` when `s` is outside the closed-set arm-string
3323 /// set [`Self::as_str`] emits. Dispatches on the same lifted
3324 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3325 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants the
3326 /// [`Self::as_str`] emitter walks, so the parse and emit halves of
3327 /// the round-trip migrate through one caixa-core edit on any future
3328 /// list-axis addition.
3329 ///
3330 /// Prior to this lift the substrate carried only the forward
3331 /// `Self → &str` projection on the two-list dep-graph axis (the
3332 /// [`Self::as_str`] emitter, the [`std::fmt::Display`] impl routed
3333 /// through it, the two [`DepError::DuplicateNome`] /
3334 /// [`DepError::DepIsSelf`] variants that carry the wire tag verbatim
3335 /// as a `&'static str` `list:` field). Every future consumer that
3336 /// wanted to promote the wire tag back to the typed enum (a future
3337 /// `feira dep --list <deps|deps-dev>` CLI arg-parse that binds the
3338 /// wire form into the typed enum before dispatching to
3339 /// [`crate::Caixa::deps_of`] / [`crate::Caixa::push_dep`], the M4
3340 /// `mesh.pleme.io/v1alpha1/Caixa` CR materializer's admission-time
3341 /// wire re-parse of the per-list diagnostic body, a future
3342 /// [`DepError`] widening that promotes the two `list: &'static str`
3343 /// fields to a typed `list: DepList` carry so downstream consumers
3344 /// dispatch on the enum rather than string-comparing the wire
3345 /// scalar) would have had to re-inline a two-arm `match s { ":deps"
3346 /// => …, ":deps-dev" => …, _ => … }` cascade that expressed no
3347 /// compile-time link back to the typed [`DepList`] enum. A future
3348 /// variant addition (a `:build-dep` or `:test-dep` third list once
3349 /// the substrate grows Cargo-style split-graphs, a `:tool-dep` for
3350 /// build-time-only tooling per the peer Cargo `[build-dependencies]`
3351 /// / `[target.<cfg>.dev-dependencies]` future admission surface)
3352 /// would silently split the wire byte-string the emitter walks from
3353 /// the parser's arm-set — the round-trip would carry the new list
3354 /// through the forward projection but land on the fallback silently
3355 /// at every non-updated reverse parser, far from the arm-addition
3356 /// commit that caused the drift. Lifting the resolver to a typed
3357 /// method on the substrate primitive closes the drift footgun by
3358 /// construction: the parser's accept-set is the same set the
3359 /// [`Self::as_str`] emitter walks (routed through the same lifted
3360 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3361 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] consts), so both halves
3362 /// of the round-trip migrate through one caixa-core edit on any
3363 /// future list-axis addition.
3364 ///
3365 /// Same closed-set-reverse-projection discipline the sibling
3366 /// [`crate::CaixaKind::from_wire`] (2aa6d23) /
3367 /// [`crate::supervisor::RestartStrategy::from_wire`] (4eec29c) /
3368 /// [`crate::supervisor::RestartPolicy::from_wire`] (dd32ccf) /
3369 /// [`crate::aplicacao::PlacementStrategy::from_wire`] (18c7342) /
3370 /// [`crate::aplicacao::RateLimitUnit::from_suffix`] typed enums
3371 /// carry on the peer wire-side `str → Self` axes — extended onto
3372 /// the two-list dep-graph closed-set axis, the sixth substrate-side
3373 /// closed-set typed enum on the caixa surface to converge on the
3374 /// two-way `str ↔ Self` round-trip. Method-named `from_wire` (not
3375 /// `from_str`) to match the peer shapes verbatim and side-step the
3376 /// derived [`std::str::FromStr`] impls the sibling
3377 /// [`gen_platform::FromStrKind`]-carrying axes install on their
3378 /// kebab-case dispatcher-catalog identity. Returns `Option<Self>`
3379 /// (rather than `Result<Self, _>`) to match the peer shapes: the
3380 /// caller picks the diagnostic form appropriate for its use site —
3381 /// a future `feira dep --list …` arg-parse that surfaces
3382 /// `unknown list: <arg>` at the CLI builds one on top by iterating
3383 /// [`Self::ALL`], while the future M4 admission-webhook's rejection
3384 /// path folds `None` onto its per-CR structured refusal body.
3385 #[must_use]
3386 pub fn from_wire(s: &str) -> Option<Self> {
3387 match s {
3388 crate::render::DEP_AUTHOR_KEY_DEPS => Some(Self::Prod),
3389 crate::render::DEP_AUTHOR_KEY_DEPS_DEV => Some(Self::Dev),
3390 _ => None,
3391 }
3392 }
3393}
3394
3395/// Route [`std::fmt::Display`] through [`DepList::as_str`], so every
3396/// consumer that formats the axis as user-facing text (a future
3397/// `feira app graph` per-list summary, a future M4 admission-webhook
3398/// rejection body naming the offending list, this crate's own
3399/// [`DepError`] `#[error(...)]` templates when they widen to carry a
3400/// typed [`DepList`]) lands on the same author-surface tag the
3401/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3402/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry. Same
3403/// as-str-through-Display convergence discipline the sibling
3404/// [`crate::aplicacao::PlacementStrategy`],
3405/// [`crate::aplicacao::RateLimitUnit`],
3406/// [`crate::supervisor::RestartStrategy`],
3407/// [`crate::supervisor::RestartPolicy`], and [`crate::CaixaKind`]
3408/// closed-set typed enums carry.
3409impl std::fmt::Display for DepList {
3410 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3411 f.write_str(self.as_str())
3412 }
3413}
3414
3415/// Errors raised by [`Dep::validate`].
3416///
3417/// Mirrors the per-axis error families the other `:versao`-carrying
3418/// typed surfaces expose
3419/// ([`crate::AplicacaoError::MembroVersaoEmpty`] /
3420/// [`crate::AplicacaoError::MembroVersaoInvalid`],
3421/// [`crate::SupervisorError::EmptyChildVersion`] /
3422/// [`crate::SupervisorError::ChildVersaoInvalid`]) so a future top-
3423/// level `CaixaError` (M4) sums these without reshaping the diagnostic.
3424#[derive(Debug, Error, PartialEq, Eq)]
3425pub enum DepError {
3426 #[error(
3427 ":deps entry has empty :nome (every dep must name a target caixa; \
3428 omit the entry instead of carrying an empty name)"
3429 )]
3430 NomeEmpty,
3431 #[error(
3432 ":deps entry :nome {nome:?} is not a valid DNS-1123 label: {reason} \
3433 (the value flows verbatim as the target caixa's `:nome`, the rendered \
3434 `lareira-<nome>` Helm chart name segment, the `LABEL_PROGRAM` label \
3435 value, and the resolver's checkout-directory leaf — each apiserver-side \
3436 schema rejects non-DNS-1123 names at admission time; use a lowercase \
3437 RFC 1123 label like `\"caixa-teia\"` or `\"pleme-mesh\"`, 1..=63 bytes, \
3438 pattern `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)"
3439 )]
3440 NomeInvalid { nome: String, reason: String },
3441 #[error(
3442 ":deps entry {nome:?} has empty :versao (every dep must pin a semver \
3443 constraint that resolves through the lacre pipeline)"
3444 )]
3445 VersaoEmpty { nome: String },
3446 #[error(
3447 ":deps entry {nome:?} :versao {versao:?} is not a valid semver \
3448 requirement: {reason} (use Cargo-shaped forms like `\"^0.1\"`, \
3449 `\"~0.1.2\"`, `\"0.1.0\"`, or `\"*\"` — the same shape `:membros :versao` \
3450 and `:children :versao` carry; the lacre pipeline resolves all three \
3451 through the same parser)"
3452 )]
3453 VersaoInvalid {
3454 nome: String,
3455 versao: String,
3456 reason: String,
3457 },
3458 #[error(
3459 ":deps entry {nome:?} :fonte (:tipo git …) has empty :repo \
3460 (every git source must name a repo — use a `github:org/repo` \
3461 shorthand, an `https://…` URL, or an ssh-git URL; omit the \
3462 entire :fonte block to fall back to the default-host resolver \
3463 convention)"
3464 )]
3465 FonteRepoEmpty { nome: String },
3466 #[error(
3467 ":deps entry {nome:?} :fonte (:tipo git …) :repo {repo:?} has \
3468 invalid value-shape: {reason} (the value flows verbatim into the \
3469 caixa-resolver's `git clone <repo>` subprocess invocation; every \
3470 documented form carries a `:` separator and no whitespace / \
3471 control / non-ASCII bytes — use a `github:org/repo` shorthand, \
3472 an `https://host/path` / `ssh://[user@]host/path` / \
3473 `git://host/path` / `file:///path` URL, or the `git@host:path` \
3474 scp-style SSH form)"
3475 )]
3476 FonteRepoShape {
3477 nome: String,
3478 repo: String,
3479 reason: String,
3480 },
3481 #[error(
3482 ":deps entry {nome:?} :fonte (:tipo git …) has no pin set \
3483 (set exactly one of :tag, :rev, or :branch so the resolver \
3484 can pick a reproducible commit; omit the entire :fonte block \
3485 to fall back to the default-host resolver convention, which \
3486 resolves the latest tag matching :versao)"
3487 )]
3488 FontePinMissing { nome: String },
3489 #[error(
3490 ":deps entry {nome:?} :fonte (:tipo git …) has multiple pins \
3491 set ({pins}); exactly one of :tag, :rev, or :branch must be \
3492 set so the resolver's checkout target is unambiguous (the \
3493 resolver's silent precedence is :rev > :tag > :branch — if \
3494 you intended one specifically, drop the others)"
3495 )]
3496 FontePinAmbiguous { nome: String, pins: String },
3497 #[error(
3498 ":deps entry {nome:?} :fonte (:tipo git …) has empty {pin} \
3499 (a set pin must name a non-empty git ref; drop the {pin} key \
3500 entirely to fall through to another pin axis)"
3501 )]
3502 FontePinEmpty { nome: String, pin: String },
3503 #[error(
3504 ":deps entry {nome:?} :fonte (:tipo git …) {pin} {value:?} has invalid \
3505 value-shape: {reason} (the git porcelain enforces the same shape at \
3506 `git fetch` / `git checkout` time on every pin; use a leaf refname \
3507 like `\"v0.1.0\"` for `:tag` or `\"main\"` / `\"feature/foo\"` for \
3508 `:branch`, or a full 40/64 lowercase-hex commit OID for `:rev` — \
3509 drop any `refs/heads/` or `refs/tags/` prefix the caixa-resolver \
3510 prepends at clone time, and avoid abbreviated SHAs which are \
3511 ambiguous across repository history)"
3512 )]
3513 FontePinShape {
3514 nome: String,
3515 pin: String,
3516 value: String,
3517 reason: String,
3518 },
3519 #[error(
3520 ":deps entry {nome:?} :fonte (:tipo path …) has empty :caminho \
3521 (every path source must name a non-empty filesystem path; \
3522 omit the entire :fonte block to fall back to the default-host \
3523 resolver convention)"
3524 )]
3525 FonteCaminhoEmpty { nome: String },
3526 #[error(
3527 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} is \
3528 absolute (the lacre pipeline embeds the value verbatim in its \
3529 per-dep content-address `path:{caminho}` at \
3530 caixa-resolver/src/resolve.rs:189, so an absolute path makes the \
3531 BLAKE3 closure differ across machines — defeating the \
3532 reproducibility contract that's load-bearing for CSE; express \
3533 the path relative to the caixa.lisp location, e.g. \
3534 \"../caixa-teia\" for a sibling workspace dep)"
3535 )]
3536 FonteCaminhoAbsolute { nome: String, caminho: String },
3537 #[error(
3538 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3539 with `~` (the leading-tilde is a shell-expansion convention, not a \
3540 POSIX path component — `Path::is_absolute` returns false on it, so \
3541 the b94fd83 absolute-path gate doesn't catch it, but the lacre \
3542 pipeline embeds the value verbatim in its per-dep content-address \
3543 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3544 caixa-resolver folds it through `Path::join` without `~`-expansion, \
3545 so the build looks for a literal `./{caminho}` subdirectory and \
3546 fails at resolve time far from the source caixa.lisp; even worse, a \
3547 future caixa-resolver pass that *does* expand `~` would silently \
3548 re-open the host-layout-leak the b94fd83 absolute gate closes — \
3549 Alice's `~` resolves to `/home/alice`, Bob's to `/home/bob`, two CI \
3550 runners with different `$HOME` layouts resolve to two distinct paths \
3551 for the byte-identical caixa, defeating the THEORY.md §V.2 render-\
3552 determinism contract; express the path relative to the caixa.lisp \
3553 location, e.g. \"../caixa-teia\" for a sibling workspace dep, or \
3554 spell out the full relative path explicitly if a workstation-rooted \
3555 dep is genuinely intended)"
3556 )]
3557 FonteCaminhoTildeExpansion { nome: String, caminho: String },
3558 #[error(
3559 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3560 with `$` (the leading-`$` is a shell-variable-expansion convention, \
3561 not a POSIX path component — `Path::is_absolute` returns false on it \
3562 and the a5c248e tilde gate doesn't catch it, but the lacre pipeline \
3563 embeds the value verbatim in its per-dep content-address \
3564 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3565 caixa-resolver folds it through `Path::join` without `$`-expansion, \
3566 so the build looks for a literal `./{caminho}` subdirectory and \
3567 fails at resolve time far from the source caixa.lisp; even worse, a \
3568 future caixa-resolver pass that *does* expand `$VAR` (the canonical \
3569 shell-convention idiom that CI's `${{WORKSPACE}}` paste-idiom \
3570 invites) would silently re-open the host-layout-leak the b94fd83 \
3571 absolute gate closes — Alice's `$HOME` resolves to `/home/alice`, \
3572 Bob's to `/home/bob`, two CI runners with different `${{WORKSPACE}}` \
3573 layouts resolve to two distinct paths for the byte-identical caixa, \
3574 defeating the THEORY.md §V.2 render-determinism contract; express \
3575 the path relative to the caixa.lisp location, e.g. \"../caixa-teia\" \
3576 for a sibling workspace dep, or spell out the full relative path \
3577 explicitly if a workstation-rooted dep is genuinely intended)"
3578 )]
3579 FonteCaminhoVarExpansion { nome: String, caminho: String },
3580 #[error(
3581 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3582 with a space (the leading ASCII space `0x20` is the orthogonal \
3583 paste-from-aligned-doc footgun that silently passes \
3584 `Path::is_absolute` and every prior leading-byte arm — \
3585 `\" ../caixa-teia\"` resolves via `Path::join` to a literal \
3586 `./ ../caixa-teia` subdirectory the resolver fails to find at \
3587 resolve time with a non-self-locating `No such file or directory` \
3588 error far from the source caixa.lisp; the lacre pipeline embeds \
3589 the value verbatim in its per-dep content-address `path:{caminho}` \
3590 at caixa-resolver/src/resolve.rs:189, so byte-divergent / \
3591 semantic-identical caixa values (` ../caixa-teia` vs \
3592 `../caixa-teia`) yield two distinct BLAKE3 closures across two \
3593 workstations whose authors differ only in paste-from-aligned- \
3594 caixa.lisp-doc whitespace habits — the most insidious failure \
3595 mode the typed slot can carry (no error surfaces; the divergence \
3596 is invisible until two machines compare lacres), defeating the \
3597 THEORY.md §V.2 render-determinism contract. The canonical \
3598 paste-from-aligned-`:deps`-block footgun (every `:fonte` form in \
3599 a multi-entry `:deps` block sits at the same column — an author \
3600 selecting `\"<sp><sp><sp>../caixa-teia\"` and pasting it from \
3601 the rendered alignment into a fresh entry preserves the leading \
3602 whitespace verbatim); peer `:fonte :repo` axis already rejects \
3603 leading whitespace via `is_git_repo_url`, `:fonte :tag` / \
3604 `:fonte :branch` via `is_git_ref_name`, `:descricao` via \
3605 `is_chart_description_shape`, `:licenca` via \
3606 `is_spdx_expression_shape`. Drop the leading space; express the \
3607 path as a bare relative single-token like \"../caixa-teia\")"
3608 )]
3609 FonteCaminhoLeadingWhitespace { nome: String, caminho: String },
3610 #[error(
3611 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3612 with `-` (the canonical CLI-argument-injection footgun on the \
3613 `:caminho` axis — the lacre pipeline embeds the value verbatim in \
3614 its per-dep content-address `path:{caminho}` at \
3615 caixa-resolver/src/resolve.rs:189 and the caixa-resolver folds it \
3616 through `Path::join` looking for a literal `./{caminho}` \
3617 subdirectory. Every downstream subprocess that consumes the resolved \
3618 path — `git -C {caminho} <verb>`, `terraform -chdir={caminho}`, \
3619 `nix build --path {caminho}`, `find {caminho}`, `stat {caminho}`, \
3620 `cp -r {caminho} …`, `rm -rf {caminho}` — reinterprets a leading-`-` \
3621 value as a CLI flag rather than a positional path when the invocation \
3622 does not carry a `--` argument-list terminator between the flag block \
3623 and the path (the common case at every porcelain entry point). The \
3624 canonical footguns: `:caminho \"-rf\"` (bare short-flag paste), \
3625 `:caminho \"-C\"` (`git -C -C` config-injection paste), \
3626 `:caminho \"--upload-pack=cat /etc/passwd\"` (the canonical long-flag \
3627 CLI-arg-injection vector at every git porcelain entry point that \
3628 consumes a path or URL argument, peer with is_git_repo_url's \
3629 leading-`-` arm on the sibling `:fonte :repo` axis), \
3630 `:caminho \"--config=…\"` (`git -c foo=bar` config-override paste). \
3631 POSIX `std::path::Path` treats a leading `-` as a literal filename \
3632 byte so the resolver folds `\"-rf\"` through `Path::join` and looks \
3633 for a literal `./-rf` subdirectory that fails at resolve time with a \
3634 non-self-locating `No such file or directory` error far from the \
3635 source caixa.lisp — but on any downstream shell-out without `--` the \
3636 reinterpretation is silent and the failure mode is arbitrary-\
3637 argument-injection. Peer arms: `is_git_repo_url` (render.rs:2037) \
3638 rejects leading `-` on `:fonte :repo` for `git clone <repo>` CLI-\
3639 arg-injection; `is_git_ref_name` (render.rs:1381, 5a28454) rejects \
3640 leading `-` on `:fonte :tag` / `:branch` for `git checkout <ref>` \
3641 CLI-arg-injection; `is_dns_1123_label` rejects leading `-` on every \
3642 DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros :caixa`, \
3643 `:children :caixa`, `:deps :nome`, cluster names); \
3644 `is_cargo_feature_name` rejects leading `-` on `:caracteristicas`; \
3645 the feira `init` / `add <nome>` positional gate (868c191) rejects \
3646 leading `-` on the CLI positional itself. Express the path as a bare \
3647 relative single-token like \"../caixa-teia\" — the sibling-workspace \
3648 directory name carries no leading-hyphen semantic, and `./` / `../` \
3649 prefixes structurally partition the leading-byte set to safe values.)"
3650 )]
3651 FonteCaminhoLeadingHyphen { nome: String, caminho: String },
3652 #[error(
3653 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains \
3654 ASCII control byte 0x{byte:02x} (POSIX paths reject NUL `0x00` outright — \
3655 every `std::fs` syscall routes the path through `CString::new` which \
3656 fails with `NulError` at resolve time; the lacre pipeline embeds the \
3657 value verbatim in its per-dep content-address `path:{caminho}` at \
3658 caixa-resolver/src/resolve.rs:189 so a control byte anywhere in the \
3659 value lands in the BLAKE3 closure and breaks the THEORY.md §V.2 render-\
3660 determinism contract — the canonical paste-from-multiline-doc \
3661 (`\\n`/`\\r`), paste-from-aligned-table (`\\t`), or paste-from-binary-\
3662 blob (`0x00`-DEL) footgun every peer single-token-shaped axis \
3663 (`:fonte :repo`, `:fonte :tag`/`:branch`, the Helm chart-string axes) \
3664 already gates against. Express the path as a relative single-line ASCII \
3665 string, e.g. \"../caixa-teia\" for a sibling workspace dep)"
3666 )]
3667 FonteCaminhoControlChar {
3668 nome: String,
3669 caminho: String,
3670 byte: u8,
3671 },
3672 #[error(
3673 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains `\\` \
3674 (POSIX `std::path::Path` treats `\\` as a literal byte inside a single path \
3675 component, so `..\\caixa-teia` is one directory named literally `..\\caixa-teia` — \
3676 not the parent's sibling — and the caixa-resolver folds the value through \
3677 `Path::join` looking for a literal `./{caminho}` subdirectory that fails at \
3678 resolve time with a non-self-locating `No such file or directory` error far \
3679 from the source caixa.lisp; Windows `std::path::Path` treats `\\` as a \
3680 primary path separator equal to `/`, so byte-identical caixa.lisp values \
3681 resolve to two distinct directories across runner OSes — the lacre pipeline \
3682 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3683 caixa-resolver/src/resolve.rs:189, defeating the THEORY.md §V.2 render-\
3684 determinism contract via the cross-host-OS-separator divergence vector. The \
3685 canonical Windows-Explorer `Copy as path` / PowerShell `Get-Location` \
3686 paste-idiom footgun; peer `:fonte :tag` / `:fonte :branch` axis already \
3687 rejects `\\` via `is_git_ref_name` for the same Windows-path-leak reason, \
3688 and `:entrada :paths` rejects `\\` via `is_gateway_api_http_path`'s eleven-\
3689 byte RFC-3986-reserved set. Express the path with `/` as the separator, e.g. \
3690 \"../caixa-teia\" for a sibling workspace dep)"
3691 )]
3692 FonteCaminhoBackslash { nome: String, caminho: String },
3693 #[error(
3694 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3695 redirection metacharacter 0x{byte:02x} `{ch}` (every interactive shell — bash / \
3696 zsh / fish / nushell — lexes `<` and `>` as input / output redirection \
3697 operators, so `:caminho \"../caixa-teia>build.log\"` is the canonical \
3698 paste-from-shell-pipeline footgun where an author copies a `command > log` \
3699 tail without trimming the redirect; POSIX `std::path::Path` treats both bytes \
3700 as literal path-component bytes, so the resolver folds the value through \
3701 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3702 subdirectory and fails at resolve time with a non-self-locating `No such \
3703 file or directory` error far from the source caixa.lisp. The lacre pipeline \
3704 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3705 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure \
3706 and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3707 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3708 canonical CRLF-at-subprocess-argument / shell-metachar injection surface every \
3709 peer single-token-shaped typed slot already closes. The peer `:fonte :tag` / \
3710 `:fonte :branch` axis already rejects `<` / `>` via `is_git_ref_name`, and \
3711 `:entrada :paths` rejects them via `is_gateway_api_http_path`'s eleven-byte \
3712 RFC-3986-reserved set. Express the path as a bare relative single-token like \
3713 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3714 redirection semantic.",
3715 ch = *byte as char
3716 )]
3717 FonteCaminhoShellRedirection {
3718 nome: String,
3719 caminho: String,
3720 byte: u8,
3721 },
3722 #[error(
3723 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-pipe \
3724 metacharacter `|` (every interactive shell — bash / zsh / fish / nushell — lexes \
3725 `|` as the pipe operator that wires one command's stdout to the next command's \
3726 stdin, so `:caminho \"../caixa-teia | grep foo\"` is the canonical paste-from-\
3727 shell-history footgun where an author copies a `ls ../caixa-teia | grep` line \
3728 without trimming the pipeline tail, and `:caminho \"../foo||bar\"` is the \
3729 symmetric `cmd-a || cmd-b` short-circuit-OR paste shape; POSIX `std::path::Path` \
3730 treats `|` as a literal path-component byte, so the resolver folds the value \
3731 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3732 subdirectory and fails at resolve time with a non-self-locating `No such file or \
3733 directory` error far from the source caixa.lisp. The lacre pipeline embeds the \
3734 value verbatim in its per-dep content-address `path:{caminho}` at caixa-resolver/\
3735 src/resolve.rs:189, so the byte lands in the BLAKE3 closure and rides into every \
3736 shell-spawned subprocess (the resolver's `git clone`, a future `feira tofu` \
3737 shell-out, a future operator-side `nix` spawn) as the canonical CRLF-at-\
3738 subprocess-argument / shell-metachar injection surface every peer single-token-\
3739 shaped typed slot already closes. The peer `:entrada :paths` axis rejects `|` \
3740 via `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3741 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3742 workspace directory name carries no shell-pipe semantic."
3743 )]
3744 FonteCaminhoShellPipe { nome: String, caminho: String },
3745 #[error(
3746 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3747 command-separator metacharacter `;` (every interactive shell — bash / zsh / fish \
3748 / nushell — lexes `;` as the sequential-command terminator that fires the next \
3749 command regardless of the prior command's exit status, so `:caminho \
3750 \"../caixa-teia; rm -rf build\"` is the canonical paste-from-shell-one-liner \
3751 footgun where an author copies a `cd path; do-thing` chain without trimming \
3752 the cleanup tail, and `:caminho \"../foo;;bar\"` is the symmetric POSIX `case` \
3753 arm `;;` terminator paste shape; POSIX `std::path::Path` treats `;` as a \
3754 literal path-component byte, so the resolver folds the value through \
3755 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3756 subdirectory and fails at resolve time with a non-self-locating `No such file \
3757 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3758 the value verbatim in its per-dep content-address `path:{caminho}` at \
3759 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3760 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3761 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3762 canonical shell-metachar injection surface every peer single-token-shaped \
3763 typed slot already closes. The peer `:entrada :paths` axis rejects `;` via \
3764 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3765 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3766 workspace directory name carries no shell-command-separator semantic."
3767 )]
3768 FonteCaminhoShellSemicolon { nome: String, caminho: String },
3769 #[error(
3770 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3771 background / list-AND metacharacter `&` (every interactive shell — bash / zsh \
3772 / fish / nushell — lexes `&` two ways: single `&` as the background-task \
3773 terminator detaching the prior command and returning control immediately to \
3774 the prompt, double `&&` as the logical-AND list operator firing the next \
3775 command only if the prior succeeded; POSIX `std::path::Path` treats it as a \
3776 literal byte. The canonical paste-from-shell-prompt footgun is a `cd path & \
3777 sleep 1` background-launch one-liner or a `cd path && make install` build-\
3778 chain idiom selected whole into the `:caminho` slot — the prior `;` arm at \
3779 05c358e closed the sequential-command-separator vector, this arm closes the \
3780 orthogonal background-task / logical-AND vector on the same paste-from-shell-\
3781 prompt class. The lacre pipeline embeds the value verbatim in its per-dep \
3782 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3783 byte lands in the BLAKE3 closure and rides into every shell-spawned \
3784 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3785 future operator-side `nix` spawn) as the canonical shell-metachar injection \
3786 surface every peer single-token-shaped typed slot already closes. The peer \
3787 `:entrada :paths` axis rejects `&` via `is_gateway_api_http_path`'s eleven-\
3788 byte RFC-3986-reserved set. Express the path as a bare relative single-token \
3789 like \"../caixa-teia\" — the sibling-workspace directory name carries no \
3790 shell-background / logical-AND semantic."
3791 )]
3792 FonteCaminhoShellBackground { nome: String, caminho: String },
3793 #[error(
3794 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3795 command-substitution metacharacter `` ` `` (every POSIX shell — sh / bash / zsh / \
3796 dash / ksh / fish / nushell — lexes the byte as the legacy command-substitution \
3797 wrapper that runs the enclosed command and substitutes its standard-output \
3798 verbatim into the surrounding word, so a backticked `whoami` expands to the \
3799 current user's name and a backticked `cat /etc/passwd` expands to the file's \
3800 contents — the canonical CWE-78 shell-command-injection vector; POSIX \
3801 `std::path::Path` treats the byte as a literal path-component byte. The canonical \
3802 paste-from-shell-prompt footgun is a `cd ../path/<backtick>whoami<backtick>` legacy substitution \
3803 one-liner or a `cd <backtick>pwd<backtick>/path` working-directory expansion idiom selected whole \
3804 into the `:caminho` slot — the prior `&` arm at e12e4f3 closed the shell-\
3805 background / logical-AND vector, this arm closes the orthogonal command-\
3806 substitution vector on the same paste-from-shell-prompt class (the modern `$()` \
3807 form is gated at leading position by the f4efe9c `FonteCaminhoVarExpansion` arm; \
3808 the legacy backtick form is the orthogonal axis). The lacre pipeline embeds the \
3809 value verbatim in its per-dep content-address `path:{caminho}` at \
3810 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3811 rides into every shell-spawned subprocess (the resolver's `git clone`, a future \
3812 `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3813 shell-metachar injection surface every peer single-token-shaped typed slot \
3814 already closes. The peer `:entrada :paths` axis rejects the byte via \
3815 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the path \
3816 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3817 directory name carries no shell-command-substitution semantic."
3818 )]
3819 FonteCaminhoShellCommandSubstitution { nome: String, caminho: String },
3820 #[error(
3821 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3822 glob / pathname-expansion metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — \
3823 sh / bash / zsh / dash / ksh / fish / nushell — lexes `*` and `?` as pathname-\
3824 expansion wildcards: `*` matches any sequence of characters in a path component \
3825 and `?` matches exactly one character, so a `:caminho \"../caixa-teia/*\"` is the \
3826 canonical paste-from-shell-listing footgun where an author copies a \
3827 `ls ../caixa-teia/*` listing without trimming the wildcard, and `:caminho \
3828 \"../foo?\"` is the symmetric single-char-wildcard paste shape; POSIX \
3829 `std::path::Path` treats both bytes as literal path-component bytes, so the \
3830 resolver folds the value through `Path::new(caminho).join(<file>)` looking for \
3831 a literal `./{caminho}` subdirectory and fails at resolve time with a non-self-\
3832 locating `No such file or directory` error far from the source caixa.lisp. The \
3833 lacre pipeline embeds the value verbatim in its per-dep content-address \
3834 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the \
3835 BLAKE3 closure and rides into every shell-spawned subprocess (the resolver's \
3836 `git clone`, a future `feira tofu` shell-out, a future operator-side `nix` \
3837 spawn) as the canonical shell-metachar / glob-expansion surface every peer \
3838 single-token-shaped typed slot already closes. The peer `:entrada :paths` axis \
3839 rejects `*` and `?` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-\
3840 reserved set. Express the path as a bare relative single-token like \
3841 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-glob \
3842 / pathname-expansion semantic.",
3843 ch = *byte as char
3844 )]
3845 FonteCaminhoShellGlob {
3846 nome: String,
3847 caminho: String,
3848 byte: u8,
3849 },
3850 #[error(
3851 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3852 subshell-grouping metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / \
3853 zsh / dash / ksh / fish / nushell — lexes `(` and `)` as the subshell-grouping \
3854 operator: `(<cmd>)` runs `<cmd>` in a child shell with a fresh environment scope \
3855 (the canonical `(cd <path> && <cmd>)` shell-history one-liner scopes a `cd` to one \
3856 subshell without disturbing the parent's working directory), and `$(<cmd>)` is the \
3857 modern Bourne command-substitution shape the leading-`$` `FonteCaminhoVarExpansion` \
3858 arm closes the leading byte of — together the two arms now structurally exclude the \
3859 entire `$(<cmd>)` substitution surface from the typed `:caminho` accepted set. \
3860 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3861 `:caminho \"../caixa-teia/$(date)/build\"` (the canonical paste-from-shell-history \
3862 modern-command-substitution footgun) or `:caminho \"../(cd foo && pwd)/caixa-teia\"` \
3863 (the symmetric subshell-grouping working-directory-probe paste idiom) silently passes \
3864 every prior arm and the resolver folds the value through `Path::new(caminho).join(\
3865 <file>)` looking for a literal subdirectory and fails at resolve time with a non-\
3866 self-locating `No such file or directory` error far from the source caixa.lisp. The \
3867 lacre pipeline embeds the value verbatim in its per-dep content-address `path:\
3868 {caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 \
3869 closure and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3870 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3871 shell-metachar / subshell-grouping surface every peer single-token-shaped typed slot \
3872 already closes. The peer `:fonte :repo` axis (3b99147) closes the same byte under the \
3873 same shell-subshell-grouping / RFC-3986-sub-delims banner on `is_git_repo_url`, \
3874 together with the leading-`$` `FonteCaminhoVarExpansion` arm closing the leading byte \
3875 of every `$(<cmd>)` shape. Express the path as a bare relative single-token \
3876 like \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3877 subshell-grouping semantic.",
3878 ch = *byte as char
3879 )]
3880 FonteCaminhoShellSubshellGrouping {
3881 nome: String,
3882 caminho: String,
3883 byte: u8,
3884 },
3885 #[error(
3886 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3887 brace-expansion / URI-Template placeholder metacharacter 0x{byte:02x} `{ch}` \
3888 (every POSIX-derived brace-expanding shell — bash / zsh / ksh / fish — lexes `{{` / \
3889 `}}` as the brace-expansion operator: `{{a,b,c}}` expands to the cross-product of \
3890 comma-separated members and `{{1..10}}` expands to the integer range — the \
3891 canonical `mkdir -p ../{{caixa-teia,caixa-helm,caixa-flux}}` / `cp file{{,.bak}}` \
3892 idiom every shell-history block carries; RFC 6570 reserves the matched pair for \
3893 URI Template placeholders (the canonical `https://{{host}}/{{org}}/{{repo}}` \
3894 substitution shape every OpenAPI / Swagger / Postman / GitHub Octokit client \
3895 library / Helm chart-URL fragment carries) and the Mustache / Handlebars / \
3896 Tera / Jinja2 / Go html/template doubled-brace substitution form every IaC \
3897 templating engine (Helm, Kustomize, Terraform's `${{var}}` cousin) emits. POSIX \
3898 `std::path::Path` treats the byte as a literal path-component byte, so a \
3899 `:caminho \"../{{caixa-teia,caixa-helm}}/build\"` (the canonical paste-from-\
3900 shell-history brace-expansion fan-across-siblings footgun) or `:caminho \"../{{{{org}}}}/\
3901 caixa-teia\"` (the symmetric paste-from-templated-doc URI-Template placeholder \
3902 idiom every README quick-start / OpenAPI spec / Helm chart `home:` field carries) \
3903 silently passes every prior arm and the resolver folds the value through \
3904 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3905 resolve time with a non-self-locating `No such file or directory` error far from \
3906 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its \
3907 per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
3908 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
3909 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3910 future operator-side `nix` spawn) as the canonical shell-metachar / brace-\
3911 expansion / URI-Template-placeholder surface every peer single-token-shaped \
3912 typed slot already closes. The peer `:fonte :repo` axis (42d8f9d) closes the \
3913 same byte pair on `is_git_repo_url` under the same RFC-3986-'delims' / \
3914 RFC-6570-URI-Template / shell-brace-expansion banner. Express the path as a \
3915 bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3916 directory name carries no shell-brace-expansion / URI-Template-placeholder \
3917 semantic; if two siblings actually need pinning, author two separate `:deps` \
3918 entries rather than one brace-expanded `:caminho` value.",
3919 ch = *byte as char
3920 )]
3921 FonteCaminhoShellBraceExpansion {
3922 nome: String,
3923 caminho: String,
3924 byte: u8,
3925 },
3926 #[error(
3927 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3928 bracket-expansion / POSIX glob-character-class / shell-`test`-builtin metacharacter \
3929 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / nushell \
3930 — lexes the bracket pair as the glob character-class operator: `[abc]` matches one of \
3931 `a` / `b` / `c`, `[a-z]` matches any lowercase ASCII letter, `[^x]` negates — the \
3932 canonical `ls *.[ch]` C-source-file glob and `cd ../caixa-[a-z]*` lowercase-sibling \
3933 glob every shell-history block carries; the bracket pair additionally carries the \
3934 POSIX `test` / `[` builtin command (`[ -d ../caixa-teia ] && cd ...` every shell-\
3935 script conditional uses) and bash's `[[ ... ]]` extended-test grammar; beyond shell \
3936 the pair is the TOML inline-array delimiter (`features = [\"a\", \"b\"]` — the \
3937 canonical paste-from-Cargo-manifest cross-idiom-leak vector), the YAML flow-sequence \
3938 delimiter (`paths: [/a, /b]` — the canonical paste-from-values.yaml cross-idiom \
3939 leak), the JSON array delimiter, and the POSIX-ERE / PCRE bracket-expression anchor. \
3940 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3941 `:caminho \"../caixa-[a-z]/build\"` (the canonical paste-from-shell-history glob-\
3942 character-class fan-across-siblings footgun) or `:caminho \"../[caixa-teia]/build\"` \
3943 (the symmetric paste-from-TOML-array / paste-from-YAML-flow-sequence cross-idiom \
3944 leak) silently passes every prior arm and the resolver folds the value through \
3945 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3946 resolve time with a non-self-locating `No such file or directory` error far from \
3947 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3948 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3949 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3950 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3951 `nix` spawn) as the canonical shell-metachar / glob-character-class / TOML-array \
3952 surface every peer single-token-shaped typed slot already closes. Express the path \
3953 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3954 directory name carries no shell-bracket-expansion / glob-character-class / array-\
3955 literal semantic; if a family of sibling caixas actually needs pinning, author \
3956 separate `:deps` entries rather than one character-class-expanded `:caminho` value.",
3957 ch = *byte as char
3958 )]
3959 FonteCaminhoShellBracketExpansion {
3960 nome: String,
3961 caminho: String,
3962 byte: u8,
3963 },
3964 #[error(
3965 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3966 quote-grouping / cross-config-DSL string-literal-delimiter metacharacter \
3967 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3968 nushell — lexes `'` as the strong string-literal delimiter (`'…'` — no expansion) \
3969 and `\"` as the weak string-literal delimiter (`\"…\"` — variable- / command-\
3970 substitution-preserving); the canonical `cd '../caixa-teia'` shell-history idiom \
3971 every path-with-embedded-whitespace paste block carries and the symmetric \
3972 `git clone \"$REPO\"` weak-quoted CI-manifest shape both leak the pair verbatim. \
3973 Beyond shell the pair is the JSON string-literal delimiter (`\"key\": \"value\"` — \
3974 the canonical paste-from-JSON-config cross-idiom-leak vector), the YAML double- \
3975 and single-quoted flow-scalar delimiter (`path: \"../caixa-teia\"` — the canonical \
3976 paste-from-values.yaml / paste-from-K8s-YAML-manifest cross-idiom leak), the TOML \
3977 basic and literal string delimiter (`path = \"../caixa-teia\"` — the canonical \
3978 paste-from-Cargo-manifest cross-idiom leak), the tatara-lisp string-literal \
3979 delimiter itself (`(:caminho \"../caixa-teia\")` — the canonical \"I copied the \
3980 entire `:caminho \"...\"` slot rather than just the string body\" author-surface \
3981 footgun), and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which excludes \
3982 both bytes from the `pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"` \
3983 production. POSIX `std::path::Path` treats the byte as a literal path-component \
3984 byte, so a `:caminho \"'../caixa-teia'\"` (the canonical paste-from-shell-history \
3985 strong-quoted sibling-workspace path footgun) or `:caminho \"\\\"../caixa-teia\\\"\"` \
3986 (the symmetric weak-quoted paste-from-JSON / paste-from-YAML flow-scalar / paste-\
3987 from-TOML basic-string / paste-from-tatara-lisp string-literal cross-idiom-leak \
3988 shape) silently passes every prior arm and the resolver folds the value through \
3989 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3990 resolve time with a non-self-locating `No such file or directory` error far from \
3991 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3992 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3993 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3994 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3995 `nix` spawn) as the canonical shell-metachar / string-literal-delimiter surface \
3996 every peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
3997 axis closes both bytes under the same shell-quote-grouping / RFC-3986-sub-delims \
3998 banner (e7a109f `'` shell-single-quote + 4267d8b `\"` shell-double-quote on \
3999 `is_git_repo_url`). Express the path as a bare relative single-token like \
4000 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-quote-\
4001 grouping / string-literal-delimiter semantic; strip the outer quote pair from the \
4002 paste (the tatara-lisp `:caminho \"...\"` slot already carries the string-literal \
4003 quoting on the outer syntactic layer, so an inner quote pair would nest and \
4004 desugar to a broken layer).",
4005 ch = *byte as char
4006 )]
4007 FonteCaminhoShellQuoteGrouping {
4008 nome: String,
4009 caminho: String,
4010 byte: u8,
4011 },
4012 #[error(
4013 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4014 comment / URL-fragment-identifier / YAML-comment cross-config-DSL metacharacter \
4015 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
4016 nushell — lexes an unquoted `#` at the head of a word or after unquoted \
4017 whitespace as the comment-lead per POSIX.1-2017 §2.3 Token Recognition step 6, \
4018 discarding the byte and everything after it to the end of the physical line \
4019 before command parsing (`cd ../caixa-teia # legacy sibling` — the canonical \
4020 paste-from-shell-history-with-trailing-annotation shape every operator-notebook \
4021 and CI-manifest carries); YAML 1.2 §6.6 makes `#` the comment-lead at any \
4022 position preceded by whitespace or at line-start (`path: ../caixa-teia # pin` \
4023 — the canonical paste-from-values.yaml / paste-from-K8s-manifest cross-idiom-\
4024 leak); RFC 3986 §3.5 reserves `#` as the URL fragment-identifier delimiter (the \
4025 canonical paste-from-browser-address-bar `github.com/foo/bar#readme` / \
4026 `github.com/foo/bar#L42` permalink shape, and the symmetric Nix-flake-ref \
4027 cross-idiom leak `github:foo/bar#packageName` where `#` selects a flake \
4028 output); the same cross-config-DSL surface extends to HCL / Terraform / Nix \
4029 flake attributes / dotenv `.env` / gitconfig / .gitignore / ini / TOML where \
4030 `#` is likewise the comment-lead. POSIX `std::path::Path` treats the byte as a \
4031 literal path-component byte, so a `:caminho \"../caixa-teia # legacy sibling\"` \
4032 (the canonical paste-from-shell-history-with-trailing-annotation footgun), \
4033 `:caminho \"../caixa-teia # pin\"` (the symmetric YAML flow-scalar paste-with-\
4034 trailing-comment shape), or `:caminho \"../caixa-teia#readme\"` (the URL \
4035 fragment paste-from-browser-address-bar shape) silently passes every prior arm \
4036 and the resolver folds the value through `Path::new(caminho).join(<file>)` \
4037 looking for a literal subdirectory named `../caixa-teia # legacy sibling` and \
4038 fails at resolve time with a non-self-locating `No such file or directory` \
4039 error far from the source caixa.lisp — while every downstream shell / YAML / \
4040 URL parser silently truncates the value at the `#` byte to `../caixa-teia`, so \
4041 a `feira tofu` shell-out and a `nix flake check` on an emitted YAML `path:` \
4042 scalar disagree with the resolver on which directory the value names. The \
4043 lacre pipeline embeds the value verbatim in its per-dep content-address \
4044 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in \
4045 the BLAKE3 closure and rides into every shell-spawned subprocess (the \
4046 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-\
4047 side `nix` spawn) as the canonical shell-metachar / comment-lead / URL-\
4048 fragment-delimiter surface every peer single-token-shaped typed slot already \
4049 closes. The peer `:fonte :repo` axis closes the byte under the same URL-\
4050 fragment-identifier banner (a68f818 `#` on `is_git_repo_url`). Express the \
4051 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
4052 workspace directory name carries no shell-comment / URL-fragment / YAML-\
4053 comment semantic; move any trailing annotation to a tatara-lisp `;`-comment \
4054 on the surrounding form (`;; legacy sibling` above the `(:caminho ...)` slot) \
4055 and drop any `#fragment` tail entirely (fragment identifiers select \
4056 renderings, not directories, and `:caminho` names a directory).",
4057 ch = *byte as char
4058 )]
4059 FonteCaminhoShellComment {
4060 nome: String,
4061 caminho: String,
4062 byte: u8,
4063 },
4064 #[error(
4065 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains URL-\
4066 percent-encoding-escape / printf-format-specifier / bash-job-control-specifier \
4067 / YAML-directive-lead metacharacter 0x{byte:02x} `{ch}` (RFC 3986 §2.1 reserves \
4068 `%` as the URL percent-encoding-escape — `%HH` is the mandatory encoding \
4069 mechanism for every byte outside the `unreserved` alphanumeric / `-` / `.` / \
4070 `_` / `~` set, and `%` itself must be percent-encoded as `%25` to appear \
4071 literally inside a URL value. The canonical paste-from-browser-address-bar \
4072 percent-encoded-space footgun (an author copies `../caixa%20teia` out of a URL-\
4073 encoded README hyperlink / browser address bar / percent-encoded permalink \
4074 expecting `%20` to decode to a literal space at the filesystem layer) locks two \
4075 distinct BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`) for \
4076 what the author intended as the byte-identical sibling-workspace dep. POSIX \
4077 `std::path::Path` treats the byte as a literal path-component byte, so \
4078 `Path::join` looks for a literal `./{caminho}` subdirectory and fails at \
4079 resolve time with a non-self-locating `No such file or directory` error far \
4080 from the source caixa.lisp — while every downstream URL parser / shell printf \
4081 builtin / YAML directive parser silently reinterprets the byte to a different \
4082 value than the resolver's `Path::join` sees. Beyond the URL-encoding hazard, \
4083 `%` is the C / POSIX printf format-directive lead-in (`%s`, `%d`, `%02x` — \
4084 wired into every POSIX shell's `printf` builtin, the canonical CWE-134 format-\
4085 string-injection vector); the bash / zsh / ksh job-control-specifier lead-in \
4086 (`%1` names \"job 1\", `%%` names \"the current job\", `%foo` names \"the most \
4087 recent job whose command started with `foo`\" — a future `kill %1` invocation \
4088 silently redirects the signal to a wrong target); the YAML 1.2 §6.8.1 \
4089 directive lead-in (`%YAML 1.2` / `%TAG` — the paste-from-top-of-doc YAML \
4090 directive block cross-idiom leak); and the Windows-shell env-var-reference \
4091 lead-in (`%PATH%` — the paste-from-`.bat` / paste-from-PowerShell-`%env:PATH%` \
4092 cross-idiom leak). The lacre pipeline embeds the value verbatim in its per-dep \
4093 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
4094 byte lands in the BLAKE3 closure and rides into every shell-spawned subprocess \
4095 (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4096 operator-side `nix` spawn) as the canonical URL-percent-encoding-escape / \
4097 printf-format-specifier / job-control-specifier surface every peer single-\
4098 token-shaped typed slot already closes. The peer `:fonte :repo` axis closes \
4099 the byte under the same URL-percent-encoding-escape banner (a323db8 `%` on \
4100 `is_git_repo_url`). Express the path as a bare relative single-token like \
4101 \"../caixa-teia\" — the sibling-workspace directory name carries no URL-\
4102 percent-encoding-escape / format-specifier / job-control semantic; substitute \
4103 any `%20` percent-encoded-space with a literal space then reject the whole \
4104 value at the leading-whitespace / embedded-`?` arm on the same axis (a caixa \
4105 directory name never carries an embedded space in practice); drop any \
4106 `%2F`-encoded path separator in favor of a literal `/`; and drop any leading \
4107 `%YAML` / `%PATH%` cross-idiom-leak prefix entirely.",
4108 ch = *byte as char
4109 )]
4110 FonteCaminhoUrlPercentEncoding {
4111 nome: String,
4112 caminho: String,
4113 byte: u8,
4114 },
4115 #[error(
4116 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4117 variable-expansion / command-substitution / arithmetic-expansion / cross-config-\
4118 DSL-interpolation metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / \
4119 bash / zsh / dash / ksh / busybox ash / fish / nushell — lexes `$` per \
4120 POSIX.1-2017 §2.6 as the variable-expansion `$<name>` / braced-form `${{<name>}}` \
4121 / command-substitution `$(<cmd>)` / arithmetic-expansion `$((<expr>))` operator; \
4122 Nix uses `${{var}}` as the string-interpolation lead, Make uses `$(var)` / `$@` \
4123 / `$<` for variables and automatic-variables, JavaScript / TypeScript template \
4124 literals use `${{expr}}` for interpolation, envsubst / Kubernetes / OpenShift \
4125 templates use `${{VAR}}` for env-var-reference, PHP uses `$_GET` / `$_ENV` for \
4126 superglobals, Perl uses `$foo` for scalars, SASS / SCSS uses `$primary-color` \
4127 for variables, and PostgreSQL / SQLite use `$1` / `$2` for bind parameters — \
4128 the byte is a first-class parser byte in nearly every config / templating / \
4129 build-system DSL the substrate's paste-idiom surface routinely crosses. POSIX \
4130 `std::path::Path` treats the byte as a literal path-component byte, so the \
4131 canonical paste-from-shell-one-liner `:caminho \"../foo$HOME/bar\"` / paste-\
4132 from-CI-manifest `:caminho \"../foo${{WORKSPACE}}/bar\"` / paste-from-shell-\
4133 prompt `:caminho \"../foo$(whoami)/bar\"` footguns silently pass every prior \
4134 cascade arm (`$` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / \
4135 `?` / `(` / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%`) and route \
4136 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4137 subdirectory that fails at resolve time with a non-self-locating `No such file \
4138 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4139 the value verbatim in its per-dep content-address `path:{caminho}` at \
4140 caixa-resolver/src/resolve.rs:189, so byte-identical caixa.lisp values differing \
4141 only in whether the author substituted `$HOME` / `${{WORKSPACE}}` at author \
4142 time lock to two distinct BLAKE3 closures across two workstations whose \
4143 downstream envsubst / Nix / Make / K8s-template layers differ in `$VAR` \
4144 recognition — defeating the THEORY.md §V.2 render-determinism contract on the \
4145 same axis every prior `:caminho` arm protects. Beyond the determinism vector, \
4146 `$` at any position in a value flowing verbatim into a shell-spawned subprocess \
4147 is the canonical CWE-78 shell-command-injection surface every peer single-\
4148 token-shaped typed slot already closes: peer `:fonte :repo` axis rejects `$` \
4149 under the shell-variable-expansion / URL-sub-delim banner via `is_git_repo_url` \
4150 (b9d187c), peer `:fonte :tag` / `:fonte :branch` axes reject `$` as part of \
4151 `is_git_ref_name`'s printable-ASCII-restricted grammar (`git check-ref-format` \
4152 rejects the byte outright), and peer `:entrada :paths` axis rejects `$` via \
4153 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. The leading-`$` \
4154 position on the same axis routes through `FonteCaminhoVarExpansion` at the \
4155 f4efe9c leading-byte arm; this arm closes the last positional gap on the byte \
4156 so every position — leading and embedded — is structurally rejected. Substitute \
4157 the `$VAR` / `${{VAR}}` / `$(cmd)` template with the literal value at author \
4158 time, or express the path as a bare relative single-token like \
4159 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
4160 variable-expansion / command-substitution / arithmetic-expansion semantic.",
4161 ch = *byte as char
4162 )]
4163 FonteCaminhoShellVariableExpansion {
4164 nome: String,
4165 caminho: String,
4166 byte: u8,
4167 },
4168 #[error(
4169 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4170 history-expansion / RFC-3986-sub-delims / bang-operator metacharacter 0x{byte:02x} \
4171 `{ch}` (every interactive POSIX shell with history enabled — bash / ksh / zsh's \
4172 `bashcompat` / csh / tcsh — lexes `!` as the history-expansion prefix per bash \
4173 reference §9.3: `!command` re-runs the most recent history entry beginning with \
4174 `command`, `!!` re-runs the prior command verbatim, `!$` substitutes the last \
4175 word of the prior command, `!:N` substitutes the Nth word of the prior command, \
4176 and the substitution fires at every history-expansion-enabled shell context — \
4177 `set -o histexpand` is bash's default for interactive sessions and the layer \
4178 every `feira tofu` / `git clone` / `nix flake check` subprocess-argument \
4179 invocation crosses when spawned under `bash -i`. Beyond shell history, RFC 3986 \
4180 §2.2 lists `!` in the `sub-delims` set (the URL grammar admits the byte inside \
4181 a path segment, but every WHATWG-conformant special-scheme URL parser percent-\
4182 encodes it inside a query component via the 'special-query percent-encode set' \
4183 the peer `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte is \
4184 also the C / C++ / Rust / JavaScript / Python bang-operator (logical-negation \
4185 prefix — the paste-from-source-code idiom where an author copies \
4186 `!path.exists()` out of a Rust snippet and the trailing punctuation crosses \
4187 the string-literal boundary); the canonical English-typography emphasis / \
4188 exclamation mark (the paste-from-prose enthusiasm-form idiom where an author \
4189 writes `:caminho \"../caixa-teia!\"` expecting the substrate to coerce it to a \
4190 kebab-case slug); and the Nix flake-ref attribute-selection operator surface. \
4191 POSIX `std::path::Path` treats `!` as a literal path-component byte, so the \
4192 canonical paste-from-shell-history footgun `:caminho \"../caixa-teia!sudo\"` \
4193 (an author copies a `cd ../caixa-teia && !sudo make install` one-liner from a \
4194 quick-start README and the trailing `!sudo` rides in verbatim as a history-\
4195 expansion reference), the symmetric `:caminho \"../foo!!/bar\"` (the `!!` \
4196 repeat-prior-command paste idiom), the English-typography `:caminho \
4197 \"../caixa-teia!\"` (paste-from-prose enthusiasm-form), and the last-word-\
4198 substitution `:caminho \"../foo!$\"` shape silently pass every prior cascade \
4199 arm (`!` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` \
4200 / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$`) and route \
4201 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4202 subdirectory that fails at resolve time with a non-self-locating `No such file \
4203 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4204 the value verbatim in its per-dep content-address `path:{caminho}` at \
4205 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
4206 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
4207 future `feira tofu` shell-out, a future operator-side `nix flake check` spawn) \
4208 as the canonical shell-history-expansion / RFC-3986-sub-delims surface every \
4209 peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4210 axis closes the byte under the same shell-history-expansion / RFC-3986-sub-\
4211 delims banner (7d53c68 `!` on `is_git_repo_url`). Express the path as a bare \
4212 relative single-token like \"../caixa-teia\" — the sibling-workspace directory \
4213 name carries no shell-history-expansion / bang-operator semantic; drop any \
4214 `!sudo` / `!!` / `!$` history-expansion trailing paste-from-shell-history \
4215 idiom; and drop any trailing English-typography exclamation mark that pasted \
4216 from prose.",
4217 ch = *byte as char
4218 )]
4219 FonteCaminhoShellHistoryExpansion {
4220 nome: String,
4221 caminho: String,
4222 byte: u8,
4223 },
4224 #[error(
4225 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4226 history-substitution / RFC-3986-'unwise' / regex-negation metacharacter 0x{byte:02x} \
4227 `{ch}` (POSIX bash's `set -o histexpand` mode — the default for every interactive \
4228 session and every `bash -i` subprocess-argument context `feira tofu` / `git clone` / \
4229 `nix flake check` cross — lexes `^old^new^` per bash reference §9.3 as the 'quick \
4230 substitution' history operator that rewrites the prior command's `old` string to \
4231 `new` and re-executes it verbatim, the canonical typo-correction one-liner idiom \
4232 (`git clone <bad-url>` → `^bad^good` typo-fix-and-rerun the paste-from-shell-\
4233 history author trims only the leading `git clone` prefix from). RFC 3986 §2 lists \
4234 `^` in the 'unwise' set every URL parser is required to percent-encode-or-refuse at \
4235 the wire boundary, and the WHATWG URL spec's 'fragment percent-encode set' maps \
4236 `^` → `%5E` at the query / fragment component transition, so `Path::join` on the \
4237 literal value diverges from every downstream `feira tofu` curl-invocation / \
4238 artifact-registry-fetch that percent-encodes the byte before the wire. `^` is also \
4239 the regex character-class negation prefix (`[^abc]`), the bitwise XOR operator in \
4240 C / C++ / Rust / Python / JavaScript / Nix / Go, the Windows `cmd.exe` escape \
4241 metacharacter, and the LaTeX / Markdown / BibTeX superscript operator. POSIX \
4242 `std::path::Path` treats `^` as a literal path-component byte, so \
4243 `:caminho \"../foo^bar/baz\"` (embedded quick-substitution), `:caminho \
4244 \"../foo^\"` (trailing history-substitution-open shape), or `:caminho \"../x^y\"` \
4245 (XOR-expression paste-from-source) silently pass every prior cascade arm (`^` \
4246 isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` / `)` / `{{` \
4247 / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$` / `!`) and route through \
4248 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` subdirectory \
4249 that fails at resolve time with a non-self-locating `No such file or directory` \
4250 error far from the source caixa.lisp. The lacre pipeline embeds the value verbatim \
4251 in its per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
4252 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
4253 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4254 operator-side `nix flake check` spawn) as the canonical shell-history-substitution \
4255 / RFC-3986-unwise surface every peer single-token-shaped typed slot already closes. \
4256 The peer `:fonte :repo` axis closes the byte under the same shell-history-\
4257 substitution / RFC-3986-unwise banner (49e142f `^` on `is_git_repo_url`). Together \
4258 with the immediate-predecessor `!` arm (6a04767) this arm closes the full `set -o \
4259 histexpand` operator surface on the `:caminho` axis — the `!command` / `!!` / `!$` \
4260 prefix form via `!`, the `^old^new^` quick-substitution form via `^`. Express the \
4261 path as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
4262 directory name carries no shell-history-substitution / regex-negation / XOR-operator \
4263 semantic; drop any `^old^new` history-substitution paste-from-shell-history idiom; \
4264 drop any trailing `^` history-substitution-open fragment.",
4265 ch = *byte as char
4266 )]
4267 FonteCaminhoShellHistorySubstitution {
4268 nome: String,
4269 caminho: String,
4270 byte: u8,
4271 },
4272 #[error(
4273 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} has a trailing \
4274 `/` (the resolver's `Path::join` resolves `\"../caixa-teia\"` and \
4275 `\"../caixa-teia/\"` to the same directory, but the lacre pipeline embeds the \
4276 value verbatim in its per-dep content-address `path:{caminho}` at \
4277 caixa-resolver/src/resolve.rs:189, so two authors whose only difference is \
4278 shell tab-completion emit byte-divergent BLAKE3 closures for the same caixa — \
4279 defeating the THEORY.md §V.2 render-determinism contract via the trailing-\
4280 separator vector (the canonical paste-from-shell-tab-completion + paste-from-\
4281 `pwd`-with-`/`-suffix footgun, and the canonical Cargo-style `path = \
4282 \"../caixa-teia/\"` paste-from-Cargo-manifest cross-idiom leak). Drop the \
4283 trailing `/`; every `:caminho` value names a sibling-workspace directory \
4284 already, so the trailing separator carries no information. Use \
4285 `\"../caixa-teia\"` rather than `\"../caixa-teia/\"`)"
4286 )]
4287 FonteCaminhoTrailingSlash { nome: String, caminho: String },
4288 #[error(
4289 "{list} carries duplicate entry :nome {nome:?} — every dep list keys its \
4290 entries by caixa name (Cargo's [dependencies] / [dev-dependencies] tables \
4291 apply the same set-not-multiset discipline; one package per table), and \
4292 two entries naming the same caixa carry two version constraints / source \
4293 pins / feature sets for one identity. The caixa-resolver's lacre pipeline \
4294 consumes the list as a `HashMap`-keyed-by-`:nome` lookup: the second entry \
4295 silently overwrites the first at the resolver-side `concrete_versao` step, \
4296 and the dropped entry's pin / features never reach the closure — far from \
4297 the source caixa.lisp, with no field naming which `:deps` entry was the \
4298 silent loser. If two version constraints are genuinely needed (the rare \
4299 multi-version closure case the lacre pipeline doesn't yet support), the \
4300 author surface is two distinct caixa names (e.g. a `caixa-teia-v01` / \
4301 `caixa-teia-v02` aliased pair); within one list, one entry per caixa name."
4302 )]
4303 DuplicateNome { nome: String, list: &'static str },
4304 #[error(
4305 ":deps entry {nome:?} has empty :caracteristicas entry — every feature flag must \
4306 name a non-empty identifier on the target caixa (Cargo's [dependencies.<dep>.features] \
4307 applies the same per-entry non-empty discipline). An empty feature flag reaches the \
4308 caixa-resolver's lacre pipeline as a no-op feature enable, silently dropping the \
4309 author's intent far from the source caixa.lisp; drop the empty entry, or replace it \
4310 with the canonical kebab-case feature name the target caixa declares."
4311 )]
4312 CaracteristicaEmpty { nome: String },
4313 #[error(
4314 ":deps entry {nome:?} :caracteristicas entry {caracteristica:?} is not a valid Cargo \
4315 feature name: {reason} (the value flows verbatim into Cargo's \
4316 [dependencies.<dep>.features] list and Cargo's `restricted_names::validate_feature_name` \
4317 parser enforces the same shape at `cargo metadata` time; use a single-token \
4318 identifier like `\"http\"`, `\"derive\"`, or `\"runtime-tokio\"` — kebab-case ASCII \
4319 alphanumeric with `-`, `_`, `+`, or `.` as continuation characters, starting with \
4320 an ASCII alphanumeric or `_`)"
4321 )]
4322 CaracteristicaInvalid {
4323 nome: String,
4324 caracteristica: String,
4325 reason: String,
4326 },
4327 #[error(
4328 ":deps entry {nome:?} :caracteristicas carries duplicate feature {caracteristica:?} — \
4329 every feature-flag list keys its entries by name (Cargo's \
4330 [dependencies.<dep>.features] applies the same set-not-multiset discipline; one entry \
4331 per feature per dep), and two entries naming the same feature are a redundant \
4332 set-membership declaration for one identity (the feature-toggle slot is set-shaped; \
4333 enabling a feature twice has no additional semantic). The caixa-resolver's lacre \
4334 pipeline consumes the list as a set-shaped feature toggle — the resolver enables the \
4335 feature once regardless of declaration count, so the duplicate's pin / position never \
4336 reaches the closure with no field naming the silent loser. One entry per feature per \
4337 dep; if two distinct features are intended, name each verbatim."
4338 )]
4339 CaracteristicaDuplicate {
4340 nome: String,
4341 caracteristica: String,
4342 },
4343 #[error(
4344 "{list} entry :nome {nome:?} names the caixa itself — a caixa cannot depend \
4345 on itself (the lacre closure's dep-graph traversal is rooted at the caixa's \
4346 :nome, and a self-dep would be a one-node cycle the caixa-resolver either \
4347 rejects mid-traversal far from the source caixa.lisp or recurses on until \
4348 it exhausts its stack). Every :nome is globally-unique substrate identity, \
4349 so a :deps / :deps-dev entry whose :nome equals the parent caixa's :nome \
4350 *is* the parent itself, not a coincidentally-named peer. Drop the \
4351 self-referential dep entry — to reference code from this caixa, use \
4352 :bibliotecas / :exe / :servicos (the substrate-blessed shape for \
4353 referencing the caixa's own code surface) instead."
4354 )]
4355 DepIsSelf { nome: String, list: &'static str },
4356}
4357
4358// Fold the eleven `DepError::FonteCaminho<Variant> { nome: nome.to_string(),
4359// caminho: caminho.to_string() }` two-slot struct-variant wire-up sites at
4360// [`DepSource::validate_caminho`] onto one substrate primitive per typed
4361// variant — the paired `{ nome: String, caminho: String }` two-slot family
4362// on [`DepError`], sibling of the peer
4363// [`crate::supervisor::supervisor_caixa_only_ctors!`] (db09650, 3 variants
4364// on `{ caixa: String }`) on the `SupervisorError` envelope, the peer
4365// [`crate::aplicacao::contrato_empty_pair_ctors!`] (8580068, 4 variants on
4366// `{ de, para }`), [`crate::aplicacao::aplicacao_field_reason_ctors!`]
4367// (981060b, 7 variants on `{ <field>: String, reason: String }`),
4368// [`crate::aplicacao::contrato_target_ctors!`] (14b81d5, 2 variants on
4369// `{ de, para, wit, expected }`), and
4370// [`crate::aplicacao::contrato_pair_value_reason_ctors!`] (14e13f1, 3
4371// variants on `{ de, para, <field>: String, reason: String }`) on the
4372// `AplicacaoError` envelopes, the peer
4373// [`crate::layout::layout_violation_ctors!`] (131ca0d, 16 variants on
4374// `{ caixa, issue }`), [`crate::layout::layout_slot_kind_ctors!`]
4375// (0419438, 4 variants on `{ caixa, kind, slots }`),
4376// [`crate::LayoutError::missing_entry`] (1b09f9d, one variant on
4377// `{ kind, path }`), and [`crate::layout::layout_nome_only_ctors!`]
4378// (3fe3dd7, 6 variants on `<Variant>(String)`) on the `LayoutError`
4379// envelopes, the peer three [`crate::limits::limits_codec_value_*_ctors!`]
4380// codec-family macros (81c856c, 12 wire-ups) on the `LimitsError`
4381// envelope, and the peer [`crate::upgrade::upgrade_from_script_ctors!`]
4382// (8e67041, 3 variants on `{ from: String, script: PathBuf }`) on the
4383// `UpgradeError` envelope. First fold family on this `DepError` envelope.
4384//
4385// Each of the eleven wire-up sites on this shape (the leading-byte cascade
4386// closing the seven `FonteCaminho{Absolute, TildeExpansion, VarExpansion,
4387// LeadingWhitespace, LeadingHyphen}` arms; the orthogonal single-metachar
4388// cascade closing `FonteCaminhoBackslash` on `\`; the shell-lexer-metachar
4389// cascade closing `FonteCaminhoShell{Pipe, Semicolon, Background,
4390// CommandSubstitution}` on the four single-byte shell operators; and the
4391// trailing-`/` reproducibility arm closing `FonteCaminhoTrailingSlash`)
4392// opened the identical `DepError::FonteCaminho<Variant> { nome:
4393// nome.to_string(), caminho: caminho.to_string() }` four-line
4394// struct-literal against the same `(nome: &str, caminho: &str)` local pair
4395// — the exact "same block re-inlined at every consumer" shape the PRIME
4396// DIRECTIVE names as a bug, on the same altitude the peer `LayoutError` /
4397// `AplicacaoError` / `SupervisorError` / `LimitsError` / `UpgradeError`
4398// families each closed on their sibling envelopes. The eleven variants
4399// share one `{ nome: String, caminho: String }` shape, so the fold routes
4400// each wire-up site through one dispatch per typed variant.
4401//
4402// The macro below generates one `#[must_use]` inherent constructor per
4403// variant of shape `fn <ctor>(nome: &str, caminho: &str) -> Self`, so every
4404// wire-up site collapses onto one dispatch:
4405// `DepError::<ctor>(nome, caminho)`, byte-equal to the pre-lift
4406// struct-literal on the same `(&str, &str)` fixture. The uniform two-field
4407// construction (`nome.to_string()` / `caminho.to_string()`) is spelled
4408// once — inside the macro — rather than at every wire-up site.
4409//
4410// The three sibling shapes on this envelope carrying additional payload
4411// (the `FonteCaminhoEmpty` one-field `{ nome }` shape at the empty-first
4412// arm, the twelve `FonteCaminho<Variant> { nome, caminho, byte }`
4413// three-field shapes at the per-byte-classification arms, and the
4414// per-arm `FonteCaminho{ControlChar,ShellRedirection,ShellGlob,
4415// ShellSubshellGrouping,ShellBraceExpansion,ShellBracketExpansion,
4416// ShellQuoteGrouping,ShellComment,UrlPercentEncoding,
4417// ShellVariableExpansion,ShellHistoryExpansion,ShellHistorySubstitution}`
4418// cluster) stay on their pre-lift open-coded shape — each carries a
4419// distinct field set (`byte: u8` naming the offending byte) that would
4420// break the uniform-two-field routing this macro promises. Each is one
4421// wire-up per variant already, so extending the fold to a per-shape
4422// sibling macro is future compounding work rather than duplication this
4423// lift needs to close.
4424//
4425// Every future consumer that wants to construct one of these eleven
4426// variants outside the current in-crate [`DepSource::validate_caminho`]
4427// wire-up sites (a deferred `caixa-resolver` per-`:caminho` re-validator
4428// at lacre-resolve time re-checking the same value-shape axes the resolver
4429// consumes, a future `feira validate --deps` per-caixa admission verb
4430// re-checking the `:fonte :caminho` axis, a per-lacre overlay resolver
4431// rejecting a `:caminho` value against a cluster-local snapshot) now
4432// reaches each variant through one call rather than re-inlining the
4433// four-line struct-literal in lockstep with the eleven in-crate wire-up
4434// sites.
4435macro_rules! fonte_caminho_ctors {
4436 ($($ctor:ident => $variant:ident),* $(,)?) => {
4437 impl DepError {
4438 $(
4439 #[doc = concat!(
4440 "Construct a [`DepError::",
4441 stringify!($variant),
4442 "`] naming the offending `:deps :nome` + `:fonte ",
4443 "(:tipo path …) :caminho` pair. Folds the uniform ",
4444 "`Self::",
4445 stringify!($variant),
4446 " { nome: nome.to_string(), caminho: caminho.to_string() }` ",
4447 "two-slot struct-literal onto one substrate primitive so ",
4448 "every [`DepSource::validate_caminho`] wire-up on this ",
4449 "variant reads through one dispatch rather than the ",
4450 "pre-lift four-line open-coded block."
4451 )]
4452 #[must_use]
4453 pub fn $ctor(nome: &str, caminho: &str) -> Self {
4454 Self::$variant {
4455 nome: nome.to_string(),
4456 caminho: caminho.to_string(),
4457 }
4458 }
4459 )*
4460 }
4461 };
4462}
4463
4464fonte_caminho_ctors! {
4465 fonte_caminho_absolute => FonteCaminhoAbsolute,
4466 fonte_caminho_tilde_expansion => FonteCaminhoTildeExpansion,
4467 fonte_caminho_var_expansion => FonteCaminhoVarExpansion,
4468 fonte_caminho_leading_whitespace => FonteCaminhoLeadingWhitespace,
4469 fonte_caminho_leading_hyphen => FonteCaminhoLeadingHyphen,
4470 fonte_caminho_backslash => FonteCaminhoBackslash,
4471 fonte_caminho_shell_pipe => FonteCaminhoShellPipe,
4472 fonte_caminho_shell_semicolon => FonteCaminhoShellSemicolon,
4473 fonte_caminho_shell_background => FonteCaminhoShellBackground,
4474 fonte_caminho_shell_command_substitution => FonteCaminhoShellCommandSubstitution,
4475 fonte_caminho_trailing_slash => FonteCaminhoTrailingSlash,
4476}
4477
4478#[allow(clippy::trivially_copy_pass_by_ref)]
4479fn is_false(b: &bool) -> bool {
4480 !*b
4481}
4482
4483#[cfg(test)]
4484mod tests {
4485 use super::*;
4486
4487 #[test]
4488 fn registry_dep_is_minimal() {
4489 let d = Dep::simple("caixa-teia", "^0.1");
4490 assert_eq!(d.nome, "caixa-teia");
4491 assert_eq!(d.versao, "^0.1");
4492 assert!(d.fonte.is_none());
4493 assert!(!d.opcional());
4494 assert!(d.caracteristicas().is_empty());
4495 }
4496
4497 #[test]
4498 fn dep_string_scalar_accessor_pair_is_const_fn() {
4499 // Fail-before-pass-after pin on [`Dep::nome`] +
4500 // [`Dep::versao_requirement`]'s `const`-eval-surface posture.
4501 // Each accessor projects the per-`:deps` / per-`:deps-dev`
4502 // entry's [`String`] storage through the `pub const fn`
4503 // [`String::as_str`] (const-stable since Rust 1.87, well
4504 // within the workspace MSRV) — any future accidental
4505 // downgrade to non-`const` fails the corresponding
4506 // `<name>_via_const_fn` wrapper at caixa-core build time with
4507 // E0015 (`cannot call non-const method`), strictly stronger
4508 // than a runtime `assert!`. Sibling of the peer
4509 // per-M2/M3/universal-axis `String → &str` scalar-accessor
4510 // family pins on the sibling `const`-eval-surface passes
4511 // ([`crate::Caixa::nome`] / [`crate::Caixa::versao`] at the
4512 // top-level manifest, [`crate::CaixaVersion::as_str`] at the
4513 // typed-newtype wrapper, [`crate::aplicacao::Membro::nome`] /
4514 // [`crate::aplicacao::Membro::versao_requirement`] at the M3
4515 // membership axis, [`crate::aplicacao::Entrada::hostname`] /
4516 // [`crate::aplicacao::Entrada::destination`] at the M3
4517 // ingress axis, [`crate::supervisor::ChildSpec::nome`] /
4518 // [`crate::supervisor::ChildSpec::versao_requirement`] at the
4519 // M2 supervisor-tree axis,
4520 // [`crate::upgrade::UpgradeFromEntry::prior_versao`] at the
4521 // M2 upgrade axis, and the per-`:contratos`
4522 // [`crate::aplicacao::WitContract::source`] /
4523 // [`crate::aplicacao::WitContract::destination`] /
4524 // [`crate::aplicacao::WitContract::world_ref`] trio the
4525 // sibling pin at 279823b already anchors).
4526 const fn nome_via_const_fn(d: &Dep) -> &str {
4527 d.nome()
4528 }
4529 const fn versao_via_const_fn(d: &Dep) -> &str {
4530 d.versao_requirement()
4531 }
4532 for (nome, versao) in [
4533 ("caixa-teia", "^0.1"),
4534 ("caixa-mesh", "~0.2.3"),
4535 ("caixa-helm", "*"),
4536 ] {
4537 let d = Dep::simple(nome, versao);
4538 assert_eq!(nome_via_const_fn(&d), d.nome());
4539 assert_eq!(versao_via_const_fn(&d), d.versao_requirement());
4540 assert_eq!(d.nome(), nome);
4541 assert_eq!(d.versao_requirement(), versao);
4542 }
4543 }
4544
4545 #[test]
4546 fn dep_outer_accessor_family_is_const_fn() {
4547 // Fail-before-pass-after pin on [`Dep::fonte`] +
4548 // [`Dep::caracteristicas`]'s `const`-eval-surface posture.
4549 // Each accessor projects the per-`:deps` / per-`:deps-dev`
4550 // entry's composite / list storage through a `pub const fn`
4551 // stdlib method (`Option::<DepSource>::as_ref` /
4552 // `Vec::<String>::as_slice`, both const-stable since Rust
4553 // 1.83, well within the workspace MSRV). Any future
4554 // accidental downgrade to non-`const` fails the corresponding
4555 // `<name>_via_const_fn` wrapper at caixa-core build time with
4556 // E0015 (`cannot call non-const method`), strictly stronger
4557 // than a runtime `assert!` and side-stepping the destructor-
4558 // in-const restriction the `Dep` fixture's `String` /
4559 // `Option<DepSource>` / `Vec<String>` carriers rule out on the
4560 // direct-`const _: () = assert!(...)` residence.
4561 //
4562 // Peer of the sibling per-`Dep` scalar-accessor pair pin
4563 // [`dep_string_scalar_accessor_pair_is_const_fn`] on the same
4564 // outer per-dep-list-entry [`Dep`] altitude — this pin extends
4565 // the `const`-eval-surface discipline onto the composite-
4566 // reference and slice-return arms of the outer-`Dep` accessor
4567 // family, closing the four-slot outer surface (`:nome` +
4568 // `:versao` + `:fonte` + `:caracteristicas`) on the `const`-fn
4569 // posture. The `:opcional` `bool` arm already carries the
4570 // posture through [`Dep::opcional`]'s prior `pub const fn`
4571 // declaration, so this pin lands the last two unlifted
4572 // outer-`Dep` accessors and closes the family.
4573 const fn fonte_via_const_fn(d: &Dep) -> Option<&DepSource> {
4574 d.fonte()
4575 }
4576 const fn caracteristicas_via_const_fn(d: &Dep) -> &[String] {
4577 d.caracteristicas()
4578 }
4579 // `Dep::simple` — no `:fonte`, empty `:caracteristicas`.
4580 let empty = Dep::simple("caixa-teia", "^0.1");
4581 assert!(fonte_via_const_fn(&empty).is_none());
4582 assert_eq!(fonte_via_const_fn(&empty), empty.fonte());
4583 assert!(caracteristicas_via_const_fn(&empty).is_empty());
4584 assert_eq!(
4585 caracteristicas_via_const_fn(&empty),
4586 empty.caracteristicas()
4587 );
4588 // `Dep::git` — `:fonte` is `Some(Git{…})`, `:caracteristicas`
4589 // still empty.
4590 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
4591 assert!(fonte_via_const_fn(&git).is_some());
4592 assert_eq!(fonte_via_const_fn(&git), git.fonte());
4593 assert_eq!(caracteristicas_via_const_fn(&git), git.caracteristicas());
4594 // Populated `:caracteristicas` — exercise the non-empty
4595 // slice-view arm to pin the accessor's borrow shape against
4596 // both a `Vec::new()` empty backing buffer and a populated one.
4597 let mut with_features = Dep::simple("caixa-teia", "^0.1");
4598 with_features.caracteristicas = vec!["feat-a".into(), "feat-b".into()];
4599 assert_eq!(caracteristicas_via_const_fn(&with_features).len(), 2);
4600 assert_eq!(
4601 caracteristicas_via_const_fn(&with_features),
4602 with_features.caracteristicas()
4603 );
4604 }
4605
4606 #[test]
4607 fn git_dep_carries_tag() {
4608 let d = Dep::git("t", "*", "github:o/r", "v1");
4609 match d.fonte {
4610 Some(DepSource::Git {
4611 ref repo, ref tag, ..
4612 }) => {
4613 assert_eq!(repo, "github:o/r");
4614 assert_eq!(tag.as_deref(), Some("v1"));
4615 }
4616 _ => panic!("expected Git source"),
4617 }
4618 }
4619
4620 #[test]
4621 fn validate_accepts_simple_dep() {
4622 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
4623 }
4624
4625 #[test]
4626 fn validate_rejects_empty_nome() {
4627 // The fail-before-pass-after pin for `:nome ""`: the empty-name
4628 // arm fires first so the per-entry parse-side diagnostic doesn't
4629 // emit a useless `nome: ""` reference.
4630 let mut d = Dep::simple("placeholder", "^0.1");
4631 d.nome = String::new();
4632 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4633 }
4634
4635 #[test]
4636 fn validate_rejects_empty_versao() {
4637 // `parse_requirement("")` returns `Ok(VersionReq::STAR)` (the
4638 // semver crate accepts the empty string as a wildcard match),
4639 // so the empty-`:versao` arm is structurally necessary even
4640 // with the parse arm in place — mirrors `MembroVersaoEmpty` /
4641 // `EmptyChildVersion` ordering on the other two `:versao` axes.
4642 let mut d = Dep::simple("caixa-teia", "ignored");
4643 d.versao = String::new();
4644 let err = d.validate().unwrap_err();
4645 assert!(
4646 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4647 "got {err:?}"
4648 );
4649 }
4650
4651 // ── value-shape: DNS-1123 label on :deps :nome ────────────────────────
4652
4653 #[test]
4654 fn validate_rejects_nome_with_uppercase() {
4655 // The fail-before-pass-after pin: a non-empty but uppercase
4656 // `:nome` silently passed `validate()` on every pre-gate
4657 // codebase because the prior shape only refused the empty
4658 // string. The DNS-1123 violation surfaced far downstream at
4659 // lacre-resolve time when the *target* caixa's `:nome` failed
4660 // its own gate — far from the `:deps` entry, with a diagnostic
4661 // naming the target rather than the dep entry that referenced
4662 // it. Same fail-before-pass-after fixture pinned for
4663 // `:membros :caixa` (3f9d7a0), `:children :caixa` (31bfa43),
4664 // and Caixa `:nome` (6c992f8).
4665 let d = Dep::simple("Caixa-Teia", "^0.1");
4666 let err = d.validate().unwrap_err();
4667 assert!(
4668 matches!(
4669 err,
4670 DepError::NomeInvalid { ref nome, ref reason }
4671 if nome == "Caixa-Teia" && reason.contains("uppercase")
4672 ),
4673 "got {err:?}"
4674 );
4675 }
4676
4677 #[test]
4678 fn validate_rejects_nome_with_underscore() {
4679 // RFC 1123 allows `[a-z0-9-]` only; underscore is the canonical
4680 // "I'm thinking of Go module names / Python identifiers" leak.
4681 // Same fixture pinned for the peer caixa-identifier axes.
4682 let d = Dep::simple("caixa_teia", "^0.1");
4683 let err = d.validate().unwrap_err();
4684 assert!(
4685 matches!(
4686 err,
4687 DepError::NomeInvalid { ref nome, ref reason }
4688 if nome == "caixa_teia" && reason.contains('_')
4689 ),
4690 "got {err:?}"
4691 );
4692 }
4693
4694 #[test]
4695 fn validate_rejects_nome_with_dot() {
4696 // A `:deps :nome` is a single DNS-1123 *label*, not a
4697 // subdomain — dots are rejected. The `"caixa.teia"` shape is
4698 // the canonical "I confused the dep name with the FQDN /
4699 // namespace" footgun, distinct from the legitimate
4700 // `:fonte :repo "github:org/caixa-teia"` axis.
4701 let d = Dep::simple("caixa.teia", "^0.1");
4702 let err = d.validate().unwrap_err();
4703 assert!(
4704 matches!(
4705 err,
4706 DepError::NomeInvalid { ref nome, ref reason }
4707 if nome == "caixa.teia" && reason.contains('.')
4708 ),
4709 "got {err:?}"
4710 );
4711 }
4712
4713 #[test]
4714 fn validate_rejects_nome_with_leading_hyphen() {
4715 // RFC 1123 requires alphanumeric at both label boundaries.
4716 // Pinned in parity with the peer DNS-1123 fixtures.
4717 let d = Dep::simple("-caixa-teia", "^0.1");
4718 let err = d.validate().unwrap_err();
4719 assert!(
4720 matches!(
4721 err,
4722 DepError::NomeInvalid { ref nome, ref reason }
4723 if nome == "-caixa-teia" && reason.contains("alphanumeric")
4724 ),
4725 "got {err:?}"
4726 );
4727 }
4728
4729 #[test]
4730 fn validate_rejects_nome_with_trailing_hyphen() {
4731 let d = Dep::simple("caixa-teia-", "^0.1");
4732 let err = d.validate().unwrap_err();
4733 assert!(
4734 matches!(
4735 err,
4736 DepError::NomeInvalid { ref nome, ref reason }
4737 if nome == "caixa-teia-" && reason.contains("alphanumeric")
4738 ),
4739 "got {err:?}"
4740 );
4741 }
4742
4743 #[test]
4744 fn validate_rejects_nome_with_slash() {
4745 // The canonical "I copied the GitHub repo path into `:nome`
4746 // instead of `:fonte :repo`" typo. A `/` in the name leaks the
4747 // lacre-side `:repositorio` shape (`pleme-io/caixa-teia`) into
4748 // the local-name slot. Same fixture pinned for `:membros
4749 // :caixa` (3f9d7a0).
4750 let d = Dep::simple("pleme-io/caixa-teia", "^0.1");
4751 let err = d.validate().unwrap_err();
4752 assert!(
4753 matches!(
4754 err,
4755 DepError::NomeInvalid { ref nome, ref reason }
4756 if nome == "pleme-io/caixa-teia" && reason.contains('/')
4757 ),
4758 "got {err:?}"
4759 );
4760 }
4761
4762 #[test]
4763 fn validate_rejects_nome_too_long() {
4764 // 64-byte label — one over the RFC 1035 / RFC 1123 label cap.
4765 // Built from a valid character set so the length-bound
4766 // diagnostic surfaces before any per-character check (the
4767 // order pin parallel to the per-character predicates inside
4768 // [`crate::render::is_dns_1123_label`]).
4769 let long = "a".repeat(64);
4770 let d = Dep::simple(&long, "^0.1");
4771 let err = d.validate().unwrap_err();
4772 assert!(
4773 matches!(
4774 err,
4775 DepError::NomeInvalid { ref nome, ref reason }
4776 if nome.len() == 64 && reason.contains("max length of 63")
4777 ),
4778 "got {err:?}"
4779 );
4780 }
4781
4782 #[test]
4783 fn validate_accepts_canonical_nome_labels() {
4784 // Positive-control sweep — every form the K8s apiserver
4785 // accepts as a DNS-1123 label must round-trip through
4786 // validate. Covers a hyphen-bearing label, a numeric-suffix
4787 // label, a leading-digit label, a single-character label, and
4788 // a 63-byte (exactly the cap) label — the same fixture set
4789 // the peer `:membros :caixa` / `:children :caixa` positive
4790 // controls pin.
4791 for nome in [
4792 "caixa-teia",
4793 "caixa-resolver2",
4794 "2nd-tier-cache",
4795 "x",
4796 "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0",
4797 ] {
4798 Dep::simple(nome, "^0.1")
4799 .validate()
4800 .unwrap_or_else(|e| panic!("canonical label {nome:?} must validate, got {e:?}"));
4801 }
4802 }
4803
4804 #[test]
4805 fn nome_empty_takes_precedence_over_nome_invalid() {
4806 // Ordering pin: `NomeEmpty` is the more self-locating
4807 // diagnostic on `""` and must lead — `is_dns_1123_label` is
4808 // only reached after the empty-check fires at the call site.
4809 // Mirrors `membro_caixa_empty_takes_precedence_over_invalid`
4810 // (3f9d7a0) on the peer caixa-identifier axis.
4811 let mut d = Dep::simple("placeholder", "^0.1");
4812 d.nome = String::new();
4813 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4814 }
4815
4816 #[test]
4817 fn nome_invalid_fires_before_versao_empty() {
4818 // Ordering pin: a malformed `:nome` fires before any `:versao`
4819 // axis check on the *same* entry — the per-entry shape gates
4820 // run top-to-bottom (nome empty → nome shape → versao empty →
4821 // versao parse → fonte shape), so a one-entry caixa.lisp with
4822 // both wrong sees the name-side diagnostic first (the name is
4823 // the self-locating axis — without a valid name, the parse
4824 // diagnostic can't quote `:nome "<bad>"`). Same ordering
4825 // discipline as `membro_caixa_invalid_fires_before_versao_check`
4826 // (3f9d7a0).
4827 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4828 d.versao = String::new();
4829 let err = d.validate().unwrap_err();
4830 assert!(
4831 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4832 "got {err:?}"
4833 );
4834 }
4835
4836 #[test]
4837 fn nome_invalid_fires_before_versao_invalid() {
4838 // Ordering pin: a malformed `:nome` fires before the `:versao`
4839 // parse-side check on the *same* entry. Pin separately from
4840 // the empty-versao ordering so a future re-ordering surfaces
4841 // here, parallel to the b0c8389 / c4213a4 trajectory.
4842 let d = Dep::simple("Caixa-Teia", "^^0.1");
4843 let err = d.validate().unwrap_err();
4844 assert!(
4845 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4846 "got {err:?}"
4847 );
4848 }
4849
4850 #[test]
4851 fn nome_invalid_fires_before_fonte_invalid() {
4852 // Ordering pin: a malformed `:nome` fires before the `:fonte`
4853 // shape check on the *same* entry. The `:fonte` diagnostic
4854 // names the offending dep's `:nome` verbatim (via
4855 // `DepSource::validate(&self.nome)`), so a non-self-locating
4856 // name would taint the downstream diagnostic too — the gate
4857 // ordering keeps both diagnostics individually self-locating.
4858 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4859 d.fonte = Some(DepSource::Git {
4860 repo: String::new(),
4861 tag: None,
4862 rev: None,
4863 branch: None,
4864 });
4865 let err = d.validate().unwrap_err();
4866 assert!(
4867 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4868 "got {err:?}"
4869 );
4870 }
4871
4872 #[test]
4873 fn nome_invalid_diagnostic_carries_offending_name() {
4874 // The diagnostic-shape pin: the error names the offending
4875 // `:nome` value verbatim so the author can grep their
4876 // caixa.lisp without re-running the build, and carries a
4877 // non-empty `reason` from `is_dns_1123_label` so the
4878 // predicate's own wording flows through to the diagnostic.
4879 // Same shape as `MembroCaixaInvalid` (3f9d7a0),
4880 // `ChildCaixaInvalid` (31bfa43), `ManifestError::NomeInvalid`
4881 // (6c992f8) — the four DNS-1123 caixa-identifier axes now
4882 // share a structurally-equivalent diagnostic family.
4883 let d = Dep::simple("Caixa_Teia", "^0.1");
4884 let err = d.validate().unwrap_err();
4885 let DepError::NomeInvalid { nome, reason } = err else {
4886 panic!("expected NomeInvalid, got other variant");
4887 };
4888 assert_eq!(nome, "Caixa_Teia");
4889 assert!(
4890 !reason.is_empty(),
4891 "NomeInvalid `reason` must carry the predicate's wording verbatim"
4892 );
4893 }
4894
4895 #[test]
4896 fn validate_rejects_invalid_versao_requirement() {
4897 // The fail-before-pass-after pin: a non-empty but malformed
4898 // requirement (`"^bad-version"`) silently passed every pre-gate
4899 // codebase because `:deps :versao` wasn't validated. The parse
4900 // failure surfaced far downstream at lacre-resolve time with a
4901 // `semver::Error` that didn't name which `:deps` entry carried
4902 // the typo. The new gate moves the check to caixa-build time
4903 // at the source caixa.lisp.
4904 let d = Dep::simple("caixa-teia", "^bad-version");
4905 let err = d.validate().unwrap_err();
4906 assert!(
4907 matches!(
4908 err,
4909 DepError::VersaoInvalid { ref nome, ref versao, .. }
4910 if nome == "caixa-teia" && versao == "^bad-version"
4911 ),
4912 "got {err:?}"
4913 );
4914 }
4915
4916 #[test]
4917 fn validate_rejects_versao_with_double_caret_typo() {
4918 // `"^^0.1"` is the canonical doubled-caret typo — looks like a
4919 // Cargo-shaped requirement on first glance but fails the parser
4920 // because semver doesn't accept stacked operators. Pin this
4921 // adjacent-shape footgun explicitly so a future relaxation that
4922 // accepts "looks-canonical-but-isn't" forms surfaces here, in
4923 // parity with the `:membros` / `:children` fixtures.
4924 let d = Dep::simple("caixa-teia", "^^0.1");
4925 let err = d.validate().unwrap_err();
4926 assert!(
4927 matches!(
4928 err,
4929 DepError::VersaoInvalid { ref nome, ref versao, .. }
4930 if nome == "caixa-teia" && versao == "^^0.1"
4931 ),
4932 "got {err:?}"
4933 );
4934 }
4935
4936 #[test]
4937 fn validate_rejects_versao_with_v_prefixed_tag() {
4938 // `"v0.1"` is the canonical "git-tag-shape leaking into the
4939 // semver requirement slot" typo — an author copies the
4940 // publish-side git-tag string verbatim into `:versao`, but
4941 // Cargo's semver parser rejects the leading `v`. Same fixture
4942 // pinned for `:membros :versao` (9888b13) and `:children
4943 // :versao` (b38ff3a). (Bare `x`-glob shorthands like `^0.1.x`
4944 // are *accepted* by the semver crate as an `*` wildcard on the
4945 // patch axis — they're a Cargo-side valid shape, not a typo.)
4946 let d = Dep::simple("caixa-teia", "v0.1");
4947 let err = d.validate().unwrap_err();
4948 assert!(
4949 matches!(
4950 err,
4951 DepError::VersaoInvalid { ref nome, ref versao, .. }
4952 if nome == "caixa-teia" && versao == "v0.1"
4953 ),
4954 "got {err:?}"
4955 );
4956 }
4957
4958 #[test]
4959 fn validate_accepts_canonical_versao_forms() {
4960 // The five Cargo-shaped requirement forms `:membros :versao`
4961 // and `:children :versao` already accept via
4962 // `crate::parse_requirement` must pass the deps gate without
4963 // re-validating at the resolver layer. Pin every leg so a
4964 // future tightening of the canonical set surfaces here as a
4965 // test failure.
4966 for form in [
4967 "^0.1", // caret — minor-range pin (the most common shape)
4968 "~0.1.2", // tilde — patch-range pin
4969 "0.1.0", // exact — single-version pin
4970 "*", // wildcard — explicitly any-version
4971 ">=0.1, <2", // multi-range — comma-separated comparators
4972 ] {
4973 Dep::simple("caixa-teia", form)
4974 .validate()
4975 .unwrap_or_else(|e| panic!("canonical form {form:?} must validate, got {e:?}"));
4976 }
4977 }
4978
4979 #[test]
4980 fn versao_empty_takes_precedence_over_invalid() {
4981 // Order pin: the existing `VersaoEmpty` diagnostic (which
4982 // doesn't try to parse) fires before the new `VersaoInvalid`
4983 // parse-side diagnostic, so an empty `:versao` keeps its
4984 // narrower error message — `parse_requirement("")` would
4985 // otherwise return `Ok(STAR)` and silently pass, but the empty
4986 // arm catches it first.
4987 let mut d = Dep::simple("caixa-teia", "ignored");
4988 d.versao = String::new();
4989 let err = d.validate().unwrap_err();
4990 assert!(
4991 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4992 "got {err:?}"
4993 );
4994 }
4995
4996 #[test]
4997 fn nome_empty_takes_precedence_over_versao_invalid() {
4998 // Order pin: even when `:versao` is malformed and would raise
4999 // its own diagnostic, `:nome ""` fires first because the
5000 // per-entry parse diagnostic needs a non-empty name to be
5001 // self-locating. Mirrors the
5002 // `membros_validation_runs_before_contratos_membership_check`
5003 // ordering on the typed-graph layer.
5004 let mut d = Dep::simple("placeholder", "^bad");
5005 d.nome = String::new();
5006 let err = d.validate().unwrap_err();
5007 assert_eq!(err, DepError::NomeEmpty);
5008 }
5009
5010 #[test]
5011 fn versao_invalid_diagnostic_carries_offending_versao() {
5012 // The diagnostic-shape pin: the error names the offending
5013 // `:versao` value verbatim so the author can grep their
5014 // caixa.lisp without re-running the build, and carries a
5015 // non-empty `reason` from `semver::VersionReq::parse` so the
5016 // parser's own wording flows through to the diagnostic.
5017 let d = Dep::simple("caixa-teia", "not-a-req");
5018 let err = d.validate().unwrap_err();
5019 let DepError::VersaoInvalid {
5020 nome,
5021 versao,
5022 reason,
5023 } = err
5024 else {
5025 panic!("expected VersaoInvalid, got other variant");
5026 };
5027 assert_eq!(nome, "caixa-teia");
5028 assert_eq!(versao, "not-a-req");
5029 assert!(
5030 !reason.is_empty(),
5031 "VersaoInvalid `reason` must carry the parser's wording verbatim"
5032 );
5033 }
5034
5035 // -- :fonte value-shape gate ------------------------------------------
5036
5037 fn dep_with_fonte(fonte: DepSource) -> Dep {
5038 let mut d = Dep::simple("caixa-teia", "^0.1");
5039 d.fonte = Some(fonte);
5040 d
5041 }
5042
5043 #[test]
5044 fn validate_accepts_git_fonte_with_tag() {
5045 // The positive-control pin on the canonical git source — exactly
5046 // one of :tag/:rev/:branch set, non-empty :repo. Mirrors the
5047 // shape every existing caixa-resolver integration test uses.
5048 let d = dep_with_fonte(DepSource::Git {
5049 repo: "github:pleme-io/caixa-teia".into(),
5050 tag: Some("v0.1.0".into()),
5051 rev: None,
5052 branch: None,
5053 });
5054 d.validate().unwrap();
5055 }
5056
5057 #[test]
5058 fn validate_accepts_git_fonte_with_rev() {
5059 // Each of the three pin axes is independently a valid single-pin
5060 // shape; pin the :rev arm so a future relaxation that only
5061 // accepts :tag surfaces here. The value is a full 40-hex SHA-1
5062 // OID — the canonical `git rev-parse HEAD` emission shape the
5063 // `crate::render::is_git_oid` value-shape gate now requires;
5064 // abbreviated OIDs are ambiguous across repo history and
5065 // rejected at this gate (pinned separately by
5066 // `validate_rejects_git_fonte_with_rev_abbreviated_prefix`).
5067 let d = dep_with_fonte(DepSource::Git {
5068 repo: "github:pleme-io/caixa-teia".into(),
5069 tag: None,
5070 rev: Some("c0ffee0123abcdef0123456789abcdef01234567".into()),
5071 branch: None,
5072 });
5073 d.validate().unwrap();
5074 }
5075
5076 #[test]
5077 fn validate_accepts_git_fonte_with_branch() {
5078 // The :branch arm is the third valid single-pin shape — pinned
5079 // separately so the gate-accepts-all-three-pin-axes contract is
5080 // a build-error to relax.
5081 let d = dep_with_fonte(DepSource::Git {
5082 repo: "github:pleme-io/caixa-teia".into(),
5083 tag: None,
5084 rev: None,
5085 branch: Some("main".into()),
5086 });
5087 d.validate().unwrap();
5088 }
5089
5090 #[test]
5091 fn validate_accepts_path_fonte() {
5092 // The positive-control pin on the path source — non-empty
5093 // :caminho, no pin axes (paths have no commit identity). Pinned
5094 // so a future "paths must also pin a rev" tightening surfaces
5095 // here as a structural decision, not a silent break.
5096 let d = dep_with_fonte(DepSource::Path {
5097 caminho: "../caixa-teia".into(),
5098 });
5099 d.validate().unwrap();
5100 }
5101
5102 #[test]
5103 fn validate_rejects_git_fonte_with_empty_repo() {
5104 // The fail-before-pass-after pin for `(:tipo git :repo "" :tag
5105 // "v1")`: the empty-repo shape silently passed every pre-gate
5106 // codebase because `:fonte` wasn't validated. The git-clone
5107 // failure surfaced far downstream at lacre-resolve time with no
5108 // field naming which `:deps` entry carried the typo. The new
5109 // gate moves the check to caixa-build time at the source
5110 // caixa.lisp.
5111 let d = dep_with_fonte(DepSource::Git {
5112 repo: String::new(),
5113 tag: Some("v0.1.0".into()),
5114 rev: None,
5115 branch: None,
5116 });
5117 let err = d.validate().unwrap_err();
5118 assert!(
5119 matches!(err, DepError::FonteRepoEmpty { ref nome } if nome == "caixa-teia"),
5120 "got {err:?}"
5121 );
5122 }
5123
5124 // -- :repo value-shape gate -------------------------------------------
5125 //
5126 // The `:fonte (:tipo git :repo …)` value flows verbatim into the
5127 // caixa-resolver's `git clone <repo>` subprocess. The pre-gate
5128 // codebase admitted any non-empty string; the new
5129 // [`crate::render::is_git_repo_url`] predicate gates the git-porcelain
5130 // URL intersection-floor at validate time, peer with the three pin
5131 // axes (`:tag` + `:branch` via `is_git_ref_name`, `:rev` via
5132 // `is_git_oid`). Every test in this section is a fail-before /
5133 // pass-after pin on a specific authoring footgun.
5134
5135 #[test]
5136 fn validate_rejects_git_fonte_with_repo_carrying_trailing_space() {
5137 // The canonical paste-from-doc footgun on `:repo` — an author
5138 // copies `"github:pleme-io/caixa-teia "` (trailing space) out of
5139 // a doc paragraph. Until this gate landed the empty-repo arm
5140 // passed (the string isn't empty), the resolver issued
5141 // `git clone 'github:pleme-io/caixa-teia '`, and the failure
5142 // surfaced at clone time with a quoting-confused error far from
5143 // the source caixa.lisp. Same paste-from-doc footgun the
5144 // `:tag "v0.1.0 "` gate (e70d213) closes on the peer refname
5145 // axis — now closed on the `:repo` URL axis too.
5146 let d = dep_with_fonte(DepSource::Git {
5147 repo: "github:pleme-io/caixa-teia ".into(),
5148 tag: Some("v0.1.0".into()),
5149 rev: None,
5150 branch: None,
5151 });
5152 let err = d.validate().unwrap_err();
5153 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5154 panic!("expected FonteRepoShape, got other variant");
5155 };
5156 assert_eq!(nome, "caixa-teia");
5157 assert_eq!(repo, "github:pleme-io/caixa-teia ");
5158 assert!(
5159 reason.contains("whitespace"),
5160 "reason must surface the whitespace arm, got {reason:?}"
5161 );
5162 }
5163
5164 #[test]
5165 fn validate_rejects_git_fonte_with_repo_starting_with_dash() {
5166 // The canonical CLI-argument-injection footgun at the `git clone`
5167 // subprocess boundary — `:repo "-upload-pack=evil"` makes git's
5168 // argv parser read the value as a CLI flag, escaping the
5169 // subprocess argument boundary. The `--` separator workaround
5170 // does not fix the typed slot's accepted set; the gate rejects
5171 // the shape upstream at validate time so the resolver never
5172 // invokes a `git clone -…` subprocess.
5173 let d = dep_with_fonte(DepSource::Git {
5174 repo: "-upload-pack=evil".into(),
5175 tag: Some("v0.1.0".into()),
5176 rev: None,
5177 branch: None,
5178 });
5179 let err = d.validate().unwrap_err();
5180 let DepError::FonteRepoShape { repo, reason, .. } = err else {
5181 panic!("expected FonteRepoShape, got other variant");
5182 };
5183 assert_eq!(repo, "-upload-pack=evil");
5184 assert!(
5185 reason.contains("must not start with `-`"),
5186 "reason must surface the leading-`-` arm, got {reason:?}"
5187 );
5188 }
5189
5190 #[test]
5191 fn validate_rejects_git_fonte_with_repo_carrying_embedded_newline() {
5192 // The canonical paste-from-multiline-doc footgun — a `:repo`
5193 // string with an embedded `\n` silently breaks git's URL parser
5194 // and is a class of CRLF-injection at the subprocess-argument
5195 // boundary. Caught by the control-char arm (0x0A < 0x20).
5196 let d = dep_with_fonte(DepSource::Git {
5197 repo: "github:pleme-io/caixa-teia\nrm -rf /".into(),
5198 tag: Some("v0.1.0".into()),
5199 rev: None,
5200 branch: None,
5201 });
5202 let err = d.validate().unwrap_err();
5203 let DepError::FonteRepoShape { reason, .. } = err else {
5204 panic!("expected FonteRepoShape, got other variant");
5205 };
5206 assert!(
5207 reason.contains("control character"),
5208 "reason must surface the control-char arm, got {reason:?}"
5209 );
5210 }
5211
5212 #[test]
5213 fn validate_rejects_git_fonte_with_repo_carrying_tab() {
5214 // Tab is the sibling whitespace footgun (the canonical
5215 // copy-from-aligned-table paste); pinned separately from the
5216 // space arm so a future relaxation that only catches one
5217 // surfaces here.
5218 let d = dep_with_fonte(DepSource::Git {
5219 repo: "github:pleme-io/caixa-teia\t".into(),
5220 tag: Some("v0.1.0".into()),
5221 rev: None,
5222 branch: None,
5223 });
5224 let err = d.validate().unwrap_err();
5225 assert!(
5226 matches!(
5227 err,
5228 DepError::FonteRepoShape { ref reason, .. }
5229 if reason.contains("whitespace")
5230 ),
5231 "got {err:?}"
5232 );
5233 }
5234
5235 #[test]
5236 fn validate_rejects_git_fonte_with_repo_carrying_non_ascii() {
5237 // IDN hosts must be pre-encoded as Punycode (`xn--…`) — raw
5238 // non-ASCII silently breaks at git's URL parser and round-trips
5239 // inconsistently across NFC/NFD normalization on APFS /
5240 // case-folding filesystems. Same intersection-floor
5241 // [`is_git_ref_name`] enforces on the refname axes.
5242 let d = dep_with_fonte(DepSource::Git {
5243 repo: "https://github.com/pleme-io/café".into(),
5244 tag: Some("v0.1.0".into()),
5245 rev: None,
5246 branch: None,
5247 });
5248 let err = d.validate().unwrap_err();
5249 assert!(
5250 matches!(
5251 err,
5252 DepError::FonteRepoShape { ref reason, .. }
5253 if reason.contains("non-ASCII")
5254 ),
5255 "got {err:?}"
5256 );
5257 }
5258
5259 #[test]
5260 fn validate_rejects_git_fonte_with_repo_carrying_fragment_anchor() {
5261 // The fail-before-pass-after pin for the canonical paste-from-
5262 // browser-address-bar footgun on `:repo`: an author copies a
5263 // GitHub permalink to a README anchor / line-permalink and
5264 // forgets to trim the `#fragment` tail. Until this arm landed
5265 // `:repo "https://github.com/pleme-io/caixa-teia#readme"`
5266 // silently passed every prior arm (no whitespace, no control
5267 // chars, no non-ASCII, contains a `:`, doesn't start with `-`
5268 // or `:`), libcurl's URL parser stripped the `#readme` tail
5269 // before opening the HTTPS transport, and the lacre embedded
5270 // the value verbatim in its per-dep BLAKE3 closure — two
5271 // authors whose values differ only in their fragment anchor
5272 // (`#readme` vs `#L42`) resolve to the byte-identical upstream
5273 // `git clone` but lock to two distinct lacres, defeating the
5274 // THEORY.md §V.2 render-determinism contract. Same value-shape
5275 // axis-floor every peer typed surface enforces; peer `:fonte
5276 // :tag` / `:fonte :branch` already reject the byte-class through
5277 // `is_git_ref_name`'s alphabet (refs are leaf identifiers, no
5278 // URL grammar admitted) and `:entrada :paths` rejects `#` as
5279 // part of `is_gateway_api_http_path`'s RFC-3986-reserved set.
5280 let d = dep_with_fonte(DepSource::Git {
5281 repo: "https://github.com/pleme-io/caixa-teia#readme".into(),
5282 tag: Some("v0.1.0".into()),
5283 rev: None,
5284 branch: None,
5285 });
5286 let err = d.validate().unwrap_err();
5287 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5288 panic!("expected FonteRepoShape, got other variant");
5289 };
5290 assert_eq!(nome, "caixa-teia");
5291 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia#readme");
5292 assert!(
5293 reason.contains("must not contain `#`"),
5294 "reason must surface the fragment-`#` arm, got {reason:?}"
5295 );
5296 assert!(
5297 reason.contains("fragment"),
5298 "reason must name the URL fragment grammar, got {reason:?}"
5299 );
5300 }
5301
5302 #[test]
5303 fn validate_rejects_git_fonte_with_repo_carrying_flake_ref_fragment() {
5304 // The symmetric paste-from-Nix-flake-ref footgun — an author
5305 // confuses the Nix flake-reference idiom (`github:foo/
5306 // bar#packageName`, where `#packageName` selects a flake
5307 // output) with the bare git `:repo` shape. The pleme-io
5308 // substrate authors compose flakes downstream of caixa
5309 // (caixa-flake renders a flake.nix), so the cross-idiom leak
5310 // is the canonical near-miss: the author writes the
5311 // flake-ref shape into a git `:repo` slot. Pinned separately
5312 // from the HTTPS-anchor arm so a future relaxation that
5313 // narrows to one URL scheme surfaces here.
5314 let d = dep_with_fonte(DepSource::Git {
5315 repo: "github:pleme-io/caixa-teia#caixa-teia".into(),
5316 tag: Some("v0.1.0".into()),
5317 rev: None,
5318 branch: None,
5319 });
5320 let err = d.validate().unwrap_err();
5321 let DepError::FonteRepoShape { reason, .. } = err else {
5322 panic!("expected FonteRepoShape, got other variant");
5323 };
5324 assert!(
5325 reason.contains("must not contain `#`"),
5326 "reason must surface the fragment-`#` arm, got {reason:?}"
5327 );
5328 assert!(
5329 reason.contains("Nix flake"),
5330 "reason must name the Nix-flake-ref cross-idiom footgun, got {reason:?}"
5331 );
5332 }
5333
5334 #[test]
5335 fn validate_rejects_git_fonte_with_repo_carrying_query_string() {
5336 // The fail-before-pass-after pin for the canonical paste-from-
5337 // browser-address-bar footgun on `:repo` (peer with the
5338 // a68f818 fragment-`#` arm on the same axis). An author
5339 // copies a GitHub tab deep-link out of the address bar and
5340 // forgets to trim the `?tab=…` query tail. Until this arm
5341 // landed `:repo "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"`
5342 // silently passed every prior arm (no whitespace, no control
5343 // chars, no non-ASCII, no `#` fragment, contains a `:`,
5344 // doesn't start with `-` or `:`); GitHub silently ignored
5345 // the `?query` tail and served the same repo regardless;
5346 // the lacre embedded the value verbatim in its per-dep
5347 // BLAKE3 closure — two authors whose values differ only in
5348 // their query tail (`?tab=readme-ov-file` vs `?ref=main` vs
5349 // `?utm_source=twitter`) resolve to the byte-identical
5350 // upstream `git clone` but lock to two distinct lacres,
5351 // defeating the THEORY.md §V.2 render-determinism contract
5352 // on the same axis the `#` fragment arm closes. Same value-
5353 // shape axis-floor every peer typed surface enforces; peer
5354 // `:fonte :tag` / `:fonte :branch` already reject the byte-
5355 // class through `is_git_ref_name`'s alphabet (refspec glob
5356 // wildcards, caixa-core/src/render.rs:1426) and `:entrada
5357 // :paths` rejects `?` as the query separator in
5358 // `is_gateway_api_http_path` (caixa-core/src/render.rs:473).
5359 let d = dep_with_fonte(DepSource::Git {
5360 repo: "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file".into(),
5361 tag: Some("v0.1.0".into()),
5362 rev: None,
5363 branch: None,
5364 });
5365 let err = d.validate().unwrap_err();
5366 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5367 panic!("expected FonteRepoShape, got other variant");
5368 };
5369 assert_eq!(nome, "caixa-teia");
5370 assert_eq!(
5371 repo,
5372 "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"
5373 );
5374 assert!(
5375 reason.contains("must not contain `?`"),
5376 "reason must surface the query-`?` arm, got {reason:?}"
5377 );
5378 assert!(
5379 reason.contains("query"),
5380 "reason must name the URL query grammar, got {reason:?}"
5381 );
5382 }
5383
5384 #[test]
5385 fn validate_rejects_git_fonte_with_repo_carrying_utm_tracker() {
5386 // The symmetric paste-from-social-share footgun — an author
5387 // copies a repo URL out of a Slack unfurl / Twitter share /
5388 // newsletter link / Discord embed and forgets to trim the
5389 // `?utm_source=…` / `?utm_medium=…` / `?utm_campaign=…`
5390 // campaign-tracker tail. Every major social-share / unfurl /
5391 // newsletter platform appends these UTM parameters; the
5392 // canonical near-miss on the `:repo` axis. Pinned separately
5393 // from the GitHub-tab-deep-link arm so a future relaxation
5394 // that narrows to one query-parameter class surfaces here.
5395 let d = dep_with_fonte(DepSource::Git {
5396 repo: "https://github.com/pleme-io/caixa-teia?utm_source=twitter&utm_campaign=launch"
5397 .into(),
5398 tag: Some("v0.1.0".into()),
5399 rev: None,
5400 branch: None,
5401 });
5402 let err = d.validate().unwrap_err();
5403 let DepError::FonteRepoShape { reason, .. } = err else {
5404 panic!("expected FonteRepoShape, got other variant");
5405 };
5406 assert!(
5407 reason.contains("must not contain `?`"),
5408 "reason must surface the query-`?` arm, got {reason:?}"
5409 );
5410 assert!(
5411 reason.contains("campaign-tracker"),
5412 "reason must name the campaign-tracker paste footgun, got {reason:?}"
5413 );
5414 }
5415
5416 #[test]
5417 fn fonte_repo_fragment_fires_before_query_when_fragment_first() {
5418 // Cascade pin: the fragment-`#` arm and the query-`?` arm are
5419 // both per-byte arms inside the same `for &b in s.as_bytes()`
5420 // loop, so the byte that appears first in the value's byte
5421 // order wins. A `:repo "https://github.com/p/x#readme?ref=main"`
5422 // (fragment before query — unusual URL-grammar but value-
5423 // disjoint at byte level) carries both `#` and `?`; the `#`
5424 // byte appears first, so the fragment-`#` arm fires, surfacing
5425 // the more self-locating diagnostic on the byte the author
5426 // pasted earliest in the URL. Mirrors the peer cascade
5427 // discipline `fonte_repo_control_char_fires_before_fragment`
5428 // pins on the prior `:repo` byte-class arm.
5429 let d = dep_with_fonte(DepSource::Git {
5430 repo: "https://github.com/pleme-io/caixa-teia#readme?ref=main".into(),
5431 tag: Some("v0.1.0".into()),
5432 rev: None,
5433 branch: None,
5434 });
5435 let err = d.validate().unwrap_err();
5436 let DepError::FonteRepoShape { reason, .. } = err else {
5437 panic!("expected FonteRepoShape, got other variant");
5438 };
5439 assert!(
5440 reason.contains("must not contain `#`"),
5441 "reason must surface the fragment-`#` arm (fires before query-`?` when \
5442 `#` byte appears first in value), got {reason:?}"
5443 );
5444 }
5445
5446 #[test]
5447 fn fonte_repo_control_char_fires_before_fragment() {
5448 // Cascade pin: the control-char arm structurally precedes the
5449 // fragment-`#` arm. A value like `"github:p/x\n#readme"` probes
5450 // positive on both arms (contains LF and `#`), but the narrower
5451 // POSIX-syscall-rejected / CRLF-injection-class diagnostic
5452 // (`control character`) wins so the author sees the more
5453 // self-locating arm first. Mirrors the peer cascade discipline
5454 // every prior `:repo` byte-class arm establishes.
5455 let d = dep_with_fonte(DepSource::Git {
5456 repo: "github:pleme-io/caixa-teia\n#readme".into(),
5457 tag: Some("v0.1.0".into()),
5458 rev: None,
5459 branch: None,
5460 });
5461 let err = d.validate().unwrap_err();
5462 let DepError::FonteRepoShape { reason, .. } = err else {
5463 panic!("expected FonteRepoShape, got other variant");
5464 };
5465 assert!(
5466 reason.contains("control character"),
5467 "reason must surface the control-char arm, got {reason:?}"
5468 );
5469 }
5470
5471 #[test]
5472 fn validate_rejects_git_fonte_with_repo_carrying_embedded_backslash() {
5473 // The fail-before-pass-after pin for the canonical Windows-
5474 // file-path-confusion footgun on `:repo` (peer with the 3a4e1d7
5475 // backslash arm on the sibling `:caminho` path-fonte axis).
5476 // An author pastes a Windows Explorer address-bar / PowerShell
5477 // `Get-Location` output into a `file://` URL slot, producing
5478 // `file:///C:\Users\me\caixa-teia`. Until this arm landed the
5479 // value silently passed every prior arm (no whitespace, no
5480 // control chars, no non-ASCII, no `#`, no `?`, doesn't start
5481 // with `-` or `:`); libcurl's URL parser silently translates
5482 // `\` → `/` on some platforms and refuses it on others, so
5483 // the byte rides verbatim into the lacre's per-dep content-
5484 // address but is silently rewritten / rejected at the wire —
5485 // two authors whose `:repo` values differ only in backslash-
5486 // vs-forward-slash (`file:///C:\path` vs `file:///C:/path`)
5487 // resolve to the byte-identical local clone but lock to two
5488 // distinct BLAKE3 closures, defeating the THEORY.md §V.2
5489 // render-determinism contract on the same axis the `#`
5490 // fragment and `?` query arms close. Same value-shape axis-
5491 // floor every peer typed surface enforces; the `:caminho`
5492 // 3a4e1d7 arm closes the same byte on the path-fonte axis.
5493 let d = dep_with_fonte(DepSource::Git {
5494 repo: "file:///C:\\Users\\me\\caixa-teia".into(),
5495 tag: Some("v0.1.0".into()),
5496 rev: None,
5497 branch: None,
5498 });
5499 let err = d.validate().unwrap_err();
5500 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5501 panic!("expected FonteRepoShape, got other variant");
5502 };
5503 assert_eq!(nome, "caixa-teia");
5504 assert_eq!(repo, "file:///C:\\Users\\me\\caixa-teia");
5505 assert!(
5506 reason.contains("must not contain `\\`"),
5507 "reason must surface the backslash-`\\` arm, got {reason:?}"
5508 );
5509 assert!(
5510 reason.contains("Windows"),
5511 "reason must name the Windows-path-confusion footgun, got {reason:?}"
5512 );
5513 }
5514
5515 #[test]
5516 fn validate_rejects_git_fonte_with_repo_carrying_mangled_https_backslashes() {
5517 // The symmetric Win32-shell-mangled-slashes footgun — an author
5518 // copies `https://github.com/foo/bar` into a Win32 shell that
5519 // rewrites every `/` to `\` (the canonical `cmd.exe` path-
5520 // separator-coercion bug), pastes the result into a `:repo`
5521 // slot, and produces `https:\\github.com\foo\bar`. Pinned
5522 // separately from the `file://` Explorer-paste arm so a future
5523 // relaxation that narrows to one URL scheme surfaces here.
5524 let d = dep_with_fonte(DepSource::Git {
5525 repo: "https:\\\\github.com\\pleme-io\\caixa-teia".into(),
5526 tag: Some("v0.1.0".into()),
5527 rev: None,
5528 branch: None,
5529 });
5530 let err = d.validate().unwrap_err();
5531 let DepError::FonteRepoShape { reason, .. } = err else {
5532 panic!("expected FonteRepoShape, got other variant");
5533 };
5534 assert!(
5535 reason.contains("must not contain `\\`"),
5536 "reason must surface the backslash-`\\` arm, got {reason:?}"
5537 );
5538 assert!(
5539 reason.contains("path separator") || reason.contains("path-segment separator"),
5540 "reason must name the URL path-segment separator grammar, got {reason:?}"
5541 );
5542 }
5543
5544 #[test]
5545 fn fonte_repo_fragment_fires_before_backslash_when_fragment_first() {
5546 // Cascade pin: the fragment-`#` arm and the backslash-`\` arm
5547 // are both per-byte arms inside the same `for &b in s.as_bytes()`
5548 // loop, so the byte that appears first in the value's byte order
5549 // wins. A `:repo "https://github.com/p/x#readme\\foo"` carries
5550 // both `#` and `\`; the `#` byte appears first, so the fragment-
5551 // `#` arm fires, surfacing the more self-locating diagnostic on
5552 // the byte the author pasted earliest in the URL. Mirrors the
5553 // peer cascade discipline `fonte_repo_fragment_fires_before_query_when_fragment_first`
5554 // pins on the prior `:repo` byte-class arm.
5555 let d = dep_with_fonte(DepSource::Git {
5556 repo: "https://github.com/pleme-io/caixa-teia#readme\\foo".into(),
5557 tag: Some("v0.1.0".into()),
5558 rev: None,
5559 branch: None,
5560 });
5561 let err = d.validate().unwrap_err();
5562 let DepError::FonteRepoShape { reason, .. } = err else {
5563 panic!("expected FonteRepoShape, got other variant");
5564 };
5565 assert!(
5566 reason.contains("must not contain `#`"),
5567 "reason must surface the fragment-`#` arm (fires before backslash-`\\` when \
5568 `#` byte appears first in value), got {reason:?}"
5569 );
5570 }
5571
5572 #[test]
5573 fn validate_rejects_git_fonte_with_repo_carrying_uri_template_placeholder() {
5574 // The fail-before-pass-after pin for the canonical URI Template
5575 // (RFC 6570) placeholder footgun on `:repo`. An author copies a
5576 // README quick-start snippet / OpenAPI `servers:` URL / Helm
5577 // chart `home:` template that carries unresolved
5578 // `{org}` / `{repo}` placeholders and pastes the raw template
5579 // into the `:repo` slot, expecting the substrate to resolve the
5580 // placeholder downstream. Until this arm landed the value
5581 // silently passed every prior arm (no whitespace, no control
5582 // chars, no non-ASCII, no `#`, no `?`, no `\`, doesn't start
5583 // with `-` or `:`); libcurl percent-encodes `{` / `}` to `%7B`
5584 // / `%7D` on the wire, so the byte rides verbatim into the
5585 // lacre's per-dep content-address but round-trips inconsistently
5586 // between the lacre's per-dep content-address and the
5587 // resolver's `git clone <repo>` invocation, defeating the
5588 // THEORY.md §V.2 render-determinism contract on the same axis
5589 // the `#` fragment, `?` query, and `\` backslash arms close;
5590 // every git porcelain entry-point additionally fetches a
5591 // nonexistent literal-`{placeholder}`-named path far from the
5592 // source caixa.lisp.
5593 let d = dep_with_fonte(DepSource::Git {
5594 repo: "https://github.com/{org}/caixa-teia".into(),
5595 tag: Some("v0.1.0".into()),
5596 rev: None,
5597 branch: None,
5598 });
5599 let err = d.validate().unwrap_err();
5600 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5601 panic!("expected FonteRepoShape, got other variant");
5602 };
5603 assert_eq!(nome, "caixa-teia");
5604 assert_eq!(repo, "https://github.com/{org}/caixa-teia");
5605 assert!(
5606 reason.contains("must not contain `{`"),
5607 "reason must surface the open-brace `{{` arm, got {reason:?}"
5608 );
5609 assert!(
5610 reason.contains("URI Template") || reason.contains("RFC 6570"),
5611 "reason must name the RFC 6570 URI Template grammar, got {reason:?}"
5612 );
5613 }
5614
5615 #[test]
5616 fn validate_rejects_git_fonte_with_repo_carrying_handlebars_doubled_brace() {
5617 // The symmetric Mustache / Handlebars doubled-brace
5618 // substitution-form footgun every CI / IaC templating engine
5619 // (Argo Workflows, Jinja2, Liquid, Vue / Angular interpolation,
5620 // GitHub Actions `${{ … }}` even though Actions uses `${{`) /
5621 // chart README quick-start snippet emits. Pinned separately
5622 // from the single-`{` `{org}` arm so a future relaxation that
5623 // narrows to one substitution-form surfaces here.
5624 let d = dep_with_fonte(DepSource::Git {
5625 repo: "https://github.com/{{org}}/caixa-teia".into(),
5626 tag: Some("v0.1.0".into()),
5627 rev: None,
5628 branch: None,
5629 });
5630 let err = d.validate().unwrap_err();
5631 let DepError::FonteRepoShape { reason, .. } = err else {
5632 panic!("expected FonteRepoShape, got other variant");
5633 };
5634 assert!(
5635 reason.contains("must not contain `{`"),
5636 "reason must surface the open-brace `{{` arm, got {reason:?}"
5637 );
5638 }
5639
5640 #[test]
5641 fn validate_rejects_git_fonte_with_repo_carrying_closing_brace_only() {
5642 // Asymmetric `}`-only shape — covers the closing-brace-by-
5643 // itself footgun (an author truncated `{org}/{repo}` mid-edit
5644 // and left a trailing `}` from the prior template fragment,
5645 // or pasted a value that included a closing brace from a
5646 // surrounding shell context). Pinned to ensure the predicate
5647 // refuses each brace independently rather than only when both
5648 // appear — a future regression that ANDs the two byte tests
5649 // surfaces here.
5650 let d = dep_with_fonte(DepSource::Git {
5651 repo: "https://github.com/pleme-io/caixa-teia}".into(),
5652 tag: Some("v0.1.0".into()),
5653 rev: None,
5654 branch: None,
5655 });
5656 let err = d.validate().unwrap_err();
5657 let DepError::FonteRepoShape { reason, .. } = err else {
5658 panic!("expected FonteRepoShape, got other variant");
5659 };
5660 assert!(
5661 reason.contains("must not contain `}`"),
5662 "reason must surface the close-brace `}}` arm, got {reason:?}"
5663 );
5664 }
5665
5666 #[test]
5667 fn fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first() {
5668 // Cascade pin: the fragment-`#` arm and the template-`{` /
5669 // `}` arm are both per-byte arms inside the same
5670 // `for &b in s.as_bytes()` loop, so the byte that appears
5671 // first in the value's byte order wins. A `:repo
5672 // "https://github.com/p/x#readme{org}"` carries both `#` and
5673 // `{`; the `#` byte appears first, so the fragment-`#` arm
5674 // fires, surfacing the more self-locating diagnostic on the
5675 // byte the author pasted earliest in the URL. Mirrors the
5676 // peer cascade discipline `fonte_repo_fragment_fires_before_backslash_when_fragment_first`
5677 // pins on the prior `:repo` byte-class arm.
5678 let d = dep_with_fonte(DepSource::Git {
5679 repo: "https://github.com/pleme-io/caixa-teia#readme{org}".into(),
5680 tag: Some("v0.1.0".into()),
5681 rev: None,
5682 branch: None,
5683 });
5684 let err = d.validate().unwrap_err();
5685 let DepError::FonteRepoShape { reason, .. } = err else {
5686 panic!("expected FonteRepoShape, got other variant");
5687 };
5688 assert!(
5689 reason.contains("must not contain `#`"),
5690 "reason must surface the fragment-`#` arm (fires before template-`{{` when \
5691 `#` byte appears first in value), got {reason:?}"
5692 );
5693 }
5694
5695 #[test]
5696 fn validate_rejects_git_fonte_with_repo_carrying_output_redirection() {
5697 // The fail-before-pass-after pin for the canonical
5698 // shell-output-redirection footgun on `:repo`: an author
5699 // pastes a shell-pipeline tail (`git clone <repo> > build.log`
5700 // / `… >output.txt`) into the `:repo` slot without trimming
5701 // the redirect. Until this arm landed the value silently
5702 // passed every prior arm (no whitespace, no control chars,
5703 // no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, doesn't
5704 // start with `-` or `:`); RFC 3986 §2 lists `<` / `>` in the
5705 // 'delims' / 'unwise' set and the WHATWG URL spec's fragment
5706 // percent-encode set maps `>` → `%3E` on the wire, so the
5707 // byte rides verbatim into the lacre's per-dep BLAKE3 closure
5708 // but is silently rewritten or rejected at libcurl's URL-
5709 // parser layer — two authors whose values differ only in
5710 // their redirect tail (`>build.log` vs nothing) resolve to
5711 // the byte-identical upstream `git clone` but lock to two
5712 // distinct lacres, defeating the THEORY.md §V.2 render-
5713 // determinism contract. Peer with the `:caminho` axis's
5714 // `FonteCaminhoShellRedirection` arm (e457141) on the sibling
5715 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5716 // byte RFC-3986-reserved set on `:entrada :paths`.
5717 let d = dep_with_fonte(DepSource::Git {
5718 repo: "https://github.com/pleme-io/caixa-teia>build.log".into(),
5719 tag: Some("v0.1.0".into()),
5720 rev: None,
5721 branch: None,
5722 });
5723 let err = d.validate().unwrap_err();
5724 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5725 panic!("expected FonteRepoShape, got other variant");
5726 };
5727 assert_eq!(nome, "caixa-teia");
5728 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia>build.log");
5729 assert!(
5730 reason.contains("must not contain `>`"),
5731 "reason must surface the output-redirection `>` arm, got {reason:?}"
5732 );
5733 assert!(
5734 reason.contains("redirection") || reason.contains("'delims'"),
5735 "reason must name the shell-redirection / RFC-3986-unwise rationale, got {reason:?}"
5736 );
5737 }
5738
5739 #[test]
5740 fn validate_rejects_git_fonte_with_repo_carrying_input_redirection() {
5741 // The symmetric shell-input-redirection footgun — an author
5742 // pastes a shell-pipeline head (`git clone <input.url` /
5743 // `cat <README.md`) into the `:repo` slot. Pinned separately
5744 // from the `>`-output arm so a future relaxation that only
5745 // catches one of the two redirect bytes surfaces here. Peer
5746 // with the `:caminho` axis's `FonteCaminhoShellRedirection`
5747 // arm which closes both `<` and `>` under the same banner.
5748 let d = dep_with_fonte(DepSource::Git {
5749 repo: "https://github.com/pleme-io/caixa-teia<input.url".into(),
5750 tag: Some("v0.1.0".into()),
5751 rev: None,
5752 branch: None,
5753 });
5754 let err = d.validate().unwrap_err();
5755 let DepError::FonteRepoShape { reason, .. } = err else {
5756 panic!("expected FonteRepoShape, got other variant");
5757 };
5758 assert!(
5759 reason.contains("must not contain `<`"),
5760 "reason must surface the input-redirection `<` arm, got {reason:?}"
5761 );
5762 assert!(
5763 reason.contains("RFC 3986") || reason.contains("'unwise'"),
5764 "reason must name the RFC 3986 'unwise' grammar, got {reason:?}"
5765 );
5766 }
5767
5768 #[test]
5769 fn validate_rejects_git_fonte_with_repo_carrying_backtick_command_substitution() {
5770 // The fail-before-pass-after pin for the canonical
5771 // paste-from-shell-prompt-with-backticked-substitution footgun
5772 // on `:repo` (peer with the c4d62b3 backtick arm on the sibling
5773 // `:caminho` path-fonte axis). An author pastes a URL whose
5774 // segment carries a backticked command-substitution wrapper
5775 // (`` `whoami` ``, `` `git config user.name` ``, `` `pwd` ``)
5776 // from a doc / README quick-start snippet that expected the
5777 // substrate to substitute the value downstream. Until this arm
5778 // landed the value silently passed every prior arm (no
5779 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5780 // no `\`, no `{`/`}`, no `<`/`>`, doesn't start with `-` or
5781 // `:`); RFC 3986 §2 lists the backtick byte in the 'delims' /
5782 // 'unwise' set and the WHATWG URL spec's fragment percent-
5783 // encode set maps `` ` `` → `%60` on the wire, so the byte
5784 // rides verbatim into the lacre's per-dep BLAKE3 closure but
5785 // is silently rewritten or rejected at libcurl's URL-parser
5786 // layer — two authors whose values differ only in their
5787 // backtick wrapper (`` `whoami` `` vs nothing) resolve to the
5788 // byte-identical upstream `git clone` but lock to two distinct
5789 // lacres, defeating the THEORY.md §V.2 render-determinism
5790 // contract. Peer with the `:caminho` axis's
5791 // `FonteCaminhoShellCommandSubstitution` arm (c4d62b3) on the
5792 // sibling path-fonte axis, and `is_gateway_api_http_path`'s
5793 // eleven-byte RFC-3986-reserved set on `:entrada :paths`.
5794 let d = dep_with_fonte(DepSource::Git {
5795 repo: "https://github.com/pleme-io/`whoami`/caixa-teia".into(),
5796 tag: Some("v0.1.0".into()),
5797 rev: None,
5798 branch: None,
5799 });
5800 let err = d.validate().unwrap_err();
5801 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5802 panic!("expected FonteRepoShape, got other variant");
5803 };
5804 assert_eq!(nome, "caixa-teia");
5805 assert_eq!(repo, "https://github.com/pleme-io/`whoami`/caixa-teia");
5806 assert!(
5807 reason.contains("must not contain `` ` ``"),
5808 "reason must surface the backtick command-substitution arm, got {reason:?}"
5809 );
5810 assert!(
5811 reason.contains("command-substitution") || reason.contains("'unwise'"),
5812 "reason must name the shell-command-substitution / RFC-3986-unwise rationale, \
5813 got {reason:?}"
5814 );
5815 }
5816
5817 #[test]
5818 fn fonte_repo_fragment_fires_before_backtick_when_fragment_first() {
5819 // Cascade pin: the fragment-`#` arm and the backtick command-
5820 // substitution arm are both per-byte arms inside the same
5821 // `for &b in s.as_bytes()` loop, so the byte that appears first
5822 // in the value's byte order wins. A `:repo
5823 // "https://github.com/p/x#readme/`whoami`"` carries both `#`
5824 // and backtick; the `#` byte appears first, so the fragment-
5825 // `#` arm fires, surfacing the more self-locating diagnostic
5826 // on the byte the author pasted earliest in the URL. Mirrors
5827 // the peer cascade discipline
5828 // `fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first`
5829 // pins on the prior `:repo` byte-class arm.
5830 let d = dep_with_fonte(DepSource::Git {
5831 repo: "https://github.com/pleme-io/caixa-teia#readme/`whoami`".into(),
5832 tag: Some("v0.1.0".into()),
5833 rev: None,
5834 branch: None,
5835 });
5836 let err = d.validate().unwrap_err();
5837 let DepError::FonteRepoShape { reason, .. } = err else {
5838 panic!("expected FonteRepoShape, got other variant");
5839 };
5840 assert!(
5841 reason.contains("must not contain `#`"),
5842 "reason must surface the fragment-`#` arm (fires before backtick when `#` byte \
5843 appears first in value), got {reason:?}"
5844 );
5845 }
5846
5847 #[test]
5848 fn fonte_repo_shell_redirection_fires_before_backtick_when_redirection_first() {
5849 // Cascade pin: the shell-redirection `<` / `>` arm and the
5850 // backtick command-substitution arm are both per-byte arms
5851 // inside the same `for &b in s.as_bytes()` loop, so the byte
5852 // that appears first in the value's byte order wins. A `:repo
5853 // "https://github.com/p/x>build.log/`whoami`"` carries both
5854 // `>` and backtick; the `>` byte appears first, so the
5855 // shell-redirection arm fires, surfacing the more self-
5856 // locating diagnostic on the byte the author pasted earliest
5857 // in the URL. Pins the natural-order cascade so a future
5858 // reorder of the per-byte arms surfaces here.
5859 let d = dep_with_fonte(DepSource::Git {
5860 repo: "https://github.com/pleme-io/caixa-teia>build.log/`whoami`".into(),
5861 tag: Some("v0.1.0".into()),
5862 rev: None,
5863 branch: None,
5864 });
5865 let err = d.validate().unwrap_err();
5866 let DepError::FonteRepoShape { reason, .. } = err else {
5867 panic!("expected FonteRepoShape, got other variant");
5868 };
5869 assert!(
5870 reason.contains("must not contain `>`"),
5871 "reason must surface the shell-redirection `>` arm (fires before backtick when \
5872 `>` byte appears first in value), got {reason:?}"
5873 );
5874 }
5875
5876 #[test]
5877 fn fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first() {
5878 // Cascade pin: the fragment-`#` arm and the shell-redirection
5879 // `<` / `>` arm are both per-byte arms inside the same
5880 // `for &b in s.as_bytes()` loop, so the byte that appears
5881 // first in the value's byte order wins. A `:repo
5882 // "https://github.com/p/x#readme>build.log"` carries both
5883 // `#` and `>`; the `#` byte appears first, so the fragment-
5884 // `#` arm fires, surfacing the more self-locating diagnostic
5885 // on the byte the author pasted earliest in the URL. Mirrors
5886 // the peer cascade discipline
5887 // `fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first`
5888 // pins on the prior `:repo` byte-class arm.
5889 let d = dep_with_fonte(DepSource::Git {
5890 repo: "https://github.com/pleme-io/caixa-teia#readme>build.log".into(),
5891 tag: Some("v0.1.0".into()),
5892 rev: None,
5893 branch: None,
5894 });
5895 let err = d.validate().unwrap_err();
5896 let DepError::FonteRepoShape { reason, .. } = err else {
5897 panic!("expected FonteRepoShape, got other variant");
5898 };
5899 assert!(
5900 reason.contains("must not contain `#`"),
5901 "reason must surface the fragment-`#` arm (fires before shell-redirection `>` when \
5902 `#` byte appears first in value), got {reason:?}"
5903 );
5904 }
5905
5906 #[test]
5907 fn validate_rejects_git_fonte_with_repo_carrying_shell_pipe() {
5908 // The fail-before-pass-after pin for the canonical
5909 // paste-from-shell-prompt-with-piped-pipeline footgun on
5910 // `:repo` (peer with the 124106f pipe arm on the sibling
5911 // `:caminho` path-fonte axis). An author pastes a shell
5912 // pipeline (`git clone <url> | tee build.log`,
5913 // `git ls-remote <url> | head`) into the `:repo` slot,
5914 // forgetting to trim the `| <consumer>` tail. Until this arm
5915 // landed the value silently passed every prior arm (no
5916 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5917 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, doesn't start
5918 // with `-` or `:`); RFC 3986 §2 lists the pipe byte in the
5919 // 'unwise' set and the WHATWG URL spec's fragment percent-
5920 // encode set maps `|` → `%7C` on the wire, so the byte rides
5921 // verbatim into the lacre's per-dep BLAKE3 closure but is
5922 // silently rewritten or rejected at libcurl's URL-parser
5923 // layer — two authors whose values differ only in their pipe
5924 // tail (`|tee build.log` vs nothing) resolve to the byte-
5925 // identical upstream `git clone` but lock to two distinct
5926 // lacres, defeating the THEORY.md §V.2 render-determinism
5927 // contract. Peer with the `:caminho` axis's
5928 // `FonteCaminhoShellPipe` arm (124106f) on the sibling path-
5929 // fonte axis, and `is_gateway_api_http_path`'s eleven-byte
5930 // RFC-3986-reserved set on `:entrada :paths`.
5931 let d = dep_with_fonte(DepSource::Git {
5932 repo: "https://github.com/pleme-io/caixa-teia|tee build.log".into(),
5933 tag: Some("v0.1.0".into()),
5934 rev: None,
5935 branch: None,
5936 });
5937 let err = d.validate().unwrap_err();
5938 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5939 panic!("expected FonteRepoShape, got other variant");
5940 };
5941 assert_eq!(nome, "caixa-teia");
5942 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia|tee build.log");
5943 assert!(
5944 reason.contains("must not contain `|`"),
5945 "reason must surface the shell-pipe arm, got {reason:?}"
5946 );
5947 assert!(
5948 reason.contains("pipe") || reason.contains("'unwise'"),
5949 "reason must name the shell-pipe / RFC-3986-unwise rationale, got {reason:?}"
5950 );
5951 }
5952
5953 #[test]
5954 fn fonte_repo_fragment_fires_before_pipe_when_fragment_first() {
5955 // Cascade pin: the fragment-`#` arm and the pipe arm are both
5956 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5957 // so the byte that appears first in the value's byte order
5958 // wins. A `:repo "https://github.com/p/x#readme|tee"` carries
5959 // both `#` and `|`; the `#` byte appears first, so the
5960 // fragment-`#` arm fires, surfacing the more self-locating
5961 // diagnostic on the byte the author pasted earliest in the
5962 // URL. Mirrors the peer cascade discipline
5963 // `fonte_repo_fragment_fires_before_backtick_when_fragment_first`
5964 // pins on the prior `:repo` byte-class arm.
5965 let d = dep_with_fonte(DepSource::Git {
5966 repo: "https://github.com/pleme-io/caixa-teia#readme|tee".into(),
5967 tag: Some("v0.1.0".into()),
5968 rev: None,
5969 branch: None,
5970 });
5971 let err = d.validate().unwrap_err();
5972 let DepError::FonteRepoShape { reason, .. } = err else {
5973 panic!("expected FonteRepoShape, got other variant");
5974 };
5975 assert!(
5976 reason.contains("must not contain `#`"),
5977 "reason must surface the fragment-`#` arm (fires before pipe when `#` byte \
5978 appears first in value), got {reason:?}"
5979 );
5980 }
5981
5982 #[test]
5983 fn fonte_repo_backtick_fires_before_pipe_when_backtick_first() {
5984 // Cascade pin: the backtick arm and the pipe arm are both per-
5985 // byte arms inside the same `for &b in s.as_bytes()` loop, so
5986 // the byte that appears first in the value's byte order wins.
5987 // A `:repo "https://github.com/p/x/`whoami`|tee"` carries both
5988 // `` ` `` and `|`; the backtick byte appears first, so the
5989 // backtick arm fires, surfacing the more self-locating
5990 // diagnostic on the byte the author pasted earliest in the
5991 // URL. Pins the natural-order cascade so a future reorder of
5992 // the per-byte arms surfaces here.
5993 let d = dep_with_fonte(DepSource::Git {
5994 repo: "https://github.com/pleme-io/caixa-teia/`whoami`|tee".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 { reason, .. } = err else {
6001 panic!("expected FonteRepoShape, got other variant");
6002 };
6003 assert!(
6004 reason.contains("must not contain `` ` ``"),
6005 "reason must surface the backtick arm (fires before pipe when `` ` `` byte \
6006 appears first in value), got {reason:?}"
6007 );
6008 }
6009
6010 #[test]
6011 fn validate_rejects_git_fonte_with_repo_carrying_shell_command_separator() {
6012 // The fail-before-pass-after pin for the canonical
6013 // paste-from-shell-prompt-with-sequential-command-tail footgun
6014 // on `:repo` (peer with the 05c358e `;` arm on the sibling
6015 // `:caminho` path-fonte axis). An author pastes a shell
6016 // one-liner that chained a cleanup tail after the URL
6017 // (`git clone <url>; rm -rf build`, `git ls-remote <url>;
6018 // echo done`) into the `:repo` slot, forgetting to trim the
6019 // `; <cmd>` tail. Until this arm landed the value silently
6020 // passed every prior `is_git_repo_url` arm (no whitespace, no
6021 // control chars, no non-ASCII, no `#`, no `?`, no `\`, no
6022 // `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, doesn't start with
6023 // `-` or `:`); RFC 3986 §2 lists `;` in the 'sub-delims' /
6024 // reserved set and the WHATWG URL spec's fragment percent-
6025 // encode set maps `;` → `%3B` on the wire, so the byte rides
6026 // verbatim into the lacre's per-dep BLAKE3 closure but is
6027 // silently rewritten at libcurl's URL-parser layer — two
6028 // authors whose values differ only in their sequential-command
6029 // tail (`; rm -rf build` vs nothing) resolve to the byte-
6030 // identical upstream `git clone` but lock to two distinct
6031 // lacres, defeating the THEORY.md §V.2 render-determinism
6032 // contract. Peer with the `:caminho` axis's
6033 // `FonteCaminhoShellSemicolon` arm (05c358e) on the sibling
6034 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
6035 // byte RFC-3986-reserved set on `:entrada :paths`.
6036 let d = dep_with_fonte(DepSource::Git {
6037 repo: "https://github.com/pleme-io/caixa-teia; rm -rf build".into(),
6038 tag: Some("v0.1.0".into()),
6039 rev: None,
6040 branch: None,
6041 });
6042 let err = d.validate().unwrap_err();
6043 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6044 panic!("expected FonteRepoShape, got other variant");
6045 };
6046 assert_eq!(nome, "caixa-teia");
6047 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia; rm -rf build");
6048 assert!(
6049 reason.contains("must not contain `;`"),
6050 "reason must surface the shell-command-separator arm, got {reason:?}"
6051 );
6052 assert!(
6053 reason.contains("sequential-command") || reason.contains("'sub-delims'"),
6054 "reason must name the shell-command-separator / RFC-3986-sub-delims \
6055 rationale, got {reason:?}"
6056 );
6057 }
6058
6059 #[test]
6060 fn fonte_repo_fragment_fires_before_semicolon_when_fragment_first() {
6061 // Cascade pin: the fragment-`#` arm and the semicolon arm are
6062 // both per-byte arms inside the same `for &b in s.as_bytes()`
6063 // loop, so the byte that appears first in the value's byte
6064 // order wins. A `:repo "https://github.com/p/x#readme; rm"`
6065 // carries both `#` and `;`; the `#` byte appears first, so the
6066 // fragment-`#` arm fires, surfacing the more self-locating
6067 // diagnostic on the byte the author pasted earliest in the URL.
6068 // Mirrors the peer cascade discipline
6069 // `fonte_repo_fragment_fires_before_pipe_when_fragment_first`
6070 // pins on the prior `:repo` byte-class arm.
6071 let d = dep_with_fonte(DepSource::Git {
6072 repo: "https://github.com/pleme-io/caixa-teia#readme; rm".into(),
6073 tag: Some("v0.1.0".into()),
6074 rev: None,
6075 branch: None,
6076 });
6077 let err = d.validate().unwrap_err();
6078 let DepError::FonteRepoShape { reason, .. } = err else {
6079 panic!("expected FonteRepoShape, got other variant");
6080 };
6081 assert!(
6082 reason.contains("must not contain `#`"),
6083 "reason must surface the fragment-`#` arm (fires before semicolon when `#` \
6084 byte appears first in value), got {reason:?}"
6085 );
6086 }
6087
6088 #[test]
6089 fn fonte_repo_pipe_fires_before_semicolon_when_pipe_first() {
6090 // Cascade pin: the pipe arm and the semicolon arm are both
6091 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6092 // so the byte that appears first in the value's byte order
6093 // wins. A `:repo "https://github.com/p/x|tee; rm"` carries
6094 // both `|` and `;`; the `|` byte appears first, so the
6095 // pipe arm fires, surfacing the more self-locating diagnostic
6096 // on the byte the author pasted earliest in the URL. Pins the
6097 // natural-order cascade so a future reorder of the per-byte
6098 // arms surfaces here.
6099 let d = dep_with_fonte(DepSource::Git {
6100 repo: "https://github.com/pleme-io/caixa-teia|tee; rm".into(),
6101 tag: Some("v0.1.0".into()),
6102 rev: None,
6103 branch: None,
6104 });
6105 let err = d.validate().unwrap_err();
6106 let DepError::FonteRepoShape { reason, .. } = err else {
6107 panic!("expected FonteRepoShape, got other variant");
6108 };
6109 assert!(
6110 reason.contains("must not contain `|`"),
6111 "reason must surface the pipe arm (fires before semicolon when `|` byte \
6112 appears first in value), got {reason:?}"
6113 );
6114 }
6115
6116 #[test]
6117 fn validate_rejects_git_fonte_with_repo_carrying_shell_background() {
6118 // The fail-before-pass-after pin for the canonical
6119 // paste-from-shell-prompt-with-background-launch-tail footgun
6120 // on `:repo` (peer with the e12e4f3 `&` arm on the sibling
6121 // `:caminho` path-fonte axis). An author pastes a shell one-
6122 // liner that detached the clone into the background
6123 // (`git clone <url> & sleep 1`, `git clone <url> && cd …`)
6124 // into the `:repo` slot, forgetting to trim the `& <cmd>` /
6125 // `&& <cmd>` tail. Until this arm landed the value silently
6126 // passed every prior `is_git_repo_url` arm (no whitespace,
6127 // no control chars, no non-ASCII, no `#`, no `?`, no `\`,
6128 // no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6129 // doesn't start with `-` or `:`); RFC 3986 §2 lists `&` in
6130 // the 'sub-delims' / reserved set and the WHATWG URL spec's
6131 // fragment percent-encode set maps `&` → `%26` on the wire,
6132 // so the byte rides verbatim into the lacre's per-dep
6133 // BLAKE3 closure but is silently rewritten at libcurl's
6134 // URL-parser layer — two authors whose values differ only
6135 // in their background-launch tail (`& sleep 1` vs nothing)
6136 // resolve to the byte-identical upstream `git clone` but
6137 // lock to two distinct lacres, defeating the THEORY.md
6138 // §V.2 render-determinism contract. Peer with the
6139 // `:caminho` axis's `FonteCaminhoShellBackground` arm
6140 // (e12e4f3) on the sibling path-fonte axis, and
6141 // `is_gateway_api_http_path`'s eleven-byte RFC-3986-
6142 // reserved set on `:entrada :paths`.
6143 let d = dep_with_fonte(DepSource::Git {
6144 repo: "https://github.com/pleme-io/caixa-teia&sleep".into(),
6145 tag: Some("v0.1.0".into()),
6146 rev: None,
6147 branch: None,
6148 });
6149 let err = d.validate().unwrap_err();
6150 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6151 panic!("expected FonteRepoShape, got other variant");
6152 };
6153 assert_eq!(nome, "caixa-teia");
6154 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia&sleep");
6155 assert!(
6156 reason.contains("must not contain `&`"),
6157 "reason must surface the shell-background / logical-AND arm, got {reason:?}"
6158 );
6159 assert!(
6160 reason.contains("background-task") || reason.contains("'sub-delims'"),
6161 "reason must name the shell-background / RFC-3986-sub-delims rationale, \
6162 got {reason:?}"
6163 );
6164 }
6165
6166 #[test]
6167 fn validate_rejects_git_fonte_with_repo_carrying_logical_and() {
6168 // The fail-before-pass-after pin for the symmetric `&&`
6169 // logical-AND build-chain paste footgun: an author pastes
6170 // a `git clone <url> && cd <repo>` build-chain one-liner
6171 // and forgets to trim the `&& <cmd>` tail. The `&&` shape
6172 // is the same `&` byte twice in a row; the per-byte arm
6173 // fires on the first `&` it sees. Pinned separately from
6174 // the single-`&` background-launch shape so a future
6175 // diagnostic-surface change that special-cased the
6176 // doubled-byte form surfaces here.
6177 let d = dep_with_fonte(DepSource::Git {
6178 repo: "github:pleme-io/caixa-teia&&echo".into(),
6179 tag: Some("v0.1.0".into()),
6180 rev: None,
6181 branch: None,
6182 });
6183 let err = d.validate().unwrap_err();
6184 let DepError::FonteRepoShape { reason, .. } = err else {
6185 panic!("expected FonteRepoShape, got other variant");
6186 };
6187 assert!(
6188 reason.contains("must not contain `&`"),
6189 "reason must surface the shell-background / logical-AND arm on the doubled-`&&` \
6190 shape too, got {reason:?}"
6191 );
6192 }
6193
6194 #[test]
6195 fn fonte_repo_fragment_fires_before_background_when_fragment_first() {
6196 // Cascade pin: the fragment-`#` arm and the background-`&`
6197 // arm are both per-byte arms inside the same `for &b in
6198 // s.as_bytes()` loop, so the byte that appears first in the
6199 // value's byte order wins. A `:repo
6200 // "https://github.com/p/x#readme & sleep"` carries both `#`
6201 // and `&`; the `#` byte appears first, so the fragment-`#`
6202 // arm fires, surfacing the more self-locating diagnostic on
6203 // the byte the author pasted earliest in the URL. Mirrors
6204 // the peer cascade discipline
6205 // `fonte_repo_fragment_fires_before_semicolon_when_fragment_first`
6206 // on the prior `:repo` byte-class arm.
6207 let d = dep_with_fonte(DepSource::Git {
6208 repo: "https://github.com/pleme-io/caixa-teia#readme&sleep".into(),
6209 tag: Some("v0.1.0".into()),
6210 rev: None,
6211 branch: None,
6212 });
6213 let err = d.validate().unwrap_err();
6214 let DepError::FonteRepoShape { reason, .. } = err else {
6215 panic!("expected FonteRepoShape, got other variant");
6216 };
6217 assert!(
6218 reason.contains("must not contain `#`"),
6219 "reason must surface the fragment-`#` arm (fires before background-`&` when `#` \
6220 byte appears first in value), got {reason:?}"
6221 );
6222 }
6223
6224 #[test]
6225 fn fonte_repo_semicolon_fires_before_background_when_semicolon_first() {
6226 // Cascade pin: the semicolon arm and the background-`&` arm
6227 // are both per-byte arms inside the same `for &b in
6228 // s.as_bytes()` loop, so the byte that appears first in the
6229 // value's byte order wins. A `:repo
6230 // "https://github.com/p/x; rm & sleep"` carries both `;` and
6231 // `&`; the `;` byte appears first, so the semicolon arm
6232 // fires, surfacing the more self-locating diagnostic on the
6233 // byte the author pasted earliest in the URL. Pins the
6234 // natural-order cascade so a future reorder of the per-byte
6235 // arms surfaces here.
6236 let d = dep_with_fonte(DepSource::Git {
6237 repo: "https://github.com/pleme-io/caixa-teia;rm&sleep".into(),
6238 tag: Some("v0.1.0".into()),
6239 rev: None,
6240 branch: None,
6241 });
6242 let err = d.validate().unwrap_err();
6243 let DepError::FonteRepoShape { reason, .. } = err else {
6244 panic!("expected FonteRepoShape, got other variant");
6245 };
6246 assert!(
6247 reason.contains("must not contain `;`"),
6248 "reason must surface the semicolon arm (fires before background-`&` when `;` \
6249 byte appears first in value), got {reason:?}"
6250 );
6251 }
6252
6253 #[test]
6254 fn validate_rejects_git_fonte_with_repo_carrying_shell_variable_expansion() {
6255 // The fail-before-pass-after pin for the canonical
6256 // paste-from-shell-prompt-with-unsubstituted-variable footgun
6257 // on `:repo` (peer with the f4efe9c `$` arm on the sibling
6258 // `:caminho` path-fonte axis). An author pastes a shell one-
6259 // liner that referenced an environment variable
6260 // (`git clone https://github.com/$ORG/x`, `git clone
6261 // github:$USER/repo`) into the `:repo` slot, forgetting to
6262 // substitute the literal value at author time. Until this arm
6263 // landed the value silently passed every prior
6264 // `is_git_repo_url` arm (no whitespace, no control chars, no
6265 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6266 // no `` ` ``, no `|`, no `;`, no `&`, doesn't start with `-`
6267 // or `:`); RFC 3986 §2 lists `$` in the 'sub-delims' /
6268 // reserved set and the WHATWG URL spec's fragment percent-
6269 // encode set maps `$` → `%24` on the wire, so the byte rides
6270 // verbatim into the lacre's per-dep BLAKE3 closure but is
6271 // silently rewritten at libcurl's URL-parser layer — two
6272 // authors whose values differ only in their `$VAR` /
6273 // `${VAR}` / `$(cmd)` expansion tail resolve to the byte-
6274 // identical upstream `git clone` but lock to two distinct
6275 // lacres, defeating the THEORY.md §V.2 render-determinism
6276 // contract. Beyond determinism, the value is a structural
6277 // host-layout leak: two authors with the same `:repo` slot
6278 // but different `$ORG` / `$HOME` / `$WORKSPACE` resolve
6279 // different upstreams. Peer with the `:caminho` axis's
6280 // `FonteCaminhoVarExpansion` arm (f4efe9c) on the sibling
6281 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
6282 // byte RFC-3986-reserved set on `:entrada :paths`.
6283 let d = dep_with_fonte(DepSource::Git {
6284 repo: "https://github.com/$ORG/caixa-teia".into(),
6285 tag: Some("v0.1.0".into()),
6286 rev: None,
6287 branch: None,
6288 });
6289 let err = d.validate().unwrap_err();
6290 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6291 panic!("expected FonteRepoShape, got other variant");
6292 };
6293 assert_eq!(nome, "caixa-teia");
6294 assert_eq!(repo, "https://github.com/$ORG/caixa-teia");
6295 assert!(
6296 reason.contains("must not contain `$`"),
6297 "reason must surface the shell-variable-expansion arm, got {reason:?}"
6298 );
6299 assert!(
6300 reason.contains("variable-expansion") || reason.contains("'sub-delims'"),
6301 "reason must name the shell-variable-expansion / RFC-3986-sub-delims \
6302 rationale, got {reason:?}"
6303 );
6304 }
6305
6306 #[test]
6307 fn validate_rejects_git_fonte_with_repo_carrying_braced_variable_expansion() {
6308 // The fail-before-pass-after pin for the symmetric POSIX-
6309 // shell braced `${VAR}` expansion paste footgun: an author
6310 // pastes a CI-manifest line `git clone
6311 // https://github.com/${WORKSPACE}/x` (the canonical GitHub
6312 // Actions / GitLab CI / Drone shape) and forgets to
6313 // substitute the literal value. The `${...}` shape is the
6314 // same `$` byte at the leading position of the expansion;
6315 // the per-byte arm fires on the `$`. Pinned separately from
6316 // the bare-`$VAR` shape so a future diagnostic-surface
6317 // change that special-cased the braced form surfaces here.
6318 let d = dep_with_fonte(DepSource::Git {
6319 repo: "https://github.com/${WORKSPACE}/caixa-teia".into(),
6320 tag: Some("v0.1.0".into()),
6321 rev: None,
6322 branch: None,
6323 });
6324 let err = d.validate().unwrap_err();
6325 let DepError::FonteRepoShape { reason, .. } = err else {
6326 panic!("expected FonteRepoShape, got other variant");
6327 };
6328 assert!(
6329 reason.contains("must not contain `$`"),
6330 "reason must surface the shell-variable-expansion arm on the braced `${{...}}` \
6331 shape too, got {reason:?}"
6332 );
6333 }
6334
6335 #[test]
6336 fn fonte_repo_fragment_fires_before_var_expansion_when_fragment_first() {
6337 // Cascade pin: the fragment-`#` arm and the var-expansion-`$`
6338 // arm are both per-byte arms inside the same `for &b in
6339 // s.as_bytes()` loop, so the byte that appears first in the
6340 // value's byte order wins. A `:repo
6341 // "https://github.com/p/x#readme$HOME"` carries both `#` and
6342 // `$`; the `#` byte appears first, so the fragment-`#` arm
6343 // fires, surfacing the more self-locating diagnostic on the
6344 // byte the author pasted earliest in the URL. Mirrors the
6345 // peer cascade discipline
6346 // `fonte_repo_fragment_fires_before_background_when_fragment_first`
6347 // on the prior `:repo` byte-class arm.
6348 let d = dep_with_fonte(DepSource::Git {
6349 repo: "https://github.com/pleme-io/caixa-teia#readme$HOME".into(),
6350 tag: Some("v0.1.0".into()),
6351 rev: None,
6352 branch: None,
6353 });
6354 let err = d.validate().unwrap_err();
6355 let DepError::FonteRepoShape { reason, .. } = err else {
6356 panic!("expected FonteRepoShape, got other variant");
6357 };
6358 assert!(
6359 reason.contains("must not contain `#`"),
6360 "reason must surface the fragment-`#` arm (fires before var-expansion-`$` when \
6361 `#` byte appears first in value), got {reason:?}"
6362 );
6363 }
6364
6365 #[test]
6366 fn fonte_repo_background_fires_before_var_expansion_when_background_first() {
6367 // Cascade pin: the background-`&` arm and the
6368 // var-expansion-`$` arm are both per-byte arms inside the
6369 // same `for &b in s.as_bytes()` loop, so the byte that
6370 // appears first in the value's byte order wins. A `:repo
6371 // "https://github.com/p/x&sleep$HOME"` carries both `&` and
6372 // `$`; the `&` byte appears first, so the background arm
6373 // fires, surfacing the more self-locating diagnostic on the
6374 // byte the author pasted earliest in the URL. Pins the
6375 // natural-order cascade so a future reorder of the per-byte
6376 // arms surfaces here — `$` is the most recent byte-class arm,
6377 // so the cascade-pin sweep extends to cover every immediately
6378 // prior byte arm (`#`, `&`) firing first when ordered ahead
6379 // of `$` in the value.
6380 let d = dep_with_fonte(DepSource::Git {
6381 repo: "https://github.com/pleme-io/caixa-teia&sleep$HOME".into(),
6382 tag: Some("v0.1.0".into()),
6383 rev: None,
6384 branch: None,
6385 });
6386 let err = d.validate().unwrap_err();
6387 let DepError::FonteRepoShape { reason, .. } = err else {
6388 panic!("expected FonteRepoShape, got other variant");
6389 };
6390 assert!(
6391 reason.contains("must not contain `&`"),
6392 "reason must surface the background-`&` arm (fires before var-expansion-`$` when \
6393 `&` byte appears first in value), got {reason:?}"
6394 );
6395 }
6396
6397 #[test]
6398 fn validate_rejects_git_fonte_with_repo_carrying_shell_glob_wildcard() {
6399 // The fail-before-pass-after pin for the canonical
6400 // paste-from-shell-prompt glob footgun on `:repo` (peer with
6401 // the cf9034b `*` / `?` arm on the sibling `:caminho`
6402 // path-fonte axis). An author pastes a shell one-liner that
6403 // referenced a glob expansion (`ls
6404 // github.com/pleme-io/caixa-*`, `git clone
6405 // github:pleme-io/caixa-*`) into the `:repo` slot, forgetting
6406 // to substitute the literal repo name. Until this arm landed
6407 // the `*` byte silently passed every prior `is_git_repo_url`
6408 // arm (no whitespace, no control chars, no non-ASCII, no `#`,
6409 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`,
6410 // no `;`, no `&`, no `$`, doesn't start with `-` or `:`); RFC
6411 // 3986 §2 lists `*` in the 'sub-delims' / reserved set and
6412 // the WHATWG URL spec's special-query percent-encode set maps
6413 // `*` → `%2A` on the wire, so the byte rides verbatim into
6414 // the lacre's per-dep BLAKE3 closure but is silently
6415 // rewritten at libcurl's URL-parser layer — two authors
6416 // whose values differ only in their asterisk presence
6417 // resolve to the byte-identical upstream `git clone` but
6418 // lock to two distinct lacres, defeating the THEORY.md §V.2
6419 // render-determinism contract. Peer with the `:caminho`
6420 // axis's `FonteCaminhoShellGlob` arm (cf9034b) on the
6421 // sibling path-fonte axis, and the `is_git_ref_name`
6422 // refspec-wildcard cascade on the `:fonte :tag` / `:branch`
6423 // axes.
6424 let d = dep_with_fonte(DepSource::Git {
6425 repo: "https://github.com/pleme-io/caixa-*".into(),
6426 tag: Some("v0.1.0".into()),
6427 rev: None,
6428 branch: None,
6429 });
6430 let err = d.validate().unwrap_err();
6431 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6432 panic!("expected FonteRepoShape, got other variant");
6433 };
6434 assert_eq!(nome, "caixa-teia");
6435 assert_eq!(repo, "https://github.com/pleme-io/caixa-*");
6436 assert!(
6437 reason.contains("must not contain `*`"),
6438 "reason must surface the shell-glob arm, got {reason:?}"
6439 );
6440 assert!(
6441 reason.contains("pathname-expansion") || reason.contains("'sub-delims'"),
6442 "reason must name the shell-glob / pathname-expansion / \
6443 RFC-3986-sub-delims rationale, got {reason:?}"
6444 );
6445 }
6446
6447 #[test]
6448 fn validate_rejects_git_fonte_with_repo_carrying_recursive_shell_glob() {
6449 // The fail-before-pass-after pin for the symmetric bash
6450 // `globstar` recursive-glob paste footgun: an author pastes
6451 // a `ls github.com/pleme-io/**/x` (the canonical
6452 // `globstar`-shopt-enabled recursive-listing tail) into the
6453 // `:repo` slot. The `**` shape is two `*` bytes adjacent;
6454 // the per-byte arm fires on the first `*`. Pinned
6455 // separately from the single-`*` shape so a future
6456 // diagnostic-surface change that special-cased the
6457 // double-`*` form surfaces here.
6458 let d = dep_with_fonte(DepSource::Git {
6459 repo: "https://github.com/pleme-io/**/caixa-teia".into(),
6460 tag: Some("v0.1.0".into()),
6461 rev: None,
6462 branch: None,
6463 });
6464 let err = d.validate().unwrap_err();
6465 let DepError::FonteRepoShape { reason, .. } = err else {
6466 panic!("expected FonteRepoShape, got other variant");
6467 };
6468 assert!(
6469 reason.contains("must not contain `*`"),
6470 "reason must surface the shell-glob arm on the `**` recursive-glob shape too, \
6471 got {reason:?}"
6472 );
6473 }
6474
6475 #[test]
6476 fn fonte_repo_fragment_fires_before_glob_when_fragment_first() {
6477 // Cascade pin: the fragment-`#` arm and the glob-`*` arm are
6478 // both per-byte arms inside the same `for &b in s.as_bytes()`
6479 // loop, so the byte that appears first in the value's byte
6480 // order wins. A `:repo
6481 // "https://github.com/p/x#readme*tail"` carries both `#` and
6482 // `*`; the `#` byte appears first, so the fragment-`#` arm
6483 // fires, surfacing the more self-locating diagnostic on the
6484 // byte the author pasted earliest in the URL. Mirrors the
6485 // peer cascade discipline
6486 // `fonte_repo_fragment_fires_before_var_expansion_when_fragment_first`
6487 // on the prior `:repo` byte-class arm.
6488 let d = dep_with_fonte(DepSource::Git {
6489 repo: "https://github.com/pleme-io/caixa-teia#readme*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 fragment-`#` arm (fires before glob-`*` when `#` byte \
6501 appears first in value), got {reason:?}"
6502 );
6503 }
6504
6505 #[test]
6506 fn fonte_repo_var_expansion_fires_before_glob_when_var_expansion_first() {
6507 // Cascade pin: the var-expansion-`$` arm and the glob-`*`
6508 // arm are both per-byte arms inside the same `for &b in
6509 // s.as_bytes()` loop, so the byte that appears first in the
6510 // value's byte order wins. A `:repo
6511 // "https://github.com/p/$ORG-*"` carries both `$` and `*`;
6512 // the `$` byte appears first, so the var-expansion arm
6513 // fires, surfacing the more self-locating diagnostic on the
6514 // byte the author pasted earliest in the URL. Pins the
6515 // natural-order cascade so a future reorder of the per-byte
6516 // arms surfaces here — `*` is the most recent byte-class
6517 // arm, so the cascade-pin sweep extends to cover the
6518 // immediately prior `$` byte arm firing first when ordered
6519 // ahead of `*` in the value.
6520 let d = dep_with_fonte(DepSource::Git {
6521 repo: "https://github.com/pleme-io/$ORG-caixa-*".into(),
6522 tag: Some("v0.1.0".into()),
6523 rev: None,
6524 branch: None,
6525 });
6526 let err = d.validate().unwrap_err();
6527 let DepError::FonteRepoShape { reason, .. } = err else {
6528 panic!("expected FonteRepoShape, got other variant");
6529 };
6530 assert!(
6531 reason.contains("must not contain `$`"),
6532 "reason must surface the var-expansion-`$` arm (fires before glob-`*` when `$` \
6533 byte appears first in value), got {reason:?}"
6534 );
6535 }
6536
6537 #[test]
6538 fn validate_rejects_git_fonte_with_repo_carrying_subshell_open_paren() {
6539 // The fail-before-pass-after pin for the canonical paste-from-
6540 // shell-prompt subshell-grouping footgun on `:repo`. An author
6541 // pastes a doc / README snippet carrying a regex-alternation
6542 // grouping shape (`https://github.com/(foo|bar)/repo`) or a
6543 // dynamic-config-substitution wrapper (`$(<cmd>)`) into the
6544 // `:repo` slot, forgetting to substitute one literal org name.
6545 // Until this arm landed the `(` byte silently passed every
6546 // prior `is_git_repo_url` arm (no whitespace, no control
6547 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6548 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no
6549 // `*`, doesn't start with `-` or `:`); RFC 3986 §2 lists `(`
6550 // / `)` in the 'sub-delims' / reserved set, and the WHATWG
6551 // URL spec's special-query percent-encode set maps `(` →
6552 // `%28` and `)` → `%29` on the wire, so the byte rides
6553 // verbatim into the lacre's per-dep BLAKE3 closure but is
6554 // silently rewritten at libcurl's URL-parser layer —
6555 // defeating the THEORY.md §V.2 render-determinism contract on
6556 // the same axis the prior twelve byte-class arms close.
6557 let d = dep_with_fonte(DepSource::Git {
6558 repo: "https://github.com/(foo|bar)/caixa-teia".into(),
6559 tag: Some("v0.1.0".into()),
6560 rev: None,
6561 branch: None,
6562 });
6563 let err = d.validate().unwrap_err();
6564 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6565 panic!("expected FonteRepoShape, got other variant");
6566 };
6567 assert_eq!(nome, "caixa-teia");
6568 assert_eq!(repo, "https://github.com/(foo|bar)/caixa-teia");
6569 assert!(
6570 reason.contains("must not contain `(`"),
6571 "reason must surface the subshell-open-paren arm, got {reason:?}"
6572 );
6573 assert!(
6574 reason.contains("subshell-grouping") || reason.contains("'sub-delims'"),
6575 "reason must name the shell-subshell-grouping / RFC-3986-sub-delims rationale, \
6576 got {reason:?}"
6577 );
6578 }
6579
6580 #[test]
6581 fn validate_rejects_git_fonte_with_repo_carrying_subshell_close_paren() {
6582 // The symmetric arm pin on the closing `)` byte: an author
6583 // pastes a `$(date)` command-substitution wrapper or a
6584 // regex-alternation `(foo|bar)` tail into the `:repo` slot.
6585 // Pinned separately from the opening `(` shape so a future
6586 // diagnostic-surface change that only checked one boundary
6587 // surfaces here. The `(` byte appears earlier in the
6588 // canonical regex / subshell wrapper so the per-byte loop
6589 // fires on `(` first; this test exercises a `:repo` value
6590 // carrying only the closing `)` byte (no opening paren) so
6591 // the `)` arm fires directly — pinning the byte-class arm
6592 // independent of order.
6593 let d = dep_with_fonte(DepSource::Git {
6594 repo: "github:pleme-io/caixa-teia)tail".into(),
6595 tag: Some("v0.1.0".into()),
6596 rev: None,
6597 branch: None,
6598 });
6599 let err = d.validate().unwrap_err();
6600 let DepError::FonteRepoShape { reason, .. } = err else {
6601 panic!("expected FonteRepoShape, got other variant");
6602 };
6603 assert!(
6604 reason.contains("must not contain `)`"),
6605 "reason must surface the subshell-close-paren arm on the bare `)` shape, \
6606 got {reason:?}"
6607 );
6608 }
6609
6610 #[test]
6611 fn fonte_repo_fragment_fires_before_subshell_when_fragment_first() {
6612 // Cascade pin: the fragment-`#` arm and the subshell-`(` arm
6613 // are both per-byte arms inside the same `for &b in
6614 // s.as_bytes()` loop, so the byte that appears first in the
6615 // value's byte order wins. A `:repo
6616 // "https://github.com/p/x#readme(tail)"` carries both `#` and
6617 // `(`; the `#` byte appears first, so the fragment-`#` arm
6618 // fires, surfacing the more self-locating diagnostic on the
6619 // byte the author pasted earliest in the URL. Mirrors the
6620 // peer cascade discipline
6621 // `fonte_repo_fragment_fires_before_glob_when_fragment_first`
6622 // on the prior `:repo` byte-class arm.
6623 let d = dep_with_fonte(DepSource::Git {
6624 repo: "https://github.com/pleme-io/caixa-teia#readme(tail)".into(),
6625 tag: Some("v0.1.0".into()),
6626 rev: None,
6627 branch: None,
6628 });
6629 let err = d.validate().unwrap_err();
6630 let DepError::FonteRepoShape { reason, .. } = err else {
6631 panic!("expected FonteRepoShape, got other variant");
6632 };
6633 assert!(
6634 reason.contains("must not contain `#`"),
6635 "reason must surface the fragment-`#` arm (fires before subshell-`(` when `#` \
6636 byte appears first in value), got {reason:?}"
6637 );
6638 }
6639
6640 #[test]
6641 fn fonte_repo_glob_fires_before_subshell_when_glob_first() {
6642 // Cascade pin: the glob-`*` arm (the immediate-predecessor
6643 // byte-class arm, 3902a9a) and the subshell-`(` arm are both
6644 // per-byte arms inside the same `for &b in s.as_bytes()`
6645 // loop, so the byte that appears first in the value's byte
6646 // order wins. A `:repo
6647 // "https://github.com/p/x-*-(date)"` carries both `*` and
6648 // `(`; the `*` byte appears first, so the glob arm fires,
6649 // surfacing the more self-locating diagnostic on the byte
6650 // the author pasted earliest in the URL. Pins the natural-
6651 // order cascade so a future reorder of the per-byte arms
6652 // surfaces here — `(` is the most recent byte-class arm,
6653 // so the cascade-pin sweep extends to cover the immediately
6654 // prior `*` byte arm firing first when ordered ahead of `(`
6655 // in the value.
6656 let d = dep_with_fonte(DepSource::Git {
6657 repo: "https://github.com/pleme-io/caixa-teia-*-(date)".into(),
6658 tag: Some("v0.1.0".into()),
6659 rev: None,
6660 branch: None,
6661 });
6662 let err = d.validate().unwrap_err();
6663 let DepError::FonteRepoShape { reason, .. } = err else {
6664 panic!("expected FonteRepoShape, got other variant");
6665 };
6666 assert!(
6667 reason.contains("must not contain `*`"),
6668 "reason must surface the glob-`*` arm (fires before subshell-`(` when `*` byte \
6669 appears first in value), got {reason:?}"
6670 );
6671 }
6672
6673 #[test]
6674 fn validate_rejects_git_fonte_with_repo_carrying_shell_double_quote() {
6675 // The fail-before-pass-after pin for the canonical paste-from-
6676 // doc-shell-quoting footgun on `:repo`. An author copies a
6677 // README quick-start snippet (`$ git clone "https://github.com/
6678 // foo/bar"`) and keeps the surrounding double-quote bytes when
6679 // pasting into the `:repo` slot — the doc wraps the URL in
6680 // double quotes so the shell doesn't re-lex metachars inside,
6681 // but the typed slot is itself a byte-level string parser, not
6682 // a shell context, so the quote bytes ride into the value
6683 // verbatim. Until this arm landed the `"` byte silently passed
6684 // every prior `is_git_repo_url` arm (no whitespace, no control
6685 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6686 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`,
6687 // no `(`/`)`, doesn't start with `-` or `:`); RFC 3986 §2 lists
6688 // `"` in the strict four-byte 'delims' subset (with `<`, `>`,
6689 // `` ` ``) every URL parser is required to refuse or percent-
6690 // encode, and the WHATWG URL spec's 'C0 control percent-encode
6691 // set' maps `"` → `%22` on the wire, so the byte rides verbatim
6692 // into the lacre's per-dep BLAKE3 closure but is silently
6693 // rewritten at libcurl's URL-parser layer, defeating the
6694 // THEORY.md §V.2 render-determinism contract.
6695 let d = dep_with_fonte(DepSource::Git {
6696 repo: "\"https://github.com/pleme-io/caixa-teia\"".into(),
6697 tag: Some("v0.1.0".into()),
6698 rev: None,
6699 branch: None,
6700 });
6701 let err = d.validate().unwrap_err();
6702 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6703 panic!("expected FonteRepoShape, got other variant");
6704 };
6705 assert_eq!(nome, "caixa-teia");
6706 assert_eq!(repo, "\"https://github.com/pleme-io/caixa-teia\"");
6707 assert!(
6708 reason.contains("must not contain `\"`"),
6709 "reason must surface the shell-double-quote arm, got {reason:?}"
6710 );
6711 assert!(
6712 reason.contains("double-quote") || reason.contains("'delims'"),
6713 "reason must name the shell-double-quote / RFC-3986-delims rationale, \
6714 got {reason:?}"
6715 );
6716 }
6717
6718 #[test]
6719 fn validate_rejects_git_fonte_with_repo_carrying_stray_trailing_double_quote() {
6720 // The symmetric stray-quote tail pin: an author pastes only a
6721 // closing `"` from a shell-history line like `git clone
6722 // "https://github.com/foo/bar" && cd …` (the trim went too
6723 // far in one direction but not the other) into the `:repo`
6724 // slot. Pinned separately from the wrapped-quote shape so a
6725 // future diagnostic-surface change that only checked one
6726 // boundary (only leading, only trailing, only paired) surfaces
6727 // here — the per-byte arm fires anywhere `"` appears.
6728 let d = dep_with_fonte(DepSource::Git {
6729 repo: "github:pleme-io/caixa-teia\"".into(),
6730 tag: Some("v0.1.0".into()),
6731 rev: None,
6732 branch: None,
6733 });
6734 let err = d.validate().unwrap_err();
6735 let DepError::FonteRepoShape { reason, .. } = err else {
6736 panic!("expected FonteRepoShape, got other variant");
6737 };
6738 assert!(
6739 reason.contains("must not contain `\"`"),
6740 "reason must surface the shell-double-quote arm on the trailing-`\"` shape, \
6741 got {reason:?}"
6742 );
6743 }
6744
6745 #[test]
6746 fn fonte_repo_fragment_fires_before_double_quote_when_fragment_first() {
6747 // Cascade pin: the fragment-`#` arm and the double-quote arm
6748 // are both per-byte arms inside the same `for &b in
6749 // s.as_bytes()` loop, so the byte that appears first in the
6750 // value's byte order wins. A `:repo
6751 // "https://github.com/p/x#readme\"tail"` carries both `#` and
6752 // `"`; the `#` byte appears first, so the fragment-`#` arm
6753 // fires, surfacing the more self-locating diagnostic on the
6754 // byte the author pasted earliest in the URL.
6755 let d = dep_with_fonte(DepSource::Git {
6756 repo: "https://github.com/pleme-io/caixa-teia#readme\"tail".into(),
6757 tag: Some("v0.1.0".into()),
6758 rev: None,
6759 branch: None,
6760 });
6761 let err = d.validate().unwrap_err();
6762 let DepError::FonteRepoShape { reason, .. } = err else {
6763 panic!("expected FonteRepoShape, got other variant");
6764 };
6765 assert!(
6766 reason.contains("must not contain `#`"),
6767 "reason must surface the fragment-`#` arm (fires before double-quote when `#` \
6768 byte appears first in value), got {reason:?}"
6769 );
6770 }
6771
6772 #[test]
6773 fn fonte_repo_subshell_fires_before_double_quote_when_subshell_first() {
6774 // Cascade pin: the subshell-`(` arm (the immediate-predecessor
6775 // byte-class arm, 3b99147) and the double-quote arm are both
6776 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6777 // so the byte that appears first in the value's byte order
6778 // wins. A `:repo "github:p/x(date)\"tail"` carries both `(`
6779 // and `"`; the `(` byte appears first, so the subshell arm
6780 // fires, surfacing the more self-locating diagnostic on the
6781 // byte the author pasted earliest in the URL. Pins the natural-
6782 // order cascade so a future reorder of the per-byte arms
6783 // surfaces here — `"` is the most recent byte-class arm, so
6784 // the cascade-pin sweep extends to cover the immediately prior
6785 // `(` byte arm firing first when ordered ahead of `"` in the
6786 // value.
6787 let d = dep_with_fonte(DepSource::Git {
6788 repo: "github:pleme-io/caixa-teia(date)\"tail".into(),
6789 tag: Some("v0.1.0".into()),
6790 rev: None,
6791 branch: None,
6792 });
6793 let err = d.validate().unwrap_err();
6794 let DepError::FonteRepoShape { reason, .. } = err else {
6795 panic!("expected FonteRepoShape, got other variant");
6796 };
6797 assert!(
6798 reason.contains("must not contain `(`"),
6799 "reason must surface the subshell-`(` arm (fires before double-quote when `(` \
6800 byte appears first in value), got {reason:?}"
6801 );
6802 }
6803
6804 #[test]
6805 fn validate_rejects_git_fonte_with_repo_carrying_shell_single_quote() {
6806 // The fail-before-pass-after pin for the canonical paste-from-
6807 // doc-strong-quoting footgun on `:repo`. An author copies a
6808 // security-conscious README quick-start snippet (`$ git clone
6809 // 'https://github.com/foo/bar'`) and keeps the surrounding
6810 // single-quote bytes when pasting into the `:repo` slot — the
6811 // doc strong-quotes the URL so the shell suppresses every form
6812 // of expansion on the bytes inside (no `$`, no backtick, no
6813 // glob, no word-splitting), but the typed slot is itself a
6814 // byte-level string parser, not a shell context, so the quote
6815 // bytes ride into the value verbatim. Until this arm landed the
6816 // `'` byte silently passed every prior `is_git_repo_url` arm
6817 // (no whitespace, no control chars, no non-ASCII, no `#`, no
6818 // `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no
6819 // `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`, doesn't start
6820 // with `-` or `:`); RFC 3986 §2.2 lists `'` in the 'sub-delims'
6821 // set, peer with the `\"` 'delims' double-quote arm and the
6822 // partner ASCII shell-string-delimiter byte every byte-level
6823 // string parser sharing a value-shape with a shell argument
6824 // must refuse on a URL-shaped slot.
6825 let d = dep_with_fonte(DepSource::Git {
6826 repo: "'https://github.com/pleme-io/caixa-teia'".into(),
6827 tag: Some("v0.1.0".into()),
6828 rev: None,
6829 branch: None,
6830 });
6831 let err = d.validate().unwrap_err();
6832 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6833 panic!("expected FonteRepoShape, got other variant");
6834 };
6835 assert_eq!(nome, "caixa-teia");
6836 assert_eq!(repo, "'https://github.com/pleme-io/caixa-teia'");
6837 assert!(
6838 reason.contains("must not contain `'`"),
6839 "reason must surface the shell-single-quote arm, got {reason:?}"
6840 );
6841 assert!(
6842 reason.contains("single-quote") || reason.contains("strong-quote"),
6843 "reason must name the shell-single-quote / strong-quote rationale, \
6844 got {reason:?}"
6845 );
6846 }
6847
6848 #[test]
6849 fn validate_rejects_git_fonte_with_repo_carrying_english_apostrophe() {
6850 // The symmetric English-typography pin: an author writes
6851 // `:repo "github:p/repo's-fork"` (the possessive-form paste-
6852 // from-prose idiom every README / commit-message / chat-thread
6853 // reference to a repo carries) expecting the substrate to
6854 // coerce it to a kebab-case slug — but the byte rides into the
6855 // lacre verbatim. Pinned separately from the wrapped-quote
6856 // shape so a future diagnostic-surface change that only checked
6857 // the boundary positions (only leading, only trailing, only
6858 // paired) surfaces here — the per-byte arm fires anywhere `'`
6859 // appears in the value.
6860 let d = dep_with_fonte(DepSource::Git {
6861 repo: "github:pleme-io/repo's-fork".into(),
6862 tag: Some("v0.1.0".into()),
6863 rev: None,
6864 branch: None,
6865 });
6866 let err = d.validate().unwrap_err();
6867 let DepError::FonteRepoShape { reason, .. } = err else {
6868 panic!("expected FonteRepoShape, got other variant");
6869 };
6870 assert!(
6871 reason.contains("must not contain `'`"),
6872 "reason must surface the shell-single-quote arm on the mid-string \
6873 apostrophe shape, got {reason:?}"
6874 );
6875 }
6876
6877 #[test]
6878 fn fonte_repo_fragment_fires_before_single_quote_when_fragment_first() {
6879 // Cascade pin: the fragment-`#` arm and the single-quote arm
6880 // are both per-byte arms inside the same `for &b in
6881 // s.as_bytes()` loop, so the byte that appears first in the
6882 // value's byte order wins. A `:repo
6883 // "https://github.com/p/x#readme'tail"` carries both `#` and
6884 // `'`; the `#` byte appears first, so the fragment-`#` arm
6885 // fires, surfacing the more self-locating diagnostic on the
6886 // byte the author pasted earliest in the URL.
6887 let d = dep_with_fonte(DepSource::Git {
6888 repo: "https://github.com/pleme-io/caixa-teia#readme'tail".into(),
6889 tag: Some("v0.1.0".into()),
6890 rev: None,
6891 branch: None,
6892 });
6893 let err = d.validate().unwrap_err();
6894 let DepError::FonteRepoShape { reason, .. } = err else {
6895 panic!("expected FonteRepoShape, got other variant");
6896 };
6897 assert!(
6898 reason.contains("must not contain `#`"),
6899 "reason must surface the fragment-`#` arm (fires before single-quote when `#` \
6900 byte appears first in value), got {reason:?}"
6901 );
6902 }
6903
6904 #[test]
6905 fn fonte_repo_double_quote_fires_before_single_quote_when_double_quote_first() {
6906 // Cascade pin: the double-quote-`"` arm (the immediate-predecessor
6907 // byte-class arm, 4267d8b) and the single-quote arm are both
6908 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6909 // so the byte that appears first in the value's byte order
6910 // wins. A `:repo "github:p/x\"mid'tail"` carries both `"` and
6911 // `'`; the `"` byte appears first, so the double-quote arm
6912 // fires, surfacing the more self-locating diagnostic on the
6913 // byte the author pasted earliest in the URL. Pins the natural-
6914 // order cascade so a future reorder of the per-byte arms
6915 // surfaces here — `'` is the most recent byte-class arm, so
6916 // the cascade-pin sweep extends to cover the immediately prior
6917 // `"` byte arm firing first when ordered ahead of `'` in the
6918 // value.
6919 let d = dep_with_fonte(DepSource::Git {
6920 repo: "github:pleme-io/caixa-teia\"mid'tail".into(),
6921 tag: Some("v0.1.0".into()),
6922 rev: None,
6923 branch: None,
6924 });
6925 let err = d.validate().unwrap_err();
6926 let DepError::FonteRepoShape { reason, .. } = err else {
6927 panic!("expected FonteRepoShape, got other variant");
6928 };
6929 assert!(
6930 reason.contains("must not contain `\"`"),
6931 "reason must surface the double-quote arm (fires before single-quote when `\"` \
6932 byte appears first in value), got {reason:?}"
6933 );
6934 }
6935
6936 #[test]
6937 fn validate_rejects_git_fonte_with_repo_carrying_shell_history_expansion() {
6938 // The fail-before-pass-after pin for the canonical paste-from-
6939 // shell-history footgun on `:repo`. An author copies a `git
6940 // clone <url>!sudo make install` one-liner from a README's
6941 // quick-start snippet, intending the trailing `!sudo` as a
6942 // shell-history-expansion reference but the typed slot is itself
6943 // a byte-level string parser, not a shell context, so the byte
6944 // rides into the value verbatim. Until this arm landed the `!`
6945 // byte silently passed every prior `is_git_repo_url` arm (no
6946 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
6947 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6948 // no `&`, no `$`, no `*`, no `(`/`)`, no `"`, no `'`, doesn't
6949 // start with `-` or `:`); bash with the default `histexpand`
6950 // mode rewrites `!command` to the most recent history entry
6951 // beginning with `command`, the canonical RCE-class injection
6952 // vector when the byte rides into a shell argument.
6953 let d = dep_with_fonte(DepSource::Git {
6954 repo: "https://github.com/pleme-io/caixa-teia!sudo".into(),
6955 tag: Some("v0.1.0".into()),
6956 rev: None,
6957 branch: None,
6958 });
6959 let err = d.validate().unwrap_err();
6960 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6961 panic!("expected FonteRepoShape, got other variant");
6962 };
6963 assert_eq!(nome, "caixa-teia");
6964 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia!sudo");
6965 assert!(
6966 reason.contains("must not contain `!`"),
6967 "reason must surface the shell-history-expansion arm, got {reason:?}"
6968 );
6969 assert!(
6970 reason.contains("history-expansion") || reason.contains("bang"),
6971 "reason must name the shell-history-expansion / bang rationale, got {reason:?}"
6972 );
6973 }
6974
6975 #[test]
6976 fn validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference() {
6977 // The symmetric `!!` repeat-prior-command pin: an author paste-
6978 // trims a `git clone <url>` retry idiom from shell history that
6979 // expands to the previous command via `!!`. Pinned separately
6980 // from the wrapped `!command` shape so a future diagnostic-
6981 // surface change that only checked the leading or paired-bang
6982 // position surfaces here — the per-byte arm fires anywhere `!`
6983 // appears in the value.
6984 let d = dep_with_fonte(DepSource::Git {
6985 repo: "github:pleme-io/caixa-teia!!".into(),
6986 tag: Some("v0.1.0".into()),
6987 rev: None,
6988 branch: None,
6989 });
6990 let err = d.validate().unwrap_err();
6991 let DepError::FonteRepoShape { reason, .. } = err else {
6992 panic!("expected FonteRepoShape, got other variant");
6993 };
6994 assert!(
6995 reason.contains("must not contain `!`"),
6996 "reason must surface the shell-history-expansion arm on the trailing-`!!` shape, \
6997 got {reason:?}"
6998 );
6999 }
7000
7001 #[test]
7002 fn fonte_repo_fragment_fires_before_bang_when_fragment_first() {
7003 // Cascade pin: the fragment-`#` arm and the bang arm are both
7004 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7005 // so the byte that appears first in the value's byte order
7006 // wins. A `:repo "https://github.com/p/x#readme!tail"` carries
7007 // both `#` and `!`; the `#` byte appears first, so the
7008 // fragment-`#` arm fires, surfacing the more self-locating
7009 // diagnostic on the byte the author pasted earliest in the URL.
7010 let d = dep_with_fonte(DepSource::Git {
7011 repo: "https://github.com/pleme-io/caixa-teia#readme!tail".into(),
7012 tag: Some("v0.1.0".into()),
7013 rev: None,
7014 branch: None,
7015 });
7016 let err = d.validate().unwrap_err();
7017 let DepError::FonteRepoShape { reason, .. } = err else {
7018 panic!("expected FonteRepoShape, got other variant");
7019 };
7020 assert!(
7021 reason.contains("must not contain `#`"),
7022 "reason must surface the fragment-`#` arm (fires before bang when `#` byte \
7023 appears first in value), got {reason:?}"
7024 );
7025 }
7026
7027 #[test]
7028 fn fonte_repo_single_quote_fires_before_bang_when_single_quote_first() {
7029 // Cascade pin: the single-quote-`'` arm (the immediate-predecessor
7030 // byte-class arm, e7a109f) and the bang arm are both per-byte
7031 // arms inside the same `for &b in s.as_bytes()` loop, so the
7032 // byte that appears first in the value's byte order wins. A
7033 // `:repo "github:p/x'mid!tail"` carries both `'` and `!`; the
7034 // `'` byte appears first, so the single-quote arm fires,
7035 // surfacing the more self-locating diagnostic on the byte the
7036 // author pasted earliest in the URL. Pins the natural-order
7037 // cascade so a future reorder of the per-byte arms surfaces
7038 // here — `!` is the most recent byte-class arm, so the
7039 // cascade-pin sweep extends to cover the immediately prior `'`
7040 // byte arm firing first when ordered ahead of `!` in the value.
7041 let d = dep_with_fonte(DepSource::Git {
7042 repo: "github:pleme-io/caixa-teia'mid!tail".into(),
7043 tag: Some("v0.1.0".into()),
7044 rev: None,
7045 branch: None,
7046 });
7047 let err = d.validate().unwrap_err();
7048 let DepError::FonteRepoShape { reason, .. } = err else {
7049 panic!("expected FonteRepoShape, got other variant");
7050 };
7051 assert!(
7052 reason.contains("must not contain `'`"),
7053 "reason must surface the single-quote arm (fires before bang when `'` byte \
7054 appears first in value), got {reason:?}"
7055 );
7056 }
7057
7058 #[test]
7059 fn validate_rejects_git_fonte_with_repo_carrying_list_separator_comma() {
7060 // The fail-before-pass-after pin for the canonical
7061 // list-separator-belongs-to-list-grammar footgun on `:repo`.
7062 // An author copies a `git clone <a>, <b>, <c>` paste-from-CSV
7063 // one-liner from a multi-repo bootstrap doc, intending the
7064 // comma to separate multiple repo entries but the typed
7065 // `:repo` slot names *one* repo (the list-separator belongs
7066 // to the `:deps` list grammar, not to the value). Until this
7067 // arm landed the `,` byte silently passed every prior
7068 // `is_git_repo_url` arm (no whitespace, no control chars, no
7069 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
7070 // no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`, no
7071 // `(`/`)`, no `"`, no `'`, no `!`, doesn't start with `-` or
7072 // `:`); the byte rode into the lacre's per-dep content-
7073 // address and the resolver's `git clone <repo>` subprocess
7074 // invocation, where no host's repo registry resolved the
7075 // comma-bearing slug.
7076 let d = dep_with_fonte(DepSource::Git {
7077 repo: "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira".into(),
7078 tag: Some("v0.1.0".into()),
7079 rev: None,
7080 branch: None,
7081 });
7082 let err = d.validate().unwrap_err();
7083 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7084 panic!("expected FonteRepoShape, got other variant");
7085 };
7086 assert_eq!(nome, "caixa-teia");
7087 assert_eq!(
7088 repo,
7089 "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira"
7090 );
7091 assert!(
7092 reason.contains("must not contain `,`"),
7093 "reason must surface the list-separator-comma arm, got {reason:?}"
7094 );
7095 assert!(
7096 reason.contains("list-separator") || reason.contains("sub-delims"),
7097 "reason must name the list-separator / RFC-3986-sub-delims rationale, \
7098 got {reason:?}"
7099 );
7100 }
7101
7102 #[test]
7103 fn validate_rejects_git_fonte_with_repo_carrying_trailing_comma() {
7104 // The symmetric trailing-`,` paste-from-prose pin: an author
7105 // writes `:repo "github:pleme-io/caixa-feira,"` (the trailing
7106 // comma every README-prose list-of-projects sentence carries,
7107 // mistakenly retained when the slug is pasted mid-sentence)
7108 // expecting the substrate to coerce it to a kebab-case slug.
7109 // Pinned separately from the wrapped mid-token shape so a
7110 // future diagnostic-surface change that only checked the
7111 // leading or paired-comma position surfaces here — the
7112 // per-byte arm fires anywhere `,` appears in the value.
7113 let d = dep_with_fonte(DepSource::Git {
7114 repo: "github:pleme-io/caixa-feira,".into(),
7115 tag: Some("v0.1.0".into()),
7116 rev: None,
7117 branch: None,
7118 });
7119 let err = d.validate().unwrap_err();
7120 let DepError::FonteRepoShape { reason, .. } = err else {
7121 panic!("expected FonteRepoShape, got other variant");
7122 };
7123 assert!(
7124 reason.contains("must not contain `,`"),
7125 "reason must surface the list-separator-comma arm on the trailing-`,` shape, \
7126 got {reason:?}"
7127 );
7128 }
7129
7130 #[test]
7131 fn fonte_repo_fragment_fires_before_comma_when_fragment_first() {
7132 // Cascade pin: the fragment-`#` arm and the comma arm are
7133 // both per-byte arms inside the same `for &b in s.as_bytes()`
7134 // loop, so the byte that appears first in the value's byte
7135 // order wins. A `:repo "https://github.com/p/x#readme,tail"`
7136 // carries both `#` and `,`; the `#` byte appears first, so
7137 // the fragment-`#` arm fires, surfacing the more self-
7138 // locating diagnostic on the byte the author pasted earliest
7139 // in the URL.
7140 let d = dep_with_fonte(DepSource::Git {
7141 repo: "https://github.com/pleme-io/caixa-teia#readme,tail".into(),
7142 tag: Some("v0.1.0".into()),
7143 rev: None,
7144 branch: None,
7145 });
7146 let err = d.validate().unwrap_err();
7147 let DepError::FonteRepoShape { reason, .. } = err else {
7148 panic!("expected FonteRepoShape, got other variant");
7149 };
7150 assert!(
7151 reason.contains("must not contain `#`"),
7152 "reason must surface the fragment-`#` arm (fires before comma when `#` byte \
7153 appears first in value), got {reason:?}"
7154 );
7155 }
7156
7157 #[test]
7158 fn fonte_repo_bang_fires_before_comma_when_bang_first() {
7159 // Cascade pin: the bang-`!` arm (the immediate-predecessor
7160 // byte-class arm, 7d53c68) and the comma arm are both
7161 // per-byte arms inside the same `for &b in s.as_bytes()`
7162 // loop, so the byte that appears first in the value's byte
7163 // order wins. A `:repo "github:p/x!mid,tail"` carries both
7164 // `!` and `,`; the `!` byte appears first, so the bang arm
7165 // fires, surfacing the more self-locating diagnostic on the
7166 // byte the author pasted earliest in the URL. Pins the
7167 // natural-order cascade so a future reorder of the per-byte
7168 // arms surfaces here — `,` is the most recent byte-class
7169 // arm, so the cascade-pin sweep extends to cover the
7170 // immediately prior `!` byte arm firing first when ordered
7171 // ahead of `,` in the value.
7172 let d = dep_with_fonte(DepSource::Git {
7173 repo: "github:pleme-io/caixa-teia!mid,tail".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 not contain `!`"),
7184 "reason must surface the bang arm (fires before comma when `!` byte \
7185 appears first in value), got {reason:?}"
7186 );
7187 }
7188
7189 #[test]
7190 fn validate_rejects_git_fonte_with_repo_carrying_shell_env_var_assignment() {
7191 // The fail-before-pass-after pin for the canonical
7192 // shell-env-var-assignment-belongs-to-shell-grammar footgun
7193 // on `:repo`. An author copies
7194 // `GIT_TERMINAL_PROMPT=0 git clone <url>` (or
7195 // `GIT_SSL_NO_VERIFY=1 git clone <url>`, `HTTPS_PROXY=…
7196 // git clone <url>`, etc. — the canonical
7197 // git-troubleshooting README idiom for a one-shot env-var
7198 // scoped to the `git clone` invocation) from a shell-prompt
7199 // one-liner, intending the `KEY=VALUE` prefix as a shell-
7200 // grammar env-var assignment but the typed `:repo` slot is
7201 // a value parser, not a shell context, so the bytes ride
7202 // into the value verbatim. Until this arm landed the `=`
7203 // byte silently passed every prior `is_git_repo_url` arm
7204 // (no whitespace, no control chars, no non-ASCII, no `#`,
7205 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no
7206 // `|`, no `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`,
7207 // no `'`, no `!`, no `,`, doesn't start with `-` or `:`);
7208 // the byte rode into the lacre's per-dep content-address
7209 // and the resolver's `git clone <repo>` subprocess
7210 // invocation, where the upstream host's git porcelain
7211 // fetched a literal `GIT_TERMINAL_PROMPT=0 https://…`-shaped
7212 // path that no host's repo registry resolves.
7213 let d = dep_with_fonte(DepSource::Git {
7214 repo: "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia".into(),
7215 tag: Some("v0.1.0".into()),
7216 rev: None,
7217 branch: None,
7218 });
7219 let err = d.validate().unwrap_err();
7220 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7221 panic!("expected FonteRepoShape, got other variant");
7222 };
7223 assert_eq!(nome, "caixa-teia");
7224 assert_eq!(
7225 repo,
7226 "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia"
7227 );
7228 // The `=` byte at position 19 of `GIT_TERMINAL_PROMPT=0 …`
7229 // appears before the ` ` byte at position 21, so the `=`
7230 // arm fires (not the whitespace arm) — both arms guard
7231 // the slot, but the per-byte for-loop scans left-to-right
7232 // and the first matching byte wins.
7233 assert!(
7234 reason.contains("must not contain `=`"),
7235 "reason must surface the equals-`=` arm on the env-var-assignment \
7236 paste shape, got {reason:?}"
7237 );
7238 assert!(
7239 reason.contains("env-var-assignment") || reason.contains("KEY=VALUE"),
7240 "reason must name the shell-env-var-assignment rationale, got {reason:?}"
7241 );
7242 }
7243
7244 #[test]
7245 fn validate_rejects_git_fonte_with_repo_carrying_gitconfig_url_key_prefix() {
7246 // The symmetric paste-from-gitconfig pin: an author copies
7247 // `url=https://github.com/p/x` from `git config --get-all
7248 // remote.origin.url` output, a `.gitconfig` `[remote
7249 // "origin"] url = https://…` ini-stanza paste, or a
7250 // `git config remote.origin.url <value>` doc snippet,
7251 // intending the `url=` prefix as the ini-key but the typed
7252 // `:repo` slot is a URL value parser, not a gitconfig
7253 // grammar. With no leading whitespace and no earlier-arm
7254 // bytes in the value, the `=` arm itself fires (rather
7255 // than cascading to the whitespace arm as in the env-var
7256 // paste shape). Pinned separately so a future diagnostic-
7257 // surface change that only checked the whitespace-leading
7258 // shape surfaces here — the per-byte arm fires anywhere
7259 // `=` appears in the value.
7260 let d = dep_with_fonte(DepSource::Git {
7261 repo: "url=https://github.com/pleme-io/caixa-feira".into(),
7262 tag: Some("v0.1.0".into()),
7263 rev: None,
7264 branch: None,
7265 });
7266 let err = d.validate().unwrap_err();
7267 let DepError::FonteRepoShape { reason, .. } = err else {
7268 panic!("expected FonteRepoShape, got other variant");
7269 };
7270 assert!(
7271 reason.contains("must not contain `=`"),
7272 "reason must surface the equals-`=` arm on the `url=…` gitconfig \
7273 paste shape, got {reason:?}"
7274 );
7275 assert!(
7276 reason.contains("key-value-separator") || reason.contains("sub-delims"),
7277 "reason must name the key-value-separator / RFC-3986-sub-delims \
7278 rationale, got {reason:?}"
7279 );
7280 }
7281
7282 #[test]
7283 fn fonte_repo_fragment_fires_before_equals_when_fragment_first() {
7284 // Cascade pin: the fragment-`#` arm and the `=` arm are
7285 // both per-byte arms inside the same `for &b in s.as_bytes()`
7286 // loop, so the byte that appears first in the value's byte
7287 // order wins. A `:repo "https://github.com/p/x#readme=tail"`
7288 // carries both `#` and `=`; the `#` byte appears first, so
7289 // the fragment-`#` arm fires, surfacing the more self-
7290 // locating diagnostic on the byte the author pasted earliest
7291 // in the URL.
7292 let d = dep_with_fonte(DepSource::Git {
7293 repo: "https://github.com/pleme-io/caixa-teia#readme=tail".into(),
7294 tag: Some("v0.1.0".into()),
7295 rev: None,
7296 branch: None,
7297 });
7298 let err = d.validate().unwrap_err();
7299 let DepError::FonteRepoShape { reason, .. } = err else {
7300 panic!("expected FonteRepoShape, got other variant");
7301 };
7302 assert!(
7303 reason.contains("must not contain `#`"),
7304 "reason must surface the fragment-`#` arm (fires before equals when \
7305 `#` byte appears first in value), got {reason:?}"
7306 );
7307 }
7308
7309 #[test]
7310 fn fonte_repo_comma_fires_before_equals_when_comma_first() {
7311 // Cascade pin: the comma-`,` arm (the immediate-predecessor
7312 // byte-class arm, 775b80e) and the `=` arm are both per-byte
7313 // arms inside the same `for &b in s.as_bytes()` loop, so
7314 // the byte that appears first in the value's byte order
7315 // wins. A `:repo "github:p/x,mid=tail"` carries both `,`
7316 // and `=`; the `,` byte appears first, so the comma arm
7317 // fires, surfacing the more self-locating diagnostic on
7318 // the byte the author pasted earliest in the URL. Pins the
7319 // natural-order cascade so a future reorder of the per-byte
7320 // arms surfaces here — `=` is the most recent byte-class
7321 // arm, so the cascade-pin sweep extends to cover the
7322 // immediately prior `,` byte arm firing first when ordered
7323 // ahead of `=` in the value.
7324 let d = dep_with_fonte(DepSource::Git {
7325 repo: "github:pleme-io/caixa-teia,mid=tail".into(),
7326 tag: Some("v0.1.0".into()),
7327 rev: None,
7328 branch: None,
7329 });
7330 let err = d.validate().unwrap_err();
7331 let DepError::FonteRepoShape { reason, .. } = err else {
7332 panic!("expected FonteRepoShape, got other variant");
7333 };
7334 assert!(
7335 reason.contains("must not contain `,`"),
7336 "reason must surface the comma arm (fires before equals when `,` byte \
7337 appears first in value), got {reason:?}"
7338 );
7339 }
7340
7341 #[test]
7342 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_space() {
7343 // The fail-before-pass-after pin for the canonical paste-from-
7344 // browser-address-bar percent-encoded-space footgun on `:repo`.
7345 // An author copies `https://github.com/p/x%20test` from a
7346 // browser address bar (or a percent-encoded README hyperlink,
7347 // or a `curl --data-urlencode` shell-pipeline output)
7348 // intending `%20` as the URL encoding of a literal space; the
7349 // typed `:repo` slot already rejects the literal space byte
7350 // (the whitespace arm at the top of `is_git_repo_url`), so an
7351 // author trying to express "I really meant a space" reaches
7352 // for percent-encoding. Until this arm landed the `%` byte
7353 // silently passed every prior `is_git_repo_url` arm and rode
7354 // verbatim into the lacre's per-dep content-address — but
7355 // libcurl re-percent-encodes `%` to `%25` on the wire (since
7356 // `%` is reserved as the escape-sequence lead-in), so the
7357 // wire request becomes `https://github.com/p/x%2520test`, a
7358 // path the lacre's content-address never names. The classic
7359 // render-determinism violation on the encoding-mechanism axis
7360 // itself.
7361 let d = dep_with_fonte(DepSource::Git {
7362 repo: "https://github.com/pleme-io/caixa-teia%20test".into(),
7363 tag: Some("v0.1.0".into()),
7364 rev: None,
7365 branch: None,
7366 });
7367 let err = d.validate().unwrap_err();
7368 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7369 panic!("expected FonteRepoShape, got other variant");
7370 };
7371 assert_eq!(nome, "caixa-teia");
7372 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia%20test");
7373 assert!(
7374 reason.contains("must not contain `%`"),
7375 "reason must surface the percent-`%` arm on the percent-encoded-space \
7376 paste shape, got {reason:?}"
7377 );
7378 assert!(
7379 reason.contains("percent-encoding") || reason.contains("%25"),
7380 "reason must name the percent-encoding / `%25` re-encoding rationale, \
7381 got {reason:?}"
7382 );
7383 }
7384
7385 #[test]
7386 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_slash() {
7387 // The symmetric over-encoded-path-separator pin: an author
7388 // writes `:repo "https://github.com/p%2Fx"` intending the
7389 // `%2F` as the URL encoding of `/` (the canonical
7390 // paste-from-OpenAPI-spec / paste-from-percent-encoded-template
7391 // footgun every API client library and OAuth redirect-URI
7392 // documentation surfaces — the `/` is the URL-path-separator
7393 // and some templates percent-encode it to escape interpretation
7394 // as a path separator). The GitHub Smart-HTTP transport
7395 // resolves the URL's path-segment grammar before the
7396 // percent-decoding pass, so the value identifies a different
7397 // resource on the wire than the literal-`/` form the lacre's
7398 // content-address must agree with — two authors whose `:repo`
7399 // values differ only in their `/` vs `%2F` presence lock to
7400 // two distinct BLAKE3 closures for the byte-identical upstream
7401 // `git clone`. Pinned separately so a future diagnostic
7402 // surface that only catches the `%20` shape surfaces here too.
7403 let d = dep_with_fonte(DepSource::Git {
7404 repo: "https://github.com/pleme-io%2Fcaixa-teia".into(),
7405 tag: Some("v0.1.0".into()),
7406 rev: None,
7407 branch: None,
7408 });
7409 let err = d.validate().unwrap_err();
7410 let DepError::FonteRepoShape { reason, .. } = err else {
7411 panic!("expected FonteRepoShape, got other variant");
7412 };
7413 assert!(
7414 reason.contains("must not contain `%`"),
7415 "reason must surface the percent-`%` arm on the over-encoded-path \
7416 shape, got {reason:?}"
7417 );
7418 assert!(
7419 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7420 "reason must name the render-determinism / BLAKE3-closure rationale, \
7421 got {reason:?}"
7422 );
7423 }
7424
7425 #[test]
7426 fn fonte_repo_fragment_fires_before_percent_when_fragment_first() {
7427 // Cascade pin: the fragment-`#` arm and the `%` arm are both
7428 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7429 // so the byte that appears first in the value's byte order
7430 // wins. A `:repo "https://github.com/p/x#sec%20tail"` carries
7431 // both `#` and `%`; the `#` byte appears first, so the
7432 // fragment-`#` arm fires, surfacing the more self-locating
7433 // diagnostic on the byte the author pasted earliest in the URL.
7434 let d = dep_with_fonte(DepSource::Git {
7435 repo: "https://github.com/pleme-io/caixa-teia#sec%20tail".into(),
7436 tag: Some("v0.1.0".into()),
7437 rev: None,
7438 branch: None,
7439 });
7440 let err = d.validate().unwrap_err();
7441 let DepError::FonteRepoShape { reason, .. } = err else {
7442 panic!("expected FonteRepoShape, got other variant");
7443 };
7444 assert!(
7445 reason.contains("must not contain `#`"),
7446 "reason must surface the fragment-`#` arm (fires before percent when \
7447 `#` byte appears first in value), got {reason:?}"
7448 );
7449 }
7450
7451 #[test]
7452 fn fonte_repo_equals_fires_before_percent_when_equals_first() {
7453 // Cascade pin: the equals-`=` arm (the immediate-predecessor
7454 // byte-class arm, acf99af) and the `%` arm are both per-byte
7455 // arms inside the same `for &b in s.as_bytes()` loop, so the
7456 // byte that appears first in the value's byte order wins.
7457 // A `:repo "github:p/x=mid%20tail"` carries both `=` and `%`;
7458 // the `=` byte appears first, so the equals arm fires,
7459 // surfacing the more self-locating diagnostic on the byte the
7460 // author pasted earliest in the URL. Pins the natural-order
7461 // cascade so a future reorder of the per-byte arms surfaces
7462 // here — `%` is the most recent byte-class arm, so the
7463 // cascade-pin sweep extends to cover the immediately prior
7464 // `=` byte arm firing first when ordered ahead of `%` in the
7465 // value.
7466 let d = dep_with_fonte(DepSource::Git {
7467 repo: "github:pleme-io/caixa-teia=mid%20tail".into(),
7468 tag: Some("v0.1.0".into()),
7469 rev: None,
7470 branch: None,
7471 });
7472 let err = d.validate().unwrap_err();
7473 let DepError::FonteRepoShape { reason, .. } = err else {
7474 panic!("expected FonteRepoShape, got other variant");
7475 };
7476 assert!(
7477 reason.contains("must not contain `=`"),
7478 "reason must surface the equals arm (fires before percent when `=` byte \
7479 appears first in value), got {reason:?}"
7480 );
7481 }
7482
7483 #[test]
7484 fn validate_rejects_git_fonte_with_repo_carrying_caret_history_substitution() {
7485 // The fail-before-pass-after pin for the canonical paste-from-
7486 // shell-history footgun on `:repo`. An author copies a
7487 // `git clone <url>` line from their terminal followed by a
7488 // bash / ksh / zsh `^typo^fix^` quick-edit-and-rerun shell-
7489 // history shorthand (the `^old^new^` form re-runs the prior
7490 // history entry with the first `old` substituted by `new`,
7491 // bash's default behavior on interactive sessions with
7492 // `set -o histexpand`), forgetting to trim the trailing
7493 // `^...^...` shell-history fragment from the URL value. The
7494 // `^` byte sits in the RFC 3986 §2 'unwise' set (peer with
7495 // `{`, `}`, `|`, `\\` — the strictest of the §2 reserved
7496 // classes), the WHATWG URL spec's 'fragment percent-encode
7497 // set' maps `^` → `%5E` on the wire, so the byte rides
7498 // verbatim into the lacre's per-dep content-address but
7499 // libcurl re-encodes it to `%5E` at `git clone` time — the
7500 // classic render-determinism violation on the same axis the
7501 // peer `%`, `=`, `,`, `!`, `'`, `"`, `(`, `)`, `*`, `$`,
7502 // `&`, `;`, `|`, backtick, `<`, `>`, `{`, `}`, `\\`, `?`,
7503 // `#` arms close.
7504 let d = dep_with_fonte(DepSource::Git {
7505 repo: "https://github.com/pleme-io/caixa-teia^typo^fix".into(),
7506 tag: Some("v0.1.0".into()),
7507 rev: None,
7508 branch: None,
7509 });
7510 let err = d.validate().unwrap_err();
7511 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7512 panic!("expected FonteRepoShape, got other variant");
7513 };
7514 assert_eq!(nome, "caixa-teia");
7515 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia^typo^fix");
7516 assert!(
7517 reason.contains("must not contain `^`"),
7518 "reason must surface the caret-`^` arm on the paste-from-shell-history \
7519 shape, got {reason:?}"
7520 );
7521 assert!(
7522 reason.contains("history-substitution") || reason.contains("%5E"),
7523 "reason must name the shell-history-substitution / `%5E` wire-encoding \
7524 rationale, got {reason:?}"
7525 );
7526 }
7527
7528 #[test]
7529 fn validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor() {
7530 // The symmetric paste-from-doc-grep-pipeline footgun: an
7531 // author writes `:repo "github:p/^archived"` after copying a
7532 // `grep '^archived'` regex-anchor / negation idiom from a
7533 // doc / README quick-listing snippet, expecting the substrate
7534 // to coerce it to a literal repo name. The byte rides
7535 // verbatim into the lacre's per-dep content-address and
7536 // diverges from the byte-identical literal `archived` form
7537 // every other author authored — the canonical render-
7538 // determinism violation pin on the second footgun shape the
7539 // caret-`^` arm closes.
7540 let d = dep_with_fonte(DepSource::Git {
7541 repo: "github:pleme-io/^archived".into(),
7542 tag: Some("v0.1.0".into()),
7543 rev: None,
7544 branch: None,
7545 });
7546 let err = d.validate().unwrap_err();
7547 let DepError::FonteRepoShape { reason, .. } = err else {
7548 panic!("expected FonteRepoShape, got other variant");
7549 };
7550 assert!(
7551 reason.contains("must not contain `^`"),
7552 "reason must surface the caret-`^` arm on the regex-anchor shape, \
7553 got {reason:?}"
7554 );
7555 assert!(
7556 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7557 "reason must name the render-determinism / BLAKE3-closure rationale, \
7558 got {reason:?}"
7559 );
7560 }
7561
7562 #[test]
7563 fn fonte_repo_percent_fires_before_caret_when_percent_first() {
7564 // Cascade pin: the `%` arm (the immediate-predecessor byte-
7565 // class arm, a323db8) and the `^` arm are both per-byte arms
7566 // inside the same `for &b in s.as_bytes()` loop, so the byte
7567 // that appears first in the value's byte order wins. A
7568 // `:repo "https://github.com/p/x%20mid^tail"` carries both
7569 // `%` and `^`; the `%` byte appears first, so the percent
7570 // arm fires, surfacing the more self-locating diagnostic on
7571 // the byte the author pasted earliest in the URL. Pins the
7572 // natural-order cascade so a future reorder of the per-byte
7573 // arms surfaces here — `^` is the most recent byte-class arm,
7574 // so the cascade-pin sweep extends to cover the immediately
7575 // prior `%` byte arm firing first when ordered ahead of `^`
7576 // in the value.
7577 let d = dep_with_fonte(DepSource::Git {
7578 repo: "https://github.com/pleme-io/caixa-teia%20mid^tail".into(),
7579 tag: Some("v0.1.0".into()),
7580 rev: None,
7581 branch: None,
7582 });
7583 let err = d.validate().unwrap_err();
7584 let DepError::FonteRepoShape { reason, .. } = err else {
7585 panic!("expected FonteRepoShape, got other variant");
7586 };
7587 assert!(
7588 reason.contains("must not contain `%`"),
7589 "reason must surface the percent arm (fires before caret when `%` byte \
7590 appears first in value), got {reason:?}"
7591 );
7592 }
7593
7594 #[test]
7595 fn validate_rejects_git_fonte_with_repo_missing_colon_separator() {
7596 // The "I dropped the scheme" footgun — `:repo "pleme-io/caixa-teia"`
7597 // (no `github:` prefix, no scheme). Every documented form
7598 // carries a `:` (`github:`, `https://`, `ssh://`, `git://`,
7599 // `file://`, or `git@host:path`); a bare `org/repo` is
7600 // ambiguous (`git clone` reads as a relative filesystem path
7601 // rather than the GitHub-shorthand expansion the author
7602 // probably intended) and the gate rejects the shape upstream.
7603 let d = dep_with_fonte(DepSource::Git {
7604 repo: "pleme-io/caixa-teia".into(),
7605 tag: Some("v0.1.0".into()),
7606 rev: None,
7607 branch: None,
7608 });
7609 let err = d.validate().unwrap_err();
7610 let DepError::FonteRepoShape { reason, .. } = err else {
7611 panic!("expected FonteRepoShape, got other variant");
7612 };
7613 assert!(
7614 reason.contains("must contain a `:`"),
7615 "reason must surface the missing-`:` arm, got {reason:?}"
7616 );
7617 assert!(
7618 reason.contains("github:"),
7619 "reason must name the canonical `github:` shorthand prefix, got {reason:?}"
7620 );
7621 }
7622
7623 #[test]
7624 fn validate_rejects_git_fonte_with_repo_leading_colon() {
7625 // The "empty scheme" footgun — `:repo ":foo"` has a zero-length
7626 // scheme that no git porcelain entry-point accepts. Pinned
7627 // separately from the missing-`:` arm because a value with a
7628 // leading `:` does technically contain a `:` separator; the
7629 // shape gate rejects on a dedicated arm so the diagnostic
7630 // names the specific footgun.
7631 let d = dep_with_fonte(DepSource::Git {
7632 repo: ":pleme-io/caixa-teia".into(),
7633 tag: Some("v0.1.0".into()),
7634 rev: None,
7635 branch: None,
7636 });
7637 let err = d.validate().unwrap_err();
7638 let DepError::FonteRepoShape { reason, .. } = err else {
7639 panic!("expected FonteRepoShape, got other variant");
7640 };
7641 assert!(
7642 reason.contains("must not start with `:`"),
7643 "reason must surface the leading-`:` arm, got {reason:?}"
7644 );
7645 }
7646
7647 #[test]
7648 fn validate_rejects_git_fonte_with_repo_too_long() {
7649 // The cap arm — a `:repo` value longer than
7650 // [`crate::render::GIT_REPO_URL_MAX_LEN`] (2048) bytes is
7651 // structurally untenable on every realistic landing site (the
7652 // resolver's `git clone` invocation, the future M4 CR
7653 // materializer's per-dep `repo:` axis); a value of that length
7654 // is almost certainly a paste-from-binary slug.
7655 let too_long = format!(
7656 "github:pleme-io/{}",
7657 "x".repeat(crate::render::GIT_REPO_URL_MAX_LEN)
7658 );
7659 let d = dep_with_fonte(DepSource::Git {
7660 repo: too_long.clone(),
7661 tag: Some("v0.1.0".into()),
7662 rev: None,
7663 branch: None,
7664 });
7665 let err = d.validate().unwrap_err();
7666 let DepError::FonteRepoShape { reason, .. } = err else {
7667 panic!("expected FonteRepoShape, got other variant");
7668 };
7669 assert!(
7670 reason.contains("2048"),
7671 "reason must name the cap, got {reason:?}"
7672 );
7673 }
7674
7675 #[test]
7676 fn validate_accepts_canonical_git_fonte_repo_shapes() {
7677 // The positive-control sweep: every documented author shape on
7678 // the `:fonte :repo` axis ([`crate::DepSource::Git`] doc comment)
7679 // must pass the value-shape gate. Pinned so a future tightening
7680 // (e.g. forbidding `http://` in favor of `https://`-only) surfaces
7681 // here as a structural decision. Each form is exercised with the
7682 // same canonical `:tag` pin so only the `:repo` axis varies.
7683 for repo in [
7684 // The pleme-io registry-shorthand convention — `github:org/repo`.
7685 "github:pleme-io/caixa-teia",
7686 // Other host-aliased shorthands (the resolver's pluggable
7687 // host-prefix table).
7688 "gitlab:pleme-io/caixa-teia",
7689 "codeberg:pleme-io/caixa-teia",
7690 "sourcehut:~pleme-io/caixa-teia",
7691 // Full HTTPS URL with and without `.git` suffix.
7692 "https://github.com/pleme-io/caixa-teia",
7693 "https://github.com/pleme-io/caixa-teia.git",
7694 // HTTP (rare; dev / mirror).
7695 "http://example.com/pleme-io/caixa-teia.git",
7696 // SSH URL.
7697 "ssh://git@github.com/pleme-io/caixa-teia.git",
7698 "ssh://git@git.example.com:2222/pleme-io/caixa-teia.git",
7699 // Scp-style SSH — the canonical `git@host:path` short form.
7700 "git@github.com:pleme-io/caixa-teia.git",
7701 "git@git.example.com:team/private.git",
7702 // Anonymous git protocol.
7703 "git://git.example.com/pleme-io/caixa-teia.git",
7704 // Local file URL (dev path).
7705 "file:///tmp/caixa-teia",
7706 ] {
7707 let d = dep_with_fonte(DepSource::Git {
7708 repo: repo.into(),
7709 tag: Some("v0.1.0".into()),
7710 rev: None,
7711 branch: None,
7712 });
7713 d.validate()
7714 .unwrap_or_else(|e| panic!("canonical repo {repo:?} must validate, got {e:?}"));
7715 }
7716 }
7717
7718 #[test]
7719 fn fonte_repo_empty_takes_precedence_over_shape() {
7720 // Order pin: the existing `FonteRepoEmpty` diagnostic (narrower
7721 // diagnostic; doesn't try to parse the URL shape) fires before
7722 // the new `FonteRepoShape` per-axis gate, so an empty `:repo`
7723 // keeps its narrower error message. Mirrors
7724 // `fonte_repo_empty_fires_before_pin_missing` (already pinned)
7725 // on the ordering layer.
7726 let d = dep_with_fonte(DepSource::Git {
7727 repo: String::new(),
7728 tag: Some("v0.1.0".into()),
7729 rev: None,
7730 branch: None,
7731 });
7732 let err = d.validate().unwrap_err();
7733 assert!(
7734 matches!(err, DepError::FonteRepoEmpty { .. }),
7735 "got {err:?}"
7736 );
7737 }
7738
7739 #[test]
7740 fn fonte_repo_shape_fires_before_pin_missing() {
7741 // Order pin: a malformed `:repo` value on a dep with no pin set
7742 // surfaces the `:repo` shape diagnostic (the more self-locating
7743 // axis — the `:repo` is the load-bearing identity of the source;
7744 // a missing pin is downstream from "do we even know the repo")
7745 // rather than collapsing onto the pin-missing diagnostic. The
7746 // shape gate runs inline before the pin enumeration in
7747 // `DepSource::validate`.
7748 let d = dep_with_fonte(DepSource::Git {
7749 repo: "pleme-io/caixa-teia".into(), // missing `:` separator
7750 tag: None,
7751 rev: None,
7752 branch: None,
7753 });
7754 let err = d.validate().unwrap_err();
7755 assert!(
7756 matches!(err, DepError::FonteRepoShape { .. }),
7757 "got {err:?}"
7758 );
7759 }
7760
7761 #[test]
7762 fn fonte_repo_shape_diagnostic_carries_offending_repo_verbatim() {
7763 // The diagnostic-shape pin: the error names the offending
7764 // `:repo` value verbatim plus a non-empty parser-shaped `reason`
7765 // so the author can grep their caixa.lisp without re-running
7766 // the build. Mirrors the diagnostic-shape sweep on every prior
7767 // value-shape gate (3f9d7a0, 6cbb900, c7d05ec, e70d213, be07fd5).
7768 let d = dep_with_fonte(DepSource::Git {
7769 repo: "pleme-io/caixa-teia".into(),
7770 tag: Some("v0.1.0".into()),
7771 rev: None,
7772 branch: None,
7773 });
7774 let err = d.validate().unwrap_err();
7775 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7776 panic!("expected FonteRepoShape, got other variant");
7777 };
7778 assert_eq!(nome, "caixa-teia");
7779 assert_eq!(repo, "pleme-io/caixa-teia");
7780 assert!(
7781 !reason.is_empty(),
7782 "FonteRepoShape `reason` must carry the predicate's wording verbatim"
7783 );
7784 }
7785
7786 #[test]
7787 fn validate_rejects_git_fonte_with_no_pin() {
7788 // The fail-before-pass-after pin for the canonical
7789 // `(:tipo git :repo "github:pleme-io/x")` shape with no
7790 // :tag/:rev/:branch — until this gate landed the resolver's
7791 // ResolveError::MissingPin surfaced at fetch time, far from the
7792 // source caixa.lisp. The new gate moves the check to validate
7793 // time and names the offending dep.
7794 let d = dep_with_fonte(DepSource::Git {
7795 repo: "github:pleme-io/caixa-teia".into(),
7796 tag: None,
7797 rev: None,
7798 branch: None,
7799 });
7800 let err = d.validate().unwrap_err();
7801 assert!(
7802 matches!(err, DepError::FontePinMissing { ref nome } if nome == "caixa-teia"),
7803 "got {err:?}"
7804 );
7805 }
7806
7807 #[test]
7808 fn validate_rejects_git_fonte_with_ambiguous_tag_and_branch() {
7809 // The canonical "pin drift" footgun: an author writes
7810 // `:tag "v1"` and later adds `:branch "main"` without removing
7811 // the :tag, and the resolver silently picks :tag (precedence
7812 // :rev > :tag > :branch). The :branch was dropped with no
7813 // diagnostic. The gate now rejects multi-pin shapes so the
7814 // author makes the precedence explicit at the source.
7815 let d = dep_with_fonte(DepSource::Git {
7816 repo: "github:pleme-io/caixa-teia".into(),
7817 tag: Some("v0.1.0".into()),
7818 rev: None,
7819 branch: Some("main".into()),
7820 });
7821 let err = d.validate().unwrap_err();
7822 let DepError::FontePinAmbiguous { nome, pins } = err else {
7823 panic!("expected FontePinAmbiguous");
7824 };
7825 assert_eq!(nome, "caixa-teia");
7826 assert!(pins.contains(":tag"));
7827 assert!(pins.contains(":branch"));
7828 assert!(!pins.contains(":rev"));
7829 }
7830
7831 #[test]
7832 fn validate_rejects_git_fonte_with_ambiguous_tag_and_rev() {
7833 // Sibling arm of the pin-drift footgun: :tag + :rev set
7834 // simultaneously. Pinned separately so a future relaxation
7835 // that only catches the (:tag, :branch) pair surfaces here.
7836 let d = dep_with_fonte(DepSource::Git {
7837 repo: "github:pleme-io/caixa-teia".into(),
7838 tag: Some("v0.1.0".into()),
7839 rev: Some("c0ffee".into()),
7840 branch: None,
7841 });
7842 let err = d.validate().unwrap_err();
7843 let DepError::FontePinAmbiguous { nome, pins } = err else {
7844 panic!("expected FontePinAmbiguous");
7845 };
7846 assert_eq!(nome, "caixa-teia");
7847 assert!(pins.contains(":tag"));
7848 assert!(pins.contains(":rev"));
7849 }
7850
7851 #[test]
7852 fn validate_rejects_git_fonte_with_all_three_pins() {
7853 // The maximal ambiguity case — every pin axis set. Pinned so a
7854 // future relaxation that only catches pairs surfaces here. The
7855 // diagnostic must enumerate every offending axis so the author
7856 // sees the full set, not just the first match.
7857 let d = dep_with_fonte(DepSource::Git {
7858 repo: "github:pleme-io/caixa-teia".into(),
7859 tag: Some("v0.1.0".into()),
7860 rev: Some("c0ffee".into()),
7861 branch: Some("main".into()),
7862 });
7863 let err = d.validate().unwrap_err();
7864 let DepError::FontePinAmbiguous { nome, pins } = err else {
7865 panic!("expected FontePinAmbiguous");
7866 };
7867 assert_eq!(nome, "caixa-teia");
7868 assert!(pins.contains(":tag"));
7869 assert!(pins.contains(":rev"));
7870 assert!(pins.contains(":branch"));
7871 }
7872
7873 #[test]
7874 fn validate_rejects_git_fonte_with_empty_tag_pin() {
7875 // The empty-pin arm: exactly one pin axis is `Some(_)`, but its
7876 // inner string is empty. Distinct from FontePinMissing (where
7877 // every axis is None) — pinned separately so a future
7878 // tightening collapsing them surfaces here as a structural
7879 // decision.
7880 let d = dep_with_fonte(DepSource::Git {
7881 repo: "github:pleme-io/caixa-teia".into(),
7882 tag: Some(String::new()),
7883 rev: None,
7884 branch: None,
7885 });
7886 let err = d.validate().unwrap_err();
7887 let DepError::FontePinEmpty { nome, pin } = err else {
7888 panic!("expected FontePinEmpty");
7889 };
7890 assert_eq!(nome, "caixa-teia");
7891 assert_eq!(pin, ":tag");
7892 }
7893
7894 #[test]
7895 fn validate_rejects_git_fonte_with_empty_rev_pin() {
7896 // Sibling arm — the empty-pin diagnostic names which axis
7897 // carries the empty value, so the author's grep target is
7898 // unambiguous.
7899 let d = dep_with_fonte(DepSource::Git {
7900 repo: "github:pleme-io/caixa-teia".into(),
7901 tag: None,
7902 rev: Some(String::new()),
7903 branch: None,
7904 });
7905 let err = d.validate().unwrap_err();
7906 let DepError::FontePinEmpty { nome, pin } = err else {
7907 panic!("expected FontePinEmpty");
7908 };
7909 assert_eq!(nome, "caixa-teia");
7910 assert_eq!(pin, ":rev");
7911 }
7912
7913 #[test]
7914 fn validate_rejects_path_fonte_with_empty_caminho() {
7915 // The fail-before-pass-after pin for `(:tipo path :caminho "")`:
7916 // until this gate landed the resolver's
7917 // ResolveError::MissingPath surfaced with `path: PathBuf("")` at
7918 // fetch time — not actionable. The new gate moves the check to
7919 // validate time and names the offending dep.
7920 let d = dep_with_fonte(DepSource::Path {
7921 caminho: String::new(),
7922 });
7923 let err = d.validate().unwrap_err();
7924 assert!(
7925 matches!(err, DepError::FonteCaminhoEmpty { ref nome } if nome == "caixa-teia"),
7926 "got {err:?}"
7927 );
7928 }
7929
7930 #[test]
7931 fn validate_rejects_path_fonte_with_absolute_caminho() {
7932 // The fail-before-pass-after pin for the absolute-`:caminho`
7933 // shape: `(:tipo path :caminho "/home/me/work/caixa-teia")`.
7934 // Until this gate landed an absolute `:caminho` silently
7935 // passed validate; the lacre pipeline embedded the
7936 // host-specific filesystem path verbatim in its
7937 // content-address (`conteudo: format!("path:{caminho}")`,
7938 // caixa-resolver/src/resolve.rs:189), so the BLAKE3 closure
7939 // differed per machine — the build succeeded but two CI
7940 // runners with different `${HOME}` layouts emitted two
7941 // distinct lacres for the byte-identical caixa, silently
7942 // breaking the THEORY.md §V.2 render-determinism contract
7943 // far from the source caixa.lisp. The new gate moves the
7944 // check to validate time and names the offending dep +
7945 // caminho verbatim.
7946 let d = dep_with_fonte(DepSource::Path {
7947 caminho: "/home/me/work/caixa-teia".into(),
7948 });
7949 let err = d.validate().unwrap_err();
7950 let DepError::FonteCaminhoAbsolute { nome, caminho } = err else {
7951 panic!("expected FonteCaminhoAbsolute, got other variant");
7952 };
7953 assert_eq!(nome, "caixa-teia");
7954 assert_eq!(caminho, "/home/me/work/caixa-teia");
7955 }
7956
7957 #[test]
7958 fn validate_accepts_path_fonte_with_parent_escape_caminho() {
7959 // The canonical sibling-workspace dep form
7960 // (`:caminho "../caixa-teia"`) remains accepted. The
7961 // absolute-path gate above is specifically narrower than the
7962 // shared [`crate::render::is_sandboxed_relative_path`]
7963 // predicate (which additionally forbids `..` traversal): a
7964 // local-path dep's canonical author surface is the in-tree
7965 // sibling-workspace path, so a full sandboxed-relative-path
7966 // lift would structurally reject every legitimate path-fonte
7967 // dep. Pinned so a future tightening to the full predicate
7968 // surfaces here as a structural decision, not a silent break.
7969 let d = dep_with_fonte(DepSource::Path {
7970 caminho: "../caixa-teia".into(),
7971 });
7972 d.validate().unwrap();
7973 }
7974
7975 #[test]
7976 fn validate_accepts_path_fonte_with_deeply_nested_relative_caminho() {
7977 // A multi-segment relative `:caminho`
7978 // (`"vendor/forks/caixa-teia"`) remains accepted — the
7979 // absolute-path gate brackets the host-layout-leaking shape
7980 // at the leading-`/` boundary only; every relative shape past
7981 // the empty arm continues to pass. Pinned alongside the
7982 // `..`-traversal positive control so a future tightening
7983 // surfaces the full set of legitimate relative forms here
7984 // rather than at a downstream consumer.
7985 let d = dep_with_fonte(DepSource::Path {
7986 caminho: "vendor/forks/caixa-teia".into(),
7987 });
7988 d.validate().unwrap();
7989 }
7990
7991 #[test]
7992 fn validate_rejects_path_fonte_with_tilde_prefix_caminho() {
7993 // The fail-before-pass-after pin for the tilde-expansion
7994 // `:caminho` shape: `(:tipo path :caminho "~/work/caixa-teia")`.
7995 // Until this gate landed the b94fd83 absolute arm let `~/foo`
7996 // through (`Path::is_absolute` returns false on a leading `~`
7997 // — the tilde is a shell-expansion convention, not a POSIX
7998 // path component), so the lacre embedded the value verbatim
7999 // and the resolver folded it through `Path::join` without
8000 // expansion, looking for a literal `./~/work/caixa-teia`
8001 // subdirectory and failing at resolve time with a
8002 // `No such file or directory` error far from the source
8003 // caixa.lisp. The new gate moves the check to validate time
8004 // and names the offending dep + caminho verbatim.
8005 let d = dep_with_fonte(DepSource::Path {
8006 caminho: "~/work/caixa-teia".into(),
8007 });
8008 let err = d.validate().unwrap_err();
8009 let DepError::FonteCaminhoTildeExpansion { nome, caminho } = err else {
8010 panic!("expected FonteCaminhoTildeExpansion, got {err:?}");
8011 };
8012 assert_eq!(nome, "caixa-teia");
8013 assert_eq!(caminho, "~/work/caixa-teia");
8014 }
8015
8016 #[test]
8017 fn validate_rejects_path_fonte_with_bare_tilde_caminho() {
8018 // The bare `~` form (canonical "I meant `$HOME` and forgot
8019 // the rest"): both the leading-tilde arm catches it and the
8020 // canonical-user-tilde shell idiom (`~alice/dev/caixa-teia`)
8021 // sweeps through the same arm. Pinned both to ensure the
8022 // gate doesn't narrow to `~/` only.
8023 for s in ["~", "~alice/dev/caixa-teia", "~/", "~root/work"] {
8024 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
8025 let err = d.validate().unwrap_err();
8026 assert!(
8027 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
8028 "{s:?} → {err:?}",
8029 );
8030 }
8031 }
8032
8033 #[test]
8034 fn validate_accepts_path_fonte_with_mid_path_tilde_caminho() {
8035 // The leading-`~` is the canonical shell-expansion footgun —
8036 // a tilde mid-path (`"../foo~bar/caixa-teia"` — the canonical
8037 // backup-file-suffix idiom) is a legitimate POSIX path byte
8038 // with no shell-expansion semantic at the leading position.
8039 // Pinned so the gate doesn't widen to a full no-tilde-anywhere
8040 // sweep that would break every legitimate-shape backup-file
8041 // path.
8042 let d = dep_with_fonte(DepSource::Path {
8043 caminho: "../foo~bar/caixa-teia".into(),
8044 });
8045 d.validate().unwrap();
8046 }
8047
8048 #[test]
8049 fn fonte_caminho_empty_fires_before_tilde_expansion() {
8050 // Cascade pin: the empty arm structurally precedes the
8051 // tilde arm (the bytes `""` and `"~"` don't overlap), but the
8052 // pin establishes the precedence at the diagnostic-shape
8053 // level should a future codec round-trip ever produce a
8054 // probe-as-both value. Mirrors the peer
8055 // `fonte_repo_empty_fires_before_pin_missing` cascade
8056 // discipline.
8057 let d = dep_with_fonte(DepSource::Path {
8058 caminho: String::new(),
8059 });
8060 let err = d.validate().unwrap_err();
8061 assert!(
8062 matches!(err, DepError::FonteCaminhoEmpty { .. }),
8063 "got {err:?}",
8064 );
8065 }
8066
8067 #[test]
8068 fn fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho() {
8069 // Diagnostic-shape pin (peer with
8070 // `validate_rejects_path_fonte_with_absolute_caminho`'s
8071 // payload assertion): the error's Display surfaces both the
8072 // offending `:nome` and the offending `:caminho` verbatim
8073 // so a `feira lint` run can render the diagnostic without
8074 // re-parsing.
8075 let d = dep_with_fonte(DepSource::Path {
8076 caminho: "~alice/dev/caixa-teia".into(),
8077 });
8078 let rendered = d.validate().unwrap_err().to_string();
8079 assert!(
8080 rendered.contains("caixa-teia"),
8081 "diagnostic must name the offending dep: {rendered}",
8082 );
8083 assert!(
8084 rendered.contains("~alice/dev/caixa-teia"),
8085 "diagnostic must quote the offending caminho: {rendered}",
8086 );
8087 assert!(
8088 rendered.contains('~'),
8089 "diagnostic must reference the tilde footgun: {rendered}",
8090 );
8091 }
8092
8093 #[test]
8094 fn validate_rejects_path_fonte_with_dollar_prefix_caminho() {
8095 // The fail-before-pass-after pin for the shell-variable-
8096 // expansion `:caminho` shape: `(:tipo path :caminho
8097 // "$HOME/work/caixa-teia")`. Until this gate landed the
8098 // b94fd83 absolute arm + the a5c248e tilde arm both let
8099 // `$HOME/foo` through (`Path::is_absolute` returns false on
8100 // a leading `$` — the `$` is a shell convention, not a POSIX
8101 // path component; `starts_with('~')` returns false too), so
8102 // the lacre embedded the value verbatim and the resolver
8103 // folded it through `Path::join` without `$`-expansion,
8104 // looking for a literal `./$HOME/work/caixa-teia`
8105 // subdirectory and failing at resolve time with a
8106 // `No such file or directory` error far from the source
8107 // caixa.lisp. The new gate moves the check to validate time
8108 // and names the offending dep + caminho verbatim.
8109 let d = dep_with_fonte(DepSource::Path {
8110 caminho: "$HOME/work/caixa-teia".into(),
8111 });
8112 let err = d.validate().unwrap_err();
8113 let DepError::FonteCaminhoVarExpansion { nome, caminho } = err else {
8114 panic!("expected FonteCaminhoVarExpansion, got {err:?}");
8115 };
8116 assert_eq!(nome, "caixa-teia");
8117 assert_eq!(caminho, "$HOME/work/caixa-teia");
8118 }
8119
8120 #[test]
8121 fn validate_rejects_path_fonte_with_dollar_brace_prefix_caminho() {
8122 // Sweep over every leading-`$` shape: the `${VAR}`-braced
8123 // form (canonical "paste-from-CI-manifest" footgun every
8124 // GitHub Actions / GitLab CI / Drone manifest carries on
8125 // `${WORKSPACE}`), the XDG idiom (`$XDG_CONFIG_HOME/caixa`,
8126 // canonical "I'm referencing a per-user config dir"),
8127 // and the bare `$` (canonical "I meant `$HOME` and forgot
8128 // the rest"). All shapes route through the same gate's
8129 // byte check. Pinned so the gate doesn't narrow to a
8130 // single shape (e.g. `$HOME/` only).
8131 for s in [
8132 "${HOME}/work/caixa-teia",
8133 "${WORKSPACE}/caixa-teia",
8134 "$XDG_CONFIG_HOME/caixa",
8135 "$",
8136 ] {
8137 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
8138 let err = d.validate().unwrap_err();
8139 assert!(
8140 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8141 "{s:?} → {err:?}",
8142 );
8143 }
8144 }
8145
8146 #[test]
8147 fn validate_rejects_path_fonte_with_mid_path_dollar_caminho() {
8148 // The `$` byte is the canonical shell-variable-expansion /
8149 // command-substitution / arithmetic-expansion sentinel and
8150 // is rejected at *every* position on the `:caminho` axis: the
8151 // leading arm surfaces `FonteCaminhoVarExpansion`, the
8152 // embedded arm surfaces `FonteCaminhoShellVariableExpansion`
8153 // (6620f39). Pinned so a future arm doesn't narrow the gate
8154 // back to the leading position and re-open the paste-from-
8155 // shell-one-liner `"../foo$HOME/bar"` / paste-from-CI-
8156 // manifest `"../foo${WORKSPACE}/bar"` / paste-from-shell-
8157 // prompt `"../foo$(whoami)/bar"` cross-idiom-leak surface on
8158 // the lacre content-address (`path:{caminho}`,
8159 // caixa-resolver/src/resolve.rs:189).
8160 let d = dep_with_fonte(DepSource::Path {
8161 caminho: "../foo$bar/caixa-teia".into(),
8162 });
8163 let err = d.validate().unwrap_err();
8164 assert!(
8165 matches!(
8166 err,
8167 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
8168 ),
8169 "got {err:?}",
8170 );
8171 }
8172
8173 #[test]
8174 fn fonte_caminho_tilde_fires_before_var_expansion() {
8175 // Cascade pin: the tilde arm structurally precedes the var
8176 // arm (the bytes `~` and `$` don't overlap at the leading
8177 // position), but the pin establishes the precedence at the
8178 // diagnostic-shape level should a future codec round-trip
8179 // ever produce a probe-as-both value. Mirrors the peer
8180 // `fonte_caminho_empty_fires_before_tilde_expansion` cascade
8181 // discipline on the immediate-predecessor arm.
8182 let d = dep_with_fonte(DepSource::Path {
8183 caminho: "~/work/caixa-teia".into(),
8184 });
8185 let err = d.validate().unwrap_err();
8186 assert!(
8187 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
8188 "got {err:?}",
8189 );
8190 }
8191
8192 #[test]
8193 fn fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho() {
8194 // Diagnostic-shape pin (peer with
8195 // `fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho`'s
8196 // payload assertion on the immediate-predecessor arm): the
8197 // error's Display surfaces both the offending `:nome` and
8198 // the offending `:caminho` verbatim plus the `$` footgun
8199 // character itself so a `feira lint` run can render the
8200 // diagnostic without re-parsing.
8201 let d = dep_with_fonte(DepSource::Path {
8202 caminho: "${WORKSPACE}/caixa-teia".into(),
8203 });
8204 let rendered = d.validate().unwrap_err().to_string();
8205 assert!(
8206 rendered.contains("caixa-teia"),
8207 "diagnostic must name the offending dep: {rendered}",
8208 );
8209 assert!(
8210 rendered.contains("${WORKSPACE}/caixa-teia"),
8211 "diagnostic must quote the offending caminho: {rendered}",
8212 );
8213 assert!(
8214 rendered.contains('$'),
8215 "diagnostic must reference the dollar footgun: {rendered}",
8216 );
8217 }
8218
8219 #[test]
8220 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_nul() {
8221 // The fail-before-pass-after pin for the load-bearing NUL byte:
8222 // POSIX paths cannot contain `0x00` (every `std::fs` syscall
8223 // routes the path through `CString::new` which fails with
8224 // `NulError`); until this gate landed a `:caminho
8225 // "../caixa\0teia"` silently passed validate, the lacre
8226 // pipeline embedded the value verbatim, and the failure
8227 // surfaced at the resolver's `Path::join` → `CString::new`
8228 // boundary with a non-self-locating `NulError` far from the
8229 // source caixa.lisp. The new gate moves the check to validate
8230 // time and names the offending dep + caminho + offending byte
8231 // verbatim.
8232 let d = dep_with_fonte(DepSource::Path {
8233 caminho: "../caixa\0teia".into(),
8234 });
8235 let err = d.validate().unwrap_err();
8236 let DepError::FonteCaminhoControlChar {
8237 nome,
8238 caminho,
8239 byte,
8240 } = err
8241 else {
8242 panic!("expected FonteCaminhoControlChar, got {err:?}");
8243 };
8244 assert_eq!(nome, "caixa-teia");
8245 assert_eq!(caminho, "../caixa\0teia");
8246 assert_eq!(byte, 0x00);
8247 }
8248
8249 #[test]
8250 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_newline() {
8251 // The canonical paste-from-multiline-doc footgun on `:caminho`
8252 // — author copies `"../caixa-teia\n"` (trailing newline) out
8253 // of a multi-line code-fence or, worse, a `:caminho
8254 // "../caixa-teia\nrm -rf /"` value (CRLF-at-subprocess-argument
8255 // injection sibling on the path axis the `is_git_repo_url`
8256 // control-char arm already closes on `:repo`). Pinned
8257 // separately from the NUL arm so a future relaxation that
8258 // catches one but not the other surfaces here.
8259 let d = dep_with_fonte(DepSource::Path {
8260 caminho: "../caixa-teia\n".into(),
8261 });
8262 let err = d.validate().unwrap_err();
8263 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8264 panic!("expected FonteCaminhoControlChar, got {err:?}");
8265 };
8266 assert_eq!(byte, 0x0A);
8267 }
8268
8269 #[test]
8270 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_carriage_return() {
8271 // The CRLF sibling of the LF arm — Windows-line-ending
8272 // paste-from-multiline-doc on a `\r\n`-terminated buffer
8273 // leaves a stray `\r` mid-string after the LF strip. Pinned
8274 // separately from the LF arm so a future relaxation that
8275 // only catches LF surfaces here.
8276 let d = dep_with_fonte(DepSource::Path {
8277 caminho: "../caixa-teia\r".into(),
8278 });
8279 let err = d.validate().unwrap_err();
8280 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8281 panic!("expected FonteCaminhoControlChar, got {err:?}");
8282 };
8283 assert_eq!(byte, 0x0D);
8284 }
8285
8286 #[test]
8287 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_tab() {
8288 // The canonical paste-from-aligned-table footgun — a `\t`
8289 // mid-`:caminho` is invisible in most editors but rides
8290 // through the lacre's content-address verbatim, so two
8291 // paste-from-distinct-tables (one editor strips tabs, one
8292 // preserves them) yield divergent lacres for the byte-
8293 // identical-looking caixa. Pinned separately from the
8294 // whitespace-shaped LF/CR arms so a future relaxation that
8295 // narrows to line-terminator-only surfaces here.
8296 let d = dep_with_fonte(DepSource::Path {
8297 caminho: "../caixa\tteia".into(),
8298 });
8299 let err = d.validate().unwrap_err();
8300 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8301 panic!("expected FonteCaminhoControlChar, got {err:?}");
8302 };
8303 assert_eq!(byte, 0x09);
8304 }
8305
8306 #[test]
8307 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_del() {
8308 // The DEL byte (`0x7F`) closes the upper-end paste-from-
8309 // binary-blob footgun — the gate's contract is `b < 0x20 ||
8310 // b == 0x7F`, matching the `is_git_repo_url` /
8311 // `is_git_ref_name` predicates' control-char arms. Pinned
8312 // separately from the lower-range arms so a future narrowing
8313 // to `< 0x20` only surfaces here.
8314 let d = dep_with_fonte(DepSource::Path {
8315 caminho: "../caixa\x7fteia".into(),
8316 });
8317 let err = d.validate().unwrap_err();
8318 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8319 panic!("expected FonteCaminhoControlChar, got {err:?}");
8320 };
8321 assert_eq!(byte, 0x7F);
8322 }
8323
8324 #[test]
8325 fn validate_accepts_path_fonte_with_caminho_carrying_high_bit_utf8() {
8326 // The control-byte arm targets `0x00..=0x1F` + `0x7F` only —
8327 // high-bit / non-ASCII UTF-8 bytes are not gated. POSIX paths
8328 // are opaque byte sequences and UTF-8 multi-byte sequences
8329 // are a legitimate filename shape (the `café-teia/foo` idiom).
8330 // Pinned so the gate doesn't widen to a full ASCII-only sweep
8331 // that would break every legitimate-shape UTF-8 path.
8332 let d = dep_with_fonte(DepSource::Path {
8333 caminho: "../café-teia/foo".into(),
8334 });
8335 d.validate().unwrap();
8336 }
8337
8338 #[test]
8339 fn fonte_caminho_var_fires_before_control_char() {
8340 // Cascade pin: the var-expansion arm structurally precedes the
8341 // control-char arm. A value like `"$\n"` probes positive on
8342 // both arms (`starts_with('$')` and contains LF), but the
8343 // narrower leading-byte diagnostic (`FonteCaminhoVarExpansion`)
8344 // wins so the author sees the more self-locating shell-
8345 // expansion arm first. Mirrors the
8346 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8347 // discipline on the immediate-predecessor arm.
8348 let d = dep_with_fonte(DepSource::Path {
8349 caminho: "$HOME\n".into(),
8350 });
8351 let err = d.validate().unwrap_err();
8352 assert!(
8353 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8354 "got {err:?}",
8355 );
8356 }
8357
8358 #[test]
8359 fn validate_rejects_path_fonte_with_leading_space_caminho() {
8360 // The fail-before-pass-after pin for the leading ASCII space
8361 // `:caminho` shape: `(:tipo path :caminho " ../caixa-teia")`.
8362 // Until this gate landed the b94fd83 absolute arm + the a5c248e
8363 // tilde arm + the f4efe9c var arm + the d624c8d control-byte arm
8364 // all let `" ../caixa-teia"` through: `Path::is_absolute` returns
8365 // false on a leading space (the leading byte is `0x20`, not `0x2F`),
8366 // `starts_with('~')` / `starts_with('$')` return false, and `0x20`
8367 // is not in the `0x00..=0x1F` plus `0x7F` control-byte set (the
8368 // four ASCII whitespace bytes `0x09` tab, `0x0A` LF, `0x0D` CR
8369 // are caught, but the most common whitespace `0x20` space is
8370 // not). The lacre embedded the value verbatim and the resolver
8371 // folded it through `Path::join` looking for a literal `./ ../
8372 // caixa-teia` subdirectory and failing at resolve time with a
8373 // non-self-locating `No such file or directory` error far from
8374 // the source caixa.lisp. The new gate moves the check to
8375 // validate time and names the offending dep + caminho verbatim.
8376 let d = dep_with_fonte(DepSource::Path {
8377 caminho: " ../caixa-teia".into(),
8378 });
8379 let err = d.validate().unwrap_err();
8380 let DepError::FonteCaminhoLeadingWhitespace { nome, caminho } = err else {
8381 panic!("expected FonteCaminhoLeadingWhitespace, got {err:?}");
8382 };
8383 assert_eq!(nome, "caixa-teia");
8384 assert_eq!(caminho, " ../caixa-teia");
8385 }
8386
8387 #[test]
8388 fn validate_rejects_path_fonte_with_multiple_leading_spaces_caminho() {
8389 // The aligned-doc paste footgun sweep: more than one leading
8390 // space (`" ../caixa-teia"` — the canonical "I selected the
8391 // aligned column from a four-`:fonte`-entry `:deps` block"
8392 // paste) routes through the same gate's `starts_with(' ')`
8393 // byte check. Pinned so the gate doesn't narrow to a
8394 // single-space prefix.
8395 let d = dep_with_fonte(DepSource::Path {
8396 caminho: " ../caixa-teia".into(),
8397 });
8398 let err = d.validate().unwrap_err();
8399 assert!(
8400 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8401 "got {err:?}",
8402 );
8403 }
8404
8405 #[test]
8406 fn validate_accepts_path_fonte_with_mid_path_space_caminho() {
8407 // The leading-space is the canonical paste-from-aligned-doc
8408 // footgun — a space mid-path (`"../my dir/caixa-teia"` — the
8409 // canonical "I have a directory with a space in its name"
8410 // idiom; ASCII `0x20` is a valid POSIX filename byte) is a
8411 // legitimate path with no whitespace-leak semantic at the
8412 // non-leading position. Pinned so the gate doesn't widen to a
8413 // full no-space-anywhere sweep that would break every
8414 // legitimate-shape space-in-filename path.
8415 let d = dep_with_fonte(DepSource::Path {
8416 caminho: "../my dir/caixa-teia".into(),
8417 });
8418 d.validate().unwrap();
8419 }
8420
8421 #[test]
8422 fn fonte_caminho_var_fires_before_leading_whitespace() {
8423 // Cascade pin: the var-expansion arm structurally precedes the
8424 // leading-whitespace arm. A value like `"$ "` would probe positive
8425 // on var (`starts_with('$')`) but the leading-byte arms walk
8426 // left-to-right so the var arm fires on the leading `$` before
8427 // the leading-whitespace arm probes. Mirrors the
8428 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8429 // discipline on the immediate-predecessor arms.
8430 let d = dep_with_fonte(DepSource::Path {
8431 caminho: "$VAR".into(),
8432 });
8433 let err = d.validate().unwrap_err();
8434 assert!(
8435 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8436 "got {err:?}",
8437 );
8438 }
8439
8440 #[test]
8441 fn fonte_caminho_leading_whitespace_fires_before_control_char() {
8442 // Cascade pin: the leading-whitespace arm structurally precedes
8443 // the control-char arm. A value like `" ../foo\n"` probes
8444 // positive on both (starts with space AND contains LF), but
8445 // the narrower leading-byte diagnostic
8446 // (`FonteCaminhoLeadingWhitespace`) wins so the author sees the
8447 // more self-locating paste-from-aligned-doc arm first. Mirrors
8448 // the `fonte_caminho_var_fires_before_control_char` cascade
8449 // discipline on the immediate-predecessor arm.
8450 let d = dep_with_fonte(DepSource::Path {
8451 caminho: " ../foo\n".into(),
8452 });
8453 let err = d.validate().unwrap_err();
8454 assert!(
8455 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8456 "got {err:?}",
8457 );
8458 }
8459
8460 #[test]
8461 fn fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho() {
8462 // Diagnostic-shape pin (peer with
8463 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8464 // payload assertion on the immediate-predecessor arm): the
8465 // error's Display surfaces both the offending `:nome` and the
8466 // offending `:caminho` verbatim, so a `feira lint` run can
8467 // render the diagnostic without re-parsing and the author can
8468 // grep their caixa.lisp for `:caminho "<value>"` and fix it in
8469 // one edit.
8470 let d = dep_with_fonte(DepSource::Path {
8471 caminho: " ../caixa-teia".into(),
8472 });
8473 let rendered = d.validate().unwrap_err().to_string();
8474 assert!(
8475 rendered.contains("caixa-teia"),
8476 "diagnostic must name the offending dep: {rendered}",
8477 );
8478 assert!(
8479 rendered.contains(" ../caixa-teia"),
8480 "diagnostic must quote the offending caminho: {rendered}",
8481 );
8482 assert!(
8483 rendered.contains("space"),
8484 "diagnostic must name the space footgun: {rendered}",
8485 );
8486 }
8487
8488 #[test]
8489 fn fonte_caminho_absolute_fires_before_control_char() {
8490 // Cascade pin on the sibling leading-byte arm: a leading `/`
8491 // value with embedded control byte (`"/etc/passwd\n"`) routes
8492 // through `FonteCaminhoAbsolute` not `FonteCaminhoControlChar`
8493 // — the host-layout-leak diagnostic is the load-bearing axis,
8494 // the control byte is the secondary observation. Same precedence
8495 // logic on every prior leading-byte arm.
8496 let d = dep_with_fonte(DepSource::Path {
8497 caminho: "/etc/passwd\n".into(),
8498 });
8499 let err = d.validate().unwrap_err();
8500 assert!(
8501 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8502 "got {err:?}",
8503 );
8504 }
8505
8506 #[test]
8507 fn validate_rejects_path_fonte_with_leading_hyphen_caminho() {
8508 // The fail-before-pass-after pin for the leading-`-` CLI-arg-
8509 // injection `:caminho` shape sweep. Until this gate landed
8510 // every prior leading-byte arm passed a leading-`-` value
8511 // through: `Path::is_absolute` returns false on `-` (the
8512 // leading byte is `0x2D`, not `0x2F`), `starts_with('~')` /
8513 // `starts_with('$')` / `starts_with(' ')` all return false,
8514 // and `0x2D` sits outside the control-byte set. The lacre
8515 // embedded the value verbatim and the resolver folded it
8516 // through `Path::join` looking for a literal `./-rf` /
8517 // `./-C` / `./--upload-pack=…` subdirectory; the failure at
8518 // `Path::join` time is non-self-locating but harmless, while
8519 // the failure at every downstream `git -C {caminho}` /
8520 // `terraform -chdir={caminho}` / `find {caminho}` shell-out
8521 // is arbitrary-CLI-arg-injection because none of those
8522 // porcelains carry a `--` argument-list terminator between
8523 // the flag block and the path argument. The new arm moves the
8524 // rejection to `Caixa::from_lisp` boundary time and names
8525 // the offending dep + caminho verbatim.
8526 //
8527 // Sweep spans the canonical CLI-arg-injection shapes matching
8528 // the peer sweep on the sibling `is_git_ref_name` /
8529 // `is_git_repo_url` axes: short-flag `-rf` (the `rm -rf` /
8530 // `find -rf` reinterpretation vector), `-C` (the `git -C`
8531 // change-directory-config-injection paste), long-flag
8532 // `--upload-pack=cat /etc/passwd` (the canonical
8533 // arbitrary-command-execution vector on every git porcelain
8534 // entry point), git-config-injection `--config=core.merge=ours`,
8535 // and the degenerate single-byte `-` value.
8536 for caminho in [
8537 "-rf",
8538 "-C",
8539 "--upload-pack=cat /etc/passwd",
8540 "--config=core.merge=ours",
8541 "-",
8542 ] {
8543 let d = dep_with_fonte(DepSource::Path {
8544 caminho: caminho.into(),
8545 });
8546 let err = d.validate().unwrap_err();
8547 let DepError::FonteCaminhoLeadingHyphen { nome, caminho: got } = err else {
8548 panic!("expected FonteCaminhoLeadingHyphen for {caminho:?}, got {err:?}");
8549 };
8550 assert_eq!(nome, "caixa-teia");
8551 assert_eq!(got, caminho);
8552 }
8553 }
8554
8555 #[test]
8556 fn validate_accepts_path_fonte_with_mid_path_hyphen_caminho() {
8557 // The leading-`-` is the canonical CLI-arg-injection footgun
8558 // — a `-` anywhere else in the path (`"../caixa-teia"` — the
8559 // canonical kebab-separator-between-alphanumeric-segments
8560 // shape every DNS-1123-shaped caixa name carries; `"../-hidden"`
8561 // — a mid-path segment starting with `-`, still a legitimate
8562 // POSIX filename byte at that non-leading position because the
8563 // subprocess reads the whole `{caminho}` value as one positional
8564 // argument, so only the very first byte of the composite path
8565 // string is at the CLI-arg-injection boundary) is a legitimate
8566 // path with no CLI-flag-reinterpretation semantic at the non-
8567 // leading position of the top-level value. Pinned so the gate
8568 // doesn't widen to a full no-`-`-anywhere sweep that would
8569 // break every legitimate-shape kebab-in-filename path (i.e.
8570 // essentially every sibling-workspace caixa dep).
8571 for caminho in [
8572 "../caixa-teia",
8573 "../caixa-teia/-hidden",
8574 "./my-lib",
8575 "../foo-bar/baz",
8576 ] {
8577 let d = dep_with_fonte(DepSource::Path {
8578 caminho: caminho.into(),
8579 });
8580 d.validate()
8581 .unwrap_or_else(|e| panic!("mid-path `-` caminho {caminho:?} must pass: {e:?}"));
8582 }
8583 }
8584
8585 #[test]
8586 fn fonte_caminho_leading_whitespace_fires_before_leading_hyphen() {
8587 // Cascade pin: the leading-whitespace arm structurally precedes
8588 // the leading-hyphen arm. A value like `" -rf"` probes positive
8589 // on both (leading space AND, one byte in, a `-` — though the
8590 // leading-hyphen arm probes only the very first byte so it
8591 // wouldn't fire on this value; the pin instead documents the
8592 // arm order on the more common "leading space then a hyphen"
8593 // paste-from-aligned-doc paste-flag-shell-one-liner idiom).
8594 // The narrower leading-space diagnostic (the paste-from-aligned-
8595 // doc footgun) wins so the author sees the more self-locating
8596 // whitespace arm first. Mirrors the
8597 // `fonte_caminho_var_fires_before_leading_whitespace` cascade
8598 // discipline on the immediate-predecessor arm.
8599 let d = dep_with_fonte(DepSource::Path {
8600 caminho: " -rf".into(),
8601 });
8602 let err = d.validate().unwrap_err();
8603 assert!(
8604 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8605 "got {err:?}",
8606 );
8607 }
8608
8609 #[test]
8610 fn fonte_caminho_leading_hyphen_fires_before_control_char() {
8611 // Cascade pin: the leading-hyphen arm structurally precedes
8612 // the control-char arm. A value like `"-rf\n"` probes positive
8613 // on both (starts with `-` AND contains LF), but the narrower
8614 // leading-byte diagnostic (`FonteCaminhoLeadingHyphen`) wins so
8615 // the author sees the more self-locating CLI-arg-injection arm
8616 // first. Mirrors the
8617 // `fonte_caminho_leading_whitespace_fires_before_control_char`
8618 // cascade discipline on the immediate-predecessor arm.
8619 let d = dep_with_fonte(DepSource::Path {
8620 caminho: "-rf\n".into(),
8621 });
8622 let err = d.validate().unwrap_err();
8623 assert!(
8624 matches!(err, DepError::FonteCaminhoLeadingHyphen { .. }),
8625 "got {err:?}",
8626 );
8627 }
8628
8629 #[test]
8630 fn fonte_caminho_leading_hyphen_diagnostic_carries_offending_dep_and_caminho() {
8631 // Diagnostic-shape pin (peer with
8632 // `fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho`'s
8633 // payload assertion on the immediate-predecessor arm): the
8634 // error's Display surfaces both the offending `:nome` and the
8635 // offending `:caminho` verbatim plus the CLI-argument-injection
8636 // vocabulary, so a `feira lint` run can render the diagnostic
8637 // without re-parsing and the author can grep their caixa.lisp
8638 // for `:caminho "<value>"` and fix it in one edit.
8639 let d = dep_with_fonte(DepSource::Path {
8640 caminho: "--upload-pack=cat /etc/passwd".into(),
8641 });
8642 let rendered = d.validate().unwrap_err().to_string();
8643 assert!(
8644 rendered.contains("caixa-teia"),
8645 "diagnostic must name the offending dep: {rendered}",
8646 );
8647 assert!(
8648 rendered.contains("--upload-pack=cat /etc/passwd"),
8649 "diagnostic must quote the offending caminho: {rendered}",
8650 );
8651 assert!(
8652 rendered.contains("CLI-argument-injection"),
8653 "diagnostic must name the CLI-argument-injection vector: {rendered}",
8654 );
8655 assert!(
8656 rendered.contains("`-`"),
8657 "diagnostic must name the offending byte: {rendered}",
8658 );
8659 }
8660
8661 #[test]
8662 fn fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte() {
8663 // Diagnostic-shape pin (peer with
8664 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8665 // payload assertion on the immediate-predecessor arm): the
8666 // error's Display surfaces the offending `:nome`, the
8667 // offending `:caminho` verbatim, and the offending byte in
8668 // hex form (`0x09` for tab) so a `feira lint` run can render
8669 // the diagnostic without re-parsing.
8670 let d = dep_with_fonte(DepSource::Path {
8671 caminho: "../caixa\tteia".into(),
8672 });
8673 let rendered = d.validate().unwrap_err().to_string();
8674 assert!(
8675 rendered.contains("caixa-teia"),
8676 "diagnostic must name the offending dep: {rendered}",
8677 );
8678 assert!(
8679 rendered.contains("../caixa\tteia"),
8680 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8681 );
8682 assert!(
8683 rendered.contains("0x09"),
8684 "diagnostic must name the offending byte in hex: {rendered:?}",
8685 );
8686 }
8687
8688 #[test]
8689 fn validate_rejects_path_fonte_with_caminho_carrying_backslash() {
8690 // The fail-before-pass-after pin for the canonical Windows-
8691 // path-separator paste footgun: an author who pastes a path
8692 // from Windows-Explorer's `Copy as path`, PowerShell's
8693 // `Get-Location`, or any CMD/Cygwin/MSYS shell prompt
8694 // produces `..\caixa-teia`-shape values that silently passed
8695 // every prior arm (`Path::is_absolute("..\\caixa-teia")` is
8696 // false; `\` is neither a leading-byte sentinel nor a
8697 // control byte). On POSIX resolvers the value rides through
8698 // `Path::join` as a literal directory name and fails at
8699 // resolve time with `No such file or directory`; on Windows
8700 // resolvers the value resolves to the parent's sibling — two
8701 // distinct directories for the byte-identical caixa.lisp.
8702 // The new arm moves the rejection to validate time and names
8703 // the offending dep + caminho verbatim.
8704 let d = dep_with_fonte(DepSource::Path {
8705 caminho: "..\\caixa-teia".into(),
8706 });
8707 let err = d.validate().unwrap_err();
8708 let DepError::FonteCaminhoBackslash { nome, caminho } = err else {
8709 panic!("expected FonteCaminhoBackslash, got {err:?}");
8710 };
8711 assert_eq!(nome, "caixa-teia");
8712 assert_eq!(caminho, "..\\caixa-teia");
8713 }
8714
8715 #[test]
8716 fn validate_rejects_path_fonte_with_caminho_carrying_windows_drive_letter() {
8717 // The Windows drive-letter paste shape (`C:\work\caixa-teia`
8718 // out of Explorer / `cd`-and-`pwd`-on-Windows). On POSIX
8719 // hosts `Path::is_absolute("C:\\work\\caixa-teia")` returns
8720 // false (POSIX absolute paths start with `/`, drive letters
8721 // are not a POSIX concept), so the b94fd83 absolute arm
8722 // doesn't fire; the value contains `\` bytes that this arm
8723 // now catches with the more self-locating Windows-path-
8724 // separator diagnostic. Pinned separately from the bare
8725 // `..\caixa-teia` shape so a future arm that targets only
8726 // leading-`..\` doesn't regress the drive-letter coverage.
8727 let d = dep_with_fonte(DepSource::Path {
8728 caminho: "C:\\work\\caixa-teia".into(),
8729 });
8730 let err = d.validate().unwrap_err();
8731 assert!(
8732 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8733 "got {err:?}",
8734 );
8735 }
8736
8737 #[test]
8738 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backslash() {
8739 // The trailing-`\` shape (`..\caixa-teia\` — the canonical
8740 // PowerShell tab-completion-on-a-directory append). Pinned
8741 // separately from the embedded-`\` shape so the gate's
8742 // contract is "any `\` anywhere", not "any `\` not at end".
8743 let d = dep_with_fonte(DepSource::Path {
8744 caminho: "..\\caixa-teia\\".into(),
8745 });
8746 let err = d.validate().unwrap_err();
8747 assert!(
8748 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8749 "got {err:?}",
8750 );
8751 }
8752
8753 #[test]
8754 fn validate_accepts_path_fonte_with_caminho_carrying_legitimate_forward_slash() {
8755 // The positive-control pin: the gate targets `\` only,
8756 // never `/`. The canonical relative POSIX path
8757 // (`../caixa-teia/foo/bar`) must continue to validate cleanly
8758 // so legitimate nested-directory deps aren't broken. Pinned
8759 // so the gate doesn't accidentally widen to a "no path
8760 // separators at all" sweep.
8761 let d = dep_with_fonte(DepSource::Path {
8762 caminho: "../caixa-teia/foo/bar".into(),
8763 });
8764 d.validate().unwrap();
8765 }
8766
8767 #[test]
8768 fn fonte_caminho_control_char_fires_before_backslash() {
8769 // Cascade pin: the control-char arm structurally precedes the
8770 // backslash arm. A value like `"..\caixa\0teia"` probes
8771 // positive on both (`\` byte + NUL byte), but the control-
8772 // char diagnostic wins so the author sees the more self-
8773 // locating POSIX-syscall-rejected-byte diagnostic first
8774 // (NUL outright breaks `CString::new` at every `std::fs`
8775 // syscall boundary; the `\` divergence is the cross-OS-
8776 // separator axis). Mirrors the
8777 // `fonte_caminho_var_fires_before_control_char` cascade
8778 // discipline on the immediate-predecessor arm.
8779 let d = dep_with_fonte(DepSource::Path {
8780 caminho: "..\\caixa\0teia".into(),
8781 });
8782 let err = d.validate().unwrap_err();
8783 assert!(
8784 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8785 "got {err:?}",
8786 );
8787 }
8788
8789 #[test]
8790 fn fonte_caminho_absolute_fires_before_backslash() {
8791 // Cascade pin on the load-bearing leading-byte arm: a leading
8792 // `/` value with embedded `\` (`/etc/passwd\foo`) routes
8793 // through `FonteCaminhoAbsolute` not `FonteCaminhoBackslash`
8794 // — the host-layout-leak diagnostic is the load-bearing
8795 // axis, the `\` byte is the secondary observation. Same
8796 // precedence logic as every prior leading-byte arm.
8797 let d = dep_with_fonte(DepSource::Path {
8798 caminho: "/etc/passwd\\foo".into(),
8799 });
8800 let err = d.validate().unwrap_err();
8801 assert!(
8802 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8803 "got {err:?}",
8804 );
8805 }
8806
8807 #[test]
8808 fn fonte_caminho_var_fires_before_backslash() {
8809 // Cascade pin on the var-expansion arm: a leading-`$` value
8810 // with embedded `\` (`$WORKSPACE\caixa-teia` — the canonical
8811 // PowerShell-env-var paste-from-CI-manifest footgun) routes
8812 // through `FonteCaminhoVarExpansion` not `FonteCaminhoBackslash`.
8813 // The shell-expansion diagnostic is the more self-locating
8814 // axis since both the leading `$` and the embedded `\`
8815 // are Windows-shell artifacts but the `$` is the root-cause
8816 // surface (an author who removes the `$` is likely to leave
8817 // the `\` too).
8818 let d = dep_with_fonte(DepSource::Path {
8819 caminho: "$WORKSPACE\\caixa-teia".into(),
8820 });
8821 let err = d.validate().unwrap_err();
8822 assert!(
8823 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8824 "got {err:?}",
8825 );
8826 }
8827
8828 #[test]
8829 fn fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho() {
8830 // Diagnostic-shape pin (peer with the prior
8831 // `fonte_caminho_*_diagnostic_carries_*` payload assertions
8832 // on every preceding arm): the error's Display surfaces the
8833 // offending `:nome` and the offending `:caminho` verbatim
8834 // so a `feira lint` run can render the diagnostic without
8835 // re-parsing.
8836 let d = dep_with_fonte(DepSource::Path {
8837 caminho: "..\\caixa-teia".into(),
8838 });
8839 let rendered = d.validate().unwrap_err().to_string();
8840 assert!(
8841 rendered.contains("caixa-teia"),
8842 "diagnostic must name the offending dep: {rendered}",
8843 );
8844 assert!(
8845 rendered.contains("..\\caixa-teia"),
8846 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8847 );
8848 assert!(
8849 rendered.contains('\\'),
8850 "diagnostic must reference the backslash footgun: {rendered:?}",
8851 );
8852 }
8853
8854 #[test]
8855 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_slash() {
8856 // The fail-before-pass-after pin for the canonical trailing-`/`
8857 // paste footgun: an author who shell-tab-completes a sibling
8858 // directory (every interactive shell — bash/zsh/fish/nushell —
8859 // appends `/` on tab-completing a directory) produces
8860 // `"../caixa-teia/"`-shape values that silently passed every
8861 // prior arm (the leading byte is `.`, no control bytes, no
8862 // backslash). `Path::join` resolves both shapes to the same
8863 // directory at the resolver, but the lacre embeds the value
8864 // verbatim and the BLAKE3 closures diverge across two
8865 // workstations whose authors differ only in tab-completion
8866 // habits.
8867 let d = dep_with_fonte(DepSource::Path {
8868 caminho: "../caixa-teia/".into(),
8869 });
8870 let err = d.validate().unwrap_err();
8871 let DepError::FonteCaminhoTrailingSlash { nome, caminho } = err else {
8872 panic!("expected FonteCaminhoTrailingSlash, got {err:?}");
8873 };
8874 assert_eq!(nome, "caixa-teia");
8875 assert_eq!(caminho, "../caixa-teia/");
8876 }
8877
8878 #[test]
8879 fn validate_rejects_path_fonte_with_caminho_carrying_bare_dot_slash() {
8880 // The `"./"` shape (the canonical "I meant the caixa.lisp's own
8881 // directory and tab-completed it" footgun). Pinned separately
8882 // from the canonical `"../caixa-teia/"` shape so the gate's
8883 // contract is "any trailing `/`", not "trailing `/` after a leaf
8884 // name".
8885 let d = dep_with_fonte(DepSource::Path {
8886 caminho: "./".into(),
8887 });
8888 let err = d.validate().unwrap_err();
8889 assert!(
8890 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8891 "got {err:?}",
8892 );
8893 }
8894
8895 #[test]
8896 fn validate_rejects_path_fonte_with_caminho_carrying_consecutive_trailing_slashes() {
8897 // The `"foo//"` shape (the canonical "I pasted from a CI manifest
8898 // that double-templated `${VAR}/` over an already-`/`-suffixed
8899 // path" footgun). The gate fires on the last byte being `/`
8900 // regardless of how many `/` precede it; the arm contract is
8901 // "the value ends with `/`", structurally.
8902 let d = dep_with_fonte(DepSource::Path {
8903 caminho: "../caixa-teia//".into(),
8904 });
8905 let err = d.validate().unwrap_err();
8906 assert!(
8907 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8908 "got {err:?}",
8909 );
8910 }
8911
8912 #[test]
8913 fn validate_rejects_path_fonte_with_caminho_carrying_dotdot_trailing_slash() {
8914 // The `"../"` shape (the canonical "I want the parent" tab-
8915 // completion footgun on a bare `..` path). Pinned separately so
8916 // the gate doesn't accidentally narrow to "trailing `/` only on
8917 // multi-segment paths".
8918 let d = dep_with_fonte(DepSource::Path {
8919 caminho: "../".into(),
8920 });
8921 let err = d.validate().unwrap_err();
8922 assert!(
8923 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8924 "got {err:?}",
8925 );
8926 }
8927
8928 #[test]
8929 fn validate_accepts_path_fonte_with_caminho_carrying_internal_slashes() {
8930 // The positive-control pin: the gate targets the trailing byte
8931 // only, never internal `/` separators. The canonical nested
8932 // relative POSIX path (`"../caixa-teia/foo/bar"`) must continue
8933 // to validate cleanly so legitimate deeply-nested deps aren't
8934 // broken. Pinned so the gate doesn't accidentally widen to a
8935 // "no `/` separators anywhere" sweep that would defeat the
8936 // entire path-fonte author surface.
8937 let d = dep_with_fonte(DepSource::Path {
8938 caminho: "../caixa-teia/foo/bar".into(),
8939 });
8940 d.validate().unwrap();
8941 }
8942
8943 #[test]
8944 fn validate_accepts_path_fonte_with_caminho_carrying_bare_dot() {
8945 // The positive-control pin on the degenerate single-`.` shape
8946 // (the canonical "the caixa.lisp's own directory" idiom). The
8947 // gate fires on the trailing byte being `/`, not on the path
8948 // being short, so `"."` (one byte, not `/`) must continue to
8949 // validate cleanly.
8950 let d = dep_with_fonte(DepSource::Path {
8951 caminho: ".".into(),
8952 });
8953 d.validate().unwrap();
8954 }
8955
8956 #[test]
8957 fn fonte_caminho_control_char_fires_before_trailing_slash() {
8958 // Cascade pin: the control-char arm structurally precedes the
8959 // trailing-slash arm. A value like `"../foo\n/"` ends in `/`
8960 // but the embedded LF (`0x0A`) is the load-bearing diagnostic
8961 // (control bytes are the paste-from-multiline-doc footgun the
8962 // d624c8d arm already closes). Mirrors the
8963 // `fonte_caminho_control_char_fires_before_backslash` cascade
8964 // discipline on the immediate-predecessor arm.
8965 let d = dep_with_fonte(DepSource::Path {
8966 caminho: "../foo\n/".into(),
8967 });
8968 let err = d.validate().unwrap_err();
8969 assert!(
8970 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8971 "got {err:?}",
8972 );
8973 }
8974
8975 #[test]
8976 fn fonte_caminho_backslash_fires_before_trailing_slash() {
8977 // Cascade pin on the backslash arm: a value like `"..\foo/"`
8978 // ends in `/` but the embedded `\` is the load-bearing
8979 // diagnostic (the cross-host-OS-separator divergence vector
8980 // the 3a4e1d7 arm closes). Same precedence logic as the prior
8981 // narrower-diagnostic-first cascade.
8982 let d = dep_with_fonte(DepSource::Path {
8983 caminho: "..\\caixa-teia/".into(),
8984 });
8985 let err = d.validate().unwrap_err();
8986 assert!(
8987 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8988 "got {err:?}",
8989 );
8990 }
8991
8992 #[test]
8993 fn fonte_caminho_absolute_fires_before_trailing_slash() {
8994 // Cascade pin on the load-bearing leading-byte arm: a leading
8995 // `/` value with a trailing `/` (`"/etc/passwd/"`) routes
8996 // through `FonteCaminhoAbsolute` not `FonteCaminhoTrailingSlash`
8997 // — the host-layout-leak diagnostic is the load-bearing axis,
8998 // the trailing `/` is the secondary observation. Same
8999 // precedence logic as every prior leading-byte arm.
9000 let d = dep_with_fonte(DepSource::Path {
9001 caminho: "/etc/passwd/".into(),
9002 });
9003 let err = d.validate().unwrap_err();
9004 assert!(
9005 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9006 "got {err:?}",
9007 );
9008 }
9009
9010 #[test]
9011 fn fonte_caminho_trailing_slash_diagnostic_carries_offending_dep_and_caminho() {
9012 // Diagnostic-shape pin (peer with the prior
9013 // `fonte_caminho_*_diagnostic_carries_*` payload assertions on
9014 // every preceding arm): the error's Display surfaces the
9015 // offending `:nome` and the offending `:caminho` verbatim so a
9016 // `feira lint` run can render the diagnostic without re-parsing.
9017 let d = dep_with_fonte(DepSource::Path {
9018 caminho: "../caixa-teia/".into(),
9019 });
9020 let rendered = d.validate().unwrap_err().to_string();
9021 assert!(
9022 rendered.contains("caixa-teia"),
9023 "diagnostic must name the offending dep: {rendered}",
9024 );
9025 assert!(
9026 rendered.contains("../caixa-teia/"),
9027 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9028 );
9029 assert!(
9030 rendered.contains("trailing"),
9031 "diagnostic must reference the trailing-slash footgun: {rendered:?}",
9032 );
9033 }
9034
9035 // -- :caminho shell-redirection metacharacter arm -----------------------
9036
9037 #[test]
9038 fn validate_rejects_path_fonte_with_caminho_carrying_gt_redirection() {
9039 // The fail-before-pass-after pin for the canonical output-redirection
9040 // paste footgun: an author copies a shell pipeline tail
9041 // (`"../caixa-teia>build.log"` — the canonical "I selected the whole
9042 // line including the `> build.log` redirect" idiom) and silently
9043 // passed every prior arm (`Path::is_absolute` false on `..`, no
9044 // control bytes, no backslash, doesn't end in `/`). The lacre
9045 // embedded the value verbatim, the resolver folded it through
9046 // `Path::join` looking for a literal `./../caixa-teia>build.log`
9047 // subdirectory, and the failure surfaced at resolve time with a
9048 // non-self-locating `No such file or directory` error. The new arm
9049 // moves the rejection to validate time and names the offending dep
9050 // + caminho + byte verbatim.
9051 let d = dep_with_fonte(DepSource::Path {
9052 caminho: "../caixa-teia>build.log".into(),
9053 });
9054 let err = d.validate().unwrap_err();
9055 let DepError::FonteCaminhoShellRedirection {
9056 nome,
9057 caminho,
9058 byte,
9059 } = err
9060 else {
9061 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
9062 };
9063 assert_eq!(nome, "caixa-teia");
9064 assert_eq!(caminho, "../caixa-teia>build.log");
9065 assert_eq!(byte, b'>');
9066 }
9067
9068 #[test]
9069 fn validate_rejects_path_fonte_with_caminho_carrying_lt_redirection() {
9070 // The symmetric input-redirection paste shape
9071 // (`"../caixa-teia<input.lisp"` — the canonical "I copied a
9072 // `command < input.lisp` line from a tatara-lisp REPL log"
9073 // idiom). Pinned separately from the `>` shape so the gate's
9074 // contract is "any `<` or `>` anywhere", not single-byte coverage.
9075 let d = dep_with_fonte(DepSource::Path {
9076 caminho: "../caixa-teia<input.lisp".into(),
9077 });
9078 let err = d.validate().unwrap_err();
9079 let DepError::FonteCaminhoShellRedirection { byte, .. } = err else {
9080 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
9081 };
9082 assert_eq!(byte, b'<');
9083 }
9084
9085 #[test]
9086 fn validate_rejects_path_fonte_with_caminho_carrying_leading_gt_redirection() {
9087 // Leading-position `>` shape (`">../caixa-teia"` — the degenerate
9088 // "I forgot the source side of the redirect" idiom). Pinned
9089 // separately from the embedded-byte shapes so the gate covers
9090 // every position, not only mid-path.
9091 let d = dep_with_fonte(DepSource::Path {
9092 caminho: ">../caixa-teia".into(),
9093 });
9094 let err = d.validate().unwrap_err();
9095 assert!(
9096 matches!(
9097 err,
9098 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9099 ),
9100 "got {err:?}",
9101 );
9102 }
9103
9104 #[test]
9105 fn validate_rejects_path_fonte_with_caminho_carrying_double_gt_append() {
9106 // The bash append-redirection shape (`"../caixa-teia>>build.log"` —
9107 // the canonical "I copied a `>>` append redirect" idiom). The arm
9108 // fires on the first `>` encountered; pinned so a future arm that
9109 // tries to distinguish `>` from `>>` doesn't break the broader
9110 // contract.
9111 let d = dep_with_fonte(DepSource::Path {
9112 caminho: "../caixa-teia>>build.log".into(),
9113 });
9114 let err = d.validate().unwrap_err();
9115 assert!(
9116 matches!(
9117 err,
9118 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9119 ),
9120 "got {err:?}",
9121 );
9122 }
9123
9124 #[test]
9125 fn validate_accepts_path_fonte_with_caminho_carrying_no_redirection() {
9126 // The positive-control pin: the gate targets only `<` / `>`,
9127 // never adjacent printable ASCII or POSIX-valid bytes. The
9128 // canonical relative POSIX path (`"../caixa-teia"`) and a
9129 // nested deeply-pathed variant (`"../caixa-teia/foo/bar"`) must
9130 // continue to validate cleanly so the gate doesn't widen to a
9131 // "no printable punctuation anywhere" sweep that would defeat
9132 // the entire path-fonte author surface.
9133 let d = dep_with_fonte(DepSource::Path {
9134 caminho: "../caixa-teia/foo/bar".into(),
9135 });
9136 d.validate().unwrap();
9137 }
9138
9139 #[test]
9140 fn fonte_caminho_backslash_fires_before_shell_redirection() {
9141 // Cascade pin on the immediate-predecessor arm: a value carrying
9142 // both `\` and `<` / `>` (`"..\caixa-teia>build.log"` — the
9143 // canonical "I pasted a Windows-shell command with output
9144 // redirect" footgun) routes through `FonteCaminhoBackslash` not
9145 // `FonteCaminhoShellRedirection`. The cross-host-OS-separator
9146 // divergence is the load-bearing axis (an author who removes
9147 // the `\` is the root-cause edit; the `>` falls away in the
9148 // same edit since it's downstream of the Windows-shell
9149 // convention).
9150 let d = dep_with_fonte(DepSource::Path {
9151 caminho: "..\\caixa-teia>build.log".into(),
9152 });
9153 let err = d.validate().unwrap_err();
9154 assert!(
9155 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9156 "got {err:?}",
9157 );
9158 }
9159
9160 #[test]
9161 fn fonte_caminho_control_char_fires_before_shell_redirection() {
9162 // Cascade pin on the embedded-control-byte arm: a value carrying
9163 // both a control byte and `<` / `>` (`"../foo\n>bar"` — the
9164 // canonical paste-from-multiline-doc footgun where a newline
9165 // landed mid-caminho) routes through `FonteCaminhoControlChar`
9166 // not `FonteCaminhoShellRedirection`. The POSIX-syscall-
9167 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
9168 // load-bearing axis on every value that probes positive for
9169 // both — mirrors the cascade discipline on every prior arm.
9170 let d = dep_with_fonte(DepSource::Path {
9171 caminho: "../foo\n>bar".into(),
9172 });
9173 let err = d.validate().unwrap_err();
9174 assert!(
9175 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9176 "got {err:?}",
9177 );
9178 }
9179
9180 #[test]
9181 fn fonte_caminho_absolute_fires_before_shell_redirection() {
9182 // Cascade pin on the load-bearing leading-byte arm: a leading
9183 // `/` value with embedded `<` / `>` (`"/etc/passwd>out"`)
9184 // routes through `FonteCaminhoAbsolute` not
9185 // `FonteCaminhoShellRedirection` — the host-layout-leak
9186 // diagnostic is the load-bearing axis, the `>` byte is the
9187 // secondary observation. Same precedence logic as every prior
9188 // leading-byte arm.
9189 let d = dep_with_fonte(DepSource::Path {
9190 caminho: "/etc/passwd>out".into(),
9191 });
9192 let err = d.validate().unwrap_err();
9193 assert!(
9194 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9195 "got {err:?}",
9196 );
9197 }
9198
9199 #[test]
9200 fn fonte_caminho_shell_redirection_fires_before_trailing_slash() {
9201 // Cascade pin on the immediate-successor arm: a value carrying
9202 // both `<` / `>` and a trailing `/` (`"../foo></"` — the
9203 // canonical "I tab-completed a path that already had a
9204 // redirect" footgun) routes through `FonteCaminhoShellRedirection`
9205 // not `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9206 // the more semantic-locating axis (an author who removes the
9207 // `<` / `>` typically also drops the trailing separator since
9208 // both are paste-from-shell artifacts).
9209 let d = dep_with_fonte(DepSource::Path {
9210 caminho: "../foo></".into(),
9211 });
9212 let err = d.validate().unwrap_err();
9213 assert!(
9214 matches!(
9215 err,
9216 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9217 ),
9218 "got {err:?}",
9219 );
9220 }
9221
9222 #[test]
9223 fn fonte_caminho_shell_redirection_diagnostic_carries_offending_dep_caminho_byte() {
9224 // Diagnostic-shape pin (peer with
9225 // `fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte`'s
9226 // payload assertion on the closest peer arm that also carries a
9227 // `byte` field): the error's Display surfaces the offending
9228 // `:nome`, the offending `:caminho` verbatim, and the offending
9229 // byte in hex (`0x3c` for `<`, `0x3e` for `>`) so a `feira lint`
9230 // run can render the diagnostic without re-parsing.
9231 let d = dep_with_fonte(DepSource::Path {
9232 caminho: "../caixa-teia>build.log".into(),
9233 });
9234 let rendered = d.validate().unwrap_err().to_string();
9235 assert!(
9236 rendered.contains("caixa-teia"),
9237 "diagnostic must name the offending dep: {rendered}",
9238 );
9239 assert!(
9240 rendered.contains("../caixa-teia>build.log"),
9241 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9242 );
9243 assert!(
9244 rendered.contains("0x3e"),
9245 "diagnostic must name the offending byte in hex: {rendered:?}",
9246 );
9247 assert!(
9248 rendered.contains("redirection"),
9249 "diagnostic must name the shell-redirection footgun: {rendered:?}",
9250 );
9251 }
9252
9253 // -- :caminho shell-pipe metacharacter arm ----------------------------
9254
9255 #[test]
9256 fn validate_rejects_path_fonte_with_caminho_carrying_pipe() {
9257 // The fail-before-pass-after pin for the canonical shell-pipe
9258 // paste footgun: an author copies a shell-history line
9259 // (`"../caixa-teia | grep foo"` — the canonical "I selected
9260 // the whole `ls dir | grep` line out of zsh history") and
9261 // silently passed every prior arm (`Path::is_absolute` false
9262 // on `..`, no control bytes, no backslash, no `<` / `>`,
9263 // doesn't end in `/`). The lacre embedded the value verbatim,
9264 // the resolver folded it through `Path::join` looking for a
9265 // literal `./../caixa-teia | grep foo` subdirectory, and the
9266 // failure surfaced at resolve time with a non-self-locating
9267 // `No such file or directory` error. The new arm moves the
9268 // rejection to validate time and names the offending dep +
9269 // caminho verbatim.
9270 let d = dep_with_fonte(DepSource::Path {
9271 caminho: "../caixa-teia | grep foo".into(),
9272 });
9273 let err = d.validate().unwrap_err();
9274 let DepError::FonteCaminhoShellPipe { nome, caminho } = err else {
9275 panic!("expected FonteCaminhoShellPipe, got {err:?}");
9276 };
9277 assert_eq!(nome, "caixa-teia");
9278 assert_eq!(caminho, "../caixa-teia | grep foo");
9279 }
9280
9281 #[test]
9282 fn validate_rejects_path_fonte_with_caminho_carrying_leading_pipe() {
9283 // Leading-position `|` shape (`"|../caixa-teia"` — the
9284 // degenerate "I forgot the source side of the pipe" idiom).
9285 // Pinned separately from the embedded-byte shape so the gate
9286 // covers every position, not only mid-path.
9287 let d = dep_with_fonte(DepSource::Path {
9288 caminho: "|../caixa-teia".into(),
9289 });
9290 let err = d.validate().unwrap_err();
9291 assert!(
9292 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9293 "got {err:?}",
9294 );
9295 }
9296
9297 #[test]
9298 fn validate_rejects_path_fonte_with_caminho_carrying_double_pipe_or() {
9299 // The bash short-circuit-OR shape (`"../caixa-teia||fallback"`
9300 // — the canonical "I copied a `cmd-a || cmd-b` fallback line"
9301 // idiom). The arm fires on the first `|` encountered; pinned
9302 // so a future arm that tries to distinguish `|` from `||`
9303 // doesn't break the broader contract.
9304 let d = dep_with_fonte(DepSource::Path {
9305 caminho: "../caixa-teia||fallback".into(),
9306 });
9307 let err = d.validate().unwrap_err();
9308 assert!(
9309 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9310 "got {err:?}",
9311 );
9312 }
9313
9314 #[test]
9315 fn validate_accepts_path_fonte_with_caminho_carrying_no_pipe() {
9316 // The positive-control pin: the gate targets only `|`, never
9317 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9318 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9319 // pathed variant with adjacent printable punctuation
9320 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9321 // cleanly so the gate doesn't widen to a "no printable
9322 // punctuation anywhere" sweep that would defeat the entire
9323 // path-fonte author surface.
9324 let d = dep_with_fonte(DepSource::Path {
9325 caminho: "../caixa-teia/sub-dir.v2".into(),
9326 });
9327 d.validate().unwrap();
9328 }
9329
9330 #[test]
9331 fn fonte_caminho_shell_redirection_fires_before_shell_pipe() {
9332 // Cascade pin on the immediate-predecessor arm: a value carrying
9333 // both `<` / `>` and `|` (`"../caixa-teia<input|tee"` — the
9334 // canonical "I pasted a `cmd < input | tee` pipeline tail"
9335 // footgun) routes through `FonteCaminhoShellRedirection` not
9336 // `FonteCaminhoShellPipe`. The input/output redirection
9337 // metachar carries the more self-locating `byte: u8` payload
9338 // (it names which of `<` or `>` triggered), so the prior arm
9339 // wins on every probe-as-both value — same cascade discipline
9340 // every prior `:caminho` arm establishes.
9341 let d = dep_with_fonte(DepSource::Path {
9342 caminho: "../caixa-teia<input|tee".into(),
9343 });
9344 let err = d.validate().unwrap_err();
9345 assert!(
9346 matches!(
9347 err,
9348 DepError::FonteCaminhoShellRedirection { byte: b'<', .. }
9349 ),
9350 "got {err:?}",
9351 );
9352 }
9353
9354 #[test]
9355 fn fonte_caminho_backslash_fires_before_shell_pipe() {
9356 // Cascade pin on the upstream backslash arm: a value carrying
9357 // both `\` and `|` (`"..\caixa-teia|tee"` — the canonical
9358 // "I pasted a Windows-shell command with pipe to tee"
9359 // footgun) routes through `FonteCaminhoBackslash` not
9360 // `FonteCaminhoShellPipe`. The cross-host-OS-separator
9361 // divergence is the load-bearing axis on every probe-as-both
9362 // value (an author who removes the `\` is the root-cause edit;
9363 // the `|` falls away in the same edit since it's downstream of
9364 // the Windows-shell convention).
9365 let d = dep_with_fonte(DepSource::Path {
9366 caminho: "..\\caixa-teia|tee".into(),
9367 });
9368 let err = d.validate().unwrap_err();
9369 assert!(
9370 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9371 "got {err:?}",
9372 );
9373 }
9374
9375 #[test]
9376 fn fonte_caminho_control_char_fires_before_shell_pipe() {
9377 // Cascade pin on the embedded-control-byte arm: a value
9378 // carrying both a control byte and `|` (`"../foo\n|bar"` —
9379 // the canonical paste-from-multiline-doc footgun where a
9380 // newline landed mid-caminho) routes through
9381 // `FonteCaminhoControlChar` not `FonteCaminhoShellPipe`. The
9382 // POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9383 // diagnostic is the load-bearing axis on every value that
9384 // probes positive for both — mirrors the cascade discipline
9385 // on every prior arm.
9386 let d = dep_with_fonte(DepSource::Path {
9387 caminho: "../foo\n|bar".into(),
9388 });
9389 let err = d.validate().unwrap_err();
9390 assert!(
9391 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9392 "got {err:?}",
9393 );
9394 }
9395
9396 #[test]
9397 fn fonte_caminho_absolute_fires_before_shell_pipe() {
9398 // Cascade pin on the load-bearing leading-byte arm: a leading
9399 // `/` value with embedded `|` (`"/etc/passwd|tee"`) routes
9400 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellPipe`
9401 // — the host-layout-leak diagnostic is the load-bearing axis,
9402 // the `|` byte is the secondary observation. Same precedence
9403 // logic as every prior leading-byte arm.
9404 let d = dep_with_fonte(DepSource::Path {
9405 caminho: "/etc/passwd|tee".into(),
9406 });
9407 let err = d.validate().unwrap_err();
9408 assert!(
9409 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9410 "got {err:?}",
9411 );
9412 }
9413
9414 #[test]
9415 fn fonte_caminho_shell_pipe_fires_before_trailing_slash() {
9416 // Cascade pin on the immediate-successor arm: a value carrying
9417 // both `|` and a trailing `/` (`"../foo|tee/"` — the canonical
9418 // "I tab-completed a path that already had a pipeline tail"
9419 // footgun) routes through `FonteCaminhoShellPipe` not
9420 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9421 // the more semantic-locating axis (an author who removes the
9422 // `|` typically also drops the trailing separator since both
9423 // are paste-from-shell artifacts).
9424 let d = dep_with_fonte(DepSource::Path {
9425 caminho: "../foo|tee/".into(),
9426 });
9427 let err = d.validate().unwrap_err();
9428 assert!(
9429 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9430 "got {err:?}",
9431 );
9432 }
9433
9434 #[test]
9435 fn fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho() {
9436 // Diagnostic-shape pin (peer with
9437 // `fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho`
9438 // on the closest single-byte peer arm): the error's Display
9439 // surfaces the offending `:nome` and the offending `:caminho`
9440 // verbatim, and names the shell-pipe footgun explicitly so a
9441 // `feira lint` run can render the diagnostic without
9442 // re-parsing.
9443 let d = dep_with_fonte(DepSource::Path {
9444 caminho: "../caixa-teia | grep foo".into(),
9445 });
9446 let rendered = d.validate().unwrap_err().to_string();
9447 assert!(
9448 rendered.contains("caixa-teia"),
9449 "diagnostic must name the offending dep: {rendered}",
9450 );
9451 assert!(
9452 rendered.contains("../caixa-teia | grep foo"),
9453 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9454 );
9455 assert!(
9456 rendered.contains('|'),
9457 "diagnostic must reference the pipe footgun: {rendered:?}",
9458 );
9459 assert!(
9460 rendered.contains("pipe"),
9461 "diagnostic must name the shell-pipe footgun: {rendered:?}",
9462 );
9463 }
9464
9465 // -- :caminho shell-command-separator metacharacter arm ---------------
9466
9467 #[test]
9468 fn validate_rejects_path_fonte_with_caminho_carrying_semicolon() {
9469 // The fail-before-pass-after pin for the canonical shell-command-
9470 // separator paste footgun: an author copies a shell one-liner
9471 // (`"../caixa-teia; rm -rf build"` — the canonical "I selected the
9472 // whole `cd path; do-thing` chain out of a shell-history block")
9473 // and silently passed every prior arm (`Path::is_absolute` false
9474 // on `..`, no control bytes, no backslash, no `<` / `>`, no `|`,
9475 // doesn't end in `/`). The lacre embedded the value verbatim, the
9476 // resolver folded it through `Path::join` looking for a literal
9477 // `./../caixa-teia; rm -rf build` subdirectory, and the failure
9478 // surfaced at resolve time with a non-self-locating `No such file
9479 // or directory` error. The new arm moves the rejection to validate
9480 // time and names the offending dep + caminho verbatim.
9481 let d = dep_with_fonte(DepSource::Path {
9482 caminho: "../caixa-teia; rm -rf build".into(),
9483 });
9484 let err = d.validate().unwrap_err();
9485 let DepError::FonteCaminhoShellSemicolon { nome, caminho } = err else {
9486 panic!("expected FonteCaminhoShellSemicolon, got {err:?}");
9487 };
9488 assert_eq!(nome, "caixa-teia");
9489 assert_eq!(caminho, "../caixa-teia; rm -rf build");
9490 }
9491
9492 #[test]
9493 fn validate_rejects_path_fonte_with_caminho_carrying_leading_semicolon() {
9494 // Leading-position `;` shape (`";../caixa-teia"` — the degenerate
9495 // "I forgot the prior command side of the separator" idiom).
9496 // Pinned separately from the embedded-byte shape so the gate
9497 // covers every position, not only mid-path.
9498 let d = dep_with_fonte(DepSource::Path {
9499 caminho: ";../caixa-teia".into(),
9500 });
9501 let err = d.validate().unwrap_err();
9502 assert!(
9503 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9504 "got {err:?}",
9505 );
9506 }
9507
9508 #[test]
9509 fn validate_rejects_path_fonte_with_caminho_carrying_double_semicolon() {
9510 // The POSIX `case` arm `;;` terminator shape
9511 // (`"../caixa-teia;;next"` — the canonical "I copied a `case`
9512 // arm tail" idiom). The arm fires on the first `;` encountered;
9513 // pinned so a future arm that tries to distinguish `;` from `;;`
9514 // doesn't break the broader contract.
9515 let d = dep_with_fonte(DepSource::Path {
9516 caminho: "../caixa-teia;;next".into(),
9517 });
9518 let err = d.validate().unwrap_err();
9519 assert!(
9520 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9521 "got {err:?}",
9522 );
9523 }
9524
9525 #[test]
9526 fn validate_accepts_path_fonte_with_caminho_carrying_no_semicolon() {
9527 // The positive-control pin: the gate targets only `;`, never
9528 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9529 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9530 // pathed variant with adjacent printable punctuation
9531 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9532 // cleanly so the gate doesn't widen to a "no printable
9533 // punctuation anywhere" sweep that would defeat the entire
9534 // path-fonte author surface.
9535 let d = dep_with_fonte(DepSource::Path {
9536 caminho: "../caixa-teia/sub-dir.v2".into(),
9537 });
9538 d.validate().unwrap();
9539 }
9540
9541 #[test]
9542 fn fonte_caminho_shell_pipe_fires_before_shell_semicolon() {
9543 // Cascade pin on the immediate-predecessor arm: a value carrying
9544 // both `|` and `;` (`"../caixa-teia | tee; rm"` — the canonical
9545 // "I pasted a `cmd | tee; cleanup` chain" footgun) routes through
9546 // `FonteCaminhoShellPipe` not `FonteCaminhoShellSemicolon`. The
9547 // pipeline-tail paste is the load-bearing root-cause edit on
9548 // every probe-as-both value (an author who removes the `|`
9549 // typically also drops the trailing `; cleanup` since both are
9550 // the same paste-from-shell-history artifact) — same cascade
9551 // discipline every prior `:caminho` arm establishes.
9552 let d = dep_with_fonte(DepSource::Path {
9553 caminho: "../caixa-teia | tee; rm".into(),
9554 });
9555 let err = d.validate().unwrap_err();
9556 assert!(
9557 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9558 "got {err:?}",
9559 );
9560 }
9561
9562 #[test]
9563 fn fonte_caminho_shell_redirection_fires_before_shell_semicolon() {
9564 // Cascade pin on the upstream shell-redirection arm: a value
9565 // carrying both `<` / `>` and `;` (`"../caixa-teia>log; rm"` —
9566 // the canonical "I pasted a `cmd > log; cleanup` chain"
9567 // footgun) routes through `FonteCaminhoShellRedirection` not
9568 // `FonteCaminhoShellSemicolon`. The input/output redirection
9569 // metachar carries the more self-locating `byte: u8` payload
9570 // (it names which of `<` or `>` triggered), so the prior arm
9571 // wins on every probe-as-both value.
9572 let d = dep_with_fonte(DepSource::Path {
9573 caminho: "../caixa-teia>log; rm".into(),
9574 });
9575 let err = d.validate().unwrap_err();
9576 assert!(
9577 matches!(
9578 err,
9579 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9580 ),
9581 "got {err:?}",
9582 );
9583 }
9584
9585 #[test]
9586 fn fonte_caminho_backslash_fires_before_shell_semicolon() {
9587 // Cascade pin on the upstream backslash arm: a value carrying
9588 // both `\` and `;` (`"..\caixa-teia;rm"` — the canonical "I
9589 // pasted a Windows-shell `cd ..\path; cleanup` chain") routes
9590 // through `FonteCaminhoBackslash` not `FonteCaminhoShellSemicolon`.
9591 // The cross-host-OS-separator divergence is the load-bearing axis
9592 // on every probe-as-both value (an author who removes the `\` is
9593 // the root-cause edit; the `;` falls away in the same edit since
9594 // it's downstream of the Windows-shell convention).
9595 let d = dep_with_fonte(DepSource::Path {
9596 caminho: "..\\caixa-teia;rm".into(),
9597 });
9598 let err = d.validate().unwrap_err();
9599 assert!(
9600 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9601 "got {err:?}",
9602 );
9603 }
9604
9605 #[test]
9606 fn fonte_caminho_control_char_fires_before_shell_semicolon() {
9607 // Cascade pin on the embedded-control-byte arm: a value carrying
9608 // both a control byte and `;` (`"../foo\n;bar"` — the canonical
9609 // paste-from-multiline-doc footgun where a newline landed mid-
9610 // caminho) routes through `FonteCaminhoControlChar` not
9611 // `FonteCaminhoShellSemicolon`. The POSIX-syscall-rejected-byte
9612 // / NUL-`CString::new`-fail diagnostic is the load-bearing axis
9613 // on every value that probes positive for both — mirrors the
9614 // cascade discipline on every prior arm.
9615 let d = dep_with_fonte(DepSource::Path {
9616 caminho: "../foo\n;bar".into(),
9617 });
9618 let err = d.validate().unwrap_err();
9619 assert!(
9620 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9621 "got {err:?}",
9622 );
9623 }
9624
9625 #[test]
9626 fn fonte_caminho_absolute_fires_before_shell_semicolon() {
9627 // Cascade pin on the load-bearing leading-byte arm: a leading
9628 // `/` value with embedded `;` (`"/etc/passwd;rm"`) routes
9629 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellSemicolon`
9630 // — the host-layout-leak diagnostic is the load-bearing axis,
9631 // the `;` byte is the secondary observation. Same precedence
9632 // logic as every prior leading-byte arm.
9633 let d = dep_with_fonte(DepSource::Path {
9634 caminho: "/etc/passwd;rm".into(),
9635 });
9636 let err = d.validate().unwrap_err();
9637 assert!(
9638 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9639 "got {err:?}",
9640 );
9641 }
9642
9643 #[test]
9644 fn fonte_caminho_shell_semicolon_fires_before_trailing_slash() {
9645 // Cascade pin on the immediate-successor arm: a value carrying
9646 // both `;` and a trailing `/` (`"../foo;rm/"` — the canonical
9647 // "I tab-completed a path that already had a `; cleanup` tail"
9648 // footgun) routes through `FonteCaminhoShellSemicolon` not
9649 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9650 // the more semantic-locating axis (an author who removes the
9651 // `;` typically also drops the trailing separator since both
9652 // are paste-from-shell artifacts).
9653 let d = dep_with_fonte(DepSource::Path {
9654 caminho: "../foo;rm/".into(),
9655 });
9656 let err = d.validate().unwrap_err();
9657 assert!(
9658 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9659 "got {err:?}",
9660 );
9661 }
9662
9663 #[test]
9664 fn fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho() {
9665 // Diagnostic-shape pin (peer with
9666 // `fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho`
9667 // on the closest single-byte peer arm): the error's Display
9668 // surfaces the offending `:nome` and the offending `:caminho`
9669 // verbatim, and names the shell-command-separator footgun
9670 // explicitly so a `feira lint` run can render the diagnostic
9671 // without re-parsing.
9672 let d = dep_with_fonte(DepSource::Path {
9673 caminho: "../caixa-teia; rm -rf build".into(),
9674 });
9675 let rendered = d.validate().unwrap_err().to_string();
9676 assert!(
9677 rendered.contains("caixa-teia"),
9678 "diagnostic must name the offending dep: {rendered}",
9679 );
9680 assert!(
9681 rendered.contains("../caixa-teia; rm -rf build"),
9682 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9683 );
9684 assert!(
9685 rendered.contains(';'),
9686 "diagnostic must reference the semicolon footgun: {rendered:?}",
9687 );
9688 assert!(
9689 rendered.contains("command-separator"),
9690 "diagnostic must name the shell-command-separator footgun: {rendered:?}",
9691 );
9692 }
9693
9694 #[test]
9695 fn validate_rejects_path_fonte_with_caminho_carrying_ampersand() {
9696 // The fail-before-pass-after pin for the canonical shell-
9697 // background-task paste footgun: an author copies a shell one-
9698 // liner (`"../caixa-teia & sleep 1"` — the canonical "I selected
9699 // the whole `cd path & sleep 1` background-launch out of a
9700 // shell-history block") and silently passed every prior arm
9701 // (`Path::is_absolute` false on `..`, no control bytes, no
9702 // backslash, no `<` / `>`, no `|`, no `;`, doesn't end in `/`).
9703 // The lacre embedded the value verbatim, the resolver folded it
9704 // through `Path::join` looking for a literal `./../caixa-teia &
9705 // sleep 1` subdirectory, and the failure surfaced at resolve
9706 // time with a non-self-locating `No such file or directory`
9707 // error. The new arm moves the rejection to validate time and
9708 // names the offending dep + caminho verbatim.
9709 let d = dep_with_fonte(DepSource::Path {
9710 caminho: "../caixa-teia & sleep 1".into(),
9711 });
9712 let err = d.validate().unwrap_err();
9713 let DepError::FonteCaminhoShellBackground { nome, caminho } = err else {
9714 panic!("expected FonteCaminhoShellBackground, got {err:?}");
9715 };
9716 assert_eq!(nome, "caixa-teia");
9717 assert_eq!(caminho, "../caixa-teia & sleep 1");
9718 }
9719
9720 #[test]
9721 fn validate_rejects_path_fonte_with_caminho_carrying_leading_ampersand() {
9722 // Leading-position `&` shape (`"&../caixa-teia"` — the
9723 // degenerate "I forgot the prior command side of the
9724 // background terminator" idiom). Pinned separately from the
9725 // embedded-byte shape so the gate covers every position, not
9726 // only mid-path.
9727 let d = dep_with_fonte(DepSource::Path {
9728 caminho: "&../caixa-teia".into(),
9729 });
9730 let err = d.validate().unwrap_err();
9731 assert!(
9732 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9733 "got {err:?}",
9734 );
9735 }
9736
9737 #[test]
9738 fn validate_rejects_path_fonte_with_caminho_carrying_double_ampersand() {
9739 // The logical-AND `&&` shape (`"../caixa-teia && make"` — the
9740 // canonical "I copied a `cd path && make` build chain" idiom
9741 // every Makefile / shell-script wraps). The arm fires on the
9742 // first `&` encountered; pinned so a future arm that tries to
9743 // distinguish `&` from `&&` doesn't break the broader contract.
9744 let d = dep_with_fonte(DepSource::Path {
9745 caminho: "../caixa-teia && make".into(),
9746 });
9747 let err = d.validate().unwrap_err();
9748 assert!(
9749 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9750 "got {err:?}",
9751 );
9752 }
9753
9754 #[test]
9755 fn validate_accepts_path_fonte_with_caminho_carrying_no_ampersand() {
9756 // The positive-control pin: the gate targets only `&`, never
9757 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9758 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9759 // pathed variant with adjacent printable punctuation
9760 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9761 // cleanly so the gate doesn't widen to a "no printable
9762 // punctuation anywhere" sweep that would defeat the entire
9763 // path-fonte author surface.
9764 let d = dep_with_fonte(DepSource::Path {
9765 caminho: "../caixa-teia/sub-dir.v2".into(),
9766 });
9767 d.validate().unwrap();
9768 }
9769
9770 #[test]
9771 fn fonte_caminho_shell_semicolon_fires_before_shell_background() {
9772 // Cascade pin on the immediate-predecessor arm: a value carrying
9773 // both `;` and `&` (`"../caixa-teia; rm & sleep"` — the
9774 // canonical "I pasted a `cmd; cleanup & sleep` chain" footgun)
9775 // routes through `FonteCaminhoShellSemicolon` not
9776 // `FonteCaminhoShellBackground`. The sequential-command-
9777 // separator paste is the more common shell-history paste idiom
9778 // on every probe-as-both value (an author who removes the `;`
9779 // typically also drops the trailing `& sleep` since both are
9780 // paste-from-shell-history artifacts) — same cascade discipline
9781 // every prior `:caminho` arm establishes.
9782 let d = dep_with_fonte(DepSource::Path {
9783 caminho: "../caixa-teia; rm & sleep".into(),
9784 });
9785 let err = d.validate().unwrap_err();
9786 assert!(
9787 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9788 "got {err:?}",
9789 );
9790 }
9791
9792 #[test]
9793 fn fonte_caminho_shell_pipe_fires_before_shell_background() {
9794 // Cascade pin on the upstream shell-pipe arm: a value carrying
9795 // both `|` and `&` (`"../caixa-teia | tee & sleep"` — the
9796 // canonical "I pasted a `cmd | tee & sleep` background-pipeline
9797 // chain" footgun) routes through `FonteCaminhoShellPipe` not
9798 // `FonteCaminhoShellBackground`. The pipeline-tail paste is the
9799 // load-bearing root-cause edit on every probe-as-both value.
9800 let d = dep_with_fonte(DepSource::Path {
9801 caminho: "../caixa-teia | tee & sleep".into(),
9802 });
9803 let err = d.validate().unwrap_err();
9804 assert!(
9805 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9806 "got {err:?}",
9807 );
9808 }
9809
9810 #[test]
9811 fn fonte_caminho_shell_redirection_fires_before_shell_background() {
9812 // Cascade pin on the upstream shell-redirection arm: a value
9813 // carrying both `>` and `&` (`"../caixa-teia>log & sleep"` —
9814 // the canonical "I pasted a `cmd > log & sleep` background-
9815 // redirect chain" footgun) routes through
9816 // `FonteCaminhoShellRedirection` not
9817 // `FonteCaminhoShellBackground`. The input/output redirection
9818 // metachar carries the more self-locating `byte: u8` payload
9819 // (it names which of `<` or `>` triggered), so the prior arm
9820 // wins on every probe-as-both value.
9821 let d = dep_with_fonte(DepSource::Path {
9822 caminho: "../caixa-teia>log & sleep".into(),
9823 });
9824 let err = d.validate().unwrap_err();
9825 assert!(
9826 matches!(
9827 err,
9828 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9829 ),
9830 "got {err:?}",
9831 );
9832 }
9833
9834 #[test]
9835 fn fonte_caminho_backslash_fires_before_shell_background() {
9836 // Cascade pin on the upstream backslash arm: a value carrying
9837 // both `\` and `&` (`"..\caixa-teia & sleep"` — the canonical
9838 // "I pasted a Windows-shell `cd ..\path & sleep` background-
9839 // launch chain") routes through `FonteCaminhoBackslash` not
9840 // `FonteCaminhoShellBackground`. The cross-host-OS-separator
9841 // divergence is the load-bearing axis on every probe-as-both
9842 // value (an author who removes the `\` is the root-cause edit;
9843 // the `&` falls away in the same edit since it's downstream of
9844 // the Windows-shell convention).
9845 let d = dep_with_fonte(DepSource::Path {
9846 caminho: "..\\caixa-teia & sleep".into(),
9847 });
9848 let err = d.validate().unwrap_err();
9849 assert!(
9850 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9851 "got {err:?}",
9852 );
9853 }
9854
9855 #[test]
9856 fn fonte_caminho_control_char_fires_before_shell_background() {
9857 // Cascade pin on the embedded-control-byte arm: a value
9858 // carrying both a control byte and `&` (`"../foo\n&sleep"` —
9859 // the canonical paste-from-multiline-doc footgun where a
9860 // newline landed mid-caminho) routes through
9861 // `FonteCaminhoControlChar` not `FonteCaminhoShellBackground`.
9862 // The POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9863 // diagnostic is the load-bearing axis on every value that
9864 // probes positive for both — mirrors the cascade discipline on
9865 // every prior arm.
9866 let d = dep_with_fonte(DepSource::Path {
9867 caminho: "../foo\n&sleep".into(),
9868 });
9869 let err = d.validate().unwrap_err();
9870 assert!(
9871 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9872 "got {err:?}",
9873 );
9874 }
9875
9876 #[test]
9877 fn fonte_caminho_absolute_fires_before_shell_background() {
9878 // Cascade pin on the load-bearing leading-byte arm: a leading
9879 // `/` value with embedded `&` (`"/etc/passwd & sleep"`) routes
9880 // through `FonteCaminhoAbsolute` not
9881 // `FonteCaminhoShellBackground` — the host-layout-leak
9882 // diagnostic is the load-bearing axis, the `&` byte is the
9883 // secondary observation. Same precedence logic as every prior
9884 // leading-byte arm.
9885 let d = dep_with_fonte(DepSource::Path {
9886 caminho: "/etc/passwd & sleep".into(),
9887 });
9888 let err = d.validate().unwrap_err();
9889 assert!(
9890 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9891 "got {err:?}",
9892 );
9893 }
9894
9895 #[test]
9896 fn fonte_caminho_shell_background_fires_before_trailing_slash() {
9897 // Cascade pin on the immediate-successor arm: a value carrying
9898 // both `&` and a trailing `/` (`"../foo&sleep/"` — the
9899 // canonical "I tab-completed a path that already had a `&
9900 // sleep` background-launch tail" footgun) routes through
9901 // `FonteCaminhoShellBackground` not `FonteCaminhoTrailingSlash`.
9902 // The embedded shell-metachar is the more semantic-locating
9903 // axis (an author who removes the `&` typically also drops
9904 // the trailing separator since both are paste-from-shell
9905 // artifacts).
9906 let d = dep_with_fonte(DepSource::Path {
9907 caminho: "../foo&sleep/".into(),
9908 });
9909 let err = d.validate().unwrap_err();
9910 assert!(
9911 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9912 "got {err:?}",
9913 );
9914 }
9915
9916 #[test]
9917 fn fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho() {
9918 // Diagnostic-shape pin (peer with
9919 // `fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho`
9920 // on the closest single-byte peer arm): the error's Display
9921 // surfaces the offending `:nome` and the offending `:caminho`
9922 // verbatim, and names the shell-background / logical-AND
9923 // footgun explicitly so a `feira lint` run can render the
9924 // diagnostic without re-parsing.
9925 let d = dep_with_fonte(DepSource::Path {
9926 caminho: "../caixa-teia & sleep 1".into(),
9927 });
9928 let rendered = d.validate().unwrap_err().to_string();
9929 assert!(
9930 rendered.contains("caixa-teia"),
9931 "diagnostic must name the offending dep: {rendered}",
9932 );
9933 assert!(
9934 rendered.contains("../caixa-teia & sleep 1"),
9935 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9936 );
9937 assert!(
9938 rendered.contains('&'),
9939 "diagnostic must reference the ampersand footgun: {rendered:?}",
9940 );
9941 assert!(
9942 rendered.contains("background") || rendered.contains("list-AND"),
9943 "diagnostic must name the shell-background / logical-AND footgun: {rendered:?}",
9944 );
9945 }
9946
9947 #[test]
9948 fn validate_rejects_path_fonte_with_caminho_carrying_backtick() {
9949 // The fail-before-pass-after pin for the canonical shell-
9950 // command-substitution paste footgun: an author copies a
9951 // POSIX legacy backticked one-liner (`"../caixa-teia/`whoami`"`
9952 // — the canonical "I pasted a path that included a `pwd`
9953 // / `whoami` / `date` legacy command-substitution expansion
9954 // out of a shell-history block") and silently passed every
9955 // prior arm (`Path::is_absolute` false on `..`, no control
9956 // bytes, no `\`, no `<` / `>`, no `|`, no `;`, no `&`, doesn't
9957 // end in `/`). The lacre embedded the value verbatim, the
9958 // resolver folded it through `Path::join` looking for a
9959 // literal `./../caixa-teia/`whoami`` subdirectory, and the
9960 // failure surfaced at resolve time with a non-self-locating
9961 // `No such file or directory` error. The new arm moves the
9962 // rejection to validate time and names the offending dep +
9963 // caminho verbatim.
9964 let d = dep_with_fonte(DepSource::Path {
9965 caminho: "../caixa-teia/`whoami`".into(),
9966 });
9967 let err = d.validate().unwrap_err();
9968 let DepError::FonteCaminhoShellCommandSubstitution { nome, caminho } = err else {
9969 panic!("expected FonteCaminhoShellCommandSubstitution, got {err:?}");
9970 };
9971 assert_eq!(nome, "caixa-teia");
9972 assert_eq!(caminho, "../caixa-teia/`whoami`");
9973 }
9974
9975 #[test]
9976 fn validate_rejects_path_fonte_with_caminho_carrying_leading_backtick() {
9977 // Leading-position backtick shape (``"`pwd`/caixa-teia"`` —
9978 // the canonical `<backtick>pwd<backtick>/path` working-
9979 // directory expansion shape every shell-side path-composition
9980 // idiom carries). Pinned separately from the embedded-byte
9981 // shape so the gate covers every position, not only mid-path.
9982 let d = dep_with_fonte(DepSource::Path {
9983 caminho: "`pwd`/caixa-teia".into(),
9984 });
9985 let err = d.validate().unwrap_err();
9986 assert!(
9987 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9988 "got {err:?}",
9989 );
9990 }
9991
9992 #[test]
9993 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backtick() {
9994 // Trailing-position backtick shape (`"../caixa-teia`"` — the
9995 // degenerate "I selected an unbalanced backtick out of a
9996 // shell-history block" idiom that probes for the cascade's
9997 // last-byte handling). The trailing-`/` arm fires only on
9998 // last-byte `/`; an unbalanced trailing backtick must route
9999 // through this arm regardless of position.
10000 let d = dep_with_fonte(DepSource::Path {
10001 caminho: "../caixa-teia`".into(),
10002 });
10003 let err = d.validate().unwrap_err();
10004 assert!(
10005 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10006 "got {err:?}",
10007 );
10008 }
10009
10010 #[test]
10011 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_backtick_pair() {
10012 // The canonical balanced-pair shape (``"../<backtick>cat
10013 // /etc/passwd<backtick>"`` — the canonical CWE-78 shell-
10014 // command-injection paste idiom every shell-side hardening
10015 // guide enumerates first). The arm fires on the first
10016 // backtick encountered; pinned so a future arm that tries to
10017 // distinguish the opening from the closing byte doesn't break
10018 // the broader contract.
10019 let d = dep_with_fonte(DepSource::Path {
10020 caminho: "../`cat /etc/passwd`".into(),
10021 });
10022 let err = d.validate().unwrap_err();
10023 assert!(
10024 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10025 "got {err:?}",
10026 );
10027 }
10028
10029 #[test]
10030 fn validate_accepts_path_fonte_with_caminho_carrying_no_backtick() {
10031 // The positive-control pin: the gate targets only the
10032 // backtick byte, never adjacent printable ASCII or POSIX-
10033 // valid bytes. The canonical relative POSIX path
10034 // (`"../caixa-teia"`) and a nested deeply-pathed variant with
10035 // adjacent printable punctuation
10036 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
10037 // cleanly so the gate doesn't widen to a "no printable
10038 // punctuation anywhere" sweep that would defeat the entire
10039 // path-fonte author surface.
10040 let d = dep_with_fonte(DepSource::Path {
10041 caminho: "../caixa-teia/sub-dir.v2".into(),
10042 });
10043 d.validate().unwrap();
10044 }
10045
10046 #[test]
10047 fn fonte_caminho_shell_background_fires_before_shell_command_substitution() {
10048 // Cascade pin on the immediate-predecessor arm: a value
10049 // carrying both `&` and a backtick (``"../caixa-teia &
10050 // <backtick>sleep 1<backtick>"`` — the canonical "I pasted a
10051 // `cmd & <backtick>sleep N<backtick>` background-launch +
10052 // command-substitution chain" footgun) routes through
10053 // `FonteCaminhoShellBackground` not
10054 // `FonteCaminhoShellCommandSubstitution`. The background-
10055 // launch tail is the more common shell-history paste idiom
10056 // on every probe-as-both value — same cascade discipline
10057 // every prior `:caminho` arm establishes.
10058 let d = dep_with_fonte(DepSource::Path {
10059 caminho: "../caixa-teia & `sleep 1`".into(),
10060 });
10061 let err = d.validate().unwrap_err();
10062 assert!(
10063 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10064 "got {err:?}",
10065 );
10066 }
10067
10068 #[test]
10069 fn fonte_caminho_shell_semicolon_fires_before_shell_command_substitution() {
10070 // Cascade pin on the upstream shell-semicolon arm: a value
10071 // carrying both `;` and a backtick (``"../caixa-teia;
10072 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
10073 // `cmd; <backtick>follow-up<backtick>` sequential-chain
10074 // footgun) routes through `FonteCaminhoShellSemicolon` not
10075 // `FonteCaminhoShellCommandSubstitution`. The sequential-
10076 // command-separator paste is the load-bearing root-cause
10077 // edit on every probe-as-both value.
10078 let d = dep_with_fonte(DepSource::Path {
10079 caminho: "../caixa-teia; `whoami`".into(),
10080 });
10081 let err = d.validate().unwrap_err();
10082 assert!(
10083 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10084 "got {err:?}",
10085 );
10086 }
10087
10088 #[test]
10089 fn fonte_caminho_shell_pipe_fires_before_shell_command_substitution() {
10090 // Cascade pin on the upstream shell-pipe arm: a value
10091 // carrying both `|` and a backtick (``"../caixa-teia |
10092 // <backtick>tee log<backtick>"`` — the canonical pipeline-to-
10093 // command-substitution paste idiom) routes through
10094 // `FonteCaminhoShellPipe` not
10095 // `FonteCaminhoShellCommandSubstitution`. The pipeline-tail
10096 // paste is the load-bearing root-cause edit on every
10097 // probe-as-both value.
10098 let d = dep_with_fonte(DepSource::Path {
10099 caminho: "../caixa-teia | `tee log`".into(),
10100 });
10101 let err = d.validate().unwrap_err();
10102 assert!(
10103 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10104 "got {err:?}",
10105 );
10106 }
10107
10108 #[test]
10109 fn fonte_caminho_shell_redirection_fires_before_shell_command_substitution() {
10110 // Cascade pin on the upstream shell-redirection arm: a value
10111 // carrying both `>` and a backtick (``"../caixa-teia>log
10112 // <backtick>date<backtick>"`` — the canonical "I pasted a
10113 // `cmd > log <backtick>date<backtick>` redirect-plus-
10114 // substitution chain" footgun) routes through
10115 // `FonteCaminhoShellRedirection` not
10116 // `FonteCaminhoShellCommandSubstitution`. The input/output
10117 // redirection metachar carries the more self-locating `byte`
10118 // payload (it names which of `<` or `>` triggered), so the
10119 // prior arm wins on every probe-as-both value.
10120 let d = dep_with_fonte(DepSource::Path {
10121 caminho: "../caixa-teia>log `date`".into(),
10122 });
10123 let err = d.validate().unwrap_err();
10124 assert!(
10125 matches!(
10126 err,
10127 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10128 ),
10129 "got {err:?}",
10130 );
10131 }
10132
10133 #[test]
10134 fn fonte_caminho_backslash_fires_before_shell_command_substitution() {
10135 // Cascade pin on the upstream backslash arm: a value
10136 // carrying both `\` and a backtick (``"..\caixa-teia
10137 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
10138 // Windows-shell `cd ..\path <backtick>whoami<backtick>`
10139 // chain") routes through `FonteCaminhoBackslash` not
10140 // `FonteCaminhoShellCommandSubstitution`. The cross-host-OS-
10141 // separator divergence is the load-bearing axis on every
10142 // probe-as-both value (an author who removes the `\` is the
10143 // root-cause edit; the backtick falls away in the same edit
10144 // since it's downstream of the Windows-shell convention).
10145 let d = dep_with_fonte(DepSource::Path {
10146 caminho: "..\\caixa-teia `whoami`".into(),
10147 });
10148 let err = d.validate().unwrap_err();
10149 assert!(
10150 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10151 "got {err:?}",
10152 );
10153 }
10154
10155 #[test]
10156 fn fonte_caminho_control_char_fires_before_shell_command_substitution() {
10157 // Cascade pin on the embedded-control-byte arm: a value
10158 // carrying both a control byte and a backtick (`"../foo\n
10159 // `whoami`"` — the canonical paste-from-multiline-doc
10160 // footgun where a newline landed mid-caminho between two
10161 // paste fragments) routes through `FonteCaminhoControlChar`
10162 // not `FonteCaminhoShellCommandSubstitution`. The POSIX-
10163 // syscall-rejected-byte / NUL-`CString::new`-fail diagnostic
10164 // is the load-bearing axis on every value that probes
10165 // positive for both — mirrors the cascade discipline on
10166 // every prior arm.
10167 let d = dep_with_fonte(DepSource::Path {
10168 caminho: "../foo\n`whoami`".into(),
10169 });
10170 let err = d.validate().unwrap_err();
10171 assert!(
10172 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10173 "got {err:?}",
10174 );
10175 }
10176
10177 #[test]
10178 fn fonte_caminho_absolute_fires_before_shell_command_substitution() {
10179 // Cascade pin on the load-bearing leading-byte arm: a
10180 // leading `/` value with embedded backtick (``"/etc/passwd
10181 // <backtick>whoami<backtick>"``) routes through
10182 // `FonteCaminhoAbsolute` not
10183 // `FonteCaminhoShellCommandSubstitution` — the host-layout-
10184 // leak diagnostic is the load-bearing axis, the backtick
10185 // byte is the secondary observation. Same precedence logic
10186 // as every prior leading-byte arm.
10187 let d = dep_with_fonte(DepSource::Path {
10188 caminho: "/etc/passwd `whoami`".into(),
10189 });
10190 let err = d.validate().unwrap_err();
10191 assert!(
10192 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10193 "got {err:?}",
10194 );
10195 }
10196
10197 #[test]
10198 fn fonte_caminho_shell_command_substitution_fires_before_trailing_slash() {
10199 // Cascade pin on the immediate-successor arm: a value
10200 // carrying both a backtick and a trailing `/`
10201 // (``"../`whoami`/"`` — the canonical "I tab-completed a
10202 // path that already had a backticked `whoami` substitution
10203 // tail" footgun) routes through
10204 // `FonteCaminhoShellCommandSubstitution` not
10205 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
10206 // is the more semantic-locating axis (an author who removes
10207 // the backtick typically also drops the trailing separator
10208 // since both are paste-from-shell artifacts).
10209 let d = dep_with_fonte(DepSource::Path {
10210 caminho: "../`whoami`/".into(),
10211 });
10212 let err = d.validate().unwrap_err();
10213 assert!(
10214 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10215 "got {err:?}",
10216 );
10217 }
10218
10219 #[test]
10220 fn fonte_caminho_shell_command_substitution_diagnostic_carries_offending_dep_and_caminho() {
10221 // Diagnostic-shape pin (peer with
10222 // `fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho`
10223 // on the closest single-byte peer arm): the error's Display
10224 // surfaces the offending `:nome` and the offending `:caminho`
10225 // verbatim, and names the shell-command-substitution footgun
10226 // explicitly so a `feira lint` run can render the diagnostic
10227 // without re-parsing.
10228 let d = dep_with_fonte(DepSource::Path {
10229 caminho: "../caixa-teia/`whoami`".into(),
10230 });
10231 let rendered = d.validate().unwrap_err().to_string();
10232 assert!(
10233 rendered.contains("caixa-teia"),
10234 "diagnostic must name the offending dep: {rendered}",
10235 );
10236 assert!(
10237 rendered.contains("../caixa-teia/`whoami`"),
10238 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10239 );
10240 assert!(
10241 rendered.contains('`'),
10242 "diagnostic must reference the backtick footgun: {rendered:?}",
10243 );
10244 assert!(
10245 rendered.contains("command-substitution"),
10246 "diagnostic must name the shell-command-substitution footgun: {rendered:?}",
10247 );
10248 }
10249
10250 #[test]
10251 fn validate_rejects_path_fonte_with_caminho_carrying_star_glob() {
10252 // The fail-before-pass-after pin for the canonical pathname-
10253 // expansion paste footgun: an author copies an `ls
10254 // ../caixa-teia/*` shell-listing tail into the `:caminho`
10255 // slot and silently passes every prior arm
10256 // (`Path::is_absolute` false on `..`, no control bytes, no
10257 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick,
10258 // doesn't end in `/`). The lacre embedded the value
10259 // verbatim, the resolver folded it through `Path::join`
10260 // looking for a literal `./../caixa-teia/*` subdirectory,
10261 // and the failure surfaced at resolve time with a non-self-
10262 // locating `No such file or directory` error. The new arm
10263 // moves the rejection to validate time and names the
10264 // offending dep + caminho + byte verbatim.
10265 let d = dep_with_fonte(DepSource::Path {
10266 caminho: "../caixa-teia/*".into(),
10267 });
10268 let err = d.validate().unwrap_err();
10269 let DepError::FonteCaminhoShellGlob {
10270 nome,
10271 caminho,
10272 byte,
10273 } = err
10274 else {
10275 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10276 };
10277 assert_eq!(nome, "caixa-teia");
10278 assert_eq!(caminho, "../caixa-teia/*");
10279 assert_eq!(byte, b'*');
10280 }
10281
10282 #[test]
10283 fn validate_rejects_path_fonte_with_caminho_carrying_question_glob() {
10284 // The symmetric single-char-wildcard paste shape
10285 // (`"../foo?"` — the canonical "I copied a `rm foo?` line
10286 // out of shell history" idiom). Pinned separately from the
10287 // `*` shape so the gate's contract is "any `*` or `?`
10288 // anywhere", not single-byte coverage.
10289 let d = dep_with_fonte(DepSource::Path {
10290 caminho: "../foo?".into(),
10291 });
10292 let err = d.validate().unwrap_err();
10293 let DepError::FonteCaminhoShellGlob { byte, .. } = err else {
10294 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10295 };
10296 assert_eq!(byte, b'?');
10297 }
10298
10299 #[test]
10300 fn validate_rejects_path_fonte_with_caminho_carrying_leading_star_glob() {
10301 // Leading-position `*` shape (`"*/caixa-teia"` — the
10302 // degenerate "I selected only the wildcard prefix out of a
10303 // shell-glob expression" idiom). Pinned separately from the
10304 // embedded-byte shapes so the gate covers every position,
10305 // not only mid-path.
10306 let d = dep_with_fonte(DepSource::Path {
10307 caminho: "*/caixa-teia".into(),
10308 });
10309 let err = d.validate().unwrap_err();
10310 assert!(
10311 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10312 "got {err:?}",
10313 );
10314 }
10315
10316 #[test]
10317 fn validate_rejects_path_fonte_with_caminho_carrying_double_star_recursive_glob() {
10318 // The bash/zsh `globstar` recursive-glob shape
10319 // (`"../caixa-teia/**/foo"` — the canonical "I copied a
10320 // `find ../caixa-teia/**/foo` recursive expansion" idiom).
10321 // The arm fires on the first `*` encountered; pinned so a
10322 // future arm that tries to distinguish single `*` from
10323 // double `**` doesn't break the broader contract.
10324 let d = dep_with_fonte(DepSource::Path {
10325 caminho: "../caixa-teia/**/foo".into(),
10326 });
10327 let err = d.validate().unwrap_err();
10328 assert!(
10329 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10330 "got {err:?}",
10331 );
10332 }
10333
10334 #[test]
10335 fn validate_rejects_path_fonte_with_caminho_carrying_dotted_extension_glob() {
10336 // The canonical extension-glob shape (`"../caixa-teia/*.lisp"`
10337 // — the "I selected `*.lisp` to mean every Lisp source file
10338 // in the dep root" footgun the prior arms structurally
10339 // cannot catch since `.` is a POSIX-valid path-component
10340 // byte). Pinned so the gate's contract covers the most
10341 // idiomatic glob-paste shape every author meets first.
10342 let d = dep_with_fonte(DepSource::Path {
10343 caminho: "../caixa-teia/*.lisp".into(),
10344 });
10345 let err = d.validate().unwrap_err();
10346 assert!(
10347 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10348 "got {err:?}",
10349 );
10350 }
10351
10352 #[test]
10353 fn validate_accepts_path_fonte_with_caminho_carrying_no_glob() {
10354 // The positive-control pin: the gate targets only `*` /
10355 // `?`, never adjacent printable ASCII or POSIX-valid bytes.
10356 // The canonical relative POSIX path (`"../caixa-teia"`) and
10357 // a nested deeply-pathed variant with adjacent printable
10358 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
10359 // to validate cleanly so the gate doesn't widen to a "no
10360 // printable punctuation anywhere" sweep that would defeat
10361 // the entire path-fonte author surface.
10362 let d = dep_with_fonte(DepSource::Path {
10363 caminho: "../caixa-teia/sub-dir.v2".into(),
10364 });
10365 d.validate().unwrap();
10366 }
10367
10368 #[test]
10369 fn fonte_caminho_shell_command_substitution_fires_before_shell_glob() {
10370 // Cascade pin on the immediate-predecessor arm: a value
10371 // carrying both a backtick and `*` (``"../`whoami`/*"`` —
10372 // the canonical "I pasted a `cd <backtick>whoami<backtick>/*`
10373 // command-substitution + glob chain") routes through
10374 // `FonteCaminhoShellCommandSubstitution` not
10375 // `FonteCaminhoShellGlob`. The CWE-78 shell-command-
10376 // injection vector is the load-bearing root-cause edit on
10377 // every probe-as-both value — same cascade discipline every
10378 // prior `:caminho` arm establishes.
10379 let d = dep_with_fonte(DepSource::Path {
10380 caminho: "../`whoami`/*".into(),
10381 });
10382 let err = d.validate().unwrap_err();
10383 assert!(
10384 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10385 "got {err:?}",
10386 );
10387 }
10388
10389 #[test]
10390 fn fonte_caminho_shell_background_fires_before_shell_glob() {
10391 // Cascade pin on the upstream shell-background arm: a value
10392 // carrying both `&` and `*` (`"../caixa-teia & ls /*"` — the
10393 // canonical "I pasted a `cmd & ls /*` background + glob
10394 // chain" footgun) routes through `FonteCaminhoShellBackground`
10395 // not `FonteCaminhoShellGlob`. The background-launch tail is
10396 // the load-bearing root-cause edit on every probe-as-both
10397 // value.
10398 let d = dep_with_fonte(DepSource::Path {
10399 caminho: "../caixa-teia & ls /*".into(),
10400 });
10401 let err = d.validate().unwrap_err();
10402 assert!(
10403 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10404 "got {err:?}",
10405 );
10406 }
10407
10408 #[test]
10409 fn fonte_caminho_shell_semicolon_fires_before_shell_glob() {
10410 // Cascade pin on the upstream shell-semicolon arm: a value
10411 // carrying both `;` and `*` (`"../caixa-teia; rm *"` — the
10412 // canonical sequential-cleanup + glob paste idiom) routes
10413 // through `FonteCaminhoShellSemicolon` not
10414 // `FonteCaminhoShellGlob`. The sequential-command-separator
10415 // paste is the load-bearing root-cause edit on every
10416 // probe-as-both value.
10417 let d = dep_with_fonte(DepSource::Path {
10418 caminho: "../caixa-teia; rm *".into(),
10419 });
10420 let err = d.validate().unwrap_err();
10421 assert!(
10422 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10423 "got {err:?}",
10424 );
10425 }
10426
10427 #[test]
10428 fn fonte_caminho_shell_pipe_fires_before_shell_glob() {
10429 // Cascade pin on the upstream shell-pipe arm: a value
10430 // carrying both `|` and `*` (`"../caixa-teia | ls *"` — the
10431 // canonical pipeline-to-glob paste idiom) routes through
10432 // `FonteCaminhoShellPipe` not `FonteCaminhoShellGlob`. The
10433 // pipeline-tail paste is the load-bearing root-cause edit
10434 // on every probe-as-both value.
10435 let d = dep_with_fonte(DepSource::Path {
10436 caminho: "../caixa-teia | ls *".into(),
10437 });
10438 let err = d.validate().unwrap_err();
10439 assert!(
10440 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10441 "got {err:?}",
10442 );
10443 }
10444
10445 #[test]
10446 fn fonte_caminho_shell_redirection_fires_before_shell_glob() {
10447 // Cascade pin on the upstream shell-redirection arm: a value
10448 // carrying both `>` and `*` (`"../caixa-teia>log *"` — the
10449 // canonical "I pasted a `cmd > log *` redirect-plus-glob
10450 // chain" footgun) routes through
10451 // `FonteCaminhoShellRedirection` not `FonteCaminhoShellGlob`.
10452 // The input/output redirection metachar carries the more
10453 // self-locating `byte` payload (it names which of `<` or `>`
10454 // triggered), so the prior arm wins on every probe-as-both
10455 // value.
10456 let d = dep_with_fonte(DepSource::Path {
10457 caminho: "../caixa-teia>log *".into(),
10458 });
10459 let err = d.validate().unwrap_err();
10460 assert!(
10461 matches!(
10462 err,
10463 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10464 ),
10465 "got {err:?}",
10466 );
10467 }
10468
10469 #[test]
10470 fn fonte_caminho_backslash_fires_before_shell_glob() {
10471 // Cascade pin on the upstream backslash arm: a value
10472 // carrying both `\` and `*` (`"..\caixa-teia\*"` — the
10473 // canonical "I pasted a Windows-shell `cd ..\path\*` glob
10474 // expression" footgun) routes through
10475 // `FonteCaminhoBackslash` not `FonteCaminhoShellGlob`. The
10476 // cross-host-OS-separator divergence is the load-bearing
10477 // axis on every probe-as-both value (an author who removes
10478 // the `\` is the root-cause edit; the `*` falls away in the
10479 // same edit since it's downstream of the Windows-shell
10480 // convention).
10481 let d = dep_with_fonte(DepSource::Path {
10482 caminho: "..\\caixa-teia\\*".into(),
10483 });
10484 let err = d.validate().unwrap_err();
10485 assert!(
10486 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10487 "got {err:?}",
10488 );
10489 }
10490
10491 #[test]
10492 fn fonte_caminho_control_char_fires_before_shell_glob() {
10493 // Cascade pin on the embedded-control-byte arm: a value
10494 // carrying both a control byte and `*` (`"../foo\n*"` — the
10495 // canonical paste-from-multiline-doc footgun where a
10496 // newline landed mid-caminho between two paste fragments)
10497 // routes through `FonteCaminhoControlChar` not
10498 // `FonteCaminhoShellGlob`. The POSIX-syscall-rejected-byte /
10499 // NUL-`CString::new`-fail diagnostic is the load-bearing
10500 // axis on every value that probes positive for both —
10501 // mirrors the cascade discipline on every prior arm.
10502 let d = dep_with_fonte(DepSource::Path {
10503 caminho: "../foo\n*".into(),
10504 });
10505 let err = d.validate().unwrap_err();
10506 assert!(
10507 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10508 "got {err:?}",
10509 );
10510 }
10511
10512 #[test]
10513 fn fonte_caminho_absolute_fires_before_shell_glob() {
10514 // Cascade pin on the load-bearing leading-byte arm: a
10515 // leading `/` value with embedded `*` (`"/etc/*"`) routes
10516 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellGlob`
10517 // — the host-layout-leak diagnostic is the load-bearing
10518 // axis, the glob byte is the secondary observation. Same
10519 // precedence logic as every prior leading-byte arm.
10520 let d = dep_with_fonte(DepSource::Path {
10521 caminho: "/etc/*".into(),
10522 });
10523 let err = d.validate().unwrap_err();
10524 assert!(
10525 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10526 "got {err:?}",
10527 );
10528 }
10529
10530 #[test]
10531 fn fonte_caminho_shell_glob_fires_before_trailing_slash() {
10532 // Cascade pin on the immediate-successor arm: a value
10533 // carrying both `*` and a trailing `/` (`"../foo*/"` — the
10534 // canonical "I tab-completed a path that already had a
10535 // glob-expansion tail" footgun) routes through
10536 // `FonteCaminhoShellGlob` not `FonteCaminhoTrailingSlash`.
10537 // The embedded shell-metachar is the more semantic-locating
10538 // axis (an author who removes the `*` typically also drops
10539 // the trailing separator since both are paste-from-shell
10540 // artifacts).
10541 let d = dep_with_fonte(DepSource::Path {
10542 caminho: "../foo*/".into(),
10543 });
10544 let err = d.validate().unwrap_err();
10545 assert!(
10546 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10547 "got {err:?}",
10548 );
10549 }
10550
10551 #[test]
10552 fn fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte() {
10553 // Diagnostic-shape pin (peer with
10554 // `fonte_caminho_shell_redirection_diagnostic_*` on the
10555 // closest two-byte peer arm): the error's Display surfaces
10556 // the offending `:nome`, the offending `:caminho` verbatim,
10557 // the offending byte's hex / character form, and names the
10558 // shell-glob / pathname-expansion footgun explicitly so a
10559 // `feira lint` run can render the diagnostic without
10560 // re-parsing.
10561 let d = dep_with_fonte(DepSource::Path {
10562 caminho: "../caixa-teia/*.lisp".into(),
10563 });
10564 let rendered = d.validate().unwrap_err().to_string();
10565 assert!(
10566 rendered.contains("caixa-teia"),
10567 "diagnostic must name the offending dep: {rendered}",
10568 );
10569 assert!(
10570 rendered.contains("../caixa-teia/*.lisp"),
10571 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10572 );
10573 assert!(
10574 rendered.contains("0x2a"),
10575 "diagnostic must surface the offending byte hex: {rendered:?}",
10576 );
10577 assert!(
10578 rendered.contains("glob"),
10579 "diagnostic must name the shell-glob footgun: {rendered:?}",
10580 );
10581 assert!(
10582 rendered.contains("pathname-expansion"),
10583 "diagnostic must reference the POSIX pathname-expansion vocabulary: {rendered:?}",
10584 );
10585 }
10586
10587 #[test]
10588 fn validate_rejects_path_fonte_with_caminho_carrying_modern_command_substitution() {
10589 // The fail-before-pass-after pin for the canonical modern-Bourne
10590 // command-substitution paste footgun: an author copies a
10591 // `cd ../caixa-teia/$(date)/build` shell-history one-liner whose
10592 // `$(<cmd>)` expansion would land the current date as a
10593 // subdirectory name and silently passed every prior arm
10594 // (`Path::is_absolute` false on `..`, no control bytes, no `\`,
10595 // no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no `*` /
10596 // `?`, doesn't end in `/`; the leading-`$` f4efe9c
10597 // `FonteCaminhoVarExpansion` arm doesn't fire because the `$`
10598 // sits mid-path). The lacre embedded the value verbatim, the
10599 // resolver folded it through `Path::join` looking for a literal
10600 // `./../caixa-teia/$(date)/build` subdirectory, and the failure
10601 // surfaced at resolve time with a non-self-locating `No such
10602 // file or directory` error. The new arm moves the rejection to
10603 // validate time and names the offending dep + caminho + byte
10604 // verbatim. The arm fires on the first `(` encountered (the
10605 // opening byte of `$(date)`).
10606 let d = dep_with_fonte(DepSource::Path {
10607 caminho: "../caixa-teia/$(date)/build".into(),
10608 });
10609 let err = d.validate().unwrap_err();
10610 let DepError::FonteCaminhoShellSubshellGrouping {
10611 nome,
10612 caminho,
10613 byte,
10614 } = err
10615 else {
10616 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10617 };
10618 assert_eq!(nome, "caixa-teia");
10619 assert_eq!(caminho, "../caixa-teia/$(date)/build");
10620 assert_eq!(byte, b'(');
10621 }
10622
10623 #[test]
10624 fn validate_rejects_path_fonte_with_caminho_carrying_close_paren() {
10625 // The symmetric close-paren paste shape (`"../caixa-teia)"` —
10626 // the degenerate "I selected an unbalanced closing paren out of
10627 // a shell-history block" idiom that probes for the cascade's
10628 // last-byte handling on a value carrying only the closing byte).
10629 // Pinned separately from the open-paren shape so the gate's
10630 // contract is "any `(` or `)` anywhere", not single-byte
10631 // coverage. Mirrors the peer `validate_rejects_path_fonte_with_\
10632 // caminho_carrying_question_glob` shape on the immediate-
10633 // predecessor `FonteCaminhoShellGlob` arm.
10634 let d = dep_with_fonte(DepSource::Path {
10635 caminho: "../caixa-teia)".into(),
10636 });
10637 let err = d.validate().unwrap_err();
10638 let DepError::FonteCaminhoShellSubshellGrouping { byte, .. } = err else {
10639 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10640 };
10641 assert_eq!(byte, b')');
10642 }
10643
10644 #[test]
10645 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_paren() {
10646 // Leading-position `(` shape (`"(cd foo)/caixa-teia"` — the
10647 // canonical "I selected a `(cd foo)` subshell-grouping prefix
10648 // out of a `(cd foo) && cmd` shell-history one-liner" idiom).
10649 // Pinned separately from the embedded-byte shape so the gate
10650 // covers every position, not only mid-path.
10651 let d = dep_with_fonte(DepSource::Path {
10652 caminho: "(cd foo)/caixa-teia".into(),
10653 });
10654 let err = d.validate().unwrap_err();
10655 assert!(
10656 matches!(
10657 err,
10658 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10659 ),
10660 "got {err:?}",
10661 );
10662 }
10663
10664 #[test]
10665 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_subshell_grouping_pair() {
10666 // The canonical balanced-pair shape (`"../(pwd)/caixa-teia"`
10667 // — the canonical "I copied a `(pwd)` working-directory-probe
10668 // subshell-grouping idiom every shell-history block carries"
10669 // footgun). The value carries no other cascade-preceding
10670 // shell metachar (`&` / `;` / `|` / `<` / `>` / backtick /
10671 // `*` / `?`) so the arm fires on the first `(` encountered;
10672 // pinned so a future arm that tries to distinguish the
10673 // opening from the closing byte doesn't break the broader
10674 // contract. Mirrors the peer
10675 // `validate_rejects_path_fonte_with_caminho_carrying_balanced_\
10676 // backtick_pair` shape on the upstream `FonteCaminhoShell\
10677 // CommandSubstitution` arm.
10678 let d = dep_with_fonte(DepSource::Path {
10679 caminho: "../(pwd)/caixa-teia".into(),
10680 });
10681 let err = d.validate().unwrap_err();
10682 assert!(
10683 matches!(
10684 err,
10685 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10686 ),
10687 "got {err:?}",
10688 );
10689 }
10690
10691 #[test]
10692 fn validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping() {
10693 // The positive-control pin: the gate targets only `(` / `)`,
10694 // never adjacent printable ASCII or POSIX-valid bytes. The
10695 // canonical relative POSIX path (`"../caixa-teia"`) and a
10696 // nested deeply-pathed variant with adjacent printable
10697 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10698 // validate cleanly so the gate doesn't widen to a "no printable
10699 // punctuation anywhere" sweep that would defeat the entire
10700 // path-fonte author surface.
10701 let d = dep_with_fonte(DepSource::Path {
10702 caminho: "../caixa-teia/sub-dir.v2".into(),
10703 });
10704 d.validate().unwrap();
10705 }
10706
10707 #[test]
10708 fn fonte_caminho_shell_glob_fires_before_shell_subshell_grouping() {
10709 // Cascade pin on the immediate-predecessor arm: a value
10710 // carrying both `*` and `(` (`"../caixa-teia/*(date)"` — the
10711 // canonical "I pasted a glob expansion followed by a
10712 // subshell-grouping tail" footgun) routes through
10713 // `FonteCaminhoShellGlob` not
10714 // `FonteCaminhoShellSubshellGrouping`. The pathname-expansion
10715 // shape is the more common shell-history paste idiom on every
10716 // probe-as-both value — same cascade discipline every prior
10717 // `:caminho` arm establishes.
10718 let d = dep_with_fonte(DepSource::Path {
10719 caminho: "../caixa-teia/*(date)".into(),
10720 });
10721 let err = d.validate().unwrap_err();
10722 assert!(
10723 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10724 "got {err:?}",
10725 );
10726 }
10727
10728 #[test]
10729 fn fonte_caminho_shell_command_substitution_fires_before_shell_subshell_grouping() {
10730 // Cascade pin on the upstream shell-command-substitution arm: a
10731 // value carrying both a backtick and `(` (``"../`whoami`/$(date)"``
10732 // — the canonical "I pasted a legacy-backtick + modern-paren
10733 // command-substitution chain" footgun) routes through
10734 // `FonteCaminhoShellCommandSubstitution` not
10735 // `FonteCaminhoShellSubshellGrouping`. The CWE-78 shell-
10736 // command-injection vector is the load-bearing root-cause edit
10737 // on every probe-as-both value.
10738 let d = dep_with_fonte(DepSource::Path {
10739 caminho: "../`whoami`/$(date)".into(),
10740 });
10741 let err = d.validate().unwrap_err();
10742 assert!(
10743 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10744 "got {err:?}",
10745 );
10746 }
10747
10748 #[test]
10749 fn fonte_caminho_shell_background_fires_before_shell_subshell_grouping() {
10750 // Cascade pin on the upstream shell-background arm: a value
10751 // carrying both `&` and `(` (`"../caixa-teia & (cd foo)"` —
10752 // the canonical "I pasted a `cmd & (cd foo)` background-launch
10753 // + subshell-grouping chain" footgun) routes through
10754 // `FonteCaminhoShellBackground` not
10755 // `FonteCaminhoShellSubshellGrouping`. The background-launch
10756 // tail is the load-bearing root-cause edit on every probe-as-
10757 // both value.
10758 let d = dep_with_fonte(DepSource::Path {
10759 caminho: "../caixa-teia & (cd foo)".into(),
10760 });
10761 let err = d.validate().unwrap_err();
10762 assert!(
10763 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10764 "got {err:?}",
10765 );
10766 }
10767
10768 #[test]
10769 fn fonte_caminho_shell_semicolon_fires_before_shell_subshell_grouping() {
10770 // Cascade pin on the upstream shell-semicolon arm: a value
10771 // carrying both `;` and `(` (`"../caixa-teia; (cd foo)"` —
10772 // the canonical sequential-cleanup + subshell-grouping paste
10773 // idiom) routes through `FonteCaminhoShellSemicolon` not
10774 // `FonteCaminhoShellSubshellGrouping`. The sequential-command-
10775 // separator paste is the load-bearing root-cause edit on
10776 // every probe-as-both value.
10777 let d = dep_with_fonte(DepSource::Path {
10778 caminho: "../caixa-teia; (cd foo)".into(),
10779 });
10780 let err = d.validate().unwrap_err();
10781 assert!(
10782 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10783 "got {err:?}",
10784 );
10785 }
10786
10787 #[test]
10788 fn fonte_caminho_shell_pipe_fires_before_shell_subshell_grouping() {
10789 // Cascade pin on the upstream shell-pipe arm: a value carrying
10790 // both `|` and `(` (`"../caixa-teia | (tee log)"` — the
10791 // canonical pipeline-to-subshell-grouping paste idiom) routes
10792 // through `FonteCaminhoShellPipe` not
10793 // `FonteCaminhoShellSubshellGrouping`. The pipeline-tail paste
10794 // is the load-bearing root-cause edit on every probe-as-both
10795 // value.
10796 let d = dep_with_fonte(DepSource::Path {
10797 caminho: "../caixa-teia | (tee log)".into(),
10798 });
10799 let err = d.validate().unwrap_err();
10800 assert!(
10801 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10802 "got {err:?}",
10803 );
10804 }
10805
10806 #[test]
10807 fn fonte_caminho_shell_redirection_fires_before_shell_subshell_grouping() {
10808 // Cascade pin on the upstream shell-redirection arm: a value
10809 // carrying both `>` and `(` (`"../caixa-teia>log (cd foo)"` —
10810 // the canonical "I pasted a `cmd > log (cd foo)` redirect-
10811 // plus-subshell-grouping chain" footgun) routes through
10812 // `FonteCaminhoShellRedirection` not
10813 // `FonteCaminhoShellSubshellGrouping`. The input/output
10814 // redirection metachar carries the more self-locating `byte`
10815 // payload (it names which of `<` or `>` triggered), so the
10816 // prior arm wins on every probe-as-both value.
10817 let d = dep_with_fonte(DepSource::Path {
10818 caminho: "../caixa-teia>log (cd foo)".into(),
10819 });
10820 let err = d.validate().unwrap_err();
10821 assert!(
10822 matches!(
10823 err,
10824 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10825 ),
10826 "got {err:?}",
10827 );
10828 }
10829
10830 #[test]
10831 fn fonte_caminho_backslash_fires_before_shell_subshell_grouping() {
10832 // Cascade pin on the upstream backslash arm: a value carrying
10833 // both `\` and `(` (`"..\caixa-teia\(cd foo)"` — the canonical
10834 // "I pasted a Windows-shell `cd ..\path\(cmd)` chain") routes
10835 // through `FonteCaminhoBackslash` not
10836 // `FonteCaminhoShellSubshellGrouping`. The cross-host-OS-
10837 // separator divergence is the load-bearing axis on every
10838 // probe-as-both value (an author who removes the `\` is the
10839 // root-cause edit; the `(` falls away in the same edit since
10840 // it's downstream of the Windows-shell convention).
10841 let d = dep_with_fonte(DepSource::Path {
10842 caminho: "..\\caixa-teia\\(cd foo)".into(),
10843 });
10844 let err = d.validate().unwrap_err();
10845 assert!(
10846 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10847 "got {err:?}",
10848 );
10849 }
10850
10851 #[test]
10852 fn fonte_caminho_control_char_fires_before_shell_subshell_grouping() {
10853 // Cascade pin on the embedded-control-byte arm: a value
10854 // carrying both a control byte and `(` (`"../foo\n(cd bar)"` —
10855 // the canonical paste-from-multiline-doc footgun where a
10856 // newline landed mid-caminho between two paste fragments)
10857 // routes through `FonteCaminhoControlChar` not
10858 // `FonteCaminhoShellSubshellGrouping`. The POSIX-syscall-
10859 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10860 // load-bearing axis on every value that probes positive for
10861 // both — mirrors the cascade discipline on every prior arm.
10862 let d = dep_with_fonte(DepSource::Path {
10863 caminho: "../foo\n(cd bar)".into(),
10864 });
10865 let err = d.validate().unwrap_err();
10866 assert!(
10867 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10868 "got {err:?}",
10869 );
10870 }
10871
10872 #[test]
10873 fn fonte_caminho_absolute_fires_before_shell_subshell_grouping() {
10874 // Cascade pin on the load-bearing leading-byte arm: a leading
10875 // `/` value with embedded `(` (`"/etc/(cd foo)"`) routes
10876 // through `FonteCaminhoAbsolute` not
10877 // `FonteCaminhoShellSubshellGrouping` — the host-layout-leak
10878 // diagnostic is the load-bearing axis, the subshell-grouping
10879 // byte is the secondary observation. Same precedence logic as
10880 // every prior leading-byte arm.
10881 let d = dep_with_fonte(DepSource::Path {
10882 caminho: "/etc/(cd foo)".into(),
10883 });
10884 let err = d.validate().unwrap_err();
10885 assert!(
10886 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10887 "got {err:?}",
10888 );
10889 }
10890
10891 #[test]
10892 fn fonte_caminho_var_expansion_fires_before_shell_subshell_grouping() {
10893 // Cascade pin on the upstream leading-`$` var-expansion arm: a
10894 // value carrying both a leading `$` and a `(` (`"$(date)/\
10895 // caixa-teia"` — the canonical "I pasted a `$(date)` modern-
10896 // command-substitution at the head of a sibling-workspace
10897 // path" footgun) routes through `FonteCaminhoVarExpansion` not
10898 // `FonteCaminhoShellSubshellGrouping`. The leading-byte
10899 // shell-variable-expansion is the more self-locating diagnostic
10900 // on values that probe as both — same load-bearing-leading-
10901 // byte cascade discipline every prior `:caminho` arm
10902 // establishes. Closing both halves of `$(<cmd>)` structurally
10903 // (leading `$` here, trailing `)` on the new arm) excludes the
10904 // entire modern Bourne command-substitution surface from the
10905 // typed `:caminho` accepted set; the cascade preserves the
10906 // narrower leading-byte diagnostic on values that probe both
10907 // halves at the canonical leading position.
10908 let d = dep_with_fonte(DepSource::Path {
10909 caminho: "$(date)/caixa-teia".into(),
10910 });
10911 let err = d.validate().unwrap_err();
10912 assert!(
10913 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
10914 "got {err:?}",
10915 );
10916 }
10917
10918 #[test]
10919 fn fonte_caminho_shell_subshell_grouping_fires_before_trailing_slash() {
10920 // Cascade pin on the immediate-successor arm: a value carrying
10921 // both `(` and a trailing `/` (`"../(cd foo)/"` — the canonical
10922 // "I tab-completed a path that already had a subshell-grouping
10923 // expansion tail" footgun) routes through
10924 // `FonteCaminhoShellSubshellGrouping` not
10925 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
10926 // the more semantic-locating axis (an author who removes the
10927 // `(` typically also drops the trailing separator since both
10928 // are paste-from-shell artifacts).
10929 let d = dep_with_fonte(DepSource::Path {
10930 caminho: "../(cd foo)/".into(),
10931 });
10932 let err = d.validate().unwrap_err();
10933 assert!(
10934 matches!(
10935 err,
10936 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10937 ),
10938 "got {err:?}",
10939 );
10940 }
10941
10942 #[test]
10943 fn fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
10944 // Diagnostic-shape pin (peer with
10945 // `fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte`
10946 // on the closest two-byte peer arm): the error's Display
10947 // surfaces the offending `:nome`, the offending `:caminho`
10948 // verbatim, the offending byte's hex / character form, and
10949 // names the shell-subshell-grouping footgun explicitly so a
10950 // `feira lint` run can render the diagnostic without re-
10951 // parsing.
10952 let d = dep_with_fonte(DepSource::Path {
10953 caminho: "../caixa-teia/$(date)/build".into(),
10954 });
10955 let rendered = d.validate().unwrap_err().to_string();
10956 assert!(
10957 rendered.contains("caixa-teia"),
10958 "diagnostic must name the offending dep: {rendered}",
10959 );
10960 assert!(
10961 rendered.contains("../caixa-teia/$(date)/build"),
10962 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10963 );
10964 assert!(
10965 rendered.contains("0x28"),
10966 "diagnostic must surface the offending byte hex: {rendered:?}",
10967 );
10968 assert!(
10969 rendered.contains("subshell-grouping"),
10970 "diagnostic must name the shell-subshell-grouping footgun: {rendered:?}",
10971 );
10972 assert!(
10973 rendered.contains("command-substitution"),
10974 "diagnostic must reference the `$(<cmd>)` command-substitution vocabulary: \
10975 {rendered:?}",
10976 );
10977 }
10978
10979 // ── shell-brace-expansion / URI-Template-placeholder arm ───────────
10980 //
10981 // Peer with the prior `FonteCaminhoShellSubshellGrouping` (`(` /
10982 // `)`) byte-pair arm: the same per-byte cascade with the same
10983 // self-locating `byte: u8` diagnostic on the orthogonal `{` /
10984 // `}` brace-expansion / URI-Template placeholder axis. The peer
10985 // [`crate::render::is_git_repo_url`] (42d8f9d) closes the same
10986 // byte pair on the sibling `:fonte :repo` axis under the same
10987 // banner.
10988
10989 #[test]
10990 fn validate_rejects_path_fonte_with_caminho_carrying_brace_expansion_fan_across_siblings() {
10991 // The fail-before-pass-after pin for the canonical paste-from-
10992 // shell-history brace-expansion footgun: an author copies a
10993 // `cd ../{caixa-teia,caixa-helm}/build` shell-history one-
10994 // liner whose `{a,b}` brace expansion fans across two siblings
10995 // and silently passed every prior arm (`Path::is_absolute`
10996 // false on `..`, no control bytes, no `\`, no `<` / `>`, no
10997 // `|`, no `;`, no `&`, no backtick, no `*` / `?`, no `(` /
10998 // `)`, doesn't end in `/`; the leading-`$` f4efe9c
10999 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11000 // value starts with `..` not `$`). The lacre embedded the
11001 // value verbatim, the resolver folded it through `Path::join`
11002 // looking for a literal `./../{caixa-teia,caixa-helm}/build`
11003 // subdirectory, and the failure surfaced at resolve time with
11004 // a non-self-locating `No such file or directory` error. The
11005 // new arm moves the rejection to validate time and names the
11006 // offending dep + caminho + byte verbatim. The arm fires on
11007 // the first `{` encountered.
11008 let d = dep_with_fonte(DepSource::Path {
11009 caminho: "../{caixa-teia,caixa-helm}/build".into(),
11010 });
11011 let err = d.validate().unwrap_err();
11012 let DepError::FonteCaminhoShellBraceExpansion {
11013 nome,
11014 caminho,
11015 byte,
11016 } = err
11017 else {
11018 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
11019 };
11020 assert_eq!(nome, "caixa-teia");
11021 assert_eq!(caminho, "../{caixa-teia,caixa-helm}/build");
11022 assert_eq!(byte, b'{');
11023 }
11024
11025 #[test]
11026 fn validate_rejects_path_fonte_with_caminho_carrying_close_brace() {
11027 // The symmetric close-brace paste shape (`"../caixa-teia}"` —
11028 // the degenerate "I selected an unbalanced closing brace out
11029 // of a shell-history block" idiom that probes for the
11030 // cascade's last-byte handling on a value carrying only the
11031 // closing byte). Pinned separately from the open-brace shape
11032 // so the gate's contract is "any `{` or `}` anywhere", not
11033 // single-byte coverage. Mirrors the peer
11034 // `validate_rejects_path_fonte_with_caminho_carrying_close_paren`
11035 // shape on the immediate-predecessor `FonteCaminhoShellSubshellGrouping`
11036 // arm.
11037 let d = dep_with_fonte(DepSource::Path {
11038 caminho: "../caixa-teia}".into(),
11039 });
11040 let err = d.validate().unwrap_err();
11041 let DepError::FonteCaminhoShellBraceExpansion { byte, .. } = err else {
11042 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
11043 };
11044 assert_eq!(byte, b'}');
11045 }
11046
11047 #[test]
11048 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_brace() {
11049 // Leading-position `{` shape (`"{caixa-teia,caixa-helm}/build"`
11050 // — the canonical "I selected a `{a,b}` brace-expansion prefix
11051 // out of a shell-history one-liner" idiom). Pinned separately
11052 // from the embedded-byte shape so the gate covers every
11053 // position, not only mid-path.
11054 let d = dep_with_fonte(DepSource::Path {
11055 caminho: "{caixa-teia,caixa-helm}/build".into(),
11056 });
11057 let err = d.validate().unwrap_err();
11058 assert!(
11059 matches!(
11060 err,
11061 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11062 ),
11063 "got {err:?}",
11064 );
11065 }
11066
11067 #[test]
11068 fn validate_rejects_path_fonte_with_caminho_carrying_uri_template_placeholder() {
11069 // The canonical URI-Template / Mustache / Helm doubled-brace
11070 // placeholder shape (`"../{{org}}/caixa-teia"` — the canonical
11071 // "I copied a `https://github.com/{{org}}/caixa-teia` README
11072 // quick-start / OpenAPI spec / Helm chart `home:` template
11073 // and forgot to substitute the placeholder" footgun). The arm
11074 // fires on the first `{` encountered; pinned so the gate's
11075 // coverage extends from the bare-brace shell-history shape to
11076 // the doubled-brace URI-Template / templating-engine shape.
11077 // Mirrors the peer 42d8f9d `is_git_repo_url` arm on the
11078 // sibling `:fonte :repo` axis.
11079 let d = dep_with_fonte(DepSource::Path {
11080 caminho: "../{{org}}/caixa-teia".into(),
11081 });
11082 let err = d.validate().unwrap_err();
11083 assert!(
11084 matches!(
11085 err,
11086 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11087 ),
11088 "got {err:?}",
11089 );
11090 }
11091
11092 #[test]
11093 fn validate_rejects_path_fonte_with_caminho_carrying_brace_range_expansion() {
11094 // The canonical bash brace-range-expansion shape (`"../caixa-
11095 // v{1..10}"` — the `{1..10}` sequence expansion every bash /
11096 // zsh `for i in {1..10}; do …; done` idiom uses, the symmetric
11097 // sequence-range form to the `{a,b,c}` comma-separated form).
11098 // The arm fires on the first `{` encountered; pinned so the
11099 // gate's coverage extends from the comma-separated form to
11100 // the integer-range form.
11101 let d = dep_with_fonte(DepSource::Path {
11102 caminho: "../caixa-v{1..10}".into(),
11103 });
11104 let err = d.validate().unwrap_err();
11105 assert!(
11106 matches!(
11107 err,
11108 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11109 ),
11110 "got {err:?}",
11111 );
11112 }
11113
11114 #[test]
11115 fn validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion() {
11116 // The positive-control pin: the gate targets only `{` / `}`,
11117 // never adjacent printable ASCII or POSIX-valid bytes. The
11118 // canonical relative POSIX path (`"../caixa-teia"`) and a
11119 // nested deeply-pathed variant with adjacent printable
11120 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
11121 // validate cleanly so the gate doesn't widen to a "no
11122 // printable punctuation anywhere" sweep that would defeat
11123 // the entire path-fonte author surface. Peer with
11124 // `validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping`
11125 // on the immediate-predecessor arm.
11126 let d = dep_with_fonte(DepSource::Path {
11127 caminho: "../caixa-teia/sub-dir.v2".into(),
11128 });
11129 d.validate().unwrap();
11130 }
11131
11132 #[test]
11133 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_brace_expansion() {
11134 // Cascade pin on the immediate-predecessor arm: a value
11135 // carrying both `(` and `{` (`"../(cd foo)/{a,b}"` — the
11136 // canonical "I pasted a subshell-grouping followed by a
11137 // brace-expansion tail" footgun) routes through
11138 // `FonteCaminhoShellSubshellGrouping` not
11139 // `FonteCaminhoShellBraceExpansion`. The subshell-grouping
11140 // shape is the more semantic-locating axis on every probe-
11141 // as-both value because it closes both halves of the modern
11142 // Bourne `$(<cmd>)` command-substitution surface — same
11143 // cascade discipline every prior `:caminho` arm establishes.
11144 let d = dep_with_fonte(DepSource::Path {
11145 caminho: "../(cd foo)/{a,b}".into(),
11146 });
11147 let err = d.validate().unwrap_err();
11148 assert!(
11149 matches!(
11150 err,
11151 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11152 ),
11153 "got {err:?}",
11154 );
11155 }
11156
11157 #[test]
11158 fn fonte_caminho_shell_glob_fires_before_shell_brace_expansion() {
11159 // Cascade pin on the upstream shell-glob arm: a value carrying
11160 // both `*` and `{` (`"../caixa-teia/*{a,b}"` — the canonical
11161 // "I pasted a glob expansion followed by a brace-expansion
11162 // tail" footgun) routes through `FonteCaminhoShellGlob` not
11163 // `FonteCaminhoShellBraceExpansion`. The pathname-expansion
11164 // shape is the load-bearing root-cause edit on every
11165 // probe-as-both value.
11166 let d = dep_with_fonte(DepSource::Path {
11167 caminho: "../caixa-teia/*{a,b}".into(),
11168 });
11169 let err = d.validate().unwrap_err();
11170 assert!(
11171 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11172 "got {err:?}",
11173 );
11174 }
11175
11176 #[test]
11177 fn fonte_caminho_shell_command_substitution_fires_before_shell_brace_expansion() {
11178 // Cascade pin on the upstream shell-command-substitution arm:
11179 // a value carrying both a backtick and `{` (``"../`whoami`/{a,b}"``
11180 // — the canonical "I pasted a legacy-backtick command-
11181 // substitution followed by a brace-expansion fan-out" footgun)
11182 // routes through `FonteCaminhoShellCommandSubstitution` not
11183 // `FonteCaminhoShellBraceExpansion`. The CWE-78 shell-
11184 // command-injection vector is the load-bearing root-cause
11185 // edit on every probe-as-both value.
11186 let d = dep_with_fonte(DepSource::Path {
11187 caminho: "../`whoami`/{a,b}".into(),
11188 });
11189 let err = d.validate().unwrap_err();
11190 assert!(
11191 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11192 "got {err:?}",
11193 );
11194 }
11195
11196 #[test]
11197 fn fonte_caminho_shell_background_fires_before_shell_brace_expansion() {
11198 // Cascade pin on the upstream shell-background arm: a value
11199 // carrying both `&` and `{` (`"../caixa-teia & {a,b}"` — the
11200 // canonical "I pasted a `cmd & {fork-fan}` background-launch
11201 // + brace-expansion chain" footgun) routes through
11202 // `FonteCaminhoShellBackground` not
11203 // `FonteCaminhoShellBraceExpansion`. The background-launch
11204 // tail is the load-bearing root-cause edit on every
11205 // probe-as-both value.
11206 let d = dep_with_fonte(DepSource::Path {
11207 caminho: "../caixa-teia & {a,b}".into(),
11208 });
11209 let err = d.validate().unwrap_err();
11210 assert!(
11211 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11212 "got {err:?}",
11213 );
11214 }
11215
11216 #[test]
11217 fn fonte_caminho_shell_semicolon_fires_before_shell_brace_expansion() {
11218 // Cascade pin on the upstream shell-semicolon arm: a value
11219 // carrying both `;` and `{` (`"../caixa-teia; {a,b}"` — the
11220 // canonical sequential-cleanup + brace-expansion paste
11221 // idiom) routes through `FonteCaminhoShellSemicolon` not
11222 // `FonteCaminhoShellBraceExpansion`. The sequential-command-
11223 // separator paste is the load-bearing root-cause edit on
11224 // every probe-as-both value.
11225 let d = dep_with_fonte(DepSource::Path {
11226 caminho: "../caixa-teia; {a,b}".into(),
11227 });
11228 let err = d.validate().unwrap_err();
11229 assert!(
11230 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11231 "got {err:?}",
11232 );
11233 }
11234
11235 #[test]
11236 fn fonte_caminho_shell_pipe_fires_before_shell_brace_expansion() {
11237 // Cascade pin on the upstream shell-pipe arm: a value
11238 // carrying both `|` and `{` (`"../caixa-teia | {tee,cat}"`
11239 // — the canonical pipeline-to-brace-expansion paste idiom)
11240 // routes through `FonteCaminhoShellPipe` not
11241 // `FonteCaminhoShellBraceExpansion`. The pipeline-tail paste
11242 // is the load-bearing root-cause edit on every probe-as-
11243 // both value.
11244 let d = dep_with_fonte(DepSource::Path {
11245 caminho: "../caixa-teia | {tee,cat}".into(),
11246 });
11247 let err = d.validate().unwrap_err();
11248 assert!(
11249 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11250 "got {err:?}",
11251 );
11252 }
11253
11254 #[test]
11255 fn fonte_caminho_shell_redirection_fires_before_shell_brace_expansion() {
11256 // Cascade pin on the upstream shell-redirection arm: a value
11257 // carrying both `>` and `{` (`"../caixa-teia>log {a,b}"` —
11258 // the canonical "I pasted a `cmd > log {a,b}` redirect-
11259 // plus-brace-expansion chain" footgun) routes through
11260 // `FonteCaminhoShellRedirection` not
11261 // `FonteCaminhoShellBraceExpansion`. The input/output
11262 // redirection metachar carries the more self-locating
11263 // `byte` payload, so the prior arm wins on every probe-
11264 // as-both value.
11265 let d = dep_with_fonte(DepSource::Path {
11266 caminho: "../caixa-teia>log {a,b}".into(),
11267 });
11268 let err = d.validate().unwrap_err();
11269 assert!(
11270 matches!(
11271 err,
11272 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11273 ),
11274 "got {err:?}",
11275 );
11276 }
11277
11278 #[test]
11279 fn fonte_caminho_backslash_fires_before_shell_brace_expansion() {
11280 // Cascade pin on the upstream backslash arm: a value
11281 // carrying both `\` and `{` (`"..\caixa-teia\{a,b}"` — the
11282 // canonical "I pasted a Windows-shell `cd ..\path\{a,b}`
11283 // chain") routes through `FonteCaminhoBackslash` not
11284 // `FonteCaminhoShellBraceExpansion`. The cross-host-OS-
11285 // separator divergence is the load-bearing axis on every
11286 // probe-as-both value.
11287 let d = dep_with_fonte(DepSource::Path {
11288 caminho: "..\\caixa-teia\\{a,b}".into(),
11289 });
11290 let err = d.validate().unwrap_err();
11291 assert!(
11292 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11293 "got {err:?}",
11294 );
11295 }
11296
11297 #[test]
11298 fn fonte_caminho_control_char_fires_before_shell_brace_expansion() {
11299 // Cascade pin on the embedded-control-byte arm: a value
11300 // carrying both a control byte and `{` (`"../foo\n{a,b}"` —
11301 // the canonical paste-from-multiline-doc footgun where a
11302 // newline landed mid-caminho between two paste fragments)
11303 // routes through `FonteCaminhoControlChar` not
11304 // `FonteCaminhoShellBraceExpansion`. The POSIX-syscall-
11305 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
11306 // load-bearing axis on every value that probes positive for
11307 // both — mirrors the cascade discipline on every prior arm.
11308 let d = dep_with_fonte(DepSource::Path {
11309 caminho: "../foo\n{a,b}".into(),
11310 });
11311 let err = d.validate().unwrap_err();
11312 assert!(
11313 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11314 "got {err:?}",
11315 );
11316 }
11317
11318 #[test]
11319 fn fonte_caminho_absolute_fires_before_shell_brace_expansion() {
11320 // Cascade pin on the load-bearing leading-byte arm: a
11321 // leading `/` value with embedded `{` (`"/etc/{a,b}"`)
11322 // routes through `FonteCaminhoAbsolute` not
11323 // `FonteCaminhoShellBraceExpansion` — the host-layout-leak
11324 // diagnostic is the load-bearing axis, the brace-expansion
11325 // byte is the secondary observation. Same precedence logic
11326 // as every prior leading-byte arm.
11327 let d = dep_with_fonte(DepSource::Path {
11328 caminho: "/etc/{a,b}".into(),
11329 });
11330 let err = d.validate().unwrap_err();
11331 assert!(
11332 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11333 "got {err:?}",
11334 );
11335 }
11336
11337 #[test]
11338 fn fonte_caminho_var_expansion_fires_before_shell_brace_expansion() {
11339 // Cascade pin on the upstream leading-`$` var-expansion
11340 // arm: a value carrying both a leading `$` and a `{`
11341 // (`"${ORG}/caixa-teia"` — the canonical "I pasted a
11342 // `${ORG}` shell-variable + curly-brace expansion at the
11343 // head of a sibling-workspace path" footgun) routes through
11344 // `FonteCaminhoVarExpansion` not
11345 // `FonteCaminhoShellBraceExpansion`. The leading-byte
11346 // shell-variable-expansion is the more self-locating
11347 // diagnostic on values that probe as both — same
11348 // load-bearing-leading-byte cascade discipline every prior
11349 // `:caminho` arm establishes.
11350 let d = dep_with_fonte(DepSource::Path {
11351 caminho: "${ORG}/caixa-teia".into(),
11352 });
11353 let err = d.validate().unwrap_err();
11354 assert!(
11355 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11356 "got {err:?}",
11357 );
11358 }
11359
11360 #[test]
11361 fn fonte_caminho_shell_brace_expansion_fires_before_trailing_slash() {
11362 // Cascade pin on the immediate-successor arm: a value
11363 // carrying both `{` and a trailing `/`
11364 // (`"../{caixa-teia,caixa-helm}/"` — the canonical "I
11365 // tab-completed a path that already had a brace-expansion
11366 // expansion tail" footgun) routes through
11367 // `FonteCaminhoShellBraceExpansion` not
11368 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11369 // is the more semantic-locating axis (an author who removes
11370 // the `{` typically also drops the trailing separator since
11371 // both are paste-from-shell artifacts).
11372 let d = dep_with_fonte(DepSource::Path {
11373 caminho: "../{caixa-teia,caixa-helm}/".into(),
11374 });
11375 let err = d.validate().unwrap_err();
11376 assert!(
11377 matches!(
11378 err,
11379 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11380 ),
11381 "got {err:?}",
11382 );
11383 }
11384
11385 #[test]
11386 fn fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11387 // Diagnostic-shape pin (peer with
11388 // `fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
11389 // on the closest two-byte peer arm): the error's Display
11390 // surfaces the offending `:nome`, the offending `:caminho`
11391 // verbatim, the offending byte's hex / character form, and
11392 // names the shell-brace-expansion / URI-Template footgun
11393 // explicitly so a `feira lint` run can render the diagnostic
11394 // without re-parsing.
11395 let d = dep_with_fonte(DepSource::Path {
11396 caminho: "../{caixa-teia,caixa-helm}/build".into(),
11397 });
11398 let rendered = d.validate().unwrap_err().to_string();
11399 assert!(
11400 rendered.contains("caixa-teia"),
11401 "diagnostic must name the offending dep: {rendered}",
11402 );
11403 assert!(
11404 rendered.contains("../{caixa-teia,caixa-helm}/build"),
11405 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11406 );
11407 assert!(
11408 rendered.contains("0x7b"),
11409 "diagnostic must surface the offending byte hex: {rendered:?}",
11410 );
11411 assert!(
11412 rendered.contains("brace-expansion"),
11413 "diagnostic must name the shell-brace-expansion footgun: {rendered:?}",
11414 );
11415 assert!(
11416 rendered.contains("URI Template"),
11417 "diagnostic must reference the RFC-6570 URI-Template-placeholder vocabulary: \
11418 {rendered:?}",
11419 );
11420 }
11421
11422 #[test]
11423 fn validate_rejects_path_fonte_with_caminho_carrying_bracket_glob_character_class() {
11424 // The canonical paste-from-shell-history bracket-glob /
11425 // character-class footgun: an author copies a
11426 // `cd ../caixa-[a-z]/build` shell-history one-liner whose
11427 // `[a-z]` POSIX glob character-class matches every lowercase-
11428 // ASCII-suffix sibling caixa directory and silently passed
11429 // every prior arm (`Path::is_absolute` false on `..`, no
11430 // control bytes, no `\`, no `<` / `>`, no `|`, no `;`, no
11431 // `&`, no backtick, no `*` / `?`, no `(` / `)`, no `{` /
11432 // `}`, doesn't end in `/`; the leading-`$` f4efe9c
11433 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11434 // value starts with `..` not `$`). The lacre embedded the
11435 // value verbatim, the resolver folded it through
11436 // `Path::join` looking for a literal `./../caixa-[a-z]/
11437 // build` subdirectory, and the failure surfaced at resolve
11438 // time with a non-self-locating `No such file or directory`
11439 // error. The new arm moves the rejection to validate time
11440 // and names the offending dep + caminho + byte verbatim.
11441 // The arm fires on the first `[` encountered.
11442 let d = dep_with_fonte(DepSource::Path {
11443 caminho: "../caixa-[a-z]/build".into(),
11444 });
11445 let err = d.validate().unwrap_err();
11446 let DepError::FonteCaminhoShellBracketExpansion {
11447 nome,
11448 caminho,
11449 byte,
11450 } = err
11451 else {
11452 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11453 };
11454 assert_eq!(nome, "caixa-teia");
11455 assert_eq!(caminho, "../caixa-[a-z]/build");
11456 assert_eq!(byte, b'[');
11457 }
11458
11459 #[test]
11460 fn validate_rejects_path_fonte_with_caminho_carrying_close_bracket() {
11461 // The symmetric close-bracket paste shape (`"../caixa-teia]"`
11462 // — the degenerate "I selected an unbalanced closing bracket
11463 // out of a glob character-class block" idiom that probes for
11464 // the cascade's last-byte handling on a value carrying only
11465 // the closing byte). Pinned separately from the open-bracket
11466 // shape so the gate's contract is "any `[` or `]` anywhere",
11467 // not single-byte coverage. Mirrors the peer
11468 // `validate_rejects_path_fonte_with_caminho_carrying_close_brace`
11469 // shape on the immediate-predecessor
11470 // `FonteCaminhoShellBraceExpansion` arm.
11471 let d = dep_with_fonte(DepSource::Path {
11472 caminho: "../caixa-teia]".into(),
11473 });
11474 let err = d.validate().unwrap_err();
11475 let DepError::FonteCaminhoShellBracketExpansion { byte, .. } = err else {
11476 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11477 };
11478 assert_eq!(byte, b']');
11479 }
11480
11481 #[test]
11482 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_bracket() {
11483 // Leading-position `[` shape (`"[caixa-teia]/build"` — the
11484 // canonical "I selected a `[caixa-teia]` TOML-table-header /
11485 // glob-character-class prefix out of an aligned config /
11486 // shell-history one-liner" idiom). Pinned separately from
11487 // the embedded-byte shape so the gate covers every position,
11488 // not only mid-path.
11489 let d = dep_with_fonte(DepSource::Path {
11490 caminho: "[caixa-teia]/build".into(),
11491 });
11492 let err = d.validate().unwrap_err();
11493 assert!(
11494 matches!(
11495 err,
11496 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11497 ),
11498 "got {err:?}",
11499 );
11500 }
11501
11502 #[test]
11503 fn validate_rejects_path_fonte_with_caminho_carrying_toml_inline_array() {
11504 // The canonical TOML inline-array / YAML flow-sequence
11505 // paste shape (`"../[\"a\", \"b\"]/caixa-teia"` — the
11506 // canonical "I copied a `features = [\"a\", \"b\"]` TOML
11507 // inline-array out of a sibling-Cargo manifest" cross-idiom
11508 // leak; the symmetric YAML flow-sequence form `paths: [/a,
11509 // /b]` paste-from-values.yaml shape carries the same
11510 // bracket pair). The arm fires on the first `[` encountered;
11511 // pinned so the gate's coverage extends from the bare-
11512 // bracket glob-character-class shape to the TOML / YAML /
11513 // JSON array-literal shape.
11514 let d = dep_with_fonte(DepSource::Path {
11515 caminho: "../[\"a\", \"b\"]/caixa-teia".into(),
11516 });
11517 let err = d.validate().unwrap_err();
11518 assert!(
11519 matches!(
11520 err,
11521 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11522 ),
11523 "got {err:?}",
11524 );
11525 }
11526
11527 #[test]
11528 fn validate_rejects_path_fonte_with_caminho_carrying_shell_test_builtin() {
11529 // The canonical POSIX `test` / `[` builtin command paste
11530 // shape (`"../[ -d caixa-teia ]"` — the `[ <expr> ]` shell-
11531 // script conditional every paste-from-shell-script idiom
11532 // carries; bash's `[[ <expr> ]]` extended-test grammar
11533 // would surface the same byte pair). The arm fires on the
11534 // first `[` encountered; pinned so the gate's coverage
11535 // extends from the embedded-glob-character-class shape to
11536 // the leading-`test`-builtin / extended-test form.
11537 let d = dep_with_fonte(DepSource::Path {
11538 caminho: "../[ -d caixa-teia ]".into(),
11539 });
11540 let err = d.validate().unwrap_err();
11541 assert!(
11542 matches!(
11543 err,
11544 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11545 ),
11546 "got {err:?}",
11547 );
11548 }
11549
11550 #[test]
11551 fn validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion() {
11552 // The positive-control pin: the gate targets only `[` /
11553 // `]`, never adjacent printable ASCII or POSIX-valid bytes.
11554 // The canonical relative POSIX path (`"../caixa-teia"`) and
11555 // a nested deeply-pathed variant with adjacent printable
11556 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11557 // to validate cleanly so the gate doesn't widen to a "no
11558 // printable punctuation anywhere" sweep that would defeat
11559 // the entire path-fonte author surface. Peer with
11560 // `validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion`
11561 // on the immediate-predecessor arm.
11562 let d = dep_with_fonte(DepSource::Path {
11563 caminho: "../caixa-teia/sub-dir.v2".into(),
11564 });
11565 d.validate().unwrap();
11566 }
11567
11568 #[test]
11569 fn fonte_caminho_shell_brace_expansion_fires_before_shell_bracket_expansion() {
11570 // Cascade pin on the immediate-predecessor arm: a value
11571 // carrying both `{` and `[` (`"../{a,b}[ch]"` — the
11572 // canonical "I pasted a brace-expansion fan followed by a
11573 // glob-character-class tail" footgun) routes through
11574 // `FonteCaminhoShellBraceExpansion` not
11575 // `FonteCaminhoShellBracketExpansion`. The brace-expansion
11576 // fan is the load-bearing root-cause edit on every
11577 // probe-as-both value because the bracket-class tail
11578 // typically rides on a prior brace-expansion expansion;
11579 // same cascade discipline every prior `:caminho` arm
11580 // establishes.
11581 let d = dep_with_fonte(DepSource::Path {
11582 caminho: "../{a,b}[ch]".into(),
11583 });
11584 let err = d.validate().unwrap_err();
11585 assert!(
11586 matches!(
11587 err,
11588 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11589 ),
11590 "got {err:?}",
11591 );
11592 }
11593
11594 #[test]
11595 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_bracket_expansion() {
11596 // Cascade pin on the upstream shell-subshell-grouping arm:
11597 // a value carrying both `(` and `[` (`"../(cd foo)/[ch]"` —
11598 // the canonical "I pasted a subshell-grouping followed by
11599 // a glob-character-class tail" footgun) routes through
11600 // `FonteCaminhoShellSubshellGrouping` not
11601 // `FonteCaminhoShellBracketExpansion`. The modern Bourne
11602 // `$(<cmd>)` command-substitution boundary is the load-
11603 // bearing axis on every probe-as-both value.
11604 let d = dep_with_fonte(DepSource::Path {
11605 caminho: "../(cd foo)/[ch]".into(),
11606 });
11607 let err = d.validate().unwrap_err();
11608 assert!(
11609 matches!(
11610 err,
11611 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11612 ),
11613 "got {err:?}",
11614 );
11615 }
11616
11617 #[test]
11618 fn fonte_caminho_shell_glob_fires_before_shell_bracket_expansion() {
11619 // Cascade pin on the upstream shell-glob arm: a value
11620 // carrying both `*` and `[` (`"../caixa-teia/*[ch]"` — the
11621 // canonical "I pasted a `*.[ch]` C-source-file glob whose
11622 // unbounded `*` precedes the bracket character-class"
11623 // footgun) routes through `FonteCaminhoShellGlob` not
11624 // `FonteCaminhoShellBracketExpansion`. The unbounded
11625 // pathname-expansion sentinel is the load-bearing root-
11626 // cause edit on every probe-as-both value — the unbounded
11627 // `*` carries the more aggressive expansion vector than
11628 // the bounded `[ch]` class, so the prior arm wins.
11629 let d = dep_with_fonte(DepSource::Path {
11630 caminho: "../caixa-teia/*[ch]".into(),
11631 });
11632 let err = d.validate().unwrap_err();
11633 assert!(
11634 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11635 "got {err:?}",
11636 );
11637 }
11638
11639 #[test]
11640 fn fonte_caminho_shell_command_substitution_fires_before_shell_bracket_expansion() {
11641 // Cascade pin on the upstream shell-command-substitution
11642 // arm: a value carrying both a backtick and `[`
11643 // (``"../`whoami`/[ch]"`` — the canonical "I pasted a
11644 // legacy-backtick command-substitution followed by a
11645 // glob-character-class tail" footgun) routes through
11646 // `FonteCaminhoShellCommandSubstitution` not
11647 // `FonteCaminhoShellBracketExpansion`. The CWE-78 shell-
11648 // command-injection vector is the load-bearing root-cause
11649 // edit on every probe-as-both value.
11650 let d = dep_with_fonte(DepSource::Path {
11651 caminho: "../`whoami`/[ch]".into(),
11652 });
11653 let err = d.validate().unwrap_err();
11654 assert!(
11655 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11656 "got {err:?}",
11657 );
11658 }
11659
11660 #[test]
11661 fn fonte_caminho_shell_background_fires_before_shell_bracket_expansion() {
11662 // Cascade pin on the upstream shell-background arm: a
11663 // value carrying both `&` and `[` (`"../caixa-teia & [ch]"`
11664 // — the canonical "I pasted a `cmd & [glob]` background-
11665 // launch + bracket-class chain" footgun) routes through
11666 // `FonteCaminhoShellBackground` not
11667 // `FonteCaminhoShellBracketExpansion`. The background-
11668 // launch tail is the load-bearing root-cause edit on
11669 // every probe-as-both value.
11670 let d = dep_with_fonte(DepSource::Path {
11671 caminho: "../caixa-teia & [ch]".into(),
11672 });
11673 let err = d.validate().unwrap_err();
11674 assert!(
11675 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11676 "got {err:?}",
11677 );
11678 }
11679
11680 #[test]
11681 fn fonte_caminho_shell_semicolon_fires_before_shell_bracket_expansion() {
11682 // Cascade pin on the upstream shell-semicolon arm: a value
11683 // carrying both `;` and `[` (`"../caixa-teia; [ch]"` — the
11684 // canonical sequential-cleanup + bracket-class paste
11685 // idiom) routes through `FonteCaminhoShellSemicolon` not
11686 // `FonteCaminhoShellBracketExpansion`. The sequential-
11687 // command-separator paste is the load-bearing root-cause
11688 // edit on every probe-as-both value.
11689 let d = dep_with_fonte(DepSource::Path {
11690 caminho: "../caixa-teia; [ch]".into(),
11691 });
11692 let err = d.validate().unwrap_err();
11693 assert!(
11694 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11695 "got {err:?}",
11696 );
11697 }
11698
11699 #[test]
11700 fn fonte_caminho_shell_pipe_fires_before_shell_bracket_expansion() {
11701 // Cascade pin on the upstream shell-pipe arm: a value
11702 // carrying both `|` and `[` (`"../caixa-teia | [tee]"` —
11703 // the canonical pipeline-to-bracket-class paste idiom)
11704 // routes through `FonteCaminhoShellPipe` not
11705 // `FonteCaminhoShellBracketExpansion`. The pipeline-tail
11706 // paste is the load-bearing root-cause edit on every
11707 // probe-as-both value.
11708 let d = dep_with_fonte(DepSource::Path {
11709 caminho: "../caixa-teia | [tee]".into(),
11710 });
11711 let err = d.validate().unwrap_err();
11712 assert!(
11713 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11714 "got {err:?}",
11715 );
11716 }
11717
11718 #[test]
11719 fn fonte_caminho_shell_redirection_fires_before_shell_bracket_expansion() {
11720 // Cascade pin on the upstream shell-redirection arm: a
11721 // value carrying both `>` and `[` (`"../caixa-teia>log
11722 // [ch]"` — the canonical "I pasted a `cmd > log [glob]`
11723 // redirect-plus-bracket chain" footgun) routes through
11724 // `FonteCaminhoShellRedirection` not
11725 // `FonteCaminhoShellBracketExpansion`. The input/output
11726 // redirection metachar carries the more self-locating
11727 // `byte` payload, so the prior arm wins on every
11728 // probe-as-both value.
11729 let d = dep_with_fonte(DepSource::Path {
11730 caminho: "../caixa-teia>log [ch]".into(),
11731 });
11732 let err = d.validate().unwrap_err();
11733 assert!(
11734 matches!(
11735 err,
11736 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11737 ),
11738 "got {err:?}",
11739 );
11740 }
11741
11742 #[test]
11743 fn fonte_caminho_backslash_fires_before_shell_bracket_expansion() {
11744 // Cascade pin on the upstream backslash arm: a value
11745 // carrying both `\` and `[` (`"..\caixa-teia\[ch]"` — the
11746 // canonical "I pasted a Windows-shell `cd ..\path\[glob]`
11747 // chain") routes through `FonteCaminhoBackslash` not
11748 // `FonteCaminhoShellBracketExpansion`. The cross-host-OS-
11749 // separator divergence is the load-bearing axis on every
11750 // probe-as-both value.
11751 let d = dep_with_fonte(DepSource::Path {
11752 caminho: "..\\caixa-teia\\[ch]".into(),
11753 });
11754 let err = d.validate().unwrap_err();
11755 assert!(
11756 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11757 "got {err:?}",
11758 );
11759 }
11760
11761 #[test]
11762 fn fonte_caminho_control_char_fires_before_shell_bracket_expansion() {
11763 // Cascade pin on the embedded-control-byte arm: a value
11764 // carrying both a control byte and `[` (`"../foo\n[ch]"` —
11765 // the canonical paste-from-multiline-doc footgun where a
11766 // newline landed mid-caminho between two paste fragments)
11767 // routes through `FonteCaminhoControlChar` not
11768 // `FonteCaminhoShellBracketExpansion`. The POSIX-syscall-
11769 // rejected-byte / NUL-`CString::new`-fail diagnostic is
11770 // the load-bearing axis on every value that probes
11771 // positive for both — mirrors the cascade discipline on
11772 // every prior arm.
11773 let d = dep_with_fonte(DepSource::Path {
11774 caminho: "../foo\n[ch]".into(),
11775 });
11776 let err = d.validate().unwrap_err();
11777 assert!(
11778 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11779 "got {err:?}",
11780 );
11781 }
11782
11783 #[test]
11784 fn fonte_caminho_absolute_fires_before_shell_bracket_expansion() {
11785 // Cascade pin on the load-bearing leading-byte arm: a
11786 // leading `/` value with embedded `[` (`"/etc/[ch]"`)
11787 // routes through `FonteCaminhoAbsolute` not
11788 // `FonteCaminhoShellBracketExpansion` — the host-layout-
11789 // leak diagnostic is the load-bearing axis, the bracket-
11790 // expansion byte is the secondary observation. Same
11791 // precedence logic as every prior leading-byte arm.
11792 let d = dep_with_fonte(DepSource::Path {
11793 caminho: "/etc/[ch]".into(),
11794 });
11795 let err = d.validate().unwrap_err();
11796 assert!(
11797 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11798 "got {err:?}",
11799 );
11800 }
11801
11802 #[test]
11803 fn fonte_caminho_var_expansion_fires_before_shell_bracket_expansion() {
11804 // Cascade pin on the upstream leading-`$` var-expansion
11805 // arm: a value carrying both a leading `$` and a `[`
11806 // (`"$DIR/[ch]"` — the canonical "I pasted a `$DIR` shell-
11807 // variable + bracket-class at the head of a sibling-
11808 // workspace path" footgun) routes through
11809 // `FonteCaminhoVarExpansion` not
11810 // `FonteCaminhoShellBracketExpansion`. The leading-byte
11811 // shell-variable-expansion is the more self-locating
11812 // diagnostic on values that probe as both — same
11813 // load-bearing-leading-byte cascade discipline every
11814 // prior `:caminho` arm establishes.
11815 let d = dep_with_fonte(DepSource::Path {
11816 caminho: "$DIR/[ch]".into(),
11817 });
11818 let err = d.validate().unwrap_err();
11819 assert!(
11820 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11821 "got {err:?}",
11822 );
11823 }
11824
11825 #[test]
11826 fn fonte_caminho_shell_bracket_expansion_fires_before_trailing_slash() {
11827 // Cascade pin on the immediate-successor arm: a value
11828 // carrying both `[` and a trailing `/` (`"../[a-z]/"` —
11829 // the canonical "I tab-completed a path that already had
11830 // a bracket-glob-character-class expansion tail" footgun)
11831 // routes through `FonteCaminhoShellBracketExpansion` not
11832 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11833 // is the more semantic-locating axis (an author who
11834 // removes the `[` typically also drops the trailing
11835 // separator since both are paste-from-shell artifacts).
11836 let d = dep_with_fonte(DepSource::Path {
11837 caminho: "../[a-z]/".into(),
11838 });
11839 let err = d.validate().unwrap_err();
11840 assert!(
11841 matches!(
11842 err,
11843 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11844 ),
11845 "got {err:?}",
11846 );
11847 }
11848
11849 #[test]
11850 fn fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11851 // Diagnostic-shape pin (peer with
11852 // `fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11853 // on the closest two-byte peer arm): the error's Display
11854 // surfaces the offending `:nome`, the offending `:caminho`
11855 // verbatim, the offending byte's hex / character form, and
11856 // names the shell-bracket-expansion / glob-character-class
11857 // footgun explicitly so a `feira lint` run can render the
11858 // diagnostic without re-parsing.
11859 let d = dep_with_fonte(DepSource::Path {
11860 caminho: "../caixa-[a-z]/build".into(),
11861 });
11862 let rendered = d.validate().unwrap_err().to_string();
11863 assert!(
11864 rendered.contains("caixa-teia"),
11865 "diagnostic must name the offending dep: {rendered}",
11866 );
11867 assert!(
11868 rendered.contains("../caixa-[a-z]/build"),
11869 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11870 );
11871 assert!(
11872 rendered.contains("0x5b"),
11873 "diagnostic must surface the offending byte hex: {rendered:?}",
11874 );
11875 assert!(
11876 rendered.contains("bracket-expansion"),
11877 "diagnostic must name the shell-bracket-expansion footgun: {rendered:?}",
11878 );
11879 assert!(
11880 rendered.contains("glob-character-class"),
11881 "diagnostic must reference the POSIX glob-character-class vocabulary: \
11882 {rendered:?}",
11883 );
11884 }
11885
11886 #[test]
11887 fn validate_rejects_path_fonte_with_caminho_carrying_single_quote_grouping() {
11888 // The canonical paste-from-shell-history strong-quoted
11889 // sibling-workspace-path footgun: an author copies a
11890 // `cd '../caixa-teia'` shell-history one-liner whose strong-
11891 // quoting preserved the path across a whitespace paste
11892 // boundary and silently passed every prior arm
11893 // (`Path::is_absolute` false on `'..`, no control bytes, no
11894 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no
11895 // `*` / `?`, no `(` / `)`, no `{` / `}`, no `[` / `]`,
11896 // doesn't end in `/`; the leading-`$` f4efe9c
11897 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11898 // value starts with `'` not `$`). The lacre embedded the
11899 // value verbatim, the resolver folded it through
11900 // `Path::join` looking for a literal `./'../caixa-teia'`
11901 // subdirectory, and the failure surfaced at resolve time
11902 // with a non-self-locating `No such file or directory`
11903 // error. The new arm moves the rejection to validate time
11904 // and names the offending dep + caminho + byte verbatim.
11905 // The arm fires on the first `'` encountered.
11906 let d = dep_with_fonte(DepSource::Path {
11907 caminho: "'../caixa-teia'".into(),
11908 });
11909 let err = d.validate().unwrap_err();
11910 let DepError::FonteCaminhoShellQuoteGrouping {
11911 nome,
11912 caminho,
11913 byte,
11914 } = err
11915 else {
11916 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11917 };
11918 assert_eq!(nome, "caixa-teia");
11919 assert_eq!(caminho, "'../caixa-teia'");
11920 assert_eq!(byte, b'\'');
11921 }
11922
11923 #[test]
11924 fn validate_rejects_path_fonte_with_caminho_carrying_double_quote_grouping() {
11925 // The symmetric weak-quoted paste shape (`"\"../caixa-teia\""`
11926 // — the canonical paste-from-JSON-config / paste-from-YAML-
11927 // flow-scalar / paste-from-TOML-basic-string / paste-from-
11928 // tatara-lisp-string-literal cross-idiom leak). Pinned
11929 // separately from the single-quote shape so the gate's
11930 // contract is "any `'` or `\"` anywhere", not single-byte
11931 // coverage. Mirrors the peer
11932 // `validate_rejects_path_fonte_with_caminho_carrying_close_bracket`
11933 // shape on the immediate-predecessor
11934 // `FonteCaminhoShellBracketExpansion` arm.
11935 let d = dep_with_fonte(DepSource::Path {
11936 caminho: "\"../caixa-teia\"".into(),
11937 });
11938 let err = d.validate().unwrap_err();
11939 let DepError::FonteCaminhoShellQuoteGrouping { byte, .. } = err else {
11940 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11941 };
11942 assert_eq!(byte, b'"');
11943 }
11944
11945 #[test]
11946 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_double_quote() {
11947 // Embedded-position `"` shape (`"../\"caixa-teia\""` — the
11948 // canonical "I pasted a JSON key-value pair fragment into
11949 // the middle of the path" idiom). Pinned separately from
11950 // the leading-byte shape so the gate covers every position,
11951 // not only leading.
11952 let d = dep_with_fonte(DepSource::Path {
11953 caminho: "../\"caixa-teia\"".into(),
11954 });
11955 let err = d.validate().unwrap_err();
11956 assert!(
11957 matches!(
11958 err,
11959 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11960 ),
11961 "got {err:?}",
11962 );
11963 }
11964
11965 #[test]
11966 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_flow_scalar_paste() {
11967 // The canonical YAML double-quoted flow-scalar cross-idiom
11968 // leak shape (`"path: \"../caixa-teia\""` — the "I copied a
11969 // `path: \"...\"` YAML flow-scalar entry out of an aligned
11970 // values.yaml / K8s manifest and dropped it verbatim into
11971 // the `:caminho` slot including the `path: ` key prefix"
11972 // paste-idiom). The arm fires on the first `"` encountered;
11973 // pinned so the gate's coverage extends from the bare-quote
11974 // paste shape to the aligned-YAML-manifest cross-idiom-leak
11975 // shape.
11976 let d = dep_with_fonte(DepSource::Path {
11977 caminho: "path: \"../caixa-teia\"".into(),
11978 });
11979 let err = d.validate().unwrap_err();
11980 assert!(
11981 matches!(
11982 err,
11983 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11984 ),
11985 "got {err:?}",
11986 );
11987 }
11988
11989 #[test]
11990 fn validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping() {
11991 // The positive-control pin: the gate targets only `'` /
11992 // `"`, never adjacent printable ASCII or POSIX-valid bytes.
11993 // The canonical relative POSIX path (`"../caixa-teia"`) and
11994 // a nested deeply-pathed variant with adjacent printable
11995 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11996 // to validate cleanly so the gate doesn't widen to a "no
11997 // printable punctuation anywhere" sweep that would defeat
11998 // the entire path-fonte author surface. Peer with
11999 // `validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion`
12000 // on the immediate-predecessor arm.
12001 let d = dep_with_fonte(DepSource::Path {
12002 caminho: "../caixa-teia/sub-dir.v2".into(),
12003 });
12004 d.validate().unwrap();
12005 }
12006
12007 #[test]
12008 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_quote_grouping() {
12009 // Cascade pin on the immediate-predecessor arm: a value
12010 // carrying both `[` and `'` (`"../[a-z]'x'"` — the canonical
12011 // "I pasted a glob-character-class followed by a strong-
12012 // quoted literal tail" footgun) routes through
12013 // `FonteCaminhoShellBracketExpansion` not
12014 // `FonteCaminhoShellQuoteGrouping`. The glob-character-class
12015 // expansion is the load-bearing root-cause edit on every
12016 // probe-as-both value; same cascade discipline every prior
12017 // `:caminho` arm establishes.
12018 let d = dep_with_fonte(DepSource::Path {
12019 caminho: "../[a-z]'x'".into(),
12020 });
12021 let err = d.validate().unwrap_err();
12022 assert!(
12023 matches!(
12024 err,
12025 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12026 ),
12027 "got {err:?}",
12028 );
12029 }
12030
12031 #[test]
12032 fn fonte_caminho_shell_brace_expansion_fires_before_shell_quote_grouping() {
12033 // Cascade pin on the upstream shell-brace-expansion arm: a
12034 // value carrying both `{` and `'` (`"../{a,b}'x'"` — the
12035 // canonical "I pasted a brace-expansion fan followed by a
12036 // strong-quoted literal tail" footgun) routes through
12037 // `FonteCaminhoShellBraceExpansion` not
12038 // `FonteCaminhoShellQuoteGrouping`. The brace-expansion fan
12039 // is the load-bearing root-cause edit on every probe-as-
12040 // both value.
12041 let d = dep_with_fonte(DepSource::Path {
12042 caminho: "../{a,b}'x'".into(),
12043 });
12044 let err = d.validate().unwrap_err();
12045 assert!(
12046 matches!(
12047 err,
12048 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12049 ),
12050 "got {err:?}",
12051 );
12052 }
12053
12054 #[test]
12055 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_quote_grouping() {
12056 // Cascade pin on the upstream shell-subshell-grouping arm:
12057 // a value carrying both `(` and `'` (`"../(cd foo)/'x'"` —
12058 // the canonical "I pasted a subshell-grouping followed by
12059 // a strong-quoted literal tail" footgun) routes through
12060 // `FonteCaminhoShellSubshellGrouping` not
12061 // `FonteCaminhoShellQuoteGrouping`. The modern Bourne
12062 // `$(<cmd>)` command-substitution boundary is the load-
12063 // bearing axis on every probe-as-both value.
12064 let d = dep_with_fonte(DepSource::Path {
12065 caminho: "../(cd foo)/'x'".into(),
12066 });
12067 let err = d.validate().unwrap_err();
12068 assert!(
12069 matches!(
12070 err,
12071 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12072 ),
12073 "got {err:?}",
12074 );
12075 }
12076
12077 #[test]
12078 fn fonte_caminho_shell_glob_fires_before_shell_quote_grouping() {
12079 // Cascade pin on the upstream shell-glob arm: a value
12080 // carrying both `*` and `'` (`"../caixa-teia/*'x'"` — the
12081 // canonical "I pasted a `*` unbounded pathname-expansion
12082 // followed by a strong-quoted literal tail" footgun) routes
12083 // through `FonteCaminhoShellGlob` not
12084 // `FonteCaminhoShellQuoteGrouping`. The unbounded pathname-
12085 // expansion sentinel is the load-bearing root-cause edit
12086 // on every probe-as-both value.
12087 let d = dep_with_fonte(DepSource::Path {
12088 caminho: "../caixa-teia/*'x'".into(),
12089 });
12090 let err = d.validate().unwrap_err();
12091 assert!(
12092 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12093 "got {err:?}",
12094 );
12095 }
12096
12097 #[test]
12098 fn fonte_caminho_shell_command_substitution_fires_before_shell_quote_grouping() {
12099 // Cascade pin on the upstream shell-command-substitution
12100 // arm: a value carrying both a backtick and `'`
12101 // (``"../`whoami`/'x'"`` — the canonical "I pasted a
12102 // legacy-backtick command-substitution followed by a
12103 // strong-quoted literal tail" footgun) routes through
12104 // `FonteCaminhoShellCommandSubstitution` not
12105 // `FonteCaminhoShellQuoteGrouping`. The CWE-78 shell-
12106 // command-injection vector is the load-bearing root-cause
12107 // edit on every probe-as-both value.
12108 let d = dep_with_fonte(DepSource::Path {
12109 caminho: "../`whoami`/'x'".into(),
12110 });
12111 let err = d.validate().unwrap_err();
12112 assert!(
12113 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12114 "got {err:?}",
12115 );
12116 }
12117
12118 #[test]
12119 fn fonte_caminho_shell_background_fires_before_shell_quote_grouping() {
12120 // Cascade pin on the upstream shell-background arm: a value
12121 // carrying both `&` and `'` (`"../caixa-teia & 'x'"` — the
12122 // canonical "I pasted a `cmd & 'literal'` background-launch
12123 // + quote chain" footgun) routes through
12124 // `FonteCaminhoShellBackground` not
12125 // `FonteCaminhoShellQuoteGrouping`. The background-launch
12126 // tail is the load-bearing root-cause edit on every
12127 // probe-as-both value.
12128 let d = dep_with_fonte(DepSource::Path {
12129 caminho: "../caixa-teia & 'x'".into(),
12130 });
12131 let err = d.validate().unwrap_err();
12132 assert!(
12133 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12134 "got {err:?}",
12135 );
12136 }
12137
12138 #[test]
12139 fn fonte_caminho_shell_semicolon_fires_before_shell_quote_grouping() {
12140 // Cascade pin on the upstream shell-semicolon arm: a value
12141 // carrying both `;` and `'` (`"../caixa-teia; 'x'"` — the
12142 // canonical sequential-cleanup + quote paste idiom) routes
12143 // through `FonteCaminhoShellSemicolon` not
12144 // `FonteCaminhoShellQuoteGrouping`. The sequential-command-
12145 // separator paste is the load-bearing root-cause edit on
12146 // every probe-as-both value.
12147 let d = dep_with_fonte(DepSource::Path {
12148 caminho: "../caixa-teia; 'x'".into(),
12149 });
12150 let err = d.validate().unwrap_err();
12151 assert!(
12152 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12153 "got {err:?}",
12154 );
12155 }
12156
12157 #[test]
12158 fn fonte_caminho_shell_pipe_fires_before_shell_quote_grouping() {
12159 // Cascade pin on the upstream shell-pipe arm: a value
12160 // carrying both `|` and `'` (`"../caixa-teia | 'x'"` — the
12161 // canonical pipeline-to-quoted-literal paste idiom) routes
12162 // through `FonteCaminhoShellPipe` not
12163 // `FonteCaminhoShellQuoteGrouping`. The pipeline-tail paste
12164 // is the load-bearing root-cause edit on every probe-as-
12165 // both value.
12166 let d = dep_with_fonte(DepSource::Path {
12167 caminho: "../caixa-teia | 'x'".into(),
12168 });
12169 let err = d.validate().unwrap_err();
12170 assert!(
12171 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12172 "got {err:?}",
12173 );
12174 }
12175
12176 #[test]
12177 fn fonte_caminho_shell_redirection_fires_before_shell_quote_grouping() {
12178 // Cascade pin on the upstream shell-redirection arm: a
12179 // value carrying both `>` and `'` (`"../caixa-teia>log 'x'"`
12180 // — the canonical "I pasted a `cmd > log 'literal'`
12181 // redirect-plus-quote chain" footgun) routes through
12182 // `FonteCaminhoShellRedirection` not
12183 // `FonteCaminhoShellQuoteGrouping`. The input/output
12184 // redirection metachar carries the more self-locating
12185 // `byte` payload, so the prior arm wins on every probe-as-
12186 // both value.
12187 let d = dep_with_fonte(DepSource::Path {
12188 caminho: "../caixa-teia>log 'x'".into(),
12189 });
12190 let err = d.validate().unwrap_err();
12191 assert!(
12192 matches!(
12193 err,
12194 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12195 ),
12196 "got {err:?}",
12197 );
12198 }
12199
12200 #[test]
12201 fn fonte_caminho_backslash_fires_before_shell_quote_grouping() {
12202 // Cascade pin on the upstream backslash arm: a value
12203 // carrying both `\` and `'` (`"..\caixa-teia\'x'"` — the
12204 // canonical "I pasted a Windows-shell `cd ..\path\'literal'`
12205 // chain" footgun) routes through `FonteCaminhoBackslash`
12206 // not `FonteCaminhoShellQuoteGrouping`. The cross-host-OS-
12207 // separator divergence is the load-bearing axis on every
12208 // probe-as-both value.
12209 let d = dep_with_fonte(DepSource::Path {
12210 caminho: "..\\caixa-teia\\'x'".into(),
12211 });
12212 let err = d.validate().unwrap_err();
12213 assert!(
12214 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12215 "got {err:?}",
12216 );
12217 }
12218
12219 #[test]
12220 fn fonte_caminho_control_char_fires_before_shell_quote_grouping() {
12221 // Cascade pin on the embedded-control-byte arm: a value
12222 // carrying both a control byte and `'` (`"../foo\n'x'"` —
12223 // the canonical paste-from-multiline-doc footgun where a
12224 // newline landed mid-caminho between two paste fragments)
12225 // routes through `FonteCaminhoControlChar` not
12226 // `FonteCaminhoShellQuoteGrouping`. The POSIX-syscall-
12227 // rejected-byte / NUL-`CString::new`-fail diagnostic is
12228 // the load-bearing axis on every value that probes
12229 // positive for both — mirrors the cascade discipline on
12230 // every prior arm.
12231 let d = dep_with_fonte(DepSource::Path {
12232 caminho: "../foo\n'x'".into(),
12233 });
12234 let err = d.validate().unwrap_err();
12235 assert!(
12236 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12237 "got {err:?}",
12238 );
12239 }
12240
12241 #[test]
12242 fn fonte_caminho_absolute_fires_before_shell_quote_grouping() {
12243 // Cascade pin on the load-bearing leading-byte arm: a
12244 // leading `/` value with embedded `'` (`"/etc/'x'"`) routes
12245 // through `FonteCaminhoAbsolute` not
12246 // `FonteCaminhoShellQuoteGrouping` — the host-layout-leak
12247 // diagnostic is the load-bearing axis, the quote byte is
12248 // the secondary observation. Same precedence logic as every
12249 // prior leading-byte arm.
12250 let d = dep_with_fonte(DepSource::Path {
12251 caminho: "/etc/'x'".into(),
12252 });
12253 let err = d.validate().unwrap_err();
12254 assert!(
12255 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12256 "got {err:?}",
12257 );
12258 }
12259
12260 #[test]
12261 fn fonte_caminho_var_expansion_fires_before_shell_quote_grouping() {
12262 // Cascade pin on the upstream leading-`$` var-expansion
12263 // arm: a value carrying both a leading `$` and a `'`
12264 // (`"$DIR/'x'"` — the canonical "I pasted a `$DIR` shell-
12265 // variable + quoted literal at the head of a sibling-
12266 // workspace path" footgun) routes through
12267 // `FonteCaminhoVarExpansion` not
12268 // `FonteCaminhoShellQuoteGrouping`. The leading-byte
12269 // shell-variable-expansion is the more self-locating
12270 // diagnostic on values that probe as both — same
12271 // load-bearing-leading-byte cascade discipline every
12272 // prior `:caminho` arm establishes.
12273 let d = dep_with_fonte(DepSource::Path {
12274 caminho: "$DIR/'x'".into(),
12275 });
12276 let err = d.validate().unwrap_err();
12277 assert!(
12278 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12279 "got {err:?}",
12280 );
12281 }
12282
12283 #[test]
12284 fn fonte_caminho_shell_quote_grouping_fires_before_trailing_slash() {
12285 // Cascade pin on the immediate-successor arm: a value
12286 // carrying both `'` and a trailing `/` (`"../'caixa-teia'/"`
12287 // — the canonical "I tab-completed a path whose strong-
12288 // quoted body already carried the quoting from a shell-
12289 // history paste" footgun) routes through
12290 // `FonteCaminhoShellQuoteGrouping` not
12291 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
12292 // is the more semantic-locating axis (an author who removes
12293 // the `'` typically also drops the trailing separator since
12294 // both are paste-from-shell artifacts).
12295 let d = dep_with_fonte(DepSource::Path {
12296 caminho: "../'caixa-teia'/".into(),
12297 });
12298 let err = d.validate().unwrap_err();
12299 assert!(
12300 matches!(
12301 err,
12302 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12303 ),
12304 "got {err:?}",
12305 );
12306 }
12307
12308 #[test]
12309 fn fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
12310 // Diagnostic-shape pin (peer with
12311 // `fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
12312 // on the closest two-byte peer arm): the error's Display
12313 // surfaces the offending `:nome`, the offending `:caminho`
12314 // verbatim, the offending byte's hex / character form, and
12315 // names the shell-quote-grouping / cross-config-DSL-string-
12316 // literal-delimiter footgun explicitly so a `feira lint`
12317 // run can render the diagnostic without re-parsing.
12318 let d = dep_with_fonte(DepSource::Path {
12319 caminho: "'../caixa-teia'".into(),
12320 });
12321 let rendered = d.validate().unwrap_err().to_string();
12322 assert!(
12323 rendered.contains("caixa-teia"),
12324 "diagnostic must name the offending dep: {rendered}",
12325 );
12326 assert!(
12327 rendered.contains("'../caixa-teia'"),
12328 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12329 );
12330 assert!(
12331 rendered.contains("0x27"),
12332 "diagnostic must surface the offending byte hex: {rendered:?}",
12333 );
12334 assert!(
12335 rendered.contains("quote-grouping"),
12336 "diagnostic must name the shell-quote-grouping footgun: {rendered:?}",
12337 );
12338 assert!(
12339 rendered.contains("string-literal"),
12340 "diagnostic must reference the cross-config-DSL string-literal-delimiter \
12341 vocabulary: {rendered:?}",
12342 );
12343 }
12344
12345 #[test]
12346 fn validate_rejects_path_fonte_with_caminho_carrying_shell_comment_lead() {
12347 // The canonical paste-from-shell-history-with-trailing-
12348 // annotation footgun: an author pastes a `cd ../caixa-teia
12349 // # legacy sibling` shell-history one-liner whose unquoted `#`
12350 // comment-lead separates the path from an inline annotation.
12351 // The POSIX shell trims the annotation to `../caixa-teia`
12352 // (POSIX.1-2017 §2.3 Token Recognition step 6), but
12353 // `Path::is_absolute` returns false on `..`, `#` is neither
12354 // a leading-byte sentinel nor a control byte nor `\` nor
12355 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` /
12356 // `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` /
12357 // `"`, and the value's last byte isn't `/` — so the value
12358 // silently passed every prior arm. The resolver folded the
12359 // value through `Path::join` looking for a literal
12360 // `./../caixa-teia # legacy sibling` subdirectory and the
12361 // failure surfaced at resolve time with a non-self-locating
12362 // `No such file or directory` error. The new arm moves the
12363 // rejection to validate time and names the offending dep +
12364 // caminho + byte verbatim.
12365 let d = dep_with_fonte(DepSource::Path {
12366 caminho: "../caixa-teia # legacy sibling".into(),
12367 });
12368 let err = d.validate().unwrap_err();
12369 let DepError::FonteCaminhoShellComment {
12370 nome,
12371 caminho,
12372 byte,
12373 } = err
12374 else {
12375 panic!("expected FonteCaminhoShellComment, got {err:?}");
12376 };
12377 assert_eq!(nome, "caixa-teia");
12378 assert_eq!(caminho, "../caixa-teia # legacy sibling");
12379 assert_eq!(byte, b'#');
12380 }
12381
12382 #[test]
12383 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_comment_paste() {
12384 // The symmetric YAML flow-scalar / values.yaml / K8s-manifest
12385 // cross-idiom-leak shape (`"../caixa-teia # pin"` — the
12386 // canonical "I copied a `path: ../caixa-teia # pin` YAML
12387 // scalar-plus-comment entry out of an aligned values.yaml and
12388 // dropped it verbatim into the `:caminho` slot" paste-idiom).
12389 // Pinned separately from the shell-history shape so the
12390 // gate's coverage extends from the single-space `#` shape to
12391 // the YAML-canonical double-space ` #` shape. YAML 1.2 §6.6
12392 // requires the `#` to be preceded by whitespace to lex as a
12393 // comment (bare `foo#bar` is a single scalar); the double-
12394 // space paste from an aligned manifest is the canonical
12395 // shape.
12396 let d = dep_with_fonte(DepSource::Path {
12397 caminho: "../caixa-teia # pin".into(),
12398 });
12399 let err = d.validate().unwrap_err();
12400 assert!(
12401 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12402 "got {err:?}",
12403 );
12404 }
12405
12406 #[test]
12407 fn validate_rejects_path_fonte_with_caminho_carrying_url_fragment_anchor() {
12408 // The URL-fragment-identifier paste shape
12409 // (`"../caixa-teia#readme"` — the canonical
12410 // paste-from-browser-address-bar permalink shape where the
12411 // browser preserved the `#anchor` tail on the copy). Pinned
12412 // separately from the whitespace-separated shell / YAML
12413 // comment shapes so the gate covers the unpadded RFC 3986
12414 // §3.5 fragment-delimiter position too, not only positions
12415 // preceded by unquoted whitespace. Peer with the immediate-
12416 // sibling `is_git_repo_url` arm on the `:fonte :repo` axis
12417 // (a68f818) which closes the same byte under the same URL-
12418 // fragment-identifier banner.
12419 let d = dep_with_fonte(DepSource::Path {
12420 caminho: "../caixa-teia#readme".into(),
12421 });
12422 let err = d.validate().unwrap_err();
12423 assert!(
12424 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12425 "got {err:?}",
12426 );
12427 }
12428
12429 #[test]
12430 fn validate_rejects_path_fonte_with_caminho_carrying_leading_shell_comment() {
12431 // Leading-position `#` shape (`"#../caixa-teia"` — the
12432 // "I copied a shell-comment-out entry from a commented-out
12433 // dep row" footgun). Pinned separately from the embedded
12434 // shapes so the gate covers every position, not only
12435 // whitespace-preceded / mid-value.
12436 let d = dep_with_fonte(DepSource::Path {
12437 caminho: "#../caixa-teia".into(),
12438 });
12439 let err = d.validate().unwrap_err();
12440 assert!(
12441 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12442 "got {err:?}",
12443 );
12444 }
12445
12446 #[test]
12447 fn validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment() {
12448 // The positive-control pin: the gate targets only `#`,
12449 // never adjacent printable ASCII or POSIX-valid bytes. The
12450 // canonical relative POSIX path (`"../caixa-teia"`) and a
12451 // nested deeply-pathed variant with adjacent printable
12452 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12453 // to validate cleanly so the gate doesn't widen to a "no
12454 // printable punctuation anywhere" sweep that would defeat
12455 // the entire path-fonte author surface. Peer with
12456 // `validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping`
12457 // on the immediate-predecessor arm.
12458 let d = dep_with_fonte(DepSource::Path {
12459 caminho: "../caixa-teia/sub-dir.v2".into(),
12460 });
12461 d.validate().unwrap();
12462 }
12463
12464 #[test]
12465 fn fonte_caminho_shell_quote_grouping_fires_before_shell_comment() {
12466 // Cascade pin on the immediate-predecessor arm: a value
12467 // carrying both `'` and `#` (`"../'x'#pin"` — the canonical
12468 // "I pasted a strong-quoted literal followed by a URL-
12469 // fragment permalink tail" footgun) routes through
12470 // `FonteCaminhoShellQuoteGrouping` not
12471 // `FonteCaminhoShellComment`. The shell-string-literal-
12472 // delimiter is the load-bearing root-cause edit on every
12473 // probe-as-both value; same cascade discipline every prior
12474 // `:caminho` arm establishes.
12475 let d = dep_with_fonte(DepSource::Path {
12476 caminho: "../'x'#pin".into(),
12477 });
12478 let err = d.validate().unwrap_err();
12479 assert!(
12480 matches!(
12481 err,
12482 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12483 ),
12484 "got {err:?}",
12485 );
12486 }
12487
12488 #[test]
12489 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_comment() {
12490 // Cascade pin on the upstream shell-bracket-expansion arm:
12491 // a value carrying both `[` and `#` (`"../[a-z]#pin"` — the
12492 // canonical "I pasted a glob-character-class followed by a
12493 // URL-fragment tail" footgun) routes through
12494 // `FonteCaminhoShellBracketExpansion` not
12495 // `FonteCaminhoShellComment`. The glob-character-class
12496 // expansion is the load-bearing root-cause edit on every
12497 // probe-as-both value.
12498 let d = dep_with_fonte(DepSource::Path {
12499 caminho: "../[a-z]#pin".into(),
12500 });
12501 let err = d.validate().unwrap_err();
12502 assert!(
12503 matches!(
12504 err,
12505 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12506 ),
12507 "got {err:?}",
12508 );
12509 }
12510
12511 #[test]
12512 fn fonte_caminho_shell_brace_expansion_fires_before_shell_comment() {
12513 // Cascade pin on the upstream shell-brace-expansion arm: a
12514 // value carrying both `{` and `#` (`"../{a,b}#pin"` — the
12515 // canonical "I pasted a brace-expansion fan followed by a
12516 // URL-fragment tail" footgun) routes through
12517 // `FonteCaminhoShellBraceExpansion` not
12518 // `FonteCaminhoShellComment`. The brace-expansion fan is the
12519 // load-bearing root-cause edit on every probe-as-both value.
12520 let d = dep_with_fonte(DepSource::Path {
12521 caminho: "../{a,b}#pin".into(),
12522 });
12523 let err = d.validate().unwrap_err();
12524 assert!(
12525 matches!(
12526 err,
12527 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12528 ),
12529 "got {err:?}",
12530 );
12531 }
12532
12533 #[test]
12534 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_comment() {
12535 // Cascade pin on the upstream shell-subshell-grouping arm:
12536 // a value carrying both `(` and `#` (`"../(cd foo)#pin"` —
12537 // the canonical "I pasted a subshell-grouping followed by a
12538 // URL-fragment tail" footgun) routes through
12539 // `FonteCaminhoShellSubshellGrouping` not
12540 // `FonteCaminhoShellComment`. The modern Bourne `$(<cmd>)`
12541 // command-substitution boundary is the load-bearing axis on
12542 // every probe-as-both value.
12543 let d = dep_with_fonte(DepSource::Path {
12544 caminho: "../(cd foo)#pin".into(),
12545 });
12546 let err = d.validate().unwrap_err();
12547 assert!(
12548 matches!(
12549 err,
12550 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12551 ),
12552 "got {err:?}",
12553 );
12554 }
12555
12556 #[test]
12557 fn fonte_caminho_shell_glob_fires_before_shell_comment() {
12558 // Cascade pin on the upstream shell-glob arm: a value
12559 // carrying both `*` and `#` (`"../caixa-teia/*#pin"` — the
12560 // canonical "I pasted a `*` unbounded pathname-expansion
12561 // followed by a URL-fragment tail" footgun) routes through
12562 // `FonteCaminhoShellGlob` not `FonteCaminhoShellComment`.
12563 // The unbounded pathname-expansion sentinel is the load-
12564 // bearing root-cause edit on every probe-as-both value.
12565 let d = dep_with_fonte(DepSource::Path {
12566 caminho: "../caixa-teia/*#pin".into(),
12567 });
12568 let err = d.validate().unwrap_err();
12569 assert!(
12570 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12571 "got {err:?}",
12572 );
12573 }
12574
12575 #[test]
12576 fn fonte_caminho_shell_command_substitution_fires_before_shell_comment() {
12577 // Cascade pin on the upstream shell-command-substitution
12578 // arm: a value carrying both a backtick and `#`
12579 // (``"../`whoami`#pin"`` — the canonical "I pasted a
12580 // legacy-backtick command-substitution followed by a URL-
12581 // fragment tail" footgun) routes through
12582 // `FonteCaminhoShellCommandSubstitution` not
12583 // `FonteCaminhoShellComment`. The CWE-78 shell-command-
12584 // injection vector is the load-bearing root-cause edit on
12585 // every probe-as-both value.
12586 let d = dep_with_fonte(DepSource::Path {
12587 caminho: "../`whoami`#pin".into(),
12588 });
12589 let err = d.validate().unwrap_err();
12590 assert!(
12591 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12592 "got {err:?}",
12593 );
12594 }
12595
12596 #[test]
12597 fn fonte_caminho_shell_background_fires_before_shell_comment() {
12598 // Cascade pin on the upstream shell-background arm: a value
12599 // carrying both `&` and `#` (`"../caixa-teia&pin#tail"` —
12600 // the canonical "I pasted a `cmd &` background-launch
12601 // followed by a URL-fragment tail" footgun) routes through
12602 // `FonteCaminhoShellBackground` not
12603 // `FonteCaminhoShellComment`. The background-launch tail is
12604 // the load-bearing root-cause edit on every probe-as-both
12605 // value.
12606 let d = dep_with_fonte(DepSource::Path {
12607 caminho: "../caixa-teia&pin#tail".into(),
12608 });
12609 let err = d.validate().unwrap_err();
12610 assert!(
12611 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12612 "got {err:?}",
12613 );
12614 }
12615
12616 #[test]
12617 fn fonte_caminho_shell_semicolon_fires_before_shell_comment() {
12618 // Cascade pin on the upstream shell-semicolon arm: a value
12619 // carrying both `;` and `#` (`"../caixa-teia;pin#tail"` —
12620 // the canonical sequential-cleanup + URL-fragment paste
12621 // idiom) routes through `FonteCaminhoShellSemicolon` not
12622 // `FonteCaminhoShellComment`. The sequential-command-
12623 // separator paste is the load-bearing root-cause edit on
12624 // every probe-as-both value.
12625 let d = dep_with_fonte(DepSource::Path {
12626 caminho: "../caixa-teia;pin#tail".into(),
12627 });
12628 let err = d.validate().unwrap_err();
12629 assert!(
12630 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12631 "got {err:?}",
12632 );
12633 }
12634
12635 #[test]
12636 fn fonte_caminho_shell_pipe_fires_before_shell_comment() {
12637 // Cascade pin on the upstream shell-pipe arm: a value
12638 // carrying both `|` and `#` (`"../caixa-teia|pin#tail"` —
12639 // the canonical pipeline-to-URL-fragment paste idiom) routes
12640 // through `FonteCaminhoShellPipe` not
12641 // `FonteCaminhoShellComment`. The pipeline-tail paste is
12642 // the load-bearing root-cause edit on every probe-as-both
12643 // value.
12644 let d = dep_with_fonte(DepSource::Path {
12645 caminho: "../caixa-teia|pin#tail".into(),
12646 });
12647 let err = d.validate().unwrap_err();
12648 assert!(
12649 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12650 "got {err:?}",
12651 );
12652 }
12653
12654 #[test]
12655 fn fonte_caminho_shell_redirection_fires_before_shell_comment() {
12656 // Cascade pin on the upstream shell-redirection arm: a
12657 // value carrying both `>` and `#` (`"../caixa-teia>log#pin"`
12658 // — the canonical "I pasted a `cmd > log` redirect followed
12659 // by a URL-fragment tail" footgun) routes through
12660 // `FonteCaminhoShellRedirection` not
12661 // `FonteCaminhoShellComment`. The input/output redirection
12662 // metachar carries the more self-locating `byte` payload,
12663 // so the prior arm wins on every probe-as-both value.
12664 let d = dep_with_fonte(DepSource::Path {
12665 caminho: "../caixa-teia>log#pin".into(),
12666 });
12667 let err = d.validate().unwrap_err();
12668 assert!(
12669 matches!(
12670 err,
12671 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12672 ),
12673 "got {err:?}",
12674 );
12675 }
12676
12677 #[test]
12678 fn fonte_caminho_backslash_fires_before_shell_comment() {
12679 // Cascade pin on the upstream backslash arm: a value
12680 // carrying both `\` and `#` (`"..\caixa-teia#pin"` — the
12681 // canonical "I pasted a Windows-shell path followed by a
12682 // URL-fragment tail" footgun) routes through
12683 // `FonteCaminhoBackslash` not `FonteCaminhoShellComment`.
12684 // The cross-host-OS-separator divergence is the load-
12685 // bearing axis on every probe-as-both value.
12686 let d = dep_with_fonte(DepSource::Path {
12687 caminho: "..\\caixa-teia#pin".into(),
12688 });
12689 let err = d.validate().unwrap_err();
12690 assert!(
12691 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12692 "got {err:?}",
12693 );
12694 }
12695
12696 #[test]
12697 fn fonte_caminho_control_char_fires_before_shell_comment() {
12698 // Cascade pin on the embedded-control-byte arm: a value
12699 // carrying both a control byte and `#` (`"../foo\n#pin"` —
12700 // the canonical paste-from-multiline-doc footgun where a
12701 // newline landed mid-caminho between the path and an
12702 // annotation) routes through `FonteCaminhoControlChar` not
12703 // `FonteCaminhoShellComment`. The POSIX-syscall-rejected-
12704 // byte diagnostic is the load-bearing axis on every value
12705 // that probes positive for both — mirrors the cascade
12706 // discipline on every prior arm.
12707 let d = dep_with_fonte(DepSource::Path {
12708 caminho: "../foo\n#pin".into(),
12709 });
12710 let err = d.validate().unwrap_err();
12711 assert!(
12712 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12713 "got {err:?}",
12714 );
12715 }
12716
12717 #[test]
12718 fn fonte_caminho_absolute_fires_before_shell_comment() {
12719 // Cascade pin on the load-bearing leading-byte arm: a
12720 // leading `/` value with embedded `#` (`"/etc/foo#pin"`)
12721 // routes through `FonteCaminhoAbsolute` not
12722 // `FonteCaminhoShellComment` — the host-layout-leak
12723 // diagnostic is the load-bearing axis, the fragment byte is
12724 // the secondary observation. Same precedence logic as every
12725 // prior leading-byte arm.
12726 let d = dep_with_fonte(DepSource::Path {
12727 caminho: "/etc/foo#pin".into(),
12728 });
12729 let err = d.validate().unwrap_err();
12730 assert!(
12731 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12732 "got {err:?}",
12733 );
12734 }
12735
12736 #[test]
12737 fn fonte_caminho_var_expansion_fires_before_shell_comment() {
12738 // Cascade pin on the upstream leading-`$` var-expansion
12739 // arm: a value carrying both a leading `$` and a `#`
12740 // (`"$DIR/foo#pin"` — the canonical "I pasted a `$DIR`
12741 // shell-variable at the head of a sibling-workspace path
12742 // followed by a URL-fragment tail" footgun) routes through
12743 // `FonteCaminhoVarExpansion` not `FonteCaminhoShellComment`.
12744 // The leading-byte shell-variable-expansion is the more
12745 // self-locating diagnostic on values that probe as both.
12746 let d = dep_with_fonte(DepSource::Path {
12747 caminho: "$DIR/foo#pin".into(),
12748 });
12749 let err = d.validate().unwrap_err();
12750 assert!(
12751 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12752 "got {err:?}",
12753 );
12754 }
12755
12756 #[test]
12757 fn fonte_caminho_shell_comment_fires_before_trailing_slash() {
12758 // Cascade pin on the immediate-successor arm: a value
12759 // carrying both `#` and a trailing `/`
12760 // (`"../caixa-teia#pin/"` — the canonical "I tab-completed
12761 // a URL-fragment-carrying path" footgun) routes through
12762 // `FonteCaminhoShellComment` not
12763 // `FonteCaminhoTrailingSlash`. The embedded fragment /
12764 // comment-lead byte is the more semantic-locating axis (an
12765 // author who removes the `#pin` fragment typically also
12766 // drops the trailing separator since both are paste-from-
12767 // URL / paste-from-shell-tab-completion artifacts).
12768 let d = dep_with_fonte(DepSource::Path {
12769 caminho: "../caixa-teia#pin/".into(),
12770 });
12771 let err = d.validate().unwrap_err();
12772 assert!(
12773 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. },),
12774 "got {err:?}",
12775 );
12776 }
12777
12778 #[test]
12779 fn fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte() {
12780 // Diagnostic-shape pin (peer with
12781 // `fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
12782 // on the immediate-predecessor arm): the error's Display
12783 // surfaces the offending `:nome`, the offending `:caminho`
12784 // verbatim, the offending byte's hex / character form, and
12785 // names the shell-comment / URL-fragment-identifier /
12786 // YAML-comment cross-config-DSL footgun explicitly so a
12787 // `feira lint` run can render the diagnostic without
12788 // re-parsing.
12789 let d = dep_with_fonte(DepSource::Path {
12790 caminho: "../caixa-teia#readme".into(),
12791 });
12792 let rendered = d.validate().unwrap_err().to_string();
12793 assert!(
12794 rendered.contains("caixa-teia"),
12795 "diagnostic must name the offending dep: {rendered}",
12796 );
12797 assert!(
12798 rendered.contains("../caixa-teia#readme"),
12799 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12800 );
12801 assert!(
12802 rendered.contains("0x23"),
12803 "diagnostic must surface the offending byte hex: {rendered:?}",
12804 );
12805 assert!(
12806 rendered.contains("shell-comment") || rendered.contains("comment-lead"),
12807 "diagnostic must name the shell-comment footgun: {rendered:?}",
12808 );
12809 assert!(
12810 rendered.contains("fragment") || rendered.contains("URL-fragment"),
12811 "diagnostic must reference the URL-fragment-identifier vocabulary: \
12812 {rendered:?}",
12813 );
12814 }
12815
12816 #[test]
12817 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_space() {
12818 // The canonical paste-from-browser-address-bar percent-
12819 // encoded-space footgun: an author copies `../caixa%20teia`
12820 // out of a URL-encoded README hyperlink / browser address
12821 // bar / percent-encoded permalink expecting `%20` to decode
12822 // to a literal space at the filesystem layer. POSIX
12823 // `std::path::Path` treats `%` as a literal path-component
12824 // byte, so `Path::join` looks for a literal
12825 // `./../caixa%20teia` subdirectory. `Path::is_absolute`
12826 // returns false on `..`, `%` is neither a leading-byte
12827 // sentinel nor a control byte nor `\` nor `<` / `>` nor
12828 // `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` /
12829 // `)` nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`,
12830 // and the value's last byte isn't `/` — so the value
12831 // silently passed every prior arm. The new arm moves the
12832 // rejection to validate time and names the offending dep +
12833 // caminho + byte verbatim.
12834 let d = dep_with_fonte(DepSource::Path {
12835 caminho: "../caixa%20teia".into(),
12836 });
12837 let err = d.validate().unwrap_err();
12838 let DepError::FonteCaminhoUrlPercentEncoding {
12839 nome,
12840 caminho,
12841 byte,
12842 } = err
12843 else {
12844 panic!("expected FonteCaminhoUrlPercentEncoding, got {err:?}");
12845 };
12846 assert_eq!(nome, "caixa-teia");
12847 assert_eq!(caminho, "../caixa%20teia");
12848 assert_eq!(byte, b'%');
12849 }
12850
12851 #[test]
12852 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_slash() {
12853 // The over-encoded path-separator shape (`"../caixa%2Fteia"`
12854 // intending the `%2F` as the URL encoding of `/`) locks a
12855 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
12856 // the byte-identical `path:../caixa/teia` form. Pinned
12857 // separately from the space-encoded shape so the gate's
12858 // coverage extends past the single canonical `%20` example
12859 // to any two-hex-digit percent-encoded sequence.
12860 let d = dep_with_fonte(DepSource::Path {
12861 caminho: "../caixa%2Fteia".into(),
12862 });
12863 let err = d.validate().unwrap_err();
12864 assert!(
12865 matches!(
12866 err,
12867 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12868 ),
12869 "got {err:?}",
12870 );
12871 }
12872
12873 #[test]
12874 fn validate_rejects_path_fonte_with_caminho_carrying_lone_percent() {
12875 // The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
12876 // where `%` isn't followed by two hex digits) — every
12877 // WHATWG-conformant URL parser rejects the value at parse
12878 // time per RFC 3986 §2.1, but the byte would silently ride
12879 // into the lacre before the resolver subprocess crosses the
12880 // URL-parser boundary. Pinned separately from the well-
12881 // formed `%HH` shapes so the gate covers every percent-
12882 // occurrence, not only strictly-conformant escapes.
12883 let d = dep_with_fonte(DepSource::Path {
12884 caminho: "../caixa-teia%foo".into(),
12885 });
12886 let err = d.validate().unwrap_err();
12887 assert!(
12888 matches!(
12889 err,
12890 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12891 ),
12892 "got {err:?}",
12893 );
12894 }
12895
12896 #[test]
12897 fn validate_rejects_path_fonte_with_caminho_carrying_leading_yaml_directive() {
12898 // The YAML-directive-lead paste shape (`"%YAML/../caixa-teia"`
12899 // — the canonical paste-from-top-of-doc YAML directive
12900 // block cross-idiom leak per YAML 1.2 §6.8.1). Pinned
12901 // separately from embedded shapes so the gate covers the
12902 // leading-position `%` too, not only mid-value occurrences.
12903 let d = dep_with_fonte(DepSource::Path {
12904 caminho: "%YAML/../caixa-teia".into(),
12905 });
12906 let err = d.validate().unwrap_err();
12907 assert!(
12908 matches!(
12909 err,
12910 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12911 ),
12912 "got {err:?}",
12913 );
12914 }
12915
12916 #[test]
12917 fn validate_rejects_path_fonte_with_caminho_carrying_printf_format_specifier() {
12918 // The printf-format-specifier paste shape
12919 // (`"../caixa-%s-teia"` — the canonical paste-from-shell-
12920 // diagnostic-one-liner `printf "path=%s\n" ...` idiom, CWE-
12921 // 134 format-string-injection vector). Pinned separately
12922 // from the URL-encoding shapes so the gate's rationale
12923 // extends past the RFC 3986 axis to the C / POSIX printf
12924 // format-directive-lead axis.
12925 let d = dep_with_fonte(DepSource::Path {
12926 caminho: "../caixa-%s-teia".into(),
12927 });
12928 let err = d.validate().unwrap_err();
12929 assert!(
12930 matches!(
12931 err,
12932 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12933 ),
12934 "got {err:?}",
12935 );
12936 }
12937
12938 #[test]
12939 fn validate_accepts_path_fonte_with_caminho_carrying_no_percent() {
12940 // The positive-control pin: the gate targets only `%`,
12941 // never adjacent printable ASCII or POSIX-valid bytes. The
12942 // canonical relative POSIX path (`"../caixa-teia"`) and a
12943 // nested deeply-pathed variant with adjacent printable
12944 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12945 // to validate cleanly so the gate doesn't widen to a "no
12946 // printable punctuation anywhere" sweep that would defeat
12947 // the entire path-fonte author surface. Peer with
12948 // `validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment`
12949 // on the immediate-predecessor arm.
12950 let d = dep_with_fonte(DepSource::Path {
12951 caminho: "../caixa-teia/sub-dir.v2".into(),
12952 });
12953 d.validate().unwrap();
12954 }
12955
12956 #[test]
12957 fn fonte_caminho_shell_comment_fires_before_url_percent_encoding() {
12958 // Cascade pin on the immediate-predecessor arm: a value
12959 // carrying both `#` and `%` (`"../caixa-teia#pin%20"` — the
12960 // canonical "I pasted a URL-fragment permalink followed by a
12961 // percent-encoded space tail" footgun) routes through
12962 // `FonteCaminhoShellComment` not
12963 // `FonteCaminhoUrlPercentEncoding`. The URL-fragment-
12964 // identifier is the load-bearing downstream-truncation edit
12965 // on every probe-as-both value; same cascade discipline
12966 // every prior `:caminho` arm establishes.
12967 let d = dep_with_fonte(DepSource::Path {
12968 caminho: "../caixa-teia#pin%20".into(),
12969 });
12970 let err = d.validate().unwrap_err();
12971 assert!(
12972 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12973 "got {err:?}",
12974 );
12975 }
12976
12977 #[test]
12978 fn fonte_caminho_shell_quote_grouping_fires_before_url_percent_encoding() {
12979 // Cascade pin on the upstream shell-quote-grouping arm: a
12980 // value carrying both `'` and `%` (`"../'x'%20teia"` — the
12981 // canonical "I pasted a strong-quoted literal followed by
12982 // a percent-encoded space" footgun) routes through
12983 // `FonteCaminhoShellQuoteGrouping` not
12984 // `FonteCaminhoUrlPercentEncoding`. The shell-string-
12985 // literal-delimiter is the load-bearing root-cause edit on
12986 // every probe-as-both value.
12987 let d = dep_with_fonte(DepSource::Path {
12988 caminho: "../'x'%20teia".into(),
12989 });
12990 let err = d.validate().unwrap_err();
12991 assert!(
12992 matches!(
12993 err,
12994 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12995 ),
12996 "got {err:?}",
12997 );
12998 }
12999
13000 #[test]
13001 fn fonte_caminho_backslash_fires_before_url_percent_encoding() {
13002 // Cascade pin on the upstream backslash arm: a value
13003 // carrying both `\` and `%` (`"..\\caixa%20teia"` — the
13004 // canonical "I pasted a Windows-shell path followed by a
13005 // percent-encoded space" footgun) routes through
13006 // `FonteCaminhoBackslash` not
13007 // `FonteCaminhoUrlPercentEncoding`. The cross-host-OS-
13008 // separator divergence is the load-bearing root-cause edit
13009 // on every probe-as-both value.
13010 let d = dep_with_fonte(DepSource::Path {
13011 caminho: "..\\caixa%20teia".into(),
13012 });
13013 let err = d.validate().unwrap_err();
13014 assert!(
13015 matches!(err, DepError::FonteCaminhoBackslash { .. }),
13016 "got {err:?}",
13017 );
13018 }
13019
13020 #[test]
13021 fn fonte_caminho_control_char_fires_before_url_percent_encoding() {
13022 // Cascade pin on the upstream control-char arm: a value
13023 // carrying both a NUL byte and `%` (`"../caixa\0%20teia"` —
13024 // the canonical "I pasted a paste-from-binary-blob path
13025 // followed by a percent-encoded space" footgun) routes
13026 // through `FonteCaminhoControlChar` not
13027 // `FonteCaminhoUrlPercentEncoding`. The POSIX-syscall-
13028 // rejected byte is the load-bearing root-cause edit on
13029 // every probe-as-both value.
13030 let d = dep_with_fonte(DepSource::Path {
13031 caminho: "../caixa\0%20teia".into(),
13032 });
13033 let err = d.validate().unwrap_err();
13034 assert!(
13035 matches!(err, DepError::FonteCaminhoControlChar { byte: 0x00, .. },),
13036 "got {err:?}",
13037 );
13038 }
13039
13040 #[test]
13041 fn fonte_caminho_absolute_fires_before_url_percent_encoding() {
13042 // Cascade pin on the upstream absolute-path arm: a value
13043 // that's both absolute and carries `%` (`"/etc/passwd%20"`
13044 // — the canonical "I pasted an absolute path with a
13045 // percent-encoded space tail" footgun) routes through
13046 // `FonteCaminhoAbsolute` not
13047 // `FonteCaminhoUrlPercentEncoding`. The host-layout-leak is
13048 // the load-bearing root-cause edit on every probe-as-both
13049 // value.
13050 let d = dep_with_fonte(DepSource::Path {
13051 caminho: "/etc/passwd%20".into(),
13052 });
13053 let err = d.validate().unwrap_err();
13054 assert!(
13055 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
13056 "got {err:?}",
13057 );
13058 }
13059
13060 #[test]
13061 fn fonte_caminho_var_expansion_fires_before_url_percent_encoding() {
13062 // Cascade pin on the upstream var-expansion arm: a value
13063 // starting with `$` and carrying `%` (`"$HOME/caixa%20teia"`
13064 // — the canonical "I pasted a `$HOME`-rooted path with a
13065 // percent-encoded space" footgun) routes through
13066 // `FonteCaminhoVarExpansion` not
13067 // `FonteCaminhoUrlPercentEncoding`. The shell-variable-
13068 // expansion is the load-bearing root-cause edit on every
13069 // probe-as-both value.
13070 let d = dep_with_fonte(DepSource::Path {
13071 caminho: "$HOME/caixa%20teia".into(),
13072 });
13073 let err = d.validate().unwrap_err();
13074 assert!(
13075 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
13076 "got {err:?}",
13077 );
13078 }
13079
13080 #[test]
13081 fn fonte_caminho_url_percent_encoding_fires_before_trailing_slash() {
13082 // Cascade pin on the immediate-successor arm: a value
13083 // carrying both `%` and a trailing `/`
13084 // (`"../caixa%20teia/"` — the canonical "I tab-completed a
13085 // percent-encoded-space-carrying path" footgun) routes
13086 // through `FonteCaminhoUrlPercentEncoding` not
13087 // `FonteCaminhoTrailingSlash`. The embedded percent-
13088 // encoding-escape byte is the more semantic-locating axis
13089 // (an author who decodes the `%20` to a literal space is
13090 // likely to also tab-strip the trailing separator since
13091 // both are paste-from-URL / paste-from-shell-tab-completion
13092 // artifacts).
13093 let d = dep_with_fonte(DepSource::Path {
13094 caminho: "../caixa%20teia/".into(),
13095 });
13096 let err = d.validate().unwrap_err();
13097 assert!(
13098 matches!(
13099 err,
13100 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13101 ),
13102 "got {err:?}",
13103 );
13104 }
13105
13106 #[test]
13107 fn fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte() {
13108 // Diagnostic-shape pin (peer with
13109 // `fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte`
13110 // on the immediate-predecessor arm): the error's Display
13111 // surfaces the offending `:nome`, the offending `:caminho`
13112 // verbatim, the offending byte's hex / character form, and
13113 // names the URL-percent-encoding-escape / printf-format-
13114 // specifier footgun explicitly so a `feira lint` run can
13115 // render the diagnostic without re-parsing.
13116 let d = dep_with_fonte(DepSource::Path {
13117 caminho: "../caixa%20teia".into(),
13118 });
13119 let rendered = d.validate().unwrap_err().to_string();
13120 assert!(
13121 rendered.contains("caixa-teia"),
13122 "diagnostic must name the offending dep: {rendered}",
13123 );
13124 assert!(
13125 rendered.contains("../caixa%20teia"),
13126 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13127 );
13128 assert!(
13129 rendered.contains("0x25"),
13130 "diagnostic must surface the offending byte hex: {rendered:?}",
13131 );
13132 assert!(
13133 rendered.contains("percent-encoding") || rendered.contains("percent-encoded"),
13134 "diagnostic must name the URL-percent-encoding-escape footgun: {rendered:?}",
13135 );
13136 assert!(
13137 rendered.contains("printf") || rendered.contains("format-specifier"),
13138 "diagnostic must reference the printf-format-specifier vocabulary: \
13139 {rendered:?}",
13140 );
13141 }
13142
13143 #[test]
13144 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_var_expansion() {
13145 // The canonical embedded-`$` shell-variable-expansion paste
13146 // shape (`"../foo$HOME/bar"` — an author copies a partially-
13147 // substituted shell one-liner where the leading segment is a
13148 // literal `../foo` while the mid segment carries the un-
13149 // substituted `$HOME` template). The leading-`$` position is
13150 // already gated by the f4efe9c leading-byte arm which routes
13151 // through `FonteCaminhoVarExpansion`; this arm closes the
13152 // last positional gap on `$` — every position on the axis is
13153 // structurally rejected.
13154 let d = dep_with_fonte(DepSource::Path {
13155 caminho: "../foo$HOME/bar".into(),
13156 });
13157 let err = d.validate().unwrap_err();
13158 let DepError::FonteCaminhoShellVariableExpansion {
13159 nome,
13160 caminho,
13161 byte,
13162 } = err
13163 else {
13164 panic!("expected FonteCaminhoShellVariableExpansion, got {err:?}");
13165 };
13166 assert_eq!(nome, "caixa-teia");
13167 assert_eq!(caminho, "../foo$HOME/bar");
13168 assert_eq!(byte, b'$');
13169 }
13170
13171 #[test]
13172 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_braced_var_expansion() {
13173 // The symmetric braced-CI-manifest paste shape
13174 // (`"../foo${WORKSPACE}/bar"` — the canonical paste-from-
13175 // GitHub-Actions-workflow / paste-from-`.gitlab-ci.yml`
13176 // footgun). Pinned separately from the bare-`$VAR` shape so
13177 // the gate covers both POSIX shell §2.6 Parameter Expansion
13178 // syntactic forms, not only the unbraced variant. The
13179 // embedded `{` byte in `${...}` is also caught by the 598b770
13180 // shell-brace-expansion arm but that arm fires earlier in
13181 // the cascade — the `$` arm's coverage extends to `${...}`
13182 // structurally, so the diagnostic asserted here is the
13183 // brace-expansion one (which is a valid outcome; the point
13184 // of the pin is that the value never survives validation).
13185 let d = dep_with_fonte(DepSource::Path {
13186 caminho: "../foo${WORKSPACE}/bar".into(),
13187 });
13188 let err = d.validate().unwrap_err();
13189 assert!(
13190 matches!(
13191 err,
13192 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. }
13193 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13194 ),
13195 "got {err:?}",
13196 );
13197 }
13198
13199 #[test]
13200 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_command_substitution() {
13201 // The paste-from-shell-prompt command-substitution idiom
13202 // (`"../foo$(whoami)/bar"`). Pinned separately from the bare-
13203 // `$VAR` shape so the gate's rationale extends to POSIX shell
13204 // §2.6.3 Command Substitution (the modern `$(<cmd>)` form; the
13205 // legacy `` `<cmd>` `` form is already closed by the c370458
13206 // backtick arm). The embedded `(` byte in `$(...)` is also
13207 // caught structurally by the 0633c91 shell-subshell-grouping
13208 // arm which fires earlier in the cascade — the diagnostic
13209 // asserted here is either outcome, since both structurally
13210 // reject the value; the point of the pin is that the value
13211 // never survives validation.
13212 let d = dep_with_fonte(DepSource::Path {
13213 caminho: "../foo$(whoami)/bar".into(),
13214 });
13215 let err = d.validate().unwrap_err();
13216 assert!(
13217 matches!(
13218 err,
13219 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. }
13220 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13221 ),
13222 "got {err:?}",
13223 );
13224 }
13225
13226 #[test]
13227 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_positional_parameter() {
13228 // The paste-from-`Makefile` / paste-from-SQL-migration bare-
13229 // `$1` positional-parameter shape (`"../foo$1/bar"` — a Make
13230 // automatic-variable `$1` or a PostgreSQL bind-parameter `$1`
13231 // idiom copied into a caminho template). None of the prior
13232 // shell-metachar arms cover this shape (`1` is a bare digit;
13233 // no `(` / `{` / letter follows the `$`), so the arm is the
13234 // sole gate on the shape.
13235 let d = dep_with_fonte(DepSource::Path {
13236 caminho: "../foo$1/bar".into(),
13237 });
13238 let err = d.validate().unwrap_err();
13239 assert!(
13240 matches!(
13241 err,
13242 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13243 ),
13244 "got {err:?}",
13245 );
13246 }
13247
13248 #[test]
13249 fn validate_accepts_path_fonte_with_caminho_carrying_no_dollar() {
13250 // The positive-control pin (peer with
13251 // `validate_accepts_path_fonte_with_caminho_carrying_no_percent`
13252 // on the immediate-predecessor arm): the gate targets only
13253 // `$`, never adjacent printable ASCII or POSIX-valid bytes.
13254 // A relative POSIX path carrying dashes / dots / slashes /
13255 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13256 // validate cleanly so the gate doesn't widen to a "no
13257 // printable punctuation anywhere" sweep that would defeat
13258 // the entire path-fonte author surface.
13259 let d = dep_with_fonte(DepSource::Path {
13260 caminho: "../caixa-teia/sub-dir.v2".into(),
13261 });
13262 d.validate().unwrap();
13263 }
13264
13265 #[test]
13266 fn fonte_caminho_var_expansion_fires_before_shell_variable_expansion() {
13267 // Cascade pin on the leading-`$` sibling arm at line 540: a
13268 // value starting with `$` and carrying an embedded `$` too
13269 // (`"$HOME/foo$WORKSPACE/bar"` — the canonical "I pasted a
13270 // fully-templated CI path with two un-substituted variables")
13271 // routes through `FonteCaminhoVarExpansion` not
13272 // `FonteCaminhoShellVariableExpansion`. The leading-byte
13273 // host-layout-leak is the load-bearing self-locating axis
13274 // (the leading position dominates the semantic-locating
13275 // rationale on every probe-as-both value); the embedded
13276 // arm's positional-agnostic sweep catches only values whose
13277 // leading byte doesn't route through the earlier leading-
13278 // byte arms.
13279 let d = dep_with_fonte(DepSource::Path {
13280 caminho: "$HOME/foo$WORKSPACE/bar".into(),
13281 });
13282 let err = d.validate().unwrap_err();
13283 assert!(
13284 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
13285 "got {err:?}",
13286 );
13287 }
13288
13289 #[test]
13290 fn fonte_caminho_url_percent_encoding_fires_before_shell_variable_expansion() {
13291 // Cascade pin on the immediate-predecessor arm: a value
13292 // carrying both `%` and embedded `$` (`"../foo%20$HOME/bar"`
13293 // — the canonical "I pasted a percent-encoded space adjacent
13294 // to a `$HOME` template") routes through
13295 // `FonteCaminhoUrlPercentEncoding` not
13296 // `FonteCaminhoShellVariableExpansion`. The URL-percent-
13297 // encoding-escape byte is the more semantic-locating axis
13298 // (the paste-from-browser-address-bar shape is the load-
13299 // bearing self-locating edit); same cascade discipline every
13300 // prior `:caminho` arm establishes.
13301 let d = dep_with_fonte(DepSource::Path {
13302 caminho: "../foo%20$HOME/bar".into(),
13303 });
13304 let err = d.validate().unwrap_err();
13305 assert!(
13306 matches!(
13307 err,
13308 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13309 ),
13310 "got {err:?}",
13311 );
13312 }
13313
13314 #[test]
13315 fn fonte_caminho_shell_variable_expansion_fires_before_trailing_slash() {
13316 // Cascade pin on the immediate-successor arm: a value
13317 // carrying both embedded `$` and a trailing `/`
13318 // (`"../foo$HOME/bar/"` — the canonical "I tab-completed a
13319 // `$HOME`-template-carrying path") routes through
13320 // `FonteCaminhoShellVariableExpansion` not
13321 // `FonteCaminhoTrailingSlash`. The embedded shell-variable-
13322 // expansion byte is the more semantic-locating axis on
13323 // probe-as-both values (an author who substitutes the
13324 // `$HOME` template with a literal value is likely to also
13325 // tab-strip the trailing separator).
13326 let d = dep_with_fonte(DepSource::Path {
13327 caminho: "../foo$HOME/bar/".into(),
13328 });
13329 let err = d.validate().unwrap_err();
13330 assert!(
13331 matches!(
13332 err,
13333 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13334 ),
13335 "got {err:?}",
13336 );
13337 }
13338
13339 #[test]
13340 fn fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13341 // Diagnostic-shape pin (peer with
13342 // `fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte`
13343 // on the immediate-predecessor arm): the error's Display
13344 // surfaces the offending `:nome`, the offending `:caminho`
13345 // verbatim, the offending byte's hex / character form, and
13346 // names the shell-variable-expansion / command-substitution
13347 // footgun explicitly so a `feira lint` run can render the
13348 // diagnostic without re-parsing.
13349 let d = dep_with_fonte(DepSource::Path {
13350 caminho: "../foo$HOME/bar".into(),
13351 });
13352 let rendered = d.validate().unwrap_err().to_string();
13353 assert!(
13354 rendered.contains("caixa-teia"),
13355 "diagnostic must name the offending dep: {rendered}",
13356 );
13357 assert!(
13358 rendered.contains("../foo$HOME/bar"),
13359 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13360 );
13361 assert!(
13362 rendered.contains("0x24"),
13363 "diagnostic must surface the offending byte hex: {rendered:?}",
13364 );
13365 assert!(
13366 rendered.contains("variable-expansion") || rendered.contains("variable expansion"),
13367 "diagnostic must name the shell-variable-expansion footgun: {rendered:?}",
13368 );
13369 assert!(
13370 rendered.contains("command-substitution") || rendered.contains("command substitution"),
13371 "diagnostic must reference the command-substitution vocabulary: {rendered:?}",
13372 );
13373 }
13374
13375 #[test]
13376 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_expansion() {
13377 // The fail-before-pass-after pin for the canonical paste-from-
13378 // shell-history footgun on `:caminho`. An author copies a `cd
13379 // ../caixa-teia && !sudo make install` one-liner from a quick-
13380 // start README, intending the trailing `!sudo` as a shell-
13381 // history-expansion reference but the typed slot is itself a
13382 // byte-level string parser, not a shell context, so the byte
13383 // rides into the value verbatim. Until this arm landed the `!`
13384 // byte silently passed every prior `:caminho` cascade arm
13385 // (`!` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick /
13386 // `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` /
13387 // `#` / `%` / `$`); bash with the default `histexpand` mode
13388 // rewrites `!command` to the most recent history entry
13389 // beginning with `command`, the canonical RCE-class injection
13390 // vector when the byte rides into a shell argument executed
13391 // under `bash -i` (the operator-notebook interactive shell).
13392 let d = dep_with_fonte(DepSource::Path {
13393 caminho: "../caixa-teia!sudo".into(),
13394 });
13395 let err = d.validate().unwrap_err();
13396 let DepError::FonteCaminhoShellHistoryExpansion {
13397 nome,
13398 caminho,
13399 byte,
13400 } = err
13401 else {
13402 panic!("expected FonteCaminhoShellHistoryExpansion, got {err:?}");
13403 };
13404 assert_eq!(nome, "caixa-teia");
13405 assert_eq!(caminho, "../caixa-teia!sudo");
13406 assert_eq!(byte, b'!');
13407 }
13408
13409 #[test]
13410 fn validate_rejects_path_fonte_with_caminho_carrying_double_bang_history_reference() {
13411 // The symmetric `!!` repeat-prior-command paste idiom (peer with
13412 // `validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference`
13413 // on `is_git_repo_url`). Pinned separately from the wrapped
13414 // `!command` shape so a future diagnostic-surface change that
13415 // only checked the leading or paired-bang position surfaces
13416 // here — the per-byte arm fires anywhere `!` appears in the
13417 // value, including at consecutive positions in the middle.
13418 let d = dep_with_fonte(DepSource::Path {
13419 caminho: "../foo!!/bar".into(),
13420 });
13421 let err = d.validate().unwrap_err();
13422 assert!(
13423 matches!(
13424 err,
13425 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13426 ),
13427 "got {err:?}",
13428 );
13429 }
13430
13431 #[test]
13432 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_enthusiasm_bang() {
13433 // The English-typography enthusiasm-form paste-from-prose
13434 // idiom: an author writes `:caminho "../caixa-teia!"`
13435 // expecting the substrate to coerce it to a kebab-case slug.
13436 // Pinned separately from the `!<word>` shell-history shape so
13437 // the gate's rationale extends to the paste-from-prose surface
13438 // (the same rationale the peer `is_git_repo_url` bang arm at
13439 // 7d53c68 covers). None of the prior shell-metachar arms cover
13440 // this shape (no `!<word>` reference and no `!!` repeat), so
13441 // the arm is the sole gate on the shape.
13442 let d = dep_with_fonte(DepSource::Path {
13443 caminho: "../caixa-teia!".into(),
13444 });
13445 let err = d.validate().unwrap_err();
13446 assert!(
13447 matches!(
13448 err,
13449 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13450 ),
13451 "got {err:?}",
13452 );
13453 }
13454
13455 #[test]
13456 fn validate_accepts_path_fonte_with_caminho_carrying_no_bang() {
13457 // The positive-control pin (peer with
13458 // `validate_accepts_path_fonte_with_caminho_carrying_no_dollar`
13459 // on the immediate-predecessor arm): the gate targets only
13460 // `!`, never adjacent printable ASCII or POSIX-valid bytes.
13461 // A relative POSIX path carrying dashes / dots / slashes /
13462 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13463 // validate cleanly so the gate doesn't widen to a "no
13464 // printable punctuation anywhere" sweep that would defeat
13465 // the entire path-fonte author surface.
13466 let d = dep_with_fonte(DepSource::Path {
13467 caminho: "../caixa-teia/sub-dir.v2".into(),
13468 });
13469 d.validate().unwrap();
13470 }
13471
13472 #[test]
13473 fn fonte_caminho_shell_variable_expansion_fires_before_shell_history_expansion() {
13474 // Cascade pin on the immediate-predecessor arm: a value
13475 // carrying both embedded `$` and `!` (`"../foo$HOME/bar!sudo"`
13476 // — the canonical "I pasted a `$HOME`-templated path adjacent
13477 // to a trailing `!sudo` history-expansion") routes through
13478 // `FonteCaminhoShellVariableExpansion` not
13479 // `FonteCaminhoShellHistoryExpansion`. The shell-variable-
13480 // expansion byte is the more semantic-locating axis on
13481 // probe-as-both values (the paste-from-CI-manifest-with-`$VAR`-
13482 // template shape is the load-bearing self-locating edit);
13483 // same cascade discipline every prior `:caminho` arm
13484 // establishes.
13485 let d = dep_with_fonte(DepSource::Path {
13486 caminho: "../foo$HOME/bar!sudo".into(),
13487 });
13488 let err = d.validate().unwrap_err();
13489 assert!(
13490 matches!(
13491 err,
13492 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13493 ),
13494 "got {err:?}",
13495 );
13496 }
13497
13498 #[test]
13499 fn fonte_caminho_shell_history_expansion_fires_before_trailing_slash() {
13500 // Cascade pin on the immediate-successor arm: a value carrying
13501 // both embedded `!` and a trailing `/` (`"../caixa-teia!sudo/"`
13502 // — the canonical "I tab-completed a `!sudo`-carrying path")
13503 // routes through `FonteCaminhoShellHistoryExpansion` not
13504 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13505 // expansion byte is the more semantic-locating axis on probe-
13506 // as-both values (an author who removes the `!sudo` history
13507 // reference is likely to also tab-strip the trailing separator).
13508 let d = dep_with_fonte(DepSource::Path {
13509 caminho: "../caixa-teia!sudo/".into(),
13510 });
13511 let err = d.validate().unwrap_err();
13512 assert!(
13513 matches!(
13514 err,
13515 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13516 ),
13517 "got {err:?}",
13518 );
13519 }
13520
13521 #[test]
13522 fn fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13523 // Diagnostic-shape pin (peer with
13524 // `fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13525 // on the immediate-predecessor arm): the error's Display
13526 // surfaces the offending `:nome`, the offending `:caminho`
13527 // verbatim, the offending byte's hex / character form, and
13528 // names the shell-history-expansion / bang-operator footgun
13529 // explicitly so a `feira lint` run can render the diagnostic
13530 // without re-parsing.
13531 let d = dep_with_fonte(DepSource::Path {
13532 caminho: "../caixa-teia!sudo".into(),
13533 });
13534 let rendered = d.validate().unwrap_err().to_string();
13535 assert!(
13536 rendered.contains("caixa-teia"),
13537 "diagnostic must name the offending dep: {rendered}",
13538 );
13539 assert!(
13540 rendered.contains("../caixa-teia!sudo"),
13541 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13542 );
13543 assert!(
13544 rendered.contains("0x21"),
13545 "diagnostic must surface the offending byte hex: {rendered:?}",
13546 );
13547 assert!(
13548 rendered.contains("history-expansion") || rendered.contains("history expansion"),
13549 "diagnostic must name the shell-history-expansion footgun: {rendered:?}",
13550 );
13551 assert!(
13552 rendered.contains("bang"),
13553 "diagnostic must reference the bang-operator vocabulary: {rendered:?}",
13554 );
13555 }
13556
13557 #[test]
13558 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_substitution() {
13559 // The fail-before-pass-after pin for the canonical paste-from-
13560 // shell-history-quick-substitution footgun on `:caminho`. An
13561 // author copies a `git clone <bad-url>` line from their terminal,
13562 // corrects it via bash's `^bad^good` quick-substitution history
13563 // operator (bash reference §9.3, `set -o histexpand` mode's
13564 // default for interactive sessions), and pastes the trailing
13565 // `^bad^good` substitution fragment into a `:caminho` value
13566 // without trimming the leading `git clone` prefix — the byte
13567 // rides into the manifest verbatim. Until this arm landed the
13568 // `^` byte silently passed every prior `:caminho` cascade arm
13569 // (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick / `*`
13570 // / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` / `#` /
13571 // `%` / `$` / `!`); bash with the default `histexpand` mode
13572 // rewrites the prior command's `bad` string to `good` and re-
13573 // executes it, the paired-operator half of the `set -o
13574 // histexpand` feature the peer `!` arm already closes the prefix
13575 // half of. The peer `is_git_repo_url` axis rejects the byte at
13576 // 49e142f under the same shell-history-substitution / RFC-3986-
13577 // unwise banner.
13578 let d = dep_with_fonte(DepSource::Path {
13579 caminho: "../foo^bad^good".into(),
13580 });
13581 let err = d.validate().unwrap_err();
13582 let DepError::FonteCaminhoShellHistorySubstitution {
13583 nome,
13584 caminho,
13585 byte,
13586 } = err
13587 else {
13588 panic!("expected FonteCaminhoShellHistorySubstitution, got {err:?}");
13589 };
13590 assert_eq!(nome, "caixa-teia");
13591 assert_eq!(caminho, "../foo^bad^good");
13592 assert_eq!(byte, b'^');
13593 }
13594
13595 #[test]
13596 fn validate_rejects_path_fonte_with_caminho_carrying_regex_negation_anchor() {
13597 // The symmetric paste-from-doc-grep-pipeline footgun (peer with
13598 // `validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor`
13599 // on `is_git_repo_url`). An author copies a `grep '^archived'`
13600 // regex-anchor / negation idiom from a doc snippet and the byte
13601 // rides in verbatim. Pinned separately from the `^old^new^`
13602 // quick-substitution shape so a future diagnostic-surface change
13603 // that only checked the paired-caret history-substitution
13604 // position surfaces here — the per-byte arm fires anywhere `^`
13605 // appears in the value, including at a solitary leading-of-
13606 // segment position.
13607 let d = dep_with_fonte(DepSource::Path {
13608 caminho: "../foo/^archived".into(),
13609 });
13610 let err = d.validate().unwrap_err();
13611 assert!(
13612 matches!(
13613 err,
13614 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13615 ),
13616 "got {err:?}",
13617 );
13618 }
13619
13620 #[test]
13621 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_history_substitution_open() {
13622 // The trailing-`^` history-substitution-open shape — an author
13623 // starts typing a `^bad^good` quick-substitution but pastes only
13624 // the leading `^` sentinel before context-switching (a bash-
13625 // reference §9.3 valid histexpand prefix on its own — even a
13626 // solitary `^` on the prior command's whole re-execution shape).
13627 // Pinned separately from the `^old^new^` full-form and the leading-
13628 // of-segment `^archived` regex-anchor shape so the gate's
13629 // rationale extends to the paste-from-shell-history-with-only-
13630 // the-first-byte-selected surface. None of the prior shell-
13631 // metachar arms cover this shape.
13632 let d = dep_with_fonte(DepSource::Path {
13633 caminho: "../caixa-teia^".into(),
13634 });
13635 let err = d.validate().unwrap_err();
13636 assert!(
13637 matches!(
13638 err,
13639 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13640 ),
13641 "got {err:?}",
13642 );
13643 }
13644
13645 #[test]
13646 fn validate_accepts_path_fonte_with_caminho_carrying_no_caret() {
13647 // The positive-control pin (peer with
13648 // `validate_accepts_path_fonte_with_caminho_carrying_no_bang`
13649 // on the immediate-predecessor arm): the gate targets only
13650 // `^`, never adjacent printable ASCII or POSIX-valid bytes.
13651 // A relative POSIX path carrying dashes / dots / slashes /
13652 // digits / underscore (`"../caixa-teia/sub_v2.rc"`) must
13653 // continue to validate cleanly so the gate doesn't widen to
13654 // a "no printable punctuation anywhere" sweep that would
13655 // defeat the entire path-fonte author surface.
13656 let d = dep_with_fonte(DepSource::Path {
13657 caminho: "../caixa-teia/sub_v2.rc".into(),
13658 });
13659 d.validate().unwrap();
13660 }
13661
13662 #[test]
13663 fn fonte_caminho_shell_history_expansion_fires_before_shell_history_substitution() {
13664 // Cascade pin on the immediate-predecessor arm: a value carrying
13665 // both embedded `!` and `^` (`"../foo!sudo^bad^good"` — the
13666 // canonical "I pasted a `!sudo` history-reference next to a
13667 // `^bad^good` quick-substitution") routes through
13668 // `FonteCaminhoShellHistoryExpansion` not
13669 // `FonteCaminhoShellHistorySubstitution`. The `!` prefix form is
13670 // the more semantic-locating axis on probe-as-both values (an
13671 // author who removes the `!sudo` reference is likely to also
13672 // strip the paired `^` substitution fragment); same cascade
13673 // discipline every prior `:caminho` arm establishes.
13674 let d = dep_with_fonte(DepSource::Path {
13675 caminho: "../foo!sudo^bad^good".into(),
13676 });
13677 let err = d.validate().unwrap_err();
13678 assert!(
13679 matches!(
13680 err,
13681 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13682 ),
13683 "got {err:?}",
13684 );
13685 }
13686
13687 #[test]
13688 fn fonte_caminho_shell_history_substitution_fires_before_trailing_slash() {
13689 // Cascade pin on the immediate-successor arm: a value carrying
13690 // both embedded `^` and a trailing `/` (`"../foo^bad^good/"` —
13691 // the canonical "I tab-completed a `^bad^good`-carrying path")
13692 // routes through `FonteCaminhoShellHistorySubstitution` not
13693 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13694 // substitution byte is the more semantic-locating axis on probe-
13695 // as-both values (an author who removes the `^bad^good`
13696 // substitution fragment is likely to also tab-strip the trailing
13697 // separator).
13698 let d = dep_with_fonte(DepSource::Path {
13699 caminho: "../foo^bad^good/".into(),
13700 });
13701 let err = d.validate().unwrap_err();
13702 assert!(
13703 matches!(
13704 err,
13705 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13706 ),
13707 "got {err:?}",
13708 );
13709 }
13710
13711 #[test]
13712 fn fonte_caminho_shell_history_substitution_diagnostic_carries_offending_dep_caminho_and_byte()
13713 {
13714 // Diagnostic-shape pin (peer with
13715 // `fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13716 // on the immediate-predecessor arm): the error's Display
13717 // surfaces the offending `:nome`, the offending `:caminho`
13718 // verbatim, the offending byte's hex form, and names the
13719 // shell-history-substitution / RFC-3986-'unwise' / regex-
13720 // negation footgun explicitly so a `feira lint` run can render
13721 // the diagnostic without re-parsing.
13722 let d = dep_with_fonte(DepSource::Path {
13723 caminho: "../foo^bad^good".into(),
13724 });
13725 let rendered = d.validate().unwrap_err().to_string();
13726 assert!(
13727 rendered.contains("caixa-teia"),
13728 "diagnostic must name the offending dep: {rendered}",
13729 );
13730 assert!(
13731 rendered.contains("../foo^bad^good"),
13732 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13733 );
13734 assert!(
13735 rendered.contains("0x5e") || rendered.contains("0x5E"),
13736 "diagnostic must surface the offending byte hex: {rendered:?}",
13737 );
13738 assert!(
13739 rendered.contains("history-substitution") || rendered.contains("history substitution"),
13740 "diagnostic must name the shell-history-substitution footgun: {rendered:?}",
13741 );
13742 assert!(
13743 rendered.contains("unwise"),
13744 "diagnostic must reference the RFC-3986 'unwise' set vocabulary: {rendered:?}",
13745 );
13746 }
13747
13748 #[test]
13749 fn fonte_repo_empty_fires_before_pin_missing() {
13750 // Order pin: empty `:repo` is the more self-locating diagnostic
13751 // (every git source needs a repo; the pin discussion is
13752 // secondary), so it fires before the pin-missing arm even when
13753 // both are violated. Mirrors the
13754 // `nome_empty_takes_precedence_over_versao_invalid` ordering
13755 // discipline on the per-entry layer.
13756 let d = dep_with_fonte(DepSource::Git {
13757 repo: String::new(),
13758 tag: None,
13759 rev: None,
13760 branch: None,
13761 });
13762 let err = d.validate().unwrap_err();
13763 assert!(
13764 matches!(err, DepError::FonteRepoEmpty { .. }),
13765 "got {err:?}"
13766 );
13767 }
13768
13769 #[test]
13770 fn fonte_pin_missing_fires_before_pin_empty() {
13771 // Order pin: a fully-None pin set is structurally distinct from
13772 // a Some(empty) pin — the first surfaces as FontePinMissing
13773 // (no axis chosen), the second as FontePinEmpty (axis chosen
13774 // but value blank). Pin the disjoint relationship so a future
13775 // unification collapses to one variant only as a structural
13776 // decision.
13777 let d = dep_with_fonte(DepSource::Git {
13778 repo: "github:pleme-io/caixa-teia".into(),
13779 tag: None,
13780 rev: None,
13781 branch: None,
13782 });
13783 assert!(matches!(
13784 d.validate().unwrap_err(),
13785 DepError::FontePinMissing { .. }
13786 ));
13787 }
13788
13789 #[test]
13790 fn nome_empty_takes_precedence_over_fonte_invalid() {
13791 // Order pin: a per-entry diagnostic without a non-empty :nome
13792 // can't be self-locating, so :nome "" fires first even when
13793 // :fonte is also malformed. Mirrors
13794 // `nome_empty_takes_precedence_over_versao_invalid` on the
13795 // adjacent axis.
13796 let mut d = dep_with_fonte(DepSource::Git {
13797 repo: String::new(),
13798 tag: None,
13799 rev: None,
13800 branch: None,
13801 });
13802 d.nome = String::new();
13803 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
13804 }
13805
13806 #[test]
13807 fn versao_invalid_takes_precedence_over_fonte_invalid() {
13808 // Order pin: the :versao parse-side diagnostic is narrower than
13809 // the :fonte shape diagnostic — a malformed :versao always names
13810 // the parser's reason, which is more actionable than the
13811 // :fonte gate's "the pins are wrong" wording. Pin the ordering
13812 // so a re-ordering surfaces here.
13813 let mut d = dep_with_fonte(DepSource::Git {
13814 repo: String::new(),
13815 tag: None,
13816 rev: None,
13817 branch: None,
13818 });
13819 d.versao = "v0.1".into();
13820 let err = d.validate().unwrap_err();
13821 assert!(
13822 matches!(err, DepError::VersaoInvalid { ref nome, .. } if nome == "caixa-teia"),
13823 "got {err:?}"
13824 );
13825 }
13826
13827 #[test]
13828 fn fonte_invalid_diagnostic_carries_offending_nome() {
13829 // The diagnostic-shape pin: every :fonte error variant names
13830 // the offending dep's :nome verbatim, so the author can grep
13831 // caixa.lisp for the `:nome "<n>"` block and fix it in one
13832 // edit. Cover all seven variants so a future variant addition
13833 // forces a parallel diagnostic-shape decision.
13834 for (case, fonte) in [
13835 (
13836 "repo-empty",
13837 DepSource::Git {
13838 repo: String::new(),
13839 tag: Some("v1".into()),
13840 rev: None,
13841 branch: None,
13842 },
13843 ),
13844 (
13845 "repo-shape",
13846 DepSource::Git {
13847 repo: "github:p/x ".into(),
13848 tag: Some("v1".into()),
13849 rev: None,
13850 branch: None,
13851 },
13852 ),
13853 (
13854 "pin-missing",
13855 DepSource::Git {
13856 repo: "github:p/x".into(),
13857 tag: None,
13858 rev: None,
13859 branch: None,
13860 },
13861 ),
13862 (
13863 "pin-ambiguous",
13864 DepSource::Git {
13865 repo: "github:p/x".into(),
13866 tag: Some("v1".into()),
13867 rev: None,
13868 branch: Some("main".into()),
13869 },
13870 ),
13871 (
13872 "pin-empty",
13873 DepSource::Git {
13874 repo: "github:p/x".into(),
13875 tag: Some(String::new()),
13876 rev: None,
13877 branch: None,
13878 },
13879 ),
13880 (
13881 "caminho-empty",
13882 DepSource::Path {
13883 caminho: String::new(),
13884 },
13885 ),
13886 (
13887 "caminho-absolute",
13888 DepSource::Path {
13889 caminho: "/home/me/work/caixa-teia".into(),
13890 },
13891 ),
13892 ] {
13893 let d = dep_with_fonte(fonte);
13894 let msg = d
13895 .validate()
13896 .expect_err(&format!("{case}: expected fonte error"))
13897 .to_string();
13898 assert!(
13899 msg.contains("\"caixa-teia\""),
13900 "{case}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
13901 );
13902 }
13903 }
13904
13905 // -- :tag / :branch value-shape gate ----------------------------------
13906
13907 #[test]
13908 fn validate_rejects_git_fonte_with_tag_carrying_trailing_space() {
13909 // The canonical paste-from-doc footgun on `:tag` — author
13910 // copies `"v0.1.0 "` (trailing space) out of a release-notes
13911 // paragraph. Until this gate landed the empty-pin arm passed
13912 // (the string isn't empty), the resolver issued
13913 // `git fetch <remote> tag 'v0.1.0 '`, and the failure
13914 // surfaced at clone time with a quoting-confused git error
13915 // far from the source caixa.lisp. The new gate moves the
13916 // check to caixa-build time and names the offending dep +
13917 // pin + value verbatim.
13918 let d = dep_with_fonte(DepSource::Git {
13919 repo: "github:pleme-io/caixa-teia".into(),
13920 tag: Some("v0.1.0 ".into()),
13921 rev: None,
13922 branch: None,
13923 });
13924 let err = d.validate().unwrap_err();
13925 let DepError::FontePinShape {
13926 nome,
13927 pin,
13928 value,
13929 reason,
13930 } = err
13931 else {
13932 panic!("expected FontePinShape, got other variant");
13933 };
13934 assert_eq!(nome, "caixa-teia");
13935 assert_eq!(pin, ":tag");
13936 assert_eq!(value, "v0.1.0 ");
13937 assert!(
13938 reason.contains("whitespace"),
13939 "reason must surface the whitespace arm, got {reason:?}"
13940 );
13941 }
13942
13943 #[test]
13944 fn validate_rejects_git_fonte_with_tag_carrying_lock_suffix() {
13945 // The `.lock` suffix is git's atomic-rename guard for
13946 // in-flight ref updates — a refname ending in `.lock` is
13947 // unwritable on disk. Pinned separately from the whitespace
13948 // arm so a future relaxation that admits one but not the
13949 // other surfaces here.
13950 let d = dep_with_fonte(DepSource::Git {
13951 repo: "github:pleme-io/caixa-teia".into(),
13952 tag: Some("v0.1.0.lock".into()),
13953 rev: None,
13954 branch: None,
13955 });
13956 let err = d.validate().unwrap_err();
13957 let DepError::FontePinShape {
13958 pin, value, reason, ..
13959 } = err
13960 else {
13961 panic!("expected FontePinShape, got other variant");
13962 };
13963 assert_eq!(pin, ":tag");
13964 assert_eq!(value, "v0.1.0.lock");
13965 assert!(
13966 reason.contains(".lock"),
13967 "reason must surface the .lock arm, got {reason:?}"
13968 );
13969 }
13970
13971 #[test]
13972 fn validate_rejects_git_fonte_with_branch_carrying_embedded_space() {
13973 // The canonical "branch name with spaces" footgun (`feature
13974 // foo`, `release branch`) — git's refname parser rejects raw
13975 // whitespace, and the failure surfaces at `git checkout
13976 // 'feature foo'` time with a quoting-confused error far from
13977 // the source caixa.lisp. Pinned on the `:branch` axis so the
13978 // gate-applies-to-both-:tag-and-:branch contract is a build-
13979 // error to relax.
13980 let d = dep_with_fonte(DepSource::Git {
13981 repo: "github:pleme-io/caixa-teia".into(),
13982 tag: None,
13983 rev: None,
13984 branch: Some("feature/foo bar".into()),
13985 });
13986 let err = d.validate().unwrap_err();
13987 let DepError::FontePinShape {
13988 pin, value, reason, ..
13989 } = err
13990 else {
13991 panic!("expected FontePinShape, got other variant");
13992 };
13993 assert_eq!(pin, ":branch");
13994 assert_eq!(value, "feature/foo bar");
13995 assert!(
13996 reason.contains("whitespace"),
13997 "reason must surface the whitespace arm, got {reason:?}"
13998 );
13999 }
14000
14001 #[test]
14002 fn validate_rejects_git_fonte_with_branch_carrying_qualified_prefix() {
14003 // The `refs/heads/main` shape — the canonical "I copied the
14004 // fully-qualified ref out of `git show-ref` instead of the
14005 // leaf" footgun. The caixa-resolver prepends `refs/heads/`
14006 // at clone time, so this resolves to a literal ref named
14007 // `refs/heads/refs/heads/main` on disk; the silent double-
14008 // prefix is the load-bearing reason to gate at validate.
14009 // The diagnostic must enumerate the leaf the author probably
14010 // meant (`"main"`) so the fix is one edit.
14011 let d = dep_with_fonte(DepSource::Git {
14012 repo: "github:pleme-io/caixa-teia".into(),
14013 tag: None,
14014 rev: None,
14015 branch: Some("refs/heads/main".into()),
14016 });
14017 let err = d.validate().unwrap_err();
14018 let DepError::FontePinShape {
14019 pin, value, reason, ..
14020 } = err
14021 else {
14022 panic!("expected FontePinShape, got other variant");
14023 };
14024 assert_eq!(pin, ":branch");
14025 assert_eq!(value, "refs/heads/main");
14026 assert!(
14027 reason.contains("fully-qualified"),
14028 "reason must surface the qualified-prefix arm, got {reason:?}"
14029 );
14030 assert!(
14031 reason.contains("\"main\""),
14032 "reason must quote the leaf the author probably meant, got {reason:?}"
14033 );
14034 }
14035
14036 #[test]
14037 fn validate_rejects_git_fonte_with_tag_carrying_qualified_prefix() {
14038 // Sibling arm of the qualified-prefix gate on the `:tag`
14039 // axis (`refs/tags/v0.1.0` — same `git show-ref` output-leak
14040 // footgun). Pinned separately so a future relaxation that
14041 // only catches the `:branch` arm surfaces here.
14042 let d = dep_with_fonte(DepSource::Git {
14043 repo: "github:pleme-io/caixa-teia".into(),
14044 tag: Some("refs/tags/v0.1.0".into()),
14045 rev: None,
14046 branch: None,
14047 });
14048 let err = d.validate().unwrap_err();
14049 let DepError::FontePinShape {
14050 pin, value, reason, ..
14051 } = err
14052 else {
14053 panic!("expected FontePinShape, got other variant");
14054 };
14055 assert_eq!(pin, ":tag");
14056 assert_eq!(value, "refs/tags/v0.1.0");
14057 assert!(
14058 reason.contains("fully-qualified"),
14059 "reason must surface the qualified-prefix arm, got {reason:?}"
14060 );
14061 assert!(
14062 reason.contains("\"v0.1.0\""),
14063 "reason must quote the leaf the author probably meant, got {reason:?}"
14064 );
14065 }
14066
14067 #[test]
14068 fn validate_rejects_git_fonte_with_branch_named_at() {
14069 // The bare `@` is git's alias for `HEAD`; a `:branch "@"` is
14070 // unsourceable. Pinned so a future relaxation that admits
14071 // any single-character refname surfaces here.
14072 let d = dep_with_fonte(DepSource::Git {
14073 repo: "github:pleme-io/caixa-teia".into(),
14074 tag: None,
14075 rev: None,
14076 branch: Some("@".into()),
14077 });
14078 let err = d.validate().unwrap_err();
14079 let DepError::FontePinShape { pin, value, .. } = err else {
14080 panic!("expected FontePinShape, got other variant");
14081 };
14082 assert_eq!(pin, ":branch");
14083 assert_eq!(value, "@");
14084 }
14085
14086 #[test]
14087 fn validate_rejects_git_fonte_with_tag_carrying_double_dot() {
14088 // Git's `<rev1>..<rev2>` range grammar reserves `..` —
14089 // a `:tag "../escape"` (path-traversal-shaped slug) silently
14090 // passes parse and surfaces as a refname-parse error or, on
14091 // older git, a literal `../escape` checkout that escapes the
14092 // refs/ directory tree. Pinned separately from the
14093 // qualified-prefix arm so a future relaxation that catches
14094 // one but not the other surfaces here.
14095 let d = dep_with_fonte(DepSource::Git {
14096 repo: "github:pleme-io/caixa-teia".into(),
14097 tag: Some("../escape".into()),
14098 rev: None,
14099 branch: None,
14100 });
14101 let err = d.validate().unwrap_err();
14102 let DepError::FontePinShape { pin, value, .. } = err else {
14103 panic!("expected FontePinShape, got other variant");
14104 };
14105 assert_eq!(pin, ":tag");
14106 assert_eq!(value, "../escape");
14107 }
14108
14109 #[test]
14110 fn validate_accepts_git_fonte_with_hierarchical_branch() {
14111 // The positive-control pin: hierarchical refnames with one or
14112 // more `/` separators (the `feature/foo` / `user/jdoe/feat`
14113 // canonical idiom) round-trip through the gate. Pinned
14114 // separately from the leaf-`"main"` positive control so a
14115 // future tightening that rejects all multi-component refnames
14116 // surfaces here.
14117 let d = dep_with_fonte(DepSource::Git {
14118 repo: "github:pleme-io/caixa-teia".into(),
14119 tag: None,
14120 rev: None,
14121 branch: Some("feature/checkout-rewrite".into()),
14122 });
14123 d.validate().unwrap();
14124 }
14125
14126 #[test]
14127 fn validate_accepts_git_fonte_with_prerelease_tag() {
14128 // The positive-control pin: semver pre-release shape
14129 // (`v0.1.0-alpha.1`) — the in-component dot is allowed
14130 // (only consecutive `..` and trailing `.` are rejected), the
14131 // mid-component hyphen is allowed. Pinned separately from
14132 // the bare-`"v0.1.0"` positive control so a future tightening
14133 // that rejects pre-release tags surfaces here.
14134 let d = dep_with_fonte(DepSource::Git {
14135 repo: "github:pleme-io/caixa-teia".into(),
14136 tag: Some("v0.1.0-alpha.1".into()),
14137 rev: None,
14138 branch: None,
14139 });
14140 d.validate().unwrap();
14141 }
14142
14143 #[test]
14144 fn validate_rejects_git_fonte_with_rev_carrying_refname_unfriendly_value() {
14145 // The `:rev` axis is routed through `crate::render::is_git_oid`
14146 // (a SHA's character set is `[0-9a-f]`, not a refname's), so a
14147 // value with refname-shape punctuation (here, a `:` mid-string
14148 // — would be a refname violation under `is_git_ref_name` too)
14149 // is rejected at the OID-shape gate. The two predicates
14150 // partition the `:fonte` pin axes structurally: an `:rev` value
14151 // that's a valid refname (`:rev "main"`, `:rev "v0.1.0"`) is
14152 // *still* rejected here because every refname character outside
14153 // `[0-9a-f]` fails the OID gate. Same shape as
14154 // `fonte_pin_shape_diagnostic_carries_offending_nome_pin_value`
14155 // on the refname-shaped axes — the diagnostic names the
14156 // offending dep + pin + value verbatim. The flip-from-accept
14157 // case the prior `:tag`/`:branch` gate left as a "future axis"
14158 // (e70d213) — now landed.
14159 let d = dep_with_fonte(DepSource::Git {
14160 repo: "github:pleme-io/caixa-teia".into(),
14161 tag: None,
14162 rev: Some("c0ffee:notarefname".into()),
14163 branch: None,
14164 });
14165 let err = d.validate().unwrap_err();
14166 let DepError::FontePinShape {
14167 nome,
14168 pin,
14169 value,
14170 reason,
14171 } = err
14172 else {
14173 panic!("expected FontePinShape, got other variant");
14174 };
14175 assert_eq!(nome, "caixa-teia");
14176 assert_eq!(pin, ":rev");
14177 assert_eq!(value, "c0ffee:notarefname");
14178 assert!(
14179 !reason.is_empty(),
14180 "FontePinShape `reason` must carry the predicate's wording verbatim"
14181 );
14182 }
14183
14184 #[test]
14185 fn validate_accepts_git_fonte_with_rev_full_sha1() {
14186 // The positive-control pin on the SHA-1 OID width: exactly 40
14187 // lowercase hex characters — the canonical `git rev-parse HEAD`
14188 // emission on a SHA-1-hashed repository (the default on every
14189 // pre-2.42 git and the canonical pleme-io substrate hash).
14190 // Pinned separately from the SHA-256 positive control so a
14191 // future tightening that only admits one width surfaces here.
14192 let d = dep_with_fonte(DepSource::Git {
14193 repo: "github:pleme-io/caixa-teia".into(),
14194 tag: None,
14195 rev: Some("0123456789abcdef0123456789abcdef01234567".into()),
14196 branch: None,
14197 });
14198 d.validate().unwrap();
14199 }
14200
14201 #[test]
14202 fn validate_accepts_git_fonte_with_rev_full_sha256() {
14203 // The positive-control pin on the SHA-256 OID width: exactly
14204 // 64 lowercase hex characters — `git`'s
14205 // `extensions.objectFormat = sha256` emission (GA since Git
14206 // 2.42 / Oct 2023). The substrate admits either canonical
14207 // width so an `:rev` authored against a SHA-256-hashed
14208 // upstream round-trips through the gate without per-repo
14209 // configuration. Pinned separately from the SHA-1 positive
14210 // control so a future tightening that drops one width surfaces
14211 // here as a structural decision.
14212 let d = dep_with_fonte(DepSource::Git {
14213 repo: "github:pleme-io/caixa-teia".into(),
14214 tag: None,
14215 rev: Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into()),
14216 branch: None,
14217 });
14218 d.validate().unwrap();
14219 }
14220
14221 #[test]
14222 fn validate_rejects_git_fonte_with_rev_abbreviated_prefix() {
14223 // The canonical `git log --short` / `git rev-parse --short HEAD`
14224 // paste-from-release-notes footgun: a 7-char prefix (git's
14225 // default `core.abbrev`) silently passes string emptiness
14226 // checks and resolves to one commit today, but becomes ambiguous
14227 // tomorrow as the repo grows. Until this gate landed the empty-
14228 // pin arm passed (the string isn't empty) and the resolver
14229 // accepted the prefix through git's separate prefix-lookup pass
14230 // — defeating the reproducibility contract `:rev` carries vs.
14231 // `:tag` / `:branch`. The new gate moves the check to caixa-
14232 // build time and names the offending dep + pin + value verbatim.
14233 let d = dep_with_fonte(DepSource::Git {
14234 repo: "github:pleme-io/caixa-teia".into(),
14235 tag: None,
14236 rev: Some("c0ffee0".into()),
14237 branch: None,
14238 });
14239 let err = d.validate().unwrap_err();
14240 let DepError::FontePinShape {
14241 pin, value, reason, ..
14242 } = err
14243 else {
14244 panic!("expected FontePinShape, got other variant");
14245 };
14246 assert_eq!(pin, ":rev");
14247 assert_eq!(value, "c0ffee0");
14248 assert!(
14249 reason.contains("abbreviated") || reason.contains("ambiguous"),
14250 "reason must surface the abbreviation arm, got {reason:?}"
14251 );
14252 }
14253
14254 #[test]
14255 fn validate_rejects_git_fonte_with_rev_uppercase_hex() {
14256 // The canonical "I pasted the SHA in uppercase" footgun: `git
14257 // porcelain` emits OIDs lowercase exclusively, so an uppercase-
14258 // bearing `:rev` round-trips inconsistently across the
14259 // resolver's `git fetch <remote> <:rev>` ↔ `git rev-parse HEAD`
14260 // equality-check pipeline and fails the lacre's content-
14261 // addressing probe with a confusing case-only diff. Pinned
14262 // separately from the non-hex arm so a future relaxation that
14263 // admits one but not the other surfaces here.
14264 let d = dep_with_fonte(DepSource::Git {
14265 repo: "github:pleme-io/caixa-teia".into(),
14266 tag: None,
14267 rev: Some("DEADBEEFCAFEBABE0123456789ABCDEF01234567".into()),
14268 branch: None,
14269 });
14270 let err = d.validate().unwrap_err();
14271 let DepError::FontePinShape {
14272 pin, value, reason, ..
14273 } = err
14274 else {
14275 panic!("expected FontePinShape, got other variant");
14276 };
14277 assert_eq!(pin, ":rev");
14278 assert_eq!(value, "DEADBEEFCAFEBABE0123456789ABCDEF01234567");
14279 assert!(
14280 reason.contains("uppercase"),
14281 "reason must surface the uppercase arm, got {reason:?}"
14282 );
14283 }
14284
14285 #[test]
14286 fn validate_rejects_git_fonte_with_rev_refname_value() {
14287 // The cross-axis mis-slot footgun: `:rev "main"` — the author
14288 // conflated `:rev` (hex commit ID, immutable) and `:branch`
14289 // (mutable ref pointing at whatever HEAD is today). Until this
14290 // gate landed the resolver silently dispatched on the value
14291 // shape ("`main` doesn't look like a SHA, fall back to
14292 // refname"), defeating the `:rev` reproducibility contract.
14293 // The new gate rejects every non-hex value on the `:rev` axis,
14294 // so the `:rev`/`:branch` boundary is structurally enforced —
14295 // a refname in the `:rev` slot is a build error, not a
14296 // resolver-time silent reinterpretation.
14297 let d = dep_with_fonte(DepSource::Git {
14298 repo: "github:pleme-io/caixa-teia".into(),
14299 tag: None,
14300 rev: Some("main".into()),
14301 branch: None,
14302 });
14303 let err = d.validate().unwrap_err();
14304 let DepError::FontePinShape {
14305 pin, value, reason, ..
14306 } = err
14307 else {
14308 panic!("expected FontePinShape, got other variant");
14309 };
14310 assert_eq!(pin, ":rev");
14311 assert_eq!(value, "main");
14312 // 4 chars `main` fails the length arm before the character arm,
14313 // so the diagnostic surfaces the abbreviation wording (same
14314 // path the `c0ffee0` 7-char fixture lands on); the structural
14315 // assertion is just that the `:rev "main"` value is rejected.
14316 assert!(
14317 !reason.is_empty(),
14318 "FontePinShape reason must be non-empty for refname-shaped :rev"
14319 );
14320 }
14321
14322 #[test]
14323 fn validate_rejects_git_fonte_with_rev_tag_shaped_value() {
14324 // Sibling cross-axis mis-slot: `:rev "v0.1.0"` — the author
14325 // conflated `:rev` and `:tag`. Pinned separately from the
14326 // `:rev "main"` (`:branch` mis-slot) arm so a future relaxation
14327 // that catches one but not the other surfaces here. The
14328 // length arm fires first (6 chars ≠ 40 ≠ 64); the structural
14329 // assertion is just that the cross-axis mis-slot is a build
14330 // error, regardless of which sub-arm surfaces the diagnostic
14331 // (`is_git_oid` rejects at the first violation; longer
14332 // tag-shape values would hit the non-hex arm instead).
14333 let d = dep_with_fonte(DepSource::Git {
14334 repo: "github:pleme-io/caixa-teia".into(),
14335 tag: None,
14336 rev: Some("v0.1.0".into()),
14337 branch: None,
14338 });
14339 let err = d.validate().unwrap_err();
14340 let DepError::FontePinShape {
14341 pin, value, reason, ..
14342 } = err
14343 else {
14344 panic!("expected FontePinShape, got other variant");
14345 };
14346 assert_eq!(pin, ":rev");
14347 assert_eq!(value, "v0.1.0");
14348 assert!(
14349 !reason.is_empty(),
14350 "FontePinShape reason must be non-empty for tag-shaped :rev"
14351 );
14352 }
14353
14354 #[test]
14355 fn validate_rejects_git_fonte_with_rev_too_long() {
14356 // Boundary case on the upper end: 41 hex chars — one past the
14357 // SHA-1 width, well below the SHA-256 width. Pin so a future
14358 // relaxation that admits "long enough to be a SHA" without
14359 // matching either canonical width surfaces here. The diagnostic
14360 // names the offending length verbatim so the author's grep
14361 // target is unambiguous (either trim one char or paste the
14362 // full SHA-256).
14363 let too_long: String = "0".repeat(41);
14364 let d = dep_with_fonte(DepSource::Git {
14365 repo: "github:pleme-io/caixa-teia".into(),
14366 tag: None,
14367 rev: Some(too_long.clone()),
14368 branch: None,
14369 });
14370 let err = d.validate().unwrap_err();
14371 let DepError::FontePinShape {
14372 pin, value, reason, ..
14373 } = err
14374 else {
14375 panic!("expected FontePinShape, got other variant");
14376 };
14377 assert_eq!(pin, ":rev");
14378 assert_eq!(value, too_long);
14379 assert!(
14380 reason.contains("41"),
14381 "reason must surface the offending length verbatim, got {reason:?}"
14382 );
14383 }
14384
14385 #[test]
14386 fn validate_rejects_git_fonte_with_rev_carrying_whitespace() {
14387 // The canonical paste-from-doc footgun on `:rev` — author
14388 // copies `"deadbeefcafe…0123 "` (trailing space) out of a
14389 // commit-message paragraph. Until this gate landed the empty-
14390 // pin arm passed (the string isn't empty), the resolver issued
14391 // `git fetch <remote> 'deadbeef… '` and the failure surfaced at
14392 // clone time with a quoting-confused git error far from the
14393 // source caixa.lisp. The new gate moves the check to caixa-
14394 // build time. Length is 41 (40 hex + space) so the length arm
14395 // fires first — pinned separately from the pure-length arm to
14396 // ensure the diagnostic surfaces *some* parser wording, not
14397 // silently pass through.
14398 let with_space = "0123456789abcdef0123456789abcdef01234567 ".to_string();
14399 let d = dep_with_fonte(DepSource::Git {
14400 repo: "github:pleme-io/caixa-teia".into(),
14401 tag: None,
14402 rev: Some(with_space.clone()),
14403 branch: None,
14404 });
14405 let err = d.validate().unwrap_err();
14406 let DepError::FontePinShape {
14407 pin, value, reason, ..
14408 } = err
14409 else {
14410 panic!("expected FontePinShape, got other variant");
14411 };
14412 assert_eq!(pin, ":rev");
14413 assert_eq!(value, with_space);
14414 assert!(
14415 !reason.is_empty(),
14416 "FontePinShape reason must be non-empty for whitespace-bearing :rev"
14417 );
14418 }
14419
14420 #[test]
14421 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value_for_rev() {
14422 // Diagnostic-shape pin on the `:rev` axis: every FontePinShape
14423 // variant on this axis names the offending dep's `:nome` + the
14424 // `:rev` axis + the offending value verbatim, so the author's
14425 // grep target is the literal `:rev "<value>"` block in
14426 // caixa.lisp. Sibling of the `fonte_pin_shape_diagnostic_
14427 // carries_offending_nome_pin_value` test on the refname-shaped
14428 // (`:tag` / `:branch`) axes.
14429 let d = dep_with_fonte(DepSource::Git {
14430 repo: "github:p/x".into(),
14431 tag: None,
14432 rev: Some("not-a-sha".into()),
14433 branch: None,
14434 });
14435 let msg = d
14436 .validate()
14437 .expect_err(":rev: expected FontePinShape")
14438 .to_string();
14439 assert!(
14440 msg.contains("\"caixa-teia\""),
14441 ":rev: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14442 );
14443 assert!(
14444 msg.contains(":rev"),
14445 ":rev: diagnostic must name the offending pin axis, got {msg:?}"
14446 );
14447 assert!(
14448 msg.contains("not-a-sha"),
14449 ":rev: diagnostic must quote the offending value verbatim, got {msg:?}"
14450 );
14451 }
14452
14453 #[test]
14454 fn fonte_pin_empty_fires_before_pin_shape() {
14455 // Order pin: a `Some("")` `:tag` is the more self-locating
14456 // diagnostic (the author chose an axis but left it blank;
14457 // grep is unambiguous), so it fires before the shape gate
14458 // even when both arms would match. Pinned so a future
14459 // reordering surfaces here. Mirrors the
14460 // `fonte_repo_empty_fires_before_pin_missing` ordering
14461 // discipline on the peer per-axis arms.
14462 let d = dep_with_fonte(DepSource::Git {
14463 repo: "github:pleme-io/caixa-teia".into(),
14464 tag: Some(String::new()),
14465 rev: None,
14466 branch: None,
14467 });
14468 assert!(matches!(
14469 d.validate().unwrap_err(),
14470 DepError::FontePinEmpty { ref pin, .. } if pin == ":tag"
14471 ));
14472 }
14473
14474 #[test]
14475 fn fonte_pin_shape_fires_after_repo_empty() {
14476 // Order pin: `:repo ""` is the more self-locating axis
14477 // (every git source needs a repo; the per-pin shape gate is
14478 // secondary), so the repo-empty arm fires before the
14479 // per-pin shape arm even when both are violated. Pinned so
14480 // a future reordering surfaces here. Mirrors
14481 // `fonte_repo_empty_fires_before_pin_missing` on the
14482 // adjacent axis pair.
14483 let d = dep_with_fonte(DepSource::Git {
14484 repo: String::new(),
14485 tag: Some("v0.1.0 ".into()),
14486 rev: None,
14487 branch: None,
14488 });
14489 assert!(matches!(
14490 d.validate().unwrap_err(),
14491 DepError::FonteRepoEmpty { .. }
14492 ));
14493 }
14494
14495 #[test]
14496 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value() {
14497 // Diagnostic-shape pin across both refname-shaped axes
14498 // (`:tag` + `:branch`): every `FontePinShape` variant names
14499 // the offending dep's `:nome` + the offending pin axis + the
14500 // offending value verbatim, so the author's grep target is
14501 // unambiguous (the literal `:tag "<value>"` / `:branch
14502 // "<value>"` lands in caixa.lisp with quotes). Cover both
14503 // pin axes so a future variant addition forces a parallel
14504 // diagnostic-shape decision.
14505 for (pin_label, fonte) in [
14506 (
14507 ":tag",
14508 DepSource::Git {
14509 repo: "github:p/x".into(),
14510 tag: Some("v0.1.0~1".into()),
14511 rev: None,
14512 branch: None,
14513 },
14514 ),
14515 (
14516 ":branch",
14517 DepSource::Git {
14518 repo: "github:p/x".into(),
14519 tag: None,
14520 rev: None,
14521 branch: Some("feature/foo*".into()),
14522 },
14523 ),
14524 ] {
14525 let d = dep_with_fonte(fonte);
14526 let msg = d
14527 .validate()
14528 .expect_err(&format!("{pin_label}: expected FontePinShape"))
14529 .to_string();
14530 assert!(
14531 msg.contains("\"caixa-teia\""),
14532 "{pin_label}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14533 );
14534 assert!(
14535 msg.contains(pin_label),
14536 "{pin_label}: diagnostic must name the offending pin axis, got {msg:?}"
14537 );
14538 }
14539 }
14540
14541 #[test]
14542 fn git_source_json_round_trip() {
14543 let src = DepSource::Git {
14544 repo: "github:pleme-io/caixa-teia".into(),
14545 tag: Some("v0.1.0".into()),
14546 rev: None,
14547 branch: None,
14548 };
14549 let s = serde_json::to_string(&src).unwrap();
14550 assert!(s.contains(&format!(
14551 r#""{tipo}":"{git}""#,
14552 tipo = crate::render::DEP_SOURCE_KEY_TIPO,
14553 git = crate::render::DEP_SOURCE_TIPO_GIT,
14554 )));
14555 assert!(s.contains(r#""repo":"github:pleme-io/caixa-teia""#));
14556 assert!(s.contains(r#""tag":"v0.1.0""#));
14557 assert!(!s.contains("rev"));
14558 assert!(!s.contains("branch"));
14559 let round: DepSource = serde_json::from_str(&s).unwrap();
14560 assert_eq!(round, src);
14561 }
14562
14563 // ── DEP_SOURCE_{KEY_TIPO,TIPO_GIT,TIPO_PATH} drift-detection ────────
14564 //
14565 // The `#[serde(tag = "tipo", rename_all = "lowercase")]` derive
14566 // attribute on [`DepSource`] pins three load-bearing byte-sequences
14567 // that flow into every serialized `Dep.fonte` block: the outer
14568 // discriminator-key `"tipo"` the `tag = "tipo"` attribute names, and
14569 // the two admitted variant-tag values `"git"` / `"path"` the
14570 // `rename_all = "lowercase"` attribute pins as the discriminator's
14571 // closed-set arms. The three pin tests below round-trip a
14572 // fully-populated variant of each arm through
14573 // [`serde_json::to_value`] and assert each canonical byte-sequence
14574 // appears at its axis — pins a hypothetical future
14575 // `tag = "type"` / `tag = "source_type"` typo, a `rename_all`
14576 // rebrand (`"UPPERCASE"` / `"snake_case"` / `"kebab-case"`), or a
14577 // Rust-side variant rename (`Git` → `Repository`, `Path` → `Local`)
14578 // at build time rather than at fetch time when the resolver's
14579 // `Dep.fonte` dispatch silently fails to match on the drifted
14580 // discriminator. Same "serialize-and-check" discipline the peer
14581 // `M2_LIMITS_KEY_*`, `M2_BEHAVIOR_KEY_ON_*`, `SUPERVISOR_KEY_*`,
14582 // and `MEMBRO_KEY_*` drift-detection pins carry — extended here
14583 // to the last `#[serde(tag = ..., rename_all = ...)]` discriminator
14584 // family in caixa-core lacking a lifted peer.
14585
14586 #[test]
14587 fn dep_source_git_serde_keys_match_lifted_dep_source_key_consts() {
14588 // Fail-before-pass-after: a future `tag = "type"` at the derive
14589 // attribute would serialize under `"type":"git"`, and this test
14590 // would trip because `"tipo"` no longer appears at the emitted
14591 // discriminator key. A future `rename_all = "kebab-case"` /
14592 // `"snake_case"` (both no-ops on `Git` since it lacks internal
14593 // word boundaries) is caught by the sibling
14594 // `dep_source_path_serde_keys_match_lifted_dep_source_key_consts`
14595 // pin below (Path has no internal boundary either but the pair
14596 // catches any per-arm inconsistency). A future variant rename
14597 // `Git` → `Repository` would emit `"tipo":"repository"` and
14598 // trip this pin.
14599 let src = DepSource::Git {
14600 repo: "github:pleme-io/caixa-teia".into(),
14601 tag: Some("v0.1.0".into()),
14602 rev: None,
14603 branch: None,
14604 };
14605 let json = serde_json::to_value(&src).unwrap();
14606 let obj = json.as_object().expect("Git serializes as a JSON object");
14607 assert_eq!(
14608 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14609 .and_then(serde_json::Value::as_str),
14610 Some(crate::render::DEP_SOURCE_TIPO_GIT),
14611 "DepSource::Git must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14612 with value DEP_SOURCE_TIPO_GIT — attribute drift or variant rename \
14613 detected in {json}"
14614 );
14615 }
14616
14617 #[test]
14618 fn dep_source_path_serde_keys_match_lifted_dep_source_key_consts() {
14619 // Fail-before-pass-after: a future variant rename `Path` →
14620 // `Local` / `Filesystem` would emit `"tipo":"local"` and trip
14621 // this pin. A per-consumer disambiguation as the `defcaixa`
14622 // macro stabilizes ("caminho" → "path" for English-uniformity)
14623 // is scoped to the inner field key, not the discriminator; this
14624 // pin is orthogonal to that and catches only the outer
14625 // discriminator drift.
14626 let src = DepSource::Path {
14627 caminho: "../caixa-teia".into(),
14628 };
14629 let json = serde_json::to_value(&src).unwrap();
14630 let obj = json.as_object().expect("Path serializes as a JSON object");
14631 assert_eq!(
14632 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14633 .and_then(serde_json::Value::as_str),
14634 Some(crate::render::DEP_SOURCE_TIPO_PATH),
14635 "DepSource::Path must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14636 with value DEP_SOURCE_TIPO_PATH — attribute drift or variant rename \
14637 detected in {json}"
14638 );
14639 }
14640
14641 #[test]
14642 fn dep_source_key_consts_are_pairwise_distinct() {
14643 // Cross-axis collapse detector: a hypothetical future edit that
14644 // accidentally set two of the three consts to the same byte
14645 // (`DEP_SOURCE_TIPO_GIT = "path"` typo matching a peer arm) would
14646 // pass every per-arm serialize pin above but silently collapse
14647 // the discriminator's closed-set arms onto one another; this pin
14648 // catches the collapse at build time.
14649 assert_ne!(
14650 crate::render::DEP_SOURCE_KEY_TIPO,
14651 crate::render::DEP_SOURCE_TIPO_GIT,
14652 );
14653 assert_ne!(
14654 crate::render::DEP_SOURCE_KEY_TIPO,
14655 crate::render::DEP_SOURCE_TIPO_PATH,
14656 );
14657 assert_ne!(
14658 crate::render::DEP_SOURCE_TIPO_GIT,
14659 crate::render::DEP_SOURCE_TIPO_PATH,
14660 );
14661 }
14662
14663 #[test]
14664 fn dep_source_tipo_variant_consts_are_ascii_lowercase_shape() {
14665 // Shape pin against `rename_all` drift: the two variant-tag
14666 // consts must be ASCII-lowercase-only to match the
14667 // `rename_all = "lowercase"` attribute the derive uses; a future
14668 // rebrand to `"UPPERCASE"` / `"PascalCase"` at the attribute
14669 // would emit `"GIT"` / `"Git"` instead and trip this pin.
14670 for (label, s) in [
14671 ("DEP_SOURCE_TIPO_GIT", crate::render::DEP_SOURCE_TIPO_GIT),
14672 ("DEP_SOURCE_TIPO_PATH", crate::render::DEP_SOURCE_TIPO_PATH),
14673 ] {
14674 assert!(!s.is_empty(), "{label} must not be empty");
14675 assert!(
14676 s.bytes().all(|b| b.is_ascii_lowercase()),
14677 "{label} must be ASCII-lowercase-only (matching \
14678 rename_all = \"lowercase\"), got {s:?}",
14679 );
14680 }
14681 }
14682
14683 // ── per-entry :caracteristicas set-not-multiset gate ────────────
14684 //
14685 // Every Vec-keyed-by-name authoring surface on the typed Caixa
14686 // surface that identifies its entries by a name field now uniformly
14687 // closes the set-not-multiset discipline at build time (cite
14688 // `validate_caracteristicas`'s peer-axis enumeration). The
14689 // `:caracteristicas` axis is per-`Dep`: the feature-toggle slot is
14690 // set-shaped (a feature is either enabled or not — there is no
14691 // `feature × 2` semantic), so two entries naming the same feature
14692 // are a redundant declaration the caixa-resolver's lacre pipeline
14693 // would silently dedup at resolve time. The empty-feature arm
14694 // closes the parallel "operationally-meaningless value" axis on
14695 // the same slot. Same linear-walk + `HashSet` + first-collision
14696 // shape every peer set gate uses; same empty-first cascade every
14697 // peer per-entry shape + duplicate gate uses (the empty-feature
14698 // axis is the more-actionable defect since two `""` entries would
14699 // both report `caracteristica: ""` under a duplicate-first
14700 // ordering, with no way to distinguish the offending site).
14701
14702 fn dep_with_features(features: &[&str]) -> Dep {
14703 Dep {
14704 nome: "caixa-teia".into(),
14705 versao: "^0.1".into(),
14706 fonte: None,
14707 opcional: false,
14708 caracteristicas: features.iter().map(|s| (*s).into()).collect(),
14709 }
14710 }
14711
14712 #[test]
14713 fn validate_rejects_empty_caracteristica() {
14714 // Fail-before-pass-after pin: every pre-gate codebase accepted
14715 // `(:caracteristicas (""))` cleanly (the `Vec<String>` field
14716 // imposed no per-entry shape contract), the dep validated, and
14717 // the empty feature would have reached the future caixa-resolver
14718 // lacre pipeline as a no-op feature enable — silently dropping
14719 // the author's intent far from the source `caixa.lisp`. The new
14720 // gate surfaces the structural defect at the typed-validate
14721 // surface with a self-locating diagnostic naming the offending
14722 // dep's `:nome`.
14723 let d = dep_with_features(&[""]);
14724 assert!(
14725 matches!(d.validate().unwrap_err(), DepError::CaracteristicaEmpty { ref nome } if nome == "caixa-teia"),
14726 "expected CaracteristicaEmpty, got {:?}",
14727 d.validate(),
14728 );
14729 }
14730
14731 #[test]
14732 fn validate_rejects_duplicate_caracteristica() {
14733 // Fail-before-pass-after pin on the set-not-multiset arm: the
14734 // feature-toggle slot is set-shaped, so `(:caracteristicas
14735 // ("http" "http"))` is a redundant declaration the lacre
14736 // pipeline dedupes silently at resolve time. The diagnostic
14737 // names the offending dep + the colliding feature verbatim so
14738 // the author can grep their caixa.lisp for `:caracteristicas`
14739 // and fix it in one edit. First-collision determinism is
14740 // pinned separately below.
14741 let d = dep_with_features(&["http", "http"]);
14742 assert!(
14743 matches!(
14744 d.validate().unwrap_err(),
14745 DepError::CaracteristicaDuplicate { ref nome, ref caracteristica }
14746 if nome == "caixa-teia" && caracteristica == "http"
14747 ),
14748 "expected CaracteristicaDuplicate, got {:?}",
14749 d.validate(),
14750 );
14751 }
14752
14753 #[test]
14754 fn validate_accepts_distinct_caracteristicas() {
14755 // The canonical authoring shape — every feature distinct — must
14756 // remain a clean pass (positive control sweep). Covers the
14757 // canonical kebab-case feature names a target caixa typically
14758 // declares.
14759 dep_with_features(&["http", "json", "tls"])
14760 .validate()
14761 .unwrap();
14762 }
14763
14764 #[test]
14765 fn validate_accepts_single_caracteristica() {
14766 // Single-element list is the minimum non-empty shape; passes
14767 // the gate as the identity of the duplicate check (no second
14768 // entry to collide with).
14769 dep_with_features(&["http"]).validate().unwrap();
14770 }
14771
14772 #[test]
14773 fn validate_accepts_empty_caracteristicas_list() {
14774 // The bare-dep authoring shape (`Dep::simple` / `Dep::git`)
14775 // produces `caracteristicas: Vec::new()`; the empty list is
14776 // the gate's empty-set identity and passes vacuously. Pin
14777 // this so a future tightening that requires ≥1 feature
14778 // surfaces here as a test failure rather than a silent
14779 // contract narrowing.
14780 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14781 assert!(dep_with_features(&[]).validate().is_ok());
14782 }
14783
14784 #[test]
14785 fn validate_caracteristica_empty_fires_before_duplicate() {
14786 // Empty-first cascade: an entry with an empty feature *and*
14787 // duplicate entries surfaces the empty diagnostic first. The
14788 // empty-feature axis is the more-actionable defect since
14789 // `caracteristica: ""` is unambiguous; under duplicate-first
14790 // ordering the diagnostic could report the empty string from
14791 // either of two empty entries with no way to distinguish.
14792 // Mirrors the peer empty-before-duplicate ordering
14793 // discipline every per-entry shape + duplicate gate establishes
14794 // (`SupervisorSpec::validate`'s `EmptyChildName` arm before
14795 // `DuplicateChildCaixa`, `validate_membros`'s
14796 // `MembroCaixaEmpty` arm before `MembroDuplicate`).
14797 let d = dep_with_features(&["", "http", "http"]);
14798 assert!(matches!(
14799 d.validate().unwrap_err(),
14800 DepError::CaracteristicaEmpty { .. }
14801 ));
14802 }
14803
14804 #[test]
14805 fn validate_caracteristica_duplicate_first_collision_determinism() {
14806 // Three matching entries: the second occurrence surfaces the
14807 // diagnostic (the second is the first *collision* — the first
14808 // entry is the establishing one, not a duplicate). Mirrors
14809 // every peer first-collision posture
14810 // (`SupervisorError::DuplicateChildCaixa` reports the second
14811 // collision, `AplicacaoError::MembroDuplicate` reports the
14812 // second, `DepError::DuplicateNome` reports the second).
14813 // Pinning this so a future shortcut that flips to last-
14814 // collision (or non-deterministic) surfaces here.
14815 let d = dep_with_features(&["http", "http", "http"]);
14816 assert!(matches!(
14817 d.validate().unwrap_err(),
14818 DepError::CaracteristicaDuplicate { ref caracteristica, .. } if caracteristica == "http"
14819 ));
14820 }
14821
14822 #[test]
14823 fn validate_per_entry_shape_fires_before_caracteristicas() {
14824 // Per-entry shape precedence: a dep with a malformed `:nome`
14825 // (uppercase) AND duplicate `:caracteristicas` surfaces the
14826 // narrower `NomeInvalid` diagnostic first, not the set-gate
14827 // diagnostic. The `:nome` is the self-locating axis (every
14828 // diagnostic from the caracteristicas gate quotes the
14829 // offending dep's `:nome` to anchor the grep target —
14830 // surfacing the malformed name first keeps that anchor
14831 // valid). Same precedence shape every peer per-entry-shape
14832 // arm establishes against its peer set-gate
14833 // (`validate_deps_per_entry_validate_fires_before_duplicate_in_deps`
14834 // on the cross-entry `:nome` axis).
14835 let d = Dep {
14836 nome: "Caixa-Teia".into(), // uppercase — DNS-1123 violation
14837 versao: "^0.1".into(),
14838 fonte: None,
14839 opcional: false,
14840 caracteristicas: vec!["http".into(), "http".into()],
14841 };
14842 assert!(matches!(
14843 d.validate().unwrap_err(),
14844 DepError::NomeInvalid { .. }
14845 ));
14846 }
14847
14848 // ── per-entry :caracteristicas value-shape gate ──────────────────
14849 //
14850 // Until this gate landed `:caracteristicas` only refused the empty
14851 // string and cross-entry duplicates: a non-empty distinct but
14852 // structurally invalid feature name silently passed validate and the
14853 // failure surfaced at `cargo metadata` time as Cargo's
14854 // `restricted_names::validate_feature_name` parser rejection, far from
14855 // the source `caixa.lisp` with no field naming which `:deps` entry's
14856 // `:caracteristicas` carried the typo. The lifted predicate makes the
14857 // Cargo-feature-name-grammar intersection-floor a substrate-level
14858 // invariant at validate time. Same trajectory as the eight peer
14859 // value-shape predicates each typed surface downstream of a structured
14860 // grammar already follows.
14861
14862 #[test]
14863 fn validate_rejects_caracteristica_with_leading_plus() {
14864 // Fail-before-pass-after pin on the canonical Cargo
14865 // `+<feature>` activation-form-in-feature-name-slot footgun.
14866 // Cargo's `[dependencies.<dep>.features]` list grammar accepts
14867 // `+optional-feature` as an enablement of a previously-disabled
14868 // feature; pasting that activation form into `:caracteristicas`
14869 // (which names the feature itself) silently passed pre-gate and
14870 // failed at `cargo metadata` parse time.
14871 let d = dep_with_features(&["+http"]);
14872 let err = d.validate().unwrap_err();
14873 assert!(
14874 matches!(
14875 err,
14876 DepError::CaracteristicaInvalid { ref nome, ref caracteristica, .. }
14877 if nome == "caixa-teia" && caracteristica == "+http"
14878 ),
14879 "expected CaracteristicaInvalid, got {err:?}"
14880 );
14881 }
14882
14883 #[test]
14884 fn validate_rejects_caracteristica_with_leading_hyphen() {
14885 // Fail-before-pass-after pin on the leading-hyphen footgun. `-`
14886 // is a legitimate continuation character (kebab-case feature
14887 // names like `runtime-tokio` pass) but Cargo rejects it at the
14888 // start; the structural defect — and its CLI-argument-injection
14889 // adjacency at any downstream Cargo subprocess invocation — is
14890 // closed at validate time, not at `cargo metadata` time.
14891 let d = dep_with_features(&["-json"]);
14892 let err = d.validate().unwrap_err();
14893 assert!(
14894 matches!(
14895 err,
14896 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "-json"
14897 ),
14898 "expected CaracteristicaInvalid, got {err:?}"
14899 );
14900 }
14901
14902 #[test]
14903 fn validate_rejects_caracteristica_with_leading_dot() {
14904 // Fail-before-pass-after pin on the leading-dot footgun. `.` is
14905 // a legitimate continuation character (version-suffix shapes
14906 // like `feat.v2` pass) but the leading-dot form is the
14907 // canonical dotted-version-suffix-as-feature-name confusion.
14908 let d = dep_with_features(&[".feat"]);
14909 let err = d.validate().unwrap_err();
14910 assert!(matches!(
14911 err,
14912 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == ".feat"
14913 ));
14914 }
14915
14916 #[test]
14917 fn validate_rejects_caracteristica_with_whitespace() {
14918 // Fail-before-pass-after pin on the embedded-whitespace footgun:
14919 // a feature name with a space inside is structurally a multi-
14920 // token blob (the canonical paste-from-doc footgun, or an
14921 // accidental `"http server"` where the author meant
14922 // `"http-server"`).
14923 let d = dep_with_features(&["http feature"]);
14924 let err = d.validate().unwrap_err();
14925 assert!(matches!(
14926 err,
14927 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http feature"
14928 ));
14929 }
14930
14931 #[test]
14932 fn validate_rejects_caracteristica_with_comma() {
14933 // Fail-before-pass-after pin on the embedded-comma footgun:
14934 // the list-separator-belongs-to-the-list-grammar
14935 // miscomprehension where the author writes
14936 // `:caracteristicas ("http,json")` intending two features but
14937 // the `Vec<String>` field consumes the bare token as one entry.
14938 let d = dep_with_features(&["http,json"]);
14939 let err = d.validate().unwrap_err();
14940 assert!(matches!(
14941 err,
14942 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http,json"
14943 ));
14944 }
14945
14946 #[test]
14947 fn validate_rejects_caracteristica_with_slash() {
14948 // Fail-before-pass-after pin on the embedded-slash footgun:
14949 // Cargo's `dep/feat` namespaced-dep syntax applies inside
14950 // `[dependencies.<dep>.features]` list entries that already
14951 // name the parent dep (so the syntax says "enable feature
14952 // `feat` on a transitive dep `dep`"); `:caracteristicas` is
14953 // per-dep already (a sibling slot on the `Dep` itself), so the
14954 // segment separator within an entry must be `-`, `_`, `+`,
14955 // or `.`. The diagnostic remediation points at the canonical
14956 // Cargo namespaced-dep discipline.
14957 let d = dep_with_features(&["http/json"]);
14958 let err = d.validate().unwrap_err();
14959 assert!(matches!(
14960 err,
14961 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http/json"
14962 ));
14963 }
14964
14965 #[test]
14966 fn validate_rejects_caracteristica_with_non_ascii() {
14967 // Fail-before-pass-after pin on the un-percent-encoded non-ASCII
14968 // byte footgun: NFC-vs-NFD normalization across filesystems
14969 // silently rewrites the feature-key, breaking the lacre's
14970 // content-addressing invariant. Pinned at a canonical
14971 // smart-quote-paste shape (`café`) where the raw `é` byte is the
14972 // documented APFS round-trip break.
14973 let d = dep_with_features(&["caf\u{e9}"]);
14974 let err = d.validate().unwrap_err();
14975 assert!(matches!(
14976 err,
14977 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "caf\u{e9}"
14978 ));
14979 }
14980
14981 #[test]
14982 fn validate_rejects_caracteristica_with_control_character() {
14983 // Fail-before-pass-after pin on the embedded-control-character
14984 // footgun: a CR/LF or any 0x00..0x1F / 0x7F byte landing in a
14985 // feature name is the canonical paste-from-multiline-doc
14986 // footgun the predicate's reason wording specifically calls out.
14987 let d = dep_with_features(&["http\njson"]);
14988 let err = d.validate().unwrap_err();
14989 assert!(matches!(err, DepError::CaracteristicaInvalid { .. }));
14990 }
14991
14992 #[test]
14993 fn validate_accepts_canonical_caracteristicas_shapes() {
14994 // Positive control sweep: every canonical Cargo feature name
14995 // shape the pleme-io ecosystem uses must still pass. Mirrors
14996 // the substrate-side `cargo_feature_name_accepts_canonical_forms`
14997 // sweep — drift between either landing site and the predicate's
14998 // accepted set is a build error visible at this pair of tests,
14999 // not a per-renderer "this passed validate but failed at
15000 // cargo metadata time" surprise on the next acceptance.
15001 for s in [
15002 "http",
15003 "json",
15004 "derive",
15005 "serde_json",
15006 "runtime-tokio",
15007 "tokio.full",
15008 "v0.1",
15009 "http+json",
15010 "_internal",
15011 "__private",
15012 "default",
15013 "rt-multi-thread",
15014 "feat.v2",
15015 ] {
15016 let d = dep_with_features(&[s]);
15017 d.validate().unwrap_or_else(|e| {
15018 panic!("canonical Cargo feature name {s:?} must pass validate: {e:?}")
15019 });
15020 }
15021 }
15022
15023 #[test]
15024 fn validate_caracteristica_empty_fires_before_invalid() {
15025 // Cascade precedence pin: an entry list with both an empty
15026 // feature AND an invalid-shape feature surfaces the
15027 // `CaracteristicaEmpty` arm first (the empty value carries no
15028 // self-locating data — `caracteristica: ""` is the diagnostic
15029 // with no way to anchor a grep target — so closing the empty
15030 // axis first preserves the per-entry-shape diagnostic's
15031 // self-locating discipline). Same empty-first cascade every
15032 // peer per-entry shape gate establishes
15033 // (`SupervisorSpec::validate`'s `EmptyChildName` before
15034 // `ChildCaixaInvalid`, `validate_membros`'s `MembroCaixaEmpty`
15035 // before `MembroCaixaInvalid`).
15036 let d = dep_with_features(&["", "+http"]);
15037 assert!(matches!(
15038 d.validate().unwrap_err(),
15039 DepError::CaracteristicaEmpty { .. }
15040 ));
15041 }
15042
15043 #[test]
15044 fn validate_caracteristica_invalid_fires_before_duplicate() {
15045 // Per-entry-shape precedence pin: an entry list with the same
15046 // invalid feature shape declared twice surfaces the
15047 // `CaracteristicaInvalid` diagnostic on the first entry, not
15048 // the `CaracteristicaDuplicate` on the second collision. The
15049 // per-entry shape gate fires before the cross-entry set gate
15050 // — same precedence shape every peer two-arm-plus-set gate
15051 // establishes (`SupervisorSpec::validate`'s
15052 // `ChildCaixaInvalid` before `DuplicateChildCaixa`,
15053 // `validate_membros`'s `MembroCaixaInvalid` before
15054 // `MembroDuplicate`, `Dep::validate`'s `NomeInvalid` before
15055 // cross-list `DuplicateNome`).
15056 let d = dep_with_features(&["+http", "+http"]);
15057 assert!(matches!(
15058 d.validate().unwrap_err(),
15059 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "+http"
15060 ));
15061 }
15062
15063 #[test]
15064 fn validate_rejects_caracteristica_at_65_byte_boundary() {
15065 // Boundary pin on the 64-byte cap — both the boundary-accepting
15066 // case and the boundary-exceeding case in one place, so a
15067 // future cap shift surfaces both arms simultaneously, mirroring
15068 // the peer `cargo_feature_name_rejects_at_65_byte_boundary`
15069 // predicate-level pin at the dep-axis landing site.
15070 let max_ok = "a".repeat(64);
15071 dep_with_features(&[&max_ok])
15072 .validate()
15073 .unwrap_or_else(|e| panic!("64-byte feature name must pass: {e:?}"));
15074 let too_long = "a".repeat(65);
15075 let d = dep_with_features(&[&too_long]);
15076 assert!(matches!(
15077 d.validate().unwrap_err(),
15078 DepError::CaracteristicaInvalid { .. }
15079 ));
15080 }
15081
15082 // ── self-dep cross-slot gate ─────────────────────────────────────
15083
15084 #[test]
15085 fn validate_no_self_dep_rejects_self_in_deps() {
15086 // A caixa whose `:deps` lists its own `:nome` is a one-node
15087 // cycle in the lacre closure's dep-graph traversal — rejected,
15088 // naming the parent and the offending list tag.
15089 let deps = vec![
15090 Dep::simple("caixa-teia", "^0.1"),
15091 Dep::simple("orquestra", "^0.1"),
15092 ];
15093 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15094 assert!(
15095 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
15096 "got {err:?}"
15097 );
15098 }
15099
15100 #[test]
15101 fn validate_no_self_dep_rejects_self_in_deps_dev() {
15102 // Same gate on the `:deps-dev` axis — neither dep list is a
15103 // second-class citizen on the self-edge invariant.
15104 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15105 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15106 assert!(
15107 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
15108 "got {err:?}"
15109 );
15110 }
15111
15112 #[test]
15113 fn validate_no_self_dep_deps_fires_before_deps_dev() {
15114 // Walk order pin: a caixa that self-references on both lists
15115 // surfaces the `:deps` arm first — the load-bearing axis the
15116 // lacre closure resolves at every build. Mirrors the canonical
15117 // [`Caixa::validate_deps`] cascade (`:deps` → `:deps-dev`).
15118 let deps = vec![Dep::simple("orquestra", "^0.1")];
15119 let deps_dev = vec![Dep::simple("orquestra", "^0.2")];
15120 let err = validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap_err();
15121 assert!(
15122 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
15123 "got {err:?}"
15124 );
15125 }
15126
15127 #[test]
15128 fn validate_no_self_dep_accepts_distinct_names() {
15129 // Positive control: every dep names a distinct caixa. The
15130 // canonical author surface — peer of
15131 // [`validate_no_self_supervision_accepts_distinct_children`].
15132 let deps = vec![
15133 Dep::simple("caixa-teia", "^0.1"),
15134 Dep::simple("caixa-arch", "^0.1"),
15135 ];
15136 let deps_dev = vec![Dep::simple("caixa-test", "^0.1")];
15137 validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap();
15138 }
15139
15140 #[test]
15141 fn validate_no_self_dep_empty_lists_pass() {
15142 // A caixa with no declared deps has nothing to self-reference —
15143 // the gate is vacuously satisfied. Peer of
15144 // [`validate_no_self_supervision_empty_children_is_ok`].
15145 validate_no_self_dep(&[], &[], "orquestra").unwrap();
15146 }
15147
15148 #[test]
15149 fn validate_no_self_dep_diagnostic_carries_offending_list_and_nome() {
15150 // Diagnostic-shape pin (peer with
15151 // [`validate_no_self_supervision`]'s diagnostic): the error's
15152 // Display surfaces both the offending list tag and the
15153 // parent's `:nome` verbatim, so the author can grep their
15154 // caixa.lisp for the offending block in one edit. Names
15155 // `:bibliotecas` / `:exe` / `:servicos` as the corrective
15156 // surface — every legitimate "I want to use code from this
15157 // caixa" intent routes through one of those three slots.
15158 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15159 let rendered = validate_no_self_dep(&[], &deps_dev, "orquestra")
15160 .unwrap_err()
15161 .to_string();
15162 assert!(
15163 rendered.contains(crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
15164 "diagnostic must name the offending list tag: {rendered}",
15165 );
15166 assert!(
15167 rendered.contains("orquestra"),
15168 "diagnostic must quote the parent caixa name: {rendered}",
15169 );
15170 assert!(
15171 rendered.contains(":bibliotecas"),
15172 "diagnostic must point at the corrective code-surface slot: {rendered}",
15173 );
15174 }
15175
15176 #[test]
15177 fn validate_no_self_dep_accepts_coincidental_substring_match() {
15178 // Identity is exact-string equality, not substring — a dep
15179 // named `"orquestra-helper"` is a distinct caixa even when the
15180 // parent is `"orquestra"`. Pin the exact-match discipline so a
15181 // future relaxation that uses `contains` surfaces here, peer
15182 // with the supervision-tree and Aplicacao-membership gates
15183 // which all use exact-string equality on the typed identity.
15184 let deps = vec![Dep::simple("orquestra-helper", "^0.1")];
15185 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15186 }
15187
15188 // ── drift-detection: DEP_AUTHOR_KEY_{DEPS,DEPS_DEV} pin ─────────────
15189
15190 #[test]
15191 fn dep_author_key_consts_pin_canonical_kebab_case_labels() {
15192 // Scalar-value pin: the two author-facing kebab-case labels the
15193 // `(defcaixa … :deps ((…)) :deps-dev ((…)))` surface admits on
15194 // the two-list dep-graph slot axis, one arm per typed slot.
15195 // Mirrors the peer scalar-value pin the sibling
15196 // [`crate::M2_AUTHOR_KEY_LIMITS`] /
15197 // [`crate::M2_AUTHOR_KEY_BEHAVIOR`] /
15198 // [`crate::M2_AUTHOR_KEY_UPGRADE_FROM`] (f49c8b0) M2 top-level
15199 // author-labels, [`crate::M3_AUTHOR_KEY_MEMBROS`] etc.
15200 // (882f498) M3 top-level author-labels, and
15201 // [`crate::SUPERVISOR_AUTHOR_KEY_ESTRATEGIA`] etc. (be40492)
15202 // Supervisor top-level author-labels carry, so every kind-scoped
15203 // typed-slot-family axis routes through one canonical per-arm
15204 // declaration.
15205 //
15206 // A future rebrand (`:deps` → `:dependencies` matching Cargo's
15207 // verbatim key, `:deps-dev` → `:dev-dependencies` matching the
15208 // same, `:deps` / `:deps-dev` → `:runtime-deps` / `:dev-deps`
15209 // for symmetry) lands as an edit to exactly one const, and
15210 // every consumer that reaches for the label picks it up at
15211 // build time rather than at runtime as a downstream mismatch on
15212 // a `DepError::DuplicateNome { list: … }` diagnostic far from
15213 // the rename's commit.
15214 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS, ":deps");
15215 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS_DEV, ":deps-dev");
15216 }
15217
15218 #[test]
15219 fn dep_author_key_consts_are_pairwise_distinct() {
15220 // Distinct-labels pin: the two `:deps` / `:deps-dev` labels
15221 // must not collapse onto one byte-string. A future copy-paste
15222 // slip that renamed both consts to the same value (or a rebrand
15223 // that dropped the `-dev` suffix from one but not the other)
15224 // would leave every `DepError::DuplicateNome { list: … }`
15225 // diagnostic naming an unattributable list — the linter would
15226 // route the author to the wrong caixa.lisp block, or the
15227 // cross-list precedence gate
15228 // (`validate_deps_duplicate_in_deps_fires_before_duplicate_in_deps_dev`)
15229 // would surface a `:deps`-tagged diagnostic on a `:deps-dev`
15230 // duplicate. Peer of the sibling
15231 // `m2_author_key_consts_are_pairwise_distinct`-shape gates the
15232 // other top-level kind-scoped slot-family axes carry
15233 // (implicitly held by their different byte-values today).
15234 assert_ne!(
15235 crate::render::DEP_AUTHOR_KEY_DEPS,
15236 crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15237 "DEP_AUTHOR_KEY_{{DEPS,DEPS_DEV}} consts must be pairwise-distinct \
15238 so a `DepError::DuplicateNome {{ list: … }}` diagnostic \
15239 self-locates the offending block in the author's caixa.lisp",
15240 );
15241 }
15242
15243 #[test]
15244 fn validate_no_self_dep_routes_through_lifted_dep_author_key_consts() {
15245 // Production-through-const pin: the two per-arm list tags
15246 // [`validate_no_self_dep`] threads onto the `list:` field of a
15247 // returned [`DepError::DepIsSelf`] route through the lifted
15248 // [`crate::DEP_AUTHOR_KEY_DEPS`] /
15249 // [`crate::DEP_AUTHOR_KEY_DEPS_DEV`] consts. A future drift at
15250 // the walker (a rename that reaches one arm but not the const,
15251 // or vice versa) surfaces here at build time rather than at
15252 // runtime as a `feira lint` diagnostic naming the wrong list
15253 // tag. Mirror of the peer
15254 // [`crate::Caixa::declared_servico_slots`] production tagger
15255 // pin (f49c8b0) on the sibling M2 top-level slot axis, extended
15256 // onto the two-list dep-graph gate.
15257 let deps = vec![Dep::simple("orquestra", "^0.1")];
15258 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15259 let DepError::DepIsSelf { list, .. } = err else {
15260 panic!("expected DepIsSelf from :deps walk");
15261 };
15262 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS);
15263
15264 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15265 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15266 let DepError::DepIsSelf { list, .. } = err else {
15267 panic!("expected DepIsSelf from :deps-dev walk");
15268 };
15269 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS_DEV);
15270 }
15271
15272 // ── Dep::nome accessor pins ───────────────────────────────────────
15273 //
15274 // Three coherence pins on the lifted `Dep::nome` accessor: byte-equal
15275 // projection over the plain-shorthand / explicit-git / explicit-path
15276 // fixture triad the [`Dep`] docstring lists (so the accessor's
15277 // accept-set is exercised across every author-surface `:fonte`
15278 // shape); by-borrow pointer identity so the projection stays
15279 // zero-copy at every consumer site; and validate-composition through
15280 // the [`validate_no_self_dep`] cross-slot gate reading its
15281 // parent-name equality check through the lifted accessor rather than
15282 // the raw field.
15283
15284 #[test]
15285 fn dep_nome_returns_declared_nome_across_fonte_shapes() {
15286 // Plain-shorthand form (`:fonte None`).
15287 assert_eq!(Dep::simple("caixa-teia", "^0.1").nome(), "caixa-teia");
15288 // Explicit git-source form with a tag pin — same accessor path.
15289 assert_eq!(
15290 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").nome(),
15291 "caixa-teia",
15292 );
15293 // Explicit path-source form.
15294 assert_eq!(
15295 Dep {
15296 nome: "caixa-teia".to_string(),
15297 versao: "0.1.0".to_string(),
15298 fonte: Some(DepSource::Path {
15299 caminho: "../caixa-teia".to_string(),
15300 }),
15301 opcional: false,
15302 caracteristicas: Vec::new(),
15303 }
15304 .nome(),
15305 "caixa-teia",
15306 );
15307 // The empty-string `:nome` sentinel (which [`Dep::validate`]
15308 // refuses through the [`DepError::NomeEmpty`] arm) still round-
15309 // trips as an empty `&str` through the accessor — the accessor is
15310 // a projection, not a gate; the gate is [`Dep::validate`].
15311 assert_eq!(Dep::simple("", "^0.1").nome(), "");
15312 }
15313
15314 #[test]
15315 fn dep_nome_is_by_borrow_pointer_identity() {
15316 // Zero-copy pin: the accessor must borrow into the field's own
15317 // storage, not clone. If a future rewrite regresses to
15318 // `self.nome.clone().leak()` or an owned-buffer shape, the two
15319 // pointers diverge and this pin fails at build time.
15320 let d = Dep::simple("caixa-teia", "^0.1");
15321 assert!(std::ptr::eq(d.nome().as_ptr(), d.nome.as_ptr()));
15322 }
15323
15324 // ── Dep::versao_requirement accessor pins ─────────────────────────
15325 //
15326 // Three coherence pins on the lifted `Dep::versao_requirement`
15327 // accessor: byte-equal projection over the plain-shorthand /
15328 // explicit-git / explicit-path fixture triad the [`Dep`] docstring
15329 // lists plus the empty-sentinel that round-trips as `""` (the accessor
15330 // is a projection, not a gate; the gate is [`Dep::validate`]); by-
15331 // borrow pointer identity so the projection stays zero-copy at every
15332 // consumer site; and validate-composition through the
15333 // [`crate::render::require_valid_versao_requirement`] cascade reading
15334 // its requirement-shape check through the lifted accessor rather than
15335 // the raw field.
15336 #[test]
15337 fn dep_versao_requirement_returns_declared_versao_across_fonte_shapes() {
15338 // Plain-shorthand form (`:fonte None`).
15339 assert_eq!(
15340 Dep::simple("caixa-teia", "^0.1").versao_requirement(),
15341 "^0.1",
15342 );
15343 // Explicit git-source form with a tag pin — same accessor path.
15344 assert_eq!(
15345 Dep::git(
15346 "caixa-teia",
15347 "~0.1.2",
15348 "github:pleme-io/caixa-teia",
15349 "v0.1.0"
15350 )
15351 .versao_requirement(),
15352 "~0.1.2",
15353 );
15354 // Explicit path-source form.
15355 assert_eq!(
15356 Dep {
15357 nome: "caixa-teia".to_string(),
15358 versao: "0.1.0".to_string(),
15359 fonte: Some(DepSource::Path {
15360 caminho: "../caixa-teia".to_string(),
15361 }),
15362 opcional: false,
15363 caracteristicas: Vec::new(),
15364 }
15365 .versao_requirement(),
15366 "0.1.0",
15367 );
15368 // The wildcard requirement (`"*"`) — the shorthand
15369 // `parse_requirement` accepts as `VersionReq::STAR` — round-trips
15370 // verbatim through the accessor as `"*"`, same byte-shape the
15371 // author wrote.
15372 assert_eq!(Dep::simple("caixa-teia", "*").versao_requirement(), "*");
15373 // The empty-string `:versao` sentinel (which [`Dep::validate`]
15374 // refuses through the [`DepError::VersaoEmpty`] arm) still round-
15375 // trips as an empty `&str` through the accessor — the accessor is
15376 // a projection, not a gate; the gate is [`Dep::validate`]. Peer
15377 // of the sibling [`Dep::nome`] empty-sentinel round-trip pin.
15378 assert_eq!(Dep::simple("caixa-teia", "").versao_requirement(), "");
15379 }
15380
15381 #[test]
15382 fn dep_versao_requirement_is_by_borrow_pointer_identity() {
15383 // Zero-copy pin: the accessor must borrow into the field's own
15384 // storage, not clone. If a future rewrite regresses to
15385 // `self.versao.clone().leak()` or an owned-buffer shape, the two
15386 // pointers diverge and this pin fails at build time. Peer of the
15387 // sibling [`Dep::nome`] pointer-identity pin — same by-borrow
15388 // discipline extended onto the requirement-carrying axis.
15389 let d = Dep::simple("caixa-teia", "^0.1");
15390 assert!(std::ptr::eq(
15391 d.versao_requirement().as_ptr(),
15392 d.versao.as_ptr(),
15393 ));
15394 }
15395
15396 #[test]
15397 fn dep_validate_reads_requirement_through_accessor() {
15398 // Composition pin: the [`Dep::validate`]
15399 // [`crate::render::require_valid_versao_requirement`] cascade
15400 // consumes the requirement string through the lifted accessor —
15401 // both the requirement-gate input and the
15402 // [`DepError::VersaoInvalid`] error-body carrier route through
15403 // `self.versao_requirement()`. A valid requirement passes
15404 // (positive control); a malformed-but-non-empty requirement fails
15405 // and the diagnostic quotes the offending byte-string verbatim
15406 // (same shape the accessor projects), so a future regression that
15407 // detoured the requirement carrier through a different byte-
15408 // string (say the parsed `VersionReq`'s `Display`, or a
15409 // normalized rewrite) would surface here at build time. The
15410 // empty-`:versao` arm fires the [`DepError::VersaoEmpty`] variant
15411 // ahead of the parse arm, pinning the empty-first cascade the
15412 // accessor's `""` sentinel round-trip acknowledges.
15413 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15414 let err = Dep::simple("caixa-teia", "v0.1").validate().unwrap_err();
15415 assert!(
15416 matches!(
15417 &err,
15418 DepError::VersaoInvalid {
15419 nome,
15420 versao,
15421 ..
15422 } if nome == "caixa-teia" && versao == "v0.1",
15423 ),
15424 "expected VersaoInvalid quoting the accessor-projected requirement, got {err:?}",
15425 );
15426 let err = Dep::simple("caixa-teia", "").validate().unwrap_err();
15427 assert!(
15428 matches!(
15429 &err,
15430 DepError::VersaoEmpty { nome } if nome == "caixa-teia",
15431 ),
15432 "expected VersaoEmpty from the empty-first arm, got {err:?}",
15433 );
15434 }
15435
15436 // ── Dep::fonte accessor pins ──────────────────────────────────────
15437 //
15438 // Three coherence pins on the lifted `Dep::fonte` accessor: byte-
15439 // equal projection over the plain-shorthand (`:fonte None`) /
15440 // explicit-git-tag / explicit-path fixture triad the [`Dep`]
15441 // docstring lists (so the accessor's accept-set is exercised across
15442 // every author-surface `:fonte` shape and both `DepSource` variants);
15443 // pointer identity so the borrowed reference points into the field's
15444 // own `Option<DepSource>` storage (not a cloned side-buffer); and
15445 // validate-composition through the [`Dep::validate`] gate reading
15446 // its per-`:fonte` [`DepSource::validate`] delegation through the
15447 // lifted accessor rather than the raw `if let Some(ref fonte) =
15448 // self.fonte` bracket.
15449
15450 #[test]
15451 fn dep_fonte_returns_declared_source_across_shapes() {
15452 // Plain-shorthand form — `:fonte` omitted, accessor projects
15453 // the `None` partition the resolver-side default-fill treats
15454 // as "resolve through `github:<default-org>/<nome>`".
15455 assert!(Dep::simple("caixa-teia", "^0.1").fonte().is_none());
15456 // Explicit git-source form with a tag pin — same accessor path.
15457 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15458 match git.fonte() {
15459 Some(DepSource::Git {
15460 repo,
15461 tag,
15462 rev,
15463 branch,
15464 }) => {
15465 assert_eq!(repo, "github:pleme-io/caixa-teia");
15466 assert_eq!(tag.as_deref(), Some("v0.1.0"));
15467 assert!(rev.is_none());
15468 assert!(branch.is_none());
15469 }
15470 other => panic!("expected explicit git :fonte, got {other:?}"),
15471 }
15472 // Explicit path-source form — the dev-only local-filesystem
15473 // arm the [`Dep`] docstring's third fixture carries.
15474 let path = Dep {
15475 nome: "caixa-teia".to_string(),
15476 versao: "0.1.0".to_string(),
15477 fonte: Some(DepSource::Path {
15478 caminho: "../caixa-teia".to_string(),
15479 }),
15480 opcional: false,
15481 caracteristicas: Vec::new(),
15482 };
15483 match path.fonte() {
15484 Some(DepSource::Path { caminho }) => {
15485 assert_eq!(caminho, "../caixa-teia");
15486 }
15487 other => panic!("expected explicit path :fonte, got {other:?}"),
15488 }
15489 }
15490
15491 #[test]
15492 fn dep_fonte_is_by_borrow_pointer_identity() {
15493 // Zero-copy pin: the accessor must borrow into the field's own
15494 // `Option<DepSource>` storage, not clone into a side buffer. If
15495 // a future rewrite regresses to `self.fonte.clone()` or an
15496 // owned-buffer shape, the two pointers diverge and this pin
15497 // fails at build time. Peer of the sibling per-`Dep` [`Dep::nome`]
15498 // (eba2cde) / [`Dep::versao_requirement`] (05529b1) pointer-
15499 // identity pins — same by-borrow discipline extended onto the
15500 // outer-`Dep` `Option<&Composite>` composite-reference axis.
15501 let d = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15502 let accessed = d.fonte().expect("git :fonte present") as *const DepSource;
15503 let raw = d.fonte.as_ref().expect("git :fonte present") as *const DepSource;
15504 assert!(std::ptr::eq(accessed, raw));
15505 }
15506
15507 #[test]
15508 fn dep_validate_reads_fonte_through_accessor() {
15509 // Composition pin: [`Dep::validate`]'s per-`:fonte`
15510 // [`DepSource::validate`] delegation consumes the typed slot
15511 // through the lifted accessor — an author-omitted `:fonte`
15512 // still passes the outer gate (positive control), an explicit
15513 // well-formed git source with exactly one pin passes, and a
15514 // malformed git source (empty `:repo`) surfaces the
15515 // [`DepError::FonteRepoEmpty`] variant quoting the offending
15516 // dep's `:nome` verbatim so a future regression that detoured
15517 // the `:fonte` delegation through a different path (say a
15518 // per-scope override projector) would surface here at build
15519 // time. Peer of the sibling
15520 // `dep_validate_reads_requirement_through_accessor` composition
15521 // pin on the `:versao` axis.
15522 // Positive control 1: no `:fonte` at all.
15523 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15524 // Positive control 2: well-formed git source.
15525 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15526 .validate()
15527 .unwrap();
15528 // Negative control: empty `:repo` — the accessor still returns
15529 // `Some(&DepSource::Git { repo: "", … })` and the delegated
15530 // `DepSource::validate` gate raises the typed carrier.
15531 let bad = Dep {
15532 nome: "caixa-teia".to_string(),
15533 versao: "^0.1".to_string(),
15534 fonte: Some(DepSource::Git {
15535 repo: String::new(),
15536 tag: Some("v0.1.0".to_string()),
15537 rev: None,
15538 branch: None,
15539 }),
15540 opcional: false,
15541 caracteristicas: Vec::new(),
15542 };
15543 let err = bad.validate().unwrap_err();
15544 assert!(
15545 matches!(
15546 &err,
15547 DepError::FonteRepoEmpty { nome } if nome == "caixa-teia",
15548 ),
15549 "expected FonteRepoEmpty from the accessor-routed :fonte gate, got {err:?}",
15550 );
15551 }
15552
15553 #[test]
15554 fn validate_no_self_dep_reads_parent_equality_through_accessor() {
15555 // Composition pin: the cross-slot [`validate_no_self_dep`] gate
15556 // rejects a `:deps` entry whose `:nome` equals the parent caixa's
15557 // own `:nome` through the lifted accessor rather than the raw
15558 // field. Fails-before-passes-after: with the accessor lifted the
15559 // gate reads its equality check through `dep.nome() ==
15560 // parent_nome` on both the `:deps` and `:deps-dev` traversals, so
15561 // the diagnostic still names the offending list tag as expected.
15562 let deps = vec![Dep::simple("orquestra", "^0.1")];
15563 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15564 assert!(matches!(
15565 err,
15566 DepError::DepIsSelf {
15567 ref nome,
15568 list,
15569 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS,
15570 ));
15571 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15572 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15573 assert!(matches!(
15574 err,
15575 DepError::DepIsSelf {
15576 ref nome,
15577 list,
15578 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15579 ));
15580 // A non-matching `:nome` passes through the accessor gate.
15581 let deps = vec![Dep::simple("caixa-teia", "^0.1")];
15582 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15583 }
15584
15585 // ── Dep::caracteristicas accessor pins ────────────────────────────
15586 //
15587 // Three coherence pins on the lifted `Dep::caracteristicas` accessor:
15588 // byte-equal projection over the default-empty / single-entry /
15589 // multi-entry fixture triad (so the accessor's accept-set is
15590 // exercised across every author-surface `:caracteristicas` shape,
15591 // matching the peer sibling family's fixture-triad discipline); by-
15592 // borrow pointer identity so the projection stays zero-copy at every
15593 // consumer site; and validate-composition through the
15594 // [`Dep::validate_caracteristicas`] gate reading its per-entry
15595 // linear walk through the lifted accessor rather than the raw
15596 // `for c in &self.caracteristicas` bracket.
15597
15598 #[test]
15599 fn dep_caracteristicas_returns_declared_features_across_shapes() {
15600 // Default-empty form — the [`Dep::simple`] constructor's
15601 // `Vec::new()` fill; the accessor projects the empty slice
15602 // verbatim (no `None` collapse).
15603 assert!(
15604 Dep::simple("caixa-teia", "^0.1")
15605 .caracteristicas()
15606 .is_empty(),
15607 );
15608 // Single-entry form — the canonical Cargo-shaped one-feature
15609 // enable ([`crate::render::is_cargo_feature_name`] accepts the
15610 // `"http"` byte-string as a valid feature name).
15611 let one = Dep {
15612 nome: "caixa-teia".to_string(),
15613 versao: "^0.1".to_string(),
15614 fonte: None,
15615 opcional: false,
15616 caracteristicas: vec!["http".to_string()],
15617 };
15618 assert_eq!(one.caracteristicas(), &["http".to_string()]);
15619 // Multi-entry form — the substrate's set-shaped multi-feature
15620 // enable, exercising the accessor over a length-two slice with
15621 // no duplicate collapse.
15622 let two = Dep {
15623 nome: "caixa-teia".to_string(),
15624 versao: "^0.1".to_string(),
15625 fonte: None,
15626 opcional: false,
15627 caracteristicas: vec!["http".to_string(), "json".to_string()],
15628 };
15629 assert_eq!(
15630 two.caracteristicas(),
15631 &["http".to_string(), "json".to_string()],
15632 );
15633 }
15634
15635 #[test]
15636 fn dep_caracteristicas_is_by_borrow_pointer_identity() {
15637 // Zero-copy pin: the accessor must borrow into the field's own
15638 // `Vec<String>` storage, not clone into a side buffer. If a
15639 // future rewrite regresses to `self.caracteristicas.clone()` or
15640 // an owned-buffer shape, the two pointers diverge and this pin
15641 // fails at build time. Peer of the sibling per-`Dep`
15642 // [`Dep::nome`] (eba2cde) / [`Dep::versao_requirement`] (05529b1)
15643 // / [`Dep::fonte`] (d65d1bf) pointer-identity pins — same by-
15644 // borrow discipline extended onto the outer-`Dep` `&[String]`
15645 // slice-projection axis.
15646 let d = Dep {
15647 nome: "caixa-teia".to_string(),
15648 versao: "^0.1".to_string(),
15649 fonte: None,
15650 opcional: false,
15651 caracteristicas: vec!["http".to_string(), "json".to_string()],
15652 };
15653 assert!(std::ptr::eq(
15654 d.caracteristicas().as_ptr(),
15655 d.caracteristicas.as_ptr(),
15656 ));
15657 }
15658
15659 #[test]
15660 fn dep_validate_reads_caracteristicas_through_accessor() {
15661 // Composition pin: [`Dep::validate_caracteristicas`]'s per-entry
15662 // linear walk consumes the feature-toggle list through the
15663 // lifted accessor — a well-formed `:caracteristicas` set passes
15664 // (positive control), an empty-string entry surfaces the
15665 // [`DepError::CaracteristicaEmpty`] variant quoting the offending
15666 // `Dep::nome`, and a within-list duplicate surfaces the
15667 // [`DepError::CaracteristicaDuplicate`] variant so a future
15668 // regression that detoured the walk through a different byte-
15669 // string list (say a per-scope override projector) would surface
15670 // here at build time. Peer of the sibling
15671 // `dep_validate_reads_fonte_through_accessor` /
15672 // `dep_validate_reads_requirement_through_accessor` composition
15673 // pins on the `:fonte` / `:versao` axes.
15674 // Positive control: two distinct well-formed feature names pass.
15675 Dep {
15676 nome: "caixa-teia".to_string(),
15677 versao: "^0.1".to_string(),
15678 fonte: None,
15679 opcional: false,
15680 caracteristicas: vec!["http".to_string(), "json".to_string()],
15681 }
15682 .validate()
15683 .unwrap();
15684 // Negative control 1: empty-string feature-name entry — the
15685 // accessor still returns `&[""]` and the walk raises the typed
15686 // empty-first carrier.
15687 let err = Dep {
15688 nome: "caixa-teia".to_string(),
15689 versao: "^0.1".to_string(),
15690 fonte: None,
15691 opcional: false,
15692 caracteristicas: vec![String::new()],
15693 }
15694 .validate()
15695 .unwrap_err();
15696 assert!(
15697 matches!(
15698 &err,
15699 DepError::CaracteristicaEmpty { nome } if nome == "caixa-teia",
15700 ),
15701 "expected CaracteristicaEmpty from the accessor-routed walk, got {err:?}",
15702 );
15703 // Negative control 2: within-list duplicate — the accessor's
15704 // slice view carries both entries, and the walk's dedup arm
15705 // raises the typed duplicate carrier quoting the offending
15706 // feature name verbatim.
15707 let err = Dep {
15708 nome: "caixa-teia".to_string(),
15709 versao: "^0.1".to_string(),
15710 fonte: None,
15711 opcional: false,
15712 caracteristicas: vec!["http".to_string(), "http".to_string()],
15713 }
15714 .validate()
15715 .unwrap_err();
15716 assert!(
15717 matches!(
15718 &err,
15719 DepError::CaracteristicaDuplicate {
15720 nome,
15721 caracteristica,
15722 } if nome == "caixa-teia" && caracteristica == "http",
15723 ),
15724 "expected CaracteristicaDuplicate from the accessor-routed dedup, got {err:?}",
15725 );
15726 }
15727
15728 // ── Dep::opcional accessor pins ───────────────────────────────────
15729 //
15730 // Two coherence pins on the lifted `Dep::opcional` accessor: byte-
15731 // equal projection over the default-`false` / explicit-`true`
15732 // fixture pair across the plain-shorthand (`:fonte None`) / explicit-
15733 // git-tag / explicit-path fixture triad the [`Dep`] docstring lists,
15734 // exercising the accessor's accept-set over every author-surface
15735 // `:fonte` shape × every author-surface `:opcional` shape; and by-
15736 // `Copy` idempotency so the projection stays value-return (no
15737 // silent detour to a fresh `&bool` borrow that would introduce a
15738 // lifetime on the return type the plain-`Copy`-scalar axis's `bool`
15739 // shape elides). No composition pin — `:opcional` does not
15740 // participate in [`Dep::validate`] (an opcional dep with any bool
15741 // value is validate-accepted; the missing-source arm is a resolver-
15742 // side runtime dispatch, not a build-time refusal), so the axis
15743 // reduces to the value-shape + `Copy` pin pair the peer
15744 // [`crate::Caixa::max_restarts`] / [`crate::Caixa::estrategia`]
15745 // outer-`Option<Copy>` accessor pins already carry.
15746
15747 #[test]
15748 fn dep_opcional_returns_declared_opcional_across_fonte_shapes() {
15749 // Default-`false` form via the [`Dep::simple`] constructor —
15750 // the accessor projects the `false` bit the default-fill sets.
15751 assert!(!Dep::simple("caixa-teia", "^0.1").opcional());
15752 // Default-`false` form via the [`Dep::git`] constructor — same
15753 // default fill; the accessor projects `false` regardless of the
15754 // `:fonte` arm.
15755 assert!(!Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").opcional(),);
15756 // Explicit-`true` form × plain-shorthand `:fonte` — the
15757 // canonical author-surface "this dep may be missing" shape.
15758 let plain_true = Dep {
15759 nome: "caixa-teia".to_string(),
15760 versao: "^0.1".to_string(),
15761 fonte: None,
15762 opcional: true,
15763 caracteristicas: Vec::new(),
15764 };
15765 assert!(plain_true.opcional());
15766 // Explicit-`true` form × explicit git-source — the accessor
15767 // projects the bit verbatim regardless of the `:fonte` arm.
15768 let git_true = Dep {
15769 nome: "caixa-teia".to_string(),
15770 versao: "^0.1".to_string(),
15771 fonte: Some(DepSource::Git {
15772 repo: "github:pleme-io/caixa-teia".to_string(),
15773 tag: Some("v0.1.0".to_string()),
15774 rev: None,
15775 branch: None,
15776 }),
15777 opcional: true,
15778 caracteristicas: Vec::new(),
15779 };
15780 assert!(git_true.opcional());
15781 // Explicit-`true` form × explicit path-source — the dev-only
15782 // local-filesystem arm the [`Dep`] docstring's third fixture
15783 // carries.
15784 let path_true = Dep {
15785 nome: "caixa-teia".to_string(),
15786 versao: "0.1.0".to_string(),
15787 fonte: Some(DepSource::Path {
15788 caminho: "../caixa-teia".to_string(),
15789 }),
15790 opcional: true,
15791 caracteristicas: Vec::new(),
15792 };
15793 assert!(path_true.opcional());
15794 }
15795
15796 #[test]
15797 fn dep_opcional_projects_bool_by_copy() {
15798 // The by-`Copy` pin: [`Dep::opcional`] returns `bool` by value
15799 // (`bool: Copy`) — the accessor does not borrow `&self` past
15800 // the call (no lifetime on the return type), and calling the
15801 // accessor twice on the same [`Dep`] must yield discriminant-
15802 // equal values (idempotent, no side effects on `&self`). Peer
15803 // of the sibling outer-`Caixa` `Option<Copy>` by-`Copy`
15804 // `max_restarts_projects_option_by_copy` (eba5211) /
15805 // `estrategia_projects_option_by_copy` (ed04d3c) pins on the
15806 // outer-`Caixa` altitude — extended here to the outer-`Dep`
15807 // altitude's plain-`Copy` `bool` axis. The `Copy` discipline
15808 // replaces the pointer-equality claim the sibling per-`Dep`
15809 // by-borrow pins (`dep_nome_is_by_borrow_pointer_identity`
15810 // eba2cde, `dep_versao_requirement_is_by_borrow_pointer_identity`
15811 // 05529b1, `dep_fonte_is_by_borrow_pointer_identity` d65d1bf,
15812 // `dep_caracteristicas_is_by_borrow_pointer_identity` 9197944)
15813 // carry (a fresh `Copy` of a `Copy` discriminant is definitionally
15814 // the same discriminant, so the axis reduces to discriminant
15815 // equality).
15816 //
15817 // Pins against a future silent detour that returned a fresh
15818 // `&bool` reference (which would type-check but silently
15819 // introduce a borrow of `&self` past the call, collapsing the
15820 // load-bearing "no lifetime on the return type" `Copy`
15821 // projection the plain-`Copy`-scalar axis's `bool` shape
15822 // carries) or a stale-read side effect that flipped the outer
15823 // discriminant on successive calls.
15824 for opcional in [false, true] {
15825 let d = Dep {
15826 nome: "caixa-teia".to_string(),
15827 versao: "^0.1".to_string(),
15828 fonte: None,
15829 opcional,
15830 caracteristicas: Vec::new(),
15831 };
15832 let first = d.opcional();
15833 let second = d.opcional();
15834 assert_eq!(
15835 first, second,
15836 "Dep::opcional must be idempotent — two successive calls \
15837 on the same &self must return the same bool",
15838 );
15839 assert_eq!(
15840 first, opcional,
15841 "Dep::opcional must return :opcional verbatim by Copy — \
15842 got {first}, expected {opcional}",
15843 );
15844 assert_eq!(
15845 d.opcional(),
15846 d.opcional,
15847 "Dep::opcional accessor and self.opcional field access \
15848 must byte-equal — a bit-flip drift would silently split \
15849 the paired resolver-side drop-vs-error dispatch from \
15850 the storage-side default-fill the [`Dep::simple`] / \
15851 [`Dep::git`] constructor pair carries",
15852 );
15853 }
15854 }
15855
15856 // ── DepSource::sole_pin — sole-set git-pin accessor ─────────────────
15857
15858 #[test]
15859 fn sole_pin_returns_none_for_path_source() {
15860 // A path source carries no git-ref, so `sole_pin()` returns
15861 // `None` structurally — the sibling arm every git-fetching
15862 // consumer partitions off before reaching for a git-ref. Pins
15863 // the Path-arm branch of the accessor against a future silent
15864 // detour that treats a `Self::Path` as an unpinned-git source
15865 // and returns the wrong "no pin" signal (e.g. the empty string,
15866 // or a hard-coded `Some("HEAD")` matching the caixa-crd
15867 // path-arm `git_ref` fill).
15868 let s = DepSource::Path {
15869 caminho: "../local-caixa".to_string(),
15870 };
15871 assert_eq!(s.sole_pin(), None);
15872 }
15873
15874 #[test]
15875 fn sole_pin_returns_none_for_unpinned_git_source() {
15876 // The [`DepSource::default_github`] shorthand shape carries no
15877 // pin — every `tag`/`rev`/`branch` is `None`, and `sole_pin()`
15878 // returns `None`. This is the shape caixa-resolver's `fetch_dep`
15879 // materializes when the author omits `:fonte` entirely, then
15880 // hands to `fetch_git` which raises `ResolveError::MissingPin`
15881 // on the `None` arm — the accessor's return matches the arm
15882 // the resolver's diagnostic keys off.
15883 let s = DepSource::default_github("pleme-io", "caixa-teia");
15884 assert_eq!(s.sole_pin(), None);
15885 }
15886
15887 #[test]
15888 fn sole_pin_returns_rev_when_only_rev_is_set() {
15889 let s = DepSource::Git {
15890 repo: "github:o/x".into(),
15891 tag: None,
15892 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15893 branch: None,
15894 };
15895 assert_eq!(
15896 s.sole_pin(),
15897 Some("deadbeefcafebabe1234567890abcdef12345678")
15898 );
15899 }
15900
15901 #[test]
15902 fn sole_pin_returns_tag_when_only_tag_is_set() {
15903 let s = DepSource::Git {
15904 repo: "github:o/x".into(),
15905 tag: Some("v0.1.0".into()),
15906 rev: None,
15907 branch: None,
15908 };
15909 assert_eq!(s.sole_pin(), Some("v0.1.0"));
15910 }
15911
15912 #[test]
15913 fn sole_pin_returns_branch_when_only_branch_is_set() {
15914 let s = DepSource::Git {
15915 repo: "github:o/x".into(),
15916 tag: None,
15917 rev: None,
15918 branch: Some("main".into()),
15919 };
15920 assert_eq!(s.sole_pin(), Some("main"));
15921 }
15922
15923 #[test]
15924 fn sole_pin_precedence_rev_beats_tag_and_branch() {
15925 // Precedence: rev > tag > branch. Validate() rejects
15926 // multiple-pin shapes, but the accessor's precedence is defined
15927 // for pre-validate consumers (the resolver's `MissingPin`
15928 // diagnostic path, the caixa-crd round-trip's default `"main"`
15929 // fallback) and as defense-in-depth if the gate is ever
15930 // bypassed. Pins the same precedence caixa-resolver's
15931 // `fetch_git` and caixa-crd's `dep_into_ref` already apply
15932 // inline.
15933 let s = DepSource::Git {
15934 repo: "github:o/x".into(),
15935 tag: Some("v1".into()),
15936 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15937 branch: Some("main".into()),
15938 };
15939 assert_eq!(
15940 s.sole_pin(),
15941 Some("deadbeefcafebabe1234567890abcdef12345678")
15942 );
15943 }
15944
15945 #[test]
15946 fn sole_pin_precedence_tag_beats_branch_when_no_rev() {
15947 let s = DepSource::Git {
15948 repo: "github:o/x".into(),
15949 tag: Some("v1".into()),
15950 rev: None,
15951 branch: Some("main".into()),
15952 };
15953 assert_eq!(s.sole_pin(), Some("v1"));
15954 }
15955
15956 #[test]
15957 fn sole_pin_byte_equals_inline_rev_or_tag_or_branch_cascade() {
15958 // Fail-before-pass-after byte-parity pin: the substrate accessor
15959 // must return byte-identical to the inline
15960 // `rev.as_deref().or(tag.as_deref()).or(branch.as_deref())`
15961 // cascade both caixa-resolver's `fetch_git` and caixa-crd's
15962 // `dep_into_ref` open-coded pre-lift. Trips at caixa-core build
15963 // time if the accessor's precedence silently drifts from the
15964 // consumer-side cascade — the exact drift this lift converges
15965 // to one substrate primitive to close structurally.
15966 //
15967 // Iterates through the 2^3 = 8 combinations of (tag, rev,
15968 // branch) each-either-`None`-or-`Some`, so every arm of the
15969 // precedence cascade lands under the pin. `validate()` refuses
15970 // the 4 multi-pin combinations, but the accessor's return is
15971 // defined on all 8.
15972 let vals = [Some("R".to_string()), None];
15973 for tag in &vals {
15974 for rev in &vals {
15975 for branch in &vals {
15976 let s = DepSource::Git {
15977 repo: "github:o/x".into(),
15978 tag: tag.clone(),
15979 rev: rev.clone(),
15980 branch: branch.clone(),
15981 };
15982 // The exact inline cascade the two pre-lift
15983 // consumer sites hand-rolled, byte-for-byte.
15984 let expected = rev.as_deref().or(tag.as_deref()).or(branch.as_deref());
15985 assert_eq!(
15986 s.sole_pin(),
15987 expected,
15988 "sole_pin() must byte-equal \
15989 rev.or(tag).or(branch) for \
15990 (tag={tag:?}, rev={rev:?}, branch={branch:?}) — \
15991 a drift would silently split caixa-resolver's \
15992 fetch_git checkout target from caixa-crd's \
15993 dep_into_ref git_ref fill",
15994 );
15995 }
15996 }
15997 }
15998 }
15999
16000 // Fail-before-pass-after pins on the eleven
16001 // [`fonte_caminho_ctors!`]-generated `DepError::fonte_caminho_*`
16002 // constructors folded from the [`DepSource::validate_caminho`]
16003 // wire-up sites. Each pins the generated ctor's output to the
16004 // pre-lift struct-literal on the same `(&str, &str)` fixture, so
16005 // any wrapper-side lowercase / trim / re-order / silent-field-swap
16006 // regression on the two-field `{ nome: nome.to_string(), caminho:
16007 // caminho.to_string() }` construction surfaces here rather than at
16008 // a downstream diagnostic-shape mismatch. Peer of the sibling
16009 // `empty_child_version_ctor_matches_struct_literal_wrap` /
16010 // `contrato_endpoint_empty_ctor_matches_struct_literal_wrap` /
16011 // `entrada_host_invalid_ctor_matches_struct_literal_wrap` /
16012 // `nome_only_ctor_routes_caixa_through_nome_accessor` equivalence
16013 // pins on the peer `SupervisorError` / `AplicacaoError` /
16014 // `LayoutError` / `LimitsError` / `UpgradeError` envelopes.
16015
16016 #[test]
16017 fn fonte_caminho_absolute_ctor_matches_struct_literal_wrap() {
16018 assert_eq!(
16019 DepError::fonte_caminho_absolute("caixa-teia", "/home/me/work/caixa-teia"),
16020 DepError::FonteCaminhoAbsolute {
16021 nome: "caixa-teia".to_string(),
16022 caminho: "/home/me/work/caixa-teia".to_string(),
16023 },
16024 "generated fonte_caminho_absolute ctor must produce byte-equal \
16025 DepError to the open-coded struct-literal wrap on the same \
16026 (&str, &str) fixture",
16027 );
16028 }
16029
16030 #[test]
16031 fn fonte_caminho_tilde_expansion_ctor_matches_struct_literal_wrap() {
16032 assert_eq!(
16033 DepError::fonte_caminho_tilde_expansion("caixa-teia", "~/work/caixa-teia"),
16034 DepError::FonteCaminhoTildeExpansion {
16035 nome: "caixa-teia".to_string(),
16036 caminho: "~/work/caixa-teia".to_string(),
16037 },
16038 );
16039 }
16040
16041 #[test]
16042 fn fonte_caminho_var_expansion_ctor_matches_struct_literal_wrap() {
16043 assert_eq!(
16044 DepError::fonte_caminho_var_expansion("caixa-teia", "$HOME/work/caixa-teia"),
16045 DepError::FonteCaminhoVarExpansion {
16046 nome: "caixa-teia".to_string(),
16047 caminho: "$HOME/work/caixa-teia".to_string(),
16048 },
16049 );
16050 }
16051
16052 #[test]
16053 fn fonte_caminho_leading_whitespace_ctor_matches_struct_literal_wrap() {
16054 assert_eq!(
16055 DepError::fonte_caminho_leading_whitespace("caixa-teia", " ../caixa-teia"),
16056 DepError::FonteCaminhoLeadingWhitespace {
16057 nome: "caixa-teia".to_string(),
16058 caminho: " ../caixa-teia".to_string(),
16059 },
16060 );
16061 }
16062
16063 #[test]
16064 fn fonte_caminho_leading_hyphen_ctor_matches_struct_literal_wrap() {
16065 assert_eq!(
16066 DepError::fonte_caminho_leading_hyphen("caixa-teia", "-rf"),
16067 DepError::FonteCaminhoLeadingHyphen {
16068 nome: "caixa-teia".to_string(),
16069 caminho: "-rf".to_string(),
16070 },
16071 );
16072 }
16073
16074 #[test]
16075 fn fonte_caminho_backslash_ctor_matches_struct_literal_wrap() {
16076 assert_eq!(
16077 DepError::fonte_caminho_backslash("caixa-teia", "..\\caixa-teia"),
16078 DepError::FonteCaminhoBackslash {
16079 nome: "caixa-teia".to_string(),
16080 caminho: "..\\caixa-teia".to_string(),
16081 },
16082 );
16083 }
16084
16085 #[test]
16086 fn fonte_caminho_shell_pipe_ctor_matches_struct_literal_wrap() {
16087 assert_eq!(
16088 DepError::fonte_caminho_shell_pipe("caixa-teia", "../caixa-teia|evil"),
16089 DepError::FonteCaminhoShellPipe {
16090 nome: "caixa-teia".to_string(),
16091 caminho: "../caixa-teia|evil".to_string(),
16092 },
16093 );
16094 }
16095
16096 #[test]
16097 fn fonte_caminho_shell_semicolon_ctor_matches_struct_literal_wrap() {
16098 assert_eq!(
16099 DepError::fonte_caminho_shell_semicolon("caixa-teia", "../caixa-teia;evil"),
16100 DepError::FonteCaminhoShellSemicolon {
16101 nome: "caixa-teia".to_string(),
16102 caminho: "../caixa-teia;evil".to_string(),
16103 },
16104 );
16105 }
16106
16107 #[test]
16108 fn fonte_caminho_shell_background_ctor_matches_struct_literal_wrap() {
16109 assert_eq!(
16110 DepError::fonte_caminho_shell_background("caixa-teia", "../caixa-teia&"),
16111 DepError::FonteCaminhoShellBackground {
16112 nome: "caixa-teia".to_string(),
16113 caminho: "../caixa-teia&".to_string(),
16114 },
16115 );
16116 }
16117
16118 #[test]
16119 fn fonte_caminho_shell_command_substitution_ctor_matches_struct_literal_wrap() {
16120 assert_eq!(
16121 DepError::fonte_caminho_shell_command_substitution(
16122 "caixa-teia",
16123 "../caixa-teia`whoami`",
16124 ),
16125 DepError::FonteCaminhoShellCommandSubstitution {
16126 nome: "caixa-teia".to_string(),
16127 caminho: "../caixa-teia`whoami`".to_string(),
16128 },
16129 );
16130 }
16131
16132 #[test]
16133 fn fonte_caminho_trailing_slash_ctor_matches_struct_literal_wrap() {
16134 assert_eq!(
16135 DepError::fonte_caminho_trailing_slash("caixa-teia", "../caixa-teia/"),
16136 DepError::FonteCaminhoTrailingSlash {
16137 nome: "caixa-teia".to_string(),
16138 caminho: "../caixa-teia/".to_string(),
16139 },
16140 );
16141 }
16142
16143 #[test]
16144 fn fonte_caminho_ctors_route_nome_and_caminho_through_to_string() {
16145 // Cross-axis pin: sweep the two constructor input axes
16146 // (`nome: &str`, `caminho: &str`) through a non-default fixture
16147 // pair against every generated arm in the
16148 // [`fonte_caminho_ctors!`] macro, so any wrapper-side lowercase
16149 // / trim / truncate / re-order on the two-field
16150 // `{ nome, caminho }` construction — or a silent field swap
16151 // between the two axes at codegen time — surfaces here rather
16152 // than at a downstream diagnostic-shape mismatch. Peer of the
16153 // sibling `supervisor_caixa_only_ctors_route_caixa_through_
16154 // to_string` cross-axis routing pin on the peer
16155 // `SupervisorError` envelope, extended here onto the
16156 // `DepError` `{ nome: String, caminho: String }` envelope so
16157 // every substrate-primitive ctor family in caixa-core
16158 // guarantees each `&str`-field construction routes the
16159 // caller's `&str` verbatim through `.to_string()`.
16160 let nome = "sibling-teia";
16161 let caminho = "../workspace/sibling";
16162 let cases: [(DepError, DepError); 11] = [
16163 (
16164 DepError::fonte_caminho_absolute(nome, caminho),
16165 DepError::FonteCaminhoAbsolute {
16166 nome: nome.to_string(),
16167 caminho: caminho.to_string(),
16168 },
16169 ),
16170 (
16171 DepError::fonte_caminho_tilde_expansion(nome, caminho),
16172 DepError::FonteCaminhoTildeExpansion {
16173 nome: nome.to_string(),
16174 caminho: caminho.to_string(),
16175 },
16176 ),
16177 (
16178 DepError::fonte_caminho_var_expansion(nome, caminho),
16179 DepError::FonteCaminhoVarExpansion {
16180 nome: nome.to_string(),
16181 caminho: caminho.to_string(),
16182 },
16183 ),
16184 (
16185 DepError::fonte_caminho_leading_whitespace(nome, caminho),
16186 DepError::FonteCaminhoLeadingWhitespace {
16187 nome: nome.to_string(),
16188 caminho: caminho.to_string(),
16189 },
16190 ),
16191 (
16192 DepError::fonte_caminho_leading_hyphen(nome, caminho),
16193 DepError::FonteCaminhoLeadingHyphen {
16194 nome: nome.to_string(),
16195 caminho: caminho.to_string(),
16196 },
16197 ),
16198 (
16199 DepError::fonte_caminho_backslash(nome, caminho),
16200 DepError::FonteCaminhoBackslash {
16201 nome: nome.to_string(),
16202 caminho: caminho.to_string(),
16203 },
16204 ),
16205 (
16206 DepError::fonte_caminho_shell_pipe(nome, caminho),
16207 DepError::FonteCaminhoShellPipe {
16208 nome: nome.to_string(),
16209 caminho: caminho.to_string(),
16210 },
16211 ),
16212 (
16213 DepError::fonte_caminho_shell_semicolon(nome, caminho),
16214 DepError::FonteCaminhoShellSemicolon {
16215 nome: nome.to_string(),
16216 caminho: caminho.to_string(),
16217 },
16218 ),
16219 (
16220 DepError::fonte_caminho_shell_background(nome, caminho),
16221 DepError::FonteCaminhoShellBackground {
16222 nome: nome.to_string(),
16223 caminho: caminho.to_string(),
16224 },
16225 ),
16226 (
16227 DepError::fonte_caminho_shell_command_substitution(nome, caminho),
16228 DepError::FonteCaminhoShellCommandSubstitution {
16229 nome: nome.to_string(),
16230 caminho: caminho.to_string(),
16231 },
16232 ),
16233 (
16234 DepError::fonte_caminho_trailing_slash(nome, caminho),
16235 DepError::FonteCaminhoTrailingSlash {
16236 nome: nome.to_string(),
16237 caminho: caminho.to_string(),
16238 },
16239 ),
16240 ];
16241 for (via_ctor, via_struct_literal) in cases {
16242 assert_eq!(
16243 via_ctor, via_struct_literal,
16244 "fonte_caminho_ctors!-generated ctor must route (nome, caminho) \
16245 through `.to_string()` in declared field order — a field-swap or \
16246 silent-conversion regression surfaces here rather than at a \
16247 downstream diagnostic-shape mismatch",
16248 );
16249 }
16250 }
16251}
16252
16253#[cfg(test)]
16254mod dep_source_is_variant_tests {
16255 use super::*;
16256
16257 fn all_variants() -> Vec<(DepSource, &'static str)> {
16258 vec![
16259 (
16260 DepSource::Git {
16261 repo: "github:pleme-io/caixa-teia".into(),
16262 tag: Some("v0.1.0".into()),
16263 rev: None,
16264 branch: None,
16265 },
16266 "Git",
16267 ),
16268 (
16269 DepSource::Path {
16270 caminho: "../caixa-teia".into(),
16271 },
16272 "Path",
16273 ),
16274 ]
16275 }
16276
16277 fn predicate_row(s: &DepSource) -> [bool; 2] {
16278 [s.is_git(), s.is_path()]
16279 }
16280
16281 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
16282 // derive-generated per-arm predicate partition — for every variant
16283 // in `all_variants()`, the observed 2-slot predicate row must equal
16284 // a one-hot row with the `true` at exactly the same index as the
16285 // variant's declaration order. Expected rows are generated live
16286 // from the enumeration rather than transcribed by hand, so a
16287 // copy-paste flip that reroutes one arm through the wrong predicate
16288 // lane trips at the identity-diagonal assertion the way every peer
16289 // sibling [`DepList`] / [`crate::CaixaKind`] / [`crate::CaixaDialeto`]
16290 // / [`crate::supervisor::RestartStrategy`] / [`crate::supervisor::RestartPolicy`]
16291 // / [`crate::upgrade::UpgradeInstruction`] /
16292 // [`crate::aplicacao::PlacementStrategy`] /
16293 // [`crate::aplicacao::RateLimitUnit`] /
16294 // [`crate::aplicacao::WitTarget`] /
16295 // [`crate::render::PathShapeViolation`] partition pin already does.
16296 #[test]
16297 fn dep_source_is_variant_predicates_partition_the_arm_set() {
16298 let variants = all_variants();
16299 for (idx, (variant, name)) in variants.iter().enumerate() {
16300 let observed = predicate_row(variant);
16301 let mut expected = [false; 2];
16302 expected[idx] = true;
16303 assert_eq!(
16304 observed, expected,
16305 "DepSource::{name} at declaration-order slot {idx} must \
16306 satisfy exactly one is_* predicate (its own); observed \
16307 row must equal the one-hot expected row — a drift \
16308 would silently reroute one `:fonte`-arm consumer \
16309 through the wrong predicate lane"
16310 );
16311 }
16312 }
16313
16314 // Byte-parity pin on the two field-agnostic `matches!` shapes the
16315 // per-arm arm-discriminator predicates replace at any future
16316 // consumer site (a `:fonte`-shape-only lint rule that flags path
16317 // deps outside dev-caixas via `dep.fonte().is_some_and(DepSource::is_path)`,
16318 // a future admission-webhook that rejects `:fonte` shapes outside
16319 // the `is_git()` accept-set, a caixa-lacre indexing pass that
16320 // dispatches on `s.is_git()` without extracting `repo` / `caminho`).
16321 // Refuses a future accidental split between the derived predicate
16322 // and its `matches!` shape — a hand-rolled shadow impl that
16323 // overrides one path, an accidental rebrand that leaves one
16324 // consumer on the raw `matches!` form — on the two load-bearing
16325 // `:fonte`-arm-discriminator axes every downstream substrate
16326 // consumer of the dep-source axis keys off.
16327 #[test]
16328 fn dep_source_is_git_and_is_path_byte_equal_matches_shape() {
16329 for (variant, name) in all_variants() {
16330 let via_matches_git = matches!(variant, DepSource::Git { .. });
16331 let via_predicate_git = variant.is_git();
16332 assert_eq!(
16333 via_predicate_git, via_matches_git,
16334 "DepSource::{name}.is_git() must byte-equal \
16335 matches!(_, DepSource::Git {{ .. }}) — otherwise a \
16336 future converged consumer site would silently \
16337 disagree with its pre-lift shape"
16338 );
16339 let via_matches_path = matches!(variant, DepSource::Path { .. });
16340 let via_predicate_path = variant.is_path();
16341 assert_eq!(
16342 via_predicate_path, via_matches_path,
16343 "DepSource::{name}.is_path() must byte-equal \
16344 matches!(_, DepSource::Path {{ .. }}) — otherwise a \
16345 future converged consumer site would silently \
16346 disagree with its pre-lift shape"
16347 );
16348 }
16349 }
16350
16351 // Cross-pin against every constructor path that materializes a
16352 // [`DepSource`] shape today (the [`DepSource::default_github`]
16353 // resolver-side fallback that materializes an unpinned
16354 // `github:<org>/<nome>` git shorthand, the [`Dep::git`] author-
16355 // surface constructor that materializes a pinned `:tag`-carrying
16356 // `DepSource::Git`, a hand-rolled `DepSource::Path` the dev-mode
16357 // fixture family builds inline). Every constructor's return must
16358 // satisfy the arm-discriminator predicate the constructor's
16359 // variant name matches — a future constructor addition (an
16360 // in-tree registry-fetch pin, a `DepSource::Feira` variant the
16361 // enclosing docstring already names as a trajectory item) surfaces
16362 // as a build-time failure that names the offending drift when its
16363 // return arm doesn't route through the paired predicate.
16364 #[test]
16365 fn dep_source_constructors_route_through_paired_is_variant_predicate() {
16366 let via_default_github = DepSource::default_github("pleme-io", "caixa-teia");
16367 assert!(
16368 via_default_github.is_git(),
16369 "DepSource::default_github must materialize a Git-arm shape — \
16370 a future constructor that routed through a non-Git arm \
16371 (a registry-fetch pin, a `DepSource::Feira` promotion) \
16372 would silently split the resolver's unpinned-shorthand \
16373 materializer from the sole_pin() precedence cascade"
16374 );
16375 assert!(
16376 !via_default_github.is_path(),
16377 "DepSource::default_github must NOT materialize a Path-arm \
16378 shape — the paired negation pin"
16379 );
16380
16381 let via_dep_git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
16382 .fonte
16383 .expect("Dep::git materializes a Some(fonte)");
16384 assert!(
16385 via_dep_git.is_git(),
16386 "Dep::git's `:fonte` materialization must land on the Git \
16387 arm — the author-surface pinned-git constructor's return \
16388 must route through the paired predicate"
16389 );
16390 assert!(!via_dep_git.is_path(), "paired negation pin");
16391
16392 let via_path = DepSource::Path {
16393 caminho: "../caixa-teia".into(),
16394 };
16395 assert!(
16396 via_path.is_path(),
16397 "the dev-mode Path-arm materialization must satisfy is_path()"
16398 );
16399 assert!(!via_path.is_git(), "paired negation pin");
16400 }
16401}