Skip to content

Commit 5161f86

Browse files
committed
ci(lint): update validation code for unicorn v68
The validation code landed after the branch's previous base, so Unicorn 68's new checks only surfaced once the branch was rebased.
1 parent 0594002 commit 5161f86

7 files changed

Lines changed: 53 additions & 21 deletions

File tree

ci/test-optimization-validation/command-output-policy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function assertOutputParentsUnchanged (state) {
108108
}
109109
}
110110

111-
const lastExisting = state.parentIdentities[state.parentIdentities.length - 1].path
111+
const lastExisting = state.parentIdentities.at(-1).path
112112
const relative = path.relative(lastExisting, path.dirname(state.outputPath))
113113
let current = lastExisting
114114
for (const segment of relative ? relative.split(path.sep) : []) {

ci/test-optimization-validation/command-runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ function formatApprovalArgument (value) {
645645
const argument = String(value)
646646
if (/^[A-Za-z0-9_@%+=:,./\\-]+$/.test(argument)) return argument
647647
if (process.platform === 'win32') return JSON.stringify(argument)
648-
return `'${argument.replaceAll('\'', String.raw`'"'"'`)}'`
648+
return `'${argument.replaceAll('\'', '\'"\'"\'')}'`
649649
}
650650

651651
function serializeDisplayCommand (command) {

ci/test-optimization-validation/command-suitability.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ function isProducedBySetup (framework, localPath) {
101101
return false
102102
}
103103

104+
/**
105+
* @param {{ usesShell?: boolean, argv?: string[] }} command
106+
* @param {string} repositoryRoot
107+
*/
104108
function getRepositoryYarnError (command, repositoryRoot) {
105109
if (command.usesShell || path.basename(command.argv?.[0] || '') !== 'yarn') return
106110

@@ -112,7 +116,7 @@ function getRepositoryYarnError (command, repositoryRoot) {
112116
.sort()
113117
} catch {}
114118
if (releases?.length > 0) {
115-
const release = path.posix.join('.yarn', 'releases', releases[releases.length - 1])
119+
const release = path.posix.join('.yarn', 'releases', releases.at(-1))
116120
return `uses bare "yarn", but this repository pins ${release}. Use the structured command ` +
117121
`argv [process.execPath, "${release}", ...] so validation does not depend on an ambient Yarn shim.`
118122
}

ci/test-optimization-validation/plan-writer.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ function formatExecutionPlan ({
136136
'preloads are shown as package names; the validator resolves them from the installed `dd-trace` package.',
137137
''
138138
)
139-
for (const framework of manifest.frameworks.filter(entry => entry.status === 'runnable')) {
139+
for (const framework of manifest.frameworks) {
140+
if (framework.status !== 'runnable') continue
141+
140142
appendFrameworkExecutions(
141143
lines,
142144
framework,
@@ -273,7 +275,9 @@ function formatApprovalSummary ({
273275
}
274276

275277
lines.push('', '## Commands', '')
276-
for (const framework of manifest.frameworks.filter(entry => entry.status === 'runnable')) {
278+
for (const framework of manifest.frameworks) {
279+
if (framework.status !== 'runnable') continue
280+
277281
appendApprovalSummaryFramework(lines, framework, requestedScenario, repositoryRoot)
278282
}
279283

@@ -490,7 +494,9 @@ function getApprovalSummaryPath (out) {
490494
* @returns {void}
491495
*/
492496
function assertPlannedExecutablesAvailable (manifest, requestedScenario) {
493-
for (const framework of manifest.frameworks.filter(entry => entry.status === 'runnable')) {
497+
for (const framework of manifest.frameworks) {
498+
if (framework.status !== 'runnable') continue
499+
494500
const plannedCommands = getPlannedCommands(framework, requestedScenario)
495501
for (const plannedCommand of plannedCommands) {
496502
const executable = getUnavailableExecutable(plannedCommand.command)
@@ -1016,7 +1022,9 @@ function formatFrameworkLabel (framework, repositoryRoot) {
10161022
*/
10171023
function appendCommandIntegrity (lines, manifest, requestedScenario) {
10181024
const executables = new Map()
1019-
for (const framework of manifest.frameworks.filter(entry => entry.status === 'runnable')) {
1025+
for (const framework of manifest.frameworks) {
1026+
if (framework.status !== 'runnable') continue
1027+
10201028
for (const { command } of getPlannedCommands(framework, requestedScenario)) {
10211029
const executable = getApprovedExecutable(command)
10221030
if (executable) {

ci/test-optimization-validation/redaction.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ const EXACT_SECRET_ASSIGNMENT_NAME_SOURCE = [
2727
'JWT',
2828
'WEBHOOK(?:_URL)?',
2929
].join('|')
30-
const SECRET_NAME_CHARS = String.raw`[A-Za-z0-9_.-]`
30+
const SECRET_NAME_CHARS = '[A-Za-z0-9_.-]'
3131
const SECRET_ASSIGNMENT_NAME_SOURCE = [
32-
String.raw`(?:${EXACT_SECRET_ASSIGNMENT_NAME_SOURCE})`,
33-
String.raw`[A-Za-z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
34-
String.raw`[A-Za-z_]${SECRET_NAME_CHARS}*[-_]PASS`,
35-
String.raw`[A-Za-z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
36-
String.raw`[A-Za-z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
32+
`(?:${EXACT_SECRET_ASSIGNMENT_NAME_SOURCE})`,
33+
`[A-Za-z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
34+
`[A-Za-z_]${SECRET_NAME_CHARS}*[-_]PASS`,
35+
`[A-Za-z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
36+
`[A-Za-z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
3737
'PASS',
3838
'AUTH',
3939
'AUTHORIZATION',
@@ -68,7 +68,7 @@ const SECRET_FLAG_PATTERN = new RegExp(
6868
'gi'
6969
)
7070
const SECRET_FLAG_NAME_PATTERN = new RegExp(
71-
String.raw`^--(?:${SECRET_FLAG_SOURCE})(?:-[A-Za-z0-9]+)*$`,
71+
`^--(?:${SECRET_FLAG_SOURCE})(?:-[A-Za-z0-9]+)*$`,
7272
'i'
7373
)
7474
const AUTH_HEADER_PATTERN = /\b(Bearer)\s+([^\s'",}\]]+)/gi
@@ -92,10 +92,10 @@ const JWT_VALUE_PATTERN = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9
9292
const KNOWN_TOKEN_VALUE_PATTERN =
9393
/\b(?:gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{20,})\b/g
9494
const SECRET_HEADER_ENV_NAME_SOURCE = [
95-
String.raw`(?:${SECRET_NAME_SOURCE}|PAT|JWT|WEBHOOK(?:_URL)?)`,
96-
String.raw`[A-Za-z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
97-
String.raw`[A-Za-z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
98-
String.raw`[A-Za-z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
95+
`(?:${SECRET_NAME_SOURCE}|PAT|JWT|WEBHOOK(?:_URL)?)`,
96+
`[A-Za-z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
97+
`[A-Za-z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
98+
`[A-Za-z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
9999
].join('|')
100100
const SECRET_HEADER_NAME_SOURCE = [
101101
'dd-api-key',

ci/test-optimization-validation/scenarios/ci-wiring.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ function getMonorepoFindings ({ framework, command, probe }) {
694694
return findings
695695
}
696696

697+
/**
698+
* @param {object|undefined} probe
699+
* @param {string} name
700+
*/
697701
function hasProbeTool (probe, name) {
698702
const signals = [
699703
...(probe?.wrapperSignals || []),
@@ -703,6 +707,9 @@ function hasProbeTool (probe, name) {
703707
return signals.some(signal => signal.name === name)
704708
}
705709

710+
/**
711+
* @param {Array<{ name?: string }>} signals
712+
*/
706713
function formatToolNames (signals) {
707714
const names = []
708715
const seen = new Set()
@@ -715,9 +722,12 @@ function formatToolNames (signals) {
715722

716723
if (names.length === 0) return ''
717724
if (names.length === 1) return names[0]
718-
return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`
725+
return `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`
719726
}
720727

728+
/**
729+
* @param {string|undefined} frameworkName
730+
*/
721731
function getDisplayFrameworkName (frameworkName) {
722732
return {
723733
cucumber: 'Cucumber',

packages/dd-trace/test/ci-visibility/ci-wiring.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ describe('test optimization CI wiring validation', () => {
416416

417417
it('records when NODE_OPTIONS reaches a wrapper but not the test runner', async () => {
418418
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'dd-test-optimization-ci-wiring-'))
419+
const packageManagerScript = path.join(out, 'pnpm.cjs')
419420
const nxScript = path.join(out, 'nx.js')
420421
const jestScript = path.join(out, 'jest.js')
421422
fs.writeFileSync(jestScript, 'console.log("1 passing")\n')
@@ -429,6 +430,11 @@ describe('test optimization CI wiring validation', () => {
429430
})
430431
process.exit(child.status)
431432
`)
433+
fs.writeFileSync(packageManagerScript, `
434+
const { spawnSync } = require('node:child_process')
435+
const child = spawnSync(process.execPath, [${JSON.stringify(nxScript)}], { stdio: 'inherit' })
436+
process.exit(child.status)
437+
`)
432438

433439
try {
434440
const result = await runCiWiring({
@@ -445,7 +451,7 @@ describe('test optimization CI wiring validation', () => {
445451
},
446452
ciWiringCommand: {
447453
cwd: out,
448-
argv: [process.execPath, nxScript],
454+
argv: [process.execPath, packageManagerScript],
449455
},
450456
preflight: {
451457
ran: true,
@@ -465,7 +471,11 @@ describe('test optimization CI wiring validation', () => {
465471
assert.strictEqual(result.evidence.initializationProbe.reachedAnyNodeProcess, true)
466472
assert.strictEqual(result.evidence.initializationProbe.reachedTestRunnerProcess, false)
467473
assert.deepStrictEqual(result.evidence.initializationProbe.wrapperSignals.map(signal => signal.name), ['nx'])
468-
assert.match(result.diagnosis, /NODE_OPTIONS probe reached nx/)
474+
assert.deepStrictEqual(
475+
result.evidence.initializationProbe.packageManagerSignals.map(signal => signal.name),
476+
['pnpm']
477+
)
478+
assert.match(result.diagnosis, /NODE_OPTIONS probe reached nx and pnpm/)
469479
assert.match(result.diagnosis, /did not appear to reach a Jest process/)
470480
assert.strictEqual(result.evidence.monorepoFindings[0].id, 'nx-executor-env-forwarding')
471481
assert.strictEqual(result.evidence.monorepoFindings.at(-1).id, 'node-options-not-observed-in-test-runner')

0 commit comments

Comments
 (0)