dd-trace 5.134.0 → 5.136.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 (353) hide show
  1. package/LICENSE-3rdparty.csv +0 -1
  2. package/ci/cypress/support.js +15 -1
  3. package/ci/init.js +2 -22
  4. package/ci/test-annotations.d.ts +5 -0
  5. package/ci/test-annotations.js +5 -0
  6. package/ci/vitest-no-worker-init-annotations.mjs +4 -0
  7. package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
  8. package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
  9. package/ci/vitest-no-worker-init-setup.mjs +34 -12
  10. package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
  11. package/ext/exporters.js +1 -1
  12. package/index.d.ts +124 -5
  13. package/initialize.mjs +5 -2
  14. package/lambda.d.ts +39 -0
  15. package/lambda.js +3 -0
  16. package/loader-hook.mjs +53 -0
  17. package/openfeature/exposure-hook.d.ts +66 -0
  18. package/openfeature/exposure-hook.js +5 -0
  19. package/package.json +19 -15
  20. package/packages/datadog-core/src/storage.js +1 -1
  21. package/packages/datadog-esbuild/index.js +78 -62
  22. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  23. package/packages/datadog-instrumentations/src/cucumber.js +56 -19
  24. package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
  25. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  26. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  27. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  28. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  29. package/packages/datadog-instrumentations/src/graphql.js +29 -20
  30. package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
  31. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  32. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  33. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  34. package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
  35. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
  36. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  37. package/packages/datadog-instrumentations/src/helpers/hooks.js +4 -8
  38. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  39. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +18 -6
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  46. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  47. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
  48. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  49. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
  50. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
  51. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +58 -0
  52. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
  53. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +25 -3
  54. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  55. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  56. package/packages/datadog-instrumentations/src/jest.js +265 -82
  57. package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
  58. package/packages/datadog-instrumentations/src/mariadb.js +13 -6
  59. package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
  60. package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
  61. package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
  62. package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
  63. package/packages/datadog-instrumentations/src/next.js +19 -6
  64. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  65. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  66. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  67. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  68. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  69. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  70. package/packages/datadog-instrumentations/src/oracledb.js +33 -0
  71. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  72. package/packages/datadog-instrumentations/src/pg.js +2 -1
  73. package/packages/datadog-instrumentations/src/playwright.js +81 -28
  74. package/packages/datadog-instrumentations/src/react-router.js +106 -0
  75. package/packages/datadog-instrumentations/src/typesafe.js +89 -0
  76. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
  77. package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
  78. package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
  79. package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
  80. package/packages/datadog-instrumentations/src/vitest.js +10 -8
  81. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  82. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  83. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  84. package/packages/datadog-plugin-cucumber/src/index.js +5 -0
  85. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +296 -55
  86. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  87. package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
  88. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  89. package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
  90. package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
  91. package/packages/datadog-plugin-cypress/src/support.js +1217 -439
  92. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  93. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  94. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  95. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  96. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  97. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  98. package/packages/datadog-plugin-graphql/src/utils.js +5 -5
  99. package/packages/datadog-plugin-http/src/client.js +32 -9
  100. package/packages/datadog-plugin-http2/src/client.js +38 -13
  101. package/packages/datadog-plugin-jest/src/index.js +25 -3
  102. package/packages/datadog-plugin-mocha/src/index.js +47 -6
  103. package/packages/datadog-plugin-next/src/index.js +112 -14
  104. package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
  105. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  106. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  107. package/packages/datadog-plugin-react-router/src/index.js +118 -0
  108. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  109. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  110. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  111. package/packages/datadog-plugin-typesafe/src/index.js +17 -0
  112. package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
  113. package/packages/datadog-plugin-undici/src/index.js +22 -7
  114. package/packages/datadog-plugin-vitest/src/index.js +8 -0
  115. package/packages/datadog-turbopack/index.js +4 -28
  116. package/packages/datadog-turbopack/src/loader.js +14 -452
  117. package/packages/datadog-webpack/index.js +3 -55
  118. package/packages/dd-trace/src/agent/info.js +2 -1
  119. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  120. package/packages/dd-trace/src/aiguard/sdk.js +8 -13
  121. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  122. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  123. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  124. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  125. package/packages/dd-trace/src/before-exit.js +32 -0
  126. package/packages/dd-trace/src/bootstrap.js +5 -3
  127. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +24 -18
  128. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +16 -36
  129. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  130. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  131. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +10 -18
  132. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +10 -15
  133. package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
  134. package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
  135. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  136. package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
  137. package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
  138. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +10 -17
  139. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  140. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  141. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  142. package/packages/dd-trace/src/config/defaults.js +9 -3
  143. package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -2
  144. package/packages/dd-trace/src/config/index.js +111 -43
  145. package/packages/dd-trace/src/config/parsers.js +18 -1
  146. package/packages/dd-trace/src/config/supported-configurations.json +174 -4
  147. package/packages/dd-trace/src/constants.js +1 -0
  148. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  149. package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
  150. package/packages/dd-trace/src/encode/0.4.js +2 -2
  151. package/packages/dd-trace/src/esm-module-load.js +58 -0
  152. package/packages/dd-trace/src/exporter.js +23 -15
  153. package/packages/dd-trace/src/exporters/agent/index.js +3 -1
  154. package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
  155. package/packages/dd-trace/src/exporters/common/request.js +83 -50
  156. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  157. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  158. package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
  159. package/packages/dd-trace/src/exporters/log/index.js +4 -3
  160. package/packages/dd-trace/src/id.js +1 -1
  161. package/packages/dd-trace/src/lambda/facade.js +74 -0
  162. package/packages/dd-trace/src/lambda/handler.js +3 -41
  163. package/packages/dd-trace/src/lambda/index.js +38 -15
  164. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  165. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  166. package/packages/dd-trace/src/llmobs/constants/tags.js +3 -0
  167. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  168. package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
  169. package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
  170. package/packages/dd-trace/src/llmobs/index.js +13 -2
  171. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  172. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  173. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  174. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +27 -10
  175. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  176. package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
  177. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  178. package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
  179. package/packages/dd-trace/src/llmobs/sdk.js +21 -1
  180. package/packages/dd-trace/src/llmobs/span_processor.js +219 -12
  181. package/packages/dd-trace/src/llmobs/tagger.js +25 -0
  182. package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
  183. package/packages/dd-trace/src/log/channels.js +4 -0
  184. package/packages/dd-trace/src/log/writer.js +13 -2
  185. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +68 -6
  186. package/packages/dd-trace/src/openfeature/configuration_source.js +41 -17
  187. package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
  188. package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
  189. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  190. package/packages/dd-trace/src/openfeature/flagging_provider.js +58 -14
  191. package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
  192. package/packages/dd-trace/src/openfeature/writers/base.js +63 -30
  193. package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
  194. package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
  195. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
  196. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
  197. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
  198. package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
  199. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  200. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  201. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  202. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  203. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  204. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
  205. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  206. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  207. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  208. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  209. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  210. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  211. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  212. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
  213. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  214. package/packages/dd-trace/src/opentracing/tracer.js +33 -13
  215. package/packages/dd-trace/src/otel-thread-ctx.js +72 -49
  216. package/packages/dd-trace/src/plugin_manager.js +34 -7
  217. package/packages/dd-trace/src/plugins/ci_plugin.js +45 -14
  218. package/packages/dd-trace/src/plugins/index.js +9 -0
  219. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  220. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  221. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  222. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  223. package/packages/dd-trace/src/plugins/util/git.js +273 -86
  224. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +77 -50
  225. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  226. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  227. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  228. package/packages/dd-trace/src/plugins/util/test.js +90 -45
  229. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  230. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  231. package/packages/dd-trace/src/plugins/util/web.js +81 -10
  232. package/packages/dd-trace/src/process-tags/index.js +1 -1
  233. package/packages/dd-trace/src/profiling/config.js +6 -3
  234. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  235. package/packages/dd-trace/src/proxy.js +48 -57
  236. package/packages/dd-trace/src/serverless.js +3 -2
  237. package/packages/dd-trace/src/span_processor.js +41 -9
  238. package/packages/dd-trace/src/span_stats.js +28 -2
  239. package/packages/dd-trace/src/startup-log.js +8 -5
  240. package/packages/dd-trace/src/tagger.js +7 -5
  241. package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
  242. package/packages/dd-trace/src/telemetry/index.js +3 -0
  243. package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
  244. package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
  245. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  246. package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
  247. package/packages/dd-trace/src/tracer.js +0 -2
  248. package/packages/dd-trace/src/util.js +1 -1
  249. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  250. package/register.js +4 -2
  251. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  252. package/vendor/dist/{@opentelemetry/resources → @datadog/flagging-core}/LICENSE +22 -2
  253. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  254. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  255. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  256. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  257. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
  258. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
  259. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  260. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  261. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  262. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  263. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  264. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  265. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  266. package/vendor/dist/esquery/LICENSE +2 -0
  267. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  268. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  269. package/vendor/dist/jest-docblock/LICENSE +16 -0
  270. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  271. package/vendor/dist/limiter/LICENSE +2 -0
  272. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  273. package/vendor/dist/lru-cache/LICENSE +13 -0
  274. package/vendor/dist/meriyah/LICENSE +13 -0
  275. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  276. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  277. package/vendor/dist/pprof-format/LICENSE +13 -0
  278. package/vendor/dist/pprof-format/index.js +1 -1
  279. package/vendor/dist/protobufjs/LICENSE +219 -0
  280. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  281. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  282. package/vendor/dist/retry/LICENSE +2 -0
  283. package/vendor/dist/rfdc/LICENSE +2 -0
  284. package/vendor/dist/semifies/LICENSE +3 -1
  285. package/vendor/dist/shell-quote/LICENSE +3 -1
  286. package/vendor/dist/source-map/LICENSE +1 -0
  287. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  288. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  289. package/vendor/dist/ttl-set/LICENSE +28 -0
  290. package/ci/diagnose.js +0 -2215
  291. package/ci/runbook.md +0 -299
  292. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  293. package/ci/test-optimization-validation/approval.js +0 -386
  294. package/ci/test-optimization-validation/artifact-id.js +0 -19
  295. package/ci/test-optimization-validation/blocker-category.js +0 -24
  296. package/ci/test-optimization-validation/bounded-json.js +0 -120
  297. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  298. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  299. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  300. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  301. package/ci/test-optimization-validation/cli.js +0 -954
  302. package/ci/test-optimization-validation/command-blocker.js +0 -377
  303. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  304. package/ci/test-optimization-validation/command-runner.js +0 -650
  305. package/ci/test-optimization-validation/environment.js +0 -88
  306. package/ci/test-optimization-validation/executable-approval.js +0 -47
  307. package/ci/test-optimization-validation/executable.js +0 -244
  308. package/ci/test-optimization-validation/execution-lock.js +0 -70
  309. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  310. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  311. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  312. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  313. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  314. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  315. package/ci/test-optimization-validation/generated-files.js +0 -425
  316. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  317. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  318. package/ci/test-optimization-validation/literal-environment.js +0 -56
  319. package/ci/test-optimization-validation/literal-glob.js +0 -52
  320. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  321. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  322. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  323. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  324. package/ci/test-optimization-validation/offline-output.js +0 -406
  325. package/ci/test-optimization-validation/package-check.js +0 -97
  326. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  327. package/ci/test-optimization-validation/plan-writer.js +0 -541
  328. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  329. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  330. package/ci/test-optimization-validation/redaction.js +0 -319
  331. package/ci/test-optimization-validation/report-writer.js +0 -666
  332. package/ci/test-optimization-validation/result-semantics.js +0 -103
  333. package/ci/test-optimization-validation/runner-command.js +0 -264
  334. package/ci/test-optimization-validation/runner-contract.js +0 -695
  335. package/ci/test-optimization-validation/safe-files.js +0 -202
  336. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  337. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  338. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  339. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  340. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  341. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  342. package/ci/test-optimization-validation/source-text.js +0 -84
  343. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  344. package/ci/test-optimization-validation/test-output.js +0 -120
  345. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  346. package/ci/validate-test-optimization.js +0 -3
  347. package/packages/datadog-esbuild/src/resolver.js +0 -284
  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
  353. package/vendor/dist/@opentelemetry/resources/index.js +0 -1
@@ -1,695 +0,0 @@
1
- 'use strict'
2
-
3
- const fs = require('node:fs')
4
- const path = require('node:path')
5
-
6
- const { environmentNamesEqual, setEnvironmentValue } = require('./environment')
7
-
8
- const RUNNER_OPTIONS = {
9
- cucumber: {
10
- flags: new Set(['--backtrace', '--fail-fast', '--no-strict', '--strict']),
11
- values: new Set([
12
- '-p', '--config', '--import', '--language', '--loader', '--profile', '--require', '--require-module',
13
- '--parallel', '--world-parameters',
14
- ]),
15
- },
16
- cypress: {
17
- flags: new Set(['--component', '--e2e', '--headed', '--headless']),
18
- values: new Set(['--browser', '--config-file']),
19
- },
20
- jest: {
21
- flags: new Set(['--color', '--colors', '--detectLeaks']),
22
- values: new Set(['-c', '--config', '--env', '--runner', '--testEnvironment']),
23
- },
24
- mocha: {
25
- flags: new Set(['--check-leaks', '--enable-source-maps']),
26
- values: new Set(['-r', '-t', '-u', '--config', '--extension', '--loader', '--require', '--timeout', '--ui']),
27
- },
28
- playwright: {
29
- flags: new Set(),
30
- values: new Set(['-c', '--config', '--project']),
31
- },
32
- vitest: {
33
- flags: new Set(['--browser']),
34
- values: new Set(['--config', '--environment', '--project', '--root']),
35
- },
36
- }
37
- const IGNORED_RUNNER_OPTIONS = {
38
- mocha: {
39
- flags: new Set(),
40
- values: new Set(['-R', '--reporter']),
41
- },
42
- }
43
- const OMITTED_RUNNER_OPTIONS = {
44
- vitest: new Set(['--run', '--typecheck']),
45
- }
46
- const SOURCE_SELECTOR_OPTIONS = {
47
- cypress: new Set(['--spec']),
48
- }
49
- const RUNNER_ENVIRONMENT_NAMES = new Set([
50
- 'BABEL_ENV',
51
- 'CI',
52
- 'NODE_ENV',
53
- 'TS_NODE_PROJECT',
54
- 'TZ',
55
- ])
56
- const RUNNER_LAUNCHERS = new Set(['c8', 'cross-env', 'env', 'npx', 'nyc', 'node'])
57
- const MODULE_OPTIONS = new Set([
58
- '-r',
59
- '-u',
60
- '--env',
61
- '--environment',
62
- '--import',
63
- '--loader',
64
- '--require',
65
- '--require-module',
66
- '--runner',
67
- '--testEnvironment',
68
- '--ui',
69
- ])
70
- const FILE_OPTIONS = new Set(['-c', '--config', '--config-file'])
71
- const DIRECTORY_OPTIONS = new Set(['--root'])
72
- const UNSUPPORTED_CONFIGURATION_OPTIONS = {
73
- cypress: new Set(['--config']),
74
- jest: new Set(['--projects']),
75
- mocha: new Set(['--config']),
76
- }
77
- const BUILTIN_MODULE_VALUES = new Map([
78
- ['-u', new Set(['bdd', 'exports', 'qunit', 'tdd'])],
79
- ['--env', new Set(['node'])],
80
- ['--environment', new Set(['node'])],
81
- ['--testEnvironment', new Set(['node'])],
82
- ['--ui', new Set(['bdd', 'exports', 'qunit', 'tdd'])],
83
- ])
84
- const CONTROL_PATTERN = /[\0\r\n;&|`]|\$\(|\$\{/
85
- const ENVIRONMENT_EXPANSION_PATTERN = /\$|%[^%]+%|![^!]+!/
86
-
87
- /**
88
- * Extracts bounded runner configuration from a detected package script.
89
- *
90
- * @param {string} framework framework name
91
- * @param {string} command detected package script
92
- * @param {string} projectRoot detected project root
93
- * @param {string} repositoryRoot repository root
94
- * @param {string} [platform] target platform
95
- * @returns {{
96
- * environment: Record<string, string>,
97
- * error?: string,
98
- * inputFiles: string[],
99
- * runnerArgs: string[]
100
- * }} runner contract
101
- */
102
- function getRunnerContract (framework, command, projectRoot, repositoryRoot, platform = process.platform) {
103
- const dynamicEnvironmentError = getDynamicRunnerEnvironmentError(command)
104
- if (dynamicEnvironmentError) {
105
- return { environment: {}, error: dynamicEnvironmentError, inputFiles: [], runnerArgs: [] }
106
- }
107
- const invocation = getFrameworkInvocation(command, framework)
108
- if (!invocation) return { environment: {}, inputFiles: [], runnerArgs: [] }
109
- if (invocation.error) {
110
- return { environment: {}, error: invocation.error, inputFiles: [], runnerArgs: [] }
111
- }
112
- const unsupportedOption = getUnsupportedConfigurationOption(framework, invocation)
113
- if (unsupportedOption) {
114
- return {
115
- environment: {},
116
- error: `${unsupportedOption} has configuration semantics that the validator does not preserve`,
117
- inputFiles: [],
118
- runnerArgs: [],
119
- }
120
- }
121
- const unknownOption = getUnknownRunnerOption(framework, invocation)
122
- if (unknownOption) {
123
- return {
124
- environment: {},
125
- error: `${unknownOption} is not preserved by the validator direct-runner contract`,
126
- inputFiles: [],
127
- runnerArgs: [],
128
- }
129
- }
130
- const omittedOptions = getOmittedRunnerOptions(framework, invocation)
131
-
132
- const environment = getRunnerEnvironment(invocation, platform)
133
- const environmentError = getRunnerEnvironmentError(environment, platform)
134
- if (environmentError) {
135
- return { environment: {}, error: `runner environment ${environmentError}`, inputFiles: [], runnerArgs: [] }
136
- }
137
- const runnerArgs = getRunnerArgs(framework, invocation)
138
- const runnerArgsError = getRunnerArgsError(framework, runnerArgs)
139
- if (runnerArgsError) {
140
- return {
141
- environment: {},
142
- error: `runner arguments ${runnerArgsError}`,
143
- inputFiles: [],
144
- runnerArgs: [],
145
- }
146
- }
147
- const inputs = getRunnerInputs(runnerArgs, environment, projectRoot, repositoryRoot)
148
- if (inputs.error) {
149
- return { environment: {}, error: inputs.error, inputFiles: [], runnerArgs: [] }
150
- }
151
- return {
152
- environment,
153
- inputFiles: inputs.files,
154
- omittedOptions,
155
- runnerArgs,
156
- }
157
- }
158
-
159
- function getRunnerConfigurationContract (framework, runnerArgs, environment, projectRoot, repositoryRoot) {
160
- const runnerArgsError = getRunnerArgsError(framework, runnerArgs)
161
- if (runnerArgsError) {
162
- return {
163
- environment: {},
164
- error: `runner arguments ${runnerArgsError}`,
165
- inputFiles: [],
166
- runnerArgs: [],
167
- }
168
- }
169
- const inputs = getRunnerInputs(runnerArgs, environment, projectRoot, repositoryRoot)
170
- if (inputs.error) {
171
- return { environment: {}, error: inputs.error, inputFiles: [], runnerArgs: [] }
172
- }
173
- return { environment, inputFiles: inputs.files, runnerArgs }
174
- }
175
-
176
- /**
177
- * Rejects shell-expanded allowlisted environment assignments before command tokenization.
178
- *
179
- * @param {string} command detected package script
180
- * @returns {string|undefined} validation error
181
- */
182
- function getDynamicRunnerEnvironmentError (command) {
183
- const source = String(command || '')
184
- for (const match of source.matchAll(
185
- /(?:^|\s)([A-Za-z_][A-Za-z0-9_]*)=(?:"([^"]*)"|'([^']*)'|([^\s]+))/g
186
- )) {
187
- const value = match[2] ?? match[3] ?? match[4]
188
- if (RUNNER_ENVIRONMENT_NAMES.has(match[1]) && ENVIRONMENT_EXPANSION_PATTERN.test(value)) {
189
- return `runner environment contains an unsafe value for ${match[1]}`
190
- }
191
- }
192
- if (ENVIRONMENT_EXPANSION_PATTERN.test(source)) {
193
- return 'runner command contains shell-expanded values that the validator does not preserve'
194
- }
195
- }
196
-
197
- /**
198
- * Returns literal existing test roots selected by a direct framework invocation.
199
- *
200
- * @param {string} framework framework name
201
- * @param {string} command detected package script
202
- * @param {string} projectRoot detected project root
203
- * @param {string} repositoryRoot repository root
204
- * @returns {string[]} physical search roots
205
- */
206
- function getRunnerSearchRoots (framework, command, projectRoot, repositoryRoot) {
207
- const invocation = getFrameworkInvocation(command, framework)
208
- const options = RUNNER_OPTIONS[framework]
209
- if (!invocation || invocation.error || !options) return []
210
-
211
- const roots = new Set()
212
- const selectors = SOURCE_SELECTOR_OPTIONS[framework] || new Set()
213
- const tokens = invocation.tokens.slice(invocation.runnerIndex + 1)
214
- for (let index = 0; index < tokens.length; index++) {
215
- const token = tokens[index]
216
- if (token.startsWith('-')) {
217
- const option = token.split('=', 1)[0]
218
- if (DIRECTORY_OPTIONS.has(option)) {
219
- const value = token.includes('=') ? token.slice(token.indexOf('=') + 1) : tokens[++index]
220
- addRunnerSearchRoot(roots, value, projectRoot, repositoryRoot, true)
221
- } else if (selectors.has(option)) {
222
- const value = token.includes('=') ? token.slice(token.indexOf('=') + 1) : tokens[++index]
223
- addRunnerSearchRoot(roots, value, projectRoot, repositoryRoot, false)
224
- } else if (options.values.has(option) && !token.includes('=')) {
225
- index++
226
- }
227
- continue
228
- }
229
- if (['run', 'test'].includes(token)) continue
230
- addRunnerSearchRoot(roots, token, projectRoot, repositoryRoot, false)
231
- if (roots.size === 3) break
232
- }
233
- return [...roots]
234
- }
235
-
236
- /**
237
- * Adds one literal, contained command selector to the representative search roots.
238
- *
239
- * @param {Set<string>} roots accumulated physical roots
240
- * @param {string|undefined} value command selector
241
- * @param {string} projectRoot detected project root
242
- * @param {string} repositoryRoot repository root
243
- * @param {boolean} directory whether the option explicitly requires a directory
244
- */
245
- function addRunnerSearchRoot (roots, value, projectRoot, repositoryRoot, directory) {
246
- if (typeof value !== 'string' || !value) return
247
- const literal = value.split(/[*?{[]/, 1)[0].replace(/(?<![\\/])[\\/]+$/, '')
248
- if (!literal) return
249
- const candidate = path.resolve(projectRoot, literal)
250
- const searchRoot = directory || !path.extname(candidate) ? candidate : path.dirname(candidate)
251
- try {
252
- const physical = fs.realpathSync(searchRoot)
253
- if (fs.statSync(physical).isDirectory() &&
254
- isPathInside(fs.realpathSync(repositoryRoot), physical)) roots.add(physical)
255
- } catch {}
256
- }
257
-
258
- /**
259
- * Returns a configuration-bearing option that the direct-runner contract intentionally rejects.
260
- *
261
- * @param {string} framework framework name
262
- * @param {{runnerIndex: number, tokens: string[]}} invocation parsed invocation
263
- * @returns {string|undefined} unsupported option
264
- */
265
- function getUnsupportedConfigurationOption (framework, invocation) {
266
- const unsupported = UNSUPPORTED_CONFIGURATION_OPTIONS[framework]
267
- if (!unsupported) return
268
- return invocation.tokens.slice(invocation.runnerIndex + 1).find(token => {
269
- return token.startsWith('-') && unsupported.has(token.split('=', 1)[0])
270
- })?.split('=', 1)[0]
271
- }
272
-
273
- /**
274
- * Returns the first runner option whose semantics are neither retained nor explicitly safe to omit.
275
- *
276
- * @param {string} framework framework name
277
- * @param {{runnerIndex: number, tokens: string[]}} invocation parsed invocation
278
- * @returns {string|undefined} unsupported option
279
- */
280
- function getUnknownRunnerOption (framework, invocation) {
281
- const retained = RUNNER_OPTIONS[framework]
282
- if (!retained) return
283
- const ignored = IGNORED_RUNNER_OPTIONS[framework] || { flags: new Set(), values: new Set() }
284
- const omitted = OMITTED_RUNNER_OPTIONS[framework] || new Set()
285
- const selectors = SOURCE_SELECTOR_OPTIONS[framework] || new Set()
286
- const tokens = invocation.tokens.slice(invocation.runnerIndex + 1)
287
-
288
- for (let index = 0; index < tokens.length; index++) {
289
- const token = tokens[index]
290
- if (!token.startsWith('-')) continue
291
- const option = token.split('=', 1)[0]
292
- if (omitted.has(option)) {
293
- if (token !== option) return option
294
- continue
295
- }
296
- if (selectors.has(option)) {
297
- const value = token.includes('=') ? token.slice(token.indexOf('=') + 1) : tokens[index + 1]
298
- if (!value || value.startsWith('-')) return option
299
- if (!token.includes('=')) index++
300
- continue
301
- }
302
- if (retained.flags.has(option) || ignored.flags.has(option)) continue
303
- if (retained.values.has(option) || ignored.values.has(option)) {
304
- if (!token.includes('=') && tokens[index + 1] && !tokens[index + 1].startsWith('-')) index++
305
- continue
306
- }
307
- return option
308
- }
309
- }
310
-
311
- function getOmittedRunnerOptions (framework, invocation) {
312
- const omitted = OMITTED_RUNNER_OPTIONS[framework] || new Set()
313
- const ignored = IGNORED_RUNNER_OPTIONS[framework] || { flags: new Set(), values: new Set() }
314
- return [...new Set(invocation.tokens
315
- .slice(invocation.runnerIndex + 1)
316
- .filter(token => {
317
- if (!token.startsWith('-')) return false
318
- const option = token.split('=', 1)[0]
319
- return omitted.has(option) || ignored.flags.has(option) || ignored.values.has(option)
320
- })
321
- .map(token => token.split('=', 1)[0]))]
322
- }
323
-
324
- function getArgumentOptionValues (args, expected) {
325
- const values = []
326
- for (let index = 0; index < args.length; index++) {
327
- if (args[index].split('=', 1)[0] !== expected) continue
328
- values.push(args[index].includes('=') ? args[index].slice(args[index].indexOf('=') + 1) : args[index + 1])
329
- }
330
- return values
331
- }
332
-
333
- /**
334
- * Selects a project-owned runner only for an exact `node <regular-file>` package script.
335
- *
336
- * @param {string} command detected package script
337
- * @param {string} projectRoot detected project root
338
- * @param {string} repositoryRoot repository root
339
- * @returns {string|undefined} physical runner path
340
- */
341
- function getProjectNodeRunner (command, projectRoot, repositoryRoot) {
342
- if (CONTROL_PATTERN.test(String(command || ''))) return
343
- const tokens = tokenizeCommand(command)
344
- if (tokens.length !== 2 || !/^node(?:\.exe)?$/i.test(path.basename(tokens[0])) || tokens[1].startsWith('-')) return
345
-
346
- const filename = path.resolve(projectRoot, tokens[1])
347
- try {
348
- const lexicalStat = fs.lstatSync(filename)
349
- const physical = fs.realpathSync(filename)
350
- if (!lexicalStat.isFile() || lexicalStat.isSymbolicLink() ||
351
- !fs.statSync(physical).isFile() ||
352
- !isPathInside(fs.realpathSync(repositoryRoot), physical)) return
353
- return physical
354
- } catch {}
355
- }
356
-
357
- /**
358
- * Validates scaffold-owned runner arguments before they can affect execution.
359
- *
360
- * @param {string} framework framework name
361
- * @param {unknown} args runner arguments
362
- * @returns {string|undefined} validation error
363
- */
364
- function getRunnerArgsError (framework, args) {
365
- if (!Array.isArray(args)) return 'must be an array'
366
- const options = RUNNER_OPTIONS[framework]
367
- if (!options) return 'are unsupported for this framework'
368
-
369
- for (let index = 0; index < args.length; index++) {
370
- const token = args[index]
371
- if (typeof token !== 'string' || !token || CONTROL_PATTERN.test(token)) {
372
- return 'must contain only bounded strings without shell control syntax'
373
- }
374
- const option = token.split('=', 1)[0]
375
- if (options.flags.has(option)) {
376
- if (token !== option &&
377
- !/^--(?:color|colors|detectLeaks)=(?:true|false)$/.test(token)) {
378
- return `contain an invalid value for ${option}`
379
- }
380
- continue
381
- }
382
- if (!options.values.has(option)) return `contain unsupported option ${option}`
383
- if (token.includes('=')) {
384
- if (!token.slice(token.indexOf('=') + 1)) return `contain a missing value for ${option}`
385
- continue
386
- }
387
- const value = args[++index]
388
- if (typeof value !== 'string' || !value || value.startsWith('-') || CONTROL_PATTERN.test(value)) {
389
- return `contain a missing or unsafe value for ${option}`
390
- }
391
- }
392
-
393
- if (framework === 'cucumber') {
394
- const language = getArgumentOptionValues(args, '--language').find(value => value !== 'en')
395
- if (language) {
396
- return `--language ${language} is not supported by the validator-generated English scenarios`
397
- }
398
- }
399
- }
400
-
401
- /**
402
- * Validates the small static environment retained from a runner invocation.
403
- *
404
- * @param {unknown} environment runner environment
405
- * @param {string} [platform] target platform
406
- * @returns {string|undefined} validation error
407
- */
408
- function getRunnerEnvironmentError (environment, platform = process.platform) {
409
- if (!environment || typeof environment !== 'object' || Array.isArray(environment)) return 'must be an object'
410
- for (const [name, value] of Object.entries(environment)) {
411
- if (!getCanonicalRunnerEnvironmentName(name, platform)) return `contains unsupported variable ${name}`
412
- if (typeof value !== 'string' || Buffer.byteLength(value) > 4096 ||
413
- CONTROL_PATTERN.test(value) || ENVIRONMENT_EXPANSION_PATTERN.test(value)) {
414
- return `contains an unsafe value for ${name}`
415
- }
416
- }
417
- }
418
-
419
- /**
420
- * Validates that retained code-loading inputs are contained and approval-bound.
421
- *
422
- * @param {string[]} args runner arguments
423
- * @param {Record<string, string>} environment runner environment
424
- * @param {string} projectRoot project root
425
- * @param {string} repositoryRoot repository root
426
- * @param {string[]} configFiles approval-bound project inputs
427
- * @returns {string|undefined} validation error
428
- */
429
- function getRunnerInputError (args, environment, projectRoot, repositoryRoot, configFiles) {
430
- const inputs = getRunnerInputs(args, environment, projectRoot, repositoryRoot)
431
- if (inputs.error) return inputs.error
432
-
433
- const approved = new Set()
434
- if (configFiles) {
435
- for (const filename of configFiles) {
436
- try {
437
- approved.add(fs.realpathSync(filename))
438
- } catch {}
439
- }
440
- }
441
- const unbound = inputs.files.find(filename => !approved.has(filename))
442
- if (unbound) return `references an input that is not approval-bound: ${unbound}`
443
- }
444
-
445
- /**
446
- * Finds a direct framework executable behind inert launch wrappers.
447
- *
448
- * @param {string} command detected package script
449
- * @param {string} framework framework name
450
- * @returns {{error?: string, runnerIndex: number, tokens: string[]}|undefined} parsed invocation
451
- */
452
- function getFrameworkInvocation (command, framework) {
453
- if (CONTROL_PATTERN.test(String(command || '')) || command === `direct ${framework} binary`) return
454
- const tokens = tokenizeCommand(command)
455
- const executable = getRunnerExecutableName(framework)
456
- const runnerIndex = tokens.findIndex(token => {
457
- const basename = normalizeRunnerBasename(token)
458
- return basename === executable ||
459
- (framework === 'cucumber' && ['cucumber', 'cucumber-js'].includes(basename))
460
- })
461
- if (runnerIndex === -1) return
462
-
463
- const prefixError = getRunnerPrefixError(tokens.slice(0, runnerIndex))
464
- if (prefixError) return { error: prefixError, runnerIndex, tokens }
465
- return { runnerIndex, tokens }
466
- }
467
-
468
- function getRunnerPrefixError (prefix) {
469
- let coverageLauncher = false
470
- for (let index = 0; index < prefix.length; index++) {
471
- const token = prefix[index]
472
- if (/^[A-Za-z_][A-Za-z0-9_]*=[^;&|`]*$/.test(token)) continue
473
-
474
- const basename = path.basename(token).toLowerCase()
475
- if (RUNNER_LAUNCHERS.has(basename)) {
476
- coverageLauncher = basename === 'c8' || basename === 'nyc'
477
- continue
478
- }
479
- if (coverageLauncher && /^(?:-r|--reporter)=\S+$/.test(token)) continue
480
- if (coverageLauncher && /^(?:-r|--reporter)$/.test(token) &&
481
- prefix[index + 1] && !prefix[index + 1].startsWith('-')) {
482
- index++
483
- continue
484
- }
485
- if (!prefix.some(candidate => RUNNER_LAUNCHERS.has(path.basename(candidate).toLowerCase()))) {
486
- return `runner launch wrapper ${path.basename(token)} is not allowlisted`
487
- }
488
- return 'runner launch wrapper contains options or positional arguments whose semantics the validator does not ' +
489
- 'preserve'
490
- }
491
- }
492
-
493
- /**
494
- * Extracts allowlisted runner options while dropping source selectors and presentation flags.
495
- *
496
- * @param {string} framework framework name
497
- * @param {{runnerIndex: number, tokens: string[]}} invocation parsed invocation
498
- * @returns {string[]} retained options
499
- */
500
- function getRunnerArgs (framework, invocation) {
501
- const options = RUNNER_OPTIONS[framework]
502
- if (!options) return []
503
- const args = []
504
- for (let index = invocation.runnerIndex + 1; index < invocation.tokens.length; index++) {
505
- const token = invocation.tokens[index]
506
- if (!token.startsWith('-')) continue
507
- const option = token.split('=', 1)[0]
508
- if (options.flags.has(option)) {
509
- args.push(token)
510
- } else if (options.values.has(option)) {
511
- args.push(token)
512
- if (!token.includes('=') && invocation.tokens[index + 1] && !invocation.tokens[index + 1].startsWith('-')) {
513
- args.push(invocation.tokens[++index])
514
- }
515
- }
516
- }
517
- return args
518
- }
519
-
520
- /**
521
- * Normalizes executable shims and supported JavaScript runner entrypoints.
522
- *
523
- * @param {string} token command token
524
- */
525
- function normalizeRunnerBasename (token) {
526
- return path.basename(token)
527
- .replace(/\.cmd$/i, '')
528
- .replace(/\.(?:cjs|mjs|js)$/i, '')
529
- .toLowerCase()
530
- }
531
-
532
- /**
533
- * Extracts allowlisted literal environment assignments before the framework runner.
534
- *
535
- * @param {{runnerIndex: number, tokens: string[]}} invocation parsed invocation
536
- * @param {string} [platform] target platform
537
- * @returns {Record<string, string>} retained environment
538
- */
539
- function getRunnerEnvironment (invocation, platform = process.platform) {
540
- const environment = {}
541
- for (const token of invocation.tokens.slice(0, invocation.runnerIndex)) {
542
- const match = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(token)
543
- const name = match && getCanonicalRunnerEnvironmentName(match[1], platform)
544
- if (name && !CONTROL_PATTERN.test(match[2])) {
545
- setEnvironmentValue(environment, name, match[2], platform)
546
- }
547
- }
548
- return environment
549
- }
550
-
551
- function getCanonicalRunnerEnvironmentName (name, platform) {
552
- return [...RUNNER_ENVIRONMENT_NAMES].find(candidate => {
553
- return environmentNamesEqual(candidate, name, platform)
554
- })
555
- }
556
-
557
- /**
558
- * Resolves regular files referenced by retained configuration.
559
- *
560
- * @param {string[]} args runner arguments
561
- * @param {Record<string, string>} environment runner environment
562
- * @param {string} projectRoot project root
563
- * @param {string} repositoryRoot repository root
564
- * @returns {{error?: string, files: string[]}} physical input files
565
- */
566
- function getRunnerInputs (args, environment, projectRoot, repositoryRoot) {
567
- const values = []
568
- for (let index = 0; index < args.length; index++) {
569
- const option = args[index].split('=', 1)[0]
570
- if (!MODULE_OPTIONS.has(option) && !FILE_OPTIONS.has(option) && !DIRECTORY_OPTIONS.has(option)) continue
571
- const value = args[index].includes('=') ? args[index].slice(args[index].indexOf('=') + 1) : args[++index]
572
- values.push({
573
- directory: DIRECTORY_OPTIONS.has(option),
574
- label: option,
575
- module: MODULE_OPTIONS.has(option),
576
- value,
577
- })
578
- }
579
- if (environment.TS_NODE_PROJECT) {
580
- values.push({
581
- directory: false,
582
- label: 'TS_NODE_PROJECT',
583
- module: false,
584
- value: environment.TS_NODE_PROJECT,
585
- })
586
- }
587
-
588
- const files = new Set()
589
- for (const input of values) {
590
- if (input.directory) {
591
- const directoryError = getContainedDirectoryError(input, projectRoot, repositoryRoot)
592
- if (directoryError) return { error: directoryError, files: [] }
593
- continue
594
- }
595
- if (input.module && BUILTIN_MODULE_VALUES.get(input.label)?.has(input.value)) continue
596
- const filename = resolveInputFile(input, projectRoot)
597
- if (!filename) return { error: `${input.label} does not resolve to a repository-contained file`, files: [] }
598
- try {
599
- const physical = fs.realpathSync(filename)
600
- if (!fs.statSync(physical).isFile() || !isPathInside(fs.realpathSync(repositoryRoot), physical)) {
601
- return { error: `${input.label} resolves outside the repository`, files: [] }
602
- }
603
- files.add(physical)
604
- } catch {
605
- return { error: `${input.label} does not resolve to a repository-contained file`, files: [] }
606
- }
607
- }
608
- if (files.size > 20) return { error: 'retains more than 20 code-loading inputs', files: [] }
609
- return { files: [...files].sort() }
610
- }
611
-
612
- /**
613
- * Checks one retained directory selector without traversing it.
614
- *
615
- * @param {{label: string, value: string}} input input descriptor
616
- * @param {string} projectRoot project root
617
- * @param {string} repositoryRoot repository root
618
- * @returns {string|undefined} validation error
619
- */
620
- function getContainedDirectoryError (input, projectRoot, repositoryRoot) {
621
- try {
622
- const physical = fs.realpathSync(path.resolve(projectRoot, input.value))
623
- if (!fs.statSync(physical).isDirectory() || !isPathInside(fs.realpathSync(repositoryRoot), physical)) {
624
- return `${input.label} resolves outside the repository`
625
- }
626
- } catch {
627
- return `${input.label} does not resolve to a repository-contained directory`
628
- }
629
- }
630
-
631
- /**
632
- * Resolves one module or path without loading it.
633
- *
634
- * @param {{module: boolean, value: string}} input input descriptor
635
- * @param {string} projectRoot project root
636
- * @returns {string|undefined} resolved filename
637
- */
638
- function resolveInputFile (input, projectRoot) {
639
- if (!input.value) return
640
- if (!input.module || path.isAbsolute(input.value) || input.value.startsWith('.')) {
641
- return path.resolve(projectRoot, input.value)
642
- }
643
- const projectRelative = path.resolve(projectRoot, input.value)
644
- try {
645
- return require.resolve(projectRelative)
646
- } catch {}
647
- try {
648
- return require.resolve(input.value, { paths: [projectRoot] })
649
- } catch {}
650
- }
651
-
652
- /**
653
- * Tokenizes bounded package-script evidence without expanding variables or invoking a shell.
654
- *
655
- * @param {string} command package script
656
- * @returns {string[]} inert tokens
657
- */
658
- function tokenizeCommand (command) {
659
- const tokens = []
660
- for (const match of String(command || '').matchAll(/"([^"\r\n]*)"|'([^'\r\n]*)'|([^\s"']+)/g)) {
661
- tokens.push(match[1] ?? match[2] ?? match[3])
662
- }
663
- return tokens
664
- }
665
-
666
- /**
667
- * Returns the executable name for a framework.
668
- *
669
- * @param {string} framework framework name
670
- */
671
- function getRunnerExecutableName (framework) {
672
- if (framework === 'cucumber') return 'cucumber-js'
673
- return framework === 'playwright' ? 'playwright' : framework
674
- }
675
-
676
- /**
677
- * Checks physical path containment.
678
- *
679
- * @param {string} root root path
680
- * @param {string} filename candidate path
681
- */
682
- function isPathInside (root, filename) {
683
- const relative = path.relative(path.resolve(root), path.resolve(filename))
684
- return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
685
- }
686
-
687
- module.exports = {
688
- getProjectNodeRunner,
689
- getRunnerArgsError,
690
- getRunnerConfigurationContract,
691
- getRunnerContract,
692
- getRunnerEnvironmentError,
693
- getRunnerInputError,
694
- getRunnerSearchRoots,
695
- }