Troubleshooting: Copilot CLI Installation False Negative¶
Quick solution for when amplihack copilot reports installation failure despite successful installation.
Quick Diagnosis¶
Run this diagnostic to verify actual installation status:
# Check if Copilot CLI is actually installed
which github-copilot-cli
# Check npm global packages
npm list -g github-copilot-cli
Expected output if installed:
Issue: "Failed to install Copilot CLI" Despite Successful Installation¶
Symptoms¶
- Installation completes successfully (npm returns exit code 0)
- Message displays: "Failed to install Copilot CLI"
- Command exits with error code 1
- Running
which github-copilot-clishows installation succeeded - Subsequent runs work correctly
Cause¶
Fixed in version 0.3.2
The launch_copilot() function performed redundant verification after installation that failed due to PATH propagation timing. The code trusted the initial shutil.which() check but then re-checked after installation, catching a race condition where the PATH hadn't propagated yet.
Technical Details¶
The bug occurred in this flow:
# 1. Initial check passes (Copilot not installed)
if not shutil.which("github-copilot-cli"):
# 2. install_copilot() runs and succeeds
success = install_copilot() # Returns True, installation worked
# 3. Redundant verification fails (PATH timing issue)
if not shutil.which("github-copilot-cli"):
print("Failed to install...") # FALSE NEGATIVE
sys.exit(1)
The redundant verification in step 3 would fail because:
- npm's global installation completes successfully
- Binary is written to disk
- Shell PATH hasn't propagated to current process yet
shutil.which()can't find the binary immediately
Solution¶
The fix removes the redundant verification and trusts the installer's return value:
# Now correctly trusts the installer
if not shutil.which("github-copilot-cli"):
success = install_copilot() # Validates via npm exit code
if not success:
print("Failed to install Copilot CLI")
sys.exit(1)
print("Successfully installed Copilot CLI")
Changes:
- Removed redundant
shutil.which()check after installation - Trust
install_copilot()return value (already validates via npm exit code) - Display success message when installation completes
- Exit with code 0 on success, code 1 only on actual failure
Verification¶
After the fix, successful installation shows:
$ amplihack copilot
Installing Copilot CLI...
Successfully installed Copilot CLI
[Copilot CLI launches]
Failed installation shows:
Testing¶
The fix includes comprehensive test coverage:
Unit Tests¶
def test_launch_copilot_installs_when_missing():
"""Verify installation triggers when CLI not found."""
with patch('shutil.which', return_value=None), \
patch('amplihack.launcher.install_copilot', return_value=True):
# Should succeed after installation
launch_copilot()
def test_launch_copilot_reports_install_failure():
"""Verify failure reported when installation actually fails."""
with patch('shutil.which', return_value=None), \
patch('amplihack.launcher.install_copilot', return_value=False):
with pytest.raises(SystemExit) as exc:
launch_copilot()
assert exc.value.code == 1
Integration Tests¶
Test on fresh system without Copilot CLI:
# Uninstall Copilot CLI
npm uninstall -g github-copilot-cli
# Test installation from scratch
amplihack copilot
# Verify success message appears and CLI launches
Related Issues¶
- PATH propagation timing: Other tools that verify immediately after installation may hit similar issues
- npm global installs: Consider using
npm bin -gto check installation location instead of PATH lookup - Subprocess environment: Child processes inherit environment at spawn time, not dynamically
Prevention¶
To avoid similar issues in other commands:
- Trust the installer: If installation tool returns success, don't re-verify immediately
- Check exit codes: npm/pip exit codes are reliable (0 = success, non-zero = failure)
- Document timing: Note that PATH propagation isn't instant
- Test on fresh systems: Integration tests should install from scratch
Additional Resources¶
- Copilot CLI Integration - Complete integration guide
- Platform Bridge - Multi-platform support patterns
Last Updated: 2025-02-13 Fixed In Version: 0.3.2 Affects: amplihack copilot command on fresh installations