Skip to content

Commit cd4f890

Browse files
committed
fix(NODE-7512): work around Windows C:/Z: NTFS junction in CI scripts
On some Windows Evergreen hosts, install-node.sh resolves NODE_ARTIFACTS_PATH to Z: (via realpath following an NTFS junction) but DRIVERS_TOOLS is always set to C: by prepare-shell.sh. When run-tests.sh later calls init-node-and-npm-env.sh via the C: path, NODE_ARTIFACTS_PATH gets recomputed to C: and npm is not found. Fix by persisting the correctly-resolved NODE_ARTIFACTS_PATH to $DRIVERS_TOOLS/.env in install-dependencies.sh, and restoring it in run-tests.sh if npm is inaccessible after init-node-and-npm-env.sh runs.
1 parent ac6efd8 commit cd4f890

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

.evergreen/install-dependencies.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ if [ -z ${NODE_LTS_VERSION+omitted} ]; then echo "NODE_LTS_VERSION is unset" &&
1212
# be handled by this script in drivers tools.
1313
source $DRIVERS_TOOLS/.evergreen/install-node.sh
1414

15+
# On Windows, install-node.sh resolves SCRIPT_DIR via realpath which may follow an NTFS
16+
# junction (e.g. C: -> Z:), so NODE_ARTIFACTS_PATH is now correctly set to the real drive.
17+
# Persist it to .env so that subsequent shells (e.g. run-tests.sh) can recover it even
18+
# when they call init-node-and-npm-env.sh via the C: DRIVERS_TOOLS path.
19+
if [ "${OS:-}" = "Windows_NT" ] && [ -n "${NODE_ARTIFACTS_PATH:-}" ]; then
20+
echo "NODE_ARTIFACTS_PATH=${NODE_ARTIFACTS_PATH}" >> "${DRIVERS_TOOLS}/.env"
21+
fi
22+
_INSTALL_DEPS_NODE_ARTIFACTS_PATH="${NODE_ARTIFACTS_PATH:-}"
23+
1524
if [ "$NATIVE" = "true" ]; then
1625
# https://github.com/nodejs/node-gyp#configuring-python-dependency
1726
. $DRIVERS_TOOLS/.evergreen/find-python3.sh
@@ -22,3 +31,10 @@ fi
2231
npm install "${NPM_OPTIONS}"
2332

2433
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
34+
# On Windows, the init call above may have overwritten NODE_ARTIFACTS_PATH with the wrong
35+
# drive letter. Restore the previously resolved path if npm is no longer accessible.
36+
if [ "${OS:-}" = "Windows_NT" ] && [ -n "$_INSTALL_DEPS_NODE_ARTIFACTS_PATH" ] && ! command -v npm >/dev/null 2>&1; then
37+
export NODE_ARTIFACTS_PATH="$_INSTALL_DEPS_NODE_ARTIFACTS_PATH"
38+
export PATH="$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
39+
hash -r
40+
fi

.evergreen/run-tests.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,19 @@ echo "Running $AUTH tests over $SSL, connecting to $MONGODB_URI"
3636
if [[ -z "${SKIP_DEPS}" ]]; then
3737
source "${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh"
3838
else
39+
# On Windows, DRIVERS_TOOLS is a C: path but Node may have been installed on Z: (NTFS
40+
# junction). Load NODE_ARTIFACTS_PATH written by install-dependencies.sh before calling
41+
# init so we can restore it if init resolves to the wrong drive.
42+
_RUN_TESTS_SAVED_NODE_PATH=""
43+
if [ "${OS:-}" = "Windows_NT" ] && [ -f "${DRIVERS_TOOLS}/.env" ]; then
44+
_RUN_TESTS_SAVED_NODE_PATH=$(grep '^NODE_ARTIFACTS_PATH=' "${DRIVERS_TOOLS}/.env" | tail -1 | cut -d= -f2-)
45+
fi
3946
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
47+
if [ "${OS:-}" = "Windows_NT" ] && [ -n "$_RUN_TESTS_SAVED_NODE_PATH" ] && ! command -v npm >/dev/null 2>&1; then
48+
export NODE_ARTIFACTS_PATH="$_RUN_TESTS_SAVED_NODE_PATH"
49+
export PATH="$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
50+
hash -r
51+
fi
4052
fi
4153

4254
if [ "$COMPRESSOR" != "" ]; then

0 commit comments

Comments
 (0)