Skip to content

DRIVERS-3590 Improve local dev workflow - #815

Merged
blink1073 merged 25 commits into
mongodb-labs:masterfrom
blink1073:add-make-install-lint
Aug 21, 2026
Merged

blink1073 merged 25 commits into
mongodb-labs:masterfrom
blink1073:add-make-install-lint

Conversation

@blink1073

@blink1073 blink1073 commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Ref: DRIVERS-3590

Summary

Adds make install, make lint, and make test-connect so local setup, linting, and connectivity checks have documented commands. mongodb_runner.py now installs Node only when it needs it, so using the other CLIs does not require installing Node.

Groundwork for an AGENTS.md describing how to run these tasks.

Reviewer notes

_mongodb_runner_supported no longer tries to gate the Node version or look for problematic package versions. It attempts the install and lets npm --engine-strict decide, so the Node requirement stays with mongodb-runner's dependencies. That costs roughly 30 seconds on hosts that fail the check, which in CI is rhel7 alone.

The OCSP and data-lake test scripts now call check-connection.sh instead of their own inline mongosh pings.

Test plan

  • make install succeeds with no Node, uv, or pre-commit present
  • make test still writes the stub results file Evergreen depends on
  • rhel7 falls back to mongo-orchestration, with npm's reason in the log
  • Patch green except test-auth-aws, which fails on master too

Add `make install` (pre-commit + python CLIs) and `make lint` targets so
contributors can bootstrap and lint without going through the orchestration
setup script. Repurpose `make test` to check connectivity to a running
server, moving the old stub JSON writer to `make test-results`.

Node.js is now installed on-demand inside mongodb_runner.py only when
mongodb-runner is actually invoked and npm isn't already available, instead
of being installed unconditionally by orchestration/setup.sh. This means
`make install` no longer requires Node.
…ndling

Keep `make test` as the original Evergreen-compatible stub (this repo's own
CI relies on it writing test-results.json via a global post-task step), and
move the real connectivity check to a new `make test-connect` target instead.

Also make the `install` target's pre-commit setup robust regardless of the
caller's PATH: pin UV_TOOL_BIN_DIR to the repo-local .bin dir (already used
for the bootstrapped uv binary) and run the uv install + pre-commit install
steps in a single shell so the PATH/UV_TOOL_BIN_DIR overrides actually apply
to both.
Replace the tests.yml workflow's inline mongosh ping with `make test-connect`,
so CI exercises the same connectivity-check path a contributor would run
locally. check-connection.sh now accepts optional extra mongosh args via
$MONGOSH_EXTRA_ARGS (used here for the SSL cert flags), rather than
positional args, since it's sourced (not just executed) by
atlas/setup.sh and serverless/setup.sh where inherited $@ would leak
unrelated caller arguments into the mongosh call.

Left the pre-commit and eslint jobs as-is: pre-commit/action already
installs+runs+caches pre-commit more efficiently than make install/lint
would (which would also pull in the unrelated Python CLI installs), and
eslint is unrelated to the new Python-focused targets.
Replace the duplicated inline mongosh ping calls in test-ocsp.sh and
test-data-lake.sh with the shared check-connection.sh, passing the
TLS/binary/URI overrides via env vars (MONGODB_URI, MONGODB_BINARIES,
MONGOSH_EXTRA_ARGS) instead of duplicating the mongosh invocation.

test-mongodb-runner.sh's connect_mongodb() is intentionally left as-is:
it needs custom eval commands and an expected-failure assertion (the
auth-rejection check) that check-connection.sh doesn't support, so it
isn't a good fit for consolidation. .evergreen/config.yml needed no
changes, since it only dispatches to these scripts and has no inline
connectivity-check logic of its own.
@blink1073 blink1073 changed the title DRIVERS-3590 Add a self-service local dev workflow DRIVERS-3590 Improve dev workflow Jul 28, 2026
…ismatch

npm's "latest" dist-tag now resolves to npm@12, which requires
Node >=22.22.2/24.15.0/26.0.0 and fails outright against the Node 20
this script installs by default. npm@10 explicitly supports
Node >=18.17.0 || >=20.5.0, so extend the existing pinning logic to
cover the 18-21 range instead of only 18-19, and reserve "latest" for
Node >=22 where it's actually compatible.

Reproduced locally: `npm install --silent --global npm@latest` against
Node 20 fails with EBADENGINE; `npm install --silent --global npm@10`
succeeds cleanly.
test-mongodb-runner-partial still fails on some hosts with
"--experimental-global-webcrypto is not allowed in NODE_OPTIONS", even
though node_major should be 20 (not <19) and shouldn't trigger this
flag at all. Reproduced Node v20.20.2 locally and confirmed the flag
works fine via NODE_OPTIONS on that exact version, so something in this
environment is causing the node_major check to behave unexpectedly.
Logging node_bin/PATH/node_ver/node_major to see the real values on
the next CI run. To be removed once the cause is confirmed.
Diagnostics showed the real bug: on some hosts (amazon2023, rhel8-power8)
an unrelated, ancient Node (v8.11.3, bundled at /opt/node for other
tooling) sits on PATH ahead of anything we'd install ourselves. The old
check only asked "does npm exist anywhere on PATH", so it found that
stale npm and skipped installing Node entirely. mongodb-runner's own
`npm install` step still succeeded against it (old npm can still resolve
and download packages), but actually running mongodb-runner then failed,
since Node 8 is far too old to even recognize the
--experimental-global-webcrypto flag our code correctly tries to add for
Node <19 - hence "not allowed in NODE_OPTIONS".

_install_mongodb_runner() now checks that node itself resolves and is
>=16 (_node_is_usable()) before trusting it, instead of just checking
for npm's presence. This forces our own Node install whenever the node
on PATH is too old, regardless of what else is present.

Removes the temporary diagnostic logging added in the previous commit
now that the cause is confirmed.
…lint

# Conflicts:
#	.evergreen/install-node.sh
#	.evergreen/orchestration/mongodb_runner.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the contributor/dev workflow by introducing Makefile targets that mirror CI behavior (install/lint/connectivity), and by refactoring connectivity checks into a shared script while making Node.js installation lazy (only when mongodb-runner is invoked).

Changes:

  • Add make install, make lint, and make test-connect targets and update CONTRIBUTING docs to point at them.
  • Centralize mongosh connectivity validation in .evergreen/check-connection.sh and reuse it from GitHub Actions + Evergreen test scripts.
  • Make Node installation lazy for mongodb-runner by installing Node from mongodb_runner.py only when needed (and removing eager Node setup from orchestration setup).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Makefile Adds install/lint/test-connect targets for local workflows.
CONTRIBUTING.md Updates contributor instructions to use the new Make targets.
.github/workflows/tests.yml Uses make test-connect to validate cluster connectivity in CI.
.evergreen/tests/test-ocsp.sh Reuses shared connectivity check instead of inline mongosh invocation.
.evergreen/tests/test-data-lake.sh Reuses shared connectivity check instead of inline mongosh invocation.
.evergreen/orchestration/setup.sh Removes eager Node installation; documents lazy Node behavior for mongodb-runner.
.evergreen/orchestration/mongodb_runner.py Adds lazy Node installation logic when mongodb-runner is installed/used.
.evergreen/check-connection.sh Adds support for passing extra mongosh args (e.g., TLS flags) via env var.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Makefile Resolved
Comment thread .evergreen/check-connection.sh Resolved
Comment thread .evergreen/tests/test-data-lake.sh Resolved
Comment thread .evergreen/tests/test-ocsp.sh Resolved
Comment thread .evergreen/orchestration/setup.sh Resolved
- Makefile: `make lint` now puts the repo-local .bin dir on PATH, so it can
  find the pre-commit that `make install` installs there. Previously a
  contributor with no global pre-commit got exit 127 from `make lint`.
  Also switch $$PWD to $(CURDIR) and join the install steps with && .
- mongodb_runner.py: align _MIN_NODE_MAJOR with mongodb-runner's actual
  Node >=18 requirement (was 16, so a Node 16/17 host was considered
  "usable" while _mongodb_runner_supported() rejected it), and factor the
  duplicated version parsing into _node_major_version() so both checks
  share one constant.
- test-ocsp.sh / test-data-lake.sh: run check-connection.sh as a
  subprocess instead of sourcing it, so it no longer overwrites the
  caller's SCRIPT_DIR or imposes `set -eu` on the caller.
- test-data-lake.sh: fix the cleanup path, which concatenated two absolute
  paths and so never removed the download dir.
- orchestration/setup.sh: use $_HERE instead of the never-set $HERE in the
  node-artifacts check, which expanded to /node-artifacts and made the
  guard always fall through to reinstalling Node.
- check-connection.sh: document why MONGOSH_EXTRA_ARGS is unquoted and add
  an explicit SC2086 disable.
_mongodb_runner_supported() ran before any Node install and judged support
from whatever "node" happened to be first on PATH. With the eager install
removed, hosts that ship an unrelated ancient Node (amazon2023 and the
Windows hosts have Node 8 at /opt/node) were reported unsupported, so
run() silently fell back to mongo-orchestration. The test-mongodb-runner
tasks stayed green while no longer exercising mongodb-runner at all, and
the Node install inside _install_mongodb_runner() was never reached on
exactly the hosts it was written for.

Split the ensure-Node step into _ensure_usable_node() and call it from the
support check, after the cheap RHEL7 platform test so old-glibc hosts still
short-circuit without downloading anything. A host with a stale Node now
installs a supported one and uses mongodb-runner; a host that genuinely
cannot get Node 18+ still degrades gracefully to mongo-orchestration
instead of raising.

Also fold the duplicated node --version parsing in start_mongodb_runner()
into _node_major_version(), and restore an explicit error when npm is
missing next to an otherwise usable Node.
DRIVERS-3564 moved install-cli.sh onto ensure-uv.sh and dropped its
fallback that symlinked uv into the repo-local bin dir. The install target
was relying on that side effect to put uv on PATH, so on a checkout with
no global uv the pre-commit step now failed with "uv: command not found".
Source ensure-uv.sh and call ensure_uv directly instead, which is the
convention the other scripts now follow.

Set SHELL to bash, since ensure-uv.sh refuses to run under a non-bash
shell and make otherwise uses /bin/sh (dash on most Linux hosts).

Also export DRIVERS_TOOLS so ensure_uv scopes UV_TOOL_DIR into the
checkout the way it does for install-cli.sh. Without it the pre-commit
tool environment was written to the developer's global uv tool dir, which
is exactly what ensure_uv's scoping is meant to avoid; the shim still goes
to the repo-local bin dir so "make lint" can find it.
install-node.sh already selects Node 16 whenever glibc is older than 2.28,
so ensuring a usable Node and then checking its major version rejects those
hosts on its own. The explicit infer_target() == "rhel7" short-circuit only
avoided a wasted Node 16 download, at the cost of importing mongodl here,
hardcoding a distro name, and duplicating install-node.sh's glibc policy in
a second place where it could silently go stale.

install-node.sh exits early when the requested version is already installed,
so the extra cost is a single Node 16 download on the affected variants.
mongodb-runner only needs Node 18+, but Node 16-18 additionally needs
--experimental-global-webcrypto in NODE_OPTIONS so the mongodb driver sees
WebCrypto as a global. Raising the floor to 20 removes the need for that
flag: start_mongodb_runner can no longer be reached with Node < 20, so the
conditional that added it was dead code, along with the environment copy
that existed only to carry it.

install-node.sh already installs Node 20 by default, so hosts that can run
it are unaffected. Hosts whose glibc limits them to Node 16 were already
falling back to mongo-orchestration and continue to.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (4)

.evergreen/orchestration/mongodb_runner.py:127

  • This support probe now installs Node, but run-mongodb.sh always passes --mongodb-runner and drivers_orchestration.py:553 calls the probe before its local-Atlas branch at line 560. Consequently make run-local-atlas still downloads Node even though mongodb-runner is never used, contrary to the PR's lazy-install behavior. Gate the probe on not opts.local_atlas or defer it into the mongodb-runner branch.
    return _ensure_usable_node()

.evergreen/orchestration/setup.sh:32

  • Checking only for the artifact directory can reuse the Node 20 installation created by the normal runner path, even though this development runner requires Node 22+. Invoke install-node.sh with version 22 unconditionally; the script already exits early when that exact version is cached.
  if [ ! -d "$_HERE/../node-artifacts" ]; then
    # The dev version requires Node 22+.
    NODE_LTS_VERSION=22 bash $_HERE/../install-node.sh

.evergreen/orchestration/mongodb_runner.py:95

  • A system can have a usable Node executable without npm (for example, when distributions package them separately). This currently makes _ensure_usable_node() return success, after which _install_mongodb_runner() raises instead of performing the promised lazy installation. Include npm in the usability check so the local Node distribution is installed when either executable is missing.

This issue also appears on line 127 of the same file.

    node_major = _node_major_version()
    return node_major is not None and node_major >= _MIN_NODE_MAJOR

CONTRIBUTING.md:67

  • make install now places pre-commit only in the repository-local .bin, but the individual-hook instructions below still invoke bare pre-commit. On a fresh setup that command is not on PATH; document the local executable (or provide an equivalent Make target).
make install

Four issues raised in review, all confirmed before changing anything:

Skip the mongodb-runner support probe when --local-atlas is set.
run-mongodb.sh passes --mongodb-runner unconditionally, so it arrives set
even for `make run-local-atlas`, and the probe now installs Node as a side
effect. The local-Atlas branch wins regardless, so the install was pure
waste. Verified by running the local-atlas path with a too-old node
shadowing PATH: before, it logged "No usable Node found, installing
Node..."; after, the probe never runs.

Check for npm alongside node when deciding whether Node is usable. Some
distributions package them separately, and a host with a new enough node
but no npm was reported usable, skipping the install that would have
provided both and then raising instead. That raise is now unreachable and
has been removed.

Install Node 22 unconditionally for the dev mongodb-runner. The previous
guard only checked whether the artifacts directory existed, so it could
reuse the Node 20 that the normal path now installs. install-node.sh
exits early only on an exact version match, so asking for 22 outright is
both safe and correct.

Point the individual-hook instructions in CONTRIBUTING.md at
.bin/pre-commit, since `make install` no longer puts it on PATH.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Makefile:25

  • On Cygwin, $(LOCAL_BIN) can be a /cygdrive/... path, which uv rejects for UV_TOOL_BIN_DIR; the existing platform handling in .evergreen/install-cli.sh:42-47 converts this value with cygpath for that reason. As written, the documented make install workflow can fail on Windows. Keep the Unix path for PATH, but pass a native Windows path to uv.
	export UV_TOOL_BIN_DIR="$(LOCAL_BIN)"; \

uv rejects /cygdrive/... paths for UV_TOOL_BIN_DIR, and under Cygwin make
CURDIR is exactly that, so the documented `make install` workflow could not
work on Windows. Convert the value with cygpath there, the way
install-cli.sh already does for the same variable, and keep the Unix form
for PATH.

Also install pre-commit with --force. Without it uv reports the tool as
already installed and skips linking the executable, so it never appears in
a new UV_TOOL_BIN_DIR -- which would have kept the fix above from taking
effect on a checkout that had already run `make install`. It also leaves
`make install` unable to restore its own shim if that is ever removed,
which makes `make lint` fail with a bare command-not-found.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

The gate compared only the major version, so Node 20.0-20.18, every 21.x,
and 22.0-22.11 counted as usable and skipped the lazy install even though
mongodb-runner cannot run on them: it depends on yargs@18, whose range is
^20.19.0 || ^22.12.0 || >=23. mongodb-runner declares no engines of its
own, so that constraint is a transitive one, and restating it here would
mean re-checking it against the dependency tree on every version bump.

Install with --engine-strict instead, which turns those declared ranges
into errors rather than npm's default warnings, and retry once after
installing our own Node if the first attempt is rejected. npm is then the
only thing that knows what Node is required, and the version comparison
goes away entirely.

Verified --engine-strict does not spuriously reject a supported host: a
full install of the pinned tree succeeds on Node 20.20.2 with npm 11.15.0,
which is what install-node.sh provides in CI, as well as on Node 25.

Hosts that cannot reach a supported Node still degrade the same way, but
now pay two failed installs before falling back rather than a single
version check.
--silent suppressed npm's error output, so a rejected host produced only
"returned non-zero exit status 1" -- no EBADENGINE, no offending package, no
required range. The rhel7 variant logged that same empty message five times
per task, which tells a reader nothing about why mongodb-runner was skipped,
and would be equally unhelpful for a genuine failure on a platform that is
supposed to work.

Use --loglevel=error instead. The output is captured either way, so a
successful install stays quiet, while a failure now carries npm's diagnosis:
the code, the package, the range it needs and the node/npm actually present.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

.evergreen/orchestration/mongodb_runner.py:159

  • The downloaded Node is added only to this Python process's PATH. After the runner is cached, a later direct drivers-orchestration run --mongodb-runner invocation skips this install/fallback block, so on a machine without system Node the cached runner fails at startup with /usr/bin/env: node: No such file or directory. Ensure Node is available/engine-compatible before returning a cached runner as well (for example, validate the cached install with npm and reuse the same Node fallback).
        # Try the Node already on PATH first. If npm rejects it -- or there is
        # no npm at all -- install our own Node and give it one more go.
        error = _npm_install(install_dir)
        if error is not None:
            LOGGER.info(f"Installing mongodb-runner failed, installing Node: {error}")
            if _install_node():
                error = _npm_install(install_dir)

The rhel7 log shows npm rejecting on @peculiar/x509 needing >=20.0.0,
not the yargs range the docstring cited. The same sentence already
argues that pinning a package and range here means re-verifying both on
every _MR_VERSION bump, so drop them.
Cut the restatement and the justifications that propped up other
justifications, and replace the "--" asides with plain connecting words.
The support-check docstring no longer names RHEL7, which contradicted its
own point about not naming platforms.
HOOK expands to nothing when unset, so `make lint` still runs everything. Taking a bare trailing goal instead would need a catch-all rule, which also swallows typos and shadows real target names.
@blink1073 blink1073 changed the title DRIVERS-3590 Improve dev workflow DRIVERS-3590 Improve local dev workflow Aug 21, 2026
@blink1073
blink1073 requested a balanced review from Copilot August 21, 2026 10:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (2)

.evergreen/orchestration/mongodb_runner.py:126

  • When USE_DEV_MONGODB_RUNNER is set, start_mongodb_runner() uses the compiled devtools-shared runner, but this probe now installs the pinned production package anyway. A registry/install failure therefore disables a valid dev runner and falls back to mongo-orchestration. Skip the production install for dev mode and only verify that Node is available.
    try:
        _install_mongodb_runner()

.evergreen/orchestration/mongodb_runner.py:147

  • The npm/Node compatibility check only runs when the runner executable is absent. If the temp cache contains a runner but node-artifacts was removed (as the Docker entrypoints explicitly do), _mongodb_runner_supported() returns true without installing Node, and the cached shim then fails at startup instead of falling back. Cached runners must also validate the current Node environment and trigger the install/retry path when needed.
        # Try the Node already on PATH first, then install our own and retry.
        error = _npm_install(install_dir)

The install is the support check, so short-circuiting on a cached shim skipped the check entirely and reported success with no node present. The docker entrypoints delete node-artifacts while the cache under TMPDIR survives, so treat a missing node as a cache miss and let the existing install-and-retry path handle it. Dev mode runs the compiled runner directly and never installs the pinned package, so it only checks that node is there.
@blink1073
blink1073 requested a review from NoahStapp August 21, 2026 11:13
@blink1073
blink1073 marked this pull request as ready for review August 21, 2026 11:13
@blink1073
blink1073 merged commit 135b3f3 into mongodb-labs:master Aug 21, 2026
55 checks passed
@blink1073
blink1073 deleted the add-make-install-lint branch August 21, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants