Skip to content

Commit 69a5174

Browse files
committed
Add test to verify that scripts are still executed even if ado-helper fails
1 parent f959bcc commit 69a5174

File tree

5 files changed

+68
-13
lines changed

5 files changed

+68
-13
lines changed

src/artifacts-helper/README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ to download the package.
7777

7878
The shim scripts (e.g., `dotnet`, `npm`, `nuget`) now include a wait mechanism for the Azure DevOps authentication helper. When invoked, these scripts will:
7979

80-
1. Wait up to 3 minutes for the `ado-auth-helper` to become available
80+
1. Wait up to 3 minutes for the `ado-auth-helper` to become available (configurable via `MAX_WAIT` environment variable)
8181
2. Display progress indicators every 20 seconds while waiting
8282
3. Continue execution once authentication is successful
83-
4. Return an error (but not terminate dependent scripts) if the helper is not available after the timeout
83+
4. **Continue with the underlying command even if authentication is not available** after the timeout
8484

85-
This ensures that package restore operations can proceed even if there's a slight delay in the authentication helper installation, which can occur in some codespace initialization scenarios.
85+
This ensures that package restore operations can proceed even if there's a slight delay in the authentication helper installation, which can occur in some codespace initialization scenarios. Commands will still execute without authentication, though they may fail to access private Azure Artifacts feeds.
8686

87-
The scripts are designed to be sourced safely, meaning they won't terminate the calling shell if authentication fails - they will simply return an error code that can be handled by the calling script.
87+
The scripts are designed to be sourced safely, meaning they won't terminate the calling shell if authentication fails - they will simply return an error code and allow the underlying tool to execute. This allows you to work with public packages or other package sources even when Azure Artifacts authentication is unavailable.
8888

8989
## OS Support
9090

@@ -102,11 +102,6 @@ devcontainer features test -f artifacts-helper
102102
devcontainer features test -f artifacts-helper --scenario test_auth_wait
103103
```
104104

105-
The test suite includes:
106-
- **test_auth_wait.sh**: Verifies that auth-ado.sh can be sourced without terminating the shell
107-
- **test_shim_integration.sh**: Tests that shim scripts properly handle missing authentication helper
108-
- **Python keyring tests**: Validates Python package installation with Azure Artifacts authentication
109-
110105
## Changing where functions are configured
111106

112107
By default, the functions are defined in `/etc/bash.bashrc` and `/etc/zsh/zshrc` if the container user is `root`, otherwise `~/.bashrc` and `~/.zshrc`.

src/artifacts-helper/scripts/auth-ado.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
echo "::step::Waiting for AzDO Authentication Helper..."
44

55
# Wait up to 3 minutes for the ado-auth-helper to be installed
6-
MAX_WAIT=180
6+
# Can be overridden via environment variable for testing
7+
MAX_WAIT=${MAX_WAIT:-180}
78
ELAPSED=0
89

910
while [ $ELAPSED -lt $MAX_WAIT ]; do
@@ -22,8 +23,8 @@ while [ $ELAPSED -lt $MAX_WAIT ]; do
2223
fi
2324
done
2425

25-
# Timeout reached
26-
echo "::error::AzDO Authentication Helper not found after ${MAX_WAIT} seconds"
26+
# Timeout reached - continue without authentication
27+
echo "::warning::AzDO Authentication Helper not found after ${MAX_WAIT} seconds"
2728
echo "Expected location: ${HOME}/ado-auth-helper"
28-
echo "Restore cannot proceed without authentication"
29+
echo "Continuing without Azure Artifacts authentication..."
2930
return 1

test/artifacts-helper/scenarios.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,17 @@
5858
"nugetAlias": true
5959
}
6060
}
61+
},
62+
"test_fallback_execution": {
63+
"image": "mcr.microsoft.com/devcontainers/base:debian",
64+
"features": {
65+
"ghcr.io/devcontainers/features/dotnet:1": {},
66+
"ghcr.io/devcontainers/features/node:1": {},
67+
"artifacts-helper": {
68+
"dotnetAlias": true,
69+
"npmAlias": true,
70+
"nugetAlias": true
71+
}
72+
}
6173
}
6274
}

test/artifacts-helper/test_auth_wait.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ check "npm shim exists" test -f /usr/local/share/codespace-shims/npm
99
check "nuget shim exists" test -f /usr/local/share/codespace-shims/nuget
1010

1111
# Test that auth-ado.sh can be sourced without exiting the shell
12+
export MAX_WAIT=5
1213
check "auth-ado.sh can be sourced" bash -c 'source /usr/local/share/codespace-shims/auth-ado.sh 2>/dev/null || true; echo "still running"'
1314

1415
# Test that sourcing auth-ado.sh doesn't terminate the parent shell
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
# Import test library bundled with the devcontainer CLI
4+
source dev-container-features-test-lib || exit 1
5+
6+
# Test that shim scripts call the underlying command even when auth helper is not found
7+
8+
# Create a temporary directory to simulate a clean environment
9+
TEST_HOME=$(mktemp -d)
10+
11+
# Mock scenario: ado-auth-helper doesn't exist, but the underlying command should still run
12+
check "dotnet command executes without auth helper" bash -c '
13+
# Use a short timeout to avoid waiting 3 minutes
14+
# The shim should call dotnet even if auth fails
15+
export HOME='"$TEST_HOME"'
16+
export MAX_WAIT=5
17+
18+
# Call dotnet --version which should work even without auth
19+
timeout 10 /usr/local/share/codespace-shims/dotnet --version 2>&1 | grep -q "dotnet\|\.NET" && echo "SUCCESS" || echo "FAILED"
20+
' | grep -q "SUCCESS"
21+
22+
# Test with npm as well
23+
check "npm command executes without auth helper" bash -c '
24+
export HOME='"$TEST_HOME"'
25+
export MAX_WAIT=5
26+
27+
# npm --version should work without auth
28+
timeout 10 /usr/local/share/codespace-shims/npm --version 2>&1 | grep -q "[0-9]\+\.[0-9]\+\.[0-9]\+" && echo "SUCCESS" || echo "FAILED"
29+
' | grep -q "SUCCESS"
30+
31+
# Test that nuget can be called (may not return version without auth, but should not crash)
32+
check "nuget command attempts to execute without auth helper" bash -c '
33+
export HOME='"$TEST_HOME"'
34+
export MAX_WAIT=5
35+
36+
# Try to call nuget - it should attempt to run even if auth fails
37+
timeout 10 /usr/local/share/codespace-shims/nuget help 2>&1 || true
38+
# Just verify we get here without the shell crashing
39+
echo "completed"
40+
' | grep -q "completed"
41+
42+
# Cleanup
43+
rm -rf "$TEST_HOME"
44+
45+
# Report results
46+
reportResults

0 commit comments

Comments
 (0)