|
| 1 | +# Testing Azure Artifacts Helper |
| 2 | + |
| 3 | +This document describes how to test the artifacts-helper feature, particularly the authentication wait behavior and shim script resilience. |
| 4 | + |
| 5 | +## Test Scenarios |
| 6 | + |
| 7 | +### 1. Authentication Wait Test (`test_auth_wait`) |
| 8 | + |
| 9 | +**Purpose**: Verify that the auth-ado.sh script can be sourced without terminating the parent shell. |
| 10 | + |
| 11 | +**What it tests**: |
| 12 | +- Shim scripts exist in `/usr/local/share/codespace-shims/` |
| 13 | +- `auth-ado.sh` can be sourced multiple times without crashing |
| 14 | +- Sourcing the script doesn't terminate the parent shell even on error |
| 15 | + |
| 16 | +**Expected behavior**: |
| 17 | +- Scripts are executable and in the correct location |
| 18 | +- Sourcing auth-ado.sh returns control to the caller |
| 19 | +- Parent shell continues executing after sourcing fails |
| 20 | + |
| 21 | +### 2. Shim Integration Test (`test_shim_integration`) |
| 22 | + |
| 23 | +**Purpose**: Test that shim scripts properly handle missing authentication helper. |
| 24 | + |
| 25 | +**What it tests**: |
| 26 | +- Shim scripts source auth-ado.sh correctly |
| 27 | +- Scripts handle timeout gracefully when ado-auth-helper is missing |
| 28 | +- Shim directory is in PATH |
| 29 | +- Scripts don't crash when authentication fails |
| 30 | + |
| 31 | +**Expected behavior**: |
| 32 | +- Shims wait for up to 3 minutes for authentication |
| 33 | +- Timeout error is returned but doesn't crash the script |
| 34 | +- Calling scripts can continue or handle error appropriately |
| 35 | + |
| 36 | +### 3. Python Keyring Tests |
| 37 | + |
| 38 | +Multiple scenarios test Python integration: |
| 39 | +- `python38_and_keyring_debian`: Python 3.8 on Debian with keyring |
| 40 | +- `python38_and_keyring_ubuntu`: Python 3.8 on Ubuntu with keyring |
| 41 | +- `python312_and_keyring_debian`: Python 3.12 on Debian with keyring |
| 42 | +- `python_and_no_keyring`: Python without keyring helper |
| 43 | + |
| 44 | +## Running Tests |
| 45 | + |
| 46 | +### Run All Tests |
| 47 | + |
| 48 | +```bash |
| 49 | +cd /path/to/codespace-features |
| 50 | +devcontainer features test -f artifacts-helper |
| 51 | +``` |
| 52 | + |
| 53 | +### Run Specific Test Scenario |
| 54 | + |
| 55 | +```bash |
| 56 | +devcontainer features test -f artifacts-helper --scenario test_auth_wait |
| 57 | +devcontainer features test -f artifacts-helper --scenario test_shim_integration |
| 58 | +``` |
| 59 | + |
| 60 | +### Run Individual Test Script |
| 61 | + |
| 62 | +If you want to test a specific script in an already-built container: |
| 63 | + |
| 64 | +```bash |
| 65 | +# Inside a devcontainer with artifacts-helper installed |
| 66 | +bash /path/to/test/artifacts-helper/test_auth_wait.sh |
| 67 | +``` |
| 68 | + |
| 69 | +## Manual Testing |
| 70 | + |
| 71 | +### Test Authentication Wait Behavior |
| 72 | + |
| 73 | +1. Create a test devcontainer with artifacts-helper feature |
| 74 | +2. Remove or delay the ado-auth-helper installation |
| 75 | +3. Try to run a package manager command (e.g., `dotnet restore`) |
| 76 | +4. Observe that the script waits and shows progress |
| 77 | +5. Verify the script eventually times out with error but doesn't crash |
| 78 | + |
| 79 | +```bash |
| 80 | +# Mock a scenario where ado-auth-helper is missing |
| 81 | +rm -f ~/ado-auth-helper |
| 82 | + |
| 83 | +# Try to run dotnet - should wait and timeout gracefully |
| 84 | +timeout 10 dotnet --version |
| 85 | +echo "Exit code: $?" # Should be non-zero but script continues |
| 86 | + |
| 87 | +# Verify we can still run commands |
| 88 | +echo "Shell is still active" |
| 89 | +``` |
| 90 | + |
| 91 | +### Test Shim Sourcing Behavior |
| 92 | + |
| 93 | +```bash |
| 94 | +# Test that sourcing doesn't exit the shell |
| 95 | +bash -c ' |
| 96 | + source /usr/local/share/codespace-shims/auth-ado.sh 2>/dev/null || echo "Returned with error" |
| 97 | + echo "Shell still running" |
| 98 | +' |
| 99 | +``` |
| 100 | + |
| 101 | +### Test with Actual Authentication |
| 102 | + |
| 103 | +1. Set up a codespace with the ADO Codespaces Auth extension |
| 104 | +2. Configure an Azure Artifacts feed |
| 105 | +3. Wait for ado-auth-helper to be installed |
| 106 | +4. Run package restore commands |
| 107 | +5. Verify authentication succeeds |
| 108 | + |
| 109 | +## What Changed in PR #85 |
| 110 | + |
| 111 | +The key changes improve resilience when the authentication helper isn't immediately available: |
| 112 | + |
| 113 | +1. **Added wait loop**: Scripts now wait up to 3 minutes for ado-auth-helper |
| 114 | +2. **Removed `set -e`**: Prevents sourced script from terminating parent shell |
| 115 | +3. **Changed `exit` to `return`**: Allows error handling in calling scripts |
| 116 | +4. **Added progress indicators**: Shows wait progress every 20 seconds |
| 117 | +5. **Fixed PATH**: Uses hardcoded `/usr/local/share/codespace-shims` instead of variable |
| 118 | + |
| 119 | +## Troubleshooting Test Failures |
| 120 | + |
| 121 | +### "auth-ado.sh terminates shell" |
| 122 | +- Check that `set -e` is removed from auth-ado.sh |
| 123 | +- Verify `return 1` is used instead of `exit 1` |
| 124 | + |
| 125 | +### "Shim scripts not found" |
| 126 | +- Verify PATH includes `/usr/local/share/codespace-shims` |
| 127 | +- Check that install.sh properly creates the shim scripts |
| 128 | +- Ensure containerEnv in devcontainer-feature.json is correct |
| 129 | + |
| 130 | +### "Tests timeout" |
| 131 | +- Reduce MAX_WAIT in auth-ado.sh for faster testing |
| 132 | +- Use `timeout` command to limit test duration |
| 133 | +- Check that progress indicators are working |
| 134 | + |
| 135 | +## CI/CD Integration |
| 136 | + |
| 137 | +These tests are designed to work with the devcontainer features test framework and can be integrated into CI/CD pipelines: |
| 138 | + |
| 139 | +```yaml |
| 140 | +- name: Test artifacts-helper feature |
| 141 | + run: | |
| 142 | + devcontainer features test -f artifacts-helper |
| 143 | +``` |
0 commit comments