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::fonte_repo_empty(nome));
254 }
255 // The `:repo` value flows verbatim into the caixa-resolver's
256 // `git clone <repo>` subprocess invocation. Until this gate
257 // landed `:repo` was the last untyped `:fonte`-related axis
258 // past the empty arm: a malformed-but-non-empty repo URL
259 // (`":repo "github:p/x ""` trailing space, paste-from-doc;
260 // `":repo "-upload-pack=evil""` leading `-` — the canonical
261 // CLI-argument-injection vector at the `git clone` boundary;
262 // `":repo "pleme-io/caixa-teia""` missing scheme — `git clone`
263 // reads as a relative filesystem path rather than the
264 // GitHub-shorthand expansion; `":repo "github:p/x\n""`
265 // embedded newline; `":repo "github:café/x""` raw non-ASCII)
266 // silently passed validate and the failure surfaced at
267 // lacre-resolve time with a porcelain-quoting-confused error
268 // far from the source caixa.lisp. The lifted predicate makes
269 // the git-porcelain-URL intersection-floor a substrate-level
270 // invariant at validate time, peer with the three pin axes
271 // (`:tag` + `:branch` via [`crate::render::is_git_ref_name`],
272 // e70d213; `:rev` via [`crate::render::is_git_oid`], be07fd5)
273 // — every `:fonte (:tipo git …)` past validate is now
274 // structurally accept-shaped on every axis the resolver
275 // consumes (the `:repo` URL the `git clone` invokes against,
276 // the `:tag`/`:branch` refname `git fetch`/`git checkout`
277 // accepts, the `:rev` commit OID the lacre's content-
278 // addressing equality probe resolves), closing the
279 // `:fonte` slot's value-shape trajectory end-to-end.
280 if let Err(reason) = crate::render::is_git_repo_url(repo) {
281 return Err(DepError::FonteRepoShape {
282 nome: nome.to_string(),
283 repo: repo.clone(),
284 reason,
285 });
286 }
287 let pins: [(&'static str, Option<&String>); 3] = [
288 (":tag", tag.as_ref()),
289 (":rev", rev.as_ref()),
290 (":branch", branch.as_ref()),
291 ];
292 let set: Vec<&'static str> =
293 pins.iter().filter_map(|(n, v)| v.map(|_| *n)).collect();
294 match set.len() {
295 0 => {
296 return Err(DepError::fonte_pin_missing(nome));
297 }
298 1 => {
299 for (pin, value) in pins {
300 if value.is_some_and(String::is_empty) {
301 return Err(DepError::FontePinEmpty {
302 nome: nome.to_string(),
303 pin: pin.to_string(),
304 });
305 }
306 }
307 }
308 _ => {
309 return Err(DepError::FontePinAmbiguous {
310 nome: nome.to_string(),
311 pins: set.join(", "),
312 });
313 }
314 }
315 // Per-pin value-shape gate. The refname-shaped axes
316 // (`:tag` + `:branch`) route through
317 // [`crate::render::is_git_ref_name`]; the hex-OID-shaped
318 // `:rev` axis routes through
319 // [`crate::render::is_git_oid`]. The two predicates
320 // partition the `:fonte` pin axes structurally — refname
321 // vs. hex commit — so a cross-axis mis-slot (the
322 // canonical "I conflated `:rev` and `:branch`" footgun:
323 // `:rev "main"` defeating the reproducibility contract,
324 // `:tag "deadbeef…"` mis-slotting a SHA into the
325 // refname-shaped axis) lands at the offending axis's
326 // predicate, not at lacre-resolve `git fetch` /
327 // `git checkout` time. Their valid sets intersect at
328 // the empty set: every refname is rejected by
329 // `is_git_oid`, every OID is rejected by
330 // `is_git_ref_name`, structurally.
331 //
332 // Until this gate landed `:tag` / `:branch` were the
333 // refname-shaped axes still untyped past the empty-pin
334 // arm: a malformed-but-non-empty refname
335 // (`:tag "v0.1.0 "` trailing space — the canonical
336 // paste-from-doc footgun; `:tag "v0.1.0.lock"` colliding
337 // with git's atomic-rename guard suffix; `:tag "../escape"`
338 // path-traversal via consecutive dots; `:branch "main "`
339 // trailing space; `:branch "feature/foo bar"` embedded
340 // space; `:branch "@"` the literal HEAD alias;
341 // `:branch "refs/heads/main"` the fully-qualified ref
342 // copied from `git show-ref` output that resolves to
343 // a literal ref named `refs/heads/refs/heads/main` on
344 // disk) silently passed validate; the `:rev` axis was
345 // the last `:fonte`-related axis still untyped past the
346 // empty-pin arm: a malformed-but-non-empty hex-OID
347 // (`:rev "main"` conflating with `:branch` — the
348 // reproducibility-contract leak; `:rev "v0.1.0"`
349 // conflating with `:tag` — the same mis-slot on the
350 // refname/OID boundary; `:rev "c0ffee"` an abbreviated
351 // 6-char prefix that's ambiguous across repo history;
352 // `:rev "DEADBEEF…"` an uppercase OID that round-trips
353 // inconsistently against `git rev-parse HEAD`'s
354 // lowercase emission) silently passed validate and the
355 // failure surfaced at lacre-resolve `git fetch` /
356 // `git checkout` time with a quoting-confused error
357 // far from the source caixa.lisp, with no field naming
358 // which `:deps` entry carried the typo. Lifting both
359 // gates to caixa-build time matches the value-shape
360 // trajectory the peer typed axes already follow
361 // (c4213a4 typed WitContract endpoint/subject/slot;
362 // eb3456d :entrada :paths; c7d05ec :entrada :host;
363 // 4f0390b :contratos :endpoint; 6226bf4 :contratos :wit;
364 // 63e18a0 :contratos :subject; 2f4316e :contratos
365 // :slot; e70d213 :fonte :tag + :branch) — the typed
366 // slot's valid set matches its downstream consumer's
367 // accepted set (here, the git porcelain's refname /
368 // commit-OID grammars at `git fetch` / `git checkout`
369 // time), structurally. Same diagnostic shape every
370 // per-axis value-shape lift already exposes
371 // (`*Invalid { axis, reason }`); the `value:` field
372 // carries the offending refname / OID verbatim so the
373 // author can grep their caixa.lisp for the
374 // `:tag "<value>"` / `:branch "<value>"` /
375 // `:rev "<value>"` literal and fix it in one edit.
376 for (pin, value) in [(":tag", tag.as_ref()), (":branch", branch.as_ref())] {
377 if let Some(v) = value
378 && let Err(reason) = crate::render::is_git_ref_name(v)
379 {
380 return Err(DepError::FontePinShape {
381 nome: nome.to_string(),
382 pin: pin.to_string(),
383 value: v.clone(),
384 reason,
385 });
386 }
387 }
388 if let Some(v) = rev.as_ref()
389 && let Err(reason) = crate::render::is_git_oid(v)
390 {
391 return Err(DepError::FontePinShape {
392 nome: nome.to_string(),
393 pin: ":rev".to_string(),
394 value: v.clone(),
395 reason,
396 });
397 }
398 Ok(())
399 }
400 Self::Path { caminho } => Self::validate_caminho(nome, caminho),
401 }
402 }
403
404 /// Reproducibility + path-API gate on the `:fonte (:tipo path …)`
405 /// `:caminho` axis. Walks the leading-byte cascade closed by the
406 /// b94fd83 (`/`), a5c248e (`~`), and f4efe9c (`$`) arms; the
407 /// orthogonal embedded-control-byte arm (d624c8d) covering
408 /// `0x00..=0x1F` plus `0x7F` anywhere in the value; and the
409 /// embedded-`\` Windows-path-separator arm closing the
410 /// cross-host-OS-separator divergence vector on the same
411 /// THEORY.md §V.2 render-determinism axis.
412 ///
413 /// Extracted from [`Self::validate`]'s `Self::Path` arm because the
414 /// per-arm cascade now spans nine diagnostic shapes — every new
415 /// `:caminho` arm (a future `&` / `;` / `|` shell-metachar arm,
416 /// a future glob-metachar `*` / `?` arm) lands here rather than
417 /// re-inflating `Self::validate`. The
418 /// function stays a thin per-arm linear walk for one reason: each
419 /// arm's diagnostic carries a distinct typed [`DepError`] variant
420 /// rather than a parser-shaped `reason` string, so collapsing the
421 /// cascade onto a generic [`crate::render`] predicate would regress
422 /// the per-arm self-locating diagnostic that `feira lint` consumers
423 /// depend on. The wrapped predicate trajectory ([`crate::render::is_dns_1123_label`],
424 /// [`crate::render::is_git_repo_url`], etc.) lives on the
425 /// reason-string-shaped axes; the `:caminho` axis keeps its
426 /// per-arm variant shape.
427 #[allow(
428 clippy::too_many_lines,
429 reason = "the per-arm cascade is structurally flat by design — every \
430 `:caminho` arm carries its own typed [`DepError`] variant + \
431 per-arm Why comment, so collapsing the cascade onto a generic \
432 [`crate::render`] predicate would regress the per-arm self-locating \
433 diagnostic the `feira lint` consumer surface depends on"
434 )]
435 fn validate_caminho(nome: &str, caminho: &str) -> Result<(), DepError> {
436 if caminho.is_empty() {
437 return Err(DepError::fonte_caminho_empty(nome));
438 }
439 // Reproducibility gate on the `:fonte (:tipo path …)`
440 // `:caminho` axis. The lacre pipeline embeds the value
441 // verbatim in its per-dep content-address
442 // (`conteudo: format!("path:{caminho}")`,
443 // caixa-resolver/src/resolve.rs:189) and that string
444 // folds into the BLAKE3 closure the lacre keys every
445 // downstream consumer (the substrate's reproducibility
446 // contract, CAIXA-SDLC §III.2 — the lacre is the
447 // build's content-addressed identity, peer of the Nix
448 // store path) against. Until this gate landed an
449 // absolute `:caminho` (`/home/me/work/caixa-teia` — the
450 // canonical "I dragged the folder out of Finder into
451 // my editor" footgun; `/Users/alice/dev/caixa-teia` on
452 // the macOS path-layout peer; the
453 // `${WORKSPACE}/caixa-teia` shell-expanded literal
454 // pasted from a CI manifest) silently passed validate
455 // and the failure surfaced *as a successful build with
456 // a divergent lacre*: the BLAKE3 closure on Alice's
457 // workstation differed from the closure on Bob's
458 // workstation, two CI runners with different
459 // `${HOME}` layouts emitted two distinct
460 // content-addresses for the byte-identical caixa, and
461 // the substrate's "the lacre is the build's identity"
462 // contract silently broke far from the source
463 // caixa.lisp — the most insidious failure mode the
464 // typed slot can carry (no error surfaces; the
465 // divergence is invisible until two machines compare
466 // lacres). The same THEORY.md §V.2 render-determinism
467 // discipline `is_sandboxed_relative_path` already
468 // applies on the M2 typed path-slots
469 // (`:behavior :on-*`, `:upgrade-from :state-change
470 // :script`, `:bibliotecas`, `:exe`, `:servicos`), here
471 // narrowed to the absolute-vs-relative axis only:
472 // `:fonte :caminho`'s canonical author-surface form is
473 // the `..`-traversing sibling-workspace path
474 // (`"../caixa-teia"`, the in-tree dev-dep frame), so a
475 // full `is_sandboxed_relative_path` lift would
476 // structurally reject every legitimate path-fonte
477 // dep. The narrower
478 // `std::path::Path::is_absolute` cut admits the
479 // sibling-workspace form while still rejecting the
480 // host-layout-leaking absolute shape — the
481 // reproducibility contract bites at exactly the
482 // absolute boundary, and that's the axis the
483 // substrate-level invariant is meant to hold. Same
484 // diagnostic shape every per-axis value-shape lift on
485 // the surrounding [`DepError::Fonte*`] cluster carries
486 // (the offending `:nome` + offending `:caminho`
487 // quoted verbatim so the author can grep their
488 // caixa.lisp for the `:caminho "<value>"` literal and
489 // fix it in one edit). The empty arm strictly
490 // precedes this arm so the blank-string footgun
491 // surfaces the more self-locating
492 // `FonteCaminhoEmpty` diagnostic (the empty string
493 // is not absolute under `Path::new("").is_absolute()`
494 // so the precedence is a no-op at value level — the
495 // pin matters only at the diagnostic-shape level if
496 // a future codec round-trip ever produces an empty
497 // string that probes as absolute).
498 if std::path::Path::new(caminho).is_absolute() {
499 return Err(DepError::fonte_caminho_absolute(nome, caminho));
500 }
501 // Reproducibility gate's tilde-expansion arm. The b94fd83
502 // `FonteCaminhoAbsolute` closes the leading-`/`
503 // host-layout-leak; a `:caminho "~/work/caixa-teia"` (the
504 // canonical paste-from-shell-prompt / paste-from-`cd ~`-
505 // doc footgun) silently passed both the empty arm and
506 // the absolute arm because `Path::new("~").is_absolute()`
507 // returns `false` — `~` is a shell-expansion convention,
508 // not a POSIX path component, so `std::path::Path` treats
509 // it as a literal directory-name segment. The lacre
510 // pipeline then embedded the value verbatim
511 // (`conteudo: format!("path:~/work/caixa-teia")`) and the
512 // failure mode forked per consumer:
513 //
514 // - The caixa-resolver's `Path` arm folds `:caminho`
515 // through `Path::new(caminho).join(<file>)` without
516 // `~`-expansion, so the build looked for a literal
517 // `./~/work/caixa-teia` subdirectory and failed at
518 // resolve time with a `No such file or directory`
519 // error far from the source caixa.lisp (the lacre
520 // itself, though, was already byte-identical across
521 // machines — every machine emitted the same
522 // `path:~/work/caixa-teia` content-address).
523 // - A future caixa-resolver pass that *does* expand `~`
524 // (the canonical shell-convention idiom every
525 // resolver eventually reaches for once an author
526 // reports the literal-`~`-directory bug) would re-
527 // introduce the host-layout-leak the b94fd83 absolute
528 // gate closes: Alice's `~` expands to `/home/alice`,
529 // Bob's to `/home/bob`, two CI runners with different
530 // `$HOME` layouts resolve to two distinct paths for
531 // the byte-identical caixa, and the substrate's
532 // "the lacre is the build's identity" contract
533 // silently breaks far from the source caixa.lisp.
534 //
535 // Closing the gate at `DepSource::validate` (here at the
536 // canonical caixa-build-time boundary, peer with the
537 // absolute arm above) refuses both failure modes
538 // structurally: the typed accepted set excludes every
539 // `~`-prefixed authoring shape, so the resolver is
540 // free to grow `~`-expansion (or any other convention-
541 // expansion the substrate adopts) without re-opening
542 // the host-layout-leak at the typed boundary. Same
543 // diagnostic shape every per-axis value-shape gate on
544 // the surrounding [`DepError::Fonte*`] cluster carries
545 // (the offending `:nome` + offending `:caminho` quoted
546 // verbatim so the author can grep their caixa.lisp for
547 // the `:caminho "<value>"` literal and fix it in one
548 // edit).
549 //
550 // The cascade preserves narrower-diagnostic-first
551 // ordering: `FonteCaminhoEmpty` → `FonteCaminhoAbsolute`
552 // → `FonteCaminhoTildeExpansion`. The empty arm
553 // structurally precedes both (the bytes "" / "~" don't
554 // overlap), and the absolute arm structurally precedes
555 // the tilde arm (an absolute path can't start with `~`
556 // since absolute paths start with `/`; the bytes "/" /
557 // "~" don't overlap either). Both arms are
558 // value-disjoint, so the precedence is a no-op at value
559 // level — the pin matters only at the diagnostic-shape
560 // level if a future codec round-trip ever produces a
561 // value that probes as both absolute and tilde-prefixed.
562 if caminho.starts_with('~') {
563 return Err(DepError::fonte_caminho_tilde_expansion(nome, caminho));
564 }
565 // Reproducibility gate's shell-variable-expansion arm.
566 // The b94fd83 `FonteCaminhoAbsolute` closes the leading-`/`
567 // host-layout-leak; the a5c248e `FonteCaminhoTildeExpansion`
568 // closes the leading-`~` shell-home-expansion shape; the
569 // leading-`$` is the sibling shell-variable-expansion shape
570 // — same host-layout-leaking semantic, different syntactic
571 // surface. A `:caminho "$HOME/work/caixa-teia"` (the
572 // canonical paste-from-`echo $HOME`-doc footgun) and the
573 // `${VAR}`-braced variant (`"${WORKSPACE}/caixa-teia"` —
574 // the canonical paste-from-CI-manifest footgun every
575 // GitHub Actions / GitLab CI / Drone manifest carries)
576 // silently passed every prior arm because
577 // `Path::is_absolute` returns false on `$` (the `$` is a
578 // shell convention, not a POSIX path component, so
579 // `std::path::Path` treats it as a literal directory-name
580 // segment) and the tilde arm's `starts_with('~')` doesn't
581 // fire.
582 //
583 // Same per-consumer failure-fork the tilde arm closes:
584 //
585 // - The caixa-resolver's `Path` arm folds `:caminho`
586 // through `Path::new(caminho).join(<file>)` without
587 // `$`-expansion, so the build looks for a literal
588 // `./$HOME/work/caixa-teia` subdirectory and fails at
589 // resolve time with a `No such file or directory`
590 // error far from the source caixa.lisp.
591 // - A future caixa-resolver pass that *does* expand
592 // `$VAR` (the shell-convention idiom every resolver
593 // eventually reaches for once an author reports the
594 // literal-`$HOME`-directory bug, especially for CI's
595 // `${WORKSPACE}` idiom) would re-introduce the host-
596 // layout-leak the b94fd83 absolute gate closes:
597 // Alice's `$HOME` expands to `/home/alice`, Bob's to
598 // `/home/bob`, two CI runners with different
599 // `${WORKSPACE}` layouts resolve to two distinct
600 // paths for the byte-identical caixa, and the
601 // substrate's "the lacre is the build's identity"
602 // contract silently breaks far from the source
603 // caixa.lisp.
604 //
605 // Closing the gate at `DepSource::validate` (here at the
606 // canonical caixa-build-time boundary, peer with the
607 // absolute + tilde arms above) refuses both failure modes
608 // structurally. Same diagnostic shape every per-axis
609 // value-shape gate on the surrounding [`DepError::Fonte*`]
610 // cluster carries (the offending `:nome` + offending
611 // `:caminho` quoted verbatim).
612 //
613 // The cascade preserves narrower-diagnostic-first ordering:
614 // `FonteCaminhoEmpty` → `FonteCaminhoAbsolute` →
615 // `FonteCaminhoTildeExpansion` → `FonteCaminhoVarExpansion`.
616 // The empty arm structurally precedes all three subsequent
617 // arms; the absolute arm structurally precedes both the
618 // tilde and the var arms (absolute paths start with `/`,
619 // the bytes `/` / `~` / `$` don't overlap at the leading
620 // position); the tilde arm structurally precedes the var
621 // arm (`~` and `$` don't overlap at the leading position).
622 // Every pair is value-disjoint, so the precedence is a
623 // no-op at value level — the pin matters only at the
624 // diagnostic-shape level if a future codec round-trip ever
625 // produces a probe-as-both value.
626 //
627 // The gate covers every leading-`$` shape: the canonical
628 // `"$HOME/work/caixa-teia"` (POSIX shell), the braced
629 // `"${HOME}/work/caixa-teia"` (POSIX shell braces), the
630 // CI-manifest idiom `"${WORKSPACE}/caixa-teia"` (the
631 // GitHub Actions / GitLab CI / Drone paste footgun), the
632 // XDG idiom `"$XDG_CONFIG_HOME/caixa"`, and the bare `$`
633 // (degenerate "I meant `$HOME` and forgot the rest"). All
634 // shapes route through the same `caminho.starts_with('$')`
635 // byte check.
636 if caminho.starts_with('$') {
637 return Err(DepError::fonte_caminho_var_expansion(nome, caminho));
638 }
639 // Reproducibility gate's leading-space arm. The b94fd83 / a5c248e /
640 // f4efe9c arms closed the leading-byte host-layout-leak shapes
641 // (`/` / `~` / `$`); the embedded-control-byte arm below closes
642 // every byte in `0x00..=0x1F` plus `0x7F` (which already includes
643 // tab `0x09`, LF `0x0A`, CR `0x0D` — every ASCII whitespace
644 // *except* the ASCII space byte `0x20`). The bare ASCII space at
645 // the leading position is the orthogonal paste-from-aligned-doc
646 // shape that silently passed every prior arm: `Path::is_absolute`
647 // returns false on `" ../caixa-teia"` (the leading byte is `0x20`
648 // not `0x2F`), `0x20` is not `~` / `$` / `\` / a control byte, and
649 // the value's last byte is not `/`, so the canonical
650 // paste-from-aligned-`caixa.lisp`-doc footgun (every `:fonte`
651 // form in a multi-entry `:deps` block sits at the same column —
652 // an author selecting `"<sp><sp><sp>../caixa-teia"` and pasting
653 // it from the rendered alignment into a fresh entry preserves the
654 // leading whitespace verbatim) silently rendered as a path with
655 // a leading-space directory component the resolver folds through
656 // `Path::join` looking for a literal `./ ../caixa-teia`
657 // subdirectory that fails at resolve time with a non-self-
658 // locating `No such file or directory` error.
659 //
660 // The lacre pipeline's reproducibility contract bites
661 // strictly at this byte: `path:" ../caixa-teia"` and
662 // `path:"../caixa-teia"` yield distinct BLAKE3 closures
663 // (`conteudo: format!("path:{caminho}")`,
664 // caixa-resolver/src/resolve.rs:189) for the byte-divergent /
665 // semantic-identical caixa, and the substrate's "the lacre is
666 // the build's identity" contract (CAIXA-SDLC §III.2) silently
667 // breaks across two workstations whose authors differ only in
668 // paste-from-aligned-doc whitespace habits — the most insidious
669 // failure mode the typed slot can carry (no error surfaces; the
670 // divergence is invisible until two machines compare lacres).
671 //
672 // The arm fires AFTER the absolute / tilde / var leading-byte
673 // arms (each names the more self-locating shell-convention
674 // diagnostic on values that probe as that arm's leading-byte
675 // sentinel followed by a leading space — e.g.
676 // `:caminho "/ /foo"` surfaces `FonteCaminhoAbsolute` because
677 // the leading byte is `/`, not space) and BEFORE the
678 // embedded-control-byte arm (a leading-space value with an
679 // embedded control byte surfaces the broader leading-space
680 // diagnostic because the cascade walks leading-byte arms first
681 // — peer with how `FonteCaminhoAbsolute` precedes
682 // `FonteCaminhoControlChar` on `"/etc/passwd\n"`).
683 //
684 // The peer single-token-shaped axes already reject leading
685 // whitespace on the same paste-from-aligned-doc contract:
686 // [`crate::render::is_git_repo_url`] rejects leading whitespace
687 // on `:fonte :repo`, [`crate::render::is_git_ref_name`] rejects
688 // leading whitespace on `:fonte :tag`/`:branch`,
689 // [`crate::render::is_chart_description_shape`] rejects leading
690 // whitespace on `:descricao`,
691 // [`crate::render::is_spdx_expression_shape`] rejects leading
692 // whitespace on `:licenca`. Closing the same byte on
693 // `:fonte :caminho` makes the substrate-wide "no leading ASCII
694 // space anywhere in a typed string slot" invariant structurally
695 // consistent across every value-shape-gated typed surface (the
696 // `:caminho` axis was the last typed string surface still
697 // admitting a leading space byte).
698 if caminho.starts_with(' ') {
699 return Err(DepError::fonte_caminho_leading_whitespace(nome, caminho));
700 }
701 // Reproducibility gate's leading-`-` CLI-argument-injection arm.
702 // The b94fd83 + a5c248e + f4efe9c + LeadingWhitespace arms closed
703 // the four prior leading-byte shapes (`/` / `~` / `$` / space);
704 // this arm closes the orthogonal leading-`-` axis on the same
705 // subprocess-argument-boundary the peer `is_git_repo_url` arm
706 // (render.rs:2037, `-upload-pack=…` on `:fonte :repo`) and
707 // `is_git_ref_name` arm (render.rs:1381, 5a28454, `-stable` on
708 // `:fonte :tag` / `:branch`) already reject.
709 //
710 // The lacre pipeline embeds `:caminho` verbatim in its per-dep
711 // content-address (`conteudo: format!("path:{caminho}")`,
712 // caixa-resolver/src/resolve.rs:189) and the resolver folds the
713 // value through `Path::join` looking for a literal `./{caminho}`
714 // subdirectory. Every downstream subprocess that consumes the
715 // resolved path — a `git -C {caminho} <verb>` invocation, a
716 // future `feira tofu` `terraform -chdir={caminho}` shell-out, a
717 // future operator-side `nix build --path {caminho}` spawn, an
718 // `xargs` / `find {caminho}` / `stat {caminho}` /
719 // `rm -rf {caminho}` cleanup — reinterprets a leading-`-` value
720 // as a CLI flag rather than a positional path when the
721 // subprocess invocation does not carry a `--` argument-list
722 // terminator between the flag block and the path argument. The
723 // canonical footguns:
724 //
725 // - `:caminho "-rf"` — bare short-flag paste (`rm -rf` /
726 // `find -rf` reinterpretation; the byte the peer
727 // `FonteCaminhoShellSemicolon` arm's `; rm -rf build`
728 // example paste-idiom carries as its first token).
729 // - `:caminho "-C"` — `git -C` config-injection paste
730 // (`git -C -C` reinterprets the second `-C` as another
731 // `--change-directory` flag rather than the path
732 // argument; the canonical `git -C <path>` porcelain
733 // idiom every multi-repo workspace tool carries).
734 // - `:caminho "--upload-pack=cat /etc/passwd"` — the
735 // canonical long-flag CLI-arg-injection vector at every
736 // git porcelain entry point (`git clone`, `git fetch`,
737 // `git ls-remote`) that consumes a path or URL
738 // argument; peer with `is_git_repo_url`'s leading-`-`
739 // arm (render.rs:2037) on the sibling `:fonte :repo`
740 // axis, which the arm's diagnostic explicitly cites.
741 // - `:caminho "--config=…"` / `:caminho "-c"` — git-config
742 // override paste-idiom (paste-from-`git -c foo=bar`
743 // shell-history footgun that reinterprets the value as
744 // a `[foo] bar` config injection on every git porcelain
745 // entry point).
746 //
747 // POSIX `std::path::Path` treats a leading `-` as a literal
748 // filename byte, so the resolver folds `-rf` through `Path::join`
749 // and looks for a literal `./-rf` subdirectory — the failure
750 // surfaces at resolve time with a non-self-locating `No such
751 // file or directory` error far from the source caixa.lisp, and
752 // the value rides through the lacre content-address into every
753 // downstream shell-spawned subprocess. On any consumer that
754 // shells out without the `--` terminator (the common case at
755 // every porcelain entry-point) the reinterpretation is silent
756 // and the failure mode is arbitrary-argument-injection.
757 //
758 // The arm fires AFTER the absolute / tilde / var / leading-space
759 // leading-byte arms (each names the more self-locating shell-
760 // convention diagnostic on values that probe as that arm's
761 // leading-byte sentinel — the byte sets are pairwise disjoint at
762 // the leading position, so the precedence pin is a no-op at
763 // value level, but the ordering keeps every leading-byte arm's
764 // diagnostic-shape stable) and BEFORE the embedded-control-byte
765 // arm (a leading-`-` value with an embedded control byte
766 // surfaces the narrower leading-`-` diagnostic because the
767 // cascade walks leading-byte arms first — peer with how
768 // `FonteCaminhoAbsolute` precedes `FonteCaminhoControlChar` on
769 // `"/etc/passwd\n"`, and how `FonteCaminhoLeadingWhitespace`
770 // precedes `FonteCaminhoControlChar` on `" ../foo\n"`).
771 //
772 // The peer single-token-shaped axes already reject leading `-`
773 // on the same CLI-arg-injection contract:
774 // [`crate::render::is_git_repo_url`] rejects it on `:fonte :repo`
775 // (render.rs:2037), [`crate::render::is_git_ref_name`] rejects
776 // it on `:fonte :tag` / `:fonte :branch` (render.rs:1381,
777 // 5a28454), [`crate::render::is_dns_1123_label`] rejects it on
778 // every DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros
779 // :caixa`, `:children :caixa`, `:deps :nome`, cluster names),
780 // [`crate::render::is_cargo_feature_name`] rejects it on
781 // `:caracteristicas`, and the feira `init` / `add <nome>`
782 // positional gate (868c191) rejects it on the CLI positional
783 // itself. Closing the same byte on `:fonte :caminho` makes the
784 // substrate-wide "no leading `-` anywhere in a typed single-
785 // token string slot routed through a subprocess argument"
786 // invariant structurally consistent across every value-shape-
787 // gated typed surface (the `:caminho` axis was the last typed
788 // string surface still admitting a leading `-` byte).
789 if caminho.starts_with('-') {
790 return Err(DepError::fonte_caminho_leading_hyphen(nome, caminho));
791 }
792 // Reproducibility gate's embedded-control-byte arm. The
793 // b94fd83 + a5c248e + f4efe9c arms closed the three
794 // leading-byte host-layout-leak shapes (`/` / `~` / `$`);
795 // this arm closes the orthogonal embedded-control-byte
796 // axis — any ASCII control byte (`0x00..=0x1F` plus
797 // `0x7F` DEL) appearing anywhere in `:caminho`. Same
798 // shape every peer single-token-typed-slot value-shape
799 // predicate the surrounding [`crate::render`] cluster
800 // gates against (the lifted `is_git_repo_url` arm on
801 // `:fonte :repo`, the `is_git_ref_name` arm on
802 // `:tag`/`:branch`, the `is_chart_description_shape` /
803 // `is_chart_maintainer_name_shape` /
804 // `is_chart_keyword_shape` arms on the
805 // Helm-chart-shaped axes); now consistent on the
806 // `:caminho` axis too.
807 //
808 // Until this gate landed any embedded control byte
809 // silently passed validate, the lacre pipeline embedded
810 // the value verbatim in its per-dep content-address
811 // (`conteudo: format!("path:{caminho}")`,
812 // caixa-resolver/src/resolve.rs:189), and the failure
813 // forked per byte and per consumer:
814 //
815 // - NUL (`0x00`) the canonical "POSIX paths cannot
816 // contain a NUL byte" shape: every `std::fs` syscall
817 // routes the path through `CString::new`, which
818 // fails with `NulError` on the first NUL byte; the
819 // build would surface a `NulError` at resolve time
820 // far from the source caixa.lisp.
821 // - LF (`0x0A`) / CR (`0x0D`) the canonical paste-from-
822 // multiline-doc footgun: a `:caminho
823 // "../caixa-teia\nrm -rf /"` value (paste landed mid-
824 // `:caminho` block from a multi-line code-fence)
825 // silently round-trips through `Path::join` but the
826 // embedded newline class is a sibling of the CRLF-at-
827 // subprocess-argument injection vector
828 // `is_git_repo_url` already closes on `:repo`.
829 // - Tab (`0x09`) the canonical paste-from-aligned-table
830 // footgun: the tab is invisible in most editors, and
831 // the lacre embeds the value verbatim so two
832 // paste-from-distinct-tables yield divergent lacres
833 // across host editors that strip vs preserve tabs.
834 // - DEL (`0x7F`) + every other `0x00..=0x1F` byte: the
835 // paste-from-binary-blob shape every peer single-
836 // token-shaped slot rejects under the same
837 // `b < 0x20 || b == 0x7F` predicate.
838 //
839 // Mirrors the cascade discipline every prior `:caminho`
840 // arm establishes: `FonteCaminhoEmpty` →
841 // `FonteCaminhoAbsolute` → `FonteCaminhoTildeExpansion`
842 // → `FonteCaminhoVarExpansion` →
843 // `FonteCaminhoLeadingWhitespace` →
844 // `FonteCaminhoLeadingHyphen` → `FonteCaminhoControlChar`.
845 // The six leading-byte arms structurally precede the
846 // embedded-byte arm because the leading-byte shapes are
847 // the more self-locating diagnostic on values that probe
848 // as both (e.g. `:caminho "/etc/passwd\n"` surfaces the
849 // narrower `FonteCaminhoAbsolute` rather than the broader
850 // embedded-control-byte arm); the precedence pin matters
851 // at the diagnostic-shape level even though the empty /
852 // absolute / tilde / var arms are value-disjoint from a
853 // bare control byte (which would itself be a leading
854 // byte under the empty / absolute / tilde / var arms'
855 // leading-position semantics, but those arms guard the
856 // specific shell-convention characters `/` / `~` / `$`
857 // — a leading `0x01` byte falls through to this arm).
858 for &b in caminho.as_bytes() {
859 if b < 0x20 || b == 0x7F {
860 return Err(DepError::fonte_caminho_control_char(nome, caminho, b));
861 }
862 }
863 // Reproducibility gate's Windows-path-separator arm. The four
864 // leading-byte arms (`/` / `~` / `$`) and the embedded-
865 // control-byte arm close the host-layout-leaking + paste-from-
866 // multiline-doc shapes; the leading-`\` / embedded-`\` byte is
867 // the orthogonal cross-host-OS-separator shape — same render-
868 // determinism axis, different semantic mechanism. POSIX
869 // [`std::path::Path`] treats `\` (0x5C) as a literal byte
870 // inside a single path component (so `..\caixa-teia` is one
871 // directory named literally `..\caixa-teia`, sibling of `.`
872 // and `..`); Windows [`std::path::Path`] treats `\` as a
873 // primary path separator equal to `/` (so `..\caixa-teia` is
874 // the parent's sibling directory `caixa-teia`). The lacre
875 // pipeline embeds the value verbatim in its per-dep content-
876 // address (`conteudo: format!("path:{caminho}")`, caixa-
877 // resolver/src/resolve.rs:189), so byte-identical caixa.lisp
878 // values resolve to two distinct directories across runner
879 // OSes — the same THEORY.md §V.2 render-determinism contract
880 // the absolute / tilde / var arms protect, here against the
881 // cross-host-OS-separator divergence vector. Even on POSIX-
882 // only resolvers (the canonical pleme-io substrate posture),
883 // a `..\caixa-teia` (the Windows-Explorer "copy as path" /
884 // PowerShell `Get-Location` paste-idiom footgun) silently
885 // passes every prior arm because `Path::is_absolute` returns
886 // false on `..` and `\` is neither a leading-byte sentinel
887 // nor a control byte, then the resolver folds the value
888 // through `Path::new(caminho).join(<file>)` looking for a
889 // literal `./..\caixa-teia` subdirectory and fails at
890 // resolve time with a non-self-locating `No such file or
891 // directory` error far from the source caixa.lisp.
892 //
893 // The peer single-token-shaped axes on the same git-CLI /
894 // path-CLI consumer cluster already reject `\` under the same
895 // Windows-path-leak banner: [`crate::render::is_git_ref_name`]
896 // line 1441 (`"must not contain \\ … the canonical Windows-
897 // path-leak footgun; use / for hierarchical refs"`) gates
898 // `:fonte :tag` / `:fonte :branch` against the same byte,
899 // and [`crate::render::is_gateway_api_http_path`] line 506
900 // includes `\` in the eleven-byte RFC-3986-reserved rejection
901 // set on `:entrada :paths`. Closing the same byte on `:fonte
902 // :caminho` makes the substrate-wide "no Windows path
903 // separator anywhere in a typed string slot" invariant
904 // structurally consistent across every path-shaped typed
905 // surface (the `:caminho` axis was the last typed string
906 // surface still admitting `\`).
907 //
908 // The arm fires AFTER the control-char arm because the
909 // control-char diagnostic is the more self-locating axis on
910 // values that probe as both (`"..\caixa\0teia"` carries both
911 // a `\` and a NUL — NUL is the load-bearing POSIX-syscall-
912 // rejected byte, so `FonteCaminhoControlChar` wins). Same
913 // narrower-diagnostic-first cascade discipline every prior
914 // arm establishes. A pure-`\` value
915 // (`"..\caixa-teia"` with no control bytes) falls through
916 // every prior arm and lands here.
917 for &b in caminho.as_bytes() {
918 if b == b'\\' {
919 return Err(DepError::fonte_caminho_backslash(nome, caminho));
920 }
921 }
922 // Reproducibility gate's shell-redirection arm. The 3a4e1d7 backslash
923 // arm closes the cross-host-OS-separator vector; `<` (`0x3C`) and `>`
924 // (`0x3E`) are the orthogonal shell-redirection sentinels — same
925 // paste-from-shell-prompt footgun class, different syntactic surface.
926 // POSIX `std::path::Path` treats `<` / `>` as literal bytes inside a
927 // single path component (so `../caixa-teia>output` is one directory
928 // named literally `../caixa-teia>output`, sibling of `.` and `..`),
929 // but every interactive shell (bash / zsh / fish / nushell) lexes
930 // `<` / `>` as input / output redirection operators — a `:caminho
931 // "../caixa-teia>build.log"` (the canonical "I pasted a shell
932 // pipeline that wrote build output and forgot to trim the redirect"
933 // footgun) or `:caminho "../<input.lisp"` (the symmetric input-
934 // redirection paste idiom) silently passes every prior arm because
935 // `Path::is_absolute` returns false, `<` / `>` are neither leading-
936 // byte sentinels nor control bytes nor `\`, and the value's last byte
937 // isn't `/`. The resolver folds the value through
938 // `Path::new(caminho).join(<file>)` looking for a literal
939 // `./..\caixa-teia>build.log` subdirectory and fails at resolve time
940 // with a non-self-locating `No such file or directory` error far
941 // from the source caixa.lisp.
942 //
943 // The lacre pipeline embeds the value verbatim in its per-dep
944 // content-address (`conteudo: format!("path:{caminho}")`,
945 // caixa-resolver/src/resolve.rs:189), so a `<` / `>` byte lands in
946 // the BLAKE3 closure and rides downstream as part of the build's
947 // identity. The bytes carry a second class of hazard the prior
948 // separator-shaped arms don't: every typed-string slot whose value
949 // ever flows verbatim into a shell-spawned subprocess (the caixa-
950 // resolver's `git clone` invocation, a future `feira tofu` shell-
951 // out, a future operator-side `nix flake check` spawn) is the
952 // canonical CRLF-at-subprocess-argument / shell-metachar injection
953 // surface that every peer single-token-shaped typed slot already
954 // closes. The peer path-shaped axis `[crate::render::is_gateway_api_http_path]`
955 // (caixa-core/src/render.rs:506) rejects `<` / `>` as part of its
956 // eleven-byte RFC-3986-reserved set on `:entrada :paths`, and the
957 // peer git-ref-shaped axis `[crate::render::is_git_ref_name]` rejects
958 // `<` / `>` on `:fonte :tag` / `:fonte :branch` under the same
959 // shell-metachar-injection banner. The `:caminho` axis was the last
960 // typed string surface still admitting these two bytes; this arm
961 // closes the gap so the substrate-wide "no shell-redirection
962 // metacharacter anywhere in a typed string slot" invariant is now
963 // structurally consistent across every path-shaped typed surface.
964 //
965 // The arm fires AFTER the control-char arm + backslash arm because
966 // both prior arms carry more self-locating diagnostics on values
967 // that probe as both (`"..\foo<bar"` carries both `\` and `<` — the
968 // cross-OS-separator divergence is the load-bearing axis, so the
969 // backslash arm wins; `"../foo\n<bar"` carries both LF and `<` —
970 // the POSIX-syscall-rejected byte is the load-bearing axis, so the
971 // control-char arm wins). The arm fires BEFORE the trailing-`/` arm
972 // because the embedded redirection byte is the more semantic-
973 // locating axis on probe-as-both values (`"../foo</"` ends in `/`
974 // but the load-bearing diagnostic is the embedded `<` shell-
975 // redirection — the trailing `/` is the secondary observation, and
976 // an author who removes the `<` is likely to also tab-strip the
977 // trailing separator).
978 for &b in caminho.as_bytes() {
979 if b == b'<' || b == b'>' {
980 return Err(DepError::fonte_caminho_shell_redirection(nome, caminho, b));
981 }
982 }
983 // Reproducibility gate's shell-pipe arm. The e457141 shell-redirection
984 // arm closes the `<` / `>` input/output redirection sentinels; `|`
985 // (`0x7C`) is the orthogonal shell-pipe sentinel — same paste-from-
986 // shell-prompt footgun class, different syntactic surface. POSIX
987 // `std::path::Path` treats `|` as a literal path-component byte (so
988 // `../caixa-teia|tee` is one directory named literally
989 // `../caixa-teia|tee`, sibling of `.` and `..`), but every interactive
990 // shell (bash / zsh / fish / nushell) lexes `|` as the pipe operator
991 // — a `:caminho "../caixa-teia | grep foo"` (the canonical "I copied a
992 // `ls ../caixa-teia | grep` line out of a shell-history block and
993 // forgot to trim the pipeline tail" footgun) or `:caminho
994 // "../foo||bar"` (the symmetric "I copied a `cmd-a || cmd-b` short-
995 // circuit OR line" idiom) silently passes every prior arm because
996 // `Path::is_absolute` returns false on `..`, `|` is neither a leading-
997 // byte sentinel nor a control byte nor `\` nor `<` / `>`, and the
998 // value's last byte isn't `/`. The resolver folds the value through
999 // `Path::new(caminho).join(<file>)` looking for a literal
1000 // `./../caixa-teia | grep foo` subdirectory and fails at resolve time
1001 // with a non-self-locating `No such file or directory` error far
1002 // from the source caixa.lisp.
1003 //
1004 // The lacre pipeline embeds the value verbatim in its per-dep
1005 // content-address (`conteudo: format!("path:{caminho}")`,
1006 // caixa-resolver/src/resolve.rs:189), so a `|` byte lands in the
1007 // BLAKE3 closure and rides downstream as part of the build's identity
1008 // into every shell-spawned subprocess (the caixa-resolver's `git
1009 // clone` invocation, a future `feira tofu` shell-out, a future
1010 // operator-side `nix flake check` spawn) as the canonical CRLF-at-
1011 // subprocess-argument / shell-metachar injection surface every peer
1012 // single-token-shaped typed slot already closes. The peer path-shaped
1013 // axis [`crate::render::is_gateway_api_http_path`]
1014 // (caixa-core/src/render.rs:506) rejects `|` as part of its eleven-
1015 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1016 // axis was the last typed path-string surface still admitting this
1017 // byte; this arm closes the gap so the substrate-wide "no shell-
1018 // composition metacharacter anywhere in a typed string slot that
1019 // flows verbatim into a shell-spawned subprocess" invariant extends
1020 // from shell-redirection (`<` / `>`) to shell-pipe (`|`) on the
1021 // `:caminho` axis.
1022 //
1023 // The arm fires AFTER the shell-redirection arm because the prior
1024 // arm's two-byte `byte: u8` payload is the more self-locating axis on
1025 // values that probe as both (`"../caixa-teia<input|tee"` carries both
1026 // `<` and `|` — the input-redirection-paste idiom is the load-bearing
1027 // root-cause edit, so `FonteCaminhoShellRedirection` wins; same
1028 // cascade discipline every prior `:caminho` arm establishes). The arm
1029 // fires BEFORE the trailing-`/` arm because the embedded pipe byte is
1030 // the more semantic-locating axis on probe-as-both values
1031 // (`"../foo|tee/"` ends in `/` but the load-bearing diagnostic is the
1032 // embedded `|` shell-pipe — the trailing `/` is the secondary
1033 // observation, and an author who removes the `|` is likely to also
1034 // tab-strip the trailing separator).
1035 for &b in caminho.as_bytes() {
1036 if b == b'|' {
1037 return Err(DepError::fonte_caminho_shell_pipe(nome, caminho));
1038 }
1039 }
1040 // Reproducibility gate's shell-command-separator arm. The 124106f
1041 // shell-pipe arm closes the `|` byte; `;` (`0x3B`) is the orthogonal
1042 // shell-command-separator sentinel — same paste-from-shell-prompt
1043 // footgun class, different syntactic surface. POSIX `std::path::Path`
1044 // treats `;` as a literal path-component byte (so
1045 // `../caixa-teia;rm -rf /` is one directory named literally
1046 // `../caixa-teia;rm -rf /`, sibling of `.` and `..`), but every
1047 // interactive shell (bash / zsh / fish / nushell) lexes `;` as the
1048 // sequential-command terminator that fires the next command
1049 // regardless of the prior command's exit status — a `:caminho
1050 // "../caixa-teia; rm -rf build"` (the canonical "I pasted a shell
1051 // one-liner that chained a cleanup tail after the directory name"
1052 // footgun) or `:caminho "../foo;;bar"` (the symmetric "I copied a
1053 // POSIX `case` arm's `;;` terminator into the middle of a path"
1054 // idiom) silently passes every prior arm because `Path::is_absolute`
1055 // returns false on `..`, `;` is neither a leading-byte sentinel nor a
1056 // control byte nor `\` nor `<` / `>` nor `|`, and the value's last
1057 // byte isn't `/`. The resolver folds the value through
1058 // `Path::new(caminho).join(<file>)` looking for a literal
1059 // `./../caixa-teia; rm -rf build` subdirectory and fails at resolve
1060 // time with a non-self-locating `No such file or directory` error far
1061 // from the source caixa.lisp.
1062 //
1063 // The lacre pipeline embeds the value verbatim in its per-dep
1064 // content-address (`conteudo: format!("path:{caminho}")`,
1065 // caixa-resolver/src/resolve.rs:189), so a `;` byte lands in the
1066 // BLAKE3 closure and rides downstream as part of the build's identity
1067 // into every shell-spawned subprocess (the caixa-resolver's `git
1068 // clone` invocation, a future `feira tofu` shell-out, a future
1069 // operator-side `nix flake check` spawn) as the canonical
1070 // shell-metachar injection surface every peer single-token-shaped
1071 // typed slot already closes. The peer path-shaped axis
1072 // [`crate::render::is_gateway_api_http_path`]
1073 // (caixa-core/src/render.rs:506) rejects `;` as part of its eleven-
1074 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1075 // axis was the last typed path-string surface still admitting this
1076 // byte; this arm closes the gap so the substrate-wide "no shell-
1077 // composition metacharacter anywhere in a typed string slot that
1078 // flows verbatim into a shell-spawned subprocess" invariant extends
1079 // from shell-pipe (`|`) to shell-command-separator (`;`) on the
1080 // `:caminho` axis.
1081 //
1082 // The arm fires AFTER the shell-pipe arm because the prior arm's
1083 // canonical-cmd-a-|-cmd-b shape is the more common shell-history
1084 // paste idiom on values that probe as both (`"../caixa-teia | tee;
1085 // rm"` carries both `|` and `;` — the pipeline-tail paste is the
1086 // load-bearing root-cause edit, so `FonteCaminhoShellPipe` wins; same
1087 // cascade discipline every prior `:caminho` arm establishes). The arm
1088 // fires BEFORE the trailing-`/` arm because the embedded
1089 // command-separator byte is the more semantic-locating axis on
1090 // probe-as-both values (`"../foo;rm/"` ends in `/` but the
1091 // load-bearing diagnostic is the embedded `;` shell-command-
1092 // separator — the trailing `/` is the secondary observation, and an
1093 // author who removes the `;` is likely to also tab-strip the trailing
1094 // separator).
1095 for &b in caminho.as_bytes() {
1096 if b == b';' {
1097 return Err(DepError::fonte_caminho_shell_semicolon(nome, caminho));
1098 }
1099 }
1100 // Reproducibility gate's shell-background / logical-AND arm. The
1101 // 05c358e shell-command-separator arm closes the `;` byte; `&`
1102 // (`0x26`) is the orthogonal shell-background / list-AND sentinel
1103 // — same paste-from-shell-prompt footgun class, different
1104 // syntactic surface. POSIX `std::path::Path` treats `&` as a
1105 // literal path-component byte (so `../caixa-teia & sleep 1` is
1106 // one directory named literally `../caixa-teia & sleep 1`,
1107 // sibling of `.` and `..`), but every interactive shell
1108 // (bash / zsh / fish / nushell) lexes `&` two ways:
1109 //
1110 // - Single `&` as the background-task terminator that detaches
1111 // the prior command into the background and returns control
1112 // to the prompt immediately (the canonical `cmd &` idiom
1113 // every long-running pipeline uses);
1114 // - Double `&&` as the logical-AND list operator that fires
1115 // the next command only if the prior command succeeded (the
1116 // canonical `make && make install` idiom every build script
1117 // carries).
1118 //
1119 // A `:caminho "../caixa-teia & sleep 1"` (the canonical "I
1120 // pasted a `cd path & sleep 1` background-launch into the
1121 // `:caminho` slot" footgun) or `:caminho "../caixa-teia && make"`
1122 // (the symmetric "I copied a `cd path && make` build chain"
1123 // idiom) silently passes every prior arm because
1124 // `Path::is_absolute` returns false on `..`, `&` is neither a
1125 // leading-byte sentinel nor a control byte nor `\` nor
1126 // `<` / `>` nor `|` nor `;`, and the value's last byte isn't `/`.
1127 // The resolver folds the value through
1128 // `Path::new(caminho).join(<file>)` looking for a literal
1129 // `./../caixa-teia & sleep 1` subdirectory and fails at resolve
1130 // time with a non-self-locating `No such file or directory`
1131 // error far from the source caixa.lisp.
1132 //
1133 // The lacre pipeline embeds the value verbatim in its per-dep
1134 // content-address (`conteudo: format!("path:{caminho}")`,
1135 // caixa-resolver/src/resolve.rs:189), so an `&` byte lands in
1136 // the BLAKE3 closure and rides downstream as part of the build's
1137 // identity into every shell-spawned subprocess (the
1138 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1139 // shell-out, a future operator-side `nix flake check` spawn) as
1140 // the canonical shell-metachar injection surface every peer
1141 // single-token-shaped typed slot already closes. The peer
1142 // path-shaped axis [`crate::render::is_gateway_api_http_path`]
1143 // (caixa-core/src/render.rs:506) rejects `&` as part of its
1144 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1145 // `:caminho` axis was the last typed path-string surface still
1146 // admitting this byte; this arm closes the gap so the
1147 // substrate-wide "no shell-composition metacharacter anywhere
1148 // in a typed string slot that flows verbatim into a
1149 // shell-spawned subprocess" invariant extends from
1150 // shell-command-separator (`;`) to shell-background /
1151 // logical-AND (`&`) on the `:caminho` axis.
1152 //
1153 // The arm fires AFTER the shell-command-separator arm because
1154 // the prior arm's `cmd-a; cmd-b` shape is the more common
1155 // shell-history paste idiom on values that probe as both
1156 // (`"../caixa-teia; rm & sleep"` carries both `;` and `&` — the
1157 // command-separator-tail paste is the load-bearing root-cause
1158 // edit, so `FonteCaminhoShellSemicolon` wins; same cascade
1159 // discipline every prior `:caminho` arm establishes). The arm
1160 // fires BEFORE the trailing-`/` arm because the embedded
1161 // background / list-AND byte is the more semantic-locating axis
1162 // on probe-as-both values (`"../foo&bar/"` ends in `/` but the
1163 // load-bearing diagnostic is the embedded `&` shell-background
1164 // / logical-AND metachar — the trailing `/` is the secondary
1165 // observation, and an author who removes the `&` is likely to
1166 // also tab-strip the trailing separator).
1167 for &b in caminho.as_bytes() {
1168 if b == b'&' {
1169 return Err(DepError::fonte_caminho_shell_background(nome, caminho));
1170 }
1171 }
1172 // Reproducibility gate's shell-command-substitution arm. The
1173 // e12e4f3 shell-background / logical-AND arm closes the `&`
1174 // byte; the backtick (`0x60`) is the orthogonal POSIX legacy
1175 // command-substitution sentinel — every POSIX shell (sh /
1176 // bash / zsh / dash / ksh / fish / nushell) lexes the byte as
1177 // the canonical legacy wrapper that runs the enclosed command
1178 // and substitutes its standard-output verbatim into the
1179 // surrounding word (a `whoami` wrapped in backticks expands
1180 // to the current user's name; a `cat /etc/passwd` wrapped in
1181 // backticks expands to the file's contents — the canonical
1182 // CWE-78 shell-command-injection vector every shell-side
1183 // hardening guide enumerates first). POSIX
1184 // `std::path::Path` treats backtick as a literal path-
1185 // component byte (so `../caixa-teia/<backtick>whoami<backtick>`
1186 // is one directory named literally that, sibling of `.` and
1187 // `..`).
1188 //
1189 // A `:caminho "../caixa-teia/<backtick>whoami<backtick>"` (the
1190 // canonical "I pasted a shell one-liner carrying a backticked
1191 // `whoami` command-substitution expansion into the `:caminho`
1192 // slot" footgun) or `:caminho "<backtick>pwd<backtick>/caixa-
1193 // teia"` (the symmetric "I copied a `<backtick>pwd<backtick>/
1194 // path` working-directory expansion") silently passes every
1195 // prior arm because `Path::is_absolute` returns false on
1196 // `..`, the backtick byte is neither a leading-byte sentinel
1197 // (the f4efe9c `FonteCaminhoVarExpansion` arm catches the
1198 // modern `$()` form at leading position only; backtick is
1199 // the orthogonal legacy form) nor a control byte nor `\` nor
1200 // `<` / `>` nor `|` nor `;` nor `&`, and the value's last
1201 // byte isn't `/`. The resolver folds the value through
1202 // `Path::new(caminho).join(<file>)` looking for a literal
1203 // subdirectory whose name embeds the backticked token and
1204 // fails at resolve time with a non-self-locating `No such
1205 // file or directory` error far from the source caixa.lisp.
1206 //
1207 // The lacre pipeline embeds the value verbatim in its per-
1208 // dep content-address (`conteudo: format!("path:{caminho}")`,
1209 // caixa-resolver/src/resolve.rs:189), so a backtick byte
1210 // lands in the BLAKE3 closure and rides downstream as part
1211 // of the build's identity into every shell-spawned
1212 // subprocess (the caixa-resolver's `git clone` invocation, a
1213 // future `feira tofu` shell-out, a future operator-side
1214 // `nix flake check` spawn) as the canonical shell-metachar
1215 // injection surface every peer single-token-shaped typed
1216 // slot already closes. The peer path-shaped axis
1217 // [`crate::render::is_gateway_api_http_path`]
1218 // (caixa-core/src/render.rs:506) rejects backtick as part of
1219 // its eleven-byte RFC-3986-reserved set on `:entrada
1220 // :paths`. The `:caminho` axis was the last typed path-
1221 // string surface still admitting this byte; this arm closes
1222 // the gap so the substrate-wide "no shell-composition
1223 // metacharacter anywhere in a typed string slot that flows
1224 // verbatim into a shell-spawned subprocess" invariant
1225 // extends from shell-background / logical-AND (`&`) to
1226 // shell-command-substitution (backtick) on the `:caminho`
1227 // axis.
1228 //
1229 // The arm fires AFTER the shell-background arm because the
1230 // prior arm's `cmd & sleep` shape is the more common shell-
1231 // history paste idiom on values that probe as both (a
1232 // `"../caixa-teia & <backtick>whoami<backtick>"` carries
1233 // both `&` and a backtick — the background-launch tail is
1234 // the load-bearing root-cause edit, so
1235 // `FonteCaminhoShellBackground` wins; same cascade
1236 // discipline every prior `:caminho` arm establishes). The
1237 // arm fires BEFORE the trailing-`/` arm because the
1238 // embedded command-substitution byte is the more semantic-
1239 // locating axis on probe-as-both values (a
1240 // `"../<backtick>whoami<backtick>/"` ends in `/` but the
1241 // load-bearing diagnostic is the embedded backtick shell-
1242 // command-substitution metachar — the trailing `/` is the
1243 // secondary observation, and an author who removes the
1244 // backtick is likely to also tab-strip the trailing
1245 // separator).
1246 for &b in caminho.as_bytes() {
1247 if b == b'`' {
1248 return Err(DepError::fonte_caminho_shell_command_substitution(
1249 nome, caminho,
1250 ));
1251 }
1252 }
1253 // Reproducibility gate's shell-glob arm. The c4d62b3 shell-command-
1254 // substitution arm closes the backtick byte; `*` (`0x2A`) and `?`
1255 // (`0x3F`) are the orthogonal POSIX glob-expansion sentinels — same
1256 // paste-from-shell-prompt footgun class, different syntactic surface.
1257 // Every POSIX shell (sh / bash / zsh / dash / ksh / fish / nushell)
1258 // lexes `*` and `?` as pathname-expansion wildcards: `*` matches any
1259 // sequence of characters in a path component (including the empty
1260 // sequence), `?` matches exactly one character. POSIX
1261 // `std::path::Path` treats both bytes as literal path-component bytes
1262 // (so `../caixa-teia/*.lisp` is one directory named literally
1263 // `../caixa-teia/*.lisp`, sibling of `.` and `..`).
1264 //
1265 // A `:caminho "../caixa-teia/*"` (the canonical "I pasted a
1266 // `ls ../caixa-teia/*` shell-listing one-liner into the `:caminho`
1267 // slot" footgun) or `:caminho "../foo?"` (the symmetric "I copied a
1268 // `rm foo?` single-char-wildcard removal idiom") silently passes
1269 // every prior arm because `Path::is_absolute` returns false on `..`,
1270 // `*` / `?` are neither leading-byte sentinels nor control bytes nor
1271 // `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick, and the
1272 // value's last byte isn't `/`. The resolver folds the value through
1273 // `Path::new(caminho).join(<file>)` looking for a literal
1274 // `./../caixa-teia/*` subdirectory and fails at resolve time with a
1275 // non-self-locating `No such file or directory` error far from the
1276 // source caixa.lisp.
1277 //
1278 // The lacre pipeline embeds the value verbatim in its per-dep
1279 // content-address (`conteudo: format!("path:{caminho}")`,
1280 // caixa-resolver/src/resolve.rs:189), so a `*` or `?` byte lands in
1281 // the BLAKE3 closure and rides downstream as part of the build's
1282 // identity into every shell-spawned subprocess (the caixa-resolver's
1283 // `git clone` invocation, a future `feira tofu` shell-out, a future
1284 // operator-side `nix flake check` spawn) as the canonical
1285 // shell-metachar / pathname-expansion surface every peer
1286 // single-token-shaped typed slot already closes. The peer path-shaped
1287 // axis [`crate::render::is_gateway_api_http_path`]
1288 // (caixa-core/src/render.rs:506) rejects `*` and `?` as part of its
1289 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1290 // `:caminho` axis was the last typed path-string surface still
1291 // admitting these two bytes; this arm closes the gap so the
1292 // substrate-wide "no shell-composition / glob-expansion
1293 // metacharacter anywhere in a typed string slot that flows verbatim
1294 // into a shell-spawned subprocess" invariant extends from
1295 // shell-command-substitution (backtick) to glob-expansion
1296 // (`*` / `?`) on the `:caminho` axis.
1297 //
1298 // The arm fires AFTER the backtick arm because the prior arm's
1299 // CWE-78 shell-command-injection vector is the load-bearing
1300 // diagnostic on values that probe as both (a `"../`whoami`/*"`
1301 // carries both backtick and `*` — the command-substitution paste
1302 // is the load-bearing root-cause edit, so
1303 // `FonteCaminhoShellCommandSubstitution` wins; same cascade
1304 // discipline every prior `:caminho` arm establishes). The arm
1305 // fires BEFORE the trailing-`/` arm because the embedded glob
1306 // byte is the more semantic-locating axis on probe-as-both values
1307 // (`"../foo*/"` ends in `/` but the load-bearing diagnostic is the
1308 // embedded `*` glob metachar — the trailing `/` is the secondary
1309 // observation, and an author who removes the `*` is likely to
1310 // also tab-strip the trailing separator).
1311 for &b in caminho.as_bytes() {
1312 if b == b'*' || b == b'?' {
1313 return Err(DepError::fonte_caminho_shell_glob(nome, caminho, b));
1314 }
1315 }
1316 // Reproducibility gate's shell-subshell-grouping arm. The cf9034b
1317 // shell-glob arm closes the `*` / `?` pathname-expansion sentinels;
1318 // `(` (`0x28`) and `)` (`0x29`) are the orthogonal POSIX subshell-
1319 // grouping sentinels — same paste-from-shell-prompt footgun class,
1320 // different syntactic surface. Every POSIX shell (sh / bash / zsh /
1321 // dash / ksh / fish / nushell) lexes the parenthesis pair as the
1322 // subshell-grouping operator: `(<cmd>)` runs `<cmd>` in a child
1323 // shell with a fresh environment scope (the canonical sandboxing
1324 // idiom every shell-history `(cd <path> && <cmd>)` one-liner uses
1325 // to scope a `cd` to one subshell without disturbing the parent's
1326 // working directory), and `$(<cmd>)` is the modern Bourne
1327 // command-substitution shape the upstream f4efe9c
1328 // `FonteCaminhoVarExpansion` arm closes the leading `$` byte of —
1329 // the closing `)` byte completes that substitution shape and must
1330 // be refused on the same axis (peer with the
1331 // [`crate::render::is_git_repo_url`] 3b99147 arm that closes the
1332 // same byte-pair on the sibling `:fonte :repo` axis under the
1333 // same shell-subshell-grouping + RFC-3986-sub-delims banner).
1334 // POSIX `std::path::Path` treats both bytes as literal path-
1335 // component bytes (so `../caixa-teia/(date)` is one directory
1336 // named literally `../caixa-teia/(date)`, sibling of `.` and
1337 // `..`).
1338 //
1339 // A `:caminho "../caixa-teia/$(date)/build"` (the canonical "I
1340 // pasted a `cd ../caixa-teia/$(date)/build` shell-history one-
1341 // liner whose modern command-substitution expansion lands the
1342 // current date as a subdirectory name" footgun) or `:caminho
1343 // "../(cd foo && pwd)/caixa-teia"` (the symmetric "I copied a
1344 // `(cd foo && pwd)` subshell-grouping working-directory probe
1345 // idiom") silently passes every prior arm because
1346 // `Path::is_absolute` returns false on `..`, `(` / `)` are
1347 // neither leading-byte sentinels nor control bytes nor `\` nor
1348 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` / `?`,
1349 // and the value's last byte isn't `/`. The resolver folds the
1350 // value through `Path::new(caminho).join(<file>)` looking for a
1351 // literal `./../caixa-teia/$(date)/build` subdirectory and fails
1352 // at resolve time with a non-self-locating `No such file or
1353 // directory` error far from the source caixa.lisp.
1354 //
1355 // The lacre pipeline embeds the value verbatim in its per-dep
1356 // content-address (`conteudo: format!("path:{caminho}")`,
1357 // caixa-resolver/src/resolve.rs:189), so a `(` or `)` byte lands
1358 // in the BLAKE3 closure and rides downstream as part of the
1359 // build's identity into every shell-spawned subprocess (the
1360 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1361 // shell-out, a future operator-side `nix flake check` spawn) as
1362 // the canonical shell-metachar / subshell-grouping surface every
1363 // peer single-token-shaped typed slot already closes. The peer
1364 // git-source axis [`crate::render::is_git_repo_url`] (3b99147)
1365 // rejects the same byte pair on `:fonte :repo` under the same
1366 // shell-subshell-grouping / RFC-3986-sub-delims banner. The
1367 // `:caminho` axis was the last typed path-string surface still
1368 // admitting these two bytes;
1369 // this arm closes the gap so the substrate-wide "no shell-
1370 // composition metacharacter anywhere in a typed string slot that
1371 // flows verbatim into a shell-spawned subprocess" invariant
1372 // extends from shell-glob (`*` / `?`) to shell-subshell-grouping
1373 // (`(` / `)`) on the `:caminho` axis. Together with the f4efe9c
1374 // leading-`$` arm, the typed `:caminho` accepted set now
1375 // structurally excludes the entire modern Bourne
1376 // command-substitution surface — leading `$` closes the
1377 // leading byte of every `$(<cmd>)` shape, this arm closes the
1378 // trailing `)` boundary.
1379 //
1380 // The arm fires AFTER the shell-glob arm because the prior arm's
1381 // `*` / `?` pathname-expansion shape is the more common shell-
1382 // history paste idiom on values that probe as both
1383 // (`"../caixa-teia/*(date)"` carries both `*` and `(` — the
1384 // glob-paste-tail is the load-bearing root-cause edit, so
1385 // `FonteCaminhoShellGlob` wins; same cascade discipline every
1386 // prior `:caminho` arm establishes). The arm fires BEFORE the
1387 // trailing-`/` arm because the embedded subshell-grouping byte
1388 // is the more semantic-locating axis on probe-as-both values
1389 // (`"../foo(date)/"` ends in `/` but the load-bearing diagnostic
1390 // is the embedded `(` shell-subshell-grouping metachar — the
1391 // trailing `/` is the secondary observation, and an author who
1392 // removes the `(` is likely to also tab-strip the trailing
1393 // separator).
1394 for &b in caminho.as_bytes() {
1395 if b == b'(' || b == b')' {
1396 return Err(DepError::fonte_caminho_shell_subshell_grouping(
1397 nome, caminho, b,
1398 ));
1399 }
1400 }
1401 // Reproducibility gate's shell-brace-expansion arm. The 0633c91
1402 // shell-subshell-grouping arm closes `(` / `)`; `{` (`0x7b`) and
1403 // `}` (`0x7d`) are the orthogonal shell-brace-expansion /
1404 // URI-Template-placeholder byte pair — same paste-from-shell-
1405 // prompt + paste-from-templated-doc footgun class, different
1406 // syntactic surface. Every POSIX-derived shell that implements
1407 // brace expansion (bash / zsh / ksh / fish; the canonical
1408 // `mkdir -p ../{caixa-teia,caixa-helm,caixa-flux}` /
1409 // `cp file{,.bak}` idiom every shell-history block carries)
1410 // expands `{a,b,c}` to the cross-product of its comma-separated
1411 // members and `{1..10}` to the integer range; RFC 6570 reserves
1412 // the matched pair for URI Template placeholders (the canonical
1413 // `https://{host}/{org}/{repo}` substitution shape every
1414 // OpenAPI / Swagger / Postman / GitHub Octokit client /
1415 // Helm chart-URL fragment / Mustache `{{org}}` doubled-brace
1416 // form carries), and Tera / Jinja2 / Handlebars / Go html/template
1417 // every IaC tool (Helm, Kustomize, Terraform's `${var}` cousin
1418 // shape) emit. POSIX `std::path::Path` treats both bytes as
1419 // literal path-component bytes (so `../{caixa-teia,caixa-helm}`
1420 // is one directory named literally `../{caixa-teia,caixa-helm}`,
1421 // sibling of `.` and `..`).
1422 //
1423 // A `:caminho "../{caixa-teia,caixa-helm}/build"` (the canonical
1424 // "I pasted a `cd ../{caixa-teia,caixa-helm}` shell brace-
1425 // expansion one-liner that fans across two siblings" footgun)
1426 // or `:caminho "../{{org}}/caixa-teia"` (the symmetric "I copied
1427 // a `{{org}}` Mustache / Helm template placeholder out of a
1428 // README quick-start and forgot to substitute") silently passes
1429 // every prior arm because `Path::is_absolute` returns false on
1430 // `..`, `{` / `}` are neither leading-byte sentinels nor control
1431 // bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor
1432 // backtick nor `*` / `?` nor `(` / `)`, and the value's last
1433 // byte isn't `/`. The resolver folds the value through
1434 // `Path::new(caminho).join(<file>)` looking for a literal
1435 // `./../{caixa-teia,caixa-helm}/build` subdirectory and fails
1436 // at resolve time with a non-self-locating `No such file or
1437 // directory` error far from the source caixa.lisp.
1438 //
1439 // The lacre pipeline embeds the value verbatim in its per-dep
1440 // content-address (`conteudo: format!("path:{caminho}")`,
1441 // caixa-resolver/src/resolve.rs:189), so a `{` or `}` byte
1442 // lands in the BLAKE3 closure and rides downstream as part of
1443 // the build's identity into every shell-spawned subprocess
1444 // (the caixa-resolver's `git clone` invocation, a future
1445 // `feira tofu` shell-out, a future operator-side `nix flake
1446 // check` spawn) as the canonical shell-metachar / brace-
1447 // expansion surface every peer single-token-shaped typed
1448 // slot already closes. The peer git-source axis
1449 // [`crate::render::is_git_repo_url`] (42d8f9d — the URI Template
1450 // placeholder arm) rejects the same byte pair on `:fonte :repo`
1451 // under the same RFC-3986-'delims' / RFC-6570-URI-Template /
1452 // shell-brace-expansion banner. The `:caminho` axis was the last
1453 // typed path-string surface still admitting these two bytes;
1454 // this arm closes the gap so the substrate-wide "no shell-
1455 // composition metacharacter anywhere in a typed string slot
1456 // that flows verbatim into a shell-spawned subprocess"
1457 // invariant extends from shell-subshell-grouping (`(` / `)`)
1458 // to shell-brace-expansion (`{` / `}`) on the `:caminho` axis,
1459 // and the typed `:caminho` accepted set now also structurally
1460 // excludes the URI Template / templating-engine placeholder
1461 // surface that would silently round-trip through any
1462 // downstream IaC templating-engine layer.
1463 //
1464 // The arm fires AFTER the shell-subshell-grouping arm because
1465 // the prior arm's `(` / `)` shape is the more semantic-locating
1466 // axis on values that probe as both (`"../{cd foo}(date)"`
1467 // carries both `{` and `(` — the parenthesis-pair is the
1468 // load-bearing modern-Bourne-command-substitution surface the
1469 // prior arm closes; same cascade discipline every prior
1470 // `:caminho` arm establishes). The arm fires BEFORE the
1471 // trailing-`/` arm because the embedded brace-expansion byte
1472 // is the more semantic-locating axis on probe-as-both values
1473 // (`"../{caixa-teia,caixa-helm}/"` ends in `/` but the
1474 // load-bearing diagnostic is the embedded `{` brace-expansion
1475 // metachar — the trailing `/` is the secondary observation,
1476 // and an author who removes the `{` is likely to also tab-
1477 // strip the trailing separator).
1478 for &b in caminho.as_bytes() {
1479 if b == b'{' || b == b'}' {
1480 return Err(DepError::fonte_caminho_shell_brace_expansion(
1481 nome, caminho, b,
1482 ));
1483 }
1484 }
1485 // Reproducibility gate's shell-bracket-expansion arm. The 598b770
1486 // shell-brace-expansion arm closes `{` / `}`; `[` (`0x5b`) and
1487 // `]` (`0x5d`) are the orthogonal POSIX glob-character-class /
1488 // shell-`test`-builtin byte pair — same paste-from-shell-prompt
1489 // footgun class, different syntactic surface. Every POSIX shell
1490 // (sh / bash / zsh / dash / ksh / fish / nushell) lexes the
1491 // bracket pair as the glob character-class operator: `[abc]`
1492 // matches one of `a`, `b`, `c`; `[a-z]` matches any lowercase
1493 // ASCII letter; `[^x]` negates (the canonical
1494 // `ls *.[ch]` C-source-file glob and the `cd ../[a-z]*`
1495 // lowercase-sibling glob every shell-history block carries —
1496 // the orthogonal axis to the cf9034b `*` / `?` shell-glob arm
1497 // closing the unbounded pathname-expansion sentinels). The
1498 // bracket pair additionally carries the POSIX `test` /
1499 // `[` builtin command (`[ -d ../caixa-teia ] && cd ...` —
1500 // the canonical idiom every shell-script conditional uses) and
1501 // bash's `[[ ... ]]` extended-test grammar. Beyond shell, the
1502 // bracket pair is the TOML inline-array delimiter
1503 // (`features = ["a", "b"]` — the canonical paste-from-Cargo-
1504 // manifest cross-idiom-leak vector), the YAML flow-sequence
1505 // delimiter (`paths: [/a, /b]` — the canonical paste-from-
1506 // values.yaml cross-idiom leak), the JSON array delimiter,
1507 // and the POSIX-ERE / PCRE bracket-expression / character-
1508 // class anchor (the canonical paste-from-regex-doc shape).
1509 // POSIX `std::path::Path` treats both bytes as literal path-
1510 // component bytes (so `../[caixa-teia]` is one directory
1511 // named literally `../[caixa-teia]`, sibling of `.` and
1512 // `..`).
1513 //
1514 // A `:caminho "../caixa-[a-z]/build"` (the canonical "I
1515 // pasted a `cd ../caixa-[a-z]/build` glob-character-class
1516 // one-liner that matches every lowercase-sibling-suffix
1517 // sibling directory" footgun), `:caminho "../[caixa-teia]/
1518 // build"` (the symmetric "I pasted a TOML inline-array /
1519 // YAML flow-sequence shape out of an aligned manifest"
1520 // idiom), or `:caminho "../caixa-[ch]"` (the canonical
1521 // `*.[ch]` C-source character-class paste-from-shell-history
1522 // shape) silently passes every prior arm because
1523 // `Path::is_absolute` returns false on `..`, `[` / `]` are
1524 // neither leading-byte sentinels nor control bytes nor `\`
1525 // nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1526 // `*` / `?` nor `(` / `)` nor `{` / `}`, and the value's
1527 // last byte isn't `/`. The resolver folds the value through
1528 // `Path::new(caminho).join(<file>)` looking for a literal
1529 // `./../caixa-[a-z]/build` subdirectory and fails at resolve
1530 // time with a non-self-locating `No such file or directory`
1531 // error far from the source caixa.lisp.
1532 //
1533 // The lacre pipeline embeds the value verbatim in its per-dep
1534 // content-address (`conteudo: format!("path:{caminho}")`,
1535 // caixa-resolver/src/resolve.rs:189), so a `[` or `]` byte
1536 // lands in the BLAKE3 closure and rides downstream as part of
1537 // the build's identity into every shell-spawned subprocess
1538 // (the caixa-resolver's `git clone` invocation, a future
1539 // `feira tofu` shell-out, a future operator-side `nix flake
1540 // check` spawn) as the canonical shell-metachar / glob-
1541 // character-class / TOML-array surface every peer single-
1542 // token-shaped typed slot already closes. The `:caminho` axis
1543 // was the last typed path-string surface still admitting
1544 // these two bytes; this arm closes the gap so the substrate-
1545 // wide "no shell-composition metacharacter anywhere in a
1546 // typed string slot that flows verbatim into a shell-spawned
1547 // subprocess" invariant extends from shell-brace-expansion
1548 // (`{` / `}`) to shell-bracket-expansion (`[` / `]`) on the
1549 // `:caminho` axis. Together with the cf9034b `*` / `?` arm,
1550 // the typed `:caminho` accepted set now structurally excludes
1551 // the entire POSIX pathname-expansion / glob surface —
1552 // unbounded glob (`*` / `?`) AND bounded character-class
1553 // (`[abc]` / `[a-z]`).
1554 //
1555 // The arm fires AFTER the shell-brace-expansion arm because
1556 // the prior arm's `{` / `}` shape is the more semantic-
1557 // locating axis on values that probe as both
1558 // (`"../{a,b}[ch]"` carries both `{` and `[` — the brace-
1559 // expansion fan is the load-bearing root-cause edit, so
1560 // `FonteCaminhoShellBraceExpansion` wins; same cascade
1561 // discipline every prior `:caminho` arm establishes). The arm
1562 // fires BEFORE the trailing-`/` arm because the embedded
1563 // bracket-expansion byte is the more semantic-locating axis
1564 // on probe-as-both values (`"../[a-z]/"` ends in `/` but the
1565 // load-bearing diagnostic is the embedded `[` glob-character-
1566 // class metachar — the trailing `/` is the secondary
1567 // observation, and an author who removes the `[` is likely
1568 // to also tab-strip the trailing separator).
1569 for &b in caminho.as_bytes() {
1570 if b == b'[' || b == b']' {
1571 return Err(DepError::fonte_caminho_shell_bracket_expansion(
1572 nome, caminho, b,
1573 ));
1574 }
1575 }
1576 // Reproducibility gate's shell-quote-grouping arm. The 986963b
1577 // shell-bracket-expansion arm closes `[` / `]`; `'` (`0x27`) and
1578 // `"` (`0x22`) are the orthogonal POSIX shell-string-literal
1579 // delimiter pair — same paste-from-shell-prompt footgun class,
1580 // different syntactic surface. Every POSIX shell (sh / bash /
1581 // zsh / dash / ksh / fish / nushell) lexes the pair as the
1582 // string-literal quoting operator: `'…'` is the strong
1583 // (no-expansion) single-quoted string and `"…"` is the weak
1584 // (variable-/command-substitution-preserving) double-quoted
1585 // string — the canonical `cd '../caixa-teia'` shell-history
1586 // idiom every path-with-embedded-whitespace paste block carries,
1587 // and the symmetric `git clone "$REPO"` weak-quoted CI-manifest
1588 // shape. Beyond shell, the two bytes carry the JSON string-literal
1589 // delimiter (`"key": "value"` — the canonical paste-from-JSON-
1590 // config cross-idiom-leak vector), the YAML double-quoted +
1591 // single-quoted flow-scalar delimiters (`path: "../caixa-teia"`
1592 // — the canonical paste-from-values.yaml / paste-from-K8s-YAML-
1593 // manifest cross-idiom leak), the TOML basic + literal string
1594 // delimiters (`path = "../caixa-teia"` — the canonical paste-
1595 // from-Cargo-manifest cross-idiom-leak vector), the tatara-lisp
1596 // string-literal delimiter itself (`(:caminho "../caixa-teia")`
1597 // — the canonical "I copied the entire `:caminho "..."` slot
1598 // rather than just the string body" author-surface footgun),
1599 // and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which
1600 // excludes both bytes from the `unreserved / pct-encoded /
1601 // sub-delims / ":" / "@"` `pchar` production. POSIX
1602 // `std::path::Path` treats both bytes as literal path-component
1603 // bytes (so `../"caixa-teia"` is one directory named literally
1604 // `../"caixa-teia"`, sibling of `.` and `..`).
1605 //
1606 // A `:caminho "'../caixa-teia'"` (the canonical "I pasted a
1607 // `cd '../caixa-teia'` shell-history one-liner whose strong-
1608 // quoting preserved the sibling-workspace path verbatim across
1609 // the whitespace paste boundary" footgun), `:caminho
1610 // "\"../caixa-teia\""` (the symmetric weak-quoted paste-from-
1611 // JSON / paste-from-YAML flow-scalar / paste-from-TOML basic-
1612 // string / paste-from-tatara-lisp string-literal cross-idiom-
1613 // leak shape), or `:caminho "../\"caixa-teia\""` (the embedded-
1614 // quote "I pasted a JSON key-value pair fragment into the
1615 // middle of the path" idiom) silently passes every prior arm
1616 // because `Path::is_absolute` returns false on `..` / `'` /
1617 // `"`, `'` / `"` are neither leading-byte sentinels nor
1618 // control bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&`
1619 // nor backtick nor `*` / `?` nor `(` / `)` nor `{` / `}` nor
1620 // `[` / `]`, and the value's last byte isn't `/`. The resolver
1621 // folds the value through `Path::new(caminho).join(<file>)`
1622 // looking for a literal `./'../caixa-teia'` subdirectory and
1623 // fails at resolve time with a non-self-locating `No such file
1624 // or directory` error far from the source caixa.lisp.
1625 //
1626 // The lacre pipeline embeds the value verbatim in its per-dep
1627 // content-address (`conteudo: format!("path:{caminho}")`,
1628 // caixa-resolver/src/resolve.rs:189), so a `'` or `"` byte
1629 // lands in the BLAKE3 closure and rides downstream as part of
1630 // the build's identity into every shell-spawned subprocess
1631 // (the caixa-resolver's `git clone` invocation, a future
1632 // `feira tofu` shell-out, a future operator-side `nix flake
1633 // check` spawn) as the canonical shell-metachar / string-
1634 // literal-delimiter surface every peer single-token-shaped
1635 // typed slot already closes. The peer `:fonte :repo` axis
1636 // closes both bytes under the same shell-quote-grouping /
1637 // RFC-3986-sub-delims banner (e7a109f `'` shell-single-quote
1638 // + 4267d8b `"` shell-double-quote on `is_git_repo_url`). The
1639 // `:caminho` axis was the last typed path-string surface
1640 // still admitting these two bytes; this arm closes the gap
1641 // so the substrate-wide "no shell-composition metacharacter
1642 // anywhere in a typed string slot that flows verbatim into a
1643 // shell-spawned subprocess" invariant extends from shell-
1644 // bracket-expansion (`[` / `]`) to shell-quote-grouping (`'`
1645 // / `"`) on the `:caminho` axis. Together with the peer
1646 // JSON / YAML / TOML string-literal delimiters closing at
1647 // this arm and the 598b770 `{` / `}` brace-expansion arm
1648 // closing the templating-engine-placeholder boundary, the
1649 // typed `:caminho` accepted set now structurally excludes
1650 // the entire cross-config-DSL string-literal / templating
1651 // paste-from-aligned-manifest cross-idiom-leak surface that
1652 // would silently round-trip through any downstream JSON /
1653 // YAML / TOML / HCL / tatara-lisp parsing layer.
1654 //
1655 // The arm fires AFTER the shell-bracket-expansion arm because
1656 // the prior arm's `[` / `]` shape is the more semantic-
1657 // locating axis on values that probe as both (`"../[a-z]'x'"`
1658 // carries both `[` and `'` — the glob-character-class
1659 // expansion is the load-bearing root-cause edit, so
1660 // `FonteCaminhoShellBracketExpansion` wins; same cascade
1661 // discipline every prior `:caminho` arm establishes). The arm
1662 // fires BEFORE the trailing-`/` arm because the embedded
1663 // quote-grouping byte is the more semantic-locating axis on
1664 // probe-as-both values (`"../'caixa-teia'/"` ends in `/` but
1665 // the load-bearing diagnostic is the embedded `'` shell-
1666 // string-literal metachar — the trailing `/` is the secondary
1667 // observation, and an author who removes the `'` is likely to
1668 // also tab-strip the trailing separator).
1669 for &b in caminho.as_bytes() {
1670 if b == b'\'' || b == b'"' {
1671 return Err(DepError::fonte_caminho_shell_quote_grouping(
1672 nome, caminho, b,
1673 ));
1674 }
1675 }
1676 // Reproducibility gate's shell-comment / URL-fragment / YAML-comment arm.
1677 // The d14cbc5 shell-quote-grouping arm closes `'` / `"`; `#` (`0x23`) is
1678 // the orthogonal "byte at which four distinct downstream parsers all
1679 // truncate the value at the first occurrence" surface, and no prior arm
1680 // has covered it on the `:caminho` axis. Every POSIX shell (sh / bash /
1681 // zsh / dash / ksh / fish / nushell) lexes an unquoted `#` at the head
1682 // of a word (or after unquoted whitespace) as the comment-lead: from
1683 // that byte to the end of the physical line is a comment discarded
1684 // before command parsing (`cd ../caixa-teia # legacy sibling` — the
1685 // canonical paste-from-shell-history-with-trailing-annotation shape
1686 // every operator-notebook and CI-manifest carries; POSIX.1-2017 §2.3
1687 // Token Recognition step 6). YAML 1.2 §6.6 makes `#` the comment lead
1688 // at any position preceded by whitespace or at line-start (`path:
1689 // ../caixa-teia # pin` — the canonical paste-from-values.yaml /
1690 // paste-from-K8s-manifest cross-idiom-leak shape). tatara-lisp itself
1691 // treats `;` as the comment-lead but a growing number of consumer
1692 // config-DSL layers (HCL, Terraform, Nix flake attributes, .env
1693 // dotenv-style files, gitconfig / .gitignore, ini / TOML) use `#` as
1694 // the comment-lead too — the pair extends the cross-config-DSL
1695 // paste-idiom surface the d14cbc5 quote-grouping arm and the 598b770
1696 // brace-expansion arm already cover on adjacent axes. RFC 3986 §3.5
1697 // reserves `#` as the URL fragment-identifier delimiter (the canonical
1698 // paste-from-browser-address-bar `github.com/foo/bar#readme` /
1699 // `github.com/foo/bar#L42` permalink shape, and the symmetric
1700 // Nix-flake-ref cross-idiom leak `github:foo/bar#packageName` where
1701 // `#` selects a flake output — the same axis the peer
1702 // [`crate::render::is_git_repo_url`] closes on the `:fonte :repo`
1703 // surface at a68f818 with the same downstream-drops-the-tail
1704 // rationale).
1705 //
1706 // POSIX `std::path::Path` treats `#` as a literal path-component byte,
1707 // so a `:caminho "../caixa-teia # legacy sibling"` (the canonical
1708 // paste-from-shell-history-with-trailing-annotation footgun),
1709 // `:caminho "../caixa-teia # pin"` (the symmetric YAML flow-scalar
1710 // paste-with-trailing-comment shape), or `:caminho "../caixa-teia
1711 // #readme"` (the URL fragment paste-from-browser-address-bar shape)
1712 // silently passes every prior arm because `Path::is_absolute` returns
1713 // false on `..`, `#` is neither a leading-byte sentinel nor a control
1714 // byte nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1715 // `*` / `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` / `"`,
1716 // and the value's last byte isn't `/`. The resolver folds the value
1717 // through `Path::new(caminho).join(<file>)` looking for a literal
1718 // subdirectory named `../caixa-teia # legacy sibling` and fails at
1719 // resolve time with a non-self-locating `No such file or directory`
1720 // error far from the source caixa.lisp — while every downstream
1721 // shell / YAML / URL parser silently truncates the value at the `#`
1722 // byte to `../caixa-teia`, so a `feira tofu` shell-out to a
1723 // `cd '{caminho}'` command line and a `nix flake check` invocation on
1724 // an emitted YAML `path:` scalar disagree with the resolver on which
1725 // directory the value names. Two workstations whose downstream
1726 // shell / YAML / URL parsing layers differ in unquoted-`#`
1727 // recognition emit divergent build artifacts for the byte-identical
1728 // caixa.lisp value.
1729 //
1730 // The lacre pipeline embeds the value verbatim in its per-dep
1731 // content-address (`conteudo: format!("path:{caminho}")`,
1732 // caixa-resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1733 // closure and rides downstream as part of the build's identity into
1734 // every shell-spawned subprocess (the caixa-resolver's `git clone`
1735 // invocation, a future `feira tofu` shell-out, a future operator-side
1736 // `nix flake check` spawn) as the canonical shell-metachar /
1737 // comment-lead / URL-fragment-delimiter surface every peer
1738 // single-token-shaped typed slot already closes. The peer `:fonte
1739 // :repo` axis closes the byte under the URL-fragment-identifier
1740 // banner (a68f818 `#` on `is_git_repo_url`); the `:caminho` axis was
1741 // the last typed path-string surface still admitting the byte. This
1742 // arm closes the gap so the substrate-wide "no shell-composition
1743 // metacharacter / comment-lead / URL-fragment-delimiter anywhere in a
1744 // typed string slot that flows verbatim into a shell-spawned
1745 // subprocess or downstream YAML / URL parser" invariant extends from
1746 // shell-quote-grouping (`'` / `"`) to shell-comment / URL-fragment
1747 // (`#`) on the `:caminho` axis. Together with the peer JSON / YAML /
1748 // TOML string-literal delimiters the d14cbc5 quote-grouping arm
1749 // closes and the 598b770 `{` / `}` brace-expansion arm closes on the
1750 // templating-engine-placeholder boundary, the typed `:caminho`
1751 // accepted set now structurally excludes the entire
1752 // paste-with-trailing-annotation / paste-from-URL-permalink /
1753 // paste-from-YAML-comment cross-idiom-leak surface that would
1754 // silently round-trip through any downstream shell / YAML / URL /
1755 // dotenv / gitconfig / HCL parsing layer to a different value than
1756 // the resolver's `Path::join` sees.
1757 //
1758 // The arm fires AFTER the shell-quote-grouping arm because the prior
1759 // arm's `'` / `"` shape is the more semantic-locating axis on values
1760 // that probe as both (`"../'x'#pin"` carries both `'` and `#` — the
1761 // shell-string-literal-delimiter is the load-bearing root-cause edit,
1762 // so `FonteCaminhoShellQuoteGrouping` wins; same cascade discipline
1763 // every prior `:caminho` arm establishes). The arm fires BEFORE the
1764 // trailing-`/` arm because the embedded comment-lead / fragment-
1765 // delimiter byte is the more semantic-locating axis on probe-as-both
1766 // values (`"../caixa-teia#pin/"` ends in `/` but the load-bearing
1767 // diagnostic is the embedded `#` — the trailing `/` is the secondary
1768 // observation, and an author who removes the `#pin` fragment is
1769 // likely to also tab-strip the trailing separator).
1770 for &b in caminho.as_bytes() {
1771 if b == b'#' {
1772 return Err(DepError::fonte_caminho_shell_comment(nome, caminho, b));
1773 }
1774 }
1775 // Reproducibility gate's URL-percent-encoding-escape arm. The 6622063
1776 // shell-comment arm closes the `#` URL-fragment-identifier byte; `%`
1777 // (`0x25`) is the orthogonal RFC 3986 §2.1 URL percent-encoding-escape
1778 // byte — the mandatory encoding mechanism for every byte outside the
1779 // `unreserved` alphanumeric / `-` / `.` / `_` / `~` set, and `%`
1780 // itself must be percent-encoded as `%25` to appear literally inside
1781 // a URL value. The byte carries three distinct render-determinism
1782 // hazards on the `:caminho` axis, no prior arm has covered it, and
1783 // the peer `:fonte :repo` axis (a323db8 `%` on `is_git_repo_url`)
1784 // already closes the same byte under the same URL-percent-encoding
1785 // banner — the `:caminho` axis was the last typed path-string surface
1786 // still admitting the byte.
1787 //
1788 // First, the paste-from-browser-address-bar percent-encoded-space
1789 // footgun: an author copies `../caixa%20teia` out of a URL-encoded
1790 // README hyperlink / a browser address bar / a percent-encoded
1791 // permalink expecting `%20` to decode to a literal space at the
1792 // filesystem layer. POSIX `std::path::Path` treats the byte as a
1793 // literal path-component byte, so `Path::join` looks for a literal
1794 // `./../caixa%20teia` subdirectory and fails at resolve time with a
1795 // non-self-locating `No such file or directory` error far from the
1796 // source caixa.lisp — while the author's mental model was
1797 // `../caixa teia`, the decoded shape. Two authors whose only
1798 // difference is percent-encoding presence resolve to two distinct
1799 // BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`)
1800 // for what they intended as the byte-identical sibling-workspace
1801 // dep. The lacre pipeline embeds the value verbatim in its per-dep
1802 // content-address (`conteudo: format!("path:{caminho}")`,
1803 // caixa-resolver/src/resolve.rs:189), so the divergence rides
1804 // downstream into the BLAKE3 closure and locks the substrate's
1805 // "the lacre is the build's identity" contract (CAIXA-SDLC §III.2)
1806 // to the wrong encoding — the same THEORY.md §V.2 render-
1807 // determinism vector every prior `:caminho` arm protects.
1808 //
1809 // Second, the printf-format-specifier lead footgun: `%` is the C /
1810 // POSIX printf format-directive lead-in (`%s`, `%d`, `%02x`, the
1811 // canonical `printf "path=%s\n" ../caixa-teia` invocation every
1812 // shell-diagnostic one-liner carries) and the printf builtin is
1813 // wired into every POSIX shell (bash / zsh / dash / ksh / busybox
1814 // ash) as the format-string lead. A `:caminho "../caixa-%s-teia"`
1815 // value flowing into any future `feira` verb that shells out with a
1816 // printf-formatted path template silently gets reinterpreted as a
1817 // format-directive rather than a literal byte — the canonical
1818 // CWE-134 format-string-injection vector.
1819 //
1820 // Third, the bash-job-control-specifier lead footgun: bash / zsh /
1821 // ksh reserve `%N` at word-start as the job-control specifier —
1822 // `%1` names "job 1", `%%` names "the current job", `%foo` names
1823 // "the most recent job whose command started with `foo`". A future
1824 // `feira` verb that invokes `kill %1` on a caminho-scoped
1825 // subprocess would silently redirect the signal to a wrong target.
1826 //
1827 // Beyond the three shell-side hazards, `%` is a first-class parser
1828 // byte in three cross-config-DSL layers the substrate's paste-idiom
1829 // surface routinely crosses: YAML 1.2 §6.8.1 lexes `%` at
1830 // line-start as the directive lead (`%YAML 1.2` / `%TAG` — a
1831 // `:caminho "%YAML/1.2/../caixa-teia"` paste from a top-of-doc
1832 // YAML directive block silently trips the YAML directive parser on
1833 // any downstream emitted YAML manifest); Prometheus / Grafana
1834 // template syntax uses `%(var)s` as the substitution lead; and Nix
1835 // interpolation uses `${var}` (not `%`) but Envsubst /
1836 // Kubernetes / OpenShift template layers use `%VAR%` as the
1837 // Windows-shell env-var-reference lead — the paste-from-`.bat` /
1838 // paste-from-PowerShell-`%env:PATH%` cross-idiom leak.
1839 //
1840 // The three malformed-`%HH` classes documented on the peer
1841 // `is_git_repo_url` `%` arm (a323db8) apply here too:
1842 //
1843 // - The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
1844 // where `%` isn't followed by two hex digits) — every WHATWG-
1845 // conformant URL parser rejects the value at parse time per
1846 // RFC 3986 §2.1, but the byte rides into the lacre before
1847 // the resolver subprocess crosses the URL-parser boundary.
1848 // - The over-encoded path-separator shape (`"../caixa%2Fteia"`
1849 // intending the `%2F` as the URL encoding of `/`) locks a
1850 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
1851 // the byte-identical `path:../caixa/teia` form.
1852 // - The double-encoded shape (`"../caixa%2520teia"` — the `%25`
1853 // already itself an encoded `%`, so the intent was likely a
1854 // literal `%20` that survived one round-trip through a
1855 // URL-encoder that shouldn't have run) locks a triply-
1856 // divergent closure across the encoded / once-decoded /
1857 // twice-decoded chain.
1858 //
1859 // POSIX `std::path::Path` treats the byte as a literal path-
1860 // component byte, so a `:caminho "../caixa%20teia"` (the canonical
1861 // paste-from-browser-address-bar percent-encoded-space footgun),
1862 // `:caminho "%YAML/../caixa-teia"` (the symmetric paste-from-YAML-
1863 // directive-block cross-idiom leak), or `:caminho
1864 // "../caixa-%s-teia"` (the printf-format-specifier paste-from-
1865 // shell-diagnostic-one-liner shape) silently passes every prior arm
1866 // because `Path::is_absolute` returns false on `..`, `%` is neither
1867 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
1868 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
1869 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`, and the
1870 // value's last byte isn't `/`. The resolver folds the value through
1871 // `Path::new(caminho).join(<file>)` looking for a literal
1872 // subdirectory named `../caixa%20teia` and fails at resolve time
1873 // with a non-self-locating `No such file or directory` error far
1874 // from the source caixa.lisp — while every downstream URL parser /
1875 // shell printf builtin / YAML directive parser silently
1876 // reinterprets the byte to a different value than the resolver's
1877 // `Path::join` sees. Two workstations whose downstream URL / shell
1878 // / YAML layers differ in `%HH` recognition emit divergent build
1879 // artifacts for the byte-identical caixa.lisp value.
1880 //
1881 // The lacre pipeline embeds the value verbatim in its per-dep
1882 // content-address (`conteudo: format!("path:{caminho}")`, caixa-
1883 // resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1884 // closure and rides into every shell-spawned subprocess (the
1885 // resolver's `git clone`, a future `feira tofu` shell-out, a
1886 // future operator-side `nix flake check` spawn) as the canonical
1887 // URL-percent-encoding-escape / printf-format-specifier / bash-
1888 // job-control-specifier surface every peer single-token-shaped
1889 // typed slot already closes. This arm closes the gap so the
1890 // substrate-wide "no URL-percent-encoding-escape / printf-format-
1891 // specifier / job-control-specifier / YAML-directive-lead byte
1892 // anywhere in a typed string slot that flows verbatim into a
1893 // shell-spawned subprocess or downstream URL / printf / YAML
1894 // parser" invariant extends from shell-comment / URL-fragment
1895 // (`#` — 6622063) to URL-percent-encoding-escape (`%`) on the
1896 // `:caminho` axis.
1897 //
1898 // The arm fires AFTER the shell-comment arm because the prior
1899 // arm's `#` shape is the more semantic-locating axis on values
1900 // that probe as both (`"../caixa%20teia#pin"` carries both `%`
1901 // and `#` — the URL-fragment-identifier is the load-bearing
1902 // downstream-truncation edit, so `FonteCaminhoShellComment` wins;
1903 // same cascade discipline every prior `:caminho` arm establishes).
1904 // The arm fires BEFORE the trailing-`/` arm because the embedded
1905 // percent-encoding-escape byte is the more semantic-locating axis
1906 // on probe-as-both values (`"../caixa%20teia/"` ends in `/` but
1907 // the load-bearing diagnostic is the embedded `%` percent-
1908 // encoding-escape — the trailing `/` is the secondary observation,
1909 // and an author who decodes the `%20` to a literal space is
1910 // likely to also tab-strip the trailing separator).
1911 for &b in caminho.as_bytes() {
1912 if b == b'%' {
1913 return Err(DepError::fonte_caminho_url_percent_encoding(
1914 nome, caminho, b,
1915 ));
1916 }
1917 }
1918 // Reproducibility gate's embedded-`$` shell-variable-expansion /
1919 // command-substitution / arithmetic-expansion arm. The f4efe9c
1920 // leading-`$` arm at line 540 routes `caminho.starts_with('$')`
1921 // through `FonteCaminhoVarExpansion` under the leading-byte-
1922 // sentinel host-layout-leak banner (peer with the b94fd83
1923 // absolute / a5c248e tilde leading-byte arms), but the arm
1924 // fires only at position 0 — a `:caminho "../foo$HOME/bar"`
1925 // (embedded `$HOME` in a nested path segment — the canonical
1926 // paste-from-`ls ../foo$HOME/bar`-shell-one-liner footgun where
1927 // an author copies a partially-substituted shell one-liner and
1928 // the leading segment is a literal `../foo` while the mid
1929 // segment carries the un-substituted `$HOME` template), a
1930 // `:caminho "../foo${WORKSPACE}/bar"` (the symmetric braced-CI-
1931 // manifest paste-from-`.gitlab-ci.yml` / paste-from-GitHub-
1932 // Actions-workflow shape), a `:caminho "../foo$(whoami)/bar"`
1933 // (the paste-from-shell-prompt command-substitution idiom), or
1934 // a `:caminho "../foo$((1+2))/bar"` (the arithmetic-expansion
1935 // idiom) silently passes every prior arm because
1936 // `Path::is_absolute` returns false on `..`, `$` is neither a
1937 // leading-byte sentinel (the f4efe9c arm fires only at position
1938 // 0) nor a control byte nor `\` nor `<` / `>` nor `|` nor `;`
1939 // nor `&` nor backtick nor `*` / `?` nor `(` / `)` nor `{` /
1940 // `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%`, and the
1941 // value's last byte isn't `/`. Note that `$(...)` command-
1942 // substitution and `$((...))` arithmetic-expansion each carry
1943 // an embedded `(` byte that the 0633c91 shell-subshell-grouping
1944 // arm catches structurally at the earlier `(` position — but
1945 // an author who reaches for the sh-brace-substitution
1946 // `${VAR}` or the bare `$VAR` shape carries only the `$` byte,
1947 // which no prior arm covers. This arm closes the last
1948 // positional gap on the `$` byte on the `:caminho` axis so
1949 // every position — leading (`FonteCaminhoVarExpansion`) and
1950 // embedded (`FonteCaminhoShellVariableExpansion`) — is
1951 // structurally rejected.
1952 //
1953 // Every POSIX shell (sh / bash / zsh / dash / ksh / busybox
1954 // ash / fish / nushell) lexes `$` as the variable-expansion /
1955 // command-substitution / arithmetic-expansion operator per
1956 // POSIX.1-2017 §2.6 (Word Expansions): `$<name>` (Parameter
1957 // Expansion) expands a named variable, `${<name>}` (Parameter
1958 // Expansion braced form) does the same with an explicit token
1959 // boundary, `$(<cmd>)` (Command Substitution modern form,
1960 // `` `<cmd>` `` legacy form which the c370458 backtick arm
1961 // already closes) runs a subshell and substitutes its stdout,
1962 // and `$((<expr>))` (Arithmetic Expansion) evaluates an
1963 // arithmetic expression. Every form is a host-layout /
1964 // environment-state / shell-subprocess-side-effect leak when
1965 // the byte lands in a value the resolver passes to a shell-
1966 // spawned subprocess. Beyond the POSIX shell layer, `$` is
1967 // the Nix `${var}` string-interpolation lead (the paste-from-
1968 // `flake.nix` / paste-from-`.nix`-attribute cross-idiom leak
1969 // where an author copies `"${pkgs.hello}/bin/hello"` out of a
1970 // nix expression), the Make `$(var)` / `$@` / `$<` automatic-
1971 // variable lead (the paste-from-`Makefile` shape), the
1972 // JavaScript / TypeScript template-literal `${expr}` interp
1973 // lead (the paste-from-JS-template-string idiom in a
1974 // multi-lang-monorepo where a `path` attribute gets copied out
1975 // of a `package.json` script or a Vite config), the envsubst /
1976 // Kubernetes / OpenShift template `${VAR}` interp lead (the
1977 // paste-from-Helm-values / paste-from-K8s-manifest cross-idiom
1978 // leak), the PHP variable lead (`$_GET`, `$_ENV` — the paste-
1979 // from-`.php`-config footgun), the Perl scalar-variable lead
1980 // (`$foo`), the SASS / SCSS variable lead (`$primary-color`),
1981 // and the SQL bind-parameter lead in PostgreSQL / SQLite
1982 // (`$1`, `$2` — the paste-from-`.sql`-migration idiom). The
1983 // cross-idiom paste-footgun surface is broader than any single
1984 // shell layer — `$` is a first-class parser byte in nearly
1985 // every config / templating / build-system DSL the substrate's
1986 // paste-idiom surface routinely crosses. The peer `:fonte
1987 // :repo` axis closes the byte under the shell-variable-
1988 // expansion / URL-sub-delim banner (b9d187c `$` on
1989 // `is_git_repo_url`), the peer `:fonte :tag` / `:fonte :branch`
1990 // axes close `$` as part of `is_git_ref_name`'s printable-
1991 // ASCII-restricted grammar (`git check-ref-format` rejects the
1992 // byte outright), and the peer `:entrada :paths` axis closes
1993 // `$` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-
1994 // reserved set. The `:caminho` axis was the last typed path-
1995 // string surface still admitting `$` at positions other than 0.
1996 //
1997 // POSIX `std::path::Path` treats `$` as a literal path-
1998 // component byte, so `:caminho "../foo$HOME/bar"` silently
1999 // routes through `Path::new(caminho).join(<file>)` looking for
2000 // a literal `./{caminho}` subdirectory that fails at resolve
2001 // time with a non-self-locating `No such file or directory`
2002 // error far from the source caixa.lisp. But every downstream
2003 // shell / envsubst / Nix / Make / K8s-template parser silently
2004 // reinterprets the byte to a different value than the
2005 // resolver's `Path::join` sees — so a `feira tofu` shell-out
2006 // to a `cd '{caminho}'` command line, a `nix flake check`
2007 // invocation on an emitted YAML `path:` scalar folded through
2008 // envsubst, or a `helm template` invocation with a
2009 // `values.yaml` `path: {caminho}` embedded in a `{{`-quoted
2010 // template all disagree with the resolver on which directory
2011 // the value names. Two workstations whose downstream shell /
2012 // envsubst / Nix / Make / K8s-template parsing layers differ
2013 // in `$VAR` recognition (or, worse, expand the byte against
2014 // divergent environments — Alice's `$HOME=/home/alice`, Bob's
2015 // `$HOME=/home/bob`) emit divergent build artifacts for the
2016 // byte-identical caixa.lisp value. Even in the case where the
2017 // resolver strictly does NOT expand `$VAR` (the current
2018 // implementation) the divergence still bites at the lacre-
2019 // identity axis: the lacre pipeline embeds the value verbatim
2020 // in its per-dep content-address (`conteudo:
2021 // format!("path:{caminho}")`, caixa-resolver/src/resolve.rs:189),
2022 // so `path:../foo$HOME/bar` locks a BLAKE3 closure distinct
2023 // from the byte-identical-semantic `path:../foo/home/alice/bar`
2024 // one author would have produced by substituting the literal
2025 // value at author time, defeating the THEORY.md §V.2 render-
2026 // determinism contract on the same axis every prior `:caminho`
2027 // arm protects.
2028 //
2029 // Beyond the render-determinism / host-layout-leak vectors,
2030 // `$` at any position in a value flowing verbatim into a
2031 // shell-spawned subprocess is the canonical CWE-78 shell-
2032 // command-injection surface every peer single-token-shaped
2033 // typed slot already closes. A `:caminho "../foo$(whoami)/bar"`
2034 // that rides into a future `feira tofu` shell-out as `cd
2035 // '../foo$(whoami)/bar'` gets substituted by the shell at
2036 // subprocess-argument-expansion time even inside single quotes
2037 // in fewer positions than one might expect (the substitution
2038 // fires only outside single-quoting per POSIX §2.2.2, but
2039 // eval-style wrappers and `sh -c` layers that route the value
2040 // through re-parsing round-trip the substitution — the same
2041 // vector the c370458 backtick arm closes at the sibling
2042 // command-substitution-legacy-form surface). Every future
2043 // `feira` verb that shells out with a `caminho`-formatted
2044 // subprocess argument silently inherits this substitution
2045 // vector unless the typed slot's accepted set structurally
2046 // excludes the byte.
2047 //
2048 // Frontier inspiration: OTP's `gen_server` return-value grammar
2049 // rejects mid-tuple shell-metachar bytes by construction —
2050 // `{noreply, State}` never carries a raw `$` because the
2051 // Erlang term type system has no notion of "string that gets
2052 // shelled out"; caixa's typed slots inherit the same
2053 // structural discipline (types-are-theorems, the compounding
2054 // mandate's leverage-point-1) by refusing values that would
2055 // silently reinterpret at any downstream layer. Peer with
2056 // Unison's content-addressed code (no ambient environment —
2057 // every reference is a hash, no `$VAR` substitution possible)
2058 // and Pony's capabilities (a path capability that carries a
2059 // `$` would be ill-typed at the reference layer).
2060 //
2061 // The arm fires AFTER the URL-percent-encoding-escape arm (the
2062 // e3558fa `%` arm) because a value carrying both `%` and `$`
2063 // (`"../foo%20$HOME/bar"` — the canonical "I pasted a percent-
2064 // encoded space next to a `$HOME` template") surfaces the
2065 // narrower URL-encoding diagnostic first — the paste-from-
2066 // browser-address-bar shape is the load-bearing self-locating
2067 // edit on every probe-as-both value; same cascade discipline
2068 // every prior `:caminho` arm establishes (a323db8 % before
2069 // this arm, this arm before trailing-`/`). The arm fires
2070 // BEFORE the trailing-`/` arm because the embedded shell-
2071 // variable-expansion byte is the more semantic-locating axis
2072 // on probe-as-both values (`"../foo$HOME/bar/"` ends in `/`
2073 // but the load-bearing diagnostic is the embedded `$` — the
2074 // trailing `/` is the secondary observation, and an author
2075 // who substitutes the `$HOME` template with a literal value is
2076 // likely to also tab-strip the trailing separator).
2077 for &b in caminho.as_bytes() {
2078 if b == b'$' {
2079 return Err(DepError::fonte_caminho_shell_variable_expansion(
2080 nome, caminho, b,
2081 ));
2082 }
2083 }
2084 // Reproducibility gate's shell-history-expansion / RFC-3986-sub-delims
2085 // arm. The immediate-predecessor `$` embedded arm closes the shell-
2086 // variable-expansion / command-substitution byte; `!` (`0x21`) is the
2087 // orthogonal POSIX shell-history-expansion sentinel every interactive
2088 // shell with history enabled (bash / ksh / zsh's `bashcompat` /
2089 // csh / tcsh) lexes as the history-expansion prefix: `!command`
2090 // re-runs the most recent history entry beginning with `command`,
2091 // `!!` re-runs the prior command verbatim, `!$` substitutes the
2092 // last word of the prior command, `!:N` substitutes the Nth word,
2093 // `^old^new` rewrites the prior command's `old` to `new` (the
2094 // canonical set of `set -o histexpand` operators bash's default
2095 // interactive session enables). Beyond the shell-history layer,
2096 // RFC 3986 §2.2 lists `!` in the `sub-delims` set (the URL grammar
2097 // admits the byte inside a path segment, but every WHATWG-conformant
2098 // special-scheme URL parser percent-encodes it inside a query
2099 // component via the 'special-query percent-encode set' the peer
2100 // `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte
2101 // is also the C / C++ / Rust / JavaScript / Python bang-operator
2102 // (logical-negation prefix — the paste-from-source-code idiom where
2103 // an author copies `!path.exists()` out of a Rust snippet and the
2104 // trailing punctuation crosses the string-literal boundary); the
2105 // canonical English-typography emphasis / exclamation mark (the
2106 // paste-from-prose enthusiasm-form idiom where an author writes
2107 // `:caminho "../caixa-teia!"` expecting the substrate to coerce it
2108 // to a kebab-case slug); and the Nix flake-ref import-attribute
2109 // `import ./foo.nix { … }` sibling operator surface.
2110 //
2111 // POSIX `std::path::Path` treats `!` as a literal path-component
2112 // byte, so a `:caminho "../caixa-teia!sudo"` (the canonical paste-
2113 // from-shell-history footgun where the author copies a `cd
2114 // ../caixa-teia && !sudo make install` one-liner from a quick-
2115 // start README and the trailing `!sudo` rides in verbatim as a
2116 // history-expansion reference), a `:caminho "../foo!!/bar"` (the
2117 // `!!` repeat-prior-command paste idiom), a `:caminho
2118 // "../caixa-teia!"` (the English-typography enthusiasm-form
2119 // paste-from-prose footgun), or a `:caminho "../foo!$"` (the
2120 // last-word-substitution shape) silently pass every prior arm
2121 // because `Path::is_absolute` returns false on `..`, `!` is neither
2122 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
2123 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
2124 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%` nor `$`,
2125 // and the value's last byte isn't `/`. The resolver folds the value
2126 // through `Path::new(caminho).join(<file>)` looking for a literal
2127 // `./../caixa-teia!sudo` subdirectory and fails at resolve time
2128 // with a non-self-locating `No such file or directory` error far
2129 // from the source caixa.lisp — while every downstream interactive
2130 // shell with `set -o histexpand` reinterprets the byte as the
2131 // history-expansion prefix, and the failure mode forks per
2132 // consumer: a `feira tofu` shell-out to a `cd '{caminho}'` command
2133 // line executed under `bash -i` (the operator-notebook interactive
2134 // shell) substitutes the `!sudo` reference to the most recent
2135 // history entry starting with `sudo`, silently invoking whatever
2136 // privileged command that entry named.
2137 //
2138 // The lacre pipeline embeds the value verbatim in its per-dep
2139 // content-address (`conteudo: format!("path:{caminho}")`,
2140 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2141 // BLAKE3 closure and rides into every shell-spawned subprocess
2142 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2143 // a future operator-side `nix flake check` spawn) as the
2144 // canonical shell-history-expansion / RFC-3986-sub-delims surface
2145 // every peer single-token-shaped typed slot already closes. The
2146 // peer `:fonte :repo` axis closes the byte under the same shell-
2147 // history-expansion / RFC-3986-sub-delims banner (7d53c68 `!` on
2148 // `is_git_repo_url`); the `:caminho` axis was the last typed
2149 // path-string surface still admitting the byte. This arm closes
2150 // the gap so the substrate-wide "no shell-composition
2151 // metacharacter / history-expansion sentinel anywhere in a typed
2152 // string slot that flows verbatim into a shell-spawned subprocess"
2153 // invariant extends from shell-variable-expansion (`$`) to shell-
2154 // history-expansion (`!`) on the `:caminho` axis. Together with
2155 // the peer c370458 backtick command-substitution-legacy-form arm
2156 // and the b9d187c-`$`-embedded-variable-expansion arm on the
2157 // sibling `:repo` axis, the typed `:caminho` accepted set now
2158 // structurally excludes every byte the POSIX shell §2.6 Word
2159 // Expansions section, §2.3 Token Recognition step 6, and every
2160 // history-expansion / brace-expansion / pathname-expansion /
2161 // parameter-expansion / command-substitution / arithmetic-
2162 // expansion operator lexes as a first-class parser byte.
2163 //
2164 // Frontier inspiration: Unison's content-addressed code (no
2165 // ambient environment — every reference is a hash, no `!<num>`
2166 // history-index substitution possible; the caixa substrate's
2167 // lacre discipline arrives at the same guarantee by refusing
2168 // bytes at manifest-parse time that would reinterpret against
2169 // ambient shell history state); Pony's capabilities (a path
2170 // capability that carries a `!` would be ill-typed at the
2171 // reference layer).
2172 //
2173 // The arm fires AFTER the shell-variable-expansion arm because a
2174 // value carrying both `$` and `!` (`"../foo$HOME/bar!sudo"` — the
2175 // canonical "I pasted a `$HOME`-templated path adjacent to a
2176 // trailing `!sudo` history-expansion") surfaces the narrower
2177 // shell-variable-expansion diagnostic first — the paste-from-CI-
2178 // manifest-with-`$VAR`-template shape is the load-bearing self-
2179 // locating edit on every probe-as-both value; same cascade
2180 // discipline every prior `:caminho` arm establishes. The arm
2181 // fires BEFORE the trailing-`/` arm because the embedded shell-
2182 // history-expansion byte is the more semantic-locating axis on
2183 // probe-as-both values (`"../foo!sudo/"` ends in `/` but the
2184 // load-bearing diagnostic is the embedded `!` — the trailing `/`
2185 // is the secondary observation, and an author who removes the
2186 // `!sudo` history reference is likely to also tab-strip the
2187 // trailing separator).
2188 for &b in caminho.as_bytes() {
2189 if b == b'!' {
2190 return Err(DepError::fonte_caminho_shell_history_expansion(
2191 nome, caminho, b,
2192 ));
2193 }
2194 }
2195 // Reproducibility gate's shell-history-substitution / RFC-3986-unwise
2196 // / regex-anchor arm. The immediate-predecessor `!` arm closes the
2197 // POSIX `!command` / `!!` / `!$` history-expansion prefix; `^`
2198 // (`0x5E`) is the paired-operator half of the same bash-reference
2199 // §9.3 histexpand feature — the `^old^new^` "quick substitution"
2200 // form (POSIX bash rewrites the prior command's `old` string to
2201 // `new` and re-executes it, the canonical typo-correction one-
2202 // liner idiom `git clone <bad-url>` → `^bad^good` that pastes the
2203 // trailing substitution fragment verbatim into a `:caminho` value
2204 // when the author trims only the leading `git clone` prefix). The
2205 // peer `:fonte :repo` axis closes the byte under the same
2206 // shell-history-substitution / RFC-3986-unwise banner (49e142f `^`
2207 // on `is_git_repo_url`); the `:caminho` axis was the last typed
2208 // path-string surface still admitting the byte after 6a04767
2209 // landed the `!` arm.
2210 //
2211 // Beyond bash history-substitution, `^` carries five distinct
2212 // downstream-reinterpretation surfaces the typed slot's accepted
2213 // set must structurally exclude:
2214 //
2215 // 1. **RFC 3986 §2 'unwise' set** — the four-byte cross-transport
2216 // layer set (`{`, `}`, `|`, `\`) plus `^` every URL parser is
2217 // required to percent-encode-or-refuse at the wire boundary.
2218 // The WHATWG URL spec's 'fragment percent-encode set' maps
2219 // `^` → `%5E` at the query / fragment component transition;
2220 // libcurl silently percent-encodes the byte on the wire, so a
2221 // `:caminho "../foo^bar"` value the resolver's `Path::join`
2222 // sees as a literal `./../foo^bar` subdirectory diverges from
2223 // the byte-transformed `%5E` shape any downstream `feira tofu`
2224 // curl-invocation or artifact-registry-fetch would emit — the
2225 // canonical wire-boundary divergence vector the peer
2226 // `{`, `}`, `|`, `\` `:caminho` arms already close (
2227 // `FonteCaminhoShellBraceExpansion` at 598b770,
2228 // `FonteCaminhoShellPipe` at the pipe arm,
2229 // `FonteCaminhoBackslash` at the backslash arm).
2230 // 2. **Regex character-class negation prefix `[^abc]`** — the
2231 // canonical paste-from-doc-regex-pipeline footgun where an
2232 // author copies a `grep '[^abc]'` idiom from a docs quick-
2233 // listing and the character-class negation byte rides in
2234 // verbatim.
2235 // 3. **Bitwise XOR operator** in C / C++ / Rust / Python /
2236 // JavaScript / Nix / Go — the paste-from-source-code idiom
2237 // where an author copies an `x ^ y`-shaped expression out of
2238 // a source snippet and the operator crosses the string-
2239 // literal boundary.
2240 // 4. **Windows `cmd.exe` escape metacharacter** — the byte
2241 // escapes the next character in a `cmd.exe` batch context (a
2242 // peer of the backslash arm's Windows-separator-leak vector).
2243 // A `:caminho "..^&whoami"` cross-platform paste-from-batch-
2244 // file footgun reinterprets at every `cmd.exe`-spawned
2245 // subprocess (the resolver's future Windows-runner shell-out,
2246 // the operator's WinRM path, a future PowerShell-embedded
2247 // invocation).
2248 // 5. **LaTeX / Markdown / BibTeX superscript operator** — the
2249 // paste-from-typeset-doc footgun where a mathematical
2250 // superscript notation (`x^2` / `M^T`) leaks from prose.
2251 //
2252 // POSIX `std::path::Path` treats `^` as a literal path-component
2253 // byte, so `:caminho "../foo^bar/baz"` (embedded quick-
2254 // substitution), `:caminho "../foo^"` (trailing history-
2255 // substitution-open shape), `:caminho "../[^a-z]/foo"` (regex-
2256 // negation-prefix paste from a grep pipeline; note the `[` / `]`
2257 // arm at 986963b fires first on this shape), or `:caminho
2258 // "../x^y"` (XOR-expression paste-from-source) all silently pass
2259 // every prior arm (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` /
2260 // backtick / `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'`
2261 // / `"` / `#` / `%` / `$` / `!`) and route through
2262 // `Path::new(caminho).join(<file>)` looking for a literal
2263 // `./{caminho}` subdirectory that fails at resolve time with a
2264 // non-self-locating `No such file or directory` error far from
2265 // the source caixa.lisp — while every downstream shell / curl /
2266 // regex / `cmd.exe` layer reinterprets the byte to its own
2267 // semantic.
2268 //
2269 // The lacre pipeline embeds the value verbatim in its per-dep
2270 // content-address (`conteudo: format!("path:{caminho}")`,
2271 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2272 // BLAKE3 closure and rides into every shell-spawned subprocess
2273 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2274 // a future operator-side `nix flake check` spawn) as the
2275 // canonical shell-history-substitution / RFC-3986-unwise /
2276 // regex-negation surface every peer single-token-shaped typed
2277 // slot already closes. This arm together with the immediate-
2278 // predecessor `!` arm (6a04767) closes the full `set -o
2279 // histexpand` operator surface on the `:caminho` axis — the
2280 // `!command` / `!!` / `!$` prefix form via `!`, the `^old^new^`
2281 // quick-substitution form via `^` — so the substrate-wide "no
2282 // shell-history operator anywhere in a typed string slot that
2283 // flows verbatim into a shell-spawned subprocess" invariant
2284 // extends from the `!` prefix half to the `^` quick-substitution
2285 // half. Every peer bash-history operator now fails at manifest-
2286 // parse time with a self-locating diagnostic naming the offending
2287 // caixa.lisp rather than at resolve-time as a `Path::join`-
2288 // derived `No such file or directory` (harmless but non-self-
2289 // locating) or worse riding into a downstream `bash -i` context
2290 // that reinterprets the byte-pair against ambient history state.
2291 //
2292 // Frontier inspiration: bash reference §9.3 HISTORY EXPANSION
2293 // "Quick substitution. Repeat the previous command, replacing
2294 // string1 with string2." + RFC 3986 §2 'unwise' set
2295 // ("characters that gateways and other transport agents are
2296 // known to sometimes modify") + Pony's capabilities (a path
2297 // capability that carries a `^` would be ill-typed at the
2298 // reference layer, matching the same structural discipline the
2299 // sibling `!` history-expansion arm inherits from Unison's
2300 // content-addressed no-ambient-history discipline).
2301 //
2302 // The arm fires AFTER the shell-history-expansion `!` arm because
2303 // a value carrying both `!` and `^` (`"../foo!sudo^bad^good"` —
2304 // the canonical "I pasted a `!sudo` history-reference next to a
2305 // `^bad^good` quick-substitution") surfaces the narrower prefix-
2306 // form `!` diagnostic first — the `!` form is the load-bearing
2307 // self-locating edit on every probe-as-both value (an author who
2308 // removes the `!sudo` reference is likely to also strip the
2309 // paired `^` substitution fragment); same cascade discipline
2310 // every prior `:caminho` arm establishes. The arm fires BEFORE
2311 // the trailing-`/` arm because the embedded shell-history-
2312 // substitution byte is the more semantic-locating axis on
2313 // probe-as-both values (`"../foo^bar/"` ends in `/` but the
2314 // load-bearing diagnostic is the embedded `^` — the trailing `/`
2315 // is the secondary observation, and an author who removes the
2316 // `^bar` substitution fragment is likely to also tab-strip the
2317 // trailing separator).
2318 for &b in caminho.as_bytes() {
2319 if b == b'^' {
2320 return Err(DepError::fonte_caminho_shell_history_substitution(
2321 nome, caminho, b,
2322 ));
2323 }
2324 }
2325 // Reproducibility gate's trailing-`/` arm. The b94fd83 absolute arm
2326 // closes the leading-`/` host-layout-leak; the embedded-control-byte
2327 // arm closes any byte-in-the-`0x00..=0x1F` / `0x7F` range; the
2328 // backslash arm closes the cross-host-OS-separator vector. The
2329 // trailing-`/` is the orthogonal shell-tab-completion-on-a-directory
2330 // footgun — `Path::join("../caixa-teia")` and
2331 // `Path::join("../caixa-teia/")` resolve to the same directory
2332 // (POSIX path-component-walk treats trailing `/` as a no-op for
2333 // directory targets, which `:caminho` always names — the sibling-
2334 // workspace dep root is structurally a directory). The lacre
2335 // pipeline embeds the value verbatim in its per-dep content-address
2336 // (`conteudo: format!("path:{caminho}")`,
2337 // caixa-resolver/src/resolve.rs:189), so byte-identical caixa
2338 // semantic-meaning yields two distinct BLAKE3 closures depending on
2339 // whether the author shell-tab-completed the path (every interactive
2340 // shell appends `/` on tab-completing a directory, idiomatic in
2341 // bash / zsh / fish / nushell), pasted from `pwd` (which on most
2342 // shells emits without trailing `/`, but `realpath -e -m` on a
2343 // directory with trailing `/` preserves it), or copied a Cargo
2344 // `path = "../caixa-teia/"` entry from cross-substrate documentation
2345 // (Cargo accepts both shapes and folds them the same way). Two
2346 // workstations whose authors differ only in tab-completion habits
2347 // emit byte-divergent lacres for the byte-identical-semantic caixa,
2348 // and the substrate's "the lacre is the build's identity" contract
2349 // (CAIXA-SDLC §III.2) silently breaks far from the source caixa.lisp.
2350 //
2351 // Same THEORY.md §V.2 render-determinism axis every prior `:caminho`
2352 // arm protects, here against the trailing-separator divergence
2353 // vector: every typed slot's accepted set excludes byte-divergent
2354 // values that round-trip to the same downstream semantic. The peer
2355 // path-shaped axes already reject trailing separators on the same
2356 // contract: [`crate::render::is_gateway_api_http_path`] gates
2357 // `:entrada :paths` against any non-canonical normalization, and
2358 // [`crate::render::is_sandboxed_relative_path`] gates the M2 typed
2359 // path-slots (`:behavior :on-*`, `:upgrade-from :state-change
2360 // :script`, `:bibliotecas`, `:exe`, `:servicos`) against shapes
2361 // whose canonical form would re-introduce determinism divergence.
2362 //
2363 // The arm fires last in the cascade because every prior arm carries
2364 // a more self-locating diagnostic on values that probe as both
2365 // (e.g. `:caminho "../foo/\0/"` ends in `/` but the load-bearing
2366 // diagnostic is the NUL byte's POSIX-syscall-rejection — the
2367 // control-char arm wins; `:caminho "/etc/passwd/"` ends in `/` but
2368 // the load-bearing diagnostic is the absolute host-layout-leak —
2369 // the absolute arm wins; `:caminho "..\caixa-teia/"` ends in `/`
2370 // but the load-bearing diagnostic is the Windows-separator cross-
2371 // OS divergence — the backslash arm wins). The arm covers every
2372 // shape where the last byte is `/` regardless of length, including
2373 // the degenerate single-`/` (which the absolute arm catches first)
2374 // and the consecutive-`//` (where every prior arm passes on the
2375 // bytes other than the trailing `/`).
2376 if caminho.as_bytes().last() == Some(&b'/') {
2377 return Err(DepError::fonte_caminho_trailing_slash(nome, caminho));
2378 }
2379 Ok(())
2380 }
2381}
2382
2383impl Dep {
2384 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:nome` scalar
2385 /// accessor every consumer of the dep-graph identity axis keys off —
2386 /// returns the author-declared `:nome` byte-string verbatim as a
2387 /// `&str`, borrowed from the typed slot's own [`String`] storage.
2388 ///
2389 /// The `:deps :nome` / `:deps-dev :nome` slot carries the DNS-1123
2390 /// label that names the target caixa (validated by [`Self::validate`]
2391 /// through the shared [`crate::render::is_dns_1123_label`] predicate,
2392 /// same accept-set the peer caixa-identifier axes carry — top-level
2393 /// [`crate::Caixa::nome`], per-`:membros` [`crate::Membro::nome`],
2394 /// per-`:children` [`crate::supervisor::ChildSpec::nome`]). Every
2395 /// downstream consumer that fans on the dep's name-identity keys off
2396 /// this scalar: the [`crate::Caixa::validate_deps`] per-list
2397 /// [`crate::render::insert_first_seen`] dedup key + the paired
2398 /// [`DepError::DuplicateNome`] carrier the walk raises on collision,
2399 /// the cross-list [`validate_no_self_dep`] parent-name equality gate
2400 /// on both `:deps` and `:deps-dev` traversals, the `caixa-resolver`
2401 /// pipeline's `HashSet<String>` seen-set the closure walker gates
2402 /// requeueing off (`caixa-resolver/src/resolve.rs:55`), the resolver's
2403 /// per-transitive-target requeue path (`resolve.rs:63,66`), the
2404 /// [`crate::DepSource::default_github`]-shaped resolver-side shorthand
2405 /// fill-in that folds `:nome` into the fetched-git-URL (`resolve.rs:147`),
2406 /// every `caixa-resolver` `ResolveError::MissingPath` /
2407 /// `ResolveError::MissingPin` carrier that names the offending dep
2408 /// (`resolve.rs:177,206`), each resolved
2409 /// `caixa-lacre::LacreEntry` `nome:` field the closure hash keys off
2410 /// (`resolve.rs:108,113`), and the peer `feira lock` stub-resolver's
2411 /// `LacreEntry` emitter (`caixa-feira/src/cmd/lock.rs:59,61,64`).
2412 ///
2413 /// Prior to this lift the `.nome` byte-string was read inline at every
2414 /// production site — the [`crate::Caixa::validate_deps`] paired
2415 /// `dep.nome.as_str()` / `dep.nome.clone()` accesses on both `:deps`
2416 /// and `:deps-dev` traversals, the [`validate_no_self_dep`] pair of
2417 /// parent-equality checks, and every caixa-resolver / caixa-feira
2418 /// site enumerated above — open-coded field-accesses that expressed
2419 /// no compile-time link back to the typed slot. A future extension of
2420 /// the `:deps :nome` axis to a richer author surface (a per-scope
2421 /// alias table the resolver folds through the `~/.config/caixa/config.yaml`
2422 /// entry the [`crate::dep::Dep`] docstring already acknowledges, a
2423 /// namespace-qualified rewrite the future M4 lacre-federation layer
2424 /// applies per-cluster, a promotion of the plain [`String`] byte-string
2425 /// to a richer scoped-identifier newtype once cross-registry federation
2426 /// lands) would have had to be threaded through every open-coded copy
2427 /// in lockstep or two consumers would silently disagree on which caixa
2428 /// a given dep resolves to — the [`crate::Caixa::validate_deps`] dedup
2429 /// set treating the name as `"caixa-teia"` while the caixa-resolver
2430 /// closure walker treated it as `"tenant-a/caixa-teia"` would silently
2431 /// split the [`DepError::DuplicateNome`] refusal from the resolver's
2432 /// requeue-suppression seen-set, one build-time diagnostic
2433 /// disagreeing with the run-time closure the substrate's lacre
2434 /// pipeline actually materializes. Lifting the resolution rule to a
2435 /// typed method on the substrate primitive means every downstream
2436 /// consumer of the caixa's per-`:deps` identity surface reaches for
2437 /// exactly one typed dispatch — the resolver's accept-set migrates as
2438 /// a unit on any future axis addition.
2439 ///
2440 /// First accessor on the outer `Dep` type — opens the outer-`Dep`
2441 /// `&str`-return required-scalar projection pattern the sibling
2442 /// per-`Dep` `:versao` future lift folds on. Peer of the sibling
2443 /// per-`:membros` [`crate::Membro::nome`] (4a32abf) /
2444 /// per-`:children` [`crate::supervisor::ChildSpec::nome`] (dfb4a81)
2445 /// / top-level [`crate::Caixa::nome`] (e6b7d97) caixa-identity scalar
2446 /// accessors — same "one typed dispatch on the substrate primitive,
2447 /// thin projections at each consumer" discipline extended onto the
2448 /// third named-caixa-referencing axis (`:deps` / `:deps-dev`), the
2449 /// remaining unlifted caixa-name-referencing accessor family in the
2450 /// substrate. Named `nome()` to match the tatara-lisp author-surface
2451 /// term the field's docstring already reaches for ("Caixa name — must
2452 /// match the target caixa's `:nome`") and the peer caixa-identity
2453 /// accessor family the substrate already carries.
2454 #[must_use]
2455 pub const fn nome(&self) -> &str {
2456 self.nome.as_str()
2457 }
2458
2459 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:versao`
2460 /// Cargo-shaped semver-requirement scalar accessor every consumer of
2461 /// the dep-graph version-pin axis keys off — returns the author-
2462 /// declared `:versao` requirement byte-string verbatim as a `&str`,
2463 /// borrowed from the typed slot's own [`String`] storage.
2464 ///
2465 /// The `:deps :versao` / `:deps-dev :versao` slot carries the
2466 /// Cargo-shaped semver requirement string (`"^0.1"`, `"~0.1.2"`,
2467 /// `"0.1.0"`, `"*"`) the shared [`crate::version::parse_requirement`]
2468 /// entry-point consumes — same accept-set the peer requirement-
2469 /// carrying axes carry (per-`:membros`
2470 /// [`crate::Membro::versao_requirement`], per-`:children`
2471 /// [`crate::supervisor::ChildSpec::versao_requirement`]), validated
2472 /// through the shared
2473 /// [`crate::render::require_valid_versao_requirement`] cascade in
2474 /// [`Self::validate`]. Every downstream consumer that fans on the
2475 /// dep's version-pin keys off this scalar: the [`Self::validate`]
2476 /// `require_valid_versao_requirement` gate + the paired
2477 /// [`DepError::VersaoInvalid`] carrier the cascade raises on
2478 /// requirement-shape rejection, the `feira lock` stub-resolver's
2479 /// `format!("{}@{}", dep.nome(), dep.versao_requirement())`
2480 /// `conteudo` hash-input interpolation and the paired
2481 /// `LacreEntry.versao:` `String`-carry fill (`caixa-feira/src/cmd/lock.rs`),
2482 /// and the peer `feira lock` end-to-end fixture in `caixa-feira/tests/feira_e2e.rs`.
2483 ///
2484 /// Prior to this lift the `.versao` byte-string was read inline at
2485 /// every production site — the [`Self::validate`] paired
2486 /// `&self.versao` requirement-gate reference and `self.versao.clone()`
2487 /// error-body carrier, the `caixa-feira/src/cmd/lock.rs` paired
2488 /// `format!("{}@{}", dep.nome(), dep.versao)` `conteudo` interpolation
2489 /// and `versao: dep.versao.clone()` `LacreEntry` fill, and the
2490 /// `caixa-feira/tests/feira_e2e.rs` end-to-end fixture's pair of the
2491 /// same shapes — open-coded field-accesses that expressed no
2492 /// compile-time link back to the typed slot. A future extension of
2493 /// the `:deps :versao` axis to a richer author surface (a per-scope
2494 /// version-lock overlay the resolver folds through the
2495 /// `~/.config/caixa/config.yaml` entry the [`crate::dep::Dep`]
2496 /// docstring already acknowledges, a per-cluster canary-version
2497 /// overlay per MESH-COMPOSITION §III.2, a promotion of the plain
2498 /// [`String`] requirement to a richer parsed-`VersionReq` newtype
2499 /// once cross-registry federation lands) would have had to be
2500 /// threaded through every open-coded copy in lockstep or two
2501 /// consumers would silently disagree on which release constraint a
2502 /// given dep resolves to — the [`Self::validate`] requirement-gate
2503 /// call reading `"^0.1"` while the `feira lock` stub-resolver's
2504 /// `conteudo` hash-input read `"tenant-a-pin/^0.1"` would silently
2505 /// split the [`DepError::VersaoInvalid`] refusal from the lacre's
2506 /// content-addressed hash the substrate's fetch pipeline actually
2507 /// materializes, one build-time diagnostic disagreeing with the
2508 /// run-time closure. Lifting the resolution rule to a typed method
2509 /// on the substrate primitive means every downstream consumer of
2510 /// the caixa's per-`:deps` version-pin surface reaches for exactly
2511 /// one typed dispatch — the resolver's accept-set migrates as a
2512 /// unit on any future axis addition.
2513 ///
2514 /// Second accessor on the outer `Dep` type — folds on the outer-
2515 /// `Dep` `&str`-return required-scalar projection pattern the
2516 /// sibling per-`Dep` [`Self::nome`] (eba2cde) accessor opened. Peer
2517 /// of the per-`:membros` [`crate::Membro::versao_requirement`]
2518 /// (a40b0e3) / per-`:children`
2519 /// [`crate::supervisor::ChildSpec::versao_requirement`] (7844f4e
2520 /// family) member/child version-pin accessors — the three
2521 /// requirement-carrying axes (`Dep::versao_requirement` on the
2522 /// per-caixa dep-graph edge, `Membro::versao_requirement` on the M3
2523 /// Aplicacao side, `ChildSpec::versao_requirement` on the M2
2524 /// Supervisor side) now share one accessor discipline for the
2525 /// shared substrate concept "another caixa referenced by a
2526 /// Cargo-shaped semver requirement". The pair
2527 /// `(nome(), versao_requirement())` jointly projects the
2528 /// `(nome, versao)` field pair every dep-graph consumer that fans
2529 /// on per-dep identity + version pin keys off. Named
2530 /// `versao_requirement()` rather than `versao()` because the field's
2531 /// storage-side `.versao` label is already the author-surface term
2532 /// (`:versao`); the accessor's name carries the semantic role — the
2533 /// semver *requirement* string the shared
2534 /// [`crate::version::parse_requirement`] entry-point consumes — so a
2535 /// raw field access and a typed dispatch read differently at every
2536 /// consumer site. Matches the peer
2537 /// [`crate::Membro::versao_requirement`] /
2538 /// [`crate::supervisor::ChildSpec::versao_requirement`] naming
2539 /// discipline verbatim.
2540 #[must_use]
2541 pub const fn versao_requirement(&self) -> &str {
2542 self.versao.as_str()
2543 }
2544
2545 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:fonte`
2546 /// Zig-store-model per-dep source-tuple optional-composite-reference
2547 /// accessor every consumer of the dep-graph fetch-source axis keys
2548 /// off — returns the author-declared `:fonte` typed [`DepSource`]
2549 /// verbatim as an `Option<&DepSource>` borrowed from the typed slot's
2550 /// own `Option<DepSource>` storage, with `None` naming the "author
2551 /// omitted `:fonte`" shorthand every resolver-side default-fill
2552 /// (`caixa-feira/src/cmd/lock.rs`'s stub, `caixa-resolver/src/resolve.rs`'s
2553 /// canonical fetcher, per the [`DepSource::default_github`] fallback
2554 /// the [`Dep::fonte`] field docstring already documents) treats as
2555 /// the "resolve through the configured default host / org
2556 /// (`github:<default-org>/<nome>`)" partition.
2557 ///
2558 /// The `:deps :fonte` / `:deps-dev :fonte` slot carries the two-
2559 /// arm typed [`DepSource`] the `Zig-style git-only store model` the
2560 /// enclosing [`Dep`] docstring names — `DepSource::Git { repo, tag,
2561 /// rev, branch }` for the git-clone arm every published caixa
2562 /// resolves through, `DepSource::Path { caminho }` for the dev-only
2563 /// local-filesystem arm every unpublishable in-tree checkout
2564 /// resolves through. Every downstream consumer that fans on the
2565 /// dep's fetch-source keys off this accessor: [`Self::validate`]'s
2566 /// per-`:fonte` [`DepSource::validate`] delegation (which raises
2567 /// the empty-`:repo` / missing-pin / multiple-pin / empty-`:caminho`
2568 /// diagnostics through the [`DepError::Fonte*`] carrier family
2569 /// naming the offending `Dep::nome`), the caixa-crd conversion
2570 /// crate's `dep_into_ref` two-arm projection into the `CaixaSource`
2571 /// `{repo, git_ref}` pair the K8s-CR side consumes
2572 /// (`caixa-crd/src/conversion.rs`), and — through the paired
2573 /// resolver-side default-fill's `Option::unwrap_or_else` — every
2574 /// `caixa-feira` / `caixa-resolver` fetch site that requires a
2575 /// concrete `DepSource` at run time.
2576 ///
2577 /// Prior to this lift the `.fonte` typed slot was read inline at
2578 /// every production site — the [`Self::validate`]
2579 /// `if let Some(ref fonte) = self.fonte` bracket the per-`:fonte`
2580 /// gate delegates through, the caixa-crd `dep_into_ref`
2581 /// `d.fonte.as_ref().and_then(...)` two-arm `CaixaSource` projector,
2582 /// the resolver-side `caixa-feira/src/cmd/lock.rs` / `caixa-resolver/src/resolve.rs`
2583 /// `dep.fonte.clone().unwrap_or_else(...)` default-fill pair — open-
2584 /// coded field-accesses that expressed no compile-time link back to
2585 /// the typed slot. A future extension of the `:deps :fonte` axis
2586 /// to a richer author surface (a per-scope source-override table
2587 /// the resolver folds through the `~/.config/caixa/config.yaml`
2588 /// entry the [`Dep`] docstring already acknowledges, a per-org
2589 /// mirror-fallback list the future M4 lacre-federation resolver
2590 /// consults ahead of the `default_github` fallback, a promotion of
2591 /// the plain `Option<DepSource>` to a richer
2592 /// `{primary, mirrors, integrity}` triple once cross-registry
2593 /// federation lands, a per-dep `sri:sha256-…` integrity slot the
2594 /// M4 lacre gate binds against ahead of the git-fetch) would have
2595 /// had to be threaded through every open-coded copy in lockstep or
2596 /// two consumers would silently disagree on which fetch source a
2597 /// given dep resolves to — the [`Self::validate`] per-`:fonte`
2598 /// gate reading the author-declared source while the caixa-crd
2599 /// projector read a per-scope-override-resolved source would
2600 /// silently split the build-time refusal from the CR the
2601 /// substrate's admission pipeline actually materializes, one
2602 /// build-time diagnostic disagreeing with the run-time closure.
2603 /// Lifting the resolution rule to a typed method on the substrate
2604 /// primitive means every downstream consumer of the caixa's per-
2605 /// `:deps` fetch-source surface reaches for exactly one typed
2606 /// dispatch — the resolver's accept-set migrates as a unit on any
2607 /// future axis addition.
2608 ///
2609 /// First outer-`Dep` `Option<&Composite>`-return composite-reference
2610 /// accessor — opens the outer-`Dep` `Option<&Composite>` composite-
2611 /// reference projection pattern the sibling per-`Dep` `:opcional`
2612 /// (`Option<Copy>` — the plain-bool axis) / `:caracteristicas`
2613 /// (`&[String]` — the feature-flag list) future outer scalar / slice
2614 /// lifts fold on. Peer of the outer-top-level [`crate::Caixa`]
2615 /// `Option<&Composite>` composite-reference sub-family the
2616 /// [`crate::Caixa::limits`] (b2bd9d7) / [`crate::Caixa::behavior`]
2617 /// (35d8b52) / [`crate::Caixa::politicas`] (5d23d29) /
2618 /// [`crate::Caixa::placement`] (4fb8074) / [`crate::Caixa::entrada`]
2619 /// (e4128e4) accessors already close on the outer [`crate::Caixa`]
2620 /// altitude, and of the outer M3 mesh-slot [`crate::AplicacaoSpec`]
2621 /// altitude the sibling [`crate::AplicacaoSpec::entrada`] (d32111c)
2622 /// accessor already carries — extends that "one typed dispatch on
2623 /// the substrate primitive, thin projections at each consumer"
2624 /// discipline onto the third outer typed-slot altitude that carries
2625 /// an `Option<Composite>` axis (`Dep`, the outer per-dep-list-entry
2626 /// slot). Returns `Option<&DepSource>` (not the owning composite by
2627 /// copy or clone) because every downstream consumer of the fonte
2628 /// composite treats it as a read-only per-arm dispatch source — the
2629 /// reference-view is the narrowest borrow that supports every
2630 /// present + roadmapped consumer (per-arm match projection at the
2631 /// caixa-crd `CaixaSource` two-arm emitter, presence-probe early
2632 /// return on the "author-omitted `:fonte` ⇒ resolver-side
2633 /// `default_github` fill applies" partition every resolver
2634 /// consults, `.cloned()`-on-demand for the two resolver-side
2635 /// default-fill call sites that require an owned `DepSource` for
2636 /// `Option::unwrap_or_else`) without cloning the composite through
2637 /// every consumer's fast path. The `Option` half of the return-type
2638 /// preserves the load-bearing "author-omitted `:fonte` ⇒ resolver-
2639 /// side default applies" partition (not a default composite the
2640 /// downstream must reject on emptiness) — the accessor projects the
2641 /// raw `Option<DepSource>` slot's presence bit through the
2642 /// reference-return unchanged. Named `fonte()` to match the storage
2643 /// field's name verbatim and the tatara-lisp author-surface term
2644 /// (`:fonte`) the field's own docstring already carries.
2645 ///
2646 /// Declared `pub const fn` — the body projects through
2647 /// `Option::<DepSource>::as_ref`, const-stable since Rust 1.83 and
2648 /// well within the workspace MSRV, so every downstream `const`-
2649 /// context consumer of the per-`Dep` `:fonte` composite-reference
2650 /// accessor reaches through the same typed dispatch on the
2651 /// substrate primitive at const-eval time as at runtime. The
2652 /// paired [`dep_outer_accessor_family_is_const_fn`][pin] pin
2653 /// (a `const fn <name>_via_const_fn(d: &Dep) -> …` wrapper family
2654 /// that forwards through each lifted accessor) locks the posture
2655 /// load-bearing at caixa-core build time — any future accidental
2656 /// downgrade to non-`const` fails the wrapper with E0015
2657 /// (`cannot call non-const method`), strictly stronger than a
2658 /// runtime `assert!` and side-stepping the destructor-in-const
2659 /// restriction the `Dep` fixture's `String` / `Option<DepSource>`
2660 /// / `Vec<String>` carriers rule out. Peer of the sibling per-
2661 /// `WitContract` pre-projection accessor family's `const`-eval-
2662 /// surface pass (279823b) and of the outer-`Caixa` slice-return
2663 /// accessor family's parallel pass (231a968) — same "one canonical
2664 /// dispatch per axis, `const`-eval posture pinned at the substrate
2665 /// primitive, thin projections at each consumer" discipline
2666 /// extended onto the outer per-dep-list-entry [`Dep`] altitude.
2667 ///
2668 /// [pin]: tests::dep_outer_accessor_family_is_const_fn
2669 #[must_use]
2670 pub const fn fonte(&self) -> Option<&DepSource> {
2671 self.fonte.as_ref()
2672 }
2673
2674 /// Substrate-canonical per-`:deps` / `:deps-dev` entry
2675 /// `:caracteristicas` Cargo-shaped feature-toggle-set slice accessor
2676 /// every consumer of the dep-graph feature-flag axis keys off —
2677 /// returns the author-declared `:caracteristicas` feature-name list
2678 /// verbatim as a `&[String]` slice-view over the same backing buffer
2679 /// the raw `self.caracteristicas.as_slice()` field access borrows
2680 /// from. Empty-list-carrying (`:caracteristicas` is a default-empty
2681 /// axis every `Dep` supplies with `Vec::new()` when the author omits
2682 /// the slot; the [`crate::Caixa::from_lisp`] derive folds an omitted
2683 /// `:caracteristicas` through `#[serde(default)]` to `Vec::new()`,
2684 /// so a `Dep` past parse definitionally carries a `Vec<String>` slot
2685 /// — possibly empty — and the returned `&[String]` degenerates to
2686 /// an empty slice on that arm without any silent `None` collapse).
2687 ///
2688 /// The `:deps :caracteristicas` / `:deps-dev :caracteristicas` slot
2689 /// carries the set-shaped feature-toggle list the substrate walks
2690 /// through the [`Self::validate_caracteristicas`] per-entry shape +
2691 /// duplicate cascade — same Cargo `[dependencies.<dep>.features]`
2692 /// accept-set (per-entry Cargo-feature-name grammar via the shared
2693 /// [`crate::render::is_cargo_feature_name`] predicate, cross-entry
2694 /// uniqueness via the shared [`crate::render::insert_first_seen`]
2695 /// walk, empty-first / value-shape-second / duplicate-third
2696 /// precedence via the peer per-axis two-arm cascade discipline every
2697 /// substrate-blessed Vec-keyed-by-name slot already follows).
2698 /// Every downstream consumer that fans on the dep's feature-toggle
2699 /// keys off this accessor: [`Self::validate_caracteristicas`]'s
2700 /// per-entry linear walk that gates each feature-name byte-string
2701 /// through the empty / value-shape / duplicate arms (raising the
2702 /// [`DepError::CaracteristicaEmpty`] / [`DepError::CaracteristicaInvalid`]
2703 /// / [`DepError::CaracteristicaDuplicate`] carrier family naming the
2704 /// offending `Dep::nome`), and every future
2705 /// per-`Caixa`-manifest / caixa-resolver / caixa-crd feature-toggle-
2706 /// facing consumer the CAIXA-SDLC §I roadmap acknowledges (the
2707 /// future caixa-resolver per-dep feature-projection walk that folds
2708 /// the toggle set into the resolved [`crate::Caixa`]'s activated
2709 /// [`crate::render::CARGO_FEATURE_NAME_MAX_LEN`]-bounded feature
2710 /// closure ahead of the lacre hash, the future caixa-crd per-`spec.deps`
2711 /// features slice the K8s-CR admission gate consumes, the future
2712 /// per-cluster feature-overlay the M4 lacre-federation resolver
2713 /// composes ahead of the substrate-wide feature-name accept-set).
2714 ///
2715 /// Prior to this lift the `.caracteristicas` byte-string list was
2716 /// read inline at the [`Self::validate_caracteristicas`] `for c in
2717 /// &self.caracteristicas` walk — the only in-crate consumer of the
2718 /// raw field beyond the per-`Dep` constructor pair
2719 /// ([`Self::simple`] / [`Self::git`]) and the paired serde
2720 /// round-trip / per-test fixture-mutation paths — an open-coded
2721 /// field-access that expressed no compile-time link back to the
2722 /// typed slot. A future extension of the `:caracteristicas` axis to
2723 /// a richer author surface (a per-scope feature-overlay the resolver
2724 /// folds through the `~/.config/caixa/config.yaml` entry the
2725 /// [`Dep`] docstring already acknowledges, a per-cluster feature-
2726 /// activation overlay the future M4 lacre-federation layer applies
2727 /// per-CR, a promotion of the plain `Vec<String>` byte-string list
2728 /// to a richer parsed-feature-set newtype once the Cargo-shaped
2729 /// namespaced-dep `dep/feat` syntax the value-shape gate's
2730 /// docstring anticipates lands) would have had to be threaded
2731 /// through every open-coded copy in lockstep or two consumers
2732 /// would silently disagree on which feature closure a given dep
2733 /// activates — the [`Self::validate_caracteristicas`] gate walking
2734 /// the author-declared list while a downstream caixa-resolver
2735 /// consumer walked a per-scope-override-resolved list would
2736 /// silently split the build-time refusal from the lacre closure
2737 /// the substrate's fetch pipeline actually materializes, one
2738 /// build-time diagnostic disagreeing with the run-time closure.
2739 /// Lifting the resolution rule to a typed method on the substrate
2740 /// primitive means every downstream consumer of the caixa's per-
2741 /// `:deps` feature-toggle surface reaches for exactly one typed
2742 /// dispatch — the resolver's accept-set migrates as a unit on any
2743 /// future axis addition.
2744 ///
2745 /// First outer-`Dep` `&[T]`-return slice accessor — opens the
2746 /// outer-`Dep` `&[String]` slice projection pattern the sibling
2747 /// per-`Dep` `:opcional` (`bool` — the plain-`Copy`-scalar axis)
2748 /// future outer scalar lift folds on and closes the outer-`Dep`
2749 /// slot-family the sibling [`Self::nome`] (eba2cde) /
2750 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2751 /// accessors already open, leaving the `:opcional` `Copy`-scalar arm
2752 /// as the sole remaining unlifted outer-`Dep` slot. Peer of the
2753 /// outer top-level [`crate::Caixa`] `&[String]`-return foreign-code-
2754 /// slot sub-family ([`crate::Caixa::bibliotecas`] 8a36c23,
2755 /// [`crate::Caixa::exe`] 65d9527, [`crate::Caixa::servicos`]
2756 /// 611f78b) and the outer top-level [`crate::Caixa`] universal-axis
2757 /// text-tag family ([`crate::Caixa::autores`] b5d813f,
2758 /// [`crate::Caixa::etiquetas`] 78c7d3c) that already carry the
2759 /// `&[String]` slice-projection discipline on the outer-`Caixa`
2760 /// altitude — extends the "one typed dispatch on the substrate
2761 /// primitive, thin projections at each consumer" discipline onto the
2762 /// outer per-dep-list-entry [`Dep`] altitude's set-shaped byte-
2763 /// string list slot. Returns `&[String]` (not `&Vec<String>`)
2764 /// because every downstream consumer of the feature-toggle list
2765 /// treats it as a read-only sequence — the slice-view is the
2766 /// narrowest borrow that supports every present + roadmapped
2767 /// consumer (`.iter()`, `.len()`, `.is_empty()`) without leaking
2768 /// the backing `Vec`'s grow/push/reserve surface no consumer of
2769 /// the typed view reaches for (the storage-side `Vec` remains
2770 /// reachable through the `pub caracteristicas` field for the
2771 /// mutation-carrying serde round-trip and per-test fixture-mutation
2772 /// paths). Named `caracteristicas()` to match the storage field's
2773 /// name verbatim and the tatara-lisp author-surface term
2774 /// (`:caracteristicas`) the field's own docstring already carries.
2775 ///
2776 /// Declared `pub const fn` — the body projects through
2777 /// `Vec::<String>::as_slice`, const-stable since Rust 1.83 and
2778 /// well within the workspace MSRV, so every downstream `const`-
2779 /// context consumer of the per-`Dep` `:caracteristicas` slice-
2780 /// accessor reaches through the same typed dispatch on the
2781 /// substrate primitive at const-eval time as at runtime. Pinned
2782 /// load-bearing by the paired
2783 /// [`dep_outer_accessor_family_is_const_fn`][pin] wrapper family
2784 /// alongside its sibling [`Self::fonte`] — see [`Self::fonte`] for
2785 /// the full pin-shape rationale.
2786 ///
2787 /// [pin]: tests::dep_outer_accessor_family_is_const_fn
2788 #[must_use]
2789 pub const fn caracteristicas(&self) -> &[String] {
2790 self.caracteristicas.as_slice()
2791 }
2792
2793 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:opcional`
2794 /// missing-source-tolerance flag scalar accessor every consumer of
2795 /// the dep-graph opt-in-fetch axis keys off — returns the author-
2796 /// declared `:opcional` `bool` verbatim, `Copy`-projected from the
2797 /// typed slot's own `bool` storage (no borrow of `&self` past the
2798 /// call; the `Copy`-return arm matches the peer
2799 /// [`crate::Caixa::max_restarts`] (eba5211) `Option<u32>` `Copy`-
2800 /// projected sibling discipline the outer flat-spread family
2801 /// already carries). Default-`false` (`#[serde(default,
2802 /// skip_serializing_if = "is_false")]` on the storage slot, so a
2803 /// `Dep` past parse definitionally carries a `bool` — `false` when
2804 /// the author omits `:opcional` — and the returned value degenerates
2805 /// to `false` on that arm without any silent `None` collapse).
2806 ///
2807 /// The `:deps :opcional` / `:deps-dev :opcional` slot carries the
2808 /// per-entry "if this dep's `:fonte` cannot be resolved, treat the
2809 /// missing-source arm as a soft-fail rather than a build refusal"
2810 /// bit — the same Cargo-shaped `[dependencies.<dep>.optional = true]`
2811 /// accept-set (an opcional dep whose `:fonte` fails to resolve is
2812 /// dropped from the resolved dep-graph rather than tripping the
2813 /// build-refusal edge that a mandatory `:opcional false` entry
2814 /// would). Every downstream consumer that fans on the dep's
2815 /// missing-source-tolerance keys off this accessor: the future
2816 /// caixa-resolver's per-`:fonte` resolve-fail arm (drop-vs-error
2817 /// dispatch on the opcional bit ahead of the lacre closure
2818 /// materialization), the future caixa-crd per-`spec.deps`
2819 /// `optional` boolean the K8s-CR admission gate consumes on the
2820 /// per-dep partition, and the future feira / caixa-resolver /
2821 /// caixa-crd feature-projection walk that folds the opcional bit
2822 /// into the resolved feature-closure the future M4 lacre-federation
2823 /// layer emits.
2824 ///
2825 /// Prior to this lift the `.opcional` `bool` slot was read inline
2826 /// at the sole in-crate consumer site — the tests-module
2827 /// `registry_dep_is_minimal` fixture's `assert!(!d.opcional)` gate
2828 /// pinning the [`Self::simple`] constructor's default-`false` fill
2829 /// (the only in-crate read of the raw field beyond the per-`Dep`
2830 /// constructor pair [`Self::simple`] / [`Self::git`] and the paired
2831 /// serde round-trip / per-test fixture-mutation paths) — an open-
2832 /// coded field-access that expressed no compile-time link back to
2833 /// the typed slot. A future extension of the `:opcional` axis to a
2834 /// richer author surface (a per-scope opcional-override the resolver
2835 /// folds through the `~/.config/caixa/config.yaml` entry the [`Dep`]
2836 /// docstring already acknowledges, a per-cluster opcional-override
2837 /// the future M4 lacre-federation layer applies per-CR, a promotion
2838 /// of the plain `bool` to a richer `OpcionalPolicy { drop, warn,
2839 /// error }` tri-state once the CAIXA-SDLC §II opcional-policy
2840 /// roadmap lands) would have had to be threaded through every open-
2841 /// coded copy in lockstep or two consumers would silently disagree
2842 /// on which missing-source arm a given dep resolves to — the
2843 /// [`Self::simple`] constructor's default-`false` fill reading
2844 /// verbatim while a downstream caixa-resolver consumer read a per-
2845 /// scope-override-resolved bit would silently split the build-time
2846 /// arm from the lacre closure the substrate's fetch pipeline
2847 /// actually materializes, one build-time diagnostic disagreeing
2848 /// with the run-time closure. Lifting the resolution rule to a
2849 /// typed method on the substrate primitive means every downstream
2850 /// consumer of the caixa's per-`:deps` opcional-tolerance surface
2851 /// reaches for exactly one typed dispatch — the resolver's accept-
2852 /// set migrates as a unit on any future axis addition.
2853 ///
2854 /// Fifth and final outer-`Dep` accessor — closes the outer-`Dep`
2855 /// slot-family the sibling per-`Dep` [`Self::nome`] (eba2cde) /
2856 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2857 /// / [`Self::caracteristicas`] (9197944) accessors opened, so every
2858 /// outer-`Dep` slot (`:nome`, `:versao`, `:fonte`, `:opcional`,
2859 /// `:caracteristicas`) now routes through exactly one typed
2860 /// dispatch on the substrate primitive. First outer-`Dep`
2861 /// `bool`-return / plain-`Copy`-scalar accessor — opens the
2862 /// outer-`Dep` `Copy`-scalar projection pattern that folds on the
2863 /// peer outer-top-level [`crate::Caixa`] `Option<Copy>`
2864 /// flat-spread sub-family ([`crate::Caixa::max_restarts`] eba5211,
2865 /// [`crate::Caixa::estrategia`] ed04d3c) the outer-`Caixa` altitude
2866 /// already carries — extends the "one typed dispatch on the
2867 /// substrate primitive, thin projections at each consumer"
2868 /// discipline onto the outer per-dep-list-entry [`Dep`] altitude's
2869 /// bool-shaped missing-source-tolerance slot. Returns `bool` by
2870 /// `Copy` (not by `&bool` reference) because `bool` is `Copy` and
2871 /// every downstream consumer treats it as a plain discriminant
2872 /// value — the by-value return is the narrowest return-shape that
2873 /// supports every present + roadmapped consumer (`.then(…)` early
2874 /// return on the resolver-side drop-vs-error partition, direct
2875 /// bool composition with a per-scope-override projector, plain
2876 /// `if dep.opcional() { … }` early return at every future admission
2877 /// gate) without leaking the storage field's `bool`-in-`&self`
2878 /// lifetime the by-value return elides. Marked `pub const fn` so
2879 /// the accessor is `const`-callable — same discipline the peer
2880 /// [`crate::Caixa::max_restarts`] `Option<u32>` `Copy`-return
2881 /// accessor carries. Named `opcional()` to match the storage
2882 /// field's name verbatim and the tatara-lisp author-surface term
2883 /// (`:opcional`) the field's own docstring already carries.
2884 #[must_use]
2885 pub const fn opcional(&self) -> bool {
2886 self.opcional
2887 }
2888
2889 /// Build a minimal registry-sourced dep.
2890 #[must_use]
2891 pub fn simple(nome: impl Into<String>, versao: impl Into<String>) -> Self {
2892 Self {
2893 nome: nome.into(),
2894 versao: versao.into(),
2895 fonte: None,
2896 opcional: false,
2897 caracteristicas: Vec::new(),
2898 }
2899 }
2900
2901 /// Build a Git-sourced dep (tag-based).
2902 #[must_use]
2903 pub fn git(
2904 nome: impl Into<String>,
2905 versao: impl Into<String>,
2906 repo: impl Into<String>,
2907 tag: impl Into<String>,
2908 ) -> Self {
2909 Self {
2910 nome: nome.into(),
2911 versao: versao.into(),
2912 fonte: Some(DepSource::Git {
2913 repo: repo.into(),
2914 tag: Some(tag.into()),
2915 rev: None,
2916 branch: None,
2917 }),
2918 opcional: false,
2919 caracteristicas: Vec::new(),
2920 }
2921 }
2922
2923 /// Reject dependency entries whose `:nome` or `:versao` are empty,
2924 /// whose `:nome` is non-empty but not a valid DNS-1123 label,
2925 /// or whose `:versao` is non-empty but not a valid Cargo-shaped
2926 /// semver requirement.
2927 ///
2928 /// The author surface for `:deps :versao` (and `:deps-dev :versao`)
2929 /// is the same Cargo-shaped requirement string `:membros :versao`
2930 /// (validated at [`crate::AplicacaoSpec::validate`] since 9888b13)
2931 /// and `:children :versao` (validated at
2932 /// [`crate::SupervisorSpec::validate`] since b38ff3a) carry — and
2933 /// the lacre pipeline resolves all three axes through the same
2934 /// [`crate::parse_requirement`] entry-point. Until 2420c44 landed
2935 /// `:deps :versao` was the last `:versao` axis untyped past
2936 /// `Caixa::from_lisp`: a malformed-but-non-empty requirement
2937 /// (`"^bad-version"`, `"^^0.1"`, the canonical git-tag-shape-
2938 /// leaking-into-:versao `"v0.1"` typo, the accidental
2939 /// `"not-a-req"`) silently passed parse and the `semver::Error`
2940 /// surfaced at lacre-resolve time, far from the source
2941 /// caixa.lisp, with no field naming which `:deps` entry carried
2942 /// the typo. The diagnostic [`DepError::VersaoInvalid`] carries
2943 /// the offending entry's `:nome` + the offending `:versao`
2944 /// verbatim + the parser's own wording in `reason`, so the
2945 /// author's grep target is unambiguous.
2946 ///
2947 /// The author surface for `:deps :nome` is the same DNS-1123 label
2948 /// the peer caixa-identifier axes carry — top-level Caixa `:nome`
2949 /// (validated at [`crate::Caixa::validate_nome`] since 6c992f8),
2950 /// `:membros :caixa` (validated at
2951 /// [`crate::AplicacaoSpec::validate_membros`] since 3f9d7a0),
2952 /// `:children :caixa` (validated at
2953 /// [`crate::SupervisorSpec::validate`] since 31bfa43). A `:deps
2954 /// :nome` value flows verbatim through the lacre pipeline as the
2955 /// target caixa's `:nome` (which the gate at the *target* side now
2956 /// rejects if non-DNS-1123) and lands as the rendered caixa's
2957 /// `lareira-<nome>` Helm chart name segment, the per-dep
2958 /// `LABEL_PROGRAM` label value, and the `caixa-resolver`'s
2959 /// `~/.cache/caixa/<org>/<nome>` checkout-directory leaf. Until
2960 /// this gate landed `:deps :nome` was the fourth and last
2961 /// DNS-1123-shaped caixa-identifier axis still untyped past
2962 /// `Caixa::from_lisp`: a syntactically wrong dep name (`"Caixa-
2963 /// Teia"` uppercase — the canonical "I copied the README header"
2964 /// typo; `"caixa_teia"` underscore — the Go module / Python
2965 /// identifier leak; `"caixa-teia."` trailing dot — the FQDN
2966 /// confusion; `"-caixa-teia"` leading hyphen; a 64-byte slug)
2967 /// silently passed parse and surfaced at lacre-resolve time when
2968 /// the resolved target caixa's `:nome` failed *its* DNS-1123 gate
2969 /// — far from the source `:deps` entry, with a diagnostic naming
2970 /// the *target's* `:nome` rather than the dep entry that referenced
2971 /// it. Mirroring the 3f9d7a0 / 31bfa43 / 6c992f8 trajectory through
2972 /// the lifted [`crate::render::is_dns_1123_label`] predicate (the
2973 /// "before its third occurrence" PRIME DIRECTIVE boundary, THEORY.md
2974 /// §I.3.5): every `Dep::nome` past validate is DNS-1123-label-shaped,
2975 /// so every downstream consumer (caixa-resolver's lacre fetch,
2976 /// caixa-helm's `lareira-<nome>` chart name, the future M4 per-dep
2977 /// fan-out emitter) reaches for the name knowing the value is
2978 /// apiserver-valid without re-validating.
2979 ///
2980 /// Empty checks fire first (narrower diagnostic), parse last —
2981 /// same ordering discipline as
2982 /// [`crate::AplicacaoSpec::validate_membros`] and
2983 /// [`crate::SupervisorSpec::validate`]. `parse_requirement("")`
2984 /// returns `Ok(VersionReq::STAR)`, so the empty-`:versao` arm is
2985 /// structurally necessary even with the parse arm in place. The
2986 /// `:nome` shape gate runs after the `:nome` empty gate and before
2987 /// the `:versao` checks so a one-entry caixa.lisp with both wrong
2988 /// sees the name-side diagnostic first (the name is the
2989 /// self-locating axis — without it, the parse diagnostic can't
2990 /// quote `:nome "<bad>"`).
2991 pub fn validate(&self) -> Result<(), DepError> {
2992 if self.nome.is_empty() {
2993 return Err(DepError::NomeEmpty);
2994 }
2995 if let Err(reason) = crate::render::is_dns_1123_label(&self.nome) {
2996 return Err(DepError::NomeInvalid {
2997 nome: self.nome.clone(),
2998 reason,
2999 });
3000 }
3001 // Delegate the empty-first + `parse_requirement` cascade to the
3002 // shared [`crate::render::require_valid_versao_requirement`]
3003 // helper — same two-arm shape the peer
3004 // [`crate::AplicacaoSpec::validate_membros`] on `:membros
3005 // :versao` and [`crate::SupervisorSpec::validate`] on `:children
3006 // :versao` route through, so drift between the three axes'
3007 // accepted requirement sets is structurally impossible and the
3008 // parse-side no-op the empty-first arm closes (semver's empty
3009 // parse yields an implicit `*`) lives in exactly one predicate.
3010 crate::render::require_valid_versao_requirement(
3011 self.versao_requirement(),
3012 || DepError::versao_empty(&self.nome),
3013 |reason| DepError::VersaoInvalid {
3014 nome: self.nome.clone(),
3015 versao: self.versao_requirement().to_string(),
3016 reason,
3017 },
3018 )?;
3019 if let Some(fonte) = self.fonte() {
3020 fonte.validate(&self.nome)?;
3021 }
3022 self.validate_caracteristicas()?;
3023 Ok(())
3024 }
3025
3026 /// Reject per-entry `:caracteristicas` (feature-flag) values that
3027 /// are operationally meaningless. The `:caracteristicas` slot is
3028 /// a set of feature toggles to enable on the target caixa — same
3029 /// shape as Cargo's `[dependencies.<dep>.features]` list — and
3030 /// two structural footguns close here:
3031 ///
3032 /// - empty-string entry (`(:caracteristicas (""))`): the future
3033 /// caixa-resolver lacre pipeline would consume the empty
3034 /// identifier as a no-op feature enable, silently dropping the
3035 /// author's intent far from the source `caixa.lisp`;
3036 /// - duplicate entry within one dep (`(:caracteristicas ("http"
3037 /// "http"))`): the feature-toggle slot is set-shaped (enabling
3038 /// a feature twice has no additional semantic — there is no
3039 /// `feature × 2`), so two entries naming the same feature are
3040 /// a silent miscount, the same set-not-multiset distinction
3041 /// every peer Vec-keyed-by-name axis already closes
3042 /// ([`crate::SupervisorError::DuplicateChildCaixa`] on
3043 /// `:children :caixa`, [`crate::AplicacaoError::MembroDuplicate`]
3044 /// on `:membros :caixa`, [`crate::AplicacaoError::ContratoDuplicate`]
3045 /// on `:contratos`, [`crate::AplicacaoError::PlacementClusterDuplicate`]
3046 /// on `:placement :clusters`, [`crate::AplicacaoError::EntradaPathDuplicate`]
3047 /// on `:entrada :paths`, [`crate::UpgradeError::DuplicateFrom`]
3048 /// on `:upgrade-from :from`, [`crate::UpgradeError::DuplicateLoadModule`]
3049 /// / [`crate::UpgradeError::DuplicateStateChange`] /
3050 /// [`crate::UpgradeError::DuplicateCleanup`] on the within-
3051 /// entry `:upgrade-from` axes, and [`DepError::DuplicateNome`]
3052 /// on the cross-entry `:deps`/`:deps-dev` `:nome` axis the
3053 /// immediate-predecessor 359fba5 closed).
3054 ///
3055 /// Same linear-walk + `HashSet` + first-collision diagnostic shape
3056 /// every peer set-not-multiset gate uses; the empty arm fires
3057 /// before the duplicate arm so an entry with both an empty feature
3058 /// *and* a duplicate of some later feature surfaces the empty-
3059 /// shape diagnostic first (the empty-feature axis is the
3060 /// more-actionable defect since the missing-name renders the
3061 /// duplicate-key arm ambiguous: two `""` entries would both report
3062 /// `caracteristica: ""` with no way to distinguish the offending
3063 /// site). Empty-first cascade discipline mirrors every peer per-
3064 /// entry shape + duplicate gate
3065 /// (`SupervisorSpec::validate`'s `EmptyChildName` before
3066 /// `DuplicateChildCaixa`; `validate_membros`'s `MembroCaixaEmpty`
3067 /// before `MembroDuplicate`).
3068 ///
3069 /// The per-entry value-shape gate (Cargo-feature-name grammar via
3070 /// the lifted [`crate::render::is_cargo_feature_name`] predicate)
3071 /// fires between the empty arm and the duplicate arm — the
3072 /// canonical per-entry-shape-before-cross-entry-uniqueness
3073 /// precedence every peer two-arm + value-shape gate establishes
3074 /// ([`crate::SupervisorSpec::validate`]'s `EmptyChildName` →
3075 /// `ChildCaixaInvalid` → `DuplicateChildCaixa`,
3076 /// [`crate::AplicacaoSpec::validate_membros`]'s `MembroCaixaEmpty`
3077 /// → `MembroCaixaInvalid` → `MembroDuplicate`, [`Dep::validate`]'s
3078 /// `NomeEmpty` → `NomeInvalid` → cross-list `DuplicateNome`).
3079 /// Until the value-shape arm landed `:caracteristicas` accepted
3080 /// every non-empty distinct string — a structurally invalid
3081 /// feature name (`"http feature"` whitespace, `"+http"` the
3082 /// canonical paste-from-`+optional-feature` doc activation-form
3083 /// footgun, `"-flag"` leading hyphen, `".feat"` leading dot,
3084 /// `"http/json"` Cargo's `dep/feat` namespaced-dep syntax that
3085 /// only applies inside list-grammar contexts, `"http,json"`
3086 /// list-separator-belongs-to-the-list-grammar miscomprehension,
3087 /// `"café"` un-percent-encoded non-ASCII silently round-tripping
3088 /// inconsistently across NFC/NFD normalization, the 65-byte
3089 /// paste-from-binary slug) silently passed validate and the
3090 /// failure surfaced at `cargo metadata` time as the
3091 /// `restricted_names::validate_feature_name` parser's rejection,
3092 /// far from the source `caixa.lisp`, with no field naming which
3093 /// `:deps` entry's `:caracteristicas` carried the typo. The
3094 /// lifted predicate makes the Cargo-feature-name-grammar
3095 /// intersection-floor a substrate-level invariant at validate
3096 /// time — same trajectory as the eight peer
3097 /// [`crate::render`] value-shape predicates each typed surface
3098 /// downstream of a structured grammar already follows
3099 /// ([`is_dns_1123_label`](crate::render::is_dns_1123_label),
3100 /// [`is_gateway_api_http_path`](crate::render::is_gateway_api_http_path),
3101 /// [`is_wit_world_ref`](crate::render::is_wit_world_ref),
3102 /// [`is_nats_subject`](crate::render::is_nats_subject),
3103 /// [`is_wasi_keyvalue_slot`](crate::render::is_wasi_keyvalue_slot),
3104 /// [`is_git_ref_name`](crate::render::is_git_ref_name),
3105 /// [`is_git_oid`](crate::render::is_git_oid),
3106 /// [`is_git_repo_url`](crate::render::is_git_repo_url)).
3107 fn validate_caracteristicas(&self) -> Result<(), DepError> {
3108 let mut seen = std::collections::HashSet::new();
3109 for c in self.caracteristicas() {
3110 if c.is_empty() {
3111 return Err(DepError::caracteristica_empty(&self.nome));
3112 }
3113 if let Err(reason) = crate::render::is_cargo_feature_name(c) {
3114 return Err(DepError::CaracteristicaInvalid {
3115 nome: self.nome.clone(),
3116 caracteristica: c.clone(),
3117 reason,
3118 });
3119 }
3120 crate::render::insert_first_seen(&mut seen, c.as_str(), || {
3121 DepError::CaracteristicaDuplicate {
3122 nome: self.nome.clone(),
3123 caracteristica: c.clone(),
3124 }
3125 })?;
3126 }
3127 Ok(())
3128 }
3129}
3130
3131/// Cross-slot coherence gate on the dep-graph axis: no `:deps` or
3132/// `:deps-dev` entry may name the caixa's own `:nome`.
3133///
3134/// A caixa that lists itself as a dep is a degenerate self-edge in the
3135/// lacre closure's dep-graph — the closure is a DAG rooted at the
3136/// caixa's `:nome`, and the caixa-resolver's lacre pipeline traverses
3137/// every `:deps` / `:deps-dev` entry's target by name. A self-dep
3138/// hands the resolver a node that is its own parent: a one-node cycle
3139/// it either rejects mid-traversal far from the source `caixa.lisp`
3140/// (the resolver detecting infinite recursion on the closure walk) or,
3141/// worse, recurses on until it exhausts its stack. Because every
3142/// `:nome` is a globally-unique substrate identity (DNS-1123 label +
3143/// lacre closure root), a dep entry whose `:nome` equals the caixa's
3144/// own `:nome` *is* the caixa itself, not a coincidentally-named peer.
3145///
3146/// Lives outside [`Caixa::validate_deps`] because the dep-list view
3147/// carries the entries but not the parent `:nome`; mirrors the
3148/// cross-slot self-edge gates [`crate::supervisor::validate_no_self_supervision`]
3149/// (ad4abf1) on the `:children :caixa` axis and
3150/// [`crate::aplicacao::validate_no_self_membership`] on the
3151/// `:membros :caixa` axis — the same "an edge from a graph node to
3152/// itself is structurally not a tree/graph edge" discipline, here on
3153/// the third typed-name-graph axis (the dep closure; the supervision
3154/// tree and the Aplicacao membership set were the prior two).
3155///
3156/// Walks `:deps` first then `:deps-dev` so the diagnostic for a caixa
3157/// that self-references on both axes surfaces the `:deps` arm first —
3158/// the load-bearing axis the lacre closure resolves at every build,
3159/// peer with the canonical [`Caixa::validate_deps`] walk order
3160/// (`:deps` → `:deps-dev`).
3161///
3162/// Carries the offending list tag (`":deps"` or `":deps-dev"`)
3163/// verbatim into the diagnostic so the author can grep their
3164/// `caixa.lisp` for the offending block in one edit — same
3165/// `list: &'static str` shape [`DepError::DuplicateNome`] (359fba5)
3166/// uses on the cross-list duplicate-name axis.
3167///
3168/// `Code paths` (`:bibliotecas` / `:exe` / `:servicos`) are the
3169/// substrate-blessed shape for referencing the caixa's *own* code, so
3170/// the diagnostic names them as the corrective surface — every
3171/// legitimate "I want to use code from this caixa" authoring intent
3172/// routes through one of those three slots, not a self-dep.
3173pub fn validate_no_self_dep(
3174 deps: &[Dep],
3175 deps_dev: &[Dep],
3176 parent_nome: &str,
3177) -> Result<(), DepError> {
3178 for dep in deps {
3179 if dep.nome() == parent_nome {
3180 return Err(DepError::dep_is_self(
3181 parent_nome,
3182 crate::render::DEP_AUTHOR_KEY_DEPS,
3183 ));
3184 }
3185 }
3186 for dep in deps_dev {
3187 if dep.nome() == parent_nome {
3188 return Err(DepError::dep_is_self(
3189 parent_nome,
3190 crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3191 ));
3192 }
3193 }
3194 Ok(())
3195}
3196
3197/// Closed-set typed enum for the two dep-list author-surface axes every
3198/// top-level [`crate::Caixa`] carries — the runtime-closure `:deps` slot
3199/// (`Prod`) and the dev-only-closure `:deps-dev` slot (`Dev`). Every
3200/// substrate consumer that dispatches on "which of the two dep-lists"
3201/// (the `feira add` mutation head, the future per-cluster dev-closure-
3202/// audit overlay the M4 CR materializer resolves per-CR, the future
3203/// `caixa app graph` per-list dep summary, every future
3204/// `Caixa::push_dep` / `Caixa::deps_by_list` typed-method dispatch a
3205/// caller reaches for) reads through this enum rather than through a
3206/// bare `&'static str` — the closed-set is expressed at the type layer,
3207/// so a future third dep-list axis (a `:deps-build` build-only closure
3208/// once the substrate grows cross-artifact heterogeneous dep-graphs,
3209/// per CAIXA-SDLC §I) is one variant plus one arm per method and the
3210/// compiler enforces exhaustiveness on every consumer's `match` arms.
3211///
3212/// The wire byte-string [`Self::as_str`] returns is the same author-
3213/// surface tag the sibling [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3214/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry — the
3215/// [`DepError::DuplicateNome`] / [`DepError::DepIsSelf`] `list:
3216/// &'static str` payload family the substrate already emits routes
3217/// through the same source of truth (an author reading a
3218/// [`DepError::DuplicateNome`] refusal can grep their `caixa.lisp`
3219/// for the offending `:deps` / `:deps-dev` block in one edit whether
3220/// the diagnostic came from a `Caixa::validate_deps` walk or a
3221/// `Caixa::push_dep` mutation).
3222///
3223/// Same "closed-set typed-enum discriminator with canonical
3224/// projections per axis" discipline the sibling closed-set typed enums
3225/// on the caixa typed surface carry
3226/// ([`crate::aplicacao::PlacementStrategy`] cc8f749,
3227/// [`crate::aplicacao::RateLimitUnit`] 6bce03d,
3228/// [`crate::supervisor::RestartStrategy`],
3229/// [`crate::supervisor::RestartPolicy`],
3230/// [`crate::upgrade::UpgradeInstruction`], [`crate::CaixaKind`])
3231/// — extended onto the outer-`Caixa` two-list dep-graph axis, the
3232/// substrate's last unlifted closed-set-shaped `&'static str`-carrying
3233/// axis on the top-level manifest surface.
3234#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
3235pub enum DepList {
3236 /// Runtime-closure `:deps` axis — the load-bearing dep-list the
3237 /// lacre closure resolves at every build. Wire-format
3238 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`].
3239 Prod,
3240 /// Dev-only-closure `:deps-dev` axis — Cargo's `[dev-dependencies]`
3241 /// table's dev-time-only visibility contract per CAIXA-SDLC §I.
3242 /// Wire-format [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`].
3243 Dev,
3244}
3245
3246impl DepList {
3247 /// Exhaustive iteration surface for every consumer that reads the
3248 /// full closed-set (the future M4 admission webhook's per-list
3249 /// summary rejection body, any future round-trip pin harness). A
3250 /// future variant addition extends this slice as a single edit and
3251 /// every consumer picks up the new entry by construction — the
3252 /// compiler-checked exhaustiveness on the sibling method `match`
3253 /// arms is the build-time guarantee that no arm forgets to grow.
3254 pub const ALL: &'static [Self] = &[Self::Prod, Self::Dev];
3255
3256 /// Canonical author-surface tag every substrate consumer that
3257 /// names the offending dep-list in a diagnostic reaches for —
3258 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] for [`Self::Prod`] and
3259 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] for [`Self::Dev`],
3260 /// the same `&'static str` payload the sibling
3261 /// [`DepError::DuplicateNome`] and [`DepError::DepIsSelf`] variants
3262 /// already carry. Routing every dep-list diagnostic through the
3263 /// closed-set enum's `as_str` closes the last `&'static str`-shape
3264 /// literal-carry axis on the two-list dep-graph surface — a
3265 /// future kebab-case rebrand (`":deps"` → `":packages"`) or a
3266 /// wire-format promotion (a distinct diagnostic form for the
3267 /// `Dev` arm) reaches every consumer through one edit on the
3268 /// canonical constant, not a coordinated rewrite across the
3269 /// substrate's dep-graph consumers.
3270 #[must_use]
3271 pub const fn as_str(self) -> &'static str {
3272 match self {
3273 Self::Prod => crate::render::DEP_AUTHOR_KEY_DEPS,
3274 Self::Dev => crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3275 }
3276 }
3277
3278 /// Substrate-canonical reverse projection on the two-list dep-graph
3279 /// axis — parses the author-surface wire tag back to the typed
3280 /// variant, or `None` when `s` is outside the closed-set arm-string
3281 /// set [`Self::as_str`] emits. Dispatches on the same lifted
3282 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3283 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants the
3284 /// [`Self::as_str`] emitter walks, so the parse and emit halves of
3285 /// the round-trip migrate through one caixa-core edit on any future
3286 /// list-axis addition.
3287 ///
3288 /// Prior to this lift the substrate carried only the forward
3289 /// `Self → &str` projection on the two-list dep-graph axis (the
3290 /// [`Self::as_str`] emitter, the [`std::fmt::Display`] impl routed
3291 /// through it, the two [`DepError::DuplicateNome`] /
3292 /// [`DepError::DepIsSelf`] variants that carry the wire tag verbatim
3293 /// as a `&'static str` `list:` field). Every future consumer that
3294 /// wanted to promote the wire tag back to the typed enum (a future
3295 /// `feira dep --list <deps|deps-dev>` CLI arg-parse that binds the
3296 /// wire form into the typed enum before dispatching to
3297 /// [`crate::Caixa::deps_of`] / [`crate::Caixa::push_dep`], the M4
3298 /// `mesh.pleme.io/v1alpha1/Caixa` CR materializer's admission-time
3299 /// wire re-parse of the per-list diagnostic body, a future
3300 /// [`DepError`] widening that promotes the two `list: &'static str`
3301 /// fields to a typed `list: DepList` carry so downstream consumers
3302 /// dispatch on the enum rather than string-comparing the wire
3303 /// scalar) would have had to re-inline a two-arm `match s { ":deps"
3304 /// => …, ":deps-dev" => …, _ => … }` cascade that expressed no
3305 /// compile-time link back to the typed [`DepList`] enum. A future
3306 /// variant addition (a `:build-dep` or `:test-dep` third list once
3307 /// the substrate grows Cargo-style split-graphs, a `:tool-dep` for
3308 /// build-time-only tooling per the peer Cargo `[build-dependencies]`
3309 /// / `[target.<cfg>.dev-dependencies]` future admission surface)
3310 /// would silently split the wire byte-string the emitter walks from
3311 /// the parser's arm-set — the round-trip would carry the new list
3312 /// through the forward projection but land on the fallback silently
3313 /// at every non-updated reverse parser, far from the arm-addition
3314 /// commit that caused the drift. Lifting the resolver to a typed
3315 /// method on the substrate primitive closes the drift footgun by
3316 /// construction: the parser's accept-set is the same set the
3317 /// [`Self::as_str`] emitter walks (routed through the same lifted
3318 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3319 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] consts), so both halves
3320 /// of the round-trip migrate through one caixa-core edit on any
3321 /// future list-axis addition.
3322 ///
3323 /// Same closed-set-reverse-projection discipline the sibling
3324 /// [`crate::CaixaKind::from_wire`] (2aa6d23) /
3325 /// [`crate::supervisor::RestartStrategy::from_wire`] (4eec29c) /
3326 /// [`crate::supervisor::RestartPolicy::from_wire`] (dd32ccf) /
3327 /// [`crate::aplicacao::PlacementStrategy::from_wire`] (18c7342) /
3328 /// [`crate::aplicacao::RateLimitUnit::from_suffix`] typed enums
3329 /// carry on the peer wire-side `str → Self` axes — extended onto
3330 /// the two-list dep-graph closed-set axis, the sixth substrate-side
3331 /// closed-set typed enum on the caixa surface to converge on the
3332 /// two-way `str ↔ Self` round-trip. Method-named `from_wire` (not
3333 /// `from_str`) to match the peer shapes verbatim and side-step the
3334 /// derived [`std::str::FromStr`] impls the sibling
3335 /// [`gen_platform::FromStrKind`]-carrying axes install on their
3336 /// kebab-case dispatcher-catalog identity. Returns `Option<Self>`
3337 /// (rather than `Result<Self, _>`) to match the peer shapes: the
3338 /// caller picks the diagnostic form appropriate for its use site —
3339 /// a future `feira dep --list …` arg-parse that surfaces
3340 /// `unknown list: <arg>` at the CLI builds one on top by iterating
3341 /// [`Self::ALL`], while the future M4 admission-webhook's rejection
3342 /// path folds `None` onto its per-CR structured refusal body.
3343 #[must_use]
3344 pub fn from_wire(s: &str) -> Option<Self> {
3345 match s {
3346 crate::render::DEP_AUTHOR_KEY_DEPS => Some(Self::Prod),
3347 crate::render::DEP_AUTHOR_KEY_DEPS_DEV => Some(Self::Dev),
3348 _ => None,
3349 }
3350 }
3351}
3352
3353/// Route [`std::fmt::Display`] through [`DepList::as_str`], so every
3354/// consumer that formats the axis as user-facing text (a future
3355/// `feira app graph` per-list summary, a future M4 admission-webhook
3356/// rejection body naming the offending list, this crate's own
3357/// [`DepError`] `#[error(...)]` templates when they widen to carry a
3358/// typed [`DepList`]) lands on the same author-surface tag the
3359/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3360/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry. Same
3361/// as-str-through-Display convergence discipline the sibling
3362/// [`crate::aplicacao::PlacementStrategy`],
3363/// [`crate::aplicacao::RateLimitUnit`],
3364/// [`crate::supervisor::RestartStrategy`],
3365/// [`crate::supervisor::RestartPolicy`], and [`crate::CaixaKind`]
3366/// closed-set typed enums carry.
3367impl std::fmt::Display for DepList {
3368 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3369 f.write_str(self.as_str())
3370 }
3371}
3372
3373/// Errors raised by [`Dep::validate`].
3374///
3375/// Mirrors the per-axis error families the other `:versao`-carrying
3376/// typed surfaces expose
3377/// ([`crate::AplicacaoError::MembroVersaoEmpty`] /
3378/// [`crate::AplicacaoError::MembroVersaoInvalid`],
3379/// [`crate::SupervisorError::EmptyChildVersion`] /
3380/// [`crate::SupervisorError::ChildVersaoInvalid`]) so a future top-
3381/// level `CaixaError` (M4) sums these without reshaping the diagnostic.
3382#[derive(Debug, Error, PartialEq, Eq)]
3383pub enum DepError {
3384 #[error(
3385 ":deps entry has empty :nome (every dep must name a target caixa; \
3386 omit the entry instead of carrying an empty name)"
3387 )]
3388 NomeEmpty,
3389 #[error(
3390 ":deps entry :nome {nome:?} is not a valid DNS-1123 label: {reason} \
3391 (the value flows verbatim as the target caixa's `:nome`, the rendered \
3392 `lareira-<nome>` Helm chart name segment, the `LABEL_PROGRAM` label \
3393 value, and the resolver's checkout-directory leaf — each apiserver-side \
3394 schema rejects non-DNS-1123 names at admission time; use a lowercase \
3395 RFC 1123 label like `\"caixa-teia\"` or `\"pleme-mesh\"`, 1..=63 bytes, \
3396 pattern `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)"
3397 )]
3398 NomeInvalid { nome: String, reason: String },
3399 #[error(
3400 ":deps entry {nome:?} has empty :versao (every dep must pin a semver \
3401 constraint that resolves through the lacre pipeline)"
3402 )]
3403 VersaoEmpty { nome: String },
3404 #[error(
3405 ":deps entry {nome:?} :versao {versao:?} is not a valid semver \
3406 requirement: {reason} (use Cargo-shaped forms like `\"^0.1\"`, \
3407 `\"~0.1.2\"`, `\"0.1.0\"`, or `\"*\"` — the same shape `:membros :versao` \
3408 and `:children :versao` carry; the lacre pipeline resolves all three \
3409 through the same parser)"
3410 )]
3411 VersaoInvalid {
3412 nome: String,
3413 versao: String,
3414 reason: String,
3415 },
3416 #[error(
3417 ":deps entry {nome:?} :fonte (:tipo git …) has empty :repo \
3418 (every git source must name a repo — use a `github:org/repo` \
3419 shorthand, an `https://…` URL, or an ssh-git URL; omit the \
3420 entire :fonte block to fall back to the default-host resolver \
3421 convention)"
3422 )]
3423 FonteRepoEmpty { nome: String },
3424 #[error(
3425 ":deps entry {nome:?} :fonte (:tipo git …) :repo {repo:?} has \
3426 invalid value-shape: {reason} (the value flows verbatim into the \
3427 caixa-resolver's `git clone <repo>` subprocess invocation; every \
3428 documented form carries a `:` separator and no whitespace / \
3429 control / non-ASCII bytes — use a `github:org/repo` shorthand, \
3430 an `https://host/path` / `ssh://[user@]host/path` / \
3431 `git://host/path` / `file:///path` URL, or the `git@host:path` \
3432 scp-style SSH form)"
3433 )]
3434 FonteRepoShape {
3435 nome: String,
3436 repo: String,
3437 reason: String,
3438 },
3439 #[error(
3440 ":deps entry {nome:?} :fonte (:tipo git …) has no pin set \
3441 (set exactly one of :tag, :rev, or :branch so the resolver \
3442 can pick a reproducible commit; omit the entire :fonte block \
3443 to fall back to the default-host resolver convention, which \
3444 resolves the latest tag matching :versao)"
3445 )]
3446 FontePinMissing { nome: String },
3447 #[error(
3448 ":deps entry {nome:?} :fonte (:tipo git …) has multiple pins \
3449 set ({pins}); exactly one of :tag, :rev, or :branch must be \
3450 set so the resolver's checkout target is unambiguous (the \
3451 resolver's silent precedence is :rev > :tag > :branch — if \
3452 you intended one specifically, drop the others)"
3453 )]
3454 FontePinAmbiguous { nome: String, pins: String },
3455 #[error(
3456 ":deps entry {nome:?} :fonte (:tipo git …) has empty {pin} \
3457 (a set pin must name a non-empty git ref; drop the {pin} key \
3458 entirely to fall through to another pin axis)"
3459 )]
3460 FontePinEmpty { nome: String, pin: String },
3461 #[error(
3462 ":deps entry {nome:?} :fonte (:tipo git …) {pin} {value:?} has invalid \
3463 value-shape: {reason} (the git porcelain enforces the same shape at \
3464 `git fetch` / `git checkout` time on every pin; use a leaf refname \
3465 like `\"v0.1.0\"` for `:tag` or `\"main\"` / `\"feature/foo\"` for \
3466 `:branch`, or a full 40/64 lowercase-hex commit OID for `:rev` — \
3467 drop any `refs/heads/` or `refs/tags/` prefix the caixa-resolver \
3468 prepends at clone time, and avoid abbreviated SHAs which are \
3469 ambiguous across repository history)"
3470 )]
3471 FontePinShape {
3472 nome: String,
3473 pin: String,
3474 value: String,
3475 reason: String,
3476 },
3477 #[error(
3478 ":deps entry {nome:?} :fonte (:tipo path …) has empty :caminho \
3479 (every path source must name a non-empty filesystem path; \
3480 omit the entire :fonte block to fall back to the default-host \
3481 resolver convention)"
3482 )]
3483 FonteCaminhoEmpty { nome: String },
3484 #[error(
3485 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} is \
3486 absolute (the lacre pipeline embeds the value verbatim in its \
3487 per-dep content-address `path:{caminho}` at \
3488 caixa-resolver/src/resolve.rs:189, so an absolute path makes the \
3489 BLAKE3 closure differ across machines — defeating the \
3490 reproducibility contract that's load-bearing for CSE; express \
3491 the path relative to the caixa.lisp location, e.g. \
3492 \"../caixa-teia\" for a sibling workspace dep)"
3493 )]
3494 FonteCaminhoAbsolute { nome: String, caminho: String },
3495 #[error(
3496 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3497 with `~` (the leading-tilde is a shell-expansion convention, not a \
3498 POSIX path component — `Path::is_absolute` returns false on it, so \
3499 the b94fd83 absolute-path gate doesn't catch it, but the lacre \
3500 pipeline embeds the value verbatim in its per-dep content-address \
3501 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3502 caixa-resolver folds it through `Path::join` without `~`-expansion, \
3503 so the build looks for a literal `./{caminho}` subdirectory and \
3504 fails at resolve time far from the source caixa.lisp; even worse, a \
3505 future caixa-resolver pass that *does* expand `~` would silently \
3506 re-open the host-layout-leak the b94fd83 absolute gate closes — \
3507 Alice's `~` resolves to `/home/alice`, Bob's to `/home/bob`, two CI \
3508 runners with different `$HOME` layouts resolve to two distinct paths \
3509 for the byte-identical caixa, defeating the THEORY.md §V.2 render-\
3510 determinism contract; express the path relative to the caixa.lisp \
3511 location, e.g. \"../caixa-teia\" for a sibling workspace dep, or \
3512 spell out the full relative path explicitly if a workstation-rooted \
3513 dep is genuinely intended)"
3514 )]
3515 FonteCaminhoTildeExpansion { nome: String, caminho: String },
3516 #[error(
3517 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3518 with `$` (the leading-`$` is a shell-variable-expansion convention, \
3519 not a POSIX path component — `Path::is_absolute` returns false on it \
3520 and the a5c248e tilde gate doesn't catch it, but the lacre pipeline \
3521 embeds the value verbatim in its per-dep content-address \
3522 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3523 caixa-resolver folds it through `Path::join` without `$`-expansion, \
3524 so the build looks for a literal `./{caminho}` subdirectory and \
3525 fails at resolve time far from the source caixa.lisp; even worse, a \
3526 future caixa-resolver pass that *does* expand `$VAR` (the canonical \
3527 shell-convention idiom that CI's `${{WORKSPACE}}` paste-idiom \
3528 invites) would silently re-open the host-layout-leak the b94fd83 \
3529 absolute gate closes — Alice's `$HOME` resolves to `/home/alice`, \
3530 Bob's to `/home/bob`, two CI runners with different `${{WORKSPACE}}` \
3531 layouts resolve to two distinct paths for the byte-identical caixa, \
3532 defeating the THEORY.md §V.2 render-determinism contract; express \
3533 the path relative to the caixa.lisp location, e.g. \"../caixa-teia\" \
3534 for a sibling workspace dep, or spell out the full relative path \
3535 explicitly if a workstation-rooted dep is genuinely intended)"
3536 )]
3537 FonteCaminhoVarExpansion { nome: String, caminho: String },
3538 #[error(
3539 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3540 with a space (the leading ASCII space `0x20` is the orthogonal \
3541 paste-from-aligned-doc footgun that silently passes \
3542 `Path::is_absolute` and every prior leading-byte arm — \
3543 `\" ../caixa-teia\"` resolves via `Path::join` to a literal \
3544 `./ ../caixa-teia` subdirectory the resolver fails to find at \
3545 resolve time with a non-self-locating `No such file or directory` \
3546 error far from the source caixa.lisp; the lacre pipeline embeds \
3547 the value verbatim in its per-dep content-address `path:{caminho}` \
3548 at caixa-resolver/src/resolve.rs:189, so byte-divergent / \
3549 semantic-identical caixa values (` ../caixa-teia` vs \
3550 `../caixa-teia`) yield two distinct BLAKE3 closures across two \
3551 workstations whose authors differ only in paste-from-aligned- \
3552 caixa.lisp-doc whitespace habits — the most insidious failure \
3553 mode the typed slot can carry (no error surfaces; the divergence \
3554 is invisible until two machines compare lacres), defeating the \
3555 THEORY.md §V.2 render-determinism contract. The canonical \
3556 paste-from-aligned-`:deps`-block footgun (every `:fonte` form in \
3557 a multi-entry `:deps` block sits at the same column — an author \
3558 selecting `\"<sp><sp><sp>../caixa-teia\"` and pasting it from \
3559 the rendered alignment into a fresh entry preserves the leading \
3560 whitespace verbatim); peer `:fonte :repo` axis already rejects \
3561 leading whitespace via `is_git_repo_url`, `:fonte :tag` / \
3562 `:fonte :branch` via `is_git_ref_name`, `:descricao` via \
3563 `is_chart_description_shape`, `:licenca` via \
3564 `is_spdx_expression_shape`. Drop the leading space; express the \
3565 path as a bare relative single-token like \"../caixa-teia\")"
3566 )]
3567 FonteCaminhoLeadingWhitespace { nome: String, caminho: String },
3568 #[error(
3569 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3570 with `-` (the canonical CLI-argument-injection footgun on the \
3571 `:caminho` axis — the lacre pipeline embeds the value verbatim in \
3572 its per-dep content-address `path:{caminho}` at \
3573 caixa-resolver/src/resolve.rs:189 and the caixa-resolver folds it \
3574 through `Path::join` looking for a literal `./{caminho}` \
3575 subdirectory. Every downstream subprocess that consumes the resolved \
3576 path — `git -C {caminho} <verb>`, `terraform -chdir={caminho}`, \
3577 `nix build --path {caminho}`, `find {caminho}`, `stat {caminho}`, \
3578 `cp -r {caminho} …`, `rm -rf {caminho}` — reinterprets a leading-`-` \
3579 value as a CLI flag rather than a positional path when the invocation \
3580 does not carry a `--` argument-list terminator between the flag block \
3581 and the path (the common case at every porcelain entry point). The \
3582 canonical footguns: `:caminho \"-rf\"` (bare short-flag paste), \
3583 `:caminho \"-C\"` (`git -C -C` config-injection paste), \
3584 `:caminho \"--upload-pack=cat /etc/passwd\"` (the canonical long-flag \
3585 CLI-arg-injection vector at every git porcelain entry point that \
3586 consumes a path or URL argument, peer with is_git_repo_url's \
3587 leading-`-` arm on the sibling `:fonte :repo` axis), \
3588 `:caminho \"--config=…\"` (`git -c foo=bar` config-override paste). \
3589 POSIX `std::path::Path` treats a leading `-` as a literal filename \
3590 byte so the resolver folds `\"-rf\"` through `Path::join` and looks \
3591 for a literal `./-rf` subdirectory that fails at resolve time with a \
3592 non-self-locating `No such file or directory` error far from the \
3593 source caixa.lisp — but on any downstream shell-out without `--` the \
3594 reinterpretation is silent and the failure mode is arbitrary-\
3595 argument-injection. Peer arms: `is_git_repo_url` (render.rs:2037) \
3596 rejects leading `-` on `:fonte :repo` for `git clone <repo>` CLI-\
3597 arg-injection; `is_git_ref_name` (render.rs:1381, 5a28454) rejects \
3598 leading `-` on `:fonte :tag` / `:branch` for `git checkout <ref>` \
3599 CLI-arg-injection; `is_dns_1123_label` rejects leading `-` on every \
3600 DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros :caixa`, \
3601 `:children :caixa`, `:deps :nome`, cluster names); \
3602 `is_cargo_feature_name` rejects leading `-` on `:caracteristicas`; \
3603 the feira `init` / `add <nome>` positional gate (868c191) rejects \
3604 leading `-` on the CLI positional itself. Express the path as a bare \
3605 relative single-token like \"../caixa-teia\" — the sibling-workspace \
3606 directory name carries no leading-hyphen semantic, and `./` / `../` \
3607 prefixes structurally partition the leading-byte set to safe values.)"
3608 )]
3609 FonteCaminhoLeadingHyphen { nome: String, caminho: String },
3610 #[error(
3611 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains \
3612 ASCII control byte 0x{byte:02x} (POSIX paths reject NUL `0x00` outright — \
3613 every `std::fs` syscall routes the path through `CString::new` which \
3614 fails with `NulError` at resolve time; the lacre pipeline embeds the \
3615 value verbatim in its per-dep content-address `path:{caminho}` at \
3616 caixa-resolver/src/resolve.rs:189 so a control byte anywhere in the \
3617 value lands in the BLAKE3 closure and breaks the THEORY.md §V.2 render-\
3618 determinism contract — the canonical paste-from-multiline-doc \
3619 (`\\n`/`\\r`), paste-from-aligned-table (`\\t`), or paste-from-binary-\
3620 blob (`0x00`-DEL) footgun every peer single-token-shaped axis \
3621 (`:fonte :repo`, `:fonte :tag`/`:branch`, the Helm chart-string axes) \
3622 already gates against. Express the path as a relative single-line ASCII \
3623 string, e.g. \"../caixa-teia\" for a sibling workspace dep)"
3624 )]
3625 FonteCaminhoControlChar {
3626 nome: String,
3627 caminho: String,
3628 byte: u8,
3629 },
3630 #[error(
3631 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains `\\` \
3632 (POSIX `std::path::Path` treats `\\` as a literal byte inside a single path \
3633 component, so `..\\caixa-teia` is one directory named literally `..\\caixa-teia` — \
3634 not the parent's sibling — and the caixa-resolver folds the value through \
3635 `Path::join` looking for a literal `./{caminho}` subdirectory that fails at \
3636 resolve time with a non-self-locating `No such file or directory` error far \
3637 from the source caixa.lisp; Windows `std::path::Path` treats `\\` as a \
3638 primary path separator equal to `/`, so byte-identical caixa.lisp values \
3639 resolve to two distinct directories across runner OSes — the lacre pipeline \
3640 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3641 caixa-resolver/src/resolve.rs:189, defeating the THEORY.md §V.2 render-\
3642 determinism contract via the cross-host-OS-separator divergence vector. The \
3643 canonical Windows-Explorer `Copy as path` / PowerShell `Get-Location` \
3644 paste-idiom footgun; peer `:fonte :tag` / `:fonte :branch` axis already \
3645 rejects `\\` via `is_git_ref_name` for the same Windows-path-leak reason, \
3646 and `:entrada :paths` rejects `\\` via `is_gateway_api_http_path`'s eleven-\
3647 byte RFC-3986-reserved set. Express the path with `/` as the separator, e.g. \
3648 \"../caixa-teia\" for a sibling workspace dep)"
3649 )]
3650 FonteCaminhoBackslash { nome: String, caminho: String },
3651 #[error(
3652 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3653 redirection metacharacter 0x{byte:02x} `{ch}` (every interactive shell — bash / \
3654 zsh / fish / nushell — lexes `<` and `>` as input / output redirection \
3655 operators, so `:caminho \"../caixa-teia>build.log\"` is the canonical \
3656 paste-from-shell-pipeline footgun where an author copies a `command > log` \
3657 tail without trimming the redirect; POSIX `std::path::Path` treats both bytes \
3658 as literal path-component bytes, so the resolver folds the value through \
3659 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3660 subdirectory and fails at resolve time with a non-self-locating `No such \
3661 file or directory` error far from the source caixa.lisp. The lacre pipeline \
3662 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3663 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure \
3664 and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3665 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3666 canonical CRLF-at-subprocess-argument / shell-metachar injection surface every \
3667 peer single-token-shaped typed slot already closes. The peer `:fonte :tag` / \
3668 `:fonte :branch` axis already rejects `<` / `>` via `is_git_ref_name`, and \
3669 `:entrada :paths` rejects them via `is_gateway_api_http_path`'s eleven-byte \
3670 RFC-3986-reserved set. Express the path as a bare relative single-token like \
3671 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3672 redirection semantic.",
3673 ch = *byte as char
3674 )]
3675 FonteCaminhoShellRedirection {
3676 nome: String,
3677 caminho: String,
3678 byte: u8,
3679 },
3680 #[error(
3681 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-pipe \
3682 metacharacter `|` (every interactive shell — bash / zsh / fish / nushell — lexes \
3683 `|` as the pipe operator that wires one command's stdout to the next command's \
3684 stdin, so `:caminho \"../caixa-teia | grep foo\"` is the canonical paste-from-\
3685 shell-history footgun where an author copies a `ls ../caixa-teia | grep` line \
3686 without trimming the pipeline tail, and `:caminho \"../foo||bar\"` is the \
3687 symmetric `cmd-a || cmd-b` short-circuit-OR paste shape; POSIX `std::path::Path` \
3688 treats `|` as a literal path-component byte, so the resolver folds the value \
3689 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3690 subdirectory and fails at resolve time with a non-self-locating `No such file or \
3691 directory` error far from the source caixa.lisp. The lacre pipeline embeds the \
3692 value verbatim in its per-dep content-address `path:{caminho}` at caixa-resolver/\
3693 src/resolve.rs:189, so the byte lands in the BLAKE3 closure and rides into every \
3694 shell-spawned subprocess (the resolver's `git clone`, a future `feira tofu` \
3695 shell-out, a future operator-side `nix` spawn) as the canonical CRLF-at-\
3696 subprocess-argument / shell-metachar injection surface every peer single-token-\
3697 shaped typed slot already closes. The peer `:entrada :paths` axis rejects `|` \
3698 via `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3699 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3700 workspace directory name carries no shell-pipe semantic."
3701 )]
3702 FonteCaminhoShellPipe { nome: String, caminho: String },
3703 #[error(
3704 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3705 command-separator metacharacter `;` (every interactive shell — bash / zsh / fish \
3706 / nushell — lexes `;` as the sequential-command terminator that fires the next \
3707 command regardless of the prior command's exit status, so `:caminho \
3708 \"../caixa-teia; rm -rf build\"` is the canonical paste-from-shell-one-liner \
3709 footgun where an author copies a `cd path; do-thing` chain without trimming \
3710 the cleanup tail, and `:caminho \"../foo;;bar\"` is the symmetric POSIX `case` \
3711 arm `;;` terminator paste shape; POSIX `std::path::Path` treats `;` as a \
3712 literal path-component byte, so the resolver folds the value through \
3713 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3714 subdirectory and fails at resolve time with a non-self-locating `No such file \
3715 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3716 the value verbatim in its per-dep content-address `path:{caminho}` at \
3717 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3718 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3719 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3720 canonical shell-metachar injection surface every peer single-token-shaped \
3721 typed slot already closes. The peer `:entrada :paths` axis rejects `;` via \
3722 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3723 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3724 workspace directory name carries no shell-command-separator semantic."
3725 )]
3726 FonteCaminhoShellSemicolon { nome: String, caminho: String },
3727 #[error(
3728 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3729 background / list-AND metacharacter `&` (every interactive shell — bash / zsh \
3730 / fish / nushell — lexes `&` two ways: single `&` as the background-task \
3731 terminator detaching the prior command and returning control immediately to \
3732 the prompt, double `&&` as the logical-AND list operator firing the next \
3733 command only if the prior succeeded; POSIX `std::path::Path` treats it as a \
3734 literal byte. The canonical paste-from-shell-prompt footgun is a `cd path & \
3735 sleep 1` background-launch one-liner or a `cd path && make install` build-\
3736 chain idiom selected whole into the `:caminho` slot — the prior `;` arm at \
3737 05c358e closed the sequential-command-separator vector, this arm closes the \
3738 orthogonal background-task / logical-AND vector on the same paste-from-shell-\
3739 prompt class. The lacre pipeline embeds the value verbatim in its per-dep \
3740 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3741 byte lands in the BLAKE3 closure and rides into every shell-spawned \
3742 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3743 future operator-side `nix` spawn) as the canonical shell-metachar injection \
3744 surface every peer single-token-shaped typed slot already closes. The peer \
3745 `:entrada :paths` axis rejects `&` via `is_gateway_api_http_path`'s eleven-\
3746 byte RFC-3986-reserved set. Express the path as a bare relative single-token \
3747 like \"../caixa-teia\" — the sibling-workspace directory name carries no \
3748 shell-background / logical-AND semantic."
3749 )]
3750 FonteCaminhoShellBackground { nome: String, caminho: String },
3751 #[error(
3752 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3753 command-substitution metacharacter `` ` `` (every POSIX shell — sh / bash / zsh / \
3754 dash / ksh / fish / nushell — lexes the byte as the legacy command-substitution \
3755 wrapper that runs the enclosed command and substitutes its standard-output \
3756 verbatim into the surrounding word, so a backticked `whoami` expands to the \
3757 current user's name and a backticked `cat /etc/passwd` expands to the file's \
3758 contents — the canonical CWE-78 shell-command-injection vector; POSIX \
3759 `std::path::Path` treats the byte as a literal path-component byte. The canonical \
3760 paste-from-shell-prompt footgun is a `cd ../path/<backtick>whoami<backtick>` legacy substitution \
3761 one-liner or a `cd <backtick>pwd<backtick>/path` working-directory expansion idiom selected whole \
3762 into the `:caminho` slot — the prior `&` arm at e12e4f3 closed the shell-\
3763 background / logical-AND vector, this arm closes the orthogonal command-\
3764 substitution vector on the same paste-from-shell-prompt class (the modern `$()` \
3765 form is gated at leading position by the f4efe9c `FonteCaminhoVarExpansion` arm; \
3766 the legacy backtick form is the orthogonal axis). The lacre pipeline embeds the \
3767 value verbatim in its per-dep content-address `path:{caminho}` at \
3768 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3769 rides into every shell-spawned subprocess (the resolver's `git clone`, a future \
3770 `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3771 shell-metachar injection surface every peer single-token-shaped typed slot \
3772 already closes. The peer `:entrada :paths` axis rejects the byte via \
3773 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the path \
3774 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3775 directory name carries no shell-command-substitution semantic."
3776 )]
3777 FonteCaminhoShellCommandSubstitution { nome: String, caminho: String },
3778 #[error(
3779 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3780 glob / pathname-expansion metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — \
3781 sh / bash / zsh / dash / ksh / fish / nushell — lexes `*` and `?` as pathname-\
3782 expansion wildcards: `*` matches any sequence of characters in a path component \
3783 and `?` matches exactly one character, so a `:caminho \"../caixa-teia/*\"` is the \
3784 canonical paste-from-shell-listing footgun where an author copies a \
3785 `ls ../caixa-teia/*` listing without trimming the wildcard, and `:caminho \
3786 \"../foo?\"` is the symmetric single-char-wildcard paste shape; POSIX \
3787 `std::path::Path` treats both bytes as literal path-component bytes, so the \
3788 resolver folds the value through `Path::new(caminho).join(<file>)` looking for \
3789 a literal `./{caminho}` subdirectory and fails at resolve time with a non-self-\
3790 locating `No such file or directory` error far from the source caixa.lisp. The \
3791 lacre pipeline embeds the value verbatim in its per-dep content-address \
3792 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the \
3793 BLAKE3 closure and rides into every shell-spawned subprocess (the resolver's \
3794 `git clone`, a future `feira tofu` shell-out, a future operator-side `nix` \
3795 spawn) as the canonical shell-metachar / glob-expansion surface every peer \
3796 single-token-shaped typed slot already closes. The peer `:entrada :paths` axis \
3797 rejects `*` and `?` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-\
3798 reserved set. Express the path as a bare relative single-token like \
3799 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-glob \
3800 / pathname-expansion semantic.",
3801 ch = *byte as char
3802 )]
3803 FonteCaminhoShellGlob {
3804 nome: String,
3805 caminho: String,
3806 byte: u8,
3807 },
3808 #[error(
3809 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3810 subshell-grouping metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / \
3811 zsh / dash / ksh / fish / nushell — lexes `(` and `)` as the subshell-grouping \
3812 operator: `(<cmd>)` runs `<cmd>` in a child shell with a fresh environment scope \
3813 (the canonical `(cd <path> && <cmd>)` shell-history one-liner scopes a `cd` to one \
3814 subshell without disturbing the parent's working directory), and `$(<cmd>)` is the \
3815 modern Bourne command-substitution shape the leading-`$` `FonteCaminhoVarExpansion` \
3816 arm closes the leading byte of — together the two arms now structurally exclude the \
3817 entire `$(<cmd>)` substitution surface from the typed `:caminho` accepted set. \
3818 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3819 `:caminho \"../caixa-teia/$(date)/build\"` (the canonical paste-from-shell-history \
3820 modern-command-substitution footgun) or `:caminho \"../(cd foo && pwd)/caixa-teia\"` \
3821 (the symmetric subshell-grouping working-directory-probe paste idiom) silently passes \
3822 every prior arm and the resolver folds the value through `Path::new(caminho).join(\
3823 <file>)` looking for a literal subdirectory and fails at resolve time with a non-\
3824 self-locating `No such file or directory` error far from the source caixa.lisp. The \
3825 lacre pipeline embeds the value verbatim in its per-dep content-address `path:\
3826 {caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 \
3827 closure and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3828 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3829 shell-metachar / subshell-grouping surface every peer single-token-shaped typed slot \
3830 already closes. The peer `:fonte :repo` axis (3b99147) closes the same byte under the \
3831 same shell-subshell-grouping / RFC-3986-sub-delims banner on `is_git_repo_url`, \
3832 together with the leading-`$` `FonteCaminhoVarExpansion` arm closing the leading byte \
3833 of every `$(<cmd>)` shape. Express the path as a bare relative single-token \
3834 like \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3835 subshell-grouping semantic.",
3836 ch = *byte as char
3837 )]
3838 FonteCaminhoShellSubshellGrouping {
3839 nome: String,
3840 caminho: String,
3841 byte: u8,
3842 },
3843 #[error(
3844 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3845 brace-expansion / URI-Template placeholder metacharacter 0x{byte:02x} `{ch}` \
3846 (every POSIX-derived brace-expanding shell — bash / zsh / ksh / fish — lexes `{{` / \
3847 `}}` as the brace-expansion operator: `{{a,b,c}}` expands to the cross-product of \
3848 comma-separated members and `{{1..10}}` expands to the integer range — the \
3849 canonical `mkdir -p ../{{caixa-teia,caixa-helm,caixa-flux}}` / `cp file{{,.bak}}` \
3850 idiom every shell-history block carries; RFC 6570 reserves the matched pair for \
3851 URI Template placeholders (the canonical `https://{{host}}/{{org}}/{{repo}}` \
3852 substitution shape every OpenAPI / Swagger / Postman / GitHub Octokit client \
3853 library / Helm chart-URL fragment carries) and the Mustache / Handlebars / \
3854 Tera / Jinja2 / Go html/template doubled-brace substitution form every IaC \
3855 templating engine (Helm, Kustomize, Terraform's `${{var}}` cousin) emits. POSIX \
3856 `std::path::Path` treats the byte as a literal path-component byte, so a \
3857 `:caminho \"../{{caixa-teia,caixa-helm}}/build\"` (the canonical paste-from-\
3858 shell-history brace-expansion fan-across-siblings footgun) or `:caminho \"../{{{{org}}}}/\
3859 caixa-teia\"` (the symmetric paste-from-templated-doc URI-Template placeholder \
3860 idiom every README quick-start / OpenAPI spec / Helm chart `home:` field carries) \
3861 silently passes every prior arm and the resolver folds the value through \
3862 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3863 resolve time with a non-self-locating `No such file or directory` error far from \
3864 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its \
3865 per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
3866 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
3867 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3868 future operator-side `nix` spawn) as the canonical shell-metachar / brace-\
3869 expansion / URI-Template-placeholder surface every peer single-token-shaped \
3870 typed slot already closes. The peer `:fonte :repo` axis (42d8f9d) closes the \
3871 same byte pair on `is_git_repo_url` under the same RFC-3986-'delims' / \
3872 RFC-6570-URI-Template / shell-brace-expansion banner. Express the path as a \
3873 bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3874 directory name carries no shell-brace-expansion / URI-Template-placeholder \
3875 semantic; if two siblings actually need pinning, author two separate `:deps` \
3876 entries rather than one brace-expanded `:caminho` value.",
3877 ch = *byte as char
3878 )]
3879 FonteCaminhoShellBraceExpansion {
3880 nome: String,
3881 caminho: String,
3882 byte: u8,
3883 },
3884 #[error(
3885 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3886 bracket-expansion / POSIX glob-character-class / shell-`test`-builtin metacharacter \
3887 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / nushell \
3888 — lexes the bracket pair as the glob character-class operator: `[abc]` matches one of \
3889 `a` / `b` / `c`, `[a-z]` matches any lowercase ASCII letter, `[^x]` negates — the \
3890 canonical `ls *.[ch]` C-source-file glob and `cd ../caixa-[a-z]*` lowercase-sibling \
3891 glob every shell-history block carries; the bracket pair additionally carries the \
3892 POSIX `test` / `[` builtin command (`[ -d ../caixa-teia ] && cd ...` every shell-\
3893 script conditional uses) and bash's `[[ ... ]]` extended-test grammar; beyond shell \
3894 the pair is the TOML inline-array delimiter (`features = [\"a\", \"b\"]` — the \
3895 canonical paste-from-Cargo-manifest cross-idiom-leak vector), the YAML flow-sequence \
3896 delimiter (`paths: [/a, /b]` — the canonical paste-from-values.yaml cross-idiom \
3897 leak), the JSON array delimiter, and the POSIX-ERE / PCRE bracket-expression anchor. \
3898 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3899 `:caminho \"../caixa-[a-z]/build\"` (the canonical paste-from-shell-history glob-\
3900 character-class fan-across-siblings footgun) or `:caminho \"../[caixa-teia]/build\"` \
3901 (the symmetric paste-from-TOML-array / paste-from-YAML-flow-sequence cross-idiom \
3902 leak) silently passes every prior arm and the resolver folds the value through \
3903 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3904 resolve time with a non-self-locating `No such file or directory` error far from \
3905 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3906 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3907 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3908 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3909 `nix` spawn) as the canonical shell-metachar / glob-character-class / TOML-array \
3910 surface every peer single-token-shaped typed slot already closes. Express the path \
3911 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3912 directory name carries no shell-bracket-expansion / glob-character-class / array-\
3913 literal semantic; if a family of sibling caixas actually needs pinning, author \
3914 separate `:deps` entries rather than one character-class-expanded `:caminho` value.",
3915 ch = *byte as char
3916 )]
3917 FonteCaminhoShellBracketExpansion {
3918 nome: String,
3919 caminho: String,
3920 byte: u8,
3921 },
3922 #[error(
3923 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3924 quote-grouping / cross-config-DSL string-literal-delimiter metacharacter \
3925 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3926 nushell — lexes `'` as the strong string-literal delimiter (`'…'` — no expansion) \
3927 and `\"` as the weak string-literal delimiter (`\"…\"` — variable- / command-\
3928 substitution-preserving); the canonical `cd '../caixa-teia'` shell-history idiom \
3929 every path-with-embedded-whitespace paste block carries and the symmetric \
3930 `git clone \"$REPO\"` weak-quoted CI-manifest shape both leak the pair verbatim. \
3931 Beyond shell the pair is the JSON string-literal delimiter (`\"key\": \"value\"` — \
3932 the canonical paste-from-JSON-config cross-idiom-leak vector), the YAML double- \
3933 and single-quoted flow-scalar delimiter (`path: \"../caixa-teia\"` — the canonical \
3934 paste-from-values.yaml / paste-from-K8s-YAML-manifest cross-idiom leak), the TOML \
3935 basic and literal string delimiter (`path = \"../caixa-teia\"` — the canonical \
3936 paste-from-Cargo-manifest cross-idiom leak), the tatara-lisp string-literal \
3937 delimiter itself (`(:caminho \"../caixa-teia\")` — the canonical \"I copied the \
3938 entire `:caminho \"...\"` slot rather than just the string body\" author-surface \
3939 footgun), and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which excludes \
3940 both bytes from the `pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"` \
3941 production. POSIX `std::path::Path` treats the byte as a literal path-component \
3942 byte, so a `:caminho \"'../caixa-teia'\"` (the canonical paste-from-shell-history \
3943 strong-quoted sibling-workspace path footgun) or `:caminho \"\\\"../caixa-teia\\\"\"` \
3944 (the symmetric weak-quoted paste-from-JSON / paste-from-YAML flow-scalar / paste-\
3945 from-TOML basic-string / paste-from-tatara-lisp string-literal cross-idiom-leak \
3946 shape) silently passes every prior arm and the resolver folds the value through \
3947 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3948 resolve time with a non-self-locating `No such file or directory` error far from \
3949 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3950 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3951 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3952 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3953 `nix` spawn) as the canonical shell-metachar / string-literal-delimiter surface \
3954 every peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
3955 axis closes both bytes under the same shell-quote-grouping / RFC-3986-sub-delims \
3956 banner (e7a109f `'` shell-single-quote + 4267d8b `\"` shell-double-quote on \
3957 `is_git_repo_url`). Express the path as a bare relative single-token like \
3958 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-quote-\
3959 grouping / string-literal-delimiter semantic; strip the outer quote pair from the \
3960 paste (the tatara-lisp `:caminho \"...\"` slot already carries the string-literal \
3961 quoting on the outer syntactic layer, so an inner quote pair would nest and \
3962 desugar to a broken layer).",
3963 ch = *byte as char
3964 )]
3965 FonteCaminhoShellQuoteGrouping {
3966 nome: String,
3967 caminho: String,
3968 byte: u8,
3969 },
3970 #[error(
3971 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3972 comment / URL-fragment-identifier / YAML-comment cross-config-DSL metacharacter \
3973 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3974 nushell — lexes an unquoted `#` at the head of a word or after unquoted \
3975 whitespace as the comment-lead per POSIX.1-2017 §2.3 Token Recognition step 6, \
3976 discarding the byte and everything after it to the end of the physical line \
3977 before command parsing (`cd ../caixa-teia # legacy sibling` — the canonical \
3978 paste-from-shell-history-with-trailing-annotation shape every operator-notebook \
3979 and CI-manifest carries); YAML 1.2 §6.6 makes `#` the comment-lead at any \
3980 position preceded by whitespace or at line-start (`path: ../caixa-teia # pin` \
3981 — the canonical paste-from-values.yaml / paste-from-K8s-manifest cross-idiom-\
3982 leak); RFC 3986 §3.5 reserves `#` as the URL fragment-identifier delimiter (the \
3983 canonical paste-from-browser-address-bar `github.com/foo/bar#readme` / \
3984 `github.com/foo/bar#L42` permalink shape, and the symmetric Nix-flake-ref \
3985 cross-idiom leak `github:foo/bar#packageName` where `#` selects a flake \
3986 output); the same cross-config-DSL surface extends to HCL / Terraform / Nix \
3987 flake attributes / dotenv `.env` / gitconfig / .gitignore / ini / TOML where \
3988 `#` is likewise the comment-lead. POSIX `std::path::Path` treats the byte as a \
3989 literal path-component byte, so a `:caminho \"../caixa-teia # legacy sibling\"` \
3990 (the canonical paste-from-shell-history-with-trailing-annotation footgun), \
3991 `:caminho \"../caixa-teia # pin\"` (the symmetric YAML flow-scalar paste-with-\
3992 trailing-comment shape), or `:caminho \"../caixa-teia#readme\"` (the URL \
3993 fragment paste-from-browser-address-bar shape) silently passes every prior arm \
3994 and the resolver folds the value through `Path::new(caminho).join(<file>)` \
3995 looking for a literal subdirectory named `../caixa-teia # legacy sibling` and \
3996 fails at resolve time with a non-self-locating `No such file or directory` \
3997 error far from the source caixa.lisp — while every downstream shell / YAML / \
3998 URL parser silently truncates the value at the `#` byte to `../caixa-teia`, so \
3999 a `feira tofu` shell-out and a `nix flake check` on an emitted YAML `path:` \
4000 scalar disagree with the resolver on which directory the value names. The \
4001 lacre pipeline embeds the value verbatim in its per-dep content-address \
4002 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in \
4003 the BLAKE3 closure and rides into every shell-spawned subprocess (the \
4004 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-\
4005 side `nix` spawn) as the canonical shell-metachar / comment-lead / URL-\
4006 fragment-delimiter surface every peer single-token-shaped typed slot already \
4007 closes. The peer `:fonte :repo` axis closes the byte under the same URL-\
4008 fragment-identifier banner (a68f818 `#` on `is_git_repo_url`). Express the \
4009 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
4010 workspace directory name carries no shell-comment / URL-fragment / YAML-\
4011 comment semantic; move any trailing annotation to a tatara-lisp `;`-comment \
4012 on the surrounding form (`;; legacy sibling` above the `(:caminho ...)` slot) \
4013 and drop any `#fragment` tail entirely (fragment identifiers select \
4014 renderings, not directories, and `:caminho` names a directory).",
4015 ch = *byte as char
4016 )]
4017 FonteCaminhoShellComment {
4018 nome: String,
4019 caminho: String,
4020 byte: u8,
4021 },
4022 #[error(
4023 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains URL-\
4024 percent-encoding-escape / printf-format-specifier / bash-job-control-specifier \
4025 / YAML-directive-lead metacharacter 0x{byte:02x} `{ch}` (RFC 3986 §2.1 reserves \
4026 `%` as the URL percent-encoding-escape — `%HH` is the mandatory encoding \
4027 mechanism for every byte outside the `unreserved` alphanumeric / `-` / `.` / \
4028 `_` / `~` set, and `%` itself must be percent-encoded as `%25` to appear \
4029 literally inside a URL value. The canonical paste-from-browser-address-bar \
4030 percent-encoded-space footgun (an author copies `../caixa%20teia` out of a URL-\
4031 encoded README hyperlink / browser address bar / percent-encoded permalink \
4032 expecting `%20` to decode to a literal space at the filesystem layer) locks two \
4033 distinct BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`) for \
4034 what the author intended as the byte-identical sibling-workspace dep. POSIX \
4035 `std::path::Path` treats the byte as a literal path-component byte, so \
4036 `Path::join` looks for a literal `./{caminho}` subdirectory and fails at \
4037 resolve time with a non-self-locating `No such file or directory` error far \
4038 from the source caixa.lisp — while every downstream URL parser / shell printf \
4039 builtin / YAML directive parser silently reinterprets the byte to a different \
4040 value than the resolver's `Path::join` sees. Beyond the URL-encoding hazard, \
4041 `%` is the C / POSIX printf format-directive lead-in (`%s`, `%d`, `%02x` — \
4042 wired into every POSIX shell's `printf` builtin, the canonical CWE-134 format-\
4043 string-injection vector); the bash / zsh / ksh job-control-specifier lead-in \
4044 (`%1` names \"job 1\", `%%` names \"the current job\", `%foo` names \"the most \
4045 recent job whose command started with `foo`\" — a future `kill %1` invocation \
4046 silently redirects the signal to a wrong target); the YAML 1.2 §6.8.1 \
4047 directive lead-in (`%YAML 1.2` / `%TAG` — the paste-from-top-of-doc YAML \
4048 directive block cross-idiom leak); and the Windows-shell env-var-reference \
4049 lead-in (`%PATH%` — the paste-from-`.bat` / paste-from-PowerShell-`%env:PATH%` \
4050 cross-idiom leak). The lacre pipeline embeds the value verbatim in its per-dep \
4051 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
4052 byte lands in the BLAKE3 closure and rides into every shell-spawned subprocess \
4053 (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4054 operator-side `nix` spawn) as the canonical URL-percent-encoding-escape / \
4055 printf-format-specifier / job-control-specifier surface every peer single-\
4056 token-shaped typed slot already closes. The peer `:fonte :repo` axis closes \
4057 the byte under the same URL-percent-encoding-escape banner (a323db8 `%` on \
4058 `is_git_repo_url`). Express the path as a bare relative single-token like \
4059 \"../caixa-teia\" — the sibling-workspace directory name carries no URL-\
4060 percent-encoding-escape / format-specifier / job-control semantic; substitute \
4061 any `%20` percent-encoded-space with a literal space then reject the whole \
4062 value at the leading-whitespace / embedded-`?` arm on the same axis (a caixa \
4063 directory name never carries an embedded space in practice); drop any \
4064 `%2F`-encoded path separator in favor of a literal `/`; and drop any leading \
4065 `%YAML` / `%PATH%` cross-idiom-leak prefix entirely.",
4066 ch = *byte as char
4067 )]
4068 FonteCaminhoUrlPercentEncoding {
4069 nome: String,
4070 caminho: String,
4071 byte: u8,
4072 },
4073 #[error(
4074 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4075 variable-expansion / command-substitution / arithmetic-expansion / cross-config-\
4076 DSL-interpolation metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / \
4077 bash / zsh / dash / ksh / busybox ash / fish / nushell — lexes `$` per \
4078 POSIX.1-2017 §2.6 as the variable-expansion `$<name>` / braced-form `${{<name>}}` \
4079 / command-substitution `$(<cmd>)` / arithmetic-expansion `$((<expr>))` operator; \
4080 Nix uses `${{var}}` as the string-interpolation lead, Make uses `$(var)` / `$@` \
4081 / `$<` for variables and automatic-variables, JavaScript / TypeScript template \
4082 literals use `${{expr}}` for interpolation, envsubst / Kubernetes / OpenShift \
4083 templates use `${{VAR}}` for env-var-reference, PHP uses `$_GET` / `$_ENV` for \
4084 superglobals, Perl uses `$foo` for scalars, SASS / SCSS uses `$primary-color` \
4085 for variables, and PostgreSQL / SQLite use `$1` / `$2` for bind parameters — \
4086 the byte is a first-class parser byte in nearly every config / templating / \
4087 build-system DSL the substrate's paste-idiom surface routinely crosses. POSIX \
4088 `std::path::Path` treats the byte as a literal path-component byte, so the \
4089 canonical paste-from-shell-one-liner `:caminho \"../foo$HOME/bar\"` / paste-\
4090 from-CI-manifest `:caminho \"../foo${{WORKSPACE}}/bar\"` / paste-from-shell-\
4091 prompt `:caminho \"../foo$(whoami)/bar\"` footguns silently pass every prior \
4092 cascade arm (`$` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / \
4093 `?` / `(` / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%`) and route \
4094 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4095 subdirectory that fails at resolve time with a non-self-locating `No such file \
4096 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4097 the value verbatim in its per-dep content-address `path:{caminho}` at \
4098 caixa-resolver/src/resolve.rs:189, so byte-identical caixa.lisp values differing \
4099 only in whether the author substituted `$HOME` / `${{WORKSPACE}}` at author \
4100 time lock to two distinct BLAKE3 closures across two workstations whose \
4101 downstream envsubst / Nix / Make / K8s-template layers differ in `$VAR` \
4102 recognition — defeating the THEORY.md §V.2 render-determinism contract on the \
4103 same axis every prior `:caminho` arm protects. Beyond the determinism vector, \
4104 `$` at any position in a value flowing verbatim into a shell-spawned subprocess \
4105 is the canonical CWE-78 shell-command-injection surface every peer single-\
4106 token-shaped typed slot already closes: peer `:fonte :repo` axis rejects `$` \
4107 under the shell-variable-expansion / URL-sub-delim banner via `is_git_repo_url` \
4108 (b9d187c), peer `:fonte :tag` / `:fonte :branch` axes reject `$` as part of \
4109 `is_git_ref_name`'s printable-ASCII-restricted grammar (`git check-ref-format` \
4110 rejects the byte outright), and peer `:entrada :paths` axis rejects `$` via \
4111 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. The leading-`$` \
4112 position on the same axis routes through `FonteCaminhoVarExpansion` at the \
4113 f4efe9c leading-byte arm; this arm closes the last positional gap on the byte \
4114 so every position — leading and embedded — is structurally rejected. Substitute \
4115 the `$VAR` / `${{VAR}}` / `$(cmd)` template with the literal value at author \
4116 time, or express the path as a bare relative single-token like \
4117 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
4118 variable-expansion / command-substitution / arithmetic-expansion semantic.",
4119 ch = *byte as char
4120 )]
4121 FonteCaminhoShellVariableExpansion {
4122 nome: String,
4123 caminho: String,
4124 byte: u8,
4125 },
4126 #[error(
4127 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4128 history-expansion / RFC-3986-sub-delims / bang-operator metacharacter 0x{byte:02x} \
4129 `{ch}` (every interactive POSIX shell with history enabled — bash / ksh / zsh's \
4130 `bashcompat` / csh / tcsh — lexes `!` as the history-expansion prefix per bash \
4131 reference §9.3: `!command` re-runs the most recent history entry beginning with \
4132 `command`, `!!` re-runs the prior command verbatim, `!$` substitutes the last \
4133 word of the prior command, `!:N` substitutes the Nth word of the prior command, \
4134 and the substitution fires at every history-expansion-enabled shell context — \
4135 `set -o histexpand` is bash's default for interactive sessions and the layer \
4136 every `feira tofu` / `git clone` / `nix flake check` subprocess-argument \
4137 invocation crosses when spawned under `bash -i`. Beyond shell history, RFC 3986 \
4138 §2.2 lists `!` in the `sub-delims` set (the URL grammar admits the byte inside \
4139 a path segment, but every WHATWG-conformant special-scheme URL parser percent-\
4140 encodes it inside a query component via the 'special-query percent-encode set' \
4141 the peer `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte is \
4142 also the C / C++ / Rust / JavaScript / Python bang-operator (logical-negation \
4143 prefix — the paste-from-source-code idiom where an author copies \
4144 `!path.exists()` out of a Rust snippet and the trailing punctuation crosses \
4145 the string-literal boundary); the canonical English-typography emphasis / \
4146 exclamation mark (the paste-from-prose enthusiasm-form idiom where an author \
4147 writes `:caminho \"../caixa-teia!\"` expecting the substrate to coerce it to a \
4148 kebab-case slug); and the Nix flake-ref attribute-selection operator surface. \
4149 POSIX `std::path::Path` treats `!` as a literal path-component byte, so the \
4150 canonical paste-from-shell-history footgun `:caminho \"../caixa-teia!sudo\"` \
4151 (an author copies a `cd ../caixa-teia && !sudo make install` one-liner from a \
4152 quick-start README and the trailing `!sudo` rides in verbatim as a history-\
4153 expansion reference), the symmetric `:caminho \"../foo!!/bar\"` (the `!!` \
4154 repeat-prior-command paste idiom), the English-typography `:caminho \
4155 \"../caixa-teia!\"` (paste-from-prose enthusiasm-form), and the last-word-\
4156 substitution `:caminho \"../foo!$\"` shape silently pass every prior cascade \
4157 arm (`!` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` \
4158 / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$`) and route \
4159 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4160 subdirectory that fails at resolve time with a non-self-locating `No such file \
4161 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4162 the value verbatim in its per-dep content-address `path:{caminho}` at \
4163 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
4164 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
4165 future `feira tofu` shell-out, a future operator-side `nix flake check` spawn) \
4166 as the canonical shell-history-expansion / RFC-3986-sub-delims surface every \
4167 peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4168 axis closes the byte under the same shell-history-expansion / RFC-3986-sub-\
4169 delims banner (7d53c68 `!` on `is_git_repo_url`). Express the path as a bare \
4170 relative single-token like \"../caixa-teia\" — the sibling-workspace directory \
4171 name carries no shell-history-expansion / bang-operator semantic; drop any \
4172 `!sudo` / `!!` / `!$` history-expansion trailing paste-from-shell-history \
4173 idiom; and drop any trailing English-typography exclamation mark that pasted \
4174 from prose.",
4175 ch = *byte as char
4176 )]
4177 FonteCaminhoShellHistoryExpansion {
4178 nome: String,
4179 caminho: String,
4180 byte: u8,
4181 },
4182 #[error(
4183 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4184 history-substitution / RFC-3986-'unwise' / regex-negation metacharacter 0x{byte:02x} \
4185 `{ch}` (POSIX bash's `set -o histexpand` mode — the default for every interactive \
4186 session and every `bash -i` subprocess-argument context `feira tofu` / `git clone` / \
4187 `nix flake check` cross — lexes `^old^new^` per bash reference §9.3 as the 'quick \
4188 substitution' history operator that rewrites the prior command's `old` string to \
4189 `new` and re-executes it verbatim, the canonical typo-correction one-liner idiom \
4190 (`git clone <bad-url>` → `^bad^good` typo-fix-and-rerun the paste-from-shell-\
4191 history author trims only the leading `git clone` prefix from). RFC 3986 §2 lists \
4192 `^` in the 'unwise' set every URL parser is required to percent-encode-or-refuse at \
4193 the wire boundary, and the WHATWG URL spec's 'fragment percent-encode set' maps \
4194 `^` → `%5E` at the query / fragment component transition, so `Path::join` on the \
4195 literal value diverges from every downstream `feira tofu` curl-invocation / \
4196 artifact-registry-fetch that percent-encodes the byte before the wire. `^` is also \
4197 the regex character-class negation prefix (`[^abc]`), the bitwise XOR operator in \
4198 C / C++ / Rust / Python / JavaScript / Nix / Go, the Windows `cmd.exe` escape \
4199 metacharacter, and the LaTeX / Markdown / BibTeX superscript operator. POSIX \
4200 `std::path::Path` treats `^` as a literal path-component byte, so \
4201 `:caminho \"../foo^bar/baz\"` (embedded quick-substitution), `:caminho \
4202 \"../foo^\"` (trailing history-substitution-open shape), or `:caminho \"../x^y\"` \
4203 (XOR-expression paste-from-source) silently pass every prior cascade arm (`^` \
4204 isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` / `)` / `{{` \
4205 / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$` / `!`) and route through \
4206 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` subdirectory \
4207 that fails at resolve time with a non-self-locating `No such file or directory` \
4208 error far from the source caixa.lisp. The lacre pipeline embeds the value verbatim \
4209 in its per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
4210 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
4211 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4212 operator-side `nix flake check` spawn) as the canonical shell-history-substitution \
4213 / RFC-3986-unwise surface every peer single-token-shaped typed slot already closes. \
4214 The peer `:fonte :repo` axis closes the byte under the same shell-history-\
4215 substitution / RFC-3986-unwise banner (49e142f `^` on `is_git_repo_url`). Together \
4216 with the immediate-predecessor `!` arm (6a04767) this arm closes the full `set -o \
4217 histexpand` operator surface on the `:caminho` axis — the `!command` / `!!` / `!$` \
4218 prefix form via `!`, the `^old^new^` quick-substitution form via `^`. Express the \
4219 path as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
4220 directory name carries no shell-history-substitution / regex-negation / XOR-operator \
4221 semantic; drop any `^old^new` history-substitution paste-from-shell-history idiom; \
4222 drop any trailing `^` history-substitution-open fragment.",
4223 ch = *byte as char
4224 )]
4225 FonteCaminhoShellHistorySubstitution {
4226 nome: String,
4227 caminho: String,
4228 byte: u8,
4229 },
4230 #[error(
4231 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} has a trailing \
4232 `/` (the resolver's `Path::join` resolves `\"../caixa-teia\"` and \
4233 `\"../caixa-teia/\"` to the same directory, but the lacre pipeline embeds the \
4234 value verbatim in its per-dep content-address `path:{caminho}` at \
4235 caixa-resolver/src/resolve.rs:189, so two authors whose only difference is \
4236 shell tab-completion emit byte-divergent BLAKE3 closures for the same caixa — \
4237 defeating the THEORY.md §V.2 render-determinism contract via the trailing-\
4238 separator vector (the canonical paste-from-shell-tab-completion + paste-from-\
4239 `pwd`-with-`/`-suffix footgun, and the canonical Cargo-style `path = \
4240 \"../caixa-teia/\"` paste-from-Cargo-manifest cross-idiom leak). Drop the \
4241 trailing `/`; every `:caminho` value names a sibling-workspace directory \
4242 already, so the trailing separator carries no information. Use \
4243 `\"../caixa-teia\"` rather than `\"../caixa-teia/\"`)"
4244 )]
4245 FonteCaminhoTrailingSlash { nome: String, caminho: String },
4246 #[error(
4247 "{list} carries duplicate entry :nome {nome:?} — every dep list keys its \
4248 entries by caixa name (Cargo's [dependencies] / [dev-dependencies] tables \
4249 apply the same set-not-multiset discipline; one package per table), and \
4250 two entries naming the same caixa carry two version constraints / source \
4251 pins / feature sets for one identity. The caixa-resolver's lacre pipeline \
4252 consumes the list as a `HashMap`-keyed-by-`:nome` lookup: the second entry \
4253 silently overwrites the first at the resolver-side `concrete_versao` step, \
4254 and the dropped entry's pin / features never reach the closure — far from \
4255 the source caixa.lisp, with no field naming which `:deps` entry was the \
4256 silent loser. If two version constraints are genuinely needed (the rare \
4257 multi-version closure case the lacre pipeline doesn't yet support), the \
4258 author surface is two distinct caixa names (e.g. a `caixa-teia-v01` / \
4259 `caixa-teia-v02` aliased pair); within one list, one entry per caixa name."
4260 )]
4261 DuplicateNome { nome: String, list: &'static str },
4262 #[error(
4263 ":deps entry {nome:?} has empty :caracteristicas entry — every feature flag must \
4264 name a non-empty identifier on the target caixa (Cargo's [dependencies.<dep>.features] \
4265 applies the same per-entry non-empty discipline). An empty feature flag reaches the \
4266 caixa-resolver's lacre pipeline as a no-op feature enable, silently dropping the \
4267 author's intent far from the source caixa.lisp; drop the empty entry, or replace it \
4268 with the canonical kebab-case feature name the target caixa declares."
4269 )]
4270 CaracteristicaEmpty { nome: String },
4271 #[error(
4272 ":deps entry {nome:?} :caracteristicas entry {caracteristica:?} is not a valid Cargo \
4273 feature name: {reason} (the value flows verbatim into Cargo's \
4274 [dependencies.<dep>.features] list and Cargo's `restricted_names::validate_feature_name` \
4275 parser enforces the same shape at `cargo metadata` time; use a single-token \
4276 identifier like `\"http\"`, `\"derive\"`, or `\"runtime-tokio\"` — kebab-case ASCII \
4277 alphanumeric with `-`, `_`, `+`, or `.` as continuation characters, starting with \
4278 an ASCII alphanumeric or `_`)"
4279 )]
4280 CaracteristicaInvalid {
4281 nome: String,
4282 caracteristica: String,
4283 reason: String,
4284 },
4285 #[error(
4286 ":deps entry {nome:?} :caracteristicas carries duplicate feature {caracteristica:?} — \
4287 every feature-flag list keys its entries by name (Cargo's \
4288 [dependencies.<dep>.features] applies the same set-not-multiset discipline; one entry \
4289 per feature per dep), and two entries naming the same feature are a redundant \
4290 set-membership declaration for one identity (the feature-toggle slot is set-shaped; \
4291 enabling a feature twice has no additional semantic). The caixa-resolver's lacre \
4292 pipeline consumes the list as a set-shaped feature toggle — the resolver enables the \
4293 feature once regardless of declaration count, so the duplicate's pin / position never \
4294 reaches the closure with no field naming the silent loser. One entry per feature per \
4295 dep; if two distinct features are intended, name each verbatim."
4296 )]
4297 CaracteristicaDuplicate {
4298 nome: String,
4299 caracteristica: String,
4300 },
4301 #[error(
4302 "{list} entry :nome {nome:?} names the caixa itself — a caixa cannot depend \
4303 on itself (the lacre closure's dep-graph traversal is rooted at the caixa's \
4304 :nome, and a self-dep would be a one-node cycle the caixa-resolver either \
4305 rejects mid-traversal far from the source caixa.lisp or recurses on until \
4306 it exhausts its stack). Every :nome is globally-unique substrate identity, \
4307 so a :deps / :deps-dev entry whose :nome equals the parent caixa's :nome \
4308 *is* the parent itself, not a coincidentally-named peer. Drop the \
4309 self-referential dep entry — to reference code from this caixa, use \
4310 :bibliotecas / :exe / :servicos (the substrate-blessed shape for \
4311 referencing the caixa's own code surface) instead."
4312 )]
4313 DepIsSelf { nome: String, list: &'static str },
4314}
4315
4316// Fold the eleven `DepError::FonteCaminho<Variant> { nome: nome.to_string(),
4317// caminho: caminho.to_string() }` two-slot struct-variant wire-up sites at
4318// [`DepSource::validate_caminho`] onto one substrate primitive per typed
4319// variant — the paired `{ nome: String, caminho: String }` two-slot family
4320// on [`DepError`], sibling of the peer
4321// [`crate::supervisor::supervisor_caixa_only_ctors!`] (db09650, 3 variants
4322// on `{ caixa: String }`) on the `SupervisorError` envelope, the peer
4323// [`crate::aplicacao::contrato_empty_pair_ctors!`] (8580068, 4 variants on
4324// `{ de, para }`), [`crate::aplicacao::aplicacao_field_reason_ctors!`]
4325// (981060b, 7 variants on `{ <field>: String, reason: String }`),
4326// [`crate::aplicacao::contrato_target_ctors!`] (14b81d5, 2 variants on
4327// `{ de, para, wit, expected }`), and
4328// [`crate::aplicacao::contrato_pair_value_reason_ctors!`] (14e13f1, 3
4329// variants on `{ de, para, <field>: String, reason: String }`) on the
4330// `AplicacaoError` envelopes, the peer
4331// [`crate::layout::layout_violation_ctors!`] (131ca0d, 16 variants on
4332// `{ caixa, issue }`), [`crate::layout::layout_slot_kind_ctors!`]
4333// (0419438, 4 variants on `{ caixa, kind, slots }`),
4334// [`crate::LayoutError::missing_entry`] (1b09f9d, one variant on
4335// `{ kind, path }`), and [`crate::layout::layout_nome_only_ctors!`]
4336// (3fe3dd7, 6 variants on `<Variant>(String)`) on the `LayoutError`
4337// envelopes, the peer three [`crate::limits::limits_codec_value_*_ctors!`]
4338// codec-family macros (81c856c, 12 wire-ups) on the `LimitsError`
4339// envelope, and the peer [`crate::upgrade::upgrade_from_script_ctors!`]
4340// (8e67041, 3 variants on `{ from: String, script: PathBuf }`) on the
4341// `UpgradeError` envelope. First fold family on this `DepError` envelope.
4342//
4343// Each of the eleven wire-up sites on this shape (the leading-byte cascade
4344// closing the seven `FonteCaminho{Absolute, TildeExpansion, VarExpansion,
4345// LeadingWhitespace, LeadingHyphen}` arms; the orthogonal single-metachar
4346// cascade closing `FonteCaminhoBackslash` on `\`; the shell-lexer-metachar
4347// cascade closing `FonteCaminhoShell{Pipe, Semicolon, Background,
4348// CommandSubstitution}` on the four single-byte shell operators; and the
4349// trailing-`/` reproducibility arm closing `FonteCaminhoTrailingSlash`)
4350// opened the identical `DepError::FonteCaminho<Variant> { nome:
4351// nome.to_string(), caminho: caminho.to_string() }` four-line
4352// struct-literal against the same `(nome: &str, caminho: &str)` local pair
4353// — the exact "same block re-inlined at every consumer" shape the PRIME
4354// DIRECTIVE names as a bug, on the same altitude the peer `LayoutError` /
4355// `AplicacaoError` / `SupervisorError` / `LimitsError` / `UpgradeError`
4356// families each closed on their sibling envelopes. The eleven variants
4357// share one `{ nome: String, caminho: String }` shape, so the fold routes
4358// each wire-up site through one dispatch per typed variant.
4359//
4360// The macro below generates one `#[must_use]` inherent constructor per
4361// variant of shape `fn <ctor>(nome: &str, caminho: &str) -> Self`, so every
4362// wire-up site collapses onto one dispatch:
4363// `DepError::<ctor>(nome, caminho)`, byte-equal to the pre-lift
4364// struct-literal on the same `(&str, &str)` fixture. The uniform two-field
4365// construction (`nome.to_string()` / `caminho.to_string()`) is spelled
4366// once — inside the macro — rather than at every wire-up site.
4367//
4368// The twelve `FonteCaminho<Variant> { nome, caminho, byte }` three-field
4369// shapes at the per-byte-classification arms — the
4370// `FonteCaminho{ControlChar,ShellRedirection,ShellGlob,
4371// ShellSubshellGrouping,ShellBraceExpansion,ShellBracketExpansion,
4372// ShellQuoteGrouping,ShellComment,UrlPercentEncoding,
4373// ShellVariableExpansion,ShellHistoryExpansion,ShellHistorySubstitution}`
4374// cluster — carry an additional `byte: u8` naming the offending byte and
4375// so would break the uniform-two-field routing this macro promises. They
4376// instead fold onto the sibling three-field envelope through
4377// [`fonte_caminho_byte_ctors!`] (this-commit-lift, 12 variants on the
4378// `{ nome, caminho, byte }` shape), whose sole additional axis over this
4379// two-slot family is the `byte: u8` classification the arms carry. The
4380// remaining `FonteCaminhoEmpty` one-field `{ nome }` shape at the empty-
4381// first arm folds instead onto the peer [`dep_nome_only_ctors!`]
4382// (792aa92, 5 variants on `{ nome: String }`) sibling family of this
4383// envelope.
4384//
4385// Every future consumer that wants to construct one of these eleven
4386// variants outside the current in-crate [`DepSource::validate_caminho`]
4387// wire-up sites (a deferred `caixa-resolver` per-`:caminho` re-validator
4388// at lacre-resolve time re-checking the same value-shape axes the resolver
4389// consumes, a future `feira validate --deps` per-caixa admission verb
4390// re-checking the `:fonte :caminho` axis, a per-lacre overlay resolver
4391// rejecting a `:caminho` value against a cluster-local snapshot) now
4392// reaches each variant through one call rather than re-inlining the
4393// four-line struct-literal in lockstep with the eleven in-crate wire-up
4394// sites.
4395macro_rules! fonte_caminho_ctors {
4396 ($($ctor:ident => $variant:ident),* $(,)?) => {
4397 impl DepError {
4398 $(
4399 #[doc = concat!(
4400 "Construct a [`DepError::",
4401 stringify!($variant),
4402 "`] naming the offending `:deps :nome` + `:fonte ",
4403 "(:tipo path …) :caminho` pair. Folds the uniform ",
4404 "`Self::",
4405 stringify!($variant),
4406 " { nome: nome.to_string(), caminho: caminho.to_string() }` ",
4407 "two-slot struct-literal onto one substrate primitive so ",
4408 "every [`DepSource::validate_caminho`] wire-up on this ",
4409 "variant reads through one dispatch rather than the ",
4410 "pre-lift four-line open-coded block."
4411 )]
4412 #[must_use]
4413 pub fn $ctor(nome: &str, caminho: &str) -> Self {
4414 Self::$variant {
4415 nome: nome.to_string(),
4416 caminho: caminho.to_string(),
4417 }
4418 }
4419 )*
4420 }
4421 };
4422}
4423
4424fonte_caminho_ctors! {
4425 fonte_caminho_absolute => FonteCaminhoAbsolute,
4426 fonte_caminho_tilde_expansion => FonteCaminhoTildeExpansion,
4427 fonte_caminho_var_expansion => FonteCaminhoVarExpansion,
4428 fonte_caminho_leading_whitespace => FonteCaminhoLeadingWhitespace,
4429 fonte_caminho_leading_hyphen => FonteCaminhoLeadingHyphen,
4430 fonte_caminho_backslash => FonteCaminhoBackslash,
4431 fonte_caminho_shell_pipe => FonteCaminhoShellPipe,
4432 fonte_caminho_shell_semicolon => FonteCaminhoShellSemicolon,
4433 fonte_caminho_shell_background => FonteCaminhoShellBackground,
4434 fonte_caminho_shell_command_substitution => FonteCaminhoShellCommandSubstitution,
4435 fonte_caminho_trailing_slash => FonteCaminhoTrailingSlash,
4436}
4437
4438// Fold the twelve `DepError::FonteCaminho<Variant> { nome: nome.to_string(),
4439// caminho: caminho.to_string(), byte: b }` three-slot struct-variant wire-up
4440// sites at [`DepSource::validate_caminho`] onto one substrate primitive per
4441// typed variant — the paired `{ nome: String, caminho: String, byte: u8 }`
4442// three-slot family on [`DepError`], strict sibling of the peer
4443// [`fonte_caminho_ctors!`] (f85f145, 11 variants on the two-slot
4444// `{ nome: String, caminho: String }` envelope) of this envelope. Extends
4445// that fold onto the `byte`-classifying arms whose additional `byte: u8`
4446// axis broke its uniform-two-field routing — the exact "future compounding
4447// work" the pre-lift `fonte_caminho_ctors!` prose named as deferred, closed
4448// here. Third fold family on this `DepError` envelope, sibling of the peer
4449// two-slot [`fonte_caminho_ctors!`] and one-slot [`dep_nome_only_ctors!`]
4450// (792aa92, 5 variants on the `{ nome: String }` envelope) families on the
4451// same enum.
4452//
4453// Each of the twelve wire-up sites on this shape (the control-byte arm
4454// closing `FonteCaminhoControlChar` on the sub-`0x20` / `0x7F` cluster; the
4455// shell-lexer-metachar cascade closing `FonteCaminhoShellRedirection` on
4456// `< >`, `FonteCaminhoShellGlob` on `* ?`, `FonteCaminhoShellSubshellGrouping`
4457// on `( )`, `FonteCaminhoShellBraceExpansion` on `{ }`,
4458// `FonteCaminhoShellBracketExpansion` on `[ ]`, and
4459// `FonteCaminhoShellQuoteGrouping` on `' "`; the single-metachar arms
4460// closing `FonteCaminhoShellComment` on `#`, `FonteCaminhoUrlPercentEncoding`
4461// on `%`, `FonteCaminhoShellVariableExpansion` on `$`,
4462// `FonteCaminhoShellHistoryExpansion` on `!`, and
4463// `FonteCaminhoShellHistorySubstitution` on `^`) opened the identical
4464// `DepError::FonteCaminho<Variant> { nome: nome.to_string(),
4465// caminho: caminho.to_string(), byte: b }` five-line struct-literal against
4466// the same `(nome: &str, caminho: &str, b: u8)` local triple — the exact
4467// "same block re-inlined at every consumer" shape the PRIME DIRECTIVE names
4468// as a bug, on the same altitude the peer two-slot `fonte_caminho_ctors!`
4469// closed on the sibling two-field envelope of this same enum. The twelve
4470// variants share one `{ nome: String, caminho: String, byte: u8 }` shape, so
4471// the fold routes each wire-up site through one dispatch per typed variant.
4472//
4473// The macro below generates one `#[must_use]` inherent constructor per
4474// variant of shape `fn <ctor>(nome: &str, caminho: &str, byte: u8) -> Self`,
4475// so every wire-up site collapses onto one dispatch:
4476// `DepError::<ctor>(nome, caminho, b)`, byte-equal to the pre-lift
4477// struct-literal on the same `(&str, &str, u8)` fixture. The uniform
4478// three-field construction (`nome.to_string()` / `caminho.to_string()` /
4479// `byte`) is spelled once — inside the macro — rather than at every wire-up
4480// site.
4481//
4482// Every future consumer that wants to construct one of these twelve
4483// variants outside the current in-crate [`DepSource::validate_caminho`]
4484// wire-up sites (a deferred `caixa-resolver` per-`:caminho` re-validator
4485// at lacre-resolve time re-checking the same value-shape axes the resolver
4486// consumes, a future `feira validate --deps` per-caixa admission verb
4487// re-checking the `:fonte :caminho` axis against the shell-metachar
4488// classification bytes this cluster catches, a per-lacre overlay resolver
4489// rejecting a `:caminho` value against a cluster-local snapshot) now
4490// reaches each variant through one call rather than re-inlining the
4491// five-line struct-literal in lockstep with the twelve in-crate wire-up
4492// sites.
4493macro_rules! fonte_caminho_byte_ctors {
4494 ($($ctor:ident => $variant:ident),* $(,)?) => {
4495 impl DepError {
4496 $(
4497 #[doc = concat!(
4498 "Construct a [`DepError::",
4499 stringify!($variant),
4500 "`] naming the offending `:deps :nome` + `:fonte ",
4501 "(:tipo path …) :caminho` pair + the offending `byte: u8` ",
4502 "classification. Folds the uniform `Self::",
4503 stringify!($variant),
4504 " { nome: nome.to_string(), caminho: caminho.to_string(), ",
4505 "byte }` three-slot struct-literal onto one substrate ",
4506 "primitive so every [`DepSource::validate_caminho`] wire-up ",
4507 "on this variant reads through one dispatch rather than ",
4508 "the pre-lift five-line open-coded block."
4509 )]
4510 #[must_use]
4511 pub fn $ctor(nome: &str, caminho: &str, byte: u8) -> Self {
4512 Self::$variant {
4513 nome: nome.to_string(),
4514 caminho: caminho.to_string(),
4515 byte,
4516 }
4517 }
4518 )*
4519 }
4520 };
4521}
4522
4523fonte_caminho_byte_ctors! {
4524 fonte_caminho_control_char => FonteCaminhoControlChar,
4525 fonte_caminho_shell_redirection => FonteCaminhoShellRedirection,
4526 fonte_caminho_shell_glob => FonteCaminhoShellGlob,
4527 fonte_caminho_shell_subshell_grouping => FonteCaminhoShellSubshellGrouping,
4528 fonte_caminho_shell_brace_expansion => FonteCaminhoShellBraceExpansion,
4529 fonte_caminho_shell_bracket_expansion => FonteCaminhoShellBracketExpansion,
4530 fonte_caminho_shell_quote_grouping => FonteCaminhoShellQuoteGrouping,
4531 fonte_caminho_shell_comment => FonteCaminhoShellComment,
4532 fonte_caminho_url_percent_encoding => FonteCaminhoUrlPercentEncoding,
4533 fonte_caminho_shell_variable_expansion => FonteCaminhoShellVariableExpansion,
4534 fonte_caminho_shell_history_expansion => FonteCaminhoShellHistoryExpansion,
4535 fonte_caminho_shell_history_substitution => FonteCaminhoShellHistorySubstitution,
4536}
4537
4538// Fold the five `DepError::<Variant> { nome: <owner>.clone_or_to_string() }`
4539// single-slot struct-variant wire-up sites scattered across
4540// [`Dep::validate`] / [`Dep::validate_caracteristicas`] /
4541// [`DepSource::validate`] / [`DepSource::validate_caminho`] onto one
4542// substrate primitive per typed variant — the paired `{ nome: String }`
4543// single-slot family on [`DepError`], sibling of the peer
4544// [`fonte_caminho_ctors!`] (f85f145, 11 variants on
4545// `{ nome: String, caminho: String }`) on the sibling two-slot envelope of
4546// the same enum, and of the peer
4547// [`crate::supervisor::supervisor_caixa_only_ctors!`] (db09650, 3 variants
4548// on `{ caixa: String }`) on the `SupervisorError` envelope's single-slot
4549// axis. Second fold family on this `DepError` envelope, and the first on
4550// the single-`{ nome }` shape.
4551//
4552// The five wire-up sites this fold closes each opened the identical
4553// `DepError::<Variant> { nome: <owner>.to_string_or_clone() }` three-line
4554// struct-literal against the same `nome: &str` (or `self.nome: &String`)
4555// local — the exact "same block re-inlined at every consumer" shape the
4556// PRIME DIRECTIVE names as a bug. The five variants share one
4557// `{ nome: String }` shape, so the fold routes each wire-up site through
4558// one dispatch per typed variant.
4559//
4560// The macro below generates one `#[must_use]` inherent constructor per
4561// variant of shape `fn <ctor>(nome: &str) -> Self`, so every wire-up site
4562// collapses onto one dispatch: `DepError::<ctor>(nome)`, byte-equal to the
4563// pre-lift struct-literal on the same `&str` fixture. The uniform
4564// one-field construction (`nome.to_string()`) is spelled once — inside
4565// the macro — rather than at every wire-up site. Callers that hold a
4566// `String` (`self.nome`) pass `&self.nome`, which auto-derefs to `&str`
4567// and lets the macro-owned `.to_string()` produce the fresh owning copy
4568// the enum variant needs; the semantics collapse onto the same
4569// `.clone()`-equivalent one this fold replaces at every site.
4570//
4571// The sibling `NomeEmpty` unit-variant (`enum DepError { NomeEmpty, … }`)
4572// on the same envelope stays on its pre-lift open-coded wire-up shape —
4573// it carries no `nome` field (the offending `:nome` value *is* the empty
4574// string this variant catches) so the uniform `fn(nome: &str) -> Self`
4575// signature this macro promises does not apply. Every future consumer
4576// that wants to construct one of these five variants outside the current
4577// in-crate wire-up sites (a deferred `caixa-resolver` per-`:versao` /
4578// `:caracteristicas` / `:fonte :repo` / `:fonte :pin` / `:fonte :caminho`
4579// re-validator at lacre-resolve time, a future `feira validate --deps`
4580// per-caixa admission verb, a per-lacre overlay resolver rejecting one of
4581// these empty-value shapes against a cluster-local snapshot) now reaches
4582// each variant through one call rather than re-inlining the three-line
4583// struct-literal in lockstep with the five in-crate wire-up sites.
4584macro_rules! dep_nome_only_ctors {
4585 ($($ctor:ident => $variant:ident),* $(,)?) => {
4586 impl DepError {
4587 $(
4588 #[doc = concat!(
4589 "Construct a [`DepError::",
4590 stringify!($variant),
4591 "`] naming the offending `:deps :nome`. Folds the ",
4592 "uniform `Self::",
4593 stringify!($variant),
4594 " { nome: nome.to_string() }` one-field ",
4595 "struct-literal onto one substrate primitive so every ",
4596 "in-crate wire-up on this variant reads through one ",
4597 "dispatch rather than the pre-lift three-line ",
4598 "open-coded block."
4599 )]
4600 #[must_use]
4601 pub fn $ctor(nome: &str) -> Self {
4602 Self::$variant { nome: nome.to_string() }
4603 }
4604 )*
4605 }
4606 };
4607}
4608
4609dep_nome_only_ctors! {
4610 versao_empty => VersaoEmpty,
4611 fonte_repo_empty => FonteRepoEmpty,
4612 fonte_pin_missing => FontePinMissing,
4613 fonte_caminho_empty => FonteCaminhoEmpty,
4614 caracteristica_empty => CaracteristicaEmpty,
4615}
4616
4617// Fold the four `DepError::{DuplicateNome, DepIsSelf}` struct-variant
4618// wire-up sites at [`crate::manifest::Caixa::push_dep`] +
4619// [`crate::manifest::Caixa::validate_deps`] +
4620// [`validate_no_self_dep`] onto one substrate-primitive family per
4621// typed variant — the `DepError`-side siblings of the peer
4622// [`crate::supervisor::supervisor_caixa_only_ctors!`] macro (db09650)
4623// on the `SupervisorError { caixa: String }` one-slot envelope and of
4624// the peer [`dep_nome_only_ctors!`] macro (792aa92) on the
4625// `DepError { nome: String }` one-slot envelope. The two variants
4626// carry the same `{ nome: String, list: &'static str }` two-slot
4627// shape: the `nome` field names the offending dep the diagnostic
4628// points the author back at, and the `list` field carries the
4629// `":deps"` / `":deps-dev"` author-surface tag verbatim (via
4630// [`crate::dep::DepList::as_str`] on the [`push_dep`] /
4631// [`validate_deps`] arms, and via the paired
4632// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
4633// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] `&'static str`
4634// canonicals on the [`validate_no_self_dep`] arm) so the author can
4635// grep their caixa.lisp for the offending list block in one edit.
4636//
4637// Each of the four wire-up sites opened the same struct-literal
4638// `DepError::<Variant> { nome: <name>.to_string(), list: <tag> }`
4639// two-line block — the exact "same block re-inlined at every
4640// consumer" shape the PRIME DIRECTIVE names as a bug, on the same
4641// altitude the peer `DepError` / `SupervisorError` /
4642// `AplicacaoError` / `LayoutError` / `LimitsError` ctor families
4643// already closed on their sibling envelopes. The two `#[must_use]`
4644// inherent constructors below fold each wire-up onto one dispatch:
4645// `DepError::duplicate_nome(<nome>, <list>)` and
4646// `DepError::dep_is_self(<nome>, <list>)`, byte-equal to the
4647// pre-lift struct-literal on the same scalar fixtures. The `list:
4648// &'static str` parameter (not `impl Into<String>`) preserves the
4649// exact wire tag every consumer already passes verbatim — no
4650// downstream diagnostic reshaping at the lift, matching the peer
4651// `DepList::as_str` / `DEP_AUTHOR_KEY_DEPS*` `&'static str`
4652// contract each wire-up site already keys off.
4653macro_rules! dep_nome_list_ctors {
4654 ($($ctor:ident => $variant:ident),* $(,)?) => {
4655 impl DepError {
4656 $(
4657 #[doc = concat!(
4658 "Construct a [`DepError::",
4659 stringify!($variant),
4660 "`] naming the offending `:deps :nome` and the ",
4661 "author-surface list tag (`:deps` vs. `:deps-dev`) ",
4662 "the diagnostic points the author back at. Folds ",
4663 "the uniform `Self::",
4664 stringify!($variant),
4665 " { nome: nome.to_string(), list }` two-field ",
4666 "struct-literal onto one substrate primitive so ",
4667 "every in-crate wire-up on this variant reads ",
4668 "through one dispatch rather than the pre-lift ",
4669 "open-coded struct-literal block."
4670 )]
4671 #[must_use]
4672 pub fn $ctor(nome: &str, list: &'static str) -> Self {
4673 Self::$variant { nome: nome.to_string(), list }
4674 }
4675 )*
4676 }
4677 };
4678}
4679
4680dep_nome_list_ctors! {
4681 duplicate_nome => DuplicateNome,
4682 dep_is_self => DepIsSelf,
4683}
4684
4685#[allow(clippy::trivially_copy_pass_by_ref)]
4686fn is_false(b: &bool) -> bool {
4687 !*b
4688}
4689
4690#[cfg(test)]
4691mod tests {
4692 use super::*;
4693
4694 #[test]
4695 fn registry_dep_is_minimal() {
4696 let d = Dep::simple("caixa-teia", "^0.1");
4697 assert_eq!(d.nome, "caixa-teia");
4698 assert_eq!(d.versao, "^0.1");
4699 assert!(d.fonte.is_none());
4700 assert!(!d.opcional());
4701 assert!(d.caracteristicas().is_empty());
4702 }
4703
4704 #[test]
4705 fn dep_string_scalar_accessor_pair_is_const_fn() {
4706 // Fail-before-pass-after pin on [`Dep::nome`] +
4707 // [`Dep::versao_requirement`]'s `const`-eval-surface posture.
4708 // Each accessor projects the per-`:deps` / per-`:deps-dev`
4709 // entry's [`String`] storage through the `pub const fn`
4710 // [`String::as_str`] (const-stable since Rust 1.87, well
4711 // within the workspace MSRV) — any future accidental
4712 // downgrade to non-`const` fails the corresponding
4713 // `<name>_via_const_fn` wrapper at caixa-core build time with
4714 // E0015 (`cannot call non-const method`), strictly stronger
4715 // than a runtime `assert!`. Sibling of the peer
4716 // per-M2/M3/universal-axis `String → &str` scalar-accessor
4717 // family pins on the sibling `const`-eval-surface passes
4718 // ([`crate::Caixa::nome`] / [`crate::Caixa::versao`] at the
4719 // top-level manifest, [`crate::CaixaVersion::as_str`] at the
4720 // typed-newtype wrapper, [`crate::aplicacao::Membro::nome`] /
4721 // [`crate::aplicacao::Membro::versao_requirement`] at the M3
4722 // membership axis, [`crate::aplicacao::Entrada::hostname`] /
4723 // [`crate::aplicacao::Entrada::destination`] at the M3
4724 // ingress axis, [`crate::supervisor::ChildSpec::nome`] /
4725 // [`crate::supervisor::ChildSpec::versao_requirement`] at the
4726 // M2 supervisor-tree axis,
4727 // [`crate::upgrade::UpgradeFromEntry::prior_versao`] at the
4728 // M2 upgrade axis, and the per-`:contratos`
4729 // [`crate::aplicacao::WitContract::source`] /
4730 // [`crate::aplicacao::WitContract::destination`] /
4731 // [`crate::aplicacao::WitContract::world_ref`] trio the
4732 // sibling pin at 279823b already anchors).
4733 const fn nome_via_const_fn(d: &Dep) -> &str {
4734 d.nome()
4735 }
4736 const fn versao_via_const_fn(d: &Dep) -> &str {
4737 d.versao_requirement()
4738 }
4739 for (nome, versao) in [
4740 ("caixa-teia", "^0.1"),
4741 ("caixa-mesh", "~0.2.3"),
4742 ("caixa-helm", "*"),
4743 ] {
4744 let d = Dep::simple(nome, versao);
4745 assert_eq!(nome_via_const_fn(&d), d.nome());
4746 assert_eq!(versao_via_const_fn(&d), d.versao_requirement());
4747 assert_eq!(d.nome(), nome);
4748 assert_eq!(d.versao_requirement(), versao);
4749 }
4750 }
4751
4752 #[test]
4753 fn dep_outer_accessor_family_is_const_fn() {
4754 // Fail-before-pass-after pin on [`Dep::fonte`] +
4755 // [`Dep::caracteristicas`]'s `const`-eval-surface posture.
4756 // Each accessor projects the per-`:deps` / per-`:deps-dev`
4757 // entry's composite / list storage through a `pub const fn`
4758 // stdlib method (`Option::<DepSource>::as_ref` /
4759 // `Vec::<String>::as_slice`, both const-stable since Rust
4760 // 1.83, well within the workspace MSRV). Any future
4761 // accidental downgrade to non-`const` fails the corresponding
4762 // `<name>_via_const_fn` wrapper at caixa-core build time with
4763 // E0015 (`cannot call non-const method`), strictly stronger
4764 // than a runtime `assert!` and side-stepping the destructor-
4765 // in-const restriction the `Dep` fixture's `String` /
4766 // `Option<DepSource>` / `Vec<String>` carriers rule out on the
4767 // direct-`const _: () = assert!(...)` residence.
4768 //
4769 // Peer of the sibling per-`Dep` scalar-accessor pair pin
4770 // [`dep_string_scalar_accessor_pair_is_const_fn`] on the same
4771 // outer per-dep-list-entry [`Dep`] altitude — this pin extends
4772 // the `const`-eval-surface discipline onto the composite-
4773 // reference and slice-return arms of the outer-`Dep` accessor
4774 // family, closing the four-slot outer surface (`:nome` +
4775 // `:versao` + `:fonte` + `:caracteristicas`) on the `const`-fn
4776 // posture. The `:opcional` `bool` arm already carries the
4777 // posture through [`Dep::opcional`]'s prior `pub const fn`
4778 // declaration, so this pin lands the last two unlifted
4779 // outer-`Dep` accessors and closes the family.
4780 const fn fonte_via_const_fn(d: &Dep) -> Option<&DepSource> {
4781 d.fonte()
4782 }
4783 const fn caracteristicas_via_const_fn(d: &Dep) -> &[String] {
4784 d.caracteristicas()
4785 }
4786 // `Dep::simple` — no `:fonte`, empty `:caracteristicas`.
4787 let empty = Dep::simple("caixa-teia", "^0.1");
4788 assert!(fonte_via_const_fn(&empty).is_none());
4789 assert_eq!(fonte_via_const_fn(&empty), empty.fonte());
4790 assert!(caracteristicas_via_const_fn(&empty).is_empty());
4791 assert_eq!(
4792 caracteristicas_via_const_fn(&empty),
4793 empty.caracteristicas()
4794 );
4795 // `Dep::git` — `:fonte` is `Some(Git{…})`, `:caracteristicas`
4796 // still empty.
4797 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
4798 assert!(fonte_via_const_fn(&git).is_some());
4799 assert_eq!(fonte_via_const_fn(&git), git.fonte());
4800 assert_eq!(caracteristicas_via_const_fn(&git), git.caracteristicas());
4801 // Populated `:caracteristicas` — exercise the non-empty
4802 // slice-view arm to pin the accessor's borrow shape against
4803 // both a `Vec::new()` empty backing buffer and a populated one.
4804 let mut with_features = Dep::simple("caixa-teia", "^0.1");
4805 with_features.caracteristicas = vec!["feat-a".into(), "feat-b".into()];
4806 assert_eq!(caracteristicas_via_const_fn(&with_features).len(), 2);
4807 assert_eq!(
4808 caracteristicas_via_const_fn(&with_features),
4809 with_features.caracteristicas()
4810 );
4811 }
4812
4813 #[test]
4814 fn git_dep_carries_tag() {
4815 let d = Dep::git("t", "*", "github:o/r", "v1");
4816 match d.fonte {
4817 Some(DepSource::Git {
4818 ref repo, ref tag, ..
4819 }) => {
4820 assert_eq!(repo, "github:o/r");
4821 assert_eq!(tag.as_deref(), Some("v1"));
4822 }
4823 _ => panic!("expected Git source"),
4824 }
4825 }
4826
4827 #[test]
4828 fn validate_accepts_simple_dep() {
4829 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
4830 }
4831
4832 #[test]
4833 fn validate_rejects_empty_nome() {
4834 // The fail-before-pass-after pin for `:nome ""`: the empty-name
4835 // arm fires first so the per-entry parse-side diagnostic doesn't
4836 // emit a useless `nome: ""` reference.
4837 let mut d = Dep::simple("placeholder", "^0.1");
4838 d.nome = String::new();
4839 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4840 }
4841
4842 #[test]
4843 fn validate_rejects_empty_versao() {
4844 // `parse_requirement("")` returns `Ok(VersionReq::STAR)` (the
4845 // semver crate accepts the empty string as a wildcard match),
4846 // so the empty-`:versao` arm is structurally necessary even
4847 // with the parse arm in place — mirrors `MembroVersaoEmpty` /
4848 // `EmptyChildVersion` ordering on the other two `:versao` axes.
4849 let mut d = Dep::simple("caixa-teia", "ignored");
4850 d.versao = String::new();
4851 let err = d.validate().unwrap_err();
4852 assert!(
4853 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4854 "got {err:?}"
4855 );
4856 }
4857
4858 // ── value-shape: DNS-1123 label on :deps :nome ────────────────────────
4859
4860 #[test]
4861 fn validate_rejects_nome_with_uppercase() {
4862 // The fail-before-pass-after pin: a non-empty but uppercase
4863 // `:nome` silently passed `validate()` on every pre-gate
4864 // codebase because the prior shape only refused the empty
4865 // string. The DNS-1123 violation surfaced far downstream at
4866 // lacre-resolve time when the *target* caixa's `:nome` failed
4867 // its own gate — far from the `:deps` entry, with a diagnostic
4868 // naming the target rather than the dep entry that referenced
4869 // it. Same fail-before-pass-after fixture pinned for
4870 // `:membros :caixa` (3f9d7a0), `:children :caixa` (31bfa43),
4871 // and Caixa `:nome` (6c992f8).
4872 let d = Dep::simple("Caixa-Teia", "^0.1");
4873 let err = d.validate().unwrap_err();
4874 assert!(
4875 matches!(
4876 err,
4877 DepError::NomeInvalid { ref nome, ref reason }
4878 if nome == "Caixa-Teia" && reason.contains("uppercase")
4879 ),
4880 "got {err:?}"
4881 );
4882 }
4883
4884 #[test]
4885 fn validate_rejects_nome_with_underscore() {
4886 // RFC 1123 allows `[a-z0-9-]` only; underscore is the canonical
4887 // "I'm thinking of Go module names / Python identifiers" leak.
4888 // Same fixture pinned for the peer caixa-identifier axes.
4889 let d = Dep::simple("caixa_teia", "^0.1");
4890 let err = d.validate().unwrap_err();
4891 assert!(
4892 matches!(
4893 err,
4894 DepError::NomeInvalid { ref nome, ref reason }
4895 if nome == "caixa_teia" && reason.contains('_')
4896 ),
4897 "got {err:?}"
4898 );
4899 }
4900
4901 #[test]
4902 fn validate_rejects_nome_with_dot() {
4903 // A `:deps :nome` is a single DNS-1123 *label*, not a
4904 // subdomain — dots are rejected. The `"caixa.teia"` shape is
4905 // the canonical "I confused the dep name with the FQDN /
4906 // namespace" footgun, distinct from the legitimate
4907 // `:fonte :repo "github:org/caixa-teia"` axis.
4908 let d = Dep::simple("caixa.teia", "^0.1");
4909 let err = d.validate().unwrap_err();
4910 assert!(
4911 matches!(
4912 err,
4913 DepError::NomeInvalid { ref nome, ref reason }
4914 if nome == "caixa.teia" && reason.contains('.')
4915 ),
4916 "got {err:?}"
4917 );
4918 }
4919
4920 #[test]
4921 fn validate_rejects_nome_with_leading_hyphen() {
4922 // RFC 1123 requires alphanumeric at both label boundaries.
4923 // Pinned in parity with the peer DNS-1123 fixtures.
4924 let d = Dep::simple("-caixa-teia", "^0.1");
4925 let err = d.validate().unwrap_err();
4926 assert!(
4927 matches!(
4928 err,
4929 DepError::NomeInvalid { ref nome, ref reason }
4930 if nome == "-caixa-teia" && reason.contains("alphanumeric")
4931 ),
4932 "got {err:?}"
4933 );
4934 }
4935
4936 #[test]
4937 fn validate_rejects_nome_with_trailing_hyphen() {
4938 let d = Dep::simple("caixa-teia-", "^0.1");
4939 let err = d.validate().unwrap_err();
4940 assert!(
4941 matches!(
4942 err,
4943 DepError::NomeInvalid { ref nome, ref reason }
4944 if nome == "caixa-teia-" && reason.contains("alphanumeric")
4945 ),
4946 "got {err:?}"
4947 );
4948 }
4949
4950 #[test]
4951 fn validate_rejects_nome_with_slash() {
4952 // The canonical "I copied the GitHub repo path into `:nome`
4953 // instead of `:fonte :repo`" typo. A `/` in the name leaks the
4954 // lacre-side `:repositorio` shape (`pleme-io/caixa-teia`) into
4955 // the local-name slot. Same fixture pinned for `:membros
4956 // :caixa` (3f9d7a0).
4957 let d = Dep::simple("pleme-io/caixa-teia", "^0.1");
4958 let err = d.validate().unwrap_err();
4959 assert!(
4960 matches!(
4961 err,
4962 DepError::NomeInvalid { ref nome, ref reason }
4963 if nome == "pleme-io/caixa-teia" && reason.contains('/')
4964 ),
4965 "got {err:?}"
4966 );
4967 }
4968
4969 #[test]
4970 fn validate_rejects_nome_too_long() {
4971 // 64-byte label — one over the RFC 1035 / RFC 1123 label cap.
4972 // Built from a valid character set so the length-bound
4973 // diagnostic surfaces before any per-character check (the
4974 // order pin parallel to the per-character predicates inside
4975 // [`crate::render::is_dns_1123_label`]).
4976 let long = "a".repeat(64);
4977 let d = Dep::simple(&long, "^0.1");
4978 let err = d.validate().unwrap_err();
4979 assert!(
4980 matches!(
4981 err,
4982 DepError::NomeInvalid { ref nome, ref reason }
4983 if nome.len() == 64 && reason.contains("max length of 63")
4984 ),
4985 "got {err:?}"
4986 );
4987 }
4988
4989 #[test]
4990 fn validate_accepts_canonical_nome_labels() {
4991 // Positive-control sweep — every form the K8s apiserver
4992 // accepts as a DNS-1123 label must round-trip through
4993 // validate. Covers a hyphen-bearing label, a numeric-suffix
4994 // label, a leading-digit label, a single-character label, and
4995 // a 63-byte (exactly the cap) label — the same fixture set
4996 // the peer `:membros :caixa` / `:children :caixa` positive
4997 // controls pin.
4998 for nome in [
4999 "caixa-teia",
5000 "caixa-resolver2",
5001 "2nd-tier-cache",
5002 "x",
5003 "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0",
5004 ] {
5005 Dep::simple(nome, "^0.1")
5006 .validate()
5007 .unwrap_or_else(|e| panic!("canonical label {nome:?} must validate, got {e:?}"));
5008 }
5009 }
5010
5011 #[test]
5012 fn nome_empty_takes_precedence_over_nome_invalid() {
5013 // Ordering pin: `NomeEmpty` is the more self-locating
5014 // diagnostic on `""` and must lead — `is_dns_1123_label` is
5015 // only reached after the empty-check fires at the call site.
5016 // Mirrors `membro_caixa_empty_takes_precedence_over_invalid`
5017 // (3f9d7a0) on the peer caixa-identifier axis.
5018 let mut d = Dep::simple("placeholder", "^0.1");
5019 d.nome = String::new();
5020 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
5021 }
5022
5023 #[test]
5024 fn nome_invalid_fires_before_versao_empty() {
5025 // Ordering pin: a malformed `:nome` fires before any `:versao`
5026 // axis check on the *same* entry — the per-entry shape gates
5027 // run top-to-bottom (nome empty → nome shape → versao empty →
5028 // versao parse → fonte shape), so a one-entry caixa.lisp with
5029 // both wrong sees the name-side diagnostic first (the name is
5030 // the self-locating axis — without a valid name, the parse
5031 // diagnostic can't quote `:nome "<bad>"`). Same ordering
5032 // discipline as `membro_caixa_invalid_fires_before_versao_check`
5033 // (3f9d7a0).
5034 let mut d = Dep::simple("Caixa-Teia", "^0.1");
5035 d.versao = String::new();
5036 let err = d.validate().unwrap_err();
5037 assert!(
5038 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
5039 "got {err:?}"
5040 );
5041 }
5042
5043 #[test]
5044 fn nome_invalid_fires_before_versao_invalid() {
5045 // Ordering pin: a malformed `:nome` fires before the `:versao`
5046 // parse-side check on the *same* entry. Pin separately from
5047 // the empty-versao ordering so a future re-ordering surfaces
5048 // here, parallel to the b0c8389 / c4213a4 trajectory.
5049 let d = Dep::simple("Caixa-Teia", "^^0.1");
5050 let err = d.validate().unwrap_err();
5051 assert!(
5052 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
5053 "got {err:?}"
5054 );
5055 }
5056
5057 #[test]
5058 fn nome_invalid_fires_before_fonte_invalid() {
5059 // Ordering pin: a malformed `:nome` fires before the `:fonte`
5060 // shape check on the *same* entry. The `:fonte` diagnostic
5061 // names the offending dep's `:nome` verbatim (via
5062 // `DepSource::validate(&self.nome)`), so a non-self-locating
5063 // name would taint the downstream diagnostic too — the gate
5064 // ordering keeps both diagnostics individually self-locating.
5065 let mut d = Dep::simple("Caixa-Teia", "^0.1");
5066 d.fonte = Some(DepSource::Git {
5067 repo: String::new(),
5068 tag: None,
5069 rev: None,
5070 branch: None,
5071 });
5072 let err = d.validate().unwrap_err();
5073 assert!(
5074 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
5075 "got {err:?}"
5076 );
5077 }
5078
5079 #[test]
5080 fn nome_invalid_diagnostic_carries_offending_name() {
5081 // The diagnostic-shape pin: the error names the offending
5082 // `:nome` value verbatim so the author can grep their
5083 // caixa.lisp without re-running the build, and carries a
5084 // non-empty `reason` from `is_dns_1123_label` so the
5085 // predicate's own wording flows through to the diagnostic.
5086 // Same shape as `MembroCaixaInvalid` (3f9d7a0),
5087 // `ChildCaixaInvalid` (31bfa43), `ManifestError::NomeInvalid`
5088 // (6c992f8) — the four DNS-1123 caixa-identifier axes now
5089 // share a structurally-equivalent diagnostic family.
5090 let d = Dep::simple("Caixa_Teia", "^0.1");
5091 let err = d.validate().unwrap_err();
5092 let DepError::NomeInvalid { nome, reason } = err else {
5093 panic!("expected NomeInvalid, got other variant");
5094 };
5095 assert_eq!(nome, "Caixa_Teia");
5096 assert!(
5097 !reason.is_empty(),
5098 "NomeInvalid `reason` must carry the predicate's wording verbatim"
5099 );
5100 }
5101
5102 #[test]
5103 fn validate_rejects_invalid_versao_requirement() {
5104 // The fail-before-pass-after pin: a non-empty but malformed
5105 // requirement (`"^bad-version"`) silently passed every pre-gate
5106 // codebase because `:deps :versao` wasn't validated. The parse
5107 // failure surfaced far downstream at lacre-resolve time with a
5108 // `semver::Error` that didn't name which `:deps` entry carried
5109 // the typo. The new gate moves the check to caixa-build time
5110 // at the source caixa.lisp.
5111 let d = Dep::simple("caixa-teia", "^bad-version");
5112 let err = d.validate().unwrap_err();
5113 assert!(
5114 matches!(
5115 err,
5116 DepError::VersaoInvalid { ref nome, ref versao, .. }
5117 if nome == "caixa-teia" && versao == "^bad-version"
5118 ),
5119 "got {err:?}"
5120 );
5121 }
5122
5123 #[test]
5124 fn validate_rejects_versao_with_double_caret_typo() {
5125 // `"^^0.1"` is the canonical doubled-caret typo — looks like a
5126 // Cargo-shaped requirement on first glance but fails the parser
5127 // because semver doesn't accept stacked operators. Pin this
5128 // adjacent-shape footgun explicitly so a future relaxation that
5129 // accepts "looks-canonical-but-isn't" forms surfaces here, in
5130 // parity with the `:membros` / `:children` fixtures.
5131 let d = Dep::simple("caixa-teia", "^^0.1");
5132 let err = d.validate().unwrap_err();
5133 assert!(
5134 matches!(
5135 err,
5136 DepError::VersaoInvalid { ref nome, ref versao, .. }
5137 if nome == "caixa-teia" && versao == "^^0.1"
5138 ),
5139 "got {err:?}"
5140 );
5141 }
5142
5143 #[test]
5144 fn validate_rejects_versao_with_v_prefixed_tag() {
5145 // `"v0.1"` is the canonical "git-tag-shape leaking into the
5146 // semver requirement slot" typo — an author copies the
5147 // publish-side git-tag string verbatim into `:versao`, but
5148 // Cargo's semver parser rejects the leading `v`. Same fixture
5149 // pinned for `:membros :versao` (9888b13) and `:children
5150 // :versao` (b38ff3a). (Bare `x`-glob shorthands like `^0.1.x`
5151 // are *accepted* by the semver crate as an `*` wildcard on the
5152 // patch axis — they're a Cargo-side valid shape, not a typo.)
5153 let d = Dep::simple("caixa-teia", "v0.1");
5154 let err = d.validate().unwrap_err();
5155 assert!(
5156 matches!(
5157 err,
5158 DepError::VersaoInvalid { ref nome, ref versao, .. }
5159 if nome == "caixa-teia" && versao == "v0.1"
5160 ),
5161 "got {err:?}"
5162 );
5163 }
5164
5165 #[test]
5166 fn validate_accepts_canonical_versao_forms() {
5167 // The five Cargo-shaped requirement forms `:membros :versao`
5168 // and `:children :versao` already accept via
5169 // `crate::parse_requirement` must pass the deps gate without
5170 // re-validating at the resolver layer. Pin every leg so a
5171 // future tightening of the canonical set surfaces here as a
5172 // test failure.
5173 for form in [
5174 "^0.1", // caret — minor-range pin (the most common shape)
5175 "~0.1.2", // tilde — patch-range pin
5176 "0.1.0", // exact — single-version pin
5177 "*", // wildcard — explicitly any-version
5178 ">=0.1, <2", // multi-range — comma-separated comparators
5179 ] {
5180 Dep::simple("caixa-teia", form)
5181 .validate()
5182 .unwrap_or_else(|e| panic!("canonical form {form:?} must validate, got {e:?}"));
5183 }
5184 }
5185
5186 #[test]
5187 fn versao_empty_takes_precedence_over_invalid() {
5188 // Order pin: the existing `VersaoEmpty` diagnostic (which
5189 // doesn't try to parse) fires before the new `VersaoInvalid`
5190 // parse-side diagnostic, so an empty `:versao` keeps its
5191 // narrower error message — `parse_requirement("")` would
5192 // otherwise return `Ok(STAR)` and silently pass, but the empty
5193 // arm catches it first.
5194 let mut d = Dep::simple("caixa-teia", "ignored");
5195 d.versao = String::new();
5196 let err = d.validate().unwrap_err();
5197 assert!(
5198 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
5199 "got {err:?}"
5200 );
5201 }
5202
5203 #[test]
5204 fn nome_empty_takes_precedence_over_versao_invalid() {
5205 // Order pin: even when `:versao` is malformed and would raise
5206 // its own diagnostic, `:nome ""` fires first because the
5207 // per-entry parse diagnostic needs a non-empty name to be
5208 // self-locating. Mirrors the
5209 // `membros_validation_runs_before_contratos_membership_check`
5210 // ordering on the typed-graph layer.
5211 let mut d = Dep::simple("placeholder", "^bad");
5212 d.nome = String::new();
5213 let err = d.validate().unwrap_err();
5214 assert_eq!(err, DepError::NomeEmpty);
5215 }
5216
5217 #[test]
5218 fn versao_invalid_diagnostic_carries_offending_versao() {
5219 // The diagnostic-shape pin: the error names the offending
5220 // `:versao` value verbatim so the author can grep their
5221 // caixa.lisp without re-running the build, and carries a
5222 // non-empty `reason` from `semver::VersionReq::parse` so the
5223 // parser's own wording flows through to the diagnostic.
5224 let d = Dep::simple("caixa-teia", "not-a-req");
5225 let err = d.validate().unwrap_err();
5226 let DepError::VersaoInvalid {
5227 nome,
5228 versao,
5229 reason,
5230 } = err
5231 else {
5232 panic!("expected VersaoInvalid, got other variant");
5233 };
5234 assert_eq!(nome, "caixa-teia");
5235 assert_eq!(versao, "not-a-req");
5236 assert!(
5237 !reason.is_empty(),
5238 "VersaoInvalid `reason` must carry the parser's wording verbatim"
5239 );
5240 }
5241
5242 // -- :fonte value-shape gate ------------------------------------------
5243
5244 fn dep_with_fonte(fonte: DepSource) -> Dep {
5245 let mut d = Dep::simple("caixa-teia", "^0.1");
5246 d.fonte = Some(fonte);
5247 d
5248 }
5249
5250 #[test]
5251 fn validate_accepts_git_fonte_with_tag() {
5252 // The positive-control pin on the canonical git source — exactly
5253 // one of :tag/:rev/:branch set, non-empty :repo. Mirrors the
5254 // shape every existing caixa-resolver integration test uses.
5255 let d = dep_with_fonte(DepSource::Git {
5256 repo: "github:pleme-io/caixa-teia".into(),
5257 tag: Some("v0.1.0".into()),
5258 rev: None,
5259 branch: None,
5260 });
5261 d.validate().unwrap();
5262 }
5263
5264 #[test]
5265 fn validate_accepts_git_fonte_with_rev() {
5266 // Each of the three pin axes is independently a valid single-pin
5267 // shape; pin the :rev arm so a future relaxation that only
5268 // accepts :tag surfaces here. The value is a full 40-hex SHA-1
5269 // OID — the canonical `git rev-parse HEAD` emission shape the
5270 // `crate::render::is_git_oid` value-shape gate now requires;
5271 // abbreviated OIDs are ambiguous across repo history and
5272 // rejected at this gate (pinned separately by
5273 // `validate_rejects_git_fonte_with_rev_abbreviated_prefix`).
5274 let d = dep_with_fonte(DepSource::Git {
5275 repo: "github:pleme-io/caixa-teia".into(),
5276 tag: None,
5277 rev: Some("c0ffee0123abcdef0123456789abcdef01234567".into()),
5278 branch: None,
5279 });
5280 d.validate().unwrap();
5281 }
5282
5283 #[test]
5284 fn validate_accepts_git_fonte_with_branch() {
5285 // The :branch arm is the third valid single-pin shape — pinned
5286 // separately so the gate-accepts-all-three-pin-axes contract is
5287 // a build-error to relax.
5288 let d = dep_with_fonte(DepSource::Git {
5289 repo: "github:pleme-io/caixa-teia".into(),
5290 tag: None,
5291 rev: None,
5292 branch: Some("main".into()),
5293 });
5294 d.validate().unwrap();
5295 }
5296
5297 #[test]
5298 fn validate_accepts_path_fonte() {
5299 // The positive-control pin on the path source — non-empty
5300 // :caminho, no pin axes (paths have no commit identity). Pinned
5301 // so a future "paths must also pin a rev" tightening surfaces
5302 // here as a structural decision, not a silent break.
5303 let d = dep_with_fonte(DepSource::Path {
5304 caminho: "../caixa-teia".into(),
5305 });
5306 d.validate().unwrap();
5307 }
5308
5309 #[test]
5310 fn validate_rejects_git_fonte_with_empty_repo() {
5311 // The fail-before-pass-after pin for `(:tipo git :repo "" :tag
5312 // "v1")`: the empty-repo shape silently passed every pre-gate
5313 // codebase because `:fonte` wasn't validated. The git-clone
5314 // failure surfaced far downstream at lacre-resolve time with no
5315 // field naming which `:deps` entry carried the typo. The new
5316 // gate moves the check to caixa-build time at the source
5317 // caixa.lisp.
5318 let d = dep_with_fonte(DepSource::Git {
5319 repo: String::new(),
5320 tag: Some("v0.1.0".into()),
5321 rev: None,
5322 branch: None,
5323 });
5324 let err = d.validate().unwrap_err();
5325 assert!(
5326 matches!(err, DepError::FonteRepoEmpty { ref nome } if nome == "caixa-teia"),
5327 "got {err:?}"
5328 );
5329 }
5330
5331 // -- :repo value-shape gate -------------------------------------------
5332 //
5333 // The `:fonte (:tipo git :repo …)` value flows verbatim into the
5334 // caixa-resolver's `git clone <repo>` subprocess. The pre-gate
5335 // codebase admitted any non-empty string; the new
5336 // [`crate::render::is_git_repo_url`] predicate gates the git-porcelain
5337 // URL intersection-floor at validate time, peer with the three pin
5338 // axes (`:tag` + `:branch` via `is_git_ref_name`, `:rev` via
5339 // `is_git_oid`). Every test in this section is a fail-before /
5340 // pass-after pin on a specific authoring footgun.
5341
5342 #[test]
5343 fn validate_rejects_git_fonte_with_repo_carrying_trailing_space() {
5344 // The canonical paste-from-doc footgun on `:repo` — an author
5345 // copies `"github:pleme-io/caixa-teia "` (trailing space) out of
5346 // a doc paragraph. Until this gate landed the empty-repo arm
5347 // passed (the string isn't empty), the resolver issued
5348 // `git clone 'github:pleme-io/caixa-teia '`, and the failure
5349 // surfaced at clone time with a quoting-confused error far from
5350 // the source caixa.lisp. Same paste-from-doc footgun the
5351 // `:tag "v0.1.0 "` gate (e70d213) closes on the peer refname
5352 // axis — now closed on the `:repo` URL axis too.
5353 let d = dep_with_fonte(DepSource::Git {
5354 repo: "github:pleme-io/caixa-teia ".into(),
5355 tag: Some("v0.1.0".into()),
5356 rev: None,
5357 branch: None,
5358 });
5359 let err = d.validate().unwrap_err();
5360 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5361 panic!("expected FonteRepoShape, got other variant");
5362 };
5363 assert_eq!(nome, "caixa-teia");
5364 assert_eq!(repo, "github:pleme-io/caixa-teia ");
5365 assert!(
5366 reason.contains("whitespace"),
5367 "reason must surface the whitespace arm, got {reason:?}"
5368 );
5369 }
5370
5371 #[test]
5372 fn validate_rejects_git_fonte_with_repo_starting_with_dash() {
5373 // The canonical CLI-argument-injection footgun at the `git clone`
5374 // subprocess boundary — `:repo "-upload-pack=evil"` makes git's
5375 // argv parser read the value as a CLI flag, escaping the
5376 // subprocess argument boundary. The `--` separator workaround
5377 // does not fix the typed slot's accepted set; the gate rejects
5378 // the shape upstream at validate time so the resolver never
5379 // invokes a `git clone -…` subprocess.
5380 let d = dep_with_fonte(DepSource::Git {
5381 repo: "-upload-pack=evil".into(),
5382 tag: Some("v0.1.0".into()),
5383 rev: None,
5384 branch: None,
5385 });
5386 let err = d.validate().unwrap_err();
5387 let DepError::FonteRepoShape { repo, reason, .. } = err else {
5388 panic!("expected FonteRepoShape, got other variant");
5389 };
5390 assert_eq!(repo, "-upload-pack=evil");
5391 assert!(
5392 reason.contains("must not start with `-`"),
5393 "reason must surface the leading-`-` arm, got {reason:?}"
5394 );
5395 }
5396
5397 #[test]
5398 fn validate_rejects_git_fonte_with_repo_carrying_embedded_newline() {
5399 // The canonical paste-from-multiline-doc footgun — a `:repo`
5400 // string with an embedded `\n` silently breaks git's URL parser
5401 // and is a class of CRLF-injection at the subprocess-argument
5402 // boundary. Caught by the control-char arm (0x0A < 0x20).
5403 let d = dep_with_fonte(DepSource::Git {
5404 repo: "github:pleme-io/caixa-teia\nrm -rf /".into(),
5405 tag: Some("v0.1.0".into()),
5406 rev: None,
5407 branch: None,
5408 });
5409 let err = d.validate().unwrap_err();
5410 let DepError::FonteRepoShape { reason, .. } = err else {
5411 panic!("expected FonteRepoShape, got other variant");
5412 };
5413 assert!(
5414 reason.contains("control character"),
5415 "reason must surface the control-char arm, got {reason:?}"
5416 );
5417 }
5418
5419 #[test]
5420 fn validate_rejects_git_fonte_with_repo_carrying_tab() {
5421 // Tab is the sibling whitespace footgun (the canonical
5422 // copy-from-aligned-table paste); pinned separately from the
5423 // space arm so a future relaxation that only catches one
5424 // surfaces here.
5425 let d = dep_with_fonte(DepSource::Git {
5426 repo: "github:pleme-io/caixa-teia\t".into(),
5427 tag: Some("v0.1.0".into()),
5428 rev: None,
5429 branch: None,
5430 });
5431 let err = d.validate().unwrap_err();
5432 assert!(
5433 matches!(
5434 err,
5435 DepError::FonteRepoShape { ref reason, .. }
5436 if reason.contains("whitespace")
5437 ),
5438 "got {err:?}"
5439 );
5440 }
5441
5442 #[test]
5443 fn validate_rejects_git_fonte_with_repo_carrying_non_ascii() {
5444 // IDN hosts must be pre-encoded as Punycode (`xn--…`) — raw
5445 // non-ASCII silently breaks at git's URL parser and round-trips
5446 // inconsistently across NFC/NFD normalization on APFS /
5447 // case-folding filesystems. Same intersection-floor
5448 // [`is_git_ref_name`] enforces on the refname axes.
5449 let d = dep_with_fonte(DepSource::Git {
5450 repo: "https://github.com/pleme-io/café".into(),
5451 tag: Some("v0.1.0".into()),
5452 rev: None,
5453 branch: None,
5454 });
5455 let err = d.validate().unwrap_err();
5456 assert!(
5457 matches!(
5458 err,
5459 DepError::FonteRepoShape { ref reason, .. }
5460 if reason.contains("non-ASCII")
5461 ),
5462 "got {err:?}"
5463 );
5464 }
5465
5466 #[test]
5467 fn validate_rejects_git_fonte_with_repo_carrying_fragment_anchor() {
5468 // The fail-before-pass-after pin for the canonical paste-from-
5469 // browser-address-bar footgun on `:repo`: an author copies a
5470 // GitHub permalink to a README anchor / line-permalink and
5471 // forgets to trim the `#fragment` tail. Until this arm landed
5472 // `:repo "https://github.com/pleme-io/caixa-teia#readme"`
5473 // silently passed every prior arm (no whitespace, no control
5474 // chars, no non-ASCII, contains a `:`, doesn't start with `-`
5475 // or `:`), libcurl's URL parser stripped the `#readme` tail
5476 // before opening the HTTPS transport, and the lacre embedded
5477 // the value verbatim in its per-dep BLAKE3 closure — two
5478 // authors whose values differ only in their fragment anchor
5479 // (`#readme` vs `#L42`) resolve to the byte-identical upstream
5480 // `git clone` but lock to two distinct lacres, defeating the
5481 // THEORY.md §V.2 render-determinism contract. Same value-shape
5482 // axis-floor every peer typed surface enforces; peer `:fonte
5483 // :tag` / `:fonte :branch` already reject the byte-class through
5484 // `is_git_ref_name`'s alphabet (refs are leaf identifiers, no
5485 // URL grammar admitted) and `:entrada :paths` rejects `#` as
5486 // part of `is_gateway_api_http_path`'s RFC-3986-reserved set.
5487 let d = dep_with_fonte(DepSource::Git {
5488 repo: "https://github.com/pleme-io/caixa-teia#readme".into(),
5489 tag: Some("v0.1.0".into()),
5490 rev: None,
5491 branch: None,
5492 });
5493 let err = d.validate().unwrap_err();
5494 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5495 panic!("expected FonteRepoShape, got other variant");
5496 };
5497 assert_eq!(nome, "caixa-teia");
5498 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia#readme");
5499 assert!(
5500 reason.contains("must not contain `#`"),
5501 "reason must surface the fragment-`#` arm, got {reason:?}"
5502 );
5503 assert!(
5504 reason.contains("fragment"),
5505 "reason must name the URL fragment grammar, got {reason:?}"
5506 );
5507 }
5508
5509 #[test]
5510 fn validate_rejects_git_fonte_with_repo_carrying_flake_ref_fragment() {
5511 // The symmetric paste-from-Nix-flake-ref footgun — an author
5512 // confuses the Nix flake-reference idiom (`github:foo/
5513 // bar#packageName`, where `#packageName` selects a flake
5514 // output) with the bare git `:repo` shape. The pleme-io
5515 // substrate authors compose flakes downstream of caixa
5516 // (caixa-flake renders a flake.nix), so the cross-idiom leak
5517 // is the canonical near-miss: the author writes the
5518 // flake-ref shape into a git `:repo` slot. Pinned separately
5519 // from the HTTPS-anchor arm so a future relaxation that
5520 // narrows to one URL scheme surfaces here.
5521 let d = dep_with_fonte(DepSource::Git {
5522 repo: "github:pleme-io/caixa-teia#caixa-teia".into(),
5523 tag: Some("v0.1.0".into()),
5524 rev: None,
5525 branch: None,
5526 });
5527 let err = d.validate().unwrap_err();
5528 let DepError::FonteRepoShape { reason, .. } = err else {
5529 panic!("expected FonteRepoShape, got other variant");
5530 };
5531 assert!(
5532 reason.contains("must not contain `#`"),
5533 "reason must surface the fragment-`#` arm, got {reason:?}"
5534 );
5535 assert!(
5536 reason.contains("Nix flake"),
5537 "reason must name the Nix-flake-ref cross-idiom footgun, got {reason:?}"
5538 );
5539 }
5540
5541 #[test]
5542 fn validate_rejects_git_fonte_with_repo_carrying_query_string() {
5543 // The fail-before-pass-after pin for the canonical paste-from-
5544 // browser-address-bar footgun on `:repo` (peer with the
5545 // a68f818 fragment-`#` arm on the same axis). An author
5546 // copies a GitHub tab deep-link out of the address bar and
5547 // forgets to trim the `?tab=…` query tail. Until this arm
5548 // landed `:repo "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"`
5549 // silently passed every prior arm (no whitespace, no control
5550 // chars, no non-ASCII, no `#` fragment, contains a `:`,
5551 // doesn't start with `-` or `:`); GitHub silently ignored
5552 // the `?query` tail and served the same repo regardless;
5553 // the lacre embedded the value verbatim in its per-dep
5554 // BLAKE3 closure — two authors whose values differ only in
5555 // their query tail (`?tab=readme-ov-file` vs `?ref=main` vs
5556 // `?utm_source=twitter`) resolve to the byte-identical
5557 // upstream `git clone` but lock to two distinct lacres,
5558 // defeating the THEORY.md §V.2 render-determinism contract
5559 // on the same axis the `#` fragment arm closes. Same value-
5560 // shape axis-floor every peer typed surface enforces; peer
5561 // `:fonte :tag` / `:fonte :branch` already reject the byte-
5562 // class through `is_git_ref_name`'s alphabet (refspec glob
5563 // wildcards, caixa-core/src/render.rs:1426) and `:entrada
5564 // :paths` rejects `?` as the query separator in
5565 // `is_gateway_api_http_path` (caixa-core/src/render.rs:473).
5566 let d = dep_with_fonte(DepSource::Git {
5567 repo: "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file".into(),
5568 tag: Some("v0.1.0".into()),
5569 rev: None,
5570 branch: None,
5571 });
5572 let err = d.validate().unwrap_err();
5573 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5574 panic!("expected FonteRepoShape, got other variant");
5575 };
5576 assert_eq!(nome, "caixa-teia");
5577 assert_eq!(
5578 repo,
5579 "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"
5580 );
5581 assert!(
5582 reason.contains("must not contain `?`"),
5583 "reason must surface the query-`?` arm, got {reason:?}"
5584 );
5585 assert!(
5586 reason.contains("query"),
5587 "reason must name the URL query grammar, got {reason:?}"
5588 );
5589 }
5590
5591 #[test]
5592 fn validate_rejects_git_fonte_with_repo_carrying_utm_tracker() {
5593 // The symmetric paste-from-social-share footgun — an author
5594 // copies a repo URL out of a Slack unfurl / Twitter share /
5595 // newsletter link / Discord embed and forgets to trim the
5596 // `?utm_source=…` / `?utm_medium=…` / `?utm_campaign=…`
5597 // campaign-tracker tail. Every major social-share / unfurl /
5598 // newsletter platform appends these UTM parameters; the
5599 // canonical near-miss on the `:repo` axis. Pinned separately
5600 // from the GitHub-tab-deep-link arm so a future relaxation
5601 // that narrows to one query-parameter class surfaces here.
5602 let d = dep_with_fonte(DepSource::Git {
5603 repo: "https://github.com/pleme-io/caixa-teia?utm_source=twitter&utm_campaign=launch"
5604 .into(),
5605 tag: Some("v0.1.0".into()),
5606 rev: None,
5607 branch: None,
5608 });
5609 let err = d.validate().unwrap_err();
5610 let DepError::FonteRepoShape { reason, .. } = err else {
5611 panic!("expected FonteRepoShape, got other variant");
5612 };
5613 assert!(
5614 reason.contains("must not contain `?`"),
5615 "reason must surface the query-`?` arm, got {reason:?}"
5616 );
5617 assert!(
5618 reason.contains("campaign-tracker"),
5619 "reason must name the campaign-tracker paste footgun, got {reason:?}"
5620 );
5621 }
5622
5623 #[test]
5624 fn fonte_repo_fragment_fires_before_query_when_fragment_first() {
5625 // Cascade pin: the fragment-`#` arm and the query-`?` arm are
5626 // both per-byte arms inside the same `for &b in s.as_bytes()`
5627 // loop, so the byte that appears first in the value's byte
5628 // order wins. A `:repo "https://github.com/p/x#readme?ref=main"`
5629 // (fragment before query — unusual URL-grammar but value-
5630 // disjoint at byte level) carries both `#` and `?`; the `#`
5631 // byte appears first, so the fragment-`#` arm fires, surfacing
5632 // the more self-locating diagnostic on the byte the author
5633 // pasted earliest in the URL. Mirrors the peer cascade
5634 // discipline `fonte_repo_control_char_fires_before_fragment`
5635 // pins on the prior `:repo` byte-class arm.
5636 let d = dep_with_fonte(DepSource::Git {
5637 repo: "https://github.com/pleme-io/caixa-teia#readme?ref=main".into(),
5638 tag: Some("v0.1.0".into()),
5639 rev: None,
5640 branch: None,
5641 });
5642 let err = d.validate().unwrap_err();
5643 let DepError::FonteRepoShape { reason, .. } = err else {
5644 panic!("expected FonteRepoShape, got other variant");
5645 };
5646 assert!(
5647 reason.contains("must not contain `#`"),
5648 "reason must surface the fragment-`#` arm (fires before query-`?` when \
5649 `#` byte appears first in value), got {reason:?}"
5650 );
5651 }
5652
5653 #[test]
5654 fn fonte_repo_control_char_fires_before_fragment() {
5655 // Cascade pin: the control-char arm structurally precedes the
5656 // fragment-`#` arm. A value like `"github:p/x\n#readme"` probes
5657 // positive on both arms (contains LF and `#`), but the narrower
5658 // POSIX-syscall-rejected / CRLF-injection-class diagnostic
5659 // (`control character`) wins so the author sees the more
5660 // self-locating arm first. Mirrors the peer cascade discipline
5661 // every prior `:repo` byte-class arm establishes.
5662 let d = dep_with_fonte(DepSource::Git {
5663 repo: "github:pleme-io/caixa-teia\n#readme".into(),
5664 tag: Some("v0.1.0".into()),
5665 rev: None,
5666 branch: None,
5667 });
5668 let err = d.validate().unwrap_err();
5669 let DepError::FonteRepoShape { reason, .. } = err else {
5670 panic!("expected FonteRepoShape, got other variant");
5671 };
5672 assert!(
5673 reason.contains("control character"),
5674 "reason must surface the control-char arm, got {reason:?}"
5675 );
5676 }
5677
5678 #[test]
5679 fn validate_rejects_git_fonte_with_repo_carrying_embedded_backslash() {
5680 // The fail-before-pass-after pin for the canonical Windows-
5681 // file-path-confusion footgun on `:repo` (peer with the 3a4e1d7
5682 // backslash arm on the sibling `:caminho` path-fonte axis).
5683 // An author pastes a Windows Explorer address-bar / PowerShell
5684 // `Get-Location` output into a `file://` URL slot, producing
5685 // `file:///C:\Users\me\caixa-teia`. Until this arm landed the
5686 // value silently passed every prior arm (no whitespace, no
5687 // control chars, no non-ASCII, no `#`, no `?`, doesn't start
5688 // with `-` or `:`); libcurl's URL parser silently translates
5689 // `\` → `/` on some platforms and refuses it on others, so
5690 // the byte rides verbatim into the lacre's per-dep content-
5691 // address but is silently rewritten / rejected at the wire —
5692 // two authors whose `:repo` values differ only in backslash-
5693 // vs-forward-slash (`file:///C:\path` vs `file:///C:/path`)
5694 // resolve to the byte-identical local clone but lock to two
5695 // distinct BLAKE3 closures, defeating the THEORY.md §V.2
5696 // render-determinism contract on the same axis the `#`
5697 // fragment and `?` query arms close. Same value-shape axis-
5698 // floor every peer typed surface enforces; the `:caminho`
5699 // 3a4e1d7 arm closes the same byte on the path-fonte axis.
5700 let d = dep_with_fonte(DepSource::Git {
5701 repo: "file:///C:\\Users\\me\\caixa-teia".into(),
5702 tag: Some("v0.1.0".into()),
5703 rev: None,
5704 branch: None,
5705 });
5706 let err = d.validate().unwrap_err();
5707 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5708 panic!("expected FonteRepoShape, got other variant");
5709 };
5710 assert_eq!(nome, "caixa-teia");
5711 assert_eq!(repo, "file:///C:\\Users\\me\\caixa-teia");
5712 assert!(
5713 reason.contains("must not contain `\\`"),
5714 "reason must surface the backslash-`\\` arm, got {reason:?}"
5715 );
5716 assert!(
5717 reason.contains("Windows"),
5718 "reason must name the Windows-path-confusion footgun, got {reason:?}"
5719 );
5720 }
5721
5722 #[test]
5723 fn validate_rejects_git_fonte_with_repo_carrying_mangled_https_backslashes() {
5724 // The symmetric Win32-shell-mangled-slashes footgun — an author
5725 // copies `https://github.com/foo/bar` into a Win32 shell that
5726 // rewrites every `/` to `\` (the canonical `cmd.exe` path-
5727 // separator-coercion bug), pastes the result into a `:repo`
5728 // slot, and produces `https:\\github.com\foo\bar`. Pinned
5729 // separately from the `file://` Explorer-paste arm so a future
5730 // relaxation that narrows to one URL scheme surfaces here.
5731 let d = dep_with_fonte(DepSource::Git {
5732 repo: "https:\\\\github.com\\pleme-io\\caixa-teia".into(),
5733 tag: Some("v0.1.0".into()),
5734 rev: None,
5735 branch: None,
5736 });
5737 let err = d.validate().unwrap_err();
5738 let DepError::FonteRepoShape { reason, .. } = err else {
5739 panic!("expected FonteRepoShape, got other variant");
5740 };
5741 assert!(
5742 reason.contains("must not contain `\\`"),
5743 "reason must surface the backslash-`\\` arm, got {reason:?}"
5744 );
5745 assert!(
5746 reason.contains("path separator") || reason.contains("path-segment separator"),
5747 "reason must name the URL path-segment separator grammar, got {reason:?}"
5748 );
5749 }
5750
5751 #[test]
5752 fn fonte_repo_fragment_fires_before_backslash_when_fragment_first() {
5753 // Cascade pin: the fragment-`#` arm and the backslash-`\` arm
5754 // are both per-byte arms inside the same `for &b in s.as_bytes()`
5755 // loop, so the byte that appears first in the value's byte order
5756 // wins. A `:repo "https://github.com/p/x#readme\\foo"` carries
5757 // both `#` and `\`; the `#` byte appears first, so the fragment-
5758 // `#` arm fires, surfacing the more self-locating diagnostic on
5759 // the byte the author pasted earliest in the URL. Mirrors the
5760 // peer cascade discipline `fonte_repo_fragment_fires_before_query_when_fragment_first`
5761 // pins on the prior `:repo` byte-class arm.
5762 let d = dep_with_fonte(DepSource::Git {
5763 repo: "https://github.com/pleme-io/caixa-teia#readme\\foo".into(),
5764 tag: Some("v0.1.0".into()),
5765 rev: None,
5766 branch: None,
5767 });
5768 let err = d.validate().unwrap_err();
5769 let DepError::FonteRepoShape { reason, .. } = err else {
5770 panic!("expected FonteRepoShape, got other variant");
5771 };
5772 assert!(
5773 reason.contains("must not contain `#`"),
5774 "reason must surface the fragment-`#` arm (fires before backslash-`\\` when \
5775 `#` byte appears first in value), got {reason:?}"
5776 );
5777 }
5778
5779 #[test]
5780 fn validate_rejects_git_fonte_with_repo_carrying_uri_template_placeholder() {
5781 // The fail-before-pass-after pin for the canonical URI Template
5782 // (RFC 6570) placeholder footgun on `:repo`. An author copies a
5783 // README quick-start snippet / OpenAPI `servers:` URL / Helm
5784 // chart `home:` template that carries unresolved
5785 // `{org}` / `{repo}` placeholders and pastes the raw template
5786 // into the `:repo` slot, expecting the substrate to resolve the
5787 // placeholder downstream. Until this arm landed the value
5788 // silently passed every prior arm (no whitespace, no control
5789 // chars, no non-ASCII, no `#`, no `?`, no `\`, doesn't start
5790 // with `-` or `:`); libcurl percent-encodes `{` / `}` to `%7B`
5791 // / `%7D` on the wire, so the byte rides verbatim into the
5792 // lacre's per-dep content-address but round-trips inconsistently
5793 // between the lacre's per-dep content-address and the
5794 // resolver's `git clone <repo>` invocation, defeating the
5795 // THEORY.md §V.2 render-determinism contract on the same axis
5796 // the `#` fragment, `?` query, and `\` backslash arms close;
5797 // every git porcelain entry-point additionally fetches a
5798 // nonexistent literal-`{placeholder}`-named path far from the
5799 // source caixa.lisp.
5800 let d = dep_with_fonte(DepSource::Git {
5801 repo: "https://github.com/{org}/caixa-teia".into(),
5802 tag: Some("v0.1.0".into()),
5803 rev: None,
5804 branch: None,
5805 });
5806 let err = d.validate().unwrap_err();
5807 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5808 panic!("expected FonteRepoShape, got other variant");
5809 };
5810 assert_eq!(nome, "caixa-teia");
5811 assert_eq!(repo, "https://github.com/{org}/caixa-teia");
5812 assert!(
5813 reason.contains("must not contain `{`"),
5814 "reason must surface the open-brace `{{` arm, got {reason:?}"
5815 );
5816 assert!(
5817 reason.contains("URI Template") || reason.contains("RFC 6570"),
5818 "reason must name the RFC 6570 URI Template grammar, got {reason:?}"
5819 );
5820 }
5821
5822 #[test]
5823 fn validate_rejects_git_fonte_with_repo_carrying_handlebars_doubled_brace() {
5824 // The symmetric Mustache / Handlebars doubled-brace
5825 // substitution-form footgun every CI / IaC templating engine
5826 // (Argo Workflows, Jinja2, Liquid, Vue / Angular interpolation,
5827 // GitHub Actions `${{ … }}` even though Actions uses `${{`) /
5828 // chart README quick-start snippet emits. Pinned separately
5829 // from the single-`{` `{org}` arm so a future relaxation that
5830 // narrows to one substitution-form surfaces here.
5831 let d = dep_with_fonte(DepSource::Git {
5832 repo: "https://github.com/{{org}}/caixa-teia".into(),
5833 tag: Some("v0.1.0".into()),
5834 rev: None,
5835 branch: None,
5836 });
5837 let err = d.validate().unwrap_err();
5838 let DepError::FonteRepoShape { reason, .. } = err else {
5839 panic!("expected FonteRepoShape, got other variant");
5840 };
5841 assert!(
5842 reason.contains("must not contain `{`"),
5843 "reason must surface the open-brace `{{` arm, got {reason:?}"
5844 );
5845 }
5846
5847 #[test]
5848 fn validate_rejects_git_fonte_with_repo_carrying_closing_brace_only() {
5849 // Asymmetric `}`-only shape — covers the closing-brace-by-
5850 // itself footgun (an author truncated `{org}/{repo}` mid-edit
5851 // and left a trailing `}` from the prior template fragment,
5852 // or pasted a value that included a closing brace from a
5853 // surrounding shell context). Pinned to ensure the predicate
5854 // refuses each brace independently rather than only when both
5855 // appear — a future regression that ANDs the two byte tests
5856 // surfaces here.
5857 let d = dep_with_fonte(DepSource::Git {
5858 repo: "https://github.com/pleme-io/caixa-teia}".into(),
5859 tag: Some("v0.1.0".into()),
5860 rev: None,
5861 branch: None,
5862 });
5863 let err = d.validate().unwrap_err();
5864 let DepError::FonteRepoShape { reason, .. } = err else {
5865 panic!("expected FonteRepoShape, got other variant");
5866 };
5867 assert!(
5868 reason.contains("must not contain `}`"),
5869 "reason must surface the close-brace `}}` arm, got {reason:?}"
5870 );
5871 }
5872
5873 #[test]
5874 fn fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first() {
5875 // Cascade pin: the fragment-`#` arm and the template-`{` /
5876 // `}` arm are both per-byte arms inside the same
5877 // `for &b in s.as_bytes()` loop, so the byte that appears
5878 // first in the value's byte order wins. A `:repo
5879 // "https://github.com/p/x#readme{org}"` carries both `#` and
5880 // `{`; the `#` byte appears first, so the fragment-`#` arm
5881 // fires, surfacing the more self-locating diagnostic on the
5882 // byte the author pasted earliest in the URL. Mirrors the
5883 // peer cascade discipline `fonte_repo_fragment_fires_before_backslash_when_fragment_first`
5884 // pins on the prior `:repo` byte-class arm.
5885 let d = dep_with_fonte(DepSource::Git {
5886 repo: "https://github.com/pleme-io/caixa-teia#readme{org}".into(),
5887 tag: Some("v0.1.0".into()),
5888 rev: None,
5889 branch: None,
5890 });
5891 let err = d.validate().unwrap_err();
5892 let DepError::FonteRepoShape { reason, .. } = err else {
5893 panic!("expected FonteRepoShape, got other variant");
5894 };
5895 assert!(
5896 reason.contains("must not contain `#`"),
5897 "reason must surface the fragment-`#` arm (fires before template-`{{` when \
5898 `#` byte appears first in value), got {reason:?}"
5899 );
5900 }
5901
5902 #[test]
5903 fn validate_rejects_git_fonte_with_repo_carrying_output_redirection() {
5904 // The fail-before-pass-after pin for the canonical
5905 // shell-output-redirection footgun on `:repo`: an author
5906 // pastes a shell-pipeline tail (`git clone <repo> > build.log`
5907 // / `… >output.txt`) into the `:repo` slot without trimming
5908 // the redirect. Until this arm landed the value silently
5909 // passed every prior arm (no whitespace, no control chars,
5910 // no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, doesn't
5911 // start with `-` or `:`); RFC 3986 §2 lists `<` / `>` in the
5912 // 'delims' / 'unwise' set and the WHATWG URL spec's fragment
5913 // percent-encode set maps `>` → `%3E` on the wire, so the
5914 // byte rides verbatim into the lacre's per-dep BLAKE3 closure
5915 // but is silently rewritten or rejected at libcurl's URL-
5916 // parser layer — two authors whose values differ only in
5917 // their redirect tail (`>build.log` vs nothing) resolve to
5918 // the byte-identical upstream `git clone` but lock to two
5919 // distinct lacres, defeating the THEORY.md §V.2 render-
5920 // determinism contract. Peer with the `:caminho` axis's
5921 // `FonteCaminhoShellRedirection` arm (e457141) on the sibling
5922 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5923 // byte RFC-3986-reserved set on `:entrada :paths`.
5924 let d = dep_with_fonte(DepSource::Git {
5925 repo: "https://github.com/pleme-io/caixa-teia>build.log".into(),
5926 tag: Some("v0.1.0".into()),
5927 rev: None,
5928 branch: None,
5929 });
5930 let err = d.validate().unwrap_err();
5931 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5932 panic!("expected FonteRepoShape, got other variant");
5933 };
5934 assert_eq!(nome, "caixa-teia");
5935 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia>build.log");
5936 assert!(
5937 reason.contains("must not contain `>`"),
5938 "reason must surface the output-redirection `>` arm, got {reason:?}"
5939 );
5940 assert!(
5941 reason.contains("redirection") || reason.contains("'delims'"),
5942 "reason must name the shell-redirection / RFC-3986-unwise rationale, got {reason:?}"
5943 );
5944 }
5945
5946 #[test]
5947 fn validate_rejects_git_fonte_with_repo_carrying_input_redirection() {
5948 // The symmetric shell-input-redirection footgun — an author
5949 // pastes a shell-pipeline head (`git clone <input.url` /
5950 // `cat <README.md`) into the `:repo` slot. Pinned separately
5951 // from the `>`-output arm so a future relaxation that only
5952 // catches one of the two redirect bytes surfaces here. Peer
5953 // with the `:caminho` axis's `FonteCaminhoShellRedirection`
5954 // arm which closes both `<` and `>` under the same banner.
5955 let d = dep_with_fonte(DepSource::Git {
5956 repo: "https://github.com/pleme-io/caixa-teia<input.url".into(),
5957 tag: Some("v0.1.0".into()),
5958 rev: None,
5959 branch: None,
5960 });
5961 let err = d.validate().unwrap_err();
5962 let DepError::FonteRepoShape { reason, .. } = err else {
5963 panic!("expected FonteRepoShape, got other variant");
5964 };
5965 assert!(
5966 reason.contains("must not contain `<`"),
5967 "reason must surface the input-redirection `<` arm, got {reason:?}"
5968 );
5969 assert!(
5970 reason.contains("RFC 3986") || reason.contains("'unwise'"),
5971 "reason must name the RFC 3986 'unwise' grammar, got {reason:?}"
5972 );
5973 }
5974
5975 #[test]
5976 fn validate_rejects_git_fonte_with_repo_carrying_backtick_command_substitution() {
5977 // The fail-before-pass-after pin for the canonical
5978 // paste-from-shell-prompt-with-backticked-substitution footgun
5979 // on `:repo` (peer with the c4d62b3 backtick arm on the sibling
5980 // `:caminho` path-fonte axis). An author pastes a URL whose
5981 // segment carries a backticked command-substitution wrapper
5982 // (`` `whoami` ``, `` `git config user.name` ``, `` `pwd` ``)
5983 // from a doc / README quick-start snippet that expected the
5984 // substrate to substitute the value downstream. Until this arm
5985 // landed the value silently passed every prior arm (no
5986 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5987 // no `\`, no `{`/`}`, no `<`/`>`, doesn't start with `-` or
5988 // `:`); RFC 3986 §2 lists the backtick byte in the 'delims' /
5989 // 'unwise' set and the WHATWG URL spec's fragment percent-
5990 // encode set maps `` ` `` → `%60` on the wire, so the byte
5991 // rides verbatim into the lacre's per-dep BLAKE3 closure but
5992 // is silently rewritten or rejected at libcurl's URL-parser
5993 // layer — two authors whose values differ only in their
5994 // backtick wrapper (`` `whoami` `` vs nothing) resolve to the
5995 // byte-identical upstream `git clone` but lock to two distinct
5996 // lacres, defeating the THEORY.md §V.2 render-determinism
5997 // contract. Peer with the `:caminho` axis's
5998 // `FonteCaminhoShellCommandSubstitution` arm (c4d62b3) on the
5999 // sibling path-fonte axis, and `is_gateway_api_http_path`'s
6000 // eleven-byte RFC-3986-reserved set on `:entrada :paths`.
6001 let d = dep_with_fonte(DepSource::Git {
6002 repo: "https://github.com/pleme-io/`whoami`/caixa-teia".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 { nome, repo, reason } = err else {
6009 panic!("expected FonteRepoShape, got other variant");
6010 };
6011 assert_eq!(nome, "caixa-teia");
6012 assert_eq!(repo, "https://github.com/pleme-io/`whoami`/caixa-teia");
6013 assert!(
6014 reason.contains("must not contain `` ` ``"),
6015 "reason must surface the backtick command-substitution arm, got {reason:?}"
6016 );
6017 assert!(
6018 reason.contains("command-substitution") || reason.contains("'unwise'"),
6019 "reason must name the shell-command-substitution / RFC-3986-unwise rationale, \
6020 got {reason:?}"
6021 );
6022 }
6023
6024 #[test]
6025 fn fonte_repo_fragment_fires_before_backtick_when_fragment_first() {
6026 // Cascade pin: the fragment-`#` arm and the backtick command-
6027 // substitution arm are both per-byte arms inside the same
6028 // `for &b in s.as_bytes()` loop, so the byte that appears first
6029 // in the value's byte order wins. A `:repo
6030 // "https://github.com/p/x#readme/`whoami`"` carries both `#`
6031 // and backtick; the `#` byte appears first, so the fragment-
6032 // `#` arm fires, surfacing the more self-locating diagnostic
6033 // on the byte the author pasted earliest in the URL. Mirrors
6034 // the peer cascade discipline
6035 // `fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first`
6036 // pins on the prior `:repo` byte-class arm.
6037 let d = dep_with_fonte(DepSource::Git {
6038 repo: "https://github.com/pleme-io/caixa-teia#readme/`whoami`".into(),
6039 tag: Some("v0.1.0".into()),
6040 rev: None,
6041 branch: None,
6042 });
6043 let err = d.validate().unwrap_err();
6044 let DepError::FonteRepoShape { reason, .. } = err else {
6045 panic!("expected FonteRepoShape, got other variant");
6046 };
6047 assert!(
6048 reason.contains("must not contain `#`"),
6049 "reason must surface the fragment-`#` arm (fires before backtick when `#` byte \
6050 appears first in value), got {reason:?}"
6051 );
6052 }
6053
6054 #[test]
6055 fn fonte_repo_shell_redirection_fires_before_backtick_when_redirection_first() {
6056 // Cascade pin: the shell-redirection `<` / `>` arm and the
6057 // backtick command-substitution arm are both per-byte arms
6058 // inside the same `for &b in s.as_bytes()` loop, so the byte
6059 // that appears first in the value's byte order wins. A `:repo
6060 // "https://github.com/p/x>build.log/`whoami`"` carries both
6061 // `>` and backtick; the `>` byte appears first, so the
6062 // shell-redirection arm fires, surfacing the more self-
6063 // locating diagnostic on the byte the author pasted earliest
6064 // in the URL. Pins the natural-order cascade so a future
6065 // reorder of the per-byte arms surfaces here.
6066 let d = dep_with_fonte(DepSource::Git {
6067 repo: "https://github.com/pleme-io/caixa-teia>build.log/`whoami`".into(),
6068 tag: Some("v0.1.0".into()),
6069 rev: None,
6070 branch: None,
6071 });
6072 let err = d.validate().unwrap_err();
6073 let DepError::FonteRepoShape { reason, .. } = err else {
6074 panic!("expected FonteRepoShape, got other variant");
6075 };
6076 assert!(
6077 reason.contains("must not contain `>`"),
6078 "reason must surface the shell-redirection `>` arm (fires before backtick when \
6079 `>` byte appears first in value), got {reason:?}"
6080 );
6081 }
6082
6083 #[test]
6084 fn fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first() {
6085 // Cascade pin: the fragment-`#` arm and the shell-redirection
6086 // `<` / `>` arm are both per-byte arms inside the same
6087 // `for &b in s.as_bytes()` loop, so the byte that appears
6088 // first in the value's byte order wins. A `:repo
6089 // "https://github.com/p/x#readme>build.log"` carries both
6090 // `#` and `>`; the `#` byte appears first, so the fragment-
6091 // `#` arm fires, surfacing the more self-locating diagnostic
6092 // on the byte the author pasted earliest in the URL. Mirrors
6093 // the peer cascade discipline
6094 // `fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first`
6095 // pins on the prior `:repo` byte-class arm.
6096 let d = dep_with_fonte(DepSource::Git {
6097 repo: "https://github.com/pleme-io/caixa-teia#readme>build.log".into(),
6098 tag: Some("v0.1.0".into()),
6099 rev: None,
6100 branch: None,
6101 });
6102 let err = d.validate().unwrap_err();
6103 let DepError::FonteRepoShape { reason, .. } = err else {
6104 panic!("expected FonteRepoShape, got other variant");
6105 };
6106 assert!(
6107 reason.contains("must not contain `#`"),
6108 "reason must surface the fragment-`#` arm (fires before shell-redirection `>` when \
6109 `#` byte appears first in value), got {reason:?}"
6110 );
6111 }
6112
6113 #[test]
6114 fn validate_rejects_git_fonte_with_repo_carrying_shell_pipe() {
6115 // The fail-before-pass-after pin for the canonical
6116 // paste-from-shell-prompt-with-piped-pipeline footgun on
6117 // `:repo` (peer with the 124106f pipe arm on the sibling
6118 // `:caminho` path-fonte axis). An author pastes a shell
6119 // pipeline (`git clone <url> | tee build.log`,
6120 // `git ls-remote <url> | head`) into the `:repo` slot,
6121 // forgetting to trim the `| <consumer>` tail. Until this arm
6122 // landed the value silently passed every prior arm (no
6123 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
6124 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, doesn't start
6125 // with `-` or `:`); RFC 3986 §2 lists the pipe byte in the
6126 // 'unwise' set and the WHATWG URL spec's fragment percent-
6127 // encode set maps `|` → `%7C` on the wire, so the byte rides
6128 // verbatim into the lacre's per-dep BLAKE3 closure but is
6129 // silently rewritten or rejected at libcurl's URL-parser
6130 // layer — two authors whose values differ only in their pipe
6131 // tail (`|tee build.log` vs nothing) resolve to the byte-
6132 // identical upstream `git clone` but lock to two distinct
6133 // lacres, defeating the THEORY.md §V.2 render-determinism
6134 // contract. Peer with the `:caminho` axis's
6135 // `FonteCaminhoShellPipe` arm (124106f) on the sibling path-
6136 // fonte axis, and `is_gateway_api_http_path`'s eleven-byte
6137 // RFC-3986-reserved set on `:entrada :paths`.
6138 let d = dep_with_fonte(DepSource::Git {
6139 repo: "https://github.com/pleme-io/caixa-teia|tee build.log".into(),
6140 tag: Some("v0.1.0".into()),
6141 rev: None,
6142 branch: None,
6143 });
6144 let err = d.validate().unwrap_err();
6145 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6146 panic!("expected FonteRepoShape, got other variant");
6147 };
6148 assert_eq!(nome, "caixa-teia");
6149 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia|tee build.log");
6150 assert!(
6151 reason.contains("must not contain `|`"),
6152 "reason must surface the shell-pipe arm, got {reason:?}"
6153 );
6154 assert!(
6155 reason.contains("pipe") || reason.contains("'unwise'"),
6156 "reason must name the shell-pipe / RFC-3986-unwise rationale, got {reason:?}"
6157 );
6158 }
6159
6160 #[test]
6161 fn fonte_repo_fragment_fires_before_pipe_when_fragment_first() {
6162 // Cascade pin: the fragment-`#` arm and the pipe arm are both
6163 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6164 // so the byte that appears first in the value's byte order
6165 // wins. A `:repo "https://github.com/p/x#readme|tee"` carries
6166 // both `#` and `|`; the `#` byte appears first, so the
6167 // fragment-`#` arm fires, surfacing the more self-locating
6168 // diagnostic on the byte the author pasted earliest in the
6169 // URL. Mirrors the peer cascade discipline
6170 // `fonte_repo_fragment_fires_before_backtick_when_fragment_first`
6171 // pins on the prior `:repo` byte-class arm.
6172 let d = dep_with_fonte(DepSource::Git {
6173 repo: "https://github.com/pleme-io/caixa-teia#readme|tee".into(),
6174 tag: Some("v0.1.0".into()),
6175 rev: None,
6176 branch: None,
6177 });
6178 let err = d.validate().unwrap_err();
6179 let DepError::FonteRepoShape { reason, .. } = err else {
6180 panic!("expected FonteRepoShape, got other variant");
6181 };
6182 assert!(
6183 reason.contains("must not contain `#`"),
6184 "reason must surface the fragment-`#` arm (fires before pipe when `#` byte \
6185 appears first in value), got {reason:?}"
6186 );
6187 }
6188
6189 #[test]
6190 fn fonte_repo_backtick_fires_before_pipe_when_backtick_first() {
6191 // Cascade pin: the backtick arm and the pipe arm are both per-
6192 // byte arms inside the same `for &b in s.as_bytes()` loop, so
6193 // the byte that appears first in the value's byte order wins.
6194 // A `:repo "https://github.com/p/x/`whoami`|tee"` carries both
6195 // `` ` `` and `|`; the backtick byte appears first, so the
6196 // backtick arm fires, surfacing the more self-locating
6197 // diagnostic on the byte the author pasted earliest in the
6198 // URL. Pins the natural-order cascade so a future reorder of
6199 // the per-byte arms surfaces here.
6200 let d = dep_with_fonte(DepSource::Git {
6201 repo: "https://github.com/pleme-io/caixa-teia/`whoami`|tee".into(),
6202 tag: Some("v0.1.0".into()),
6203 rev: None,
6204 branch: None,
6205 });
6206 let err = d.validate().unwrap_err();
6207 let DepError::FonteRepoShape { reason, .. } = err else {
6208 panic!("expected FonteRepoShape, got other variant");
6209 };
6210 assert!(
6211 reason.contains("must not contain `` ` ``"),
6212 "reason must surface the backtick arm (fires before pipe when `` ` `` byte \
6213 appears first in value), got {reason:?}"
6214 );
6215 }
6216
6217 #[test]
6218 fn validate_rejects_git_fonte_with_repo_carrying_shell_command_separator() {
6219 // The fail-before-pass-after pin for the canonical
6220 // paste-from-shell-prompt-with-sequential-command-tail footgun
6221 // on `:repo` (peer with the 05c358e `;` arm on the sibling
6222 // `:caminho` path-fonte axis). An author pastes a shell
6223 // one-liner that chained a cleanup tail after the URL
6224 // (`git clone <url>; rm -rf build`, `git ls-remote <url>;
6225 // echo done`) into the `:repo` slot, forgetting to trim the
6226 // `; <cmd>` tail. Until this arm landed the value silently
6227 // passed every prior `is_git_repo_url` arm (no whitespace, no
6228 // control chars, no non-ASCII, no `#`, no `?`, no `\`, no
6229 // `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, doesn't start with
6230 // `-` or `:`); RFC 3986 §2 lists `;` in the 'sub-delims' /
6231 // reserved set and the WHATWG URL spec's fragment percent-
6232 // encode set maps `;` → `%3B` on the wire, so the byte rides
6233 // verbatim into the lacre's per-dep BLAKE3 closure but is
6234 // silently rewritten at libcurl's URL-parser layer — two
6235 // authors whose values differ only in their sequential-command
6236 // tail (`; rm -rf build` vs nothing) resolve to the byte-
6237 // identical upstream `git clone` but lock to two distinct
6238 // lacres, defeating the THEORY.md §V.2 render-determinism
6239 // contract. Peer with the `:caminho` axis's
6240 // `FonteCaminhoShellSemicolon` arm (05c358e) on the sibling
6241 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
6242 // byte RFC-3986-reserved set on `:entrada :paths`.
6243 let d = dep_with_fonte(DepSource::Git {
6244 repo: "https://github.com/pleme-io/caixa-teia; rm -rf build".into(),
6245 tag: Some("v0.1.0".into()),
6246 rev: None,
6247 branch: None,
6248 });
6249 let err = d.validate().unwrap_err();
6250 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6251 panic!("expected FonteRepoShape, got other variant");
6252 };
6253 assert_eq!(nome, "caixa-teia");
6254 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia; rm -rf build");
6255 assert!(
6256 reason.contains("must not contain `;`"),
6257 "reason must surface the shell-command-separator arm, got {reason:?}"
6258 );
6259 assert!(
6260 reason.contains("sequential-command") || reason.contains("'sub-delims'"),
6261 "reason must name the shell-command-separator / RFC-3986-sub-delims \
6262 rationale, got {reason:?}"
6263 );
6264 }
6265
6266 #[test]
6267 fn fonte_repo_fragment_fires_before_semicolon_when_fragment_first() {
6268 // Cascade pin: the fragment-`#` arm and the semicolon arm are
6269 // both per-byte arms inside the same `for &b in s.as_bytes()`
6270 // loop, so the byte that appears first in the value's byte
6271 // order wins. A `:repo "https://github.com/p/x#readme; rm"`
6272 // carries both `#` and `;`; the `#` byte appears first, so the
6273 // fragment-`#` arm fires, surfacing the more self-locating
6274 // diagnostic on the byte the author pasted earliest in the URL.
6275 // Mirrors the peer cascade discipline
6276 // `fonte_repo_fragment_fires_before_pipe_when_fragment_first`
6277 // pins on the prior `:repo` byte-class arm.
6278 let d = dep_with_fonte(DepSource::Git {
6279 repo: "https://github.com/pleme-io/caixa-teia#readme; rm".into(),
6280 tag: Some("v0.1.0".into()),
6281 rev: None,
6282 branch: None,
6283 });
6284 let err = d.validate().unwrap_err();
6285 let DepError::FonteRepoShape { reason, .. } = err else {
6286 panic!("expected FonteRepoShape, got other variant");
6287 };
6288 assert!(
6289 reason.contains("must not contain `#`"),
6290 "reason must surface the fragment-`#` arm (fires before semicolon when `#` \
6291 byte appears first in value), got {reason:?}"
6292 );
6293 }
6294
6295 #[test]
6296 fn fonte_repo_pipe_fires_before_semicolon_when_pipe_first() {
6297 // Cascade pin: the pipe arm and the semicolon arm are both
6298 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6299 // so the byte that appears first in the value's byte order
6300 // wins. A `:repo "https://github.com/p/x|tee; rm"` carries
6301 // both `|` and `;`; the `|` byte appears first, so the
6302 // pipe arm fires, surfacing the more self-locating diagnostic
6303 // on the byte the author pasted earliest in the URL. Pins the
6304 // natural-order cascade so a future reorder of the per-byte
6305 // arms surfaces here.
6306 let d = dep_with_fonte(DepSource::Git {
6307 repo: "https://github.com/pleme-io/caixa-teia|tee; rm".into(),
6308 tag: Some("v0.1.0".into()),
6309 rev: None,
6310 branch: None,
6311 });
6312 let err = d.validate().unwrap_err();
6313 let DepError::FonteRepoShape { reason, .. } = err else {
6314 panic!("expected FonteRepoShape, got other variant");
6315 };
6316 assert!(
6317 reason.contains("must not contain `|`"),
6318 "reason must surface the pipe arm (fires before semicolon when `|` byte \
6319 appears first in value), got {reason:?}"
6320 );
6321 }
6322
6323 #[test]
6324 fn validate_rejects_git_fonte_with_repo_carrying_shell_background() {
6325 // The fail-before-pass-after pin for the canonical
6326 // paste-from-shell-prompt-with-background-launch-tail footgun
6327 // on `:repo` (peer with the e12e4f3 `&` arm on the sibling
6328 // `:caminho` path-fonte axis). An author pastes a shell one-
6329 // liner that detached the clone into the background
6330 // (`git clone <url> & sleep 1`, `git clone <url> && cd …`)
6331 // into the `:repo` slot, forgetting to trim the `& <cmd>` /
6332 // `&& <cmd>` tail. Until this arm landed the value silently
6333 // passed every prior `is_git_repo_url` arm (no whitespace,
6334 // no control chars, no non-ASCII, no `#`, no `?`, no `\`,
6335 // no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6336 // doesn't start with `-` or `:`); RFC 3986 §2 lists `&` in
6337 // the 'sub-delims' / reserved set and the WHATWG URL spec's
6338 // fragment percent-encode set maps `&` → `%26` on the wire,
6339 // so the byte rides verbatim into the lacre's per-dep
6340 // BLAKE3 closure but is silently rewritten at libcurl's
6341 // URL-parser layer — two authors whose values differ only
6342 // in their background-launch tail (`& sleep 1` vs nothing)
6343 // resolve to the byte-identical upstream `git clone` but
6344 // lock to two distinct lacres, defeating the THEORY.md
6345 // §V.2 render-determinism contract. Peer with the
6346 // `:caminho` axis's `FonteCaminhoShellBackground` arm
6347 // (e12e4f3) on the sibling path-fonte axis, and
6348 // `is_gateway_api_http_path`'s eleven-byte RFC-3986-
6349 // reserved set on `:entrada :paths`.
6350 let d = dep_with_fonte(DepSource::Git {
6351 repo: "https://github.com/pleme-io/caixa-teia&sleep".into(),
6352 tag: Some("v0.1.0".into()),
6353 rev: None,
6354 branch: None,
6355 });
6356 let err = d.validate().unwrap_err();
6357 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6358 panic!("expected FonteRepoShape, got other variant");
6359 };
6360 assert_eq!(nome, "caixa-teia");
6361 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia&sleep");
6362 assert!(
6363 reason.contains("must not contain `&`"),
6364 "reason must surface the shell-background / logical-AND arm, got {reason:?}"
6365 );
6366 assert!(
6367 reason.contains("background-task") || reason.contains("'sub-delims'"),
6368 "reason must name the shell-background / RFC-3986-sub-delims rationale, \
6369 got {reason:?}"
6370 );
6371 }
6372
6373 #[test]
6374 fn validate_rejects_git_fonte_with_repo_carrying_logical_and() {
6375 // The fail-before-pass-after pin for the symmetric `&&`
6376 // logical-AND build-chain paste footgun: an author pastes
6377 // a `git clone <url> && cd <repo>` build-chain one-liner
6378 // and forgets to trim the `&& <cmd>` tail. The `&&` shape
6379 // is the same `&` byte twice in a row; the per-byte arm
6380 // fires on the first `&` it sees. Pinned separately from
6381 // the single-`&` background-launch shape so a future
6382 // diagnostic-surface change that special-cased the
6383 // doubled-byte form surfaces here.
6384 let d = dep_with_fonte(DepSource::Git {
6385 repo: "github:pleme-io/caixa-teia&&echo".into(),
6386 tag: Some("v0.1.0".into()),
6387 rev: None,
6388 branch: None,
6389 });
6390 let err = d.validate().unwrap_err();
6391 let DepError::FonteRepoShape { reason, .. } = err else {
6392 panic!("expected FonteRepoShape, got other variant");
6393 };
6394 assert!(
6395 reason.contains("must not contain `&`"),
6396 "reason must surface the shell-background / logical-AND arm on the doubled-`&&` \
6397 shape too, got {reason:?}"
6398 );
6399 }
6400
6401 #[test]
6402 fn fonte_repo_fragment_fires_before_background_when_fragment_first() {
6403 // Cascade pin: the fragment-`#` arm and the background-`&`
6404 // arm are both per-byte arms inside the same `for &b in
6405 // s.as_bytes()` loop, so the byte that appears first in the
6406 // value's byte order wins. A `:repo
6407 // "https://github.com/p/x#readme & sleep"` carries both `#`
6408 // and `&`; the `#` byte appears first, so the fragment-`#`
6409 // arm fires, surfacing the more self-locating diagnostic on
6410 // the byte the author pasted earliest in the URL. Mirrors
6411 // the peer cascade discipline
6412 // `fonte_repo_fragment_fires_before_semicolon_when_fragment_first`
6413 // on the prior `:repo` byte-class arm.
6414 let d = dep_with_fonte(DepSource::Git {
6415 repo: "https://github.com/pleme-io/caixa-teia#readme&sleep".into(),
6416 tag: Some("v0.1.0".into()),
6417 rev: None,
6418 branch: None,
6419 });
6420 let err = d.validate().unwrap_err();
6421 let DepError::FonteRepoShape { reason, .. } = err else {
6422 panic!("expected FonteRepoShape, got other variant");
6423 };
6424 assert!(
6425 reason.contains("must not contain `#`"),
6426 "reason must surface the fragment-`#` arm (fires before background-`&` when `#` \
6427 byte appears first in value), got {reason:?}"
6428 );
6429 }
6430
6431 #[test]
6432 fn fonte_repo_semicolon_fires_before_background_when_semicolon_first() {
6433 // Cascade pin: the semicolon arm and the background-`&` arm
6434 // are both per-byte arms inside the same `for &b in
6435 // s.as_bytes()` loop, so the byte that appears first in the
6436 // value's byte order wins. A `:repo
6437 // "https://github.com/p/x; rm & sleep"` carries both `;` and
6438 // `&`; the `;` byte appears first, so the semicolon arm
6439 // fires, surfacing the more self-locating diagnostic on the
6440 // byte the author pasted earliest in the URL. Pins the
6441 // natural-order cascade so a future reorder of the per-byte
6442 // arms surfaces here.
6443 let d = dep_with_fonte(DepSource::Git {
6444 repo: "https://github.com/pleme-io/caixa-teia;rm&sleep".into(),
6445 tag: Some("v0.1.0".into()),
6446 rev: None,
6447 branch: None,
6448 });
6449 let err = d.validate().unwrap_err();
6450 let DepError::FonteRepoShape { reason, .. } = err else {
6451 panic!("expected FonteRepoShape, got other variant");
6452 };
6453 assert!(
6454 reason.contains("must not contain `;`"),
6455 "reason must surface the semicolon arm (fires before background-`&` when `;` \
6456 byte appears first in value), got {reason:?}"
6457 );
6458 }
6459
6460 #[test]
6461 fn validate_rejects_git_fonte_with_repo_carrying_shell_variable_expansion() {
6462 // The fail-before-pass-after pin for the canonical
6463 // paste-from-shell-prompt-with-unsubstituted-variable footgun
6464 // on `:repo` (peer with the f4efe9c `$` arm on the sibling
6465 // `:caminho` path-fonte axis). An author pastes a shell one-
6466 // liner that referenced an environment variable
6467 // (`git clone https://github.com/$ORG/x`, `git clone
6468 // github:$USER/repo`) into the `:repo` slot, forgetting to
6469 // substitute the literal value at author time. Until this arm
6470 // landed the value silently passed every prior
6471 // `is_git_repo_url` arm (no whitespace, no control chars, no
6472 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6473 // no `` ` ``, no `|`, no `;`, no `&`, doesn't start with `-`
6474 // or `:`); RFC 3986 §2 lists `$` in the 'sub-delims' /
6475 // reserved set and the WHATWG URL spec's fragment percent-
6476 // encode set maps `$` → `%24` on the wire, so the byte rides
6477 // verbatim into the lacre's per-dep BLAKE3 closure but is
6478 // silently rewritten at libcurl's URL-parser layer — two
6479 // authors whose values differ only in their `$VAR` /
6480 // `${VAR}` / `$(cmd)` expansion tail resolve to the byte-
6481 // identical upstream `git clone` but lock to two distinct
6482 // lacres, defeating the THEORY.md §V.2 render-determinism
6483 // contract. Beyond determinism, the value is a structural
6484 // host-layout leak: two authors with the same `:repo` slot
6485 // but different `$ORG` / `$HOME` / `$WORKSPACE` resolve
6486 // different upstreams. Peer with the `:caminho` axis's
6487 // `FonteCaminhoVarExpansion` arm (f4efe9c) on the sibling
6488 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
6489 // byte RFC-3986-reserved set on `:entrada :paths`.
6490 let d = dep_with_fonte(DepSource::Git {
6491 repo: "https://github.com/$ORG/caixa-teia".into(),
6492 tag: Some("v0.1.0".into()),
6493 rev: None,
6494 branch: None,
6495 });
6496 let err = d.validate().unwrap_err();
6497 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6498 panic!("expected FonteRepoShape, got other variant");
6499 };
6500 assert_eq!(nome, "caixa-teia");
6501 assert_eq!(repo, "https://github.com/$ORG/caixa-teia");
6502 assert!(
6503 reason.contains("must not contain `$`"),
6504 "reason must surface the shell-variable-expansion arm, got {reason:?}"
6505 );
6506 assert!(
6507 reason.contains("variable-expansion") || reason.contains("'sub-delims'"),
6508 "reason must name the shell-variable-expansion / RFC-3986-sub-delims \
6509 rationale, got {reason:?}"
6510 );
6511 }
6512
6513 #[test]
6514 fn validate_rejects_git_fonte_with_repo_carrying_braced_variable_expansion() {
6515 // The fail-before-pass-after pin for the symmetric POSIX-
6516 // shell braced `${VAR}` expansion paste footgun: an author
6517 // pastes a CI-manifest line `git clone
6518 // https://github.com/${WORKSPACE}/x` (the canonical GitHub
6519 // Actions / GitLab CI / Drone shape) and forgets to
6520 // substitute the literal value. The `${...}` shape is the
6521 // same `$` byte at the leading position of the expansion;
6522 // the per-byte arm fires on the `$`. Pinned separately from
6523 // the bare-`$VAR` shape so a future diagnostic-surface
6524 // change that special-cased the braced form surfaces here.
6525 let d = dep_with_fonte(DepSource::Git {
6526 repo: "https://github.com/${WORKSPACE}/caixa-teia".into(),
6527 tag: Some("v0.1.0".into()),
6528 rev: None,
6529 branch: None,
6530 });
6531 let err = d.validate().unwrap_err();
6532 let DepError::FonteRepoShape { reason, .. } = err else {
6533 panic!("expected FonteRepoShape, got other variant");
6534 };
6535 assert!(
6536 reason.contains("must not contain `$`"),
6537 "reason must surface the shell-variable-expansion arm on the braced `${{...}}` \
6538 shape too, got {reason:?}"
6539 );
6540 }
6541
6542 #[test]
6543 fn fonte_repo_fragment_fires_before_var_expansion_when_fragment_first() {
6544 // Cascade pin: the fragment-`#` arm and the var-expansion-`$`
6545 // arm are both per-byte arms inside the same `for &b in
6546 // s.as_bytes()` loop, so the byte that appears first in the
6547 // value's byte order wins. A `:repo
6548 // "https://github.com/p/x#readme$HOME"` carries both `#` and
6549 // `$`; the `#` byte appears first, so the fragment-`#` arm
6550 // fires, surfacing the more self-locating diagnostic on the
6551 // byte the author pasted earliest in the URL. Mirrors the
6552 // peer cascade discipline
6553 // `fonte_repo_fragment_fires_before_background_when_fragment_first`
6554 // on the prior `:repo` byte-class arm.
6555 let d = dep_with_fonte(DepSource::Git {
6556 repo: "https://github.com/pleme-io/caixa-teia#readme$HOME".into(),
6557 tag: Some("v0.1.0".into()),
6558 rev: None,
6559 branch: None,
6560 });
6561 let err = d.validate().unwrap_err();
6562 let DepError::FonteRepoShape { reason, .. } = err else {
6563 panic!("expected FonteRepoShape, got other variant");
6564 };
6565 assert!(
6566 reason.contains("must not contain `#`"),
6567 "reason must surface the fragment-`#` arm (fires before var-expansion-`$` when \
6568 `#` byte appears first in value), got {reason:?}"
6569 );
6570 }
6571
6572 #[test]
6573 fn fonte_repo_background_fires_before_var_expansion_when_background_first() {
6574 // Cascade pin: the background-`&` arm and the
6575 // var-expansion-`$` arm are both per-byte arms inside the
6576 // same `for &b in s.as_bytes()` loop, so the byte that
6577 // appears first in the value's byte order wins. A `:repo
6578 // "https://github.com/p/x&sleep$HOME"` carries both `&` and
6579 // `$`; the `&` byte appears first, so the background arm
6580 // fires, surfacing the more self-locating diagnostic on the
6581 // byte the author pasted earliest in the URL. Pins the
6582 // natural-order cascade so a future reorder of the per-byte
6583 // arms surfaces here — `$` is the most recent byte-class arm,
6584 // so the cascade-pin sweep extends to cover every immediately
6585 // prior byte arm (`#`, `&`) firing first when ordered ahead
6586 // of `$` in the value.
6587 let d = dep_with_fonte(DepSource::Git {
6588 repo: "https://github.com/pleme-io/caixa-teia&sleep$HOME".into(),
6589 tag: Some("v0.1.0".into()),
6590 rev: None,
6591 branch: None,
6592 });
6593 let err = d.validate().unwrap_err();
6594 let DepError::FonteRepoShape { reason, .. } = err else {
6595 panic!("expected FonteRepoShape, got other variant");
6596 };
6597 assert!(
6598 reason.contains("must not contain `&`"),
6599 "reason must surface the background-`&` arm (fires before var-expansion-`$` when \
6600 `&` byte appears first in value), got {reason:?}"
6601 );
6602 }
6603
6604 #[test]
6605 fn validate_rejects_git_fonte_with_repo_carrying_shell_glob_wildcard() {
6606 // The fail-before-pass-after pin for the canonical
6607 // paste-from-shell-prompt glob footgun on `:repo` (peer with
6608 // the cf9034b `*` / `?` arm on the sibling `:caminho`
6609 // path-fonte axis). An author pastes a shell one-liner that
6610 // referenced a glob expansion (`ls
6611 // github.com/pleme-io/caixa-*`, `git clone
6612 // github:pleme-io/caixa-*`) into the `:repo` slot, forgetting
6613 // to substitute the literal repo name. Until this arm landed
6614 // the `*` byte silently passed every prior `is_git_repo_url`
6615 // arm (no whitespace, no control chars, no non-ASCII, no `#`,
6616 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`,
6617 // no `;`, no `&`, no `$`, doesn't start with `-` or `:`); RFC
6618 // 3986 §2 lists `*` in the 'sub-delims' / reserved set and
6619 // the WHATWG URL spec's special-query percent-encode set maps
6620 // `*` → `%2A` on the wire, so the byte rides verbatim into
6621 // the lacre's per-dep BLAKE3 closure but is silently
6622 // rewritten at libcurl's URL-parser layer — two authors
6623 // whose values differ only in their asterisk presence
6624 // resolve to the byte-identical upstream `git clone` but
6625 // lock to two distinct lacres, defeating the THEORY.md §V.2
6626 // render-determinism contract. Peer with the `:caminho`
6627 // axis's `FonteCaminhoShellGlob` arm (cf9034b) on the
6628 // sibling path-fonte axis, and the `is_git_ref_name`
6629 // refspec-wildcard cascade on the `:fonte :tag` / `:branch`
6630 // axes.
6631 let d = dep_with_fonte(DepSource::Git {
6632 repo: "https://github.com/pleme-io/caixa-*".into(),
6633 tag: Some("v0.1.0".into()),
6634 rev: None,
6635 branch: None,
6636 });
6637 let err = d.validate().unwrap_err();
6638 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6639 panic!("expected FonteRepoShape, got other variant");
6640 };
6641 assert_eq!(nome, "caixa-teia");
6642 assert_eq!(repo, "https://github.com/pleme-io/caixa-*");
6643 assert!(
6644 reason.contains("must not contain `*`"),
6645 "reason must surface the shell-glob arm, got {reason:?}"
6646 );
6647 assert!(
6648 reason.contains("pathname-expansion") || reason.contains("'sub-delims'"),
6649 "reason must name the shell-glob / pathname-expansion / \
6650 RFC-3986-sub-delims rationale, got {reason:?}"
6651 );
6652 }
6653
6654 #[test]
6655 fn validate_rejects_git_fonte_with_repo_carrying_recursive_shell_glob() {
6656 // The fail-before-pass-after pin for the symmetric bash
6657 // `globstar` recursive-glob paste footgun: an author pastes
6658 // a `ls github.com/pleme-io/**/x` (the canonical
6659 // `globstar`-shopt-enabled recursive-listing tail) into the
6660 // `:repo` slot. The `**` shape is two `*` bytes adjacent;
6661 // the per-byte arm fires on the first `*`. Pinned
6662 // separately from the single-`*` shape so a future
6663 // diagnostic-surface change that special-cased the
6664 // double-`*` form surfaces here.
6665 let d = dep_with_fonte(DepSource::Git {
6666 repo: "https://github.com/pleme-io/**/caixa-teia".into(),
6667 tag: Some("v0.1.0".into()),
6668 rev: None,
6669 branch: None,
6670 });
6671 let err = d.validate().unwrap_err();
6672 let DepError::FonteRepoShape { reason, .. } = err else {
6673 panic!("expected FonteRepoShape, got other variant");
6674 };
6675 assert!(
6676 reason.contains("must not contain `*`"),
6677 "reason must surface the shell-glob arm on the `**` recursive-glob shape too, \
6678 got {reason:?}"
6679 );
6680 }
6681
6682 #[test]
6683 fn fonte_repo_fragment_fires_before_glob_when_fragment_first() {
6684 // Cascade pin: the fragment-`#` arm and the glob-`*` arm are
6685 // both per-byte arms inside the same `for &b in s.as_bytes()`
6686 // loop, so the byte that appears first in the value's byte
6687 // order wins. A `:repo
6688 // "https://github.com/p/x#readme*tail"` carries both `#` and
6689 // `*`; the `#` byte appears first, so the fragment-`#` arm
6690 // fires, surfacing the more self-locating diagnostic on the
6691 // byte the author pasted earliest in the URL. Mirrors the
6692 // peer cascade discipline
6693 // `fonte_repo_fragment_fires_before_var_expansion_when_fragment_first`
6694 // on the prior `:repo` byte-class arm.
6695 let d = dep_with_fonte(DepSource::Git {
6696 repo: "https://github.com/pleme-io/caixa-teia#readme*tail".into(),
6697 tag: Some("v0.1.0".into()),
6698 rev: None,
6699 branch: None,
6700 });
6701 let err = d.validate().unwrap_err();
6702 let DepError::FonteRepoShape { reason, .. } = err else {
6703 panic!("expected FonteRepoShape, got other variant");
6704 };
6705 assert!(
6706 reason.contains("must not contain `#`"),
6707 "reason must surface the fragment-`#` arm (fires before glob-`*` when `#` byte \
6708 appears first in value), got {reason:?}"
6709 );
6710 }
6711
6712 #[test]
6713 fn fonte_repo_var_expansion_fires_before_glob_when_var_expansion_first() {
6714 // Cascade pin: the var-expansion-`$` arm and the glob-`*`
6715 // arm are both per-byte arms inside the same `for &b in
6716 // s.as_bytes()` loop, so the byte that appears first in the
6717 // value's byte order wins. A `:repo
6718 // "https://github.com/p/$ORG-*"` carries both `$` and `*`;
6719 // the `$` byte appears first, so the var-expansion arm
6720 // fires, surfacing the more self-locating diagnostic on the
6721 // byte the author pasted earliest in the URL. Pins the
6722 // natural-order cascade so a future reorder of the per-byte
6723 // arms surfaces here — `*` is the most recent byte-class
6724 // arm, so the cascade-pin sweep extends to cover the
6725 // immediately prior `$` byte arm firing first when ordered
6726 // ahead of `*` in the value.
6727 let d = dep_with_fonte(DepSource::Git {
6728 repo: "https://github.com/pleme-io/$ORG-caixa-*".into(),
6729 tag: Some("v0.1.0".into()),
6730 rev: None,
6731 branch: None,
6732 });
6733 let err = d.validate().unwrap_err();
6734 let DepError::FonteRepoShape { reason, .. } = err else {
6735 panic!("expected FonteRepoShape, got other variant");
6736 };
6737 assert!(
6738 reason.contains("must not contain `$`"),
6739 "reason must surface the var-expansion-`$` arm (fires before glob-`*` when `$` \
6740 byte appears first in value), got {reason:?}"
6741 );
6742 }
6743
6744 #[test]
6745 fn validate_rejects_git_fonte_with_repo_carrying_subshell_open_paren() {
6746 // The fail-before-pass-after pin for the canonical paste-from-
6747 // shell-prompt subshell-grouping footgun on `:repo`. An author
6748 // pastes a doc / README snippet carrying a regex-alternation
6749 // grouping shape (`https://github.com/(foo|bar)/repo`) or a
6750 // dynamic-config-substitution wrapper (`$(<cmd>)`) into the
6751 // `:repo` slot, forgetting to substitute one literal org name.
6752 // Until this arm landed the `(` byte silently passed every
6753 // prior `is_git_repo_url` arm (no whitespace, no control
6754 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6755 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no
6756 // `*`, doesn't start with `-` or `:`); RFC 3986 §2 lists `(`
6757 // / `)` in the 'sub-delims' / reserved set, and the WHATWG
6758 // URL spec's special-query percent-encode set maps `(` →
6759 // `%28` and `)` → `%29` on the wire, so the byte rides
6760 // verbatim into the lacre's per-dep BLAKE3 closure but is
6761 // silently rewritten at libcurl's URL-parser layer —
6762 // defeating the THEORY.md §V.2 render-determinism contract on
6763 // the same axis the prior twelve byte-class arms close.
6764 let d = dep_with_fonte(DepSource::Git {
6765 repo: "https://github.com/(foo|bar)/caixa-teia".into(),
6766 tag: Some("v0.1.0".into()),
6767 rev: None,
6768 branch: None,
6769 });
6770 let err = d.validate().unwrap_err();
6771 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6772 panic!("expected FonteRepoShape, got other variant");
6773 };
6774 assert_eq!(nome, "caixa-teia");
6775 assert_eq!(repo, "https://github.com/(foo|bar)/caixa-teia");
6776 assert!(
6777 reason.contains("must not contain `(`"),
6778 "reason must surface the subshell-open-paren arm, got {reason:?}"
6779 );
6780 assert!(
6781 reason.contains("subshell-grouping") || reason.contains("'sub-delims'"),
6782 "reason must name the shell-subshell-grouping / RFC-3986-sub-delims rationale, \
6783 got {reason:?}"
6784 );
6785 }
6786
6787 #[test]
6788 fn validate_rejects_git_fonte_with_repo_carrying_subshell_close_paren() {
6789 // The symmetric arm pin on the closing `)` byte: an author
6790 // pastes a `$(date)` command-substitution wrapper or a
6791 // regex-alternation `(foo|bar)` tail into the `:repo` slot.
6792 // Pinned separately from the opening `(` shape so a future
6793 // diagnostic-surface change that only checked one boundary
6794 // surfaces here. The `(` byte appears earlier in the
6795 // canonical regex / subshell wrapper so the per-byte loop
6796 // fires on `(` first; this test exercises a `:repo` value
6797 // carrying only the closing `)` byte (no opening paren) so
6798 // the `)` arm fires directly — pinning the byte-class arm
6799 // independent of order.
6800 let d = dep_with_fonte(DepSource::Git {
6801 repo: "github:pleme-io/caixa-teia)tail".into(),
6802 tag: Some("v0.1.0".into()),
6803 rev: None,
6804 branch: None,
6805 });
6806 let err = d.validate().unwrap_err();
6807 let DepError::FonteRepoShape { reason, .. } = err else {
6808 panic!("expected FonteRepoShape, got other variant");
6809 };
6810 assert!(
6811 reason.contains("must not contain `)`"),
6812 "reason must surface the subshell-close-paren arm on the bare `)` shape, \
6813 got {reason:?}"
6814 );
6815 }
6816
6817 #[test]
6818 fn fonte_repo_fragment_fires_before_subshell_when_fragment_first() {
6819 // Cascade pin: the fragment-`#` arm and the subshell-`(` arm
6820 // are both per-byte arms inside the same `for &b in
6821 // s.as_bytes()` loop, so the byte that appears first in the
6822 // value's byte order wins. A `:repo
6823 // "https://github.com/p/x#readme(tail)"` carries both `#` and
6824 // `(`; the `#` byte appears first, so the fragment-`#` arm
6825 // fires, surfacing the more self-locating diagnostic on the
6826 // byte the author pasted earliest in the URL. Mirrors the
6827 // peer cascade discipline
6828 // `fonte_repo_fragment_fires_before_glob_when_fragment_first`
6829 // on the prior `:repo` byte-class arm.
6830 let d = dep_with_fonte(DepSource::Git {
6831 repo: "https://github.com/pleme-io/caixa-teia#readme(tail)".into(),
6832 tag: Some("v0.1.0".into()),
6833 rev: None,
6834 branch: None,
6835 });
6836 let err = d.validate().unwrap_err();
6837 let DepError::FonteRepoShape { reason, .. } = err else {
6838 panic!("expected FonteRepoShape, got other variant");
6839 };
6840 assert!(
6841 reason.contains("must not contain `#`"),
6842 "reason must surface the fragment-`#` arm (fires before subshell-`(` when `#` \
6843 byte appears first in value), got {reason:?}"
6844 );
6845 }
6846
6847 #[test]
6848 fn fonte_repo_glob_fires_before_subshell_when_glob_first() {
6849 // Cascade pin: the glob-`*` arm (the immediate-predecessor
6850 // byte-class arm, 3902a9a) and the subshell-`(` arm are both
6851 // per-byte arms inside the same `for &b in s.as_bytes()`
6852 // loop, so the byte that appears first in the value's byte
6853 // order wins. A `:repo
6854 // "https://github.com/p/x-*-(date)"` carries both `*` and
6855 // `(`; the `*` byte appears first, so the glob arm fires,
6856 // surfacing the more self-locating diagnostic on the byte
6857 // the author pasted earliest in the URL. Pins the natural-
6858 // order cascade so a future reorder of the per-byte arms
6859 // surfaces here — `(` is the most recent byte-class arm,
6860 // so the cascade-pin sweep extends to cover the immediately
6861 // prior `*` byte arm firing first when ordered ahead of `(`
6862 // in the value.
6863 let d = dep_with_fonte(DepSource::Git {
6864 repo: "https://github.com/pleme-io/caixa-teia-*-(date)".into(),
6865 tag: Some("v0.1.0".into()),
6866 rev: None,
6867 branch: None,
6868 });
6869 let err = d.validate().unwrap_err();
6870 let DepError::FonteRepoShape { reason, .. } = err else {
6871 panic!("expected FonteRepoShape, got other variant");
6872 };
6873 assert!(
6874 reason.contains("must not contain `*`"),
6875 "reason must surface the glob-`*` arm (fires before subshell-`(` when `*` byte \
6876 appears first in value), got {reason:?}"
6877 );
6878 }
6879
6880 #[test]
6881 fn validate_rejects_git_fonte_with_repo_carrying_shell_double_quote() {
6882 // The fail-before-pass-after pin for the canonical paste-from-
6883 // doc-shell-quoting footgun on `:repo`. An author copies a
6884 // README quick-start snippet (`$ git clone "https://github.com/
6885 // foo/bar"`) and keeps the surrounding double-quote bytes when
6886 // pasting into the `:repo` slot — the doc wraps the URL in
6887 // double quotes so the shell doesn't re-lex metachars inside,
6888 // but the typed slot is itself a byte-level string parser, not
6889 // a shell context, so the quote bytes ride into the value
6890 // verbatim. Until this arm landed the `"` byte silently passed
6891 // every prior `is_git_repo_url` arm (no whitespace, no control
6892 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6893 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`,
6894 // no `(`/`)`, doesn't start with `-` or `:`); RFC 3986 §2 lists
6895 // `"` in the strict four-byte 'delims' subset (with `<`, `>`,
6896 // `` ` ``) every URL parser is required to refuse or percent-
6897 // encode, and the WHATWG URL spec's 'C0 control percent-encode
6898 // set' maps `"` → `%22` on the wire, so the byte rides verbatim
6899 // into the lacre's per-dep BLAKE3 closure but is silently
6900 // rewritten at libcurl's URL-parser layer, defeating the
6901 // THEORY.md §V.2 render-determinism contract.
6902 let d = dep_with_fonte(DepSource::Git {
6903 repo: "\"https://github.com/pleme-io/caixa-teia\"".into(),
6904 tag: Some("v0.1.0".into()),
6905 rev: None,
6906 branch: None,
6907 });
6908 let err = d.validate().unwrap_err();
6909 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6910 panic!("expected FonteRepoShape, got other variant");
6911 };
6912 assert_eq!(nome, "caixa-teia");
6913 assert_eq!(repo, "\"https://github.com/pleme-io/caixa-teia\"");
6914 assert!(
6915 reason.contains("must not contain `\"`"),
6916 "reason must surface the shell-double-quote arm, got {reason:?}"
6917 );
6918 assert!(
6919 reason.contains("double-quote") || reason.contains("'delims'"),
6920 "reason must name the shell-double-quote / RFC-3986-delims rationale, \
6921 got {reason:?}"
6922 );
6923 }
6924
6925 #[test]
6926 fn validate_rejects_git_fonte_with_repo_carrying_stray_trailing_double_quote() {
6927 // The symmetric stray-quote tail pin: an author pastes only a
6928 // closing `"` from a shell-history line like `git clone
6929 // "https://github.com/foo/bar" && cd …` (the trim went too
6930 // far in one direction but not the other) into the `:repo`
6931 // slot. Pinned separately from the wrapped-quote shape so a
6932 // future diagnostic-surface change that only checked one
6933 // boundary (only leading, only trailing, only paired) surfaces
6934 // here — the per-byte arm fires anywhere `"` appears.
6935 let d = dep_with_fonte(DepSource::Git {
6936 repo: "github:pleme-io/caixa-teia\"".into(),
6937 tag: Some("v0.1.0".into()),
6938 rev: None,
6939 branch: None,
6940 });
6941 let err = d.validate().unwrap_err();
6942 let DepError::FonteRepoShape { reason, .. } = err else {
6943 panic!("expected FonteRepoShape, got other variant");
6944 };
6945 assert!(
6946 reason.contains("must not contain `\"`"),
6947 "reason must surface the shell-double-quote arm on the trailing-`\"` shape, \
6948 got {reason:?}"
6949 );
6950 }
6951
6952 #[test]
6953 fn fonte_repo_fragment_fires_before_double_quote_when_fragment_first() {
6954 // Cascade pin: the fragment-`#` arm and the double-quote arm
6955 // are both per-byte arms inside the same `for &b in
6956 // s.as_bytes()` loop, so the byte that appears first in the
6957 // value's byte order wins. A `:repo
6958 // "https://github.com/p/x#readme\"tail"` carries both `#` and
6959 // `"`; the `#` byte appears first, so the fragment-`#` arm
6960 // fires, surfacing the more self-locating diagnostic on the
6961 // byte the author pasted earliest in the URL.
6962 let d = dep_with_fonte(DepSource::Git {
6963 repo: "https://github.com/pleme-io/caixa-teia#readme\"tail".into(),
6964 tag: Some("v0.1.0".into()),
6965 rev: None,
6966 branch: None,
6967 });
6968 let err = d.validate().unwrap_err();
6969 let DepError::FonteRepoShape { reason, .. } = err else {
6970 panic!("expected FonteRepoShape, got other variant");
6971 };
6972 assert!(
6973 reason.contains("must not contain `#`"),
6974 "reason must surface the fragment-`#` arm (fires before double-quote when `#` \
6975 byte appears first in value), got {reason:?}"
6976 );
6977 }
6978
6979 #[test]
6980 fn fonte_repo_subshell_fires_before_double_quote_when_subshell_first() {
6981 // Cascade pin: the subshell-`(` arm (the immediate-predecessor
6982 // byte-class arm, 3b99147) and the double-quote arm are both
6983 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6984 // so the byte that appears first in the value's byte order
6985 // wins. A `:repo "github:p/x(date)\"tail"` carries both `(`
6986 // and `"`; the `(` byte appears first, so the subshell arm
6987 // fires, surfacing the more self-locating diagnostic on the
6988 // byte the author pasted earliest in the URL. Pins the natural-
6989 // order cascade so a future reorder of the per-byte arms
6990 // surfaces here — `"` is the most recent byte-class arm, so
6991 // the cascade-pin sweep extends to cover the immediately prior
6992 // `(` byte arm firing first when ordered ahead of `"` in the
6993 // value.
6994 let d = dep_with_fonte(DepSource::Git {
6995 repo: "github:pleme-io/caixa-teia(date)\"tail".into(),
6996 tag: Some("v0.1.0".into()),
6997 rev: None,
6998 branch: None,
6999 });
7000 let err = d.validate().unwrap_err();
7001 let DepError::FonteRepoShape { reason, .. } = err else {
7002 panic!("expected FonteRepoShape, got other variant");
7003 };
7004 assert!(
7005 reason.contains("must not contain `(`"),
7006 "reason must surface the subshell-`(` arm (fires before double-quote when `(` \
7007 byte appears first in value), got {reason:?}"
7008 );
7009 }
7010
7011 #[test]
7012 fn validate_rejects_git_fonte_with_repo_carrying_shell_single_quote() {
7013 // The fail-before-pass-after pin for the canonical paste-from-
7014 // doc-strong-quoting footgun on `:repo`. An author copies a
7015 // security-conscious README quick-start snippet (`$ git clone
7016 // 'https://github.com/foo/bar'`) and keeps the surrounding
7017 // single-quote bytes when pasting into the `:repo` slot — the
7018 // doc strong-quotes the URL so the shell suppresses every form
7019 // of expansion on the bytes inside (no `$`, no backtick, no
7020 // glob, no word-splitting), but the typed slot is itself a
7021 // byte-level string parser, not a shell context, so the quote
7022 // bytes ride into the value verbatim. Until this arm landed the
7023 // `'` byte silently passed every prior `is_git_repo_url` arm
7024 // (no whitespace, no control chars, no non-ASCII, no `#`, no
7025 // `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no
7026 // `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`, doesn't start
7027 // with `-` or `:`); RFC 3986 §2.2 lists `'` in the 'sub-delims'
7028 // set, peer with the `\"` 'delims' double-quote arm and the
7029 // partner ASCII shell-string-delimiter byte every byte-level
7030 // string parser sharing a value-shape with a shell argument
7031 // must refuse on a URL-shaped slot.
7032 let d = dep_with_fonte(DepSource::Git {
7033 repo: "'https://github.com/pleme-io/caixa-teia'".into(),
7034 tag: Some("v0.1.0".into()),
7035 rev: None,
7036 branch: None,
7037 });
7038 let err = d.validate().unwrap_err();
7039 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7040 panic!("expected FonteRepoShape, got other variant");
7041 };
7042 assert_eq!(nome, "caixa-teia");
7043 assert_eq!(repo, "'https://github.com/pleme-io/caixa-teia'");
7044 assert!(
7045 reason.contains("must not contain `'`"),
7046 "reason must surface the shell-single-quote arm, got {reason:?}"
7047 );
7048 assert!(
7049 reason.contains("single-quote") || reason.contains("strong-quote"),
7050 "reason must name the shell-single-quote / strong-quote rationale, \
7051 got {reason:?}"
7052 );
7053 }
7054
7055 #[test]
7056 fn validate_rejects_git_fonte_with_repo_carrying_english_apostrophe() {
7057 // The symmetric English-typography pin: an author writes
7058 // `:repo "github:p/repo's-fork"` (the possessive-form paste-
7059 // from-prose idiom every README / commit-message / chat-thread
7060 // reference to a repo carries) expecting the substrate to
7061 // coerce it to a kebab-case slug — but the byte rides into the
7062 // lacre verbatim. Pinned separately from the wrapped-quote
7063 // shape so a future diagnostic-surface change that only checked
7064 // the boundary positions (only leading, only trailing, only
7065 // paired) surfaces here — the per-byte arm fires anywhere `'`
7066 // appears in the value.
7067 let d = dep_with_fonte(DepSource::Git {
7068 repo: "github:pleme-io/repo's-fork".into(),
7069 tag: Some("v0.1.0".into()),
7070 rev: None,
7071 branch: None,
7072 });
7073 let err = d.validate().unwrap_err();
7074 let DepError::FonteRepoShape { reason, .. } = err else {
7075 panic!("expected FonteRepoShape, got other variant");
7076 };
7077 assert!(
7078 reason.contains("must not contain `'`"),
7079 "reason must surface the shell-single-quote arm on the mid-string \
7080 apostrophe shape, got {reason:?}"
7081 );
7082 }
7083
7084 #[test]
7085 fn fonte_repo_fragment_fires_before_single_quote_when_fragment_first() {
7086 // Cascade pin: the fragment-`#` arm and the single-quote arm
7087 // are both per-byte arms inside the same `for &b in
7088 // s.as_bytes()` loop, so the byte that appears first in the
7089 // value's byte order wins. A `:repo
7090 // "https://github.com/p/x#readme'tail"` carries both `#` and
7091 // `'`; the `#` byte appears first, so the fragment-`#` arm
7092 // fires, surfacing the more self-locating diagnostic on the
7093 // byte the author pasted earliest in the URL.
7094 let d = dep_with_fonte(DepSource::Git {
7095 repo: "https://github.com/pleme-io/caixa-teia#readme'tail".into(),
7096 tag: Some("v0.1.0".into()),
7097 rev: None,
7098 branch: None,
7099 });
7100 let err = d.validate().unwrap_err();
7101 let DepError::FonteRepoShape { reason, .. } = err else {
7102 panic!("expected FonteRepoShape, got other variant");
7103 };
7104 assert!(
7105 reason.contains("must not contain `#`"),
7106 "reason must surface the fragment-`#` arm (fires before single-quote when `#` \
7107 byte appears first in value), got {reason:?}"
7108 );
7109 }
7110
7111 #[test]
7112 fn fonte_repo_double_quote_fires_before_single_quote_when_double_quote_first() {
7113 // Cascade pin: the double-quote-`"` arm (the immediate-predecessor
7114 // byte-class arm, 4267d8b) and the single-quote arm are both
7115 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7116 // so the byte that appears first in the value's byte order
7117 // wins. A `:repo "github:p/x\"mid'tail"` carries both `"` and
7118 // `'`; the `"` byte appears first, so the double-quote arm
7119 // fires, surfacing the more self-locating diagnostic on the
7120 // byte the author pasted earliest in the URL. Pins the natural-
7121 // order cascade so a future reorder of the per-byte arms
7122 // surfaces here — `'` is the most recent byte-class arm, so
7123 // the cascade-pin sweep extends to cover the immediately prior
7124 // `"` byte arm firing first when ordered ahead of `'` in the
7125 // value.
7126 let d = dep_with_fonte(DepSource::Git {
7127 repo: "github:pleme-io/caixa-teia\"mid'tail".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 { reason, .. } = err else {
7134 panic!("expected FonteRepoShape, got other variant");
7135 };
7136 assert!(
7137 reason.contains("must not contain `\"`"),
7138 "reason must surface the double-quote arm (fires before single-quote when `\"` \
7139 byte appears first in value), got {reason:?}"
7140 );
7141 }
7142
7143 #[test]
7144 fn validate_rejects_git_fonte_with_repo_carrying_shell_history_expansion() {
7145 // The fail-before-pass-after pin for the canonical paste-from-
7146 // shell-history footgun on `:repo`. An author copies a `git
7147 // clone <url>!sudo make install` one-liner from a README's
7148 // quick-start snippet, intending the trailing `!sudo` as a
7149 // shell-history-expansion reference but the typed slot is itself
7150 // a byte-level string parser, not a shell context, so the byte
7151 // rides into the value verbatim. Until this arm landed the `!`
7152 // byte silently passed every prior `is_git_repo_url` arm (no
7153 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
7154 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
7155 // no `&`, no `$`, no `*`, no `(`/`)`, no `"`, no `'`, doesn't
7156 // start with `-` or `:`); bash with the default `histexpand`
7157 // mode rewrites `!command` to the most recent history entry
7158 // beginning with `command`, the canonical RCE-class injection
7159 // vector when the byte rides into a shell argument.
7160 let d = dep_with_fonte(DepSource::Git {
7161 repo: "https://github.com/pleme-io/caixa-teia!sudo".into(),
7162 tag: Some("v0.1.0".into()),
7163 rev: None,
7164 branch: None,
7165 });
7166 let err = d.validate().unwrap_err();
7167 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7168 panic!("expected FonteRepoShape, got other variant");
7169 };
7170 assert_eq!(nome, "caixa-teia");
7171 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia!sudo");
7172 assert!(
7173 reason.contains("must not contain `!`"),
7174 "reason must surface the shell-history-expansion arm, got {reason:?}"
7175 );
7176 assert!(
7177 reason.contains("history-expansion") || reason.contains("bang"),
7178 "reason must name the shell-history-expansion / bang rationale, got {reason:?}"
7179 );
7180 }
7181
7182 #[test]
7183 fn validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference() {
7184 // The symmetric `!!` repeat-prior-command pin: an author paste-
7185 // trims a `git clone <url>` retry idiom from shell history that
7186 // expands to the previous command via `!!`. Pinned separately
7187 // from the wrapped `!command` shape so a future diagnostic-
7188 // surface change that only checked the leading or paired-bang
7189 // position surfaces here — the per-byte arm fires anywhere `!`
7190 // appears in the value.
7191 let d = dep_with_fonte(DepSource::Git {
7192 repo: "github:pleme-io/caixa-teia!!".into(),
7193 tag: Some("v0.1.0".into()),
7194 rev: None,
7195 branch: None,
7196 });
7197 let err = d.validate().unwrap_err();
7198 let DepError::FonteRepoShape { reason, .. } = err else {
7199 panic!("expected FonteRepoShape, got other variant");
7200 };
7201 assert!(
7202 reason.contains("must not contain `!`"),
7203 "reason must surface the shell-history-expansion arm on the trailing-`!!` shape, \
7204 got {reason:?}"
7205 );
7206 }
7207
7208 #[test]
7209 fn fonte_repo_fragment_fires_before_bang_when_fragment_first() {
7210 // Cascade pin: the fragment-`#` arm and the bang arm are both
7211 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7212 // so the byte that appears first in the value's byte order
7213 // wins. A `:repo "https://github.com/p/x#readme!tail"` carries
7214 // both `#` and `!`; the `#` byte appears first, so the
7215 // fragment-`#` arm fires, surfacing the more self-locating
7216 // diagnostic on the byte the author pasted earliest in the URL.
7217 let d = dep_with_fonte(DepSource::Git {
7218 repo: "https://github.com/pleme-io/caixa-teia#readme!tail".into(),
7219 tag: Some("v0.1.0".into()),
7220 rev: None,
7221 branch: None,
7222 });
7223 let err = d.validate().unwrap_err();
7224 let DepError::FonteRepoShape { reason, .. } = err else {
7225 panic!("expected FonteRepoShape, got other variant");
7226 };
7227 assert!(
7228 reason.contains("must not contain `#`"),
7229 "reason must surface the fragment-`#` arm (fires before bang when `#` byte \
7230 appears first in value), got {reason:?}"
7231 );
7232 }
7233
7234 #[test]
7235 fn fonte_repo_single_quote_fires_before_bang_when_single_quote_first() {
7236 // Cascade pin: the single-quote-`'` arm (the immediate-predecessor
7237 // byte-class arm, e7a109f) and the bang arm are both per-byte
7238 // arms inside the same `for &b in s.as_bytes()` loop, so the
7239 // byte that appears first in the value's byte order wins. A
7240 // `:repo "github:p/x'mid!tail"` carries both `'` and `!`; the
7241 // `'` byte appears first, so the single-quote arm fires,
7242 // surfacing the more self-locating diagnostic on the byte the
7243 // author pasted earliest in the URL. Pins the natural-order
7244 // cascade so a future reorder of the per-byte arms surfaces
7245 // here — `!` is the most recent byte-class arm, so the
7246 // cascade-pin sweep extends to cover the immediately prior `'`
7247 // byte arm firing first when ordered ahead of `!` in the value.
7248 let d = dep_with_fonte(DepSource::Git {
7249 repo: "github:pleme-io/caixa-teia'mid!tail".into(),
7250 tag: Some("v0.1.0".into()),
7251 rev: None,
7252 branch: None,
7253 });
7254 let err = d.validate().unwrap_err();
7255 let DepError::FonteRepoShape { reason, .. } = err else {
7256 panic!("expected FonteRepoShape, got other variant");
7257 };
7258 assert!(
7259 reason.contains("must not contain `'`"),
7260 "reason must surface the single-quote arm (fires before bang when `'` byte \
7261 appears first in value), got {reason:?}"
7262 );
7263 }
7264
7265 #[test]
7266 fn validate_rejects_git_fonte_with_repo_carrying_list_separator_comma() {
7267 // The fail-before-pass-after pin for the canonical
7268 // list-separator-belongs-to-list-grammar footgun on `:repo`.
7269 // An author copies a `git clone <a>, <b>, <c>` paste-from-CSV
7270 // one-liner from a multi-repo bootstrap doc, intending the
7271 // comma to separate multiple repo entries but the typed
7272 // `:repo` slot names *one* repo (the list-separator belongs
7273 // to the `:deps` list grammar, not to the value). Until this
7274 // arm landed the `,` byte silently passed every prior
7275 // `is_git_repo_url` arm (no whitespace, no control chars, no
7276 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
7277 // no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`, no
7278 // `(`/`)`, no `"`, no `'`, no `!`, doesn't start with `-` or
7279 // `:`); the byte rode into the lacre's per-dep content-
7280 // address and the resolver's `git clone <repo>` subprocess
7281 // invocation, where no host's repo registry resolved the
7282 // comma-bearing slug.
7283 let d = dep_with_fonte(DepSource::Git {
7284 repo: "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira".into(),
7285 tag: Some("v0.1.0".into()),
7286 rev: None,
7287 branch: None,
7288 });
7289 let err = d.validate().unwrap_err();
7290 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7291 panic!("expected FonteRepoShape, got other variant");
7292 };
7293 assert_eq!(nome, "caixa-teia");
7294 assert_eq!(
7295 repo,
7296 "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira"
7297 );
7298 assert!(
7299 reason.contains("must not contain `,`"),
7300 "reason must surface the list-separator-comma arm, got {reason:?}"
7301 );
7302 assert!(
7303 reason.contains("list-separator") || reason.contains("sub-delims"),
7304 "reason must name the list-separator / RFC-3986-sub-delims rationale, \
7305 got {reason:?}"
7306 );
7307 }
7308
7309 #[test]
7310 fn validate_rejects_git_fonte_with_repo_carrying_trailing_comma() {
7311 // The symmetric trailing-`,` paste-from-prose pin: an author
7312 // writes `:repo "github:pleme-io/caixa-feira,"` (the trailing
7313 // comma every README-prose list-of-projects sentence carries,
7314 // mistakenly retained when the slug is pasted mid-sentence)
7315 // expecting the substrate to coerce it to a kebab-case slug.
7316 // Pinned separately from the wrapped mid-token shape so a
7317 // future diagnostic-surface change that only checked the
7318 // leading or paired-comma position surfaces here — the
7319 // per-byte arm fires anywhere `,` appears in the value.
7320 let d = dep_with_fonte(DepSource::Git {
7321 repo: "github:pleme-io/caixa-feira,".into(),
7322 tag: Some("v0.1.0".into()),
7323 rev: None,
7324 branch: None,
7325 });
7326 let err = d.validate().unwrap_err();
7327 let DepError::FonteRepoShape { reason, .. } = err else {
7328 panic!("expected FonteRepoShape, got other variant");
7329 };
7330 assert!(
7331 reason.contains("must not contain `,`"),
7332 "reason must surface the list-separator-comma arm on the trailing-`,` shape, \
7333 got {reason:?}"
7334 );
7335 }
7336
7337 #[test]
7338 fn fonte_repo_fragment_fires_before_comma_when_fragment_first() {
7339 // Cascade pin: the fragment-`#` arm and the comma arm are
7340 // both per-byte arms inside the same `for &b in s.as_bytes()`
7341 // loop, so the byte that appears first in the value's byte
7342 // order wins. A `:repo "https://github.com/p/x#readme,tail"`
7343 // carries both `#` and `,`; the `#` byte appears first, so
7344 // the fragment-`#` arm fires, surfacing the more self-
7345 // locating diagnostic on the byte the author pasted earliest
7346 // in the URL.
7347 let d = dep_with_fonte(DepSource::Git {
7348 repo: "https://github.com/pleme-io/caixa-teia#readme,tail".into(),
7349 tag: Some("v0.1.0".into()),
7350 rev: None,
7351 branch: None,
7352 });
7353 let err = d.validate().unwrap_err();
7354 let DepError::FonteRepoShape { reason, .. } = err else {
7355 panic!("expected FonteRepoShape, got other variant");
7356 };
7357 assert!(
7358 reason.contains("must not contain `#`"),
7359 "reason must surface the fragment-`#` arm (fires before comma when `#` byte \
7360 appears first in value), got {reason:?}"
7361 );
7362 }
7363
7364 #[test]
7365 fn fonte_repo_bang_fires_before_comma_when_bang_first() {
7366 // Cascade pin: the bang-`!` arm (the immediate-predecessor
7367 // byte-class arm, 7d53c68) and the comma arm are both
7368 // per-byte arms inside the same `for &b in s.as_bytes()`
7369 // loop, so the byte that appears first in the value's byte
7370 // order wins. A `:repo "github:p/x!mid,tail"` carries both
7371 // `!` and `,`; the `!` byte appears first, so the bang arm
7372 // fires, surfacing the more self-locating diagnostic on the
7373 // byte the author pasted earliest in the URL. Pins the
7374 // natural-order cascade so a future reorder of the per-byte
7375 // arms surfaces here — `,` is the most recent byte-class
7376 // arm, so the cascade-pin sweep extends to cover the
7377 // immediately prior `!` byte arm firing first when ordered
7378 // ahead of `,` in the value.
7379 let d = dep_with_fonte(DepSource::Git {
7380 repo: "github:pleme-io/caixa-teia!mid,tail".into(),
7381 tag: Some("v0.1.0".into()),
7382 rev: None,
7383 branch: None,
7384 });
7385 let err = d.validate().unwrap_err();
7386 let DepError::FonteRepoShape { reason, .. } = err else {
7387 panic!("expected FonteRepoShape, got other variant");
7388 };
7389 assert!(
7390 reason.contains("must not contain `!`"),
7391 "reason must surface the bang arm (fires before comma when `!` byte \
7392 appears first in value), got {reason:?}"
7393 );
7394 }
7395
7396 #[test]
7397 fn validate_rejects_git_fonte_with_repo_carrying_shell_env_var_assignment() {
7398 // The fail-before-pass-after pin for the canonical
7399 // shell-env-var-assignment-belongs-to-shell-grammar footgun
7400 // on `:repo`. An author copies
7401 // `GIT_TERMINAL_PROMPT=0 git clone <url>` (or
7402 // `GIT_SSL_NO_VERIFY=1 git clone <url>`, `HTTPS_PROXY=…
7403 // git clone <url>`, etc. — the canonical
7404 // git-troubleshooting README idiom for a one-shot env-var
7405 // scoped to the `git clone` invocation) from a shell-prompt
7406 // one-liner, intending the `KEY=VALUE` prefix as a shell-
7407 // grammar env-var assignment but the typed `:repo` slot is
7408 // a value parser, not a shell context, so the bytes ride
7409 // into the value verbatim. Until this arm landed the `=`
7410 // byte silently passed every prior `is_git_repo_url` arm
7411 // (no whitespace, no control chars, no non-ASCII, no `#`,
7412 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no
7413 // `|`, no `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`,
7414 // no `'`, no `!`, no `,`, doesn't start with `-` or `:`);
7415 // the byte rode into the lacre's per-dep content-address
7416 // and the resolver's `git clone <repo>` subprocess
7417 // invocation, where the upstream host's git porcelain
7418 // fetched a literal `GIT_TERMINAL_PROMPT=0 https://…`-shaped
7419 // path that no host's repo registry resolves.
7420 let d = dep_with_fonte(DepSource::Git {
7421 repo: "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia".into(),
7422 tag: Some("v0.1.0".into()),
7423 rev: None,
7424 branch: None,
7425 });
7426 let err = d.validate().unwrap_err();
7427 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7428 panic!("expected FonteRepoShape, got other variant");
7429 };
7430 assert_eq!(nome, "caixa-teia");
7431 assert_eq!(
7432 repo,
7433 "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia"
7434 );
7435 // The `=` byte at position 19 of `GIT_TERMINAL_PROMPT=0 …`
7436 // appears before the ` ` byte at position 21, so the `=`
7437 // arm fires (not the whitespace arm) — both arms guard
7438 // the slot, but the per-byte for-loop scans left-to-right
7439 // and the first matching byte wins.
7440 assert!(
7441 reason.contains("must not contain `=`"),
7442 "reason must surface the equals-`=` arm on the env-var-assignment \
7443 paste shape, got {reason:?}"
7444 );
7445 assert!(
7446 reason.contains("env-var-assignment") || reason.contains("KEY=VALUE"),
7447 "reason must name the shell-env-var-assignment rationale, got {reason:?}"
7448 );
7449 }
7450
7451 #[test]
7452 fn validate_rejects_git_fonte_with_repo_carrying_gitconfig_url_key_prefix() {
7453 // The symmetric paste-from-gitconfig pin: an author copies
7454 // `url=https://github.com/p/x` from `git config --get-all
7455 // remote.origin.url` output, a `.gitconfig` `[remote
7456 // "origin"] url = https://…` ini-stanza paste, or a
7457 // `git config remote.origin.url <value>` doc snippet,
7458 // intending the `url=` prefix as the ini-key but the typed
7459 // `:repo` slot is a URL value parser, not a gitconfig
7460 // grammar. With no leading whitespace and no earlier-arm
7461 // bytes in the value, the `=` arm itself fires (rather
7462 // than cascading to the whitespace arm as in the env-var
7463 // paste shape). Pinned separately so a future diagnostic-
7464 // surface change that only checked the whitespace-leading
7465 // shape surfaces here — the per-byte arm fires anywhere
7466 // `=` appears in the value.
7467 let d = dep_with_fonte(DepSource::Git {
7468 repo: "url=https://github.com/pleme-io/caixa-feira".into(),
7469 tag: Some("v0.1.0".into()),
7470 rev: None,
7471 branch: None,
7472 });
7473 let err = d.validate().unwrap_err();
7474 let DepError::FonteRepoShape { reason, .. } = err else {
7475 panic!("expected FonteRepoShape, got other variant");
7476 };
7477 assert!(
7478 reason.contains("must not contain `=`"),
7479 "reason must surface the equals-`=` arm on the `url=…` gitconfig \
7480 paste shape, got {reason:?}"
7481 );
7482 assert!(
7483 reason.contains("key-value-separator") || reason.contains("sub-delims"),
7484 "reason must name the key-value-separator / RFC-3986-sub-delims \
7485 rationale, got {reason:?}"
7486 );
7487 }
7488
7489 #[test]
7490 fn fonte_repo_fragment_fires_before_equals_when_fragment_first() {
7491 // Cascade pin: the fragment-`#` arm and the `=` arm are
7492 // both per-byte arms inside the same `for &b in s.as_bytes()`
7493 // loop, so the byte that appears first in the value's byte
7494 // order wins. A `:repo "https://github.com/p/x#readme=tail"`
7495 // carries both `#` and `=`; the `#` byte appears first, so
7496 // the fragment-`#` arm fires, surfacing the more self-
7497 // locating diagnostic on the byte the author pasted earliest
7498 // in the URL.
7499 let d = dep_with_fonte(DepSource::Git {
7500 repo: "https://github.com/pleme-io/caixa-teia#readme=tail".into(),
7501 tag: Some("v0.1.0".into()),
7502 rev: None,
7503 branch: None,
7504 });
7505 let err = d.validate().unwrap_err();
7506 let DepError::FonteRepoShape { reason, .. } = err else {
7507 panic!("expected FonteRepoShape, got other variant");
7508 };
7509 assert!(
7510 reason.contains("must not contain `#`"),
7511 "reason must surface the fragment-`#` arm (fires before equals when \
7512 `#` byte appears first in value), got {reason:?}"
7513 );
7514 }
7515
7516 #[test]
7517 fn fonte_repo_comma_fires_before_equals_when_comma_first() {
7518 // Cascade pin: the comma-`,` arm (the immediate-predecessor
7519 // byte-class arm, 775b80e) and the `=` arm are both per-byte
7520 // arms inside the same `for &b in s.as_bytes()` loop, so
7521 // the byte that appears first in the value's byte order
7522 // wins. A `:repo "github:p/x,mid=tail"` carries both `,`
7523 // and `=`; the `,` byte appears first, so the comma arm
7524 // fires, surfacing the more self-locating diagnostic on
7525 // the byte the author pasted earliest in the URL. Pins the
7526 // natural-order cascade so a future reorder of the per-byte
7527 // arms surfaces here — `=` is the most recent byte-class
7528 // arm, so the cascade-pin sweep extends to cover the
7529 // immediately prior `,` byte arm firing first when ordered
7530 // ahead of `=` in the value.
7531 let d = dep_with_fonte(DepSource::Git {
7532 repo: "github:pleme-io/caixa-teia,mid=tail".into(),
7533 tag: Some("v0.1.0".into()),
7534 rev: None,
7535 branch: None,
7536 });
7537 let err = d.validate().unwrap_err();
7538 let DepError::FonteRepoShape { reason, .. } = err else {
7539 panic!("expected FonteRepoShape, got other variant");
7540 };
7541 assert!(
7542 reason.contains("must not contain `,`"),
7543 "reason must surface the comma arm (fires before equals when `,` byte \
7544 appears first in value), got {reason:?}"
7545 );
7546 }
7547
7548 #[test]
7549 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_space() {
7550 // The fail-before-pass-after pin for the canonical paste-from-
7551 // browser-address-bar percent-encoded-space footgun on `:repo`.
7552 // An author copies `https://github.com/p/x%20test` from a
7553 // browser address bar (or a percent-encoded README hyperlink,
7554 // or a `curl --data-urlencode` shell-pipeline output)
7555 // intending `%20` as the URL encoding of a literal space; the
7556 // typed `:repo` slot already rejects the literal space byte
7557 // (the whitespace arm at the top of `is_git_repo_url`), so an
7558 // author trying to express "I really meant a space" reaches
7559 // for percent-encoding. Until this arm landed the `%` byte
7560 // silently passed every prior `is_git_repo_url` arm and rode
7561 // verbatim into the lacre's per-dep content-address — but
7562 // libcurl re-percent-encodes `%` to `%25` on the wire (since
7563 // `%` is reserved as the escape-sequence lead-in), so the
7564 // wire request becomes `https://github.com/p/x%2520test`, a
7565 // path the lacre's content-address never names. The classic
7566 // render-determinism violation on the encoding-mechanism axis
7567 // itself.
7568 let d = dep_with_fonte(DepSource::Git {
7569 repo: "https://github.com/pleme-io/caixa-teia%20test".into(),
7570 tag: Some("v0.1.0".into()),
7571 rev: None,
7572 branch: None,
7573 });
7574 let err = d.validate().unwrap_err();
7575 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7576 panic!("expected FonteRepoShape, got other variant");
7577 };
7578 assert_eq!(nome, "caixa-teia");
7579 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia%20test");
7580 assert!(
7581 reason.contains("must not contain `%`"),
7582 "reason must surface the percent-`%` arm on the percent-encoded-space \
7583 paste shape, got {reason:?}"
7584 );
7585 assert!(
7586 reason.contains("percent-encoding") || reason.contains("%25"),
7587 "reason must name the percent-encoding / `%25` re-encoding rationale, \
7588 got {reason:?}"
7589 );
7590 }
7591
7592 #[test]
7593 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_slash() {
7594 // The symmetric over-encoded-path-separator pin: an author
7595 // writes `:repo "https://github.com/p%2Fx"` intending the
7596 // `%2F` as the URL encoding of `/` (the canonical
7597 // paste-from-OpenAPI-spec / paste-from-percent-encoded-template
7598 // footgun every API client library and OAuth redirect-URI
7599 // documentation surfaces — the `/` is the URL-path-separator
7600 // and some templates percent-encode it to escape interpretation
7601 // as a path separator). The GitHub Smart-HTTP transport
7602 // resolves the URL's path-segment grammar before the
7603 // percent-decoding pass, so the value identifies a different
7604 // resource on the wire than the literal-`/` form the lacre's
7605 // content-address must agree with — two authors whose `:repo`
7606 // values differ only in their `/` vs `%2F` presence lock to
7607 // two distinct BLAKE3 closures for the byte-identical upstream
7608 // `git clone`. Pinned separately so a future diagnostic
7609 // surface that only catches the `%20` shape surfaces here too.
7610 let d = dep_with_fonte(DepSource::Git {
7611 repo: "https://github.com/pleme-io%2Fcaixa-teia".into(),
7612 tag: Some("v0.1.0".into()),
7613 rev: None,
7614 branch: None,
7615 });
7616 let err = d.validate().unwrap_err();
7617 let DepError::FonteRepoShape { reason, .. } = err else {
7618 panic!("expected FonteRepoShape, got other variant");
7619 };
7620 assert!(
7621 reason.contains("must not contain `%`"),
7622 "reason must surface the percent-`%` arm on the over-encoded-path \
7623 shape, got {reason:?}"
7624 );
7625 assert!(
7626 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7627 "reason must name the render-determinism / BLAKE3-closure rationale, \
7628 got {reason:?}"
7629 );
7630 }
7631
7632 #[test]
7633 fn fonte_repo_fragment_fires_before_percent_when_fragment_first() {
7634 // Cascade pin: the fragment-`#` arm and the `%` arm are both
7635 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7636 // so the byte that appears first in the value's byte order
7637 // wins. A `:repo "https://github.com/p/x#sec%20tail"` carries
7638 // both `#` and `%`; the `#` byte appears first, so the
7639 // fragment-`#` arm fires, surfacing the more self-locating
7640 // diagnostic on the byte the author pasted earliest in the URL.
7641 let d = dep_with_fonte(DepSource::Git {
7642 repo: "https://github.com/pleme-io/caixa-teia#sec%20tail".into(),
7643 tag: Some("v0.1.0".into()),
7644 rev: None,
7645 branch: None,
7646 });
7647 let err = d.validate().unwrap_err();
7648 let DepError::FonteRepoShape { reason, .. } = err else {
7649 panic!("expected FonteRepoShape, got other variant");
7650 };
7651 assert!(
7652 reason.contains("must not contain `#`"),
7653 "reason must surface the fragment-`#` arm (fires before percent when \
7654 `#` byte appears first in value), got {reason:?}"
7655 );
7656 }
7657
7658 #[test]
7659 fn fonte_repo_equals_fires_before_percent_when_equals_first() {
7660 // Cascade pin: the equals-`=` arm (the immediate-predecessor
7661 // byte-class arm, acf99af) and the `%` arm are both per-byte
7662 // arms inside the same `for &b in s.as_bytes()` loop, so the
7663 // byte that appears first in the value's byte order wins.
7664 // A `:repo "github:p/x=mid%20tail"` carries both `=` and `%`;
7665 // the `=` byte appears first, so the equals arm fires,
7666 // surfacing the more self-locating diagnostic on the byte the
7667 // author pasted earliest in the URL. Pins the natural-order
7668 // cascade so a future reorder of the per-byte arms surfaces
7669 // here — `%` is the most recent byte-class arm, so the
7670 // cascade-pin sweep extends to cover the immediately prior
7671 // `=` byte arm firing first when ordered ahead of `%` in the
7672 // value.
7673 let d = dep_with_fonte(DepSource::Git {
7674 repo: "github:pleme-io/caixa-teia=mid%20tail".into(),
7675 tag: Some("v0.1.0".into()),
7676 rev: None,
7677 branch: None,
7678 });
7679 let err = d.validate().unwrap_err();
7680 let DepError::FonteRepoShape { reason, .. } = err else {
7681 panic!("expected FonteRepoShape, got other variant");
7682 };
7683 assert!(
7684 reason.contains("must not contain `=`"),
7685 "reason must surface the equals arm (fires before percent when `=` byte \
7686 appears first in value), got {reason:?}"
7687 );
7688 }
7689
7690 #[test]
7691 fn validate_rejects_git_fonte_with_repo_carrying_caret_history_substitution() {
7692 // The fail-before-pass-after pin for the canonical paste-from-
7693 // shell-history footgun on `:repo`. An author copies a
7694 // `git clone <url>` line from their terminal followed by a
7695 // bash / ksh / zsh `^typo^fix^` quick-edit-and-rerun shell-
7696 // history shorthand (the `^old^new^` form re-runs the prior
7697 // history entry with the first `old` substituted by `new`,
7698 // bash's default behavior on interactive sessions with
7699 // `set -o histexpand`), forgetting to trim the trailing
7700 // `^...^...` shell-history fragment from the URL value. The
7701 // `^` byte sits in the RFC 3986 §2 'unwise' set (peer with
7702 // `{`, `}`, `|`, `\\` — the strictest of the §2 reserved
7703 // classes), the WHATWG URL spec's 'fragment percent-encode
7704 // set' maps `^` → `%5E` on the wire, so the byte rides
7705 // verbatim into the lacre's per-dep content-address but
7706 // libcurl re-encodes it to `%5E` at `git clone` time — the
7707 // classic render-determinism violation on the same axis the
7708 // peer `%`, `=`, `,`, `!`, `'`, `"`, `(`, `)`, `*`, `$`,
7709 // `&`, `;`, `|`, backtick, `<`, `>`, `{`, `}`, `\\`, `?`,
7710 // `#` arms close.
7711 let d = dep_with_fonte(DepSource::Git {
7712 repo: "https://github.com/pleme-io/caixa-teia^typo^fix".into(),
7713 tag: Some("v0.1.0".into()),
7714 rev: None,
7715 branch: None,
7716 });
7717 let err = d.validate().unwrap_err();
7718 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7719 panic!("expected FonteRepoShape, got other variant");
7720 };
7721 assert_eq!(nome, "caixa-teia");
7722 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia^typo^fix");
7723 assert!(
7724 reason.contains("must not contain `^`"),
7725 "reason must surface the caret-`^` arm on the paste-from-shell-history \
7726 shape, got {reason:?}"
7727 );
7728 assert!(
7729 reason.contains("history-substitution") || reason.contains("%5E"),
7730 "reason must name the shell-history-substitution / `%5E` wire-encoding \
7731 rationale, got {reason:?}"
7732 );
7733 }
7734
7735 #[test]
7736 fn validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor() {
7737 // The symmetric paste-from-doc-grep-pipeline footgun: an
7738 // author writes `:repo "github:p/^archived"` after copying a
7739 // `grep '^archived'` regex-anchor / negation idiom from a
7740 // doc / README quick-listing snippet, expecting the substrate
7741 // to coerce it to a literal repo name. The byte rides
7742 // verbatim into the lacre's per-dep content-address and
7743 // diverges from the byte-identical literal `archived` form
7744 // every other author authored — the canonical render-
7745 // determinism violation pin on the second footgun shape the
7746 // caret-`^` arm closes.
7747 let d = dep_with_fonte(DepSource::Git {
7748 repo: "github:pleme-io/^archived".into(),
7749 tag: Some("v0.1.0".into()),
7750 rev: None,
7751 branch: None,
7752 });
7753 let err = d.validate().unwrap_err();
7754 let DepError::FonteRepoShape { reason, .. } = err else {
7755 panic!("expected FonteRepoShape, got other variant");
7756 };
7757 assert!(
7758 reason.contains("must not contain `^`"),
7759 "reason must surface the caret-`^` arm on the regex-anchor shape, \
7760 got {reason:?}"
7761 );
7762 assert!(
7763 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7764 "reason must name the render-determinism / BLAKE3-closure rationale, \
7765 got {reason:?}"
7766 );
7767 }
7768
7769 #[test]
7770 fn fonte_repo_percent_fires_before_caret_when_percent_first() {
7771 // Cascade pin: the `%` arm (the immediate-predecessor byte-
7772 // class arm, a323db8) and the `^` arm are both per-byte arms
7773 // inside the same `for &b in s.as_bytes()` loop, so the byte
7774 // that appears first in the value's byte order wins. A
7775 // `:repo "https://github.com/p/x%20mid^tail"` carries both
7776 // `%` and `^`; the `%` byte appears first, so the percent
7777 // arm fires, surfacing the more self-locating diagnostic on
7778 // the byte the author pasted earliest in the URL. Pins the
7779 // natural-order cascade so a future reorder of the per-byte
7780 // arms surfaces here — `^` is the most recent byte-class arm,
7781 // so the cascade-pin sweep extends to cover the immediately
7782 // prior `%` byte arm firing first when ordered ahead of `^`
7783 // in the value.
7784 let d = dep_with_fonte(DepSource::Git {
7785 repo: "https://github.com/pleme-io/caixa-teia%20mid^tail".into(),
7786 tag: Some("v0.1.0".into()),
7787 rev: None,
7788 branch: None,
7789 });
7790 let err = d.validate().unwrap_err();
7791 let DepError::FonteRepoShape { reason, .. } = err else {
7792 panic!("expected FonteRepoShape, got other variant");
7793 };
7794 assert!(
7795 reason.contains("must not contain `%`"),
7796 "reason must surface the percent arm (fires before caret when `%` byte \
7797 appears first in value), got {reason:?}"
7798 );
7799 }
7800
7801 #[test]
7802 fn validate_rejects_git_fonte_with_repo_missing_colon_separator() {
7803 // The "I dropped the scheme" footgun — `:repo "pleme-io/caixa-teia"`
7804 // (no `github:` prefix, no scheme). Every documented form
7805 // carries a `:` (`github:`, `https://`, `ssh://`, `git://`,
7806 // `file://`, or `git@host:path`); a bare `org/repo` is
7807 // ambiguous (`git clone` reads as a relative filesystem path
7808 // rather than the GitHub-shorthand expansion the author
7809 // probably intended) and the gate rejects the shape upstream.
7810 let d = dep_with_fonte(DepSource::Git {
7811 repo: "pleme-io/caixa-teia".into(),
7812 tag: Some("v0.1.0".into()),
7813 rev: None,
7814 branch: None,
7815 });
7816 let err = d.validate().unwrap_err();
7817 let DepError::FonteRepoShape { reason, .. } = err else {
7818 panic!("expected FonteRepoShape, got other variant");
7819 };
7820 assert!(
7821 reason.contains("must contain a `:`"),
7822 "reason must surface the missing-`:` arm, got {reason:?}"
7823 );
7824 assert!(
7825 reason.contains("github:"),
7826 "reason must name the canonical `github:` shorthand prefix, got {reason:?}"
7827 );
7828 }
7829
7830 #[test]
7831 fn validate_rejects_git_fonte_with_repo_leading_colon() {
7832 // The "empty scheme" footgun — `:repo ":foo"` has a zero-length
7833 // scheme that no git porcelain entry-point accepts. Pinned
7834 // separately from the missing-`:` arm because a value with a
7835 // leading `:` does technically contain a `:` separator; the
7836 // shape gate rejects on a dedicated arm so the diagnostic
7837 // names the specific footgun.
7838 let d = dep_with_fonte(DepSource::Git {
7839 repo: ":pleme-io/caixa-teia".into(),
7840 tag: Some("v0.1.0".into()),
7841 rev: None,
7842 branch: None,
7843 });
7844 let err = d.validate().unwrap_err();
7845 let DepError::FonteRepoShape { reason, .. } = err else {
7846 panic!("expected FonteRepoShape, got other variant");
7847 };
7848 assert!(
7849 reason.contains("must not start with `:`"),
7850 "reason must surface the leading-`:` arm, got {reason:?}"
7851 );
7852 }
7853
7854 #[test]
7855 fn validate_rejects_git_fonte_with_repo_too_long() {
7856 // The cap arm — a `:repo` value longer than
7857 // [`crate::render::GIT_REPO_URL_MAX_LEN`] (2048) bytes is
7858 // structurally untenable on every realistic landing site (the
7859 // resolver's `git clone` invocation, the future M4 CR
7860 // materializer's per-dep `repo:` axis); a value of that length
7861 // is almost certainly a paste-from-binary slug.
7862 let too_long = format!(
7863 "github:pleme-io/{}",
7864 "x".repeat(crate::render::GIT_REPO_URL_MAX_LEN)
7865 );
7866 let d = dep_with_fonte(DepSource::Git {
7867 repo: too_long.clone(),
7868 tag: Some("v0.1.0".into()),
7869 rev: None,
7870 branch: None,
7871 });
7872 let err = d.validate().unwrap_err();
7873 let DepError::FonteRepoShape { reason, .. } = err else {
7874 panic!("expected FonteRepoShape, got other variant");
7875 };
7876 assert!(
7877 reason.contains("2048"),
7878 "reason must name the cap, got {reason:?}"
7879 );
7880 }
7881
7882 #[test]
7883 fn validate_accepts_canonical_git_fonte_repo_shapes() {
7884 // The positive-control sweep: every documented author shape on
7885 // the `:fonte :repo` axis ([`crate::DepSource::Git`] doc comment)
7886 // must pass the value-shape gate. Pinned so a future tightening
7887 // (e.g. forbidding `http://` in favor of `https://`-only) surfaces
7888 // here as a structural decision. Each form is exercised with the
7889 // same canonical `:tag` pin so only the `:repo` axis varies.
7890 for repo in [
7891 // The pleme-io registry-shorthand convention — `github:org/repo`.
7892 "github:pleme-io/caixa-teia",
7893 // Other host-aliased shorthands (the resolver's pluggable
7894 // host-prefix table).
7895 "gitlab:pleme-io/caixa-teia",
7896 "codeberg:pleme-io/caixa-teia",
7897 "sourcehut:~pleme-io/caixa-teia",
7898 // Full HTTPS URL with and without `.git` suffix.
7899 "https://github.com/pleme-io/caixa-teia",
7900 "https://github.com/pleme-io/caixa-teia.git",
7901 // HTTP (rare; dev / mirror).
7902 "http://example.com/pleme-io/caixa-teia.git",
7903 // SSH URL.
7904 "ssh://git@github.com/pleme-io/caixa-teia.git",
7905 "ssh://git@git.example.com:2222/pleme-io/caixa-teia.git",
7906 // Scp-style SSH — the canonical `git@host:path` short form.
7907 "git@github.com:pleme-io/caixa-teia.git",
7908 "git@git.example.com:team/private.git",
7909 // Anonymous git protocol.
7910 "git://git.example.com/pleme-io/caixa-teia.git",
7911 // Local file URL (dev path).
7912 "file:///tmp/caixa-teia",
7913 ] {
7914 let d = dep_with_fonte(DepSource::Git {
7915 repo: repo.into(),
7916 tag: Some("v0.1.0".into()),
7917 rev: None,
7918 branch: None,
7919 });
7920 d.validate()
7921 .unwrap_or_else(|e| panic!("canonical repo {repo:?} must validate, got {e:?}"));
7922 }
7923 }
7924
7925 #[test]
7926 fn fonte_repo_empty_takes_precedence_over_shape() {
7927 // Order pin: the existing `FonteRepoEmpty` diagnostic (narrower
7928 // diagnostic; doesn't try to parse the URL shape) fires before
7929 // the new `FonteRepoShape` per-axis gate, so an empty `:repo`
7930 // keeps its narrower error message. Mirrors
7931 // `fonte_repo_empty_fires_before_pin_missing` (already pinned)
7932 // on the ordering layer.
7933 let d = dep_with_fonte(DepSource::Git {
7934 repo: String::new(),
7935 tag: Some("v0.1.0".into()),
7936 rev: None,
7937 branch: None,
7938 });
7939 let err = d.validate().unwrap_err();
7940 assert!(
7941 matches!(err, DepError::FonteRepoEmpty { .. }),
7942 "got {err:?}"
7943 );
7944 }
7945
7946 #[test]
7947 fn fonte_repo_shape_fires_before_pin_missing() {
7948 // Order pin: a malformed `:repo` value on a dep with no pin set
7949 // surfaces the `:repo` shape diagnostic (the more self-locating
7950 // axis — the `:repo` is the load-bearing identity of the source;
7951 // a missing pin is downstream from "do we even know the repo")
7952 // rather than collapsing onto the pin-missing diagnostic. The
7953 // shape gate runs inline before the pin enumeration in
7954 // `DepSource::validate`.
7955 let d = dep_with_fonte(DepSource::Git {
7956 repo: "pleme-io/caixa-teia".into(), // missing `:` separator
7957 tag: None,
7958 rev: None,
7959 branch: None,
7960 });
7961 let err = d.validate().unwrap_err();
7962 assert!(
7963 matches!(err, DepError::FonteRepoShape { .. }),
7964 "got {err:?}"
7965 );
7966 }
7967
7968 #[test]
7969 fn fonte_repo_shape_diagnostic_carries_offending_repo_verbatim() {
7970 // The diagnostic-shape pin: the error names the offending
7971 // `:repo` value verbatim plus a non-empty parser-shaped `reason`
7972 // so the author can grep their caixa.lisp without re-running
7973 // the build. Mirrors the diagnostic-shape sweep on every prior
7974 // value-shape gate (3f9d7a0, 6cbb900, c7d05ec, e70d213, be07fd5).
7975 let d = dep_with_fonte(DepSource::Git {
7976 repo: "pleme-io/caixa-teia".into(),
7977 tag: Some("v0.1.0".into()),
7978 rev: None,
7979 branch: None,
7980 });
7981 let err = d.validate().unwrap_err();
7982 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7983 panic!("expected FonteRepoShape, got other variant");
7984 };
7985 assert_eq!(nome, "caixa-teia");
7986 assert_eq!(repo, "pleme-io/caixa-teia");
7987 assert!(
7988 !reason.is_empty(),
7989 "FonteRepoShape `reason` must carry the predicate's wording verbatim"
7990 );
7991 }
7992
7993 #[test]
7994 fn validate_rejects_git_fonte_with_no_pin() {
7995 // The fail-before-pass-after pin for the canonical
7996 // `(:tipo git :repo "github:pleme-io/x")` shape with no
7997 // :tag/:rev/:branch — until this gate landed the resolver's
7998 // ResolveError::MissingPin surfaced at fetch time, far from the
7999 // source caixa.lisp. The new gate moves the check to validate
8000 // time and names the offending dep.
8001 let d = dep_with_fonte(DepSource::Git {
8002 repo: "github:pleme-io/caixa-teia".into(),
8003 tag: None,
8004 rev: None,
8005 branch: None,
8006 });
8007 let err = d.validate().unwrap_err();
8008 assert!(
8009 matches!(err, DepError::FontePinMissing { ref nome } if nome == "caixa-teia"),
8010 "got {err:?}"
8011 );
8012 }
8013
8014 #[test]
8015 fn validate_rejects_git_fonte_with_ambiguous_tag_and_branch() {
8016 // The canonical "pin drift" footgun: an author writes
8017 // `:tag "v1"` and later adds `:branch "main"` without removing
8018 // the :tag, and the resolver silently picks :tag (precedence
8019 // :rev > :tag > :branch). The :branch was dropped with no
8020 // diagnostic. The gate now rejects multi-pin shapes so the
8021 // author makes the precedence explicit at the source.
8022 let d = dep_with_fonte(DepSource::Git {
8023 repo: "github:pleme-io/caixa-teia".into(),
8024 tag: Some("v0.1.0".into()),
8025 rev: None,
8026 branch: Some("main".into()),
8027 });
8028 let err = d.validate().unwrap_err();
8029 let DepError::FontePinAmbiguous { nome, pins } = err else {
8030 panic!("expected FontePinAmbiguous");
8031 };
8032 assert_eq!(nome, "caixa-teia");
8033 assert!(pins.contains(":tag"));
8034 assert!(pins.contains(":branch"));
8035 assert!(!pins.contains(":rev"));
8036 }
8037
8038 #[test]
8039 fn validate_rejects_git_fonte_with_ambiguous_tag_and_rev() {
8040 // Sibling arm of the pin-drift footgun: :tag + :rev set
8041 // simultaneously. Pinned separately so a future relaxation
8042 // that only catches the (:tag, :branch) pair surfaces here.
8043 let d = dep_with_fonte(DepSource::Git {
8044 repo: "github:pleme-io/caixa-teia".into(),
8045 tag: Some("v0.1.0".into()),
8046 rev: Some("c0ffee".into()),
8047 branch: None,
8048 });
8049 let err = d.validate().unwrap_err();
8050 let DepError::FontePinAmbiguous { nome, pins } = err else {
8051 panic!("expected FontePinAmbiguous");
8052 };
8053 assert_eq!(nome, "caixa-teia");
8054 assert!(pins.contains(":tag"));
8055 assert!(pins.contains(":rev"));
8056 }
8057
8058 #[test]
8059 fn validate_rejects_git_fonte_with_all_three_pins() {
8060 // The maximal ambiguity case — every pin axis set. Pinned so a
8061 // future relaxation that only catches pairs surfaces here. The
8062 // diagnostic must enumerate every offending axis so the author
8063 // sees the full set, not just the first match.
8064 let d = dep_with_fonte(DepSource::Git {
8065 repo: "github:pleme-io/caixa-teia".into(),
8066 tag: Some("v0.1.0".into()),
8067 rev: Some("c0ffee".into()),
8068 branch: Some("main".into()),
8069 });
8070 let err = d.validate().unwrap_err();
8071 let DepError::FontePinAmbiguous { nome, pins } = err else {
8072 panic!("expected FontePinAmbiguous");
8073 };
8074 assert_eq!(nome, "caixa-teia");
8075 assert!(pins.contains(":tag"));
8076 assert!(pins.contains(":rev"));
8077 assert!(pins.contains(":branch"));
8078 }
8079
8080 #[test]
8081 fn validate_rejects_git_fonte_with_empty_tag_pin() {
8082 // The empty-pin arm: exactly one pin axis is `Some(_)`, but its
8083 // inner string is empty. Distinct from FontePinMissing (where
8084 // every axis is None) — pinned separately so a future
8085 // tightening collapsing them surfaces here as a structural
8086 // decision.
8087 let d = dep_with_fonte(DepSource::Git {
8088 repo: "github:pleme-io/caixa-teia".into(),
8089 tag: Some(String::new()),
8090 rev: None,
8091 branch: None,
8092 });
8093 let err = d.validate().unwrap_err();
8094 let DepError::FontePinEmpty { nome, pin } = err else {
8095 panic!("expected FontePinEmpty");
8096 };
8097 assert_eq!(nome, "caixa-teia");
8098 assert_eq!(pin, ":tag");
8099 }
8100
8101 #[test]
8102 fn validate_rejects_git_fonte_with_empty_rev_pin() {
8103 // Sibling arm — the empty-pin diagnostic names which axis
8104 // carries the empty value, so the author's grep target is
8105 // unambiguous.
8106 let d = dep_with_fonte(DepSource::Git {
8107 repo: "github:pleme-io/caixa-teia".into(),
8108 tag: None,
8109 rev: Some(String::new()),
8110 branch: None,
8111 });
8112 let err = d.validate().unwrap_err();
8113 let DepError::FontePinEmpty { nome, pin } = err else {
8114 panic!("expected FontePinEmpty");
8115 };
8116 assert_eq!(nome, "caixa-teia");
8117 assert_eq!(pin, ":rev");
8118 }
8119
8120 #[test]
8121 fn validate_rejects_path_fonte_with_empty_caminho() {
8122 // The fail-before-pass-after pin for `(:tipo path :caminho "")`:
8123 // until this gate landed the resolver's
8124 // ResolveError::MissingPath surfaced with `path: PathBuf("")` at
8125 // fetch time — not actionable. The new gate moves the check to
8126 // validate time and names the offending dep.
8127 let d = dep_with_fonte(DepSource::Path {
8128 caminho: String::new(),
8129 });
8130 let err = d.validate().unwrap_err();
8131 assert!(
8132 matches!(err, DepError::FonteCaminhoEmpty { ref nome } if nome == "caixa-teia"),
8133 "got {err:?}"
8134 );
8135 }
8136
8137 #[test]
8138 fn validate_rejects_path_fonte_with_absolute_caminho() {
8139 // The fail-before-pass-after pin for the absolute-`:caminho`
8140 // shape: `(:tipo path :caminho "/home/me/work/caixa-teia")`.
8141 // Until this gate landed an absolute `:caminho` silently
8142 // passed validate; the lacre pipeline embedded the
8143 // host-specific filesystem path verbatim in its
8144 // content-address (`conteudo: format!("path:{caminho}")`,
8145 // caixa-resolver/src/resolve.rs:189), so the BLAKE3 closure
8146 // differed per machine — the build succeeded but two CI
8147 // runners with different `${HOME}` layouts emitted two
8148 // distinct lacres for the byte-identical caixa, silently
8149 // breaking the THEORY.md §V.2 render-determinism contract
8150 // far from the source caixa.lisp. The new gate moves the
8151 // check to validate time and names the offending dep +
8152 // caminho verbatim.
8153 let d = dep_with_fonte(DepSource::Path {
8154 caminho: "/home/me/work/caixa-teia".into(),
8155 });
8156 let err = d.validate().unwrap_err();
8157 let DepError::FonteCaminhoAbsolute { nome, caminho } = err else {
8158 panic!("expected FonteCaminhoAbsolute, got other variant");
8159 };
8160 assert_eq!(nome, "caixa-teia");
8161 assert_eq!(caminho, "/home/me/work/caixa-teia");
8162 }
8163
8164 #[test]
8165 fn validate_accepts_path_fonte_with_parent_escape_caminho() {
8166 // The canonical sibling-workspace dep form
8167 // (`:caminho "../caixa-teia"`) remains accepted. The
8168 // absolute-path gate above is specifically narrower than the
8169 // shared [`crate::render::is_sandboxed_relative_path`]
8170 // predicate (which additionally forbids `..` traversal): a
8171 // local-path dep's canonical author surface is the in-tree
8172 // sibling-workspace path, so a full sandboxed-relative-path
8173 // lift would structurally reject every legitimate path-fonte
8174 // dep. Pinned so a future tightening to the full predicate
8175 // surfaces here as a structural decision, not a silent break.
8176 let d = dep_with_fonte(DepSource::Path {
8177 caminho: "../caixa-teia".into(),
8178 });
8179 d.validate().unwrap();
8180 }
8181
8182 #[test]
8183 fn validate_accepts_path_fonte_with_deeply_nested_relative_caminho() {
8184 // A multi-segment relative `:caminho`
8185 // (`"vendor/forks/caixa-teia"`) remains accepted — the
8186 // absolute-path gate brackets the host-layout-leaking shape
8187 // at the leading-`/` boundary only; every relative shape past
8188 // the empty arm continues to pass. Pinned alongside the
8189 // `..`-traversal positive control so a future tightening
8190 // surfaces the full set of legitimate relative forms here
8191 // rather than at a downstream consumer.
8192 let d = dep_with_fonte(DepSource::Path {
8193 caminho: "vendor/forks/caixa-teia".into(),
8194 });
8195 d.validate().unwrap();
8196 }
8197
8198 #[test]
8199 fn validate_rejects_path_fonte_with_tilde_prefix_caminho() {
8200 // The fail-before-pass-after pin for the tilde-expansion
8201 // `:caminho` shape: `(:tipo path :caminho "~/work/caixa-teia")`.
8202 // Until this gate landed the b94fd83 absolute arm let `~/foo`
8203 // through (`Path::is_absolute` returns false on a leading `~`
8204 // — the tilde is a shell-expansion convention, not a POSIX
8205 // path component), so the lacre embedded the value verbatim
8206 // and the resolver folded it through `Path::join` without
8207 // expansion, looking for a literal `./~/work/caixa-teia`
8208 // subdirectory and failing at resolve time with a
8209 // `No such file or directory` error far from the source
8210 // caixa.lisp. The new gate moves the check to validate time
8211 // and names the offending dep + caminho verbatim.
8212 let d = dep_with_fonte(DepSource::Path {
8213 caminho: "~/work/caixa-teia".into(),
8214 });
8215 let err = d.validate().unwrap_err();
8216 let DepError::FonteCaminhoTildeExpansion { nome, caminho } = err else {
8217 panic!("expected FonteCaminhoTildeExpansion, got {err:?}");
8218 };
8219 assert_eq!(nome, "caixa-teia");
8220 assert_eq!(caminho, "~/work/caixa-teia");
8221 }
8222
8223 #[test]
8224 fn validate_rejects_path_fonte_with_bare_tilde_caminho() {
8225 // The bare `~` form (canonical "I meant `$HOME` and forgot
8226 // the rest"): both the leading-tilde arm catches it and the
8227 // canonical-user-tilde shell idiom (`~alice/dev/caixa-teia`)
8228 // sweeps through the same arm. Pinned both to ensure the
8229 // gate doesn't narrow to `~/` only.
8230 for s in ["~", "~alice/dev/caixa-teia", "~/", "~root/work"] {
8231 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
8232 let err = d.validate().unwrap_err();
8233 assert!(
8234 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
8235 "{s:?} → {err:?}",
8236 );
8237 }
8238 }
8239
8240 #[test]
8241 fn validate_accepts_path_fonte_with_mid_path_tilde_caminho() {
8242 // The leading-`~` is the canonical shell-expansion footgun —
8243 // a tilde mid-path (`"../foo~bar/caixa-teia"` — the canonical
8244 // backup-file-suffix idiom) is a legitimate POSIX path byte
8245 // with no shell-expansion semantic at the leading position.
8246 // Pinned so the gate doesn't widen to a full no-tilde-anywhere
8247 // sweep that would break every legitimate-shape backup-file
8248 // path.
8249 let d = dep_with_fonte(DepSource::Path {
8250 caminho: "../foo~bar/caixa-teia".into(),
8251 });
8252 d.validate().unwrap();
8253 }
8254
8255 #[test]
8256 fn fonte_caminho_empty_fires_before_tilde_expansion() {
8257 // Cascade pin: the empty arm structurally precedes the
8258 // tilde arm (the bytes `""` and `"~"` don't overlap), but the
8259 // pin establishes the precedence at the diagnostic-shape
8260 // level should a future codec round-trip ever produce a
8261 // probe-as-both value. Mirrors the peer
8262 // `fonte_repo_empty_fires_before_pin_missing` cascade
8263 // discipline.
8264 let d = dep_with_fonte(DepSource::Path {
8265 caminho: String::new(),
8266 });
8267 let err = d.validate().unwrap_err();
8268 assert!(
8269 matches!(err, DepError::FonteCaminhoEmpty { .. }),
8270 "got {err:?}",
8271 );
8272 }
8273
8274 #[test]
8275 fn fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho() {
8276 // Diagnostic-shape pin (peer with
8277 // `validate_rejects_path_fonte_with_absolute_caminho`'s
8278 // payload assertion): the error's Display surfaces both the
8279 // offending `:nome` and the offending `:caminho` verbatim
8280 // so a `feira lint` run can render the diagnostic without
8281 // re-parsing.
8282 let d = dep_with_fonte(DepSource::Path {
8283 caminho: "~alice/dev/caixa-teia".into(),
8284 });
8285 let rendered = d.validate().unwrap_err().to_string();
8286 assert!(
8287 rendered.contains("caixa-teia"),
8288 "diagnostic must name the offending dep: {rendered}",
8289 );
8290 assert!(
8291 rendered.contains("~alice/dev/caixa-teia"),
8292 "diagnostic must quote the offending caminho: {rendered}",
8293 );
8294 assert!(
8295 rendered.contains('~'),
8296 "diagnostic must reference the tilde footgun: {rendered}",
8297 );
8298 }
8299
8300 #[test]
8301 fn validate_rejects_path_fonte_with_dollar_prefix_caminho() {
8302 // The fail-before-pass-after pin for the shell-variable-
8303 // expansion `:caminho` shape: `(:tipo path :caminho
8304 // "$HOME/work/caixa-teia")`. Until this gate landed the
8305 // b94fd83 absolute arm + the a5c248e tilde arm both let
8306 // `$HOME/foo` through (`Path::is_absolute` returns false on
8307 // a leading `$` — the `$` is a shell convention, not a POSIX
8308 // path component; `starts_with('~')` returns false too), so
8309 // the lacre embedded the value verbatim and the resolver
8310 // folded it through `Path::join` without `$`-expansion,
8311 // looking for a literal `./$HOME/work/caixa-teia`
8312 // subdirectory and failing at resolve time with a
8313 // `No such file or directory` error far from the source
8314 // caixa.lisp. The new gate moves the check to validate time
8315 // and names the offending dep + caminho verbatim.
8316 let d = dep_with_fonte(DepSource::Path {
8317 caminho: "$HOME/work/caixa-teia".into(),
8318 });
8319 let err = d.validate().unwrap_err();
8320 let DepError::FonteCaminhoVarExpansion { nome, caminho } = err else {
8321 panic!("expected FonteCaminhoVarExpansion, got {err:?}");
8322 };
8323 assert_eq!(nome, "caixa-teia");
8324 assert_eq!(caminho, "$HOME/work/caixa-teia");
8325 }
8326
8327 #[test]
8328 fn validate_rejects_path_fonte_with_dollar_brace_prefix_caminho() {
8329 // Sweep over every leading-`$` shape: the `${VAR}`-braced
8330 // form (canonical "paste-from-CI-manifest" footgun every
8331 // GitHub Actions / GitLab CI / Drone manifest carries on
8332 // `${WORKSPACE}`), the XDG idiom (`$XDG_CONFIG_HOME/caixa`,
8333 // canonical "I'm referencing a per-user config dir"),
8334 // and the bare `$` (canonical "I meant `$HOME` and forgot
8335 // the rest"). All shapes route through the same gate's
8336 // byte check. Pinned so the gate doesn't narrow to a
8337 // single shape (e.g. `$HOME/` only).
8338 for s in [
8339 "${HOME}/work/caixa-teia",
8340 "${WORKSPACE}/caixa-teia",
8341 "$XDG_CONFIG_HOME/caixa",
8342 "$",
8343 ] {
8344 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
8345 let err = d.validate().unwrap_err();
8346 assert!(
8347 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8348 "{s:?} → {err:?}",
8349 );
8350 }
8351 }
8352
8353 #[test]
8354 fn validate_rejects_path_fonte_with_mid_path_dollar_caminho() {
8355 // The `$` byte is the canonical shell-variable-expansion /
8356 // command-substitution / arithmetic-expansion sentinel and
8357 // is rejected at *every* position on the `:caminho` axis: the
8358 // leading arm surfaces `FonteCaminhoVarExpansion`, the
8359 // embedded arm surfaces `FonteCaminhoShellVariableExpansion`
8360 // (6620f39). Pinned so a future arm doesn't narrow the gate
8361 // back to the leading position and re-open the paste-from-
8362 // shell-one-liner `"../foo$HOME/bar"` / paste-from-CI-
8363 // manifest `"../foo${WORKSPACE}/bar"` / paste-from-shell-
8364 // prompt `"../foo$(whoami)/bar"` cross-idiom-leak surface on
8365 // the lacre content-address (`path:{caminho}`,
8366 // caixa-resolver/src/resolve.rs:189).
8367 let d = dep_with_fonte(DepSource::Path {
8368 caminho: "../foo$bar/caixa-teia".into(),
8369 });
8370 let err = d.validate().unwrap_err();
8371 assert!(
8372 matches!(
8373 err,
8374 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
8375 ),
8376 "got {err:?}",
8377 );
8378 }
8379
8380 #[test]
8381 fn fonte_caminho_tilde_fires_before_var_expansion() {
8382 // Cascade pin: the tilde arm structurally precedes the var
8383 // arm (the bytes `~` and `$` don't overlap at the leading
8384 // position), but the pin establishes the precedence at the
8385 // diagnostic-shape level should a future codec round-trip
8386 // ever produce a probe-as-both value. Mirrors the peer
8387 // `fonte_caminho_empty_fires_before_tilde_expansion` cascade
8388 // discipline on the immediate-predecessor arm.
8389 let d = dep_with_fonte(DepSource::Path {
8390 caminho: "~/work/caixa-teia".into(),
8391 });
8392 let err = d.validate().unwrap_err();
8393 assert!(
8394 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
8395 "got {err:?}",
8396 );
8397 }
8398
8399 #[test]
8400 fn fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho() {
8401 // Diagnostic-shape pin (peer with
8402 // `fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho`'s
8403 // payload assertion on the immediate-predecessor arm): the
8404 // error's Display surfaces both the offending `:nome` and
8405 // the offending `:caminho` verbatim plus the `$` footgun
8406 // character itself so a `feira lint` run can render the
8407 // diagnostic without re-parsing.
8408 let d = dep_with_fonte(DepSource::Path {
8409 caminho: "${WORKSPACE}/caixa-teia".into(),
8410 });
8411 let rendered = d.validate().unwrap_err().to_string();
8412 assert!(
8413 rendered.contains("caixa-teia"),
8414 "diagnostic must name the offending dep: {rendered}",
8415 );
8416 assert!(
8417 rendered.contains("${WORKSPACE}/caixa-teia"),
8418 "diagnostic must quote the offending caminho: {rendered}",
8419 );
8420 assert!(
8421 rendered.contains('$'),
8422 "diagnostic must reference the dollar footgun: {rendered}",
8423 );
8424 }
8425
8426 #[test]
8427 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_nul() {
8428 // The fail-before-pass-after pin for the load-bearing NUL byte:
8429 // POSIX paths cannot contain `0x00` (every `std::fs` syscall
8430 // routes the path through `CString::new` which fails with
8431 // `NulError`); until this gate landed a `:caminho
8432 // "../caixa\0teia"` silently passed validate, the lacre
8433 // pipeline embedded the value verbatim, and the failure
8434 // surfaced at the resolver's `Path::join` → `CString::new`
8435 // boundary with a non-self-locating `NulError` far from the
8436 // source caixa.lisp. The new gate moves the check to validate
8437 // time and names the offending dep + caminho + offending byte
8438 // verbatim.
8439 let d = dep_with_fonte(DepSource::Path {
8440 caminho: "../caixa\0teia".into(),
8441 });
8442 let err = d.validate().unwrap_err();
8443 let DepError::FonteCaminhoControlChar {
8444 nome,
8445 caminho,
8446 byte,
8447 } = err
8448 else {
8449 panic!("expected FonteCaminhoControlChar, got {err:?}");
8450 };
8451 assert_eq!(nome, "caixa-teia");
8452 assert_eq!(caminho, "../caixa\0teia");
8453 assert_eq!(byte, 0x00);
8454 }
8455
8456 #[test]
8457 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_newline() {
8458 // The canonical paste-from-multiline-doc footgun on `:caminho`
8459 // — author copies `"../caixa-teia\n"` (trailing newline) out
8460 // of a multi-line code-fence or, worse, a `:caminho
8461 // "../caixa-teia\nrm -rf /"` value (CRLF-at-subprocess-argument
8462 // injection sibling on the path axis the `is_git_repo_url`
8463 // control-char arm already closes on `:repo`). Pinned
8464 // separately from the NUL arm so a future relaxation that
8465 // catches one but not the other surfaces here.
8466 let d = dep_with_fonte(DepSource::Path {
8467 caminho: "../caixa-teia\n".into(),
8468 });
8469 let err = d.validate().unwrap_err();
8470 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8471 panic!("expected FonteCaminhoControlChar, got {err:?}");
8472 };
8473 assert_eq!(byte, 0x0A);
8474 }
8475
8476 #[test]
8477 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_carriage_return() {
8478 // The CRLF sibling of the LF arm — Windows-line-ending
8479 // paste-from-multiline-doc on a `\r\n`-terminated buffer
8480 // leaves a stray `\r` mid-string after the LF strip. Pinned
8481 // separately from the LF arm so a future relaxation that
8482 // only catches LF surfaces here.
8483 let d = dep_with_fonte(DepSource::Path {
8484 caminho: "../caixa-teia\r".into(),
8485 });
8486 let err = d.validate().unwrap_err();
8487 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8488 panic!("expected FonteCaminhoControlChar, got {err:?}");
8489 };
8490 assert_eq!(byte, 0x0D);
8491 }
8492
8493 #[test]
8494 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_tab() {
8495 // The canonical paste-from-aligned-table footgun — a `\t`
8496 // mid-`:caminho` is invisible in most editors but rides
8497 // through the lacre's content-address verbatim, so two
8498 // paste-from-distinct-tables (one editor strips tabs, one
8499 // preserves them) yield divergent lacres for the byte-
8500 // identical-looking caixa. Pinned separately from the
8501 // whitespace-shaped LF/CR arms so a future relaxation that
8502 // narrows to line-terminator-only surfaces here.
8503 let d = dep_with_fonte(DepSource::Path {
8504 caminho: "../caixa\tteia".into(),
8505 });
8506 let err = d.validate().unwrap_err();
8507 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8508 panic!("expected FonteCaminhoControlChar, got {err:?}");
8509 };
8510 assert_eq!(byte, 0x09);
8511 }
8512
8513 #[test]
8514 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_del() {
8515 // The DEL byte (`0x7F`) closes the upper-end paste-from-
8516 // binary-blob footgun — the gate's contract is `b < 0x20 ||
8517 // b == 0x7F`, matching the `is_git_repo_url` /
8518 // `is_git_ref_name` predicates' control-char arms. Pinned
8519 // separately from the lower-range arms so a future narrowing
8520 // to `< 0x20` only surfaces here.
8521 let d = dep_with_fonte(DepSource::Path {
8522 caminho: "../caixa\x7fteia".into(),
8523 });
8524 let err = d.validate().unwrap_err();
8525 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8526 panic!("expected FonteCaminhoControlChar, got {err:?}");
8527 };
8528 assert_eq!(byte, 0x7F);
8529 }
8530
8531 #[test]
8532 fn validate_accepts_path_fonte_with_caminho_carrying_high_bit_utf8() {
8533 // The control-byte arm targets `0x00..=0x1F` + `0x7F` only —
8534 // high-bit / non-ASCII UTF-8 bytes are not gated. POSIX paths
8535 // are opaque byte sequences and UTF-8 multi-byte sequences
8536 // are a legitimate filename shape (the `café-teia/foo` idiom).
8537 // Pinned so the gate doesn't widen to a full ASCII-only sweep
8538 // that would break every legitimate-shape UTF-8 path.
8539 let d = dep_with_fonte(DepSource::Path {
8540 caminho: "../café-teia/foo".into(),
8541 });
8542 d.validate().unwrap();
8543 }
8544
8545 #[test]
8546 fn fonte_caminho_var_fires_before_control_char() {
8547 // Cascade pin: the var-expansion arm structurally precedes the
8548 // control-char arm. A value like `"$\n"` probes positive on
8549 // both arms (`starts_with('$')` and contains LF), but the
8550 // narrower leading-byte diagnostic (`FonteCaminhoVarExpansion`)
8551 // wins so the author sees the more self-locating shell-
8552 // expansion arm first. Mirrors the
8553 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8554 // discipline on the immediate-predecessor arm.
8555 let d = dep_with_fonte(DepSource::Path {
8556 caminho: "$HOME\n".into(),
8557 });
8558 let err = d.validate().unwrap_err();
8559 assert!(
8560 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8561 "got {err:?}",
8562 );
8563 }
8564
8565 #[test]
8566 fn validate_rejects_path_fonte_with_leading_space_caminho() {
8567 // The fail-before-pass-after pin for the leading ASCII space
8568 // `:caminho` shape: `(:tipo path :caminho " ../caixa-teia")`.
8569 // Until this gate landed the b94fd83 absolute arm + the a5c248e
8570 // tilde arm + the f4efe9c var arm + the d624c8d control-byte arm
8571 // all let `" ../caixa-teia"` through: `Path::is_absolute` returns
8572 // false on a leading space (the leading byte is `0x20`, not `0x2F`),
8573 // `starts_with('~')` / `starts_with('$')` return false, and `0x20`
8574 // is not in the `0x00..=0x1F` plus `0x7F` control-byte set (the
8575 // four ASCII whitespace bytes `0x09` tab, `0x0A` LF, `0x0D` CR
8576 // are caught, but the most common whitespace `0x20` space is
8577 // not). The lacre embedded the value verbatim and the resolver
8578 // folded it through `Path::join` looking for a literal `./ ../
8579 // caixa-teia` subdirectory and failing at resolve time with a
8580 // non-self-locating `No such file or directory` error far from
8581 // the source caixa.lisp. The new gate moves the check to
8582 // validate time and names the offending dep + caminho verbatim.
8583 let d = dep_with_fonte(DepSource::Path {
8584 caminho: " ../caixa-teia".into(),
8585 });
8586 let err = d.validate().unwrap_err();
8587 let DepError::FonteCaminhoLeadingWhitespace { nome, caminho } = err else {
8588 panic!("expected FonteCaminhoLeadingWhitespace, got {err:?}");
8589 };
8590 assert_eq!(nome, "caixa-teia");
8591 assert_eq!(caminho, " ../caixa-teia");
8592 }
8593
8594 #[test]
8595 fn validate_rejects_path_fonte_with_multiple_leading_spaces_caminho() {
8596 // The aligned-doc paste footgun sweep: more than one leading
8597 // space (`" ../caixa-teia"` — the canonical "I selected the
8598 // aligned column from a four-`:fonte`-entry `:deps` block"
8599 // paste) routes through the same gate's `starts_with(' ')`
8600 // byte check. Pinned so the gate doesn't narrow to a
8601 // single-space prefix.
8602 let d = dep_with_fonte(DepSource::Path {
8603 caminho: " ../caixa-teia".into(),
8604 });
8605 let err = d.validate().unwrap_err();
8606 assert!(
8607 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8608 "got {err:?}",
8609 );
8610 }
8611
8612 #[test]
8613 fn validate_accepts_path_fonte_with_mid_path_space_caminho() {
8614 // The leading-space is the canonical paste-from-aligned-doc
8615 // footgun — a space mid-path (`"../my dir/caixa-teia"` — the
8616 // canonical "I have a directory with a space in its name"
8617 // idiom; ASCII `0x20` is a valid POSIX filename byte) is a
8618 // legitimate path with no whitespace-leak semantic at the
8619 // non-leading position. Pinned so the gate doesn't widen to a
8620 // full no-space-anywhere sweep that would break every
8621 // legitimate-shape space-in-filename path.
8622 let d = dep_with_fonte(DepSource::Path {
8623 caminho: "../my dir/caixa-teia".into(),
8624 });
8625 d.validate().unwrap();
8626 }
8627
8628 #[test]
8629 fn fonte_caminho_var_fires_before_leading_whitespace() {
8630 // Cascade pin: the var-expansion arm structurally precedes the
8631 // leading-whitespace arm. A value like `"$ "` would probe positive
8632 // on var (`starts_with('$')`) but the leading-byte arms walk
8633 // left-to-right so the var arm fires on the leading `$` before
8634 // the leading-whitespace arm probes. Mirrors the
8635 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8636 // discipline on the immediate-predecessor arms.
8637 let d = dep_with_fonte(DepSource::Path {
8638 caminho: "$VAR".into(),
8639 });
8640 let err = d.validate().unwrap_err();
8641 assert!(
8642 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8643 "got {err:?}",
8644 );
8645 }
8646
8647 #[test]
8648 fn fonte_caminho_leading_whitespace_fires_before_control_char() {
8649 // Cascade pin: the leading-whitespace arm structurally precedes
8650 // the control-char arm. A value like `" ../foo\n"` probes
8651 // positive on both (starts with space AND contains LF), but
8652 // the narrower leading-byte diagnostic
8653 // (`FonteCaminhoLeadingWhitespace`) wins so the author sees the
8654 // more self-locating paste-from-aligned-doc arm first. Mirrors
8655 // the `fonte_caminho_var_fires_before_control_char` cascade
8656 // discipline on the immediate-predecessor arm.
8657 let d = dep_with_fonte(DepSource::Path {
8658 caminho: " ../foo\n".into(),
8659 });
8660 let err = d.validate().unwrap_err();
8661 assert!(
8662 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8663 "got {err:?}",
8664 );
8665 }
8666
8667 #[test]
8668 fn fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho() {
8669 // Diagnostic-shape pin (peer with
8670 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8671 // payload assertion on the immediate-predecessor arm): the
8672 // error's Display surfaces both the offending `:nome` and the
8673 // offending `:caminho` verbatim, so a `feira lint` run can
8674 // render the diagnostic without re-parsing and the author can
8675 // grep their caixa.lisp for `:caminho "<value>"` and fix it in
8676 // one edit.
8677 let d = dep_with_fonte(DepSource::Path {
8678 caminho: " ../caixa-teia".into(),
8679 });
8680 let rendered = d.validate().unwrap_err().to_string();
8681 assert!(
8682 rendered.contains("caixa-teia"),
8683 "diagnostic must name the offending dep: {rendered}",
8684 );
8685 assert!(
8686 rendered.contains(" ../caixa-teia"),
8687 "diagnostic must quote the offending caminho: {rendered}",
8688 );
8689 assert!(
8690 rendered.contains("space"),
8691 "diagnostic must name the space footgun: {rendered}",
8692 );
8693 }
8694
8695 #[test]
8696 fn fonte_caminho_absolute_fires_before_control_char() {
8697 // Cascade pin on the sibling leading-byte arm: a leading `/`
8698 // value with embedded control byte (`"/etc/passwd\n"`) routes
8699 // through `FonteCaminhoAbsolute` not `FonteCaminhoControlChar`
8700 // — the host-layout-leak diagnostic is the load-bearing axis,
8701 // the control byte is the secondary observation. Same precedence
8702 // logic on every prior leading-byte arm.
8703 let d = dep_with_fonte(DepSource::Path {
8704 caminho: "/etc/passwd\n".into(),
8705 });
8706 let err = d.validate().unwrap_err();
8707 assert!(
8708 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8709 "got {err:?}",
8710 );
8711 }
8712
8713 #[test]
8714 fn validate_rejects_path_fonte_with_leading_hyphen_caminho() {
8715 // The fail-before-pass-after pin for the leading-`-` CLI-arg-
8716 // injection `:caminho` shape sweep. Until this gate landed
8717 // every prior leading-byte arm passed a leading-`-` value
8718 // through: `Path::is_absolute` returns false on `-` (the
8719 // leading byte is `0x2D`, not `0x2F`), `starts_with('~')` /
8720 // `starts_with('$')` / `starts_with(' ')` all return false,
8721 // and `0x2D` sits outside the control-byte set. The lacre
8722 // embedded the value verbatim and the resolver folded it
8723 // through `Path::join` looking for a literal `./-rf` /
8724 // `./-C` / `./--upload-pack=…` subdirectory; the failure at
8725 // `Path::join` time is non-self-locating but harmless, while
8726 // the failure at every downstream `git -C {caminho}` /
8727 // `terraform -chdir={caminho}` / `find {caminho}` shell-out
8728 // is arbitrary-CLI-arg-injection because none of those
8729 // porcelains carry a `--` argument-list terminator between
8730 // the flag block and the path argument. The new arm moves the
8731 // rejection to `Caixa::from_lisp` boundary time and names
8732 // the offending dep + caminho verbatim.
8733 //
8734 // Sweep spans the canonical CLI-arg-injection shapes matching
8735 // the peer sweep on the sibling `is_git_ref_name` /
8736 // `is_git_repo_url` axes: short-flag `-rf` (the `rm -rf` /
8737 // `find -rf` reinterpretation vector), `-C` (the `git -C`
8738 // change-directory-config-injection paste), long-flag
8739 // `--upload-pack=cat /etc/passwd` (the canonical
8740 // arbitrary-command-execution vector on every git porcelain
8741 // entry point), git-config-injection `--config=core.merge=ours`,
8742 // and the degenerate single-byte `-` value.
8743 for caminho in [
8744 "-rf",
8745 "-C",
8746 "--upload-pack=cat /etc/passwd",
8747 "--config=core.merge=ours",
8748 "-",
8749 ] {
8750 let d = dep_with_fonte(DepSource::Path {
8751 caminho: caminho.into(),
8752 });
8753 let err = d.validate().unwrap_err();
8754 let DepError::FonteCaminhoLeadingHyphen { nome, caminho: got } = err else {
8755 panic!("expected FonteCaminhoLeadingHyphen for {caminho:?}, got {err:?}");
8756 };
8757 assert_eq!(nome, "caixa-teia");
8758 assert_eq!(got, caminho);
8759 }
8760 }
8761
8762 #[test]
8763 fn validate_accepts_path_fonte_with_mid_path_hyphen_caminho() {
8764 // The leading-`-` is the canonical CLI-arg-injection footgun
8765 // — a `-` anywhere else in the path (`"../caixa-teia"` — the
8766 // canonical kebab-separator-between-alphanumeric-segments
8767 // shape every DNS-1123-shaped caixa name carries; `"../-hidden"`
8768 // — a mid-path segment starting with `-`, still a legitimate
8769 // POSIX filename byte at that non-leading position because the
8770 // subprocess reads the whole `{caminho}` value as one positional
8771 // argument, so only the very first byte of the composite path
8772 // string is at the CLI-arg-injection boundary) is a legitimate
8773 // path with no CLI-flag-reinterpretation semantic at the non-
8774 // leading position of the top-level value. Pinned so the gate
8775 // doesn't widen to a full no-`-`-anywhere sweep that would
8776 // break every legitimate-shape kebab-in-filename path (i.e.
8777 // essentially every sibling-workspace caixa dep).
8778 for caminho in [
8779 "../caixa-teia",
8780 "../caixa-teia/-hidden",
8781 "./my-lib",
8782 "../foo-bar/baz",
8783 ] {
8784 let d = dep_with_fonte(DepSource::Path {
8785 caminho: caminho.into(),
8786 });
8787 d.validate()
8788 .unwrap_or_else(|e| panic!("mid-path `-` caminho {caminho:?} must pass: {e:?}"));
8789 }
8790 }
8791
8792 #[test]
8793 fn fonte_caminho_leading_whitespace_fires_before_leading_hyphen() {
8794 // Cascade pin: the leading-whitespace arm structurally precedes
8795 // the leading-hyphen arm. A value like `" -rf"` probes positive
8796 // on both (leading space AND, one byte in, a `-` — though the
8797 // leading-hyphen arm probes only the very first byte so it
8798 // wouldn't fire on this value; the pin instead documents the
8799 // arm order on the more common "leading space then a hyphen"
8800 // paste-from-aligned-doc paste-flag-shell-one-liner idiom).
8801 // The narrower leading-space diagnostic (the paste-from-aligned-
8802 // doc footgun) wins so the author sees the more self-locating
8803 // whitespace arm first. Mirrors the
8804 // `fonte_caminho_var_fires_before_leading_whitespace` cascade
8805 // discipline on the immediate-predecessor arm.
8806 let d = dep_with_fonte(DepSource::Path {
8807 caminho: " -rf".into(),
8808 });
8809 let err = d.validate().unwrap_err();
8810 assert!(
8811 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8812 "got {err:?}",
8813 );
8814 }
8815
8816 #[test]
8817 fn fonte_caminho_leading_hyphen_fires_before_control_char() {
8818 // Cascade pin: the leading-hyphen arm structurally precedes
8819 // the control-char arm. A value like `"-rf\n"` probes positive
8820 // on both (starts with `-` AND contains LF), but the narrower
8821 // leading-byte diagnostic (`FonteCaminhoLeadingHyphen`) wins so
8822 // the author sees the more self-locating CLI-arg-injection arm
8823 // first. Mirrors the
8824 // `fonte_caminho_leading_whitespace_fires_before_control_char`
8825 // cascade discipline on the immediate-predecessor arm.
8826 let d = dep_with_fonte(DepSource::Path {
8827 caminho: "-rf\n".into(),
8828 });
8829 let err = d.validate().unwrap_err();
8830 assert!(
8831 matches!(err, DepError::FonteCaminhoLeadingHyphen { .. }),
8832 "got {err:?}",
8833 );
8834 }
8835
8836 #[test]
8837 fn fonte_caminho_leading_hyphen_diagnostic_carries_offending_dep_and_caminho() {
8838 // Diagnostic-shape pin (peer with
8839 // `fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho`'s
8840 // payload assertion on the immediate-predecessor arm): the
8841 // error's Display surfaces both the offending `:nome` and the
8842 // offending `:caminho` verbatim plus the CLI-argument-injection
8843 // vocabulary, so a `feira lint` run can render the diagnostic
8844 // without re-parsing and the author can grep their caixa.lisp
8845 // for `:caminho "<value>"` and fix it in one edit.
8846 let d = dep_with_fonte(DepSource::Path {
8847 caminho: "--upload-pack=cat /etc/passwd".into(),
8848 });
8849 let rendered = d.validate().unwrap_err().to_string();
8850 assert!(
8851 rendered.contains("caixa-teia"),
8852 "diagnostic must name the offending dep: {rendered}",
8853 );
8854 assert!(
8855 rendered.contains("--upload-pack=cat /etc/passwd"),
8856 "diagnostic must quote the offending caminho: {rendered}",
8857 );
8858 assert!(
8859 rendered.contains("CLI-argument-injection"),
8860 "diagnostic must name the CLI-argument-injection vector: {rendered}",
8861 );
8862 assert!(
8863 rendered.contains("`-`"),
8864 "diagnostic must name the offending byte: {rendered}",
8865 );
8866 }
8867
8868 #[test]
8869 fn fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte() {
8870 // Diagnostic-shape pin (peer with
8871 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8872 // payload assertion on the immediate-predecessor arm): the
8873 // error's Display surfaces the offending `:nome`, the
8874 // offending `:caminho` verbatim, and the offending byte in
8875 // hex form (`0x09` for tab) so a `feira lint` run can render
8876 // the diagnostic without re-parsing.
8877 let d = dep_with_fonte(DepSource::Path {
8878 caminho: "../caixa\tteia".into(),
8879 });
8880 let rendered = d.validate().unwrap_err().to_string();
8881 assert!(
8882 rendered.contains("caixa-teia"),
8883 "diagnostic must name the offending dep: {rendered}",
8884 );
8885 assert!(
8886 rendered.contains("../caixa\tteia"),
8887 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8888 );
8889 assert!(
8890 rendered.contains("0x09"),
8891 "diagnostic must name the offending byte in hex: {rendered:?}",
8892 );
8893 }
8894
8895 #[test]
8896 fn validate_rejects_path_fonte_with_caminho_carrying_backslash() {
8897 // The fail-before-pass-after pin for the canonical Windows-
8898 // path-separator paste footgun: an author who pastes a path
8899 // from Windows-Explorer's `Copy as path`, PowerShell's
8900 // `Get-Location`, or any CMD/Cygwin/MSYS shell prompt
8901 // produces `..\caixa-teia`-shape values that silently passed
8902 // every prior arm (`Path::is_absolute("..\\caixa-teia")` is
8903 // false; `\` is neither a leading-byte sentinel nor a
8904 // control byte). On POSIX resolvers the value rides through
8905 // `Path::join` as a literal directory name and fails at
8906 // resolve time with `No such file or directory`; on Windows
8907 // resolvers the value resolves to the parent's sibling — two
8908 // distinct directories for the byte-identical caixa.lisp.
8909 // The new arm moves the rejection to validate time and names
8910 // the offending dep + caminho verbatim.
8911 let d = dep_with_fonte(DepSource::Path {
8912 caminho: "..\\caixa-teia".into(),
8913 });
8914 let err = d.validate().unwrap_err();
8915 let DepError::FonteCaminhoBackslash { nome, caminho } = err else {
8916 panic!("expected FonteCaminhoBackslash, got {err:?}");
8917 };
8918 assert_eq!(nome, "caixa-teia");
8919 assert_eq!(caminho, "..\\caixa-teia");
8920 }
8921
8922 #[test]
8923 fn validate_rejects_path_fonte_with_caminho_carrying_windows_drive_letter() {
8924 // The Windows drive-letter paste shape (`C:\work\caixa-teia`
8925 // out of Explorer / `cd`-and-`pwd`-on-Windows). On POSIX
8926 // hosts `Path::is_absolute("C:\\work\\caixa-teia")` returns
8927 // false (POSIX absolute paths start with `/`, drive letters
8928 // are not a POSIX concept), so the b94fd83 absolute arm
8929 // doesn't fire; the value contains `\` bytes that this arm
8930 // now catches with the more self-locating Windows-path-
8931 // separator diagnostic. Pinned separately from the bare
8932 // `..\caixa-teia` shape so a future arm that targets only
8933 // leading-`..\` doesn't regress the drive-letter coverage.
8934 let d = dep_with_fonte(DepSource::Path {
8935 caminho: "C:\\work\\caixa-teia".into(),
8936 });
8937 let err = d.validate().unwrap_err();
8938 assert!(
8939 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8940 "got {err:?}",
8941 );
8942 }
8943
8944 #[test]
8945 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backslash() {
8946 // The trailing-`\` shape (`..\caixa-teia\` — the canonical
8947 // PowerShell tab-completion-on-a-directory append). Pinned
8948 // separately from the embedded-`\` shape so the gate's
8949 // contract is "any `\` anywhere", not "any `\` not at end".
8950 let d = dep_with_fonte(DepSource::Path {
8951 caminho: "..\\caixa-teia\\".into(),
8952 });
8953 let err = d.validate().unwrap_err();
8954 assert!(
8955 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8956 "got {err:?}",
8957 );
8958 }
8959
8960 #[test]
8961 fn validate_accepts_path_fonte_with_caminho_carrying_legitimate_forward_slash() {
8962 // The positive-control pin: the gate targets `\` only,
8963 // never `/`. The canonical relative POSIX path
8964 // (`../caixa-teia/foo/bar`) must continue to validate cleanly
8965 // so legitimate nested-directory deps aren't broken. Pinned
8966 // so the gate doesn't accidentally widen to a "no path
8967 // separators at all" sweep.
8968 let d = dep_with_fonte(DepSource::Path {
8969 caminho: "../caixa-teia/foo/bar".into(),
8970 });
8971 d.validate().unwrap();
8972 }
8973
8974 #[test]
8975 fn fonte_caminho_control_char_fires_before_backslash() {
8976 // Cascade pin: the control-char arm structurally precedes the
8977 // backslash arm. A value like `"..\caixa\0teia"` probes
8978 // positive on both (`\` byte + NUL byte), but the control-
8979 // char diagnostic wins so the author sees the more self-
8980 // locating POSIX-syscall-rejected-byte diagnostic first
8981 // (NUL outright breaks `CString::new` at every `std::fs`
8982 // syscall boundary; the `\` divergence is the cross-OS-
8983 // separator axis). Mirrors the
8984 // `fonte_caminho_var_fires_before_control_char` cascade
8985 // discipline on the immediate-predecessor arm.
8986 let d = dep_with_fonte(DepSource::Path {
8987 caminho: "..\\caixa\0teia".into(),
8988 });
8989 let err = d.validate().unwrap_err();
8990 assert!(
8991 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8992 "got {err:?}",
8993 );
8994 }
8995
8996 #[test]
8997 fn fonte_caminho_absolute_fires_before_backslash() {
8998 // Cascade pin on the load-bearing leading-byte arm: a leading
8999 // `/` value with embedded `\` (`/etc/passwd\foo`) routes
9000 // through `FonteCaminhoAbsolute` not `FonteCaminhoBackslash`
9001 // — the host-layout-leak diagnostic is the load-bearing
9002 // axis, the `\` byte is the secondary observation. Same
9003 // precedence logic as every prior leading-byte arm.
9004 let d = dep_with_fonte(DepSource::Path {
9005 caminho: "/etc/passwd\\foo".into(),
9006 });
9007 let err = d.validate().unwrap_err();
9008 assert!(
9009 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9010 "got {err:?}",
9011 );
9012 }
9013
9014 #[test]
9015 fn fonte_caminho_var_fires_before_backslash() {
9016 // Cascade pin on the var-expansion arm: a leading-`$` value
9017 // with embedded `\` (`$WORKSPACE\caixa-teia` — the canonical
9018 // PowerShell-env-var paste-from-CI-manifest footgun) routes
9019 // through `FonteCaminhoVarExpansion` not `FonteCaminhoBackslash`.
9020 // The shell-expansion diagnostic is the more self-locating
9021 // axis since both the leading `$` and the embedded `\`
9022 // are Windows-shell artifacts but the `$` is the root-cause
9023 // surface (an author who removes the `$` is likely to leave
9024 // the `\` too).
9025 let d = dep_with_fonte(DepSource::Path {
9026 caminho: "$WORKSPACE\\caixa-teia".into(),
9027 });
9028 let err = d.validate().unwrap_err();
9029 assert!(
9030 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
9031 "got {err:?}",
9032 );
9033 }
9034
9035 #[test]
9036 fn fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho() {
9037 // Diagnostic-shape pin (peer with the prior
9038 // `fonte_caminho_*_diagnostic_carries_*` payload assertions
9039 // on every preceding arm): the error's Display surfaces the
9040 // offending `:nome` and the offending `:caminho` verbatim
9041 // so a `feira lint` run can render the diagnostic without
9042 // re-parsing.
9043 let d = dep_with_fonte(DepSource::Path {
9044 caminho: "..\\caixa-teia".into(),
9045 });
9046 let rendered = d.validate().unwrap_err().to_string();
9047 assert!(
9048 rendered.contains("caixa-teia"),
9049 "diagnostic must name the offending dep: {rendered}",
9050 );
9051 assert!(
9052 rendered.contains("..\\caixa-teia"),
9053 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9054 );
9055 assert!(
9056 rendered.contains('\\'),
9057 "diagnostic must reference the backslash footgun: {rendered:?}",
9058 );
9059 }
9060
9061 #[test]
9062 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_slash() {
9063 // The fail-before-pass-after pin for the canonical trailing-`/`
9064 // paste footgun: an author who shell-tab-completes a sibling
9065 // directory (every interactive shell — bash/zsh/fish/nushell —
9066 // appends `/` on tab-completing a directory) produces
9067 // `"../caixa-teia/"`-shape values that silently passed every
9068 // prior arm (the leading byte is `.`, no control bytes, no
9069 // backslash). `Path::join` resolves both shapes to the same
9070 // directory at the resolver, but the lacre embeds the value
9071 // verbatim and the BLAKE3 closures diverge across two
9072 // workstations whose authors differ only in tab-completion
9073 // habits.
9074 let d = dep_with_fonte(DepSource::Path {
9075 caminho: "../caixa-teia/".into(),
9076 });
9077 let err = d.validate().unwrap_err();
9078 let DepError::FonteCaminhoTrailingSlash { nome, caminho } = err else {
9079 panic!("expected FonteCaminhoTrailingSlash, got {err:?}");
9080 };
9081 assert_eq!(nome, "caixa-teia");
9082 assert_eq!(caminho, "../caixa-teia/");
9083 }
9084
9085 #[test]
9086 fn validate_rejects_path_fonte_with_caminho_carrying_bare_dot_slash() {
9087 // The `"./"` shape (the canonical "I meant the caixa.lisp's own
9088 // directory and tab-completed it" footgun). Pinned separately
9089 // from the canonical `"../caixa-teia/"` shape so the gate's
9090 // contract is "any trailing `/`", not "trailing `/` after a leaf
9091 // name".
9092 let d = dep_with_fonte(DepSource::Path {
9093 caminho: "./".into(),
9094 });
9095 let err = d.validate().unwrap_err();
9096 assert!(
9097 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
9098 "got {err:?}",
9099 );
9100 }
9101
9102 #[test]
9103 fn validate_rejects_path_fonte_with_caminho_carrying_consecutive_trailing_slashes() {
9104 // The `"foo//"` shape (the canonical "I pasted from a CI manifest
9105 // that double-templated `${VAR}/` over an already-`/`-suffixed
9106 // path" footgun). The gate fires on the last byte being `/`
9107 // regardless of how many `/` precede it; the arm contract is
9108 // "the value ends with `/`", structurally.
9109 let d = dep_with_fonte(DepSource::Path {
9110 caminho: "../caixa-teia//".into(),
9111 });
9112 let err = d.validate().unwrap_err();
9113 assert!(
9114 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
9115 "got {err:?}",
9116 );
9117 }
9118
9119 #[test]
9120 fn validate_rejects_path_fonte_with_caminho_carrying_dotdot_trailing_slash() {
9121 // The `"../"` shape (the canonical "I want the parent" tab-
9122 // completion footgun on a bare `..` path). Pinned separately so
9123 // the gate doesn't accidentally narrow to "trailing `/` only on
9124 // multi-segment paths".
9125 let d = dep_with_fonte(DepSource::Path {
9126 caminho: "../".into(),
9127 });
9128 let err = d.validate().unwrap_err();
9129 assert!(
9130 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
9131 "got {err:?}",
9132 );
9133 }
9134
9135 #[test]
9136 fn validate_accepts_path_fonte_with_caminho_carrying_internal_slashes() {
9137 // The positive-control pin: the gate targets the trailing byte
9138 // only, never internal `/` separators. The canonical nested
9139 // relative POSIX path (`"../caixa-teia/foo/bar"`) must continue
9140 // to validate cleanly so legitimate deeply-nested deps aren't
9141 // broken. Pinned so the gate doesn't accidentally widen to a
9142 // "no `/` separators anywhere" sweep that would defeat the
9143 // entire path-fonte author surface.
9144 let d = dep_with_fonte(DepSource::Path {
9145 caminho: "../caixa-teia/foo/bar".into(),
9146 });
9147 d.validate().unwrap();
9148 }
9149
9150 #[test]
9151 fn validate_accepts_path_fonte_with_caminho_carrying_bare_dot() {
9152 // The positive-control pin on the degenerate single-`.` shape
9153 // (the canonical "the caixa.lisp's own directory" idiom). The
9154 // gate fires on the trailing byte being `/`, not on the path
9155 // being short, so `"."` (one byte, not `/`) must continue to
9156 // validate cleanly.
9157 let d = dep_with_fonte(DepSource::Path {
9158 caminho: ".".into(),
9159 });
9160 d.validate().unwrap();
9161 }
9162
9163 #[test]
9164 fn fonte_caminho_control_char_fires_before_trailing_slash() {
9165 // Cascade pin: the control-char arm structurally precedes the
9166 // trailing-slash arm. A value like `"../foo\n/"` ends in `/`
9167 // but the embedded LF (`0x0A`) is the load-bearing diagnostic
9168 // (control bytes are the paste-from-multiline-doc footgun the
9169 // d624c8d arm already closes). Mirrors the
9170 // `fonte_caminho_control_char_fires_before_backslash` cascade
9171 // discipline on the immediate-predecessor arm.
9172 let d = dep_with_fonte(DepSource::Path {
9173 caminho: "../foo\n/".into(),
9174 });
9175 let err = d.validate().unwrap_err();
9176 assert!(
9177 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9178 "got {err:?}",
9179 );
9180 }
9181
9182 #[test]
9183 fn fonte_caminho_backslash_fires_before_trailing_slash() {
9184 // Cascade pin on the backslash arm: a value like `"..\foo/"`
9185 // ends in `/` but the embedded `\` is the load-bearing
9186 // diagnostic (the cross-host-OS-separator divergence vector
9187 // the 3a4e1d7 arm closes). Same precedence logic as the prior
9188 // narrower-diagnostic-first cascade.
9189 let d = dep_with_fonte(DepSource::Path {
9190 caminho: "..\\caixa-teia/".into(),
9191 });
9192 let err = d.validate().unwrap_err();
9193 assert!(
9194 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9195 "got {err:?}",
9196 );
9197 }
9198
9199 #[test]
9200 fn fonte_caminho_absolute_fires_before_trailing_slash() {
9201 // Cascade pin on the load-bearing leading-byte arm: a leading
9202 // `/` value with a trailing `/` (`"/etc/passwd/"`) routes
9203 // through `FonteCaminhoAbsolute` not `FonteCaminhoTrailingSlash`
9204 // — the host-layout-leak diagnostic is the load-bearing axis,
9205 // the trailing `/` is the secondary observation. Same
9206 // precedence logic as every prior leading-byte arm.
9207 let d = dep_with_fonte(DepSource::Path {
9208 caminho: "/etc/passwd/".into(),
9209 });
9210 let err = d.validate().unwrap_err();
9211 assert!(
9212 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9213 "got {err:?}",
9214 );
9215 }
9216
9217 #[test]
9218 fn fonte_caminho_trailing_slash_diagnostic_carries_offending_dep_and_caminho() {
9219 // Diagnostic-shape pin (peer with the prior
9220 // `fonte_caminho_*_diagnostic_carries_*` payload assertions on
9221 // every preceding arm): the error's Display surfaces the
9222 // offending `:nome` and the offending `:caminho` verbatim so a
9223 // `feira lint` run can render the diagnostic without re-parsing.
9224 let d = dep_with_fonte(DepSource::Path {
9225 caminho: "../caixa-teia/".into(),
9226 });
9227 let rendered = d.validate().unwrap_err().to_string();
9228 assert!(
9229 rendered.contains("caixa-teia"),
9230 "diagnostic must name the offending dep: {rendered}",
9231 );
9232 assert!(
9233 rendered.contains("../caixa-teia/"),
9234 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9235 );
9236 assert!(
9237 rendered.contains("trailing"),
9238 "diagnostic must reference the trailing-slash footgun: {rendered:?}",
9239 );
9240 }
9241
9242 // -- :caminho shell-redirection metacharacter arm -----------------------
9243
9244 #[test]
9245 fn validate_rejects_path_fonte_with_caminho_carrying_gt_redirection() {
9246 // The fail-before-pass-after pin for the canonical output-redirection
9247 // paste footgun: an author copies a shell pipeline tail
9248 // (`"../caixa-teia>build.log"` — the canonical "I selected the whole
9249 // line including the `> build.log` redirect" idiom) and silently
9250 // passed every prior arm (`Path::is_absolute` false on `..`, no
9251 // control bytes, no backslash, doesn't end in `/`). The lacre
9252 // embedded the value verbatim, the resolver folded it through
9253 // `Path::join` looking for a literal `./../caixa-teia>build.log`
9254 // subdirectory, and the failure surfaced at resolve time with a
9255 // non-self-locating `No such file or directory` error. The new arm
9256 // moves the rejection to validate time and names the offending dep
9257 // + caminho + byte verbatim.
9258 let d = dep_with_fonte(DepSource::Path {
9259 caminho: "../caixa-teia>build.log".into(),
9260 });
9261 let err = d.validate().unwrap_err();
9262 let DepError::FonteCaminhoShellRedirection {
9263 nome,
9264 caminho,
9265 byte,
9266 } = err
9267 else {
9268 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
9269 };
9270 assert_eq!(nome, "caixa-teia");
9271 assert_eq!(caminho, "../caixa-teia>build.log");
9272 assert_eq!(byte, b'>');
9273 }
9274
9275 #[test]
9276 fn validate_rejects_path_fonte_with_caminho_carrying_lt_redirection() {
9277 // The symmetric input-redirection paste shape
9278 // (`"../caixa-teia<input.lisp"` — the canonical "I copied a
9279 // `command < input.lisp` line from a tatara-lisp REPL log"
9280 // idiom). Pinned separately from the `>` shape so the gate's
9281 // contract is "any `<` or `>` anywhere", not single-byte coverage.
9282 let d = dep_with_fonte(DepSource::Path {
9283 caminho: "../caixa-teia<input.lisp".into(),
9284 });
9285 let err = d.validate().unwrap_err();
9286 let DepError::FonteCaminhoShellRedirection { byte, .. } = err else {
9287 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
9288 };
9289 assert_eq!(byte, b'<');
9290 }
9291
9292 #[test]
9293 fn validate_rejects_path_fonte_with_caminho_carrying_leading_gt_redirection() {
9294 // Leading-position `>` shape (`">../caixa-teia"` — the degenerate
9295 // "I forgot the source side of the redirect" idiom). Pinned
9296 // separately from the embedded-byte shapes so the gate covers
9297 // every position, not only mid-path.
9298 let d = dep_with_fonte(DepSource::Path {
9299 caminho: ">../caixa-teia".into(),
9300 });
9301 let err = d.validate().unwrap_err();
9302 assert!(
9303 matches!(
9304 err,
9305 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9306 ),
9307 "got {err:?}",
9308 );
9309 }
9310
9311 #[test]
9312 fn validate_rejects_path_fonte_with_caminho_carrying_double_gt_append() {
9313 // The bash append-redirection shape (`"../caixa-teia>>build.log"` —
9314 // the canonical "I copied a `>>` append redirect" idiom). The arm
9315 // fires on the first `>` encountered; pinned so a future arm that
9316 // tries to distinguish `>` from `>>` doesn't break the broader
9317 // contract.
9318 let d = dep_with_fonte(DepSource::Path {
9319 caminho: "../caixa-teia>>build.log".into(),
9320 });
9321 let err = d.validate().unwrap_err();
9322 assert!(
9323 matches!(
9324 err,
9325 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9326 ),
9327 "got {err:?}",
9328 );
9329 }
9330
9331 #[test]
9332 fn validate_accepts_path_fonte_with_caminho_carrying_no_redirection() {
9333 // The positive-control pin: the gate targets only `<` / `>`,
9334 // never adjacent printable ASCII or POSIX-valid bytes. The
9335 // canonical relative POSIX path (`"../caixa-teia"`) and a
9336 // nested deeply-pathed variant (`"../caixa-teia/foo/bar"`) must
9337 // continue to validate cleanly so the gate doesn't widen to a
9338 // "no printable punctuation anywhere" sweep that would defeat
9339 // the entire path-fonte author surface.
9340 let d = dep_with_fonte(DepSource::Path {
9341 caminho: "../caixa-teia/foo/bar".into(),
9342 });
9343 d.validate().unwrap();
9344 }
9345
9346 #[test]
9347 fn fonte_caminho_backslash_fires_before_shell_redirection() {
9348 // Cascade pin on the immediate-predecessor arm: a value carrying
9349 // both `\` and `<` / `>` (`"..\caixa-teia>build.log"` — the
9350 // canonical "I pasted a Windows-shell command with output
9351 // redirect" footgun) routes through `FonteCaminhoBackslash` not
9352 // `FonteCaminhoShellRedirection`. The cross-host-OS-separator
9353 // divergence is the load-bearing axis (an author who removes
9354 // the `\` is the root-cause edit; the `>` falls away in the
9355 // same edit since it's downstream of the Windows-shell
9356 // convention).
9357 let d = dep_with_fonte(DepSource::Path {
9358 caminho: "..\\caixa-teia>build.log".into(),
9359 });
9360 let err = d.validate().unwrap_err();
9361 assert!(
9362 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9363 "got {err:?}",
9364 );
9365 }
9366
9367 #[test]
9368 fn fonte_caminho_control_char_fires_before_shell_redirection() {
9369 // Cascade pin on the embedded-control-byte arm: a value carrying
9370 // both a control byte and `<` / `>` (`"../foo\n>bar"` — the
9371 // canonical paste-from-multiline-doc footgun where a newline
9372 // landed mid-caminho) routes through `FonteCaminhoControlChar`
9373 // not `FonteCaminhoShellRedirection`. The POSIX-syscall-
9374 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
9375 // load-bearing axis on every value that probes positive for
9376 // both — mirrors the cascade discipline on every prior arm.
9377 let d = dep_with_fonte(DepSource::Path {
9378 caminho: "../foo\n>bar".into(),
9379 });
9380 let err = d.validate().unwrap_err();
9381 assert!(
9382 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9383 "got {err:?}",
9384 );
9385 }
9386
9387 #[test]
9388 fn fonte_caminho_absolute_fires_before_shell_redirection() {
9389 // Cascade pin on the load-bearing leading-byte arm: a leading
9390 // `/` value with embedded `<` / `>` (`"/etc/passwd>out"`)
9391 // routes through `FonteCaminhoAbsolute` not
9392 // `FonteCaminhoShellRedirection` — the host-layout-leak
9393 // diagnostic is the load-bearing axis, the `>` byte is the
9394 // secondary observation. Same precedence logic as every prior
9395 // leading-byte arm.
9396 let d = dep_with_fonte(DepSource::Path {
9397 caminho: "/etc/passwd>out".into(),
9398 });
9399 let err = d.validate().unwrap_err();
9400 assert!(
9401 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9402 "got {err:?}",
9403 );
9404 }
9405
9406 #[test]
9407 fn fonte_caminho_shell_redirection_fires_before_trailing_slash() {
9408 // Cascade pin on the immediate-successor arm: a value carrying
9409 // both `<` / `>` and a trailing `/` (`"../foo></"` — the
9410 // canonical "I tab-completed a path that already had a
9411 // redirect" footgun) routes through `FonteCaminhoShellRedirection`
9412 // not `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9413 // the more semantic-locating axis (an author who removes the
9414 // `<` / `>` typically also drops the trailing separator since
9415 // both are paste-from-shell artifacts).
9416 let d = dep_with_fonte(DepSource::Path {
9417 caminho: "../foo></".into(),
9418 });
9419 let err = d.validate().unwrap_err();
9420 assert!(
9421 matches!(
9422 err,
9423 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9424 ),
9425 "got {err:?}",
9426 );
9427 }
9428
9429 #[test]
9430 fn fonte_caminho_shell_redirection_diagnostic_carries_offending_dep_caminho_byte() {
9431 // Diagnostic-shape pin (peer with
9432 // `fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte`'s
9433 // payload assertion on the closest peer arm that also carries a
9434 // `byte` field): the error's Display surfaces the offending
9435 // `:nome`, the offending `:caminho` verbatim, and the offending
9436 // byte in hex (`0x3c` for `<`, `0x3e` for `>`) so a `feira lint`
9437 // run can render the diagnostic without re-parsing.
9438 let d = dep_with_fonte(DepSource::Path {
9439 caminho: "../caixa-teia>build.log".into(),
9440 });
9441 let rendered = d.validate().unwrap_err().to_string();
9442 assert!(
9443 rendered.contains("caixa-teia"),
9444 "diagnostic must name the offending dep: {rendered}",
9445 );
9446 assert!(
9447 rendered.contains("../caixa-teia>build.log"),
9448 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9449 );
9450 assert!(
9451 rendered.contains("0x3e"),
9452 "diagnostic must name the offending byte in hex: {rendered:?}",
9453 );
9454 assert!(
9455 rendered.contains("redirection"),
9456 "diagnostic must name the shell-redirection footgun: {rendered:?}",
9457 );
9458 }
9459
9460 // -- :caminho shell-pipe metacharacter arm ----------------------------
9461
9462 #[test]
9463 fn validate_rejects_path_fonte_with_caminho_carrying_pipe() {
9464 // The fail-before-pass-after pin for the canonical shell-pipe
9465 // paste footgun: an author copies a shell-history line
9466 // (`"../caixa-teia | grep foo"` — the canonical "I selected
9467 // the whole `ls dir | grep` line out of zsh history") and
9468 // silently passed every prior arm (`Path::is_absolute` false
9469 // on `..`, no control bytes, no backslash, no `<` / `>`,
9470 // doesn't end in `/`). The lacre embedded the value verbatim,
9471 // the resolver folded it through `Path::join` looking for a
9472 // literal `./../caixa-teia | grep foo` subdirectory, and the
9473 // failure surfaced at resolve time with a non-self-locating
9474 // `No such file or directory` error. The new arm moves the
9475 // rejection to validate time and names the offending dep +
9476 // caminho verbatim.
9477 let d = dep_with_fonte(DepSource::Path {
9478 caminho: "../caixa-teia | grep foo".into(),
9479 });
9480 let err = d.validate().unwrap_err();
9481 let DepError::FonteCaminhoShellPipe { nome, caminho } = err else {
9482 panic!("expected FonteCaminhoShellPipe, got {err:?}");
9483 };
9484 assert_eq!(nome, "caixa-teia");
9485 assert_eq!(caminho, "../caixa-teia | grep foo");
9486 }
9487
9488 #[test]
9489 fn validate_rejects_path_fonte_with_caminho_carrying_leading_pipe() {
9490 // Leading-position `|` shape (`"|../caixa-teia"` — the
9491 // degenerate "I forgot the source side of the pipe" idiom).
9492 // Pinned separately from the embedded-byte shape so the gate
9493 // covers every position, not only mid-path.
9494 let d = dep_with_fonte(DepSource::Path {
9495 caminho: "|../caixa-teia".into(),
9496 });
9497 let err = d.validate().unwrap_err();
9498 assert!(
9499 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9500 "got {err:?}",
9501 );
9502 }
9503
9504 #[test]
9505 fn validate_rejects_path_fonte_with_caminho_carrying_double_pipe_or() {
9506 // The bash short-circuit-OR shape (`"../caixa-teia||fallback"`
9507 // — the canonical "I copied a `cmd-a || cmd-b` fallback line"
9508 // idiom). The arm fires on the first `|` encountered; pinned
9509 // so a future arm that tries to distinguish `|` from `||`
9510 // doesn't break the broader contract.
9511 let d = dep_with_fonte(DepSource::Path {
9512 caminho: "../caixa-teia||fallback".into(),
9513 });
9514 let err = d.validate().unwrap_err();
9515 assert!(
9516 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9517 "got {err:?}",
9518 );
9519 }
9520
9521 #[test]
9522 fn validate_accepts_path_fonte_with_caminho_carrying_no_pipe() {
9523 // The positive-control pin: the gate targets only `|`, never
9524 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9525 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9526 // pathed variant with adjacent printable punctuation
9527 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9528 // cleanly so the gate doesn't widen to a "no printable
9529 // punctuation anywhere" sweep that would defeat the entire
9530 // path-fonte author surface.
9531 let d = dep_with_fonte(DepSource::Path {
9532 caminho: "../caixa-teia/sub-dir.v2".into(),
9533 });
9534 d.validate().unwrap();
9535 }
9536
9537 #[test]
9538 fn fonte_caminho_shell_redirection_fires_before_shell_pipe() {
9539 // Cascade pin on the immediate-predecessor arm: a value carrying
9540 // both `<` / `>` and `|` (`"../caixa-teia<input|tee"` — the
9541 // canonical "I pasted a `cmd < input | tee` pipeline tail"
9542 // footgun) routes through `FonteCaminhoShellRedirection` not
9543 // `FonteCaminhoShellPipe`. The input/output redirection
9544 // metachar carries the more self-locating `byte: u8` payload
9545 // (it names which of `<` or `>` triggered), so the prior arm
9546 // wins on every probe-as-both value — same cascade discipline
9547 // every prior `:caminho` arm establishes.
9548 let d = dep_with_fonte(DepSource::Path {
9549 caminho: "../caixa-teia<input|tee".into(),
9550 });
9551 let err = d.validate().unwrap_err();
9552 assert!(
9553 matches!(
9554 err,
9555 DepError::FonteCaminhoShellRedirection { byte: b'<', .. }
9556 ),
9557 "got {err:?}",
9558 );
9559 }
9560
9561 #[test]
9562 fn fonte_caminho_backslash_fires_before_shell_pipe() {
9563 // Cascade pin on the upstream backslash arm: a value carrying
9564 // both `\` and `|` (`"..\caixa-teia|tee"` — the canonical
9565 // "I pasted a Windows-shell command with pipe to tee"
9566 // footgun) routes through `FonteCaminhoBackslash` not
9567 // `FonteCaminhoShellPipe`. The cross-host-OS-separator
9568 // divergence is the load-bearing axis on every probe-as-both
9569 // value (an author who removes the `\` is the root-cause edit;
9570 // the `|` falls away in the same edit since it's downstream of
9571 // the Windows-shell convention).
9572 let d = dep_with_fonte(DepSource::Path {
9573 caminho: "..\\caixa-teia|tee".into(),
9574 });
9575 let err = d.validate().unwrap_err();
9576 assert!(
9577 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9578 "got {err:?}",
9579 );
9580 }
9581
9582 #[test]
9583 fn fonte_caminho_control_char_fires_before_shell_pipe() {
9584 // Cascade pin on the embedded-control-byte arm: a value
9585 // carrying both a control byte and `|` (`"../foo\n|bar"` —
9586 // the canonical paste-from-multiline-doc footgun where a
9587 // newline landed mid-caminho) routes through
9588 // `FonteCaminhoControlChar` not `FonteCaminhoShellPipe`. The
9589 // POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9590 // diagnostic is the load-bearing axis on every value that
9591 // probes positive for both — mirrors the cascade discipline
9592 // on every prior arm.
9593 let d = dep_with_fonte(DepSource::Path {
9594 caminho: "../foo\n|bar".into(),
9595 });
9596 let err = d.validate().unwrap_err();
9597 assert!(
9598 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9599 "got {err:?}",
9600 );
9601 }
9602
9603 #[test]
9604 fn fonte_caminho_absolute_fires_before_shell_pipe() {
9605 // Cascade pin on the load-bearing leading-byte arm: a leading
9606 // `/` value with embedded `|` (`"/etc/passwd|tee"`) routes
9607 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellPipe`
9608 // — the host-layout-leak diagnostic is the load-bearing axis,
9609 // the `|` byte is the secondary observation. Same precedence
9610 // logic as every prior leading-byte arm.
9611 let d = dep_with_fonte(DepSource::Path {
9612 caminho: "/etc/passwd|tee".into(),
9613 });
9614 let err = d.validate().unwrap_err();
9615 assert!(
9616 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9617 "got {err:?}",
9618 );
9619 }
9620
9621 #[test]
9622 fn fonte_caminho_shell_pipe_fires_before_trailing_slash() {
9623 // Cascade pin on the immediate-successor arm: a value carrying
9624 // both `|` and a trailing `/` (`"../foo|tee/"` — the canonical
9625 // "I tab-completed a path that already had a pipeline tail"
9626 // footgun) routes through `FonteCaminhoShellPipe` not
9627 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9628 // the more semantic-locating axis (an author who removes the
9629 // `|` typically also drops the trailing separator since both
9630 // are paste-from-shell artifacts).
9631 let d = dep_with_fonte(DepSource::Path {
9632 caminho: "../foo|tee/".into(),
9633 });
9634 let err = d.validate().unwrap_err();
9635 assert!(
9636 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9637 "got {err:?}",
9638 );
9639 }
9640
9641 #[test]
9642 fn fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho() {
9643 // Diagnostic-shape pin (peer with
9644 // `fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho`
9645 // on the closest single-byte peer arm): the error's Display
9646 // surfaces the offending `:nome` and the offending `:caminho`
9647 // verbatim, and names the shell-pipe footgun explicitly so a
9648 // `feira lint` run can render the diagnostic without
9649 // re-parsing.
9650 let d = dep_with_fonte(DepSource::Path {
9651 caminho: "../caixa-teia | grep foo".into(),
9652 });
9653 let rendered = d.validate().unwrap_err().to_string();
9654 assert!(
9655 rendered.contains("caixa-teia"),
9656 "diagnostic must name the offending dep: {rendered}",
9657 );
9658 assert!(
9659 rendered.contains("../caixa-teia | grep foo"),
9660 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9661 );
9662 assert!(
9663 rendered.contains('|'),
9664 "diagnostic must reference the pipe footgun: {rendered:?}",
9665 );
9666 assert!(
9667 rendered.contains("pipe"),
9668 "diagnostic must name the shell-pipe footgun: {rendered:?}",
9669 );
9670 }
9671
9672 // -- :caminho shell-command-separator metacharacter arm ---------------
9673
9674 #[test]
9675 fn validate_rejects_path_fonte_with_caminho_carrying_semicolon() {
9676 // The fail-before-pass-after pin for the canonical shell-command-
9677 // separator paste footgun: an author copies a shell one-liner
9678 // (`"../caixa-teia; rm -rf build"` — the canonical "I selected the
9679 // whole `cd path; do-thing` chain out of a shell-history block")
9680 // and silently passed every prior arm (`Path::is_absolute` false
9681 // on `..`, no control bytes, no backslash, no `<` / `>`, no `|`,
9682 // doesn't end in `/`). The lacre embedded the value verbatim, the
9683 // resolver folded it through `Path::join` looking for a literal
9684 // `./../caixa-teia; rm -rf build` subdirectory, and the failure
9685 // surfaced at resolve time with a non-self-locating `No such file
9686 // or directory` error. The new arm moves the rejection to validate
9687 // time and names the offending dep + caminho verbatim.
9688 let d = dep_with_fonte(DepSource::Path {
9689 caminho: "../caixa-teia; rm -rf build".into(),
9690 });
9691 let err = d.validate().unwrap_err();
9692 let DepError::FonteCaminhoShellSemicolon { nome, caminho } = err else {
9693 panic!("expected FonteCaminhoShellSemicolon, got {err:?}");
9694 };
9695 assert_eq!(nome, "caixa-teia");
9696 assert_eq!(caminho, "../caixa-teia; rm -rf build");
9697 }
9698
9699 #[test]
9700 fn validate_rejects_path_fonte_with_caminho_carrying_leading_semicolon() {
9701 // Leading-position `;` shape (`";../caixa-teia"` — the degenerate
9702 // "I forgot the prior command side of the separator" idiom).
9703 // Pinned separately from the embedded-byte shape so the gate
9704 // covers every position, not only mid-path.
9705 let d = dep_with_fonte(DepSource::Path {
9706 caminho: ";../caixa-teia".into(),
9707 });
9708 let err = d.validate().unwrap_err();
9709 assert!(
9710 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9711 "got {err:?}",
9712 );
9713 }
9714
9715 #[test]
9716 fn validate_rejects_path_fonte_with_caminho_carrying_double_semicolon() {
9717 // The POSIX `case` arm `;;` terminator shape
9718 // (`"../caixa-teia;;next"` — the canonical "I copied a `case`
9719 // arm tail" idiom). The arm fires on the first `;` encountered;
9720 // pinned so a future arm that tries to distinguish `;` from `;;`
9721 // doesn't break the broader contract.
9722 let d = dep_with_fonte(DepSource::Path {
9723 caminho: "../caixa-teia;;next".into(),
9724 });
9725 let err = d.validate().unwrap_err();
9726 assert!(
9727 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9728 "got {err:?}",
9729 );
9730 }
9731
9732 #[test]
9733 fn validate_accepts_path_fonte_with_caminho_carrying_no_semicolon() {
9734 // The positive-control pin: the gate targets only `;`, never
9735 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9736 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9737 // pathed variant with adjacent printable punctuation
9738 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9739 // cleanly so the gate doesn't widen to a "no printable
9740 // punctuation anywhere" sweep that would defeat the entire
9741 // path-fonte author surface.
9742 let d = dep_with_fonte(DepSource::Path {
9743 caminho: "../caixa-teia/sub-dir.v2".into(),
9744 });
9745 d.validate().unwrap();
9746 }
9747
9748 #[test]
9749 fn fonte_caminho_shell_pipe_fires_before_shell_semicolon() {
9750 // Cascade pin on the immediate-predecessor arm: a value carrying
9751 // both `|` and `;` (`"../caixa-teia | tee; rm"` — the canonical
9752 // "I pasted a `cmd | tee; cleanup` chain" footgun) routes through
9753 // `FonteCaminhoShellPipe` not `FonteCaminhoShellSemicolon`. The
9754 // pipeline-tail paste is the load-bearing root-cause edit on
9755 // every probe-as-both value (an author who removes the `|`
9756 // typically also drops the trailing `; cleanup` since both are
9757 // the same paste-from-shell-history artifact) — same cascade
9758 // discipline every prior `:caminho` arm establishes.
9759 let d = dep_with_fonte(DepSource::Path {
9760 caminho: "../caixa-teia | tee; rm".into(),
9761 });
9762 let err = d.validate().unwrap_err();
9763 assert!(
9764 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9765 "got {err:?}",
9766 );
9767 }
9768
9769 #[test]
9770 fn fonte_caminho_shell_redirection_fires_before_shell_semicolon() {
9771 // Cascade pin on the upstream shell-redirection arm: a value
9772 // carrying both `<` / `>` and `;` (`"../caixa-teia>log; rm"` —
9773 // the canonical "I pasted a `cmd > log; cleanup` chain"
9774 // footgun) routes through `FonteCaminhoShellRedirection` not
9775 // `FonteCaminhoShellSemicolon`. The input/output redirection
9776 // metachar carries the more self-locating `byte: u8` payload
9777 // (it names which of `<` or `>` triggered), so the prior arm
9778 // wins on every probe-as-both value.
9779 let d = dep_with_fonte(DepSource::Path {
9780 caminho: "../caixa-teia>log; rm".into(),
9781 });
9782 let err = d.validate().unwrap_err();
9783 assert!(
9784 matches!(
9785 err,
9786 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9787 ),
9788 "got {err:?}",
9789 );
9790 }
9791
9792 #[test]
9793 fn fonte_caminho_backslash_fires_before_shell_semicolon() {
9794 // Cascade pin on the upstream backslash arm: a value carrying
9795 // both `\` and `;` (`"..\caixa-teia;rm"` — the canonical "I
9796 // pasted a Windows-shell `cd ..\path; cleanup` chain") routes
9797 // through `FonteCaminhoBackslash` not `FonteCaminhoShellSemicolon`.
9798 // The cross-host-OS-separator divergence is the load-bearing axis
9799 // on every probe-as-both value (an author who removes the `\` is
9800 // the root-cause edit; the `;` falls away in the same edit since
9801 // it's downstream of the Windows-shell convention).
9802 let d = dep_with_fonte(DepSource::Path {
9803 caminho: "..\\caixa-teia;rm".into(),
9804 });
9805 let err = d.validate().unwrap_err();
9806 assert!(
9807 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9808 "got {err:?}",
9809 );
9810 }
9811
9812 #[test]
9813 fn fonte_caminho_control_char_fires_before_shell_semicolon() {
9814 // Cascade pin on the embedded-control-byte arm: a value carrying
9815 // both a control byte and `;` (`"../foo\n;bar"` — the canonical
9816 // paste-from-multiline-doc footgun where a newline landed mid-
9817 // caminho) routes through `FonteCaminhoControlChar` not
9818 // `FonteCaminhoShellSemicolon`. The POSIX-syscall-rejected-byte
9819 // / NUL-`CString::new`-fail diagnostic is the load-bearing axis
9820 // on every value that probes positive for both — mirrors the
9821 // cascade discipline on every prior arm.
9822 let d = dep_with_fonte(DepSource::Path {
9823 caminho: "../foo\n;bar".into(),
9824 });
9825 let err = d.validate().unwrap_err();
9826 assert!(
9827 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9828 "got {err:?}",
9829 );
9830 }
9831
9832 #[test]
9833 fn fonte_caminho_absolute_fires_before_shell_semicolon() {
9834 // Cascade pin on the load-bearing leading-byte arm: a leading
9835 // `/` value with embedded `;` (`"/etc/passwd;rm"`) routes
9836 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellSemicolon`
9837 // — the host-layout-leak diagnostic is the load-bearing axis,
9838 // the `;` byte is the secondary observation. Same precedence
9839 // logic as every prior leading-byte arm.
9840 let d = dep_with_fonte(DepSource::Path {
9841 caminho: "/etc/passwd;rm".into(),
9842 });
9843 let err = d.validate().unwrap_err();
9844 assert!(
9845 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9846 "got {err:?}",
9847 );
9848 }
9849
9850 #[test]
9851 fn fonte_caminho_shell_semicolon_fires_before_trailing_slash() {
9852 // Cascade pin on the immediate-successor arm: a value carrying
9853 // both `;` and a trailing `/` (`"../foo;rm/"` — the canonical
9854 // "I tab-completed a path that already had a `; cleanup` tail"
9855 // footgun) routes through `FonteCaminhoShellSemicolon` not
9856 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9857 // the more semantic-locating axis (an author who removes the
9858 // `;` typically also drops the trailing separator since both
9859 // are paste-from-shell artifacts).
9860 let d = dep_with_fonte(DepSource::Path {
9861 caminho: "../foo;rm/".into(),
9862 });
9863 let err = d.validate().unwrap_err();
9864 assert!(
9865 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9866 "got {err:?}",
9867 );
9868 }
9869
9870 #[test]
9871 fn fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho() {
9872 // Diagnostic-shape pin (peer with
9873 // `fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho`
9874 // on the closest single-byte peer arm): the error's Display
9875 // surfaces the offending `:nome` and the offending `:caminho`
9876 // verbatim, and names the shell-command-separator footgun
9877 // explicitly so a `feira lint` run can render the diagnostic
9878 // without re-parsing.
9879 let d = dep_with_fonte(DepSource::Path {
9880 caminho: "../caixa-teia; rm -rf build".into(),
9881 });
9882 let rendered = d.validate().unwrap_err().to_string();
9883 assert!(
9884 rendered.contains("caixa-teia"),
9885 "diagnostic must name the offending dep: {rendered}",
9886 );
9887 assert!(
9888 rendered.contains("../caixa-teia; rm -rf build"),
9889 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9890 );
9891 assert!(
9892 rendered.contains(';'),
9893 "diagnostic must reference the semicolon footgun: {rendered:?}",
9894 );
9895 assert!(
9896 rendered.contains("command-separator"),
9897 "diagnostic must name the shell-command-separator footgun: {rendered:?}",
9898 );
9899 }
9900
9901 #[test]
9902 fn validate_rejects_path_fonte_with_caminho_carrying_ampersand() {
9903 // The fail-before-pass-after pin for the canonical shell-
9904 // background-task paste footgun: an author copies a shell one-
9905 // liner (`"../caixa-teia & sleep 1"` — the canonical "I selected
9906 // the whole `cd path & sleep 1` background-launch out of a
9907 // shell-history block") and silently passed every prior arm
9908 // (`Path::is_absolute` false on `..`, no control bytes, no
9909 // backslash, no `<` / `>`, no `|`, no `;`, doesn't end in `/`).
9910 // The lacre embedded the value verbatim, the resolver folded it
9911 // through `Path::join` looking for a literal `./../caixa-teia &
9912 // sleep 1` subdirectory, and the failure surfaced at resolve
9913 // time with a non-self-locating `No such file or directory`
9914 // error. The new arm moves the rejection to validate time and
9915 // names the offending dep + caminho verbatim.
9916 let d = dep_with_fonte(DepSource::Path {
9917 caminho: "../caixa-teia & sleep 1".into(),
9918 });
9919 let err = d.validate().unwrap_err();
9920 let DepError::FonteCaminhoShellBackground { nome, caminho } = err else {
9921 panic!("expected FonteCaminhoShellBackground, got {err:?}");
9922 };
9923 assert_eq!(nome, "caixa-teia");
9924 assert_eq!(caminho, "../caixa-teia & sleep 1");
9925 }
9926
9927 #[test]
9928 fn validate_rejects_path_fonte_with_caminho_carrying_leading_ampersand() {
9929 // Leading-position `&` shape (`"&../caixa-teia"` — the
9930 // degenerate "I forgot the prior command side of the
9931 // background terminator" idiom). Pinned separately from the
9932 // embedded-byte shape so the gate covers every position, not
9933 // only mid-path.
9934 let d = dep_with_fonte(DepSource::Path {
9935 caminho: "&../caixa-teia".into(),
9936 });
9937 let err = d.validate().unwrap_err();
9938 assert!(
9939 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9940 "got {err:?}",
9941 );
9942 }
9943
9944 #[test]
9945 fn validate_rejects_path_fonte_with_caminho_carrying_double_ampersand() {
9946 // The logical-AND `&&` shape (`"../caixa-teia && make"` — the
9947 // canonical "I copied a `cd path && make` build chain" idiom
9948 // every Makefile / shell-script wraps). The arm fires on the
9949 // first `&` encountered; pinned so a future arm that tries to
9950 // distinguish `&` from `&&` doesn't break the broader contract.
9951 let d = dep_with_fonte(DepSource::Path {
9952 caminho: "../caixa-teia && make".into(),
9953 });
9954 let err = d.validate().unwrap_err();
9955 assert!(
9956 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9957 "got {err:?}",
9958 );
9959 }
9960
9961 #[test]
9962 fn validate_accepts_path_fonte_with_caminho_carrying_no_ampersand() {
9963 // The positive-control pin: the gate targets only `&`, never
9964 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9965 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9966 // pathed variant with adjacent printable punctuation
9967 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9968 // cleanly so the gate doesn't widen to a "no printable
9969 // punctuation anywhere" sweep that would defeat the entire
9970 // path-fonte author surface.
9971 let d = dep_with_fonte(DepSource::Path {
9972 caminho: "../caixa-teia/sub-dir.v2".into(),
9973 });
9974 d.validate().unwrap();
9975 }
9976
9977 #[test]
9978 fn fonte_caminho_shell_semicolon_fires_before_shell_background() {
9979 // Cascade pin on the immediate-predecessor arm: a value carrying
9980 // both `;` and `&` (`"../caixa-teia; rm & sleep"` — the
9981 // canonical "I pasted a `cmd; cleanup & sleep` chain" footgun)
9982 // routes through `FonteCaminhoShellSemicolon` not
9983 // `FonteCaminhoShellBackground`. The sequential-command-
9984 // separator paste is the more common shell-history paste idiom
9985 // on every probe-as-both value (an author who removes the `;`
9986 // typically also drops the trailing `& sleep` since both are
9987 // paste-from-shell-history artifacts) — same cascade discipline
9988 // every prior `:caminho` arm establishes.
9989 let d = dep_with_fonte(DepSource::Path {
9990 caminho: "../caixa-teia; rm & sleep".into(),
9991 });
9992 let err = d.validate().unwrap_err();
9993 assert!(
9994 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9995 "got {err:?}",
9996 );
9997 }
9998
9999 #[test]
10000 fn fonte_caminho_shell_pipe_fires_before_shell_background() {
10001 // Cascade pin on the upstream shell-pipe arm: a value carrying
10002 // both `|` and `&` (`"../caixa-teia | tee & sleep"` — the
10003 // canonical "I pasted a `cmd | tee & sleep` background-pipeline
10004 // chain" footgun) routes through `FonteCaminhoShellPipe` not
10005 // `FonteCaminhoShellBackground`. The pipeline-tail paste is the
10006 // load-bearing root-cause edit on every probe-as-both value.
10007 let d = dep_with_fonte(DepSource::Path {
10008 caminho: "../caixa-teia | tee & sleep".into(),
10009 });
10010 let err = d.validate().unwrap_err();
10011 assert!(
10012 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10013 "got {err:?}",
10014 );
10015 }
10016
10017 #[test]
10018 fn fonte_caminho_shell_redirection_fires_before_shell_background() {
10019 // Cascade pin on the upstream shell-redirection arm: a value
10020 // carrying both `>` and `&` (`"../caixa-teia>log & sleep"` —
10021 // the canonical "I pasted a `cmd > log & sleep` background-
10022 // redirect chain" footgun) routes through
10023 // `FonteCaminhoShellRedirection` not
10024 // `FonteCaminhoShellBackground`. The input/output redirection
10025 // metachar carries the more self-locating `byte: u8` payload
10026 // (it names which of `<` or `>` triggered), so the prior arm
10027 // wins on every probe-as-both value.
10028 let d = dep_with_fonte(DepSource::Path {
10029 caminho: "../caixa-teia>log & sleep".into(),
10030 });
10031 let err = d.validate().unwrap_err();
10032 assert!(
10033 matches!(
10034 err,
10035 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10036 ),
10037 "got {err:?}",
10038 );
10039 }
10040
10041 #[test]
10042 fn fonte_caminho_backslash_fires_before_shell_background() {
10043 // Cascade pin on the upstream backslash arm: a value carrying
10044 // both `\` and `&` (`"..\caixa-teia & sleep"` — the canonical
10045 // "I pasted a Windows-shell `cd ..\path & sleep` background-
10046 // launch chain") routes through `FonteCaminhoBackslash` not
10047 // `FonteCaminhoShellBackground`. The cross-host-OS-separator
10048 // divergence is the load-bearing axis on every probe-as-both
10049 // value (an author who removes the `\` is the root-cause edit;
10050 // the `&` falls away in the same edit since it's downstream of
10051 // the Windows-shell convention).
10052 let d = dep_with_fonte(DepSource::Path {
10053 caminho: "..\\caixa-teia & sleep".into(),
10054 });
10055 let err = d.validate().unwrap_err();
10056 assert!(
10057 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10058 "got {err:?}",
10059 );
10060 }
10061
10062 #[test]
10063 fn fonte_caminho_control_char_fires_before_shell_background() {
10064 // Cascade pin on the embedded-control-byte arm: a value
10065 // carrying both a control byte and `&` (`"../foo\n&sleep"` —
10066 // the canonical paste-from-multiline-doc footgun where a
10067 // newline landed mid-caminho) routes through
10068 // `FonteCaminhoControlChar` not `FonteCaminhoShellBackground`.
10069 // The POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
10070 // diagnostic is the load-bearing axis on every value that
10071 // probes positive for both — mirrors the cascade discipline on
10072 // every prior arm.
10073 let d = dep_with_fonte(DepSource::Path {
10074 caminho: "../foo\n&sleep".into(),
10075 });
10076 let err = d.validate().unwrap_err();
10077 assert!(
10078 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10079 "got {err:?}",
10080 );
10081 }
10082
10083 #[test]
10084 fn fonte_caminho_absolute_fires_before_shell_background() {
10085 // Cascade pin on the load-bearing leading-byte arm: a leading
10086 // `/` value with embedded `&` (`"/etc/passwd & sleep"`) routes
10087 // through `FonteCaminhoAbsolute` not
10088 // `FonteCaminhoShellBackground` — the host-layout-leak
10089 // diagnostic is the load-bearing axis, the `&` byte is the
10090 // secondary observation. Same precedence logic as every prior
10091 // leading-byte arm.
10092 let d = dep_with_fonte(DepSource::Path {
10093 caminho: "/etc/passwd & sleep".into(),
10094 });
10095 let err = d.validate().unwrap_err();
10096 assert!(
10097 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10098 "got {err:?}",
10099 );
10100 }
10101
10102 #[test]
10103 fn fonte_caminho_shell_background_fires_before_trailing_slash() {
10104 // Cascade pin on the immediate-successor arm: a value carrying
10105 // both `&` and a trailing `/` (`"../foo&sleep/"` — the
10106 // canonical "I tab-completed a path that already had a `&
10107 // sleep` background-launch tail" footgun) routes through
10108 // `FonteCaminhoShellBackground` not `FonteCaminhoTrailingSlash`.
10109 // The embedded shell-metachar is the more semantic-locating
10110 // axis (an author who removes the `&` typically also drops
10111 // the trailing separator since both are paste-from-shell
10112 // artifacts).
10113 let d = dep_with_fonte(DepSource::Path {
10114 caminho: "../foo&sleep/".into(),
10115 });
10116 let err = d.validate().unwrap_err();
10117 assert!(
10118 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10119 "got {err:?}",
10120 );
10121 }
10122
10123 #[test]
10124 fn fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho() {
10125 // Diagnostic-shape pin (peer with
10126 // `fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho`
10127 // on the closest single-byte peer arm): the error's Display
10128 // surfaces the offending `:nome` and the offending `:caminho`
10129 // verbatim, and names the shell-background / logical-AND
10130 // footgun explicitly so a `feira lint` run can render the
10131 // diagnostic without re-parsing.
10132 let d = dep_with_fonte(DepSource::Path {
10133 caminho: "../caixa-teia & sleep 1".into(),
10134 });
10135 let rendered = d.validate().unwrap_err().to_string();
10136 assert!(
10137 rendered.contains("caixa-teia"),
10138 "diagnostic must name the offending dep: {rendered}",
10139 );
10140 assert!(
10141 rendered.contains("../caixa-teia & sleep 1"),
10142 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10143 );
10144 assert!(
10145 rendered.contains('&'),
10146 "diagnostic must reference the ampersand footgun: {rendered:?}",
10147 );
10148 assert!(
10149 rendered.contains("background") || rendered.contains("list-AND"),
10150 "diagnostic must name the shell-background / logical-AND footgun: {rendered:?}",
10151 );
10152 }
10153
10154 #[test]
10155 fn validate_rejects_path_fonte_with_caminho_carrying_backtick() {
10156 // The fail-before-pass-after pin for the canonical shell-
10157 // command-substitution paste footgun: an author copies a
10158 // POSIX legacy backticked one-liner (`"../caixa-teia/`whoami`"`
10159 // — the canonical "I pasted a path that included a `pwd`
10160 // / `whoami` / `date` legacy command-substitution expansion
10161 // out of a shell-history block") and silently passed every
10162 // prior arm (`Path::is_absolute` false on `..`, no control
10163 // bytes, no `\`, no `<` / `>`, no `|`, no `;`, no `&`, doesn't
10164 // end in `/`). The lacre embedded the value verbatim, the
10165 // resolver folded it through `Path::join` looking for a
10166 // literal `./../caixa-teia/`whoami`` subdirectory, and the
10167 // failure surfaced at resolve time with a non-self-locating
10168 // `No such file or directory` error. The new arm moves the
10169 // rejection to validate time and names the offending dep +
10170 // caminho verbatim.
10171 let d = dep_with_fonte(DepSource::Path {
10172 caminho: "../caixa-teia/`whoami`".into(),
10173 });
10174 let err = d.validate().unwrap_err();
10175 let DepError::FonteCaminhoShellCommandSubstitution { nome, caminho } = err else {
10176 panic!("expected FonteCaminhoShellCommandSubstitution, got {err:?}");
10177 };
10178 assert_eq!(nome, "caixa-teia");
10179 assert_eq!(caminho, "../caixa-teia/`whoami`");
10180 }
10181
10182 #[test]
10183 fn validate_rejects_path_fonte_with_caminho_carrying_leading_backtick() {
10184 // Leading-position backtick shape (``"`pwd`/caixa-teia"`` —
10185 // the canonical `<backtick>pwd<backtick>/path` working-
10186 // directory expansion shape every shell-side path-composition
10187 // idiom carries). Pinned separately from the embedded-byte
10188 // shape so the gate covers every position, not only mid-path.
10189 let d = dep_with_fonte(DepSource::Path {
10190 caminho: "`pwd`/caixa-teia".into(),
10191 });
10192 let err = d.validate().unwrap_err();
10193 assert!(
10194 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10195 "got {err:?}",
10196 );
10197 }
10198
10199 #[test]
10200 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backtick() {
10201 // Trailing-position backtick shape (`"../caixa-teia`"` — the
10202 // degenerate "I selected an unbalanced backtick out of a
10203 // shell-history block" idiom that probes for the cascade's
10204 // last-byte handling). The trailing-`/` arm fires only on
10205 // last-byte `/`; an unbalanced trailing backtick must route
10206 // through this arm regardless of position.
10207 let d = dep_with_fonte(DepSource::Path {
10208 caminho: "../caixa-teia`".into(),
10209 });
10210 let err = d.validate().unwrap_err();
10211 assert!(
10212 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10213 "got {err:?}",
10214 );
10215 }
10216
10217 #[test]
10218 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_backtick_pair() {
10219 // The canonical balanced-pair shape (``"../<backtick>cat
10220 // /etc/passwd<backtick>"`` — the canonical CWE-78 shell-
10221 // command-injection paste idiom every shell-side hardening
10222 // guide enumerates first). The arm fires on the first
10223 // backtick encountered; pinned so a future arm that tries to
10224 // distinguish the opening from the closing byte doesn't break
10225 // the broader contract.
10226 let d = dep_with_fonte(DepSource::Path {
10227 caminho: "../`cat /etc/passwd`".into(),
10228 });
10229 let err = d.validate().unwrap_err();
10230 assert!(
10231 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10232 "got {err:?}",
10233 );
10234 }
10235
10236 #[test]
10237 fn validate_accepts_path_fonte_with_caminho_carrying_no_backtick() {
10238 // The positive-control pin: the gate targets only the
10239 // backtick byte, never adjacent printable ASCII or POSIX-
10240 // valid bytes. The canonical relative POSIX path
10241 // (`"../caixa-teia"`) and a nested deeply-pathed variant with
10242 // adjacent printable punctuation
10243 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
10244 // cleanly so the gate doesn't widen to a "no printable
10245 // punctuation anywhere" sweep that would defeat the entire
10246 // path-fonte author surface.
10247 let d = dep_with_fonte(DepSource::Path {
10248 caminho: "../caixa-teia/sub-dir.v2".into(),
10249 });
10250 d.validate().unwrap();
10251 }
10252
10253 #[test]
10254 fn fonte_caminho_shell_background_fires_before_shell_command_substitution() {
10255 // Cascade pin on the immediate-predecessor arm: a value
10256 // carrying both `&` and a backtick (``"../caixa-teia &
10257 // <backtick>sleep 1<backtick>"`` — the canonical "I pasted a
10258 // `cmd & <backtick>sleep N<backtick>` background-launch +
10259 // command-substitution chain" footgun) routes through
10260 // `FonteCaminhoShellBackground` not
10261 // `FonteCaminhoShellCommandSubstitution`. The background-
10262 // launch tail is the more common shell-history paste idiom
10263 // on every probe-as-both value — same cascade discipline
10264 // every prior `:caminho` arm establishes.
10265 let d = dep_with_fonte(DepSource::Path {
10266 caminho: "../caixa-teia & `sleep 1`".into(),
10267 });
10268 let err = d.validate().unwrap_err();
10269 assert!(
10270 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10271 "got {err:?}",
10272 );
10273 }
10274
10275 #[test]
10276 fn fonte_caminho_shell_semicolon_fires_before_shell_command_substitution() {
10277 // Cascade pin on the upstream shell-semicolon arm: a value
10278 // carrying both `;` and a backtick (``"../caixa-teia;
10279 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
10280 // `cmd; <backtick>follow-up<backtick>` sequential-chain
10281 // footgun) routes through `FonteCaminhoShellSemicolon` not
10282 // `FonteCaminhoShellCommandSubstitution`. The sequential-
10283 // command-separator paste is the load-bearing root-cause
10284 // edit on every probe-as-both value.
10285 let d = dep_with_fonte(DepSource::Path {
10286 caminho: "../caixa-teia; `whoami`".into(),
10287 });
10288 let err = d.validate().unwrap_err();
10289 assert!(
10290 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10291 "got {err:?}",
10292 );
10293 }
10294
10295 #[test]
10296 fn fonte_caminho_shell_pipe_fires_before_shell_command_substitution() {
10297 // Cascade pin on the upstream shell-pipe arm: a value
10298 // carrying both `|` and a backtick (``"../caixa-teia |
10299 // <backtick>tee log<backtick>"`` — the canonical pipeline-to-
10300 // command-substitution paste idiom) routes through
10301 // `FonteCaminhoShellPipe` not
10302 // `FonteCaminhoShellCommandSubstitution`. The pipeline-tail
10303 // paste is the load-bearing root-cause edit on every
10304 // probe-as-both value.
10305 let d = dep_with_fonte(DepSource::Path {
10306 caminho: "../caixa-teia | `tee log`".into(),
10307 });
10308 let err = d.validate().unwrap_err();
10309 assert!(
10310 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10311 "got {err:?}",
10312 );
10313 }
10314
10315 #[test]
10316 fn fonte_caminho_shell_redirection_fires_before_shell_command_substitution() {
10317 // Cascade pin on the upstream shell-redirection arm: a value
10318 // carrying both `>` and a backtick (``"../caixa-teia>log
10319 // <backtick>date<backtick>"`` — the canonical "I pasted a
10320 // `cmd > log <backtick>date<backtick>` redirect-plus-
10321 // substitution chain" footgun) routes through
10322 // `FonteCaminhoShellRedirection` not
10323 // `FonteCaminhoShellCommandSubstitution`. The input/output
10324 // redirection metachar carries the more self-locating `byte`
10325 // payload (it names which of `<` or `>` triggered), so the
10326 // prior arm wins on every probe-as-both value.
10327 let d = dep_with_fonte(DepSource::Path {
10328 caminho: "../caixa-teia>log `date`".into(),
10329 });
10330 let err = d.validate().unwrap_err();
10331 assert!(
10332 matches!(
10333 err,
10334 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10335 ),
10336 "got {err:?}",
10337 );
10338 }
10339
10340 #[test]
10341 fn fonte_caminho_backslash_fires_before_shell_command_substitution() {
10342 // Cascade pin on the upstream backslash arm: a value
10343 // carrying both `\` and a backtick (``"..\caixa-teia
10344 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
10345 // Windows-shell `cd ..\path <backtick>whoami<backtick>`
10346 // chain") routes through `FonteCaminhoBackslash` not
10347 // `FonteCaminhoShellCommandSubstitution`. The cross-host-OS-
10348 // separator divergence is the load-bearing axis on every
10349 // probe-as-both value (an author who removes the `\` is the
10350 // root-cause edit; the backtick falls away in the same edit
10351 // since it's downstream of the Windows-shell convention).
10352 let d = dep_with_fonte(DepSource::Path {
10353 caminho: "..\\caixa-teia `whoami`".into(),
10354 });
10355 let err = d.validate().unwrap_err();
10356 assert!(
10357 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10358 "got {err:?}",
10359 );
10360 }
10361
10362 #[test]
10363 fn fonte_caminho_control_char_fires_before_shell_command_substitution() {
10364 // Cascade pin on the embedded-control-byte arm: a value
10365 // carrying both a control byte and a backtick (`"../foo\n
10366 // `whoami`"` — the canonical paste-from-multiline-doc
10367 // footgun where a newline landed mid-caminho between two
10368 // paste fragments) routes through `FonteCaminhoControlChar`
10369 // not `FonteCaminhoShellCommandSubstitution`. The POSIX-
10370 // syscall-rejected-byte / NUL-`CString::new`-fail diagnostic
10371 // is the load-bearing axis on every value that probes
10372 // positive for both — mirrors the cascade discipline on
10373 // every prior arm.
10374 let d = dep_with_fonte(DepSource::Path {
10375 caminho: "../foo\n`whoami`".into(),
10376 });
10377 let err = d.validate().unwrap_err();
10378 assert!(
10379 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10380 "got {err:?}",
10381 );
10382 }
10383
10384 #[test]
10385 fn fonte_caminho_absolute_fires_before_shell_command_substitution() {
10386 // Cascade pin on the load-bearing leading-byte arm: a
10387 // leading `/` value with embedded backtick (``"/etc/passwd
10388 // <backtick>whoami<backtick>"``) routes through
10389 // `FonteCaminhoAbsolute` not
10390 // `FonteCaminhoShellCommandSubstitution` — the host-layout-
10391 // leak diagnostic is the load-bearing axis, the backtick
10392 // byte is the secondary observation. Same precedence logic
10393 // as every prior leading-byte arm.
10394 let d = dep_with_fonte(DepSource::Path {
10395 caminho: "/etc/passwd `whoami`".into(),
10396 });
10397 let err = d.validate().unwrap_err();
10398 assert!(
10399 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10400 "got {err:?}",
10401 );
10402 }
10403
10404 #[test]
10405 fn fonte_caminho_shell_command_substitution_fires_before_trailing_slash() {
10406 // Cascade pin on the immediate-successor arm: a value
10407 // carrying both a backtick and a trailing `/`
10408 // (``"../`whoami`/"`` — the canonical "I tab-completed a
10409 // path that already had a backticked `whoami` substitution
10410 // tail" footgun) routes through
10411 // `FonteCaminhoShellCommandSubstitution` not
10412 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
10413 // is the more semantic-locating axis (an author who removes
10414 // the backtick typically also drops the trailing separator
10415 // since both are paste-from-shell artifacts).
10416 let d = dep_with_fonte(DepSource::Path {
10417 caminho: "../`whoami`/".into(),
10418 });
10419 let err = d.validate().unwrap_err();
10420 assert!(
10421 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10422 "got {err:?}",
10423 );
10424 }
10425
10426 #[test]
10427 fn fonte_caminho_shell_command_substitution_diagnostic_carries_offending_dep_and_caminho() {
10428 // Diagnostic-shape pin (peer with
10429 // `fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho`
10430 // on the closest single-byte peer arm): the error's Display
10431 // surfaces the offending `:nome` and the offending `:caminho`
10432 // verbatim, and names the shell-command-substitution footgun
10433 // explicitly so a `feira lint` run can render the diagnostic
10434 // without re-parsing.
10435 let d = dep_with_fonte(DepSource::Path {
10436 caminho: "../caixa-teia/`whoami`".into(),
10437 });
10438 let rendered = d.validate().unwrap_err().to_string();
10439 assert!(
10440 rendered.contains("caixa-teia"),
10441 "diagnostic must name the offending dep: {rendered}",
10442 );
10443 assert!(
10444 rendered.contains("../caixa-teia/`whoami`"),
10445 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10446 );
10447 assert!(
10448 rendered.contains('`'),
10449 "diagnostic must reference the backtick footgun: {rendered:?}",
10450 );
10451 assert!(
10452 rendered.contains("command-substitution"),
10453 "diagnostic must name the shell-command-substitution footgun: {rendered:?}",
10454 );
10455 }
10456
10457 #[test]
10458 fn validate_rejects_path_fonte_with_caminho_carrying_star_glob() {
10459 // The fail-before-pass-after pin for the canonical pathname-
10460 // expansion paste footgun: an author copies an `ls
10461 // ../caixa-teia/*` shell-listing tail into the `:caminho`
10462 // slot and silently passes every prior arm
10463 // (`Path::is_absolute` false on `..`, no control bytes, no
10464 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick,
10465 // doesn't end in `/`). The lacre embedded the value
10466 // verbatim, the resolver folded it through `Path::join`
10467 // looking for a literal `./../caixa-teia/*` subdirectory,
10468 // and the failure surfaced at resolve time with a non-self-
10469 // locating `No such file or directory` error. The new arm
10470 // moves the rejection to validate time and names the
10471 // offending dep + caminho + byte verbatim.
10472 let d = dep_with_fonte(DepSource::Path {
10473 caminho: "../caixa-teia/*".into(),
10474 });
10475 let err = d.validate().unwrap_err();
10476 let DepError::FonteCaminhoShellGlob {
10477 nome,
10478 caminho,
10479 byte,
10480 } = err
10481 else {
10482 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10483 };
10484 assert_eq!(nome, "caixa-teia");
10485 assert_eq!(caminho, "../caixa-teia/*");
10486 assert_eq!(byte, b'*');
10487 }
10488
10489 #[test]
10490 fn validate_rejects_path_fonte_with_caminho_carrying_question_glob() {
10491 // The symmetric single-char-wildcard paste shape
10492 // (`"../foo?"` — the canonical "I copied a `rm foo?` line
10493 // out of shell history" idiom). Pinned separately from the
10494 // `*` shape so the gate's contract is "any `*` or `?`
10495 // anywhere", not single-byte coverage.
10496 let d = dep_with_fonte(DepSource::Path {
10497 caminho: "../foo?".into(),
10498 });
10499 let err = d.validate().unwrap_err();
10500 let DepError::FonteCaminhoShellGlob { byte, .. } = err else {
10501 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10502 };
10503 assert_eq!(byte, b'?');
10504 }
10505
10506 #[test]
10507 fn validate_rejects_path_fonte_with_caminho_carrying_leading_star_glob() {
10508 // Leading-position `*` shape (`"*/caixa-teia"` — the
10509 // degenerate "I selected only the wildcard prefix out of a
10510 // shell-glob expression" idiom). Pinned separately from the
10511 // embedded-byte shapes so the gate covers every position,
10512 // not only mid-path.
10513 let d = dep_with_fonte(DepSource::Path {
10514 caminho: "*/caixa-teia".into(),
10515 });
10516 let err = d.validate().unwrap_err();
10517 assert!(
10518 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10519 "got {err:?}",
10520 );
10521 }
10522
10523 #[test]
10524 fn validate_rejects_path_fonte_with_caminho_carrying_double_star_recursive_glob() {
10525 // The bash/zsh `globstar` recursive-glob shape
10526 // (`"../caixa-teia/**/foo"` — the canonical "I copied a
10527 // `find ../caixa-teia/**/foo` recursive expansion" idiom).
10528 // The arm fires on the first `*` encountered; pinned so a
10529 // future arm that tries to distinguish single `*` from
10530 // double `**` doesn't break the broader contract.
10531 let d = dep_with_fonte(DepSource::Path {
10532 caminho: "../caixa-teia/**/foo".into(),
10533 });
10534 let err = d.validate().unwrap_err();
10535 assert!(
10536 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10537 "got {err:?}",
10538 );
10539 }
10540
10541 #[test]
10542 fn validate_rejects_path_fonte_with_caminho_carrying_dotted_extension_glob() {
10543 // The canonical extension-glob shape (`"../caixa-teia/*.lisp"`
10544 // — the "I selected `*.lisp` to mean every Lisp source file
10545 // in the dep root" footgun the prior arms structurally
10546 // cannot catch since `.` is a POSIX-valid path-component
10547 // byte). Pinned so the gate's contract covers the most
10548 // idiomatic glob-paste shape every author meets first.
10549 let d = dep_with_fonte(DepSource::Path {
10550 caminho: "../caixa-teia/*.lisp".into(),
10551 });
10552 let err = d.validate().unwrap_err();
10553 assert!(
10554 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10555 "got {err:?}",
10556 );
10557 }
10558
10559 #[test]
10560 fn validate_accepts_path_fonte_with_caminho_carrying_no_glob() {
10561 // The positive-control pin: the gate targets only `*` /
10562 // `?`, never adjacent printable ASCII or POSIX-valid bytes.
10563 // The canonical relative POSIX path (`"../caixa-teia"`) and
10564 // a nested deeply-pathed variant with adjacent printable
10565 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
10566 // to validate cleanly so the gate doesn't widen to a "no
10567 // printable punctuation anywhere" sweep that would defeat
10568 // the entire path-fonte author surface.
10569 let d = dep_with_fonte(DepSource::Path {
10570 caminho: "../caixa-teia/sub-dir.v2".into(),
10571 });
10572 d.validate().unwrap();
10573 }
10574
10575 #[test]
10576 fn fonte_caminho_shell_command_substitution_fires_before_shell_glob() {
10577 // Cascade pin on the immediate-predecessor arm: a value
10578 // carrying both a backtick and `*` (``"../`whoami`/*"`` —
10579 // the canonical "I pasted a `cd <backtick>whoami<backtick>/*`
10580 // command-substitution + glob chain") routes through
10581 // `FonteCaminhoShellCommandSubstitution` not
10582 // `FonteCaminhoShellGlob`. The CWE-78 shell-command-
10583 // injection vector is the load-bearing root-cause edit on
10584 // every probe-as-both value — same cascade discipline every
10585 // prior `:caminho` arm establishes.
10586 let d = dep_with_fonte(DepSource::Path {
10587 caminho: "../`whoami`/*".into(),
10588 });
10589 let err = d.validate().unwrap_err();
10590 assert!(
10591 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10592 "got {err:?}",
10593 );
10594 }
10595
10596 #[test]
10597 fn fonte_caminho_shell_background_fires_before_shell_glob() {
10598 // Cascade pin on the upstream shell-background arm: a value
10599 // carrying both `&` and `*` (`"../caixa-teia & ls /*"` — the
10600 // canonical "I pasted a `cmd & ls /*` background + glob
10601 // chain" footgun) routes through `FonteCaminhoShellBackground`
10602 // not `FonteCaminhoShellGlob`. The background-launch tail is
10603 // the load-bearing root-cause edit on every probe-as-both
10604 // value.
10605 let d = dep_with_fonte(DepSource::Path {
10606 caminho: "../caixa-teia & ls /*".into(),
10607 });
10608 let err = d.validate().unwrap_err();
10609 assert!(
10610 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10611 "got {err:?}",
10612 );
10613 }
10614
10615 #[test]
10616 fn fonte_caminho_shell_semicolon_fires_before_shell_glob() {
10617 // Cascade pin on the upstream shell-semicolon arm: a value
10618 // carrying both `;` and `*` (`"../caixa-teia; rm *"` — the
10619 // canonical sequential-cleanup + glob paste idiom) routes
10620 // through `FonteCaminhoShellSemicolon` not
10621 // `FonteCaminhoShellGlob`. The sequential-command-separator
10622 // paste is the load-bearing root-cause edit on every
10623 // probe-as-both value.
10624 let d = dep_with_fonte(DepSource::Path {
10625 caminho: "../caixa-teia; rm *".into(),
10626 });
10627 let err = d.validate().unwrap_err();
10628 assert!(
10629 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10630 "got {err:?}",
10631 );
10632 }
10633
10634 #[test]
10635 fn fonte_caminho_shell_pipe_fires_before_shell_glob() {
10636 // Cascade pin on the upstream shell-pipe arm: a value
10637 // carrying both `|` and `*` (`"../caixa-teia | ls *"` — the
10638 // canonical pipeline-to-glob paste idiom) routes through
10639 // `FonteCaminhoShellPipe` not `FonteCaminhoShellGlob`. The
10640 // pipeline-tail paste is the load-bearing root-cause edit
10641 // on every probe-as-both value.
10642 let d = dep_with_fonte(DepSource::Path {
10643 caminho: "../caixa-teia | ls *".into(),
10644 });
10645 let err = d.validate().unwrap_err();
10646 assert!(
10647 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10648 "got {err:?}",
10649 );
10650 }
10651
10652 #[test]
10653 fn fonte_caminho_shell_redirection_fires_before_shell_glob() {
10654 // Cascade pin on the upstream shell-redirection arm: a value
10655 // carrying both `>` and `*` (`"../caixa-teia>log *"` — the
10656 // canonical "I pasted a `cmd > log *` redirect-plus-glob
10657 // chain" footgun) routes through
10658 // `FonteCaminhoShellRedirection` not `FonteCaminhoShellGlob`.
10659 // The input/output redirection metachar carries the more
10660 // self-locating `byte` payload (it names which of `<` or `>`
10661 // triggered), so the prior arm wins on every probe-as-both
10662 // value.
10663 let d = dep_with_fonte(DepSource::Path {
10664 caminho: "../caixa-teia>log *".into(),
10665 });
10666 let err = d.validate().unwrap_err();
10667 assert!(
10668 matches!(
10669 err,
10670 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10671 ),
10672 "got {err:?}",
10673 );
10674 }
10675
10676 #[test]
10677 fn fonte_caminho_backslash_fires_before_shell_glob() {
10678 // Cascade pin on the upstream backslash arm: a value
10679 // carrying both `\` and `*` (`"..\caixa-teia\*"` — the
10680 // canonical "I pasted a Windows-shell `cd ..\path\*` glob
10681 // expression" footgun) routes through
10682 // `FonteCaminhoBackslash` not `FonteCaminhoShellGlob`. The
10683 // cross-host-OS-separator divergence is the load-bearing
10684 // axis on every probe-as-both value (an author who removes
10685 // the `\` is the root-cause edit; the `*` falls away in the
10686 // same edit since it's downstream of the Windows-shell
10687 // convention).
10688 let d = dep_with_fonte(DepSource::Path {
10689 caminho: "..\\caixa-teia\\*".into(),
10690 });
10691 let err = d.validate().unwrap_err();
10692 assert!(
10693 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10694 "got {err:?}",
10695 );
10696 }
10697
10698 #[test]
10699 fn fonte_caminho_control_char_fires_before_shell_glob() {
10700 // Cascade pin on the embedded-control-byte arm: a value
10701 // carrying both a control byte and `*` (`"../foo\n*"` — the
10702 // canonical paste-from-multiline-doc footgun where a
10703 // newline landed mid-caminho between two paste fragments)
10704 // routes through `FonteCaminhoControlChar` not
10705 // `FonteCaminhoShellGlob`. The POSIX-syscall-rejected-byte /
10706 // NUL-`CString::new`-fail diagnostic is the load-bearing
10707 // axis on every value that probes positive for both —
10708 // mirrors the cascade discipline on every prior arm.
10709 let d = dep_with_fonte(DepSource::Path {
10710 caminho: "../foo\n*".into(),
10711 });
10712 let err = d.validate().unwrap_err();
10713 assert!(
10714 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10715 "got {err:?}",
10716 );
10717 }
10718
10719 #[test]
10720 fn fonte_caminho_absolute_fires_before_shell_glob() {
10721 // Cascade pin on the load-bearing leading-byte arm: a
10722 // leading `/` value with embedded `*` (`"/etc/*"`) routes
10723 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellGlob`
10724 // — the host-layout-leak diagnostic is the load-bearing
10725 // axis, the glob byte is the secondary observation. Same
10726 // precedence logic as every prior leading-byte arm.
10727 let d = dep_with_fonte(DepSource::Path {
10728 caminho: "/etc/*".into(),
10729 });
10730 let err = d.validate().unwrap_err();
10731 assert!(
10732 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10733 "got {err:?}",
10734 );
10735 }
10736
10737 #[test]
10738 fn fonte_caminho_shell_glob_fires_before_trailing_slash() {
10739 // Cascade pin on the immediate-successor arm: a value
10740 // carrying both `*` and a trailing `/` (`"../foo*/"` — the
10741 // canonical "I tab-completed a path that already had a
10742 // glob-expansion tail" footgun) routes through
10743 // `FonteCaminhoShellGlob` not `FonteCaminhoTrailingSlash`.
10744 // The embedded shell-metachar is the more semantic-locating
10745 // axis (an author who removes the `*` typically also drops
10746 // the trailing separator since both are paste-from-shell
10747 // artifacts).
10748 let d = dep_with_fonte(DepSource::Path {
10749 caminho: "../foo*/".into(),
10750 });
10751 let err = d.validate().unwrap_err();
10752 assert!(
10753 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10754 "got {err:?}",
10755 );
10756 }
10757
10758 #[test]
10759 fn fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte() {
10760 // Diagnostic-shape pin (peer with
10761 // `fonte_caminho_shell_redirection_diagnostic_*` on the
10762 // closest two-byte peer arm): the error's Display surfaces
10763 // the offending `:nome`, the offending `:caminho` verbatim,
10764 // the offending byte's hex / character form, and names the
10765 // shell-glob / pathname-expansion footgun explicitly so a
10766 // `feira lint` run can render the diagnostic without
10767 // re-parsing.
10768 let d = dep_with_fonte(DepSource::Path {
10769 caminho: "../caixa-teia/*.lisp".into(),
10770 });
10771 let rendered = d.validate().unwrap_err().to_string();
10772 assert!(
10773 rendered.contains("caixa-teia"),
10774 "diagnostic must name the offending dep: {rendered}",
10775 );
10776 assert!(
10777 rendered.contains("../caixa-teia/*.lisp"),
10778 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10779 );
10780 assert!(
10781 rendered.contains("0x2a"),
10782 "diagnostic must surface the offending byte hex: {rendered:?}",
10783 );
10784 assert!(
10785 rendered.contains("glob"),
10786 "diagnostic must name the shell-glob footgun: {rendered:?}",
10787 );
10788 assert!(
10789 rendered.contains("pathname-expansion"),
10790 "diagnostic must reference the POSIX pathname-expansion vocabulary: {rendered:?}",
10791 );
10792 }
10793
10794 #[test]
10795 fn validate_rejects_path_fonte_with_caminho_carrying_modern_command_substitution() {
10796 // The fail-before-pass-after pin for the canonical modern-Bourne
10797 // command-substitution paste footgun: an author copies a
10798 // `cd ../caixa-teia/$(date)/build` shell-history one-liner whose
10799 // `$(<cmd>)` expansion would land the current date as a
10800 // subdirectory name and silently passed every prior arm
10801 // (`Path::is_absolute` false on `..`, no control bytes, no `\`,
10802 // no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no `*` /
10803 // `?`, doesn't end in `/`; the leading-`$` f4efe9c
10804 // `FonteCaminhoVarExpansion` arm doesn't fire because the `$`
10805 // sits mid-path). The lacre embedded the value verbatim, the
10806 // resolver folded it through `Path::join` looking for a literal
10807 // `./../caixa-teia/$(date)/build` subdirectory, and the failure
10808 // surfaced at resolve time with a non-self-locating `No such
10809 // file or directory` error. The new arm moves the rejection to
10810 // validate time and names the offending dep + caminho + byte
10811 // verbatim. The arm fires on the first `(` encountered (the
10812 // opening byte of `$(date)`).
10813 let d = dep_with_fonte(DepSource::Path {
10814 caminho: "../caixa-teia/$(date)/build".into(),
10815 });
10816 let err = d.validate().unwrap_err();
10817 let DepError::FonteCaminhoShellSubshellGrouping {
10818 nome,
10819 caminho,
10820 byte,
10821 } = err
10822 else {
10823 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10824 };
10825 assert_eq!(nome, "caixa-teia");
10826 assert_eq!(caminho, "../caixa-teia/$(date)/build");
10827 assert_eq!(byte, b'(');
10828 }
10829
10830 #[test]
10831 fn validate_rejects_path_fonte_with_caminho_carrying_close_paren() {
10832 // The symmetric close-paren paste shape (`"../caixa-teia)"` —
10833 // the degenerate "I selected an unbalanced closing paren out of
10834 // a shell-history block" idiom that probes for the cascade's
10835 // last-byte handling on a value carrying only the closing byte).
10836 // Pinned separately from the open-paren shape so the gate's
10837 // contract is "any `(` or `)` anywhere", not single-byte
10838 // coverage. Mirrors the peer `validate_rejects_path_fonte_with_\
10839 // caminho_carrying_question_glob` shape on the immediate-
10840 // predecessor `FonteCaminhoShellGlob` arm.
10841 let d = dep_with_fonte(DepSource::Path {
10842 caminho: "../caixa-teia)".into(),
10843 });
10844 let err = d.validate().unwrap_err();
10845 let DepError::FonteCaminhoShellSubshellGrouping { byte, .. } = err else {
10846 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10847 };
10848 assert_eq!(byte, b')');
10849 }
10850
10851 #[test]
10852 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_paren() {
10853 // Leading-position `(` shape (`"(cd foo)/caixa-teia"` — the
10854 // canonical "I selected a `(cd foo)` subshell-grouping prefix
10855 // out of a `(cd foo) && cmd` shell-history one-liner" idiom).
10856 // Pinned separately from the embedded-byte shape so the gate
10857 // covers every position, not only mid-path.
10858 let d = dep_with_fonte(DepSource::Path {
10859 caminho: "(cd foo)/caixa-teia".into(),
10860 });
10861 let err = d.validate().unwrap_err();
10862 assert!(
10863 matches!(
10864 err,
10865 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10866 ),
10867 "got {err:?}",
10868 );
10869 }
10870
10871 #[test]
10872 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_subshell_grouping_pair() {
10873 // The canonical balanced-pair shape (`"../(pwd)/caixa-teia"`
10874 // — the canonical "I copied a `(pwd)` working-directory-probe
10875 // subshell-grouping idiom every shell-history block carries"
10876 // footgun). The value carries no other cascade-preceding
10877 // shell metachar (`&` / `;` / `|` / `<` / `>` / backtick /
10878 // `*` / `?`) so the arm fires on the first `(` encountered;
10879 // pinned so a future arm that tries to distinguish the
10880 // opening from the closing byte doesn't break the broader
10881 // contract. Mirrors the peer
10882 // `validate_rejects_path_fonte_with_caminho_carrying_balanced_\
10883 // backtick_pair` shape on the upstream `FonteCaminhoShell\
10884 // CommandSubstitution` arm.
10885 let d = dep_with_fonte(DepSource::Path {
10886 caminho: "../(pwd)/caixa-teia".into(),
10887 });
10888 let err = d.validate().unwrap_err();
10889 assert!(
10890 matches!(
10891 err,
10892 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10893 ),
10894 "got {err:?}",
10895 );
10896 }
10897
10898 #[test]
10899 fn validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping() {
10900 // The positive-control pin: the gate targets only `(` / `)`,
10901 // never adjacent printable ASCII or POSIX-valid bytes. The
10902 // canonical relative POSIX path (`"../caixa-teia"`) and a
10903 // nested deeply-pathed variant with adjacent printable
10904 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10905 // validate cleanly so the gate doesn't widen to a "no printable
10906 // punctuation anywhere" sweep that would defeat the entire
10907 // path-fonte author surface.
10908 let d = dep_with_fonte(DepSource::Path {
10909 caminho: "../caixa-teia/sub-dir.v2".into(),
10910 });
10911 d.validate().unwrap();
10912 }
10913
10914 #[test]
10915 fn fonte_caminho_shell_glob_fires_before_shell_subshell_grouping() {
10916 // Cascade pin on the immediate-predecessor arm: a value
10917 // carrying both `*` and `(` (`"../caixa-teia/*(date)"` — the
10918 // canonical "I pasted a glob expansion followed by a
10919 // subshell-grouping tail" footgun) routes through
10920 // `FonteCaminhoShellGlob` not
10921 // `FonteCaminhoShellSubshellGrouping`. The pathname-expansion
10922 // shape is the more common shell-history paste idiom on every
10923 // probe-as-both value — same cascade discipline every prior
10924 // `:caminho` arm establishes.
10925 let d = dep_with_fonte(DepSource::Path {
10926 caminho: "../caixa-teia/*(date)".into(),
10927 });
10928 let err = d.validate().unwrap_err();
10929 assert!(
10930 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10931 "got {err:?}",
10932 );
10933 }
10934
10935 #[test]
10936 fn fonte_caminho_shell_command_substitution_fires_before_shell_subshell_grouping() {
10937 // Cascade pin on the upstream shell-command-substitution arm: a
10938 // value carrying both a backtick and `(` (``"../`whoami`/$(date)"``
10939 // — the canonical "I pasted a legacy-backtick + modern-paren
10940 // command-substitution chain" footgun) routes through
10941 // `FonteCaminhoShellCommandSubstitution` not
10942 // `FonteCaminhoShellSubshellGrouping`. The CWE-78 shell-
10943 // command-injection vector is the load-bearing root-cause edit
10944 // on every probe-as-both value.
10945 let d = dep_with_fonte(DepSource::Path {
10946 caminho: "../`whoami`/$(date)".into(),
10947 });
10948 let err = d.validate().unwrap_err();
10949 assert!(
10950 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10951 "got {err:?}",
10952 );
10953 }
10954
10955 #[test]
10956 fn fonte_caminho_shell_background_fires_before_shell_subshell_grouping() {
10957 // Cascade pin on the upstream shell-background arm: a value
10958 // carrying both `&` and `(` (`"../caixa-teia & (cd foo)"` —
10959 // the canonical "I pasted a `cmd & (cd foo)` background-launch
10960 // + subshell-grouping chain" footgun) routes through
10961 // `FonteCaminhoShellBackground` not
10962 // `FonteCaminhoShellSubshellGrouping`. The background-launch
10963 // tail is the load-bearing root-cause edit on every probe-as-
10964 // both value.
10965 let d = dep_with_fonte(DepSource::Path {
10966 caminho: "../caixa-teia & (cd foo)".into(),
10967 });
10968 let err = d.validate().unwrap_err();
10969 assert!(
10970 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10971 "got {err:?}",
10972 );
10973 }
10974
10975 #[test]
10976 fn fonte_caminho_shell_semicolon_fires_before_shell_subshell_grouping() {
10977 // Cascade pin on the upstream shell-semicolon arm: a value
10978 // carrying both `;` and `(` (`"../caixa-teia; (cd foo)"` —
10979 // the canonical sequential-cleanup + subshell-grouping paste
10980 // idiom) routes through `FonteCaminhoShellSemicolon` not
10981 // `FonteCaminhoShellSubshellGrouping`. The sequential-command-
10982 // separator paste is the load-bearing root-cause edit on
10983 // every probe-as-both value.
10984 let d = dep_with_fonte(DepSource::Path {
10985 caminho: "../caixa-teia; (cd foo)".into(),
10986 });
10987 let err = d.validate().unwrap_err();
10988 assert!(
10989 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10990 "got {err:?}",
10991 );
10992 }
10993
10994 #[test]
10995 fn fonte_caminho_shell_pipe_fires_before_shell_subshell_grouping() {
10996 // Cascade pin on the upstream shell-pipe arm: a value carrying
10997 // both `|` and `(` (`"../caixa-teia | (tee log)"` — the
10998 // canonical pipeline-to-subshell-grouping paste idiom) routes
10999 // through `FonteCaminhoShellPipe` not
11000 // `FonteCaminhoShellSubshellGrouping`. The pipeline-tail paste
11001 // is the load-bearing root-cause edit on every probe-as-both
11002 // value.
11003 let d = dep_with_fonte(DepSource::Path {
11004 caminho: "../caixa-teia | (tee log)".into(),
11005 });
11006 let err = d.validate().unwrap_err();
11007 assert!(
11008 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11009 "got {err:?}",
11010 );
11011 }
11012
11013 #[test]
11014 fn fonte_caminho_shell_redirection_fires_before_shell_subshell_grouping() {
11015 // Cascade pin on the upstream shell-redirection arm: a value
11016 // carrying both `>` and `(` (`"../caixa-teia>log (cd foo)"` —
11017 // the canonical "I pasted a `cmd > log (cd foo)` redirect-
11018 // plus-subshell-grouping chain" footgun) routes through
11019 // `FonteCaminhoShellRedirection` not
11020 // `FonteCaminhoShellSubshellGrouping`. The input/output
11021 // redirection metachar carries the more self-locating `byte`
11022 // payload (it names which of `<` or `>` triggered), so the
11023 // prior arm wins on every probe-as-both value.
11024 let d = dep_with_fonte(DepSource::Path {
11025 caminho: "../caixa-teia>log (cd foo)".into(),
11026 });
11027 let err = d.validate().unwrap_err();
11028 assert!(
11029 matches!(
11030 err,
11031 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11032 ),
11033 "got {err:?}",
11034 );
11035 }
11036
11037 #[test]
11038 fn fonte_caminho_backslash_fires_before_shell_subshell_grouping() {
11039 // Cascade pin on the upstream backslash arm: a value carrying
11040 // both `\` and `(` (`"..\caixa-teia\(cd foo)"` — the canonical
11041 // "I pasted a Windows-shell `cd ..\path\(cmd)` chain") routes
11042 // through `FonteCaminhoBackslash` not
11043 // `FonteCaminhoShellSubshellGrouping`. The cross-host-OS-
11044 // separator divergence is the load-bearing axis on every
11045 // probe-as-both value (an author who removes the `\` is the
11046 // root-cause edit; the `(` falls away in the same edit since
11047 // it's downstream of the Windows-shell convention).
11048 let d = dep_with_fonte(DepSource::Path {
11049 caminho: "..\\caixa-teia\\(cd foo)".into(),
11050 });
11051 let err = d.validate().unwrap_err();
11052 assert!(
11053 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11054 "got {err:?}",
11055 );
11056 }
11057
11058 #[test]
11059 fn fonte_caminho_control_char_fires_before_shell_subshell_grouping() {
11060 // Cascade pin on the embedded-control-byte arm: a value
11061 // carrying both a control byte and `(` (`"../foo\n(cd bar)"` —
11062 // the canonical paste-from-multiline-doc footgun where a
11063 // newline landed mid-caminho between two paste fragments)
11064 // routes through `FonteCaminhoControlChar` not
11065 // `FonteCaminhoShellSubshellGrouping`. The POSIX-syscall-
11066 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
11067 // load-bearing axis on every value that probes positive for
11068 // both — mirrors the cascade discipline on every prior arm.
11069 let d = dep_with_fonte(DepSource::Path {
11070 caminho: "../foo\n(cd bar)".into(),
11071 });
11072 let err = d.validate().unwrap_err();
11073 assert!(
11074 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11075 "got {err:?}",
11076 );
11077 }
11078
11079 #[test]
11080 fn fonte_caminho_absolute_fires_before_shell_subshell_grouping() {
11081 // Cascade pin on the load-bearing leading-byte arm: a leading
11082 // `/` value with embedded `(` (`"/etc/(cd foo)"`) routes
11083 // through `FonteCaminhoAbsolute` not
11084 // `FonteCaminhoShellSubshellGrouping` — the host-layout-leak
11085 // diagnostic is the load-bearing axis, the subshell-grouping
11086 // byte is the secondary observation. Same precedence logic as
11087 // every prior leading-byte arm.
11088 let d = dep_with_fonte(DepSource::Path {
11089 caminho: "/etc/(cd foo)".into(),
11090 });
11091 let err = d.validate().unwrap_err();
11092 assert!(
11093 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11094 "got {err:?}",
11095 );
11096 }
11097
11098 #[test]
11099 fn fonte_caminho_var_expansion_fires_before_shell_subshell_grouping() {
11100 // Cascade pin on the upstream leading-`$` var-expansion arm: a
11101 // value carrying both a leading `$` and a `(` (`"$(date)/\
11102 // caixa-teia"` — the canonical "I pasted a `$(date)` modern-
11103 // command-substitution at the head of a sibling-workspace
11104 // path" footgun) routes through `FonteCaminhoVarExpansion` not
11105 // `FonteCaminhoShellSubshellGrouping`. The leading-byte
11106 // shell-variable-expansion is the more self-locating diagnostic
11107 // on values that probe as both — same load-bearing-leading-
11108 // byte cascade discipline every prior `:caminho` arm
11109 // establishes. Closing both halves of `$(<cmd>)` structurally
11110 // (leading `$` here, trailing `)` on the new arm) excludes the
11111 // entire modern Bourne command-substitution surface from the
11112 // typed `:caminho` accepted set; the cascade preserves the
11113 // narrower leading-byte diagnostic on values that probe both
11114 // halves at the canonical leading position.
11115 let d = dep_with_fonte(DepSource::Path {
11116 caminho: "$(date)/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_subshell_grouping_fires_before_trailing_slash() {
11127 // Cascade pin on the immediate-successor arm: a value carrying
11128 // both `(` and a trailing `/` (`"../(cd foo)/"` — the canonical
11129 // "I tab-completed a path that already had a subshell-grouping
11130 // expansion tail" footgun) routes through
11131 // `FonteCaminhoShellSubshellGrouping` not
11132 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
11133 // the more semantic-locating axis (an author who removes the
11134 // `(` typically also drops the trailing separator since both
11135 // are paste-from-shell artifacts).
11136 let d = dep_with_fonte(DepSource::Path {
11137 caminho: "../(cd foo)/".into(),
11138 });
11139 let err = d.validate().unwrap_err();
11140 assert!(
11141 matches!(
11142 err,
11143 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11144 ),
11145 "got {err:?}",
11146 );
11147 }
11148
11149 #[test]
11150 fn fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
11151 // Diagnostic-shape pin (peer with
11152 // `fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte`
11153 // on the closest two-byte peer arm): the error's Display
11154 // surfaces the offending `:nome`, the offending `:caminho`
11155 // verbatim, the offending byte's hex / character form, and
11156 // names the shell-subshell-grouping footgun explicitly so a
11157 // `feira lint` run can render the diagnostic without re-
11158 // parsing.
11159 let d = dep_with_fonte(DepSource::Path {
11160 caminho: "../caixa-teia/$(date)/build".into(),
11161 });
11162 let rendered = d.validate().unwrap_err().to_string();
11163 assert!(
11164 rendered.contains("caixa-teia"),
11165 "diagnostic must name the offending dep: {rendered}",
11166 );
11167 assert!(
11168 rendered.contains("../caixa-teia/$(date)/build"),
11169 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11170 );
11171 assert!(
11172 rendered.contains("0x28"),
11173 "diagnostic must surface the offending byte hex: {rendered:?}",
11174 );
11175 assert!(
11176 rendered.contains("subshell-grouping"),
11177 "diagnostic must name the shell-subshell-grouping footgun: {rendered:?}",
11178 );
11179 assert!(
11180 rendered.contains("command-substitution"),
11181 "diagnostic must reference the `$(<cmd>)` command-substitution vocabulary: \
11182 {rendered:?}",
11183 );
11184 }
11185
11186 // ── shell-brace-expansion / URI-Template-placeholder arm ───────────
11187 //
11188 // Peer with the prior `FonteCaminhoShellSubshellGrouping` (`(` /
11189 // `)`) byte-pair arm: the same per-byte cascade with the same
11190 // self-locating `byte: u8` diagnostic on the orthogonal `{` /
11191 // `}` brace-expansion / URI-Template placeholder axis. The peer
11192 // [`crate::render::is_git_repo_url`] (42d8f9d) closes the same
11193 // byte pair on the sibling `:fonte :repo` axis under the same
11194 // banner.
11195
11196 #[test]
11197 fn validate_rejects_path_fonte_with_caminho_carrying_brace_expansion_fan_across_siblings() {
11198 // The fail-before-pass-after pin for the canonical paste-from-
11199 // shell-history brace-expansion footgun: an author copies a
11200 // `cd ../{caixa-teia,caixa-helm}/build` shell-history one-
11201 // liner whose `{a,b}` brace expansion fans across two siblings
11202 // and silently passed every prior arm (`Path::is_absolute`
11203 // false on `..`, no control bytes, no `\`, no `<` / `>`, no
11204 // `|`, no `;`, no `&`, no backtick, no `*` / `?`, no `(` /
11205 // `)`, doesn't end in `/`; the leading-`$` f4efe9c
11206 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11207 // value starts with `..` not `$`). The lacre embedded the
11208 // value verbatim, the resolver folded it through `Path::join`
11209 // looking for a literal `./../{caixa-teia,caixa-helm}/build`
11210 // subdirectory, and the failure surfaced at resolve time with
11211 // a non-self-locating `No such file or directory` error. The
11212 // new arm moves the rejection to validate time and names the
11213 // offending dep + caminho + byte verbatim. The arm fires on
11214 // the first `{` encountered.
11215 let d = dep_with_fonte(DepSource::Path {
11216 caminho: "../{caixa-teia,caixa-helm}/build".into(),
11217 });
11218 let err = d.validate().unwrap_err();
11219 let DepError::FonteCaminhoShellBraceExpansion {
11220 nome,
11221 caminho,
11222 byte,
11223 } = err
11224 else {
11225 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
11226 };
11227 assert_eq!(nome, "caixa-teia");
11228 assert_eq!(caminho, "../{caixa-teia,caixa-helm}/build");
11229 assert_eq!(byte, b'{');
11230 }
11231
11232 #[test]
11233 fn validate_rejects_path_fonte_with_caminho_carrying_close_brace() {
11234 // The symmetric close-brace paste shape (`"../caixa-teia}"` —
11235 // the degenerate "I selected an unbalanced closing brace out
11236 // of a shell-history block" idiom that probes for the
11237 // cascade's last-byte handling on a value carrying only the
11238 // closing byte). Pinned separately from the open-brace shape
11239 // so the gate's contract is "any `{` or `}` anywhere", not
11240 // single-byte coverage. Mirrors the peer
11241 // `validate_rejects_path_fonte_with_caminho_carrying_close_paren`
11242 // shape on the immediate-predecessor `FonteCaminhoShellSubshellGrouping`
11243 // arm.
11244 let d = dep_with_fonte(DepSource::Path {
11245 caminho: "../caixa-teia}".into(),
11246 });
11247 let err = d.validate().unwrap_err();
11248 let DepError::FonteCaminhoShellBraceExpansion { byte, .. } = err else {
11249 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
11250 };
11251 assert_eq!(byte, b'}');
11252 }
11253
11254 #[test]
11255 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_brace() {
11256 // Leading-position `{` shape (`"{caixa-teia,caixa-helm}/build"`
11257 // — the canonical "I selected a `{a,b}` brace-expansion prefix
11258 // out of a shell-history one-liner" idiom). Pinned separately
11259 // from the embedded-byte shape so the gate covers every
11260 // position, not only mid-path.
11261 let d = dep_with_fonte(DepSource::Path {
11262 caminho: "{caixa-teia,caixa-helm}/build".into(),
11263 });
11264 let err = d.validate().unwrap_err();
11265 assert!(
11266 matches!(
11267 err,
11268 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11269 ),
11270 "got {err:?}",
11271 );
11272 }
11273
11274 #[test]
11275 fn validate_rejects_path_fonte_with_caminho_carrying_uri_template_placeholder() {
11276 // The canonical URI-Template / Mustache / Helm doubled-brace
11277 // placeholder shape (`"../{{org}}/caixa-teia"` — the canonical
11278 // "I copied a `https://github.com/{{org}}/caixa-teia` README
11279 // quick-start / OpenAPI spec / Helm chart `home:` template
11280 // and forgot to substitute the placeholder" footgun). The arm
11281 // fires on the first `{` encountered; pinned so the gate's
11282 // coverage extends from the bare-brace shell-history shape to
11283 // the doubled-brace URI-Template / templating-engine shape.
11284 // Mirrors the peer 42d8f9d `is_git_repo_url` arm on the
11285 // sibling `:fonte :repo` axis.
11286 let d = dep_with_fonte(DepSource::Path {
11287 caminho: "../{{org}}/caixa-teia".into(),
11288 });
11289 let err = d.validate().unwrap_err();
11290 assert!(
11291 matches!(
11292 err,
11293 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11294 ),
11295 "got {err:?}",
11296 );
11297 }
11298
11299 #[test]
11300 fn validate_rejects_path_fonte_with_caminho_carrying_brace_range_expansion() {
11301 // The canonical bash brace-range-expansion shape (`"../caixa-
11302 // v{1..10}"` — the `{1..10}` sequence expansion every bash /
11303 // zsh `for i in {1..10}; do …; done` idiom uses, the symmetric
11304 // sequence-range form to the `{a,b,c}` comma-separated form).
11305 // The arm fires on the first `{` encountered; pinned so the
11306 // gate's coverage extends from the comma-separated form to
11307 // the integer-range form.
11308 let d = dep_with_fonte(DepSource::Path {
11309 caminho: "../caixa-v{1..10}".into(),
11310 });
11311 let err = d.validate().unwrap_err();
11312 assert!(
11313 matches!(
11314 err,
11315 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11316 ),
11317 "got {err:?}",
11318 );
11319 }
11320
11321 #[test]
11322 fn validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion() {
11323 // The positive-control pin: the gate targets only `{` / `}`,
11324 // never adjacent printable ASCII or POSIX-valid bytes. The
11325 // canonical relative POSIX path (`"../caixa-teia"`) and a
11326 // nested deeply-pathed variant with adjacent printable
11327 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
11328 // validate cleanly so the gate doesn't widen to a "no
11329 // printable punctuation anywhere" sweep that would defeat
11330 // the entire path-fonte author surface. Peer with
11331 // `validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping`
11332 // on the immediate-predecessor arm.
11333 let d = dep_with_fonte(DepSource::Path {
11334 caminho: "../caixa-teia/sub-dir.v2".into(),
11335 });
11336 d.validate().unwrap();
11337 }
11338
11339 #[test]
11340 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_brace_expansion() {
11341 // Cascade pin on the immediate-predecessor arm: a value
11342 // carrying both `(` and `{` (`"../(cd foo)/{a,b}"` — the
11343 // canonical "I pasted a subshell-grouping followed by a
11344 // brace-expansion tail" footgun) routes through
11345 // `FonteCaminhoShellSubshellGrouping` not
11346 // `FonteCaminhoShellBraceExpansion`. The subshell-grouping
11347 // shape is the more semantic-locating axis on every probe-
11348 // as-both value because it closes both halves of the modern
11349 // Bourne `$(<cmd>)` command-substitution surface — same
11350 // cascade discipline every prior `:caminho` arm establishes.
11351 let d = dep_with_fonte(DepSource::Path {
11352 caminho: "../(cd foo)/{a,b}".into(),
11353 });
11354 let err = d.validate().unwrap_err();
11355 assert!(
11356 matches!(
11357 err,
11358 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11359 ),
11360 "got {err:?}",
11361 );
11362 }
11363
11364 #[test]
11365 fn fonte_caminho_shell_glob_fires_before_shell_brace_expansion() {
11366 // Cascade pin on the upstream shell-glob arm: a value carrying
11367 // both `*` and `{` (`"../caixa-teia/*{a,b}"` — the canonical
11368 // "I pasted a glob expansion followed by a brace-expansion
11369 // tail" footgun) routes through `FonteCaminhoShellGlob` not
11370 // `FonteCaminhoShellBraceExpansion`. The pathname-expansion
11371 // shape is the load-bearing root-cause edit on every
11372 // probe-as-both value.
11373 let d = dep_with_fonte(DepSource::Path {
11374 caminho: "../caixa-teia/*{a,b}".into(),
11375 });
11376 let err = d.validate().unwrap_err();
11377 assert!(
11378 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11379 "got {err:?}",
11380 );
11381 }
11382
11383 #[test]
11384 fn fonte_caminho_shell_command_substitution_fires_before_shell_brace_expansion() {
11385 // Cascade pin on the upstream shell-command-substitution arm:
11386 // a value carrying both a backtick and `{` (``"../`whoami`/{a,b}"``
11387 // — the canonical "I pasted a legacy-backtick command-
11388 // substitution followed by a brace-expansion fan-out" footgun)
11389 // routes through `FonteCaminhoShellCommandSubstitution` not
11390 // `FonteCaminhoShellBraceExpansion`. The CWE-78 shell-
11391 // command-injection vector is the load-bearing root-cause
11392 // edit on every probe-as-both value.
11393 let d = dep_with_fonte(DepSource::Path {
11394 caminho: "../`whoami`/{a,b}".into(),
11395 });
11396 let err = d.validate().unwrap_err();
11397 assert!(
11398 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11399 "got {err:?}",
11400 );
11401 }
11402
11403 #[test]
11404 fn fonte_caminho_shell_background_fires_before_shell_brace_expansion() {
11405 // Cascade pin on the upstream shell-background arm: a value
11406 // carrying both `&` and `{` (`"../caixa-teia & {a,b}"` — the
11407 // canonical "I pasted a `cmd & {fork-fan}` background-launch
11408 // + brace-expansion chain" footgun) routes through
11409 // `FonteCaminhoShellBackground` not
11410 // `FonteCaminhoShellBraceExpansion`. The background-launch
11411 // tail is the load-bearing root-cause edit on every
11412 // probe-as-both value.
11413 let d = dep_with_fonte(DepSource::Path {
11414 caminho: "../caixa-teia & {a,b}".into(),
11415 });
11416 let err = d.validate().unwrap_err();
11417 assert!(
11418 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11419 "got {err:?}",
11420 );
11421 }
11422
11423 #[test]
11424 fn fonte_caminho_shell_semicolon_fires_before_shell_brace_expansion() {
11425 // Cascade pin on the upstream shell-semicolon arm: a value
11426 // carrying both `;` and `{` (`"../caixa-teia; {a,b}"` — the
11427 // canonical sequential-cleanup + brace-expansion paste
11428 // idiom) routes through `FonteCaminhoShellSemicolon` not
11429 // `FonteCaminhoShellBraceExpansion`. The sequential-command-
11430 // separator paste is the load-bearing root-cause edit on
11431 // every probe-as-both value.
11432 let d = dep_with_fonte(DepSource::Path {
11433 caminho: "../caixa-teia; {a,b}".into(),
11434 });
11435 let err = d.validate().unwrap_err();
11436 assert!(
11437 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11438 "got {err:?}",
11439 );
11440 }
11441
11442 #[test]
11443 fn fonte_caminho_shell_pipe_fires_before_shell_brace_expansion() {
11444 // Cascade pin on the upstream shell-pipe arm: a value
11445 // carrying both `|` and `{` (`"../caixa-teia | {tee,cat}"`
11446 // — the canonical pipeline-to-brace-expansion paste idiom)
11447 // routes through `FonteCaminhoShellPipe` not
11448 // `FonteCaminhoShellBraceExpansion`. The pipeline-tail paste
11449 // is the load-bearing root-cause edit on every probe-as-
11450 // both value.
11451 let d = dep_with_fonte(DepSource::Path {
11452 caminho: "../caixa-teia | {tee,cat}".into(),
11453 });
11454 let err = d.validate().unwrap_err();
11455 assert!(
11456 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11457 "got {err:?}",
11458 );
11459 }
11460
11461 #[test]
11462 fn fonte_caminho_shell_redirection_fires_before_shell_brace_expansion() {
11463 // Cascade pin on the upstream shell-redirection arm: a value
11464 // carrying both `>` and `{` (`"../caixa-teia>log {a,b}"` —
11465 // the canonical "I pasted a `cmd > log {a,b}` redirect-
11466 // plus-brace-expansion chain" footgun) routes through
11467 // `FonteCaminhoShellRedirection` not
11468 // `FonteCaminhoShellBraceExpansion`. The input/output
11469 // redirection metachar carries the more self-locating
11470 // `byte` payload, so the prior arm wins on every probe-
11471 // as-both value.
11472 let d = dep_with_fonte(DepSource::Path {
11473 caminho: "../caixa-teia>log {a,b}".into(),
11474 });
11475 let err = d.validate().unwrap_err();
11476 assert!(
11477 matches!(
11478 err,
11479 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11480 ),
11481 "got {err:?}",
11482 );
11483 }
11484
11485 #[test]
11486 fn fonte_caminho_backslash_fires_before_shell_brace_expansion() {
11487 // Cascade pin on the upstream backslash arm: a value
11488 // carrying both `\` and `{` (`"..\caixa-teia\{a,b}"` — the
11489 // canonical "I pasted a Windows-shell `cd ..\path\{a,b}`
11490 // chain") routes through `FonteCaminhoBackslash` not
11491 // `FonteCaminhoShellBraceExpansion`. The cross-host-OS-
11492 // separator divergence is the load-bearing axis on every
11493 // probe-as-both value.
11494 let d = dep_with_fonte(DepSource::Path {
11495 caminho: "..\\caixa-teia\\{a,b}".into(),
11496 });
11497 let err = d.validate().unwrap_err();
11498 assert!(
11499 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11500 "got {err:?}",
11501 );
11502 }
11503
11504 #[test]
11505 fn fonte_caminho_control_char_fires_before_shell_brace_expansion() {
11506 // Cascade pin on the embedded-control-byte arm: a value
11507 // carrying both a control byte and `{` (`"../foo\n{a,b}"` —
11508 // the canonical paste-from-multiline-doc footgun where a
11509 // newline landed mid-caminho between two paste fragments)
11510 // routes through `FonteCaminhoControlChar` not
11511 // `FonteCaminhoShellBraceExpansion`. The POSIX-syscall-
11512 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
11513 // load-bearing axis on every value that probes positive for
11514 // both — mirrors the cascade discipline on every prior arm.
11515 let d = dep_with_fonte(DepSource::Path {
11516 caminho: "../foo\n{a,b}".into(),
11517 });
11518 let err = d.validate().unwrap_err();
11519 assert!(
11520 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11521 "got {err:?}",
11522 );
11523 }
11524
11525 #[test]
11526 fn fonte_caminho_absolute_fires_before_shell_brace_expansion() {
11527 // Cascade pin on the load-bearing leading-byte arm: a
11528 // leading `/` value with embedded `{` (`"/etc/{a,b}"`)
11529 // routes through `FonteCaminhoAbsolute` not
11530 // `FonteCaminhoShellBraceExpansion` — the host-layout-leak
11531 // diagnostic is the load-bearing axis, the brace-expansion
11532 // byte is the secondary observation. Same precedence logic
11533 // as every prior leading-byte arm.
11534 let d = dep_with_fonte(DepSource::Path {
11535 caminho: "/etc/{a,b}".into(),
11536 });
11537 let err = d.validate().unwrap_err();
11538 assert!(
11539 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11540 "got {err:?}",
11541 );
11542 }
11543
11544 #[test]
11545 fn fonte_caminho_var_expansion_fires_before_shell_brace_expansion() {
11546 // Cascade pin on the upstream leading-`$` var-expansion
11547 // arm: a value carrying both a leading `$` and a `{`
11548 // (`"${ORG}/caixa-teia"` — the canonical "I pasted a
11549 // `${ORG}` shell-variable + curly-brace expansion at the
11550 // head of a sibling-workspace path" footgun) routes through
11551 // `FonteCaminhoVarExpansion` not
11552 // `FonteCaminhoShellBraceExpansion`. The leading-byte
11553 // shell-variable-expansion is the more self-locating
11554 // diagnostic on values that probe as both — same
11555 // load-bearing-leading-byte cascade discipline every prior
11556 // `:caminho` arm establishes.
11557 let d = dep_with_fonte(DepSource::Path {
11558 caminho: "${ORG}/caixa-teia".into(),
11559 });
11560 let err = d.validate().unwrap_err();
11561 assert!(
11562 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11563 "got {err:?}",
11564 );
11565 }
11566
11567 #[test]
11568 fn fonte_caminho_shell_brace_expansion_fires_before_trailing_slash() {
11569 // Cascade pin on the immediate-successor arm: a value
11570 // carrying both `{` and a trailing `/`
11571 // (`"../{caixa-teia,caixa-helm}/"` — the canonical "I
11572 // tab-completed a path that already had a brace-expansion
11573 // expansion tail" footgun) routes through
11574 // `FonteCaminhoShellBraceExpansion` not
11575 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11576 // is the more semantic-locating axis (an author who removes
11577 // the `{` typically also drops the trailing separator since
11578 // both are paste-from-shell artifacts).
11579 let d = dep_with_fonte(DepSource::Path {
11580 caminho: "../{caixa-teia,caixa-helm}/".into(),
11581 });
11582 let err = d.validate().unwrap_err();
11583 assert!(
11584 matches!(
11585 err,
11586 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11587 ),
11588 "got {err:?}",
11589 );
11590 }
11591
11592 #[test]
11593 fn fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11594 // Diagnostic-shape pin (peer with
11595 // `fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
11596 // on the closest two-byte peer arm): the error's Display
11597 // surfaces the offending `:nome`, the offending `:caminho`
11598 // verbatim, the offending byte's hex / character form, and
11599 // names the shell-brace-expansion / URI-Template footgun
11600 // explicitly so a `feira lint` run can render the diagnostic
11601 // without re-parsing.
11602 let d = dep_with_fonte(DepSource::Path {
11603 caminho: "../{caixa-teia,caixa-helm}/build".into(),
11604 });
11605 let rendered = d.validate().unwrap_err().to_string();
11606 assert!(
11607 rendered.contains("caixa-teia"),
11608 "diagnostic must name the offending dep: {rendered}",
11609 );
11610 assert!(
11611 rendered.contains("../{caixa-teia,caixa-helm}/build"),
11612 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11613 );
11614 assert!(
11615 rendered.contains("0x7b"),
11616 "diagnostic must surface the offending byte hex: {rendered:?}",
11617 );
11618 assert!(
11619 rendered.contains("brace-expansion"),
11620 "diagnostic must name the shell-brace-expansion footgun: {rendered:?}",
11621 );
11622 assert!(
11623 rendered.contains("URI Template"),
11624 "diagnostic must reference the RFC-6570 URI-Template-placeholder vocabulary: \
11625 {rendered:?}",
11626 );
11627 }
11628
11629 #[test]
11630 fn validate_rejects_path_fonte_with_caminho_carrying_bracket_glob_character_class() {
11631 // The canonical paste-from-shell-history bracket-glob /
11632 // character-class footgun: an author copies a
11633 // `cd ../caixa-[a-z]/build` shell-history one-liner whose
11634 // `[a-z]` POSIX glob character-class matches every lowercase-
11635 // ASCII-suffix sibling caixa directory and silently passed
11636 // every prior arm (`Path::is_absolute` false on `..`, no
11637 // control bytes, no `\`, no `<` / `>`, no `|`, no `;`, no
11638 // `&`, no backtick, no `*` / `?`, no `(` / `)`, no `{` /
11639 // `}`, doesn't end in `/`; the leading-`$` f4efe9c
11640 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11641 // value starts with `..` not `$`). The lacre embedded the
11642 // value verbatim, the resolver folded it through
11643 // `Path::join` looking for a literal `./../caixa-[a-z]/
11644 // build` subdirectory, and the failure surfaced at resolve
11645 // time with a non-self-locating `No such file or directory`
11646 // error. The new arm moves the rejection to validate time
11647 // and names the offending dep + caminho + byte verbatim.
11648 // The arm fires on the first `[` encountered.
11649 let d = dep_with_fonte(DepSource::Path {
11650 caminho: "../caixa-[a-z]/build".into(),
11651 });
11652 let err = d.validate().unwrap_err();
11653 let DepError::FonteCaminhoShellBracketExpansion {
11654 nome,
11655 caminho,
11656 byte,
11657 } = err
11658 else {
11659 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11660 };
11661 assert_eq!(nome, "caixa-teia");
11662 assert_eq!(caminho, "../caixa-[a-z]/build");
11663 assert_eq!(byte, b'[');
11664 }
11665
11666 #[test]
11667 fn validate_rejects_path_fonte_with_caminho_carrying_close_bracket() {
11668 // The symmetric close-bracket paste shape (`"../caixa-teia]"`
11669 // — the degenerate "I selected an unbalanced closing bracket
11670 // out of a glob character-class block" idiom that probes for
11671 // the cascade's last-byte handling on a value carrying only
11672 // the closing byte). Pinned separately from the open-bracket
11673 // shape so the gate's contract is "any `[` or `]` anywhere",
11674 // not single-byte coverage. Mirrors the peer
11675 // `validate_rejects_path_fonte_with_caminho_carrying_close_brace`
11676 // shape on the immediate-predecessor
11677 // `FonteCaminhoShellBraceExpansion` arm.
11678 let d = dep_with_fonte(DepSource::Path {
11679 caminho: "../caixa-teia]".into(),
11680 });
11681 let err = d.validate().unwrap_err();
11682 let DepError::FonteCaminhoShellBracketExpansion { byte, .. } = err else {
11683 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11684 };
11685 assert_eq!(byte, b']');
11686 }
11687
11688 #[test]
11689 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_bracket() {
11690 // Leading-position `[` shape (`"[caixa-teia]/build"` — the
11691 // canonical "I selected a `[caixa-teia]` TOML-table-header /
11692 // glob-character-class prefix out of an aligned config /
11693 // shell-history one-liner" idiom). Pinned separately from
11694 // the embedded-byte shape so the gate covers every position,
11695 // not only mid-path.
11696 let d = dep_with_fonte(DepSource::Path {
11697 caminho: "[caixa-teia]/build".into(),
11698 });
11699 let err = d.validate().unwrap_err();
11700 assert!(
11701 matches!(
11702 err,
11703 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11704 ),
11705 "got {err:?}",
11706 );
11707 }
11708
11709 #[test]
11710 fn validate_rejects_path_fonte_with_caminho_carrying_toml_inline_array() {
11711 // The canonical TOML inline-array / YAML flow-sequence
11712 // paste shape (`"../[\"a\", \"b\"]/caixa-teia"` — the
11713 // canonical "I copied a `features = [\"a\", \"b\"]` TOML
11714 // inline-array out of a sibling-Cargo manifest" cross-idiom
11715 // leak; the symmetric YAML flow-sequence form `paths: [/a,
11716 // /b]` paste-from-values.yaml shape carries the same
11717 // bracket pair). The arm fires on the first `[` encountered;
11718 // pinned so the gate's coverage extends from the bare-
11719 // bracket glob-character-class shape to the TOML / YAML /
11720 // JSON array-literal shape.
11721 let d = dep_with_fonte(DepSource::Path {
11722 caminho: "../[\"a\", \"b\"]/caixa-teia".into(),
11723 });
11724 let err = d.validate().unwrap_err();
11725 assert!(
11726 matches!(
11727 err,
11728 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11729 ),
11730 "got {err:?}",
11731 );
11732 }
11733
11734 #[test]
11735 fn validate_rejects_path_fonte_with_caminho_carrying_shell_test_builtin() {
11736 // The canonical POSIX `test` / `[` builtin command paste
11737 // shape (`"../[ -d caixa-teia ]"` — the `[ <expr> ]` shell-
11738 // script conditional every paste-from-shell-script idiom
11739 // carries; bash's `[[ <expr> ]]` extended-test grammar
11740 // would surface the same byte pair). The arm fires on the
11741 // first `[` encountered; pinned so the gate's coverage
11742 // extends from the embedded-glob-character-class shape to
11743 // the leading-`test`-builtin / extended-test form.
11744 let d = dep_with_fonte(DepSource::Path {
11745 caminho: "../[ -d caixa-teia ]".into(),
11746 });
11747 let err = d.validate().unwrap_err();
11748 assert!(
11749 matches!(
11750 err,
11751 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11752 ),
11753 "got {err:?}",
11754 );
11755 }
11756
11757 #[test]
11758 fn validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion() {
11759 // The positive-control pin: the gate targets only `[` /
11760 // `]`, never adjacent printable ASCII or POSIX-valid bytes.
11761 // The canonical relative POSIX path (`"../caixa-teia"`) and
11762 // a nested deeply-pathed variant with adjacent printable
11763 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11764 // to validate cleanly so the gate doesn't widen to a "no
11765 // printable punctuation anywhere" sweep that would defeat
11766 // the entire path-fonte author surface. Peer with
11767 // `validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion`
11768 // on the immediate-predecessor arm.
11769 let d = dep_with_fonte(DepSource::Path {
11770 caminho: "../caixa-teia/sub-dir.v2".into(),
11771 });
11772 d.validate().unwrap();
11773 }
11774
11775 #[test]
11776 fn fonte_caminho_shell_brace_expansion_fires_before_shell_bracket_expansion() {
11777 // Cascade pin on the immediate-predecessor arm: a value
11778 // carrying both `{` and `[` (`"../{a,b}[ch]"` — the
11779 // canonical "I pasted a brace-expansion fan followed by a
11780 // glob-character-class tail" footgun) routes through
11781 // `FonteCaminhoShellBraceExpansion` not
11782 // `FonteCaminhoShellBracketExpansion`. The brace-expansion
11783 // fan is the load-bearing root-cause edit on every
11784 // probe-as-both value because the bracket-class tail
11785 // typically rides on a prior brace-expansion expansion;
11786 // same cascade discipline every prior `:caminho` arm
11787 // establishes.
11788 let d = dep_with_fonte(DepSource::Path {
11789 caminho: "../{a,b}[ch]".into(),
11790 });
11791 let err = d.validate().unwrap_err();
11792 assert!(
11793 matches!(
11794 err,
11795 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11796 ),
11797 "got {err:?}",
11798 );
11799 }
11800
11801 #[test]
11802 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_bracket_expansion() {
11803 // Cascade pin on the upstream shell-subshell-grouping arm:
11804 // a value carrying both `(` and `[` (`"../(cd foo)/[ch]"` —
11805 // the canonical "I pasted a subshell-grouping followed by
11806 // a glob-character-class tail" footgun) routes through
11807 // `FonteCaminhoShellSubshellGrouping` not
11808 // `FonteCaminhoShellBracketExpansion`. The modern Bourne
11809 // `$(<cmd>)` command-substitution boundary is the load-
11810 // bearing axis on every probe-as-both value.
11811 let d = dep_with_fonte(DepSource::Path {
11812 caminho: "../(cd foo)/[ch]".into(),
11813 });
11814 let err = d.validate().unwrap_err();
11815 assert!(
11816 matches!(
11817 err,
11818 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11819 ),
11820 "got {err:?}",
11821 );
11822 }
11823
11824 #[test]
11825 fn fonte_caminho_shell_glob_fires_before_shell_bracket_expansion() {
11826 // Cascade pin on the upstream shell-glob arm: a value
11827 // carrying both `*` and `[` (`"../caixa-teia/*[ch]"` — the
11828 // canonical "I pasted a `*.[ch]` C-source-file glob whose
11829 // unbounded `*` precedes the bracket character-class"
11830 // footgun) routes through `FonteCaminhoShellGlob` not
11831 // `FonteCaminhoShellBracketExpansion`. The unbounded
11832 // pathname-expansion sentinel is the load-bearing root-
11833 // cause edit on every probe-as-both value — the unbounded
11834 // `*` carries the more aggressive expansion vector than
11835 // the bounded `[ch]` class, so the prior arm wins.
11836 let d = dep_with_fonte(DepSource::Path {
11837 caminho: "../caixa-teia/*[ch]".into(),
11838 });
11839 let err = d.validate().unwrap_err();
11840 assert!(
11841 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11842 "got {err:?}",
11843 );
11844 }
11845
11846 #[test]
11847 fn fonte_caminho_shell_command_substitution_fires_before_shell_bracket_expansion() {
11848 // Cascade pin on the upstream shell-command-substitution
11849 // arm: a value carrying both a backtick and `[`
11850 // (``"../`whoami`/[ch]"`` — the canonical "I pasted a
11851 // legacy-backtick command-substitution followed by a
11852 // glob-character-class tail" footgun) routes through
11853 // `FonteCaminhoShellCommandSubstitution` not
11854 // `FonteCaminhoShellBracketExpansion`. The CWE-78 shell-
11855 // command-injection vector is the load-bearing root-cause
11856 // edit on every probe-as-both value.
11857 let d = dep_with_fonte(DepSource::Path {
11858 caminho: "../`whoami`/[ch]".into(),
11859 });
11860 let err = d.validate().unwrap_err();
11861 assert!(
11862 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11863 "got {err:?}",
11864 );
11865 }
11866
11867 #[test]
11868 fn fonte_caminho_shell_background_fires_before_shell_bracket_expansion() {
11869 // Cascade pin on the upstream shell-background arm: a
11870 // value carrying both `&` and `[` (`"../caixa-teia & [ch]"`
11871 // — the canonical "I pasted a `cmd & [glob]` background-
11872 // launch + bracket-class chain" footgun) routes through
11873 // `FonteCaminhoShellBackground` not
11874 // `FonteCaminhoShellBracketExpansion`. The background-
11875 // launch tail is the load-bearing root-cause edit on
11876 // every probe-as-both value.
11877 let d = dep_with_fonte(DepSource::Path {
11878 caminho: "../caixa-teia & [ch]".into(),
11879 });
11880 let err = d.validate().unwrap_err();
11881 assert!(
11882 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11883 "got {err:?}",
11884 );
11885 }
11886
11887 #[test]
11888 fn fonte_caminho_shell_semicolon_fires_before_shell_bracket_expansion() {
11889 // Cascade pin on the upstream shell-semicolon arm: a value
11890 // carrying both `;` and `[` (`"../caixa-teia; [ch]"` — the
11891 // canonical sequential-cleanup + bracket-class paste
11892 // idiom) routes through `FonteCaminhoShellSemicolon` not
11893 // `FonteCaminhoShellBracketExpansion`. The sequential-
11894 // command-separator paste is the load-bearing root-cause
11895 // edit on every probe-as-both value.
11896 let d = dep_with_fonte(DepSource::Path {
11897 caminho: "../caixa-teia; [ch]".into(),
11898 });
11899 let err = d.validate().unwrap_err();
11900 assert!(
11901 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11902 "got {err:?}",
11903 );
11904 }
11905
11906 #[test]
11907 fn fonte_caminho_shell_pipe_fires_before_shell_bracket_expansion() {
11908 // Cascade pin on the upstream shell-pipe arm: a value
11909 // carrying both `|` and `[` (`"../caixa-teia | [tee]"` —
11910 // the canonical pipeline-to-bracket-class paste idiom)
11911 // routes through `FonteCaminhoShellPipe` not
11912 // `FonteCaminhoShellBracketExpansion`. The pipeline-tail
11913 // paste is the load-bearing root-cause edit on every
11914 // probe-as-both value.
11915 let d = dep_with_fonte(DepSource::Path {
11916 caminho: "../caixa-teia | [tee]".into(),
11917 });
11918 let err = d.validate().unwrap_err();
11919 assert!(
11920 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11921 "got {err:?}",
11922 );
11923 }
11924
11925 #[test]
11926 fn fonte_caminho_shell_redirection_fires_before_shell_bracket_expansion() {
11927 // Cascade pin on the upstream shell-redirection arm: a
11928 // value carrying both `>` and `[` (`"../caixa-teia>log
11929 // [ch]"` — the canonical "I pasted a `cmd > log [glob]`
11930 // redirect-plus-bracket chain" footgun) routes through
11931 // `FonteCaminhoShellRedirection` not
11932 // `FonteCaminhoShellBracketExpansion`. The input/output
11933 // redirection metachar carries the more self-locating
11934 // `byte` payload, so the prior arm wins on every
11935 // probe-as-both value.
11936 let d = dep_with_fonte(DepSource::Path {
11937 caminho: "../caixa-teia>log [ch]".into(),
11938 });
11939 let err = d.validate().unwrap_err();
11940 assert!(
11941 matches!(
11942 err,
11943 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11944 ),
11945 "got {err:?}",
11946 );
11947 }
11948
11949 #[test]
11950 fn fonte_caminho_backslash_fires_before_shell_bracket_expansion() {
11951 // Cascade pin on the upstream backslash arm: a value
11952 // carrying both `\` and `[` (`"..\caixa-teia\[ch]"` — the
11953 // canonical "I pasted a Windows-shell `cd ..\path\[glob]`
11954 // chain") routes through `FonteCaminhoBackslash` not
11955 // `FonteCaminhoShellBracketExpansion`. The cross-host-OS-
11956 // separator divergence is the load-bearing axis on every
11957 // probe-as-both value.
11958 let d = dep_with_fonte(DepSource::Path {
11959 caminho: "..\\caixa-teia\\[ch]".into(),
11960 });
11961 let err = d.validate().unwrap_err();
11962 assert!(
11963 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11964 "got {err:?}",
11965 );
11966 }
11967
11968 #[test]
11969 fn fonte_caminho_control_char_fires_before_shell_bracket_expansion() {
11970 // Cascade pin on the embedded-control-byte arm: a value
11971 // carrying both a control byte and `[` (`"../foo\n[ch]"` —
11972 // the canonical paste-from-multiline-doc footgun where a
11973 // newline landed mid-caminho between two paste fragments)
11974 // routes through `FonteCaminhoControlChar` not
11975 // `FonteCaminhoShellBracketExpansion`. The POSIX-syscall-
11976 // rejected-byte / NUL-`CString::new`-fail diagnostic is
11977 // the load-bearing axis on every value that probes
11978 // positive for both — mirrors the cascade discipline on
11979 // every prior arm.
11980 let d = dep_with_fonte(DepSource::Path {
11981 caminho: "../foo\n[ch]".into(),
11982 });
11983 let err = d.validate().unwrap_err();
11984 assert!(
11985 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11986 "got {err:?}",
11987 );
11988 }
11989
11990 #[test]
11991 fn fonte_caminho_absolute_fires_before_shell_bracket_expansion() {
11992 // Cascade pin on the load-bearing leading-byte arm: a
11993 // leading `/` value with embedded `[` (`"/etc/[ch]"`)
11994 // routes through `FonteCaminhoAbsolute` not
11995 // `FonteCaminhoShellBracketExpansion` — the host-layout-
11996 // leak diagnostic is the load-bearing axis, the bracket-
11997 // expansion byte is the secondary observation. Same
11998 // precedence logic as every prior leading-byte arm.
11999 let d = dep_with_fonte(DepSource::Path {
12000 caminho: "/etc/[ch]".into(),
12001 });
12002 let err = d.validate().unwrap_err();
12003 assert!(
12004 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12005 "got {err:?}",
12006 );
12007 }
12008
12009 #[test]
12010 fn fonte_caminho_var_expansion_fires_before_shell_bracket_expansion() {
12011 // Cascade pin on the upstream leading-`$` var-expansion
12012 // arm: a value carrying both a leading `$` and a `[`
12013 // (`"$DIR/[ch]"` — the canonical "I pasted a `$DIR` shell-
12014 // variable + bracket-class at the head of a sibling-
12015 // workspace path" footgun) routes through
12016 // `FonteCaminhoVarExpansion` not
12017 // `FonteCaminhoShellBracketExpansion`. The leading-byte
12018 // shell-variable-expansion is the more self-locating
12019 // diagnostic on values that probe as both — same
12020 // load-bearing-leading-byte cascade discipline every
12021 // prior `:caminho` arm establishes.
12022 let d = dep_with_fonte(DepSource::Path {
12023 caminho: "$DIR/[ch]".into(),
12024 });
12025 let err = d.validate().unwrap_err();
12026 assert!(
12027 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12028 "got {err:?}",
12029 );
12030 }
12031
12032 #[test]
12033 fn fonte_caminho_shell_bracket_expansion_fires_before_trailing_slash() {
12034 // Cascade pin on the immediate-successor arm: a value
12035 // carrying both `[` and a trailing `/` (`"../[a-z]/"` —
12036 // the canonical "I tab-completed a path that already had
12037 // a bracket-glob-character-class expansion tail" footgun)
12038 // routes through `FonteCaminhoShellBracketExpansion` not
12039 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
12040 // is the more semantic-locating axis (an author who
12041 // removes the `[` typically also drops the trailing
12042 // separator since both are paste-from-shell artifacts).
12043 let d = dep_with_fonte(DepSource::Path {
12044 caminho: "../[a-z]/".into(),
12045 });
12046 let err = d.validate().unwrap_err();
12047 assert!(
12048 matches!(
12049 err,
12050 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12051 ),
12052 "got {err:?}",
12053 );
12054 }
12055
12056 #[test]
12057 fn fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
12058 // Diagnostic-shape pin (peer with
12059 // `fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
12060 // on the closest two-byte peer arm): the error's Display
12061 // surfaces the offending `:nome`, the offending `:caminho`
12062 // verbatim, the offending byte's hex / character form, and
12063 // names the shell-bracket-expansion / glob-character-class
12064 // footgun explicitly so a `feira lint` run can render the
12065 // diagnostic without re-parsing.
12066 let d = dep_with_fonte(DepSource::Path {
12067 caminho: "../caixa-[a-z]/build".into(),
12068 });
12069 let rendered = d.validate().unwrap_err().to_string();
12070 assert!(
12071 rendered.contains("caixa-teia"),
12072 "diagnostic must name the offending dep: {rendered}",
12073 );
12074 assert!(
12075 rendered.contains("../caixa-[a-z]/build"),
12076 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12077 );
12078 assert!(
12079 rendered.contains("0x5b"),
12080 "diagnostic must surface the offending byte hex: {rendered:?}",
12081 );
12082 assert!(
12083 rendered.contains("bracket-expansion"),
12084 "diagnostic must name the shell-bracket-expansion footgun: {rendered:?}",
12085 );
12086 assert!(
12087 rendered.contains("glob-character-class"),
12088 "diagnostic must reference the POSIX glob-character-class vocabulary: \
12089 {rendered:?}",
12090 );
12091 }
12092
12093 #[test]
12094 fn validate_rejects_path_fonte_with_caminho_carrying_single_quote_grouping() {
12095 // The canonical paste-from-shell-history strong-quoted
12096 // sibling-workspace-path footgun: an author copies a
12097 // `cd '../caixa-teia'` shell-history one-liner whose strong-
12098 // quoting preserved the path across a whitespace paste
12099 // boundary and silently passed every prior arm
12100 // (`Path::is_absolute` false on `'..`, no control bytes, no
12101 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no
12102 // `*` / `?`, no `(` / `)`, no `{` / `}`, no `[` / `]`,
12103 // doesn't end in `/`; the leading-`$` f4efe9c
12104 // `FonteCaminhoVarExpansion` arm doesn't fire because the
12105 // value starts with `'` not `$`). The lacre embedded the
12106 // value verbatim, the resolver folded it through
12107 // `Path::join` looking for a literal `./'../caixa-teia'`
12108 // subdirectory, and the failure surfaced at resolve time
12109 // with a non-self-locating `No such file or directory`
12110 // error. The new arm moves the rejection to validate time
12111 // and names the offending dep + caminho + byte verbatim.
12112 // The arm fires on the first `'` encountered.
12113 let d = dep_with_fonte(DepSource::Path {
12114 caminho: "'../caixa-teia'".into(),
12115 });
12116 let err = d.validate().unwrap_err();
12117 let DepError::FonteCaminhoShellQuoteGrouping {
12118 nome,
12119 caminho,
12120 byte,
12121 } = err
12122 else {
12123 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
12124 };
12125 assert_eq!(nome, "caixa-teia");
12126 assert_eq!(caminho, "'../caixa-teia'");
12127 assert_eq!(byte, b'\'');
12128 }
12129
12130 #[test]
12131 fn validate_rejects_path_fonte_with_caminho_carrying_double_quote_grouping() {
12132 // The symmetric weak-quoted paste shape (`"\"../caixa-teia\""`
12133 // — the canonical paste-from-JSON-config / paste-from-YAML-
12134 // flow-scalar / paste-from-TOML-basic-string / paste-from-
12135 // tatara-lisp-string-literal cross-idiom leak). Pinned
12136 // separately from the single-quote shape so the gate's
12137 // contract is "any `'` or `\"` anywhere", not single-byte
12138 // coverage. Mirrors the peer
12139 // `validate_rejects_path_fonte_with_caminho_carrying_close_bracket`
12140 // shape on the immediate-predecessor
12141 // `FonteCaminhoShellBracketExpansion` arm.
12142 let d = dep_with_fonte(DepSource::Path {
12143 caminho: "\"../caixa-teia\"".into(),
12144 });
12145 let err = d.validate().unwrap_err();
12146 let DepError::FonteCaminhoShellQuoteGrouping { byte, .. } = err else {
12147 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
12148 };
12149 assert_eq!(byte, b'"');
12150 }
12151
12152 #[test]
12153 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_double_quote() {
12154 // Embedded-position `"` shape (`"../\"caixa-teia\""` — the
12155 // canonical "I pasted a JSON key-value pair fragment into
12156 // the middle of the path" idiom). Pinned separately from
12157 // the leading-byte shape so the gate covers every position,
12158 // not only leading.
12159 let d = dep_with_fonte(DepSource::Path {
12160 caminho: "../\"caixa-teia\"".into(),
12161 });
12162 let err = d.validate().unwrap_err();
12163 assert!(
12164 matches!(
12165 err,
12166 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
12167 ),
12168 "got {err:?}",
12169 );
12170 }
12171
12172 #[test]
12173 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_flow_scalar_paste() {
12174 // The canonical YAML double-quoted flow-scalar cross-idiom
12175 // leak shape (`"path: \"../caixa-teia\""` — the "I copied a
12176 // `path: \"...\"` YAML flow-scalar entry out of an aligned
12177 // values.yaml / K8s manifest and dropped it verbatim into
12178 // the `:caminho` slot including the `path: ` key prefix"
12179 // paste-idiom). The arm fires on the first `"` encountered;
12180 // pinned so the gate's coverage extends from the bare-quote
12181 // paste shape to the aligned-YAML-manifest cross-idiom-leak
12182 // shape.
12183 let d = dep_with_fonte(DepSource::Path {
12184 caminho: "path: \"../caixa-teia\"".into(),
12185 });
12186 let err = d.validate().unwrap_err();
12187 assert!(
12188 matches!(
12189 err,
12190 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
12191 ),
12192 "got {err:?}",
12193 );
12194 }
12195
12196 #[test]
12197 fn validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping() {
12198 // The positive-control pin: the gate targets only `'` /
12199 // `"`, never adjacent printable ASCII or POSIX-valid bytes.
12200 // The canonical relative POSIX path (`"../caixa-teia"`) and
12201 // a nested deeply-pathed variant with adjacent printable
12202 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12203 // to validate cleanly so the gate doesn't widen to a "no
12204 // printable punctuation anywhere" sweep that would defeat
12205 // the entire path-fonte author surface. Peer with
12206 // `validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion`
12207 // on the immediate-predecessor arm.
12208 let d = dep_with_fonte(DepSource::Path {
12209 caminho: "../caixa-teia/sub-dir.v2".into(),
12210 });
12211 d.validate().unwrap();
12212 }
12213
12214 #[test]
12215 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_quote_grouping() {
12216 // Cascade pin on the immediate-predecessor arm: a value
12217 // carrying both `[` and `'` (`"../[a-z]'x'"` — the canonical
12218 // "I pasted a glob-character-class followed by a strong-
12219 // quoted literal tail" footgun) routes through
12220 // `FonteCaminhoShellBracketExpansion` not
12221 // `FonteCaminhoShellQuoteGrouping`. The glob-character-class
12222 // expansion is the load-bearing root-cause edit on every
12223 // probe-as-both value; same cascade discipline every prior
12224 // `:caminho` arm establishes.
12225 let d = dep_with_fonte(DepSource::Path {
12226 caminho: "../[a-z]'x'".into(),
12227 });
12228 let err = d.validate().unwrap_err();
12229 assert!(
12230 matches!(
12231 err,
12232 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12233 ),
12234 "got {err:?}",
12235 );
12236 }
12237
12238 #[test]
12239 fn fonte_caminho_shell_brace_expansion_fires_before_shell_quote_grouping() {
12240 // Cascade pin on the upstream shell-brace-expansion arm: a
12241 // value carrying both `{` and `'` (`"../{a,b}'x'"` — the
12242 // canonical "I pasted a brace-expansion fan followed by a
12243 // strong-quoted literal tail" footgun) routes through
12244 // `FonteCaminhoShellBraceExpansion` not
12245 // `FonteCaminhoShellQuoteGrouping`. The brace-expansion fan
12246 // is the load-bearing root-cause edit on every probe-as-
12247 // both value.
12248 let d = dep_with_fonte(DepSource::Path {
12249 caminho: "../{a,b}'x'".into(),
12250 });
12251 let err = d.validate().unwrap_err();
12252 assert!(
12253 matches!(
12254 err,
12255 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12256 ),
12257 "got {err:?}",
12258 );
12259 }
12260
12261 #[test]
12262 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_quote_grouping() {
12263 // Cascade pin on the upstream shell-subshell-grouping arm:
12264 // a value carrying both `(` and `'` (`"../(cd foo)/'x'"` —
12265 // the canonical "I pasted a subshell-grouping followed by
12266 // a strong-quoted literal tail" footgun) routes through
12267 // `FonteCaminhoShellSubshellGrouping` not
12268 // `FonteCaminhoShellQuoteGrouping`. The modern Bourne
12269 // `$(<cmd>)` command-substitution boundary is the load-
12270 // bearing axis on every probe-as-both value.
12271 let d = dep_with_fonte(DepSource::Path {
12272 caminho: "../(cd foo)/'x'".into(),
12273 });
12274 let err = d.validate().unwrap_err();
12275 assert!(
12276 matches!(
12277 err,
12278 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12279 ),
12280 "got {err:?}",
12281 );
12282 }
12283
12284 #[test]
12285 fn fonte_caminho_shell_glob_fires_before_shell_quote_grouping() {
12286 // Cascade pin on the upstream shell-glob arm: a value
12287 // carrying both `*` and `'` (`"../caixa-teia/*'x'"` — the
12288 // canonical "I pasted a `*` unbounded pathname-expansion
12289 // followed by a strong-quoted literal tail" footgun) routes
12290 // through `FonteCaminhoShellGlob` not
12291 // `FonteCaminhoShellQuoteGrouping`. The unbounded pathname-
12292 // expansion sentinel is the load-bearing root-cause edit
12293 // on every probe-as-both value.
12294 let d = dep_with_fonte(DepSource::Path {
12295 caminho: "../caixa-teia/*'x'".into(),
12296 });
12297 let err = d.validate().unwrap_err();
12298 assert!(
12299 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12300 "got {err:?}",
12301 );
12302 }
12303
12304 #[test]
12305 fn fonte_caminho_shell_command_substitution_fires_before_shell_quote_grouping() {
12306 // Cascade pin on the upstream shell-command-substitution
12307 // arm: a value carrying both a backtick and `'`
12308 // (``"../`whoami`/'x'"`` — the canonical "I pasted a
12309 // legacy-backtick command-substitution followed by a
12310 // strong-quoted literal tail" footgun) routes through
12311 // `FonteCaminhoShellCommandSubstitution` not
12312 // `FonteCaminhoShellQuoteGrouping`. The CWE-78 shell-
12313 // command-injection vector is the load-bearing root-cause
12314 // edit on every probe-as-both value.
12315 let d = dep_with_fonte(DepSource::Path {
12316 caminho: "../`whoami`/'x'".into(),
12317 });
12318 let err = d.validate().unwrap_err();
12319 assert!(
12320 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12321 "got {err:?}",
12322 );
12323 }
12324
12325 #[test]
12326 fn fonte_caminho_shell_background_fires_before_shell_quote_grouping() {
12327 // Cascade pin on the upstream shell-background arm: a value
12328 // carrying both `&` and `'` (`"../caixa-teia & 'x'"` — the
12329 // canonical "I pasted a `cmd & 'literal'` background-launch
12330 // + quote chain" footgun) routes through
12331 // `FonteCaminhoShellBackground` not
12332 // `FonteCaminhoShellQuoteGrouping`. The background-launch
12333 // tail is the load-bearing root-cause edit on every
12334 // probe-as-both value.
12335 let d = dep_with_fonte(DepSource::Path {
12336 caminho: "../caixa-teia & 'x'".into(),
12337 });
12338 let err = d.validate().unwrap_err();
12339 assert!(
12340 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12341 "got {err:?}",
12342 );
12343 }
12344
12345 #[test]
12346 fn fonte_caminho_shell_semicolon_fires_before_shell_quote_grouping() {
12347 // Cascade pin on the upstream shell-semicolon arm: a value
12348 // carrying both `;` and `'` (`"../caixa-teia; 'x'"` — the
12349 // canonical sequential-cleanup + quote paste idiom) routes
12350 // through `FonteCaminhoShellSemicolon` not
12351 // `FonteCaminhoShellQuoteGrouping`. The sequential-command-
12352 // separator paste is the load-bearing root-cause edit on
12353 // every probe-as-both value.
12354 let d = dep_with_fonte(DepSource::Path {
12355 caminho: "../caixa-teia; 'x'".into(),
12356 });
12357 let err = d.validate().unwrap_err();
12358 assert!(
12359 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12360 "got {err:?}",
12361 );
12362 }
12363
12364 #[test]
12365 fn fonte_caminho_shell_pipe_fires_before_shell_quote_grouping() {
12366 // Cascade pin on the upstream shell-pipe arm: a value
12367 // carrying both `|` and `'` (`"../caixa-teia | 'x'"` — the
12368 // canonical pipeline-to-quoted-literal paste idiom) routes
12369 // through `FonteCaminhoShellPipe` not
12370 // `FonteCaminhoShellQuoteGrouping`. The pipeline-tail paste
12371 // is the load-bearing root-cause edit on every probe-as-
12372 // both value.
12373 let d = dep_with_fonte(DepSource::Path {
12374 caminho: "../caixa-teia | 'x'".into(),
12375 });
12376 let err = d.validate().unwrap_err();
12377 assert!(
12378 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12379 "got {err:?}",
12380 );
12381 }
12382
12383 #[test]
12384 fn fonte_caminho_shell_redirection_fires_before_shell_quote_grouping() {
12385 // Cascade pin on the upstream shell-redirection arm: a
12386 // value carrying both `>` and `'` (`"../caixa-teia>log 'x'"`
12387 // — the canonical "I pasted a `cmd > log 'literal'`
12388 // redirect-plus-quote chain" footgun) routes through
12389 // `FonteCaminhoShellRedirection` not
12390 // `FonteCaminhoShellQuoteGrouping`. The input/output
12391 // redirection metachar carries the more self-locating
12392 // `byte` payload, so the prior arm wins on every probe-as-
12393 // both value.
12394 let d = dep_with_fonte(DepSource::Path {
12395 caminho: "../caixa-teia>log 'x'".into(),
12396 });
12397 let err = d.validate().unwrap_err();
12398 assert!(
12399 matches!(
12400 err,
12401 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12402 ),
12403 "got {err:?}",
12404 );
12405 }
12406
12407 #[test]
12408 fn fonte_caminho_backslash_fires_before_shell_quote_grouping() {
12409 // Cascade pin on the upstream backslash arm: a value
12410 // carrying both `\` and `'` (`"..\caixa-teia\'x'"` — the
12411 // canonical "I pasted a Windows-shell `cd ..\path\'literal'`
12412 // chain" footgun) routes through `FonteCaminhoBackslash`
12413 // not `FonteCaminhoShellQuoteGrouping`. The cross-host-OS-
12414 // separator divergence is the load-bearing axis on every
12415 // probe-as-both value.
12416 let d = dep_with_fonte(DepSource::Path {
12417 caminho: "..\\caixa-teia\\'x'".into(),
12418 });
12419 let err = d.validate().unwrap_err();
12420 assert!(
12421 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12422 "got {err:?}",
12423 );
12424 }
12425
12426 #[test]
12427 fn fonte_caminho_control_char_fires_before_shell_quote_grouping() {
12428 // Cascade pin on the embedded-control-byte arm: a value
12429 // carrying both a control byte and `'` (`"../foo\n'x'"` —
12430 // the canonical paste-from-multiline-doc footgun where a
12431 // newline landed mid-caminho between two paste fragments)
12432 // routes through `FonteCaminhoControlChar` not
12433 // `FonteCaminhoShellQuoteGrouping`. The POSIX-syscall-
12434 // rejected-byte / NUL-`CString::new`-fail diagnostic is
12435 // the load-bearing axis on every value that probes
12436 // positive for both — mirrors the cascade discipline on
12437 // every prior arm.
12438 let d = dep_with_fonte(DepSource::Path {
12439 caminho: "../foo\n'x'".into(),
12440 });
12441 let err = d.validate().unwrap_err();
12442 assert!(
12443 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12444 "got {err:?}",
12445 );
12446 }
12447
12448 #[test]
12449 fn fonte_caminho_absolute_fires_before_shell_quote_grouping() {
12450 // Cascade pin on the load-bearing leading-byte arm: a
12451 // leading `/` value with embedded `'` (`"/etc/'x'"`) routes
12452 // through `FonteCaminhoAbsolute` not
12453 // `FonteCaminhoShellQuoteGrouping` — the host-layout-leak
12454 // diagnostic is the load-bearing axis, the quote byte is
12455 // the secondary observation. Same precedence logic as every
12456 // prior leading-byte arm.
12457 let d = dep_with_fonte(DepSource::Path {
12458 caminho: "/etc/'x'".into(),
12459 });
12460 let err = d.validate().unwrap_err();
12461 assert!(
12462 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12463 "got {err:?}",
12464 );
12465 }
12466
12467 #[test]
12468 fn fonte_caminho_var_expansion_fires_before_shell_quote_grouping() {
12469 // Cascade pin on the upstream leading-`$` var-expansion
12470 // arm: a value carrying both a leading `$` and a `'`
12471 // (`"$DIR/'x'"` — the canonical "I pasted a `$DIR` shell-
12472 // variable + quoted literal at the head of a sibling-
12473 // workspace path" footgun) routes through
12474 // `FonteCaminhoVarExpansion` not
12475 // `FonteCaminhoShellQuoteGrouping`. The leading-byte
12476 // shell-variable-expansion is the more self-locating
12477 // diagnostic on values that probe as both — same
12478 // load-bearing-leading-byte cascade discipline every
12479 // prior `:caminho` arm establishes.
12480 let d = dep_with_fonte(DepSource::Path {
12481 caminho: "$DIR/'x'".into(),
12482 });
12483 let err = d.validate().unwrap_err();
12484 assert!(
12485 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12486 "got {err:?}",
12487 );
12488 }
12489
12490 #[test]
12491 fn fonte_caminho_shell_quote_grouping_fires_before_trailing_slash() {
12492 // Cascade pin on the immediate-successor arm: a value
12493 // carrying both `'` and a trailing `/` (`"../'caixa-teia'/"`
12494 // — the canonical "I tab-completed a path whose strong-
12495 // quoted body already carried the quoting from a shell-
12496 // history paste" footgun) routes through
12497 // `FonteCaminhoShellQuoteGrouping` not
12498 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
12499 // is the more semantic-locating axis (an author who removes
12500 // the `'` typically also drops the trailing separator since
12501 // both are paste-from-shell artifacts).
12502 let d = dep_with_fonte(DepSource::Path {
12503 caminho: "../'caixa-teia'/".into(),
12504 });
12505 let err = d.validate().unwrap_err();
12506 assert!(
12507 matches!(
12508 err,
12509 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12510 ),
12511 "got {err:?}",
12512 );
12513 }
12514
12515 #[test]
12516 fn fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
12517 // Diagnostic-shape pin (peer with
12518 // `fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
12519 // on the closest two-byte peer arm): the error's Display
12520 // surfaces the offending `:nome`, the offending `:caminho`
12521 // verbatim, the offending byte's hex / character form, and
12522 // names the shell-quote-grouping / cross-config-DSL-string-
12523 // literal-delimiter footgun explicitly so a `feira lint`
12524 // run can render the diagnostic without re-parsing.
12525 let d = dep_with_fonte(DepSource::Path {
12526 caminho: "'../caixa-teia'".into(),
12527 });
12528 let rendered = d.validate().unwrap_err().to_string();
12529 assert!(
12530 rendered.contains("caixa-teia"),
12531 "diagnostic must name the offending dep: {rendered}",
12532 );
12533 assert!(
12534 rendered.contains("'../caixa-teia'"),
12535 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12536 );
12537 assert!(
12538 rendered.contains("0x27"),
12539 "diagnostic must surface the offending byte hex: {rendered:?}",
12540 );
12541 assert!(
12542 rendered.contains("quote-grouping"),
12543 "diagnostic must name the shell-quote-grouping footgun: {rendered:?}",
12544 );
12545 assert!(
12546 rendered.contains("string-literal"),
12547 "diagnostic must reference the cross-config-DSL string-literal-delimiter \
12548 vocabulary: {rendered:?}",
12549 );
12550 }
12551
12552 #[test]
12553 fn validate_rejects_path_fonte_with_caminho_carrying_shell_comment_lead() {
12554 // The canonical paste-from-shell-history-with-trailing-
12555 // annotation footgun: an author pastes a `cd ../caixa-teia
12556 // # legacy sibling` shell-history one-liner whose unquoted `#`
12557 // comment-lead separates the path from an inline annotation.
12558 // The POSIX shell trims the annotation to `../caixa-teia`
12559 // (POSIX.1-2017 §2.3 Token Recognition step 6), but
12560 // `Path::is_absolute` returns false on `..`, `#` is neither
12561 // a leading-byte sentinel nor a control byte nor `\` nor
12562 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` /
12563 // `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` /
12564 // `"`, and the value's last byte isn't `/` — so the value
12565 // silently passed every prior arm. The resolver folded the
12566 // value through `Path::join` looking for a literal
12567 // `./../caixa-teia # legacy sibling` subdirectory and the
12568 // failure surfaced at resolve time with a non-self-locating
12569 // `No such file or directory` error. The new arm moves the
12570 // rejection to validate time and names the offending dep +
12571 // caminho + byte verbatim.
12572 let d = dep_with_fonte(DepSource::Path {
12573 caminho: "../caixa-teia # legacy sibling".into(),
12574 });
12575 let err = d.validate().unwrap_err();
12576 let DepError::FonteCaminhoShellComment {
12577 nome,
12578 caminho,
12579 byte,
12580 } = err
12581 else {
12582 panic!("expected FonteCaminhoShellComment, got {err:?}");
12583 };
12584 assert_eq!(nome, "caixa-teia");
12585 assert_eq!(caminho, "../caixa-teia # legacy sibling");
12586 assert_eq!(byte, b'#');
12587 }
12588
12589 #[test]
12590 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_comment_paste() {
12591 // The symmetric YAML flow-scalar / values.yaml / K8s-manifest
12592 // cross-idiom-leak shape (`"../caixa-teia # pin"` — the
12593 // canonical "I copied a `path: ../caixa-teia # pin` YAML
12594 // scalar-plus-comment entry out of an aligned values.yaml and
12595 // dropped it verbatim into the `:caminho` slot" paste-idiom).
12596 // Pinned separately from the shell-history shape so the
12597 // gate's coverage extends from the single-space `#` shape to
12598 // the YAML-canonical double-space ` #` shape. YAML 1.2 §6.6
12599 // requires the `#` to be preceded by whitespace to lex as a
12600 // comment (bare `foo#bar` is a single scalar); the double-
12601 // space paste from an aligned manifest is the canonical
12602 // shape.
12603 let d = dep_with_fonte(DepSource::Path {
12604 caminho: "../caixa-teia # pin".into(),
12605 });
12606 let err = d.validate().unwrap_err();
12607 assert!(
12608 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12609 "got {err:?}",
12610 );
12611 }
12612
12613 #[test]
12614 fn validate_rejects_path_fonte_with_caminho_carrying_url_fragment_anchor() {
12615 // The URL-fragment-identifier paste shape
12616 // (`"../caixa-teia#readme"` — the canonical
12617 // paste-from-browser-address-bar permalink shape where the
12618 // browser preserved the `#anchor` tail on the copy). Pinned
12619 // separately from the whitespace-separated shell / YAML
12620 // comment shapes so the gate covers the unpadded RFC 3986
12621 // §3.5 fragment-delimiter position too, not only positions
12622 // preceded by unquoted whitespace. Peer with the immediate-
12623 // sibling `is_git_repo_url` arm on the `:fonte :repo` axis
12624 // (a68f818) which closes the same byte under the same URL-
12625 // fragment-identifier banner.
12626 let d = dep_with_fonte(DepSource::Path {
12627 caminho: "../caixa-teia#readme".into(),
12628 });
12629 let err = d.validate().unwrap_err();
12630 assert!(
12631 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12632 "got {err:?}",
12633 );
12634 }
12635
12636 #[test]
12637 fn validate_rejects_path_fonte_with_caminho_carrying_leading_shell_comment() {
12638 // Leading-position `#` shape (`"#../caixa-teia"` — the
12639 // "I copied a shell-comment-out entry from a commented-out
12640 // dep row" footgun). Pinned separately from the embedded
12641 // shapes so the gate covers every position, not only
12642 // whitespace-preceded / mid-value.
12643 let d = dep_with_fonte(DepSource::Path {
12644 caminho: "#../caixa-teia".into(),
12645 });
12646 let err = d.validate().unwrap_err();
12647 assert!(
12648 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12649 "got {err:?}",
12650 );
12651 }
12652
12653 #[test]
12654 fn validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment() {
12655 // The positive-control pin: the gate targets only `#`,
12656 // never adjacent printable ASCII or POSIX-valid bytes. The
12657 // canonical relative POSIX path (`"../caixa-teia"`) and a
12658 // nested deeply-pathed variant with adjacent printable
12659 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12660 // to validate cleanly so the gate doesn't widen to a "no
12661 // printable punctuation anywhere" sweep that would defeat
12662 // the entire path-fonte author surface. Peer with
12663 // `validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping`
12664 // on the immediate-predecessor arm.
12665 let d = dep_with_fonte(DepSource::Path {
12666 caminho: "../caixa-teia/sub-dir.v2".into(),
12667 });
12668 d.validate().unwrap();
12669 }
12670
12671 #[test]
12672 fn fonte_caminho_shell_quote_grouping_fires_before_shell_comment() {
12673 // Cascade pin on the immediate-predecessor arm: a value
12674 // carrying both `'` and `#` (`"../'x'#pin"` — the canonical
12675 // "I pasted a strong-quoted literal followed by a URL-
12676 // fragment permalink tail" footgun) routes through
12677 // `FonteCaminhoShellQuoteGrouping` not
12678 // `FonteCaminhoShellComment`. The shell-string-literal-
12679 // delimiter is the load-bearing root-cause edit on every
12680 // probe-as-both value; same cascade discipline every prior
12681 // `:caminho` arm establishes.
12682 let d = dep_with_fonte(DepSource::Path {
12683 caminho: "../'x'#pin".into(),
12684 });
12685 let err = d.validate().unwrap_err();
12686 assert!(
12687 matches!(
12688 err,
12689 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12690 ),
12691 "got {err:?}",
12692 );
12693 }
12694
12695 #[test]
12696 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_comment() {
12697 // Cascade pin on the upstream shell-bracket-expansion arm:
12698 // a value carrying both `[` and `#` (`"../[a-z]#pin"` — the
12699 // canonical "I pasted a glob-character-class followed by a
12700 // URL-fragment tail" footgun) routes through
12701 // `FonteCaminhoShellBracketExpansion` not
12702 // `FonteCaminhoShellComment`. The glob-character-class
12703 // expansion is the load-bearing root-cause edit on every
12704 // probe-as-both value.
12705 let d = dep_with_fonte(DepSource::Path {
12706 caminho: "../[a-z]#pin".into(),
12707 });
12708 let err = d.validate().unwrap_err();
12709 assert!(
12710 matches!(
12711 err,
12712 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12713 ),
12714 "got {err:?}",
12715 );
12716 }
12717
12718 #[test]
12719 fn fonte_caminho_shell_brace_expansion_fires_before_shell_comment() {
12720 // Cascade pin on the upstream shell-brace-expansion arm: a
12721 // value carrying both `{` and `#` (`"../{a,b}#pin"` — the
12722 // canonical "I pasted a brace-expansion fan followed by a
12723 // URL-fragment tail" footgun) routes through
12724 // `FonteCaminhoShellBraceExpansion` not
12725 // `FonteCaminhoShellComment`. The brace-expansion fan is the
12726 // load-bearing root-cause edit on every probe-as-both value.
12727 let d = dep_with_fonte(DepSource::Path {
12728 caminho: "../{a,b}#pin".into(),
12729 });
12730 let err = d.validate().unwrap_err();
12731 assert!(
12732 matches!(
12733 err,
12734 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12735 ),
12736 "got {err:?}",
12737 );
12738 }
12739
12740 #[test]
12741 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_comment() {
12742 // Cascade pin on the upstream shell-subshell-grouping arm:
12743 // a value carrying both `(` and `#` (`"../(cd foo)#pin"` —
12744 // the canonical "I pasted a subshell-grouping followed by a
12745 // URL-fragment tail" footgun) routes through
12746 // `FonteCaminhoShellSubshellGrouping` not
12747 // `FonteCaminhoShellComment`. The modern Bourne `$(<cmd>)`
12748 // command-substitution boundary is the load-bearing axis on
12749 // every probe-as-both value.
12750 let d = dep_with_fonte(DepSource::Path {
12751 caminho: "../(cd foo)#pin".into(),
12752 });
12753 let err = d.validate().unwrap_err();
12754 assert!(
12755 matches!(
12756 err,
12757 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12758 ),
12759 "got {err:?}",
12760 );
12761 }
12762
12763 #[test]
12764 fn fonte_caminho_shell_glob_fires_before_shell_comment() {
12765 // Cascade pin on the upstream shell-glob arm: a value
12766 // carrying both `*` and `#` (`"../caixa-teia/*#pin"` — the
12767 // canonical "I pasted a `*` unbounded pathname-expansion
12768 // followed by a URL-fragment tail" footgun) routes through
12769 // `FonteCaminhoShellGlob` not `FonteCaminhoShellComment`.
12770 // The unbounded pathname-expansion sentinel is the load-
12771 // bearing root-cause edit on every probe-as-both value.
12772 let d = dep_with_fonte(DepSource::Path {
12773 caminho: "../caixa-teia/*#pin".into(),
12774 });
12775 let err = d.validate().unwrap_err();
12776 assert!(
12777 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12778 "got {err:?}",
12779 );
12780 }
12781
12782 #[test]
12783 fn fonte_caminho_shell_command_substitution_fires_before_shell_comment() {
12784 // Cascade pin on the upstream shell-command-substitution
12785 // arm: a value carrying both a backtick and `#`
12786 // (``"../`whoami`#pin"`` — the canonical "I pasted a
12787 // legacy-backtick command-substitution followed by a URL-
12788 // fragment tail" footgun) routes through
12789 // `FonteCaminhoShellCommandSubstitution` not
12790 // `FonteCaminhoShellComment`. The CWE-78 shell-command-
12791 // injection vector is the load-bearing root-cause edit on
12792 // every probe-as-both value.
12793 let d = dep_with_fonte(DepSource::Path {
12794 caminho: "../`whoami`#pin".into(),
12795 });
12796 let err = d.validate().unwrap_err();
12797 assert!(
12798 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12799 "got {err:?}",
12800 );
12801 }
12802
12803 #[test]
12804 fn fonte_caminho_shell_background_fires_before_shell_comment() {
12805 // Cascade pin on the upstream shell-background arm: a value
12806 // carrying both `&` and `#` (`"../caixa-teia&pin#tail"` —
12807 // the canonical "I pasted a `cmd &` background-launch
12808 // followed by a URL-fragment tail" footgun) routes through
12809 // `FonteCaminhoShellBackground` not
12810 // `FonteCaminhoShellComment`. The background-launch tail is
12811 // the load-bearing root-cause edit on every probe-as-both
12812 // value.
12813 let d = dep_with_fonte(DepSource::Path {
12814 caminho: "../caixa-teia&pin#tail".into(),
12815 });
12816 let err = d.validate().unwrap_err();
12817 assert!(
12818 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12819 "got {err:?}",
12820 );
12821 }
12822
12823 #[test]
12824 fn fonte_caminho_shell_semicolon_fires_before_shell_comment() {
12825 // Cascade pin on the upstream shell-semicolon arm: a value
12826 // carrying both `;` and `#` (`"../caixa-teia;pin#tail"` —
12827 // the canonical sequential-cleanup + URL-fragment paste
12828 // idiom) routes through `FonteCaminhoShellSemicolon` not
12829 // `FonteCaminhoShellComment`. The sequential-command-
12830 // separator paste is the load-bearing root-cause edit on
12831 // every probe-as-both value.
12832 let d = dep_with_fonte(DepSource::Path {
12833 caminho: "../caixa-teia;pin#tail".into(),
12834 });
12835 let err = d.validate().unwrap_err();
12836 assert!(
12837 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12838 "got {err:?}",
12839 );
12840 }
12841
12842 #[test]
12843 fn fonte_caminho_shell_pipe_fires_before_shell_comment() {
12844 // Cascade pin on the upstream shell-pipe arm: a value
12845 // carrying both `|` and `#` (`"../caixa-teia|pin#tail"` —
12846 // the canonical pipeline-to-URL-fragment paste idiom) routes
12847 // through `FonteCaminhoShellPipe` not
12848 // `FonteCaminhoShellComment`. The pipeline-tail paste is
12849 // the load-bearing root-cause edit on every probe-as-both
12850 // value.
12851 let d = dep_with_fonte(DepSource::Path {
12852 caminho: "../caixa-teia|pin#tail".into(),
12853 });
12854 let err = d.validate().unwrap_err();
12855 assert!(
12856 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12857 "got {err:?}",
12858 );
12859 }
12860
12861 #[test]
12862 fn fonte_caminho_shell_redirection_fires_before_shell_comment() {
12863 // Cascade pin on the upstream shell-redirection arm: a
12864 // value carrying both `>` and `#` (`"../caixa-teia>log#pin"`
12865 // — the canonical "I pasted a `cmd > log` redirect followed
12866 // by a URL-fragment tail" footgun) routes through
12867 // `FonteCaminhoShellRedirection` not
12868 // `FonteCaminhoShellComment`. The input/output redirection
12869 // metachar carries the more self-locating `byte` payload,
12870 // so the prior arm wins on every probe-as-both value.
12871 let d = dep_with_fonte(DepSource::Path {
12872 caminho: "../caixa-teia>log#pin".into(),
12873 });
12874 let err = d.validate().unwrap_err();
12875 assert!(
12876 matches!(
12877 err,
12878 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12879 ),
12880 "got {err:?}",
12881 );
12882 }
12883
12884 #[test]
12885 fn fonte_caminho_backslash_fires_before_shell_comment() {
12886 // Cascade pin on the upstream backslash arm: a value
12887 // carrying both `\` and `#` (`"..\caixa-teia#pin"` — the
12888 // canonical "I pasted a Windows-shell path followed by a
12889 // URL-fragment tail" footgun) routes through
12890 // `FonteCaminhoBackslash` not `FonteCaminhoShellComment`.
12891 // The cross-host-OS-separator divergence is the load-
12892 // bearing axis on every probe-as-both value.
12893 let d = dep_with_fonte(DepSource::Path {
12894 caminho: "..\\caixa-teia#pin".into(),
12895 });
12896 let err = d.validate().unwrap_err();
12897 assert!(
12898 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12899 "got {err:?}",
12900 );
12901 }
12902
12903 #[test]
12904 fn fonte_caminho_control_char_fires_before_shell_comment() {
12905 // Cascade pin on the embedded-control-byte arm: a value
12906 // carrying both a control byte and `#` (`"../foo\n#pin"` —
12907 // the canonical paste-from-multiline-doc footgun where a
12908 // newline landed mid-caminho between the path and an
12909 // annotation) routes through `FonteCaminhoControlChar` not
12910 // `FonteCaminhoShellComment`. The POSIX-syscall-rejected-
12911 // byte diagnostic is the load-bearing axis on every value
12912 // that probes positive for both — mirrors the cascade
12913 // discipline on every prior arm.
12914 let d = dep_with_fonte(DepSource::Path {
12915 caminho: "../foo\n#pin".into(),
12916 });
12917 let err = d.validate().unwrap_err();
12918 assert!(
12919 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12920 "got {err:?}",
12921 );
12922 }
12923
12924 #[test]
12925 fn fonte_caminho_absolute_fires_before_shell_comment() {
12926 // Cascade pin on the load-bearing leading-byte arm: a
12927 // leading `/` value with embedded `#` (`"/etc/foo#pin"`)
12928 // routes through `FonteCaminhoAbsolute` not
12929 // `FonteCaminhoShellComment` — the host-layout-leak
12930 // diagnostic is the load-bearing axis, the fragment byte is
12931 // the secondary observation. Same precedence logic as every
12932 // prior leading-byte arm.
12933 let d = dep_with_fonte(DepSource::Path {
12934 caminho: "/etc/foo#pin".into(),
12935 });
12936 let err = d.validate().unwrap_err();
12937 assert!(
12938 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12939 "got {err:?}",
12940 );
12941 }
12942
12943 #[test]
12944 fn fonte_caminho_var_expansion_fires_before_shell_comment() {
12945 // Cascade pin on the upstream leading-`$` var-expansion
12946 // arm: a value carrying both a leading `$` and a `#`
12947 // (`"$DIR/foo#pin"` — the canonical "I pasted a `$DIR`
12948 // shell-variable at the head of a sibling-workspace path
12949 // followed by a URL-fragment tail" footgun) routes through
12950 // `FonteCaminhoVarExpansion` not `FonteCaminhoShellComment`.
12951 // The leading-byte shell-variable-expansion is the more
12952 // self-locating diagnostic on values that probe as both.
12953 let d = dep_with_fonte(DepSource::Path {
12954 caminho: "$DIR/foo#pin".into(),
12955 });
12956 let err = d.validate().unwrap_err();
12957 assert!(
12958 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12959 "got {err:?}",
12960 );
12961 }
12962
12963 #[test]
12964 fn fonte_caminho_shell_comment_fires_before_trailing_slash() {
12965 // Cascade pin on the immediate-successor arm: a value
12966 // carrying both `#` and a trailing `/`
12967 // (`"../caixa-teia#pin/"` — the canonical "I tab-completed
12968 // a URL-fragment-carrying path" footgun) routes through
12969 // `FonteCaminhoShellComment` not
12970 // `FonteCaminhoTrailingSlash`. The embedded fragment /
12971 // comment-lead byte is the more semantic-locating axis (an
12972 // author who removes the `#pin` fragment typically also
12973 // drops the trailing separator since both are paste-from-
12974 // URL / paste-from-shell-tab-completion artifacts).
12975 let d = dep_with_fonte(DepSource::Path {
12976 caminho: "../caixa-teia#pin/".into(),
12977 });
12978 let err = d.validate().unwrap_err();
12979 assert!(
12980 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. },),
12981 "got {err:?}",
12982 );
12983 }
12984
12985 #[test]
12986 fn fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte() {
12987 // Diagnostic-shape pin (peer with
12988 // `fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
12989 // on the immediate-predecessor arm): the error's Display
12990 // surfaces the offending `:nome`, the offending `:caminho`
12991 // verbatim, the offending byte's hex / character form, and
12992 // names the shell-comment / URL-fragment-identifier /
12993 // YAML-comment cross-config-DSL footgun explicitly so a
12994 // `feira lint` run can render the diagnostic without
12995 // re-parsing.
12996 let d = dep_with_fonte(DepSource::Path {
12997 caminho: "../caixa-teia#readme".into(),
12998 });
12999 let rendered = d.validate().unwrap_err().to_string();
13000 assert!(
13001 rendered.contains("caixa-teia"),
13002 "diagnostic must name the offending dep: {rendered}",
13003 );
13004 assert!(
13005 rendered.contains("../caixa-teia#readme"),
13006 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13007 );
13008 assert!(
13009 rendered.contains("0x23"),
13010 "diagnostic must surface the offending byte hex: {rendered:?}",
13011 );
13012 assert!(
13013 rendered.contains("shell-comment") || rendered.contains("comment-lead"),
13014 "diagnostic must name the shell-comment footgun: {rendered:?}",
13015 );
13016 assert!(
13017 rendered.contains("fragment") || rendered.contains("URL-fragment"),
13018 "diagnostic must reference the URL-fragment-identifier vocabulary: \
13019 {rendered:?}",
13020 );
13021 }
13022
13023 #[test]
13024 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_space() {
13025 // The canonical paste-from-browser-address-bar percent-
13026 // encoded-space footgun: an author copies `../caixa%20teia`
13027 // out of a URL-encoded README hyperlink / browser address
13028 // bar / percent-encoded permalink expecting `%20` to decode
13029 // to a literal space at the filesystem layer. POSIX
13030 // `std::path::Path` treats `%` as a literal path-component
13031 // byte, so `Path::join` looks for a literal
13032 // `./../caixa%20teia` subdirectory. `Path::is_absolute`
13033 // returns false on `..`, `%` is neither a leading-byte
13034 // sentinel nor a control byte nor `\` nor `<` / `>` nor
13035 // `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` /
13036 // `)` nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`,
13037 // and the value's last byte isn't `/` — so the value
13038 // silently passed every prior arm. The new arm moves the
13039 // rejection to validate time and names the offending dep +
13040 // caminho + byte verbatim.
13041 let d = dep_with_fonte(DepSource::Path {
13042 caminho: "../caixa%20teia".into(),
13043 });
13044 let err = d.validate().unwrap_err();
13045 let DepError::FonteCaminhoUrlPercentEncoding {
13046 nome,
13047 caminho,
13048 byte,
13049 } = err
13050 else {
13051 panic!("expected FonteCaminhoUrlPercentEncoding, got {err:?}");
13052 };
13053 assert_eq!(nome, "caixa-teia");
13054 assert_eq!(caminho, "../caixa%20teia");
13055 assert_eq!(byte, b'%');
13056 }
13057
13058 #[test]
13059 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_slash() {
13060 // The over-encoded path-separator shape (`"../caixa%2Fteia"`
13061 // intending the `%2F` as the URL encoding of `/`) locks a
13062 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
13063 // the byte-identical `path:../caixa/teia` form. Pinned
13064 // separately from the space-encoded shape so the gate's
13065 // coverage extends past the single canonical `%20` example
13066 // to any two-hex-digit percent-encoded sequence.
13067 let d = dep_with_fonte(DepSource::Path {
13068 caminho: "../caixa%2Fteia".into(),
13069 });
13070 let err = d.validate().unwrap_err();
13071 assert!(
13072 matches!(
13073 err,
13074 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13075 ),
13076 "got {err:?}",
13077 );
13078 }
13079
13080 #[test]
13081 fn validate_rejects_path_fonte_with_caminho_carrying_lone_percent() {
13082 // The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
13083 // where `%` isn't followed by two hex digits) — every
13084 // WHATWG-conformant URL parser rejects the value at parse
13085 // time per RFC 3986 §2.1, but the byte would silently ride
13086 // into the lacre before the resolver subprocess crosses the
13087 // URL-parser boundary. Pinned separately from the well-
13088 // formed `%HH` shapes so the gate covers every percent-
13089 // occurrence, not only strictly-conformant escapes.
13090 let d = dep_with_fonte(DepSource::Path {
13091 caminho: "../caixa-teia%foo".into(),
13092 });
13093 let err = d.validate().unwrap_err();
13094 assert!(
13095 matches!(
13096 err,
13097 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13098 ),
13099 "got {err:?}",
13100 );
13101 }
13102
13103 #[test]
13104 fn validate_rejects_path_fonte_with_caminho_carrying_leading_yaml_directive() {
13105 // The YAML-directive-lead paste shape (`"%YAML/../caixa-teia"`
13106 // — the canonical paste-from-top-of-doc YAML directive
13107 // block cross-idiom leak per YAML 1.2 §6.8.1). Pinned
13108 // separately from embedded shapes so the gate covers the
13109 // leading-position `%` too, not only mid-value occurrences.
13110 let d = dep_with_fonte(DepSource::Path {
13111 caminho: "%YAML/../caixa-teia".into(),
13112 });
13113 let err = d.validate().unwrap_err();
13114 assert!(
13115 matches!(
13116 err,
13117 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13118 ),
13119 "got {err:?}",
13120 );
13121 }
13122
13123 #[test]
13124 fn validate_rejects_path_fonte_with_caminho_carrying_printf_format_specifier() {
13125 // The printf-format-specifier paste shape
13126 // (`"../caixa-%s-teia"` — the canonical paste-from-shell-
13127 // diagnostic-one-liner `printf "path=%s\n" ...` idiom, CWE-
13128 // 134 format-string-injection vector). Pinned separately
13129 // from the URL-encoding shapes so the gate's rationale
13130 // extends past the RFC 3986 axis to the C / POSIX printf
13131 // format-directive-lead axis.
13132 let d = dep_with_fonte(DepSource::Path {
13133 caminho: "../caixa-%s-teia".into(),
13134 });
13135 let err = d.validate().unwrap_err();
13136 assert!(
13137 matches!(
13138 err,
13139 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13140 ),
13141 "got {err:?}",
13142 );
13143 }
13144
13145 #[test]
13146 fn validate_accepts_path_fonte_with_caminho_carrying_no_percent() {
13147 // The positive-control pin: the gate targets only `%`,
13148 // never adjacent printable ASCII or POSIX-valid bytes. The
13149 // canonical relative POSIX path (`"../caixa-teia"`) and a
13150 // nested deeply-pathed variant with adjacent printable
13151 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
13152 // to validate cleanly so the gate doesn't widen to a "no
13153 // printable punctuation anywhere" sweep that would defeat
13154 // the entire path-fonte author surface. Peer with
13155 // `validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment`
13156 // on the immediate-predecessor arm.
13157 let d = dep_with_fonte(DepSource::Path {
13158 caminho: "../caixa-teia/sub-dir.v2".into(),
13159 });
13160 d.validate().unwrap();
13161 }
13162
13163 #[test]
13164 fn fonte_caminho_shell_comment_fires_before_url_percent_encoding() {
13165 // Cascade pin on the immediate-predecessor arm: a value
13166 // carrying both `#` and `%` (`"../caixa-teia#pin%20"` — the
13167 // canonical "I pasted a URL-fragment permalink followed by a
13168 // percent-encoded space tail" footgun) routes through
13169 // `FonteCaminhoShellComment` not
13170 // `FonteCaminhoUrlPercentEncoding`. The URL-fragment-
13171 // identifier is the load-bearing downstream-truncation edit
13172 // on every probe-as-both value; same cascade discipline
13173 // every prior `:caminho` arm establishes.
13174 let d = dep_with_fonte(DepSource::Path {
13175 caminho: "../caixa-teia#pin%20".into(),
13176 });
13177 let err = d.validate().unwrap_err();
13178 assert!(
13179 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
13180 "got {err:?}",
13181 );
13182 }
13183
13184 #[test]
13185 fn fonte_caminho_shell_quote_grouping_fires_before_url_percent_encoding() {
13186 // Cascade pin on the upstream shell-quote-grouping arm: a
13187 // value carrying both `'` and `%` (`"../'x'%20teia"` — the
13188 // canonical "I pasted a strong-quoted literal followed by
13189 // a percent-encoded space" footgun) routes through
13190 // `FonteCaminhoShellQuoteGrouping` not
13191 // `FonteCaminhoUrlPercentEncoding`. The shell-string-
13192 // literal-delimiter is the load-bearing root-cause edit on
13193 // every probe-as-both value.
13194 let d = dep_with_fonte(DepSource::Path {
13195 caminho: "../'x'%20teia".into(),
13196 });
13197 let err = d.validate().unwrap_err();
13198 assert!(
13199 matches!(
13200 err,
13201 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
13202 ),
13203 "got {err:?}",
13204 );
13205 }
13206
13207 #[test]
13208 fn fonte_caminho_backslash_fires_before_url_percent_encoding() {
13209 // Cascade pin on the upstream backslash arm: a value
13210 // carrying both `\` and `%` (`"..\\caixa%20teia"` — the
13211 // canonical "I pasted a Windows-shell path followed by a
13212 // percent-encoded space" footgun) routes through
13213 // `FonteCaminhoBackslash` not
13214 // `FonteCaminhoUrlPercentEncoding`. The cross-host-OS-
13215 // separator divergence is the load-bearing root-cause edit
13216 // on every probe-as-both value.
13217 let d = dep_with_fonte(DepSource::Path {
13218 caminho: "..\\caixa%20teia".into(),
13219 });
13220 let err = d.validate().unwrap_err();
13221 assert!(
13222 matches!(err, DepError::FonteCaminhoBackslash { .. }),
13223 "got {err:?}",
13224 );
13225 }
13226
13227 #[test]
13228 fn fonte_caminho_control_char_fires_before_url_percent_encoding() {
13229 // Cascade pin on the upstream control-char arm: a value
13230 // carrying both a NUL byte and `%` (`"../caixa\0%20teia"` —
13231 // the canonical "I pasted a paste-from-binary-blob path
13232 // followed by a percent-encoded space" footgun) routes
13233 // through `FonteCaminhoControlChar` not
13234 // `FonteCaminhoUrlPercentEncoding`. The POSIX-syscall-
13235 // rejected byte is the load-bearing root-cause edit on
13236 // every probe-as-both value.
13237 let d = dep_with_fonte(DepSource::Path {
13238 caminho: "../caixa\0%20teia".into(),
13239 });
13240 let err = d.validate().unwrap_err();
13241 assert!(
13242 matches!(err, DepError::FonteCaminhoControlChar { byte: 0x00, .. },),
13243 "got {err:?}",
13244 );
13245 }
13246
13247 #[test]
13248 fn fonte_caminho_absolute_fires_before_url_percent_encoding() {
13249 // Cascade pin on the upstream absolute-path arm: a value
13250 // that's both absolute and carries `%` (`"/etc/passwd%20"`
13251 // — the canonical "I pasted an absolute path with a
13252 // percent-encoded space tail" footgun) routes through
13253 // `FonteCaminhoAbsolute` not
13254 // `FonteCaminhoUrlPercentEncoding`. The host-layout-leak is
13255 // the load-bearing root-cause edit on every probe-as-both
13256 // value.
13257 let d = dep_with_fonte(DepSource::Path {
13258 caminho: "/etc/passwd%20".into(),
13259 });
13260 let err = d.validate().unwrap_err();
13261 assert!(
13262 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
13263 "got {err:?}",
13264 );
13265 }
13266
13267 #[test]
13268 fn fonte_caminho_var_expansion_fires_before_url_percent_encoding() {
13269 // Cascade pin on the upstream var-expansion arm: a value
13270 // starting with `$` and carrying `%` (`"$HOME/caixa%20teia"`
13271 // — the canonical "I pasted a `$HOME`-rooted path with a
13272 // percent-encoded space" footgun) routes through
13273 // `FonteCaminhoVarExpansion` not
13274 // `FonteCaminhoUrlPercentEncoding`. The shell-variable-
13275 // expansion is the load-bearing root-cause edit on every
13276 // probe-as-both value.
13277 let d = dep_with_fonte(DepSource::Path {
13278 caminho: "$HOME/caixa%20teia".into(),
13279 });
13280 let err = d.validate().unwrap_err();
13281 assert!(
13282 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
13283 "got {err:?}",
13284 );
13285 }
13286
13287 #[test]
13288 fn fonte_caminho_url_percent_encoding_fires_before_trailing_slash() {
13289 // Cascade pin on the immediate-successor arm: a value
13290 // carrying both `%` and a trailing `/`
13291 // (`"../caixa%20teia/"` — the canonical "I tab-completed a
13292 // percent-encoded-space-carrying path" footgun) routes
13293 // through `FonteCaminhoUrlPercentEncoding` not
13294 // `FonteCaminhoTrailingSlash`. The embedded percent-
13295 // encoding-escape byte is the more semantic-locating axis
13296 // (an author who decodes the `%20` to a literal space is
13297 // likely to also tab-strip the trailing separator since
13298 // both are paste-from-URL / paste-from-shell-tab-completion
13299 // artifacts).
13300 let d = dep_with_fonte(DepSource::Path {
13301 caminho: "../caixa%20teia/".into(),
13302 });
13303 let err = d.validate().unwrap_err();
13304 assert!(
13305 matches!(
13306 err,
13307 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13308 ),
13309 "got {err:?}",
13310 );
13311 }
13312
13313 #[test]
13314 fn fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte() {
13315 // Diagnostic-shape pin (peer with
13316 // `fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte`
13317 // on the immediate-predecessor arm): the error's Display
13318 // surfaces the offending `:nome`, the offending `:caminho`
13319 // verbatim, the offending byte's hex / character form, and
13320 // names the URL-percent-encoding-escape / printf-format-
13321 // specifier footgun explicitly so a `feira lint` run can
13322 // render the diagnostic without re-parsing.
13323 let d = dep_with_fonte(DepSource::Path {
13324 caminho: "../caixa%20teia".into(),
13325 });
13326 let rendered = d.validate().unwrap_err().to_string();
13327 assert!(
13328 rendered.contains("caixa-teia"),
13329 "diagnostic must name the offending dep: {rendered}",
13330 );
13331 assert!(
13332 rendered.contains("../caixa%20teia"),
13333 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13334 );
13335 assert!(
13336 rendered.contains("0x25"),
13337 "diagnostic must surface the offending byte hex: {rendered:?}",
13338 );
13339 assert!(
13340 rendered.contains("percent-encoding") || rendered.contains("percent-encoded"),
13341 "diagnostic must name the URL-percent-encoding-escape footgun: {rendered:?}",
13342 );
13343 assert!(
13344 rendered.contains("printf") || rendered.contains("format-specifier"),
13345 "diagnostic must reference the printf-format-specifier vocabulary: \
13346 {rendered:?}",
13347 );
13348 }
13349
13350 #[test]
13351 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_var_expansion() {
13352 // The canonical embedded-`$` shell-variable-expansion paste
13353 // shape (`"../foo$HOME/bar"` — an author copies a partially-
13354 // substituted shell one-liner where the leading segment is a
13355 // literal `../foo` while the mid segment carries the un-
13356 // substituted `$HOME` template). The leading-`$` position is
13357 // already gated by the f4efe9c leading-byte arm which routes
13358 // through `FonteCaminhoVarExpansion`; this arm closes the
13359 // last positional gap on `$` — every position on the axis is
13360 // structurally rejected.
13361 let d = dep_with_fonte(DepSource::Path {
13362 caminho: "../foo$HOME/bar".into(),
13363 });
13364 let err = d.validate().unwrap_err();
13365 let DepError::FonteCaminhoShellVariableExpansion {
13366 nome,
13367 caminho,
13368 byte,
13369 } = err
13370 else {
13371 panic!("expected FonteCaminhoShellVariableExpansion, got {err:?}");
13372 };
13373 assert_eq!(nome, "caixa-teia");
13374 assert_eq!(caminho, "../foo$HOME/bar");
13375 assert_eq!(byte, b'$');
13376 }
13377
13378 #[test]
13379 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_braced_var_expansion() {
13380 // The symmetric braced-CI-manifest paste shape
13381 // (`"../foo${WORKSPACE}/bar"` — the canonical paste-from-
13382 // GitHub-Actions-workflow / paste-from-`.gitlab-ci.yml`
13383 // footgun). Pinned separately from the bare-`$VAR` shape so
13384 // the gate covers both POSIX shell §2.6 Parameter Expansion
13385 // syntactic forms, not only the unbraced variant. The
13386 // embedded `{` byte in `${...}` is also caught by the 598b770
13387 // shell-brace-expansion arm but that arm fires earlier in
13388 // the cascade — the `$` arm's coverage extends to `${...}`
13389 // structurally, so the diagnostic asserted here is the
13390 // brace-expansion one (which is a valid outcome; the point
13391 // of the pin is that the value never survives validation).
13392 let d = dep_with_fonte(DepSource::Path {
13393 caminho: "../foo${WORKSPACE}/bar".into(),
13394 });
13395 let err = d.validate().unwrap_err();
13396 assert!(
13397 matches!(
13398 err,
13399 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. }
13400 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13401 ),
13402 "got {err:?}",
13403 );
13404 }
13405
13406 #[test]
13407 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_command_substitution() {
13408 // The paste-from-shell-prompt command-substitution idiom
13409 // (`"../foo$(whoami)/bar"`). Pinned separately from the bare-
13410 // `$VAR` shape so the gate's rationale extends to POSIX shell
13411 // §2.6.3 Command Substitution (the modern `$(<cmd>)` form; the
13412 // legacy `` `<cmd>` `` form is already closed by the c370458
13413 // backtick arm). The embedded `(` byte in `$(...)` is also
13414 // caught structurally by the 0633c91 shell-subshell-grouping
13415 // arm which fires earlier in the cascade — the diagnostic
13416 // asserted here is either outcome, since both structurally
13417 // reject the value; the point of the pin is that the value
13418 // never survives validation.
13419 let d = dep_with_fonte(DepSource::Path {
13420 caminho: "../foo$(whoami)/bar".into(),
13421 });
13422 let err = d.validate().unwrap_err();
13423 assert!(
13424 matches!(
13425 err,
13426 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. }
13427 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13428 ),
13429 "got {err:?}",
13430 );
13431 }
13432
13433 #[test]
13434 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_positional_parameter() {
13435 // The paste-from-`Makefile` / paste-from-SQL-migration bare-
13436 // `$1` positional-parameter shape (`"../foo$1/bar"` — a Make
13437 // automatic-variable `$1` or a PostgreSQL bind-parameter `$1`
13438 // idiom copied into a caminho template). None of the prior
13439 // shell-metachar arms cover this shape (`1` is a bare digit;
13440 // no `(` / `{` / letter follows the `$`), so the arm is the
13441 // sole gate on the shape.
13442 let d = dep_with_fonte(DepSource::Path {
13443 caminho: "../foo$1/bar".into(),
13444 });
13445 let err = d.validate().unwrap_err();
13446 assert!(
13447 matches!(
13448 err,
13449 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13450 ),
13451 "got {err:?}",
13452 );
13453 }
13454
13455 #[test]
13456 fn validate_accepts_path_fonte_with_caminho_carrying_no_dollar() {
13457 // The positive-control pin (peer with
13458 // `validate_accepts_path_fonte_with_caminho_carrying_no_percent`
13459 // on the immediate-predecessor arm): the gate targets only
13460 // `$`, never adjacent printable ASCII or POSIX-valid bytes.
13461 // A relative POSIX path carrying dashes / dots / slashes /
13462 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13463 // validate cleanly so the gate doesn't widen to a "no
13464 // printable punctuation anywhere" sweep that would defeat
13465 // the entire path-fonte author surface.
13466 let d = dep_with_fonte(DepSource::Path {
13467 caminho: "../caixa-teia/sub-dir.v2".into(),
13468 });
13469 d.validate().unwrap();
13470 }
13471
13472 #[test]
13473 fn fonte_caminho_var_expansion_fires_before_shell_variable_expansion() {
13474 // Cascade pin on the leading-`$` sibling arm at line 540: a
13475 // value starting with `$` and carrying an embedded `$` too
13476 // (`"$HOME/foo$WORKSPACE/bar"` — the canonical "I pasted a
13477 // fully-templated CI path with two un-substituted variables")
13478 // routes through `FonteCaminhoVarExpansion` not
13479 // `FonteCaminhoShellVariableExpansion`. The leading-byte
13480 // host-layout-leak is the load-bearing self-locating axis
13481 // (the leading position dominates the semantic-locating
13482 // rationale on every probe-as-both value); the embedded
13483 // arm's positional-agnostic sweep catches only values whose
13484 // leading byte doesn't route through the earlier leading-
13485 // byte arms.
13486 let d = dep_with_fonte(DepSource::Path {
13487 caminho: "$HOME/foo$WORKSPACE/bar".into(),
13488 });
13489 let err = d.validate().unwrap_err();
13490 assert!(
13491 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
13492 "got {err:?}",
13493 );
13494 }
13495
13496 #[test]
13497 fn fonte_caminho_url_percent_encoding_fires_before_shell_variable_expansion() {
13498 // Cascade pin on the immediate-predecessor arm: a value
13499 // carrying both `%` and embedded `$` (`"../foo%20$HOME/bar"`
13500 // — the canonical "I pasted a percent-encoded space adjacent
13501 // to a `$HOME` template") routes through
13502 // `FonteCaminhoUrlPercentEncoding` not
13503 // `FonteCaminhoShellVariableExpansion`. The URL-percent-
13504 // encoding-escape byte is the more semantic-locating axis
13505 // (the paste-from-browser-address-bar shape is the load-
13506 // bearing self-locating edit); same cascade discipline every
13507 // prior `:caminho` arm establishes.
13508 let d = dep_with_fonte(DepSource::Path {
13509 caminho: "../foo%20$HOME/bar".into(),
13510 });
13511 let err = d.validate().unwrap_err();
13512 assert!(
13513 matches!(
13514 err,
13515 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13516 ),
13517 "got {err:?}",
13518 );
13519 }
13520
13521 #[test]
13522 fn fonte_caminho_shell_variable_expansion_fires_before_trailing_slash() {
13523 // Cascade pin on the immediate-successor arm: a value
13524 // carrying both embedded `$` and a trailing `/`
13525 // (`"../foo$HOME/bar/"` — the canonical "I tab-completed a
13526 // `$HOME`-template-carrying path") routes through
13527 // `FonteCaminhoShellVariableExpansion` not
13528 // `FonteCaminhoTrailingSlash`. The embedded shell-variable-
13529 // expansion byte is the more semantic-locating axis on
13530 // probe-as-both values (an author who substitutes the
13531 // `$HOME` template with a literal value is likely to also
13532 // tab-strip the trailing separator).
13533 let d = dep_with_fonte(DepSource::Path {
13534 caminho: "../foo$HOME/bar/".into(),
13535 });
13536 let err = d.validate().unwrap_err();
13537 assert!(
13538 matches!(
13539 err,
13540 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13541 ),
13542 "got {err:?}",
13543 );
13544 }
13545
13546 #[test]
13547 fn fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13548 // Diagnostic-shape pin (peer with
13549 // `fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte`
13550 // on the immediate-predecessor arm): the error's Display
13551 // surfaces the offending `:nome`, the offending `:caminho`
13552 // verbatim, the offending byte's hex / character form, and
13553 // names the shell-variable-expansion / command-substitution
13554 // footgun explicitly so a `feira lint` run can render the
13555 // diagnostic without re-parsing.
13556 let d = dep_with_fonte(DepSource::Path {
13557 caminho: "../foo$HOME/bar".into(),
13558 });
13559 let rendered = d.validate().unwrap_err().to_string();
13560 assert!(
13561 rendered.contains("caixa-teia"),
13562 "diagnostic must name the offending dep: {rendered}",
13563 );
13564 assert!(
13565 rendered.contains("../foo$HOME/bar"),
13566 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13567 );
13568 assert!(
13569 rendered.contains("0x24"),
13570 "diagnostic must surface the offending byte hex: {rendered:?}",
13571 );
13572 assert!(
13573 rendered.contains("variable-expansion") || rendered.contains("variable expansion"),
13574 "diagnostic must name the shell-variable-expansion footgun: {rendered:?}",
13575 );
13576 assert!(
13577 rendered.contains("command-substitution") || rendered.contains("command substitution"),
13578 "diagnostic must reference the command-substitution vocabulary: {rendered:?}",
13579 );
13580 }
13581
13582 #[test]
13583 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_expansion() {
13584 // The fail-before-pass-after pin for the canonical paste-from-
13585 // shell-history footgun on `:caminho`. An author copies a `cd
13586 // ../caixa-teia && !sudo make install` one-liner from a quick-
13587 // start README, intending the trailing `!sudo` as a shell-
13588 // history-expansion reference but the typed slot is itself a
13589 // byte-level string parser, not a shell context, so the byte
13590 // rides into the value verbatim. Until this arm landed the `!`
13591 // byte silently passed every prior `:caminho` cascade arm
13592 // (`!` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick /
13593 // `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` /
13594 // `#` / `%` / `$`); bash with the default `histexpand` mode
13595 // rewrites `!command` to the most recent history entry
13596 // beginning with `command`, the canonical RCE-class injection
13597 // vector when the byte rides into a shell argument executed
13598 // under `bash -i` (the operator-notebook interactive shell).
13599 let d = dep_with_fonte(DepSource::Path {
13600 caminho: "../caixa-teia!sudo".into(),
13601 });
13602 let err = d.validate().unwrap_err();
13603 let DepError::FonteCaminhoShellHistoryExpansion {
13604 nome,
13605 caminho,
13606 byte,
13607 } = err
13608 else {
13609 panic!("expected FonteCaminhoShellHistoryExpansion, got {err:?}");
13610 };
13611 assert_eq!(nome, "caixa-teia");
13612 assert_eq!(caminho, "../caixa-teia!sudo");
13613 assert_eq!(byte, b'!');
13614 }
13615
13616 #[test]
13617 fn validate_rejects_path_fonte_with_caminho_carrying_double_bang_history_reference() {
13618 // The symmetric `!!` repeat-prior-command paste idiom (peer with
13619 // `validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference`
13620 // on `is_git_repo_url`). Pinned separately from the wrapped
13621 // `!command` shape so a future diagnostic-surface change that
13622 // only checked the leading or paired-bang position surfaces
13623 // here — the per-byte arm fires anywhere `!` appears in the
13624 // value, including at consecutive positions in the middle.
13625 let d = dep_with_fonte(DepSource::Path {
13626 caminho: "../foo!!/bar".into(),
13627 });
13628 let err = d.validate().unwrap_err();
13629 assert!(
13630 matches!(
13631 err,
13632 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13633 ),
13634 "got {err:?}",
13635 );
13636 }
13637
13638 #[test]
13639 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_enthusiasm_bang() {
13640 // The English-typography enthusiasm-form paste-from-prose
13641 // idiom: an author writes `:caminho "../caixa-teia!"`
13642 // expecting the substrate to coerce it to a kebab-case slug.
13643 // Pinned separately from the `!<word>` shell-history shape so
13644 // the gate's rationale extends to the paste-from-prose surface
13645 // (the same rationale the peer `is_git_repo_url` bang arm at
13646 // 7d53c68 covers). None of the prior shell-metachar arms cover
13647 // this shape (no `!<word>` reference and no `!!` repeat), so
13648 // the arm is the sole gate on the shape.
13649 let d = dep_with_fonte(DepSource::Path {
13650 caminho: "../caixa-teia!".into(),
13651 });
13652 let err = d.validate().unwrap_err();
13653 assert!(
13654 matches!(
13655 err,
13656 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13657 ),
13658 "got {err:?}",
13659 );
13660 }
13661
13662 #[test]
13663 fn validate_accepts_path_fonte_with_caminho_carrying_no_bang() {
13664 // The positive-control pin (peer with
13665 // `validate_accepts_path_fonte_with_caminho_carrying_no_dollar`
13666 // on the immediate-predecessor arm): the gate targets only
13667 // `!`, never adjacent printable ASCII or POSIX-valid bytes.
13668 // A relative POSIX path carrying dashes / dots / slashes /
13669 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13670 // validate cleanly so the gate doesn't widen to a "no
13671 // printable punctuation anywhere" sweep that would defeat
13672 // the entire path-fonte author surface.
13673 let d = dep_with_fonte(DepSource::Path {
13674 caminho: "../caixa-teia/sub-dir.v2".into(),
13675 });
13676 d.validate().unwrap();
13677 }
13678
13679 #[test]
13680 fn fonte_caminho_shell_variable_expansion_fires_before_shell_history_expansion() {
13681 // Cascade pin on the immediate-predecessor arm: a value
13682 // carrying both embedded `$` and `!` (`"../foo$HOME/bar!sudo"`
13683 // — the canonical "I pasted a `$HOME`-templated path adjacent
13684 // to a trailing `!sudo` history-expansion") routes through
13685 // `FonteCaminhoShellVariableExpansion` not
13686 // `FonteCaminhoShellHistoryExpansion`. The shell-variable-
13687 // expansion byte is the more semantic-locating axis on
13688 // probe-as-both values (the paste-from-CI-manifest-with-`$VAR`-
13689 // template shape is the load-bearing self-locating edit);
13690 // same cascade discipline every prior `:caminho` arm
13691 // establishes.
13692 let d = dep_with_fonte(DepSource::Path {
13693 caminho: "../foo$HOME/bar!sudo".into(),
13694 });
13695 let err = d.validate().unwrap_err();
13696 assert!(
13697 matches!(
13698 err,
13699 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13700 ),
13701 "got {err:?}",
13702 );
13703 }
13704
13705 #[test]
13706 fn fonte_caminho_shell_history_expansion_fires_before_trailing_slash() {
13707 // Cascade pin on the immediate-successor arm: a value carrying
13708 // both embedded `!` and a trailing `/` (`"../caixa-teia!sudo/"`
13709 // — the canonical "I tab-completed a `!sudo`-carrying path")
13710 // routes through `FonteCaminhoShellHistoryExpansion` not
13711 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13712 // expansion byte is the more semantic-locating axis on probe-
13713 // as-both values (an author who removes the `!sudo` history
13714 // reference is likely to also tab-strip the trailing separator).
13715 let d = dep_with_fonte(DepSource::Path {
13716 caminho: "../caixa-teia!sudo/".into(),
13717 });
13718 let err = d.validate().unwrap_err();
13719 assert!(
13720 matches!(
13721 err,
13722 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13723 ),
13724 "got {err:?}",
13725 );
13726 }
13727
13728 #[test]
13729 fn fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13730 // Diagnostic-shape pin (peer with
13731 // `fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13732 // on the immediate-predecessor arm): the error's Display
13733 // surfaces the offending `:nome`, the offending `:caminho`
13734 // verbatim, the offending byte's hex / character form, and
13735 // names the shell-history-expansion / bang-operator footgun
13736 // explicitly so a `feira lint` run can render the diagnostic
13737 // without re-parsing.
13738 let d = dep_with_fonte(DepSource::Path {
13739 caminho: "../caixa-teia!sudo".into(),
13740 });
13741 let rendered = d.validate().unwrap_err().to_string();
13742 assert!(
13743 rendered.contains("caixa-teia"),
13744 "diagnostic must name the offending dep: {rendered}",
13745 );
13746 assert!(
13747 rendered.contains("../caixa-teia!sudo"),
13748 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13749 );
13750 assert!(
13751 rendered.contains("0x21"),
13752 "diagnostic must surface the offending byte hex: {rendered:?}",
13753 );
13754 assert!(
13755 rendered.contains("history-expansion") || rendered.contains("history expansion"),
13756 "diagnostic must name the shell-history-expansion footgun: {rendered:?}",
13757 );
13758 assert!(
13759 rendered.contains("bang"),
13760 "diagnostic must reference the bang-operator vocabulary: {rendered:?}",
13761 );
13762 }
13763
13764 #[test]
13765 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_substitution() {
13766 // The fail-before-pass-after pin for the canonical paste-from-
13767 // shell-history-quick-substitution footgun on `:caminho`. An
13768 // author copies a `git clone <bad-url>` line from their terminal,
13769 // corrects it via bash's `^bad^good` quick-substitution history
13770 // operator (bash reference §9.3, `set -o histexpand` mode's
13771 // default for interactive sessions), and pastes the trailing
13772 // `^bad^good` substitution fragment into a `:caminho` value
13773 // without trimming the leading `git clone` prefix — the byte
13774 // rides into the manifest verbatim. Until this arm landed the
13775 // `^` byte silently passed every prior `:caminho` cascade arm
13776 // (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick / `*`
13777 // / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` / `#` /
13778 // `%` / `$` / `!`); bash with the default `histexpand` mode
13779 // rewrites the prior command's `bad` string to `good` and re-
13780 // executes it, the paired-operator half of the `set -o
13781 // histexpand` feature the peer `!` arm already closes the prefix
13782 // half of. The peer `is_git_repo_url` axis rejects the byte at
13783 // 49e142f under the same shell-history-substitution / RFC-3986-
13784 // unwise banner.
13785 let d = dep_with_fonte(DepSource::Path {
13786 caminho: "../foo^bad^good".into(),
13787 });
13788 let err = d.validate().unwrap_err();
13789 let DepError::FonteCaminhoShellHistorySubstitution {
13790 nome,
13791 caminho,
13792 byte,
13793 } = err
13794 else {
13795 panic!("expected FonteCaminhoShellHistorySubstitution, got {err:?}");
13796 };
13797 assert_eq!(nome, "caixa-teia");
13798 assert_eq!(caminho, "../foo^bad^good");
13799 assert_eq!(byte, b'^');
13800 }
13801
13802 #[test]
13803 fn validate_rejects_path_fonte_with_caminho_carrying_regex_negation_anchor() {
13804 // The symmetric paste-from-doc-grep-pipeline footgun (peer with
13805 // `validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor`
13806 // on `is_git_repo_url`). An author copies a `grep '^archived'`
13807 // regex-anchor / negation idiom from a doc snippet and the byte
13808 // rides in verbatim. Pinned separately from the `^old^new^`
13809 // quick-substitution shape so a future diagnostic-surface change
13810 // that only checked the paired-caret history-substitution
13811 // position surfaces here — the per-byte arm fires anywhere `^`
13812 // appears in the value, including at a solitary leading-of-
13813 // segment position.
13814 let d = dep_with_fonte(DepSource::Path {
13815 caminho: "../foo/^archived".into(),
13816 });
13817 let err = d.validate().unwrap_err();
13818 assert!(
13819 matches!(
13820 err,
13821 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13822 ),
13823 "got {err:?}",
13824 );
13825 }
13826
13827 #[test]
13828 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_history_substitution_open() {
13829 // The trailing-`^` history-substitution-open shape — an author
13830 // starts typing a `^bad^good` quick-substitution but pastes only
13831 // the leading `^` sentinel before context-switching (a bash-
13832 // reference §9.3 valid histexpand prefix on its own — even a
13833 // solitary `^` on the prior command's whole re-execution shape).
13834 // Pinned separately from the `^old^new^` full-form and the leading-
13835 // of-segment `^archived` regex-anchor shape so the gate's
13836 // rationale extends to the paste-from-shell-history-with-only-
13837 // the-first-byte-selected surface. None of the prior shell-
13838 // metachar arms cover this shape.
13839 let d = dep_with_fonte(DepSource::Path {
13840 caminho: "../caixa-teia^".into(),
13841 });
13842 let err = d.validate().unwrap_err();
13843 assert!(
13844 matches!(
13845 err,
13846 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13847 ),
13848 "got {err:?}",
13849 );
13850 }
13851
13852 #[test]
13853 fn validate_accepts_path_fonte_with_caminho_carrying_no_caret() {
13854 // The positive-control pin (peer with
13855 // `validate_accepts_path_fonte_with_caminho_carrying_no_bang`
13856 // on the immediate-predecessor arm): the gate targets only
13857 // `^`, never adjacent printable ASCII or POSIX-valid bytes.
13858 // A relative POSIX path carrying dashes / dots / slashes /
13859 // digits / underscore (`"../caixa-teia/sub_v2.rc"`) must
13860 // continue to validate cleanly so the gate doesn't widen to
13861 // a "no printable punctuation anywhere" sweep that would
13862 // defeat the entire path-fonte author surface.
13863 let d = dep_with_fonte(DepSource::Path {
13864 caminho: "../caixa-teia/sub_v2.rc".into(),
13865 });
13866 d.validate().unwrap();
13867 }
13868
13869 #[test]
13870 fn fonte_caminho_shell_history_expansion_fires_before_shell_history_substitution() {
13871 // Cascade pin on the immediate-predecessor arm: a value carrying
13872 // both embedded `!` and `^` (`"../foo!sudo^bad^good"` — the
13873 // canonical "I pasted a `!sudo` history-reference next to a
13874 // `^bad^good` quick-substitution") routes through
13875 // `FonteCaminhoShellHistoryExpansion` not
13876 // `FonteCaminhoShellHistorySubstitution`. The `!` prefix form is
13877 // the more semantic-locating axis on probe-as-both values (an
13878 // author who removes the `!sudo` reference is likely to also
13879 // strip the paired `^` substitution fragment); same cascade
13880 // discipline every prior `:caminho` arm establishes.
13881 let d = dep_with_fonte(DepSource::Path {
13882 caminho: "../foo!sudo^bad^good".into(),
13883 });
13884 let err = d.validate().unwrap_err();
13885 assert!(
13886 matches!(
13887 err,
13888 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13889 ),
13890 "got {err:?}",
13891 );
13892 }
13893
13894 #[test]
13895 fn fonte_caminho_shell_history_substitution_fires_before_trailing_slash() {
13896 // Cascade pin on the immediate-successor arm: a value carrying
13897 // both embedded `^` and a trailing `/` (`"../foo^bad^good/"` —
13898 // the canonical "I tab-completed a `^bad^good`-carrying path")
13899 // routes through `FonteCaminhoShellHistorySubstitution` not
13900 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13901 // substitution byte is the more semantic-locating axis on probe-
13902 // as-both values (an author who removes the `^bad^good`
13903 // substitution fragment is likely to also tab-strip the trailing
13904 // separator).
13905 let d = dep_with_fonte(DepSource::Path {
13906 caminho: "../foo^bad^good/".into(),
13907 });
13908 let err = d.validate().unwrap_err();
13909 assert!(
13910 matches!(
13911 err,
13912 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13913 ),
13914 "got {err:?}",
13915 );
13916 }
13917
13918 #[test]
13919 fn fonte_caminho_shell_history_substitution_diagnostic_carries_offending_dep_caminho_and_byte()
13920 {
13921 // Diagnostic-shape pin (peer with
13922 // `fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13923 // on the immediate-predecessor arm): the error's Display
13924 // surfaces the offending `:nome`, the offending `:caminho`
13925 // verbatim, the offending byte's hex form, and names the
13926 // shell-history-substitution / RFC-3986-'unwise' / regex-
13927 // negation footgun explicitly so a `feira lint` run can render
13928 // the diagnostic without re-parsing.
13929 let d = dep_with_fonte(DepSource::Path {
13930 caminho: "../foo^bad^good".into(),
13931 });
13932 let rendered = d.validate().unwrap_err().to_string();
13933 assert!(
13934 rendered.contains("caixa-teia"),
13935 "diagnostic must name the offending dep: {rendered}",
13936 );
13937 assert!(
13938 rendered.contains("../foo^bad^good"),
13939 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13940 );
13941 assert!(
13942 rendered.contains("0x5e") || rendered.contains("0x5E"),
13943 "diagnostic must surface the offending byte hex: {rendered:?}",
13944 );
13945 assert!(
13946 rendered.contains("history-substitution") || rendered.contains("history substitution"),
13947 "diagnostic must name the shell-history-substitution footgun: {rendered:?}",
13948 );
13949 assert!(
13950 rendered.contains("unwise"),
13951 "diagnostic must reference the RFC-3986 'unwise' set vocabulary: {rendered:?}",
13952 );
13953 }
13954
13955 #[test]
13956 fn fonte_repo_empty_fires_before_pin_missing() {
13957 // Order pin: empty `:repo` is the more self-locating diagnostic
13958 // (every git source needs a repo; the pin discussion is
13959 // secondary), so it fires before the pin-missing arm even when
13960 // both are violated. Mirrors the
13961 // `nome_empty_takes_precedence_over_versao_invalid` ordering
13962 // discipline on the per-entry layer.
13963 let d = dep_with_fonte(DepSource::Git {
13964 repo: String::new(),
13965 tag: None,
13966 rev: None,
13967 branch: None,
13968 });
13969 let err = d.validate().unwrap_err();
13970 assert!(
13971 matches!(err, DepError::FonteRepoEmpty { .. }),
13972 "got {err:?}"
13973 );
13974 }
13975
13976 #[test]
13977 fn fonte_pin_missing_fires_before_pin_empty() {
13978 // Order pin: a fully-None pin set is structurally distinct from
13979 // a Some(empty) pin — the first surfaces as FontePinMissing
13980 // (no axis chosen), the second as FontePinEmpty (axis chosen
13981 // but value blank). Pin the disjoint relationship so a future
13982 // unification collapses to one variant only as a structural
13983 // decision.
13984 let d = dep_with_fonte(DepSource::Git {
13985 repo: "github:pleme-io/caixa-teia".into(),
13986 tag: None,
13987 rev: None,
13988 branch: None,
13989 });
13990 assert!(matches!(
13991 d.validate().unwrap_err(),
13992 DepError::FontePinMissing { .. }
13993 ));
13994 }
13995
13996 #[test]
13997 fn nome_empty_takes_precedence_over_fonte_invalid() {
13998 // Order pin: a per-entry diagnostic without a non-empty :nome
13999 // can't be self-locating, so :nome "" fires first even when
14000 // :fonte is also malformed. Mirrors
14001 // `nome_empty_takes_precedence_over_versao_invalid` on the
14002 // adjacent axis.
14003 let mut d = dep_with_fonte(DepSource::Git {
14004 repo: String::new(),
14005 tag: None,
14006 rev: None,
14007 branch: None,
14008 });
14009 d.nome = String::new();
14010 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
14011 }
14012
14013 #[test]
14014 fn versao_invalid_takes_precedence_over_fonte_invalid() {
14015 // Order pin: the :versao parse-side diagnostic is narrower than
14016 // the :fonte shape diagnostic — a malformed :versao always names
14017 // the parser's reason, which is more actionable than the
14018 // :fonte gate's "the pins are wrong" wording. Pin the ordering
14019 // so a re-ordering surfaces here.
14020 let mut d = dep_with_fonte(DepSource::Git {
14021 repo: String::new(),
14022 tag: None,
14023 rev: None,
14024 branch: None,
14025 });
14026 d.versao = "v0.1".into();
14027 let err = d.validate().unwrap_err();
14028 assert!(
14029 matches!(err, DepError::VersaoInvalid { ref nome, .. } if nome == "caixa-teia"),
14030 "got {err:?}"
14031 );
14032 }
14033
14034 #[test]
14035 fn fonte_invalid_diagnostic_carries_offending_nome() {
14036 // The diagnostic-shape pin: every :fonte error variant names
14037 // the offending dep's :nome verbatim, so the author can grep
14038 // caixa.lisp for the `:nome "<n>"` block and fix it in one
14039 // edit. Cover all seven variants so a future variant addition
14040 // forces a parallel diagnostic-shape decision.
14041 for (case, fonte) in [
14042 (
14043 "repo-empty",
14044 DepSource::Git {
14045 repo: String::new(),
14046 tag: Some("v1".into()),
14047 rev: None,
14048 branch: None,
14049 },
14050 ),
14051 (
14052 "repo-shape",
14053 DepSource::Git {
14054 repo: "github:p/x ".into(),
14055 tag: Some("v1".into()),
14056 rev: None,
14057 branch: None,
14058 },
14059 ),
14060 (
14061 "pin-missing",
14062 DepSource::Git {
14063 repo: "github:p/x".into(),
14064 tag: None,
14065 rev: None,
14066 branch: None,
14067 },
14068 ),
14069 (
14070 "pin-ambiguous",
14071 DepSource::Git {
14072 repo: "github:p/x".into(),
14073 tag: Some("v1".into()),
14074 rev: None,
14075 branch: Some("main".into()),
14076 },
14077 ),
14078 (
14079 "pin-empty",
14080 DepSource::Git {
14081 repo: "github:p/x".into(),
14082 tag: Some(String::new()),
14083 rev: None,
14084 branch: None,
14085 },
14086 ),
14087 (
14088 "caminho-empty",
14089 DepSource::Path {
14090 caminho: String::new(),
14091 },
14092 ),
14093 (
14094 "caminho-absolute",
14095 DepSource::Path {
14096 caminho: "/home/me/work/caixa-teia".into(),
14097 },
14098 ),
14099 ] {
14100 let d = dep_with_fonte(fonte);
14101 let msg = d
14102 .validate()
14103 .expect_err(&format!("{case}: expected fonte error"))
14104 .to_string();
14105 assert!(
14106 msg.contains("\"caixa-teia\""),
14107 "{case}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14108 );
14109 }
14110 }
14111
14112 // -- :tag / :branch value-shape gate ----------------------------------
14113
14114 #[test]
14115 fn validate_rejects_git_fonte_with_tag_carrying_trailing_space() {
14116 // The canonical paste-from-doc footgun on `:tag` — author
14117 // copies `"v0.1.0 "` (trailing space) out of a release-notes
14118 // paragraph. Until this gate landed the empty-pin arm passed
14119 // (the string isn't empty), the resolver issued
14120 // `git fetch <remote> tag 'v0.1.0 '`, and the failure
14121 // surfaced at clone time with a quoting-confused git error
14122 // far from the source caixa.lisp. The new gate moves the
14123 // check to caixa-build time and names the offending dep +
14124 // pin + value verbatim.
14125 let d = dep_with_fonte(DepSource::Git {
14126 repo: "github:pleme-io/caixa-teia".into(),
14127 tag: Some("v0.1.0 ".into()),
14128 rev: None,
14129 branch: None,
14130 });
14131 let err = d.validate().unwrap_err();
14132 let DepError::FontePinShape {
14133 nome,
14134 pin,
14135 value,
14136 reason,
14137 } = err
14138 else {
14139 panic!("expected FontePinShape, got other variant");
14140 };
14141 assert_eq!(nome, "caixa-teia");
14142 assert_eq!(pin, ":tag");
14143 assert_eq!(value, "v0.1.0 ");
14144 assert!(
14145 reason.contains("whitespace"),
14146 "reason must surface the whitespace arm, got {reason:?}"
14147 );
14148 }
14149
14150 #[test]
14151 fn validate_rejects_git_fonte_with_tag_carrying_lock_suffix() {
14152 // The `.lock` suffix is git's atomic-rename guard for
14153 // in-flight ref updates — a refname ending in `.lock` is
14154 // unwritable on disk. Pinned separately from the whitespace
14155 // arm so a future relaxation that admits one but not the
14156 // other surfaces here.
14157 let d = dep_with_fonte(DepSource::Git {
14158 repo: "github:pleme-io/caixa-teia".into(),
14159 tag: Some("v0.1.0.lock".into()),
14160 rev: None,
14161 branch: None,
14162 });
14163 let err = d.validate().unwrap_err();
14164 let DepError::FontePinShape {
14165 pin, value, reason, ..
14166 } = err
14167 else {
14168 panic!("expected FontePinShape, got other variant");
14169 };
14170 assert_eq!(pin, ":tag");
14171 assert_eq!(value, "v0.1.0.lock");
14172 assert!(
14173 reason.contains(".lock"),
14174 "reason must surface the .lock arm, got {reason:?}"
14175 );
14176 }
14177
14178 #[test]
14179 fn validate_rejects_git_fonte_with_branch_carrying_embedded_space() {
14180 // The canonical "branch name with spaces" footgun (`feature
14181 // foo`, `release branch`) — git's refname parser rejects raw
14182 // whitespace, and the failure surfaces at `git checkout
14183 // 'feature foo'` time with a quoting-confused error far from
14184 // the source caixa.lisp. Pinned on the `:branch` axis so the
14185 // gate-applies-to-both-:tag-and-:branch contract is a build-
14186 // error to relax.
14187 let d = dep_with_fonte(DepSource::Git {
14188 repo: "github:pleme-io/caixa-teia".into(),
14189 tag: None,
14190 rev: None,
14191 branch: Some("feature/foo bar".into()),
14192 });
14193 let err = d.validate().unwrap_err();
14194 let DepError::FontePinShape {
14195 pin, value, reason, ..
14196 } = err
14197 else {
14198 panic!("expected FontePinShape, got other variant");
14199 };
14200 assert_eq!(pin, ":branch");
14201 assert_eq!(value, "feature/foo bar");
14202 assert!(
14203 reason.contains("whitespace"),
14204 "reason must surface the whitespace arm, got {reason:?}"
14205 );
14206 }
14207
14208 #[test]
14209 fn validate_rejects_git_fonte_with_branch_carrying_qualified_prefix() {
14210 // The `refs/heads/main` shape — the canonical "I copied the
14211 // fully-qualified ref out of `git show-ref` instead of the
14212 // leaf" footgun. The caixa-resolver prepends `refs/heads/`
14213 // at clone time, so this resolves to a literal ref named
14214 // `refs/heads/refs/heads/main` on disk; the silent double-
14215 // prefix is the load-bearing reason to gate at validate.
14216 // The diagnostic must enumerate the leaf the author probably
14217 // meant (`"main"`) so the fix is one edit.
14218 let d = dep_with_fonte(DepSource::Git {
14219 repo: "github:pleme-io/caixa-teia".into(),
14220 tag: None,
14221 rev: None,
14222 branch: Some("refs/heads/main".into()),
14223 });
14224 let err = d.validate().unwrap_err();
14225 let DepError::FontePinShape {
14226 pin, value, reason, ..
14227 } = err
14228 else {
14229 panic!("expected FontePinShape, got other variant");
14230 };
14231 assert_eq!(pin, ":branch");
14232 assert_eq!(value, "refs/heads/main");
14233 assert!(
14234 reason.contains("fully-qualified"),
14235 "reason must surface the qualified-prefix arm, got {reason:?}"
14236 );
14237 assert!(
14238 reason.contains("\"main\""),
14239 "reason must quote the leaf the author probably meant, got {reason:?}"
14240 );
14241 }
14242
14243 #[test]
14244 fn validate_rejects_git_fonte_with_tag_carrying_qualified_prefix() {
14245 // Sibling arm of the qualified-prefix gate on the `:tag`
14246 // axis (`refs/tags/v0.1.0` — same `git show-ref` output-leak
14247 // footgun). Pinned separately so a future relaxation that
14248 // only catches the `:branch` arm surfaces here.
14249 let d = dep_with_fonte(DepSource::Git {
14250 repo: "github:pleme-io/caixa-teia".into(),
14251 tag: Some("refs/tags/v0.1.0".into()),
14252 rev: None,
14253 branch: None,
14254 });
14255 let err = d.validate().unwrap_err();
14256 let DepError::FontePinShape {
14257 pin, value, reason, ..
14258 } = err
14259 else {
14260 panic!("expected FontePinShape, got other variant");
14261 };
14262 assert_eq!(pin, ":tag");
14263 assert_eq!(value, "refs/tags/v0.1.0");
14264 assert!(
14265 reason.contains("fully-qualified"),
14266 "reason must surface the qualified-prefix arm, got {reason:?}"
14267 );
14268 assert!(
14269 reason.contains("\"v0.1.0\""),
14270 "reason must quote the leaf the author probably meant, got {reason:?}"
14271 );
14272 }
14273
14274 #[test]
14275 fn validate_rejects_git_fonte_with_branch_named_at() {
14276 // The bare `@` is git's alias for `HEAD`; a `:branch "@"` is
14277 // unsourceable. Pinned so a future relaxation that admits
14278 // any single-character refname surfaces here.
14279 let d = dep_with_fonte(DepSource::Git {
14280 repo: "github:pleme-io/caixa-teia".into(),
14281 tag: None,
14282 rev: None,
14283 branch: Some("@".into()),
14284 });
14285 let err = d.validate().unwrap_err();
14286 let DepError::FontePinShape { pin, value, .. } = err else {
14287 panic!("expected FontePinShape, got other variant");
14288 };
14289 assert_eq!(pin, ":branch");
14290 assert_eq!(value, "@");
14291 }
14292
14293 #[test]
14294 fn validate_rejects_git_fonte_with_tag_carrying_double_dot() {
14295 // Git's `<rev1>..<rev2>` range grammar reserves `..` —
14296 // a `:tag "../escape"` (path-traversal-shaped slug) silently
14297 // passes parse and surfaces as a refname-parse error or, on
14298 // older git, a literal `../escape` checkout that escapes the
14299 // refs/ directory tree. Pinned separately from the
14300 // qualified-prefix arm so a future relaxation that catches
14301 // one but not the other surfaces here.
14302 let d = dep_with_fonte(DepSource::Git {
14303 repo: "github:pleme-io/caixa-teia".into(),
14304 tag: Some("../escape".into()),
14305 rev: None,
14306 branch: None,
14307 });
14308 let err = d.validate().unwrap_err();
14309 let DepError::FontePinShape { pin, value, .. } = err else {
14310 panic!("expected FontePinShape, got other variant");
14311 };
14312 assert_eq!(pin, ":tag");
14313 assert_eq!(value, "../escape");
14314 }
14315
14316 #[test]
14317 fn validate_accepts_git_fonte_with_hierarchical_branch() {
14318 // The positive-control pin: hierarchical refnames with one or
14319 // more `/` separators (the `feature/foo` / `user/jdoe/feat`
14320 // canonical idiom) round-trip through the gate. Pinned
14321 // separately from the leaf-`"main"` positive control so a
14322 // future tightening that rejects all multi-component refnames
14323 // surfaces here.
14324 let d = dep_with_fonte(DepSource::Git {
14325 repo: "github:pleme-io/caixa-teia".into(),
14326 tag: None,
14327 rev: None,
14328 branch: Some("feature/checkout-rewrite".into()),
14329 });
14330 d.validate().unwrap();
14331 }
14332
14333 #[test]
14334 fn validate_accepts_git_fonte_with_prerelease_tag() {
14335 // The positive-control pin: semver pre-release shape
14336 // (`v0.1.0-alpha.1`) — the in-component dot is allowed
14337 // (only consecutive `..` and trailing `.` are rejected), the
14338 // mid-component hyphen is allowed. Pinned separately from
14339 // the bare-`"v0.1.0"` positive control so a future tightening
14340 // that rejects pre-release tags surfaces here.
14341 let d = dep_with_fonte(DepSource::Git {
14342 repo: "github:pleme-io/caixa-teia".into(),
14343 tag: Some("v0.1.0-alpha.1".into()),
14344 rev: None,
14345 branch: None,
14346 });
14347 d.validate().unwrap();
14348 }
14349
14350 #[test]
14351 fn validate_rejects_git_fonte_with_rev_carrying_refname_unfriendly_value() {
14352 // The `:rev` axis is routed through `crate::render::is_git_oid`
14353 // (a SHA's character set is `[0-9a-f]`, not a refname's), so a
14354 // value with refname-shape punctuation (here, a `:` mid-string
14355 // — would be a refname violation under `is_git_ref_name` too)
14356 // is rejected at the OID-shape gate. The two predicates
14357 // partition the `:fonte` pin axes structurally: an `:rev` value
14358 // that's a valid refname (`:rev "main"`, `:rev "v0.1.0"`) is
14359 // *still* rejected here because every refname character outside
14360 // `[0-9a-f]` fails the OID gate. Same shape as
14361 // `fonte_pin_shape_diagnostic_carries_offending_nome_pin_value`
14362 // on the refname-shaped axes — the diagnostic names the
14363 // offending dep + pin + value verbatim. The flip-from-accept
14364 // case the prior `:tag`/`:branch` gate left as a "future axis"
14365 // (e70d213) — now landed.
14366 let d = dep_with_fonte(DepSource::Git {
14367 repo: "github:pleme-io/caixa-teia".into(),
14368 tag: None,
14369 rev: Some("c0ffee:notarefname".into()),
14370 branch: None,
14371 });
14372 let err = d.validate().unwrap_err();
14373 let DepError::FontePinShape {
14374 nome,
14375 pin,
14376 value,
14377 reason,
14378 } = err
14379 else {
14380 panic!("expected FontePinShape, got other variant");
14381 };
14382 assert_eq!(nome, "caixa-teia");
14383 assert_eq!(pin, ":rev");
14384 assert_eq!(value, "c0ffee:notarefname");
14385 assert!(
14386 !reason.is_empty(),
14387 "FontePinShape `reason` must carry the predicate's wording verbatim"
14388 );
14389 }
14390
14391 #[test]
14392 fn validate_accepts_git_fonte_with_rev_full_sha1() {
14393 // The positive-control pin on the SHA-1 OID width: exactly 40
14394 // lowercase hex characters — the canonical `git rev-parse HEAD`
14395 // emission on a SHA-1-hashed repository (the default on every
14396 // pre-2.42 git and the canonical pleme-io substrate hash).
14397 // Pinned separately from the SHA-256 positive control so a
14398 // future tightening that only admits one width surfaces here.
14399 let d = dep_with_fonte(DepSource::Git {
14400 repo: "github:pleme-io/caixa-teia".into(),
14401 tag: None,
14402 rev: Some("0123456789abcdef0123456789abcdef01234567".into()),
14403 branch: None,
14404 });
14405 d.validate().unwrap();
14406 }
14407
14408 #[test]
14409 fn validate_accepts_git_fonte_with_rev_full_sha256() {
14410 // The positive-control pin on the SHA-256 OID width: exactly
14411 // 64 lowercase hex characters — `git`'s
14412 // `extensions.objectFormat = sha256` emission (GA since Git
14413 // 2.42 / Oct 2023). The substrate admits either canonical
14414 // width so an `:rev` authored against a SHA-256-hashed
14415 // upstream round-trips through the gate without per-repo
14416 // configuration. Pinned separately from the SHA-1 positive
14417 // control so a future tightening that drops one width surfaces
14418 // here as a structural decision.
14419 let d = dep_with_fonte(DepSource::Git {
14420 repo: "github:pleme-io/caixa-teia".into(),
14421 tag: None,
14422 rev: Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into()),
14423 branch: None,
14424 });
14425 d.validate().unwrap();
14426 }
14427
14428 #[test]
14429 fn validate_rejects_git_fonte_with_rev_abbreviated_prefix() {
14430 // The canonical `git log --short` / `git rev-parse --short HEAD`
14431 // paste-from-release-notes footgun: a 7-char prefix (git's
14432 // default `core.abbrev`) silently passes string emptiness
14433 // checks and resolves to one commit today, but becomes ambiguous
14434 // tomorrow as the repo grows. Until this gate landed the empty-
14435 // pin arm passed (the string isn't empty) and the resolver
14436 // accepted the prefix through git's separate prefix-lookup pass
14437 // — defeating the reproducibility contract `:rev` carries vs.
14438 // `:tag` / `:branch`. The new gate moves the check to caixa-
14439 // build time and names the offending dep + pin + value verbatim.
14440 let d = dep_with_fonte(DepSource::Git {
14441 repo: "github:pleme-io/caixa-teia".into(),
14442 tag: None,
14443 rev: Some("c0ffee0".into()),
14444 branch: None,
14445 });
14446 let err = d.validate().unwrap_err();
14447 let DepError::FontePinShape {
14448 pin, value, reason, ..
14449 } = err
14450 else {
14451 panic!("expected FontePinShape, got other variant");
14452 };
14453 assert_eq!(pin, ":rev");
14454 assert_eq!(value, "c0ffee0");
14455 assert!(
14456 reason.contains("abbreviated") || reason.contains("ambiguous"),
14457 "reason must surface the abbreviation arm, got {reason:?}"
14458 );
14459 }
14460
14461 #[test]
14462 fn validate_rejects_git_fonte_with_rev_uppercase_hex() {
14463 // The canonical "I pasted the SHA in uppercase" footgun: `git
14464 // porcelain` emits OIDs lowercase exclusively, so an uppercase-
14465 // bearing `:rev` round-trips inconsistently across the
14466 // resolver's `git fetch <remote> <:rev>` ↔ `git rev-parse HEAD`
14467 // equality-check pipeline and fails the lacre's content-
14468 // addressing probe with a confusing case-only diff. Pinned
14469 // separately from the non-hex arm so a future relaxation that
14470 // admits one but not the other surfaces here.
14471 let d = dep_with_fonte(DepSource::Git {
14472 repo: "github:pleme-io/caixa-teia".into(),
14473 tag: None,
14474 rev: Some("DEADBEEFCAFEBABE0123456789ABCDEF01234567".into()),
14475 branch: None,
14476 });
14477 let err = d.validate().unwrap_err();
14478 let DepError::FontePinShape {
14479 pin, value, reason, ..
14480 } = err
14481 else {
14482 panic!("expected FontePinShape, got other variant");
14483 };
14484 assert_eq!(pin, ":rev");
14485 assert_eq!(value, "DEADBEEFCAFEBABE0123456789ABCDEF01234567");
14486 assert!(
14487 reason.contains("uppercase"),
14488 "reason must surface the uppercase arm, got {reason:?}"
14489 );
14490 }
14491
14492 #[test]
14493 fn validate_rejects_git_fonte_with_rev_refname_value() {
14494 // The cross-axis mis-slot footgun: `:rev "main"` — the author
14495 // conflated `:rev` (hex commit ID, immutable) and `:branch`
14496 // (mutable ref pointing at whatever HEAD is today). Until this
14497 // gate landed the resolver silently dispatched on the value
14498 // shape ("`main` doesn't look like a SHA, fall back to
14499 // refname"), defeating the `:rev` reproducibility contract.
14500 // The new gate rejects every non-hex value on the `:rev` axis,
14501 // so the `:rev`/`:branch` boundary is structurally enforced —
14502 // a refname in the `:rev` slot is a build error, not a
14503 // resolver-time silent reinterpretation.
14504 let d = dep_with_fonte(DepSource::Git {
14505 repo: "github:pleme-io/caixa-teia".into(),
14506 tag: None,
14507 rev: Some("main".into()),
14508 branch: None,
14509 });
14510 let err = d.validate().unwrap_err();
14511 let DepError::FontePinShape {
14512 pin, value, reason, ..
14513 } = err
14514 else {
14515 panic!("expected FontePinShape, got other variant");
14516 };
14517 assert_eq!(pin, ":rev");
14518 assert_eq!(value, "main");
14519 // 4 chars `main` fails the length arm before the character arm,
14520 // so the diagnostic surfaces the abbreviation wording (same
14521 // path the `c0ffee0` 7-char fixture lands on); the structural
14522 // assertion is just that the `:rev "main"` value is rejected.
14523 assert!(
14524 !reason.is_empty(),
14525 "FontePinShape reason must be non-empty for refname-shaped :rev"
14526 );
14527 }
14528
14529 #[test]
14530 fn validate_rejects_git_fonte_with_rev_tag_shaped_value() {
14531 // Sibling cross-axis mis-slot: `:rev "v0.1.0"` — the author
14532 // conflated `:rev` and `:tag`. Pinned separately from the
14533 // `:rev "main"` (`:branch` mis-slot) arm so a future relaxation
14534 // that catches one but not the other surfaces here. The
14535 // length arm fires first (6 chars ≠ 40 ≠ 64); the structural
14536 // assertion is just that the cross-axis mis-slot is a build
14537 // error, regardless of which sub-arm surfaces the diagnostic
14538 // (`is_git_oid` rejects at the first violation; longer
14539 // tag-shape values would hit the non-hex arm instead).
14540 let d = dep_with_fonte(DepSource::Git {
14541 repo: "github:pleme-io/caixa-teia".into(),
14542 tag: None,
14543 rev: Some("v0.1.0".into()),
14544 branch: None,
14545 });
14546 let err = d.validate().unwrap_err();
14547 let DepError::FontePinShape {
14548 pin, value, reason, ..
14549 } = err
14550 else {
14551 panic!("expected FontePinShape, got other variant");
14552 };
14553 assert_eq!(pin, ":rev");
14554 assert_eq!(value, "v0.1.0");
14555 assert!(
14556 !reason.is_empty(),
14557 "FontePinShape reason must be non-empty for tag-shaped :rev"
14558 );
14559 }
14560
14561 #[test]
14562 fn validate_rejects_git_fonte_with_rev_too_long() {
14563 // Boundary case on the upper end: 41 hex chars — one past the
14564 // SHA-1 width, well below the SHA-256 width. Pin so a future
14565 // relaxation that admits "long enough to be a SHA" without
14566 // matching either canonical width surfaces here. The diagnostic
14567 // names the offending length verbatim so the author's grep
14568 // target is unambiguous (either trim one char or paste the
14569 // full SHA-256).
14570 let too_long: String = "0".repeat(41);
14571 let d = dep_with_fonte(DepSource::Git {
14572 repo: "github:pleme-io/caixa-teia".into(),
14573 tag: None,
14574 rev: Some(too_long.clone()),
14575 branch: None,
14576 });
14577 let err = d.validate().unwrap_err();
14578 let DepError::FontePinShape {
14579 pin, value, reason, ..
14580 } = err
14581 else {
14582 panic!("expected FontePinShape, got other variant");
14583 };
14584 assert_eq!(pin, ":rev");
14585 assert_eq!(value, too_long);
14586 assert!(
14587 reason.contains("41"),
14588 "reason must surface the offending length verbatim, got {reason:?}"
14589 );
14590 }
14591
14592 #[test]
14593 fn validate_rejects_git_fonte_with_rev_carrying_whitespace() {
14594 // The canonical paste-from-doc footgun on `:rev` — author
14595 // copies `"deadbeefcafe…0123 "` (trailing space) out of a
14596 // commit-message paragraph. Until this gate landed the empty-
14597 // pin arm passed (the string isn't empty), the resolver issued
14598 // `git fetch <remote> 'deadbeef… '` and the failure surfaced at
14599 // clone time with a quoting-confused git error far from the
14600 // source caixa.lisp. The new gate moves the check to caixa-
14601 // build time. Length is 41 (40 hex + space) so the length arm
14602 // fires first — pinned separately from the pure-length arm to
14603 // ensure the diagnostic surfaces *some* parser wording, not
14604 // silently pass through.
14605 let with_space = "0123456789abcdef0123456789abcdef01234567 ".to_string();
14606 let d = dep_with_fonte(DepSource::Git {
14607 repo: "github:pleme-io/caixa-teia".into(),
14608 tag: None,
14609 rev: Some(with_space.clone()),
14610 branch: None,
14611 });
14612 let err = d.validate().unwrap_err();
14613 let DepError::FontePinShape {
14614 pin, value, reason, ..
14615 } = err
14616 else {
14617 panic!("expected FontePinShape, got other variant");
14618 };
14619 assert_eq!(pin, ":rev");
14620 assert_eq!(value, with_space);
14621 assert!(
14622 !reason.is_empty(),
14623 "FontePinShape reason must be non-empty for whitespace-bearing :rev"
14624 );
14625 }
14626
14627 #[test]
14628 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value_for_rev() {
14629 // Diagnostic-shape pin on the `:rev` axis: every FontePinShape
14630 // variant on this axis names the offending dep's `:nome` + the
14631 // `:rev` axis + the offending value verbatim, so the author's
14632 // grep target is the literal `:rev "<value>"` block in
14633 // caixa.lisp. Sibling of the `fonte_pin_shape_diagnostic_
14634 // carries_offending_nome_pin_value` test on the refname-shaped
14635 // (`:tag` / `:branch`) axes.
14636 let d = dep_with_fonte(DepSource::Git {
14637 repo: "github:p/x".into(),
14638 tag: None,
14639 rev: Some("not-a-sha".into()),
14640 branch: None,
14641 });
14642 let msg = d
14643 .validate()
14644 .expect_err(":rev: expected FontePinShape")
14645 .to_string();
14646 assert!(
14647 msg.contains("\"caixa-teia\""),
14648 ":rev: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14649 );
14650 assert!(
14651 msg.contains(":rev"),
14652 ":rev: diagnostic must name the offending pin axis, got {msg:?}"
14653 );
14654 assert!(
14655 msg.contains("not-a-sha"),
14656 ":rev: diagnostic must quote the offending value verbatim, got {msg:?}"
14657 );
14658 }
14659
14660 #[test]
14661 fn fonte_pin_empty_fires_before_pin_shape() {
14662 // Order pin: a `Some("")` `:tag` is the more self-locating
14663 // diagnostic (the author chose an axis but left it blank;
14664 // grep is unambiguous), so it fires before the shape gate
14665 // even when both arms would match. Pinned so a future
14666 // reordering surfaces here. Mirrors the
14667 // `fonte_repo_empty_fires_before_pin_missing` ordering
14668 // discipline on the peer per-axis arms.
14669 let d = dep_with_fonte(DepSource::Git {
14670 repo: "github:pleme-io/caixa-teia".into(),
14671 tag: Some(String::new()),
14672 rev: None,
14673 branch: None,
14674 });
14675 assert!(matches!(
14676 d.validate().unwrap_err(),
14677 DepError::FontePinEmpty { ref pin, .. } if pin == ":tag"
14678 ));
14679 }
14680
14681 #[test]
14682 fn fonte_pin_shape_fires_after_repo_empty() {
14683 // Order pin: `:repo ""` is the more self-locating axis
14684 // (every git source needs a repo; the per-pin shape gate is
14685 // secondary), so the repo-empty arm fires before the
14686 // per-pin shape arm even when both are violated. Pinned so
14687 // a future reordering surfaces here. Mirrors
14688 // `fonte_repo_empty_fires_before_pin_missing` on the
14689 // adjacent axis pair.
14690 let d = dep_with_fonte(DepSource::Git {
14691 repo: String::new(),
14692 tag: Some("v0.1.0 ".into()),
14693 rev: None,
14694 branch: None,
14695 });
14696 assert!(matches!(
14697 d.validate().unwrap_err(),
14698 DepError::FonteRepoEmpty { .. }
14699 ));
14700 }
14701
14702 #[test]
14703 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value() {
14704 // Diagnostic-shape pin across both refname-shaped axes
14705 // (`:tag` + `:branch`): every `FontePinShape` variant names
14706 // the offending dep's `:nome` + the offending pin axis + the
14707 // offending value verbatim, so the author's grep target is
14708 // unambiguous (the literal `:tag "<value>"` / `:branch
14709 // "<value>"` lands in caixa.lisp with quotes). Cover both
14710 // pin axes so a future variant addition forces a parallel
14711 // diagnostic-shape decision.
14712 for (pin_label, fonte) in [
14713 (
14714 ":tag",
14715 DepSource::Git {
14716 repo: "github:p/x".into(),
14717 tag: Some("v0.1.0~1".into()),
14718 rev: None,
14719 branch: None,
14720 },
14721 ),
14722 (
14723 ":branch",
14724 DepSource::Git {
14725 repo: "github:p/x".into(),
14726 tag: None,
14727 rev: None,
14728 branch: Some("feature/foo*".into()),
14729 },
14730 ),
14731 ] {
14732 let d = dep_with_fonte(fonte);
14733 let msg = d
14734 .validate()
14735 .expect_err(&format!("{pin_label}: expected FontePinShape"))
14736 .to_string();
14737 assert!(
14738 msg.contains("\"caixa-teia\""),
14739 "{pin_label}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14740 );
14741 assert!(
14742 msg.contains(pin_label),
14743 "{pin_label}: diagnostic must name the offending pin axis, got {msg:?}"
14744 );
14745 }
14746 }
14747
14748 #[test]
14749 fn git_source_json_round_trip() {
14750 let src = DepSource::Git {
14751 repo: "github:pleme-io/caixa-teia".into(),
14752 tag: Some("v0.1.0".into()),
14753 rev: None,
14754 branch: None,
14755 };
14756 let s = serde_json::to_string(&src).unwrap();
14757 assert!(s.contains(&format!(
14758 r#""{tipo}":"{git}""#,
14759 tipo = crate::render::DEP_SOURCE_KEY_TIPO,
14760 git = crate::render::DEP_SOURCE_TIPO_GIT,
14761 )));
14762 assert!(s.contains(r#""repo":"github:pleme-io/caixa-teia""#));
14763 assert!(s.contains(r#""tag":"v0.1.0""#));
14764 assert!(!s.contains("rev"));
14765 assert!(!s.contains("branch"));
14766 let round: DepSource = serde_json::from_str(&s).unwrap();
14767 assert_eq!(round, src);
14768 }
14769
14770 // ── DEP_SOURCE_{KEY_TIPO,TIPO_GIT,TIPO_PATH} drift-detection ────────
14771 //
14772 // The `#[serde(tag = "tipo", rename_all = "lowercase")]` derive
14773 // attribute on [`DepSource`] pins three load-bearing byte-sequences
14774 // that flow into every serialized `Dep.fonte` block: the outer
14775 // discriminator-key `"tipo"` the `tag = "tipo"` attribute names, and
14776 // the two admitted variant-tag values `"git"` / `"path"` the
14777 // `rename_all = "lowercase"` attribute pins as the discriminator's
14778 // closed-set arms. The three pin tests below round-trip a
14779 // fully-populated variant of each arm through
14780 // [`serde_json::to_value`] and assert each canonical byte-sequence
14781 // appears at its axis — pins a hypothetical future
14782 // `tag = "type"` / `tag = "source_type"` typo, a `rename_all`
14783 // rebrand (`"UPPERCASE"` / `"snake_case"` / `"kebab-case"`), or a
14784 // Rust-side variant rename (`Git` → `Repository`, `Path` → `Local`)
14785 // at build time rather than at fetch time when the resolver's
14786 // `Dep.fonte` dispatch silently fails to match on the drifted
14787 // discriminator. Same "serialize-and-check" discipline the peer
14788 // `M2_LIMITS_KEY_*`, `M2_BEHAVIOR_KEY_ON_*`, `SUPERVISOR_KEY_*`,
14789 // and `MEMBRO_KEY_*` drift-detection pins carry — extended here
14790 // to the last `#[serde(tag = ..., rename_all = ...)]` discriminator
14791 // family in caixa-core lacking a lifted peer.
14792
14793 #[test]
14794 fn dep_source_git_serde_keys_match_lifted_dep_source_key_consts() {
14795 // Fail-before-pass-after: a future `tag = "type"` at the derive
14796 // attribute would serialize under `"type":"git"`, and this test
14797 // would trip because `"tipo"` no longer appears at the emitted
14798 // discriminator key. A future `rename_all = "kebab-case"` /
14799 // `"snake_case"` (both no-ops on `Git` since it lacks internal
14800 // word boundaries) is caught by the sibling
14801 // `dep_source_path_serde_keys_match_lifted_dep_source_key_consts`
14802 // pin below (Path has no internal boundary either but the pair
14803 // catches any per-arm inconsistency). A future variant rename
14804 // `Git` → `Repository` would emit `"tipo":"repository"` and
14805 // trip this pin.
14806 let src = DepSource::Git {
14807 repo: "github:pleme-io/caixa-teia".into(),
14808 tag: Some("v0.1.0".into()),
14809 rev: None,
14810 branch: None,
14811 };
14812 let json = serde_json::to_value(&src).unwrap();
14813 let obj = json.as_object().expect("Git serializes as a JSON object");
14814 assert_eq!(
14815 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14816 .and_then(serde_json::Value::as_str),
14817 Some(crate::render::DEP_SOURCE_TIPO_GIT),
14818 "DepSource::Git must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14819 with value DEP_SOURCE_TIPO_GIT — attribute drift or variant rename \
14820 detected in {json}"
14821 );
14822 }
14823
14824 #[test]
14825 fn dep_source_path_serde_keys_match_lifted_dep_source_key_consts() {
14826 // Fail-before-pass-after: a future variant rename `Path` →
14827 // `Local` / `Filesystem` would emit `"tipo":"local"` and trip
14828 // this pin. A per-consumer disambiguation as the `defcaixa`
14829 // macro stabilizes ("caminho" → "path" for English-uniformity)
14830 // is scoped to the inner field key, not the discriminator; this
14831 // pin is orthogonal to that and catches only the outer
14832 // discriminator drift.
14833 let src = DepSource::Path {
14834 caminho: "../caixa-teia".into(),
14835 };
14836 let json = serde_json::to_value(&src).unwrap();
14837 let obj = json.as_object().expect("Path serializes as a JSON object");
14838 assert_eq!(
14839 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14840 .and_then(serde_json::Value::as_str),
14841 Some(crate::render::DEP_SOURCE_TIPO_PATH),
14842 "DepSource::Path must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14843 with value DEP_SOURCE_TIPO_PATH — attribute drift or variant rename \
14844 detected in {json}"
14845 );
14846 }
14847
14848 #[test]
14849 fn dep_source_key_consts_are_pairwise_distinct() {
14850 // Cross-axis collapse detector: a hypothetical future edit that
14851 // accidentally set two of the three consts to the same byte
14852 // (`DEP_SOURCE_TIPO_GIT = "path"` typo matching a peer arm) would
14853 // pass every per-arm serialize pin above but silently collapse
14854 // the discriminator's closed-set arms onto one another; this pin
14855 // catches the collapse at build time.
14856 assert_ne!(
14857 crate::render::DEP_SOURCE_KEY_TIPO,
14858 crate::render::DEP_SOURCE_TIPO_GIT,
14859 );
14860 assert_ne!(
14861 crate::render::DEP_SOURCE_KEY_TIPO,
14862 crate::render::DEP_SOURCE_TIPO_PATH,
14863 );
14864 assert_ne!(
14865 crate::render::DEP_SOURCE_TIPO_GIT,
14866 crate::render::DEP_SOURCE_TIPO_PATH,
14867 );
14868 }
14869
14870 #[test]
14871 fn dep_source_tipo_variant_consts_are_ascii_lowercase_shape() {
14872 // Shape pin against `rename_all` drift: the two variant-tag
14873 // consts must be ASCII-lowercase-only to match the
14874 // `rename_all = "lowercase"` attribute the derive uses; a future
14875 // rebrand to `"UPPERCASE"` / `"PascalCase"` at the attribute
14876 // would emit `"GIT"` / `"Git"` instead and trip this pin.
14877 for (label, s) in [
14878 ("DEP_SOURCE_TIPO_GIT", crate::render::DEP_SOURCE_TIPO_GIT),
14879 ("DEP_SOURCE_TIPO_PATH", crate::render::DEP_SOURCE_TIPO_PATH),
14880 ] {
14881 assert!(!s.is_empty(), "{label} must not be empty");
14882 assert!(
14883 s.bytes().all(|b| b.is_ascii_lowercase()),
14884 "{label} must be ASCII-lowercase-only (matching \
14885 rename_all = \"lowercase\"), got {s:?}",
14886 );
14887 }
14888 }
14889
14890 // ── per-entry :caracteristicas set-not-multiset gate ────────────
14891 //
14892 // Every Vec-keyed-by-name authoring surface on the typed Caixa
14893 // surface that identifies its entries by a name field now uniformly
14894 // closes the set-not-multiset discipline at build time (cite
14895 // `validate_caracteristicas`'s peer-axis enumeration). The
14896 // `:caracteristicas` axis is per-`Dep`: the feature-toggle slot is
14897 // set-shaped (a feature is either enabled or not — there is no
14898 // `feature × 2` semantic), so two entries naming the same feature
14899 // are a redundant declaration the caixa-resolver's lacre pipeline
14900 // would silently dedup at resolve time. The empty-feature arm
14901 // closes the parallel "operationally-meaningless value" axis on
14902 // the same slot. Same linear-walk + `HashSet` + first-collision
14903 // shape every peer set gate uses; same empty-first cascade every
14904 // peer per-entry shape + duplicate gate uses (the empty-feature
14905 // axis is the more-actionable defect since two `""` entries would
14906 // both report `caracteristica: ""` under a duplicate-first
14907 // ordering, with no way to distinguish the offending site).
14908
14909 fn dep_with_features(features: &[&str]) -> Dep {
14910 Dep {
14911 nome: "caixa-teia".into(),
14912 versao: "^0.1".into(),
14913 fonte: None,
14914 opcional: false,
14915 caracteristicas: features.iter().map(|s| (*s).into()).collect(),
14916 }
14917 }
14918
14919 #[test]
14920 fn validate_rejects_empty_caracteristica() {
14921 // Fail-before-pass-after pin: every pre-gate codebase accepted
14922 // `(:caracteristicas (""))` cleanly (the `Vec<String>` field
14923 // imposed no per-entry shape contract), the dep validated, and
14924 // the empty feature would have reached the future caixa-resolver
14925 // lacre pipeline as a no-op feature enable — silently dropping
14926 // the author's intent far from the source `caixa.lisp`. The new
14927 // gate surfaces the structural defect at the typed-validate
14928 // surface with a self-locating diagnostic naming the offending
14929 // dep's `:nome`.
14930 let d = dep_with_features(&[""]);
14931 assert!(
14932 matches!(d.validate().unwrap_err(), DepError::CaracteristicaEmpty { ref nome } if nome == "caixa-teia"),
14933 "expected CaracteristicaEmpty, got {:?}",
14934 d.validate(),
14935 );
14936 }
14937
14938 #[test]
14939 fn validate_rejects_duplicate_caracteristica() {
14940 // Fail-before-pass-after pin on the set-not-multiset arm: the
14941 // feature-toggle slot is set-shaped, so `(:caracteristicas
14942 // ("http" "http"))` is a redundant declaration the lacre
14943 // pipeline dedupes silently at resolve time. The diagnostic
14944 // names the offending dep + the colliding feature verbatim so
14945 // the author can grep their caixa.lisp for `:caracteristicas`
14946 // and fix it in one edit. First-collision determinism is
14947 // pinned separately below.
14948 let d = dep_with_features(&["http", "http"]);
14949 assert!(
14950 matches!(
14951 d.validate().unwrap_err(),
14952 DepError::CaracteristicaDuplicate { ref nome, ref caracteristica }
14953 if nome == "caixa-teia" && caracteristica == "http"
14954 ),
14955 "expected CaracteristicaDuplicate, got {:?}",
14956 d.validate(),
14957 );
14958 }
14959
14960 #[test]
14961 fn validate_accepts_distinct_caracteristicas() {
14962 // The canonical authoring shape — every feature distinct — must
14963 // remain a clean pass (positive control sweep). Covers the
14964 // canonical kebab-case feature names a target caixa typically
14965 // declares.
14966 dep_with_features(&["http", "json", "tls"])
14967 .validate()
14968 .unwrap();
14969 }
14970
14971 #[test]
14972 fn validate_accepts_single_caracteristica() {
14973 // Single-element list is the minimum non-empty shape; passes
14974 // the gate as the identity of the duplicate check (no second
14975 // entry to collide with).
14976 dep_with_features(&["http"]).validate().unwrap();
14977 }
14978
14979 #[test]
14980 fn validate_accepts_empty_caracteristicas_list() {
14981 // The bare-dep authoring shape (`Dep::simple` / `Dep::git`)
14982 // produces `caracteristicas: Vec::new()`; the empty list is
14983 // the gate's empty-set identity and passes vacuously. Pin
14984 // this so a future tightening that requires ≥1 feature
14985 // surfaces here as a test failure rather than a silent
14986 // contract narrowing.
14987 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14988 assert!(dep_with_features(&[]).validate().is_ok());
14989 }
14990
14991 #[test]
14992 fn validate_caracteristica_empty_fires_before_duplicate() {
14993 // Empty-first cascade: an entry with an empty feature *and*
14994 // duplicate entries surfaces the empty diagnostic first. The
14995 // empty-feature axis is the more-actionable defect since
14996 // `caracteristica: ""` is unambiguous; under duplicate-first
14997 // ordering the diagnostic could report the empty string from
14998 // either of two empty entries with no way to distinguish.
14999 // Mirrors the peer empty-before-duplicate ordering
15000 // discipline every per-entry shape + duplicate gate establishes
15001 // (`SupervisorSpec::validate`'s `EmptyChildName` arm before
15002 // `DuplicateChildCaixa`, `validate_membros`'s
15003 // `MembroCaixaEmpty` arm before `MembroDuplicate`).
15004 let d = dep_with_features(&["", "http", "http"]);
15005 assert!(matches!(
15006 d.validate().unwrap_err(),
15007 DepError::CaracteristicaEmpty { .. }
15008 ));
15009 }
15010
15011 #[test]
15012 fn validate_caracteristica_duplicate_first_collision_determinism() {
15013 // Three matching entries: the second occurrence surfaces the
15014 // diagnostic (the second is the first *collision* — the first
15015 // entry is the establishing one, not a duplicate). Mirrors
15016 // every peer first-collision posture
15017 // (`SupervisorError::DuplicateChildCaixa` reports the second
15018 // collision, `AplicacaoError::MembroDuplicate` reports the
15019 // second, `DepError::DuplicateNome` reports the second).
15020 // Pinning this so a future shortcut that flips to last-
15021 // collision (or non-deterministic) surfaces here.
15022 let d = dep_with_features(&["http", "http", "http"]);
15023 assert!(matches!(
15024 d.validate().unwrap_err(),
15025 DepError::CaracteristicaDuplicate { ref caracteristica, .. } if caracteristica == "http"
15026 ));
15027 }
15028
15029 #[test]
15030 fn validate_per_entry_shape_fires_before_caracteristicas() {
15031 // Per-entry shape precedence: a dep with a malformed `:nome`
15032 // (uppercase) AND duplicate `:caracteristicas` surfaces the
15033 // narrower `NomeInvalid` diagnostic first, not the set-gate
15034 // diagnostic. The `:nome` is the self-locating axis (every
15035 // diagnostic from the caracteristicas gate quotes the
15036 // offending dep's `:nome` to anchor the grep target —
15037 // surfacing the malformed name first keeps that anchor
15038 // valid). Same precedence shape every peer per-entry-shape
15039 // arm establishes against its peer set-gate
15040 // (`validate_deps_per_entry_validate_fires_before_duplicate_in_deps`
15041 // on the cross-entry `:nome` axis).
15042 let d = Dep {
15043 nome: "Caixa-Teia".into(), // uppercase — DNS-1123 violation
15044 versao: "^0.1".into(),
15045 fonte: None,
15046 opcional: false,
15047 caracteristicas: vec!["http".into(), "http".into()],
15048 };
15049 assert!(matches!(
15050 d.validate().unwrap_err(),
15051 DepError::NomeInvalid { .. }
15052 ));
15053 }
15054
15055 // ── per-entry :caracteristicas value-shape gate ──────────────────
15056 //
15057 // Until this gate landed `:caracteristicas` only refused the empty
15058 // string and cross-entry duplicates: a non-empty distinct but
15059 // structurally invalid feature name silently passed validate and the
15060 // failure surfaced at `cargo metadata` time as Cargo's
15061 // `restricted_names::validate_feature_name` parser rejection, far from
15062 // the source `caixa.lisp` with no field naming which `:deps` entry's
15063 // `:caracteristicas` carried the typo. The lifted predicate makes the
15064 // Cargo-feature-name-grammar intersection-floor a substrate-level
15065 // invariant at validate time. Same trajectory as the eight peer
15066 // value-shape predicates each typed surface downstream of a structured
15067 // grammar already follows.
15068
15069 #[test]
15070 fn validate_rejects_caracteristica_with_leading_plus() {
15071 // Fail-before-pass-after pin on the canonical Cargo
15072 // `+<feature>` activation-form-in-feature-name-slot footgun.
15073 // Cargo's `[dependencies.<dep>.features]` list grammar accepts
15074 // `+optional-feature` as an enablement of a previously-disabled
15075 // feature; pasting that activation form into `:caracteristicas`
15076 // (which names the feature itself) silently passed pre-gate and
15077 // failed at `cargo metadata` parse time.
15078 let d = dep_with_features(&["+http"]);
15079 let err = d.validate().unwrap_err();
15080 assert!(
15081 matches!(
15082 err,
15083 DepError::CaracteristicaInvalid { ref nome, ref caracteristica, .. }
15084 if nome == "caixa-teia" && caracteristica == "+http"
15085 ),
15086 "expected CaracteristicaInvalid, got {err:?}"
15087 );
15088 }
15089
15090 #[test]
15091 fn validate_rejects_caracteristica_with_leading_hyphen() {
15092 // Fail-before-pass-after pin on the leading-hyphen footgun. `-`
15093 // is a legitimate continuation character (kebab-case feature
15094 // names like `runtime-tokio` pass) but Cargo rejects it at the
15095 // start; the structural defect — and its CLI-argument-injection
15096 // adjacency at any downstream Cargo subprocess invocation — is
15097 // closed at validate time, not at `cargo metadata` time.
15098 let d = dep_with_features(&["-json"]);
15099 let err = d.validate().unwrap_err();
15100 assert!(
15101 matches!(
15102 err,
15103 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "-json"
15104 ),
15105 "expected CaracteristicaInvalid, got {err:?}"
15106 );
15107 }
15108
15109 #[test]
15110 fn validate_rejects_caracteristica_with_leading_dot() {
15111 // Fail-before-pass-after pin on the leading-dot footgun. `.` is
15112 // a legitimate continuation character (version-suffix shapes
15113 // like `feat.v2` pass) but the leading-dot form is the
15114 // canonical dotted-version-suffix-as-feature-name confusion.
15115 let d = dep_with_features(&[".feat"]);
15116 let err = d.validate().unwrap_err();
15117 assert!(matches!(
15118 err,
15119 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == ".feat"
15120 ));
15121 }
15122
15123 #[test]
15124 fn validate_rejects_caracteristica_with_whitespace() {
15125 // Fail-before-pass-after pin on the embedded-whitespace footgun:
15126 // a feature name with a space inside is structurally a multi-
15127 // token blob (the canonical paste-from-doc footgun, or an
15128 // accidental `"http server"` where the author meant
15129 // `"http-server"`).
15130 let d = dep_with_features(&["http feature"]);
15131 let err = d.validate().unwrap_err();
15132 assert!(matches!(
15133 err,
15134 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http feature"
15135 ));
15136 }
15137
15138 #[test]
15139 fn validate_rejects_caracteristica_with_comma() {
15140 // Fail-before-pass-after pin on the embedded-comma footgun:
15141 // the list-separator-belongs-to-the-list-grammar
15142 // miscomprehension where the author writes
15143 // `:caracteristicas ("http,json")` intending two features but
15144 // the `Vec<String>` field consumes the bare token as one entry.
15145 let d = dep_with_features(&["http,json"]);
15146 let err = d.validate().unwrap_err();
15147 assert!(matches!(
15148 err,
15149 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http,json"
15150 ));
15151 }
15152
15153 #[test]
15154 fn validate_rejects_caracteristica_with_slash() {
15155 // Fail-before-pass-after pin on the embedded-slash footgun:
15156 // Cargo's `dep/feat` namespaced-dep syntax applies inside
15157 // `[dependencies.<dep>.features]` list entries that already
15158 // name the parent dep (so the syntax says "enable feature
15159 // `feat` on a transitive dep `dep`"); `:caracteristicas` is
15160 // per-dep already (a sibling slot on the `Dep` itself), so the
15161 // segment separator within an entry must be `-`, `_`, `+`,
15162 // or `.`. The diagnostic remediation points at the canonical
15163 // Cargo namespaced-dep discipline.
15164 let d = dep_with_features(&["http/json"]);
15165 let err = d.validate().unwrap_err();
15166 assert!(matches!(
15167 err,
15168 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http/json"
15169 ));
15170 }
15171
15172 #[test]
15173 fn validate_rejects_caracteristica_with_non_ascii() {
15174 // Fail-before-pass-after pin on the un-percent-encoded non-ASCII
15175 // byte footgun: NFC-vs-NFD normalization across filesystems
15176 // silently rewrites the feature-key, breaking the lacre's
15177 // content-addressing invariant. Pinned at a canonical
15178 // smart-quote-paste shape (`café`) where the raw `é` byte is the
15179 // documented APFS round-trip break.
15180 let d = dep_with_features(&["caf\u{e9}"]);
15181 let err = d.validate().unwrap_err();
15182 assert!(matches!(
15183 err,
15184 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "caf\u{e9}"
15185 ));
15186 }
15187
15188 #[test]
15189 fn validate_rejects_caracteristica_with_control_character() {
15190 // Fail-before-pass-after pin on the embedded-control-character
15191 // footgun: a CR/LF or any 0x00..0x1F / 0x7F byte landing in a
15192 // feature name is the canonical paste-from-multiline-doc
15193 // footgun the predicate's reason wording specifically calls out.
15194 let d = dep_with_features(&["http\njson"]);
15195 let err = d.validate().unwrap_err();
15196 assert!(matches!(err, DepError::CaracteristicaInvalid { .. }));
15197 }
15198
15199 #[test]
15200 fn validate_accepts_canonical_caracteristicas_shapes() {
15201 // Positive control sweep: every canonical Cargo feature name
15202 // shape the pleme-io ecosystem uses must still pass. Mirrors
15203 // the substrate-side `cargo_feature_name_accepts_canonical_forms`
15204 // sweep — drift between either landing site and the predicate's
15205 // accepted set is a build error visible at this pair of tests,
15206 // not a per-renderer "this passed validate but failed at
15207 // cargo metadata time" surprise on the next acceptance.
15208 for s in [
15209 "http",
15210 "json",
15211 "derive",
15212 "serde_json",
15213 "runtime-tokio",
15214 "tokio.full",
15215 "v0.1",
15216 "http+json",
15217 "_internal",
15218 "__private",
15219 "default",
15220 "rt-multi-thread",
15221 "feat.v2",
15222 ] {
15223 let d = dep_with_features(&[s]);
15224 d.validate().unwrap_or_else(|e| {
15225 panic!("canonical Cargo feature name {s:?} must pass validate: {e:?}")
15226 });
15227 }
15228 }
15229
15230 #[test]
15231 fn validate_caracteristica_empty_fires_before_invalid() {
15232 // Cascade precedence pin: an entry list with both an empty
15233 // feature AND an invalid-shape feature surfaces the
15234 // `CaracteristicaEmpty` arm first (the empty value carries no
15235 // self-locating data — `caracteristica: ""` is the diagnostic
15236 // with no way to anchor a grep target — so closing the empty
15237 // axis first preserves the per-entry-shape diagnostic's
15238 // self-locating discipline). Same empty-first cascade every
15239 // peer per-entry shape gate establishes
15240 // (`SupervisorSpec::validate`'s `EmptyChildName` before
15241 // `ChildCaixaInvalid`, `validate_membros`'s `MembroCaixaEmpty`
15242 // before `MembroCaixaInvalid`).
15243 let d = dep_with_features(&["", "+http"]);
15244 assert!(matches!(
15245 d.validate().unwrap_err(),
15246 DepError::CaracteristicaEmpty { .. }
15247 ));
15248 }
15249
15250 #[test]
15251 fn validate_caracteristica_invalid_fires_before_duplicate() {
15252 // Per-entry-shape precedence pin: an entry list with the same
15253 // invalid feature shape declared twice surfaces the
15254 // `CaracteristicaInvalid` diagnostic on the first entry, not
15255 // the `CaracteristicaDuplicate` on the second collision. The
15256 // per-entry shape gate fires before the cross-entry set gate
15257 // — same precedence shape every peer two-arm-plus-set gate
15258 // establishes (`SupervisorSpec::validate`'s
15259 // `ChildCaixaInvalid` before `DuplicateChildCaixa`,
15260 // `validate_membros`'s `MembroCaixaInvalid` before
15261 // `MembroDuplicate`, `Dep::validate`'s `NomeInvalid` before
15262 // cross-list `DuplicateNome`).
15263 let d = dep_with_features(&["+http", "+http"]);
15264 assert!(matches!(
15265 d.validate().unwrap_err(),
15266 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "+http"
15267 ));
15268 }
15269
15270 #[test]
15271 fn validate_rejects_caracteristica_at_65_byte_boundary() {
15272 // Boundary pin on the 64-byte cap — both the boundary-accepting
15273 // case and the boundary-exceeding case in one place, so a
15274 // future cap shift surfaces both arms simultaneously, mirroring
15275 // the peer `cargo_feature_name_rejects_at_65_byte_boundary`
15276 // predicate-level pin at the dep-axis landing site.
15277 let max_ok = "a".repeat(64);
15278 dep_with_features(&[&max_ok])
15279 .validate()
15280 .unwrap_or_else(|e| panic!("64-byte feature name must pass: {e:?}"));
15281 let too_long = "a".repeat(65);
15282 let d = dep_with_features(&[&too_long]);
15283 assert!(matches!(
15284 d.validate().unwrap_err(),
15285 DepError::CaracteristicaInvalid { .. }
15286 ));
15287 }
15288
15289 // ── self-dep cross-slot gate ─────────────────────────────────────
15290
15291 #[test]
15292 fn validate_no_self_dep_rejects_self_in_deps() {
15293 // A caixa whose `:deps` lists its own `:nome` is a one-node
15294 // cycle in the lacre closure's dep-graph traversal — rejected,
15295 // naming the parent and the offending list tag.
15296 let deps = vec![
15297 Dep::simple("caixa-teia", "^0.1"),
15298 Dep::simple("orquestra", "^0.1"),
15299 ];
15300 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15301 assert!(
15302 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
15303 "got {err:?}"
15304 );
15305 }
15306
15307 #[test]
15308 fn validate_no_self_dep_rejects_self_in_deps_dev() {
15309 // Same gate on the `:deps-dev` axis — neither dep list is a
15310 // second-class citizen on the self-edge invariant.
15311 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15312 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15313 assert!(
15314 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
15315 "got {err:?}"
15316 );
15317 }
15318
15319 #[test]
15320 fn validate_no_self_dep_deps_fires_before_deps_dev() {
15321 // Walk order pin: a caixa that self-references on both lists
15322 // surfaces the `:deps` arm first — the load-bearing axis the
15323 // lacre closure resolves at every build. Mirrors the canonical
15324 // [`Caixa::validate_deps`] cascade (`:deps` → `:deps-dev`).
15325 let deps = vec![Dep::simple("orquestra", "^0.1")];
15326 let deps_dev = vec![Dep::simple("orquestra", "^0.2")];
15327 let err = validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap_err();
15328 assert!(
15329 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
15330 "got {err:?}"
15331 );
15332 }
15333
15334 #[test]
15335 fn validate_no_self_dep_accepts_distinct_names() {
15336 // Positive control: every dep names a distinct caixa. The
15337 // canonical author surface — peer of
15338 // [`validate_no_self_supervision_accepts_distinct_children`].
15339 let deps = vec![
15340 Dep::simple("caixa-teia", "^0.1"),
15341 Dep::simple("caixa-arch", "^0.1"),
15342 ];
15343 let deps_dev = vec![Dep::simple("caixa-test", "^0.1")];
15344 validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap();
15345 }
15346
15347 #[test]
15348 fn validate_no_self_dep_empty_lists_pass() {
15349 // A caixa with no declared deps has nothing to self-reference —
15350 // the gate is vacuously satisfied. Peer of
15351 // [`validate_no_self_supervision_empty_children_is_ok`].
15352 validate_no_self_dep(&[], &[], "orquestra").unwrap();
15353 }
15354
15355 #[test]
15356 fn validate_no_self_dep_diagnostic_carries_offending_list_and_nome() {
15357 // Diagnostic-shape pin (peer with
15358 // [`validate_no_self_supervision`]'s diagnostic): the error's
15359 // Display surfaces both the offending list tag and the
15360 // parent's `:nome` verbatim, so the author can grep their
15361 // caixa.lisp for the offending block in one edit. Names
15362 // `:bibliotecas` / `:exe` / `:servicos` as the corrective
15363 // surface — every legitimate "I want to use code from this
15364 // caixa" intent routes through one of those three slots.
15365 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15366 let rendered = validate_no_self_dep(&[], &deps_dev, "orquestra")
15367 .unwrap_err()
15368 .to_string();
15369 assert!(
15370 rendered.contains(crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
15371 "diagnostic must name the offending list tag: {rendered}",
15372 );
15373 assert!(
15374 rendered.contains("orquestra"),
15375 "diagnostic must quote the parent caixa name: {rendered}",
15376 );
15377 assert!(
15378 rendered.contains(":bibliotecas"),
15379 "diagnostic must point at the corrective code-surface slot: {rendered}",
15380 );
15381 }
15382
15383 #[test]
15384 fn validate_no_self_dep_accepts_coincidental_substring_match() {
15385 // Identity is exact-string equality, not substring — a dep
15386 // named `"orquestra-helper"` is a distinct caixa even when the
15387 // parent is `"orquestra"`. Pin the exact-match discipline so a
15388 // future relaxation that uses `contains` surfaces here, peer
15389 // with the supervision-tree and Aplicacao-membership gates
15390 // which all use exact-string equality on the typed identity.
15391 let deps = vec![Dep::simple("orquestra-helper", "^0.1")];
15392 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15393 }
15394
15395 // ── drift-detection: DEP_AUTHOR_KEY_{DEPS,DEPS_DEV} pin ─────────────
15396
15397 #[test]
15398 fn dep_author_key_consts_pin_canonical_kebab_case_labels() {
15399 // Scalar-value pin: the two author-facing kebab-case labels the
15400 // `(defcaixa … :deps ((…)) :deps-dev ((…)))` surface admits on
15401 // the two-list dep-graph slot axis, one arm per typed slot.
15402 // Mirrors the peer scalar-value pin the sibling
15403 // [`crate::M2_AUTHOR_KEY_LIMITS`] /
15404 // [`crate::M2_AUTHOR_KEY_BEHAVIOR`] /
15405 // [`crate::M2_AUTHOR_KEY_UPGRADE_FROM`] (f49c8b0) M2 top-level
15406 // author-labels, [`crate::M3_AUTHOR_KEY_MEMBROS`] etc.
15407 // (882f498) M3 top-level author-labels, and
15408 // [`crate::SUPERVISOR_AUTHOR_KEY_ESTRATEGIA`] etc. (be40492)
15409 // Supervisor top-level author-labels carry, so every kind-scoped
15410 // typed-slot-family axis routes through one canonical per-arm
15411 // declaration.
15412 //
15413 // A future rebrand (`:deps` → `:dependencies` matching Cargo's
15414 // verbatim key, `:deps-dev` → `:dev-dependencies` matching the
15415 // same, `:deps` / `:deps-dev` → `:runtime-deps` / `:dev-deps`
15416 // for symmetry) lands as an edit to exactly one const, and
15417 // every consumer that reaches for the label picks it up at
15418 // build time rather than at runtime as a downstream mismatch on
15419 // a `DepError::DuplicateNome { list: … }` diagnostic far from
15420 // the rename's commit.
15421 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS, ":deps");
15422 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS_DEV, ":deps-dev");
15423 }
15424
15425 #[test]
15426 fn dep_author_key_consts_are_pairwise_distinct() {
15427 // Distinct-labels pin: the two `:deps` / `:deps-dev` labels
15428 // must not collapse onto one byte-string. A future copy-paste
15429 // slip that renamed both consts to the same value (or a rebrand
15430 // that dropped the `-dev` suffix from one but not the other)
15431 // would leave every `DepError::DuplicateNome { list: … }`
15432 // diagnostic naming an unattributable list — the linter would
15433 // route the author to the wrong caixa.lisp block, or the
15434 // cross-list precedence gate
15435 // (`validate_deps_duplicate_in_deps_fires_before_duplicate_in_deps_dev`)
15436 // would surface a `:deps`-tagged diagnostic on a `:deps-dev`
15437 // duplicate. Peer of the sibling
15438 // `m2_author_key_consts_are_pairwise_distinct`-shape gates the
15439 // other top-level kind-scoped slot-family axes carry
15440 // (implicitly held by their different byte-values today).
15441 assert_ne!(
15442 crate::render::DEP_AUTHOR_KEY_DEPS,
15443 crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15444 "DEP_AUTHOR_KEY_{{DEPS,DEPS_DEV}} consts must be pairwise-distinct \
15445 so a `DepError::DuplicateNome {{ list: … }}` diagnostic \
15446 self-locates the offending block in the author's caixa.lisp",
15447 );
15448 }
15449
15450 #[test]
15451 fn validate_no_self_dep_routes_through_lifted_dep_author_key_consts() {
15452 // Production-through-const pin: the two per-arm list tags
15453 // [`validate_no_self_dep`] threads onto the `list:` field of a
15454 // returned [`DepError::DepIsSelf`] route through the lifted
15455 // [`crate::DEP_AUTHOR_KEY_DEPS`] /
15456 // [`crate::DEP_AUTHOR_KEY_DEPS_DEV`] consts. A future drift at
15457 // the walker (a rename that reaches one arm but not the const,
15458 // or vice versa) surfaces here at build time rather than at
15459 // runtime as a `feira lint` diagnostic naming the wrong list
15460 // tag. Mirror of the peer
15461 // [`crate::Caixa::declared_servico_slots`] production tagger
15462 // pin (f49c8b0) on the sibling M2 top-level slot axis, extended
15463 // onto the two-list dep-graph gate.
15464 let deps = vec![Dep::simple("orquestra", "^0.1")];
15465 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15466 let DepError::DepIsSelf { list, .. } = err else {
15467 panic!("expected DepIsSelf from :deps walk");
15468 };
15469 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS);
15470
15471 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15472 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15473 let DepError::DepIsSelf { list, .. } = err else {
15474 panic!("expected DepIsSelf from :deps-dev walk");
15475 };
15476 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS_DEV);
15477 }
15478
15479 // ── Dep::nome accessor pins ───────────────────────────────────────
15480 //
15481 // Three coherence pins on the lifted `Dep::nome` accessor: byte-equal
15482 // projection over the plain-shorthand / explicit-git / explicit-path
15483 // fixture triad the [`Dep`] docstring lists (so the accessor's
15484 // accept-set is exercised across every author-surface `:fonte`
15485 // shape); by-borrow pointer identity so the projection stays
15486 // zero-copy at every consumer site; and validate-composition through
15487 // the [`validate_no_self_dep`] cross-slot gate reading its
15488 // parent-name equality check through the lifted accessor rather than
15489 // the raw field.
15490
15491 #[test]
15492 fn dep_nome_returns_declared_nome_across_fonte_shapes() {
15493 // Plain-shorthand form (`:fonte None`).
15494 assert_eq!(Dep::simple("caixa-teia", "^0.1").nome(), "caixa-teia");
15495 // Explicit git-source form with a tag pin — same accessor path.
15496 assert_eq!(
15497 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").nome(),
15498 "caixa-teia",
15499 );
15500 // Explicit path-source form.
15501 assert_eq!(
15502 Dep {
15503 nome: "caixa-teia".to_string(),
15504 versao: "0.1.0".to_string(),
15505 fonte: Some(DepSource::Path {
15506 caminho: "../caixa-teia".to_string(),
15507 }),
15508 opcional: false,
15509 caracteristicas: Vec::new(),
15510 }
15511 .nome(),
15512 "caixa-teia",
15513 );
15514 // The empty-string `:nome` sentinel (which [`Dep::validate`]
15515 // refuses through the [`DepError::NomeEmpty`] arm) still round-
15516 // trips as an empty `&str` through the accessor — the accessor is
15517 // a projection, not a gate; the gate is [`Dep::validate`].
15518 assert_eq!(Dep::simple("", "^0.1").nome(), "");
15519 }
15520
15521 #[test]
15522 fn dep_nome_is_by_borrow_pointer_identity() {
15523 // Zero-copy pin: the accessor must borrow into the field's own
15524 // storage, not clone. If a future rewrite regresses to
15525 // `self.nome.clone().leak()` or an owned-buffer shape, the two
15526 // pointers diverge and this pin fails at build time.
15527 let d = Dep::simple("caixa-teia", "^0.1");
15528 assert!(std::ptr::eq(d.nome().as_ptr(), d.nome.as_ptr()));
15529 }
15530
15531 // ── Dep::versao_requirement accessor pins ─────────────────────────
15532 //
15533 // Three coherence pins on the lifted `Dep::versao_requirement`
15534 // accessor: byte-equal projection over the plain-shorthand /
15535 // explicit-git / explicit-path fixture triad the [`Dep`] docstring
15536 // lists plus the empty-sentinel that round-trips as `""` (the accessor
15537 // is a projection, not a gate; the gate is [`Dep::validate`]); by-
15538 // borrow pointer identity so the projection stays zero-copy at every
15539 // consumer site; and validate-composition through the
15540 // [`crate::render::require_valid_versao_requirement`] cascade reading
15541 // its requirement-shape check through the lifted accessor rather than
15542 // the raw field.
15543 #[test]
15544 fn dep_versao_requirement_returns_declared_versao_across_fonte_shapes() {
15545 // Plain-shorthand form (`:fonte None`).
15546 assert_eq!(
15547 Dep::simple("caixa-teia", "^0.1").versao_requirement(),
15548 "^0.1",
15549 );
15550 // Explicit git-source form with a tag pin — same accessor path.
15551 assert_eq!(
15552 Dep::git(
15553 "caixa-teia",
15554 "~0.1.2",
15555 "github:pleme-io/caixa-teia",
15556 "v0.1.0"
15557 )
15558 .versao_requirement(),
15559 "~0.1.2",
15560 );
15561 // Explicit path-source form.
15562 assert_eq!(
15563 Dep {
15564 nome: "caixa-teia".to_string(),
15565 versao: "0.1.0".to_string(),
15566 fonte: Some(DepSource::Path {
15567 caminho: "../caixa-teia".to_string(),
15568 }),
15569 opcional: false,
15570 caracteristicas: Vec::new(),
15571 }
15572 .versao_requirement(),
15573 "0.1.0",
15574 );
15575 // The wildcard requirement (`"*"`) — the shorthand
15576 // `parse_requirement` accepts as `VersionReq::STAR` — round-trips
15577 // verbatim through the accessor as `"*"`, same byte-shape the
15578 // author wrote.
15579 assert_eq!(Dep::simple("caixa-teia", "*").versao_requirement(), "*");
15580 // The empty-string `:versao` sentinel (which [`Dep::validate`]
15581 // refuses through the [`DepError::VersaoEmpty`] arm) still round-
15582 // trips as an empty `&str` through the accessor — the accessor is
15583 // a projection, not a gate; the gate is [`Dep::validate`]. Peer
15584 // of the sibling [`Dep::nome`] empty-sentinel round-trip pin.
15585 assert_eq!(Dep::simple("caixa-teia", "").versao_requirement(), "");
15586 }
15587
15588 #[test]
15589 fn dep_versao_requirement_is_by_borrow_pointer_identity() {
15590 // Zero-copy pin: the accessor must borrow into the field's own
15591 // storage, not clone. If a future rewrite regresses to
15592 // `self.versao.clone().leak()` or an owned-buffer shape, the two
15593 // pointers diverge and this pin fails at build time. Peer of the
15594 // sibling [`Dep::nome`] pointer-identity pin — same by-borrow
15595 // discipline extended onto the requirement-carrying axis.
15596 let d = Dep::simple("caixa-teia", "^0.1");
15597 assert!(std::ptr::eq(
15598 d.versao_requirement().as_ptr(),
15599 d.versao.as_ptr(),
15600 ));
15601 }
15602
15603 #[test]
15604 fn dep_validate_reads_requirement_through_accessor() {
15605 // Composition pin: the [`Dep::validate`]
15606 // [`crate::render::require_valid_versao_requirement`] cascade
15607 // consumes the requirement string through the lifted accessor —
15608 // both the requirement-gate input and the
15609 // [`DepError::VersaoInvalid`] error-body carrier route through
15610 // `self.versao_requirement()`. A valid requirement passes
15611 // (positive control); a malformed-but-non-empty requirement fails
15612 // and the diagnostic quotes the offending byte-string verbatim
15613 // (same shape the accessor projects), so a future regression that
15614 // detoured the requirement carrier through a different byte-
15615 // string (say the parsed `VersionReq`'s `Display`, or a
15616 // normalized rewrite) would surface here at build time. The
15617 // empty-`:versao` arm fires the [`DepError::VersaoEmpty`] variant
15618 // ahead of the parse arm, pinning the empty-first cascade the
15619 // accessor's `""` sentinel round-trip acknowledges.
15620 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15621 let err = Dep::simple("caixa-teia", "v0.1").validate().unwrap_err();
15622 assert!(
15623 matches!(
15624 &err,
15625 DepError::VersaoInvalid {
15626 nome,
15627 versao,
15628 ..
15629 } if nome == "caixa-teia" && versao == "v0.1",
15630 ),
15631 "expected VersaoInvalid quoting the accessor-projected requirement, got {err:?}",
15632 );
15633 let err = Dep::simple("caixa-teia", "").validate().unwrap_err();
15634 assert!(
15635 matches!(
15636 &err,
15637 DepError::VersaoEmpty { nome } if nome == "caixa-teia",
15638 ),
15639 "expected VersaoEmpty from the empty-first arm, got {err:?}",
15640 );
15641 }
15642
15643 // ── Dep::fonte accessor pins ──────────────────────────────────────
15644 //
15645 // Three coherence pins on the lifted `Dep::fonte` accessor: byte-
15646 // equal projection over the plain-shorthand (`:fonte None`) /
15647 // explicit-git-tag / explicit-path fixture triad the [`Dep`]
15648 // docstring lists (so the accessor's accept-set is exercised across
15649 // every author-surface `:fonte` shape and both `DepSource` variants);
15650 // pointer identity so the borrowed reference points into the field's
15651 // own `Option<DepSource>` storage (not a cloned side-buffer); and
15652 // validate-composition through the [`Dep::validate`] gate reading
15653 // its per-`:fonte` [`DepSource::validate`] delegation through the
15654 // lifted accessor rather than the raw `if let Some(ref fonte) =
15655 // self.fonte` bracket.
15656
15657 #[test]
15658 fn dep_fonte_returns_declared_source_across_shapes() {
15659 // Plain-shorthand form — `:fonte` omitted, accessor projects
15660 // the `None` partition the resolver-side default-fill treats
15661 // as "resolve through `github:<default-org>/<nome>`".
15662 assert!(Dep::simple("caixa-teia", "^0.1").fonte().is_none());
15663 // Explicit git-source form with a tag pin — same accessor path.
15664 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15665 match git.fonte() {
15666 Some(DepSource::Git {
15667 repo,
15668 tag,
15669 rev,
15670 branch,
15671 }) => {
15672 assert_eq!(repo, "github:pleme-io/caixa-teia");
15673 assert_eq!(tag.as_deref(), Some("v0.1.0"));
15674 assert!(rev.is_none());
15675 assert!(branch.is_none());
15676 }
15677 other => panic!("expected explicit git :fonte, got {other:?}"),
15678 }
15679 // Explicit path-source form — the dev-only local-filesystem
15680 // arm the [`Dep`] docstring's third fixture carries.
15681 let path = Dep {
15682 nome: "caixa-teia".to_string(),
15683 versao: "0.1.0".to_string(),
15684 fonte: Some(DepSource::Path {
15685 caminho: "../caixa-teia".to_string(),
15686 }),
15687 opcional: false,
15688 caracteristicas: Vec::new(),
15689 };
15690 match path.fonte() {
15691 Some(DepSource::Path { caminho }) => {
15692 assert_eq!(caminho, "../caixa-teia");
15693 }
15694 other => panic!("expected explicit path :fonte, got {other:?}"),
15695 }
15696 }
15697
15698 #[test]
15699 fn dep_fonte_is_by_borrow_pointer_identity() {
15700 // Zero-copy pin: the accessor must borrow into the field's own
15701 // `Option<DepSource>` storage, not clone into a side buffer. If
15702 // a future rewrite regresses to `self.fonte.clone()` or an
15703 // owned-buffer shape, the two pointers diverge and this pin
15704 // fails at build time. Peer of the sibling per-`Dep` [`Dep::nome`]
15705 // (eba2cde) / [`Dep::versao_requirement`] (05529b1) pointer-
15706 // identity pins — same by-borrow discipline extended onto the
15707 // outer-`Dep` `Option<&Composite>` composite-reference axis.
15708 let d = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15709 let accessed = d.fonte().expect("git :fonte present") as *const DepSource;
15710 let raw = d.fonte.as_ref().expect("git :fonte present") as *const DepSource;
15711 assert!(std::ptr::eq(accessed, raw));
15712 }
15713
15714 #[test]
15715 fn dep_validate_reads_fonte_through_accessor() {
15716 // Composition pin: [`Dep::validate`]'s per-`:fonte`
15717 // [`DepSource::validate`] delegation consumes the typed slot
15718 // through the lifted accessor — an author-omitted `:fonte`
15719 // still passes the outer gate (positive control), an explicit
15720 // well-formed git source with exactly one pin passes, and a
15721 // malformed git source (empty `:repo`) surfaces the
15722 // [`DepError::FonteRepoEmpty`] variant quoting the offending
15723 // dep's `:nome` verbatim so a future regression that detoured
15724 // the `:fonte` delegation through a different path (say a
15725 // per-scope override projector) would surface here at build
15726 // time. Peer of the sibling
15727 // `dep_validate_reads_requirement_through_accessor` composition
15728 // pin on the `:versao` axis.
15729 // Positive control 1: no `:fonte` at all.
15730 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15731 // Positive control 2: well-formed git source.
15732 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15733 .validate()
15734 .unwrap();
15735 // Negative control: empty `:repo` — the accessor still returns
15736 // `Some(&DepSource::Git { repo: "", … })` and the delegated
15737 // `DepSource::validate` gate raises the typed carrier.
15738 let bad = Dep {
15739 nome: "caixa-teia".to_string(),
15740 versao: "^0.1".to_string(),
15741 fonte: Some(DepSource::Git {
15742 repo: String::new(),
15743 tag: Some("v0.1.0".to_string()),
15744 rev: None,
15745 branch: None,
15746 }),
15747 opcional: false,
15748 caracteristicas: Vec::new(),
15749 };
15750 let err = bad.validate().unwrap_err();
15751 assert!(
15752 matches!(
15753 &err,
15754 DepError::FonteRepoEmpty { nome } if nome == "caixa-teia",
15755 ),
15756 "expected FonteRepoEmpty from the accessor-routed :fonte gate, got {err:?}",
15757 );
15758 }
15759
15760 #[test]
15761 fn validate_no_self_dep_reads_parent_equality_through_accessor() {
15762 // Composition pin: the cross-slot [`validate_no_self_dep`] gate
15763 // rejects a `:deps` entry whose `:nome` equals the parent caixa's
15764 // own `:nome` through the lifted accessor rather than the raw
15765 // field. Fails-before-passes-after: with the accessor lifted the
15766 // gate reads its equality check through `dep.nome() ==
15767 // parent_nome` on both the `:deps` and `:deps-dev` traversals, so
15768 // the diagnostic still names the offending list tag as expected.
15769 let deps = vec![Dep::simple("orquestra", "^0.1")];
15770 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15771 assert!(matches!(
15772 err,
15773 DepError::DepIsSelf {
15774 ref nome,
15775 list,
15776 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS,
15777 ));
15778 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15779 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15780 assert!(matches!(
15781 err,
15782 DepError::DepIsSelf {
15783 ref nome,
15784 list,
15785 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15786 ));
15787 // A non-matching `:nome` passes through the accessor gate.
15788 let deps = vec![Dep::simple("caixa-teia", "^0.1")];
15789 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15790 }
15791
15792 // ── Dep::caracteristicas accessor pins ────────────────────────────
15793 //
15794 // Three coherence pins on the lifted `Dep::caracteristicas` accessor:
15795 // byte-equal projection over the default-empty / single-entry /
15796 // multi-entry fixture triad (so the accessor's accept-set is
15797 // exercised across every author-surface `:caracteristicas` shape,
15798 // matching the peer sibling family's fixture-triad discipline); by-
15799 // borrow pointer identity so the projection stays zero-copy at every
15800 // consumer site; and validate-composition through the
15801 // [`Dep::validate_caracteristicas`] gate reading its per-entry
15802 // linear walk through the lifted accessor rather than the raw
15803 // `for c in &self.caracteristicas` bracket.
15804
15805 #[test]
15806 fn dep_caracteristicas_returns_declared_features_across_shapes() {
15807 // Default-empty form — the [`Dep::simple`] constructor's
15808 // `Vec::new()` fill; the accessor projects the empty slice
15809 // verbatim (no `None` collapse).
15810 assert!(
15811 Dep::simple("caixa-teia", "^0.1")
15812 .caracteristicas()
15813 .is_empty(),
15814 );
15815 // Single-entry form — the canonical Cargo-shaped one-feature
15816 // enable ([`crate::render::is_cargo_feature_name`] accepts the
15817 // `"http"` byte-string as a valid feature name).
15818 let one = Dep {
15819 nome: "caixa-teia".to_string(),
15820 versao: "^0.1".to_string(),
15821 fonte: None,
15822 opcional: false,
15823 caracteristicas: vec!["http".to_string()],
15824 };
15825 assert_eq!(one.caracteristicas(), &["http".to_string()]);
15826 // Multi-entry form — the substrate's set-shaped multi-feature
15827 // enable, exercising the accessor over a length-two slice with
15828 // no duplicate collapse.
15829 let two = Dep {
15830 nome: "caixa-teia".to_string(),
15831 versao: "^0.1".to_string(),
15832 fonte: None,
15833 opcional: false,
15834 caracteristicas: vec!["http".to_string(), "json".to_string()],
15835 };
15836 assert_eq!(
15837 two.caracteristicas(),
15838 &["http".to_string(), "json".to_string()],
15839 );
15840 }
15841
15842 #[test]
15843 fn dep_caracteristicas_is_by_borrow_pointer_identity() {
15844 // Zero-copy pin: the accessor must borrow into the field's own
15845 // `Vec<String>` storage, not clone into a side buffer. If a
15846 // future rewrite regresses to `self.caracteristicas.clone()` or
15847 // an owned-buffer shape, the two pointers diverge and this pin
15848 // fails at build time. Peer of the sibling per-`Dep`
15849 // [`Dep::nome`] (eba2cde) / [`Dep::versao_requirement`] (05529b1)
15850 // / [`Dep::fonte`] (d65d1bf) pointer-identity pins — same by-
15851 // borrow discipline extended onto the outer-`Dep` `&[String]`
15852 // slice-projection axis.
15853 let d = Dep {
15854 nome: "caixa-teia".to_string(),
15855 versao: "^0.1".to_string(),
15856 fonte: None,
15857 opcional: false,
15858 caracteristicas: vec!["http".to_string(), "json".to_string()],
15859 };
15860 assert!(std::ptr::eq(
15861 d.caracteristicas().as_ptr(),
15862 d.caracteristicas.as_ptr(),
15863 ));
15864 }
15865
15866 #[test]
15867 fn dep_validate_reads_caracteristicas_through_accessor() {
15868 // Composition pin: [`Dep::validate_caracteristicas`]'s per-entry
15869 // linear walk consumes the feature-toggle list through the
15870 // lifted accessor — a well-formed `:caracteristicas` set passes
15871 // (positive control), an empty-string entry surfaces the
15872 // [`DepError::CaracteristicaEmpty`] variant quoting the offending
15873 // `Dep::nome`, and a within-list duplicate surfaces the
15874 // [`DepError::CaracteristicaDuplicate`] variant so a future
15875 // regression that detoured the walk through a different byte-
15876 // string list (say a per-scope override projector) would surface
15877 // here at build time. Peer of the sibling
15878 // `dep_validate_reads_fonte_through_accessor` /
15879 // `dep_validate_reads_requirement_through_accessor` composition
15880 // pins on the `:fonte` / `:versao` axes.
15881 // Positive control: two distinct well-formed feature names pass.
15882 Dep {
15883 nome: "caixa-teia".to_string(),
15884 versao: "^0.1".to_string(),
15885 fonte: None,
15886 opcional: false,
15887 caracteristicas: vec!["http".to_string(), "json".to_string()],
15888 }
15889 .validate()
15890 .unwrap();
15891 // Negative control 1: empty-string feature-name entry — the
15892 // accessor still returns `&[""]` and the walk raises the typed
15893 // empty-first carrier.
15894 let err = Dep {
15895 nome: "caixa-teia".to_string(),
15896 versao: "^0.1".to_string(),
15897 fonte: None,
15898 opcional: false,
15899 caracteristicas: vec![String::new()],
15900 }
15901 .validate()
15902 .unwrap_err();
15903 assert!(
15904 matches!(
15905 &err,
15906 DepError::CaracteristicaEmpty { nome } if nome == "caixa-teia",
15907 ),
15908 "expected CaracteristicaEmpty from the accessor-routed walk, got {err:?}",
15909 );
15910 // Negative control 2: within-list duplicate — the accessor's
15911 // slice view carries both entries, and the walk's dedup arm
15912 // raises the typed duplicate carrier quoting the offending
15913 // feature name verbatim.
15914 let err = Dep {
15915 nome: "caixa-teia".to_string(),
15916 versao: "^0.1".to_string(),
15917 fonte: None,
15918 opcional: false,
15919 caracteristicas: vec!["http".to_string(), "http".to_string()],
15920 }
15921 .validate()
15922 .unwrap_err();
15923 assert!(
15924 matches!(
15925 &err,
15926 DepError::CaracteristicaDuplicate {
15927 nome,
15928 caracteristica,
15929 } if nome == "caixa-teia" && caracteristica == "http",
15930 ),
15931 "expected CaracteristicaDuplicate from the accessor-routed dedup, got {err:?}",
15932 );
15933 }
15934
15935 // ── Dep::opcional accessor pins ───────────────────────────────────
15936 //
15937 // Two coherence pins on the lifted `Dep::opcional` accessor: byte-
15938 // equal projection over the default-`false` / explicit-`true`
15939 // fixture pair across the plain-shorthand (`:fonte None`) / explicit-
15940 // git-tag / explicit-path fixture triad the [`Dep`] docstring lists,
15941 // exercising the accessor's accept-set over every author-surface
15942 // `:fonte` shape × every author-surface `:opcional` shape; and by-
15943 // `Copy` idempotency so the projection stays value-return (no
15944 // silent detour to a fresh `&bool` borrow that would introduce a
15945 // lifetime on the return type the plain-`Copy`-scalar axis's `bool`
15946 // shape elides). No composition pin — `:opcional` does not
15947 // participate in [`Dep::validate`] (an opcional dep with any bool
15948 // value is validate-accepted; the missing-source arm is a resolver-
15949 // side runtime dispatch, not a build-time refusal), so the axis
15950 // reduces to the value-shape + `Copy` pin pair the peer
15951 // [`crate::Caixa::max_restarts`] / [`crate::Caixa::estrategia`]
15952 // outer-`Option<Copy>` accessor pins already carry.
15953
15954 #[test]
15955 fn dep_opcional_returns_declared_opcional_across_fonte_shapes() {
15956 // Default-`false` form via the [`Dep::simple`] constructor —
15957 // the accessor projects the `false` bit the default-fill sets.
15958 assert!(!Dep::simple("caixa-teia", "^0.1").opcional());
15959 // Default-`false` form via the [`Dep::git`] constructor — same
15960 // default fill; the accessor projects `false` regardless of the
15961 // `:fonte` arm.
15962 assert!(!Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").opcional(),);
15963 // Explicit-`true` form × plain-shorthand `:fonte` — the
15964 // canonical author-surface "this dep may be missing" shape.
15965 let plain_true = Dep {
15966 nome: "caixa-teia".to_string(),
15967 versao: "^0.1".to_string(),
15968 fonte: None,
15969 opcional: true,
15970 caracteristicas: Vec::new(),
15971 };
15972 assert!(plain_true.opcional());
15973 // Explicit-`true` form × explicit git-source — the accessor
15974 // projects the bit verbatim regardless of the `:fonte` arm.
15975 let git_true = Dep {
15976 nome: "caixa-teia".to_string(),
15977 versao: "^0.1".to_string(),
15978 fonte: Some(DepSource::Git {
15979 repo: "github:pleme-io/caixa-teia".to_string(),
15980 tag: Some("v0.1.0".to_string()),
15981 rev: None,
15982 branch: None,
15983 }),
15984 opcional: true,
15985 caracteristicas: Vec::new(),
15986 };
15987 assert!(git_true.opcional());
15988 // Explicit-`true` form × explicit path-source — the dev-only
15989 // local-filesystem arm the [`Dep`] docstring's third fixture
15990 // carries.
15991 let path_true = Dep {
15992 nome: "caixa-teia".to_string(),
15993 versao: "0.1.0".to_string(),
15994 fonte: Some(DepSource::Path {
15995 caminho: "../caixa-teia".to_string(),
15996 }),
15997 opcional: true,
15998 caracteristicas: Vec::new(),
15999 };
16000 assert!(path_true.opcional());
16001 }
16002
16003 #[test]
16004 fn dep_opcional_projects_bool_by_copy() {
16005 // The by-`Copy` pin: [`Dep::opcional`] returns `bool` by value
16006 // (`bool: Copy`) — the accessor does not borrow `&self` past
16007 // the call (no lifetime on the return type), and calling the
16008 // accessor twice on the same [`Dep`] must yield discriminant-
16009 // equal values (idempotent, no side effects on `&self`). Peer
16010 // of the sibling outer-`Caixa` `Option<Copy>` by-`Copy`
16011 // `max_restarts_projects_option_by_copy` (eba5211) /
16012 // `estrategia_projects_option_by_copy` (ed04d3c) pins on the
16013 // outer-`Caixa` altitude — extended here to the outer-`Dep`
16014 // altitude's plain-`Copy` `bool` axis. The `Copy` discipline
16015 // replaces the pointer-equality claim the sibling per-`Dep`
16016 // by-borrow pins (`dep_nome_is_by_borrow_pointer_identity`
16017 // eba2cde, `dep_versao_requirement_is_by_borrow_pointer_identity`
16018 // 05529b1, `dep_fonte_is_by_borrow_pointer_identity` d65d1bf,
16019 // `dep_caracteristicas_is_by_borrow_pointer_identity` 9197944)
16020 // carry (a fresh `Copy` of a `Copy` discriminant is definitionally
16021 // the same discriminant, so the axis reduces to discriminant
16022 // equality).
16023 //
16024 // Pins against a future silent detour that returned a fresh
16025 // `&bool` reference (which would type-check but silently
16026 // introduce a borrow of `&self` past the call, collapsing the
16027 // load-bearing "no lifetime on the return type" `Copy`
16028 // projection the plain-`Copy`-scalar axis's `bool` shape
16029 // carries) or a stale-read side effect that flipped the outer
16030 // discriminant on successive calls.
16031 for opcional in [false, true] {
16032 let d = Dep {
16033 nome: "caixa-teia".to_string(),
16034 versao: "^0.1".to_string(),
16035 fonte: None,
16036 opcional,
16037 caracteristicas: Vec::new(),
16038 };
16039 let first = d.opcional();
16040 let second = d.opcional();
16041 assert_eq!(
16042 first, second,
16043 "Dep::opcional must be idempotent — two successive calls \
16044 on the same &self must return the same bool",
16045 );
16046 assert_eq!(
16047 first, opcional,
16048 "Dep::opcional must return :opcional verbatim by Copy — \
16049 got {first}, expected {opcional}",
16050 );
16051 assert_eq!(
16052 d.opcional(),
16053 d.opcional,
16054 "Dep::opcional accessor and self.opcional field access \
16055 must byte-equal — a bit-flip drift would silently split \
16056 the paired resolver-side drop-vs-error dispatch from \
16057 the storage-side default-fill the [`Dep::simple`] / \
16058 [`Dep::git`] constructor pair carries",
16059 );
16060 }
16061 }
16062
16063 // ── DepSource::sole_pin — sole-set git-pin accessor ─────────────────
16064
16065 #[test]
16066 fn sole_pin_returns_none_for_path_source() {
16067 // A path source carries no git-ref, so `sole_pin()` returns
16068 // `None` structurally — the sibling arm every git-fetching
16069 // consumer partitions off before reaching for a git-ref. Pins
16070 // the Path-arm branch of the accessor against a future silent
16071 // detour that treats a `Self::Path` as an unpinned-git source
16072 // and returns the wrong "no pin" signal (e.g. the empty string,
16073 // or a hard-coded `Some("HEAD")` matching the caixa-crd
16074 // path-arm `git_ref` fill).
16075 let s = DepSource::Path {
16076 caminho: "../local-caixa".to_string(),
16077 };
16078 assert_eq!(s.sole_pin(), None);
16079 }
16080
16081 #[test]
16082 fn sole_pin_returns_none_for_unpinned_git_source() {
16083 // The [`DepSource::default_github`] shorthand shape carries no
16084 // pin — every `tag`/`rev`/`branch` is `None`, and `sole_pin()`
16085 // returns `None`. This is the shape caixa-resolver's `fetch_dep`
16086 // materializes when the author omits `:fonte` entirely, then
16087 // hands to `fetch_git` which raises `ResolveError::MissingPin`
16088 // on the `None` arm — the accessor's return matches the arm
16089 // the resolver's diagnostic keys off.
16090 let s = DepSource::default_github("pleme-io", "caixa-teia");
16091 assert_eq!(s.sole_pin(), None);
16092 }
16093
16094 #[test]
16095 fn sole_pin_returns_rev_when_only_rev_is_set() {
16096 let s = DepSource::Git {
16097 repo: "github:o/x".into(),
16098 tag: None,
16099 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
16100 branch: None,
16101 };
16102 assert_eq!(
16103 s.sole_pin(),
16104 Some("deadbeefcafebabe1234567890abcdef12345678")
16105 );
16106 }
16107
16108 #[test]
16109 fn sole_pin_returns_tag_when_only_tag_is_set() {
16110 let s = DepSource::Git {
16111 repo: "github:o/x".into(),
16112 tag: Some("v0.1.0".into()),
16113 rev: None,
16114 branch: None,
16115 };
16116 assert_eq!(s.sole_pin(), Some("v0.1.0"));
16117 }
16118
16119 #[test]
16120 fn sole_pin_returns_branch_when_only_branch_is_set() {
16121 let s = DepSource::Git {
16122 repo: "github:o/x".into(),
16123 tag: None,
16124 rev: None,
16125 branch: Some("main".into()),
16126 };
16127 assert_eq!(s.sole_pin(), Some("main"));
16128 }
16129
16130 #[test]
16131 fn sole_pin_precedence_rev_beats_tag_and_branch() {
16132 // Precedence: rev > tag > branch. Validate() rejects
16133 // multiple-pin shapes, but the accessor's precedence is defined
16134 // for pre-validate consumers (the resolver's `MissingPin`
16135 // diagnostic path, the caixa-crd round-trip's default `"main"`
16136 // fallback) and as defense-in-depth if the gate is ever
16137 // bypassed. Pins the same precedence caixa-resolver's
16138 // `fetch_git` and caixa-crd's `dep_into_ref` already apply
16139 // inline.
16140 let s = DepSource::Git {
16141 repo: "github:o/x".into(),
16142 tag: Some("v1".into()),
16143 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
16144 branch: Some("main".into()),
16145 };
16146 assert_eq!(
16147 s.sole_pin(),
16148 Some("deadbeefcafebabe1234567890abcdef12345678")
16149 );
16150 }
16151
16152 #[test]
16153 fn sole_pin_precedence_tag_beats_branch_when_no_rev() {
16154 let s = DepSource::Git {
16155 repo: "github:o/x".into(),
16156 tag: Some("v1".into()),
16157 rev: None,
16158 branch: Some("main".into()),
16159 };
16160 assert_eq!(s.sole_pin(), Some("v1"));
16161 }
16162
16163 #[test]
16164 fn sole_pin_byte_equals_inline_rev_or_tag_or_branch_cascade() {
16165 // Fail-before-pass-after byte-parity pin: the substrate accessor
16166 // must return byte-identical to the inline
16167 // `rev.as_deref().or(tag.as_deref()).or(branch.as_deref())`
16168 // cascade both caixa-resolver's `fetch_git` and caixa-crd's
16169 // `dep_into_ref` open-coded pre-lift. Trips at caixa-core build
16170 // time if the accessor's precedence silently drifts from the
16171 // consumer-side cascade — the exact drift this lift converges
16172 // to one substrate primitive to close structurally.
16173 //
16174 // Iterates through the 2^3 = 8 combinations of (tag, rev,
16175 // branch) each-either-`None`-or-`Some`, so every arm of the
16176 // precedence cascade lands under the pin. `validate()` refuses
16177 // the 4 multi-pin combinations, but the accessor's return is
16178 // defined on all 8.
16179 let vals = [Some("R".to_string()), None];
16180 for tag in &vals {
16181 for rev in &vals {
16182 for branch in &vals {
16183 let s = DepSource::Git {
16184 repo: "github:o/x".into(),
16185 tag: tag.clone(),
16186 rev: rev.clone(),
16187 branch: branch.clone(),
16188 };
16189 // The exact inline cascade the two pre-lift
16190 // consumer sites hand-rolled, byte-for-byte.
16191 let expected = rev.as_deref().or(tag.as_deref()).or(branch.as_deref());
16192 assert_eq!(
16193 s.sole_pin(),
16194 expected,
16195 "sole_pin() must byte-equal \
16196 rev.or(tag).or(branch) for \
16197 (tag={tag:?}, rev={rev:?}, branch={branch:?}) — \
16198 a drift would silently split caixa-resolver's \
16199 fetch_git checkout target from caixa-crd's \
16200 dep_into_ref git_ref fill",
16201 );
16202 }
16203 }
16204 }
16205 }
16206
16207 // Fail-before-pass-after pins on the eleven
16208 // [`fonte_caminho_ctors!`]-generated `DepError::fonte_caminho_*`
16209 // constructors folded from the [`DepSource::validate_caminho`]
16210 // wire-up sites. Each pins the generated ctor's output to the
16211 // pre-lift struct-literal on the same `(&str, &str)` fixture, so
16212 // any wrapper-side lowercase / trim / re-order / silent-field-swap
16213 // regression on the two-field `{ nome: nome.to_string(), caminho:
16214 // caminho.to_string() }` construction surfaces here rather than at
16215 // a downstream diagnostic-shape mismatch. Peer of the sibling
16216 // `empty_child_version_ctor_matches_struct_literal_wrap` /
16217 // `contrato_endpoint_empty_ctor_matches_struct_literal_wrap` /
16218 // `entrada_host_invalid_ctor_matches_struct_literal_wrap` /
16219 // `nome_only_ctor_routes_caixa_through_nome_accessor` equivalence
16220 // pins on the peer `SupervisorError` / `AplicacaoError` /
16221 // `LayoutError` / `LimitsError` / `UpgradeError` envelopes.
16222
16223 #[test]
16224 fn fonte_caminho_absolute_ctor_matches_struct_literal_wrap() {
16225 assert_eq!(
16226 DepError::fonte_caminho_absolute("caixa-teia", "/home/me/work/caixa-teia"),
16227 DepError::FonteCaminhoAbsolute {
16228 nome: "caixa-teia".to_string(),
16229 caminho: "/home/me/work/caixa-teia".to_string(),
16230 },
16231 "generated fonte_caminho_absolute ctor must produce byte-equal \
16232 DepError to the open-coded struct-literal wrap on the same \
16233 (&str, &str) fixture",
16234 );
16235 }
16236
16237 #[test]
16238 fn fonte_caminho_tilde_expansion_ctor_matches_struct_literal_wrap() {
16239 assert_eq!(
16240 DepError::fonte_caminho_tilde_expansion("caixa-teia", "~/work/caixa-teia"),
16241 DepError::FonteCaminhoTildeExpansion {
16242 nome: "caixa-teia".to_string(),
16243 caminho: "~/work/caixa-teia".to_string(),
16244 },
16245 );
16246 }
16247
16248 #[test]
16249 fn fonte_caminho_var_expansion_ctor_matches_struct_literal_wrap() {
16250 assert_eq!(
16251 DepError::fonte_caminho_var_expansion("caixa-teia", "$HOME/work/caixa-teia"),
16252 DepError::FonteCaminhoVarExpansion {
16253 nome: "caixa-teia".to_string(),
16254 caminho: "$HOME/work/caixa-teia".to_string(),
16255 },
16256 );
16257 }
16258
16259 #[test]
16260 fn fonte_caminho_leading_whitespace_ctor_matches_struct_literal_wrap() {
16261 assert_eq!(
16262 DepError::fonte_caminho_leading_whitespace("caixa-teia", " ../caixa-teia"),
16263 DepError::FonteCaminhoLeadingWhitespace {
16264 nome: "caixa-teia".to_string(),
16265 caminho: " ../caixa-teia".to_string(),
16266 },
16267 );
16268 }
16269
16270 #[test]
16271 fn fonte_caminho_leading_hyphen_ctor_matches_struct_literal_wrap() {
16272 assert_eq!(
16273 DepError::fonte_caminho_leading_hyphen("caixa-teia", "-rf"),
16274 DepError::FonteCaminhoLeadingHyphen {
16275 nome: "caixa-teia".to_string(),
16276 caminho: "-rf".to_string(),
16277 },
16278 );
16279 }
16280
16281 #[test]
16282 fn fonte_caminho_backslash_ctor_matches_struct_literal_wrap() {
16283 assert_eq!(
16284 DepError::fonte_caminho_backslash("caixa-teia", "..\\caixa-teia"),
16285 DepError::FonteCaminhoBackslash {
16286 nome: "caixa-teia".to_string(),
16287 caminho: "..\\caixa-teia".to_string(),
16288 },
16289 );
16290 }
16291
16292 #[test]
16293 fn fonte_caminho_shell_pipe_ctor_matches_struct_literal_wrap() {
16294 assert_eq!(
16295 DepError::fonte_caminho_shell_pipe("caixa-teia", "../caixa-teia|evil"),
16296 DepError::FonteCaminhoShellPipe {
16297 nome: "caixa-teia".to_string(),
16298 caminho: "../caixa-teia|evil".to_string(),
16299 },
16300 );
16301 }
16302
16303 #[test]
16304 fn fonte_caminho_shell_semicolon_ctor_matches_struct_literal_wrap() {
16305 assert_eq!(
16306 DepError::fonte_caminho_shell_semicolon("caixa-teia", "../caixa-teia;evil"),
16307 DepError::FonteCaminhoShellSemicolon {
16308 nome: "caixa-teia".to_string(),
16309 caminho: "../caixa-teia;evil".to_string(),
16310 },
16311 );
16312 }
16313
16314 #[test]
16315 fn fonte_caminho_shell_background_ctor_matches_struct_literal_wrap() {
16316 assert_eq!(
16317 DepError::fonte_caminho_shell_background("caixa-teia", "../caixa-teia&"),
16318 DepError::FonteCaminhoShellBackground {
16319 nome: "caixa-teia".to_string(),
16320 caminho: "../caixa-teia&".to_string(),
16321 },
16322 );
16323 }
16324
16325 #[test]
16326 fn fonte_caminho_shell_command_substitution_ctor_matches_struct_literal_wrap() {
16327 assert_eq!(
16328 DepError::fonte_caminho_shell_command_substitution(
16329 "caixa-teia",
16330 "../caixa-teia`whoami`",
16331 ),
16332 DepError::FonteCaminhoShellCommandSubstitution {
16333 nome: "caixa-teia".to_string(),
16334 caminho: "../caixa-teia`whoami`".to_string(),
16335 },
16336 );
16337 }
16338
16339 #[test]
16340 fn fonte_caminho_trailing_slash_ctor_matches_struct_literal_wrap() {
16341 assert_eq!(
16342 DepError::fonte_caminho_trailing_slash("caixa-teia", "../caixa-teia/"),
16343 DepError::FonteCaminhoTrailingSlash {
16344 nome: "caixa-teia".to_string(),
16345 caminho: "../caixa-teia/".to_string(),
16346 },
16347 );
16348 }
16349
16350 #[test]
16351 fn fonte_caminho_ctors_route_nome_and_caminho_through_to_string() {
16352 // Cross-axis pin: sweep the two constructor input axes
16353 // (`nome: &str`, `caminho: &str`) through a non-default fixture
16354 // pair against every generated arm in the
16355 // [`fonte_caminho_ctors!`] macro, so any wrapper-side lowercase
16356 // / trim / truncate / re-order on the two-field
16357 // `{ nome, caminho }` construction — or a silent field swap
16358 // between the two axes at codegen time — surfaces here rather
16359 // than at a downstream diagnostic-shape mismatch. Peer of the
16360 // sibling `supervisor_caixa_only_ctors_route_caixa_through_
16361 // to_string` cross-axis routing pin on the peer
16362 // `SupervisorError` envelope, extended here onto the
16363 // `DepError` `{ nome: String, caminho: String }` envelope so
16364 // every substrate-primitive ctor family in caixa-core
16365 // guarantees each `&str`-field construction routes the
16366 // caller's `&str` verbatim through `.to_string()`.
16367 let nome = "sibling-teia";
16368 let caminho = "../workspace/sibling";
16369 let cases: [(DepError, DepError); 11] = [
16370 (
16371 DepError::fonte_caminho_absolute(nome, caminho),
16372 DepError::FonteCaminhoAbsolute {
16373 nome: nome.to_string(),
16374 caminho: caminho.to_string(),
16375 },
16376 ),
16377 (
16378 DepError::fonte_caminho_tilde_expansion(nome, caminho),
16379 DepError::FonteCaminhoTildeExpansion {
16380 nome: nome.to_string(),
16381 caminho: caminho.to_string(),
16382 },
16383 ),
16384 (
16385 DepError::fonte_caminho_var_expansion(nome, caminho),
16386 DepError::FonteCaminhoVarExpansion {
16387 nome: nome.to_string(),
16388 caminho: caminho.to_string(),
16389 },
16390 ),
16391 (
16392 DepError::fonte_caminho_leading_whitespace(nome, caminho),
16393 DepError::FonteCaminhoLeadingWhitespace {
16394 nome: nome.to_string(),
16395 caminho: caminho.to_string(),
16396 },
16397 ),
16398 (
16399 DepError::fonte_caminho_leading_hyphen(nome, caminho),
16400 DepError::FonteCaminhoLeadingHyphen {
16401 nome: nome.to_string(),
16402 caminho: caminho.to_string(),
16403 },
16404 ),
16405 (
16406 DepError::fonte_caminho_backslash(nome, caminho),
16407 DepError::FonteCaminhoBackslash {
16408 nome: nome.to_string(),
16409 caminho: caminho.to_string(),
16410 },
16411 ),
16412 (
16413 DepError::fonte_caminho_shell_pipe(nome, caminho),
16414 DepError::FonteCaminhoShellPipe {
16415 nome: nome.to_string(),
16416 caminho: caminho.to_string(),
16417 },
16418 ),
16419 (
16420 DepError::fonte_caminho_shell_semicolon(nome, caminho),
16421 DepError::FonteCaminhoShellSemicolon {
16422 nome: nome.to_string(),
16423 caminho: caminho.to_string(),
16424 },
16425 ),
16426 (
16427 DepError::fonte_caminho_shell_background(nome, caminho),
16428 DepError::FonteCaminhoShellBackground {
16429 nome: nome.to_string(),
16430 caminho: caminho.to_string(),
16431 },
16432 ),
16433 (
16434 DepError::fonte_caminho_shell_command_substitution(nome, caminho),
16435 DepError::FonteCaminhoShellCommandSubstitution {
16436 nome: nome.to_string(),
16437 caminho: caminho.to_string(),
16438 },
16439 ),
16440 (
16441 DepError::fonte_caminho_trailing_slash(nome, caminho),
16442 DepError::FonteCaminhoTrailingSlash {
16443 nome: nome.to_string(),
16444 caminho: caminho.to_string(),
16445 },
16446 ),
16447 ];
16448 for (via_ctor, via_struct_literal) in cases {
16449 assert_eq!(
16450 via_ctor, via_struct_literal,
16451 "fonte_caminho_ctors!-generated ctor must route (nome, caminho) \
16452 through `.to_string()` in declared field order — a field-swap or \
16453 silent-conversion regression surfaces here rather than at a \
16454 downstream diagnostic-shape mismatch",
16455 );
16456 }
16457 }
16458
16459 // ── `dep_nome_only_ctors!` — the paired `{ nome: String }` single-slot
16460 // envelope on `DepError`, sibling of the peer `fonte_caminho_ctors!`
16461 // (f85f145) on the `{ nome, caminho }` two-slot envelope of the same
16462 // enum, and of `supervisor_caixa_only_ctors!` (db09650) on the peer
16463 // `SupervisorError` envelope's `{ caixa: String }` single-slot axis.
16464
16465 #[test]
16466 fn versao_empty_ctor_matches_struct_literal_wrap() {
16467 assert_eq!(
16468 DepError::versao_empty("caixa-teia"),
16469 DepError::VersaoEmpty {
16470 nome: "caixa-teia".to_string(),
16471 },
16472 );
16473 }
16474
16475 #[test]
16476 fn fonte_repo_empty_ctor_matches_struct_literal_wrap() {
16477 assert_eq!(
16478 DepError::fonte_repo_empty("caixa-teia"),
16479 DepError::FonteRepoEmpty {
16480 nome: "caixa-teia".to_string(),
16481 },
16482 );
16483 }
16484
16485 #[test]
16486 fn fonte_pin_missing_ctor_matches_struct_literal_wrap() {
16487 assert_eq!(
16488 DepError::fonte_pin_missing("caixa-teia"),
16489 DepError::FontePinMissing {
16490 nome: "caixa-teia".to_string(),
16491 },
16492 );
16493 }
16494
16495 #[test]
16496 fn fonte_caminho_empty_ctor_matches_struct_literal_wrap() {
16497 assert_eq!(
16498 DepError::fonte_caminho_empty("caixa-teia"),
16499 DepError::FonteCaminhoEmpty {
16500 nome: "caixa-teia".to_string(),
16501 },
16502 );
16503 }
16504
16505 #[test]
16506 fn caracteristica_empty_ctor_matches_struct_literal_wrap() {
16507 assert_eq!(
16508 DepError::caracteristica_empty("caixa-teia"),
16509 DepError::CaracteristicaEmpty {
16510 nome: "caixa-teia".to_string(),
16511 },
16512 );
16513 }
16514
16515 #[test]
16516 fn dep_nome_only_ctors_route_nome_through_to_string() {
16517 // Cross-axis routing pin: sweep the single constructor input
16518 // axis (`nome: &str`) through a non-default fixture against
16519 // every generated arm in the [`dep_nome_only_ctors!`] macro, so
16520 // any wrapper-side lowercase / trim / truncate at codegen time
16521 // — or a silent field re-name away from the canonical `nome`
16522 // axis on any one variant — surfaces here rather than at a
16523 // downstream diagnostic-shape mismatch. Peer of the sibling
16524 // `fonte_caminho_ctors_route_nome_and_caminho_through_
16525 // to_string` cross-axis routing pin on the same envelope's
16526 // two-slot family (f85f145) and of the peer
16527 // `supervisor_caixa_only_ctors_route_caixa_through_to_string`
16528 // pin on the `SupervisorError` single-slot family (db09650).
16529 let nome = "sibling-teia";
16530 let cases: [(DepError, DepError); 5] = [
16531 (
16532 DepError::versao_empty(nome),
16533 DepError::VersaoEmpty {
16534 nome: nome.to_string(),
16535 },
16536 ),
16537 (
16538 DepError::fonte_repo_empty(nome),
16539 DepError::FonteRepoEmpty {
16540 nome: nome.to_string(),
16541 },
16542 ),
16543 (
16544 DepError::fonte_pin_missing(nome),
16545 DepError::FontePinMissing {
16546 nome: nome.to_string(),
16547 },
16548 ),
16549 (
16550 DepError::fonte_caminho_empty(nome),
16551 DepError::FonteCaminhoEmpty {
16552 nome: nome.to_string(),
16553 },
16554 ),
16555 (
16556 DepError::caracteristica_empty(nome),
16557 DepError::CaracteristicaEmpty {
16558 nome: nome.to_string(),
16559 },
16560 ),
16561 ];
16562 for (via_ctor, via_struct_literal) in cases {
16563 assert_eq!(
16564 via_ctor, via_struct_literal,
16565 "dep_nome_only_ctors!-generated ctor must route `nome` \
16566 through `.to_string()` onto the canonical `nome` field \
16567 — a field-rename or silent-conversion regression surfaces \
16568 here rather than at a downstream diagnostic-shape mismatch",
16569 );
16570 }
16571 }
16572
16573 // ── `dep_nome_list_ctors!` — the paired `{ nome: String, list:
16574 // &'static str }` two-slot envelope on `DepError`, strict
16575 // sibling of the peer `dep_nome_only_ctors!` (792aa92) on the
16576 // same envelope's `{ nome: String }` one-slot shape and of the
16577 // peer `supervisor_caixa_only_ctors!` (db09650) on the
16578 // `SupervisorError` envelope's `{ caixa: String }` one-slot axis.
16579
16580 #[test]
16581 fn duplicate_nome_ctor_matches_struct_literal_wrap() {
16582 assert_eq!(
16583 DepError::duplicate_nome("caixa-teia", crate::render::DEP_AUTHOR_KEY_DEPS),
16584 DepError::DuplicateNome {
16585 nome: "caixa-teia".to_string(),
16586 list: crate::render::DEP_AUTHOR_KEY_DEPS,
16587 },
16588 "generated duplicate_nome ctor must produce byte-equal \
16589 `DepError::DuplicateNome` to the pre-lift struct-literal \
16590 wrap on the same scalar fixtures",
16591 );
16592 }
16593
16594 #[test]
16595 fn dep_is_self_ctor_matches_struct_literal_wrap() {
16596 assert_eq!(
16597 DepError::dep_is_self("orquestra", crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
16598 DepError::DepIsSelf {
16599 nome: "orquestra".to_string(),
16600 list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
16601 },
16602 "generated dep_is_self ctor must produce byte-equal \
16603 `DepError::DepIsSelf` to the pre-lift struct-literal \
16604 wrap on the same scalar fixtures",
16605 );
16606 }
16607
16608 #[test]
16609 fn dep_nome_list_ctors_route_nome_and_list_through_uniformly() {
16610 // Cross-axis routing pin: sweep the two constructor input axes
16611 // (`nome: &str`, `list: &'static str`) through non-default
16612 // fixtures against every generated arm in the
16613 // [`dep_nome_list_ctors!`] macro, so any wrapper-side
16614 // lowercase / trim / truncate at codegen time — or a silent
16615 // field re-name away from the canonical `nome` / `list` axes
16616 // on any one variant, or a `list` axis silently rerouted
16617 // through `.to_string()` instead of passed as `&'static str`
16618 // verbatim — surfaces here rather than at a downstream
16619 // diagnostic-shape mismatch. Peer of the sibling
16620 // `dep_nome_only_ctors_route_nome_through_to_string` pin
16621 // (792aa92) on the same envelope's one-slot family, and of the
16622 // peer
16623 // `supervisor_child_reason_ctors_route_reason_through_into_uniformly`
16624 // pin (d2ef2ec) on the sibling `SupervisorError` envelope's
16625 // two-slot `{ caixa: String, reason: String }` shape.
16626 let nome = "sibling-teia";
16627 let cases: [(DepError, DepError); 4] = [
16628 (
16629 DepError::duplicate_nome(nome, crate::render::DEP_AUTHOR_KEY_DEPS),
16630 DepError::DuplicateNome {
16631 nome: nome.to_string(),
16632 list: crate::render::DEP_AUTHOR_KEY_DEPS,
16633 },
16634 ),
16635 (
16636 DepError::duplicate_nome(nome, crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
16637 DepError::DuplicateNome {
16638 nome: nome.to_string(),
16639 list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
16640 },
16641 ),
16642 (
16643 DepError::dep_is_self(nome, crate::render::DEP_AUTHOR_KEY_DEPS),
16644 DepError::DepIsSelf {
16645 nome: nome.to_string(),
16646 list: crate::render::DEP_AUTHOR_KEY_DEPS,
16647 },
16648 ),
16649 (
16650 DepError::dep_is_self(nome, crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
16651 DepError::DepIsSelf {
16652 nome: nome.to_string(),
16653 list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
16654 },
16655 ),
16656 ];
16657 for (via_ctor, via_struct_literal) in cases {
16658 assert_eq!(
16659 via_ctor, via_struct_literal,
16660 "dep_nome_list_ctors!-generated ctor must route `nome` \
16661 through `.to_string()` onto the canonical `nome` field \
16662 and pass `list` verbatim onto the canonical `&'static str` \
16663 `list` field — a field-rename, silent-conversion, or \
16664 axis-swap regression surfaces here rather than at a \
16665 downstream diagnostic-shape mismatch",
16666 );
16667 }
16668 }
16669
16670 // ── `fonte_caminho_byte_ctors!` — the paired `{ nome: String,
16671 // caminho: String, byte: u8 }` three-slot envelope on `DepError`,
16672 // strict sibling of the peer `fonte_caminho_ctors!` (f85f145) on
16673 // the same envelope's `{ nome: String, caminho: String }` two-slot
16674 // shape, and of the peer `dep_nome_only_ctors!` (792aa92) on the
16675 // same envelope's `{ nome: String }` one-slot shape.
16676
16677 #[test]
16678 fn fonte_caminho_control_char_ctor_matches_struct_literal_wrap() {
16679 assert_eq!(
16680 DepError::fonte_caminho_control_char("caixa-teia", "../caixa-teia\x00foo", 0x00),
16681 DepError::FonteCaminhoControlChar {
16682 nome: "caixa-teia".to_string(),
16683 caminho: "../caixa-teia\x00foo".to_string(),
16684 byte: 0x00,
16685 },
16686 );
16687 }
16688
16689 #[test]
16690 fn fonte_caminho_shell_redirection_ctor_matches_struct_literal_wrap() {
16691 assert_eq!(
16692 DepError::fonte_caminho_shell_redirection("caixa-teia", "../caixa-teia>log", b'>'),
16693 DepError::FonteCaminhoShellRedirection {
16694 nome: "caixa-teia".to_string(),
16695 caminho: "../caixa-teia>log".to_string(),
16696 byte: b'>',
16697 },
16698 );
16699 }
16700
16701 #[test]
16702 #[allow(
16703 clippy::too_many_lines,
16704 reason = "cross-axis routing pin sweeps twelve typed variants, one per \
16705 byte-classification arm on the {nome,caminho,byte} envelope; \
16706 the linear per-variant repetition is exactly what the sweep \
16707 is pinning — a helper macro would hide the shape the fold is \
16708 keying on"
16709 )]
16710 fn fonte_caminho_byte_ctors_route_nome_caminho_and_byte_through_to_string() {
16711 // Cross-axis routing pin: sweep the three constructor input axes
16712 // (`nome: &str`, `caminho: &str`, `byte: u8`) through a
16713 // non-default fixture triple against every generated arm in the
16714 // [`fonte_caminho_byte_ctors!`] macro, so any wrapper-side
16715 // lowercase / trim / truncate on the two `&str` axes — a silent
16716 // field swap between `nome` and `caminho`, or a silent
16717 // re-classification of the offending byte — surfaces here rather
16718 // than at a downstream diagnostic-shape mismatch. Peer of the
16719 // sibling `fonte_caminho_ctors_route_nome_and_caminho_through_
16720 // to_string` cross-axis routing pin on the same envelope's
16721 // two-slot family (f85f145) and of the sibling
16722 // `dep_nome_only_ctors_route_nome_through_to_string` pin on the
16723 // same envelope's one-slot family (792aa92), extended here onto
16724 // the `{ nome: String, caminho: String, byte: u8 }` three-slot
16725 // envelope so every substrate-primitive ctor family in
16726 // caixa-core's `DepError` envelope guarantees each field routes
16727 // the caller's value verbatim through `.to_string()` (or byte-
16728 // identity for `byte: u8`) in declared field order.
16729 let nome = "sibling-teia";
16730 let caminho = "../workspace/sibling";
16731 let byte = 0x2A_u8;
16732 let cases: [(DepError, DepError); 12] = [
16733 (
16734 DepError::fonte_caminho_control_char(nome, caminho, byte),
16735 DepError::FonteCaminhoControlChar {
16736 nome: nome.to_string(),
16737 caminho: caminho.to_string(),
16738 byte,
16739 },
16740 ),
16741 (
16742 DepError::fonte_caminho_shell_redirection(nome, caminho, byte),
16743 DepError::FonteCaminhoShellRedirection {
16744 nome: nome.to_string(),
16745 caminho: caminho.to_string(),
16746 byte,
16747 },
16748 ),
16749 (
16750 DepError::fonte_caminho_shell_glob(nome, caminho, byte),
16751 DepError::FonteCaminhoShellGlob {
16752 nome: nome.to_string(),
16753 caminho: caminho.to_string(),
16754 byte,
16755 },
16756 ),
16757 (
16758 DepError::fonte_caminho_shell_subshell_grouping(nome, caminho, byte),
16759 DepError::FonteCaminhoShellSubshellGrouping {
16760 nome: nome.to_string(),
16761 caminho: caminho.to_string(),
16762 byte,
16763 },
16764 ),
16765 (
16766 DepError::fonte_caminho_shell_brace_expansion(nome, caminho, byte),
16767 DepError::FonteCaminhoShellBraceExpansion {
16768 nome: nome.to_string(),
16769 caminho: caminho.to_string(),
16770 byte,
16771 },
16772 ),
16773 (
16774 DepError::fonte_caminho_shell_bracket_expansion(nome, caminho, byte),
16775 DepError::FonteCaminhoShellBracketExpansion {
16776 nome: nome.to_string(),
16777 caminho: caminho.to_string(),
16778 byte,
16779 },
16780 ),
16781 (
16782 DepError::fonte_caminho_shell_quote_grouping(nome, caminho, byte),
16783 DepError::FonteCaminhoShellQuoteGrouping {
16784 nome: nome.to_string(),
16785 caminho: caminho.to_string(),
16786 byte,
16787 },
16788 ),
16789 (
16790 DepError::fonte_caminho_shell_comment(nome, caminho, byte),
16791 DepError::FonteCaminhoShellComment {
16792 nome: nome.to_string(),
16793 caminho: caminho.to_string(),
16794 byte,
16795 },
16796 ),
16797 (
16798 DepError::fonte_caminho_url_percent_encoding(nome, caminho, byte),
16799 DepError::FonteCaminhoUrlPercentEncoding {
16800 nome: nome.to_string(),
16801 caminho: caminho.to_string(),
16802 byte,
16803 },
16804 ),
16805 (
16806 DepError::fonte_caminho_shell_variable_expansion(nome, caminho, byte),
16807 DepError::FonteCaminhoShellVariableExpansion {
16808 nome: nome.to_string(),
16809 caminho: caminho.to_string(),
16810 byte,
16811 },
16812 ),
16813 (
16814 DepError::fonte_caminho_shell_history_expansion(nome, caminho, byte),
16815 DepError::FonteCaminhoShellHistoryExpansion {
16816 nome: nome.to_string(),
16817 caminho: caminho.to_string(),
16818 byte,
16819 },
16820 ),
16821 (
16822 DepError::fonte_caminho_shell_history_substitution(nome, caminho, byte),
16823 DepError::FonteCaminhoShellHistorySubstitution {
16824 nome: nome.to_string(),
16825 caminho: caminho.to_string(),
16826 byte,
16827 },
16828 ),
16829 ];
16830 for (via_ctor, via_struct_literal) in cases {
16831 assert_eq!(
16832 via_ctor, via_struct_literal,
16833 "fonte_caminho_byte_ctors!-generated ctor must route \
16834 (nome, caminho, byte) through `.to_string()` / byte-\
16835 identity in declared field order — a field-swap or \
16836 silent-conversion regression surfaces here rather than \
16837 at a downstream diagnostic-shape mismatch",
16838 );
16839 }
16840 }
16841}
16842
16843#[cfg(test)]
16844mod dep_source_is_variant_tests {
16845 use super::*;
16846
16847 fn all_variants() -> Vec<(DepSource, &'static str)> {
16848 vec![
16849 (
16850 DepSource::Git {
16851 repo: "github:pleme-io/caixa-teia".into(),
16852 tag: Some("v0.1.0".into()),
16853 rev: None,
16854 branch: None,
16855 },
16856 "Git",
16857 ),
16858 (
16859 DepSource::Path {
16860 caminho: "../caixa-teia".into(),
16861 },
16862 "Path",
16863 ),
16864 ]
16865 }
16866
16867 fn predicate_row(s: &DepSource) -> [bool; 2] {
16868 [s.is_git(), s.is_path()]
16869 }
16870
16871 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
16872 // derive-generated per-arm predicate partition — for every variant
16873 // in `all_variants()`, the observed 2-slot predicate row must equal
16874 // a one-hot row with the `true` at exactly the same index as the
16875 // variant's declaration order. Expected rows are generated live
16876 // from the enumeration rather than transcribed by hand, so a
16877 // copy-paste flip that reroutes one arm through the wrong predicate
16878 // lane trips at the identity-diagonal assertion the way every peer
16879 // sibling [`DepList`] / [`crate::CaixaKind`] / [`crate::CaixaDialeto`]
16880 // / [`crate::supervisor::RestartStrategy`] / [`crate::supervisor::RestartPolicy`]
16881 // / [`crate::upgrade::UpgradeInstruction`] /
16882 // [`crate::aplicacao::PlacementStrategy`] /
16883 // [`crate::aplicacao::RateLimitUnit`] /
16884 // [`crate::aplicacao::WitTarget`] /
16885 // [`crate::render::PathShapeViolation`] partition pin already does.
16886 #[test]
16887 fn dep_source_is_variant_predicates_partition_the_arm_set() {
16888 let variants = all_variants();
16889 for (idx, (variant, name)) in variants.iter().enumerate() {
16890 let observed = predicate_row(variant);
16891 let mut expected = [false; 2];
16892 expected[idx] = true;
16893 assert_eq!(
16894 observed, expected,
16895 "DepSource::{name} at declaration-order slot {idx} must \
16896 satisfy exactly one is_* predicate (its own); observed \
16897 row must equal the one-hot expected row — a drift \
16898 would silently reroute one `:fonte`-arm consumer \
16899 through the wrong predicate lane"
16900 );
16901 }
16902 }
16903
16904 // Byte-parity pin on the two field-agnostic `matches!` shapes the
16905 // per-arm arm-discriminator predicates replace at any future
16906 // consumer site (a `:fonte`-shape-only lint rule that flags path
16907 // deps outside dev-caixas via `dep.fonte().is_some_and(DepSource::is_path)`,
16908 // a future admission-webhook that rejects `:fonte` shapes outside
16909 // the `is_git()` accept-set, a caixa-lacre indexing pass that
16910 // dispatches on `s.is_git()` without extracting `repo` / `caminho`).
16911 // Refuses a future accidental split between the derived predicate
16912 // and its `matches!` shape — a hand-rolled shadow impl that
16913 // overrides one path, an accidental rebrand that leaves one
16914 // consumer on the raw `matches!` form — on the two load-bearing
16915 // `:fonte`-arm-discriminator axes every downstream substrate
16916 // consumer of the dep-source axis keys off.
16917 #[test]
16918 fn dep_source_is_git_and_is_path_byte_equal_matches_shape() {
16919 for (variant, name) in all_variants() {
16920 let via_matches_git = matches!(variant, DepSource::Git { .. });
16921 let via_predicate_git = variant.is_git();
16922 assert_eq!(
16923 via_predicate_git, via_matches_git,
16924 "DepSource::{name}.is_git() must byte-equal \
16925 matches!(_, DepSource::Git {{ .. }}) — otherwise a \
16926 future converged consumer site would silently \
16927 disagree with its pre-lift shape"
16928 );
16929 let via_matches_path = matches!(variant, DepSource::Path { .. });
16930 let via_predicate_path = variant.is_path();
16931 assert_eq!(
16932 via_predicate_path, via_matches_path,
16933 "DepSource::{name}.is_path() must byte-equal \
16934 matches!(_, DepSource::Path {{ .. }}) — otherwise a \
16935 future converged consumer site would silently \
16936 disagree with its pre-lift shape"
16937 );
16938 }
16939 }
16940
16941 // Cross-pin against every constructor path that materializes a
16942 // [`DepSource`] shape today (the [`DepSource::default_github`]
16943 // resolver-side fallback that materializes an unpinned
16944 // `github:<org>/<nome>` git shorthand, the [`Dep::git`] author-
16945 // surface constructor that materializes a pinned `:tag`-carrying
16946 // `DepSource::Git`, a hand-rolled `DepSource::Path` the dev-mode
16947 // fixture family builds inline). Every constructor's return must
16948 // satisfy the arm-discriminator predicate the constructor's
16949 // variant name matches — a future constructor addition (an
16950 // in-tree registry-fetch pin, a `DepSource::Feira` variant the
16951 // enclosing docstring already names as a trajectory item) surfaces
16952 // as a build-time failure that names the offending drift when its
16953 // return arm doesn't route through the paired predicate.
16954 #[test]
16955 fn dep_source_constructors_route_through_paired_is_variant_predicate() {
16956 let via_default_github = DepSource::default_github("pleme-io", "caixa-teia");
16957 assert!(
16958 via_default_github.is_git(),
16959 "DepSource::default_github must materialize a Git-arm shape — \
16960 a future constructor that routed through a non-Git arm \
16961 (a registry-fetch pin, a `DepSource::Feira` promotion) \
16962 would silently split the resolver's unpinned-shorthand \
16963 materializer from the sole_pin() precedence cascade"
16964 );
16965 assert!(
16966 !via_default_github.is_path(),
16967 "DepSource::default_github must NOT materialize a Path-arm \
16968 shape — the paired negation pin"
16969 );
16970
16971 let via_dep_git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
16972 .fonte
16973 .expect("Dep::git materializes a Some(fonte)");
16974 assert!(
16975 via_dep_git.is_git(),
16976 "Dep::git's `:fonte` materialization must land on the Git \
16977 arm — the author-surface pinned-git constructor's return \
16978 must route through the paired predicate"
16979 );
16980 assert!(!via_dep_git.is_path(), "paired negation pin");
16981
16982 let via_path = DepSource::Path {
16983 caminho: "../caixa-teia".into(),
16984 };
16985 assert!(
16986 via_path.is_path(),
16987 "the dev-mode Path-arm materialization must satisfy is_path()"
16988 );
16989 assert!(!via_path.is_git(), "paired negation pin");
16990 }
16991}