Conversation
johnmtll
force-pushed
the
NODE-7666/environment-variables-in-the-handshake-metadata
branch
4 times, most recently
from
September 14, 2026 21:46
50be426 to
cb1f4c9
Compare
| }); | ||
| }); | ||
|
|
||
| // Ref: https://github.com/aclark4life/specifications/blob/feaec8d0ca332a80f457f75c6ef1600267e61d64/source/mongodb-handshake/tests/README.md#test-3-test-that-agent-metadata-is-properly-captured |
Contributor
There was a problem hiding this comment.
The new spec and unit tests need to clean up the env vars before starting, so the developer's local variables do not impact the tests.
| const agentEnv = getAgentEnv(); | ||
|
|
||
| const fullEnv = new Map<string, unknown>(); | ||
| if (containerMetadata.size > 0) fullEnv.set('container', containerMetadata); |
Contributor
There was a problem hiding this comment.
With this insertion order, container data is dropped before faas. Current (main) implementation tries to re-add container after faas gets booted, so this is a change in behavior.
| * Resolves `env.agent` from the environment, or an empty string when no agent variable is | ||
| * populated. Returns the value of the first populated variable in `AGENT_ENV_VARIABLES`. | ||
| */ | ||
| export function getAgentEnv(): string { |
Contributor
There was a problem hiding this comment.
This function should be added to test/mongodb_bundled.ts (alphabetically next to getFAASEnv) for the bundled tests to succeed.
johnmtll
added a commit
that referenced
this pull request
Sep 16, 2026
johnmtll
added a commit
that referenced
this pull request
Sep 16, 2026
johnmtll
added a commit
that referenced
this pull request
Sep 16, 2026
johnmtll
force-pushed
the
NODE-7666/environment-variables-in-the-handshake-metadata
branch
from
September 17, 2026 19:27
612b981 to
b9f4582
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary of Changes
env.agent, to the client metadata handshake.envsub-document is built and truncated.Notes for Reviewers
env.agentenv.agentis populated using first-match, order-bound logic over the agent-related environment variables defined in the spec. Depending on which variable matches, the value is either a generic marker (AI_AGENT) or the variable's literal value.Per the spec, "a variable is considered populated if it is present in the environment with a non-empty value." We treat any value that is empty after normalization/truncation as unpopulated and skip it.
envconstruction and truncationThe spec's truncation order is:
Previously,
envwas built by progressively appending members to the live metadata document, and the spec was partially-satisfied somewhat incidentally:env.namehappened to be the last FaaS member added, so it was deleted last — butenv.containeris appended after that, making it theoretically possible to end up with anenvcontaining onlycontainer.envis now constructed as a standalone document, truncated independently. This prepares us for a future spec alignment effort tracked in https://jira.mongodb.org/browse/NODE-7851.Truncation is a byte-op, not a character-op. This means that we can potentially slice multi-byte values during truncation. The remnants of a multi-byte slice are discarded. This allows us to also close out an outstanding bug (NODE-5150) via the use of a shared util (truncateStringBytes) where multi-byte partials remained when constructing appName.
Other info
Refer to: mongodb/specifications#1967 for the incoming changes.
Some tests which covered truncation logic (appName construction) have been moved to util tests when using a shared function. This is to keep the tests purely-scoped to the behaviour of the function being tested.
What is the motivation for this change?
For bug fixes
Current (incorrect) behavior:
Expected behavior:
How to reproduce:
Affected versions:
Release Highlight
Release notes highlight
Double check the following
npm run check:lint)type(NODE-xxxx)[!]: descriptionfeat(NODE-1234)!: rewriting everything in coffeescript