1use std::borrow::Cow;
17use std::cell::RefCell;
18
19pub mod anchor;
20pub mod folder;
21pub(crate) use folder::judging;
22mod home;
23pub mod item_shape;
24mod lexical;
25mod physical;
26mod placing;
27mod vars;
28pub use item_shape::{Binding, Facts, ItemShape, ItemShapeGuard, binding, enter_loop_shape, enter_stdin_shape, loop_shape, stdin_shape};
29use lexical::{expand_home, lexical_join, names_no_known_directory};
30pub(crate) use placing::on_the_link;
31use placing::resolve_placed;
32pub use vars::{LoopGuard, VarGuard, enter_loop_var, enter_var, expand_vars, names_a_loop_var};
33
34#[derive(Clone, Default)]
38pub struct PathCtx {
39 pub cwd: Option<String>,
40 pub root: Option<String>,
41 pub session_id: Option<String>,
44}
45
46thread_local! {
47 static CURRENT: RefCell<PathCtx> = RefCell::new(PathCtx::default());
48}
49
50#[must_use]
53pub fn enter(ctx: PathCtx) -> Guard {
54 Guard(CURRENT.with(|c| c.replace(ctx)))
55}
56
57pub struct Guard(PathCtx);
59
60impl Drop for Guard {
61 fn drop(&mut self) {
62 CURRENT.with(|c| *c.borrow_mut() = std::mem::take(&mut self.0));
63 }
64}
65
66#[must_use]
69pub fn enter_cwd(cwd: Option<String>) -> Guard {
70 Guard(CURRENT.with(|c| {
71 let mut b = c.borrow_mut();
72 PathCtx { cwd: std::mem::replace(&mut b.cwd, cwd), root: b.root.clone(), session_id: b.session_id.clone() }
75 }))
76}
77
78pub fn cwd() -> Option<String> {
80 CURRENT.with(|c| c.borrow().cwd.clone())
81}
82
83pub fn root() -> Option<String> {
86 CURRENT.with(|c| {
87 let b = c.borrow();
88 b.root.clone().or_else(|| b.cwd.clone())
89 })
90}
91
92pub fn in_session_scratchpad(path: &str) -> bool {
113 let Some(id) = CURRENT.with(|c| c.borrow().session_id.clone()) else {
114 return false;
115 };
116 if id.len() < 8 || !id.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') {
119 return false;
120 }
121 if !under_temp_root(path) {
122 return false;
123 }
124 path.split('/').any(|seg| seg == id)
125}
126
127const TEMP_ROOTS: &[&str] = &["/tmp/", "/private/tmp/", "/var/tmp/", "/private/var/tmp/"];
128const TEMP_ROOTS_ANY_CASE: &[&str] =
129 &["/tmp/", "/private/tmp/", "/var/tmp/", "/private/var/tmp/", "/var/folders/", "/private/var/folders/"];
130
131pub fn under_temp_root(path: &str) -> bool {
138 if TEMP_ROOTS.iter().any(|r| path.starts_with(r)) {
139 return true;
140 }
141 std::env::var("TMPDIR").ok().is_some_and(|t| {
142 let t = t.trim_end_matches('/');
143 !t.is_empty() && t.starts_with('/') && path.starts_with(&format!("{t}/"))
144 })
145}
146
147pub fn under_temp(path: &str) -> bool {
152 let folded = strip_data_volume(path).to_ascii_lowercase();
153 let dir = if folded.ends_with('/') { folded } else { format!("{folded}/") };
154 TEMP_ROOTS_ANY_CASE.iter().any(|root| dir.starts_with(root)) || tmpdir_spellings().iter().any(|root| dir.starts_with(root))
155}
156
157fn strip_data_volume(path: &str) -> String {
158 let mut rest = path;
159 const PREFIX: &str = "/system/volumes/data";
160 while rest.get(..PREFIX.len()).is_some_and(|head| head.eq_ignore_ascii_case(PREFIX)) {
162 let after = &rest[PREFIX.len()..];
163 if after.is_empty() || after.starts_with('/') {
164 rest = after;
165 continue;
166 }
167 break;
168 }
169 rest.to_string()
170}
171
172fn tmpdir_spellings() -> Vec<String> {
173 let Ok(raw) = std::env::var("TMPDIR") else { return Vec::new() };
174 let dir = raw.trim_end_matches('/').to_ascii_lowercase();
175 if dir.len() <= 1 || !dir.starts_with('/') {
176 return Vec::new();
177 }
178 let mut out = vec![format!("{dir}/")];
179 if let Some(rest) = dir.strip_prefix("/private/") {
180 out.push(format!("/{rest}/"));
181 } else if dir == "/tmp" || dir.starts_with("/tmp/") || dir == "/var" || dir.starts_with("/var/") {
182 out.push(format!("/private{dir}/"));
183 }
184 out
185}
186
187pub(crate) fn physical_directory(path: &str) -> String {
189 if !path.starts_with('/') {
190 return path.to_string();
191 }
192 physical::resolve(path, true).unwrap_or_else(|| path.to_string())
193}
194
195thread_local! {
196 static STDIN_REPR: RefCell<Vec<String>> = const { RefCell::new(Vec::new()) };
197}
198
199#[must_use]
204pub fn enter_stdin_repr(repr: String) -> StdinReprGuard {
205 STDIN_REPR.with(|v| v.borrow_mut().push(repr));
206 StdinReprGuard
207}
208
209pub fn stdin_item_repr() -> Option<String> {
212 STDIN_REPR.with(|v| v.borrow().last().cloned())
213}
214
215pub struct StdinReprGuard;
216
217impl Drop for StdinReprGuard {
218 fn drop(&mut self) {
219 STDIN_REPR.with(|v| {
220 v.borrow_mut().pop();
221 });
222 }
223}
224
225pub fn resolve(path: &str) -> Cow<'_, str> {
237 resolve_placed(path, None)
238}
239
240pub fn resolve_for(path: &str, use_: anchor::Use) -> Cow<'_, str> {
243 if use_.mutates() {
244 folder::note_named_write();
245 }
246 resolve_placed(path, Some(use_))
247}
248
249pub(crate) const UNRESOLVED_CWD: &str = "/__SAFE_CHAINS_CMDSUB__";
252
253pub fn join_cwd(cur: Option<&str>, target: &str) -> Option<String> {
268 join_cwd_mode(cur, target, false)
269}
270
271pub fn join_cwd_mode(cur: Option<&str>, target: &str, physical: bool) -> Option<String> {
272 let expanded = match expand_home(target) {
273 Some(t) => t,
274 None => return Some(UNRESOLVED_CWD.to_string()), };
276 if names_no_known_directory(&expanded) {
284 return Some(UNRESOLVED_CWD.to_string());
285 }
286 let raw = if let Some(landed) = declared_substitution_directory(cur, &expanded) {
287 landed
288 } else if expanded.starts_with('/') {
289 expanded.into_owned()
290 } else {
291 let c = cur.filter(|c| c.starts_with('/'))?;
292 format!("{c}/{expanded}")
293 };
294 Some(if physical { physical::resolve(&raw, true).unwrap_or_else(|| lexical_join("/", &raw)) } else { lexical_join("/", &raw) })
295}
296
297fn declared_substitution_directory(cur: Option<&str>, expanded: &str) -> Option<String> {
299 use crate::engine::facet::{FacetTerm, LocalLocus};
300 let after = expanded.strip_prefix(crate::cst::eval::TAGGED_PREFIX)?;
301 let (term, tail) = after.split_once("__").unwrap_or(("", ""));
302 let Some(tag) = LocalLocus::from_term(&term.to_lowercase().replace('_', "-")) else {
303 return Some(UNRESOLVED_CWD.to_string());
304 };
305 let Some(cur) = cur.filter(|c| c.starts_with('/') && *c != UNRESOLVED_CWD) else {
306 return Some(UNRESOLVED_CWD.to_string());
307 };
308 let here = crate::engine::resolve::locus::read_locus(cur);
309 if here == tag {
310 let rel = tail.trim_start_matches('/');
311 return Some(if rel.is_empty() { cur.to_string() } else { lexical::lexical_join(cur, rel) });
312 }
313 let in_band = |locus: LocalLocus| locus >= LocalLocus::SandboxScope && locus <= LocalLocus::WorktreeTrusted;
314 if in_band(tag) && !in_band(here) {
315 return Some(UNRESOLVED_CWD.to_string());
316 }
317 let base = match tag {
318 LocalLocus::Temp => "/tmp",
319 _ => return Some(UNRESOLVED_CWD.to_string()),
320 };
321 let rel = tail.trim_start_matches('/');
322 Some(if rel.is_empty() { base.to_string() } else { lexical::lexical_join(base, rel) })
323}
324
325#[cfg(test)]
326mod tests {
327 use super::*;
328
329 const SID: &str = "7676dbc5-a265-43b3-a0f8-49666792bd9b";
330
331 fn with_session<T>(id: Option<&str>, f: impl FnOnce() -> T) -> T {
332 let _g = enter(PathCtx { cwd: Some("/home/u/proj".into()), root: Some("/home/u/proj".into()), session_id: id.map(str::to_string) });
333 f()
334 }
335
336 #[test]
341 fn only_this_sessions_scratchpad_is_recognized() {
342 let scratch = format!("/private/tmp/claude-501/-Users-u-proj/{SID}/scratchpad");
343 let matching: &[String] = &[
344 format!("{scratch}/build.sh"),
345 format!("{scratch}/nested/deep/gen.py"),
346 scratch.clone(),
347 format!("/tmp/{SID}/x.sh"),
349 format!("/tmp/some-other-harness/{SID}/work/x.sh"),
350 format!("/var/tmp/{SID}/x.sh"),
351 ];
352 let rejected: &[String] = &[
353 "/private/tmp/claude-501/-Users-u-proj/00000000-1111-2222-3333-444444444444/scratchpad/x.sh".into(),
355 format!("/tmp/{SID}-evil/x.sh"),
357 format!("/tmp/evil-{SID}/x.sh"),
358 format!("/tmp/a{SID}/x.sh"),
359 format!("/home/u/{SID}/x.sh"),
361 format!("~/.ssh/{SID}/id_rsa"),
362 format!("/etc/{SID}/passwd"),
363 "/tmp/evil.sh".into(),
365 "/private/tmp/downloaded.sh".into(),
366 format!("/TMP/{SID}/x.sh"),
369 format!("/System/Volumes/Data/tmp/{SID}/x.sh"),
370 format!("/private/var/folders/xx/yy/T/{SID}/x.sh"),
371 ];
372 with_session(Some(SID), || {
373 for p in matching {
374 assert!(in_session_scratchpad(p), "should be recognized: {p}");
375 }
376 for p in rejected {
377 assert!(!in_session_scratchpad(p), "must NOT be recognized: {p}");
378 }
379 });
380 }
381
382 #[test]
385 fn a_missing_or_unusable_session_id_recognizes_nothing() {
386 let path = format!("/tmp/{SID}/x.sh");
387 with_session(None, || {
388 assert!(!in_session_scratchpad(&path), "no session id → no recognition");
389 });
390 for weak in ["", "abc", "1234567", "..", "/", "a/b", "id with space", "x*y"] {
391 with_session(Some(weak), || {
392 assert!(!in_session_scratchpad(&format!("/tmp/{weak}/x.sh")), "weak id {weak:?} must not anchor recognition",);
393 });
394 }
395 }
396
397 #[test]
398 fn under_temp_never_slices_inside_a_multibyte_character() {
399 let prefix = "/system/volumes/data";
400 for filler in ["\u{fffd}", "\u{e9}", "\u{1f600}"] {
401 for cut in 0..=prefix.len() {
402 let path = format!("{}{filler}{}", &prefix[..cut], &prefix[cut..]);
403 assert!(!under_temp(&path), "{path}");
404 }
405 }
406 assert!(under_temp("/System/Volumes/Data/tmp/x"));
407 }
408
409 #[test]
410 fn under_temp_folds_case_firmlinks_and_var_folders_without_admitting_them() {
411 for path in [
412 "/TMP/y", "/Tmp/y", "/PRIVATE/TMP/y", "/private/TMP/y", "/System/Volumes/Data/tmp/y", "/System/Volumes/Data/private/tmp/y",
413 "/private/var/folders/xx/yy/T/y", "/var/folders/xx/yy/T/y", "/VAR/folders/xx/yy/T/y", "/Var/Folders/xx/yy/T/y",
414 ] {
415 assert!(under_temp(path), "{path}");
416 assert!(crate::engine::resolve::locus::under_temp(path), "locus: {path}");
417 assert!(!under_temp_root(path), "exact prefix must stay strict: {path}");
418 }
419 assert!(under_temp("/tmp/y"));
420 assert!(under_temp_root("/tmp/y"));
421 assert!(!under_temp("/etc/y"));
422 assert!(!under_temp("/tmpfile/y"));
423 }
424
425 #[test]
426 fn no_context_leaves_paths_unchanged() {
427 assert_eq!(resolve("./x"), "./x");
428 assert_eq!(resolve("config"), "config");
429 assert_eq!(resolve("/etc/x"), "/etc/x");
430 }
431
432 #[test]
433 fn relative_inside_the_project_stays_worktree_relative() {
434 let _g = enter(PathCtx { cwd: Some("/home/u/proj/sub".into()), root: Some("/home/u/proj".into()), ..Default::default() });
435 assert_eq!(resolve("x"), "sub/x", "cwd under root → root-relative");
436 assert_eq!(resolve("./y"), "sub/y");
437 assert_eq!(resolve("../z"), "z", ".. that stays inside root");
438 }
439
440 #[test]
441 fn relative_outside_the_project_becomes_absolute() {
442 let _g = enter(PathCtx { cwd: Some("/etc".into()), root: Some("/home/u/proj".into()), ..Default::default() });
443 assert_eq!(resolve("x"), "/etc/x", "cd /etc → the real target");
444 assert_eq!(resolve("passwd"), "/etc/passwd");
445 assert_eq!(resolve("no-such-dir/*"), "/etc/no-such-dir/*");
446 }
447
448 #[test]
449 fn dotdot_escaping_the_project_becomes_absolute() {
450 let _g = enter(PathCtx { cwd: Some("/home/u/proj".into()), root: Some("/home/u/proj".into()), ..Default::default() });
451 assert_eq!(resolve("../../../etc/x"), "/etc/x");
452 }
453
454 #[test]
455 fn absolute_in_root_becomes_root_relative_outside_stays_absolute() {
456 let _g = enter(PathCtx { cwd: Some("/home/u/proj/sub".into()), root: Some("/home/u/proj".into()), ..Default::default() });
457 assert_eq!(resolve("/home/u/proj/main.rs"), "main.rs");
459 assert_eq!(resolve("/home/u/proj/sub/x"), "sub/x");
460 assert_eq!(resolve("/home/u/proj/a/../b"), "b", "normalized in place");
461 assert_eq!(resolve("/home/u/proj"), ".", "the project root itself");
462 assert_eq!(resolve("/usr/bin/x"), "/usr/bin/x");
464 assert_eq!(resolve("/home/u/proj/../../etc/x"), "/home/etc/x", "climbs to /home, still outside root");
465 assert_eq!(resolve("/home/u/proj/../../../etc/x"), "/etc/x", "escapes to /etc via ..");
466 assert_eq!(
467 resolve("/home/u/proj-evil/secret"),
468 "/home/u/proj-evil/secret",
469 "a sibling dir is not confused for inside by bare string prefix",
470 );
471 assert_eq!(resolve("$HOME/x"), "$HOME/x");
473 assert_eq!(resolve("~/x"), "~/x");
474 }
475
476 #[test]
477 fn a_home_spelled_path_inside_root_becomes_root_relative() {
478 let Some(home) = std::env::var("HOME").ok().filter(|h| h.starts_with('/') && h.len() > 1) else {
479 return;
480 };
481 let root = format!("{home}/projects/app");
482 let _g = enter(PathCtx { cwd: Some(format!("{root}/sub")), root: Some(root), ..Default::default() });
483 assert_eq!(resolve("~/projects/app/src/main.rs"), "src/main.rs");
484 assert_eq!(resolve("~/projects/app"), ".");
485 assert_eq!(resolve("~/projects/app/"), ".");
486 let under = |rest: &str| format!("~/projects/{rest}");
487 assert_eq!(resolve(&under("app/a/../b")), "b");
488 assert_eq!(resolve(&under("app/.git/hooks/pre-commit")), ".git/hooks/pre-commit");
489 for (outside, why) in [("peer/x", "a sibling"), ("app-evil/x", "no bare string prefix"), ("app/../../.ssh/id_rsa", "an escape")] {
490 assert_eq!(resolve(&under(outside)), under(outside), "{why} stays home-spelled");
491 }
492 assert_eq!(resolve("~/.ssh/id_rsa"), "~/.ssh/id_rsa");
493 assert_eq!(resolve("~"), "~");
494 assert_eq!(resolve("~bob/projects/app/x"), "~bob/projects/app/x", "another user's home is not ours");
495 }
496
497 #[test]
498 fn a_home_spelled_path_needs_an_absolute_root() {
499 let _none = enter(PathCtx { cwd: Some("/w".into()), root: None, ..Default::default() });
500 assert_eq!(resolve("~/x"), "~/x");
501 drop(_none);
502 let _rel = enter(PathCtx { cwd: Some("/w".into()), root: Some("w".into()), ..Default::default() });
503 assert_eq!(resolve("~/x"), "~/x");
504 }
505
506 #[test]
507 fn a_home_rooted_workspace_leaves_home_paths_to_the_home_classifiers() {
508 let Some(home) = std::env::var("HOME").ok().filter(|h| h.starts_with('/') && h.len() > 1) else {
509 return;
510 };
511 let _g = enter(PathCtx { cwd: Some(home.clone()), root: Some(home.clone()), ..Default::default() });
512 assert_eq!(resolve("~"), "~");
513 assert_eq!(resolve("~/notes.txt"), "~/notes.txt");
514 assert_eq!(resolve("notes.txt"), format!("{home}/notes.txt"));
515 assert_eq!(resolve("."), home);
516 }
517
518 #[test]
519 fn a_home_spelled_path_is_not_resolved_from_outside_the_root_or_through_a_glob() {
520 let Some(home) = std::env::var("HOME").ok().filter(|h| h.starts_with('/') && h.len() > 1) else {
521 return;
522 };
523 let root = format!("{home}/projects/app");
524 let outside = enter(PathCtx { cwd: Some("/etc".into()), root: Some(root.clone()), ..Default::default() });
525 assert_eq!(resolve("~/projects/app/x"), "~/projects/app/x", "a quoted `~` would name a directory under the cwd");
526 drop(outside);
527 let _g = enter(PathCtx { cwd: Some(root.clone()), root: Some(root), ..Default::default() });
528 for glob in ["app/.ss?/id_rsa", "app/*"].map(|rest| format!("~/projects/{rest}")) {
529 assert_eq!(resolve(&glob), glob);
530 }
531 }
532
533 #[test]
534 fn a_home_spelled_path_is_not_resolved_into_a_protected_root() {
535 let Some(home) = std::env::var("HOME").ok().filter(|h| h.starts_with('/') && h.len() > 1) else {
536 return;
537 };
538 let root = format!("{home}/.ssh");
539 let _g = enter(PathCtx { cwd: Some(root.clone()), root: Some(root), ..Default::default() });
540 assert_eq!(resolve("~/.ssh/id_rsa"), "~/.ssh/id_rsa");
541 }
542
543 #[test]
544 fn a_root_holding_a_protected_place_keeps_every_path_absolute() {
545 let _g = enter(PathCtx { cwd: Some("/".into()), root: Some("/".into()), ..Default::default() });
546 assert_eq!(resolve("/etc/shadow"), "/etc/shadow");
547 assert_eq!(resolve("etc/sudoers"), "/etc/sudoers");
548 assert_eq!(resolve("etc"), "/etc");
549 assert_eq!(resolve("/srv/app/x"), "/srv/app/x");
550 assert_eq!(resolve("."), "/");
551 drop(_g);
552 let _etc = enter(PathCtx { cwd: Some("/etc".into()), root: Some("/etc".into()), ..Default::default() });
553 assert_eq!(resolve("hosts"), "hosts", "an unprotected file in a root below every home is the worktree");
554 assert_eq!(resolve("sudoers"), "/etc/sudoers");
555 assert_eq!(resolve("."), "/etc", "the root itself is above a protected place");
556 drop(_etc);
557 let _inside = enter(PathCtx { cwd: Some("/root/app".into()), root: Some("/root/app".into()), ..Default::default() });
558 assert_eq!(resolve("/root/app/x"), "x", "a root inside the protected place is where the user works");
559 }
560
561 #[test]
562 fn loop_var_expands_to_its_representative_per_face() {
563 let _g = enter_loop_var("f".into(), "read_item".into(), "write_item".into());
564 assert_eq!(expand_vars("$f", false), "read_item");
565 assert_eq!(expand_vars("$f", true), "write_item");
566 assert_eq!(expand_vars("${f}", false), "read_item");
567 assert_eq!(expand_vars("$f.bak", false), "read_item.bak", "compound suffix");
568 assert_eq!(expand_vars("pre/$f", false), "pre/read_item");
569 assert_eq!(expand_vars("$foo", false), "$foo", "$foo is not $f");
570 assert_eq!(expand_vars("$g", false), "$g", "unbound var untouched");
571 assert_eq!(expand_vars("plain", false), "plain");
572 }
573
574 #[test]
575 fn loop_var_binding_is_scoped_and_nests() {
576 assert_eq!(expand_vars("$f", false), "$f", "no binding");
577 {
578 let _outer = enter_loop_var("f".into(), "outer".into(), "outer".into());
579 {
580 let _inner = enter_loop_var("f".into(), "inner".into(), "inner".into());
581 assert_eq!(expand_vars("$f", false), "inner", "innermost wins");
582 }
583 assert_eq!(expand_vars("$f", false), "outer", "inner popped on drop");
584 }
585 assert_eq!(expand_vars("$f", false), "$f", "all popped");
586 }
587
588 #[test]
589 fn the_guard_restores_on_drop() {
590 {
591 let _g = enter(PathCtx { cwd: Some("/etc".into()), root: Some("/r".into()), ..Default::default() });
592 assert_eq!(resolve("x"), "/etc/x");
593 }
594 assert_eq!(resolve("x"), "x", "context cleared after the guard drops");
595 }
596
597 const PROBE_VAR: &str = "SAFE_CHAINS_TMPDIR_PROBE_PATH";
598
599 fn tmpdir_verdict(tmpdir: &str, path: &str) -> bool {
600 let out = std::process::Command::new(std::env::current_exe().expect("test exe"))
601 .args(["--exact", "pathctx::tests::tmpdir_probe", "--nocapture", "--test-threads=1"])
602 .env("TMPDIR", tmpdir)
603 .env(PROBE_VAR, path)
604 .output()
605 .expect("spawn probe");
606 let stdout = String::from_utf8_lossy(&out.stdout);
607 assert!(out.status.success(), "probe failed for TMPDIR={tmpdir:?} path={path:?}: {stdout}");
608 match (stdout.contains("PROBE_VERDICT=true"), stdout.contains("PROBE_VERDICT=false")) {
609 (true, false) => true,
610 (false, true) => false,
611 _ => panic!("probe did not run for TMPDIR={tmpdir:?} path={path:?}: {stdout}"),
612 }
613 }
614
615 #[test]
616 fn tmpdir_probe() {
617 let Ok(path) = std::env::var(PROBE_VAR) else {
618 return;
619 };
620 println!("PROBE_VERDICT={}", under_temp_root(&path));
621 }
622
623 #[test]
624 fn a_tmpdir_root_counts_only_when_absolute_and_non_empty() {
625 for (tmpdir, path, expected) in [
626 ("/work/scratch", "/work/scratch/x.sh", true),
627 ("/work/scratch/", "/work/scratch/x.sh", true),
628 ("/work/scratch//", "/work/scratch/nested/x.sh", true),
629 ("/work/scratch", "/work/scratch", false),
630 ("/work/scratch", "/work/scratchy/x.sh", false),
631 ("/work/scratch", "/work/other/x.sh", false),
632 ("/work/scratch", "work/scratch/x.sh", false),
633 ("", "/x.sh", false),
634 ("", "/", false),
635 ("/", "/x.sh", false),
636 ("//", "/x.sh", false),
637 ("scratch", "scratch/x.sh", false),
638 ("scratch/", "scratch/x.sh", false),
639 ("./scratch", "./scratch/x.sh", false),
640 ("$SCRATCH", "$SCRATCH/x.sh", false),
641 ("relative/dir", "relative/dir/x.sh", false),
642 ] {
643 assert_eq!(tmpdir_verdict(tmpdir, path), expected, "TMPDIR={tmpdir:?} path={path:?}");
644 }
645 }
646
647 #[test]
648 fn the_fixed_temp_roots_hold_whatever_tmpdir_says() {
649 for tmpdir in ["", "scratch", "/work/scratch"] {
650 for path in ["/tmp/x", "/private/tmp/x", "/var/tmp/x", "/private/var/tmp/x"] {
651 assert!(tmpdir_verdict(tmpdir, path), "TMPDIR={tmpdir:?} path={path:?}");
652 }
653 assert!(!tmpdir_verdict(tmpdir, "/tmp"), "the bare root is not under itself");
654 }
655 }
656}