@@ -166,9 +166,10 @@ func TestLastReindexTime_EmptyWAL(t *testing.T) {
166166// ---------------------------------------------------------------------------
167167
168168func TestFindCopilotBinary_NoCandidates (t * testing.T ) {
169- // Set environment to non-existent paths.
169+ // Set environment to non-existent paths and isolate PATH .
170170 t .Setenv ("ProgramFiles" , filepath .Join (t .TempDir (), "nonexistent" ))
171171 t .Setenv ("APPDATA" , "" )
172+ t .Setenv ("PATH" , t .TempDir ())
172173
173174 got := findCopilotBinary ()
174175 if got != "" {
@@ -179,6 +180,7 @@ func TestFindCopilotBinary_NoCandidates(t *testing.T) {
179180func TestFindCopilotBinary_WithAPPDATA (t * testing.T ) {
180181 tmp := t .TempDir ()
181182 t .Setenv ("ProgramFiles" , filepath .Join (tmp , "nonexistent" ))
183+ t .Setenv ("PATH" , filepath .Join (tmp , "emptypath" ))
182184
183185 // Create the APPDATA candidate path.
184186 appdata := filepath .Join (tmp , "appdata" )
@@ -206,6 +208,7 @@ func TestFindCopilotBinary_WithProgramFiles(t *testing.T) {
206208 progFiles := filepath .Join (tmp , "Program Files" )
207209 t .Setenv ("ProgramFiles" , progFiles )
208210 t .Setenv ("APPDATA" , "" )
211+ t .Setenv ("PATH" , filepath .Join (tmp , "emptypath" ))
209212
210213 candidatePath := filepath .Join (progFiles , "nodejs" , "node_modules" ,
211214 "@github" , "copilot" , "node_modules" , "@github" , "copilot-win32-x64" )
@@ -223,6 +226,28 @@ func TestFindCopilotBinary_WithProgramFiles(t *testing.T) {
223226 }
224227}
225228
229+ func TestFindCopilotBinary_ViaPath (t * testing.T ) {
230+ tmp := t .TempDir ()
231+ t .Setenv ("ProgramFiles" , filepath .Join (tmp , "nonexistent" ))
232+ t .Setenv ("APPDATA" , "" )
233+
234+ // Place a copilot.exe on PATH.
235+ binDir := filepath .Join (tmp , "bin" )
236+ if err := os .MkdirAll (binDir , 0o755 ); err != nil {
237+ t .Fatalf ("creating bin dir: %v" , err )
238+ }
239+ fakeBinary := filepath .Join (binDir , "copilot.exe" )
240+ if err := os .WriteFile (fakeBinary , []byte ("fake" ), 0o755 ); err != nil {
241+ t .Fatalf ("writing fake binary: %v" , err )
242+ }
243+ t .Setenv ("PATH" , binDir )
244+
245+ got := findCopilotBinary ()
246+ if got != fakeBinary {
247+ t .Errorf ("findCopilotBinary() = %q, want %q" , got , fakeBinary )
248+ }
249+ }
250+
226251// ---------------------------------------------------------------------------
227252// Maintain — 56% coverage, test error branches
228253// ---------------------------------------------------------------------------
0 commit comments