caixa_core/dep.rs
1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4/// A single dependency declaration in a `caixa.lisp` manifest.
5///
6/// **Store model = Git, like Zig.** There is no central registry; a caixa is
7/// just a Git repo with a `caixa.lisp` at its root. When `:fonte` is omitted,
8/// the resolver falls back to `github:<default-org>/<nome>` (org defaults to
9/// `pleme-io`, override via `~/.config/caixa/config.yaml`).
10///
11/// ```lisp
12/// ;; Shorthand — resolves to github:pleme-io/caixa-teia (or your default org):
13/// (:nome "caixa-teia" :versao "^0.1")
14///
15/// ;; Explicit git source:
16/// (:nome "caixa-teia"
17/// :versao "^0.1"
18/// :fonte (:tipo git :repo "github:pleme-io/caixa-teia" :tag "v0.1.0"))
19///
20/// ;; Arbitrary git URL (not limited to GitHub):
21/// (:nome "private-caixa"
22/// :versao "*"
23/// :fonte (:tipo git :repo "ssh://git@git.example/team/priv-caixa.git" :branch "main"))
24///
25/// ;; Local path (dev only; not publishable):
26/// (:nome "caixa-teia"
27/// :versao "0.1.0"
28/// :fonte (:tipo path :caminho "../caixa-teia"))
29/// ```
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
31#[serde(rename_all = "camelCase")]
32pub struct Dep {
33 /// Caixa name — must match the target caixa's `:nome`.
34 pub nome: String,
35
36 /// Semver constraint string (`"^0.1"`, `"~0.1.2"`, `"0.1.0"`, `"*"`).
37 pub versao: String,
38
39 /// Where to fetch the caixa from. Defaults to the feira registry.
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub fonte: Option<DepSource>,
42
43 /// If true, a missing `:fonte` is not a build failure.
44 #[serde(default, skip_serializing_if = "is_false")]
45 pub opcional: bool,
46
47 /// Feature flags to enable on the target caixa.
48 #[serde(default, skip_serializing_if = "Vec::is_empty")]
49 pub caracteristicas: Vec<String>,
50}
51
52/// Where a dep is fetched from. Tagged via `:tipo` in Lisp.
53///
54/// Only two shapes — Git and local Path. No central registry variant: a caixa
55/// is just a Git repo. Omitting `:fonte` means *"use the default resolver
56/// convention"*, which is `github:<default-org>/<nome>`; the resolver fills
57/// that in when computing the lacre.
58///
59/// The [`gen_platform::IsVariant`] derive emits per-arm arm-discriminator
60/// predicates — [`Self::is_git`], [`Self::is_path`] — so every downstream
61/// consumer that only needs the arm-discriminator projection (not the
62/// borrowed field value) reaches for one typed dispatch on the substrate
63/// primitive rather than a hand-rolled `matches!(s, DepSource::X { .. })`
64/// literal. Extends the closed-set-typed-enum discipline the sibling
65/// caixa-core enums ([`crate::CaixaKind`], [`crate::CaixaDialeto`],
66/// [`crate::supervisor::RestartStrategy`], [`crate::supervisor::RestartPolicy`],
67/// [`crate::upgrade::UpgradeInstruction`], [`crate::aplicacao::PlacementStrategy`],
68/// [`crate::aplicacao::RateLimitUnit`], [`crate::aplicacao::WitTarget`],
69/// [`crate::render::PathShapeViolation`], [`DepList`]) and the sibling
70/// out-of-crate enums (caixa-arch's `InvariantKind` + `ArchVerdict`,
71/// caixa-lint's `Severity` + `FixSafety`, caixa-provedor's
72/// `FerriteRuntime`, caixa-theme's `Semantic`, caixa-flux's `GitRefSpec`,
73/// caixa-ast's `NodeKind` + `TriviaKind`) already carry onto the
74/// two-arm `:fonte` dep-source axis — the 17th closed-set typed enum
75/// on the caixa surface, and the first on the outer-`Dep` `:fonte`-slot
76/// axis every git-fetching consumer runs after the outer `:fonte` slot
77/// resolves to a shape.
78#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, gen_platform::IsVariant)]
79#[serde(tag = "tipo", rename_all = "lowercase")]
80pub enum DepSource {
81 /// Clone from Git. One of `:tag`, `:rev`, or `:branch` may be set.
82 /// `repo` can be a `github:org/repo` shorthand, a full `https://…` URL,
83 /// or any git-ssh URL.
84 Git {
85 repo: String,
86 #[serde(default, skip_serializing_if = "Option::is_none")]
87 tag: Option<String>,
88 #[serde(default, skip_serializing_if = "Option::is_none")]
89 rev: Option<String>,
90 #[serde(default, skip_serializing_if = "Option::is_none")]
91 branch: Option<String>,
92 },
93 /// Local filesystem path — dev only; cannot be published.
94 Path { caminho: String },
95}
96
97impl DepSource {
98 /// Build a registry-shorthand git source (`github:<org>/<nome>`).
99 ///
100 /// This is the resolver-side fallback for `dep.fonte: None`, not an
101 /// author-surface value — it carries no pin (`:tag`/`:rev`/`:branch`
102 /// all `None`) and is therefore rejected by [`Self::validate`]. The
103 /// resolver fills the pin in at fetch time from the resolved commit;
104 /// authors never serialize this shape as a `Dep::fonte` value.
105 #[must_use]
106 pub fn default_github(org: &str, nome: &str) -> Self {
107 Self::Git {
108 repo: format!("github:{org}/{nome}"),
109 tag: None,
110 rev: None,
111 branch: None,
112 }
113 }
114
115 /// Substrate-canonical per-`:fonte` sole-set git-pin scalar accessor
116 /// every consumer that reads "which single git ref does this source
117 /// resolve to?" keys off — returns the author-declared `:tag` /
118 /// `:rev` / `:branch` byte-string verbatim as an `Option<&str>`,
119 /// borrowed from the typed slot's own `Option<String>` storage; `None`
120 /// on [`Self::Path`] (a path source carries no git-ref) and on a
121 /// [`Self::Git`] variant whose `tag`, `rev`, and `branch` are all
122 /// `None` (the [`Self::default_github`] shorthand shape the resolver
123 /// materializes when the author omits `:fonte` — rejected by
124 /// [`Self::validate`], but the accessor's return is defined on this
125 /// arm too so pre-validate consumers reach for the same typed dispatch
126 /// as post-validate ones).
127 ///
128 /// **Precedence: rev > tag > branch.** The canonical precedence every
129 /// per-`:fonte` git-ref consumer already applies: caixa-resolver's
130 /// per-fetch `git checkout <ref>` reads through the same
131 /// `rev.or(tag).or(branch)` cascade at caixa-resolver/src/resolve.rs,
132 /// and caixa-crd's `dep_into_ref` `CaixaSource.git_ref` fill reads
133 /// through the same cascade at caixa-crd/src/conversion.rs. The
134 /// [`Self::validate`] gate enforces "exactly one pin set" — under
135 /// that invariant every accepted [`Self::Git`] carries exactly one
136 /// non-`None` pin and the precedence is unobservable, but the
137 /// precedence remains defined for pre-validate consumers (the
138 /// resolver's `MissingPin` diagnostic path, the caixa-crd
139 /// round-trip's default `"main"` fallback the author never sees a
140 /// diagnostic on) and defense-in-depth for a hypothetical future
141 /// state where multiple pins survive the gate. The precedence is
142 /// **rev before tag** because `:rev` (a git commit OID) is the
143 /// reproducibility-strongest identifier — an OID resolves to exactly
144 /// one commit regardless of which refname points at it, whereas
145 /// `:tag` and `:branch` are refnames the remote can silently move
146 /// (a tag re-push, a branch head advance); the resolver's freeze
147 /// step at fetch time promotes the resolved commit to `:rev` for
148 /// exactly this reason. **Tag before branch** because `:tag` is
149 /// conventionally immutable (a release tag) whereas `:branch` is
150 /// conventionally mutable (a tracking ref) — a caixa carrying both
151 /// a release tag and a tracking branch reads as "prefer the release
152 /// pin, fall through to the tracking pin only if the release is
153 /// missing". The cascade order also matches the byte-order every
154 /// per-`:tag`/`:rev`/`:branch` diagnostic tuple this crate emits
155 /// (`(":tag", tag), (":rev", rev), (":branch", branch)` — see
156 /// [`Self::validate`]'s `pins` array).
157 ///
158 /// Prior to this lift the "sole set pin" projection sat twice in the
159 /// workspace — inline at caixa-resolver's `fetch_git` (`let gitref =
160 /// rev.or(tag).or(branch).ok_or_else(|| ResolveError::MissingPin
161 /// { … })?;`) and at caixa-crd's `dep_into_ref`
162 /// (`git_ref: rev.clone().or(tag.clone()).or(branch.clone())
163 /// .unwrap_or_else(|| "main".to_string())`) — two open-coded copies
164 /// of the same precedence cascade with no compile-time link back to
165 /// the typed slot. A future extension of the pin axis to a richer
166 /// author surface (a `:commit` pin peer of `:rev` once the substrate
167 /// grows a signed-commit-verification pin, a `:ref` pin the M4
168 /// substrate operator resolves per-cluster ahead of fetch, a
169 /// promotion of the plain `Option<String>` pins to a typed
170 /// `GitPin::{Rev(Oid), Tag(RefName), Branch(RefName)}` newtype
171 /// once the sibling [`crate::render::is_git_oid`] /
172 /// [`crate::render::is_git_ref_name`] gates land as typed
173 /// constructors) would have had to be threaded through both
174 /// open-coded copies in lockstep or the resolver's `git checkout`
175 /// target would silently disagree with the CRD's `git_ref` fill —
176 /// an author's `(:fonte (:tipo git :repo "…" :rev "deadbeef" :tag
177 /// "v1"))` would ship with the resolver checking out `deadbeef`
178 /// while the CRD round-trip re-emitted a Dep pointing at `v1`, one
179 /// lacre closure disagreeing with the emitted K8s CR the operator
180 /// reads. Lifting the resolution to a typed method on the substrate
181 /// primitive means both downstream consumers reach for exactly one
182 /// typed dispatch — the resolver's accept-set migrates as a unit on
183 /// any future pin-axis addition.
184 ///
185 /// Peer of the sibling outer-`Dep` [`Dep::fonte`] (d65d1bf)
186 /// `Option<&DepSource>` composite-reference accessor on the outer-
187 /// `Dep` `:fonte`-slot axis — extended one nesting level down onto
188 /// the per-[`Self::Git`]-variant sole-set-pin projection axis every
189 /// git-fetching consumer runs after the outer `:fonte` slot resolves
190 /// to a [`Self::Git`] shape. Same "one typed dispatch on the
191 /// substrate primitive, thin projections at each consumer" discipline
192 /// the outer accessor family already carries.
193 #[must_use]
194 pub fn sole_pin(&self) -> Option<&str> {
195 match self {
196 Self::Git {
197 tag, rev, branch, ..
198 } => rev.as_deref().or(tag.as_deref()).or(branch.as_deref()),
199 Self::Path { .. } => None,
200 }
201 }
202
203 /// Validate the `:fonte` value-shape: every author-surface
204 /// `:fonte (:tipo git …)` must carry a non-empty `:repo` and
205 /// exactly one of `:tag` / `:rev` / `:branch` set to a non-empty
206 /// value; every `:fonte (:tipo path …)` must carry a non-empty
207 /// `:caminho`.
208 ///
209 /// Called from [`Dep::validate`] with the dep's `:nome` so every
210 /// diagnostic carries the offending entry verbatim — same
211 /// self-locating shape the `:deps :versao` (2420c44),
212 /// `:membros :versao` (9888b13), `:children :versao` (b38ff3a),
213 /// `:placement :clusters` (6cbb900), and `:membros :caixa`
214 /// (3f9d7a0) gates already expose.
215 ///
216 /// Until this gate landed `:fonte` was the only `:deps`-related
217 /// typed surface still untyped past `Caixa::from_lisp`:
218 /// - Empty `:repo` (`(:tipo git :repo "" :tag "v1")`) silently
219 /// passed parse and surfaced as a git-clone failure at
220 /// lacre-resolve time, far from the source caixa.lisp.
221 /// - A bare `(:tipo git :repo "…")` with no `:tag`/`:rev`/`:branch`
222 /// passed parse and surfaced as the resolver's
223 /// [`ResolveError::MissingPin`](../../caixa-resolver/src/resolve.rs)
224 /// at fetch time, again far from the source caixa.lisp; lifting
225 /// to validate-time gives the author the same diagnostic at the
226 /// edit site.
227 /// - `(:tipo git :repo "…" :tag "v1" :branch "main")` — multiple
228 /// pins set — passed parse and the resolver silently picked
229 /// `:rev > :tag > :branch`, ignoring the other pins with no
230 /// diagnostic; the author had no way to know their `:branch`
231 /// was dropped. This is the canonical "pin drift" footgun.
232 /// - An empty pin value (`(:tipo git :repo "…" :tag "")`) silently
233 /// passed parse and surfaced as `git checkout ""` at fetch time.
234 /// - Empty `:caminho` (`(:tipo path :caminho "")`) silently passed
235 /// parse and surfaced as
236 /// [`ResolveError::MissingPath`](../../caixa-resolver/src/resolve.rs)
237 /// with `path: PathBuf("")` — not actionable.
238 ///
239 /// Each rejected shape maps to a typed
240 /// [`DepError::Fonte*`] variant that names the offending
241 /// dep's `:nome` and the specific axis, so the author can grep
242 /// their caixa.lisp for the `:nome "<nome>"` block and fix it in
243 /// one edit.
244 pub fn validate(&self, nome: &str) -> Result<(), DepError> {
245 match self {
246 Self::Git {
247 repo,
248 tag,
249 rev,
250 branch,
251 } => {
252 if repo.is_empty() {
253 return Err(DepError::FonteRepoEmpty {
254 nome: nome.to_string(),
255 });
256 }
257 // The `:repo` value flows verbatim into the caixa-resolver's
258 // `git clone <repo>` subprocess invocation. Until this gate
259 // landed `:repo` was the last untyped `:fonte`-related axis
260 // past the empty arm: a malformed-but-non-empty repo URL
261 // (`":repo "github:p/x ""` trailing space, paste-from-doc;
262 // `":repo "-upload-pack=evil""` leading `-` — the canonical
263 // CLI-argument-injection vector at the `git clone` boundary;
264 // `":repo "pleme-io/caixa-teia""` missing scheme — `git clone`
265 // reads as a relative filesystem path rather than the
266 // GitHub-shorthand expansion; `":repo "github:p/x\n""`
267 // embedded newline; `":repo "github:café/x""` raw non-ASCII)
268 // silently passed validate and the failure surfaced at
269 // lacre-resolve time with a porcelain-quoting-confused error
270 // far from the source caixa.lisp. The lifted predicate makes
271 // the git-porcelain-URL intersection-floor a substrate-level
272 // invariant at validate time, peer with the three pin axes
273 // (`:tag` + `:branch` via [`crate::render::is_git_ref_name`],
274 // e70d213; `:rev` via [`crate::render::is_git_oid`], be07fd5)
275 // — every `:fonte (:tipo git …)` past validate is now
276 // structurally accept-shaped on every axis the resolver
277 // consumes (the `:repo` URL the `git clone` invokes against,
278 // the `:tag`/`:branch` refname `git fetch`/`git checkout`
279 // accepts, the `:rev` commit OID the lacre's content-
280 // addressing equality probe resolves), closing the
281 // `:fonte` slot's value-shape trajectory end-to-end.
282 if let Err(reason) = crate::render::is_git_repo_url(repo) {
283 return Err(DepError::FonteRepoShape {
284 nome: nome.to_string(),
285 repo: repo.clone(),
286 reason,
287 });
288 }
289 let pins: [(&'static str, Option<&String>); 3] = [
290 (":tag", tag.as_ref()),
291 (":rev", rev.as_ref()),
292 (":branch", branch.as_ref()),
293 ];
294 let set: Vec<&'static str> =
295 pins.iter().filter_map(|(n, v)| v.map(|_| *n)).collect();
296 match set.len() {
297 0 => {
298 return Err(DepError::FontePinMissing {
299 nome: nome.to_string(),
300 });
301 }
302 1 => {
303 for (pin, value) in pins {
304 if value.is_some_and(String::is_empty) {
305 return Err(DepError::FontePinEmpty {
306 nome: nome.to_string(),
307 pin: pin.to_string(),
308 });
309 }
310 }
311 }
312 _ => {
313 return Err(DepError::FontePinAmbiguous {
314 nome: nome.to_string(),
315 pins: set.join(", "),
316 });
317 }
318 }
319 // Per-pin value-shape gate. The refname-shaped axes
320 // (`:tag` + `:branch`) route through
321 // [`crate::render::is_git_ref_name`]; the hex-OID-shaped
322 // `:rev` axis routes through
323 // [`crate::render::is_git_oid`]. The two predicates
324 // partition the `:fonte` pin axes structurally — refname
325 // vs. hex commit — so a cross-axis mis-slot (the
326 // canonical "I conflated `:rev` and `:branch`" footgun:
327 // `:rev "main"` defeating the reproducibility contract,
328 // `:tag "deadbeef…"` mis-slotting a SHA into the
329 // refname-shaped axis) lands at the offending axis's
330 // predicate, not at lacre-resolve `git fetch` /
331 // `git checkout` time. Their valid sets intersect at
332 // the empty set: every refname is rejected by
333 // `is_git_oid`, every OID is rejected by
334 // `is_git_ref_name`, structurally.
335 //
336 // Until this gate landed `:tag` / `:branch` were the
337 // refname-shaped axes still untyped past the empty-pin
338 // arm: a malformed-but-non-empty refname
339 // (`:tag "v0.1.0 "` trailing space — the canonical
340 // paste-from-doc footgun; `:tag "v0.1.0.lock"` colliding
341 // with git's atomic-rename guard suffix; `:tag "../escape"`
342 // path-traversal via consecutive dots; `:branch "main "`
343 // trailing space; `:branch "feature/foo bar"` embedded
344 // space; `:branch "@"` the literal HEAD alias;
345 // `:branch "refs/heads/main"` the fully-qualified ref
346 // copied from `git show-ref` output that resolves to
347 // a literal ref named `refs/heads/refs/heads/main` on
348 // disk) silently passed validate; the `:rev` axis was
349 // the last `:fonte`-related axis still untyped past the
350 // empty-pin arm: a malformed-but-non-empty hex-OID
351 // (`:rev "main"` conflating with `:branch` — the
352 // reproducibility-contract leak; `:rev "v0.1.0"`
353 // conflating with `:tag` — the same mis-slot on the
354 // refname/OID boundary; `:rev "c0ffee"` an abbreviated
355 // 6-char prefix that's ambiguous across repo history;
356 // `:rev "DEADBEEF…"` an uppercase OID that round-trips
357 // inconsistently against `git rev-parse HEAD`'s
358 // lowercase emission) silently passed validate and the
359 // failure surfaced at lacre-resolve `git fetch` /
360 // `git checkout` time with a quoting-confused error
361 // far from the source caixa.lisp, with no field naming
362 // which `:deps` entry carried the typo. Lifting both
363 // gates to caixa-build time matches the value-shape
364 // trajectory the peer typed axes already follow
365 // (c4213a4 typed WitContract endpoint/subject/slot;
366 // eb3456d :entrada :paths; c7d05ec :entrada :host;
367 // 4f0390b :contratos :endpoint; 6226bf4 :contratos :wit;
368 // 63e18a0 :contratos :subject; 2f4316e :contratos
369 // :slot; e70d213 :fonte :tag + :branch) — the typed
370 // slot's valid set matches its downstream consumer's
371 // accepted set (here, the git porcelain's refname /
372 // commit-OID grammars at `git fetch` / `git checkout`
373 // time), structurally. Same diagnostic shape every
374 // per-axis value-shape lift already exposes
375 // (`*Invalid { axis, reason }`); the `value:` field
376 // carries the offending refname / OID verbatim so the
377 // author can grep their caixa.lisp for the
378 // `:tag "<value>"` / `:branch "<value>"` /
379 // `:rev "<value>"` literal and fix it in one edit.
380 for (pin, value) in [(":tag", tag.as_ref()), (":branch", branch.as_ref())] {
381 if let Some(v) = value
382 && let Err(reason) = crate::render::is_git_ref_name(v)
383 {
384 return Err(DepError::FontePinShape {
385 nome: nome.to_string(),
386 pin: pin.to_string(),
387 value: v.clone(),
388 reason,
389 });
390 }
391 }
392 if let Some(v) = rev.as_ref()
393 && let Err(reason) = crate::render::is_git_oid(v)
394 {
395 return Err(DepError::FontePinShape {
396 nome: nome.to_string(),
397 pin: ":rev".to_string(),
398 value: v.clone(),
399 reason,
400 });
401 }
402 Ok(())
403 }
404 Self::Path { caminho } => Self::validate_caminho(nome, caminho),
405 }
406 }
407
408 /// Reproducibility + path-API gate on the `:fonte (:tipo path …)`
409 /// `:caminho` axis. Walks the leading-byte cascade closed by the
410 /// b94fd83 (`/`), a5c248e (`~`), and f4efe9c (`$`) arms; the
411 /// orthogonal embedded-control-byte arm (d624c8d) covering
412 /// `0x00..=0x1F` plus `0x7F` anywhere in the value; and the
413 /// embedded-`\` Windows-path-separator arm closing the
414 /// cross-host-OS-separator divergence vector on the same
415 /// THEORY.md §V.2 render-determinism axis.
416 ///
417 /// Extracted from [`Self::validate`]'s `Self::Path` arm because the
418 /// per-arm cascade now spans nine diagnostic shapes — every new
419 /// `:caminho` arm (a future `&` / `;` / `|` shell-metachar arm,
420 /// a future glob-metachar `*` / `?` arm) lands here rather than
421 /// re-inflating `Self::validate`. The
422 /// function stays a thin per-arm linear walk for one reason: each
423 /// arm's diagnostic carries a distinct typed [`DepError`] variant
424 /// rather than a parser-shaped `reason` string, so collapsing the
425 /// cascade onto a generic [`crate::render`] predicate would regress
426 /// the per-arm self-locating diagnostic that `feira lint` consumers
427 /// depend on. The wrapped predicate trajectory ([`crate::render::is_dns_1123_label`],
428 /// [`crate::render::is_git_repo_url`], etc.) lives on the
429 /// reason-string-shaped axes; the `:caminho` axis keeps its
430 /// per-arm variant shape.
431 #[allow(
432 clippy::too_many_lines,
433 reason = "the per-arm cascade is structurally flat by design — every \
434 `:caminho` arm carries its own typed [`DepError`] variant + \
435 per-arm Why comment, so collapsing the cascade onto a generic \
436 [`crate::render`] predicate would regress the per-arm self-locating \
437 diagnostic the `feira lint` consumer surface depends on"
438 )]
439 fn validate_caminho(nome: &str, caminho: &str) -> Result<(), DepError> {
440 if caminho.is_empty() {
441 return Err(DepError::FonteCaminhoEmpty {
442 nome: nome.to_string(),
443 });
444 }
445 // Reproducibility gate on the `:fonte (:tipo path …)`
446 // `:caminho` axis. The lacre pipeline embeds the value
447 // verbatim in its per-dep content-address
448 // (`conteudo: format!("path:{caminho}")`,
449 // caixa-resolver/src/resolve.rs:189) and that string
450 // folds into the BLAKE3 closure the lacre keys every
451 // downstream consumer (the substrate's reproducibility
452 // contract, CAIXA-SDLC §III.2 — the lacre is the
453 // build's content-addressed identity, peer of the Nix
454 // store path) against. Until this gate landed an
455 // absolute `:caminho` (`/home/me/work/caixa-teia` — the
456 // canonical "I dragged the folder out of Finder into
457 // my editor" footgun; `/Users/alice/dev/caixa-teia` on
458 // the macOS path-layout peer; the
459 // `${WORKSPACE}/caixa-teia` shell-expanded literal
460 // pasted from a CI manifest) silently passed validate
461 // and the failure surfaced *as a successful build with
462 // a divergent lacre*: the BLAKE3 closure on Alice's
463 // workstation differed from the closure on Bob's
464 // workstation, two CI runners with different
465 // `${HOME}` layouts emitted two distinct
466 // content-addresses for the byte-identical caixa, and
467 // the substrate's "the lacre is the build's identity"
468 // contract silently broke far from the source
469 // caixa.lisp — the most insidious failure mode the
470 // typed slot can carry (no error surfaces; the
471 // divergence is invisible until two machines compare
472 // lacres). The same THEORY.md §V.2 render-determinism
473 // discipline `is_sandboxed_relative_path` already
474 // applies on the M2 typed path-slots
475 // (`:behavior :on-*`, `:upgrade-from :state-change
476 // :script`, `:bibliotecas`, `:exe`, `:servicos`), here
477 // narrowed to the absolute-vs-relative axis only:
478 // `:fonte :caminho`'s canonical author-surface form is
479 // the `..`-traversing sibling-workspace path
480 // (`"../caixa-teia"`, the in-tree dev-dep frame), so a
481 // full `is_sandboxed_relative_path` lift would
482 // structurally reject every legitimate path-fonte
483 // dep. The narrower
484 // `std::path::Path::is_absolute` cut admits the
485 // sibling-workspace form while still rejecting the
486 // host-layout-leaking absolute shape — the
487 // reproducibility contract bites at exactly the
488 // absolute boundary, and that's the axis the
489 // substrate-level invariant is meant to hold. Same
490 // diagnostic shape every per-axis value-shape lift on
491 // the surrounding [`DepError::Fonte*`] cluster carries
492 // (the offending `:nome` + offending `:caminho`
493 // quoted verbatim so the author can grep their
494 // caixa.lisp for the `:caminho "<value>"` literal and
495 // fix it in one edit). The empty arm strictly
496 // precedes this arm so the blank-string footgun
497 // surfaces the more self-locating
498 // `FonteCaminhoEmpty` diagnostic (the empty string
499 // is not absolute under `Path::new("").is_absolute()`
500 // so the precedence is a no-op at value level — the
501 // pin matters only at the diagnostic-shape level if
502 // a future codec round-trip ever produces an empty
503 // string that probes as absolute).
504 if std::path::Path::new(caminho).is_absolute() {
505 return Err(DepError::FonteCaminhoAbsolute {
506 nome: nome.to_string(),
507 caminho: caminho.to_string(),
508 });
509 }
510 // Reproducibility gate's tilde-expansion arm. The b94fd83
511 // `FonteCaminhoAbsolute` closes the leading-`/`
512 // host-layout-leak; a `:caminho "~/work/caixa-teia"` (the
513 // canonical paste-from-shell-prompt / paste-from-`cd ~`-
514 // doc footgun) silently passed both the empty arm and
515 // the absolute arm because `Path::new("~").is_absolute()`
516 // returns `false` — `~` is a shell-expansion convention,
517 // not a POSIX path component, so `std::path::Path` treats
518 // it as a literal directory-name segment. The lacre
519 // pipeline then embedded the value verbatim
520 // (`conteudo: format!("path:~/work/caixa-teia")`) and the
521 // failure mode forked per consumer:
522 //
523 // - The caixa-resolver's `Path` arm folds `:caminho`
524 // through `Path::new(caminho).join(<file>)` without
525 // `~`-expansion, so the build looked for a literal
526 // `./~/work/caixa-teia` subdirectory and failed at
527 // resolve time with a `No such file or directory`
528 // error far from the source caixa.lisp (the lacre
529 // itself, though, was already byte-identical across
530 // machines — every machine emitted the same
531 // `path:~/work/caixa-teia` content-address).
532 // - A future caixa-resolver pass that *does* expand `~`
533 // (the canonical shell-convention idiom every
534 // resolver eventually reaches for once an author
535 // reports the literal-`~`-directory bug) would re-
536 // introduce the host-layout-leak the b94fd83 absolute
537 // gate closes: Alice's `~` expands to `/home/alice`,
538 // Bob's to `/home/bob`, two CI runners with different
539 // `$HOME` layouts resolve to two distinct paths for
540 // the byte-identical caixa, and the substrate's
541 // "the lacre is the build's identity" contract
542 // silently breaks far from the source caixa.lisp.
543 //
544 // Closing the gate at `DepSource::validate` (here at the
545 // canonical caixa-build-time boundary, peer with the
546 // absolute arm above) refuses both failure modes
547 // structurally: the typed accepted set excludes every
548 // `~`-prefixed authoring shape, so the resolver is
549 // free to grow `~`-expansion (or any other convention-
550 // expansion the substrate adopts) without re-opening
551 // the host-layout-leak at the typed boundary. Same
552 // diagnostic shape every per-axis value-shape gate on
553 // the surrounding [`DepError::Fonte*`] cluster carries
554 // (the offending `:nome` + offending `:caminho` quoted
555 // verbatim so the author can grep their caixa.lisp for
556 // the `:caminho "<value>"` literal and fix it in one
557 // edit).
558 //
559 // The cascade preserves narrower-diagnostic-first
560 // ordering: `FonteCaminhoEmpty` → `FonteCaminhoAbsolute`
561 // → `FonteCaminhoTildeExpansion`. The empty arm
562 // structurally precedes both (the bytes "" / "~" don't
563 // overlap), and the absolute arm structurally precedes
564 // the tilde arm (an absolute path can't start with `~`
565 // since absolute paths start with `/`; the bytes "/" /
566 // "~" don't overlap either). Both arms are
567 // value-disjoint, so the precedence is a no-op at value
568 // level — the pin matters only at the diagnostic-shape
569 // level if a future codec round-trip ever produces a
570 // value that probes as both absolute and tilde-prefixed.
571 if caminho.starts_with('~') {
572 return Err(DepError::FonteCaminhoTildeExpansion {
573 nome: nome.to_string(),
574 caminho: caminho.to_string(),
575 });
576 }
577 // Reproducibility gate's shell-variable-expansion arm.
578 // The b94fd83 `FonteCaminhoAbsolute` closes the leading-`/`
579 // host-layout-leak; the a5c248e `FonteCaminhoTildeExpansion`
580 // closes the leading-`~` shell-home-expansion shape; the
581 // leading-`$` is the sibling shell-variable-expansion shape
582 // — same host-layout-leaking semantic, different syntactic
583 // surface. A `:caminho "$HOME/work/caixa-teia"` (the
584 // canonical paste-from-`echo $HOME`-doc footgun) and the
585 // `${VAR}`-braced variant (`"${WORKSPACE}/caixa-teia"` —
586 // the canonical paste-from-CI-manifest footgun every
587 // GitHub Actions / GitLab CI / Drone manifest carries)
588 // silently passed every prior arm because
589 // `Path::is_absolute` returns false on `$` (the `$` is a
590 // shell convention, not a POSIX path component, so
591 // `std::path::Path` treats it as a literal directory-name
592 // segment) and the tilde arm's `starts_with('~')` doesn't
593 // fire.
594 //
595 // Same per-consumer failure-fork the tilde arm closes:
596 //
597 // - The caixa-resolver's `Path` arm folds `:caminho`
598 // through `Path::new(caminho).join(<file>)` without
599 // `$`-expansion, so the build looks for a literal
600 // `./$HOME/work/caixa-teia` subdirectory and fails at
601 // resolve time with a `No such file or directory`
602 // error far from the source caixa.lisp.
603 // - A future caixa-resolver pass that *does* expand
604 // `$VAR` (the shell-convention idiom every resolver
605 // eventually reaches for once an author reports the
606 // literal-`$HOME`-directory bug, especially for CI's
607 // `${WORKSPACE}` idiom) would re-introduce the host-
608 // layout-leak the b94fd83 absolute gate closes:
609 // Alice's `$HOME` expands to `/home/alice`, Bob's to
610 // `/home/bob`, two CI runners with different
611 // `${WORKSPACE}` layouts resolve to two distinct
612 // paths for the byte-identical caixa, and the
613 // substrate's "the lacre is the build's identity"
614 // contract silently breaks far from the source
615 // caixa.lisp.
616 //
617 // Closing the gate at `DepSource::validate` (here at the
618 // canonical caixa-build-time boundary, peer with the
619 // absolute + tilde arms above) refuses both failure modes
620 // structurally. Same diagnostic shape every per-axis
621 // value-shape gate on the surrounding [`DepError::Fonte*`]
622 // cluster carries (the offending `:nome` + offending
623 // `:caminho` quoted verbatim).
624 //
625 // The cascade preserves narrower-diagnostic-first ordering:
626 // `FonteCaminhoEmpty` → `FonteCaminhoAbsolute` →
627 // `FonteCaminhoTildeExpansion` → `FonteCaminhoVarExpansion`.
628 // The empty arm structurally precedes all three subsequent
629 // arms; the absolute arm structurally precedes both the
630 // tilde and the var arms (absolute paths start with `/`,
631 // the bytes `/` / `~` / `$` don't overlap at the leading
632 // position); the tilde arm structurally precedes the var
633 // arm (`~` and `$` don't overlap at the leading position).
634 // Every pair is value-disjoint, so the precedence is a
635 // no-op at value level — the pin matters only at the
636 // diagnostic-shape level if a future codec round-trip ever
637 // produces a probe-as-both value.
638 //
639 // The gate covers every leading-`$` shape: the canonical
640 // `"$HOME/work/caixa-teia"` (POSIX shell), the braced
641 // `"${HOME}/work/caixa-teia"` (POSIX shell braces), the
642 // CI-manifest idiom `"${WORKSPACE}/caixa-teia"` (the
643 // GitHub Actions / GitLab CI / Drone paste footgun), the
644 // XDG idiom `"$XDG_CONFIG_HOME/caixa"`, and the bare `$`
645 // (degenerate "I meant `$HOME` and forgot the rest"). All
646 // shapes route through the same `caminho.starts_with('$')`
647 // byte check.
648 if caminho.starts_with('$') {
649 return Err(DepError::FonteCaminhoVarExpansion {
650 nome: nome.to_string(),
651 caminho: caminho.to_string(),
652 });
653 }
654 // Reproducibility gate's leading-space arm. The b94fd83 / a5c248e /
655 // f4efe9c arms closed the leading-byte host-layout-leak shapes
656 // (`/` / `~` / `$`); the embedded-control-byte arm below closes
657 // every byte in `0x00..=0x1F` plus `0x7F` (which already includes
658 // tab `0x09`, LF `0x0A`, CR `0x0D` — every ASCII whitespace
659 // *except* the ASCII space byte `0x20`). The bare ASCII space at
660 // the leading position is the orthogonal paste-from-aligned-doc
661 // shape that silently passed every prior arm: `Path::is_absolute`
662 // returns false on `" ../caixa-teia"` (the leading byte is `0x20`
663 // not `0x2F`), `0x20` is not `~` / `$` / `\` / a control byte, and
664 // the value's last byte is not `/`, so the canonical
665 // paste-from-aligned-`caixa.lisp`-doc footgun (every `:fonte`
666 // form in a multi-entry `:deps` block sits at the same column —
667 // an author selecting `"<sp><sp><sp>../caixa-teia"` and pasting
668 // it from the rendered alignment into a fresh entry preserves the
669 // leading whitespace verbatim) silently rendered as a path with
670 // a leading-space directory component the resolver folds through
671 // `Path::join` looking for a literal `./ ../caixa-teia`
672 // subdirectory that fails at resolve time with a non-self-
673 // locating `No such file or directory` error.
674 //
675 // The lacre pipeline's reproducibility contract bites
676 // strictly at this byte: `path:" ../caixa-teia"` and
677 // `path:"../caixa-teia"` yield distinct BLAKE3 closures
678 // (`conteudo: format!("path:{caminho}")`,
679 // caixa-resolver/src/resolve.rs:189) for the byte-divergent /
680 // semantic-identical caixa, and the substrate's "the lacre is
681 // the build's identity" contract (CAIXA-SDLC §III.2) silently
682 // breaks across two workstations whose authors differ only in
683 // paste-from-aligned-doc whitespace habits — the most insidious
684 // failure mode the typed slot can carry (no error surfaces; the
685 // divergence is invisible until two machines compare lacres).
686 //
687 // The arm fires AFTER the absolute / tilde / var leading-byte
688 // arms (each names the more self-locating shell-convention
689 // diagnostic on values that probe as that arm's leading-byte
690 // sentinel followed by a leading space — e.g.
691 // `:caminho "/ /foo"` surfaces `FonteCaminhoAbsolute` because
692 // the leading byte is `/`, not space) and BEFORE the
693 // embedded-control-byte arm (a leading-space value with an
694 // embedded control byte surfaces the broader leading-space
695 // diagnostic because the cascade walks leading-byte arms first
696 // — peer with how `FonteCaminhoAbsolute` precedes
697 // `FonteCaminhoControlChar` on `"/etc/passwd\n"`).
698 //
699 // The peer single-token-shaped axes already reject leading
700 // whitespace on the same paste-from-aligned-doc contract:
701 // [`crate::render::is_git_repo_url`] rejects leading whitespace
702 // on `:fonte :repo`, [`crate::render::is_git_ref_name`] rejects
703 // leading whitespace on `:fonte :tag`/`:branch`,
704 // [`crate::render::is_chart_description_shape`] rejects leading
705 // whitespace on `:descricao`,
706 // [`crate::render::is_spdx_expression_shape`] rejects leading
707 // whitespace on `:licenca`. Closing the same byte on
708 // `:fonte :caminho` makes the substrate-wide "no leading ASCII
709 // space anywhere in a typed string slot" invariant structurally
710 // consistent across every value-shape-gated typed surface (the
711 // `:caminho` axis was the last typed string surface still
712 // admitting a leading space byte).
713 if caminho.starts_with(' ') {
714 return Err(DepError::FonteCaminhoLeadingWhitespace {
715 nome: nome.to_string(),
716 caminho: caminho.to_string(),
717 });
718 }
719 // Reproducibility gate's leading-`-` CLI-argument-injection arm.
720 // The b94fd83 + a5c248e + f4efe9c + LeadingWhitespace arms closed
721 // the four prior leading-byte shapes (`/` / `~` / `$` / space);
722 // this arm closes the orthogonal leading-`-` axis on the same
723 // subprocess-argument-boundary the peer `is_git_repo_url` arm
724 // (render.rs:2037, `-upload-pack=…` on `:fonte :repo`) and
725 // `is_git_ref_name` arm (render.rs:1381, 5a28454, `-stable` on
726 // `:fonte :tag` / `:branch`) already reject.
727 //
728 // The lacre pipeline embeds `:caminho` verbatim in its per-dep
729 // content-address (`conteudo: format!("path:{caminho}")`,
730 // caixa-resolver/src/resolve.rs:189) and the resolver folds the
731 // value through `Path::join` looking for a literal `./{caminho}`
732 // subdirectory. Every downstream subprocess that consumes the
733 // resolved path — a `git -C {caminho} <verb>` invocation, a
734 // future `feira tofu` `terraform -chdir={caminho}` shell-out, a
735 // future operator-side `nix build --path {caminho}` spawn, an
736 // `xargs` / `find {caminho}` / `stat {caminho}` /
737 // `rm -rf {caminho}` cleanup — reinterprets a leading-`-` value
738 // as a CLI flag rather than a positional path when the
739 // subprocess invocation does not carry a `--` argument-list
740 // terminator between the flag block and the path argument. The
741 // canonical footguns:
742 //
743 // - `:caminho "-rf"` — bare short-flag paste (`rm -rf` /
744 // `find -rf` reinterpretation; the byte the peer
745 // `FonteCaminhoShellSemicolon` arm's `; rm -rf build`
746 // example paste-idiom carries as its first token).
747 // - `:caminho "-C"` — `git -C` config-injection paste
748 // (`git -C -C` reinterprets the second `-C` as another
749 // `--change-directory` flag rather than the path
750 // argument; the canonical `git -C <path>` porcelain
751 // idiom every multi-repo workspace tool carries).
752 // - `:caminho "--upload-pack=cat /etc/passwd"` — the
753 // canonical long-flag CLI-arg-injection vector at every
754 // git porcelain entry point (`git clone`, `git fetch`,
755 // `git ls-remote`) that consumes a path or URL
756 // argument; peer with `is_git_repo_url`'s leading-`-`
757 // arm (render.rs:2037) on the sibling `:fonte :repo`
758 // axis, which the arm's diagnostic explicitly cites.
759 // - `:caminho "--config=…"` / `:caminho "-c"` — git-config
760 // override paste-idiom (paste-from-`git -c foo=bar`
761 // shell-history footgun that reinterprets the value as
762 // a `[foo] bar` config injection on every git porcelain
763 // entry point).
764 //
765 // POSIX `std::path::Path` treats a leading `-` as a literal
766 // filename byte, so the resolver folds `-rf` through `Path::join`
767 // and looks for a literal `./-rf` subdirectory — the failure
768 // surfaces at resolve time with a non-self-locating `No such
769 // file or directory` error far from the source caixa.lisp, and
770 // the value rides through the lacre content-address into every
771 // downstream shell-spawned subprocess. On any consumer that
772 // shells out without the `--` terminator (the common case at
773 // every porcelain entry-point) the reinterpretation is silent
774 // and the failure mode is arbitrary-argument-injection.
775 //
776 // The arm fires AFTER the absolute / tilde / var / leading-space
777 // leading-byte arms (each names the more self-locating shell-
778 // convention diagnostic on values that probe as that arm's
779 // leading-byte sentinel — the byte sets are pairwise disjoint at
780 // the leading position, so the precedence pin is a no-op at
781 // value level, but the ordering keeps every leading-byte arm's
782 // diagnostic-shape stable) and BEFORE the embedded-control-byte
783 // arm (a leading-`-` value with an embedded control byte
784 // surfaces the narrower leading-`-` diagnostic because the
785 // cascade walks leading-byte arms first — peer with how
786 // `FonteCaminhoAbsolute` precedes `FonteCaminhoControlChar` on
787 // `"/etc/passwd\n"`, and how `FonteCaminhoLeadingWhitespace`
788 // precedes `FonteCaminhoControlChar` on `" ../foo\n"`).
789 //
790 // The peer single-token-shaped axes already reject leading `-`
791 // on the same CLI-arg-injection contract:
792 // [`crate::render::is_git_repo_url`] rejects it on `:fonte :repo`
793 // (render.rs:2037), [`crate::render::is_git_ref_name`] rejects
794 // it on `:fonte :tag` / `:fonte :branch` (render.rs:1381,
795 // 5a28454), [`crate::render::is_dns_1123_label`] rejects it on
796 // every DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros
797 // :caixa`, `:children :caixa`, `:deps :nome`, cluster names),
798 // [`crate::render::is_cargo_feature_name`] rejects it on
799 // `:caracteristicas`, and the feira `init` / `add <nome>`
800 // positional gate (868c191) rejects it on the CLI positional
801 // itself. Closing the same byte on `:fonte :caminho` makes the
802 // substrate-wide "no leading `-` anywhere in a typed single-
803 // token string slot routed through a subprocess argument"
804 // invariant structurally consistent across every value-shape-
805 // gated typed surface (the `:caminho` axis was the last typed
806 // string surface still admitting a leading `-` byte).
807 if caminho.starts_with('-') {
808 return Err(DepError::FonteCaminhoLeadingHyphen {
809 nome: nome.to_string(),
810 caminho: caminho.to_string(),
811 });
812 }
813 // Reproducibility gate's embedded-control-byte arm. The
814 // b94fd83 + a5c248e + f4efe9c arms closed the three
815 // leading-byte host-layout-leak shapes (`/` / `~` / `$`);
816 // this arm closes the orthogonal embedded-control-byte
817 // axis — any ASCII control byte (`0x00..=0x1F` plus
818 // `0x7F` DEL) appearing anywhere in `:caminho`. Same
819 // shape every peer single-token-typed-slot value-shape
820 // predicate the surrounding [`crate::render`] cluster
821 // gates against (the lifted `is_git_repo_url` arm on
822 // `:fonte :repo`, the `is_git_ref_name` arm on
823 // `:tag`/`:branch`, the `is_chart_description_shape` /
824 // `is_chart_maintainer_name_shape` /
825 // `is_chart_keyword_shape` arms on the
826 // Helm-chart-shaped axes); now consistent on the
827 // `:caminho` axis too.
828 //
829 // Until this gate landed any embedded control byte
830 // silently passed validate, the lacre pipeline embedded
831 // the value verbatim in its per-dep content-address
832 // (`conteudo: format!("path:{caminho}")`,
833 // caixa-resolver/src/resolve.rs:189), and the failure
834 // forked per byte and per consumer:
835 //
836 // - NUL (`0x00`) the canonical "POSIX paths cannot
837 // contain a NUL byte" shape: every `std::fs` syscall
838 // routes the path through `CString::new`, which
839 // fails with `NulError` on the first NUL byte; the
840 // build would surface a `NulError` at resolve time
841 // far from the source caixa.lisp.
842 // - LF (`0x0A`) / CR (`0x0D`) the canonical paste-from-
843 // multiline-doc footgun: a `:caminho
844 // "../caixa-teia\nrm -rf /"` value (paste landed mid-
845 // `:caminho` block from a multi-line code-fence)
846 // silently round-trips through `Path::join` but the
847 // embedded newline class is a sibling of the CRLF-at-
848 // subprocess-argument injection vector
849 // `is_git_repo_url` already closes on `:repo`.
850 // - Tab (`0x09`) the canonical paste-from-aligned-table
851 // footgun: the tab is invisible in most editors, and
852 // the lacre embeds the value verbatim so two
853 // paste-from-distinct-tables yield divergent lacres
854 // across host editors that strip vs preserve tabs.
855 // - DEL (`0x7F`) + every other `0x00..=0x1F` byte: the
856 // paste-from-binary-blob shape every peer single-
857 // token-shaped slot rejects under the same
858 // `b < 0x20 || b == 0x7F` predicate.
859 //
860 // Mirrors the cascade discipline every prior `:caminho`
861 // arm establishes: `FonteCaminhoEmpty` →
862 // `FonteCaminhoAbsolute` → `FonteCaminhoTildeExpansion`
863 // → `FonteCaminhoVarExpansion` →
864 // `FonteCaminhoLeadingWhitespace` →
865 // `FonteCaminhoLeadingHyphen` → `FonteCaminhoControlChar`.
866 // The six leading-byte arms structurally precede the
867 // embedded-byte arm because the leading-byte shapes are
868 // the more self-locating diagnostic on values that probe
869 // as both (e.g. `:caminho "/etc/passwd\n"` surfaces the
870 // narrower `FonteCaminhoAbsolute` rather than the broader
871 // embedded-control-byte arm); the precedence pin matters
872 // at the diagnostic-shape level even though the empty /
873 // absolute / tilde / var arms are value-disjoint from a
874 // bare control byte (which would itself be a leading
875 // byte under the empty / absolute / tilde / var arms'
876 // leading-position semantics, but those arms guard the
877 // specific shell-convention characters `/` / `~` / `$`
878 // — a leading `0x01` byte falls through to this arm).
879 for &b in caminho.as_bytes() {
880 if b < 0x20 || b == 0x7F {
881 return Err(DepError::FonteCaminhoControlChar {
882 nome: nome.to_string(),
883 caminho: caminho.to_string(),
884 byte: b,
885 });
886 }
887 }
888 // Reproducibility gate's Windows-path-separator arm. The four
889 // leading-byte arms (`/` / `~` / `$`) and the embedded-
890 // control-byte arm close the host-layout-leaking + paste-from-
891 // multiline-doc shapes; the leading-`\` / embedded-`\` byte is
892 // the orthogonal cross-host-OS-separator shape — same render-
893 // determinism axis, different semantic mechanism. POSIX
894 // [`std::path::Path`] treats `\` (0x5C) as a literal byte
895 // inside a single path component (so `..\caixa-teia` is one
896 // directory named literally `..\caixa-teia`, sibling of `.`
897 // and `..`); Windows [`std::path::Path`] treats `\` as a
898 // primary path separator equal to `/` (so `..\caixa-teia` is
899 // the parent's sibling directory `caixa-teia`). The lacre
900 // pipeline embeds the value verbatim in its per-dep content-
901 // address (`conteudo: format!("path:{caminho}")`, caixa-
902 // resolver/src/resolve.rs:189), so byte-identical caixa.lisp
903 // values resolve to two distinct directories across runner
904 // OSes — the same THEORY.md §V.2 render-determinism contract
905 // the absolute / tilde / var arms protect, here against the
906 // cross-host-OS-separator divergence vector. Even on POSIX-
907 // only resolvers (the canonical pleme-io substrate posture),
908 // a `..\caixa-teia` (the Windows-Explorer "copy as path" /
909 // PowerShell `Get-Location` paste-idiom footgun) silently
910 // passes every prior arm because `Path::is_absolute` returns
911 // false on `..` and `\` is neither a leading-byte sentinel
912 // nor a control byte, then the resolver folds the value
913 // through `Path::new(caminho).join(<file>)` looking for a
914 // literal `./..\caixa-teia` subdirectory and fails at
915 // resolve time with a non-self-locating `No such file or
916 // directory` error far from the source caixa.lisp.
917 //
918 // The peer single-token-shaped axes on the same git-CLI /
919 // path-CLI consumer cluster already reject `\` under the same
920 // Windows-path-leak banner: [`crate::render::is_git_ref_name`]
921 // line 1441 (`"must not contain \\ … the canonical Windows-
922 // path-leak footgun; use / for hierarchical refs"`) gates
923 // `:fonte :tag` / `:fonte :branch` against the same byte,
924 // and [`crate::render::is_gateway_api_http_path`] line 506
925 // includes `\` in the eleven-byte RFC-3986-reserved rejection
926 // set on `:entrada :paths`. Closing the same byte on `:fonte
927 // :caminho` makes the substrate-wide "no Windows path
928 // separator anywhere in a typed string slot" invariant
929 // structurally consistent across every path-shaped typed
930 // surface (the `:caminho` axis was the last typed string
931 // surface still admitting `\`).
932 //
933 // The arm fires AFTER the control-char arm because the
934 // control-char diagnostic is the more self-locating axis on
935 // values that probe as both (`"..\caixa\0teia"` carries both
936 // a `\` and a NUL — NUL is the load-bearing POSIX-syscall-
937 // rejected byte, so `FonteCaminhoControlChar` wins). Same
938 // narrower-diagnostic-first cascade discipline every prior
939 // arm establishes. A pure-`\` value
940 // (`"..\caixa-teia"` with no control bytes) falls through
941 // every prior arm and lands here.
942 for &b in caminho.as_bytes() {
943 if b == b'\\' {
944 return Err(DepError::FonteCaminhoBackslash {
945 nome: nome.to_string(),
946 caminho: caminho.to_string(),
947 });
948 }
949 }
950 // Reproducibility gate's shell-redirection arm. The 3a4e1d7 backslash
951 // arm closes the cross-host-OS-separator vector; `<` (`0x3C`) and `>`
952 // (`0x3E`) are the orthogonal shell-redirection sentinels — same
953 // paste-from-shell-prompt footgun class, different syntactic surface.
954 // POSIX `std::path::Path` treats `<` / `>` as literal bytes inside a
955 // single path component (so `../caixa-teia>output` is one directory
956 // named literally `../caixa-teia>output`, sibling of `.` and `..`),
957 // but every interactive shell (bash / zsh / fish / nushell) lexes
958 // `<` / `>` as input / output redirection operators — a `:caminho
959 // "../caixa-teia>build.log"` (the canonical "I pasted a shell
960 // pipeline that wrote build output and forgot to trim the redirect"
961 // footgun) or `:caminho "../<input.lisp"` (the symmetric input-
962 // redirection paste idiom) silently passes every prior arm because
963 // `Path::is_absolute` returns false, `<` / `>` are neither leading-
964 // byte sentinels nor control bytes nor `\`, and the value's last byte
965 // isn't `/`. The resolver folds the value through
966 // `Path::new(caminho).join(<file>)` looking for a literal
967 // `./..\caixa-teia>build.log` subdirectory and fails at resolve time
968 // with a non-self-locating `No such file or directory` error far
969 // from the source caixa.lisp.
970 //
971 // The lacre pipeline embeds the value verbatim in its per-dep
972 // content-address (`conteudo: format!("path:{caminho}")`,
973 // caixa-resolver/src/resolve.rs:189), so a `<` / `>` byte lands in
974 // the BLAKE3 closure and rides downstream as part of the build's
975 // identity. The bytes carry a second class of hazard the prior
976 // separator-shaped arms don't: every typed-string slot whose value
977 // ever flows verbatim into a shell-spawned subprocess (the caixa-
978 // resolver's `git clone` invocation, a future `feira tofu` shell-
979 // out, a future operator-side `nix flake check` spawn) is the
980 // canonical CRLF-at-subprocess-argument / shell-metachar injection
981 // surface that every peer single-token-shaped typed slot already
982 // closes. The peer path-shaped axis `[crate::render::is_gateway_api_http_path]`
983 // (caixa-core/src/render.rs:506) rejects `<` / `>` as part of its
984 // eleven-byte RFC-3986-reserved set on `:entrada :paths`, and the
985 // peer git-ref-shaped axis `[crate::render::is_git_ref_name]` rejects
986 // `<` / `>` on `:fonte :tag` / `:fonte :branch` under the same
987 // shell-metachar-injection banner. The `:caminho` axis was the last
988 // typed string surface still admitting these two bytes; this arm
989 // closes the gap so the substrate-wide "no shell-redirection
990 // metacharacter anywhere in a typed string slot" invariant is now
991 // structurally consistent across every path-shaped typed surface.
992 //
993 // The arm fires AFTER the control-char arm + backslash arm because
994 // both prior arms carry more self-locating diagnostics on values
995 // that probe as both (`"..\foo<bar"` carries both `\` and `<` — the
996 // cross-OS-separator divergence is the load-bearing axis, so the
997 // backslash arm wins; `"../foo\n<bar"` carries both LF and `<` —
998 // the POSIX-syscall-rejected byte is the load-bearing axis, so the
999 // control-char arm wins). The arm fires BEFORE the trailing-`/` arm
1000 // because the embedded redirection byte is the more semantic-
1001 // locating axis on probe-as-both values (`"../foo</"` ends in `/`
1002 // but the load-bearing diagnostic is the embedded `<` shell-
1003 // redirection — the trailing `/` is the secondary observation, and
1004 // an author who removes the `<` is likely to also tab-strip the
1005 // trailing separator).
1006 for &b in caminho.as_bytes() {
1007 if b == b'<' || b == b'>' {
1008 return Err(DepError::FonteCaminhoShellRedirection {
1009 nome: nome.to_string(),
1010 caminho: caminho.to_string(),
1011 byte: b,
1012 });
1013 }
1014 }
1015 // Reproducibility gate's shell-pipe arm. The e457141 shell-redirection
1016 // arm closes the `<` / `>` input/output redirection sentinels; `|`
1017 // (`0x7C`) is the orthogonal shell-pipe sentinel — same paste-from-
1018 // shell-prompt footgun class, different syntactic surface. POSIX
1019 // `std::path::Path` treats `|` as a literal path-component byte (so
1020 // `../caixa-teia|tee` is one directory named literally
1021 // `../caixa-teia|tee`, sibling of `.` and `..`), but every interactive
1022 // shell (bash / zsh / fish / nushell) lexes `|` as the pipe operator
1023 // — a `:caminho "../caixa-teia | grep foo"` (the canonical "I copied a
1024 // `ls ../caixa-teia | grep` line out of a shell-history block and
1025 // forgot to trim the pipeline tail" footgun) or `:caminho
1026 // "../foo||bar"` (the symmetric "I copied a `cmd-a || cmd-b` short-
1027 // circuit OR line" idiom) silently passes every prior arm because
1028 // `Path::is_absolute` returns false on `..`, `|` is neither a leading-
1029 // byte sentinel nor a control byte nor `\` nor `<` / `>`, and the
1030 // value's last byte isn't `/`. The resolver folds the value through
1031 // `Path::new(caminho).join(<file>)` looking for a literal
1032 // `./../caixa-teia | grep foo` subdirectory and fails at resolve time
1033 // with a non-self-locating `No such file or directory` error far
1034 // from the source caixa.lisp.
1035 //
1036 // The lacre pipeline embeds the value verbatim in its per-dep
1037 // content-address (`conteudo: format!("path:{caminho}")`,
1038 // caixa-resolver/src/resolve.rs:189), so a `|` byte lands in the
1039 // BLAKE3 closure and rides downstream as part of the build's identity
1040 // into every shell-spawned subprocess (the caixa-resolver's `git
1041 // clone` invocation, a future `feira tofu` shell-out, a future
1042 // operator-side `nix flake check` spawn) as the canonical CRLF-at-
1043 // subprocess-argument / shell-metachar injection surface every peer
1044 // single-token-shaped typed slot already closes. The peer path-shaped
1045 // axis [`crate::render::is_gateway_api_http_path`]
1046 // (caixa-core/src/render.rs:506) rejects `|` as part of its eleven-
1047 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1048 // axis was the last typed path-string surface still admitting this
1049 // byte; this arm closes the gap so the substrate-wide "no shell-
1050 // composition metacharacter anywhere in a typed string slot that
1051 // flows verbatim into a shell-spawned subprocess" invariant extends
1052 // from shell-redirection (`<` / `>`) to shell-pipe (`|`) on the
1053 // `:caminho` axis.
1054 //
1055 // The arm fires AFTER the shell-redirection arm because the prior
1056 // arm's two-byte `byte: u8` payload is the more self-locating axis on
1057 // values that probe as both (`"../caixa-teia<input|tee"` carries both
1058 // `<` and `|` — the input-redirection-paste idiom is the load-bearing
1059 // root-cause edit, so `FonteCaminhoShellRedirection` wins; same
1060 // cascade discipline every prior `:caminho` arm establishes). The arm
1061 // fires BEFORE the trailing-`/` arm because the embedded pipe byte is
1062 // the more semantic-locating axis on probe-as-both values
1063 // (`"../foo|tee/"` ends in `/` but the load-bearing diagnostic is the
1064 // embedded `|` shell-pipe — the trailing `/` is the secondary
1065 // observation, and an author who removes the `|` is likely to also
1066 // tab-strip the trailing separator).
1067 for &b in caminho.as_bytes() {
1068 if b == b'|' {
1069 return Err(DepError::FonteCaminhoShellPipe {
1070 nome: nome.to_string(),
1071 caminho: caminho.to_string(),
1072 });
1073 }
1074 }
1075 // Reproducibility gate's shell-command-separator arm. The 124106f
1076 // shell-pipe arm closes the `|` byte; `;` (`0x3B`) is the orthogonal
1077 // shell-command-separator sentinel — same paste-from-shell-prompt
1078 // footgun class, different syntactic surface. POSIX `std::path::Path`
1079 // treats `;` as a literal path-component byte (so
1080 // `../caixa-teia;rm -rf /` is one directory named literally
1081 // `../caixa-teia;rm -rf /`, sibling of `.` and `..`), but every
1082 // interactive shell (bash / zsh / fish / nushell) lexes `;` as the
1083 // sequential-command terminator that fires the next command
1084 // regardless of the prior command's exit status — a `:caminho
1085 // "../caixa-teia; rm -rf build"` (the canonical "I pasted a shell
1086 // one-liner that chained a cleanup tail after the directory name"
1087 // footgun) or `:caminho "../foo;;bar"` (the symmetric "I copied a
1088 // POSIX `case` arm's `;;` terminator into the middle of a path"
1089 // idiom) silently passes every prior arm because `Path::is_absolute`
1090 // returns false on `..`, `;` is neither a leading-byte sentinel nor a
1091 // control byte nor `\` nor `<` / `>` nor `|`, and the value's last
1092 // byte isn't `/`. The resolver folds the value through
1093 // `Path::new(caminho).join(<file>)` looking for a literal
1094 // `./../caixa-teia; rm -rf build` subdirectory and fails at resolve
1095 // time with a non-self-locating `No such file or directory` error far
1096 // from the source caixa.lisp.
1097 //
1098 // The lacre pipeline embeds the value verbatim in its per-dep
1099 // content-address (`conteudo: format!("path:{caminho}")`,
1100 // caixa-resolver/src/resolve.rs:189), so a `;` byte lands in the
1101 // BLAKE3 closure and rides downstream as part of the build's identity
1102 // into every shell-spawned subprocess (the caixa-resolver's `git
1103 // clone` invocation, a future `feira tofu` shell-out, a future
1104 // operator-side `nix flake check` spawn) as the canonical
1105 // shell-metachar injection surface every peer single-token-shaped
1106 // typed slot already closes. The peer path-shaped axis
1107 // [`crate::render::is_gateway_api_http_path`]
1108 // (caixa-core/src/render.rs:506) rejects `;` as part of its eleven-
1109 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1110 // axis was the last typed path-string surface still admitting this
1111 // byte; this arm closes the gap so the substrate-wide "no shell-
1112 // composition metacharacter anywhere in a typed string slot that
1113 // flows verbatim into a shell-spawned subprocess" invariant extends
1114 // from shell-pipe (`|`) to shell-command-separator (`;`) on the
1115 // `:caminho` axis.
1116 //
1117 // The arm fires AFTER the shell-pipe arm because the prior arm's
1118 // canonical-cmd-a-|-cmd-b shape is the more common shell-history
1119 // paste idiom on values that probe as both (`"../caixa-teia | tee;
1120 // rm"` carries both `|` and `;` — the pipeline-tail paste is the
1121 // load-bearing root-cause edit, so `FonteCaminhoShellPipe` wins; same
1122 // cascade discipline every prior `:caminho` arm establishes). The arm
1123 // fires BEFORE the trailing-`/` arm because the embedded
1124 // command-separator byte is the more semantic-locating axis on
1125 // probe-as-both values (`"../foo;rm/"` ends in `/` but the
1126 // load-bearing diagnostic is the embedded `;` shell-command-
1127 // separator — the trailing `/` is the secondary observation, and an
1128 // author who removes the `;` is likely to also tab-strip the trailing
1129 // separator).
1130 for &b in caminho.as_bytes() {
1131 if b == b';' {
1132 return Err(DepError::FonteCaminhoShellSemicolon {
1133 nome: nome.to_string(),
1134 caminho: caminho.to_string(),
1135 });
1136 }
1137 }
1138 // Reproducibility gate's shell-background / logical-AND arm. The
1139 // 05c358e shell-command-separator arm closes the `;` byte; `&`
1140 // (`0x26`) is the orthogonal shell-background / list-AND sentinel
1141 // — same paste-from-shell-prompt footgun class, different
1142 // syntactic surface. POSIX `std::path::Path` treats `&` as a
1143 // literal path-component byte (so `../caixa-teia & sleep 1` is
1144 // one directory named literally `../caixa-teia & sleep 1`,
1145 // sibling of `.` and `..`), but every interactive shell
1146 // (bash / zsh / fish / nushell) lexes `&` two ways:
1147 //
1148 // - Single `&` as the background-task terminator that detaches
1149 // the prior command into the background and returns control
1150 // to the prompt immediately (the canonical `cmd &` idiom
1151 // every long-running pipeline uses);
1152 // - Double `&&` as the logical-AND list operator that fires
1153 // the next command only if the prior command succeeded (the
1154 // canonical `make && make install` idiom every build script
1155 // carries).
1156 //
1157 // A `:caminho "../caixa-teia & sleep 1"` (the canonical "I
1158 // pasted a `cd path & sleep 1` background-launch into the
1159 // `:caminho` slot" footgun) or `:caminho "../caixa-teia && make"`
1160 // (the symmetric "I copied a `cd path && make` build chain"
1161 // idiom) silently passes every prior arm because
1162 // `Path::is_absolute` returns false on `..`, `&` is neither a
1163 // leading-byte sentinel nor a control byte nor `\` nor
1164 // `<` / `>` nor `|` nor `;`, and the value's last byte isn't `/`.
1165 // The resolver folds the value through
1166 // `Path::new(caminho).join(<file>)` looking for a literal
1167 // `./../caixa-teia & sleep 1` subdirectory and fails at resolve
1168 // time with a non-self-locating `No such file or directory`
1169 // error far from the source caixa.lisp.
1170 //
1171 // The lacre pipeline embeds the value verbatim in its per-dep
1172 // content-address (`conteudo: format!("path:{caminho}")`,
1173 // caixa-resolver/src/resolve.rs:189), so an `&` byte lands in
1174 // the BLAKE3 closure and rides downstream as part of the build's
1175 // identity into every shell-spawned subprocess (the
1176 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1177 // shell-out, a future operator-side `nix flake check` spawn) as
1178 // the canonical shell-metachar injection surface every peer
1179 // single-token-shaped typed slot already closes. The peer
1180 // path-shaped axis [`crate::render::is_gateway_api_http_path`]
1181 // (caixa-core/src/render.rs:506) rejects `&` as part of its
1182 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1183 // `:caminho` axis was the last typed path-string surface still
1184 // admitting this byte; this arm closes the gap so the
1185 // substrate-wide "no shell-composition metacharacter anywhere
1186 // in a typed string slot that flows verbatim into a
1187 // shell-spawned subprocess" invariant extends from
1188 // shell-command-separator (`;`) to shell-background /
1189 // logical-AND (`&`) on the `:caminho` axis.
1190 //
1191 // The arm fires AFTER the shell-command-separator arm because
1192 // the prior arm's `cmd-a; cmd-b` shape is the more common
1193 // shell-history paste idiom on values that probe as both
1194 // (`"../caixa-teia; rm & sleep"` carries both `;` and `&` — the
1195 // command-separator-tail paste is the load-bearing root-cause
1196 // edit, so `FonteCaminhoShellSemicolon` wins; same cascade
1197 // discipline every prior `:caminho` arm establishes). The arm
1198 // fires BEFORE the trailing-`/` arm because the embedded
1199 // background / list-AND byte is the more semantic-locating axis
1200 // on probe-as-both values (`"../foo&bar/"` ends in `/` but the
1201 // load-bearing diagnostic is the embedded `&` shell-background
1202 // / logical-AND metachar — the trailing `/` is the secondary
1203 // observation, and an author who removes the `&` is likely to
1204 // also tab-strip the trailing separator).
1205 for &b in caminho.as_bytes() {
1206 if b == b'&' {
1207 return Err(DepError::FonteCaminhoShellBackground {
1208 nome: nome.to_string(),
1209 caminho: caminho.to_string(),
1210 });
1211 }
1212 }
1213 // Reproducibility gate's shell-command-substitution arm. The
1214 // e12e4f3 shell-background / logical-AND arm closes the `&`
1215 // byte; the backtick (`0x60`) is the orthogonal POSIX legacy
1216 // command-substitution sentinel — every POSIX shell (sh /
1217 // bash / zsh / dash / ksh / fish / nushell) lexes the byte as
1218 // the canonical legacy wrapper that runs the enclosed command
1219 // and substitutes its standard-output verbatim into the
1220 // surrounding word (a `whoami` wrapped in backticks expands
1221 // to the current user's name; a `cat /etc/passwd` wrapped in
1222 // backticks expands to the file's contents — the canonical
1223 // CWE-78 shell-command-injection vector every shell-side
1224 // hardening guide enumerates first). POSIX
1225 // `std::path::Path` treats backtick as a literal path-
1226 // component byte (so `../caixa-teia/<backtick>whoami<backtick>`
1227 // is one directory named literally that, sibling of `.` and
1228 // `..`).
1229 //
1230 // A `:caminho "../caixa-teia/<backtick>whoami<backtick>"` (the
1231 // canonical "I pasted a shell one-liner carrying a backticked
1232 // `whoami` command-substitution expansion into the `:caminho`
1233 // slot" footgun) or `:caminho "<backtick>pwd<backtick>/caixa-
1234 // teia"` (the symmetric "I copied a `<backtick>pwd<backtick>/
1235 // path` working-directory expansion") silently passes every
1236 // prior arm because `Path::is_absolute` returns false on
1237 // `..`, the backtick byte is neither a leading-byte sentinel
1238 // (the f4efe9c `FonteCaminhoVarExpansion` arm catches the
1239 // modern `$()` form at leading position only; backtick is
1240 // the orthogonal legacy form) nor a control byte nor `\` nor
1241 // `<` / `>` nor `|` nor `;` nor `&`, and the value's last
1242 // byte isn't `/`. The resolver folds the value through
1243 // `Path::new(caminho).join(<file>)` looking for a literal
1244 // subdirectory whose name embeds the backticked token and
1245 // fails at resolve time with a non-self-locating `No such
1246 // file or directory` error far from the source caixa.lisp.
1247 //
1248 // The lacre pipeline embeds the value verbatim in its per-
1249 // dep content-address (`conteudo: format!("path:{caminho}")`,
1250 // caixa-resolver/src/resolve.rs:189), so a backtick byte
1251 // lands in the BLAKE3 closure and rides downstream as part
1252 // of the build's identity into every shell-spawned
1253 // subprocess (the caixa-resolver's `git clone` invocation, a
1254 // future `feira tofu` shell-out, a future operator-side
1255 // `nix flake check` spawn) as the canonical shell-metachar
1256 // injection surface every peer single-token-shaped typed
1257 // slot already closes. The peer path-shaped axis
1258 // [`crate::render::is_gateway_api_http_path`]
1259 // (caixa-core/src/render.rs:506) rejects backtick as part of
1260 // its eleven-byte RFC-3986-reserved set on `:entrada
1261 // :paths`. The `:caminho` axis was the last typed path-
1262 // string surface still admitting this byte; this arm closes
1263 // the gap so the substrate-wide "no shell-composition
1264 // metacharacter anywhere in a typed string slot that flows
1265 // verbatim into a shell-spawned subprocess" invariant
1266 // extends from shell-background / logical-AND (`&`) to
1267 // shell-command-substitution (backtick) on the `:caminho`
1268 // axis.
1269 //
1270 // The arm fires AFTER the shell-background arm because the
1271 // prior arm's `cmd & sleep` shape is the more common shell-
1272 // history paste idiom on values that probe as both (a
1273 // `"../caixa-teia & <backtick>whoami<backtick>"` carries
1274 // both `&` and a backtick — the background-launch tail is
1275 // the load-bearing root-cause edit, so
1276 // `FonteCaminhoShellBackground` wins; same cascade
1277 // discipline every prior `:caminho` arm establishes). The
1278 // arm fires BEFORE the trailing-`/` arm because the
1279 // embedded command-substitution byte is the more semantic-
1280 // locating axis on probe-as-both values (a
1281 // `"../<backtick>whoami<backtick>/"` ends in `/` but the
1282 // load-bearing diagnostic is the embedded backtick shell-
1283 // command-substitution metachar — the trailing `/` is the
1284 // secondary observation, and an author who removes the
1285 // backtick is likely to also tab-strip the trailing
1286 // separator).
1287 for &b in caminho.as_bytes() {
1288 if b == b'`' {
1289 return Err(DepError::FonteCaminhoShellCommandSubstitution {
1290 nome: nome.to_string(),
1291 caminho: caminho.to_string(),
1292 });
1293 }
1294 }
1295 // Reproducibility gate's shell-glob arm. The c4d62b3 shell-command-
1296 // substitution arm closes the backtick byte; `*` (`0x2A`) and `?`
1297 // (`0x3F`) are the orthogonal POSIX glob-expansion sentinels — same
1298 // paste-from-shell-prompt footgun class, different syntactic surface.
1299 // Every POSIX shell (sh / bash / zsh / dash / ksh / fish / nushell)
1300 // lexes `*` and `?` as pathname-expansion wildcards: `*` matches any
1301 // sequence of characters in a path component (including the empty
1302 // sequence), `?` matches exactly one character. POSIX
1303 // `std::path::Path` treats both bytes as literal path-component bytes
1304 // (so `../caixa-teia/*.lisp` is one directory named literally
1305 // `../caixa-teia/*.lisp`, sibling of `.` and `..`).
1306 //
1307 // A `:caminho "../caixa-teia/*"` (the canonical "I pasted a
1308 // `ls ../caixa-teia/*` shell-listing one-liner into the `:caminho`
1309 // slot" footgun) or `:caminho "../foo?"` (the symmetric "I copied a
1310 // `rm foo?` single-char-wildcard removal idiom") silently passes
1311 // every prior arm because `Path::is_absolute` returns false on `..`,
1312 // `*` / `?` are neither leading-byte sentinels nor control bytes nor
1313 // `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick, and the
1314 // value's last byte isn't `/`. The resolver folds the value through
1315 // `Path::new(caminho).join(<file>)` looking for a literal
1316 // `./../caixa-teia/*` subdirectory and fails at resolve time with a
1317 // non-self-locating `No such file or directory` error far from the
1318 // source caixa.lisp.
1319 //
1320 // The lacre pipeline embeds the value verbatim in its per-dep
1321 // content-address (`conteudo: format!("path:{caminho}")`,
1322 // caixa-resolver/src/resolve.rs:189), so a `*` or `?` byte lands in
1323 // the BLAKE3 closure and rides downstream as part of the build's
1324 // identity into every shell-spawned subprocess (the caixa-resolver's
1325 // `git clone` invocation, a future `feira tofu` shell-out, a future
1326 // operator-side `nix flake check` spawn) as the canonical
1327 // shell-metachar / pathname-expansion surface every peer
1328 // single-token-shaped typed slot already closes. The peer path-shaped
1329 // axis [`crate::render::is_gateway_api_http_path`]
1330 // (caixa-core/src/render.rs:506) rejects `*` and `?` as part of its
1331 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1332 // `:caminho` axis was the last typed path-string surface still
1333 // admitting these two bytes; this arm closes the gap so the
1334 // substrate-wide "no shell-composition / glob-expansion
1335 // metacharacter anywhere in a typed string slot that flows verbatim
1336 // into a shell-spawned subprocess" invariant extends from
1337 // shell-command-substitution (backtick) to glob-expansion
1338 // (`*` / `?`) on the `:caminho` axis.
1339 //
1340 // The arm fires AFTER the backtick arm because the prior arm's
1341 // CWE-78 shell-command-injection vector is the load-bearing
1342 // diagnostic on values that probe as both (a `"../`whoami`/*"`
1343 // carries both backtick and `*` — the command-substitution paste
1344 // is the load-bearing root-cause edit, so
1345 // `FonteCaminhoShellCommandSubstitution` wins; same cascade
1346 // discipline every prior `:caminho` arm establishes). The arm
1347 // fires BEFORE the trailing-`/` arm because the embedded glob
1348 // byte is the more semantic-locating axis on probe-as-both values
1349 // (`"../foo*/"` ends in `/` but the load-bearing diagnostic is the
1350 // embedded `*` glob metachar — the trailing `/` is the secondary
1351 // observation, and an author who removes the `*` is likely to
1352 // also tab-strip the trailing separator).
1353 for &b in caminho.as_bytes() {
1354 if b == b'*' || b == b'?' {
1355 return Err(DepError::FonteCaminhoShellGlob {
1356 nome: nome.to_string(),
1357 caminho: caminho.to_string(),
1358 byte: b,
1359 });
1360 }
1361 }
1362 // Reproducibility gate's shell-subshell-grouping arm. The cf9034b
1363 // shell-glob arm closes the `*` / `?` pathname-expansion sentinels;
1364 // `(` (`0x28`) and `)` (`0x29`) are the orthogonal POSIX subshell-
1365 // grouping sentinels — same paste-from-shell-prompt footgun class,
1366 // different syntactic surface. Every POSIX shell (sh / bash / zsh /
1367 // dash / ksh / fish / nushell) lexes the parenthesis pair as the
1368 // subshell-grouping operator: `(<cmd>)` runs `<cmd>` in a child
1369 // shell with a fresh environment scope (the canonical sandboxing
1370 // idiom every shell-history `(cd <path> && <cmd>)` one-liner uses
1371 // to scope a `cd` to one subshell without disturbing the parent's
1372 // working directory), and `$(<cmd>)` is the modern Bourne
1373 // command-substitution shape the upstream f4efe9c
1374 // `FonteCaminhoVarExpansion` arm closes the leading `$` byte of —
1375 // the closing `)` byte completes that substitution shape and must
1376 // be refused on the same axis (peer with the
1377 // [`crate::render::is_git_repo_url`] 3b99147 arm that closes the
1378 // same byte-pair on the sibling `:fonte :repo` axis under the
1379 // same shell-subshell-grouping + RFC-3986-sub-delims banner).
1380 // POSIX `std::path::Path` treats both bytes as literal path-
1381 // component bytes (so `../caixa-teia/(date)` is one directory
1382 // named literally `../caixa-teia/(date)`, sibling of `.` and
1383 // `..`).
1384 //
1385 // A `:caminho "../caixa-teia/$(date)/build"` (the canonical "I
1386 // pasted a `cd ../caixa-teia/$(date)/build` shell-history one-
1387 // liner whose modern command-substitution expansion lands the
1388 // current date as a subdirectory name" footgun) or `:caminho
1389 // "../(cd foo && pwd)/caixa-teia"` (the symmetric "I copied a
1390 // `(cd foo && pwd)` subshell-grouping working-directory probe
1391 // idiom") silently passes every prior arm because
1392 // `Path::is_absolute` returns false on `..`, `(` / `)` are
1393 // neither leading-byte sentinels nor control bytes nor `\` nor
1394 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` / `?`,
1395 // and the value's last byte isn't `/`. The resolver folds the
1396 // value through `Path::new(caminho).join(<file>)` looking for a
1397 // literal `./../caixa-teia/$(date)/build` subdirectory and fails
1398 // at resolve time with a non-self-locating `No such file or
1399 // directory` error far from the source caixa.lisp.
1400 //
1401 // The lacre pipeline embeds the value verbatim in its per-dep
1402 // content-address (`conteudo: format!("path:{caminho}")`,
1403 // caixa-resolver/src/resolve.rs:189), so a `(` or `)` byte lands
1404 // in the BLAKE3 closure and rides downstream as part of the
1405 // build's identity into every shell-spawned subprocess (the
1406 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1407 // shell-out, a future operator-side `nix flake check` spawn) as
1408 // the canonical shell-metachar / subshell-grouping surface every
1409 // peer single-token-shaped typed slot already closes. The peer
1410 // git-source axis [`crate::render::is_git_repo_url`] (3b99147)
1411 // rejects the same byte pair on `:fonte :repo` under the same
1412 // shell-subshell-grouping / RFC-3986-sub-delims banner. The
1413 // `:caminho` axis was the last typed path-string surface still
1414 // admitting these two bytes;
1415 // this arm closes the gap so the substrate-wide "no shell-
1416 // composition metacharacter anywhere in a typed string slot that
1417 // flows verbatim into a shell-spawned subprocess" invariant
1418 // extends from shell-glob (`*` / `?`) to shell-subshell-grouping
1419 // (`(` / `)`) on the `:caminho` axis. Together with the f4efe9c
1420 // leading-`$` arm, the typed `:caminho` accepted set now
1421 // structurally excludes the entire modern Bourne
1422 // command-substitution surface — leading `$` closes the
1423 // leading byte of every `$(<cmd>)` shape, this arm closes the
1424 // trailing `)` boundary.
1425 //
1426 // The arm fires AFTER the shell-glob arm because the prior arm's
1427 // `*` / `?` pathname-expansion shape is the more common shell-
1428 // history paste idiom on values that probe as both
1429 // (`"../caixa-teia/*(date)"` carries both `*` and `(` — the
1430 // glob-paste-tail is the load-bearing root-cause edit, so
1431 // `FonteCaminhoShellGlob` wins; same cascade discipline every
1432 // prior `:caminho` arm establishes). The arm fires BEFORE the
1433 // trailing-`/` arm because the embedded subshell-grouping byte
1434 // is the more semantic-locating axis on probe-as-both values
1435 // (`"../foo(date)/"` ends in `/` but the load-bearing diagnostic
1436 // is the embedded `(` shell-subshell-grouping metachar — the
1437 // trailing `/` is the secondary observation, and an author who
1438 // removes the `(` is likely to also tab-strip the trailing
1439 // separator).
1440 for &b in caminho.as_bytes() {
1441 if b == b'(' || b == b')' {
1442 return Err(DepError::FonteCaminhoShellSubshellGrouping {
1443 nome: nome.to_string(),
1444 caminho: caminho.to_string(),
1445 byte: b,
1446 });
1447 }
1448 }
1449 // Reproducibility gate's shell-brace-expansion arm. The 0633c91
1450 // shell-subshell-grouping arm closes `(` / `)`; `{` (`0x7b`) and
1451 // `}` (`0x7d`) are the orthogonal shell-brace-expansion /
1452 // URI-Template-placeholder byte pair — same paste-from-shell-
1453 // prompt + paste-from-templated-doc footgun class, different
1454 // syntactic surface. Every POSIX-derived shell that implements
1455 // brace expansion (bash / zsh / ksh / fish; the canonical
1456 // `mkdir -p ../{caixa-teia,caixa-helm,caixa-flux}` /
1457 // `cp file{,.bak}` idiom every shell-history block carries)
1458 // expands `{a,b,c}` to the cross-product of its comma-separated
1459 // members and `{1..10}` to the integer range; RFC 6570 reserves
1460 // the matched pair for URI Template placeholders (the canonical
1461 // `https://{host}/{org}/{repo}` substitution shape every
1462 // OpenAPI / Swagger / Postman / GitHub Octokit client /
1463 // Helm chart-URL fragment / Mustache `{{org}}` doubled-brace
1464 // form carries), and Tera / Jinja2 / Handlebars / Go html/template
1465 // every IaC tool (Helm, Kustomize, Terraform's `${var}` cousin
1466 // shape) emit. POSIX `std::path::Path` treats both bytes as
1467 // literal path-component bytes (so `../{caixa-teia,caixa-helm}`
1468 // is one directory named literally `../{caixa-teia,caixa-helm}`,
1469 // sibling of `.` and `..`).
1470 //
1471 // A `:caminho "../{caixa-teia,caixa-helm}/build"` (the canonical
1472 // "I pasted a `cd ../{caixa-teia,caixa-helm}` shell brace-
1473 // expansion one-liner that fans across two siblings" footgun)
1474 // or `:caminho "../{{org}}/caixa-teia"` (the symmetric "I copied
1475 // a `{{org}}` Mustache / Helm template placeholder out of a
1476 // README quick-start and forgot to substitute") silently passes
1477 // every prior arm because `Path::is_absolute` returns false on
1478 // `..`, `{` / `}` are neither leading-byte sentinels nor control
1479 // bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor
1480 // backtick nor `*` / `?` nor `(` / `)`, and the value's last
1481 // byte isn't `/`. The resolver folds the value through
1482 // `Path::new(caminho).join(<file>)` looking for a literal
1483 // `./../{caixa-teia,caixa-helm}/build` subdirectory and fails
1484 // at resolve time with a non-self-locating `No such file or
1485 // directory` error far from the source caixa.lisp.
1486 //
1487 // The lacre pipeline embeds the value verbatim in its per-dep
1488 // content-address (`conteudo: format!("path:{caminho}")`,
1489 // caixa-resolver/src/resolve.rs:189), so a `{` or `}` byte
1490 // lands in the BLAKE3 closure and rides downstream as part of
1491 // the build's identity into every shell-spawned subprocess
1492 // (the caixa-resolver's `git clone` invocation, a future
1493 // `feira tofu` shell-out, a future operator-side `nix flake
1494 // check` spawn) as the canonical shell-metachar / brace-
1495 // expansion surface every peer single-token-shaped typed
1496 // slot already closes. The peer git-source axis
1497 // [`crate::render::is_git_repo_url`] (42d8f9d — the URI Template
1498 // placeholder arm) rejects the same byte pair on `:fonte :repo`
1499 // under the same RFC-3986-'delims' / RFC-6570-URI-Template /
1500 // shell-brace-expansion banner. The `:caminho` axis was the last
1501 // typed path-string surface still admitting these two bytes;
1502 // this arm closes the gap so the substrate-wide "no shell-
1503 // composition metacharacter anywhere in a typed string slot
1504 // that flows verbatim into a shell-spawned subprocess"
1505 // invariant extends from shell-subshell-grouping (`(` / `)`)
1506 // to shell-brace-expansion (`{` / `}`) on the `:caminho` axis,
1507 // and the typed `:caminho` accepted set now also structurally
1508 // excludes the URI Template / templating-engine placeholder
1509 // surface that would silently round-trip through any
1510 // downstream IaC templating-engine layer.
1511 //
1512 // The arm fires AFTER the shell-subshell-grouping arm because
1513 // the prior arm's `(` / `)` shape is the more semantic-locating
1514 // axis on values that probe as both (`"../{cd foo}(date)"`
1515 // carries both `{` and `(` — the parenthesis-pair is the
1516 // load-bearing modern-Bourne-command-substitution surface the
1517 // prior arm closes; same cascade discipline every prior
1518 // `:caminho` arm establishes). The arm fires BEFORE the
1519 // trailing-`/` arm because the embedded brace-expansion byte
1520 // is the more semantic-locating axis on probe-as-both values
1521 // (`"../{caixa-teia,caixa-helm}/"` ends in `/` but the
1522 // load-bearing diagnostic is the embedded `{` brace-expansion
1523 // metachar — the trailing `/` is the secondary observation,
1524 // and an author who removes the `{` is likely to also tab-
1525 // strip the trailing separator).
1526 for &b in caminho.as_bytes() {
1527 if b == b'{' || b == b'}' {
1528 return Err(DepError::FonteCaminhoShellBraceExpansion {
1529 nome: nome.to_string(),
1530 caminho: caminho.to_string(),
1531 byte: b,
1532 });
1533 }
1534 }
1535 // Reproducibility gate's shell-bracket-expansion arm. The 598b770
1536 // shell-brace-expansion arm closes `{` / `}`; `[` (`0x5b`) and
1537 // `]` (`0x5d`) are the orthogonal POSIX glob-character-class /
1538 // shell-`test`-builtin byte pair — same paste-from-shell-prompt
1539 // footgun class, different syntactic surface. Every POSIX shell
1540 // (sh / bash / zsh / dash / ksh / fish / nushell) lexes the
1541 // bracket pair as the glob character-class operator: `[abc]`
1542 // matches one of `a`, `b`, `c`; `[a-z]` matches any lowercase
1543 // ASCII letter; `[^x]` negates (the canonical
1544 // `ls *.[ch]` C-source-file glob and the `cd ../[a-z]*`
1545 // lowercase-sibling glob every shell-history block carries —
1546 // the orthogonal axis to the cf9034b `*` / `?` shell-glob arm
1547 // closing the unbounded pathname-expansion sentinels). The
1548 // bracket pair additionally carries the POSIX `test` /
1549 // `[` builtin command (`[ -d ../caixa-teia ] && cd ...` —
1550 // the canonical idiom every shell-script conditional uses) and
1551 // bash's `[[ ... ]]` extended-test grammar. Beyond shell, the
1552 // bracket pair is the TOML inline-array delimiter
1553 // (`features = ["a", "b"]` — the canonical paste-from-Cargo-
1554 // manifest cross-idiom-leak vector), the YAML flow-sequence
1555 // delimiter (`paths: [/a, /b]` — the canonical paste-from-
1556 // values.yaml cross-idiom leak), the JSON array delimiter,
1557 // and the POSIX-ERE / PCRE bracket-expression / character-
1558 // class anchor (the canonical paste-from-regex-doc shape).
1559 // POSIX `std::path::Path` treats both bytes as literal path-
1560 // component bytes (so `../[caixa-teia]` is one directory
1561 // named literally `../[caixa-teia]`, sibling of `.` and
1562 // `..`).
1563 //
1564 // A `:caminho "../caixa-[a-z]/build"` (the canonical "I
1565 // pasted a `cd ../caixa-[a-z]/build` glob-character-class
1566 // one-liner that matches every lowercase-sibling-suffix
1567 // sibling directory" footgun), `:caminho "../[caixa-teia]/
1568 // build"` (the symmetric "I pasted a TOML inline-array /
1569 // YAML flow-sequence shape out of an aligned manifest"
1570 // idiom), or `:caminho "../caixa-[ch]"` (the canonical
1571 // `*.[ch]` C-source character-class paste-from-shell-history
1572 // shape) silently passes every prior arm because
1573 // `Path::is_absolute` returns false on `..`, `[` / `]` are
1574 // neither leading-byte sentinels nor control bytes nor `\`
1575 // nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1576 // `*` / `?` nor `(` / `)` nor `{` / `}`, and the value's
1577 // last byte isn't `/`. The resolver folds the value through
1578 // `Path::new(caminho).join(<file>)` looking for a literal
1579 // `./../caixa-[a-z]/build` subdirectory and fails at resolve
1580 // time with a non-self-locating `No such file or directory`
1581 // error far from the source caixa.lisp.
1582 //
1583 // The lacre pipeline embeds the value verbatim in its per-dep
1584 // content-address (`conteudo: format!("path:{caminho}")`,
1585 // caixa-resolver/src/resolve.rs:189), so a `[` or `]` byte
1586 // lands in the BLAKE3 closure and rides downstream as part of
1587 // the build's identity into every shell-spawned subprocess
1588 // (the caixa-resolver's `git clone` invocation, a future
1589 // `feira tofu` shell-out, a future operator-side `nix flake
1590 // check` spawn) as the canonical shell-metachar / glob-
1591 // character-class / TOML-array surface every peer single-
1592 // token-shaped typed slot already closes. The `:caminho` axis
1593 // was the last typed path-string surface still admitting
1594 // these two bytes; this arm closes the gap so the substrate-
1595 // wide "no shell-composition metacharacter anywhere in a
1596 // typed string slot that flows verbatim into a shell-spawned
1597 // subprocess" invariant extends from shell-brace-expansion
1598 // (`{` / `}`) to shell-bracket-expansion (`[` / `]`) on the
1599 // `:caminho` axis. Together with the cf9034b `*` / `?` arm,
1600 // the typed `:caminho` accepted set now structurally excludes
1601 // the entire POSIX pathname-expansion / glob surface —
1602 // unbounded glob (`*` / `?`) AND bounded character-class
1603 // (`[abc]` / `[a-z]`).
1604 //
1605 // The arm fires AFTER the shell-brace-expansion arm because
1606 // the prior arm's `{` / `}` shape is the more semantic-
1607 // locating axis on values that probe as both
1608 // (`"../{a,b}[ch]"` carries both `{` and `[` — the brace-
1609 // expansion fan is the load-bearing root-cause edit, so
1610 // `FonteCaminhoShellBraceExpansion` wins; same cascade
1611 // discipline every prior `:caminho` arm establishes). The arm
1612 // fires BEFORE the trailing-`/` arm because the embedded
1613 // bracket-expansion byte is the more semantic-locating axis
1614 // on probe-as-both values (`"../[a-z]/"` ends in `/` but the
1615 // load-bearing diagnostic is the embedded `[` glob-character-
1616 // class metachar — the trailing `/` is the secondary
1617 // observation, and an author who removes the `[` is likely
1618 // to also tab-strip the trailing separator).
1619 for &b in caminho.as_bytes() {
1620 if b == b'[' || b == b']' {
1621 return Err(DepError::FonteCaminhoShellBracketExpansion {
1622 nome: nome.to_string(),
1623 caminho: caminho.to_string(),
1624 byte: b,
1625 });
1626 }
1627 }
1628 // Reproducibility gate's shell-quote-grouping arm. The 986963b
1629 // shell-bracket-expansion arm closes `[` / `]`; `'` (`0x27`) and
1630 // `"` (`0x22`) are the orthogonal POSIX shell-string-literal
1631 // delimiter pair — same paste-from-shell-prompt footgun class,
1632 // different syntactic surface. Every POSIX shell (sh / bash /
1633 // zsh / dash / ksh / fish / nushell) lexes the pair as the
1634 // string-literal quoting operator: `'…'` is the strong
1635 // (no-expansion) single-quoted string and `"…"` is the weak
1636 // (variable-/command-substitution-preserving) double-quoted
1637 // string — the canonical `cd '../caixa-teia'` shell-history
1638 // idiom every path-with-embedded-whitespace paste block carries,
1639 // and the symmetric `git clone "$REPO"` weak-quoted CI-manifest
1640 // shape. Beyond shell, the two bytes carry the JSON string-literal
1641 // delimiter (`"key": "value"` — the canonical paste-from-JSON-
1642 // config cross-idiom-leak vector), the YAML double-quoted +
1643 // single-quoted flow-scalar delimiters (`path: "../caixa-teia"`
1644 // — the canonical paste-from-values.yaml / paste-from-K8s-YAML-
1645 // manifest cross-idiom leak), the TOML basic + literal string
1646 // delimiters (`path = "../caixa-teia"` — the canonical paste-
1647 // from-Cargo-manifest cross-idiom-leak vector), the tatara-lisp
1648 // string-literal delimiter itself (`(:caminho "../caixa-teia")`
1649 // — the canonical "I copied the entire `:caminho "..."` slot
1650 // rather than just the string body" author-surface footgun),
1651 // and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which
1652 // excludes both bytes from the `unreserved / pct-encoded /
1653 // sub-delims / ":" / "@"` `pchar` production. POSIX
1654 // `std::path::Path` treats both bytes as literal path-component
1655 // bytes (so `../"caixa-teia"` is one directory named literally
1656 // `../"caixa-teia"`, sibling of `.` and `..`).
1657 //
1658 // A `:caminho "'../caixa-teia'"` (the canonical "I pasted a
1659 // `cd '../caixa-teia'` shell-history one-liner whose strong-
1660 // quoting preserved the sibling-workspace path verbatim across
1661 // the whitespace paste boundary" footgun), `:caminho
1662 // "\"../caixa-teia\""` (the symmetric weak-quoted paste-from-
1663 // JSON / paste-from-YAML flow-scalar / paste-from-TOML basic-
1664 // string / paste-from-tatara-lisp string-literal cross-idiom-
1665 // leak shape), or `:caminho "../\"caixa-teia\""` (the embedded-
1666 // quote "I pasted a JSON key-value pair fragment into the
1667 // middle of the path" idiom) silently passes every prior arm
1668 // because `Path::is_absolute` returns false on `..` / `'` /
1669 // `"`, `'` / `"` are neither leading-byte sentinels nor
1670 // control bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&`
1671 // nor backtick nor `*` / `?` nor `(` / `)` nor `{` / `}` nor
1672 // `[` / `]`, and the value's last byte isn't `/`. The resolver
1673 // folds the value through `Path::new(caminho).join(<file>)`
1674 // looking for a literal `./'../caixa-teia'` subdirectory and
1675 // fails at resolve time with a non-self-locating `No such file
1676 // or directory` error far from the source caixa.lisp.
1677 //
1678 // The lacre pipeline embeds the value verbatim in its per-dep
1679 // content-address (`conteudo: format!("path:{caminho}")`,
1680 // caixa-resolver/src/resolve.rs:189), so a `'` or `"` byte
1681 // lands in the BLAKE3 closure and rides downstream as part of
1682 // the build's identity into every shell-spawned subprocess
1683 // (the caixa-resolver's `git clone` invocation, a future
1684 // `feira tofu` shell-out, a future operator-side `nix flake
1685 // check` spawn) as the canonical shell-metachar / string-
1686 // literal-delimiter surface every peer single-token-shaped
1687 // typed slot already closes. The peer `:fonte :repo` axis
1688 // closes both bytes under the same shell-quote-grouping /
1689 // RFC-3986-sub-delims banner (e7a109f `'` shell-single-quote
1690 // + 4267d8b `"` shell-double-quote on `is_git_repo_url`). The
1691 // `:caminho` axis was the last typed path-string surface
1692 // still admitting these two bytes; this arm closes the gap
1693 // so the substrate-wide "no shell-composition metacharacter
1694 // anywhere in a typed string slot that flows verbatim into a
1695 // shell-spawned subprocess" invariant extends from shell-
1696 // bracket-expansion (`[` / `]`) to shell-quote-grouping (`'`
1697 // / `"`) on the `:caminho` axis. Together with the peer
1698 // JSON / YAML / TOML string-literal delimiters closing at
1699 // this arm and the 598b770 `{` / `}` brace-expansion arm
1700 // closing the templating-engine-placeholder boundary, the
1701 // typed `:caminho` accepted set now structurally excludes
1702 // the entire cross-config-DSL string-literal / templating
1703 // paste-from-aligned-manifest cross-idiom-leak surface that
1704 // would silently round-trip through any downstream JSON /
1705 // YAML / TOML / HCL / tatara-lisp parsing layer.
1706 //
1707 // The arm fires AFTER the shell-bracket-expansion arm because
1708 // the prior arm's `[` / `]` shape is the more semantic-
1709 // locating axis on values that probe as both (`"../[a-z]'x'"`
1710 // carries both `[` and `'` — the glob-character-class
1711 // expansion is the load-bearing root-cause edit, so
1712 // `FonteCaminhoShellBracketExpansion` wins; same cascade
1713 // discipline every prior `:caminho` arm establishes). The arm
1714 // fires BEFORE the trailing-`/` arm because the embedded
1715 // quote-grouping byte is the more semantic-locating axis on
1716 // probe-as-both values (`"../'caixa-teia'/"` ends in `/` but
1717 // the load-bearing diagnostic is the embedded `'` shell-
1718 // string-literal metachar — the trailing `/` is the secondary
1719 // observation, and an author who removes the `'` is likely to
1720 // also tab-strip the trailing separator).
1721 for &b in caminho.as_bytes() {
1722 if b == b'\'' || b == b'"' {
1723 return Err(DepError::FonteCaminhoShellQuoteGrouping {
1724 nome: nome.to_string(),
1725 caminho: caminho.to_string(),
1726 byte: b,
1727 });
1728 }
1729 }
1730 // Reproducibility gate's shell-comment / URL-fragment / YAML-comment arm.
1731 // The d14cbc5 shell-quote-grouping arm closes `'` / `"`; `#` (`0x23`) is
1732 // the orthogonal "byte at which four distinct downstream parsers all
1733 // truncate the value at the first occurrence" surface, and no prior arm
1734 // has covered it on the `:caminho` axis. Every POSIX shell (sh / bash /
1735 // zsh / dash / ksh / fish / nushell) lexes an unquoted `#` at the head
1736 // of a word (or after unquoted whitespace) as the comment-lead: from
1737 // that byte to the end of the physical line is a comment discarded
1738 // before command parsing (`cd ../caixa-teia # legacy sibling` — the
1739 // canonical paste-from-shell-history-with-trailing-annotation shape
1740 // every operator-notebook and CI-manifest carries; POSIX.1-2017 §2.3
1741 // Token Recognition step 6). YAML 1.2 §6.6 makes `#` the comment lead
1742 // at any position preceded by whitespace or at line-start (`path:
1743 // ../caixa-teia # pin` — the canonical paste-from-values.yaml /
1744 // paste-from-K8s-manifest cross-idiom-leak shape). tatara-lisp itself
1745 // treats `;` as the comment-lead but a growing number of consumer
1746 // config-DSL layers (HCL, Terraform, Nix flake attributes, .env
1747 // dotenv-style files, gitconfig / .gitignore, ini / TOML) use `#` as
1748 // the comment-lead too — the pair extends the cross-config-DSL
1749 // paste-idiom surface the d14cbc5 quote-grouping arm and the 598b770
1750 // brace-expansion arm already cover on adjacent axes. RFC 3986 §3.5
1751 // reserves `#` as the URL fragment-identifier delimiter (the canonical
1752 // paste-from-browser-address-bar `github.com/foo/bar#readme` /
1753 // `github.com/foo/bar#L42` permalink shape, and the symmetric
1754 // Nix-flake-ref cross-idiom leak `github:foo/bar#packageName` where
1755 // `#` selects a flake output — the same axis the peer
1756 // [`crate::render::is_git_repo_url`] closes on the `:fonte :repo`
1757 // surface at a68f818 with the same downstream-drops-the-tail
1758 // rationale).
1759 //
1760 // POSIX `std::path::Path` treats `#` as a literal path-component byte,
1761 // so a `:caminho "../caixa-teia # legacy sibling"` (the canonical
1762 // paste-from-shell-history-with-trailing-annotation footgun),
1763 // `:caminho "../caixa-teia # pin"` (the symmetric YAML flow-scalar
1764 // paste-with-trailing-comment shape), or `:caminho "../caixa-teia
1765 // #readme"` (the URL fragment paste-from-browser-address-bar shape)
1766 // silently passes every prior arm because `Path::is_absolute` returns
1767 // false on `..`, `#` is neither a leading-byte sentinel nor a control
1768 // byte nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1769 // `*` / `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` / `"`,
1770 // and the value's last byte isn't `/`. The resolver folds the value
1771 // through `Path::new(caminho).join(<file>)` looking for a literal
1772 // subdirectory named `../caixa-teia # legacy sibling` and fails at
1773 // resolve time with a non-self-locating `No such file or directory`
1774 // error far from the source caixa.lisp — while every downstream
1775 // shell / YAML / URL parser silently truncates the value at the `#`
1776 // byte to `../caixa-teia`, so a `feira tofu` shell-out to a
1777 // `cd '{caminho}'` command line and a `nix flake check` invocation on
1778 // an emitted YAML `path:` scalar disagree with the resolver on which
1779 // directory the value names. Two workstations whose downstream
1780 // shell / YAML / URL parsing layers differ in unquoted-`#`
1781 // recognition emit divergent build artifacts for the byte-identical
1782 // caixa.lisp value.
1783 //
1784 // The lacre pipeline embeds the value verbatim in its per-dep
1785 // content-address (`conteudo: format!("path:{caminho}")`,
1786 // caixa-resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1787 // closure and rides downstream as part of the build's identity into
1788 // every shell-spawned subprocess (the caixa-resolver's `git clone`
1789 // invocation, a future `feira tofu` shell-out, a future operator-side
1790 // `nix flake check` spawn) as the canonical shell-metachar /
1791 // comment-lead / URL-fragment-delimiter surface every peer
1792 // single-token-shaped typed slot already closes. The peer `:fonte
1793 // :repo` axis closes the byte under the URL-fragment-identifier
1794 // banner (a68f818 `#` on `is_git_repo_url`); the `:caminho` axis was
1795 // the last typed path-string surface still admitting the byte. This
1796 // arm closes the gap so the substrate-wide "no shell-composition
1797 // metacharacter / comment-lead / URL-fragment-delimiter anywhere in a
1798 // typed string slot that flows verbatim into a shell-spawned
1799 // subprocess or downstream YAML / URL parser" invariant extends from
1800 // shell-quote-grouping (`'` / `"`) to shell-comment / URL-fragment
1801 // (`#`) on the `:caminho` axis. Together with the peer JSON / YAML /
1802 // TOML string-literal delimiters the d14cbc5 quote-grouping arm
1803 // closes and the 598b770 `{` / `}` brace-expansion arm closes on the
1804 // templating-engine-placeholder boundary, the typed `:caminho`
1805 // accepted set now structurally excludes the entire
1806 // paste-with-trailing-annotation / paste-from-URL-permalink /
1807 // paste-from-YAML-comment cross-idiom-leak surface that would
1808 // silently round-trip through any downstream shell / YAML / URL /
1809 // dotenv / gitconfig / HCL parsing layer to a different value than
1810 // the resolver's `Path::join` sees.
1811 //
1812 // The arm fires AFTER the shell-quote-grouping arm because the prior
1813 // arm's `'` / `"` shape is the more semantic-locating axis on values
1814 // that probe as both (`"../'x'#pin"` carries both `'` and `#` — the
1815 // shell-string-literal-delimiter is the load-bearing root-cause edit,
1816 // so `FonteCaminhoShellQuoteGrouping` wins; same cascade discipline
1817 // every prior `:caminho` arm establishes). The arm fires BEFORE the
1818 // trailing-`/` arm because the embedded comment-lead / fragment-
1819 // delimiter byte is the more semantic-locating axis on probe-as-both
1820 // values (`"../caixa-teia#pin/"` ends in `/` but the load-bearing
1821 // diagnostic is the embedded `#` — the trailing `/` is the secondary
1822 // observation, and an author who removes the `#pin` fragment is
1823 // likely to also tab-strip the trailing separator).
1824 for &b in caminho.as_bytes() {
1825 if b == b'#' {
1826 return Err(DepError::FonteCaminhoShellComment {
1827 nome: nome.to_string(),
1828 caminho: caminho.to_string(),
1829 byte: b,
1830 });
1831 }
1832 }
1833 // Reproducibility gate's URL-percent-encoding-escape arm. The 6622063
1834 // shell-comment arm closes the `#` URL-fragment-identifier byte; `%`
1835 // (`0x25`) is the orthogonal RFC 3986 §2.1 URL percent-encoding-escape
1836 // byte — the mandatory encoding mechanism for every byte outside the
1837 // `unreserved` alphanumeric / `-` / `.` / `_` / `~` set, and `%`
1838 // itself must be percent-encoded as `%25` to appear literally inside
1839 // a URL value. The byte carries three distinct render-determinism
1840 // hazards on the `:caminho` axis, no prior arm has covered it, and
1841 // the peer `:fonte :repo` axis (a323db8 `%` on `is_git_repo_url`)
1842 // already closes the same byte under the same URL-percent-encoding
1843 // banner — the `:caminho` axis was the last typed path-string surface
1844 // still admitting the byte.
1845 //
1846 // First, the paste-from-browser-address-bar percent-encoded-space
1847 // footgun: an author copies `../caixa%20teia` out of a URL-encoded
1848 // README hyperlink / a browser address bar / a percent-encoded
1849 // permalink expecting `%20` to decode to a literal space at the
1850 // filesystem layer. POSIX `std::path::Path` treats the byte as a
1851 // literal path-component byte, so `Path::join` looks for a literal
1852 // `./../caixa%20teia` subdirectory and fails at resolve time with a
1853 // non-self-locating `No such file or directory` error far from the
1854 // source caixa.lisp — while the author's mental model was
1855 // `../caixa teia`, the decoded shape. Two authors whose only
1856 // difference is percent-encoding presence resolve to two distinct
1857 // BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`)
1858 // for what they intended as the byte-identical sibling-workspace
1859 // dep. The lacre pipeline embeds the value verbatim in its per-dep
1860 // content-address (`conteudo: format!("path:{caminho}")`,
1861 // caixa-resolver/src/resolve.rs:189), so the divergence rides
1862 // downstream into the BLAKE3 closure and locks the substrate's
1863 // "the lacre is the build's identity" contract (CAIXA-SDLC §III.2)
1864 // to the wrong encoding — the same THEORY.md §V.2 render-
1865 // determinism vector every prior `:caminho` arm protects.
1866 //
1867 // Second, the printf-format-specifier lead footgun: `%` is the C /
1868 // POSIX printf format-directive lead-in (`%s`, `%d`, `%02x`, the
1869 // canonical `printf "path=%s\n" ../caixa-teia` invocation every
1870 // shell-diagnostic one-liner carries) and the printf builtin is
1871 // wired into every POSIX shell (bash / zsh / dash / ksh / busybox
1872 // ash) as the format-string lead. A `:caminho "../caixa-%s-teia"`
1873 // value flowing into any future `feira` verb that shells out with a
1874 // printf-formatted path template silently gets reinterpreted as a
1875 // format-directive rather than a literal byte — the canonical
1876 // CWE-134 format-string-injection vector.
1877 //
1878 // Third, the bash-job-control-specifier lead footgun: bash / zsh /
1879 // ksh reserve `%N` at word-start as the job-control specifier —
1880 // `%1` names "job 1", `%%` names "the current job", `%foo` names
1881 // "the most recent job whose command started with `foo`". A future
1882 // `feira` verb that invokes `kill %1` on a caminho-scoped
1883 // subprocess would silently redirect the signal to a wrong target.
1884 //
1885 // Beyond the three shell-side hazards, `%` is a first-class parser
1886 // byte in three cross-config-DSL layers the substrate's paste-idiom
1887 // surface routinely crosses: YAML 1.2 §6.8.1 lexes `%` at
1888 // line-start as the directive lead (`%YAML 1.2` / `%TAG` — a
1889 // `:caminho "%YAML/1.2/../caixa-teia"` paste from a top-of-doc
1890 // YAML directive block silently trips the YAML directive parser on
1891 // any downstream emitted YAML manifest); Prometheus / Grafana
1892 // template syntax uses `%(var)s` as the substitution lead; and Nix
1893 // interpolation uses `${var}` (not `%`) but Envsubst /
1894 // Kubernetes / OpenShift template layers use `%VAR%` as the
1895 // Windows-shell env-var-reference lead — the paste-from-`.bat` /
1896 // paste-from-PowerShell-`%env:PATH%` cross-idiom leak.
1897 //
1898 // The three malformed-`%HH` classes documented on the peer
1899 // `is_git_repo_url` `%` arm (a323db8) apply here too:
1900 //
1901 // - The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
1902 // where `%` isn't followed by two hex digits) — every WHATWG-
1903 // conformant URL parser rejects the value at parse time per
1904 // RFC 3986 §2.1, but the byte rides into the lacre before
1905 // the resolver subprocess crosses the URL-parser boundary.
1906 // - The over-encoded path-separator shape (`"../caixa%2Fteia"`
1907 // intending the `%2F` as the URL encoding of `/`) locks a
1908 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
1909 // the byte-identical `path:../caixa/teia` form.
1910 // - The double-encoded shape (`"../caixa%2520teia"` — the `%25`
1911 // already itself an encoded `%`, so the intent was likely a
1912 // literal `%20` that survived one round-trip through a
1913 // URL-encoder that shouldn't have run) locks a triply-
1914 // divergent closure across the encoded / once-decoded /
1915 // twice-decoded chain.
1916 //
1917 // POSIX `std::path::Path` treats the byte as a literal path-
1918 // component byte, so a `:caminho "../caixa%20teia"` (the canonical
1919 // paste-from-browser-address-bar percent-encoded-space footgun),
1920 // `:caminho "%YAML/../caixa-teia"` (the symmetric paste-from-YAML-
1921 // directive-block cross-idiom leak), or `:caminho
1922 // "../caixa-%s-teia"` (the printf-format-specifier paste-from-
1923 // shell-diagnostic-one-liner shape) silently passes every prior arm
1924 // because `Path::is_absolute` returns false on `..`, `%` is neither
1925 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
1926 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
1927 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`, and the
1928 // value's last byte isn't `/`. The resolver folds the value through
1929 // `Path::new(caminho).join(<file>)` looking for a literal
1930 // subdirectory named `../caixa%20teia` and fails at resolve time
1931 // with a non-self-locating `No such file or directory` error far
1932 // from the source caixa.lisp — while every downstream URL parser /
1933 // shell printf builtin / YAML directive parser silently
1934 // reinterprets the byte to a different value than the resolver's
1935 // `Path::join` sees. Two workstations whose downstream URL / shell
1936 // / YAML layers differ in `%HH` recognition emit divergent build
1937 // artifacts for the byte-identical caixa.lisp value.
1938 //
1939 // The lacre pipeline embeds the value verbatim in its per-dep
1940 // content-address (`conteudo: format!("path:{caminho}")`, caixa-
1941 // resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1942 // closure and rides into every shell-spawned subprocess (the
1943 // resolver's `git clone`, a future `feira tofu` shell-out, a
1944 // future operator-side `nix flake check` spawn) as the canonical
1945 // URL-percent-encoding-escape / printf-format-specifier / bash-
1946 // job-control-specifier surface every peer single-token-shaped
1947 // typed slot already closes. This arm closes the gap so the
1948 // substrate-wide "no URL-percent-encoding-escape / printf-format-
1949 // specifier / job-control-specifier / YAML-directive-lead byte
1950 // anywhere in a typed string slot that flows verbatim into a
1951 // shell-spawned subprocess or downstream URL / printf / YAML
1952 // parser" invariant extends from shell-comment / URL-fragment
1953 // (`#` — 6622063) to URL-percent-encoding-escape (`%`) on the
1954 // `:caminho` axis.
1955 //
1956 // The arm fires AFTER the shell-comment arm because the prior
1957 // arm's `#` shape is the more semantic-locating axis on values
1958 // that probe as both (`"../caixa%20teia#pin"` carries both `%`
1959 // and `#` — the URL-fragment-identifier is the load-bearing
1960 // downstream-truncation edit, so `FonteCaminhoShellComment` wins;
1961 // same cascade discipline every prior `:caminho` arm establishes).
1962 // The arm fires BEFORE the trailing-`/` arm because the embedded
1963 // percent-encoding-escape byte is the more semantic-locating axis
1964 // on probe-as-both values (`"../caixa%20teia/"` ends in `/` but
1965 // the load-bearing diagnostic is the embedded `%` percent-
1966 // encoding-escape — the trailing `/` is the secondary observation,
1967 // and an author who decodes the `%20` to a literal space is
1968 // likely to also tab-strip the trailing separator).
1969 for &b in caminho.as_bytes() {
1970 if b == b'%' {
1971 return Err(DepError::FonteCaminhoUrlPercentEncoding {
1972 nome: nome.to_string(),
1973 caminho: caminho.to_string(),
1974 byte: b,
1975 });
1976 }
1977 }
1978 // Reproducibility gate's embedded-`$` shell-variable-expansion /
1979 // command-substitution / arithmetic-expansion arm. The f4efe9c
1980 // leading-`$` arm at line 540 routes `caminho.starts_with('$')`
1981 // through `FonteCaminhoVarExpansion` under the leading-byte-
1982 // sentinel host-layout-leak banner (peer with the b94fd83
1983 // absolute / a5c248e tilde leading-byte arms), but the arm
1984 // fires only at position 0 — a `:caminho "../foo$HOME/bar"`
1985 // (embedded `$HOME` in a nested path segment — the canonical
1986 // paste-from-`ls ../foo$HOME/bar`-shell-one-liner footgun where
1987 // an author copies a partially-substituted shell one-liner and
1988 // the leading segment is a literal `../foo` while the mid
1989 // segment carries the un-substituted `$HOME` template), a
1990 // `:caminho "../foo${WORKSPACE}/bar"` (the symmetric braced-CI-
1991 // manifest paste-from-`.gitlab-ci.yml` / paste-from-GitHub-
1992 // Actions-workflow shape), a `:caminho "../foo$(whoami)/bar"`
1993 // (the paste-from-shell-prompt command-substitution idiom), or
1994 // a `:caminho "../foo$((1+2))/bar"` (the arithmetic-expansion
1995 // idiom) silently passes every prior arm because
1996 // `Path::is_absolute` returns false on `..`, `$` is neither a
1997 // leading-byte sentinel (the f4efe9c arm fires only at position
1998 // 0) nor a control byte nor `\` nor `<` / `>` nor `|` nor `;`
1999 // nor `&` nor backtick nor `*` / `?` nor `(` / `)` nor `{` /
2000 // `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%`, and the
2001 // value's last byte isn't `/`. Note that `$(...)` command-
2002 // substitution and `$((...))` arithmetic-expansion each carry
2003 // an embedded `(` byte that the 0633c91 shell-subshell-grouping
2004 // arm catches structurally at the earlier `(` position — but
2005 // an author who reaches for the sh-brace-substitution
2006 // `${VAR}` or the bare `$VAR` shape carries only the `$` byte,
2007 // which no prior arm covers. This arm closes the last
2008 // positional gap on the `$` byte on the `:caminho` axis so
2009 // every position — leading (`FonteCaminhoVarExpansion`) and
2010 // embedded (`FonteCaminhoShellVariableExpansion`) — is
2011 // structurally rejected.
2012 //
2013 // Every POSIX shell (sh / bash / zsh / dash / ksh / busybox
2014 // ash / fish / nushell) lexes `$` as the variable-expansion /
2015 // command-substitution / arithmetic-expansion operator per
2016 // POSIX.1-2017 §2.6 (Word Expansions): `$<name>` (Parameter
2017 // Expansion) expands a named variable, `${<name>}` (Parameter
2018 // Expansion braced form) does the same with an explicit token
2019 // boundary, `$(<cmd>)` (Command Substitution modern form,
2020 // `` `<cmd>` `` legacy form which the c370458 backtick arm
2021 // already closes) runs a subshell and substitutes its stdout,
2022 // and `$((<expr>))` (Arithmetic Expansion) evaluates an
2023 // arithmetic expression. Every form is a host-layout /
2024 // environment-state / shell-subprocess-side-effect leak when
2025 // the byte lands in a value the resolver passes to a shell-
2026 // spawned subprocess. Beyond the POSIX shell layer, `$` is
2027 // the Nix `${var}` string-interpolation lead (the paste-from-
2028 // `flake.nix` / paste-from-`.nix`-attribute cross-idiom leak
2029 // where an author copies `"${pkgs.hello}/bin/hello"` out of a
2030 // nix expression), the Make `$(var)` / `$@` / `$<` automatic-
2031 // variable lead (the paste-from-`Makefile` shape), the
2032 // JavaScript / TypeScript template-literal `${expr}` interp
2033 // lead (the paste-from-JS-template-string idiom in a
2034 // multi-lang-monorepo where a `path` attribute gets copied out
2035 // of a `package.json` script or a Vite config), the envsubst /
2036 // Kubernetes / OpenShift template `${VAR}` interp lead (the
2037 // paste-from-Helm-values / paste-from-K8s-manifest cross-idiom
2038 // leak), the PHP variable lead (`$_GET`, `$_ENV` — the paste-
2039 // from-`.php`-config footgun), the Perl scalar-variable lead
2040 // (`$foo`), the SASS / SCSS variable lead (`$primary-color`),
2041 // and the SQL bind-parameter lead in PostgreSQL / SQLite
2042 // (`$1`, `$2` — the paste-from-`.sql`-migration idiom). The
2043 // cross-idiom paste-footgun surface is broader than any single
2044 // shell layer — `$` is a first-class parser byte in nearly
2045 // every config / templating / build-system DSL the substrate's
2046 // paste-idiom surface routinely crosses. The peer `:fonte
2047 // :repo` axis closes the byte under the shell-variable-
2048 // expansion / URL-sub-delim banner (b9d187c `$` on
2049 // `is_git_repo_url`), the peer `:fonte :tag` / `:fonte :branch`
2050 // axes close `$` as part of `is_git_ref_name`'s printable-
2051 // ASCII-restricted grammar (`git check-ref-format` rejects the
2052 // byte outright), and the peer `:entrada :paths` axis closes
2053 // `$` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-
2054 // reserved set. The `:caminho` axis was the last typed path-
2055 // string surface still admitting `$` at positions other than 0.
2056 //
2057 // POSIX `std::path::Path` treats `$` as a literal path-
2058 // component byte, so `:caminho "../foo$HOME/bar"` silently
2059 // routes through `Path::new(caminho).join(<file>)` looking for
2060 // a literal `./{caminho}` subdirectory that fails at resolve
2061 // time with a non-self-locating `No such file or directory`
2062 // error far from the source caixa.lisp. But every downstream
2063 // shell / envsubst / Nix / Make / K8s-template parser silently
2064 // reinterprets the byte to a different value than the
2065 // resolver's `Path::join` sees — so a `feira tofu` shell-out
2066 // to a `cd '{caminho}'` command line, a `nix flake check`
2067 // invocation on an emitted YAML `path:` scalar folded through
2068 // envsubst, or a `helm template` invocation with a
2069 // `values.yaml` `path: {caminho}` embedded in a `{{`-quoted
2070 // template all disagree with the resolver on which directory
2071 // the value names. Two workstations whose downstream shell /
2072 // envsubst / Nix / Make / K8s-template parsing layers differ
2073 // in `$VAR` recognition (or, worse, expand the byte against
2074 // divergent environments — Alice's `$HOME=/home/alice`, Bob's
2075 // `$HOME=/home/bob`) emit divergent build artifacts for the
2076 // byte-identical caixa.lisp value. Even in the case where the
2077 // resolver strictly does NOT expand `$VAR` (the current
2078 // implementation) the divergence still bites at the lacre-
2079 // identity axis: the lacre pipeline embeds the value verbatim
2080 // in its per-dep content-address (`conteudo:
2081 // format!("path:{caminho}")`, caixa-resolver/src/resolve.rs:189),
2082 // so `path:../foo$HOME/bar` locks a BLAKE3 closure distinct
2083 // from the byte-identical-semantic `path:../foo/home/alice/bar`
2084 // one author would have produced by substituting the literal
2085 // value at author time, defeating the THEORY.md §V.2 render-
2086 // determinism contract on the same axis every prior `:caminho`
2087 // arm protects.
2088 //
2089 // Beyond the render-determinism / host-layout-leak vectors,
2090 // `$` at any position in a value flowing verbatim into a
2091 // shell-spawned subprocess is the canonical CWE-78 shell-
2092 // command-injection surface every peer single-token-shaped
2093 // typed slot already closes. A `:caminho "../foo$(whoami)/bar"`
2094 // that rides into a future `feira tofu` shell-out as `cd
2095 // '../foo$(whoami)/bar'` gets substituted by the shell at
2096 // subprocess-argument-expansion time even inside single quotes
2097 // in fewer positions than one might expect (the substitution
2098 // fires only outside single-quoting per POSIX §2.2.2, but
2099 // eval-style wrappers and `sh -c` layers that route the value
2100 // through re-parsing round-trip the substitution — the same
2101 // vector the c370458 backtick arm closes at the sibling
2102 // command-substitution-legacy-form surface). Every future
2103 // `feira` verb that shells out with a `caminho`-formatted
2104 // subprocess argument silently inherits this substitution
2105 // vector unless the typed slot's accepted set structurally
2106 // excludes the byte.
2107 //
2108 // Frontier inspiration: OTP's `gen_server` return-value grammar
2109 // rejects mid-tuple shell-metachar bytes by construction —
2110 // `{noreply, State}` never carries a raw `$` because the
2111 // Erlang term type system has no notion of "string that gets
2112 // shelled out"; caixa's typed slots inherit the same
2113 // structural discipline (types-are-theorems, the compounding
2114 // mandate's leverage-point-1) by refusing values that would
2115 // silently reinterpret at any downstream layer. Peer with
2116 // Unison's content-addressed code (no ambient environment —
2117 // every reference is a hash, no `$VAR` substitution possible)
2118 // and Pony's capabilities (a path capability that carries a
2119 // `$` would be ill-typed at the reference layer).
2120 //
2121 // The arm fires AFTER the URL-percent-encoding-escape arm (the
2122 // e3558fa `%` arm) because a value carrying both `%` and `$`
2123 // (`"../foo%20$HOME/bar"` — the canonical "I pasted a percent-
2124 // encoded space next to a `$HOME` template") surfaces the
2125 // narrower URL-encoding diagnostic first — the paste-from-
2126 // browser-address-bar shape is the load-bearing self-locating
2127 // edit on every probe-as-both value; same cascade discipline
2128 // every prior `:caminho` arm establishes (a323db8 % before
2129 // this arm, this arm before trailing-`/`). The arm fires
2130 // BEFORE the trailing-`/` arm because the embedded shell-
2131 // variable-expansion byte is the more semantic-locating axis
2132 // on probe-as-both values (`"../foo$HOME/bar/"` ends in `/`
2133 // but the load-bearing diagnostic is the embedded `$` — the
2134 // trailing `/` is the secondary observation, and an author
2135 // who substitutes the `$HOME` template with a literal value is
2136 // likely to also tab-strip the trailing separator).
2137 for &b in caminho.as_bytes() {
2138 if b == b'$' {
2139 return Err(DepError::FonteCaminhoShellVariableExpansion {
2140 nome: nome.to_string(),
2141 caminho: caminho.to_string(),
2142 byte: b,
2143 });
2144 }
2145 }
2146 // Reproducibility gate's shell-history-expansion / RFC-3986-sub-delims
2147 // arm. The immediate-predecessor `$` embedded arm closes the shell-
2148 // variable-expansion / command-substitution byte; `!` (`0x21`) is the
2149 // orthogonal POSIX shell-history-expansion sentinel every interactive
2150 // shell with history enabled (bash / ksh / zsh's `bashcompat` /
2151 // csh / tcsh) lexes as the history-expansion prefix: `!command`
2152 // re-runs the most recent history entry beginning with `command`,
2153 // `!!` re-runs the prior command verbatim, `!$` substitutes the
2154 // last word of the prior command, `!:N` substitutes the Nth word,
2155 // `^old^new` rewrites the prior command's `old` to `new` (the
2156 // canonical set of `set -o histexpand` operators bash's default
2157 // interactive session enables). Beyond the shell-history layer,
2158 // RFC 3986 §2.2 lists `!` in the `sub-delims` set (the URL grammar
2159 // admits the byte inside a path segment, but every WHATWG-conformant
2160 // special-scheme URL parser percent-encodes it inside a query
2161 // component via the 'special-query percent-encode set' the peer
2162 // `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte
2163 // is also the C / C++ / Rust / JavaScript / Python bang-operator
2164 // (logical-negation prefix — the paste-from-source-code idiom where
2165 // an author copies `!path.exists()` out of a Rust snippet and the
2166 // trailing punctuation crosses the string-literal boundary); the
2167 // canonical English-typography emphasis / exclamation mark (the
2168 // paste-from-prose enthusiasm-form idiom where an author writes
2169 // `:caminho "../caixa-teia!"` expecting the substrate to coerce it
2170 // to a kebab-case slug); and the Nix flake-ref import-attribute
2171 // `import ./foo.nix { … }` sibling operator surface.
2172 //
2173 // POSIX `std::path::Path` treats `!` as a literal path-component
2174 // byte, so a `:caminho "../caixa-teia!sudo"` (the canonical paste-
2175 // from-shell-history footgun where the author copies a `cd
2176 // ../caixa-teia && !sudo make install` one-liner from a quick-
2177 // start README and the trailing `!sudo` rides in verbatim as a
2178 // history-expansion reference), a `:caminho "../foo!!/bar"` (the
2179 // `!!` repeat-prior-command paste idiom), a `:caminho
2180 // "../caixa-teia!"` (the English-typography enthusiasm-form
2181 // paste-from-prose footgun), or a `:caminho "../foo!$"` (the
2182 // last-word-substitution shape) silently pass every prior arm
2183 // because `Path::is_absolute` returns false on `..`, `!` is neither
2184 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
2185 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
2186 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%` nor `$`,
2187 // and the value's last byte isn't `/`. The resolver folds the value
2188 // through `Path::new(caminho).join(<file>)` looking for a literal
2189 // `./../caixa-teia!sudo` subdirectory and fails at resolve time
2190 // with a non-self-locating `No such file or directory` error far
2191 // from the source caixa.lisp — while every downstream interactive
2192 // shell with `set -o histexpand` reinterprets the byte as the
2193 // history-expansion prefix, and the failure mode forks per
2194 // consumer: a `feira tofu` shell-out to a `cd '{caminho}'` command
2195 // line executed under `bash -i` (the operator-notebook interactive
2196 // shell) substitutes the `!sudo` reference to the most recent
2197 // history entry starting with `sudo`, silently invoking whatever
2198 // privileged command that entry named.
2199 //
2200 // The lacre pipeline embeds the value verbatim in its per-dep
2201 // content-address (`conteudo: format!("path:{caminho}")`,
2202 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2203 // BLAKE3 closure and rides into every shell-spawned subprocess
2204 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2205 // a future operator-side `nix flake check` spawn) as the
2206 // canonical shell-history-expansion / RFC-3986-sub-delims surface
2207 // every peer single-token-shaped typed slot already closes. The
2208 // peer `:fonte :repo` axis closes the byte under the same shell-
2209 // history-expansion / RFC-3986-sub-delims banner (7d53c68 `!` on
2210 // `is_git_repo_url`); the `:caminho` axis was the last typed
2211 // path-string surface still admitting the byte. This arm closes
2212 // the gap so the substrate-wide "no shell-composition
2213 // metacharacter / history-expansion sentinel anywhere in a typed
2214 // string slot that flows verbatim into a shell-spawned subprocess"
2215 // invariant extends from shell-variable-expansion (`$`) to shell-
2216 // history-expansion (`!`) on the `:caminho` axis. Together with
2217 // the peer c370458 backtick command-substitution-legacy-form arm
2218 // and the b9d187c-`$`-embedded-variable-expansion arm on the
2219 // sibling `:repo` axis, the typed `:caminho` accepted set now
2220 // structurally excludes every byte the POSIX shell §2.6 Word
2221 // Expansions section, §2.3 Token Recognition step 6, and every
2222 // history-expansion / brace-expansion / pathname-expansion /
2223 // parameter-expansion / command-substitution / arithmetic-
2224 // expansion operator lexes as a first-class parser byte.
2225 //
2226 // Frontier inspiration: Unison's content-addressed code (no
2227 // ambient environment — every reference is a hash, no `!<num>`
2228 // history-index substitution possible; the caixa substrate's
2229 // lacre discipline arrives at the same guarantee by refusing
2230 // bytes at manifest-parse time that would reinterpret against
2231 // ambient shell history state); Pony's capabilities (a path
2232 // capability that carries a `!` would be ill-typed at the
2233 // reference layer).
2234 //
2235 // The arm fires AFTER the shell-variable-expansion arm because a
2236 // value carrying both `$` and `!` (`"../foo$HOME/bar!sudo"` — the
2237 // canonical "I pasted a `$HOME`-templated path adjacent to a
2238 // trailing `!sudo` history-expansion") surfaces the narrower
2239 // shell-variable-expansion diagnostic first — the paste-from-CI-
2240 // manifest-with-`$VAR`-template shape is the load-bearing self-
2241 // locating edit on every probe-as-both value; same cascade
2242 // discipline every prior `:caminho` arm establishes. The arm
2243 // fires BEFORE the trailing-`/` arm because the embedded shell-
2244 // history-expansion byte is the more semantic-locating axis on
2245 // probe-as-both values (`"../foo!sudo/"` ends in `/` but the
2246 // load-bearing diagnostic is the embedded `!` — the trailing `/`
2247 // is the secondary observation, and an author who removes the
2248 // `!sudo` history reference is likely to also tab-strip the
2249 // trailing separator).
2250 for &b in caminho.as_bytes() {
2251 if b == b'!' {
2252 return Err(DepError::FonteCaminhoShellHistoryExpansion {
2253 nome: nome.to_string(),
2254 caminho: caminho.to_string(),
2255 byte: b,
2256 });
2257 }
2258 }
2259 // Reproducibility gate's shell-history-substitution / RFC-3986-unwise
2260 // / regex-anchor arm. The immediate-predecessor `!` arm closes the
2261 // POSIX `!command` / `!!` / `!$` history-expansion prefix; `^`
2262 // (`0x5E`) is the paired-operator half of the same bash-reference
2263 // §9.3 histexpand feature — the `^old^new^` "quick substitution"
2264 // form (POSIX bash rewrites the prior command's `old` string to
2265 // `new` and re-executes it, the canonical typo-correction one-
2266 // liner idiom `git clone <bad-url>` → `^bad^good` that pastes the
2267 // trailing substitution fragment verbatim into a `:caminho` value
2268 // when the author trims only the leading `git clone` prefix). The
2269 // peer `:fonte :repo` axis closes the byte under the same
2270 // shell-history-substitution / RFC-3986-unwise banner (49e142f `^`
2271 // on `is_git_repo_url`); the `:caminho` axis was the last typed
2272 // path-string surface still admitting the byte after 6a04767
2273 // landed the `!` arm.
2274 //
2275 // Beyond bash history-substitution, `^` carries five distinct
2276 // downstream-reinterpretation surfaces the typed slot's accepted
2277 // set must structurally exclude:
2278 //
2279 // 1. **RFC 3986 §2 'unwise' set** — the four-byte cross-transport
2280 // layer set (`{`, `}`, `|`, `\`) plus `^` every URL parser is
2281 // required to percent-encode-or-refuse at the wire boundary.
2282 // The WHATWG URL spec's 'fragment percent-encode set' maps
2283 // `^` → `%5E` at the query / fragment component transition;
2284 // libcurl silently percent-encodes the byte on the wire, so a
2285 // `:caminho "../foo^bar"` value the resolver's `Path::join`
2286 // sees as a literal `./../foo^bar` subdirectory diverges from
2287 // the byte-transformed `%5E` shape any downstream `feira tofu`
2288 // curl-invocation or artifact-registry-fetch would emit — the
2289 // canonical wire-boundary divergence vector the peer
2290 // `{`, `}`, `|`, `\` `:caminho` arms already close (
2291 // `FonteCaminhoShellBraceExpansion` at 598b770,
2292 // `FonteCaminhoShellPipe` at the pipe arm,
2293 // `FonteCaminhoBackslash` at the backslash arm).
2294 // 2. **Regex character-class negation prefix `[^abc]`** — the
2295 // canonical paste-from-doc-regex-pipeline footgun where an
2296 // author copies a `grep '[^abc]'` idiom from a docs quick-
2297 // listing and the character-class negation byte rides in
2298 // verbatim.
2299 // 3. **Bitwise XOR operator** in C / C++ / Rust / Python /
2300 // JavaScript / Nix / Go — the paste-from-source-code idiom
2301 // where an author copies an `x ^ y`-shaped expression out of
2302 // a source snippet and the operator crosses the string-
2303 // literal boundary.
2304 // 4. **Windows `cmd.exe` escape metacharacter** — the byte
2305 // escapes the next character in a `cmd.exe` batch context (a
2306 // peer of the backslash arm's Windows-separator-leak vector).
2307 // A `:caminho "..^&whoami"` cross-platform paste-from-batch-
2308 // file footgun reinterprets at every `cmd.exe`-spawned
2309 // subprocess (the resolver's future Windows-runner shell-out,
2310 // the operator's WinRM path, a future PowerShell-embedded
2311 // invocation).
2312 // 5. **LaTeX / Markdown / BibTeX superscript operator** — the
2313 // paste-from-typeset-doc footgun where a mathematical
2314 // superscript notation (`x^2` / `M^T`) leaks from prose.
2315 //
2316 // POSIX `std::path::Path` treats `^` as a literal path-component
2317 // byte, so `:caminho "../foo^bar/baz"` (embedded quick-
2318 // substitution), `:caminho "../foo^"` (trailing history-
2319 // substitution-open shape), `:caminho "../[^a-z]/foo"` (regex-
2320 // negation-prefix paste from a grep pipeline; note the `[` / `]`
2321 // arm at 986963b fires first on this shape), or `:caminho
2322 // "../x^y"` (XOR-expression paste-from-source) all silently pass
2323 // every prior arm (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` /
2324 // backtick / `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'`
2325 // / `"` / `#` / `%` / `$` / `!`) and route through
2326 // `Path::new(caminho).join(<file>)` looking for a literal
2327 // `./{caminho}` subdirectory that fails at resolve time with a
2328 // non-self-locating `No such file or directory` error far from
2329 // the source caixa.lisp — while every downstream shell / curl /
2330 // regex / `cmd.exe` layer reinterprets the byte to its own
2331 // semantic.
2332 //
2333 // The lacre pipeline embeds the value verbatim in its per-dep
2334 // content-address (`conteudo: format!("path:{caminho}")`,
2335 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2336 // BLAKE3 closure and rides into every shell-spawned subprocess
2337 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2338 // a future operator-side `nix flake check` spawn) as the
2339 // canonical shell-history-substitution / RFC-3986-unwise /
2340 // regex-negation surface every peer single-token-shaped typed
2341 // slot already closes. This arm together with the immediate-
2342 // predecessor `!` arm (6a04767) closes the full `set -o
2343 // histexpand` operator surface on the `:caminho` axis — the
2344 // `!command` / `!!` / `!$` prefix form via `!`, the `^old^new^`
2345 // quick-substitution form via `^` — so the substrate-wide "no
2346 // shell-history operator anywhere in a typed string slot that
2347 // flows verbatim into a shell-spawned subprocess" invariant
2348 // extends from the `!` prefix half to the `^` quick-substitution
2349 // half. Every peer bash-history operator now fails at manifest-
2350 // parse time with a self-locating diagnostic naming the offending
2351 // caixa.lisp rather than at resolve-time as a `Path::join`-
2352 // derived `No such file or directory` (harmless but non-self-
2353 // locating) or worse riding into a downstream `bash -i` context
2354 // that reinterprets the byte-pair against ambient history state.
2355 //
2356 // Frontier inspiration: bash reference §9.3 HISTORY EXPANSION
2357 // "Quick substitution. Repeat the previous command, replacing
2358 // string1 with string2." + RFC 3986 §2 'unwise' set
2359 // ("characters that gateways and other transport agents are
2360 // known to sometimes modify") + Pony's capabilities (a path
2361 // capability that carries a `^` would be ill-typed at the
2362 // reference layer, matching the same structural discipline the
2363 // sibling `!` history-expansion arm inherits from Unison's
2364 // content-addressed no-ambient-history discipline).
2365 //
2366 // The arm fires AFTER the shell-history-expansion `!` arm because
2367 // a value carrying both `!` and `^` (`"../foo!sudo^bad^good"` —
2368 // the canonical "I pasted a `!sudo` history-reference next to a
2369 // `^bad^good` quick-substitution") surfaces the narrower prefix-
2370 // form `!` diagnostic first — the `!` form is the load-bearing
2371 // self-locating edit on every probe-as-both value (an author who
2372 // removes the `!sudo` reference is likely to also strip the
2373 // paired `^` substitution fragment); same cascade discipline
2374 // every prior `:caminho` arm establishes. The arm fires BEFORE
2375 // the trailing-`/` arm because the embedded shell-history-
2376 // substitution byte is the more semantic-locating axis on
2377 // probe-as-both values (`"../foo^bar/"` ends in `/` but the
2378 // load-bearing diagnostic is the embedded `^` — the trailing `/`
2379 // is the secondary observation, and an author who removes the
2380 // `^bar` substitution fragment is likely to also tab-strip the
2381 // trailing separator).
2382 for &b in caminho.as_bytes() {
2383 if b == b'^' {
2384 return Err(DepError::FonteCaminhoShellHistorySubstitution {
2385 nome: nome.to_string(),
2386 caminho: caminho.to_string(),
2387 byte: b,
2388 });
2389 }
2390 }
2391 // Reproducibility gate's trailing-`/` arm. The b94fd83 absolute arm
2392 // closes the leading-`/` host-layout-leak; the embedded-control-byte
2393 // arm closes any byte-in-the-`0x00..=0x1F` / `0x7F` range; the
2394 // backslash arm closes the cross-host-OS-separator vector. The
2395 // trailing-`/` is the orthogonal shell-tab-completion-on-a-directory
2396 // footgun — `Path::join("../caixa-teia")` and
2397 // `Path::join("../caixa-teia/")` resolve to the same directory
2398 // (POSIX path-component-walk treats trailing `/` as a no-op for
2399 // directory targets, which `:caminho` always names — the sibling-
2400 // workspace dep root is structurally a directory). The lacre
2401 // pipeline embeds the value verbatim in its per-dep content-address
2402 // (`conteudo: format!("path:{caminho}")`,
2403 // caixa-resolver/src/resolve.rs:189), so byte-identical caixa
2404 // semantic-meaning yields two distinct BLAKE3 closures depending on
2405 // whether the author shell-tab-completed the path (every interactive
2406 // shell appends `/` on tab-completing a directory, idiomatic in
2407 // bash / zsh / fish / nushell), pasted from `pwd` (which on most
2408 // shells emits without trailing `/`, but `realpath -e -m` on a
2409 // directory with trailing `/` preserves it), or copied a Cargo
2410 // `path = "../caixa-teia/"` entry from cross-substrate documentation
2411 // (Cargo accepts both shapes and folds them the same way). Two
2412 // workstations whose authors differ only in tab-completion habits
2413 // emit byte-divergent lacres for the byte-identical-semantic caixa,
2414 // and the substrate's "the lacre is the build's identity" contract
2415 // (CAIXA-SDLC §III.2) silently breaks far from the source caixa.lisp.
2416 //
2417 // Same THEORY.md §V.2 render-determinism axis every prior `:caminho`
2418 // arm protects, here against the trailing-separator divergence
2419 // vector: every typed slot's accepted set excludes byte-divergent
2420 // values that round-trip to the same downstream semantic. The peer
2421 // path-shaped axes already reject trailing separators on the same
2422 // contract: [`crate::render::is_gateway_api_http_path`] gates
2423 // `:entrada :paths` against any non-canonical normalization, and
2424 // [`crate::render::is_sandboxed_relative_path`] gates the M2 typed
2425 // path-slots (`:behavior :on-*`, `:upgrade-from :state-change
2426 // :script`, `:bibliotecas`, `:exe`, `:servicos`) against shapes
2427 // whose canonical form would re-introduce determinism divergence.
2428 //
2429 // The arm fires last in the cascade because every prior arm carries
2430 // a more self-locating diagnostic on values that probe as both
2431 // (e.g. `:caminho "../foo/\0/"` ends in `/` but the load-bearing
2432 // diagnostic is the NUL byte's POSIX-syscall-rejection — the
2433 // control-char arm wins; `:caminho "/etc/passwd/"` ends in `/` but
2434 // the load-bearing diagnostic is the absolute host-layout-leak —
2435 // the absolute arm wins; `:caminho "..\caixa-teia/"` ends in `/`
2436 // but the load-bearing diagnostic is the Windows-separator cross-
2437 // OS divergence — the backslash arm wins). The arm covers every
2438 // shape where the last byte is `/` regardless of length, including
2439 // the degenerate single-`/` (which the absolute arm catches first)
2440 // and the consecutive-`//` (where every prior arm passes on the
2441 // bytes other than the trailing `/`).
2442 if caminho.as_bytes().last() == Some(&b'/') {
2443 return Err(DepError::FonteCaminhoTrailingSlash {
2444 nome: nome.to_string(),
2445 caminho: caminho.to_string(),
2446 });
2447 }
2448 Ok(())
2449 }
2450}
2451
2452impl Dep {
2453 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:nome` scalar
2454 /// accessor every consumer of the dep-graph identity axis keys off —
2455 /// returns the author-declared `:nome` byte-string verbatim as a
2456 /// `&str`, borrowed from the typed slot's own [`String`] storage.
2457 ///
2458 /// The `:deps :nome` / `:deps-dev :nome` slot carries the DNS-1123
2459 /// label that names the target caixa (validated by [`Self::validate`]
2460 /// through the shared [`crate::render::is_dns_1123_label`] predicate,
2461 /// same accept-set the peer caixa-identifier axes carry — top-level
2462 /// [`crate::Caixa::nome`], per-`:membros` [`crate::Membro::nome`],
2463 /// per-`:children` [`crate::supervisor::ChildSpec::nome`]). Every
2464 /// downstream consumer that fans on the dep's name-identity keys off
2465 /// this scalar: the [`crate::Caixa::validate_deps`] per-list
2466 /// [`crate::render::insert_first_seen`] dedup key + the paired
2467 /// [`DepError::DuplicateNome`] carrier the walk raises on collision,
2468 /// the cross-list [`validate_no_self_dep`] parent-name equality gate
2469 /// on both `:deps` and `:deps-dev` traversals, the `caixa-resolver`
2470 /// pipeline's `HashSet<String>` seen-set the closure walker gates
2471 /// requeueing off (`caixa-resolver/src/resolve.rs:55`), the resolver's
2472 /// per-transitive-target requeue path (`resolve.rs:63,66`), the
2473 /// [`crate::DepSource::default_github`]-shaped resolver-side shorthand
2474 /// fill-in that folds `:nome` into the fetched-git-URL (`resolve.rs:147`),
2475 /// every `caixa-resolver` `ResolveError::MissingPath` /
2476 /// `ResolveError::MissingPin` carrier that names the offending dep
2477 /// (`resolve.rs:177,206`), each resolved
2478 /// `caixa-lacre::LacreEntry` `nome:` field the closure hash keys off
2479 /// (`resolve.rs:108,113`), and the peer `feira lock` stub-resolver's
2480 /// `LacreEntry` emitter (`caixa-feira/src/cmd/lock.rs:59,61,64`).
2481 ///
2482 /// Prior to this lift the `.nome` byte-string was read inline at every
2483 /// production site — the [`crate::Caixa::validate_deps`] paired
2484 /// `dep.nome.as_str()` / `dep.nome.clone()` accesses on both `:deps`
2485 /// and `:deps-dev` traversals, the [`validate_no_self_dep`] pair of
2486 /// parent-equality checks, and every caixa-resolver / caixa-feira
2487 /// site enumerated above — open-coded field-accesses that expressed
2488 /// no compile-time link back to the typed slot. A future extension of
2489 /// the `:deps :nome` axis to a richer author surface (a per-scope
2490 /// alias table the resolver folds through the `~/.config/caixa/config.yaml`
2491 /// entry the [`crate::dep::Dep`] docstring already acknowledges, a
2492 /// namespace-qualified rewrite the future M4 lacre-federation layer
2493 /// applies per-cluster, a promotion of the plain [`String`] byte-string
2494 /// to a richer scoped-identifier newtype once cross-registry federation
2495 /// lands) would have had to be threaded through every open-coded copy
2496 /// in lockstep or two consumers would silently disagree on which caixa
2497 /// a given dep resolves to — the [`crate::Caixa::validate_deps`] dedup
2498 /// set treating the name as `"caixa-teia"` while the caixa-resolver
2499 /// closure walker treated it as `"tenant-a/caixa-teia"` would silently
2500 /// split the [`DepError::DuplicateNome`] refusal from the resolver's
2501 /// requeue-suppression seen-set, one build-time diagnostic
2502 /// disagreeing with the run-time closure the substrate's lacre
2503 /// pipeline actually materializes. Lifting the resolution rule to a
2504 /// typed method on the substrate primitive means every downstream
2505 /// consumer of the caixa's per-`:deps` identity surface reaches for
2506 /// exactly one typed dispatch — the resolver's accept-set migrates as
2507 /// a unit on any future axis addition.
2508 ///
2509 /// First accessor on the outer `Dep` type — opens the outer-`Dep`
2510 /// `&str`-return required-scalar projection pattern the sibling
2511 /// per-`Dep` `:versao` future lift folds on. Peer of the sibling
2512 /// per-`:membros` [`crate::Membro::nome`] (4a32abf) /
2513 /// per-`:children` [`crate::supervisor::ChildSpec::nome`] (dfb4a81)
2514 /// / top-level [`crate::Caixa::nome`] (e6b7d97) caixa-identity scalar
2515 /// accessors — same "one typed dispatch on the substrate primitive,
2516 /// thin projections at each consumer" discipline extended onto the
2517 /// third named-caixa-referencing axis (`:deps` / `:deps-dev`), the
2518 /// remaining unlifted caixa-name-referencing accessor family in the
2519 /// substrate. Named `nome()` to match the tatara-lisp author-surface
2520 /// term the field's docstring already reaches for ("Caixa name — must
2521 /// match the target caixa's `:nome`") and the peer caixa-identity
2522 /// accessor family the substrate already carries.
2523 #[must_use]
2524 pub fn nome(&self) -> &str {
2525 self.nome.as_str()
2526 }
2527
2528 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:versao`
2529 /// Cargo-shaped semver-requirement scalar accessor every consumer of
2530 /// the dep-graph version-pin axis keys off — returns the author-
2531 /// declared `:versao` requirement byte-string verbatim as a `&str`,
2532 /// borrowed from the typed slot's own [`String`] storage.
2533 ///
2534 /// The `:deps :versao` / `:deps-dev :versao` slot carries the
2535 /// Cargo-shaped semver requirement string (`"^0.1"`, `"~0.1.2"`,
2536 /// `"0.1.0"`, `"*"`) the shared [`crate::version::parse_requirement`]
2537 /// entry-point consumes — same accept-set the peer requirement-
2538 /// carrying axes carry (per-`:membros`
2539 /// [`crate::Membro::versao_requirement`], per-`:children`
2540 /// [`crate::supervisor::ChildSpec::versao_requirement`]), validated
2541 /// through the shared
2542 /// [`crate::render::require_valid_versao_requirement`] cascade in
2543 /// [`Self::validate`]. Every downstream consumer that fans on the
2544 /// dep's version-pin keys off this scalar: the [`Self::validate`]
2545 /// `require_valid_versao_requirement` gate + the paired
2546 /// [`DepError::VersaoInvalid`] carrier the cascade raises on
2547 /// requirement-shape rejection, the `feira lock` stub-resolver's
2548 /// `format!("{}@{}", dep.nome(), dep.versao_requirement())`
2549 /// `conteudo` hash-input interpolation and the paired
2550 /// `LacreEntry.versao:` `String`-carry fill (`caixa-feira/src/cmd/lock.rs`),
2551 /// and the peer `feira lock` end-to-end fixture in `caixa-feira/tests/feira_e2e.rs`.
2552 ///
2553 /// Prior to this lift the `.versao` byte-string was read inline at
2554 /// every production site — the [`Self::validate`] paired
2555 /// `&self.versao` requirement-gate reference and `self.versao.clone()`
2556 /// error-body carrier, the `caixa-feira/src/cmd/lock.rs` paired
2557 /// `format!("{}@{}", dep.nome(), dep.versao)` `conteudo` interpolation
2558 /// and `versao: dep.versao.clone()` `LacreEntry` fill, and the
2559 /// `caixa-feira/tests/feira_e2e.rs` end-to-end fixture's pair of the
2560 /// same shapes — open-coded field-accesses that expressed no
2561 /// compile-time link back to the typed slot. A future extension of
2562 /// the `:deps :versao` axis to a richer author surface (a per-scope
2563 /// version-lock overlay the resolver folds through the
2564 /// `~/.config/caixa/config.yaml` entry the [`crate::dep::Dep`]
2565 /// docstring already acknowledges, a per-cluster canary-version
2566 /// overlay per MESH-COMPOSITION §III.2, a promotion of the plain
2567 /// [`String`] requirement to a richer parsed-`VersionReq` newtype
2568 /// once cross-registry federation lands) would have had to be
2569 /// threaded through every open-coded copy in lockstep or two
2570 /// consumers would silently disagree on which release constraint a
2571 /// given dep resolves to — the [`Self::validate`] requirement-gate
2572 /// call reading `"^0.1"` while the `feira lock` stub-resolver's
2573 /// `conteudo` hash-input read `"tenant-a-pin/^0.1"` would silently
2574 /// split the [`DepError::VersaoInvalid`] refusal from the lacre's
2575 /// content-addressed hash the substrate's fetch pipeline actually
2576 /// materializes, one build-time diagnostic disagreeing with the
2577 /// run-time closure. Lifting the resolution rule to a typed method
2578 /// on the substrate primitive means every downstream consumer of
2579 /// the caixa's per-`:deps` version-pin surface reaches for exactly
2580 /// one typed dispatch — the resolver's accept-set migrates as a
2581 /// unit on any future axis addition.
2582 ///
2583 /// Second accessor on the outer `Dep` type — folds on the outer-
2584 /// `Dep` `&str`-return required-scalar projection pattern the
2585 /// sibling per-`Dep` [`Self::nome`] (eba2cde) accessor opened. Peer
2586 /// of the per-`:membros` [`crate::Membro::versao_requirement`]
2587 /// (a40b0e3) / per-`:children`
2588 /// [`crate::supervisor::ChildSpec::versao_requirement`] (7844f4e
2589 /// family) member/child version-pin accessors — the three
2590 /// requirement-carrying axes (`Dep::versao_requirement` on the
2591 /// per-caixa dep-graph edge, `Membro::versao_requirement` on the M3
2592 /// Aplicacao side, `ChildSpec::versao_requirement` on the M2
2593 /// Supervisor side) now share one accessor discipline for the
2594 /// shared substrate concept "another caixa referenced by a
2595 /// Cargo-shaped semver requirement". The pair
2596 /// `(nome(), versao_requirement())` jointly projects the
2597 /// `(nome, versao)` field pair every dep-graph consumer that fans
2598 /// on per-dep identity + version pin keys off. Named
2599 /// `versao_requirement()` rather than `versao()` because the field's
2600 /// storage-side `.versao` label is already the author-surface term
2601 /// (`:versao`); the accessor's name carries the semantic role — the
2602 /// semver *requirement* string the shared
2603 /// [`crate::version::parse_requirement`] entry-point consumes — so a
2604 /// raw field access and a typed dispatch read differently at every
2605 /// consumer site. Matches the peer
2606 /// [`crate::Membro::versao_requirement`] /
2607 /// [`crate::supervisor::ChildSpec::versao_requirement`] naming
2608 /// discipline verbatim.
2609 #[must_use]
2610 pub fn versao_requirement(&self) -> &str {
2611 self.versao.as_str()
2612 }
2613
2614 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:fonte`
2615 /// Zig-store-model per-dep source-tuple optional-composite-reference
2616 /// accessor every consumer of the dep-graph fetch-source axis keys
2617 /// off — returns the author-declared `:fonte` typed [`DepSource`]
2618 /// verbatim as an `Option<&DepSource>` borrowed from the typed slot's
2619 /// own `Option<DepSource>` storage, with `None` naming the "author
2620 /// omitted `:fonte`" shorthand every resolver-side default-fill
2621 /// (`caixa-feira/src/cmd/lock.rs`'s stub, `caixa-resolver/src/resolve.rs`'s
2622 /// canonical fetcher, per the [`DepSource::default_github`] fallback
2623 /// the [`Dep::fonte`] field docstring already documents) treats as
2624 /// the "resolve through the configured default host / org
2625 /// (`github:<default-org>/<nome>`)" partition.
2626 ///
2627 /// The `:deps :fonte` / `:deps-dev :fonte` slot carries the two-
2628 /// arm typed [`DepSource`] the `Zig-style git-only store model` the
2629 /// enclosing [`Dep`] docstring names — `DepSource::Git { repo, tag,
2630 /// rev, branch }` for the git-clone arm every published caixa
2631 /// resolves through, `DepSource::Path { caminho }` for the dev-only
2632 /// local-filesystem arm every unpublishable in-tree checkout
2633 /// resolves through. Every downstream consumer that fans on the
2634 /// dep's fetch-source keys off this accessor: [`Self::validate`]'s
2635 /// per-`:fonte` [`DepSource::validate`] delegation (which raises
2636 /// the empty-`:repo` / missing-pin / multiple-pin / empty-`:caminho`
2637 /// diagnostics through the [`DepError::Fonte*`] carrier family
2638 /// naming the offending `Dep::nome`), the caixa-crd conversion
2639 /// crate's `dep_into_ref` two-arm projection into the `CaixaSource`
2640 /// `{repo, git_ref}` pair the K8s-CR side consumes
2641 /// (`caixa-crd/src/conversion.rs`), and — through the paired
2642 /// resolver-side default-fill's `Option::unwrap_or_else` — every
2643 /// `caixa-feira` / `caixa-resolver` fetch site that requires a
2644 /// concrete `DepSource` at run time.
2645 ///
2646 /// Prior to this lift the `.fonte` typed slot was read inline at
2647 /// every production site — the [`Self::validate`]
2648 /// `if let Some(ref fonte) = self.fonte` bracket the per-`:fonte`
2649 /// gate delegates through, the caixa-crd `dep_into_ref`
2650 /// `d.fonte.as_ref().and_then(...)` two-arm `CaixaSource` projector,
2651 /// the resolver-side `caixa-feira/src/cmd/lock.rs` / `caixa-resolver/src/resolve.rs`
2652 /// `dep.fonte.clone().unwrap_or_else(...)` default-fill pair — open-
2653 /// coded field-accesses that expressed no compile-time link back to
2654 /// the typed slot. A future extension of the `:deps :fonte` axis
2655 /// to a richer author surface (a per-scope source-override table
2656 /// the resolver folds through the `~/.config/caixa/config.yaml`
2657 /// entry the [`Dep`] docstring already acknowledges, a per-org
2658 /// mirror-fallback list the future M4 lacre-federation resolver
2659 /// consults ahead of the `default_github` fallback, a promotion of
2660 /// the plain `Option<DepSource>` to a richer
2661 /// `{primary, mirrors, integrity}` triple once cross-registry
2662 /// federation lands, a per-dep `sri:sha256-…` integrity slot the
2663 /// M4 lacre gate binds against ahead of the git-fetch) would have
2664 /// had to be threaded through every open-coded copy in lockstep or
2665 /// two consumers would silently disagree on which fetch source a
2666 /// given dep resolves to — the [`Self::validate`] per-`:fonte`
2667 /// gate reading the author-declared source while the caixa-crd
2668 /// projector read a per-scope-override-resolved source would
2669 /// silently split the build-time refusal from the CR the
2670 /// substrate's admission pipeline actually materializes, one
2671 /// build-time diagnostic disagreeing with the run-time closure.
2672 /// Lifting the resolution rule to a typed method on the substrate
2673 /// primitive means every downstream consumer of the caixa's per-
2674 /// `:deps` fetch-source surface reaches for exactly one typed
2675 /// dispatch — the resolver's accept-set migrates as a unit on any
2676 /// future axis addition.
2677 ///
2678 /// First outer-`Dep` `Option<&Composite>`-return composite-reference
2679 /// accessor — opens the outer-`Dep` `Option<&Composite>` composite-
2680 /// reference projection pattern the sibling per-`Dep` `:opcional`
2681 /// (`Option<Copy>` — the plain-bool axis) / `:caracteristicas`
2682 /// (`&[String]` — the feature-flag list) future outer scalar / slice
2683 /// lifts fold on. Peer of the outer-top-level [`crate::Caixa`]
2684 /// `Option<&Composite>` composite-reference sub-family the
2685 /// [`crate::Caixa::limits`] (b2bd9d7) / [`crate::Caixa::behavior`]
2686 /// (35d8b52) / [`crate::Caixa::politicas`] (5d23d29) /
2687 /// [`crate::Caixa::placement`] (4fb8074) / [`crate::Caixa::entrada`]
2688 /// (e4128e4) accessors already close on the outer [`crate::Caixa`]
2689 /// altitude, and of the outer M3 mesh-slot [`crate::AplicacaoSpec`]
2690 /// altitude the sibling [`crate::AplicacaoSpec::entrada`] (d32111c)
2691 /// accessor already carries — extends that "one typed dispatch on
2692 /// the substrate primitive, thin projections at each consumer"
2693 /// discipline onto the third outer typed-slot altitude that carries
2694 /// an `Option<Composite>` axis (`Dep`, the outer per-dep-list-entry
2695 /// slot). Returns `Option<&DepSource>` (not the owning composite by
2696 /// copy or clone) because every downstream consumer of the fonte
2697 /// composite treats it as a read-only per-arm dispatch source — the
2698 /// reference-view is the narrowest borrow that supports every
2699 /// present + roadmapped consumer (per-arm match projection at the
2700 /// caixa-crd `CaixaSource` two-arm emitter, presence-probe early
2701 /// return on the "author-omitted `:fonte` ⇒ resolver-side
2702 /// `default_github` fill applies" partition every resolver
2703 /// consults, `.cloned()`-on-demand for the two resolver-side
2704 /// default-fill call sites that require an owned `DepSource` for
2705 /// `Option::unwrap_or_else`) without cloning the composite through
2706 /// every consumer's fast path. The `Option` half of the return-type
2707 /// preserves the load-bearing "author-omitted `:fonte` ⇒ resolver-
2708 /// side default applies" partition (not a default composite the
2709 /// downstream must reject on emptiness) — the accessor projects the
2710 /// raw `Option<DepSource>` slot's presence bit through the
2711 /// reference-return unchanged. Named `fonte()` to match the storage
2712 /// field's name verbatim and the tatara-lisp author-surface term
2713 /// (`:fonte`) the field's own docstring already carries.
2714 #[must_use]
2715 pub fn fonte(&self) -> Option<&DepSource> {
2716 self.fonte.as_ref()
2717 }
2718
2719 /// Substrate-canonical per-`:deps` / `:deps-dev` entry
2720 /// `:caracteristicas` Cargo-shaped feature-toggle-set slice accessor
2721 /// every consumer of the dep-graph feature-flag axis keys off —
2722 /// returns the author-declared `:caracteristicas` feature-name list
2723 /// verbatim as a `&[String]` slice-view over the same backing buffer
2724 /// the raw `self.caracteristicas.as_slice()` field access borrows
2725 /// from. Empty-list-carrying (`:caracteristicas` is a default-empty
2726 /// axis every `Dep` supplies with `Vec::new()` when the author omits
2727 /// the slot; the [`crate::Caixa::from_lisp`] derive folds an omitted
2728 /// `:caracteristicas` through `#[serde(default)]` to `Vec::new()`,
2729 /// so a `Dep` past parse definitionally carries a `Vec<String>` slot
2730 /// — possibly empty — and the returned `&[String]` degenerates to
2731 /// an empty slice on that arm without any silent `None` collapse).
2732 ///
2733 /// The `:deps :caracteristicas` / `:deps-dev :caracteristicas` slot
2734 /// carries the set-shaped feature-toggle list the substrate walks
2735 /// through the [`Self::validate_caracteristicas`] per-entry shape +
2736 /// duplicate cascade — same Cargo `[dependencies.<dep>.features]`
2737 /// accept-set (per-entry Cargo-feature-name grammar via the shared
2738 /// [`crate::render::is_cargo_feature_name`] predicate, cross-entry
2739 /// uniqueness via the shared [`crate::render::insert_first_seen`]
2740 /// walk, empty-first / value-shape-second / duplicate-third
2741 /// precedence via the peer per-axis two-arm cascade discipline every
2742 /// substrate-blessed Vec-keyed-by-name slot already follows).
2743 /// Every downstream consumer that fans on the dep's feature-toggle
2744 /// keys off this accessor: [`Self::validate_caracteristicas`]'s
2745 /// per-entry linear walk that gates each feature-name byte-string
2746 /// through the empty / value-shape / duplicate arms (raising the
2747 /// [`DepError::CaracteristicaEmpty`] / [`DepError::CaracteristicaInvalid`]
2748 /// / [`DepError::CaracteristicaDuplicate`] carrier family naming the
2749 /// offending `Dep::nome`), and every future
2750 /// per-`Caixa`-manifest / caixa-resolver / caixa-crd feature-toggle-
2751 /// facing consumer the CAIXA-SDLC §I roadmap acknowledges (the
2752 /// future caixa-resolver per-dep feature-projection walk that folds
2753 /// the toggle set into the resolved [`crate::Caixa`]'s activated
2754 /// [`crate::render::CARGO_FEATURE_NAME_MAX_LEN`]-bounded feature
2755 /// closure ahead of the lacre hash, the future caixa-crd per-`spec.deps`
2756 /// features slice the K8s-CR admission gate consumes, the future
2757 /// per-cluster feature-overlay the M4 lacre-federation resolver
2758 /// composes ahead of the substrate-wide feature-name accept-set).
2759 ///
2760 /// Prior to this lift the `.caracteristicas` byte-string list was
2761 /// read inline at the [`Self::validate_caracteristicas`] `for c in
2762 /// &self.caracteristicas` walk — the only in-crate consumer of the
2763 /// raw field beyond the per-`Dep` constructor pair
2764 /// ([`Self::simple`] / [`Self::git`]) and the paired serde
2765 /// round-trip / per-test fixture-mutation paths — an open-coded
2766 /// field-access that expressed no compile-time link back to the
2767 /// typed slot. A future extension of the `:caracteristicas` axis to
2768 /// a richer author surface (a per-scope feature-overlay the resolver
2769 /// folds through the `~/.config/caixa/config.yaml` entry the
2770 /// [`Dep`] docstring already acknowledges, a per-cluster feature-
2771 /// activation overlay the future M4 lacre-federation layer applies
2772 /// per-CR, a promotion of the plain `Vec<String>` byte-string list
2773 /// to a richer parsed-feature-set newtype once the Cargo-shaped
2774 /// namespaced-dep `dep/feat` syntax the value-shape gate's
2775 /// docstring anticipates lands) would have had to be threaded
2776 /// through every open-coded copy in lockstep or two consumers
2777 /// would silently disagree on which feature closure a given dep
2778 /// activates — the [`Self::validate_caracteristicas`] gate walking
2779 /// the author-declared list while a downstream caixa-resolver
2780 /// consumer walked a per-scope-override-resolved list would
2781 /// silently split the build-time refusal from the lacre closure
2782 /// the substrate's fetch pipeline actually materializes, one
2783 /// build-time diagnostic disagreeing with the run-time closure.
2784 /// Lifting the resolution rule to a typed method on the substrate
2785 /// primitive means every downstream consumer of the caixa's per-
2786 /// `:deps` feature-toggle surface reaches for exactly one typed
2787 /// dispatch — the resolver's accept-set migrates as a unit on any
2788 /// future axis addition.
2789 ///
2790 /// First outer-`Dep` `&[T]`-return slice accessor — opens the
2791 /// outer-`Dep` `&[String]` slice projection pattern the sibling
2792 /// per-`Dep` `:opcional` (`bool` — the plain-`Copy`-scalar axis)
2793 /// future outer scalar lift folds on and closes the outer-`Dep`
2794 /// slot-family the sibling [`Self::nome`] (eba2cde) /
2795 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2796 /// accessors already open, leaving the `:opcional` `Copy`-scalar arm
2797 /// as the sole remaining unlifted outer-`Dep` slot. Peer of the
2798 /// outer top-level [`crate::Caixa`] `&[String]`-return foreign-code-
2799 /// slot sub-family ([`crate::Caixa::bibliotecas`] 8a36c23,
2800 /// [`crate::Caixa::exe`] 65d9527, [`crate::Caixa::servicos`]
2801 /// 611f78b) and the outer top-level [`crate::Caixa`] universal-axis
2802 /// text-tag family ([`crate::Caixa::autores`] b5d813f,
2803 /// [`crate::Caixa::etiquetas`] 78c7d3c) that already carry the
2804 /// `&[String]` slice-projection discipline on the outer-`Caixa`
2805 /// altitude — extends the "one typed dispatch on the substrate
2806 /// primitive, thin projections at each consumer" discipline onto the
2807 /// outer per-dep-list-entry [`Dep`] altitude's set-shaped byte-
2808 /// string list slot. Returns `&[String]` (not `&Vec<String>`)
2809 /// because every downstream consumer of the feature-toggle list
2810 /// treats it as a read-only sequence — the slice-view is the
2811 /// narrowest borrow that supports every present + roadmapped
2812 /// consumer (`.iter()`, `.len()`, `.is_empty()`) without leaking
2813 /// the backing `Vec`'s grow/push/reserve surface no consumer of
2814 /// the typed view reaches for (the storage-side `Vec` remains
2815 /// reachable through the `pub caracteristicas` field for the
2816 /// mutation-carrying serde round-trip and per-test fixture-mutation
2817 /// paths). Named `caracteristicas()` to match the storage field's
2818 /// name verbatim and the tatara-lisp author-surface term
2819 /// (`:caracteristicas`) the field's own docstring already carries.
2820 #[must_use]
2821 pub fn caracteristicas(&self) -> &[String] {
2822 self.caracteristicas.as_slice()
2823 }
2824
2825 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:opcional`
2826 /// missing-source-tolerance flag scalar accessor every consumer of
2827 /// the dep-graph opt-in-fetch axis keys off — returns the author-
2828 /// declared `:opcional` `bool` verbatim, `Copy`-projected from the
2829 /// typed slot's own `bool` storage (no borrow of `&self` past the
2830 /// call; the `Copy`-return arm matches the peer
2831 /// [`crate::Caixa::max_restarts`] (eba5211) `Option<u32>` `Copy`-
2832 /// projected sibling discipline the outer flat-spread family
2833 /// already carries). Default-`false` (`#[serde(default,
2834 /// skip_serializing_if = "is_false")]` on the storage slot, so a
2835 /// `Dep` past parse definitionally carries a `bool` — `false` when
2836 /// the author omits `:opcional` — and the returned value degenerates
2837 /// to `false` on that arm without any silent `None` collapse).
2838 ///
2839 /// The `:deps :opcional` / `:deps-dev :opcional` slot carries the
2840 /// per-entry "if this dep's `:fonte` cannot be resolved, treat the
2841 /// missing-source arm as a soft-fail rather than a build refusal"
2842 /// bit — the same Cargo-shaped `[dependencies.<dep>.optional = true]`
2843 /// accept-set (an opcional dep whose `:fonte` fails to resolve is
2844 /// dropped from the resolved dep-graph rather than tripping the
2845 /// build-refusal edge that a mandatory `:opcional false` entry
2846 /// would). Every downstream consumer that fans on the dep's
2847 /// missing-source-tolerance keys off this accessor: the future
2848 /// caixa-resolver's per-`:fonte` resolve-fail arm (drop-vs-error
2849 /// dispatch on the opcional bit ahead of the lacre closure
2850 /// materialization), the future caixa-crd per-`spec.deps`
2851 /// `optional` boolean the K8s-CR admission gate consumes on the
2852 /// per-dep partition, and the future feira / caixa-resolver /
2853 /// caixa-crd feature-projection walk that folds the opcional bit
2854 /// into the resolved feature-closure the future M4 lacre-federation
2855 /// layer emits.
2856 ///
2857 /// Prior to this lift the `.opcional` `bool` slot was read inline
2858 /// at the sole in-crate consumer site — the tests-module
2859 /// `registry_dep_is_minimal` fixture's `assert!(!d.opcional)` gate
2860 /// pinning the [`Self::simple`] constructor's default-`false` fill
2861 /// (the only in-crate read of the raw field beyond the per-`Dep`
2862 /// constructor pair [`Self::simple`] / [`Self::git`] and the paired
2863 /// serde round-trip / per-test fixture-mutation paths) — an open-
2864 /// coded field-access that expressed no compile-time link back to
2865 /// the typed slot. A future extension of the `:opcional` axis to a
2866 /// richer author surface (a per-scope opcional-override the resolver
2867 /// folds through the `~/.config/caixa/config.yaml` entry the [`Dep`]
2868 /// docstring already acknowledges, a per-cluster opcional-override
2869 /// the future M4 lacre-federation layer applies per-CR, a promotion
2870 /// of the plain `bool` to a richer `OpcionalPolicy { drop, warn,
2871 /// error }` tri-state once the CAIXA-SDLC §II opcional-policy
2872 /// roadmap lands) would have had to be threaded through every open-
2873 /// coded copy in lockstep or two consumers would silently disagree
2874 /// on which missing-source arm a given dep resolves to — the
2875 /// [`Self::simple`] constructor's default-`false` fill reading
2876 /// verbatim while a downstream caixa-resolver consumer read a per-
2877 /// scope-override-resolved bit would silently split the build-time
2878 /// arm from the lacre closure the substrate's fetch pipeline
2879 /// actually materializes, one build-time diagnostic disagreeing
2880 /// with the run-time closure. Lifting the resolution rule to a
2881 /// typed method on the substrate primitive means every downstream
2882 /// consumer of the caixa's per-`:deps` opcional-tolerance surface
2883 /// reaches for exactly one typed dispatch — the resolver's accept-
2884 /// set migrates as a unit on any future axis addition.
2885 ///
2886 /// Fifth and final outer-`Dep` accessor — closes the outer-`Dep`
2887 /// slot-family the sibling per-`Dep` [`Self::nome`] (eba2cde) /
2888 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2889 /// / [`Self::caracteristicas`] (9197944) accessors opened, so every
2890 /// outer-`Dep` slot (`:nome`, `:versao`, `:fonte`, `:opcional`,
2891 /// `:caracteristicas`) now routes through exactly one typed
2892 /// dispatch on the substrate primitive. First outer-`Dep`
2893 /// `bool`-return / plain-`Copy`-scalar accessor — opens the
2894 /// outer-`Dep` `Copy`-scalar projection pattern that folds on the
2895 /// peer outer-top-level [`crate::Caixa`] `Option<Copy>`
2896 /// flat-spread sub-family ([`crate::Caixa::max_restarts`] eba5211,
2897 /// [`crate::Caixa::estrategia`] ed04d3c) the outer-`Caixa` altitude
2898 /// already carries — extends the "one typed dispatch on the
2899 /// substrate primitive, thin projections at each consumer"
2900 /// discipline onto the outer per-dep-list-entry [`Dep`] altitude's
2901 /// bool-shaped missing-source-tolerance slot. Returns `bool` by
2902 /// `Copy` (not by `&bool` reference) because `bool` is `Copy` and
2903 /// every downstream consumer treats it as a plain discriminant
2904 /// value — the by-value return is the narrowest return-shape that
2905 /// supports every present + roadmapped consumer (`.then(…)` early
2906 /// return on the resolver-side drop-vs-error partition, direct
2907 /// bool composition with a per-scope-override projector, plain
2908 /// `if dep.opcional() { … }` early return at every future admission
2909 /// gate) without leaking the storage field's `bool`-in-`&self`
2910 /// lifetime the by-value return elides. Marked `pub const fn` so
2911 /// the accessor is `const`-callable — same discipline the peer
2912 /// [`crate::Caixa::max_restarts`] `Option<u32>` `Copy`-return
2913 /// accessor carries. Named `opcional()` to match the storage
2914 /// field's name verbatim and the tatara-lisp author-surface term
2915 /// (`:opcional`) the field's own docstring already carries.
2916 #[must_use]
2917 pub const fn opcional(&self) -> bool {
2918 self.opcional
2919 }
2920
2921 /// Build a minimal registry-sourced dep.
2922 #[must_use]
2923 pub fn simple(nome: impl Into<String>, versao: impl Into<String>) -> Self {
2924 Self {
2925 nome: nome.into(),
2926 versao: versao.into(),
2927 fonte: None,
2928 opcional: false,
2929 caracteristicas: Vec::new(),
2930 }
2931 }
2932
2933 /// Build a Git-sourced dep (tag-based).
2934 #[must_use]
2935 pub fn git(
2936 nome: impl Into<String>,
2937 versao: impl Into<String>,
2938 repo: impl Into<String>,
2939 tag: impl Into<String>,
2940 ) -> Self {
2941 Self {
2942 nome: nome.into(),
2943 versao: versao.into(),
2944 fonte: Some(DepSource::Git {
2945 repo: repo.into(),
2946 tag: Some(tag.into()),
2947 rev: None,
2948 branch: None,
2949 }),
2950 opcional: false,
2951 caracteristicas: Vec::new(),
2952 }
2953 }
2954
2955 /// Reject dependency entries whose `:nome` or `:versao` are empty,
2956 /// whose `:nome` is non-empty but not a valid DNS-1123 label,
2957 /// or whose `:versao` is non-empty but not a valid Cargo-shaped
2958 /// semver requirement.
2959 ///
2960 /// The author surface for `:deps :versao` (and `:deps-dev :versao`)
2961 /// is the same Cargo-shaped requirement string `:membros :versao`
2962 /// (validated at [`crate::AplicacaoSpec::validate`] since 9888b13)
2963 /// and `:children :versao` (validated at
2964 /// [`crate::SupervisorSpec::validate`] since b38ff3a) carry — and
2965 /// the lacre pipeline resolves all three axes through the same
2966 /// [`crate::parse_requirement`] entry-point. Until 2420c44 landed
2967 /// `:deps :versao` was the last `:versao` axis untyped past
2968 /// `Caixa::from_lisp`: a malformed-but-non-empty requirement
2969 /// (`"^bad-version"`, `"^^0.1"`, the canonical git-tag-shape-
2970 /// leaking-into-:versao `"v0.1"` typo, the accidental
2971 /// `"not-a-req"`) silently passed parse and the `semver::Error`
2972 /// surfaced at lacre-resolve time, far from the source
2973 /// caixa.lisp, with no field naming which `:deps` entry carried
2974 /// the typo. The diagnostic [`DepError::VersaoInvalid`] carries
2975 /// the offending entry's `:nome` + the offending `:versao`
2976 /// verbatim + the parser's own wording in `reason`, so the
2977 /// author's grep target is unambiguous.
2978 ///
2979 /// The author surface for `:deps :nome` is the same DNS-1123 label
2980 /// the peer caixa-identifier axes carry — top-level Caixa `:nome`
2981 /// (validated at [`crate::Caixa::validate_nome`] since 6c992f8),
2982 /// `:membros :caixa` (validated at
2983 /// [`crate::AplicacaoSpec::validate_membros`] since 3f9d7a0),
2984 /// `:children :caixa` (validated at
2985 /// [`crate::SupervisorSpec::validate`] since 31bfa43). A `:deps
2986 /// :nome` value flows verbatim through the lacre pipeline as the
2987 /// target caixa's `:nome` (which the gate at the *target* side now
2988 /// rejects if non-DNS-1123) and lands as the rendered caixa's
2989 /// `lareira-<nome>` Helm chart name segment, the per-dep
2990 /// `LABEL_PROGRAM` label value, and the `caixa-resolver`'s
2991 /// `~/.cache/caixa/<org>/<nome>` checkout-directory leaf. Until
2992 /// this gate landed `:deps :nome` was the fourth and last
2993 /// DNS-1123-shaped caixa-identifier axis still untyped past
2994 /// `Caixa::from_lisp`: a syntactically wrong dep name (`"Caixa-
2995 /// Teia"` uppercase — the canonical "I copied the README header"
2996 /// typo; `"caixa_teia"` underscore — the Go module / Python
2997 /// identifier leak; `"caixa-teia."` trailing dot — the FQDN
2998 /// confusion; `"-caixa-teia"` leading hyphen; a 64-byte slug)
2999 /// silently passed parse and surfaced at lacre-resolve time when
3000 /// the resolved target caixa's `:nome` failed *its* DNS-1123 gate
3001 /// — far from the source `:deps` entry, with a diagnostic naming
3002 /// the *target's* `:nome` rather than the dep entry that referenced
3003 /// it. Mirroring the 3f9d7a0 / 31bfa43 / 6c992f8 trajectory through
3004 /// the lifted [`crate::render::is_dns_1123_label`] predicate (the
3005 /// "before its third occurrence" PRIME DIRECTIVE boundary, THEORY.md
3006 /// §I.3.5): every `Dep::nome` past validate is DNS-1123-label-shaped,
3007 /// so every downstream consumer (caixa-resolver's lacre fetch,
3008 /// caixa-helm's `lareira-<nome>` chart name, the future M4 per-dep
3009 /// fan-out emitter) reaches for the name knowing the value is
3010 /// apiserver-valid without re-validating.
3011 ///
3012 /// Empty checks fire first (narrower diagnostic), parse last —
3013 /// same ordering discipline as
3014 /// [`crate::AplicacaoSpec::validate_membros`] and
3015 /// [`crate::SupervisorSpec::validate`]. `parse_requirement("")`
3016 /// returns `Ok(VersionReq::STAR)`, so the empty-`:versao` arm is
3017 /// structurally necessary even with the parse arm in place. The
3018 /// `:nome` shape gate runs after the `:nome` empty gate and before
3019 /// the `:versao` checks so a one-entry caixa.lisp with both wrong
3020 /// sees the name-side diagnostic first (the name is the
3021 /// self-locating axis — without it, the parse diagnostic can't
3022 /// quote `:nome "<bad>"`).
3023 pub fn validate(&self) -> Result<(), DepError> {
3024 if self.nome.is_empty() {
3025 return Err(DepError::NomeEmpty);
3026 }
3027 if let Err(reason) = crate::render::is_dns_1123_label(&self.nome) {
3028 return Err(DepError::NomeInvalid {
3029 nome: self.nome.clone(),
3030 reason,
3031 });
3032 }
3033 // Delegate the empty-first + `parse_requirement` cascade to the
3034 // shared [`crate::render::require_valid_versao_requirement`]
3035 // helper — same two-arm shape the peer
3036 // [`crate::AplicacaoSpec::validate_membros`] on `:membros
3037 // :versao` and [`crate::SupervisorSpec::validate`] on `:children
3038 // :versao` route through, so drift between the three axes'
3039 // accepted requirement sets is structurally impossible and the
3040 // parse-side no-op the empty-first arm closes (semver's empty
3041 // parse yields an implicit `*`) lives in exactly one predicate.
3042 crate::render::require_valid_versao_requirement(
3043 self.versao_requirement(),
3044 || DepError::VersaoEmpty {
3045 nome: self.nome.clone(),
3046 },
3047 |reason| DepError::VersaoInvalid {
3048 nome: self.nome.clone(),
3049 versao: self.versao_requirement().to_string(),
3050 reason,
3051 },
3052 )?;
3053 if let Some(fonte) = self.fonte() {
3054 fonte.validate(&self.nome)?;
3055 }
3056 self.validate_caracteristicas()?;
3057 Ok(())
3058 }
3059
3060 /// Reject per-entry `:caracteristicas` (feature-flag) values that
3061 /// are operationally meaningless. The `:caracteristicas` slot is
3062 /// a set of feature toggles to enable on the target caixa — same
3063 /// shape as Cargo's `[dependencies.<dep>.features]` list — and
3064 /// two structural footguns close here:
3065 ///
3066 /// - empty-string entry (`(:caracteristicas (""))`): the future
3067 /// caixa-resolver lacre pipeline would consume the empty
3068 /// identifier as a no-op feature enable, silently dropping the
3069 /// author's intent far from the source `caixa.lisp`;
3070 /// - duplicate entry within one dep (`(:caracteristicas ("http"
3071 /// "http"))`): the feature-toggle slot is set-shaped (enabling
3072 /// a feature twice has no additional semantic — there is no
3073 /// `feature × 2`), so two entries naming the same feature are
3074 /// a silent miscount, the same set-not-multiset distinction
3075 /// every peer Vec-keyed-by-name axis already closes
3076 /// ([`crate::SupervisorError::DuplicateChildCaixa`] on
3077 /// `:children :caixa`, [`crate::AplicacaoError::MembroDuplicate`]
3078 /// on `:membros :caixa`, [`crate::AplicacaoError::ContratoDuplicate`]
3079 /// on `:contratos`, [`crate::AplicacaoError::PlacementClusterDuplicate`]
3080 /// on `:placement :clusters`, [`crate::AplicacaoError::EntradaPathDuplicate`]
3081 /// on `:entrada :paths`, [`crate::UpgradeError::DuplicateFrom`]
3082 /// on `:upgrade-from :from`, [`crate::UpgradeError::DuplicateLoadModule`]
3083 /// / [`crate::UpgradeError::DuplicateStateChange`] /
3084 /// [`crate::UpgradeError::DuplicateCleanup`] on the within-
3085 /// entry `:upgrade-from` axes, and [`DepError::DuplicateNome`]
3086 /// on the cross-entry `:deps`/`:deps-dev` `:nome` axis the
3087 /// immediate-predecessor 359fba5 closed).
3088 ///
3089 /// Same linear-walk + `HashSet` + first-collision diagnostic shape
3090 /// every peer set-not-multiset gate uses; the empty arm fires
3091 /// before the duplicate arm so an entry with both an empty feature
3092 /// *and* a duplicate of some later feature surfaces the empty-
3093 /// shape diagnostic first (the empty-feature axis is the
3094 /// more-actionable defect since the missing-name renders the
3095 /// duplicate-key arm ambiguous: two `""` entries would both report
3096 /// `caracteristica: ""` with no way to distinguish the offending
3097 /// site). Empty-first cascade discipline mirrors every peer per-
3098 /// entry shape + duplicate gate
3099 /// (`SupervisorSpec::validate`'s `EmptyChildName` before
3100 /// `DuplicateChildCaixa`; `validate_membros`'s `MembroCaixaEmpty`
3101 /// before `MembroDuplicate`).
3102 ///
3103 /// The per-entry value-shape gate (Cargo-feature-name grammar via
3104 /// the lifted [`crate::render::is_cargo_feature_name`] predicate)
3105 /// fires between the empty arm and the duplicate arm — the
3106 /// canonical per-entry-shape-before-cross-entry-uniqueness
3107 /// precedence every peer two-arm + value-shape gate establishes
3108 /// ([`crate::SupervisorSpec::validate`]'s `EmptyChildName` →
3109 /// `ChildCaixaInvalid` → `DuplicateChildCaixa`,
3110 /// [`crate::AplicacaoSpec::validate_membros`]'s `MembroCaixaEmpty`
3111 /// → `MembroCaixaInvalid` → `MembroDuplicate`, [`Dep::validate`]'s
3112 /// `NomeEmpty` → `NomeInvalid` → cross-list `DuplicateNome`).
3113 /// Until the value-shape arm landed `:caracteristicas` accepted
3114 /// every non-empty distinct string — a structurally invalid
3115 /// feature name (`"http feature"` whitespace, `"+http"` the
3116 /// canonical paste-from-`+optional-feature` doc activation-form
3117 /// footgun, `"-flag"` leading hyphen, `".feat"` leading dot,
3118 /// `"http/json"` Cargo's `dep/feat` namespaced-dep syntax that
3119 /// only applies inside list-grammar contexts, `"http,json"`
3120 /// list-separator-belongs-to-the-list-grammar miscomprehension,
3121 /// `"café"` un-percent-encoded non-ASCII silently round-tripping
3122 /// inconsistently across NFC/NFD normalization, the 65-byte
3123 /// paste-from-binary slug) silently passed validate and the
3124 /// failure surfaced at `cargo metadata` time as the
3125 /// `restricted_names::validate_feature_name` parser's rejection,
3126 /// far from the source `caixa.lisp`, with no field naming which
3127 /// `:deps` entry's `:caracteristicas` carried the typo. The
3128 /// lifted predicate makes the Cargo-feature-name-grammar
3129 /// intersection-floor a substrate-level invariant at validate
3130 /// time — same trajectory as the eight peer
3131 /// [`crate::render`] value-shape predicates each typed surface
3132 /// downstream of a structured grammar already follows
3133 /// ([`is_dns_1123_label`](crate::render::is_dns_1123_label),
3134 /// [`is_gateway_api_http_path`](crate::render::is_gateway_api_http_path),
3135 /// [`is_wit_world_ref`](crate::render::is_wit_world_ref),
3136 /// [`is_nats_subject`](crate::render::is_nats_subject),
3137 /// [`is_wasi_keyvalue_slot`](crate::render::is_wasi_keyvalue_slot),
3138 /// [`is_git_ref_name`](crate::render::is_git_ref_name),
3139 /// [`is_git_oid`](crate::render::is_git_oid),
3140 /// [`is_git_repo_url`](crate::render::is_git_repo_url)).
3141 fn validate_caracteristicas(&self) -> Result<(), DepError> {
3142 let mut seen = std::collections::HashSet::new();
3143 for c in self.caracteristicas() {
3144 if c.is_empty() {
3145 return Err(DepError::CaracteristicaEmpty {
3146 nome: self.nome.clone(),
3147 });
3148 }
3149 if let Err(reason) = crate::render::is_cargo_feature_name(c) {
3150 return Err(DepError::CaracteristicaInvalid {
3151 nome: self.nome.clone(),
3152 caracteristica: c.clone(),
3153 reason,
3154 });
3155 }
3156 crate::render::insert_first_seen(&mut seen, c.as_str(), || {
3157 DepError::CaracteristicaDuplicate {
3158 nome: self.nome.clone(),
3159 caracteristica: c.clone(),
3160 }
3161 })?;
3162 }
3163 Ok(())
3164 }
3165}
3166
3167/// Cross-slot coherence gate on the dep-graph axis: no `:deps` or
3168/// `:deps-dev` entry may name the caixa's own `:nome`.
3169///
3170/// A caixa that lists itself as a dep is a degenerate self-edge in the
3171/// lacre closure's dep-graph — the closure is a DAG rooted at the
3172/// caixa's `:nome`, and the caixa-resolver's lacre pipeline traverses
3173/// every `:deps` / `:deps-dev` entry's target by name. A self-dep
3174/// hands the resolver a node that is its own parent: a one-node cycle
3175/// it either rejects mid-traversal far from the source `caixa.lisp`
3176/// (the resolver detecting infinite recursion on the closure walk) or,
3177/// worse, recurses on until it exhausts its stack. Because every
3178/// `:nome` is a globally-unique substrate identity (DNS-1123 label +
3179/// lacre closure root), a dep entry whose `:nome` equals the caixa's
3180/// own `:nome` *is* the caixa itself, not a coincidentally-named peer.
3181///
3182/// Lives outside [`Caixa::validate_deps`] because the dep-list view
3183/// carries the entries but not the parent `:nome`; mirrors the
3184/// cross-slot self-edge gates [`crate::supervisor::validate_no_self_supervision`]
3185/// (ad4abf1) on the `:children :caixa` axis and
3186/// [`crate::aplicacao::validate_no_self_membership`] on the
3187/// `:membros :caixa` axis — the same "an edge from a graph node to
3188/// itself is structurally not a tree/graph edge" discipline, here on
3189/// the third typed-name-graph axis (the dep closure; the supervision
3190/// tree and the Aplicacao membership set were the prior two).
3191///
3192/// Walks `:deps` first then `:deps-dev` so the diagnostic for a caixa
3193/// that self-references on both axes surfaces the `:deps` arm first —
3194/// the load-bearing axis the lacre closure resolves at every build,
3195/// peer with the canonical [`Caixa::validate_deps`] walk order
3196/// (`:deps` → `:deps-dev`).
3197///
3198/// Carries the offending list tag (`":deps"` or `":deps-dev"`)
3199/// verbatim into the diagnostic so the author can grep their
3200/// `caixa.lisp` for the offending block in one edit — same
3201/// `list: &'static str` shape [`DepError::DuplicateNome`] (359fba5)
3202/// uses on the cross-list duplicate-name axis.
3203///
3204/// `Code paths` (`:bibliotecas` / `:exe` / `:servicos`) are the
3205/// substrate-blessed shape for referencing the caixa's *own* code, so
3206/// the diagnostic names them as the corrective surface — every
3207/// legitimate "I want to use code from this caixa" authoring intent
3208/// routes through one of those three slots, not a self-dep.
3209pub fn validate_no_self_dep(
3210 deps: &[Dep],
3211 deps_dev: &[Dep],
3212 parent_nome: &str,
3213) -> Result<(), DepError> {
3214 for dep in deps {
3215 if dep.nome() == parent_nome {
3216 return Err(DepError::DepIsSelf {
3217 nome: parent_nome.to_string(),
3218 list: crate::render::DEP_AUTHOR_KEY_DEPS,
3219 });
3220 }
3221 }
3222 for dep in deps_dev {
3223 if dep.nome() == parent_nome {
3224 return Err(DepError::DepIsSelf {
3225 nome: parent_nome.to_string(),
3226 list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3227 });
3228 }
3229 }
3230 Ok(())
3231}
3232
3233/// Closed-set typed enum for the two dep-list author-surface axes every
3234/// top-level [`crate::Caixa`] carries — the runtime-closure `:deps` slot
3235/// (`Prod`) and the dev-only-closure `:deps-dev` slot (`Dev`). Every
3236/// substrate consumer that dispatches on "which of the two dep-lists"
3237/// (the `feira add` mutation head, the future per-cluster dev-closure-
3238/// audit overlay the M4 CR materializer resolves per-CR, the future
3239/// `caixa app graph` per-list dep summary, every future
3240/// `Caixa::push_dep` / `Caixa::deps_by_list` typed-method dispatch a
3241/// caller reaches for) reads through this enum rather than through a
3242/// bare `&'static str` — the closed-set is expressed at the type layer,
3243/// so a future third dep-list axis (a `:deps-build` build-only closure
3244/// once the substrate grows cross-artifact heterogeneous dep-graphs,
3245/// per CAIXA-SDLC §I) is one variant plus one arm per method and the
3246/// compiler enforces exhaustiveness on every consumer's `match` arms.
3247///
3248/// The wire byte-string [`Self::as_str`] returns is the same author-
3249/// surface tag the sibling [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3250/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry — the
3251/// [`DepError::DuplicateNome`] / [`DepError::DepIsSelf`] `list:
3252/// &'static str` payload family the substrate already emits routes
3253/// through the same source of truth (an author reading a
3254/// [`DepError::DuplicateNome`] refusal can grep their `caixa.lisp`
3255/// for the offending `:deps` / `:deps-dev` block in one edit whether
3256/// the diagnostic came from a `Caixa::validate_deps` walk or a
3257/// `Caixa::push_dep` mutation).
3258///
3259/// Same "closed-set typed-enum discriminator with canonical
3260/// projections per axis" discipline the sibling closed-set typed enums
3261/// on the caixa typed surface carry
3262/// ([`crate::aplicacao::PlacementStrategy`] cc8f749,
3263/// [`crate::aplicacao::RateLimitUnit`] 6bce03d,
3264/// [`crate::supervisor::RestartStrategy`],
3265/// [`crate::supervisor::RestartPolicy`],
3266/// [`crate::upgrade::UpgradeInstruction`], [`crate::CaixaKind`])
3267/// — extended onto the outer-`Caixa` two-list dep-graph axis, the
3268/// substrate's last unlifted closed-set-shaped `&'static str`-carrying
3269/// axis on the top-level manifest surface.
3270#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
3271pub enum DepList {
3272 /// Runtime-closure `:deps` axis — the load-bearing dep-list the
3273 /// lacre closure resolves at every build. Wire-format
3274 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`].
3275 Prod,
3276 /// Dev-only-closure `:deps-dev` axis — Cargo's `[dev-dependencies]`
3277 /// table's dev-time-only visibility contract per CAIXA-SDLC §I.
3278 /// Wire-format [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`].
3279 Dev,
3280}
3281
3282impl DepList {
3283 /// Exhaustive iteration surface for every consumer that reads the
3284 /// full closed-set (the future M4 admission webhook's per-list
3285 /// summary rejection body, any future round-trip pin harness). A
3286 /// future variant addition extends this slice as a single edit and
3287 /// every consumer picks up the new entry by construction — the
3288 /// compiler-checked exhaustiveness on the sibling method `match`
3289 /// arms is the build-time guarantee that no arm forgets to grow.
3290 pub const ALL: &'static [Self] = &[Self::Prod, Self::Dev];
3291
3292 /// Canonical author-surface tag every substrate consumer that
3293 /// names the offending dep-list in a diagnostic reaches for —
3294 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] for [`Self::Prod`] and
3295 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] for [`Self::Dev`],
3296 /// the same `&'static str` payload the sibling
3297 /// [`DepError::DuplicateNome`] and [`DepError::DepIsSelf`] variants
3298 /// already carry. Routing every dep-list diagnostic through the
3299 /// closed-set enum's `as_str` closes the last `&'static str`-shape
3300 /// literal-carry axis on the two-list dep-graph surface — a
3301 /// future kebab-case rebrand (`":deps"` → `":packages"`) or a
3302 /// wire-format promotion (a distinct diagnostic form for the
3303 /// `Dev` arm) reaches every consumer through one edit on the
3304 /// canonical constant, not a coordinated rewrite across the
3305 /// substrate's dep-graph consumers.
3306 #[must_use]
3307 pub const fn as_str(self) -> &'static str {
3308 match self {
3309 Self::Prod => crate::render::DEP_AUTHOR_KEY_DEPS,
3310 Self::Dev => crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3311 }
3312 }
3313
3314 /// Substrate-canonical reverse projection on the two-list dep-graph
3315 /// axis — parses the author-surface wire tag back to the typed
3316 /// variant, or `None` when `s` is outside the closed-set arm-string
3317 /// set [`Self::as_str`] emits. Dispatches on the same lifted
3318 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3319 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants the
3320 /// [`Self::as_str`] emitter walks, so the parse and emit halves of
3321 /// the round-trip migrate through one caixa-core edit on any future
3322 /// list-axis addition.
3323 ///
3324 /// Prior to this lift the substrate carried only the forward
3325 /// `Self → &str` projection on the two-list dep-graph axis (the
3326 /// [`Self::as_str`] emitter, the [`std::fmt::Display`] impl routed
3327 /// through it, the two [`DepError::DuplicateNome`] /
3328 /// [`DepError::DepIsSelf`] variants that carry the wire tag verbatim
3329 /// as a `&'static str` `list:` field). Every future consumer that
3330 /// wanted to promote the wire tag back to the typed enum (a future
3331 /// `feira dep --list <deps|deps-dev>` CLI arg-parse that binds the
3332 /// wire form into the typed enum before dispatching to
3333 /// [`crate::Caixa::deps_of`] / [`crate::Caixa::push_dep`], the M4
3334 /// `mesh.pleme.io/v1alpha1/Caixa` CR materializer's admission-time
3335 /// wire re-parse of the per-list diagnostic body, a future
3336 /// [`DepError`] widening that promotes the two `list: &'static str`
3337 /// fields to a typed `list: DepList` carry so downstream consumers
3338 /// dispatch on the enum rather than string-comparing the wire
3339 /// scalar) would have had to re-inline a two-arm `match s { ":deps"
3340 /// => …, ":deps-dev" => …, _ => … }` cascade that expressed no
3341 /// compile-time link back to the typed [`DepList`] enum. A future
3342 /// variant addition (a `:build-dep` or `:test-dep` third list once
3343 /// the substrate grows Cargo-style split-graphs, a `:tool-dep` for
3344 /// build-time-only tooling per the peer Cargo `[build-dependencies]`
3345 /// / `[target.<cfg>.dev-dependencies]` future admission surface)
3346 /// would silently split the wire byte-string the emitter walks from
3347 /// the parser's arm-set — the round-trip would carry the new list
3348 /// through the forward projection but land on the fallback silently
3349 /// at every non-updated reverse parser, far from the arm-addition
3350 /// commit that caused the drift. Lifting the resolver to a typed
3351 /// method on the substrate primitive closes the drift footgun by
3352 /// construction: the parser's accept-set is the same set the
3353 /// [`Self::as_str`] emitter walks (routed through the same lifted
3354 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3355 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] consts), so both halves
3356 /// of the round-trip migrate through one caixa-core edit on any
3357 /// future list-axis addition.
3358 ///
3359 /// Same closed-set-reverse-projection discipline the sibling
3360 /// [`crate::CaixaKind::from_wire`] (2aa6d23) /
3361 /// [`crate::supervisor::RestartStrategy::from_wire`] (4eec29c) /
3362 /// [`crate::supervisor::RestartPolicy::from_wire`] (dd32ccf) /
3363 /// [`crate::aplicacao::PlacementStrategy::from_wire`] (18c7342) /
3364 /// [`crate::aplicacao::RateLimitUnit::from_suffix`] typed enums
3365 /// carry on the peer wire-side `str → Self` axes — extended onto
3366 /// the two-list dep-graph closed-set axis, the sixth substrate-side
3367 /// closed-set typed enum on the caixa surface to converge on the
3368 /// two-way `str ↔ Self` round-trip. Method-named `from_wire` (not
3369 /// `from_str`) to match the peer shapes verbatim and side-step the
3370 /// derived [`std::str::FromStr`] impls the sibling
3371 /// [`gen_platform::FromStrKind`]-carrying axes install on their
3372 /// kebab-case dispatcher-catalog identity. Returns `Option<Self>`
3373 /// (rather than `Result<Self, _>`) to match the peer shapes: the
3374 /// caller picks the diagnostic form appropriate for its use site —
3375 /// a future `feira dep --list …` arg-parse that surfaces
3376 /// `unknown list: <arg>` at the CLI builds one on top by iterating
3377 /// [`Self::ALL`], while the future M4 admission-webhook's rejection
3378 /// path folds `None` onto its per-CR structured refusal body.
3379 #[must_use]
3380 pub fn from_wire(s: &str) -> Option<Self> {
3381 match s {
3382 crate::render::DEP_AUTHOR_KEY_DEPS => Some(Self::Prod),
3383 crate::render::DEP_AUTHOR_KEY_DEPS_DEV => Some(Self::Dev),
3384 _ => None,
3385 }
3386 }
3387}
3388
3389/// Route [`std::fmt::Display`] through [`DepList::as_str`], so every
3390/// consumer that formats the axis as user-facing text (a future
3391/// `feira app graph` per-list summary, a future M4 admission-webhook
3392/// rejection body naming the offending list, this crate's own
3393/// [`DepError`] `#[error(...)]` templates when they widen to carry a
3394/// typed [`DepList`]) lands on the same author-surface tag the
3395/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3396/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry. Same
3397/// as-str-through-Display convergence discipline the sibling
3398/// [`crate::aplicacao::PlacementStrategy`],
3399/// [`crate::aplicacao::RateLimitUnit`],
3400/// [`crate::supervisor::RestartStrategy`],
3401/// [`crate::supervisor::RestartPolicy`], and [`crate::CaixaKind`]
3402/// closed-set typed enums carry.
3403impl std::fmt::Display for DepList {
3404 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3405 f.write_str(self.as_str())
3406 }
3407}
3408
3409/// Errors raised by [`Dep::validate`].
3410///
3411/// Mirrors the per-axis error families the other `:versao`-carrying
3412/// typed surfaces expose
3413/// ([`crate::AplicacaoError::MembroVersaoEmpty`] /
3414/// [`crate::AplicacaoError::MembroVersaoInvalid`],
3415/// [`crate::SupervisorError::EmptyChildVersion`] /
3416/// [`crate::SupervisorError::ChildVersaoInvalid`]) so a future top-
3417/// level `CaixaError` (M4) sums these without reshaping the diagnostic.
3418#[derive(Debug, Error, PartialEq, Eq)]
3419pub enum DepError {
3420 #[error(
3421 ":deps entry has empty :nome (every dep must name a target caixa; \
3422 omit the entry instead of carrying an empty name)"
3423 )]
3424 NomeEmpty,
3425 #[error(
3426 ":deps entry :nome {nome:?} is not a valid DNS-1123 label: {reason} \
3427 (the value flows verbatim as the target caixa's `:nome`, the rendered \
3428 `lareira-<nome>` Helm chart name segment, the `LABEL_PROGRAM` label \
3429 value, and the resolver's checkout-directory leaf — each apiserver-side \
3430 schema rejects non-DNS-1123 names at admission time; use a lowercase \
3431 RFC 1123 label like `\"caixa-teia\"` or `\"pleme-mesh\"`, 1..=63 bytes, \
3432 pattern `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)"
3433 )]
3434 NomeInvalid { nome: String, reason: String },
3435 #[error(
3436 ":deps entry {nome:?} has empty :versao (every dep must pin a semver \
3437 constraint that resolves through the lacre pipeline)"
3438 )]
3439 VersaoEmpty { nome: String },
3440 #[error(
3441 ":deps entry {nome:?} :versao {versao:?} is not a valid semver \
3442 requirement: {reason} (use Cargo-shaped forms like `\"^0.1\"`, \
3443 `\"~0.1.2\"`, `\"0.1.0\"`, or `\"*\"` — the same shape `:membros :versao` \
3444 and `:children :versao` carry; the lacre pipeline resolves all three \
3445 through the same parser)"
3446 )]
3447 VersaoInvalid {
3448 nome: String,
3449 versao: String,
3450 reason: String,
3451 },
3452 #[error(
3453 ":deps entry {nome:?} :fonte (:tipo git …) has empty :repo \
3454 (every git source must name a repo — use a `github:org/repo` \
3455 shorthand, an `https://…` URL, or an ssh-git URL; omit the \
3456 entire :fonte block to fall back to the default-host resolver \
3457 convention)"
3458 )]
3459 FonteRepoEmpty { nome: String },
3460 #[error(
3461 ":deps entry {nome:?} :fonte (:tipo git …) :repo {repo:?} has \
3462 invalid value-shape: {reason} (the value flows verbatim into the \
3463 caixa-resolver's `git clone <repo>` subprocess invocation; every \
3464 documented form carries a `:` separator and no whitespace / \
3465 control / non-ASCII bytes — use a `github:org/repo` shorthand, \
3466 an `https://host/path` / `ssh://[user@]host/path` / \
3467 `git://host/path` / `file:///path` URL, or the `git@host:path` \
3468 scp-style SSH form)"
3469 )]
3470 FonteRepoShape {
3471 nome: String,
3472 repo: String,
3473 reason: String,
3474 },
3475 #[error(
3476 ":deps entry {nome:?} :fonte (:tipo git …) has no pin set \
3477 (set exactly one of :tag, :rev, or :branch so the resolver \
3478 can pick a reproducible commit; omit the entire :fonte block \
3479 to fall back to the default-host resolver convention, which \
3480 resolves the latest tag matching :versao)"
3481 )]
3482 FontePinMissing { nome: String },
3483 #[error(
3484 ":deps entry {nome:?} :fonte (:tipo git …) has multiple pins \
3485 set ({pins}); exactly one of :tag, :rev, or :branch must be \
3486 set so the resolver's checkout target is unambiguous (the \
3487 resolver's silent precedence is :rev > :tag > :branch — if \
3488 you intended one specifically, drop the others)"
3489 )]
3490 FontePinAmbiguous { nome: String, pins: String },
3491 #[error(
3492 ":deps entry {nome:?} :fonte (:tipo git …) has empty {pin} \
3493 (a set pin must name a non-empty git ref; drop the {pin} key \
3494 entirely to fall through to another pin axis)"
3495 )]
3496 FontePinEmpty { nome: String, pin: String },
3497 #[error(
3498 ":deps entry {nome:?} :fonte (:tipo git …) {pin} {value:?} has invalid \
3499 value-shape: {reason} (the git porcelain enforces the same shape at \
3500 `git fetch` / `git checkout` time on every pin; use a leaf refname \
3501 like `\"v0.1.0\"` for `:tag` or `\"main\"` / `\"feature/foo\"` for \
3502 `:branch`, or a full 40/64 lowercase-hex commit OID for `:rev` — \
3503 drop any `refs/heads/` or `refs/tags/` prefix the caixa-resolver \
3504 prepends at clone time, and avoid abbreviated SHAs which are \
3505 ambiguous across repository history)"
3506 )]
3507 FontePinShape {
3508 nome: String,
3509 pin: String,
3510 value: String,
3511 reason: String,
3512 },
3513 #[error(
3514 ":deps entry {nome:?} :fonte (:tipo path …) has empty :caminho \
3515 (every path source must name a non-empty filesystem path; \
3516 omit the entire :fonte block to fall back to the default-host \
3517 resolver convention)"
3518 )]
3519 FonteCaminhoEmpty { nome: String },
3520 #[error(
3521 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} is \
3522 absolute (the lacre pipeline embeds the value verbatim in its \
3523 per-dep content-address `path:{caminho}` at \
3524 caixa-resolver/src/resolve.rs:189, so an absolute path makes the \
3525 BLAKE3 closure differ across machines — defeating the \
3526 reproducibility contract that's load-bearing for CSE; express \
3527 the path relative to the caixa.lisp location, e.g. \
3528 \"../caixa-teia\" for a sibling workspace dep)"
3529 )]
3530 FonteCaminhoAbsolute { nome: String, caminho: String },
3531 #[error(
3532 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3533 with `~` (the leading-tilde is a shell-expansion convention, not a \
3534 POSIX path component — `Path::is_absolute` returns false on it, so \
3535 the b94fd83 absolute-path gate doesn't catch it, but the lacre \
3536 pipeline embeds the value verbatim in its per-dep content-address \
3537 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3538 caixa-resolver folds it through `Path::join` without `~`-expansion, \
3539 so the build looks for a literal `./{caminho}` subdirectory and \
3540 fails at resolve time far from the source caixa.lisp; even worse, a \
3541 future caixa-resolver pass that *does* expand `~` would silently \
3542 re-open the host-layout-leak the b94fd83 absolute gate closes — \
3543 Alice's `~` resolves to `/home/alice`, Bob's to `/home/bob`, two CI \
3544 runners with different `$HOME` layouts resolve to two distinct paths \
3545 for the byte-identical caixa, defeating the THEORY.md §V.2 render-\
3546 determinism contract; express the path relative to the caixa.lisp \
3547 location, e.g. \"../caixa-teia\" for a sibling workspace dep, or \
3548 spell out the full relative path explicitly if a workstation-rooted \
3549 dep is genuinely intended)"
3550 )]
3551 FonteCaminhoTildeExpansion { nome: String, caminho: String },
3552 #[error(
3553 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3554 with `$` (the leading-`$` is a shell-variable-expansion convention, \
3555 not a POSIX path component — `Path::is_absolute` returns false on it \
3556 and the a5c248e tilde gate doesn't catch it, but the lacre pipeline \
3557 embeds the value verbatim in its per-dep content-address \
3558 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3559 caixa-resolver folds it through `Path::join` without `$`-expansion, \
3560 so the build looks for a literal `./{caminho}` subdirectory and \
3561 fails at resolve time far from the source caixa.lisp; even worse, a \
3562 future caixa-resolver pass that *does* expand `$VAR` (the canonical \
3563 shell-convention idiom that CI's `${{WORKSPACE}}` paste-idiom \
3564 invites) would silently re-open the host-layout-leak the b94fd83 \
3565 absolute gate closes — Alice's `$HOME` resolves to `/home/alice`, \
3566 Bob's to `/home/bob`, two CI runners with different `${{WORKSPACE}}` \
3567 layouts resolve to two distinct paths for the byte-identical caixa, \
3568 defeating the THEORY.md §V.2 render-determinism contract; express \
3569 the path relative to the caixa.lisp location, e.g. \"../caixa-teia\" \
3570 for a sibling workspace dep, or spell out the full relative path \
3571 explicitly if a workstation-rooted dep is genuinely intended)"
3572 )]
3573 FonteCaminhoVarExpansion { nome: String, caminho: String },
3574 #[error(
3575 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3576 with a space (the leading ASCII space `0x20` is the orthogonal \
3577 paste-from-aligned-doc footgun that silently passes \
3578 `Path::is_absolute` and every prior leading-byte arm — \
3579 `\" ../caixa-teia\"` resolves via `Path::join` to a literal \
3580 `./ ../caixa-teia` subdirectory the resolver fails to find at \
3581 resolve time with a non-self-locating `No such file or directory` \
3582 error far from the source caixa.lisp; the lacre pipeline embeds \
3583 the value verbatim in its per-dep content-address `path:{caminho}` \
3584 at caixa-resolver/src/resolve.rs:189, so byte-divergent / \
3585 semantic-identical caixa values (` ../caixa-teia` vs \
3586 `../caixa-teia`) yield two distinct BLAKE3 closures across two \
3587 workstations whose authors differ only in paste-from-aligned- \
3588 caixa.lisp-doc whitespace habits — the most insidious failure \
3589 mode the typed slot can carry (no error surfaces; the divergence \
3590 is invisible until two machines compare lacres), defeating the \
3591 THEORY.md §V.2 render-determinism contract. The canonical \
3592 paste-from-aligned-`:deps`-block footgun (every `:fonte` form in \
3593 a multi-entry `:deps` block sits at the same column — an author \
3594 selecting `\"<sp><sp><sp>../caixa-teia\"` and pasting it from \
3595 the rendered alignment into a fresh entry preserves the leading \
3596 whitespace verbatim); peer `:fonte :repo` axis already rejects \
3597 leading whitespace via `is_git_repo_url`, `:fonte :tag` / \
3598 `:fonte :branch` via `is_git_ref_name`, `:descricao` via \
3599 `is_chart_description_shape`, `:licenca` via \
3600 `is_spdx_expression_shape`. Drop the leading space; express the \
3601 path as a bare relative single-token like \"../caixa-teia\")"
3602 )]
3603 FonteCaminhoLeadingWhitespace { nome: String, caminho: String },
3604 #[error(
3605 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3606 with `-` (the canonical CLI-argument-injection footgun on the \
3607 `:caminho` axis — the lacre pipeline embeds the value verbatim in \
3608 its per-dep content-address `path:{caminho}` at \
3609 caixa-resolver/src/resolve.rs:189 and the caixa-resolver folds it \
3610 through `Path::join` looking for a literal `./{caminho}` \
3611 subdirectory. Every downstream subprocess that consumes the resolved \
3612 path — `git -C {caminho} <verb>`, `terraform -chdir={caminho}`, \
3613 `nix build --path {caminho}`, `find {caminho}`, `stat {caminho}`, \
3614 `cp -r {caminho} …`, `rm -rf {caminho}` — reinterprets a leading-`-` \
3615 value as a CLI flag rather than a positional path when the invocation \
3616 does not carry a `--` argument-list terminator between the flag block \
3617 and the path (the common case at every porcelain entry point). The \
3618 canonical footguns: `:caminho \"-rf\"` (bare short-flag paste), \
3619 `:caminho \"-C\"` (`git -C -C` config-injection paste), \
3620 `:caminho \"--upload-pack=cat /etc/passwd\"` (the canonical long-flag \
3621 CLI-arg-injection vector at every git porcelain entry point that \
3622 consumes a path or URL argument, peer with is_git_repo_url's \
3623 leading-`-` arm on the sibling `:fonte :repo` axis), \
3624 `:caminho \"--config=…\"` (`git -c foo=bar` config-override paste). \
3625 POSIX `std::path::Path` treats a leading `-` as a literal filename \
3626 byte so the resolver folds `\"-rf\"` through `Path::join` and looks \
3627 for a literal `./-rf` subdirectory that fails at resolve time with a \
3628 non-self-locating `No such file or directory` error far from the \
3629 source caixa.lisp — but on any downstream shell-out without `--` the \
3630 reinterpretation is silent and the failure mode is arbitrary-\
3631 argument-injection. Peer arms: `is_git_repo_url` (render.rs:2037) \
3632 rejects leading `-` on `:fonte :repo` for `git clone <repo>` CLI-\
3633 arg-injection; `is_git_ref_name` (render.rs:1381, 5a28454) rejects \
3634 leading `-` on `:fonte :tag` / `:branch` for `git checkout <ref>` \
3635 CLI-arg-injection; `is_dns_1123_label` rejects leading `-` on every \
3636 DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros :caixa`, \
3637 `:children :caixa`, `:deps :nome`, cluster names); \
3638 `is_cargo_feature_name` rejects leading `-` on `:caracteristicas`; \
3639 the feira `init` / `add <nome>` positional gate (868c191) rejects \
3640 leading `-` on the CLI positional itself. Express the path as a bare \
3641 relative single-token like \"../caixa-teia\" — the sibling-workspace \
3642 directory name carries no leading-hyphen semantic, and `./` / `../` \
3643 prefixes structurally partition the leading-byte set to safe values.)"
3644 )]
3645 FonteCaminhoLeadingHyphen { nome: String, caminho: String },
3646 #[error(
3647 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains \
3648 ASCII control byte 0x{byte:02x} (POSIX paths reject NUL `0x00` outright — \
3649 every `std::fs` syscall routes the path through `CString::new` which \
3650 fails with `NulError` at resolve time; the lacre pipeline embeds the \
3651 value verbatim in its per-dep content-address `path:{caminho}` at \
3652 caixa-resolver/src/resolve.rs:189 so a control byte anywhere in the \
3653 value lands in the BLAKE3 closure and breaks the THEORY.md §V.2 render-\
3654 determinism contract — the canonical paste-from-multiline-doc \
3655 (`\\n`/`\\r`), paste-from-aligned-table (`\\t`), or paste-from-binary-\
3656 blob (`0x00`-DEL) footgun every peer single-token-shaped axis \
3657 (`:fonte :repo`, `:fonte :tag`/`:branch`, the Helm chart-string axes) \
3658 already gates against. Express the path as a relative single-line ASCII \
3659 string, e.g. \"../caixa-teia\" for a sibling workspace dep)"
3660 )]
3661 FonteCaminhoControlChar {
3662 nome: String,
3663 caminho: String,
3664 byte: u8,
3665 },
3666 #[error(
3667 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains `\\` \
3668 (POSIX `std::path::Path` treats `\\` as a literal byte inside a single path \
3669 component, so `..\\caixa-teia` is one directory named literally `..\\caixa-teia` — \
3670 not the parent's sibling — and the caixa-resolver folds the value through \
3671 `Path::join` looking for a literal `./{caminho}` subdirectory that fails at \
3672 resolve time with a non-self-locating `No such file or directory` error far \
3673 from the source caixa.lisp; Windows `std::path::Path` treats `\\` as a \
3674 primary path separator equal to `/`, so byte-identical caixa.lisp values \
3675 resolve to two distinct directories across runner OSes — the lacre pipeline \
3676 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3677 caixa-resolver/src/resolve.rs:189, defeating the THEORY.md §V.2 render-\
3678 determinism contract via the cross-host-OS-separator divergence vector. The \
3679 canonical Windows-Explorer `Copy as path` / PowerShell `Get-Location` \
3680 paste-idiom footgun; peer `:fonte :tag` / `:fonte :branch` axis already \
3681 rejects `\\` via `is_git_ref_name` for the same Windows-path-leak reason, \
3682 and `:entrada :paths` rejects `\\` via `is_gateway_api_http_path`'s eleven-\
3683 byte RFC-3986-reserved set. Express the path with `/` as the separator, e.g. \
3684 \"../caixa-teia\" for a sibling workspace dep)"
3685 )]
3686 FonteCaminhoBackslash { nome: String, caminho: String },
3687 #[error(
3688 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3689 redirection metacharacter 0x{byte:02x} `{ch}` (every interactive shell — bash / \
3690 zsh / fish / nushell — lexes `<` and `>` as input / output redirection \
3691 operators, so `:caminho \"../caixa-teia>build.log\"` is the canonical \
3692 paste-from-shell-pipeline footgun where an author copies a `command > log` \
3693 tail without trimming the redirect; POSIX `std::path::Path` treats both bytes \
3694 as literal path-component bytes, so the resolver folds the value through \
3695 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3696 subdirectory and fails at resolve time with a non-self-locating `No such \
3697 file or directory` error far from the source caixa.lisp. The lacre pipeline \
3698 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3699 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure \
3700 and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3701 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3702 canonical CRLF-at-subprocess-argument / shell-metachar injection surface every \
3703 peer single-token-shaped typed slot already closes. The peer `:fonte :tag` / \
3704 `:fonte :branch` axis already rejects `<` / `>` via `is_git_ref_name`, and \
3705 `:entrada :paths` rejects them via `is_gateway_api_http_path`'s eleven-byte \
3706 RFC-3986-reserved set. Express the path as a bare relative single-token like \
3707 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3708 redirection semantic.",
3709 ch = *byte as char
3710 )]
3711 FonteCaminhoShellRedirection {
3712 nome: String,
3713 caminho: String,
3714 byte: u8,
3715 },
3716 #[error(
3717 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-pipe \
3718 metacharacter `|` (every interactive shell — bash / zsh / fish / nushell — lexes \
3719 `|` as the pipe operator that wires one command's stdout to the next command's \
3720 stdin, so `:caminho \"../caixa-teia | grep foo\"` is the canonical paste-from-\
3721 shell-history footgun where an author copies a `ls ../caixa-teia | grep` line \
3722 without trimming the pipeline tail, and `:caminho \"../foo||bar\"` is the \
3723 symmetric `cmd-a || cmd-b` short-circuit-OR paste shape; POSIX `std::path::Path` \
3724 treats `|` as a literal path-component byte, so the resolver folds the value \
3725 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3726 subdirectory and fails at resolve time with a non-self-locating `No such file or \
3727 directory` error far from the source caixa.lisp. The lacre pipeline embeds the \
3728 value verbatim in its per-dep content-address `path:{caminho}` at caixa-resolver/\
3729 src/resolve.rs:189, so the byte lands in the BLAKE3 closure and rides into every \
3730 shell-spawned subprocess (the resolver's `git clone`, a future `feira tofu` \
3731 shell-out, a future operator-side `nix` spawn) as the canonical CRLF-at-\
3732 subprocess-argument / shell-metachar injection surface every peer single-token-\
3733 shaped typed slot already closes. The peer `:entrada :paths` axis rejects `|` \
3734 via `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3735 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3736 workspace directory name carries no shell-pipe semantic."
3737 )]
3738 FonteCaminhoShellPipe { nome: String, caminho: String },
3739 #[error(
3740 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3741 command-separator metacharacter `;` (every interactive shell — bash / zsh / fish \
3742 / nushell — lexes `;` as the sequential-command terminator that fires the next \
3743 command regardless of the prior command's exit status, so `:caminho \
3744 \"../caixa-teia; rm -rf build\"` is the canonical paste-from-shell-one-liner \
3745 footgun where an author copies a `cd path; do-thing` chain without trimming \
3746 the cleanup tail, and `:caminho \"../foo;;bar\"` is the symmetric POSIX `case` \
3747 arm `;;` terminator paste shape; POSIX `std::path::Path` treats `;` as a \
3748 literal path-component byte, so the resolver folds the value through \
3749 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3750 subdirectory and fails at resolve time with a non-self-locating `No such file \
3751 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3752 the value verbatim in its per-dep content-address `path:{caminho}` at \
3753 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3754 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3755 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3756 canonical shell-metachar injection surface every peer single-token-shaped \
3757 typed slot already closes. The peer `:entrada :paths` axis rejects `;` via \
3758 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3759 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3760 workspace directory name carries no shell-command-separator semantic."
3761 )]
3762 FonteCaminhoShellSemicolon { nome: String, caminho: String },
3763 #[error(
3764 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3765 background / list-AND metacharacter `&` (every interactive shell — bash / zsh \
3766 / fish / nushell — lexes `&` two ways: single `&` as the background-task \
3767 terminator detaching the prior command and returning control immediately to \
3768 the prompt, double `&&` as the logical-AND list operator firing the next \
3769 command only if the prior succeeded; POSIX `std::path::Path` treats it as a \
3770 literal byte. The canonical paste-from-shell-prompt footgun is a `cd path & \
3771 sleep 1` background-launch one-liner or a `cd path && make install` build-\
3772 chain idiom selected whole into the `:caminho` slot — the prior `;` arm at \
3773 05c358e closed the sequential-command-separator vector, this arm closes the \
3774 orthogonal background-task / logical-AND vector on the same paste-from-shell-\
3775 prompt class. The lacre pipeline embeds the value verbatim in its per-dep \
3776 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3777 byte lands in the BLAKE3 closure and rides into every shell-spawned \
3778 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3779 future operator-side `nix` spawn) as the canonical shell-metachar injection \
3780 surface every peer single-token-shaped typed slot already closes. The peer \
3781 `:entrada :paths` axis rejects `&` via `is_gateway_api_http_path`'s eleven-\
3782 byte RFC-3986-reserved set. Express the path as a bare relative single-token \
3783 like \"../caixa-teia\" — the sibling-workspace directory name carries no \
3784 shell-background / logical-AND semantic."
3785 )]
3786 FonteCaminhoShellBackground { nome: String, caminho: String },
3787 #[error(
3788 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3789 command-substitution metacharacter `` ` `` (every POSIX shell — sh / bash / zsh / \
3790 dash / ksh / fish / nushell — lexes the byte as the legacy command-substitution \
3791 wrapper that runs the enclosed command and substitutes its standard-output \
3792 verbatim into the surrounding word, so a backticked `whoami` expands to the \
3793 current user's name and a backticked `cat /etc/passwd` expands to the file's \
3794 contents — the canonical CWE-78 shell-command-injection vector; POSIX \
3795 `std::path::Path` treats the byte as a literal path-component byte. The canonical \
3796 paste-from-shell-prompt footgun is a `cd ../path/<backtick>whoami<backtick>` legacy substitution \
3797 one-liner or a `cd <backtick>pwd<backtick>/path` working-directory expansion idiom selected whole \
3798 into the `:caminho` slot — the prior `&` arm at e12e4f3 closed the shell-\
3799 background / logical-AND vector, this arm closes the orthogonal command-\
3800 substitution vector on the same paste-from-shell-prompt class (the modern `$()` \
3801 form is gated at leading position by the f4efe9c `FonteCaminhoVarExpansion` arm; \
3802 the legacy backtick form is the orthogonal axis). The lacre pipeline embeds the \
3803 value verbatim in its per-dep content-address `path:{caminho}` at \
3804 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3805 rides into every shell-spawned subprocess (the resolver's `git clone`, a future \
3806 `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3807 shell-metachar injection surface every peer single-token-shaped typed slot \
3808 already closes. The peer `:entrada :paths` axis rejects the byte via \
3809 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the path \
3810 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3811 directory name carries no shell-command-substitution semantic."
3812 )]
3813 FonteCaminhoShellCommandSubstitution { nome: String, caminho: String },
3814 #[error(
3815 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3816 glob / pathname-expansion metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — \
3817 sh / bash / zsh / dash / ksh / fish / nushell — lexes `*` and `?` as pathname-\
3818 expansion wildcards: `*` matches any sequence of characters in a path component \
3819 and `?` matches exactly one character, so a `:caminho \"../caixa-teia/*\"` is the \
3820 canonical paste-from-shell-listing footgun where an author copies a \
3821 `ls ../caixa-teia/*` listing without trimming the wildcard, and `:caminho \
3822 \"../foo?\"` is the symmetric single-char-wildcard paste shape; POSIX \
3823 `std::path::Path` treats both bytes as literal path-component bytes, so the \
3824 resolver folds the value through `Path::new(caminho).join(<file>)` looking for \
3825 a literal `./{caminho}` subdirectory and fails at resolve time with a non-self-\
3826 locating `No such file or directory` error far from the source caixa.lisp. The \
3827 lacre pipeline embeds the value verbatim in its per-dep content-address \
3828 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the \
3829 BLAKE3 closure and rides into every shell-spawned subprocess (the resolver's \
3830 `git clone`, a future `feira tofu` shell-out, a future operator-side `nix` \
3831 spawn) as the canonical shell-metachar / glob-expansion surface every peer \
3832 single-token-shaped typed slot already closes. The peer `:entrada :paths` axis \
3833 rejects `*` and `?` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-\
3834 reserved set. Express the path as a bare relative single-token like \
3835 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-glob \
3836 / pathname-expansion semantic.",
3837 ch = *byte as char
3838 )]
3839 FonteCaminhoShellGlob {
3840 nome: String,
3841 caminho: String,
3842 byte: u8,
3843 },
3844 #[error(
3845 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3846 subshell-grouping metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / \
3847 zsh / dash / ksh / fish / nushell — lexes `(` and `)` as the subshell-grouping \
3848 operator: `(<cmd>)` runs `<cmd>` in a child shell with a fresh environment scope \
3849 (the canonical `(cd <path> && <cmd>)` shell-history one-liner scopes a `cd` to one \
3850 subshell without disturbing the parent's working directory), and `$(<cmd>)` is the \
3851 modern Bourne command-substitution shape the leading-`$` `FonteCaminhoVarExpansion` \
3852 arm closes the leading byte of — together the two arms now structurally exclude the \
3853 entire `$(<cmd>)` substitution surface from the typed `:caminho` accepted set. \
3854 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3855 `:caminho \"../caixa-teia/$(date)/build\"` (the canonical paste-from-shell-history \
3856 modern-command-substitution footgun) or `:caminho \"../(cd foo && pwd)/caixa-teia\"` \
3857 (the symmetric subshell-grouping working-directory-probe paste idiom) silently passes \
3858 every prior arm and the resolver folds the value through `Path::new(caminho).join(\
3859 <file>)` looking for a literal subdirectory and fails at resolve time with a non-\
3860 self-locating `No such file or directory` error far from the source caixa.lisp. The \
3861 lacre pipeline embeds the value verbatim in its per-dep content-address `path:\
3862 {caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 \
3863 closure and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3864 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3865 shell-metachar / subshell-grouping surface every peer single-token-shaped typed slot \
3866 already closes. The peer `:fonte :repo` axis (3b99147) closes the same byte under the \
3867 same shell-subshell-grouping / RFC-3986-sub-delims banner on `is_git_repo_url`, \
3868 together with the leading-`$` `FonteCaminhoVarExpansion` arm closing the leading byte \
3869 of every `$(<cmd>)` shape. Express the path as a bare relative single-token \
3870 like \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3871 subshell-grouping semantic.",
3872 ch = *byte as char
3873 )]
3874 FonteCaminhoShellSubshellGrouping {
3875 nome: String,
3876 caminho: String,
3877 byte: u8,
3878 },
3879 #[error(
3880 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3881 brace-expansion / URI-Template placeholder metacharacter 0x{byte:02x} `{ch}` \
3882 (every POSIX-derived brace-expanding shell — bash / zsh / ksh / fish — lexes `{{` / \
3883 `}}` as the brace-expansion operator: `{{a,b,c}}` expands to the cross-product of \
3884 comma-separated members and `{{1..10}}` expands to the integer range — the \
3885 canonical `mkdir -p ../{{caixa-teia,caixa-helm,caixa-flux}}` / `cp file{{,.bak}}` \
3886 idiom every shell-history block carries; RFC 6570 reserves the matched pair for \
3887 URI Template placeholders (the canonical `https://{{host}}/{{org}}/{{repo}}` \
3888 substitution shape every OpenAPI / Swagger / Postman / GitHub Octokit client \
3889 library / Helm chart-URL fragment carries) and the Mustache / Handlebars / \
3890 Tera / Jinja2 / Go html/template doubled-brace substitution form every IaC \
3891 templating engine (Helm, Kustomize, Terraform's `${{var}}` cousin) emits. POSIX \
3892 `std::path::Path` treats the byte as a literal path-component byte, so a \
3893 `:caminho \"../{{caixa-teia,caixa-helm}}/build\"` (the canonical paste-from-\
3894 shell-history brace-expansion fan-across-siblings footgun) or `:caminho \"../{{{{org}}}}/\
3895 caixa-teia\"` (the symmetric paste-from-templated-doc URI-Template placeholder \
3896 idiom every README quick-start / OpenAPI spec / Helm chart `home:` field carries) \
3897 silently passes every prior arm and the resolver folds the value through \
3898 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3899 resolve time with a non-self-locating `No such file or directory` error far from \
3900 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its \
3901 per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
3902 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
3903 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3904 future operator-side `nix` spawn) as the canonical shell-metachar / brace-\
3905 expansion / URI-Template-placeholder surface every peer single-token-shaped \
3906 typed slot already closes. The peer `:fonte :repo` axis (42d8f9d) closes the \
3907 same byte pair on `is_git_repo_url` under the same RFC-3986-'delims' / \
3908 RFC-6570-URI-Template / shell-brace-expansion banner. Express the path as a \
3909 bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3910 directory name carries no shell-brace-expansion / URI-Template-placeholder \
3911 semantic; if two siblings actually need pinning, author two separate `:deps` \
3912 entries rather than one brace-expanded `:caminho` value.",
3913 ch = *byte as char
3914 )]
3915 FonteCaminhoShellBraceExpansion {
3916 nome: String,
3917 caminho: String,
3918 byte: u8,
3919 },
3920 #[error(
3921 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3922 bracket-expansion / POSIX glob-character-class / shell-`test`-builtin metacharacter \
3923 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / nushell \
3924 — lexes the bracket pair as the glob character-class operator: `[abc]` matches one of \
3925 `a` / `b` / `c`, `[a-z]` matches any lowercase ASCII letter, `[^x]` negates — the \
3926 canonical `ls *.[ch]` C-source-file glob and `cd ../caixa-[a-z]*` lowercase-sibling \
3927 glob every shell-history block carries; the bracket pair additionally carries the \
3928 POSIX `test` / `[` builtin command (`[ -d ../caixa-teia ] && cd ...` every shell-\
3929 script conditional uses) and bash's `[[ ... ]]` extended-test grammar; beyond shell \
3930 the pair is the TOML inline-array delimiter (`features = [\"a\", \"b\"]` — the \
3931 canonical paste-from-Cargo-manifest cross-idiom-leak vector), the YAML flow-sequence \
3932 delimiter (`paths: [/a, /b]` — the canonical paste-from-values.yaml cross-idiom \
3933 leak), the JSON array delimiter, and the POSIX-ERE / PCRE bracket-expression anchor. \
3934 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3935 `:caminho \"../caixa-[a-z]/build\"` (the canonical paste-from-shell-history glob-\
3936 character-class fan-across-siblings footgun) or `:caminho \"../[caixa-teia]/build\"` \
3937 (the symmetric paste-from-TOML-array / paste-from-YAML-flow-sequence cross-idiom \
3938 leak) silently passes every prior arm and the resolver folds the value through \
3939 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3940 resolve time with a non-self-locating `No such file or directory` error far from \
3941 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3942 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3943 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3944 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3945 `nix` spawn) as the canonical shell-metachar / glob-character-class / TOML-array \
3946 surface every peer single-token-shaped typed slot already closes. Express the path \
3947 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3948 directory name carries no shell-bracket-expansion / glob-character-class / array-\
3949 literal semantic; if a family of sibling caixas actually needs pinning, author \
3950 separate `:deps` entries rather than one character-class-expanded `:caminho` value.",
3951 ch = *byte as char
3952 )]
3953 FonteCaminhoShellBracketExpansion {
3954 nome: String,
3955 caminho: String,
3956 byte: u8,
3957 },
3958 #[error(
3959 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3960 quote-grouping / cross-config-DSL string-literal-delimiter metacharacter \
3961 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3962 nushell — lexes `'` as the strong string-literal delimiter (`'…'` — no expansion) \
3963 and `\"` as the weak string-literal delimiter (`\"…\"` — variable- / command-\
3964 substitution-preserving); the canonical `cd '../caixa-teia'` shell-history idiom \
3965 every path-with-embedded-whitespace paste block carries and the symmetric \
3966 `git clone \"$REPO\"` weak-quoted CI-manifest shape both leak the pair verbatim. \
3967 Beyond shell the pair is the JSON string-literal delimiter (`\"key\": \"value\"` — \
3968 the canonical paste-from-JSON-config cross-idiom-leak vector), the YAML double- \
3969 and single-quoted flow-scalar delimiter (`path: \"../caixa-teia\"` — the canonical \
3970 paste-from-values.yaml / paste-from-K8s-YAML-manifest cross-idiom leak), the TOML \
3971 basic and literal string delimiter (`path = \"../caixa-teia\"` — the canonical \
3972 paste-from-Cargo-manifest cross-idiom leak), the tatara-lisp string-literal \
3973 delimiter itself (`(:caminho \"../caixa-teia\")` — the canonical \"I copied the \
3974 entire `:caminho \"...\"` slot rather than just the string body\" author-surface \
3975 footgun), and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which excludes \
3976 both bytes from the `pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"` \
3977 production. POSIX `std::path::Path` treats the byte as a literal path-component \
3978 byte, so a `:caminho \"'../caixa-teia'\"` (the canonical paste-from-shell-history \
3979 strong-quoted sibling-workspace path footgun) or `:caminho \"\\\"../caixa-teia\\\"\"` \
3980 (the symmetric weak-quoted paste-from-JSON / paste-from-YAML flow-scalar / paste-\
3981 from-TOML basic-string / paste-from-tatara-lisp string-literal cross-idiom-leak \
3982 shape) silently passes every prior arm and the resolver folds the value through \
3983 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3984 resolve time with a non-self-locating `No such file or directory` error far from \
3985 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3986 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3987 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3988 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3989 `nix` spawn) as the canonical shell-metachar / string-literal-delimiter surface \
3990 every peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
3991 axis closes both bytes under the same shell-quote-grouping / RFC-3986-sub-delims \
3992 banner (e7a109f `'` shell-single-quote + 4267d8b `\"` shell-double-quote on \
3993 `is_git_repo_url`). Express the path as a bare relative single-token like \
3994 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-quote-\
3995 grouping / string-literal-delimiter semantic; strip the outer quote pair from the \
3996 paste (the tatara-lisp `:caminho \"...\"` slot already carries the string-literal \
3997 quoting on the outer syntactic layer, so an inner quote pair would nest and \
3998 desugar to a broken layer).",
3999 ch = *byte as char
4000 )]
4001 FonteCaminhoShellQuoteGrouping {
4002 nome: String,
4003 caminho: String,
4004 byte: u8,
4005 },
4006 #[error(
4007 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4008 comment / URL-fragment-identifier / YAML-comment cross-config-DSL metacharacter \
4009 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
4010 nushell — lexes an unquoted `#` at the head of a word or after unquoted \
4011 whitespace as the comment-lead per POSIX.1-2017 §2.3 Token Recognition step 6, \
4012 discarding the byte and everything after it to the end of the physical line \
4013 before command parsing (`cd ../caixa-teia # legacy sibling` — the canonical \
4014 paste-from-shell-history-with-trailing-annotation shape every operator-notebook \
4015 and CI-manifest carries); YAML 1.2 §6.6 makes `#` the comment-lead at any \
4016 position preceded by whitespace or at line-start (`path: ../caixa-teia # pin` \
4017 — the canonical paste-from-values.yaml / paste-from-K8s-manifest cross-idiom-\
4018 leak); RFC 3986 §3.5 reserves `#` as the URL fragment-identifier delimiter (the \
4019 canonical paste-from-browser-address-bar `github.com/foo/bar#readme` / \
4020 `github.com/foo/bar#L42` permalink shape, and the symmetric Nix-flake-ref \
4021 cross-idiom leak `github:foo/bar#packageName` where `#` selects a flake \
4022 output); the same cross-config-DSL surface extends to HCL / Terraform / Nix \
4023 flake attributes / dotenv `.env` / gitconfig / .gitignore / ini / TOML where \
4024 `#` is likewise the comment-lead. POSIX `std::path::Path` treats the byte as a \
4025 literal path-component byte, so a `:caminho \"../caixa-teia # legacy sibling\"` \
4026 (the canonical paste-from-shell-history-with-trailing-annotation footgun), \
4027 `:caminho \"../caixa-teia # pin\"` (the symmetric YAML flow-scalar paste-with-\
4028 trailing-comment shape), or `:caminho \"../caixa-teia#readme\"` (the URL \
4029 fragment paste-from-browser-address-bar shape) silently passes every prior arm \
4030 and the resolver folds the value through `Path::new(caminho).join(<file>)` \
4031 looking for a literal subdirectory named `../caixa-teia # legacy sibling` and \
4032 fails at resolve time with a non-self-locating `No such file or directory` \
4033 error far from the source caixa.lisp — while every downstream shell / YAML / \
4034 URL parser silently truncates the value at the `#` byte to `../caixa-teia`, so \
4035 a `feira tofu` shell-out and a `nix flake check` on an emitted YAML `path:` \
4036 scalar disagree with the resolver on which directory the value names. The \
4037 lacre pipeline embeds the value verbatim in its per-dep content-address \
4038 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in \
4039 the BLAKE3 closure and rides into every shell-spawned subprocess (the \
4040 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-\
4041 side `nix` spawn) as the canonical shell-metachar / comment-lead / URL-\
4042 fragment-delimiter surface every peer single-token-shaped typed slot already \
4043 closes. The peer `:fonte :repo` axis closes the byte under the same URL-\
4044 fragment-identifier banner (a68f818 `#` on `is_git_repo_url`). Express the \
4045 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
4046 workspace directory name carries no shell-comment / URL-fragment / YAML-\
4047 comment semantic; move any trailing annotation to a tatara-lisp `;`-comment \
4048 on the surrounding form (`;; legacy sibling` above the `(:caminho ...)` slot) \
4049 and drop any `#fragment` tail entirely (fragment identifiers select \
4050 renderings, not directories, and `:caminho` names a directory).",
4051 ch = *byte as char
4052 )]
4053 FonteCaminhoShellComment {
4054 nome: String,
4055 caminho: String,
4056 byte: u8,
4057 },
4058 #[error(
4059 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains URL-\
4060 percent-encoding-escape / printf-format-specifier / bash-job-control-specifier \
4061 / YAML-directive-lead metacharacter 0x{byte:02x} `{ch}` (RFC 3986 §2.1 reserves \
4062 `%` as the URL percent-encoding-escape — `%HH` is the mandatory encoding \
4063 mechanism for every byte outside the `unreserved` alphanumeric / `-` / `.` / \
4064 `_` / `~` set, and `%` itself must be percent-encoded as `%25` to appear \
4065 literally inside a URL value. The canonical paste-from-browser-address-bar \
4066 percent-encoded-space footgun (an author copies `../caixa%20teia` out of a URL-\
4067 encoded README hyperlink / browser address bar / percent-encoded permalink \
4068 expecting `%20` to decode to a literal space at the filesystem layer) locks two \
4069 distinct BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`) for \
4070 what the author intended as the byte-identical sibling-workspace dep. POSIX \
4071 `std::path::Path` treats the byte as a literal path-component byte, so \
4072 `Path::join` looks for a literal `./{caminho}` subdirectory and fails at \
4073 resolve time with a non-self-locating `No such file or directory` error far \
4074 from the source caixa.lisp — while every downstream URL parser / shell printf \
4075 builtin / YAML directive parser silently reinterprets the byte to a different \
4076 value than the resolver's `Path::join` sees. Beyond the URL-encoding hazard, \
4077 `%` is the C / POSIX printf format-directive lead-in (`%s`, `%d`, `%02x` — \
4078 wired into every POSIX shell's `printf` builtin, the canonical CWE-134 format-\
4079 string-injection vector); the bash / zsh / ksh job-control-specifier lead-in \
4080 (`%1` names \"job 1\", `%%` names \"the current job\", `%foo` names \"the most \
4081 recent job whose command started with `foo`\" — a future `kill %1` invocation \
4082 silently redirects the signal to a wrong target); the YAML 1.2 §6.8.1 \
4083 directive lead-in (`%YAML 1.2` / `%TAG` — the paste-from-top-of-doc YAML \
4084 directive block cross-idiom leak); and the Windows-shell env-var-reference \
4085 lead-in (`%PATH%` — the paste-from-`.bat` / paste-from-PowerShell-`%env:PATH%` \
4086 cross-idiom leak). The lacre pipeline embeds the value verbatim in its per-dep \
4087 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
4088 byte lands in the BLAKE3 closure and rides into every shell-spawned subprocess \
4089 (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4090 operator-side `nix` spawn) as the canonical URL-percent-encoding-escape / \
4091 printf-format-specifier / job-control-specifier surface every peer single-\
4092 token-shaped typed slot already closes. The peer `:fonte :repo` axis closes \
4093 the byte under the same URL-percent-encoding-escape banner (a323db8 `%` on \
4094 `is_git_repo_url`). Express the path as a bare relative single-token like \
4095 \"../caixa-teia\" — the sibling-workspace directory name carries no URL-\
4096 percent-encoding-escape / format-specifier / job-control semantic; substitute \
4097 any `%20` percent-encoded-space with a literal space then reject the whole \
4098 value at the leading-whitespace / embedded-`?` arm on the same axis (a caixa \
4099 directory name never carries an embedded space in practice); drop any \
4100 `%2F`-encoded path separator in favor of a literal `/`; and drop any leading \
4101 `%YAML` / `%PATH%` cross-idiom-leak prefix entirely.",
4102 ch = *byte as char
4103 )]
4104 FonteCaminhoUrlPercentEncoding {
4105 nome: String,
4106 caminho: String,
4107 byte: u8,
4108 },
4109 #[error(
4110 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4111 variable-expansion / command-substitution / arithmetic-expansion / cross-config-\
4112 DSL-interpolation metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / \
4113 bash / zsh / dash / ksh / busybox ash / fish / nushell — lexes `$` per \
4114 POSIX.1-2017 §2.6 as the variable-expansion `$<name>` / braced-form `${{<name>}}` \
4115 / command-substitution `$(<cmd>)` / arithmetic-expansion `$((<expr>))` operator; \
4116 Nix uses `${{var}}` as the string-interpolation lead, Make uses `$(var)` / `$@` \
4117 / `$<` for variables and automatic-variables, JavaScript / TypeScript template \
4118 literals use `${{expr}}` for interpolation, envsubst / Kubernetes / OpenShift \
4119 templates use `${{VAR}}` for env-var-reference, PHP uses `$_GET` / `$_ENV` for \
4120 superglobals, Perl uses `$foo` for scalars, SASS / SCSS uses `$primary-color` \
4121 for variables, and PostgreSQL / SQLite use `$1` / `$2` for bind parameters — \
4122 the byte is a first-class parser byte in nearly every config / templating / \
4123 build-system DSL the substrate's paste-idiom surface routinely crosses. POSIX \
4124 `std::path::Path` treats the byte as a literal path-component byte, so the \
4125 canonical paste-from-shell-one-liner `:caminho \"../foo$HOME/bar\"` / paste-\
4126 from-CI-manifest `:caminho \"../foo${{WORKSPACE}}/bar\"` / paste-from-shell-\
4127 prompt `:caminho \"../foo$(whoami)/bar\"` footguns silently pass every prior \
4128 cascade arm (`$` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / \
4129 `?` / `(` / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%`) and route \
4130 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4131 subdirectory that fails at resolve time with a non-self-locating `No such file \
4132 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4133 the value verbatim in its per-dep content-address `path:{caminho}` at \
4134 caixa-resolver/src/resolve.rs:189, so byte-identical caixa.lisp values differing \
4135 only in whether the author substituted `$HOME` / `${{WORKSPACE}}` at author \
4136 time lock to two distinct BLAKE3 closures across two workstations whose \
4137 downstream envsubst / Nix / Make / K8s-template layers differ in `$VAR` \
4138 recognition — defeating the THEORY.md §V.2 render-determinism contract on the \
4139 same axis every prior `:caminho` arm protects. Beyond the determinism vector, \
4140 `$` at any position in a value flowing verbatim into a shell-spawned subprocess \
4141 is the canonical CWE-78 shell-command-injection surface every peer single-\
4142 token-shaped typed slot already closes: peer `:fonte :repo` axis rejects `$` \
4143 under the shell-variable-expansion / URL-sub-delim banner via `is_git_repo_url` \
4144 (b9d187c), peer `:fonte :tag` / `:fonte :branch` axes reject `$` as part of \
4145 `is_git_ref_name`'s printable-ASCII-restricted grammar (`git check-ref-format` \
4146 rejects the byte outright), and peer `:entrada :paths` axis rejects `$` via \
4147 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. The leading-`$` \
4148 position on the same axis routes through `FonteCaminhoVarExpansion` at the \
4149 f4efe9c leading-byte arm; this arm closes the last positional gap on the byte \
4150 so every position — leading and embedded — is structurally rejected. Substitute \
4151 the `$VAR` / `${{VAR}}` / `$(cmd)` template with the literal value at author \
4152 time, or express the path as a bare relative single-token like \
4153 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
4154 variable-expansion / command-substitution / arithmetic-expansion semantic.",
4155 ch = *byte as char
4156 )]
4157 FonteCaminhoShellVariableExpansion {
4158 nome: String,
4159 caminho: String,
4160 byte: u8,
4161 },
4162 #[error(
4163 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4164 history-expansion / RFC-3986-sub-delims / bang-operator metacharacter 0x{byte:02x} \
4165 `{ch}` (every interactive POSIX shell with history enabled — bash / ksh / zsh's \
4166 `bashcompat` / csh / tcsh — lexes `!` as the history-expansion prefix per bash \
4167 reference §9.3: `!command` re-runs the most recent history entry beginning with \
4168 `command`, `!!` re-runs the prior command verbatim, `!$` substitutes the last \
4169 word of the prior command, `!:N` substitutes the Nth word of the prior command, \
4170 and the substitution fires at every history-expansion-enabled shell context — \
4171 `set -o histexpand` is bash's default for interactive sessions and the layer \
4172 every `feira tofu` / `git clone` / `nix flake check` subprocess-argument \
4173 invocation crosses when spawned under `bash -i`. Beyond shell history, RFC 3986 \
4174 §2.2 lists `!` in the `sub-delims` set (the URL grammar admits the byte inside \
4175 a path segment, but every WHATWG-conformant special-scheme URL parser percent-\
4176 encodes it inside a query component via the 'special-query percent-encode set' \
4177 the peer `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte is \
4178 also the C / C++ / Rust / JavaScript / Python bang-operator (logical-negation \
4179 prefix — the paste-from-source-code idiom where an author copies \
4180 `!path.exists()` out of a Rust snippet and the trailing punctuation crosses \
4181 the string-literal boundary); the canonical English-typography emphasis / \
4182 exclamation mark (the paste-from-prose enthusiasm-form idiom where an author \
4183 writes `:caminho \"../caixa-teia!\"` expecting the substrate to coerce it to a \
4184 kebab-case slug); and the Nix flake-ref attribute-selection operator surface. \
4185 POSIX `std::path::Path` treats `!` as a literal path-component byte, so the \
4186 canonical paste-from-shell-history footgun `:caminho \"../caixa-teia!sudo\"` \
4187 (an author copies a `cd ../caixa-teia && !sudo make install` one-liner from a \
4188 quick-start README and the trailing `!sudo` rides in verbatim as a history-\
4189 expansion reference), the symmetric `:caminho \"../foo!!/bar\"` (the `!!` \
4190 repeat-prior-command paste idiom), the English-typography `:caminho \
4191 \"../caixa-teia!\"` (paste-from-prose enthusiasm-form), and the last-word-\
4192 substitution `:caminho \"../foo!$\"` shape silently pass every prior cascade \
4193 arm (`!` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` \
4194 / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$`) and route \
4195 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4196 subdirectory that fails at resolve time with a non-self-locating `No such file \
4197 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4198 the value verbatim in its per-dep content-address `path:{caminho}` at \
4199 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
4200 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
4201 future `feira tofu` shell-out, a future operator-side `nix flake check` spawn) \
4202 as the canonical shell-history-expansion / RFC-3986-sub-delims surface every \
4203 peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4204 axis closes the byte under the same shell-history-expansion / RFC-3986-sub-\
4205 delims banner (7d53c68 `!` on `is_git_repo_url`). Express the path as a bare \
4206 relative single-token like \"../caixa-teia\" — the sibling-workspace directory \
4207 name carries no shell-history-expansion / bang-operator semantic; drop any \
4208 `!sudo` / `!!` / `!$` history-expansion trailing paste-from-shell-history \
4209 idiom; and drop any trailing English-typography exclamation mark that pasted \
4210 from prose.",
4211 ch = *byte as char
4212 )]
4213 FonteCaminhoShellHistoryExpansion {
4214 nome: String,
4215 caminho: String,
4216 byte: u8,
4217 },
4218 #[error(
4219 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4220 history-substitution / RFC-3986-'unwise' / regex-negation metacharacter 0x{byte:02x} \
4221 `{ch}` (POSIX bash's `set -o histexpand` mode — the default for every interactive \
4222 session and every `bash -i` subprocess-argument context `feira tofu` / `git clone` / \
4223 `nix flake check` cross — lexes `^old^new^` per bash reference §9.3 as the 'quick \
4224 substitution' history operator that rewrites the prior command's `old` string to \
4225 `new` and re-executes it verbatim, the canonical typo-correction one-liner idiom \
4226 (`git clone <bad-url>` → `^bad^good` typo-fix-and-rerun the paste-from-shell-\
4227 history author trims only the leading `git clone` prefix from). RFC 3986 §2 lists \
4228 `^` in the 'unwise' set every URL parser is required to percent-encode-or-refuse at \
4229 the wire boundary, and the WHATWG URL spec's 'fragment percent-encode set' maps \
4230 `^` → `%5E` at the query / fragment component transition, so `Path::join` on the \
4231 literal value diverges from every downstream `feira tofu` curl-invocation / \
4232 artifact-registry-fetch that percent-encodes the byte before the wire. `^` is also \
4233 the regex character-class negation prefix (`[^abc]`), the bitwise XOR operator in \
4234 C / C++ / Rust / Python / JavaScript / Nix / Go, the Windows `cmd.exe` escape \
4235 metacharacter, and the LaTeX / Markdown / BibTeX superscript operator. POSIX \
4236 `std::path::Path` treats `^` as a literal path-component byte, so \
4237 `:caminho \"../foo^bar/baz\"` (embedded quick-substitution), `:caminho \
4238 \"../foo^\"` (trailing history-substitution-open shape), or `:caminho \"../x^y\"` \
4239 (XOR-expression paste-from-source) silently pass every prior cascade arm (`^` \
4240 isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` / `)` / `{{` \
4241 / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$` / `!`) and route through \
4242 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` subdirectory \
4243 that fails at resolve time with a non-self-locating `No such file or directory` \
4244 error far from the source caixa.lisp. The lacre pipeline embeds the value verbatim \
4245 in its per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
4246 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
4247 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4248 operator-side `nix flake check` spawn) as the canonical shell-history-substitution \
4249 / RFC-3986-unwise surface every peer single-token-shaped typed slot already closes. \
4250 The peer `:fonte :repo` axis closes the byte under the same shell-history-\
4251 substitution / RFC-3986-unwise banner (49e142f `^` on `is_git_repo_url`). Together \
4252 with the immediate-predecessor `!` arm (6a04767) this arm closes the full `set -o \
4253 histexpand` operator surface on the `:caminho` axis — the `!command` / `!!` / `!$` \
4254 prefix form via `!`, the `^old^new^` quick-substitution form via `^`. Express the \
4255 path as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
4256 directory name carries no shell-history-substitution / regex-negation / XOR-operator \
4257 semantic; drop any `^old^new` history-substitution paste-from-shell-history idiom; \
4258 drop any trailing `^` history-substitution-open fragment.",
4259 ch = *byte as char
4260 )]
4261 FonteCaminhoShellHistorySubstitution {
4262 nome: String,
4263 caminho: String,
4264 byte: u8,
4265 },
4266 #[error(
4267 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} has a trailing \
4268 `/` (the resolver's `Path::join` resolves `\"../caixa-teia\"` and \
4269 `\"../caixa-teia/\"` to the same directory, but the lacre pipeline embeds the \
4270 value verbatim in its per-dep content-address `path:{caminho}` at \
4271 caixa-resolver/src/resolve.rs:189, so two authors whose only difference is \
4272 shell tab-completion emit byte-divergent BLAKE3 closures for the same caixa — \
4273 defeating the THEORY.md §V.2 render-determinism contract via the trailing-\
4274 separator vector (the canonical paste-from-shell-tab-completion + paste-from-\
4275 `pwd`-with-`/`-suffix footgun, and the canonical Cargo-style `path = \
4276 \"../caixa-teia/\"` paste-from-Cargo-manifest cross-idiom leak). Drop the \
4277 trailing `/`; every `:caminho` value names a sibling-workspace directory \
4278 already, so the trailing separator carries no information. Use \
4279 `\"../caixa-teia\"` rather than `\"../caixa-teia/\"`)"
4280 )]
4281 FonteCaminhoTrailingSlash { nome: String, caminho: String },
4282 #[error(
4283 "{list} carries duplicate entry :nome {nome:?} — every dep list keys its \
4284 entries by caixa name (Cargo's [dependencies] / [dev-dependencies] tables \
4285 apply the same set-not-multiset discipline; one package per table), and \
4286 two entries naming the same caixa carry two version constraints / source \
4287 pins / feature sets for one identity. The caixa-resolver's lacre pipeline \
4288 consumes the list as a `HashMap`-keyed-by-`:nome` lookup: the second entry \
4289 silently overwrites the first at the resolver-side `concrete_versao` step, \
4290 and the dropped entry's pin / features never reach the closure — far from \
4291 the source caixa.lisp, with no field naming which `:deps` entry was the \
4292 silent loser. If two version constraints are genuinely needed (the rare \
4293 multi-version closure case the lacre pipeline doesn't yet support), the \
4294 author surface is two distinct caixa names (e.g. a `caixa-teia-v01` / \
4295 `caixa-teia-v02` aliased pair); within one list, one entry per caixa name."
4296 )]
4297 DuplicateNome { nome: String, list: &'static str },
4298 #[error(
4299 ":deps entry {nome:?} has empty :caracteristicas entry — every feature flag must \
4300 name a non-empty identifier on the target caixa (Cargo's [dependencies.<dep>.features] \
4301 applies the same per-entry non-empty discipline). An empty feature flag reaches the \
4302 caixa-resolver's lacre pipeline as a no-op feature enable, silently dropping the \
4303 author's intent far from the source caixa.lisp; drop the empty entry, or replace it \
4304 with the canonical kebab-case feature name the target caixa declares."
4305 )]
4306 CaracteristicaEmpty { nome: String },
4307 #[error(
4308 ":deps entry {nome:?} :caracteristicas entry {caracteristica:?} is not a valid Cargo \
4309 feature name: {reason} (the value flows verbatim into Cargo's \
4310 [dependencies.<dep>.features] list and Cargo's `restricted_names::validate_feature_name` \
4311 parser enforces the same shape at `cargo metadata` time; use a single-token \
4312 identifier like `\"http\"`, `\"derive\"`, or `\"runtime-tokio\"` — kebab-case ASCII \
4313 alphanumeric with `-`, `_`, `+`, or `.` as continuation characters, starting with \
4314 an ASCII alphanumeric or `_`)"
4315 )]
4316 CaracteristicaInvalid {
4317 nome: String,
4318 caracteristica: String,
4319 reason: String,
4320 },
4321 #[error(
4322 ":deps entry {nome:?} :caracteristicas carries duplicate feature {caracteristica:?} — \
4323 every feature-flag list keys its entries by name (Cargo's \
4324 [dependencies.<dep>.features] applies the same set-not-multiset discipline; one entry \
4325 per feature per dep), and two entries naming the same feature are a redundant \
4326 set-membership declaration for one identity (the feature-toggle slot is set-shaped; \
4327 enabling a feature twice has no additional semantic). The caixa-resolver's lacre \
4328 pipeline consumes the list as a set-shaped feature toggle — the resolver enables the \
4329 feature once regardless of declaration count, so the duplicate's pin / position never \
4330 reaches the closure with no field naming the silent loser. One entry per feature per \
4331 dep; if two distinct features are intended, name each verbatim."
4332 )]
4333 CaracteristicaDuplicate {
4334 nome: String,
4335 caracteristica: String,
4336 },
4337 #[error(
4338 "{list} entry :nome {nome:?} names the caixa itself — a caixa cannot depend \
4339 on itself (the lacre closure's dep-graph traversal is rooted at the caixa's \
4340 :nome, and a self-dep would be a one-node cycle the caixa-resolver either \
4341 rejects mid-traversal far from the source caixa.lisp or recurses on until \
4342 it exhausts its stack). Every :nome is globally-unique substrate identity, \
4343 so a :deps / :deps-dev entry whose :nome equals the parent caixa's :nome \
4344 *is* the parent itself, not a coincidentally-named peer. Drop the \
4345 self-referential dep entry — to reference code from this caixa, use \
4346 :bibliotecas / :exe / :servicos (the substrate-blessed shape for \
4347 referencing the caixa's own code surface) instead."
4348 )]
4349 DepIsSelf { nome: String, list: &'static str },
4350}
4351
4352#[allow(clippy::trivially_copy_pass_by_ref)]
4353fn is_false(b: &bool) -> bool {
4354 !*b
4355}
4356
4357#[cfg(test)]
4358mod tests {
4359 use super::*;
4360
4361 #[test]
4362 fn registry_dep_is_minimal() {
4363 let d = Dep::simple("caixa-teia", "^0.1");
4364 assert_eq!(d.nome, "caixa-teia");
4365 assert_eq!(d.versao, "^0.1");
4366 assert!(d.fonte.is_none());
4367 assert!(!d.opcional());
4368 assert!(d.caracteristicas().is_empty());
4369 }
4370
4371 #[test]
4372 fn git_dep_carries_tag() {
4373 let d = Dep::git("t", "*", "github:o/r", "v1");
4374 match d.fonte {
4375 Some(DepSource::Git {
4376 ref repo, ref tag, ..
4377 }) => {
4378 assert_eq!(repo, "github:o/r");
4379 assert_eq!(tag.as_deref(), Some("v1"));
4380 }
4381 _ => panic!("expected Git source"),
4382 }
4383 }
4384
4385 #[test]
4386 fn validate_accepts_simple_dep() {
4387 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
4388 }
4389
4390 #[test]
4391 fn validate_rejects_empty_nome() {
4392 // The fail-before-pass-after pin for `:nome ""`: the empty-name
4393 // arm fires first so the per-entry parse-side diagnostic doesn't
4394 // emit a useless `nome: ""` reference.
4395 let mut d = Dep::simple("placeholder", "^0.1");
4396 d.nome = String::new();
4397 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4398 }
4399
4400 #[test]
4401 fn validate_rejects_empty_versao() {
4402 // `parse_requirement("")` returns `Ok(VersionReq::STAR)` (the
4403 // semver crate accepts the empty string as a wildcard match),
4404 // so the empty-`:versao` arm is structurally necessary even
4405 // with the parse arm in place — mirrors `MembroVersaoEmpty` /
4406 // `EmptyChildVersion` ordering on the other two `:versao` axes.
4407 let mut d = Dep::simple("caixa-teia", "ignored");
4408 d.versao = String::new();
4409 let err = d.validate().unwrap_err();
4410 assert!(
4411 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4412 "got {err:?}"
4413 );
4414 }
4415
4416 // ── value-shape: DNS-1123 label on :deps :nome ────────────────────────
4417
4418 #[test]
4419 fn validate_rejects_nome_with_uppercase() {
4420 // The fail-before-pass-after pin: a non-empty but uppercase
4421 // `:nome` silently passed `validate()` on every pre-gate
4422 // codebase because the prior shape only refused the empty
4423 // string. The DNS-1123 violation surfaced far downstream at
4424 // lacre-resolve time when the *target* caixa's `:nome` failed
4425 // its own gate — far from the `:deps` entry, with a diagnostic
4426 // naming the target rather than the dep entry that referenced
4427 // it. Same fail-before-pass-after fixture pinned for
4428 // `:membros :caixa` (3f9d7a0), `:children :caixa` (31bfa43),
4429 // and Caixa `:nome` (6c992f8).
4430 let d = Dep::simple("Caixa-Teia", "^0.1");
4431 let err = d.validate().unwrap_err();
4432 assert!(
4433 matches!(
4434 err,
4435 DepError::NomeInvalid { ref nome, ref reason }
4436 if nome == "Caixa-Teia" && reason.contains("uppercase")
4437 ),
4438 "got {err:?}"
4439 );
4440 }
4441
4442 #[test]
4443 fn validate_rejects_nome_with_underscore() {
4444 // RFC 1123 allows `[a-z0-9-]` only; underscore is the canonical
4445 // "I'm thinking of Go module names / Python identifiers" leak.
4446 // Same fixture pinned for the peer caixa-identifier axes.
4447 let d = Dep::simple("caixa_teia", "^0.1");
4448 let err = d.validate().unwrap_err();
4449 assert!(
4450 matches!(
4451 err,
4452 DepError::NomeInvalid { ref nome, ref reason }
4453 if nome == "caixa_teia" && reason.contains('_')
4454 ),
4455 "got {err:?}"
4456 );
4457 }
4458
4459 #[test]
4460 fn validate_rejects_nome_with_dot() {
4461 // A `:deps :nome` is a single DNS-1123 *label*, not a
4462 // subdomain — dots are rejected. The `"caixa.teia"` shape is
4463 // the canonical "I confused the dep name with the FQDN /
4464 // namespace" footgun, distinct from the legitimate
4465 // `:fonte :repo "github:org/caixa-teia"` axis.
4466 let d = Dep::simple("caixa.teia", "^0.1");
4467 let err = d.validate().unwrap_err();
4468 assert!(
4469 matches!(
4470 err,
4471 DepError::NomeInvalid { ref nome, ref reason }
4472 if nome == "caixa.teia" && reason.contains('.')
4473 ),
4474 "got {err:?}"
4475 );
4476 }
4477
4478 #[test]
4479 fn validate_rejects_nome_with_leading_hyphen() {
4480 // RFC 1123 requires alphanumeric at both label boundaries.
4481 // Pinned in parity with the peer DNS-1123 fixtures.
4482 let d = Dep::simple("-caixa-teia", "^0.1");
4483 let err = d.validate().unwrap_err();
4484 assert!(
4485 matches!(
4486 err,
4487 DepError::NomeInvalid { ref nome, ref reason }
4488 if nome == "-caixa-teia" && reason.contains("alphanumeric")
4489 ),
4490 "got {err:?}"
4491 );
4492 }
4493
4494 #[test]
4495 fn validate_rejects_nome_with_trailing_hyphen() {
4496 let d = Dep::simple("caixa-teia-", "^0.1");
4497 let err = d.validate().unwrap_err();
4498 assert!(
4499 matches!(
4500 err,
4501 DepError::NomeInvalid { ref nome, ref reason }
4502 if nome == "caixa-teia-" && reason.contains("alphanumeric")
4503 ),
4504 "got {err:?}"
4505 );
4506 }
4507
4508 #[test]
4509 fn validate_rejects_nome_with_slash() {
4510 // The canonical "I copied the GitHub repo path into `:nome`
4511 // instead of `:fonte :repo`" typo. A `/` in the name leaks the
4512 // lacre-side `:repositorio` shape (`pleme-io/caixa-teia`) into
4513 // the local-name slot. Same fixture pinned for `:membros
4514 // :caixa` (3f9d7a0).
4515 let d = Dep::simple("pleme-io/caixa-teia", "^0.1");
4516 let err = d.validate().unwrap_err();
4517 assert!(
4518 matches!(
4519 err,
4520 DepError::NomeInvalid { ref nome, ref reason }
4521 if nome == "pleme-io/caixa-teia" && reason.contains('/')
4522 ),
4523 "got {err:?}"
4524 );
4525 }
4526
4527 #[test]
4528 fn validate_rejects_nome_too_long() {
4529 // 64-byte label — one over the RFC 1035 / RFC 1123 label cap.
4530 // Built from a valid character set so the length-bound
4531 // diagnostic surfaces before any per-character check (the
4532 // order pin parallel to the per-character predicates inside
4533 // [`crate::render::is_dns_1123_label`]).
4534 let long = "a".repeat(64);
4535 let d = Dep::simple(&long, "^0.1");
4536 let err = d.validate().unwrap_err();
4537 assert!(
4538 matches!(
4539 err,
4540 DepError::NomeInvalid { ref nome, ref reason }
4541 if nome.len() == 64 && reason.contains("max length of 63")
4542 ),
4543 "got {err:?}"
4544 );
4545 }
4546
4547 #[test]
4548 fn validate_accepts_canonical_nome_labels() {
4549 // Positive-control sweep — every form the K8s apiserver
4550 // accepts as a DNS-1123 label must round-trip through
4551 // validate. Covers a hyphen-bearing label, a numeric-suffix
4552 // label, a leading-digit label, a single-character label, and
4553 // a 63-byte (exactly the cap) label — the same fixture set
4554 // the peer `:membros :caixa` / `:children :caixa` positive
4555 // controls pin.
4556 for nome in [
4557 "caixa-teia",
4558 "caixa-resolver2",
4559 "2nd-tier-cache",
4560 "x",
4561 "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0",
4562 ] {
4563 Dep::simple(nome, "^0.1")
4564 .validate()
4565 .unwrap_or_else(|e| panic!("canonical label {nome:?} must validate, got {e:?}"));
4566 }
4567 }
4568
4569 #[test]
4570 fn nome_empty_takes_precedence_over_nome_invalid() {
4571 // Ordering pin: `NomeEmpty` is the more self-locating
4572 // diagnostic on `""` and must lead — `is_dns_1123_label` is
4573 // only reached after the empty-check fires at the call site.
4574 // Mirrors `membro_caixa_empty_takes_precedence_over_invalid`
4575 // (3f9d7a0) on the peer caixa-identifier axis.
4576 let mut d = Dep::simple("placeholder", "^0.1");
4577 d.nome = String::new();
4578 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4579 }
4580
4581 #[test]
4582 fn nome_invalid_fires_before_versao_empty() {
4583 // Ordering pin: a malformed `:nome` fires before any `:versao`
4584 // axis check on the *same* entry — the per-entry shape gates
4585 // run top-to-bottom (nome empty → nome shape → versao empty →
4586 // versao parse → fonte shape), so a one-entry caixa.lisp with
4587 // both wrong sees the name-side diagnostic first (the name is
4588 // the self-locating axis — without a valid name, the parse
4589 // diagnostic can't quote `:nome "<bad>"`). Same ordering
4590 // discipline as `membro_caixa_invalid_fires_before_versao_check`
4591 // (3f9d7a0).
4592 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4593 d.versao = String::new();
4594 let err = d.validate().unwrap_err();
4595 assert!(
4596 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4597 "got {err:?}"
4598 );
4599 }
4600
4601 #[test]
4602 fn nome_invalid_fires_before_versao_invalid() {
4603 // Ordering pin: a malformed `:nome` fires before the `:versao`
4604 // parse-side check on the *same* entry. Pin separately from
4605 // the empty-versao ordering so a future re-ordering surfaces
4606 // here, parallel to the b0c8389 / c4213a4 trajectory.
4607 let d = Dep::simple("Caixa-Teia", "^^0.1");
4608 let err = d.validate().unwrap_err();
4609 assert!(
4610 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4611 "got {err:?}"
4612 );
4613 }
4614
4615 #[test]
4616 fn nome_invalid_fires_before_fonte_invalid() {
4617 // Ordering pin: a malformed `:nome` fires before the `:fonte`
4618 // shape check on the *same* entry. The `:fonte` diagnostic
4619 // names the offending dep's `:nome` verbatim (via
4620 // `DepSource::validate(&self.nome)`), so a non-self-locating
4621 // name would taint the downstream diagnostic too — the gate
4622 // ordering keeps both diagnostics individually self-locating.
4623 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4624 d.fonte = Some(DepSource::Git {
4625 repo: String::new(),
4626 tag: None,
4627 rev: None,
4628 branch: None,
4629 });
4630 let err = d.validate().unwrap_err();
4631 assert!(
4632 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4633 "got {err:?}"
4634 );
4635 }
4636
4637 #[test]
4638 fn nome_invalid_diagnostic_carries_offending_name() {
4639 // The diagnostic-shape pin: the error names the offending
4640 // `:nome` value verbatim so the author can grep their
4641 // caixa.lisp without re-running the build, and carries a
4642 // non-empty `reason` from `is_dns_1123_label` so the
4643 // predicate's own wording flows through to the diagnostic.
4644 // Same shape as `MembroCaixaInvalid` (3f9d7a0),
4645 // `ChildCaixaInvalid` (31bfa43), `ManifestError::NomeInvalid`
4646 // (6c992f8) — the four DNS-1123 caixa-identifier axes now
4647 // share a structurally-equivalent diagnostic family.
4648 let d = Dep::simple("Caixa_Teia", "^0.1");
4649 let err = d.validate().unwrap_err();
4650 let DepError::NomeInvalid { nome, reason } = err else {
4651 panic!("expected NomeInvalid, got other variant");
4652 };
4653 assert_eq!(nome, "Caixa_Teia");
4654 assert!(
4655 !reason.is_empty(),
4656 "NomeInvalid `reason` must carry the predicate's wording verbatim"
4657 );
4658 }
4659
4660 #[test]
4661 fn validate_rejects_invalid_versao_requirement() {
4662 // The fail-before-pass-after pin: a non-empty but malformed
4663 // requirement (`"^bad-version"`) silently passed every pre-gate
4664 // codebase because `:deps :versao` wasn't validated. The parse
4665 // failure surfaced far downstream at lacre-resolve time with a
4666 // `semver::Error` that didn't name which `:deps` entry carried
4667 // the typo. The new gate moves the check to caixa-build time
4668 // at the source caixa.lisp.
4669 let d = Dep::simple("caixa-teia", "^bad-version");
4670 let err = d.validate().unwrap_err();
4671 assert!(
4672 matches!(
4673 err,
4674 DepError::VersaoInvalid { ref nome, ref versao, .. }
4675 if nome == "caixa-teia" && versao == "^bad-version"
4676 ),
4677 "got {err:?}"
4678 );
4679 }
4680
4681 #[test]
4682 fn validate_rejects_versao_with_double_caret_typo() {
4683 // `"^^0.1"` is the canonical doubled-caret typo — looks like a
4684 // Cargo-shaped requirement on first glance but fails the parser
4685 // because semver doesn't accept stacked operators. Pin this
4686 // adjacent-shape footgun explicitly so a future relaxation that
4687 // accepts "looks-canonical-but-isn't" forms surfaces here, in
4688 // parity with the `:membros` / `:children` fixtures.
4689 let d = Dep::simple("caixa-teia", "^^0.1");
4690 let err = d.validate().unwrap_err();
4691 assert!(
4692 matches!(
4693 err,
4694 DepError::VersaoInvalid { ref nome, ref versao, .. }
4695 if nome == "caixa-teia" && versao == "^^0.1"
4696 ),
4697 "got {err:?}"
4698 );
4699 }
4700
4701 #[test]
4702 fn validate_rejects_versao_with_v_prefixed_tag() {
4703 // `"v0.1"` is the canonical "git-tag-shape leaking into the
4704 // semver requirement slot" typo — an author copies the
4705 // publish-side git-tag string verbatim into `:versao`, but
4706 // Cargo's semver parser rejects the leading `v`. Same fixture
4707 // pinned for `:membros :versao` (9888b13) and `:children
4708 // :versao` (b38ff3a). (Bare `x`-glob shorthands like `^0.1.x`
4709 // are *accepted* by the semver crate as an `*` wildcard on the
4710 // patch axis — they're a Cargo-side valid shape, not a typo.)
4711 let d = Dep::simple("caixa-teia", "v0.1");
4712 let err = d.validate().unwrap_err();
4713 assert!(
4714 matches!(
4715 err,
4716 DepError::VersaoInvalid { ref nome, ref versao, .. }
4717 if nome == "caixa-teia" && versao == "v0.1"
4718 ),
4719 "got {err:?}"
4720 );
4721 }
4722
4723 #[test]
4724 fn validate_accepts_canonical_versao_forms() {
4725 // The five Cargo-shaped requirement forms `:membros :versao`
4726 // and `:children :versao` already accept via
4727 // `crate::parse_requirement` must pass the deps gate without
4728 // re-validating at the resolver layer. Pin every leg so a
4729 // future tightening of the canonical set surfaces here as a
4730 // test failure.
4731 for form in [
4732 "^0.1", // caret — minor-range pin (the most common shape)
4733 "~0.1.2", // tilde — patch-range pin
4734 "0.1.0", // exact — single-version pin
4735 "*", // wildcard — explicitly any-version
4736 ">=0.1, <2", // multi-range — comma-separated comparators
4737 ] {
4738 Dep::simple("caixa-teia", form)
4739 .validate()
4740 .unwrap_or_else(|e| panic!("canonical form {form:?} must validate, got {e:?}"));
4741 }
4742 }
4743
4744 #[test]
4745 fn versao_empty_takes_precedence_over_invalid() {
4746 // Order pin: the existing `VersaoEmpty` diagnostic (which
4747 // doesn't try to parse) fires before the new `VersaoInvalid`
4748 // parse-side diagnostic, so an empty `:versao` keeps its
4749 // narrower error message — `parse_requirement("")` would
4750 // otherwise return `Ok(STAR)` and silently pass, but the empty
4751 // arm catches it first.
4752 let mut d = Dep::simple("caixa-teia", "ignored");
4753 d.versao = String::new();
4754 let err = d.validate().unwrap_err();
4755 assert!(
4756 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4757 "got {err:?}"
4758 );
4759 }
4760
4761 #[test]
4762 fn nome_empty_takes_precedence_over_versao_invalid() {
4763 // Order pin: even when `:versao` is malformed and would raise
4764 // its own diagnostic, `:nome ""` fires first because the
4765 // per-entry parse diagnostic needs a non-empty name to be
4766 // self-locating. Mirrors the
4767 // `membros_validation_runs_before_contratos_membership_check`
4768 // ordering on the typed-graph layer.
4769 let mut d = Dep::simple("placeholder", "^bad");
4770 d.nome = String::new();
4771 let err = d.validate().unwrap_err();
4772 assert_eq!(err, DepError::NomeEmpty);
4773 }
4774
4775 #[test]
4776 fn versao_invalid_diagnostic_carries_offending_versao() {
4777 // The diagnostic-shape pin: the error names the offending
4778 // `:versao` value verbatim so the author can grep their
4779 // caixa.lisp without re-running the build, and carries a
4780 // non-empty `reason` from `semver::VersionReq::parse` so the
4781 // parser's own wording flows through to the diagnostic.
4782 let d = Dep::simple("caixa-teia", "not-a-req");
4783 let err = d.validate().unwrap_err();
4784 let DepError::VersaoInvalid {
4785 nome,
4786 versao,
4787 reason,
4788 } = err
4789 else {
4790 panic!("expected VersaoInvalid, got other variant");
4791 };
4792 assert_eq!(nome, "caixa-teia");
4793 assert_eq!(versao, "not-a-req");
4794 assert!(
4795 !reason.is_empty(),
4796 "VersaoInvalid `reason` must carry the parser's wording verbatim"
4797 );
4798 }
4799
4800 // -- :fonte value-shape gate ------------------------------------------
4801
4802 fn dep_with_fonte(fonte: DepSource) -> Dep {
4803 let mut d = Dep::simple("caixa-teia", "^0.1");
4804 d.fonte = Some(fonte);
4805 d
4806 }
4807
4808 #[test]
4809 fn validate_accepts_git_fonte_with_tag() {
4810 // The positive-control pin on the canonical git source — exactly
4811 // one of :tag/:rev/:branch set, non-empty :repo. Mirrors the
4812 // shape every existing caixa-resolver integration test uses.
4813 let d = dep_with_fonte(DepSource::Git {
4814 repo: "github:pleme-io/caixa-teia".into(),
4815 tag: Some("v0.1.0".into()),
4816 rev: None,
4817 branch: None,
4818 });
4819 d.validate().unwrap();
4820 }
4821
4822 #[test]
4823 fn validate_accepts_git_fonte_with_rev() {
4824 // Each of the three pin axes is independently a valid single-pin
4825 // shape; pin the :rev arm so a future relaxation that only
4826 // accepts :tag surfaces here. The value is a full 40-hex SHA-1
4827 // OID — the canonical `git rev-parse HEAD` emission shape the
4828 // `crate::render::is_git_oid` value-shape gate now requires;
4829 // abbreviated OIDs are ambiguous across repo history and
4830 // rejected at this gate (pinned separately by
4831 // `validate_rejects_git_fonte_with_rev_abbreviated_prefix`).
4832 let d = dep_with_fonte(DepSource::Git {
4833 repo: "github:pleme-io/caixa-teia".into(),
4834 tag: None,
4835 rev: Some("c0ffee0123abcdef0123456789abcdef01234567".into()),
4836 branch: None,
4837 });
4838 d.validate().unwrap();
4839 }
4840
4841 #[test]
4842 fn validate_accepts_git_fonte_with_branch() {
4843 // The :branch arm is the third valid single-pin shape — pinned
4844 // separately so the gate-accepts-all-three-pin-axes contract is
4845 // a build-error to relax.
4846 let d = dep_with_fonte(DepSource::Git {
4847 repo: "github:pleme-io/caixa-teia".into(),
4848 tag: None,
4849 rev: None,
4850 branch: Some("main".into()),
4851 });
4852 d.validate().unwrap();
4853 }
4854
4855 #[test]
4856 fn validate_accepts_path_fonte() {
4857 // The positive-control pin on the path source — non-empty
4858 // :caminho, no pin axes (paths have no commit identity). Pinned
4859 // so a future "paths must also pin a rev" tightening surfaces
4860 // here as a structural decision, not a silent break.
4861 let d = dep_with_fonte(DepSource::Path {
4862 caminho: "../caixa-teia".into(),
4863 });
4864 d.validate().unwrap();
4865 }
4866
4867 #[test]
4868 fn validate_rejects_git_fonte_with_empty_repo() {
4869 // The fail-before-pass-after pin for `(:tipo git :repo "" :tag
4870 // "v1")`: the empty-repo shape silently passed every pre-gate
4871 // codebase because `:fonte` wasn't validated. The git-clone
4872 // failure surfaced far downstream at lacre-resolve time with no
4873 // field naming which `:deps` entry carried the typo. The new
4874 // gate moves the check to caixa-build time at the source
4875 // caixa.lisp.
4876 let d = dep_with_fonte(DepSource::Git {
4877 repo: String::new(),
4878 tag: Some("v0.1.0".into()),
4879 rev: None,
4880 branch: None,
4881 });
4882 let err = d.validate().unwrap_err();
4883 assert!(
4884 matches!(err, DepError::FonteRepoEmpty { ref nome } if nome == "caixa-teia"),
4885 "got {err:?}"
4886 );
4887 }
4888
4889 // -- :repo value-shape gate -------------------------------------------
4890 //
4891 // The `:fonte (:tipo git :repo …)` value flows verbatim into the
4892 // caixa-resolver's `git clone <repo>` subprocess. The pre-gate
4893 // codebase admitted any non-empty string; the new
4894 // [`crate::render::is_git_repo_url`] predicate gates the git-porcelain
4895 // URL intersection-floor at validate time, peer with the three pin
4896 // axes (`:tag` + `:branch` via `is_git_ref_name`, `:rev` via
4897 // `is_git_oid`). Every test in this section is a fail-before /
4898 // pass-after pin on a specific authoring footgun.
4899
4900 #[test]
4901 fn validate_rejects_git_fonte_with_repo_carrying_trailing_space() {
4902 // The canonical paste-from-doc footgun on `:repo` — an author
4903 // copies `"github:pleme-io/caixa-teia "` (trailing space) out of
4904 // a doc paragraph. Until this gate landed the empty-repo arm
4905 // passed (the string isn't empty), the resolver issued
4906 // `git clone 'github:pleme-io/caixa-teia '`, and the failure
4907 // surfaced at clone time with a quoting-confused error far from
4908 // the source caixa.lisp. Same paste-from-doc footgun the
4909 // `:tag "v0.1.0 "` gate (e70d213) closes on the peer refname
4910 // axis — now closed on the `:repo` URL axis too.
4911 let d = dep_with_fonte(DepSource::Git {
4912 repo: "github:pleme-io/caixa-teia ".into(),
4913 tag: Some("v0.1.0".into()),
4914 rev: None,
4915 branch: None,
4916 });
4917 let err = d.validate().unwrap_err();
4918 let DepError::FonteRepoShape { nome, repo, reason } = err else {
4919 panic!("expected FonteRepoShape, got other variant");
4920 };
4921 assert_eq!(nome, "caixa-teia");
4922 assert_eq!(repo, "github:pleme-io/caixa-teia ");
4923 assert!(
4924 reason.contains("whitespace"),
4925 "reason must surface the whitespace arm, got {reason:?}"
4926 );
4927 }
4928
4929 #[test]
4930 fn validate_rejects_git_fonte_with_repo_starting_with_dash() {
4931 // The canonical CLI-argument-injection footgun at the `git clone`
4932 // subprocess boundary — `:repo "-upload-pack=evil"` makes git's
4933 // argv parser read the value as a CLI flag, escaping the
4934 // subprocess argument boundary. The `--` separator workaround
4935 // does not fix the typed slot's accepted set; the gate rejects
4936 // the shape upstream at validate time so the resolver never
4937 // invokes a `git clone -…` subprocess.
4938 let d = dep_with_fonte(DepSource::Git {
4939 repo: "-upload-pack=evil".into(),
4940 tag: Some("v0.1.0".into()),
4941 rev: None,
4942 branch: None,
4943 });
4944 let err = d.validate().unwrap_err();
4945 let DepError::FonteRepoShape { repo, reason, .. } = err else {
4946 panic!("expected FonteRepoShape, got other variant");
4947 };
4948 assert_eq!(repo, "-upload-pack=evil");
4949 assert!(
4950 reason.contains("must not start with `-`"),
4951 "reason must surface the leading-`-` arm, got {reason:?}"
4952 );
4953 }
4954
4955 #[test]
4956 fn validate_rejects_git_fonte_with_repo_carrying_embedded_newline() {
4957 // The canonical paste-from-multiline-doc footgun — a `:repo`
4958 // string with an embedded `\n` silently breaks git's URL parser
4959 // and is a class of CRLF-injection at the subprocess-argument
4960 // boundary. Caught by the control-char arm (0x0A < 0x20).
4961 let d = dep_with_fonte(DepSource::Git {
4962 repo: "github:pleme-io/caixa-teia\nrm -rf /".into(),
4963 tag: Some("v0.1.0".into()),
4964 rev: None,
4965 branch: None,
4966 });
4967 let err = d.validate().unwrap_err();
4968 let DepError::FonteRepoShape { reason, .. } = err else {
4969 panic!("expected FonteRepoShape, got other variant");
4970 };
4971 assert!(
4972 reason.contains("control character"),
4973 "reason must surface the control-char arm, got {reason:?}"
4974 );
4975 }
4976
4977 #[test]
4978 fn validate_rejects_git_fonte_with_repo_carrying_tab() {
4979 // Tab is the sibling whitespace footgun (the canonical
4980 // copy-from-aligned-table paste); pinned separately from the
4981 // space arm so a future relaxation that only catches one
4982 // surfaces here.
4983 let d = dep_with_fonte(DepSource::Git {
4984 repo: "github:pleme-io/caixa-teia\t".into(),
4985 tag: Some("v0.1.0".into()),
4986 rev: None,
4987 branch: None,
4988 });
4989 let err = d.validate().unwrap_err();
4990 assert!(
4991 matches!(
4992 err,
4993 DepError::FonteRepoShape { ref reason, .. }
4994 if reason.contains("whitespace")
4995 ),
4996 "got {err:?}"
4997 );
4998 }
4999
5000 #[test]
5001 fn validate_rejects_git_fonte_with_repo_carrying_non_ascii() {
5002 // IDN hosts must be pre-encoded as Punycode (`xn--…`) — raw
5003 // non-ASCII silently breaks at git's URL parser and round-trips
5004 // inconsistently across NFC/NFD normalization on APFS /
5005 // case-folding filesystems. Same intersection-floor
5006 // [`is_git_ref_name`] enforces on the refname axes.
5007 let d = dep_with_fonte(DepSource::Git {
5008 repo: "https://github.com/pleme-io/café".into(),
5009 tag: Some("v0.1.0".into()),
5010 rev: None,
5011 branch: None,
5012 });
5013 let err = d.validate().unwrap_err();
5014 assert!(
5015 matches!(
5016 err,
5017 DepError::FonteRepoShape { ref reason, .. }
5018 if reason.contains("non-ASCII")
5019 ),
5020 "got {err:?}"
5021 );
5022 }
5023
5024 #[test]
5025 fn validate_rejects_git_fonte_with_repo_carrying_fragment_anchor() {
5026 // The fail-before-pass-after pin for the canonical paste-from-
5027 // browser-address-bar footgun on `:repo`: an author copies a
5028 // GitHub permalink to a README anchor / line-permalink and
5029 // forgets to trim the `#fragment` tail. Until this arm landed
5030 // `:repo "https://github.com/pleme-io/caixa-teia#readme"`
5031 // silently passed every prior arm (no whitespace, no control
5032 // chars, no non-ASCII, contains a `:`, doesn't start with `-`
5033 // or `:`), libcurl's URL parser stripped the `#readme` tail
5034 // before opening the HTTPS transport, and the lacre embedded
5035 // the value verbatim in its per-dep BLAKE3 closure — two
5036 // authors whose values differ only in their fragment anchor
5037 // (`#readme` vs `#L42`) resolve to the byte-identical upstream
5038 // `git clone` but lock to two distinct lacres, defeating the
5039 // THEORY.md §V.2 render-determinism contract. Same value-shape
5040 // axis-floor every peer typed surface enforces; peer `:fonte
5041 // :tag` / `:fonte :branch` already reject the byte-class through
5042 // `is_git_ref_name`'s alphabet (refs are leaf identifiers, no
5043 // URL grammar admitted) and `:entrada :paths` rejects `#` as
5044 // part of `is_gateway_api_http_path`'s RFC-3986-reserved set.
5045 let d = dep_with_fonte(DepSource::Git {
5046 repo: "https://github.com/pleme-io/caixa-teia#readme".into(),
5047 tag: Some("v0.1.0".into()),
5048 rev: None,
5049 branch: None,
5050 });
5051 let err = d.validate().unwrap_err();
5052 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5053 panic!("expected FonteRepoShape, got other variant");
5054 };
5055 assert_eq!(nome, "caixa-teia");
5056 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia#readme");
5057 assert!(
5058 reason.contains("must not contain `#`"),
5059 "reason must surface the fragment-`#` arm, got {reason:?}"
5060 );
5061 assert!(
5062 reason.contains("fragment"),
5063 "reason must name the URL fragment grammar, got {reason:?}"
5064 );
5065 }
5066
5067 #[test]
5068 fn validate_rejects_git_fonte_with_repo_carrying_flake_ref_fragment() {
5069 // The symmetric paste-from-Nix-flake-ref footgun — an author
5070 // confuses the Nix flake-reference idiom (`github:foo/
5071 // bar#packageName`, where `#packageName` selects a flake
5072 // output) with the bare git `:repo` shape. The pleme-io
5073 // substrate authors compose flakes downstream of caixa
5074 // (caixa-flake renders a flake.nix), so the cross-idiom leak
5075 // is the canonical near-miss: the author writes the
5076 // flake-ref shape into a git `:repo` slot. Pinned separately
5077 // from the HTTPS-anchor arm so a future relaxation that
5078 // narrows to one URL scheme surfaces here.
5079 let d = dep_with_fonte(DepSource::Git {
5080 repo: "github:pleme-io/caixa-teia#caixa-teia".into(),
5081 tag: Some("v0.1.0".into()),
5082 rev: None,
5083 branch: None,
5084 });
5085 let err = d.validate().unwrap_err();
5086 let DepError::FonteRepoShape { reason, .. } = err else {
5087 panic!("expected FonteRepoShape, got other variant");
5088 };
5089 assert!(
5090 reason.contains("must not contain `#`"),
5091 "reason must surface the fragment-`#` arm, got {reason:?}"
5092 );
5093 assert!(
5094 reason.contains("Nix flake"),
5095 "reason must name the Nix-flake-ref cross-idiom footgun, got {reason:?}"
5096 );
5097 }
5098
5099 #[test]
5100 fn validate_rejects_git_fonte_with_repo_carrying_query_string() {
5101 // The fail-before-pass-after pin for the canonical paste-from-
5102 // browser-address-bar footgun on `:repo` (peer with the
5103 // a68f818 fragment-`#` arm on the same axis). An author
5104 // copies a GitHub tab deep-link out of the address bar and
5105 // forgets to trim the `?tab=…` query tail. Until this arm
5106 // landed `:repo "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"`
5107 // silently passed every prior arm (no whitespace, no control
5108 // chars, no non-ASCII, no `#` fragment, contains a `:`,
5109 // doesn't start with `-` or `:`); GitHub silently ignored
5110 // the `?query` tail and served the same repo regardless;
5111 // the lacre embedded the value verbatim in its per-dep
5112 // BLAKE3 closure — two authors whose values differ only in
5113 // their query tail (`?tab=readme-ov-file` vs `?ref=main` vs
5114 // `?utm_source=twitter`) resolve to the byte-identical
5115 // upstream `git clone` but lock to two distinct lacres,
5116 // defeating the THEORY.md §V.2 render-determinism contract
5117 // on the same axis the `#` fragment arm closes. Same value-
5118 // shape axis-floor every peer typed surface enforces; peer
5119 // `:fonte :tag` / `:fonte :branch` already reject the byte-
5120 // class through `is_git_ref_name`'s alphabet (refspec glob
5121 // wildcards, caixa-core/src/render.rs:1426) and `:entrada
5122 // :paths` rejects `?` as the query separator in
5123 // `is_gateway_api_http_path` (caixa-core/src/render.rs:473).
5124 let d = dep_with_fonte(DepSource::Git {
5125 repo: "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file".into(),
5126 tag: Some("v0.1.0".into()),
5127 rev: None,
5128 branch: None,
5129 });
5130 let err = d.validate().unwrap_err();
5131 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5132 panic!("expected FonteRepoShape, got other variant");
5133 };
5134 assert_eq!(nome, "caixa-teia");
5135 assert_eq!(
5136 repo,
5137 "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"
5138 );
5139 assert!(
5140 reason.contains("must not contain `?`"),
5141 "reason must surface the query-`?` arm, got {reason:?}"
5142 );
5143 assert!(
5144 reason.contains("query"),
5145 "reason must name the URL query grammar, got {reason:?}"
5146 );
5147 }
5148
5149 #[test]
5150 fn validate_rejects_git_fonte_with_repo_carrying_utm_tracker() {
5151 // The symmetric paste-from-social-share footgun — an author
5152 // copies a repo URL out of a Slack unfurl / Twitter share /
5153 // newsletter link / Discord embed and forgets to trim the
5154 // `?utm_source=…` / `?utm_medium=…` / `?utm_campaign=…`
5155 // campaign-tracker tail. Every major social-share / unfurl /
5156 // newsletter platform appends these UTM parameters; the
5157 // canonical near-miss on the `:repo` axis. Pinned separately
5158 // from the GitHub-tab-deep-link arm so a future relaxation
5159 // that narrows to one query-parameter class surfaces here.
5160 let d = dep_with_fonte(DepSource::Git {
5161 repo: "https://github.com/pleme-io/caixa-teia?utm_source=twitter&utm_campaign=launch"
5162 .into(),
5163 tag: Some("v0.1.0".into()),
5164 rev: None,
5165 branch: None,
5166 });
5167 let err = d.validate().unwrap_err();
5168 let DepError::FonteRepoShape { reason, .. } = err else {
5169 panic!("expected FonteRepoShape, got other variant");
5170 };
5171 assert!(
5172 reason.contains("must not contain `?`"),
5173 "reason must surface the query-`?` arm, got {reason:?}"
5174 );
5175 assert!(
5176 reason.contains("campaign-tracker"),
5177 "reason must name the campaign-tracker paste footgun, got {reason:?}"
5178 );
5179 }
5180
5181 #[test]
5182 fn fonte_repo_fragment_fires_before_query_when_fragment_first() {
5183 // Cascade pin: the fragment-`#` arm and the query-`?` arm are
5184 // both per-byte arms inside the same `for &b in s.as_bytes()`
5185 // loop, so the byte that appears first in the value's byte
5186 // order wins. A `:repo "https://github.com/p/x#readme?ref=main"`
5187 // (fragment before query — unusual URL-grammar but value-
5188 // disjoint at byte level) carries both `#` and `?`; the `#`
5189 // byte appears first, so the fragment-`#` arm fires, surfacing
5190 // the more self-locating diagnostic on the byte the author
5191 // pasted earliest in the URL. Mirrors the peer cascade
5192 // discipline `fonte_repo_control_char_fires_before_fragment`
5193 // pins on the prior `:repo` byte-class arm.
5194 let d = dep_with_fonte(DepSource::Git {
5195 repo: "https://github.com/pleme-io/caixa-teia#readme?ref=main".into(),
5196 tag: Some("v0.1.0".into()),
5197 rev: None,
5198 branch: None,
5199 });
5200 let err = d.validate().unwrap_err();
5201 let DepError::FonteRepoShape { reason, .. } = err else {
5202 panic!("expected FonteRepoShape, got other variant");
5203 };
5204 assert!(
5205 reason.contains("must not contain `#`"),
5206 "reason must surface the fragment-`#` arm (fires before query-`?` when \
5207 `#` byte appears first in value), got {reason:?}"
5208 );
5209 }
5210
5211 #[test]
5212 fn fonte_repo_control_char_fires_before_fragment() {
5213 // Cascade pin: the control-char arm structurally precedes the
5214 // fragment-`#` arm. A value like `"github:p/x\n#readme"` probes
5215 // positive on both arms (contains LF and `#`), but the narrower
5216 // POSIX-syscall-rejected / CRLF-injection-class diagnostic
5217 // (`control character`) wins so the author sees the more
5218 // self-locating arm first. Mirrors the peer cascade discipline
5219 // every prior `:repo` byte-class arm establishes.
5220 let d = dep_with_fonte(DepSource::Git {
5221 repo: "github:pleme-io/caixa-teia\n#readme".into(),
5222 tag: Some("v0.1.0".into()),
5223 rev: None,
5224 branch: None,
5225 });
5226 let err = d.validate().unwrap_err();
5227 let DepError::FonteRepoShape { reason, .. } = err else {
5228 panic!("expected FonteRepoShape, got other variant");
5229 };
5230 assert!(
5231 reason.contains("control character"),
5232 "reason must surface the control-char arm, got {reason:?}"
5233 );
5234 }
5235
5236 #[test]
5237 fn validate_rejects_git_fonte_with_repo_carrying_embedded_backslash() {
5238 // The fail-before-pass-after pin for the canonical Windows-
5239 // file-path-confusion footgun on `:repo` (peer with the 3a4e1d7
5240 // backslash arm on the sibling `:caminho` path-fonte axis).
5241 // An author pastes a Windows Explorer address-bar / PowerShell
5242 // `Get-Location` output into a `file://` URL slot, producing
5243 // `file:///C:\Users\me\caixa-teia`. Until this arm landed the
5244 // value silently passed every prior arm (no whitespace, no
5245 // control chars, no non-ASCII, no `#`, no `?`, doesn't start
5246 // with `-` or `:`); libcurl's URL parser silently translates
5247 // `\` → `/` on some platforms and refuses it on others, so
5248 // the byte rides verbatim into the lacre's per-dep content-
5249 // address but is silently rewritten / rejected at the wire —
5250 // two authors whose `:repo` values differ only in backslash-
5251 // vs-forward-slash (`file:///C:\path` vs `file:///C:/path`)
5252 // resolve to the byte-identical local clone but lock to two
5253 // distinct BLAKE3 closures, defeating the THEORY.md §V.2
5254 // render-determinism contract on the same axis the `#`
5255 // fragment and `?` query arms close. Same value-shape axis-
5256 // floor every peer typed surface enforces; the `:caminho`
5257 // 3a4e1d7 arm closes the same byte on the path-fonte axis.
5258 let d = dep_with_fonte(DepSource::Git {
5259 repo: "file:///C:\\Users\\me\\caixa-teia".into(),
5260 tag: Some("v0.1.0".into()),
5261 rev: None,
5262 branch: None,
5263 });
5264 let err = d.validate().unwrap_err();
5265 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5266 panic!("expected FonteRepoShape, got other variant");
5267 };
5268 assert_eq!(nome, "caixa-teia");
5269 assert_eq!(repo, "file:///C:\\Users\\me\\caixa-teia");
5270 assert!(
5271 reason.contains("must not contain `\\`"),
5272 "reason must surface the backslash-`\\` arm, got {reason:?}"
5273 );
5274 assert!(
5275 reason.contains("Windows"),
5276 "reason must name the Windows-path-confusion footgun, got {reason:?}"
5277 );
5278 }
5279
5280 #[test]
5281 fn validate_rejects_git_fonte_with_repo_carrying_mangled_https_backslashes() {
5282 // The symmetric Win32-shell-mangled-slashes footgun — an author
5283 // copies `https://github.com/foo/bar` into a Win32 shell that
5284 // rewrites every `/` to `\` (the canonical `cmd.exe` path-
5285 // separator-coercion bug), pastes the result into a `:repo`
5286 // slot, and produces `https:\\github.com\foo\bar`. Pinned
5287 // separately from the `file://` Explorer-paste arm so a future
5288 // relaxation that narrows to one URL scheme surfaces here.
5289 let d = dep_with_fonte(DepSource::Git {
5290 repo: "https:\\\\github.com\\pleme-io\\caixa-teia".into(),
5291 tag: Some("v0.1.0".into()),
5292 rev: None,
5293 branch: None,
5294 });
5295 let err = d.validate().unwrap_err();
5296 let DepError::FonteRepoShape { reason, .. } = err else {
5297 panic!("expected FonteRepoShape, got other variant");
5298 };
5299 assert!(
5300 reason.contains("must not contain `\\`"),
5301 "reason must surface the backslash-`\\` arm, got {reason:?}"
5302 );
5303 assert!(
5304 reason.contains("path separator") || reason.contains("path-segment separator"),
5305 "reason must name the URL path-segment separator grammar, got {reason:?}"
5306 );
5307 }
5308
5309 #[test]
5310 fn fonte_repo_fragment_fires_before_backslash_when_fragment_first() {
5311 // Cascade pin: the fragment-`#` arm and the backslash-`\` arm
5312 // are both per-byte arms inside the same `for &b in s.as_bytes()`
5313 // loop, so the byte that appears first in the value's byte order
5314 // wins. A `:repo "https://github.com/p/x#readme\\foo"` carries
5315 // both `#` and `\`; the `#` byte appears first, so the fragment-
5316 // `#` arm fires, surfacing the more self-locating diagnostic on
5317 // the byte the author pasted earliest in the URL. Mirrors the
5318 // peer cascade discipline `fonte_repo_fragment_fires_before_query_when_fragment_first`
5319 // pins on the prior `:repo` byte-class arm.
5320 let d = dep_with_fonte(DepSource::Git {
5321 repo: "https://github.com/pleme-io/caixa-teia#readme\\foo".into(),
5322 tag: Some("v0.1.0".into()),
5323 rev: None,
5324 branch: None,
5325 });
5326 let err = d.validate().unwrap_err();
5327 let DepError::FonteRepoShape { reason, .. } = err else {
5328 panic!("expected FonteRepoShape, got other variant");
5329 };
5330 assert!(
5331 reason.contains("must not contain `#`"),
5332 "reason must surface the fragment-`#` arm (fires before backslash-`\\` when \
5333 `#` byte appears first in value), got {reason:?}"
5334 );
5335 }
5336
5337 #[test]
5338 fn validate_rejects_git_fonte_with_repo_carrying_uri_template_placeholder() {
5339 // The fail-before-pass-after pin for the canonical URI Template
5340 // (RFC 6570) placeholder footgun on `:repo`. An author copies a
5341 // README quick-start snippet / OpenAPI `servers:` URL / Helm
5342 // chart `home:` template that carries unresolved
5343 // `{org}` / `{repo}` placeholders and pastes the raw template
5344 // into the `:repo` slot, expecting the substrate to resolve the
5345 // placeholder downstream. Until this arm landed the value
5346 // silently passed every prior arm (no whitespace, no control
5347 // chars, no non-ASCII, no `#`, no `?`, no `\`, doesn't start
5348 // with `-` or `:`); libcurl percent-encodes `{` / `}` to `%7B`
5349 // / `%7D` on the wire, so the byte rides verbatim into the
5350 // lacre's per-dep content-address but round-trips inconsistently
5351 // between the lacre's per-dep content-address and the
5352 // resolver's `git clone <repo>` invocation, defeating the
5353 // THEORY.md §V.2 render-determinism contract on the same axis
5354 // the `#` fragment, `?` query, and `\` backslash arms close;
5355 // every git porcelain entry-point additionally fetches a
5356 // nonexistent literal-`{placeholder}`-named path far from the
5357 // source caixa.lisp.
5358 let d = dep_with_fonte(DepSource::Git {
5359 repo: "https://github.com/{org}/caixa-teia".into(),
5360 tag: Some("v0.1.0".into()),
5361 rev: None,
5362 branch: None,
5363 });
5364 let err = d.validate().unwrap_err();
5365 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5366 panic!("expected FonteRepoShape, got other variant");
5367 };
5368 assert_eq!(nome, "caixa-teia");
5369 assert_eq!(repo, "https://github.com/{org}/caixa-teia");
5370 assert!(
5371 reason.contains("must not contain `{`"),
5372 "reason must surface the open-brace `{{` arm, got {reason:?}"
5373 );
5374 assert!(
5375 reason.contains("URI Template") || reason.contains("RFC 6570"),
5376 "reason must name the RFC 6570 URI Template grammar, got {reason:?}"
5377 );
5378 }
5379
5380 #[test]
5381 fn validate_rejects_git_fonte_with_repo_carrying_handlebars_doubled_brace() {
5382 // The symmetric Mustache / Handlebars doubled-brace
5383 // substitution-form footgun every CI / IaC templating engine
5384 // (Argo Workflows, Jinja2, Liquid, Vue / Angular interpolation,
5385 // GitHub Actions `${{ … }}` even though Actions uses `${{`) /
5386 // chart README quick-start snippet emits. Pinned separately
5387 // from the single-`{` `{org}` arm so a future relaxation that
5388 // narrows to one substitution-form surfaces here.
5389 let d = dep_with_fonte(DepSource::Git {
5390 repo: "https://github.com/{{org}}/caixa-teia".into(),
5391 tag: Some("v0.1.0".into()),
5392 rev: None,
5393 branch: None,
5394 });
5395 let err = d.validate().unwrap_err();
5396 let DepError::FonteRepoShape { reason, .. } = err else {
5397 panic!("expected FonteRepoShape, got other variant");
5398 };
5399 assert!(
5400 reason.contains("must not contain `{`"),
5401 "reason must surface the open-brace `{{` arm, got {reason:?}"
5402 );
5403 }
5404
5405 #[test]
5406 fn validate_rejects_git_fonte_with_repo_carrying_closing_brace_only() {
5407 // Asymmetric `}`-only shape — covers the closing-brace-by-
5408 // itself footgun (an author truncated `{org}/{repo}` mid-edit
5409 // and left a trailing `}` from the prior template fragment,
5410 // or pasted a value that included a closing brace from a
5411 // surrounding shell context). Pinned to ensure the predicate
5412 // refuses each brace independently rather than only when both
5413 // appear — a future regression that ANDs the two byte tests
5414 // surfaces here.
5415 let d = dep_with_fonte(DepSource::Git {
5416 repo: "https://github.com/pleme-io/caixa-teia}".into(),
5417 tag: Some("v0.1.0".into()),
5418 rev: None,
5419 branch: None,
5420 });
5421 let err = d.validate().unwrap_err();
5422 let DepError::FonteRepoShape { reason, .. } = err else {
5423 panic!("expected FonteRepoShape, got other variant");
5424 };
5425 assert!(
5426 reason.contains("must not contain `}`"),
5427 "reason must surface the close-brace `}}` arm, got {reason:?}"
5428 );
5429 }
5430
5431 #[test]
5432 fn fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first() {
5433 // Cascade pin: the fragment-`#` arm and the template-`{` /
5434 // `}` arm are both per-byte arms inside the same
5435 // `for &b in s.as_bytes()` loop, so the byte that appears
5436 // first in the value's byte order wins. A `:repo
5437 // "https://github.com/p/x#readme{org}"` carries both `#` and
5438 // `{`; the `#` byte appears first, so the fragment-`#` arm
5439 // fires, surfacing the more self-locating diagnostic on the
5440 // byte the author pasted earliest in the URL. Mirrors the
5441 // peer cascade discipline `fonte_repo_fragment_fires_before_backslash_when_fragment_first`
5442 // pins on the prior `:repo` byte-class arm.
5443 let d = dep_with_fonte(DepSource::Git {
5444 repo: "https://github.com/pleme-io/caixa-teia#readme{org}".into(),
5445 tag: Some("v0.1.0".into()),
5446 rev: None,
5447 branch: None,
5448 });
5449 let err = d.validate().unwrap_err();
5450 let DepError::FonteRepoShape { reason, .. } = err else {
5451 panic!("expected FonteRepoShape, got other variant");
5452 };
5453 assert!(
5454 reason.contains("must not contain `#`"),
5455 "reason must surface the fragment-`#` arm (fires before template-`{{` when \
5456 `#` byte appears first in value), got {reason:?}"
5457 );
5458 }
5459
5460 #[test]
5461 fn validate_rejects_git_fonte_with_repo_carrying_output_redirection() {
5462 // The fail-before-pass-after pin for the canonical
5463 // shell-output-redirection footgun on `:repo`: an author
5464 // pastes a shell-pipeline tail (`git clone <repo> > build.log`
5465 // / `… >output.txt`) into the `:repo` slot without trimming
5466 // the redirect. Until this arm landed the value silently
5467 // passed every prior arm (no whitespace, no control chars,
5468 // no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, doesn't
5469 // start with `-` or `:`); RFC 3986 §2 lists `<` / `>` in the
5470 // 'delims' / 'unwise' set and the WHATWG URL spec's fragment
5471 // percent-encode set maps `>` → `%3E` on the wire, so the
5472 // byte rides verbatim into the lacre's per-dep BLAKE3 closure
5473 // but is silently rewritten or rejected at libcurl's URL-
5474 // parser layer — two authors whose values differ only in
5475 // their redirect tail (`>build.log` vs nothing) resolve to
5476 // the byte-identical upstream `git clone` but lock to two
5477 // distinct lacres, defeating the THEORY.md §V.2 render-
5478 // determinism contract. Peer with the `:caminho` axis's
5479 // `FonteCaminhoShellRedirection` arm (e457141) on the sibling
5480 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5481 // byte RFC-3986-reserved set on `:entrada :paths`.
5482 let d = dep_with_fonte(DepSource::Git {
5483 repo: "https://github.com/pleme-io/caixa-teia>build.log".into(),
5484 tag: Some("v0.1.0".into()),
5485 rev: None,
5486 branch: None,
5487 });
5488 let err = d.validate().unwrap_err();
5489 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5490 panic!("expected FonteRepoShape, got other variant");
5491 };
5492 assert_eq!(nome, "caixa-teia");
5493 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia>build.log");
5494 assert!(
5495 reason.contains("must not contain `>`"),
5496 "reason must surface the output-redirection `>` arm, got {reason:?}"
5497 );
5498 assert!(
5499 reason.contains("redirection") || reason.contains("'delims'"),
5500 "reason must name the shell-redirection / RFC-3986-unwise rationale, got {reason:?}"
5501 );
5502 }
5503
5504 #[test]
5505 fn validate_rejects_git_fonte_with_repo_carrying_input_redirection() {
5506 // The symmetric shell-input-redirection footgun — an author
5507 // pastes a shell-pipeline head (`git clone <input.url` /
5508 // `cat <README.md`) into the `:repo` slot. Pinned separately
5509 // from the `>`-output arm so a future relaxation that only
5510 // catches one of the two redirect bytes surfaces here. Peer
5511 // with the `:caminho` axis's `FonteCaminhoShellRedirection`
5512 // arm which closes both `<` and `>` under the same banner.
5513 let d = dep_with_fonte(DepSource::Git {
5514 repo: "https://github.com/pleme-io/caixa-teia<input.url".into(),
5515 tag: Some("v0.1.0".into()),
5516 rev: None,
5517 branch: None,
5518 });
5519 let err = d.validate().unwrap_err();
5520 let DepError::FonteRepoShape { reason, .. } = err else {
5521 panic!("expected FonteRepoShape, got other variant");
5522 };
5523 assert!(
5524 reason.contains("must not contain `<`"),
5525 "reason must surface the input-redirection `<` arm, got {reason:?}"
5526 );
5527 assert!(
5528 reason.contains("RFC 3986") || reason.contains("'unwise'"),
5529 "reason must name the RFC 3986 'unwise' grammar, got {reason:?}"
5530 );
5531 }
5532
5533 #[test]
5534 fn validate_rejects_git_fonte_with_repo_carrying_backtick_command_substitution() {
5535 // The fail-before-pass-after pin for the canonical
5536 // paste-from-shell-prompt-with-backticked-substitution footgun
5537 // on `:repo` (peer with the c4d62b3 backtick arm on the sibling
5538 // `:caminho` path-fonte axis). An author pastes a URL whose
5539 // segment carries a backticked command-substitution wrapper
5540 // (`` `whoami` ``, `` `git config user.name` ``, `` `pwd` ``)
5541 // from a doc / README quick-start snippet that expected the
5542 // substrate to substitute the value downstream. Until this arm
5543 // landed the value silently passed every prior arm (no
5544 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5545 // no `\`, no `{`/`}`, no `<`/`>`, doesn't start with `-` or
5546 // `:`); RFC 3986 §2 lists the backtick byte in the 'delims' /
5547 // 'unwise' set and the WHATWG URL spec's fragment percent-
5548 // encode set maps `` ` `` → `%60` on the wire, so the byte
5549 // rides verbatim into the lacre's per-dep BLAKE3 closure but
5550 // is silently rewritten or rejected at libcurl's URL-parser
5551 // layer — two authors whose values differ only in their
5552 // backtick wrapper (`` `whoami` `` vs nothing) resolve to the
5553 // byte-identical upstream `git clone` but lock to two distinct
5554 // lacres, defeating the THEORY.md §V.2 render-determinism
5555 // contract. Peer with the `:caminho` axis's
5556 // `FonteCaminhoShellCommandSubstitution` arm (c4d62b3) on the
5557 // sibling path-fonte axis, and `is_gateway_api_http_path`'s
5558 // eleven-byte RFC-3986-reserved set on `:entrada :paths`.
5559 let d = dep_with_fonte(DepSource::Git {
5560 repo: "https://github.com/pleme-io/`whoami`/caixa-teia".into(),
5561 tag: Some("v0.1.0".into()),
5562 rev: None,
5563 branch: None,
5564 });
5565 let err = d.validate().unwrap_err();
5566 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5567 panic!("expected FonteRepoShape, got other variant");
5568 };
5569 assert_eq!(nome, "caixa-teia");
5570 assert_eq!(repo, "https://github.com/pleme-io/`whoami`/caixa-teia");
5571 assert!(
5572 reason.contains("must not contain `` ` ``"),
5573 "reason must surface the backtick command-substitution arm, got {reason:?}"
5574 );
5575 assert!(
5576 reason.contains("command-substitution") || reason.contains("'unwise'"),
5577 "reason must name the shell-command-substitution / RFC-3986-unwise rationale, \
5578 got {reason:?}"
5579 );
5580 }
5581
5582 #[test]
5583 fn fonte_repo_fragment_fires_before_backtick_when_fragment_first() {
5584 // Cascade pin: the fragment-`#` arm and the backtick command-
5585 // substitution arm are both per-byte arms inside the same
5586 // `for &b in s.as_bytes()` loop, so the byte that appears first
5587 // in the value's byte order wins. A `:repo
5588 // "https://github.com/p/x#readme/`whoami`"` carries both `#`
5589 // and backtick; the `#` byte appears first, so the fragment-
5590 // `#` arm fires, surfacing the more self-locating diagnostic
5591 // on the byte the author pasted earliest in the URL. Mirrors
5592 // the peer cascade discipline
5593 // `fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first`
5594 // pins on the prior `:repo` byte-class arm.
5595 let d = dep_with_fonte(DepSource::Git {
5596 repo: "https://github.com/pleme-io/caixa-teia#readme/`whoami`".into(),
5597 tag: Some("v0.1.0".into()),
5598 rev: None,
5599 branch: None,
5600 });
5601 let err = d.validate().unwrap_err();
5602 let DepError::FonteRepoShape { reason, .. } = err else {
5603 panic!("expected FonteRepoShape, got other variant");
5604 };
5605 assert!(
5606 reason.contains("must not contain `#`"),
5607 "reason must surface the fragment-`#` arm (fires before backtick when `#` byte \
5608 appears first in value), got {reason:?}"
5609 );
5610 }
5611
5612 #[test]
5613 fn fonte_repo_shell_redirection_fires_before_backtick_when_redirection_first() {
5614 // Cascade pin: the shell-redirection `<` / `>` arm and the
5615 // backtick command-substitution arm are both per-byte arms
5616 // inside the same `for &b in s.as_bytes()` loop, so the byte
5617 // that appears first in the value's byte order wins. A `:repo
5618 // "https://github.com/p/x>build.log/`whoami`"` carries both
5619 // `>` and backtick; the `>` byte appears first, so the
5620 // shell-redirection arm fires, surfacing the more self-
5621 // locating diagnostic on the byte the author pasted earliest
5622 // in the URL. Pins the natural-order cascade so a future
5623 // reorder of the per-byte arms surfaces here.
5624 let d = dep_with_fonte(DepSource::Git {
5625 repo: "https://github.com/pleme-io/caixa-teia>build.log/`whoami`".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 shell-redirection `>` arm (fires before backtick when \
5637 `>` byte appears first in value), got {reason:?}"
5638 );
5639 }
5640
5641 #[test]
5642 fn fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first() {
5643 // Cascade pin: the fragment-`#` arm and the shell-redirection
5644 // `<` / `>` arm are both per-byte arms inside the same
5645 // `for &b in s.as_bytes()` loop, so the byte that appears
5646 // first in the value's byte order wins. A `:repo
5647 // "https://github.com/p/x#readme>build.log"` carries both
5648 // `#` and `>`; the `#` byte appears first, so the fragment-
5649 // `#` arm fires, surfacing the more self-locating diagnostic
5650 // on the byte the author pasted earliest in the URL. Mirrors
5651 // the peer cascade discipline
5652 // `fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first`
5653 // pins on the prior `:repo` byte-class arm.
5654 let d = dep_with_fonte(DepSource::Git {
5655 repo: "https://github.com/pleme-io/caixa-teia#readme>build.log".into(),
5656 tag: Some("v0.1.0".into()),
5657 rev: None,
5658 branch: None,
5659 });
5660 let err = d.validate().unwrap_err();
5661 let DepError::FonteRepoShape { reason, .. } = err else {
5662 panic!("expected FonteRepoShape, got other variant");
5663 };
5664 assert!(
5665 reason.contains("must not contain `#`"),
5666 "reason must surface the fragment-`#` arm (fires before shell-redirection `>` when \
5667 `#` byte appears first in value), got {reason:?}"
5668 );
5669 }
5670
5671 #[test]
5672 fn validate_rejects_git_fonte_with_repo_carrying_shell_pipe() {
5673 // The fail-before-pass-after pin for the canonical
5674 // paste-from-shell-prompt-with-piped-pipeline footgun on
5675 // `:repo` (peer with the 124106f pipe arm on the sibling
5676 // `:caminho` path-fonte axis). An author pastes a shell
5677 // pipeline (`git clone <url> | tee build.log`,
5678 // `git ls-remote <url> | head`) into the `:repo` slot,
5679 // forgetting to trim the `| <consumer>` tail. Until this arm
5680 // landed the value silently passed every prior arm (no
5681 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5682 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, doesn't start
5683 // with `-` or `:`); RFC 3986 §2 lists the pipe byte in the
5684 // 'unwise' set and the WHATWG URL spec's fragment percent-
5685 // encode set maps `|` → `%7C` on the wire, so the byte rides
5686 // verbatim into the lacre's per-dep BLAKE3 closure but is
5687 // silently rewritten or rejected at libcurl's URL-parser
5688 // layer — two authors whose values differ only in their pipe
5689 // tail (`|tee build.log` vs nothing) resolve to the byte-
5690 // identical upstream `git clone` but lock to two distinct
5691 // lacres, defeating the THEORY.md §V.2 render-determinism
5692 // contract. Peer with the `:caminho` axis's
5693 // `FonteCaminhoShellPipe` arm (124106f) on the sibling path-
5694 // fonte axis, and `is_gateway_api_http_path`'s eleven-byte
5695 // RFC-3986-reserved set on `:entrada :paths`.
5696 let d = dep_with_fonte(DepSource::Git {
5697 repo: "https://github.com/pleme-io/caixa-teia|tee build.log".into(),
5698 tag: Some("v0.1.0".into()),
5699 rev: None,
5700 branch: None,
5701 });
5702 let err = d.validate().unwrap_err();
5703 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5704 panic!("expected FonteRepoShape, got other variant");
5705 };
5706 assert_eq!(nome, "caixa-teia");
5707 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia|tee build.log");
5708 assert!(
5709 reason.contains("must not contain `|`"),
5710 "reason must surface the shell-pipe arm, got {reason:?}"
5711 );
5712 assert!(
5713 reason.contains("pipe") || reason.contains("'unwise'"),
5714 "reason must name the shell-pipe / RFC-3986-unwise rationale, got {reason:?}"
5715 );
5716 }
5717
5718 #[test]
5719 fn fonte_repo_fragment_fires_before_pipe_when_fragment_first() {
5720 // Cascade pin: the fragment-`#` arm and the pipe arm are both
5721 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5722 // so the byte that appears first in the value's byte order
5723 // wins. A `:repo "https://github.com/p/x#readme|tee"` carries
5724 // both `#` and `|`; the `#` byte appears first, so the
5725 // fragment-`#` arm fires, surfacing the more self-locating
5726 // diagnostic on the byte the author pasted earliest in the
5727 // URL. Mirrors the peer cascade discipline
5728 // `fonte_repo_fragment_fires_before_backtick_when_fragment_first`
5729 // pins on the prior `:repo` byte-class arm.
5730 let d = dep_with_fonte(DepSource::Git {
5731 repo: "https://github.com/pleme-io/caixa-teia#readme|tee".into(),
5732 tag: Some("v0.1.0".into()),
5733 rev: None,
5734 branch: None,
5735 });
5736 let err = d.validate().unwrap_err();
5737 let DepError::FonteRepoShape { reason, .. } = err else {
5738 panic!("expected FonteRepoShape, got other variant");
5739 };
5740 assert!(
5741 reason.contains("must not contain `#`"),
5742 "reason must surface the fragment-`#` arm (fires before pipe when `#` byte \
5743 appears first in value), got {reason:?}"
5744 );
5745 }
5746
5747 #[test]
5748 fn fonte_repo_backtick_fires_before_pipe_when_backtick_first() {
5749 // Cascade pin: the backtick arm and the pipe arm are both per-
5750 // byte arms inside the same `for &b in s.as_bytes()` loop, so
5751 // the byte that appears first in the value's byte order wins.
5752 // A `:repo "https://github.com/p/x/`whoami`|tee"` carries both
5753 // `` ` `` and `|`; the backtick byte appears first, so the
5754 // backtick arm fires, surfacing the more self-locating
5755 // diagnostic on the byte the author pasted earliest in the
5756 // URL. Pins the natural-order cascade so a future reorder of
5757 // the per-byte arms surfaces here.
5758 let d = dep_with_fonte(DepSource::Git {
5759 repo: "https://github.com/pleme-io/caixa-teia/`whoami`|tee".into(),
5760 tag: Some("v0.1.0".into()),
5761 rev: None,
5762 branch: None,
5763 });
5764 let err = d.validate().unwrap_err();
5765 let DepError::FonteRepoShape { reason, .. } = err else {
5766 panic!("expected FonteRepoShape, got other variant");
5767 };
5768 assert!(
5769 reason.contains("must not contain `` ` ``"),
5770 "reason must surface the backtick arm (fires before pipe when `` ` `` byte \
5771 appears first in value), got {reason:?}"
5772 );
5773 }
5774
5775 #[test]
5776 fn validate_rejects_git_fonte_with_repo_carrying_shell_command_separator() {
5777 // The fail-before-pass-after pin for the canonical
5778 // paste-from-shell-prompt-with-sequential-command-tail footgun
5779 // on `:repo` (peer with the 05c358e `;` arm on the sibling
5780 // `:caminho` path-fonte axis). An author pastes a shell
5781 // one-liner that chained a cleanup tail after the URL
5782 // (`git clone <url>; rm -rf build`, `git ls-remote <url>;
5783 // echo done`) into the `:repo` slot, forgetting to trim the
5784 // `; <cmd>` tail. Until this arm landed the value silently
5785 // passed every prior `is_git_repo_url` arm (no whitespace, no
5786 // control chars, no non-ASCII, no `#`, no `?`, no `\`, no
5787 // `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, doesn't start with
5788 // `-` or `:`); RFC 3986 §2 lists `;` in the 'sub-delims' /
5789 // reserved set and the WHATWG URL spec's fragment percent-
5790 // encode set maps `;` → `%3B` on the wire, so the byte rides
5791 // verbatim into the lacre's per-dep BLAKE3 closure but is
5792 // silently rewritten at libcurl's URL-parser layer — two
5793 // authors whose values differ only in their sequential-command
5794 // tail (`; rm -rf build` vs nothing) resolve to the byte-
5795 // identical upstream `git clone` but lock to two distinct
5796 // lacres, defeating the THEORY.md §V.2 render-determinism
5797 // contract. Peer with the `:caminho` axis's
5798 // `FonteCaminhoShellSemicolon` arm (05c358e) on the sibling
5799 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5800 // byte RFC-3986-reserved set on `:entrada :paths`.
5801 let d = dep_with_fonte(DepSource::Git {
5802 repo: "https://github.com/pleme-io/caixa-teia; rm -rf build".into(),
5803 tag: Some("v0.1.0".into()),
5804 rev: None,
5805 branch: None,
5806 });
5807 let err = d.validate().unwrap_err();
5808 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5809 panic!("expected FonteRepoShape, got other variant");
5810 };
5811 assert_eq!(nome, "caixa-teia");
5812 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia; rm -rf build");
5813 assert!(
5814 reason.contains("must not contain `;`"),
5815 "reason must surface the shell-command-separator arm, got {reason:?}"
5816 );
5817 assert!(
5818 reason.contains("sequential-command") || reason.contains("'sub-delims'"),
5819 "reason must name the shell-command-separator / RFC-3986-sub-delims \
5820 rationale, got {reason:?}"
5821 );
5822 }
5823
5824 #[test]
5825 fn fonte_repo_fragment_fires_before_semicolon_when_fragment_first() {
5826 // Cascade pin: the fragment-`#` arm and the semicolon arm are
5827 // both per-byte arms inside the same `for &b in s.as_bytes()`
5828 // loop, so the byte that appears first in the value's byte
5829 // order wins. A `:repo "https://github.com/p/x#readme; rm"`
5830 // carries both `#` and `;`; the `#` byte appears first, so the
5831 // fragment-`#` arm fires, surfacing the more self-locating
5832 // diagnostic on the byte the author pasted earliest in the URL.
5833 // Mirrors the peer cascade discipline
5834 // `fonte_repo_fragment_fires_before_pipe_when_fragment_first`
5835 // pins on the prior `:repo` byte-class arm.
5836 let d = dep_with_fonte(DepSource::Git {
5837 repo: "https://github.com/pleme-io/caixa-teia#readme; rm".into(),
5838 tag: Some("v0.1.0".into()),
5839 rev: None,
5840 branch: None,
5841 });
5842 let err = d.validate().unwrap_err();
5843 let DepError::FonteRepoShape { reason, .. } = err else {
5844 panic!("expected FonteRepoShape, got other variant");
5845 };
5846 assert!(
5847 reason.contains("must not contain `#`"),
5848 "reason must surface the fragment-`#` arm (fires before semicolon when `#` \
5849 byte appears first in value), got {reason:?}"
5850 );
5851 }
5852
5853 #[test]
5854 fn fonte_repo_pipe_fires_before_semicolon_when_pipe_first() {
5855 // Cascade pin: the pipe arm and the semicolon arm are both
5856 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5857 // so the byte that appears first in the value's byte order
5858 // wins. A `:repo "https://github.com/p/x|tee; rm"` carries
5859 // both `|` and `;`; the `|` byte appears first, so the
5860 // pipe arm fires, surfacing the more self-locating diagnostic
5861 // on the byte the author pasted earliest in the URL. Pins the
5862 // natural-order cascade so a future reorder of the per-byte
5863 // arms surfaces here.
5864 let d = dep_with_fonte(DepSource::Git {
5865 repo: "https://github.com/pleme-io/caixa-teia|tee; rm".into(),
5866 tag: Some("v0.1.0".into()),
5867 rev: None,
5868 branch: None,
5869 });
5870 let err = d.validate().unwrap_err();
5871 let DepError::FonteRepoShape { reason, .. } = err else {
5872 panic!("expected FonteRepoShape, got other variant");
5873 };
5874 assert!(
5875 reason.contains("must not contain `|`"),
5876 "reason must surface the pipe arm (fires before semicolon when `|` byte \
5877 appears first in value), got {reason:?}"
5878 );
5879 }
5880
5881 #[test]
5882 fn validate_rejects_git_fonte_with_repo_carrying_shell_background() {
5883 // The fail-before-pass-after pin for the canonical
5884 // paste-from-shell-prompt-with-background-launch-tail footgun
5885 // on `:repo` (peer with the e12e4f3 `&` arm on the sibling
5886 // `:caminho` path-fonte axis). An author pastes a shell one-
5887 // liner that detached the clone into the background
5888 // (`git clone <url> & sleep 1`, `git clone <url> && cd …`)
5889 // into the `:repo` slot, forgetting to trim the `& <cmd>` /
5890 // `&& <cmd>` tail. Until this arm landed the value silently
5891 // passed every prior `is_git_repo_url` arm (no whitespace,
5892 // no control chars, no non-ASCII, no `#`, no `?`, no `\`,
5893 // no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
5894 // doesn't start with `-` or `:`); RFC 3986 §2 lists `&` in
5895 // the 'sub-delims' / reserved set and the WHATWG URL spec's
5896 // fragment percent-encode set maps `&` → `%26` on the wire,
5897 // so the byte rides verbatim into the lacre's per-dep
5898 // BLAKE3 closure but is silently rewritten at libcurl's
5899 // URL-parser layer — two authors whose values differ only
5900 // in their background-launch tail (`& sleep 1` vs nothing)
5901 // resolve to the byte-identical upstream `git clone` but
5902 // lock to two distinct lacres, defeating the THEORY.md
5903 // §V.2 render-determinism contract. Peer with the
5904 // `:caminho` axis's `FonteCaminhoShellBackground` arm
5905 // (e12e4f3) on the sibling path-fonte axis, and
5906 // `is_gateway_api_http_path`'s eleven-byte RFC-3986-
5907 // reserved set on `:entrada :paths`.
5908 let d = dep_with_fonte(DepSource::Git {
5909 repo: "https://github.com/pleme-io/caixa-teia&sleep".into(),
5910 tag: Some("v0.1.0".into()),
5911 rev: None,
5912 branch: None,
5913 });
5914 let err = d.validate().unwrap_err();
5915 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5916 panic!("expected FonteRepoShape, got other variant");
5917 };
5918 assert_eq!(nome, "caixa-teia");
5919 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia&sleep");
5920 assert!(
5921 reason.contains("must not contain `&`"),
5922 "reason must surface the shell-background / logical-AND arm, got {reason:?}"
5923 );
5924 assert!(
5925 reason.contains("background-task") || reason.contains("'sub-delims'"),
5926 "reason must name the shell-background / RFC-3986-sub-delims rationale, \
5927 got {reason:?}"
5928 );
5929 }
5930
5931 #[test]
5932 fn validate_rejects_git_fonte_with_repo_carrying_logical_and() {
5933 // The fail-before-pass-after pin for the symmetric `&&`
5934 // logical-AND build-chain paste footgun: an author pastes
5935 // a `git clone <url> && cd <repo>` build-chain one-liner
5936 // and forgets to trim the `&& <cmd>` tail. The `&&` shape
5937 // is the same `&` byte twice in a row; the per-byte arm
5938 // fires on the first `&` it sees. Pinned separately from
5939 // the single-`&` background-launch shape so a future
5940 // diagnostic-surface change that special-cased the
5941 // doubled-byte form surfaces here.
5942 let d = dep_with_fonte(DepSource::Git {
5943 repo: "github:pleme-io/caixa-teia&&echo".into(),
5944 tag: Some("v0.1.0".into()),
5945 rev: None,
5946 branch: None,
5947 });
5948 let err = d.validate().unwrap_err();
5949 let DepError::FonteRepoShape { reason, .. } = err else {
5950 panic!("expected FonteRepoShape, got other variant");
5951 };
5952 assert!(
5953 reason.contains("must not contain `&`"),
5954 "reason must surface the shell-background / logical-AND arm on the doubled-`&&` \
5955 shape too, got {reason:?}"
5956 );
5957 }
5958
5959 #[test]
5960 fn fonte_repo_fragment_fires_before_background_when_fragment_first() {
5961 // Cascade pin: the fragment-`#` arm and the background-`&`
5962 // arm are both per-byte arms inside the same `for &b in
5963 // s.as_bytes()` loop, so the byte that appears first in the
5964 // value's byte order wins. A `:repo
5965 // "https://github.com/p/x#readme & sleep"` carries both `#`
5966 // and `&`; the `#` byte appears first, so the fragment-`#`
5967 // arm fires, surfacing the more self-locating diagnostic on
5968 // the byte the author pasted earliest in the URL. Mirrors
5969 // the peer cascade discipline
5970 // `fonte_repo_fragment_fires_before_semicolon_when_fragment_first`
5971 // on the prior `:repo` byte-class arm.
5972 let d = dep_with_fonte(DepSource::Git {
5973 repo: "https://github.com/pleme-io/caixa-teia#readme&sleep".into(),
5974 tag: Some("v0.1.0".into()),
5975 rev: None,
5976 branch: None,
5977 });
5978 let err = d.validate().unwrap_err();
5979 let DepError::FonteRepoShape { reason, .. } = err else {
5980 panic!("expected FonteRepoShape, got other variant");
5981 };
5982 assert!(
5983 reason.contains("must not contain `#`"),
5984 "reason must surface the fragment-`#` arm (fires before background-`&` when `#` \
5985 byte appears first in value), got {reason:?}"
5986 );
5987 }
5988
5989 #[test]
5990 fn fonte_repo_semicolon_fires_before_background_when_semicolon_first() {
5991 // Cascade pin: the semicolon arm and the background-`&` arm
5992 // are both per-byte arms inside the same `for &b in
5993 // s.as_bytes()` loop, so the byte that appears first in the
5994 // value's byte order wins. A `:repo
5995 // "https://github.com/p/x; rm & sleep"` carries both `;` and
5996 // `&`; the `;` byte appears first, so the semicolon arm
5997 // fires, surfacing the more self-locating diagnostic on the
5998 // byte the author pasted earliest in the URL. Pins the
5999 // natural-order cascade so a future reorder of the per-byte
6000 // arms surfaces here.
6001 let d = dep_with_fonte(DepSource::Git {
6002 repo: "https://github.com/pleme-io/caixa-teia;rm&sleep".into(),
6003 tag: Some("v0.1.0".into()),
6004 rev: None,
6005 branch: None,
6006 });
6007 let err = d.validate().unwrap_err();
6008 let DepError::FonteRepoShape { reason, .. } = err else {
6009 panic!("expected FonteRepoShape, got other variant");
6010 };
6011 assert!(
6012 reason.contains("must not contain `;`"),
6013 "reason must surface the semicolon arm (fires before background-`&` when `;` \
6014 byte appears first in value), got {reason:?}"
6015 );
6016 }
6017
6018 #[test]
6019 fn validate_rejects_git_fonte_with_repo_carrying_shell_variable_expansion() {
6020 // The fail-before-pass-after pin for the canonical
6021 // paste-from-shell-prompt-with-unsubstituted-variable footgun
6022 // on `:repo` (peer with the f4efe9c `$` arm on the sibling
6023 // `:caminho` path-fonte axis). An author pastes a shell one-
6024 // liner that referenced an environment variable
6025 // (`git clone https://github.com/$ORG/x`, `git clone
6026 // github:$USER/repo`) into the `:repo` slot, forgetting to
6027 // substitute the literal value at author time. Until this arm
6028 // landed the value silently passed every prior
6029 // `is_git_repo_url` arm (no whitespace, no control chars, no
6030 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6031 // no `` ` ``, no `|`, no `;`, no `&`, doesn't start with `-`
6032 // or `:`); RFC 3986 §2 lists `$` in the 'sub-delims' /
6033 // reserved set and the WHATWG URL spec's fragment percent-
6034 // encode set maps `$` → `%24` on the wire, so the byte rides
6035 // verbatim into the lacre's per-dep BLAKE3 closure but is
6036 // silently rewritten at libcurl's URL-parser layer — two
6037 // authors whose values differ only in their `$VAR` /
6038 // `${VAR}` / `$(cmd)` expansion tail resolve to the byte-
6039 // identical upstream `git clone` but lock to two distinct
6040 // lacres, defeating the THEORY.md §V.2 render-determinism
6041 // contract. Beyond determinism, the value is a structural
6042 // host-layout leak: two authors with the same `:repo` slot
6043 // but different `$ORG` / `$HOME` / `$WORKSPACE` resolve
6044 // different upstreams. Peer with the `:caminho` axis's
6045 // `FonteCaminhoVarExpansion` arm (f4efe9c) on the sibling
6046 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
6047 // byte RFC-3986-reserved set on `:entrada :paths`.
6048 let d = dep_with_fonte(DepSource::Git {
6049 repo: "https://github.com/$ORG/caixa-teia".into(),
6050 tag: Some("v0.1.0".into()),
6051 rev: None,
6052 branch: None,
6053 });
6054 let err = d.validate().unwrap_err();
6055 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6056 panic!("expected FonteRepoShape, got other variant");
6057 };
6058 assert_eq!(nome, "caixa-teia");
6059 assert_eq!(repo, "https://github.com/$ORG/caixa-teia");
6060 assert!(
6061 reason.contains("must not contain `$`"),
6062 "reason must surface the shell-variable-expansion arm, got {reason:?}"
6063 );
6064 assert!(
6065 reason.contains("variable-expansion") || reason.contains("'sub-delims'"),
6066 "reason must name the shell-variable-expansion / RFC-3986-sub-delims \
6067 rationale, got {reason:?}"
6068 );
6069 }
6070
6071 #[test]
6072 fn validate_rejects_git_fonte_with_repo_carrying_braced_variable_expansion() {
6073 // The fail-before-pass-after pin for the symmetric POSIX-
6074 // shell braced `${VAR}` expansion paste footgun: an author
6075 // pastes a CI-manifest line `git clone
6076 // https://github.com/${WORKSPACE}/x` (the canonical GitHub
6077 // Actions / GitLab CI / Drone shape) and forgets to
6078 // substitute the literal value. The `${...}` shape is the
6079 // same `$` byte at the leading position of the expansion;
6080 // the per-byte arm fires on the `$`. Pinned separately from
6081 // the bare-`$VAR` shape so a future diagnostic-surface
6082 // change that special-cased the braced form surfaces here.
6083 let d = dep_with_fonte(DepSource::Git {
6084 repo: "https://github.com/${WORKSPACE}/caixa-teia".into(),
6085 tag: Some("v0.1.0".into()),
6086 rev: None,
6087 branch: None,
6088 });
6089 let err = d.validate().unwrap_err();
6090 let DepError::FonteRepoShape { reason, .. } = err else {
6091 panic!("expected FonteRepoShape, got other variant");
6092 };
6093 assert!(
6094 reason.contains("must not contain `$`"),
6095 "reason must surface the shell-variable-expansion arm on the braced `${{...}}` \
6096 shape too, got {reason:?}"
6097 );
6098 }
6099
6100 #[test]
6101 fn fonte_repo_fragment_fires_before_var_expansion_when_fragment_first() {
6102 // Cascade pin: the fragment-`#` arm and the var-expansion-`$`
6103 // arm are both per-byte arms inside the same `for &b in
6104 // s.as_bytes()` loop, so the byte that appears first in the
6105 // value's byte order wins. A `:repo
6106 // "https://github.com/p/x#readme$HOME"` carries both `#` and
6107 // `$`; the `#` byte appears first, so the fragment-`#` arm
6108 // fires, surfacing the more self-locating diagnostic on the
6109 // byte the author pasted earliest in the URL. Mirrors the
6110 // peer cascade discipline
6111 // `fonte_repo_fragment_fires_before_background_when_fragment_first`
6112 // on the prior `:repo` byte-class arm.
6113 let d = dep_with_fonte(DepSource::Git {
6114 repo: "https://github.com/pleme-io/caixa-teia#readme$HOME".into(),
6115 tag: Some("v0.1.0".into()),
6116 rev: None,
6117 branch: None,
6118 });
6119 let err = d.validate().unwrap_err();
6120 let DepError::FonteRepoShape { reason, .. } = err else {
6121 panic!("expected FonteRepoShape, got other variant");
6122 };
6123 assert!(
6124 reason.contains("must not contain `#`"),
6125 "reason must surface the fragment-`#` arm (fires before var-expansion-`$` when \
6126 `#` byte appears first in value), got {reason:?}"
6127 );
6128 }
6129
6130 #[test]
6131 fn fonte_repo_background_fires_before_var_expansion_when_background_first() {
6132 // Cascade pin: the background-`&` arm and the
6133 // var-expansion-`$` arm are both per-byte arms inside the
6134 // same `for &b in s.as_bytes()` loop, so the byte that
6135 // appears first in the value's byte order wins. A `:repo
6136 // "https://github.com/p/x&sleep$HOME"` carries both `&` and
6137 // `$`; the `&` byte appears first, so the background arm
6138 // fires, surfacing the more self-locating diagnostic on the
6139 // byte the author pasted earliest in the URL. Pins the
6140 // natural-order cascade so a future reorder of the per-byte
6141 // arms surfaces here — `$` is the most recent byte-class arm,
6142 // so the cascade-pin sweep extends to cover every immediately
6143 // prior byte arm (`#`, `&`) firing first when ordered ahead
6144 // of `$` in the value.
6145 let d = dep_with_fonte(DepSource::Git {
6146 repo: "https://github.com/pleme-io/caixa-teia&sleep$HOME".into(),
6147 tag: Some("v0.1.0".into()),
6148 rev: None,
6149 branch: None,
6150 });
6151 let err = d.validate().unwrap_err();
6152 let DepError::FonteRepoShape { reason, .. } = err else {
6153 panic!("expected FonteRepoShape, got other variant");
6154 };
6155 assert!(
6156 reason.contains("must not contain `&`"),
6157 "reason must surface the background-`&` arm (fires before var-expansion-`$` when \
6158 `&` byte appears first in value), got {reason:?}"
6159 );
6160 }
6161
6162 #[test]
6163 fn validate_rejects_git_fonte_with_repo_carrying_shell_glob_wildcard() {
6164 // The fail-before-pass-after pin for the canonical
6165 // paste-from-shell-prompt glob footgun on `:repo` (peer with
6166 // the cf9034b `*` / `?` arm on the sibling `:caminho`
6167 // path-fonte axis). An author pastes a shell one-liner that
6168 // referenced a glob expansion (`ls
6169 // github.com/pleme-io/caixa-*`, `git clone
6170 // github:pleme-io/caixa-*`) into the `:repo` slot, forgetting
6171 // to substitute the literal repo name. Until this arm landed
6172 // the `*` byte silently passed every prior `is_git_repo_url`
6173 // arm (no whitespace, no control chars, no non-ASCII, no `#`,
6174 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`,
6175 // no `;`, no `&`, no `$`, doesn't start with `-` or `:`); RFC
6176 // 3986 §2 lists `*` in the 'sub-delims' / reserved set and
6177 // the WHATWG URL spec's special-query percent-encode set maps
6178 // `*` → `%2A` on the wire, so the byte rides verbatim into
6179 // the lacre's per-dep BLAKE3 closure but is silently
6180 // rewritten at libcurl's URL-parser layer — two authors
6181 // whose values differ only in their asterisk presence
6182 // resolve to the byte-identical upstream `git clone` but
6183 // lock to two distinct lacres, defeating the THEORY.md §V.2
6184 // render-determinism contract. Peer with the `:caminho`
6185 // axis's `FonteCaminhoShellGlob` arm (cf9034b) on the
6186 // sibling path-fonte axis, and the `is_git_ref_name`
6187 // refspec-wildcard cascade on the `:fonte :tag` / `:branch`
6188 // axes.
6189 let d = dep_with_fonte(DepSource::Git {
6190 repo: "https://github.com/pleme-io/caixa-*".into(),
6191 tag: Some("v0.1.0".into()),
6192 rev: None,
6193 branch: None,
6194 });
6195 let err = d.validate().unwrap_err();
6196 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6197 panic!("expected FonteRepoShape, got other variant");
6198 };
6199 assert_eq!(nome, "caixa-teia");
6200 assert_eq!(repo, "https://github.com/pleme-io/caixa-*");
6201 assert!(
6202 reason.contains("must not contain `*`"),
6203 "reason must surface the shell-glob arm, got {reason:?}"
6204 );
6205 assert!(
6206 reason.contains("pathname-expansion") || reason.contains("'sub-delims'"),
6207 "reason must name the shell-glob / pathname-expansion / \
6208 RFC-3986-sub-delims rationale, got {reason:?}"
6209 );
6210 }
6211
6212 #[test]
6213 fn validate_rejects_git_fonte_with_repo_carrying_recursive_shell_glob() {
6214 // The fail-before-pass-after pin for the symmetric bash
6215 // `globstar` recursive-glob paste footgun: an author pastes
6216 // a `ls github.com/pleme-io/**/x` (the canonical
6217 // `globstar`-shopt-enabled recursive-listing tail) into the
6218 // `:repo` slot. The `**` shape is two `*` bytes adjacent;
6219 // the per-byte arm fires on the first `*`. Pinned
6220 // separately from the single-`*` shape so a future
6221 // diagnostic-surface change that special-cased the
6222 // double-`*` form surfaces here.
6223 let d = dep_with_fonte(DepSource::Git {
6224 repo: "https://github.com/pleme-io/**/caixa-teia".into(),
6225 tag: Some("v0.1.0".into()),
6226 rev: None,
6227 branch: None,
6228 });
6229 let err = d.validate().unwrap_err();
6230 let DepError::FonteRepoShape { reason, .. } = err else {
6231 panic!("expected FonteRepoShape, got other variant");
6232 };
6233 assert!(
6234 reason.contains("must not contain `*`"),
6235 "reason must surface the shell-glob arm on the `**` recursive-glob shape too, \
6236 got {reason:?}"
6237 );
6238 }
6239
6240 #[test]
6241 fn fonte_repo_fragment_fires_before_glob_when_fragment_first() {
6242 // Cascade pin: the fragment-`#` arm and the glob-`*` arm are
6243 // both per-byte arms inside the same `for &b in s.as_bytes()`
6244 // loop, so the byte that appears first in the value's byte
6245 // order wins. A `:repo
6246 // "https://github.com/p/x#readme*tail"` carries both `#` and
6247 // `*`; the `#` byte appears first, so the fragment-`#` arm
6248 // fires, surfacing the more self-locating diagnostic on the
6249 // byte the author pasted earliest in the URL. Mirrors the
6250 // peer cascade discipline
6251 // `fonte_repo_fragment_fires_before_var_expansion_when_fragment_first`
6252 // on the prior `:repo` byte-class arm.
6253 let d = dep_with_fonte(DepSource::Git {
6254 repo: "https://github.com/pleme-io/caixa-teia#readme*tail".into(),
6255 tag: Some("v0.1.0".into()),
6256 rev: None,
6257 branch: None,
6258 });
6259 let err = d.validate().unwrap_err();
6260 let DepError::FonteRepoShape { reason, .. } = err else {
6261 panic!("expected FonteRepoShape, got other variant");
6262 };
6263 assert!(
6264 reason.contains("must not contain `#`"),
6265 "reason must surface the fragment-`#` arm (fires before glob-`*` when `#` byte \
6266 appears first in value), got {reason:?}"
6267 );
6268 }
6269
6270 #[test]
6271 fn fonte_repo_var_expansion_fires_before_glob_when_var_expansion_first() {
6272 // Cascade pin: the var-expansion-`$` arm and the glob-`*`
6273 // arm are both per-byte arms inside the same `for &b in
6274 // s.as_bytes()` loop, so the byte that appears first in the
6275 // value's byte order wins. A `:repo
6276 // "https://github.com/p/$ORG-*"` carries both `$` and `*`;
6277 // the `$` byte appears first, so the var-expansion arm
6278 // fires, surfacing the more self-locating diagnostic on the
6279 // byte the author pasted earliest in the URL. Pins the
6280 // natural-order cascade so a future reorder of the per-byte
6281 // arms surfaces here — `*` is the most recent byte-class
6282 // arm, so the cascade-pin sweep extends to cover the
6283 // immediately prior `$` byte arm firing first when ordered
6284 // ahead of `*` in the value.
6285 let d = dep_with_fonte(DepSource::Git {
6286 repo: "https://github.com/pleme-io/$ORG-caixa-*".into(),
6287 tag: Some("v0.1.0".into()),
6288 rev: None,
6289 branch: None,
6290 });
6291 let err = d.validate().unwrap_err();
6292 let DepError::FonteRepoShape { reason, .. } = err else {
6293 panic!("expected FonteRepoShape, got other variant");
6294 };
6295 assert!(
6296 reason.contains("must not contain `$`"),
6297 "reason must surface the var-expansion-`$` arm (fires before glob-`*` when `$` \
6298 byte appears first in value), got {reason:?}"
6299 );
6300 }
6301
6302 #[test]
6303 fn validate_rejects_git_fonte_with_repo_carrying_subshell_open_paren() {
6304 // The fail-before-pass-after pin for the canonical paste-from-
6305 // shell-prompt subshell-grouping footgun on `:repo`. An author
6306 // pastes a doc / README snippet carrying a regex-alternation
6307 // grouping shape (`https://github.com/(foo|bar)/repo`) or a
6308 // dynamic-config-substitution wrapper (`$(<cmd>)`) into the
6309 // `:repo` slot, forgetting to substitute one literal org name.
6310 // Until this arm landed the `(` byte silently passed every
6311 // prior `is_git_repo_url` arm (no whitespace, no control
6312 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6313 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no
6314 // `*`, doesn't start with `-` or `:`); RFC 3986 §2 lists `(`
6315 // / `)` in the 'sub-delims' / reserved set, and the WHATWG
6316 // URL spec's special-query percent-encode set maps `(` →
6317 // `%28` and `)` → `%29` on the wire, so the byte rides
6318 // verbatim into the lacre's per-dep BLAKE3 closure but is
6319 // silently rewritten at libcurl's URL-parser layer —
6320 // defeating the THEORY.md §V.2 render-determinism contract on
6321 // the same axis the prior twelve byte-class arms close.
6322 let d = dep_with_fonte(DepSource::Git {
6323 repo: "https://github.com/(foo|bar)/caixa-teia".into(),
6324 tag: Some("v0.1.0".into()),
6325 rev: None,
6326 branch: None,
6327 });
6328 let err = d.validate().unwrap_err();
6329 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6330 panic!("expected FonteRepoShape, got other variant");
6331 };
6332 assert_eq!(nome, "caixa-teia");
6333 assert_eq!(repo, "https://github.com/(foo|bar)/caixa-teia");
6334 assert!(
6335 reason.contains("must not contain `(`"),
6336 "reason must surface the subshell-open-paren arm, got {reason:?}"
6337 );
6338 assert!(
6339 reason.contains("subshell-grouping") || reason.contains("'sub-delims'"),
6340 "reason must name the shell-subshell-grouping / RFC-3986-sub-delims rationale, \
6341 got {reason:?}"
6342 );
6343 }
6344
6345 #[test]
6346 fn validate_rejects_git_fonte_with_repo_carrying_subshell_close_paren() {
6347 // The symmetric arm pin on the closing `)` byte: an author
6348 // pastes a `$(date)` command-substitution wrapper or a
6349 // regex-alternation `(foo|bar)` tail into the `:repo` slot.
6350 // Pinned separately from the opening `(` shape so a future
6351 // diagnostic-surface change that only checked one boundary
6352 // surfaces here. The `(` byte appears earlier in the
6353 // canonical regex / subshell wrapper so the per-byte loop
6354 // fires on `(` first; this test exercises a `:repo` value
6355 // carrying only the closing `)` byte (no opening paren) so
6356 // the `)` arm fires directly — pinning the byte-class arm
6357 // independent of order.
6358 let d = dep_with_fonte(DepSource::Git {
6359 repo: "github:pleme-io/caixa-teia)tail".into(),
6360 tag: Some("v0.1.0".into()),
6361 rev: None,
6362 branch: None,
6363 });
6364 let err = d.validate().unwrap_err();
6365 let DepError::FonteRepoShape { reason, .. } = err else {
6366 panic!("expected FonteRepoShape, got other variant");
6367 };
6368 assert!(
6369 reason.contains("must not contain `)`"),
6370 "reason must surface the subshell-close-paren arm on the bare `)` shape, \
6371 got {reason:?}"
6372 );
6373 }
6374
6375 #[test]
6376 fn fonte_repo_fragment_fires_before_subshell_when_fragment_first() {
6377 // Cascade pin: the fragment-`#` arm and the subshell-`(` arm
6378 // are both per-byte arms inside the same `for &b in
6379 // s.as_bytes()` loop, so the byte that appears first in the
6380 // value's byte order wins. A `:repo
6381 // "https://github.com/p/x#readme(tail)"` carries both `#` and
6382 // `(`; the `#` byte appears first, so the fragment-`#` arm
6383 // fires, surfacing the more self-locating diagnostic on the
6384 // byte the author pasted earliest in the URL. Mirrors the
6385 // peer cascade discipline
6386 // `fonte_repo_fragment_fires_before_glob_when_fragment_first`
6387 // on the prior `:repo` byte-class arm.
6388 let d = dep_with_fonte(DepSource::Git {
6389 repo: "https://github.com/pleme-io/caixa-teia#readme(tail)".into(),
6390 tag: Some("v0.1.0".into()),
6391 rev: None,
6392 branch: None,
6393 });
6394 let err = d.validate().unwrap_err();
6395 let DepError::FonteRepoShape { reason, .. } = err else {
6396 panic!("expected FonteRepoShape, got other variant");
6397 };
6398 assert!(
6399 reason.contains("must not contain `#`"),
6400 "reason must surface the fragment-`#` arm (fires before subshell-`(` when `#` \
6401 byte appears first in value), got {reason:?}"
6402 );
6403 }
6404
6405 #[test]
6406 fn fonte_repo_glob_fires_before_subshell_when_glob_first() {
6407 // Cascade pin: the glob-`*` arm (the immediate-predecessor
6408 // byte-class arm, 3902a9a) and the subshell-`(` arm are both
6409 // per-byte arms inside the same `for &b in s.as_bytes()`
6410 // loop, so the byte that appears first in the value's byte
6411 // order wins. A `:repo
6412 // "https://github.com/p/x-*-(date)"` carries both `*` and
6413 // `(`; the `*` byte appears first, so the glob arm fires,
6414 // surfacing the more self-locating diagnostic on the byte
6415 // the author pasted earliest in the URL. Pins the natural-
6416 // order cascade so a future reorder of the per-byte arms
6417 // surfaces here — `(` is the most recent byte-class arm,
6418 // so the cascade-pin sweep extends to cover the immediately
6419 // prior `*` byte arm firing first when ordered ahead of `(`
6420 // in the value.
6421 let d = dep_with_fonte(DepSource::Git {
6422 repo: "https://github.com/pleme-io/caixa-teia-*-(date)".into(),
6423 tag: Some("v0.1.0".into()),
6424 rev: None,
6425 branch: None,
6426 });
6427 let err = d.validate().unwrap_err();
6428 let DepError::FonteRepoShape { reason, .. } = err else {
6429 panic!("expected FonteRepoShape, got other variant");
6430 };
6431 assert!(
6432 reason.contains("must not contain `*`"),
6433 "reason must surface the glob-`*` arm (fires before subshell-`(` when `*` byte \
6434 appears first in value), got {reason:?}"
6435 );
6436 }
6437
6438 #[test]
6439 fn validate_rejects_git_fonte_with_repo_carrying_shell_double_quote() {
6440 // The fail-before-pass-after pin for the canonical paste-from-
6441 // doc-shell-quoting footgun on `:repo`. An author copies a
6442 // README quick-start snippet (`$ git clone "https://github.com/
6443 // foo/bar"`) and keeps the surrounding double-quote bytes when
6444 // pasting into the `:repo` slot — the doc wraps the URL in
6445 // double quotes so the shell doesn't re-lex metachars inside,
6446 // but the typed slot is itself a byte-level string parser, not
6447 // a shell context, so the quote bytes ride into the value
6448 // verbatim. Until this arm landed the `"` byte silently passed
6449 // every prior `is_git_repo_url` arm (no whitespace, no control
6450 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6451 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`,
6452 // no `(`/`)`, doesn't start with `-` or `:`); RFC 3986 §2 lists
6453 // `"` in the strict four-byte 'delims' subset (with `<`, `>`,
6454 // `` ` ``) every URL parser is required to refuse or percent-
6455 // encode, and the WHATWG URL spec's 'C0 control percent-encode
6456 // set' maps `"` → `%22` on the wire, so the byte rides verbatim
6457 // into the lacre's per-dep BLAKE3 closure but is silently
6458 // rewritten at libcurl's URL-parser layer, defeating the
6459 // THEORY.md §V.2 render-determinism contract.
6460 let d = dep_with_fonte(DepSource::Git {
6461 repo: "\"https://github.com/pleme-io/caixa-teia\"".into(),
6462 tag: Some("v0.1.0".into()),
6463 rev: None,
6464 branch: None,
6465 });
6466 let err = d.validate().unwrap_err();
6467 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6468 panic!("expected FonteRepoShape, got other variant");
6469 };
6470 assert_eq!(nome, "caixa-teia");
6471 assert_eq!(repo, "\"https://github.com/pleme-io/caixa-teia\"");
6472 assert!(
6473 reason.contains("must not contain `\"`"),
6474 "reason must surface the shell-double-quote arm, got {reason:?}"
6475 );
6476 assert!(
6477 reason.contains("double-quote") || reason.contains("'delims'"),
6478 "reason must name the shell-double-quote / RFC-3986-delims rationale, \
6479 got {reason:?}"
6480 );
6481 }
6482
6483 #[test]
6484 fn validate_rejects_git_fonte_with_repo_carrying_stray_trailing_double_quote() {
6485 // The symmetric stray-quote tail pin: an author pastes only a
6486 // closing `"` from a shell-history line like `git clone
6487 // "https://github.com/foo/bar" && cd …` (the trim went too
6488 // far in one direction but not the other) into the `:repo`
6489 // slot. Pinned separately from the wrapped-quote shape so a
6490 // future diagnostic-surface change that only checked one
6491 // boundary (only leading, only trailing, only paired) surfaces
6492 // here — the per-byte arm fires anywhere `"` appears.
6493 let d = dep_with_fonte(DepSource::Git {
6494 repo: "github:pleme-io/caixa-teia\"".into(),
6495 tag: Some("v0.1.0".into()),
6496 rev: None,
6497 branch: None,
6498 });
6499 let err = d.validate().unwrap_err();
6500 let DepError::FonteRepoShape { reason, .. } = err else {
6501 panic!("expected FonteRepoShape, got other variant");
6502 };
6503 assert!(
6504 reason.contains("must not contain `\"`"),
6505 "reason must surface the shell-double-quote arm on the trailing-`\"` shape, \
6506 got {reason:?}"
6507 );
6508 }
6509
6510 #[test]
6511 fn fonte_repo_fragment_fires_before_double_quote_when_fragment_first() {
6512 // Cascade pin: the fragment-`#` arm and the double-quote arm
6513 // are both per-byte arms inside the same `for &b in
6514 // s.as_bytes()` loop, so the byte that appears first in the
6515 // value's byte order wins. A `:repo
6516 // "https://github.com/p/x#readme\"tail"` carries both `#` and
6517 // `"`; the `#` byte appears first, so the fragment-`#` arm
6518 // fires, surfacing the more self-locating diagnostic on the
6519 // byte the author pasted earliest in the URL.
6520 let d = dep_with_fonte(DepSource::Git {
6521 repo: "https://github.com/pleme-io/caixa-teia#readme\"tail".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 fragment-`#` arm (fires before double-quote when `#` \
6533 byte appears first in value), got {reason:?}"
6534 );
6535 }
6536
6537 #[test]
6538 fn fonte_repo_subshell_fires_before_double_quote_when_subshell_first() {
6539 // Cascade pin: the subshell-`(` arm (the immediate-predecessor
6540 // byte-class arm, 3b99147) and the double-quote arm are both
6541 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6542 // so the byte that appears first in the value's byte order
6543 // wins. A `:repo "github:p/x(date)\"tail"` carries both `(`
6544 // and `"`; the `(` byte appears first, so the subshell arm
6545 // fires, surfacing the more self-locating diagnostic on the
6546 // byte the author pasted earliest in the URL. Pins the natural-
6547 // order cascade so a future reorder of the per-byte arms
6548 // surfaces here — `"` is the most recent byte-class arm, so
6549 // the cascade-pin sweep extends to cover the immediately prior
6550 // `(` byte arm firing first when ordered ahead of `"` in the
6551 // value.
6552 let d = dep_with_fonte(DepSource::Git {
6553 repo: "github:pleme-io/caixa-teia(date)\"tail".into(),
6554 tag: Some("v0.1.0".into()),
6555 rev: None,
6556 branch: None,
6557 });
6558 let err = d.validate().unwrap_err();
6559 let DepError::FonteRepoShape { reason, .. } = err else {
6560 panic!("expected FonteRepoShape, got other variant");
6561 };
6562 assert!(
6563 reason.contains("must not contain `(`"),
6564 "reason must surface the subshell-`(` arm (fires before double-quote when `(` \
6565 byte appears first in value), got {reason:?}"
6566 );
6567 }
6568
6569 #[test]
6570 fn validate_rejects_git_fonte_with_repo_carrying_shell_single_quote() {
6571 // The fail-before-pass-after pin for the canonical paste-from-
6572 // doc-strong-quoting footgun on `:repo`. An author copies a
6573 // security-conscious README quick-start snippet (`$ git clone
6574 // 'https://github.com/foo/bar'`) and keeps the surrounding
6575 // single-quote bytes when pasting into the `:repo` slot — the
6576 // doc strong-quotes the URL so the shell suppresses every form
6577 // of expansion on the bytes inside (no `$`, no backtick, no
6578 // glob, no word-splitting), but the typed slot is itself a
6579 // byte-level string parser, not a shell context, so the quote
6580 // bytes ride into the value verbatim. Until this arm landed the
6581 // `'` byte silently passed every prior `is_git_repo_url` arm
6582 // (no whitespace, no control chars, no non-ASCII, no `#`, no
6583 // `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no
6584 // `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`, doesn't start
6585 // with `-` or `:`); RFC 3986 §2.2 lists `'` in the 'sub-delims'
6586 // set, peer with the `\"` 'delims' double-quote arm and the
6587 // partner ASCII shell-string-delimiter byte every byte-level
6588 // string parser sharing a value-shape with a shell argument
6589 // must refuse on a URL-shaped slot.
6590 let d = dep_with_fonte(DepSource::Git {
6591 repo: "'https://github.com/pleme-io/caixa-teia'".into(),
6592 tag: Some("v0.1.0".into()),
6593 rev: None,
6594 branch: None,
6595 });
6596 let err = d.validate().unwrap_err();
6597 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6598 panic!("expected FonteRepoShape, got other variant");
6599 };
6600 assert_eq!(nome, "caixa-teia");
6601 assert_eq!(repo, "'https://github.com/pleme-io/caixa-teia'");
6602 assert!(
6603 reason.contains("must not contain `'`"),
6604 "reason must surface the shell-single-quote arm, got {reason:?}"
6605 );
6606 assert!(
6607 reason.contains("single-quote") || reason.contains("strong-quote"),
6608 "reason must name the shell-single-quote / strong-quote rationale, \
6609 got {reason:?}"
6610 );
6611 }
6612
6613 #[test]
6614 fn validate_rejects_git_fonte_with_repo_carrying_english_apostrophe() {
6615 // The symmetric English-typography pin: an author writes
6616 // `:repo "github:p/repo's-fork"` (the possessive-form paste-
6617 // from-prose idiom every README / commit-message / chat-thread
6618 // reference to a repo carries) expecting the substrate to
6619 // coerce it to a kebab-case slug — but the byte rides into the
6620 // lacre verbatim. Pinned separately from the wrapped-quote
6621 // shape so a future diagnostic-surface change that only checked
6622 // the boundary positions (only leading, only trailing, only
6623 // paired) surfaces here — the per-byte arm fires anywhere `'`
6624 // appears in the value.
6625 let d = dep_with_fonte(DepSource::Git {
6626 repo: "github:pleme-io/repo's-fork".into(),
6627 tag: Some("v0.1.0".into()),
6628 rev: None,
6629 branch: None,
6630 });
6631 let err = d.validate().unwrap_err();
6632 let DepError::FonteRepoShape { reason, .. } = err else {
6633 panic!("expected FonteRepoShape, got other variant");
6634 };
6635 assert!(
6636 reason.contains("must not contain `'`"),
6637 "reason must surface the shell-single-quote arm on the mid-string \
6638 apostrophe shape, got {reason:?}"
6639 );
6640 }
6641
6642 #[test]
6643 fn fonte_repo_fragment_fires_before_single_quote_when_fragment_first() {
6644 // Cascade pin: the fragment-`#` arm and the single-quote arm
6645 // are both per-byte arms inside the same `for &b in
6646 // s.as_bytes()` loop, so the byte that appears first in the
6647 // value's byte order wins. A `:repo
6648 // "https://github.com/p/x#readme'tail"` carries both `#` and
6649 // `'`; the `#` byte appears first, so the fragment-`#` arm
6650 // fires, surfacing the more self-locating diagnostic on the
6651 // byte the author pasted earliest in the URL.
6652 let d = dep_with_fonte(DepSource::Git {
6653 repo: "https://github.com/pleme-io/caixa-teia#readme'tail".into(),
6654 tag: Some("v0.1.0".into()),
6655 rev: None,
6656 branch: None,
6657 });
6658 let err = d.validate().unwrap_err();
6659 let DepError::FonteRepoShape { reason, .. } = err else {
6660 panic!("expected FonteRepoShape, got other variant");
6661 };
6662 assert!(
6663 reason.contains("must not contain `#`"),
6664 "reason must surface the fragment-`#` arm (fires before single-quote when `#` \
6665 byte appears first in value), got {reason:?}"
6666 );
6667 }
6668
6669 #[test]
6670 fn fonte_repo_double_quote_fires_before_single_quote_when_double_quote_first() {
6671 // Cascade pin: the double-quote-`"` arm (the immediate-predecessor
6672 // byte-class arm, 4267d8b) and the single-quote arm are both
6673 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6674 // so the byte that appears first in the value's byte order
6675 // wins. A `:repo "github:p/x\"mid'tail"` carries both `"` and
6676 // `'`; the `"` byte appears first, so the double-quote arm
6677 // fires, surfacing the more self-locating diagnostic on the
6678 // byte the author pasted earliest in the URL. Pins the natural-
6679 // order cascade so a future reorder of the per-byte arms
6680 // surfaces here — `'` is the most recent byte-class arm, so
6681 // the cascade-pin sweep extends to cover the immediately prior
6682 // `"` byte arm firing first when ordered ahead of `'` in the
6683 // value.
6684 let d = dep_with_fonte(DepSource::Git {
6685 repo: "github:pleme-io/caixa-teia\"mid'tail".into(),
6686 tag: Some("v0.1.0".into()),
6687 rev: None,
6688 branch: None,
6689 });
6690 let err = d.validate().unwrap_err();
6691 let DepError::FonteRepoShape { reason, .. } = err else {
6692 panic!("expected FonteRepoShape, got other variant");
6693 };
6694 assert!(
6695 reason.contains("must not contain `\"`"),
6696 "reason must surface the double-quote arm (fires before single-quote when `\"` \
6697 byte appears first in value), got {reason:?}"
6698 );
6699 }
6700
6701 #[test]
6702 fn validate_rejects_git_fonte_with_repo_carrying_shell_history_expansion() {
6703 // The fail-before-pass-after pin for the canonical paste-from-
6704 // shell-history footgun on `:repo`. An author copies a `git
6705 // clone <url>!sudo make install` one-liner from a README's
6706 // quick-start snippet, intending the trailing `!sudo` as a
6707 // shell-history-expansion reference but the typed slot is itself
6708 // a byte-level string parser, not a shell context, so the byte
6709 // rides into the value verbatim. Until this arm landed the `!`
6710 // byte silently passed every prior `is_git_repo_url` arm (no
6711 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
6712 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6713 // no `&`, no `$`, no `*`, no `(`/`)`, no `"`, no `'`, doesn't
6714 // start with `-` or `:`); bash with the default `histexpand`
6715 // mode rewrites `!command` to the most recent history entry
6716 // beginning with `command`, the canonical RCE-class injection
6717 // vector when the byte rides into a shell argument.
6718 let d = dep_with_fonte(DepSource::Git {
6719 repo: "https://github.com/pleme-io/caixa-teia!sudo".into(),
6720 tag: Some("v0.1.0".into()),
6721 rev: None,
6722 branch: None,
6723 });
6724 let err = d.validate().unwrap_err();
6725 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6726 panic!("expected FonteRepoShape, got other variant");
6727 };
6728 assert_eq!(nome, "caixa-teia");
6729 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia!sudo");
6730 assert!(
6731 reason.contains("must not contain `!`"),
6732 "reason must surface the shell-history-expansion arm, got {reason:?}"
6733 );
6734 assert!(
6735 reason.contains("history-expansion") || reason.contains("bang"),
6736 "reason must name the shell-history-expansion / bang rationale, got {reason:?}"
6737 );
6738 }
6739
6740 #[test]
6741 fn validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference() {
6742 // The symmetric `!!` repeat-prior-command pin: an author paste-
6743 // trims a `git clone <url>` retry idiom from shell history that
6744 // expands to the previous command via `!!`. Pinned separately
6745 // from the wrapped `!command` shape so a future diagnostic-
6746 // surface change that only checked the leading or paired-bang
6747 // position surfaces here — the per-byte arm fires anywhere `!`
6748 // appears in the value.
6749 let d = dep_with_fonte(DepSource::Git {
6750 repo: "github:pleme-io/caixa-teia!!".into(),
6751 tag: Some("v0.1.0".into()),
6752 rev: None,
6753 branch: None,
6754 });
6755 let err = d.validate().unwrap_err();
6756 let DepError::FonteRepoShape { reason, .. } = err else {
6757 panic!("expected FonteRepoShape, got other variant");
6758 };
6759 assert!(
6760 reason.contains("must not contain `!`"),
6761 "reason must surface the shell-history-expansion arm on the trailing-`!!` shape, \
6762 got {reason:?}"
6763 );
6764 }
6765
6766 #[test]
6767 fn fonte_repo_fragment_fires_before_bang_when_fragment_first() {
6768 // Cascade pin: the fragment-`#` arm and the bang arm are both
6769 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6770 // so the byte that appears first in the value's byte order
6771 // wins. A `:repo "https://github.com/p/x#readme!tail"` carries
6772 // both `#` and `!`; the `#` byte appears first, so the
6773 // fragment-`#` arm fires, surfacing the more self-locating
6774 // diagnostic on the byte the author pasted earliest in the URL.
6775 let d = dep_with_fonte(DepSource::Git {
6776 repo: "https://github.com/pleme-io/caixa-teia#readme!tail".into(),
6777 tag: Some("v0.1.0".into()),
6778 rev: None,
6779 branch: None,
6780 });
6781 let err = d.validate().unwrap_err();
6782 let DepError::FonteRepoShape { reason, .. } = err else {
6783 panic!("expected FonteRepoShape, got other variant");
6784 };
6785 assert!(
6786 reason.contains("must not contain `#`"),
6787 "reason must surface the fragment-`#` arm (fires before bang when `#` byte \
6788 appears first in value), got {reason:?}"
6789 );
6790 }
6791
6792 #[test]
6793 fn fonte_repo_single_quote_fires_before_bang_when_single_quote_first() {
6794 // Cascade pin: the single-quote-`'` arm (the immediate-predecessor
6795 // byte-class arm, e7a109f) and the bang arm are both per-byte
6796 // arms inside the same `for &b in s.as_bytes()` loop, so the
6797 // byte that appears first in the value's byte order wins. A
6798 // `:repo "github:p/x'mid!tail"` carries both `'` and `!`; the
6799 // `'` byte appears first, so the single-quote arm fires,
6800 // surfacing the more self-locating diagnostic on the byte the
6801 // author pasted earliest in the URL. Pins the natural-order
6802 // cascade so a future reorder of the per-byte arms surfaces
6803 // here — `!` is the most recent byte-class arm, so the
6804 // cascade-pin sweep extends to cover the immediately prior `'`
6805 // byte arm firing first when ordered ahead of `!` in the value.
6806 let d = dep_with_fonte(DepSource::Git {
6807 repo: "github:pleme-io/caixa-teia'mid!tail".into(),
6808 tag: Some("v0.1.0".into()),
6809 rev: None,
6810 branch: None,
6811 });
6812 let err = d.validate().unwrap_err();
6813 let DepError::FonteRepoShape { reason, .. } = err else {
6814 panic!("expected FonteRepoShape, got other variant");
6815 };
6816 assert!(
6817 reason.contains("must not contain `'`"),
6818 "reason must surface the single-quote arm (fires before bang when `'` byte \
6819 appears first in value), got {reason:?}"
6820 );
6821 }
6822
6823 #[test]
6824 fn validate_rejects_git_fonte_with_repo_carrying_list_separator_comma() {
6825 // The fail-before-pass-after pin for the canonical
6826 // list-separator-belongs-to-list-grammar footgun on `:repo`.
6827 // An author copies a `git clone <a>, <b>, <c>` paste-from-CSV
6828 // one-liner from a multi-repo bootstrap doc, intending the
6829 // comma to separate multiple repo entries but the typed
6830 // `:repo` slot names *one* repo (the list-separator belongs
6831 // to the `:deps` list grammar, not to the value). Until this
6832 // arm landed the `,` byte silently passed every prior
6833 // `is_git_repo_url` arm (no whitespace, no control chars, no
6834 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6835 // no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`, no
6836 // `(`/`)`, no `"`, no `'`, no `!`, doesn't start with `-` or
6837 // `:`); the byte rode into the lacre's per-dep content-
6838 // address and the resolver's `git clone <repo>` subprocess
6839 // invocation, where no host's repo registry resolved the
6840 // comma-bearing slug.
6841 let d = dep_with_fonte(DepSource::Git {
6842 repo: "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira".into(),
6843 tag: Some("v0.1.0".into()),
6844 rev: None,
6845 branch: None,
6846 });
6847 let err = d.validate().unwrap_err();
6848 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6849 panic!("expected FonteRepoShape, got other variant");
6850 };
6851 assert_eq!(nome, "caixa-teia");
6852 assert_eq!(
6853 repo,
6854 "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira"
6855 );
6856 assert!(
6857 reason.contains("must not contain `,`"),
6858 "reason must surface the list-separator-comma arm, got {reason:?}"
6859 );
6860 assert!(
6861 reason.contains("list-separator") || reason.contains("sub-delims"),
6862 "reason must name the list-separator / RFC-3986-sub-delims rationale, \
6863 got {reason:?}"
6864 );
6865 }
6866
6867 #[test]
6868 fn validate_rejects_git_fonte_with_repo_carrying_trailing_comma() {
6869 // The symmetric trailing-`,` paste-from-prose pin: an author
6870 // writes `:repo "github:pleme-io/caixa-feira,"` (the trailing
6871 // comma every README-prose list-of-projects sentence carries,
6872 // mistakenly retained when the slug is pasted mid-sentence)
6873 // expecting the substrate to coerce it to a kebab-case slug.
6874 // Pinned separately from the wrapped mid-token shape so a
6875 // future diagnostic-surface change that only checked the
6876 // leading or paired-comma position surfaces here — the
6877 // per-byte arm fires anywhere `,` appears in the value.
6878 let d = dep_with_fonte(DepSource::Git {
6879 repo: "github:pleme-io/caixa-feira,".into(),
6880 tag: Some("v0.1.0".into()),
6881 rev: None,
6882 branch: None,
6883 });
6884 let err = d.validate().unwrap_err();
6885 let DepError::FonteRepoShape { reason, .. } = err else {
6886 panic!("expected FonteRepoShape, got other variant");
6887 };
6888 assert!(
6889 reason.contains("must not contain `,`"),
6890 "reason must surface the list-separator-comma arm on the trailing-`,` shape, \
6891 got {reason:?}"
6892 );
6893 }
6894
6895 #[test]
6896 fn fonte_repo_fragment_fires_before_comma_when_fragment_first() {
6897 // Cascade pin: the fragment-`#` arm and the comma arm are
6898 // both per-byte arms inside the same `for &b in s.as_bytes()`
6899 // loop, so the byte that appears first in the value's byte
6900 // order wins. A `:repo "https://github.com/p/x#readme,tail"`
6901 // carries both `#` and `,`; the `#` byte appears first, so
6902 // the fragment-`#` arm fires, surfacing the more self-
6903 // locating diagnostic on the byte the author pasted earliest
6904 // in the URL.
6905 let d = dep_with_fonte(DepSource::Git {
6906 repo: "https://github.com/pleme-io/caixa-teia#readme,tail".into(),
6907 tag: Some("v0.1.0".into()),
6908 rev: None,
6909 branch: None,
6910 });
6911 let err = d.validate().unwrap_err();
6912 let DepError::FonteRepoShape { reason, .. } = err else {
6913 panic!("expected FonteRepoShape, got other variant");
6914 };
6915 assert!(
6916 reason.contains("must not contain `#`"),
6917 "reason must surface the fragment-`#` arm (fires before comma when `#` byte \
6918 appears first in value), got {reason:?}"
6919 );
6920 }
6921
6922 #[test]
6923 fn fonte_repo_bang_fires_before_comma_when_bang_first() {
6924 // Cascade pin: the bang-`!` arm (the immediate-predecessor
6925 // byte-class arm, 7d53c68) and the comma arm are both
6926 // per-byte arms inside the same `for &b in s.as_bytes()`
6927 // loop, so the byte that appears first in the value's byte
6928 // order wins. A `:repo "github:p/x!mid,tail"` carries both
6929 // `!` and `,`; the `!` byte appears first, so the bang arm
6930 // fires, surfacing the more self-locating diagnostic on the
6931 // byte the author pasted earliest in the URL. Pins the
6932 // natural-order cascade so a future reorder of the per-byte
6933 // arms surfaces here — `,` is the most recent byte-class
6934 // arm, so the cascade-pin sweep extends to cover the
6935 // immediately prior `!` byte arm firing first when ordered
6936 // ahead of `,` in the value.
6937 let d = dep_with_fonte(DepSource::Git {
6938 repo: "github:pleme-io/caixa-teia!mid,tail".into(),
6939 tag: Some("v0.1.0".into()),
6940 rev: None,
6941 branch: None,
6942 });
6943 let err = d.validate().unwrap_err();
6944 let DepError::FonteRepoShape { reason, .. } = err else {
6945 panic!("expected FonteRepoShape, got other variant");
6946 };
6947 assert!(
6948 reason.contains("must not contain `!`"),
6949 "reason must surface the bang arm (fires before comma when `!` byte \
6950 appears first in value), got {reason:?}"
6951 );
6952 }
6953
6954 #[test]
6955 fn validate_rejects_git_fonte_with_repo_carrying_shell_env_var_assignment() {
6956 // The fail-before-pass-after pin for the canonical
6957 // shell-env-var-assignment-belongs-to-shell-grammar footgun
6958 // on `:repo`. An author copies
6959 // `GIT_TERMINAL_PROMPT=0 git clone <url>` (or
6960 // `GIT_SSL_NO_VERIFY=1 git clone <url>`, `HTTPS_PROXY=…
6961 // git clone <url>`, etc. — the canonical
6962 // git-troubleshooting README idiom for a one-shot env-var
6963 // scoped to the `git clone` invocation) from a shell-prompt
6964 // one-liner, intending the `KEY=VALUE` prefix as a shell-
6965 // grammar env-var assignment but the typed `:repo` slot is
6966 // a value parser, not a shell context, so the bytes ride
6967 // into the value verbatim. Until this arm landed the `=`
6968 // byte silently passed every prior `is_git_repo_url` arm
6969 // (no whitespace, no control chars, no non-ASCII, no `#`,
6970 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no
6971 // `|`, no `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`,
6972 // no `'`, no `!`, no `,`, doesn't start with `-` or `:`);
6973 // the byte rode into the lacre's per-dep content-address
6974 // and the resolver's `git clone <repo>` subprocess
6975 // invocation, where the upstream host's git porcelain
6976 // fetched a literal `GIT_TERMINAL_PROMPT=0 https://…`-shaped
6977 // path that no host's repo registry resolves.
6978 let d = dep_with_fonte(DepSource::Git {
6979 repo: "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia".into(),
6980 tag: Some("v0.1.0".into()),
6981 rev: None,
6982 branch: None,
6983 });
6984 let err = d.validate().unwrap_err();
6985 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6986 panic!("expected FonteRepoShape, got other variant");
6987 };
6988 assert_eq!(nome, "caixa-teia");
6989 assert_eq!(
6990 repo,
6991 "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia"
6992 );
6993 // The `=` byte at position 19 of `GIT_TERMINAL_PROMPT=0 …`
6994 // appears before the ` ` byte at position 21, so the `=`
6995 // arm fires (not the whitespace arm) — both arms guard
6996 // the slot, but the per-byte for-loop scans left-to-right
6997 // and the first matching byte wins.
6998 assert!(
6999 reason.contains("must not contain `=`"),
7000 "reason must surface the equals-`=` arm on the env-var-assignment \
7001 paste shape, got {reason:?}"
7002 );
7003 assert!(
7004 reason.contains("env-var-assignment") || reason.contains("KEY=VALUE"),
7005 "reason must name the shell-env-var-assignment rationale, got {reason:?}"
7006 );
7007 }
7008
7009 #[test]
7010 fn validate_rejects_git_fonte_with_repo_carrying_gitconfig_url_key_prefix() {
7011 // The symmetric paste-from-gitconfig pin: an author copies
7012 // `url=https://github.com/p/x` from `git config --get-all
7013 // remote.origin.url` output, a `.gitconfig` `[remote
7014 // "origin"] url = https://…` ini-stanza paste, or a
7015 // `git config remote.origin.url <value>` doc snippet,
7016 // intending the `url=` prefix as the ini-key but the typed
7017 // `:repo` slot is a URL value parser, not a gitconfig
7018 // grammar. With no leading whitespace and no earlier-arm
7019 // bytes in the value, the `=` arm itself fires (rather
7020 // than cascading to the whitespace arm as in the env-var
7021 // paste shape). Pinned separately so a future diagnostic-
7022 // surface change that only checked the whitespace-leading
7023 // shape surfaces here — the per-byte arm fires anywhere
7024 // `=` appears in the value.
7025 let d = dep_with_fonte(DepSource::Git {
7026 repo: "url=https://github.com/pleme-io/caixa-feira".into(),
7027 tag: Some("v0.1.0".into()),
7028 rev: None,
7029 branch: None,
7030 });
7031 let err = d.validate().unwrap_err();
7032 let DepError::FonteRepoShape { reason, .. } = err else {
7033 panic!("expected FonteRepoShape, got other variant");
7034 };
7035 assert!(
7036 reason.contains("must not contain `=`"),
7037 "reason must surface the equals-`=` arm on the `url=…` gitconfig \
7038 paste shape, got {reason:?}"
7039 );
7040 assert!(
7041 reason.contains("key-value-separator") || reason.contains("sub-delims"),
7042 "reason must name the key-value-separator / RFC-3986-sub-delims \
7043 rationale, got {reason:?}"
7044 );
7045 }
7046
7047 #[test]
7048 fn fonte_repo_fragment_fires_before_equals_when_fragment_first() {
7049 // Cascade pin: the fragment-`#` arm and the `=` arm are
7050 // both per-byte arms inside the same `for &b in s.as_bytes()`
7051 // loop, so the byte that appears first in the value's byte
7052 // order wins. A `:repo "https://github.com/p/x#readme=tail"`
7053 // carries both `#` and `=`; the `#` byte appears first, so
7054 // the fragment-`#` arm fires, surfacing the more self-
7055 // locating diagnostic on the byte the author pasted earliest
7056 // in the URL.
7057 let d = dep_with_fonte(DepSource::Git {
7058 repo: "https://github.com/pleme-io/caixa-teia#readme=tail".into(),
7059 tag: Some("v0.1.0".into()),
7060 rev: None,
7061 branch: None,
7062 });
7063 let err = d.validate().unwrap_err();
7064 let DepError::FonteRepoShape { reason, .. } = err else {
7065 panic!("expected FonteRepoShape, got other variant");
7066 };
7067 assert!(
7068 reason.contains("must not contain `#`"),
7069 "reason must surface the fragment-`#` arm (fires before equals when \
7070 `#` byte appears first in value), got {reason:?}"
7071 );
7072 }
7073
7074 #[test]
7075 fn fonte_repo_comma_fires_before_equals_when_comma_first() {
7076 // Cascade pin: the comma-`,` arm (the immediate-predecessor
7077 // byte-class arm, 775b80e) and the `=` arm are both per-byte
7078 // arms inside the same `for &b in s.as_bytes()` loop, so
7079 // the byte that appears first in the value's byte order
7080 // wins. A `:repo "github:p/x,mid=tail"` carries both `,`
7081 // and `=`; the `,` byte appears first, so the comma arm
7082 // fires, surfacing the more self-locating diagnostic on
7083 // the byte the author pasted earliest in the URL. Pins the
7084 // natural-order cascade so a future reorder of the per-byte
7085 // arms surfaces here — `=` is the most recent byte-class
7086 // arm, so the cascade-pin sweep extends to cover the
7087 // immediately prior `,` byte arm firing first when ordered
7088 // ahead of `=` in the value.
7089 let d = dep_with_fonte(DepSource::Git {
7090 repo: "github:pleme-io/caixa-teia,mid=tail".into(),
7091 tag: Some("v0.1.0".into()),
7092 rev: None,
7093 branch: None,
7094 });
7095 let err = d.validate().unwrap_err();
7096 let DepError::FonteRepoShape { reason, .. } = err else {
7097 panic!("expected FonteRepoShape, got other variant");
7098 };
7099 assert!(
7100 reason.contains("must not contain `,`"),
7101 "reason must surface the comma arm (fires before equals when `,` byte \
7102 appears first in value), got {reason:?}"
7103 );
7104 }
7105
7106 #[test]
7107 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_space() {
7108 // The fail-before-pass-after pin for the canonical paste-from-
7109 // browser-address-bar percent-encoded-space footgun on `:repo`.
7110 // An author copies `https://github.com/p/x%20test` from a
7111 // browser address bar (or a percent-encoded README hyperlink,
7112 // or a `curl --data-urlencode` shell-pipeline output)
7113 // intending `%20` as the URL encoding of a literal space; the
7114 // typed `:repo` slot already rejects the literal space byte
7115 // (the whitespace arm at the top of `is_git_repo_url`), so an
7116 // author trying to express "I really meant a space" reaches
7117 // for percent-encoding. Until this arm landed the `%` byte
7118 // silently passed every prior `is_git_repo_url` arm and rode
7119 // verbatim into the lacre's per-dep content-address — but
7120 // libcurl re-percent-encodes `%` to `%25` on the wire (since
7121 // `%` is reserved as the escape-sequence lead-in), so the
7122 // wire request becomes `https://github.com/p/x%2520test`, a
7123 // path the lacre's content-address never names. The classic
7124 // render-determinism violation on the encoding-mechanism axis
7125 // itself.
7126 let d = dep_with_fonte(DepSource::Git {
7127 repo: "https://github.com/pleme-io/caixa-teia%20test".into(),
7128 tag: Some("v0.1.0".into()),
7129 rev: None,
7130 branch: None,
7131 });
7132 let err = d.validate().unwrap_err();
7133 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7134 panic!("expected FonteRepoShape, got other variant");
7135 };
7136 assert_eq!(nome, "caixa-teia");
7137 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia%20test");
7138 assert!(
7139 reason.contains("must not contain `%`"),
7140 "reason must surface the percent-`%` arm on the percent-encoded-space \
7141 paste shape, got {reason:?}"
7142 );
7143 assert!(
7144 reason.contains("percent-encoding") || reason.contains("%25"),
7145 "reason must name the percent-encoding / `%25` re-encoding rationale, \
7146 got {reason:?}"
7147 );
7148 }
7149
7150 #[test]
7151 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_slash() {
7152 // The symmetric over-encoded-path-separator pin: an author
7153 // writes `:repo "https://github.com/p%2Fx"` intending the
7154 // `%2F` as the URL encoding of `/` (the canonical
7155 // paste-from-OpenAPI-spec / paste-from-percent-encoded-template
7156 // footgun every API client library and OAuth redirect-URI
7157 // documentation surfaces — the `/` is the URL-path-separator
7158 // and some templates percent-encode it to escape interpretation
7159 // as a path separator). The GitHub Smart-HTTP transport
7160 // resolves the URL's path-segment grammar before the
7161 // percent-decoding pass, so the value identifies a different
7162 // resource on the wire than the literal-`/` form the lacre's
7163 // content-address must agree with — two authors whose `:repo`
7164 // values differ only in their `/` vs `%2F` presence lock to
7165 // two distinct BLAKE3 closures for the byte-identical upstream
7166 // `git clone`. Pinned separately so a future diagnostic
7167 // surface that only catches the `%20` shape surfaces here too.
7168 let d = dep_with_fonte(DepSource::Git {
7169 repo: "https://github.com/pleme-io%2Fcaixa-teia".into(),
7170 tag: Some("v0.1.0".into()),
7171 rev: None,
7172 branch: None,
7173 });
7174 let err = d.validate().unwrap_err();
7175 let DepError::FonteRepoShape { reason, .. } = err else {
7176 panic!("expected FonteRepoShape, got other variant");
7177 };
7178 assert!(
7179 reason.contains("must not contain `%`"),
7180 "reason must surface the percent-`%` arm on the over-encoded-path \
7181 shape, got {reason:?}"
7182 );
7183 assert!(
7184 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7185 "reason must name the render-determinism / BLAKE3-closure rationale, \
7186 got {reason:?}"
7187 );
7188 }
7189
7190 #[test]
7191 fn fonte_repo_fragment_fires_before_percent_when_fragment_first() {
7192 // Cascade pin: the fragment-`#` arm and the `%` arm are both
7193 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7194 // so the byte that appears first in the value's byte order
7195 // wins. A `:repo "https://github.com/p/x#sec%20tail"` carries
7196 // both `#` and `%`; the `#` byte appears first, so the
7197 // fragment-`#` arm fires, surfacing the more self-locating
7198 // diagnostic on the byte the author pasted earliest in the URL.
7199 let d = dep_with_fonte(DepSource::Git {
7200 repo: "https://github.com/pleme-io/caixa-teia#sec%20tail".into(),
7201 tag: Some("v0.1.0".into()),
7202 rev: None,
7203 branch: None,
7204 });
7205 let err = d.validate().unwrap_err();
7206 let DepError::FonteRepoShape { reason, .. } = err else {
7207 panic!("expected FonteRepoShape, got other variant");
7208 };
7209 assert!(
7210 reason.contains("must not contain `#`"),
7211 "reason must surface the fragment-`#` arm (fires before percent when \
7212 `#` byte appears first in value), got {reason:?}"
7213 );
7214 }
7215
7216 #[test]
7217 fn fonte_repo_equals_fires_before_percent_when_equals_first() {
7218 // Cascade pin: the equals-`=` arm (the immediate-predecessor
7219 // byte-class arm, acf99af) and the `%` arm are both per-byte
7220 // arms inside the same `for &b in s.as_bytes()` loop, so the
7221 // byte that appears first in the value's byte order wins.
7222 // A `:repo "github:p/x=mid%20tail"` carries both `=` and `%`;
7223 // the `=` byte appears first, so the equals arm fires,
7224 // surfacing the more self-locating diagnostic on the byte the
7225 // author pasted earliest in the URL. Pins the natural-order
7226 // cascade so a future reorder of the per-byte arms surfaces
7227 // here — `%` is the most recent byte-class arm, so the
7228 // cascade-pin sweep extends to cover the immediately prior
7229 // `=` byte arm firing first when ordered ahead of `%` in the
7230 // value.
7231 let d = dep_with_fonte(DepSource::Git {
7232 repo: "github:pleme-io/caixa-teia=mid%20tail".into(),
7233 tag: Some("v0.1.0".into()),
7234 rev: None,
7235 branch: None,
7236 });
7237 let err = d.validate().unwrap_err();
7238 let DepError::FonteRepoShape { reason, .. } = err else {
7239 panic!("expected FonteRepoShape, got other variant");
7240 };
7241 assert!(
7242 reason.contains("must not contain `=`"),
7243 "reason must surface the equals arm (fires before percent when `=` byte \
7244 appears first in value), got {reason:?}"
7245 );
7246 }
7247
7248 #[test]
7249 fn validate_rejects_git_fonte_with_repo_carrying_caret_history_substitution() {
7250 // The fail-before-pass-after pin for the canonical paste-from-
7251 // shell-history footgun on `:repo`. An author copies a
7252 // `git clone <url>` line from their terminal followed by a
7253 // bash / ksh / zsh `^typo^fix^` quick-edit-and-rerun shell-
7254 // history shorthand (the `^old^new^` form re-runs the prior
7255 // history entry with the first `old` substituted by `new`,
7256 // bash's default behavior on interactive sessions with
7257 // `set -o histexpand`), forgetting to trim the trailing
7258 // `^...^...` shell-history fragment from the URL value. The
7259 // `^` byte sits in the RFC 3986 §2 'unwise' set (peer with
7260 // `{`, `}`, `|`, `\\` — the strictest of the §2 reserved
7261 // classes), the WHATWG URL spec's 'fragment percent-encode
7262 // set' maps `^` → `%5E` on the wire, so the byte rides
7263 // verbatim into the lacre's per-dep content-address but
7264 // libcurl re-encodes it to `%5E` at `git clone` time — the
7265 // classic render-determinism violation on the same axis the
7266 // peer `%`, `=`, `,`, `!`, `'`, `"`, `(`, `)`, `*`, `$`,
7267 // `&`, `;`, `|`, backtick, `<`, `>`, `{`, `}`, `\\`, `?`,
7268 // `#` arms close.
7269 let d = dep_with_fonte(DepSource::Git {
7270 repo: "https://github.com/pleme-io/caixa-teia^typo^fix".into(),
7271 tag: Some("v0.1.0".into()),
7272 rev: None,
7273 branch: None,
7274 });
7275 let err = d.validate().unwrap_err();
7276 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7277 panic!("expected FonteRepoShape, got other variant");
7278 };
7279 assert_eq!(nome, "caixa-teia");
7280 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia^typo^fix");
7281 assert!(
7282 reason.contains("must not contain `^`"),
7283 "reason must surface the caret-`^` arm on the paste-from-shell-history \
7284 shape, got {reason:?}"
7285 );
7286 assert!(
7287 reason.contains("history-substitution") || reason.contains("%5E"),
7288 "reason must name the shell-history-substitution / `%5E` wire-encoding \
7289 rationale, got {reason:?}"
7290 );
7291 }
7292
7293 #[test]
7294 fn validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor() {
7295 // The symmetric paste-from-doc-grep-pipeline footgun: an
7296 // author writes `:repo "github:p/^archived"` after copying a
7297 // `grep '^archived'` regex-anchor / negation idiom from a
7298 // doc / README quick-listing snippet, expecting the substrate
7299 // to coerce it to a literal repo name. The byte rides
7300 // verbatim into the lacre's per-dep content-address and
7301 // diverges from the byte-identical literal `archived` form
7302 // every other author authored — the canonical render-
7303 // determinism violation pin on the second footgun shape the
7304 // caret-`^` arm closes.
7305 let d = dep_with_fonte(DepSource::Git {
7306 repo: "github:pleme-io/^archived".into(),
7307 tag: Some("v0.1.0".into()),
7308 rev: None,
7309 branch: None,
7310 });
7311 let err = d.validate().unwrap_err();
7312 let DepError::FonteRepoShape { reason, .. } = err else {
7313 panic!("expected FonteRepoShape, got other variant");
7314 };
7315 assert!(
7316 reason.contains("must not contain `^`"),
7317 "reason must surface the caret-`^` arm on the regex-anchor shape, \
7318 got {reason:?}"
7319 );
7320 assert!(
7321 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7322 "reason must name the render-determinism / BLAKE3-closure rationale, \
7323 got {reason:?}"
7324 );
7325 }
7326
7327 #[test]
7328 fn fonte_repo_percent_fires_before_caret_when_percent_first() {
7329 // Cascade pin: the `%` arm (the immediate-predecessor byte-
7330 // class arm, a323db8) and the `^` arm are both per-byte arms
7331 // inside the same `for &b in s.as_bytes()` loop, so the byte
7332 // that appears first in the value's byte order wins. A
7333 // `:repo "https://github.com/p/x%20mid^tail"` carries both
7334 // `%` and `^`; the `%` byte appears first, so the percent
7335 // arm fires, surfacing the more self-locating diagnostic on
7336 // the byte the author pasted earliest in the URL. Pins the
7337 // natural-order cascade so a future reorder of the per-byte
7338 // arms surfaces here — `^` is the most recent byte-class arm,
7339 // so the cascade-pin sweep extends to cover the immediately
7340 // prior `%` byte arm firing first when ordered ahead of `^`
7341 // in the value.
7342 let d = dep_with_fonte(DepSource::Git {
7343 repo: "https://github.com/pleme-io/caixa-teia%20mid^tail".into(),
7344 tag: Some("v0.1.0".into()),
7345 rev: None,
7346 branch: None,
7347 });
7348 let err = d.validate().unwrap_err();
7349 let DepError::FonteRepoShape { reason, .. } = err else {
7350 panic!("expected FonteRepoShape, got other variant");
7351 };
7352 assert!(
7353 reason.contains("must not contain `%`"),
7354 "reason must surface the percent arm (fires before caret when `%` byte \
7355 appears first in value), got {reason:?}"
7356 );
7357 }
7358
7359 #[test]
7360 fn validate_rejects_git_fonte_with_repo_missing_colon_separator() {
7361 // The "I dropped the scheme" footgun — `:repo "pleme-io/caixa-teia"`
7362 // (no `github:` prefix, no scheme). Every documented form
7363 // carries a `:` (`github:`, `https://`, `ssh://`, `git://`,
7364 // `file://`, or `git@host:path`); a bare `org/repo` is
7365 // ambiguous (`git clone` reads as a relative filesystem path
7366 // rather than the GitHub-shorthand expansion the author
7367 // probably intended) and the gate rejects the shape upstream.
7368 let d = dep_with_fonte(DepSource::Git {
7369 repo: "pleme-io/caixa-teia".into(),
7370 tag: Some("v0.1.0".into()),
7371 rev: None,
7372 branch: None,
7373 });
7374 let err = d.validate().unwrap_err();
7375 let DepError::FonteRepoShape { reason, .. } = err else {
7376 panic!("expected FonteRepoShape, got other variant");
7377 };
7378 assert!(
7379 reason.contains("must contain a `:`"),
7380 "reason must surface the missing-`:` arm, got {reason:?}"
7381 );
7382 assert!(
7383 reason.contains("github:"),
7384 "reason must name the canonical `github:` shorthand prefix, got {reason:?}"
7385 );
7386 }
7387
7388 #[test]
7389 fn validate_rejects_git_fonte_with_repo_leading_colon() {
7390 // The "empty scheme" footgun — `:repo ":foo"` has a zero-length
7391 // scheme that no git porcelain entry-point accepts. Pinned
7392 // separately from the missing-`:` arm because a value with a
7393 // leading `:` does technically contain a `:` separator; the
7394 // shape gate rejects on a dedicated arm so the diagnostic
7395 // names the specific footgun.
7396 let d = dep_with_fonte(DepSource::Git {
7397 repo: ":pleme-io/caixa-teia".into(),
7398 tag: Some("v0.1.0".into()),
7399 rev: None,
7400 branch: None,
7401 });
7402 let err = d.validate().unwrap_err();
7403 let DepError::FonteRepoShape { reason, .. } = err else {
7404 panic!("expected FonteRepoShape, got other variant");
7405 };
7406 assert!(
7407 reason.contains("must not start with `:`"),
7408 "reason must surface the leading-`:` arm, got {reason:?}"
7409 );
7410 }
7411
7412 #[test]
7413 fn validate_rejects_git_fonte_with_repo_too_long() {
7414 // The cap arm — a `:repo` value longer than
7415 // [`crate::render::GIT_REPO_URL_MAX_LEN`] (2048) bytes is
7416 // structurally untenable on every realistic landing site (the
7417 // resolver's `git clone` invocation, the future M4 CR
7418 // materializer's per-dep `repo:` axis); a value of that length
7419 // is almost certainly a paste-from-binary slug.
7420 let too_long = format!(
7421 "github:pleme-io/{}",
7422 "x".repeat(crate::render::GIT_REPO_URL_MAX_LEN)
7423 );
7424 let d = dep_with_fonte(DepSource::Git {
7425 repo: too_long.clone(),
7426 tag: Some("v0.1.0".into()),
7427 rev: None,
7428 branch: None,
7429 });
7430 let err = d.validate().unwrap_err();
7431 let DepError::FonteRepoShape { reason, .. } = err else {
7432 panic!("expected FonteRepoShape, got other variant");
7433 };
7434 assert!(
7435 reason.contains("2048"),
7436 "reason must name the cap, got {reason:?}"
7437 );
7438 }
7439
7440 #[test]
7441 fn validate_accepts_canonical_git_fonte_repo_shapes() {
7442 // The positive-control sweep: every documented author shape on
7443 // the `:fonte :repo` axis ([`crate::DepSource::Git`] doc comment)
7444 // must pass the value-shape gate. Pinned so a future tightening
7445 // (e.g. forbidding `http://` in favor of `https://`-only) surfaces
7446 // here as a structural decision. Each form is exercised with the
7447 // same canonical `:tag` pin so only the `:repo` axis varies.
7448 for repo in [
7449 // The pleme-io registry-shorthand convention — `github:org/repo`.
7450 "github:pleme-io/caixa-teia",
7451 // Other host-aliased shorthands (the resolver's pluggable
7452 // host-prefix table).
7453 "gitlab:pleme-io/caixa-teia",
7454 "codeberg:pleme-io/caixa-teia",
7455 "sourcehut:~pleme-io/caixa-teia",
7456 // Full HTTPS URL with and without `.git` suffix.
7457 "https://github.com/pleme-io/caixa-teia",
7458 "https://github.com/pleme-io/caixa-teia.git",
7459 // HTTP (rare; dev / mirror).
7460 "http://example.com/pleme-io/caixa-teia.git",
7461 // SSH URL.
7462 "ssh://git@github.com/pleme-io/caixa-teia.git",
7463 "ssh://git@git.example.com:2222/pleme-io/caixa-teia.git",
7464 // Scp-style SSH — the canonical `git@host:path` short form.
7465 "git@github.com:pleme-io/caixa-teia.git",
7466 "git@git.example.com:team/private.git",
7467 // Anonymous git protocol.
7468 "git://git.example.com/pleme-io/caixa-teia.git",
7469 // Local file URL (dev path).
7470 "file:///tmp/caixa-teia",
7471 ] {
7472 let d = dep_with_fonte(DepSource::Git {
7473 repo: repo.into(),
7474 tag: Some("v0.1.0".into()),
7475 rev: None,
7476 branch: None,
7477 });
7478 d.validate()
7479 .unwrap_or_else(|e| panic!("canonical repo {repo:?} must validate, got {e:?}"));
7480 }
7481 }
7482
7483 #[test]
7484 fn fonte_repo_empty_takes_precedence_over_shape() {
7485 // Order pin: the existing `FonteRepoEmpty` diagnostic (narrower
7486 // diagnostic; doesn't try to parse the URL shape) fires before
7487 // the new `FonteRepoShape` per-axis gate, so an empty `:repo`
7488 // keeps its narrower error message. Mirrors
7489 // `fonte_repo_empty_fires_before_pin_missing` (already pinned)
7490 // on the ordering layer.
7491 let d = dep_with_fonte(DepSource::Git {
7492 repo: String::new(),
7493 tag: Some("v0.1.0".into()),
7494 rev: None,
7495 branch: None,
7496 });
7497 let err = d.validate().unwrap_err();
7498 assert!(
7499 matches!(err, DepError::FonteRepoEmpty { .. }),
7500 "got {err:?}"
7501 );
7502 }
7503
7504 #[test]
7505 fn fonte_repo_shape_fires_before_pin_missing() {
7506 // Order pin: a malformed `:repo` value on a dep with no pin set
7507 // surfaces the `:repo` shape diagnostic (the more self-locating
7508 // axis — the `:repo` is the load-bearing identity of the source;
7509 // a missing pin is downstream from "do we even know the repo")
7510 // rather than collapsing onto the pin-missing diagnostic. The
7511 // shape gate runs inline before the pin enumeration in
7512 // `DepSource::validate`.
7513 let d = dep_with_fonte(DepSource::Git {
7514 repo: "pleme-io/caixa-teia".into(), // missing `:` separator
7515 tag: None,
7516 rev: None,
7517 branch: None,
7518 });
7519 let err = d.validate().unwrap_err();
7520 assert!(
7521 matches!(err, DepError::FonteRepoShape { .. }),
7522 "got {err:?}"
7523 );
7524 }
7525
7526 #[test]
7527 fn fonte_repo_shape_diagnostic_carries_offending_repo_verbatim() {
7528 // The diagnostic-shape pin: the error names the offending
7529 // `:repo` value verbatim plus a non-empty parser-shaped `reason`
7530 // so the author can grep their caixa.lisp without re-running
7531 // the build. Mirrors the diagnostic-shape sweep on every prior
7532 // value-shape gate (3f9d7a0, 6cbb900, c7d05ec, e70d213, be07fd5).
7533 let d = dep_with_fonte(DepSource::Git {
7534 repo: "pleme-io/caixa-teia".into(),
7535 tag: Some("v0.1.0".into()),
7536 rev: None,
7537 branch: None,
7538 });
7539 let err = d.validate().unwrap_err();
7540 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7541 panic!("expected FonteRepoShape, got other variant");
7542 };
7543 assert_eq!(nome, "caixa-teia");
7544 assert_eq!(repo, "pleme-io/caixa-teia");
7545 assert!(
7546 !reason.is_empty(),
7547 "FonteRepoShape `reason` must carry the predicate's wording verbatim"
7548 );
7549 }
7550
7551 #[test]
7552 fn validate_rejects_git_fonte_with_no_pin() {
7553 // The fail-before-pass-after pin for the canonical
7554 // `(:tipo git :repo "github:pleme-io/x")` shape with no
7555 // :tag/:rev/:branch — until this gate landed the resolver's
7556 // ResolveError::MissingPin surfaced at fetch time, far from the
7557 // source caixa.lisp. The new gate moves the check to validate
7558 // time and names the offending dep.
7559 let d = dep_with_fonte(DepSource::Git {
7560 repo: "github:pleme-io/caixa-teia".into(),
7561 tag: None,
7562 rev: None,
7563 branch: None,
7564 });
7565 let err = d.validate().unwrap_err();
7566 assert!(
7567 matches!(err, DepError::FontePinMissing { ref nome } if nome == "caixa-teia"),
7568 "got {err:?}"
7569 );
7570 }
7571
7572 #[test]
7573 fn validate_rejects_git_fonte_with_ambiguous_tag_and_branch() {
7574 // The canonical "pin drift" footgun: an author writes
7575 // `:tag "v1"` and later adds `:branch "main"` without removing
7576 // the :tag, and the resolver silently picks :tag (precedence
7577 // :rev > :tag > :branch). The :branch was dropped with no
7578 // diagnostic. The gate now rejects multi-pin shapes so the
7579 // author makes the precedence explicit at the source.
7580 let d = dep_with_fonte(DepSource::Git {
7581 repo: "github:pleme-io/caixa-teia".into(),
7582 tag: Some("v0.1.0".into()),
7583 rev: None,
7584 branch: Some("main".into()),
7585 });
7586 let err = d.validate().unwrap_err();
7587 let DepError::FontePinAmbiguous { nome, pins } = err else {
7588 panic!("expected FontePinAmbiguous");
7589 };
7590 assert_eq!(nome, "caixa-teia");
7591 assert!(pins.contains(":tag"));
7592 assert!(pins.contains(":branch"));
7593 assert!(!pins.contains(":rev"));
7594 }
7595
7596 #[test]
7597 fn validate_rejects_git_fonte_with_ambiguous_tag_and_rev() {
7598 // Sibling arm of the pin-drift footgun: :tag + :rev set
7599 // simultaneously. Pinned separately so a future relaxation
7600 // that only catches the (:tag, :branch) pair surfaces here.
7601 let d = dep_with_fonte(DepSource::Git {
7602 repo: "github:pleme-io/caixa-teia".into(),
7603 tag: Some("v0.1.0".into()),
7604 rev: Some("c0ffee".into()),
7605 branch: None,
7606 });
7607 let err = d.validate().unwrap_err();
7608 let DepError::FontePinAmbiguous { nome, pins } = err else {
7609 panic!("expected FontePinAmbiguous");
7610 };
7611 assert_eq!(nome, "caixa-teia");
7612 assert!(pins.contains(":tag"));
7613 assert!(pins.contains(":rev"));
7614 }
7615
7616 #[test]
7617 fn validate_rejects_git_fonte_with_all_three_pins() {
7618 // The maximal ambiguity case — every pin axis set. Pinned so a
7619 // future relaxation that only catches pairs surfaces here. The
7620 // diagnostic must enumerate every offending axis so the author
7621 // sees the full set, not just the first match.
7622 let d = dep_with_fonte(DepSource::Git {
7623 repo: "github:pleme-io/caixa-teia".into(),
7624 tag: Some("v0.1.0".into()),
7625 rev: Some("c0ffee".into()),
7626 branch: Some("main".into()),
7627 });
7628 let err = d.validate().unwrap_err();
7629 let DepError::FontePinAmbiguous { nome, pins } = err else {
7630 panic!("expected FontePinAmbiguous");
7631 };
7632 assert_eq!(nome, "caixa-teia");
7633 assert!(pins.contains(":tag"));
7634 assert!(pins.contains(":rev"));
7635 assert!(pins.contains(":branch"));
7636 }
7637
7638 #[test]
7639 fn validate_rejects_git_fonte_with_empty_tag_pin() {
7640 // The empty-pin arm: exactly one pin axis is `Some(_)`, but its
7641 // inner string is empty. Distinct from FontePinMissing (where
7642 // every axis is None) — pinned separately so a future
7643 // tightening collapsing them surfaces here as a structural
7644 // decision.
7645 let d = dep_with_fonte(DepSource::Git {
7646 repo: "github:pleme-io/caixa-teia".into(),
7647 tag: Some(String::new()),
7648 rev: None,
7649 branch: None,
7650 });
7651 let err = d.validate().unwrap_err();
7652 let DepError::FontePinEmpty { nome, pin } = err else {
7653 panic!("expected FontePinEmpty");
7654 };
7655 assert_eq!(nome, "caixa-teia");
7656 assert_eq!(pin, ":tag");
7657 }
7658
7659 #[test]
7660 fn validate_rejects_git_fonte_with_empty_rev_pin() {
7661 // Sibling arm — the empty-pin diagnostic names which axis
7662 // carries the empty value, so the author's grep target is
7663 // unambiguous.
7664 let d = dep_with_fonte(DepSource::Git {
7665 repo: "github:pleme-io/caixa-teia".into(),
7666 tag: None,
7667 rev: Some(String::new()),
7668 branch: None,
7669 });
7670 let err = d.validate().unwrap_err();
7671 let DepError::FontePinEmpty { nome, pin } = err else {
7672 panic!("expected FontePinEmpty");
7673 };
7674 assert_eq!(nome, "caixa-teia");
7675 assert_eq!(pin, ":rev");
7676 }
7677
7678 #[test]
7679 fn validate_rejects_path_fonte_with_empty_caminho() {
7680 // The fail-before-pass-after pin for `(:tipo path :caminho "")`:
7681 // until this gate landed the resolver's
7682 // ResolveError::MissingPath surfaced with `path: PathBuf("")` at
7683 // fetch time — not actionable. The new gate moves the check to
7684 // validate time and names the offending dep.
7685 let d = dep_with_fonte(DepSource::Path {
7686 caminho: String::new(),
7687 });
7688 let err = d.validate().unwrap_err();
7689 assert!(
7690 matches!(err, DepError::FonteCaminhoEmpty { ref nome } if nome == "caixa-teia"),
7691 "got {err:?}"
7692 );
7693 }
7694
7695 #[test]
7696 fn validate_rejects_path_fonte_with_absolute_caminho() {
7697 // The fail-before-pass-after pin for the absolute-`:caminho`
7698 // shape: `(:tipo path :caminho "/home/me/work/caixa-teia")`.
7699 // Until this gate landed an absolute `:caminho` silently
7700 // passed validate; the lacre pipeline embedded the
7701 // host-specific filesystem path verbatim in its
7702 // content-address (`conteudo: format!("path:{caminho}")`,
7703 // caixa-resolver/src/resolve.rs:189), so the BLAKE3 closure
7704 // differed per machine — the build succeeded but two CI
7705 // runners with different `${HOME}` layouts emitted two
7706 // distinct lacres for the byte-identical caixa, silently
7707 // breaking the THEORY.md §V.2 render-determinism contract
7708 // far from the source caixa.lisp. The new gate moves the
7709 // check to validate time and names the offending dep +
7710 // caminho verbatim.
7711 let d = dep_with_fonte(DepSource::Path {
7712 caminho: "/home/me/work/caixa-teia".into(),
7713 });
7714 let err = d.validate().unwrap_err();
7715 let DepError::FonteCaminhoAbsolute { nome, caminho } = err else {
7716 panic!("expected FonteCaminhoAbsolute, got other variant");
7717 };
7718 assert_eq!(nome, "caixa-teia");
7719 assert_eq!(caminho, "/home/me/work/caixa-teia");
7720 }
7721
7722 #[test]
7723 fn validate_accepts_path_fonte_with_parent_escape_caminho() {
7724 // The canonical sibling-workspace dep form
7725 // (`:caminho "../caixa-teia"`) remains accepted. The
7726 // absolute-path gate above is specifically narrower than the
7727 // shared [`crate::render::is_sandboxed_relative_path`]
7728 // predicate (which additionally forbids `..` traversal): a
7729 // local-path dep's canonical author surface is the in-tree
7730 // sibling-workspace path, so a full sandboxed-relative-path
7731 // lift would structurally reject every legitimate path-fonte
7732 // dep. Pinned so a future tightening to the full predicate
7733 // surfaces here as a structural decision, not a silent break.
7734 let d = dep_with_fonte(DepSource::Path {
7735 caminho: "../caixa-teia".into(),
7736 });
7737 d.validate().unwrap();
7738 }
7739
7740 #[test]
7741 fn validate_accepts_path_fonte_with_deeply_nested_relative_caminho() {
7742 // A multi-segment relative `:caminho`
7743 // (`"vendor/forks/caixa-teia"`) remains accepted — the
7744 // absolute-path gate brackets the host-layout-leaking shape
7745 // at the leading-`/` boundary only; every relative shape past
7746 // the empty arm continues to pass. Pinned alongside the
7747 // `..`-traversal positive control so a future tightening
7748 // surfaces the full set of legitimate relative forms here
7749 // rather than at a downstream consumer.
7750 let d = dep_with_fonte(DepSource::Path {
7751 caminho: "vendor/forks/caixa-teia".into(),
7752 });
7753 d.validate().unwrap();
7754 }
7755
7756 #[test]
7757 fn validate_rejects_path_fonte_with_tilde_prefix_caminho() {
7758 // The fail-before-pass-after pin for the tilde-expansion
7759 // `:caminho` shape: `(:tipo path :caminho "~/work/caixa-teia")`.
7760 // Until this gate landed the b94fd83 absolute arm let `~/foo`
7761 // through (`Path::is_absolute` returns false on a leading `~`
7762 // — the tilde is a shell-expansion convention, not a POSIX
7763 // path component), so the lacre embedded the value verbatim
7764 // and the resolver folded it through `Path::join` without
7765 // expansion, looking for a literal `./~/work/caixa-teia`
7766 // subdirectory and failing at resolve time with a
7767 // `No such file or directory` error far from the source
7768 // caixa.lisp. The new gate moves the check to validate time
7769 // and names the offending dep + caminho verbatim.
7770 let d = dep_with_fonte(DepSource::Path {
7771 caminho: "~/work/caixa-teia".into(),
7772 });
7773 let err = d.validate().unwrap_err();
7774 let DepError::FonteCaminhoTildeExpansion { nome, caminho } = err else {
7775 panic!("expected FonteCaminhoTildeExpansion, got {err:?}");
7776 };
7777 assert_eq!(nome, "caixa-teia");
7778 assert_eq!(caminho, "~/work/caixa-teia");
7779 }
7780
7781 #[test]
7782 fn validate_rejects_path_fonte_with_bare_tilde_caminho() {
7783 // The bare `~` form (canonical "I meant `$HOME` and forgot
7784 // the rest"): both the leading-tilde arm catches it and the
7785 // canonical-user-tilde shell idiom (`~alice/dev/caixa-teia`)
7786 // sweeps through the same arm. Pinned both to ensure the
7787 // gate doesn't narrow to `~/` only.
7788 for s in ["~", "~alice/dev/caixa-teia", "~/", "~root/work"] {
7789 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7790 let err = d.validate().unwrap_err();
7791 assert!(
7792 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7793 "{s:?} → {err:?}",
7794 );
7795 }
7796 }
7797
7798 #[test]
7799 fn validate_accepts_path_fonte_with_mid_path_tilde_caminho() {
7800 // The leading-`~` is the canonical shell-expansion footgun —
7801 // a tilde mid-path (`"../foo~bar/caixa-teia"` — the canonical
7802 // backup-file-suffix idiom) is a legitimate POSIX path byte
7803 // with no shell-expansion semantic at the leading position.
7804 // Pinned so the gate doesn't widen to a full no-tilde-anywhere
7805 // sweep that would break every legitimate-shape backup-file
7806 // path.
7807 let d = dep_with_fonte(DepSource::Path {
7808 caminho: "../foo~bar/caixa-teia".into(),
7809 });
7810 d.validate().unwrap();
7811 }
7812
7813 #[test]
7814 fn fonte_caminho_empty_fires_before_tilde_expansion() {
7815 // Cascade pin: the empty arm structurally precedes the
7816 // tilde arm (the bytes `""` and `"~"` don't overlap), but the
7817 // pin establishes the precedence at the diagnostic-shape
7818 // level should a future codec round-trip ever produce a
7819 // probe-as-both value. Mirrors the peer
7820 // `fonte_repo_empty_fires_before_pin_missing` cascade
7821 // discipline.
7822 let d = dep_with_fonte(DepSource::Path {
7823 caminho: String::new(),
7824 });
7825 let err = d.validate().unwrap_err();
7826 assert!(
7827 matches!(err, DepError::FonteCaminhoEmpty { .. }),
7828 "got {err:?}",
7829 );
7830 }
7831
7832 #[test]
7833 fn fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho() {
7834 // Diagnostic-shape pin (peer with
7835 // `validate_rejects_path_fonte_with_absolute_caminho`'s
7836 // payload assertion): the error's Display surfaces both the
7837 // offending `:nome` and the offending `:caminho` verbatim
7838 // so a `feira lint` run can render the diagnostic without
7839 // re-parsing.
7840 let d = dep_with_fonte(DepSource::Path {
7841 caminho: "~alice/dev/caixa-teia".into(),
7842 });
7843 let rendered = d.validate().unwrap_err().to_string();
7844 assert!(
7845 rendered.contains("caixa-teia"),
7846 "diagnostic must name the offending dep: {rendered}",
7847 );
7848 assert!(
7849 rendered.contains("~alice/dev/caixa-teia"),
7850 "diagnostic must quote the offending caminho: {rendered}",
7851 );
7852 assert!(
7853 rendered.contains('~'),
7854 "diagnostic must reference the tilde footgun: {rendered}",
7855 );
7856 }
7857
7858 #[test]
7859 fn validate_rejects_path_fonte_with_dollar_prefix_caminho() {
7860 // The fail-before-pass-after pin for the shell-variable-
7861 // expansion `:caminho` shape: `(:tipo path :caminho
7862 // "$HOME/work/caixa-teia")`. Until this gate landed the
7863 // b94fd83 absolute arm + the a5c248e tilde arm both let
7864 // `$HOME/foo` through (`Path::is_absolute` returns false on
7865 // a leading `$` — the `$` is a shell convention, not a POSIX
7866 // path component; `starts_with('~')` returns false too), so
7867 // the lacre embedded the value verbatim and the resolver
7868 // folded it through `Path::join` without `$`-expansion,
7869 // looking for a literal `./$HOME/work/caixa-teia`
7870 // subdirectory and failing at resolve time with a
7871 // `No such file or directory` error far from the source
7872 // caixa.lisp. The new gate moves the check to validate time
7873 // and names the offending dep + caminho verbatim.
7874 let d = dep_with_fonte(DepSource::Path {
7875 caminho: "$HOME/work/caixa-teia".into(),
7876 });
7877 let err = d.validate().unwrap_err();
7878 let DepError::FonteCaminhoVarExpansion { nome, caminho } = err else {
7879 panic!("expected FonteCaminhoVarExpansion, got {err:?}");
7880 };
7881 assert_eq!(nome, "caixa-teia");
7882 assert_eq!(caminho, "$HOME/work/caixa-teia");
7883 }
7884
7885 #[test]
7886 fn validate_rejects_path_fonte_with_dollar_brace_prefix_caminho() {
7887 // Sweep over every leading-`$` shape: the `${VAR}`-braced
7888 // form (canonical "paste-from-CI-manifest" footgun every
7889 // GitHub Actions / GitLab CI / Drone manifest carries on
7890 // `${WORKSPACE}`), the XDG idiom (`$XDG_CONFIG_HOME/caixa`,
7891 // canonical "I'm referencing a per-user config dir"),
7892 // and the bare `$` (canonical "I meant `$HOME` and forgot
7893 // the rest"). All shapes route through the same gate's
7894 // byte check. Pinned so the gate doesn't narrow to a
7895 // single shape (e.g. `$HOME/` only).
7896 for s in [
7897 "${HOME}/work/caixa-teia",
7898 "${WORKSPACE}/caixa-teia",
7899 "$XDG_CONFIG_HOME/caixa",
7900 "$",
7901 ] {
7902 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7903 let err = d.validate().unwrap_err();
7904 assert!(
7905 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
7906 "{s:?} → {err:?}",
7907 );
7908 }
7909 }
7910
7911 #[test]
7912 fn validate_rejects_path_fonte_with_mid_path_dollar_caminho() {
7913 // The `$` byte is the canonical shell-variable-expansion /
7914 // command-substitution / arithmetic-expansion sentinel and
7915 // is rejected at *every* position on the `:caminho` axis: the
7916 // leading arm surfaces `FonteCaminhoVarExpansion`, the
7917 // embedded arm surfaces `FonteCaminhoShellVariableExpansion`
7918 // (6620f39). Pinned so a future arm doesn't narrow the gate
7919 // back to the leading position and re-open the paste-from-
7920 // shell-one-liner `"../foo$HOME/bar"` / paste-from-CI-
7921 // manifest `"../foo${WORKSPACE}/bar"` / paste-from-shell-
7922 // prompt `"../foo$(whoami)/bar"` cross-idiom-leak surface on
7923 // the lacre content-address (`path:{caminho}`,
7924 // caixa-resolver/src/resolve.rs:189).
7925 let d = dep_with_fonte(DepSource::Path {
7926 caminho: "../foo$bar/caixa-teia".into(),
7927 });
7928 let err = d.validate().unwrap_err();
7929 assert!(
7930 matches!(
7931 err,
7932 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
7933 ),
7934 "got {err:?}",
7935 );
7936 }
7937
7938 #[test]
7939 fn fonte_caminho_tilde_fires_before_var_expansion() {
7940 // Cascade pin: the tilde arm structurally precedes the var
7941 // arm (the bytes `~` and `$` don't overlap at the leading
7942 // position), but the pin establishes the precedence at the
7943 // diagnostic-shape level should a future codec round-trip
7944 // ever produce a probe-as-both value. Mirrors the peer
7945 // `fonte_caminho_empty_fires_before_tilde_expansion` cascade
7946 // discipline on the immediate-predecessor arm.
7947 let d = dep_with_fonte(DepSource::Path {
7948 caminho: "~/work/caixa-teia".into(),
7949 });
7950 let err = d.validate().unwrap_err();
7951 assert!(
7952 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7953 "got {err:?}",
7954 );
7955 }
7956
7957 #[test]
7958 fn fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho() {
7959 // Diagnostic-shape pin (peer with
7960 // `fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho`'s
7961 // payload assertion on the immediate-predecessor arm): the
7962 // error's Display surfaces both the offending `:nome` and
7963 // the offending `:caminho` verbatim plus the `$` footgun
7964 // character itself so a `feira lint` run can render the
7965 // diagnostic without re-parsing.
7966 let d = dep_with_fonte(DepSource::Path {
7967 caminho: "${WORKSPACE}/caixa-teia".into(),
7968 });
7969 let rendered = d.validate().unwrap_err().to_string();
7970 assert!(
7971 rendered.contains("caixa-teia"),
7972 "diagnostic must name the offending dep: {rendered}",
7973 );
7974 assert!(
7975 rendered.contains("${WORKSPACE}/caixa-teia"),
7976 "diagnostic must quote the offending caminho: {rendered}",
7977 );
7978 assert!(
7979 rendered.contains('$'),
7980 "diagnostic must reference the dollar footgun: {rendered}",
7981 );
7982 }
7983
7984 #[test]
7985 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_nul() {
7986 // The fail-before-pass-after pin for the load-bearing NUL byte:
7987 // POSIX paths cannot contain `0x00` (every `std::fs` syscall
7988 // routes the path through `CString::new` which fails with
7989 // `NulError`); until this gate landed a `:caminho
7990 // "../caixa\0teia"` silently passed validate, the lacre
7991 // pipeline embedded the value verbatim, and the failure
7992 // surfaced at the resolver's `Path::join` → `CString::new`
7993 // boundary with a non-self-locating `NulError` far from the
7994 // source caixa.lisp. The new gate moves the check to validate
7995 // time and names the offending dep + caminho + offending byte
7996 // verbatim.
7997 let d = dep_with_fonte(DepSource::Path {
7998 caminho: "../caixa\0teia".into(),
7999 });
8000 let err = d.validate().unwrap_err();
8001 let DepError::FonteCaminhoControlChar {
8002 nome,
8003 caminho,
8004 byte,
8005 } = err
8006 else {
8007 panic!("expected FonteCaminhoControlChar, got {err:?}");
8008 };
8009 assert_eq!(nome, "caixa-teia");
8010 assert_eq!(caminho, "../caixa\0teia");
8011 assert_eq!(byte, 0x00);
8012 }
8013
8014 #[test]
8015 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_newline() {
8016 // The canonical paste-from-multiline-doc footgun on `:caminho`
8017 // — author copies `"../caixa-teia\n"` (trailing newline) out
8018 // of a multi-line code-fence or, worse, a `:caminho
8019 // "../caixa-teia\nrm -rf /"` value (CRLF-at-subprocess-argument
8020 // injection sibling on the path axis the `is_git_repo_url`
8021 // control-char arm already closes on `:repo`). Pinned
8022 // separately from the NUL arm so a future relaxation that
8023 // catches one but not the other surfaces here.
8024 let d = dep_with_fonte(DepSource::Path {
8025 caminho: "../caixa-teia\n".into(),
8026 });
8027 let err = d.validate().unwrap_err();
8028 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8029 panic!("expected FonteCaminhoControlChar, got {err:?}");
8030 };
8031 assert_eq!(byte, 0x0A);
8032 }
8033
8034 #[test]
8035 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_carriage_return() {
8036 // The CRLF sibling of the LF arm — Windows-line-ending
8037 // paste-from-multiline-doc on a `\r\n`-terminated buffer
8038 // leaves a stray `\r` mid-string after the LF strip. Pinned
8039 // separately from the LF arm so a future relaxation that
8040 // only catches LF surfaces here.
8041 let d = dep_with_fonte(DepSource::Path {
8042 caminho: "../caixa-teia\r".into(),
8043 });
8044 let err = d.validate().unwrap_err();
8045 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8046 panic!("expected FonteCaminhoControlChar, got {err:?}");
8047 };
8048 assert_eq!(byte, 0x0D);
8049 }
8050
8051 #[test]
8052 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_tab() {
8053 // The canonical paste-from-aligned-table footgun — a `\t`
8054 // mid-`:caminho` is invisible in most editors but rides
8055 // through the lacre's content-address verbatim, so two
8056 // paste-from-distinct-tables (one editor strips tabs, one
8057 // preserves them) yield divergent lacres for the byte-
8058 // identical-looking caixa. Pinned separately from the
8059 // whitespace-shaped LF/CR arms so a future relaxation that
8060 // narrows to line-terminator-only surfaces here.
8061 let d = dep_with_fonte(DepSource::Path {
8062 caminho: "../caixa\tteia".into(),
8063 });
8064 let err = d.validate().unwrap_err();
8065 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8066 panic!("expected FonteCaminhoControlChar, got {err:?}");
8067 };
8068 assert_eq!(byte, 0x09);
8069 }
8070
8071 #[test]
8072 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_del() {
8073 // The DEL byte (`0x7F`) closes the upper-end paste-from-
8074 // binary-blob footgun — the gate's contract is `b < 0x20 ||
8075 // b == 0x7F`, matching the `is_git_repo_url` /
8076 // `is_git_ref_name` predicates' control-char arms. Pinned
8077 // separately from the lower-range arms so a future narrowing
8078 // to `< 0x20` only surfaces here.
8079 let d = dep_with_fonte(DepSource::Path {
8080 caminho: "../caixa\x7fteia".into(),
8081 });
8082 let err = d.validate().unwrap_err();
8083 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8084 panic!("expected FonteCaminhoControlChar, got {err:?}");
8085 };
8086 assert_eq!(byte, 0x7F);
8087 }
8088
8089 #[test]
8090 fn validate_accepts_path_fonte_with_caminho_carrying_high_bit_utf8() {
8091 // The control-byte arm targets `0x00..=0x1F` + `0x7F` only —
8092 // high-bit / non-ASCII UTF-8 bytes are not gated. POSIX paths
8093 // are opaque byte sequences and UTF-8 multi-byte sequences
8094 // are a legitimate filename shape (the `café-teia/foo` idiom).
8095 // Pinned so the gate doesn't widen to a full ASCII-only sweep
8096 // that would break every legitimate-shape UTF-8 path.
8097 let d = dep_with_fonte(DepSource::Path {
8098 caminho: "../café-teia/foo".into(),
8099 });
8100 d.validate().unwrap();
8101 }
8102
8103 #[test]
8104 fn fonte_caminho_var_fires_before_control_char() {
8105 // Cascade pin: the var-expansion arm structurally precedes the
8106 // control-char arm. A value like `"$\n"` probes positive on
8107 // both arms (`starts_with('$')` and contains LF), but the
8108 // narrower leading-byte diagnostic (`FonteCaminhoVarExpansion`)
8109 // wins so the author sees the more self-locating shell-
8110 // expansion arm first. Mirrors the
8111 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8112 // discipline on the immediate-predecessor arm.
8113 let d = dep_with_fonte(DepSource::Path {
8114 caminho: "$HOME\n".into(),
8115 });
8116 let err = d.validate().unwrap_err();
8117 assert!(
8118 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8119 "got {err:?}",
8120 );
8121 }
8122
8123 #[test]
8124 fn validate_rejects_path_fonte_with_leading_space_caminho() {
8125 // The fail-before-pass-after pin for the leading ASCII space
8126 // `:caminho` shape: `(:tipo path :caminho " ../caixa-teia")`.
8127 // Until this gate landed the b94fd83 absolute arm + the a5c248e
8128 // tilde arm + the f4efe9c var arm + the d624c8d control-byte arm
8129 // all let `" ../caixa-teia"` through: `Path::is_absolute` returns
8130 // false on a leading space (the leading byte is `0x20`, not `0x2F`),
8131 // `starts_with('~')` / `starts_with('$')` return false, and `0x20`
8132 // is not in the `0x00..=0x1F` plus `0x7F` control-byte set (the
8133 // four ASCII whitespace bytes `0x09` tab, `0x0A` LF, `0x0D` CR
8134 // are caught, but the most common whitespace `0x20` space is
8135 // not). The lacre embedded the value verbatim and the resolver
8136 // folded it through `Path::join` looking for a literal `./ ../
8137 // caixa-teia` subdirectory and failing at resolve time with a
8138 // non-self-locating `No such file or directory` error far from
8139 // the source caixa.lisp. The new gate moves the check to
8140 // validate time and names the offending dep + caminho verbatim.
8141 let d = dep_with_fonte(DepSource::Path {
8142 caminho: " ../caixa-teia".into(),
8143 });
8144 let err = d.validate().unwrap_err();
8145 let DepError::FonteCaminhoLeadingWhitespace { nome, caminho } = err else {
8146 panic!("expected FonteCaminhoLeadingWhitespace, got {err:?}");
8147 };
8148 assert_eq!(nome, "caixa-teia");
8149 assert_eq!(caminho, " ../caixa-teia");
8150 }
8151
8152 #[test]
8153 fn validate_rejects_path_fonte_with_multiple_leading_spaces_caminho() {
8154 // The aligned-doc paste footgun sweep: more than one leading
8155 // space (`" ../caixa-teia"` — the canonical "I selected the
8156 // aligned column from a four-`:fonte`-entry `:deps` block"
8157 // paste) routes through the same gate's `starts_with(' ')`
8158 // byte check. Pinned so the gate doesn't narrow to a
8159 // single-space prefix.
8160 let d = dep_with_fonte(DepSource::Path {
8161 caminho: " ../caixa-teia".into(),
8162 });
8163 let err = d.validate().unwrap_err();
8164 assert!(
8165 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8166 "got {err:?}",
8167 );
8168 }
8169
8170 #[test]
8171 fn validate_accepts_path_fonte_with_mid_path_space_caminho() {
8172 // The leading-space is the canonical paste-from-aligned-doc
8173 // footgun — a space mid-path (`"../my dir/caixa-teia"` — the
8174 // canonical "I have a directory with a space in its name"
8175 // idiom; ASCII `0x20` is a valid POSIX filename byte) is a
8176 // legitimate path with no whitespace-leak semantic at the
8177 // non-leading position. Pinned so the gate doesn't widen to a
8178 // full no-space-anywhere sweep that would break every
8179 // legitimate-shape space-in-filename path.
8180 let d = dep_with_fonte(DepSource::Path {
8181 caminho: "../my dir/caixa-teia".into(),
8182 });
8183 d.validate().unwrap();
8184 }
8185
8186 #[test]
8187 fn fonte_caminho_var_fires_before_leading_whitespace() {
8188 // Cascade pin: the var-expansion arm structurally precedes the
8189 // leading-whitespace arm. A value like `"$ "` would probe positive
8190 // on var (`starts_with('$')`) but the leading-byte arms walk
8191 // left-to-right so the var arm fires on the leading `$` before
8192 // the leading-whitespace arm probes. Mirrors the
8193 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8194 // discipline on the immediate-predecessor arms.
8195 let d = dep_with_fonte(DepSource::Path {
8196 caminho: "$VAR".into(),
8197 });
8198 let err = d.validate().unwrap_err();
8199 assert!(
8200 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8201 "got {err:?}",
8202 );
8203 }
8204
8205 #[test]
8206 fn fonte_caminho_leading_whitespace_fires_before_control_char() {
8207 // Cascade pin: the leading-whitespace arm structurally precedes
8208 // the control-char arm. A value like `" ../foo\n"` probes
8209 // positive on both (starts with space AND contains LF), but
8210 // the narrower leading-byte diagnostic
8211 // (`FonteCaminhoLeadingWhitespace`) wins so the author sees the
8212 // more self-locating paste-from-aligned-doc arm first. Mirrors
8213 // the `fonte_caminho_var_fires_before_control_char` cascade
8214 // discipline on the immediate-predecessor arm.
8215 let d = dep_with_fonte(DepSource::Path {
8216 caminho: " ../foo\n".into(),
8217 });
8218 let err = d.validate().unwrap_err();
8219 assert!(
8220 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8221 "got {err:?}",
8222 );
8223 }
8224
8225 #[test]
8226 fn fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho() {
8227 // Diagnostic-shape pin (peer with
8228 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8229 // payload assertion on the immediate-predecessor arm): the
8230 // error's Display surfaces both the offending `:nome` and the
8231 // offending `:caminho` verbatim, so a `feira lint` run can
8232 // render the diagnostic without re-parsing and the author can
8233 // grep their caixa.lisp for `:caminho "<value>"` and fix it in
8234 // one edit.
8235 let d = dep_with_fonte(DepSource::Path {
8236 caminho: " ../caixa-teia".into(),
8237 });
8238 let rendered = d.validate().unwrap_err().to_string();
8239 assert!(
8240 rendered.contains("caixa-teia"),
8241 "diagnostic must name the offending dep: {rendered}",
8242 );
8243 assert!(
8244 rendered.contains(" ../caixa-teia"),
8245 "diagnostic must quote the offending caminho: {rendered}",
8246 );
8247 assert!(
8248 rendered.contains("space"),
8249 "diagnostic must name the space footgun: {rendered}",
8250 );
8251 }
8252
8253 #[test]
8254 fn fonte_caminho_absolute_fires_before_control_char() {
8255 // Cascade pin on the sibling leading-byte arm: a leading `/`
8256 // value with embedded control byte (`"/etc/passwd\n"`) routes
8257 // through `FonteCaminhoAbsolute` not `FonteCaminhoControlChar`
8258 // — the host-layout-leak diagnostic is the load-bearing axis,
8259 // the control byte is the secondary observation. Same precedence
8260 // logic on every prior leading-byte arm.
8261 let d = dep_with_fonte(DepSource::Path {
8262 caminho: "/etc/passwd\n".into(),
8263 });
8264 let err = d.validate().unwrap_err();
8265 assert!(
8266 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8267 "got {err:?}",
8268 );
8269 }
8270
8271 #[test]
8272 fn validate_rejects_path_fonte_with_leading_hyphen_caminho() {
8273 // The fail-before-pass-after pin for the leading-`-` CLI-arg-
8274 // injection `:caminho` shape sweep. Until this gate landed
8275 // every prior leading-byte arm passed a leading-`-` value
8276 // through: `Path::is_absolute` returns false on `-` (the
8277 // leading byte is `0x2D`, not `0x2F`), `starts_with('~')` /
8278 // `starts_with('$')` / `starts_with(' ')` all return false,
8279 // and `0x2D` sits outside the control-byte set. The lacre
8280 // embedded the value verbatim and the resolver folded it
8281 // through `Path::join` looking for a literal `./-rf` /
8282 // `./-C` / `./--upload-pack=…` subdirectory; the failure at
8283 // `Path::join` time is non-self-locating but harmless, while
8284 // the failure at every downstream `git -C {caminho}` /
8285 // `terraform -chdir={caminho}` / `find {caminho}` shell-out
8286 // is arbitrary-CLI-arg-injection because none of those
8287 // porcelains carry a `--` argument-list terminator between
8288 // the flag block and the path argument. The new arm moves the
8289 // rejection to `Caixa::from_lisp` boundary time and names
8290 // the offending dep + caminho verbatim.
8291 //
8292 // Sweep spans the canonical CLI-arg-injection shapes matching
8293 // the peer sweep on the sibling `is_git_ref_name` /
8294 // `is_git_repo_url` axes: short-flag `-rf` (the `rm -rf` /
8295 // `find -rf` reinterpretation vector), `-C` (the `git -C`
8296 // change-directory-config-injection paste), long-flag
8297 // `--upload-pack=cat /etc/passwd` (the canonical
8298 // arbitrary-command-execution vector on every git porcelain
8299 // entry point), git-config-injection `--config=core.merge=ours`,
8300 // and the degenerate single-byte `-` value.
8301 for caminho in [
8302 "-rf",
8303 "-C",
8304 "--upload-pack=cat /etc/passwd",
8305 "--config=core.merge=ours",
8306 "-",
8307 ] {
8308 let d = dep_with_fonte(DepSource::Path {
8309 caminho: caminho.into(),
8310 });
8311 let err = d.validate().unwrap_err();
8312 let DepError::FonteCaminhoLeadingHyphen { nome, caminho: got } = err else {
8313 panic!("expected FonteCaminhoLeadingHyphen for {caminho:?}, got {err:?}");
8314 };
8315 assert_eq!(nome, "caixa-teia");
8316 assert_eq!(got, caminho);
8317 }
8318 }
8319
8320 #[test]
8321 fn validate_accepts_path_fonte_with_mid_path_hyphen_caminho() {
8322 // The leading-`-` is the canonical CLI-arg-injection footgun
8323 // — a `-` anywhere else in the path (`"../caixa-teia"` — the
8324 // canonical kebab-separator-between-alphanumeric-segments
8325 // shape every DNS-1123-shaped caixa name carries; `"../-hidden"`
8326 // — a mid-path segment starting with `-`, still a legitimate
8327 // POSIX filename byte at that non-leading position because the
8328 // subprocess reads the whole `{caminho}` value as one positional
8329 // argument, so only the very first byte of the composite path
8330 // string is at the CLI-arg-injection boundary) is a legitimate
8331 // path with no CLI-flag-reinterpretation semantic at the non-
8332 // leading position of the top-level value. Pinned so the gate
8333 // doesn't widen to a full no-`-`-anywhere sweep that would
8334 // break every legitimate-shape kebab-in-filename path (i.e.
8335 // essentially every sibling-workspace caixa dep).
8336 for caminho in [
8337 "../caixa-teia",
8338 "../caixa-teia/-hidden",
8339 "./my-lib",
8340 "../foo-bar/baz",
8341 ] {
8342 let d = dep_with_fonte(DepSource::Path {
8343 caminho: caminho.into(),
8344 });
8345 d.validate()
8346 .unwrap_or_else(|e| panic!("mid-path `-` caminho {caminho:?} must pass: {e:?}"));
8347 }
8348 }
8349
8350 #[test]
8351 fn fonte_caminho_leading_whitespace_fires_before_leading_hyphen() {
8352 // Cascade pin: the leading-whitespace arm structurally precedes
8353 // the leading-hyphen arm. A value like `" -rf"` probes positive
8354 // on both (leading space AND, one byte in, a `-` — though the
8355 // leading-hyphen arm probes only the very first byte so it
8356 // wouldn't fire on this value; the pin instead documents the
8357 // arm order on the more common "leading space then a hyphen"
8358 // paste-from-aligned-doc paste-flag-shell-one-liner idiom).
8359 // The narrower leading-space diagnostic (the paste-from-aligned-
8360 // doc footgun) wins so the author sees the more self-locating
8361 // whitespace arm first. Mirrors the
8362 // `fonte_caminho_var_fires_before_leading_whitespace` cascade
8363 // discipline on the immediate-predecessor arm.
8364 let d = dep_with_fonte(DepSource::Path {
8365 caminho: " -rf".into(),
8366 });
8367 let err = d.validate().unwrap_err();
8368 assert!(
8369 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8370 "got {err:?}",
8371 );
8372 }
8373
8374 #[test]
8375 fn fonte_caminho_leading_hyphen_fires_before_control_char() {
8376 // Cascade pin: the leading-hyphen arm structurally precedes
8377 // the control-char arm. A value like `"-rf\n"` probes positive
8378 // on both (starts with `-` AND contains LF), but the narrower
8379 // leading-byte diagnostic (`FonteCaminhoLeadingHyphen`) wins so
8380 // the author sees the more self-locating CLI-arg-injection arm
8381 // first. Mirrors the
8382 // `fonte_caminho_leading_whitespace_fires_before_control_char`
8383 // cascade discipline on the immediate-predecessor arm.
8384 let d = dep_with_fonte(DepSource::Path {
8385 caminho: "-rf\n".into(),
8386 });
8387 let err = d.validate().unwrap_err();
8388 assert!(
8389 matches!(err, DepError::FonteCaminhoLeadingHyphen { .. }),
8390 "got {err:?}",
8391 );
8392 }
8393
8394 #[test]
8395 fn fonte_caminho_leading_hyphen_diagnostic_carries_offending_dep_and_caminho() {
8396 // Diagnostic-shape pin (peer with
8397 // `fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho`'s
8398 // payload assertion on the immediate-predecessor arm): the
8399 // error's Display surfaces both the offending `:nome` and the
8400 // offending `:caminho` verbatim plus the CLI-argument-injection
8401 // vocabulary, so a `feira lint` run can render the diagnostic
8402 // without re-parsing and the author can grep their caixa.lisp
8403 // for `:caminho "<value>"` and fix it in one edit.
8404 let d = dep_with_fonte(DepSource::Path {
8405 caminho: "--upload-pack=cat /etc/passwd".into(),
8406 });
8407 let rendered = d.validate().unwrap_err().to_string();
8408 assert!(
8409 rendered.contains("caixa-teia"),
8410 "diagnostic must name the offending dep: {rendered}",
8411 );
8412 assert!(
8413 rendered.contains("--upload-pack=cat /etc/passwd"),
8414 "diagnostic must quote the offending caminho: {rendered}",
8415 );
8416 assert!(
8417 rendered.contains("CLI-argument-injection"),
8418 "diagnostic must name the CLI-argument-injection vector: {rendered}",
8419 );
8420 assert!(
8421 rendered.contains("`-`"),
8422 "diagnostic must name the offending byte: {rendered}",
8423 );
8424 }
8425
8426 #[test]
8427 fn fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte() {
8428 // Diagnostic-shape pin (peer with
8429 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8430 // payload assertion on the immediate-predecessor arm): the
8431 // error's Display surfaces the offending `:nome`, the
8432 // offending `:caminho` verbatim, and the offending byte in
8433 // hex form (`0x09` for tab) so a `feira lint` run can render
8434 // the diagnostic without re-parsing.
8435 let d = dep_with_fonte(DepSource::Path {
8436 caminho: "../caixa\tteia".into(),
8437 });
8438 let rendered = d.validate().unwrap_err().to_string();
8439 assert!(
8440 rendered.contains("caixa-teia"),
8441 "diagnostic must name the offending dep: {rendered}",
8442 );
8443 assert!(
8444 rendered.contains("../caixa\tteia"),
8445 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8446 );
8447 assert!(
8448 rendered.contains("0x09"),
8449 "diagnostic must name the offending byte in hex: {rendered:?}",
8450 );
8451 }
8452
8453 #[test]
8454 fn validate_rejects_path_fonte_with_caminho_carrying_backslash() {
8455 // The fail-before-pass-after pin for the canonical Windows-
8456 // path-separator paste footgun: an author who pastes a path
8457 // from Windows-Explorer's `Copy as path`, PowerShell's
8458 // `Get-Location`, or any CMD/Cygwin/MSYS shell prompt
8459 // produces `..\caixa-teia`-shape values that silently passed
8460 // every prior arm (`Path::is_absolute("..\\caixa-teia")` is
8461 // false; `\` is neither a leading-byte sentinel nor a
8462 // control byte). On POSIX resolvers the value rides through
8463 // `Path::join` as a literal directory name and fails at
8464 // resolve time with `No such file or directory`; on Windows
8465 // resolvers the value resolves to the parent's sibling — two
8466 // distinct directories for the byte-identical caixa.lisp.
8467 // The new arm moves the rejection to validate time and names
8468 // the offending dep + caminho verbatim.
8469 let d = dep_with_fonte(DepSource::Path {
8470 caminho: "..\\caixa-teia".into(),
8471 });
8472 let err = d.validate().unwrap_err();
8473 let DepError::FonteCaminhoBackslash { nome, caminho } = err else {
8474 panic!("expected FonteCaminhoBackslash, got {err:?}");
8475 };
8476 assert_eq!(nome, "caixa-teia");
8477 assert_eq!(caminho, "..\\caixa-teia");
8478 }
8479
8480 #[test]
8481 fn validate_rejects_path_fonte_with_caminho_carrying_windows_drive_letter() {
8482 // The Windows drive-letter paste shape (`C:\work\caixa-teia`
8483 // out of Explorer / `cd`-and-`pwd`-on-Windows). On POSIX
8484 // hosts `Path::is_absolute("C:\\work\\caixa-teia")` returns
8485 // false (POSIX absolute paths start with `/`, drive letters
8486 // are not a POSIX concept), so the b94fd83 absolute arm
8487 // doesn't fire; the value contains `\` bytes that this arm
8488 // now catches with the more self-locating Windows-path-
8489 // separator diagnostic. Pinned separately from the bare
8490 // `..\caixa-teia` shape so a future arm that targets only
8491 // leading-`..\` doesn't regress the drive-letter coverage.
8492 let d = dep_with_fonte(DepSource::Path {
8493 caminho: "C:\\work\\caixa-teia".into(),
8494 });
8495 let err = d.validate().unwrap_err();
8496 assert!(
8497 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8498 "got {err:?}",
8499 );
8500 }
8501
8502 #[test]
8503 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backslash() {
8504 // The trailing-`\` shape (`..\caixa-teia\` — the canonical
8505 // PowerShell tab-completion-on-a-directory append). Pinned
8506 // separately from the embedded-`\` shape so the gate's
8507 // contract is "any `\` anywhere", not "any `\` not at end".
8508 let d = dep_with_fonte(DepSource::Path {
8509 caminho: "..\\caixa-teia\\".into(),
8510 });
8511 let err = d.validate().unwrap_err();
8512 assert!(
8513 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8514 "got {err:?}",
8515 );
8516 }
8517
8518 #[test]
8519 fn validate_accepts_path_fonte_with_caminho_carrying_legitimate_forward_slash() {
8520 // The positive-control pin: the gate targets `\` only,
8521 // never `/`. The canonical relative POSIX path
8522 // (`../caixa-teia/foo/bar`) must continue to validate cleanly
8523 // so legitimate nested-directory deps aren't broken. Pinned
8524 // so the gate doesn't accidentally widen to a "no path
8525 // separators at all" sweep.
8526 let d = dep_with_fonte(DepSource::Path {
8527 caminho: "../caixa-teia/foo/bar".into(),
8528 });
8529 d.validate().unwrap();
8530 }
8531
8532 #[test]
8533 fn fonte_caminho_control_char_fires_before_backslash() {
8534 // Cascade pin: the control-char arm structurally precedes the
8535 // backslash arm. A value like `"..\caixa\0teia"` probes
8536 // positive on both (`\` byte + NUL byte), but the control-
8537 // char diagnostic wins so the author sees the more self-
8538 // locating POSIX-syscall-rejected-byte diagnostic first
8539 // (NUL outright breaks `CString::new` at every `std::fs`
8540 // syscall boundary; the `\` divergence is the cross-OS-
8541 // separator axis). Mirrors the
8542 // `fonte_caminho_var_fires_before_control_char` cascade
8543 // discipline on the immediate-predecessor arm.
8544 let d = dep_with_fonte(DepSource::Path {
8545 caminho: "..\\caixa\0teia".into(),
8546 });
8547 let err = d.validate().unwrap_err();
8548 assert!(
8549 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8550 "got {err:?}",
8551 );
8552 }
8553
8554 #[test]
8555 fn fonte_caminho_absolute_fires_before_backslash() {
8556 // Cascade pin on the load-bearing leading-byte arm: a leading
8557 // `/` value with embedded `\` (`/etc/passwd\foo`) routes
8558 // through `FonteCaminhoAbsolute` not `FonteCaminhoBackslash`
8559 // — the host-layout-leak diagnostic is the load-bearing
8560 // axis, the `\` byte is the secondary observation. Same
8561 // precedence logic as every prior leading-byte arm.
8562 let d = dep_with_fonte(DepSource::Path {
8563 caminho: "/etc/passwd\\foo".into(),
8564 });
8565 let err = d.validate().unwrap_err();
8566 assert!(
8567 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8568 "got {err:?}",
8569 );
8570 }
8571
8572 #[test]
8573 fn fonte_caminho_var_fires_before_backslash() {
8574 // Cascade pin on the var-expansion arm: a leading-`$` value
8575 // with embedded `\` (`$WORKSPACE\caixa-teia` — the canonical
8576 // PowerShell-env-var paste-from-CI-manifest footgun) routes
8577 // through `FonteCaminhoVarExpansion` not `FonteCaminhoBackslash`.
8578 // The shell-expansion diagnostic is the more self-locating
8579 // axis since both the leading `$` and the embedded `\`
8580 // are Windows-shell artifacts but the `$` is the root-cause
8581 // surface (an author who removes the `$` is likely to leave
8582 // the `\` too).
8583 let d = dep_with_fonte(DepSource::Path {
8584 caminho: "$WORKSPACE\\caixa-teia".into(),
8585 });
8586 let err = d.validate().unwrap_err();
8587 assert!(
8588 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8589 "got {err:?}",
8590 );
8591 }
8592
8593 #[test]
8594 fn fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho() {
8595 // Diagnostic-shape pin (peer with the prior
8596 // `fonte_caminho_*_diagnostic_carries_*` payload assertions
8597 // on every preceding arm): the error's Display surfaces the
8598 // offending `:nome` and the offending `:caminho` verbatim
8599 // so a `feira lint` run can render the diagnostic without
8600 // re-parsing.
8601 let d = dep_with_fonte(DepSource::Path {
8602 caminho: "..\\caixa-teia".into(),
8603 });
8604 let rendered = d.validate().unwrap_err().to_string();
8605 assert!(
8606 rendered.contains("caixa-teia"),
8607 "diagnostic must name the offending dep: {rendered}",
8608 );
8609 assert!(
8610 rendered.contains("..\\caixa-teia"),
8611 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8612 );
8613 assert!(
8614 rendered.contains('\\'),
8615 "diagnostic must reference the backslash footgun: {rendered:?}",
8616 );
8617 }
8618
8619 #[test]
8620 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_slash() {
8621 // The fail-before-pass-after pin for the canonical trailing-`/`
8622 // paste footgun: an author who shell-tab-completes a sibling
8623 // directory (every interactive shell — bash/zsh/fish/nushell —
8624 // appends `/` on tab-completing a directory) produces
8625 // `"../caixa-teia/"`-shape values that silently passed every
8626 // prior arm (the leading byte is `.`, no control bytes, no
8627 // backslash). `Path::join` resolves both shapes to the same
8628 // directory at the resolver, but the lacre embeds the value
8629 // verbatim and the BLAKE3 closures diverge across two
8630 // workstations whose authors differ only in tab-completion
8631 // habits.
8632 let d = dep_with_fonte(DepSource::Path {
8633 caminho: "../caixa-teia/".into(),
8634 });
8635 let err = d.validate().unwrap_err();
8636 let DepError::FonteCaminhoTrailingSlash { nome, caminho } = err else {
8637 panic!("expected FonteCaminhoTrailingSlash, got {err:?}");
8638 };
8639 assert_eq!(nome, "caixa-teia");
8640 assert_eq!(caminho, "../caixa-teia/");
8641 }
8642
8643 #[test]
8644 fn validate_rejects_path_fonte_with_caminho_carrying_bare_dot_slash() {
8645 // The `"./"` shape (the canonical "I meant the caixa.lisp's own
8646 // directory and tab-completed it" footgun). Pinned separately
8647 // from the canonical `"../caixa-teia/"` shape so the gate's
8648 // contract is "any trailing `/`", not "trailing `/` after a leaf
8649 // name".
8650 let d = dep_with_fonte(DepSource::Path {
8651 caminho: "./".into(),
8652 });
8653 let err = d.validate().unwrap_err();
8654 assert!(
8655 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8656 "got {err:?}",
8657 );
8658 }
8659
8660 #[test]
8661 fn validate_rejects_path_fonte_with_caminho_carrying_consecutive_trailing_slashes() {
8662 // The `"foo//"` shape (the canonical "I pasted from a CI manifest
8663 // that double-templated `${VAR}/` over an already-`/`-suffixed
8664 // path" footgun). The gate fires on the last byte being `/`
8665 // regardless of how many `/` precede it; the arm contract is
8666 // "the value ends with `/`", structurally.
8667 let d = dep_with_fonte(DepSource::Path {
8668 caminho: "../caixa-teia//".into(),
8669 });
8670 let err = d.validate().unwrap_err();
8671 assert!(
8672 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8673 "got {err:?}",
8674 );
8675 }
8676
8677 #[test]
8678 fn validate_rejects_path_fonte_with_caminho_carrying_dotdot_trailing_slash() {
8679 // The `"../"` shape (the canonical "I want the parent" tab-
8680 // completion footgun on a bare `..` path). Pinned separately so
8681 // the gate doesn't accidentally narrow to "trailing `/` only on
8682 // multi-segment paths".
8683 let d = dep_with_fonte(DepSource::Path {
8684 caminho: "../".into(),
8685 });
8686 let err = d.validate().unwrap_err();
8687 assert!(
8688 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8689 "got {err:?}",
8690 );
8691 }
8692
8693 #[test]
8694 fn validate_accepts_path_fonte_with_caminho_carrying_internal_slashes() {
8695 // The positive-control pin: the gate targets the trailing byte
8696 // only, never internal `/` separators. The canonical nested
8697 // relative POSIX path (`"../caixa-teia/foo/bar"`) must continue
8698 // to validate cleanly so legitimate deeply-nested deps aren't
8699 // broken. Pinned so the gate doesn't accidentally widen to a
8700 // "no `/` separators anywhere" sweep that would defeat the
8701 // entire path-fonte author surface.
8702 let d = dep_with_fonte(DepSource::Path {
8703 caminho: "../caixa-teia/foo/bar".into(),
8704 });
8705 d.validate().unwrap();
8706 }
8707
8708 #[test]
8709 fn validate_accepts_path_fonte_with_caminho_carrying_bare_dot() {
8710 // The positive-control pin on the degenerate single-`.` shape
8711 // (the canonical "the caixa.lisp's own directory" idiom). The
8712 // gate fires on the trailing byte being `/`, not on the path
8713 // being short, so `"."` (one byte, not `/`) must continue to
8714 // validate cleanly.
8715 let d = dep_with_fonte(DepSource::Path {
8716 caminho: ".".into(),
8717 });
8718 d.validate().unwrap();
8719 }
8720
8721 #[test]
8722 fn fonte_caminho_control_char_fires_before_trailing_slash() {
8723 // Cascade pin: the control-char arm structurally precedes the
8724 // trailing-slash arm. A value like `"../foo\n/"` ends in `/`
8725 // but the embedded LF (`0x0A`) is the load-bearing diagnostic
8726 // (control bytes are the paste-from-multiline-doc footgun the
8727 // d624c8d arm already closes). Mirrors the
8728 // `fonte_caminho_control_char_fires_before_backslash` cascade
8729 // discipline on the immediate-predecessor arm.
8730 let d = dep_with_fonte(DepSource::Path {
8731 caminho: "../foo\n/".into(),
8732 });
8733 let err = d.validate().unwrap_err();
8734 assert!(
8735 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8736 "got {err:?}",
8737 );
8738 }
8739
8740 #[test]
8741 fn fonte_caminho_backslash_fires_before_trailing_slash() {
8742 // Cascade pin on the backslash arm: a value like `"..\foo/"`
8743 // ends in `/` but the embedded `\` is the load-bearing
8744 // diagnostic (the cross-host-OS-separator divergence vector
8745 // the 3a4e1d7 arm closes). Same precedence logic as the prior
8746 // narrower-diagnostic-first cascade.
8747 let d = dep_with_fonte(DepSource::Path {
8748 caminho: "..\\caixa-teia/".into(),
8749 });
8750 let err = d.validate().unwrap_err();
8751 assert!(
8752 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8753 "got {err:?}",
8754 );
8755 }
8756
8757 #[test]
8758 fn fonte_caminho_absolute_fires_before_trailing_slash() {
8759 // Cascade pin on the load-bearing leading-byte arm: a leading
8760 // `/` value with a trailing `/` (`"/etc/passwd/"`) routes
8761 // through `FonteCaminhoAbsolute` not `FonteCaminhoTrailingSlash`
8762 // — the host-layout-leak diagnostic is the load-bearing axis,
8763 // the trailing `/` is the secondary observation. Same
8764 // precedence logic as every prior leading-byte arm.
8765 let d = dep_with_fonte(DepSource::Path {
8766 caminho: "/etc/passwd/".into(),
8767 });
8768 let err = d.validate().unwrap_err();
8769 assert!(
8770 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8771 "got {err:?}",
8772 );
8773 }
8774
8775 #[test]
8776 fn fonte_caminho_trailing_slash_diagnostic_carries_offending_dep_and_caminho() {
8777 // Diagnostic-shape pin (peer with the prior
8778 // `fonte_caminho_*_diagnostic_carries_*` payload assertions on
8779 // every preceding arm): the error's Display surfaces the
8780 // offending `:nome` and the offending `:caminho` verbatim so a
8781 // `feira lint` run can render the diagnostic without re-parsing.
8782 let d = dep_with_fonte(DepSource::Path {
8783 caminho: "../caixa-teia/".into(),
8784 });
8785 let rendered = d.validate().unwrap_err().to_string();
8786 assert!(
8787 rendered.contains("caixa-teia"),
8788 "diagnostic must name the offending dep: {rendered}",
8789 );
8790 assert!(
8791 rendered.contains("../caixa-teia/"),
8792 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8793 );
8794 assert!(
8795 rendered.contains("trailing"),
8796 "diagnostic must reference the trailing-slash footgun: {rendered:?}",
8797 );
8798 }
8799
8800 // -- :caminho shell-redirection metacharacter arm -----------------------
8801
8802 #[test]
8803 fn validate_rejects_path_fonte_with_caminho_carrying_gt_redirection() {
8804 // The fail-before-pass-after pin for the canonical output-redirection
8805 // paste footgun: an author copies a shell pipeline tail
8806 // (`"../caixa-teia>build.log"` — the canonical "I selected the whole
8807 // line including the `> build.log` redirect" idiom) and silently
8808 // passed every prior arm (`Path::is_absolute` false on `..`, no
8809 // control bytes, no backslash, doesn't end in `/`). The lacre
8810 // embedded the value verbatim, the resolver folded it through
8811 // `Path::join` looking for a literal `./../caixa-teia>build.log`
8812 // subdirectory, and the failure surfaced at resolve time with a
8813 // non-self-locating `No such file or directory` error. The new arm
8814 // moves the rejection to validate time and names the offending dep
8815 // + caminho + byte verbatim.
8816 let d = dep_with_fonte(DepSource::Path {
8817 caminho: "../caixa-teia>build.log".into(),
8818 });
8819 let err = d.validate().unwrap_err();
8820 let DepError::FonteCaminhoShellRedirection {
8821 nome,
8822 caminho,
8823 byte,
8824 } = err
8825 else {
8826 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8827 };
8828 assert_eq!(nome, "caixa-teia");
8829 assert_eq!(caminho, "../caixa-teia>build.log");
8830 assert_eq!(byte, b'>');
8831 }
8832
8833 #[test]
8834 fn validate_rejects_path_fonte_with_caminho_carrying_lt_redirection() {
8835 // The symmetric input-redirection paste shape
8836 // (`"../caixa-teia<input.lisp"` — the canonical "I copied a
8837 // `command < input.lisp` line from a tatara-lisp REPL log"
8838 // idiom). Pinned separately from the `>` shape so the gate's
8839 // contract is "any `<` or `>` anywhere", not single-byte coverage.
8840 let d = dep_with_fonte(DepSource::Path {
8841 caminho: "../caixa-teia<input.lisp".into(),
8842 });
8843 let err = d.validate().unwrap_err();
8844 let DepError::FonteCaminhoShellRedirection { byte, .. } = err else {
8845 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8846 };
8847 assert_eq!(byte, b'<');
8848 }
8849
8850 #[test]
8851 fn validate_rejects_path_fonte_with_caminho_carrying_leading_gt_redirection() {
8852 // Leading-position `>` shape (`">../caixa-teia"` — the degenerate
8853 // "I forgot the source side of the redirect" idiom). Pinned
8854 // separately from the embedded-byte shapes so the gate covers
8855 // every position, not only mid-path.
8856 let d = dep_with_fonte(DepSource::Path {
8857 caminho: ">../caixa-teia".into(),
8858 });
8859 let err = d.validate().unwrap_err();
8860 assert!(
8861 matches!(
8862 err,
8863 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8864 ),
8865 "got {err:?}",
8866 );
8867 }
8868
8869 #[test]
8870 fn validate_rejects_path_fonte_with_caminho_carrying_double_gt_append() {
8871 // The bash append-redirection shape (`"../caixa-teia>>build.log"` —
8872 // the canonical "I copied a `>>` append redirect" idiom). The arm
8873 // fires on the first `>` encountered; pinned so a future arm that
8874 // tries to distinguish `>` from `>>` doesn't break the broader
8875 // contract.
8876 let d = dep_with_fonte(DepSource::Path {
8877 caminho: "../caixa-teia>>build.log".into(),
8878 });
8879 let err = d.validate().unwrap_err();
8880 assert!(
8881 matches!(
8882 err,
8883 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8884 ),
8885 "got {err:?}",
8886 );
8887 }
8888
8889 #[test]
8890 fn validate_accepts_path_fonte_with_caminho_carrying_no_redirection() {
8891 // The positive-control pin: the gate targets only `<` / `>`,
8892 // never adjacent printable ASCII or POSIX-valid bytes. The
8893 // canonical relative POSIX path (`"../caixa-teia"`) and a
8894 // nested deeply-pathed variant (`"../caixa-teia/foo/bar"`) must
8895 // continue to validate cleanly so the gate doesn't widen to a
8896 // "no printable punctuation anywhere" sweep that would defeat
8897 // the entire path-fonte author surface.
8898 let d = dep_with_fonte(DepSource::Path {
8899 caminho: "../caixa-teia/foo/bar".into(),
8900 });
8901 d.validate().unwrap();
8902 }
8903
8904 #[test]
8905 fn fonte_caminho_backslash_fires_before_shell_redirection() {
8906 // Cascade pin on the immediate-predecessor arm: a value carrying
8907 // both `\` and `<` / `>` (`"..\caixa-teia>build.log"` — the
8908 // canonical "I pasted a Windows-shell command with output
8909 // redirect" footgun) routes through `FonteCaminhoBackslash` not
8910 // `FonteCaminhoShellRedirection`. The cross-host-OS-separator
8911 // divergence is the load-bearing axis (an author who removes
8912 // the `\` is the root-cause edit; the `>` falls away in the
8913 // same edit since it's downstream of the Windows-shell
8914 // convention).
8915 let d = dep_with_fonte(DepSource::Path {
8916 caminho: "..\\caixa-teia>build.log".into(),
8917 });
8918 let err = d.validate().unwrap_err();
8919 assert!(
8920 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8921 "got {err:?}",
8922 );
8923 }
8924
8925 #[test]
8926 fn fonte_caminho_control_char_fires_before_shell_redirection() {
8927 // Cascade pin on the embedded-control-byte arm: a value carrying
8928 // both a control byte and `<` / `>` (`"../foo\n>bar"` — the
8929 // canonical paste-from-multiline-doc footgun where a newline
8930 // landed mid-caminho) routes through `FonteCaminhoControlChar`
8931 // not `FonteCaminhoShellRedirection`. The POSIX-syscall-
8932 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
8933 // load-bearing axis on every value that probes positive for
8934 // both — mirrors the cascade discipline on every prior arm.
8935 let d = dep_with_fonte(DepSource::Path {
8936 caminho: "../foo\n>bar".into(),
8937 });
8938 let err = d.validate().unwrap_err();
8939 assert!(
8940 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8941 "got {err:?}",
8942 );
8943 }
8944
8945 #[test]
8946 fn fonte_caminho_absolute_fires_before_shell_redirection() {
8947 // Cascade pin on the load-bearing leading-byte arm: a leading
8948 // `/` value with embedded `<` / `>` (`"/etc/passwd>out"`)
8949 // routes through `FonteCaminhoAbsolute` not
8950 // `FonteCaminhoShellRedirection` — the host-layout-leak
8951 // diagnostic is the load-bearing axis, the `>` byte is the
8952 // secondary observation. Same precedence logic as every prior
8953 // leading-byte arm.
8954 let d = dep_with_fonte(DepSource::Path {
8955 caminho: "/etc/passwd>out".into(),
8956 });
8957 let err = d.validate().unwrap_err();
8958 assert!(
8959 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8960 "got {err:?}",
8961 );
8962 }
8963
8964 #[test]
8965 fn fonte_caminho_shell_redirection_fires_before_trailing_slash() {
8966 // Cascade pin on the immediate-successor arm: a value carrying
8967 // both `<` / `>` and a trailing `/` (`"../foo></"` — the
8968 // canonical "I tab-completed a path that already had a
8969 // redirect" footgun) routes through `FonteCaminhoShellRedirection`
8970 // not `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
8971 // the more semantic-locating axis (an author who removes the
8972 // `<` / `>` typically also drops the trailing separator since
8973 // both are paste-from-shell artifacts).
8974 let d = dep_with_fonte(DepSource::Path {
8975 caminho: "../foo></".into(),
8976 });
8977 let err = d.validate().unwrap_err();
8978 assert!(
8979 matches!(
8980 err,
8981 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
8982 ),
8983 "got {err:?}",
8984 );
8985 }
8986
8987 #[test]
8988 fn fonte_caminho_shell_redirection_diagnostic_carries_offending_dep_caminho_byte() {
8989 // Diagnostic-shape pin (peer with
8990 // `fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte`'s
8991 // payload assertion on the closest peer arm that also carries a
8992 // `byte` field): the error's Display surfaces the offending
8993 // `:nome`, the offending `:caminho` verbatim, and the offending
8994 // byte in hex (`0x3c` for `<`, `0x3e` for `>`) so a `feira lint`
8995 // run can render the diagnostic without re-parsing.
8996 let d = dep_with_fonte(DepSource::Path {
8997 caminho: "../caixa-teia>build.log".into(),
8998 });
8999 let rendered = d.validate().unwrap_err().to_string();
9000 assert!(
9001 rendered.contains("caixa-teia"),
9002 "diagnostic must name the offending dep: {rendered}",
9003 );
9004 assert!(
9005 rendered.contains("../caixa-teia>build.log"),
9006 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9007 );
9008 assert!(
9009 rendered.contains("0x3e"),
9010 "diagnostic must name the offending byte in hex: {rendered:?}",
9011 );
9012 assert!(
9013 rendered.contains("redirection"),
9014 "diagnostic must name the shell-redirection footgun: {rendered:?}",
9015 );
9016 }
9017
9018 // -- :caminho shell-pipe metacharacter arm ----------------------------
9019
9020 #[test]
9021 fn validate_rejects_path_fonte_with_caminho_carrying_pipe() {
9022 // The fail-before-pass-after pin for the canonical shell-pipe
9023 // paste footgun: an author copies a shell-history line
9024 // (`"../caixa-teia | grep foo"` — the canonical "I selected
9025 // the whole `ls dir | grep` line out of zsh history") and
9026 // silently passed every prior arm (`Path::is_absolute` false
9027 // on `..`, no control bytes, no backslash, no `<` / `>`,
9028 // doesn't end in `/`). The lacre embedded the value verbatim,
9029 // the resolver folded it through `Path::join` looking for a
9030 // literal `./../caixa-teia | grep foo` subdirectory, and the
9031 // failure surfaced at resolve time with a non-self-locating
9032 // `No such file or directory` error. The new arm moves the
9033 // rejection to validate time and names the offending dep +
9034 // caminho verbatim.
9035 let d = dep_with_fonte(DepSource::Path {
9036 caminho: "../caixa-teia | grep foo".into(),
9037 });
9038 let err = d.validate().unwrap_err();
9039 let DepError::FonteCaminhoShellPipe { nome, caminho } = err else {
9040 panic!("expected FonteCaminhoShellPipe, got {err:?}");
9041 };
9042 assert_eq!(nome, "caixa-teia");
9043 assert_eq!(caminho, "../caixa-teia | grep foo");
9044 }
9045
9046 #[test]
9047 fn validate_rejects_path_fonte_with_caminho_carrying_leading_pipe() {
9048 // Leading-position `|` shape (`"|../caixa-teia"` — the
9049 // degenerate "I forgot the source side of the pipe" idiom).
9050 // Pinned separately from the embedded-byte shape so the gate
9051 // covers every position, not only mid-path.
9052 let d = dep_with_fonte(DepSource::Path {
9053 caminho: "|../caixa-teia".into(),
9054 });
9055 let err = d.validate().unwrap_err();
9056 assert!(
9057 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9058 "got {err:?}",
9059 );
9060 }
9061
9062 #[test]
9063 fn validate_rejects_path_fonte_with_caminho_carrying_double_pipe_or() {
9064 // The bash short-circuit-OR shape (`"../caixa-teia||fallback"`
9065 // — the canonical "I copied a `cmd-a || cmd-b` fallback line"
9066 // idiom). The arm fires on the first `|` encountered; pinned
9067 // so a future arm that tries to distinguish `|` from `||`
9068 // doesn't break the broader contract.
9069 let d = dep_with_fonte(DepSource::Path {
9070 caminho: "../caixa-teia||fallback".into(),
9071 });
9072 let err = d.validate().unwrap_err();
9073 assert!(
9074 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9075 "got {err:?}",
9076 );
9077 }
9078
9079 #[test]
9080 fn validate_accepts_path_fonte_with_caminho_carrying_no_pipe() {
9081 // The positive-control pin: the gate targets only `|`, never
9082 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9083 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9084 // pathed variant with adjacent printable punctuation
9085 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9086 // cleanly so the gate doesn't widen to a "no printable
9087 // punctuation anywhere" sweep that would defeat the entire
9088 // path-fonte author surface.
9089 let d = dep_with_fonte(DepSource::Path {
9090 caminho: "../caixa-teia/sub-dir.v2".into(),
9091 });
9092 d.validate().unwrap();
9093 }
9094
9095 #[test]
9096 fn fonte_caminho_shell_redirection_fires_before_shell_pipe() {
9097 // Cascade pin on the immediate-predecessor arm: a value carrying
9098 // both `<` / `>` and `|` (`"../caixa-teia<input|tee"` — the
9099 // canonical "I pasted a `cmd < input | tee` pipeline tail"
9100 // footgun) routes through `FonteCaminhoShellRedirection` not
9101 // `FonteCaminhoShellPipe`. The input/output redirection
9102 // metachar carries the more self-locating `byte: u8` payload
9103 // (it names which of `<` or `>` triggered), so the prior arm
9104 // wins on every probe-as-both value — same cascade discipline
9105 // every prior `:caminho` arm establishes.
9106 let d = dep_with_fonte(DepSource::Path {
9107 caminho: "../caixa-teia<input|tee".into(),
9108 });
9109 let err = d.validate().unwrap_err();
9110 assert!(
9111 matches!(
9112 err,
9113 DepError::FonteCaminhoShellRedirection { byte: b'<', .. }
9114 ),
9115 "got {err:?}",
9116 );
9117 }
9118
9119 #[test]
9120 fn fonte_caminho_backslash_fires_before_shell_pipe() {
9121 // Cascade pin on the upstream backslash arm: a value carrying
9122 // both `\` and `|` (`"..\caixa-teia|tee"` — the canonical
9123 // "I pasted a Windows-shell command with pipe to tee"
9124 // footgun) routes through `FonteCaminhoBackslash` not
9125 // `FonteCaminhoShellPipe`. The cross-host-OS-separator
9126 // divergence is the load-bearing axis on every probe-as-both
9127 // value (an author who removes the `\` is the root-cause edit;
9128 // the `|` falls away in the same edit since it's downstream of
9129 // the Windows-shell convention).
9130 let d = dep_with_fonte(DepSource::Path {
9131 caminho: "..\\caixa-teia|tee".into(),
9132 });
9133 let err = d.validate().unwrap_err();
9134 assert!(
9135 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9136 "got {err:?}",
9137 );
9138 }
9139
9140 #[test]
9141 fn fonte_caminho_control_char_fires_before_shell_pipe() {
9142 // Cascade pin on the embedded-control-byte arm: a value
9143 // carrying both a control byte and `|` (`"../foo\n|bar"` —
9144 // the canonical paste-from-multiline-doc footgun where a
9145 // newline landed mid-caminho) routes through
9146 // `FonteCaminhoControlChar` not `FonteCaminhoShellPipe`. The
9147 // POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9148 // diagnostic is the load-bearing axis on every value that
9149 // probes positive for both — mirrors the cascade discipline
9150 // on every prior arm.
9151 let d = dep_with_fonte(DepSource::Path {
9152 caminho: "../foo\n|bar".into(),
9153 });
9154 let err = d.validate().unwrap_err();
9155 assert!(
9156 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9157 "got {err:?}",
9158 );
9159 }
9160
9161 #[test]
9162 fn fonte_caminho_absolute_fires_before_shell_pipe() {
9163 // Cascade pin on the load-bearing leading-byte arm: a leading
9164 // `/` value with embedded `|` (`"/etc/passwd|tee"`) routes
9165 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellPipe`
9166 // — the host-layout-leak diagnostic is the load-bearing axis,
9167 // the `|` byte is the secondary observation. Same precedence
9168 // logic as every prior leading-byte arm.
9169 let d = dep_with_fonte(DepSource::Path {
9170 caminho: "/etc/passwd|tee".into(),
9171 });
9172 let err = d.validate().unwrap_err();
9173 assert!(
9174 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9175 "got {err:?}",
9176 );
9177 }
9178
9179 #[test]
9180 fn fonte_caminho_shell_pipe_fires_before_trailing_slash() {
9181 // Cascade pin on the immediate-successor arm: a value carrying
9182 // both `|` and a trailing `/` (`"../foo|tee/"` — the canonical
9183 // "I tab-completed a path that already had a pipeline tail"
9184 // footgun) routes through `FonteCaminhoShellPipe` not
9185 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9186 // the more semantic-locating axis (an author who removes the
9187 // `|` typically also drops the trailing separator since both
9188 // are paste-from-shell artifacts).
9189 let d = dep_with_fonte(DepSource::Path {
9190 caminho: "../foo|tee/".into(),
9191 });
9192 let err = d.validate().unwrap_err();
9193 assert!(
9194 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9195 "got {err:?}",
9196 );
9197 }
9198
9199 #[test]
9200 fn fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho() {
9201 // Diagnostic-shape pin (peer with
9202 // `fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho`
9203 // on the closest single-byte peer arm): the error's Display
9204 // surfaces the offending `:nome` and the offending `:caminho`
9205 // verbatim, and names the shell-pipe footgun explicitly so a
9206 // `feira lint` run can render the diagnostic without
9207 // re-parsing.
9208 let d = dep_with_fonte(DepSource::Path {
9209 caminho: "../caixa-teia | grep foo".into(),
9210 });
9211 let rendered = d.validate().unwrap_err().to_string();
9212 assert!(
9213 rendered.contains("caixa-teia"),
9214 "diagnostic must name the offending dep: {rendered}",
9215 );
9216 assert!(
9217 rendered.contains("../caixa-teia | grep foo"),
9218 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9219 );
9220 assert!(
9221 rendered.contains('|'),
9222 "diagnostic must reference the pipe footgun: {rendered:?}",
9223 );
9224 assert!(
9225 rendered.contains("pipe"),
9226 "diagnostic must name the shell-pipe footgun: {rendered:?}",
9227 );
9228 }
9229
9230 // -- :caminho shell-command-separator metacharacter arm ---------------
9231
9232 #[test]
9233 fn validate_rejects_path_fonte_with_caminho_carrying_semicolon() {
9234 // The fail-before-pass-after pin for the canonical shell-command-
9235 // separator paste footgun: an author copies a shell one-liner
9236 // (`"../caixa-teia; rm -rf build"` — the canonical "I selected the
9237 // whole `cd path; do-thing` chain out of a shell-history block")
9238 // and silently passed every prior arm (`Path::is_absolute` false
9239 // on `..`, no control bytes, no backslash, no `<` / `>`, no `|`,
9240 // doesn't end in `/`). The lacre embedded the value verbatim, the
9241 // resolver folded it through `Path::join` looking for a literal
9242 // `./../caixa-teia; rm -rf build` subdirectory, and the failure
9243 // surfaced at resolve time with a non-self-locating `No such file
9244 // or directory` error. The new arm moves the rejection to validate
9245 // time and names the offending dep + caminho verbatim.
9246 let d = dep_with_fonte(DepSource::Path {
9247 caminho: "../caixa-teia; rm -rf build".into(),
9248 });
9249 let err = d.validate().unwrap_err();
9250 let DepError::FonteCaminhoShellSemicolon { nome, caminho } = err else {
9251 panic!("expected FonteCaminhoShellSemicolon, got {err:?}");
9252 };
9253 assert_eq!(nome, "caixa-teia");
9254 assert_eq!(caminho, "../caixa-teia; rm -rf build");
9255 }
9256
9257 #[test]
9258 fn validate_rejects_path_fonte_with_caminho_carrying_leading_semicolon() {
9259 // Leading-position `;` shape (`";../caixa-teia"` — the degenerate
9260 // "I forgot the prior command side of the separator" idiom).
9261 // Pinned separately from the embedded-byte shape so the gate
9262 // covers every position, not only mid-path.
9263 let d = dep_with_fonte(DepSource::Path {
9264 caminho: ";../caixa-teia".into(),
9265 });
9266 let err = d.validate().unwrap_err();
9267 assert!(
9268 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9269 "got {err:?}",
9270 );
9271 }
9272
9273 #[test]
9274 fn validate_rejects_path_fonte_with_caminho_carrying_double_semicolon() {
9275 // The POSIX `case` arm `;;` terminator shape
9276 // (`"../caixa-teia;;next"` — the canonical "I copied a `case`
9277 // arm tail" idiom). The arm fires on the first `;` encountered;
9278 // pinned so a future arm that tries to distinguish `;` from `;;`
9279 // doesn't break the broader contract.
9280 let d = dep_with_fonte(DepSource::Path {
9281 caminho: "../caixa-teia;;next".into(),
9282 });
9283 let err = d.validate().unwrap_err();
9284 assert!(
9285 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9286 "got {err:?}",
9287 );
9288 }
9289
9290 #[test]
9291 fn validate_accepts_path_fonte_with_caminho_carrying_no_semicolon() {
9292 // The positive-control pin: the gate targets only `;`, never
9293 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9294 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9295 // pathed variant with adjacent printable punctuation
9296 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9297 // cleanly so the gate doesn't widen to a "no printable
9298 // punctuation anywhere" sweep that would defeat the entire
9299 // path-fonte author surface.
9300 let d = dep_with_fonte(DepSource::Path {
9301 caminho: "../caixa-teia/sub-dir.v2".into(),
9302 });
9303 d.validate().unwrap();
9304 }
9305
9306 #[test]
9307 fn fonte_caminho_shell_pipe_fires_before_shell_semicolon() {
9308 // Cascade pin on the immediate-predecessor arm: a value carrying
9309 // both `|` and `;` (`"../caixa-teia | tee; rm"` — the canonical
9310 // "I pasted a `cmd | tee; cleanup` chain" footgun) routes through
9311 // `FonteCaminhoShellPipe` not `FonteCaminhoShellSemicolon`. The
9312 // pipeline-tail paste is the load-bearing root-cause edit on
9313 // every probe-as-both value (an author who removes the `|`
9314 // typically also drops the trailing `; cleanup` since both are
9315 // the same paste-from-shell-history artifact) — same cascade
9316 // discipline every prior `:caminho` arm establishes.
9317 let d = dep_with_fonte(DepSource::Path {
9318 caminho: "../caixa-teia | tee; rm".into(),
9319 });
9320 let err = d.validate().unwrap_err();
9321 assert!(
9322 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9323 "got {err:?}",
9324 );
9325 }
9326
9327 #[test]
9328 fn fonte_caminho_shell_redirection_fires_before_shell_semicolon() {
9329 // Cascade pin on the upstream shell-redirection arm: a value
9330 // carrying both `<` / `>` and `;` (`"../caixa-teia>log; rm"` —
9331 // the canonical "I pasted a `cmd > log; cleanup` chain"
9332 // footgun) routes through `FonteCaminhoShellRedirection` not
9333 // `FonteCaminhoShellSemicolon`. The input/output redirection
9334 // metachar carries the more self-locating `byte: u8` payload
9335 // (it names which of `<` or `>` triggered), so the prior arm
9336 // wins on every probe-as-both value.
9337 let d = dep_with_fonte(DepSource::Path {
9338 caminho: "../caixa-teia>log; rm".into(),
9339 });
9340 let err = d.validate().unwrap_err();
9341 assert!(
9342 matches!(
9343 err,
9344 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9345 ),
9346 "got {err:?}",
9347 );
9348 }
9349
9350 #[test]
9351 fn fonte_caminho_backslash_fires_before_shell_semicolon() {
9352 // Cascade pin on the upstream backslash arm: a value carrying
9353 // both `\` and `;` (`"..\caixa-teia;rm"` — the canonical "I
9354 // pasted a Windows-shell `cd ..\path; cleanup` chain") routes
9355 // through `FonteCaminhoBackslash` not `FonteCaminhoShellSemicolon`.
9356 // The cross-host-OS-separator divergence is the load-bearing axis
9357 // on every probe-as-both value (an author who removes the `\` is
9358 // the root-cause edit; the `;` falls away in the same edit since
9359 // it's downstream of the Windows-shell convention).
9360 let d = dep_with_fonte(DepSource::Path {
9361 caminho: "..\\caixa-teia;rm".into(),
9362 });
9363 let err = d.validate().unwrap_err();
9364 assert!(
9365 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9366 "got {err:?}",
9367 );
9368 }
9369
9370 #[test]
9371 fn fonte_caminho_control_char_fires_before_shell_semicolon() {
9372 // Cascade pin on the embedded-control-byte arm: a value carrying
9373 // both a control byte and `;` (`"../foo\n;bar"` — the canonical
9374 // paste-from-multiline-doc footgun where a newline landed mid-
9375 // caminho) routes through `FonteCaminhoControlChar` not
9376 // `FonteCaminhoShellSemicolon`. The POSIX-syscall-rejected-byte
9377 // / NUL-`CString::new`-fail diagnostic is the load-bearing axis
9378 // on every value that probes positive for both — mirrors the
9379 // cascade discipline on every prior arm.
9380 let d = dep_with_fonte(DepSource::Path {
9381 caminho: "../foo\n;bar".into(),
9382 });
9383 let err = d.validate().unwrap_err();
9384 assert!(
9385 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9386 "got {err:?}",
9387 );
9388 }
9389
9390 #[test]
9391 fn fonte_caminho_absolute_fires_before_shell_semicolon() {
9392 // Cascade pin on the load-bearing leading-byte arm: a leading
9393 // `/` value with embedded `;` (`"/etc/passwd;rm"`) routes
9394 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellSemicolon`
9395 // — the host-layout-leak diagnostic is the load-bearing axis,
9396 // the `;` byte is the secondary observation. Same precedence
9397 // logic as every prior leading-byte arm.
9398 let d = dep_with_fonte(DepSource::Path {
9399 caminho: "/etc/passwd;rm".into(),
9400 });
9401 let err = d.validate().unwrap_err();
9402 assert!(
9403 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9404 "got {err:?}",
9405 );
9406 }
9407
9408 #[test]
9409 fn fonte_caminho_shell_semicolon_fires_before_trailing_slash() {
9410 // Cascade pin on the immediate-successor arm: a value carrying
9411 // both `;` and a trailing `/` (`"../foo;rm/"` — the canonical
9412 // "I tab-completed a path that already had a `; cleanup` tail"
9413 // footgun) routes through `FonteCaminhoShellSemicolon` not
9414 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9415 // the more semantic-locating axis (an author who removes the
9416 // `;` typically also drops the trailing separator since both
9417 // are paste-from-shell artifacts).
9418 let d = dep_with_fonte(DepSource::Path {
9419 caminho: "../foo;rm/".into(),
9420 });
9421 let err = d.validate().unwrap_err();
9422 assert!(
9423 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9424 "got {err:?}",
9425 );
9426 }
9427
9428 #[test]
9429 fn fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho() {
9430 // Diagnostic-shape pin (peer with
9431 // `fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho`
9432 // on the closest single-byte peer arm): the error's Display
9433 // surfaces the offending `:nome` and the offending `:caminho`
9434 // verbatim, and names the shell-command-separator footgun
9435 // explicitly so a `feira lint` run can render the diagnostic
9436 // without re-parsing.
9437 let d = dep_with_fonte(DepSource::Path {
9438 caminho: "../caixa-teia; rm -rf build".into(),
9439 });
9440 let rendered = d.validate().unwrap_err().to_string();
9441 assert!(
9442 rendered.contains("caixa-teia"),
9443 "diagnostic must name the offending dep: {rendered}",
9444 );
9445 assert!(
9446 rendered.contains("../caixa-teia; rm -rf build"),
9447 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9448 );
9449 assert!(
9450 rendered.contains(';'),
9451 "diagnostic must reference the semicolon footgun: {rendered:?}",
9452 );
9453 assert!(
9454 rendered.contains("command-separator"),
9455 "diagnostic must name the shell-command-separator footgun: {rendered:?}",
9456 );
9457 }
9458
9459 #[test]
9460 fn validate_rejects_path_fonte_with_caminho_carrying_ampersand() {
9461 // The fail-before-pass-after pin for the canonical shell-
9462 // background-task paste footgun: an author copies a shell one-
9463 // liner (`"../caixa-teia & sleep 1"` — the canonical "I selected
9464 // the whole `cd path & sleep 1` background-launch out of a
9465 // shell-history block") and silently passed every prior arm
9466 // (`Path::is_absolute` false on `..`, no control bytes, no
9467 // backslash, no `<` / `>`, no `|`, no `;`, doesn't end in `/`).
9468 // The lacre embedded the value verbatim, the resolver folded it
9469 // through `Path::join` looking for a literal `./../caixa-teia &
9470 // sleep 1` subdirectory, and the failure surfaced at resolve
9471 // time with a non-self-locating `No such file or directory`
9472 // error. The new arm moves the rejection to validate time and
9473 // names the offending dep + caminho verbatim.
9474 let d = dep_with_fonte(DepSource::Path {
9475 caminho: "../caixa-teia & sleep 1".into(),
9476 });
9477 let err = d.validate().unwrap_err();
9478 let DepError::FonteCaminhoShellBackground { nome, caminho } = err else {
9479 panic!("expected FonteCaminhoShellBackground, got {err:?}");
9480 };
9481 assert_eq!(nome, "caixa-teia");
9482 assert_eq!(caminho, "../caixa-teia & sleep 1");
9483 }
9484
9485 #[test]
9486 fn validate_rejects_path_fonte_with_caminho_carrying_leading_ampersand() {
9487 // Leading-position `&` shape (`"&../caixa-teia"` — the
9488 // degenerate "I forgot the prior command side of the
9489 // background terminator" idiom). Pinned separately from the
9490 // embedded-byte shape so the gate covers every position, not
9491 // only mid-path.
9492 let d = dep_with_fonte(DepSource::Path {
9493 caminho: "&../caixa-teia".into(),
9494 });
9495 let err = d.validate().unwrap_err();
9496 assert!(
9497 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9498 "got {err:?}",
9499 );
9500 }
9501
9502 #[test]
9503 fn validate_rejects_path_fonte_with_caminho_carrying_double_ampersand() {
9504 // The logical-AND `&&` shape (`"../caixa-teia && make"` — the
9505 // canonical "I copied a `cd path && make` build chain" idiom
9506 // every Makefile / shell-script wraps). The arm fires on the
9507 // first `&` encountered; pinned so a future arm that tries to
9508 // distinguish `&` from `&&` doesn't break the broader contract.
9509 let d = dep_with_fonte(DepSource::Path {
9510 caminho: "../caixa-teia && make".into(),
9511 });
9512 let err = d.validate().unwrap_err();
9513 assert!(
9514 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9515 "got {err:?}",
9516 );
9517 }
9518
9519 #[test]
9520 fn validate_accepts_path_fonte_with_caminho_carrying_no_ampersand() {
9521 // The positive-control pin: the gate targets only `&`, never
9522 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9523 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9524 // pathed variant with adjacent printable punctuation
9525 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9526 // cleanly so the gate doesn't widen to a "no printable
9527 // punctuation anywhere" sweep that would defeat the entire
9528 // path-fonte author surface.
9529 let d = dep_with_fonte(DepSource::Path {
9530 caminho: "../caixa-teia/sub-dir.v2".into(),
9531 });
9532 d.validate().unwrap();
9533 }
9534
9535 #[test]
9536 fn fonte_caminho_shell_semicolon_fires_before_shell_background() {
9537 // Cascade pin on the immediate-predecessor arm: a value carrying
9538 // both `;` and `&` (`"../caixa-teia; rm & sleep"` — the
9539 // canonical "I pasted a `cmd; cleanup & sleep` chain" footgun)
9540 // routes through `FonteCaminhoShellSemicolon` not
9541 // `FonteCaminhoShellBackground`. The sequential-command-
9542 // separator paste is the more common shell-history paste idiom
9543 // on every probe-as-both value (an author who removes the `;`
9544 // typically also drops the trailing `& sleep` since both are
9545 // paste-from-shell-history artifacts) — same cascade discipline
9546 // every prior `:caminho` arm establishes.
9547 let d = dep_with_fonte(DepSource::Path {
9548 caminho: "../caixa-teia; rm & sleep".into(),
9549 });
9550 let err = d.validate().unwrap_err();
9551 assert!(
9552 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9553 "got {err:?}",
9554 );
9555 }
9556
9557 #[test]
9558 fn fonte_caminho_shell_pipe_fires_before_shell_background() {
9559 // Cascade pin on the upstream shell-pipe arm: a value carrying
9560 // both `|` and `&` (`"../caixa-teia | tee & sleep"` — the
9561 // canonical "I pasted a `cmd | tee & sleep` background-pipeline
9562 // chain" footgun) routes through `FonteCaminhoShellPipe` not
9563 // `FonteCaminhoShellBackground`. The pipeline-tail paste is the
9564 // load-bearing root-cause edit on every probe-as-both value.
9565 let d = dep_with_fonte(DepSource::Path {
9566 caminho: "../caixa-teia | tee & sleep".into(),
9567 });
9568 let err = d.validate().unwrap_err();
9569 assert!(
9570 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9571 "got {err:?}",
9572 );
9573 }
9574
9575 #[test]
9576 fn fonte_caminho_shell_redirection_fires_before_shell_background() {
9577 // Cascade pin on the upstream shell-redirection arm: a value
9578 // carrying both `>` and `&` (`"../caixa-teia>log & sleep"` —
9579 // the canonical "I pasted a `cmd > log & sleep` background-
9580 // redirect chain" footgun) routes through
9581 // `FonteCaminhoShellRedirection` not
9582 // `FonteCaminhoShellBackground`. The input/output redirection
9583 // metachar carries the more self-locating `byte: u8` payload
9584 // (it names which of `<` or `>` triggered), so the prior arm
9585 // wins on every probe-as-both value.
9586 let d = dep_with_fonte(DepSource::Path {
9587 caminho: "../caixa-teia>log & sleep".into(),
9588 });
9589 let err = d.validate().unwrap_err();
9590 assert!(
9591 matches!(
9592 err,
9593 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9594 ),
9595 "got {err:?}",
9596 );
9597 }
9598
9599 #[test]
9600 fn fonte_caminho_backslash_fires_before_shell_background() {
9601 // Cascade pin on the upstream backslash arm: a value carrying
9602 // both `\` and `&` (`"..\caixa-teia & sleep"` — the canonical
9603 // "I pasted a Windows-shell `cd ..\path & sleep` background-
9604 // launch chain") routes through `FonteCaminhoBackslash` not
9605 // `FonteCaminhoShellBackground`. The cross-host-OS-separator
9606 // divergence is the load-bearing axis on every probe-as-both
9607 // value (an author who removes the `\` is the root-cause edit;
9608 // the `&` falls away in the same edit since it's downstream of
9609 // the Windows-shell convention).
9610 let d = dep_with_fonte(DepSource::Path {
9611 caminho: "..\\caixa-teia & sleep".into(),
9612 });
9613 let err = d.validate().unwrap_err();
9614 assert!(
9615 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9616 "got {err:?}",
9617 );
9618 }
9619
9620 #[test]
9621 fn fonte_caminho_control_char_fires_before_shell_background() {
9622 // Cascade pin on the embedded-control-byte arm: a value
9623 // carrying both a control byte and `&` (`"../foo\n&sleep"` —
9624 // the canonical paste-from-multiline-doc footgun where a
9625 // newline landed mid-caminho) routes through
9626 // `FonteCaminhoControlChar` not `FonteCaminhoShellBackground`.
9627 // The POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9628 // diagnostic is the load-bearing axis on every value that
9629 // probes positive for both — mirrors the cascade discipline on
9630 // every prior arm.
9631 let d = dep_with_fonte(DepSource::Path {
9632 caminho: "../foo\n&sleep".into(),
9633 });
9634 let err = d.validate().unwrap_err();
9635 assert!(
9636 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9637 "got {err:?}",
9638 );
9639 }
9640
9641 #[test]
9642 fn fonte_caminho_absolute_fires_before_shell_background() {
9643 // Cascade pin on the load-bearing leading-byte arm: a leading
9644 // `/` value with embedded `&` (`"/etc/passwd & sleep"`) routes
9645 // through `FonteCaminhoAbsolute` not
9646 // `FonteCaminhoShellBackground` — the host-layout-leak
9647 // diagnostic is the load-bearing axis, the `&` byte is the
9648 // secondary observation. Same precedence logic as every prior
9649 // leading-byte arm.
9650 let d = dep_with_fonte(DepSource::Path {
9651 caminho: "/etc/passwd & sleep".into(),
9652 });
9653 let err = d.validate().unwrap_err();
9654 assert!(
9655 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9656 "got {err:?}",
9657 );
9658 }
9659
9660 #[test]
9661 fn fonte_caminho_shell_background_fires_before_trailing_slash() {
9662 // Cascade pin on the immediate-successor arm: a value carrying
9663 // both `&` and a trailing `/` (`"../foo&sleep/"` — the
9664 // canonical "I tab-completed a path that already had a `&
9665 // sleep` background-launch tail" footgun) routes through
9666 // `FonteCaminhoShellBackground` not `FonteCaminhoTrailingSlash`.
9667 // The embedded shell-metachar is the more semantic-locating
9668 // axis (an author who removes the `&` typically also drops
9669 // the trailing separator since both are paste-from-shell
9670 // artifacts).
9671 let d = dep_with_fonte(DepSource::Path {
9672 caminho: "../foo&sleep/".into(),
9673 });
9674 let err = d.validate().unwrap_err();
9675 assert!(
9676 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9677 "got {err:?}",
9678 );
9679 }
9680
9681 #[test]
9682 fn fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho() {
9683 // Diagnostic-shape pin (peer with
9684 // `fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho`
9685 // on the closest single-byte peer arm): the error's Display
9686 // surfaces the offending `:nome` and the offending `:caminho`
9687 // verbatim, and names the shell-background / logical-AND
9688 // footgun explicitly so a `feira lint` run can render the
9689 // diagnostic without re-parsing.
9690 let d = dep_with_fonte(DepSource::Path {
9691 caminho: "../caixa-teia & sleep 1".into(),
9692 });
9693 let rendered = d.validate().unwrap_err().to_string();
9694 assert!(
9695 rendered.contains("caixa-teia"),
9696 "diagnostic must name the offending dep: {rendered}",
9697 );
9698 assert!(
9699 rendered.contains("../caixa-teia & sleep 1"),
9700 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9701 );
9702 assert!(
9703 rendered.contains('&'),
9704 "diagnostic must reference the ampersand footgun: {rendered:?}",
9705 );
9706 assert!(
9707 rendered.contains("background") || rendered.contains("list-AND"),
9708 "diagnostic must name the shell-background / logical-AND footgun: {rendered:?}",
9709 );
9710 }
9711
9712 #[test]
9713 fn validate_rejects_path_fonte_with_caminho_carrying_backtick() {
9714 // The fail-before-pass-after pin for the canonical shell-
9715 // command-substitution paste footgun: an author copies a
9716 // POSIX legacy backticked one-liner (`"../caixa-teia/`whoami`"`
9717 // — the canonical "I pasted a path that included a `pwd`
9718 // / `whoami` / `date` legacy command-substitution expansion
9719 // out of a shell-history block") and silently passed every
9720 // prior arm (`Path::is_absolute` false on `..`, no control
9721 // bytes, no `\`, no `<` / `>`, no `|`, no `;`, no `&`, doesn't
9722 // end in `/`). The lacre embedded the value verbatim, the
9723 // resolver folded it through `Path::join` looking for a
9724 // literal `./../caixa-teia/`whoami`` subdirectory, and the
9725 // failure surfaced at resolve time with a non-self-locating
9726 // `No such file or directory` error. The new arm moves the
9727 // rejection to validate time and names the offending dep +
9728 // caminho verbatim.
9729 let d = dep_with_fonte(DepSource::Path {
9730 caminho: "../caixa-teia/`whoami`".into(),
9731 });
9732 let err = d.validate().unwrap_err();
9733 let DepError::FonteCaminhoShellCommandSubstitution { nome, caminho } = err else {
9734 panic!("expected FonteCaminhoShellCommandSubstitution, got {err:?}");
9735 };
9736 assert_eq!(nome, "caixa-teia");
9737 assert_eq!(caminho, "../caixa-teia/`whoami`");
9738 }
9739
9740 #[test]
9741 fn validate_rejects_path_fonte_with_caminho_carrying_leading_backtick() {
9742 // Leading-position backtick shape (``"`pwd`/caixa-teia"`` —
9743 // the canonical `<backtick>pwd<backtick>/path` working-
9744 // directory expansion shape every shell-side path-composition
9745 // idiom carries). Pinned separately from the embedded-byte
9746 // shape so the gate covers every position, not only mid-path.
9747 let d = dep_with_fonte(DepSource::Path {
9748 caminho: "`pwd`/caixa-teia".into(),
9749 });
9750 let err = d.validate().unwrap_err();
9751 assert!(
9752 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9753 "got {err:?}",
9754 );
9755 }
9756
9757 #[test]
9758 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backtick() {
9759 // Trailing-position backtick shape (`"../caixa-teia`"` — the
9760 // degenerate "I selected an unbalanced backtick out of a
9761 // shell-history block" idiom that probes for the cascade's
9762 // last-byte handling). The trailing-`/` arm fires only on
9763 // last-byte `/`; an unbalanced trailing backtick must route
9764 // through this arm regardless of position.
9765 let d = dep_with_fonte(DepSource::Path {
9766 caminho: "../caixa-teia`".into(),
9767 });
9768 let err = d.validate().unwrap_err();
9769 assert!(
9770 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9771 "got {err:?}",
9772 );
9773 }
9774
9775 #[test]
9776 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_backtick_pair() {
9777 // The canonical balanced-pair shape (``"../<backtick>cat
9778 // /etc/passwd<backtick>"`` — the canonical CWE-78 shell-
9779 // command-injection paste idiom every shell-side hardening
9780 // guide enumerates first). The arm fires on the first
9781 // backtick encountered; pinned so a future arm that tries to
9782 // distinguish the opening from the closing byte doesn't break
9783 // the broader contract.
9784 let d = dep_with_fonte(DepSource::Path {
9785 caminho: "../`cat /etc/passwd`".into(),
9786 });
9787 let err = d.validate().unwrap_err();
9788 assert!(
9789 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9790 "got {err:?}",
9791 );
9792 }
9793
9794 #[test]
9795 fn validate_accepts_path_fonte_with_caminho_carrying_no_backtick() {
9796 // The positive-control pin: the gate targets only the
9797 // backtick byte, never adjacent printable ASCII or POSIX-
9798 // valid bytes. The canonical relative POSIX path
9799 // (`"../caixa-teia"`) and a nested deeply-pathed variant with
9800 // adjacent printable punctuation
9801 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9802 // cleanly so the gate doesn't widen to a "no printable
9803 // punctuation anywhere" sweep that would defeat the entire
9804 // path-fonte author surface.
9805 let d = dep_with_fonte(DepSource::Path {
9806 caminho: "../caixa-teia/sub-dir.v2".into(),
9807 });
9808 d.validate().unwrap();
9809 }
9810
9811 #[test]
9812 fn fonte_caminho_shell_background_fires_before_shell_command_substitution() {
9813 // Cascade pin on the immediate-predecessor arm: a value
9814 // carrying both `&` and a backtick (``"../caixa-teia &
9815 // <backtick>sleep 1<backtick>"`` — the canonical "I pasted a
9816 // `cmd & <backtick>sleep N<backtick>` background-launch +
9817 // command-substitution chain" footgun) routes through
9818 // `FonteCaminhoShellBackground` not
9819 // `FonteCaminhoShellCommandSubstitution`. The background-
9820 // launch tail is the more common shell-history paste idiom
9821 // on every probe-as-both value — same cascade discipline
9822 // every prior `:caminho` arm establishes.
9823 let d = dep_with_fonte(DepSource::Path {
9824 caminho: "../caixa-teia & `sleep 1`".into(),
9825 });
9826 let err = d.validate().unwrap_err();
9827 assert!(
9828 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9829 "got {err:?}",
9830 );
9831 }
9832
9833 #[test]
9834 fn fonte_caminho_shell_semicolon_fires_before_shell_command_substitution() {
9835 // Cascade pin on the upstream shell-semicolon arm: a value
9836 // carrying both `;` and a backtick (``"../caixa-teia;
9837 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9838 // `cmd; <backtick>follow-up<backtick>` sequential-chain
9839 // footgun) routes through `FonteCaminhoShellSemicolon` not
9840 // `FonteCaminhoShellCommandSubstitution`. The sequential-
9841 // command-separator paste is the load-bearing root-cause
9842 // edit on every probe-as-both value.
9843 let d = dep_with_fonte(DepSource::Path {
9844 caminho: "../caixa-teia; `whoami`".into(),
9845 });
9846 let err = d.validate().unwrap_err();
9847 assert!(
9848 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9849 "got {err:?}",
9850 );
9851 }
9852
9853 #[test]
9854 fn fonte_caminho_shell_pipe_fires_before_shell_command_substitution() {
9855 // Cascade pin on the upstream shell-pipe arm: a value
9856 // carrying both `|` and a backtick (``"../caixa-teia |
9857 // <backtick>tee log<backtick>"`` — the canonical pipeline-to-
9858 // command-substitution paste idiom) routes through
9859 // `FonteCaminhoShellPipe` not
9860 // `FonteCaminhoShellCommandSubstitution`. The pipeline-tail
9861 // paste is the load-bearing root-cause edit on every
9862 // probe-as-both value.
9863 let d = dep_with_fonte(DepSource::Path {
9864 caminho: "../caixa-teia | `tee log`".into(),
9865 });
9866 let err = d.validate().unwrap_err();
9867 assert!(
9868 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9869 "got {err:?}",
9870 );
9871 }
9872
9873 #[test]
9874 fn fonte_caminho_shell_redirection_fires_before_shell_command_substitution() {
9875 // Cascade pin on the upstream shell-redirection arm: a value
9876 // carrying both `>` and a backtick (``"../caixa-teia>log
9877 // <backtick>date<backtick>"`` — the canonical "I pasted a
9878 // `cmd > log <backtick>date<backtick>` redirect-plus-
9879 // substitution chain" footgun) routes through
9880 // `FonteCaminhoShellRedirection` not
9881 // `FonteCaminhoShellCommandSubstitution`. The input/output
9882 // redirection metachar carries the more self-locating `byte`
9883 // payload (it names which of `<` or `>` triggered), so the
9884 // prior arm wins on every probe-as-both value.
9885 let d = dep_with_fonte(DepSource::Path {
9886 caminho: "../caixa-teia>log `date`".into(),
9887 });
9888 let err = d.validate().unwrap_err();
9889 assert!(
9890 matches!(
9891 err,
9892 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9893 ),
9894 "got {err:?}",
9895 );
9896 }
9897
9898 #[test]
9899 fn fonte_caminho_backslash_fires_before_shell_command_substitution() {
9900 // Cascade pin on the upstream backslash arm: a value
9901 // carrying both `\` and a backtick (``"..\caixa-teia
9902 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9903 // Windows-shell `cd ..\path <backtick>whoami<backtick>`
9904 // chain") routes through `FonteCaminhoBackslash` not
9905 // `FonteCaminhoShellCommandSubstitution`. The cross-host-OS-
9906 // separator divergence is the load-bearing axis on every
9907 // probe-as-both value (an author who removes the `\` is the
9908 // root-cause edit; the backtick falls away in the same edit
9909 // since it's downstream of the Windows-shell convention).
9910 let d = dep_with_fonte(DepSource::Path {
9911 caminho: "..\\caixa-teia `whoami`".into(),
9912 });
9913 let err = d.validate().unwrap_err();
9914 assert!(
9915 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9916 "got {err:?}",
9917 );
9918 }
9919
9920 #[test]
9921 fn fonte_caminho_control_char_fires_before_shell_command_substitution() {
9922 // Cascade pin on the embedded-control-byte arm: a value
9923 // carrying both a control byte and a backtick (`"../foo\n
9924 // `whoami`"` — the canonical paste-from-multiline-doc
9925 // footgun where a newline landed mid-caminho between two
9926 // paste fragments) routes through `FonteCaminhoControlChar`
9927 // not `FonteCaminhoShellCommandSubstitution`. The POSIX-
9928 // syscall-rejected-byte / NUL-`CString::new`-fail diagnostic
9929 // is the load-bearing axis on every value that probes
9930 // positive for both — mirrors the cascade discipline on
9931 // every prior arm.
9932 let d = dep_with_fonte(DepSource::Path {
9933 caminho: "../foo\n`whoami`".into(),
9934 });
9935 let err = d.validate().unwrap_err();
9936 assert!(
9937 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9938 "got {err:?}",
9939 );
9940 }
9941
9942 #[test]
9943 fn fonte_caminho_absolute_fires_before_shell_command_substitution() {
9944 // Cascade pin on the load-bearing leading-byte arm: a
9945 // leading `/` value with embedded backtick (``"/etc/passwd
9946 // <backtick>whoami<backtick>"``) routes through
9947 // `FonteCaminhoAbsolute` not
9948 // `FonteCaminhoShellCommandSubstitution` — the host-layout-
9949 // leak diagnostic is the load-bearing axis, the backtick
9950 // byte is the secondary observation. Same precedence logic
9951 // as every prior leading-byte arm.
9952 let d = dep_with_fonte(DepSource::Path {
9953 caminho: "/etc/passwd `whoami`".into(),
9954 });
9955 let err = d.validate().unwrap_err();
9956 assert!(
9957 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9958 "got {err:?}",
9959 );
9960 }
9961
9962 #[test]
9963 fn fonte_caminho_shell_command_substitution_fires_before_trailing_slash() {
9964 // Cascade pin on the immediate-successor arm: a value
9965 // carrying both a backtick and a trailing `/`
9966 // (``"../`whoami`/"`` — the canonical "I tab-completed a
9967 // path that already had a backticked `whoami` substitution
9968 // tail" footgun) routes through
9969 // `FonteCaminhoShellCommandSubstitution` not
9970 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
9971 // is the more semantic-locating axis (an author who removes
9972 // the backtick typically also drops the trailing separator
9973 // since both are paste-from-shell artifacts).
9974 let d = dep_with_fonte(DepSource::Path {
9975 caminho: "../`whoami`/".into(),
9976 });
9977 let err = d.validate().unwrap_err();
9978 assert!(
9979 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9980 "got {err:?}",
9981 );
9982 }
9983
9984 #[test]
9985 fn fonte_caminho_shell_command_substitution_diagnostic_carries_offending_dep_and_caminho() {
9986 // Diagnostic-shape pin (peer with
9987 // `fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho`
9988 // on the closest single-byte peer arm): the error's Display
9989 // surfaces the offending `:nome` and the offending `:caminho`
9990 // verbatim, and names the shell-command-substitution footgun
9991 // explicitly so a `feira lint` run can render the diagnostic
9992 // without re-parsing.
9993 let d = dep_with_fonte(DepSource::Path {
9994 caminho: "../caixa-teia/`whoami`".into(),
9995 });
9996 let rendered = d.validate().unwrap_err().to_string();
9997 assert!(
9998 rendered.contains("caixa-teia"),
9999 "diagnostic must name the offending dep: {rendered}",
10000 );
10001 assert!(
10002 rendered.contains("../caixa-teia/`whoami`"),
10003 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10004 );
10005 assert!(
10006 rendered.contains('`'),
10007 "diagnostic must reference the backtick footgun: {rendered:?}",
10008 );
10009 assert!(
10010 rendered.contains("command-substitution"),
10011 "diagnostic must name the shell-command-substitution footgun: {rendered:?}",
10012 );
10013 }
10014
10015 #[test]
10016 fn validate_rejects_path_fonte_with_caminho_carrying_star_glob() {
10017 // The fail-before-pass-after pin for the canonical pathname-
10018 // expansion paste footgun: an author copies an `ls
10019 // ../caixa-teia/*` shell-listing tail into the `:caminho`
10020 // slot and silently passes every prior arm
10021 // (`Path::is_absolute` false on `..`, no control bytes, no
10022 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick,
10023 // doesn't end in `/`). The lacre embedded the value
10024 // verbatim, the resolver folded it through `Path::join`
10025 // looking for a literal `./../caixa-teia/*` subdirectory,
10026 // and the failure surfaced at resolve time with a non-self-
10027 // locating `No such file or directory` error. The new arm
10028 // moves the rejection to validate time and names the
10029 // offending dep + caminho + byte verbatim.
10030 let d = dep_with_fonte(DepSource::Path {
10031 caminho: "../caixa-teia/*".into(),
10032 });
10033 let err = d.validate().unwrap_err();
10034 let DepError::FonteCaminhoShellGlob {
10035 nome,
10036 caminho,
10037 byte,
10038 } = err
10039 else {
10040 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10041 };
10042 assert_eq!(nome, "caixa-teia");
10043 assert_eq!(caminho, "../caixa-teia/*");
10044 assert_eq!(byte, b'*');
10045 }
10046
10047 #[test]
10048 fn validate_rejects_path_fonte_with_caminho_carrying_question_glob() {
10049 // The symmetric single-char-wildcard paste shape
10050 // (`"../foo?"` — the canonical "I copied a `rm foo?` line
10051 // out of shell history" idiom). Pinned separately from the
10052 // `*` shape so the gate's contract is "any `*` or `?`
10053 // anywhere", not single-byte coverage.
10054 let d = dep_with_fonte(DepSource::Path {
10055 caminho: "../foo?".into(),
10056 });
10057 let err = d.validate().unwrap_err();
10058 let DepError::FonteCaminhoShellGlob { byte, .. } = err else {
10059 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10060 };
10061 assert_eq!(byte, b'?');
10062 }
10063
10064 #[test]
10065 fn validate_rejects_path_fonte_with_caminho_carrying_leading_star_glob() {
10066 // Leading-position `*` shape (`"*/caixa-teia"` — the
10067 // degenerate "I selected only the wildcard prefix out of a
10068 // shell-glob expression" idiom). Pinned separately from the
10069 // embedded-byte shapes so the gate covers every position,
10070 // not only mid-path.
10071 let d = dep_with_fonte(DepSource::Path {
10072 caminho: "*/caixa-teia".into(),
10073 });
10074 let err = d.validate().unwrap_err();
10075 assert!(
10076 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10077 "got {err:?}",
10078 );
10079 }
10080
10081 #[test]
10082 fn validate_rejects_path_fonte_with_caminho_carrying_double_star_recursive_glob() {
10083 // The bash/zsh `globstar` recursive-glob shape
10084 // (`"../caixa-teia/**/foo"` — the canonical "I copied a
10085 // `find ../caixa-teia/**/foo` recursive expansion" idiom).
10086 // The arm fires on the first `*` encountered; pinned so a
10087 // future arm that tries to distinguish single `*` from
10088 // double `**` doesn't break the broader contract.
10089 let d = dep_with_fonte(DepSource::Path {
10090 caminho: "../caixa-teia/**/foo".into(),
10091 });
10092 let err = d.validate().unwrap_err();
10093 assert!(
10094 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10095 "got {err:?}",
10096 );
10097 }
10098
10099 #[test]
10100 fn validate_rejects_path_fonte_with_caminho_carrying_dotted_extension_glob() {
10101 // The canonical extension-glob shape (`"../caixa-teia/*.lisp"`
10102 // — the "I selected `*.lisp` to mean every Lisp source file
10103 // in the dep root" footgun the prior arms structurally
10104 // cannot catch since `.` is a POSIX-valid path-component
10105 // byte). Pinned so the gate's contract covers the most
10106 // idiomatic glob-paste shape every author meets first.
10107 let d = dep_with_fonte(DepSource::Path {
10108 caminho: "../caixa-teia/*.lisp".into(),
10109 });
10110 let err = d.validate().unwrap_err();
10111 assert!(
10112 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10113 "got {err:?}",
10114 );
10115 }
10116
10117 #[test]
10118 fn validate_accepts_path_fonte_with_caminho_carrying_no_glob() {
10119 // The positive-control pin: the gate targets only `*` /
10120 // `?`, never adjacent printable ASCII or POSIX-valid bytes.
10121 // The canonical relative POSIX path (`"../caixa-teia"`) and
10122 // a nested deeply-pathed variant with adjacent printable
10123 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
10124 // to validate cleanly so the gate doesn't widen to a "no
10125 // printable punctuation anywhere" sweep that would defeat
10126 // the entire path-fonte author surface.
10127 let d = dep_with_fonte(DepSource::Path {
10128 caminho: "../caixa-teia/sub-dir.v2".into(),
10129 });
10130 d.validate().unwrap();
10131 }
10132
10133 #[test]
10134 fn fonte_caminho_shell_command_substitution_fires_before_shell_glob() {
10135 // Cascade pin on the immediate-predecessor arm: a value
10136 // carrying both a backtick and `*` (``"../`whoami`/*"`` —
10137 // the canonical "I pasted a `cd <backtick>whoami<backtick>/*`
10138 // command-substitution + glob chain") routes through
10139 // `FonteCaminhoShellCommandSubstitution` not
10140 // `FonteCaminhoShellGlob`. The CWE-78 shell-command-
10141 // injection vector is the load-bearing root-cause edit on
10142 // every probe-as-both value — same cascade discipline every
10143 // prior `:caminho` arm establishes.
10144 let d = dep_with_fonte(DepSource::Path {
10145 caminho: "../`whoami`/*".into(),
10146 });
10147 let err = d.validate().unwrap_err();
10148 assert!(
10149 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10150 "got {err:?}",
10151 );
10152 }
10153
10154 #[test]
10155 fn fonte_caminho_shell_background_fires_before_shell_glob() {
10156 // Cascade pin on the upstream shell-background arm: a value
10157 // carrying both `&` and `*` (`"../caixa-teia & ls /*"` — the
10158 // canonical "I pasted a `cmd & ls /*` background + glob
10159 // chain" footgun) routes through `FonteCaminhoShellBackground`
10160 // not `FonteCaminhoShellGlob`. The background-launch tail is
10161 // the load-bearing root-cause edit on every probe-as-both
10162 // value.
10163 let d = dep_with_fonte(DepSource::Path {
10164 caminho: "../caixa-teia & ls /*".into(),
10165 });
10166 let err = d.validate().unwrap_err();
10167 assert!(
10168 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10169 "got {err:?}",
10170 );
10171 }
10172
10173 #[test]
10174 fn fonte_caminho_shell_semicolon_fires_before_shell_glob() {
10175 // Cascade pin on the upstream shell-semicolon arm: a value
10176 // carrying both `;` and `*` (`"../caixa-teia; rm *"` — the
10177 // canonical sequential-cleanup + glob paste idiom) routes
10178 // through `FonteCaminhoShellSemicolon` not
10179 // `FonteCaminhoShellGlob`. The sequential-command-separator
10180 // paste is the load-bearing root-cause edit on every
10181 // probe-as-both value.
10182 let d = dep_with_fonte(DepSource::Path {
10183 caminho: "../caixa-teia; rm *".into(),
10184 });
10185 let err = d.validate().unwrap_err();
10186 assert!(
10187 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10188 "got {err:?}",
10189 );
10190 }
10191
10192 #[test]
10193 fn fonte_caminho_shell_pipe_fires_before_shell_glob() {
10194 // Cascade pin on the upstream shell-pipe arm: a value
10195 // carrying both `|` and `*` (`"../caixa-teia | ls *"` — the
10196 // canonical pipeline-to-glob paste idiom) routes through
10197 // `FonteCaminhoShellPipe` not `FonteCaminhoShellGlob`. The
10198 // pipeline-tail paste is the load-bearing root-cause edit
10199 // on every probe-as-both value.
10200 let d = dep_with_fonte(DepSource::Path {
10201 caminho: "../caixa-teia | ls *".into(),
10202 });
10203 let err = d.validate().unwrap_err();
10204 assert!(
10205 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10206 "got {err:?}",
10207 );
10208 }
10209
10210 #[test]
10211 fn fonte_caminho_shell_redirection_fires_before_shell_glob() {
10212 // Cascade pin on the upstream shell-redirection arm: a value
10213 // carrying both `>` and `*` (`"../caixa-teia>log *"` — the
10214 // canonical "I pasted a `cmd > log *` redirect-plus-glob
10215 // chain" footgun) routes through
10216 // `FonteCaminhoShellRedirection` not `FonteCaminhoShellGlob`.
10217 // The input/output redirection metachar carries the more
10218 // self-locating `byte` payload (it names which of `<` or `>`
10219 // triggered), so the prior arm wins on every probe-as-both
10220 // value.
10221 let d = dep_with_fonte(DepSource::Path {
10222 caminho: "../caixa-teia>log *".into(),
10223 });
10224 let err = d.validate().unwrap_err();
10225 assert!(
10226 matches!(
10227 err,
10228 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10229 ),
10230 "got {err:?}",
10231 );
10232 }
10233
10234 #[test]
10235 fn fonte_caminho_backslash_fires_before_shell_glob() {
10236 // Cascade pin on the upstream backslash arm: a value
10237 // carrying both `\` and `*` (`"..\caixa-teia\*"` — the
10238 // canonical "I pasted a Windows-shell `cd ..\path\*` glob
10239 // expression" footgun) routes through
10240 // `FonteCaminhoBackslash` not `FonteCaminhoShellGlob`. The
10241 // cross-host-OS-separator divergence is the load-bearing
10242 // axis on every probe-as-both value (an author who removes
10243 // the `\` is the root-cause edit; the `*` falls away in the
10244 // same edit since it's downstream of the Windows-shell
10245 // convention).
10246 let d = dep_with_fonte(DepSource::Path {
10247 caminho: "..\\caixa-teia\\*".into(),
10248 });
10249 let err = d.validate().unwrap_err();
10250 assert!(
10251 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10252 "got {err:?}",
10253 );
10254 }
10255
10256 #[test]
10257 fn fonte_caminho_control_char_fires_before_shell_glob() {
10258 // Cascade pin on the embedded-control-byte arm: a value
10259 // carrying both a control byte and `*` (`"../foo\n*"` — the
10260 // canonical paste-from-multiline-doc footgun where a
10261 // newline landed mid-caminho between two paste fragments)
10262 // routes through `FonteCaminhoControlChar` not
10263 // `FonteCaminhoShellGlob`. The POSIX-syscall-rejected-byte /
10264 // NUL-`CString::new`-fail diagnostic is the load-bearing
10265 // axis on every value that probes positive for both —
10266 // mirrors the cascade discipline on every prior arm.
10267 let d = dep_with_fonte(DepSource::Path {
10268 caminho: "../foo\n*".into(),
10269 });
10270 let err = d.validate().unwrap_err();
10271 assert!(
10272 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10273 "got {err:?}",
10274 );
10275 }
10276
10277 #[test]
10278 fn fonte_caminho_absolute_fires_before_shell_glob() {
10279 // Cascade pin on the load-bearing leading-byte arm: a
10280 // leading `/` value with embedded `*` (`"/etc/*"`) routes
10281 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellGlob`
10282 // — the host-layout-leak diagnostic is the load-bearing
10283 // axis, the glob byte is the secondary observation. Same
10284 // precedence logic as every prior leading-byte arm.
10285 let d = dep_with_fonte(DepSource::Path {
10286 caminho: "/etc/*".into(),
10287 });
10288 let err = d.validate().unwrap_err();
10289 assert!(
10290 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10291 "got {err:?}",
10292 );
10293 }
10294
10295 #[test]
10296 fn fonte_caminho_shell_glob_fires_before_trailing_slash() {
10297 // Cascade pin on the immediate-successor arm: a value
10298 // carrying both `*` and a trailing `/` (`"../foo*/"` — the
10299 // canonical "I tab-completed a path that already had a
10300 // glob-expansion tail" footgun) routes through
10301 // `FonteCaminhoShellGlob` not `FonteCaminhoTrailingSlash`.
10302 // The embedded shell-metachar is the more semantic-locating
10303 // axis (an author who removes the `*` typically also drops
10304 // the trailing separator since both are paste-from-shell
10305 // artifacts).
10306 let d = dep_with_fonte(DepSource::Path {
10307 caminho: "../foo*/".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 fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte() {
10318 // Diagnostic-shape pin (peer with
10319 // `fonte_caminho_shell_redirection_diagnostic_*` on the
10320 // closest two-byte peer arm): the error's Display surfaces
10321 // the offending `:nome`, the offending `:caminho` verbatim,
10322 // the offending byte's hex / character form, and names the
10323 // shell-glob / pathname-expansion footgun explicitly so a
10324 // `feira lint` run can render the diagnostic without
10325 // re-parsing.
10326 let d = dep_with_fonte(DepSource::Path {
10327 caminho: "../caixa-teia/*.lisp".into(),
10328 });
10329 let rendered = d.validate().unwrap_err().to_string();
10330 assert!(
10331 rendered.contains("caixa-teia"),
10332 "diagnostic must name the offending dep: {rendered}",
10333 );
10334 assert!(
10335 rendered.contains("../caixa-teia/*.lisp"),
10336 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10337 );
10338 assert!(
10339 rendered.contains("0x2a"),
10340 "diagnostic must surface the offending byte hex: {rendered:?}",
10341 );
10342 assert!(
10343 rendered.contains("glob"),
10344 "diagnostic must name the shell-glob footgun: {rendered:?}",
10345 );
10346 assert!(
10347 rendered.contains("pathname-expansion"),
10348 "diagnostic must reference the POSIX pathname-expansion vocabulary: {rendered:?}",
10349 );
10350 }
10351
10352 #[test]
10353 fn validate_rejects_path_fonte_with_caminho_carrying_modern_command_substitution() {
10354 // The fail-before-pass-after pin for the canonical modern-Bourne
10355 // command-substitution paste footgun: an author copies a
10356 // `cd ../caixa-teia/$(date)/build` shell-history one-liner whose
10357 // `$(<cmd>)` expansion would land the current date as a
10358 // subdirectory name and silently passed every prior arm
10359 // (`Path::is_absolute` false on `..`, no control bytes, no `\`,
10360 // no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no `*` /
10361 // `?`, doesn't end in `/`; the leading-`$` f4efe9c
10362 // `FonteCaminhoVarExpansion` arm doesn't fire because the `$`
10363 // sits mid-path). The lacre embedded the value verbatim, the
10364 // resolver folded it through `Path::join` looking for a literal
10365 // `./../caixa-teia/$(date)/build` subdirectory, and the failure
10366 // surfaced at resolve time with a non-self-locating `No such
10367 // file or directory` error. The new arm moves the rejection to
10368 // validate time and names the offending dep + caminho + byte
10369 // verbatim. The arm fires on the first `(` encountered (the
10370 // opening byte of `$(date)`).
10371 let d = dep_with_fonte(DepSource::Path {
10372 caminho: "../caixa-teia/$(date)/build".into(),
10373 });
10374 let err = d.validate().unwrap_err();
10375 let DepError::FonteCaminhoShellSubshellGrouping {
10376 nome,
10377 caminho,
10378 byte,
10379 } = err
10380 else {
10381 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10382 };
10383 assert_eq!(nome, "caixa-teia");
10384 assert_eq!(caminho, "../caixa-teia/$(date)/build");
10385 assert_eq!(byte, b'(');
10386 }
10387
10388 #[test]
10389 fn validate_rejects_path_fonte_with_caminho_carrying_close_paren() {
10390 // The symmetric close-paren paste shape (`"../caixa-teia)"` —
10391 // the degenerate "I selected an unbalanced closing paren out of
10392 // a shell-history block" idiom that probes for the cascade's
10393 // last-byte handling on a value carrying only the closing byte).
10394 // Pinned separately from the open-paren shape so the gate's
10395 // contract is "any `(` or `)` anywhere", not single-byte
10396 // coverage. Mirrors the peer `validate_rejects_path_fonte_with_\
10397 // caminho_carrying_question_glob` shape on the immediate-
10398 // predecessor `FonteCaminhoShellGlob` arm.
10399 let d = dep_with_fonte(DepSource::Path {
10400 caminho: "../caixa-teia)".into(),
10401 });
10402 let err = d.validate().unwrap_err();
10403 let DepError::FonteCaminhoShellSubshellGrouping { byte, .. } = err else {
10404 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10405 };
10406 assert_eq!(byte, b')');
10407 }
10408
10409 #[test]
10410 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_paren() {
10411 // Leading-position `(` shape (`"(cd foo)/caixa-teia"` — the
10412 // canonical "I selected a `(cd foo)` subshell-grouping prefix
10413 // out of a `(cd foo) && cmd` shell-history one-liner" idiom).
10414 // Pinned separately from the embedded-byte shape so the gate
10415 // covers every position, not only mid-path.
10416 let d = dep_with_fonte(DepSource::Path {
10417 caminho: "(cd foo)/caixa-teia".into(),
10418 });
10419 let err = d.validate().unwrap_err();
10420 assert!(
10421 matches!(
10422 err,
10423 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10424 ),
10425 "got {err:?}",
10426 );
10427 }
10428
10429 #[test]
10430 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_subshell_grouping_pair() {
10431 // The canonical balanced-pair shape (`"../(pwd)/caixa-teia"`
10432 // — the canonical "I copied a `(pwd)` working-directory-probe
10433 // subshell-grouping idiom every shell-history block carries"
10434 // footgun). The value carries no other cascade-preceding
10435 // shell metachar (`&` / `;` / `|` / `<` / `>` / backtick /
10436 // `*` / `?`) so the arm fires on the first `(` encountered;
10437 // pinned so a future arm that tries to distinguish the
10438 // opening from the closing byte doesn't break the broader
10439 // contract. Mirrors the peer
10440 // `validate_rejects_path_fonte_with_caminho_carrying_balanced_\
10441 // backtick_pair` shape on the upstream `FonteCaminhoShell\
10442 // CommandSubstitution` arm.
10443 let d = dep_with_fonte(DepSource::Path {
10444 caminho: "../(pwd)/caixa-teia".into(),
10445 });
10446 let err = d.validate().unwrap_err();
10447 assert!(
10448 matches!(
10449 err,
10450 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10451 ),
10452 "got {err:?}",
10453 );
10454 }
10455
10456 #[test]
10457 fn validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping() {
10458 // The positive-control pin: the gate targets only `(` / `)`,
10459 // never adjacent printable ASCII or POSIX-valid bytes. The
10460 // canonical relative POSIX path (`"../caixa-teia"`) and a
10461 // nested deeply-pathed variant with adjacent printable
10462 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10463 // validate cleanly so the gate doesn't widen to a "no printable
10464 // punctuation anywhere" sweep that would defeat the entire
10465 // path-fonte author surface.
10466 let d = dep_with_fonte(DepSource::Path {
10467 caminho: "../caixa-teia/sub-dir.v2".into(),
10468 });
10469 d.validate().unwrap();
10470 }
10471
10472 #[test]
10473 fn fonte_caminho_shell_glob_fires_before_shell_subshell_grouping() {
10474 // Cascade pin on the immediate-predecessor arm: a value
10475 // carrying both `*` and `(` (`"../caixa-teia/*(date)"` — the
10476 // canonical "I pasted a glob expansion followed by a
10477 // subshell-grouping tail" footgun) routes through
10478 // `FonteCaminhoShellGlob` not
10479 // `FonteCaminhoShellSubshellGrouping`. The pathname-expansion
10480 // shape is the more common shell-history paste idiom on every
10481 // probe-as-both value — same cascade discipline every prior
10482 // `:caminho` arm establishes.
10483 let d = dep_with_fonte(DepSource::Path {
10484 caminho: "../caixa-teia/*(date)".into(),
10485 });
10486 let err = d.validate().unwrap_err();
10487 assert!(
10488 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10489 "got {err:?}",
10490 );
10491 }
10492
10493 #[test]
10494 fn fonte_caminho_shell_command_substitution_fires_before_shell_subshell_grouping() {
10495 // Cascade pin on the upstream shell-command-substitution arm: a
10496 // value carrying both a backtick and `(` (``"../`whoami`/$(date)"``
10497 // — the canonical "I pasted a legacy-backtick + modern-paren
10498 // command-substitution chain" footgun) routes through
10499 // `FonteCaminhoShellCommandSubstitution` not
10500 // `FonteCaminhoShellSubshellGrouping`. The CWE-78 shell-
10501 // command-injection vector is the load-bearing root-cause edit
10502 // on every probe-as-both value.
10503 let d = dep_with_fonte(DepSource::Path {
10504 caminho: "../`whoami`/$(date)".into(),
10505 });
10506 let err = d.validate().unwrap_err();
10507 assert!(
10508 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10509 "got {err:?}",
10510 );
10511 }
10512
10513 #[test]
10514 fn fonte_caminho_shell_background_fires_before_shell_subshell_grouping() {
10515 // Cascade pin on the upstream shell-background arm: a value
10516 // carrying both `&` and `(` (`"../caixa-teia & (cd foo)"` —
10517 // the canonical "I pasted a `cmd & (cd foo)` background-launch
10518 // + subshell-grouping chain" footgun) routes through
10519 // `FonteCaminhoShellBackground` not
10520 // `FonteCaminhoShellSubshellGrouping`. The background-launch
10521 // tail is the load-bearing root-cause edit on every probe-as-
10522 // both value.
10523 let d = dep_with_fonte(DepSource::Path {
10524 caminho: "../caixa-teia & (cd foo)".into(),
10525 });
10526 let err = d.validate().unwrap_err();
10527 assert!(
10528 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10529 "got {err:?}",
10530 );
10531 }
10532
10533 #[test]
10534 fn fonte_caminho_shell_semicolon_fires_before_shell_subshell_grouping() {
10535 // Cascade pin on the upstream shell-semicolon arm: a value
10536 // carrying both `;` and `(` (`"../caixa-teia; (cd foo)"` —
10537 // the canonical sequential-cleanup + subshell-grouping paste
10538 // idiom) routes through `FonteCaminhoShellSemicolon` not
10539 // `FonteCaminhoShellSubshellGrouping`. The sequential-command-
10540 // separator paste is the load-bearing root-cause edit on
10541 // every probe-as-both value.
10542 let d = dep_with_fonte(DepSource::Path {
10543 caminho: "../caixa-teia; (cd foo)".into(),
10544 });
10545 let err = d.validate().unwrap_err();
10546 assert!(
10547 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10548 "got {err:?}",
10549 );
10550 }
10551
10552 #[test]
10553 fn fonte_caminho_shell_pipe_fires_before_shell_subshell_grouping() {
10554 // Cascade pin on the upstream shell-pipe arm: a value carrying
10555 // both `|` and `(` (`"../caixa-teia | (tee log)"` — the
10556 // canonical pipeline-to-subshell-grouping paste idiom) routes
10557 // through `FonteCaminhoShellPipe` not
10558 // `FonteCaminhoShellSubshellGrouping`. The pipeline-tail paste
10559 // is the load-bearing root-cause edit on every probe-as-both
10560 // value.
10561 let d = dep_with_fonte(DepSource::Path {
10562 caminho: "../caixa-teia | (tee log)".into(),
10563 });
10564 let err = d.validate().unwrap_err();
10565 assert!(
10566 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10567 "got {err:?}",
10568 );
10569 }
10570
10571 #[test]
10572 fn fonte_caminho_shell_redirection_fires_before_shell_subshell_grouping() {
10573 // Cascade pin on the upstream shell-redirection arm: a value
10574 // carrying both `>` and `(` (`"../caixa-teia>log (cd foo)"` —
10575 // the canonical "I pasted a `cmd > log (cd foo)` redirect-
10576 // plus-subshell-grouping chain" footgun) routes through
10577 // `FonteCaminhoShellRedirection` not
10578 // `FonteCaminhoShellSubshellGrouping`. The input/output
10579 // redirection metachar carries the more self-locating `byte`
10580 // payload (it names which of `<` or `>` triggered), so the
10581 // prior arm wins on every probe-as-both value.
10582 let d = dep_with_fonte(DepSource::Path {
10583 caminho: "../caixa-teia>log (cd foo)".into(),
10584 });
10585 let err = d.validate().unwrap_err();
10586 assert!(
10587 matches!(
10588 err,
10589 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10590 ),
10591 "got {err:?}",
10592 );
10593 }
10594
10595 #[test]
10596 fn fonte_caminho_backslash_fires_before_shell_subshell_grouping() {
10597 // Cascade pin on the upstream backslash arm: a value carrying
10598 // both `\` and `(` (`"..\caixa-teia\(cd foo)"` — the canonical
10599 // "I pasted a Windows-shell `cd ..\path\(cmd)` chain") routes
10600 // through `FonteCaminhoBackslash` not
10601 // `FonteCaminhoShellSubshellGrouping`. The cross-host-OS-
10602 // separator divergence is the load-bearing axis on every
10603 // probe-as-both value (an author who removes the `\` is the
10604 // root-cause edit; the `(` falls away in the same edit since
10605 // it's downstream of the Windows-shell convention).
10606 let d = dep_with_fonte(DepSource::Path {
10607 caminho: "..\\caixa-teia\\(cd foo)".into(),
10608 });
10609 let err = d.validate().unwrap_err();
10610 assert!(
10611 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10612 "got {err:?}",
10613 );
10614 }
10615
10616 #[test]
10617 fn fonte_caminho_control_char_fires_before_shell_subshell_grouping() {
10618 // Cascade pin on the embedded-control-byte arm: a value
10619 // carrying both a control byte and `(` (`"../foo\n(cd bar)"` —
10620 // the canonical paste-from-multiline-doc footgun where a
10621 // newline landed mid-caminho between two paste fragments)
10622 // routes through `FonteCaminhoControlChar` not
10623 // `FonteCaminhoShellSubshellGrouping`. The POSIX-syscall-
10624 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10625 // load-bearing axis on every value that probes positive for
10626 // both — mirrors the cascade discipline on every prior arm.
10627 let d = dep_with_fonte(DepSource::Path {
10628 caminho: "../foo\n(cd bar)".into(),
10629 });
10630 let err = d.validate().unwrap_err();
10631 assert!(
10632 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10633 "got {err:?}",
10634 );
10635 }
10636
10637 #[test]
10638 fn fonte_caminho_absolute_fires_before_shell_subshell_grouping() {
10639 // Cascade pin on the load-bearing leading-byte arm: a leading
10640 // `/` value with embedded `(` (`"/etc/(cd foo)"`) routes
10641 // through `FonteCaminhoAbsolute` not
10642 // `FonteCaminhoShellSubshellGrouping` — the host-layout-leak
10643 // diagnostic is the load-bearing axis, the subshell-grouping
10644 // byte is the secondary observation. Same precedence logic as
10645 // every prior leading-byte arm.
10646 let d = dep_with_fonte(DepSource::Path {
10647 caminho: "/etc/(cd foo)".into(),
10648 });
10649 let err = d.validate().unwrap_err();
10650 assert!(
10651 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10652 "got {err:?}",
10653 );
10654 }
10655
10656 #[test]
10657 fn fonte_caminho_var_expansion_fires_before_shell_subshell_grouping() {
10658 // Cascade pin on the upstream leading-`$` var-expansion arm: a
10659 // value carrying both a leading `$` and a `(` (`"$(date)/\
10660 // caixa-teia"` — the canonical "I pasted a `$(date)` modern-
10661 // command-substitution at the head of a sibling-workspace
10662 // path" footgun) routes through `FonteCaminhoVarExpansion` not
10663 // `FonteCaminhoShellSubshellGrouping`. The leading-byte
10664 // shell-variable-expansion is the more self-locating diagnostic
10665 // on values that probe as both — same load-bearing-leading-
10666 // byte cascade discipline every prior `:caminho` arm
10667 // establishes. Closing both halves of `$(<cmd>)` structurally
10668 // (leading `$` here, trailing `)` on the new arm) excludes the
10669 // entire modern Bourne command-substitution surface from the
10670 // typed `:caminho` accepted set; the cascade preserves the
10671 // narrower leading-byte diagnostic on values that probe both
10672 // halves at the canonical leading position.
10673 let d = dep_with_fonte(DepSource::Path {
10674 caminho: "$(date)/caixa-teia".into(),
10675 });
10676 let err = d.validate().unwrap_err();
10677 assert!(
10678 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
10679 "got {err:?}",
10680 );
10681 }
10682
10683 #[test]
10684 fn fonte_caminho_shell_subshell_grouping_fires_before_trailing_slash() {
10685 // Cascade pin on the immediate-successor arm: a value carrying
10686 // both `(` and a trailing `/` (`"../(cd foo)/"` — the canonical
10687 // "I tab-completed a path that already had a subshell-grouping
10688 // expansion tail" footgun) routes through
10689 // `FonteCaminhoShellSubshellGrouping` not
10690 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
10691 // the more semantic-locating axis (an author who removes the
10692 // `(` typically also drops the trailing separator since both
10693 // are paste-from-shell artifacts).
10694 let d = dep_with_fonte(DepSource::Path {
10695 caminho: "../(cd foo)/".into(),
10696 });
10697 let err = d.validate().unwrap_err();
10698 assert!(
10699 matches!(
10700 err,
10701 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10702 ),
10703 "got {err:?}",
10704 );
10705 }
10706
10707 #[test]
10708 fn fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
10709 // Diagnostic-shape pin (peer with
10710 // `fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte`
10711 // on the closest two-byte peer arm): the error's Display
10712 // surfaces the offending `:nome`, the offending `:caminho`
10713 // verbatim, the offending byte's hex / character form, and
10714 // names the shell-subshell-grouping footgun explicitly so a
10715 // `feira lint` run can render the diagnostic without re-
10716 // parsing.
10717 let d = dep_with_fonte(DepSource::Path {
10718 caminho: "../caixa-teia/$(date)/build".into(),
10719 });
10720 let rendered = d.validate().unwrap_err().to_string();
10721 assert!(
10722 rendered.contains("caixa-teia"),
10723 "diagnostic must name the offending dep: {rendered}",
10724 );
10725 assert!(
10726 rendered.contains("../caixa-teia/$(date)/build"),
10727 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10728 );
10729 assert!(
10730 rendered.contains("0x28"),
10731 "diagnostic must surface the offending byte hex: {rendered:?}",
10732 );
10733 assert!(
10734 rendered.contains("subshell-grouping"),
10735 "diagnostic must name the shell-subshell-grouping footgun: {rendered:?}",
10736 );
10737 assert!(
10738 rendered.contains("command-substitution"),
10739 "diagnostic must reference the `$(<cmd>)` command-substitution vocabulary: \
10740 {rendered:?}",
10741 );
10742 }
10743
10744 // ── shell-brace-expansion / URI-Template-placeholder arm ───────────
10745 //
10746 // Peer with the prior `FonteCaminhoShellSubshellGrouping` (`(` /
10747 // `)`) byte-pair arm: the same per-byte cascade with the same
10748 // self-locating `byte: u8` diagnostic on the orthogonal `{` /
10749 // `}` brace-expansion / URI-Template placeholder axis. The peer
10750 // [`crate::render::is_git_repo_url`] (42d8f9d) closes the same
10751 // byte pair on the sibling `:fonte :repo` axis under the same
10752 // banner.
10753
10754 #[test]
10755 fn validate_rejects_path_fonte_with_caminho_carrying_brace_expansion_fan_across_siblings() {
10756 // The fail-before-pass-after pin for the canonical paste-from-
10757 // shell-history brace-expansion footgun: an author copies a
10758 // `cd ../{caixa-teia,caixa-helm}/build` shell-history one-
10759 // liner whose `{a,b}` brace expansion fans across two siblings
10760 // and silently passed every prior arm (`Path::is_absolute`
10761 // false on `..`, no control bytes, no `\`, no `<` / `>`, no
10762 // `|`, no `;`, no `&`, no backtick, no `*` / `?`, no `(` /
10763 // `)`, doesn't end in `/`; the leading-`$` f4efe9c
10764 // `FonteCaminhoVarExpansion` arm doesn't fire because the
10765 // value starts with `..` not `$`). The lacre embedded the
10766 // value verbatim, the resolver folded it through `Path::join`
10767 // looking for a literal `./../{caixa-teia,caixa-helm}/build`
10768 // subdirectory, and the failure surfaced at resolve time with
10769 // a non-self-locating `No such file or directory` error. The
10770 // new arm moves the rejection to validate time and names the
10771 // offending dep + caminho + byte verbatim. The arm fires on
10772 // the first `{` encountered.
10773 let d = dep_with_fonte(DepSource::Path {
10774 caminho: "../{caixa-teia,caixa-helm}/build".into(),
10775 });
10776 let err = d.validate().unwrap_err();
10777 let DepError::FonteCaminhoShellBraceExpansion {
10778 nome,
10779 caminho,
10780 byte,
10781 } = err
10782 else {
10783 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10784 };
10785 assert_eq!(nome, "caixa-teia");
10786 assert_eq!(caminho, "../{caixa-teia,caixa-helm}/build");
10787 assert_eq!(byte, b'{');
10788 }
10789
10790 #[test]
10791 fn validate_rejects_path_fonte_with_caminho_carrying_close_brace() {
10792 // The symmetric close-brace paste shape (`"../caixa-teia}"` —
10793 // the degenerate "I selected an unbalanced closing brace out
10794 // of a shell-history block" idiom that probes for the
10795 // cascade's last-byte handling on a value carrying only the
10796 // closing byte). Pinned separately from the open-brace shape
10797 // so the gate's contract is "any `{` or `}` anywhere", not
10798 // single-byte coverage. Mirrors the peer
10799 // `validate_rejects_path_fonte_with_caminho_carrying_close_paren`
10800 // shape on the immediate-predecessor `FonteCaminhoShellSubshellGrouping`
10801 // arm.
10802 let d = dep_with_fonte(DepSource::Path {
10803 caminho: "../caixa-teia}".into(),
10804 });
10805 let err = d.validate().unwrap_err();
10806 let DepError::FonteCaminhoShellBraceExpansion { byte, .. } = err else {
10807 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10808 };
10809 assert_eq!(byte, b'}');
10810 }
10811
10812 #[test]
10813 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_brace() {
10814 // Leading-position `{` shape (`"{caixa-teia,caixa-helm}/build"`
10815 // — the canonical "I selected a `{a,b}` brace-expansion prefix
10816 // out of a shell-history one-liner" idiom). Pinned separately
10817 // from the embedded-byte shape so the gate covers every
10818 // position, not only mid-path.
10819 let d = dep_with_fonte(DepSource::Path {
10820 caminho: "{caixa-teia,caixa-helm}/build".into(),
10821 });
10822 let err = d.validate().unwrap_err();
10823 assert!(
10824 matches!(
10825 err,
10826 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10827 ),
10828 "got {err:?}",
10829 );
10830 }
10831
10832 #[test]
10833 fn validate_rejects_path_fonte_with_caminho_carrying_uri_template_placeholder() {
10834 // The canonical URI-Template / Mustache / Helm doubled-brace
10835 // placeholder shape (`"../{{org}}/caixa-teia"` — the canonical
10836 // "I copied a `https://github.com/{{org}}/caixa-teia` README
10837 // quick-start / OpenAPI spec / Helm chart `home:` template
10838 // and forgot to substitute the placeholder" footgun). The arm
10839 // fires on the first `{` encountered; pinned so the gate's
10840 // coverage extends from the bare-brace shell-history shape to
10841 // the doubled-brace URI-Template / templating-engine shape.
10842 // Mirrors the peer 42d8f9d `is_git_repo_url` arm on the
10843 // sibling `:fonte :repo` axis.
10844 let d = dep_with_fonte(DepSource::Path {
10845 caminho: "../{{org}}/caixa-teia".into(),
10846 });
10847 let err = d.validate().unwrap_err();
10848 assert!(
10849 matches!(
10850 err,
10851 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10852 ),
10853 "got {err:?}",
10854 );
10855 }
10856
10857 #[test]
10858 fn validate_rejects_path_fonte_with_caminho_carrying_brace_range_expansion() {
10859 // The canonical bash brace-range-expansion shape (`"../caixa-
10860 // v{1..10}"` — the `{1..10}` sequence expansion every bash /
10861 // zsh `for i in {1..10}; do …; done` idiom uses, the symmetric
10862 // sequence-range form to the `{a,b,c}` comma-separated form).
10863 // The arm fires on the first `{` encountered; pinned so the
10864 // gate's coverage extends from the comma-separated form to
10865 // the integer-range form.
10866 let d = dep_with_fonte(DepSource::Path {
10867 caminho: "../caixa-v{1..10}".into(),
10868 });
10869 let err = d.validate().unwrap_err();
10870 assert!(
10871 matches!(
10872 err,
10873 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10874 ),
10875 "got {err:?}",
10876 );
10877 }
10878
10879 #[test]
10880 fn validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion() {
10881 // The positive-control pin: the gate targets only `{` / `}`,
10882 // never adjacent printable ASCII or POSIX-valid bytes. The
10883 // canonical relative POSIX path (`"../caixa-teia"`) and a
10884 // nested deeply-pathed variant with adjacent printable
10885 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10886 // validate cleanly so the gate doesn't widen to a "no
10887 // printable punctuation anywhere" sweep that would defeat
10888 // the entire path-fonte author surface. Peer with
10889 // `validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping`
10890 // on the immediate-predecessor arm.
10891 let d = dep_with_fonte(DepSource::Path {
10892 caminho: "../caixa-teia/sub-dir.v2".into(),
10893 });
10894 d.validate().unwrap();
10895 }
10896
10897 #[test]
10898 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_brace_expansion() {
10899 // Cascade pin on the immediate-predecessor arm: a value
10900 // carrying both `(` and `{` (`"../(cd foo)/{a,b}"` — the
10901 // canonical "I pasted a subshell-grouping followed by a
10902 // brace-expansion tail" footgun) routes through
10903 // `FonteCaminhoShellSubshellGrouping` not
10904 // `FonteCaminhoShellBraceExpansion`. The subshell-grouping
10905 // shape is the more semantic-locating axis on every probe-
10906 // as-both value because it closes both halves of the modern
10907 // Bourne `$(<cmd>)` command-substitution surface — same
10908 // cascade discipline every prior `:caminho` arm establishes.
10909 let d = dep_with_fonte(DepSource::Path {
10910 caminho: "../(cd foo)/{a,b}".into(),
10911 });
10912 let err = d.validate().unwrap_err();
10913 assert!(
10914 matches!(
10915 err,
10916 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10917 ),
10918 "got {err:?}",
10919 );
10920 }
10921
10922 #[test]
10923 fn fonte_caminho_shell_glob_fires_before_shell_brace_expansion() {
10924 // Cascade pin on the upstream shell-glob arm: a value carrying
10925 // both `*` and `{` (`"../caixa-teia/*{a,b}"` — the canonical
10926 // "I pasted a glob expansion followed by a brace-expansion
10927 // tail" footgun) routes through `FonteCaminhoShellGlob` not
10928 // `FonteCaminhoShellBraceExpansion`. The pathname-expansion
10929 // shape is the load-bearing root-cause edit on every
10930 // probe-as-both value.
10931 let d = dep_with_fonte(DepSource::Path {
10932 caminho: "../caixa-teia/*{a,b}".into(),
10933 });
10934 let err = d.validate().unwrap_err();
10935 assert!(
10936 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10937 "got {err:?}",
10938 );
10939 }
10940
10941 #[test]
10942 fn fonte_caminho_shell_command_substitution_fires_before_shell_brace_expansion() {
10943 // Cascade pin on the upstream shell-command-substitution arm:
10944 // a value carrying both a backtick and `{` (``"../`whoami`/{a,b}"``
10945 // — the canonical "I pasted a legacy-backtick command-
10946 // substitution followed by a brace-expansion fan-out" footgun)
10947 // routes through `FonteCaminhoShellCommandSubstitution` not
10948 // `FonteCaminhoShellBraceExpansion`. The CWE-78 shell-
10949 // command-injection vector is the load-bearing root-cause
10950 // edit on every probe-as-both value.
10951 let d = dep_with_fonte(DepSource::Path {
10952 caminho: "../`whoami`/{a,b}".into(),
10953 });
10954 let err = d.validate().unwrap_err();
10955 assert!(
10956 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10957 "got {err:?}",
10958 );
10959 }
10960
10961 #[test]
10962 fn fonte_caminho_shell_background_fires_before_shell_brace_expansion() {
10963 // Cascade pin on the upstream shell-background arm: a value
10964 // carrying both `&` and `{` (`"../caixa-teia & {a,b}"` — the
10965 // canonical "I pasted a `cmd & {fork-fan}` background-launch
10966 // + brace-expansion chain" footgun) routes through
10967 // `FonteCaminhoShellBackground` not
10968 // `FonteCaminhoShellBraceExpansion`. The background-launch
10969 // tail is the load-bearing root-cause edit on every
10970 // probe-as-both value.
10971 let d = dep_with_fonte(DepSource::Path {
10972 caminho: "../caixa-teia & {a,b}".into(),
10973 });
10974 let err = d.validate().unwrap_err();
10975 assert!(
10976 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10977 "got {err:?}",
10978 );
10979 }
10980
10981 #[test]
10982 fn fonte_caminho_shell_semicolon_fires_before_shell_brace_expansion() {
10983 // Cascade pin on the upstream shell-semicolon arm: a value
10984 // carrying both `;` and `{` (`"../caixa-teia; {a,b}"` — the
10985 // canonical sequential-cleanup + brace-expansion paste
10986 // idiom) routes through `FonteCaminhoShellSemicolon` not
10987 // `FonteCaminhoShellBraceExpansion`. The sequential-command-
10988 // separator paste is the load-bearing root-cause edit on
10989 // every probe-as-both value.
10990 let d = dep_with_fonte(DepSource::Path {
10991 caminho: "../caixa-teia; {a,b}".into(),
10992 });
10993 let err = d.validate().unwrap_err();
10994 assert!(
10995 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10996 "got {err:?}",
10997 );
10998 }
10999
11000 #[test]
11001 fn fonte_caminho_shell_pipe_fires_before_shell_brace_expansion() {
11002 // Cascade pin on the upstream shell-pipe arm: a value
11003 // carrying both `|` and `{` (`"../caixa-teia | {tee,cat}"`
11004 // — the canonical pipeline-to-brace-expansion paste idiom)
11005 // routes through `FonteCaminhoShellPipe` not
11006 // `FonteCaminhoShellBraceExpansion`. The pipeline-tail paste
11007 // is the load-bearing root-cause edit on every probe-as-
11008 // both value.
11009 let d = dep_with_fonte(DepSource::Path {
11010 caminho: "../caixa-teia | {tee,cat}".into(),
11011 });
11012 let err = d.validate().unwrap_err();
11013 assert!(
11014 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11015 "got {err:?}",
11016 );
11017 }
11018
11019 #[test]
11020 fn fonte_caminho_shell_redirection_fires_before_shell_brace_expansion() {
11021 // Cascade pin on the upstream shell-redirection arm: a value
11022 // carrying both `>` and `{` (`"../caixa-teia>log {a,b}"` —
11023 // the canonical "I pasted a `cmd > log {a,b}` redirect-
11024 // plus-brace-expansion chain" footgun) routes through
11025 // `FonteCaminhoShellRedirection` not
11026 // `FonteCaminhoShellBraceExpansion`. The input/output
11027 // redirection metachar carries the more self-locating
11028 // `byte` payload, so the prior arm wins on every probe-
11029 // as-both value.
11030 let d = dep_with_fonte(DepSource::Path {
11031 caminho: "../caixa-teia>log {a,b}".into(),
11032 });
11033 let err = d.validate().unwrap_err();
11034 assert!(
11035 matches!(
11036 err,
11037 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11038 ),
11039 "got {err:?}",
11040 );
11041 }
11042
11043 #[test]
11044 fn fonte_caminho_backslash_fires_before_shell_brace_expansion() {
11045 // Cascade pin on the upstream backslash arm: a value
11046 // carrying both `\` and `{` (`"..\caixa-teia\{a,b}"` — the
11047 // canonical "I pasted a Windows-shell `cd ..\path\{a,b}`
11048 // chain") routes through `FonteCaminhoBackslash` not
11049 // `FonteCaminhoShellBraceExpansion`. The cross-host-OS-
11050 // separator divergence is the load-bearing axis on every
11051 // probe-as-both value.
11052 let d = dep_with_fonte(DepSource::Path {
11053 caminho: "..\\caixa-teia\\{a,b}".into(),
11054 });
11055 let err = d.validate().unwrap_err();
11056 assert!(
11057 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11058 "got {err:?}",
11059 );
11060 }
11061
11062 #[test]
11063 fn fonte_caminho_control_char_fires_before_shell_brace_expansion() {
11064 // Cascade pin on the embedded-control-byte arm: a value
11065 // carrying both a control byte and `{` (`"../foo\n{a,b}"` —
11066 // the canonical paste-from-multiline-doc footgun where a
11067 // newline landed mid-caminho between two paste fragments)
11068 // routes through `FonteCaminhoControlChar` not
11069 // `FonteCaminhoShellBraceExpansion`. The POSIX-syscall-
11070 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
11071 // load-bearing axis on every value that probes positive for
11072 // both — mirrors the cascade discipline on every prior arm.
11073 let d = dep_with_fonte(DepSource::Path {
11074 caminho: "../foo\n{a,b}".into(),
11075 });
11076 let err = d.validate().unwrap_err();
11077 assert!(
11078 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11079 "got {err:?}",
11080 );
11081 }
11082
11083 #[test]
11084 fn fonte_caminho_absolute_fires_before_shell_brace_expansion() {
11085 // Cascade pin on the load-bearing leading-byte arm: a
11086 // leading `/` value with embedded `{` (`"/etc/{a,b}"`)
11087 // routes through `FonteCaminhoAbsolute` not
11088 // `FonteCaminhoShellBraceExpansion` — the host-layout-leak
11089 // diagnostic is the load-bearing axis, the brace-expansion
11090 // byte is the secondary observation. Same precedence logic
11091 // as every prior leading-byte arm.
11092 let d = dep_with_fonte(DepSource::Path {
11093 caminho: "/etc/{a,b}".into(),
11094 });
11095 let err = d.validate().unwrap_err();
11096 assert!(
11097 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11098 "got {err:?}",
11099 );
11100 }
11101
11102 #[test]
11103 fn fonte_caminho_var_expansion_fires_before_shell_brace_expansion() {
11104 // Cascade pin on the upstream leading-`$` var-expansion
11105 // arm: a value carrying both a leading `$` and a `{`
11106 // (`"${ORG}/caixa-teia"` — the canonical "I pasted a
11107 // `${ORG}` shell-variable + curly-brace expansion at the
11108 // head of a sibling-workspace path" footgun) routes through
11109 // `FonteCaminhoVarExpansion` not
11110 // `FonteCaminhoShellBraceExpansion`. The leading-byte
11111 // shell-variable-expansion is the more self-locating
11112 // diagnostic on values that probe as both — same
11113 // load-bearing-leading-byte cascade discipline every prior
11114 // `:caminho` arm establishes.
11115 let d = dep_with_fonte(DepSource::Path {
11116 caminho: "${ORG}/caixa-teia".into(),
11117 });
11118 let err = d.validate().unwrap_err();
11119 assert!(
11120 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11121 "got {err:?}",
11122 );
11123 }
11124
11125 #[test]
11126 fn fonte_caminho_shell_brace_expansion_fires_before_trailing_slash() {
11127 // Cascade pin on the immediate-successor arm: a value
11128 // carrying both `{` and a trailing `/`
11129 // (`"../{caixa-teia,caixa-helm}/"` — the canonical "I
11130 // tab-completed a path that already had a brace-expansion
11131 // expansion tail" footgun) routes through
11132 // `FonteCaminhoShellBraceExpansion` not
11133 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11134 // is the more semantic-locating axis (an author who removes
11135 // the `{` typically also drops the trailing separator since
11136 // both are paste-from-shell artifacts).
11137 let d = dep_with_fonte(DepSource::Path {
11138 caminho: "../{caixa-teia,caixa-helm}/".into(),
11139 });
11140 let err = d.validate().unwrap_err();
11141 assert!(
11142 matches!(
11143 err,
11144 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11145 ),
11146 "got {err:?}",
11147 );
11148 }
11149
11150 #[test]
11151 fn fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11152 // Diagnostic-shape pin (peer with
11153 // `fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
11154 // on the closest two-byte peer arm): the error's Display
11155 // surfaces the offending `:nome`, the offending `:caminho`
11156 // verbatim, the offending byte's hex / character form, and
11157 // names the shell-brace-expansion / URI-Template footgun
11158 // explicitly so a `feira lint` run can render the diagnostic
11159 // without re-parsing.
11160 let d = dep_with_fonte(DepSource::Path {
11161 caminho: "../{caixa-teia,caixa-helm}/build".into(),
11162 });
11163 let rendered = d.validate().unwrap_err().to_string();
11164 assert!(
11165 rendered.contains("caixa-teia"),
11166 "diagnostic must name the offending dep: {rendered}",
11167 );
11168 assert!(
11169 rendered.contains("../{caixa-teia,caixa-helm}/build"),
11170 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11171 );
11172 assert!(
11173 rendered.contains("0x7b"),
11174 "diagnostic must surface the offending byte hex: {rendered:?}",
11175 );
11176 assert!(
11177 rendered.contains("brace-expansion"),
11178 "diagnostic must name the shell-brace-expansion footgun: {rendered:?}",
11179 );
11180 assert!(
11181 rendered.contains("URI Template"),
11182 "diagnostic must reference the RFC-6570 URI-Template-placeholder vocabulary: \
11183 {rendered:?}",
11184 );
11185 }
11186
11187 #[test]
11188 fn validate_rejects_path_fonte_with_caminho_carrying_bracket_glob_character_class() {
11189 // The canonical paste-from-shell-history bracket-glob /
11190 // character-class footgun: an author copies a
11191 // `cd ../caixa-[a-z]/build` shell-history one-liner whose
11192 // `[a-z]` POSIX glob character-class matches every lowercase-
11193 // ASCII-suffix sibling caixa directory and silently passed
11194 // every prior arm (`Path::is_absolute` false on `..`, no
11195 // control bytes, no `\`, no `<` / `>`, no `|`, no `;`, no
11196 // `&`, no backtick, no `*` / `?`, no `(` / `)`, no `{` /
11197 // `}`, doesn't end in `/`; the leading-`$` f4efe9c
11198 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11199 // value starts with `..` not `$`). The lacre embedded the
11200 // value verbatim, the resolver folded it through
11201 // `Path::join` looking for a literal `./../caixa-[a-z]/
11202 // build` subdirectory, and the failure surfaced at resolve
11203 // time with a non-self-locating `No such file or directory`
11204 // error. The new arm moves the rejection to validate time
11205 // and names the offending dep + caminho + byte verbatim.
11206 // The arm fires on the first `[` encountered.
11207 let d = dep_with_fonte(DepSource::Path {
11208 caminho: "../caixa-[a-z]/build".into(),
11209 });
11210 let err = d.validate().unwrap_err();
11211 let DepError::FonteCaminhoShellBracketExpansion {
11212 nome,
11213 caminho,
11214 byte,
11215 } = err
11216 else {
11217 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11218 };
11219 assert_eq!(nome, "caixa-teia");
11220 assert_eq!(caminho, "../caixa-[a-z]/build");
11221 assert_eq!(byte, b'[');
11222 }
11223
11224 #[test]
11225 fn validate_rejects_path_fonte_with_caminho_carrying_close_bracket() {
11226 // The symmetric close-bracket paste shape (`"../caixa-teia]"`
11227 // — the degenerate "I selected an unbalanced closing bracket
11228 // out of a glob character-class block" idiom that probes for
11229 // the cascade's last-byte handling on a value carrying only
11230 // the closing byte). Pinned separately from the open-bracket
11231 // shape so the gate's contract is "any `[` or `]` anywhere",
11232 // not single-byte coverage. Mirrors the peer
11233 // `validate_rejects_path_fonte_with_caminho_carrying_close_brace`
11234 // shape on the immediate-predecessor
11235 // `FonteCaminhoShellBraceExpansion` arm.
11236 let d = dep_with_fonte(DepSource::Path {
11237 caminho: "../caixa-teia]".into(),
11238 });
11239 let err = d.validate().unwrap_err();
11240 let DepError::FonteCaminhoShellBracketExpansion { byte, .. } = err else {
11241 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11242 };
11243 assert_eq!(byte, b']');
11244 }
11245
11246 #[test]
11247 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_bracket() {
11248 // Leading-position `[` shape (`"[caixa-teia]/build"` — the
11249 // canonical "I selected a `[caixa-teia]` TOML-table-header /
11250 // glob-character-class prefix out of an aligned config /
11251 // shell-history one-liner" idiom). Pinned separately from
11252 // the embedded-byte shape so the gate covers every position,
11253 // not only mid-path.
11254 let d = dep_with_fonte(DepSource::Path {
11255 caminho: "[caixa-teia]/build".into(),
11256 });
11257 let err = d.validate().unwrap_err();
11258 assert!(
11259 matches!(
11260 err,
11261 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11262 ),
11263 "got {err:?}",
11264 );
11265 }
11266
11267 #[test]
11268 fn validate_rejects_path_fonte_with_caminho_carrying_toml_inline_array() {
11269 // The canonical TOML inline-array / YAML flow-sequence
11270 // paste shape (`"../[\"a\", \"b\"]/caixa-teia"` — the
11271 // canonical "I copied a `features = [\"a\", \"b\"]` TOML
11272 // inline-array out of a sibling-Cargo manifest" cross-idiom
11273 // leak; the symmetric YAML flow-sequence form `paths: [/a,
11274 // /b]` paste-from-values.yaml shape carries the same
11275 // bracket pair). The arm fires on the first `[` encountered;
11276 // pinned so the gate's coverage extends from the bare-
11277 // bracket glob-character-class shape to the TOML / YAML /
11278 // JSON array-literal shape.
11279 let d = dep_with_fonte(DepSource::Path {
11280 caminho: "../[\"a\", \"b\"]/caixa-teia".into(),
11281 });
11282 let err = d.validate().unwrap_err();
11283 assert!(
11284 matches!(
11285 err,
11286 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11287 ),
11288 "got {err:?}",
11289 );
11290 }
11291
11292 #[test]
11293 fn validate_rejects_path_fonte_with_caminho_carrying_shell_test_builtin() {
11294 // The canonical POSIX `test` / `[` builtin command paste
11295 // shape (`"../[ -d caixa-teia ]"` — the `[ <expr> ]` shell-
11296 // script conditional every paste-from-shell-script idiom
11297 // carries; bash's `[[ <expr> ]]` extended-test grammar
11298 // would surface the same byte pair). The arm fires on the
11299 // first `[` encountered; pinned so the gate's coverage
11300 // extends from the embedded-glob-character-class shape to
11301 // the leading-`test`-builtin / extended-test form.
11302 let d = dep_with_fonte(DepSource::Path {
11303 caminho: "../[ -d caixa-teia ]".into(),
11304 });
11305 let err = d.validate().unwrap_err();
11306 assert!(
11307 matches!(
11308 err,
11309 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11310 ),
11311 "got {err:?}",
11312 );
11313 }
11314
11315 #[test]
11316 fn validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion() {
11317 // The positive-control pin: the gate targets only `[` /
11318 // `]`, never adjacent printable ASCII or POSIX-valid bytes.
11319 // The canonical relative POSIX path (`"../caixa-teia"`) and
11320 // a nested deeply-pathed variant with adjacent printable
11321 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11322 // to validate cleanly so the gate doesn't widen to a "no
11323 // printable punctuation anywhere" sweep that would defeat
11324 // the entire path-fonte author surface. Peer with
11325 // `validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion`
11326 // on the immediate-predecessor arm.
11327 let d = dep_with_fonte(DepSource::Path {
11328 caminho: "../caixa-teia/sub-dir.v2".into(),
11329 });
11330 d.validate().unwrap();
11331 }
11332
11333 #[test]
11334 fn fonte_caminho_shell_brace_expansion_fires_before_shell_bracket_expansion() {
11335 // Cascade pin on the immediate-predecessor arm: a value
11336 // carrying both `{` and `[` (`"../{a,b}[ch]"` — the
11337 // canonical "I pasted a brace-expansion fan followed by a
11338 // glob-character-class tail" footgun) routes through
11339 // `FonteCaminhoShellBraceExpansion` not
11340 // `FonteCaminhoShellBracketExpansion`. The brace-expansion
11341 // fan is the load-bearing root-cause edit on every
11342 // probe-as-both value because the bracket-class tail
11343 // typically rides on a prior brace-expansion expansion;
11344 // same cascade discipline every prior `:caminho` arm
11345 // establishes.
11346 let d = dep_with_fonte(DepSource::Path {
11347 caminho: "../{a,b}[ch]".into(),
11348 });
11349 let err = d.validate().unwrap_err();
11350 assert!(
11351 matches!(
11352 err,
11353 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11354 ),
11355 "got {err:?}",
11356 );
11357 }
11358
11359 #[test]
11360 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_bracket_expansion() {
11361 // Cascade pin on the upstream shell-subshell-grouping arm:
11362 // a value carrying both `(` and `[` (`"../(cd foo)/[ch]"` —
11363 // the canonical "I pasted a subshell-grouping followed by
11364 // a glob-character-class tail" footgun) routes through
11365 // `FonteCaminhoShellSubshellGrouping` not
11366 // `FonteCaminhoShellBracketExpansion`. The modern Bourne
11367 // `$(<cmd>)` command-substitution boundary is the load-
11368 // bearing axis on every probe-as-both value.
11369 let d = dep_with_fonte(DepSource::Path {
11370 caminho: "../(cd foo)/[ch]".into(),
11371 });
11372 let err = d.validate().unwrap_err();
11373 assert!(
11374 matches!(
11375 err,
11376 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11377 ),
11378 "got {err:?}",
11379 );
11380 }
11381
11382 #[test]
11383 fn fonte_caminho_shell_glob_fires_before_shell_bracket_expansion() {
11384 // Cascade pin on the upstream shell-glob arm: a value
11385 // carrying both `*` and `[` (`"../caixa-teia/*[ch]"` — the
11386 // canonical "I pasted a `*.[ch]` C-source-file glob whose
11387 // unbounded `*` precedes the bracket character-class"
11388 // footgun) routes through `FonteCaminhoShellGlob` not
11389 // `FonteCaminhoShellBracketExpansion`. The unbounded
11390 // pathname-expansion sentinel is the load-bearing root-
11391 // cause edit on every probe-as-both value — the unbounded
11392 // `*` carries the more aggressive expansion vector than
11393 // the bounded `[ch]` class, so the prior arm wins.
11394 let d = dep_with_fonte(DepSource::Path {
11395 caminho: "../caixa-teia/*[ch]".into(),
11396 });
11397 let err = d.validate().unwrap_err();
11398 assert!(
11399 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11400 "got {err:?}",
11401 );
11402 }
11403
11404 #[test]
11405 fn fonte_caminho_shell_command_substitution_fires_before_shell_bracket_expansion() {
11406 // Cascade pin on the upstream shell-command-substitution
11407 // arm: a value carrying both a backtick and `[`
11408 // (``"../`whoami`/[ch]"`` — the canonical "I pasted a
11409 // legacy-backtick command-substitution followed by a
11410 // glob-character-class tail" footgun) routes through
11411 // `FonteCaminhoShellCommandSubstitution` not
11412 // `FonteCaminhoShellBracketExpansion`. The CWE-78 shell-
11413 // command-injection vector is the load-bearing root-cause
11414 // edit on every probe-as-both value.
11415 let d = dep_with_fonte(DepSource::Path {
11416 caminho: "../`whoami`/[ch]".into(),
11417 });
11418 let err = d.validate().unwrap_err();
11419 assert!(
11420 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11421 "got {err:?}",
11422 );
11423 }
11424
11425 #[test]
11426 fn fonte_caminho_shell_background_fires_before_shell_bracket_expansion() {
11427 // Cascade pin on the upstream shell-background arm: a
11428 // value carrying both `&` and `[` (`"../caixa-teia & [ch]"`
11429 // — the canonical "I pasted a `cmd & [glob]` background-
11430 // launch + bracket-class chain" footgun) routes through
11431 // `FonteCaminhoShellBackground` not
11432 // `FonteCaminhoShellBracketExpansion`. The background-
11433 // launch tail is the load-bearing root-cause edit on
11434 // every probe-as-both value.
11435 let d = dep_with_fonte(DepSource::Path {
11436 caminho: "../caixa-teia & [ch]".into(),
11437 });
11438 let err = d.validate().unwrap_err();
11439 assert!(
11440 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11441 "got {err:?}",
11442 );
11443 }
11444
11445 #[test]
11446 fn fonte_caminho_shell_semicolon_fires_before_shell_bracket_expansion() {
11447 // Cascade pin on the upstream shell-semicolon arm: a value
11448 // carrying both `;` and `[` (`"../caixa-teia; [ch]"` — the
11449 // canonical sequential-cleanup + bracket-class paste
11450 // idiom) routes through `FonteCaminhoShellSemicolon` not
11451 // `FonteCaminhoShellBracketExpansion`. The sequential-
11452 // command-separator paste is the load-bearing root-cause
11453 // edit on every probe-as-both value.
11454 let d = dep_with_fonte(DepSource::Path {
11455 caminho: "../caixa-teia; [ch]".into(),
11456 });
11457 let err = d.validate().unwrap_err();
11458 assert!(
11459 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11460 "got {err:?}",
11461 );
11462 }
11463
11464 #[test]
11465 fn fonte_caminho_shell_pipe_fires_before_shell_bracket_expansion() {
11466 // Cascade pin on the upstream shell-pipe arm: a value
11467 // carrying both `|` and `[` (`"../caixa-teia | [tee]"` —
11468 // the canonical pipeline-to-bracket-class paste idiom)
11469 // routes through `FonteCaminhoShellPipe` not
11470 // `FonteCaminhoShellBracketExpansion`. The pipeline-tail
11471 // paste is the load-bearing root-cause edit on every
11472 // probe-as-both value.
11473 let d = dep_with_fonte(DepSource::Path {
11474 caminho: "../caixa-teia | [tee]".into(),
11475 });
11476 let err = d.validate().unwrap_err();
11477 assert!(
11478 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11479 "got {err:?}",
11480 );
11481 }
11482
11483 #[test]
11484 fn fonte_caminho_shell_redirection_fires_before_shell_bracket_expansion() {
11485 // Cascade pin on the upstream shell-redirection arm: a
11486 // value carrying both `>` and `[` (`"../caixa-teia>log
11487 // [ch]"` — the canonical "I pasted a `cmd > log [glob]`
11488 // redirect-plus-bracket chain" footgun) routes through
11489 // `FonteCaminhoShellRedirection` not
11490 // `FonteCaminhoShellBracketExpansion`. The input/output
11491 // redirection metachar carries the more self-locating
11492 // `byte` payload, so the prior arm wins on every
11493 // probe-as-both value.
11494 let d = dep_with_fonte(DepSource::Path {
11495 caminho: "../caixa-teia>log [ch]".into(),
11496 });
11497 let err = d.validate().unwrap_err();
11498 assert!(
11499 matches!(
11500 err,
11501 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11502 ),
11503 "got {err:?}",
11504 );
11505 }
11506
11507 #[test]
11508 fn fonte_caminho_backslash_fires_before_shell_bracket_expansion() {
11509 // Cascade pin on the upstream backslash arm: a value
11510 // carrying both `\` and `[` (`"..\caixa-teia\[ch]"` — the
11511 // canonical "I pasted a Windows-shell `cd ..\path\[glob]`
11512 // chain") routes through `FonteCaminhoBackslash` not
11513 // `FonteCaminhoShellBracketExpansion`. The cross-host-OS-
11514 // separator divergence is the load-bearing axis on every
11515 // probe-as-both value.
11516 let d = dep_with_fonte(DepSource::Path {
11517 caminho: "..\\caixa-teia\\[ch]".into(),
11518 });
11519 let err = d.validate().unwrap_err();
11520 assert!(
11521 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11522 "got {err:?}",
11523 );
11524 }
11525
11526 #[test]
11527 fn fonte_caminho_control_char_fires_before_shell_bracket_expansion() {
11528 // Cascade pin on the embedded-control-byte arm: a value
11529 // carrying both a control byte and `[` (`"../foo\n[ch]"` —
11530 // the canonical paste-from-multiline-doc footgun where a
11531 // newline landed mid-caminho between two paste fragments)
11532 // routes through `FonteCaminhoControlChar` not
11533 // `FonteCaminhoShellBracketExpansion`. The POSIX-syscall-
11534 // rejected-byte / NUL-`CString::new`-fail diagnostic is
11535 // the load-bearing axis on every value that probes
11536 // positive for both — mirrors the cascade discipline on
11537 // every prior arm.
11538 let d = dep_with_fonte(DepSource::Path {
11539 caminho: "../foo\n[ch]".into(),
11540 });
11541 let err = d.validate().unwrap_err();
11542 assert!(
11543 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11544 "got {err:?}",
11545 );
11546 }
11547
11548 #[test]
11549 fn fonte_caminho_absolute_fires_before_shell_bracket_expansion() {
11550 // Cascade pin on the load-bearing leading-byte arm: a
11551 // leading `/` value with embedded `[` (`"/etc/[ch]"`)
11552 // routes through `FonteCaminhoAbsolute` not
11553 // `FonteCaminhoShellBracketExpansion` — the host-layout-
11554 // leak diagnostic is the load-bearing axis, the bracket-
11555 // expansion byte is the secondary observation. Same
11556 // precedence logic as every prior leading-byte arm.
11557 let d = dep_with_fonte(DepSource::Path {
11558 caminho: "/etc/[ch]".into(),
11559 });
11560 let err = d.validate().unwrap_err();
11561 assert!(
11562 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11563 "got {err:?}",
11564 );
11565 }
11566
11567 #[test]
11568 fn fonte_caminho_var_expansion_fires_before_shell_bracket_expansion() {
11569 // Cascade pin on the upstream leading-`$` var-expansion
11570 // arm: a value carrying both a leading `$` and a `[`
11571 // (`"$DIR/[ch]"` — the canonical "I pasted a `$DIR` shell-
11572 // variable + bracket-class at the head of a sibling-
11573 // workspace path" footgun) routes through
11574 // `FonteCaminhoVarExpansion` not
11575 // `FonteCaminhoShellBracketExpansion`. The leading-byte
11576 // shell-variable-expansion is the more self-locating
11577 // diagnostic on values that probe as both — same
11578 // load-bearing-leading-byte cascade discipline every
11579 // prior `:caminho` arm establishes.
11580 let d = dep_with_fonte(DepSource::Path {
11581 caminho: "$DIR/[ch]".into(),
11582 });
11583 let err = d.validate().unwrap_err();
11584 assert!(
11585 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11586 "got {err:?}",
11587 );
11588 }
11589
11590 #[test]
11591 fn fonte_caminho_shell_bracket_expansion_fires_before_trailing_slash() {
11592 // Cascade pin on the immediate-successor arm: a value
11593 // carrying both `[` and a trailing `/` (`"../[a-z]/"` —
11594 // the canonical "I tab-completed a path that already had
11595 // a bracket-glob-character-class expansion tail" footgun)
11596 // routes through `FonteCaminhoShellBracketExpansion` not
11597 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11598 // is the more semantic-locating axis (an author who
11599 // removes the `[` typically also drops the trailing
11600 // separator since both are paste-from-shell artifacts).
11601 let d = dep_with_fonte(DepSource::Path {
11602 caminho: "../[a-z]/".into(),
11603 });
11604 let err = d.validate().unwrap_err();
11605 assert!(
11606 matches!(
11607 err,
11608 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11609 ),
11610 "got {err:?}",
11611 );
11612 }
11613
11614 #[test]
11615 fn fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11616 // Diagnostic-shape pin (peer with
11617 // `fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11618 // on the closest two-byte peer arm): the error's Display
11619 // surfaces the offending `:nome`, the offending `:caminho`
11620 // verbatim, the offending byte's hex / character form, and
11621 // names the shell-bracket-expansion / glob-character-class
11622 // footgun explicitly so a `feira lint` run can render the
11623 // diagnostic without re-parsing.
11624 let d = dep_with_fonte(DepSource::Path {
11625 caminho: "../caixa-[a-z]/build".into(),
11626 });
11627 let rendered = d.validate().unwrap_err().to_string();
11628 assert!(
11629 rendered.contains("caixa-teia"),
11630 "diagnostic must name the offending dep: {rendered}",
11631 );
11632 assert!(
11633 rendered.contains("../caixa-[a-z]/build"),
11634 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11635 );
11636 assert!(
11637 rendered.contains("0x5b"),
11638 "diagnostic must surface the offending byte hex: {rendered:?}",
11639 );
11640 assert!(
11641 rendered.contains("bracket-expansion"),
11642 "diagnostic must name the shell-bracket-expansion footgun: {rendered:?}",
11643 );
11644 assert!(
11645 rendered.contains("glob-character-class"),
11646 "diagnostic must reference the POSIX glob-character-class vocabulary: \
11647 {rendered:?}",
11648 );
11649 }
11650
11651 #[test]
11652 fn validate_rejects_path_fonte_with_caminho_carrying_single_quote_grouping() {
11653 // The canonical paste-from-shell-history strong-quoted
11654 // sibling-workspace-path footgun: an author copies a
11655 // `cd '../caixa-teia'` shell-history one-liner whose strong-
11656 // quoting preserved the path across a whitespace paste
11657 // boundary and silently passed every prior arm
11658 // (`Path::is_absolute` false on `'..`, no control bytes, no
11659 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no
11660 // `*` / `?`, no `(` / `)`, no `{` / `}`, no `[` / `]`,
11661 // doesn't end in `/`; the leading-`$` f4efe9c
11662 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11663 // value starts with `'` not `$`). The lacre embedded the
11664 // value verbatim, the resolver folded it through
11665 // `Path::join` looking for a literal `./'../caixa-teia'`
11666 // subdirectory, and the failure surfaced at resolve time
11667 // with a non-self-locating `No such file or directory`
11668 // error. The new arm moves the rejection to validate time
11669 // and names the offending dep + caminho + byte verbatim.
11670 // The arm fires on the first `'` encountered.
11671 let d = dep_with_fonte(DepSource::Path {
11672 caminho: "'../caixa-teia'".into(),
11673 });
11674 let err = d.validate().unwrap_err();
11675 let DepError::FonteCaminhoShellQuoteGrouping {
11676 nome,
11677 caminho,
11678 byte,
11679 } = err
11680 else {
11681 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11682 };
11683 assert_eq!(nome, "caixa-teia");
11684 assert_eq!(caminho, "'../caixa-teia'");
11685 assert_eq!(byte, b'\'');
11686 }
11687
11688 #[test]
11689 fn validate_rejects_path_fonte_with_caminho_carrying_double_quote_grouping() {
11690 // The symmetric weak-quoted paste shape (`"\"../caixa-teia\""`
11691 // — the canonical paste-from-JSON-config / paste-from-YAML-
11692 // flow-scalar / paste-from-TOML-basic-string / paste-from-
11693 // tatara-lisp-string-literal cross-idiom leak). Pinned
11694 // separately from the single-quote shape so the gate's
11695 // contract is "any `'` or `\"` anywhere", not single-byte
11696 // coverage. Mirrors the peer
11697 // `validate_rejects_path_fonte_with_caminho_carrying_close_bracket`
11698 // shape on the immediate-predecessor
11699 // `FonteCaminhoShellBracketExpansion` arm.
11700 let d = dep_with_fonte(DepSource::Path {
11701 caminho: "\"../caixa-teia\"".into(),
11702 });
11703 let err = d.validate().unwrap_err();
11704 let DepError::FonteCaminhoShellQuoteGrouping { byte, .. } = err else {
11705 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11706 };
11707 assert_eq!(byte, b'"');
11708 }
11709
11710 #[test]
11711 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_double_quote() {
11712 // Embedded-position `"` shape (`"../\"caixa-teia\""` — the
11713 // canonical "I pasted a JSON key-value pair fragment into
11714 // the middle of the path" idiom). Pinned separately from
11715 // the leading-byte shape so the gate covers every position,
11716 // not only leading.
11717 let d = dep_with_fonte(DepSource::Path {
11718 caminho: "../\"caixa-teia\"".into(),
11719 });
11720 let err = d.validate().unwrap_err();
11721 assert!(
11722 matches!(
11723 err,
11724 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11725 ),
11726 "got {err:?}",
11727 );
11728 }
11729
11730 #[test]
11731 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_flow_scalar_paste() {
11732 // The canonical YAML double-quoted flow-scalar cross-idiom
11733 // leak shape (`"path: \"../caixa-teia\""` — the "I copied a
11734 // `path: \"...\"` YAML flow-scalar entry out of an aligned
11735 // values.yaml / K8s manifest and dropped it verbatim into
11736 // the `:caminho` slot including the `path: ` key prefix"
11737 // paste-idiom). The arm fires on the first `"` encountered;
11738 // pinned so the gate's coverage extends from the bare-quote
11739 // paste shape to the aligned-YAML-manifest cross-idiom-leak
11740 // shape.
11741 let d = dep_with_fonte(DepSource::Path {
11742 caminho: "path: \"../caixa-teia\"".into(),
11743 });
11744 let err = d.validate().unwrap_err();
11745 assert!(
11746 matches!(
11747 err,
11748 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11749 ),
11750 "got {err:?}",
11751 );
11752 }
11753
11754 #[test]
11755 fn validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping() {
11756 // The positive-control pin: the gate targets only `'` /
11757 // `"`, never adjacent printable ASCII or POSIX-valid bytes.
11758 // The canonical relative POSIX path (`"../caixa-teia"`) and
11759 // a nested deeply-pathed variant with adjacent printable
11760 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11761 // to validate cleanly so the gate doesn't widen to a "no
11762 // printable punctuation anywhere" sweep that would defeat
11763 // the entire path-fonte author surface. Peer with
11764 // `validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion`
11765 // on the immediate-predecessor arm.
11766 let d = dep_with_fonte(DepSource::Path {
11767 caminho: "../caixa-teia/sub-dir.v2".into(),
11768 });
11769 d.validate().unwrap();
11770 }
11771
11772 #[test]
11773 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_quote_grouping() {
11774 // Cascade pin on the immediate-predecessor arm: a value
11775 // carrying both `[` and `'` (`"../[a-z]'x'"` — the canonical
11776 // "I pasted a glob-character-class followed by a strong-
11777 // quoted literal tail" footgun) routes through
11778 // `FonteCaminhoShellBracketExpansion` not
11779 // `FonteCaminhoShellQuoteGrouping`. The glob-character-class
11780 // expansion is the load-bearing root-cause edit on every
11781 // probe-as-both value; same cascade discipline every prior
11782 // `:caminho` arm establishes.
11783 let d = dep_with_fonte(DepSource::Path {
11784 caminho: "../[a-z]'x'".into(),
11785 });
11786 let err = d.validate().unwrap_err();
11787 assert!(
11788 matches!(
11789 err,
11790 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11791 ),
11792 "got {err:?}",
11793 );
11794 }
11795
11796 #[test]
11797 fn fonte_caminho_shell_brace_expansion_fires_before_shell_quote_grouping() {
11798 // Cascade pin on the upstream shell-brace-expansion arm: a
11799 // value carrying both `{` and `'` (`"../{a,b}'x'"` — the
11800 // canonical "I pasted a brace-expansion fan followed by a
11801 // strong-quoted literal tail" footgun) routes through
11802 // `FonteCaminhoShellBraceExpansion` not
11803 // `FonteCaminhoShellQuoteGrouping`. The brace-expansion fan
11804 // is the load-bearing root-cause edit on every probe-as-
11805 // both value.
11806 let d = dep_with_fonte(DepSource::Path {
11807 caminho: "../{a,b}'x'".into(),
11808 });
11809 let err = d.validate().unwrap_err();
11810 assert!(
11811 matches!(
11812 err,
11813 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11814 ),
11815 "got {err:?}",
11816 );
11817 }
11818
11819 #[test]
11820 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_quote_grouping() {
11821 // Cascade pin on the upstream shell-subshell-grouping arm:
11822 // a value carrying both `(` and `'` (`"../(cd foo)/'x'"` —
11823 // the canonical "I pasted a subshell-grouping followed by
11824 // a strong-quoted literal tail" footgun) routes through
11825 // `FonteCaminhoShellSubshellGrouping` not
11826 // `FonteCaminhoShellQuoteGrouping`. The modern Bourne
11827 // `$(<cmd>)` command-substitution boundary is the load-
11828 // bearing axis on every probe-as-both value.
11829 let d = dep_with_fonte(DepSource::Path {
11830 caminho: "../(cd foo)/'x'".into(),
11831 });
11832 let err = d.validate().unwrap_err();
11833 assert!(
11834 matches!(
11835 err,
11836 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11837 ),
11838 "got {err:?}",
11839 );
11840 }
11841
11842 #[test]
11843 fn fonte_caminho_shell_glob_fires_before_shell_quote_grouping() {
11844 // Cascade pin on the upstream shell-glob arm: a value
11845 // carrying both `*` and `'` (`"../caixa-teia/*'x'"` — the
11846 // canonical "I pasted a `*` unbounded pathname-expansion
11847 // followed by a strong-quoted literal tail" footgun) routes
11848 // through `FonteCaminhoShellGlob` not
11849 // `FonteCaminhoShellQuoteGrouping`. The unbounded pathname-
11850 // expansion sentinel is the load-bearing root-cause edit
11851 // on every probe-as-both value.
11852 let d = dep_with_fonte(DepSource::Path {
11853 caminho: "../caixa-teia/*'x'".into(),
11854 });
11855 let err = d.validate().unwrap_err();
11856 assert!(
11857 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11858 "got {err:?}",
11859 );
11860 }
11861
11862 #[test]
11863 fn fonte_caminho_shell_command_substitution_fires_before_shell_quote_grouping() {
11864 // Cascade pin on the upstream shell-command-substitution
11865 // arm: a value carrying both a backtick and `'`
11866 // (``"../`whoami`/'x'"`` — the canonical "I pasted a
11867 // legacy-backtick command-substitution followed by a
11868 // strong-quoted literal tail" footgun) routes through
11869 // `FonteCaminhoShellCommandSubstitution` not
11870 // `FonteCaminhoShellQuoteGrouping`. The CWE-78 shell-
11871 // command-injection vector is the load-bearing root-cause
11872 // edit on every probe-as-both value.
11873 let d = dep_with_fonte(DepSource::Path {
11874 caminho: "../`whoami`/'x'".into(),
11875 });
11876 let err = d.validate().unwrap_err();
11877 assert!(
11878 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11879 "got {err:?}",
11880 );
11881 }
11882
11883 #[test]
11884 fn fonte_caminho_shell_background_fires_before_shell_quote_grouping() {
11885 // Cascade pin on the upstream shell-background arm: a value
11886 // carrying both `&` and `'` (`"../caixa-teia & 'x'"` — the
11887 // canonical "I pasted a `cmd & 'literal'` background-launch
11888 // + quote chain" footgun) routes through
11889 // `FonteCaminhoShellBackground` not
11890 // `FonteCaminhoShellQuoteGrouping`. The background-launch
11891 // tail is the load-bearing root-cause edit on every
11892 // probe-as-both value.
11893 let d = dep_with_fonte(DepSource::Path {
11894 caminho: "../caixa-teia & 'x'".into(),
11895 });
11896 let err = d.validate().unwrap_err();
11897 assert!(
11898 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11899 "got {err:?}",
11900 );
11901 }
11902
11903 #[test]
11904 fn fonte_caminho_shell_semicolon_fires_before_shell_quote_grouping() {
11905 // Cascade pin on the upstream shell-semicolon arm: a value
11906 // carrying both `;` and `'` (`"../caixa-teia; 'x'"` — the
11907 // canonical sequential-cleanup + quote paste idiom) routes
11908 // through `FonteCaminhoShellSemicolon` not
11909 // `FonteCaminhoShellQuoteGrouping`. The sequential-command-
11910 // separator paste is the load-bearing root-cause edit on
11911 // every probe-as-both value.
11912 let d = dep_with_fonte(DepSource::Path {
11913 caminho: "../caixa-teia; 'x'".into(),
11914 });
11915 let err = d.validate().unwrap_err();
11916 assert!(
11917 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11918 "got {err:?}",
11919 );
11920 }
11921
11922 #[test]
11923 fn fonte_caminho_shell_pipe_fires_before_shell_quote_grouping() {
11924 // Cascade pin on the upstream shell-pipe arm: a value
11925 // carrying both `|` and `'` (`"../caixa-teia | 'x'"` — the
11926 // canonical pipeline-to-quoted-literal paste idiom) routes
11927 // through `FonteCaminhoShellPipe` not
11928 // `FonteCaminhoShellQuoteGrouping`. The pipeline-tail paste
11929 // is the load-bearing root-cause edit on every probe-as-
11930 // both value.
11931 let d = dep_with_fonte(DepSource::Path {
11932 caminho: "../caixa-teia | 'x'".into(),
11933 });
11934 let err = d.validate().unwrap_err();
11935 assert!(
11936 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11937 "got {err:?}",
11938 );
11939 }
11940
11941 #[test]
11942 fn fonte_caminho_shell_redirection_fires_before_shell_quote_grouping() {
11943 // Cascade pin on the upstream shell-redirection arm: a
11944 // value carrying both `>` and `'` (`"../caixa-teia>log 'x'"`
11945 // — the canonical "I pasted a `cmd > log 'literal'`
11946 // redirect-plus-quote chain" footgun) routes through
11947 // `FonteCaminhoShellRedirection` not
11948 // `FonteCaminhoShellQuoteGrouping`. The input/output
11949 // redirection metachar carries the more self-locating
11950 // `byte` payload, so the prior arm wins on every probe-as-
11951 // both value.
11952 let d = dep_with_fonte(DepSource::Path {
11953 caminho: "../caixa-teia>log 'x'".into(),
11954 });
11955 let err = d.validate().unwrap_err();
11956 assert!(
11957 matches!(
11958 err,
11959 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11960 ),
11961 "got {err:?}",
11962 );
11963 }
11964
11965 #[test]
11966 fn fonte_caminho_backslash_fires_before_shell_quote_grouping() {
11967 // Cascade pin on the upstream backslash arm: a value
11968 // carrying both `\` and `'` (`"..\caixa-teia\'x'"` — the
11969 // canonical "I pasted a Windows-shell `cd ..\path\'literal'`
11970 // chain" footgun) routes through `FonteCaminhoBackslash`
11971 // not `FonteCaminhoShellQuoteGrouping`. The cross-host-OS-
11972 // separator divergence is the load-bearing axis on every
11973 // probe-as-both value.
11974 let d = dep_with_fonte(DepSource::Path {
11975 caminho: "..\\caixa-teia\\'x'".into(),
11976 });
11977 let err = d.validate().unwrap_err();
11978 assert!(
11979 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11980 "got {err:?}",
11981 );
11982 }
11983
11984 #[test]
11985 fn fonte_caminho_control_char_fires_before_shell_quote_grouping() {
11986 // Cascade pin on the embedded-control-byte arm: a value
11987 // carrying both a control byte and `'` (`"../foo\n'x'"` —
11988 // the canonical paste-from-multiline-doc footgun where a
11989 // newline landed mid-caminho between two paste fragments)
11990 // routes through `FonteCaminhoControlChar` not
11991 // `FonteCaminhoShellQuoteGrouping`. The POSIX-syscall-
11992 // rejected-byte / NUL-`CString::new`-fail diagnostic is
11993 // the load-bearing axis on every value that probes
11994 // positive for both — mirrors the cascade discipline on
11995 // every prior arm.
11996 let d = dep_with_fonte(DepSource::Path {
11997 caminho: "../foo\n'x'".into(),
11998 });
11999 let err = d.validate().unwrap_err();
12000 assert!(
12001 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12002 "got {err:?}",
12003 );
12004 }
12005
12006 #[test]
12007 fn fonte_caminho_absolute_fires_before_shell_quote_grouping() {
12008 // Cascade pin on the load-bearing leading-byte arm: a
12009 // leading `/` value with embedded `'` (`"/etc/'x'"`) routes
12010 // through `FonteCaminhoAbsolute` not
12011 // `FonteCaminhoShellQuoteGrouping` — the host-layout-leak
12012 // diagnostic is the load-bearing axis, the quote byte is
12013 // the secondary observation. Same precedence logic as every
12014 // prior leading-byte arm.
12015 let d = dep_with_fonte(DepSource::Path {
12016 caminho: "/etc/'x'".into(),
12017 });
12018 let err = d.validate().unwrap_err();
12019 assert!(
12020 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12021 "got {err:?}",
12022 );
12023 }
12024
12025 #[test]
12026 fn fonte_caminho_var_expansion_fires_before_shell_quote_grouping() {
12027 // Cascade pin on the upstream leading-`$` var-expansion
12028 // arm: a value carrying both a leading `$` and a `'`
12029 // (`"$DIR/'x'"` — the canonical "I pasted a `$DIR` shell-
12030 // variable + quoted literal at the head of a sibling-
12031 // workspace path" footgun) routes through
12032 // `FonteCaminhoVarExpansion` not
12033 // `FonteCaminhoShellQuoteGrouping`. The leading-byte
12034 // shell-variable-expansion is the more self-locating
12035 // diagnostic on values that probe as both — same
12036 // load-bearing-leading-byte cascade discipline every
12037 // prior `:caminho` arm establishes.
12038 let d = dep_with_fonte(DepSource::Path {
12039 caminho: "$DIR/'x'".into(),
12040 });
12041 let err = d.validate().unwrap_err();
12042 assert!(
12043 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12044 "got {err:?}",
12045 );
12046 }
12047
12048 #[test]
12049 fn fonte_caminho_shell_quote_grouping_fires_before_trailing_slash() {
12050 // Cascade pin on the immediate-successor arm: a value
12051 // carrying both `'` and a trailing `/` (`"../'caixa-teia'/"`
12052 // — the canonical "I tab-completed a path whose strong-
12053 // quoted body already carried the quoting from a shell-
12054 // history paste" footgun) routes through
12055 // `FonteCaminhoShellQuoteGrouping` not
12056 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
12057 // is the more semantic-locating axis (an author who removes
12058 // the `'` typically also drops the trailing separator since
12059 // both are paste-from-shell artifacts).
12060 let d = dep_with_fonte(DepSource::Path {
12061 caminho: "../'caixa-teia'/".into(),
12062 });
12063 let err = d.validate().unwrap_err();
12064 assert!(
12065 matches!(
12066 err,
12067 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12068 ),
12069 "got {err:?}",
12070 );
12071 }
12072
12073 #[test]
12074 fn fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
12075 // Diagnostic-shape pin (peer with
12076 // `fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
12077 // on the closest two-byte peer arm): the error's Display
12078 // surfaces the offending `:nome`, the offending `:caminho`
12079 // verbatim, the offending byte's hex / character form, and
12080 // names the shell-quote-grouping / cross-config-DSL-string-
12081 // literal-delimiter footgun explicitly so a `feira lint`
12082 // run can render the diagnostic without re-parsing.
12083 let d = dep_with_fonte(DepSource::Path {
12084 caminho: "'../caixa-teia'".into(),
12085 });
12086 let rendered = d.validate().unwrap_err().to_string();
12087 assert!(
12088 rendered.contains("caixa-teia"),
12089 "diagnostic must name the offending dep: {rendered}",
12090 );
12091 assert!(
12092 rendered.contains("'../caixa-teia'"),
12093 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12094 );
12095 assert!(
12096 rendered.contains("0x27"),
12097 "diagnostic must surface the offending byte hex: {rendered:?}",
12098 );
12099 assert!(
12100 rendered.contains("quote-grouping"),
12101 "diagnostic must name the shell-quote-grouping footgun: {rendered:?}",
12102 );
12103 assert!(
12104 rendered.contains("string-literal"),
12105 "diagnostic must reference the cross-config-DSL string-literal-delimiter \
12106 vocabulary: {rendered:?}",
12107 );
12108 }
12109
12110 #[test]
12111 fn validate_rejects_path_fonte_with_caminho_carrying_shell_comment_lead() {
12112 // The canonical paste-from-shell-history-with-trailing-
12113 // annotation footgun: an author pastes a `cd ../caixa-teia
12114 // # legacy sibling` shell-history one-liner whose unquoted `#`
12115 // comment-lead separates the path from an inline annotation.
12116 // The POSIX shell trims the annotation to `../caixa-teia`
12117 // (POSIX.1-2017 §2.3 Token Recognition step 6), but
12118 // `Path::is_absolute` returns false on `..`, `#` is neither
12119 // a leading-byte sentinel nor a control byte nor `\` nor
12120 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` /
12121 // `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` /
12122 // `"`, and the value's last byte isn't `/` — so the value
12123 // silently passed every prior arm. The resolver folded the
12124 // value through `Path::join` looking for a literal
12125 // `./../caixa-teia # legacy sibling` subdirectory and the
12126 // failure surfaced at resolve time with a non-self-locating
12127 // `No such file or directory` error. The new arm moves the
12128 // rejection to validate time and names the offending dep +
12129 // caminho + byte verbatim.
12130 let d = dep_with_fonte(DepSource::Path {
12131 caminho: "../caixa-teia # legacy sibling".into(),
12132 });
12133 let err = d.validate().unwrap_err();
12134 let DepError::FonteCaminhoShellComment {
12135 nome,
12136 caminho,
12137 byte,
12138 } = err
12139 else {
12140 panic!("expected FonteCaminhoShellComment, got {err:?}");
12141 };
12142 assert_eq!(nome, "caixa-teia");
12143 assert_eq!(caminho, "../caixa-teia # legacy sibling");
12144 assert_eq!(byte, b'#');
12145 }
12146
12147 #[test]
12148 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_comment_paste() {
12149 // The symmetric YAML flow-scalar / values.yaml / K8s-manifest
12150 // cross-idiom-leak shape (`"../caixa-teia # pin"` — the
12151 // canonical "I copied a `path: ../caixa-teia # pin` YAML
12152 // scalar-plus-comment entry out of an aligned values.yaml and
12153 // dropped it verbatim into the `:caminho` slot" paste-idiom).
12154 // Pinned separately from the shell-history shape so the
12155 // gate's coverage extends from the single-space `#` shape to
12156 // the YAML-canonical double-space ` #` shape. YAML 1.2 §6.6
12157 // requires the `#` to be preceded by whitespace to lex as a
12158 // comment (bare `foo#bar` is a single scalar); the double-
12159 // space paste from an aligned manifest is the canonical
12160 // shape.
12161 let d = dep_with_fonte(DepSource::Path {
12162 caminho: "../caixa-teia # pin".into(),
12163 });
12164 let err = d.validate().unwrap_err();
12165 assert!(
12166 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12167 "got {err:?}",
12168 );
12169 }
12170
12171 #[test]
12172 fn validate_rejects_path_fonte_with_caminho_carrying_url_fragment_anchor() {
12173 // The URL-fragment-identifier paste shape
12174 // (`"../caixa-teia#readme"` — the canonical
12175 // paste-from-browser-address-bar permalink shape where the
12176 // browser preserved the `#anchor` tail on the copy). Pinned
12177 // separately from the whitespace-separated shell / YAML
12178 // comment shapes so the gate covers the unpadded RFC 3986
12179 // §3.5 fragment-delimiter position too, not only positions
12180 // preceded by unquoted whitespace. Peer with the immediate-
12181 // sibling `is_git_repo_url` arm on the `:fonte :repo` axis
12182 // (a68f818) which closes the same byte under the same URL-
12183 // fragment-identifier banner.
12184 let d = dep_with_fonte(DepSource::Path {
12185 caminho: "../caixa-teia#readme".into(),
12186 });
12187 let err = d.validate().unwrap_err();
12188 assert!(
12189 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12190 "got {err:?}",
12191 );
12192 }
12193
12194 #[test]
12195 fn validate_rejects_path_fonte_with_caminho_carrying_leading_shell_comment() {
12196 // Leading-position `#` shape (`"#../caixa-teia"` — the
12197 // "I copied a shell-comment-out entry from a commented-out
12198 // dep row" footgun). Pinned separately from the embedded
12199 // shapes so the gate covers every position, not only
12200 // whitespace-preceded / mid-value.
12201 let d = dep_with_fonte(DepSource::Path {
12202 caminho: "#../caixa-teia".into(),
12203 });
12204 let err = d.validate().unwrap_err();
12205 assert!(
12206 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12207 "got {err:?}",
12208 );
12209 }
12210
12211 #[test]
12212 fn validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment() {
12213 // The positive-control pin: the gate targets only `#`,
12214 // never adjacent printable ASCII or POSIX-valid bytes. The
12215 // canonical relative POSIX path (`"../caixa-teia"`) and a
12216 // nested deeply-pathed variant with adjacent printable
12217 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12218 // to validate cleanly so the gate doesn't widen to a "no
12219 // printable punctuation anywhere" sweep that would defeat
12220 // the entire path-fonte author surface. Peer with
12221 // `validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping`
12222 // on the immediate-predecessor arm.
12223 let d = dep_with_fonte(DepSource::Path {
12224 caminho: "../caixa-teia/sub-dir.v2".into(),
12225 });
12226 d.validate().unwrap();
12227 }
12228
12229 #[test]
12230 fn fonte_caminho_shell_quote_grouping_fires_before_shell_comment() {
12231 // Cascade pin on the immediate-predecessor arm: a value
12232 // carrying both `'` and `#` (`"../'x'#pin"` — the canonical
12233 // "I pasted a strong-quoted literal followed by a URL-
12234 // fragment permalink tail" footgun) routes through
12235 // `FonteCaminhoShellQuoteGrouping` not
12236 // `FonteCaminhoShellComment`. The shell-string-literal-
12237 // delimiter is the load-bearing root-cause edit on every
12238 // probe-as-both value; same cascade discipline every prior
12239 // `:caminho` arm establishes.
12240 let d = dep_with_fonte(DepSource::Path {
12241 caminho: "../'x'#pin".into(),
12242 });
12243 let err = d.validate().unwrap_err();
12244 assert!(
12245 matches!(
12246 err,
12247 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12248 ),
12249 "got {err:?}",
12250 );
12251 }
12252
12253 #[test]
12254 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_comment() {
12255 // Cascade pin on the upstream shell-bracket-expansion arm:
12256 // a value carrying both `[` and `#` (`"../[a-z]#pin"` — the
12257 // canonical "I pasted a glob-character-class followed by a
12258 // URL-fragment tail" footgun) routes through
12259 // `FonteCaminhoShellBracketExpansion` not
12260 // `FonteCaminhoShellComment`. The glob-character-class
12261 // expansion is the load-bearing root-cause edit on every
12262 // probe-as-both value.
12263 let d = dep_with_fonte(DepSource::Path {
12264 caminho: "../[a-z]#pin".into(),
12265 });
12266 let err = d.validate().unwrap_err();
12267 assert!(
12268 matches!(
12269 err,
12270 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12271 ),
12272 "got {err:?}",
12273 );
12274 }
12275
12276 #[test]
12277 fn fonte_caminho_shell_brace_expansion_fires_before_shell_comment() {
12278 // Cascade pin on the upstream shell-brace-expansion arm: a
12279 // value carrying both `{` and `#` (`"../{a,b}#pin"` — the
12280 // canonical "I pasted a brace-expansion fan followed by a
12281 // URL-fragment tail" footgun) routes through
12282 // `FonteCaminhoShellBraceExpansion` not
12283 // `FonteCaminhoShellComment`. The brace-expansion fan is the
12284 // load-bearing root-cause edit on every probe-as-both value.
12285 let d = dep_with_fonte(DepSource::Path {
12286 caminho: "../{a,b}#pin".into(),
12287 });
12288 let err = d.validate().unwrap_err();
12289 assert!(
12290 matches!(
12291 err,
12292 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12293 ),
12294 "got {err:?}",
12295 );
12296 }
12297
12298 #[test]
12299 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_comment() {
12300 // Cascade pin on the upstream shell-subshell-grouping arm:
12301 // a value carrying both `(` and `#` (`"../(cd foo)#pin"` —
12302 // the canonical "I pasted a subshell-grouping followed by a
12303 // URL-fragment tail" footgun) routes through
12304 // `FonteCaminhoShellSubshellGrouping` not
12305 // `FonteCaminhoShellComment`. The modern Bourne `$(<cmd>)`
12306 // command-substitution boundary is the load-bearing axis on
12307 // every probe-as-both value.
12308 let d = dep_with_fonte(DepSource::Path {
12309 caminho: "../(cd foo)#pin".into(),
12310 });
12311 let err = d.validate().unwrap_err();
12312 assert!(
12313 matches!(
12314 err,
12315 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12316 ),
12317 "got {err:?}",
12318 );
12319 }
12320
12321 #[test]
12322 fn fonte_caminho_shell_glob_fires_before_shell_comment() {
12323 // Cascade pin on the upstream shell-glob arm: a value
12324 // carrying both `*` and `#` (`"../caixa-teia/*#pin"` — the
12325 // canonical "I pasted a `*` unbounded pathname-expansion
12326 // followed by a URL-fragment tail" footgun) routes through
12327 // `FonteCaminhoShellGlob` not `FonteCaminhoShellComment`.
12328 // The unbounded pathname-expansion sentinel is the load-
12329 // bearing root-cause edit on every probe-as-both value.
12330 let d = dep_with_fonte(DepSource::Path {
12331 caminho: "../caixa-teia/*#pin".into(),
12332 });
12333 let err = d.validate().unwrap_err();
12334 assert!(
12335 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12336 "got {err:?}",
12337 );
12338 }
12339
12340 #[test]
12341 fn fonte_caminho_shell_command_substitution_fires_before_shell_comment() {
12342 // Cascade pin on the upstream shell-command-substitution
12343 // arm: a value carrying both a backtick and `#`
12344 // (``"../`whoami`#pin"`` — the canonical "I pasted a
12345 // legacy-backtick command-substitution followed by a URL-
12346 // fragment tail" footgun) routes through
12347 // `FonteCaminhoShellCommandSubstitution` not
12348 // `FonteCaminhoShellComment`. The CWE-78 shell-command-
12349 // injection vector is the load-bearing root-cause edit on
12350 // every probe-as-both value.
12351 let d = dep_with_fonte(DepSource::Path {
12352 caminho: "../`whoami`#pin".into(),
12353 });
12354 let err = d.validate().unwrap_err();
12355 assert!(
12356 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12357 "got {err:?}",
12358 );
12359 }
12360
12361 #[test]
12362 fn fonte_caminho_shell_background_fires_before_shell_comment() {
12363 // Cascade pin on the upstream shell-background arm: a value
12364 // carrying both `&` and `#` (`"../caixa-teia&pin#tail"` —
12365 // the canonical "I pasted a `cmd &` background-launch
12366 // followed by a URL-fragment tail" footgun) routes through
12367 // `FonteCaminhoShellBackground` not
12368 // `FonteCaminhoShellComment`. The background-launch tail is
12369 // the load-bearing root-cause edit on every probe-as-both
12370 // value.
12371 let d = dep_with_fonte(DepSource::Path {
12372 caminho: "../caixa-teia&pin#tail".into(),
12373 });
12374 let err = d.validate().unwrap_err();
12375 assert!(
12376 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12377 "got {err:?}",
12378 );
12379 }
12380
12381 #[test]
12382 fn fonte_caminho_shell_semicolon_fires_before_shell_comment() {
12383 // Cascade pin on the upstream shell-semicolon arm: a value
12384 // carrying both `;` and `#` (`"../caixa-teia;pin#tail"` —
12385 // the canonical sequential-cleanup + URL-fragment paste
12386 // idiom) routes through `FonteCaminhoShellSemicolon` not
12387 // `FonteCaminhoShellComment`. The sequential-command-
12388 // separator paste is the load-bearing root-cause edit on
12389 // every probe-as-both value.
12390 let d = dep_with_fonte(DepSource::Path {
12391 caminho: "../caixa-teia;pin#tail".into(),
12392 });
12393 let err = d.validate().unwrap_err();
12394 assert!(
12395 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12396 "got {err:?}",
12397 );
12398 }
12399
12400 #[test]
12401 fn fonte_caminho_shell_pipe_fires_before_shell_comment() {
12402 // Cascade pin on the upstream shell-pipe arm: a value
12403 // carrying both `|` and `#` (`"../caixa-teia|pin#tail"` —
12404 // the canonical pipeline-to-URL-fragment paste idiom) routes
12405 // through `FonteCaminhoShellPipe` not
12406 // `FonteCaminhoShellComment`. The pipeline-tail paste is
12407 // the load-bearing root-cause edit on every probe-as-both
12408 // value.
12409 let d = dep_with_fonte(DepSource::Path {
12410 caminho: "../caixa-teia|pin#tail".into(),
12411 });
12412 let err = d.validate().unwrap_err();
12413 assert!(
12414 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12415 "got {err:?}",
12416 );
12417 }
12418
12419 #[test]
12420 fn fonte_caminho_shell_redirection_fires_before_shell_comment() {
12421 // Cascade pin on the upstream shell-redirection arm: a
12422 // value carrying both `>` and `#` (`"../caixa-teia>log#pin"`
12423 // — the canonical "I pasted a `cmd > log` redirect followed
12424 // by a URL-fragment tail" footgun) routes through
12425 // `FonteCaminhoShellRedirection` not
12426 // `FonteCaminhoShellComment`. The input/output redirection
12427 // metachar carries the more self-locating `byte` payload,
12428 // so the prior arm wins on every probe-as-both value.
12429 let d = dep_with_fonte(DepSource::Path {
12430 caminho: "../caixa-teia>log#pin".into(),
12431 });
12432 let err = d.validate().unwrap_err();
12433 assert!(
12434 matches!(
12435 err,
12436 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12437 ),
12438 "got {err:?}",
12439 );
12440 }
12441
12442 #[test]
12443 fn fonte_caminho_backslash_fires_before_shell_comment() {
12444 // Cascade pin on the upstream backslash arm: a value
12445 // carrying both `\` and `#` (`"..\caixa-teia#pin"` — the
12446 // canonical "I pasted a Windows-shell path followed by a
12447 // URL-fragment tail" footgun) routes through
12448 // `FonteCaminhoBackslash` not `FonteCaminhoShellComment`.
12449 // The cross-host-OS-separator divergence is the load-
12450 // bearing axis on every probe-as-both value.
12451 let d = dep_with_fonte(DepSource::Path {
12452 caminho: "..\\caixa-teia#pin".into(),
12453 });
12454 let err = d.validate().unwrap_err();
12455 assert!(
12456 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12457 "got {err:?}",
12458 );
12459 }
12460
12461 #[test]
12462 fn fonte_caminho_control_char_fires_before_shell_comment() {
12463 // Cascade pin on the embedded-control-byte arm: a value
12464 // carrying both a control byte and `#` (`"../foo\n#pin"` —
12465 // the canonical paste-from-multiline-doc footgun where a
12466 // newline landed mid-caminho between the path and an
12467 // annotation) routes through `FonteCaminhoControlChar` not
12468 // `FonteCaminhoShellComment`. The POSIX-syscall-rejected-
12469 // byte diagnostic is the load-bearing axis on every value
12470 // that probes positive for both — mirrors the cascade
12471 // discipline on every prior arm.
12472 let d = dep_with_fonte(DepSource::Path {
12473 caminho: "../foo\n#pin".into(),
12474 });
12475 let err = d.validate().unwrap_err();
12476 assert!(
12477 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12478 "got {err:?}",
12479 );
12480 }
12481
12482 #[test]
12483 fn fonte_caminho_absolute_fires_before_shell_comment() {
12484 // Cascade pin on the load-bearing leading-byte arm: a
12485 // leading `/` value with embedded `#` (`"/etc/foo#pin"`)
12486 // routes through `FonteCaminhoAbsolute` not
12487 // `FonteCaminhoShellComment` — the host-layout-leak
12488 // diagnostic is the load-bearing axis, the fragment byte is
12489 // the secondary observation. Same precedence logic as every
12490 // prior leading-byte arm.
12491 let d = dep_with_fonte(DepSource::Path {
12492 caminho: "/etc/foo#pin".into(),
12493 });
12494 let err = d.validate().unwrap_err();
12495 assert!(
12496 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12497 "got {err:?}",
12498 );
12499 }
12500
12501 #[test]
12502 fn fonte_caminho_var_expansion_fires_before_shell_comment() {
12503 // Cascade pin on the upstream leading-`$` var-expansion
12504 // arm: a value carrying both a leading `$` and a `#`
12505 // (`"$DIR/foo#pin"` — the canonical "I pasted a `$DIR`
12506 // shell-variable at the head of a sibling-workspace path
12507 // followed by a URL-fragment tail" footgun) routes through
12508 // `FonteCaminhoVarExpansion` not `FonteCaminhoShellComment`.
12509 // The leading-byte shell-variable-expansion is the more
12510 // self-locating diagnostic on values that probe as both.
12511 let d = dep_with_fonte(DepSource::Path {
12512 caminho: "$DIR/foo#pin".into(),
12513 });
12514 let err = d.validate().unwrap_err();
12515 assert!(
12516 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12517 "got {err:?}",
12518 );
12519 }
12520
12521 #[test]
12522 fn fonte_caminho_shell_comment_fires_before_trailing_slash() {
12523 // Cascade pin on the immediate-successor arm: a value
12524 // carrying both `#` and a trailing `/`
12525 // (`"../caixa-teia#pin/"` — the canonical "I tab-completed
12526 // a URL-fragment-carrying path" footgun) routes through
12527 // `FonteCaminhoShellComment` not
12528 // `FonteCaminhoTrailingSlash`. The embedded fragment /
12529 // comment-lead byte is the more semantic-locating axis (an
12530 // author who removes the `#pin` fragment typically also
12531 // drops the trailing separator since both are paste-from-
12532 // URL / paste-from-shell-tab-completion artifacts).
12533 let d = dep_with_fonte(DepSource::Path {
12534 caminho: "../caixa-teia#pin/".into(),
12535 });
12536 let err = d.validate().unwrap_err();
12537 assert!(
12538 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. },),
12539 "got {err:?}",
12540 );
12541 }
12542
12543 #[test]
12544 fn fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte() {
12545 // Diagnostic-shape pin (peer with
12546 // `fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
12547 // on the immediate-predecessor arm): the error's Display
12548 // surfaces the offending `:nome`, the offending `:caminho`
12549 // verbatim, the offending byte's hex / character form, and
12550 // names the shell-comment / URL-fragment-identifier /
12551 // YAML-comment cross-config-DSL footgun explicitly so a
12552 // `feira lint` run can render the diagnostic without
12553 // re-parsing.
12554 let d = dep_with_fonte(DepSource::Path {
12555 caminho: "../caixa-teia#readme".into(),
12556 });
12557 let rendered = d.validate().unwrap_err().to_string();
12558 assert!(
12559 rendered.contains("caixa-teia"),
12560 "diagnostic must name the offending dep: {rendered}",
12561 );
12562 assert!(
12563 rendered.contains("../caixa-teia#readme"),
12564 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12565 );
12566 assert!(
12567 rendered.contains("0x23"),
12568 "diagnostic must surface the offending byte hex: {rendered:?}",
12569 );
12570 assert!(
12571 rendered.contains("shell-comment") || rendered.contains("comment-lead"),
12572 "diagnostic must name the shell-comment footgun: {rendered:?}",
12573 );
12574 assert!(
12575 rendered.contains("fragment") || rendered.contains("URL-fragment"),
12576 "diagnostic must reference the URL-fragment-identifier vocabulary: \
12577 {rendered:?}",
12578 );
12579 }
12580
12581 #[test]
12582 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_space() {
12583 // The canonical paste-from-browser-address-bar percent-
12584 // encoded-space footgun: an author copies `../caixa%20teia`
12585 // out of a URL-encoded README hyperlink / browser address
12586 // bar / percent-encoded permalink expecting `%20` to decode
12587 // to a literal space at the filesystem layer. POSIX
12588 // `std::path::Path` treats `%` as a literal path-component
12589 // byte, so `Path::join` looks for a literal
12590 // `./../caixa%20teia` subdirectory. `Path::is_absolute`
12591 // returns false on `..`, `%` is neither a leading-byte
12592 // sentinel nor a control byte nor `\` nor `<` / `>` nor
12593 // `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` /
12594 // `)` nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`,
12595 // and the value's last byte isn't `/` — so the value
12596 // silently passed every prior arm. The new arm moves the
12597 // rejection to validate time and names the offending dep +
12598 // caminho + byte verbatim.
12599 let d = dep_with_fonte(DepSource::Path {
12600 caminho: "../caixa%20teia".into(),
12601 });
12602 let err = d.validate().unwrap_err();
12603 let DepError::FonteCaminhoUrlPercentEncoding {
12604 nome,
12605 caminho,
12606 byte,
12607 } = err
12608 else {
12609 panic!("expected FonteCaminhoUrlPercentEncoding, got {err:?}");
12610 };
12611 assert_eq!(nome, "caixa-teia");
12612 assert_eq!(caminho, "../caixa%20teia");
12613 assert_eq!(byte, b'%');
12614 }
12615
12616 #[test]
12617 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_slash() {
12618 // The over-encoded path-separator shape (`"../caixa%2Fteia"`
12619 // intending the `%2F` as the URL encoding of `/`) locks a
12620 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
12621 // the byte-identical `path:../caixa/teia` form. Pinned
12622 // separately from the space-encoded shape so the gate's
12623 // coverage extends past the single canonical `%20` example
12624 // to any two-hex-digit percent-encoded sequence.
12625 let d = dep_with_fonte(DepSource::Path {
12626 caminho: "../caixa%2Fteia".into(),
12627 });
12628 let err = d.validate().unwrap_err();
12629 assert!(
12630 matches!(
12631 err,
12632 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12633 ),
12634 "got {err:?}",
12635 );
12636 }
12637
12638 #[test]
12639 fn validate_rejects_path_fonte_with_caminho_carrying_lone_percent() {
12640 // The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
12641 // where `%` isn't followed by two hex digits) — every
12642 // WHATWG-conformant URL parser rejects the value at parse
12643 // time per RFC 3986 §2.1, but the byte would silently ride
12644 // into the lacre before the resolver subprocess crosses the
12645 // URL-parser boundary. Pinned separately from the well-
12646 // formed `%HH` shapes so the gate covers every percent-
12647 // occurrence, not only strictly-conformant escapes.
12648 let d = dep_with_fonte(DepSource::Path {
12649 caminho: "../caixa-teia%foo".into(),
12650 });
12651 let err = d.validate().unwrap_err();
12652 assert!(
12653 matches!(
12654 err,
12655 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12656 ),
12657 "got {err:?}",
12658 );
12659 }
12660
12661 #[test]
12662 fn validate_rejects_path_fonte_with_caminho_carrying_leading_yaml_directive() {
12663 // The YAML-directive-lead paste shape (`"%YAML/../caixa-teia"`
12664 // — the canonical paste-from-top-of-doc YAML directive
12665 // block cross-idiom leak per YAML 1.2 §6.8.1). Pinned
12666 // separately from embedded shapes so the gate covers the
12667 // leading-position `%` too, not only mid-value occurrences.
12668 let d = dep_with_fonte(DepSource::Path {
12669 caminho: "%YAML/../caixa-teia".into(),
12670 });
12671 let err = d.validate().unwrap_err();
12672 assert!(
12673 matches!(
12674 err,
12675 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12676 ),
12677 "got {err:?}",
12678 );
12679 }
12680
12681 #[test]
12682 fn validate_rejects_path_fonte_with_caminho_carrying_printf_format_specifier() {
12683 // The printf-format-specifier paste shape
12684 // (`"../caixa-%s-teia"` — the canonical paste-from-shell-
12685 // diagnostic-one-liner `printf "path=%s\n" ...` idiom, CWE-
12686 // 134 format-string-injection vector). Pinned separately
12687 // from the URL-encoding shapes so the gate's rationale
12688 // extends past the RFC 3986 axis to the C / POSIX printf
12689 // format-directive-lead axis.
12690 let d = dep_with_fonte(DepSource::Path {
12691 caminho: "../caixa-%s-teia".into(),
12692 });
12693 let err = d.validate().unwrap_err();
12694 assert!(
12695 matches!(
12696 err,
12697 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12698 ),
12699 "got {err:?}",
12700 );
12701 }
12702
12703 #[test]
12704 fn validate_accepts_path_fonte_with_caminho_carrying_no_percent() {
12705 // The positive-control pin: the gate targets only `%`,
12706 // never adjacent printable ASCII or POSIX-valid bytes. The
12707 // canonical relative POSIX path (`"../caixa-teia"`) and a
12708 // nested deeply-pathed variant with adjacent printable
12709 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12710 // to validate cleanly so the gate doesn't widen to a "no
12711 // printable punctuation anywhere" sweep that would defeat
12712 // the entire path-fonte author surface. Peer with
12713 // `validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment`
12714 // on the immediate-predecessor arm.
12715 let d = dep_with_fonte(DepSource::Path {
12716 caminho: "../caixa-teia/sub-dir.v2".into(),
12717 });
12718 d.validate().unwrap();
12719 }
12720
12721 #[test]
12722 fn fonte_caminho_shell_comment_fires_before_url_percent_encoding() {
12723 // Cascade pin on the immediate-predecessor arm: a value
12724 // carrying both `#` and `%` (`"../caixa-teia#pin%20"` — the
12725 // canonical "I pasted a URL-fragment permalink followed by a
12726 // percent-encoded space tail" footgun) routes through
12727 // `FonteCaminhoShellComment` not
12728 // `FonteCaminhoUrlPercentEncoding`. The URL-fragment-
12729 // identifier is the load-bearing downstream-truncation edit
12730 // on every probe-as-both value; same cascade discipline
12731 // every prior `:caminho` arm establishes.
12732 let d = dep_with_fonte(DepSource::Path {
12733 caminho: "../caixa-teia#pin%20".into(),
12734 });
12735 let err = d.validate().unwrap_err();
12736 assert!(
12737 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12738 "got {err:?}",
12739 );
12740 }
12741
12742 #[test]
12743 fn fonte_caminho_shell_quote_grouping_fires_before_url_percent_encoding() {
12744 // Cascade pin on the upstream shell-quote-grouping arm: a
12745 // value carrying both `'` and `%` (`"../'x'%20teia"` — the
12746 // canonical "I pasted a strong-quoted literal followed by
12747 // a percent-encoded space" footgun) routes through
12748 // `FonteCaminhoShellQuoteGrouping` not
12749 // `FonteCaminhoUrlPercentEncoding`. The shell-string-
12750 // literal-delimiter is the load-bearing root-cause edit on
12751 // every probe-as-both value.
12752 let d = dep_with_fonte(DepSource::Path {
12753 caminho: "../'x'%20teia".into(),
12754 });
12755 let err = d.validate().unwrap_err();
12756 assert!(
12757 matches!(
12758 err,
12759 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12760 ),
12761 "got {err:?}",
12762 );
12763 }
12764
12765 #[test]
12766 fn fonte_caminho_backslash_fires_before_url_percent_encoding() {
12767 // Cascade pin on the upstream backslash arm: a value
12768 // carrying both `\` and `%` (`"..\\caixa%20teia"` — the
12769 // canonical "I pasted a Windows-shell path followed by a
12770 // percent-encoded space" footgun) routes through
12771 // `FonteCaminhoBackslash` not
12772 // `FonteCaminhoUrlPercentEncoding`. The cross-host-OS-
12773 // separator divergence is the load-bearing root-cause edit
12774 // on every probe-as-both value.
12775 let d = dep_with_fonte(DepSource::Path {
12776 caminho: "..\\caixa%20teia".into(),
12777 });
12778 let err = d.validate().unwrap_err();
12779 assert!(
12780 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12781 "got {err:?}",
12782 );
12783 }
12784
12785 #[test]
12786 fn fonte_caminho_control_char_fires_before_url_percent_encoding() {
12787 // Cascade pin on the upstream control-char arm: a value
12788 // carrying both a NUL byte and `%` (`"../caixa\0%20teia"` —
12789 // the canonical "I pasted a paste-from-binary-blob path
12790 // followed by a percent-encoded space" footgun) routes
12791 // through `FonteCaminhoControlChar` not
12792 // `FonteCaminhoUrlPercentEncoding`. The POSIX-syscall-
12793 // rejected byte is the load-bearing root-cause edit on
12794 // every probe-as-both value.
12795 let d = dep_with_fonte(DepSource::Path {
12796 caminho: "../caixa\0%20teia".into(),
12797 });
12798 let err = d.validate().unwrap_err();
12799 assert!(
12800 matches!(err, DepError::FonteCaminhoControlChar { byte: 0x00, .. },),
12801 "got {err:?}",
12802 );
12803 }
12804
12805 #[test]
12806 fn fonte_caminho_absolute_fires_before_url_percent_encoding() {
12807 // Cascade pin on the upstream absolute-path arm: a value
12808 // that's both absolute and carries `%` (`"/etc/passwd%20"`
12809 // — the canonical "I pasted an absolute path with a
12810 // percent-encoded space tail" footgun) routes through
12811 // `FonteCaminhoAbsolute` not
12812 // `FonteCaminhoUrlPercentEncoding`. The host-layout-leak is
12813 // the load-bearing root-cause edit on every probe-as-both
12814 // value.
12815 let d = dep_with_fonte(DepSource::Path {
12816 caminho: "/etc/passwd%20".into(),
12817 });
12818 let err = d.validate().unwrap_err();
12819 assert!(
12820 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12821 "got {err:?}",
12822 );
12823 }
12824
12825 #[test]
12826 fn fonte_caminho_var_expansion_fires_before_url_percent_encoding() {
12827 // Cascade pin on the upstream var-expansion arm: a value
12828 // starting with `$` and carrying `%` (`"$HOME/caixa%20teia"`
12829 // — the canonical "I pasted a `$HOME`-rooted path with a
12830 // percent-encoded space" footgun) routes through
12831 // `FonteCaminhoVarExpansion` not
12832 // `FonteCaminhoUrlPercentEncoding`. The shell-variable-
12833 // expansion is the load-bearing root-cause edit on every
12834 // probe-as-both value.
12835 let d = dep_with_fonte(DepSource::Path {
12836 caminho: "$HOME/caixa%20teia".into(),
12837 });
12838 let err = d.validate().unwrap_err();
12839 assert!(
12840 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12841 "got {err:?}",
12842 );
12843 }
12844
12845 #[test]
12846 fn fonte_caminho_url_percent_encoding_fires_before_trailing_slash() {
12847 // Cascade pin on the immediate-successor arm: a value
12848 // carrying both `%` and a trailing `/`
12849 // (`"../caixa%20teia/"` — the canonical "I tab-completed a
12850 // percent-encoded-space-carrying path" footgun) routes
12851 // through `FonteCaminhoUrlPercentEncoding` not
12852 // `FonteCaminhoTrailingSlash`. The embedded percent-
12853 // encoding-escape byte is the more semantic-locating axis
12854 // (an author who decodes the `%20` to a literal space is
12855 // likely to also tab-strip the trailing separator since
12856 // both are paste-from-URL / paste-from-shell-tab-completion
12857 // artifacts).
12858 let d = dep_with_fonte(DepSource::Path {
12859 caminho: "../caixa%20teia/".into(),
12860 });
12861 let err = d.validate().unwrap_err();
12862 assert!(
12863 matches!(
12864 err,
12865 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12866 ),
12867 "got {err:?}",
12868 );
12869 }
12870
12871 #[test]
12872 fn fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte() {
12873 // Diagnostic-shape pin (peer with
12874 // `fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte`
12875 // on the immediate-predecessor arm): the error's Display
12876 // surfaces the offending `:nome`, the offending `:caminho`
12877 // verbatim, the offending byte's hex / character form, and
12878 // names the URL-percent-encoding-escape / printf-format-
12879 // specifier footgun explicitly so a `feira lint` run can
12880 // render the diagnostic without re-parsing.
12881 let d = dep_with_fonte(DepSource::Path {
12882 caminho: "../caixa%20teia".into(),
12883 });
12884 let rendered = d.validate().unwrap_err().to_string();
12885 assert!(
12886 rendered.contains("caixa-teia"),
12887 "diagnostic must name the offending dep: {rendered}",
12888 );
12889 assert!(
12890 rendered.contains("../caixa%20teia"),
12891 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12892 );
12893 assert!(
12894 rendered.contains("0x25"),
12895 "diagnostic must surface the offending byte hex: {rendered:?}",
12896 );
12897 assert!(
12898 rendered.contains("percent-encoding") || rendered.contains("percent-encoded"),
12899 "diagnostic must name the URL-percent-encoding-escape footgun: {rendered:?}",
12900 );
12901 assert!(
12902 rendered.contains("printf") || rendered.contains("format-specifier"),
12903 "diagnostic must reference the printf-format-specifier vocabulary: \
12904 {rendered:?}",
12905 );
12906 }
12907
12908 #[test]
12909 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_var_expansion() {
12910 // The canonical embedded-`$` shell-variable-expansion paste
12911 // shape (`"../foo$HOME/bar"` — an author copies a partially-
12912 // substituted shell one-liner where the leading segment is a
12913 // literal `../foo` while the mid segment carries the un-
12914 // substituted `$HOME` template). The leading-`$` position is
12915 // already gated by the f4efe9c leading-byte arm which routes
12916 // through `FonteCaminhoVarExpansion`; this arm closes the
12917 // last positional gap on `$` — every position on the axis is
12918 // structurally rejected.
12919 let d = dep_with_fonte(DepSource::Path {
12920 caminho: "../foo$HOME/bar".into(),
12921 });
12922 let err = d.validate().unwrap_err();
12923 let DepError::FonteCaminhoShellVariableExpansion {
12924 nome,
12925 caminho,
12926 byte,
12927 } = err
12928 else {
12929 panic!("expected FonteCaminhoShellVariableExpansion, got {err:?}");
12930 };
12931 assert_eq!(nome, "caixa-teia");
12932 assert_eq!(caminho, "../foo$HOME/bar");
12933 assert_eq!(byte, b'$');
12934 }
12935
12936 #[test]
12937 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_braced_var_expansion() {
12938 // The symmetric braced-CI-manifest paste shape
12939 // (`"../foo${WORKSPACE}/bar"` — the canonical paste-from-
12940 // GitHub-Actions-workflow / paste-from-`.gitlab-ci.yml`
12941 // footgun). Pinned separately from the bare-`$VAR` shape so
12942 // the gate covers both POSIX shell §2.6 Parameter Expansion
12943 // syntactic forms, not only the unbraced variant. The
12944 // embedded `{` byte in `${...}` is also caught by the 598b770
12945 // shell-brace-expansion arm but that arm fires earlier in
12946 // the cascade — the `$` arm's coverage extends to `${...}`
12947 // structurally, so the diagnostic asserted here is the
12948 // brace-expansion one (which is a valid outcome; the point
12949 // of the pin is that the value never survives validation).
12950 let d = dep_with_fonte(DepSource::Path {
12951 caminho: "../foo${WORKSPACE}/bar".into(),
12952 });
12953 let err = d.validate().unwrap_err();
12954 assert!(
12955 matches!(
12956 err,
12957 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. }
12958 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12959 ),
12960 "got {err:?}",
12961 );
12962 }
12963
12964 #[test]
12965 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_command_substitution() {
12966 // The paste-from-shell-prompt command-substitution idiom
12967 // (`"../foo$(whoami)/bar"`). Pinned separately from the bare-
12968 // `$VAR` shape so the gate's rationale extends to POSIX shell
12969 // §2.6.3 Command Substitution (the modern `$(<cmd>)` form; the
12970 // legacy `` `<cmd>` `` form is already closed by the c370458
12971 // backtick arm). The embedded `(` byte in `$(...)` is also
12972 // caught structurally by the 0633c91 shell-subshell-grouping
12973 // arm which fires earlier in the cascade — the diagnostic
12974 // asserted here is either outcome, since both structurally
12975 // reject the value; the point of the pin is that the value
12976 // never survives validation.
12977 let d = dep_with_fonte(DepSource::Path {
12978 caminho: "../foo$(whoami)/bar".into(),
12979 });
12980 let err = d.validate().unwrap_err();
12981 assert!(
12982 matches!(
12983 err,
12984 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. }
12985 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
12986 ),
12987 "got {err:?}",
12988 );
12989 }
12990
12991 #[test]
12992 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_positional_parameter() {
12993 // The paste-from-`Makefile` / paste-from-SQL-migration bare-
12994 // `$1` positional-parameter shape (`"../foo$1/bar"` — a Make
12995 // automatic-variable `$1` or a PostgreSQL bind-parameter `$1`
12996 // idiom copied into a caminho template). None of the prior
12997 // shell-metachar arms cover this shape (`1` is a bare digit;
12998 // no `(` / `{` / letter follows the `$`), so the arm is the
12999 // sole gate on the shape.
13000 let d = dep_with_fonte(DepSource::Path {
13001 caminho: "../foo$1/bar".into(),
13002 });
13003 let err = d.validate().unwrap_err();
13004 assert!(
13005 matches!(
13006 err,
13007 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13008 ),
13009 "got {err:?}",
13010 );
13011 }
13012
13013 #[test]
13014 fn validate_accepts_path_fonte_with_caminho_carrying_no_dollar() {
13015 // The positive-control pin (peer with
13016 // `validate_accepts_path_fonte_with_caminho_carrying_no_percent`
13017 // on the immediate-predecessor arm): the gate targets only
13018 // `$`, never adjacent printable ASCII or POSIX-valid bytes.
13019 // A relative POSIX path carrying dashes / dots / slashes /
13020 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13021 // validate cleanly so the gate doesn't widen to a "no
13022 // printable punctuation anywhere" sweep that would defeat
13023 // the entire path-fonte author surface.
13024 let d = dep_with_fonte(DepSource::Path {
13025 caminho: "../caixa-teia/sub-dir.v2".into(),
13026 });
13027 d.validate().unwrap();
13028 }
13029
13030 #[test]
13031 fn fonte_caminho_var_expansion_fires_before_shell_variable_expansion() {
13032 // Cascade pin on the leading-`$` sibling arm at line 540: a
13033 // value starting with `$` and carrying an embedded `$` too
13034 // (`"$HOME/foo$WORKSPACE/bar"` — the canonical "I pasted a
13035 // fully-templated CI path with two un-substituted variables")
13036 // routes through `FonteCaminhoVarExpansion` not
13037 // `FonteCaminhoShellVariableExpansion`. The leading-byte
13038 // host-layout-leak is the load-bearing self-locating axis
13039 // (the leading position dominates the semantic-locating
13040 // rationale on every probe-as-both value); the embedded
13041 // arm's positional-agnostic sweep catches only values whose
13042 // leading byte doesn't route through the earlier leading-
13043 // byte arms.
13044 let d = dep_with_fonte(DepSource::Path {
13045 caminho: "$HOME/foo$WORKSPACE/bar".into(),
13046 });
13047 let err = d.validate().unwrap_err();
13048 assert!(
13049 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
13050 "got {err:?}",
13051 );
13052 }
13053
13054 #[test]
13055 fn fonte_caminho_url_percent_encoding_fires_before_shell_variable_expansion() {
13056 // Cascade pin on the immediate-predecessor arm: a value
13057 // carrying both `%` and embedded `$` (`"../foo%20$HOME/bar"`
13058 // — the canonical "I pasted a percent-encoded space adjacent
13059 // to a `$HOME` template") routes through
13060 // `FonteCaminhoUrlPercentEncoding` not
13061 // `FonteCaminhoShellVariableExpansion`. The URL-percent-
13062 // encoding-escape byte is the more semantic-locating axis
13063 // (the paste-from-browser-address-bar shape is the load-
13064 // bearing self-locating edit); same cascade discipline every
13065 // prior `:caminho` arm establishes.
13066 let d = dep_with_fonte(DepSource::Path {
13067 caminho: "../foo%20$HOME/bar".into(),
13068 });
13069 let err = d.validate().unwrap_err();
13070 assert!(
13071 matches!(
13072 err,
13073 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13074 ),
13075 "got {err:?}",
13076 );
13077 }
13078
13079 #[test]
13080 fn fonte_caminho_shell_variable_expansion_fires_before_trailing_slash() {
13081 // Cascade pin on the immediate-successor arm: a value
13082 // carrying both embedded `$` and a trailing `/`
13083 // (`"../foo$HOME/bar/"` — the canonical "I tab-completed a
13084 // `$HOME`-template-carrying path") routes through
13085 // `FonteCaminhoShellVariableExpansion` not
13086 // `FonteCaminhoTrailingSlash`. The embedded shell-variable-
13087 // expansion byte is the more semantic-locating axis on
13088 // probe-as-both values (an author who substitutes the
13089 // `$HOME` template with a literal value is likely to also
13090 // tab-strip the trailing separator).
13091 let d = dep_with_fonte(DepSource::Path {
13092 caminho: "../foo$HOME/bar/".into(),
13093 });
13094 let err = d.validate().unwrap_err();
13095 assert!(
13096 matches!(
13097 err,
13098 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13099 ),
13100 "got {err:?}",
13101 );
13102 }
13103
13104 #[test]
13105 fn fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13106 // Diagnostic-shape pin (peer with
13107 // `fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte`
13108 // on the immediate-predecessor arm): the error's Display
13109 // surfaces the offending `:nome`, the offending `:caminho`
13110 // verbatim, the offending byte's hex / character form, and
13111 // names the shell-variable-expansion / command-substitution
13112 // footgun explicitly so a `feira lint` run can render the
13113 // diagnostic without re-parsing.
13114 let d = dep_with_fonte(DepSource::Path {
13115 caminho: "../foo$HOME/bar".into(),
13116 });
13117 let rendered = d.validate().unwrap_err().to_string();
13118 assert!(
13119 rendered.contains("caixa-teia"),
13120 "diagnostic must name the offending dep: {rendered}",
13121 );
13122 assert!(
13123 rendered.contains("../foo$HOME/bar"),
13124 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13125 );
13126 assert!(
13127 rendered.contains("0x24"),
13128 "diagnostic must surface the offending byte hex: {rendered:?}",
13129 );
13130 assert!(
13131 rendered.contains("variable-expansion") || rendered.contains("variable expansion"),
13132 "diagnostic must name the shell-variable-expansion footgun: {rendered:?}",
13133 );
13134 assert!(
13135 rendered.contains("command-substitution") || rendered.contains("command substitution"),
13136 "diagnostic must reference the command-substitution vocabulary: {rendered:?}",
13137 );
13138 }
13139
13140 #[test]
13141 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_expansion() {
13142 // The fail-before-pass-after pin for the canonical paste-from-
13143 // shell-history footgun on `:caminho`. An author copies a `cd
13144 // ../caixa-teia && !sudo make install` one-liner from a quick-
13145 // start README, intending the trailing `!sudo` as a shell-
13146 // history-expansion reference but the typed slot is itself a
13147 // byte-level string parser, not a shell context, so the byte
13148 // rides into the value verbatim. Until this arm landed the `!`
13149 // byte silently passed every prior `:caminho` cascade arm
13150 // (`!` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick /
13151 // `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` /
13152 // `#` / `%` / `$`); bash with the default `histexpand` mode
13153 // rewrites `!command` to the most recent history entry
13154 // beginning with `command`, the canonical RCE-class injection
13155 // vector when the byte rides into a shell argument executed
13156 // under `bash -i` (the operator-notebook interactive shell).
13157 let d = dep_with_fonte(DepSource::Path {
13158 caminho: "../caixa-teia!sudo".into(),
13159 });
13160 let err = d.validate().unwrap_err();
13161 let DepError::FonteCaminhoShellHistoryExpansion {
13162 nome,
13163 caminho,
13164 byte,
13165 } = err
13166 else {
13167 panic!("expected FonteCaminhoShellHistoryExpansion, got {err:?}");
13168 };
13169 assert_eq!(nome, "caixa-teia");
13170 assert_eq!(caminho, "../caixa-teia!sudo");
13171 assert_eq!(byte, b'!');
13172 }
13173
13174 #[test]
13175 fn validate_rejects_path_fonte_with_caminho_carrying_double_bang_history_reference() {
13176 // The symmetric `!!` repeat-prior-command paste idiom (peer with
13177 // `validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference`
13178 // on `is_git_repo_url`). Pinned separately from the wrapped
13179 // `!command` shape so a future diagnostic-surface change that
13180 // only checked the leading or paired-bang position surfaces
13181 // here — the per-byte arm fires anywhere `!` appears in the
13182 // value, including at consecutive positions in the middle.
13183 let d = dep_with_fonte(DepSource::Path {
13184 caminho: "../foo!!/bar".into(),
13185 });
13186 let err = d.validate().unwrap_err();
13187 assert!(
13188 matches!(
13189 err,
13190 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13191 ),
13192 "got {err:?}",
13193 );
13194 }
13195
13196 #[test]
13197 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_enthusiasm_bang() {
13198 // The English-typography enthusiasm-form paste-from-prose
13199 // idiom: an author writes `:caminho "../caixa-teia!"`
13200 // expecting the substrate to coerce it to a kebab-case slug.
13201 // Pinned separately from the `!<word>` shell-history shape so
13202 // the gate's rationale extends to the paste-from-prose surface
13203 // (the same rationale the peer `is_git_repo_url` bang arm at
13204 // 7d53c68 covers). None of the prior shell-metachar arms cover
13205 // this shape (no `!<word>` reference and no `!!` repeat), so
13206 // the arm is the sole gate on the shape.
13207 let d = dep_with_fonte(DepSource::Path {
13208 caminho: "../caixa-teia!".into(),
13209 });
13210 let err = d.validate().unwrap_err();
13211 assert!(
13212 matches!(
13213 err,
13214 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13215 ),
13216 "got {err:?}",
13217 );
13218 }
13219
13220 #[test]
13221 fn validate_accepts_path_fonte_with_caminho_carrying_no_bang() {
13222 // The positive-control pin (peer with
13223 // `validate_accepts_path_fonte_with_caminho_carrying_no_dollar`
13224 // on the immediate-predecessor arm): the gate targets only
13225 // `!`, never adjacent printable ASCII or POSIX-valid bytes.
13226 // A relative POSIX path carrying dashes / dots / slashes /
13227 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13228 // validate cleanly so the gate doesn't widen to a "no
13229 // printable punctuation anywhere" sweep that would defeat
13230 // the entire path-fonte author surface.
13231 let d = dep_with_fonte(DepSource::Path {
13232 caminho: "../caixa-teia/sub-dir.v2".into(),
13233 });
13234 d.validate().unwrap();
13235 }
13236
13237 #[test]
13238 fn fonte_caminho_shell_variable_expansion_fires_before_shell_history_expansion() {
13239 // Cascade pin on the immediate-predecessor arm: a value
13240 // carrying both embedded `$` and `!` (`"../foo$HOME/bar!sudo"`
13241 // — the canonical "I pasted a `$HOME`-templated path adjacent
13242 // to a trailing `!sudo` history-expansion") routes through
13243 // `FonteCaminhoShellVariableExpansion` not
13244 // `FonteCaminhoShellHistoryExpansion`. The shell-variable-
13245 // expansion byte is the more semantic-locating axis on
13246 // probe-as-both values (the paste-from-CI-manifest-with-`$VAR`-
13247 // template shape is the load-bearing self-locating edit);
13248 // same cascade discipline every prior `:caminho` arm
13249 // establishes.
13250 let d = dep_with_fonte(DepSource::Path {
13251 caminho: "../foo$HOME/bar!sudo".into(),
13252 });
13253 let err = d.validate().unwrap_err();
13254 assert!(
13255 matches!(
13256 err,
13257 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13258 ),
13259 "got {err:?}",
13260 );
13261 }
13262
13263 #[test]
13264 fn fonte_caminho_shell_history_expansion_fires_before_trailing_slash() {
13265 // Cascade pin on the immediate-successor arm: a value carrying
13266 // both embedded `!` and a trailing `/` (`"../caixa-teia!sudo/"`
13267 // — the canonical "I tab-completed a `!sudo`-carrying path")
13268 // routes through `FonteCaminhoShellHistoryExpansion` not
13269 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13270 // expansion byte is the more semantic-locating axis on probe-
13271 // as-both values (an author who removes the `!sudo` history
13272 // reference is likely to also tab-strip the trailing separator).
13273 let d = dep_with_fonte(DepSource::Path {
13274 caminho: "../caixa-teia!sudo/".into(),
13275 });
13276 let err = d.validate().unwrap_err();
13277 assert!(
13278 matches!(
13279 err,
13280 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13281 ),
13282 "got {err:?}",
13283 );
13284 }
13285
13286 #[test]
13287 fn fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13288 // Diagnostic-shape pin (peer with
13289 // `fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13290 // on the immediate-predecessor arm): the error's Display
13291 // surfaces the offending `:nome`, the offending `:caminho`
13292 // verbatim, the offending byte's hex / character form, and
13293 // names the shell-history-expansion / bang-operator footgun
13294 // explicitly so a `feira lint` run can render the diagnostic
13295 // without re-parsing.
13296 let d = dep_with_fonte(DepSource::Path {
13297 caminho: "../caixa-teia!sudo".into(),
13298 });
13299 let rendered = d.validate().unwrap_err().to_string();
13300 assert!(
13301 rendered.contains("caixa-teia"),
13302 "diagnostic must name the offending dep: {rendered}",
13303 );
13304 assert!(
13305 rendered.contains("../caixa-teia!sudo"),
13306 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13307 );
13308 assert!(
13309 rendered.contains("0x21"),
13310 "diagnostic must surface the offending byte hex: {rendered:?}",
13311 );
13312 assert!(
13313 rendered.contains("history-expansion") || rendered.contains("history expansion"),
13314 "diagnostic must name the shell-history-expansion footgun: {rendered:?}",
13315 );
13316 assert!(
13317 rendered.contains("bang"),
13318 "diagnostic must reference the bang-operator vocabulary: {rendered:?}",
13319 );
13320 }
13321
13322 #[test]
13323 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_substitution() {
13324 // The fail-before-pass-after pin for the canonical paste-from-
13325 // shell-history-quick-substitution footgun on `:caminho`. An
13326 // author copies a `git clone <bad-url>` line from their terminal,
13327 // corrects it via bash's `^bad^good` quick-substitution history
13328 // operator (bash reference §9.3, `set -o histexpand` mode's
13329 // default for interactive sessions), and pastes the trailing
13330 // `^bad^good` substitution fragment into a `:caminho` value
13331 // without trimming the leading `git clone` prefix — the byte
13332 // rides into the manifest verbatim. Until this arm landed the
13333 // `^` byte silently passed every prior `:caminho` cascade arm
13334 // (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick / `*`
13335 // / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` / `#` /
13336 // `%` / `$` / `!`); bash with the default `histexpand` mode
13337 // rewrites the prior command's `bad` string to `good` and re-
13338 // executes it, the paired-operator half of the `set -o
13339 // histexpand` feature the peer `!` arm already closes the prefix
13340 // half of. The peer `is_git_repo_url` axis rejects the byte at
13341 // 49e142f under the same shell-history-substitution / RFC-3986-
13342 // unwise banner.
13343 let d = dep_with_fonte(DepSource::Path {
13344 caminho: "../foo^bad^good".into(),
13345 });
13346 let err = d.validate().unwrap_err();
13347 let DepError::FonteCaminhoShellHistorySubstitution {
13348 nome,
13349 caminho,
13350 byte,
13351 } = err
13352 else {
13353 panic!("expected FonteCaminhoShellHistorySubstitution, got {err:?}");
13354 };
13355 assert_eq!(nome, "caixa-teia");
13356 assert_eq!(caminho, "../foo^bad^good");
13357 assert_eq!(byte, b'^');
13358 }
13359
13360 #[test]
13361 fn validate_rejects_path_fonte_with_caminho_carrying_regex_negation_anchor() {
13362 // The symmetric paste-from-doc-grep-pipeline footgun (peer with
13363 // `validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor`
13364 // on `is_git_repo_url`). An author copies a `grep '^archived'`
13365 // regex-anchor / negation idiom from a doc snippet and the byte
13366 // rides in verbatim. Pinned separately from the `^old^new^`
13367 // quick-substitution shape so a future diagnostic-surface change
13368 // that only checked the paired-caret history-substitution
13369 // position surfaces here — the per-byte arm fires anywhere `^`
13370 // appears in the value, including at a solitary leading-of-
13371 // segment position.
13372 let d = dep_with_fonte(DepSource::Path {
13373 caminho: "../foo/^archived".into(),
13374 });
13375 let err = d.validate().unwrap_err();
13376 assert!(
13377 matches!(
13378 err,
13379 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13380 ),
13381 "got {err:?}",
13382 );
13383 }
13384
13385 #[test]
13386 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_history_substitution_open() {
13387 // The trailing-`^` history-substitution-open shape — an author
13388 // starts typing a `^bad^good` quick-substitution but pastes only
13389 // the leading `^` sentinel before context-switching (a bash-
13390 // reference §9.3 valid histexpand prefix on its own — even a
13391 // solitary `^` on the prior command's whole re-execution shape).
13392 // Pinned separately from the `^old^new^` full-form and the leading-
13393 // of-segment `^archived` regex-anchor shape so the gate's
13394 // rationale extends to the paste-from-shell-history-with-only-
13395 // the-first-byte-selected surface. None of the prior shell-
13396 // metachar arms cover this shape.
13397 let d = dep_with_fonte(DepSource::Path {
13398 caminho: "../caixa-teia^".into(),
13399 });
13400 let err = d.validate().unwrap_err();
13401 assert!(
13402 matches!(
13403 err,
13404 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13405 ),
13406 "got {err:?}",
13407 );
13408 }
13409
13410 #[test]
13411 fn validate_accepts_path_fonte_with_caminho_carrying_no_caret() {
13412 // The positive-control pin (peer with
13413 // `validate_accepts_path_fonte_with_caminho_carrying_no_bang`
13414 // on the immediate-predecessor arm): the gate targets only
13415 // `^`, never adjacent printable ASCII or POSIX-valid bytes.
13416 // A relative POSIX path carrying dashes / dots / slashes /
13417 // digits / underscore (`"../caixa-teia/sub_v2.rc"`) must
13418 // continue to validate cleanly so the gate doesn't widen to
13419 // a "no printable punctuation anywhere" sweep that would
13420 // defeat the entire path-fonte author surface.
13421 let d = dep_with_fonte(DepSource::Path {
13422 caminho: "../caixa-teia/sub_v2.rc".into(),
13423 });
13424 d.validate().unwrap();
13425 }
13426
13427 #[test]
13428 fn fonte_caminho_shell_history_expansion_fires_before_shell_history_substitution() {
13429 // Cascade pin on the immediate-predecessor arm: a value carrying
13430 // both embedded `!` and `^` (`"../foo!sudo^bad^good"` — the
13431 // canonical "I pasted a `!sudo` history-reference next to a
13432 // `^bad^good` quick-substitution") routes through
13433 // `FonteCaminhoShellHistoryExpansion` not
13434 // `FonteCaminhoShellHistorySubstitution`. The `!` prefix form is
13435 // the more semantic-locating axis on probe-as-both values (an
13436 // author who removes the `!sudo` reference is likely to also
13437 // strip the paired `^` substitution fragment); same cascade
13438 // discipline every prior `:caminho` arm establishes.
13439 let d = dep_with_fonte(DepSource::Path {
13440 caminho: "../foo!sudo^bad^good".into(),
13441 });
13442 let err = d.validate().unwrap_err();
13443 assert!(
13444 matches!(
13445 err,
13446 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13447 ),
13448 "got {err:?}",
13449 );
13450 }
13451
13452 #[test]
13453 fn fonte_caminho_shell_history_substitution_fires_before_trailing_slash() {
13454 // Cascade pin on the immediate-successor arm: a value carrying
13455 // both embedded `^` and a trailing `/` (`"../foo^bad^good/"` —
13456 // the canonical "I tab-completed a `^bad^good`-carrying path")
13457 // routes through `FonteCaminhoShellHistorySubstitution` not
13458 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13459 // substitution byte is the more semantic-locating axis on probe-
13460 // as-both values (an author who removes the `^bad^good`
13461 // substitution fragment is likely to also tab-strip the trailing
13462 // separator).
13463 let d = dep_with_fonte(DepSource::Path {
13464 caminho: "../foo^bad^good/".into(),
13465 });
13466 let err = d.validate().unwrap_err();
13467 assert!(
13468 matches!(
13469 err,
13470 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13471 ),
13472 "got {err:?}",
13473 );
13474 }
13475
13476 #[test]
13477 fn fonte_caminho_shell_history_substitution_diagnostic_carries_offending_dep_caminho_and_byte()
13478 {
13479 // Diagnostic-shape pin (peer with
13480 // `fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13481 // on the immediate-predecessor arm): the error's Display
13482 // surfaces the offending `:nome`, the offending `:caminho`
13483 // verbatim, the offending byte's hex form, and names the
13484 // shell-history-substitution / RFC-3986-'unwise' / regex-
13485 // negation footgun explicitly so a `feira lint` run can render
13486 // the diagnostic without re-parsing.
13487 let d = dep_with_fonte(DepSource::Path {
13488 caminho: "../foo^bad^good".into(),
13489 });
13490 let rendered = d.validate().unwrap_err().to_string();
13491 assert!(
13492 rendered.contains("caixa-teia"),
13493 "diagnostic must name the offending dep: {rendered}",
13494 );
13495 assert!(
13496 rendered.contains("../foo^bad^good"),
13497 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13498 );
13499 assert!(
13500 rendered.contains("0x5e") || rendered.contains("0x5E"),
13501 "diagnostic must surface the offending byte hex: {rendered:?}",
13502 );
13503 assert!(
13504 rendered.contains("history-substitution") || rendered.contains("history substitution"),
13505 "diagnostic must name the shell-history-substitution footgun: {rendered:?}",
13506 );
13507 assert!(
13508 rendered.contains("unwise"),
13509 "diagnostic must reference the RFC-3986 'unwise' set vocabulary: {rendered:?}",
13510 );
13511 }
13512
13513 #[test]
13514 fn fonte_repo_empty_fires_before_pin_missing() {
13515 // Order pin: empty `:repo` is the more self-locating diagnostic
13516 // (every git source needs a repo; the pin discussion is
13517 // secondary), so it fires before the pin-missing arm even when
13518 // both are violated. Mirrors the
13519 // `nome_empty_takes_precedence_over_versao_invalid` ordering
13520 // discipline on the per-entry layer.
13521 let d = dep_with_fonte(DepSource::Git {
13522 repo: String::new(),
13523 tag: None,
13524 rev: None,
13525 branch: None,
13526 });
13527 let err = d.validate().unwrap_err();
13528 assert!(
13529 matches!(err, DepError::FonteRepoEmpty { .. }),
13530 "got {err:?}"
13531 );
13532 }
13533
13534 #[test]
13535 fn fonte_pin_missing_fires_before_pin_empty() {
13536 // Order pin: a fully-None pin set is structurally distinct from
13537 // a Some(empty) pin — the first surfaces as FontePinMissing
13538 // (no axis chosen), the second as FontePinEmpty (axis chosen
13539 // but value blank). Pin the disjoint relationship so a future
13540 // unification collapses to one variant only as a structural
13541 // decision.
13542 let d = dep_with_fonte(DepSource::Git {
13543 repo: "github:pleme-io/caixa-teia".into(),
13544 tag: None,
13545 rev: None,
13546 branch: None,
13547 });
13548 assert!(matches!(
13549 d.validate().unwrap_err(),
13550 DepError::FontePinMissing { .. }
13551 ));
13552 }
13553
13554 #[test]
13555 fn nome_empty_takes_precedence_over_fonte_invalid() {
13556 // Order pin: a per-entry diagnostic without a non-empty :nome
13557 // can't be self-locating, so :nome "" fires first even when
13558 // :fonte is also malformed. Mirrors
13559 // `nome_empty_takes_precedence_over_versao_invalid` on the
13560 // adjacent axis.
13561 let mut d = dep_with_fonte(DepSource::Git {
13562 repo: String::new(),
13563 tag: None,
13564 rev: None,
13565 branch: None,
13566 });
13567 d.nome = String::new();
13568 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
13569 }
13570
13571 #[test]
13572 fn versao_invalid_takes_precedence_over_fonte_invalid() {
13573 // Order pin: the :versao parse-side diagnostic is narrower than
13574 // the :fonte shape diagnostic — a malformed :versao always names
13575 // the parser's reason, which is more actionable than the
13576 // :fonte gate's "the pins are wrong" wording. Pin the ordering
13577 // so a re-ordering surfaces here.
13578 let mut d = dep_with_fonte(DepSource::Git {
13579 repo: String::new(),
13580 tag: None,
13581 rev: None,
13582 branch: None,
13583 });
13584 d.versao = "v0.1".into();
13585 let err = d.validate().unwrap_err();
13586 assert!(
13587 matches!(err, DepError::VersaoInvalid { ref nome, .. } if nome == "caixa-teia"),
13588 "got {err:?}"
13589 );
13590 }
13591
13592 #[test]
13593 fn fonte_invalid_diagnostic_carries_offending_nome() {
13594 // The diagnostic-shape pin: every :fonte error variant names
13595 // the offending dep's :nome verbatim, so the author can grep
13596 // caixa.lisp for the `:nome "<n>"` block and fix it in one
13597 // edit. Cover all seven variants so a future variant addition
13598 // forces a parallel diagnostic-shape decision.
13599 for (case, fonte) in [
13600 (
13601 "repo-empty",
13602 DepSource::Git {
13603 repo: String::new(),
13604 tag: Some("v1".into()),
13605 rev: None,
13606 branch: None,
13607 },
13608 ),
13609 (
13610 "repo-shape",
13611 DepSource::Git {
13612 repo: "github:p/x ".into(),
13613 tag: Some("v1".into()),
13614 rev: None,
13615 branch: None,
13616 },
13617 ),
13618 (
13619 "pin-missing",
13620 DepSource::Git {
13621 repo: "github:p/x".into(),
13622 tag: None,
13623 rev: None,
13624 branch: None,
13625 },
13626 ),
13627 (
13628 "pin-ambiguous",
13629 DepSource::Git {
13630 repo: "github:p/x".into(),
13631 tag: Some("v1".into()),
13632 rev: None,
13633 branch: Some("main".into()),
13634 },
13635 ),
13636 (
13637 "pin-empty",
13638 DepSource::Git {
13639 repo: "github:p/x".into(),
13640 tag: Some(String::new()),
13641 rev: None,
13642 branch: None,
13643 },
13644 ),
13645 (
13646 "caminho-empty",
13647 DepSource::Path {
13648 caminho: String::new(),
13649 },
13650 ),
13651 (
13652 "caminho-absolute",
13653 DepSource::Path {
13654 caminho: "/home/me/work/caixa-teia".into(),
13655 },
13656 ),
13657 ] {
13658 let d = dep_with_fonte(fonte);
13659 let msg = d
13660 .validate()
13661 .expect_err(&format!("{case}: expected fonte error"))
13662 .to_string();
13663 assert!(
13664 msg.contains("\"caixa-teia\""),
13665 "{case}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
13666 );
13667 }
13668 }
13669
13670 // -- :tag / :branch value-shape gate ----------------------------------
13671
13672 #[test]
13673 fn validate_rejects_git_fonte_with_tag_carrying_trailing_space() {
13674 // The canonical paste-from-doc footgun on `:tag` — author
13675 // copies `"v0.1.0 "` (trailing space) out of a release-notes
13676 // paragraph. Until this gate landed the empty-pin arm passed
13677 // (the string isn't empty), the resolver issued
13678 // `git fetch <remote> tag 'v0.1.0 '`, and the failure
13679 // surfaced at clone time with a quoting-confused git error
13680 // far from the source caixa.lisp. The new gate moves the
13681 // check to caixa-build time and names the offending dep +
13682 // pin + value verbatim.
13683 let d = dep_with_fonte(DepSource::Git {
13684 repo: "github:pleme-io/caixa-teia".into(),
13685 tag: Some("v0.1.0 ".into()),
13686 rev: None,
13687 branch: None,
13688 });
13689 let err = d.validate().unwrap_err();
13690 let DepError::FontePinShape {
13691 nome,
13692 pin,
13693 value,
13694 reason,
13695 } = err
13696 else {
13697 panic!("expected FontePinShape, got other variant");
13698 };
13699 assert_eq!(nome, "caixa-teia");
13700 assert_eq!(pin, ":tag");
13701 assert_eq!(value, "v0.1.0 ");
13702 assert!(
13703 reason.contains("whitespace"),
13704 "reason must surface the whitespace arm, got {reason:?}"
13705 );
13706 }
13707
13708 #[test]
13709 fn validate_rejects_git_fonte_with_tag_carrying_lock_suffix() {
13710 // The `.lock` suffix is git's atomic-rename guard for
13711 // in-flight ref updates — a refname ending in `.lock` is
13712 // unwritable on disk. Pinned separately from the whitespace
13713 // arm so a future relaxation that admits one but not the
13714 // other surfaces here.
13715 let d = dep_with_fonte(DepSource::Git {
13716 repo: "github:pleme-io/caixa-teia".into(),
13717 tag: Some("v0.1.0.lock".into()),
13718 rev: None,
13719 branch: None,
13720 });
13721 let err = d.validate().unwrap_err();
13722 let DepError::FontePinShape {
13723 pin, value, reason, ..
13724 } = err
13725 else {
13726 panic!("expected FontePinShape, got other variant");
13727 };
13728 assert_eq!(pin, ":tag");
13729 assert_eq!(value, "v0.1.0.lock");
13730 assert!(
13731 reason.contains(".lock"),
13732 "reason must surface the .lock arm, got {reason:?}"
13733 );
13734 }
13735
13736 #[test]
13737 fn validate_rejects_git_fonte_with_branch_carrying_embedded_space() {
13738 // The canonical "branch name with spaces" footgun (`feature
13739 // foo`, `release branch`) — git's refname parser rejects raw
13740 // whitespace, and the failure surfaces at `git checkout
13741 // 'feature foo'` time with a quoting-confused error far from
13742 // the source caixa.lisp. Pinned on the `:branch` axis so the
13743 // gate-applies-to-both-:tag-and-:branch contract is a build-
13744 // error to relax.
13745 let d = dep_with_fonte(DepSource::Git {
13746 repo: "github:pleme-io/caixa-teia".into(),
13747 tag: None,
13748 rev: None,
13749 branch: Some("feature/foo bar".into()),
13750 });
13751 let err = d.validate().unwrap_err();
13752 let DepError::FontePinShape {
13753 pin, value, reason, ..
13754 } = err
13755 else {
13756 panic!("expected FontePinShape, got other variant");
13757 };
13758 assert_eq!(pin, ":branch");
13759 assert_eq!(value, "feature/foo bar");
13760 assert!(
13761 reason.contains("whitespace"),
13762 "reason must surface the whitespace arm, got {reason:?}"
13763 );
13764 }
13765
13766 #[test]
13767 fn validate_rejects_git_fonte_with_branch_carrying_qualified_prefix() {
13768 // The `refs/heads/main` shape — the canonical "I copied the
13769 // fully-qualified ref out of `git show-ref` instead of the
13770 // leaf" footgun. The caixa-resolver prepends `refs/heads/`
13771 // at clone time, so this resolves to a literal ref named
13772 // `refs/heads/refs/heads/main` on disk; the silent double-
13773 // prefix is the load-bearing reason to gate at validate.
13774 // The diagnostic must enumerate the leaf the author probably
13775 // meant (`"main"`) so the fix is one edit.
13776 let d = dep_with_fonte(DepSource::Git {
13777 repo: "github:pleme-io/caixa-teia".into(),
13778 tag: None,
13779 rev: None,
13780 branch: Some("refs/heads/main".into()),
13781 });
13782 let err = d.validate().unwrap_err();
13783 let DepError::FontePinShape {
13784 pin, value, reason, ..
13785 } = err
13786 else {
13787 panic!("expected FontePinShape, got other variant");
13788 };
13789 assert_eq!(pin, ":branch");
13790 assert_eq!(value, "refs/heads/main");
13791 assert!(
13792 reason.contains("fully-qualified"),
13793 "reason must surface the qualified-prefix arm, got {reason:?}"
13794 );
13795 assert!(
13796 reason.contains("\"main\""),
13797 "reason must quote the leaf the author probably meant, got {reason:?}"
13798 );
13799 }
13800
13801 #[test]
13802 fn validate_rejects_git_fonte_with_tag_carrying_qualified_prefix() {
13803 // Sibling arm of the qualified-prefix gate on the `:tag`
13804 // axis (`refs/tags/v0.1.0` — same `git show-ref` output-leak
13805 // footgun). Pinned separately so a future relaxation that
13806 // only catches the `:branch` arm surfaces here.
13807 let d = dep_with_fonte(DepSource::Git {
13808 repo: "github:pleme-io/caixa-teia".into(),
13809 tag: Some("refs/tags/v0.1.0".into()),
13810 rev: None,
13811 branch: None,
13812 });
13813 let err = d.validate().unwrap_err();
13814 let DepError::FontePinShape {
13815 pin, value, reason, ..
13816 } = err
13817 else {
13818 panic!("expected FontePinShape, got other variant");
13819 };
13820 assert_eq!(pin, ":tag");
13821 assert_eq!(value, "refs/tags/v0.1.0");
13822 assert!(
13823 reason.contains("fully-qualified"),
13824 "reason must surface the qualified-prefix arm, got {reason:?}"
13825 );
13826 assert!(
13827 reason.contains("\"v0.1.0\""),
13828 "reason must quote the leaf the author probably meant, got {reason:?}"
13829 );
13830 }
13831
13832 #[test]
13833 fn validate_rejects_git_fonte_with_branch_named_at() {
13834 // The bare `@` is git's alias for `HEAD`; a `:branch "@"` is
13835 // unsourceable. Pinned so a future relaxation that admits
13836 // any single-character refname surfaces here.
13837 let d = dep_with_fonte(DepSource::Git {
13838 repo: "github:pleme-io/caixa-teia".into(),
13839 tag: None,
13840 rev: None,
13841 branch: Some("@".into()),
13842 });
13843 let err = d.validate().unwrap_err();
13844 let DepError::FontePinShape { pin, value, .. } = err else {
13845 panic!("expected FontePinShape, got other variant");
13846 };
13847 assert_eq!(pin, ":branch");
13848 assert_eq!(value, "@");
13849 }
13850
13851 #[test]
13852 fn validate_rejects_git_fonte_with_tag_carrying_double_dot() {
13853 // Git's `<rev1>..<rev2>` range grammar reserves `..` —
13854 // a `:tag "../escape"` (path-traversal-shaped slug) silently
13855 // passes parse and surfaces as a refname-parse error or, on
13856 // older git, a literal `../escape` checkout that escapes the
13857 // refs/ directory tree. Pinned separately from the
13858 // qualified-prefix arm so a future relaxation that catches
13859 // one but not the other surfaces here.
13860 let d = dep_with_fonte(DepSource::Git {
13861 repo: "github:pleme-io/caixa-teia".into(),
13862 tag: Some("../escape".into()),
13863 rev: None,
13864 branch: None,
13865 });
13866 let err = d.validate().unwrap_err();
13867 let DepError::FontePinShape { pin, value, .. } = err else {
13868 panic!("expected FontePinShape, got other variant");
13869 };
13870 assert_eq!(pin, ":tag");
13871 assert_eq!(value, "../escape");
13872 }
13873
13874 #[test]
13875 fn validate_accepts_git_fonte_with_hierarchical_branch() {
13876 // The positive-control pin: hierarchical refnames with one or
13877 // more `/` separators (the `feature/foo` / `user/jdoe/feat`
13878 // canonical idiom) round-trip through the gate. Pinned
13879 // separately from the leaf-`"main"` positive control so a
13880 // future tightening that rejects all multi-component refnames
13881 // surfaces here.
13882 let d = dep_with_fonte(DepSource::Git {
13883 repo: "github:pleme-io/caixa-teia".into(),
13884 tag: None,
13885 rev: None,
13886 branch: Some("feature/checkout-rewrite".into()),
13887 });
13888 d.validate().unwrap();
13889 }
13890
13891 #[test]
13892 fn validate_accepts_git_fonte_with_prerelease_tag() {
13893 // The positive-control pin: semver pre-release shape
13894 // (`v0.1.0-alpha.1`) — the in-component dot is allowed
13895 // (only consecutive `..` and trailing `.` are rejected), the
13896 // mid-component hyphen is allowed. Pinned separately from
13897 // the bare-`"v0.1.0"` positive control so a future tightening
13898 // that rejects pre-release tags surfaces here.
13899 let d = dep_with_fonte(DepSource::Git {
13900 repo: "github:pleme-io/caixa-teia".into(),
13901 tag: Some("v0.1.0-alpha.1".into()),
13902 rev: None,
13903 branch: None,
13904 });
13905 d.validate().unwrap();
13906 }
13907
13908 #[test]
13909 fn validate_rejects_git_fonte_with_rev_carrying_refname_unfriendly_value() {
13910 // The `:rev` axis is routed through `crate::render::is_git_oid`
13911 // (a SHA's character set is `[0-9a-f]`, not a refname's), so a
13912 // value with refname-shape punctuation (here, a `:` mid-string
13913 // — would be a refname violation under `is_git_ref_name` too)
13914 // is rejected at the OID-shape gate. The two predicates
13915 // partition the `:fonte` pin axes structurally: an `:rev` value
13916 // that's a valid refname (`:rev "main"`, `:rev "v0.1.0"`) is
13917 // *still* rejected here because every refname character outside
13918 // `[0-9a-f]` fails the OID gate. Same shape as
13919 // `fonte_pin_shape_diagnostic_carries_offending_nome_pin_value`
13920 // on the refname-shaped axes — the diagnostic names the
13921 // offending dep + pin + value verbatim. The flip-from-accept
13922 // case the prior `:tag`/`:branch` gate left as a "future axis"
13923 // (e70d213) — now landed.
13924 let d = dep_with_fonte(DepSource::Git {
13925 repo: "github:pleme-io/caixa-teia".into(),
13926 tag: None,
13927 rev: Some("c0ffee:notarefname".into()),
13928 branch: None,
13929 });
13930 let err = d.validate().unwrap_err();
13931 let DepError::FontePinShape {
13932 nome,
13933 pin,
13934 value,
13935 reason,
13936 } = err
13937 else {
13938 panic!("expected FontePinShape, got other variant");
13939 };
13940 assert_eq!(nome, "caixa-teia");
13941 assert_eq!(pin, ":rev");
13942 assert_eq!(value, "c0ffee:notarefname");
13943 assert!(
13944 !reason.is_empty(),
13945 "FontePinShape `reason` must carry the predicate's wording verbatim"
13946 );
13947 }
13948
13949 #[test]
13950 fn validate_accepts_git_fonte_with_rev_full_sha1() {
13951 // The positive-control pin on the SHA-1 OID width: exactly 40
13952 // lowercase hex characters — the canonical `git rev-parse HEAD`
13953 // emission on a SHA-1-hashed repository (the default on every
13954 // pre-2.42 git and the canonical pleme-io substrate hash).
13955 // Pinned separately from the SHA-256 positive control so a
13956 // future tightening that only admits one width surfaces here.
13957 let d = dep_with_fonte(DepSource::Git {
13958 repo: "github:pleme-io/caixa-teia".into(),
13959 tag: None,
13960 rev: Some("0123456789abcdef0123456789abcdef01234567".into()),
13961 branch: None,
13962 });
13963 d.validate().unwrap();
13964 }
13965
13966 #[test]
13967 fn validate_accepts_git_fonte_with_rev_full_sha256() {
13968 // The positive-control pin on the SHA-256 OID width: exactly
13969 // 64 lowercase hex characters — `git`'s
13970 // `extensions.objectFormat = sha256` emission (GA since Git
13971 // 2.42 / Oct 2023). The substrate admits either canonical
13972 // width so an `:rev` authored against a SHA-256-hashed
13973 // upstream round-trips through the gate without per-repo
13974 // configuration. Pinned separately from the SHA-1 positive
13975 // control so a future tightening that drops one width surfaces
13976 // here as a structural decision.
13977 let d = dep_with_fonte(DepSource::Git {
13978 repo: "github:pleme-io/caixa-teia".into(),
13979 tag: None,
13980 rev: Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into()),
13981 branch: None,
13982 });
13983 d.validate().unwrap();
13984 }
13985
13986 #[test]
13987 fn validate_rejects_git_fonte_with_rev_abbreviated_prefix() {
13988 // The canonical `git log --short` / `git rev-parse --short HEAD`
13989 // paste-from-release-notes footgun: a 7-char prefix (git's
13990 // default `core.abbrev`) silently passes string emptiness
13991 // checks and resolves to one commit today, but becomes ambiguous
13992 // tomorrow as the repo grows. Until this gate landed the empty-
13993 // pin arm passed (the string isn't empty) and the resolver
13994 // accepted the prefix through git's separate prefix-lookup pass
13995 // — defeating the reproducibility contract `:rev` carries vs.
13996 // `:tag` / `:branch`. The new gate moves the check to caixa-
13997 // build time and names the offending dep + pin + value verbatim.
13998 let d = dep_with_fonte(DepSource::Git {
13999 repo: "github:pleme-io/caixa-teia".into(),
14000 tag: None,
14001 rev: Some("c0ffee0".into()),
14002 branch: None,
14003 });
14004 let err = d.validate().unwrap_err();
14005 let DepError::FontePinShape {
14006 pin, value, reason, ..
14007 } = err
14008 else {
14009 panic!("expected FontePinShape, got other variant");
14010 };
14011 assert_eq!(pin, ":rev");
14012 assert_eq!(value, "c0ffee0");
14013 assert!(
14014 reason.contains("abbreviated") || reason.contains("ambiguous"),
14015 "reason must surface the abbreviation arm, got {reason:?}"
14016 );
14017 }
14018
14019 #[test]
14020 fn validate_rejects_git_fonte_with_rev_uppercase_hex() {
14021 // The canonical "I pasted the SHA in uppercase" footgun: `git
14022 // porcelain` emits OIDs lowercase exclusively, so an uppercase-
14023 // bearing `:rev` round-trips inconsistently across the
14024 // resolver's `git fetch <remote> <:rev>` ↔ `git rev-parse HEAD`
14025 // equality-check pipeline and fails the lacre's content-
14026 // addressing probe with a confusing case-only diff. Pinned
14027 // separately from the non-hex arm so a future relaxation that
14028 // admits one but not the other surfaces here.
14029 let d = dep_with_fonte(DepSource::Git {
14030 repo: "github:pleme-io/caixa-teia".into(),
14031 tag: None,
14032 rev: Some("DEADBEEFCAFEBABE0123456789ABCDEF01234567".into()),
14033 branch: None,
14034 });
14035 let err = d.validate().unwrap_err();
14036 let DepError::FontePinShape {
14037 pin, value, reason, ..
14038 } = err
14039 else {
14040 panic!("expected FontePinShape, got other variant");
14041 };
14042 assert_eq!(pin, ":rev");
14043 assert_eq!(value, "DEADBEEFCAFEBABE0123456789ABCDEF01234567");
14044 assert!(
14045 reason.contains("uppercase"),
14046 "reason must surface the uppercase arm, got {reason:?}"
14047 );
14048 }
14049
14050 #[test]
14051 fn validate_rejects_git_fonte_with_rev_refname_value() {
14052 // The cross-axis mis-slot footgun: `:rev "main"` — the author
14053 // conflated `:rev` (hex commit ID, immutable) and `:branch`
14054 // (mutable ref pointing at whatever HEAD is today). Until this
14055 // gate landed the resolver silently dispatched on the value
14056 // shape ("`main` doesn't look like a SHA, fall back to
14057 // refname"), defeating the `:rev` reproducibility contract.
14058 // The new gate rejects every non-hex value on the `:rev` axis,
14059 // so the `:rev`/`:branch` boundary is structurally enforced —
14060 // a refname in the `:rev` slot is a build error, not a
14061 // resolver-time silent reinterpretation.
14062 let d = dep_with_fonte(DepSource::Git {
14063 repo: "github:pleme-io/caixa-teia".into(),
14064 tag: None,
14065 rev: Some("main".into()),
14066 branch: None,
14067 });
14068 let err = d.validate().unwrap_err();
14069 let DepError::FontePinShape {
14070 pin, value, reason, ..
14071 } = err
14072 else {
14073 panic!("expected FontePinShape, got other variant");
14074 };
14075 assert_eq!(pin, ":rev");
14076 assert_eq!(value, "main");
14077 // 4 chars `main` fails the length arm before the character arm,
14078 // so the diagnostic surfaces the abbreviation wording (same
14079 // path the `c0ffee0` 7-char fixture lands on); the structural
14080 // assertion is just that the `:rev "main"` value is rejected.
14081 assert!(
14082 !reason.is_empty(),
14083 "FontePinShape reason must be non-empty for refname-shaped :rev"
14084 );
14085 }
14086
14087 #[test]
14088 fn validate_rejects_git_fonte_with_rev_tag_shaped_value() {
14089 // Sibling cross-axis mis-slot: `:rev "v0.1.0"` — the author
14090 // conflated `:rev` and `:tag`. Pinned separately from the
14091 // `:rev "main"` (`:branch` mis-slot) arm so a future relaxation
14092 // that catches one but not the other surfaces here. The
14093 // length arm fires first (6 chars ≠ 40 ≠ 64); the structural
14094 // assertion is just that the cross-axis mis-slot is a build
14095 // error, regardless of which sub-arm surfaces the diagnostic
14096 // (`is_git_oid` rejects at the first violation; longer
14097 // tag-shape values would hit the non-hex arm instead).
14098 let d = dep_with_fonte(DepSource::Git {
14099 repo: "github:pleme-io/caixa-teia".into(),
14100 tag: None,
14101 rev: Some("v0.1.0".into()),
14102 branch: None,
14103 });
14104 let err = d.validate().unwrap_err();
14105 let DepError::FontePinShape {
14106 pin, value, reason, ..
14107 } = err
14108 else {
14109 panic!("expected FontePinShape, got other variant");
14110 };
14111 assert_eq!(pin, ":rev");
14112 assert_eq!(value, "v0.1.0");
14113 assert!(
14114 !reason.is_empty(),
14115 "FontePinShape reason must be non-empty for tag-shaped :rev"
14116 );
14117 }
14118
14119 #[test]
14120 fn validate_rejects_git_fonte_with_rev_too_long() {
14121 // Boundary case on the upper end: 41 hex chars — one past the
14122 // SHA-1 width, well below the SHA-256 width. Pin so a future
14123 // relaxation that admits "long enough to be a SHA" without
14124 // matching either canonical width surfaces here. The diagnostic
14125 // names the offending length verbatim so the author's grep
14126 // target is unambiguous (either trim one char or paste the
14127 // full SHA-256).
14128 let too_long: String = "0".repeat(41);
14129 let d = dep_with_fonte(DepSource::Git {
14130 repo: "github:pleme-io/caixa-teia".into(),
14131 tag: None,
14132 rev: Some(too_long.clone()),
14133 branch: None,
14134 });
14135 let err = d.validate().unwrap_err();
14136 let DepError::FontePinShape {
14137 pin, value, reason, ..
14138 } = err
14139 else {
14140 panic!("expected FontePinShape, got other variant");
14141 };
14142 assert_eq!(pin, ":rev");
14143 assert_eq!(value, too_long);
14144 assert!(
14145 reason.contains("41"),
14146 "reason must surface the offending length verbatim, got {reason:?}"
14147 );
14148 }
14149
14150 #[test]
14151 fn validate_rejects_git_fonte_with_rev_carrying_whitespace() {
14152 // The canonical paste-from-doc footgun on `:rev` — author
14153 // copies `"deadbeefcafe…0123 "` (trailing space) out of a
14154 // commit-message paragraph. Until this gate landed the empty-
14155 // pin arm passed (the string isn't empty), the resolver issued
14156 // `git fetch <remote> 'deadbeef… '` and the failure surfaced at
14157 // clone time with a quoting-confused git error far from the
14158 // source caixa.lisp. The new gate moves the check to caixa-
14159 // build time. Length is 41 (40 hex + space) so the length arm
14160 // fires first — pinned separately from the pure-length arm to
14161 // ensure the diagnostic surfaces *some* parser wording, not
14162 // silently pass through.
14163 let with_space = "0123456789abcdef0123456789abcdef01234567 ".to_string();
14164 let d = dep_with_fonte(DepSource::Git {
14165 repo: "github:pleme-io/caixa-teia".into(),
14166 tag: None,
14167 rev: Some(with_space.clone()),
14168 branch: None,
14169 });
14170 let err = d.validate().unwrap_err();
14171 let DepError::FontePinShape {
14172 pin, value, reason, ..
14173 } = err
14174 else {
14175 panic!("expected FontePinShape, got other variant");
14176 };
14177 assert_eq!(pin, ":rev");
14178 assert_eq!(value, with_space);
14179 assert!(
14180 !reason.is_empty(),
14181 "FontePinShape reason must be non-empty for whitespace-bearing :rev"
14182 );
14183 }
14184
14185 #[test]
14186 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value_for_rev() {
14187 // Diagnostic-shape pin on the `:rev` axis: every FontePinShape
14188 // variant on this axis names the offending dep's `:nome` + the
14189 // `:rev` axis + the offending value verbatim, so the author's
14190 // grep target is the literal `:rev "<value>"` block in
14191 // caixa.lisp. Sibling of the `fonte_pin_shape_diagnostic_
14192 // carries_offending_nome_pin_value` test on the refname-shaped
14193 // (`:tag` / `:branch`) axes.
14194 let d = dep_with_fonte(DepSource::Git {
14195 repo: "github:p/x".into(),
14196 tag: None,
14197 rev: Some("not-a-sha".into()),
14198 branch: None,
14199 });
14200 let msg = d
14201 .validate()
14202 .expect_err(":rev: expected FontePinShape")
14203 .to_string();
14204 assert!(
14205 msg.contains("\"caixa-teia\""),
14206 ":rev: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14207 );
14208 assert!(
14209 msg.contains(":rev"),
14210 ":rev: diagnostic must name the offending pin axis, got {msg:?}"
14211 );
14212 assert!(
14213 msg.contains("not-a-sha"),
14214 ":rev: diagnostic must quote the offending value verbatim, got {msg:?}"
14215 );
14216 }
14217
14218 #[test]
14219 fn fonte_pin_empty_fires_before_pin_shape() {
14220 // Order pin: a `Some("")` `:tag` is the more self-locating
14221 // diagnostic (the author chose an axis but left it blank;
14222 // grep is unambiguous), so it fires before the shape gate
14223 // even when both arms would match. Pinned so a future
14224 // reordering surfaces here. Mirrors the
14225 // `fonte_repo_empty_fires_before_pin_missing` ordering
14226 // discipline on the peer per-axis arms.
14227 let d = dep_with_fonte(DepSource::Git {
14228 repo: "github:pleme-io/caixa-teia".into(),
14229 tag: Some(String::new()),
14230 rev: None,
14231 branch: None,
14232 });
14233 assert!(matches!(
14234 d.validate().unwrap_err(),
14235 DepError::FontePinEmpty { ref pin, .. } if pin == ":tag"
14236 ));
14237 }
14238
14239 #[test]
14240 fn fonte_pin_shape_fires_after_repo_empty() {
14241 // Order pin: `:repo ""` is the more self-locating axis
14242 // (every git source needs a repo; the per-pin shape gate is
14243 // secondary), so the repo-empty arm fires before the
14244 // per-pin shape arm even when both are violated. Pinned so
14245 // a future reordering surfaces here. Mirrors
14246 // `fonte_repo_empty_fires_before_pin_missing` on the
14247 // adjacent axis pair.
14248 let d = dep_with_fonte(DepSource::Git {
14249 repo: String::new(),
14250 tag: Some("v0.1.0 ".into()),
14251 rev: None,
14252 branch: None,
14253 });
14254 assert!(matches!(
14255 d.validate().unwrap_err(),
14256 DepError::FonteRepoEmpty { .. }
14257 ));
14258 }
14259
14260 #[test]
14261 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value() {
14262 // Diagnostic-shape pin across both refname-shaped axes
14263 // (`:tag` + `:branch`): every `FontePinShape` variant names
14264 // the offending dep's `:nome` + the offending pin axis + the
14265 // offending value verbatim, so the author's grep target is
14266 // unambiguous (the literal `:tag "<value>"` / `:branch
14267 // "<value>"` lands in caixa.lisp with quotes). Cover both
14268 // pin axes so a future variant addition forces a parallel
14269 // diagnostic-shape decision.
14270 for (pin_label, fonte) in [
14271 (
14272 ":tag",
14273 DepSource::Git {
14274 repo: "github:p/x".into(),
14275 tag: Some("v0.1.0~1".into()),
14276 rev: None,
14277 branch: None,
14278 },
14279 ),
14280 (
14281 ":branch",
14282 DepSource::Git {
14283 repo: "github:p/x".into(),
14284 tag: None,
14285 rev: None,
14286 branch: Some("feature/foo*".into()),
14287 },
14288 ),
14289 ] {
14290 let d = dep_with_fonte(fonte);
14291 let msg = d
14292 .validate()
14293 .expect_err(&format!("{pin_label}: expected FontePinShape"))
14294 .to_string();
14295 assert!(
14296 msg.contains("\"caixa-teia\""),
14297 "{pin_label}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14298 );
14299 assert!(
14300 msg.contains(pin_label),
14301 "{pin_label}: diagnostic must name the offending pin axis, got {msg:?}"
14302 );
14303 }
14304 }
14305
14306 #[test]
14307 fn git_source_json_round_trip() {
14308 let src = DepSource::Git {
14309 repo: "github:pleme-io/caixa-teia".into(),
14310 tag: Some("v0.1.0".into()),
14311 rev: None,
14312 branch: None,
14313 };
14314 let s = serde_json::to_string(&src).unwrap();
14315 assert!(s.contains(&format!(
14316 r#""{tipo}":"{git}""#,
14317 tipo = crate::render::DEP_SOURCE_KEY_TIPO,
14318 git = crate::render::DEP_SOURCE_TIPO_GIT,
14319 )));
14320 assert!(s.contains(r#""repo":"github:pleme-io/caixa-teia""#));
14321 assert!(s.contains(r#""tag":"v0.1.0""#));
14322 assert!(!s.contains("rev"));
14323 assert!(!s.contains("branch"));
14324 let round: DepSource = serde_json::from_str(&s).unwrap();
14325 assert_eq!(round, src);
14326 }
14327
14328 // ── DEP_SOURCE_{KEY_TIPO,TIPO_GIT,TIPO_PATH} drift-detection ────────
14329 //
14330 // The `#[serde(tag = "tipo", rename_all = "lowercase")]` derive
14331 // attribute on [`DepSource`] pins three load-bearing byte-sequences
14332 // that flow into every serialized `Dep.fonte` block: the outer
14333 // discriminator-key `"tipo"` the `tag = "tipo"` attribute names, and
14334 // the two admitted variant-tag values `"git"` / `"path"` the
14335 // `rename_all = "lowercase"` attribute pins as the discriminator's
14336 // closed-set arms. The three pin tests below round-trip a
14337 // fully-populated variant of each arm through
14338 // [`serde_json::to_value`] and assert each canonical byte-sequence
14339 // appears at its axis — pins a hypothetical future
14340 // `tag = "type"` / `tag = "source_type"` typo, a `rename_all`
14341 // rebrand (`"UPPERCASE"` / `"snake_case"` / `"kebab-case"`), or a
14342 // Rust-side variant rename (`Git` → `Repository`, `Path` → `Local`)
14343 // at build time rather than at fetch time when the resolver's
14344 // `Dep.fonte` dispatch silently fails to match on the drifted
14345 // discriminator. Same "serialize-and-check" discipline the peer
14346 // `M2_LIMITS_KEY_*`, `M2_BEHAVIOR_KEY_ON_*`, `SUPERVISOR_KEY_*`,
14347 // and `MEMBRO_KEY_*` drift-detection pins carry — extended here
14348 // to the last `#[serde(tag = ..., rename_all = ...)]` discriminator
14349 // family in caixa-core lacking a lifted peer.
14350
14351 #[test]
14352 fn dep_source_git_serde_keys_match_lifted_dep_source_key_consts() {
14353 // Fail-before-pass-after: a future `tag = "type"` at the derive
14354 // attribute would serialize under `"type":"git"`, and this test
14355 // would trip because `"tipo"` no longer appears at the emitted
14356 // discriminator key. A future `rename_all = "kebab-case"` /
14357 // `"snake_case"` (both no-ops on `Git` since it lacks internal
14358 // word boundaries) is caught by the sibling
14359 // `dep_source_path_serde_keys_match_lifted_dep_source_key_consts`
14360 // pin below (Path has no internal boundary either but the pair
14361 // catches any per-arm inconsistency). A future variant rename
14362 // `Git` → `Repository` would emit `"tipo":"repository"` and
14363 // trip this pin.
14364 let src = DepSource::Git {
14365 repo: "github:pleme-io/caixa-teia".into(),
14366 tag: Some("v0.1.0".into()),
14367 rev: None,
14368 branch: None,
14369 };
14370 let json = serde_json::to_value(&src).unwrap();
14371 let obj = json.as_object().expect("Git serializes as a JSON object");
14372 assert_eq!(
14373 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14374 .and_then(serde_json::Value::as_str),
14375 Some(crate::render::DEP_SOURCE_TIPO_GIT),
14376 "DepSource::Git must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14377 with value DEP_SOURCE_TIPO_GIT — attribute drift or variant rename \
14378 detected in {json}"
14379 );
14380 }
14381
14382 #[test]
14383 fn dep_source_path_serde_keys_match_lifted_dep_source_key_consts() {
14384 // Fail-before-pass-after: a future variant rename `Path` →
14385 // `Local` / `Filesystem` would emit `"tipo":"local"` and trip
14386 // this pin. A per-consumer disambiguation as the `defcaixa`
14387 // macro stabilizes ("caminho" → "path" for English-uniformity)
14388 // is scoped to the inner field key, not the discriminator; this
14389 // pin is orthogonal to that and catches only the outer
14390 // discriminator drift.
14391 let src = DepSource::Path {
14392 caminho: "../caixa-teia".into(),
14393 };
14394 let json = serde_json::to_value(&src).unwrap();
14395 let obj = json.as_object().expect("Path serializes as a JSON object");
14396 assert_eq!(
14397 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14398 .and_then(serde_json::Value::as_str),
14399 Some(crate::render::DEP_SOURCE_TIPO_PATH),
14400 "DepSource::Path must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14401 with value DEP_SOURCE_TIPO_PATH — attribute drift or variant rename \
14402 detected in {json}"
14403 );
14404 }
14405
14406 #[test]
14407 fn dep_source_key_consts_are_pairwise_distinct() {
14408 // Cross-axis collapse detector: a hypothetical future edit that
14409 // accidentally set two of the three consts to the same byte
14410 // (`DEP_SOURCE_TIPO_GIT = "path"` typo matching a peer arm) would
14411 // pass every per-arm serialize pin above but silently collapse
14412 // the discriminator's closed-set arms onto one another; this pin
14413 // catches the collapse at build time.
14414 assert_ne!(
14415 crate::render::DEP_SOURCE_KEY_TIPO,
14416 crate::render::DEP_SOURCE_TIPO_GIT,
14417 );
14418 assert_ne!(
14419 crate::render::DEP_SOURCE_KEY_TIPO,
14420 crate::render::DEP_SOURCE_TIPO_PATH,
14421 );
14422 assert_ne!(
14423 crate::render::DEP_SOURCE_TIPO_GIT,
14424 crate::render::DEP_SOURCE_TIPO_PATH,
14425 );
14426 }
14427
14428 #[test]
14429 fn dep_source_tipo_variant_consts_are_ascii_lowercase_shape() {
14430 // Shape pin against `rename_all` drift: the two variant-tag
14431 // consts must be ASCII-lowercase-only to match the
14432 // `rename_all = "lowercase"` attribute the derive uses; a future
14433 // rebrand to `"UPPERCASE"` / `"PascalCase"` at the attribute
14434 // would emit `"GIT"` / `"Git"` instead and trip this pin.
14435 for (label, s) in [
14436 ("DEP_SOURCE_TIPO_GIT", crate::render::DEP_SOURCE_TIPO_GIT),
14437 ("DEP_SOURCE_TIPO_PATH", crate::render::DEP_SOURCE_TIPO_PATH),
14438 ] {
14439 assert!(!s.is_empty(), "{label} must not be empty");
14440 assert!(
14441 s.bytes().all(|b| b.is_ascii_lowercase()),
14442 "{label} must be ASCII-lowercase-only (matching \
14443 rename_all = \"lowercase\"), got {s:?}",
14444 );
14445 }
14446 }
14447
14448 // ── per-entry :caracteristicas set-not-multiset gate ────────────
14449 //
14450 // Every Vec-keyed-by-name authoring surface on the typed Caixa
14451 // surface that identifies its entries by a name field now uniformly
14452 // closes the set-not-multiset discipline at build time (cite
14453 // `validate_caracteristicas`'s peer-axis enumeration). The
14454 // `:caracteristicas` axis is per-`Dep`: the feature-toggle slot is
14455 // set-shaped (a feature is either enabled or not — there is no
14456 // `feature × 2` semantic), so two entries naming the same feature
14457 // are a redundant declaration the caixa-resolver's lacre pipeline
14458 // would silently dedup at resolve time. The empty-feature arm
14459 // closes the parallel "operationally-meaningless value" axis on
14460 // the same slot. Same linear-walk + `HashSet` + first-collision
14461 // shape every peer set gate uses; same empty-first cascade every
14462 // peer per-entry shape + duplicate gate uses (the empty-feature
14463 // axis is the more-actionable defect since two `""` entries would
14464 // both report `caracteristica: ""` under a duplicate-first
14465 // ordering, with no way to distinguish the offending site).
14466
14467 fn dep_with_features(features: &[&str]) -> Dep {
14468 Dep {
14469 nome: "caixa-teia".into(),
14470 versao: "^0.1".into(),
14471 fonte: None,
14472 opcional: false,
14473 caracteristicas: features.iter().map(|s| (*s).into()).collect(),
14474 }
14475 }
14476
14477 #[test]
14478 fn validate_rejects_empty_caracteristica() {
14479 // Fail-before-pass-after pin: every pre-gate codebase accepted
14480 // `(:caracteristicas (""))` cleanly (the `Vec<String>` field
14481 // imposed no per-entry shape contract), the dep validated, and
14482 // the empty feature would have reached the future caixa-resolver
14483 // lacre pipeline as a no-op feature enable — silently dropping
14484 // the author's intent far from the source `caixa.lisp`. The new
14485 // gate surfaces the structural defect at the typed-validate
14486 // surface with a self-locating diagnostic naming the offending
14487 // dep's `:nome`.
14488 let d = dep_with_features(&[""]);
14489 assert!(
14490 matches!(d.validate().unwrap_err(), DepError::CaracteristicaEmpty { ref nome } if nome == "caixa-teia"),
14491 "expected CaracteristicaEmpty, got {:?}",
14492 d.validate(),
14493 );
14494 }
14495
14496 #[test]
14497 fn validate_rejects_duplicate_caracteristica() {
14498 // Fail-before-pass-after pin on the set-not-multiset arm: the
14499 // feature-toggle slot is set-shaped, so `(:caracteristicas
14500 // ("http" "http"))` is a redundant declaration the lacre
14501 // pipeline dedupes silently at resolve time. The diagnostic
14502 // names the offending dep + the colliding feature verbatim so
14503 // the author can grep their caixa.lisp for `:caracteristicas`
14504 // and fix it in one edit. First-collision determinism is
14505 // pinned separately below.
14506 let d = dep_with_features(&["http", "http"]);
14507 assert!(
14508 matches!(
14509 d.validate().unwrap_err(),
14510 DepError::CaracteristicaDuplicate { ref nome, ref caracteristica }
14511 if nome == "caixa-teia" && caracteristica == "http"
14512 ),
14513 "expected CaracteristicaDuplicate, got {:?}",
14514 d.validate(),
14515 );
14516 }
14517
14518 #[test]
14519 fn validate_accepts_distinct_caracteristicas() {
14520 // The canonical authoring shape — every feature distinct — must
14521 // remain a clean pass (positive control sweep). Covers the
14522 // canonical kebab-case feature names a target caixa typically
14523 // declares.
14524 dep_with_features(&["http", "json", "tls"])
14525 .validate()
14526 .unwrap();
14527 }
14528
14529 #[test]
14530 fn validate_accepts_single_caracteristica() {
14531 // Single-element list is the minimum non-empty shape; passes
14532 // the gate as the identity of the duplicate check (no second
14533 // entry to collide with).
14534 dep_with_features(&["http"]).validate().unwrap();
14535 }
14536
14537 #[test]
14538 fn validate_accepts_empty_caracteristicas_list() {
14539 // The bare-dep authoring shape (`Dep::simple` / `Dep::git`)
14540 // produces `caracteristicas: Vec::new()`; the empty list is
14541 // the gate's empty-set identity and passes vacuously. Pin
14542 // this so a future tightening that requires ≥1 feature
14543 // surfaces here as a test failure rather than a silent
14544 // contract narrowing.
14545 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14546 assert!(dep_with_features(&[]).validate().is_ok());
14547 }
14548
14549 #[test]
14550 fn validate_caracteristica_empty_fires_before_duplicate() {
14551 // Empty-first cascade: an entry with an empty feature *and*
14552 // duplicate entries surfaces the empty diagnostic first. The
14553 // empty-feature axis is the more-actionable defect since
14554 // `caracteristica: ""` is unambiguous; under duplicate-first
14555 // ordering the diagnostic could report the empty string from
14556 // either of two empty entries with no way to distinguish.
14557 // Mirrors the peer empty-before-duplicate ordering
14558 // discipline every per-entry shape + duplicate gate establishes
14559 // (`SupervisorSpec::validate`'s `EmptyChildName` arm before
14560 // `DuplicateChildCaixa`, `validate_membros`'s
14561 // `MembroCaixaEmpty` arm before `MembroDuplicate`).
14562 let d = dep_with_features(&["", "http", "http"]);
14563 assert!(matches!(
14564 d.validate().unwrap_err(),
14565 DepError::CaracteristicaEmpty { .. }
14566 ));
14567 }
14568
14569 #[test]
14570 fn validate_caracteristica_duplicate_first_collision_determinism() {
14571 // Three matching entries: the second occurrence surfaces the
14572 // diagnostic (the second is the first *collision* — the first
14573 // entry is the establishing one, not a duplicate). Mirrors
14574 // every peer first-collision posture
14575 // (`SupervisorError::DuplicateChildCaixa` reports the second
14576 // collision, `AplicacaoError::MembroDuplicate` reports the
14577 // second, `DepError::DuplicateNome` reports the second).
14578 // Pinning this so a future shortcut that flips to last-
14579 // collision (or non-deterministic) surfaces here.
14580 let d = dep_with_features(&["http", "http", "http"]);
14581 assert!(matches!(
14582 d.validate().unwrap_err(),
14583 DepError::CaracteristicaDuplicate { ref caracteristica, .. } if caracteristica == "http"
14584 ));
14585 }
14586
14587 #[test]
14588 fn validate_per_entry_shape_fires_before_caracteristicas() {
14589 // Per-entry shape precedence: a dep with a malformed `:nome`
14590 // (uppercase) AND duplicate `:caracteristicas` surfaces the
14591 // narrower `NomeInvalid` diagnostic first, not the set-gate
14592 // diagnostic. The `:nome` is the self-locating axis (every
14593 // diagnostic from the caracteristicas gate quotes the
14594 // offending dep's `:nome` to anchor the grep target —
14595 // surfacing the malformed name first keeps that anchor
14596 // valid). Same precedence shape every peer per-entry-shape
14597 // arm establishes against its peer set-gate
14598 // (`validate_deps_per_entry_validate_fires_before_duplicate_in_deps`
14599 // on the cross-entry `:nome` axis).
14600 let d = Dep {
14601 nome: "Caixa-Teia".into(), // uppercase — DNS-1123 violation
14602 versao: "^0.1".into(),
14603 fonte: None,
14604 opcional: false,
14605 caracteristicas: vec!["http".into(), "http".into()],
14606 };
14607 assert!(matches!(
14608 d.validate().unwrap_err(),
14609 DepError::NomeInvalid { .. }
14610 ));
14611 }
14612
14613 // ── per-entry :caracteristicas value-shape gate ──────────────────
14614 //
14615 // Until this gate landed `:caracteristicas` only refused the empty
14616 // string and cross-entry duplicates: a non-empty distinct but
14617 // structurally invalid feature name silently passed validate and the
14618 // failure surfaced at `cargo metadata` time as Cargo's
14619 // `restricted_names::validate_feature_name` parser rejection, far from
14620 // the source `caixa.lisp` with no field naming which `:deps` entry's
14621 // `:caracteristicas` carried the typo. The lifted predicate makes the
14622 // Cargo-feature-name-grammar intersection-floor a substrate-level
14623 // invariant at validate time. Same trajectory as the eight peer
14624 // value-shape predicates each typed surface downstream of a structured
14625 // grammar already follows.
14626
14627 #[test]
14628 fn validate_rejects_caracteristica_with_leading_plus() {
14629 // Fail-before-pass-after pin on the canonical Cargo
14630 // `+<feature>` activation-form-in-feature-name-slot footgun.
14631 // Cargo's `[dependencies.<dep>.features]` list grammar accepts
14632 // `+optional-feature` as an enablement of a previously-disabled
14633 // feature; pasting that activation form into `:caracteristicas`
14634 // (which names the feature itself) silently passed pre-gate and
14635 // failed at `cargo metadata` parse time.
14636 let d = dep_with_features(&["+http"]);
14637 let err = d.validate().unwrap_err();
14638 assert!(
14639 matches!(
14640 err,
14641 DepError::CaracteristicaInvalid { ref nome, ref caracteristica, .. }
14642 if nome == "caixa-teia" && caracteristica == "+http"
14643 ),
14644 "expected CaracteristicaInvalid, got {err:?}"
14645 );
14646 }
14647
14648 #[test]
14649 fn validate_rejects_caracteristica_with_leading_hyphen() {
14650 // Fail-before-pass-after pin on the leading-hyphen footgun. `-`
14651 // is a legitimate continuation character (kebab-case feature
14652 // names like `runtime-tokio` pass) but Cargo rejects it at the
14653 // start; the structural defect — and its CLI-argument-injection
14654 // adjacency at any downstream Cargo subprocess invocation — is
14655 // closed at validate time, not at `cargo metadata` time.
14656 let d = dep_with_features(&["-json"]);
14657 let err = d.validate().unwrap_err();
14658 assert!(
14659 matches!(
14660 err,
14661 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "-json"
14662 ),
14663 "expected CaracteristicaInvalid, got {err:?}"
14664 );
14665 }
14666
14667 #[test]
14668 fn validate_rejects_caracteristica_with_leading_dot() {
14669 // Fail-before-pass-after pin on the leading-dot footgun. `.` is
14670 // a legitimate continuation character (version-suffix shapes
14671 // like `feat.v2` pass) but the leading-dot form is the
14672 // canonical dotted-version-suffix-as-feature-name confusion.
14673 let d = dep_with_features(&[".feat"]);
14674 let err = d.validate().unwrap_err();
14675 assert!(matches!(
14676 err,
14677 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == ".feat"
14678 ));
14679 }
14680
14681 #[test]
14682 fn validate_rejects_caracteristica_with_whitespace() {
14683 // Fail-before-pass-after pin on the embedded-whitespace footgun:
14684 // a feature name with a space inside is structurally a multi-
14685 // token blob (the canonical paste-from-doc footgun, or an
14686 // accidental `"http server"` where the author meant
14687 // `"http-server"`).
14688 let d = dep_with_features(&["http feature"]);
14689 let err = d.validate().unwrap_err();
14690 assert!(matches!(
14691 err,
14692 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http feature"
14693 ));
14694 }
14695
14696 #[test]
14697 fn validate_rejects_caracteristica_with_comma() {
14698 // Fail-before-pass-after pin on the embedded-comma footgun:
14699 // the list-separator-belongs-to-the-list-grammar
14700 // miscomprehension where the author writes
14701 // `:caracteristicas ("http,json")` intending two features but
14702 // the `Vec<String>` field consumes the bare token as one entry.
14703 let d = dep_with_features(&["http,json"]);
14704 let err = d.validate().unwrap_err();
14705 assert!(matches!(
14706 err,
14707 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http,json"
14708 ));
14709 }
14710
14711 #[test]
14712 fn validate_rejects_caracteristica_with_slash() {
14713 // Fail-before-pass-after pin on the embedded-slash footgun:
14714 // Cargo's `dep/feat` namespaced-dep syntax applies inside
14715 // `[dependencies.<dep>.features]` list entries that already
14716 // name the parent dep (so the syntax says "enable feature
14717 // `feat` on a transitive dep `dep`"); `:caracteristicas` is
14718 // per-dep already (a sibling slot on the `Dep` itself), so the
14719 // segment separator within an entry must be `-`, `_`, `+`,
14720 // or `.`. The diagnostic remediation points at the canonical
14721 // Cargo namespaced-dep discipline.
14722 let d = dep_with_features(&["http/json"]);
14723 let err = d.validate().unwrap_err();
14724 assert!(matches!(
14725 err,
14726 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http/json"
14727 ));
14728 }
14729
14730 #[test]
14731 fn validate_rejects_caracteristica_with_non_ascii() {
14732 // Fail-before-pass-after pin on the un-percent-encoded non-ASCII
14733 // byte footgun: NFC-vs-NFD normalization across filesystems
14734 // silently rewrites the feature-key, breaking the lacre's
14735 // content-addressing invariant. Pinned at a canonical
14736 // smart-quote-paste shape (`café`) where the raw `é` byte is the
14737 // documented APFS round-trip break.
14738 let d = dep_with_features(&["caf\u{e9}"]);
14739 let err = d.validate().unwrap_err();
14740 assert!(matches!(
14741 err,
14742 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "caf\u{e9}"
14743 ));
14744 }
14745
14746 #[test]
14747 fn validate_rejects_caracteristica_with_control_character() {
14748 // Fail-before-pass-after pin on the embedded-control-character
14749 // footgun: a CR/LF or any 0x00..0x1F / 0x7F byte landing in a
14750 // feature name is the canonical paste-from-multiline-doc
14751 // footgun the predicate's reason wording specifically calls out.
14752 let d = dep_with_features(&["http\njson"]);
14753 let err = d.validate().unwrap_err();
14754 assert!(matches!(err, DepError::CaracteristicaInvalid { .. }));
14755 }
14756
14757 #[test]
14758 fn validate_accepts_canonical_caracteristicas_shapes() {
14759 // Positive control sweep: every canonical Cargo feature name
14760 // shape the pleme-io ecosystem uses must still pass. Mirrors
14761 // the substrate-side `cargo_feature_name_accepts_canonical_forms`
14762 // sweep — drift between either landing site and the predicate's
14763 // accepted set is a build error visible at this pair of tests,
14764 // not a per-renderer "this passed validate but failed at
14765 // cargo metadata time" surprise on the next acceptance.
14766 for s in [
14767 "http",
14768 "json",
14769 "derive",
14770 "serde_json",
14771 "runtime-tokio",
14772 "tokio.full",
14773 "v0.1",
14774 "http+json",
14775 "_internal",
14776 "__private",
14777 "default",
14778 "rt-multi-thread",
14779 "feat.v2",
14780 ] {
14781 let d = dep_with_features(&[s]);
14782 d.validate().unwrap_or_else(|e| {
14783 panic!("canonical Cargo feature name {s:?} must pass validate: {e:?}")
14784 });
14785 }
14786 }
14787
14788 #[test]
14789 fn validate_caracteristica_empty_fires_before_invalid() {
14790 // Cascade precedence pin: an entry list with both an empty
14791 // feature AND an invalid-shape feature surfaces the
14792 // `CaracteristicaEmpty` arm first (the empty value carries no
14793 // self-locating data — `caracteristica: ""` is the diagnostic
14794 // with no way to anchor a grep target — so closing the empty
14795 // axis first preserves the per-entry-shape diagnostic's
14796 // self-locating discipline). Same empty-first cascade every
14797 // peer per-entry shape gate establishes
14798 // (`SupervisorSpec::validate`'s `EmptyChildName` before
14799 // `ChildCaixaInvalid`, `validate_membros`'s `MembroCaixaEmpty`
14800 // before `MembroCaixaInvalid`).
14801 let d = dep_with_features(&["", "+http"]);
14802 assert!(matches!(
14803 d.validate().unwrap_err(),
14804 DepError::CaracteristicaEmpty { .. }
14805 ));
14806 }
14807
14808 #[test]
14809 fn validate_caracteristica_invalid_fires_before_duplicate() {
14810 // Per-entry-shape precedence pin: an entry list with the same
14811 // invalid feature shape declared twice surfaces the
14812 // `CaracteristicaInvalid` diagnostic on the first entry, not
14813 // the `CaracteristicaDuplicate` on the second collision. The
14814 // per-entry shape gate fires before the cross-entry set gate
14815 // — same precedence shape every peer two-arm-plus-set gate
14816 // establishes (`SupervisorSpec::validate`'s
14817 // `ChildCaixaInvalid` before `DuplicateChildCaixa`,
14818 // `validate_membros`'s `MembroCaixaInvalid` before
14819 // `MembroDuplicate`, `Dep::validate`'s `NomeInvalid` before
14820 // cross-list `DuplicateNome`).
14821 let d = dep_with_features(&["+http", "+http"]);
14822 assert!(matches!(
14823 d.validate().unwrap_err(),
14824 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "+http"
14825 ));
14826 }
14827
14828 #[test]
14829 fn validate_rejects_caracteristica_at_65_byte_boundary() {
14830 // Boundary pin on the 64-byte cap — both the boundary-accepting
14831 // case and the boundary-exceeding case in one place, so a
14832 // future cap shift surfaces both arms simultaneously, mirroring
14833 // the peer `cargo_feature_name_rejects_at_65_byte_boundary`
14834 // predicate-level pin at the dep-axis landing site.
14835 let max_ok = "a".repeat(64);
14836 dep_with_features(&[&max_ok])
14837 .validate()
14838 .unwrap_or_else(|e| panic!("64-byte feature name must pass: {e:?}"));
14839 let too_long = "a".repeat(65);
14840 let d = dep_with_features(&[&too_long]);
14841 assert!(matches!(
14842 d.validate().unwrap_err(),
14843 DepError::CaracteristicaInvalid { .. }
14844 ));
14845 }
14846
14847 // ── self-dep cross-slot gate ─────────────────────────────────────
14848
14849 #[test]
14850 fn validate_no_self_dep_rejects_self_in_deps() {
14851 // A caixa whose `:deps` lists its own `:nome` is a one-node
14852 // cycle in the lacre closure's dep-graph traversal — rejected,
14853 // naming the parent and the offending list tag.
14854 let deps = vec![
14855 Dep::simple("caixa-teia", "^0.1"),
14856 Dep::simple("orquestra", "^0.1"),
14857 ];
14858 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
14859 assert!(
14860 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14861 "got {err:?}"
14862 );
14863 }
14864
14865 #[test]
14866 fn validate_no_self_dep_rejects_self_in_deps_dev() {
14867 // Same gate on the `:deps-dev` axis — neither dep list is a
14868 // second-class citizen on the self-edge invariant.
14869 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14870 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
14871 assert!(
14872 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14873 "got {err:?}"
14874 );
14875 }
14876
14877 #[test]
14878 fn validate_no_self_dep_deps_fires_before_deps_dev() {
14879 // Walk order pin: a caixa that self-references on both lists
14880 // surfaces the `:deps` arm first — the load-bearing axis the
14881 // lacre closure resolves at every build. Mirrors the canonical
14882 // [`Caixa::validate_deps`] cascade (`:deps` → `:deps-dev`).
14883 let deps = vec![Dep::simple("orquestra", "^0.1")];
14884 let deps_dev = vec![Dep::simple("orquestra", "^0.2")];
14885 let err = validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap_err();
14886 assert!(
14887 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
14888 "got {err:?}"
14889 );
14890 }
14891
14892 #[test]
14893 fn validate_no_self_dep_accepts_distinct_names() {
14894 // Positive control: every dep names a distinct caixa. The
14895 // canonical author surface — peer of
14896 // [`validate_no_self_supervision_accepts_distinct_children`].
14897 let deps = vec![
14898 Dep::simple("caixa-teia", "^0.1"),
14899 Dep::simple("caixa-arch", "^0.1"),
14900 ];
14901 let deps_dev = vec![Dep::simple("caixa-test", "^0.1")];
14902 validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap();
14903 }
14904
14905 #[test]
14906 fn validate_no_self_dep_empty_lists_pass() {
14907 // A caixa with no declared deps has nothing to self-reference —
14908 // the gate is vacuously satisfied. Peer of
14909 // [`validate_no_self_supervision_empty_children_is_ok`].
14910 validate_no_self_dep(&[], &[], "orquestra").unwrap();
14911 }
14912
14913 #[test]
14914 fn validate_no_self_dep_diagnostic_carries_offending_list_and_nome() {
14915 // Diagnostic-shape pin (peer with
14916 // [`validate_no_self_supervision`]'s diagnostic): the error's
14917 // Display surfaces both the offending list tag and the
14918 // parent's `:nome` verbatim, so the author can grep their
14919 // caixa.lisp for the offending block in one edit. Names
14920 // `:bibliotecas` / `:exe` / `:servicos` as the corrective
14921 // surface — every legitimate "I want to use code from this
14922 // caixa" intent routes through one of those three slots.
14923 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
14924 let rendered = validate_no_self_dep(&[], &deps_dev, "orquestra")
14925 .unwrap_err()
14926 .to_string();
14927 assert!(
14928 rendered.contains(crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
14929 "diagnostic must name the offending list tag: {rendered}",
14930 );
14931 assert!(
14932 rendered.contains("orquestra"),
14933 "diagnostic must quote the parent caixa name: {rendered}",
14934 );
14935 assert!(
14936 rendered.contains(":bibliotecas"),
14937 "diagnostic must point at the corrective code-surface slot: {rendered}",
14938 );
14939 }
14940
14941 #[test]
14942 fn validate_no_self_dep_accepts_coincidental_substring_match() {
14943 // Identity is exact-string equality, not substring — a dep
14944 // named `"orquestra-helper"` is a distinct caixa even when the
14945 // parent is `"orquestra"`. Pin the exact-match discipline so a
14946 // future relaxation that uses `contains` surfaces here, peer
14947 // with the supervision-tree and Aplicacao-membership gates
14948 // which all use exact-string equality on the typed identity.
14949 let deps = vec![Dep::simple("orquestra-helper", "^0.1")];
14950 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
14951 }
14952
14953 // ── drift-detection: DEP_AUTHOR_KEY_{DEPS,DEPS_DEV} pin ─────────────
14954
14955 #[test]
14956 fn dep_author_key_consts_pin_canonical_kebab_case_labels() {
14957 // Scalar-value pin: the two author-facing kebab-case labels the
14958 // `(defcaixa … :deps ((…)) :deps-dev ((…)))` surface admits on
14959 // the two-list dep-graph slot axis, one arm per typed slot.
14960 // Mirrors the peer scalar-value pin the sibling
14961 // [`crate::M2_AUTHOR_KEY_LIMITS`] /
14962 // [`crate::M2_AUTHOR_KEY_BEHAVIOR`] /
14963 // [`crate::M2_AUTHOR_KEY_UPGRADE_FROM`] (f49c8b0) M2 top-level
14964 // author-labels, [`crate::M3_AUTHOR_KEY_MEMBROS`] etc.
14965 // (882f498) M3 top-level author-labels, and
14966 // [`crate::SUPERVISOR_AUTHOR_KEY_ESTRATEGIA`] etc. (be40492)
14967 // Supervisor top-level author-labels carry, so every kind-scoped
14968 // typed-slot-family axis routes through one canonical per-arm
14969 // declaration.
14970 //
14971 // A future rebrand (`:deps` → `:dependencies` matching Cargo's
14972 // verbatim key, `:deps-dev` → `:dev-dependencies` matching the
14973 // same, `:deps` / `:deps-dev` → `:runtime-deps` / `:dev-deps`
14974 // for symmetry) lands as an edit to exactly one const, and
14975 // every consumer that reaches for the label picks it up at
14976 // build time rather than at runtime as a downstream mismatch on
14977 // a `DepError::DuplicateNome { list: … }` diagnostic far from
14978 // the rename's commit.
14979 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS, ":deps");
14980 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS_DEV, ":deps-dev");
14981 }
14982
14983 #[test]
14984 fn dep_author_key_consts_are_pairwise_distinct() {
14985 // Distinct-labels pin: the two `:deps` / `:deps-dev` labels
14986 // must not collapse onto one byte-string. A future copy-paste
14987 // slip that renamed both consts to the same value (or a rebrand
14988 // that dropped the `-dev` suffix from one but not the other)
14989 // would leave every `DepError::DuplicateNome { list: … }`
14990 // diagnostic naming an unattributable list — the linter would
14991 // route the author to the wrong caixa.lisp block, or the
14992 // cross-list precedence gate
14993 // (`validate_deps_duplicate_in_deps_fires_before_duplicate_in_deps_dev`)
14994 // would surface a `:deps`-tagged diagnostic on a `:deps-dev`
14995 // duplicate. Peer of the sibling
14996 // `m2_author_key_consts_are_pairwise_distinct`-shape gates the
14997 // other top-level kind-scoped slot-family axes carry
14998 // (implicitly held by their different byte-values today).
14999 assert_ne!(
15000 crate::render::DEP_AUTHOR_KEY_DEPS,
15001 crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15002 "DEP_AUTHOR_KEY_{{DEPS,DEPS_DEV}} consts must be pairwise-distinct \
15003 so a `DepError::DuplicateNome {{ list: … }}` diagnostic \
15004 self-locates the offending block in the author's caixa.lisp",
15005 );
15006 }
15007
15008 #[test]
15009 fn validate_no_self_dep_routes_through_lifted_dep_author_key_consts() {
15010 // Production-through-const pin: the two per-arm list tags
15011 // [`validate_no_self_dep`] threads onto the `list:` field of a
15012 // returned [`DepError::DepIsSelf`] route through the lifted
15013 // [`crate::DEP_AUTHOR_KEY_DEPS`] /
15014 // [`crate::DEP_AUTHOR_KEY_DEPS_DEV`] consts. A future drift at
15015 // the walker (a rename that reaches one arm but not the const,
15016 // or vice versa) surfaces here at build time rather than at
15017 // runtime as a `feira lint` diagnostic naming the wrong list
15018 // tag. Mirror of the peer
15019 // [`crate::Caixa::declared_servico_slots`] production tagger
15020 // pin (f49c8b0) on the sibling M2 top-level slot axis, extended
15021 // onto the two-list dep-graph gate.
15022 let deps = vec![Dep::simple("orquestra", "^0.1")];
15023 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15024 let DepError::DepIsSelf { list, .. } = err else {
15025 panic!("expected DepIsSelf from :deps walk");
15026 };
15027 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS);
15028
15029 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15030 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15031 let DepError::DepIsSelf { list, .. } = err else {
15032 panic!("expected DepIsSelf from :deps-dev walk");
15033 };
15034 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS_DEV);
15035 }
15036
15037 // ── Dep::nome accessor pins ───────────────────────────────────────
15038 //
15039 // Three coherence pins on the lifted `Dep::nome` accessor: byte-equal
15040 // projection over the plain-shorthand / explicit-git / explicit-path
15041 // fixture triad the [`Dep`] docstring lists (so the accessor's
15042 // accept-set is exercised across every author-surface `:fonte`
15043 // shape); by-borrow pointer identity so the projection stays
15044 // zero-copy at every consumer site; and validate-composition through
15045 // the [`validate_no_self_dep`] cross-slot gate reading its
15046 // parent-name equality check through the lifted accessor rather than
15047 // the raw field.
15048
15049 #[test]
15050 fn dep_nome_returns_declared_nome_across_fonte_shapes() {
15051 // Plain-shorthand form (`:fonte None`).
15052 assert_eq!(Dep::simple("caixa-teia", "^0.1").nome(), "caixa-teia");
15053 // Explicit git-source form with a tag pin — same accessor path.
15054 assert_eq!(
15055 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").nome(),
15056 "caixa-teia",
15057 );
15058 // Explicit path-source form.
15059 assert_eq!(
15060 Dep {
15061 nome: "caixa-teia".to_string(),
15062 versao: "0.1.0".to_string(),
15063 fonte: Some(DepSource::Path {
15064 caminho: "../caixa-teia".to_string(),
15065 }),
15066 opcional: false,
15067 caracteristicas: Vec::new(),
15068 }
15069 .nome(),
15070 "caixa-teia",
15071 );
15072 // The empty-string `:nome` sentinel (which [`Dep::validate`]
15073 // refuses through the [`DepError::NomeEmpty`] arm) still round-
15074 // trips as an empty `&str` through the accessor — the accessor is
15075 // a projection, not a gate; the gate is [`Dep::validate`].
15076 assert_eq!(Dep::simple("", "^0.1").nome(), "");
15077 }
15078
15079 #[test]
15080 fn dep_nome_is_by_borrow_pointer_identity() {
15081 // Zero-copy pin: the accessor must borrow into the field's own
15082 // storage, not clone. If a future rewrite regresses to
15083 // `self.nome.clone().leak()` or an owned-buffer shape, the two
15084 // pointers diverge and this pin fails at build time.
15085 let d = Dep::simple("caixa-teia", "^0.1");
15086 assert!(std::ptr::eq(d.nome().as_ptr(), d.nome.as_ptr()));
15087 }
15088
15089 // ── Dep::versao_requirement accessor pins ─────────────────────────
15090 //
15091 // Three coherence pins on the lifted `Dep::versao_requirement`
15092 // accessor: byte-equal projection over the plain-shorthand /
15093 // explicit-git / explicit-path fixture triad the [`Dep`] docstring
15094 // lists plus the empty-sentinel that round-trips as `""` (the accessor
15095 // is a projection, not a gate; the gate is [`Dep::validate`]); by-
15096 // borrow pointer identity so the projection stays zero-copy at every
15097 // consumer site; and validate-composition through the
15098 // [`crate::render::require_valid_versao_requirement`] cascade reading
15099 // its requirement-shape check through the lifted accessor rather than
15100 // the raw field.
15101 #[test]
15102 fn dep_versao_requirement_returns_declared_versao_across_fonte_shapes() {
15103 // Plain-shorthand form (`:fonte None`).
15104 assert_eq!(
15105 Dep::simple("caixa-teia", "^0.1").versao_requirement(),
15106 "^0.1",
15107 );
15108 // Explicit git-source form with a tag pin — same accessor path.
15109 assert_eq!(
15110 Dep::git(
15111 "caixa-teia",
15112 "~0.1.2",
15113 "github:pleme-io/caixa-teia",
15114 "v0.1.0"
15115 )
15116 .versao_requirement(),
15117 "~0.1.2",
15118 );
15119 // Explicit path-source form.
15120 assert_eq!(
15121 Dep {
15122 nome: "caixa-teia".to_string(),
15123 versao: "0.1.0".to_string(),
15124 fonte: Some(DepSource::Path {
15125 caminho: "../caixa-teia".to_string(),
15126 }),
15127 opcional: false,
15128 caracteristicas: Vec::new(),
15129 }
15130 .versao_requirement(),
15131 "0.1.0",
15132 );
15133 // The wildcard requirement (`"*"`) — the shorthand
15134 // `parse_requirement` accepts as `VersionReq::STAR` — round-trips
15135 // verbatim through the accessor as `"*"`, same byte-shape the
15136 // author wrote.
15137 assert_eq!(Dep::simple("caixa-teia", "*").versao_requirement(), "*");
15138 // The empty-string `:versao` sentinel (which [`Dep::validate`]
15139 // refuses through the [`DepError::VersaoEmpty`] arm) still round-
15140 // trips as an empty `&str` through the accessor — the accessor is
15141 // a projection, not a gate; the gate is [`Dep::validate`]. Peer
15142 // of the sibling [`Dep::nome`] empty-sentinel round-trip pin.
15143 assert_eq!(Dep::simple("caixa-teia", "").versao_requirement(), "");
15144 }
15145
15146 #[test]
15147 fn dep_versao_requirement_is_by_borrow_pointer_identity() {
15148 // Zero-copy pin: the accessor must borrow into the field's own
15149 // storage, not clone. If a future rewrite regresses to
15150 // `self.versao.clone().leak()` or an owned-buffer shape, the two
15151 // pointers diverge and this pin fails at build time. Peer of the
15152 // sibling [`Dep::nome`] pointer-identity pin — same by-borrow
15153 // discipline extended onto the requirement-carrying axis.
15154 let d = Dep::simple("caixa-teia", "^0.1");
15155 assert!(std::ptr::eq(
15156 d.versao_requirement().as_ptr(),
15157 d.versao.as_ptr(),
15158 ));
15159 }
15160
15161 #[test]
15162 fn dep_validate_reads_requirement_through_accessor() {
15163 // Composition pin: the [`Dep::validate`]
15164 // [`crate::render::require_valid_versao_requirement`] cascade
15165 // consumes the requirement string through the lifted accessor —
15166 // both the requirement-gate input and the
15167 // [`DepError::VersaoInvalid`] error-body carrier route through
15168 // `self.versao_requirement()`. A valid requirement passes
15169 // (positive control); a malformed-but-non-empty requirement fails
15170 // and the diagnostic quotes the offending byte-string verbatim
15171 // (same shape the accessor projects), so a future regression that
15172 // detoured the requirement carrier through a different byte-
15173 // string (say the parsed `VersionReq`'s `Display`, or a
15174 // normalized rewrite) would surface here at build time. The
15175 // empty-`:versao` arm fires the [`DepError::VersaoEmpty`] variant
15176 // ahead of the parse arm, pinning the empty-first cascade the
15177 // accessor's `""` sentinel round-trip acknowledges.
15178 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15179 let err = Dep::simple("caixa-teia", "v0.1").validate().unwrap_err();
15180 assert!(
15181 matches!(
15182 &err,
15183 DepError::VersaoInvalid {
15184 nome,
15185 versao,
15186 ..
15187 } if nome == "caixa-teia" && versao == "v0.1",
15188 ),
15189 "expected VersaoInvalid quoting the accessor-projected requirement, got {err:?}",
15190 );
15191 let err = Dep::simple("caixa-teia", "").validate().unwrap_err();
15192 assert!(
15193 matches!(
15194 &err,
15195 DepError::VersaoEmpty { nome } if nome == "caixa-teia",
15196 ),
15197 "expected VersaoEmpty from the empty-first arm, got {err:?}",
15198 );
15199 }
15200
15201 // ── Dep::fonte accessor pins ──────────────────────────────────────
15202 //
15203 // Three coherence pins on the lifted `Dep::fonte` accessor: byte-
15204 // equal projection over the plain-shorthand (`:fonte None`) /
15205 // explicit-git-tag / explicit-path fixture triad the [`Dep`]
15206 // docstring lists (so the accessor's accept-set is exercised across
15207 // every author-surface `:fonte` shape and both `DepSource` variants);
15208 // pointer identity so the borrowed reference points into the field's
15209 // own `Option<DepSource>` storage (not a cloned side-buffer); and
15210 // validate-composition through the [`Dep::validate`] gate reading
15211 // its per-`:fonte` [`DepSource::validate`] delegation through the
15212 // lifted accessor rather than the raw `if let Some(ref fonte) =
15213 // self.fonte` bracket.
15214
15215 #[test]
15216 fn dep_fonte_returns_declared_source_across_shapes() {
15217 // Plain-shorthand form — `:fonte` omitted, accessor projects
15218 // the `None` partition the resolver-side default-fill treats
15219 // as "resolve through `github:<default-org>/<nome>`".
15220 assert!(Dep::simple("caixa-teia", "^0.1").fonte().is_none());
15221 // Explicit git-source form with a tag pin — same accessor path.
15222 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15223 match git.fonte() {
15224 Some(DepSource::Git {
15225 repo,
15226 tag,
15227 rev,
15228 branch,
15229 }) => {
15230 assert_eq!(repo, "github:pleme-io/caixa-teia");
15231 assert_eq!(tag.as_deref(), Some("v0.1.0"));
15232 assert!(rev.is_none());
15233 assert!(branch.is_none());
15234 }
15235 other => panic!("expected explicit git :fonte, got {other:?}"),
15236 }
15237 // Explicit path-source form — the dev-only local-filesystem
15238 // arm the [`Dep`] docstring's third fixture carries.
15239 let path = Dep {
15240 nome: "caixa-teia".to_string(),
15241 versao: "0.1.0".to_string(),
15242 fonte: Some(DepSource::Path {
15243 caminho: "../caixa-teia".to_string(),
15244 }),
15245 opcional: false,
15246 caracteristicas: Vec::new(),
15247 };
15248 match path.fonte() {
15249 Some(DepSource::Path { caminho }) => {
15250 assert_eq!(caminho, "../caixa-teia");
15251 }
15252 other => panic!("expected explicit path :fonte, got {other:?}"),
15253 }
15254 }
15255
15256 #[test]
15257 fn dep_fonte_is_by_borrow_pointer_identity() {
15258 // Zero-copy pin: the accessor must borrow into the field's own
15259 // `Option<DepSource>` storage, not clone into a side buffer. If
15260 // a future rewrite regresses to `self.fonte.clone()` or an
15261 // owned-buffer shape, the two pointers diverge and this pin
15262 // fails at build time. Peer of the sibling per-`Dep` [`Dep::nome`]
15263 // (eba2cde) / [`Dep::versao_requirement`] (05529b1) pointer-
15264 // identity pins — same by-borrow discipline extended onto the
15265 // outer-`Dep` `Option<&Composite>` composite-reference axis.
15266 let d = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15267 let accessed = d.fonte().expect("git :fonte present") as *const DepSource;
15268 let raw = d.fonte.as_ref().expect("git :fonte present") as *const DepSource;
15269 assert!(std::ptr::eq(accessed, raw));
15270 }
15271
15272 #[test]
15273 fn dep_validate_reads_fonte_through_accessor() {
15274 // Composition pin: [`Dep::validate`]'s per-`:fonte`
15275 // [`DepSource::validate`] delegation consumes the typed slot
15276 // through the lifted accessor — an author-omitted `:fonte`
15277 // still passes the outer gate (positive control), an explicit
15278 // well-formed git source with exactly one pin passes, and a
15279 // malformed git source (empty `:repo`) surfaces the
15280 // [`DepError::FonteRepoEmpty`] variant quoting the offending
15281 // dep's `:nome` verbatim so a future regression that detoured
15282 // the `:fonte` delegation through a different path (say a
15283 // per-scope override projector) would surface here at build
15284 // time. Peer of the sibling
15285 // `dep_validate_reads_requirement_through_accessor` composition
15286 // pin on the `:versao` axis.
15287 // Positive control 1: no `:fonte` at all.
15288 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15289 // Positive control 2: well-formed git source.
15290 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15291 .validate()
15292 .unwrap();
15293 // Negative control: empty `:repo` — the accessor still returns
15294 // `Some(&DepSource::Git { repo: "", … })` and the delegated
15295 // `DepSource::validate` gate raises the typed carrier.
15296 let bad = Dep {
15297 nome: "caixa-teia".to_string(),
15298 versao: "^0.1".to_string(),
15299 fonte: Some(DepSource::Git {
15300 repo: String::new(),
15301 tag: Some("v0.1.0".to_string()),
15302 rev: None,
15303 branch: None,
15304 }),
15305 opcional: false,
15306 caracteristicas: Vec::new(),
15307 };
15308 let err = bad.validate().unwrap_err();
15309 assert!(
15310 matches!(
15311 &err,
15312 DepError::FonteRepoEmpty { nome } if nome == "caixa-teia",
15313 ),
15314 "expected FonteRepoEmpty from the accessor-routed :fonte gate, got {err:?}",
15315 );
15316 }
15317
15318 #[test]
15319 fn validate_no_self_dep_reads_parent_equality_through_accessor() {
15320 // Composition pin: the cross-slot [`validate_no_self_dep`] gate
15321 // rejects a `:deps` entry whose `:nome` equals the parent caixa's
15322 // own `:nome` through the lifted accessor rather than the raw
15323 // field. Fails-before-passes-after: with the accessor lifted the
15324 // gate reads its equality check through `dep.nome() ==
15325 // parent_nome` on both the `:deps` and `:deps-dev` traversals, so
15326 // the diagnostic still names the offending list tag as expected.
15327 let deps = vec![Dep::simple("orquestra", "^0.1")];
15328 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15329 assert!(matches!(
15330 err,
15331 DepError::DepIsSelf {
15332 ref nome,
15333 list,
15334 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS,
15335 ));
15336 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15337 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15338 assert!(matches!(
15339 err,
15340 DepError::DepIsSelf {
15341 ref nome,
15342 list,
15343 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15344 ));
15345 // A non-matching `:nome` passes through the accessor gate.
15346 let deps = vec![Dep::simple("caixa-teia", "^0.1")];
15347 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15348 }
15349
15350 // ── Dep::caracteristicas accessor pins ────────────────────────────
15351 //
15352 // Three coherence pins on the lifted `Dep::caracteristicas` accessor:
15353 // byte-equal projection over the default-empty / single-entry /
15354 // multi-entry fixture triad (so the accessor's accept-set is
15355 // exercised across every author-surface `:caracteristicas` shape,
15356 // matching the peer sibling family's fixture-triad discipline); by-
15357 // borrow pointer identity so the projection stays zero-copy at every
15358 // consumer site; and validate-composition through the
15359 // [`Dep::validate_caracteristicas`] gate reading its per-entry
15360 // linear walk through the lifted accessor rather than the raw
15361 // `for c in &self.caracteristicas` bracket.
15362
15363 #[test]
15364 fn dep_caracteristicas_returns_declared_features_across_shapes() {
15365 // Default-empty form — the [`Dep::simple`] constructor's
15366 // `Vec::new()` fill; the accessor projects the empty slice
15367 // verbatim (no `None` collapse).
15368 assert!(
15369 Dep::simple("caixa-teia", "^0.1")
15370 .caracteristicas()
15371 .is_empty(),
15372 );
15373 // Single-entry form — the canonical Cargo-shaped one-feature
15374 // enable ([`crate::render::is_cargo_feature_name`] accepts the
15375 // `"http"` byte-string as a valid feature name).
15376 let one = Dep {
15377 nome: "caixa-teia".to_string(),
15378 versao: "^0.1".to_string(),
15379 fonte: None,
15380 opcional: false,
15381 caracteristicas: vec!["http".to_string()],
15382 };
15383 assert_eq!(one.caracteristicas(), &["http".to_string()]);
15384 // Multi-entry form — the substrate's set-shaped multi-feature
15385 // enable, exercising the accessor over a length-two slice with
15386 // no duplicate collapse.
15387 let two = Dep {
15388 nome: "caixa-teia".to_string(),
15389 versao: "^0.1".to_string(),
15390 fonte: None,
15391 opcional: false,
15392 caracteristicas: vec!["http".to_string(), "json".to_string()],
15393 };
15394 assert_eq!(
15395 two.caracteristicas(),
15396 &["http".to_string(), "json".to_string()],
15397 );
15398 }
15399
15400 #[test]
15401 fn dep_caracteristicas_is_by_borrow_pointer_identity() {
15402 // Zero-copy pin: the accessor must borrow into the field's own
15403 // `Vec<String>` storage, not clone into a side buffer. If a
15404 // future rewrite regresses to `self.caracteristicas.clone()` or
15405 // an owned-buffer shape, the two pointers diverge and this pin
15406 // fails at build time. Peer of the sibling per-`Dep`
15407 // [`Dep::nome`] (eba2cde) / [`Dep::versao_requirement`] (05529b1)
15408 // / [`Dep::fonte`] (d65d1bf) pointer-identity pins — same by-
15409 // borrow discipline extended onto the outer-`Dep` `&[String]`
15410 // slice-projection axis.
15411 let d = Dep {
15412 nome: "caixa-teia".to_string(),
15413 versao: "^0.1".to_string(),
15414 fonte: None,
15415 opcional: false,
15416 caracteristicas: vec!["http".to_string(), "json".to_string()],
15417 };
15418 assert!(std::ptr::eq(
15419 d.caracteristicas().as_ptr(),
15420 d.caracteristicas.as_ptr(),
15421 ));
15422 }
15423
15424 #[test]
15425 fn dep_validate_reads_caracteristicas_through_accessor() {
15426 // Composition pin: [`Dep::validate_caracteristicas`]'s per-entry
15427 // linear walk consumes the feature-toggle list through the
15428 // lifted accessor — a well-formed `:caracteristicas` set passes
15429 // (positive control), an empty-string entry surfaces the
15430 // [`DepError::CaracteristicaEmpty`] variant quoting the offending
15431 // `Dep::nome`, and a within-list duplicate surfaces the
15432 // [`DepError::CaracteristicaDuplicate`] variant so a future
15433 // regression that detoured the walk through a different byte-
15434 // string list (say a per-scope override projector) would surface
15435 // here at build time. Peer of the sibling
15436 // `dep_validate_reads_fonte_through_accessor` /
15437 // `dep_validate_reads_requirement_through_accessor` composition
15438 // pins on the `:fonte` / `:versao` axes.
15439 // Positive control: two distinct well-formed feature names pass.
15440 Dep {
15441 nome: "caixa-teia".to_string(),
15442 versao: "^0.1".to_string(),
15443 fonte: None,
15444 opcional: false,
15445 caracteristicas: vec!["http".to_string(), "json".to_string()],
15446 }
15447 .validate()
15448 .unwrap();
15449 // Negative control 1: empty-string feature-name entry — the
15450 // accessor still returns `&[""]` and the walk raises the typed
15451 // empty-first carrier.
15452 let err = Dep {
15453 nome: "caixa-teia".to_string(),
15454 versao: "^0.1".to_string(),
15455 fonte: None,
15456 opcional: false,
15457 caracteristicas: vec![String::new()],
15458 }
15459 .validate()
15460 .unwrap_err();
15461 assert!(
15462 matches!(
15463 &err,
15464 DepError::CaracteristicaEmpty { nome } if nome == "caixa-teia",
15465 ),
15466 "expected CaracteristicaEmpty from the accessor-routed walk, got {err:?}",
15467 );
15468 // Negative control 2: within-list duplicate — the accessor's
15469 // slice view carries both entries, and the walk's dedup arm
15470 // raises the typed duplicate carrier quoting the offending
15471 // feature name verbatim.
15472 let err = Dep {
15473 nome: "caixa-teia".to_string(),
15474 versao: "^0.1".to_string(),
15475 fonte: None,
15476 opcional: false,
15477 caracteristicas: vec!["http".to_string(), "http".to_string()],
15478 }
15479 .validate()
15480 .unwrap_err();
15481 assert!(
15482 matches!(
15483 &err,
15484 DepError::CaracteristicaDuplicate {
15485 nome,
15486 caracteristica,
15487 } if nome == "caixa-teia" && caracteristica == "http",
15488 ),
15489 "expected CaracteristicaDuplicate from the accessor-routed dedup, got {err:?}",
15490 );
15491 }
15492
15493 // ── Dep::opcional accessor pins ───────────────────────────────────
15494 //
15495 // Two coherence pins on the lifted `Dep::opcional` accessor: byte-
15496 // equal projection over the default-`false` / explicit-`true`
15497 // fixture pair across the plain-shorthand (`:fonte None`) / explicit-
15498 // git-tag / explicit-path fixture triad the [`Dep`] docstring lists,
15499 // exercising the accessor's accept-set over every author-surface
15500 // `:fonte` shape × every author-surface `:opcional` shape; and by-
15501 // `Copy` idempotency so the projection stays value-return (no
15502 // silent detour to a fresh `&bool` borrow that would introduce a
15503 // lifetime on the return type the plain-`Copy`-scalar axis's `bool`
15504 // shape elides). No composition pin — `:opcional` does not
15505 // participate in [`Dep::validate`] (an opcional dep with any bool
15506 // value is validate-accepted; the missing-source arm is a resolver-
15507 // side runtime dispatch, not a build-time refusal), so the axis
15508 // reduces to the value-shape + `Copy` pin pair the peer
15509 // [`crate::Caixa::max_restarts`] / [`crate::Caixa::estrategia`]
15510 // outer-`Option<Copy>` accessor pins already carry.
15511
15512 #[test]
15513 fn dep_opcional_returns_declared_opcional_across_fonte_shapes() {
15514 // Default-`false` form via the [`Dep::simple`] constructor —
15515 // the accessor projects the `false` bit the default-fill sets.
15516 assert!(!Dep::simple("caixa-teia", "^0.1").opcional());
15517 // Default-`false` form via the [`Dep::git`] constructor — same
15518 // default fill; the accessor projects `false` regardless of the
15519 // `:fonte` arm.
15520 assert!(!Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").opcional(),);
15521 // Explicit-`true` form × plain-shorthand `:fonte` — the
15522 // canonical author-surface "this dep may be missing" shape.
15523 let plain_true = Dep {
15524 nome: "caixa-teia".to_string(),
15525 versao: "^0.1".to_string(),
15526 fonte: None,
15527 opcional: true,
15528 caracteristicas: Vec::new(),
15529 };
15530 assert!(plain_true.opcional());
15531 // Explicit-`true` form × explicit git-source — the accessor
15532 // projects the bit verbatim regardless of the `:fonte` arm.
15533 let git_true = Dep {
15534 nome: "caixa-teia".to_string(),
15535 versao: "^0.1".to_string(),
15536 fonte: Some(DepSource::Git {
15537 repo: "github:pleme-io/caixa-teia".to_string(),
15538 tag: Some("v0.1.0".to_string()),
15539 rev: None,
15540 branch: None,
15541 }),
15542 opcional: true,
15543 caracteristicas: Vec::new(),
15544 };
15545 assert!(git_true.opcional());
15546 // Explicit-`true` form × explicit path-source — the dev-only
15547 // local-filesystem arm the [`Dep`] docstring's third fixture
15548 // carries.
15549 let path_true = Dep {
15550 nome: "caixa-teia".to_string(),
15551 versao: "0.1.0".to_string(),
15552 fonte: Some(DepSource::Path {
15553 caminho: "../caixa-teia".to_string(),
15554 }),
15555 opcional: true,
15556 caracteristicas: Vec::new(),
15557 };
15558 assert!(path_true.opcional());
15559 }
15560
15561 #[test]
15562 fn dep_opcional_projects_bool_by_copy() {
15563 // The by-`Copy` pin: [`Dep::opcional`] returns `bool` by value
15564 // (`bool: Copy`) — the accessor does not borrow `&self` past
15565 // the call (no lifetime on the return type), and calling the
15566 // accessor twice on the same [`Dep`] must yield discriminant-
15567 // equal values (idempotent, no side effects on `&self`). Peer
15568 // of the sibling outer-`Caixa` `Option<Copy>` by-`Copy`
15569 // `max_restarts_projects_option_by_copy` (eba5211) /
15570 // `estrategia_projects_option_by_copy` (ed04d3c) pins on the
15571 // outer-`Caixa` altitude — extended here to the outer-`Dep`
15572 // altitude's plain-`Copy` `bool` axis. The `Copy` discipline
15573 // replaces the pointer-equality claim the sibling per-`Dep`
15574 // by-borrow pins (`dep_nome_is_by_borrow_pointer_identity`
15575 // eba2cde, `dep_versao_requirement_is_by_borrow_pointer_identity`
15576 // 05529b1, `dep_fonte_is_by_borrow_pointer_identity` d65d1bf,
15577 // `dep_caracteristicas_is_by_borrow_pointer_identity` 9197944)
15578 // carry (a fresh `Copy` of a `Copy` discriminant is definitionally
15579 // the same discriminant, so the axis reduces to discriminant
15580 // equality).
15581 //
15582 // Pins against a future silent detour that returned a fresh
15583 // `&bool` reference (which would type-check but silently
15584 // introduce a borrow of `&self` past the call, collapsing the
15585 // load-bearing "no lifetime on the return type" `Copy`
15586 // projection the plain-`Copy`-scalar axis's `bool` shape
15587 // carries) or a stale-read side effect that flipped the outer
15588 // discriminant on successive calls.
15589 for opcional in [false, true] {
15590 let d = Dep {
15591 nome: "caixa-teia".to_string(),
15592 versao: "^0.1".to_string(),
15593 fonte: None,
15594 opcional,
15595 caracteristicas: Vec::new(),
15596 };
15597 let first = d.opcional();
15598 let second = d.opcional();
15599 assert_eq!(
15600 first, second,
15601 "Dep::opcional must be idempotent — two successive calls \
15602 on the same &self must return the same bool",
15603 );
15604 assert_eq!(
15605 first, opcional,
15606 "Dep::opcional must return :opcional verbatim by Copy — \
15607 got {first}, expected {opcional}",
15608 );
15609 assert_eq!(
15610 d.opcional(),
15611 d.opcional,
15612 "Dep::opcional accessor and self.opcional field access \
15613 must byte-equal — a bit-flip drift would silently split \
15614 the paired resolver-side drop-vs-error dispatch from \
15615 the storage-side default-fill the [`Dep::simple`] / \
15616 [`Dep::git`] constructor pair carries",
15617 );
15618 }
15619 }
15620
15621 // ── DepSource::sole_pin — sole-set git-pin accessor ─────────────────
15622
15623 #[test]
15624 fn sole_pin_returns_none_for_path_source() {
15625 // A path source carries no git-ref, so `sole_pin()` returns
15626 // `None` structurally — the sibling arm every git-fetching
15627 // consumer partitions off before reaching for a git-ref. Pins
15628 // the Path-arm branch of the accessor against a future silent
15629 // detour that treats a `Self::Path` as an unpinned-git source
15630 // and returns the wrong "no pin" signal (e.g. the empty string,
15631 // or a hard-coded `Some("HEAD")` matching the caixa-crd
15632 // path-arm `git_ref` fill).
15633 let s = DepSource::Path {
15634 caminho: "../local-caixa".to_string(),
15635 };
15636 assert_eq!(s.sole_pin(), None);
15637 }
15638
15639 #[test]
15640 fn sole_pin_returns_none_for_unpinned_git_source() {
15641 // The [`DepSource::default_github`] shorthand shape carries no
15642 // pin — every `tag`/`rev`/`branch` is `None`, and `sole_pin()`
15643 // returns `None`. This is the shape caixa-resolver's `fetch_dep`
15644 // materializes when the author omits `:fonte` entirely, then
15645 // hands to `fetch_git` which raises `ResolveError::MissingPin`
15646 // on the `None` arm — the accessor's return matches the arm
15647 // the resolver's diagnostic keys off.
15648 let s = DepSource::default_github("pleme-io", "caixa-teia");
15649 assert_eq!(s.sole_pin(), None);
15650 }
15651
15652 #[test]
15653 fn sole_pin_returns_rev_when_only_rev_is_set() {
15654 let s = DepSource::Git {
15655 repo: "github:o/x".into(),
15656 tag: None,
15657 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15658 branch: None,
15659 };
15660 assert_eq!(
15661 s.sole_pin(),
15662 Some("deadbeefcafebabe1234567890abcdef12345678")
15663 );
15664 }
15665
15666 #[test]
15667 fn sole_pin_returns_tag_when_only_tag_is_set() {
15668 let s = DepSource::Git {
15669 repo: "github:o/x".into(),
15670 tag: Some("v0.1.0".into()),
15671 rev: None,
15672 branch: None,
15673 };
15674 assert_eq!(s.sole_pin(), Some("v0.1.0"));
15675 }
15676
15677 #[test]
15678 fn sole_pin_returns_branch_when_only_branch_is_set() {
15679 let s = DepSource::Git {
15680 repo: "github:o/x".into(),
15681 tag: None,
15682 rev: None,
15683 branch: Some("main".into()),
15684 };
15685 assert_eq!(s.sole_pin(), Some("main"));
15686 }
15687
15688 #[test]
15689 fn sole_pin_precedence_rev_beats_tag_and_branch() {
15690 // Precedence: rev > tag > branch. Validate() rejects
15691 // multiple-pin shapes, but the accessor's precedence is defined
15692 // for pre-validate consumers (the resolver's `MissingPin`
15693 // diagnostic path, the caixa-crd round-trip's default `"main"`
15694 // fallback) and as defense-in-depth if the gate is ever
15695 // bypassed. Pins the same precedence caixa-resolver's
15696 // `fetch_git` and caixa-crd's `dep_into_ref` already apply
15697 // inline.
15698 let s = DepSource::Git {
15699 repo: "github:o/x".into(),
15700 tag: Some("v1".into()),
15701 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15702 branch: Some("main".into()),
15703 };
15704 assert_eq!(
15705 s.sole_pin(),
15706 Some("deadbeefcafebabe1234567890abcdef12345678")
15707 );
15708 }
15709
15710 #[test]
15711 fn sole_pin_precedence_tag_beats_branch_when_no_rev() {
15712 let s = DepSource::Git {
15713 repo: "github:o/x".into(),
15714 tag: Some("v1".into()),
15715 rev: None,
15716 branch: Some("main".into()),
15717 };
15718 assert_eq!(s.sole_pin(), Some("v1"));
15719 }
15720
15721 #[test]
15722 fn sole_pin_byte_equals_inline_rev_or_tag_or_branch_cascade() {
15723 // Fail-before-pass-after byte-parity pin: the substrate accessor
15724 // must return byte-identical to the inline
15725 // `rev.as_deref().or(tag.as_deref()).or(branch.as_deref())`
15726 // cascade both caixa-resolver's `fetch_git` and caixa-crd's
15727 // `dep_into_ref` open-coded pre-lift. Trips at caixa-core build
15728 // time if the accessor's precedence silently drifts from the
15729 // consumer-side cascade — the exact drift this lift converges
15730 // to one substrate primitive to close structurally.
15731 //
15732 // Iterates through the 2^3 = 8 combinations of (tag, rev,
15733 // branch) each-either-`None`-or-`Some`, so every arm of the
15734 // precedence cascade lands under the pin. `validate()` refuses
15735 // the 4 multi-pin combinations, but the accessor's return is
15736 // defined on all 8.
15737 let vals = [Some("R".to_string()), None];
15738 for tag in &vals {
15739 for rev in &vals {
15740 for branch in &vals {
15741 let s = DepSource::Git {
15742 repo: "github:o/x".into(),
15743 tag: tag.clone(),
15744 rev: rev.clone(),
15745 branch: branch.clone(),
15746 };
15747 // The exact inline cascade the two pre-lift
15748 // consumer sites hand-rolled, byte-for-byte.
15749 let expected = rev.as_deref().or(tag.as_deref()).or(branch.as_deref());
15750 assert_eq!(
15751 s.sole_pin(),
15752 expected,
15753 "sole_pin() must byte-equal \
15754 rev.or(tag).or(branch) for \
15755 (tag={tag:?}, rev={rev:?}, branch={branch:?}) — \
15756 a drift would silently split caixa-resolver's \
15757 fetch_git checkout target from caixa-crd's \
15758 dep_into_ref git_ref fill",
15759 );
15760 }
15761 }
15762 }
15763 }
15764}
15765
15766#[cfg(test)]
15767mod dep_source_is_variant_tests {
15768 use super::*;
15769
15770 fn all_variants() -> Vec<(DepSource, &'static str)> {
15771 vec![
15772 (
15773 DepSource::Git {
15774 repo: "github:pleme-io/caixa-teia".into(),
15775 tag: Some("v0.1.0".into()),
15776 rev: None,
15777 branch: None,
15778 },
15779 "Git",
15780 ),
15781 (
15782 DepSource::Path {
15783 caminho: "../caixa-teia".into(),
15784 },
15785 "Path",
15786 ),
15787 ]
15788 }
15789
15790 fn predicate_row(s: &DepSource) -> [bool; 2] {
15791 [s.is_git(), s.is_path()]
15792 }
15793
15794 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
15795 // derive-generated per-arm predicate partition — for every variant
15796 // in `all_variants()`, the observed 2-slot predicate row must equal
15797 // a one-hot row with the `true` at exactly the same index as the
15798 // variant's declaration order. Expected rows are generated live
15799 // from the enumeration rather than transcribed by hand, so a
15800 // copy-paste flip that reroutes one arm through the wrong predicate
15801 // lane trips at the identity-diagonal assertion the way every peer
15802 // sibling [`DepList`] / [`crate::CaixaKind`] / [`crate::CaixaDialeto`]
15803 // / [`crate::supervisor::RestartStrategy`] / [`crate::supervisor::RestartPolicy`]
15804 // / [`crate::upgrade::UpgradeInstruction`] /
15805 // [`crate::aplicacao::PlacementStrategy`] /
15806 // [`crate::aplicacao::RateLimitUnit`] /
15807 // [`crate::aplicacao::WitTarget`] /
15808 // [`crate::render::PathShapeViolation`] partition pin already does.
15809 #[test]
15810 fn dep_source_is_variant_predicates_partition_the_arm_set() {
15811 let variants = all_variants();
15812 for (idx, (variant, name)) in variants.iter().enumerate() {
15813 let observed = predicate_row(variant);
15814 let mut expected = [false; 2];
15815 expected[idx] = true;
15816 assert_eq!(
15817 observed, expected,
15818 "DepSource::{name} at declaration-order slot {idx} must \
15819 satisfy exactly one is_* predicate (its own); observed \
15820 row must equal the one-hot expected row — a drift \
15821 would silently reroute one `:fonte`-arm consumer \
15822 through the wrong predicate lane"
15823 );
15824 }
15825 }
15826
15827 // Byte-parity pin on the two field-agnostic `matches!` shapes the
15828 // per-arm arm-discriminator predicates replace at any future
15829 // consumer site (a `:fonte`-shape-only lint rule that flags path
15830 // deps outside dev-caixas via `dep.fonte().is_some_and(DepSource::is_path)`,
15831 // a future admission-webhook that rejects `:fonte` shapes outside
15832 // the `is_git()` accept-set, a caixa-lacre indexing pass that
15833 // dispatches on `s.is_git()` without extracting `repo` / `caminho`).
15834 // Refuses a future accidental split between the derived predicate
15835 // and its `matches!` shape — a hand-rolled shadow impl that
15836 // overrides one path, an accidental rebrand that leaves one
15837 // consumer on the raw `matches!` form — on the two load-bearing
15838 // `:fonte`-arm-discriminator axes every downstream substrate
15839 // consumer of the dep-source axis keys off.
15840 #[test]
15841 fn dep_source_is_git_and_is_path_byte_equal_matches_shape() {
15842 for (variant, name) in all_variants() {
15843 let via_matches_git = matches!(variant, DepSource::Git { .. });
15844 let via_predicate_git = variant.is_git();
15845 assert_eq!(
15846 via_predicate_git, via_matches_git,
15847 "DepSource::{name}.is_git() must byte-equal \
15848 matches!(_, DepSource::Git {{ .. }}) — otherwise a \
15849 future converged consumer site would silently \
15850 disagree with its pre-lift shape"
15851 );
15852 let via_matches_path = matches!(variant, DepSource::Path { .. });
15853 let via_predicate_path = variant.is_path();
15854 assert_eq!(
15855 via_predicate_path, via_matches_path,
15856 "DepSource::{name}.is_path() must byte-equal \
15857 matches!(_, DepSource::Path {{ .. }}) — otherwise a \
15858 future converged consumer site would silently \
15859 disagree with its pre-lift shape"
15860 );
15861 }
15862 }
15863
15864 // Cross-pin against every constructor path that materializes a
15865 // [`DepSource`] shape today (the [`DepSource::default_github`]
15866 // resolver-side fallback that materializes an unpinned
15867 // `github:<org>/<nome>` git shorthand, the [`Dep::git`] author-
15868 // surface constructor that materializes a pinned `:tag`-carrying
15869 // `DepSource::Git`, a hand-rolled `DepSource::Path` the dev-mode
15870 // fixture family builds inline). Every constructor's return must
15871 // satisfy the arm-discriminator predicate the constructor's
15872 // variant name matches — a future constructor addition (an
15873 // in-tree registry-fetch pin, a `DepSource::Feira` variant the
15874 // enclosing docstring already names as a trajectory item) surfaces
15875 // as a build-time failure that names the offending drift when its
15876 // return arm doesn't route through the paired predicate.
15877 #[test]
15878 fn dep_source_constructors_route_through_paired_is_variant_predicate() {
15879 let via_default_github = DepSource::default_github("pleme-io", "caixa-teia");
15880 assert!(
15881 via_default_github.is_git(),
15882 "DepSource::default_github must materialize a Git-arm shape — \
15883 a future constructor that routed through a non-Git arm \
15884 (a registry-fetch pin, a `DepSource::Feira` promotion) \
15885 would silently split the resolver's unpinned-shorthand \
15886 materializer from the sole_pin() precedence cascade"
15887 );
15888 assert!(
15889 !via_default_github.is_path(),
15890 "DepSource::default_github must NOT materialize a Path-arm \
15891 shape — the paired negation pin"
15892 );
15893
15894 let via_dep_git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15895 .fonte
15896 .expect("Dep::git materializes a Some(fonte)");
15897 assert!(
15898 via_dep_git.is_git(),
15899 "Dep::git's `:fonte` materialization must land on the Git \
15900 arm — the author-surface pinned-git constructor's return \
15901 must route through the paired predicate"
15902 );
15903 assert!(!via_dep_git.is_path(), "paired negation pin");
15904
15905 let via_path = DepSource::Path {
15906 caminho: "../caixa-teia".into(),
15907 };
15908 assert!(
15909 via_path.is_path(),
15910 "the dev-mode Path-arm materialization must satisfy is_path()"
15911 );
15912 assert!(!via_path.is_git(), "paired negation pin");
15913 }
15914}