dd-trace 6.24.0 → 6.26.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 (352) hide show
  1. package/README.md +3 -0
  2. package/ci/cypress/support.js +2 -1
  3. package/ci/init.js +2 -22
  4. package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
  5. package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
  6. package/ci/vitest-no-worker-init-setup.mjs +729 -724
  7. package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
  8. package/ext/exporters.js +0 -1
  9. package/index.d.ts +105 -5
  10. package/initialize.mjs +5 -2
  11. package/package.json +41 -36
  12. package/packages/datadog-esbuild/index.js +16 -70
  13. package/packages/datadog-esbuild/src/log.js +2 -29
  14. package/packages/datadog-instrumentations/src/ai.js +6 -1
  15. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  16. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  17. package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
  18. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  19. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  20. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  21. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  22. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  23. package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
  24. package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
  25. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
  26. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  27. package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
  28. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  29. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  30. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
  33. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  34. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  35. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  36. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
  37. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
  38. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
  39. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  46. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  47. package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
  48. package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
  49. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
  50. package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
  51. package/packages/datadog-instrumentations/src/next.js +203 -26
  52. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  53. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  54. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  55. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  56. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  57. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  58. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  59. package/packages/datadog-instrumentations/src/router.js +35 -12
  60. package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
  61. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  62. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  63. package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
  64. package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
  65. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  66. package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
  67. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
  68. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
  69. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
  70. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
  71. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
  72. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
  73. package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
  74. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  75. package/packages/datadog-plugin-express/src/code_origin.js +2 -2
  76. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  77. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
  78. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
  79. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
  80. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  81. package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
  82. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  83. package/packages/datadog-plugin-http/src/client.js +34 -10
  84. package/packages/datadog-plugin-http2/src/client.js +40 -14
  85. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
  86. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
  87. package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
  88. package/packages/datadog-plugin-next/src/index.js +112 -14
  89. package/packages/datadog-plugin-postgres/src/index.js +118 -41
  90. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  91. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
  92. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
  93. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
  94. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  95. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  96. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  97. package/packages/datadog-plugin-undici/src/index.js +22 -7
  98. package/packages/datadog-plugin-vitest/src/index.js +3 -2
  99. package/packages/datadog-plugin-ws/src/close.js +3 -5
  100. package/packages/datadog-plugin-ws/src/producer.js +1 -4
  101. package/packages/datadog-plugin-ws/src/receiver.js +3 -5
  102. package/packages/datadog-plugin-ws/src/server.js +44 -13
  103. package/packages/datadog-turbopack/index.js +4 -28
  104. package/packages/datadog-turbopack/src/loader.js +14 -452
  105. package/packages/datadog-vite/index.js +537 -0
  106. package/packages/datadog-vite/src/log.js +5 -0
  107. package/packages/datadog-webpack/index.js +3 -55
  108. package/packages/datadog-webpack/src/log.js +2 -29
  109. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  110. package/packages/dd-trace/src/aiguard/index.js +1 -1
  111. package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
  112. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  113. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  114. package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
  115. package/packages/dd-trace/src/appsec/channels.js +7 -0
  116. package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
  117. package/packages/dd-trace/src/appsec/graphql.js +89 -7
  118. package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
  119. package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
  120. package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
  121. package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
  122. package/packages/dd-trace/src/appsec/index.js +6 -0
  123. package/packages/dd-trace/src/appsec/lambda.js +17 -17
  124. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
  125. package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
  126. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
  127. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
  128. package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
  129. package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
  130. package/packages/dd-trace/src/appsec/recommended.json +1358 -94
  131. package/packages/dd-trace/src/appsec/reporter.js +9 -0
  132. package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
  133. package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
  134. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  135. package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
  136. package/packages/dd-trace/src/appsec/waf/index.js +65 -6
  137. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
  138. package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
  139. package/packages/dd-trace/src/before-exit.js +32 -0
  140. package/packages/dd-trace/src/bootstrap.js +5 -3
  141. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  142. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  143. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  144. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  145. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  146. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  147. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  148. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  149. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  150. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  151. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  152. package/packages/dd-trace/src/config/defaults.js +5 -0
  153. package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
  154. package/packages/dd-trace/src/config/index.js +63 -31
  155. package/packages/dd-trace/src/config/parsers.js +44 -0
  156. package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
  157. package/packages/dd-trace/src/config/remote_config.js +2 -1
  158. package/packages/dd-trace/src/config/supported-configurations.json +172 -10
  159. package/packages/dd-trace/src/constants.js +1 -0
  160. package/packages/dd-trace/src/datastreams/fnv.js +27 -0
  161. package/packages/dd-trace/src/datastreams/pathway.js +113 -28
  162. package/packages/dd-trace/src/datastreams/processor.js +5 -4
  163. package/packages/dd-trace/src/debugger/config.js +1 -1
  164. package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
  165. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
  166. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  167. package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
  168. package/packages/dd-trace/src/debugger/index.js +2 -2
  169. package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
  170. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
  171. package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
  172. package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
  173. package/packages/dd-trace/src/exporter.js +0 -11
  174. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  175. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  176. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  177. package/packages/dd-trace/src/git_metadata.js +2 -1
  178. package/packages/dd-trace/src/id.js +1 -1
  179. package/packages/dd-trace/src/index.js +6 -3
  180. package/packages/dd-trace/src/lambda/facade.js +75 -0
  181. package/packages/dd-trace/src/lambda/handler.js +3 -41
  182. package/packages/dd-trace/src/lambda/index.js +38 -15
  183. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  184. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  185. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  186. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  187. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  188. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  189. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
  190. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
  191. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  192. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  193. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  194. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  195. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  196. package/packages/dd-trace/src/log/channels.js +4 -0
  197. package/packages/dd-trace/src/log/writer.js +6 -1
  198. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
  199. package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
  200. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  201. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  202. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  203. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  204. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  205. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  206. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  207. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  208. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  209. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  210. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  211. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  212. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  213. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  214. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  215. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  216. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  217. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  218. package/packages/dd-trace/src/plugin_manager.js +34 -7
  219. package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
  220. package/packages/dd-trace/src/plugins/index.js +8 -0
  221. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  222. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  223. package/packages/dd-trace/src/plugins/util/ci.js +52 -1
  224. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  225. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  226. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
  227. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  228. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  229. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  230. package/packages/dd-trace/src/plugins/util/test.js +92 -40
  231. package/packages/dd-trace/src/plugins/util/url.js +18 -7
  232. package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
  233. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  234. package/packages/dd-trace/src/process-tags/index.js +1 -1
  235. package/packages/dd-trace/src/profiler.js +74 -12
  236. package/packages/dd-trace/src/profiling/profiler.js +30 -2
  237. package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
  238. package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
  239. package/packages/dd-trace/src/profiling/remote-config.js +354 -0
  240. package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
  241. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  242. package/packages/dd-trace/src/propagation-hash/index.js +7 -0
  243. package/packages/dd-trace/src/proxy.js +46 -54
  244. package/packages/dd-trace/src/span_processor.js +20 -0
  245. package/packages/dd-trace/src/startup-log.js +8 -6
  246. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  247. package/packages/dd-trace/src/tracer.js +0 -2
  248. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  249. package/register.js +2 -1
  250. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  251. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  252. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  253. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  254. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  255. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  256. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  257. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  258. package/vendor/dist/@opentelemetry/core/LICENSE +220 -1
  259. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  260. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  261. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  262. package/vendor/dist/esquery/LICENSE +2 -0
  263. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  264. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  265. package/vendor/dist/jest-docblock/LICENSE +16 -0
  266. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  267. package/vendor/dist/limiter/LICENSE +2 -0
  268. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  269. package/vendor/dist/lru-cache/LICENSE +13 -0
  270. package/vendor/dist/meriyah/LICENSE +13 -0
  271. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  272. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  273. package/vendor/dist/pprof-format/LICENSE +13 -0
  274. package/vendor/dist/pprof-format/index.js +1 -1
  275. package/vendor/dist/protobufjs/LICENSE +219 -0
  276. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  277. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  278. package/vendor/dist/retry/LICENSE +2 -0
  279. package/vendor/dist/rfdc/LICENSE +2 -0
  280. package/vendor/dist/semifies/LICENSE +3 -1
  281. package/vendor/dist/shell-quote/LICENSE +3 -1
  282. package/vendor/dist/source-map/LICENSE +1 -0
  283. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  284. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  285. package/vendor/dist/ttl-set/LICENSE +28 -0
  286. package/vite.d.ts +7 -0
  287. package/vite.js +3 -0
  288. package/ci/diagnose.js +0 -2215
  289. package/ci/runbook.md +0 -299
  290. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  291. package/ci/test-optimization-validation/approval.js +0 -386
  292. package/ci/test-optimization-validation/artifact-id.js +0 -18
  293. package/ci/test-optimization-validation/blocker-category.js +0 -24
  294. package/ci/test-optimization-validation/bounded-json.js +0 -120
  295. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  296. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  297. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  298. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  299. package/ci/test-optimization-validation/cli.js +0 -954
  300. package/ci/test-optimization-validation/command-blocker.js +0 -377
  301. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  302. package/ci/test-optimization-validation/command-runner.js +0 -649
  303. package/ci/test-optimization-validation/environment.js +0 -88
  304. package/ci/test-optimization-validation/executable-approval.js +0 -47
  305. package/ci/test-optimization-validation/executable.js +0 -244
  306. package/ci/test-optimization-validation/execution-lock.js +0 -70
  307. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  308. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  309. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  310. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  311. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  312. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  313. package/ci/test-optimization-validation/generated-files.js +0 -425
  314. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  315. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  316. package/ci/test-optimization-validation/literal-environment.js +0 -56
  317. package/ci/test-optimization-validation/literal-glob.js +0 -52
  318. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  319. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  320. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  321. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  322. package/ci/test-optimization-validation/offline-output.js +0 -406
  323. package/ci/test-optimization-validation/package-check.js +0 -97
  324. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  325. package/ci/test-optimization-validation/plan-writer.js +0 -541
  326. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  327. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  328. package/ci/test-optimization-validation/redaction.js +0 -319
  329. package/ci/test-optimization-validation/report-writer.js +0 -666
  330. package/ci/test-optimization-validation/result-semantics.js +0 -103
  331. package/ci/test-optimization-validation/runner-command.js +0 -264
  332. package/ci/test-optimization-validation/runner-contract.js +0 -695
  333. package/ci/test-optimization-validation/safe-files.js +0 -202
  334. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  335. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  336. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  337. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  338. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  339. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  340. package/ci/test-optimization-validation/source-text.js +0 -84
  341. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  342. package/ci/test-optimization-validation/test-output.js +0 -120
  343. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  344. package/ci/validate-test-optimization.js +0 -3
  345. package/packages/datadog-esbuild/src/resolver.js +0 -284
  346. package/packages/datadog-esbuild/src/utils.js +0 -318
  347. package/packages/datadog-plugin-cypress/src/support.js +0 -1348
  348. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  349. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  350. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  351. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  352. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -1,767 +0,0 @@
1
- 'use strict'
2
-
3
- const fs = require('node:fs')
4
- const path = require('node:path')
5
-
6
- const { matchesLiteralGlob } = require('../literal-glob')
7
-
8
- const CUCUMBER_PACKAGE = '@cucumber/cucumber'
9
- const CONFIG_PATTERN = /^cucumber\.(?:[cm]?js|json|ya?ml)$/
10
- const MAX_CONFIG_BYTES = 512 * 1024
11
- const GENERATED_STEPS_FILENAME = 'dd-test-optimization-validation.steps.cjs'
12
- const ISOLATION_CONFIG_PATH = path.join(__dirname, 'cucumber-validation.json')
13
- const PROFILE_VALUE_OPTIONS = new Map([
14
- ['import', '--import'],
15
- ['language', '--language'],
16
- ['loader', '--loader'],
17
- ['parallel', '--parallel'],
18
- ['require', '--require'],
19
- ['requireModule', '--require-module'],
20
- ['worldParameters', '--world-parameters'],
21
- ])
22
- const PROFILE_FLAG_OPTIONS = new Map([
23
- ['backtrace', '--backtrace'],
24
- ['failFast', '--fail-fast'],
25
- ['strict', '--strict'],
26
- ])
27
- const OMITTED_PROFILE_KEYS = new Set([
28
- 'dryRun',
29
- 'forceExit',
30
- 'format',
31
- 'formatOptions',
32
- 'name',
33
- 'order',
34
- 'paths',
35
- 'publish',
36
- 'publishQuiet',
37
- 'retry',
38
- 'retryTagFilter',
39
- 'tags',
40
- ])
41
- const OMITTED_PROFILE_OPTIONS = new Map([
42
- ['-f', true],
43
- ['--dry-run', false],
44
- ['--exit', false],
45
- ['--force-exit', false],
46
- ['--format', true],
47
- ['--format-options', true],
48
- ['--name', true],
49
- ['--order', true],
50
- ['--publish', false],
51
- ['--publish-quiet', false],
52
- ['--retry', true],
53
- ['--retry-tag-filter', true],
54
- ['--tags', true],
55
- ['-t', true],
56
- ])
57
- const RETAINED_PROFILE_FLAGS = new Set(['--backtrace', '--fail-fast', '--no-strict', '--strict'])
58
- const RETAINED_PROFILE_VALUES = new Set([
59
- '-i',
60
- '-r',
61
- '--import',
62
- '--language',
63
- '--loader',
64
- '--parallel',
65
- '--require',
66
- '--require-module',
67
- '--world-parameters',
68
- ])
69
- const JAVASCRIPT_STRING_ESCAPES = Object.freeze({
70
- '"': '"',
71
- "'": "'",
72
- '/': '/',
73
- '\\': '\\',
74
- b: '\b',
75
- f: '\f',
76
- n: '\n',
77
- r: '\r',
78
- t: '\t',
79
- v: '\v',
80
- })
81
-
82
- /**
83
- * Reports whether the installed Cucumber CLI can bypass customer profiles with a validator-owned config.
84
- *
85
- * Cucumber 7 always loads cucumber.js from its working directory and has no --config option. Changing the working
86
- * directory would alter project test semantics, so those versions remain a validator limitation.
87
- *
88
- * @param {string|null|undefined} version installed Cucumber version
89
- */
90
- function supportsConfigIsolation (version) {
91
- const match = /^[v=]?(\d+)(?:\.|$)/.exec(String(version))
92
- return Boolean(match && Number(match[1]) >= 8)
93
- }
94
-
95
- /**
96
- * Reports whether a file follows the Cucumber feature convention.
97
- *
98
- * @param {string} filename candidate filename
99
- */
100
- function isTestFile (filename) {
101
- return filename.endsWith('.feature')
102
- }
103
-
104
- /**
105
- * Counts statically declared Cucumber scenarios in a feature.
106
- *
107
- * @param {string} source feature source
108
- */
109
- function getScenarioCount (source) {
110
- return [...source.matchAll(/^[ \t]*(?:Example|Scenario(?: Outline| Template)?):[ \t]*\S/gm)].length
111
- }
112
-
113
- /**
114
- * Returns validator-owned Cucumber feature source for one generated scenario.
115
- *
116
- * @param {object} input generated source input
117
- * @param {string} input.testName generated scenario name
118
- */
119
- function getGeneratedTestContent ({ testName }) {
120
- return [
121
- 'Feature: Datadog Test Optimization validation',
122
- '',
123
- ` Scenario: ${testName}`,
124
- ` Given the Datadog validation scenario ${JSON.stringify(testName)}`,
125
- ].join('\n')
126
- }
127
-
128
- /**
129
- * Returns the validator-owned Cucumber step definitions shared by generated scenarios.
130
- *
131
- */
132
- function getGeneratedStepsContent () {
133
- return [
134
- "'use strict'",
135
- '',
136
- `const { Given } = require(${JSON.stringify(CUCUMBER_PACKAGE)})`,
137
- '',
138
- 'let atrAttempt = 0',
139
- '',
140
- "Given('the Datadog validation scenario {string}', function (scenario) {",
141
- " if (scenario === 'atr-fail-once' && atrAttempt++ === 0) {",
142
- " throw new Error('dd-test-optimization-validation atr first failure')",
143
- ' }',
144
- '})',
145
- ].join('\n')
146
- }
147
-
148
- /**
149
- * Returns the generated Cucumber step-definition path for a feature directory.
150
- *
151
- * @param {string} testDirectory generated feature directory
152
- */
153
- function getGeneratedStepsPath (testDirectory) {
154
- return path.join(testDirectory, GENERATED_STEPS_FILENAME)
155
- }
156
-
157
- /**
158
- * Returns Cucumber arguments that select one existing feature.
159
- *
160
- * @param {string} filename selected Cucumber feature
161
- * @param {string} cwd project working directory
162
- * @returns {string[]} focused Cucumber arguments
163
- */
164
- function getFocusedTestArgs (filename, cwd) {
165
- return [...getIsolationArgs(cwd), filename, '--format', 'json']
166
- }
167
-
168
- /**
169
- * Returns Cucumber arguments for one isolated generated scenario.
170
- *
171
- * @param {string} filename generated Cucumber feature
172
- * @param {string} stepsFile generated Cucumber step definitions
173
- * @param {string} cwd project working directory
174
- * @returns {string[]} generated scenario arguments
175
- */
176
- function getGeneratedTestArgs (filename, stepsFile, cwd) {
177
- return [...getIsolationArgs(cwd), '--require', stepsFile, '--format', 'json', filename]
178
- }
179
-
180
- /**
181
- * Extracts the executed-scenario count from the final Cucumber summary.
182
- *
183
- * @param {string} output Cucumber output without ANSI escapes
184
- * @returns {number|null} final scenario count when present
185
- */
186
- function getObservedTestCount (output) {
187
- const jsonCount = getJsonScenarioCount(output)
188
- if (jsonCount !== null) return jsonCount
189
-
190
- let count = null
191
- for (const match of output.matchAll(/\b(\d+)\s+scenarios?\b/gi)) count = Number(match[1])
192
- return count
193
- }
194
-
195
- /**
196
- * Expands selected Cucumber profiles without loading customer JavaScript.
197
- *
198
- * Profile feature paths, filters, retries, publishing, and formatters are intentionally omitted. The validator
199
- * supplies one exact feature and a machine-readable formatter.
200
- *
201
- * @param {object} input profile inputs
202
- * @param {string[]} input.configFiles bounded Cucumber config files
203
- * @param {string} input.projectRoot project root
204
- * @param {string[]} input.projectFiles bounded project files
205
- * @param {string[]} input.runnerArgs retained command-line arguments
206
- * @returns {{error?: string, runnerArgs: string[]}} expanded profile arguments
207
- */
208
- function expandProfiles ({ configFiles, projectFiles, projectRoot, runnerArgs }) {
209
- const selectedProfiles = getOptionValues(runnerArgs, new Set(['-p', '--profile']))
210
- const explicitConfig = getOptionValues(runnerArgs, new Set(['--config']))[0]
211
- const explicitConfigFile = explicitConfig && getPhysicalPath(path.resolve(projectRoot, explicitConfig))
212
- const physicalProjectRoot = getPhysicalDirectory(projectRoot)
213
- const configFile = explicitConfig
214
- ? configFiles.find(filename => path.resolve(filename) === explicitConfigFile)
215
- : configFiles.find(filename =>
216
- path.dirname(filename) === physicalProjectRoot && CONFIG_PATTERN.test(path.basename(filename)))
217
- const directArgs = omitOptions(runnerArgs, new Set(['-p', '--config', '--profile']))
218
-
219
- if (explicitConfig && !configFile) {
220
- return {
221
- error: `explicit Cucumber config ${JSON.stringify(explicitConfig)} is not an approval-bound regular file`,
222
- runnerArgs: [],
223
- }
224
- }
225
- if (!configFile) return expandSupportPaths(directArgs, projectFiles, projectRoot)
226
-
227
- let definitions
228
- try {
229
- definitions = readProfileDefinitions(configFile)
230
- } catch (error) {
231
- return { error: `Cucumber configuration could not be expanded statically: ${error.message}`, runnerArgs: [] }
232
- }
233
-
234
- const profiles = selectedProfiles.length > 0 ? selectedProfiles : ['default']
235
- const expanded = []
236
- for (const profile of profiles) {
237
- const definition = definitions.get(profile)
238
- if (definition === undefined) {
239
- return {
240
- error: `Cucumber profile ${JSON.stringify(profile)} is not a static literal in ${path.basename(configFile)}`,
241
- runnerArgs: [],
242
- }
243
- }
244
- const parsed = getProfileArgs(definition)
245
- if (parsed.error) {
246
- return {
247
- error: `Cucumber profile ${JSON.stringify(profile)} ${parsed.error}`,
248
- runnerArgs: [],
249
- }
250
- }
251
- expanded.push(...parsed.args)
252
- }
253
- return expandSupportPaths([...expanded, ...directArgs], projectFiles, projectRoot)
254
- }
255
-
256
- function getIsolationArgs (cwd) {
257
- return ['--config', path.relative(cwd, ISOLATION_CONFIG_PATH)]
258
- }
259
-
260
- function readProfileDefinitions (filename) {
261
- const stat = fs.lstatSync(filename)
262
- if (!stat.isFile() || stat.isSymbolicLink()) {
263
- throw new Error('configuration must be a regular non-symbolic-link file')
264
- }
265
- if (stat.size > MAX_CONFIG_BYTES) {
266
- throw new Error(`configuration exceeds the ${MAX_CONFIG_BYTES}-byte limit`)
267
- }
268
- const source = fs.readFileSync(filename, 'utf8')
269
- const extension = path.extname(filename)
270
- if (extension === '.json') return getDataProfileDefinitions(JSON.parse(source))
271
- if (extension === '.yaml' || extension === '.yml') {
272
- return getYamlStringProfileDefinitions(source)
273
- }
274
- return getJavascriptProfileDefinitions(source)
275
- }
276
-
277
- function getJavascriptProfileDefinitions (source) {
278
- const syntax = maskJavascriptCommentsAndStrings(source)
279
- const exports = [...syntax.matchAll(
280
- /(?:^|\S[\t\v\f\p{Zs}\uFEFF]*[\n\r\u2028\u2029])\s*(?:module\s*\.\s*exports\s*=|export\s+default)\s*\{/gu
281
- )]
282
- if (exports.length === 0) return new Map()
283
- if (exports.length !== 1) throw new Error('configuration must export one literal profile object')
284
-
285
- const objectStart = exports[0].index + exports[0][0].lastIndexOf('{')
286
- const objectEnd = findClosingBrace(syntax, objectStart)
287
- if (objectEnd === -1) throw new Error('configuration contains an unterminated profile object')
288
- const definitions = new Map()
289
- let index = objectStart + 1
290
- while (index < objectEnd) {
291
- index = skipWhitespace(syntax, index)
292
- if (syntax[index] === ',') {
293
- index++
294
- continue
295
- }
296
- if (index >= objectEnd) break
297
-
298
- let name
299
- const quotedName = readQuotedString(source, index)
300
- if (quotedName) {
301
- name = quotedName.value
302
- index = quotedName.end
303
- } else {
304
- const identifier = /^[A-Za-z_$][\w$]*/.exec(syntax.slice(index))
305
- if (!identifier) throw new Error('profile names must be static literal properties')
306
- name = identifier[0]
307
- index += identifier[0].length
308
- }
309
-
310
- index = skipWhitespace(syntax, index)
311
- if (syntax[index] !== ':') throw new Error(`profile ${JSON.stringify(name)} must have a literal value`)
312
- index = skipWhitespace(syntax, index + 1)
313
- const definition = readJavascriptLiteral(source, syntax, index)
314
- if (!definition || (typeof definition.value !== 'string' &&
315
- (!definition.value || typeof definition.value !== 'object' || Array.isArray(definition.value)))) {
316
- throw new Error(`profile ${JSON.stringify(name)} must be a literal string or object`)
317
- }
318
- definitions.set(name, definition.value)
319
- index = skipWhitespace(syntax, definition.end)
320
- if (index < objectEnd && syntax[index] !== ',') {
321
- throw new Error(`profile ${JSON.stringify(name)} must be followed by a comma`)
322
- }
323
- }
324
- if (!/^[\s;]*$/.test(syntax.slice(objectEnd + 1))) {
325
- throw new Error('configuration contains code after the exported profile object')
326
- }
327
- return definitions
328
- }
329
-
330
- function maskJavascriptCommentsAndStrings (source) {
331
- const syntax = [...source]
332
- let quote
333
- let lineComment = false
334
- let blockComment = false
335
- for (let index = 0; index < source.length; index++) {
336
- const character = source[index]
337
- const next = source[index + 1]
338
- if (lineComment) {
339
- if (character === '\n') lineComment = false
340
- else syntax[index] = ' '
341
- continue
342
- }
343
- if (blockComment) {
344
- syntax[index] = ' '
345
- if (character === '*' && next === '/') {
346
- syntax[++index] = ' '
347
- blockComment = false
348
- }
349
- continue
350
- }
351
- if (quote) {
352
- if (character === '\\') {
353
- syntax[index] = ' '
354
- if (index + 1 < source.length) syntax[++index] = ' '
355
- } else if (character === quote) {
356
- quote = undefined
357
- } else {
358
- syntax[index] = ' '
359
- }
360
- continue
361
- }
362
- if (character === '/' && next === '/') {
363
- syntax[index] = syntax[++index] = ' '
364
- lineComment = true
365
- } else if (character === '/' && next === '*') {
366
- syntax[index] = syntax[++index] = ' '
367
- blockComment = true
368
- } else if (character === '"' || character === "'" || character === '`') {
369
- quote = character
370
- }
371
- }
372
- return syntax.join('')
373
- }
374
-
375
- function findClosingBrace (source, start) {
376
- let depth = 0
377
- for (let index = start; index < source.length; index++) {
378
- if (source[index] === '{') depth++
379
- else if (source[index] === '}' && --depth === 0) return index
380
- }
381
- return -1
382
- }
383
-
384
- function skipWhitespace (source, start) {
385
- let index = start
386
- while (/\s/.test(source[index] || '')) index++
387
- return index
388
- }
389
-
390
- /**
391
- * Reads a bounded JSON-shaped JavaScript literal without evaluating customer code.
392
- *
393
- * @param {string} source original JavaScript source
394
- * @param {string} syntax source with comments and string contents masked
395
- * @param {number} start literal start offset
396
- * @param {number} [depth] current literal nesting depth
397
- * @returns {{end: number, value: unknown}|undefined} parsed literal and ending offset
398
- */
399
- function readJavascriptLiteral (source, syntax, start, depth = 0) {
400
- if (depth > 16) return
401
- let index = skipWhitespace(syntax, start)
402
- const quoted = readQuotedString(source, index)
403
- if (quoted) return quoted
404
-
405
- const primitive = /^(true|false|null|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)(?![\w$.])/.exec(
406
- syntax.slice(index)
407
- )
408
- if (primitive) {
409
- const values = { false: false, null: null, true: true }
410
- const value = Object.hasOwn(values, primitive[1]) ? values[primitive[1]] : Number(primitive[1])
411
- if (typeof value === 'number' && (!Number.isFinite(value) || Object.is(value, -0))) return
412
- return {
413
- end: index + primitive[0].length,
414
- value,
415
- }
416
- }
417
-
418
- const open = syntax[index]
419
- if (open !== '[' && open !== '{') return
420
- const close = open === '[' ? ']' : '}'
421
- const value = open === '[' ? [] : Object.create(null)
422
- index++
423
- while (index < syntax.length) {
424
- index = skipWhitespace(syntax, index)
425
- if (syntax[index] === close) return { end: index + 1, value }
426
-
427
- let item
428
- if (open === '[') {
429
- item = readJavascriptLiteral(source, syntax, index, depth + 1)
430
- if (!item) return
431
- value.push(item.value)
432
- } else {
433
- const property = readJavascriptPropertyName(source, syntax, index)
434
- if (!property || property.value === '__proto__' || Object.hasOwn(value, property.value)) return
435
- index = skipWhitespace(syntax, property.end)
436
- if (syntax[index] !== ':') return
437
- item = readJavascriptLiteral(source, syntax, index + 1, depth + 1)
438
- if (!item) return
439
- value[property.value] = item.value
440
- }
441
- index = item.end
442
-
443
- index = skipWhitespace(syntax, index)
444
- if (syntax[index] === close) return { end: index + 1, value }
445
- if (syntax[index] !== ',') return
446
- index++
447
- }
448
- }
449
-
450
- /**
451
- * Reads one static quoted or identifier JavaScript object property name.
452
- *
453
- * @param {string} source original JavaScript source
454
- * @param {string} syntax source with comments and string contents masked
455
- * @param {number} start property start offset
456
- * @returns {{end: number, value: string}|undefined} property name and ending offset
457
- */
458
- function readJavascriptPropertyName (source, syntax, start) {
459
- const index = skipWhitespace(syntax, start)
460
- const quoted = readQuotedString(source, index)
461
- if (quoted) return quoted
462
- const identifier = /^[A-Za-z_$][\w$]*/.exec(syntax.slice(index))
463
- if (identifier) return { end: index + identifier[0].length, value: identifier[0] }
464
- }
465
-
466
- function getDataProfileDefinitions (value) {
467
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
468
- throw new Error('configuration must contain a profile object')
469
- }
470
- return new Map(Object.entries(value))
471
- }
472
-
473
- function getYamlStringProfileDefinitions (source) {
474
- const definitions = new Map()
475
- for (const line of source.split(/\r?\n/)) {
476
- if (!line.trim() || /^\s*#/.test(line)) continue
477
- const match = /^([A-Za-z0-9_-]+):(.*)$/.exec(line)
478
- const definition = match && !/^\s/.test(line) ? getYamlStringProfileDefinition(match[2]) : undefined
479
- if (definition === undefined) {
480
- throw new Error('YAML profiles must be literal one-line command strings')
481
- }
482
- definitions.set(match[1], definition)
483
- }
484
- return definitions
485
- }
486
-
487
- function getYamlStringProfileDefinition (source) {
488
- const value = source.trimStart()
489
- const quote = value[0]
490
- if (quote !== '"' && quote !== "'") {
491
- const comment = /[ \t]#/.exec(value)
492
- const definition = value.slice(0, comment?.index ?? value.length).trimEnd()
493
- return definition || undefined
494
- }
495
-
496
- let definition = ''
497
- for (let index = 1; index < value.length; index++) {
498
- const character = value[index]
499
- if (quote === '"' && character === '\\') {
500
- return
501
- }
502
- if (quote === "'" && character === quote && value[index + 1] === quote) {
503
- definition += quote
504
- index++
505
- continue
506
- }
507
- if (character !== quote) {
508
- definition += character
509
- continue
510
- }
511
- const remainder = value.slice(index + 1)
512
- if (!remainder.trim() || /^\s+#/.test(remainder)) return definition
513
- return
514
- }
515
- }
516
-
517
- function readQuotedString (source, start) {
518
- const quote = source[start]
519
- if (quote !== '"' && quote !== "'") return
520
- let value = ''
521
- let index = start + 1
522
- while (index < source.length) {
523
- const character = source[index]
524
- if (character === quote) return { end: index + 1, value }
525
- if (character === '\r' || character === '\n') return
526
- if (character !== '\\') {
527
- value += character
528
- index++
529
- continue
530
- }
531
- const escaped = readJavascriptStringEscape(source, index + 1)
532
- if (!escaped) return
533
- value += escaped.value
534
- index = escaped.end
535
- }
536
- }
537
-
538
- /**
539
- * Decodes one bounded JavaScript string escape without evaluating source.
540
- *
541
- * @param {string} source original JavaScript source
542
- * @param {number} start first character after the backslash
543
- * @returns {{end: number, value: string}|undefined} decoded character and ending offset
544
- */
545
- function readJavascriptStringEscape (source, start) {
546
- const escaped = source[start]
547
- if (Object.hasOwn(JAVASCRIPT_STRING_ESCAPES, escaped)) {
548
- return { end: start + 1, value: JAVASCRIPT_STRING_ESCAPES[escaped] }
549
- }
550
- if (escaped === '\n') return { end: start + 1, value: '' }
551
- if (escaped === '\r') {
552
- return { end: source[start + 1] === '\n' ? start + 2 : start + 1, value: '' }
553
- }
554
-
555
- if (escaped === 'x') {
556
- const hexadecimal = source.slice(start + 1, start + 3)
557
- if (/^[\da-fA-F]{2}$/.test(hexadecimal)) {
558
- return { end: start + 3, value: String.fromCharCode(Number.parseInt(hexadecimal, 16)) }
559
- }
560
- return
561
- }
562
- if (escaped !== 'u') return
563
-
564
- if (source[start + 1] === '{') {
565
- const match = /^\{([\da-fA-F]{1,6})\}/.exec(source.slice(start + 1))
566
- if (!match) return
567
- const codePoint = Number.parseInt(match[1], 16)
568
- if (codePoint > 1_114_111) return
569
- return { end: start + 1 + match[0].length, value: String.fromCodePoint(codePoint) }
570
- }
571
-
572
- const hexadecimal = source.slice(start + 1, start + 5)
573
- if (/^[\da-fA-F]{4}$/.test(hexadecimal)) {
574
- return { end: start + 5, value: String.fromCharCode(Number.parseInt(hexadecimal, 16)) }
575
- }
576
- }
577
-
578
- function getProfileArgs (definition) {
579
- if (typeof definition === 'string') return getStringProfileArgs(definition)
580
- if (!definition || typeof definition !== 'object' || Array.isArray(definition)) {
581
- return { error: 'must be a literal string or object', args: [] }
582
- }
583
-
584
- const args = []
585
- for (const [key, value] of Object.entries(definition)) {
586
- if (OMITTED_PROFILE_KEYS.has(key)) continue
587
- const flag = PROFILE_FLAG_OPTIONS.get(key)
588
- if (flag) {
589
- if (typeof value !== 'boolean') return { error: `contains non-boolean ${key}`, args: [] }
590
- if (key === 'strict') args.push(value ? '--strict' : '--no-strict')
591
- else if (value) args.push(flag)
592
- continue
593
- }
594
- const option = PROFILE_VALUE_OPTIONS.get(key)
595
- if (!option) return { error: `contains unsupported option ${key}`, args: [] }
596
-
597
- if (key === 'worldParameters') {
598
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
599
- return { error: 'contains non-object worldParameters', args: [] }
600
- }
601
- args.push(option, JSON.stringify(value))
602
- continue
603
- }
604
-
605
- const values = Array.isArray(value) ? value : [value]
606
- for (const item of values) {
607
- if (item !== null && typeof item === 'object') {
608
- return { error: `contains unsupported object value for ${key}`, args: [] }
609
- }
610
- args.push(option, String(item))
611
- }
612
- }
613
- return { args }
614
- }
615
-
616
- function getStringProfileArgs (definition) {
617
- const tokens = tokenizeProfile(definition)
618
- if (!tokens) return { error: 'contains shell control syntax or unbalanced quoting', args: [] }
619
-
620
- const args = []
621
- for (let index = 0; index < tokens.length; index++) {
622
- const token = tokens[index]
623
- if (!token.startsWith('-')) continue
624
- const option = token.split('=', 1)[0]
625
- if (RETAINED_PROFILE_FLAGS.has(option)) {
626
- args.push(token)
627
- continue
628
- }
629
- if (RETAINED_PROFILE_VALUES.has(option)) {
630
- const value = token.includes('=') ? token.slice(token.indexOf('=') + 1) : tokens[++index]
631
- if (!value || value.startsWith('-')) return { error: `has a missing value for ${option}`, args: [] }
632
- args.push(option, value)
633
- continue
634
- }
635
- if (OMITTED_PROFILE_OPTIONS.has(option)) {
636
- if (OMITTED_PROFILE_OPTIONS.get(option) && !token.includes('=')) index++
637
- continue
638
- }
639
- return { error: `contains unsupported option ${option}`, args: [] }
640
- }
641
- return { args }
642
- }
643
-
644
- function tokenizeProfile (source) {
645
- if (/[\0\r\n;&|`]|\$\(|\$\{/.test(source)) return
646
- const tokens = []
647
- const pattern = /"([^"\r\n]*)"|'([^'\r\n]*)'|([^\s"']+)/g
648
- let consumed = 0
649
- for (const match of source.matchAll(pattern)) {
650
- if (source.slice(consumed, match.index).trim()) return
651
- tokens.push(match[1] ?? match[2] ?? match[3])
652
- consumed = match.index + match[0].length
653
- }
654
- if (source.slice(consumed).trim()) return
655
- return tokens
656
- }
657
-
658
- function getOptionValues (args, options) {
659
- const values = []
660
- for (let index = 0; index < args.length; index++) {
661
- const option = args[index].split('=', 1)[0]
662
- if (!options.has(option)) continue
663
- values.push(args[index].includes('=') ? args[index].slice(args[index].indexOf('=') + 1) : args[++index])
664
- }
665
- return values.filter(Boolean)
666
- }
667
-
668
- function getPhysicalPath (filename) {
669
- try {
670
- return fs.realpathSync(filename)
671
- } catch {}
672
- }
673
-
674
- function omitOptions (args, options) {
675
- const retained = []
676
- for (let index = 0; index < args.length; index++) {
677
- const option = args[index].split('=', 1)[0]
678
- if (!options.has(option)) {
679
- retained.push(args[index])
680
- continue
681
- }
682
- if (!args[index].includes('=')) index++
683
- }
684
- return retained
685
- }
686
-
687
- function expandSupportPaths (args, projectFiles, projectRoot) {
688
- const expanded = []
689
- const pathOptions = new Set(['-i', '-r', '--import', '--require'])
690
- const aliases = { '-i': '--import', '-r': '--require' }
691
- for (let index = 0; index < args.length; index++) {
692
- const option = args[index].split('=', 1)[0]
693
- if (!pathOptions.has(option)) {
694
- expanded.push(args[index])
695
- continue
696
- }
697
-
698
- const value = args[index].includes('=') ? args[index].slice(args[index].indexOf('=') + 1) : args[++index]
699
- const matches = getSupportPathMatches(value, projectFiles, projectRoot)
700
- if (matches.length === 0) {
701
- return {
702
- error: `Cucumber support path ${JSON.stringify(value)} does not match a repository-contained file`,
703
- runnerArgs: [],
704
- }
705
- }
706
- for (const filename of matches) expanded.push(aliases[option] || option, filename)
707
- }
708
- return { runnerArgs: expanded }
709
- }
710
-
711
- function getSupportPathMatches (value, projectFiles, projectRoot) {
712
- const normalized = String(value || '').replaceAll('\\', '/')
713
- const candidate = path.resolve(projectRoot, value)
714
- try {
715
- if (fs.statSync(candidate).isFile()) return [candidate]
716
- if (fs.statSync(candidate).isDirectory()) {
717
- return projectFiles.filter(filename => {
718
- const relative = path.relative(candidate, filename)
719
- return relative && !relative.startsWith('..') && !path.isAbsolute(relative) &&
720
- /\.[cm]?[jt]s$/.test(filename)
721
- }).sort()
722
- }
723
- } catch {}
724
- if (!/[*?[\]{}]/.test(normalized)) return []
725
- return projectFiles.filter(filename => {
726
- return matchesLiteralGlob(path.relative(projectRoot, filename), normalized)
727
- }).sort()
728
- }
729
-
730
- function getJsonScenarioCount (output) {
731
- const source = output.trim()
732
- const end = source.lastIndexOf(']')
733
- if (end === -1) return null
734
- let attempts = 0
735
- for (let start = source.indexOf('['); start !== -1 && start < end && attempts < 20;
736
- start = source.indexOf('[', start + 1), attempts++) {
737
- try {
738
- const features = JSON.parse(source.slice(start, end + 1))
739
- if (!Array.isArray(features)) continue
740
- return features.reduce((count, feature) => {
741
- return count + (feature.elements || []).filter(element => element.type === 'scenario').length
742
- }, 0)
743
- } catch {}
744
- }
745
- return null
746
- }
747
-
748
- function getPhysicalDirectory (directory) {
749
- try {
750
- const physical = fs.realpathSync(directory)
751
- if (fs.statSync(physical).isDirectory()) return physical
752
- } catch {}
753
- }
754
-
755
- module.exports = {
756
- CONFIG_PATTERN,
757
- expandProfiles,
758
- getFocusedTestArgs,
759
- getGeneratedStepsContent,
760
- getGeneratedStepsPath,
761
- getGeneratedTestArgs,
762
- getGeneratedTestContent,
763
- getObservedTestCount,
764
- getScenarioCount,
765
- isTestFile,
766
- supportsConfigIsolation,
767
- }