-
Notifications
You must be signed in to change notification settings - Fork 401
test: add shared plugin version resolver #9021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BridgeAR
merged 1 commit into
BridgeAR/2026-06-22-install-concurrency-helper
from
BridgeAR/2026-06-22-plugin-version-resolver
Jun 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| 'use strict' | ||
|
|
||
| const assert = require('node:assert/strict') | ||
|
|
||
| const { describe, it } = require('mocha') | ||
| const { coerce, major } = require('semver') | ||
|
|
||
| const { getVersionList, resolvePluginVersions } = require('./versions') | ||
|
|
||
| const latests = require('./versions/package.json').dependencies | ||
|
|
||
| const keys = (name, versions, nonConsecutive) => | ||
| getVersionList(name, versions, nonConsecutive).map(({ versionKey }) => versionKey) | ||
|
|
||
| const latestMajorKey = name => String(major(coerce(latests[name]))) | ||
|
|
||
| describe('getVersionList', () => { | ||
| it('collapses the wildcard to the latest major', () => { | ||
| assert.deepEqual(keys('mongodb', ['*']), [latestMajorKey('mongodb')]) | ||
| }) | ||
|
|
||
| it('collapses equivalent exact-version notations to a single key', () => { | ||
| assert.deepEqual(keys('mongodb', ['1.2.3', '=1.2.3', 'v1.2.3']), ['1.2.3']) | ||
| }) | ||
|
|
||
| it('pins the floor and the major for a single-major range', () => { | ||
| // `<3` caps the range to major 2, so only the pinned floor and the latest of major 2 are keys. | ||
| assert.deepEqual(keys('mongodb', ['>=2 <3']), ['2.0.0', '2']) | ||
| }) | ||
|
|
||
| it('covers the floor major and every major up to the range top', () => { | ||
| // `<5` caps the top at major 4; the floor (2.0.0) is pinned and majors 2-4 each resolve to their latest. | ||
| assert.deepEqual(keys('mongodb', ['>=2 <5']), ['2.0.0', '2', '3', '4']) | ||
| }) | ||
|
|
||
| it('covers every major from the floor to the capped top', () => { | ||
| // `<6` caps the top at major 5; the floor major's latest (1) is covered too, not only the newest of the range. | ||
| assert.deepEqual(keys('mongodb', ['>=1 <6']), ['1.0.0', '1', '2', '3', '4', '5']) | ||
| }) | ||
|
|
||
| it('de-duplicates a shared floor across multiple ranges', () => { | ||
| assert.deepEqual(keys('mongodb', ['>=2 <3', '^2.0.0']), ['2.0.0', '2']) | ||
| }) | ||
|
|
||
| it('consolidates the floor with the top major when the floor is the pinned latest', () => { | ||
| // `>=<pinned latest>` floors at the newest version, so the bare top-major key resolves to that same version and is | ||
| // dropped; the pinned package.json is what proves the two keys identical. | ||
| assert.deepEqual(keys('mongodb', [`>=${latests.mongodb}`]), [latests.mongodb]) | ||
| }) | ||
|
|
||
| it('adds the floor, the floor major and the top major for non-consecutive packages', () => { | ||
| // The middle majors may be unpublished, but the floor major (1) and the top major (5) both exist and are tested. | ||
| assert.deepEqual(keys('mongodb', ['>=1 <6'], new Set(['mongodb'])), ['1.0.0', '1', '5']) | ||
| }) | ||
|
|
||
| it('treats the built-in non-consecutive packages as floor + floor major + top major', () => { | ||
| // graphql jumps from 0.x to 14.x; 1.x–13.x are skipped, but the latest 0.x and the newest major are still tested. | ||
| assert.deepEqual(keys('graphql', ['>=0.10']), ['0.10.0', '0', latestMajorKey('graphql')]) | ||
| }) | ||
|
|
||
| it('throws on an unparseable range', () => { | ||
| assert.throws(() => getVersionList('mongodb', ['not-a-version']), /Invalid version range/) | ||
| }) | ||
|
|
||
| it('throws on an empty entry', () => { | ||
| assert.throws(() => getVersionList('mongodb', ['', '>=2 <3']), /Empty version entry/) | ||
| }) | ||
| }) | ||
|
|
||
| describe('resolvePluginVersions', () => { | ||
| const versionKeys = result => result.versionList.map(({ versionKey }) => versionKey) | ||
|
|
||
| it('expands the declared versions and points the unversioned folder at the newest in-scope key', () => { | ||
| const result = resolvePluginVersions({ name: 'mongodb', declaredVersions: ['>=2 <5'], env: {} }) | ||
|
|
||
| assert.deepEqual(versionKeys(result), ['2.0.0', '2', '3', '4']) | ||
| assert.equal(result.unversioned, '4') | ||
| }) | ||
|
|
||
| it('filters the installed keys by RANGE and follows the filtered tail', () => { | ||
| const result = resolvePluginVersions({ | ||
| name: 'mongodb', | ||
| declaredVersions: ['>=1 <6'], | ||
| env: { RANGE: '>=2.0.0 <4.0.0' }, | ||
| }) | ||
|
|
||
| assert.deepEqual(versionKeys(result), ['2', '3']) | ||
| assert.equal(result.unversioned, '3') | ||
| }) | ||
|
|
||
| it('replaces the declared versions with PACKAGE_VERSION_RANGE when the module is honoured', () => { | ||
| const result = resolvePluginVersions({ | ||
| name: 'mongodb', | ||
| declaredVersions: ['>=2 <5'], | ||
| env: { PACKAGE_VERSION_RANGE: '>=3 <4' }, | ||
| }) | ||
|
|
||
| assert.deepEqual(versionKeys(result), ['3.0.0', '3']) | ||
| assert.equal(result.unversioned, '>=3 <4') | ||
| }) | ||
|
|
||
| it('ignores PACKAGE_VERSION_RANGE for a sibling external that must not be sharded', () => { | ||
| const result = resolvePluginVersions({ | ||
| name: 'mongodb', | ||
| declaredVersions: ['>=2 <5'], | ||
| honourEnvRange: false, | ||
| env: { PACKAGE_VERSION_RANGE: '>=3 <4' }, | ||
| }) | ||
|
|
||
| assert.deepEqual(versionKeys(result), ['2.0.0', '2', '3', '4']) | ||
| assert.equal(result.unversioned, '4') | ||
| }) | ||
|
|
||
| it('keeps the unversioned folder on the raw shard while RANGE narrows the installed keys', () => { | ||
| const result = resolvePluginVersions({ | ||
| name: 'mongodb', | ||
| declaredVersions: ['>=1 <6'], | ||
| env: { PACKAGE_VERSION_RANGE: '>=2 <5', RANGE: '>=3.0.0 <4.0.0' }, | ||
| }) | ||
|
|
||
| assert.deepEqual(versionKeys(result), ['3']) | ||
| assert.equal(result.unversioned, '>=2 <5') | ||
| }) | ||
|
|
||
| it('reports nothing in scope when no version is declared', () => { | ||
| const result = resolvePluginVersions({ name: 'mongodb', declaredVersions: [], env: {} }) | ||
|
|
||
| assert.deepEqual(result.versionList, []) | ||
| assert.equal(result.unversioned, undefined) | ||
| }) | ||
|
|
||
| it('reports nothing in scope when RANGE excludes every declared key', () => { | ||
| const result = resolvePluginVersions({ | ||
| name: 'mongodb', | ||
| declaredVersions: ['>=2 <3'], | ||
| env: { RANGE: '>=9.0.0 <10.0.0' }, | ||
| }) | ||
|
|
||
| assert.deepEqual(result.versionList, []) | ||
| assert.equal(result.unversioned, undefined) | ||
| }) | ||
| }) |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For declared ranges whose upper bound falls inside a major, this loop still emits the bare major key for that top major. For example, the existing pino hook range
>=5 <6.8.0inpackages/datadog-instrumentations/src/pino.jswould producepino@6, which resolves to the latest 6.x and can be>=6.8.0, so the install/test set no longer covers the newest version below 6.8 and instead points at a version belonging to the next hook range. The same pattern exists for other sub-major ranges such as grpc and express, so the resolver needs to preserve a bounded range key (or otherwise cap the dependency) when the major is only partially included.Useful? React with 👍 / 👎.