test: reject non-string version ranges in withVersions#9187
Conversation
A Node-version gate written as `withVersions('grpc', pkg, NODE_MAJOR >= 25 &&
'>=1.3.0', cb)` collapses to `false` on older Node. The old `!range` guard in
the version filter treated `false` (and every other nullish/empty value)
identically to "no range", so the intended restriction silently vanished and
the suite ran every installed version instead of the gated subset.
withVersions now throws a TypeError when a range argument is present but not a
non-empty string, so the misuse fails loudly at collection time. Callers that
relied on the silent pass-through are updated to pass a real range:
1. The grpc ESM integration spec used the `&&` form; switched to a ternary
yielding '*' on older Node, matching its sibling unit spec.
2. The aws-sdk version helpers forwarded an omitted range as `undefined`
straight into withVersions; they now forward '*'. `semver.satisfies(v, '*')`
selects the same set the `!range` short-circuit did, so the tested versions
are unchanged.
Overall package sizeSelf size: 6.45 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 2df6d45 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-07-02 12:22:15 Comparing candidate commit 2df6d45 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2254 metrics, 32 unstable metrics.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9187 +/- ##
=======================================
Coverage 93.77% 93.77%
=======================================
Files 895 895
Lines 51538 51538
Branches 12020 12020
=======================================
Hits 48329 48329
Misses 3209 3209 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| let variants | ||
|
|
||
| withVersions('grpc', '@grpc/grpc-js', NODE_MAJOR >= 25 && '>=1.3.0', version => { | ||
| withVersions('grpc', '@grpc/grpc-js', NODE_MAJOR >= 25 ? '>=1.3.0' : '*', version => { |
There was a problem hiding this comment.
Nit: For consistency with this change, we should apply the ternary form also here
There was a problem hiding this comment.
While I agree, I will keep it for less churn for now, since it does not change behavior.
A Node-version gate written as `withVersions('grpc', pkg, NODE_MAJOR >= 25 &&
'>=1.3.0', cb)` collapses to `false` on older Node. The old `!range` guard in
the version filter treated `false` (and every other nullish/empty value)
identically to "no range", so the intended restriction silently vanished and
the suite ran every installed version instead of the gated subset.
withVersions now throws a TypeError when a range argument is present but not a
non-empty string, so the misuse fails loudly at collection time. Callers that
relied on the silent pass-through are updated to pass a real range:
1. The grpc ESM integration spec used the `&&` form; switched to a ternary
yielding '*' on older Node, matching its sibling unit spec.
2. The aws-sdk version helpers forwarded an omitted range as `undefined`
straight into withVersions; they now forward '*'. `semver.satisfies(v, '*')`
selects the same set the `!range` short-circuit did, so the tested versions
are unchanged.
A Node-version gate written as `withVersions('grpc', pkg, NODE_MAJOR >= 25 &&
'>=1.3.0', cb)` collapses to `false` on older Node. The old `!range` guard in
the version filter treated `false` (and every other nullish/empty value)
identically to "no range", so the intended restriction silently vanished and
the suite ran every installed version instead of the gated subset.
withVersions now throws a TypeError when a range argument is present but not a
non-empty string, so the misuse fails loudly at collection time. Callers that
relied on the silent pass-through are updated to pass a real range:
1. The grpc ESM integration spec used the `&&` form; switched to a ternary
yielding '*' on older Node, matching its sibling unit spec.
2. The aws-sdk version helpers forwarded an omitted range as `undefined`
straight into withVersions; they now forward '*'. `semver.satisfies(v, '*')`
selects the same set the `!range` short-circuit did, so the tested versions
are unchanged.
A Node-version gate written as `withVersions('grpc', pkg, NODE_MAJOR >= 25 &&
'>=1.3.0', cb)` collapses to `false` on older Node. The old `!range` guard in
the version filter treated `false` (and every other nullish/empty value)
identically to "no range", so the intended restriction silently vanished and
the suite ran every installed version instead of the gated subset.
withVersions now throws a TypeError when a range argument is present but not a
non-empty string, so the misuse fails loudly at collection time. Callers that
relied on the silent pass-through are updated to pass a real range:
1. The grpc ESM integration spec used the `&&` form; switched to a ternary
yielding '*' on older Node, matching its sibling unit spec.
2. The aws-sdk version helpers forwarded an omitted range as `undefined`
straight into withVersions; they now forward '*'. `semver.satisfies(v, '*')`
selects the same set the `!range` short-circuit did, so the tested versions
are unchanged.
A Node-version gate written as `withVersions('grpc', pkg, NODE_MAJOR >= 25 &&
'>=1.3.0', cb)` collapses to `false` on older Node. The old `!range` guard in
the version filter treated `false` (and every other nullish/empty value)
identically to "no range", so the intended restriction silently vanished and
the suite ran every installed version instead of the gated subset.
withVersions now throws a TypeError when a range argument is present but not a
non-empty string, so the misuse fails loudly at collection time. Callers that
relied on the silent pass-through are updated to pass a real range:
1. The grpc ESM integration spec used the `&&` form; switched to a ternary
yielding '*' on older Node, matching its sibling unit spec.
2. The aws-sdk version helpers forwarded an omitted range as `undefined`
straight into withVersions; they now forward '*'. `semver.satisfies(v, '*')`
selects the same set the `!range` short-circuit did, so the tested versions
are unchanged.
Summary
A Node-version gate written as
withVersions('grpc', pkg, NODE_MAJOR >= 25 && '>=1.3.0', cb)collapses tofalseon older Node. The version filter's!rangeguard treatedfalse(and every other nullish/empty value) identically to "no range", so the intended restriction silently vanished and the suite ran every installed version instead of the gated subset.withVersionsnow throws aTypeErrorwhen a range argument is present but is not a non-empty string, so this class of misuse fails loudly at collection time instead of running the wrong set of versions. Theundefinedproduced by the internaltypeof range === 'function'reshuffle (the legitimate "no range" form) still passes through.Callers that relied on the silent pass-through are updated to pass a real range:
&&form; switched to a ternary yielding'*'on older Node, matching its sibling unit spec.undefinedstraight intowithVersions; they now forward'*'.semver.satisfies(v, '*')selects the same set the!rangeshort-circuit did, so the tested versions are unchanged.Test plan
packages/dd-trace/test/plugins/with-versions.spec.jspins both sides: the helper throws onfalse/''/null/undefinedexplicit ranges, and lets the function form and an explicit'*'through to module resolution.