Skip to content

Commit ed88e6a

Browse files
committed
fixup!
1 parent 11ada78 commit ed88e6a

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@
528528
"name": "express",
529529
"versions": [">=4"]
530530
},
531+
{
532+
"name": "mysql2",
533+
"dep": true
534+
},
531535
{
532536
"name": "sqlite3",
533537
"versions": ["^5.0.8"]

scripts/flakiness.mjs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,34 @@ async function fetchJobsAttemptRest (params) {
7373
})
7474

7575
const headers = Object.fromEntries(res.headers.entries())
76-
const text = await res.text()
76+
let text = ''
77+
try {
78+
text = await res.text()
79+
} catch (err) {
80+
const summary = {
81+
status: res.status,
82+
headers: redactHeaders(headers),
83+
bodyUsed: res.bodyUsed,
84+
// Commonly useful when debugging truncated/gzipped payloads.
85+
contentEncoding: headers['content-encoding'],
86+
contentLength: headers['content-length'],
87+
githubRequestId: headers['x-github-request-id'],
88+
}
89+
throw new TypeError(
90+
`Failed to read jobs REST response body (${inspect(summary, { depth: 5 })}): ${inspect(err, { depth: 5 })}`
91+
)
92+
}
93+
94+
if (!res.ok) {
95+
const summary = {
96+
status: res.status,
97+
headers: redactHeaders(headers),
98+
bodyLength: text.length,
99+
bodyPrefix: text.slice(0, 200),
100+
}
101+
throw new TypeError(`GitHub REST request failed (${inspect(summary, { depth: 5 })})`)
102+
}
103+
77104
try {
78105
return JSON.parse(text)
79106
} catch (err) {
@@ -152,14 +179,19 @@ async function checkWorkflowJobs (id, attempt, page = 1) {
152179
let jobs = response?.data?.jobs
153180

154181
// If Octokit returns an invalid shape (including `data: ''`), fall back to a raw REST fetch.
182+
// `@octokit/request` may return `data: ""` if it fails to read/parse the response body.
155183
if (!Array.isArray(jobs)) {
184+
const headers = response?.headers || {}
156185
console.warn(
157186
`Octokit jobs response invalid; attempting REST fallback: ${inspect({
158187
id,
159188
attempt,
160189
page,
161190
status: response?.status,
162191
url: response?.url,
192+
githubRequestId: headers?.['x-github-request-id'],
193+
contentEncoding: headers?.['content-encoding'],
194+
contentLength: headers?.['content-length'],
163195
headers: redactHeaders(response?.headers),
164196
data: response?.data
165197
}, { depth: 5 })}`
@@ -169,7 +201,6 @@ async function checkWorkflowJobs (id, attempt, page = 1) {
169201
jobs = rest?.jobs
170202
}
171203

172-
// Octokit v5 format: response.data.jobs is an array.
173204
if (!Array.isArray(jobs)) {
174205
throw new TypeError(`Unexpected jobs response shape (${inspect(response, { depth: Infinity })})`)
175206
}

scripts/install_plugin_modules.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const excludeList = arch() === 'arm64' ? ['aerospike', 'couchbase', 'grpc', 'ora
2222
const workspaces = new Set()
2323
const externalDeps = new Map()
2424
const packagePromises = new Map()
25+
const externalSelfNames = new Set(Object.entries(externals)
26+
.filter(([key, entries]) => entries.some(entry => entry.name === key))
27+
.map(([key]) => key))
2528

2629
Object.keys(externals).forEach(external => externals[external].forEach(thing => {
2730
if (thing.dep) {
@@ -84,7 +87,11 @@ async function assertInstrumentation (instrumentation, external) {
8487
// Some tests depend on it, but creating it for every version key caused concurrent writes corrupting package.json.
8588
const unversionedVersion = versions.includes('*') ? '*' : versions.find(Boolean)
8689
if (unversionedVersion) {
87-
await assertPackageOnce(instrumentation.name, null, unversionedVersion, external)
90+
// If the package is also defined in externals.json as a "self entry" (name === key), prefer the external variant
91+
// for the unversioned install. This allows yarn to hoist it to `versions/node_modules`, making it available as a
92+
// peer/optional dependency to other generated packages (e.g. sequelize -> mysql2).
93+
const unversionedExternal = external || externalSelfNames.has(instrumentation.name)
94+
await assertPackageOnce(instrumentation.name, null, unversionedVersion, unversionedExternal)
8895
}
8996

9097
const versionKeys = new Set()

0 commit comments

Comments
 (0)