1use std::path::{Path, PathBuf};
16use std::time::{SystemTime, UNIX_EPOCH};
17
18use crate::constants::{INSTRUCTIONS_TRUNCATION_MARKER, MAX_INSTRUCTIONS_BYTES};
19
20pub const INSTRUCTION_FILENAMES: &[&str] = &["AGENTS.md", "MERMAID.md"];
25
26const MAX_WALK_DEPTH: usize = 32;
29
30#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
33pub struct InstructionSource {
34 pub path: PathBuf,
35 pub mtime: SystemTime,
36 pub byte_len: usize,
37}
38
39#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
43pub struct LoadedInstructions {
44 pub path: PathBuf,
48 pub content: String,
51 pub mtime: SystemTime,
54 pub byte_len: usize,
56 pub truncated: bool,
59 pub sources: Vec<InstructionSource>,
61}
62
63impl LoadedInstructions {
64 pub fn approx_tokens(&self) -> usize {
67 self.content.len() / 4
68 }
69}
70
71#[derive(Debug, PartialEq, Eq)]
74pub enum ReloadOutcome {
75 Unchanged,
77 LoadedFirst { tokens: usize },
80 Reloaded {
82 old_tokens: usize,
83 new_tokens: usize,
84 },
85 Removed,
87}
88
89pub fn find_instruction_files(start: &Path) -> Vec<PathBuf> {
99 find_instruction_files_bounded(start, home_dir_boundary().as_deref())
100}
101
102fn home_dir_boundary() -> Option<PathBuf> {
110 let home = std::env::var_os("HOME");
111 #[cfg(windows)]
112 let resolved = pick_home_boundary(
113 home.as_deref(),
114 std::env::var_os("USERPROFILE").as_deref(),
115 std::env::var_os("HOMEDRIVE").as_deref(),
116 std::env::var_os("HOMEPATH").as_deref(),
117 );
118 #[cfg(not(windows))]
120 let resolved = pick_home_boundary(home.as_deref(), None, None, None);
121 resolved
122}
123
124fn pick_home_boundary(
130 home: Option<&std::ffi::OsStr>,
131 userprofile: Option<&std::ffi::OsStr>,
132 homedrive: Option<&std::ffi::OsStr>,
133 homepath: Option<&std::ffi::OsStr>,
134) -> Option<PathBuf> {
135 fn nonempty(v: Option<&std::ffi::OsStr>) -> Option<&std::ffi::OsStr> {
136 v.filter(|s| !s.is_empty())
137 }
138 if let Some(home) = nonempty(home) {
139 return Some(PathBuf::from(home));
140 }
141 if let Some(profile) = nonempty(userprofile) {
142 return Some(PathBuf::from(profile));
143 }
144 if let (Some(drive), Some(path)) = (nonempty(homedrive), nonempty(homepath)) {
145 let mut combined = drive.to_os_string();
146 combined.push(path);
147 return Some(PathBuf::from(combined));
148 }
149 None
150}
151
152fn find_instruction_files_bounded(start: &Path, home: Option<&Path>) -> Vec<PathBuf> {
156 let mut current = start.to_path_buf();
157 for _ in 0..MAX_WALK_DEPTH {
158 if home == Some(current.as_path()) {
163 return Vec::new();
164 }
165 let found: Vec<PathBuf> = INSTRUCTION_FILENAMES
166 .iter()
167 .map(|name| current.join(name))
168 .filter(|candidate| candidate.is_file())
169 .collect();
170 if !found.is_empty() {
171 return found;
172 }
173 if current.join(".git").exists() {
177 return Vec::new();
178 }
179 match current.parent() {
181 Some(parent) if parent != current => current = parent.to_path_buf(),
182 _ => return Vec::new(),
183 }
184 }
185 Vec::new()
186}
187
188pub fn load_from_path(path: &Path) -> Option<LoadedInstructions> {
192 load_from_paths(&[path.to_path_buf()])
193}
194
195pub fn load_from_paths(paths: &[PathBuf]) -> Option<LoadedInstructions> {
198 let mut sources = Vec::new();
199 let mut bodies = Vec::new();
200 let mut total_byte_len = 0usize;
201 let mut latest_mtime = UNIX_EPOCH;
202
203 for path in paths {
204 let Ok(metadata) = std::fs::metadata(path) else {
210 continue;
211 };
212 let Ok(mtime) = metadata.modified() else {
213 continue;
214 };
215 let true_len = metadata.len() as usize;
216 let Ok((bytes, _truncated)) =
222 crate::utils::read_file_capped(path, MAX_INSTRUCTIONS_BYTES.saturating_add(1))
223 else {
224 continue;
225 };
226 let raw = String::from_utf8_lossy(&bytes).into_owned();
227 total_byte_len = total_byte_len.saturating_add(true_len);
228 if mtime > latest_mtime {
229 latest_mtime = mtime;
230 }
231 sources.push(InstructionSource {
232 path: path.to_path_buf(),
233 mtime,
234 byte_len: true_len,
235 });
236 bodies.push((path.to_path_buf(), raw));
237 }
238 let primary = sources.first()?.path.clone();
239 let sections = label_instruction_bodies(bodies);
240 let byte_len = total_byte_len;
241 let (content, truncated) = combine_and_cap_sections(sections, MAX_INSTRUCTIONS_BYTES);
242 Some(LoadedInstructions {
243 path: primary,
244 content,
245 mtime: latest_mtime,
246 byte_len,
247 truncated,
248 sources,
249 })
250}
251
252pub fn refresh(
259 current: Option<LoadedInstructions>,
260 cwd: &Path,
261) -> (Option<LoadedInstructions>, ReloadOutcome) {
262 match current {
263 Some(prior) => {
264 let paths: Vec<PathBuf> = if prior.sources.is_empty() {
266 vec![prior.path.clone()]
267 } else {
268 prior
269 .sources
270 .iter()
271 .map(|source| source.path.clone())
272 .collect()
273 };
274 let changed = if prior.sources.is_empty() {
275 std::fs::metadata(&prior.path)
276 .and_then(|m| m.modified())
277 .map(|mtime| mtime != prior.mtime)
278 .unwrap_or(true)
279 } else {
280 prior.sources.iter().any(|source| {
281 std::fs::metadata(&source.path)
282 .and_then(|m| m.modified())
283 .map(|mtime| mtime != source.mtime)
284 .unwrap_or(true)
285 })
286 };
287 if !changed {
288 return (Some(prior), ReloadOutcome::Unchanged);
289 }
290 let old_tokens = prior.approx_tokens();
291 match load_from_paths(&paths) {
292 Some(reloaded) => {
293 let new_tokens = reloaded.approx_tokens();
294 (
295 Some(reloaded),
296 ReloadOutcome::Reloaded {
297 old_tokens,
298 new_tokens,
299 },
300 )
301 },
302 None => {
303 (None, ReloadOutcome::Removed)
306 },
307 }
308 },
309 None => {
310 match load_from_paths(&find_instruction_files(cwd)) {
313 Some(loaded) => {
314 let tokens = loaded.approx_tokens();
315 (Some(loaded), ReloadOutcome::LoadedFirst { tokens })
316 },
317 None => (None, ReloadOutcome::Unchanged),
318 }
319 },
320 }
321}
322
323pub fn load_project_context(
331 cwd: &Path,
332 mem_cfg: &crate::app::MemoryConfig,
333) -> (
334 Option<LoadedInstructions>,
335 Option<crate::app::memory::LoadedMemory>,
336) {
337 let (instructions, _) = refresh(None, cwd);
338 let (memory, _) = crate::app::memory::refresh(None, cwd, mem_cfg);
339 (instructions, memory)
340}
341
342const INSTRUCTION_SECTION_SEPARATOR: &str = "\n\n---\n\n";
344
345fn label_instruction_bodies(bodies: Vec<(PathBuf, String)>) -> Vec<String> {
351 bodies
352 .into_iter()
353 .map(|(path, body)| {
354 let name = path
355 .file_name()
356 .and_then(|name| name.to_str())
357 .unwrap_or("instructions");
358 format!("# Project Instructions: {}\n\n{}", name, body)
359 })
360 .collect()
361}
362
363fn combine_and_cap_sections(sections: Vec<String>, cap: usize) -> (String, bool) {
381 const SEP: &str = INSTRUCTION_SECTION_SEPARATOR;
382 let marker = INSTRUCTIONS_TRUNCATION_MARKER;
383
384 let full = sections.join(SEP);
385 if full.len() <= cap {
386 return (full, false);
387 }
388 let Some(winner) = sections.last() else {
391 return (String::new(), false);
392 };
393 if winner.len() >= cap {
397 let cut = winner.floor_char_boundary(cap);
398 let mut clipped = winner[..cut].to_string();
399 clipped.push_str(marker);
400 return (clipped, true);
401 }
402 let earlier_len = sections.len() - 1;
407 let earlier_full = sections[..earlier_len].join(SEP);
408 let avail = cap.saturating_sub(winner.len() + SEP.len());
409 let cut = earlier_full.floor_char_boundary(avail);
410 if cut == 0 {
411 let mut body = winner.clone();
414 body.push_str(marker);
415 return (body, true);
416 }
417 let mut body = String::with_capacity(cut + marker.len() + SEP.len() + winner.len());
418 body.push_str(&earlier_full[..cut]);
419 body.push_str(marker);
420 body.push_str(SEP);
421 body.push_str(winner.as_str());
422 (body, true)
423}
424
425#[cfg(test)]
426mod tests {
427 use super::*;
428 use std::fs;
429 use std::sync::Mutex;
430
431 static FS_LOCK: Mutex<()> = Mutex::new(());
434
435 fn temp_dir(name: &str) -> PathBuf {
436 let p = std::env::temp_dir().join(format!("mermaid_instructions_test_{}", name));
437 let _ = fs::remove_dir_all(&p);
438 fs::create_dir_all(&p).expect("create temp dir");
439 p
440 }
441
442 #[test]
443 fn find_instruction_files_finds_in_cwd() {
444 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
445 let dir = temp_dir("cwd");
446 fs::write(dir.join("MERMAID.md"), "rules").unwrap();
447 let found = find_instruction_files(&dir);
448 assert_eq!(found, vec![dir.join("MERMAID.md")]);
449 let _ = fs::remove_dir_all(&dir);
450 }
451
452 #[test]
453 fn find_instruction_files_loads_both_in_precedence_order() {
454 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
455 let dir = temp_dir("both");
456 fs::write(dir.join("AGENTS.md"), "agent rules").unwrap();
457 fs::write(dir.join("MERMAID.md"), "mermaid rules").unwrap();
458 let found = find_instruction_files(&dir);
459 assert_eq!(found, vec![dir.join("AGENTS.md"), dir.join("MERMAID.md")]);
461 let loaded = load_from_paths(&found).expect("load combined");
462 assert!(loaded.content.contains("# Project Instructions: AGENTS.md"));
463 assert!(loaded.content.contains("agent rules"));
464 assert!(
465 loaded
466 .content
467 .contains("# Project Instructions: MERMAID.md")
468 );
469 assert!(loaded.content.contains("mermaid rules"));
470 assert!(
472 loaded.content.find("mermaid rules") > loaded.content.find("agent rules"),
473 "MERMAID.md must come last so its guidance overrides AGENTS.md"
474 );
475 assert_eq!(loaded.sources.len(), 2);
476 let _ = fs::remove_dir_all(&dir);
477 }
478
479 #[test]
480 fn find_instruction_files_walks_up_to_git_root() {
481 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
482 let root = temp_dir("walkup");
483 fs::create_dir(root.join(".git")).unwrap();
484 fs::write(root.join("MERMAID.md"), "root rules").unwrap();
485 let sub = root.join("subdir/deeper");
486 fs::create_dir_all(&sub).unwrap();
487 let found = find_instruction_files(&sub);
488 assert_eq!(found, vec![root.join("MERMAID.md")]);
489 let _ = fs::remove_dir_all(&root);
490 }
491
492 #[test]
493 fn find_instruction_files_stops_at_git_root_without_file() {
494 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
495 let root = temp_dir("git_no_md");
496 fs::create_dir(root.join(".git")).unwrap();
497 let parent = root.parent().unwrap();
500 let above_md = parent.join("MERMAID.md");
501 fs::write(&above_md, "outside").unwrap();
502 let sub = root.join("subdir");
503 fs::create_dir_all(&sub).unwrap();
504 let found = find_instruction_files(&sub);
505 assert!(found.is_empty(), "walk must stop at .git boundary");
506 let _ = fs::remove_dir_all(&root);
507 let _ = fs::remove_file(&above_md);
508 }
509
510 #[test]
511 fn find_instruction_files_returns_empty_if_absent() {
512 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
513 let dir = temp_dir("absent");
514 fs::create_dir(dir.join(".git")).unwrap();
517 let found = find_instruction_files(&dir);
518 assert!(found.is_empty());
519 let _ = fs::remove_dir_all(&dir);
520 }
521
522 #[test]
523 fn find_instruction_files_stops_at_home_boundary() {
524 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
529 let home = temp_dir("home_boundary");
530 fs::write(home.join("AGENTS.md"), "home rules").unwrap();
531 let child = home.join("project");
532 fs::create_dir_all(&child).unwrap();
533 let found = find_instruction_files_bounded(&child, Some(home.as_path()));
536 assert!(
537 found.is_empty(),
538 "walk must stop at $HOME and not load ~/AGENTS.md, got {found:?}"
539 );
540 let _ = fs::remove_dir_all(&home);
541 }
542
543 #[test]
544 fn single_file_instructions_get_labeled_header() {
545 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
549 let dir = temp_dir("single_header");
550 fs::write(dir.join("MERMAID.md"), "do the thing").unwrap();
551 let loaded = load_from_path(&dir.join("MERMAID.md")).expect("load");
552 assert!(
553 loaded
554 .content
555 .starts_with("# Project Instructions: MERMAID.md"),
556 "single-file instructions must carry a labeled header, got: {:?}",
557 loaded.content
558 );
559 assert!(loaded.content.contains("do the thing"));
560 let _ = fs::remove_dir_all(&dir);
561 }
562
563 #[test]
564 fn load_from_path_truncates_oversized_file() {
565 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
566 let dir = temp_dir("oversized");
567 let path = dir.join("MERMAID.md");
568 let big = "a".repeat(50_000);
570 fs::write(&path, &big).unwrap();
571 let loaded = load_from_path(&path).expect("load");
572 assert!(loaded.truncated);
573 assert_eq!(loaded.byte_len, 50_000); assert!(loaded.content.ends_with(INSTRUCTIONS_TRUNCATION_MARKER));
575 assert_eq!(
577 loaded.content.len(),
578 MAX_INSTRUCTIONS_BYTES + INSTRUCTIONS_TRUNCATION_MARKER.len()
579 );
580 let _ = fs::remove_dir_all(&dir);
581 }
582
583 #[test]
584 fn load_from_path_returns_none_when_missing() {
585 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
586 let dir = temp_dir("missing");
587 assert!(load_from_path(&dir.join("nope.md")).is_none());
588 let _ = fs::remove_dir_all(&dir);
589 }
590
591 #[test]
592 fn refresh_returns_unchanged_when_mtime_stable() {
593 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
594 let dir = temp_dir("stable");
595 let path = dir.join("MERMAID.md");
596 fs::write(&path, "v1").unwrap();
597 let prior = load_from_path(&path).unwrap();
598 let (after, outcome) = refresh(Some(prior.clone()), &dir);
599 assert_eq!(outcome, ReloadOutcome::Unchanged);
600 assert!(after.is_some());
601 let _ = fs::remove_dir_all(&dir);
602 }
603
604 #[test]
605 fn refresh_returns_reloaded_on_content_change() {
606 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
607 let dir = temp_dir("changed");
608 let path = dir.join("MERMAID.md");
609 fs::write(&path, "v1").unwrap();
610 let prior = load_from_path(&path).unwrap();
611 std::thread::sleep(std::time::Duration::from_millis(1100));
614 fs::write(&path, "v2 longer content here").unwrap();
615 let (after, outcome) = refresh(Some(prior), &dir);
616 assert!(matches!(outcome, ReloadOutcome::Reloaded { .. }));
617 let content = after.unwrap().content;
618 assert!(content.contains("# Project Instructions: MERMAID.md"));
619 assert!(content.contains("v2 longer content here"));
620 let _ = fs::remove_dir_all(&dir);
621 }
622
623 #[test]
624 fn refresh_returns_removed_when_file_deleted() {
625 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
626 let dir = temp_dir("removed");
627 let path = dir.join("MERMAID.md");
628 fs::write(&path, "v1").unwrap();
629 let prior = load_from_path(&path).unwrap();
630 fs::remove_file(&path).unwrap();
631 let (after, outcome) = refresh(Some(prior), &dir);
632 assert_eq!(outcome, ReloadOutcome::Removed);
633 assert!(after.is_none());
634 let _ = fs::remove_dir_all(&dir);
635 }
636
637 #[test]
638 fn refresh_returns_loaded_first_on_initial_discovery() {
639 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
640 let dir = temp_dir("first");
641 fs::create_dir(dir.join(".git")).unwrap();
643 fs::write(dir.join("MERMAID.md"), "fresh").unwrap();
645 let (after, outcome) = refresh(None, &dir);
646 assert!(matches!(outcome, ReloadOutcome::LoadedFirst { .. }));
647 let content = after.unwrap().content;
648 assert!(content.contains("# Project Instructions: MERMAID.md"));
649 assert!(content.contains("fresh"));
650 let _ = fs::remove_dir_all(&dir);
651 }
652
653 #[test]
654 fn load_project_context_loads_instructions_synchronously() {
655 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
659 let dir = temp_dir("project_context");
660 fs::create_dir(dir.join(".git")).unwrap();
661 fs::write(dir.join("MERMAID.md"), "sync-loaded instructions").unwrap();
662 let (instructions, _memory) =
663 load_project_context(&dir, &crate::app::MemoryConfig::default());
664 let content = instructions
665 .expect("instructions must load synchronously")
666 .content;
667 assert!(content.contains("sync-loaded instructions"));
668 let _ = fs::remove_dir_all(&dir);
669 }
670
671 #[test]
672 fn oversized_agents_does_not_drop_mermaid_winner() {
673 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
678 let dir = temp_dir("agents_huge");
679 fs::write(dir.join("AGENTS.md"), "A".repeat(60_000)).unwrap();
680 fs::write(dir.join("MERMAID.md"), "MERMAID_WINS_SENTINEL").unwrap();
681 let loaded =
682 load_from_paths(&[dir.join("AGENTS.md"), dir.join("MERMAID.md")]).expect("load");
683 assert!(loaded.truncated, "combined body exceeds the cap");
684 assert!(
685 loaded.content.contains("MERMAID_WINS_SENTINEL"),
686 "MERMAID.md (the winner) must survive the cap, not be dropped"
687 );
688 assert!(
689 loaded
690 .content
691 .contains("# Project Instructions: MERMAID.md")
692 );
693 assert!(loaded.content.contains(INSTRUCTIONS_TRUNCATION_MARKER));
694 let marker_at = loaded.content.find(INSTRUCTIONS_TRUNCATION_MARKER).unwrap();
697 let winner_at = loaded.content.find("MERMAID_WINS_SENTINEL").unwrap();
698 assert!(
699 winner_at > marker_at,
700 "MERMAID.md must come after the truncated AGENTS.md"
701 );
702 assert!(
704 loaded.content.len() <= MAX_INSTRUCTIONS_BYTES + INSTRUCTIONS_TRUNCATION_MARKER.len()
705 );
706 let _ = fs::remove_dir_all(&dir);
707 }
708
709 #[test]
710 fn combine_and_cap_protects_the_last_section() {
711 let lower = format!("# Project Instructions: AGENTS.md\n\n{}", "L".repeat(200));
714 let winner = "# Project Instructions: MERMAID.md\n\nWIN".to_string();
715 let (body, truncated) = combine_and_cap_sections(vec![lower, winner], 100);
716 assert!(truncated);
717 assert!(body.contains("WIN"), "winner survives the cap");
718 assert!(body.contains(INSTRUCTIONS_TRUNCATION_MARKER));
719 let marker_at = body.find(INSTRUCTIONS_TRUNCATION_MARKER).unwrap();
720 assert!(
721 body.find("WIN").unwrap() > marker_at,
722 "winner stays last so it overrides on conflict"
723 );
724 assert!(body.len() <= 100 + INSTRUCTIONS_TRUNCATION_MARKER.len());
725 }
726
727 #[test]
728 fn combine_and_cap_clips_winner_when_it_alone_overflows() {
729 let lower = "# Project Instructions: AGENTS.md\n\nlower-content".to_string();
732 let winner = format!("# Project Instructions: MERMAID.md\n\n{}", "W".repeat(300));
733 let (body, truncated) = combine_and_cap_sections(vec![lower, winner], 100);
734 assert!(truncated);
735 assert!(body.ends_with(INSTRUCTIONS_TRUNCATION_MARKER));
736 assert_eq!(body.len(), 100 + INSTRUCTIONS_TRUNCATION_MARKER.len());
737 assert!(
738 !body.contains("lower-content"),
739 "no room for the lower-precedence section"
740 );
741 }
742
743 #[test]
744 fn combine_and_cap_passes_through_when_it_fits() {
745 let a = "# Project Instructions: AGENTS.md\n\naye".to_string();
746 let b = "# Project Instructions: MERMAID.md\n\nbee".to_string();
747 let (body, truncated) = combine_and_cap_sections(vec![a, b], 10_000);
748 assert!(!truncated);
749 assert!(body.contains("aye") && body.contains("bee"));
750 assert!(
751 body.find("bee").unwrap() > body.find("aye").unwrap(),
752 "highest-precedence section stays last"
753 );
754 }
755
756 #[test]
757 fn load_from_paths_tolerates_a_missing_file() {
758 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
762 let dir = temp_dir("partial_load");
763 fs::write(dir.join("AGENTS.md"), "agent rules").unwrap();
764 let missing = dir.join("MERMAID.md"); let loaded = load_from_paths(&[dir.join("AGENTS.md"), missing])
766 .expect("AGENTS.md must still load when MERMAID.md is absent");
767 assert!(loaded.content.contains("# Project Instructions: AGENTS.md"));
768 assert!(loaded.content.contains("agent rules"));
769 assert_eq!(loaded.sources.len(), 1, "only the present file is a source");
770 assert_eq!(loaded.path, dir.join("AGENTS.md"));
771 let _ = fs::remove_dir_all(&dir);
772 }
773
774 #[test]
775 fn load_from_paths_none_when_all_missing() {
776 let _lock = FS_LOCK.lock().unwrap_or_else(|e| e.into_inner());
777 let dir = temp_dir("all_missing");
778 assert!(
779 load_from_paths(&[dir.join("AGENTS.md"), dir.join("MERMAID.md")]).is_none(),
780 "no present files => None"
781 );
782 let _ = fs::remove_dir_all(&dir);
783 }
784
785 #[test]
786 fn pick_home_boundary_resolves_windows_home_vars() {
787 use std::ffi::OsStr;
791 assert_eq!(
793 pick_home_boundary(
794 Some(OsStr::new("/home/me")),
795 Some(OsStr::new("C:\\Users\\me")),
796 None,
797 None
798 ),
799 Some(PathBuf::from("/home/me"))
800 );
801 assert_eq!(
803 pick_home_boundary(None, Some(OsStr::new("C:\\Users\\me")), None, None),
804 Some(PathBuf::from("C:\\Users\\me"))
805 );
806 assert_eq!(
808 pick_home_boundary(
809 None,
810 None,
811 Some(OsStr::new("C:")),
812 Some(OsStr::new("\\Users\\me"))
813 ),
814 Some(PathBuf::from("C:\\Users\\me"))
815 );
816 assert_eq!(
818 pick_home_boundary(Some(OsStr::new("")), Some(OsStr::new("")), None, None),
819 None
820 );
821 assert_eq!(
823 pick_home_boundary(None, None, Some(OsStr::new("C:")), None),
824 None
825 );
826 assert_eq!(
827 pick_home_boundary(None, None, None, Some(OsStr::new("\\Users\\me"))),
828 None
829 );
830 }
831}