dd-trace 6.8.0 → 6.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ci/diagnose.js +27 -25
- package/ci/init.js +6 -6
- package/ci/runbook.md +114 -20
- package/ci/test-optimization-validation/approval-artifacts.js +36 -3
- package/ci/test-optimization-validation/approval.js +78 -22
- package/ci/test-optimization-validation/blocker-category.js +24 -0
- package/ci/test-optimization-validation/ci-discovery.js +23 -17
- package/ci/test-optimization-validation/ci-package-scripts.js +34 -6
- package/ci/test-optimization-validation/ci-remediation.js +1 -1
- package/ci/test-optimization-validation/cli.js +280 -52
- package/ci/test-optimization-validation/command-blocker.js +159 -20
- package/ci/test-optimization-validation/command-output-policy.js +9 -3
- package/ci/test-optimization-validation/command-runner.js +9 -7
- package/ci/test-optimization-validation/environment.js +4 -2
- package/ci/test-optimization-validation/executable.js +15 -13
- package/ci/test-optimization-validation/execution-lock.js +70 -0
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +3 -0
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +657 -5
- package/ci/test-optimization-validation/framework-adapters/vitest.js +517 -0
- package/ci/test-optimization-validation/generated-files.js +38 -28
- package/ci/test-optimization-validation/generated-test-contract.js +8 -4
- package/ci/test-optimization-validation/generated-verifier.js +24 -17
- package/ci/test-optimization-validation/literal-glob.js +52 -0
- package/ci/test-optimization-validation/manifest-loader.js +3 -0
- package/ci/test-optimization-validation/manifest-scaffold.js +300 -50
- package/ci/test-optimization-validation/manifest-schema.js +80 -17
- package/ci/test-optimization-validation/offline-fixtures.js +13 -4
- package/ci/test-optimization-validation/package-check.js +94 -0
- package/ci/test-optimization-validation/plan-writer.js +183 -10
- package/ci/test-optimization-validation/preflight-runner.js +110 -31
- package/ci/test-optimization-validation/project-build-artifact.js +31 -0
- package/ci/test-optimization-validation/redaction.js +18 -27
- package/ci/test-optimization-validation/report-writer.js +182 -48
- package/ci/test-optimization-validation/result-semantics.js +20 -3
- package/ci/test-optimization-validation/runner-command.js +40 -20
- package/ci/test-optimization-validation/runner-contract.js +79 -43
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +59 -5
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +141 -35
- package/ci/test-optimization-validation/scenarios/helpers.js +30 -6
- package/ci/test-optimization-validation/static-diagnosis.js +10 -3
- package/ci/test-optimization-validation/test-output.js +2 -1
- package/ci/test-optimization-validation/validation-blocker.js +21 -0
- package/ci/vitest-no-worker-init-setup.mjs +30 -34
- package/index.d.ts +98 -1
- package/init.js +1 -17
- package/initialize.mjs +11 -0
- package/loader-hook.mjs +6 -4
- package/package.json +5 -3
- package/packages/datadog-core/src/utils/src/parse-tags.js +0 -1
- package/packages/datadog-esbuild/src/utils.js +16 -1
- package/packages/datadog-instrumentations/src/ai.js +61 -34
- package/packages/datadog-instrumentations/src/bluebird.js +6 -6
- package/packages/datadog-instrumentations/src/claude-agent-sdk.js +81 -5
- package/packages/datadog-instrumentations/src/cucumber.js +124 -47
- package/packages/datadog-instrumentations/src/dns.js +21 -2
- package/packages/datadog-instrumentations/src/electron.js +1 -0
- package/packages/datadog-instrumentations/src/fastify.js +3 -1
- package/packages/datadog-instrumentations/src/grpc/client.js +4 -2
- package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +3 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +33 -9
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +118 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +20 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +32 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +61 -0
- package/packages/datadog-instrumentations/src/helpers/router-helper.js +37 -6
- package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +1 -1
- package/packages/datadog-instrumentations/src/jest.js +979 -233
- package/packages/datadog-instrumentations/src/mocha/main.js +107 -9
- package/packages/datadog-instrumentations/src/mocha/utils.js +64 -42
- package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +25 -0
- package/packages/datadog-instrumentations/src/mocha/worker.js +12 -18
- package/packages/datadog-instrumentations/src/mysql.js +1 -1
- package/packages/datadog-instrumentations/src/next.js +155 -23
- package/packages/datadog-instrumentations/src/openai.js +14 -0
- package/packages/datadog-instrumentations/src/pg.js +180 -6
- package/packages/datadog-instrumentations/src/playwright.js +173 -79
- package/packages/datadog-instrumentations/src/promise-js.js +4 -4
- package/packages/datadog-instrumentations/src/promise.js +3 -3
- package/packages/datadog-instrumentations/src/router.js +195 -19
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +43 -10
- package/packages/datadog-instrumentations/src/vitest-main.js +360 -56
- package/packages/datadog-instrumentations/src/vitest-util.js +42 -7
- package/packages/datadog-instrumentations/src/vitest-worker.js +234 -17
- package/packages/datadog-instrumentations/src/webdriverio.js +194 -18
- package/packages/datadog-instrumentations/src/when.js +3 -3
- package/packages/datadog-instrumentations/src/ws.js +5 -1
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +59 -48
- package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -3
- package/packages/datadog-plugin-cucumber/src/index.js +5 -1
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -46
- package/packages/datadog-plugin-cypress/src/support.js +7 -4
- package/packages/datadog-plugin-electron/src/net.js +10 -4
- package/packages/datadog-plugin-http/src/client.js +1 -1
- package/packages/datadog-plugin-http2/src/client.js +1 -1
- package/packages/datadog-plugin-jest/src/index.js +1 -18
- package/packages/datadog-plugin-jest/src/util.js +2 -0
- package/packages/datadog-plugin-kafkajs/src/producer.js +2 -1
- package/packages/datadog-plugin-mocha/src/index.js +318 -1
- package/packages/datadog-plugin-next/src/index.js +57 -9
- package/packages/datadog-plugin-openai/src/tracing.js +4 -0
- package/packages/datadog-plugin-pg/src/index.js +65 -1
- package/packages/datadog-plugin-playwright/src/index.js +1 -1
- package/packages/datadog-plugin-vitest/src/index.js +95 -7
- package/packages/datadog-shimmer/src/shimmer.js +6 -2
- package/packages/dd-trace/src/aiguard/sdk.js +3 -0
- package/packages/dd-trace/src/appsec/{blocking.js → blocking/index.js} +26 -6
- package/packages/dd-trace/src/appsec/handlers/auth.js +62 -0
- package/packages/dd-trace/src/appsec/handlers/http-request.js +215 -0
- package/packages/dd-trace/src/appsec/handlers/http-response.js +78 -0
- package/packages/dd-trace/src/appsec/handlers/http-shared.js +24 -0
- package/packages/dd-trace/src/appsec/handlers/payments.js +104 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +1 -1
- package/packages/dd-trace/src/appsec/index.js +48 -476
- package/packages/dd-trace/src/appsec/sdk/track_event.js +9 -0
- package/packages/dd-trace/src/ci-visibility/coverage-report-discovery.js +46 -14
- package/packages/dd-trace/src/ci-visibility/efd-retry-policy.js +89 -0
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +27 -13
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +17 -0
- package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +21 -1
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +22 -7
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
- package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +21 -5
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +1 -1
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +5 -1
- package/packages/dd-trace/src/config/generated-config-types.d.ts +2 -0
- package/packages/dd-trace/src/config/helper.js +2 -0
- package/packages/dd-trace/src/config/index.js +16 -5
- package/packages/dd-trace/src/config/remote_config.js +1 -1
- package/packages/dd-trace/src/config/supported-configurations.json +8 -0
- package/packages/dd-trace/src/debugger/devtools_client/status.js +1 -1
- package/packages/dd-trace/src/encode/coverage-ci-visibility.js +0 -1
- package/packages/dd-trace/src/guardrails/apply-pm2-env.js +16 -0
- package/packages/dd-trace/src/guardrails/log.js +1 -10
- package/packages/dd-trace/src/llmobs/eval-metric.js +249 -0
- package/packages/dd-trace/src/llmobs/experiments/index.js +33 -25
- package/packages/dd-trace/src/llmobs/experiments/util.js +4 -2
- package/packages/dd-trace/src/llmobs/noop.js +2 -0
- package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/ai/util.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +5 -5
- package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +1 -1
- package/packages/dd-trace/src/llmobs/sdk.js +149 -68
- package/packages/dd-trace/src/llmobs/telemetry.js +18 -0
- package/packages/dd-trace/src/llmobs/writers/base.js +3 -0
- package/packages/dd-trace/src/llmobs/writers/util.js +2 -0
- package/packages/dd-trace/src/log/channels.js +1 -9
- package/packages/dd-trace/src/log/levels.js +12 -0
- package/packages/dd-trace/src/openfeature/writers/exposures.js +1 -1
- package/packages/dd-trace/src/openfeature/writers/util.js +1 -1
- package/packages/dd-trace/src/opentelemetry/logs/batch_log_processor.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/meter.js +8 -4
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +1 -1
- package/packages/dd-trace/src/opentelemetry/span.js +4 -0
- package/packages/dd-trace/src/plugins/ci_plugin.js +21 -5
- package/packages/dd-trace/src/plugins/index.js +1 -0
- package/packages/dd-trace/src/plugins/util/ci.js +6 -0
- package/packages/dd-trace/src/plugins/util/git.js +6 -4
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -2
- package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
- package/packages/dd-trace/src/plugins/util/stacktrace.js +3 -0
- package/packages/dd-trace/src/plugins/util/test.js +319 -75
- package/packages/dd-trace/src/plugins/util/url.js +1 -1
- package/packages/dd-trace/src/plugins/util/web.js +23 -1
- package/packages/dd-trace/src/profiler.js +1 -1
- package/packages/dd-trace/src/profiling/exporters/event_serializer.js +1 -1
- package/packages/dd-trace/src/profiling/profilers/events.js +2 -2
- package/packages/dd-trace/src/proxy.js +1 -0
- package/packages/dd-trace/src/ritm.js +5 -0
- package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +4 -2
- package/packages/dd-trace/src/sampling_rule.js +4 -2
- package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +1 -1
- package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +1 -1
- package/packages/dd-trace/src/telemetry/logs/index.js +3 -0
- package/packages/dd-trace/src/telemetry/telemetry.js +1 -1
- package/vendor/dist/pprof-format/index.js +1 -1
- package/version.js +10 -8
- /package/packages/dd-trace/src/appsec/{blocked_templates.js → blocking/templates.js} +0 -0
|
@@ -7,10 +7,10 @@ const { environmentNamesEqual, setEnvironmentValue } = require('./environment')
|
|
|
7
7
|
|
|
8
8
|
const RUNNER_OPTIONS = {
|
|
9
9
|
cucumber: {
|
|
10
|
-
flags: new Set(),
|
|
10
|
+
flags: new Set(['--backtrace', '--fail-fast', '--no-strict', '--strict']),
|
|
11
11
|
values: new Set([
|
|
12
12
|
'-p', '--config', '--import', '--language', '--loader', '--profile', '--require', '--require-module',
|
|
13
|
-
'--world-parameters',
|
|
13
|
+
'--parallel', '--world-parameters',
|
|
14
14
|
]),
|
|
15
15
|
},
|
|
16
16
|
cypress: {
|
|
@@ -18,7 +18,7 @@ const RUNNER_OPTIONS = {
|
|
|
18
18
|
values: new Set(['--browser', '--config-file']),
|
|
19
19
|
},
|
|
20
20
|
jest: {
|
|
21
|
-
flags: new Set(['--detectLeaks']),
|
|
21
|
+
flags: new Set(['--color', '--colors', '--detectLeaks']),
|
|
22
22
|
values: new Set(['-c', '--config', '--env', '--runner', '--testEnvironment']),
|
|
23
23
|
},
|
|
24
24
|
mocha: {
|
|
@@ -128,17 +128,6 @@ function getRunnerContract (framework, command, projectRoot, repositoryRoot, pla
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
const omittedOptions = getOmittedRunnerOptions(framework, invocation)
|
|
131
|
-
if (framework === 'cucumber') {
|
|
132
|
-
const language = getOptionValue(invocation, '--language')
|
|
133
|
-
if (language && language !== 'en') {
|
|
134
|
-
return {
|
|
135
|
-
environment: {},
|
|
136
|
-
error: `--language ${language} is not supported by the validator-generated English scenarios`,
|
|
137
|
-
inputFiles: [],
|
|
138
|
-
runnerArgs: [],
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
131
|
|
|
143
132
|
const environment = getRunnerEnvironment(invocation, platform)
|
|
144
133
|
const environmentError = getRunnerEnvironmentError(environment, platform)
|
|
@@ -167,6 +156,23 @@ function getRunnerContract (framework, command, projectRoot, repositoryRoot, pla
|
|
|
167
156
|
}
|
|
168
157
|
}
|
|
169
158
|
|
|
159
|
+
function getRunnerConfigurationContract (framework, runnerArgs, environment, projectRoot, repositoryRoot) {
|
|
160
|
+
const runnerArgsError = getRunnerArgsError(framework, runnerArgs)
|
|
161
|
+
if (runnerArgsError) {
|
|
162
|
+
return {
|
|
163
|
+
environment: {},
|
|
164
|
+
error: `runner arguments ${runnerArgsError}`,
|
|
165
|
+
inputFiles: [],
|
|
166
|
+
runnerArgs: [],
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const inputs = getRunnerInputs(runnerArgs, environment, projectRoot, repositoryRoot)
|
|
170
|
+
if (inputs.error) {
|
|
171
|
+
return { environment: {}, error: inputs.error, inputFiles: [], runnerArgs: [] }
|
|
172
|
+
}
|
|
173
|
+
return { environment, inputFiles: inputs.files, runnerArgs }
|
|
174
|
+
}
|
|
175
|
+
|
|
170
176
|
/**
|
|
171
177
|
* Rejects shell-expanded allowlisted environment assignments before command tokenization.
|
|
172
178
|
*
|
|
@@ -239,7 +245,7 @@ function getRunnerSearchRoots (framework, command, projectRoot, repositoryRoot)
|
|
|
239
245
|
*/
|
|
240
246
|
function addRunnerSearchRoot (roots, value, projectRoot, repositoryRoot, directory) {
|
|
241
247
|
if (typeof value !== 'string' || !value) return
|
|
242
|
-
const literal = value.split(/[*?{[]/, 1)[0].replace(/[\\/]+$/, '')
|
|
248
|
+
const literal = value.split(/[*?{[]/, 1)[0].replace(/(?<![\\/])[\\/]+$/, '')
|
|
243
249
|
if (!literal) return
|
|
244
250
|
const candidate = path.resolve(projectRoot, literal)
|
|
245
251
|
const searchRoot = directory || !path.extname(candidate) ? candidate : path.dirname(candidate)
|
|
@@ -305,17 +311,24 @@ function getUnknownRunnerOption (framework, invocation) {
|
|
|
305
311
|
|
|
306
312
|
function getOmittedRunnerOptions (framework, invocation) {
|
|
307
313
|
const omitted = OMITTED_RUNNER_OPTIONS[framework] || new Set()
|
|
314
|
+
const ignored = IGNORED_RUNNER_OPTIONS[framework] || { flags: new Set(), values: new Set() }
|
|
308
315
|
return [...new Set(invocation.tokens
|
|
309
316
|
.slice(invocation.runnerIndex + 1)
|
|
310
|
-
.filter(token =>
|
|
317
|
+
.filter(token => {
|
|
318
|
+
if (!token.startsWith('-')) return false
|
|
319
|
+
const option = token.split('=', 1)[0]
|
|
320
|
+
return omitted.has(option) || ignored.flags.has(option) || ignored.values.has(option)
|
|
321
|
+
})
|
|
322
|
+
.map(token => token.split('=', 1)[0]))]
|
|
311
323
|
}
|
|
312
324
|
|
|
313
|
-
function
|
|
314
|
-
const
|
|
315
|
-
for (let index = 0; index <
|
|
316
|
-
if (
|
|
317
|
-
|
|
325
|
+
function getArgumentOptionValues (args, expected) {
|
|
326
|
+
const values = []
|
|
327
|
+
for (let index = 0; index < args.length; index++) {
|
|
328
|
+
if (args[index].split('=', 1)[0] !== expected) continue
|
|
329
|
+
values.push(args[index].includes('=') ? args[index].slice(args[index].indexOf('=') + 1) : args[index + 1])
|
|
318
330
|
}
|
|
331
|
+
return values
|
|
319
332
|
}
|
|
320
333
|
|
|
321
334
|
/**
|
|
@@ -361,7 +374,8 @@ function getRunnerArgsError (framework, args) {
|
|
|
361
374
|
}
|
|
362
375
|
const option = token.split('=', 1)[0]
|
|
363
376
|
if (options.flags.has(option)) {
|
|
364
|
-
if (token !== option &&
|
|
377
|
+
if (token !== option &&
|
|
378
|
+
!/^--(?:color|colors|detectLeaks)=(?:true|false)$/.test(token)) {
|
|
365
379
|
return `contain an invalid value for ${option}`
|
|
366
380
|
}
|
|
367
381
|
continue
|
|
@@ -376,6 +390,13 @@ function getRunnerArgsError (framework, args) {
|
|
|
376
390
|
return `contain a missing or unsafe value for ${option}`
|
|
377
391
|
}
|
|
378
392
|
}
|
|
393
|
+
|
|
394
|
+
if (framework === 'cucumber') {
|
|
395
|
+
const language = getArgumentOptionValues(args, '--language').find(value => value !== 'en')
|
|
396
|
+
if (language) {
|
|
397
|
+
return `--language ${language} is not supported by the validator-generated English scenarios`
|
|
398
|
+
}
|
|
399
|
+
}
|
|
379
400
|
}
|
|
380
401
|
|
|
381
402
|
/**
|
|
@@ -411,10 +432,12 @@ function getRunnerInputError (args, environment, projectRoot, repositoryRoot, co
|
|
|
411
432
|
if (inputs.error) return inputs.error
|
|
412
433
|
|
|
413
434
|
const approved = new Set()
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
435
|
+
if (configFiles) {
|
|
436
|
+
for (const filename of configFiles) {
|
|
437
|
+
try {
|
|
438
|
+
approved.add(fs.realpathSync(filename))
|
|
439
|
+
} catch {}
|
|
440
|
+
}
|
|
418
441
|
}
|
|
419
442
|
const unbound = inputs.files.find(filename => !approved.has(filename))
|
|
420
443
|
if (unbound) return `references an input that is not approval-bound: ${unbound}`
|
|
@@ -439,26 +462,34 @@ function getFrameworkInvocation (command, framework) {
|
|
|
439
462
|
})
|
|
440
463
|
if (runnerIndex === -1) return
|
|
441
464
|
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
for (const token of prefix) {
|
|
452
|
-
if (RUNNER_LAUNCHERS.has(path.basename(token).toLowerCase())) continue
|
|
465
|
+
const prefixError = getRunnerPrefixError(tokens.slice(0, runnerIndex))
|
|
466
|
+
if (prefixError) return { error: prefixError, runnerIndex, tokens }
|
|
467
|
+
return { runnerIndex, tokens }
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function getRunnerPrefixError (prefix) {
|
|
471
|
+
let coverageLauncher = false
|
|
472
|
+
for (let index = 0; index < prefix.length; index++) {
|
|
473
|
+
const token = prefix[index]
|
|
453
474
|
if (/^[A-Za-z_][A-Za-z0-9_]*=[^;&|`]*$/.test(token)) continue
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
475
|
+
|
|
476
|
+
const basename = path.basename(token).toLowerCase()
|
|
477
|
+
if (RUNNER_LAUNCHERS.has(basename)) {
|
|
478
|
+
coverageLauncher = basename === 'c8' || basename === 'nyc'
|
|
479
|
+
continue
|
|
459
480
|
}
|
|
481
|
+
if (coverageLauncher && /^(?:-r|--reporter)=\S+$/.test(token)) continue
|
|
482
|
+
if (coverageLauncher && /^(?:-r|--reporter)$/.test(token) &&
|
|
483
|
+
prefix[index + 1] && !prefix[index + 1].startsWith('-')) {
|
|
484
|
+
index++
|
|
485
|
+
continue
|
|
486
|
+
}
|
|
487
|
+
if (!prefix.some(candidate => RUNNER_LAUNCHERS.has(path.basename(candidate).toLowerCase()))) {
|
|
488
|
+
return `runner launch wrapper ${path.basename(token)} is not allowlisted`
|
|
489
|
+
}
|
|
490
|
+
return 'runner launch wrapper contains options or positional arguments whose semantics the validator does not ' +
|
|
491
|
+
'preserve'
|
|
460
492
|
}
|
|
461
|
-
return { runnerIndex, tokens }
|
|
462
493
|
}
|
|
463
494
|
|
|
464
495
|
/**
|
|
@@ -612,6 +643,10 @@ function resolveInputFile (input, projectRoot) {
|
|
|
612
643
|
if (!input.module || path.isAbsolute(input.value) || input.value.startsWith('.')) {
|
|
613
644
|
return path.resolve(projectRoot, input.value)
|
|
614
645
|
}
|
|
646
|
+
const projectRelative = path.resolve(projectRoot, input.value)
|
|
647
|
+
try {
|
|
648
|
+
return require.resolve(projectRelative)
|
|
649
|
+
} catch {}
|
|
615
650
|
try {
|
|
616
651
|
return require.resolve(input.value, { paths: [projectRoot] })
|
|
617
652
|
} catch {}
|
|
@@ -657,6 +692,7 @@ function isPathInside (root, filename) {
|
|
|
657
692
|
module.exports = {
|
|
658
693
|
getProjectNodeRunner,
|
|
659
694
|
getRunnerArgsError,
|
|
695
|
+
getRunnerConfigurationContract,
|
|
660
696
|
getRunnerContract,
|
|
661
697
|
getRunnerEnvironmentError,
|
|
662
698
|
getRunnerInputError,
|
|
@@ -111,7 +111,7 @@ async function runBasicReporting ({ framework, out, options }) {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
if (!run.offline.initialized || !evidence.settingsLoadedFromCache) {
|
|
114
|
-
return
|
|
114
|
+
return failBasicWithDebugRerun({
|
|
115
115
|
command,
|
|
116
116
|
diagnosis: run.offline.initialized
|
|
117
117
|
? 'The clean test passed, but Test Optimization did not load the validator-owned offline settings.'
|
|
@@ -131,7 +131,7 @@ async function runBasicReporting ({ framework, out, options }) {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
if (run.result.exitCode !== 0) {
|
|
134
|
-
evidence.commandFailure = classifyFailure(framework, run.result)
|
|
134
|
+
evidence.commandFailure = classifyFailure(framework, run.result, run.events)
|
|
135
135
|
const confirmation = await runCleanConfirmation({ command, framework, options, out })
|
|
136
136
|
evidence.cleanConfirmation = confirmation.evidence
|
|
137
137
|
if (!confirmation.evidence.matchesPreflight) {
|
|
@@ -144,7 +144,7 @@ async function runBasicReporting ({ framework, out, options }) {
|
|
|
144
144
|
confirmation.artifacts
|
|
145
145
|
)
|
|
146
146
|
}
|
|
147
|
-
const result = await
|
|
147
|
+
const result = await failBasicWithDebugRerun({
|
|
148
148
|
command,
|
|
149
149
|
diagnosis: complete
|
|
150
150
|
? `The test passed twice without Datadog but exited ${run.result.exitCode} when initialized, after ` +
|
|
@@ -169,7 +169,7 @@ async function runBasicReporting ({ framework, out, options }) {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
const missing = getMissingLevels(evidence)
|
|
172
|
-
return
|
|
172
|
+
return failBasicWithDebugRerun({
|
|
173
173
|
command,
|
|
174
174
|
diagnosis: 'The direct test passed cleanly and while initialized, but no complete Test Optimization event ' +
|
|
175
175
|
`hierarchy was captured. Missing levels: ${missing.join(', ')}. This is a possible dd-trace adapter bug.`,
|
|
@@ -194,6 +194,50 @@ async function runBasicReporting ({ framework, out, options }) {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
async function failBasicWithDebugRerun (input) {
|
|
198
|
+
const result = await failWithDebugRerun(input)
|
|
199
|
+
const debug = result.evidence?.debugRerun
|
|
200
|
+
if (!isSuccessfulDebugRerun(debug, result.evidence?.selector)) return result
|
|
201
|
+
|
|
202
|
+
const initialDiagnosis = result.diagnosis
|
|
203
|
+
delete result.evidence.possibleLibraryBug
|
|
204
|
+
result.status = 'error'
|
|
205
|
+
result.diagnosis = 'The first initialized run failed, but the unchanged DD_TRACE_DEBUG=1 rerun exited cleanly ' +
|
|
206
|
+
'and emitted the complete event hierarchy. Basic Reporting is intermittent, so no library-bug conclusion ' +
|
|
207
|
+
'was reached.'
|
|
208
|
+
result.evidence.initialInstrumentedDiagnosis = initialDiagnosis
|
|
209
|
+
result.evidence.intermittentInstrumentedResult = true
|
|
210
|
+
result.evidence.recommendation = 'Repeat the approved initialized command without changing its test selection. ' +
|
|
211
|
+
'If the failure recurs, send both initialized runs and the clean confirmations to engineering.'
|
|
212
|
+
result.evidence.validationIncomplete = true
|
|
213
|
+
return result
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function isSuccessfulDebugRerun (debug, selector) {
|
|
217
|
+
return isDebugSelectorVerified(debug, selector) &&
|
|
218
|
+
debug?.ran === true &&
|
|
219
|
+
debug.commandExitCode === 0 &&
|
|
220
|
+
debug.commandTimedOut === false &&
|
|
221
|
+
debug.offlineExporterInitialized === true &&
|
|
222
|
+
debug.settingsLoadedFromCache === true &&
|
|
223
|
+
debug.testSessionEvents > 0 &&
|
|
224
|
+
debug.testModuleEvents > 0 &&
|
|
225
|
+
debug.testSuiteEvents > 0 &&
|
|
226
|
+
debug.testEvents > 0
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// A wrapper rerun is comparable only when events identify the approved representative and no other file.
|
|
230
|
+
function isDebugSelectorVerified (debug, selector) {
|
|
231
|
+
if (selector?.verified !== true) return false
|
|
232
|
+
if (selector.mode === 'bounded_direct_runner') return true
|
|
233
|
+
if (selector.mode !== 'instrumented_event_identity' ||
|
|
234
|
+
typeof selector.expectedTestFile !== 'string' ||
|
|
235
|
+
debug?.testEventsWithoutSourceFile !== 0 ||
|
|
236
|
+
debug?.testSourceFileCount !== 1 ||
|
|
237
|
+
debug?.testSourceFiles?.length !== 1) return false
|
|
238
|
+
return sourceFilesMatch(debug.testSourceFiles[0], selector.expectedTestFile)
|
|
239
|
+
}
|
|
240
|
+
|
|
197
241
|
/**
|
|
198
242
|
* Repeats the direct clean command after an initialized-only failure.
|
|
199
243
|
*
|
|
@@ -234,10 +278,17 @@ async function runCleanConfirmation ({ command, framework, options, out }) {
|
|
|
234
278
|
*/
|
|
235
279
|
function summarizePreflight (preflight = {}) {
|
|
236
280
|
return {
|
|
281
|
+
attempts: (preflight.attempts || []).map(attempt => ({
|
|
282
|
+
exitCode: attempt.exitCode,
|
|
283
|
+
observedTestCount: attempt.observedTestCount,
|
|
284
|
+
testFile: attempt.testFile,
|
|
285
|
+
timedOut: attempt.timedOut === true,
|
|
286
|
+
})),
|
|
237
287
|
durationMs: preflight.durationMs,
|
|
238
288
|
exitCode: preflight.exitCode,
|
|
239
289
|
observedTestCount: preflight.observedTestCount,
|
|
240
290
|
ran: preflight.ran === true,
|
|
291
|
+
selectedTestFile: preflight.selectedTestFile,
|
|
241
292
|
selectorVerification: preflight.selectorVerification,
|
|
242
293
|
timedOut: preflight.timedOut === true,
|
|
243
294
|
}
|
|
@@ -312,12 +363,15 @@ function normalizeSourceFile (filename) {
|
|
|
312
363
|
*
|
|
313
364
|
* @param {object} framework framework entry
|
|
314
365
|
* @param {object} result command result
|
|
366
|
+
* @param {object[]} [events] normalized captured events
|
|
315
367
|
* @returns {object|undefined} blocker
|
|
316
368
|
*/
|
|
317
|
-
function classifyFailure (framework, result) {
|
|
369
|
+
function classifyFailure (framework, result, events = []) {
|
|
318
370
|
return getCommandBlocker(result, {
|
|
319
371
|
browserRequired: framework.browserRequired,
|
|
320
372
|
framework: framework.framework,
|
|
373
|
+
packageJson: framework.project?.packageJson,
|
|
374
|
+
testsRan: eventsOfType(events, 'test').length > 0,
|
|
321
375
|
})
|
|
322
376
|
}
|
|
323
377
|
|
|
@@ -29,9 +29,10 @@ const RUNNER_PATTERNS = {
|
|
|
29
29
|
* @param {object} input audit inputs
|
|
30
30
|
* @param {object} input.manifest validation manifest
|
|
31
31
|
* @param {object} input.framework framework entry
|
|
32
|
+
* @param {Map<string, Buffer|undefined>} [input.projectFileSources] approval-bound project sources
|
|
32
33
|
* @returns {object} CI audit result
|
|
33
34
|
*/
|
|
34
|
-
function runCiWiring ({ manifest, framework }) {
|
|
35
|
+
function runCiWiring ({ manifest, framework, projectFileSources }) {
|
|
35
36
|
const contradiction = getFrameworkCiDiscoveryContradiction(framework, manifest)
|
|
36
37
|
if (contradiction) {
|
|
37
38
|
return getIncomplete(framework, contradiction.reason, {
|
|
@@ -47,6 +48,32 @@ function runCiWiring ({ manifest, framework }) {
|
|
|
47
48
|
domain: 'ci_configuration',
|
|
48
49
|
evidenceStrength: 'unknown',
|
|
49
50
|
}
|
|
51
|
+
if (hasNoSupportedCiConfiguration(manifest, ci)) {
|
|
52
|
+
return getIncomplete(
|
|
53
|
+
framework,
|
|
54
|
+
'No supported CI configuration file was found by bounded repository discovery. The CI audit is incomplete; ' +
|
|
55
|
+
'this does not prove that the repository has no external CI configuration.',
|
|
56
|
+
{
|
|
57
|
+
...evidence,
|
|
58
|
+
reasonCode: 'no-supported-ci-configuration',
|
|
59
|
+
recommendation: 'Identify the CI system and one repository-controlled test job. If CI is configured outside ' +
|
|
60
|
+
'this repository, review that configuration separately.',
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
if (hasUnavailableRemoteCiCommand(ci)) {
|
|
65
|
+
return getIncomplete(
|
|
66
|
+
framework,
|
|
67
|
+
'The selected CI path delegates test execution to a remote action or reusable workflow whose command is not ' +
|
|
68
|
+
'available in this repository. The CI audit is incomplete.',
|
|
69
|
+
{
|
|
70
|
+
...evidence,
|
|
71
|
+
reasonCode: 'remote-ci-command-unavailable',
|
|
72
|
+
recommendation: 'Review the referenced action or reusable workflow at its pinned revision. Keep the result ' +
|
|
73
|
+
'incomplete when its final test command and effective environment cannot be bound statically.',
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
50
77
|
const missing = getMissingReviewFields(ci)
|
|
51
78
|
if (missing.length > 0) {
|
|
52
79
|
return getIncomplete(
|
|
@@ -63,7 +90,7 @@ function runCiWiring ({ manifest, framework }) {
|
|
|
63
90
|
)
|
|
64
91
|
}
|
|
65
92
|
|
|
66
|
-
const source =
|
|
93
|
+
const source = readProjectSource(ci.configFile, projectFileSources)
|
|
67
94
|
if (!source) {
|
|
68
95
|
return getIncomplete(framework, 'The recorded CI configuration file is unavailable or too large to verify.', {
|
|
69
96
|
...evidence,
|
|
@@ -87,7 +114,7 @@ function runCiWiring ({ manifest, framework }) {
|
|
|
87
114
|
}
|
|
88
115
|
|
|
89
116
|
const command = ci.command.trim()
|
|
90
|
-
const resolution = getRunnerResolution(command, framework, ci)
|
|
117
|
+
const resolution = getRunnerResolution(command, framework, ci, projectFileSources)
|
|
91
118
|
const normalizedSource = jobSource.replaceAll('\\', '/')
|
|
92
119
|
const hasInitialization = /dd-trace\/ci\/init(?:\.js)?\b/.test(normalizedSource)
|
|
93
120
|
const matrixRelevant = matrixAffectsCiFacts(jobSource, command)
|
|
@@ -138,12 +165,16 @@ function runCiWiring ({ manifest, framework }) {
|
|
|
138
165
|
if (initialization.status === 'missing' &&
|
|
139
166
|
resolution.status === 'confirmed' &&
|
|
140
167
|
unresolved.relevant.length === 0) {
|
|
168
|
+
const transportMissing = ciFacts.transport.status === 'missing'
|
|
141
169
|
return getFailure(
|
|
142
170
|
framework,
|
|
143
171
|
'The checksum-bound CI job reaches the selected test framework through a bounded static command path, but ' +
|
|
144
|
-
|
|
172
|
+
`does not configure the dd-trace/ci/init preload${
|
|
173
|
+
transportMissing ? ' and declares no visible Datadog Agent or agentless reporting transport' : ''
|
|
174
|
+
}. Test Optimization is not configured in that job.`,
|
|
145
175
|
{
|
|
146
176
|
...evidence,
|
|
177
|
+
ciConfigurationStatus: 'not_configured',
|
|
147
178
|
ciRemediation: remediation,
|
|
148
179
|
conclusion: 'confirmed_misconfigured',
|
|
149
180
|
evidenceStrength: 'confirmed_static',
|
|
@@ -153,17 +184,25 @@ function runCiWiring ({ manifest, framework }) {
|
|
|
153
184
|
}
|
|
154
185
|
|
|
155
186
|
if (resolution.status !== 'confirmed') {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
187
|
+
const visibleFacts = []
|
|
188
|
+
if (initialization.status === 'missing') {
|
|
189
|
+
visibleFacts.push('The selected job has no visible dd-trace/ci/init preload.')
|
|
190
|
+
}
|
|
191
|
+
if (ciFacts.transport.status === 'missing') {
|
|
192
|
+
visibleFacts.push('The recorded review found no visible Datadog Agent or agentless reporting transport.')
|
|
193
|
+
}
|
|
194
|
+
const recommendation = /working directory/i.test(resolution.reason)
|
|
195
|
+
? 'Keep the CI job\'s actual working directory. Resolve the repository-root wrapper to the selected test ' +
|
|
196
|
+
'runner statically; do not substitute the framework package directory merely to make the audit conclusive.'
|
|
197
|
+
: 'Resolve the remaining wrapper or dynamic command statically, or confirm the effective NODE_OPTIONS value ' +
|
|
198
|
+
'in the final test process with DD_TRACE_DEBUG=1.'
|
|
159
199
|
return getIncomplete(
|
|
160
200
|
framework,
|
|
161
|
-
|
|
162
|
-
`${framework.framework} runner: ${resolution.reason}
|
|
201
|
+
'The CI audit remains incomplete because the selected command could not be resolved to the ' +
|
|
202
|
+
`${framework.framework} runner: ${resolution.reason}. ${visibleFacts.join(' ')}`.trim(),
|
|
163
203
|
{
|
|
164
204
|
...evidence,
|
|
165
|
-
recommendation
|
|
166
|
-
'NODE_OPTIONS value in the final test process with DD_TRACE_DEBUG=1.',
|
|
205
|
+
recommendation,
|
|
167
206
|
}
|
|
168
207
|
)
|
|
169
208
|
}
|
|
@@ -244,9 +283,10 @@ function getEffectiveNodeOptionsOverride (commandPath = []) {
|
|
|
244
283
|
* @param {string} command selected CI command
|
|
245
284
|
* @param {object} framework framework manifest entry
|
|
246
285
|
* @param {object} ci selected CI evidence
|
|
286
|
+
* @param {Map<string, Buffer|undefined>} [projectFileSources] approval-bound project sources
|
|
247
287
|
* @returns {object} static runner resolution
|
|
248
288
|
*/
|
|
249
|
-
function getRunnerResolution (command, framework, ci) {
|
|
289
|
+
function getRunnerResolution (command, framework, ci, projectFileSources) {
|
|
250
290
|
if (getDirectRunner(command, framework.framework)) {
|
|
251
291
|
return {
|
|
252
292
|
commandPath: [command],
|
|
@@ -266,7 +306,7 @@ function getRunnerResolution (command, framework, ci) {
|
|
|
266
306
|
status: 'unresolved',
|
|
267
307
|
}
|
|
268
308
|
}
|
|
269
|
-
const scripts = readProjectScripts(framework.project.packageJson)
|
|
309
|
+
const scripts = readProjectScripts(framework.project.packageJson, projectFileSources)
|
|
270
310
|
if (!scripts) {
|
|
271
311
|
return {
|
|
272
312
|
reason: 'the approval-bound project package.json is unavailable or invalid',
|
|
@@ -283,10 +323,10 @@ function getRunnerResolution (command, framework, ci) {
|
|
|
283
323
|
status: 'unresolved',
|
|
284
324
|
}
|
|
285
325
|
}
|
|
286
|
-
const
|
|
326
|
+
const candidates = expansion.terminals.filter(terminal => {
|
|
287
327
|
return getDirectRunner(terminal.command, framework.framework)
|
|
288
328
|
})
|
|
289
|
-
if (
|
|
329
|
+
if (candidates.length === 0) {
|
|
290
330
|
return {
|
|
291
331
|
lifecycleScripts: expansion.lifecycleScripts,
|
|
292
332
|
reason: 'no bounded local package-script path reaches the selected framework runner',
|
|
@@ -294,6 +334,15 @@ function getRunnerResolution (command, framework, ci) {
|
|
|
294
334
|
status: 'unresolved',
|
|
295
335
|
}
|
|
296
336
|
}
|
|
337
|
+
if (candidates.length > 1) {
|
|
338
|
+
return {
|
|
339
|
+
lifecycleScripts: expansion.lifecycleScripts,
|
|
340
|
+
reason: 'more than one bounded local package-script path reaches the selected framework runner',
|
|
341
|
+
source: 'unresolved_wrapper',
|
|
342
|
+
status: 'unresolved',
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const candidate = candidates[0]
|
|
297
346
|
return {
|
|
298
347
|
commandPath: candidate.path,
|
|
299
348
|
lifecycleScripts: expansion.lifecycleScripts,
|
|
@@ -303,11 +352,11 @@ function getRunnerResolution (command, framework, ci) {
|
|
|
303
352
|
}
|
|
304
353
|
}
|
|
305
354
|
|
|
306
|
-
function readProjectScripts (filename) {
|
|
355
|
+
function readProjectScripts (filename, projectFileSources) {
|
|
307
356
|
try {
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
310
|
-
const packageJson = JSON.parse(
|
|
357
|
+
const source = readProjectSource(filename, projectFileSources)
|
|
358
|
+
if (source === undefined) return
|
|
359
|
+
const packageJson = JSON.parse(source)
|
|
311
360
|
if (!packageJson.scripts || typeof packageJson.scripts !== 'object' ||
|
|
312
361
|
Array.isArray(packageJson.scripts)) return {}
|
|
313
362
|
return packageJson.scripts
|
|
@@ -346,18 +395,19 @@ function classifyUnresolved (ci, resolution, matrixRelevant, jobSource) {
|
|
|
346
395
|
const ignored = []
|
|
347
396
|
const unresolved = Array.isArray(ci.unresolved) ? ci.unresolved : []
|
|
348
397
|
const githubHosted = /[/\\]\.github[/\\]workflows[/\\]/.test(ci.configFile) &&
|
|
349
|
-
|
|
398
|
+
/^[ \t]*runs-on:[ \t]*(?:ubuntu|windows|macos)-/mi.test(jobSource)
|
|
350
399
|
|
|
351
400
|
for (const item of unresolved) {
|
|
352
401
|
const isMatrix = /\bmatrix\b/i.test(item)
|
|
353
|
-
const isResolvedPackagePath = resolution.
|
|
354
|
-
|
|
402
|
+
const isResolvedPackagePath = resolution.status === 'confirmed' &&
|
|
403
|
+
resolution.source === 'local_package_script' &&
|
|
404
|
+
/\b(?:bun|lifecycle|npm|package script|pnpm|pretest|posttest|yarn)\b/i.test(item)
|
|
355
405
|
const isAmbientGithubSettings = githubHosted &&
|
|
356
|
-
/\b(?:repository|organization|environment)[-\s,\w]
|
|
406
|
+
/\b(?:repository|organization|environment)[-\s,\w]+\b(?:secrets?|variables?)\b/i.test(item) &&
|
|
357
407
|
/\b(?:inject|inherit|outside)\b/i.test(item)
|
|
358
408
|
const isOtherJob = /^Other jobs?\b/i.test(item) ||
|
|
359
|
-
/\bsecond\b
|
|
360
|
-
/\brelease\b
|
|
409
|
+
/\bsecond\b.+\bjob\b.+\bonly\b.+\bselected\b/i.test(item) ||
|
|
410
|
+
/\brelease\b.+\bcontains no test job\b/i.test(item)
|
|
361
411
|
if ((isMatrix && !matrixRelevant) ||
|
|
362
412
|
isResolvedPackagePath ||
|
|
363
413
|
isAmbientGithubSettings ||
|
|
@@ -373,6 +423,29 @@ function classifyUnresolved (ci, resolution, matrixRelevant, jobSource) {
|
|
|
373
423
|
return { ignored, relevant }
|
|
374
424
|
}
|
|
375
425
|
|
|
426
|
+
function hasNoSupportedCiConfiguration (manifest, ci) {
|
|
427
|
+
if (ci.configFile || ci.job || ci.command) return false
|
|
428
|
+
const unresolved = Array.isArray(ci.unresolved) ? ci.unresolved : []
|
|
429
|
+
return manifest.ciDiscovery?.found?.length === 0 ||
|
|
430
|
+
unresolved.some(item => /No supported CI configuration file was found/i.test(item))
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function hasUnavailableRemoteCiCommand (ci) {
|
|
434
|
+
if (ci.command) return false
|
|
435
|
+
const evidence = [
|
|
436
|
+
ci.step,
|
|
437
|
+
...(Array.isArray(ci.unresolved) ? ci.unresolved : []),
|
|
438
|
+
].filter(Boolean)
|
|
439
|
+
if (evidence.some(item => {
|
|
440
|
+
return /\b(?:remote|external|third-party)\s+(?:action|workflow)\b/i.test(item)
|
|
441
|
+
})) return true
|
|
442
|
+
|
|
443
|
+
return evidence.some(item => {
|
|
444
|
+
const reference = /^\s*uses:\s*["']?([^"'\s]+)["']?\s*$/im.exec(item)?.[1]
|
|
445
|
+
return reference && !reference.startsWith('./')
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
|
|
376
449
|
function matrixAffectsCiFacts (jobSource, command) {
|
|
377
450
|
const matrixReference = /\bmatrix\s*[.[]/
|
|
378
451
|
if (!matrixReference.test(jobSource)) return false
|
|
@@ -407,6 +480,8 @@ function normalizeDirectCommand (command) {
|
|
|
407
480
|
assignments.push(...crossEnv.assignments)
|
|
408
481
|
source = source.slice(crossEnv.length)
|
|
409
482
|
}
|
|
483
|
+
source = source.replace(/^(?:(?:bunx|npx)(?:\.cmd)?|(?:pnpm|yarn)(?:\.cmd)?\s+exec)\s+/, '')
|
|
484
|
+
.replace(/^bun x\s+/, '')
|
|
410
485
|
return { assignments, index: prefix.length, source }
|
|
411
486
|
}
|
|
412
487
|
|
|
@@ -446,7 +521,7 @@ function getSelectedJobSource (source, ci) {
|
|
|
446
521
|
|
|
447
522
|
function getYamlKeyEntry (line, index) {
|
|
448
523
|
if (!line || /^\s*(?:#|$)/.test(line) || /^\s/.test(line) && line.includes('\t')) return
|
|
449
|
-
const match = /^(\s*)(?:"([^"]+)"|'([^']+)'|([
|
|
524
|
+
const match = /^(\s*)(?:"([^"]+)"|'([^']+)'|([^\s:#][^:]*)):\s*(?:#.*)?$/.exec(line)
|
|
450
525
|
if (!match) return
|
|
451
526
|
return {
|
|
452
527
|
indent: match[1].length,
|
|
@@ -491,16 +566,23 @@ function getMissingReviewFields (ci) {
|
|
|
491
566
|
}
|
|
492
567
|
|
|
493
568
|
/**
|
|
494
|
-
* Reads one bounded regular
|
|
569
|
+
* Reads one bounded regular project file or its approval-bound snapshot.
|
|
495
570
|
*
|
|
496
|
-
* @param {string} filename
|
|
571
|
+
* @param {string} filename project file
|
|
572
|
+
* @param {Map<string, Buffer|undefined>} [projectFileSources] approval-bound project sources
|
|
497
573
|
* @returns {string|undefined} source
|
|
498
574
|
*/
|
|
499
|
-
function
|
|
575
|
+
function readProjectSource (filename, projectFileSources) {
|
|
576
|
+
if (typeof filename !== 'string') return
|
|
577
|
+
const resolved = path.resolve(filename)
|
|
578
|
+
if (projectFileSources) {
|
|
579
|
+
if (!projectFileSources.has(resolved)) return
|
|
580
|
+
return projectFileSources.get(resolved)?.toString('utf8')
|
|
581
|
+
}
|
|
500
582
|
try {
|
|
501
|
-
const stat = fs.lstatSync(
|
|
583
|
+
const stat = fs.lstatSync(resolved)
|
|
502
584
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_CI_FILE_BYTES) return
|
|
503
|
-
return fs.readFileSync(
|
|
585
|
+
return fs.readFileSync(resolved, 'utf8')
|
|
504
586
|
} catch {}
|
|
505
587
|
}
|
|
506
588
|
|
|
@@ -519,11 +601,35 @@ function containsLiteral (source, value) {
|
|
|
519
601
|
|
|
520
602
|
function containsExecutionCommand (source, value) {
|
|
521
603
|
const command = String(value).replaceAll('\r\n', '\n').trim()
|
|
522
|
-
if (!command
|
|
523
|
-
|
|
604
|
+
if (!command) return false
|
|
605
|
+
const lines = source.replaceAll('\r\n', '\n').split('\n')
|
|
606
|
+
return lines.some((line, index) => {
|
|
524
607
|
if (/^\s*#/.test(line)) return false
|
|
525
|
-
const match = /^\s*(?:-\s*)?(?:run|script)
|
|
526
|
-
|
|
608
|
+
const match = /^\s*(?:-\s*)?(?:run|script):(.*)$/.exec(line)
|
|
609
|
+
if (!match) return false
|
|
610
|
+
const scalar = match[1].trim()
|
|
611
|
+
if (!/^\|[+-]?$/.test(scalar)) return scalar === command
|
|
612
|
+
|
|
613
|
+
const indicatorIndent = /^\s*/.exec(line)[0].length
|
|
614
|
+
const block = []
|
|
615
|
+
let contentIndent
|
|
616
|
+
for (let next = index + 1; next < lines.length; next++) {
|
|
617
|
+
if (!lines[next].trim()) {
|
|
618
|
+
block.push('')
|
|
619
|
+
continue
|
|
620
|
+
}
|
|
621
|
+
const nextIndent = /^\s*/.exec(lines[next])[0].length
|
|
622
|
+
if (contentIndent === undefined) {
|
|
623
|
+
if (nextIndent <= indicatorIndent) break
|
|
624
|
+
contentIndent = nextIndent
|
|
625
|
+
} else if (nextIndent < contentIndent) {
|
|
626
|
+
break
|
|
627
|
+
}
|
|
628
|
+
block.push(lines[next])
|
|
629
|
+
}
|
|
630
|
+
if (contentIndent === undefined) return false
|
|
631
|
+
const blockCommand = block.map(candidate => candidate.slice(contentIndent)).join('\n').trim()
|
|
632
|
+
return blockCommand === command
|
|
527
633
|
})
|
|
528
634
|
}
|
|
529
635
|
|