@@ -62,20 +62,27 @@ def test_unreadable_file_skipped(self):
6262 self .assertEqual (result , text )
6363
6464
65+ TEST_FILES = ["alpha.py" , "alpha_test.py" , "beta.txt" , "subdir/gamma.py" ]
66+
67+
6568class TestIclawCompleter (unittest .TestCase ):
6669 def setUp (self ):
6770 self .completer = IclawCompleter ()
6871 self .tmpdir = tempfile .mkdtemp ()
6972 self .orig_cwd = os .getcwd ()
7073 os .chdir (self .tmpdir )
71- # Create test files in the temp dir
74+ # Create actual files so os.path.isdir/isfile work in meta checks
7275 Path ("alpha.py" ).write_text ("" )
7376 Path ("alpha_test.py" ).write_text ("" )
7477 Path ("beta.txt" ).write_text ("" )
7578 os .makedirs ("subdir" , exist_ok = True )
7679 Path ("subdir/gamma.py" ).write_text ("" )
80+ # Patch _get_git_files so tests don't require a real git repo
81+ self .patcher = patch ("iclaw.main._get_git_files" , return_value = TEST_FILES )
82+ self .patcher .start ()
7783
7884 def tearDown (self ):
85+ self .patcher .stop ()
7986 os .chdir (self .orig_cwd )
8087
8188 def _completions (self , text ):
@@ -121,12 +128,22 @@ def test_at_with_space_after_at_returns_nothing(self):
121128 self .assertEqual (completions , [])
122129
123130 def test_at_limits_to_20_results (self ):
124- # Create 25 files
125- for i in range (25 ):
126- Path (f"zfile{ i :02d} .py" ).write_text ("" )
127- completions = self ._completions ("@zfile" )
131+ many_files = [f"zfile{ i :02d} .py" for i in range (25 )]
132+ with patch ("iclaw.main._get_git_files" , return_value = many_files ):
133+ completions = self ._completions ("@zfile" )
128134 self .assertLessEqual (len (completions ), 20 )
129135
136+ def test_at_excludes_gitignored_files (self ):
137+ # git ls-files naturally excludes ignored files; simulate this by
138+ # returning only non-ignored files from _get_git_files.
139+ clean_files = ["visible.py" , "README.md" ]
140+ with patch ("iclaw.main._get_git_files" , return_value = clean_files ):
141+ completions = self ._completions ("@" )
142+ paths = [c .text for c in completions ]
143+ self .assertNotIn ("visible.pyc" , paths )
144+ self .assertNotIn ("__pycache__" , paths )
145+ self .assertIn ("visible.py" , paths )
146+
130147 # --- / command completion ---
131148
132149 def test_slash_alone_returns_all_commands (self ):
0 commit comments