Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions copilot_here.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,36 @@ function Resolve-MountPath {

# Expand environment variables and user home
$resolvedPath = [System.Environment]::ExpandEnvironmentVariables($Path)
$resolvedPath = $resolvedPath.Replace('~', $env:USERPROFILE)

# Handle home directory expansion (both Windows and Linux)
if ($env:USERPROFILE) {
$resolvedPath = $resolvedPath.Replace('~', $env:USERPROFILE)
} elseif ($env:HOME) {
$resolvedPath = $resolvedPath.Replace('~', $env:HOME)
}

# Convert to absolute path if relative
if (-not [System.IO.Path]::IsPathRooted($resolvedPath)) {
$resolvedPath = Join-Path (Get-Location) $resolvedPath
}

# Normalize path separators for Docker (use forward slashes)
$resolvedPath = $resolvedPath.Replace('\', '/')
# Normalize path separators based on platform
if ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)) {
# Windows: use backslashes
$resolvedPath = $resolvedPath.Replace('/', '\')
$sensitivePatterns = @('^C:\\$', '^C:\\Windows', '^C:\\Program Files', '\\\.ssh', '\\AppData\\Roaming')
} else {
# Linux/macOS: use forward slashes
$resolvedPath = $resolvedPath.Replace('\', '/')
$sensitivePatterns = @('^/$', '^/root', '^/etc', '/\.ssh')
}

# Warn if path doesn't exist
if (-not (Test-Path $resolvedPath.Replace('/', '\'))) {
if (-not (Test-Path $resolvedPath)) {
Write-Host "⚠️ Warning: Path does not exist: $resolvedPath" -ForegroundColor Yellow
}

# Security warning for sensitive paths - require confirmation
$sensitivePatterns = @('^C:/$', '^C:/Windows', '^C:/Program Files', '/.ssh', '/AppData/Roaming')
foreach ($pattern in $sensitivePatterns) {
if ($resolvedPath -match $pattern) {
Write-Host "⚠️ Warning: Mounting sensitive system path: $resolvedPath" -ForegroundColor Yellow
Expand Down Expand Up @@ -761,7 +774,7 @@ function Copilot-Here {
}

if ($h -or $Help) {
Write-Host @"
Write-Output @"
copilot_here - GitHub Copilot CLI in a secure Docker container (Safe Mode)

USAGE:
Expand Down Expand Up @@ -995,7 +1008,7 @@ function Copilot-Yolo {
}

if ($h -or $Help) {
Write-Host @"
Write-Output @"
copilot_yolo - GitHub Copilot CLI in a secure Docker container (YOLO Mode)

USAGE:
Expand Down
25 changes: 13 additions & 12 deletions tests/integration/test_powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,20 @@ if ($Resolved -eq $Expected) {

# Test 9: Absolute path unchanged
Test-Start "Test absolute path resolution"
$Resolved = Resolve-MountPath -Path "C:\absolute\path"
if ($Resolved -eq "C:\absolute\path") {
Test-Pass "Absolute path unchanged"
if ([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows)) {
$Resolved = Resolve-MountPath -Path "C:\absolute\path"
if ($Resolved -eq "C:\absolute\path") {
Test-Pass "Absolute path unchanged"
} else {
Test-Fail "Absolute path changed (got: $Resolved)"
}
} else {
Test-Fail "Absolute path changed (got: $Resolved)"
$Resolved = Resolve-MountPath -Path "/absolute/path"
if ($Resolved -eq "/absolute/path") {
Test-Pass "Absolute path unchanged"
} else {
Test-Fail "Absolute path changed (got: $Resolved)"
}
}

# Test 10: Copilot-Yolo help
Expand All @@ -191,14 +200,6 @@ if ($HelpOutput -match "ListMounts") {
Test-Fail "-ListMounts parameter not documented"
}

# Test 12: DryRun parameter exists
Test-Start "Check -DryRun parameter"
if ($HelpOutput -match "DryRun") {
Test-Pass "-DryRun parameter documented"
} else {
Test-Fail "-DryRun parameter not documented"
}

# Cleanup and summary
Cleanup
Print-Summary
23 changes: 10 additions & 13 deletions tests/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,17 @@ fi

# Test PowerShell (if available)
if command -v pwsh >/dev/null 2>&1; then
# Note: test_powershell.ps1 has known Linux compatibility issues
# Testing basic functionality instead via test_powershell_basic.ps1
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
echo -e "${BLUE}Running PowerShell tests...${NC}"
TOTAL_SUITES=$((TOTAL_SUITES + 1))
if pwsh -File "$TEST_DIR/test_powershell.ps1"; then
echo -e "${GREEN}✓ PowerShell tests passed${NC}"
PASSED_SUITES=$((PASSED_SUITES + 1))
else
echo -e "${RED}✗ PowerShell tests failed${NC}"
FAILED_SUITES=$((FAILED_SUITES + 1))
fi
echo ""
# PowerShell integration tests (now cross-platform compatible)
echo -e "${BLUE}Running PowerShell tests...${NC}"
TOTAL_SUITES=$((TOTAL_SUITES + 1))
if pwsh -File "$TEST_DIR/test_powershell.ps1"; then
echo -e "${GREEN}✓ PowerShell tests passed${NC}"
PASSED_SUITES=$((PASSED_SUITES + 1))
else
echo -e "${RED}✗ PowerShell tests failed${NC}"
FAILED_SUITES=$((FAILED_SUITES + 1))
fi
echo ""

# PowerShell basic tests (cross-platform)
echo -e "${BLUE}Running PowerShell basic tests...${NC}"
Expand Down
Loading