@@ -534,3 +534,138 @@ def test_parent_ignore_stops_at_git_root(tmp_path, run_mapper):
534534 assert find_node_by_path (result , ["beyond_git_root" ]) is not None
535535 assert find_node_by_path (result , ["beyond_git_root" , "visible.txt" ]) is not None
536536 assert find_node_by_path (result , ["keep.txt" ]) is not None
537+
538+
539+ # --- .treemapper/ config directory tests ---
540+
541+
542+ def test_treemapper_dir_ignore (temp_project , run_mapper ):
543+ from .utils import find_node_by_path
544+
545+ config_dir = temp_project / ".treemapper"
546+ config_dir .mkdir (exist_ok = True )
547+ (config_dir / "ignore" ).write_text ("*.log\n docs/\n " )
548+ (temp_project / "app.log" ).touch ()
549+ (temp_project / "keep.txt" ).touch ()
550+
551+ output_path = temp_project / "dir_ignore_output.yaml"
552+ assert run_mapper (["." , "-o" , str (output_path )])
553+ result = load_yaml (output_path )
554+
555+ assert find_node_by_path (result , ["app.log" ]) is None
556+ assert find_node_by_path (result , ["docs" ]) is None
557+ assert find_node_by_path (result , ["keep.txt" ]) is not None
558+
559+
560+ def test_treemapper_dir_ignore_combined_with_legacy (temp_project , run_mapper ):
561+ from .utils import find_node_by_path
562+
563+ (temp_project / ".treemapperignore" ).write_text ("*.tmp\n " )
564+ config_dir = temp_project / ".treemapper"
565+ config_dir .mkdir (exist_ok = True )
566+ (config_dir / "ignore" ).write_text ("*.bak\n " )
567+ (temp_project / "file.tmp" ).touch ()
568+ (temp_project / "file.bak" ).touch ()
569+ (temp_project / "file.txt" ).touch ()
570+
571+ output_path = temp_project / "combined_dir_output.yaml"
572+ assert run_mapper (["." , "-o" , str (output_path )])
573+ result = load_yaml (output_path )
574+
575+ assert find_node_by_path (result , ["file.tmp" ]) is None
576+ assert find_node_by_path (result , ["file.bak" ]) is None
577+ assert find_node_by_path (result , ["file.txt" ]) is not None
578+
579+
580+ def test_treemapper_dir_ignore_hierarchical (temp_project , run_mapper ):
581+ from .utils import find_node_by_path
582+
583+ subdir = temp_project / "subdir"
584+ subdir .mkdir ()
585+ sub_config = subdir / ".treemapper"
586+ sub_config .mkdir ()
587+ (sub_config / "ignore" ).write_text ("*.secret\n " )
588+
589+ (temp_project / "root.secret" ).touch ()
590+ (subdir / "nested.secret" ).touch ()
591+ (subdir / "keep.txt" ).touch ()
592+
593+ output_path = temp_project / "hier_dir_output.yaml"
594+ assert run_mapper (["." , "-o" , str (output_path )])
595+ result = load_yaml (output_path )
596+
597+ assert find_node_by_path (result , ["root.secret" ]) is not None
598+ assert find_node_by_path (result , ["subdir" , "nested.secret" ]) is None
599+ assert find_node_by_path (result , ["subdir" , "keep.txt" ]) is not None
600+
601+
602+ def test_treemapper_dir_ignore_parent (tmp_path , run_mapper ):
603+ from .utils import find_node_by_path
604+
605+ parent = tmp_path / "parent_project"
606+ parent .mkdir ()
607+ (parent / ".git" ).mkdir ()
608+ config_dir = parent / ".treemapper"
609+ config_dir .mkdir ()
610+ (config_dir / "ignore" ).write_text ("packages/app/secret_dir/\n " )
611+
612+ child = parent / "packages" / "app"
613+ child .mkdir (parents = True )
614+ (child / "secret_dir" ).mkdir ()
615+ (child / "secret_dir" / "secret.txt" ).write_text ("secret" )
616+ (child / "src" ).mkdir ()
617+ (child / "src" / "main.py" ).write_text ("print('hello')" )
618+
619+ output_path = tmp_path / "parent_dir_output.yaml"
620+ assert run_mapper ([str (child ), "-o" , str (output_path )])
621+ result = load_yaml (output_path )
622+
623+ assert find_node_by_path (result , ["secret_dir" ]) is None
624+ assert find_node_by_path (result , ["src" , "main.py" ]) is not None
625+
626+
627+ def test_treemapper_dir_whitelist (temp_project , run_mapper ):
628+ config_dir = temp_project / ".treemapper"
629+ config_dir .mkdir (exist_ok = True )
630+ (config_dir / "whitelist" ).write_text ("src/**/*.py\n " )
631+
632+ output_path = temp_project / "dir_wl_output.yaml"
633+ assert run_mapper (["." , "-o" , str (output_path )])
634+ result = load_yaml (output_path )
635+ all_files = get_all_files_in_tree (result )
636+
637+ assert "main.py" in all_files
638+ assert "test.py" in all_files
639+ assert "readme.md" not in all_files
640+
641+
642+ def test_treemapper_dir_hidden_from_output (temp_project , run_mapper ):
643+ config_dir = temp_project / ".treemapper"
644+ config_dir .mkdir (exist_ok = True )
645+ (config_dir / "ignore" ).write_text ("*.log\n " )
646+ (config_dir / "whitelist" ).write_text ("src/**\n " )
647+ (temp_project / "keep.txt" ).touch ()
648+
649+ output_path = temp_project / "hidden_dir_output.yaml"
650+ assert run_mapper (["." , "-o" , str (output_path )])
651+ result = load_yaml (output_path )
652+ all_files = get_all_files_in_tree (result )
653+
654+ assert ".treemapper" not in all_files
655+ assert "ignore" not in all_files
656+ assert "whitelist" not in all_files
657+
658+
659+ def test_treemapper_dir_whitelist_over_legacy (temp_project , run_mapper ):
660+ (temp_project / ".treemapperwhitelist" ).write_text ("docs/**\n " )
661+ config_dir = temp_project / ".treemapper"
662+ config_dir .mkdir (exist_ok = True )
663+ (config_dir / "whitelist" ).write_text ("src/**/*.py\n " )
664+
665+ output_path = temp_project / "wl_precedence_output.yaml"
666+ assert run_mapper (["." , "-o" , str (output_path )])
667+ result = load_yaml (output_path )
668+ all_files = get_all_files_in_tree (result )
669+
670+ assert "main.py" in all_files
671+ assert "readme.md" not in all_files
0 commit comments