Skip to content

Commit aed28b2

Browse files
authored
remove npm api calls (#6177)
* remove npm show call for llmobs tests * disable job that may require npm show to work * remove npm api call for upstream tests * remove github api call for upstream tests * add missing axios
1 parent 77b1e77 commit aed28b2

File tree

4 files changed

+21
-86
lines changed

4 files changed

+21
-86
lines changed

.github/workflows/project.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ jobs:
8989
- run: yarn type:test
9090
- run: yarn type:doc
9191

92-
verify-yaml:
93-
runs-on: ubuntu-latest
94-
steps:
95-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
96-
- uses: ./.github/actions/node/active-lts
97-
- uses: ./.github/actions/install
98-
- run: node scripts/verify-ci-config.js
92+
# TODO: Remove need for `npm show` before re-enabling to avoid rate limit errors.
93+
# verify-yaml:
94+
# runs-on: ubuntu-latest
95+
# steps:
96+
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
97+
# - uses: ./.github/actions/node/active-lts
98+
# - uses: ./.github/actions/install
99+
# - run: node scripts/verify-ci-config.js
99100

100101
yarn-dedupe:
101102
runs-on: ubuntu-latest

packages/dd-trace/test/llmobs/sdk/typescript/index.spec.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,14 @@ const testCases = [
6767
}
6868
]
6969

70-
// a bit of devex to show the version we're actually testing
71-
// so we don't need to know ahead of time
72-
function getLatestVersion (range) {
73-
const command = `npm show typescript@${range} version`
74-
const output = execSync(command, { encoding: 'utf-8' }).trim()
75-
const versions = output.split('\n').map(line => line.split(' ')[1].replace(/'/g, ''))
76-
return versions[versions.length - 1]
77-
}
78-
7970
describe('typescript', () => {
8071
let agent
8172
let proc
8273
let sandbox
8374

8475
for (const version of testVersions) {
85-
context(`with version ${getLatestVersion(version)}`, () => {
76+
// TODO: Figure out the real version without using `npm show` as it causes rate limit errors.
77+
context(`with version ${version}`, () => {
8678
before(async function () {
8779
this.timeout(20000)
8880
sandbox = await createSandbox(

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

Lines changed: 10 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,82 +7,16 @@ const fs = require('fs')
77
const util = require('util')
88
const os = require('os')
99
const path = require('path')
10-
const https = require('https')
11-
const url = require('url')
1210
const { once } = require('events')
1311
const { expect } = require('chai')
12+
const latests = require('../plugins/versions/package.json').dependencies
1413

1514
process.env.DD_INSTRUMENTATION_TELEMETRY_ENABLED = 'false'
1615

1716
const mkdtemp = util.promisify(fs.mkdtemp)
1817

1918
const ddTraceInit = path.resolve(__dirname, '../../../../init')
2019

21-
const latestCache = []
22-
async function getLatest (modName, repoUrl) {
23-
if (latestCache[modName]) {
24-
return latestCache[modName]
25-
}
26-
const { stdout } = await retry(() => exec(`npm view ${modName} dist-tags --json`), 1000)
27-
const { latest } = JSON.parse(stdout)
28-
const tags = await get(`https://api.github.com/repos/${repoUrl}/git/refs/tags`)
29-
for (const tag of tags) {
30-
if (tag.ref.includes(latest)) {
31-
return tag.ref.split('/').pop()
32-
}
33-
}
34-
}
35-
36-
function get (theUrl) {
37-
return new Promise((resolve, reject) => {
38-
// eslint-disable-next-line n/no-deprecated-api
39-
const options = url.parse(theUrl)
40-
options.headers = {
41-
'user-agent': 'dd-trace plugin test suites'
42-
}
43-
https.get(options, res => {
44-
if (res.statusCode === 403) {
45-
console.log('403')
46-
for (const header in res.headers) {
47-
if (header.startsWith('x-ratelimit')) {
48-
console.log(header, res.headers[header])
49-
}
50-
}
51-
const resetTime = Number(res.headers['x-ratelimit-reset']) * 1000
52-
const waitTime = 1000 + resetTime - Date.now()
53-
console.log('Waiting', waitTime / 1000, 'seconds for retry')
54-
setTimeout(() => {
55-
get(theUrl).then(resolve, reject)
56-
}, waitTime)
57-
return
58-
}
59-
if (res.statusCode >= 300) {
60-
res.pipe(process.stderr)
61-
reject(new Error(res.statusCode))
62-
return
63-
}
64-
const data = []
65-
res.on('data', d => data.push(d))
66-
res.on('end', () => {
67-
resolve(JSON.parse(Buffer.concat(data).toString('utf8')))
68-
})
69-
}).on('error', reject)
70-
})
71-
}
72-
73-
async function retry (fn, delay) {
74-
let result
75-
try {
76-
result = fn()
77-
} catch (e) {
78-
console.log(e)
79-
console.log('Retrying after', delay, 'ms')
80-
await new Promise(resolve => setTimeout(resolve, delay))
81-
result = retry(fn, delay)
82-
}
83-
return result
84-
}
85-
8620
function exec (cmd, opts = {}) {
8721
const date = new Date()
8822
const time = [
@@ -127,11 +61,18 @@ function getTmpDir () {
12761

12862
async function setup (modName, repoName, commitish) {
12963
if (commitish === 'latest') {
130-
commitish = await getLatest(modName, repoName)
64+
commitish = latests[modName]
13165
}
13266
const repoUrl = `https://github.com/${repoName}.git`
13367
const cwd = await getTmpDir()
134-
await execOrError(`git clone ${repoUrl} --branch ${commitish} --single-branch ${cwd}`)
68+
const clone = `git clone ${repoUrl} --single-branch ${cwd}`
69+
70+
try {
71+
await execOrError(`${clone} --branch ${commitish}`)
72+
} catch {
73+
// Exact version doesn't exist, try with a `v` prefix for example `v1.2.3`.
74+
await execOrError(`${clone} --branch v${commitish}`)
75+
}
13576

13677
try {
13778
await execOrError('npm install --legacy-peer-deps', { cwd })

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"apollo-server-core": "3.13.0",
3737
"avsc": "5.7.9",
3838
"aws-sdk": "2.1692.0",
39+
"axios": "1.11.0",
3940
"bluebird": "3.7.2",
4041
"body-parser": "2.2.0",
4142
"bunyan": "2.0.5",

0 commit comments

Comments
 (0)