Skip to content

Commit 9dfad14

Browse files
committed
test: drive install script and withVersions from the shared resolver
Both call sites now consume resolvePluginVersions, so the generated versions/ folders and the folders withVersions() iterates derive from one place and can no longer drift. The generator caps its mkdir/writeFile fan-out through the concurrency helper to avoid EMFILE. The resolver fills every in-between major on its own, so the lodash, ws, and mquery same-name externals that only re-stated their addHook ranges are dropped. Two peer-dependency anchors are added in their place: @apollo/server pins graphql so v5 does not resolve the 15.x that apollo-server v3 drags in, and knex installs the @vscode/sqlite3 fork its 1.x dialect requires.
1 parent 53bd8bc commit 9dfad14

4 files changed

Lines changed: 177 additions & 127 deletions

File tree

packages/dd-trace/test/plugins/externals.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@ module.exports = {
187187
name: 'express',
188188
versions: ['>=4', '>=4.0.0 <4.3.0', '>=4.0.0 <5.0.0', '>=4.3.0 <5.0.0'],
189189
},
190-
{
191-
name: 'mquery',
192-
versions: ['>=5.0.0'],
193-
},
194190
{
195191
name: 'mongodb',
196192
versions: ['5', '>=6'],
@@ -316,6 +312,15 @@ module.exports = {
316312
versions: ['^16.6.0'],
317313
},
318314
],
315+
'@apollo/server': [
316+
{
317+
// The shared apollo-server-* install also brings in graphql 15.x (for apollo-server v3), which yarn may
318+
// hoist over the ^16.11 that @apollo/server v5 needs. Without the pin, v5 resolves 15.x, whose TypeInfo
319+
// lacks the `.enter`/`.leave` methods the graphql instrumentation calls, so every traced operation throws.
320+
name: 'graphql',
321+
dep: true,
322+
},
323+
],
319324
grpc: [
320325
{
321326
name: '@grpc/proto-loader',
@@ -339,6 +344,14 @@ module.exports = {
339344
name: 'sqlite3',
340345
versions: ['^5.0.8'],
341346
},
347+
{
348+
// knex 1.x is the only major whose sqlite3 dialect requires the @vscode/sqlite3 fork instead of `sqlite3`
349+
// (reverted in 2.x). The instrumentation spec loads knex from `versions/knex@<ver>` and opens a sqlite3
350+
// client, so the fork must be installed there. Pin an exact prerelease build so prebuilt binaries exist for
351+
// the whole Node CI matrix.
352+
name: '@vscode/sqlite3',
353+
versions: ['5.1.12-vscode'],
354+
},
342355
{
343356
name: 'pg',
344357
versions: [
@@ -424,12 +437,6 @@ module.exports = {
424437
versions: ['>=3'],
425438
},
426439
],
427-
lodash: [
428-
{
429-
name: 'lodash',
430-
versions: ['>=4'],
431-
},
432-
],
433440
mariadb: [
434441
{
435442
name: 'mariadb',
@@ -653,10 +660,4 @@ module.exports = {
653660
versions: ['1.20.1'],
654661
},
655662
],
656-
ws: [
657-
{
658-
name: 'ws',
659-
versions: ['>=8.0.0'],
660-
},
661-
],
662663
}

packages/dd-trace/test/plugins/versions/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"@vitest/coverage-istanbul": "4.1.9",
9090
"@vitest/coverage-v8": "4.1.9",
9191
"@vitest/runner": "4.1.9",
92+
"@vscode/sqlite3": "5.1.12-vscode",
9293
"aerospike": "6.7.0",
9394
"ai": "6.0.204",
9495
"amqp10": "3.6.0",

packages/dd-trace/test/setup/mocha.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const sinon = require('sinon')
1414
require('./core')
1515

1616
const externals = require('../plugins/externals')
17+
const { resolvePluginVersions } = require('../plugins/versions')
1718
const runtimeMetrics = require('../../src/runtime_metrics')
1819
const Nomenclature = require('../../src/service-naming')
1920
const { SVC_SRC_KEY } = require('../../src/constants')
@@ -283,20 +284,17 @@ function withVersions (plugin, modules, range, cb) {
283284

284285
// Some entries coming from `externals.js` are dependency-only (e.g. `dep: true`) and don't have `versions`.
285286
// Treat those as "not a test target" instead of crashing.
286-
const versions = process.env.PACKAGE_VERSION_RANGE
287-
? [process.env.PACKAGE_VERSION_RANGE]
288-
: normalizeVersions(instrumentation.versions)
289-
290-
for (const version of versions) {
291-
if (process.env.RANGE && !semver.subset(version, process.env.RANGE)) continue
292-
if (version !== '*') {
293-
const min = semver.coerce(version)?.version
294-
if (!min) throw new Error(`Invalid version: ${version}`)
295-
testVersions.set(min, { versionRange: version, versionKey: min, resolvedVersion: min })
296-
}
297-
298-
const max = require(getModulePath(moduleName, version)).version()
299-
testVersions.set(max, { versionRange: version, versionKey: version, resolvedVersion: max })
287+
// Share the install script's resolution so the tested folders exactly match the installed ones (lowest supported
288+
// version, the latest of every major in between, and the newest supported version), de-duplicated by version.
289+
const { versionList } = resolvePluginVersions({
290+
name: moduleName,
291+
declaredVersions: normalizeVersions(instrumentation.versions),
292+
})
293+
294+
for (const { versionKey, range: declaredRange } of versionList) {
295+
// Exact keys resolve to themselves; range keys (`*`, `>=2`, `>=3.0.0 <4.0.0`) resolve to what was installed.
296+
const resolvedVersion = semver.valid(versionKey) ?? require(getModulePath(moduleName, versionKey)).version()
297+
testVersions.set(resolvedVersion, { versionRange: declaredRange, versionKey, resolvedVersion })
300298
}
301299
}
302300

0 commit comments

Comments
 (0)