Skip to content

Commit 339dbf1

Browse files
maybeechohwille
andauthored
#1405: Fix integration test order dependency (#1657)
Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>
1 parent c9f3bb7 commit 339dbf1

3 files changed

Lines changed: 168 additions & 26 deletions

File tree

cli/src/test/all-tests-functions.sh

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,40 @@ function doDownloadSnapshot () {
4343
local url
4444
# Change OS type based on github workflow matrix.os name
4545
local osType
46-
if [ "${MATRIX_OS}" == "windows-latest" ]; then
47-
osType="windows-x64"
48-
elif [ "${MATRIX_OS}" == "ubuntu-latest" ]; then
49-
osType="linux-x64"
50-
elif [ "${MATRIX_OS}" == "macos-latest" ]; then
51-
osType="mac-arm64"
52-
elif [ "${MATRIX_OS}" == "macos-13" ]; then
53-
osType="mac-x64"
54-
fi
55-
url=$(grep "href=\"https://.*${osType}.tar.gz" "$pageHtmlLocal" | grep -o "https://.*${osType}.tar.gz" | cut -f1 -d"\"")
46+
osType=$(doGetOsType)
47+
url=$(grep "href=\"https://.*${osType}.tar.gz" "$pageHtmlLocal" | grep -o "https://[^\"]*${osType}.tar.gz" | head -1)
5648
echo "Trying to download IDEasy for OS: ${osType} from: ${url} to: ${IDEASY_COMPRESSED_FILE:?} ..."
5749
curl -o "${IDEASY_COMPRESSED_FILE:?}" "$url"
5850
rm "${pageHtmlLocal:?}"
5951
fi
6052
}
6153

54+
function doGetOsType() {
55+
local osType
56+
case "$OSTYPE" in
57+
msys*|cygwin*|win32*)
58+
osType="windows-x64"
59+
;;
60+
linux*|gnu*)
61+
osType="linux-x64"
62+
;;
63+
darwin*|macos*)
64+
# Try to distinguish between Apple Silicon and Intel Macs
65+
if sysctl -n machdep.cpu.brand_string 2>/dev/null | grep -qi "Apple"; then
66+
osType="mac-arm64"
67+
else
68+
osType="mac-x64"
69+
fi
70+
;;
71+
*)
72+
echo "Unknown OSTYPE: $OSTYPE. Falling back to windows (most common developer machine)." >&2
73+
osType="windows-x64"
74+
;;
75+
esac
76+
echo "Detected OS type: ${osType}" >&2
77+
echo "$osType"
78+
}
79+
6280

6381
function doExtract() {
6482
echo "Extracting IDEasy archive: ${IDEASY_COMPRESSED_FILE} to: ${IDEASY_DIR}"
@@ -86,15 +104,17 @@ function doError() {
86104
}
87105

88106
function doIsMacOs() {
89-
if [ "${OSTYPE:0:6}" = "darwin" ]
107+
local osType=$(doGetOsType)
108+
if [ "$osType" = "mac-arm64" ] || [ "$osType" = "mac-x64" ]
90109
then
91110
return
92111
fi
93112
return 255
94113
}
95114

96115
function doIsWindows() {
97-
if [ "${OSTYPE}" = "cygwin" ] || [ "${OSTYPE}" = "msys" ]
116+
local osType=$(doGetOsType)
117+
if [ "$osType" = "windows-x64" ]
98118
then
99119
return
100120
fi

cli/src/test/all-tests.sh

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,55 @@ touch "${HOME}"/.ide/.license.agreement
88

99
source "$(dirname "${0}")"/all-tests-functions.sh
1010

11-
MATRIX_OS="$1"
11+
# Remove side-effects
12+
BAK_IDE_ROOT="${IDE_ROOT}"
13+
BAK_PATH="${PATH}"
14+
DEBUG_INTEGRATION_TEST_PREFIX="${HOME}/tmp/ideasy-integration-test-debug"
15+
16+
# Create backups of shell RC files to prevent destroying user's existing configuration
17+
BAK_BASHRC=""
18+
BAK_ZSHRC=""
19+
if [ -f "$HOME/.bashrc" ]; then
20+
BAK_BASHRC="$HOME/.bashrc.ideasy-test-backup"
21+
cp "$HOME/.bashrc" "$BAK_BASHRC"
22+
fi
23+
if [ -f "$HOME/.zshrc" ]; then
24+
BAK_ZSHRC="$HOME/.zshrc.ideasy-test-backup"
25+
cp "$HOME/.zshrc" "$BAK_ZSHRC"
26+
fi
27+
28+
trap "export PATH=\"${BAK_PATH}\" && export IDE_ROOT=\"${BAK_IDE_ROOT}\" && rm -rf \"${DEBUG_INTEGRATION_TEST_PREFIX}\" && doRestoreRcFiles && echo \"PATH, IDE_ROOT, and shell RC files restored\"" EXIT
29+
30+
function doRestoreRcFiles() {
31+
# Restore shell RC files from backups to preserve user's existing configuration
32+
if [ -n "$BAK_BASHRC" ] && [ -f "$BAK_BASHRC" ]; then
33+
mv "$BAK_BASHRC" "$HOME/.bashrc"
34+
echo "Restored ~/.bashrc from backup"
35+
fi
36+
if [ -n "$BAK_ZSHRC" ] && [ -f "$BAK_ZSHRC" ]; then
37+
mv "$BAK_ZSHRC" "$HOME/.zshrc"
38+
echo "Restored ~/.zshrc from backup"
39+
fi
40+
}
41+
42+
function doResetVariables() {
43+
IDE_HOME="${DEBUG_INTEGRATION_TEST}/home-dir"
44+
export IDE_ROOT="${IDE_HOME}/projects"
45+
IDEASY_DIR="${IDE_ROOT}/_ide"
46+
FUNCTIONS="${IDEASY_DIR}/installation/functions"
47+
IDE="${DEBUG_INTEGRATION_TEST}/home-dir/projects/_ide/bin/${BINARY_FILE_NAME}"
48+
TEST_RESULTS_FILE="${IDE_ROOT}/testResults"
49+
}
50+
1251
# Switch IDEasy binary file name based on github workflow matrix.os name (first argument of all-tests.sh)
1352
BINARY_FILE_NAME="ideasy"
14-
if [ "${MATRIX_OS}" == "windows-latest" ]; then
53+
if doIsWindows; then
1554
BINARY_FILE_NAME="ideasy.exe"
1655
fi
1756

1857
START_TIME=$(date '+%Y-%m-%d_%H-%M-%S')
19-
20-
DEBUG_INTEGRATION_TEST_PREFIX="${HOME}/tmp/ideasy-integration-test-debug"
2158
DEBUG_INTEGRATION_TEST="${DEBUG_INTEGRATION_TEST_PREFIX}-${START_TIME}"
22-
IDE_HOME="${DEBUG_INTEGRATION_TEST}/home-dir"
23-
export IDE_ROOT="${IDE_HOME}/projects"
24-
IDEASY_DIR="${IDE_ROOT}/_ide"
25-
FUNCTIONS="${IDEASY_DIR}/installation/functions"
26-
IDE="${DEBUG_INTEGRATION_TEST}/home-dir/projects/_ide/bin/${BINARY_FILE_NAME}"
27-
TEST_RESULTS_FILE="${IDE_ROOT}/testResults"
59+
doResetVariables
2860

2961
test_files_directory=$(realpath "$0" | xargs dirname)
3062

@@ -35,6 +67,7 @@ total=0
3567
function doTestsInner() {
3668
# Note: requires var test_files_directory to be set.
3769
for testpath in "${test_files_directory:?}/integration-tests"/*; do
70+
doResetVariables
3871
testcase="${testpath/*\//}"
3972
echo "Running test #${total}: ${testcase} (${testpath})"
4073

@@ -69,8 +102,6 @@ function doDisplayResults() {
69102
while read -r line; do echo -e "${line}"; done < "${TEST_RESULTS_FILE}"
70103
}
71104

72-
73-
74105
function doTests () {
75106
doTestsInner
76107
echo -e "\n*****************************************************"
@@ -114,11 +145,22 @@ function main () {
114145

115146
# upgrade to latest snapshot
116147
echo "Upgrading IDEasy to latest SNAPSHOT"
117-
$IDE -d --batch upgrade --mode=snapshot
148+
$IDE -d --batch upgrade --mode=snapshot || echo "Upgrade failed, continuing with downloaded version"
118149

119150
# source functions (resets IDEasy)
120151
echo "Sourcing functions to: ${FUNCTIONS}"
121-
source "${FUNCTIONS:?}"
152+
# Add IDE bin to PATH so ideasy command can be found
153+
export PATH="${IDEASY_DIR}/bin:$PATH"
154+
# Try installation path first, then fall back to root
155+
if [ -f "${FUNCTIONS:?}" ]; then
156+
source "${FUNCTIONS:?}"
157+
elif [ -f "${IDEASY_DIR}/functions" ]; then
158+
echo "Using functions from root: ${IDEASY_DIR}/functions"
159+
source "${IDEASY_DIR}/functions"
160+
else
161+
echo "ERROR: Could not find functions file"
162+
exit 1
163+
fi
122164

123165
echo "Checking version after upgrade"
124166
ide -v
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
# Integration test to reproduce the issue where force install (-f) breaks environment
4+
# for subsequent tests when executed in alphabetical order
5+
6+
echo "Running force install integration test to reproduce environment interference issue"
7+
8+
# Capture initial environment state
9+
echo "=== Initial Environment State ==="
10+
env | grep -E "IDE|PATH" | sort > /tmp/env_initial.txt
11+
echo "IDE_ROOT: '$IDE_ROOT'"
12+
echo "PATH: '$PATH'"
13+
14+
# Create a dummy .gitconfig file for testing
15+
touch "$HOME"/.gitconfig
16+
17+
# Capture environment variables before force install
18+
echo "=== Environment before force install ==="
19+
env | sort > /tmp/env_before_force.txt
20+
echo "Shell RC files before:"
21+
echo "~/.bashrc exists: $(test -f ~/.bashrc && echo "yes" || echo "no")"
22+
if [ -f ~/.bashrc ]; then
23+
echo "Last 20 lines of ~/.bashrc:"
24+
tail -20 ~/.bashrc
25+
fi
26+
27+
# Run force install to reproduce the issue
28+
echo "=== Running force install ==="
29+
$IDE -f install
30+
31+
# Capture environment variables after force install
32+
echo "=== Environment after force install ==="
33+
env | sort > /tmp/env_after_force.txt
34+
echo "Shell RC files after:"
35+
echo "~/.bashrc exists: $(test -f ~/.bashrc && echo "yes" || echo "no")"
36+
if [ -f ~/.bashrc ]; then
37+
echo "Last 20 lines of ~/.bashrc:"
38+
tail -20 ~/.bashrc
39+
fi
40+
41+
# Show the differences
42+
echo "=== Environment variable differences ==="
43+
diff /tmp/env_before_force.txt /tmp/env_after_force.txt || true
44+
45+
# Test that the git longpaths configuration gets set (original test purpose)
46+
echo "=== Testing git longpaths configuration ==="
47+
if doIsWindows; then
48+
gitconfig_path="$HOME"/.gitconfig
49+
fileContent=$(cat "$gitconfig_path")
50+
assertThat "$fileContent" contains "longpaths"
51+
else
52+
echo "Skipping git longpaths test - only applicable on Windows"
53+
fi
54+
55+
# Test that subsequent IDE commands still work
56+
echo "=== Testing subsequent IDE commands ==="
57+
ide_version_output=$($IDE -v 2>&1)
58+
if [[ $? -eq 0 ]]; then
59+
echo "SUCCESS: IDE version command works after force install"
60+
echo "Version output: $ide_version_output"
61+
else
62+
echo "FAILURE: IDE version command failed after force install"
63+
echo "Error output: $ide_version_output"
64+
fi
65+
66+
# Test ide env command
67+
echo "=== Testing ide env command ==="
68+
ide_env_output=$($IDE env --bash 2>&1)
69+
if [[ $? -eq 0 ]]; then
70+
echo "SUCCESS: IDE env command works after force install"
71+
echo "Environment variables count: $(echo "$ide_env_output" | wc -l)"
72+
else
73+
echo "FAILURE: IDE env command failed after force install"
74+
echo "Error output: $ide_env_output"
75+
fi
76+
77+
# Clean up temporary files
78+
rm -f /tmp/env_initial.txt /tmp/env_before_force.txt /tmp/env_after_force.txt
79+
80+
echo "Force install test completed"

0 commit comments

Comments
 (0)