dd-trace 6.24.0 → 6.25.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.
Files changed (250) hide show
  1. package/ci/init.js +2 -22
  2. package/ext/exporters.js +0 -1
  3. package/index.d.ts +105 -5
  4. package/initialize.mjs +5 -2
  5. package/lambda.d.ts +39 -0
  6. package/lambda.js +3 -0
  7. package/package.json +11 -9
  8. package/packages/datadog-esbuild/index.js +8 -55
  9. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  10. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  11. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  12. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  13. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  14. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  15. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  16. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  17. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  18. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  21. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -1
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -3
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  33. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  34. package/packages/datadog-instrumentations/src/next.js +19 -6
  35. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  36. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  37. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  38. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  39. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  40. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  41. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  42. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  43. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  44. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  45. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +22 -11
  46. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  48. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  49. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  50. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  51. package/packages/datadog-plugin-http/src/client.js +32 -9
  52. package/packages/datadog-plugin-http2/src/client.js +38 -13
  53. package/packages/datadog-plugin-next/src/index.js +112 -14
  54. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  55. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  56. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  57. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  58. package/packages/datadog-plugin-undici/src/index.js +22 -7
  59. package/packages/datadog-turbopack/index.js +4 -28
  60. package/packages/datadog-turbopack/src/loader.js +14 -452
  61. package/packages/datadog-webpack/index.js +3 -55
  62. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  63. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  64. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  65. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  66. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  67. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  68. package/packages/dd-trace/src/before-exit.js +32 -0
  69. package/packages/dd-trace/src/bootstrap.js +5 -3
  70. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  71. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  72. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  73. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  74. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  75. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  76. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  77. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  78. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  79. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  80. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  81. package/packages/dd-trace/src/config/defaults.js +5 -0
  82. package/packages/dd-trace/src/config/generated-config-types.d.ts +42 -2
  83. package/packages/dd-trace/src/config/index.js +17 -5
  84. package/packages/dd-trace/src/config/parsers.js +9 -0
  85. package/packages/dd-trace/src/config/supported-configurations.json +158 -4
  86. package/packages/dd-trace/src/constants.js +1 -0
  87. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  88. package/packages/dd-trace/src/exporter.js +0 -11
  89. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  90. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  91. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  92. package/packages/dd-trace/src/id.js +1 -1
  93. package/packages/dd-trace/src/lambda/facade.js +74 -0
  94. package/packages/dd-trace/src/lambda/handler.js +3 -41
  95. package/packages/dd-trace/src/lambda/index.js +38 -15
  96. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  97. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  98. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  99. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  100. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  101. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  102. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  103. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  104. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  105. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  106. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  107. package/packages/dd-trace/src/log/channels.js +4 -0
  108. package/packages/dd-trace/src/log/writer.js +6 -1
  109. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +4 -0
  110. package/packages/dd-trace/src/openfeature/configuration_source.js +35 -27
  111. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  112. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  113. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  114. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  115. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  116. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  117. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  118. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  119. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  120. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  121. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  122. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  123. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  124. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  125. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  126. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  127. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  128. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  129. package/packages/dd-trace/src/plugin_manager.js +34 -7
  130. package/packages/dd-trace/src/plugins/ci_plugin.js +41 -10
  131. package/packages/dd-trace/src/plugins/index.js +6 -0
  132. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  133. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  134. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  135. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  136. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  137. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
  138. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  139. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  140. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  141. package/packages/dd-trace/src/plugins/util/test.js +64 -39
  142. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  143. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  144. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  145. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  146. package/packages/dd-trace/src/proxy.js +33 -53
  147. package/packages/dd-trace/src/span_processor.js +20 -0
  148. package/packages/dd-trace/src/startup-log.js +8 -6
  149. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  150. package/packages/dd-trace/src/tracer.js +0 -2
  151. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  152. package/register.js +2 -1
  153. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  154. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  155. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  156. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  157. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  158. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  159. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  160. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  161. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  162. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  163. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  164. package/vendor/dist/esquery/LICENSE +2 -0
  165. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  166. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  167. package/vendor/dist/jest-docblock/LICENSE +16 -0
  168. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  169. package/vendor/dist/limiter/LICENSE +2 -0
  170. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  171. package/vendor/dist/lru-cache/LICENSE +13 -0
  172. package/vendor/dist/meriyah/LICENSE +13 -0
  173. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  174. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  175. package/vendor/dist/pprof-format/LICENSE +13 -0
  176. package/vendor/dist/pprof-format/index.js +1 -1
  177. package/vendor/dist/protobufjs/LICENSE +219 -0
  178. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  179. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  180. package/vendor/dist/retry/LICENSE +2 -0
  181. package/vendor/dist/rfdc/LICENSE +2 -0
  182. package/vendor/dist/semifies/LICENSE +3 -1
  183. package/vendor/dist/shell-quote/LICENSE +3 -1
  184. package/vendor/dist/source-map/LICENSE +1 -0
  185. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  186. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  187. package/vendor/dist/ttl-set/LICENSE +28 -0
  188. package/ci/diagnose.js +0 -2215
  189. package/ci/runbook.md +0 -299
  190. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  191. package/ci/test-optimization-validation/approval.js +0 -386
  192. package/ci/test-optimization-validation/artifact-id.js +0 -18
  193. package/ci/test-optimization-validation/blocker-category.js +0 -24
  194. package/ci/test-optimization-validation/bounded-json.js +0 -120
  195. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  196. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  197. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  198. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  199. package/ci/test-optimization-validation/cli.js +0 -954
  200. package/ci/test-optimization-validation/command-blocker.js +0 -377
  201. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  202. package/ci/test-optimization-validation/command-runner.js +0 -649
  203. package/ci/test-optimization-validation/environment.js +0 -88
  204. package/ci/test-optimization-validation/executable-approval.js +0 -47
  205. package/ci/test-optimization-validation/executable.js +0 -244
  206. package/ci/test-optimization-validation/execution-lock.js +0 -70
  207. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  208. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  209. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  210. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  211. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  212. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  213. package/ci/test-optimization-validation/generated-files.js +0 -425
  214. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  215. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  216. package/ci/test-optimization-validation/literal-environment.js +0 -56
  217. package/ci/test-optimization-validation/literal-glob.js +0 -52
  218. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  219. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  220. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  221. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  222. package/ci/test-optimization-validation/offline-output.js +0 -406
  223. package/ci/test-optimization-validation/package-check.js +0 -97
  224. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  225. package/ci/test-optimization-validation/plan-writer.js +0 -541
  226. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  227. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  228. package/ci/test-optimization-validation/redaction.js +0 -319
  229. package/ci/test-optimization-validation/report-writer.js +0 -666
  230. package/ci/test-optimization-validation/result-semantics.js +0 -103
  231. package/ci/test-optimization-validation/runner-command.js +0 -264
  232. package/ci/test-optimization-validation/runner-contract.js +0 -695
  233. package/ci/test-optimization-validation/safe-files.js +0 -202
  234. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  235. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  236. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  237. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  238. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  239. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  240. package/ci/test-optimization-validation/source-text.js +0 -84
  241. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  242. package/ci/test-optimization-validation/test-output.js +0 -120
  243. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  244. package/ci/validate-test-optimization.js +0 -3
  245. package/packages/datadog-esbuild/src/resolver.js +0 -284
  246. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  247. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  248. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  249. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  250. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -1,186 +0,0 @@
1
- 'use strict'
2
-
3
- const { BLOCKER_CATEGORIES, getBlockerDomain } = require('./blocker-category')
4
- const { getCommandBlocker } = require('./command-blocker')
5
- const { runCommand, serializeDisplayCommand } = require('./command-runner')
6
- const { getBasicCommand } = require('./runner-command')
7
- const { summarizeTestOutput } = require('./scenarios/basic-reporting')
8
- const { findInterestingLines, frameworkOutDir } = require('./scenarios/helpers')
9
- const { getObservedTestCount } = require('./test-output')
10
-
11
- /**
12
- * Runs one direct representative test without Datadog initialization.
13
- *
14
- * @param {object} input preflight inputs
15
- * @param {object} input.framework framework manifest entry
16
- * @param {string} input.out validation output directory
17
- * @param {object} input.options validator options
18
- * @returns {Promise<{ok: boolean, failure?: object, preflight: object}>} preflight outcome
19
- */
20
- async function runFrameworkPreflight ({ framework, out, options }) {
21
- const candidates = [
22
- {
23
- localSocketRequired: framework.localSocketRequired,
24
- testFile: framework.validation.testFile,
25
- },
26
- ...(framework.validation.fallbackTests || []),
27
- ]
28
- const attempts = []
29
- let last
30
-
31
- for (const [index, candidate] of candidates.entries()) {
32
- // Fallbacks are ordered and later candidates must not run after one succeeds.
33
- // eslint-disable-next-line no-await-in-loop
34
- const attempt = await runCandidate({ framework, index, options, out, testFile: candidate.testFile })
35
- attempts.push(attempt.preflight)
36
- last = attempt
37
- if (!attempt.ok) {
38
- if (isSharedCandidateBlocker(attempt.commandFailure, framework)) break
39
- continue
40
- }
41
-
42
- framework.validation.testFile = candidate.testFile
43
- const preflight = { ...attempt.preflight, attempts, selectedTestFile: candidate.testFile }
44
- framework.preflight = preflight
45
- return { ok: true, preflight }
46
- }
47
-
48
- const { commandFailure, observedTestCount, preflight, result } = last
49
- const completePreflight = {
50
- ...preflight,
51
- attempts,
52
- selectedTestFile: undefined,
53
- }
54
- framework.preflight = completePreflight
55
- const blockerCategory = commandFailure?.blockerCategory ||
56
- (observedTestCount === 0
57
- ? BLOCKER_CATEGORIES.VALIDATOR_LIMITATION
58
- : BLOCKER_CATEGORIES.CLEAN_TEST_FAILED)
59
- const domain = getBlockerDomain(blockerCategory)
60
- const diagnosis = getFailureDiagnosis(
61
- result,
62
- observedTestCount,
63
- commandFailure,
64
- preflight.diagnosticSummary,
65
- framework
66
- )
67
- return {
68
- ok: false,
69
- preflight: completePreflight,
70
- failure: {
71
- frameworkId: framework.id,
72
- scenario: 'basic-reporting',
73
- status: 'blocked',
74
- diagnosis,
75
- evidence: {
76
- blockerCategory,
77
- commandFailure,
78
- domain,
79
- recommendation: commandFailure?.recommendation ||
80
- `Resolve the selected project test failure before retrying validation: ${diagnosis}`,
81
- validationIncomplete: true,
82
- },
83
- artifacts: Object.values(result.artifacts),
84
- },
85
- }
86
- }
87
-
88
- async function runCandidate ({ framework, index, options, out, testFile }) {
89
- const suffix = index === 0 ? '' : `-fallback-${index}`
90
- const command = getBasicCommand(framework, testFile)
91
- const outDir = frameworkOutDir(out, framework, `preflight${suffix}`)
92
- const result = await runCommand(command, {
93
- artifactRoot: out,
94
- envMode: 'clean',
95
- label: `${framework.id}:preflight${suffix}`,
96
- outDir,
97
- repositoryRoot: options.repositoryRoot,
98
- requireExecutableApproval: options.requireExecutableApproval,
99
- verbose: options.verbose,
100
- })
101
- const observedTestCount = getObservedTestCount(framework.framework, result.stdout, result.stderr)
102
- const commandFailure = getCommandBlocker(result, {
103
- browserRequired: framework.browserRequired,
104
- framework: framework.framework,
105
- packageJson: framework.project.packageJson,
106
- testsRan: Number.isInteger(observedTestCount) && observedTestCount > 0,
107
- })
108
- const preflight = {
109
- command: serializeDisplayCommand(command),
110
- diagnosticSummary: findInterestingLines(`${result.stdout}\n${result.stderr}`, [
111
- /\b(?:Abort trap|Cannot find|Error|TypeError|ReferenceError|RangeError|SyntaxError|ERR_[A-Z_]+|FAIL|Failed to|No tests found|Received signal|SIGABRT)\b/i,
112
- ], 4),
113
- durationMs: result.durationMs,
114
- exitCode: result.exitCode,
115
- observedTestCount,
116
- ran: true,
117
- selectorVerification: framework.validation.selectorScope === 'instrumented_event_identity'
118
- ? 'requires_instrumented_event_identity'
119
- : 'bounded_direct_runner',
120
- source: 'validator',
121
- stderrSummary: summarizeTestOutput('', result.stderr).join('\n'),
122
- stdoutSummary: summarizeTestOutput(result.stdout).join('\n'),
123
- testFile,
124
- timedOut: result.timedOut,
125
- ...(commandFailure ? { commandFailure } : {}),
126
- }
127
- return {
128
- commandFailure,
129
- observedTestCount,
130
- ok: !result.timedOut && result.exitCode === 0 && observedTestCount !== 0,
131
- preflight,
132
- result,
133
- }
134
- }
135
-
136
- /**
137
- * Explains why direct Basic Reporting could not start reliably.
138
- *
139
- * @param {object} result command result
140
- * @param {number|null} observedTestCount parsed test count
141
- * @param {object|undefined} commandFailure classified blocker
142
- * @param {string[]} diagnosticSummary bounded diagnostic lines
143
- * @param {object} framework framework manifest entry
144
- */
145
- function getFailureDiagnosis (result, observedTestCount, commandFailure, diagnosticSummary, framework) {
146
- const sharedPrerequisite = !commandFailure && framework.allCandidatesRequireLocalSocket
147
- ? ' Every approved candidate appears to require localhost, so retry in the project environment where its ' +
148
- 'listener-based tests normally pass.'
149
- : ''
150
- if (commandFailure?.summary) {
151
- return `${commandFailure.summary} Basic Reporting could not be tested reliably.${sharedPrerequisite}`
152
- }
153
- if (result.timedOut) {
154
- return 'The direct representative test exceeded its approved timeout. Basic Reporting could not be tested ' +
155
- 'reliably; rerun the test normally and confirm its prerequisites before trying again.'
156
- }
157
- if (observedTestCount === 0) {
158
- return 'The direct runner completed without reporting a test. The selected file may require project wrapper or ' +
159
- 'configuration semantics, so Basic Reporting remains incomplete.'
160
- }
161
- if (diagnosticSummary.length > 0) {
162
- return `The direct representative test exited ${result.exitCode} without Datadog initialization. ` +
163
- `The first reported issue was: ${diagnosticSummary[0]}${sharedPrerequisite}`
164
- }
165
- return `The direct representative test exited ${result.exitCode} without Datadog initialization. Fix or prepare ` +
166
- `that test normally, then create a fresh validation plan.${sharedPrerequisite}`
167
- }
168
-
169
- // Do not try fallbacks when every disclosed candidate shares the same prerequisite.
170
- function isSharedCandidateBlocker (commandFailure, framework) {
171
- if (!commandFailure) return false
172
- if (commandFailure.kind === 'local-test-socket-blocked') {
173
- return framework.allCandidatesRequireLocalSocket === true
174
- }
175
- return commandFailure.kind.endsWith('-browser-launch-blocked') ||
176
- [
177
- 'cucumber-browser-missing',
178
- 'cypress-runtime-missing',
179
- 'playwright-browser-missing',
180
- 'project-command-environment-missing',
181
- 'test-runner-command-missing',
182
- 'vitest-browser-provider-missing',
183
- ].includes(commandFailure.kind)
184
- }
185
-
186
- module.exports = { runFrameworkPreflight }
@@ -1,31 +0,0 @@
1
- 'use strict'
2
-
3
- const path = require('node:path')
4
-
5
- const BUILD_DIRECTORY_PATTERN = /(?:^|\/)(?:build|dist|generated)(?:\/|$)/
6
- const WINDOWS_ABSOLUTE_PATH_PATTERN = /^[A-Za-z]:\//
7
-
8
- // Bare package subpaths and node_modules paths belong to dependencies, not to the customer project.
9
- function isProjectBuildArtifactPath (filename, projectRoot, baseDirectory = projectRoot) {
10
- const normalized = String(filename).replaceAll('\\', '/')
11
- if (!BUILD_DIRECTORY_PATTERN.test(normalized) ||
12
- /(?:^|\/)node_modules(?:\/|$)/.test(normalized)) return false
13
-
14
- const relativePath = normalized.startsWith('./') || normalized.startsWith('../')
15
- if ((!relativePath && !normalized.startsWith('/') && !WINDOWS_ABSOLUTE_PATH_PATTERN.test(normalized)) ||
16
- typeof projectRoot !== 'string') return false
17
-
18
- const normalizedRoot = projectRoot.replaceAll('\\', '/')
19
- const windowsPath = WINDOWS_ABSOLUTE_PATH_PATTERN.test(normalized)
20
- const windowsRoot = WINDOWS_ABSOLUTE_PATH_PATTERN.test(normalizedRoot)
21
- if (windowsPath !== windowsRoot && windowsPath) return false
22
- const pathApi = windowsRoot ? path.win32 : path.posix
23
- const root = pathApi.resolve(normalizedRoot)
24
- const candidate = relativePath
25
- ? pathApi.resolve(String(baseDirectory).replaceAll('\\', '/'), normalized)
26
- : pathApi.resolve(normalized)
27
- const relative = pathApi.relative(root, candidate)
28
- return relative === '' || (!relative.startsWith('..') && !pathApi.isAbsolute(relative))
29
- }
30
-
31
- module.exports = { isProjectBuildArtifactPath }
@@ -1,319 +0,0 @@
1
- 'use strict'
2
-
3
- const REDACTED = '<redacted>'
4
- const MAX_SANITIZE_DEPTH = 128
5
- const TRUNCATED_NESTING = '[Truncated: nesting exceeds redaction limit]'
6
-
7
- const SECRET_NAME_SOURCE = [
8
- 'API_?KEY',
9
- 'APP_?KEY',
10
- 'TOKEN',
11
- 'SECRET',
12
- 'PASSWORD',
13
- 'PASSPHRASE',
14
- 'CREDENTIAL',
15
- 'PRIVATE_?KEY',
16
- 'ACCESS_?KEY',
17
- 'COOKIE',
18
- ].join('|')
19
- const EXACT_SECRET_ASSIGNMENT_NAME_SOURCE = [
20
- SECRET_NAME_SOURCE,
21
- 'AUTH',
22
- 'AUTHORIZATION',
23
- 'PASS',
24
- 'PAT',
25
- 'JWT',
26
- 'WEBHOOK(?:_URL)?',
27
- ].join('|')
28
- // Every pattern built from these name sources carries the `i` flag; the classes list uppercase only.
29
- const SECRET_NAME_CHARS = '[A-Z0-9_.-]'
30
- const SECRET_ASSIGNMENT_NAME_SOURCE = [
31
- EXACT_SECRET_ASSIGNMENT_NAME_SOURCE,
32
- `[A-Z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
33
- `[A-Z_]${SECRET_NAME_CHARS}*[-_]PASS`,
34
- `[A-Z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
35
- `[A-Z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
36
- ].join('|')
37
- const SECRET_FLAG_SOURCE = [
38
- 'api-key',
39
- 'app-key',
40
- 'token',
41
- 'secret',
42
- 'password',
43
- 'pass',
44
- 'credential',
45
- 'private-key',
46
- 'client-secret',
47
- 'access-key',
48
- 'auth',
49
- ].join('|')
50
- const SECRET_VALUE_SOURCE = String.raw`("[^"]*"|'[^']*'|[^\s,;]+)`
51
- const SENSITIVE_NAME_PATTERN = new RegExp(SECRET_NAME_SOURCE, 'i')
52
- const SENSITIVE_AUTH_NAME_PATTERN = /(?:^|_)AUTH(?:ORIZATION)?(?:_|$)/i
53
- const SENSITIVE_COOKIE_NAME_PATTERN = /(?:^|_)SET_?COOKIE(?:_|$)|(?:^|_)COOKIE(?:_|$)/i
54
- const SENSITIVE_PASS_NAME_PATTERN = /(?:^|_)PASS(?:_|$)/i
55
- const SENSITIVE_TOKEN_ALIAS_NAME_PATTERN = /(?:^|_)(?:PAT|JWT|WEBHOOK(?:_URL)?)(?:_|$)/i
56
- const SECRET_ASSIGNMENT_PATTERN = new RegExp(
57
- String.raw`\b(${SECRET_ASSIGNMENT_NAME_SOURCE})\s*=\s*` + SECRET_VALUE_SOURCE,
58
- 'gi'
59
- )
60
- const SECRET_FLAG_PATTERN = new RegExp(
61
- String.raw`(--(?:${SECRET_FLAG_SOURCE})(?:-[A-Z0-9]+)*)(=|\s+)` + SECRET_VALUE_SOURCE,
62
- 'gi'
63
- )
64
- const SECRET_FLAG_NAME_PATTERN = new RegExp(
65
- `^--(?:${SECRET_FLAG_SOURCE})(?:-[A-Z0-9]+)*$`,
66
- 'i'
67
- )
68
- const AUTH_HEADER_PATTERN = /\b(Bearer)\s+([^\s'",}\]]+)/gi
69
- const AUTH_SCHEME_ASSIGNMENT_QUOTED_PATTERN = new RegExp(
70
- String.raw`\b(${SECRET_ASSIGNMENT_NAME_SOURCE})\s*=\s*(["'])(?:Bearer|Basic)\s.*?\2`,
71
- 'gi'
72
- )
73
- const AUTH_SCHEME_ASSIGNMENT_PATTERN = new RegExp(
74
- String.raw`\b(${SECRET_ASSIGNMENT_NAME_SOURCE})\s*=\s*(?:Bearer|Basic)\s+[^\s,;]+`,
75
- 'gi'
76
- )
77
- const DEFAULT_IGNORABLE_PATTERN = /\p{Default_Ignorable_Code_Point}/gu
78
- const DEFAULT_IGNORABLE_TEST_PATTERN = /\p{Default_Ignorable_Code_Point}/u
79
- const CONTROL_CHARACTER_TEST_PATTERN = /\p{Cc}/u
80
- const UNSAFE_CONTROL_SOURCE = String.raw`[\u0000-\u0008\v\f\u000E-\u001F\u007F-\u009F]`
81
- const UNSAFE_CONTROL_PATTERN = new RegExp(UNSAFE_CONTROL_SOURCE, 'g')
82
- const UNSAFE_CONTROL_TEST_PATTERN = new RegExp(UNSAFE_CONTROL_SOURCE)
83
- const PRIVATE_KEY_BLOCK_PATTERN =
84
- /-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/g
85
- const JWT_VALUE_PATTERN = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g
86
- const KNOWN_TOKEN_VALUE_PATTERN =
87
- /\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
88
- const SECRET_HEADER_ENV_NAME_SOURCE = [
89
- `${SECRET_NAME_SOURCE}|PAT|JWT|WEBHOOK(?:_URL)?`,
90
- `[A-Z_]${SECRET_NAME_CHARS}*(?:${SECRET_NAME_SOURCE})${SECRET_NAME_CHARS}*`,
91
- `[A-Z_]${SECRET_NAME_CHARS}*[-_]AUTH(?:ORIZATION)?`,
92
- `[A-Z_]${SECRET_NAME_CHARS}*[-_](?:PAT|JWT|WEBHOOK(?:_URL)?)`,
93
- ].join('|')
94
- const SECRET_HEADER_NAME_SOURCE = [
95
- 'dd-api-key',
96
- 'x-api-key',
97
- 'api-key',
98
- 'authorization',
99
- 'proxy-authorization',
100
- SECRET_HEADER_ENV_NAME_SOURCE,
101
- ].join('|')
102
- const SECRET_HEADER_PATTERN = new RegExp(
103
- String.raw`\b(${SECRET_HEADER_NAME_SOURCE})\s*:\s*("[^"]*"|'[^']*'|[^\r\n,}]+)`,
104
- 'gi'
105
- )
106
- const URL_CREDENTIAL_PATTERN = /(?<![a-z0-9+.-])([a-z][a-z0-9+.-]*:\/\/)([^@\s/]+)(@)/gi
107
- const GITHUB_SECRET_REFERENCE_PATTERN =
108
- /(?:\b[A-Za-z_][A-Za-z0-9_.-]*\s*[:=]\s*)?\$\{\{\s*secrets\.([A-Za-z_][A-Za-z0-9_]*)\s*\}\}/g
109
- const SAFE_REFERENCE_MARKER_PATTERN = /DDCIVARREF([0-9]+)X/g
110
-
111
- const ENV_CONTAINER_KEYS = new Set([
112
- 'safeEnv',
113
- 'workflowEnv',
114
- 'jobEnv',
115
- 'stepEnv',
116
- 'inheritedEnv',
117
- ])
118
-
119
- const SECRET_NAME_ONLY_KEYS = new Set([
120
- 'requiredEnvVars',
121
- 'requiredSecretEnvVars',
122
- 'secretEnvVars',
123
- 'missingEnvVars',
124
- 'originalSecretEnvVars',
125
- ])
126
-
127
- /**
128
- * Redacts secret-like values from arbitrary report data before it is serialized.
129
- *
130
- * @param {unknown} value data to sanitize
131
- * @returns {unknown} sanitized copy
132
- */
133
- function sanitizeForReport (value) {
134
- return sanitizeValue(value, new WeakSet(), undefined, 0)
135
- }
136
-
137
- /**
138
- * Redacts secret-like values from an environment variable map.
139
- *
140
- * @param {object|undefined} env environment map
141
- * @returns {object|undefined} sanitized environment map
142
- */
143
- function sanitizeEnv (env) {
144
- if (!env || typeof env !== 'object' || Array.isArray(env)) return
145
-
146
- const sanitized = {}
147
- for (const [name, value] of Object.entries(env)) {
148
- sanitized[name] = sanitizeEnvValue(name, value)
149
- }
150
- if (Object.keys(sanitized).length > 0) return sanitized
151
- }
152
-
153
- /**
154
- * Redacts a single environment value when its name is secret-like.
155
- *
156
- * @param {string} name environment variable name
157
- * @param {unknown} value environment variable value
158
- * @returns {string|undefined} sanitized environment variable value
159
- */
160
- function sanitizeEnvValue (name, value) {
161
- if (isSensitiveName(name)) return REDACTED
162
- if (value === undefined) return
163
- return sanitizeString(String(value))
164
- }
165
-
166
- /**
167
- * Redacts common inline secret forms from strings.
168
- *
169
- * @param {string} value string to sanitize
170
- */
171
- function sanitizeString (value) {
172
- const references = []
173
- const protectedValue = value.replaceAll(GITHUB_SECRET_REFERENCE_PATTERN, reference => {
174
- return `DDCIVARREF${references.push(reference) - 1}X`
175
- })
176
- const sanitized = protectedValue
177
- .replaceAll(DEFAULT_IGNORABLE_PATTERN, '')
178
- .replaceAll(UNSAFE_CONTROL_PATTERN, '')
179
- .replaceAll(PRIVATE_KEY_BLOCK_PATTERN, '<redacted-private-key>')
180
- .replaceAll(JWT_VALUE_PATTERN, REDACTED)
181
- .replaceAll(KNOWN_TOKEN_VALUE_PATTERN, REDACTED)
182
- .replaceAll(AUTH_SCHEME_ASSIGNMENT_QUOTED_PATTERN, `$1=${REDACTED}`)
183
- .replaceAll(AUTH_SCHEME_ASSIGNMENT_PATTERN, `$1=${REDACTED}`)
184
- .replaceAll(SECRET_ASSIGNMENT_PATTERN, `$1=${REDACTED}`)
185
- .replaceAll(SECRET_FLAG_PATTERN, `$1$2${REDACTED}`)
186
- .replaceAll(SECRET_HEADER_PATTERN, `$1: ${REDACTED}`)
187
- .replaceAll(AUTH_HEADER_PATTERN, `$1 ${REDACTED}`)
188
- .replaceAll(URL_CREDENTIAL_PATTERN, `$1${REDACTED}$3`)
189
-
190
- return sanitized.replaceAll(SAFE_REFERENCE_MARKER_PATTERN, (marker, index) => references[Number(index)] || marker)
191
- }
192
-
193
- /**
194
- * Detects default-ignorable Unicode characters that can conceal executable text or secret names.
195
- *
196
- * @param {unknown} value candidate text
197
- */
198
- function hasUnicodeDefaultIgnorable (value) {
199
- return DEFAULT_IGNORABLE_TEST_PATTERN.test(String(value))
200
- }
201
-
202
- function hasUnsafeInvisibleCharacter (value) {
203
- const text = String(value)
204
- return hasUnicodeDefaultIgnorable(text) || UNSAFE_CONTROL_TEST_PATTERN.test(text)
205
- }
206
-
207
- function hasUnsafeExecutionCharacter (value) {
208
- return hasUnicodeDefaultIgnorable(value) || CONTROL_CHARACTER_TEST_PATTERN.test(String(value ?? ''))
209
- }
210
-
211
- /**
212
- * Makes untrusted text safe to print to an interactive terminal while preserving line breaks.
213
- *
214
- * @param {unknown} value console value
215
- */
216
- function sanitizeConsoleText (value) {
217
- let result = ''
218
- for (const character of sanitizeString(String(value ?? ''))) {
219
- const code = character.charCodeAt(0)
220
- result += character === '\n' || character === '\t' || code > 0x1F && code !== 0x7F
221
- ? character
222
- : String.raw`\u${code.toString(16).padStart(4, '0')}`
223
- }
224
- return result
225
- }
226
-
227
- /**
228
- * Returns whether a key or variable name usually carries secret values.
229
- *
230
- * @param {string} name key or environment variable name
231
- */
232
- function isSensitiveName (name) {
233
- const normalized = name.replaceAll(/[-.]/g, '_')
234
- return SENSITIVE_NAME_PATTERN.test(normalized) ||
235
- SENSITIVE_AUTH_NAME_PATTERN.test(normalized) ||
236
- SENSITIVE_COOKIE_NAME_PATTERN.test(normalized) ||
237
- SENSITIVE_PASS_NAME_PATTERN.test(normalized) ||
238
- SENSITIVE_TOKEN_ALIAS_NAME_PATTERN.test(normalized)
239
- }
240
-
241
- function sanitizeValue (value, seen, key, depth) {
242
- if (typeof value === 'string') {
243
- if (key && isSensitiveName(key) && !SECRET_NAME_ONLY_KEYS.has(key)) return REDACTED
244
- return sanitizeString(value)
245
- }
246
-
247
- if (value === null || typeof value !== 'object') return value
248
- if (depth > MAX_SANITIZE_DEPTH) return TRUNCATED_NESTING
249
- if (seen.has(value)) return '[Circular]'
250
- seen.add(value)
251
-
252
- if (Array.isArray(value)) {
253
- const sanitized = sanitizeArray(value, seen, key, depth)
254
- seen.delete(value)
255
- return sanitized
256
- }
257
-
258
- if (key && ENV_CONTAINER_KEYS.has(key)) {
259
- const env = sanitizeEnv(value)
260
- seen.delete(value)
261
- return env || {}
262
- }
263
-
264
- const sanitized = {}
265
- for (const [entryKey, entryValue] of Object.entries(value)) {
266
- if (isSensitiveName(entryKey) && !SECRET_NAME_ONLY_KEYS.has(entryKey) &&
267
- typeof entryValue !== 'boolean') {
268
- sanitized[entryKey] = REDACTED
269
- continue
270
- }
271
- sanitized[entryKey] = sanitizeValue(entryValue, seen, entryKey, depth + 1)
272
- }
273
- seen.delete(value)
274
- return sanitized
275
- }
276
-
277
- /**
278
- * Redacts secret flag/value pairs in arrays such as argv before sanitizing nested values.
279
- *
280
- * @param {Array<unknown>} value array to sanitize
281
- * @param {WeakSet<object>} seen objects currently being sanitized
282
- * @param {string|undefined} key parent key
283
- * @param {number} depth current nesting depth
284
- * @returns {Array<unknown>} sanitized array
285
- */
286
- function sanitizeArray (value, seen, key, depth) {
287
- const sanitized = []
288
-
289
- for (let index = 0; index < value.length; index++) {
290
- const item = value[index]
291
- if (typeof item === 'string' && SECRET_FLAG_NAME_PATTERN.test(item) && index + 1 < value.length) {
292
- sanitized.push(sanitizeString(item))
293
- if (!isFlagToken(value[index + 1])) {
294
- sanitized.push(REDACTED)
295
- index++
296
- }
297
- continue
298
- }
299
-
300
- sanitized.push(sanitizeValue(item, seen, key, depth + 1))
301
- }
302
-
303
- return sanitized
304
- }
305
-
306
- function isFlagToken (value) {
307
- return typeof value === 'string' && /^-{1,2}\S/.test(value)
308
- }
309
-
310
- module.exports = {
311
- hasUnsafeExecutionCharacter,
312
- hasUnsafeInvisibleCharacter,
313
- isSensitiveName,
314
- sanitizeConsoleText,
315
- sanitizeEnv,
316
- sanitizeEnvValue,
317
- sanitizeForReport,
318
- sanitizeString,
319
- }