@@ -113,21 +113,26 @@ test_remote_user_root() {
113113
114114# Test 10: Finding vscode user if it exists
115115test_find_vscode_user () {
116- # Check if vscode user exists
117- if id -u vscode > /dev/null 2>&1 ; then
116+ # Check if vscode user exists and no higher priority users exist
117+ if id -u vscode > /dev/null 2>&1 && \
118+ ! id -u devcontainer > /dev/null 2>&1 ; then
119+ # Unset _REMOTE_USER to ensure it doesn't interfere
120+ unset _REMOTE_USER
118121 local result=$( determine_user_from_input " automatic" )
119122 # Should find vscode (it's second in priority after devcontainer)
120123 run_test " Finds vscode user in automatic mode" " vscode" " ${result} "
121124 else
122- # Skip this test if vscode user doesn't exist
123- run_test " Finds vscode user in automatic mode (SKIPPED - user doesn't exist )" " SKIP" " SKIP"
125+ # Skip this test if vscode user doesn't exist or higher priority user exists
126+ run_test " Finds vscode user in automatic mode (SKIPPED - conditions not met )" " SKIP" " SKIP"
124127 fi
125128}
126129
127130# Test 11: Finding devcontainer user (highest priority)
128131test_find_devcontainer_user () {
129132 # Check if devcontainer user exists
130133 if id -u devcontainer > /dev/null 2>&1 ; then
134+ # Unset _REMOTE_USER to ensure it doesn't interfere
135+ unset _REMOTE_USER
131136 local result=$( determine_user_from_input " automatic" )
132137 # Should find devcontainer (highest priority)
133138 run_test " Finds devcontainer user (highest priority)" " devcontainer" " ${result} "
@@ -165,6 +170,18 @@ test_empty_input() {
165170 run_test " Empty input treated as automatic and finds UID 1000 or uses fallback" " ${expected} " " ${result} "
166171}
167172
173+ # Test 14: _REMOTE_USER set to non-existent user should use fallback
174+ test_remote_user_nonexistent () {
175+ export _REMOTE_USER=" nonexistentuser99999"
176+ local result=$( determine_user_from_input " automatic" " mydefault" )
177+ unset _REMOTE_USER
178+
179+ # Should fall through to normal detection - find UID 1000 or use fallback
180+ local uid_1000_user=$( awk -v val=1000 -F " :" ' $3==val{print $1}' /etc/passwd 2> /dev/null || echo ' ' )
181+ local expected=" ${uid_1000_user:- mydefault} "
182+ run_test " _REMOTE_USER set to non-existent user falls back to detection" " ${expected} " " ${result} "
183+ }
184+
168185# Run all tests
169186echo " Running tests for common-setup.sh..."
170187echo " ======================================"
@@ -183,6 +200,7 @@ test_find_vscode_user
183200test_find_devcontainer_user
184201test_find_uid_1000
185202test_empty_input
203+ test_remote_user_nonexistent
186204
187205# Print summary
188206echo " "
0 commit comments