1use std::path::{Component, Path, PathBuf};
55
56use serde::Deserialize;
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Default)]
59#[serde(rename_all = "lowercase")]
60pub enum Share {
61 #[default]
63 Team,
64 Local,
66}
67
68#[derive(Debug, Clone, Deserialize)]
69pub struct Entry {
70 pub name: String,
71 pub paths: Vec<String>,
72 #[serde(default)]
73 pub share: Share,
74 #[serde(default)]
77 pub experts: Vec<ExpertSource>,
78 #[serde(default)]
82 pub relay: Option<String>,
83 #[serde(default)]
87 pub mode: Option<String>,
88 #[serde(default)]
93 pub budget: Option<serde_json::Value>,
94 #[serde(default)]
101 pub risk: Option<serde_json::Value>,
102}
103
104impl Entry {
105 #[must_use]
107 pub fn budget(&self) -> Option<f64> {
108 self.budget.as_ref()?.as_f64().filter(|b| *b > 0.0)
109 }
110
111 #[must_use]
113 pub fn risk(&self) -> Option<f64> {
114 self.risk.as_ref()?.as_f64().filter(|r| (0.0..=1.0).contains(r))
115 }
116}
117
118#[derive(Debug, Clone, Deserialize)]
122pub struct ExpertSource {
123 pub name: String,
124 pub repo: String,
125 #[serde(rename = "match", default)]
126 pub matches: Vec<String>,
127 #[serde(default)]
130 pub drone: bool,
131}
132
133impl ExpertSource {
134 pub fn path(&self) -> PathBuf {
136 expand(&self.repo)
137 }
138}
139
140impl Config {
141 pub fn experts_for(&self, cwd: &str) -> Vec<&ExpertSource> {
144 let Route::Collective { name, .. } = route(Some(self), cwd, Path::new("/")) else { return Vec::new() };
145 let Some(c) = self.collectives.iter().find(|c| c.name == name) else { return Vec::new() };
146 c.experts.iter().filter(|e| self.may_consult(&c.name, e)).collect()
147 }
148
149 pub fn may_consult(&self, collective: &str, e: &ExpertSource) -> bool {
155 let p = e.path();
156 let real = p.canonicalize().ok();
157 std::iter::once(p).chain(real).all(|p| {
158 if self.off.iter().any(|o| inside(&normal(&p), o).is_some()) {
159 return false;
160 }
161 !matches!(route(Some(self), &p.to_string_lossy(), Path::new("/")),
162 Route::Collective { name, share: Share::Local, .. } if name != collective)
163 })
164 }
165}
166
167#[derive(Debug, Clone, Deserialize)]
168pub struct Config {
169 #[serde(default = "off")]
171 pub default: String,
172 #[serde(default)]
174 pub off: Vec<String>,
175 #[serde(default)]
176 pub collectives: Vec<Entry>,
177 #[serde(default, deserialize_with = "engineers")]
179 pub engineers: Vec<Engineer>,
180 #[serde(default)]
184 pub personal: Option<String>,
185}
186
187fn engineers<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Vec<Engineer>, D::Error> {
189 Vec::<Engineer>::deserialize(d).map_err(|e| serde::de::Error::custom(format!("engineers: {e}")))
190}
191
192#[derive(Debug, Clone, Deserialize)]
194#[serde(deny_unknown_fields)]
195pub struct Engineer {
196 pub name: String,
197 pub emails: Vec<String>,
198}
199
200#[derive(Debug, Clone, Default, PartialEq, Eq)]
203pub struct Aliases {
204 by_email: std::collections::HashMap<String, String>,
205}
206
207impl Aliases {
208 pub fn new(engineers: &[Engineer]) -> Aliases {
209 let by_email = engineers.iter().flat_map(|e| e.emails.iter().map(move |m| (m.trim().to_lowercase(), e.name.trim().to_string()))).collect();
210 Aliases { by_email }
211 }
212
213 pub fn canon(&self, email: &str) -> String {
216 let key = email.trim().to_lowercase();
217 self.by_email.get(&key).cloned().unwrap_or(key)
218 }
219
220 pub fn display(&self, email: &str) -> String {
222 self.by_email.get(&email.trim().to_lowercase()).cloned().unwrap_or_else(|| email.to_string())
223 }
224
225 pub fn same(&self, a: &str, b: &str) -> bool {
227 self.canon(a) == self.canon(b)
228 }
229}
230
231impl Config {
232 pub fn aliases(&self) -> Aliases {
233 Aliases::new(&self.engineers)
234 }
235}
236
237pub fn aliases() -> &'static Aliases {
241 static A: std::sync::OnceLock<Aliases> = std::sync::OnceLock::new();
242 A.get_or_init(|| {
243 if cfg!(test) {
244 return Aliases::default();
245 }
246 load().ok().flatten().map(|c| c.aliases()).unwrap_or_default()
247 })
248}
249
250fn off() -> String {
251 "off".into()
252}
253
254#[derive(Debug, Clone, PartialEq, Eq)]
255pub enum Route {
256 Off,
258 Collective {
259 name: String,
260 home: PathBuf,
261 share: Share,
262 },
263}
264
265pub fn config_path() -> PathBuf {
266 std::env::var("BORG_CONFIG")
267 .map(PathBuf::from)
268 .unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".config/borg/collectives.json"))
269}
270
271pub fn load() -> Result<Option<Config>, String> {
274 load_from(&config_path())
275}
276
277pub fn load_from(p: &Path) -> Result<Option<Config>, String> {
279 match std::fs::read_to_string(p) {
280 Ok(t) => {
281 let cfg: Config = serde_json::from_str(&t).map_err(|e| format!("{}: {e}", p.display()))?;
282 cfg.check().map_err(|e| format!("{}: {e}", p.display()))?;
283 Ok(Some(cfg))
284 }
285 Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None),
286 Err(e) => Err(format!("{}: {e}", p.display())),
287 }
288}
289
290impl Config {
291 pub fn check(&self) -> Result<(), String> {
293 if let Some(p) = &self.personal
294 && !self.collectives.iter().any(|c| &c.name == p && c.share == Share::Local)
295 {
296 return Err(format!("personal: {p:?} is not a collective with \"share\": \"local\""));
297 }
298 let mut seen: std::collections::HashMap<String, &str> = std::collections::HashMap::new();
299 for c in &self.collectives {
300 if let Some(other) = seen.insert(store_name(&c.name).to_lowercase(), &c.name) {
301 return Err(format!("collectives {other:?} and {:?} would share one store; rename one", c.name));
302 }
303 }
304 let mut names = std::collections::HashSet::new();
305 let mut owner: std::collections::HashMap<String, &str> = std::collections::HashMap::new();
306 for e in &self.engineers {
307 if e.name.trim().is_empty() {
308 return Err("engineers: an entry has no name".into());
309 }
310 if !names.insert(e.name.trim().to_lowercase()) {
311 return Err(format!("engineers: {:?} is listed twice; merge the entries", e.name));
312 }
313 if e.emails.is_empty() {
314 return Err(format!("engineers: {:?} lists no emails", e.name));
315 }
316 for m in e.emails.iter().map(|m| m.trim().to_lowercase()) {
317 if m.is_empty() {
318 return Err(format!("engineers: {:?} lists an empty email", e.name));
319 }
320 if let Some(other) = owner.insert(m.clone(), &e.name).filter(|o| *o != e.name) {
321 return Err(format!("engineers: {m} is listed under both {other:?} and {:?}", e.name));
322 }
323 }
324 }
325 Ok(())
326 }
327}
328
329pub(crate) fn expand(p: &str) -> PathBuf {
330 match p.strip_prefix("~/") {
331 Some(rest) => PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(rest),
332 None if p == "~" => PathBuf::from(std::env::var("HOME").unwrap_or_default()),
333 None => PathBuf::from(p),
334 }
335}
336
337pub(crate) fn normal(p: &Path) -> Vec<String> {
339 let mut out: Vec<String> = Vec::new();
340 for c in p.components() {
341 match c {
342 Component::ParentDir => {
343 out.pop();
344 }
345 Component::Normal(s) => out.push(s.to_string_lossy().into_owned()),
346 _ => {}
347 }
348 }
349 out
350}
351
352pub(crate) fn inside(path: &[String], prefix: &str) -> Option<usize> {
354 let pre = normal(&expand(prefix));
355 (!pre.is_empty() && path.len() >= pre.len() && path[..pre.len()] == pre[..]).then_some(pre.len())
356}
357
358fn store_name(name: &str) -> String {
361 let safe: String = name.chars().map(|c| if c.is_ascii_alphanumeric() || c == '-' || c == '_' { c } else { '_' }).collect();
362 if safe == name && !safe.is_empty() {
363 return safe;
364 }
365 let h = name.bytes().fold(0xcbf2_9ce4_8422_2325u64, |h, b| (h ^ b as u64).wrapping_mul(0x0100_0000_01b3));
368 format!("{safe}-{:08x}", h as u32 ^ (h >> 32) as u32)
369}
370
371pub fn store(base: &Path, name: &str) -> PathBuf {
373 base.join("collectives").join(store_name(name))
374}
375
376pub fn root_of(home: &Path) -> PathBuf {
378 match home.parent() {
379 Some(p) if p.file_name().is_some_and(|n| n == "collectives") => p.parent().map_or_else(|| home.to_path_buf(), Path::to_path_buf),
380 _ => home.to_path_buf(),
381 }
382}
383
384pub const REPO_DEPTH: usize = 2;
389
390pub fn places_of(cfg: &Config, repo: &str) -> Vec<PathBuf> {
394 if repo.is_empty() || repo == "." || repo == ".." || repo.contains('/') {
395 return Vec::new();
396 }
397 fn inside(p: &Path, repo: &str, depth: usize, out: &mut Vec<PathBuf>) {
398 let here = p.join(repo);
399 if here.is_dir() {
400 out.push(here);
401 }
402 if depth <= 1 {
403 return;
404 }
405 for d in std::fs::read_dir(p).into_iter().flatten().flatten() {
406 let name = d.file_name();
407 if name.to_string_lossy().starts_with('.') || name == repo || !d.file_type().is_ok_and(|t| t.is_dir()) {
408 continue;
409 }
410 inside(&d.path(), repo, depth - 1, out);
411 }
412 }
413 let mut out = Vec::new();
414 for p in cfg.collectives.iter().flat_map(|c| c.paths.iter()).chain(cfg.off.iter()).map(|p| expand(p)) {
415 if p.file_name().is_some_and(|n| n == repo) {
416 out.push(p.clone());
417 }
418 inside(&p, repo, REPO_DEPTH, &mut out);
419 }
420 out
421}
422
423pub fn route_repo(cfg: &Config, repo: &str, base: &Path) -> Option<Route> {
428 let mut routes = places_of(cfg, repo).into_iter().map(|p| route(Some(cfg), &p.to_string_lossy(), base));
429 let first = routes.next()?;
430 routes.all(|r| r == first).then_some(first)
431}
432
433pub fn is_store(cfg: &Config, home: &Path) -> bool {
435 let base = root_of(home);
436 cfg.collectives.iter().any(|c| store(&base, &c.name) == home)
437}
438
439pub fn local_owner_of<'a>(cfg: Option<&'a Config>, home: &Path, base: &Path) -> Option<&'a str> {
442 cfg?.collectives.iter().find(|c| c.share == Share::Local && store(base, &c.name) == home).map(|c| c.name.as_str())
443}
444
445fn within(cwd: &str) -> impl Fn(&str) -> Option<usize> {
449 let lexical = expand(cwd);
450 let paths: Vec<Vec<String>> = std::iter::once(normal(&lexical)).chain(lexical.canonicalize().ok().map(|p| normal(&p))).collect();
451 move |prefix: &str| {
452 let real = expand(prefix).canonicalize().ok().map(|p| p.to_string_lossy().into_owned());
453 let prefixes = std::iter::once(prefix.to_string()).chain(real);
454 prefixes.filter_map(|pre| paths.iter().filter_map(|p| inside(p, &pre)).max()).max()
455 }
456}
457
458pub fn route(cfg: Option<&Config>, cwd: &str, base: &Path) -> Route {
460 let Some(cfg) = cfg else {
461 return Route::Collective { name: "default".into(), home: base.to_path_buf(), share: Share::Team };
462 };
463 if cwd.trim().is_empty() {
464 return Route::Off; }
466 let within = within(cwd);
467 if cfg.off.iter().any(|p| within(p).is_some()) {
468 return Route::Off;
469 }
470 let best = cfg.collectives.iter().filter_map(|c| c.paths.iter().filter_map(|p| within(p)).max().map(|n| (n, c))).max_by_key(|(n, _)| *n).map(|(_, c)| c);
471 let chosen = best.or_else(|| cfg.collectives.iter().find(|c| c.name == cfg.default && cfg.default != "off"));
472 match chosen {
473 Some(c) => Route::Collective { name: c.name.clone(), home: store(base, &c.name), share: c.share },
474 None => Route::Off,
475 }
476}
477
478pub fn may_sync(r: &Route) -> bool {
481 matches!(r, Route::Collective { share: Share::Team, .. })
482}
483
484#[cfg(test)]
485mod tests {
486 use super::*;
487
488 fn cfg(json: &str) -> Config {
489 serde_json::from_str(json).unwrap()
490 }
491
492 const CFG: &str = r#"{ "default": "off",
493 "off": ["/home/u/private/diary"],
494 "collectives": [
495 { "name": "work", "paths": ["/home/u/work-repos"], "share": "team" },
496 { "name": "private", "paths": ["/home/u/private"], "share": "local" },
497 { "name": "libs", "paths": ["/home/u/work-repos/shared-libs"] } ] }"#;
498
499 fn name(r: &Route) -> &str {
500 match r {
501 Route::Off => "off",
502 Route::Collective { name, .. } => name,
503 }
504 }
505
506 #[test]
507 fn routes_by_longest_whole_component_prefix() {
508 let c = cfg(CFG);
509 let base = Path::new("/b");
510 assert_eq!(name(&route(Some(&c), "/home/u/work-repos/harbor_orion/src", base)), "work");
511 assert_eq!(name(&route(Some(&c), "/home/u/work-repos/shared-libs/x", base)), "libs", "longest prefix wins");
512 assert_eq!(name(&route(Some(&c), "/home/u/work", base)), "off", "no partial component match");
513 assert_eq!(name(&route(Some(&c), "/home/u/work-repos-old/x", base)), "off", "work-repos-old is not work-repos");
514 assert_eq!(name(&route(Some(&c), "/home/u/private/finances", base)), "private");
515 assert_eq!(name(&route(Some(&c), "/home/u/work-repos/../private/x", base)), "private", "normalised before matching");
516 }
517
518 #[test]
519 fn a_symlink_and_its_target_route_alike() {
520 let root = std::env::temp_dir().join(format!("borg-route-link-{}", std::process::id()));
523 let _ = std::fs::remove_dir_all(&root);
524 std::fs::create_dir_all(root.join("real/work/secret/x")).unwrap();
525 std::os::unix::fs::symlink(root.join("real"), root.join("link")).unwrap();
526 let (real, link) = (root.join("real").display().to_string(), root.join("link").display().to_string());
527 let c = cfg(&format!(
528 r#"{{ "default": "off", "off": ["{link}/work/secret"], "collectives": [ {{ "name": "work", "paths": ["{real}/work"], "share": "team" }} ] }}"#
529 ));
530 let base = Path::new("/b");
531 assert_eq!(route(Some(&c), &format!("{real}/work/secret/x"), base), Route::Off, "an off path written through the link");
532 assert_eq!(route(Some(&c), &format!("{link}/work/secret/x"), base), Route::Off);
533 assert_eq!(name(&route(Some(&c), &format!("{link}/work"), base)), "work", "a cwd reported through the link");
534 let _ = std::fs::remove_dir_all(root);
535 }
536
537 #[test]
538 fn off_wins_and_unknown_is_off() {
539 let c = cfg(CFG);
540 let base = Path::new("/b");
541 assert_eq!(route(Some(&c), "/home/u/private/diary/2026", base), Route::Off, "off beats the private collective above it");
542 assert_eq!(route(Some(&c), "/somewhere/else", base), Route::Off, "default off");
543 assert_eq!(route(Some(&c), "", base), Route::Off, "no cwd: never guess");
544 let d = cfg(r#"{ "default": "work", "collectives": [ { "name": "work", "paths": ["/w"] } ] }"#);
545 assert_eq!(name(&route(Some(&d), "/somewhere/else", base)), "work");
546 }
547
548 #[test]
549 fn stores_are_separate_and_local_never_syncs() {
550 let c = cfg(CFG);
551 let base = Path::new("/b");
552 let corp = route(Some(&c), "/home/u/work-repos/a", base);
553 let private = route(Some(&c), "/home/u/private/a", base);
554 let (Route::Collective { home: h1, .. }, Route::Collective { home: h2, .. }) = (&corp, &private) else { panic!() };
555 assert_ne!(h1, h2);
556 assert_eq!(h2, &PathBuf::from("/b/collectives/private"));
557 assert!(may_sync(&corp));
558 assert!(!may_sync(&private), "a local collective never leaves the machine");
559 assert!(!may_sync(&Route::Off));
560 }
561
562 #[test]
563 fn similar_names_get_separate_stores() {
564 let c = cfg(r#"{ "collectives": [
565 { "name": "my team", "paths": ["/l"], "share": "local" },
566 { "name": "my_team", "paths": ["/t"], "share": "team" } ] }"#);
567 let base = Path::new("/b");
568 let (Route::Collective { home: local, .. }, Route::Collective { home: team, .. }) = (route(Some(&c), "/l/x", base), route(Some(&c), "/t/x", base))
569 else {
570 panic!()
571 };
572 assert_ne!(local, team, "a local collective never shares a store with a team one");
573 assert_eq!(team, PathBuf::from("/b/collectives/my_team"), "safe names keep their store");
574 assert!(local.to_string_lossy().starts_with("/b/collectives/my_team-"));
575 assert_ne!(store_name("a.b"), store_name("a_b"));
576 assert_ne!(store_name("équipe"), store_name("_quipe"));
577 assert_eq!(store_name("a.b"), store_name("a.b"), "stable");
578 assert!(c.check().is_ok());
579 assert_eq!(local_owner_of(Some(&c), &team, base), None);
580 assert_eq!(local_owner_of(Some(&c), &local, base), Some("my team"));
581 }
582
583 #[test]
584 fn a_config_whose_collectives_share_a_store_is_rejected() {
585 for json in [
586 r#"{ "collectives": [ { "name": "x", "paths": ["/a"], "share": "local" }, { "name": "x", "paths": ["/b"] } ] }"#,
587 r#"{ "collectives": [ { "name": "Team", "paths": ["/a"], "share": "local" }, { "name": "team", "paths": ["/b"] } ] }"#,
588 ] {
589 assert!(cfg(json).check().unwrap_err().contains("share one store"), "{json}");
590 let p = std::env::temp_dir().join(format!("borg-collective-dup-{}.json", std::process::id()));
591 std::fs::write(&p, json).unwrap();
592 assert!(load_from(&p).is_err(), "load rejects it, so everything routes off");
593 let _ = std::fs::remove_file(&p);
594 }
595 }
596
597 #[test]
598 fn expert_repos_behind_the_boundary_are_never_consulted() {
599 let c = cfg(r#"{ "default": "off", "off": ["/home/u/secret"],
600 "collectives": [
601 { "name": "work", "paths": ["/home/u/work"], "share": "team", "experts": [
602 { "name": "open", "repo": "/home/u/src/flowlib" },
603 { "name": "mine", "repo": "/home/u/work/sdk" },
604 { "name": "offrepo", "repo": "/home/u/secret/sdk" },
605 { "name": "privaterepo", "repo": "/home/u/private/flowlib" },
606 { "name": "sneaky", "repo": "/home/u/work/../private/x" } ] },
607 { "name": "private", "paths": ["/home/u/private"], "share": "local", "experts": [
608 { "name": "own", "repo": "/home/u/private/flowlib" },
609 { "name": "team", "repo": "/home/u/work/sdk" },
610 { "name": "off", "repo": "/home/u/secret/sdk" } ] } ] }"#);
611 let names = |cwd: &str| c.experts_for(cwd).iter().map(|e| e.name.clone()).collect::<Vec<_>>();
612 assert_eq!(names("/home/u/work/app"), ["open", "mine"], "off and local-private expert repos are dropped");
613 assert_eq!(names("/home/u/private/app"), ["own", "team"], "a local collective may read its own and team repos, never off ones");
614 assert!(names("/home/u/secret/app").is_empty());
615 let d = std::env::temp_dir().canonicalize().unwrap().join(format!("borg-collective-link-{}", std::process::id()));
617 let _ = std::fs::remove_dir_all(&d);
618 std::fs::create_dir_all(d.join("secret/sdk")).unwrap();
619 std::os::unix::fs::symlink(d.join("secret/sdk"), d.join("link")).unwrap();
620 let c = cfg(&format!(
621 r#"{{ "off": ["{0}/secret"], "collectives": [ {{ "name": "t", "paths": ["/w"], "experts": [ {{ "name": "x", "repo": "{0}/link" }} ] }} ] }}"#,
622 d.display()
623 ));
624 assert!(c.experts_for("/w/app").is_empty(), "a symlink into an off path");
625 let _ = std::fs::remove_dir_all(&d);
626 }
627
628 #[test]
629 fn engineers_map_aliases_case_insensitively() {
630 let c = cfg(r#"{ "engineers": [ { "name": "dana", "emails": ["Dana.Example@corp.example", "da@home.example"] } ] }"#);
631 assert!(c.check().is_ok());
632 let a = c.aliases();
633 assert_eq!(a.canon("dana.example@CORP.example"), "dana");
634 assert_eq!(a.canon(" da@home.example "), "dana");
635 assert!(a.same("Dana.Example@corp.example", "da@home.example"));
636 assert_eq!(a.canon("Ann@X"), "ann@x", "unlisted emails still compare case-insensitively");
637 assert_eq!(a.display("Ann@X"), "Ann@X", "and display as written");
638 assert_eq!(a.display("DA@home.example"), "dana");
639 assert_eq!(a.canon(""), "");
640 assert_eq!(cfg(CFG).aliases(), Aliases::default(), "absent section: no aliases");
641 }
642
643 #[test]
644 fn an_invalid_engineers_section_is_rejected_at_load() {
645 for (json, why) in [
646 (r#"{ "engineers": [ { "name": "", "emails": ["a@x"] } ] }"#, "has no name"),
647 (r#"{ "engineers": [ { "name": "a", "emails": [] } ] }"#, "lists no emails"),
648 (r#"{ "engineers": [ { "name": "a", "emails": ["a@x", " "] } ] }"#, "empty email"),
649 (r#"{ "engineers": [ { "name": "a", "emails": ["a@x"] }, { "name": "A", "emails": ["b@x"] } ] }"#, "listed twice"),
650 (r#"{ "engineers": [ { "name": "a", "emails": ["a@x"] }, { "name": "b", "emails": ["A@X"] } ] }"#, "listed under both"),
651 (r#"{ "engineers": [ { "name": "a", "email": ["a@x"] } ] }"#, "unknown field"),
652 (r#"{ "engineers": { "name": "a" } }"#, "invalid type"),
653 ] {
654 let p = std::env::temp_dir().join(format!("borg-collective-eng-{}.json", std::process::id()));
655 std::fs::write(&p, json).unwrap();
656 let e = load_from(&p).unwrap_err();
657 assert!(e.contains(why) && e.contains(&p.display().to_string()), "{json}: {e}");
658 let _ = std::fs::remove_file(&p);
659 }
660 }
661
662 #[test]
663 fn a_repo_name_routes_only_where_no_other_place_of_it_could_be() {
664 let root = std::env::temp_dir().join(format!("borg-collective-repo-{}", std::process::id()));
665 let _ = std::fs::remove_dir_all(&root);
666 for d in ["work/group/api", "work/app", "oss/api", "oss/lib", "work/a/b/deep"] {
667 std::fs::create_dir_all(root.join(d)).unwrap();
668 }
669 let cfg: Config = serde_json::from_value(serde_json::json!({"collectives": [
670 {"name": "work", "paths": [root.join("work")]}, {"name": "oss", "paths": [root.join("oss")]}]}))
671 .unwrap();
672 let base = root.join("base");
673 let to = |name: &str| Some(Route::Collective { name: name.into(), home: store(&base, name), share: Share::Team });
674 assert_eq!(route_repo(&cfg, "lib", &base), to("oss"));
675 assert_eq!(route_repo(&cfg, "app", &base), to("work"));
676 assert_eq!(route_repo(&cfg, "api", &base), None);
678 assert_eq!(places_of(&cfg, "api").len(), 2);
679 assert_eq!(route_repo(&cfg, "deep", &base), None, "deeper than REPO_DEPTH: unknown");
680 let _ = std::fs::remove_dir_all(root);
681 }
682
683 #[test]
684 fn no_config_keeps_one_default_collective() {
685 let r = route(None, "/anything", Path::new("/b"));
686 assert_eq!(r, Route::Collective { name: "default".into(), home: PathBuf::from("/b"), share: Share::Team });
687 }
688}