caixa_core/dep.rs
1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4/// A single dependency declaration in a `caixa.lisp` manifest.
5///
6/// **Store model = Git, like Zig.** There is no central registry; a caixa is
7/// just a Git repo with a `caixa.lisp` at its root. When `:fonte` is omitted,
8/// the resolver falls back to `github:<default-org>/<nome>` (org defaults to
9/// `pleme-io`, override via `~/.config/caixa/config.yaml`).
10///
11/// ```lisp
12/// ;; Shorthand — resolves to github:pleme-io/caixa-teia (or your default org):
13/// (:nome "caixa-teia" :versao "^0.1")
14///
15/// ;; Explicit git source:
16/// (:nome "caixa-teia"
17/// :versao "^0.1"
18/// :fonte (:tipo git :repo "github:pleme-io/caixa-teia" :tag "v0.1.0"))
19///
20/// ;; Arbitrary git URL (not limited to GitHub):
21/// (:nome "private-caixa"
22/// :versao "*"
23/// :fonte (:tipo git :repo "ssh://git@git.example/team/priv-caixa.git" :branch "main"))
24///
25/// ;; Local path (dev only; not publishable):
26/// (:nome "caixa-teia"
27/// :versao "0.1.0"
28/// :fonte (:tipo path :caminho "../caixa-teia"))
29/// ```
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
31#[serde(rename_all = "camelCase")]
32pub struct Dep {
33 /// Caixa name — must match the target caixa's `:nome`.
34 pub nome: String,
35
36 /// Semver constraint string (`"^0.1"`, `"~0.1.2"`, `"0.1.0"`, `"*"`).
37 pub versao: String,
38
39 /// Where to fetch the caixa from. Defaults to the feira registry.
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub fonte: Option<DepSource>,
42
43 /// If true, a missing `:fonte` is not a build failure.
44 #[serde(default, skip_serializing_if = "is_false")]
45 pub opcional: bool,
46
47 /// Feature flags to enable on the target caixa.
48 #[serde(default, skip_serializing_if = "Vec::is_empty")]
49 pub caracteristicas: Vec<String>,
50}
51
52/// Where a dep is fetched from. Tagged via `:tipo` in Lisp.
53///
54/// Only two shapes — Git and local Path. No central registry variant: a caixa
55/// is just a Git repo. Omitting `:fonte` means *"use the default resolver
56/// convention"*, which is `github:<default-org>/<nome>`; the resolver fills
57/// that in when computing the lacre.
58///
59/// The [`gen_platform::IsVariant`] derive emits per-arm arm-discriminator
60/// predicates — [`Self::is_git`], [`Self::is_path`] — so every downstream
61/// consumer that only needs the arm-discriminator projection (not the
62/// borrowed field value) reaches for one typed dispatch on the substrate
63/// primitive rather than a hand-rolled `matches!(s, DepSource::X { .. })`
64/// literal. Extends the closed-set-typed-enum discipline the sibling
65/// caixa-core enums ([`crate::CaixaKind`], [`crate::CaixaDialeto`],
66/// [`crate::supervisor::RestartStrategy`], [`crate::supervisor::RestartPolicy`],
67/// [`crate::upgrade::UpgradeInstruction`], [`crate::aplicacao::PlacementStrategy`],
68/// [`crate::aplicacao::RateLimitUnit`], [`crate::aplicacao::WitTarget`],
69/// [`crate::render::PathShapeViolation`], [`DepList`]) and the sibling
70/// out-of-crate enums (caixa-arch's `InvariantKind` + `ArchVerdict`,
71/// caixa-lint's `Severity` + `FixSafety`, caixa-provedor's
72/// `FerriteRuntime`, caixa-theme's `Semantic`, caixa-flux's `GitRefSpec`,
73/// caixa-ast's `NodeKind` + `TriviaKind`) already carry onto the
74/// two-arm `:fonte` dep-source axis — the 17th closed-set typed enum
75/// on the caixa surface, and the first on the outer-`Dep` `:fonte`-slot
76/// axis every git-fetching consumer runs after the outer `:fonte` slot
77/// resolves to a shape.
78#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, gen_platform::IsVariant)]
79#[serde(tag = "tipo", rename_all = "lowercase")]
80pub enum DepSource {
81 /// Clone from Git. One of `:tag`, `:rev`, or `:branch` may be set.
82 /// `repo` can be a `github:org/repo` shorthand, a full `https://…` URL,
83 /// or any git-ssh URL.
84 Git {
85 repo: String,
86 #[serde(default, skip_serializing_if = "Option::is_none")]
87 tag: Option<String>,
88 #[serde(default, skip_serializing_if = "Option::is_none")]
89 rev: Option<String>,
90 #[serde(default, skip_serializing_if = "Option::is_none")]
91 branch: Option<String>,
92 },
93 /// Local filesystem path — dev only; cannot be published.
94 Path { caminho: String },
95}
96
97impl DepSource {
98 /// Build a registry-shorthand git source (`github:<org>/<nome>`).
99 ///
100 /// This is the resolver-side fallback for `dep.fonte: None`, not an
101 /// author-surface value — it carries no pin (`:tag`/`:rev`/`:branch`
102 /// all `None`) and is therefore rejected by [`Self::validate`]. The
103 /// resolver fills the pin in at fetch time from the resolved commit;
104 /// authors never serialize this shape as a `Dep::fonte` value.
105 #[must_use]
106 pub fn default_github(org: &str, nome: &str) -> Self {
107 Self::Git {
108 repo: format!("github:{org}/{nome}"),
109 tag: None,
110 rev: None,
111 branch: None,
112 }
113 }
114
115 /// Substrate-canonical per-`:fonte` sole-set git-pin scalar accessor
116 /// every consumer that reads "which single git ref does this source
117 /// resolve to?" keys off — returns the author-declared `:tag` /
118 /// `:rev` / `:branch` byte-string verbatim as an `Option<&str>`,
119 /// borrowed from the typed slot's own `Option<String>` storage; `None`
120 /// on [`Self::Path`] (a path source carries no git-ref) and on a
121 /// [`Self::Git`] variant whose `tag`, `rev`, and `branch` are all
122 /// `None` (the [`Self::default_github`] shorthand shape the resolver
123 /// materializes when the author omits `:fonte` — rejected by
124 /// [`Self::validate`], but the accessor's return is defined on this
125 /// arm too so pre-validate consumers reach for the same typed dispatch
126 /// as post-validate ones).
127 ///
128 /// **Precedence: rev > tag > branch.** The canonical precedence every
129 /// per-`:fonte` git-ref consumer already applies: caixa-resolver's
130 /// per-fetch `git checkout <ref>` reads through the same
131 /// `rev.or(tag).or(branch)` cascade at caixa-resolver/src/resolve.rs,
132 /// and caixa-crd's `dep_into_ref` `CaixaSource.git_ref` fill reads
133 /// through the same cascade at caixa-crd/src/conversion.rs. The
134 /// [`Self::validate`] gate enforces "exactly one pin set" — under
135 /// that invariant every accepted [`Self::Git`] carries exactly one
136 /// non-`None` pin and the precedence is unobservable, but the
137 /// precedence remains defined for pre-validate consumers (the
138 /// resolver's `MissingPin` diagnostic path, the caixa-crd
139 /// round-trip's default `"main"` fallback the author never sees a
140 /// diagnostic on) and defense-in-depth for a hypothetical future
141 /// state where multiple pins survive the gate. The precedence is
142 /// **rev before tag** because `:rev` (a git commit OID) is the
143 /// reproducibility-strongest identifier — an OID resolves to exactly
144 /// one commit regardless of which refname points at it, whereas
145 /// `:tag` and `:branch` are refnames the remote can silently move
146 /// (a tag re-push, a branch head advance); the resolver's freeze
147 /// step at fetch time promotes the resolved commit to `:rev` for
148 /// exactly this reason. **Tag before branch** because `:tag` is
149 /// conventionally immutable (a release tag) whereas `:branch` is
150 /// conventionally mutable (a tracking ref) — a caixa carrying both
151 /// a release tag and a tracking branch reads as "prefer the release
152 /// pin, fall through to the tracking pin only if the release is
153 /// missing". The cascade order also matches the byte-order every
154 /// per-`:tag`/`:rev`/`:branch` diagnostic tuple this crate emits
155 /// (`(":tag", tag), (":rev", rev), (":branch", branch)` — see
156 /// [`Self::validate`]'s `pins` array).
157 ///
158 /// Prior to this lift the "sole set pin" projection sat twice in the
159 /// workspace — inline at caixa-resolver's `fetch_git` (`let gitref =
160 /// rev.or(tag).or(branch).ok_or_else(|| ResolveError::MissingPin
161 /// { … })?;`) and at caixa-crd's `dep_into_ref`
162 /// (`git_ref: rev.clone().or(tag.clone()).or(branch.clone())
163 /// .unwrap_or_else(|| "main".to_string())`) — two open-coded copies
164 /// of the same precedence cascade with no compile-time link back to
165 /// the typed slot. A future extension of the pin axis to a richer
166 /// author surface (a `:commit` pin peer of `:rev` once the substrate
167 /// grows a signed-commit-verification pin, a `:ref` pin the M4
168 /// substrate operator resolves per-cluster ahead of fetch, a
169 /// promotion of the plain `Option<String>` pins to a typed
170 /// `GitPin::{Rev(Oid), Tag(RefName), Branch(RefName)}` newtype
171 /// once the sibling [`crate::render::is_git_oid`] /
172 /// [`crate::render::is_git_ref_name`] gates land as typed
173 /// constructors) would have had to be threaded through both
174 /// open-coded copies in lockstep or the resolver's `git checkout`
175 /// target would silently disagree with the CRD's `git_ref` fill —
176 /// an author's `(:fonte (:tipo git :repo "…" :rev "deadbeef" :tag
177 /// "v1"))` would ship with the resolver checking out `deadbeef`
178 /// while the CRD round-trip re-emitted a Dep pointing at `v1`, one
179 /// lacre closure disagreeing with the emitted K8s CR the operator
180 /// reads. Lifting the resolution to a typed method on the substrate
181 /// primitive means both downstream consumers reach for exactly one
182 /// typed dispatch — the resolver's accept-set migrates as a unit on
183 /// any future pin-axis addition.
184 ///
185 /// Peer of the sibling outer-`Dep` [`Dep::fonte`] (d65d1bf)
186 /// `Option<&DepSource>` composite-reference accessor on the outer-
187 /// `Dep` `:fonte`-slot axis — extended one nesting level down onto
188 /// the per-[`Self::Git`]-variant sole-set-pin projection axis every
189 /// git-fetching consumer runs after the outer `:fonte` slot resolves
190 /// to a [`Self::Git`] shape. Same "one typed dispatch on the
191 /// substrate primitive, thin projections at each consumer" discipline
192 /// the outer accessor family already carries.
193 #[must_use]
194 pub fn sole_pin(&self) -> Option<&str> {
195 match self {
196 Self::Git {
197 tag, rev, branch, ..
198 } => rev.as_deref().or(tag.as_deref()).or(branch.as_deref()),
199 Self::Path { .. } => None,
200 }
201 }
202
203 /// Validate the `:fonte` value-shape: every author-surface
204 /// `:fonte (:tipo git …)` must carry a non-empty `:repo` and
205 /// exactly one of `:tag` / `:rev` / `:branch` set to a non-empty
206 /// value; every `:fonte (:tipo path …)` must carry a non-empty
207 /// `:caminho`.
208 ///
209 /// Called from [`Dep::validate`] with the dep's `:nome` so every
210 /// diagnostic carries the offending entry verbatim — same
211 /// self-locating shape the `:deps :versao` (2420c44),
212 /// `:membros :versao` (9888b13), `:children :versao` (b38ff3a),
213 /// `:placement :clusters` (6cbb900), and `:membros :caixa`
214 /// (3f9d7a0) gates already expose.
215 ///
216 /// Until this gate landed `:fonte` was the only `:deps`-related
217 /// typed surface still untyped past `Caixa::from_lisp`:
218 /// - Empty `:repo` (`(:tipo git :repo "" :tag "v1")`) silently
219 /// passed parse and surfaced as a git-clone failure at
220 /// lacre-resolve time, far from the source caixa.lisp.
221 /// - A bare `(:tipo git :repo "…")` with no `:tag`/`:rev`/`:branch`
222 /// passed parse and surfaced as the resolver's
223 /// [`ResolveError::MissingPin`](../../caixa-resolver/src/resolve.rs)
224 /// at fetch time, again far from the source caixa.lisp; lifting
225 /// to validate-time gives the author the same diagnostic at the
226 /// edit site.
227 /// - `(:tipo git :repo "…" :tag "v1" :branch "main")` — multiple
228 /// pins set — passed parse and the resolver silently picked
229 /// `:rev > :tag > :branch`, ignoring the other pins with no
230 /// diagnostic; the author had no way to know their `:branch`
231 /// was dropped. This is the canonical "pin drift" footgun.
232 /// - An empty pin value (`(:tipo git :repo "…" :tag "")`) silently
233 /// passed parse and surfaced as `git checkout ""` at fetch time.
234 /// - Empty `:caminho` (`(:tipo path :caminho "")`) silently passed
235 /// parse and surfaced as
236 /// [`ResolveError::MissingPath`](../../caixa-resolver/src/resolve.rs)
237 /// with `path: PathBuf("")` — not actionable.
238 ///
239 /// Each rejected shape maps to a typed
240 /// [`DepError::Fonte*`] variant that names the offending
241 /// dep's `:nome` and the specific axis, so the author can grep
242 /// their caixa.lisp for the `:nome "<nome>"` block and fix it in
243 /// one edit.
244 pub fn validate(&self, nome: &str) -> Result<(), DepError> {
245 match self {
246 Self::Git {
247 repo,
248 tag,
249 rev,
250 branch,
251 } => {
252 if repo.is_empty() {
253 return Err(DepError::FonteRepoEmpty {
254 nome: nome.to_string(),
255 });
256 }
257 // The `:repo` value flows verbatim into the caixa-resolver's
258 // `git clone <repo>` subprocess invocation. Until this gate
259 // landed `:repo` was the last untyped `:fonte`-related axis
260 // past the empty arm: a malformed-but-non-empty repo URL
261 // (`":repo "github:p/x ""` trailing space, paste-from-doc;
262 // `":repo "-upload-pack=evil""` leading `-` — the canonical
263 // CLI-argument-injection vector at the `git clone` boundary;
264 // `":repo "pleme-io/caixa-teia""` missing scheme — `git clone`
265 // reads as a relative filesystem path rather than the
266 // GitHub-shorthand expansion; `":repo "github:p/x\n""`
267 // embedded newline; `":repo "github:café/x""` raw non-ASCII)
268 // silently passed validate and the failure surfaced at
269 // lacre-resolve time with a porcelain-quoting-confused error
270 // far from the source caixa.lisp. The lifted predicate makes
271 // the git-porcelain-URL intersection-floor a substrate-level
272 // invariant at validate time, peer with the three pin axes
273 // (`:tag` + `:branch` via [`crate::render::is_git_ref_name`],
274 // e70d213; `:rev` via [`crate::render::is_git_oid`], be07fd5)
275 // — every `:fonte (:tipo git …)` past validate is now
276 // structurally accept-shaped on every axis the resolver
277 // consumes (the `:repo` URL the `git clone` invokes against,
278 // the `:tag`/`:branch` refname `git fetch`/`git checkout`
279 // accepts, the `:rev` commit OID the lacre's content-
280 // addressing equality probe resolves), closing the
281 // `:fonte` slot's value-shape trajectory end-to-end.
282 if let Err(reason) = crate::render::is_git_repo_url(repo) {
283 return Err(DepError::FonteRepoShape {
284 nome: nome.to_string(),
285 repo: repo.clone(),
286 reason,
287 });
288 }
289 let pins: [(&'static str, Option<&String>); 3] = [
290 (":tag", tag.as_ref()),
291 (":rev", rev.as_ref()),
292 (":branch", branch.as_ref()),
293 ];
294 let set: Vec<&'static str> =
295 pins.iter().filter_map(|(n, v)| v.map(|_| *n)).collect();
296 match set.len() {
297 0 => {
298 return Err(DepError::FontePinMissing {
299 nome: nome.to_string(),
300 });
301 }
302 1 => {
303 for (pin, value) in pins {
304 if value.is_some_and(String::is_empty) {
305 return Err(DepError::FontePinEmpty {
306 nome: nome.to_string(),
307 pin: pin.to_string(),
308 });
309 }
310 }
311 }
312 _ => {
313 return Err(DepError::FontePinAmbiguous {
314 nome: nome.to_string(),
315 pins: set.join(", "),
316 });
317 }
318 }
319 // Per-pin value-shape gate. The refname-shaped axes
320 // (`:tag` + `:branch`) route through
321 // [`crate::render::is_git_ref_name`]; the hex-OID-shaped
322 // `:rev` axis routes through
323 // [`crate::render::is_git_oid`]. The two predicates
324 // partition the `:fonte` pin axes structurally — refname
325 // vs. hex commit — so a cross-axis mis-slot (the
326 // canonical "I conflated `:rev` and `:branch`" footgun:
327 // `:rev "main"` defeating the reproducibility contract,
328 // `:tag "deadbeef…"` mis-slotting a SHA into the
329 // refname-shaped axis) lands at the offending axis's
330 // predicate, not at lacre-resolve `git fetch` /
331 // `git checkout` time. Their valid sets intersect at
332 // the empty set: every refname is rejected by
333 // `is_git_oid`, every OID is rejected by
334 // `is_git_ref_name`, structurally.
335 //
336 // Until this gate landed `:tag` / `:branch` were the
337 // refname-shaped axes still untyped past the empty-pin
338 // arm: a malformed-but-non-empty refname
339 // (`:tag "v0.1.0 "` trailing space — the canonical
340 // paste-from-doc footgun; `:tag "v0.1.0.lock"` colliding
341 // with git's atomic-rename guard suffix; `:tag "../escape"`
342 // path-traversal via consecutive dots; `:branch "main "`
343 // trailing space; `:branch "feature/foo bar"` embedded
344 // space; `:branch "@"` the literal HEAD alias;
345 // `:branch "refs/heads/main"` the fully-qualified ref
346 // copied from `git show-ref` output that resolves to
347 // a literal ref named `refs/heads/refs/heads/main` on
348 // disk) silently passed validate; the `:rev` axis was
349 // the last `:fonte`-related axis still untyped past the
350 // empty-pin arm: a malformed-but-non-empty hex-OID
351 // (`:rev "main"` conflating with `:branch` — the
352 // reproducibility-contract leak; `:rev "v0.1.0"`
353 // conflating with `:tag` — the same mis-slot on the
354 // refname/OID boundary; `:rev "c0ffee"` an abbreviated
355 // 6-char prefix that's ambiguous across repo history;
356 // `:rev "DEADBEEF…"` an uppercase OID that round-trips
357 // inconsistently against `git rev-parse HEAD`'s
358 // lowercase emission) silently passed validate and the
359 // failure surfaced at lacre-resolve `git fetch` /
360 // `git checkout` time with a quoting-confused error
361 // far from the source caixa.lisp, with no field naming
362 // which `:deps` entry carried the typo. Lifting both
363 // gates to caixa-build time matches the value-shape
364 // trajectory the peer typed axes already follow
365 // (c4213a4 typed WitContract endpoint/subject/slot;
366 // eb3456d :entrada :paths; c7d05ec :entrada :host;
367 // 4f0390b :contratos :endpoint; 6226bf4 :contratos :wit;
368 // 63e18a0 :contratos :subject; 2f4316e :contratos
369 // :slot; e70d213 :fonte :tag + :branch) — the typed
370 // slot's valid set matches its downstream consumer's
371 // accepted set (here, the git porcelain's refname /
372 // commit-OID grammars at `git fetch` / `git checkout`
373 // time), structurally. Same diagnostic shape every
374 // per-axis value-shape lift already exposes
375 // (`*Invalid { axis, reason }`); the `value:` field
376 // carries the offending refname / OID verbatim so the
377 // author can grep their caixa.lisp for the
378 // `:tag "<value>"` / `:branch "<value>"` /
379 // `:rev "<value>"` literal and fix it in one edit.
380 for (pin, value) in [(":tag", tag.as_ref()), (":branch", branch.as_ref())] {
381 if let Some(v) = value
382 && let Err(reason) = crate::render::is_git_ref_name(v)
383 {
384 return Err(DepError::FontePinShape {
385 nome: nome.to_string(),
386 pin: pin.to_string(),
387 value: v.clone(),
388 reason,
389 });
390 }
391 }
392 if let Some(v) = rev.as_ref()
393 && let Err(reason) = crate::render::is_git_oid(v)
394 {
395 return Err(DepError::FontePinShape {
396 nome: nome.to_string(),
397 pin: ":rev".to_string(),
398 value: v.clone(),
399 reason,
400 });
401 }
402 Ok(())
403 }
404 Self::Path { caminho } => Self::validate_caminho(nome, caminho),
405 }
406 }
407
408 /// Reproducibility + path-API gate on the `:fonte (:tipo path …)`
409 /// `:caminho` axis. Walks the leading-byte cascade closed by the
410 /// b94fd83 (`/`), a5c248e (`~`), and f4efe9c (`$`) arms; the
411 /// orthogonal embedded-control-byte arm (d624c8d) covering
412 /// `0x00..=0x1F` plus `0x7F` anywhere in the value; and the
413 /// embedded-`\` Windows-path-separator arm closing the
414 /// cross-host-OS-separator divergence vector on the same
415 /// THEORY.md §V.2 render-determinism axis.
416 ///
417 /// Extracted from [`Self::validate`]'s `Self::Path` arm because the
418 /// per-arm cascade now spans nine diagnostic shapes — every new
419 /// `:caminho` arm (a future `&` / `;` / `|` shell-metachar arm,
420 /// a future glob-metachar `*` / `?` arm) lands here rather than
421 /// re-inflating `Self::validate`. The
422 /// function stays a thin per-arm linear walk for one reason: each
423 /// arm's diagnostic carries a distinct typed [`DepError`] variant
424 /// rather than a parser-shaped `reason` string, so collapsing the
425 /// cascade onto a generic [`crate::render`] predicate would regress
426 /// the per-arm self-locating diagnostic that `feira lint` consumers
427 /// depend on. The wrapped predicate trajectory ([`crate::render::is_dns_1123_label`],
428 /// [`crate::render::is_git_repo_url`], etc.) lives on the
429 /// reason-string-shaped axes; the `:caminho` axis keeps its
430 /// per-arm variant shape.
431 #[allow(
432 clippy::too_many_lines,
433 reason = "the per-arm cascade is structurally flat by design — every \
434 `:caminho` arm carries its own typed [`DepError`] variant + \
435 per-arm Why comment, so collapsing the cascade onto a generic \
436 [`crate::render`] predicate would regress the per-arm self-locating \
437 diagnostic the `feira lint` consumer surface depends on"
438 )]
439 fn validate_caminho(nome: &str, caminho: &str) -> Result<(), DepError> {
440 if caminho.is_empty() {
441 return Err(DepError::FonteCaminhoEmpty {
442 nome: nome.to_string(),
443 });
444 }
445 // Reproducibility gate on the `:fonte (:tipo path …)`
446 // `:caminho` axis. The lacre pipeline embeds the value
447 // verbatim in its per-dep content-address
448 // (`conteudo: format!("path:{caminho}")`,
449 // caixa-resolver/src/resolve.rs:189) and that string
450 // folds into the BLAKE3 closure the lacre keys every
451 // downstream consumer (the substrate's reproducibility
452 // contract, CAIXA-SDLC §III.2 — the lacre is the
453 // build's content-addressed identity, peer of the Nix
454 // store path) against. Until this gate landed an
455 // absolute `:caminho` (`/home/me/work/caixa-teia` — the
456 // canonical "I dragged the folder out of Finder into
457 // my editor" footgun; `/Users/alice/dev/caixa-teia` on
458 // the macOS path-layout peer; the
459 // `${WORKSPACE}/caixa-teia` shell-expanded literal
460 // pasted from a CI manifest) silently passed validate
461 // and the failure surfaced *as a successful build with
462 // a divergent lacre*: the BLAKE3 closure on Alice's
463 // workstation differed from the closure on Bob's
464 // workstation, two CI runners with different
465 // `${HOME}` layouts emitted two distinct
466 // content-addresses for the byte-identical caixa, and
467 // the substrate's "the lacre is the build's identity"
468 // contract silently broke far from the source
469 // caixa.lisp — the most insidious failure mode the
470 // typed slot can carry (no error surfaces; the
471 // divergence is invisible until two machines compare
472 // lacres). The same THEORY.md §V.2 render-determinism
473 // discipline `is_sandboxed_relative_path` already
474 // applies on the M2 typed path-slots
475 // (`:behavior :on-*`, `:upgrade-from :state-change
476 // :script`, `:bibliotecas`, `:exe`, `:servicos`), here
477 // narrowed to the absolute-vs-relative axis only:
478 // `:fonte :caminho`'s canonical author-surface form is
479 // the `..`-traversing sibling-workspace path
480 // (`"../caixa-teia"`, the in-tree dev-dep frame), so a
481 // full `is_sandboxed_relative_path` lift would
482 // structurally reject every legitimate path-fonte
483 // dep. The narrower
484 // `std::path::Path::is_absolute` cut admits the
485 // sibling-workspace form while still rejecting the
486 // host-layout-leaking absolute shape — the
487 // reproducibility contract bites at exactly the
488 // absolute boundary, and that's the axis the
489 // substrate-level invariant is meant to hold. Same
490 // diagnostic shape every per-axis value-shape lift on
491 // the surrounding [`DepError::Fonte*`] cluster carries
492 // (the offending `:nome` + offending `:caminho`
493 // quoted verbatim so the author can grep their
494 // caixa.lisp for the `:caminho "<value>"` literal and
495 // fix it in one edit). The empty arm strictly
496 // precedes this arm so the blank-string footgun
497 // surfaces the more self-locating
498 // `FonteCaminhoEmpty` diagnostic (the empty string
499 // is not absolute under `Path::new("").is_absolute()`
500 // so the precedence is a no-op at value level — the
501 // pin matters only at the diagnostic-shape level if
502 // a future codec round-trip ever produces an empty
503 // string that probes as absolute).
504 if std::path::Path::new(caminho).is_absolute() {
505 return Err(DepError::FonteCaminhoAbsolute {
506 nome: nome.to_string(),
507 caminho: caminho.to_string(),
508 });
509 }
510 // Reproducibility gate's tilde-expansion arm. The b94fd83
511 // `FonteCaminhoAbsolute` closes the leading-`/`
512 // host-layout-leak; a `:caminho "~/work/caixa-teia"` (the
513 // canonical paste-from-shell-prompt / paste-from-`cd ~`-
514 // doc footgun) silently passed both the empty arm and
515 // the absolute arm because `Path::new("~").is_absolute()`
516 // returns `false` — `~` is a shell-expansion convention,
517 // not a POSIX path component, so `std::path::Path` treats
518 // it as a literal directory-name segment. The lacre
519 // pipeline then embedded the value verbatim
520 // (`conteudo: format!("path:~/work/caixa-teia")`) and the
521 // failure mode forked per consumer:
522 //
523 // - The caixa-resolver's `Path` arm folds `:caminho`
524 // through `Path::new(caminho).join(<file>)` without
525 // `~`-expansion, so the build looked for a literal
526 // `./~/work/caixa-teia` subdirectory and failed at
527 // resolve time with a `No such file or directory`
528 // error far from the source caixa.lisp (the lacre
529 // itself, though, was already byte-identical across
530 // machines — every machine emitted the same
531 // `path:~/work/caixa-teia` content-address).
532 // - A future caixa-resolver pass that *does* expand `~`
533 // (the canonical shell-convention idiom every
534 // resolver eventually reaches for once an author
535 // reports the literal-`~`-directory bug) would re-
536 // introduce the host-layout-leak the b94fd83 absolute
537 // gate closes: Alice's `~` expands to `/home/alice`,
538 // Bob's to `/home/bob`, two CI runners with different
539 // `$HOME` layouts resolve to two distinct paths for
540 // the byte-identical caixa, and the substrate's
541 // "the lacre is the build's identity" contract
542 // silently breaks far from the source caixa.lisp.
543 //
544 // Closing the gate at `DepSource::validate` (here at the
545 // canonical caixa-build-time boundary, peer with the
546 // absolute arm above) refuses both failure modes
547 // structurally: the typed accepted set excludes every
548 // `~`-prefixed authoring shape, so the resolver is
549 // free to grow `~`-expansion (or any other convention-
550 // expansion the substrate adopts) without re-opening
551 // the host-layout-leak at the typed boundary. Same
552 // diagnostic shape every per-axis value-shape gate on
553 // the surrounding [`DepError::Fonte*`] cluster carries
554 // (the offending `:nome` + offending `:caminho` quoted
555 // verbatim so the author can grep their caixa.lisp for
556 // the `:caminho "<value>"` literal and fix it in one
557 // edit).
558 //
559 // The cascade preserves narrower-diagnostic-first
560 // ordering: `FonteCaminhoEmpty` → `FonteCaminhoAbsolute`
561 // → `FonteCaminhoTildeExpansion`. The empty arm
562 // structurally precedes both (the bytes "" / "~" don't
563 // overlap), and the absolute arm structurally precedes
564 // the tilde arm (an absolute path can't start with `~`
565 // since absolute paths start with `/`; the bytes "/" /
566 // "~" don't overlap either). Both arms are
567 // value-disjoint, so the precedence is a no-op at value
568 // level — the pin matters only at the diagnostic-shape
569 // level if a future codec round-trip ever produces a
570 // value that probes as both absolute and tilde-prefixed.
571 if caminho.starts_with('~') {
572 return Err(DepError::FonteCaminhoTildeExpansion {
573 nome: nome.to_string(),
574 caminho: caminho.to_string(),
575 });
576 }
577 // Reproducibility gate's shell-variable-expansion arm.
578 // The b94fd83 `FonteCaminhoAbsolute` closes the leading-`/`
579 // host-layout-leak; the a5c248e `FonteCaminhoTildeExpansion`
580 // closes the leading-`~` shell-home-expansion shape; the
581 // leading-`$` is the sibling shell-variable-expansion shape
582 // — same host-layout-leaking semantic, different syntactic
583 // surface. A `:caminho "$HOME/work/caixa-teia"` (the
584 // canonical paste-from-`echo $HOME`-doc footgun) and the
585 // `${VAR}`-braced variant (`"${WORKSPACE}/caixa-teia"` —
586 // the canonical paste-from-CI-manifest footgun every
587 // GitHub Actions / GitLab CI / Drone manifest carries)
588 // silently passed every prior arm because
589 // `Path::is_absolute` returns false on `$` (the `$` is a
590 // shell convention, not a POSIX path component, so
591 // `std::path::Path` treats it as a literal directory-name
592 // segment) and the tilde arm's `starts_with('~')` doesn't
593 // fire.
594 //
595 // Same per-consumer failure-fork the tilde arm closes:
596 //
597 // - The caixa-resolver's `Path` arm folds `:caminho`
598 // through `Path::new(caminho).join(<file>)` without
599 // `$`-expansion, so the build looks for a literal
600 // `./$HOME/work/caixa-teia` subdirectory and fails at
601 // resolve time with a `No such file or directory`
602 // error far from the source caixa.lisp.
603 // - A future caixa-resolver pass that *does* expand
604 // `$VAR` (the shell-convention idiom every resolver
605 // eventually reaches for once an author reports the
606 // literal-`$HOME`-directory bug, especially for CI's
607 // `${WORKSPACE}` idiom) would re-introduce the host-
608 // layout-leak the b94fd83 absolute gate closes:
609 // Alice's `$HOME` expands to `/home/alice`, Bob's to
610 // `/home/bob`, two CI runners with different
611 // `${WORKSPACE}` layouts resolve to two distinct
612 // paths for the byte-identical caixa, and the
613 // substrate's "the lacre is the build's identity"
614 // contract silently breaks far from the source
615 // caixa.lisp.
616 //
617 // Closing the gate at `DepSource::validate` (here at the
618 // canonical caixa-build-time boundary, peer with the
619 // absolute + tilde arms above) refuses both failure modes
620 // structurally. Same diagnostic shape every per-axis
621 // value-shape gate on the surrounding [`DepError::Fonte*`]
622 // cluster carries (the offending `:nome` + offending
623 // `:caminho` quoted verbatim).
624 //
625 // The cascade preserves narrower-diagnostic-first ordering:
626 // `FonteCaminhoEmpty` → `FonteCaminhoAbsolute` →
627 // `FonteCaminhoTildeExpansion` → `FonteCaminhoVarExpansion`.
628 // The empty arm structurally precedes all three subsequent
629 // arms; the absolute arm structurally precedes both the
630 // tilde and the var arms (absolute paths start with `/`,
631 // the bytes `/` / `~` / `$` don't overlap at the leading
632 // position); the tilde arm structurally precedes the var
633 // arm (`~` and `$` don't overlap at the leading position).
634 // Every pair is value-disjoint, so the precedence is a
635 // no-op at value level — the pin matters only at the
636 // diagnostic-shape level if a future codec round-trip ever
637 // produces a probe-as-both value.
638 //
639 // The gate covers every leading-`$` shape: the canonical
640 // `"$HOME/work/caixa-teia"` (POSIX shell), the braced
641 // `"${HOME}/work/caixa-teia"` (POSIX shell braces), the
642 // CI-manifest idiom `"${WORKSPACE}/caixa-teia"` (the
643 // GitHub Actions / GitLab CI / Drone paste footgun), the
644 // XDG idiom `"$XDG_CONFIG_HOME/caixa"`, and the bare `$`
645 // (degenerate "I meant `$HOME` and forgot the rest"). All
646 // shapes route through the same `caminho.starts_with('$')`
647 // byte check.
648 if caminho.starts_with('$') {
649 return Err(DepError::FonteCaminhoVarExpansion {
650 nome: nome.to_string(),
651 caminho: caminho.to_string(),
652 });
653 }
654 // Reproducibility gate's leading-space arm. The b94fd83 / a5c248e /
655 // f4efe9c arms closed the leading-byte host-layout-leak shapes
656 // (`/` / `~` / `$`); the embedded-control-byte arm below closes
657 // every byte in `0x00..=0x1F` plus `0x7F` (which already includes
658 // tab `0x09`, LF `0x0A`, CR `0x0D` — every ASCII whitespace
659 // *except* the ASCII space byte `0x20`). The bare ASCII space at
660 // the leading position is the orthogonal paste-from-aligned-doc
661 // shape that silently passed every prior arm: `Path::is_absolute`
662 // returns false on `" ../caixa-teia"` (the leading byte is `0x20`
663 // not `0x2F`), `0x20` is not `~` / `$` / `\` / a control byte, and
664 // the value's last byte is not `/`, so the canonical
665 // paste-from-aligned-`caixa.lisp`-doc footgun (every `:fonte`
666 // form in a multi-entry `:deps` block sits at the same column —
667 // an author selecting `"<sp><sp><sp>../caixa-teia"` and pasting
668 // it from the rendered alignment into a fresh entry preserves the
669 // leading whitespace verbatim) silently rendered as a path with
670 // a leading-space directory component the resolver folds through
671 // `Path::join` looking for a literal `./ ../caixa-teia`
672 // subdirectory that fails at resolve time with a non-self-
673 // locating `No such file or directory` error.
674 //
675 // The lacre pipeline's reproducibility contract bites
676 // strictly at this byte: `path:" ../caixa-teia"` and
677 // `path:"../caixa-teia"` yield distinct BLAKE3 closures
678 // (`conteudo: format!("path:{caminho}")`,
679 // caixa-resolver/src/resolve.rs:189) for the byte-divergent /
680 // semantic-identical caixa, and the substrate's "the lacre is
681 // the build's identity" contract (CAIXA-SDLC §III.2) silently
682 // breaks across two workstations whose authors differ only in
683 // paste-from-aligned-doc whitespace habits — the most insidious
684 // failure mode the typed slot can carry (no error surfaces; the
685 // divergence is invisible until two machines compare lacres).
686 //
687 // The arm fires AFTER the absolute / tilde / var leading-byte
688 // arms (each names the more self-locating shell-convention
689 // diagnostic on values that probe as that arm's leading-byte
690 // sentinel followed by a leading space — e.g.
691 // `:caminho "/ /foo"` surfaces `FonteCaminhoAbsolute` because
692 // the leading byte is `/`, not space) and BEFORE the
693 // embedded-control-byte arm (a leading-space value with an
694 // embedded control byte surfaces the broader leading-space
695 // diagnostic because the cascade walks leading-byte arms first
696 // — peer with how `FonteCaminhoAbsolute` precedes
697 // `FonteCaminhoControlChar` on `"/etc/passwd\n"`).
698 //
699 // The peer single-token-shaped axes already reject leading
700 // whitespace on the same paste-from-aligned-doc contract:
701 // [`crate::render::is_git_repo_url`] rejects leading whitespace
702 // on `:fonte :repo`, [`crate::render::is_git_ref_name`] rejects
703 // leading whitespace on `:fonte :tag`/`:branch`,
704 // [`crate::render::is_chart_description_shape`] rejects leading
705 // whitespace on `:descricao`,
706 // [`crate::render::is_spdx_expression_shape`] rejects leading
707 // whitespace on `:licenca`. Closing the same byte on
708 // `:fonte :caminho` makes the substrate-wide "no leading ASCII
709 // space anywhere in a typed string slot" invariant structurally
710 // consistent across every value-shape-gated typed surface (the
711 // `:caminho` axis was the last typed string surface still
712 // admitting a leading space byte).
713 if caminho.starts_with(' ') {
714 return Err(DepError::FonteCaminhoLeadingWhitespace {
715 nome: nome.to_string(),
716 caminho: caminho.to_string(),
717 });
718 }
719 // Reproducibility gate's leading-`-` CLI-argument-injection arm.
720 // The b94fd83 + a5c248e + f4efe9c + LeadingWhitespace arms closed
721 // the four prior leading-byte shapes (`/` / `~` / `$` / space);
722 // this arm closes the orthogonal leading-`-` axis on the same
723 // subprocess-argument-boundary the peer `is_git_repo_url` arm
724 // (render.rs:2037, `-upload-pack=…` on `:fonte :repo`) and
725 // `is_git_ref_name` arm (render.rs:1381, 5a28454, `-stable` on
726 // `:fonte :tag` / `:branch`) already reject.
727 //
728 // The lacre pipeline embeds `:caminho` verbatim in its per-dep
729 // content-address (`conteudo: format!("path:{caminho}")`,
730 // caixa-resolver/src/resolve.rs:189) and the resolver folds the
731 // value through `Path::join` looking for a literal `./{caminho}`
732 // subdirectory. Every downstream subprocess that consumes the
733 // resolved path — a `git -C {caminho} <verb>` invocation, a
734 // future `feira tofu` `terraform -chdir={caminho}` shell-out, a
735 // future operator-side `nix build --path {caminho}` spawn, an
736 // `xargs` / `find {caminho}` / `stat {caminho}` /
737 // `rm -rf {caminho}` cleanup — reinterprets a leading-`-` value
738 // as a CLI flag rather than a positional path when the
739 // subprocess invocation does not carry a `--` argument-list
740 // terminator between the flag block and the path argument. The
741 // canonical footguns:
742 //
743 // - `:caminho "-rf"` — bare short-flag paste (`rm -rf` /
744 // `find -rf` reinterpretation; the byte the peer
745 // `FonteCaminhoShellSemicolon` arm's `; rm -rf build`
746 // example paste-idiom carries as its first token).
747 // - `:caminho "-C"` — `git -C` config-injection paste
748 // (`git -C -C` reinterprets the second `-C` as another
749 // `--change-directory` flag rather than the path
750 // argument; the canonical `git -C <path>` porcelain
751 // idiom every multi-repo workspace tool carries).
752 // - `:caminho "--upload-pack=cat /etc/passwd"` — the
753 // canonical long-flag CLI-arg-injection vector at every
754 // git porcelain entry point (`git clone`, `git fetch`,
755 // `git ls-remote`) that consumes a path or URL
756 // argument; peer with `is_git_repo_url`'s leading-`-`
757 // arm (render.rs:2037) on the sibling `:fonte :repo`
758 // axis, which the arm's diagnostic explicitly cites.
759 // - `:caminho "--config=…"` / `:caminho "-c"` — git-config
760 // override paste-idiom (paste-from-`git -c foo=bar`
761 // shell-history footgun that reinterprets the value as
762 // a `[foo] bar` config injection on every git porcelain
763 // entry point).
764 //
765 // POSIX `std::path::Path` treats a leading `-` as a literal
766 // filename byte, so the resolver folds `-rf` through `Path::join`
767 // and looks for a literal `./-rf` subdirectory — the failure
768 // surfaces at resolve time with a non-self-locating `No such
769 // file or directory` error far from the source caixa.lisp, and
770 // the value rides through the lacre content-address into every
771 // downstream shell-spawned subprocess. On any consumer that
772 // shells out without the `--` terminator (the common case at
773 // every porcelain entry-point) the reinterpretation is silent
774 // and the failure mode is arbitrary-argument-injection.
775 //
776 // The arm fires AFTER the absolute / tilde / var / leading-space
777 // leading-byte arms (each names the more self-locating shell-
778 // convention diagnostic on values that probe as that arm's
779 // leading-byte sentinel — the byte sets are pairwise disjoint at
780 // the leading position, so the precedence pin is a no-op at
781 // value level, but the ordering keeps every leading-byte arm's
782 // diagnostic-shape stable) and BEFORE the embedded-control-byte
783 // arm (a leading-`-` value with an embedded control byte
784 // surfaces the narrower leading-`-` diagnostic because the
785 // cascade walks leading-byte arms first — peer with how
786 // `FonteCaminhoAbsolute` precedes `FonteCaminhoControlChar` on
787 // `"/etc/passwd\n"`, and how `FonteCaminhoLeadingWhitespace`
788 // precedes `FonteCaminhoControlChar` on `" ../foo\n"`).
789 //
790 // The peer single-token-shaped axes already reject leading `-`
791 // on the same CLI-arg-injection contract:
792 // [`crate::render::is_git_repo_url`] rejects it on `:fonte :repo`
793 // (render.rs:2037), [`crate::render::is_git_ref_name`] rejects
794 // it on `:fonte :tag` / `:fonte :branch` (render.rs:1381,
795 // 5a28454), [`crate::render::is_dns_1123_label`] rejects it on
796 // every DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros
797 // :caixa`, `:children :caixa`, `:deps :nome`, cluster names),
798 // [`crate::render::is_cargo_feature_name`] rejects it on
799 // `:caracteristicas`, and the feira `init` / `add <nome>`
800 // positional gate (868c191) rejects it on the CLI positional
801 // itself. Closing the same byte on `:fonte :caminho` makes the
802 // substrate-wide "no leading `-` anywhere in a typed single-
803 // token string slot routed through a subprocess argument"
804 // invariant structurally consistent across every value-shape-
805 // gated typed surface (the `:caminho` axis was the last typed
806 // string surface still admitting a leading `-` byte).
807 if caminho.starts_with('-') {
808 return Err(DepError::FonteCaminhoLeadingHyphen {
809 nome: nome.to_string(),
810 caminho: caminho.to_string(),
811 });
812 }
813 // Reproducibility gate's embedded-control-byte arm. The
814 // b94fd83 + a5c248e + f4efe9c arms closed the three
815 // leading-byte host-layout-leak shapes (`/` / `~` / `$`);
816 // this arm closes the orthogonal embedded-control-byte
817 // axis — any ASCII control byte (`0x00..=0x1F` plus
818 // `0x7F` DEL) appearing anywhere in `:caminho`. Same
819 // shape every peer single-token-typed-slot value-shape
820 // predicate the surrounding [`crate::render`] cluster
821 // gates against (the lifted `is_git_repo_url` arm on
822 // `:fonte :repo`, the `is_git_ref_name` arm on
823 // `:tag`/`:branch`, the `is_chart_description_shape` /
824 // `is_chart_maintainer_name_shape` /
825 // `is_chart_keyword_shape` arms on the
826 // Helm-chart-shaped axes); now consistent on the
827 // `:caminho` axis too.
828 //
829 // Until this gate landed any embedded control byte
830 // silently passed validate, the lacre pipeline embedded
831 // the value verbatim in its per-dep content-address
832 // (`conteudo: format!("path:{caminho}")`,
833 // caixa-resolver/src/resolve.rs:189), and the failure
834 // forked per byte and per consumer:
835 //
836 // - NUL (`0x00`) the canonical "POSIX paths cannot
837 // contain a NUL byte" shape: every `std::fs` syscall
838 // routes the path through `CString::new`, which
839 // fails with `NulError` on the first NUL byte; the
840 // build would surface a `NulError` at resolve time
841 // far from the source caixa.lisp.
842 // - LF (`0x0A`) / CR (`0x0D`) the canonical paste-from-
843 // multiline-doc footgun: a `:caminho
844 // "../caixa-teia\nrm -rf /"` value (paste landed mid-
845 // `:caminho` block from a multi-line code-fence)
846 // silently round-trips through `Path::join` but the
847 // embedded newline class is a sibling of the CRLF-at-
848 // subprocess-argument injection vector
849 // `is_git_repo_url` already closes on `:repo`.
850 // - Tab (`0x09`) the canonical paste-from-aligned-table
851 // footgun: the tab is invisible in most editors, and
852 // the lacre embeds the value verbatim so two
853 // paste-from-distinct-tables yield divergent lacres
854 // across host editors that strip vs preserve tabs.
855 // - DEL (`0x7F`) + every other `0x00..=0x1F` byte: the
856 // paste-from-binary-blob shape every peer single-
857 // token-shaped slot rejects under the same
858 // `b < 0x20 || b == 0x7F` predicate.
859 //
860 // Mirrors the cascade discipline every prior `:caminho`
861 // arm establishes: `FonteCaminhoEmpty` →
862 // `FonteCaminhoAbsolute` → `FonteCaminhoTildeExpansion`
863 // → `FonteCaminhoVarExpansion` →
864 // `FonteCaminhoLeadingWhitespace` →
865 // `FonteCaminhoLeadingHyphen` → `FonteCaminhoControlChar`.
866 // The six leading-byte arms structurally precede the
867 // embedded-byte arm because the leading-byte shapes are
868 // the more self-locating diagnostic on values that probe
869 // as both (e.g. `:caminho "/etc/passwd\n"` surfaces the
870 // narrower `FonteCaminhoAbsolute` rather than the broader
871 // embedded-control-byte arm); the precedence pin matters
872 // at the diagnostic-shape level even though the empty /
873 // absolute / tilde / var arms are value-disjoint from a
874 // bare control byte (which would itself be a leading
875 // byte under the empty / absolute / tilde / var arms'
876 // leading-position semantics, but those arms guard the
877 // specific shell-convention characters `/` / `~` / `$`
878 // — a leading `0x01` byte falls through to this arm).
879 for &b in caminho.as_bytes() {
880 if b < 0x20 || b == 0x7F {
881 return Err(DepError::FonteCaminhoControlChar {
882 nome: nome.to_string(),
883 caminho: caminho.to_string(),
884 byte: b,
885 });
886 }
887 }
888 // Reproducibility gate's Windows-path-separator arm. The four
889 // leading-byte arms (`/` / `~` / `$`) and the embedded-
890 // control-byte arm close the host-layout-leaking + paste-from-
891 // multiline-doc shapes; the leading-`\` / embedded-`\` byte is
892 // the orthogonal cross-host-OS-separator shape — same render-
893 // determinism axis, different semantic mechanism. POSIX
894 // [`std::path::Path`] treats `\` (0x5C) as a literal byte
895 // inside a single path component (so `..\caixa-teia` is one
896 // directory named literally `..\caixa-teia`, sibling of `.`
897 // and `..`); Windows [`std::path::Path`] treats `\` as a
898 // primary path separator equal to `/` (so `..\caixa-teia` is
899 // the parent's sibling directory `caixa-teia`). The lacre
900 // pipeline embeds the value verbatim in its per-dep content-
901 // address (`conteudo: format!("path:{caminho}")`, caixa-
902 // resolver/src/resolve.rs:189), so byte-identical caixa.lisp
903 // values resolve to two distinct directories across runner
904 // OSes — the same THEORY.md §V.2 render-determinism contract
905 // the absolute / tilde / var arms protect, here against the
906 // cross-host-OS-separator divergence vector. Even on POSIX-
907 // only resolvers (the canonical pleme-io substrate posture),
908 // a `..\caixa-teia` (the Windows-Explorer "copy as path" /
909 // PowerShell `Get-Location` paste-idiom footgun) silently
910 // passes every prior arm because `Path::is_absolute` returns
911 // false on `..` and `\` is neither a leading-byte sentinel
912 // nor a control byte, then the resolver folds the value
913 // through `Path::new(caminho).join(<file>)` looking for a
914 // literal `./..\caixa-teia` subdirectory and fails at
915 // resolve time with a non-self-locating `No such file or
916 // directory` error far from the source caixa.lisp.
917 //
918 // The peer single-token-shaped axes on the same git-CLI /
919 // path-CLI consumer cluster already reject `\` under the same
920 // Windows-path-leak banner: [`crate::render::is_git_ref_name`]
921 // line 1441 (`"must not contain \\ … the canonical Windows-
922 // path-leak footgun; use / for hierarchical refs"`) gates
923 // `:fonte :tag` / `:fonte :branch` against the same byte,
924 // and [`crate::render::is_gateway_api_http_path`] line 506
925 // includes `\` in the eleven-byte RFC-3986-reserved rejection
926 // set on `:entrada :paths`. Closing the same byte on `:fonte
927 // :caminho` makes the substrate-wide "no Windows path
928 // separator anywhere in a typed string slot" invariant
929 // structurally consistent across every path-shaped typed
930 // surface (the `:caminho` axis was the last typed string
931 // surface still admitting `\`).
932 //
933 // The arm fires AFTER the control-char arm because the
934 // control-char diagnostic is the more self-locating axis on
935 // values that probe as both (`"..\caixa\0teia"` carries both
936 // a `\` and a NUL — NUL is the load-bearing POSIX-syscall-
937 // rejected byte, so `FonteCaminhoControlChar` wins). Same
938 // narrower-diagnostic-first cascade discipline every prior
939 // arm establishes. A pure-`\` value
940 // (`"..\caixa-teia"` with no control bytes) falls through
941 // every prior arm and lands here.
942 for &b in caminho.as_bytes() {
943 if b == b'\\' {
944 return Err(DepError::FonteCaminhoBackslash {
945 nome: nome.to_string(),
946 caminho: caminho.to_string(),
947 });
948 }
949 }
950 // Reproducibility gate's shell-redirection arm. The 3a4e1d7 backslash
951 // arm closes the cross-host-OS-separator vector; `<` (`0x3C`) and `>`
952 // (`0x3E`) are the orthogonal shell-redirection sentinels — same
953 // paste-from-shell-prompt footgun class, different syntactic surface.
954 // POSIX `std::path::Path` treats `<` / `>` as literal bytes inside a
955 // single path component (so `../caixa-teia>output` is one directory
956 // named literally `../caixa-teia>output`, sibling of `.` and `..`),
957 // but every interactive shell (bash / zsh / fish / nushell) lexes
958 // `<` / `>` as input / output redirection operators — a `:caminho
959 // "../caixa-teia>build.log"` (the canonical "I pasted a shell
960 // pipeline that wrote build output and forgot to trim the redirect"
961 // footgun) or `:caminho "../<input.lisp"` (the symmetric input-
962 // redirection paste idiom) silently passes every prior arm because
963 // `Path::is_absolute` returns false, `<` / `>` are neither leading-
964 // byte sentinels nor control bytes nor `\`, and the value's last byte
965 // isn't `/`. The resolver folds the value through
966 // `Path::new(caminho).join(<file>)` looking for a literal
967 // `./..\caixa-teia>build.log` subdirectory and fails at resolve time
968 // with a non-self-locating `No such file or directory` error far
969 // from the source caixa.lisp.
970 //
971 // The lacre pipeline embeds the value verbatim in its per-dep
972 // content-address (`conteudo: format!("path:{caminho}")`,
973 // caixa-resolver/src/resolve.rs:189), so a `<` / `>` byte lands in
974 // the BLAKE3 closure and rides downstream as part of the build's
975 // identity. The bytes carry a second class of hazard the prior
976 // separator-shaped arms don't: every typed-string slot whose value
977 // ever flows verbatim into a shell-spawned subprocess (the caixa-
978 // resolver's `git clone` invocation, a future `feira tofu` shell-
979 // out, a future operator-side `nix flake check` spawn) is the
980 // canonical CRLF-at-subprocess-argument / shell-metachar injection
981 // surface that every peer single-token-shaped typed slot already
982 // closes. The peer path-shaped axis `[crate::render::is_gateway_api_http_path]`
983 // (caixa-core/src/render.rs:506) rejects `<` / `>` as part of its
984 // eleven-byte RFC-3986-reserved set on `:entrada :paths`, and the
985 // peer git-ref-shaped axis `[crate::render::is_git_ref_name]` rejects
986 // `<` / `>` on `:fonte :tag` / `:fonte :branch` under the same
987 // shell-metachar-injection banner. The `:caminho` axis was the last
988 // typed string surface still admitting these two bytes; this arm
989 // closes the gap so the substrate-wide "no shell-redirection
990 // metacharacter anywhere in a typed string slot" invariant is now
991 // structurally consistent across every path-shaped typed surface.
992 //
993 // The arm fires AFTER the control-char arm + backslash arm because
994 // both prior arms carry more self-locating diagnostics on values
995 // that probe as both (`"..\foo<bar"` carries both `\` and `<` — the
996 // cross-OS-separator divergence is the load-bearing axis, so the
997 // backslash arm wins; `"../foo\n<bar"` carries both LF and `<` —
998 // the POSIX-syscall-rejected byte is the load-bearing axis, so the
999 // control-char arm wins). The arm fires BEFORE the trailing-`/` arm
1000 // because the embedded redirection byte is the more semantic-
1001 // locating axis on probe-as-both values (`"../foo</"` ends in `/`
1002 // but the load-bearing diagnostic is the embedded `<` shell-
1003 // redirection — the trailing `/` is the secondary observation, and
1004 // an author who removes the `<` is likely to also tab-strip the
1005 // trailing separator).
1006 for &b in caminho.as_bytes() {
1007 if b == b'<' || b == b'>' {
1008 return Err(DepError::FonteCaminhoShellRedirection {
1009 nome: nome.to_string(),
1010 caminho: caminho.to_string(),
1011 byte: b,
1012 });
1013 }
1014 }
1015 // Reproducibility gate's shell-pipe arm. The e457141 shell-redirection
1016 // arm closes the `<` / `>` input/output redirection sentinels; `|`
1017 // (`0x7C`) is the orthogonal shell-pipe sentinel — same paste-from-
1018 // shell-prompt footgun class, different syntactic surface. POSIX
1019 // `std::path::Path` treats `|` as a literal path-component byte (so
1020 // `../caixa-teia|tee` is one directory named literally
1021 // `../caixa-teia|tee`, sibling of `.` and `..`), but every interactive
1022 // shell (bash / zsh / fish / nushell) lexes `|` as the pipe operator
1023 // — a `:caminho "../caixa-teia | grep foo"` (the canonical "I copied a
1024 // `ls ../caixa-teia | grep` line out of a shell-history block and
1025 // forgot to trim the pipeline tail" footgun) or `:caminho
1026 // "../foo||bar"` (the symmetric "I copied a `cmd-a || cmd-b` short-
1027 // circuit OR line" idiom) silently passes every prior arm because
1028 // `Path::is_absolute` returns false on `..`, `|` is neither a leading-
1029 // byte sentinel nor a control byte nor `\` nor `<` / `>`, and the
1030 // value's last byte isn't `/`. The resolver folds the value through
1031 // `Path::new(caminho).join(<file>)` looking for a literal
1032 // `./../caixa-teia | grep foo` subdirectory and fails at resolve time
1033 // with a non-self-locating `No such file or directory` error far
1034 // from the source caixa.lisp.
1035 //
1036 // The lacre pipeline embeds the value verbatim in its per-dep
1037 // content-address (`conteudo: format!("path:{caminho}")`,
1038 // caixa-resolver/src/resolve.rs:189), so a `|` byte lands in the
1039 // BLAKE3 closure and rides downstream as part of the build's identity
1040 // into every shell-spawned subprocess (the caixa-resolver's `git
1041 // clone` invocation, a future `feira tofu` shell-out, a future
1042 // operator-side `nix flake check` spawn) as the canonical CRLF-at-
1043 // subprocess-argument / shell-metachar injection surface every peer
1044 // single-token-shaped typed slot already closes. The peer path-shaped
1045 // axis [`crate::render::is_gateway_api_http_path`]
1046 // (caixa-core/src/render.rs:506) rejects `|` as part of its eleven-
1047 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1048 // axis was the last typed path-string surface still admitting this
1049 // byte; this arm closes the gap so the substrate-wide "no shell-
1050 // composition metacharacter anywhere in a typed string slot that
1051 // flows verbatim into a shell-spawned subprocess" invariant extends
1052 // from shell-redirection (`<` / `>`) to shell-pipe (`|`) on the
1053 // `:caminho` axis.
1054 //
1055 // The arm fires AFTER the shell-redirection arm because the prior
1056 // arm's two-byte `byte: u8` payload is the more self-locating axis on
1057 // values that probe as both (`"../caixa-teia<input|tee"` carries both
1058 // `<` and `|` — the input-redirection-paste idiom is the load-bearing
1059 // root-cause edit, so `FonteCaminhoShellRedirection` wins; same
1060 // cascade discipline every prior `:caminho` arm establishes). The arm
1061 // fires BEFORE the trailing-`/` arm because the embedded pipe byte is
1062 // the more semantic-locating axis on probe-as-both values
1063 // (`"../foo|tee/"` ends in `/` but the load-bearing diagnostic is the
1064 // embedded `|` shell-pipe — the trailing `/` is the secondary
1065 // observation, and an author who removes the `|` is likely to also
1066 // tab-strip the trailing separator).
1067 for &b in caminho.as_bytes() {
1068 if b == b'|' {
1069 return Err(DepError::FonteCaminhoShellPipe {
1070 nome: nome.to_string(),
1071 caminho: caminho.to_string(),
1072 });
1073 }
1074 }
1075 // Reproducibility gate's shell-command-separator arm. The 124106f
1076 // shell-pipe arm closes the `|` byte; `;` (`0x3B`) is the orthogonal
1077 // shell-command-separator sentinel — same paste-from-shell-prompt
1078 // footgun class, different syntactic surface. POSIX `std::path::Path`
1079 // treats `;` as a literal path-component byte (so
1080 // `../caixa-teia;rm -rf /` is one directory named literally
1081 // `../caixa-teia;rm -rf /`, sibling of `.` and `..`), but every
1082 // interactive shell (bash / zsh / fish / nushell) lexes `;` as the
1083 // sequential-command terminator that fires the next command
1084 // regardless of the prior command's exit status — a `:caminho
1085 // "../caixa-teia; rm -rf build"` (the canonical "I pasted a shell
1086 // one-liner that chained a cleanup tail after the directory name"
1087 // footgun) or `:caminho "../foo;;bar"` (the symmetric "I copied a
1088 // POSIX `case` arm's `;;` terminator into the middle of a path"
1089 // idiom) silently passes every prior arm because `Path::is_absolute`
1090 // returns false on `..`, `;` is neither a leading-byte sentinel nor a
1091 // control byte nor `\` nor `<` / `>` nor `|`, and the value's last
1092 // byte isn't `/`. The resolver folds the value through
1093 // `Path::new(caminho).join(<file>)` looking for a literal
1094 // `./../caixa-teia; rm -rf build` subdirectory and fails at resolve
1095 // time with a non-self-locating `No such file or directory` error far
1096 // from the source caixa.lisp.
1097 //
1098 // The lacre pipeline embeds the value verbatim in its per-dep
1099 // content-address (`conteudo: format!("path:{caminho}")`,
1100 // caixa-resolver/src/resolve.rs:189), so a `;` byte lands in the
1101 // BLAKE3 closure and rides downstream as part of the build's identity
1102 // into every shell-spawned subprocess (the caixa-resolver's `git
1103 // clone` invocation, a future `feira tofu` shell-out, a future
1104 // operator-side `nix flake check` spawn) as the canonical
1105 // shell-metachar injection surface every peer single-token-shaped
1106 // typed slot already closes. The peer path-shaped axis
1107 // [`crate::render::is_gateway_api_http_path`]
1108 // (caixa-core/src/render.rs:506) rejects `;` as part of its eleven-
1109 // byte RFC-3986-reserved set on `:entrada :paths`. The `:caminho`
1110 // axis was the last typed path-string surface still admitting this
1111 // byte; this arm closes the gap so the substrate-wide "no shell-
1112 // composition metacharacter anywhere in a typed string slot that
1113 // flows verbatim into a shell-spawned subprocess" invariant extends
1114 // from shell-pipe (`|`) to shell-command-separator (`;`) on the
1115 // `:caminho` axis.
1116 //
1117 // The arm fires AFTER the shell-pipe arm because the prior arm's
1118 // canonical-cmd-a-|-cmd-b shape is the more common shell-history
1119 // paste idiom on values that probe as both (`"../caixa-teia | tee;
1120 // rm"` carries both `|` and `;` — the pipeline-tail paste is the
1121 // load-bearing root-cause edit, so `FonteCaminhoShellPipe` wins; same
1122 // cascade discipline every prior `:caminho` arm establishes). The arm
1123 // fires BEFORE the trailing-`/` arm because the embedded
1124 // command-separator byte is the more semantic-locating axis on
1125 // probe-as-both values (`"../foo;rm/"` ends in `/` but the
1126 // load-bearing diagnostic is the embedded `;` shell-command-
1127 // separator — the trailing `/` is the secondary observation, and an
1128 // author who removes the `;` is likely to also tab-strip the trailing
1129 // separator).
1130 for &b in caminho.as_bytes() {
1131 if b == b';' {
1132 return Err(DepError::FonteCaminhoShellSemicolon {
1133 nome: nome.to_string(),
1134 caminho: caminho.to_string(),
1135 });
1136 }
1137 }
1138 // Reproducibility gate's shell-background / logical-AND arm. The
1139 // 05c358e shell-command-separator arm closes the `;` byte; `&`
1140 // (`0x26`) is the orthogonal shell-background / list-AND sentinel
1141 // — same paste-from-shell-prompt footgun class, different
1142 // syntactic surface. POSIX `std::path::Path` treats `&` as a
1143 // literal path-component byte (so `../caixa-teia & sleep 1` is
1144 // one directory named literally `../caixa-teia & sleep 1`,
1145 // sibling of `.` and `..`), but every interactive shell
1146 // (bash / zsh / fish / nushell) lexes `&` two ways:
1147 //
1148 // - Single `&` as the background-task terminator that detaches
1149 // the prior command into the background and returns control
1150 // to the prompt immediately (the canonical `cmd &` idiom
1151 // every long-running pipeline uses);
1152 // - Double `&&` as the logical-AND list operator that fires
1153 // the next command only if the prior command succeeded (the
1154 // canonical `make && make install` idiom every build script
1155 // carries).
1156 //
1157 // A `:caminho "../caixa-teia & sleep 1"` (the canonical "I
1158 // pasted a `cd path & sleep 1` background-launch into the
1159 // `:caminho` slot" footgun) or `:caminho "../caixa-teia && make"`
1160 // (the symmetric "I copied a `cd path && make` build chain"
1161 // idiom) silently passes every prior arm because
1162 // `Path::is_absolute` returns false on `..`, `&` is neither a
1163 // leading-byte sentinel nor a control byte nor `\` nor
1164 // `<` / `>` nor `|` nor `;`, and the value's last byte isn't `/`.
1165 // The resolver folds the value through
1166 // `Path::new(caminho).join(<file>)` looking for a literal
1167 // `./../caixa-teia & sleep 1` subdirectory and fails at resolve
1168 // time with a non-self-locating `No such file or directory`
1169 // error far from the source caixa.lisp.
1170 //
1171 // The lacre pipeline embeds the value verbatim in its per-dep
1172 // content-address (`conteudo: format!("path:{caminho}")`,
1173 // caixa-resolver/src/resolve.rs:189), so an `&` byte lands in
1174 // the BLAKE3 closure and rides downstream as part of the build's
1175 // identity into every shell-spawned subprocess (the
1176 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1177 // shell-out, a future operator-side `nix flake check` spawn) as
1178 // the canonical shell-metachar injection surface every peer
1179 // single-token-shaped typed slot already closes. The peer
1180 // path-shaped axis [`crate::render::is_gateway_api_http_path`]
1181 // (caixa-core/src/render.rs:506) rejects `&` as part of its
1182 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1183 // `:caminho` axis was the last typed path-string surface still
1184 // admitting this byte; this arm closes the gap so the
1185 // substrate-wide "no shell-composition metacharacter anywhere
1186 // in a typed string slot that flows verbatim into a
1187 // shell-spawned subprocess" invariant extends from
1188 // shell-command-separator (`;`) to shell-background /
1189 // logical-AND (`&`) on the `:caminho` axis.
1190 //
1191 // The arm fires AFTER the shell-command-separator arm because
1192 // the prior arm's `cmd-a; cmd-b` shape is the more common
1193 // shell-history paste idiom on values that probe as both
1194 // (`"../caixa-teia; rm & sleep"` carries both `;` and `&` — the
1195 // command-separator-tail paste is the load-bearing root-cause
1196 // edit, so `FonteCaminhoShellSemicolon` wins; same cascade
1197 // discipline every prior `:caminho` arm establishes). The arm
1198 // fires BEFORE the trailing-`/` arm because the embedded
1199 // background / list-AND byte is the more semantic-locating axis
1200 // on probe-as-both values (`"../foo&bar/"` ends in `/` but the
1201 // load-bearing diagnostic is the embedded `&` shell-background
1202 // / logical-AND metachar — the trailing `/` is the secondary
1203 // observation, and an author who removes the `&` is likely to
1204 // also tab-strip the trailing separator).
1205 for &b in caminho.as_bytes() {
1206 if b == b'&' {
1207 return Err(DepError::FonteCaminhoShellBackground {
1208 nome: nome.to_string(),
1209 caminho: caminho.to_string(),
1210 });
1211 }
1212 }
1213 // Reproducibility gate's shell-command-substitution arm. The
1214 // e12e4f3 shell-background / logical-AND arm closes the `&`
1215 // byte; the backtick (`0x60`) is the orthogonal POSIX legacy
1216 // command-substitution sentinel — every POSIX shell (sh /
1217 // bash / zsh / dash / ksh / fish / nushell) lexes the byte as
1218 // the canonical legacy wrapper that runs the enclosed command
1219 // and substitutes its standard-output verbatim into the
1220 // surrounding word (a `whoami` wrapped in backticks expands
1221 // to the current user's name; a `cat /etc/passwd` wrapped in
1222 // backticks expands to the file's contents — the canonical
1223 // CWE-78 shell-command-injection vector every shell-side
1224 // hardening guide enumerates first). POSIX
1225 // `std::path::Path` treats backtick as a literal path-
1226 // component byte (so `../caixa-teia/<backtick>whoami<backtick>`
1227 // is one directory named literally that, sibling of `.` and
1228 // `..`).
1229 //
1230 // A `:caminho "../caixa-teia/<backtick>whoami<backtick>"` (the
1231 // canonical "I pasted a shell one-liner carrying a backticked
1232 // `whoami` command-substitution expansion into the `:caminho`
1233 // slot" footgun) or `:caminho "<backtick>pwd<backtick>/caixa-
1234 // teia"` (the symmetric "I copied a `<backtick>pwd<backtick>/
1235 // path` working-directory expansion") silently passes every
1236 // prior arm because `Path::is_absolute` returns false on
1237 // `..`, the backtick byte is neither a leading-byte sentinel
1238 // (the f4efe9c `FonteCaminhoVarExpansion` arm catches the
1239 // modern `$()` form at leading position only; backtick is
1240 // the orthogonal legacy form) nor a control byte nor `\` nor
1241 // `<` / `>` nor `|` nor `;` nor `&`, and the value's last
1242 // byte isn't `/`. The resolver folds the value through
1243 // `Path::new(caminho).join(<file>)` looking for a literal
1244 // subdirectory whose name embeds the backticked token and
1245 // fails at resolve time with a non-self-locating `No such
1246 // file or directory` error far from the source caixa.lisp.
1247 //
1248 // The lacre pipeline embeds the value verbatim in its per-
1249 // dep content-address (`conteudo: format!("path:{caminho}")`,
1250 // caixa-resolver/src/resolve.rs:189), so a backtick byte
1251 // lands in the BLAKE3 closure and rides downstream as part
1252 // of the build's identity into every shell-spawned
1253 // subprocess (the caixa-resolver's `git clone` invocation, a
1254 // future `feira tofu` shell-out, a future operator-side
1255 // `nix flake check` spawn) as the canonical shell-metachar
1256 // injection surface every peer single-token-shaped typed
1257 // slot already closes. The peer path-shaped axis
1258 // [`crate::render::is_gateway_api_http_path`]
1259 // (caixa-core/src/render.rs:506) rejects backtick as part of
1260 // its eleven-byte RFC-3986-reserved set on `:entrada
1261 // :paths`. The `:caminho` axis was the last typed path-
1262 // string surface still admitting this byte; this arm closes
1263 // the gap so the substrate-wide "no shell-composition
1264 // metacharacter anywhere in a typed string slot that flows
1265 // verbatim into a shell-spawned subprocess" invariant
1266 // extends from shell-background / logical-AND (`&`) to
1267 // shell-command-substitution (backtick) on the `:caminho`
1268 // axis.
1269 //
1270 // The arm fires AFTER the shell-background arm because the
1271 // prior arm's `cmd & sleep` shape is the more common shell-
1272 // history paste idiom on values that probe as both (a
1273 // `"../caixa-teia & <backtick>whoami<backtick>"` carries
1274 // both `&` and a backtick — the background-launch tail is
1275 // the load-bearing root-cause edit, so
1276 // `FonteCaminhoShellBackground` wins; same cascade
1277 // discipline every prior `:caminho` arm establishes). The
1278 // arm fires BEFORE the trailing-`/` arm because the
1279 // embedded command-substitution byte is the more semantic-
1280 // locating axis on probe-as-both values (a
1281 // `"../<backtick>whoami<backtick>/"` ends in `/` but the
1282 // load-bearing diagnostic is the embedded backtick shell-
1283 // command-substitution metachar — the trailing `/` is the
1284 // secondary observation, and an author who removes the
1285 // backtick is likely to also tab-strip the trailing
1286 // separator).
1287 for &b in caminho.as_bytes() {
1288 if b == b'`' {
1289 return Err(DepError::FonteCaminhoShellCommandSubstitution {
1290 nome: nome.to_string(),
1291 caminho: caminho.to_string(),
1292 });
1293 }
1294 }
1295 // Reproducibility gate's shell-glob arm. The c4d62b3 shell-command-
1296 // substitution arm closes the backtick byte; `*` (`0x2A`) and `?`
1297 // (`0x3F`) are the orthogonal POSIX glob-expansion sentinels — same
1298 // paste-from-shell-prompt footgun class, different syntactic surface.
1299 // Every POSIX shell (sh / bash / zsh / dash / ksh / fish / nushell)
1300 // lexes `*` and `?` as pathname-expansion wildcards: `*` matches any
1301 // sequence of characters in a path component (including the empty
1302 // sequence), `?` matches exactly one character. POSIX
1303 // `std::path::Path` treats both bytes as literal path-component bytes
1304 // (so `../caixa-teia/*.lisp` is one directory named literally
1305 // `../caixa-teia/*.lisp`, sibling of `.` and `..`).
1306 //
1307 // A `:caminho "../caixa-teia/*"` (the canonical "I pasted a
1308 // `ls ../caixa-teia/*` shell-listing one-liner into the `:caminho`
1309 // slot" footgun) or `:caminho "../foo?"` (the symmetric "I copied a
1310 // `rm foo?` single-char-wildcard removal idiom") silently passes
1311 // every prior arm because `Path::is_absolute` returns false on `..`,
1312 // `*` / `?` are neither leading-byte sentinels nor control bytes nor
1313 // `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick, and the
1314 // value's last byte isn't `/`. The resolver folds the value through
1315 // `Path::new(caminho).join(<file>)` looking for a literal
1316 // `./../caixa-teia/*` subdirectory and fails at resolve time with a
1317 // non-self-locating `No such file or directory` error far from the
1318 // source caixa.lisp.
1319 //
1320 // The lacre pipeline embeds the value verbatim in its per-dep
1321 // content-address (`conteudo: format!("path:{caminho}")`,
1322 // caixa-resolver/src/resolve.rs:189), so a `*` or `?` byte lands in
1323 // the BLAKE3 closure and rides downstream as part of the build's
1324 // identity into every shell-spawned subprocess (the caixa-resolver's
1325 // `git clone` invocation, a future `feira tofu` shell-out, a future
1326 // operator-side `nix flake check` spawn) as the canonical
1327 // shell-metachar / pathname-expansion surface every peer
1328 // single-token-shaped typed slot already closes. The peer path-shaped
1329 // axis [`crate::render::is_gateway_api_http_path`]
1330 // (caixa-core/src/render.rs:506) rejects `*` and `?` as part of its
1331 // eleven-byte RFC-3986-reserved set on `:entrada :paths`. The
1332 // `:caminho` axis was the last typed path-string surface still
1333 // admitting these two bytes; this arm closes the gap so the
1334 // substrate-wide "no shell-composition / glob-expansion
1335 // metacharacter anywhere in a typed string slot that flows verbatim
1336 // into a shell-spawned subprocess" invariant extends from
1337 // shell-command-substitution (backtick) to glob-expansion
1338 // (`*` / `?`) on the `:caminho` axis.
1339 //
1340 // The arm fires AFTER the backtick arm because the prior arm's
1341 // CWE-78 shell-command-injection vector is the load-bearing
1342 // diagnostic on values that probe as both (a `"../`whoami`/*"`
1343 // carries both backtick and `*` — the command-substitution paste
1344 // is the load-bearing root-cause edit, so
1345 // `FonteCaminhoShellCommandSubstitution` wins; same cascade
1346 // discipline every prior `:caminho` arm establishes). The arm
1347 // fires BEFORE the trailing-`/` arm because the embedded glob
1348 // byte is the more semantic-locating axis on probe-as-both values
1349 // (`"../foo*/"` ends in `/` but the load-bearing diagnostic is the
1350 // embedded `*` glob metachar — the trailing `/` is the secondary
1351 // observation, and an author who removes the `*` is likely to
1352 // also tab-strip the trailing separator).
1353 for &b in caminho.as_bytes() {
1354 if b == b'*' || b == b'?' {
1355 return Err(DepError::FonteCaminhoShellGlob {
1356 nome: nome.to_string(),
1357 caminho: caminho.to_string(),
1358 byte: b,
1359 });
1360 }
1361 }
1362 // Reproducibility gate's shell-subshell-grouping arm. The cf9034b
1363 // shell-glob arm closes the `*` / `?` pathname-expansion sentinels;
1364 // `(` (`0x28`) and `)` (`0x29`) are the orthogonal POSIX subshell-
1365 // grouping sentinels — same paste-from-shell-prompt footgun class,
1366 // different syntactic surface. Every POSIX shell (sh / bash / zsh /
1367 // dash / ksh / fish / nushell) lexes the parenthesis pair as the
1368 // subshell-grouping operator: `(<cmd>)` runs `<cmd>` in a child
1369 // shell with a fresh environment scope (the canonical sandboxing
1370 // idiom every shell-history `(cd <path> && <cmd>)` one-liner uses
1371 // to scope a `cd` to one subshell without disturbing the parent's
1372 // working directory), and `$(<cmd>)` is the modern Bourne
1373 // command-substitution shape the upstream f4efe9c
1374 // `FonteCaminhoVarExpansion` arm closes the leading `$` byte of —
1375 // the closing `)` byte completes that substitution shape and must
1376 // be refused on the same axis (peer with the
1377 // [`crate::render::is_git_repo_url`] 3b99147 arm that closes the
1378 // same byte-pair on the sibling `:fonte :repo` axis under the
1379 // same shell-subshell-grouping + RFC-3986-sub-delims banner).
1380 // POSIX `std::path::Path` treats both bytes as literal path-
1381 // component bytes (so `../caixa-teia/(date)` is one directory
1382 // named literally `../caixa-teia/(date)`, sibling of `.` and
1383 // `..`).
1384 //
1385 // A `:caminho "../caixa-teia/$(date)/build"` (the canonical "I
1386 // pasted a `cd ../caixa-teia/$(date)/build` shell-history one-
1387 // liner whose modern command-substitution expansion lands the
1388 // current date as a subdirectory name" footgun) or `:caminho
1389 // "../(cd foo && pwd)/caixa-teia"` (the symmetric "I copied a
1390 // `(cd foo && pwd)` subshell-grouping working-directory probe
1391 // idiom") silently passes every prior arm because
1392 // `Path::is_absolute` returns false on `..`, `(` / `)` are
1393 // neither leading-byte sentinels nor control bytes nor `\` nor
1394 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` / `?`,
1395 // and the value's last byte isn't `/`. The resolver folds the
1396 // value through `Path::new(caminho).join(<file>)` looking for a
1397 // literal `./../caixa-teia/$(date)/build` subdirectory and fails
1398 // at resolve time with a non-self-locating `No such file or
1399 // directory` error far from the source caixa.lisp.
1400 //
1401 // The lacre pipeline embeds the value verbatim in its per-dep
1402 // content-address (`conteudo: format!("path:{caminho}")`,
1403 // caixa-resolver/src/resolve.rs:189), so a `(` or `)` byte lands
1404 // in the BLAKE3 closure and rides downstream as part of the
1405 // build's identity into every shell-spawned subprocess (the
1406 // caixa-resolver's `git clone` invocation, a future `feira tofu`
1407 // shell-out, a future operator-side `nix flake check` spawn) as
1408 // the canonical shell-metachar / subshell-grouping surface every
1409 // peer single-token-shaped typed slot already closes. The peer
1410 // git-source axis [`crate::render::is_git_repo_url`] (3b99147)
1411 // rejects the same byte pair on `:fonte :repo` under the same
1412 // shell-subshell-grouping / RFC-3986-sub-delims banner. The
1413 // `:caminho` axis was the last typed path-string surface still
1414 // admitting these two bytes;
1415 // this arm closes the gap so the substrate-wide "no shell-
1416 // composition metacharacter anywhere in a typed string slot that
1417 // flows verbatim into a shell-spawned subprocess" invariant
1418 // extends from shell-glob (`*` / `?`) to shell-subshell-grouping
1419 // (`(` / `)`) on the `:caminho` axis. Together with the f4efe9c
1420 // leading-`$` arm, the typed `:caminho` accepted set now
1421 // structurally excludes the entire modern Bourne
1422 // command-substitution surface — leading `$` closes the
1423 // leading byte of every `$(<cmd>)` shape, this arm closes the
1424 // trailing `)` boundary.
1425 //
1426 // The arm fires AFTER the shell-glob arm because the prior arm's
1427 // `*` / `?` pathname-expansion shape is the more common shell-
1428 // history paste idiom on values that probe as both
1429 // (`"../caixa-teia/*(date)"` carries both `*` and `(` — the
1430 // glob-paste-tail is the load-bearing root-cause edit, so
1431 // `FonteCaminhoShellGlob` wins; same cascade discipline every
1432 // prior `:caminho` arm establishes). The arm fires BEFORE the
1433 // trailing-`/` arm because the embedded subshell-grouping byte
1434 // is the more semantic-locating axis on probe-as-both values
1435 // (`"../foo(date)/"` ends in `/` but the load-bearing diagnostic
1436 // is the embedded `(` shell-subshell-grouping metachar — the
1437 // trailing `/` is the secondary observation, and an author who
1438 // removes the `(` is likely to also tab-strip the trailing
1439 // separator).
1440 for &b in caminho.as_bytes() {
1441 if b == b'(' || b == b')' {
1442 return Err(DepError::FonteCaminhoShellSubshellGrouping {
1443 nome: nome.to_string(),
1444 caminho: caminho.to_string(),
1445 byte: b,
1446 });
1447 }
1448 }
1449 // Reproducibility gate's shell-brace-expansion arm. The 0633c91
1450 // shell-subshell-grouping arm closes `(` / `)`; `{` (`0x7b`) and
1451 // `}` (`0x7d`) are the orthogonal shell-brace-expansion /
1452 // URI-Template-placeholder byte pair — same paste-from-shell-
1453 // prompt + paste-from-templated-doc footgun class, different
1454 // syntactic surface. Every POSIX-derived shell that implements
1455 // brace expansion (bash / zsh / ksh / fish; the canonical
1456 // `mkdir -p ../{caixa-teia,caixa-helm,caixa-flux}` /
1457 // `cp file{,.bak}` idiom every shell-history block carries)
1458 // expands `{a,b,c}` to the cross-product of its comma-separated
1459 // members and `{1..10}` to the integer range; RFC 6570 reserves
1460 // the matched pair for URI Template placeholders (the canonical
1461 // `https://{host}/{org}/{repo}` substitution shape every
1462 // OpenAPI / Swagger / Postman / GitHub Octokit client /
1463 // Helm chart-URL fragment / Mustache `{{org}}` doubled-brace
1464 // form carries), and Tera / Jinja2 / Handlebars / Go html/template
1465 // every IaC tool (Helm, Kustomize, Terraform's `${var}` cousin
1466 // shape) emit. POSIX `std::path::Path` treats both bytes as
1467 // literal path-component bytes (so `../{caixa-teia,caixa-helm}`
1468 // is one directory named literally `../{caixa-teia,caixa-helm}`,
1469 // sibling of `.` and `..`).
1470 //
1471 // A `:caminho "../{caixa-teia,caixa-helm}/build"` (the canonical
1472 // "I pasted a `cd ../{caixa-teia,caixa-helm}` shell brace-
1473 // expansion one-liner that fans across two siblings" footgun)
1474 // or `:caminho "../{{org}}/caixa-teia"` (the symmetric "I copied
1475 // a `{{org}}` Mustache / Helm template placeholder out of a
1476 // README quick-start and forgot to substitute") silently passes
1477 // every prior arm because `Path::is_absolute` returns false on
1478 // `..`, `{` / `}` are neither leading-byte sentinels nor control
1479 // bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor
1480 // backtick nor `*` / `?` nor `(` / `)`, and the value's last
1481 // byte isn't `/`. The resolver folds the value through
1482 // `Path::new(caminho).join(<file>)` looking for a literal
1483 // `./../{caixa-teia,caixa-helm}/build` subdirectory and fails
1484 // at resolve time with a non-self-locating `No such file or
1485 // directory` error far from the source caixa.lisp.
1486 //
1487 // The lacre pipeline embeds the value verbatim in its per-dep
1488 // content-address (`conteudo: format!("path:{caminho}")`,
1489 // caixa-resolver/src/resolve.rs:189), so a `{` or `}` byte
1490 // lands in the BLAKE3 closure and rides downstream as part of
1491 // the build's identity into every shell-spawned subprocess
1492 // (the caixa-resolver's `git clone` invocation, a future
1493 // `feira tofu` shell-out, a future operator-side `nix flake
1494 // check` spawn) as the canonical shell-metachar / brace-
1495 // expansion surface every peer single-token-shaped typed
1496 // slot already closes. The peer git-source axis
1497 // [`crate::render::is_git_repo_url`] (42d8f9d — the URI Template
1498 // placeholder arm) rejects the same byte pair on `:fonte :repo`
1499 // under the same RFC-3986-'delims' / RFC-6570-URI-Template /
1500 // shell-brace-expansion banner. The `:caminho` axis was the last
1501 // typed path-string surface still admitting these two bytes;
1502 // this arm closes the gap so the substrate-wide "no shell-
1503 // composition metacharacter anywhere in a typed string slot
1504 // that flows verbatim into a shell-spawned subprocess"
1505 // invariant extends from shell-subshell-grouping (`(` / `)`)
1506 // to shell-brace-expansion (`{` / `}`) on the `:caminho` axis,
1507 // and the typed `:caminho` accepted set now also structurally
1508 // excludes the URI Template / templating-engine placeholder
1509 // surface that would silently round-trip through any
1510 // downstream IaC templating-engine layer.
1511 //
1512 // The arm fires AFTER the shell-subshell-grouping arm because
1513 // the prior arm's `(` / `)` shape is the more semantic-locating
1514 // axis on values that probe as both (`"../{cd foo}(date)"`
1515 // carries both `{` and `(` — the parenthesis-pair is the
1516 // load-bearing modern-Bourne-command-substitution surface the
1517 // prior arm closes; same cascade discipline every prior
1518 // `:caminho` arm establishes). The arm fires BEFORE the
1519 // trailing-`/` arm because the embedded brace-expansion byte
1520 // is the more semantic-locating axis on probe-as-both values
1521 // (`"../{caixa-teia,caixa-helm}/"` ends in `/` but the
1522 // load-bearing diagnostic is the embedded `{` brace-expansion
1523 // metachar — the trailing `/` is the secondary observation,
1524 // and an author who removes the `{` is likely to also tab-
1525 // strip the trailing separator).
1526 for &b in caminho.as_bytes() {
1527 if b == b'{' || b == b'}' {
1528 return Err(DepError::FonteCaminhoShellBraceExpansion {
1529 nome: nome.to_string(),
1530 caminho: caminho.to_string(),
1531 byte: b,
1532 });
1533 }
1534 }
1535 // Reproducibility gate's shell-bracket-expansion arm. The 598b770
1536 // shell-brace-expansion arm closes `{` / `}`; `[` (`0x5b`) and
1537 // `]` (`0x5d`) are the orthogonal POSIX glob-character-class /
1538 // shell-`test`-builtin byte pair — same paste-from-shell-prompt
1539 // footgun class, different syntactic surface. Every POSIX shell
1540 // (sh / bash / zsh / dash / ksh / fish / nushell) lexes the
1541 // bracket pair as the glob character-class operator: `[abc]`
1542 // matches one of `a`, `b`, `c`; `[a-z]` matches any lowercase
1543 // ASCII letter; `[^x]` negates (the canonical
1544 // `ls *.[ch]` C-source-file glob and the `cd ../[a-z]*`
1545 // lowercase-sibling glob every shell-history block carries —
1546 // the orthogonal axis to the cf9034b `*` / `?` shell-glob arm
1547 // closing the unbounded pathname-expansion sentinels). The
1548 // bracket pair additionally carries the POSIX `test` /
1549 // `[` builtin command (`[ -d ../caixa-teia ] && cd ...` —
1550 // the canonical idiom every shell-script conditional uses) and
1551 // bash's `[[ ... ]]` extended-test grammar. Beyond shell, the
1552 // bracket pair is the TOML inline-array delimiter
1553 // (`features = ["a", "b"]` — the canonical paste-from-Cargo-
1554 // manifest cross-idiom-leak vector), the YAML flow-sequence
1555 // delimiter (`paths: [/a, /b]` — the canonical paste-from-
1556 // values.yaml cross-idiom leak), the JSON array delimiter,
1557 // and the POSIX-ERE / PCRE bracket-expression / character-
1558 // class anchor (the canonical paste-from-regex-doc shape).
1559 // POSIX `std::path::Path` treats both bytes as literal path-
1560 // component bytes (so `../[caixa-teia]` is one directory
1561 // named literally `../[caixa-teia]`, sibling of `.` and
1562 // `..`).
1563 //
1564 // A `:caminho "../caixa-[a-z]/build"` (the canonical "I
1565 // pasted a `cd ../caixa-[a-z]/build` glob-character-class
1566 // one-liner that matches every lowercase-sibling-suffix
1567 // sibling directory" footgun), `:caminho "../[caixa-teia]/
1568 // build"` (the symmetric "I pasted a TOML inline-array /
1569 // YAML flow-sequence shape out of an aligned manifest"
1570 // idiom), or `:caminho "../caixa-[ch]"` (the canonical
1571 // `*.[ch]` C-source character-class paste-from-shell-history
1572 // shape) silently passes every prior arm because
1573 // `Path::is_absolute` returns false on `..`, `[` / `]` are
1574 // neither leading-byte sentinels nor control bytes nor `\`
1575 // nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1576 // `*` / `?` nor `(` / `)` nor `{` / `}`, and the value's
1577 // last byte isn't `/`. The resolver folds the value through
1578 // `Path::new(caminho).join(<file>)` looking for a literal
1579 // `./../caixa-[a-z]/build` subdirectory and fails at resolve
1580 // time with a non-self-locating `No such file or directory`
1581 // error far from the source caixa.lisp.
1582 //
1583 // The lacre pipeline embeds the value verbatim in its per-dep
1584 // content-address (`conteudo: format!("path:{caminho}")`,
1585 // caixa-resolver/src/resolve.rs:189), so a `[` or `]` byte
1586 // lands in the BLAKE3 closure and rides downstream as part of
1587 // the build's identity into every shell-spawned subprocess
1588 // (the caixa-resolver's `git clone` invocation, a future
1589 // `feira tofu` shell-out, a future operator-side `nix flake
1590 // check` spawn) as the canonical shell-metachar / glob-
1591 // character-class / TOML-array surface every peer single-
1592 // token-shaped typed slot already closes. The `:caminho` axis
1593 // was the last typed path-string surface still admitting
1594 // these two bytes; this arm closes the gap so the substrate-
1595 // wide "no shell-composition metacharacter anywhere in a
1596 // typed string slot that flows verbatim into a shell-spawned
1597 // subprocess" invariant extends from shell-brace-expansion
1598 // (`{` / `}`) to shell-bracket-expansion (`[` / `]`) on the
1599 // `:caminho` axis. Together with the cf9034b `*` / `?` arm,
1600 // the typed `:caminho` accepted set now structurally excludes
1601 // the entire POSIX pathname-expansion / glob surface —
1602 // unbounded glob (`*` / `?`) AND bounded character-class
1603 // (`[abc]` / `[a-z]`).
1604 //
1605 // The arm fires AFTER the shell-brace-expansion arm because
1606 // the prior arm's `{` / `}` shape is the more semantic-
1607 // locating axis on values that probe as both
1608 // (`"../{a,b}[ch]"` carries both `{` and `[` — the brace-
1609 // expansion fan is the load-bearing root-cause edit, so
1610 // `FonteCaminhoShellBraceExpansion` wins; same cascade
1611 // discipline every prior `:caminho` arm establishes). The arm
1612 // fires BEFORE the trailing-`/` arm because the embedded
1613 // bracket-expansion byte is the more semantic-locating axis
1614 // on probe-as-both values (`"../[a-z]/"` ends in `/` but the
1615 // load-bearing diagnostic is the embedded `[` glob-character-
1616 // class metachar — the trailing `/` is the secondary
1617 // observation, and an author who removes the `[` is likely
1618 // to also tab-strip the trailing separator).
1619 for &b in caminho.as_bytes() {
1620 if b == b'[' || b == b']' {
1621 return Err(DepError::FonteCaminhoShellBracketExpansion {
1622 nome: nome.to_string(),
1623 caminho: caminho.to_string(),
1624 byte: b,
1625 });
1626 }
1627 }
1628 // Reproducibility gate's shell-quote-grouping arm. The 986963b
1629 // shell-bracket-expansion arm closes `[` / `]`; `'` (`0x27`) and
1630 // `"` (`0x22`) are the orthogonal POSIX shell-string-literal
1631 // delimiter pair — same paste-from-shell-prompt footgun class,
1632 // different syntactic surface. Every POSIX shell (sh / bash /
1633 // zsh / dash / ksh / fish / nushell) lexes the pair as the
1634 // string-literal quoting operator: `'…'` is the strong
1635 // (no-expansion) single-quoted string and `"…"` is the weak
1636 // (variable-/command-substitution-preserving) double-quoted
1637 // string — the canonical `cd '../caixa-teia'` shell-history
1638 // idiom every path-with-embedded-whitespace paste block carries,
1639 // and the symmetric `git clone "$REPO"` weak-quoted CI-manifest
1640 // shape. Beyond shell, the two bytes carry the JSON string-literal
1641 // delimiter (`"key": "value"` — the canonical paste-from-JSON-
1642 // config cross-idiom-leak vector), the YAML double-quoted +
1643 // single-quoted flow-scalar delimiters (`path: "../caixa-teia"`
1644 // — the canonical paste-from-values.yaml / paste-from-K8s-YAML-
1645 // manifest cross-idiom leak), the TOML basic + literal string
1646 // delimiters (`path = "../caixa-teia"` — the canonical paste-
1647 // from-Cargo-manifest cross-idiom-leak vector), the tatara-lisp
1648 // string-literal delimiter itself (`(:caminho "../caixa-teia")`
1649 // — the canonical "I copied the entire `:caminho "..."` slot
1650 // rather than just the string body" author-surface footgun),
1651 // and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which
1652 // excludes both bytes from the `unreserved / pct-encoded /
1653 // sub-delims / ":" / "@"` `pchar` production. POSIX
1654 // `std::path::Path` treats both bytes as literal path-component
1655 // bytes (so `../"caixa-teia"` is one directory named literally
1656 // `../"caixa-teia"`, sibling of `.` and `..`).
1657 //
1658 // A `:caminho "'../caixa-teia'"` (the canonical "I pasted a
1659 // `cd '../caixa-teia'` shell-history one-liner whose strong-
1660 // quoting preserved the sibling-workspace path verbatim across
1661 // the whitespace paste boundary" footgun), `:caminho
1662 // "\"../caixa-teia\""` (the symmetric weak-quoted paste-from-
1663 // JSON / paste-from-YAML flow-scalar / paste-from-TOML basic-
1664 // string / paste-from-tatara-lisp string-literal cross-idiom-
1665 // leak shape), or `:caminho "../\"caixa-teia\""` (the embedded-
1666 // quote "I pasted a JSON key-value pair fragment into the
1667 // middle of the path" idiom) silently passes every prior arm
1668 // because `Path::is_absolute` returns false on `..` / `'` /
1669 // `"`, `'` / `"` are neither leading-byte sentinels nor
1670 // control bytes nor `\` nor `<` / `>` nor `|` nor `;` nor `&`
1671 // nor backtick nor `*` / `?` nor `(` / `)` nor `{` / `}` nor
1672 // `[` / `]`, and the value's last byte isn't `/`. The resolver
1673 // folds the value through `Path::new(caminho).join(<file>)`
1674 // looking for a literal `./'../caixa-teia'` subdirectory and
1675 // fails at resolve time with a non-self-locating `No such file
1676 // or directory` error far from the source caixa.lisp.
1677 //
1678 // The lacre pipeline embeds the value verbatim in its per-dep
1679 // content-address (`conteudo: format!("path:{caminho}")`,
1680 // caixa-resolver/src/resolve.rs:189), so a `'` or `"` byte
1681 // lands in the BLAKE3 closure and rides downstream as part of
1682 // the build's identity into every shell-spawned subprocess
1683 // (the caixa-resolver's `git clone` invocation, a future
1684 // `feira tofu` shell-out, a future operator-side `nix flake
1685 // check` spawn) as the canonical shell-metachar / string-
1686 // literal-delimiter surface every peer single-token-shaped
1687 // typed slot already closes. The peer `:fonte :repo` axis
1688 // closes both bytes under the same shell-quote-grouping /
1689 // RFC-3986-sub-delims banner (e7a109f `'` shell-single-quote
1690 // + 4267d8b `"` shell-double-quote on `is_git_repo_url`). The
1691 // `:caminho` axis was the last typed path-string surface
1692 // still admitting these two bytes; this arm closes the gap
1693 // so the substrate-wide "no shell-composition metacharacter
1694 // anywhere in a typed string slot that flows verbatim into a
1695 // shell-spawned subprocess" invariant extends from shell-
1696 // bracket-expansion (`[` / `]`) to shell-quote-grouping (`'`
1697 // / `"`) on the `:caminho` axis. Together with the peer
1698 // JSON / YAML / TOML string-literal delimiters closing at
1699 // this arm and the 598b770 `{` / `}` brace-expansion arm
1700 // closing the templating-engine-placeholder boundary, the
1701 // typed `:caminho` accepted set now structurally excludes
1702 // the entire cross-config-DSL string-literal / templating
1703 // paste-from-aligned-manifest cross-idiom-leak surface that
1704 // would silently round-trip through any downstream JSON /
1705 // YAML / TOML / HCL / tatara-lisp parsing layer.
1706 //
1707 // The arm fires AFTER the shell-bracket-expansion arm because
1708 // the prior arm's `[` / `]` shape is the more semantic-
1709 // locating axis on values that probe as both (`"../[a-z]'x'"`
1710 // carries both `[` and `'` — the glob-character-class
1711 // expansion is the load-bearing root-cause edit, so
1712 // `FonteCaminhoShellBracketExpansion` wins; same cascade
1713 // discipline every prior `:caminho` arm establishes). The arm
1714 // fires BEFORE the trailing-`/` arm because the embedded
1715 // quote-grouping byte is the more semantic-locating axis on
1716 // probe-as-both values (`"../'caixa-teia'/"` ends in `/` but
1717 // the load-bearing diagnostic is the embedded `'` shell-
1718 // string-literal metachar — the trailing `/` is the secondary
1719 // observation, and an author who removes the `'` is likely to
1720 // also tab-strip the trailing separator).
1721 for &b in caminho.as_bytes() {
1722 if b == b'\'' || b == b'"' {
1723 return Err(DepError::FonteCaminhoShellQuoteGrouping {
1724 nome: nome.to_string(),
1725 caminho: caminho.to_string(),
1726 byte: b,
1727 });
1728 }
1729 }
1730 // Reproducibility gate's shell-comment / URL-fragment / YAML-comment arm.
1731 // The d14cbc5 shell-quote-grouping arm closes `'` / `"`; `#` (`0x23`) is
1732 // the orthogonal "byte at which four distinct downstream parsers all
1733 // truncate the value at the first occurrence" surface, and no prior arm
1734 // has covered it on the `:caminho` axis. Every POSIX shell (sh / bash /
1735 // zsh / dash / ksh / fish / nushell) lexes an unquoted `#` at the head
1736 // of a word (or after unquoted whitespace) as the comment-lead: from
1737 // that byte to the end of the physical line is a comment discarded
1738 // before command parsing (`cd ../caixa-teia # legacy sibling` — the
1739 // canonical paste-from-shell-history-with-trailing-annotation shape
1740 // every operator-notebook and CI-manifest carries; POSIX.1-2017 §2.3
1741 // Token Recognition step 6). YAML 1.2 §6.6 makes `#` the comment lead
1742 // at any position preceded by whitespace or at line-start (`path:
1743 // ../caixa-teia # pin` — the canonical paste-from-values.yaml /
1744 // paste-from-K8s-manifest cross-idiom-leak shape). tatara-lisp itself
1745 // treats `;` as the comment-lead but a growing number of consumer
1746 // config-DSL layers (HCL, Terraform, Nix flake attributes, .env
1747 // dotenv-style files, gitconfig / .gitignore, ini / TOML) use `#` as
1748 // the comment-lead too — the pair extends the cross-config-DSL
1749 // paste-idiom surface the d14cbc5 quote-grouping arm and the 598b770
1750 // brace-expansion arm already cover on adjacent axes. RFC 3986 §3.5
1751 // reserves `#` as the URL fragment-identifier delimiter (the canonical
1752 // paste-from-browser-address-bar `github.com/foo/bar#readme` /
1753 // `github.com/foo/bar#L42` permalink shape, and the symmetric
1754 // Nix-flake-ref cross-idiom leak `github:foo/bar#packageName` where
1755 // `#` selects a flake output — the same axis the peer
1756 // [`crate::render::is_git_repo_url`] closes on the `:fonte :repo`
1757 // surface at a68f818 with the same downstream-drops-the-tail
1758 // rationale).
1759 //
1760 // POSIX `std::path::Path` treats `#` as a literal path-component byte,
1761 // so a `:caminho "../caixa-teia # legacy sibling"` (the canonical
1762 // paste-from-shell-history-with-trailing-annotation footgun),
1763 // `:caminho "../caixa-teia # pin"` (the symmetric YAML flow-scalar
1764 // paste-with-trailing-comment shape), or `:caminho "../caixa-teia
1765 // #readme"` (the URL fragment paste-from-browser-address-bar shape)
1766 // silently passes every prior arm because `Path::is_absolute` returns
1767 // false on `..`, `#` is neither a leading-byte sentinel nor a control
1768 // byte nor `\` nor `<` / `>` nor `|` nor `;` nor `&` nor backtick nor
1769 // `*` / `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` / `"`,
1770 // and the value's last byte isn't `/`. The resolver folds the value
1771 // through `Path::new(caminho).join(<file>)` looking for a literal
1772 // subdirectory named `../caixa-teia # legacy sibling` and fails at
1773 // resolve time with a non-self-locating `No such file or directory`
1774 // error far from the source caixa.lisp — while every downstream
1775 // shell / YAML / URL parser silently truncates the value at the `#`
1776 // byte to `../caixa-teia`, so a `feira tofu` shell-out to a
1777 // `cd '{caminho}'` command line and a `nix flake check` invocation on
1778 // an emitted YAML `path:` scalar disagree with the resolver on which
1779 // directory the value names. Two workstations whose downstream
1780 // shell / YAML / URL parsing layers differ in unquoted-`#`
1781 // recognition emit divergent build artifacts for the byte-identical
1782 // caixa.lisp value.
1783 //
1784 // The lacre pipeline embeds the value verbatim in its per-dep
1785 // content-address (`conteudo: format!("path:{caminho}")`,
1786 // caixa-resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1787 // closure and rides downstream as part of the build's identity into
1788 // every shell-spawned subprocess (the caixa-resolver's `git clone`
1789 // invocation, a future `feira tofu` shell-out, a future operator-side
1790 // `nix flake check` spawn) as the canonical shell-metachar /
1791 // comment-lead / URL-fragment-delimiter surface every peer
1792 // single-token-shaped typed slot already closes. The peer `:fonte
1793 // :repo` axis closes the byte under the URL-fragment-identifier
1794 // banner (a68f818 `#` on `is_git_repo_url`); the `:caminho` axis was
1795 // the last typed path-string surface still admitting the byte. This
1796 // arm closes the gap so the substrate-wide "no shell-composition
1797 // metacharacter / comment-lead / URL-fragment-delimiter anywhere in a
1798 // typed string slot that flows verbatim into a shell-spawned
1799 // subprocess or downstream YAML / URL parser" invariant extends from
1800 // shell-quote-grouping (`'` / `"`) to shell-comment / URL-fragment
1801 // (`#`) on the `:caminho` axis. Together with the peer JSON / YAML /
1802 // TOML string-literal delimiters the d14cbc5 quote-grouping arm
1803 // closes and the 598b770 `{` / `}` brace-expansion arm closes on the
1804 // templating-engine-placeholder boundary, the typed `:caminho`
1805 // accepted set now structurally excludes the entire
1806 // paste-with-trailing-annotation / paste-from-URL-permalink /
1807 // paste-from-YAML-comment cross-idiom-leak surface that would
1808 // silently round-trip through any downstream shell / YAML / URL /
1809 // dotenv / gitconfig / HCL parsing layer to a different value than
1810 // the resolver's `Path::join` sees.
1811 //
1812 // The arm fires AFTER the shell-quote-grouping arm because the prior
1813 // arm's `'` / `"` shape is the more semantic-locating axis on values
1814 // that probe as both (`"../'x'#pin"` carries both `'` and `#` — the
1815 // shell-string-literal-delimiter is the load-bearing root-cause edit,
1816 // so `FonteCaminhoShellQuoteGrouping` wins; same cascade discipline
1817 // every prior `:caminho` arm establishes). The arm fires BEFORE the
1818 // trailing-`/` arm because the embedded comment-lead / fragment-
1819 // delimiter byte is the more semantic-locating axis on probe-as-both
1820 // values (`"../caixa-teia#pin/"` ends in `/` but the load-bearing
1821 // diagnostic is the embedded `#` — the trailing `/` is the secondary
1822 // observation, and an author who removes the `#pin` fragment is
1823 // likely to also tab-strip the trailing separator).
1824 for &b in caminho.as_bytes() {
1825 if b == b'#' {
1826 return Err(DepError::FonteCaminhoShellComment {
1827 nome: nome.to_string(),
1828 caminho: caminho.to_string(),
1829 byte: b,
1830 });
1831 }
1832 }
1833 // Reproducibility gate's URL-percent-encoding-escape arm. The 6622063
1834 // shell-comment arm closes the `#` URL-fragment-identifier byte; `%`
1835 // (`0x25`) is the orthogonal RFC 3986 §2.1 URL percent-encoding-escape
1836 // byte — the mandatory encoding mechanism for every byte outside the
1837 // `unreserved` alphanumeric / `-` / `.` / `_` / `~` set, and `%`
1838 // itself must be percent-encoded as `%25` to appear literally inside
1839 // a URL value. The byte carries three distinct render-determinism
1840 // hazards on the `:caminho` axis, no prior arm has covered it, and
1841 // the peer `:fonte :repo` axis (a323db8 `%` on `is_git_repo_url`)
1842 // already closes the same byte under the same URL-percent-encoding
1843 // banner — the `:caminho` axis was the last typed path-string surface
1844 // still admitting the byte.
1845 //
1846 // First, the paste-from-browser-address-bar percent-encoded-space
1847 // footgun: an author copies `../caixa%20teia` out of a URL-encoded
1848 // README hyperlink / a browser address bar / a percent-encoded
1849 // permalink expecting `%20` to decode to a literal space at the
1850 // filesystem layer. POSIX `std::path::Path` treats the byte as a
1851 // literal path-component byte, so `Path::join` looks for a literal
1852 // `./../caixa%20teia` subdirectory and fails at resolve time with a
1853 // non-self-locating `No such file or directory` error far from the
1854 // source caixa.lisp — while the author's mental model was
1855 // `../caixa teia`, the decoded shape. Two authors whose only
1856 // difference is percent-encoding presence resolve to two distinct
1857 // BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`)
1858 // for what they intended as the byte-identical sibling-workspace
1859 // dep. The lacre pipeline embeds the value verbatim in its per-dep
1860 // content-address (`conteudo: format!("path:{caminho}")`,
1861 // caixa-resolver/src/resolve.rs:189), so the divergence rides
1862 // downstream into the BLAKE3 closure and locks the substrate's
1863 // "the lacre is the build's identity" contract (CAIXA-SDLC §III.2)
1864 // to the wrong encoding — the same THEORY.md §V.2 render-
1865 // determinism vector every prior `:caminho` arm protects.
1866 //
1867 // Second, the printf-format-specifier lead footgun: `%` is the C /
1868 // POSIX printf format-directive lead-in (`%s`, `%d`, `%02x`, the
1869 // canonical `printf "path=%s\n" ../caixa-teia` invocation every
1870 // shell-diagnostic one-liner carries) and the printf builtin is
1871 // wired into every POSIX shell (bash / zsh / dash / ksh / busybox
1872 // ash) as the format-string lead. A `:caminho "../caixa-%s-teia"`
1873 // value flowing into any future `feira` verb that shells out with a
1874 // printf-formatted path template silently gets reinterpreted as a
1875 // format-directive rather than a literal byte — the canonical
1876 // CWE-134 format-string-injection vector.
1877 //
1878 // Third, the bash-job-control-specifier lead footgun: bash / zsh /
1879 // ksh reserve `%N` at word-start as the job-control specifier —
1880 // `%1` names "job 1", `%%` names "the current job", `%foo` names
1881 // "the most recent job whose command started with `foo`". A future
1882 // `feira` verb that invokes `kill %1` on a caminho-scoped
1883 // subprocess would silently redirect the signal to a wrong target.
1884 //
1885 // Beyond the three shell-side hazards, `%` is a first-class parser
1886 // byte in three cross-config-DSL layers the substrate's paste-idiom
1887 // surface routinely crosses: YAML 1.2 §6.8.1 lexes `%` at
1888 // line-start as the directive lead (`%YAML 1.2` / `%TAG` — a
1889 // `:caminho "%YAML/1.2/../caixa-teia"` paste from a top-of-doc
1890 // YAML directive block silently trips the YAML directive parser on
1891 // any downstream emitted YAML manifest); Prometheus / Grafana
1892 // template syntax uses `%(var)s` as the substitution lead; and Nix
1893 // interpolation uses `${var}` (not `%`) but Envsubst /
1894 // Kubernetes / OpenShift template layers use `%VAR%` as the
1895 // Windows-shell env-var-reference lead — the paste-from-`.bat` /
1896 // paste-from-PowerShell-`%env:PATH%` cross-idiom leak.
1897 //
1898 // The three malformed-`%HH` classes documented on the peer
1899 // `is_git_repo_url` `%` arm (a323db8) apply here too:
1900 //
1901 // - The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
1902 // where `%` isn't followed by two hex digits) — every WHATWG-
1903 // conformant URL parser rejects the value at parse time per
1904 // RFC 3986 §2.1, but the byte rides into the lacre before
1905 // the resolver subprocess crosses the URL-parser boundary.
1906 // - The over-encoded path-separator shape (`"../caixa%2Fteia"`
1907 // intending the `%2F` as the URL encoding of `/`) locks a
1908 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
1909 // the byte-identical `path:../caixa/teia` form.
1910 // - The double-encoded shape (`"../caixa%2520teia"` — the `%25`
1911 // already itself an encoded `%`, so the intent was likely a
1912 // literal `%20` that survived one round-trip through a
1913 // URL-encoder that shouldn't have run) locks a triply-
1914 // divergent closure across the encoded / once-decoded /
1915 // twice-decoded chain.
1916 //
1917 // POSIX `std::path::Path` treats the byte as a literal path-
1918 // component byte, so a `:caminho "../caixa%20teia"` (the canonical
1919 // paste-from-browser-address-bar percent-encoded-space footgun),
1920 // `:caminho "%YAML/../caixa-teia"` (the symmetric paste-from-YAML-
1921 // directive-block cross-idiom leak), or `:caminho
1922 // "../caixa-%s-teia"` (the printf-format-specifier paste-from-
1923 // shell-diagnostic-one-liner shape) silently passes every prior arm
1924 // because `Path::is_absolute` returns false on `..`, `%` is neither
1925 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
1926 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
1927 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`, and the
1928 // value's last byte isn't `/`. The resolver folds the value through
1929 // `Path::new(caminho).join(<file>)` looking for a literal
1930 // subdirectory named `../caixa%20teia` and fails at resolve time
1931 // with a non-self-locating `No such file or directory` error far
1932 // from the source caixa.lisp — while every downstream URL parser /
1933 // shell printf builtin / YAML directive parser silently
1934 // reinterprets the byte to a different value than the resolver's
1935 // `Path::join` sees. Two workstations whose downstream URL / shell
1936 // / YAML layers differ in `%HH` recognition emit divergent build
1937 // artifacts for the byte-identical caixa.lisp value.
1938 //
1939 // The lacre pipeline embeds the value verbatim in its per-dep
1940 // content-address (`conteudo: format!("path:{caminho}")`, caixa-
1941 // resolver/src/resolve.rs:189), so the byte lands in the BLAKE3
1942 // closure and rides into every shell-spawned subprocess (the
1943 // resolver's `git clone`, a future `feira tofu` shell-out, a
1944 // future operator-side `nix flake check` spawn) as the canonical
1945 // URL-percent-encoding-escape / printf-format-specifier / bash-
1946 // job-control-specifier surface every peer single-token-shaped
1947 // typed slot already closes. This arm closes the gap so the
1948 // substrate-wide "no URL-percent-encoding-escape / printf-format-
1949 // specifier / job-control-specifier / YAML-directive-lead byte
1950 // anywhere in a typed string slot that flows verbatim into a
1951 // shell-spawned subprocess or downstream URL / printf / YAML
1952 // parser" invariant extends from shell-comment / URL-fragment
1953 // (`#` — 6622063) to URL-percent-encoding-escape (`%`) on the
1954 // `:caminho` axis.
1955 //
1956 // The arm fires AFTER the shell-comment arm because the prior
1957 // arm's `#` shape is the more semantic-locating axis on values
1958 // that probe as both (`"../caixa%20teia#pin"` carries both `%`
1959 // and `#` — the URL-fragment-identifier is the load-bearing
1960 // downstream-truncation edit, so `FonteCaminhoShellComment` wins;
1961 // same cascade discipline every prior `:caminho` arm establishes).
1962 // The arm fires BEFORE the trailing-`/` arm because the embedded
1963 // percent-encoding-escape byte is the more semantic-locating axis
1964 // on probe-as-both values (`"../caixa%20teia/"` ends in `/` but
1965 // the load-bearing diagnostic is the embedded `%` percent-
1966 // encoding-escape — the trailing `/` is the secondary observation,
1967 // and an author who decodes the `%20` to a literal space is
1968 // likely to also tab-strip the trailing separator).
1969 for &b in caminho.as_bytes() {
1970 if b == b'%' {
1971 return Err(DepError::FonteCaminhoUrlPercentEncoding {
1972 nome: nome.to_string(),
1973 caminho: caminho.to_string(),
1974 byte: b,
1975 });
1976 }
1977 }
1978 // Reproducibility gate's embedded-`$` shell-variable-expansion /
1979 // command-substitution / arithmetic-expansion arm. The f4efe9c
1980 // leading-`$` arm at line 540 routes `caminho.starts_with('$')`
1981 // through `FonteCaminhoVarExpansion` under the leading-byte-
1982 // sentinel host-layout-leak banner (peer with the b94fd83
1983 // absolute / a5c248e tilde leading-byte arms), but the arm
1984 // fires only at position 0 — a `:caminho "../foo$HOME/bar"`
1985 // (embedded `$HOME` in a nested path segment — the canonical
1986 // paste-from-`ls ../foo$HOME/bar`-shell-one-liner footgun where
1987 // an author copies a partially-substituted shell one-liner and
1988 // the leading segment is a literal `../foo` while the mid
1989 // segment carries the un-substituted `$HOME` template), a
1990 // `:caminho "../foo${WORKSPACE}/bar"` (the symmetric braced-CI-
1991 // manifest paste-from-`.gitlab-ci.yml` / paste-from-GitHub-
1992 // Actions-workflow shape), a `:caminho "../foo$(whoami)/bar"`
1993 // (the paste-from-shell-prompt command-substitution idiom), or
1994 // a `:caminho "../foo$((1+2))/bar"` (the arithmetic-expansion
1995 // idiom) silently passes every prior arm because
1996 // `Path::is_absolute` returns false on `..`, `$` is neither a
1997 // leading-byte sentinel (the f4efe9c arm fires only at position
1998 // 0) nor a control byte nor `\` nor `<` / `>` nor `|` nor `;`
1999 // nor `&` nor backtick nor `*` / `?` nor `(` / `)` nor `{` /
2000 // `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%`, and the
2001 // value's last byte isn't `/`. Note that `$(...)` command-
2002 // substitution and `$((...))` arithmetic-expansion each carry
2003 // an embedded `(` byte that the 0633c91 shell-subshell-grouping
2004 // arm catches structurally at the earlier `(` position — but
2005 // an author who reaches for the sh-brace-substitution
2006 // `${VAR}` or the bare `$VAR` shape carries only the `$` byte,
2007 // which no prior arm covers. This arm closes the last
2008 // positional gap on the `$` byte on the `:caminho` axis so
2009 // every position — leading (`FonteCaminhoVarExpansion`) and
2010 // embedded (`FonteCaminhoShellVariableExpansion`) — is
2011 // structurally rejected.
2012 //
2013 // Every POSIX shell (sh / bash / zsh / dash / ksh / busybox
2014 // ash / fish / nushell) lexes `$` as the variable-expansion /
2015 // command-substitution / arithmetic-expansion operator per
2016 // POSIX.1-2017 §2.6 (Word Expansions): `$<name>` (Parameter
2017 // Expansion) expands a named variable, `${<name>}` (Parameter
2018 // Expansion braced form) does the same with an explicit token
2019 // boundary, `$(<cmd>)` (Command Substitution modern form,
2020 // `` `<cmd>` `` legacy form which the c370458 backtick arm
2021 // already closes) runs a subshell and substitutes its stdout,
2022 // and `$((<expr>))` (Arithmetic Expansion) evaluates an
2023 // arithmetic expression. Every form is a host-layout /
2024 // environment-state / shell-subprocess-side-effect leak when
2025 // the byte lands in a value the resolver passes to a shell-
2026 // spawned subprocess. Beyond the POSIX shell layer, `$` is
2027 // the Nix `${var}` string-interpolation lead (the paste-from-
2028 // `flake.nix` / paste-from-`.nix`-attribute cross-idiom leak
2029 // where an author copies `"${pkgs.hello}/bin/hello"` out of a
2030 // nix expression), the Make `$(var)` / `$@` / `$<` automatic-
2031 // variable lead (the paste-from-`Makefile` shape), the
2032 // JavaScript / TypeScript template-literal `${expr}` interp
2033 // lead (the paste-from-JS-template-string idiom in a
2034 // multi-lang-monorepo where a `path` attribute gets copied out
2035 // of a `package.json` script or a Vite config), the envsubst /
2036 // Kubernetes / OpenShift template `${VAR}` interp lead (the
2037 // paste-from-Helm-values / paste-from-K8s-manifest cross-idiom
2038 // leak), the PHP variable lead (`$_GET`, `$_ENV` — the paste-
2039 // from-`.php`-config footgun), the Perl scalar-variable lead
2040 // (`$foo`), the SASS / SCSS variable lead (`$primary-color`),
2041 // and the SQL bind-parameter lead in PostgreSQL / SQLite
2042 // (`$1`, `$2` — the paste-from-`.sql`-migration idiom). The
2043 // cross-idiom paste-footgun surface is broader than any single
2044 // shell layer — `$` is a first-class parser byte in nearly
2045 // every config / templating / build-system DSL the substrate's
2046 // paste-idiom surface routinely crosses. The peer `:fonte
2047 // :repo` axis closes the byte under the shell-variable-
2048 // expansion / URL-sub-delim banner (b9d187c `$` on
2049 // `is_git_repo_url`), the peer `:fonte :tag` / `:fonte :branch`
2050 // axes close `$` as part of `is_git_ref_name`'s printable-
2051 // ASCII-restricted grammar (`git check-ref-format` rejects the
2052 // byte outright), and the peer `:entrada :paths` axis closes
2053 // `$` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-
2054 // reserved set. The `:caminho` axis was the last typed path-
2055 // string surface still admitting `$` at positions other than 0.
2056 //
2057 // POSIX `std::path::Path` treats `$` as a literal path-
2058 // component byte, so `:caminho "../foo$HOME/bar"` silently
2059 // routes through `Path::new(caminho).join(<file>)` looking for
2060 // a literal `./{caminho}` subdirectory that fails at resolve
2061 // time with a non-self-locating `No such file or directory`
2062 // error far from the source caixa.lisp. But every downstream
2063 // shell / envsubst / Nix / Make / K8s-template parser silently
2064 // reinterprets the byte to a different value than the
2065 // resolver's `Path::join` sees — so a `feira tofu` shell-out
2066 // to a `cd '{caminho}'` command line, a `nix flake check`
2067 // invocation on an emitted YAML `path:` scalar folded through
2068 // envsubst, or a `helm template` invocation with a
2069 // `values.yaml` `path: {caminho}` embedded in a `{{`-quoted
2070 // template all disagree with the resolver on which directory
2071 // the value names. Two workstations whose downstream shell /
2072 // envsubst / Nix / Make / K8s-template parsing layers differ
2073 // in `$VAR` recognition (or, worse, expand the byte against
2074 // divergent environments — Alice's `$HOME=/home/alice`, Bob's
2075 // `$HOME=/home/bob`) emit divergent build artifacts for the
2076 // byte-identical caixa.lisp value. Even in the case where the
2077 // resolver strictly does NOT expand `$VAR` (the current
2078 // implementation) the divergence still bites at the lacre-
2079 // identity axis: the lacre pipeline embeds the value verbatim
2080 // in its per-dep content-address (`conteudo:
2081 // format!("path:{caminho}")`, caixa-resolver/src/resolve.rs:189),
2082 // so `path:../foo$HOME/bar` locks a BLAKE3 closure distinct
2083 // from the byte-identical-semantic `path:../foo/home/alice/bar`
2084 // one author would have produced by substituting the literal
2085 // value at author time, defeating the THEORY.md §V.2 render-
2086 // determinism contract on the same axis every prior `:caminho`
2087 // arm protects.
2088 //
2089 // Beyond the render-determinism / host-layout-leak vectors,
2090 // `$` at any position in a value flowing verbatim into a
2091 // shell-spawned subprocess is the canonical CWE-78 shell-
2092 // command-injection surface every peer single-token-shaped
2093 // typed slot already closes. A `:caminho "../foo$(whoami)/bar"`
2094 // that rides into a future `feira tofu` shell-out as `cd
2095 // '../foo$(whoami)/bar'` gets substituted by the shell at
2096 // subprocess-argument-expansion time even inside single quotes
2097 // in fewer positions than one might expect (the substitution
2098 // fires only outside single-quoting per POSIX §2.2.2, but
2099 // eval-style wrappers and `sh -c` layers that route the value
2100 // through re-parsing round-trip the substitution — the same
2101 // vector the c370458 backtick arm closes at the sibling
2102 // command-substitution-legacy-form surface). Every future
2103 // `feira` verb that shells out with a `caminho`-formatted
2104 // subprocess argument silently inherits this substitution
2105 // vector unless the typed slot's accepted set structurally
2106 // excludes the byte.
2107 //
2108 // Frontier inspiration: OTP's `gen_server` return-value grammar
2109 // rejects mid-tuple shell-metachar bytes by construction —
2110 // `{noreply, State}` never carries a raw `$` because the
2111 // Erlang term type system has no notion of "string that gets
2112 // shelled out"; caixa's typed slots inherit the same
2113 // structural discipline (types-are-theorems, the compounding
2114 // mandate's leverage-point-1) by refusing values that would
2115 // silently reinterpret at any downstream layer. Peer with
2116 // Unison's content-addressed code (no ambient environment —
2117 // every reference is a hash, no `$VAR` substitution possible)
2118 // and Pony's capabilities (a path capability that carries a
2119 // `$` would be ill-typed at the reference layer).
2120 //
2121 // The arm fires AFTER the URL-percent-encoding-escape arm (the
2122 // e3558fa `%` arm) because a value carrying both `%` and `$`
2123 // (`"../foo%20$HOME/bar"` — the canonical "I pasted a percent-
2124 // encoded space next to a `$HOME` template") surfaces the
2125 // narrower URL-encoding diagnostic first — the paste-from-
2126 // browser-address-bar shape is the load-bearing self-locating
2127 // edit on every probe-as-both value; same cascade discipline
2128 // every prior `:caminho` arm establishes (a323db8 % before
2129 // this arm, this arm before trailing-`/`). The arm fires
2130 // BEFORE the trailing-`/` arm because the embedded shell-
2131 // variable-expansion byte is the more semantic-locating axis
2132 // on probe-as-both values (`"../foo$HOME/bar/"` ends in `/`
2133 // but the load-bearing diagnostic is the embedded `$` — the
2134 // trailing `/` is the secondary observation, and an author
2135 // who substitutes the `$HOME` template with a literal value is
2136 // likely to also tab-strip the trailing separator).
2137 for &b in caminho.as_bytes() {
2138 if b == b'$' {
2139 return Err(DepError::FonteCaminhoShellVariableExpansion {
2140 nome: nome.to_string(),
2141 caminho: caminho.to_string(),
2142 byte: b,
2143 });
2144 }
2145 }
2146 // Reproducibility gate's shell-history-expansion / RFC-3986-sub-delims
2147 // arm. The immediate-predecessor `$` embedded arm closes the shell-
2148 // variable-expansion / command-substitution byte; `!` (`0x21`) is the
2149 // orthogonal POSIX shell-history-expansion sentinel every interactive
2150 // shell with history enabled (bash / ksh / zsh's `bashcompat` /
2151 // csh / tcsh) lexes as the history-expansion prefix: `!command`
2152 // re-runs the most recent history entry beginning with `command`,
2153 // `!!` re-runs the prior command verbatim, `!$` substitutes the
2154 // last word of the prior command, `!:N` substitutes the Nth word,
2155 // `^old^new` rewrites the prior command's `old` to `new` (the
2156 // canonical set of `set -o histexpand` operators bash's default
2157 // interactive session enables). Beyond the shell-history layer,
2158 // RFC 3986 §2.2 lists `!` in the `sub-delims` set (the URL grammar
2159 // admits the byte inside a path segment, but every WHATWG-conformant
2160 // special-scheme URL parser percent-encodes it inside a query
2161 // component via the 'special-query percent-encode set' the peer
2162 // `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte
2163 // is also the C / C++ / Rust / JavaScript / Python bang-operator
2164 // (logical-negation prefix — the paste-from-source-code idiom where
2165 // an author copies `!path.exists()` out of a Rust snippet and the
2166 // trailing punctuation crosses the string-literal boundary); the
2167 // canonical English-typography emphasis / exclamation mark (the
2168 // paste-from-prose enthusiasm-form idiom where an author writes
2169 // `:caminho "../caixa-teia!"` expecting the substrate to coerce it
2170 // to a kebab-case slug); and the Nix flake-ref import-attribute
2171 // `import ./foo.nix { … }` sibling operator surface.
2172 //
2173 // POSIX `std::path::Path` treats `!` as a literal path-component
2174 // byte, so a `:caminho "../caixa-teia!sudo"` (the canonical paste-
2175 // from-shell-history footgun where the author copies a `cd
2176 // ../caixa-teia && !sudo make install` one-liner from a quick-
2177 // start README and the trailing `!sudo` rides in verbatim as a
2178 // history-expansion reference), a `:caminho "../foo!!/bar"` (the
2179 // `!!` repeat-prior-command paste idiom), a `:caminho
2180 // "../caixa-teia!"` (the English-typography enthusiasm-form
2181 // paste-from-prose footgun), or a `:caminho "../foo!$"` (the
2182 // last-word-substitution shape) silently pass every prior arm
2183 // because `Path::is_absolute` returns false on `..`, `!` is neither
2184 // a leading-byte sentinel nor a control byte nor `\` nor `<` / `>`
2185 // nor `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` / `)`
2186 // nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#` nor `%` nor `$`,
2187 // and the value's last byte isn't `/`. The resolver folds the value
2188 // through `Path::new(caminho).join(<file>)` looking for a literal
2189 // `./../caixa-teia!sudo` subdirectory and fails at resolve time
2190 // with a non-self-locating `No such file or directory` error far
2191 // from the source caixa.lisp — while every downstream interactive
2192 // shell with `set -o histexpand` reinterprets the byte as the
2193 // history-expansion prefix, and the failure mode forks per
2194 // consumer: a `feira tofu` shell-out to a `cd '{caminho}'` command
2195 // line executed under `bash -i` (the operator-notebook interactive
2196 // shell) substitutes the `!sudo` reference to the most recent
2197 // history entry starting with `sudo`, silently invoking whatever
2198 // privileged command that entry named.
2199 //
2200 // The lacre pipeline embeds the value verbatim in its per-dep
2201 // content-address (`conteudo: format!("path:{caminho}")`,
2202 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2203 // BLAKE3 closure and rides into every shell-spawned subprocess
2204 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2205 // a future operator-side `nix flake check` spawn) as the
2206 // canonical shell-history-expansion / RFC-3986-sub-delims surface
2207 // every peer single-token-shaped typed slot already closes. The
2208 // peer `:fonte :repo` axis closes the byte under the same shell-
2209 // history-expansion / RFC-3986-sub-delims banner (7d53c68 `!` on
2210 // `is_git_repo_url`); the `:caminho` axis was the last typed
2211 // path-string surface still admitting the byte. This arm closes
2212 // the gap so the substrate-wide "no shell-composition
2213 // metacharacter / history-expansion sentinel anywhere in a typed
2214 // string slot that flows verbatim into a shell-spawned subprocess"
2215 // invariant extends from shell-variable-expansion (`$`) to shell-
2216 // history-expansion (`!`) on the `:caminho` axis. Together with
2217 // the peer c370458 backtick command-substitution-legacy-form arm
2218 // and the b9d187c-`$`-embedded-variable-expansion arm on the
2219 // sibling `:repo` axis, the typed `:caminho` accepted set now
2220 // structurally excludes every byte the POSIX shell §2.6 Word
2221 // Expansions section, §2.3 Token Recognition step 6, and every
2222 // history-expansion / brace-expansion / pathname-expansion /
2223 // parameter-expansion / command-substitution / arithmetic-
2224 // expansion operator lexes as a first-class parser byte.
2225 //
2226 // Frontier inspiration: Unison's content-addressed code (no
2227 // ambient environment — every reference is a hash, no `!<num>`
2228 // history-index substitution possible; the caixa substrate's
2229 // lacre discipline arrives at the same guarantee by refusing
2230 // bytes at manifest-parse time that would reinterpret against
2231 // ambient shell history state); Pony's capabilities (a path
2232 // capability that carries a `!` would be ill-typed at the
2233 // reference layer).
2234 //
2235 // The arm fires AFTER the shell-variable-expansion arm because a
2236 // value carrying both `$` and `!` (`"../foo$HOME/bar!sudo"` — the
2237 // canonical "I pasted a `$HOME`-templated path adjacent to a
2238 // trailing `!sudo` history-expansion") surfaces the narrower
2239 // shell-variable-expansion diagnostic first — the paste-from-CI-
2240 // manifest-with-`$VAR`-template shape is the load-bearing self-
2241 // locating edit on every probe-as-both value; same cascade
2242 // discipline every prior `:caminho` arm establishes. The arm
2243 // fires BEFORE the trailing-`/` arm because the embedded shell-
2244 // history-expansion byte is the more semantic-locating axis on
2245 // probe-as-both values (`"../foo!sudo/"` ends in `/` but the
2246 // load-bearing diagnostic is the embedded `!` — the trailing `/`
2247 // is the secondary observation, and an author who removes the
2248 // `!sudo` history reference is likely to also tab-strip the
2249 // trailing separator).
2250 for &b in caminho.as_bytes() {
2251 if b == b'!' {
2252 return Err(DepError::FonteCaminhoShellHistoryExpansion {
2253 nome: nome.to_string(),
2254 caminho: caminho.to_string(),
2255 byte: b,
2256 });
2257 }
2258 }
2259 // Reproducibility gate's shell-history-substitution / RFC-3986-unwise
2260 // / regex-anchor arm. The immediate-predecessor `!` arm closes the
2261 // POSIX `!command` / `!!` / `!$` history-expansion prefix; `^`
2262 // (`0x5E`) is the paired-operator half of the same bash-reference
2263 // §9.3 histexpand feature — the `^old^new^` "quick substitution"
2264 // form (POSIX bash rewrites the prior command's `old` string to
2265 // `new` and re-executes it, the canonical typo-correction one-
2266 // liner idiom `git clone <bad-url>` → `^bad^good` that pastes the
2267 // trailing substitution fragment verbatim into a `:caminho` value
2268 // when the author trims only the leading `git clone` prefix). The
2269 // peer `:fonte :repo` axis closes the byte under the same
2270 // shell-history-substitution / RFC-3986-unwise banner (49e142f `^`
2271 // on `is_git_repo_url`); the `:caminho` axis was the last typed
2272 // path-string surface still admitting the byte after 6a04767
2273 // landed the `!` arm.
2274 //
2275 // Beyond bash history-substitution, `^` carries five distinct
2276 // downstream-reinterpretation surfaces the typed slot's accepted
2277 // set must structurally exclude:
2278 //
2279 // 1. **RFC 3986 §2 'unwise' set** — the four-byte cross-transport
2280 // layer set (`{`, `}`, `|`, `\`) plus `^` every URL parser is
2281 // required to percent-encode-or-refuse at the wire boundary.
2282 // The WHATWG URL spec's 'fragment percent-encode set' maps
2283 // `^` → `%5E` at the query / fragment component transition;
2284 // libcurl silently percent-encodes the byte on the wire, so a
2285 // `:caminho "../foo^bar"` value the resolver's `Path::join`
2286 // sees as a literal `./../foo^bar` subdirectory diverges from
2287 // the byte-transformed `%5E` shape any downstream `feira tofu`
2288 // curl-invocation or artifact-registry-fetch would emit — the
2289 // canonical wire-boundary divergence vector the peer
2290 // `{`, `}`, `|`, `\` `:caminho` arms already close (
2291 // `FonteCaminhoShellBraceExpansion` at 598b770,
2292 // `FonteCaminhoShellPipe` at the pipe arm,
2293 // `FonteCaminhoBackslash` at the backslash arm).
2294 // 2. **Regex character-class negation prefix `[^abc]`** — the
2295 // canonical paste-from-doc-regex-pipeline footgun where an
2296 // author copies a `grep '[^abc]'` idiom from a docs quick-
2297 // listing and the character-class negation byte rides in
2298 // verbatim.
2299 // 3. **Bitwise XOR operator** in C / C++ / Rust / Python /
2300 // JavaScript / Nix / Go — the paste-from-source-code idiom
2301 // where an author copies an `x ^ y`-shaped expression out of
2302 // a source snippet and the operator crosses the string-
2303 // literal boundary.
2304 // 4. **Windows `cmd.exe` escape metacharacter** — the byte
2305 // escapes the next character in a `cmd.exe` batch context (a
2306 // peer of the backslash arm's Windows-separator-leak vector).
2307 // A `:caminho "..^&whoami"` cross-platform paste-from-batch-
2308 // file footgun reinterprets at every `cmd.exe`-spawned
2309 // subprocess (the resolver's future Windows-runner shell-out,
2310 // the operator's WinRM path, a future PowerShell-embedded
2311 // invocation).
2312 // 5. **LaTeX / Markdown / BibTeX superscript operator** — the
2313 // paste-from-typeset-doc footgun where a mathematical
2314 // superscript notation (`x^2` / `M^T`) leaks from prose.
2315 //
2316 // POSIX `std::path::Path` treats `^` as a literal path-component
2317 // byte, so `:caminho "../foo^bar/baz"` (embedded quick-
2318 // substitution), `:caminho "../foo^"` (trailing history-
2319 // substitution-open shape), `:caminho "../[^a-z]/foo"` (regex-
2320 // negation-prefix paste from a grep pipeline; note the `[` / `]`
2321 // arm at 986963b fires first on this shape), or `:caminho
2322 // "../x^y"` (XOR-expression paste-from-source) all silently pass
2323 // every prior arm (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` /
2324 // backtick / `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'`
2325 // / `"` / `#` / `%` / `$` / `!`) and route through
2326 // `Path::new(caminho).join(<file>)` looking for a literal
2327 // `./{caminho}` subdirectory that fails at resolve time with a
2328 // non-self-locating `No such file or directory` error far from
2329 // the source caixa.lisp — while every downstream shell / curl /
2330 // regex / `cmd.exe` layer reinterprets the byte to its own
2331 // semantic.
2332 //
2333 // The lacre pipeline embeds the value verbatim in its per-dep
2334 // content-address (`conteudo: format!("path:{caminho}")`,
2335 // caixa-resolver/src/resolve.rs:189), so the byte lands in the
2336 // BLAKE3 closure and rides into every shell-spawned subprocess
2337 // (the resolver's `git clone`, a future `feira tofu` shell-out,
2338 // a future operator-side `nix flake check` spawn) as the
2339 // canonical shell-history-substitution / RFC-3986-unwise /
2340 // regex-negation surface every peer single-token-shaped typed
2341 // slot already closes. This arm together with the immediate-
2342 // predecessor `!` arm (6a04767) closes the full `set -o
2343 // histexpand` operator surface on the `:caminho` axis — the
2344 // `!command` / `!!` / `!$` prefix form via `!`, the `^old^new^`
2345 // quick-substitution form via `^` — so the substrate-wide "no
2346 // shell-history operator anywhere in a typed string slot that
2347 // flows verbatim into a shell-spawned subprocess" invariant
2348 // extends from the `!` prefix half to the `^` quick-substitution
2349 // half. Every peer bash-history operator now fails at manifest-
2350 // parse time with a self-locating diagnostic naming the offending
2351 // caixa.lisp rather than at resolve-time as a `Path::join`-
2352 // derived `No such file or directory` (harmless but non-self-
2353 // locating) or worse riding into a downstream `bash -i` context
2354 // that reinterprets the byte-pair against ambient history state.
2355 //
2356 // Frontier inspiration: bash reference §9.3 HISTORY EXPANSION
2357 // "Quick substitution. Repeat the previous command, replacing
2358 // string1 with string2." + RFC 3986 §2 'unwise' set
2359 // ("characters that gateways and other transport agents are
2360 // known to sometimes modify") + Pony's capabilities (a path
2361 // capability that carries a `^` would be ill-typed at the
2362 // reference layer, matching the same structural discipline the
2363 // sibling `!` history-expansion arm inherits from Unison's
2364 // content-addressed no-ambient-history discipline).
2365 //
2366 // The arm fires AFTER the shell-history-expansion `!` arm because
2367 // a value carrying both `!` and `^` (`"../foo!sudo^bad^good"` —
2368 // the canonical "I pasted a `!sudo` history-reference next to a
2369 // `^bad^good` quick-substitution") surfaces the narrower prefix-
2370 // form `!` diagnostic first — the `!` form is the load-bearing
2371 // self-locating edit on every probe-as-both value (an author who
2372 // removes the `!sudo` reference is likely to also strip the
2373 // paired `^` substitution fragment); same cascade discipline
2374 // every prior `:caminho` arm establishes. The arm fires BEFORE
2375 // the trailing-`/` arm because the embedded shell-history-
2376 // substitution byte is the more semantic-locating axis on
2377 // probe-as-both values (`"../foo^bar/"` ends in `/` but the
2378 // load-bearing diagnostic is the embedded `^` — the trailing `/`
2379 // is the secondary observation, and an author who removes the
2380 // `^bar` substitution fragment is likely to also tab-strip the
2381 // trailing separator).
2382 for &b in caminho.as_bytes() {
2383 if b == b'^' {
2384 return Err(DepError::FonteCaminhoShellHistorySubstitution {
2385 nome: nome.to_string(),
2386 caminho: caminho.to_string(),
2387 byte: b,
2388 });
2389 }
2390 }
2391 // Reproducibility gate's trailing-`/` arm. The b94fd83 absolute arm
2392 // closes the leading-`/` host-layout-leak; the embedded-control-byte
2393 // arm closes any byte-in-the-`0x00..=0x1F` / `0x7F` range; the
2394 // backslash arm closes the cross-host-OS-separator vector. The
2395 // trailing-`/` is the orthogonal shell-tab-completion-on-a-directory
2396 // footgun — `Path::join("../caixa-teia")` and
2397 // `Path::join("../caixa-teia/")` resolve to the same directory
2398 // (POSIX path-component-walk treats trailing `/` as a no-op for
2399 // directory targets, which `:caminho` always names — the sibling-
2400 // workspace dep root is structurally a directory). The lacre
2401 // pipeline embeds the value verbatim in its per-dep content-address
2402 // (`conteudo: format!("path:{caminho}")`,
2403 // caixa-resolver/src/resolve.rs:189), so byte-identical caixa
2404 // semantic-meaning yields two distinct BLAKE3 closures depending on
2405 // whether the author shell-tab-completed the path (every interactive
2406 // shell appends `/` on tab-completing a directory, idiomatic in
2407 // bash / zsh / fish / nushell), pasted from `pwd` (which on most
2408 // shells emits without trailing `/`, but `realpath -e -m` on a
2409 // directory with trailing `/` preserves it), or copied a Cargo
2410 // `path = "../caixa-teia/"` entry from cross-substrate documentation
2411 // (Cargo accepts both shapes and folds them the same way). Two
2412 // workstations whose authors differ only in tab-completion habits
2413 // emit byte-divergent lacres for the byte-identical-semantic caixa,
2414 // and the substrate's "the lacre is the build's identity" contract
2415 // (CAIXA-SDLC §III.2) silently breaks far from the source caixa.lisp.
2416 //
2417 // Same THEORY.md §V.2 render-determinism axis every prior `:caminho`
2418 // arm protects, here against the trailing-separator divergence
2419 // vector: every typed slot's accepted set excludes byte-divergent
2420 // values that round-trip to the same downstream semantic. The peer
2421 // path-shaped axes already reject trailing separators on the same
2422 // contract: [`crate::render::is_gateway_api_http_path`] gates
2423 // `:entrada :paths` against any non-canonical normalization, and
2424 // [`crate::render::is_sandboxed_relative_path`] gates the M2 typed
2425 // path-slots (`:behavior :on-*`, `:upgrade-from :state-change
2426 // :script`, `:bibliotecas`, `:exe`, `:servicos`) against shapes
2427 // whose canonical form would re-introduce determinism divergence.
2428 //
2429 // The arm fires last in the cascade because every prior arm carries
2430 // a more self-locating diagnostic on values that probe as both
2431 // (e.g. `:caminho "../foo/\0/"` ends in `/` but the load-bearing
2432 // diagnostic is the NUL byte's POSIX-syscall-rejection — the
2433 // control-char arm wins; `:caminho "/etc/passwd/"` ends in `/` but
2434 // the load-bearing diagnostic is the absolute host-layout-leak —
2435 // the absolute arm wins; `:caminho "..\caixa-teia/"` ends in `/`
2436 // but the load-bearing diagnostic is the Windows-separator cross-
2437 // OS divergence — the backslash arm wins). The arm covers every
2438 // shape where the last byte is `/` regardless of length, including
2439 // the degenerate single-`/` (which the absolute arm catches first)
2440 // and the consecutive-`//` (where every prior arm passes on the
2441 // bytes other than the trailing `/`).
2442 if caminho.as_bytes().last() == Some(&b'/') {
2443 return Err(DepError::FonteCaminhoTrailingSlash {
2444 nome: nome.to_string(),
2445 caminho: caminho.to_string(),
2446 });
2447 }
2448 Ok(())
2449 }
2450}
2451
2452impl Dep {
2453 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:nome` scalar
2454 /// accessor every consumer of the dep-graph identity axis keys off —
2455 /// returns the author-declared `:nome` byte-string verbatim as a
2456 /// `&str`, borrowed from the typed slot's own [`String`] storage.
2457 ///
2458 /// The `:deps :nome` / `:deps-dev :nome` slot carries the DNS-1123
2459 /// label that names the target caixa (validated by [`Self::validate`]
2460 /// through the shared [`crate::render::is_dns_1123_label`] predicate,
2461 /// same accept-set the peer caixa-identifier axes carry — top-level
2462 /// [`crate::Caixa::nome`], per-`:membros` [`crate::Membro::nome`],
2463 /// per-`:children` [`crate::supervisor::ChildSpec::nome`]). Every
2464 /// downstream consumer that fans on the dep's name-identity keys off
2465 /// this scalar: the [`crate::Caixa::validate_deps`] per-list
2466 /// [`crate::render::insert_first_seen`] dedup key + the paired
2467 /// [`DepError::DuplicateNome`] carrier the walk raises on collision,
2468 /// the cross-list [`validate_no_self_dep`] parent-name equality gate
2469 /// on both `:deps` and `:deps-dev` traversals, the `caixa-resolver`
2470 /// pipeline's `HashSet<String>` seen-set the closure walker gates
2471 /// requeueing off (`caixa-resolver/src/resolve.rs:55`), the resolver's
2472 /// per-transitive-target requeue path (`resolve.rs:63,66`), the
2473 /// [`crate::DepSource::default_github`]-shaped resolver-side shorthand
2474 /// fill-in that folds `:nome` into the fetched-git-URL (`resolve.rs:147`),
2475 /// every `caixa-resolver` `ResolveError::MissingPath` /
2476 /// `ResolveError::MissingPin` carrier that names the offending dep
2477 /// (`resolve.rs:177,206`), each resolved
2478 /// `caixa-lacre::LacreEntry` `nome:` field the closure hash keys off
2479 /// (`resolve.rs:108,113`), and the peer `feira lock` stub-resolver's
2480 /// `LacreEntry` emitter (`caixa-feira/src/cmd/lock.rs:59,61,64`).
2481 ///
2482 /// Prior to this lift the `.nome` byte-string was read inline at every
2483 /// production site — the [`crate::Caixa::validate_deps`] paired
2484 /// `dep.nome.as_str()` / `dep.nome.clone()` accesses on both `:deps`
2485 /// and `:deps-dev` traversals, the [`validate_no_self_dep`] pair of
2486 /// parent-equality checks, and every caixa-resolver / caixa-feira
2487 /// site enumerated above — open-coded field-accesses that expressed
2488 /// no compile-time link back to the typed slot. A future extension of
2489 /// the `:deps :nome` axis to a richer author surface (a per-scope
2490 /// alias table the resolver folds through the `~/.config/caixa/config.yaml`
2491 /// entry the [`crate::dep::Dep`] docstring already acknowledges, a
2492 /// namespace-qualified rewrite the future M4 lacre-federation layer
2493 /// applies per-cluster, a promotion of the plain [`String`] byte-string
2494 /// to a richer scoped-identifier newtype once cross-registry federation
2495 /// lands) would have had to be threaded through every open-coded copy
2496 /// in lockstep or two consumers would silently disagree on which caixa
2497 /// a given dep resolves to — the [`crate::Caixa::validate_deps`] dedup
2498 /// set treating the name as `"caixa-teia"` while the caixa-resolver
2499 /// closure walker treated it as `"tenant-a/caixa-teia"` would silently
2500 /// split the [`DepError::DuplicateNome`] refusal from the resolver's
2501 /// requeue-suppression seen-set, one build-time diagnostic
2502 /// disagreeing with the run-time closure the substrate's lacre
2503 /// pipeline actually materializes. Lifting the resolution rule to a
2504 /// typed method on the substrate primitive means every downstream
2505 /// consumer of the caixa's per-`:deps` identity surface reaches for
2506 /// exactly one typed dispatch — the resolver's accept-set migrates as
2507 /// a unit on any future axis addition.
2508 ///
2509 /// First accessor on the outer `Dep` type — opens the outer-`Dep`
2510 /// `&str`-return required-scalar projection pattern the sibling
2511 /// per-`Dep` `:versao` future lift folds on. Peer of the sibling
2512 /// per-`:membros` [`crate::Membro::nome`] (4a32abf) /
2513 /// per-`:children` [`crate::supervisor::ChildSpec::nome`] (dfb4a81)
2514 /// / top-level [`crate::Caixa::nome`] (e6b7d97) caixa-identity scalar
2515 /// accessors — same "one typed dispatch on the substrate primitive,
2516 /// thin projections at each consumer" discipline extended onto the
2517 /// third named-caixa-referencing axis (`:deps` / `:deps-dev`), the
2518 /// remaining unlifted caixa-name-referencing accessor family in the
2519 /// substrate. Named `nome()` to match the tatara-lisp author-surface
2520 /// term the field's docstring already reaches for ("Caixa name — must
2521 /// match the target caixa's `:nome`") and the peer caixa-identity
2522 /// accessor family the substrate already carries.
2523 #[must_use]
2524 pub const fn nome(&self) -> &str {
2525 self.nome.as_str()
2526 }
2527
2528 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:versao`
2529 /// Cargo-shaped semver-requirement scalar accessor every consumer of
2530 /// the dep-graph version-pin axis keys off — returns the author-
2531 /// declared `:versao` requirement byte-string verbatim as a `&str`,
2532 /// borrowed from the typed slot's own [`String`] storage.
2533 ///
2534 /// The `:deps :versao` / `:deps-dev :versao` slot carries the
2535 /// Cargo-shaped semver requirement string (`"^0.1"`, `"~0.1.2"`,
2536 /// `"0.1.0"`, `"*"`) the shared [`crate::version::parse_requirement`]
2537 /// entry-point consumes — same accept-set the peer requirement-
2538 /// carrying axes carry (per-`:membros`
2539 /// [`crate::Membro::versao_requirement`], per-`:children`
2540 /// [`crate::supervisor::ChildSpec::versao_requirement`]), validated
2541 /// through the shared
2542 /// [`crate::render::require_valid_versao_requirement`] cascade in
2543 /// [`Self::validate`]. Every downstream consumer that fans on the
2544 /// dep's version-pin keys off this scalar: the [`Self::validate`]
2545 /// `require_valid_versao_requirement` gate + the paired
2546 /// [`DepError::VersaoInvalid`] carrier the cascade raises on
2547 /// requirement-shape rejection, the `feira lock` stub-resolver's
2548 /// `format!("{}@{}", dep.nome(), dep.versao_requirement())`
2549 /// `conteudo` hash-input interpolation and the paired
2550 /// `LacreEntry.versao:` `String`-carry fill (`caixa-feira/src/cmd/lock.rs`),
2551 /// and the peer `feira lock` end-to-end fixture in `caixa-feira/tests/feira_e2e.rs`.
2552 ///
2553 /// Prior to this lift the `.versao` byte-string was read inline at
2554 /// every production site — the [`Self::validate`] paired
2555 /// `&self.versao` requirement-gate reference and `self.versao.clone()`
2556 /// error-body carrier, the `caixa-feira/src/cmd/lock.rs` paired
2557 /// `format!("{}@{}", dep.nome(), dep.versao)` `conteudo` interpolation
2558 /// and `versao: dep.versao.clone()` `LacreEntry` fill, and the
2559 /// `caixa-feira/tests/feira_e2e.rs` end-to-end fixture's pair of the
2560 /// same shapes — open-coded field-accesses that expressed no
2561 /// compile-time link back to the typed slot. A future extension of
2562 /// the `:deps :versao` axis to a richer author surface (a per-scope
2563 /// version-lock overlay the resolver folds through the
2564 /// `~/.config/caixa/config.yaml` entry the [`crate::dep::Dep`]
2565 /// docstring already acknowledges, a per-cluster canary-version
2566 /// overlay per MESH-COMPOSITION §III.2, a promotion of the plain
2567 /// [`String`] requirement to a richer parsed-`VersionReq` newtype
2568 /// once cross-registry federation lands) would have had to be
2569 /// threaded through every open-coded copy in lockstep or two
2570 /// consumers would silently disagree on which release constraint a
2571 /// given dep resolves to — the [`Self::validate`] requirement-gate
2572 /// call reading `"^0.1"` while the `feira lock` stub-resolver's
2573 /// `conteudo` hash-input read `"tenant-a-pin/^0.1"` would silently
2574 /// split the [`DepError::VersaoInvalid`] refusal from the lacre's
2575 /// content-addressed hash the substrate's fetch pipeline actually
2576 /// materializes, one build-time diagnostic disagreeing with the
2577 /// run-time closure. Lifting the resolution rule to a typed method
2578 /// on the substrate primitive means every downstream consumer of
2579 /// the caixa's per-`:deps` version-pin surface reaches for exactly
2580 /// one typed dispatch — the resolver's accept-set migrates as a
2581 /// unit on any future axis addition.
2582 ///
2583 /// Second accessor on the outer `Dep` type — folds on the outer-
2584 /// `Dep` `&str`-return required-scalar projection pattern the
2585 /// sibling per-`Dep` [`Self::nome`] (eba2cde) accessor opened. Peer
2586 /// of the per-`:membros` [`crate::Membro::versao_requirement`]
2587 /// (a40b0e3) / per-`:children`
2588 /// [`crate::supervisor::ChildSpec::versao_requirement`] (7844f4e
2589 /// family) member/child version-pin accessors — the three
2590 /// requirement-carrying axes (`Dep::versao_requirement` on the
2591 /// per-caixa dep-graph edge, `Membro::versao_requirement` on the M3
2592 /// Aplicacao side, `ChildSpec::versao_requirement` on the M2
2593 /// Supervisor side) now share one accessor discipline for the
2594 /// shared substrate concept "another caixa referenced by a
2595 /// Cargo-shaped semver requirement". The pair
2596 /// `(nome(), versao_requirement())` jointly projects the
2597 /// `(nome, versao)` field pair every dep-graph consumer that fans
2598 /// on per-dep identity + version pin keys off. Named
2599 /// `versao_requirement()` rather than `versao()` because the field's
2600 /// storage-side `.versao` label is already the author-surface term
2601 /// (`:versao`); the accessor's name carries the semantic role — the
2602 /// semver *requirement* string the shared
2603 /// [`crate::version::parse_requirement`] entry-point consumes — so a
2604 /// raw field access and a typed dispatch read differently at every
2605 /// consumer site. Matches the peer
2606 /// [`crate::Membro::versao_requirement`] /
2607 /// [`crate::supervisor::ChildSpec::versao_requirement`] naming
2608 /// discipline verbatim.
2609 #[must_use]
2610 pub const fn versao_requirement(&self) -> &str {
2611 self.versao.as_str()
2612 }
2613
2614 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:fonte`
2615 /// Zig-store-model per-dep source-tuple optional-composite-reference
2616 /// accessor every consumer of the dep-graph fetch-source axis keys
2617 /// off — returns the author-declared `:fonte` typed [`DepSource`]
2618 /// verbatim as an `Option<&DepSource>` borrowed from the typed slot's
2619 /// own `Option<DepSource>` storage, with `None` naming the "author
2620 /// omitted `:fonte`" shorthand every resolver-side default-fill
2621 /// (`caixa-feira/src/cmd/lock.rs`'s stub, `caixa-resolver/src/resolve.rs`'s
2622 /// canonical fetcher, per the [`DepSource::default_github`] fallback
2623 /// the [`Dep::fonte`] field docstring already documents) treats as
2624 /// the "resolve through the configured default host / org
2625 /// (`github:<default-org>/<nome>`)" partition.
2626 ///
2627 /// The `:deps :fonte` / `:deps-dev :fonte` slot carries the two-
2628 /// arm typed [`DepSource`] the `Zig-style git-only store model` the
2629 /// enclosing [`Dep`] docstring names — `DepSource::Git { repo, tag,
2630 /// rev, branch }` for the git-clone arm every published caixa
2631 /// resolves through, `DepSource::Path { caminho }` for the dev-only
2632 /// local-filesystem arm every unpublishable in-tree checkout
2633 /// resolves through. Every downstream consumer that fans on the
2634 /// dep's fetch-source keys off this accessor: [`Self::validate`]'s
2635 /// per-`:fonte` [`DepSource::validate`] delegation (which raises
2636 /// the empty-`:repo` / missing-pin / multiple-pin / empty-`:caminho`
2637 /// diagnostics through the [`DepError::Fonte*`] carrier family
2638 /// naming the offending `Dep::nome`), the caixa-crd conversion
2639 /// crate's `dep_into_ref` two-arm projection into the `CaixaSource`
2640 /// `{repo, git_ref}` pair the K8s-CR side consumes
2641 /// (`caixa-crd/src/conversion.rs`), and — through the paired
2642 /// resolver-side default-fill's `Option::unwrap_or_else` — every
2643 /// `caixa-feira` / `caixa-resolver` fetch site that requires a
2644 /// concrete `DepSource` at run time.
2645 ///
2646 /// Prior to this lift the `.fonte` typed slot was read inline at
2647 /// every production site — the [`Self::validate`]
2648 /// `if let Some(ref fonte) = self.fonte` bracket the per-`:fonte`
2649 /// gate delegates through, the caixa-crd `dep_into_ref`
2650 /// `d.fonte.as_ref().and_then(...)` two-arm `CaixaSource` projector,
2651 /// the resolver-side `caixa-feira/src/cmd/lock.rs` / `caixa-resolver/src/resolve.rs`
2652 /// `dep.fonte.clone().unwrap_or_else(...)` default-fill pair — open-
2653 /// coded field-accesses that expressed no compile-time link back to
2654 /// the typed slot. A future extension of the `:deps :fonte` axis
2655 /// to a richer author surface (a per-scope source-override table
2656 /// the resolver folds through the `~/.config/caixa/config.yaml`
2657 /// entry the [`Dep`] docstring already acknowledges, a per-org
2658 /// mirror-fallback list the future M4 lacre-federation resolver
2659 /// consults ahead of the `default_github` fallback, a promotion of
2660 /// the plain `Option<DepSource>` to a richer
2661 /// `{primary, mirrors, integrity}` triple once cross-registry
2662 /// federation lands, a per-dep `sri:sha256-…` integrity slot the
2663 /// M4 lacre gate binds against ahead of the git-fetch) would have
2664 /// had to be threaded through every open-coded copy in lockstep or
2665 /// two consumers would silently disagree on which fetch source a
2666 /// given dep resolves to — the [`Self::validate`] per-`:fonte`
2667 /// gate reading the author-declared source while the caixa-crd
2668 /// projector read a per-scope-override-resolved source would
2669 /// silently split the build-time refusal from the CR the
2670 /// substrate's admission pipeline actually materializes, one
2671 /// build-time diagnostic disagreeing with the run-time closure.
2672 /// Lifting the resolution rule to a typed method on the substrate
2673 /// primitive means every downstream consumer of the caixa's per-
2674 /// `:deps` fetch-source surface reaches for exactly one typed
2675 /// dispatch — the resolver's accept-set migrates as a unit on any
2676 /// future axis addition.
2677 ///
2678 /// First outer-`Dep` `Option<&Composite>`-return composite-reference
2679 /// accessor — opens the outer-`Dep` `Option<&Composite>` composite-
2680 /// reference projection pattern the sibling per-`Dep` `:opcional`
2681 /// (`Option<Copy>` — the plain-bool axis) / `:caracteristicas`
2682 /// (`&[String]` — the feature-flag list) future outer scalar / slice
2683 /// lifts fold on. Peer of the outer-top-level [`crate::Caixa`]
2684 /// `Option<&Composite>` composite-reference sub-family the
2685 /// [`crate::Caixa::limits`] (b2bd9d7) / [`crate::Caixa::behavior`]
2686 /// (35d8b52) / [`crate::Caixa::politicas`] (5d23d29) /
2687 /// [`crate::Caixa::placement`] (4fb8074) / [`crate::Caixa::entrada`]
2688 /// (e4128e4) accessors already close on the outer [`crate::Caixa`]
2689 /// altitude, and of the outer M3 mesh-slot [`crate::AplicacaoSpec`]
2690 /// altitude the sibling [`crate::AplicacaoSpec::entrada`] (d32111c)
2691 /// accessor already carries — extends that "one typed dispatch on
2692 /// the substrate primitive, thin projections at each consumer"
2693 /// discipline onto the third outer typed-slot altitude that carries
2694 /// an `Option<Composite>` axis (`Dep`, the outer per-dep-list-entry
2695 /// slot). Returns `Option<&DepSource>` (not the owning composite by
2696 /// copy or clone) because every downstream consumer of the fonte
2697 /// composite treats it as a read-only per-arm dispatch source — the
2698 /// reference-view is the narrowest borrow that supports every
2699 /// present + roadmapped consumer (per-arm match projection at the
2700 /// caixa-crd `CaixaSource` two-arm emitter, presence-probe early
2701 /// return on the "author-omitted `:fonte` ⇒ resolver-side
2702 /// `default_github` fill applies" partition every resolver
2703 /// consults, `.cloned()`-on-demand for the two resolver-side
2704 /// default-fill call sites that require an owned `DepSource` for
2705 /// `Option::unwrap_or_else`) without cloning the composite through
2706 /// every consumer's fast path. The `Option` half of the return-type
2707 /// preserves the load-bearing "author-omitted `:fonte` ⇒ resolver-
2708 /// side default applies" partition (not a default composite the
2709 /// downstream must reject on emptiness) — the accessor projects the
2710 /// raw `Option<DepSource>` slot's presence bit through the
2711 /// reference-return unchanged. Named `fonte()` to match the storage
2712 /// field's name verbatim and the tatara-lisp author-surface term
2713 /// (`:fonte`) the field's own docstring already carries.
2714 ///
2715 /// Declared `pub const fn` — the body projects through
2716 /// `Option::<DepSource>::as_ref`, const-stable since Rust 1.83 and
2717 /// well within the workspace MSRV, so every downstream `const`-
2718 /// context consumer of the per-`Dep` `:fonte` composite-reference
2719 /// accessor reaches through the same typed dispatch on the
2720 /// substrate primitive at const-eval time as at runtime. The
2721 /// paired [`dep_outer_accessor_family_is_const_fn`][pin] pin
2722 /// (a `const fn <name>_via_const_fn(d: &Dep) -> …` wrapper family
2723 /// that forwards through each lifted accessor) locks the posture
2724 /// load-bearing at caixa-core build time — any future accidental
2725 /// downgrade to non-`const` fails the wrapper with E0015
2726 /// (`cannot call non-const method`), strictly stronger than a
2727 /// runtime `assert!` and side-stepping the destructor-in-const
2728 /// restriction the `Dep` fixture's `String` / `Option<DepSource>`
2729 /// / `Vec<String>` carriers rule out. Peer of the sibling per-
2730 /// `WitContract` pre-projection accessor family's `const`-eval-
2731 /// surface pass (279823b) and of the outer-`Caixa` slice-return
2732 /// accessor family's parallel pass (231a968) — same "one canonical
2733 /// dispatch per axis, `const`-eval posture pinned at the substrate
2734 /// primitive, thin projections at each consumer" discipline
2735 /// extended onto the outer per-dep-list-entry [`Dep`] altitude.
2736 ///
2737 /// [pin]: tests::dep_outer_accessor_family_is_const_fn
2738 #[must_use]
2739 pub const fn fonte(&self) -> Option<&DepSource> {
2740 self.fonte.as_ref()
2741 }
2742
2743 /// Substrate-canonical per-`:deps` / `:deps-dev` entry
2744 /// `:caracteristicas` Cargo-shaped feature-toggle-set slice accessor
2745 /// every consumer of the dep-graph feature-flag axis keys off —
2746 /// returns the author-declared `:caracteristicas` feature-name list
2747 /// verbatim as a `&[String]` slice-view over the same backing buffer
2748 /// the raw `self.caracteristicas.as_slice()` field access borrows
2749 /// from. Empty-list-carrying (`:caracteristicas` is a default-empty
2750 /// axis every `Dep` supplies with `Vec::new()` when the author omits
2751 /// the slot; the [`crate::Caixa::from_lisp`] derive folds an omitted
2752 /// `:caracteristicas` through `#[serde(default)]` to `Vec::new()`,
2753 /// so a `Dep` past parse definitionally carries a `Vec<String>` slot
2754 /// — possibly empty — and the returned `&[String]` degenerates to
2755 /// an empty slice on that arm without any silent `None` collapse).
2756 ///
2757 /// The `:deps :caracteristicas` / `:deps-dev :caracteristicas` slot
2758 /// carries the set-shaped feature-toggle list the substrate walks
2759 /// through the [`Self::validate_caracteristicas`] per-entry shape +
2760 /// duplicate cascade — same Cargo `[dependencies.<dep>.features]`
2761 /// accept-set (per-entry Cargo-feature-name grammar via the shared
2762 /// [`crate::render::is_cargo_feature_name`] predicate, cross-entry
2763 /// uniqueness via the shared [`crate::render::insert_first_seen`]
2764 /// walk, empty-first / value-shape-second / duplicate-third
2765 /// precedence via the peer per-axis two-arm cascade discipline every
2766 /// substrate-blessed Vec-keyed-by-name slot already follows).
2767 /// Every downstream consumer that fans on the dep's feature-toggle
2768 /// keys off this accessor: [`Self::validate_caracteristicas`]'s
2769 /// per-entry linear walk that gates each feature-name byte-string
2770 /// through the empty / value-shape / duplicate arms (raising the
2771 /// [`DepError::CaracteristicaEmpty`] / [`DepError::CaracteristicaInvalid`]
2772 /// / [`DepError::CaracteristicaDuplicate`] carrier family naming the
2773 /// offending `Dep::nome`), and every future
2774 /// per-`Caixa`-manifest / caixa-resolver / caixa-crd feature-toggle-
2775 /// facing consumer the CAIXA-SDLC §I roadmap acknowledges (the
2776 /// future caixa-resolver per-dep feature-projection walk that folds
2777 /// the toggle set into the resolved [`crate::Caixa`]'s activated
2778 /// [`crate::render::CARGO_FEATURE_NAME_MAX_LEN`]-bounded feature
2779 /// closure ahead of the lacre hash, the future caixa-crd per-`spec.deps`
2780 /// features slice the K8s-CR admission gate consumes, the future
2781 /// per-cluster feature-overlay the M4 lacre-federation resolver
2782 /// composes ahead of the substrate-wide feature-name accept-set).
2783 ///
2784 /// Prior to this lift the `.caracteristicas` byte-string list was
2785 /// read inline at the [`Self::validate_caracteristicas`] `for c in
2786 /// &self.caracteristicas` walk — the only in-crate consumer of the
2787 /// raw field beyond the per-`Dep` constructor pair
2788 /// ([`Self::simple`] / [`Self::git`]) and the paired serde
2789 /// round-trip / per-test fixture-mutation paths — an open-coded
2790 /// field-access that expressed no compile-time link back to the
2791 /// typed slot. A future extension of the `:caracteristicas` axis to
2792 /// a richer author surface (a per-scope feature-overlay the resolver
2793 /// folds through the `~/.config/caixa/config.yaml` entry the
2794 /// [`Dep`] docstring already acknowledges, a per-cluster feature-
2795 /// activation overlay the future M4 lacre-federation layer applies
2796 /// per-CR, a promotion of the plain `Vec<String>` byte-string list
2797 /// to a richer parsed-feature-set newtype once the Cargo-shaped
2798 /// namespaced-dep `dep/feat` syntax the value-shape gate's
2799 /// docstring anticipates lands) would have had to be threaded
2800 /// through every open-coded copy in lockstep or two consumers
2801 /// would silently disagree on which feature closure a given dep
2802 /// activates — the [`Self::validate_caracteristicas`] gate walking
2803 /// the author-declared list while a downstream caixa-resolver
2804 /// consumer walked a per-scope-override-resolved list would
2805 /// silently split the build-time refusal from the lacre closure
2806 /// the substrate's fetch pipeline actually materializes, one
2807 /// build-time diagnostic disagreeing with the run-time closure.
2808 /// Lifting the resolution rule to a typed method on the substrate
2809 /// primitive means every downstream consumer of the caixa's per-
2810 /// `:deps` feature-toggle surface reaches for exactly one typed
2811 /// dispatch — the resolver's accept-set migrates as a unit on any
2812 /// future axis addition.
2813 ///
2814 /// First outer-`Dep` `&[T]`-return slice accessor — opens the
2815 /// outer-`Dep` `&[String]` slice projection pattern the sibling
2816 /// per-`Dep` `:opcional` (`bool` — the plain-`Copy`-scalar axis)
2817 /// future outer scalar lift folds on and closes the outer-`Dep`
2818 /// slot-family the sibling [`Self::nome`] (eba2cde) /
2819 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2820 /// accessors already open, leaving the `:opcional` `Copy`-scalar arm
2821 /// as the sole remaining unlifted outer-`Dep` slot. Peer of the
2822 /// outer top-level [`crate::Caixa`] `&[String]`-return foreign-code-
2823 /// slot sub-family ([`crate::Caixa::bibliotecas`] 8a36c23,
2824 /// [`crate::Caixa::exe`] 65d9527, [`crate::Caixa::servicos`]
2825 /// 611f78b) and the outer top-level [`crate::Caixa`] universal-axis
2826 /// text-tag family ([`crate::Caixa::autores`] b5d813f,
2827 /// [`crate::Caixa::etiquetas`] 78c7d3c) that already carry the
2828 /// `&[String]` slice-projection discipline on the outer-`Caixa`
2829 /// altitude — extends the "one typed dispatch on the substrate
2830 /// primitive, thin projections at each consumer" discipline onto the
2831 /// outer per-dep-list-entry [`Dep`] altitude's set-shaped byte-
2832 /// string list slot. Returns `&[String]` (not `&Vec<String>`)
2833 /// because every downstream consumer of the feature-toggle list
2834 /// treats it as a read-only sequence — the slice-view is the
2835 /// narrowest borrow that supports every present + roadmapped
2836 /// consumer (`.iter()`, `.len()`, `.is_empty()`) without leaking
2837 /// the backing `Vec`'s grow/push/reserve surface no consumer of
2838 /// the typed view reaches for (the storage-side `Vec` remains
2839 /// reachable through the `pub caracteristicas` field for the
2840 /// mutation-carrying serde round-trip and per-test fixture-mutation
2841 /// paths). Named `caracteristicas()` to match the storage field's
2842 /// name verbatim and the tatara-lisp author-surface term
2843 /// (`:caracteristicas`) the field's own docstring already carries.
2844 ///
2845 /// Declared `pub const fn` — the body projects through
2846 /// `Vec::<String>::as_slice`, const-stable since Rust 1.83 and
2847 /// well within the workspace MSRV, so every downstream `const`-
2848 /// context consumer of the per-`Dep` `:caracteristicas` slice-
2849 /// accessor reaches through the same typed dispatch on the
2850 /// substrate primitive at const-eval time as at runtime. Pinned
2851 /// load-bearing by the paired
2852 /// [`dep_outer_accessor_family_is_const_fn`][pin] wrapper family
2853 /// alongside its sibling [`Self::fonte`] — see [`Self::fonte`] for
2854 /// the full pin-shape rationale.
2855 ///
2856 /// [pin]: tests::dep_outer_accessor_family_is_const_fn
2857 #[must_use]
2858 pub const fn caracteristicas(&self) -> &[String] {
2859 self.caracteristicas.as_slice()
2860 }
2861
2862 /// Substrate-canonical per-`:deps` / `:deps-dev` entry `:opcional`
2863 /// missing-source-tolerance flag scalar accessor every consumer of
2864 /// the dep-graph opt-in-fetch axis keys off — returns the author-
2865 /// declared `:opcional` `bool` verbatim, `Copy`-projected from the
2866 /// typed slot's own `bool` storage (no borrow of `&self` past the
2867 /// call; the `Copy`-return arm matches the peer
2868 /// [`crate::Caixa::max_restarts`] (eba5211) `Option<u32>` `Copy`-
2869 /// projected sibling discipline the outer flat-spread family
2870 /// already carries). Default-`false` (`#[serde(default,
2871 /// skip_serializing_if = "is_false")]` on the storage slot, so a
2872 /// `Dep` past parse definitionally carries a `bool` — `false` when
2873 /// the author omits `:opcional` — and the returned value degenerates
2874 /// to `false` on that arm without any silent `None` collapse).
2875 ///
2876 /// The `:deps :opcional` / `:deps-dev :opcional` slot carries the
2877 /// per-entry "if this dep's `:fonte` cannot be resolved, treat the
2878 /// missing-source arm as a soft-fail rather than a build refusal"
2879 /// bit — the same Cargo-shaped `[dependencies.<dep>.optional = true]`
2880 /// accept-set (an opcional dep whose `:fonte` fails to resolve is
2881 /// dropped from the resolved dep-graph rather than tripping the
2882 /// build-refusal edge that a mandatory `:opcional false` entry
2883 /// would). Every downstream consumer that fans on the dep's
2884 /// missing-source-tolerance keys off this accessor: the future
2885 /// caixa-resolver's per-`:fonte` resolve-fail arm (drop-vs-error
2886 /// dispatch on the opcional bit ahead of the lacre closure
2887 /// materialization), the future caixa-crd per-`spec.deps`
2888 /// `optional` boolean the K8s-CR admission gate consumes on the
2889 /// per-dep partition, and the future feira / caixa-resolver /
2890 /// caixa-crd feature-projection walk that folds the opcional bit
2891 /// into the resolved feature-closure the future M4 lacre-federation
2892 /// layer emits.
2893 ///
2894 /// Prior to this lift the `.opcional` `bool` slot was read inline
2895 /// at the sole in-crate consumer site — the tests-module
2896 /// `registry_dep_is_minimal` fixture's `assert!(!d.opcional)` gate
2897 /// pinning the [`Self::simple`] constructor's default-`false` fill
2898 /// (the only in-crate read of the raw field beyond the per-`Dep`
2899 /// constructor pair [`Self::simple`] / [`Self::git`] and the paired
2900 /// serde round-trip / per-test fixture-mutation paths) — an open-
2901 /// coded field-access that expressed no compile-time link back to
2902 /// the typed slot. A future extension of the `:opcional` axis to a
2903 /// richer author surface (a per-scope opcional-override the resolver
2904 /// folds through the `~/.config/caixa/config.yaml` entry the [`Dep`]
2905 /// docstring already acknowledges, a per-cluster opcional-override
2906 /// the future M4 lacre-federation layer applies per-CR, a promotion
2907 /// of the plain `bool` to a richer `OpcionalPolicy { drop, warn,
2908 /// error }` tri-state once the CAIXA-SDLC §II opcional-policy
2909 /// roadmap lands) would have had to be threaded through every open-
2910 /// coded copy in lockstep or two consumers would silently disagree
2911 /// on which missing-source arm a given dep resolves to — the
2912 /// [`Self::simple`] constructor's default-`false` fill reading
2913 /// verbatim while a downstream caixa-resolver consumer read a per-
2914 /// scope-override-resolved bit would silently split the build-time
2915 /// arm from the lacre closure the substrate's fetch pipeline
2916 /// actually materializes, one build-time diagnostic disagreeing
2917 /// with the run-time closure. Lifting the resolution rule to a
2918 /// typed method on the substrate primitive means every downstream
2919 /// consumer of the caixa's per-`:deps` opcional-tolerance surface
2920 /// reaches for exactly one typed dispatch — the resolver's accept-
2921 /// set migrates as a unit on any future axis addition.
2922 ///
2923 /// Fifth and final outer-`Dep` accessor — closes the outer-`Dep`
2924 /// slot-family the sibling per-`Dep` [`Self::nome`] (eba2cde) /
2925 /// [`Self::versao_requirement`] (05529b1) / [`Self::fonte`] (d65d1bf)
2926 /// / [`Self::caracteristicas`] (9197944) accessors opened, so every
2927 /// outer-`Dep` slot (`:nome`, `:versao`, `:fonte`, `:opcional`,
2928 /// `:caracteristicas`) now routes through exactly one typed
2929 /// dispatch on the substrate primitive. First outer-`Dep`
2930 /// `bool`-return / plain-`Copy`-scalar accessor — opens the
2931 /// outer-`Dep` `Copy`-scalar projection pattern that folds on the
2932 /// peer outer-top-level [`crate::Caixa`] `Option<Copy>`
2933 /// flat-spread sub-family ([`crate::Caixa::max_restarts`] eba5211,
2934 /// [`crate::Caixa::estrategia`] ed04d3c) the outer-`Caixa` altitude
2935 /// already carries — extends the "one typed dispatch on the
2936 /// substrate primitive, thin projections at each consumer"
2937 /// discipline onto the outer per-dep-list-entry [`Dep`] altitude's
2938 /// bool-shaped missing-source-tolerance slot. Returns `bool` by
2939 /// `Copy` (not by `&bool` reference) because `bool` is `Copy` and
2940 /// every downstream consumer treats it as a plain discriminant
2941 /// value — the by-value return is the narrowest return-shape that
2942 /// supports every present + roadmapped consumer (`.then(…)` early
2943 /// return on the resolver-side drop-vs-error partition, direct
2944 /// bool composition with a per-scope-override projector, plain
2945 /// `if dep.opcional() { … }` early return at every future admission
2946 /// gate) without leaking the storage field's `bool`-in-`&self`
2947 /// lifetime the by-value return elides. Marked `pub const fn` so
2948 /// the accessor is `const`-callable — same discipline the peer
2949 /// [`crate::Caixa::max_restarts`] `Option<u32>` `Copy`-return
2950 /// accessor carries. Named `opcional()` to match the storage
2951 /// field's name verbatim and the tatara-lisp author-surface term
2952 /// (`:opcional`) the field's own docstring already carries.
2953 #[must_use]
2954 pub const fn opcional(&self) -> bool {
2955 self.opcional
2956 }
2957
2958 /// Build a minimal registry-sourced dep.
2959 #[must_use]
2960 pub fn simple(nome: impl Into<String>, versao: impl Into<String>) -> Self {
2961 Self {
2962 nome: nome.into(),
2963 versao: versao.into(),
2964 fonte: None,
2965 opcional: false,
2966 caracteristicas: Vec::new(),
2967 }
2968 }
2969
2970 /// Build a Git-sourced dep (tag-based).
2971 #[must_use]
2972 pub fn git(
2973 nome: impl Into<String>,
2974 versao: impl Into<String>,
2975 repo: impl Into<String>,
2976 tag: impl Into<String>,
2977 ) -> Self {
2978 Self {
2979 nome: nome.into(),
2980 versao: versao.into(),
2981 fonte: Some(DepSource::Git {
2982 repo: repo.into(),
2983 tag: Some(tag.into()),
2984 rev: None,
2985 branch: None,
2986 }),
2987 opcional: false,
2988 caracteristicas: Vec::new(),
2989 }
2990 }
2991
2992 /// Reject dependency entries whose `:nome` or `:versao` are empty,
2993 /// whose `:nome` is non-empty but not a valid DNS-1123 label,
2994 /// or whose `:versao` is non-empty but not a valid Cargo-shaped
2995 /// semver requirement.
2996 ///
2997 /// The author surface for `:deps :versao` (and `:deps-dev :versao`)
2998 /// is the same Cargo-shaped requirement string `:membros :versao`
2999 /// (validated at [`crate::AplicacaoSpec::validate`] since 9888b13)
3000 /// and `:children :versao` (validated at
3001 /// [`crate::SupervisorSpec::validate`] since b38ff3a) carry — and
3002 /// the lacre pipeline resolves all three axes through the same
3003 /// [`crate::parse_requirement`] entry-point. Until 2420c44 landed
3004 /// `:deps :versao` was the last `:versao` axis untyped past
3005 /// `Caixa::from_lisp`: a malformed-but-non-empty requirement
3006 /// (`"^bad-version"`, `"^^0.1"`, the canonical git-tag-shape-
3007 /// leaking-into-:versao `"v0.1"` typo, the accidental
3008 /// `"not-a-req"`) silently passed parse and the `semver::Error`
3009 /// surfaced at lacre-resolve time, far from the source
3010 /// caixa.lisp, with no field naming which `:deps` entry carried
3011 /// the typo. The diagnostic [`DepError::VersaoInvalid`] carries
3012 /// the offending entry's `:nome` + the offending `:versao`
3013 /// verbatim + the parser's own wording in `reason`, so the
3014 /// author's grep target is unambiguous.
3015 ///
3016 /// The author surface for `:deps :nome` is the same DNS-1123 label
3017 /// the peer caixa-identifier axes carry — top-level Caixa `:nome`
3018 /// (validated at [`crate::Caixa::validate_nome`] since 6c992f8),
3019 /// `:membros :caixa` (validated at
3020 /// [`crate::AplicacaoSpec::validate_membros`] since 3f9d7a0),
3021 /// `:children :caixa` (validated at
3022 /// [`crate::SupervisorSpec::validate`] since 31bfa43). A `:deps
3023 /// :nome` value flows verbatim through the lacre pipeline as the
3024 /// target caixa's `:nome` (which the gate at the *target* side now
3025 /// rejects if non-DNS-1123) and lands as the rendered caixa's
3026 /// `lareira-<nome>` Helm chart name segment, the per-dep
3027 /// `LABEL_PROGRAM` label value, and the `caixa-resolver`'s
3028 /// `~/.cache/caixa/<org>/<nome>` checkout-directory leaf. Until
3029 /// this gate landed `:deps :nome` was the fourth and last
3030 /// DNS-1123-shaped caixa-identifier axis still untyped past
3031 /// `Caixa::from_lisp`: a syntactically wrong dep name (`"Caixa-
3032 /// Teia"` uppercase — the canonical "I copied the README header"
3033 /// typo; `"caixa_teia"` underscore — the Go module / Python
3034 /// identifier leak; `"caixa-teia."` trailing dot — the FQDN
3035 /// confusion; `"-caixa-teia"` leading hyphen; a 64-byte slug)
3036 /// silently passed parse and surfaced at lacre-resolve time when
3037 /// the resolved target caixa's `:nome` failed *its* DNS-1123 gate
3038 /// — far from the source `:deps` entry, with a diagnostic naming
3039 /// the *target's* `:nome` rather than the dep entry that referenced
3040 /// it. Mirroring the 3f9d7a0 / 31bfa43 / 6c992f8 trajectory through
3041 /// the lifted [`crate::render::is_dns_1123_label`] predicate (the
3042 /// "before its third occurrence" PRIME DIRECTIVE boundary, THEORY.md
3043 /// §I.3.5): every `Dep::nome` past validate is DNS-1123-label-shaped,
3044 /// so every downstream consumer (caixa-resolver's lacre fetch,
3045 /// caixa-helm's `lareira-<nome>` chart name, the future M4 per-dep
3046 /// fan-out emitter) reaches for the name knowing the value is
3047 /// apiserver-valid without re-validating.
3048 ///
3049 /// Empty checks fire first (narrower diagnostic), parse last —
3050 /// same ordering discipline as
3051 /// [`crate::AplicacaoSpec::validate_membros`] and
3052 /// [`crate::SupervisorSpec::validate`]. `parse_requirement("")`
3053 /// returns `Ok(VersionReq::STAR)`, so the empty-`:versao` arm is
3054 /// structurally necessary even with the parse arm in place. The
3055 /// `:nome` shape gate runs after the `:nome` empty gate and before
3056 /// the `:versao` checks so a one-entry caixa.lisp with both wrong
3057 /// sees the name-side diagnostic first (the name is the
3058 /// self-locating axis — without it, the parse diagnostic can't
3059 /// quote `:nome "<bad>"`).
3060 pub fn validate(&self) -> Result<(), DepError> {
3061 if self.nome.is_empty() {
3062 return Err(DepError::NomeEmpty);
3063 }
3064 if let Err(reason) = crate::render::is_dns_1123_label(&self.nome) {
3065 return Err(DepError::NomeInvalid {
3066 nome: self.nome.clone(),
3067 reason,
3068 });
3069 }
3070 // Delegate the empty-first + `parse_requirement` cascade to the
3071 // shared [`crate::render::require_valid_versao_requirement`]
3072 // helper — same two-arm shape the peer
3073 // [`crate::AplicacaoSpec::validate_membros`] on `:membros
3074 // :versao` and [`crate::SupervisorSpec::validate`] on `:children
3075 // :versao` route through, so drift between the three axes'
3076 // accepted requirement sets is structurally impossible and the
3077 // parse-side no-op the empty-first arm closes (semver's empty
3078 // parse yields an implicit `*`) lives in exactly one predicate.
3079 crate::render::require_valid_versao_requirement(
3080 self.versao_requirement(),
3081 || DepError::VersaoEmpty {
3082 nome: self.nome.clone(),
3083 },
3084 |reason| DepError::VersaoInvalid {
3085 nome: self.nome.clone(),
3086 versao: self.versao_requirement().to_string(),
3087 reason,
3088 },
3089 )?;
3090 if let Some(fonte) = self.fonte() {
3091 fonte.validate(&self.nome)?;
3092 }
3093 self.validate_caracteristicas()?;
3094 Ok(())
3095 }
3096
3097 /// Reject per-entry `:caracteristicas` (feature-flag) values that
3098 /// are operationally meaningless. The `:caracteristicas` slot is
3099 /// a set of feature toggles to enable on the target caixa — same
3100 /// shape as Cargo's `[dependencies.<dep>.features]` list — and
3101 /// two structural footguns close here:
3102 ///
3103 /// - empty-string entry (`(:caracteristicas (""))`): the future
3104 /// caixa-resolver lacre pipeline would consume the empty
3105 /// identifier as a no-op feature enable, silently dropping the
3106 /// author's intent far from the source `caixa.lisp`;
3107 /// - duplicate entry within one dep (`(:caracteristicas ("http"
3108 /// "http"))`): the feature-toggle slot is set-shaped (enabling
3109 /// a feature twice has no additional semantic — there is no
3110 /// `feature × 2`), so two entries naming the same feature are
3111 /// a silent miscount, the same set-not-multiset distinction
3112 /// every peer Vec-keyed-by-name axis already closes
3113 /// ([`crate::SupervisorError::DuplicateChildCaixa`] on
3114 /// `:children :caixa`, [`crate::AplicacaoError::MembroDuplicate`]
3115 /// on `:membros :caixa`, [`crate::AplicacaoError::ContratoDuplicate`]
3116 /// on `:contratos`, [`crate::AplicacaoError::PlacementClusterDuplicate`]
3117 /// on `:placement :clusters`, [`crate::AplicacaoError::EntradaPathDuplicate`]
3118 /// on `:entrada :paths`, [`crate::UpgradeError::DuplicateFrom`]
3119 /// on `:upgrade-from :from`, [`crate::UpgradeError::DuplicateLoadModule`]
3120 /// / [`crate::UpgradeError::DuplicateStateChange`] /
3121 /// [`crate::UpgradeError::DuplicateCleanup`] on the within-
3122 /// entry `:upgrade-from` axes, and [`DepError::DuplicateNome`]
3123 /// on the cross-entry `:deps`/`:deps-dev` `:nome` axis the
3124 /// immediate-predecessor 359fba5 closed).
3125 ///
3126 /// Same linear-walk + `HashSet` + first-collision diagnostic shape
3127 /// every peer set-not-multiset gate uses; the empty arm fires
3128 /// before the duplicate arm so an entry with both an empty feature
3129 /// *and* a duplicate of some later feature surfaces the empty-
3130 /// shape diagnostic first (the empty-feature axis is the
3131 /// more-actionable defect since the missing-name renders the
3132 /// duplicate-key arm ambiguous: two `""` entries would both report
3133 /// `caracteristica: ""` with no way to distinguish the offending
3134 /// site). Empty-first cascade discipline mirrors every peer per-
3135 /// entry shape + duplicate gate
3136 /// (`SupervisorSpec::validate`'s `EmptyChildName` before
3137 /// `DuplicateChildCaixa`; `validate_membros`'s `MembroCaixaEmpty`
3138 /// before `MembroDuplicate`).
3139 ///
3140 /// The per-entry value-shape gate (Cargo-feature-name grammar via
3141 /// the lifted [`crate::render::is_cargo_feature_name`] predicate)
3142 /// fires between the empty arm and the duplicate arm — the
3143 /// canonical per-entry-shape-before-cross-entry-uniqueness
3144 /// precedence every peer two-arm + value-shape gate establishes
3145 /// ([`crate::SupervisorSpec::validate`]'s `EmptyChildName` →
3146 /// `ChildCaixaInvalid` → `DuplicateChildCaixa`,
3147 /// [`crate::AplicacaoSpec::validate_membros`]'s `MembroCaixaEmpty`
3148 /// → `MembroCaixaInvalid` → `MembroDuplicate`, [`Dep::validate`]'s
3149 /// `NomeEmpty` → `NomeInvalid` → cross-list `DuplicateNome`).
3150 /// Until the value-shape arm landed `:caracteristicas` accepted
3151 /// every non-empty distinct string — a structurally invalid
3152 /// feature name (`"http feature"` whitespace, `"+http"` the
3153 /// canonical paste-from-`+optional-feature` doc activation-form
3154 /// footgun, `"-flag"` leading hyphen, `".feat"` leading dot,
3155 /// `"http/json"` Cargo's `dep/feat` namespaced-dep syntax that
3156 /// only applies inside list-grammar contexts, `"http,json"`
3157 /// list-separator-belongs-to-the-list-grammar miscomprehension,
3158 /// `"café"` un-percent-encoded non-ASCII silently round-tripping
3159 /// inconsistently across NFC/NFD normalization, the 65-byte
3160 /// paste-from-binary slug) silently passed validate and the
3161 /// failure surfaced at `cargo metadata` time as the
3162 /// `restricted_names::validate_feature_name` parser's rejection,
3163 /// far from the source `caixa.lisp`, with no field naming which
3164 /// `:deps` entry's `:caracteristicas` carried the typo. The
3165 /// lifted predicate makes the Cargo-feature-name-grammar
3166 /// intersection-floor a substrate-level invariant at validate
3167 /// time — same trajectory as the eight peer
3168 /// [`crate::render`] value-shape predicates each typed surface
3169 /// downstream of a structured grammar already follows
3170 /// ([`is_dns_1123_label`](crate::render::is_dns_1123_label),
3171 /// [`is_gateway_api_http_path`](crate::render::is_gateway_api_http_path),
3172 /// [`is_wit_world_ref`](crate::render::is_wit_world_ref),
3173 /// [`is_nats_subject`](crate::render::is_nats_subject),
3174 /// [`is_wasi_keyvalue_slot`](crate::render::is_wasi_keyvalue_slot),
3175 /// [`is_git_ref_name`](crate::render::is_git_ref_name),
3176 /// [`is_git_oid`](crate::render::is_git_oid),
3177 /// [`is_git_repo_url`](crate::render::is_git_repo_url)).
3178 fn validate_caracteristicas(&self) -> Result<(), DepError> {
3179 let mut seen = std::collections::HashSet::new();
3180 for c in self.caracteristicas() {
3181 if c.is_empty() {
3182 return Err(DepError::CaracteristicaEmpty {
3183 nome: self.nome.clone(),
3184 });
3185 }
3186 if let Err(reason) = crate::render::is_cargo_feature_name(c) {
3187 return Err(DepError::CaracteristicaInvalid {
3188 nome: self.nome.clone(),
3189 caracteristica: c.clone(),
3190 reason,
3191 });
3192 }
3193 crate::render::insert_first_seen(&mut seen, c.as_str(), || {
3194 DepError::CaracteristicaDuplicate {
3195 nome: self.nome.clone(),
3196 caracteristica: c.clone(),
3197 }
3198 })?;
3199 }
3200 Ok(())
3201 }
3202}
3203
3204/// Cross-slot coherence gate on the dep-graph axis: no `:deps` or
3205/// `:deps-dev` entry may name the caixa's own `:nome`.
3206///
3207/// A caixa that lists itself as a dep is a degenerate self-edge in the
3208/// lacre closure's dep-graph — the closure is a DAG rooted at the
3209/// caixa's `:nome`, and the caixa-resolver's lacre pipeline traverses
3210/// every `:deps` / `:deps-dev` entry's target by name. A self-dep
3211/// hands the resolver a node that is its own parent: a one-node cycle
3212/// it either rejects mid-traversal far from the source `caixa.lisp`
3213/// (the resolver detecting infinite recursion on the closure walk) or,
3214/// worse, recurses on until it exhausts its stack. Because every
3215/// `:nome` is a globally-unique substrate identity (DNS-1123 label +
3216/// lacre closure root), a dep entry whose `:nome` equals the caixa's
3217/// own `:nome` *is* the caixa itself, not a coincidentally-named peer.
3218///
3219/// Lives outside [`Caixa::validate_deps`] because the dep-list view
3220/// carries the entries but not the parent `:nome`; mirrors the
3221/// cross-slot self-edge gates [`crate::supervisor::validate_no_self_supervision`]
3222/// (ad4abf1) on the `:children :caixa` axis and
3223/// [`crate::aplicacao::validate_no_self_membership`] on the
3224/// `:membros :caixa` axis — the same "an edge from a graph node to
3225/// itself is structurally not a tree/graph edge" discipline, here on
3226/// the third typed-name-graph axis (the dep closure; the supervision
3227/// tree and the Aplicacao membership set were the prior two).
3228///
3229/// Walks `:deps` first then `:deps-dev` so the diagnostic for a caixa
3230/// that self-references on both axes surfaces the `:deps` arm first —
3231/// the load-bearing axis the lacre closure resolves at every build,
3232/// peer with the canonical [`Caixa::validate_deps`] walk order
3233/// (`:deps` → `:deps-dev`).
3234///
3235/// Carries the offending list tag (`":deps"` or `":deps-dev"`)
3236/// verbatim into the diagnostic so the author can grep their
3237/// `caixa.lisp` for the offending block in one edit — same
3238/// `list: &'static str` shape [`DepError::DuplicateNome`] (359fba5)
3239/// uses on the cross-list duplicate-name axis.
3240///
3241/// `Code paths` (`:bibliotecas` / `:exe` / `:servicos`) are the
3242/// substrate-blessed shape for referencing the caixa's *own* code, so
3243/// the diagnostic names them as the corrective surface — every
3244/// legitimate "I want to use code from this caixa" authoring intent
3245/// routes through one of those three slots, not a self-dep.
3246pub fn validate_no_self_dep(
3247 deps: &[Dep],
3248 deps_dev: &[Dep],
3249 parent_nome: &str,
3250) -> Result<(), DepError> {
3251 for dep in deps {
3252 if dep.nome() == parent_nome {
3253 return Err(DepError::DepIsSelf {
3254 nome: parent_nome.to_string(),
3255 list: crate::render::DEP_AUTHOR_KEY_DEPS,
3256 });
3257 }
3258 }
3259 for dep in deps_dev {
3260 if dep.nome() == parent_nome {
3261 return Err(DepError::DepIsSelf {
3262 nome: parent_nome.to_string(),
3263 list: crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3264 });
3265 }
3266 }
3267 Ok(())
3268}
3269
3270/// Closed-set typed enum for the two dep-list author-surface axes every
3271/// top-level [`crate::Caixa`] carries — the runtime-closure `:deps` slot
3272/// (`Prod`) and the dev-only-closure `:deps-dev` slot (`Dev`). Every
3273/// substrate consumer that dispatches on "which of the two dep-lists"
3274/// (the `feira add` mutation head, the future per-cluster dev-closure-
3275/// audit overlay the M4 CR materializer resolves per-CR, the future
3276/// `caixa app graph` per-list dep summary, every future
3277/// `Caixa::push_dep` / `Caixa::deps_by_list` typed-method dispatch a
3278/// caller reaches for) reads through this enum rather than through a
3279/// bare `&'static str` — the closed-set is expressed at the type layer,
3280/// so a future third dep-list axis (a `:deps-build` build-only closure
3281/// once the substrate grows cross-artifact heterogeneous dep-graphs,
3282/// per CAIXA-SDLC §I) is one variant plus one arm per method and the
3283/// compiler enforces exhaustiveness on every consumer's `match` arms.
3284///
3285/// The wire byte-string [`Self::as_str`] returns is the same author-
3286/// surface tag the sibling [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3287/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry — the
3288/// [`DepError::DuplicateNome`] / [`DepError::DepIsSelf`] `list:
3289/// &'static str` payload family the substrate already emits routes
3290/// through the same source of truth (an author reading a
3291/// [`DepError::DuplicateNome`] refusal can grep their `caixa.lisp`
3292/// for the offending `:deps` / `:deps-dev` block in one edit whether
3293/// the diagnostic came from a `Caixa::validate_deps` walk or a
3294/// `Caixa::push_dep` mutation).
3295///
3296/// Same "closed-set typed-enum discriminator with canonical
3297/// projections per axis" discipline the sibling closed-set typed enums
3298/// on the caixa typed surface carry
3299/// ([`crate::aplicacao::PlacementStrategy`] cc8f749,
3300/// [`crate::aplicacao::RateLimitUnit`] 6bce03d,
3301/// [`crate::supervisor::RestartStrategy`],
3302/// [`crate::supervisor::RestartPolicy`],
3303/// [`crate::upgrade::UpgradeInstruction`], [`crate::CaixaKind`])
3304/// — extended onto the outer-`Caixa` two-list dep-graph axis, the
3305/// substrate's last unlifted closed-set-shaped `&'static str`-carrying
3306/// axis on the top-level manifest surface.
3307#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, gen_platform::IsVariant)]
3308pub enum DepList {
3309 /// Runtime-closure `:deps` axis — the load-bearing dep-list the
3310 /// lacre closure resolves at every build. Wire-format
3311 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`].
3312 Prod,
3313 /// Dev-only-closure `:deps-dev` axis — Cargo's `[dev-dependencies]`
3314 /// table's dev-time-only visibility contract per CAIXA-SDLC §I.
3315 /// Wire-format [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`].
3316 Dev,
3317}
3318
3319impl DepList {
3320 /// Exhaustive iteration surface for every consumer that reads the
3321 /// full closed-set (the future M4 admission webhook's per-list
3322 /// summary rejection body, any future round-trip pin harness). A
3323 /// future variant addition extends this slice as a single edit and
3324 /// every consumer picks up the new entry by construction — the
3325 /// compiler-checked exhaustiveness on the sibling method `match`
3326 /// arms is the build-time guarantee that no arm forgets to grow.
3327 pub const ALL: &'static [Self] = &[Self::Prod, Self::Dev];
3328
3329 /// Canonical author-surface tag every substrate consumer that
3330 /// names the offending dep-list in a diagnostic reaches for —
3331 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] for [`Self::Prod`] and
3332 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] for [`Self::Dev`],
3333 /// the same `&'static str` payload the sibling
3334 /// [`DepError::DuplicateNome`] and [`DepError::DepIsSelf`] variants
3335 /// already carry. Routing every dep-list diagnostic through the
3336 /// closed-set enum's `as_str` closes the last `&'static str`-shape
3337 /// literal-carry axis on the two-list dep-graph surface — a
3338 /// future kebab-case rebrand (`":deps"` → `":packages"`) or a
3339 /// wire-format promotion (a distinct diagnostic form for the
3340 /// `Dev` arm) reaches every consumer through one edit on the
3341 /// canonical constant, not a coordinated rewrite across the
3342 /// substrate's dep-graph consumers.
3343 #[must_use]
3344 pub const fn as_str(self) -> &'static str {
3345 match self {
3346 Self::Prod => crate::render::DEP_AUTHOR_KEY_DEPS,
3347 Self::Dev => crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
3348 }
3349 }
3350
3351 /// Substrate-canonical reverse projection on the two-list dep-graph
3352 /// axis — parses the author-surface wire tag back to the typed
3353 /// variant, or `None` when `s` is outside the closed-set arm-string
3354 /// set [`Self::as_str`] emits. Dispatches on the same lifted
3355 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3356 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants the
3357 /// [`Self::as_str`] emitter walks, so the parse and emit halves of
3358 /// the round-trip migrate through one caixa-core edit on any future
3359 /// list-axis addition.
3360 ///
3361 /// Prior to this lift the substrate carried only the forward
3362 /// `Self → &str` projection on the two-list dep-graph axis (the
3363 /// [`Self::as_str`] emitter, the [`std::fmt::Display`] impl routed
3364 /// through it, the two [`DepError::DuplicateNome`] /
3365 /// [`DepError::DepIsSelf`] variants that carry the wire tag verbatim
3366 /// as a `&'static str` `list:` field). Every future consumer that
3367 /// wanted to promote the wire tag back to the typed enum (a future
3368 /// `feira dep --list <deps|deps-dev>` CLI arg-parse that binds the
3369 /// wire form into the typed enum before dispatching to
3370 /// [`crate::Caixa::deps_of`] / [`crate::Caixa::push_dep`], the M4
3371 /// `mesh.pleme.io/v1alpha1/Caixa` CR materializer's admission-time
3372 /// wire re-parse of the per-list diagnostic body, a future
3373 /// [`DepError`] widening that promotes the two `list: &'static str`
3374 /// fields to a typed `list: DepList` carry so downstream consumers
3375 /// dispatch on the enum rather than string-comparing the wire
3376 /// scalar) would have had to re-inline a two-arm `match s { ":deps"
3377 /// => …, ":deps-dev" => …, _ => … }` cascade that expressed no
3378 /// compile-time link back to the typed [`DepList`] enum. A future
3379 /// variant addition (a `:build-dep` or `:test-dep` third list once
3380 /// the substrate grows Cargo-style split-graphs, a `:tool-dep` for
3381 /// build-time-only tooling per the peer Cargo `[build-dependencies]`
3382 /// / `[target.<cfg>.dev-dependencies]` future admission surface)
3383 /// would silently split the wire byte-string the emitter walks from
3384 /// the parser's arm-set — the round-trip would carry the new list
3385 /// through the forward projection but land on the fallback silently
3386 /// at every non-updated reverse parser, far from the arm-addition
3387 /// commit that caused the drift. Lifting the resolver to a typed
3388 /// method on the substrate primitive closes the drift footgun by
3389 /// construction: the parser's accept-set is the same set the
3390 /// [`Self::as_str`] emitter walks (routed through the same lifted
3391 /// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3392 /// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] consts), so both halves
3393 /// of the round-trip migrate through one caixa-core edit on any
3394 /// future list-axis addition.
3395 ///
3396 /// Same closed-set-reverse-projection discipline the sibling
3397 /// [`crate::CaixaKind::from_wire`] (2aa6d23) /
3398 /// [`crate::supervisor::RestartStrategy::from_wire`] (4eec29c) /
3399 /// [`crate::supervisor::RestartPolicy::from_wire`] (dd32ccf) /
3400 /// [`crate::aplicacao::PlacementStrategy::from_wire`] (18c7342) /
3401 /// [`crate::aplicacao::RateLimitUnit::from_suffix`] typed enums
3402 /// carry on the peer wire-side `str → Self` axes — extended onto
3403 /// the two-list dep-graph closed-set axis, the sixth substrate-side
3404 /// closed-set typed enum on the caixa surface to converge on the
3405 /// two-way `str ↔ Self` round-trip. Method-named `from_wire` (not
3406 /// `from_str`) to match the peer shapes verbatim and side-step the
3407 /// derived [`std::str::FromStr`] impls the sibling
3408 /// [`gen_platform::FromStrKind`]-carrying axes install on their
3409 /// kebab-case dispatcher-catalog identity. Returns `Option<Self>`
3410 /// (rather than `Result<Self, _>`) to match the peer shapes: the
3411 /// caller picks the diagnostic form appropriate for its use site —
3412 /// a future `feira dep --list …` arg-parse that surfaces
3413 /// `unknown list: <arg>` at the CLI builds one on top by iterating
3414 /// [`Self::ALL`], while the future M4 admission-webhook's rejection
3415 /// path folds `None` onto its per-CR structured refusal body.
3416 #[must_use]
3417 pub fn from_wire(s: &str) -> Option<Self> {
3418 match s {
3419 crate::render::DEP_AUTHOR_KEY_DEPS => Some(Self::Prod),
3420 crate::render::DEP_AUTHOR_KEY_DEPS_DEV => Some(Self::Dev),
3421 _ => None,
3422 }
3423 }
3424}
3425
3426/// Route [`std::fmt::Display`] through [`DepList::as_str`], so every
3427/// consumer that formats the axis as user-facing text (a future
3428/// `feira app graph` per-list summary, a future M4 admission-webhook
3429/// rejection body naming the offending list, this crate's own
3430/// [`DepError`] `#[error(...)]` templates when they widen to carry a
3431/// typed [`DepList`]) lands on the same author-surface tag the
3432/// [`crate::render::DEP_AUTHOR_KEY_DEPS`] /
3433/// [`crate::render::DEP_AUTHOR_KEY_DEPS_DEV`] constants carry. Same
3434/// as-str-through-Display convergence discipline the sibling
3435/// [`crate::aplicacao::PlacementStrategy`],
3436/// [`crate::aplicacao::RateLimitUnit`],
3437/// [`crate::supervisor::RestartStrategy`],
3438/// [`crate::supervisor::RestartPolicy`], and [`crate::CaixaKind`]
3439/// closed-set typed enums carry.
3440impl std::fmt::Display for DepList {
3441 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3442 f.write_str(self.as_str())
3443 }
3444}
3445
3446/// Errors raised by [`Dep::validate`].
3447///
3448/// Mirrors the per-axis error families the other `:versao`-carrying
3449/// typed surfaces expose
3450/// ([`crate::AplicacaoError::MembroVersaoEmpty`] /
3451/// [`crate::AplicacaoError::MembroVersaoInvalid`],
3452/// [`crate::SupervisorError::EmptyChildVersion`] /
3453/// [`crate::SupervisorError::ChildVersaoInvalid`]) so a future top-
3454/// level `CaixaError` (M4) sums these without reshaping the diagnostic.
3455#[derive(Debug, Error, PartialEq, Eq)]
3456pub enum DepError {
3457 #[error(
3458 ":deps entry has empty :nome (every dep must name a target caixa; \
3459 omit the entry instead of carrying an empty name)"
3460 )]
3461 NomeEmpty,
3462 #[error(
3463 ":deps entry :nome {nome:?} is not a valid DNS-1123 label: {reason} \
3464 (the value flows verbatim as the target caixa's `:nome`, the rendered \
3465 `lareira-<nome>` Helm chart name segment, the `LABEL_PROGRAM` label \
3466 value, and the resolver's checkout-directory leaf — each apiserver-side \
3467 schema rejects non-DNS-1123 names at admission time; use a lowercase \
3468 RFC 1123 label like `\"caixa-teia\"` or `\"pleme-mesh\"`, 1..=63 bytes, \
3469 pattern `^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)"
3470 )]
3471 NomeInvalid { nome: String, reason: String },
3472 #[error(
3473 ":deps entry {nome:?} has empty :versao (every dep must pin a semver \
3474 constraint that resolves through the lacre pipeline)"
3475 )]
3476 VersaoEmpty { nome: String },
3477 #[error(
3478 ":deps entry {nome:?} :versao {versao:?} is not a valid semver \
3479 requirement: {reason} (use Cargo-shaped forms like `\"^0.1\"`, \
3480 `\"~0.1.2\"`, `\"0.1.0\"`, or `\"*\"` — the same shape `:membros :versao` \
3481 and `:children :versao` carry; the lacre pipeline resolves all three \
3482 through the same parser)"
3483 )]
3484 VersaoInvalid {
3485 nome: String,
3486 versao: String,
3487 reason: String,
3488 },
3489 #[error(
3490 ":deps entry {nome:?} :fonte (:tipo git …) has empty :repo \
3491 (every git source must name a repo — use a `github:org/repo` \
3492 shorthand, an `https://…` URL, or an ssh-git URL; omit the \
3493 entire :fonte block to fall back to the default-host resolver \
3494 convention)"
3495 )]
3496 FonteRepoEmpty { nome: String },
3497 #[error(
3498 ":deps entry {nome:?} :fonte (:tipo git …) :repo {repo:?} has \
3499 invalid value-shape: {reason} (the value flows verbatim into the \
3500 caixa-resolver's `git clone <repo>` subprocess invocation; every \
3501 documented form carries a `:` separator and no whitespace / \
3502 control / non-ASCII bytes — use a `github:org/repo` shorthand, \
3503 an `https://host/path` / `ssh://[user@]host/path` / \
3504 `git://host/path` / `file:///path` URL, or the `git@host:path` \
3505 scp-style SSH form)"
3506 )]
3507 FonteRepoShape {
3508 nome: String,
3509 repo: String,
3510 reason: String,
3511 },
3512 #[error(
3513 ":deps entry {nome:?} :fonte (:tipo git …) has no pin set \
3514 (set exactly one of :tag, :rev, or :branch so the resolver \
3515 can pick a reproducible commit; omit the entire :fonte block \
3516 to fall back to the default-host resolver convention, which \
3517 resolves the latest tag matching :versao)"
3518 )]
3519 FontePinMissing { nome: String },
3520 #[error(
3521 ":deps entry {nome:?} :fonte (:tipo git …) has multiple pins \
3522 set ({pins}); exactly one of :tag, :rev, or :branch must be \
3523 set so the resolver's checkout target is unambiguous (the \
3524 resolver's silent precedence is :rev > :tag > :branch — if \
3525 you intended one specifically, drop the others)"
3526 )]
3527 FontePinAmbiguous { nome: String, pins: String },
3528 #[error(
3529 ":deps entry {nome:?} :fonte (:tipo git …) has empty {pin} \
3530 (a set pin must name a non-empty git ref; drop the {pin} key \
3531 entirely to fall through to another pin axis)"
3532 )]
3533 FontePinEmpty { nome: String, pin: String },
3534 #[error(
3535 ":deps entry {nome:?} :fonte (:tipo git …) {pin} {value:?} has invalid \
3536 value-shape: {reason} (the git porcelain enforces the same shape at \
3537 `git fetch` / `git checkout` time on every pin; use a leaf refname \
3538 like `\"v0.1.0\"` for `:tag` or `\"main\"` / `\"feature/foo\"` for \
3539 `:branch`, or a full 40/64 lowercase-hex commit OID for `:rev` — \
3540 drop any `refs/heads/` or `refs/tags/` prefix the caixa-resolver \
3541 prepends at clone time, and avoid abbreviated SHAs which are \
3542 ambiguous across repository history)"
3543 )]
3544 FontePinShape {
3545 nome: String,
3546 pin: String,
3547 value: String,
3548 reason: String,
3549 },
3550 #[error(
3551 ":deps entry {nome:?} :fonte (:tipo path …) has empty :caminho \
3552 (every path source must name a non-empty filesystem path; \
3553 omit the entire :fonte block to fall back to the default-host \
3554 resolver convention)"
3555 )]
3556 FonteCaminhoEmpty { nome: String },
3557 #[error(
3558 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} is \
3559 absolute (the lacre pipeline embeds the value verbatim in its \
3560 per-dep content-address `path:{caminho}` at \
3561 caixa-resolver/src/resolve.rs:189, so an absolute path makes the \
3562 BLAKE3 closure differ across machines — defeating the \
3563 reproducibility contract that's load-bearing for CSE; express \
3564 the path relative to the caixa.lisp location, e.g. \
3565 \"../caixa-teia\" for a sibling workspace dep)"
3566 )]
3567 FonteCaminhoAbsolute { nome: String, caminho: String },
3568 #[error(
3569 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3570 with `~` (the leading-tilde is a shell-expansion convention, not a \
3571 POSIX path component — `Path::is_absolute` returns false on it, so \
3572 the b94fd83 absolute-path gate doesn't catch it, but the lacre \
3573 pipeline embeds the value verbatim in its per-dep content-address \
3574 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3575 caixa-resolver folds it through `Path::join` without `~`-expansion, \
3576 so the build looks for a literal `./{caminho}` subdirectory and \
3577 fails at resolve time far from the source caixa.lisp; even worse, a \
3578 future caixa-resolver pass that *does* expand `~` would silently \
3579 re-open the host-layout-leak the b94fd83 absolute gate closes — \
3580 Alice's `~` resolves to `/home/alice`, Bob's to `/home/bob`, two CI \
3581 runners with different `$HOME` layouts resolve to two distinct paths \
3582 for the byte-identical caixa, defeating the THEORY.md §V.2 render-\
3583 determinism contract; express the path relative to the caixa.lisp \
3584 location, e.g. \"../caixa-teia\" for a sibling workspace dep, or \
3585 spell out the full relative path explicitly if a workstation-rooted \
3586 dep is genuinely intended)"
3587 )]
3588 FonteCaminhoTildeExpansion { nome: String, caminho: String },
3589 #[error(
3590 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3591 with `$` (the leading-`$` is a shell-variable-expansion convention, \
3592 not a POSIX path component — `Path::is_absolute` returns false on it \
3593 and the a5c248e tilde gate doesn't catch it, but the lacre pipeline \
3594 embeds the value verbatim in its per-dep content-address \
3595 `path:{caminho}` at caixa-resolver/src/resolve.rs:189 and the \
3596 caixa-resolver folds it through `Path::join` without `$`-expansion, \
3597 so the build looks for a literal `./{caminho}` subdirectory and \
3598 fails at resolve time far from the source caixa.lisp; even worse, a \
3599 future caixa-resolver pass that *does* expand `$VAR` (the canonical \
3600 shell-convention idiom that CI's `${{WORKSPACE}}` paste-idiom \
3601 invites) would silently re-open the host-layout-leak the b94fd83 \
3602 absolute gate closes — Alice's `$HOME` resolves to `/home/alice`, \
3603 Bob's to `/home/bob`, two CI runners with different `${{WORKSPACE}}` \
3604 layouts resolve to two distinct paths for the byte-identical caixa, \
3605 defeating the THEORY.md §V.2 render-determinism contract; express \
3606 the path relative to the caixa.lisp location, e.g. \"../caixa-teia\" \
3607 for a sibling workspace dep, or spell out the full relative path \
3608 explicitly if a workstation-rooted dep is genuinely intended)"
3609 )]
3610 FonteCaminhoVarExpansion { nome: String, caminho: String },
3611 #[error(
3612 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3613 with a space (the leading ASCII space `0x20` is the orthogonal \
3614 paste-from-aligned-doc footgun that silently passes \
3615 `Path::is_absolute` and every prior leading-byte arm — \
3616 `\" ../caixa-teia\"` resolves via `Path::join` to a literal \
3617 `./ ../caixa-teia` subdirectory the resolver fails to find at \
3618 resolve time with a non-self-locating `No such file or directory` \
3619 error far from the source caixa.lisp; the lacre pipeline embeds \
3620 the value verbatim in its per-dep content-address `path:{caminho}` \
3621 at caixa-resolver/src/resolve.rs:189, so byte-divergent / \
3622 semantic-identical caixa values (` ../caixa-teia` vs \
3623 `../caixa-teia`) yield two distinct BLAKE3 closures across two \
3624 workstations whose authors differ only in paste-from-aligned- \
3625 caixa.lisp-doc whitespace habits — the most insidious failure \
3626 mode the typed slot can carry (no error surfaces; the divergence \
3627 is invisible until two machines compare lacres), defeating the \
3628 THEORY.md §V.2 render-determinism contract. The canonical \
3629 paste-from-aligned-`:deps`-block footgun (every `:fonte` form in \
3630 a multi-entry `:deps` block sits at the same column — an author \
3631 selecting `\"<sp><sp><sp>../caixa-teia\"` and pasting it from \
3632 the rendered alignment into a fresh entry preserves the leading \
3633 whitespace verbatim); peer `:fonte :repo` axis already rejects \
3634 leading whitespace via `is_git_repo_url`, `:fonte :tag` / \
3635 `:fonte :branch` via `is_git_ref_name`, `:descricao` via \
3636 `is_chart_description_shape`, `:licenca` via \
3637 `is_spdx_expression_shape`. Drop the leading space; express the \
3638 path as a bare relative single-token like \"../caixa-teia\")"
3639 )]
3640 FonteCaminhoLeadingWhitespace { nome: String, caminho: String },
3641 #[error(
3642 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} starts \
3643 with `-` (the canonical CLI-argument-injection footgun on the \
3644 `:caminho` axis — the lacre pipeline embeds the value verbatim in \
3645 its per-dep content-address `path:{caminho}` at \
3646 caixa-resolver/src/resolve.rs:189 and the caixa-resolver folds it \
3647 through `Path::join` looking for a literal `./{caminho}` \
3648 subdirectory. Every downstream subprocess that consumes the resolved \
3649 path — `git -C {caminho} <verb>`, `terraform -chdir={caminho}`, \
3650 `nix build --path {caminho}`, `find {caminho}`, `stat {caminho}`, \
3651 `cp -r {caminho} …`, `rm -rf {caminho}` — reinterprets a leading-`-` \
3652 value as a CLI flag rather than a positional path when the invocation \
3653 does not carry a `--` argument-list terminator between the flag block \
3654 and the path (the common case at every porcelain entry point). The \
3655 canonical footguns: `:caminho \"-rf\"` (bare short-flag paste), \
3656 `:caminho \"-C\"` (`git -C -C` config-injection paste), \
3657 `:caminho \"--upload-pack=cat /etc/passwd\"` (the canonical long-flag \
3658 CLI-arg-injection vector at every git porcelain entry point that \
3659 consumes a path or URL argument, peer with is_git_repo_url's \
3660 leading-`-` arm on the sibling `:fonte :repo` axis), \
3661 `:caminho \"--config=…\"` (`git -c foo=bar` config-override paste). \
3662 POSIX `std::path::Path` treats a leading `-` as a literal filename \
3663 byte so the resolver folds `\"-rf\"` through `Path::join` and looks \
3664 for a literal `./-rf` subdirectory that fails at resolve time with a \
3665 non-self-locating `No such file or directory` error far from the \
3666 source caixa.lisp — but on any downstream shell-out without `--` the \
3667 reinterpretation is silent and the failure mode is arbitrary-\
3668 argument-injection. Peer arms: `is_git_repo_url` (render.rs:2037) \
3669 rejects leading `-` on `:fonte :repo` for `git clone <repo>` CLI-\
3670 arg-injection; `is_git_ref_name` (render.rs:1381, 5a28454) rejects \
3671 leading `-` on `:fonte :tag` / `:branch` for `git checkout <ref>` \
3672 CLI-arg-injection; `is_dns_1123_label` rejects leading `-` on every \
3673 DNS-1123-shaped axis (top-level Caixa `:nome`, `:membros :caixa`, \
3674 `:children :caixa`, `:deps :nome`, cluster names); \
3675 `is_cargo_feature_name` rejects leading `-` on `:caracteristicas`; \
3676 the feira `init` / `add <nome>` positional gate (868c191) rejects \
3677 leading `-` on the CLI positional itself. Express the path as a bare \
3678 relative single-token like \"../caixa-teia\" — the sibling-workspace \
3679 directory name carries no leading-hyphen semantic, and `./` / `../` \
3680 prefixes structurally partition the leading-byte set to safe values.)"
3681 )]
3682 FonteCaminhoLeadingHyphen { nome: String, caminho: String },
3683 #[error(
3684 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains \
3685 ASCII control byte 0x{byte:02x} (POSIX paths reject NUL `0x00` outright — \
3686 every `std::fs` syscall routes the path through `CString::new` which \
3687 fails with `NulError` at resolve time; the lacre pipeline embeds the \
3688 value verbatim in its per-dep content-address `path:{caminho}` at \
3689 caixa-resolver/src/resolve.rs:189 so a control byte anywhere in the \
3690 value lands in the BLAKE3 closure and breaks the THEORY.md §V.2 render-\
3691 determinism contract — the canonical paste-from-multiline-doc \
3692 (`\\n`/`\\r`), paste-from-aligned-table (`\\t`), or paste-from-binary-\
3693 blob (`0x00`-DEL) footgun every peer single-token-shaped axis \
3694 (`:fonte :repo`, `:fonte :tag`/`:branch`, the Helm chart-string axes) \
3695 already gates against. Express the path as a relative single-line ASCII \
3696 string, e.g. \"../caixa-teia\" for a sibling workspace dep)"
3697 )]
3698 FonteCaminhoControlChar {
3699 nome: String,
3700 caminho: String,
3701 byte: u8,
3702 },
3703 #[error(
3704 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains `\\` \
3705 (POSIX `std::path::Path` treats `\\` as a literal byte inside a single path \
3706 component, so `..\\caixa-teia` is one directory named literally `..\\caixa-teia` — \
3707 not the parent's sibling — and the caixa-resolver folds the value through \
3708 `Path::join` looking for a literal `./{caminho}` subdirectory that fails at \
3709 resolve time with a non-self-locating `No such file or directory` error far \
3710 from the source caixa.lisp; Windows `std::path::Path` treats `\\` as a \
3711 primary path separator equal to `/`, so byte-identical caixa.lisp values \
3712 resolve to two distinct directories across runner OSes — the lacre pipeline \
3713 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3714 caixa-resolver/src/resolve.rs:189, defeating the THEORY.md §V.2 render-\
3715 determinism contract via the cross-host-OS-separator divergence vector. The \
3716 canonical Windows-Explorer `Copy as path` / PowerShell `Get-Location` \
3717 paste-idiom footgun; peer `:fonte :tag` / `:fonte :branch` axis already \
3718 rejects `\\` via `is_git_ref_name` for the same Windows-path-leak reason, \
3719 and `:entrada :paths` rejects `\\` via `is_gateway_api_http_path`'s eleven-\
3720 byte RFC-3986-reserved set. Express the path with `/` as the separator, e.g. \
3721 \"../caixa-teia\" for a sibling workspace dep)"
3722 )]
3723 FonteCaminhoBackslash { nome: String, caminho: String },
3724 #[error(
3725 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3726 redirection metacharacter 0x{byte:02x} `{ch}` (every interactive shell — bash / \
3727 zsh / fish / nushell — lexes `<` and `>` as input / output redirection \
3728 operators, so `:caminho \"../caixa-teia>build.log\"` is the canonical \
3729 paste-from-shell-pipeline footgun where an author copies a `command > log` \
3730 tail without trimming the redirect; POSIX `std::path::Path` treats both bytes \
3731 as literal path-component bytes, so the resolver folds the value through \
3732 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3733 subdirectory and fails at resolve time with a non-self-locating `No such \
3734 file or directory` error far from the source caixa.lisp. The lacre pipeline \
3735 embeds the value verbatim in its per-dep content-address `path:{caminho}` at \
3736 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure \
3737 and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3738 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3739 canonical CRLF-at-subprocess-argument / shell-metachar injection surface every \
3740 peer single-token-shaped typed slot already closes. The peer `:fonte :tag` / \
3741 `:fonte :branch` axis already rejects `<` / `>` via `is_git_ref_name`, and \
3742 `:entrada :paths` rejects them via `is_gateway_api_http_path`'s eleven-byte \
3743 RFC-3986-reserved set. Express the path as a bare relative single-token like \
3744 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3745 redirection semantic.",
3746 ch = *byte as char
3747 )]
3748 FonteCaminhoShellRedirection {
3749 nome: String,
3750 caminho: String,
3751 byte: u8,
3752 },
3753 #[error(
3754 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-pipe \
3755 metacharacter `|` (every interactive shell — bash / zsh / fish / nushell — lexes \
3756 `|` as the pipe operator that wires one command's stdout to the next command's \
3757 stdin, so `:caminho \"../caixa-teia | grep foo\"` is the canonical paste-from-\
3758 shell-history footgun where an author copies a `ls ../caixa-teia | grep` line \
3759 without trimming the pipeline tail, and `:caminho \"../foo||bar\"` is the \
3760 symmetric `cmd-a || cmd-b` short-circuit-OR paste shape; POSIX `std::path::Path` \
3761 treats `|` as a literal path-component byte, so the resolver folds the value \
3762 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3763 subdirectory and fails at resolve time with a non-self-locating `No such file or \
3764 directory` error far from the source caixa.lisp. The lacre pipeline embeds the \
3765 value verbatim in its per-dep content-address `path:{caminho}` at caixa-resolver/\
3766 src/resolve.rs:189, so the byte lands in the BLAKE3 closure and rides into every \
3767 shell-spawned subprocess (the resolver's `git clone`, a future `feira tofu` \
3768 shell-out, a future operator-side `nix` spawn) as the canonical CRLF-at-\
3769 subprocess-argument / shell-metachar injection surface every peer single-token-\
3770 shaped typed slot already closes. The peer `:entrada :paths` axis rejects `|` \
3771 via `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3772 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3773 workspace directory name carries no shell-pipe semantic."
3774 )]
3775 FonteCaminhoShellPipe { nome: String, caminho: String },
3776 #[error(
3777 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3778 command-separator metacharacter `;` (every interactive shell — bash / zsh / fish \
3779 / nushell — lexes `;` as the sequential-command terminator that fires the next \
3780 command regardless of the prior command's exit status, so `:caminho \
3781 \"../caixa-teia; rm -rf build\"` is the canonical paste-from-shell-one-liner \
3782 footgun where an author copies a `cd path; do-thing` chain without trimming \
3783 the cleanup tail, and `:caminho \"../foo;;bar\"` is the symmetric POSIX `case` \
3784 arm `;;` terminator paste shape; POSIX `std::path::Path` treats `;` as a \
3785 literal path-component byte, so the resolver folds the value through \
3786 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
3787 subdirectory and fails at resolve time with a non-self-locating `No such file \
3788 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
3789 the value verbatim in its per-dep content-address `path:{caminho}` at \
3790 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3791 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3792 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the \
3793 canonical shell-metachar injection surface every peer single-token-shaped \
3794 typed slot already closes. The peer `:entrada :paths` axis rejects `;` via \
3795 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the \
3796 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
3797 workspace directory name carries no shell-command-separator semantic."
3798 )]
3799 FonteCaminhoShellSemicolon { nome: String, caminho: String },
3800 #[error(
3801 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3802 background / list-AND metacharacter `&` (every interactive shell — bash / zsh \
3803 / fish / nushell — lexes `&` two ways: single `&` as the background-task \
3804 terminator detaching the prior command and returning control immediately to \
3805 the prompt, double `&&` as the logical-AND list operator firing the next \
3806 command only if the prior succeeded; POSIX `std::path::Path` treats it as a \
3807 literal byte. The canonical paste-from-shell-prompt footgun is a `cd path & \
3808 sleep 1` background-launch one-liner or a `cd path && make install` build-\
3809 chain idiom selected whole into the `:caminho` slot — the prior `;` arm at \
3810 05c358e closed the sequential-command-separator vector, this arm closes the \
3811 orthogonal background-task / logical-AND vector on the same paste-from-shell-\
3812 prompt class. The lacre pipeline embeds the value verbatim in its per-dep \
3813 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
3814 byte lands in the BLAKE3 closure and rides into every shell-spawned \
3815 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3816 future operator-side `nix` spawn) as the canonical shell-metachar injection \
3817 surface every peer single-token-shaped typed slot already closes. The peer \
3818 `:entrada :paths` axis rejects `&` via `is_gateway_api_http_path`'s eleven-\
3819 byte RFC-3986-reserved set. Express the path as a bare relative single-token \
3820 like \"../caixa-teia\" — the sibling-workspace directory name carries no \
3821 shell-background / logical-AND semantic."
3822 )]
3823 FonteCaminhoShellBackground { nome: String, caminho: String },
3824 #[error(
3825 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3826 command-substitution metacharacter `` ` `` (every POSIX shell — sh / bash / zsh / \
3827 dash / ksh / fish / nushell — lexes the byte as the legacy command-substitution \
3828 wrapper that runs the enclosed command and substitutes its standard-output \
3829 verbatim into the surrounding word, so a backticked `whoami` expands to the \
3830 current user's name and a backticked `cat /etc/passwd` expands to the file's \
3831 contents — the canonical CWE-78 shell-command-injection vector; POSIX \
3832 `std::path::Path` treats the byte as a literal path-component byte. The canonical \
3833 paste-from-shell-prompt footgun is a `cd ../path/<backtick>whoami<backtick>` legacy substitution \
3834 one-liner or a `cd <backtick>pwd<backtick>/path` working-directory expansion idiom selected whole \
3835 into the `:caminho` slot — the prior `&` arm at e12e4f3 closed the shell-\
3836 background / logical-AND vector, this arm closes the orthogonal command-\
3837 substitution vector on the same paste-from-shell-prompt class (the modern `$()` \
3838 form is gated at leading position by the f4efe9c `FonteCaminhoVarExpansion` arm; \
3839 the legacy backtick form is the orthogonal axis). The lacre pipeline embeds the \
3840 value verbatim in its per-dep content-address `path:{caminho}` at \
3841 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
3842 rides into every shell-spawned subprocess (the resolver's `git clone`, a future \
3843 `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3844 shell-metachar injection surface every peer single-token-shaped typed slot \
3845 already closes. The peer `:entrada :paths` axis rejects the byte via \
3846 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. Express the path \
3847 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3848 directory name carries no shell-command-substitution semantic."
3849 )]
3850 FonteCaminhoShellCommandSubstitution { nome: String, caminho: String },
3851 #[error(
3852 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3853 glob / pathname-expansion metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — \
3854 sh / bash / zsh / dash / ksh / fish / nushell — lexes `*` and `?` as pathname-\
3855 expansion wildcards: `*` matches any sequence of characters in a path component \
3856 and `?` matches exactly one character, so a `:caminho \"../caixa-teia/*\"` is the \
3857 canonical paste-from-shell-listing footgun where an author copies a \
3858 `ls ../caixa-teia/*` listing without trimming the wildcard, and `:caminho \
3859 \"../foo?\"` is the symmetric single-char-wildcard paste shape; POSIX \
3860 `std::path::Path` treats both bytes as literal path-component bytes, so the \
3861 resolver folds the value through `Path::new(caminho).join(<file>)` looking for \
3862 a literal `./{caminho}` subdirectory and fails at resolve time with a non-self-\
3863 locating `No such file or directory` error far from the source caixa.lisp. The \
3864 lacre pipeline embeds the value verbatim in its per-dep content-address \
3865 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the \
3866 BLAKE3 closure and rides into every shell-spawned subprocess (the resolver's \
3867 `git clone`, a future `feira tofu` shell-out, a future operator-side `nix` \
3868 spawn) as the canonical shell-metachar / glob-expansion surface every peer \
3869 single-token-shaped typed slot already closes. The peer `:entrada :paths` axis \
3870 rejects `*` and `?` via `is_gateway_api_http_path`'s eleven-byte RFC-3986-\
3871 reserved set. Express the path as a bare relative single-token like \
3872 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-glob \
3873 / pathname-expansion semantic.",
3874 ch = *byte as char
3875 )]
3876 FonteCaminhoShellGlob {
3877 nome: String,
3878 caminho: String,
3879 byte: u8,
3880 },
3881 #[error(
3882 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3883 subshell-grouping metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / \
3884 zsh / dash / ksh / fish / nushell — lexes `(` and `)` as the subshell-grouping \
3885 operator: `(<cmd>)` runs `<cmd>` in a child shell with a fresh environment scope \
3886 (the canonical `(cd <path> && <cmd>)` shell-history one-liner scopes a `cd` to one \
3887 subshell without disturbing the parent's working directory), and `$(<cmd>)` is the \
3888 modern Bourne command-substitution shape the leading-`$` `FonteCaminhoVarExpansion` \
3889 arm closes the leading byte of — together the two arms now structurally exclude the \
3890 entire `$(<cmd>)` substitution surface from the typed `:caminho` accepted set. \
3891 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3892 `:caminho \"../caixa-teia/$(date)/build\"` (the canonical paste-from-shell-history \
3893 modern-command-substitution footgun) or `:caminho \"../(cd foo && pwd)/caixa-teia\"` \
3894 (the symmetric subshell-grouping working-directory-probe paste idiom) silently passes \
3895 every prior arm and the resolver folds the value through `Path::new(caminho).join(\
3896 <file>)` looking for a literal subdirectory and fails at resolve time with a non-\
3897 self-locating `No such file or directory` error far from the source caixa.lisp. The \
3898 lacre pipeline embeds the value verbatim in its per-dep content-address `path:\
3899 {caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 \
3900 closure and rides into every shell-spawned subprocess (the resolver's `git clone`, a \
3901 future `feira tofu` shell-out, a future operator-side `nix` spawn) as the canonical \
3902 shell-metachar / subshell-grouping surface every peer single-token-shaped typed slot \
3903 already closes. The peer `:fonte :repo` axis (3b99147) closes the same byte under the \
3904 same shell-subshell-grouping / RFC-3986-sub-delims banner on `is_git_repo_url`, \
3905 together with the leading-`$` `FonteCaminhoVarExpansion` arm closing the leading byte \
3906 of every `$(<cmd>)` shape. Express the path as a bare relative single-token \
3907 like \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
3908 subshell-grouping semantic.",
3909 ch = *byte as char
3910 )]
3911 FonteCaminhoShellSubshellGrouping {
3912 nome: String,
3913 caminho: String,
3914 byte: u8,
3915 },
3916 #[error(
3917 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3918 brace-expansion / URI-Template placeholder metacharacter 0x{byte:02x} `{ch}` \
3919 (every POSIX-derived brace-expanding shell — bash / zsh / ksh / fish — lexes `{{` / \
3920 `}}` as the brace-expansion operator: `{{a,b,c}}` expands to the cross-product of \
3921 comma-separated members and `{{1..10}}` expands to the integer range — the \
3922 canonical `mkdir -p ../{{caixa-teia,caixa-helm,caixa-flux}}` / `cp file{{,.bak}}` \
3923 idiom every shell-history block carries; RFC 6570 reserves the matched pair for \
3924 URI Template placeholders (the canonical `https://{{host}}/{{org}}/{{repo}}` \
3925 substitution shape every OpenAPI / Swagger / Postman / GitHub Octokit client \
3926 library / Helm chart-URL fragment carries) and the Mustache / Handlebars / \
3927 Tera / Jinja2 / Go html/template doubled-brace substitution form every IaC \
3928 templating engine (Helm, Kustomize, Terraform's `${{var}}` cousin) emits. POSIX \
3929 `std::path::Path` treats the byte as a literal path-component byte, so a \
3930 `:caminho \"../{{caixa-teia,caixa-helm}}/build\"` (the canonical paste-from-\
3931 shell-history brace-expansion fan-across-siblings footgun) or `:caminho \"../{{{{org}}}}/\
3932 caixa-teia\"` (the symmetric paste-from-templated-doc URI-Template placeholder \
3933 idiom every README quick-start / OpenAPI spec / Helm chart `home:` field carries) \
3934 silently passes every prior arm and the resolver folds the value through \
3935 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3936 resolve time with a non-self-locating `No such file or directory` error far from \
3937 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its \
3938 per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
3939 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
3940 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a \
3941 future operator-side `nix` spawn) as the canonical shell-metachar / brace-\
3942 expansion / URI-Template-placeholder surface every peer single-token-shaped \
3943 typed slot already closes. The peer `:fonte :repo` axis (42d8f9d) closes the \
3944 same byte pair on `is_git_repo_url` under the same RFC-3986-'delims' / \
3945 RFC-6570-URI-Template / shell-brace-expansion banner. Express the path as a \
3946 bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3947 directory name carries no shell-brace-expansion / URI-Template-placeholder \
3948 semantic; if two siblings actually need pinning, author two separate `:deps` \
3949 entries rather than one brace-expanded `:caminho` value.",
3950 ch = *byte as char
3951 )]
3952 FonteCaminhoShellBraceExpansion {
3953 nome: String,
3954 caminho: String,
3955 byte: u8,
3956 },
3957 #[error(
3958 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3959 bracket-expansion / POSIX glob-character-class / shell-`test`-builtin metacharacter \
3960 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / nushell \
3961 — lexes the bracket pair as the glob character-class operator: `[abc]` matches one of \
3962 `a` / `b` / `c`, `[a-z]` matches any lowercase ASCII letter, `[^x]` negates — the \
3963 canonical `ls *.[ch]` C-source-file glob and `cd ../caixa-[a-z]*` lowercase-sibling \
3964 glob every shell-history block carries; the bracket pair additionally carries the \
3965 POSIX `test` / `[` builtin command (`[ -d ../caixa-teia ] && cd ...` every shell-\
3966 script conditional uses) and bash's `[[ ... ]]` extended-test grammar; beyond shell \
3967 the pair is the TOML inline-array delimiter (`features = [\"a\", \"b\"]` — the \
3968 canonical paste-from-Cargo-manifest cross-idiom-leak vector), the YAML flow-sequence \
3969 delimiter (`paths: [/a, /b]` — the canonical paste-from-values.yaml cross-idiom \
3970 leak), the JSON array delimiter, and the POSIX-ERE / PCRE bracket-expression anchor. \
3971 POSIX `std::path::Path` treats the byte as a literal path-component byte, so a \
3972 `:caminho \"../caixa-[a-z]/build\"` (the canonical paste-from-shell-history glob-\
3973 character-class fan-across-siblings footgun) or `:caminho \"../[caixa-teia]/build\"` \
3974 (the symmetric paste-from-TOML-array / paste-from-YAML-flow-sequence cross-idiom \
3975 leak) silently passes every prior arm and the resolver folds the value through \
3976 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
3977 resolve time with a non-self-locating `No such file or directory` error far from \
3978 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
3979 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
3980 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
3981 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
3982 `nix` spawn) as the canonical shell-metachar / glob-character-class / TOML-array \
3983 surface every peer single-token-shaped typed slot already closes. Express the path \
3984 as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
3985 directory name carries no shell-bracket-expansion / glob-character-class / array-\
3986 literal semantic; if a family of sibling caixas actually needs pinning, author \
3987 separate `:deps` entries rather than one character-class-expanded `:caminho` value.",
3988 ch = *byte as char
3989 )]
3990 FonteCaminhoShellBracketExpansion {
3991 nome: String,
3992 caminho: String,
3993 byte: u8,
3994 },
3995 #[error(
3996 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
3997 quote-grouping / cross-config-DSL string-literal-delimiter metacharacter \
3998 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
3999 nushell — lexes `'` as the strong string-literal delimiter (`'…'` — no expansion) \
4000 and `\"` as the weak string-literal delimiter (`\"…\"` — variable- / command-\
4001 substitution-preserving); the canonical `cd '../caixa-teia'` shell-history idiom \
4002 every path-with-embedded-whitespace paste block carries and the symmetric \
4003 `git clone \"$REPO\"` weak-quoted CI-manifest shape both leak the pair verbatim. \
4004 Beyond shell the pair is the JSON string-literal delimiter (`\"key\": \"value\"` — \
4005 the canonical paste-from-JSON-config cross-idiom-leak vector), the YAML double- \
4006 and single-quoted flow-scalar delimiter (`path: \"../caixa-teia\"` — the canonical \
4007 paste-from-values.yaml / paste-from-K8s-YAML-manifest cross-idiom leak), the TOML \
4008 basic and literal string delimiter (`path = \"../caixa-teia\"` — the canonical \
4009 paste-from-Cargo-manifest cross-idiom leak), the tatara-lisp string-literal \
4010 delimiter itself (`(:caminho \"../caixa-teia\")` — the canonical \"I copied the \
4011 entire `:caminho \"...\"` slot rather than just the string body\" author-surface \
4012 footgun), and RFC 3986 §2.2's `gen-delims` / `sub-delims` grammar which excludes \
4013 both bytes from the `pchar = unreserved / pct-encoded / sub-delims / \":\" / \"@\"` \
4014 production. POSIX `std::path::Path` treats the byte as a literal path-component \
4015 byte, so a `:caminho \"'../caixa-teia'\"` (the canonical paste-from-shell-history \
4016 strong-quoted sibling-workspace path footgun) or `:caminho \"\\\"../caixa-teia\\\"\"` \
4017 (the symmetric weak-quoted paste-from-JSON / paste-from-YAML flow-scalar / paste-\
4018 from-TOML basic-string / paste-from-tatara-lisp string-literal cross-idiom-leak \
4019 shape) silently passes every prior arm and the resolver folds the value through \
4020 `Path::new(caminho).join(<file>)` looking for a literal subdirectory and fails at \
4021 resolve time with a non-self-locating `No such file or directory` error far from \
4022 the source caixa.lisp. The lacre pipeline embeds the value verbatim in its per-dep \
4023 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte \
4024 lands in the BLAKE3 closure and rides into every shell-spawned subprocess (the \
4025 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-side \
4026 `nix` spawn) as the canonical shell-metachar / string-literal-delimiter surface \
4027 every peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4028 axis closes both bytes under the same shell-quote-grouping / RFC-3986-sub-delims \
4029 banner (e7a109f `'` shell-single-quote + 4267d8b `\"` shell-double-quote on \
4030 `is_git_repo_url`). Express the path as a bare relative single-token like \
4031 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-quote-\
4032 grouping / string-literal-delimiter semantic; strip the outer quote pair from the \
4033 paste (the tatara-lisp `:caminho \"...\"` slot already carries the string-literal \
4034 quoting on the outer syntactic layer, so an inner quote pair would nest and \
4035 desugar to a broken layer).",
4036 ch = *byte as char
4037 )]
4038 FonteCaminhoShellQuoteGrouping {
4039 nome: String,
4040 caminho: String,
4041 byte: u8,
4042 },
4043 #[error(
4044 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4045 comment / URL-fragment-identifier / YAML-comment cross-config-DSL metacharacter \
4046 0x{byte:02x} `{ch}` (every POSIX shell — sh / bash / zsh / dash / ksh / fish / \
4047 nushell — lexes an unquoted `#` at the head of a word or after unquoted \
4048 whitespace as the comment-lead per POSIX.1-2017 §2.3 Token Recognition step 6, \
4049 discarding the byte and everything after it to the end of the physical line \
4050 before command parsing (`cd ../caixa-teia # legacy sibling` — the canonical \
4051 paste-from-shell-history-with-trailing-annotation shape every operator-notebook \
4052 and CI-manifest carries); YAML 1.2 §6.6 makes `#` the comment-lead at any \
4053 position preceded by whitespace or at line-start (`path: ../caixa-teia # pin` \
4054 — the canonical paste-from-values.yaml / paste-from-K8s-manifest cross-idiom-\
4055 leak); RFC 3986 §3.5 reserves `#` as the URL fragment-identifier delimiter (the \
4056 canonical paste-from-browser-address-bar `github.com/foo/bar#readme` / \
4057 `github.com/foo/bar#L42` permalink shape, and the symmetric Nix-flake-ref \
4058 cross-idiom leak `github:foo/bar#packageName` where `#` selects a flake \
4059 output); the same cross-config-DSL surface extends to HCL / Terraform / Nix \
4060 flake attributes / dotenv `.env` / gitconfig / .gitignore / ini / TOML where \
4061 `#` is likewise the comment-lead. POSIX `std::path::Path` treats the byte as a \
4062 literal path-component byte, so a `:caminho \"../caixa-teia # legacy sibling\"` \
4063 (the canonical paste-from-shell-history-with-trailing-annotation footgun), \
4064 `:caminho \"../caixa-teia # pin\"` (the symmetric YAML flow-scalar paste-with-\
4065 trailing-comment shape), or `:caminho \"../caixa-teia#readme\"` (the URL \
4066 fragment paste-from-browser-address-bar shape) silently passes every prior arm \
4067 and the resolver folds the value through `Path::new(caminho).join(<file>)` \
4068 looking for a literal subdirectory named `../caixa-teia # legacy sibling` and \
4069 fails at resolve time with a non-self-locating `No such file or directory` \
4070 error far from the source caixa.lisp — while every downstream shell / YAML / \
4071 URL parser silently truncates the value at the `#` byte to `../caixa-teia`, so \
4072 a `feira tofu` shell-out and a `nix flake check` on an emitted YAML `path:` \
4073 scalar disagree with the resolver on which directory the value names. The \
4074 lacre pipeline embeds the value verbatim in its per-dep content-address \
4075 `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the byte lands in \
4076 the BLAKE3 closure and rides into every shell-spawned subprocess (the \
4077 resolver's `git clone`, a future `feira tofu` shell-out, a future operator-\
4078 side `nix` spawn) as the canonical shell-metachar / comment-lead / URL-\
4079 fragment-delimiter surface every peer single-token-shaped typed slot already \
4080 closes. The peer `:fonte :repo` axis closes the byte under the same URL-\
4081 fragment-identifier banner (a68f818 `#` on `is_git_repo_url`). Express the \
4082 path as a bare relative single-token like \"../caixa-teia\" — the sibling-\
4083 workspace directory name carries no shell-comment / URL-fragment / YAML-\
4084 comment semantic; move any trailing annotation to a tatara-lisp `;`-comment \
4085 on the surrounding form (`;; legacy sibling` above the `(:caminho ...)` slot) \
4086 and drop any `#fragment` tail entirely (fragment identifiers select \
4087 renderings, not directories, and `:caminho` names a directory).",
4088 ch = *byte as char
4089 )]
4090 FonteCaminhoShellComment {
4091 nome: String,
4092 caminho: String,
4093 byte: u8,
4094 },
4095 #[error(
4096 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains URL-\
4097 percent-encoding-escape / printf-format-specifier / bash-job-control-specifier \
4098 / YAML-directive-lead metacharacter 0x{byte:02x} `{ch}` (RFC 3986 §2.1 reserves \
4099 `%` as the URL percent-encoding-escape — `%HH` is the mandatory encoding \
4100 mechanism for every byte outside the `unreserved` alphanumeric / `-` / `.` / \
4101 `_` / `~` set, and `%` itself must be percent-encoded as `%25` to appear \
4102 literally inside a URL value. The canonical paste-from-browser-address-bar \
4103 percent-encoded-space footgun (an author copies `../caixa%20teia` out of a URL-\
4104 encoded README hyperlink / browser address bar / percent-encoded permalink \
4105 expecting `%20` to decode to a literal space at the filesystem layer) locks two \
4106 distinct BLAKE3 closures (`path:../caixa%20teia` vs `path:../caixa teia`) for \
4107 what the author intended as the byte-identical sibling-workspace dep. POSIX \
4108 `std::path::Path` treats the byte as a literal path-component byte, so \
4109 `Path::join` looks for a literal `./{caminho}` subdirectory and fails at \
4110 resolve time with a non-self-locating `No such file or directory` error far \
4111 from the source caixa.lisp — while every downstream URL parser / shell printf \
4112 builtin / YAML directive parser silently reinterprets the byte to a different \
4113 value than the resolver's `Path::join` sees. Beyond the URL-encoding hazard, \
4114 `%` is the C / POSIX printf format-directive lead-in (`%s`, `%d`, `%02x` — \
4115 wired into every POSIX shell's `printf` builtin, the canonical CWE-134 format-\
4116 string-injection vector); the bash / zsh / ksh job-control-specifier lead-in \
4117 (`%1` names \"job 1\", `%%` names \"the current job\", `%foo` names \"the most \
4118 recent job whose command started with `foo`\" — a future `kill %1` invocation \
4119 silently redirects the signal to a wrong target); the YAML 1.2 §6.8.1 \
4120 directive lead-in (`%YAML 1.2` / `%TAG` — the paste-from-top-of-doc YAML \
4121 directive block cross-idiom leak); and the Windows-shell env-var-reference \
4122 lead-in (`%PATH%` — the paste-from-`.bat` / paste-from-PowerShell-`%env:PATH%` \
4123 cross-idiom leak). The lacre pipeline embeds the value verbatim in its per-dep \
4124 content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, so the \
4125 byte lands in the BLAKE3 closure and rides into every shell-spawned subprocess \
4126 (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4127 operator-side `nix` spawn) as the canonical URL-percent-encoding-escape / \
4128 printf-format-specifier / job-control-specifier surface every peer single-\
4129 token-shaped typed slot already closes. The peer `:fonte :repo` axis closes \
4130 the byte under the same URL-percent-encoding-escape banner (a323db8 `%` on \
4131 `is_git_repo_url`). Express the path as a bare relative single-token like \
4132 \"../caixa-teia\" — the sibling-workspace directory name carries no URL-\
4133 percent-encoding-escape / format-specifier / job-control semantic; substitute \
4134 any `%20` percent-encoded-space with a literal space then reject the whole \
4135 value at the leading-whitespace / embedded-`?` arm on the same axis (a caixa \
4136 directory name never carries an embedded space in practice); drop any \
4137 `%2F`-encoded path separator in favor of a literal `/`; and drop any leading \
4138 `%YAML` / `%PATH%` cross-idiom-leak prefix entirely.",
4139 ch = *byte as char
4140 )]
4141 FonteCaminhoUrlPercentEncoding {
4142 nome: String,
4143 caminho: String,
4144 byte: u8,
4145 },
4146 #[error(
4147 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4148 variable-expansion / command-substitution / arithmetic-expansion / cross-config-\
4149 DSL-interpolation metacharacter 0x{byte:02x} `{ch}` (every POSIX shell — sh / \
4150 bash / zsh / dash / ksh / busybox ash / fish / nushell — lexes `$` per \
4151 POSIX.1-2017 §2.6 as the variable-expansion `$<name>` / braced-form `${{<name>}}` \
4152 / command-substitution `$(<cmd>)` / arithmetic-expansion `$((<expr>))` operator; \
4153 Nix uses `${{var}}` as the string-interpolation lead, Make uses `$(var)` / `$@` \
4154 / `$<` for variables and automatic-variables, JavaScript / TypeScript template \
4155 literals use `${{expr}}` for interpolation, envsubst / Kubernetes / OpenShift \
4156 templates use `${{VAR}}` for env-var-reference, PHP uses `$_GET` / `$_ENV` for \
4157 superglobals, Perl uses `$foo` for scalars, SASS / SCSS uses `$primary-color` \
4158 for variables, and PostgreSQL / SQLite use `$1` / `$2` for bind parameters — \
4159 the byte is a first-class parser byte in nearly every config / templating / \
4160 build-system DSL the substrate's paste-idiom surface routinely crosses. POSIX \
4161 `std::path::Path` treats the byte as a literal path-component byte, so the \
4162 canonical paste-from-shell-one-liner `:caminho \"../foo$HOME/bar\"` / paste-\
4163 from-CI-manifest `:caminho \"../foo${{WORKSPACE}}/bar\"` / paste-from-shell-\
4164 prompt `:caminho \"../foo$(whoami)/bar\"` footguns silently pass every prior \
4165 cascade arm (`$` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / \
4166 `?` / `(` / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%`) and route \
4167 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4168 subdirectory that fails at resolve time with a non-self-locating `No such file \
4169 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4170 the value verbatim in its per-dep content-address `path:{caminho}` at \
4171 caixa-resolver/src/resolve.rs:189, so byte-identical caixa.lisp values differing \
4172 only in whether the author substituted `$HOME` / `${{WORKSPACE}}` at author \
4173 time lock to two distinct BLAKE3 closures across two workstations whose \
4174 downstream envsubst / Nix / Make / K8s-template layers differ in `$VAR` \
4175 recognition — defeating the THEORY.md §V.2 render-determinism contract on the \
4176 same axis every prior `:caminho` arm protects. Beyond the determinism vector, \
4177 `$` at any position in a value flowing verbatim into a shell-spawned subprocess \
4178 is the canonical CWE-78 shell-command-injection surface every peer single-\
4179 token-shaped typed slot already closes: peer `:fonte :repo` axis rejects `$` \
4180 under the shell-variable-expansion / URL-sub-delim banner via `is_git_repo_url` \
4181 (b9d187c), peer `:fonte :tag` / `:fonte :branch` axes reject `$` as part of \
4182 `is_git_ref_name`'s printable-ASCII-restricted grammar (`git check-ref-format` \
4183 rejects the byte outright), and peer `:entrada :paths` axis rejects `$` via \
4184 `is_gateway_api_http_path`'s eleven-byte RFC-3986-reserved set. The leading-`$` \
4185 position on the same axis routes through `FonteCaminhoVarExpansion` at the \
4186 f4efe9c leading-byte arm; this arm closes the last positional gap on the byte \
4187 so every position — leading and embedded — is structurally rejected. Substitute \
4188 the `$VAR` / `${{VAR}}` / `$(cmd)` template with the literal value at author \
4189 time, or express the path as a bare relative single-token like \
4190 \"../caixa-teia\" — the sibling-workspace directory name carries no shell-\
4191 variable-expansion / command-substitution / arithmetic-expansion semantic.",
4192 ch = *byte as char
4193 )]
4194 FonteCaminhoShellVariableExpansion {
4195 nome: String,
4196 caminho: String,
4197 byte: u8,
4198 },
4199 #[error(
4200 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4201 history-expansion / RFC-3986-sub-delims / bang-operator metacharacter 0x{byte:02x} \
4202 `{ch}` (every interactive POSIX shell with history enabled — bash / ksh / zsh's \
4203 `bashcompat` / csh / tcsh — lexes `!` as the history-expansion prefix per bash \
4204 reference §9.3: `!command` re-runs the most recent history entry beginning with \
4205 `command`, `!!` re-runs the prior command verbatim, `!$` substitutes the last \
4206 word of the prior command, `!:N` substitutes the Nth word of the prior command, \
4207 and the substitution fires at every history-expansion-enabled shell context — \
4208 `set -o histexpand` is bash's default for interactive sessions and the layer \
4209 every `feira tofu` / `git clone` / `nix flake check` subprocess-argument \
4210 invocation crosses when spawned under `bash -i`. Beyond shell history, RFC 3986 \
4211 §2.2 lists `!` in the `sub-delims` set (the URL grammar admits the byte inside \
4212 a path segment, but every WHATWG-conformant special-scheme URL parser percent-\
4213 encodes it inside a query component via the 'special-query percent-encode set' \
4214 the peer `is_git_repo_url` `*` / `(` / `)` / `'` arms close on); the byte is \
4215 also the C / C++ / Rust / JavaScript / Python bang-operator (logical-negation \
4216 prefix — the paste-from-source-code idiom where an author copies \
4217 `!path.exists()` out of a Rust snippet and the trailing punctuation crosses \
4218 the string-literal boundary); the canonical English-typography emphasis / \
4219 exclamation mark (the paste-from-prose enthusiasm-form idiom where an author \
4220 writes `:caminho \"../caixa-teia!\"` expecting the substrate to coerce it to a \
4221 kebab-case slug); and the Nix flake-ref attribute-selection operator surface. \
4222 POSIX `std::path::Path` treats `!` as a literal path-component byte, so the \
4223 canonical paste-from-shell-history footgun `:caminho \"../caixa-teia!sudo\"` \
4224 (an author copies a `cd ../caixa-teia && !sudo make install` one-liner from a \
4225 quick-start README and the trailing `!sudo` rides in verbatim as a history-\
4226 expansion reference), the symmetric `:caminho \"../foo!!/bar\"` (the `!!` \
4227 repeat-prior-command paste idiom), the English-typography `:caminho \
4228 \"../caixa-teia!\"` (paste-from-prose enthusiasm-form), and the last-word-\
4229 substitution `:caminho \"../foo!$\"` shape silently pass every prior cascade \
4230 arm (`!` isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` \
4231 / `)` / `{{` / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$`) and route \
4232 through `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` \
4233 subdirectory that fails at resolve time with a non-self-locating `No such file \
4234 or directory` error far from the source caixa.lisp. The lacre pipeline embeds \
4235 the value verbatim in its per-dep content-address `path:{caminho}` at \
4236 caixa-resolver/src/resolve.rs:189, so the byte lands in the BLAKE3 closure and \
4237 rides into every shell-spawned subprocess (the resolver's `git clone`, a \
4238 future `feira tofu` shell-out, a future operator-side `nix flake check` spawn) \
4239 as the canonical shell-history-expansion / RFC-3986-sub-delims surface every \
4240 peer single-token-shaped typed slot already closes. The peer `:fonte :repo` \
4241 axis closes the byte under the same shell-history-expansion / RFC-3986-sub-\
4242 delims banner (7d53c68 `!` on `is_git_repo_url`). Express the path as a bare \
4243 relative single-token like \"../caixa-teia\" — the sibling-workspace directory \
4244 name carries no shell-history-expansion / bang-operator semantic; drop any \
4245 `!sudo` / `!!` / `!$` history-expansion trailing paste-from-shell-history \
4246 idiom; and drop any trailing English-typography exclamation mark that pasted \
4247 from prose.",
4248 ch = *byte as char
4249 )]
4250 FonteCaminhoShellHistoryExpansion {
4251 nome: String,
4252 caminho: String,
4253 byte: u8,
4254 },
4255 #[error(
4256 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} contains shell-\
4257 history-substitution / RFC-3986-'unwise' / regex-negation metacharacter 0x{byte:02x} \
4258 `{ch}` (POSIX bash's `set -o histexpand` mode — the default for every interactive \
4259 session and every `bash -i` subprocess-argument context `feira tofu` / `git clone` / \
4260 `nix flake check` cross — lexes `^old^new^` per bash reference §9.3 as the 'quick \
4261 substitution' history operator that rewrites the prior command's `old` string to \
4262 `new` and re-executes it verbatim, the canonical typo-correction one-liner idiom \
4263 (`git clone <bad-url>` → `^bad^good` typo-fix-and-rerun the paste-from-shell-\
4264 history author trims only the leading `git clone` prefix from). RFC 3986 §2 lists \
4265 `^` in the 'unwise' set every URL parser is required to percent-encode-or-refuse at \
4266 the wire boundary, and the WHATWG URL spec's 'fragment percent-encode set' maps \
4267 `^` → `%5E` at the query / fragment component transition, so `Path::join` on the \
4268 literal value diverges from every downstream `feira tofu` curl-invocation / \
4269 artifact-registry-fetch that percent-encodes the byte before the wire. `^` is also \
4270 the regex character-class negation prefix (`[^abc]`), the bitwise XOR operator in \
4271 C / C++ / Rust / Python / JavaScript / Nix / Go, the Windows `cmd.exe` escape \
4272 metacharacter, and the LaTeX / Markdown / BibTeX superscript operator. POSIX \
4273 `std::path::Path` treats `^` as a literal path-component byte, so \
4274 `:caminho \"../foo^bar/baz\"` (embedded quick-substitution), `:caminho \
4275 \"../foo^\"` (trailing history-substitution-open shape), or `:caminho \"../x^y\"` \
4276 (XOR-expression paste-from-source) silently pass every prior cascade arm (`^` \
4277 isn't `\\` / `<` / `>` / `|` / `;` / `&` / backtick / `*` / `?` / `(` / `)` / `{{` \
4278 / `}}` / `[` / `]` / `'` / `\"` / `#` / `%` / `$` / `!`) and route through \
4279 `Path::new(caminho).join(<file>)` looking for a literal `./{caminho}` subdirectory \
4280 that fails at resolve time with a non-self-locating `No such file or directory` \
4281 error far from the source caixa.lisp. The lacre pipeline embeds the value verbatim \
4282 in its per-dep content-address `path:{caminho}` at caixa-resolver/src/resolve.rs:189, \
4283 so the byte lands in the BLAKE3 closure and rides into every shell-spawned \
4284 subprocess (the resolver's `git clone`, a future `feira tofu` shell-out, a future \
4285 operator-side `nix flake check` spawn) as the canonical shell-history-substitution \
4286 / RFC-3986-unwise surface every peer single-token-shaped typed slot already closes. \
4287 The peer `:fonte :repo` axis closes the byte under the same shell-history-\
4288 substitution / RFC-3986-unwise banner (49e142f `^` on `is_git_repo_url`). Together \
4289 with the immediate-predecessor `!` arm (6a04767) this arm closes the full `set -o \
4290 histexpand` operator surface on the `:caminho` axis — the `!command` / `!!` / `!$` \
4291 prefix form via `!`, the `^old^new^` quick-substitution form via `^`. Express the \
4292 path as a bare relative single-token like \"../caixa-teia\" — the sibling-workspace \
4293 directory name carries no shell-history-substitution / regex-negation / XOR-operator \
4294 semantic; drop any `^old^new` history-substitution paste-from-shell-history idiom; \
4295 drop any trailing `^` history-substitution-open fragment.",
4296 ch = *byte as char
4297 )]
4298 FonteCaminhoShellHistorySubstitution {
4299 nome: String,
4300 caminho: String,
4301 byte: u8,
4302 },
4303 #[error(
4304 ":deps entry {nome:?} :fonte (:tipo path …) :caminho {caminho:?} has a trailing \
4305 `/` (the resolver's `Path::join` resolves `\"../caixa-teia\"` and \
4306 `\"../caixa-teia/\"` to the same directory, but the lacre pipeline embeds the \
4307 value verbatim in its per-dep content-address `path:{caminho}` at \
4308 caixa-resolver/src/resolve.rs:189, so two authors whose only difference is \
4309 shell tab-completion emit byte-divergent BLAKE3 closures for the same caixa — \
4310 defeating the THEORY.md §V.2 render-determinism contract via the trailing-\
4311 separator vector (the canonical paste-from-shell-tab-completion + paste-from-\
4312 `pwd`-with-`/`-suffix footgun, and the canonical Cargo-style `path = \
4313 \"../caixa-teia/\"` paste-from-Cargo-manifest cross-idiom leak). Drop the \
4314 trailing `/`; every `:caminho` value names a sibling-workspace directory \
4315 already, so the trailing separator carries no information. Use \
4316 `\"../caixa-teia\"` rather than `\"../caixa-teia/\"`)"
4317 )]
4318 FonteCaminhoTrailingSlash { nome: String, caminho: String },
4319 #[error(
4320 "{list} carries duplicate entry :nome {nome:?} — every dep list keys its \
4321 entries by caixa name (Cargo's [dependencies] / [dev-dependencies] tables \
4322 apply the same set-not-multiset discipline; one package per table), and \
4323 two entries naming the same caixa carry two version constraints / source \
4324 pins / feature sets for one identity. The caixa-resolver's lacre pipeline \
4325 consumes the list as a `HashMap`-keyed-by-`:nome` lookup: the second entry \
4326 silently overwrites the first at the resolver-side `concrete_versao` step, \
4327 and the dropped entry's pin / features never reach the closure — far from \
4328 the source caixa.lisp, with no field naming which `:deps` entry was the \
4329 silent loser. If two version constraints are genuinely needed (the rare \
4330 multi-version closure case the lacre pipeline doesn't yet support), the \
4331 author surface is two distinct caixa names (e.g. a `caixa-teia-v01` / \
4332 `caixa-teia-v02` aliased pair); within one list, one entry per caixa name."
4333 )]
4334 DuplicateNome { nome: String, list: &'static str },
4335 #[error(
4336 ":deps entry {nome:?} has empty :caracteristicas entry — every feature flag must \
4337 name a non-empty identifier on the target caixa (Cargo's [dependencies.<dep>.features] \
4338 applies the same per-entry non-empty discipline). An empty feature flag reaches the \
4339 caixa-resolver's lacre pipeline as a no-op feature enable, silently dropping the \
4340 author's intent far from the source caixa.lisp; drop the empty entry, or replace it \
4341 with the canonical kebab-case feature name the target caixa declares."
4342 )]
4343 CaracteristicaEmpty { nome: String },
4344 #[error(
4345 ":deps entry {nome:?} :caracteristicas entry {caracteristica:?} is not a valid Cargo \
4346 feature name: {reason} (the value flows verbatim into Cargo's \
4347 [dependencies.<dep>.features] list and Cargo's `restricted_names::validate_feature_name` \
4348 parser enforces the same shape at `cargo metadata` time; use a single-token \
4349 identifier like `\"http\"`, `\"derive\"`, or `\"runtime-tokio\"` — kebab-case ASCII \
4350 alphanumeric with `-`, `_`, `+`, or `.` as continuation characters, starting with \
4351 an ASCII alphanumeric or `_`)"
4352 )]
4353 CaracteristicaInvalid {
4354 nome: String,
4355 caracteristica: String,
4356 reason: String,
4357 },
4358 #[error(
4359 ":deps entry {nome:?} :caracteristicas carries duplicate feature {caracteristica:?} — \
4360 every feature-flag list keys its entries by name (Cargo's \
4361 [dependencies.<dep>.features] applies the same set-not-multiset discipline; one entry \
4362 per feature per dep), and two entries naming the same feature are a redundant \
4363 set-membership declaration for one identity (the feature-toggle slot is set-shaped; \
4364 enabling a feature twice has no additional semantic). The caixa-resolver's lacre \
4365 pipeline consumes the list as a set-shaped feature toggle — the resolver enables the \
4366 feature once regardless of declaration count, so the duplicate's pin / position never \
4367 reaches the closure with no field naming the silent loser. One entry per feature per \
4368 dep; if two distinct features are intended, name each verbatim."
4369 )]
4370 CaracteristicaDuplicate {
4371 nome: String,
4372 caracteristica: String,
4373 },
4374 #[error(
4375 "{list} entry :nome {nome:?} names the caixa itself — a caixa cannot depend \
4376 on itself (the lacre closure's dep-graph traversal is rooted at the caixa's \
4377 :nome, and a self-dep would be a one-node cycle the caixa-resolver either \
4378 rejects mid-traversal far from the source caixa.lisp or recurses on until \
4379 it exhausts its stack). Every :nome is globally-unique substrate identity, \
4380 so a :deps / :deps-dev entry whose :nome equals the parent caixa's :nome \
4381 *is* the parent itself, not a coincidentally-named peer. Drop the \
4382 self-referential dep entry — to reference code from this caixa, use \
4383 :bibliotecas / :exe / :servicos (the substrate-blessed shape for \
4384 referencing the caixa's own code surface) instead."
4385 )]
4386 DepIsSelf { nome: String, list: &'static str },
4387}
4388
4389#[allow(clippy::trivially_copy_pass_by_ref)]
4390fn is_false(b: &bool) -> bool {
4391 !*b
4392}
4393
4394#[cfg(test)]
4395mod tests {
4396 use super::*;
4397
4398 #[test]
4399 fn registry_dep_is_minimal() {
4400 let d = Dep::simple("caixa-teia", "^0.1");
4401 assert_eq!(d.nome, "caixa-teia");
4402 assert_eq!(d.versao, "^0.1");
4403 assert!(d.fonte.is_none());
4404 assert!(!d.opcional());
4405 assert!(d.caracteristicas().is_empty());
4406 }
4407
4408 #[test]
4409 fn dep_string_scalar_accessor_pair_is_const_fn() {
4410 // Fail-before-pass-after pin on [`Dep::nome`] +
4411 // [`Dep::versao_requirement`]'s `const`-eval-surface posture.
4412 // Each accessor projects the per-`:deps` / per-`:deps-dev`
4413 // entry's [`String`] storage through the `pub const fn`
4414 // [`String::as_str`] (const-stable since Rust 1.87, well
4415 // within the workspace MSRV) — any future accidental
4416 // downgrade to non-`const` fails the corresponding
4417 // `<name>_via_const_fn` wrapper at caixa-core build time with
4418 // E0015 (`cannot call non-const method`), strictly stronger
4419 // than a runtime `assert!`. Sibling of the peer
4420 // per-M2/M3/universal-axis `String → &str` scalar-accessor
4421 // family pins on the sibling `const`-eval-surface passes
4422 // ([`crate::Caixa::nome`] / [`crate::Caixa::versao`] at the
4423 // top-level manifest, [`crate::CaixaVersion::as_str`] at the
4424 // typed-newtype wrapper, [`crate::aplicacao::Membro::nome`] /
4425 // [`crate::aplicacao::Membro::versao_requirement`] at the M3
4426 // membership axis, [`crate::aplicacao::Entrada::hostname`] /
4427 // [`crate::aplicacao::Entrada::destination`] at the M3
4428 // ingress axis, [`crate::supervisor::ChildSpec::nome`] /
4429 // [`crate::supervisor::ChildSpec::versao_requirement`] at the
4430 // M2 supervisor-tree axis,
4431 // [`crate::upgrade::UpgradeFromEntry::prior_versao`] at the
4432 // M2 upgrade axis, and the per-`:contratos`
4433 // [`crate::aplicacao::WitContract::source`] /
4434 // [`crate::aplicacao::WitContract::destination`] /
4435 // [`crate::aplicacao::WitContract::world_ref`] trio the
4436 // sibling pin at 279823b already anchors).
4437 const fn nome_via_const_fn(d: &Dep) -> &str {
4438 d.nome()
4439 }
4440 const fn versao_via_const_fn(d: &Dep) -> &str {
4441 d.versao_requirement()
4442 }
4443 for (nome, versao) in [
4444 ("caixa-teia", "^0.1"),
4445 ("caixa-mesh", "~0.2.3"),
4446 ("caixa-helm", "*"),
4447 ] {
4448 let d = Dep::simple(nome, versao);
4449 assert_eq!(nome_via_const_fn(&d), d.nome());
4450 assert_eq!(versao_via_const_fn(&d), d.versao_requirement());
4451 assert_eq!(d.nome(), nome);
4452 assert_eq!(d.versao_requirement(), versao);
4453 }
4454 }
4455
4456 #[test]
4457 fn dep_outer_accessor_family_is_const_fn() {
4458 // Fail-before-pass-after pin on [`Dep::fonte`] +
4459 // [`Dep::caracteristicas`]'s `const`-eval-surface posture.
4460 // Each accessor projects the per-`:deps` / per-`:deps-dev`
4461 // entry's composite / list storage through a `pub const fn`
4462 // stdlib method (`Option::<DepSource>::as_ref` /
4463 // `Vec::<String>::as_slice`, both const-stable since Rust
4464 // 1.83, well within the workspace MSRV). Any future
4465 // accidental downgrade to non-`const` fails the corresponding
4466 // `<name>_via_const_fn` wrapper at caixa-core build time with
4467 // E0015 (`cannot call non-const method`), strictly stronger
4468 // than a runtime `assert!` and side-stepping the destructor-
4469 // in-const restriction the `Dep` fixture's `String` /
4470 // `Option<DepSource>` / `Vec<String>` carriers rule out on the
4471 // direct-`const _: () = assert!(...)` residence.
4472 //
4473 // Peer of the sibling per-`Dep` scalar-accessor pair pin
4474 // [`dep_string_scalar_accessor_pair_is_const_fn`] on the same
4475 // outer per-dep-list-entry [`Dep`] altitude — this pin extends
4476 // the `const`-eval-surface discipline onto the composite-
4477 // reference and slice-return arms of the outer-`Dep` accessor
4478 // family, closing the four-slot outer surface (`:nome` +
4479 // `:versao` + `:fonte` + `:caracteristicas`) on the `const`-fn
4480 // posture. The `:opcional` `bool` arm already carries the
4481 // posture through [`Dep::opcional`]'s prior `pub const fn`
4482 // declaration, so this pin lands the last two unlifted
4483 // outer-`Dep` accessors and closes the family.
4484 const fn fonte_via_const_fn(d: &Dep) -> Option<&DepSource> {
4485 d.fonte()
4486 }
4487 const fn caracteristicas_via_const_fn(d: &Dep) -> &[String] {
4488 d.caracteristicas()
4489 }
4490 // `Dep::simple` — no `:fonte`, empty `:caracteristicas`.
4491 let empty = Dep::simple("caixa-teia", "^0.1");
4492 assert!(fonte_via_const_fn(&empty).is_none());
4493 assert_eq!(fonte_via_const_fn(&empty), empty.fonte());
4494 assert!(caracteristicas_via_const_fn(&empty).is_empty());
4495 assert_eq!(
4496 caracteristicas_via_const_fn(&empty),
4497 empty.caracteristicas()
4498 );
4499 // `Dep::git` — `:fonte` is `Some(Git{…})`, `:caracteristicas`
4500 // still empty.
4501 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
4502 assert!(fonte_via_const_fn(&git).is_some());
4503 assert_eq!(fonte_via_const_fn(&git), git.fonte());
4504 assert_eq!(caracteristicas_via_const_fn(&git), git.caracteristicas());
4505 // Populated `:caracteristicas` — exercise the non-empty
4506 // slice-view arm to pin the accessor's borrow shape against
4507 // both a `Vec::new()` empty backing buffer and a populated one.
4508 let mut with_features = Dep::simple("caixa-teia", "^0.1");
4509 with_features.caracteristicas = vec!["feat-a".into(), "feat-b".into()];
4510 assert_eq!(caracteristicas_via_const_fn(&with_features).len(), 2);
4511 assert_eq!(
4512 caracteristicas_via_const_fn(&with_features),
4513 with_features.caracteristicas()
4514 );
4515 }
4516
4517 #[test]
4518 fn git_dep_carries_tag() {
4519 let d = Dep::git("t", "*", "github:o/r", "v1");
4520 match d.fonte {
4521 Some(DepSource::Git {
4522 ref repo, ref tag, ..
4523 }) => {
4524 assert_eq!(repo, "github:o/r");
4525 assert_eq!(tag.as_deref(), Some("v1"));
4526 }
4527 _ => panic!("expected Git source"),
4528 }
4529 }
4530
4531 #[test]
4532 fn validate_accepts_simple_dep() {
4533 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
4534 }
4535
4536 #[test]
4537 fn validate_rejects_empty_nome() {
4538 // The fail-before-pass-after pin for `:nome ""`: the empty-name
4539 // arm fires first so the per-entry parse-side diagnostic doesn't
4540 // emit a useless `nome: ""` reference.
4541 let mut d = Dep::simple("placeholder", "^0.1");
4542 d.nome = String::new();
4543 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4544 }
4545
4546 #[test]
4547 fn validate_rejects_empty_versao() {
4548 // `parse_requirement("")` returns `Ok(VersionReq::STAR)` (the
4549 // semver crate accepts the empty string as a wildcard match),
4550 // so the empty-`:versao` arm is structurally necessary even
4551 // with the parse arm in place — mirrors `MembroVersaoEmpty` /
4552 // `EmptyChildVersion` ordering on the other two `:versao` axes.
4553 let mut d = Dep::simple("caixa-teia", "ignored");
4554 d.versao = String::new();
4555 let err = d.validate().unwrap_err();
4556 assert!(
4557 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4558 "got {err:?}"
4559 );
4560 }
4561
4562 // ── value-shape: DNS-1123 label on :deps :nome ────────────────────────
4563
4564 #[test]
4565 fn validate_rejects_nome_with_uppercase() {
4566 // The fail-before-pass-after pin: a non-empty but uppercase
4567 // `:nome` silently passed `validate()` on every pre-gate
4568 // codebase because the prior shape only refused the empty
4569 // string. The DNS-1123 violation surfaced far downstream at
4570 // lacre-resolve time when the *target* caixa's `:nome` failed
4571 // its own gate — far from the `:deps` entry, with a diagnostic
4572 // naming the target rather than the dep entry that referenced
4573 // it. Same fail-before-pass-after fixture pinned for
4574 // `:membros :caixa` (3f9d7a0), `:children :caixa` (31bfa43),
4575 // and Caixa `:nome` (6c992f8).
4576 let d = Dep::simple("Caixa-Teia", "^0.1");
4577 let err = d.validate().unwrap_err();
4578 assert!(
4579 matches!(
4580 err,
4581 DepError::NomeInvalid { ref nome, ref reason }
4582 if nome == "Caixa-Teia" && reason.contains("uppercase")
4583 ),
4584 "got {err:?}"
4585 );
4586 }
4587
4588 #[test]
4589 fn validate_rejects_nome_with_underscore() {
4590 // RFC 1123 allows `[a-z0-9-]` only; underscore is the canonical
4591 // "I'm thinking of Go module names / Python identifiers" leak.
4592 // Same fixture pinned for the peer caixa-identifier axes.
4593 let d = Dep::simple("caixa_teia", "^0.1");
4594 let err = d.validate().unwrap_err();
4595 assert!(
4596 matches!(
4597 err,
4598 DepError::NomeInvalid { ref nome, ref reason }
4599 if nome == "caixa_teia" && reason.contains('_')
4600 ),
4601 "got {err:?}"
4602 );
4603 }
4604
4605 #[test]
4606 fn validate_rejects_nome_with_dot() {
4607 // A `:deps :nome` is a single DNS-1123 *label*, not a
4608 // subdomain — dots are rejected. The `"caixa.teia"` shape is
4609 // the canonical "I confused the dep name with the FQDN /
4610 // namespace" footgun, distinct from the legitimate
4611 // `:fonte :repo "github:org/caixa-teia"` axis.
4612 let d = Dep::simple("caixa.teia", "^0.1");
4613 let err = d.validate().unwrap_err();
4614 assert!(
4615 matches!(
4616 err,
4617 DepError::NomeInvalid { ref nome, ref reason }
4618 if nome == "caixa.teia" && reason.contains('.')
4619 ),
4620 "got {err:?}"
4621 );
4622 }
4623
4624 #[test]
4625 fn validate_rejects_nome_with_leading_hyphen() {
4626 // RFC 1123 requires alphanumeric at both label boundaries.
4627 // Pinned in parity with the peer DNS-1123 fixtures.
4628 let d = Dep::simple("-caixa-teia", "^0.1");
4629 let err = d.validate().unwrap_err();
4630 assert!(
4631 matches!(
4632 err,
4633 DepError::NomeInvalid { ref nome, ref reason }
4634 if nome == "-caixa-teia" && reason.contains("alphanumeric")
4635 ),
4636 "got {err:?}"
4637 );
4638 }
4639
4640 #[test]
4641 fn validate_rejects_nome_with_trailing_hyphen() {
4642 let d = Dep::simple("caixa-teia-", "^0.1");
4643 let err = d.validate().unwrap_err();
4644 assert!(
4645 matches!(
4646 err,
4647 DepError::NomeInvalid { ref nome, ref reason }
4648 if nome == "caixa-teia-" && reason.contains("alphanumeric")
4649 ),
4650 "got {err:?}"
4651 );
4652 }
4653
4654 #[test]
4655 fn validate_rejects_nome_with_slash() {
4656 // The canonical "I copied the GitHub repo path into `:nome`
4657 // instead of `:fonte :repo`" typo. A `/` in the name leaks the
4658 // lacre-side `:repositorio` shape (`pleme-io/caixa-teia`) into
4659 // the local-name slot. Same fixture pinned for `:membros
4660 // :caixa` (3f9d7a0).
4661 let d = Dep::simple("pleme-io/caixa-teia", "^0.1");
4662 let err = d.validate().unwrap_err();
4663 assert!(
4664 matches!(
4665 err,
4666 DepError::NomeInvalid { ref nome, ref reason }
4667 if nome == "pleme-io/caixa-teia" && reason.contains('/')
4668 ),
4669 "got {err:?}"
4670 );
4671 }
4672
4673 #[test]
4674 fn validate_rejects_nome_too_long() {
4675 // 64-byte label — one over the RFC 1035 / RFC 1123 label cap.
4676 // Built from a valid character set so the length-bound
4677 // diagnostic surfaces before any per-character check (the
4678 // order pin parallel to the per-character predicates inside
4679 // [`crate::render::is_dns_1123_label`]).
4680 let long = "a".repeat(64);
4681 let d = Dep::simple(&long, "^0.1");
4682 let err = d.validate().unwrap_err();
4683 assert!(
4684 matches!(
4685 err,
4686 DepError::NomeInvalid { ref nome, ref reason }
4687 if nome.len() == 64 && reason.contains("max length of 63")
4688 ),
4689 "got {err:?}"
4690 );
4691 }
4692
4693 #[test]
4694 fn validate_accepts_canonical_nome_labels() {
4695 // Positive-control sweep — every form the K8s apiserver
4696 // accepts as a DNS-1123 label must round-trip through
4697 // validate. Covers a hyphen-bearing label, a numeric-suffix
4698 // label, a leading-digit label, a single-character label, and
4699 // a 63-byte (exactly the cap) label — the same fixture set
4700 // the peer `:membros :caixa` / `:children :caixa` positive
4701 // controls pin.
4702 for nome in [
4703 "caixa-teia",
4704 "caixa-resolver2",
4705 "2nd-tier-cache",
4706 "x",
4707 "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0",
4708 ] {
4709 Dep::simple(nome, "^0.1")
4710 .validate()
4711 .unwrap_or_else(|e| panic!("canonical label {nome:?} must validate, got {e:?}"));
4712 }
4713 }
4714
4715 #[test]
4716 fn nome_empty_takes_precedence_over_nome_invalid() {
4717 // Ordering pin: `NomeEmpty` is the more self-locating
4718 // diagnostic on `""` and must lead — `is_dns_1123_label` is
4719 // only reached after the empty-check fires at the call site.
4720 // Mirrors `membro_caixa_empty_takes_precedence_over_invalid`
4721 // (3f9d7a0) on the peer caixa-identifier axis.
4722 let mut d = Dep::simple("placeholder", "^0.1");
4723 d.nome = String::new();
4724 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
4725 }
4726
4727 #[test]
4728 fn nome_invalid_fires_before_versao_empty() {
4729 // Ordering pin: a malformed `:nome` fires before any `:versao`
4730 // axis check on the *same* entry — the per-entry shape gates
4731 // run top-to-bottom (nome empty → nome shape → versao empty →
4732 // versao parse → fonte shape), so a one-entry caixa.lisp with
4733 // both wrong sees the name-side diagnostic first (the name is
4734 // the self-locating axis — without a valid name, the parse
4735 // diagnostic can't quote `:nome "<bad>"`). Same ordering
4736 // discipline as `membro_caixa_invalid_fires_before_versao_check`
4737 // (3f9d7a0).
4738 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4739 d.versao = String::new();
4740 let err = d.validate().unwrap_err();
4741 assert!(
4742 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4743 "got {err:?}"
4744 );
4745 }
4746
4747 #[test]
4748 fn nome_invalid_fires_before_versao_invalid() {
4749 // Ordering pin: a malformed `:nome` fires before the `:versao`
4750 // parse-side check on the *same* entry. Pin separately from
4751 // the empty-versao ordering so a future re-ordering surfaces
4752 // here, parallel to the b0c8389 / c4213a4 trajectory.
4753 let d = Dep::simple("Caixa-Teia", "^^0.1");
4754 let err = d.validate().unwrap_err();
4755 assert!(
4756 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4757 "got {err:?}"
4758 );
4759 }
4760
4761 #[test]
4762 fn nome_invalid_fires_before_fonte_invalid() {
4763 // Ordering pin: a malformed `:nome` fires before the `:fonte`
4764 // shape check on the *same* entry. The `:fonte` diagnostic
4765 // names the offending dep's `:nome` verbatim (via
4766 // `DepSource::validate(&self.nome)`), so a non-self-locating
4767 // name would taint the downstream diagnostic too — the gate
4768 // ordering keeps both diagnostics individually self-locating.
4769 let mut d = Dep::simple("Caixa-Teia", "^0.1");
4770 d.fonte = Some(DepSource::Git {
4771 repo: String::new(),
4772 tag: None,
4773 rev: None,
4774 branch: None,
4775 });
4776 let err = d.validate().unwrap_err();
4777 assert!(
4778 matches!(err, DepError::NomeInvalid { ref nome, .. } if nome == "Caixa-Teia"),
4779 "got {err:?}"
4780 );
4781 }
4782
4783 #[test]
4784 fn nome_invalid_diagnostic_carries_offending_name() {
4785 // The diagnostic-shape pin: the error names the offending
4786 // `:nome` value verbatim so the author can grep their
4787 // caixa.lisp without re-running the build, and carries a
4788 // non-empty `reason` from `is_dns_1123_label` so the
4789 // predicate's own wording flows through to the diagnostic.
4790 // Same shape as `MembroCaixaInvalid` (3f9d7a0),
4791 // `ChildCaixaInvalid` (31bfa43), `ManifestError::NomeInvalid`
4792 // (6c992f8) — the four DNS-1123 caixa-identifier axes now
4793 // share a structurally-equivalent diagnostic family.
4794 let d = Dep::simple("Caixa_Teia", "^0.1");
4795 let err = d.validate().unwrap_err();
4796 let DepError::NomeInvalid { nome, reason } = err else {
4797 panic!("expected NomeInvalid, got other variant");
4798 };
4799 assert_eq!(nome, "Caixa_Teia");
4800 assert!(
4801 !reason.is_empty(),
4802 "NomeInvalid `reason` must carry the predicate's wording verbatim"
4803 );
4804 }
4805
4806 #[test]
4807 fn validate_rejects_invalid_versao_requirement() {
4808 // The fail-before-pass-after pin: a non-empty but malformed
4809 // requirement (`"^bad-version"`) silently passed every pre-gate
4810 // codebase because `:deps :versao` wasn't validated. The parse
4811 // failure surfaced far downstream at lacre-resolve time with a
4812 // `semver::Error` that didn't name which `:deps` entry carried
4813 // the typo. The new gate moves the check to caixa-build time
4814 // at the source caixa.lisp.
4815 let d = Dep::simple("caixa-teia", "^bad-version");
4816 let err = d.validate().unwrap_err();
4817 assert!(
4818 matches!(
4819 err,
4820 DepError::VersaoInvalid { ref nome, ref versao, .. }
4821 if nome == "caixa-teia" && versao == "^bad-version"
4822 ),
4823 "got {err:?}"
4824 );
4825 }
4826
4827 #[test]
4828 fn validate_rejects_versao_with_double_caret_typo() {
4829 // `"^^0.1"` is the canonical doubled-caret typo — looks like a
4830 // Cargo-shaped requirement on first glance but fails the parser
4831 // because semver doesn't accept stacked operators. Pin this
4832 // adjacent-shape footgun explicitly so a future relaxation that
4833 // accepts "looks-canonical-but-isn't" forms surfaces here, in
4834 // parity with the `:membros` / `:children` fixtures.
4835 let d = Dep::simple("caixa-teia", "^^0.1");
4836 let err = d.validate().unwrap_err();
4837 assert!(
4838 matches!(
4839 err,
4840 DepError::VersaoInvalid { ref nome, ref versao, .. }
4841 if nome == "caixa-teia" && versao == "^^0.1"
4842 ),
4843 "got {err:?}"
4844 );
4845 }
4846
4847 #[test]
4848 fn validate_rejects_versao_with_v_prefixed_tag() {
4849 // `"v0.1"` is the canonical "git-tag-shape leaking into the
4850 // semver requirement slot" typo — an author copies the
4851 // publish-side git-tag string verbatim into `:versao`, but
4852 // Cargo's semver parser rejects the leading `v`. Same fixture
4853 // pinned for `:membros :versao` (9888b13) and `:children
4854 // :versao` (b38ff3a). (Bare `x`-glob shorthands like `^0.1.x`
4855 // are *accepted* by the semver crate as an `*` wildcard on the
4856 // patch axis — they're a Cargo-side valid shape, not a typo.)
4857 let d = Dep::simple("caixa-teia", "v0.1");
4858 let err = d.validate().unwrap_err();
4859 assert!(
4860 matches!(
4861 err,
4862 DepError::VersaoInvalid { ref nome, ref versao, .. }
4863 if nome == "caixa-teia" && versao == "v0.1"
4864 ),
4865 "got {err:?}"
4866 );
4867 }
4868
4869 #[test]
4870 fn validate_accepts_canonical_versao_forms() {
4871 // The five Cargo-shaped requirement forms `:membros :versao`
4872 // and `:children :versao` already accept via
4873 // `crate::parse_requirement` must pass the deps gate without
4874 // re-validating at the resolver layer. Pin every leg so a
4875 // future tightening of the canonical set surfaces here as a
4876 // test failure.
4877 for form in [
4878 "^0.1", // caret — minor-range pin (the most common shape)
4879 "~0.1.2", // tilde — patch-range pin
4880 "0.1.0", // exact — single-version pin
4881 "*", // wildcard — explicitly any-version
4882 ">=0.1, <2", // multi-range — comma-separated comparators
4883 ] {
4884 Dep::simple("caixa-teia", form)
4885 .validate()
4886 .unwrap_or_else(|e| panic!("canonical form {form:?} must validate, got {e:?}"));
4887 }
4888 }
4889
4890 #[test]
4891 fn versao_empty_takes_precedence_over_invalid() {
4892 // Order pin: the existing `VersaoEmpty` diagnostic (which
4893 // doesn't try to parse) fires before the new `VersaoInvalid`
4894 // parse-side diagnostic, so an empty `:versao` keeps its
4895 // narrower error message — `parse_requirement("")` would
4896 // otherwise return `Ok(STAR)` and silently pass, but the empty
4897 // arm catches it first.
4898 let mut d = Dep::simple("caixa-teia", "ignored");
4899 d.versao = String::new();
4900 let err = d.validate().unwrap_err();
4901 assert!(
4902 matches!(err, DepError::VersaoEmpty { ref nome } if nome == "caixa-teia"),
4903 "got {err:?}"
4904 );
4905 }
4906
4907 #[test]
4908 fn nome_empty_takes_precedence_over_versao_invalid() {
4909 // Order pin: even when `:versao` is malformed and would raise
4910 // its own diagnostic, `:nome ""` fires first because the
4911 // per-entry parse diagnostic needs a non-empty name to be
4912 // self-locating. Mirrors the
4913 // `membros_validation_runs_before_contratos_membership_check`
4914 // ordering on the typed-graph layer.
4915 let mut d = Dep::simple("placeholder", "^bad");
4916 d.nome = String::new();
4917 let err = d.validate().unwrap_err();
4918 assert_eq!(err, DepError::NomeEmpty);
4919 }
4920
4921 #[test]
4922 fn versao_invalid_diagnostic_carries_offending_versao() {
4923 // The diagnostic-shape pin: the error names the offending
4924 // `:versao` value verbatim so the author can grep their
4925 // caixa.lisp without re-running the build, and carries a
4926 // non-empty `reason` from `semver::VersionReq::parse` so the
4927 // parser's own wording flows through to the diagnostic.
4928 let d = Dep::simple("caixa-teia", "not-a-req");
4929 let err = d.validate().unwrap_err();
4930 let DepError::VersaoInvalid {
4931 nome,
4932 versao,
4933 reason,
4934 } = err
4935 else {
4936 panic!("expected VersaoInvalid, got other variant");
4937 };
4938 assert_eq!(nome, "caixa-teia");
4939 assert_eq!(versao, "not-a-req");
4940 assert!(
4941 !reason.is_empty(),
4942 "VersaoInvalid `reason` must carry the parser's wording verbatim"
4943 );
4944 }
4945
4946 // -- :fonte value-shape gate ------------------------------------------
4947
4948 fn dep_with_fonte(fonte: DepSource) -> Dep {
4949 let mut d = Dep::simple("caixa-teia", "^0.1");
4950 d.fonte = Some(fonte);
4951 d
4952 }
4953
4954 #[test]
4955 fn validate_accepts_git_fonte_with_tag() {
4956 // The positive-control pin on the canonical git source — exactly
4957 // one of :tag/:rev/:branch set, non-empty :repo. Mirrors the
4958 // shape every existing caixa-resolver integration test uses.
4959 let d = dep_with_fonte(DepSource::Git {
4960 repo: "github:pleme-io/caixa-teia".into(),
4961 tag: Some("v0.1.0".into()),
4962 rev: None,
4963 branch: None,
4964 });
4965 d.validate().unwrap();
4966 }
4967
4968 #[test]
4969 fn validate_accepts_git_fonte_with_rev() {
4970 // Each of the three pin axes is independently a valid single-pin
4971 // shape; pin the :rev arm so a future relaxation that only
4972 // accepts :tag surfaces here. The value is a full 40-hex SHA-1
4973 // OID — the canonical `git rev-parse HEAD` emission shape the
4974 // `crate::render::is_git_oid` value-shape gate now requires;
4975 // abbreviated OIDs are ambiguous across repo history and
4976 // rejected at this gate (pinned separately by
4977 // `validate_rejects_git_fonte_with_rev_abbreviated_prefix`).
4978 let d = dep_with_fonte(DepSource::Git {
4979 repo: "github:pleme-io/caixa-teia".into(),
4980 tag: None,
4981 rev: Some("c0ffee0123abcdef0123456789abcdef01234567".into()),
4982 branch: None,
4983 });
4984 d.validate().unwrap();
4985 }
4986
4987 #[test]
4988 fn validate_accepts_git_fonte_with_branch() {
4989 // The :branch arm is the third valid single-pin shape — pinned
4990 // separately so the gate-accepts-all-three-pin-axes contract is
4991 // a build-error to relax.
4992 let d = dep_with_fonte(DepSource::Git {
4993 repo: "github:pleme-io/caixa-teia".into(),
4994 tag: None,
4995 rev: None,
4996 branch: Some("main".into()),
4997 });
4998 d.validate().unwrap();
4999 }
5000
5001 #[test]
5002 fn validate_accepts_path_fonte() {
5003 // The positive-control pin on the path source — non-empty
5004 // :caminho, no pin axes (paths have no commit identity). Pinned
5005 // so a future "paths must also pin a rev" tightening surfaces
5006 // here as a structural decision, not a silent break.
5007 let d = dep_with_fonte(DepSource::Path {
5008 caminho: "../caixa-teia".into(),
5009 });
5010 d.validate().unwrap();
5011 }
5012
5013 #[test]
5014 fn validate_rejects_git_fonte_with_empty_repo() {
5015 // The fail-before-pass-after pin for `(:tipo git :repo "" :tag
5016 // "v1")`: the empty-repo shape silently passed every pre-gate
5017 // codebase because `:fonte` wasn't validated. The git-clone
5018 // failure surfaced far downstream at lacre-resolve time with no
5019 // field naming which `:deps` entry carried the typo. The new
5020 // gate moves the check to caixa-build time at the source
5021 // caixa.lisp.
5022 let d = dep_with_fonte(DepSource::Git {
5023 repo: String::new(),
5024 tag: Some("v0.1.0".into()),
5025 rev: None,
5026 branch: None,
5027 });
5028 let err = d.validate().unwrap_err();
5029 assert!(
5030 matches!(err, DepError::FonteRepoEmpty { ref nome } if nome == "caixa-teia"),
5031 "got {err:?}"
5032 );
5033 }
5034
5035 // -- :repo value-shape gate -------------------------------------------
5036 //
5037 // The `:fonte (:tipo git :repo …)` value flows verbatim into the
5038 // caixa-resolver's `git clone <repo>` subprocess. The pre-gate
5039 // codebase admitted any non-empty string; the new
5040 // [`crate::render::is_git_repo_url`] predicate gates the git-porcelain
5041 // URL intersection-floor at validate time, peer with the three pin
5042 // axes (`:tag` + `:branch` via `is_git_ref_name`, `:rev` via
5043 // `is_git_oid`). Every test in this section is a fail-before /
5044 // pass-after pin on a specific authoring footgun.
5045
5046 #[test]
5047 fn validate_rejects_git_fonte_with_repo_carrying_trailing_space() {
5048 // The canonical paste-from-doc footgun on `:repo` — an author
5049 // copies `"github:pleme-io/caixa-teia "` (trailing space) out of
5050 // a doc paragraph. Until this gate landed the empty-repo arm
5051 // passed (the string isn't empty), the resolver issued
5052 // `git clone 'github:pleme-io/caixa-teia '`, and the failure
5053 // surfaced at clone time with a quoting-confused error far from
5054 // the source caixa.lisp. Same paste-from-doc footgun the
5055 // `:tag "v0.1.0 "` gate (e70d213) closes on the peer refname
5056 // axis — now closed on the `:repo` URL axis too.
5057 let d = dep_with_fonte(DepSource::Git {
5058 repo: "github:pleme-io/caixa-teia ".into(),
5059 tag: Some("v0.1.0".into()),
5060 rev: None,
5061 branch: None,
5062 });
5063 let err = d.validate().unwrap_err();
5064 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5065 panic!("expected FonteRepoShape, got other variant");
5066 };
5067 assert_eq!(nome, "caixa-teia");
5068 assert_eq!(repo, "github:pleme-io/caixa-teia ");
5069 assert!(
5070 reason.contains("whitespace"),
5071 "reason must surface the whitespace arm, got {reason:?}"
5072 );
5073 }
5074
5075 #[test]
5076 fn validate_rejects_git_fonte_with_repo_starting_with_dash() {
5077 // The canonical CLI-argument-injection footgun at the `git clone`
5078 // subprocess boundary — `:repo "-upload-pack=evil"` makes git's
5079 // argv parser read the value as a CLI flag, escaping the
5080 // subprocess argument boundary. The `--` separator workaround
5081 // does not fix the typed slot's accepted set; the gate rejects
5082 // the shape upstream at validate time so the resolver never
5083 // invokes a `git clone -…` subprocess.
5084 let d = dep_with_fonte(DepSource::Git {
5085 repo: "-upload-pack=evil".into(),
5086 tag: Some("v0.1.0".into()),
5087 rev: None,
5088 branch: None,
5089 });
5090 let err = d.validate().unwrap_err();
5091 let DepError::FonteRepoShape { repo, reason, .. } = err else {
5092 panic!("expected FonteRepoShape, got other variant");
5093 };
5094 assert_eq!(repo, "-upload-pack=evil");
5095 assert!(
5096 reason.contains("must not start with `-`"),
5097 "reason must surface the leading-`-` arm, got {reason:?}"
5098 );
5099 }
5100
5101 #[test]
5102 fn validate_rejects_git_fonte_with_repo_carrying_embedded_newline() {
5103 // The canonical paste-from-multiline-doc footgun — a `:repo`
5104 // string with an embedded `\n` silently breaks git's URL parser
5105 // and is a class of CRLF-injection at the subprocess-argument
5106 // boundary. Caught by the control-char arm (0x0A < 0x20).
5107 let d = dep_with_fonte(DepSource::Git {
5108 repo: "github:pleme-io/caixa-teia\nrm -rf /".into(),
5109 tag: Some("v0.1.0".into()),
5110 rev: None,
5111 branch: None,
5112 });
5113 let err = d.validate().unwrap_err();
5114 let DepError::FonteRepoShape { reason, .. } = err else {
5115 panic!("expected FonteRepoShape, got other variant");
5116 };
5117 assert!(
5118 reason.contains("control character"),
5119 "reason must surface the control-char arm, got {reason:?}"
5120 );
5121 }
5122
5123 #[test]
5124 fn validate_rejects_git_fonte_with_repo_carrying_tab() {
5125 // Tab is the sibling whitespace footgun (the canonical
5126 // copy-from-aligned-table paste); pinned separately from the
5127 // space arm so a future relaxation that only catches one
5128 // surfaces here.
5129 let d = dep_with_fonte(DepSource::Git {
5130 repo: "github:pleme-io/caixa-teia\t".into(),
5131 tag: Some("v0.1.0".into()),
5132 rev: None,
5133 branch: None,
5134 });
5135 let err = d.validate().unwrap_err();
5136 assert!(
5137 matches!(
5138 err,
5139 DepError::FonteRepoShape { ref reason, .. }
5140 if reason.contains("whitespace")
5141 ),
5142 "got {err:?}"
5143 );
5144 }
5145
5146 #[test]
5147 fn validate_rejects_git_fonte_with_repo_carrying_non_ascii() {
5148 // IDN hosts must be pre-encoded as Punycode (`xn--…`) — raw
5149 // non-ASCII silently breaks at git's URL parser and round-trips
5150 // inconsistently across NFC/NFD normalization on APFS /
5151 // case-folding filesystems. Same intersection-floor
5152 // [`is_git_ref_name`] enforces on the refname axes.
5153 let d = dep_with_fonte(DepSource::Git {
5154 repo: "https://github.com/pleme-io/café".into(),
5155 tag: Some("v0.1.0".into()),
5156 rev: None,
5157 branch: None,
5158 });
5159 let err = d.validate().unwrap_err();
5160 assert!(
5161 matches!(
5162 err,
5163 DepError::FonteRepoShape { ref reason, .. }
5164 if reason.contains("non-ASCII")
5165 ),
5166 "got {err:?}"
5167 );
5168 }
5169
5170 #[test]
5171 fn validate_rejects_git_fonte_with_repo_carrying_fragment_anchor() {
5172 // The fail-before-pass-after pin for the canonical paste-from-
5173 // browser-address-bar footgun on `:repo`: an author copies a
5174 // GitHub permalink to a README anchor / line-permalink and
5175 // forgets to trim the `#fragment` tail. Until this arm landed
5176 // `:repo "https://github.com/pleme-io/caixa-teia#readme"`
5177 // silently passed every prior arm (no whitespace, no control
5178 // chars, no non-ASCII, contains a `:`, doesn't start with `-`
5179 // or `:`), libcurl's URL parser stripped the `#readme` tail
5180 // before opening the HTTPS transport, and the lacre embedded
5181 // the value verbatim in its per-dep BLAKE3 closure — two
5182 // authors whose values differ only in their fragment anchor
5183 // (`#readme` vs `#L42`) resolve to the byte-identical upstream
5184 // `git clone` but lock to two distinct lacres, defeating the
5185 // THEORY.md §V.2 render-determinism contract. Same value-shape
5186 // axis-floor every peer typed surface enforces; peer `:fonte
5187 // :tag` / `:fonte :branch` already reject the byte-class through
5188 // `is_git_ref_name`'s alphabet (refs are leaf identifiers, no
5189 // URL grammar admitted) and `:entrada :paths` rejects `#` as
5190 // part of `is_gateway_api_http_path`'s RFC-3986-reserved set.
5191 let d = dep_with_fonte(DepSource::Git {
5192 repo: "https://github.com/pleme-io/caixa-teia#readme".into(),
5193 tag: Some("v0.1.0".into()),
5194 rev: None,
5195 branch: None,
5196 });
5197 let err = d.validate().unwrap_err();
5198 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5199 panic!("expected FonteRepoShape, got other variant");
5200 };
5201 assert_eq!(nome, "caixa-teia");
5202 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia#readme");
5203 assert!(
5204 reason.contains("must not contain `#`"),
5205 "reason must surface the fragment-`#` arm, got {reason:?}"
5206 );
5207 assert!(
5208 reason.contains("fragment"),
5209 "reason must name the URL fragment grammar, got {reason:?}"
5210 );
5211 }
5212
5213 #[test]
5214 fn validate_rejects_git_fonte_with_repo_carrying_flake_ref_fragment() {
5215 // The symmetric paste-from-Nix-flake-ref footgun — an author
5216 // confuses the Nix flake-reference idiom (`github:foo/
5217 // bar#packageName`, where `#packageName` selects a flake
5218 // output) with the bare git `:repo` shape. The pleme-io
5219 // substrate authors compose flakes downstream of caixa
5220 // (caixa-flake renders a flake.nix), so the cross-idiom leak
5221 // is the canonical near-miss: the author writes the
5222 // flake-ref shape into a git `:repo` slot. Pinned separately
5223 // from the HTTPS-anchor arm so a future relaxation that
5224 // narrows to one URL scheme surfaces here.
5225 let d = dep_with_fonte(DepSource::Git {
5226 repo: "github:pleme-io/caixa-teia#caixa-teia".into(),
5227 tag: Some("v0.1.0".into()),
5228 rev: None,
5229 branch: None,
5230 });
5231 let err = d.validate().unwrap_err();
5232 let DepError::FonteRepoShape { reason, .. } = err else {
5233 panic!("expected FonteRepoShape, got other variant");
5234 };
5235 assert!(
5236 reason.contains("must not contain `#`"),
5237 "reason must surface the fragment-`#` arm, got {reason:?}"
5238 );
5239 assert!(
5240 reason.contains("Nix flake"),
5241 "reason must name the Nix-flake-ref cross-idiom footgun, got {reason:?}"
5242 );
5243 }
5244
5245 #[test]
5246 fn validate_rejects_git_fonte_with_repo_carrying_query_string() {
5247 // The fail-before-pass-after pin for the canonical paste-from-
5248 // browser-address-bar footgun on `:repo` (peer with the
5249 // a68f818 fragment-`#` arm on the same axis). An author
5250 // copies a GitHub tab deep-link out of the address bar and
5251 // forgets to trim the `?tab=…` query tail. Until this arm
5252 // landed `:repo "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"`
5253 // silently passed every prior arm (no whitespace, no control
5254 // chars, no non-ASCII, no `#` fragment, contains a `:`,
5255 // doesn't start with `-` or `:`); GitHub silently ignored
5256 // the `?query` tail and served the same repo regardless;
5257 // the lacre embedded the value verbatim in its per-dep
5258 // BLAKE3 closure — two authors whose values differ only in
5259 // their query tail (`?tab=readme-ov-file` vs `?ref=main` vs
5260 // `?utm_source=twitter`) resolve to the byte-identical
5261 // upstream `git clone` but lock to two distinct lacres,
5262 // defeating the THEORY.md §V.2 render-determinism contract
5263 // on the same axis the `#` fragment arm closes. Same value-
5264 // shape axis-floor every peer typed surface enforces; peer
5265 // `:fonte :tag` / `:fonte :branch` already reject the byte-
5266 // class through `is_git_ref_name`'s alphabet (refspec glob
5267 // wildcards, caixa-core/src/render.rs:1426) and `:entrada
5268 // :paths` rejects `?` as the query separator in
5269 // `is_gateway_api_http_path` (caixa-core/src/render.rs:473).
5270 let d = dep_with_fonte(DepSource::Git {
5271 repo: "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file".into(),
5272 tag: Some("v0.1.0".into()),
5273 rev: None,
5274 branch: None,
5275 });
5276 let err = d.validate().unwrap_err();
5277 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5278 panic!("expected FonteRepoShape, got other variant");
5279 };
5280 assert_eq!(nome, "caixa-teia");
5281 assert_eq!(
5282 repo,
5283 "https://github.com/pleme-io/caixa-teia?tab=readme-ov-file"
5284 );
5285 assert!(
5286 reason.contains("must not contain `?`"),
5287 "reason must surface the query-`?` arm, got {reason:?}"
5288 );
5289 assert!(
5290 reason.contains("query"),
5291 "reason must name the URL query grammar, got {reason:?}"
5292 );
5293 }
5294
5295 #[test]
5296 fn validate_rejects_git_fonte_with_repo_carrying_utm_tracker() {
5297 // The symmetric paste-from-social-share footgun — an author
5298 // copies a repo URL out of a Slack unfurl / Twitter share /
5299 // newsletter link / Discord embed and forgets to trim the
5300 // `?utm_source=…` / `?utm_medium=…` / `?utm_campaign=…`
5301 // campaign-tracker tail. Every major social-share / unfurl /
5302 // newsletter platform appends these UTM parameters; the
5303 // canonical near-miss on the `:repo` axis. Pinned separately
5304 // from the GitHub-tab-deep-link arm so a future relaxation
5305 // that narrows to one query-parameter class surfaces here.
5306 let d = dep_with_fonte(DepSource::Git {
5307 repo: "https://github.com/pleme-io/caixa-teia?utm_source=twitter&utm_campaign=launch"
5308 .into(),
5309 tag: Some("v0.1.0".into()),
5310 rev: None,
5311 branch: None,
5312 });
5313 let err = d.validate().unwrap_err();
5314 let DepError::FonteRepoShape { reason, .. } = err else {
5315 panic!("expected FonteRepoShape, got other variant");
5316 };
5317 assert!(
5318 reason.contains("must not contain `?`"),
5319 "reason must surface the query-`?` arm, got {reason:?}"
5320 );
5321 assert!(
5322 reason.contains("campaign-tracker"),
5323 "reason must name the campaign-tracker paste footgun, got {reason:?}"
5324 );
5325 }
5326
5327 #[test]
5328 fn fonte_repo_fragment_fires_before_query_when_fragment_first() {
5329 // Cascade pin: the fragment-`#` arm and the query-`?` arm are
5330 // both per-byte arms inside the same `for &b in s.as_bytes()`
5331 // loop, so the byte that appears first in the value's byte
5332 // order wins. A `:repo "https://github.com/p/x#readme?ref=main"`
5333 // (fragment before query — unusual URL-grammar but value-
5334 // disjoint at byte level) carries both `#` and `?`; the `#`
5335 // byte appears first, so the fragment-`#` arm fires, surfacing
5336 // the more self-locating diagnostic on the byte the author
5337 // pasted earliest in the URL. Mirrors the peer cascade
5338 // discipline `fonte_repo_control_char_fires_before_fragment`
5339 // pins on the prior `:repo` byte-class arm.
5340 let d = dep_with_fonte(DepSource::Git {
5341 repo: "https://github.com/pleme-io/caixa-teia#readme?ref=main".into(),
5342 tag: Some("v0.1.0".into()),
5343 rev: None,
5344 branch: None,
5345 });
5346 let err = d.validate().unwrap_err();
5347 let DepError::FonteRepoShape { reason, .. } = err else {
5348 panic!("expected FonteRepoShape, got other variant");
5349 };
5350 assert!(
5351 reason.contains("must not contain `#`"),
5352 "reason must surface the fragment-`#` arm (fires before query-`?` when \
5353 `#` byte appears first in value), got {reason:?}"
5354 );
5355 }
5356
5357 #[test]
5358 fn fonte_repo_control_char_fires_before_fragment() {
5359 // Cascade pin: the control-char arm structurally precedes the
5360 // fragment-`#` arm. A value like `"github:p/x\n#readme"` probes
5361 // positive on both arms (contains LF and `#`), but the narrower
5362 // POSIX-syscall-rejected / CRLF-injection-class diagnostic
5363 // (`control character`) wins so the author sees the more
5364 // self-locating arm first. Mirrors the peer cascade discipline
5365 // every prior `:repo` byte-class arm establishes.
5366 let d = dep_with_fonte(DepSource::Git {
5367 repo: "github:pleme-io/caixa-teia\n#readme".into(),
5368 tag: Some("v0.1.0".into()),
5369 rev: None,
5370 branch: None,
5371 });
5372 let err = d.validate().unwrap_err();
5373 let DepError::FonteRepoShape { reason, .. } = err else {
5374 panic!("expected FonteRepoShape, got other variant");
5375 };
5376 assert!(
5377 reason.contains("control character"),
5378 "reason must surface the control-char arm, got {reason:?}"
5379 );
5380 }
5381
5382 #[test]
5383 fn validate_rejects_git_fonte_with_repo_carrying_embedded_backslash() {
5384 // The fail-before-pass-after pin for the canonical Windows-
5385 // file-path-confusion footgun on `:repo` (peer with the 3a4e1d7
5386 // backslash arm on the sibling `:caminho` path-fonte axis).
5387 // An author pastes a Windows Explorer address-bar / PowerShell
5388 // `Get-Location` output into a `file://` URL slot, producing
5389 // `file:///C:\Users\me\caixa-teia`. Until this arm landed the
5390 // value silently passed every prior arm (no whitespace, no
5391 // control chars, no non-ASCII, no `#`, no `?`, doesn't start
5392 // with `-` or `:`); libcurl's URL parser silently translates
5393 // `\` → `/` on some platforms and refuses it on others, so
5394 // the byte rides verbatim into the lacre's per-dep content-
5395 // address but is silently rewritten / rejected at the wire —
5396 // two authors whose `:repo` values differ only in backslash-
5397 // vs-forward-slash (`file:///C:\path` vs `file:///C:/path`)
5398 // resolve to the byte-identical local clone but lock to two
5399 // distinct BLAKE3 closures, defeating the THEORY.md §V.2
5400 // render-determinism contract on the same axis the `#`
5401 // fragment and `?` query arms close. Same value-shape axis-
5402 // floor every peer typed surface enforces; the `:caminho`
5403 // 3a4e1d7 arm closes the same byte on the path-fonte axis.
5404 let d = dep_with_fonte(DepSource::Git {
5405 repo: "file:///C:\\Users\\me\\caixa-teia".into(),
5406 tag: Some("v0.1.0".into()),
5407 rev: None,
5408 branch: None,
5409 });
5410 let err = d.validate().unwrap_err();
5411 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5412 panic!("expected FonteRepoShape, got other variant");
5413 };
5414 assert_eq!(nome, "caixa-teia");
5415 assert_eq!(repo, "file:///C:\\Users\\me\\caixa-teia");
5416 assert!(
5417 reason.contains("must not contain `\\`"),
5418 "reason must surface the backslash-`\\` arm, got {reason:?}"
5419 );
5420 assert!(
5421 reason.contains("Windows"),
5422 "reason must name the Windows-path-confusion footgun, got {reason:?}"
5423 );
5424 }
5425
5426 #[test]
5427 fn validate_rejects_git_fonte_with_repo_carrying_mangled_https_backslashes() {
5428 // The symmetric Win32-shell-mangled-slashes footgun — an author
5429 // copies `https://github.com/foo/bar` into a Win32 shell that
5430 // rewrites every `/` to `\` (the canonical `cmd.exe` path-
5431 // separator-coercion bug), pastes the result into a `:repo`
5432 // slot, and produces `https:\\github.com\foo\bar`. Pinned
5433 // separately from the `file://` Explorer-paste arm so a future
5434 // relaxation that narrows to one URL scheme surfaces here.
5435 let d = dep_with_fonte(DepSource::Git {
5436 repo: "https:\\\\github.com\\pleme-io\\caixa-teia".into(),
5437 tag: Some("v0.1.0".into()),
5438 rev: None,
5439 branch: None,
5440 });
5441 let err = d.validate().unwrap_err();
5442 let DepError::FonteRepoShape { reason, .. } = err else {
5443 panic!("expected FonteRepoShape, got other variant");
5444 };
5445 assert!(
5446 reason.contains("must not contain `\\`"),
5447 "reason must surface the backslash-`\\` arm, got {reason:?}"
5448 );
5449 assert!(
5450 reason.contains("path separator") || reason.contains("path-segment separator"),
5451 "reason must name the URL path-segment separator grammar, got {reason:?}"
5452 );
5453 }
5454
5455 #[test]
5456 fn fonte_repo_fragment_fires_before_backslash_when_fragment_first() {
5457 // Cascade pin: the fragment-`#` arm and the backslash-`\` arm
5458 // are both per-byte arms inside the same `for &b in s.as_bytes()`
5459 // loop, so the byte that appears first in the value's byte order
5460 // wins. A `:repo "https://github.com/p/x#readme\\foo"` carries
5461 // both `#` and `\`; the `#` byte appears first, so the fragment-
5462 // `#` arm fires, surfacing the more self-locating diagnostic on
5463 // the byte the author pasted earliest in the URL. Mirrors the
5464 // peer cascade discipline `fonte_repo_fragment_fires_before_query_when_fragment_first`
5465 // pins on the prior `:repo` byte-class arm.
5466 let d = dep_with_fonte(DepSource::Git {
5467 repo: "https://github.com/pleme-io/caixa-teia#readme\\foo".into(),
5468 tag: Some("v0.1.0".into()),
5469 rev: None,
5470 branch: None,
5471 });
5472 let err = d.validate().unwrap_err();
5473 let DepError::FonteRepoShape { reason, .. } = err else {
5474 panic!("expected FonteRepoShape, got other variant");
5475 };
5476 assert!(
5477 reason.contains("must not contain `#`"),
5478 "reason must surface the fragment-`#` arm (fires before backslash-`\\` when \
5479 `#` byte appears first in value), got {reason:?}"
5480 );
5481 }
5482
5483 #[test]
5484 fn validate_rejects_git_fonte_with_repo_carrying_uri_template_placeholder() {
5485 // The fail-before-pass-after pin for the canonical URI Template
5486 // (RFC 6570) placeholder footgun on `:repo`. An author copies a
5487 // README quick-start snippet / OpenAPI `servers:` URL / Helm
5488 // chart `home:` template that carries unresolved
5489 // `{org}` / `{repo}` placeholders and pastes the raw template
5490 // into the `:repo` slot, expecting the substrate to resolve the
5491 // placeholder downstream. Until this arm landed the value
5492 // silently passed every prior arm (no whitespace, no control
5493 // chars, no non-ASCII, no `#`, no `?`, no `\`, doesn't start
5494 // with `-` or `:`); libcurl percent-encodes `{` / `}` to `%7B`
5495 // / `%7D` on the wire, so the byte rides verbatim into the
5496 // lacre's per-dep content-address but round-trips inconsistently
5497 // between the lacre's per-dep content-address and the
5498 // resolver's `git clone <repo>` invocation, defeating the
5499 // THEORY.md §V.2 render-determinism contract on the same axis
5500 // the `#` fragment, `?` query, and `\` backslash arms close;
5501 // every git porcelain entry-point additionally fetches a
5502 // nonexistent literal-`{placeholder}`-named path far from the
5503 // source caixa.lisp.
5504 let d = dep_with_fonte(DepSource::Git {
5505 repo: "https://github.com/{org}/caixa-teia".into(),
5506 tag: Some("v0.1.0".into()),
5507 rev: None,
5508 branch: None,
5509 });
5510 let err = d.validate().unwrap_err();
5511 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5512 panic!("expected FonteRepoShape, got other variant");
5513 };
5514 assert_eq!(nome, "caixa-teia");
5515 assert_eq!(repo, "https://github.com/{org}/caixa-teia");
5516 assert!(
5517 reason.contains("must not contain `{`"),
5518 "reason must surface the open-brace `{{` arm, got {reason:?}"
5519 );
5520 assert!(
5521 reason.contains("URI Template") || reason.contains("RFC 6570"),
5522 "reason must name the RFC 6570 URI Template grammar, got {reason:?}"
5523 );
5524 }
5525
5526 #[test]
5527 fn validate_rejects_git_fonte_with_repo_carrying_handlebars_doubled_brace() {
5528 // The symmetric Mustache / Handlebars doubled-brace
5529 // substitution-form footgun every CI / IaC templating engine
5530 // (Argo Workflows, Jinja2, Liquid, Vue / Angular interpolation,
5531 // GitHub Actions `${{ … }}` even though Actions uses `${{`) /
5532 // chart README quick-start snippet emits. Pinned separately
5533 // from the single-`{` `{org}` arm so a future relaxation that
5534 // narrows to one substitution-form surfaces here.
5535 let d = dep_with_fonte(DepSource::Git {
5536 repo: "https://github.com/{{org}}/caixa-teia".into(),
5537 tag: Some("v0.1.0".into()),
5538 rev: None,
5539 branch: None,
5540 });
5541 let err = d.validate().unwrap_err();
5542 let DepError::FonteRepoShape { reason, .. } = err else {
5543 panic!("expected FonteRepoShape, got other variant");
5544 };
5545 assert!(
5546 reason.contains("must not contain `{`"),
5547 "reason must surface the open-brace `{{` arm, got {reason:?}"
5548 );
5549 }
5550
5551 #[test]
5552 fn validate_rejects_git_fonte_with_repo_carrying_closing_brace_only() {
5553 // Asymmetric `}`-only shape — covers the closing-brace-by-
5554 // itself footgun (an author truncated `{org}/{repo}` mid-edit
5555 // and left a trailing `}` from the prior template fragment,
5556 // or pasted a value that included a closing brace from a
5557 // surrounding shell context). Pinned to ensure the predicate
5558 // refuses each brace independently rather than only when both
5559 // appear — a future regression that ANDs the two byte tests
5560 // surfaces here.
5561 let d = dep_with_fonte(DepSource::Git {
5562 repo: "https://github.com/pleme-io/caixa-teia}".into(),
5563 tag: Some("v0.1.0".into()),
5564 rev: None,
5565 branch: None,
5566 });
5567 let err = d.validate().unwrap_err();
5568 let DepError::FonteRepoShape { reason, .. } = err else {
5569 panic!("expected FonteRepoShape, got other variant");
5570 };
5571 assert!(
5572 reason.contains("must not contain `}`"),
5573 "reason must surface the close-brace `}}` arm, got {reason:?}"
5574 );
5575 }
5576
5577 #[test]
5578 fn fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first() {
5579 // Cascade pin: the fragment-`#` arm and the template-`{` /
5580 // `}` arm are both per-byte arms inside the same
5581 // `for &b in s.as_bytes()` loop, so the byte that appears
5582 // first in the value's byte order wins. A `:repo
5583 // "https://github.com/p/x#readme{org}"` carries both `#` and
5584 // `{`; the `#` byte appears first, so the fragment-`#` arm
5585 // fires, surfacing the more self-locating diagnostic on the
5586 // byte the author pasted earliest in the URL. Mirrors the
5587 // peer cascade discipline `fonte_repo_fragment_fires_before_backslash_when_fragment_first`
5588 // pins on the prior `:repo` byte-class arm.
5589 let d = dep_with_fonte(DepSource::Git {
5590 repo: "https://github.com/pleme-io/caixa-teia#readme{org}".into(),
5591 tag: Some("v0.1.0".into()),
5592 rev: None,
5593 branch: None,
5594 });
5595 let err = d.validate().unwrap_err();
5596 let DepError::FonteRepoShape { reason, .. } = err else {
5597 panic!("expected FonteRepoShape, got other variant");
5598 };
5599 assert!(
5600 reason.contains("must not contain `#`"),
5601 "reason must surface the fragment-`#` arm (fires before template-`{{` when \
5602 `#` byte appears first in value), got {reason:?}"
5603 );
5604 }
5605
5606 #[test]
5607 fn validate_rejects_git_fonte_with_repo_carrying_output_redirection() {
5608 // The fail-before-pass-after pin for the canonical
5609 // shell-output-redirection footgun on `:repo`: an author
5610 // pastes a shell-pipeline tail (`git clone <repo> > build.log`
5611 // / `… >output.txt`) into the `:repo` slot without trimming
5612 // the redirect. Until this arm landed the value silently
5613 // passed every prior arm (no whitespace, no control chars,
5614 // no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, doesn't
5615 // start with `-` or `:`); RFC 3986 §2 lists `<` / `>` in the
5616 // 'delims' / 'unwise' set and the WHATWG URL spec's fragment
5617 // percent-encode set maps `>` → `%3E` on the wire, so the
5618 // byte rides verbatim into the lacre's per-dep BLAKE3 closure
5619 // but is silently rewritten or rejected at libcurl's URL-
5620 // parser layer — two authors whose values differ only in
5621 // their redirect tail (`>build.log` vs nothing) resolve to
5622 // the byte-identical upstream `git clone` but lock to two
5623 // distinct lacres, defeating the THEORY.md §V.2 render-
5624 // determinism contract. Peer with the `:caminho` axis's
5625 // `FonteCaminhoShellRedirection` arm (e457141) on the sibling
5626 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5627 // byte RFC-3986-reserved set on `:entrada :paths`.
5628 let d = dep_with_fonte(DepSource::Git {
5629 repo: "https://github.com/pleme-io/caixa-teia>build.log".into(),
5630 tag: Some("v0.1.0".into()),
5631 rev: None,
5632 branch: None,
5633 });
5634 let err = d.validate().unwrap_err();
5635 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5636 panic!("expected FonteRepoShape, got other variant");
5637 };
5638 assert_eq!(nome, "caixa-teia");
5639 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia>build.log");
5640 assert!(
5641 reason.contains("must not contain `>`"),
5642 "reason must surface the output-redirection `>` arm, got {reason:?}"
5643 );
5644 assert!(
5645 reason.contains("redirection") || reason.contains("'delims'"),
5646 "reason must name the shell-redirection / RFC-3986-unwise rationale, got {reason:?}"
5647 );
5648 }
5649
5650 #[test]
5651 fn validate_rejects_git_fonte_with_repo_carrying_input_redirection() {
5652 // The symmetric shell-input-redirection footgun — an author
5653 // pastes a shell-pipeline head (`git clone <input.url` /
5654 // `cat <README.md`) into the `:repo` slot. Pinned separately
5655 // from the `>`-output arm so a future relaxation that only
5656 // catches one of the two redirect bytes surfaces here. Peer
5657 // with the `:caminho` axis's `FonteCaminhoShellRedirection`
5658 // arm which closes both `<` and `>` under the same banner.
5659 let d = dep_with_fonte(DepSource::Git {
5660 repo: "https://github.com/pleme-io/caixa-teia<input.url".into(),
5661 tag: Some("v0.1.0".into()),
5662 rev: None,
5663 branch: None,
5664 });
5665 let err = d.validate().unwrap_err();
5666 let DepError::FonteRepoShape { reason, .. } = err else {
5667 panic!("expected FonteRepoShape, got other variant");
5668 };
5669 assert!(
5670 reason.contains("must not contain `<`"),
5671 "reason must surface the input-redirection `<` arm, got {reason:?}"
5672 );
5673 assert!(
5674 reason.contains("RFC 3986") || reason.contains("'unwise'"),
5675 "reason must name the RFC 3986 'unwise' grammar, got {reason:?}"
5676 );
5677 }
5678
5679 #[test]
5680 fn validate_rejects_git_fonte_with_repo_carrying_backtick_command_substitution() {
5681 // The fail-before-pass-after pin for the canonical
5682 // paste-from-shell-prompt-with-backticked-substitution footgun
5683 // on `:repo` (peer with the c4d62b3 backtick arm on the sibling
5684 // `:caminho` path-fonte axis). An author pastes a URL whose
5685 // segment carries a backticked command-substitution wrapper
5686 // (`` `whoami` ``, `` `git config user.name` ``, `` `pwd` ``)
5687 // from a doc / README quick-start snippet that expected the
5688 // substrate to substitute the value downstream. Until this arm
5689 // landed the value silently passed every prior arm (no
5690 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5691 // no `\`, no `{`/`}`, no `<`/`>`, doesn't start with `-` or
5692 // `:`); RFC 3986 §2 lists the backtick byte in the 'delims' /
5693 // 'unwise' set and the WHATWG URL spec's fragment percent-
5694 // encode set maps `` ` `` → `%60` on the wire, so the byte
5695 // rides verbatim into the lacre's per-dep BLAKE3 closure but
5696 // is silently rewritten or rejected at libcurl's URL-parser
5697 // layer — two authors whose values differ only in their
5698 // backtick wrapper (`` `whoami` `` vs nothing) resolve to the
5699 // byte-identical upstream `git clone` but lock to two distinct
5700 // lacres, defeating the THEORY.md §V.2 render-determinism
5701 // contract. Peer with the `:caminho` axis's
5702 // `FonteCaminhoShellCommandSubstitution` arm (c4d62b3) on the
5703 // sibling path-fonte axis, and `is_gateway_api_http_path`'s
5704 // eleven-byte RFC-3986-reserved set on `:entrada :paths`.
5705 let d = dep_with_fonte(DepSource::Git {
5706 repo: "https://github.com/pleme-io/`whoami`/caixa-teia".into(),
5707 tag: Some("v0.1.0".into()),
5708 rev: None,
5709 branch: None,
5710 });
5711 let err = d.validate().unwrap_err();
5712 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5713 panic!("expected FonteRepoShape, got other variant");
5714 };
5715 assert_eq!(nome, "caixa-teia");
5716 assert_eq!(repo, "https://github.com/pleme-io/`whoami`/caixa-teia");
5717 assert!(
5718 reason.contains("must not contain `` ` ``"),
5719 "reason must surface the backtick command-substitution arm, got {reason:?}"
5720 );
5721 assert!(
5722 reason.contains("command-substitution") || reason.contains("'unwise'"),
5723 "reason must name the shell-command-substitution / RFC-3986-unwise rationale, \
5724 got {reason:?}"
5725 );
5726 }
5727
5728 #[test]
5729 fn fonte_repo_fragment_fires_before_backtick_when_fragment_first() {
5730 // Cascade pin: the fragment-`#` arm and the backtick command-
5731 // substitution arm are both per-byte arms inside the same
5732 // `for &b in s.as_bytes()` loop, so the byte that appears first
5733 // in the value's byte order wins. A `:repo
5734 // "https://github.com/p/x#readme/`whoami`"` carries both `#`
5735 // and backtick; the `#` byte appears first, so the fragment-
5736 // `#` arm fires, surfacing the more self-locating diagnostic
5737 // on the byte the author pasted earliest in the URL. Mirrors
5738 // the peer cascade discipline
5739 // `fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first`
5740 // pins on the prior `:repo` byte-class arm.
5741 let d = dep_with_fonte(DepSource::Git {
5742 repo: "https://github.com/pleme-io/caixa-teia#readme/`whoami`".into(),
5743 tag: Some("v0.1.0".into()),
5744 rev: None,
5745 branch: None,
5746 });
5747 let err = d.validate().unwrap_err();
5748 let DepError::FonteRepoShape { reason, .. } = err else {
5749 panic!("expected FonteRepoShape, got other variant");
5750 };
5751 assert!(
5752 reason.contains("must not contain `#`"),
5753 "reason must surface the fragment-`#` arm (fires before backtick when `#` byte \
5754 appears first in value), got {reason:?}"
5755 );
5756 }
5757
5758 #[test]
5759 fn fonte_repo_shell_redirection_fires_before_backtick_when_redirection_first() {
5760 // Cascade pin: the shell-redirection `<` / `>` arm and the
5761 // backtick command-substitution arm are both per-byte arms
5762 // inside the same `for &b in s.as_bytes()` loop, so the byte
5763 // that appears first in the value's byte order wins. A `:repo
5764 // "https://github.com/p/x>build.log/`whoami`"` carries both
5765 // `>` and backtick; the `>` byte appears first, so the
5766 // shell-redirection arm fires, surfacing the more self-
5767 // locating diagnostic on the byte the author pasted earliest
5768 // in the URL. Pins the natural-order cascade so a future
5769 // reorder of the per-byte arms surfaces here.
5770 let d = dep_with_fonte(DepSource::Git {
5771 repo: "https://github.com/pleme-io/caixa-teia>build.log/`whoami`".into(),
5772 tag: Some("v0.1.0".into()),
5773 rev: None,
5774 branch: None,
5775 });
5776 let err = d.validate().unwrap_err();
5777 let DepError::FonteRepoShape { reason, .. } = err else {
5778 panic!("expected FonteRepoShape, got other variant");
5779 };
5780 assert!(
5781 reason.contains("must not contain `>`"),
5782 "reason must surface the shell-redirection `>` arm (fires before backtick when \
5783 `>` byte appears first in value), got {reason:?}"
5784 );
5785 }
5786
5787 #[test]
5788 fn fonte_repo_fragment_fires_before_shell_redirection_when_fragment_first() {
5789 // Cascade pin: the fragment-`#` arm and the shell-redirection
5790 // `<` / `>` arm are both per-byte arms inside the same
5791 // `for &b in s.as_bytes()` loop, so the byte that appears
5792 // first in the value's byte order wins. A `:repo
5793 // "https://github.com/p/x#readme>build.log"` carries both
5794 // `#` and `>`; the `#` byte appears first, so the fragment-
5795 // `#` arm fires, surfacing the more self-locating diagnostic
5796 // on the byte the author pasted earliest in the URL. Mirrors
5797 // the peer cascade discipline
5798 // `fonte_repo_fragment_fires_before_template_placeholder_when_fragment_first`
5799 // pins on the prior `:repo` byte-class arm.
5800 let d = dep_with_fonte(DepSource::Git {
5801 repo: "https://github.com/pleme-io/caixa-teia#readme>build.log".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 { reason, .. } = err else {
5808 panic!("expected FonteRepoShape, got other variant");
5809 };
5810 assert!(
5811 reason.contains("must not contain `#`"),
5812 "reason must surface the fragment-`#` arm (fires before shell-redirection `>` when \
5813 `#` byte appears first in value), got {reason:?}"
5814 );
5815 }
5816
5817 #[test]
5818 fn validate_rejects_git_fonte_with_repo_carrying_shell_pipe() {
5819 // The fail-before-pass-after pin for the canonical
5820 // paste-from-shell-prompt-with-piped-pipeline footgun on
5821 // `:repo` (peer with the 124106f pipe arm on the sibling
5822 // `:caminho` path-fonte axis). An author pastes a shell
5823 // pipeline (`git clone <url> | tee build.log`,
5824 // `git ls-remote <url> | head`) into the `:repo` slot,
5825 // forgetting to trim the `| <consumer>` tail. Until this arm
5826 // landed the value silently passed every prior arm (no
5827 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
5828 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, doesn't start
5829 // with `-` or `:`); RFC 3986 §2 lists the pipe byte in the
5830 // 'unwise' set and the WHATWG URL spec's fragment percent-
5831 // encode set maps `|` → `%7C` on the wire, so the byte rides
5832 // verbatim into the lacre's per-dep BLAKE3 closure but is
5833 // silently rewritten or rejected at libcurl's URL-parser
5834 // layer — two authors whose values differ only in their pipe
5835 // tail (`|tee build.log` vs nothing) resolve to the byte-
5836 // identical upstream `git clone` but lock to two distinct
5837 // lacres, defeating the THEORY.md §V.2 render-determinism
5838 // contract. Peer with the `:caminho` axis's
5839 // `FonteCaminhoShellPipe` arm (124106f) on the sibling path-
5840 // fonte axis, and `is_gateway_api_http_path`'s eleven-byte
5841 // RFC-3986-reserved set on `:entrada :paths`.
5842 let d = dep_with_fonte(DepSource::Git {
5843 repo: "https://github.com/pleme-io/caixa-teia|tee build.log".into(),
5844 tag: Some("v0.1.0".into()),
5845 rev: None,
5846 branch: None,
5847 });
5848 let err = d.validate().unwrap_err();
5849 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5850 panic!("expected FonteRepoShape, got other variant");
5851 };
5852 assert_eq!(nome, "caixa-teia");
5853 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia|tee build.log");
5854 assert!(
5855 reason.contains("must not contain `|`"),
5856 "reason must surface the shell-pipe arm, got {reason:?}"
5857 );
5858 assert!(
5859 reason.contains("pipe") || reason.contains("'unwise'"),
5860 "reason must name the shell-pipe / RFC-3986-unwise rationale, got {reason:?}"
5861 );
5862 }
5863
5864 #[test]
5865 fn fonte_repo_fragment_fires_before_pipe_when_fragment_first() {
5866 // Cascade pin: the fragment-`#` arm and the pipe arm are both
5867 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
5868 // so the byte that appears first in the value's byte order
5869 // wins. A `:repo "https://github.com/p/x#readme|tee"` carries
5870 // both `#` and `|`; the `#` byte appears first, so the
5871 // fragment-`#` arm fires, surfacing the more self-locating
5872 // diagnostic on the byte the author pasted earliest in the
5873 // URL. Mirrors the peer cascade discipline
5874 // `fonte_repo_fragment_fires_before_backtick_when_fragment_first`
5875 // pins on the prior `:repo` byte-class arm.
5876 let d = dep_with_fonte(DepSource::Git {
5877 repo: "https://github.com/pleme-io/caixa-teia#readme|tee".into(),
5878 tag: Some("v0.1.0".into()),
5879 rev: None,
5880 branch: None,
5881 });
5882 let err = d.validate().unwrap_err();
5883 let DepError::FonteRepoShape { reason, .. } = err else {
5884 panic!("expected FonteRepoShape, got other variant");
5885 };
5886 assert!(
5887 reason.contains("must not contain `#`"),
5888 "reason must surface the fragment-`#` arm (fires before pipe when `#` byte \
5889 appears first in value), got {reason:?}"
5890 );
5891 }
5892
5893 #[test]
5894 fn fonte_repo_backtick_fires_before_pipe_when_backtick_first() {
5895 // Cascade pin: the backtick arm and the pipe arm are both per-
5896 // byte arms inside the same `for &b in s.as_bytes()` loop, so
5897 // the byte that appears first in the value's byte order wins.
5898 // A `:repo "https://github.com/p/x/`whoami`|tee"` carries both
5899 // `` ` `` and `|`; the backtick byte appears first, so the
5900 // backtick arm fires, surfacing the more self-locating
5901 // diagnostic on the byte the author pasted earliest in the
5902 // URL. Pins the natural-order cascade so a future reorder of
5903 // the per-byte arms surfaces here.
5904 let d = dep_with_fonte(DepSource::Git {
5905 repo: "https://github.com/pleme-io/caixa-teia/`whoami`|tee".into(),
5906 tag: Some("v0.1.0".into()),
5907 rev: None,
5908 branch: None,
5909 });
5910 let err = d.validate().unwrap_err();
5911 let DepError::FonteRepoShape { reason, .. } = err else {
5912 panic!("expected FonteRepoShape, got other variant");
5913 };
5914 assert!(
5915 reason.contains("must not contain `` ` ``"),
5916 "reason must surface the backtick arm (fires before pipe when `` ` `` byte \
5917 appears first in value), got {reason:?}"
5918 );
5919 }
5920
5921 #[test]
5922 fn validate_rejects_git_fonte_with_repo_carrying_shell_command_separator() {
5923 // The fail-before-pass-after pin for the canonical
5924 // paste-from-shell-prompt-with-sequential-command-tail footgun
5925 // on `:repo` (peer with the 05c358e `;` arm on the sibling
5926 // `:caminho` path-fonte axis). An author pastes a shell
5927 // one-liner that chained a cleanup tail after the URL
5928 // (`git clone <url>; rm -rf build`, `git ls-remote <url>;
5929 // echo done`) into the `:repo` slot, forgetting to trim the
5930 // `; <cmd>` tail. Until this arm landed the value silently
5931 // passed every prior `is_git_repo_url` arm (no whitespace, no
5932 // control chars, no non-ASCII, no `#`, no `?`, no `\`, no
5933 // `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, doesn't start with
5934 // `-` or `:`); RFC 3986 §2 lists `;` in the 'sub-delims' /
5935 // reserved set and the WHATWG URL spec's fragment percent-
5936 // encode set maps `;` → `%3B` on the wire, so the byte rides
5937 // verbatim into the lacre's per-dep BLAKE3 closure but is
5938 // silently rewritten at libcurl's URL-parser layer — two
5939 // authors whose values differ only in their sequential-command
5940 // tail (`; rm -rf build` vs nothing) resolve to the byte-
5941 // identical upstream `git clone` but lock to two distinct
5942 // lacres, defeating the THEORY.md §V.2 render-determinism
5943 // contract. Peer with the `:caminho` axis's
5944 // `FonteCaminhoShellSemicolon` arm (05c358e) on the sibling
5945 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
5946 // byte RFC-3986-reserved set on `:entrada :paths`.
5947 let d = dep_with_fonte(DepSource::Git {
5948 repo: "https://github.com/pleme-io/caixa-teia; rm -rf build".into(),
5949 tag: Some("v0.1.0".into()),
5950 rev: None,
5951 branch: None,
5952 });
5953 let err = d.validate().unwrap_err();
5954 let DepError::FonteRepoShape { nome, repo, reason } = err else {
5955 panic!("expected FonteRepoShape, got other variant");
5956 };
5957 assert_eq!(nome, "caixa-teia");
5958 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia; rm -rf build");
5959 assert!(
5960 reason.contains("must not contain `;`"),
5961 "reason must surface the shell-command-separator arm, got {reason:?}"
5962 );
5963 assert!(
5964 reason.contains("sequential-command") || reason.contains("'sub-delims'"),
5965 "reason must name the shell-command-separator / RFC-3986-sub-delims \
5966 rationale, got {reason:?}"
5967 );
5968 }
5969
5970 #[test]
5971 fn fonte_repo_fragment_fires_before_semicolon_when_fragment_first() {
5972 // Cascade pin: the fragment-`#` arm and the semicolon arm are
5973 // both per-byte arms inside the same `for &b in s.as_bytes()`
5974 // loop, so the byte that appears first in the value's byte
5975 // order wins. A `:repo "https://github.com/p/x#readme; rm"`
5976 // carries both `#` and `;`; the `#` byte appears first, so the
5977 // fragment-`#` arm fires, surfacing the more self-locating
5978 // diagnostic on the byte the author pasted earliest in the URL.
5979 // Mirrors the peer cascade discipline
5980 // `fonte_repo_fragment_fires_before_pipe_when_fragment_first`
5981 // pins on the prior `:repo` byte-class arm.
5982 let d = dep_with_fonte(DepSource::Git {
5983 repo: "https://github.com/pleme-io/caixa-teia#readme; rm".into(),
5984 tag: Some("v0.1.0".into()),
5985 rev: None,
5986 branch: None,
5987 });
5988 let err = d.validate().unwrap_err();
5989 let DepError::FonteRepoShape { reason, .. } = err else {
5990 panic!("expected FonteRepoShape, got other variant");
5991 };
5992 assert!(
5993 reason.contains("must not contain `#`"),
5994 "reason must surface the fragment-`#` arm (fires before semicolon when `#` \
5995 byte appears first in value), got {reason:?}"
5996 );
5997 }
5998
5999 #[test]
6000 fn fonte_repo_pipe_fires_before_semicolon_when_pipe_first() {
6001 // Cascade pin: the pipe arm and the semicolon arm are both
6002 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6003 // so the byte that appears first in the value's byte order
6004 // wins. A `:repo "https://github.com/p/x|tee; rm"` carries
6005 // both `|` and `;`; the `|` byte appears first, so the
6006 // pipe arm fires, surfacing the more self-locating diagnostic
6007 // on the byte the author pasted earliest in the URL. Pins the
6008 // natural-order cascade so a future reorder of the per-byte
6009 // arms surfaces here.
6010 let d = dep_with_fonte(DepSource::Git {
6011 repo: "https://github.com/pleme-io/caixa-teia|tee; rm".into(),
6012 tag: Some("v0.1.0".into()),
6013 rev: None,
6014 branch: None,
6015 });
6016 let err = d.validate().unwrap_err();
6017 let DepError::FonteRepoShape { reason, .. } = err else {
6018 panic!("expected FonteRepoShape, got other variant");
6019 };
6020 assert!(
6021 reason.contains("must not contain `|`"),
6022 "reason must surface the pipe arm (fires before semicolon when `|` byte \
6023 appears first in value), got {reason:?}"
6024 );
6025 }
6026
6027 #[test]
6028 fn validate_rejects_git_fonte_with_repo_carrying_shell_background() {
6029 // The fail-before-pass-after pin for the canonical
6030 // paste-from-shell-prompt-with-background-launch-tail footgun
6031 // on `:repo` (peer with the e12e4f3 `&` arm on the sibling
6032 // `:caminho` path-fonte axis). An author pastes a shell one-
6033 // liner that detached the clone into the background
6034 // (`git clone <url> & sleep 1`, `git clone <url> && cd …`)
6035 // into the `:repo` slot, forgetting to trim the `& <cmd>` /
6036 // `&& <cmd>` tail. Until this arm landed the value silently
6037 // passed every prior `is_git_repo_url` arm (no whitespace,
6038 // no control chars, no non-ASCII, no `#`, no `?`, no `\`,
6039 // no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6040 // doesn't start with `-` or `:`); RFC 3986 §2 lists `&` in
6041 // the 'sub-delims' / reserved set and the WHATWG URL spec's
6042 // fragment percent-encode set maps `&` → `%26` on the wire,
6043 // so the byte rides verbatim into the lacre's per-dep
6044 // BLAKE3 closure but is silently rewritten at libcurl's
6045 // URL-parser layer — two authors whose values differ only
6046 // in their background-launch tail (`& sleep 1` vs nothing)
6047 // resolve to the byte-identical upstream `git clone` but
6048 // lock to two distinct lacres, defeating the THEORY.md
6049 // §V.2 render-determinism contract. Peer with the
6050 // `:caminho` axis's `FonteCaminhoShellBackground` arm
6051 // (e12e4f3) on the sibling path-fonte axis, and
6052 // `is_gateway_api_http_path`'s eleven-byte RFC-3986-
6053 // reserved set on `:entrada :paths`.
6054 let d = dep_with_fonte(DepSource::Git {
6055 repo: "https://github.com/pleme-io/caixa-teia&sleep".into(),
6056 tag: Some("v0.1.0".into()),
6057 rev: None,
6058 branch: None,
6059 });
6060 let err = d.validate().unwrap_err();
6061 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6062 panic!("expected FonteRepoShape, got other variant");
6063 };
6064 assert_eq!(nome, "caixa-teia");
6065 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia&sleep");
6066 assert!(
6067 reason.contains("must not contain `&`"),
6068 "reason must surface the shell-background / logical-AND arm, got {reason:?}"
6069 );
6070 assert!(
6071 reason.contains("background-task") || reason.contains("'sub-delims'"),
6072 "reason must name the shell-background / RFC-3986-sub-delims rationale, \
6073 got {reason:?}"
6074 );
6075 }
6076
6077 #[test]
6078 fn validate_rejects_git_fonte_with_repo_carrying_logical_and() {
6079 // The fail-before-pass-after pin for the symmetric `&&`
6080 // logical-AND build-chain paste footgun: an author pastes
6081 // a `git clone <url> && cd <repo>` build-chain one-liner
6082 // and forgets to trim the `&& <cmd>` tail. The `&&` shape
6083 // is the same `&` byte twice in a row; the per-byte arm
6084 // fires on the first `&` it sees. Pinned separately from
6085 // the single-`&` background-launch shape so a future
6086 // diagnostic-surface change that special-cased the
6087 // doubled-byte form surfaces here.
6088 let d = dep_with_fonte(DepSource::Git {
6089 repo: "github:pleme-io/caixa-teia&&echo".into(),
6090 tag: Some("v0.1.0".into()),
6091 rev: None,
6092 branch: None,
6093 });
6094 let err = d.validate().unwrap_err();
6095 let DepError::FonteRepoShape { reason, .. } = err else {
6096 panic!("expected FonteRepoShape, got other variant");
6097 };
6098 assert!(
6099 reason.contains("must not contain `&`"),
6100 "reason must surface the shell-background / logical-AND arm on the doubled-`&&` \
6101 shape too, got {reason:?}"
6102 );
6103 }
6104
6105 #[test]
6106 fn fonte_repo_fragment_fires_before_background_when_fragment_first() {
6107 // Cascade pin: the fragment-`#` arm and the background-`&`
6108 // arm are both per-byte arms inside the same `for &b in
6109 // s.as_bytes()` loop, so the byte that appears first in the
6110 // value's byte order wins. A `:repo
6111 // "https://github.com/p/x#readme & sleep"` carries both `#`
6112 // and `&`; the `#` byte appears first, so the fragment-`#`
6113 // arm fires, surfacing the more self-locating diagnostic on
6114 // the byte the author pasted earliest in the URL. Mirrors
6115 // the peer cascade discipline
6116 // `fonte_repo_fragment_fires_before_semicolon_when_fragment_first`
6117 // on the prior `:repo` byte-class arm.
6118 let d = dep_with_fonte(DepSource::Git {
6119 repo: "https://github.com/pleme-io/caixa-teia#readme&sleep".into(),
6120 tag: Some("v0.1.0".into()),
6121 rev: None,
6122 branch: None,
6123 });
6124 let err = d.validate().unwrap_err();
6125 let DepError::FonteRepoShape { reason, .. } = err else {
6126 panic!("expected FonteRepoShape, got other variant");
6127 };
6128 assert!(
6129 reason.contains("must not contain `#`"),
6130 "reason must surface the fragment-`#` arm (fires before background-`&` when `#` \
6131 byte appears first in value), got {reason:?}"
6132 );
6133 }
6134
6135 #[test]
6136 fn fonte_repo_semicolon_fires_before_background_when_semicolon_first() {
6137 // Cascade pin: the semicolon arm and the background-`&` arm
6138 // are both per-byte arms inside the same `for &b in
6139 // s.as_bytes()` loop, so the byte that appears first in the
6140 // value's byte order wins. A `:repo
6141 // "https://github.com/p/x; rm & sleep"` carries both `;` and
6142 // `&`; the `;` byte appears first, so the semicolon arm
6143 // fires, surfacing the more self-locating diagnostic on the
6144 // byte the author pasted earliest in the URL. Pins the
6145 // natural-order cascade so a future reorder of the per-byte
6146 // arms surfaces here.
6147 let d = dep_with_fonte(DepSource::Git {
6148 repo: "https://github.com/pleme-io/caixa-teia;rm&sleep".into(),
6149 tag: Some("v0.1.0".into()),
6150 rev: None,
6151 branch: None,
6152 });
6153 let err = d.validate().unwrap_err();
6154 let DepError::FonteRepoShape { reason, .. } = err else {
6155 panic!("expected FonteRepoShape, got other variant");
6156 };
6157 assert!(
6158 reason.contains("must not contain `;`"),
6159 "reason must surface the semicolon arm (fires before background-`&` when `;` \
6160 byte appears first in value), got {reason:?}"
6161 );
6162 }
6163
6164 #[test]
6165 fn validate_rejects_git_fonte_with_repo_carrying_shell_variable_expansion() {
6166 // The fail-before-pass-after pin for the canonical
6167 // paste-from-shell-prompt-with-unsubstituted-variable footgun
6168 // on `:repo` (peer with the f4efe9c `$` arm on the sibling
6169 // `:caminho` path-fonte axis). An author pastes a shell one-
6170 // liner that referenced an environment variable
6171 // (`git clone https://github.com/$ORG/x`, `git clone
6172 // github:$USER/repo`) into the `:repo` slot, forgetting to
6173 // substitute the literal value at author time. Until this arm
6174 // landed the value silently passed every prior
6175 // `is_git_repo_url` arm (no whitespace, no control chars, no
6176 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6177 // no `` ` ``, no `|`, no `;`, no `&`, doesn't start with `-`
6178 // or `:`); RFC 3986 §2 lists `$` in the 'sub-delims' /
6179 // reserved set and the WHATWG URL spec's fragment percent-
6180 // encode set maps `$` → `%24` on the wire, so the byte rides
6181 // verbatim into the lacre's per-dep BLAKE3 closure but is
6182 // silently rewritten at libcurl's URL-parser layer — two
6183 // authors whose values differ only in their `$VAR` /
6184 // `${VAR}` / `$(cmd)` expansion tail resolve to the byte-
6185 // identical upstream `git clone` but lock to two distinct
6186 // lacres, defeating the THEORY.md §V.2 render-determinism
6187 // contract. Beyond determinism, the value is a structural
6188 // host-layout leak: two authors with the same `:repo` slot
6189 // but different `$ORG` / `$HOME` / `$WORKSPACE` resolve
6190 // different upstreams. Peer with the `:caminho` axis's
6191 // `FonteCaminhoVarExpansion` arm (f4efe9c) on the sibling
6192 // path-fonte axis, and `is_gateway_api_http_path`'s eleven-
6193 // byte RFC-3986-reserved set on `:entrada :paths`.
6194 let d = dep_with_fonte(DepSource::Git {
6195 repo: "https://github.com/$ORG/caixa-teia".into(),
6196 tag: Some("v0.1.0".into()),
6197 rev: None,
6198 branch: None,
6199 });
6200 let err = d.validate().unwrap_err();
6201 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6202 panic!("expected FonteRepoShape, got other variant");
6203 };
6204 assert_eq!(nome, "caixa-teia");
6205 assert_eq!(repo, "https://github.com/$ORG/caixa-teia");
6206 assert!(
6207 reason.contains("must not contain `$`"),
6208 "reason must surface the shell-variable-expansion arm, got {reason:?}"
6209 );
6210 assert!(
6211 reason.contains("variable-expansion") || reason.contains("'sub-delims'"),
6212 "reason must name the shell-variable-expansion / RFC-3986-sub-delims \
6213 rationale, got {reason:?}"
6214 );
6215 }
6216
6217 #[test]
6218 fn validate_rejects_git_fonte_with_repo_carrying_braced_variable_expansion() {
6219 // The fail-before-pass-after pin for the symmetric POSIX-
6220 // shell braced `${VAR}` expansion paste footgun: an author
6221 // pastes a CI-manifest line `git clone
6222 // https://github.com/${WORKSPACE}/x` (the canonical GitHub
6223 // Actions / GitLab CI / Drone shape) and forgets to
6224 // substitute the literal value. The `${...}` shape is the
6225 // same `$` byte at the leading position of the expansion;
6226 // the per-byte arm fires on the `$`. Pinned separately from
6227 // the bare-`$VAR` shape so a future diagnostic-surface
6228 // change that special-cased the braced form surfaces here.
6229 let d = dep_with_fonte(DepSource::Git {
6230 repo: "https://github.com/${WORKSPACE}/caixa-teia".into(),
6231 tag: Some("v0.1.0".into()),
6232 rev: None,
6233 branch: None,
6234 });
6235 let err = d.validate().unwrap_err();
6236 let DepError::FonteRepoShape { reason, .. } = err else {
6237 panic!("expected FonteRepoShape, got other variant");
6238 };
6239 assert!(
6240 reason.contains("must not contain `$`"),
6241 "reason must surface the shell-variable-expansion arm on the braced `${{...}}` \
6242 shape too, got {reason:?}"
6243 );
6244 }
6245
6246 #[test]
6247 fn fonte_repo_fragment_fires_before_var_expansion_when_fragment_first() {
6248 // Cascade pin: the fragment-`#` arm and the var-expansion-`$`
6249 // arm are both per-byte arms inside the same `for &b in
6250 // s.as_bytes()` loop, so the byte that appears first in the
6251 // value's byte order wins. A `:repo
6252 // "https://github.com/p/x#readme$HOME"` carries both `#` and
6253 // `$`; the `#` byte appears first, so the fragment-`#` arm
6254 // fires, surfacing the more self-locating diagnostic on the
6255 // byte the author pasted earliest in the URL. Mirrors the
6256 // peer cascade discipline
6257 // `fonte_repo_fragment_fires_before_background_when_fragment_first`
6258 // on the prior `:repo` byte-class arm.
6259 let d = dep_with_fonte(DepSource::Git {
6260 repo: "https://github.com/pleme-io/caixa-teia#readme$HOME".into(),
6261 tag: Some("v0.1.0".into()),
6262 rev: None,
6263 branch: None,
6264 });
6265 let err = d.validate().unwrap_err();
6266 let DepError::FonteRepoShape { reason, .. } = err else {
6267 panic!("expected FonteRepoShape, got other variant");
6268 };
6269 assert!(
6270 reason.contains("must not contain `#`"),
6271 "reason must surface the fragment-`#` arm (fires before var-expansion-`$` when \
6272 `#` byte appears first in value), got {reason:?}"
6273 );
6274 }
6275
6276 #[test]
6277 fn fonte_repo_background_fires_before_var_expansion_when_background_first() {
6278 // Cascade pin: the background-`&` arm and the
6279 // var-expansion-`$` arm are both per-byte arms inside the
6280 // same `for &b in s.as_bytes()` loop, so the byte that
6281 // appears first in the value's byte order wins. A `:repo
6282 // "https://github.com/p/x&sleep$HOME"` carries both `&` and
6283 // `$`; the `&` byte appears first, so the background arm
6284 // fires, surfacing the more self-locating diagnostic on the
6285 // byte the author pasted earliest in the URL. Pins the
6286 // natural-order cascade so a future reorder of the per-byte
6287 // arms surfaces here — `$` is the most recent byte-class arm,
6288 // so the cascade-pin sweep extends to cover every immediately
6289 // prior byte arm (`#`, `&`) firing first when ordered ahead
6290 // of `$` in the value.
6291 let d = dep_with_fonte(DepSource::Git {
6292 repo: "https://github.com/pleme-io/caixa-teia&sleep$HOME".into(),
6293 tag: Some("v0.1.0".into()),
6294 rev: None,
6295 branch: None,
6296 });
6297 let err = d.validate().unwrap_err();
6298 let DepError::FonteRepoShape { reason, .. } = err else {
6299 panic!("expected FonteRepoShape, got other variant");
6300 };
6301 assert!(
6302 reason.contains("must not contain `&`"),
6303 "reason must surface the background-`&` arm (fires before var-expansion-`$` when \
6304 `&` byte appears first in value), got {reason:?}"
6305 );
6306 }
6307
6308 #[test]
6309 fn validate_rejects_git_fonte_with_repo_carrying_shell_glob_wildcard() {
6310 // The fail-before-pass-after pin for the canonical
6311 // paste-from-shell-prompt glob footgun on `:repo` (peer with
6312 // the cf9034b `*` / `?` arm on the sibling `:caminho`
6313 // path-fonte axis). An author pastes a shell one-liner that
6314 // referenced a glob expansion (`ls
6315 // github.com/pleme-io/caixa-*`, `git clone
6316 // github:pleme-io/caixa-*`) into the `:repo` slot, forgetting
6317 // to substitute the literal repo name. Until this arm landed
6318 // the `*` byte silently passed every prior `is_git_repo_url`
6319 // arm (no whitespace, no control chars, no non-ASCII, no `#`,
6320 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`,
6321 // no `;`, no `&`, no `$`, doesn't start with `-` or `:`); RFC
6322 // 3986 §2 lists `*` in the 'sub-delims' / reserved set and
6323 // the WHATWG URL spec's special-query percent-encode set maps
6324 // `*` → `%2A` on the wire, so the byte rides verbatim into
6325 // the lacre's per-dep BLAKE3 closure but is silently
6326 // rewritten at libcurl's URL-parser layer — two authors
6327 // whose values differ only in their asterisk presence
6328 // resolve to the byte-identical upstream `git clone` but
6329 // lock to two distinct lacres, defeating the THEORY.md §V.2
6330 // render-determinism contract. Peer with the `:caminho`
6331 // axis's `FonteCaminhoShellGlob` arm (cf9034b) on the
6332 // sibling path-fonte axis, and the `is_git_ref_name`
6333 // refspec-wildcard cascade on the `:fonte :tag` / `:branch`
6334 // axes.
6335 let d = dep_with_fonte(DepSource::Git {
6336 repo: "https://github.com/pleme-io/caixa-*".into(),
6337 tag: Some("v0.1.0".into()),
6338 rev: None,
6339 branch: None,
6340 });
6341 let err = d.validate().unwrap_err();
6342 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6343 panic!("expected FonteRepoShape, got other variant");
6344 };
6345 assert_eq!(nome, "caixa-teia");
6346 assert_eq!(repo, "https://github.com/pleme-io/caixa-*");
6347 assert!(
6348 reason.contains("must not contain `*`"),
6349 "reason must surface the shell-glob arm, got {reason:?}"
6350 );
6351 assert!(
6352 reason.contains("pathname-expansion") || reason.contains("'sub-delims'"),
6353 "reason must name the shell-glob / pathname-expansion / \
6354 RFC-3986-sub-delims rationale, got {reason:?}"
6355 );
6356 }
6357
6358 #[test]
6359 fn validate_rejects_git_fonte_with_repo_carrying_recursive_shell_glob() {
6360 // The fail-before-pass-after pin for the symmetric bash
6361 // `globstar` recursive-glob paste footgun: an author pastes
6362 // a `ls github.com/pleme-io/**/x` (the canonical
6363 // `globstar`-shopt-enabled recursive-listing tail) into the
6364 // `:repo` slot. The `**` shape is two `*` bytes adjacent;
6365 // the per-byte arm fires on the first `*`. Pinned
6366 // separately from the single-`*` shape so a future
6367 // diagnostic-surface change that special-cased the
6368 // double-`*` form surfaces here.
6369 let d = dep_with_fonte(DepSource::Git {
6370 repo: "https://github.com/pleme-io/**/caixa-teia".into(),
6371 tag: Some("v0.1.0".into()),
6372 rev: None,
6373 branch: None,
6374 });
6375 let err = d.validate().unwrap_err();
6376 let DepError::FonteRepoShape { reason, .. } = err else {
6377 panic!("expected FonteRepoShape, got other variant");
6378 };
6379 assert!(
6380 reason.contains("must not contain `*`"),
6381 "reason must surface the shell-glob arm on the `**` recursive-glob shape too, \
6382 got {reason:?}"
6383 );
6384 }
6385
6386 #[test]
6387 fn fonte_repo_fragment_fires_before_glob_when_fragment_first() {
6388 // Cascade pin: the fragment-`#` arm and the glob-`*` arm are
6389 // both per-byte arms inside the same `for &b in s.as_bytes()`
6390 // loop, so the byte that appears first in the value's byte
6391 // order wins. A `:repo
6392 // "https://github.com/p/x#readme*tail"` carries both `#` and
6393 // `*`; the `#` byte appears first, so the fragment-`#` arm
6394 // fires, surfacing the more self-locating diagnostic on the
6395 // byte the author pasted earliest in the URL. Mirrors the
6396 // peer cascade discipline
6397 // `fonte_repo_fragment_fires_before_var_expansion_when_fragment_first`
6398 // on the prior `:repo` byte-class arm.
6399 let d = dep_with_fonte(DepSource::Git {
6400 repo: "https://github.com/pleme-io/caixa-teia#readme*tail".into(),
6401 tag: Some("v0.1.0".into()),
6402 rev: None,
6403 branch: None,
6404 });
6405 let err = d.validate().unwrap_err();
6406 let DepError::FonteRepoShape { reason, .. } = err else {
6407 panic!("expected FonteRepoShape, got other variant");
6408 };
6409 assert!(
6410 reason.contains("must not contain `#`"),
6411 "reason must surface the fragment-`#` arm (fires before glob-`*` when `#` byte \
6412 appears first in value), got {reason:?}"
6413 );
6414 }
6415
6416 #[test]
6417 fn fonte_repo_var_expansion_fires_before_glob_when_var_expansion_first() {
6418 // Cascade pin: the var-expansion-`$` arm and the glob-`*`
6419 // arm are both per-byte arms inside the same `for &b in
6420 // s.as_bytes()` loop, so the byte that appears first in the
6421 // value's byte order wins. A `:repo
6422 // "https://github.com/p/$ORG-*"` carries both `$` and `*`;
6423 // the `$` byte appears first, so the var-expansion arm
6424 // fires, surfacing the more self-locating diagnostic on the
6425 // byte the author pasted earliest in the URL. Pins the
6426 // natural-order cascade so a future reorder of the per-byte
6427 // arms surfaces here — `*` is the most recent byte-class
6428 // arm, so the cascade-pin sweep extends to cover the
6429 // immediately prior `$` byte arm firing first when ordered
6430 // ahead of `*` in the value.
6431 let d = dep_with_fonte(DepSource::Git {
6432 repo: "https://github.com/pleme-io/$ORG-caixa-*".into(),
6433 tag: Some("v0.1.0".into()),
6434 rev: None,
6435 branch: None,
6436 });
6437 let err = d.validate().unwrap_err();
6438 let DepError::FonteRepoShape { reason, .. } = err else {
6439 panic!("expected FonteRepoShape, got other variant");
6440 };
6441 assert!(
6442 reason.contains("must not contain `$`"),
6443 "reason must surface the var-expansion-`$` arm (fires before glob-`*` when `$` \
6444 byte appears first in value), got {reason:?}"
6445 );
6446 }
6447
6448 #[test]
6449 fn validate_rejects_git_fonte_with_repo_carrying_subshell_open_paren() {
6450 // The fail-before-pass-after pin for the canonical paste-from-
6451 // shell-prompt subshell-grouping footgun on `:repo`. An author
6452 // pastes a doc / README snippet carrying a regex-alternation
6453 // grouping shape (`https://github.com/(foo|bar)/repo`) or a
6454 // dynamic-config-substitution wrapper (`$(<cmd>)`) into the
6455 // `:repo` slot, forgetting to substitute one literal org name.
6456 // Until this arm landed the `(` byte silently passed every
6457 // prior `is_git_repo_url` arm (no whitespace, no control
6458 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6459 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no
6460 // `*`, doesn't start with `-` or `:`); RFC 3986 §2 lists `(`
6461 // / `)` in the 'sub-delims' / reserved set, and the WHATWG
6462 // URL spec's special-query percent-encode set maps `(` →
6463 // `%28` and `)` → `%29` on the wire, so the byte rides
6464 // verbatim into the lacre's per-dep BLAKE3 closure but is
6465 // silently rewritten at libcurl's URL-parser layer —
6466 // defeating the THEORY.md §V.2 render-determinism contract on
6467 // the same axis the prior twelve byte-class arms close.
6468 let d = dep_with_fonte(DepSource::Git {
6469 repo: "https://github.com/(foo|bar)/caixa-teia".into(),
6470 tag: Some("v0.1.0".into()),
6471 rev: None,
6472 branch: None,
6473 });
6474 let err = d.validate().unwrap_err();
6475 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6476 panic!("expected FonteRepoShape, got other variant");
6477 };
6478 assert_eq!(nome, "caixa-teia");
6479 assert_eq!(repo, "https://github.com/(foo|bar)/caixa-teia");
6480 assert!(
6481 reason.contains("must not contain `(`"),
6482 "reason must surface the subshell-open-paren arm, got {reason:?}"
6483 );
6484 assert!(
6485 reason.contains("subshell-grouping") || reason.contains("'sub-delims'"),
6486 "reason must name the shell-subshell-grouping / RFC-3986-sub-delims rationale, \
6487 got {reason:?}"
6488 );
6489 }
6490
6491 #[test]
6492 fn validate_rejects_git_fonte_with_repo_carrying_subshell_close_paren() {
6493 // The symmetric arm pin on the closing `)` byte: an author
6494 // pastes a `$(date)` command-substitution wrapper or a
6495 // regex-alternation `(foo|bar)` tail into the `:repo` slot.
6496 // Pinned separately from the opening `(` shape so a future
6497 // diagnostic-surface change that only checked one boundary
6498 // surfaces here. The `(` byte appears earlier in the
6499 // canonical regex / subshell wrapper so the per-byte loop
6500 // fires on `(` first; this test exercises a `:repo` value
6501 // carrying only the closing `)` byte (no opening paren) so
6502 // the `)` arm fires directly — pinning the byte-class arm
6503 // independent of order.
6504 let d = dep_with_fonte(DepSource::Git {
6505 repo: "github:pleme-io/caixa-teia)tail".into(),
6506 tag: Some("v0.1.0".into()),
6507 rev: None,
6508 branch: None,
6509 });
6510 let err = d.validate().unwrap_err();
6511 let DepError::FonteRepoShape { reason, .. } = err else {
6512 panic!("expected FonteRepoShape, got other variant");
6513 };
6514 assert!(
6515 reason.contains("must not contain `)`"),
6516 "reason must surface the subshell-close-paren arm on the bare `)` shape, \
6517 got {reason:?}"
6518 );
6519 }
6520
6521 #[test]
6522 fn fonte_repo_fragment_fires_before_subshell_when_fragment_first() {
6523 // Cascade pin: the fragment-`#` arm and the subshell-`(` arm
6524 // are both per-byte arms inside the same `for &b in
6525 // s.as_bytes()` loop, so the byte that appears first in the
6526 // value's byte order wins. A `:repo
6527 // "https://github.com/p/x#readme(tail)"` carries both `#` and
6528 // `(`; the `#` byte appears first, so the fragment-`#` arm
6529 // fires, surfacing the more self-locating diagnostic on the
6530 // byte the author pasted earliest in the URL. Mirrors the
6531 // peer cascade discipline
6532 // `fonte_repo_fragment_fires_before_glob_when_fragment_first`
6533 // on the prior `:repo` byte-class arm.
6534 let d = dep_with_fonte(DepSource::Git {
6535 repo: "https://github.com/pleme-io/caixa-teia#readme(tail)".into(),
6536 tag: Some("v0.1.0".into()),
6537 rev: None,
6538 branch: None,
6539 });
6540 let err = d.validate().unwrap_err();
6541 let DepError::FonteRepoShape { reason, .. } = err else {
6542 panic!("expected FonteRepoShape, got other variant");
6543 };
6544 assert!(
6545 reason.contains("must not contain `#`"),
6546 "reason must surface the fragment-`#` arm (fires before subshell-`(` when `#` \
6547 byte appears first in value), got {reason:?}"
6548 );
6549 }
6550
6551 #[test]
6552 fn fonte_repo_glob_fires_before_subshell_when_glob_first() {
6553 // Cascade pin: the glob-`*` arm (the immediate-predecessor
6554 // byte-class arm, 3902a9a) and the subshell-`(` arm are both
6555 // per-byte arms inside the same `for &b in s.as_bytes()`
6556 // loop, so the byte that appears first in the value's byte
6557 // order wins. A `:repo
6558 // "https://github.com/p/x-*-(date)"` carries both `*` and
6559 // `(`; the `*` byte appears first, so the glob arm fires,
6560 // surfacing the more self-locating diagnostic on the byte
6561 // the author pasted earliest in the URL. Pins the natural-
6562 // order cascade so a future reorder of the per-byte arms
6563 // surfaces here — `(` is the most recent byte-class arm,
6564 // so the cascade-pin sweep extends to cover the immediately
6565 // prior `*` byte arm firing first when ordered ahead of `(`
6566 // in the value.
6567 let d = dep_with_fonte(DepSource::Git {
6568 repo: "https://github.com/pleme-io/caixa-teia-*-(date)".into(),
6569 tag: Some("v0.1.0".into()),
6570 rev: None,
6571 branch: None,
6572 });
6573 let err = d.validate().unwrap_err();
6574 let DepError::FonteRepoShape { reason, .. } = err else {
6575 panic!("expected FonteRepoShape, got other variant");
6576 };
6577 assert!(
6578 reason.contains("must not contain `*`"),
6579 "reason must surface the glob-`*` arm (fires before subshell-`(` when `*` byte \
6580 appears first in value), got {reason:?}"
6581 );
6582 }
6583
6584 #[test]
6585 fn validate_rejects_git_fonte_with_repo_carrying_shell_double_quote() {
6586 // The fail-before-pass-after pin for the canonical paste-from-
6587 // doc-shell-quoting footgun on `:repo`. An author copies a
6588 // README quick-start snippet (`$ git clone "https://github.com/
6589 // foo/bar"`) and keeps the surrounding double-quote bytes when
6590 // pasting into the `:repo` slot — the doc wraps the URL in
6591 // double quotes so the shell doesn't re-lex metachars inside,
6592 // but the typed slot is itself a byte-level string parser, not
6593 // a shell context, so the quote bytes ride into the value
6594 // verbatim. Until this arm landed the `"` byte silently passed
6595 // every prior `is_git_repo_url` arm (no whitespace, no control
6596 // chars, no non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no
6597 // `<`/`>`, no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`,
6598 // no `(`/`)`, doesn't start with `-` or `:`); RFC 3986 §2 lists
6599 // `"` in the strict four-byte 'delims' subset (with `<`, `>`,
6600 // `` ` ``) every URL parser is required to refuse or percent-
6601 // encode, and the WHATWG URL spec's 'C0 control percent-encode
6602 // set' maps `"` → `%22` on the wire, so the byte rides verbatim
6603 // into the lacre's per-dep BLAKE3 closure but is silently
6604 // rewritten at libcurl's URL-parser layer, defeating the
6605 // THEORY.md §V.2 render-determinism contract.
6606 let d = dep_with_fonte(DepSource::Git {
6607 repo: "\"https://github.com/pleme-io/caixa-teia\"".into(),
6608 tag: Some("v0.1.0".into()),
6609 rev: None,
6610 branch: None,
6611 });
6612 let err = d.validate().unwrap_err();
6613 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6614 panic!("expected FonteRepoShape, got other variant");
6615 };
6616 assert_eq!(nome, "caixa-teia");
6617 assert_eq!(repo, "\"https://github.com/pleme-io/caixa-teia\"");
6618 assert!(
6619 reason.contains("must not contain `\"`"),
6620 "reason must surface the shell-double-quote arm, got {reason:?}"
6621 );
6622 assert!(
6623 reason.contains("double-quote") || reason.contains("'delims'"),
6624 "reason must name the shell-double-quote / RFC-3986-delims rationale, \
6625 got {reason:?}"
6626 );
6627 }
6628
6629 #[test]
6630 fn validate_rejects_git_fonte_with_repo_carrying_stray_trailing_double_quote() {
6631 // The symmetric stray-quote tail pin: an author pastes only a
6632 // closing `"` from a shell-history line like `git clone
6633 // "https://github.com/foo/bar" && cd …` (the trim went too
6634 // far in one direction but not the other) into the `:repo`
6635 // slot. Pinned separately from the wrapped-quote shape so a
6636 // future diagnostic-surface change that only checked one
6637 // boundary (only leading, only trailing, only paired) surfaces
6638 // here — the per-byte arm fires anywhere `"` appears.
6639 let d = dep_with_fonte(DepSource::Git {
6640 repo: "github:pleme-io/caixa-teia\"".into(),
6641 tag: Some("v0.1.0".into()),
6642 rev: None,
6643 branch: None,
6644 });
6645 let err = d.validate().unwrap_err();
6646 let DepError::FonteRepoShape { reason, .. } = err else {
6647 panic!("expected FonteRepoShape, got other variant");
6648 };
6649 assert!(
6650 reason.contains("must not contain `\"`"),
6651 "reason must surface the shell-double-quote arm on the trailing-`\"` shape, \
6652 got {reason:?}"
6653 );
6654 }
6655
6656 #[test]
6657 fn fonte_repo_fragment_fires_before_double_quote_when_fragment_first() {
6658 // Cascade pin: the fragment-`#` arm and the double-quote arm
6659 // are both per-byte arms inside the same `for &b in
6660 // s.as_bytes()` loop, so the byte that appears first in the
6661 // value's byte order wins. A `:repo
6662 // "https://github.com/p/x#readme\"tail"` carries both `#` and
6663 // `"`; the `#` byte appears first, so the fragment-`#` arm
6664 // fires, surfacing the more self-locating diagnostic on the
6665 // byte the author pasted earliest in the URL.
6666 let d = dep_with_fonte(DepSource::Git {
6667 repo: "https://github.com/pleme-io/caixa-teia#readme\"tail".into(),
6668 tag: Some("v0.1.0".into()),
6669 rev: None,
6670 branch: None,
6671 });
6672 let err = d.validate().unwrap_err();
6673 let DepError::FonteRepoShape { reason, .. } = err else {
6674 panic!("expected FonteRepoShape, got other variant");
6675 };
6676 assert!(
6677 reason.contains("must not contain `#`"),
6678 "reason must surface the fragment-`#` arm (fires before double-quote when `#` \
6679 byte appears first in value), got {reason:?}"
6680 );
6681 }
6682
6683 #[test]
6684 fn fonte_repo_subshell_fires_before_double_quote_when_subshell_first() {
6685 // Cascade pin: the subshell-`(` arm (the immediate-predecessor
6686 // byte-class arm, 3b99147) and the double-quote arm are both
6687 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6688 // so the byte that appears first in the value's byte order
6689 // wins. A `:repo "github:p/x(date)\"tail"` carries both `(`
6690 // and `"`; the `(` byte appears first, so the subshell arm
6691 // fires, surfacing the more self-locating diagnostic on the
6692 // byte the author pasted earliest in the URL. Pins the natural-
6693 // order cascade so a future reorder of the per-byte arms
6694 // surfaces here — `"` is the most recent byte-class arm, so
6695 // the cascade-pin sweep extends to cover the immediately prior
6696 // `(` byte arm firing first when ordered ahead of `"` in the
6697 // value.
6698 let d = dep_with_fonte(DepSource::Git {
6699 repo: "github:pleme-io/caixa-teia(date)\"tail".into(),
6700 tag: Some("v0.1.0".into()),
6701 rev: None,
6702 branch: None,
6703 });
6704 let err = d.validate().unwrap_err();
6705 let DepError::FonteRepoShape { reason, .. } = err else {
6706 panic!("expected FonteRepoShape, got other variant");
6707 };
6708 assert!(
6709 reason.contains("must not contain `(`"),
6710 "reason must surface the subshell-`(` arm (fires before double-quote when `(` \
6711 byte appears first in value), got {reason:?}"
6712 );
6713 }
6714
6715 #[test]
6716 fn validate_rejects_git_fonte_with_repo_carrying_shell_single_quote() {
6717 // The fail-before-pass-after pin for the canonical paste-from-
6718 // doc-strong-quoting footgun on `:repo`. An author copies a
6719 // security-conscious README quick-start snippet (`$ git clone
6720 // 'https://github.com/foo/bar'`) and keeps the surrounding
6721 // single-quote bytes when pasting into the `:repo` slot — the
6722 // doc strong-quotes the URL so the shell suppresses every form
6723 // of expansion on the bytes inside (no `$`, no backtick, no
6724 // glob, no word-splitting), but the typed slot is itself a
6725 // byte-level string parser, not a shell context, so the quote
6726 // bytes ride into the value verbatim. Until this arm landed the
6727 // `'` byte silently passed every prior `is_git_repo_url` arm
6728 // (no whitespace, no control chars, no non-ASCII, no `#`, no
6729 // `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no
6730 // `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`, doesn't start
6731 // with `-` or `:`); RFC 3986 §2.2 lists `'` in the 'sub-delims'
6732 // set, peer with the `\"` 'delims' double-quote arm and the
6733 // partner ASCII shell-string-delimiter byte every byte-level
6734 // string parser sharing a value-shape with a shell argument
6735 // must refuse on a URL-shaped slot.
6736 let d = dep_with_fonte(DepSource::Git {
6737 repo: "'https://github.com/pleme-io/caixa-teia'".into(),
6738 tag: Some("v0.1.0".into()),
6739 rev: None,
6740 branch: None,
6741 });
6742 let err = d.validate().unwrap_err();
6743 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6744 panic!("expected FonteRepoShape, got other variant");
6745 };
6746 assert_eq!(nome, "caixa-teia");
6747 assert_eq!(repo, "'https://github.com/pleme-io/caixa-teia'");
6748 assert!(
6749 reason.contains("must not contain `'`"),
6750 "reason must surface the shell-single-quote arm, got {reason:?}"
6751 );
6752 assert!(
6753 reason.contains("single-quote") || reason.contains("strong-quote"),
6754 "reason must name the shell-single-quote / strong-quote rationale, \
6755 got {reason:?}"
6756 );
6757 }
6758
6759 #[test]
6760 fn validate_rejects_git_fonte_with_repo_carrying_english_apostrophe() {
6761 // The symmetric English-typography pin: an author writes
6762 // `:repo "github:p/repo's-fork"` (the possessive-form paste-
6763 // from-prose idiom every README / commit-message / chat-thread
6764 // reference to a repo carries) expecting the substrate to
6765 // coerce it to a kebab-case slug — but the byte rides into the
6766 // lacre verbatim. Pinned separately from the wrapped-quote
6767 // shape so a future diagnostic-surface change that only checked
6768 // the boundary positions (only leading, only trailing, only
6769 // paired) surfaces here — the per-byte arm fires anywhere `'`
6770 // appears in the value.
6771 let d = dep_with_fonte(DepSource::Git {
6772 repo: "github:pleme-io/repo's-fork".into(),
6773 tag: Some("v0.1.0".into()),
6774 rev: None,
6775 branch: None,
6776 });
6777 let err = d.validate().unwrap_err();
6778 let DepError::FonteRepoShape { reason, .. } = err else {
6779 panic!("expected FonteRepoShape, got other variant");
6780 };
6781 assert!(
6782 reason.contains("must not contain `'`"),
6783 "reason must surface the shell-single-quote arm on the mid-string \
6784 apostrophe shape, got {reason:?}"
6785 );
6786 }
6787
6788 #[test]
6789 fn fonte_repo_fragment_fires_before_single_quote_when_fragment_first() {
6790 // Cascade pin: the fragment-`#` arm and the single-quote arm
6791 // are both per-byte arms inside the same `for &b in
6792 // s.as_bytes()` loop, so the byte that appears first in the
6793 // value's byte order wins. A `:repo
6794 // "https://github.com/p/x#readme'tail"` carries both `#` and
6795 // `'`; the `#` byte appears first, so the fragment-`#` arm
6796 // fires, surfacing the more self-locating diagnostic on the
6797 // byte the author pasted earliest in the URL.
6798 let d = dep_with_fonte(DepSource::Git {
6799 repo: "https://github.com/pleme-io/caixa-teia#readme'tail".into(),
6800 tag: Some("v0.1.0".into()),
6801 rev: None,
6802 branch: None,
6803 });
6804 let err = d.validate().unwrap_err();
6805 let DepError::FonteRepoShape { reason, .. } = err else {
6806 panic!("expected FonteRepoShape, got other variant");
6807 };
6808 assert!(
6809 reason.contains("must not contain `#`"),
6810 "reason must surface the fragment-`#` arm (fires before single-quote when `#` \
6811 byte appears first in value), got {reason:?}"
6812 );
6813 }
6814
6815 #[test]
6816 fn fonte_repo_double_quote_fires_before_single_quote_when_double_quote_first() {
6817 // Cascade pin: the double-quote-`"` arm (the immediate-predecessor
6818 // byte-class arm, 4267d8b) and the single-quote arm are both
6819 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6820 // so the byte that appears first in the value's byte order
6821 // wins. A `:repo "github:p/x\"mid'tail"` carries both `"` and
6822 // `'`; the `"` byte appears first, so the double-quote arm
6823 // fires, surfacing the more self-locating diagnostic on the
6824 // byte the author pasted earliest in the URL. Pins the natural-
6825 // order cascade so a future reorder of the per-byte arms
6826 // surfaces here — `'` is the most recent byte-class arm, so
6827 // the cascade-pin sweep extends to cover the immediately prior
6828 // `"` byte arm firing first when ordered ahead of `'` in the
6829 // value.
6830 let d = dep_with_fonte(DepSource::Git {
6831 repo: "github:pleme-io/caixa-teia\"mid'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 double-quote arm (fires before single-quote when `\"` \
6843 byte appears first in value), got {reason:?}"
6844 );
6845 }
6846
6847 #[test]
6848 fn validate_rejects_git_fonte_with_repo_carrying_shell_history_expansion() {
6849 // The fail-before-pass-after pin for the canonical paste-from-
6850 // shell-history footgun on `:repo`. An author copies a `git
6851 // clone <url>!sudo make install` one-liner from a README's
6852 // quick-start snippet, intending the trailing `!sudo` as a
6853 // shell-history-expansion reference but the typed slot is itself
6854 // a byte-level string parser, not a shell context, so the byte
6855 // rides into the value verbatim. Until this arm landed the `!`
6856 // byte silently passed every prior `is_git_repo_url` arm (no
6857 // whitespace, no control chars, no non-ASCII, no `#`, no `?`,
6858 // no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no `|`, no `;`,
6859 // no `&`, no `$`, no `*`, no `(`/`)`, no `"`, no `'`, doesn't
6860 // start with `-` or `:`); bash with the default `histexpand`
6861 // mode rewrites `!command` to the most recent history entry
6862 // beginning with `command`, the canonical RCE-class injection
6863 // vector when the byte rides into a shell argument.
6864 let d = dep_with_fonte(DepSource::Git {
6865 repo: "https://github.com/pleme-io/caixa-teia!sudo".into(),
6866 tag: Some("v0.1.0".into()),
6867 rev: None,
6868 branch: None,
6869 });
6870 let err = d.validate().unwrap_err();
6871 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6872 panic!("expected FonteRepoShape, got other variant");
6873 };
6874 assert_eq!(nome, "caixa-teia");
6875 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia!sudo");
6876 assert!(
6877 reason.contains("must not contain `!`"),
6878 "reason must surface the shell-history-expansion arm, got {reason:?}"
6879 );
6880 assert!(
6881 reason.contains("history-expansion") || reason.contains("bang"),
6882 "reason must name the shell-history-expansion / bang rationale, got {reason:?}"
6883 );
6884 }
6885
6886 #[test]
6887 fn validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference() {
6888 // The symmetric `!!` repeat-prior-command pin: an author paste-
6889 // trims a `git clone <url>` retry idiom from shell history that
6890 // expands to the previous command via `!!`. Pinned separately
6891 // from the wrapped `!command` shape so a future diagnostic-
6892 // surface change that only checked the leading or paired-bang
6893 // position surfaces here — the per-byte arm fires anywhere `!`
6894 // appears in the value.
6895 let d = dep_with_fonte(DepSource::Git {
6896 repo: "github:pleme-io/caixa-teia!!".into(),
6897 tag: Some("v0.1.0".into()),
6898 rev: None,
6899 branch: None,
6900 });
6901 let err = d.validate().unwrap_err();
6902 let DepError::FonteRepoShape { reason, .. } = err else {
6903 panic!("expected FonteRepoShape, got other variant");
6904 };
6905 assert!(
6906 reason.contains("must not contain `!`"),
6907 "reason must surface the shell-history-expansion arm on the trailing-`!!` shape, \
6908 got {reason:?}"
6909 );
6910 }
6911
6912 #[test]
6913 fn fonte_repo_fragment_fires_before_bang_when_fragment_first() {
6914 // Cascade pin: the fragment-`#` arm and the bang arm are both
6915 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
6916 // so the byte that appears first in the value's byte order
6917 // wins. A `:repo "https://github.com/p/x#readme!tail"` carries
6918 // both `#` and `!`; the `#` byte appears first, so the
6919 // fragment-`#` arm fires, surfacing the more self-locating
6920 // diagnostic on the byte the author pasted earliest in the URL.
6921 let d = dep_with_fonte(DepSource::Git {
6922 repo: "https://github.com/pleme-io/caixa-teia#readme!tail".into(),
6923 tag: Some("v0.1.0".into()),
6924 rev: None,
6925 branch: None,
6926 });
6927 let err = d.validate().unwrap_err();
6928 let DepError::FonteRepoShape { reason, .. } = err else {
6929 panic!("expected FonteRepoShape, got other variant");
6930 };
6931 assert!(
6932 reason.contains("must not contain `#`"),
6933 "reason must surface the fragment-`#` arm (fires before bang when `#` byte \
6934 appears first in value), got {reason:?}"
6935 );
6936 }
6937
6938 #[test]
6939 fn fonte_repo_single_quote_fires_before_bang_when_single_quote_first() {
6940 // Cascade pin: the single-quote-`'` arm (the immediate-predecessor
6941 // byte-class arm, e7a109f) and the bang arm are both per-byte
6942 // arms inside the same `for &b in s.as_bytes()` loop, so the
6943 // byte that appears first in the value's byte order wins. A
6944 // `:repo "github:p/x'mid!tail"` carries both `'` and `!`; the
6945 // `'` byte appears first, so the single-quote arm fires,
6946 // surfacing the more self-locating diagnostic on the byte the
6947 // author pasted earliest in the URL. Pins the natural-order
6948 // cascade so a future reorder of the per-byte arms surfaces
6949 // here — `!` is the most recent byte-class arm, so the
6950 // cascade-pin sweep extends to cover the immediately prior `'`
6951 // byte arm firing first when ordered ahead of `!` in the value.
6952 let d = dep_with_fonte(DepSource::Git {
6953 repo: "github:pleme-io/caixa-teia'mid!tail".into(),
6954 tag: Some("v0.1.0".into()),
6955 rev: None,
6956 branch: None,
6957 });
6958 let err = d.validate().unwrap_err();
6959 let DepError::FonteRepoShape { reason, .. } = err else {
6960 panic!("expected FonteRepoShape, got other variant");
6961 };
6962 assert!(
6963 reason.contains("must not contain `'`"),
6964 "reason must surface the single-quote arm (fires before bang when `'` byte \
6965 appears first in value), got {reason:?}"
6966 );
6967 }
6968
6969 #[test]
6970 fn validate_rejects_git_fonte_with_repo_carrying_list_separator_comma() {
6971 // The fail-before-pass-after pin for the canonical
6972 // list-separator-belongs-to-list-grammar footgun on `:repo`.
6973 // An author copies a `git clone <a>, <b>, <c>` paste-from-CSV
6974 // one-liner from a multi-repo bootstrap doc, intending the
6975 // comma to separate multiple repo entries but the typed
6976 // `:repo` slot names *one* repo (the list-separator belongs
6977 // to the `:deps` list grammar, not to the value). Until this
6978 // arm landed the `,` byte silently passed every prior
6979 // `is_git_repo_url` arm (no whitespace, no control chars, no
6980 // non-ASCII, no `#`, no `?`, no `\`, no `{`/`}`, no `<`/`>`,
6981 // no `` ` ``, no `|`, no `;`, no `&`, no `$`, no `*`, no
6982 // `(`/`)`, no `"`, no `'`, no `!`, doesn't start with `-` or
6983 // `:`); the byte rode into the lacre's per-dep content-
6984 // address and the resolver's `git clone <repo>` subprocess
6985 // invocation, where no host's repo registry resolved the
6986 // comma-bearing slug.
6987 let d = dep_with_fonte(DepSource::Git {
6988 repo: "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira".into(),
6989 tag: Some("v0.1.0".into()),
6990 rev: None,
6991 branch: None,
6992 });
6993 let err = d.validate().unwrap_err();
6994 let DepError::FonteRepoShape { nome, repo, reason } = err else {
6995 panic!("expected FonteRepoShape, got other variant");
6996 };
6997 assert_eq!(nome, "caixa-teia");
6998 assert_eq!(
6999 repo,
7000 "github:pleme-io/caixa-teia,github:pleme-io/caixa-feira"
7001 );
7002 assert!(
7003 reason.contains("must not contain `,`"),
7004 "reason must surface the list-separator-comma arm, got {reason:?}"
7005 );
7006 assert!(
7007 reason.contains("list-separator") || reason.contains("sub-delims"),
7008 "reason must name the list-separator / RFC-3986-sub-delims rationale, \
7009 got {reason:?}"
7010 );
7011 }
7012
7013 #[test]
7014 fn validate_rejects_git_fonte_with_repo_carrying_trailing_comma() {
7015 // The symmetric trailing-`,` paste-from-prose pin: an author
7016 // writes `:repo "github:pleme-io/caixa-feira,"` (the trailing
7017 // comma every README-prose list-of-projects sentence carries,
7018 // mistakenly retained when the slug is pasted mid-sentence)
7019 // expecting the substrate to coerce it to a kebab-case slug.
7020 // Pinned separately from the wrapped mid-token shape so a
7021 // future diagnostic-surface change that only checked the
7022 // leading or paired-comma position surfaces here — the
7023 // per-byte arm fires anywhere `,` appears in the value.
7024 let d = dep_with_fonte(DepSource::Git {
7025 repo: "github:pleme-io/caixa-feira,".into(),
7026 tag: Some("v0.1.0".into()),
7027 rev: None,
7028 branch: None,
7029 });
7030 let err = d.validate().unwrap_err();
7031 let DepError::FonteRepoShape { reason, .. } = err else {
7032 panic!("expected FonteRepoShape, got other variant");
7033 };
7034 assert!(
7035 reason.contains("must not contain `,`"),
7036 "reason must surface the list-separator-comma arm on the trailing-`,` shape, \
7037 got {reason:?}"
7038 );
7039 }
7040
7041 #[test]
7042 fn fonte_repo_fragment_fires_before_comma_when_fragment_first() {
7043 // Cascade pin: the fragment-`#` arm and the comma arm are
7044 // both per-byte arms inside the same `for &b in s.as_bytes()`
7045 // loop, so the byte that appears first in the value's byte
7046 // order wins. A `:repo "https://github.com/p/x#readme,tail"`
7047 // carries both `#` and `,`; the `#` byte appears first, so
7048 // the fragment-`#` arm fires, surfacing the more self-
7049 // locating diagnostic on the byte the author pasted earliest
7050 // in the URL.
7051 let d = dep_with_fonte(DepSource::Git {
7052 repo: "https://github.com/pleme-io/caixa-teia#readme,tail".into(),
7053 tag: Some("v0.1.0".into()),
7054 rev: None,
7055 branch: None,
7056 });
7057 let err = d.validate().unwrap_err();
7058 let DepError::FonteRepoShape { reason, .. } = err else {
7059 panic!("expected FonteRepoShape, got other variant");
7060 };
7061 assert!(
7062 reason.contains("must not contain `#`"),
7063 "reason must surface the fragment-`#` arm (fires before comma when `#` byte \
7064 appears first in value), got {reason:?}"
7065 );
7066 }
7067
7068 #[test]
7069 fn fonte_repo_bang_fires_before_comma_when_bang_first() {
7070 // Cascade pin: the bang-`!` arm (the immediate-predecessor
7071 // byte-class arm, 7d53c68) and the comma arm are both
7072 // per-byte arms inside the same `for &b in s.as_bytes()`
7073 // loop, so the byte that appears first in the value's byte
7074 // order wins. A `:repo "github:p/x!mid,tail"` carries both
7075 // `!` and `,`; the `!` byte appears first, so the bang arm
7076 // fires, surfacing the more self-locating diagnostic on the
7077 // byte the author pasted earliest in the URL. Pins the
7078 // natural-order cascade so a future reorder of the per-byte
7079 // arms surfaces here — `,` is the most recent byte-class
7080 // arm, so the cascade-pin sweep extends to cover the
7081 // immediately prior `!` byte arm firing first when ordered
7082 // ahead of `,` in the value.
7083 let d = dep_with_fonte(DepSource::Git {
7084 repo: "github:pleme-io/caixa-teia!mid,tail".into(),
7085 tag: Some("v0.1.0".into()),
7086 rev: None,
7087 branch: None,
7088 });
7089 let err = d.validate().unwrap_err();
7090 let DepError::FonteRepoShape { reason, .. } = err else {
7091 panic!("expected FonteRepoShape, got other variant");
7092 };
7093 assert!(
7094 reason.contains("must not contain `!`"),
7095 "reason must surface the bang arm (fires before comma when `!` byte \
7096 appears first in value), got {reason:?}"
7097 );
7098 }
7099
7100 #[test]
7101 fn validate_rejects_git_fonte_with_repo_carrying_shell_env_var_assignment() {
7102 // The fail-before-pass-after pin for the canonical
7103 // shell-env-var-assignment-belongs-to-shell-grammar footgun
7104 // on `:repo`. An author copies
7105 // `GIT_TERMINAL_PROMPT=0 git clone <url>` (or
7106 // `GIT_SSL_NO_VERIFY=1 git clone <url>`, `HTTPS_PROXY=…
7107 // git clone <url>`, etc. — the canonical
7108 // git-troubleshooting README idiom for a one-shot env-var
7109 // scoped to the `git clone` invocation) from a shell-prompt
7110 // one-liner, intending the `KEY=VALUE` prefix as a shell-
7111 // grammar env-var assignment but the typed `:repo` slot is
7112 // a value parser, not a shell context, so the bytes ride
7113 // into the value verbatim. Until this arm landed the `=`
7114 // byte silently passed every prior `is_git_repo_url` arm
7115 // (no whitespace, no control chars, no non-ASCII, no `#`,
7116 // no `?`, no `\`, no `{`/`}`, no `<`/`>`, no `` ` ``, no
7117 // `|`, no `;`, no `&`, no `$`, no `*`, no `(`/`)`, no `"`,
7118 // no `'`, no `!`, no `,`, doesn't start with `-` or `:`);
7119 // the byte rode into the lacre's per-dep content-address
7120 // and the resolver's `git clone <repo>` subprocess
7121 // invocation, where the upstream host's git porcelain
7122 // fetched a literal `GIT_TERMINAL_PROMPT=0 https://…`-shaped
7123 // path that no host's repo registry resolves.
7124 let d = dep_with_fonte(DepSource::Git {
7125 repo: "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia".into(),
7126 tag: Some("v0.1.0".into()),
7127 rev: None,
7128 branch: None,
7129 });
7130 let err = d.validate().unwrap_err();
7131 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7132 panic!("expected FonteRepoShape, got other variant");
7133 };
7134 assert_eq!(nome, "caixa-teia");
7135 assert_eq!(
7136 repo,
7137 "GIT_TERMINAL_PROMPT=0 https://github.com/pleme-io/caixa-teia"
7138 );
7139 // The `=` byte at position 19 of `GIT_TERMINAL_PROMPT=0 …`
7140 // appears before the ` ` byte at position 21, so the `=`
7141 // arm fires (not the whitespace arm) — both arms guard
7142 // the slot, but the per-byte for-loop scans left-to-right
7143 // and the first matching byte wins.
7144 assert!(
7145 reason.contains("must not contain `=`"),
7146 "reason must surface the equals-`=` arm on the env-var-assignment \
7147 paste shape, got {reason:?}"
7148 );
7149 assert!(
7150 reason.contains("env-var-assignment") || reason.contains("KEY=VALUE"),
7151 "reason must name the shell-env-var-assignment rationale, got {reason:?}"
7152 );
7153 }
7154
7155 #[test]
7156 fn validate_rejects_git_fonte_with_repo_carrying_gitconfig_url_key_prefix() {
7157 // The symmetric paste-from-gitconfig pin: an author copies
7158 // `url=https://github.com/p/x` from `git config --get-all
7159 // remote.origin.url` output, a `.gitconfig` `[remote
7160 // "origin"] url = https://…` ini-stanza paste, or a
7161 // `git config remote.origin.url <value>` doc snippet,
7162 // intending the `url=` prefix as the ini-key but the typed
7163 // `:repo` slot is a URL value parser, not a gitconfig
7164 // grammar. With no leading whitespace and no earlier-arm
7165 // bytes in the value, the `=` arm itself fires (rather
7166 // than cascading to the whitespace arm as in the env-var
7167 // paste shape). Pinned separately so a future diagnostic-
7168 // surface change that only checked the whitespace-leading
7169 // shape surfaces here — the per-byte arm fires anywhere
7170 // `=` appears in the value.
7171 let d = dep_with_fonte(DepSource::Git {
7172 repo: "url=https://github.com/pleme-io/caixa-feira".into(),
7173 tag: Some("v0.1.0".into()),
7174 rev: None,
7175 branch: None,
7176 });
7177 let err = d.validate().unwrap_err();
7178 let DepError::FonteRepoShape { reason, .. } = err else {
7179 panic!("expected FonteRepoShape, got other variant");
7180 };
7181 assert!(
7182 reason.contains("must not contain `=`"),
7183 "reason must surface the equals-`=` arm on the `url=…` gitconfig \
7184 paste shape, got {reason:?}"
7185 );
7186 assert!(
7187 reason.contains("key-value-separator") || reason.contains("sub-delims"),
7188 "reason must name the key-value-separator / RFC-3986-sub-delims \
7189 rationale, got {reason:?}"
7190 );
7191 }
7192
7193 #[test]
7194 fn fonte_repo_fragment_fires_before_equals_when_fragment_first() {
7195 // Cascade pin: the fragment-`#` arm and the `=` arm are
7196 // both per-byte arms inside the same `for &b in s.as_bytes()`
7197 // loop, so the byte that appears first in the value's byte
7198 // order wins. A `:repo "https://github.com/p/x#readme=tail"`
7199 // carries both `#` and `=`; the `#` byte appears first, so
7200 // the fragment-`#` arm fires, surfacing the more self-
7201 // locating diagnostic on the byte the author pasted earliest
7202 // in the URL.
7203 let d = dep_with_fonte(DepSource::Git {
7204 repo: "https://github.com/pleme-io/caixa-teia#readme=tail".into(),
7205 tag: Some("v0.1.0".into()),
7206 rev: None,
7207 branch: None,
7208 });
7209 let err = d.validate().unwrap_err();
7210 let DepError::FonteRepoShape { reason, .. } = err else {
7211 panic!("expected FonteRepoShape, got other variant");
7212 };
7213 assert!(
7214 reason.contains("must not contain `#`"),
7215 "reason must surface the fragment-`#` arm (fires before equals when \
7216 `#` byte appears first in value), got {reason:?}"
7217 );
7218 }
7219
7220 #[test]
7221 fn fonte_repo_comma_fires_before_equals_when_comma_first() {
7222 // Cascade pin: the comma-`,` arm (the immediate-predecessor
7223 // byte-class arm, 775b80e) and the `=` arm are both per-byte
7224 // arms inside the same `for &b in s.as_bytes()` loop, so
7225 // the byte that appears first in the value's byte order
7226 // wins. A `:repo "github:p/x,mid=tail"` carries both `,`
7227 // and `=`; the `,` byte appears first, so the comma arm
7228 // fires, surfacing the more self-locating diagnostic on
7229 // the byte the author pasted earliest in the URL. Pins the
7230 // natural-order cascade so a future reorder of the per-byte
7231 // arms surfaces here — `=` is the most recent byte-class
7232 // arm, so the cascade-pin sweep extends to cover the
7233 // immediately prior `,` byte arm firing first when ordered
7234 // ahead of `=` in the value.
7235 let d = dep_with_fonte(DepSource::Git {
7236 repo: "github:pleme-io/caixa-teia,mid=tail".into(),
7237 tag: Some("v0.1.0".into()),
7238 rev: None,
7239 branch: None,
7240 });
7241 let err = d.validate().unwrap_err();
7242 let DepError::FonteRepoShape { reason, .. } = err else {
7243 panic!("expected FonteRepoShape, got other variant");
7244 };
7245 assert!(
7246 reason.contains("must not contain `,`"),
7247 "reason must surface the comma arm (fires before equals when `,` byte \
7248 appears first in value), got {reason:?}"
7249 );
7250 }
7251
7252 #[test]
7253 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_space() {
7254 // The fail-before-pass-after pin for the canonical paste-from-
7255 // browser-address-bar percent-encoded-space footgun on `:repo`.
7256 // An author copies `https://github.com/p/x%20test` from a
7257 // browser address bar (or a percent-encoded README hyperlink,
7258 // or a `curl --data-urlencode` shell-pipeline output)
7259 // intending `%20` as the URL encoding of a literal space; the
7260 // typed `:repo` slot already rejects the literal space byte
7261 // (the whitespace arm at the top of `is_git_repo_url`), so an
7262 // author trying to express "I really meant a space" reaches
7263 // for percent-encoding. Until this arm landed the `%` byte
7264 // silently passed every prior `is_git_repo_url` arm and rode
7265 // verbatim into the lacre's per-dep content-address — but
7266 // libcurl re-percent-encodes `%` to `%25` on the wire (since
7267 // `%` is reserved as the escape-sequence lead-in), so the
7268 // wire request becomes `https://github.com/p/x%2520test`, a
7269 // path the lacre's content-address never names. The classic
7270 // render-determinism violation on the encoding-mechanism axis
7271 // itself.
7272 let d = dep_with_fonte(DepSource::Git {
7273 repo: "https://github.com/pleme-io/caixa-teia%20test".into(),
7274 tag: Some("v0.1.0".into()),
7275 rev: None,
7276 branch: None,
7277 });
7278 let err = d.validate().unwrap_err();
7279 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7280 panic!("expected FonteRepoShape, got other variant");
7281 };
7282 assert_eq!(nome, "caixa-teia");
7283 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia%20test");
7284 assert!(
7285 reason.contains("must not contain `%`"),
7286 "reason must surface the percent-`%` arm on the percent-encoded-space \
7287 paste shape, got {reason:?}"
7288 );
7289 assert!(
7290 reason.contains("percent-encoding") || reason.contains("%25"),
7291 "reason must name the percent-encoding / `%25` re-encoding rationale, \
7292 got {reason:?}"
7293 );
7294 }
7295
7296 #[test]
7297 fn validate_rejects_git_fonte_with_repo_carrying_percent_encoded_slash() {
7298 // The symmetric over-encoded-path-separator pin: an author
7299 // writes `:repo "https://github.com/p%2Fx"` intending the
7300 // `%2F` as the URL encoding of `/` (the canonical
7301 // paste-from-OpenAPI-spec / paste-from-percent-encoded-template
7302 // footgun every API client library and OAuth redirect-URI
7303 // documentation surfaces — the `/` is the URL-path-separator
7304 // and some templates percent-encode it to escape interpretation
7305 // as a path separator). The GitHub Smart-HTTP transport
7306 // resolves the URL's path-segment grammar before the
7307 // percent-decoding pass, so the value identifies a different
7308 // resource on the wire than the literal-`/` form the lacre's
7309 // content-address must agree with — two authors whose `:repo`
7310 // values differ only in their `/` vs `%2F` presence lock to
7311 // two distinct BLAKE3 closures for the byte-identical upstream
7312 // `git clone`. Pinned separately so a future diagnostic
7313 // surface that only catches the `%20` shape surfaces here too.
7314 let d = dep_with_fonte(DepSource::Git {
7315 repo: "https://github.com/pleme-io%2Fcaixa-teia".into(),
7316 tag: Some("v0.1.0".into()),
7317 rev: None,
7318 branch: None,
7319 });
7320 let err = d.validate().unwrap_err();
7321 let DepError::FonteRepoShape { reason, .. } = err else {
7322 panic!("expected FonteRepoShape, got other variant");
7323 };
7324 assert!(
7325 reason.contains("must not contain `%`"),
7326 "reason must surface the percent-`%` arm on the over-encoded-path \
7327 shape, got {reason:?}"
7328 );
7329 assert!(
7330 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7331 "reason must name the render-determinism / BLAKE3-closure rationale, \
7332 got {reason:?}"
7333 );
7334 }
7335
7336 #[test]
7337 fn fonte_repo_fragment_fires_before_percent_when_fragment_first() {
7338 // Cascade pin: the fragment-`#` arm and the `%` arm are both
7339 // per-byte arms inside the same `for &b in s.as_bytes()` loop,
7340 // so the byte that appears first in the value's byte order
7341 // wins. A `:repo "https://github.com/p/x#sec%20tail"` carries
7342 // both `#` and `%`; the `#` byte appears first, so the
7343 // fragment-`#` arm fires, surfacing the more self-locating
7344 // diagnostic on the byte the author pasted earliest in the URL.
7345 let d = dep_with_fonte(DepSource::Git {
7346 repo: "https://github.com/pleme-io/caixa-teia#sec%20tail".into(),
7347 tag: Some("v0.1.0".into()),
7348 rev: None,
7349 branch: None,
7350 });
7351 let err = d.validate().unwrap_err();
7352 let DepError::FonteRepoShape { reason, .. } = err else {
7353 panic!("expected FonteRepoShape, got other variant");
7354 };
7355 assert!(
7356 reason.contains("must not contain `#`"),
7357 "reason must surface the fragment-`#` arm (fires before percent when \
7358 `#` byte appears first in value), got {reason:?}"
7359 );
7360 }
7361
7362 #[test]
7363 fn fonte_repo_equals_fires_before_percent_when_equals_first() {
7364 // Cascade pin: the equals-`=` arm (the immediate-predecessor
7365 // byte-class arm, acf99af) and the `%` arm are both per-byte
7366 // arms inside the same `for &b in s.as_bytes()` loop, so the
7367 // byte that appears first in the value's byte order wins.
7368 // A `:repo "github:p/x=mid%20tail"` carries both `=` and `%`;
7369 // the `=` byte appears first, so the equals arm fires,
7370 // surfacing the more self-locating diagnostic on the byte the
7371 // author pasted earliest in the URL. Pins the natural-order
7372 // cascade so a future reorder of the per-byte arms surfaces
7373 // here — `%` is the most recent byte-class arm, so the
7374 // cascade-pin sweep extends to cover the immediately prior
7375 // `=` byte arm firing first when ordered ahead of `%` in the
7376 // value.
7377 let d = dep_with_fonte(DepSource::Git {
7378 repo: "github:pleme-io/caixa-teia=mid%20tail".into(),
7379 tag: Some("v0.1.0".into()),
7380 rev: None,
7381 branch: None,
7382 });
7383 let err = d.validate().unwrap_err();
7384 let DepError::FonteRepoShape { reason, .. } = err else {
7385 panic!("expected FonteRepoShape, got other variant");
7386 };
7387 assert!(
7388 reason.contains("must not contain `=`"),
7389 "reason must surface the equals arm (fires before percent when `=` byte \
7390 appears first in value), got {reason:?}"
7391 );
7392 }
7393
7394 #[test]
7395 fn validate_rejects_git_fonte_with_repo_carrying_caret_history_substitution() {
7396 // The fail-before-pass-after pin for the canonical paste-from-
7397 // shell-history footgun on `:repo`. An author copies a
7398 // `git clone <url>` line from their terminal followed by a
7399 // bash / ksh / zsh `^typo^fix^` quick-edit-and-rerun shell-
7400 // history shorthand (the `^old^new^` form re-runs the prior
7401 // history entry with the first `old` substituted by `new`,
7402 // bash's default behavior on interactive sessions with
7403 // `set -o histexpand`), forgetting to trim the trailing
7404 // `^...^...` shell-history fragment from the URL value. The
7405 // `^` byte sits in the RFC 3986 §2 'unwise' set (peer with
7406 // `{`, `}`, `|`, `\\` — the strictest of the §2 reserved
7407 // classes), the WHATWG URL spec's 'fragment percent-encode
7408 // set' maps `^` → `%5E` on the wire, so the byte rides
7409 // verbatim into the lacre's per-dep content-address but
7410 // libcurl re-encodes it to `%5E` at `git clone` time — the
7411 // classic render-determinism violation on the same axis the
7412 // peer `%`, `=`, `,`, `!`, `'`, `"`, `(`, `)`, `*`, `$`,
7413 // `&`, `;`, `|`, backtick, `<`, `>`, `{`, `}`, `\\`, `?`,
7414 // `#` arms close.
7415 let d = dep_with_fonte(DepSource::Git {
7416 repo: "https://github.com/pleme-io/caixa-teia^typo^fix".into(),
7417 tag: Some("v0.1.0".into()),
7418 rev: None,
7419 branch: None,
7420 });
7421 let err = d.validate().unwrap_err();
7422 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7423 panic!("expected FonteRepoShape, got other variant");
7424 };
7425 assert_eq!(nome, "caixa-teia");
7426 assert_eq!(repo, "https://github.com/pleme-io/caixa-teia^typo^fix");
7427 assert!(
7428 reason.contains("must not contain `^`"),
7429 "reason must surface the caret-`^` arm on the paste-from-shell-history \
7430 shape, got {reason:?}"
7431 );
7432 assert!(
7433 reason.contains("history-substitution") || reason.contains("%5E"),
7434 "reason must name the shell-history-substitution / `%5E` wire-encoding \
7435 rationale, got {reason:?}"
7436 );
7437 }
7438
7439 #[test]
7440 fn validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor() {
7441 // The symmetric paste-from-doc-grep-pipeline footgun: an
7442 // author writes `:repo "github:p/^archived"` after copying a
7443 // `grep '^archived'` regex-anchor / negation idiom from a
7444 // doc / README quick-listing snippet, expecting the substrate
7445 // to coerce it to a literal repo name. The byte rides
7446 // verbatim into the lacre's per-dep content-address and
7447 // diverges from the byte-identical literal `archived` form
7448 // every other author authored — the canonical render-
7449 // determinism violation pin on the second footgun shape the
7450 // caret-`^` arm closes.
7451 let d = dep_with_fonte(DepSource::Git {
7452 repo: "github:pleme-io/^archived".into(),
7453 tag: Some("v0.1.0".into()),
7454 rev: None,
7455 branch: None,
7456 });
7457 let err = d.validate().unwrap_err();
7458 let DepError::FonteRepoShape { reason, .. } = err else {
7459 panic!("expected FonteRepoShape, got other variant");
7460 };
7461 assert!(
7462 reason.contains("must not contain `^`"),
7463 "reason must surface the caret-`^` arm on the regex-anchor shape, \
7464 got {reason:?}"
7465 );
7466 assert!(
7467 reason.contains("render-determinism") || reason.contains("BLAKE3"),
7468 "reason must name the render-determinism / BLAKE3-closure rationale, \
7469 got {reason:?}"
7470 );
7471 }
7472
7473 #[test]
7474 fn fonte_repo_percent_fires_before_caret_when_percent_first() {
7475 // Cascade pin: the `%` arm (the immediate-predecessor byte-
7476 // class arm, a323db8) and the `^` arm are both per-byte arms
7477 // inside the same `for &b in s.as_bytes()` loop, so the byte
7478 // that appears first in the value's byte order wins. A
7479 // `:repo "https://github.com/p/x%20mid^tail"` carries both
7480 // `%` and `^`; the `%` byte appears first, so the percent
7481 // arm fires, surfacing the more self-locating diagnostic on
7482 // the byte the author pasted earliest in the URL. Pins the
7483 // natural-order cascade so a future reorder of the per-byte
7484 // arms surfaces here — `^` is the most recent byte-class arm,
7485 // so the cascade-pin sweep extends to cover the immediately
7486 // prior `%` byte arm firing first when ordered ahead of `^`
7487 // in the value.
7488 let d = dep_with_fonte(DepSource::Git {
7489 repo: "https://github.com/pleme-io/caixa-teia%20mid^tail".into(),
7490 tag: Some("v0.1.0".into()),
7491 rev: None,
7492 branch: None,
7493 });
7494 let err = d.validate().unwrap_err();
7495 let DepError::FonteRepoShape { reason, .. } = err else {
7496 panic!("expected FonteRepoShape, got other variant");
7497 };
7498 assert!(
7499 reason.contains("must not contain `%`"),
7500 "reason must surface the percent arm (fires before caret when `%` byte \
7501 appears first in value), got {reason:?}"
7502 );
7503 }
7504
7505 #[test]
7506 fn validate_rejects_git_fonte_with_repo_missing_colon_separator() {
7507 // The "I dropped the scheme" footgun — `:repo "pleme-io/caixa-teia"`
7508 // (no `github:` prefix, no scheme). Every documented form
7509 // carries a `:` (`github:`, `https://`, `ssh://`, `git://`,
7510 // `file://`, or `git@host:path`); a bare `org/repo` is
7511 // ambiguous (`git clone` reads as a relative filesystem path
7512 // rather than the GitHub-shorthand expansion the author
7513 // probably intended) and the gate rejects the shape upstream.
7514 let d = dep_with_fonte(DepSource::Git {
7515 repo: "pleme-io/caixa-teia".into(),
7516 tag: Some("v0.1.0".into()),
7517 rev: None,
7518 branch: None,
7519 });
7520 let err = d.validate().unwrap_err();
7521 let DepError::FonteRepoShape { reason, .. } = err else {
7522 panic!("expected FonteRepoShape, got other variant");
7523 };
7524 assert!(
7525 reason.contains("must contain a `:`"),
7526 "reason must surface the missing-`:` arm, got {reason:?}"
7527 );
7528 assert!(
7529 reason.contains("github:"),
7530 "reason must name the canonical `github:` shorthand prefix, got {reason:?}"
7531 );
7532 }
7533
7534 #[test]
7535 fn validate_rejects_git_fonte_with_repo_leading_colon() {
7536 // The "empty scheme" footgun — `:repo ":foo"` has a zero-length
7537 // scheme that no git porcelain entry-point accepts. Pinned
7538 // separately from the missing-`:` arm because a value with a
7539 // leading `:` does technically contain a `:` separator; the
7540 // shape gate rejects on a dedicated arm so the diagnostic
7541 // names the specific footgun.
7542 let d = dep_with_fonte(DepSource::Git {
7543 repo: ":pleme-io/caixa-teia".into(),
7544 tag: Some("v0.1.0".into()),
7545 rev: None,
7546 branch: None,
7547 });
7548 let err = d.validate().unwrap_err();
7549 let DepError::FonteRepoShape { reason, .. } = err else {
7550 panic!("expected FonteRepoShape, got other variant");
7551 };
7552 assert!(
7553 reason.contains("must not start with `:`"),
7554 "reason must surface the leading-`:` arm, got {reason:?}"
7555 );
7556 }
7557
7558 #[test]
7559 fn validate_rejects_git_fonte_with_repo_too_long() {
7560 // The cap arm — a `:repo` value longer than
7561 // [`crate::render::GIT_REPO_URL_MAX_LEN`] (2048) bytes is
7562 // structurally untenable on every realistic landing site (the
7563 // resolver's `git clone` invocation, the future M4 CR
7564 // materializer's per-dep `repo:` axis); a value of that length
7565 // is almost certainly a paste-from-binary slug.
7566 let too_long = format!(
7567 "github:pleme-io/{}",
7568 "x".repeat(crate::render::GIT_REPO_URL_MAX_LEN)
7569 );
7570 let d = dep_with_fonte(DepSource::Git {
7571 repo: too_long.clone(),
7572 tag: Some("v0.1.0".into()),
7573 rev: None,
7574 branch: None,
7575 });
7576 let err = d.validate().unwrap_err();
7577 let DepError::FonteRepoShape { reason, .. } = err else {
7578 panic!("expected FonteRepoShape, got other variant");
7579 };
7580 assert!(
7581 reason.contains("2048"),
7582 "reason must name the cap, got {reason:?}"
7583 );
7584 }
7585
7586 #[test]
7587 fn validate_accepts_canonical_git_fonte_repo_shapes() {
7588 // The positive-control sweep: every documented author shape on
7589 // the `:fonte :repo` axis ([`crate::DepSource::Git`] doc comment)
7590 // must pass the value-shape gate. Pinned so a future tightening
7591 // (e.g. forbidding `http://` in favor of `https://`-only) surfaces
7592 // here as a structural decision. Each form is exercised with the
7593 // same canonical `:tag` pin so only the `:repo` axis varies.
7594 for repo in [
7595 // The pleme-io registry-shorthand convention — `github:org/repo`.
7596 "github:pleme-io/caixa-teia",
7597 // Other host-aliased shorthands (the resolver's pluggable
7598 // host-prefix table).
7599 "gitlab:pleme-io/caixa-teia",
7600 "codeberg:pleme-io/caixa-teia",
7601 "sourcehut:~pleme-io/caixa-teia",
7602 // Full HTTPS URL with and without `.git` suffix.
7603 "https://github.com/pleme-io/caixa-teia",
7604 "https://github.com/pleme-io/caixa-teia.git",
7605 // HTTP (rare; dev / mirror).
7606 "http://example.com/pleme-io/caixa-teia.git",
7607 // SSH URL.
7608 "ssh://git@github.com/pleme-io/caixa-teia.git",
7609 "ssh://git@git.example.com:2222/pleme-io/caixa-teia.git",
7610 // Scp-style SSH — the canonical `git@host:path` short form.
7611 "git@github.com:pleme-io/caixa-teia.git",
7612 "git@git.example.com:team/private.git",
7613 // Anonymous git protocol.
7614 "git://git.example.com/pleme-io/caixa-teia.git",
7615 // Local file URL (dev path).
7616 "file:///tmp/caixa-teia",
7617 ] {
7618 let d = dep_with_fonte(DepSource::Git {
7619 repo: repo.into(),
7620 tag: Some("v0.1.0".into()),
7621 rev: None,
7622 branch: None,
7623 });
7624 d.validate()
7625 .unwrap_or_else(|e| panic!("canonical repo {repo:?} must validate, got {e:?}"));
7626 }
7627 }
7628
7629 #[test]
7630 fn fonte_repo_empty_takes_precedence_over_shape() {
7631 // Order pin: the existing `FonteRepoEmpty` diagnostic (narrower
7632 // diagnostic; doesn't try to parse the URL shape) fires before
7633 // the new `FonteRepoShape` per-axis gate, so an empty `:repo`
7634 // keeps its narrower error message. Mirrors
7635 // `fonte_repo_empty_fires_before_pin_missing` (already pinned)
7636 // on the ordering layer.
7637 let d = dep_with_fonte(DepSource::Git {
7638 repo: String::new(),
7639 tag: Some("v0.1.0".into()),
7640 rev: None,
7641 branch: None,
7642 });
7643 let err = d.validate().unwrap_err();
7644 assert!(
7645 matches!(err, DepError::FonteRepoEmpty { .. }),
7646 "got {err:?}"
7647 );
7648 }
7649
7650 #[test]
7651 fn fonte_repo_shape_fires_before_pin_missing() {
7652 // Order pin: a malformed `:repo` value on a dep with no pin set
7653 // surfaces the `:repo` shape diagnostic (the more self-locating
7654 // axis — the `:repo` is the load-bearing identity of the source;
7655 // a missing pin is downstream from "do we even know the repo")
7656 // rather than collapsing onto the pin-missing diagnostic. The
7657 // shape gate runs inline before the pin enumeration in
7658 // `DepSource::validate`.
7659 let d = dep_with_fonte(DepSource::Git {
7660 repo: "pleme-io/caixa-teia".into(), // missing `:` separator
7661 tag: None,
7662 rev: None,
7663 branch: None,
7664 });
7665 let err = d.validate().unwrap_err();
7666 assert!(
7667 matches!(err, DepError::FonteRepoShape { .. }),
7668 "got {err:?}"
7669 );
7670 }
7671
7672 #[test]
7673 fn fonte_repo_shape_diagnostic_carries_offending_repo_verbatim() {
7674 // The diagnostic-shape pin: the error names the offending
7675 // `:repo` value verbatim plus a non-empty parser-shaped `reason`
7676 // so the author can grep their caixa.lisp without re-running
7677 // the build. Mirrors the diagnostic-shape sweep on every prior
7678 // value-shape gate (3f9d7a0, 6cbb900, c7d05ec, e70d213, be07fd5).
7679 let d = dep_with_fonte(DepSource::Git {
7680 repo: "pleme-io/caixa-teia".into(),
7681 tag: Some("v0.1.0".into()),
7682 rev: None,
7683 branch: None,
7684 });
7685 let err = d.validate().unwrap_err();
7686 let DepError::FonteRepoShape { nome, repo, reason } = err else {
7687 panic!("expected FonteRepoShape, got other variant");
7688 };
7689 assert_eq!(nome, "caixa-teia");
7690 assert_eq!(repo, "pleme-io/caixa-teia");
7691 assert!(
7692 !reason.is_empty(),
7693 "FonteRepoShape `reason` must carry the predicate's wording verbatim"
7694 );
7695 }
7696
7697 #[test]
7698 fn validate_rejects_git_fonte_with_no_pin() {
7699 // The fail-before-pass-after pin for the canonical
7700 // `(:tipo git :repo "github:pleme-io/x")` shape with no
7701 // :tag/:rev/:branch — until this gate landed the resolver's
7702 // ResolveError::MissingPin surfaced at fetch time, far from the
7703 // source caixa.lisp. The new gate moves the check to validate
7704 // time and names the offending dep.
7705 let d = dep_with_fonte(DepSource::Git {
7706 repo: "github:pleme-io/caixa-teia".into(),
7707 tag: None,
7708 rev: None,
7709 branch: None,
7710 });
7711 let err = d.validate().unwrap_err();
7712 assert!(
7713 matches!(err, DepError::FontePinMissing { ref nome } if nome == "caixa-teia"),
7714 "got {err:?}"
7715 );
7716 }
7717
7718 #[test]
7719 fn validate_rejects_git_fonte_with_ambiguous_tag_and_branch() {
7720 // The canonical "pin drift" footgun: an author writes
7721 // `:tag "v1"` and later adds `:branch "main"` without removing
7722 // the :tag, and the resolver silently picks :tag (precedence
7723 // :rev > :tag > :branch). The :branch was dropped with no
7724 // diagnostic. The gate now rejects multi-pin shapes so the
7725 // author makes the precedence explicit at the source.
7726 let d = dep_with_fonte(DepSource::Git {
7727 repo: "github:pleme-io/caixa-teia".into(),
7728 tag: Some("v0.1.0".into()),
7729 rev: None,
7730 branch: Some("main".into()),
7731 });
7732 let err = d.validate().unwrap_err();
7733 let DepError::FontePinAmbiguous { nome, pins } = err else {
7734 panic!("expected FontePinAmbiguous");
7735 };
7736 assert_eq!(nome, "caixa-teia");
7737 assert!(pins.contains(":tag"));
7738 assert!(pins.contains(":branch"));
7739 assert!(!pins.contains(":rev"));
7740 }
7741
7742 #[test]
7743 fn validate_rejects_git_fonte_with_ambiguous_tag_and_rev() {
7744 // Sibling arm of the pin-drift footgun: :tag + :rev set
7745 // simultaneously. Pinned separately so a future relaxation
7746 // that only catches the (:tag, :branch) pair surfaces here.
7747 let d = dep_with_fonte(DepSource::Git {
7748 repo: "github:pleme-io/caixa-teia".into(),
7749 tag: Some("v0.1.0".into()),
7750 rev: Some("c0ffee".into()),
7751 branch: None,
7752 });
7753 let err = d.validate().unwrap_err();
7754 let DepError::FontePinAmbiguous { nome, pins } = err else {
7755 panic!("expected FontePinAmbiguous");
7756 };
7757 assert_eq!(nome, "caixa-teia");
7758 assert!(pins.contains(":tag"));
7759 assert!(pins.contains(":rev"));
7760 }
7761
7762 #[test]
7763 fn validate_rejects_git_fonte_with_all_three_pins() {
7764 // The maximal ambiguity case — every pin axis set. Pinned so a
7765 // future relaxation that only catches pairs surfaces here. The
7766 // diagnostic must enumerate every offending axis so the author
7767 // sees the full set, not just the first match.
7768 let d = dep_with_fonte(DepSource::Git {
7769 repo: "github:pleme-io/caixa-teia".into(),
7770 tag: Some("v0.1.0".into()),
7771 rev: Some("c0ffee".into()),
7772 branch: Some("main".into()),
7773 });
7774 let err = d.validate().unwrap_err();
7775 let DepError::FontePinAmbiguous { nome, pins } = err else {
7776 panic!("expected FontePinAmbiguous");
7777 };
7778 assert_eq!(nome, "caixa-teia");
7779 assert!(pins.contains(":tag"));
7780 assert!(pins.contains(":rev"));
7781 assert!(pins.contains(":branch"));
7782 }
7783
7784 #[test]
7785 fn validate_rejects_git_fonte_with_empty_tag_pin() {
7786 // The empty-pin arm: exactly one pin axis is `Some(_)`, but its
7787 // inner string is empty. Distinct from FontePinMissing (where
7788 // every axis is None) — pinned separately so a future
7789 // tightening collapsing them surfaces here as a structural
7790 // decision.
7791 let d = dep_with_fonte(DepSource::Git {
7792 repo: "github:pleme-io/caixa-teia".into(),
7793 tag: Some(String::new()),
7794 rev: None,
7795 branch: None,
7796 });
7797 let err = d.validate().unwrap_err();
7798 let DepError::FontePinEmpty { nome, pin } = err else {
7799 panic!("expected FontePinEmpty");
7800 };
7801 assert_eq!(nome, "caixa-teia");
7802 assert_eq!(pin, ":tag");
7803 }
7804
7805 #[test]
7806 fn validate_rejects_git_fonte_with_empty_rev_pin() {
7807 // Sibling arm — the empty-pin diagnostic names which axis
7808 // carries the empty value, so the author's grep target is
7809 // unambiguous.
7810 let d = dep_with_fonte(DepSource::Git {
7811 repo: "github:pleme-io/caixa-teia".into(),
7812 tag: None,
7813 rev: Some(String::new()),
7814 branch: None,
7815 });
7816 let err = d.validate().unwrap_err();
7817 let DepError::FontePinEmpty { nome, pin } = err else {
7818 panic!("expected FontePinEmpty");
7819 };
7820 assert_eq!(nome, "caixa-teia");
7821 assert_eq!(pin, ":rev");
7822 }
7823
7824 #[test]
7825 fn validate_rejects_path_fonte_with_empty_caminho() {
7826 // The fail-before-pass-after pin for `(:tipo path :caminho "")`:
7827 // until this gate landed the resolver's
7828 // ResolveError::MissingPath surfaced with `path: PathBuf("")` at
7829 // fetch time — not actionable. The new gate moves the check to
7830 // validate time and names the offending dep.
7831 let d = dep_with_fonte(DepSource::Path {
7832 caminho: String::new(),
7833 });
7834 let err = d.validate().unwrap_err();
7835 assert!(
7836 matches!(err, DepError::FonteCaminhoEmpty { ref nome } if nome == "caixa-teia"),
7837 "got {err:?}"
7838 );
7839 }
7840
7841 #[test]
7842 fn validate_rejects_path_fonte_with_absolute_caminho() {
7843 // The fail-before-pass-after pin for the absolute-`:caminho`
7844 // shape: `(:tipo path :caminho "/home/me/work/caixa-teia")`.
7845 // Until this gate landed an absolute `:caminho` silently
7846 // passed validate; the lacre pipeline embedded the
7847 // host-specific filesystem path verbatim in its
7848 // content-address (`conteudo: format!("path:{caminho}")`,
7849 // caixa-resolver/src/resolve.rs:189), so the BLAKE3 closure
7850 // differed per machine — the build succeeded but two CI
7851 // runners with different `${HOME}` layouts emitted two
7852 // distinct lacres for the byte-identical caixa, silently
7853 // breaking the THEORY.md §V.2 render-determinism contract
7854 // far from the source caixa.lisp. The new gate moves the
7855 // check to validate time and names the offending dep +
7856 // caminho verbatim.
7857 let d = dep_with_fonte(DepSource::Path {
7858 caminho: "/home/me/work/caixa-teia".into(),
7859 });
7860 let err = d.validate().unwrap_err();
7861 let DepError::FonteCaminhoAbsolute { nome, caminho } = err else {
7862 panic!("expected FonteCaminhoAbsolute, got other variant");
7863 };
7864 assert_eq!(nome, "caixa-teia");
7865 assert_eq!(caminho, "/home/me/work/caixa-teia");
7866 }
7867
7868 #[test]
7869 fn validate_accepts_path_fonte_with_parent_escape_caminho() {
7870 // The canonical sibling-workspace dep form
7871 // (`:caminho "../caixa-teia"`) remains accepted. The
7872 // absolute-path gate above is specifically narrower than the
7873 // shared [`crate::render::is_sandboxed_relative_path`]
7874 // predicate (which additionally forbids `..` traversal): a
7875 // local-path dep's canonical author surface is the in-tree
7876 // sibling-workspace path, so a full sandboxed-relative-path
7877 // lift would structurally reject every legitimate path-fonte
7878 // dep. Pinned so a future tightening to the full predicate
7879 // surfaces here as a structural decision, not a silent break.
7880 let d = dep_with_fonte(DepSource::Path {
7881 caminho: "../caixa-teia".into(),
7882 });
7883 d.validate().unwrap();
7884 }
7885
7886 #[test]
7887 fn validate_accepts_path_fonte_with_deeply_nested_relative_caminho() {
7888 // A multi-segment relative `:caminho`
7889 // (`"vendor/forks/caixa-teia"`) remains accepted — the
7890 // absolute-path gate brackets the host-layout-leaking shape
7891 // at the leading-`/` boundary only; every relative shape past
7892 // the empty arm continues to pass. Pinned alongside the
7893 // `..`-traversal positive control so a future tightening
7894 // surfaces the full set of legitimate relative forms here
7895 // rather than at a downstream consumer.
7896 let d = dep_with_fonte(DepSource::Path {
7897 caminho: "vendor/forks/caixa-teia".into(),
7898 });
7899 d.validate().unwrap();
7900 }
7901
7902 #[test]
7903 fn validate_rejects_path_fonte_with_tilde_prefix_caminho() {
7904 // The fail-before-pass-after pin for the tilde-expansion
7905 // `:caminho` shape: `(:tipo path :caminho "~/work/caixa-teia")`.
7906 // Until this gate landed the b94fd83 absolute arm let `~/foo`
7907 // through (`Path::is_absolute` returns false on a leading `~`
7908 // — the tilde is a shell-expansion convention, not a POSIX
7909 // path component), so the lacre embedded the value verbatim
7910 // and the resolver folded it through `Path::join` without
7911 // expansion, looking for a literal `./~/work/caixa-teia`
7912 // subdirectory and failing at resolve time with a
7913 // `No such file or directory` error far from the source
7914 // caixa.lisp. The new gate moves the check to validate time
7915 // and names the offending dep + caminho verbatim.
7916 let d = dep_with_fonte(DepSource::Path {
7917 caminho: "~/work/caixa-teia".into(),
7918 });
7919 let err = d.validate().unwrap_err();
7920 let DepError::FonteCaminhoTildeExpansion { nome, caminho } = err else {
7921 panic!("expected FonteCaminhoTildeExpansion, got {err:?}");
7922 };
7923 assert_eq!(nome, "caixa-teia");
7924 assert_eq!(caminho, "~/work/caixa-teia");
7925 }
7926
7927 #[test]
7928 fn validate_rejects_path_fonte_with_bare_tilde_caminho() {
7929 // The bare `~` form (canonical "I meant `$HOME` and forgot
7930 // the rest"): both the leading-tilde arm catches it and the
7931 // canonical-user-tilde shell idiom (`~alice/dev/caixa-teia`)
7932 // sweeps through the same arm. Pinned both to ensure the
7933 // gate doesn't narrow to `~/` only.
7934 for s in ["~", "~alice/dev/caixa-teia", "~/", "~root/work"] {
7935 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
7936 let err = d.validate().unwrap_err();
7937 assert!(
7938 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
7939 "{s:?} → {err:?}",
7940 );
7941 }
7942 }
7943
7944 #[test]
7945 fn validate_accepts_path_fonte_with_mid_path_tilde_caminho() {
7946 // The leading-`~` is the canonical shell-expansion footgun —
7947 // a tilde mid-path (`"../foo~bar/caixa-teia"` — the canonical
7948 // backup-file-suffix idiom) is a legitimate POSIX path byte
7949 // with no shell-expansion semantic at the leading position.
7950 // Pinned so the gate doesn't widen to a full no-tilde-anywhere
7951 // sweep that would break every legitimate-shape backup-file
7952 // path.
7953 let d = dep_with_fonte(DepSource::Path {
7954 caminho: "../foo~bar/caixa-teia".into(),
7955 });
7956 d.validate().unwrap();
7957 }
7958
7959 #[test]
7960 fn fonte_caminho_empty_fires_before_tilde_expansion() {
7961 // Cascade pin: the empty arm structurally precedes the
7962 // tilde arm (the bytes `""` and `"~"` don't overlap), but the
7963 // pin establishes the precedence at the diagnostic-shape
7964 // level should a future codec round-trip ever produce a
7965 // probe-as-both value. Mirrors the peer
7966 // `fonte_repo_empty_fires_before_pin_missing` cascade
7967 // discipline.
7968 let d = dep_with_fonte(DepSource::Path {
7969 caminho: String::new(),
7970 });
7971 let err = d.validate().unwrap_err();
7972 assert!(
7973 matches!(err, DepError::FonteCaminhoEmpty { .. }),
7974 "got {err:?}",
7975 );
7976 }
7977
7978 #[test]
7979 fn fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho() {
7980 // Diagnostic-shape pin (peer with
7981 // `validate_rejects_path_fonte_with_absolute_caminho`'s
7982 // payload assertion): the error's Display surfaces both the
7983 // offending `:nome` and the offending `:caminho` verbatim
7984 // so a `feira lint` run can render the diagnostic without
7985 // re-parsing.
7986 let d = dep_with_fonte(DepSource::Path {
7987 caminho: "~alice/dev/caixa-teia".into(),
7988 });
7989 let rendered = d.validate().unwrap_err().to_string();
7990 assert!(
7991 rendered.contains("caixa-teia"),
7992 "diagnostic must name the offending dep: {rendered}",
7993 );
7994 assert!(
7995 rendered.contains("~alice/dev/caixa-teia"),
7996 "diagnostic must quote the offending caminho: {rendered}",
7997 );
7998 assert!(
7999 rendered.contains('~'),
8000 "diagnostic must reference the tilde footgun: {rendered}",
8001 );
8002 }
8003
8004 #[test]
8005 fn validate_rejects_path_fonte_with_dollar_prefix_caminho() {
8006 // The fail-before-pass-after pin for the shell-variable-
8007 // expansion `:caminho` shape: `(:tipo path :caminho
8008 // "$HOME/work/caixa-teia")`. Until this gate landed the
8009 // b94fd83 absolute arm + the a5c248e tilde arm both let
8010 // `$HOME/foo` through (`Path::is_absolute` returns false on
8011 // a leading `$` — the `$` is a shell convention, not a POSIX
8012 // path component; `starts_with('~')` returns false too), so
8013 // the lacre embedded the value verbatim and the resolver
8014 // folded it through `Path::join` without `$`-expansion,
8015 // looking for a literal `./$HOME/work/caixa-teia`
8016 // subdirectory and failing at resolve time with a
8017 // `No such file or directory` error far from the source
8018 // caixa.lisp. The new gate moves the check to validate time
8019 // and names the offending dep + caminho verbatim.
8020 let d = dep_with_fonte(DepSource::Path {
8021 caminho: "$HOME/work/caixa-teia".into(),
8022 });
8023 let err = d.validate().unwrap_err();
8024 let DepError::FonteCaminhoVarExpansion { nome, caminho } = err else {
8025 panic!("expected FonteCaminhoVarExpansion, got {err:?}");
8026 };
8027 assert_eq!(nome, "caixa-teia");
8028 assert_eq!(caminho, "$HOME/work/caixa-teia");
8029 }
8030
8031 #[test]
8032 fn validate_rejects_path_fonte_with_dollar_brace_prefix_caminho() {
8033 // Sweep over every leading-`$` shape: the `${VAR}`-braced
8034 // form (canonical "paste-from-CI-manifest" footgun every
8035 // GitHub Actions / GitLab CI / Drone manifest carries on
8036 // `${WORKSPACE}`), the XDG idiom (`$XDG_CONFIG_HOME/caixa`,
8037 // canonical "I'm referencing a per-user config dir"),
8038 // and the bare `$` (canonical "I meant `$HOME` and forgot
8039 // the rest"). All shapes route through the same gate's
8040 // byte check. Pinned so the gate doesn't narrow to a
8041 // single shape (e.g. `$HOME/` only).
8042 for s in [
8043 "${HOME}/work/caixa-teia",
8044 "${WORKSPACE}/caixa-teia",
8045 "$XDG_CONFIG_HOME/caixa",
8046 "$",
8047 ] {
8048 let d = dep_with_fonte(DepSource::Path { caminho: s.into() });
8049 let err = d.validate().unwrap_err();
8050 assert!(
8051 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8052 "{s:?} → {err:?}",
8053 );
8054 }
8055 }
8056
8057 #[test]
8058 fn validate_rejects_path_fonte_with_mid_path_dollar_caminho() {
8059 // The `$` byte is the canonical shell-variable-expansion /
8060 // command-substitution / arithmetic-expansion sentinel and
8061 // is rejected at *every* position on the `:caminho` axis: the
8062 // leading arm surfaces `FonteCaminhoVarExpansion`, the
8063 // embedded arm surfaces `FonteCaminhoShellVariableExpansion`
8064 // (6620f39). Pinned so a future arm doesn't narrow the gate
8065 // back to the leading position and re-open the paste-from-
8066 // shell-one-liner `"../foo$HOME/bar"` / paste-from-CI-
8067 // manifest `"../foo${WORKSPACE}/bar"` / paste-from-shell-
8068 // prompt `"../foo$(whoami)/bar"` cross-idiom-leak surface on
8069 // the lacre content-address (`path:{caminho}`,
8070 // caixa-resolver/src/resolve.rs:189).
8071 let d = dep_with_fonte(DepSource::Path {
8072 caminho: "../foo$bar/caixa-teia".into(),
8073 });
8074 let err = d.validate().unwrap_err();
8075 assert!(
8076 matches!(
8077 err,
8078 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
8079 ),
8080 "got {err:?}",
8081 );
8082 }
8083
8084 #[test]
8085 fn fonte_caminho_tilde_fires_before_var_expansion() {
8086 // Cascade pin: the tilde arm structurally precedes the var
8087 // arm (the bytes `~` and `$` don't overlap at the leading
8088 // position), but the pin establishes the precedence at the
8089 // diagnostic-shape level should a future codec round-trip
8090 // ever produce a probe-as-both value. Mirrors the peer
8091 // `fonte_caminho_empty_fires_before_tilde_expansion` cascade
8092 // discipline on the immediate-predecessor arm.
8093 let d = dep_with_fonte(DepSource::Path {
8094 caminho: "~/work/caixa-teia".into(),
8095 });
8096 let err = d.validate().unwrap_err();
8097 assert!(
8098 matches!(err, DepError::FonteCaminhoTildeExpansion { .. }),
8099 "got {err:?}",
8100 );
8101 }
8102
8103 #[test]
8104 fn fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho() {
8105 // Diagnostic-shape pin (peer with
8106 // `fonte_caminho_tilde_diagnostic_carries_offending_dep_and_caminho`'s
8107 // payload assertion on the immediate-predecessor arm): the
8108 // error's Display surfaces both the offending `:nome` and
8109 // the offending `:caminho` verbatim plus the `$` footgun
8110 // character itself so a `feira lint` run can render the
8111 // diagnostic without re-parsing.
8112 let d = dep_with_fonte(DepSource::Path {
8113 caminho: "${WORKSPACE}/caixa-teia".into(),
8114 });
8115 let rendered = d.validate().unwrap_err().to_string();
8116 assert!(
8117 rendered.contains("caixa-teia"),
8118 "diagnostic must name the offending dep: {rendered}",
8119 );
8120 assert!(
8121 rendered.contains("${WORKSPACE}/caixa-teia"),
8122 "diagnostic must quote the offending caminho: {rendered}",
8123 );
8124 assert!(
8125 rendered.contains('$'),
8126 "diagnostic must reference the dollar footgun: {rendered}",
8127 );
8128 }
8129
8130 #[test]
8131 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_nul() {
8132 // The fail-before-pass-after pin for the load-bearing NUL byte:
8133 // POSIX paths cannot contain `0x00` (every `std::fs` syscall
8134 // routes the path through `CString::new` which fails with
8135 // `NulError`); until this gate landed a `:caminho
8136 // "../caixa\0teia"` silently passed validate, the lacre
8137 // pipeline embedded the value verbatim, and the failure
8138 // surfaced at the resolver's `Path::join` → `CString::new`
8139 // boundary with a non-self-locating `NulError` far from the
8140 // source caixa.lisp. The new gate moves the check to validate
8141 // time and names the offending dep + caminho + offending byte
8142 // verbatim.
8143 let d = dep_with_fonte(DepSource::Path {
8144 caminho: "../caixa\0teia".into(),
8145 });
8146 let err = d.validate().unwrap_err();
8147 let DepError::FonteCaminhoControlChar {
8148 nome,
8149 caminho,
8150 byte,
8151 } = err
8152 else {
8153 panic!("expected FonteCaminhoControlChar, got {err:?}");
8154 };
8155 assert_eq!(nome, "caixa-teia");
8156 assert_eq!(caminho, "../caixa\0teia");
8157 assert_eq!(byte, 0x00);
8158 }
8159
8160 #[test]
8161 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_newline() {
8162 // The canonical paste-from-multiline-doc footgun on `:caminho`
8163 // — author copies `"../caixa-teia\n"` (trailing newline) out
8164 // of a multi-line code-fence or, worse, a `:caminho
8165 // "../caixa-teia\nrm -rf /"` value (CRLF-at-subprocess-argument
8166 // injection sibling on the path axis the `is_git_repo_url`
8167 // control-char arm already closes on `:repo`). Pinned
8168 // separately from the NUL arm so a future relaxation that
8169 // catches one but not the other surfaces here.
8170 let d = dep_with_fonte(DepSource::Path {
8171 caminho: "../caixa-teia\n".into(),
8172 });
8173 let err = d.validate().unwrap_err();
8174 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8175 panic!("expected FonteCaminhoControlChar, got {err:?}");
8176 };
8177 assert_eq!(byte, 0x0A);
8178 }
8179
8180 #[test]
8181 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_carriage_return() {
8182 // The CRLF sibling of the LF arm — Windows-line-ending
8183 // paste-from-multiline-doc on a `\r\n`-terminated buffer
8184 // leaves a stray `\r` mid-string after the LF strip. Pinned
8185 // separately from the LF arm so a future relaxation that
8186 // only catches LF surfaces here.
8187 let d = dep_with_fonte(DepSource::Path {
8188 caminho: "../caixa-teia\r".into(),
8189 });
8190 let err = d.validate().unwrap_err();
8191 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8192 panic!("expected FonteCaminhoControlChar, got {err:?}");
8193 };
8194 assert_eq!(byte, 0x0D);
8195 }
8196
8197 #[test]
8198 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_tab() {
8199 // The canonical paste-from-aligned-table footgun — a `\t`
8200 // mid-`:caminho` is invisible in most editors but rides
8201 // through the lacre's content-address verbatim, so two
8202 // paste-from-distinct-tables (one editor strips tabs, one
8203 // preserves them) yield divergent lacres for the byte-
8204 // identical-looking caixa. Pinned separately from the
8205 // whitespace-shaped LF/CR arms so a future relaxation that
8206 // narrows to line-terminator-only surfaces here.
8207 let d = dep_with_fonte(DepSource::Path {
8208 caminho: "../caixa\tteia".into(),
8209 });
8210 let err = d.validate().unwrap_err();
8211 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8212 panic!("expected FonteCaminhoControlChar, got {err:?}");
8213 };
8214 assert_eq!(byte, 0x09);
8215 }
8216
8217 #[test]
8218 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_del() {
8219 // The DEL byte (`0x7F`) closes the upper-end paste-from-
8220 // binary-blob footgun — the gate's contract is `b < 0x20 ||
8221 // b == 0x7F`, matching the `is_git_repo_url` /
8222 // `is_git_ref_name` predicates' control-char arms. Pinned
8223 // separately from the lower-range arms so a future narrowing
8224 // to `< 0x20` only surfaces here.
8225 let d = dep_with_fonte(DepSource::Path {
8226 caminho: "../caixa\x7fteia".into(),
8227 });
8228 let err = d.validate().unwrap_err();
8229 let DepError::FonteCaminhoControlChar { byte, .. } = err else {
8230 panic!("expected FonteCaminhoControlChar, got {err:?}");
8231 };
8232 assert_eq!(byte, 0x7F);
8233 }
8234
8235 #[test]
8236 fn validate_accepts_path_fonte_with_caminho_carrying_high_bit_utf8() {
8237 // The control-byte arm targets `0x00..=0x1F` + `0x7F` only —
8238 // high-bit / non-ASCII UTF-8 bytes are not gated. POSIX paths
8239 // are opaque byte sequences and UTF-8 multi-byte sequences
8240 // are a legitimate filename shape (the `café-teia/foo` idiom).
8241 // Pinned so the gate doesn't widen to a full ASCII-only sweep
8242 // that would break every legitimate-shape UTF-8 path.
8243 let d = dep_with_fonte(DepSource::Path {
8244 caminho: "../café-teia/foo".into(),
8245 });
8246 d.validate().unwrap();
8247 }
8248
8249 #[test]
8250 fn fonte_caminho_var_fires_before_control_char() {
8251 // Cascade pin: the var-expansion arm structurally precedes the
8252 // control-char arm. A value like `"$\n"` probes positive on
8253 // both arms (`starts_with('$')` and contains LF), but the
8254 // narrower leading-byte diagnostic (`FonteCaminhoVarExpansion`)
8255 // wins so the author sees the more self-locating shell-
8256 // expansion arm first. Mirrors the
8257 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8258 // discipline on the immediate-predecessor arm.
8259 let d = dep_with_fonte(DepSource::Path {
8260 caminho: "$HOME\n".into(),
8261 });
8262 let err = d.validate().unwrap_err();
8263 assert!(
8264 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8265 "got {err:?}",
8266 );
8267 }
8268
8269 #[test]
8270 fn validate_rejects_path_fonte_with_leading_space_caminho() {
8271 // The fail-before-pass-after pin for the leading ASCII space
8272 // `:caminho` shape: `(:tipo path :caminho " ../caixa-teia")`.
8273 // Until this gate landed the b94fd83 absolute arm + the a5c248e
8274 // tilde arm + the f4efe9c var arm + the d624c8d control-byte arm
8275 // all let `" ../caixa-teia"` through: `Path::is_absolute` returns
8276 // false on a leading space (the leading byte is `0x20`, not `0x2F`),
8277 // `starts_with('~')` / `starts_with('$')` return false, and `0x20`
8278 // is not in the `0x00..=0x1F` plus `0x7F` control-byte set (the
8279 // four ASCII whitespace bytes `0x09` tab, `0x0A` LF, `0x0D` CR
8280 // are caught, but the most common whitespace `0x20` space is
8281 // not). The lacre embedded the value verbatim and the resolver
8282 // folded it through `Path::join` looking for a literal `./ ../
8283 // caixa-teia` subdirectory and failing at resolve time with a
8284 // non-self-locating `No such file or directory` error far from
8285 // the source caixa.lisp. The new gate moves the check to
8286 // validate time and names the offending dep + caminho verbatim.
8287 let d = dep_with_fonte(DepSource::Path {
8288 caminho: " ../caixa-teia".into(),
8289 });
8290 let err = d.validate().unwrap_err();
8291 let DepError::FonteCaminhoLeadingWhitespace { nome, caminho } = err else {
8292 panic!("expected FonteCaminhoLeadingWhitespace, got {err:?}");
8293 };
8294 assert_eq!(nome, "caixa-teia");
8295 assert_eq!(caminho, " ../caixa-teia");
8296 }
8297
8298 #[test]
8299 fn validate_rejects_path_fonte_with_multiple_leading_spaces_caminho() {
8300 // The aligned-doc paste footgun sweep: more than one leading
8301 // space (`" ../caixa-teia"` — the canonical "I selected the
8302 // aligned column from a four-`:fonte`-entry `:deps` block"
8303 // paste) routes through the same gate's `starts_with(' ')`
8304 // byte check. Pinned so the gate doesn't narrow to a
8305 // single-space prefix.
8306 let d = dep_with_fonte(DepSource::Path {
8307 caminho: " ../caixa-teia".into(),
8308 });
8309 let err = d.validate().unwrap_err();
8310 assert!(
8311 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8312 "got {err:?}",
8313 );
8314 }
8315
8316 #[test]
8317 fn validate_accepts_path_fonte_with_mid_path_space_caminho() {
8318 // The leading-space is the canonical paste-from-aligned-doc
8319 // footgun — a space mid-path (`"../my dir/caixa-teia"` — the
8320 // canonical "I have a directory with a space in its name"
8321 // idiom; ASCII `0x20` is a valid POSIX filename byte) is a
8322 // legitimate path with no whitespace-leak semantic at the
8323 // non-leading position. Pinned so the gate doesn't widen to a
8324 // full no-space-anywhere sweep that would break every
8325 // legitimate-shape space-in-filename path.
8326 let d = dep_with_fonte(DepSource::Path {
8327 caminho: "../my dir/caixa-teia".into(),
8328 });
8329 d.validate().unwrap();
8330 }
8331
8332 #[test]
8333 fn fonte_caminho_var_fires_before_leading_whitespace() {
8334 // Cascade pin: the var-expansion arm structurally precedes the
8335 // leading-whitespace arm. A value like `"$ "` would probe positive
8336 // on var (`starts_with('$')`) but the leading-byte arms walk
8337 // left-to-right so the var arm fires on the leading `$` before
8338 // the leading-whitespace arm probes. Mirrors the
8339 // `fonte_caminho_tilde_fires_before_var_expansion` cascade
8340 // discipline on the immediate-predecessor arms.
8341 let d = dep_with_fonte(DepSource::Path {
8342 caminho: "$VAR".into(),
8343 });
8344 let err = d.validate().unwrap_err();
8345 assert!(
8346 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8347 "got {err:?}",
8348 );
8349 }
8350
8351 #[test]
8352 fn fonte_caminho_leading_whitespace_fires_before_control_char() {
8353 // Cascade pin: the leading-whitespace arm structurally precedes
8354 // the control-char arm. A value like `" ../foo\n"` probes
8355 // positive on both (starts with space AND contains LF), but
8356 // the narrower leading-byte diagnostic
8357 // (`FonteCaminhoLeadingWhitespace`) wins so the author sees the
8358 // more self-locating paste-from-aligned-doc arm first. Mirrors
8359 // the `fonte_caminho_var_fires_before_control_char` cascade
8360 // discipline on the immediate-predecessor arm.
8361 let d = dep_with_fonte(DepSource::Path {
8362 caminho: " ../foo\n".into(),
8363 });
8364 let err = d.validate().unwrap_err();
8365 assert!(
8366 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8367 "got {err:?}",
8368 );
8369 }
8370
8371 #[test]
8372 fn fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho() {
8373 // Diagnostic-shape pin (peer with
8374 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8375 // payload assertion on the immediate-predecessor arm): the
8376 // error's Display surfaces both the offending `:nome` and the
8377 // offending `:caminho` verbatim, so a `feira lint` run can
8378 // render the diagnostic without re-parsing and the author can
8379 // grep their caixa.lisp for `:caminho "<value>"` and fix it in
8380 // one edit.
8381 let d = dep_with_fonte(DepSource::Path {
8382 caminho: " ../caixa-teia".into(),
8383 });
8384 let rendered = d.validate().unwrap_err().to_string();
8385 assert!(
8386 rendered.contains("caixa-teia"),
8387 "diagnostic must name the offending dep: {rendered}",
8388 );
8389 assert!(
8390 rendered.contains(" ../caixa-teia"),
8391 "diagnostic must quote the offending caminho: {rendered}",
8392 );
8393 assert!(
8394 rendered.contains("space"),
8395 "diagnostic must name the space footgun: {rendered}",
8396 );
8397 }
8398
8399 #[test]
8400 fn fonte_caminho_absolute_fires_before_control_char() {
8401 // Cascade pin on the sibling leading-byte arm: a leading `/`
8402 // value with embedded control byte (`"/etc/passwd\n"`) routes
8403 // through `FonteCaminhoAbsolute` not `FonteCaminhoControlChar`
8404 // — the host-layout-leak diagnostic is the load-bearing axis,
8405 // the control byte is the secondary observation. Same precedence
8406 // logic on every prior leading-byte arm.
8407 let d = dep_with_fonte(DepSource::Path {
8408 caminho: "/etc/passwd\n".into(),
8409 });
8410 let err = d.validate().unwrap_err();
8411 assert!(
8412 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8413 "got {err:?}",
8414 );
8415 }
8416
8417 #[test]
8418 fn validate_rejects_path_fonte_with_leading_hyphen_caminho() {
8419 // The fail-before-pass-after pin for the leading-`-` CLI-arg-
8420 // injection `:caminho` shape sweep. Until this gate landed
8421 // every prior leading-byte arm passed a leading-`-` value
8422 // through: `Path::is_absolute` returns false on `-` (the
8423 // leading byte is `0x2D`, not `0x2F`), `starts_with('~')` /
8424 // `starts_with('$')` / `starts_with(' ')` all return false,
8425 // and `0x2D` sits outside the control-byte set. The lacre
8426 // embedded the value verbatim and the resolver folded it
8427 // through `Path::join` looking for a literal `./-rf` /
8428 // `./-C` / `./--upload-pack=…` subdirectory; the failure at
8429 // `Path::join` time is non-self-locating but harmless, while
8430 // the failure at every downstream `git -C {caminho}` /
8431 // `terraform -chdir={caminho}` / `find {caminho}` shell-out
8432 // is arbitrary-CLI-arg-injection because none of those
8433 // porcelains carry a `--` argument-list terminator between
8434 // the flag block and the path argument. The new arm moves the
8435 // rejection to `Caixa::from_lisp` boundary time and names
8436 // the offending dep + caminho verbatim.
8437 //
8438 // Sweep spans the canonical CLI-arg-injection shapes matching
8439 // the peer sweep on the sibling `is_git_ref_name` /
8440 // `is_git_repo_url` axes: short-flag `-rf` (the `rm -rf` /
8441 // `find -rf` reinterpretation vector), `-C` (the `git -C`
8442 // change-directory-config-injection paste), long-flag
8443 // `--upload-pack=cat /etc/passwd` (the canonical
8444 // arbitrary-command-execution vector on every git porcelain
8445 // entry point), git-config-injection `--config=core.merge=ours`,
8446 // and the degenerate single-byte `-` value.
8447 for caminho in [
8448 "-rf",
8449 "-C",
8450 "--upload-pack=cat /etc/passwd",
8451 "--config=core.merge=ours",
8452 "-",
8453 ] {
8454 let d = dep_with_fonte(DepSource::Path {
8455 caminho: caminho.into(),
8456 });
8457 let err = d.validate().unwrap_err();
8458 let DepError::FonteCaminhoLeadingHyphen { nome, caminho: got } = err else {
8459 panic!("expected FonteCaminhoLeadingHyphen for {caminho:?}, got {err:?}");
8460 };
8461 assert_eq!(nome, "caixa-teia");
8462 assert_eq!(got, caminho);
8463 }
8464 }
8465
8466 #[test]
8467 fn validate_accepts_path_fonte_with_mid_path_hyphen_caminho() {
8468 // The leading-`-` is the canonical CLI-arg-injection footgun
8469 // — a `-` anywhere else in the path (`"../caixa-teia"` — the
8470 // canonical kebab-separator-between-alphanumeric-segments
8471 // shape every DNS-1123-shaped caixa name carries; `"../-hidden"`
8472 // — a mid-path segment starting with `-`, still a legitimate
8473 // POSIX filename byte at that non-leading position because the
8474 // subprocess reads the whole `{caminho}` value as one positional
8475 // argument, so only the very first byte of the composite path
8476 // string is at the CLI-arg-injection boundary) is a legitimate
8477 // path with no CLI-flag-reinterpretation semantic at the non-
8478 // leading position of the top-level value. Pinned so the gate
8479 // doesn't widen to a full no-`-`-anywhere sweep that would
8480 // break every legitimate-shape kebab-in-filename path (i.e.
8481 // essentially every sibling-workspace caixa dep).
8482 for caminho in [
8483 "../caixa-teia",
8484 "../caixa-teia/-hidden",
8485 "./my-lib",
8486 "../foo-bar/baz",
8487 ] {
8488 let d = dep_with_fonte(DepSource::Path {
8489 caminho: caminho.into(),
8490 });
8491 d.validate()
8492 .unwrap_or_else(|e| panic!("mid-path `-` caminho {caminho:?} must pass: {e:?}"));
8493 }
8494 }
8495
8496 #[test]
8497 fn fonte_caminho_leading_whitespace_fires_before_leading_hyphen() {
8498 // Cascade pin: the leading-whitespace arm structurally precedes
8499 // the leading-hyphen arm. A value like `" -rf"` probes positive
8500 // on both (leading space AND, one byte in, a `-` — though the
8501 // leading-hyphen arm probes only the very first byte so it
8502 // wouldn't fire on this value; the pin instead documents the
8503 // arm order on the more common "leading space then a hyphen"
8504 // paste-from-aligned-doc paste-flag-shell-one-liner idiom).
8505 // The narrower leading-space diagnostic (the paste-from-aligned-
8506 // doc footgun) wins so the author sees the more self-locating
8507 // whitespace arm first. Mirrors the
8508 // `fonte_caminho_var_fires_before_leading_whitespace` cascade
8509 // discipline on the immediate-predecessor arm.
8510 let d = dep_with_fonte(DepSource::Path {
8511 caminho: " -rf".into(),
8512 });
8513 let err = d.validate().unwrap_err();
8514 assert!(
8515 matches!(err, DepError::FonteCaminhoLeadingWhitespace { .. }),
8516 "got {err:?}",
8517 );
8518 }
8519
8520 #[test]
8521 fn fonte_caminho_leading_hyphen_fires_before_control_char() {
8522 // Cascade pin: the leading-hyphen arm structurally precedes
8523 // the control-char arm. A value like `"-rf\n"` probes positive
8524 // on both (starts with `-` AND contains LF), but the narrower
8525 // leading-byte diagnostic (`FonteCaminhoLeadingHyphen`) wins so
8526 // the author sees the more self-locating CLI-arg-injection arm
8527 // first. Mirrors the
8528 // `fonte_caminho_leading_whitespace_fires_before_control_char`
8529 // cascade discipline on the immediate-predecessor arm.
8530 let d = dep_with_fonte(DepSource::Path {
8531 caminho: "-rf\n".into(),
8532 });
8533 let err = d.validate().unwrap_err();
8534 assert!(
8535 matches!(err, DepError::FonteCaminhoLeadingHyphen { .. }),
8536 "got {err:?}",
8537 );
8538 }
8539
8540 #[test]
8541 fn fonte_caminho_leading_hyphen_diagnostic_carries_offending_dep_and_caminho() {
8542 // Diagnostic-shape pin (peer with
8543 // `fonte_caminho_leading_whitespace_diagnostic_carries_offending_dep_and_caminho`'s
8544 // payload assertion on the immediate-predecessor arm): the
8545 // error's Display surfaces both the offending `:nome` and the
8546 // offending `:caminho` verbatim plus the CLI-argument-injection
8547 // vocabulary, so a `feira lint` run can render the diagnostic
8548 // without re-parsing and the author can grep their caixa.lisp
8549 // for `:caminho "<value>"` and fix it in one edit.
8550 let d = dep_with_fonte(DepSource::Path {
8551 caminho: "--upload-pack=cat /etc/passwd".into(),
8552 });
8553 let rendered = d.validate().unwrap_err().to_string();
8554 assert!(
8555 rendered.contains("caixa-teia"),
8556 "diagnostic must name the offending dep: {rendered}",
8557 );
8558 assert!(
8559 rendered.contains("--upload-pack=cat /etc/passwd"),
8560 "diagnostic must quote the offending caminho: {rendered}",
8561 );
8562 assert!(
8563 rendered.contains("CLI-argument-injection"),
8564 "diagnostic must name the CLI-argument-injection vector: {rendered}",
8565 );
8566 assert!(
8567 rendered.contains("`-`"),
8568 "diagnostic must name the offending byte: {rendered}",
8569 );
8570 }
8571
8572 #[test]
8573 fn fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte() {
8574 // Diagnostic-shape pin (peer with
8575 // `fonte_caminho_var_diagnostic_carries_offending_dep_and_caminho`'s
8576 // payload assertion on the immediate-predecessor arm): the
8577 // error's Display surfaces the offending `:nome`, the
8578 // offending `:caminho` verbatim, and the offending byte in
8579 // hex form (`0x09` for tab) so a `feira lint` run can render
8580 // the diagnostic without re-parsing.
8581 let d = dep_with_fonte(DepSource::Path {
8582 caminho: "../caixa\tteia".into(),
8583 });
8584 let rendered = d.validate().unwrap_err().to_string();
8585 assert!(
8586 rendered.contains("caixa-teia"),
8587 "diagnostic must name the offending dep: {rendered}",
8588 );
8589 assert!(
8590 rendered.contains("../caixa\tteia"),
8591 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8592 );
8593 assert!(
8594 rendered.contains("0x09"),
8595 "diagnostic must name the offending byte in hex: {rendered:?}",
8596 );
8597 }
8598
8599 #[test]
8600 fn validate_rejects_path_fonte_with_caminho_carrying_backslash() {
8601 // The fail-before-pass-after pin for the canonical Windows-
8602 // path-separator paste footgun: an author who pastes a path
8603 // from Windows-Explorer's `Copy as path`, PowerShell's
8604 // `Get-Location`, or any CMD/Cygwin/MSYS shell prompt
8605 // produces `..\caixa-teia`-shape values that silently passed
8606 // every prior arm (`Path::is_absolute("..\\caixa-teia")` is
8607 // false; `\` is neither a leading-byte sentinel nor a
8608 // control byte). On POSIX resolvers the value rides through
8609 // `Path::join` as a literal directory name and fails at
8610 // resolve time with `No such file or directory`; on Windows
8611 // resolvers the value resolves to the parent's sibling — two
8612 // distinct directories for the byte-identical caixa.lisp.
8613 // The new arm moves the rejection to validate time and names
8614 // the offending dep + caminho verbatim.
8615 let d = dep_with_fonte(DepSource::Path {
8616 caminho: "..\\caixa-teia".into(),
8617 });
8618 let err = d.validate().unwrap_err();
8619 let DepError::FonteCaminhoBackslash { nome, caminho } = err else {
8620 panic!("expected FonteCaminhoBackslash, got {err:?}");
8621 };
8622 assert_eq!(nome, "caixa-teia");
8623 assert_eq!(caminho, "..\\caixa-teia");
8624 }
8625
8626 #[test]
8627 fn validate_rejects_path_fonte_with_caminho_carrying_windows_drive_letter() {
8628 // The Windows drive-letter paste shape (`C:\work\caixa-teia`
8629 // out of Explorer / `cd`-and-`pwd`-on-Windows). On POSIX
8630 // hosts `Path::is_absolute("C:\\work\\caixa-teia")` returns
8631 // false (POSIX absolute paths start with `/`, drive letters
8632 // are not a POSIX concept), so the b94fd83 absolute arm
8633 // doesn't fire; the value contains `\` bytes that this arm
8634 // now catches with the more self-locating Windows-path-
8635 // separator diagnostic. Pinned separately from the bare
8636 // `..\caixa-teia` shape so a future arm that targets only
8637 // leading-`..\` doesn't regress the drive-letter coverage.
8638 let d = dep_with_fonte(DepSource::Path {
8639 caminho: "C:\\work\\caixa-teia".into(),
8640 });
8641 let err = d.validate().unwrap_err();
8642 assert!(
8643 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8644 "got {err:?}",
8645 );
8646 }
8647
8648 #[test]
8649 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backslash() {
8650 // The trailing-`\` shape (`..\caixa-teia\` — the canonical
8651 // PowerShell tab-completion-on-a-directory append). Pinned
8652 // separately from the embedded-`\` shape so the gate's
8653 // contract is "any `\` anywhere", not "any `\` not at end".
8654 let d = dep_with_fonte(DepSource::Path {
8655 caminho: "..\\caixa-teia\\".into(),
8656 });
8657 let err = d.validate().unwrap_err();
8658 assert!(
8659 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8660 "got {err:?}",
8661 );
8662 }
8663
8664 #[test]
8665 fn validate_accepts_path_fonte_with_caminho_carrying_legitimate_forward_slash() {
8666 // The positive-control pin: the gate targets `\` only,
8667 // never `/`. The canonical relative POSIX path
8668 // (`../caixa-teia/foo/bar`) must continue to validate cleanly
8669 // so legitimate nested-directory deps aren't broken. Pinned
8670 // so the gate doesn't accidentally widen to a "no path
8671 // separators at all" sweep.
8672 let d = dep_with_fonte(DepSource::Path {
8673 caminho: "../caixa-teia/foo/bar".into(),
8674 });
8675 d.validate().unwrap();
8676 }
8677
8678 #[test]
8679 fn fonte_caminho_control_char_fires_before_backslash() {
8680 // Cascade pin: the control-char arm structurally precedes the
8681 // backslash arm. A value like `"..\caixa\0teia"` probes
8682 // positive on both (`\` byte + NUL byte), but the control-
8683 // char diagnostic wins so the author sees the more self-
8684 // locating POSIX-syscall-rejected-byte diagnostic first
8685 // (NUL outright breaks `CString::new` at every `std::fs`
8686 // syscall boundary; the `\` divergence is the cross-OS-
8687 // separator axis). Mirrors the
8688 // `fonte_caminho_var_fires_before_control_char` cascade
8689 // discipline on the immediate-predecessor arm.
8690 let d = dep_with_fonte(DepSource::Path {
8691 caminho: "..\\caixa\0teia".into(),
8692 });
8693 let err = d.validate().unwrap_err();
8694 assert!(
8695 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8696 "got {err:?}",
8697 );
8698 }
8699
8700 #[test]
8701 fn fonte_caminho_absolute_fires_before_backslash() {
8702 // Cascade pin on the load-bearing leading-byte arm: a leading
8703 // `/` value with embedded `\` (`/etc/passwd\foo`) routes
8704 // through `FonteCaminhoAbsolute` not `FonteCaminhoBackslash`
8705 // — the host-layout-leak diagnostic is the load-bearing
8706 // axis, the `\` byte is the secondary observation. Same
8707 // precedence logic as every prior leading-byte arm.
8708 let d = dep_with_fonte(DepSource::Path {
8709 caminho: "/etc/passwd\\foo".into(),
8710 });
8711 let err = d.validate().unwrap_err();
8712 assert!(
8713 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8714 "got {err:?}",
8715 );
8716 }
8717
8718 #[test]
8719 fn fonte_caminho_var_fires_before_backslash() {
8720 // Cascade pin on the var-expansion arm: a leading-`$` value
8721 // with embedded `\` (`$WORKSPACE\caixa-teia` — the canonical
8722 // PowerShell-env-var paste-from-CI-manifest footgun) routes
8723 // through `FonteCaminhoVarExpansion` not `FonteCaminhoBackslash`.
8724 // The shell-expansion diagnostic is the more self-locating
8725 // axis since both the leading `$` and the embedded `\`
8726 // are Windows-shell artifacts but the `$` is the root-cause
8727 // surface (an author who removes the `$` is likely to leave
8728 // the `\` too).
8729 let d = dep_with_fonte(DepSource::Path {
8730 caminho: "$WORKSPACE\\caixa-teia".into(),
8731 });
8732 let err = d.validate().unwrap_err();
8733 assert!(
8734 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
8735 "got {err:?}",
8736 );
8737 }
8738
8739 #[test]
8740 fn fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho() {
8741 // Diagnostic-shape pin (peer with the prior
8742 // `fonte_caminho_*_diagnostic_carries_*` payload assertions
8743 // on every preceding arm): the error's Display surfaces the
8744 // offending `:nome` and the offending `:caminho` verbatim
8745 // so a `feira lint` run can render the diagnostic without
8746 // re-parsing.
8747 let d = dep_with_fonte(DepSource::Path {
8748 caminho: "..\\caixa-teia".into(),
8749 });
8750 let rendered = d.validate().unwrap_err().to_string();
8751 assert!(
8752 rendered.contains("caixa-teia"),
8753 "diagnostic must name the offending dep: {rendered}",
8754 );
8755 assert!(
8756 rendered.contains("..\\caixa-teia"),
8757 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8758 );
8759 assert!(
8760 rendered.contains('\\'),
8761 "diagnostic must reference the backslash footgun: {rendered:?}",
8762 );
8763 }
8764
8765 #[test]
8766 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_slash() {
8767 // The fail-before-pass-after pin for the canonical trailing-`/`
8768 // paste footgun: an author who shell-tab-completes a sibling
8769 // directory (every interactive shell — bash/zsh/fish/nushell —
8770 // appends `/` on tab-completing a directory) produces
8771 // `"../caixa-teia/"`-shape values that silently passed every
8772 // prior arm (the leading byte is `.`, no control bytes, no
8773 // backslash). `Path::join` resolves both shapes to the same
8774 // directory at the resolver, but the lacre embeds the value
8775 // verbatim and the BLAKE3 closures diverge across two
8776 // workstations whose authors differ only in tab-completion
8777 // habits.
8778 let d = dep_with_fonte(DepSource::Path {
8779 caminho: "../caixa-teia/".into(),
8780 });
8781 let err = d.validate().unwrap_err();
8782 let DepError::FonteCaminhoTrailingSlash { nome, caminho } = err else {
8783 panic!("expected FonteCaminhoTrailingSlash, got {err:?}");
8784 };
8785 assert_eq!(nome, "caixa-teia");
8786 assert_eq!(caminho, "../caixa-teia/");
8787 }
8788
8789 #[test]
8790 fn validate_rejects_path_fonte_with_caminho_carrying_bare_dot_slash() {
8791 // The `"./"` shape (the canonical "I meant the caixa.lisp's own
8792 // directory and tab-completed it" footgun). Pinned separately
8793 // from the canonical `"../caixa-teia/"` shape so the gate's
8794 // contract is "any trailing `/`", not "trailing `/` after a leaf
8795 // name".
8796 let d = dep_with_fonte(DepSource::Path {
8797 caminho: "./".into(),
8798 });
8799 let err = d.validate().unwrap_err();
8800 assert!(
8801 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8802 "got {err:?}",
8803 );
8804 }
8805
8806 #[test]
8807 fn validate_rejects_path_fonte_with_caminho_carrying_consecutive_trailing_slashes() {
8808 // The `"foo//"` shape (the canonical "I pasted from a CI manifest
8809 // that double-templated `${VAR}/` over an already-`/`-suffixed
8810 // path" footgun). The gate fires on the last byte being `/`
8811 // regardless of how many `/` precede it; the arm contract is
8812 // "the value ends with `/`", structurally.
8813 let d = dep_with_fonte(DepSource::Path {
8814 caminho: "../caixa-teia//".into(),
8815 });
8816 let err = d.validate().unwrap_err();
8817 assert!(
8818 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8819 "got {err:?}",
8820 );
8821 }
8822
8823 #[test]
8824 fn validate_rejects_path_fonte_with_caminho_carrying_dotdot_trailing_slash() {
8825 // The `"../"` shape (the canonical "I want the parent" tab-
8826 // completion footgun on a bare `..` path). Pinned separately so
8827 // the gate doesn't accidentally narrow to "trailing `/` only on
8828 // multi-segment paths".
8829 let d = dep_with_fonte(DepSource::Path {
8830 caminho: "../".into(),
8831 });
8832 let err = d.validate().unwrap_err();
8833 assert!(
8834 matches!(err, DepError::FonteCaminhoTrailingSlash { .. }),
8835 "got {err:?}",
8836 );
8837 }
8838
8839 #[test]
8840 fn validate_accepts_path_fonte_with_caminho_carrying_internal_slashes() {
8841 // The positive-control pin: the gate targets the trailing byte
8842 // only, never internal `/` separators. The canonical nested
8843 // relative POSIX path (`"../caixa-teia/foo/bar"`) must continue
8844 // to validate cleanly so legitimate deeply-nested deps aren't
8845 // broken. Pinned so the gate doesn't accidentally widen to a
8846 // "no `/` separators anywhere" sweep that would defeat the
8847 // entire path-fonte author surface.
8848 let d = dep_with_fonte(DepSource::Path {
8849 caminho: "../caixa-teia/foo/bar".into(),
8850 });
8851 d.validate().unwrap();
8852 }
8853
8854 #[test]
8855 fn validate_accepts_path_fonte_with_caminho_carrying_bare_dot() {
8856 // The positive-control pin on the degenerate single-`.` shape
8857 // (the canonical "the caixa.lisp's own directory" idiom). The
8858 // gate fires on the trailing byte being `/`, not on the path
8859 // being short, so `"."` (one byte, not `/`) must continue to
8860 // validate cleanly.
8861 let d = dep_with_fonte(DepSource::Path {
8862 caminho: ".".into(),
8863 });
8864 d.validate().unwrap();
8865 }
8866
8867 #[test]
8868 fn fonte_caminho_control_char_fires_before_trailing_slash() {
8869 // Cascade pin: the control-char arm structurally precedes the
8870 // trailing-slash arm. A value like `"../foo\n/"` ends in `/`
8871 // but the embedded LF (`0x0A`) is the load-bearing diagnostic
8872 // (control bytes are the paste-from-multiline-doc footgun the
8873 // d624c8d arm already closes). Mirrors the
8874 // `fonte_caminho_control_char_fires_before_backslash` cascade
8875 // discipline on the immediate-predecessor arm.
8876 let d = dep_with_fonte(DepSource::Path {
8877 caminho: "../foo\n/".into(),
8878 });
8879 let err = d.validate().unwrap_err();
8880 assert!(
8881 matches!(err, DepError::FonteCaminhoControlChar { .. }),
8882 "got {err:?}",
8883 );
8884 }
8885
8886 #[test]
8887 fn fonte_caminho_backslash_fires_before_trailing_slash() {
8888 // Cascade pin on the backslash arm: a value like `"..\foo/"`
8889 // ends in `/` but the embedded `\` is the load-bearing
8890 // diagnostic (the cross-host-OS-separator divergence vector
8891 // the 3a4e1d7 arm closes). Same precedence logic as the prior
8892 // narrower-diagnostic-first cascade.
8893 let d = dep_with_fonte(DepSource::Path {
8894 caminho: "..\\caixa-teia/".into(),
8895 });
8896 let err = d.validate().unwrap_err();
8897 assert!(
8898 matches!(err, DepError::FonteCaminhoBackslash { .. }),
8899 "got {err:?}",
8900 );
8901 }
8902
8903 #[test]
8904 fn fonte_caminho_absolute_fires_before_trailing_slash() {
8905 // Cascade pin on the load-bearing leading-byte arm: a leading
8906 // `/` value with a trailing `/` (`"/etc/passwd/"`) routes
8907 // through `FonteCaminhoAbsolute` not `FonteCaminhoTrailingSlash`
8908 // — the host-layout-leak diagnostic is the load-bearing axis,
8909 // the trailing `/` is the secondary observation. Same
8910 // precedence logic as every prior leading-byte arm.
8911 let d = dep_with_fonte(DepSource::Path {
8912 caminho: "/etc/passwd/".into(),
8913 });
8914 let err = d.validate().unwrap_err();
8915 assert!(
8916 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
8917 "got {err:?}",
8918 );
8919 }
8920
8921 #[test]
8922 fn fonte_caminho_trailing_slash_diagnostic_carries_offending_dep_and_caminho() {
8923 // Diagnostic-shape pin (peer with the prior
8924 // `fonte_caminho_*_diagnostic_carries_*` payload assertions on
8925 // every preceding arm): the error's Display surfaces the
8926 // offending `:nome` and the offending `:caminho` verbatim so a
8927 // `feira lint` run can render the diagnostic without re-parsing.
8928 let d = dep_with_fonte(DepSource::Path {
8929 caminho: "../caixa-teia/".into(),
8930 });
8931 let rendered = d.validate().unwrap_err().to_string();
8932 assert!(
8933 rendered.contains("caixa-teia"),
8934 "diagnostic must name the offending dep: {rendered}",
8935 );
8936 assert!(
8937 rendered.contains("../caixa-teia/"),
8938 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
8939 );
8940 assert!(
8941 rendered.contains("trailing"),
8942 "diagnostic must reference the trailing-slash footgun: {rendered:?}",
8943 );
8944 }
8945
8946 // -- :caminho shell-redirection metacharacter arm -----------------------
8947
8948 #[test]
8949 fn validate_rejects_path_fonte_with_caminho_carrying_gt_redirection() {
8950 // The fail-before-pass-after pin for the canonical output-redirection
8951 // paste footgun: an author copies a shell pipeline tail
8952 // (`"../caixa-teia>build.log"` — the canonical "I selected the whole
8953 // line including the `> build.log` redirect" idiom) and silently
8954 // passed every prior arm (`Path::is_absolute` false on `..`, no
8955 // control bytes, no backslash, doesn't end in `/`). The lacre
8956 // embedded the value verbatim, the resolver folded it through
8957 // `Path::join` looking for a literal `./../caixa-teia>build.log`
8958 // subdirectory, and the failure surfaced at resolve time with a
8959 // non-self-locating `No such file or directory` error. The new arm
8960 // moves the rejection to validate time and names the offending dep
8961 // + caminho + byte verbatim.
8962 let d = dep_with_fonte(DepSource::Path {
8963 caminho: "../caixa-teia>build.log".into(),
8964 });
8965 let err = d.validate().unwrap_err();
8966 let DepError::FonteCaminhoShellRedirection {
8967 nome,
8968 caminho,
8969 byte,
8970 } = err
8971 else {
8972 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8973 };
8974 assert_eq!(nome, "caixa-teia");
8975 assert_eq!(caminho, "../caixa-teia>build.log");
8976 assert_eq!(byte, b'>');
8977 }
8978
8979 #[test]
8980 fn validate_rejects_path_fonte_with_caminho_carrying_lt_redirection() {
8981 // The symmetric input-redirection paste shape
8982 // (`"../caixa-teia<input.lisp"` — the canonical "I copied a
8983 // `command < input.lisp` line from a tatara-lisp REPL log"
8984 // idiom). Pinned separately from the `>` shape so the gate's
8985 // contract is "any `<` or `>` anywhere", not single-byte coverage.
8986 let d = dep_with_fonte(DepSource::Path {
8987 caminho: "../caixa-teia<input.lisp".into(),
8988 });
8989 let err = d.validate().unwrap_err();
8990 let DepError::FonteCaminhoShellRedirection { byte, .. } = err else {
8991 panic!("expected FonteCaminhoShellRedirection, got {err:?}");
8992 };
8993 assert_eq!(byte, b'<');
8994 }
8995
8996 #[test]
8997 fn validate_rejects_path_fonte_with_caminho_carrying_leading_gt_redirection() {
8998 // Leading-position `>` shape (`">../caixa-teia"` — the degenerate
8999 // "I forgot the source side of the redirect" idiom). Pinned
9000 // separately from the embedded-byte shapes so the gate covers
9001 // every position, not only mid-path.
9002 let d = dep_with_fonte(DepSource::Path {
9003 caminho: ">../caixa-teia".into(),
9004 });
9005 let err = d.validate().unwrap_err();
9006 assert!(
9007 matches!(
9008 err,
9009 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9010 ),
9011 "got {err:?}",
9012 );
9013 }
9014
9015 #[test]
9016 fn validate_rejects_path_fonte_with_caminho_carrying_double_gt_append() {
9017 // The bash append-redirection shape (`"../caixa-teia>>build.log"` —
9018 // the canonical "I copied a `>>` append redirect" idiom). The arm
9019 // fires on the first `>` encountered; pinned so a future arm that
9020 // tries to distinguish `>` from `>>` doesn't break the broader
9021 // contract.
9022 let d = dep_with_fonte(DepSource::Path {
9023 caminho: "../caixa-teia>>build.log".into(),
9024 });
9025 let err = d.validate().unwrap_err();
9026 assert!(
9027 matches!(
9028 err,
9029 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9030 ),
9031 "got {err:?}",
9032 );
9033 }
9034
9035 #[test]
9036 fn validate_accepts_path_fonte_with_caminho_carrying_no_redirection() {
9037 // The positive-control pin: the gate targets only `<` / `>`,
9038 // never adjacent printable ASCII or POSIX-valid bytes. The
9039 // canonical relative POSIX path (`"../caixa-teia"`) and a
9040 // nested deeply-pathed variant (`"../caixa-teia/foo/bar"`) must
9041 // continue to validate cleanly so the gate doesn't widen to a
9042 // "no printable punctuation anywhere" sweep that would defeat
9043 // the entire path-fonte author surface.
9044 let d = dep_with_fonte(DepSource::Path {
9045 caminho: "../caixa-teia/foo/bar".into(),
9046 });
9047 d.validate().unwrap();
9048 }
9049
9050 #[test]
9051 fn fonte_caminho_backslash_fires_before_shell_redirection() {
9052 // Cascade pin on the immediate-predecessor arm: a value carrying
9053 // both `\` and `<` / `>` (`"..\caixa-teia>build.log"` — the
9054 // canonical "I pasted a Windows-shell command with output
9055 // redirect" footgun) routes through `FonteCaminhoBackslash` not
9056 // `FonteCaminhoShellRedirection`. The cross-host-OS-separator
9057 // divergence is the load-bearing axis (an author who removes
9058 // the `\` is the root-cause edit; the `>` falls away in the
9059 // same edit since it's downstream of the Windows-shell
9060 // convention).
9061 let d = dep_with_fonte(DepSource::Path {
9062 caminho: "..\\caixa-teia>build.log".into(),
9063 });
9064 let err = d.validate().unwrap_err();
9065 assert!(
9066 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9067 "got {err:?}",
9068 );
9069 }
9070
9071 #[test]
9072 fn fonte_caminho_control_char_fires_before_shell_redirection() {
9073 // Cascade pin on the embedded-control-byte arm: a value carrying
9074 // both a control byte and `<` / `>` (`"../foo\n>bar"` — the
9075 // canonical paste-from-multiline-doc footgun where a newline
9076 // landed mid-caminho) routes through `FonteCaminhoControlChar`
9077 // not `FonteCaminhoShellRedirection`. The POSIX-syscall-
9078 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
9079 // load-bearing axis on every value that probes positive for
9080 // both — mirrors the cascade discipline on every prior arm.
9081 let d = dep_with_fonte(DepSource::Path {
9082 caminho: "../foo\n>bar".into(),
9083 });
9084 let err = d.validate().unwrap_err();
9085 assert!(
9086 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9087 "got {err:?}",
9088 );
9089 }
9090
9091 #[test]
9092 fn fonte_caminho_absolute_fires_before_shell_redirection() {
9093 // Cascade pin on the load-bearing leading-byte arm: a leading
9094 // `/` value with embedded `<` / `>` (`"/etc/passwd>out"`)
9095 // routes through `FonteCaminhoAbsolute` not
9096 // `FonteCaminhoShellRedirection` — the host-layout-leak
9097 // diagnostic is the load-bearing axis, the `>` byte is the
9098 // secondary observation. Same precedence logic as every prior
9099 // leading-byte arm.
9100 let d = dep_with_fonte(DepSource::Path {
9101 caminho: "/etc/passwd>out".into(),
9102 });
9103 let err = d.validate().unwrap_err();
9104 assert!(
9105 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9106 "got {err:?}",
9107 );
9108 }
9109
9110 #[test]
9111 fn fonte_caminho_shell_redirection_fires_before_trailing_slash() {
9112 // Cascade pin on the immediate-successor arm: a value carrying
9113 // both `<` / `>` and a trailing `/` (`"../foo></"` — the
9114 // canonical "I tab-completed a path that already had a
9115 // redirect" footgun) routes through `FonteCaminhoShellRedirection`
9116 // not `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9117 // the more semantic-locating axis (an author who removes the
9118 // `<` / `>` typically also drops the trailing separator since
9119 // both are paste-from-shell artifacts).
9120 let d = dep_with_fonte(DepSource::Path {
9121 caminho: "../foo></".into(),
9122 });
9123 let err = d.validate().unwrap_err();
9124 assert!(
9125 matches!(
9126 err,
9127 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9128 ),
9129 "got {err:?}",
9130 );
9131 }
9132
9133 #[test]
9134 fn fonte_caminho_shell_redirection_diagnostic_carries_offending_dep_caminho_byte() {
9135 // Diagnostic-shape pin (peer with
9136 // `fonte_caminho_control_diagnostic_carries_offending_dep_caminho_byte`'s
9137 // payload assertion on the closest peer arm that also carries a
9138 // `byte` field): the error's Display surfaces the offending
9139 // `:nome`, the offending `:caminho` verbatim, and the offending
9140 // byte in hex (`0x3c` for `<`, `0x3e` for `>`) so a `feira lint`
9141 // run can render the diagnostic without re-parsing.
9142 let d = dep_with_fonte(DepSource::Path {
9143 caminho: "../caixa-teia>build.log".into(),
9144 });
9145 let rendered = d.validate().unwrap_err().to_string();
9146 assert!(
9147 rendered.contains("caixa-teia"),
9148 "diagnostic must name the offending dep: {rendered}",
9149 );
9150 assert!(
9151 rendered.contains("../caixa-teia>build.log"),
9152 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9153 );
9154 assert!(
9155 rendered.contains("0x3e"),
9156 "diagnostic must name the offending byte in hex: {rendered:?}",
9157 );
9158 assert!(
9159 rendered.contains("redirection"),
9160 "diagnostic must name the shell-redirection footgun: {rendered:?}",
9161 );
9162 }
9163
9164 // -- :caminho shell-pipe metacharacter arm ----------------------------
9165
9166 #[test]
9167 fn validate_rejects_path_fonte_with_caminho_carrying_pipe() {
9168 // The fail-before-pass-after pin for the canonical shell-pipe
9169 // paste footgun: an author copies a shell-history line
9170 // (`"../caixa-teia | grep foo"` — the canonical "I selected
9171 // the whole `ls dir | grep` line out of zsh history") and
9172 // silently passed every prior arm (`Path::is_absolute` false
9173 // on `..`, no control bytes, no backslash, no `<` / `>`,
9174 // doesn't end in `/`). The lacre embedded the value verbatim,
9175 // the resolver folded it through `Path::join` looking for a
9176 // literal `./../caixa-teia | grep foo` subdirectory, and the
9177 // failure surfaced at resolve time with a non-self-locating
9178 // `No such file or directory` error. The new arm moves the
9179 // rejection to validate time and names the offending dep +
9180 // caminho verbatim.
9181 let d = dep_with_fonte(DepSource::Path {
9182 caminho: "../caixa-teia | grep foo".into(),
9183 });
9184 let err = d.validate().unwrap_err();
9185 let DepError::FonteCaminhoShellPipe { nome, caminho } = err else {
9186 panic!("expected FonteCaminhoShellPipe, got {err:?}");
9187 };
9188 assert_eq!(nome, "caixa-teia");
9189 assert_eq!(caminho, "../caixa-teia | grep foo");
9190 }
9191
9192 #[test]
9193 fn validate_rejects_path_fonte_with_caminho_carrying_leading_pipe() {
9194 // Leading-position `|` shape (`"|../caixa-teia"` — the
9195 // degenerate "I forgot the source side of the pipe" idiom).
9196 // Pinned separately from the embedded-byte shape so the gate
9197 // covers every position, not only mid-path.
9198 let d = dep_with_fonte(DepSource::Path {
9199 caminho: "|../caixa-teia".into(),
9200 });
9201 let err = d.validate().unwrap_err();
9202 assert!(
9203 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9204 "got {err:?}",
9205 );
9206 }
9207
9208 #[test]
9209 fn validate_rejects_path_fonte_with_caminho_carrying_double_pipe_or() {
9210 // The bash short-circuit-OR shape (`"../caixa-teia||fallback"`
9211 // — the canonical "I copied a `cmd-a || cmd-b` fallback line"
9212 // idiom). The arm fires on the first `|` encountered; pinned
9213 // so a future arm that tries to distinguish `|` from `||`
9214 // doesn't break the broader contract.
9215 let d = dep_with_fonte(DepSource::Path {
9216 caminho: "../caixa-teia||fallback".into(),
9217 });
9218 let err = d.validate().unwrap_err();
9219 assert!(
9220 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9221 "got {err:?}",
9222 );
9223 }
9224
9225 #[test]
9226 fn validate_accepts_path_fonte_with_caminho_carrying_no_pipe() {
9227 // The positive-control pin: the gate targets only `|`, never
9228 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9229 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9230 // pathed variant with adjacent printable punctuation
9231 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9232 // cleanly so the gate doesn't widen to a "no printable
9233 // punctuation anywhere" sweep that would defeat the entire
9234 // path-fonte author surface.
9235 let d = dep_with_fonte(DepSource::Path {
9236 caminho: "../caixa-teia/sub-dir.v2".into(),
9237 });
9238 d.validate().unwrap();
9239 }
9240
9241 #[test]
9242 fn fonte_caminho_shell_redirection_fires_before_shell_pipe() {
9243 // Cascade pin on the immediate-predecessor arm: a value carrying
9244 // both `<` / `>` and `|` (`"../caixa-teia<input|tee"` — the
9245 // canonical "I pasted a `cmd < input | tee` pipeline tail"
9246 // footgun) routes through `FonteCaminhoShellRedirection` not
9247 // `FonteCaminhoShellPipe`. The input/output redirection
9248 // metachar carries the more self-locating `byte: u8` payload
9249 // (it names which of `<` or `>` triggered), so the prior arm
9250 // wins on every probe-as-both value — same cascade discipline
9251 // every prior `:caminho` arm establishes.
9252 let d = dep_with_fonte(DepSource::Path {
9253 caminho: "../caixa-teia<input|tee".into(),
9254 });
9255 let err = d.validate().unwrap_err();
9256 assert!(
9257 matches!(
9258 err,
9259 DepError::FonteCaminhoShellRedirection { byte: b'<', .. }
9260 ),
9261 "got {err:?}",
9262 );
9263 }
9264
9265 #[test]
9266 fn fonte_caminho_backslash_fires_before_shell_pipe() {
9267 // Cascade pin on the upstream backslash arm: a value carrying
9268 // both `\` and `|` (`"..\caixa-teia|tee"` — the canonical
9269 // "I pasted a Windows-shell command with pipe to tee"
9270 // footgun) routes through `FonteCaminhoBackslash` not
9271 // `FonteCaminhoShellPipe`. The cross-host-OS-separator
9272 // divergence is the load-bearing axis on every probe-as-both
9273 // value (an author who removes the `\` is the root-cause edit;
9274 // the `|` falls away in the same edit since it's downstream of
9275 // the Windows-shell convention).
9276 let d = dep_with_fonte(DepSource::Path {
9277 caminho: "..\\caixa-teia|tee".into(),
9278 });
9279 let err = d.validate().unwrap_err();
9280 assert!(
9281 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9282 "got {err:?}",
9283 );
9284 }
9285
9286 #[test]
9287 fn fonte_caminho_control_char_fires_before_shell_pipe() {
9288 // Cascade pin on the embedded-control-byte arm: a value
9289 // carrying both a control byte and `|` (`"../foo\n|bar"` —
9290 // the canonical paste-from-multiline-doc footgun where a
9291 // newline landed mid-caminho) routes through
9292 // `FonteCaminhoControlChar` not `FonteCaminhoShellPipe`. The
9293 // POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9294 // diagnostic is the load-bearing axis on every value that
9295 // probes positive for both — mirrors the cascade discipline
9296 // on every prior arm.
9297 let d = dep_with_fonte(DepSource::Path {
9298 caminho: "../foo\n|bar".into(),
9299 });
9300 let err = d.validate().unwrap_err();
9301 assert!(
9302 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9303 "got {err:?}",
9304 );
9305 }
9306
9307 #[test]
9308 fn fonte_caminho_absolute_fires_before_shell_pipe() {
9309 // Cascade pin on the load-bearing leading-byte arm: a leading
9310 // `/` value with embedded `|` (`"/etc/passwd|tee"`) routes
9311 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellPipe`
9312 // — the host-layout-leak diagnostic is the load-bearing axis,
9313 // the `|` byte is the secondary observation. Same precedence
9314 // logic as every prior leading-byte arm.
9315 let d = dep_with_fonte(DepSource::Path {
9316 caminho: "/etc/passwd|tee".into(),
9317 });
9318 let err = d.validate().unwrap_err();
9319 assert!(
9320 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9321 "got {err:?}",
9322 );
9323 }
9324
9325 #[test]
9326 fn fonte_caminho_shell_pipe_fires_before_trailing_slash() {
9327 // Cascade pin on the immediate-successor arm: a value carrying
9328 // both `|` and a trailing `/` (`"../foo|tee/"` — the canonical
9329 // "I tab-completed a path that already had a pipeline tail"
9330 // footgun) routes through `FonteCaminhoShellPipe` not
9331 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9332 // the more semantic-locating axis (an author who removes the
9333 // `|` typically also drops the trailing separator since both
9334 // are paste-from-shell artifacts).
9335 let d = dep_with_fonte(DepSource::Path {
9336 caminho: "../foo|tee/".into(),
9337 });
9338 let err = d.validate().unwrap_err();
9339 assert!(
9340 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9341 "got {err:?}",
9342 );
9343 }
9344
9345 #[test]
9346 fn fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho() {
9347 // Diagnostic-shape pin (peer with
9348 // `fonte_caminho_backslash_diagnostic_carries_offending_dep_and_caminho`
9349 // on the closest single-byte peer arm): the error's Display
9350 // surfaces the offending `:nome` and the offending `:caminho`
9351 // verbatim, and names the shell-pipe footgun explicitly so a
9352 // `feira lint` run can render the diagnostic without
9353 // re-parsing.
9354 let d = dep_with_fonte(DepSource::Path {
9355 caminho: "../caixa-teia | grep foo".into(),
9356 });
9357 let rendered = d.validate().unwrap_err().to_string();
9358 assert!(
9359 rendered.contains("caixa-teia"),
9360 "diagnostic must name the offending dep: {rendered}",
9361 );
9362 assert!(
9363 rendered.contains("../caixa-teia | grep foo"),
9364 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9365 );
9366 assert!(
9367 rendered.contains('|'),
9368 "diagnostic must reference the pipe footgun: {rendered:?}",
9369 );
9370 assert!(
9371 rendered.contains("pipe"),
9372 "diagnostic must name the shell-pipe footgun: {rendered:?}",
9373 );
9374 }
9375
9376 // -- :caminho shell-command-separator metacharacter arm ---------------
9377
9378 #[test]
9379 fn validate_rejects_path_fonte_with_caminho_carrying_semicolon() {
9380 // The fail-before-pass-after pin for the canonical shell-command-
9381 // separator paste footgun: an author copies a shell one-liner
9382 // (`"../caixa-teia; rm -rf build"` — the canonical "I selected the
9383 // whole `cd path; do-thing` chain out of a shell-history block")
9384 // and silently passed every prior arm (`Path::is_absolute` false
9385 // on `..`, no control bytes, no backslash, no `<` / `>`, no `|`,
9386 // doesn't end in `/`). The lacre embedded the value verbatim, the
9387 // resolver folded it through `Path::join` looking for a literal
9388 // `./../caixa-teia; rm -rf build` subdirectory, and the failure
9389 // surfaced at resolve time with a non-self-locating `No such file
9390 // or directory` error. The new arm moves the rejection to validate
9391 // time and names the offending dep + caminho verbatim.
9392 let d = dep_with_fonte(DepSource::Path {
9393 caminho: "../caixa-teia; rm -rf build".into(),
9394 });
9395 let err = d.validate().unwrap_err();
9396 let DepError::FonteCaminhoShellSemicolon { nome, caminho } = err else {
9397 panic!("expected FonteCaminhoShellSemicolon, got {err:?}");
9398 };
9399 assert_eq!(nome, "caixa-teia");
9400 assert_eq!(caminho, "../caixa-teia; rm -rf build");
9401 }
9402
9403 #[test]
9404 fn validate_rejects_path_fonte_with_caminho_carrying_leading_semicolon() {
9405 // Leading-position `;` shape (`";../caixa-teia"` — the degenerate
9406 // "I forgot the prior command side of the separator" idiom).
9407 // Pinned separately from the embedded-byte shape so the gate
9408 // covers every position, not only mid-path.
9409 let d = dep_with_fonte(DepSource::Path {
9410 caminho: ";../caixa-teia".into(),
9411 });
9412 let err = d.validate().unwrap_err();
9413 assert!(
9414 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9415 "got {err:?}",
9416 );
9417 }
9418
9419 #[test]
9420 fn validate_rejects_path_fonte_with_caminho_carrying_double_semicolon() {
9421 // The POSIX `case` arm `;;` terminator shape
9422 // (`"../caixa-teia;;next"` — the canonical "I copied a `case`
9423 // arm tail" idiom). The arm fires on the first `;` encountered;
9424 // pinned so a future arm that tries to distinguish `;` from `;;`
9425 // doesn't break the broader contract.
9426 let d = dep_with_fonte(DepSource::Path {
9427 caminho: "../caixa-teia;;next".into(),
9428 });
9429 let err = d.validate().unwrap_err();
9430 assert!(
9431 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9432 "got {err:?}",
9433 );
9434 }
9435
9436 #[test]
9437 fn validate_accepts_path_fonte_with_caminho_carrying_no_semicolon() {
9438 // The positive-control pin: the gate targets only `;`, never
9439 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9440 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9441 // pathed variant with adjacent printable punctuation
9442 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9443 // cleanly so the gate doesn't widen to a "no printable
9444 // punctuation anywhere" sweep that would defeat the entire
9445 // path-fonte author surface.
9446 let d = dep_with_fonte(DepSource::Path {
9447 caminho: "../caixa-teia/sub-dir.v2".into(),
9448 });
9449 d.validate().unwrap();
9450 }
9451
9452 #[test]
9453 fn fonte_caminho_shell_pipe_fires_before_shell_semicolon() {
9454 // Cascade pin on the immediate-predecessor arm: a value carrying
9455 // both `|` and `;` (`"../caixa-teia | tee; rm"` — the canonical
9456 // "I pasted a `cmd | tee; cleanup` chain" footgun) routes through
9457 // `FonteCaminhoShellPipe` not `FonteCaminhoShellSemicolon`. The
9458 // pipeline-tail paste is the load-bearing root-cause edit on
9459 // every probe-as-both value (an author who removes the `|`
9460 // typically also drops the trailing `; cleanup` since both are
9461 // the same paste-from-shell-history artifact) — same cascade
9462 // discipline every prior `:caminho` arm establishes.
9463 let d = dep_with_fonte(DepSource::Path {
9464 caminho: "../caixa-teia | tee; rm".into(),
9465 });
9466 let err = d.validate().unwrap_err();
9467 assert!(
9468 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9469 "got {err:?}",
9470 );
9471 }
9472
9473 #[test]
9474 fn fonte_caminho_shell_redirection_fires_before_shell_semicolon() {
9475 // Cascade pin on the upstream shell-redirection arm: a value
9476 // carrying both `<` / `>` and `;` (`"../caixa-teia>log; rm"` —
9477 // the canonical "I pasted a `cmd > log; cleanup` chain"
9478 // footgun) routes through `FonteCaminhoShellRedirection` not
9479 // `FonteCaminhoShellSemicolon`. The input/output redirection
9480 // metachar carries the more self-locating `byte: u8` payload
9481 // (it names which of `<` or `>` triggered), so the prior arm
9482 // wins on every probe-as-both value.
9483 let d = dep_with_fonte(DepSource::Path {
9484 caminho: "../caixa-teia>log; rm".into(),
9485 });
9486 let err = d.validate().unwrap_err();
9487 assert!(
9488 matches!(
9489 err,
9490 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9491 ),
9492 "got {err:?}",
9493 );
9494 }
9495
9496 #[test]
9497 fn fonte_caminho_backslash_fires_before_shell_semicolon() {
9498 // Cascade pin on the upstream backslash arm: a value carrying
9499 // both `\` and `;` (`"..\caixa-teia;rm"` — the canonical "I
9500 // pasted a Windows-shell `cd ..\path; cleanup` chain") routes
9501 // through `FonteCaminhoBackslash` not `FonteCaminhoShellSemicolon`.
9502 // The cross-host-OS-separator divergence is the load-bearing axis
9503 // on every probe-as-both value (an author who removes the `\` is
9504 // the root-cause edit; the `;` falls away in the same edit since
9505 // it's downstream of the Windows-shell convention).
9506 let d = dep_with_fonte(DepSource::Path {
9507 caminho: "..\\caixa-teia;rm".into(),
9508 });
9509 let err = d.validate().unwrap_err();
9510 assert!(
9511 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9512 "got {err:?}",
9513 );
9514 }
9515
9516 #[test]
9517 fn fonte_caminho_control_char_fires_before_shell_semicolon() {
9518 // Cascade pin on the embedded-control-byte arm: a value carrying
9519 // both a control byte and `;` (`"../foo\n;bar"` — the canonical
9520 // paste-from-multiline-doc footgun where a newline landed mid-
9521 // caminho) routes through `FonteCaminhoControlChar` not
9522 // `FonteCaminhoShellSemicolon`. The POSIX-syscall-rejected-byte
9523 // / NUL-`CString::new`-fail diagnostic is the load-bearing axis
9524 // on every value that probes positive for both — mirrors the
9525 // cascade discipline on every prior arm.
9526 let d = dep_with_fonte(DepSource::Path {
9527 caminho: "../foo\n;bar".into(),
9528 });
9529 let err = d.validate().unwrap_err();
9530 assert!(
9531 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9532 "got {err:?}",
9533 );
9534 }
9535
9536 #[test]
9537 fn fonte_caminho_absolute_fires_before_shell_semicolon() {
9538 // Cascade pin on the load-bearing leading-byte arm: a leading
9539 // `/` value with embedded `;` (`"/etc/passwd;rm"`) routes
9540 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellSemicolon`
9541 // — the host-layout-leak diagnostic is the load-bearing axis,
9542 // the `;` byte is the secondary observation. Same precedence
9543 // logic as every prior leading-byte arm.
9544 let d = dep_with_fonte(DepSource::Path {
9545 caminho: "/etc/passwd;rm".into(),
9546 });
9547 let err = d.validate().unwrap_err();
9548 assert!(
9549 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9550 "got {err:?}",
9551 );
9552 }
9553
9554 #[test]
9555 fn fonte_caminho_shell_semicolon_fires_before_trailing_slash() {
9556 // Cascade pin on the immediate-successor arm: a value carrying
9557 // both `;` and a trailing `/` (`"../foo;rm/"` — the canonical
9558 // "I tab-completed a path that already had a `; cleanup` tail"
9559 // footgun) routes through `FonteCaminhoShellSemicolon` not
9560 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
9561 // the more semantic-locating axis (an author who removes the
9562 // `;` typically also drops the trailing separator since both
9563 // are paste-from-shell artifacts).
9564 let d = dep_with_fonte(DepSource::Path {
9565 caminho: "../foo;rm/".into(),
9566 });
9567 let err = d.validate().unwrap_err();
9568 assert!(
9569 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9570 "got {err:?}",
9571 );
9572 }
9573
9574 #[test]
9575 fn fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho() {
9576 // Diagnostic-shape pin (peer with
9577 // `fonte_caminho_shell_pipe_diagnostic_carries_offending_dep_and_caminho`
9578 // on the closest single-byte peer arm): the error's Display
9579 // surfaces the offending `:nome` and the offending `:caminho`
9580 // verbatim, and names the shell-command-separator footgun
9581 // explicitly so a `feira lint` run can render the diagnostic
9582 // without re-parsing.
9583 let d = dep_with_fonte(DepSource::Path {
9584 caminho: "../caixa-teia; rm -rf build".into(),
9585 });
9586 let rendered = d.validate().unwrap_err().to_string();
9587 assert!(
9588 rendered.contains("caixa-teia"),
9589 "diagnostic must name the offending dep: {rendered}",
9590 );
9591 assert!(
9592 rendered.contains("../caixa-teia; rm -rf build"),
9593 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9594 );
9595 assert!(
9596 rendered.contains(';'),
9597 "diagnostic must reference the semicolon footgun: {rendered:?}",
9598 );
9599 assert!(
9600 rendered.contains("command-separator"),
9601 "diagnostic must name the shell-command-separator footgun: {rendered:?}",
9602 );
9603 }
9604
9605 #[test]
9606 fn validate_rejects_path_fonte_with_caminho_carrying_ampersand() {
9607 // The fail-before-pass-after pin for the canonical shell-
9608 // background-task paste footgun: an author copies a shell one-
9609 // liner (`"../caixa-teia & sleep 1"` — the canonical "I selected
9610 // the whole `cd path & sleep 1` background-launch out of a
9611 // shell-history block") and silently passed every prior arm
9612 // (`Path::is_absolute` false on `..`, no control bytes, no
9613 // backslash, no `<` / `>`, no `|`, no `;`, doesn't end in `/`).
9614 // The lacre embedded the value verbatim, the resolver folded it
9615 // through `Path::join` looking for a literal `./../caixa-teia &
9616 // sleep 1` subdirectory, and the failure surfaced at resolve
9617 // time with a non-self-locating `No such file or directory`
9618 // error. The new arm moves the rejection to validate time and
9619 // names the offending dep + caminho verbatim.
9620 let d = dep_with_fonte(DepSource::Path {
9621 caminho: "../caixa-teia & sleep 1".into(),
9622 });
9623 let err = d.validate().unwrap_err();
9624 let DepError::FonteCaminhoShellBackground { nome, caminho } = err else {
9625 panic!("expected FonteCaminhoShellBackground, got {err:?}");
9626 };
9627 assert_eq!(nome, "caixa-teia");
9628 assert_eq!(caminho, "../caixa-teia & sleep 1");
9629 }
9630
9631 #[test]
9632 fn validate_rejects_path_fonte_with_caminho_carrying_leading_ampersand() {
9633 // Leading-position `&` shape (`"&../caixa-teia"` — the
9634 // degenerate "I forgot the prior command side of the
9635 // background terminator" idiom). Pinned separately from the
9636 // embedded-byte shape so the gate covers every position, not
9637 // only mid-path.
9638 let d = dep_with_fonte(DepSource::Path {
9639 caminho: "&../caixa-teia".into(),
9640 });
9641 let err = d.validate().unwrap_err();
9642 assert!(
9643 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9644 "got {err:?}",
9645 );
9646 }
9647
9648 #[test]
9649 fn validate_rejects_path_fonte_with_caminho_carrying_double_ampersand() {
9650 // The logical-AND `&&` shape (`"../caixa-teia && make"` — the
9651 // canonical "I copied a `cd path && make` build chain" idiom
9652 // every Makefile / shell-script wraps). The arm fires on the
9653 // first `&` encountered; pinned so a future arm that tries to
9654 // distinguish `&` from `&&` doesn't break the broader contract.
9655 let d = dep_with_fonte(DepSource::Path {
9656 caminho: "../caixa-teia && make".into(),
9657 });
9658 let err = d.validate().unwrap_err();
9659 assert!(
9660 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9661 "got {err:?}",
9662 );
9663 }
9664
9665 #[test]
9666 fn validate_accepts_path_fonte_with_caminho_carrying_no_ampersand() {
9667 // The positive-control pin: the gate targets only `&`, never
9668 // adjacent printable ASCII or POSIX-valid bytes. The canonical
9669 // relative POSIX path (`"../caixa-teia"`) and a nested deeply-
9670 // pathed variant with adjacent printable punctuation
9671 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9672 // cleanly so the gate doesn't widen to a "no printable
9673 // punctuation anywhere" sweep that would defeat the entire
9674 // path-fonte author surface.
9675 let d = dep_with_fonte(DepSource::Path {
9676 caminho: "../caixa-teia/sub-dir.v2".into(),
9677 });
9678 d.validate().unwrap();
9679 }
9680
9681 #[test]
9682 fn fonte_caminho_shell_semicolon_fires_before_shell_background() {
9683 // Cascade pin on the immediate-predecessor arm: a value carrying
9684 // both `;` and `&` (`"../caixa-teia; rm & sleep"` — the
9685 // canonical "I pasted a `cmd; cleanup & sleep` chain" footgun)
9686 // routes through `FonteCaminhoShellSemicolon` not
9687 // `FonteCaminhoShellBackground`. The sequential-command-
9688 // separator paste is the more common shell-history paste idiom
9689 // on every probe-as-both value (an author who removes the `;`
9690 // typically also drops the trailing `& sleep` since both are
9691 // paste-from-shell-history artifacts) — same cascade discipline
9692 // every prior `:caminho` arm establishes.
9693 let d = dep_with_fonte(DepSource::Path {
9694 caminho: "../caixa-teia; rm & sleep".into(),
9695 });
9696 let err = d.validate().unwrap_err();
9697 assert!(
9698 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
9699 "got {err:?}",
9700 );
9701 }
9702
9703 #[test]
9704 fn fonte_caminho_shell_pipe_fires_before_shell_background() {
9705 // Cascade pin on the upstream shell-pipe arm: a value carrying
9706 // both `|` and `&` (`"../caixa-teia | tee & sleep"` — the
9707 // canonical "I pasted a `cmd | tee & sleep` background-pipeline
9708 // chain" footgun) routes through `FonteCaminhoShellPipe` not
9709 // `FonteCaminhoShellBackground`. The pipeline-tail paste is the
9710 // load-bearing root-cause edit on every probe-as-both value.
9711 let d = dep_with_fonte(DepSource::Path {
9712 caminho: "../caixa-teia | tee & sleep".into(),
9713 });
9714 let err = d.validate().unwrap_err();
9715 assert!(
9716 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
9717 "got {err:?}",
9718 );
9719 }
9720
9721 #[test]
9722 fn fonte_caminho_shell_redirection_fires_before_shell_background() {
9723 // Cascade pin on the upstream shell-redirection arm: a value
9724 // carrying both `>` and `&` (`"../caixa-teia>log & sleep"` —
9725 // the canonical "I pasted a `cmd > log & sleep` background-
9726 // redirect chain" footgun) routes through
9727 // `FonteCaminhoShellRedirection` not
9728 // `FonteCaminhoShellBackground`. The input/output redirection
9729 // metachar carries the more self-locating `byte: u8` payload
9730 // (it names which of `<` or `>` triggered), so the prior arm
9731 // wins on every probe-as-both value.
9732 let d = dep_with_fonte(DepSource::Path {
9733 caminho: "../caixa-teia>log & sleep".into(),
9734 });
9735 let err = d.validate().unwrap_err();
9736 assert!(
9737 matches!(
9738 err,
9739 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
9740 ),
9741 "got {err:?}",
9742 );
9743 }
9744
9745 #[test]
9746 fn fonte_caminho_backslash_fires_before_shell_background() {
9747 // Cascade pin on the upstream backslash arm: a value carrying
9748 // both `\` and `&` (`"..\caixa-teia & sleep"` — the canonical
9749 // "I pasted a Windows-shell `cd ..\path & sleep` background-
9750 // launch chain") routes through `FonteCaminhoBackslash` not
9751 // `FonteCaminhoShellBackground`. The cross-host-OS-separator
9752 // divergence is the load-bearing axis on every probe-as-both
9753 // value (an author who removes the `\` is the root-cause edit;
9754 // the `&` falls away in the same edit since it's downstream of
9755 // the Windows-shell convention).
9756 let d = dep_with_fonte(DepSource::Path {
9757 caminho: "..\\caixa-teia & sleep".into(),
9758 });
9759 let err = d.validate().unwrap_err();
9760 assert!(
9761 matches!(err, DepError::FonteCaminhoBackslash { .. }),
9762 "got {err:?}",
9763 );
9764 }
9765
9766 #[test]
9767 fn fonte_caminho_control_char_fires_before_shell_background() {
9768 // Cascade pin on the embedded-control-byte arm: a value
9769 // carrying both a control byte and `&` (`"../foo\n&sleep"` —
9770 // the canonical paste-from-multiline-doc footgun where a
9771 // newline landed mid-caminho) routes through
9772 // `FonteCaminhoControlChar` not `FonteCaminhoShellBackground`.
9773 // The POSIX-syscall-rejected-byte / NUL-`CString::new`-fail
9774 // diagnostic is the load-bearing axis on every value that
9775 // probes positive for both — mirrors the cascade discipline on
9776 // every prior arm.
9777 let d = dep_with_fonte(DepSource::Path {
9778 caminho: "../foo\n&sleep".into(),
9779 });
9780 let err = d.validate().unwrap_err();
9781 assert!(
9782 matches!(err, DepError::FonteCaminhoControlChar { .. }),
9783 "got {err:?}",
9784 );
9785 }
9786
9787 #[test]
9788 fn fonte_caminho_absolute_fires_before_shell_background() {
9789 // Cascade pin on the load-bearing leading-byte arm: a leading
9790 // `/` value with embedded `&` (`"/etc/passwd & sleep"`) routes
9791 // through `FonteCaminhoAbsolute` not
9792 // `FonteCaminhoShellBackground` — the host-layout-leak
9793 // diagnostic is the load-bearing axis, the `&` byte is the
9794 // secondary observation. Same precedence logic as every prior
9795 // leading-byte arm.
9796 let d = dep_with_fonte(DepSource::Path {
9797 caminho: "/etc/passwd & sleep".into(),
9798 });
9799 let err = d.validate().unwrap_err();
9800 assert!(
9801 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
9802 "got {err:?}",
9803 );
9804 }
9805
9806 #[test]
9807 fn fonte_caminho_shell_background_fires_before_trailing_slash() {
9808 // Cascade pin on the immediate-successor arm: a value carrying
9809 // both `&` and a trailing `/` (`"../foo&sleep/"` — the
9810 // canonical "I tab-completed a path that already had a `&
9811 // sleep` background-launch tail" footgun) routes through
9812 // `FonteCaminhoShellBackground` not `FonteCaminhoTrailingSlash`.
9813 // The embedded shell-metachar is the more semantic-locating
9814 // axis (an author who removes the `&` typically also drops
9815 // the trailing separator since both are paste-from-shell
9816 // artifacts).
9817 let d = dep_with_fonte(DepSource::Path {
9818 caminho: "../foo&sleep/".into(),
9819 });
9820 let err = d.validate().unwrap_err();
9821 assert!(
9822 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9823 "got {err:?}",
9824 );
9825 }
9826
9827 #[test]
9828 fn fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho() {
9829 // Diagnostic-shape pin (peer with
9830 // `fonte_caminho_shell_semicolon_diagnostic_carries_offending_dep_and_caminho`
9831 // on the closest single-byte peer arm): the error's Display
9832 // surfaces the offending `:nome` and the offending `:caminho`
9833 // verbatim, and names the shell-background / logical-AND
9834 // footgun explicitly so a `feira lint` run can render the
9835 // diagnostic without re-parsing.
9836 let d = dep_with_fonte(DepSource::Path {
9837 caminho: "../caixa-teia & sleep 1".into(),
9838 });
9839 let rendered = d.validate().unwrap_err().to_string();
9840 assert!(
9841 rendered.contains("caixa-teia"),
9842 "diagnostic must name the offending dep: {rendered}",
9843 );
9844 assert!(
9845 rendered.contains("../caixa-teia & sleep 1"),
9846 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
9847 );
9848 assert!(
9849 rendered.contains('&'),
9850 "diagnostic must reference the ampersand footgun: {rendered:?}",
9851 );
9852 assert!(
9853 rendered.contains("background") || rendered.contains("list-AND"),
9854 "diagnostic must name the shell-background / logical-AND footgun: {rendered:?}",
9855 );
9856 }
9857
9858 #[test]
9859 fn validate_rejects_path_fonte_with_caminho_carrying_backtick() {
9860 // The fail-before-pass-after pin for the canonical shell-
9861 // command-substitution paste footgun: an author copies a
9862 // POSIX legacy backticked one-liner (`"../caixa-teia/`whoami`"`
9863 // — the canonical "I pasted a path that included a `pwd`
9864 // / `whoami` / `date` legacy command-substitution expansion
9865 // out of a shell-history block") and silently passed every
9866 // prior arm (`Path::is_absolute` false on `..`, no control
9867 // bytes, no `\`, no `<` / `>`, no `|`, no `;`, no `&`, doesn't
9868 // end in `/`). The lacre embedded the value verbatim, the
9869 // resolver folded it through `Path::join` looking for a
9870 // literal `./../caixa-teia/`whoami`` subdirectory, and the
9871 // failure surfaced at resolve time with a non-self-locating
9872 // `No such file or directory` error. The new arm moves the
9873 // rejection to validate time and names the offending dep +
9874 // caminho verbatim.
9875 let d = dep_with_fonte(DepSource::Path {
9876 caminho: "../caixa-teia/`whoami`".into(),
9877 });
9878 let err = d.validate().unwrap_err();
9879 let DepError::FonteCaminhoShellCommandSubstitution { nome, caminho } = err else {
9880 panic!("expected FonteCaminhoShellCommandSubstitution, got {err:?}");
9881 };
9882 assert_eq!(nome, "caixa-teia");
9883 assert_eq!(caminho, "../caixa-teia/`whoami`");
9884 }
9885
9886 #[test]
9887 fn validate_rejects_path_fonte_with_caminho_carrying_leading_backtick() {
9888 // Leading-position backtick shape (``"`pwd`/caixa-teia"`` —
9889 // the canonical `<backtick>pwd<backtick>/path` working-
9890 // directory expansion shape every shell-side path-composition
9891 // idiom carries). Pinned separately from the embedded-byte
9892 // shape so the gate covers every position, not only mid-path.
9893 let d = dep_with_fonte(DepSource::Path {
9894 caminho: "`pwd`/caixa-teia".into(),
9895 });
9896 let err = d.validate().unwrap_err();
9897 assert!(
9898 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9899 "got {err:?}",
9900 );
9901 }
9902
9903 #[test]
9904 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_backtick() {
9905 // Trailing-position backtick shape (`"../caixa-teia`"` — the
9906 // degenerate "I selected an unbalanced backtick out of a
9907 // shell-history block" idiom that probes for the cascade's
9908 // last-byte handling). The trailing-`/` arm fires only on
9909 // last-byte `/`; an unbalanced trailing backtick must route
9910 // through this arm regardless of position.
9911 let d = dep_with_fonte(DepSource::Path {
9912 caminho: "../caixa-teia`".into(),
9913 });
9914 let err = d.validate().unwrap_err();
9915 assert!(
9916 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9917 "got {err:?}",
9918 );
9919 }
9920
9921 #[test]
9922 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_backtick_pair() {
9923 // The canonical balanced-pair shape (``"../<backtick>cat
9924 // /etc/passwd<backtick>"`` — the canonical CWE-78 shell-
9925 // command-injection paste idiom every shell-side hardening
9926 // guide enumerates first). The arm fires on the first
9927 // backtick encountered; pinned so a future arm that tries to
9928 // distinguish the opening from the closing byte doesn't break
9929 // the broader contract.
9930 let d = dep_with_fonte(DepSource::Path {
9931 caminho: "../`cat /etc/passwd`".into(),
9932 });
9933 let err = d.validate().unwrap_err();
9934 assert!(
9935 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
9936 "got {err:?}",
9937 );
9938 }
9939
9940 #[test]
9941 fn validate_accepts_path_fonte_with_caminho_carrying_no_backtick() {
9942 // The positive-control pin: the gate targets only the
9943 // backtick byte, never adjacent printable ASCII or POSIX-
9944 // valid bytes. The canonical relative POSIX path
9945 // (`"../caixa-teia"`) and a nested deeply-pathed variant with
9946 // adjacent printable punctuation
9947 // (`"../caixa-teia/sub-dir.v2"`) must continue to validate
9948 // cleanly so the gate doesn't widen to a "no printable
9949 // punctuation anywhere" sweep that would defeat the entire
9950 // path-fonte author surface.
9951 let d = dep_with_fonte(DepSource::Path {
9952 caminho: "../caixa-teia/sub-dir.v2".into(),
9953 });
9954 d.validate().unwrap();
9955 }
9956
9957 #[test]
9958 fn fonte_caminho_shell_background_fires_before_shell_command_substitution() {
9959 // Cascade pin on the immediate-predecessor arm: a value
9960 // carrying both `&` and a backtick (``"../caixa-teia &
9961 // <backtick>sleep 1<backtick>"`` — the canonical "I pasted a
9962 // `cmd & <backtick>sleep N<backtick>` background-launch +
9963 // command-substitution chain" footgun) routes through
9964 // `FonteCaminhoShellBackground` not
9965 // `FonteCaminhoShellCommandSubstitution`. The background-
9966 // launch tail is the more common shell-history paste idiom
9967 // on every probe-as-both value — same cascade discipline
9968 // every prior `:caminho` arm establishes.
9969 let d = dep_with_fonte(DepSource::Path {
9970 caminho: "../caixa-teia & `sleep 1`".into(),
9971 });
9972 let err = d.validate().unwrap_err();
9973 assert!(
9974 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
9975 "got {err:?}",
9976 );
9977 }
9978
9979 #[test]
9980 fn fonte_caminho_shell_semicolon_fires_before_shell_command_substitution() {
9981 // Cascade pin on the upstream shell-semicolon arm: a value
9982 // carrying both `;` and a backtick (``"../caixa-teia;
9983 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
9984 // `cmd; <backtick>follow-up<backtick>` sequential-chain
9985 // footgun) routes through `FonteCaminhoShellSemicolon` not
9986 // `FonteCaminhoShellCommandSubstitution`. The sequential-
9987 // command-separator paste is the load-bearing root-cause
9988 // edit on every probe-as-both value.
9989 let d = dep_with_fonte(DepSource::Path {
9990 caminho: "../caixa-teia; `whoami`".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_command_substitution() {
10001 // Cascade pin on the upstream shell-pipe arm: a value
10002 // carrying both `|` and a backtick (``"../caixa-teia |
10003 // <backtick>tee log<backtick>"`` — the canonical pipeline-to-
10004 // command-substitution paste idiom) routes through
10005 // `FonteCaminhoShellPipe` not
10006 // `FonteCaminhoShellCommandSubstitution`. The pipeline-tail
10007 // paste is the load-bearing root-cause edit on every
10008 // probe-as-both value.
10009 let d = dep_with_fonte(DepSource::Path {
10010 caminho: "../caixa-teia | `tee log`".into(),
10011 });
10012 let err = d.validate().unwrap_err();
10013 assert!(
10014 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10015 "got {err:?}",
10016 );
10017 }
10018
10019 #[test]
10020 fn fonte_caminho_shell_redirection_fires_before_shell_command_substitution() {
10021 // Cascade pin on the upstream shell-redirection arm: a value
10022 // carrying both `>` and a backtick (``"../caixa-teia>log
10023 // <backtick>date<backtick>"`` — the canonical "I pasted a
10024 // `cmd > log <backtick>date<backtick>` redirect-plus-
10025 // substitution chain" footgun) routes through
10026 // `FonteCaminhoShellRedirection` not
10027 // `FonteCaminhoShellCommandSubstitution`. The input/output
10028 // redirection metachar carries the more self-locating `byte`
10029 // payload (it names which of `<` or `>` triggered), so the
10030 // prior arm wins on every probe-as-both value.
10031 let d = dep_with_fonte(DepSource::Path {
10032 caminho: "../caixa-teia>log `date`".into(),
10033 });
10034 let err = d.validate().unwrap_err();
10035 assert!(
10036 matches!(
10037 err,
10038 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10039 ),
10040 "got {err:?}",
10041 );
10042 }
10043
10044 #[test]
10045 fn fonte_caminho_backslash_fires_before_shell_command_substitution() {
10046 // Cascade pin on the upstream backslash arm: a value
10047 // carrying both `\` and a backtick (``"..\caixa-teia
10048 // <backtick>whoami<backtick>"`` — the canonical "I pasted a
10049 // Windows-shell `cd ..\path <backtick>whoami<backtick>`
10050 // chain") routes through `FonteCaminhoBackslash` not
10051 // `FonteCaminhoShellCommandSubstitution`. The cross-host-OS-
10052 // separator divergence is the load-bearing axis on every
10053 // probe-as-both value (an author who removes the `\` is the
10054 // root-cause edit; the backtick falls away in the same edit
10055 // since it's downstream of the Windows-shell convention).
10056 let d = dep_with_fonte(DepSource::Path {
10057 caminho: "..\\caixa-teia `whoami`".into(),
10058 });
10059 let err = d.validate().unwrap_err();
10060 assert!(
10061 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10062 "got {err:?}",
10063 );
10064 }
10065
10066 #[test]
10067 fn fonte_caminho_control_char_fires_before_shell_command_substitution() {
10068 // Cascade pin on the embedded-control-byte arm: a value
10069 // carrying both a control byte and a backtick (`"../foo\n
10070 // `whoami`"` — the canonical paste-from-multiline-doc
10071 // footgun where a newline landed mid-caminho between two
10072 // paste fragments) routes through `FonteCaminhoControlChar`
10073 // not `FonteCaminhoShellCommandSubstitution`. The POSIX-
10074 // syscall-rejected-byte / NUL-`CString::new`-fail diagnostic
10075 // is the load-bearing axis on every value that probes
10076 // positive for both — mirrors the cascade discipline on
10077 // every prior arm.
10078 let d = dep_with_fonte(DepSource::Path {
10079 caminho: "../foo\n`whoami`".into(),
10080 });
10081 let err = d.validate().unwrap_err();
10082 assert!(
10083 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10084 "got {err:?}",
10085 );
10086 }
10087
10088 #[test]
10089 fn fonte_caminho_absolute_fires_before_shell_command_substitution() {
10090 // Cascade pin on the load-bearing leading-byte arm: a
10091 // leading `/` value with embedded backtick (``"/etc/passwd
10092 // <backtick>whoami<backtick>"``) routes through
10093 // `FonteCaminhoAbsolute` not
10094 // `FonteCaminhoShellCommandSubstitution` — the host-layout-
10095 // leak diagnostic is the load-bearing axis, the backtick
10096 // byte is the secondary observation. Same precedence logic
10097 // as every prior leading-byte arm.
10098 let d = dep_with_fonte(DepSource::Path {
10099 caminho: "/etc/passwd `whoami`".into(),
10100 });
10101 let err = d.validate().unwrap_err();
10102 assert!(
10103 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10104 "got {err:?}",
10105 );
10106 }
10107
10108 #[test]
10109 fn fonte_caminho_shell_command_substitution_fires_before_trailing_slash() {
10110 // Cascade pin on the immediate-successor arm: a value
10111 // carrying both a backtick and a trailing `/`
10112 // (``"../`whoami`/"`` — the canonical "I tab-completed a
10113 // path that already had a backticked `whoami` substitution
10114 // tail" footgun) routes through
10115 // `FonteCaminhoShellCommandSubstitution` not
10116 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
10117 // is the more semantic-locating axis (an author who removes
10118 // the backtick typically also drops the trailing separator
10119 // since both are paste-from-shell artifacts).
10120 let d = dep_with_fonte(DepSource::Path {
10121 caminho: "../`whoami`/".into(),
10122 });
10123 let err = d.validate().unwrap_err();
10124 assert!(
10125 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10126 "got {err:?}",
10127 );
10128 }
10129
10130 #[test]
10131 fn fonte_caminho_shell_command_substitution_diagnostic_carries_offending_dep_and_caminho() {
10132 // Diagnostic-shape pin (peer with
10133 // `fonte_caminho_shell_background_diagnostic_carries_offending_dep_and_caminho`
10134 // on the closest single-byte peer arm): the error's Display
10135 // surfaces the offending `:nome` and the offending `:caminho`
10136 // verbatim, and names the shell-command-substitution footgun
10137 // explicitly so a `feira lint` run can render the diagnostic
10138 // without re-parsing.
10139 let d = dep_with_fonte(DepSource::Path {
10140 caminho: "../caixa-teia/`whoami`".into(),
10141 });
10142 let rendered = d.validate().unwrap_err().to_string();
10143 assert!(
10144 rendered.contains("caixa-teia"),
10145 "diagnostic must name the offending dep: {rendered}",
10146 );
10147 assert!(
10148 rendered.contains("../caixa-teia/`whoami`"),
10149 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10150 );
10151 assert!(
10152 rendered.contains('`'),
10153 "diagnostic must reference the backtick footgun: {rendered:?}",
10154 );
10155 assert!(
10156 rendered.contains("command-substitution"),
10157 "diagnostic must name the shell-command-substitution footgun: {rendered:?}",
10158 );
10159 }
10160
10161 #[test]
10162 fn validate_rejects_path_fonte_with_caminho_carrying_star_glob() {
10163 // The fail-before-pass-after pin for the canonical pathname-
10164 // expansion paste footgun: an author copies an `ls
10165 // ../caixa-teia/*` shell-listing tail into the `:caminho`
10166 // slot and silently passes every prior arm
10167 // (`Path::is_absolute` false on `..`, no control bytes, no
10168 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick,
10169 // doesn't end in `/`). The lacre embedded the value
10170 // verbatim, the resolver folded it through `Path::join`
10171 // looking for a literal `./../caixa-teia/*` subdirectory,
10172 // and the failure surfaced at resolve time with a non-self-
10173 // locating `No such file or directory` error. The new arm
10174 // moves the rejection to validate time and names the
10175 // offending dep + caminho + byte verbatim.
10176 let d = dep_with_fonte(DepSource::Path {
10177 caminho: "../caixa-teia/*".into(),
10178 });
10179 let err = d.validate().unwrap_err();
10180 let DepError::FonteCaminhoShellGlob {
10181 nome,
10182 caminho,
10183 byte,
10184 } = err
10185 else {
10186 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10187 };
10188 assert_eq!(nome, "caixa-teia");
10189 assert_eq!(caminho, "../caixa-teia/*");
10190 assert_eq!(byte, b'*');
10191 }
10192
10193 #[test]
10194 fn validate_rejects_path_fonte_with_caminho_carrying_question_glob() {
10195 // The symmetric single-char-wildcard paste shape
10196 // (`"../foo?"` — the canonical "I copied a `rm foo?` line
10197 // out of shell history" idiom). Pinned separately from the
10198 // `*` shape so the gate's contract is "any `*` or `?`
10199 // anywhere", not single-byte coverage.
10200 let d = dep_with_fonte(DepSource::Path {
10201 caminho: "../foo?".into(),
10202 });
10203 let err = d.validate().unwrap_err();
10204 let DepError::FonteCaminhoShellGlob { byte, .. } = err else {
10205 panic!("expected FonteCaminhoShellGlob, got {err:?}");
10206 };
10207 assert_eq!(byte, b'?');
10208 }
10209
10210 #[test]
10211 fn validate_rejects_path_fonte_with_caminho_carrying_leading_star_glob() {
10212 // Leading-position `*` shape (`"*/caixa-teia"` — the
10213 // degenerate "I selected only the wildcard prefix out of a
10214 // shell-glob expression" idiom). Pinned separately from the
10215 // embedded-byte shapes so the gate covers every position,
10216 // not only mid-path.
10217 let d = dep_with_fonte(DepSource::Path {
10218 caminho: "*/caixa-teia".into(),
10219 });
10220 let err = d.validate().unwrap_err();
10221 assert!(
10222 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10223 "got {err:?}",
10224 );
10225 }
10226
10227 #[test]
10228 fn validate_rejects_path_fonte_with_caminho_carrying_double_star_recursive_glob() {
10229 // The bash/zsh `globstar` recursive-glob shape
10230 // (`"../caixa-teia/**/foo"` — the canonical "I copied a
10231 // `find ../caixa-teia/**/foo` recursive expansion" idiom).
10232 // The arm fires on the first `*` encountered; pinned so a
10233 // future arm that tries to distinguish single `*` from
10234 // double `**` doesn't break the broader contract.
10235 let d = dep_with_fonte(DepSource::Path {
10236 caminho: "../caixa-teia/**/foo".into(),
10237 });
10238 let err = d.validate().unwrap_err();
10239 assert!(
10240 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10241 "got {err:?}",
10242 );
10243 }
10244
10245 #[test]
10246 fn validate_rejects_path_fonte_with_caminho_carrying_dotted_extension_glob() {
10247 // The canonical extension-glob shape (`"../caixa-teia/*.lisp"`
10248 // — the "I selected `*.lisp` to mean every Lisp source file
10249 // in the dep root" footgun the prior arms structurally
10250 // cannot catch since `.` is a POSIX-valid path-component
10251 // byte). Pinned so the gate's contract covers the most
10252 // idiomatic glob-paste shape every author meets first.
10253 let d = dep_with_fonte(DepSource::Path {
10254 caminho: "../caixa-teia/*.lisp".into(),
10255 });
10256 let err = d.validate().unwrap_err();
10257 assert!(
10258 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10259 "got {err:?}",
10260 );
10261 }
10262
10263 #[test]
10264 fn validate_accepts_path_fonte_with_caminho_carrying_no_glob() {
10265 // The positive-control pin: the gate targets only `*` /
10266 // `?`, never adjacent printable ASCII or POSIX-valid bytes.
10267 // The canonical relative POSIX path (`"../caixa-teia"`) and
10268 // a nested deeply-pathed variant with adjacent printable
10269 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
10270 // to validate cleanly so the gate doesn't widen to a "no
10271 // printable punctuation anywhere" sweep that would defeat
10272 // the entire path-fonte author surface.
10273 let d = dep_with_fonte(DepSource::Path {
10274 caminho: "../caixa-teia/sub-dir.v2".into(),
10275 });
10276 d.validate().unwrap();
10277 }
10278
10279 #[test]
10280 fn fonte_caminho_shell_command_substitution_fires_before_shell_glob() {
10281 // Cascade pin on the immediate-predecessor arm: a value
10282 // carrying both a backtick and `*` (``"../`whoami`/*"`` —
10283 // the canonical "I pasted a `cd <backtick>whoami<backtick>/*`
10284 // command-substitution + glob chain") routes through
10285 // `FonteCaminhoShellCommandSubstitution` not
10286 // `FonteCaminhoShellGlob`. The CWE-78 shell-command-
10287 // injection vector is the load-bearing root-cause edit on
10288 // every probe-as-both value — same cascade discipline every
10289 // prior `:caminho` arm establishes.
10290 let d = dep_with_fonte(DepSource::Path {
10291 caminho: "../`whoami`/*".into(),
10292 });
10293 let err = d.validate().unwrap_err();
10294 assert!(
10295 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10296 "got {err:?}",
10297 );
10298 }
10299
10300 #[test]
10301 fn fonte_caminho_shell_background_fires_before_shell_glob() {
10302 // Cascade pin on the upstream shell-background arm: a value
10303 // carrying both `&` and `*` (`"../caixa-teia & ls /*"` — the
10304 // canonical "I pasted a `cmd & ls /*` background + glob
10305 // chain" footgun) routes through `FonteCaminhoShellBackground`
10306 // not `FonteCaminhoShellGlob`. The background-launch tail is
10307 // the load-bearing root-cause edit on every probe-as-both
10308 // value.
10309 let d = dep_with_fonte(DepSource::Path {
10310 caminho: "../caixa-teia & ls /*".into(),
10311 });
10312 let err = d.validate().unwrap_err();
10313 assert!(
10314 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10315 "got {err:?}",
10316 );
10317 }
10318
10319 #[test]
10320 fn fonte_caminho_shell_semicolon_fires_before_shell_glob() {
10321 // Cascade pin on the upstream shell-semicolon arm: a value
10322 // carrying both `;` and `*` (`"../caixa-teia; rm *"` — the
10323 // canonical sequential-cleanup + glob paste idiom) routes
10324 // through `FonteCaminhoShellSemicolon` not
10325 // `FonteCaminhoShellGlob`. The sequential-command-separator
10326 // paste is the load-bearing root-cause edit on every
10327 // probe-as-both value.
10328 let d = dep_with_fonte(DepSource::Path {
10329 caminho: "../caixa-teia; rm *".into(),
10330 });
10331 let err = d.validate().unwrap_err();
10332 assert!(
10333 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10334 "got {err:?}",
10335 );
10336 }
10337
10338 #[test]
10339 fn fonte_caminho_shell_pipe_fires_before_shell_glob() {
10340 // Cascade pin on the upstream shell-pipe arm: a value
10341 // carrying both `|` and `*` (`"../caixa-teia | ls *"` — the
10342 // canonical pipeline-to-glob paste idiom) routes through
10343 // `FonteCaminhoShellPipe` not `FonteCaminhoShellGlob`. The
10344 // pipeline-tail paste is the load-bearing root-cause edit
10345 // on every probe-as-both value.
10346 let d = dep_with_fonte(DepSource::Path {
10347 caminho: "../caixa-teia | ls *".into(),
10348 });
10349 let err = d.validate().unwrap_err();
10350 assert!(
10351 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10352 "got {err:?}",
10353 );
10354 }
10355
10356 #[test]
10357 fn fonte_caminho_shell_redirection_fires_before_shell_glob() {
10358 // Cascade pin on the upstream shell-redirection arm: a value
10359 // carrying both `>` and `*` (`"../caixa-teia>log *"` — the
10360 // canonical "I pasted a `cmd > log *` redirect-plus-glob
10361 // chain" footgun) routes through
10362 // `FonteCaminhoShellRedirection` not `FonteCaminhoShellGlob`.
10363 // The input/output redirection metachar carries the more
10364 // self-locating `byte` payload (it names which of `<` or `>`
10365 // triggered), so the prior arm wins on every probe-as-both
10366 // value.
10367 let d = dep_with_fonte(DepSource::Path {
10368 caminho: "../caixa-teia>log *".into(),
10369 });
10370 let err = d.validate().unwrap_err();
10371 assert!(
10372 matches!(
10373 err,
10374 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10375 ),
10376 "got {err:?}",
10377 );
10378 }
10379
10380 #[test]
10381 fn fonte_caminho_backslash_fires_before_shell_glob() {
10382 // Cascade pin on the upstream backslash arm: a value
10383 // carrying both `\` and `*` (`"..\caixa-teia\*"` — the
10384 // canonical "I pasted a Windows-shell `cd ..\path\*` glob
10385 // expression" footgun) routes through
10386 // `FonteCaminhoBackslash` not `FonteCaminhoShellGlob`. The
10387 // cross-host-OS-separator divergence is the load-bearing
10388 // axis on every probe-as-both value (an author who removes
10389 // the `\` is the root-cause edit; the `*` falls away in the
10390 // same edit since it's downstream of the Windows-shell
10391 // convention).
10392 let d = dep_with_fonte(DepSource::Path {
10393 caminho: "..\\caixa-teia\\*".into(),
10394 });
10395 let err = d.validate().unwrap_err();
10396 assert!(
10397 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10398 "got {err:?}",
10399 );
10400 }
10401
10402 #[test]
10403 fn fonte_caminho_control_char_fires_before_shell_glob() {
10404 // Cascade pin on the embedded-control-byte arm: a value
10405 // carrying both a control byte and `*` (`"../foo\n*"` — the
10406 // canonical paste-from-multiline-doc footgun where a
10407 // newline landed mid-caminho between two paste fragments)
10408 // routes through `FonteCaminhoControlChar` not
10409 // `FonteCaminhoShellGlob`. The POSIX-syscall-rejected-byte /
10410 // NUL-`CString::new`-fail diagnostic is the load-bearing
10411 // axis on every value that probes positive for both —
10412 // mirrors the cascade discipline on every prior arm.
10413 let d = dep_with_fonte(DepSource::Path {
10414 caminho: "../foo\n*".into(),
10415 });
10416 let err = d.validate().unwrap_err();
10417 assert!(
10418 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10419 "got {err:?}",
10420 );
10421 }
10422
10423 #[test]
10424 fn fonte_caminho_absolute_fires_before_shell_glob() {
10425 // Cascade pin on the load-bearing leading-byte arm: a
10426 // leading `/` value with embedded `*` (`"/etc/*"`) routes
10427 // through `FonteCaminhoAbsolute` not `FonteCaminhoShellGlob`
10428 // — the host-layout-leak diagnostic is the load-bearing
10429 // axis, the glob byte is the secondary observation. Same
10430 // precedence logic as every prior leading-byte arm.
10431 let d = dep_with_fonte(DepSource::Path {
10432 caminho: "/etc/*".into(),
10433 });
10434 let err = d.validate().unwrap_err();
10435 assert!(
10436 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10437 "got {err:?}",
10438 );
10439 }
10440
10441 #[test]
10442 fn fonte_caminho_shell_glob_fires_before_trailing_slash() {
10443 // Cascade pin on the immediate-successor arm: a value
10444 // carrying both `*` and a trailing `/` (`"../foo*/"` — the
10445 // canonical "I tab-completed a path that already had a
10446 // glob-expansion tail" footgun) routes through
10447 // `FonteCaminhoShellGlob` not `FonteCaminhoTrailingSlash`.
10448 // The embedded shell-metachar is the more semantic-locating
10449 // axis (an author who removes the `*` typically also drops
10450 // the trailing separator since both are paste-from-shell
10451 // artifacts).
10452 let d = dep_with_fonte(DepSource::Path {
10453 caminho: "../foo*/".into(),
10454 });
10455 let err = d.validate().unwrap_err();
10456 assert!(
10457 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10458 "got {err:?}",
10459 );
10460 }
10461
10462 #[test]
10463 fn fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte() {
10464 // Diagnostic-shape pin (peer with
10465 // `fonte_caminho_shell_redirection_diagnostic_*` on the
10466 // closest two-byte peer arm): the error's Display surfaces
10467 // the offending `:nome`, the offending `:caminho` verbatim,
10468 // the offending byte's hex / character form, and names the
10469 // shell-glob / pathname-expansion footgun explicitly so a
10470 // `feira lint` run can render the diagnostic without
10471 // re-parsing.
10472 let d = dep_with_fonte(DepSource::Path {
10473 caminho: "../caixa-teia/*.lisp".into(),
10474 });
10475 let rendered = d.validate().unwrap_err().to_string();
10476 assert!(
10477 rendered.contains("caixa-teia"),
10478 "diagnostic must name the offending dep: {rendered}",
10479 );
10480 assert!(
10481 rendered.contains("../caixa-teia/*.lisp"),
10482 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10483 );
10484 assert!(
10485 rendered.contains("0x2a"),
10486 "diagnostic must surface the offending byte hex: {rendered:?}",
10487 );
10488 assert!(
10489 rendered.contains("glob"),
10490 "diagnostic must name the shell-glob footgun: {rendered:?}",
10491 );
10492 assert!(
10493 rendered.contains("pathname-expansion"),
10494 "diagnostic must reference the POSIX pathname-expansion vocabulary: {rendered:?}",
10495 );
10496 }
10497
10498 #[test]
10499 fn validate_rejects_path_fonte_with_caminho_carrying_modern_command_substitution() {
10500 // The fail-before-pass-after pin for the canonical modern-Bourne
10501 // command-substitution paste footgun: an author copies a
10502 // `cd ../caixa-teia/$(date)/build` shell-history one-liner whose
10503 // `$(<cmd>)` expansion would land the current date as a
10504 // subdirectory name and silently passed every prior arm
10505 // (`Path::is_absolute` false on `..`, no control bytes, no `\`,
10506 // no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no `*` /
10507 // `?`, doesn't end in `/`; the leading-`$` f4efe9c
10508 // `FonteCaminhoVarExpansion` arm doesn't fire because the `$`
10509 // sits mid-path). The lacre embedded the value verbatim, the
10510 // resolver folded it through `Path::join` looking for a literal
10511 // `./../caixa-teia/$(date)/build` subdirectory, and the failure
10512 // surfaced at resolve time with a non-self-locating `No such
10513 // file or directory` error. The new arm moves the rejection to
10514 // validate time and names the offending dep + caminho + byte
10515 // verbatim. The arm fires on the first `(` encountered (the
10516 // opening byte of `$(date)`).
10517 let d = dep_with_fonte(DepSource::Path {
10518 caminho: "../caixa-teia/$(date)/build".into(),
10519 });
10520 let err = d.validate().unwrap_err();
10521 let DepError::FonteCaminhoShellSubshellGrouping {
10522 nome,
10523 caminho,
10524 byte,
10525 } = err
10526 else {
10527 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10528 };
10529 assert_eq!(nome, "caixa-teia");
10530 assert_eq!(caminho, "../caixa-teia/$(date)/build");
10531 assert_eq!(byte, b'(');
10532 }
10533
10534 #[test]
10535 fn validate_rejects_path_fonte_with_caminho_carrying_close_paren() {
10536 // The symmetric close-paren paste shape (`"../caixa-teia)"` —
10537 // the degenerate "I selected an unbalanced closing paren out of
10538 // a shell-history block" idiom that probes for the cascade's
10539 // last-byte handling on a value carrying only the closing byte).
10540 // Pinned separately from the open-paren shape so the gate's
10541 // contract is "any `(` or `)` anywhere", not single-byte
10542 // coverage. Mirrors the peer `validate_rejects_path_fonte_with_\
10543 // caminho_carrying_question_glob` shape on the immediate-
10544 // predecessor `FonteCaminhoShellGlob` arm.
10545 let d = dep_with_fonte(DepSource::Path {
10546 caminho: "../caixa-teia)".into(),
10547 });
10548 let err = d.validate().unwrap_err();
10549 let DepError::FonteCaminhoShellSubshellGrouping { byte, .. } = err else {
10550 panic!("expected FonteCaminhoShellSubshellGrouping, got {err:?}");
10551 };
10552 assert_eq!(byte, b')');
10553 }
10554
10555 #[test]
10556 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_paren() {
10557 // Leading-position `(` shape (`"(cd foo)/caixa-teia"` — the
10558 // canonical "I selected a `(cd foo)` subshell-grouping prefix
10559 // out of a `(cd foo) && cmd` shell-history one-liner" idiom).
10560 // Pinned separately from the embedded-byte shape so the gate
10561 // covers every position, not only mid-path.
10562 let d = dep_with_fonte(DepSource::Path {
10563 caminho: "(cd foo)/caixa-teia".into(),
10564 });
10565 let err = d.validate().unwrap_err();
10566 assert!(
10567 matches!(
10568 err,
10569 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10570 ),
10571 "got {err:?}",
10572 );
10573 }
10574
10575 #[test]
10576 fn validate_rejects_path_fonte_with_caminho_carrying_balanced_subshell_grouping_pair() {
10577 // The canonical balanced-pair shape (`"../(pwd)/caixa-teia"`
10578 // — the canonical "I copied a `(pwd)` working-directory-probe
10579 // subshell-grouping idiom every shell-history block carries"
10580 // footgun). The value carries no other cascade-preceding
10581 // shell metachar (`&` / `;` / `|` / `<` / `>` / backtick /
10582 // `*` / `?`) so the arm fires on the first `(` encountered;
10583 // pinned so a future arm that tries to distinguish the
10584 // opening from the closing byte doesn't break the broader
10585 // contract. Mirrors the peer
10586 // `validate_rejects_path_fonte_with_caminho_carrying_balanced_\
10587 // backtick_pair` shape on the upstream `FonteCaminhoShell\
10588 // CommandSubstitution` arm.
10589 let d = dep_with_fonte(DepSource::Path {
10590 caminho: "../(pwd)/caixa-teia".into(),
10591 });
10592 let err = d.validate().unwrap_err();
10593 assert!(
10594 matches!(
10595 err,
10596 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10597 ),
10598 "got {err:?}",
10599 );
10600 }
10601
10602 #[test]
10603 fn validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping() {
10604 // The positive-control pin: the gate targets only `(` / `)`,
10605 // never adjacent printable ASCII or POSIX-valid bytes. The
10606 // canonical relative POSIX path (`"../caixa-teia"`) and a
10607 // nested deeply-pathed variant with adjacent printable
10608 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
10609 // validate cleanly so the gate doesn't widen to a "no printable
10610 // punctuation anywhere" sweep that would defeat the entire
10611 // path-fonte author surface.
10612 let d = dep_with_fonte(DepSource::Path {
10613 caminho: "../caixa-teia/sub-dir.v2".into(),
10614 });
10615 d.validate().unwrap();
10616 }
10617
10618 #[test]
10619 fn fonte_caminho_shell_glob_fires_before_shell_subshell_grouping() {
10620 // Cascade pin on the immediate-predecessor arm: a value
10621 // carrying both `*` and `(` (`"../caixa-teia/*(date)"` — the
10622 // canonical "I pasted a glob expansion followed by a
10623 // subshell-grouping tail" footgun) routes through
10624 // `FonteCaminhoShellGlob` not
10625 // `FonteCaminhoShellSubshellGrouping`. The pathname-expansion
10626 // shape is the more common shell-history paste idiom on every
10627 // probe-as-both value — same cascade discipline every prior
10628 // `:caminho` arm establishes.
10629 let d = dep_with_fonte(DepSource::Path {
10630 caminho: "../caixa-teia/*(date)".into(),
10631 });
10632 let err = d.validate().unwrap_err();
10633 assert!(
10634 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
10635 "got {err:?}",
10636 );
10637 }
10638
10639 #[test]
10640 fn fonte_caminho_shell_command_substitution_fires_before_shell_subshell_grouping() {
10641 // Cascade pin on the upstream shell-command-substitution arm: a
10642 // value carrying both a backtick and `(` (``"../`whoami`/$(date)"``
10643 // — the canonical "I pasted a legacy-backtick + modern-paren
10644 // command-substitution chain" footgun) routes through
10645 // `FonteCaminhoShellCommandSubstitution` not
10646 // `FonteCaminhoShellSubshellGrouping`. The CWE-78 shell-
10647 // command-injection vector is the load-bearing root-cause edit
10648 // on every probe-as-both value.
10649 let d = dep_with_fonte(DepSource::Path {
10650 caminho: "../`whoami`/$(date)".into(),
10651 });
10652 let err = d.validate().unwrap_err();
10653 assert!(
10654 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
10655 "got {err:?}",
10656 );
10657 }
10658
10659 #[test]
10660 fn fonte_caminho_shell_background_fires_before_shell_subshell_grouping() {
10661 // Cascade pin on the upstream shell-background arm: a value
10662 // carrying both `&` and `(` (`"../caixa-teia & (cd foo)"` —
10663 // the canonical "I pasted a `cmd & (cd foo)` background-launch
10664 // + subshell-grouping chain" footgun) routes through
10665 // `FonteCaminhoShellBackground` not
10666 // `FonteCaminhoShellSubshellGrouping`. The background-launch
10667 // tail is the load-bearing root-cause edit on every probe-as-
10668 // both value.
10669 let d = dep_with_fonte(DepSource::Path {
10670 caminho: "../caixa-teia & (cd foo)".into(),
10671 });
10672 let err = d.validate().unwrap_err();
10673 assert!(
10674 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
10675 "got {err:?}",
10676 );
10677 }
10678
10679 #[test]
10680 fn fonte_caminho_shell_semicolon_fires_before_shell_subshell_grouping() {
10681 // Cascade pin on the upstream shell-semicolon arm: a value
10682 // carrying both `;` and `(` (`"../caixa-teia; (cd foo)"` —
10683 // the canonical sequential-cleanup + subshell-grouping paste
10684 // idiom) routes through `FonteCaminhoShellSemicolon` not
10685 // `FonteCaminhoShellSubshellGrouping`. The sequential-command-
10686 // separator paste is the load-bearing root-cause edit on
10687 // every probe-as-both value.
10688 let d = dep_with_fonte(DepSource::Path {
10689 caminho: "../caixa-teia; (cd foo)".into(),
10690 });
10691 let err = d.validate().unwrap_err();
10692 assert!(
10693 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
10694 "got {err:?}",
10695 );
10696 }
10697
10698 #[test]
10699 fn fonte_caminho_shell_pipe_fires_before_shell_subshell_grouping() {
10700 // Cascade pin on the upstream shell-pipe arm: a value carrying
10701 // both `|` and `(` (`"../caixa-teia | (tee log)"` — the
10702 // canonical pipeline-to-subshell-grouping paste idiom) routes
10703 // through `FonteCaminhoShellPipe` not
10704 // `FonteCaminhoShellSubshellGrouping`. The pipeline-tail paste
10705 // is the load-bearing root-cause edit on every probe-as-both
10706 // value.
10707 let d = dep_with_fonte(DepSource::Path {
10708 caminho: "../caixa-teia | (tee log)".into(),
10709 });
10710 let err = d.validate().unwrap_err();
10711 assert!(
10712 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
10713 "got {err:?}",
10714 );
10715 }
10716
10717 #[test]
10718 fn fonte_caminho_shell_redirection_fires_before_shell_subshell_grouping() {
10719 // Cascade pin on the upstream shell-redirection arm: a value
10720 // carrying both `>` and `(` (`"../caixa-teia>log (cd foo)"` —
10721 // the canonical "I pasted a `cmd > log (cd foo)` redirect-
10722 // plus-subshell-grouping chain" footgun) routes through
10723 // `FonteCaminhoShellRedirection` not
10724 // `FonteCaminhoShellSubshellGrouping`. The input/output
10725 // redirection metachar carries the more self-locating `byte`
10726 // payload (it names which of `<` or `>` triggered), so the
10727 // prior arm wins on every probe-as-both value.
10728 let d = dep_with_fonte(DepSource::Path {
10729 caminho: "../caixa-teia>log (cd foo)".into(),
10730 });
10731 let err = d.validate().unwrap_err();
10732 assert!(
10733 matches!(
10734 err,
10735 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
10736 ),
10737 "got {err:?}",
10738 );
10739 }
10740
10741 #[test]
10742 fn fonte_caminho_backslash_fires_before_shell_subshell_grouping() {
10743 // Cascade pin on the upstream backslash arm: a value carrying
10744 // both `\` and `(` (`"..\caixa-teia\(cd foo)"` — the canonical
10745 // "I pasted a Windows-shell `cd ..\path\(cmd)` chain") routes
10746 // through `FonteCaminhoBackslash` not
10747 // `FonteCaminhoShellSubshellGrouping`. The cross-host-OS-
10748 // separator divergence is the load-bearing axis on every
10749 // probe-as-both value (an author who removes the `\` is the
10750 // root-cause edit; the `(` falls away in the same edit since
10751 // it's downstream of the Windows-shell convention).
10752 let d = dep_with_fonte(DepSource::Path {
10753 caminho: "..\\caixa-teia\\(cd foo)".into(),
10754 });
10755 let err = d.validate().unwrap_err();
10756 assert!(
10757 matches!(err, DepError::FonteCaminhoBackslash { .. }),
10758 "got {err:?}",
10759 );
10760 }
10761
10762 #[test]
10763 fn fonte_caminho_control_char_fires_before_shell_subshell_grouping() {
10764 // Cascade pin on the embedded-control-byte arm: a value
10765 // carrying both a control byte and `(` (`"../foo\n(cd bar)"` —
10766 // the canonical paste-from-multiline-doc footgun where a
10767 // newline landed mid-caminho between two paste fragments)
10768 // routes through `FonteCaminhoControlChar` not
10769 // `FonteCaminhoShellSubshellGrouping`. The POSIX-syscall-
10770 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
10771 // load-bearing axis on every value that probes positive for
10772 // both — mirrors the cascade discipline on every prior arm.
10773 let d = dep_with_fonte(DepSource::Path {
10774 caminho: "../foo\n(cd bar)".into(),
10775 });
10776 let err = d.validate().unwrap_err();
10777 assert!(
10778 matches!(err, DepError::FonteCaminhoControlChar { .. }),
10779 "got {err:?}",
10780 );
10781 }
10782
10783 #[test]
10784 fn fonte_caminho_absolute_fires_before_shell_subshell_grouping() {
10785 // Cascade pin on the load-bearing leading-byte arm: a leading
10786 // `/` value with embedded `(` (`"/etc/(cd foo)"`) routes
10787 // through `FonteCaminhoAbsolute` not
10788 // `FonteCaminhoShellSubshellGrouping` — the host-layout-leak
10789 // diagnostic is the load-bearing axis, the subshell-grouping
10790 // byte is the secondary observation. Same precedence logic as
10791 // every prior leading-byte arm.
10792 let d = dep_with_fonte(DepSource::Path {
10793 caminho: "/etc/(cd foo)".into(),
10794 });
10795 let err = d.validate().unwrap_err();
10796 assert!(
10797 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
10798 "got {err:?}",
10799 );
10800 }
10801
10802 #[test]
10803 fn fonte_caminho_var_expansion_fires_before_shell_subshell_grouping() {
10804 // Cascade pin on the upstream leading-`$` var-expansion arm: a
10805 // value carrying both a leading `$` and a `(` (`"$(date)/\
10806 // caixa-teia"` — the canonical "I pasted a `$(date)` modern-
10807 // command-substitution at the head of a sibling-workspace
10808 // path" footgun) routes through `FonteCaminhoVarExpansion` not
10809 // `FonteCaminhoShellSubshellGrouping`. The leading-byte
10810 // shell-variable-expansion is the more self-locating diagnostic
10811 // on values that probe as both — same load-bearing-leading-
10812 // byte cascade discipline every prior `:caminho` arm
10813 // establishes. Closing both halves of `$(<cmd>)` structurally
10814 // (leading `$` here, trailing `)` on the new arm) excludes the
10815 // entire modern Bourne command-substitution surface from the
10816 // typed `:caminho` accepted set; the cascade preserves the
10817 // narrower leading-byte diagnostic on values that probe both
10818 // halves at the canonical leading position.
10819 let d = dep_with_fonte(DepSource::Path {
10820 caminho: "$(date)/caixa-teia".into(),
10821 });
10822 let err = d.validate().unwrap_err();
10823 assert!(
10824 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
10825 "got {err:?}",
10826 );
10827 }
10828
10829 #[test]
10830 fn fonte_caminho_shell_subshell_grouping_fires_before_trailing_slash() {
10831 // Cascade pin on the immediate-successor arm: a value carrying
10832 // both `(` and a trailing `/` (`"../(cd foo)/"` — the canonical
10833 // "I tab-completed a path that already had a subshell-grouping
10834 // expansion tail" footgun) routes through
10835 // `FonteCaminhoShellSubshellGrouping` not
10836 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar is
10837 // the more semantic-locating axis (an author who removes the
10838 // `(` typically also drops the trailing separator since both
10839 // are paste-from-shell artifacts).
10840 let d = dep_with_fonte(DepSource::Path {
10841 caminho: "../(cd foo)/".into(),
10842 });
10843 let err = d.validate().unwrap_err();
10844 assert!(
10845 matches!(
10846 err,
10847 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
10848 ),
10849 "got {err:?}",
10850 );
10851 }
10852
10853 #[test]
10854 fn fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
10855 // Diagnostic-shape pin (peer with
10856 // `fonte_caminho_shell_glob_diagnostic_carries_offending_dep_caminho_and_byte`
10857 // on the closest two-byte peer arm): the error's Display
10858 // surfaces the offending `:nome`, the offending `:caminho`
10859 // verbatim, the offending byte's hex / character form, and
10860 // names the shell-subshell-grouping footgun explicitly so a
10861 // `feira lint` run can render the diagnostic without re-
10862 // parsing.
10863 let d = dep_with_fonte(DepSource::Path {
10864 caminho: "../caixa-teia/$(date)/build".into(),
10865 });
10866 let rendered = d.validate().unwrap_err().to_string();
10867 assert!(
10868 rendered.contains("caixa-teia"),
10869 "diagnostic must name the offending dep: {rendered}",
10870 );
10871 assert!(
10872 rendered.contains("../caixa-teia/$(date)/build"),
10873 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
10874 );
10875 assert!(
10876 rendered.contains("0x28"),
10877 "diagnostic must surface the offending byte hex: {rendered:?}",
10878 );
10879 assert!(
10880 rendered.contains("subshell-grouping"),
10881 "diagnostic must name the shell-subshell-grouping footgun: {rendered:?}",
10882 );
10883 assert!(
10884 rendered.contains("command-substitution"),
10885 "diagnostic must reference the `$(<cmd>)` command-substitution vocabulary: \
10886 {rendered:?}",
10887 );
10888 }
10889
10890 // ── shell-brace-expansion / URI-Template-placeholder arm ───────────
10891 //
10892 // Peer with the prior `FonteCaminhoShellSubshellGrouping` (`(` /
10893 // `)`) byte-pair arm: the same per-byte cascade with the same
10894 // self-locating `byte: u8` diagnostic on the orthogonal `{` /
10895 // `}` brace-expansion / URI-Template placeholder axis. The peer
10896 // [`crate::render::is_git_repo_url`] (42d8f9d) closes the same
10897 // byte pair on the sibling `:fonte :repo` axis under the same
10898 // banner.
10899
10900 #[test]
10901 fn validate_rejects_path_fonte_with_caminho_carrying_brace_expansion_fan_across_siblings() {
10902 // The fail-before-pass-after pin for the canonical paste-from-
10903 // shell-history brace-expansion footgun: an author copies a
10904 // `cd ../{caixa-teia,caixa-helm}/build` shell-history one-
10905 // liner whose `{a,b}` brace expansion fans across two siblings
10906 // and silently passed every prior arm (`Path::is_absolute`
10907 // false on `..`, no control bytes, no `\`, no `<` / `>`, no
10908 // `|`, no `;`, no `&`, no backtick, no `*` / `?`, no `(` /
10909 // `)`, doesn't end in `/`; the leading-`$` f4efe9c
10910 // `FonteCaminhoVarExpansion` arm doesn't fire because the
10911 // value starts with `..` not `$`). The lacre embedded the
10912 // value verbatim, the resolver folded it through `Path::join`
10913 // looking for a literal `./../{caixa-teia,caixa-helm}/build`
10914 // subdirectory, and the failure surfaced at resolve time with
10915 // a non-self-locating `No such file or directory` error. The
10916 // new arm moves the rejection to validate time and names the
10917 // offending dep + caminho + byte verbatim. The arm fires on
10918 // the first `{` encountered.
10919 let d = dep_with_fonte(DepSource::Path {
10920 caminho: "../{caixa-teia,caixa-helm}/build".into(),
10921 });
10922 let err = d.validate().unwrap_err();
10923 let DepError::FonteCaminhoShellBraceExpansion {
10924 nome,
10925 caminho,
10926 byte,
10927 } = err
10928 else {
10929 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10930 };
10931 assert_eq!(nome, "caixa-teia");
10932 assert_eq!(caminho, "../{caixa-teia,caixa-helm}/build");
10933 assert_eq!(byte, b'{');
10934 }
10935
10936 #[test]
10937 fn validate_rejects_path_fonte_with_caminho_carrying_close_brace() {
10938 // The symmetric close-brace paste shape (`"../caixa-teia}"` —
10939 // the degenerate "I selected an unbalanced closing brace out
10940 // of a shell-history block" idiom that probes for the
10941 // cascade's last-byte handling on a value carrying only the
10942 // closing byte). Pinned separately from the open-brace shape
10943 // so the gate's contract is "any `{` or `}` anywhere", not
10944 // single-byte coverage. Mirrors the peer
10945 // `validate_rejects_path_fonte_with_caminho_carrying_close_paren`
10946 // shape on the immediate-predecessor `FonteCaminhoShellSubshellGrouping`
10947 // arm.
10948 let d = dep_with_fonte(DepSource::Path {
10949 caminho: "../caixa-teia}".into(),
10950 });
10951 let err = d.validate().unwrap_err();
10952 let DepError::FonteCaminhoShellBraceExpansion { byte, .. } = err else {
10953 panic!("expected FonteCaminhoShellBraceExpansion, got {err:?}");
10954 };
10955 assert_eq!(byte, b'}');
10956 }
10957
10958 #[test]
10959 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_brace() {
10960 // Leading-position `{` shape (`"{caixa-teia,caixa-helm}/build"`
10961 // — the canonical "I selected a `{a,b}` brace-expansion prefix
10962 // out of a shell-history one-liner" idiom). Pinned separately
10963 // from the embedded-byte shape so the gate covers every
10964 // position, not only mid-path.
10965 let d = dep_with_fonte(DepSource::Path {
10966 caminho: "{caixa-teia,caixa-helm}/build".into(),
10967 });
10968 let err = d.validate().unwrap_err();
10969 assert!(
10970 matches!(
10971 err,
10972 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10973 ),
10974 "got {err:?}",
10975 );
10976 }
10977
10978 #[test]
10979 fn validate_rejects_path_fonte_with_caminho_carrying_uri_template_placeholder() {
10980 // The canonical URI-Template / Mustache / Helm doubled-brace
10981 // placeholder shape (`"../{{org}}/caixa-teia"` — the canonical
10982 // "I copied a `https://github.com/{{org}}/caixa-teia` README
10983 // quick-start / OpenAPI spec / Helm chart `home:` template
10984 // and forgot to substitute the placeholder" footgun). The arm
10985 // fires on the first `{` encountered; pinned so the gate's
10986 // coverage extends from the bare-brace shell-history shape to
10987 // the doubled-brace URI-Template / templating-engine shape.
10988 // Mirrors the peer 42d8f9d `is_git_repo_url` arm on the
10989 // sibling `:fonte :repo` axis.
10990 let d = dep_with_fonte(DepSource::Path {
10991 caminho: "../{{org}}/caixa-teia".into(),
10992 });
10993 let err = d.validate().unwrap_err();
10994 assert!(
10995 matches!(
10996 err,
10997 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
10998 ),
10999 "got {err:?}",
11000 );
11001 }
11002
11003 #[test]
11004 fn validate_rejects_path_fonte_with_caminho_carrying_brace_range_expansion() {
11005 // The canonical bash brace-range-expansion shape (`"../caixa-
11006 // v{1..10}"` — the `{1..10}` sequence expansion every bash /
11007 // zsh `for i in {1..10}; do …; done` idiom uses, the symmetric
11008 // sequence-range form to the `{a,b,c}` comma-separated form).
11009 // The arm fires on the first `{` encountered; pinned so the
11010 // gate's coverage extends from the comma-separated form to
11011 // the integer-range form.
11012 let d = dep_with_fonte(DepSource::Path {
11013 caminho: "../caixa-v{1..10}".into(),
11014 });
11015 let err = d.validate().unwrap_err();
11016 assert!(
11017 matches!(
11018 err,
11019 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11020 ),
11021 "got {err:?}",
11022 );
11023 }
11024
11025 #[test]
11026 fn validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion() {
11027 // The positive-control pin: the gate targets only `{` / `}`,
11028 // never adjacent printable ASCII or POSIX-valid bytes. The
11029 // canonical relative POSIX path (`"../caixa-teia"`) and a
11030 // nested deeply-pathed variant with adjacent printable
11031 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue to
11032 // validate cleanly so the gate doesn't widen to a "no
11033 // printable punctuation anywhere" sweep that would defeat
11034 // the entire path-fonte author surface. Peer with
11035 // `validate_accepts_path_fonte_with_caminho_carrying_no_subshell_grouping`
11036 // on the immediate-predecessor arm.
11037 let d = dep_with_fonte(DepSource::Path {
11038 caminho: "../caixa-teia/sub-dir.v2".into(),
11039 });
11040 d.validate().unwrap();
11041 }
11042
11043 #[test]
11044 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_brace_expansion() {
11045 // Cascade pin on the immediate-predecessor arm: a value
11046 // carrying both `(` and `{` (`"../(cd foo)/{a,b}"` — the
11047 // canonical "I pasted a subshell-grouping followed by a
11048 // brace-expansion tail" footgun) routes through
11049 // `FonteCaminhoShellSubshellGrouping` not
11050 // `FonteCaminhoShellBraceExpansion`. The subshell-grouping
11051 // shape is the more semantic-locating axis on every probe-
11052 // as-both value because it closes both halves of the modern
11053 // Bourne `$(<cmd>)` command-substitution surface — same
11054 // cascade discipline every prior `:caminho` arm establishes.
11055 let d = dep_with_fonte(DepSource::Path {
11056 caminho: "../(cd foo)/{a,b}".into(),
11057 });
11058 let err = d.validate().unwrap_err();
11059 assert!(
11060 matches!(
11061 err,
11062 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11063 ),
11064 "got {err:?}",
11065 );
11066 }
11067
11068 #[test]
11069 fn fonte_caminho_shell_glob_fires_before_shell_brace_expansion() {
11070 // Cascade pin on the upstream shell-glob arm: a value carrying
11071 // both `*` and `{` (`"../caixa-teia/*{a,b}"` — the canonical
11072 // "I pasted a glob expansion followed by a brace-expansion
11073 // tail" footgun) routes through `FonteCaminhoShellGlob` not
11074 // `FonteCaminhoShellBraceExpansion`. The pathname-expansion
11075 // shape is the load-bearing root-cause edit on every
11076 // probe-as-both value.
11077 let d = dep_with_fonte(DepSource::Path {
11078 caminho: "../caixa-teia/*{a,b}".into(),
11079 });
11080 let err = d.validate().unwrap_err();
11081 assert!(
11082 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11083 "got {err:?}",
11084 );
11085 }
11086
11087 #[test]
11088 fn fonte_caminho_shell_command_substitution_fires_before_shell_brace_expansion() {
11089 // Cascade pin on the upstream shell-command-substitution arm:
11090 // a value carrying both a backtick and `{` (``"../`whoami`/{a,b}"``
11091 // — the canonical "I pasted a legacy-backtick command-
11092 // substitution followed by a brace-expansion fan-out" footgun)
11093 // routes through `FonteCaminhoShellCommandSubstitution` not
11094 // `FonteCaminhoShellBraceExpansion`. The CWE-78 shell-
11095 // command-injection vector is the load-bearing root-cause
11096 // edit on every probe-as-both value.
11097 let d = dep_with_fonte(DepSource::Path {
11098 caminho: "../`whoami`/{a,b}".into(),
11099 });
11100 let err = d.validate().unwrap_err();
11101 assert!(
11102 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11103 "got {err:?}",
11104 );
11105 }
11106
11107 #[test]
11108 fn fonte_caminho_shell_background_fires_before_shell_brace_expansion() {
11109 // Cascade pin on the upstream shell-background arm: a value
11110 // carrying both `&` and `{` (`"../caixa-teia & {a,b}"` — the
11111 // canonical "I pasted a `cmd & {fork-fan}` background-launch
11112 // + brace-expansion chain" footgun) routes through
11113 // `FonteCaminhoShellBackground` not
11114 // `FonteCaminhoShellBraceExpansion`. The background-launch
11115 // tail is the load-bearing root-cause edit on every
11116 // probe-as-both value.
11117 let d = dep_with_fonte(DepSource::Path {
11118 caminho: "../caixa-teia & {a,b}".into(),
11119 });
11120 let err = d.validate().unwrap_err();
11121 assert!(
11122 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11123 "got {err:?}",
11124 );
11125 }
11126
11127 #[test]
11128 fn fonte_caminho_shell_semicolon_fires_before_shell_brace_expansion() {
11129 // Cascade pin on the upstream shell-semicolon arm: a value
11130 // carrying both `;` and `{` (`"../caixa-teia; {a,b}"` — the
11131 // canonical sequential-cleanup + brace-expansion paste
11132 // idiom) routes through `FonteCaminhoShellSemicolon` not
11133 // `FonteCaminhoShellBraceExpansion`. The sequential-command-
11134 // separator paste is the load-bearing root-cause edit on
11135 // every probe-as-both value.
11136 let d = dep_with_fonte(DepSource::Path {
11137 caminho: "../caixa-teia; {a,b}".into(),
11138 });
11139 let err = d.validate().unwrap_err();
11140 assert!(
11141 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11142 "got {err:?}",
11143 );
11144 }
11145
11146 #[test]
11147 fn fonte_caminho_shell_pipe_fires_before_shell_brace_expansion() {
11148 // Cascade pin on the upstream shell-pipe arm: a value
11149 // carrying both `|` and `{` (`"../caixa-teia | {tee,cat}"`
11150 // — the canonical pipeline-to-brace-expansion paste idiom)
11151 // routes through `FonteCaminhoShellPipe` not
11152 // `FonteCaminhoShellBraceExpansion`. The pipeline-tail paste
11153 // is the load-bearing root-cause edit on every probe-as-
11154 // both value.
11155 let d = dep_with_fonte(DepSource::Path {
11156 caminho: "../caixa-teia | {tee,cat}".into(),
11157 });
11158 let err = d.validate().unwrap_err();
11159 assert!(
11160 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11161 "got {err:?}",
11162 );
11163 }
11164
11165 #[test]
11166 fn fonte_caminho_shell_redirection_fires_before_shell_brace_expansion() {
11167 // Cascade pin on the upstream shell-redirection arm: a value
11168 // carrying both `>` and `{` (`"../caixa-teia>log {a,b}"` —
11169 // the canonical "I pasted a `cmd > log {a,b}` redirect-
11170 // plus-brace-expansion chain" footgun) routes through
11171 // `FonteCaminhoShellRedirection` not
11172 // `FonteCaminhoShellBraceExpansion`. The input/output
11173 // redirection metachar carries the more self-locating
11174 // `byte` payload, so the prior arm wins on every probe-
11175 // as-both value.
11176 let d = dep_with_fonte(DepSource::Path {
11177 caminho: "../caixa-teia>log {a,b}".into(),
11178 });
11179 let err = d.validate().unwrap_err();
11180 assert!(
11181 matches!(
11182 err,
11183 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11184 ),
11185 "got {err:?}",
11186 );
11187 }
11188
11189 #[test]
11190 fn fonte_caminho_backslash_fires_before_shell_brace_expansion() {
11191 // Cascade pin on the upstream backslash arm: a value
11192 // carrying both `\` and `{` (`"..\caixa-teia\{a,b}"` — the
11193 // canonical "I pasted a Windows-shell `cd ..\path\{a,b}`
11194 // chain") routes through `FonteCaminhoBackslash` not
11195 // `FonteCaminhoShellBraceExpansion`. The cross-host-OS-
11196 // separator divergence is the load-bearing axis on every
11197 // probe-as-both value.
11198 let d = dep_with_fonte(DepSource::Path {
11199 caminho: "..\\caixa-teia\\{a,b}".into(),
11200 });
11201 let err = d.validate().unwrap_err();
11202 assert!(
11203 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11204 "got {err:?}",
11205 );
11206 }
11207
11208 #[test]
11209 fn fonte_caminho_control_char_fires_before_shell_brace_expansion() {
11210 // Cascade pin on the embedded-control-byte arm: a value
11211 // carrying both a control byte and `{` (`"../foo\n{a,b}"` —
11212 // the canonical paste-from-multiline-doc footgun where a
11213 // newline landed mid-caminho between two paste fragments)
11214 // routes through `FonteCaminhoControlChar` not
11215 // `FonteCaminhoShellBraceExpansion`. The POSIX-syscall-
11216 // rejected-byte / NUL-`CString::new`-fail diagnostic is the
11217 // load-bearing axis on every value that probes positive for
11218 // both — mirrors the cascade discipline on every prior arm.
11219 let d = dep_with_fonte(DepSource::Path {
11220 caminho: "../foo\n{a,b}".into(),
11221 });
11222 let err = d.validate().unwrap_err();
11223 assert!(
11224 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11225 "got {err:?}",
11226 );
11227 }
11228
11229 #[test]
11230 fn fonte_caminho_absolute_fires_before_shell_brace_expansion() {
11231 // Cascade pin on the load-bearing leading-byte arm: a
11232 // leading `/` value with embedded `{` (`"/etc/{a,b}"`)
11233 // routes through `FonteCaminhoAbsolute` not
11234 // `FonteCaminhoShellBraceExpansion` — the host-layout-leak
11235 // diagnostic is the load-bearing axis, the brace-expansion
11236 // byte is the secondary observation. Same precedence logic
11237 // as every prior leading-byte arm.
11238 let d = dep_with_fonte(DepSource::Path {
11239 caminho: "/etc/{a,b}".into(),
11240 });
11241 let err = d.validate().unwrap_err();
11242 assert!(
11243 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11244 "got {err:?}",
11245 );
11246 }
11247
11248 #[test]
11249 fn fonte_caminho_var_expansion_fires_before_shell_brace_expansion() {
11250 // Cascade pin on the upstream leading-`$` var-expansion
11251 // arm: a value carrying both a leading `$` and a `{`
11252 // (`"${ORG}/caixa-teia"` — the canonical "I pasted a
11253 // `${ORG}` shell-variable + curly-brace expansion at the
11254 // head of a sibling-workspace path" footgun) routes through
11255 // `FonteCaminhoVarExpansion` not
11256 // `FonteCaminhoShellBraceExpansion`. The leading-byte
11257 // shell-variable-expansion is the more self-locating
11258 // diagnostic on values that probe as both — same
11259 // load-bearing-leading-byte cascade discipline every prior
11260 // `:caminho` arm establishes.
11261 let d = dep_with_fonte(DepSource::Path {
11262 caminho: "${ORG}/caixa-teia".into(),
11263 });
11264 let err = d.validate().unwrap_err();
11265 assert!(
11266 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11267 "got {err:?}",
11268 );
11269 }
11270
11271 #[test]
11272 fn fonte_caminho_shell_brace_expansion_fires_before_trailing_slash() {
11273 // Cascade pin on the immediate-successor arm: a value
11274 // carrying both `{` and a trailing `/`
11275 // (`"../{caixa-teia,caixa-helm}/"` — the canonical "I
11276 // tab-completed a path that already had a brace-expansion
11277 // expansion tail" footgun) routes through
11278 // `FonteCaminhoShellBraceExpansion` not
11279 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11280 // is the more semantic-locating axis (an author who removes
11281 // the `{` typically also drops the trailing separator since
11282 // both are paste-from-shell artifacts).
11283 let d = dep_with_fonte(DepSource::Path {
11284 caminho: "../{caixa-teia,caixa-helm}/".into(),
11285 });
11286 let err = d.validate().unwrap_err();
11287 assert!(
11288 matches!(
11289 err,
11290 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11291 ),
11292 "got {err:?}",
11293 );
11294 }
11295
11296 #[test]
11297 fn fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11298 // Diagnostic-shape pin (peer with
11299 // `fonte_caminho_shell_subshell_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
11300 // on the closest two-byte peer arm): the error's Display
11301 // surfaces the offending `:nome`, the offending `:caminho`
11302 // verbatim, the offending byte's hex / character form, and
11303 // names the shell-brace-expansion / URI-Template footgun
11304 // explicitly so a `feira lint` run can render the diagnostic
11305 // without re-parsing.
11306 let d = dep_with_fonte(DepSource::Path {
11307 caminho: "../{caixa-teia,caixa-helm}/build".into(),
11308 });
11309 let rendered = d.validate().unwrap_err().to_string();
11310 assert!(
11311 rendered.contains("caixa-teia"),
11312 "diagnostic must name the offending dep: {rendered}",
11313 );
11314 assert!(
11315 rendered.contains("../{caixa-teia,caixa-helm}/build"),
11316 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11317 );
11318 assert!(
11319 rendered.contains("0x7b"),
11320 "diagnostic must surface the offending byte hex: {rendered:?}",
11321 );
11322 assert!(
11323 rendered.contains("brace-expansion"),
11324 "diagnostic must name the shell-brace-expansion footgun: {rendered:?}",
11325 );
11326 assert!(
11327 rendered.contains("URI Template"),
11328 "diagnostic must reference the RFC-6570 URI-Template-placeholder vocabulary: \
11329 {rendered:?}",
11330 );
11331 }
11332
11333 #[test]
11334 fn validate_rejects_path_fonte_with_caminho_carrying_bracket_glob_character_class() {
11335 // The canonical paste-from-shell-history bracket-glob /
11336 // character-class footgun: an author copies a
11337 // `cd ../caixa-[a-z]/build` shell-history one-liner whose
11338 // `[a-z]` POSIX glob character-class matches every lowercase-
11339 // ASCII-suffix sibling caixa directory and silently passed
11340 // every prior arm (`Path::is_absolute` false on `..`, no
11341 // control bytes, no `\`, no `<` / `>`, no `|`, no `;`, no
11342 // `&`, no backtick, no `*` / `?`, no `(` / `)`, no `{` /
11343 // `}`, doesn't end in `/`; the leading-`$` f4efe9c
11344 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11345 // value starts with `..` not `$`). The lacre embedded the
11346 // value verbatim, the resolver folded it through
11347 // `Path::join` looking for a literal `./../caixa-[a-z]/
11348 // build` subdirectory, and the failure surfaced at resolve
11349 // time with a non-self-locating `No such file or directory`
11350 // error. The new arm moves the rejection to validate time
11351 // and names the offending dep + caminho + byte verbatim.
11352 // The arm fires on the first `[` encountered.
11353 let d = dep_with_fonte(DepSource::Path {
11354 caminho: "../caixa-[a-z]/build".into(),
11355 });
11356 let err = d.validate().unwrap_err();
11357 let DepError::FonteCaminhoShellBracketExpansion {
11358 nome,
11359 caminho,
11360 byte,
11361 } = err
11362 else {
11363 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11364 };
11365 assert_eq!(nome, "caixa-teia");
11366 assert_eq!(caminho, "../caixa-[a-z]/build");
11367 assert_eq!(byte, b'[');
11368 }
11369
11370 #[test]
11371 fn validate_rejects_path_fonte_with_caminho_carrying_close_bracket() {
11372 // The symmetric close-bracket paste shape (`"../caixa-teia]"`
11373 // — the degenerate "I selected an unbalanced closing bracket
11374 // out of a glob character-class block" idiom that probes for
11375 // the cascade's last-byte handling on a value carrying only
11376 // the closing byte). Pinned separately from the open-bracket
11377 // shape so the gate's contract is "any `[` or `]` anywhere",
11378 // not single-byte coverage. Mirrors the peer
11379 // `validate_rejects_path_fonte_with_caminho_carrying_close_brace`
11380 // shape on the immediate-predecessor
11381 // `FonteCaminhoShellBraceExpansion` arm.
11382 let d = dep_with_fonte(DepSource::Path {
11383 caminho: "../caixa-teia]".into(),
11384 });
11385 let err = d.validate().unwrap_err();
11386 let DepError::FonteCaminhoShellBracketExpansion { byte, .. } = err else {
11387 panic!("expected FonteCaminhoShellBracketExpansion, got {err:?}");
11388 };
11389 assert_eq!(byte, b']');
11390 }
11391
11392 #[test]
11393 fn validate_rejects_path_fonte_with_caminho_carrying_leading_open_bracket() {
11394 // Leading-position `[` shape (`"[caixa-teia]/build"` — the
11395 // canonical "I selected a `[caixa-teia]` TOML-table-header /
11396 // glob-character-class prefix out of an aligned config /
11397 // shell-history one-liner" idiom). Pinned separately from
11398 // the embedded-byte shape so the gate covers every position,
11399 // not only mid-path.
11400 let d = dep_with_fonte(DepSource::Path {
11401 caminho: "[caixa-teia]/build".into(),
11402 });
11403 let err = d.validate().unwrap_err();
11404 assert!(
11405 matches!(
11406 err,
11407 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11408 ),
11409 "got {err:?}",
11410 );
11411 }
11412
11413 #[test]
11414 fn validate_rejects_path_fonte_with_caminho_carrying_toml_inline_array() {
11415 // The canonical TOML inline-array / YAML flow-sequence
11416 // paste shape (`"../[\"a\", \"b\"]/caixa-teia"` — the
11417 // canonical "I copied a `features = [\"a\", \"b\"]` TOML
11418 // inline-array out of a sibling-Cargo manifest" cross-idiom
11419 // leak; the symmetric YAML flow-sequence form `paths: [/a,
11420 // /b]` paste-from-values.yaml shape carries the same
11421 // bracket pair). The arm fires on the first `[` encountered;
11422 // pinned so the gate's coverage extends from the bare-
11423 // bracket glob-character-class shape to the TOML / YAML /
11424 // JSON array-literal shape.
11425 let d = dep_with_fonte(DepSource::Path {
11426 caminho: "../[\"a\", \"b\"]/caixa-teia".into(),
11427 });
11428 let err = d.validate().unwrap_err();
11429 assert!(
11430 matches!(
11431 err,
11432 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11433 ),
11434 "got {err:?}",
11435 );
11436 }
11437
11438 #[test]
11439 fn validate_rejects_path_fonte_with_caminho_carrying_shell_test_builtin() {
11440 // The canonical POSIX `test` / `[` builtin command paste
11441 // shape (`"../[ -d caixa-teia ]"` — the `[ <expr> ]` shell-
11442 // script conditional every paste-from-shell-script idiom
11443 // carries; bash's `[[ <expr> ]]` extended-test grammar
11444 // would surface the same byte pair). The arm fires on the
11445 // first `[` encountered; pinned so the gate's coverage
11446 // extends from the embedded-glob-character-class shape to
11447 // the leading-`test`-builtin / extended-test form.
11448 let d = dep_with_fonte(DepSource::Path {
11449 caminho: "../[ -d caixa-teia ]".into(),
11450 });
11451 let err = d.validate().unwrap_err();
11452 assert!(
11453 matches!(
11454 err,
11455 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11456 ),
11457 "got {err:?}",
11458 );
11459 }
11460
11461 #[test]
11462 fn validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion() {
11463 // The positive-control pin: the gate targets only `[` /
11464 // `]`, never adjacent printable ASCII or POSIX-valid bytes.
11465 // The canonical relative POSIX path (`"../caixa-teia"`) and
11466 // a nested deeply-pathed variant with adjacent printable
11467 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11468 // to validate cleanly so the gate doesn't widen to a "no
11469 // printable punctuation anywhere" sweep that would defeat
11470 // the entire path-fonte author surface. Peer with
11471 // `validate_accepts_path_fonte_with_caminho_carrying_no_brace_expansion`
11472 // on the immediate-predecessor arm.
11473 let d = dep_with_fonte(DepSource::Path {
11474 caminho: "../caixa-teia/sub-dir.v2".into(),
11475 });
11476 d.validate().unwrap();
11477 }
11478
11479 #[test]
11480 fn fonte_caminho_shell_brace_expansion_fires_before_shell_bracket_expansion() {
11481 // Cascade pin on the immediate-predecessor arm: a value
11482 // carrying both `{` and `[` (`"../{a,b}[ch]"` — the
11483 // canonical "I pasted a brace-expansion fan followed by a
11484 // glob-character-class tail" footgun) routes through
11485 // `FonteCaminhoShellBraceExpansion` not
11486 // `FonteCaminhoShellBracketExpansion`. The brace-expansion
11487 // fan is the load-bearing root-cause edit on every
11488 // probe-as-both value because the bracket-class tail
11489 // typically rides on a prior brace-expansion expansion;
11490 // same cascade discipline every prior `:caminho` arm
11491 // establishes.
11492 let d = dep_with_fonte(DepSource::Path {
11493 caminho: "../{a,b}[ch]".into(),
11494 });
11495 let err = d.validate().unwrap_err();
11496 assert!(
11497 matches!(
11498 err,
11499 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11500 ),
11501 "got {err:?}",
11502 );
11503 }
11504
11505 #[test]
11506 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_bracket_expansion() {
11507 // Cascade pin on the upstream shell-subshell-grouping arm:
11508 // a value carrying both `(` and `[` (`"../(cd foo)/[ch]"` —
11509 // the canonical "I pasted a subshell-grouping followed by
11510 // a glob-character-class tail" footgun) routes through
11511 // `FonteCaminhoShellSubshellGrouping` not
11512 // `FonteCaminhoShellBracketExpansion`. The modern Bourne
11513 // `$(<cmd>)` command-substitution boundary is the load-
11514 // bearing axis on every probe-as-both value.
11515 let d = dep_with_fonte(DepSource::Path {
11516 caminho: "../(cd foo)/[ch]".into(),
11517 });
11518 let err = d.validate().unwrap_err();
11519 assert!(
11520 matches!(
11521 err,
11522 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11523 ),
11524 "got {err:?}",
11525 );
11526 }
11527
11528 #[test]
11529 fn fonte_caminho_shell_glob_fires_before_shell_bracket_expansion() {
11530 // Cascade pin on the upstream shell-glob arm: a value
11531 // carrying both `*` and `[` (`"../caixa-teia/*[ch]"` — the
11532 // canonical "I pasted a `*.[ch]` C-source-file glob whose
11533 // unbounded `*` precedes the bracket character-class"
11534 // footgun) routes through `FonteCaminhoShellGlob` not
11535 // `FonteCaminhoShellBracketExpansion`. The unbounded
11536 // pathname-expansion sentinel is the load-bearing root-
11537 // cause edit on every probe-as-both value — the unbounded
11538 // `*` carries the more aggressive expansion vector than
11539 // the bounded `[ch]` class, so the prior arm wins.
11540 let d = dep_with_fonte(DepSource::Path {
11541 caminho: "../caixa-teia/*[ch]".into(),
11542 });
11543 let err = d.validate().unwrap_err();
11544 assert!(
11545 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
11546 "got {err:?}",
11547 );
11548 }
11549
11550 #[test]
11551 fn fonte_caminho_shell_command_substitution_fires_before_shell_bracket_expansion() {
11552 // Cascade pin on the upstream shell-command-substitution
11553 // arm: a value carrying both a backtick and `[`
11554 // (``"../`whoami`/[ch]"`` — the canonical "I pasted a
11555 // legacy-backtick command-substitution followed by a
11556 // glob-character-class tail" footgun) routes through
11557 // `FonteCaminhoShellCommandSubstitution` not
11558 // `FonteCaminhoShellBracketExpansion`. The CWE-78 shell-
11559 // command-injection vector is the load-bearing root-cause
11560 // edit on every probe-as-both value.
11561 let d = dep_with_fonte(DepSource::Path {
11562 caminho: "../`whoami`/[ch]".into(),
11563 });
11564 let err = d.validate().unwrap_err();
11565 assert!(
11566 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
11567 "got {err:?}",
11568 );
11569 }
11570
11571 #[test]
11572 fn fonte_caminho_shell_background_fires_before_shell_bracket_expansion() {
11573 // Cascade pin on the upstream shell-background arm: a
11574 // value carrying both `&` and `[` (`"../caixa-teia & [ch]"`
11575 // — the canonical "I pasted a `cmd & [glob]` background-
11576 // launch + bracket-class chain" footgun) routes through
11577 // `FonteCaminhoShellBackground` not
11578 // `FonteCaminhoShellBracketExpansion`. The background-
11579 // launch tail is the load-bearing root-cause edit on
11580 // every probe-as-both value.
11581 let d = dep_with_fonte(DepSource::Path {
11582 caminho: "../caixa-teia & [ch]".into(),
11583 });
11584 let err = d.validate().unwrap_err();
11585 assert!(
11586 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
11587 "got {err:?}",
11588 );
11589 }
11590
11591 #[test]
11592 fn fonte_caminho_shell_semicolon_fires_before_shell_bracket_expansion() {
11593 // Cascade pin on the upstream shell-semicolon arm: a value
11594 // carrying both `;` and `[` (`"../caixa-teia; [ch]"` — the
11595 // canonical sequential-cleanup + bracket-class paste
11596 // idiom) routes through `FonteCaminhoShellSemicolon` not
11597 // `FonteCaminhoShellBracketExpansion`. The sequential-
11598 // command-separator paste is the load-bearing root-cause
11599 // edit on every probe-as-both value.
11600 let d = dep_with_fonte(DepSource::Path {
11601 caminho: "../caixa-teia; [ch]".into(),
11602 });
11603 let err = d.validate().unwrap_err();
11604 assert!(
11605 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
11606 "got {err:?}",
11607 );
11608 }
11609
11610 #[test]
11611 fn fonte_caminho_shell_pipe_fires_before_shell_bracket_expansion() {
11612 // Cascade pin on the upstream shell-pipe arm: a value
11613 // carrying both `|` and `[` (`"../caixa-teia | [tee]"` —
11614 // the canonical pipeline-to-bracket-class paste idiom)
11615 // routes through `FonteCaminhoShellPipe` not
11616 // `FonteCaminhoShellBracketExpansion`. The pipeline-tail
11617 // paste is the load-bearing root-cause edit on every
11618 // probe-as-both value.
11619 let d = dep_with_fonte(DepSource::Path {
11620 caminho: "../caixa-teia | [tee]".into(),
11621 });
11622 let err = d.validate().unwrap_err();
11623 assert!(
11624 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
11625 "got {err:?}",
11626 );
11627 }
11628
11629 #[test]
11630 fn fonte_caminho_shell_redirection_fires_before_shell_bracket_expansion() {
11631 // Cascade pin on the upstream shell-redirection arm: a
11632 // value carrying both `>` and `[` (`"../caixa-teia>log
11633 // [ch]"` — the canonical "I pasted a `cmd > log [glob]`
11634 // redirect-plus-bracket chain" footgun) routes through
11635 // `FonteCaminhoShellRedirection` not
11636 // `FonteCaminhoShellBracketExpansion`. The input/output
11637 // redirection metachar carries the more self-locating
11638 // `byte` payload, so the prior arm wins on every
11639 // probe-as-both value.
11640 let d = dep_with_fonte(DepSource::Path {
11641 caminho: "../caixa-teia>log [ch]".into(),
11642 });
11643 let err = d.validate().unwrap_err();
11644 assert!(
11645 matches!(
11646 err,
11647 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
11648 ),
11649 "got {err:?}",
11650 );
11651 }
11652
11653 #[test]
11654 fn fonte_caminho_backslash_fires_before_shell_bracket_expansion() {
11655 // Cascade pin on the upstream backslash arm: a value
11656 // carrying both `\` and `[` (`"..\caixa-teia\[ch]"` — the
11657 // canonical "I pasted a Windows-shell `cd ..\path\[glob]`
11658 // chain") routes through `FonteCaminhoBackslash` not
11659 // `FonteCaminhoShellBracketExpansion`. The cross-host-OS-
11660 // separator divergence is the load-bearing axis on every
11661 // probe-as-both value.
11662 let d = dep_with_fonte(DepSource::Path {
11663 caminho: "..\\caixa-teia\\[ch]".into(),
11664 });
11665 let err = d.validate().unwrap_err();
11666 assert!(
11667 matches!(err, DepError::FonteCaminhoBackslash { .. }),
11668 "got {err:?}",
11669 );
11670 }
11671
11672 #[test]
11673 fn fonte_caminho_control_char_fires_before_shell_bracket_expansion() {
11674 // Cascade pin on the embedded-control-byte arm: a value
11675 // carrying both a control byte and `[` (`"../foo\n[ch]"` —
11676 // the canonical paste-from-multiline-doc footgun where a
11677 // newline landed mid-caminho between two paste fragments)
11678 // routes through `FonteCaminhoControlChar` not
11679 // `FonteCaminhoShellBracketExpansion`. The POSIX-syscall-
11680 // rejected-byte / NUL-`CString::new`-fail diagnostic is
11681 // the load-bearing axis on every value that probes
11682 // positive for both — mirrors the cascade discipline on
11683 // every prior arm.
11684 let d = dep_with_fonte(DepSource::Path {
11685 caminho: "../foo\n[ch]".into(),
11686 });
11687 let err = d.validate().unwrap_err();
11688 assert!(
11689 matches!(err, DepError::FonteCaminhoControlChar { .. }),
11690 "got {err:?}",
11691 );
11692 }
11693
11694 #[test]
11695 fn fonte_caminho_absolute_fires_before_shell_bracket_expansion() {
11696 // Cascade pin on the load-bearing leading-byte arm: a
11697 // leading `/` value with embedded `[` (`"/etc/[ch]"`)
11698 // routes through `FonteCaminhoAbsolute` not
11699 // `FonteCaminhoShellBracketExpansion` — the host-layout-
11700 // leak diagnostic is the load-bearing axis, the bracket-
11701 // expansion byte is the secondary observation. Same
11702 // precedence logic as every prior leading-byte arm.
11703 let d = dep_with_fonte(DepSource::Path {
11704 caminho: "/etc/[ch]".into(),
11705 });
11706 let err = d.validate().unwrap_err();
11707 assert!(
11708 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
11709 "got {err:?}",
11710 );
11711 }
11712
11713 #[test]
11714 fn fonte_caminho_var_expansion_fires_before_shell_bracket_expansion() {
11715 // Cascade pin on the upstream leading-`$` var-expansion
11716 // arm: a value carrying both a leading `$` and a `[`
11717 // (`"$DIR/[ch]"` — the canonical "I pasted a `$DIR` shell-
11718 // variable + bracket-class at the head of a sibling-
11719 // workspace path" footgun) routes through
11720 // `FonteCaminhoVarExpansion` not
11721 // `FonteCaminhoShellBracketExpansion`. The leading-byte
11722 // shell-variable-expansion is the more self-locating
11723 // diagnostic on values that probe as both — same
11724 // load-bearing-leading-byte cascade discipline every
11725 // prior `:caminho` arm establishes.
11726 let d = dep_with_fonte(DepSource::Path {
11727 caminho: "$DIR/[ch]".into(),
11728 });
11729 let err = d.validate().unwrap_err();
11730 assert!(
11731 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
11732 "got {err:?}",
11733 );
11734 }
11735
11736 #[test]
11737 fn fonte_caminho_shell_bracket_expansion_fires_before_trailing_slash() {
11738 // Cascade pin on the immediate-successor arm: a value
11739 // carrying both `[` and a trailing `/` (`"../[a-z]/"` —
11740 // the canonical "I tab-completed a path that already had
11741 // a bracket-glob-character-class expansion tail" footgun)
11742 // routes through `FonteCaminhoShellBracketExpansion` not
11743 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
11744 // is the more semantic-locating axis (an author who
11745 // removes the `[` typically also drops the trailing
11746 // separator since both are paste-from-shell artifacts).
11747 let d = dep_with_fonte(DepSource::Path {
11748 caminho: "../[a-z]/".into(),
11749 });
11750 let err = d.validate().unwrap_err();
11751 assert!(
11752 matches!(
11753 err,
11754 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11755 ),
11756 "got {err:?}",
11757 );
11758 }
11759
11760 #[test]
11761 fn fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
11762 // Diagnostic-shape pin (peer with
11763 // `fonte_caminho_shell_brace_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
11764 // on the closest two-byte peer arm): the error's Display
11765 // surfaces the offending `:nome`, the offending `:caminho`
11766 // verbatim, the offending byte's hex / character form, and
11767 // names the shell-bracket-expansion / glob-character-class
11768 // footgun explicitly so a `feira lint` run can render the
11769 // diagnostic without re-parsing.
11770 let d = dep_with_fonte(DepSource::Path {
11771 caminho: "../caixa-[a-z]/build".into(),
11772 });
11773 let rendered = d.validate().unwrap_err().to_string();
11774 assert!(
11775 rendered.contains("caixa-teia"),
11776 "diagnostic must name the offending dep: {rendered}",
11777 );
11778 assert!(
11779 rendered.contains("../caixa-[a-z]/build"),
11780 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
11781 );
11782 assert!(
11783 rendered.contains("0x5b"),
11784 "diagnostic must surface the offending byte hex: {rendered:?}",
11785 );
11786 assert!(
11787 rendered.contains("bracket-expansion"),
11788 "diagnostic must name the shell-bracket-expansion footgun: {rendered:?}",
11789 );
11790 assert!(
11791 rendered.contains("glob-character-class"),
11792 "diagnostic must reference the POSIX glob-character-class vocabulary: \
11793 {rendered:?}",
11794 );
11795 }
11796
11797 #[test]
11798 fn validate_rejects_path_fonte_with_caminho_carrying_single_quote_grouping() {
11799 // The canonical paste-from-shell-history strong-quoted
11800 // sibling-workspace-path footgun: an author copies a
11801 // `cd '../caixa-teia'` shell-history one-liner whose strong-
11802 // quoting preserved the path across a whitespace paste
11803 // boundary and silently passed every prior arm
11804 // (`Path::is_absolute` false on `'..`, no control bytes, no
11805 // `\`, no `<` / `>`, no `|`, no `;`, no `&`, no backtick, no
11806 // `*` / `?`, no `(` / `)`, no `{` / `}`, no `[` / `]`,
11807 // doesn't end in `/`; the leading-`$` f4efe9c
11808 // `FonteCaminhoVarExpansion` arm doesn't fire because the
11809 // value starts with `'` not `$`). The lacre embedded the
11810 // value verbatim, the resolver folded it through
11811 // `Path::join` looking for a literal `./'../caixa-teia'`
11812 // subdirectory, and the failure surfaced at resolve time
11813 // with a non-self-locating `No such file or directory`
11814 // error. The new arm moves the rejection to validate time
11815 // and names the offending dep + caminho + byte verbatim.
11816 // The arm fires on the first `'` encountered.
11817 let d = dep_with_fonte(DepSource::Path {
11818 caminho: "'../caixa-teia'".into(),
11819 });
11820 let err = d.validate().unwrap_err();
11821 let DepError::FonteCaminhoShellQuoteGrouping {
11822 nome,
11823 caminho,
11824 byte,
11825 } = err
11826 else {
11827 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11828 };
11829 assert_eq!(nome, "caixa-teia");
11830 assert_eq!(caminho, "'../caixa-teia'");
11831 assert_eq!(byte, b'\'');
11832 }
11833
11834 #[test]
11835 fn validate_rejects_path_fonte_with_caminho_carrying_double_quote_grouping() {
11836 // The symmetric weak-quoted paste shape (`"\"../caixa-teia\""`
11837 // — the canonical paste-from-JSON-config / paste-from-YAML-
11838 // flow-scalar / paste-from-TOML-basic-string / paste-from-
11839 // tatara-lisp-string-literal cross-idiom leak). Pinned
11840 // separately from the single-quote shape so the gate's
11841 // contract is "any `'` or `\"` anywhere", not single-byte
11842 // coverage. Mirrors the peer
11843 // `validate_rejects_path_fonte_with_caminho_carrying_close_bracket`
11844 // shape on the immediate-predecessor
11845 // `FonteCaminhoShellBracketExpansion` arm.
11846 let d = dep_with_fonte(DepSource::Path {
11847 caminho: "\"../caixa-teia\"".into(),
11848 });
11849 let err = d.validate().unwrap_err();
11850 let DepError::FonteCaminhoShellQuoteGrouping { byte, .. } = err else {
11851 panic!("expected FonteCaminhoShellQuoteGrouping, got {err:?}");
11852 };
11853 assert_eq!(byte, b'"');
11854 }
11855
11856 #[test]
11857 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_double_quote() {
11858 // Embedded-position `"` shape (`"../\"caixa-teia\""` — the
11859 // canonical "I pasted a JSON key-value pair fragment into
11860 // the middle of the path" idiom). Pinned separately from
11861 // the leading-byte shape so the gate covers every position,
11862 // not only leading.
11863 let d = dep_with_fonte(DepSource::Path {
11864 caminho: "../\"caixa-teia\"".into(),
11865 });
11866 let err = d.validate().unwrap_err();
11867 assert!(
11868 matches!(
11869 err,
11870 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11871 ),
11872 "got {err:?}",
11873 );
11874 }
11875
11876 #[test]
11877 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_flow_scalar_paste() {
11878 // The canonical YAML double-quoted flow-scalar cross-idiom
11879 // leak shape (`"path: \"../caixa-teia\""` — the "I copied a
11880 // `path: \"...\"` YAML flow-scalar entry out of an aligned
11881 // values.yaml / K8s manifest and dropped it verbatim into
11882 // the `:caminho` slot including the `path: ` key prefix"
11883 // paste-idiom). The arm fires on the first `"` encountered;
11884 // pinned so the gate's coverage extends from the bare-quote
11885 // paste shape to the aligned-YAML-manifest cross-idiom-leak
11886 // shape.
11887 let d = dep_with_fonte(DepSource::Path {
11888 caminho: "path: \"../caixa-teia\"".into(),
11889 });
11890 let err = d.validate().unwrap_err();
11891 assert!(
11892 matches!(
11893 err,
11894 DepError::FonteCaminhoShellQuoteGrouping { byte: b'"', .. },
11895 ),
11896 "got {err:?}",
11897 );
11898 }
11899
11900 #[test]
11901 fn validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping() {
11902 // The positive-control pin: the gate targets only `'` /
11903 // `"`, never adjacent printable ASCII or POSIX-valid bytes.
11904 // The canonical relative POSIX path (`"../caixa-teia"`) and
11905 // a nested deeply-pathed variant with adjacent printable
11906 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
11907 // to validate cleanly so the gate doesn't widen to a "no
11908 // printable punctuation anywhere" sweep that would defeat
11909 // the entire path-fonte author surface. Peer with
11910 // `validate_accepts_path_fonte_with_caminho_carrying_no_bracket_expansion`
11911 // on the immediate-predecessor arm.
11912 let d = dep_with_fonte(DepSource::Path {
11913 caminho: "../caixa-teia/sub-dir.v2".into(),
11914 });
11915 d.validate().unwrap();
11916 }
11917
11918 #[test]
11919 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_quote_grouping() {
11920 // Cascade pin on the immediate-predecessor arm: a value
11921 // carrying both `[` and `'` (`"../[a-z]'x'"` — the canonical
11922 // "I pasted a glob-character-class followed by a strong-
11923 // quoted literal tail" footgun) routes through
11924 // `FonteCaminhoShellBracketExpansion` not
11925 // `FonteCaminhoShellQuoteGrouping`. The glob-character-class
11926 // expansion is the load-bearing root-cause edit on every
11927 // probe-as-both value; same cascade discipline every prior
11928 // `:caminho` arm establishes.
11929 let d = dep_with_fonte(DepSource::Path {
11930 caminho: "../[a-z]'x'".into(),
11931 });
11932 let err = d.validate().unwrap_err();
11933 assert!(
11934 matches!(
11935 err,
11936 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
11937 ),
11938 "got {err:?}",
11939 );
11940 }
11941
11942 #[test]
11943 fn fonte_caminho_shell_brace_expansion_fires_before_shell_quote_grouping() {
11944 // Cascade pin on the upstream shell-brace-expansion arm: a
11945 // value carrying both `{` and `'` (`"../{a,b}'x'"` — the
11946 // canonical "I pasted a brace-expansion fan followed by a
11947 // strong-quoted literal tail" footgun) routes through
11948 // `FonteCaminhoShellBraceExpansion` not
11949 // `FonteCaminhoShellQuoteGrouping`. The brace-expansion fan
11950 // is the load-bearing root-cause edit on every probe-as-
11951 // both value.
11952 let d = dep_with_fonte(DepSource::Path {
11953 caminho: "../{a,b}'x'".into(),
11954 });
11955 let err = d.validate().unwrap_err();
11956 assert!(
11957 matches!(
11958 err,
11959 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
11960 ),
11961 "got {err:?}",
11962 );
11963 }
11964
11965 #[test]
11966 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_quote_grouping() {
11967 // Cascade pin on the upstream shell-subshell-grouping arm:
11968 // a value carrying both `(` and `'` (`"../(cd foo)/'x'"` —
11969 // the canonical "I pasted a subshell-grouping followed by
11970 // a strong-quoted literal tail" footgun) routes through
11971 // `FonteCaminhoShellSubshellGrouping` not
11972 // `FonteCaminhoShellQuoteGrouping`. The modern Bourne
11973 // `$(<cmd>)` command-substitution boundary is the load-
11974 // bearing axis on every probe-as-both value.
11975 let d = dep_with_fonte(DepSource::Path {
11976 caminho: "../(cd foo)/'x'".into(),
11977 });
11978 let err = d.validate().unwrap_err();
11979 assert!(
11980 matches!(
11981 err,
11982 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
11983 ),
11984 "got {err:?}",
11985 );
11986 }
11987
11988 #[test]
11989 fn fonte_caminho_shell_glob_fires_before_shell_quote_grouping() {
11990 // Cascade pin on the upstream shell-glob arm: a value
11991 // carrying both `*` and `'` (`"../caixa-teia/*'x'"` — the
11992 // canonical "I pasted a `*` unbounded pathname-expansion
11993 // followed by a strong-quoted literal tail" footgun) routes
11994 // through `FonteCaminhoShellGlob` not
11995 // `FonteCaminhoShellQuoteGrouping`. The unbounded pathname-
11996 // expansion sentinel is the load-bearing root-cause edit
11997 // on every probe-as-both value.
11998 let d = dep_with_fonte(DepSource::Path {
11999 caminho: "../caixa-teia/*'x'".into(),
12000 });
12001 let err = d.validate().unwrap_err();
12002 assert!(
12003 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12004 "got {err:?}",
12005 );
12006 }
12007
12008 #[test]
12009 fn fonte_caminho_shell_command_substitution_fires_before_shell_quote_grouping() {
12010 // Cascade pin on the upstream shell-command-substitution
12011 // arm: a value carrying both a backtick and `'`
12012 // (``"../`whoami`/'x'"`` — the canonical "I pasted a
12013 // legacy-backtick command-substitution followed by a
12014 // strong-quoted literal tail" footgun) routes through
12015 // `FonteCaminhoShellCommandSubstitution` not
12016 // `FonteCaminhoShellQuoteGrouping`. The CWE-78 shell-
12017 // command-injection vector is the load-bearing root-cause
12018 // edit on every probe-as-both value.
12019 let d = dep_with_fonte(DepSource::Path {
12020 caminho: "../`whoami`/'x'".into(),
12021 });
12022 let err = d.validate().unwrap_err();
12023 assert!(
12024 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12025 "got {err:?}",
12026 );
12027 }
12028
12029 #[test]
12030 fn fonte_caminho_shell_background_fires_before_shell_quote_grouping() {
12031 // Cascade pin on the upstream shell-background arm: a value
12032 // carrying both `&` and `'` (`"../caixa-teia & 'x'"` — the
12033 // canonical "I pasted a `cmd & 'literal'` background-launch
12034 // + quote chain" footgun) routes through
12035 // `FonteCaminhoShellBackground` not
12036 // `FonteCaminhoShellQuoteGrouping`. The background-launch
12037 // tail is the load-bearing root-cause edit on every
12038 // probe-as-both value.
12039 let d = dep_with_fonte(DepSource::Path {
12040 caminho: "../caixa-teia & 'x'".into(),
12041 });
12042 let err = d.validate().unwrap_err();
12043 assert!(
12044 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12045 "got {err:?}",
12046 );
12047 }
12048
12049 #[test]
12050 fn fonte_caminho_shell_semicolon_fires_before_shell_quote_grouping() {
12051 // Cascade pin on the upstream shell-semicolon arm: a value
12052 // carrying both `;` and `'` (`"../caixa-teia; 'x'"` — the
12053 // canonical sequential-cleanup + quote paste idiom) routes
12054 // through `FonteCaminhoShellSemicolon` not
12055 // `FonteCaminhoShellQuoteGrouping`. The sequential-command-
12056 // separator paste is the load-bearing root-cause edit on
12057 // every probe-as-both value.
12058 let d = dep_with_fonte(DepSource::Path {
12059 caminho: "../caixa-teia; 'x'".into(),
12060 });
12061 let err = d.validate().unwrap_err();
12062 assert!(
12063 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12064 "got {err:?}",
12065 );
12066 }
12067
12068 #[test]
12069 fn fonte_caminho_shell_pipe_fires_before_shell_quote_grouping() {
12070 // Cascade pin on the upstream shell-pipe arm: a value
12071 // carrying both `|` and `'` (`"../caixa-teia | 'x'"` — the
12072 // canonical pipeline-to-quoted-literal paste idiom) routes
12073 // through `FonteCaminhoShellPipe` not
12074 // `FonteCaminhoShellQuoteGrouping`. The pipeline-tail paste
12075 // is the load-bearing root-cause edit on every probe-as-
12076 // both value.
12077 let d = dep_with_fonte(DepSource::Path {
12078 caminho: "../caixa-teia | 'x'".into(),
12079 });
12080 let err = d.validate().unwrap_err();
12081 assert!(
12082 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12083 "got {err:?}",
12084 );
12085 }
12086
12087 #[test]
12088 fn fonte_caminho_shell_redirection_fires_before_shell_quote_grouping() {
12089 // Cascade pin on the upstream shell-redirection arm: a
12090 // value carrying both `>` and `'` (`"../caixa-teia>log 'x'"`
12091 // — the canonical "I pasted a `cmd > log 'literal'`
12092 // redirect-plus-quote chain" footgun) routes through
12093 // `FonteCaminhoShellRedirection` not
12094 // `FonteCaminhoShellQuoteGrouping`. The input/output
12095 // redirection metachar carries the more self-locating
12096 // `byte` payload, so the prior arm wins on every probe-as-
12097 // both value.
12098 let d = dep_with_fonte(DepSource::Path {
12099 caminho: "../caixa-teia>log 'x'".into(),
12100 });
12101 let err = d.validate().unwrap_err();
12102 assert!(
12103 matches!(
12104 err,
12105 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12106 ),
12107 "got {err:?}",
12108 );
12109 }
12110
12111 #[test]
12112 fn fonte_caminho_backslash_fires_before_shell_quote_grouping() {
12113 // Cascade pin on the upstream backslash arm: a value
12114 // carrying both `\` and `'` (`"..\caixa-teia\'x'"` — the
12115 // canonical "I pasted a Windows-shell `cd ..\path\'literal'`
12116 // chain" footgun) routes through `FonteCaminhoBackslash`
12117 // not `FonteCaminhoShellQuoteGrouping`. The cross-host-OS-
12118 // separator divergence is the load-bearing axis on every
12119 // probe-as-both value.
12120 let d = dep_with_fonte(DepSource::Path {
12121 caminho: "..\\caixa-teia\\'x'".into(),
12122 });
12123 let err = d.validate().unwrap_err();
12124 assert!(
12125 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12126 "got {err:?}",
12127 );
12128 }
12129
12130 #[test]
12131 fn fonte_caminho_control_char_fires_before_shell_quote_grouping() {
12132 // Cascade pin on the embedded-control-byte arm: a value
12133 // carrying both a control byte and `'` (`"../foo\n'x'"` —
12134 // the canonical paste-from-multiline-doc footgun where a
12135 // newline landed mid-caminho between two paste fragments)
12136 // routes through `FonteCaminhoControlChar` not
12137 // `FonteCaminhoShellQuoteGrouping`. The POSIX-syscall-
12138 // rejected-byte / NUL-`CString::new`-fail diagnostic is
12139 // the load-bearing axis on every value that probes
12140 // positive for both — mirrors the cascade discipline on
12141 // every prior arm.
12142 let d = dep_with_fonte(DepSource::Path {
12143 caminho: "../foo\n'x'".into(),
12144 });
12145 let err = d.validate().unwrap_err();
12146 assert!(
12147 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12148 "got {err:?}",
12149 );
12150 }
12151
12152 #[test]
12153 fn fonte_caminho_absolute_fires_before_shell_quote_grouping() {
12154 // Cascade pin on the load-bearing leading-byte arm: a
12155 // leading `/` value with embedded `'` (`"/etc/'x'"`) routes
12156 // through `FonteCaminhoAbsolute` not
12157 // `FonteCaminhoShellQuoteGrouping` — the host-layout-leak
12158 // diagnostic is the load-bearing axis, the quote byte is
12159 // the secondary observation. Same precedence logic as every
12160 // prior leading-byte arm.
12161 let d = dep_with_fonte(DepSource::Path {
12162 caminho: "/etc/'x'".into(),
12163 });
12164 let err = d.validate().unwrap_err();
12165 assert!(
12166 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12167 "got {err:?}",
12168 );
12169 }
12170
12171 #[test]
12172 fn fonte_caminho_var_expansion_fires_before_shell_quote_grouping() {
12173 // Cascade pin on the upstream leading-`$` var-expansion
12174 // arm: a value carrying both a leading `$` and a `'`
12175 // (`"$DIR/'x'"` — the canonical "I pasted a `$DIR` shell-
12176 // variable + quoted literal at the head of a sibling-
12177 // workspace path" footgun) routes through
12178 // `FonteCaminhoVarExpansion` not
12179 // `FonteCaminhoShellQuoteGrouping`. The leading-byte
12180 // shell-variable-expansion is the more self-locating
12181 // diagnostic on values that probe as both — same
12182 // load-bearing-leading-byte cascade discipline every
12183 // prior `:caminho` arm establishes.
12184 let d = dep_with_fonte(DepSource::Path {
12185 caminho: "$DIR/'x'".into(),
12186 });
12187 let err = d.validate().unwrap_err();
12188 assert!(
12189 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12190 "got {err:?}",
12191 );
12192 }
12193
12194 #[test]
12195 fn fonte_caminho_shell_quote_grouping_fires_before_trailing_slash() {
12196 // Cascade pin on the immediate-successor arm: a value
12197 // carrying both `'` and a trailing `/` (`"../'caixa-teia'/"`
12198 // — the canonical "I tab-completed a path whose strong-
12199 // quoted body already carried the quoting from a shell-
12200 // history paste" footgun) routes through
12201 // `FonteCaminhoShellQuoteGrouping` not
12202 // `FonteCaminhoTrailingSlash`. The embedded shell-metachar
12203 // is the more semantic-locating axis (an author who removes
12204 // the `'` typically also drops the trailing separator since
12205 // both are paste-from-shell artifacts).
12206 let d = dep_with_fonte(DepSource::Path {
12207 caminho: "../'caixa-teia'/".into(),
12208 });
12209 let err = d.validate().unwrap_err();
12210 assert!(
12211 matches!(
12212 err,
12213 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12214 ),
12215 "got {err:?}",
12216 );
12217 }
12218
12219 #[test]
12220 fn fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte() {
12221 // Diagnostic-shape pin (peer with
12222 // `fonte_caminho_shell_bracket_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
12223 // on the closest two-byte peer arm): the error's Display
12224 // surfaces the offending `:nome`, the offending `:caminho`
12225 // verbatim, the offending byte's hex / character form, and
12226 // names the shell-quote-grouping / cross-config-DSL-string-
12227 // literal-delimiter footgun explicitly so a `feira lint`
12228 // run can render the diagnostic without re-parsing.
12229 let d = dep_with_fonte(DepSource::Path {
12230 caminho: "'../caixa-teia'".into(),
12231 });
12232 let rendered = d.validate().unwrap_err().to_string();
12233 assert!(
12234 rendered.contains("caixa-teia"),
12235 "diagnostic must name the offending dep: {rendered}",
12236 );
12237 assert!(
12238 rendered.contains("'../caixa-teia'"),
12239 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12240 );
12241 assert!(
12242 rendered.contains("0x27"),
12243 "diagnostic must surface the offending byte hex: {rendered:?}",
12244 );
12245 assert!(
12246 rendered.contains("quote-grouping"),
12247 "diagnostic must name the shell-quote-grouping footgun: {rendered:?}",
12248 );
12249 assert!(
12250 rendered.contains("string-literal"),
12251 "diagnostic must reference the cross-config-DSL string-literal-delimiter \
12252 vocabulary: {rendered:?}",
12253 );
12254 }
12255
12256 #[test]
12257 fn validate_rejects_path_fonte_with_caminho_carrying_shell_comment_lead() {
12258 // The canonical paste-from-shell-history-with-trailing-
12259 // annotation footgun: an author pastes a `cd ../caixa-teia
12260 // # legacy sibling` shell-history one-liner whose unquoted `#`
12261 // comment-lead separates the path from an inline annotation.
12262 // The POSIX shell trims the annotation to `../caixa-teia`
12263 // (POSIX.1-2017 §2.3 Token Recognition step 6), but
12264 // `Path::is_absolute` returns false on `..`, `#` is neither
12265 // a leading-byte sentinel nor a control byte nor `\` nor
12266 // `<` / `>` nor `|` nor `;` nor `&` nor backtick nor `*` /
12267 // `?` nor `(` / `)` nor `{` / `}` nor `[` / `]` nor `'` /
12268 // `"`, and the value's last byte isn't `/` — so the value
12269 // silently passed every prior arm. The resolver folded the
12270 // value through `Path::join` looking for a literal
12271 // `./../caixa-teia # legacy sibling` subdirectory and the
12272 // failure surfaced at resolve time with a non-self-locating
12273 // `No such file or directory` error. The new arm moves the
12274 // rejection to validate time and names the offending dep +
12275 // caminho + byte verbatim.
12276 let d = dep_with_fonte(DepSource::Path {
12277 caminho: "../caixa-teia # legacy sibling".into(),
12278 });
12279 let err = d.validate().unwrap_err();
12280 let DepError::FonteCaminhoShellComment {
12281 nome,
12282 caminho,
12283 byte,
12284 } = err
12285 else {
12286 panic!("expected FonteCaminhoShellComment, got {err:?}");
12287 };
12288 assert_eq!(nome, "caixa-teia");
12289 assert_eq!(caminho, "../caixa-teia # legacy sibling");
12290 assert_eq!(byte, b'#');
12291 }
12292
12293 #[test]
12294 fn validate_rejects_path_fonte_with_caminho_carrying_yaml_comment_paste() {
12295 // The symmetric YAML flow-scalar / values.yaml / K8s-manifest
12296 // cross-idiom-leak shape (`"../caixa-teia # pin"` — the
12297 // canonical "I copied a `path: ../caixa-teia # pin` YAML
12298 // scalar-plus-comment entry out of an aligned values.yaml and
12299 // dropped it verbatim into the `:caminho` slot" paste-idiom).
12300 // Pinned separately from the shell-history shape so the
12301 // gate's coverage extends from the single-space `#` shape to
12302 // the YAML-canonical double-space ` #` shape. YAML 1.2 §6.6
12303 // requires the `#` to be preceded by whitespace to lex as a
12304 // comment (bare `foo#bar` is a single scalar); the double-
12305 // space paste from an aligned manifest is the canonical
12306 // shape.
12307 let d = dep_with_fonte(DepSource::Path {
12308 caminho: "../caixa-teia # pin".into(),
12309 });
12310 let err = d.validate().unwrap_err();
12311 assert!(
12312 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12313 "got {err:?}",
12314 );
12315 }
12316
12317 #[test]
12318 fn validate_rejects_path_fonte_with_caminho_carrying_url_fragment_anchor() {
12319 // The URL-fragment-identifier paste shape
12320 // (`"../caixa-teia#readme"` — the canonical
12321 // paste-from-browser-address-bar permalink shape where the
12322 // browser preserved the `#anchor` tail on the copy). Pinned
12323 // separately from the whitespace-separated shell / YAML
12324 // comment shapes so the gate covers the unpadded RFC 3986
12325 // §3.5 fragment-delimiter position too, not only positions
12326 // preceded by unquoted whitespace. Peer with the immediate-
12327 // sibling `is_git_repo_url` arm on the `:fonte :repo` axis
12328 // (a68f818) which closes the same byte under the same URL-
12329 // fragment-identifier banner.
12330 let d = dep_with_fonte(DepSource::Path {
12331 caminho: "../caixa-teia#readme".into(),
12332 });
12333 let err = d.validate().unwrap_err();
12334 assert!(
12335 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12336 "got {err:?}",
12337 );
12338 }
12339
12340 #[test]
12341 fn validate_rejects_path_fonte_with_caminho_carrying_leading_shell_comment() {
12342 // Leading-position `#` shape (`"#../caixa-teia"` — the
12343 // "I copied a shell-comment-out entry from a commented-out
12344 // dep row" footgun). Pinned separately from the embedded
12345 // shapes so the gate covers every position, not only
12346 // whitespace-preceded / mid-value.
12347 let d = dep_with_fonte(DepSource::Path {
12348 caminho: "#../caixa-teia".into(),
12349 });
12350 let err = d.validate().unwrap_err();
12351 assert!(
12352 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12353 "got {err:?}",
12354 );
12355 }
12356
12357 #[test]
12358 fn validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment() {
12359 // The positive-control pin: the gate targets only `#`,
12360 // never adjacent printable ASCII or POSIX-valid bytes. The
12361 // canonical relative POSIX path (`"../caixa-teia"`) and a
12362 // nested deeply-pathed variant with adjacent printable
12363 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12364 // to validate cleanly so the gate doesn't widen to a "no
12365 // printable punctuation anywhere" sweep that would defeat
12366 // the entire path-fonte author surface. Peer with
12367 // `validate_accepts_path_fonte_with_caminho_carrying_no_quote_grouping`
12368 // on the immediate-predecessor arm.
12369 let d = dep_with_fonte(DepSource::Path {
12370 caminho: "../caixa-teia/sub-dir.v2".into(),
12371 });
12372 d.validate().unwrap();
12373 }
12374
12375 #[test]
12376 fn fonte_caminho_shell_quote_grouping_fires_before_shell_comment() {
12377 // Cascade pin on the immediate-predecessor arm: a value
12378 // carrying both `'` and `#` (`"../'x'#pin"` — the canonical
12379 // "I pasted a strong-quoted literal followed by a URL-
12380 // fragment permalink tail" footgun) routes through
12381 // `FonteCaminhoShellQuoteGrouping` not
12382 // `FonteCaminhoShellComment`. The shell-string-literal-
12383 // delimiter is the load-bearing root-cause edit on every
12384 // probe-as-both value; same cascade discipline every prior
12385 // `:caminho` arm establishes.
12386 let d = dep_with_fonte(DepSource::Path {
12387 caminho: "../'x'#pin".into(),
12388 });
12389 let err = d.validate().unwrap_err();
12390 assert!(
12391 matches!(
12392 err,
12393 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12394 ),
12395 "got {err:?}",
12396 );
12397 }
12398
12399 #[test]
12400 fn fonte_caminho_shell_bracket_expansion_fires_before_shell_comment() {
12401 // Cascade pin on the upstream shell-bracket-expansion arm:
12402 // a value carrying both `[` and `#` (`"../[a-z]#pin"` — the
12403 // canonical "I pasted a glob-character-class followed by a
12404 // URL-fragment tail" footgun) routes through
12405 // `FonteCaminhoShellBracketExpansion` not
12406 // `FonteCaminhoShellComment`. The glob-character-class
12407 // expansion is the load-bearing root-cause edit on every
12408 // probe-as-both value.
12409 let d = dep_with_fonte(DepSource::Path {
12410 caminho: "../[a-z]#pin".into(),
12411 });
12412 let err = d.validate().unwrap_err();
12413 assert!(
12414 matches!(
12415 err,
12416 DepError::FonteCaminhoShellBracketExpansion { byte: b'[', .. },
12417 ),
12418 "got {err:?}",
12419 );
12420 }
12421
12422 #[test]
12423 fn fonte_caminho_shell_brace_expansion_fires_before_shell_comment() {
12424 // Cascade pin on the upstream shell-brace-expansion arm: a
12425 // value carrying both `{` and `#` (`"../{a,b}#pin"` — the
12426 // canonical "I pasted a brace-expansion fan followed by a
12427 // URL-fragment tail" footgun) routes through
12428 // `FonteCaminhoShellBraceExpansion` not
12429 // `FonteCaminhoShellComment`. The brace-expansion fan is the
12430 // load-bearing root-cause edit on every probe-as-both value.
12431 let d = dep_with_fonte(DepSource::Path {
12432 caminho: "../{a,b}#pin".into(),
12433 });
12434 let err = d.validate().unwrap_err();
12435 assert!(
12436 matches!(
12437 err,
12438 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. },
12439 ),
12440 "got {err:?}",
12441 );
12442 }
12443
12444 #[test]
12445 fn fonte_caminho_shell_subshell_grouping_fires_before_shell_comment() {
12446 // Cascade pin on the upstream shell-subshell-grouping arm:
12447 // a value carrying both `(` and `#` (`"../(cd foo)#pin"` —
12448 // the canonical "I pasted a subshell-grouping followed by a
12449 // URL-fragment tail" footgun) routes through
12450 // `FonteCaminhoShellSubshellGrouping` not
12451 // `FonteCaminhoShellComment`. The modern Bourne `$(<cmd>)`
12452 // command-substitution boundary is the load-bearing axis on
12453 // every probe-as-both value.
12454 let d = dep_with_fonte(DepSource::Path {
12455 caminho: "../(cd foo)#pin".into(),
12456 });
12457 let err = d.validate().unwrap_err();
12458 assert!(
12459 matches!(
12460 err,
12461 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. },
12462 ),
12463 "got {err:?}",
12464 );
12465 }
12466
12467 #[test]
12468 fn fonte_caminho_shell_glob_fires_before_shell_comment() {
12469 // Cascade pin on the upstream shell-glob arm: a value
12470 // carrying both `*` and `#` (`"../caixa-teia/*#pin"` — the
12471 // canonical "I pasted a `*` unbounded pathname-expansion
12472 // followed by a URL-fragment tail" footgun) routes through
12473 // `FonteCaminhoShellGlob` not `FonteCaminhoShellComment`.
12474 // The unbounded pathname-expansion sentinel is the load-
12475 // bearing root-cause edit on every probe-as-both value.
12476 let d = dep_with_fonte(DepSource::Path {
12477 caminho: "../caixa-teia/*#pin".into(),
12478 });
12479 let err = d.validate().unwrap_err();
12480 assert!(
12481 matches!(err, DepError::FonteCaminhoShellGlob { byte: b'*', .. }),
12482 "got {err:?}",
12483 );
12484 }
12485
12486 #[test]
12487 fn fonte_caminho_shell_command_substitution_fires_before_shell_comment() {
12488 // Cascade pin on the upstream shell-command-substitution
12489 // arm: a value carrying both a backtick and `#`
12490 // (``"../`whoami`#pin"`` — the canonical "I pasted a
12491 // legacy-backtick command-substitution followed by a URL-
12492 // fragment tail" footgun) routes through
12493 // `FonteCaminhoShellCommandSubstitution` not
12494 // `FonteCaminhoShellComment`. The CWE-78 shell-command-
12495 // injection vector is the load-bearing root-cause edit on
12496 // every probe-as-both value.
12497 let d = dep_with_fonte(DepSource::Path {
12498 caminho: "../`whoami`#pin".into(),
12499 });
12500 let err = d.validate().unwrap_err();
12501 assert!(
12502 matches!(err, DepError::FonteCaminhoShellCommandSubstitution { .. }),
12503 "got {err:?}",
12504 );
12505 }
12506
12507 #[test]
12508 fn fonte_caminho_shell_background_fires_before_shell_comment() {
12509 // Cascade pin on the upstream shell-background arm: a value
12510 // carrying both `&` and `#` (`"../caixa-teia&pin#tail"` —
12511 // the canonical "I pasted a `cmd &` background-launch
12512 // followed by a URL-fragment tail" footgun) routes through
12513 // `FonteCaminhoShellBackground` not
12514 // `FonteCaminhoShellComment`. The background-launch tail is
12515 // the load-bearing root-cause edit on every probe-as-both
12516 // value.
12517 let d = dep_with_fonte(DepSource::Path {
12518 caminho: "../caixa-teia&pin#tail".into(),
12519 });
12520 let err = d.validate().unwrap_err();
12521 assert!(
12522 matches!(err, DepError::FonteCaminhoShellBackground { .. }),
12523 "got {err:?}",
12524 );
12525 }
12526
12527 #[test]
12528 fn fonte_caminho_shell_semicolon_fires_before_shell_comment() {
12529 // Cascade pin on the upstream shell-semicolon arm: a value
12530 // carrying both `;` and `#` (`"../caixa-teia;pin#tail"` —
12531 // the canonical sequential-cleanup + URL-fragment paste
12532 // idiom) routes through `FonteCaminhoShellSemicolon` not
12533 // `FonteCaminhoShellComment`. The sequential-command-
12534 // separator paste is the load-bearing root-cause edit on
12535 // every probe-as-both value.
12536 let d = dep_with_fonte(DepSource::Path {
12537 caminho: "../caixa-teia;pin#tail".into(),
12538 });
12539 let err = d.validate().unwrap_err();
12540 assert!(
12541 matches!(err, DepError::FonteCaminhoShellSemicolon { .. }),
12542 "got {err:?}",
12543 );
12544 }
12545
12546 #[test]
12547 fn fonte_caminho_shell_pipe_fires_before_shell_comment() {
12548 // Cascade pin on the upstream shell-pipe arm: a value
12549 // carrying both `|` and `#` (`"../caixa-teia|pin#tail"` —
12550 // the canonical pipeline-to-URL-fragment paste idiom) routes
12551 // through `FonteCaminhoShellPipe` not
12552 // `FonteCaminhoShellComment`. The pipeline-tail paste is
12553 // the load-bearing root-cause edit on every probe-as-both
12554 // value.
12555 let d = dep_with_fonte(DepSource::Path {
12556 caminho: "../caixa-teia|pin#tail".into(),
12557 });
12558 let err = d.validate().unwrap_err();
12559 assert!(
12560 matches!(err, DepError::FonteCaminhoShellPipe { .. }),
12561 "got {err:?}",
12562 );
12563 }
12564
12565 #[test]
12566 fn fonte_caminho_shell_redirection_fires_before_shell_comment() {
12567 // Cascade pin on the upstream shell-redirection arm: a
12568 // value carrying both `>` and `#` (`"../caixa-teia>log#pin"`
12569 // — the canonical "I pasted a `cmd > log` redirect followed
12570 // by a URL-fragment tail" footgun) routes through
12571 // `FonteCaminhoShellRedirection` not
12572 // `FonteCaminhoShellComment`. The input/output redirection
12573 // metachar carries the more self-locating `byte` payload,
12574 // so the prior arm wins on every probe-as-both value.
12575 let d = dep_with_fonte(DepSource::Path {
12576 caminho: "../caixa-teia>log#pin".into(),
12577 });
12578 let err = d.validate().unwrap_err();
12579 assert!(
12580 matches!(
12581 err,
12582 DepError::FonteCaminhoShellRedirection { byte: b'>', .. }
12583 ),
12584 "got {err:?}",
12585 );
12586 }
12587
12588 #[test]
12589 fn fonte_caminho_backslash_fires_before_shell_comment() {
12590 // Cascade pin on the upstream backslash arm: a value
12591 // carrying both `\` and `#` (`"..\caixa-teia#pin"` — the
12592 // canonical "I pasted a Windows-shell path followed by a
12593 // URL-fragment tail" footgun) routes through
12594 // `FonteCaminhoBackslash` not `FonteCaminhoShellComment`.
12595 // The cross-host-OS-separator divergence is the load-
12596 // bearing axis on every probe-as-both value.
12597 let d = dep_with_fonte(DepSource::Path {
12598 caminho: "..\\caixa-teia#pin".into(),
12599 });
12600 let err = d.validate().unwrap_err();
12601 assert!(
12602 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12603 "got {err:?}",
12604 );
12605 }
12606
12607 #[test]
12608 fn fonte_caminho_control_char_fires_before_shell_comment() {
12609 // Cascade pin on the embedded-control-byte arm: a value
12610 // carrying both a control byte and `#` (`"../foo\n#pin"` —
12611 // the canonical paste-from-multiline-doc footgun where a
12612 // newline landed mid-caminho between the path and an
12613 // annotation) routes through `FonteCaminhoControlChar` not
12614 // `FonteCaminhoShellComment`. The POSIX-syscall-rejected-
12615 // byte diagnostic is the load-bearing axis on every value
12616 // that probes positive for both — mirrors the cascade
12617 // discipline on every prior arm.
12618 let d = dep_with_fonte(DepSource::Path {
12619 caminho: "../foo\n#pin".into(),
12620 });
12621 let err = d.validate().unwrap_err();
12622 assert!(
12623 matches!(err, DepError::FonteCaminhoControlChar { .. }),
12624 "got {err:?}",
12625 );
12626 }
12627
12628 #[test]
12629 fn fonte_caminho_absolute_fires_before_shell_comment() {
12630 // Cascade pin on the load-bearing leading-byte arm: a
12631 // leading `/` value with embedded `#` (`"/etc/foo#pin"`)
12632 // routes through `FonteCaminhoAbsolute` not
12633 // `FonteCaminhoShellComment` — the host-layout-leak
12634 // diagnostic is the load-bearing axis, the fragment byte is
12635 // the secondary observation. Same precedence logic as every
12636 // prior leading-byte arm.
12637 let d = dep_with_fonte(DepSource::Path {
12638 caminho: "/etc/foo#pin".into(),
12639 });
12640 let err = d.validate().unwrap_err();
12641 assert!(
12642 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12643 "got {err:?}",
12644 );
12645 }
12646
12647 #[test]
12648 fn fonte_caminho_var_expansion_fires_before_shell_comment() {
12649 // Cascade pin on the upstream leading-`$` var-expansion
12650 // arm: a value carrying both a leading `$` and a `#`
12651 // (`"$DIR/foo#pin"` — the canonical "I pasted a `$DIR`
12652 // shell-variable at the head of a sibling-workspace path
12653 // followed by a URL-fragment tail" footgun) routes through
12654 // `FonteCaminhoVarExpansion` not `FonteCaminhoShellComment`.
12655 // The leading-byte shell-variable-expansion is the more
12656 // self-locating diagnostic on values that probe as both.
12657 let d = dep_with_fonte(DepSource::Path {
12658 caminho: "$DIR/foo#pin".into(),
12659 });
12660 let err = d.validate().unwrap_err();
12661 assert!(
12662 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12663 "got {err:?}",
12664 );
12665 }
12666
12667 #[test]
12668 fn fonte_caminho_shell_comment_fires_before_trailing_slash() {
12669 // Cascade pin on the immediate-successor arm: a value
12670 // carrying both `#` and a trailing `/`
12671 // (`"../caixa-teia#pin/"` — the canonical "I tab-completed
12672 // a URL-fragment-carrying path" footgun) routes through
12673 // `FonteCaminhoShellComment` not
12674 // `FonteCaminhoTrailingSlash`. The embedded fragment /
12675 // comment-lead byte is the more semantic-locating axis (an
12676 // author who removes the `#pin` fragment typically also
12677 // drops the trailing separator since both are paste-from-
12678 // URL / paste-from-shell-tab-completion artifacts).
12679 let d = dep_with_fonte(DepSource::Path {
12680 caminho: "../caixa-teia#pin/".into(),
12681 });
12682 let err = d.validate().unwrap_err();
12683 assert!(
12684 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. },),
12685 "got {err:?}",
12686 );
12687 }
12688
12689 #[test]
12690 fn fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte() {
12691 // Diagnostic-shape pin (peer with
12692 // `fonte_caminho_shell_quote_grouping_diagnostic_carries_offending_dep_caminho_and_byte`
12693 // on the immediate-predecessor arm): the error's Display
12694 // surfaces the offending `:nome`, the offending `:caminho`
12695 // verbatim, the offending byte's hex / character form, and
12696 // names the shell-comment / URL-fragment-identifier /
12697 // YAML-comment cross-config-DSL footgun explicitly so a
12698 // `feira lint` run can render the diagnostic without
12699 // re-parsing.
12700 let d = dep_with_fonte(DepSource::Path {
12701 caminho: "../caixa-teia#readme".into(),
12702 });
12703 let rendered = d.validate().unwrap_err().to_string();
12704 assert!(
12705 rendered.contains("caixa-teia"),
12706 "diagnostic must name the offending dep: {rendered}",
12707 );
12708 assert!(
12709 rendered.contains("../caixa-teia#readme"),
12710 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
12711 );
12712 assert!(
12713 rendered.contains("0x23"),
12714 "diagnostic must surface the offending byte hex: {rendered:?}",
12715 );
12716 assert!(
12717 rendered.contains("shell-comment") || rendered.contains("comment-lead"),
12718 "diagnostic must name the shell-comment footgun: {rendered:?}",
12719 );
12720 assert!(
12721 rendered.contains("fragment") || rendered.contains("URL-fragment"),
12722 "diagnostic must reference the URL-fragment-identifier vocabulary: \
12723 {rendered:?}",
12724 );
12725 }
12726
12727 #[test]
12728 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_space() {
12729 // The canonical paste-from-browser-address-bar percent-
12730 // encoded-space footgun: an author copies `../caixa%20teia`
12731 // out of a URL-encoded README hyperlink / browser address
12732 // bar / percent-encoded permalink expecting `%20` to decode
12733 // to a literal space at the filesystem layer. POSIX
12734 // `std::path::Path` treats `%` as a literal path-component
12735 // byte, so `Path::join` looks for a literal
12736 // `./../caixa%20teia` subdirectory. `Path::is_absolute`
12737 // returns false on `..`, `%` is neither a leading-byte
12738 // sentinel nor a control byte nor `\` nor `<` / `>` nor
12739 // `|` nor `;` nor `&` nor backtick nor `*` / `?` nor `(` /
12740 // `)` nor `{` / `}` nor `[` / `]` nor `'` / `"` nor `#`,
12741 // and the value's last byte isn't `/` — so the value
12742 // silently passed every prior arm. The new arm moves the
12743 // rejection to validate time and names the offending dep +
12744 // caminho + byte verbatim.
12745 let d = dep_with_fonte(DepSource::Path {
12746 caminho: "../caixa%20teia".into(),
12747 });
12748 let err = d.validate().unwrap_err();
12749 let DepError::FonteCaminhoUrlPercentEncoding {
12750 nome,
12751 caminho,
12752 byte,
12753 } = err
12754 else {
12755 panic!("expected FonteCaminhoUrlPercentEncoding, got {err:?}");
12756 };
12757 assert_eq!(nome, "caixa-teia");
12758 assert_eq!(caminho, "../caixa%20teia");
12759 assert_eq!(byte, b'%');
12760 }
12761
12762 #[test]
12763 fn validate_rejects_path_fonte_with_caminho_carrying_url_percent_encoded_slash() {
12764 // The over-encoded path-separator shape (`"../caixa%2Fteia"`
12765 // intending the `%2F` as the URL encoding of `/`) locks a
12766 // `path:../caixa%2Fteia` BLAKE3 closure that diverges from
12767 // the byte-identical `path:../caixa/teia` form. Pinned
12768 // separately from the space-encoded shape so the gate's
12769 // coverage extends past the single canonical `%20` example
12770 // to any two-hex-digit percent-encoded sequence.
12771 let d = dep_with_fonte(DepSource::Path {
12772 caminho: "../caixa%2Fteia".into(),
12773 });
12774 let err = d.validate().unwrap_err();
12775 assert!(
12776 matches!(
12777 err,
12778 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12779 ),
12780 "got {err:?}",
12781 );
12782 }
12783
12784 #[test]
12785 fn validate_rejects_path_fonte_with_caminho_carrying_lone_percent() {
12786 // The lone-`%` malformed-escape shape (`"../caixa-teia%foo"`
12787 // where `%` isn't followed by two hex digits) — every
12788 // WHATWG-conformant URL parser rejects the value at parse
12789 // time per RFC 3986 §2.1, but the byte would silently ride
12790 // into the lacre before the resolver subprocess crosses the
12791 // URL-parser boundary. Pinned separately from the well-
12792 // formed `%HH` shapes so the gate covers every percent-
12793 // occurrence, not only strictly-conformant escapes.
12794 let d = dep_with_fonte(DepSource::Path {
12795 caminho: "../caixa-teia%foo".into(),
12796 });
12797 let err = d.validate().unwrap_err();
12798 assert!(
12799 matches!(
12800 err,
12801 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12802 ),
12803 "got {err:?}",
12804 );
12805 }
12806
12807 #[test]
12808 fn validate_rejects_path_fonte_with_caminho_carrying_leading_yaml_directive() {
12809 // The YAML-directive-lead paste shape (`"%YAML/../caixa-teia"`
12810 // — the canonical paste-from-top-of-doc YAML directive
12811 // block cross-idiom leak per YAML 1.2 §6.8.1). Pinned
12812 // separately from embedded shapes so the gate covers the
12813 // leading-position `%` too, not only mid-value occurrences.
12814 let d = dep_with_fonte(DepSource::Path {
12815 caminho: "%YAML/../caixa-teia".into(),
12816 });
12817 let err = d.validate().unwrap_err();
12818 assert!(
12819 matches!(
12820 err,
12821 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12822 ),
12823 "got {err:?}",
12824 );
12825 }
12826
12827 #[test]
12828 fn validate_rejects_path_fonte_with_caminho_carrying_printf_format_specifier() {
12829 // The printf-format-specifier paste shape
12830 // (`"../caixa-%s-teia"` — the canonical paste-from-shell-
12831 // diagnostic-one-liner `printf "path=%s\n" ...` idiom, CWE-
12832 // 134 format-string-injection vector). Pinned separately
12833 // from the URL-encoding shapes so the gate's rationale
12834 // extends past the RFC 3986 axis to the C / POSIX printf
12835 // format-directive-lead axis.
12836 let d = dep_with_fonte(DepSource::Path {
12837 caminho: "../caixa-%s-teia".into(),
12838 });
12839 let err = d.validate().unwrap_err();
12840 assert!(
12841 matches!(
12842 err,
12843 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
12844 ),
12845 "got {err:?}",
12846 );
12847 }
12848
12849 #[test]
12850 fn validate_accepts_path_fonte_with_caminho_carrying_no_percent() {
12851 // The positive-control pin: the gate targets only `%`,
12852 // never adjacent printable ASCII or POSIX-valid bytes. The
12853 // canonical relative POSIX path (`"../caixa-teia"`) and a
12854 // nested deeply-pathed variant with adjacent printable
12855 // punctuation (`"../caixa-teia/sub-dir.v2"`) must continue
12856 // to validate cleanly so the gate doesn't widen to a "no
12857 // printable punctuation anywhere" sweep that would defeat
12858 // the entire path-fonte author surface. Peer with
12859 // `validate_accepts_path_fonte_with_caminho_carrying_no_shell_comment`
12860 // on the immediate-predecessor arm.
12861 let d = dep_with_fonte(DepSource::Path {
12862 caminho: "../caixa-teia/sub-dir.v2".into(),
12863 });
12864 d.validate().unwrap();
12865 }
12866
12867 #[test]
12868 fn fonte_caminho_shell_comment_fires_before_url_percent_encoding() {
12869 // Cascade pin on the immediate-predecessor arm: a value
12870 // carrying both `#` and `%` (`"../caixa-teia#pin%20"` — the
12871 // canonical "I pasted a URL-fragment permalink followed by a
12872 // percent-encoded space tail" footgun) routes through
12873 // `FonteCaminhoShellComment` not
12874 // `FonteCaminhoUrlPercentEncoding`. The URL-fragment-
12875 // identifier is the load-bearing downstream-truncation edit
12876 // on every probe-as-both value; same cascade discipline
12877 // every prior `:caminho` arm establishes.
12878 let d = dep_with_fonte(DepSource::Path {
12879 caminho: "../caixa-teia#pin%20".into(),
12880 });
12881 let err = d.validate().unwrap_err();
12882 assert!(
12883 matches!(err, DepError::FonteCaminhoShellComment { byte: b'#', .. }),
12884 "got {err:?}",
12885 );
12886 }
12887
12888 #[test]
12889 fn fonte_caminho_shell_quote_grouping_fires_before_url_percent_encoding() {
12890 // Cascade pin on the upstream shell-quote-grouping arm: a
12891 // value carrying both `'` and `%` (`"../'x'%20teia"` — the
12892 // canonical "I pasted a strong-quoted literal followed by
12893 // a percent-encoded space" footgun) routes through
12894 // `FonteCaminhoShellQuoteGrouping` not
12895 // `FonteCaminhoUrlPercentEncoding`. The shell-string-
12896 // literal-delimiter is the load-bearing root-cause edit on
12897 // every probe-as-both value.
12898 let d = dep_with_fonte(DepSource::Path {
12899 caminho: "../'x'%20teia".into(),
12900 });
12901 let err = d.validate().unwrap_err();
12902 assert!(
12903 matches!(
12904 err,
12905 DepError::FonteCaminhoShellQuoteGrouping { byte: b'\'', .. },
12906 ),
12907 "got {err:?}",
12908 );
12909 }
12910
12911 #[test]
12912 fn fonte_caminho_backslash_fires_before_url_percent_encoding() {
12913 // Cascade pin on the upstream backslash arm: a value
12914 // carrying both `\` and `%` (`"..\\caixa%20teia"` — the
12915 // canonical "I pasted a Windows-shell path followed by a
12916 // percent-encoded space" footgun) routes through
12917 // `FonteCaminhoBackslash` not
12918 // `FonteCaminhoUrlPercentEncoding`. The cross-host-OS-
12919 // separator divergence is the load-bearing root-cause edit
12920 // on every probe-as-both value.
12921 let d = dep_with_fonte(DepSource::Path {
12922 caminho: "..\\caixa%20teia".into(),
12923 });
12924 let err = d.validate().unwrap_err();
12925 assert!(
12926 matches!(err, DepError::FonteCaminhoBackslash { .. }),
12927 "got {err:?}",
12928 );
12929 }
12930
12931 #[test]
12932 fn fonte_caminho_control_char_fires_before_url_percent_encoding() {
12933 // Cascade pin on the upstream control-char arm: a value
12934 // carrying both a NUL byte and `%` (`"../caixa\0%20teia"` —
12935 // the canonical "I pasted a paste-from-binary-blob path
12936 // followed by a percent-encoded space" footgun) routes
12937 // through `FonteCaminhoControlChar` not
12938 // `FonteCaminhoUrlPercentEncoding`. The POSIX-syscall-
12939 // rejected byte is the load-bearing root-cause edit on
12940 // every probe-as-both value.
12941 let d = dep_with_fonte(DepSource::Path {
12942 caminho: "../caixa\0%20teia".into(),
12943 });
12944 let err = d.validate().unwrap_err();
12945 assert!(
12946 matches!(err, DepError::FonteCaminhoControlChar { byte: 0x00, .. },),
12947 "got {err:?}",
12948 );
12949 }
12950
12951 #[test]
12952 fn fonte_caminho_absolute_fires_before_url_percent_encoding() {
12953 // Cascade pin on the upstream absolute-path arm: a value
12954 // that's both absolute and carries `%` (`"/etc/passwd%20"`
12955 // — the canonical "I pasted an absolute path with a
12956 // percent-encoded space tail" footgun) routes through
12957 // `FonteCaminhoAbsolute` not
12958 // `FonteCaminhoUrlPercentEncoding`. The host-layout-leak is
12959 // the load-bearing root-cause edit on every probe-as-both
12960 // value.
12961 let d = dep_with_fonte(DepSource::Path {
12962 caminho: "/etc/passwd%20".into(),
12963 });
12964 let err = d.validate().unwrap_err();
12965 assert!(
12966 matches!(err, DepError::FonteCaminhoAbsolute { .. }),
12967 "got {err:?}",
12968 );
12969 }
12970
12971 #[test]
12972 fn fonte_caminho_var_expansion_fires_before_url_percent_encoding() {
12973 // Cascade pin on the upstream var-expansion arm: a value
12974 // starting with `$` and carrying `%` (`"$HOME/caixa%20teia"`
12975 // — the canonical "I pasted a `$HOME`-rooted path with a
12976 // percent-encoded space" footgun) routes through
12977 // `FonteCaminhoVarExpansion` not
12978 // `FonteCaminhoUrlPercentEncoding`. The shell-variable-
12979 // expansion is the load-bearing root-cause edit on every
12980 // probe-as-both value.
12981 let d = dep_with_fonte(DepSource::Path {
12982 caminho: "$HOME/caixa%20teia".into(),
12983 });
12984 let err = d.validate().unwrap_err();
12985 assert!(
12986 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
12987 "got {err:?}",
12988 );
12989 }
12990
12991 #[test]
12992 fn fonte_caminho_url_percent_encoding_fires_before_trailing_slash() {
12993 // Cascade pin on the immediate-successor arm: a value
12994 // carrying both `%` and a trailing `/`
12995 // (`"../caixa%20teia/"` — the canonical "I tab-completed a
12996 // percent-encoded-space-carrying path" footgun) routes
12997 // through `FonteCaminhoUrlPercentEncoding` not
12998 // `FonteCaminhoTrailingSlash`. The embedded percent-
12999 // encoding-escape byte is the more semantic-locating axis
13000 // (an author who decodes the `%20` to a literal space is
13001 // likely to also tab-strip the trailing separator since
13002 // both are paste-from-URL / paste-from-shell-tab-completion
13003 // artifacts).
13004 let d = dep_with_fonte(DepSource::Path {
13005 caminho: "../caixa%20teia/".into(),
13006 });
13007 let err = d.validate().unwrap_err();
13008 assert!(
13009 matches!(
13010 err,
13011 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13012 ),
13013 "got {err:?}",
13014 );
13015 }
13016
13017 #[test]
13018 fn fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte() {
13019 // Diagnostic-shape pin (peer with
13020 // `fonte_caminho_shell_comment_diagnostic_carries_offending_dep_caminho_and_byte`
13021 // on the immediate-predecessor arm): the error's Display
13022 // surfaces the offending `:nome`, the offending `:caminho`
13023 // verbatim, the offending byte's hex / character form, and
13024 // names the URL-percent-encoding-escape / printf-format-
13025 // specifier footgun explicitly so a `feira lint` run can
13026 // render the diagnostic without re-parsing.
13027 let d = dep_with_fonte(DepSource::Path {
13028 caminho: "../caixa%20teia".into(),
13029 });
13030 let rendered = d.validate().unwrap_err().to_string();
13031 assert!(
13032 rendered.contains("caixa-teia"),
13033 "diagnostic must name the offending dep: {rendered}",
13034 );
13035 assert!(
13036 rendered.contains("../caixa%20teia"),
13037 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13038 );
13039 assert!(
13040 rendered.contains("0x25"),
13041 "diagnostic must surface the offending byte hex: {rendered:?}",
13042 );
13043 assert!(
13044 rendered.contains("percent-encoding") || rendered.contains("percent-encoded"),
13045 "diagnostic must name the URL-percent-encoding-escape footgun: {rendered:?}",
13046 );
13047 assert!(
13048 rendered.contains("printf") || rendered.contains("format-specifier"),
13049 "diagnostic must reference the printf-format-specifier vocabulary: \
13050 {rendered:?}",
13051 );
13052 }
13053
13054 #[test]
13055 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_var_expansion() {
13056 // The canonical embedded-`$` shell-variable-expansion paste
13057 // shape (`"../foo$HOME/bar"` — an author copies a partially-
13058 // substituted shell one-liner where the leading segment is a
13059 // literal `../foo` while the mid segment carries the un-
13060 // substituted `$HOME` template). The leading-`$` position is
13061 // already gated by the f4efe9c leading-byte arm which routes
13062 // through `FonteCaminhoVarExpansion`; this arm closes the
13063 // last positional gap on `$` — every position on the axis is
13064 // structurally rejected.
13065 let d = dep_with_fonte(DepSource::Path {
13066 caminho: "../foo$HOME/bar".into(),
13067 });
13068 let err = d.validate().unwrap_err();
13069 let DepError::FonteCaminhoShellVariableExpansion {
13070 nome,
13071 caminho,
13072 byte,
13073 } = err
13074 else {
13075 panic!("expected FonteCaminhoShellVariableExpansion, got {err:?}");
13076 };
13077 assert_eq!(nome, "caixa-teia");
13078 assert_eq!(caminho, "../foo$HOME/bar");
13079 assert_eq!(byte, b'$');
13080 }
13081
13082 #[test]
13083 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_braced_var_expansion() {
13084 // The symmetric braced-CI-manifest paste shape
13085 // (`"../foo${WORKSPACE}/bar"` — the canonical paste-from-
13086 // GitHub-Actions-workflow / paste-from-`.gitlab-ci.yml`
13087 // footgun). Pinned separately from the bare-`$VAR` shape so
13088 // the gate covers both POSIX shell §2.6 Parameter Expansion
13089 // syntactic forms, not only the unbraced variant. The
13090 // embedded `{` byte in `${...}` is also caught by the 598b770
13091 // shell-brace-expansion arm but that arm fires earlier in
13092 // the cascade — the `$` arm's coverage extends to `${...}`
13093 // structurally, so the diagnostic asserted here is the
13094 // brace-expansion one (which is a valid outcome; the point
13095 // of the pin is that the value never survives validation).
13096 let d = dep_with_fonte(DepSource::Path {
13097 caminho: "../foo${WORKSPACE}/bar".into(),
13098 });
13099 let err = d.validate().unwrap_err();
13100 assert!(
13101 matches!(
13102 err,
13103 DepError::FonteCaminhoShellBraceExpansion { byte: b'{', .. }
13104 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13105 ),
13106 "got {err:?}",
13107 );
13108 }
13109
13110 #[test]
13111 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_command_substitution() {
13112 // The paste-from-shell-prompt command-substitution idiom
13113 // (`"../foo$(whoami)/bar"`). Pinned separately from the bare-
13114 // `$VAR` shape so the gate's rationale extends to POSIX shell
13115 // §2.6.3 Command Substitution (the modern `$(<cmd>)` form; the
13116 // legacy `` `<cmd>` `` form is already closed by the c370458
13117 // backtick arm). The embedded `(` byte in `$(...)` is also
13118 // caught structurally by the 0633c91 shell-subshell-grouping
13119 // arm which fires earlier in the cascade — the diagnostic
13120 // asserted here is either outcome, since both structurally
13121 // reject the value; the point of the pin is that the value
13122 // never survives validation.
13123 let d = dep_with_fonte(DepSource::Path {
13124 caminho: "../foo$(whoami)/bar".into(),
13125 });
13126 let err = d.validate().unwrap_err();
13127 assert!(
13128 matches!(
13129 err,
13130 DepError::FonteCaminhoShellSubshellGrouping { byte: b'(', .. }
13131 | DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13132 ),
13133 "got {err:?}",
13134 );
13135 }
13136
13137 #[test]
13138 fn validate_rejects_path_fonte_with_caminho_carrying_embedded_positional_parameter() {
13139 // The paste-from-`Makefile` / paste-from-SQL-migration bare-
13140 // `$1` positional-parameter shape (`"../foo$1/bar"` — a Make
13141 // automatic-variable `$1` or a PostgreSQL bind-parameter `$1`
13142 // idiom copied into a caminho template). None of the prior
13143 // shell-metachar arms cover this shape (`1` is a bare digit;
13144 // no `(` / `{` / letter follows the `$`), so the arm is the
13145 // sole gate on the shape.
13146 let d = dep_with_fonte(DepSource::Path {
13147 caminho: "../foo$1/bar".into(),
13148 });
13149 let err = d.validate().unwrap_err();
13150 assert!(
13151 matches!(
13152 err,
13153 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13154 ),
13155 "got {err:?}",
13156 );
13157 }
13158
13159 #[test]
13160 fn validate_accepts_path_fonte_with_caminho_carrying_no_dollar() {
13161 // The positive-control pin (peer with
13162 // `validate_accepts_path_fonte_with_caminho_carrying_no_percent`
13163 // on the immediate-predecessor arm): the gate targets only
13164 // `$`, never adjacent printable ASCII or POSIX-valid bytes.
13165 // A relative POSIX path carrying dashes / dots / slashes /
13166 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13167 // validate cleanly so the gate doesn't widen to a "no
13168 // printable punctuation anywhere" sweep that would defeat
13169 // the entire path-fonte author surface.
13170 let d = dep_with_fonte(DepSource::Path {
13171 caminho: "../caixa-teia/sub-dir.v2".into(),
13172 });
13173 d.validate().unwrap();
13174 }
13175
13176 #[test]
13177 fn fonte_caminho_var_expansion_fires_before_shell_variable_expansion() {
13178 // Cascade pin on the leading-`$` sibling arm at line 540: a
13179 // value starting with `$` and carrying an embedded `$` too
13180 // (`"$HOME/foo$WORKSPACE/bar"` — the canonical "I pasted a
13181 // fully-templated CI path with two un-substituted variables")
13182 // routes through `FonteCaminhoVarExpansion` not
13183 // `FonteCaminhoShellVariableExpansion`. The leading-byte
13184 // host-layout-leak is the load-bearing self-locating axis
13185 // (the leading position dominates the semantic-locating
13186 // rationale on every probe-as-both value); the embedded
13187 // arm's positional-agnostic sweep catches only values whose
13188 // leading byte doesn't route through the earlier leading-
13189 // byte arms.
13190 let d = dep_with_fonte(DepSource::Path {
13191 caminho: "$HOME/foo$WORKSPACE/bar".into(),
13192 });
13193 let err = d.validate().unwrap_err();
13194 assert!(
13195 matches!(err, DepError::FonteCaminhoVarExpansion { .. }),
13196 "got {err:?}",
13197 );
13198 }
13199
13200 #[test]
13201 fn fonte_caminho_url_percent_encoding_fires_before_shell_variable_expansion() {
13202 // Cascade pin on the immediate-predecessor arm: a value
13203 // carrying both `%` and embedded `$` (`"../foo%20$HOME/bar"`
13204 // — the canonical "I pasted a percent-encoded space adjacent
13205 // to a `$HOME` template") routes through
13206 // `FonteCaminhoUrlPercentEncoding` not
13207 // `FonteCaminhoShellVariableExpansion`. The URL-percent-
13208 // encoding-escape byte is the more semantic-locating axis
13209 // (the paste-from-browser-address-bar shape is the load-
13210 // bearing self-locating edit); same cascade discipline every
13211 // prior `:caminho` arm establishes.
13212 let d = dep_with_fonte(DepSource::Path {
13213 caminho: "../foo%20$HOME/bar".into(),
13214 });
13215 let err = d.validate().unwrap_err();
13216 assert!(
13217 matches!(
13218 err,
13219 DepError::FonteCaminhoUrlPercentEncoding { byte: b'%', .. },
13220 ),
13221 "got {err:?}",
13222 );
13223 }
13224
13225 #[test]
13226 fn fonte_caminho_shell_variable_expansion_fires_before_trailing_slash() {
13227 // Cascade pin on the immediate-successor arm: a value
13228 // carrying both embedded `$` and a trailing `/`
13229 // (`"../foo$HOME/bar/"` — the canonical "I tab-completed a
13230 // `$HOME`-template-carrying path") routes through
13231 // `FonteCaminhoShellVariableExpansion` not
13232 // `FonteCaminhoTrailingSlash`. The embedded shell-variable-
13233 // expansion byte is the more semantic-locating axis on
13234 // probe-as-both values (an author who substitutes the
13235 // `$HOME` template with a literal value is likely to also
13236 // tab-strip the trailing separator).
13237 let d = dep_with_fonte(DepSource::Path {
13238 caminho: "../foo$HOME/bar/".into(),
13239 });
13240 let err = d.validate().unwrap_err();
13241 assert!(
13242 matches!(
13243 err,
13244 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13245 ),
13246 "got {err:?}",
13247 );
13248 }
13249
13250 #[test]
13251 fn fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13252 // Diagnostic-shape pin (peer with
13253 // `fonte_caminho_url_percent_encoding_diagnostic_carries_offending_dep_caminho_and_byte`
13254 // on the immediate-predecessor arm): the error's Display
13255 // surfaces the offending `:nome`, the offending `:caminho`
13256 // verbatim, the offending byte's hex / character form, and
13257 // names the shell-variable-expansion / command-substitution
13258 // footgun explicitly so a `feira lint` run can render the
13259 // diagnostic without re-parsing.
13260 let d = dep_with_fonte(DepSource::Path {
13261 caminho: "../foo$HOME/bar".into(),
13262 });
13263 let rendered = d.validate().unwrap_err().to_string();
13264 assert!(
13265 rendered.contains("caixa-teia"),
13266 "diagnostic must name the offending dep: {rendered}",
13267 );
13268 assert!(
13269 rendered.contains("../foo$HOME/bar"),
13270 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13271 );
13272 assert!(
13273 rendered.contains("0x24"),
13274 "diagnostic must surface the offending byte hex: {rendered:?}",
13275 );
13276 assert!(
13277 rendered.contains("variable-expansion") || rendered.contains("variable expansion"),
13278 "diagnostic must name the shell-variable-expansion footgun: {rendered:?}",
13279 );
13280 assert!(
13281 rendered.contains("command-substitution") || rendered.contains("command substitution"),
13282 "diagnostic must reference the command-substitution vocabulary: {rendered:?}",
13283 );
13284 }
13285
13286 #[test]
13287 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_expansion() {
13288 // The fail-before-pass-after pin for the canonical paste-from-
13289 // shell-history footgun on `:caminho`. An author copies a `cd
13290 // ../caixa-teia && !sudo make install` one-liner from a quick-
13291 // start README, intending the trailing `!sudo` as a shell-
13292 // history-expansion reference but the typed slot is itself a
13293 // byte-level string parser, not a shell context, so the byte
13294 // rides into the value verbatim. Until this arm landed the `!`
13295 // byte silently passed every prior `:caminho` cascade arm
13296 // (`!` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick /
13297 // `*` / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` /
13298 // `#` / `%` / `$`); bash with the default `histexpand` mode
13299 // rewrites `!command` to the most recent history entry
13300 // beginning with `command`, the canonical RCE-class injection
13301 // vector when the byte rides into a shell argument executed
13302 // under `bash -i` (the operator-notebook interactive shell).
13303 let d = dep_with_fonte(DepSource::Path {
13304 caminho: "../caixa-teia!sudo".into(),
13305 });
13306 let err = d.validate().unwrap_err();
13307 let DepError::FonteCaminhoShellHistoryExpansion {
13308 nome,
13309 caminho,
13310 byte,
13311 } = err
13312 else {
13313 panic!("expected FonteCaminhoShellHistoryExpansion, got {err:?}");
13314 };
13315 assert_eq!(nome, "caixa-teia");
13316 assert_eq!(caminho, "../caixa-teia!sudo");
13317 assert_eq!(byte, b'!');
13318 }
13319
13320 #[test]
13321 fn validate_rejects_path_fonte_with_caminho_carrying_double_bang_history_reference() {
13322 // The symmetric `!!` repeat-prior-command paste idiom (peer with
13323 // `validate_rejects_git_fonte_with_repo_carrying_double_bang_history_reference`
13324 // on `is_git_repo_url`). Pinned separately from the wrapped
13325 // `!command` shape so a future diagnostic-surface change that
13326 // only checked the leading or paired-bang position surfaces
13327 // here — the per-byte arm fires anywhere `!` appears in the
13328 // value, including at consecutive positions in the middle.
13329 let d = dep_with_fonte(DepSource::Path {
13330 caminho: "../foo!!/bar".into(),
13331 });
13332 let err = d.validate().unwrap_err();
13333 assert!(
13334 matches!(
13335 err,
13336 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13337 ),
13338 "got {err:?}",
13339 );
13340 }
13341
13342 #[test]
13343 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_enthusiasm_bang() {
13344 // The English-typography enthusiasm-form paste-from-prose
13345 // idiom: an author writes `:caminho "../caixa-teia!"`
13346 // expecting the substrate to coerce it to a kebab-case slug.
13347 // Pinned separately from the `!<word>` shell-history shape so
13348 // the gate's rationale extends to the paste-from-prose surface
13349 // (the same rationale the peer `is_git_repo_url` bang arm at
13350 // 7d53c68 covers). None of the prior shell-metachar arms cover
13351 // this shape (no `!<word>` reference and no `!!` repeat), so
13352 // the arm is the sole gate on the shape.
13353 let d = dep_with_fonte(DepSource::Path {
13354 caminho: "../caixa-teia!".into(),
13355 });
13356 let err = d.validate().unwrap_err();
13357 assert!(
13358 matches!(
13359 err,
13360 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13361 ),
13362 "got {err:?}",
13363 );
13364 }
13365
13366 #[test]
13367 fn validate_accepts_path_fonte_with_caminho_carrying_no_bang() {
13368 // The positive-control pin (peer with
13369 // `validate_accepts_path_fonte_with_caminho_carrying_no_dollar`
13370 // on the immediate-predecessor arm): the gate targets only
13371 // `!`, never adjacent printable ASCII or POSIX-valid bytes.
13372 // A relative POSIX path carrying dashes / dots / slashes /
13373 // digits (`"../caixa-teia/sub-dir.v2"`) must continue to
13374 // validate cleanly so the gate doesn't widen to a "no
13375 // printable punctuation anywhere" sweep that would defeat
13376 // the entire path-fonte author surface.
13377 let d = dep_with_fonte(DepSource::Path {
13378 caminho: "../caixa-teia/sub-dir.v2".into(),
13379 });
13380 d.validate().unwrap();
13381 }
13382
13383 #[test]
13384 fn fonte_caminho_shell_variable_expansion_fires_before_shell_history_expansion() {
13385 // Cascade pin on the immediate-predecessor arm: a value
13386 // carrying both embedded `$` and `!` (`"../foo$HOME/bar!sudo"`
13387 // — the canonical "I pasted a `$HOME`-templated path adjacent
13388 // to a trailing `!sudo` history-expansion") routes through
13389 // `FonteCaminhoShellVariableExpansion` not
13390 // `FonteCaminhoShellHistoryExpansion`. The shell-variable-
13391 // expansion byte is the more semantic-locating axis on
13392 // probe-as-both values (the paste-from-CI-manifest-with-`$VAR`-
13393 // template shape is the load-bearing self-locating edit);
13394 // same cascade discipline every prior `:caminho` arm
13395 // establishes.
13396 let d = dep_with_fonte(DepSource::Path {
13397 caminho: "../foo$HOME/bar!sudo".into(),
13398 });
13399 let err = d.validate().unwrap_err();
13400 assert!(
13401 matches!(
13402 err,
13403 DepError::FonteCaminhoShellVariableExpansion { byte: b'$', .. },
13404 ),
13405 "got {err:?}",
13406 );
13407 }
13408
13409 #[test]
13410 fn fonte_caminho_shell_history_expansion_fires_before_trailing_slash() {
13411 // Cascade pin on the immediate-successor arm: a value carrying
13412 // both embedded `!` and a trailing `/` (`"../caixa-teia!sudo/"`
13413 // — the canonical "I tab-completed a `!sudo`-carrying path")
13414 // routes through `FonteCaminhoShellHistoryExpansion` not
13415 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13416 // expansion byte is the more semantic-locating axis on probe-
13417 // as-both values (an author who removes the `!sudo` history
13418 // reference is likely to also tab-strip the trailing separator).
13419 let d = dep_with_fonte(DepSource::Path {
13420 caminho: "../caixa-teia!sudo/".into(),
13421 });
13422 let err = d.validate().unwrap_err();
13423 assert!(
13424 matches!(
13425 err,
13426 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13427 ),
13428 "got {err:?}",
13429 );
13430 }
13431
13432 #[test]
13433 fn fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte() {
13434 // Diagnostic-shape pin (peer with
13435 // `fonte_caminho_shell_variable_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13436 // on the immediate-predecessor arm): the error's Display
13437 // surfaces the offending `:nome`, the offending `:caminho`
13438 // verbatim, the offending byte's hex / character form, and
13439 // names the shell-history-expansion / bang-operator footgun
13440 // explicitly so a `feira lint` run can render the diagnostic
13441 // without re-parsing.
13442 let d = dep_with_fonte(DepSource::Path {
13443 caminho: "../caixa-teia!sudo".into(),
13444 });
13445 let rendered = d.validate().unwrap_err().to_string();
13446 assert!(
13447 rendered.contains("caixa-teia"),
13448 "diagnostic must name the offending dep: {rendered}",
13449 );
13450 assert!(
13451 rendered.contains("../caixa-teia!sudo"),
13452 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13453 );
13454 assert!(
13455 rendered.contains("0x21"),
13456 "diagnostic must surface the offending byte hex: {rendered:?}",
13457 );
13458 assert!(
13459 rendered.contains("history-expansion") || rendered.contains("history expansion"),
13460 "diagnostic must name the shell-history-expansion footgun: {rendered:?}",
13461 );
13462 assert!(
13463 rendered.contains("bang"),
13464 "diagnostic must reference the bang-operator vocabulary: {rendered:?}",
13465 );
13466 }
13467
13468 #[test]
13469 fn validate_rejects_path_fonte_with_caminho_carrying_shell_history_substitution() {
13470 // The fail-before-pass-after pin for the canonical paste-from-
13471 // shell-history-quick-substitution footgun on `:caminho`. An
13472 // author copies a `git clone <bad-url>` line from their terminal,
13473 // corrects it via bash's `^bad^good` quick-substitution history
13474 // operator (bash reference §9.3, `set -o histexpand` mode's
13475 // default for interactive sessions), and pastes the trailing
13476 // `^bad^good` substitution fragment into a `:caminho` value
13477 // without trimming the leading `git clone` prefix — the byte
13478 // rides into the manifest verbatim. Until this arm landed the
13479 // `^` byte silently passed every prior `:caminho` cascade arm
13480 // (`^` isn't `\` / `<` / `>` / `|` / `;` / `&` / backtick / `*`
13481 // / `?` / `(` / `)` / `{` / `}` / `[` / `]` / `'` / `"` / `#` /
13482 // `%` / `$` / `!`); bash with the default `histexpand` mode
13483 // rewrites the prior command's `bad` string to `good` and re-
13484 // executes it, the paired-operator half of the `set -o
13485 // histexpand` feature the peer `!` arm already closes the prefix
13486 // half of. The peer `is_git_repo_url` axis rejects the byte at
13487 // 49e142f under the same shell-history-substitution / RFC-3986-
13488 // unwise banner.
13489 let d = dep_with_fonte(DepSource::Path {
13490 caminho: "../foo^bad^good".into(),
13491 });
13492 let err = d.validate().unwrap_err();
13493 let DepError::FonteCaminhoShellHistorySubstitution {
13494 nome,
13495 caminho,
13496 byte,
13497 } = err
13498 else {
13499 panic!("expected FonteCaminhoShellHistorySubstitution, got {err:?}");
13500 };
13501 assert_eq!(nome, "caixa-teia");
13502 assert_eq!(caminho, "../foo^bad^good");
13503 assert_eq!(byte, b'^');
13504 }
13505
13506 #[test]
13507 fn validate_rejects_path_fonte_with_caminho_carrying_regex_negation_anchor() {
13508 // The symmetric paste-from-doc-grep-pipeline footgun (peer with
13509 // `validate_rejects_git_fonte_with_repo_carrying_caret_regex_anchor`
13510 // on `is_git_repo_url`). An author copies a `grep '^archived'`
13511 // regex-anchor / negation idiom from a doc snippet and the byte
13512 // rides in verbatim. Pinned separately from the `^old^new^`
13513 // quick-substitution shape so a future diagnostic-surface change
13514 // that only checked the paired-caret history-substitution
13515 // position surfaces here — the per-byte arm fires anywhere `^`
13516 // appears in the value, including at a solitary leading-of-
13517 // segment position.
13518 let d = dep_with_fonte(DepSource::Path {
13519 caminho: "../foo/^archived".into(),
13520 });
13521 let err = d.validate().unwrap_err();
13522 assert!(
13523 matches!(
13524 err,
13525 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13526 ),
13527 "got {err:?}",
13528 );
13529 }
13530
13531 #[test]
13532 fn validate_rejects_path_fonte_with_caminho_carrying_trailing_history_substitution_open() {
13533 // The trailing-`^` history-substitution-open shape — an author
13534 // starts typing a `^bad^good` quick-substitution but pastes only
13535 // the leading `^` sentinel before context-switching (a bash-
13536 // reference §9.3 valid histexpand prefix on its own — even a
13537 // solitary `^` on the prior command's whole re-execution shape).
13538 // Pinned separately from the `^old^new^` full-form and the leading-
13539 // of-segment `^archived` regex-anchor shape so the gate's
13540 // rationale extends to the paste-from-shell-history-with-only-
13541 // the-first-byte-selected surface. None of the prior shell-
13542 // metachar arms cover this shape.
13543 let d = dep_with_fonte(DepSource::Path {
13544 caminho: "../caixa-teia^".into(),
13545 });
13546 let err = d.validate().unwrap_err();
13547 assert!(
13548 matches!(
13549 err,
13550 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13551 ),
13552 "got {err:?}",
13553 );
13554 }
13555
13556 #[test]
13557 fn validate_accepts_path_fonte_with_caminho_carrying_no_caret() {
13558 // The positive-control pin (peer with
13559 // `validate_accepts_path_fonte_with_caminho_carrying_no_bang`
13560 // on the immediate-predecessor arm): the gate targets only
13561 // `^`, never adjacent printable ASCII or POSIX-valid bytes.
13562 // A relative POSIX path carrying dashes / dots / slashes /
13563 // digits / underscore (`"../caixa-teia/sub_v2.rc"`) must
13564 // continue to validate cleanly so the gate doesn't widen to
13565 // a "no printable punctuation anywhere" sweep that would
13566 // defeat the entire path-fonte author surface.
13567 let d = dep_with_fonte(DepSource::Path {
13568 caminho: "../caixa-teia/sub_v2.rc".into(),
13569 });
13570 d.validate().unwrap();
13571 }
13572
13573 #[test]
13574 fn fonte_caminho_shell_history_expansion_fires_before_shell_history_substitution() {
13575 // Cascade pin on the immediate-predecessor arm: a value carrying
13576 // both embedded `!` and `^` (`"../foo!sudo^bad^good"` — the
13577 // canonical "I pasted a `!sudo` history-reference next to a
13578 // `^bad^good` quick-substitution") routes through
13579 // `FonteCaminhoShellHistoryExpansion` not
13580 // `FonteCaminhoShellHistorySubstitution`. The `!` prefix form is
13581 // the more semantic-locating axis on probe-as-both values (an
13582 // author who removes the `!sudo` reference is likely to also
13583 // strip the paired `^` substitution fragment); same cascade
13584 // discipline every prior `:caminho` arm establishes.
13585 let d = dep_with_fonte(DepSource::Path {
13586 caminho: "../foo!sudo^bad^good".into(),
13587 });
13588 let err = d.validate().unwrap_err();
13589 assert!(
13590 matches!(
13591 err,
13592 DepError::FonteCaminhoShellHistoryExpansion { byte: b'!', .. },
13593 ),
13594 "got {err:?}",
13595 );
13596 }
13597
13598 #[test]
13599 fn fonte_caminho_shell_history_substitution_fires_before_trailing_slash() {
13600 // Cascade pin on the immediate-successor arm: a value carrying
13601 // both embedded `^` and a trailing `/` (`"../foo^bad^good/"` —
13602 // the canonical "I tab-completed a `^bad^good`-carrying path")
13603 // routes through `FonteCaminhoShellHistorySubstitution` not
13604 // `FonteCaminhoTrailingSlash`. The embedded shell-history-
13605 // substitution byte is the more semantic-locating axis on probe-
13606 // as-both values (an author who removes the `^bad^good`
13607 // substitution fragment is likely to also tab-strip the trailing
13608 // separator).
13609 let d = dep_with_fonte(DepSource::Path {
13610 caminho: "../foo^bad^good/".into(),
13611 });
13612 let err = d.validate().unwrap_err();
13613 assert!(
13614 matches!(
13615 err,
13616 DepError::FonteCaminhoShellHistorySubstitution { byte: b'^', .. },
13617 ),
13618 "got {err:?}",
13619 );
13620 }
13621
13622 #[test]
13623 fn fonte_caminho_shell_history_substitution_diagnostic_carries_offending_dep_caminho_and_byte()
13624 {
13625 // Diagnostic-shape pin (peer with
13626 // `fonte_caminho_shell_history_expansion_diagnostic_carries_offending_dep_caminho_and_byte`
13627 // on the immediate-predecessor arm): the error's Display
13628 // surfaces the offending `:nome`, the offending `:caminho`
13629 // verbatim, the offending byte's hex form, and names the
13630 // shell-history-substitution / RFC-3986-'unwise' / regex-
13631 // negation footgun explicitly so a `feira lint` run can render
13632 // the diagnostic without re-parsing.
13633 let d = dep_with_fonte(DepSource::Path {
13634 caminho: "../foo^bad^good".into(),
13635 });
13636 let rendered = d.validate().unwrap_err().to_string();
13637 assert!(
13638 rendered.contains("caixa-teia"),
13639 "diagnostic must name the offending dep: {rendered}",
13640 );
13641 assert!(
13642 rendered.contains("../foo^bad^good"),
13643 "diagnostic must quote the offending caminho verbatim: {rendered:?}",
13644 );
13645 assert!(
13646 rendered.contains("0x5e") || rendered.contains("0x5E"),
13647 "diagnostic must surface the offending byte hex: {rendered:?}",
13648 );
13649 assert!(
13650 rendered.contains("history-substitution") || rendered.contains("history substitution"),
13651 "diagnostic must name the shell-history-substitution footgun: {rendered:?}",
13652 );
13653 assert!(
13654 rendered.contains("unwise"),
13655 "diagnostic must reference the RFC-3986 'unwise' set vocabulary: {rendered:?}",
13656 );
13657 }
13658
13659 #[test]
13660 fn fonte_repo_empty_fires_before_pin_missing() {
13661 // Order pin: empty `:repo` is the more self-locating diagnostic
13662 // (every git source needs a repo; the pin discussion is
13663 // secondary), so it fires before the pin-missing arm even when
13664 // both are violated. Mirrors the
13665 // `nome_empty_takes_precedence_over_versao_invalid` ordering
13666 // discipline on the per-entry layer.
13667 let d = dep_with_fonte(DepSource::Git {
13668 repo: String::new(),
13669 tag: None,
13670 rev: None,
13671 branch: None,
13672 });
13673 let err = d.validate().unwrap_err();
13674 assert!(
13675 matches!(err, DepError::FonteRepoEmpty { .. }),
13676 "got {err:?}"
13677 );
13678 }
13679
13680 #[test]
13681 fn fonte_pin_missing_fires_before_pin_empty() {
13682 // Order pin: a fully-None pin set is structurally distinct from
13683 // a Some(empty) pin — the first surfaces as FontePinMissing
13684 // (no axis chosen), the second as FontePinEmpty (axis chosen
13685 // but value blank). Pin the disjoint relationship so a future
13686 // unification collapses to one variant only as a structural
13687 // decision.
13688 let d = dep_with_fonte(DepSource::Git {
13689 repo: "github:pleme-io/caixa-teia".into(),
13690 tag: None,
13691 rev: None,
13692 branch: None,
13693 });
13694 assert!(matches!(
13695 d.validate().unwrap_err(),
13696 DepError::FontePinMissing { .. }
13697 ));
13698 }
13699
13700 #[test]
13701 fn nome_empty_takes_precedence_over_fonte_invalid() {
13702 // Order pin: a per-entry diagnostic without a non-empty :nome
13703 // can't be self-locating, so :nome "" fires first even when
13704 // :fonte is also malformed. Mirrors
13705 // `nome_empty_takes_precedence_over_versao_invalid` on the
13706 // adjacent axis.
13707 let mut d = dep_with_fonte(DepSource::Git {
13708 repo: String::new(),
13709 tag: None,
13710 rev: None,
13711 branch: None,
13712 });
13713 d.nome = String::new();
13714 assert_eq!(d.validate().unwrap_err(), DepError::NomeEmpty);
13715 }
13716
13717 #[test]
13718 fn versao_invalid_takes_precedence_over_fonte_invalid() {
13719 // Order pin: the :versao parse-side diagnostic is narrower than
13720 // the :fonte shape diagnostic — a malformed :versao always names
13721 // the parser's reason, which is more actionable than the
13722 // :fonte gate's "the pins are wrong" wording. Pin the ordering
13723 // so a re-ordering surfaces here.
13724 let mut d = dep_with_fonte(DepSource::Git {
13725 repo: String::new(),
13726 tag: None,
13727 rev: None,
13728 branch: None,
13729 });
13730 d.versao = "v0.1".into();
13731 let err = d.validate().unwrap_err();
13732 assert!(
13733 matches!(err, DepError::VersaoInvalid { ref nome, .. } if nome == "caixa-teia"),
13734 "got {err:?}"
13735 );
13736 }
13737
13738 #[test]
13739 fn fonte_invalid_diagnostic_carries_offending_nome() {
13740 // The diagnostic-shape pin: every :fonte error variant names
13741 // the offending dep's :nome verbatim, so the author can grep
13742 // caixa.lisp for the `:nome "<n>"` block and fix it in one
13743 // edit. Cover all seven variants so a future variant addition
13744 // forces a parallel diagnostic-shape decision.
13745 for (case, fonte) in [
13746 (
13747 "repo-empty",
13748 DepSource::Git {
13749 repo: String::new(),
13750 tag: Some("v1".into()),
13751 rev: None,
13752 branch: None,
13753 },
13754 ),
13755 (
13756 "repo-shape",
13757 DepSource::Git {
13758 repo: "github:p/x ".into(),
13759 tag: Some("v1".into()),
13760 rev: None,
13761 branch: None,
13762 },
13763 ),
13764 (
13765 "pin-missing",
13766 DepSource::Git {
13767 repo: "github:p/x".into(),
13768 tag: None,
13769 rev: None,
13770 branch: None,
13771 },
13772 ),
13773 (
13774 "pin-ambiguous",
13775 DepSource::Git {
13776 repo: "github:p/x".into(),
13777 tag: Some("v1".into()),
13778 rev: None,
13779 branch: Some("main".into()),
13780 },
13781 ),
13782 (
13783 "pin-empty",
13784 DepSource::Git {
13785 repo: "github:p/x".into(),
13786 tag: Some(String::new()),
13787 rev: None,
13788 branch: None,
13789 },
13790 ),
13791 (
13792 "caminho-empty",
13793 DepSource::Path {
13794 caminho: String::new(),
13795 },
13796 ),
13797 (
13798 "caminho-absolute",
13799 DepSource::Path {
13800 caminho: "/home/me/work/caixa-teia".into(),
13801 },
13802 ),
13803 ] {
13804 let d = dep_with_fonte(fonte);
13805 let msg = d
13806 .validate()
13807 .expect_err(&format!("{case}: expected fonte error"))
13808 .to_string();
13809 assert!(
13810 msg.contains("\"caixa-teia\""),
13811 "{case}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
13812 );
13813 }
13814 }
13815
13816 // -- :tag / :branch value-shape gate ----------------------------------
13817
13818 #[test]
13819 fn validate_rejects_git_fonte_with_tag_carrying_trailing_space() {
13820 // The canonical paste-from-doc footgun on `:tag` — author
13821 // copies `"v0.1.0 "` (trailing space) out of a release-notes
13822 // paragraph. Until this gate landed the empty-pin arm passed
13823 // (the string isn't empty), the resolver issued
13824 // `git fetch <remote> tag 'v0.1.0 '`, and the failure
13825 // surfaced at clone time with a quoting-confused git error
13826 // far from the source caixa.lisp. The new gate moves the
13827 // check to caixa-build time and names the offending dep +
13828 // pin + value verbatim.
13829 let d = dep_with_fonte(DepSource::Git {
13830 repo: "github:pleme-io/caixa-teia".into(),
13831 tag: Some("v0.1.0 ".into()),
13832 rev: None,
13833 branch: None,
13834 });
13835 let err = d.validate().unwrap_err();
13836 let DepError::FontePinShape {
13837 nome,
13838 pin,
13839 value,
13840 reason,
13841 } = err
13842 else {
13843 panic!("expected FontePinShape, got other variant");
13844 };
13845 assert_eq!(nome, "caixa-teia");
13846 assert_eq!(pin, ":tag");
13847 assert_eq!(value, "v0.1.0 ");
13848 assert!(
13849 reason.contains("whitespace"),
13850 "reason must surface the whitespace arm, got {reason:?}"
13851 );
13852 }
13853
13854 #[test]
13855 fn validate_rejects_git_fonte_with_tag_carrying_lock_suffix() {
13856 // The `.lock` suffix is git's atomic-rename guard for
13857 // in-flight ref updates — a refname ending in `.lock` is
13858 // unwritable on disk. Pinned separately from the whitespace
13859 // arm so a future relaxation that admits one but not the
13860 // other surfaces here.
13861 let d = dep_with_fonte(DepSource::Git {
13862 repo: "github:pleme-io/caixa-teia".into(),
13863 tag: Some("v0.1.0.lock".into()),
13864 rev: None,
13865 branch: None,
13866 });
13867 let err = d.validate().unwrap_err();
13868 let DepError::FontePinShape {
13869 pin, value, reason, ..
13870 } = err
13871 else {
13872 panic!("expected FontePinShape, got other variant");
13873 };
13874 assert_eq!(pin, ":tag");
13875 assert_eq!(value, "v0.1.0.lock");
13876 assert!(
13877 reason.contains(".lock"),
13878 "reason must surface the .lock arm, got {reason:?}"
13879 );
13880 }
13881
13882 #[test]
13883 fn validate_rejects_git_fonte_with_branch_carrying_embedded_space() {
13884 // The canonical "branch name with spaces" footgun (`feature
13885 // foo`, `release branch`) — git's refname parser rejects raw
13886 // whitespace, and the failure surfaces at `git checkout
13887 // 'feature foo'` time with a quoting-confused error far from
13888 // the source caixa.lisp. Pinned on the `:branch` axis so the
13889 // gate-applies-to-both-:tag-and-:branch contract is a build-
13890 // error to relax.
13891 let d = dep_with_fonte(DepSource::Git {
13892 repo: "github:pleme-io/caixa-teia".into(),
13893 tag: None,
13894 rev: None,
13895 branch: Some("feature/foo bar".into()),
13896 });
13897 let err = d.validate().unwrap_err();
13898 let DepError::FontePinShape {
13899 pin, value, reason, ..
13900 } = err
13901 else {
13902 panic!("expected FontePinShape, got other variant");
13903 };
13904 assert_eq!(pin, ":branch");
13905 assert_eq!(value, "feature/foo bar");
13906 assert!(
13907 reason.contains("whitespace"),
13908 "reason must surface the whitespace arm, got {reason:?}"
13909 );
13910 }
13911
13912 #[test]
13913 fn validate_rejects_git_fonte_with_branch_carrying_qualified_prefix() {
13914 // The `refs/heads/main` shape — the canonical "I copied the
13915 // fully-qualified ref out of `git show-ref` instead of the
13916 // leaf" footgun. The caixa-resolver prepends `refs/heads/`
13917 // at clone time, so this resolves to a literal ref named
13918 // `refs/heads/refs/heads/main` on disk; the silent double-
13919 // prefix is the load-bearing reason to gate at validate.
13920 // The diagnostic must enumerate the leaf the author probably
13921 // meant (`"main"`) so the fix is one edit.
13922 let d = dep_with_fonte(DepSource::Git {
13923 repo: "github:pleme-io/caixa-teia".into(),
13924 tag: None,
13925 rev: None,
13926 branch: Some("refs/heads/main".into()),
13927 });
13928 let err = d.validate().unwrap_err();
13929 let DepError::FontePinShape {
13930 pin, value, reason, ..
13931 } = err
13932 else {
13933 panic!("expected FontePinShape, got other variant");
13934 };
13935 assert_eq!(pin, ":branch");
13936 assert_eq!(value, "refs/heads/main");
13937 assert!(
13938 reason.contains("fully-qualified"),
13939 "reason must surface the qualified-prefix arm, got {reason:?}"
13940 );
13941 assert!(
13942 reason.contains("\"main\""),
13943 "reason must quote the leaf the author probably meant, got {reason:?}"
13944 );
13945 }
13946
13947 #[test]
13948 fn validate_rejects_git_fonte_with_tag_carrying_qualified_prefix() {
13949 // Sibling arm of the qualified-prefix gate on the `:tag`
13950 // axis (`refs/tags/v0.1.0` — same `git show-ref` output-leak
13951 // footgun). Pinned separately so a future relaxation that
13952 // only catches the `:branch` arm surfaces here.
13953 let d = dep_with_fonte(DepSource::Git {
13954 repo: "github:pleme-io/caixa-teia".into(),
13955 tag: Some("refs/tags/v0.1.0".into()),
13956 rev: None,
13957 branch: None,
13958 });
13959 let err = d.validate().unwrap_err();
13960 let DepError::FontePinShape {
13961 pin, value, reason, ..
13962 } = err
13963 else {
13964 panic!("expected FontePinShape, got other variant");
13965 };
13966 assert_eq!(pin, ":tag");
13967 assert_eq!(value, "refs/tags/v0.1.0");
13968 assert!(
13969 reason.contains("fully-qualified"),
13970 "reason must surface the qualified-prefix arm, got {reason:?}"
13971 );
13972 assert!(
13973 reason.contains("\"v0.1.0\""),
13974 "reason must quote the leaf the author probably meant, got {reason:?}"
13975 );
13976 }
13977
13978 #[test]
13979 fn validate_rejects_git_fonte_with_branch_named_at() {
13980 // The bare `@` is git's alias for `HEAD`; a `:branch "@"` is
13981 // unsourceable. Pinned so a future relaxation that admits
13982 // any single-character refname surfaces here.
13983 let d = dep_with_fonte(DepSource::Git {
13984 repo: "github:pleme-io/caixa-teia".into(),
13985 tag: None,
13986 rev: None,
13987 branch: Some("@".into()),
13988 });
13989 let err = d.validate().unwrap_err();
13990 let DepError::FontePinShape { pin, value, .. } = err else {
13991 panic!("expected FontePinShape, got other variant");
13992 };
13993 assert_eq!(pin, ":branch");
13994 assert_eq!(value, "@");
13995 }
13996
13997 #[test]
13998 fn validate_rejects_git_fonte_with_tag_carrying_double_dot() {
13999 // Git's `<rev1>..<rev2>` range grammar reserves `..` —
14000 // a `:tag "../escape"` (path-traversal-shaped slug) silently
14001 // passes parse and surfaces as a refname-parse error or, on
14002 // older git, a literal `../escape` checkout that escapes the
14003 // refs/ directory tree. Pinned separately from the
14004 // qualified-prefix arm so a future relaxation that catches
14005 // one but not the other surfaces here.
14006 let d = dep_with_fonte(DepSource::Git {
14007 repo: "github:pleme-io/caixa-teia".into(),
14008 tag: Some("../escape".into()),
14009 rev: None,
14010 branch: None,
14011 });
14012 let err = d.validate().unwrap_err();
14013 let DepError::FontePinShape { pin, value, .. } = err else {
14014 panic!("expected FontePinShape, got other variant");
14015 };
14016 assert_eq!(pin, ":tag");
14017 assert_eq!(value, "../escape");
14018 }
14019
14020 #[test]
14021 fn validate_accepts_git_fonte_with_hierarchical_branch() {
14022 // The positive-control pin: hierarchical refnames with one or
14023 // more `/` separators (the `feature/foo` / `user/jdoe/feat`
14024 // canonical idiom) round-trip through the gate. Pinned
14025 // separately from the leaf-`"main"` positive control so a
14026 // future tightening that rejects all multi-component refnames
14027 // surfaces here.
14028 let d = dep_with_fonte(DepSource::Git {
14029 repo: "github:pleme-io/caixa-teia".into(),
14030 tag: None,
14031 rev: None,
14032 branch: Some("feature/checkout-rewrite".into()),
14033 });
14034 d.validate().unwrap();
14035 }
14036
14037 #[test]
14038 fn validate_accepts_git_fonte_with_prerelease_tag() {
14039 // The positive-control pin: semver pre-release shape
14040 // (`v0.1.0-alpha.1`) — the in-component dot is allowed
14041 // (only consecutive `..` and trailing `.` are rejected), the
14042 // mid-component hyphen is allowed. Pinned separately from
14043 // the bare-`"v0.1.0"` positive control so a future tightening
14044 // that rejects pre-release tags surfaces here.
14045 let d = dep_with_fonte(DepSource::Git {
14046 repo: "github:pleme-io/caixa-teia".into(),
14047 tag: Some("v0.1.0-alpha.1".into()),
14048 rev: None,
14049 branch: None,
14050 });
14051 d.validate().unwrap();
14052 }
14053
14054 #[test]
14055 fn validate_rejects_git_fonte_with_rev_carrying_refname_unfriendly_value() {
14056 // The `:rev` axis is routed through `crate::render::is_git_oid`
14057 // (a SHA's character set is `[0-9a-f]`, not a refname's), so a
14058 // value with refname-shape punctuation (here, a `:` mid-string
14059 // — would be a refname violation under `is_git_ref_name` too)
14060 // is rejected at the OID-shape gate. The two predicates
14061 // partition the `:fonte` pin axes structurally: an `:rev` value
14062 // that's a valid refname (`:rev "main"`, `:rev "v0.1.0"`) is
14063 // *still* rejected here because every refname character outside
14064 // `[0-9a-f]` fails the OID gate. Same shape as
14065 // `fonte_pin_shape_diagnostic_carries_offending_nome_pin_value`
14066 // on the refname-shaped axes — the diagnostic names the
14067 // offending dep + pin + value verbatim. The flip-from-accept
14068 // case the prior `:tag`/`:branch` gate left as a "future axis"
14069 // (e70d213) — now landed.
14070 let d = dep_with_fonte(DepSource::Git {
14071 repo: "github:pleme-io/caixa-teia".into(),
14072 tag: None,
14073 rev: Some("c0ffee:notarefname".into()),
14074 branch: None,
14075 });
14076 let err = d.validate().unwrap_err();
14077 let DepError::FontePinShape {
14078 nome,
14079 pin,
14080 value,
14081 reason,
14082 } = err
14083 else {
14084 panic!("expected FontePinShape, got other variant");
14085 };
14086 assert_eq!(nome, "caixa-teia");
14087 assert_eq!(pin, ":rev");
14088 assert_eq!(value, "c0ffee:notarefname");
14089 assert!(
14090 !reason.is_empty(),
14091 "FontePinShape `reason` must carry the predicate's wording verbatim"
14092 );
14093 }
14094
14095 #[test]
14096 fn validate_accepts_git_fonte_with_rev_full_sha1() {
14097 // The positive-control pin on the SHA-1 OID width: exactly 40
14098 // lowercase hex characters — the canonical `git rev-parse HEAD`
14099 // emission on a SHA-1-hashed repository (the default on every
14100 // pre-2.42 git and the canonical pleme-io substrate hash).
14101 // Pinned separately from the SHA-256 positive control so a
14102 // future tightening that only admits one width surfaces here.
14103 let d = dep_with_fonte(DepSource::Git {
14104 repo: "github:pleme-io/caixa-teia".into(),
14105 tag: None,
14106 rev: Some("0123456789abcdef0123456789abcdef01234567".into()),
14107 branch: None,
14108 });
14109 d.validate().unwrap();
14110 }
14111
14112 #[test]
14113 fn validate_accepts_git_fonte_with_rev_full_sha256() {
14114 // The positive-control pin on the SHA-256 OID width: exactly
14115 // 64 lowercase hex characters — `git`'s
14116 // `extensions.objectFormat = sha256` emission (GA since Git
14117 // 2.42 / Oct 2023). The substrate admits either canonical
14118 // width so an `:rev` authored against a SHA-256-hashed
14119 // upstream round-trips through the gate without per-repo
14120 // configuration. Pinned separately from the SHA-1 positive
14121 // control so a future tightening that drops one width surfaces
14122 // here as a structural decision.
14123 let d = dep_with_fonte(DepSource::Git {
14124 repo: "github:pleme-io/caixa-teia".into(),
14125 tag: None,
14126 rev: Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into()),
14127 branch: None,
14128 });
14129 d.validate().unwrap();
14130 }
14131
14132 #[test]
14133 fn validate_rejects_git_fonte_with_rev_abbreviated_prefix() {
14134 // The canonical `git log --short` / `git rev-parse --short HEAD`
14135 // paste-from-release-notes footgun: a 7-char prefix (git's
14136 // default `core.abbrev`) silently passes string emptiness
14137 // checks and resolves to one commit today, but becomes ambiguous
14138 // tomorrow as the repo grows. Until this gate landed the empty-
14139 // pin arm passed (the string isn't empty) and the resolver
14140 // accepted the prefix through git's separate prefix-lookup pass
14141 // — defeating the reproducibility contract `:rev` carries vs.
14142 // `:tag` / `:branch`. The new gate moves the check to caixa-
14143 // build time and names the offending dep + pin + value verbatim.
14144 let d = dep_with_fonte(DepSource::Git {
14145 repo: "github:pleme-io/caixa-teia".into(),
14146 tag: None,
14147 rev: Some("c0ffee0".into()),
14148 branch: None,
14149 });
14150 let err = d.validate().unwrap_err();
14151 let DepError::FontePinShape {
14152 pin, value, reason, ..
14153 } = err
14154 else {
14155 panic!("expected FontePinShape, got other variant");
14156 };
14157 assert_eq!(pin, ":rev");
14158 assert_eq!(value, "c0ffee0");
14159 assert!(
14160 reason.contains("abbreviated") || reason.contains("ambiguous"),
14161 "reason must surface the abbreviation arm, got {reason:?}"
14162 );
14163 }
14164
14165 #[test]
14166 fn validate_rejects_git_fonte_with_rev_uppercase_hex() {
14167 // The canonical "I pasted the SHA in uppercase" footgun: `git
14168 // porcelain` emits OIDs lowercase exclusively, so an uppercase-
14169 // bearing `:rev` round-trips inconsistently across the
14170 // resolver's `git fetch <remote> <:rev>` ↔ `git rev-parse HEAD`
14171 // equality-check pipeline and fails the lacre's content-
14172 // addressing probe with a confusing case-only diff. Pinned
14173 // separately from the non-hex arm so a future relaxation that
14174 // admits one but not the other surfaces here.
14175 let d = dep_with_fonte(DepSource::Git {
14176 repo: "github:pleme-io/caixa-teia".into(),
14177 tag: None,
14178 rev: Some("DEADBEEFCAFEBABE0123456789ABCDEF01234567".into()),
14179 branch: None,
14180 });
14181 let err = d.validate().unwrap_err();
14182 let DepError::FontePinShape {
14183 pin, value, reason, ..
14184 } = err
14185 else {
14186 panic!("expected FontePinShape, got other variant");
14187 };
14188 assert_eq!(pin, ":rev");
14189 assert_eq!(value, "DEADBEEFCAFEBABE0123456789ABCDEF01234567");
14190 assert!(
14191 reason.contains("uppercase"),
14192 "reason must surface the uppercase arm, got {reason:?}"
14193 );
14194 }
14195
14196 #[test]
14197 fn validate_rejects_git_fonte_with_rev_refname_value() {
14198 // The cross-axis mis-slot footgun: `:rev "main"` — the author
14199 // conflated `:rev` (hex commit ID, immutable) and `:branch`
14200 // (mutable ref pointing at whatever HEAD is today). Until this
14201 // gate landed the resolver silently dispatched on the value
14202 // shape ("`main` doesn't look like a SHA, fall back to
14203 // refname"), defeating the `:rev` reproducibility contract.
14204 // The new gate rejects every non-hex value on the `:rev` axis,
14205 // so the `:rev`/`:branch` boundary is structurally enforced —
14206 // a refname in the `:rev` slot is a build error, not a
14207 // resolver-time silent reinterpretation.
14208 let d = dep_with_fonte(DepSource::Git {
14209 repo: "github:pleme-io/caixa-teia".into(),
14210 tag: None,
14211 rev: Some("main".into()),
14212 branch: None,
14213 });
14214 let err = d.validate().unwrap_err();
14215 let DepError::FontePinShape {
14216 pin, value, reason, ..
14217 } = err
14218 else {
14219 panic!("expected FontePinShape, got other variant");
14220 };
14221 assert_eq!(pin, ":rev");
14222 assert_eq!(value, "main");
14223 // 4 chars `main` fails the length arm before the character arm,
14224 // so the diagnostic surfaces the abbreviation wording (same
14225 // path the `c0ffee0` 7-char fixture lands on); the structural
14226 // assertion is just that the `:rev "main"` value is rejected.
14227 assert!(
14228 !reason.is_empty(),
14229 "FontePinShape reason must be non-empty for refname-shaped :rev"
14230 );
14231 }
14232
14233 #[test]
14234 fn validate_rejects_git_fonte_with_rev_tag_shaped_value() {
14235 // Sibling cross-axis mis-slot: `:rev "v0.1.0"` — the author
14236 // conflated `:rev` and `:tag`. Pinned separately from the
14237 // `:rev "main"` (`:branch` mis-slot) arm so a future relaxation
14238 // that catches one but not the other surfaces here. The
14239 // length arm fires first (6 chars ≠ 40 ≠ 64); the structural
14240 // assertion is just that the cross-axis mis-slot is a build
14241 // error, regardless of which sub-arm surfaces the diagnostic
14242 // (`is_git_oid` rejects at the first violation; longer
14243 // tag-shape values would hit the non-hex arm instead).
14244 let d = dep_with_fonte(DepSource::Git {
14245 repo: "github:pleme-io/caixa-teia".into(),
14246 tag: None,
14247 rev: Some("v0.1.0".into()),
14248 branch: None,
14249 });
14250 let err = d.validate().unwrap_err();
14251 let DepError::FontePinShape {
14252 pin, value, reason, ..
14253 } = err
14254 else {
14255 panic!("expected FontePinShape, got other variant");
14256 };
14257 assert_eq!(pin, ":rev");
14258 assert_eq!(value, "v0.1.0");
14259 assert!(
14260 !reason.is_empty(),
14261 "FontePinShape reason must be non-empty for tag-shaped :rev"
14262 );
14263 }
14264
14265 #[test]
14266 fn validate_rejects_git_fonte_with_rev_too_long() {
14267 // Boundary case on the upper end: 41 hex chars — one past the
14268 // SHA-1 width, well below the SHA-256 width. Pin so a future
14269 // relaxation that admits "long enough to be a SHA" without
14270 // matching either canonical width surfaces here. The diagnostic
14271 // names the offending length verbatim so the author's grep
14272 // target is unambiguous (either trim one char or paste the
14273 // full SHA-256).
14274 let too_long: String = "0".repeat(41);
14275 let d = dep_with_fonte(DepSource::Git {
14276 repo: "github:pleme-io/caixa-teia".into(),
14277 tag: None,
14278 rev: Some(too_long.clone()),
14279 branch: None,
14280 });
14281 let err = d.validate().unwrap_err();
14282 let DepError::FontePinShape {
14283 pin, value, reason, ..
14284 } = err
14285 else {
14286 panic!("expected FontePinShape, got other variant");
14287 };
14288 assert_eq!(pin, ":rev");
14289 assert_eq!(value, too_long);
14290 assert!(
14291 reason.contains("41"),
14292 "reason must surface the offending length verbatim, got {reason:?}"
14293 );
14294 }
14295
14296 #[test]
14297 fn validate_rejects_git_fonte_with_rev_carrying_whitespace() {
14298 // The canonical paste-from-doc footgun on `:rev` — author
14299 // copies `"deadbeefcafe…0123 "` (trailing space) out of a
14300 // commit-message paragraph. Until this gate landed the empty-
14301 // pin arm passed (the string isn't empty), the resolver issued
14302 // `git fetch <remote> 'deadbeef… '` and the failure surfaced at
14303 // clone time with a quoting-confused git error far from the
14304 // source caixa.lisp. The new gate moves the check to caixa-
14305 // build time. Length is 41 (40 hex + space) so the length arm
14306 // fires first — pinned separately from the pure-length arm to
14307 // ensure the diagnostic surfaces *some* parser wording, not
14308 // silently pass through.
14309 let with_space = "0123456789abcdef0123456789abcdef01234567 ".to_string();
14310 let d = dep_with_fonte(DepSource::Git {
14311 repo: "github:pleme-io/caixa-teia".into(),
14312 tag: None,
14313 rev: Some(with_space.clone()),
14314 branch: None,
14315 });
14316 let err = d.validate().unwrap_err();
14317 let DepError::FontePinShape {
14318 pin, value, reason, ..
14319 } = err
14320 else {
14321 panic!("expected FontePinShape, got other variant");
14322 };
14323 assert_eq!(pin, ":rev");
14324 assert_eq!(value, with_space);
14325 assert!(
14326 !reason.is_empty(),
14327 "FontePinShape reason must be non-empty for whitespace-bearing :rev"
14328 );
14329 }
14330
14331 #[test]
14332 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value_for_rev() {
14333 // Diagnostic-shape pin on the `:rev` axis: every FontePinShape
14334 // variant on this axis names the offending dep's `:nome` + the
14335 // `:rev` axis + the offending value verbatim, so the author's
14336 // grep target is the literal `:rev "<value>"` block in
14337 // caixa.lisp. Sibling of the `fonte_pin_shape_diagnostic_
14338 // carries_offending_nome_pin_value` test on the refname-shaped
14339 // (`:tag` / `:branch`) axes.
14340 let d = dep_with_fonte(DepSource::Git {
14341 repo: "github:p/x".into(),
14342 tag: None,
14343 rev: Some("not-a-sha".into()),
14344 branch: None,
14345 });
14346 let msg = d
14347 .validate()
14348 .expect_err(":rev: expected FontePinShape")
14349 .to_string();
14350 assert!(
14351 msg.contains("\"caixa-teia\""),
14352 ":rev: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14353 );
14354 assert!(
14355 msg.contains(":rev"),
14356 ":rev: diagnostic must name the offending pin axis, got {msg:?}"
14357 );
14358 assert!(
14359 msg.contains("not-a-sha"),
14360 ":rev: diagnostic must quote the offending value verbatim, got {msg:?}"
14361 );
14362 }
14363
14364 #[test]
14365 fn fonte_pin_empty_fires_before_pin_shape() {
14366 // Order pin: a `Some("")` `:tag` is the more self-locating
14367 // diagnostic (the author chose an axis but left it blank;
14368 // grep is unambiguous), so it fires before the shape gate
14369 // even when both arms would match. Pinned so a future
14370 // reordering surfaces here. Mirrors the
14371 // `fonte_repo_empty_fires_before_pin_missing` ordering
14372 // discipline on the peer per-axis arms.
14373 let d = dep_with_fonte(DepSource::Git {
14374 repo: "github:pleme-io/caixa-teia".into(),
14375 tag: Some(String::new()),
14376 rev: None,
14377 branch: None,
14378 });
14379 assert!(matches!(
14380 d.validate().unwrap_err(),
14381 DepError::FontePinEmpty { ref pin, .. } if pin == ":tag"
14382 ));
14383 }
14384
14385 #[test]
14386 fn fonte_pin_shape_fires_after_repo_empty() {
14387 // Order pin: `:repo ""` is the more self-locating axis
14388 // (every git source needs a repo; the per-pin shape gate is
14389 // secondary), so the repo-empty arm fires before the
14390 // per-pin shape arm even when both are violated. Pinned so
14391 // a future reordering surfaces here. Mirrors
14392 // `fonte_repo_empty_fires_before_pin_missing` on the
14393 // adjacent axis pair.
14394 let d = dep_with_fonte(DepSource::Git {
14395 repo: String::new(),
14396 tag: Some("v0.1.0 ".into()),
14397 rev: None,
14398 branch: None,
14399 });
14400 assert!(matches!(
14401 d.validate().unwrap_err(),
14402 DepError::FonteRepoEmpty { .. }
14403 ));
14404 }
14405
14406 #[test]
14407 fn fonte_pin_shape_diagnostic_carries_offending_nome_pin_value() {
14408 // Diagnostic-shape pin across both refname-shaped axes
14409 // (`:tag` + `:branch`): every `FontePinShape` variant names
14410 // the offending dep's `:nome` + the offending pin axis + the
14411 // offending value verbatim, so the author's grep target is
14412 // unambiguous (the literal `:tag "<value>"` / `:branch
14413 // "<value>"` lands in caixa.lisp with quotes). Cover both
14414 // pin axes so a future variant addition forces a parallel
14415 // diagnostic-shape decision.
14416 for (pin_label, fonte) in [
14417 (
14418 ":tag",
14419 DepSource::Git {
14420 repo: "github:p/x".into(),
14421 tag: Some("v0.1.0~1".into()),
14422 rev: None,
14423 branch: None,
14424 },
14425 ),
14426 (
14427 ":branch",
14428 DepSource::Git {
14429 repo: "github:p/x".into(),
14430 tag: None,
14431 rev: None,
14432 branch: Some("feature/foo*".into()),
14433 },
14434 ),
14435 ] {
14436 let d = dep_with_fonte(fonte);
14437 let msg = d
14438 .validate()
14439 .expect_err(&format!("{pin_label}: expected FontePinShape"))
14440 .to_string();
14441 assert!(
14442 msg.contains("\"caixa-teia\""),
14443 "{pin_label}: diagnostic must quote the offending :nome verbatim, got {msg:?}"
14444 );
14445 assert!(
14446 msg.contains(pin_label),
14447 "{pin_label}: diagnostic must name the offending pin axis, got {msg:?}"
14448 );
14449 }
14450 }
14451
14452 #[test]
14453 fn git_source_json_round_trip() {
14454 let src = DepSource::Git {
14455 repo: "github:pleme-io/caixa-teia".into(),
14456 tag: Some("v0.1.0".into()),
14457 rev: None,
14458 branch: None,
14459 };
14460 let s = serde_json::to_string(&src).unwrap();
14461 assert!(s.contains(&format!(
14462 r#""{tipo}":"{git}""#,
14463 tipo = crate::render::DEP_SOURCE_KEY_TIPO,
14464 git = crate::render::DEP_SOURCE_TIPO_GIT,
14465 )));
14466 assert!(s.contains(r#""repo":"github:pleme-io/caixa-teia""#));
14467 assert!(s.contains(r#""tag":"v0.1.0""#));
14468 assert!(!s.contains("rev"));
14469 assert!(!s.contains("branch"));
14470 let round: DepSource = serde_json::from_str(&s).unwrap();
14471 assert_eq!(round, src);
14472 }
14473
14474 // ── DEP_SOURCE_{KEY_TIPO,TIPO_GIT,TIPO_PATH} drift-detection ────────
14475 //
14476 // The `#[serde(tag = "tipo", rename_all = "lowercase")]` derive
14477 // attribute on [`DepSource`] pins three load-bearing byte-sequences
14478 // that flow into every serialized `Dep.fonte` block: the outer
14479 // discriminator-key `"tipo"` the `tag = "tipo"` attribute names, and
14480 // the two admitted variant-tag values `"git"` / `"path"` the
14481 // `rename_all = "lowercase"` attribute pins as the discriminator's
14482 // closed-set arms. The three pin tests below round-trip a
14483 // fully-populated variant of each arm through
14484 // [`serde_json::to_value`] and assert each canonical byte-sequence
14485 // appears at its axis — pins a hypothetical future
14486 // `tag = "type"` / `tag = "source_type"` typo, a `rename_all`
14487 // rebrand (`"UPPERCASE"` / `"snake_case"` / `"kebab-case"`), or a
14488 // Rust-side variant rename (`Git` → `Repository`, `Path` → `Local`)
14489 // at build time rather than at fetch time when the resolver's
14490 // `Dep.fonte` dispatch silently fails to match on the drifted
14491 // discriminator. Same "serialize-and-check" discipline the peer
14492 // `M2_LIMITS_KEY_*`, `M2_BEHAVIOR_KEY_ON_*`, `SUPERVISOR_KEY_*`,
14493 // and `MEMBRO_KEY_*` drift-detection pins carry — extended here
14494 // to the last `#[serde(tag = ..., rename_all = ...)]` discriminator
14495 // family in caixa-core lacking a lifted peer.
14496
14497 #[test]
14498 fn dep_source_git_serde_keys_match_lifted_dep_source_key_consts() {
14499 // Fail-before-pass-after: a future `tag = "type"` at the derive
14500 // attribute would serialize under `"type":"git"`, and this test
14501 // would trip because `"tipo"` no longer appears at the emitted
14502 // discriminator key. A future `rename_all = "kebab-case"` /
14503 // `"snake_case"` (both no-ops on `Git` since it lacks internal
14504 // word boundaries) is caught by the sibling
14505 // `dep_source_path_serde_keys_match_lifted_dep_source_key_consts`
14506 // pin below (Path has no internal boundary either but the pair
14507 // catches any per-arm inconsistency). A future variant rename
14508 // `Git` → `Repository` would emit `"tipo":"repository"` and
14509 // trip this pin.
14510 let src = DepSource::Git {
14511 repo: "github:pleme-io/caixa-teia".into(),
14512 tag: Some("v0.1.0".into()),
14513 rev: None,
14514 branch: None,
14515 };
14516 let json = serde_json::to_value(&src).unwrap();
14517 let obj = json.as_object().expect("Git serializes as a JSON object");
14518 assert_eq!(
14519 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14520 .and_then(serde_json::Value::as_str),
14521 Some(crate::render::DEP_SOURCE_TIPO_GIT),
14522 "DepSource::Git must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14523 with value DEP_SOURCE_TIPO_GIT — attribute drift or variant rename \
14524 detected in {json}"
14525 );
14526 }
14527
14528 #[test]
14529 fn dep_source_path_serde_keys_match_lifted_dep_source_key_consts() {
14530 // Fail-before-pass-after: a future variant rename `Path` →
14531 // `Local` / `Filesystem` would emit `"tipo":"local"` and trip
14532 // this pin. A per-consumer disambiguation as the `defcaixa`
14533 // macro stabilizes ("caminho" → "path" for English-uniformity)
14534 // is scoped to the inner field key, not the discriminator; this
14535 // pin is orthogonal to that and catches only the outer
14536 // discriminator drift.
14537 let src = DepSource::Path {
14538 caminho: "../caixa-teia".into(),
14539 };
14540 let json = serde_json::to_value(&src).unwrap();
14541 let obj = json.as_object().expect("Path serializes as a JSON object");
14542 assert_eq!(
14543 obj.get(crate::render::DEP_SOURCE_KEY_TIPO)
14544 .and_then(serde_json::Value::as_str),
14545 Some(crate::render::DEP_SOURCE_TIPO_PATH),
14546 "DepSource::Path must serialize the tipo discriminator at DEP_SOURCE_KEY_TIPO \
14547 with value DEP_SOURCE_TIPO_PATH — attribute drift or variant rename \
14548 detected in {json}"
14549 );
14550 }
14551
14552 #[test]
14553 fn dep_source_key_consts_are_pairwise_distinct() {
14554 // Cross-axis collapse detector: a hypothetical future edit that
14555 // accidentally set two of the three consts to the same byte
14556 // (`DEP_SOURCE_TIPO_GIT = "path"` typo matching a peer arm) would
14557 // pass every per-arm serialize pin above but silently collapse
14558 // the discriminator's closed-set arms onto one another; this pin
14559 // catches the collapse at build time.
14560 assert_ne!(
14561 crate::render::DEP_SOURCE_KEY_TIPO,
14562 crate::render::DEP_SOURCE_TIPO_GIT,
14563 );
14564 assert_ne!(
14565 crate::render::DEP_SOURCE_KEY_TIPO,
14566 crate::render::DEP_SOURCE_TIPO_PATH,
14567 );
14568 assert_ne!(
14569 crate::render::DEP_SOURCE_TIPO_GIT,
14570 crate::render::DEP_SOURCE_TIPO_PATH,
14571 );
14572 }
14573
14574 #[test]
14575 fn dep_source_tipo_variant_consts_are_ascii_lowercase_shape() {
14576 // Shape pin against `rename_all` drift: the two variant-tag
14577 // consts must be ASCII-lowercase-only to match the
14578 // `rename_all = "lowercase"` attribute the derive uses; a future
14579 // rebrand to `"UPPERCASE"` / `"PascalCase"` at the attribute
14580 // would emit `"GIT"` / `"Git"` instead and trip this pin.
14581 for (label, s) in [
14582 ("DEP_SOURCE_TIPO_GIT", crate::render::DEP_SOURCE_TIPO_GIT),
14583 ("DEP_SOURCE_TIPO_PATH", crate::render::DEP_SOURCE_TIPO_PATH),
14584 ] {
14585 assert!(!s.is_empty(), "{label} must not be empty");
14586 assert!(
14587 s.bytes().all(|b| b.is_ascii_lowercase()),
14588 "{label} must be ASCII-lowercase-only (matching \
14589 rename_all = \"lowercase\"), got {s:?}",
14590 );
14591 }
14592 }
14593
14594 // ── per-entry :caracteristicas set-not-multiset gate ────────────
14595 //
14596 // Every Vec-keyed-by-name authoring surface on the typed Caixa
14597 // surface that identifies its entries by a name field now uniformly
14598 // closes the set-not-multiset discipline at build time (cite
14599 // `validate_caracteristicas`'s peer-axis enumeration). The
14600 // `:caracteristicas` axis is per-`Dep`: the feature-toggle slot is
14601 // set-shaped (a feature is either enabled or not — there is no
14602 // `feature × 2` semantic), so two entries naming the same feature
14603 // are a redundant declaration the caixa-resolver's lacre pipeline
14604 // would silently dedup at resolve time. The empty-feature arm
14605 // closes the parallel "operationally-meaningless value" axis on
14606 // the same slot. Same linear-walk + `HashSet` + first-collision
14607 // shape every peer set gate uses; same empty-first cascade every
14608 // peer per-entry shape + duplicate gate uses (the empty-feature
14609 // axis is the more-actionable defect since two `""` entries would
14610 // both report `caracteristica: ""` under a duplicate-first
14611 // ordering, with no way to distinguish the offending site).
14612
14613 fn dep_with_features(features: &[&str]) -> Dep {
14614 Dep {
14615 nome: "caixa-teia".into(),
14616 versao: "^0.1".into(),
14617 fonte: None,
14618 opcional: false,
14619 caracteristicas: features.iter().map(|s| (*s).into()).collect(),
14620 }
14621 }
14622
14623 #[test]
14624 fn validate_rejects_empty_caracteristica() {
14625 // Fail-before-pass-after pin: every pre-gate codebase accepted
14626 // `(:caracteristicas (""))` cleanly (the `Vec<String>` field
14627 // imposed no per-entry shape contract), the dep validated, and
14628 // the empty feature would have reached the future caixa-resolver
14629 // lacre pipeline as a no-op feature enable — silently dropping
14630 // the author's intent far from the source `caixa.lisp`. The new
14631 // gate surfaces the structural defect at the typed-validate
14632 // surface with a self-locating diagnostic naming the offending
14633 // dep's `:nome`.
14634 let d = dep_with_features(&[""]);
14635 assert!(
14636 matches!(d.validate().unwrap_err(), DepError::CaracteristicaEmpty { ref nome } if nome == "caixa-teia"),
14637 "expected CaracteristicaEmpty, got {:?}",
14638 d.validate(),
14639 );
14640 }
14641
14642 #[test]
14643 fn validate_rejects_duplicate_caracteristica() {
14644 // Fail-before-pass-after pin on the set-not-multiset arm: the
14645 // feature-toggle slot is set-shaped, so `(:caracteristicas
14646 // ("http" "http"))` is a redundant declaration the lacre
14647 // pipeline dedupes silently at resolve time. The diagnostic
14648 // names the offending dep + the colliding feature verbatim so
14649 // the author can grep their caixa.lisp for `:caracteristicas`
14650 // and fix it in one edit. First-collision determinism is
14651 // pinned separately below.
14652 let d = dep_with_features(&["http", "http"]);
14653 assert!(
14654 matches!(
14655 d.validate().unwrap_err(),
14656 DepError::CaracteristicaDuplicate { ref nome, ref caracteristica }
14657 if nome == "caixa-teia" && caracteristica == "http"
14658 ),
14659 "expected CaracteristicaDuplicate, got {:?}",
14660 d.validate(),
14661 );
14662 }
14663
14664 #[test]
14665 fn validate_accepts_distinct_caracteristicas() {
14666 // The canonical authoring shape — every feature distinct — must
14667 // remain a clean pass (positive control sweep). Covers the
14668 // canonical kebab-case feature names a target caixa typically
14669 // declares.
14670 dep_with_features(&["http", "json", "tls"])
14671 .validate()
14672 .unwrap();
14673 }
14674
14675 #[test]
14676 fn validate_accepts_single_caracteristica() {
14677 // Single-element list is the minimum non-empty shape; passes
14678 // the gate as the identity of the duplicate check (no second
14679 // entry to collide with).
14680 dep_with_features(&["http"]).validate().unwrap();
14681 }
14682
14683 #[test]
14684 fn validate_accepts_empty_caracteristicas_list() {
14685 // The bare-dep authoring shape (`Dep::simple` / `Dep::git`)
14686 // produces `caracteristicas: Vec::new()`; the empty list is
14687 // the gate's empty-set identity and passes vacuously. Pin
14688 // this so a future tightening that requires ≥1 feature
14689 // surfaces here as a test failure rather than a silent
14690 // contract narrowing.
14691 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
14692 assert!(dep_with_features(&[]).validate().is_ok());
14693 }
14694
14695 #[test]
14696 fn validate_caracteristica_empty_fires_before_duplicate() {
14697 // Empty-first cascade: an entry with an empty feature *and*
14698 // duplicate entries surfaces the empty diagnostic first. The
14699 // empty-feature axis is the more-actionable defect since
14700 // `caracteristica: ""` is unambiguous; under duplicate-first
14701 // ordering the diagnostic could report the empty string from
14702 // either of two empty entries with no way to distinguish.
14703 // Mirrors the peer empty-before-duplicate ordering
14704 // discipline every per-entry shape + duplicate gate establishes
14705 // (`SupervisorSpec::validate`'s `EmptyChildName` arm before
14706 // `DuplicateChildCaixa`, `validate_membros`'s
14707 // `MembroCaixaEmpty` arm before `MembroDuplicate`).
14708 let d = dep_with_features(&["", "http", "http"]);
14709 assert!(matches!(
14710 d.validate().unwrap_err(),
14711 DepError::CaracteristicaEmpty { .. }
14712 ));
14713 }
14714
14715 #[test]
14716 fn validate_caracteristica_duplicate_first_collision_determinism() {
14717 // Three matching entries: the second occurrence surfaces the
14718 // diagnostic (the second is the first *collision* — the first
14719 // entry is the establishing one, not a duplicate). Mirrors
14720 // every peer first-collision posture
14721 // (`SupervisorError::DuplicateChildCaixa` reports the second
14722 // collision, `AplicacaoError::MembroDuplicate` reports the
14723 // second, `DepError::DuplicateNome` reports the second).
14724 // Pinning this so a future shortcut that flips to last-
14725 // collision (or non-deterministic) surfaces here.
14726 let d = dep_with_features(&["http", "http", "http"]);
14727 assert!(matches!(
14728 d.validate().unwrap_err(),
14729 DepError::CaracteristicaDuplicate { ref caracteristica, .. } if caracteristica == "http"
14730 ));
14731 }
14732
14733 #[test]
14734 fn validate_per_entry_shape_fires_before_caracteristicas() {
14735 // Per-entry shape precedence: a dep with a malformed `:nome`
14736 // (uppercase) AND duplicate `:caracteristicas` surfaces the
14737 // narrower `NomeInvalid` diagnostic first, not the set-gate
14738 // diagnostic. The `:nome` is the self-locating axis (every
14739 // diagnostic from the caracteristicas gate quotes the
14740 // offending dep's `:nome` to anchor the grep target —
14741 // surfacing the malformed name first keeps that anchor
14742 // valid). Same precedence shape every peer per-entry-shape
14743 // arm establishes against its peer set-gate
14744 // (`validate_deps_per_entry_validate_fires_before_duplicate_in_deps`
14745 // on the cross-entry `:nome` axis).
14746 let d = Dep {
14747 nome: "Caixa-Teia".into(), // uppercase — DNS-1123 violation
14748 versao: "^0.1".into(),
14749 fonte: None,
14750 opcional: false,
14751 caracteristicas: vec!["http".into(), "http".into()],
14752 };
14753 assert!(matches!(
14754 d.validate().unwrap_err(),
14755 DepError::NomeInvalid { .. }
14756 ));
14757 }
14758
14759 // ── per-entry :caracteristicas value-shape gate ──────────────────
14760 //
14761 // Until this gate landed `:caracteristicas` only refused the empty
14762 // string and cross-entry duplicates: a non-empty distinct but
14763 // structurally invalid feature name silently passed validate and the
14764 // failure surfaced at `cargo metadata` time as Cargo's
14765 // `restricted_names::validate_feature_name` parser rejection, far from
14766 // the source `caixa.lisp` with no field naming which `:deps` entry's
14767 // `:caracteristicas` carried the typo. The lifted predicate makes the
14768 // Cargo-feature-name-grammar intersection-floor a substrate-level
14769 // invariant at validate time. Same trajectory as the eight peer
14770 // value-shape predicates each typed surface downstream of a structured
14771 // grammar already follows.
14772
14773 #[test]
14774 fn validate_rejects_caracteristica_with_leading_plus() {
14775 // Fail-before-pass-after pin on the canonical Cargo
14776 // `+<feature>` activation-form-in-feature-name-slot footgun.
14777 // Cargo's `[dependencies.<dep>.features]` list grammar accepts
14778 // `+optional-feature` as an enablement of a previously-disabled
14779 // feature; pasting that activation form into `:caracteristicas`
14780 // (which names the feature itself) silently passed pre-gate and
14781 // failed at `cargo metadata` parse time.
14782 let d = dep_with_features(&["+http"]);
14783 let err = d.validate().unwrap_err();
14784 assert!(
14785 matches!(
14786 err,
14787 DepError::CaracteristicaInvalid { ref nome, ref caracteristica, .. }
14788 if nome == "caixa-teia" && caracteristica == "+http"
14789 ),
14790 "expected CaracteristicaInvalid, got {err:?}"
14791 );
14792 }
14793
14794 #[test]
14795 fn validate_rejects_caracteristica_with_leading_hyphen() {
14796 // Fail-before-pass-after pin on the leading-hyphen footgun. `-`
14797 // is a legitimate continuation character (kebab-case feature
14798 // names like `runtime-tokio` pass) but Cargo rejects it at the
14799 // start; the structural defect — and its CLI-argument-injection
14800 // adjacency at any downstream Cargo subprocess invocation — is
14801 // closed at validate time, not at `cargo metadata` time.
14802 let d = dep_with_features(&["-json"]);
14803 let err = d.validate().unwrap_err();
14804 assert!(
14805 matches!(
14806 err,
14807 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "-json"
14808 ),
14809 "expected CaracteristicaInvalid, got {err:?}"
14810 );
14811 }
14812
14813 #[test]
14814 fn validate_rejects_caracteristica_with_leading_dot() {
14815 // Fail-before-pass-after pin on the leading-dot footgun. `.` is
14816 // a legitimate continuation character (version-suffix shapes
14817 // like `feat.v2` pass) but the leading-dot form is the
14818 // canonical dotted-version-suffix-as-feature-name confusion.
14819 let d = dep_with_features(&[".feat"]);
14820 let err = d.validate().unwrap_err();
14821 assert!(matches!(
14822 err,
14823 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == ".feat"
14824 ));
14825 }
14826
14827 #[test]
14828 fn validate_rejects_caracteristica_with_whitespace() {
14829 // Fail-before-pass-after pin on the embedded-whitespace footgun:
14830 // a feature name with a space inside is structurally a multi-
14831 // token blob (the canonical paste-from-doc footgun, or an
14832 // accidental `"http server"` where the author meant
14833 // `"http-server"`).
14834 let d = dep_with_features(&["http feature"]);
14835 let err = d.validate().unwrap_err();
14836 assert!(matches!(
14837 err,
14838 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http feature"
14839 ));
14840 }
14841
14842 #[test]
14843 fn validate_rejects_caracteristica_with_comma() {
14844 // Fail-before-pass-after pin on the embedded-comma footgun:
14845 // the list-separator-belongs-to-the-list-grammar
14846 // miscomprehension where the author writes
14847 // `:caracteristicas ("http,json")` intending two features but
14848 // the `Vec<String>` field consumes the bare token as one entry.
14849 let d = dep_with_features(&["http,json"]);
14850 let err = d.validate().unwrap_err();
14851 assert!(matches!(
14852 err,
14853 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http,json"
14854 ));
14855 }
14856
14857 #[test]
14858 fn validate_rejects_caracteristica_with_slash() {
14859 // Fail-before-pass-after pin on the embedded-slash footgun:
14860 // Cargo's `dep/feat` namespaced-dep syntax applies inside
14861 // `[dependencies.<dep>.features]` list entries that already
14862 // name the parent dep (so the syntax says "enable feature
14863 // `feat` on a transitive dep `dep`"); `:caracteristicas` is
14864 // per-dep already (a sibling slot on the `Dep` itself), so the
14865 // segment separator within an entry must be `-`, `_`, `+`,
14866 // or `.`. The diagnostic remediation points at the canonical
14867 // Cargo namespaced-dep discipline.
14868 let d = dep_with_features(&["http/json"]);
14869 let err = d.validate().unwrap_err();
14870 assert!(matches!(
14871 err,
14872 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "http/json"
14873 ));
14874 }
14875
14876 #[test]
14877 fn validate_rejects_caracteristica_with_non_ascii() {
14878 // Fail-before-pass-after pin on the un-percent-encoded non-ASCII
14879 // byte footgun: NFC-vs-NFD normalization across filesystems
14880 // silently rewrites the feature-key, breaking the lacre's
14881 // content-addressing invariant. Pinned at a canonical
14882 // smart-quote-paste shape (`café`) where the raw `é` byte is the
14883 // documented APFS round-trip break.
14884 let d = dep_with_features(&["caf\u{e9}"]);
14885 let err = d.validate().unwrap_err();
14886 assert!(matches!(
14887 err,
14888 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "caf\u{e9}"
14889 ));
14890 }
14891
14892 #[test]
14893 fn validate_rejects_caracteristica_with_control_character() {
14894 // Fail-before-pass-after pin on the embedded-control-character
14895 // footgun: a CR/LF or any 0x00..0x1F / 0x7F byte landing in a
14896 // feature name is the canonical paste-from-multiline-doc
14897 // footgun the predicate's reason wording specifically calls out.
14898 let d = dep_with_features(&["http\njson"]);
14899 let err = d.validate().unwrap_err();
14900 assert!(matches!(err, DepError::CaracteristicaInvalid { .. }));
14901 }
14902
14903 #[test]
14904 fn validate_accepts_canonical_caracteristicas_shapes() {
14905 // Positive control sweep: every canonical Cargo feature name
14906 // shape the pleme-io ecosystem uses must still pass. Mirrors
14907 // the substrate-side `cargo_feature_name_accepts_canonical_forms`
14908 // sweep — drift between either landing site and the predicate's
14909 // accepted set is a build error visible at this pair of tests,
14910 // not a per-renderer "this passed validate but failed at
14911 // cargo metadata time" surprise on the next acceptance.
14912 for s in [
14913 "http",
14914 "json",
14915 "derive",
14916 "serde_json",
14917 "runtime-tokio",
14918 "tokio.full",
14919 "v0.1",
14920 "http+json",
14921 "_internal",
14922 "__private",
14923 "default",
14924 "rt-multi-thread",
14925 "feat.v2",
14926 ] {
14927 let d = dep_with_features(&[s]);
14928 d.validate().unwrap_or_else(|e| {
14929 panic!("canonical Cargo feature name {s:?} must pass validate: {e:?}")
14930 });
14931 }
14932 }
14933
14934 #[test]
14935 fn validate_caracteristica_empty_fires_before_invalid() {
14936 // Cascade precedence pin: an entry list with both an empty
14937 // feature AND an invalid-shape feature surfaces the
14938 // `CaracteristicaEmpty` arm first (the empty value carries no
14939 // self-locating data — `caracteristica: ""` is the diagnostic
14940 // with no way to anchor a grep target — so closing the empty
14941 // axis first preserves the per-entry-shape diagnostic's
14942 // self-locating discipline). Same empty-first cascade every
14943 // peer per-entry shape gate establishes
14944 // (`SupervisorSpec::validate`'s `EmptyChildName` before
14945 // `ChildCaixaInvalid`, `validate_membros`'s `MembroCaixaEmpty`
14946 // before `MembroCaixaInvalid`).
14947 let d = dep_with_features(&["", "+http"]);
14948 assert!(matches!(
14949 d.validate().unwrap_err(),
14950 DepError::CaracteristicaEmpty { .. }
14951 ));
14952 }
14953
14954 #[test]
14955 fn validate_caracteristica_invalid_fires_before_duplicate() {
14956 // Per-entry-shape precedence pin: an entry list with the same
14957 // invalid feature shape declared twice surfaces the
14958 // `CaracteristicaInvalid` diagnostic on the first entry, not
14959 // the `CaracteristicaDuplicate` on the second collision. The
14960 // per-entry shape gate fires before the cross-entry set gate
14961 // — same precedence shape every peer two-arm-plus-set gate
14962 // establishes (`SupervisorSpec::validate`'s
14963 // `ChildCaixaInvalid` before `DuplicateChildCaixa`,
14964 // `validate_membros`'s `MembroCaixaInvalid` before
14965 // `MembroDuplicate`, `Dep::validate`'s `NomeInvalid` before
14966 // cross-list `DuplicateNome`).
14967 let d = dep_with_features(&["+http", "+http"]);
14968 assert!(matches!(
14969 d.validate().unwrap_err(),
14970 DepError::CaracteristicaInvalid { ref caracteristica, .. } if caracteristica == "+http"
14971 ));
14972 }
14973
14974 #[test]
14975 fn validate_rejects_caracteristica_at_65_byte_boundary() {
14976 // Boundary pin on the 64-byte cap — both the boundary-accepting
14977 // case and the boundary-exceeding case in one place, so a
14978 // future cap shift surfaces both arms simultaneously, mirroring
14979 // the peer `cargo_feature_name_rejects_at_65_byte_boundary`
14980 // predicate-level pin at the dep-axis landing site.
14981 let max_ok = "a".repeat(64);
14982 dep_with_features(&[&max_ok])
14983 .validate()
14984 .unwrap_or_else(|e| panic!("64-byte feature name must pass: {e:?}"));
14985 let too_long = "a".repeat(65);
14986 let d = dep_with_features(&[&too_long]);
14987 assert!(matches!(
14988 d.validate().unwrap_err(),
14989 DepError::CaracteristicaInvalid { .. }
14990 ));
14991 }
14992
14993 // ── self-dep cross-slot gate ─────────────────────────────────────
14994
14995 #[test]
14996 fn validate_no_self_dep_rejects_self_in_deps() {
14997 // A caixa whose `:deps` lists its own `:nome` is a one-node
14998 // cycle in the lacre closure's dep-graph traversal — rejected,
14999 // naming the parent and the offending list tag.
15000 let deps = vec![
15001 Dep::simple("caixa-teia", "^0.1"),
15002 Dep::simple("orquestra", "^0.1"),
15003 ];
15004 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15005 assert!(
15006 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
15007 "got {err:?}"
15008 );
15009 }
15010
15011 #[test]
15012 fn validate_no_self_dep_rejects_self_in_deps_dev() {
15013 // Same gate on the `:deps-dev` axis — neither dep list is a
15014 // second-class citizen on the self-edge invariant.
15015 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15016 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15017 assert!(
15018 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
15019 "got {err:?}"
15020 );
15021 }
15022
15023 #[test]
15024 fn validate_no_self_dep_deps_fires_before_deps_dev() {
15025 // Walk order pin: a caixa that self-references on both lists
15026 // surfaces the `:deps` arm first — the load-bearing axis the
15027 // lacre closure resolves at every build. Mirrors the canonical
15028 // [`Caixa::validate_deps`] cascade (`:deps` → `:deps-dev`).
15029 let deps = vec![Dep::simple("orquestra", "^0.1")];
15030 let deps_dev = vec![Dep::simple("orquestra", "^0.2")];
15031 let err = validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap_err();
15032 assert!(
15033 matches!(err, DepError::DepIsSelf { ref nome, list } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS),
15034 "got {err:?}"
15035 );
15036 }
15037
15038 #[test]
15039 fn validate_no_self_dep_accepts_distinct_names() {
15040 // Positive control: every dep names a distinct caixa. The
15041 // canonical author surface — peer of
15042 // [`validate_no_self_supervision_accepts_distinct_children`].
15043 let deps = vec![
15044 Dep::simple("caixa-teia", "^0.1"),
15045 Dep::simple("caixa-arch", "^0.1"),
15046 ];
15047 let deps_dev = vec![Dep::simple("caixa-test", "^0.1")];
15048 validate_no_self_dep(&deps, &deps_dev, "orquestra").unwrap();
15049 }
15050
15051 #[test]
15052 fn validate_no_self_dep_empty_lists_pass() {
15053 // A caixa with no declared deps has nothing to self-reference —
15054 // the gate is vacuously satisfied. Peer of
15055 // [`validate_no_self_supervision_empty_children_is_ok`].
15056 validate_no_self_dep(&[], &[], "orquestra").unwrap();
15057 }
15058
15059 #[test]
15060 fn validate_no_self_dep_diagnostic_carries_offending_list_and_nome() {
15061 // Diagnostic-shape pin (peer with
15062 // [`validate_no_self_supervision`]'s diagnostic): the error's
15063 // Display surfaces both the offending list tag and the
15064 // parent's `:nome` verbatim, so the author can grep their
15065 // caixa.lisp for the offending block in one edit. Names
15066 // `:bibliotecas` / `:exe` / `:servicos` as the corrective
15067 // surface — every legitimate "I want to use code from this
15068 // caixa" intent routes through one of those three slots.
15069 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15070 let rendered = validate_no_self_dep(&[], &deps_dev, "orquestra")
15071 .unwrap_err()
15072 .to_string();
15073 assert!(
15074 rendered.contains(crate::render::DEP_AUTHOR_KEY_DEPS_DEV),
15075 "diagnostic must name the offending list tag: {rendered}",
15076 );
15077 assert!(
15078 rendered.contains("orquestra"),
15079 "diagnostic must quote the parent caixa name: {rendered}",
15080 );
15081 assert!(
15082 rendered.contains(":bibliotecas"),
15083 "diagnostic must point at the corrective code-surface slot: {rendered}",
15084 );
15085 }
15086
15087 #[test]
15088 fn validate_no_self_dep_accepts_coincidental_substring_match() {
15089 // Identity is exact-string equality, not substring — a dep
15090 // named `"orquestra-helper"` is a distinct caixa even when the
15091 // parent is `"orquestra"`. Pin the exact-match discipline so a
15092 // future relaxation that uses `contains` surfaces here, peer
15093 // with the supervision-tree and Aplicacao-membership gates
15094 // which all use exact-string equality on the typed identity.
15095 let deps = vec![Dep::simple("orquestra-helper", "^0.1")];
15096 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15097 }
15098
15099 // ── drift-detection: DEP_AUTHOR_KEY_{DEPS,DEPS_DEV} pin ─────────────
15100
15101 #[test]
15102 fn dep_author_key_consts_pin_canonical_kebab_case_labels() {
15103 // Scalar-value pin: the two author-facing kebab-case labels the
15104 // `(defcaixa … :deps ((…)) :deps-dev ((…)))` surface admits on
15105 // the two-list dep-graph slot axis, one arm per typed slot.
15106 // Mirrors the peer scalar-value pin the sibling
15107 // [`crate::M2_AUTHOR_KEY_LIMITS`] /
15108 // [`crate::M2_AUTHOR_KEY_BEHAVIOR`] /
15109 // [`crate::M2_AUTHOR_KEY_UPGRADE_FROM`] (f49c8b0) M2 top-level
15110 // author-labels, [`crate::M3_AUTHOR_KEY_MEMBROS`] etc.
15111 // (882f498) M3 top-level author-labels, and
15112 // [`crate::SUPERVISOR_AUTHOR_KEY_ESTRATEGIA`] etc. (be40492)
15113 // Supervisor top-level author-labels carry, so every kind-scoped
15114 // typed-slot-family axis routes through one canonical per-arm
15115 // declaration.
15116 //
15117 // A future rebrand (`:deps` → `:dependencies` matching Cargo's
15118 // verbatim key, `:deps-dev` → `:dev-dependencies` matching the
15119 // same, `:deps` / `:deps-dev` → `:runtime-deps` / `:dev-deps`
15120 // for symmetry) lands as an edit to exactly one const, and
15121 // every consumer that reaches for the label picks it up at
15122 // build time rather than at runtime as a downstream mismatch on
15123 // a `DepError::DuplicateNome { list: … }` diagnostic far from
15124 // the rename's commit.
15125 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS, ":deps");
15126 assert_eq!(crate::render::DEP_AUTHOR_KEY_DEPS_DEV, ":deps-dev");
15127 }
15128
15129 #[test]
15130 fn dep_author_key_consts_are_pairwise_distinct() {
15131 // Distinct-labels pin: the two `:deps` / `:deps-dev` labels
15132 // must not collapse onto one byte-string. A future copy-paste
15133 // slip that renamed both consts to the same value (or a rebrand
15134 // that dropped the `-dev` suffix from one but not the other)
15135 // would leave every `DepError::DuplicateNome { list: … }`
15136 // diagnostic naming an unattributable list — the linter would
15137 // route the author to the wrong caixa.lisp block, or the
15138 // cross-list precedence gate
15139 // (`validate_deps_duplicate_in_deps_fires_before_duplicate_in_deps_dev`)
15140 // would surface a `:deps`-tagged diagnostic on a `:deps-dev`
15141 // duplicate. Peer of the sibling
15142 // `m2_author_key_consts_are_pairwise_distinct`-shape gates the
15143 // other top-level kind-scoped slot-family axes carry
15144 // (implicitly held by their different byte-values today).
15145 assert_ne!(
15146 crate::render::DEP_AUTHOR_KEY_DEPS,
15147 crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15148 "DEP_AUTHOR_KEY_{{DEPS,DEPS_DEV}} consts must be pairwise-distinct \
15149 so a `DepError::DuplicateNome {{ list: … }}` diagnostic \
15150 self-locates the offending block in the author's caixa.lisp",
15151 );
15152 }
15153
15154 #[test]
15155 fn validate_no_self_dep_routes_through_lifted_dep_author_key_consts() {
15156 // Production-through-const pin: the two per-arm list tags
15157 // [`validate_no_self_dep`] threads onto the `list:` field of a
15158 // returned [`DepError::DepIsSelf`] route through the lifted
15159 // [`crate::DEP_AUTHOR_KEY_DEPS`] /
15160 // [`crate::DEP_AUTHOR_KEY_DEPS_DEV`] consts. A future drift at
15161 // the walker (a rename that reaches one arm but not the const,
15162 // or vice versa) surfaces here at build time rather than at
15163 // runtime as a `feira lint` diagnostic naming the wrong list
15164 // tag. Mirror of the peer
15165 // [`crate::Caixa::declared_servico_slots`] production tagger
15166 // pin (f49c8b0) on the sibling M2 top-level slot axis, extended
15167 // onto the two-list dep-graph gate.
15168 let deps = vec![Dep::simple("orquestra", "^0.1")];
15169 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15170 let DepError::DepIsSelf { list, .. } = err else {
15171 panic!("expected DepIsSelf from :deps walk");
15172 };
15173 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS);
15174
15175 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15176 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15177 let DepError::DepIsSelf { list, .. } = err else {
15178 panic!("expected DepIsSelf from :deps-dev walk");
15179 };
15180 assert_eq!(list, crate::render::DEP_AUTHOR_KEY_DEPS_DEV);
15181 }
15182
15183 // ── Dep::nome accessor pins ───────────────────────────────────────
15184 //
15185 // Three coherence pins on the lifted `Dep::nome` accessor: byte-equal
15186 // projection over the plain-shorthand / explicit-git / explicit-path
15187 // fixture triad the [`Dep`] docstring lists (so the accessor's
15188 // accept-set is exercised across every author-surface `:fonte`
15189 // shape); by-borrow pointer identity so the projection stays
15190 // zero-copy at every consumer site; and validate-composition through
15191 // the [`validate_no_self_dep`] cross-slot gate reading its
15192 // parent-name equality check through the lifted accessor rather than
15193 // the raw field.
15194
15195 #[test]
15196 fn dep_nome_returns_declared_nome_across_fonte_shapes() {
15197 // Plain-shorthand form (`:fonte None`).
15198 assert_eq!(Dep::simple("caixa-teia", "^0.1").nome(), "caixa-teia");
15199 // Explicit git-source form with a tag pin — same accessor path.
15200 assert_eq!(
15201 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").nome(),
15202 "caixa-teia",
15203 );
15204 // Explicit path-source form.
15205 assert_eq!(
15206 Dep {
15207 nome: "caixa-teia".to_string(),
15208 versao: "0.1.0".to_string(),
15209 fonte: Some(DepSource::Path {
15210 caminho: "../caixa-teia".to_string(),
15211 }),
15212 opcional: false,
15213 caracteristicas: Vec::new(),
15214 }
15215 .nome(),
15216 "caixa-teia",
15217 );
15218 // The empty-string `:nome` sentinel (which [`Dep::validate`]
15219 // refuses through the [`DepError::NomeEmpty`] arm) still round-
15220 // trips as an empty `&str` through the accessor — the accessor is
15221 // a projection, not a gate; the gate is [`Dep::validate`].
15222 assert_eq!(Dep::simple("", "^0.1").nome(), "");
15223 }
15224
15225 #[test]
15226 fn dep_nome_is_by_borrow_pointer_identity() {
15227 // Zero-copy pin: the accessor must borrow into the field's own
15228 // storage, not clone. If a future rewrite regresses to
15229 // `self.nome.clone().leak()` or an owned-buffer shape, the two
15230 // pointers diverge and this pin fails at build time.
15231 let d = Dep::simple("caixa-teia", "^0.1");
15232 assert!(std::ptr::eq(d.nome().as_ptr(), d.nome.as_ptr()));
15233 }
15234
15235 // ── Dep::versao_requirement accessor pins ─────────────────────────
15236 //
15237 // Three coherence pins on the lifted `Dep::versao_requirement`
15238 // accessor: byte-equal projection over the plain-shorthand /
15239 // explicit-git / explicit-path fixture triad the [`Dep`] docstring
15240 // lists plus the empty-sentinel that round-trips as `""` (the accessor
15241 // is a projection, not a gate; the gate is [`Dep::validate`]); by-
15242 // borrow pointer identity so the projection stays zero-copy at every
15243 // consumer site; and validate-composition through the
15244 // [`crate::render::require_valid_versao_requirement`] cascade reading
15245 // its requirement-shape check through the lifted accessor rather than
15246 // the raw field.
15247 #[test]
15248 fn dep_versao_requirement_returns_declared_versao_across_fonte_shapes() {
15249 // Plain-shorthand form (`:fonte None`).
15250 assert_eq!(
15251 Dep::simple("caixa-teia", "^0.1").versao_requirement(),
15252 "^0.1",
15253 );
15254 // Explicit git-source form with a tag pin — same accessor path.
15255 assert_eq!(
15256 Dep::git(
15257 "caixa-teia",
15258 "~0.1.2",
15259 "github:pleme-io/caixa-teia",
15260 "v0.1.0"
15261 )
15262 .versao_requirement(),
15263 "~0.1.2",
15264 );
15265 // Explicit path-source form.
15266 assert_eq!(
15267 Dep {
15268 nome: "caixa-teia".to_string(),
15269 versao: "0.1.0".to_string(),
15270 fonte: Some(DepSource::Path {
15271 caminho: "../caixa-teia".to_string(),
15272 }),
15273 opcional: false,
15274 caracteristicas: Vec::new(),
15275 }
15276 .versao_requirement(),
15277 "0.1.0",
15278 );
15279 // The wildcard requirement (`"*"`) — the shorthand
15280 // `parse_requirement` accepts as `VersionReq::STAR` — round-trips
15281 // verbatim through the accessor as `"*"`, same byte-shape the
15282 // author wrote.
15283 assert_eq!(Dep::simple("caixa-teia", "*").versao_requirement(), "*");
15284 // The empty-string `:versao` sentinel (which [`Dep::validate`]
15285 // refuses through the [`DepError::VersaoEmpty`] arm) still round-
15286 // trips as an empty `&str` through the accessor — the accessor is
15287 // a projection, not a gate; the gate is [`Dep::validate`]. Peer
15288 // of the sibling [`Dep::nome`] empty-sentinel round-trip pin.
15289 assert_eq!(Dep::simple("caixa-teia", "").versao_requirement(), "");
15290 }
15291
15292 #[test]
15293 fn dep_versao_requirement_is_by_borrow_pointer_identity() {
15294 // Zero-copy pin: the accessor must borrow into the field's own
15295 // storage, not clone. If a future rewrite regresses to
15296 // `self.versao.clone().leak()` or an owned-buffer shape, the two
15297 // pointers diverge and this pin fails at build time. Peer of the
15298 // sibling [`Dep::nome`] pointer-identity pin — same by-borrow
15299 // discipline extended onto the requirement-carrying axis.
15300 let d = Dep::simple("caixa-teia", "^0.1");
15301 assert!(std::ptr::eq(
15302 d.versao_requirement().as_ptr(),
15303 d.versao.as_ptr(),
15304 ));
15305 }
15306
15307 #[test]
15308 fn dep_validate_reads_requirement_through_accessor() {
15309 // Composition pin: the [`Dep::validate`]
15310 // [`crate::render::require_valid_versao_requirement`] cascade
15311 // consumes the requirement string through the lifted accessor —
15312 // both the requirement-gate input and the
15313 // [`DepError::VersaoInvalid`] error-body carrier route through
15314 // `self.versao_requirement()`. A valid requirement passes
15315 // (positive control); a malformed-but-non-empty requirement fails
15316 // and the diagnostic quotes the offending byte-string verbatim
15317 // (same shape the accessor projects), so a future regression that
15318 // detoured the requirement carrier through a different byte-
15319 // string (say the parsed `VersionReq`'s `Display`, or a
15320 // normalized rewrite) would surface here at build time. The
15321 // empty-`:versao` arm fires the [`DepError::VersaoEmpty`] variant
15322 // ahead of the parse arm, pinning the empty-first cascade the
15323 // accessor's `""` sentinel round-trip acknowledges.
15324 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15325 let err = Dep::simple("caixa-teia", "v0.1").validate().unwrap_err();
15326 assert!(
15327 matches!(
15328 &err,
15329 DepError::VersaoInvalid {
15330 nome,
15331 versao,
15332 ..
15333 } if nome == "caixa-teia" && versao == "v0.1",
15334 ),
15335 "expected VersaoInvalid quoting the accessor-projected requirement, got {err:?}",
15336 );
15337 let err = Dep::simple("caixa-teia", "").validate().unwrap_err();
15338 assert!(
15339 matches!(
15340 &err,
15341 DepError::VersaoEmpty { nome } if nome == "caixa-teia",
15342 ),
15343 "expected VersaoEmpty from the empty-first arm, got {err:?}",
15344 );
15345 }
15346
15347 // ── Dep::fonte accessor pins ──────────────────────────────────────
15348 //
15349 // Three coherence pins on the lifted `Dep::fonte` accessor: byte-
15350 // equal projection over the plain-shorthand (`:fonte None`) /
15351 // explicit-git-tag / explicit-path fixture triad the [`Dep`]
15352 // docstring lists (so the accessor's accept-set is exercised across
15353 // every author-surface `:fonte` shape and both `DepSource` variants);
15354 // pointer identity so the borrowed reference points into the field's
15355 // own `Option<DepSource>` storage (not a cloned side-buffer); and
15356 // validate-composition through the [`Dep::validate`] gate reading
15357 // its per-`:fonte` [`DepSource::validate`] delegation through the
15358 // lifted accessor rather than the raw `if let Some(ref fonte) =
15359 // self.fonte` bracket.
15360
15361 #[test]
15362 fn dep_fonte_returns_declared_source_across_shapes() {
15363 // Plain-shorthand form — `:fonte` omitted, accessor projects
15364 // the `None` partition the resolver-side default-fill treats
15365 // as "resolve through `github:<default-org>/<nome>`".
15366 assert!(Dep::simple("caixa-teia", "^0.1").fonte().is_none());
15367 // Explicit git-source form with a tag pin — same accessor path.
15368 let git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15369 match git.fonte() {
15370 Some(DepSource::Git {
15371 repo,
15372 tag,
15373 rev,
15374 branch,
15375 }) => {
15376 assert_eq!(repo, "github:pleme-io/caixa-teia");
15377 assert_eq!(tag.as_deref(), Some("v0.1.0"));
15378 assert!(rev.is_none());
15379 assert!(branch.is_none());
15380 }
15381 other => panic!("expected explicit git :fonte, got {other:?}"),
15382 }
15383 // Explicit path-source form — the dev-only local-filesystem
15384 // arm the [`Dep`] docstring's third fixture carries.
15385 let path = Dep {
15386 nome: "caixa-teia".to_string(),
15387 versao: "0.1.0".to_string(),
15388 fonte: Some(DepSource::Path {
15389 caminho: "../caixa-teia".to_string(),
15390 }),
15391 opcional: false,
15392 caracteristicas: Vec::new(),
15393 };
15394 match path.fonte() {
15395 Some(DepSource::Path { caminho }) => {
15396 assert_eq!(caminho, "../caixa-teia");
15397 }
15398 other => panic!("expected explicit path :fonte, got {other:?}"),
15399 }
15400 }
15401
15402 #[test]
15403 fn dep_fonte_is_by_borrow_pointer_identity() {
15404 // Zero-copy pin: the accessor must borrow into the field's own
15405 // `Option<DepSource>` storage, not clone into a side buffer. If
15406 // a future rewrite regresses to `self.fonte.clone()` or an
15407 // owned-buffer shape, the two pointers diverge and this pin
15408 // fails at build time. Peer of the sibling per-`Dep` [`Dep::nome`]
15409 // (eba2cde) / [`Dep::versao_requirement`] (05529b1) pointer-
15410 // identity pins — same by-borrow discipline extended onto the
15411 // outer-`Dep` `Option<&Composite>` composite-reference axis.
15412 let d = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0");
15413 let accessed = d.fonte().expect("git :fonte present") as *const DepSource;
15414 let raw = d.fonte.as_ref().expect("git :fonte present") as *const DepSource;
15415 assert!(std::ptr::eq(accessed, raw));
15416 }
15417
15418 #[test]
15419 fn dep_validate_reads_fonte_through_accessor() {
15420 // Composition pin: [`Dep::validate`]'s per-`:fonte`
15421 // [`DepSource::validate`] delegation consumes the typed slot
15422 // through the lifted accessor — an author-omitted `:fonte`
15423 // still passes the outer gate (positive control), an explicit
15424 // well-formed git source with exactly one pin passes, and a
15425 // malformed git source (empty `:repo`) surfaces the
15426 // [`DepError::FonteRepoEmpty`] variant quoting the offending
15427 // dep's `:nome` verbatim so a future regression that detoured
15428 // the `:fonte` delegation through a different path (say a
15429 // per-scope override projector) would surface here at build
15430 // time. Peer of the sibling
15431 // `dep_validate_reads_requirement_through_accessor` composition
15432 // pin on the `:versao` axis.
15433 // Positive control 1: no `:fonte` at all.
15434 Dep::simple("caixa-teia", "^0.1").validate().unwrap();
15435 // Positive control 2: well-formed git source.
15436 Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
15437 .validate()
15438 .unwrap();
15439 // Negative control: empty `:repo` — the accessor still returns
15440 // `Some(&DepSource::Git { repo: "", … })` and the delegated
15441 // `DepSource::validate` gate raises the typed carrier.
15442 let bad = Dep {
15443 nome: "caixa-teia".to_string(),
15444 versao: "^0.1".to_string(),
15445 fonte: Some(DepSource::Git {
15446 repo: String::new(),
15447 tag: Some("v0.1.0".to_string()),
15448 rev: None,
15449 branch: None,
15450 }),
15451 opcional: false,
15452 caracteristicas: Vec::new(),
15453 };
15454 let err = bad.validate().unwrap_err();
15455 assert!(
15456 matches!(
15457 &err,
15458 DepError::FonteRepoEmpty { nome } if nome == "caixa-teia",
15459 ),
15460 "expected FonteRepoEmpty from the accessor-routed :fonte gate, got {err:?}",
15461 );
15462 }
15463
15464 #[test]
15465 fn validate_no_self_dep_reads_parent_equality_through_accessor() {
15466 // Composition pin: the cross-slot [`validate_no_self_dep`] gate
15467 // rejects a `:deps` entry whose `:nome` equals the parent caixa's
15468 // own `:nome` through the lifted accessor rather than the raw
15469 // field. Fails-before-passes-after: with the accessor lifted the
15470 // gate reads its equality check through `dep.nome() ==
15471 // parent_nome` on both the `:deps` and `:deps-dev` traversals, so
15472 // the diagnostic still names the offending list tag as expected.
15473 let deps = vec![Dep::simple("orquestra", "^0.1")];
15474 let err = validate_no_self_dep(&deps, &[], "orquestra").unwrap_err();
15475 assert!(matches!(
15476 err,
15477 DepError::DepIsSelf {
15478 ref nome,
15479 list,
15480 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS,
15481 ));
15482 let deps_dev = vec![Dep::simple("orquestra", "^0.1")];
15483 let err = validate_no_self_dep(&[], &deps_dev, "orquestra").unwrap_err();
15484 assert!(matches!(
15485 err,
15486 DepError::DepIsSelf {
15487 ref nome,
15488 list,
15489 } if nome == "orquestra" && list == crate::render::DEP_AUTHOR_KEY_DEPS_DEV,
15490 ));
15491 // A non-matching `:nome` passes through the accessor gate.
15492 let deps = vec![Dep::simple("caixa-teia", "^0.1")];
15493 validate_no_self_dep(&deps, &[], "orquestra").unwrap();
15494 }
15495
15496 // ── Dep::caracteristicas accessor pins ────────────────────────────
15497 //
15498 // Three coherence pins on the lifted `Dep::caracteristicas` accessor:
15499 // byte-equal projection over the default-empty / single-entry /
15500 // multi-entry fixture triad (so the accessor's accept-set is
15501 // exercised across every author-surface `:caracteristicas` shape,
15502 // matching the peer sibling family's fixture-triad discipline); by-
15503 // borrow pointer identity so the projection stays zero-copy at every
15504 // consumer site; and validate-composition through the
15505 // [`Dep::validate_caracteristicas`] gate reading its per-entry
15506 // linear walk through the lifted accessor rather than the raw
15507 // `for c in &self.caracteristicas` bracket.
15508
15509 #[test]
15510 fn dep_caracteristicas_returns_declared_features_across_shapes() {
15511 // Default-empty form — the [`Dep::simple`] constructor's
15512 // `Vec::new()` fill; the accessor projects the empty slice
15513 // verbatim (no `None` collapse).
15514 assert!(
15515 Dep::simple("caixa-teia", "^0.1")
15516 .caracteristicas()
15517 .is_empty(),
15518 );
15519 // Single-entry form — the canonical Cargo-shaped one-feature
15520 // enable ([`crate::render::is_cargo_feature_name`] accepts the
15521 // `"http"` byte-string as a valid feature name).
15522 let one = Dep {
15523 nome: "caixa-teia".to_string(),
15524 versao: "^0.1".to_string(),
15525 fonte: None,
15526 opcional: false,
15527 caracteristicas: vec!["http".to_string()],
15528 };
15529 assert_eq!(one.caracteristicas(), &["http".to_string()]);
15530 // Multi-entry form — the substrate's set-shaped multi-feature
15531 // enable, exercising the accessor over a length-two slice with
15532 // no duplicate collapse.
15533 let two = Dep {
15534 nome: "caixa-teia".to_string(),
15535 versao: "^0.1".to_string(),
15536 fonte: None,
15537 opcional: false,
15538 caracteristicas: vec!["http".to_string(), "json".to_string()],
15539 };
15540 assert_eq!(
15541 two.caracteristicas(),
15542 &["http".to_string(), "json".to_string()],
15543 );
15544 }
15545
15546 #[test]
15547 fn dep_caracteristicas_is_by_borrow_pointer_identity() {
15548 // Zero-copy pin: the accessor must borrow into the field's own
15549 // `Vec<String>` storage, not clone into a side buffer. If a
15550 // future rewrite regresses to `self.caracteristicas.clone()` or
15551 // an owned-buffer shape, the two pointers diverge and this pin
15552 // fails at build time. Peer of the sibling per-`Dep`
15553 // [`Dep::nome`] (eba2cde) / [`Dep::versao_requirement`] (05529b1)
15554 // / [`Dep::fonte`] (d65d1bf) pointer-identity pins — same by-
15555 // borrow discipline extended onto the outer-`Dep` `&[String]`
15556 // slice-projection axis.
15557 let d = Dep {
15558 nome: "caixa-teia".to_string(),
15559 versao: "^0.1".to_string(),
15560 fonte: None,
15561 opcional: false,
15562 caracteristicas: vec!["http".to_string(), "json".to_string()],
15563 };
15564 assert!(std::ptr::eq(
15565 d.caracteristicas().as_ptr(),
15566 d.caracteristicas.as_ptr(),
15567 ));
15568 }
15569
15570 #[test]
15571 fn dep_validate_reads_caracteristicas_through_accessor() {
15572 // Composition pin: [`Dep::validate_caracteristicas`]'s per-entry
15573 // linear walk consumes the feature-toggle list through the
15574 // lifted accessor — a well-formed `:caracteristicas` set passes
15575 // (positive control), an empty-string entry surfaces the
15576 // [`DepError::CaracteristicaEmpty`] variant quoting the offending
15577 // `Dep::nome`, and a within-list duplicate surfaces the
15578 // [`DepError::CaracteristicaDuplicate`] variant so a future
15579 // regression that detoured the walk through a different byte-
15580 // string list (say a per-scope override projector) would surface
15581 // here at build time. Peer of the sibling
15582 // `dep_validate_reads_fonte_through_accessor` /
15583 // `dep_validate_reads_requirement_through_accessor` composition
15584 // pins on the `:fonte` / `:versao` axes.
15585 // Positive control: two distinct well-formed feature names pass.
15586 Dep {
15587 nome: "caixa-teia".to_string(),
15588 versao: "^0.1".to_string(),
15589 fonte: None,
15590 opcional: false,
15591 caracteristicas: vec!["http".to_string(), "json".to_string()],
15592 }
15593 .validate()
15594 .unwrap();
15595 // Negative control 1: empty-string feature-name entry — the
15596 // accessor still returns `&[""]` and the walk raises the typed
15597 // empty-first carrier.
15598 let err = Dep {
15599 nome: "caixa-teia".to_string(),
15600 versao: "^0.1".to_string(),
15601 fonte: None,
15602 opcional: false,
15603 caracteristicas: vec![String::new()],
15604 }
15605 .validate()
15606 .unwrap_err();
15607 assert!(
15608 matches!(
15609 &err,
15610 DepError::CaracteristicaEmpty { nome } if nome == "caixa-teia",
15611 ),
15612 "expected CaracteristicaEmpty from the accessor-routed walk, got {err:?}",
15613 );
15614 // Negative control 2: within-list duplicate — the accessor's
15615 // slice view carries both entries, and the walk's dedup arm
15616 // raises the typed duplicate carrier quoting the offending
15617 // feature name verbatim.
15618 let err = Dep {
15619 nome: "caixa-teia".to_string(),
15620 versao: "^0.1".to_string(),
15621 fonte: None,
15622 opcional: false,
15623 caracteristicas: vec!["http".to_string(), "http".to_string()],
15624 }
15625 .validate()
15626 .unwrap_err();
15627 assert!(
15628 matches!(
15629 &err,
15630 DepError::CaracteristicaDuplicate {
15631 nome,
15632 caracteristica,
15633 } if nome == "caixa-teia" && caracteristica == "http",
15634 ),
15635 "expected CaracteristicaDuplicate from the accessor-routed dedup, got {err:?}",
15636 );
15637 }
15638
15639 // ── Dep::opcional accessor pins ───────────────────────────────────
15640 //
15641 // Two coherence pins on the lifted `Dep::opcional` accessor: byte-
15642 // equal projection over the default-`false` / explicit-`true`
15643 // fixture pair across the plain-shorthand (`:fonte None`) / explicit-
15644 // git-tag / explicit-path fixture triad the [`Dep`] docstring lists,
15645 // exercising the accessor's accept-set over every author-surface
15646 // `:fonte` shape × every author-surface `:opcional` shape; and by-
15647 // `Copy` idempotency so the projection stays value-return (no
15648 // silent detour to a fresh `&bool` borrow that would introduce a
15649 // lifetime on the return type the plain-`Copy`-scalar axis's `bool`
15650 // shape elides). No composition pin — `:opcional` does not
15651 // participate in [`Dep::validate`] (an opcional dep with any bool
15652 // value is validate-accepted; the missing-source arm is a resolver-
15653 // side runtime dispatch, not a build-time refusal), so the axis
15654 // reduces to the value-shape + `Copy` pin pair the peer
15655 // [`crate::Caixa::max_restarts`] / [`crate::Caixa::estrategia`]
15656 // outer-`Option<Copy>` accessor pins already carry.
15657
15658 #[test]
15659 fn dep_opcional_returns_declared_opcional_across_fonte_shapes() {
15660 // Default-`false` form via the [`Dep::simple`] constructor —
15661 // the accessor projects the `false` bit the default-fill sets.
15662 assert!(!Dep::simple("caixa-teia", "^0.1").opcional());
15663 // Default-`false` form via the [`Dep::git`] constructor — same
15664 // default fill; the accessor projects `false` regardless of the
15665 // `:fonte` arm.
15666 assert!(!Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0").opcional(),);
15667 // Explicit-`true` form × plain-shorthand `:fonte` — the
15668 // canonical author-surface "this dep may be missing" shape.
15669 let plain_true = Dep {
15670 nome: "caixa-teia".to_string(),
15671 versao: "^0.1".to_string(),
15672 fonte: None,
15673 opcional: true,
15674 caracteristicas: Vec::new(),
15675 };
15676 assert!(plain_true.opcional());
15677 // Explicit-`true` form × explicit git-source — the accessor
15678 // projects the bit verbatim regardless of the `:fonte` arm.
15679 let git_true = Dep {
15680 nome: "caixa-teia".to_string(),
15681 versao: "^0.1".to_string(),
15682 fonte: Some(DepSource::Git {
15683 repo: "github:pleme-io/caixa-teia".to_string(),
15684 tag: Some("v0.1.0".to_string()),
15685 rev: None,
15686 branch: None,
15687 }),
15688 opcional: true,
15689 caracteristicas: Vec::new(),
15690 };
15691 assert!(git_true.opcional());
15692 // Explicit-`true` form × explicit path-source — the dev-only
15693 // local-filesystem arm the [`Dep`] docstring's third fixture
15694 // carries.
15695 let path_true = Dep {
15696 nome: "caixa-teia".to_string(),
15697 versao: "0.1.0".to_string(),
15698 fonte: Some(DepSource::Path {
15699 caminho: "../caixa-teia".to_string(),
15700 }),
15701 opcional: true,
15702 caracteristicas: Vec::new(),
15703 };
15704 assert!(path_true.opcional());
15705 }
15706
15707 #[test]
15708 fn dep_opcional_projects_bool_by_copy() {
15709 // The by-`Copy` pin: [`Dep::opcional`] returns `bool` by value
15710 // (`bool: Copy`) — the accessor does not borrow `&self` past
15711 // the call (no lifetime on the return type), and calling the
15712 // accessor twice on the same [`Dep`] must yield discriminant-
15713 // equal values (idempotent, no side effects on `&self`). Peer
15714 // of the sibling outer-`Caixa` `Option<Copy>` by-`Copy`
15715 // `max_restarts_projects_option_by_copy` (eba5211) /
15716 // `estrategia_projects_option_by_copy` (ed04d3c) pins on the
15717 // outer-`Caixa` altitude — extended here to the outer-`Dep`
15718 // altitude's plain-`Copy` `bool` axis. The `Copy` discipline
15719 // replaces the pointer-equality claim the sibling per-`Dep`
15720 // by-borrow pins (`dep_nome_is_by_borrow_pointer_identity`
15721 // eba2cde, `dep_versao_requirement_is_by_borrow_pointer_identity`
15722 // 05529b1, `dep_fonte_is_by_borrow_pointer_identity` d65d1bf,
15723 // `dep_caracteristicas_is_by_borrow_pointer_identity` 9197944)
15724 // carry (a fresh `Copy` of a `Copy` discriminant is definitionally
15725 // the same discriminant, so the axis reduces to discriminant
15726 // equality).
15727 //
15728 // Pins against a future silent detour that returned a fresh
15729 // `&bool` reference (which would type-check but silently
15730 // introduce a borrow of `&self` past the call, collapsing the
15731 // load-bearing "no lifetime on the return type" `Copy`
15732 // projection the plain-`Copy`-scalar axis's `bool` shape
15733 // carries) or a stale-read side effect that flipped the outer
15734 // discriminant on successive calls.
15735 for opcional in [false, true] {
15736 let d = Dep {
15737 nome: "caixa-teia".to_string(),
15738 versao: "^0.1".to_string(),
15739 fonte: None,
15740 opcional,
15741 caracteristicas: Vec::new(),
15742 };
15743 let first = d.opcional();
15744 let second = d.opcional();
15745 assert_eq!(
15746 first, second,
15747 "Dep::opcional must be idempotent — two successive calls \
15748 on the same &self must return the same bool",
15749 );
15750 assert_eq!(
15751 first, opcional,
15752 "Dep::opcional must return :opcional verbatim by Copy — \
15753 got {first}, expected {opcional}",
15754 );
15755 assert_eq!(
15756 d.opcional(),
15757 d.opcional,
15758 "Dep::opcional accessor and self.opcional field access \
15759 must byte-equal — a bit-flip drift would silently split \
15760 the paired resolver-side drop-vs-error dispatch from \
15761 the storage-side default-fill the [`Dep::simple`] / \
15762 [`Dep::git`] constructor pair carries",
15763 );
15764 }
15765 }
15766
15767 // ── DepSource::sole_pin — sole-set git-pin accessor ─────────────────
15768
15769 #[test]
15770 fn sole_pin_returns_none_for_path_source() {
15771 // A path source carries no git-ref, so `sole_pin()` returns
15772 // `None` structurally — the sibling arm every git-fetching
15773 // consumer partitions off before reaching for a git-ref. Pins
15774 // the Path-arm branch of the accessor against a future silent
15775 // detour that treats a `Self::Path` as an unpinned-git source
15776 // and returns the wrong "no pin" signal (e.g. the empty string,
15777 // or a hard-coded `Some("HEAD")` matching the caixa-crd
15778 // path-arm `git_ref` fill).
15779 let s = DepSource::Path {
15780 caminho: "../local-caixa".to_string(),
15781 };
15782 assert_eq!(s.sole_pin(), None);
15783 }
15784
15785 #[test]
15786 fn sole_pin_returns_none_for_unpinned_git_source() {
15787 // The [`DepSource::default_github`] shorthand shape carries no
15788 // pin — every `tag`/`rev`/`branch` is `None`, and `sole_pin()`
15789 // returns `None`. This is the shape caixa-resolver's `fetch_dep`
15790 // materializes when the author omits `:fonte` entirely, then
15791 // hands to `fetch_git` which raises `ResolveError::MissingPin`
15792 // on the `None` arm — the accessor's return matches the arm
15793 // the resolver's diagnostic keys off.
15794 let s = DepSource::default_github("pleme-io", "caixa-teia");
15795 assert_eq!(s.sole_pin(), None);
15796 }
15797
15798 #[test]
15799 fn sole_pin_returns_rev_when_only_rev_is_set() {
15800 let s = DepSource::Git {
15801 repo: "github:o/x".into(),
15802 tag: None,
15803 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15804 branch: None,
15805 };
15806 assert_eq!(
15807 s.sole_pin(),
15808 Some("deadbeefcafebabe1234567890abcdef12345678")
15809 );
15810 }
15811
15812 #[test]
15813 fn sole_pin_returns_tag_when_only_tag_is_set() {
15814 let s = DepSource::Git {
15815 repo: "github:o/x".into(),
15816 tag: Some("v0.1.0".into()),
15817 rev: None,
15818 branch: None,
15819 };
15820 assert_eq!(s.sole_pin(), Some("v0.1.0"));
15821 }
15822
15823 #[test]
15824 fn sole_pin_returns_branch_when_only_branch_is_set() {
15825 let s = DepSource::Git {
15826 repo: "github:o/x".into(),
15827 tag: None,
15828 rev: None,
15829 branch: Some("main".into()),
15830 };
15831 assert_eq!(s.sole_pin(), Some("main"));
15832 }
15833
15834 #[test]
15835 fn sole_pin_precedence_rev_beats_tag_and_branch() {
15836 // Precedence: rev > tag > branch. Validate() rejects
15837 // multiple-pin shapes, but the accessor's precedence is defined
15838 // for pre-validate consumers (the resolver's `MissingPin`
15839 // diagnostic path, the caixa-crd round-trip's default `"main"`
15840 // fallback) and as defense-in-depth if the gate is ever
15841 // bypassed. Pins the same precedence caixa-resolver's
15842 // `fetch_git` and caixa-crd's `dep_into_ref` already apply
15843 // inline.
15844 let s = DepSource::Git {
15845 repo: "github:o/x".into(),
15846 tag: Some("v1".into()),
15847 rev: Some("deadbeefcafebabe1234567890abcdef12345678".into()),
15848 branch: Some("main".into()),
15849 };
15850 assert_eq!(
15851 s.sole_pin(),
15852 Some("deadbeefcafebabe1234567890abcdef12345678")
15853 );
15854 }
15855
15856 #[test]
15857 fn sole_pin_precedence_tag_beats_branch_when_no_rev() {
15858 let s = DepSource::Git {
15859 repo: "github:o/x".into(),
15860 tag: Some("v1".into()),
15861 rev: None,
15862 branch: Some("main".into()),
15863 };
15864 assert_eq!(s.sole_pin(), Some("v1"));
15865 }
15866
15867 #[test]
15868 fn sole_pin_byte_equals_inline_rev_or_tag_or_branch_cascade() {
15869 // Fail-before-pass-after byte-parity pin: the substrate accessor
15870 // must return byte-identical to the inline
15871 // `rev.as_deref().or(tag.as_deref()).or(branch.as_deref())`
15872 // cascade both caixa-resolver's `fetch_git` and caixa-crd's
15873 // `dep_into_ref` open-coded pre-lift. Trips at caixa-core build
15874 // time if the accessor's precedence silently drifts from the
15875 // consumer-side cascade — the exact drift this lift converges
15876 // to one substrate primitive to close structurally.
15877 //
15878 // Iterates through the 2^3 = 8 combinations of (tag, rev,
15879 // branch) each-either-`None`-or-`Some`, so every arm of the
15880 // precedence cascade lands under the pin. `validate()` refuses
15881 // the 4 multi-pin combinations, but the accessor's return is
15882 // defined on all 8.
15883 let vals = [Some("R".to_string()), None];
15884 for tag in &vals {
15885 for rev in &vals {
15886 for branch in &vals {
15887 let s = DepSource::Git {
15888 repo: "github:o/x".into(),
15889 tag: tag.clone(),
15890 rev: rev.clone(),
15891 branch: branch.clone(),
15892 };
15893 // The exact inline cascade the two pre-lift
15894 // consumer sites hand-rolled, byte-for-byte.
15895 let expected = rev.as_deref().or(tag.as_deref()).or(branch.as_deref());
15896 assert_eq!(
15897 s.sole_pin(),
15898 expected,
15899 "sole_pin() must byte-equal \
15900 rev.or(tag).or(branch) for \
15901 (tag={tag:?}, rev={rev:?}, branch={branch:?}) — \
15902 a drift would silently split caixa-resolver's \
15903 fetch_git checkout target from caixa-crd's \
15904 dep_into_ref git_ref fill",
15905 );
15906 }
15907 }
15908 }
15909 }
15910}
15911
15912#[cfg(test)]
15913mod dep_source_is_variant_tests {
15914 use super::*;
15915
15916 fn all_variants() -> Vec<(DepSource, &'static str)> {
15917 vec![
15918 (
15919 DepSource::Git {
15920 repo: "github:pleme-io/caixa-teia".into(),
15921 tag: Some("v0.1.0".into()),
15922 rev: None,
15923 branch: None,
15924 },
15925 "Git",
15926 ),
15927 (
15928 DepSource::Path {
15929 caminho: "../caixa-teia".into(),
15930 },
15931 "Path",
15932 ),
15933 ]
15934 }
15935
15936 fn predicate_row(s: &DepSource) -> [bool; 2] {
15937 [s.is_git(), s.is_path()]
15938 }
15939
15940 // Fail-before-pass-after pin on the [`gen_platform::IsVariant`]
15941 // derive-generated per-arm predicate partition — for every variant
15942 // in `all_variants()`, the observed 2-slot predicate row must equal
15943 // a one-hot row with the `true` at exactly the same index as the
15944 // variant's declaration order. Expected rows are generated live
15945 // from the enumeration rather than transcribed by hand, so a
15946 // copy-paste flip that reroutes one arm through the wrong predicate
15947 // lane trips at the identity-diagonal assertion the way every peer
15948 // sibling [`DepList`] / [`crate::CaixaKind`] / [`crate::CaixaDialeto`]
15949 // / [`crate::supervisor::RestartStrategy`] / [`crate::supervisor::RestartPolicy`]
15950 // / [`crate::upgrade::UpgradeInstruction`] /
15951 // [`crate::aplicacao::PlacementStrategy`] /
15952 // [`crate::aplicacao::RateLimitUnit`] /
15953 // [`crate::aplicacao::WitTarget`] /
15954 // [`crate::render::PathShapeViolation`] partition pin already does.
15955 #[test]
15956 fn dep_source_is_variant_predicates_partition_the_arm_set() {
15957 let variants = all_variants();
15958 for (idx, (variant, name)) in variants.iter().enumerate() {
15959 let observed = predicate_row(variant);
15960 let mut expected = [false; 2];
15961 expected[idx] = true;
15962 assert_eq!(
15963 observed, expected,
15964 "DepSource::{name} at declaration-order slot {idx} must \
15965 satisfy exactly one is_* predicate (its own); observed \
15966 row must equal the one-hot expected row — a drift \
15967 would silently reroute one `:fonte`-arm consumer \
15968 through the wrong predicate lane"
15969 );
15970 }
15971 }
15972
15973 // Byte-parity pin on the two field-agnostic `matches!` shapes the
15974 // per-arm arm-discriminator predicates replace at any future
15975 // consumer site (a `:fonte`-shape-only lint rule that flags path
15976 // deps outside dev-caixas via `dep.fonte().is_some_and(DepSource::is_path)`,
15977 // a future admission-webhook that rejects `:fonte` shapes outside
15978 // the `is_git()` accept-set, a caixa-lacre indexing pass that
15979 // dispatches on `s.is_git()` without extracting `repo` / `caminho`).
15980 // Refuses a future accidental split between the derived predicate
15981 // and its `matches!` shape — a hand-rolled shadow impl that
15982 // overrides one path, an accidental rebrand that leaves one
15983 // consumer on the raw `matches!` form — on the two load-bearing
15984 // `:fonte`-arm-discriminator axes every downstream substrate
15985 // consumer of the dep-source axis keys off.
15986 #[test]
15987 fn dep_source_is_git_and_is_path_byte_equal_matches_shape() {
15988 for (variant, name) in all_variants() {
15989 let via_matches_git = matches!(variant, DepSource::Git { .. });
15990 let via_predicate_git = variant.is_git();
15991 assert_eq!(
15992 via_predicate_git, via_matches_git,
15993 "DepSource::{name}.is_git() must byte-equal \
15994 matches!(_, DepSource::Git {{ .. }}) — otherwise a \
15995 future converged consumer site would silently \
15996 disagree with its pre-lift shape"
15997 );
15998 let via_matches_path = matches!(variant, DepSource::Path { .. });
15999 let via_predicate_path = variant.is_path();
16000 assert_eq!(
16001 via_predicate_path, via_matches_path,
16002 "DepSource::{name}.is_path() must byte-equal \
16003 matches!(_, DepSource::Path {{ .. }}) — otherwise a \
16004 future converged consumer site would silently \
16005 disagree with its pre-lift shape"
16006 );
16007 }
16008 }
16009
16010 // Cross-pin against every constructor path that materializes a
16011 // [`DepSource`] shape today (the [`DepSource::default_github`]
16012 // resolver-side fallback that materializes an unpinned
16013 // `github:<org>/<nome>` git shorthand, the [`Dep::git`] author-
16014 // surface constructor that materializes a pinned `:tag`-carrying
16015 // `DepSource::Git`, a hand-rolled `DepSource::Path` the dev-mode
16016 // fixture family builds inline). Every constructor's return must
16017 // satisfy the arm-discriminator predicate the constructor's
16018 // variant name matches — a future constructor addition (an
16019 // in-tree registry-fetch pin, a `DepSource::Feira` variant the
16020 // enclosing docstring already names as a trajectory item) surfaces
16021 // as a build-time failure that names the offending drift when its
16022 // return arm doesn't route through the paired predicate.
16023 #[test]
16024 fn dep_source_constructors_route_through_paired_is_variant_predicate() {
16025 let via_default_github = DepSource::default_github("pleme-io", "caixa-teia");
16026 assert!(
16027 via_default_github.is_git(),
16028 "DepSource::default_github must materialize a Git-arm shape — \
16029 a future constructor that routed through a non-Git arm \
16030 (a registry-fetch pin, a `DepSource::Feira` promotion) \
16031 would silently split the resolver's unpinned-shorthand \
16032 materializer from the sole_pin() precedence cascade"
16033 );
16034 assert!(
16035 !via_default_github.is_path(),
16036 "DepSource::default_github must NOT materialize a Path-arm \
16037 shape — the paired negation pin"
16038 );
16039
16040 let via_dep_git = Dep::git("caixa-teia", "^0.1", "github:pleme-io/caixa-teia", "v0.1.0")
16041 .fonte
16042 .expect("Dep::git materializes a Some(fonte)");
16043 assert!(
16044 via_dep_git.is_git(),
16045 "Dep::git's `:fonte` materialization must land on the Git \
16046 arm — the author-surface pinned-git constructor's return \
16047 must route through the paired predicate"
16048 );
16049 assert!(!via_dep_git.is_path(), "paired negation pin");
16050
16051 let via_path = DepSource::Path {
16052 caminho: "../caixa-teia".into(),
16053 };
16054 assert!(
16055 via_path.is_path(),
16056 "the dev-mode Path-arm materialization must satisfy is_path()"
16057 );
16058 assert!(!via_path.is_git(), "paired negation pin");
16059 }
16060}