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,666 +0,0 @@
1
- 'use strict'
2
-
3
- const fs = require('node:fs')
4
- const path = require('node:path')
5
-
6
- const { buildCiCommandCandidate } = require('../ci-command-candidate')
7
- const { expandLocalPackageScripts } = require('../ci-package-scripts')
8
- const { buildCiRemediation } = require('../ci-remediation')
9
- const { getFrameworkCiDiscoveryContradiction } = require('../ci-discovery')
10
- const { environmentNamesEqual } = require('../environment')
11
- const { parseLiteralEnvironmentPrefix } = require('../literal-environment')
12
- const { fail, incomplete } = require('./helpers')
13
-
14
- const MAX_CI_FILE_BYTES = 512 * 1024
15
- const DYNAMIC_COMMAND_PATTERN = /[$`;&|\r\n]|%[^%\s]+%|![^!\s]+!/
16
- const RUNNER_PATTERNS = {
17
- cucumber:
18
- /^(?:(?:[^\s]*[/\\])?node(?:\.exe)?\s+)?(?:[^\s]*[/\\])?cucumber(?:-js)?(?:\.js)?(?:\s|$)/,
19
- cypress: /^(?:(?:[^\s]*[/\\])?node(?:\.exe)?\s+)?(?:[^\s]*[/\\])?cypress(?:\.js)?\s+run(?:\s|$)/,
20
- jest: /^(?:(?:[^\s]*[/\\])?node(?:\.exe)?\s+)?(?:[^\s]*[/\\])?jest(?:\.js)?(?:\s|$)/,
21
- mocha: /^(?:(?:[^\s]*[/\\])?node(?:\.exe)?\s+)?(?:[^\s]*[/\\])?mocha(?:\.js)?(?:\s|$)/,
22
- playwright: /^(?:(?:[^\s]*[/\\])?node(?:\.exe)?\s+)?(?:[^\s]*[/\\])?playwright(?:\.js)?\s+test(?:\s|$)/,
23
- vitest: /^(?:(?:[^\s]*[/\\])?node(?:\.exe)?\s+)?(?:[^\s]*[/\\])?vitest(?:\.js)?\s+(?:run|--run)(?:\s|$)/,
24
- }
25
-
26
- /**
27
- * Audits only structurally anchored, literal CI evidence.
28
- *
29
- * @param {object} input audit inputs
30
- * @param {object} input.manifest validation manifest
31
- * @param {object} input.framework framework entry
32
- * @param {Map<string, Buffer|undefined>} [input.projectFileSources] approval-bound project sources
33
- * @returns {object} CI audit result
34
- */
35
- function runCiWiring ({ manifest, framework, projectFileSources }) {
36
- const contradiction = getFrameworkCiDiscoveryContradiction(framework, manifest)
37
- if (contradiction) {
38
- return getIncomplete(framework, contradiction.reason, {
39
- ciDiscovery: contradiction.ciDiscovery,
40
- recommendation: contradiction.recommendation,
41
- })
42
- }
43
-
44
- const ci = framework.ciWiring || {}
45
- const evidence = {
46
- ciCommandCandidate: buildCiCommandCandidate(framework),
47
- conclusion: 'incomplete',
48
- domain: 'ci_configuration',
49
- evidenceStrength: 'unknown',
50
- }
51
- if (hasNoSupportedCiConfiguration(manifest, ci)) {
52
- return getIncomplete(
53
- framework,
54
- 'No supported CI configuration file was found by bounded repository discovery. The CI audit is incomplete; ' +
55
- 'this does not prove that the repository has no external CI configuration.',
56
- {
57
- ...evidence,
58
- reasonCode: 'no-supported-ci-configuration',
59
- recommendation: 'Identify the CI system and one repository-controlled test job. If CI is configured outside ' +
60
- 'this repository, review that configuration separately.',
61
- }
62
- )
63
- }
64
- if (hasUnavailableRemoteCiCommand(ci)) {
65
- return getIncomplete(
66
- framework,
67
- 'The selected CI path delegates test execution to a remote action or reusable workflow whose command is not ' +
68
- 'available in this repository. The CI audit is incomplete.',
69
- {
70
- ...evidence,
71
- reasonCode: 'remote-ci-command-unavailable',
72
- recommendation: 'Review the referenced action or reusable workflow at its pinned revision. Keep the result ' +
73
- 'incomplete when its final test command and effective environment cannot be bound statically.',
74
- }
75
- )
76
- }
77
- const missing = getMissingReviewFields(ci)
78
- if (missing.length > 0) {
79
- return getIncomplete(
80
- framework,
81
- `The CI audit is incomplete because ${[
82
- `it is missing ${missing.join(', ')}`,
83
- ...(ci.reviewComplete === true ? [] : ['the review is not marked complete']),
84
- ].join(' and ')}.`,
85
- {
86
- ...evidence,
87
- recommendation: 'Identify one exact CI test job and resolve inherited configuration and wrappers. Leave the ' +
88
- 'result incomplete when that cannot be proven statically.',
89
- }
90
- )
91
- }
92
-
93
- const source = readProjectSource(ci.configFile, projectFileSources)
94
- if (!source) {
95
- return getIncomplete(framework, 'The recorded CI configuration file is unavailable or too large to verify.', {
96
- ...evidence,
97
- recommendation: 'Regenerate the manifest from the current checkout and review the CI file again.',
98
- })
99
- }
100
- const jobSource = getSelectedJobSource(source, ci)
101
- if (!jobSource ||
102
- !containsExecutionCommand(jobSource, ci.command) ||
103
- (ci.step && !containsLiteral(jobSource, ci.step))) {
104
- return getIncomplete(
105
- framework,
106
- 'The recorded command and step could not be bound structurally to the selected job in the checksum-bound ' +
107
- 'CI file.',
108
- {
109
- ...evidence,
110
- recommendation: 'Record the exact YAML job key, literal step, and command from one supported CI job. Leave ' +
111
- 'the audit incomplete when that job structure cannot be verified.',
112
- }
113
- )
114
- }
115
-
116
- const command = ci.command.trim()
117
- const resolution = getRunnerResolution(command, framework, ci, projectFileSources)
118
- const normalizedSource = jobSource.replaceAll('\\', '/')
119
- const hasInitialization = /dd-trace\/ci\/init(?:\.js)?\b/.test(normalizedSource)
120
- const matrixRelevant = matrixAffectsCiFacts(jobSource, command)
121
- const unresolved = classifyUnresolved(ci, resolution, matrixRelevant, jobSource)
122
- const initialization = getInitializationFact(ci, hasInitialization)
123
- const ciFacts = {
124
- initialization,
125
- matrix: {
126
- status: matrixRelevant ? 'affects_relevant_configuration' : 'not_relevant_to_ci_facts',
127
- },
128
- runnerInvocation: {
129
- ...(resolution.commandPath ? { commandPath: resolution.commandPath } : {}),
130
- ...(resolution.lifecycleScripts?.length > 0
131
- ? { lifecycleScripts: resolution.lifecycleScripts }
132
- : {}),
133
- ...(resolution.reason ? { reason: resolution.reason } : {}),
134
- ...(resolution.resolvedCommand ? { resolvedCommand: resolution.resolvedCommand } : {}),
135
- source: resolution.source,
136
- status: resolution.status,
137
- },
138
- transport: getTransportFact(ci, jobSource),
139
- unresolved,
140
- }
141
- evidence.ciFacts = ciFacts
142
-
143
- const effectiveNodeOptions = resolution.status === 'confirmed'
144
- ? getEffectiveNodeOptionsOverride(resolution.commandPath)
145
- : undefined
146
- const remediation = buildCiRemediation(framework)
147
- if (resolution.status === 'confirmed' &&
148
- effectiveNodeOptions !== undefined &&
149
- !/dd-trace[\\/]ci[\\/]init(?:\.js)?\b/.test(effectiveNodeOptions) &&
150
- unresolved.relevant.length === 0) {
151
- return getFailure(
152
- framework,
153
- 'The statically resolved CI test path overrides NODE_OPTIONS without the dd-trace/ci/init preload, so Test ' +
154
- 'Optimization is not initialized in the final runner.',
155
- {
156
- ...evidence,
157
- ciRemediation: remediation,
158
- conclusion: 'confirmed_misconfigured',
159
- evidenceStrength: 'confirmed_static',
160
- recommendation: remediation.summary,
161
- }
162
- )
163
- }
164
-
165
- if (initialization.status === 'missing' &&
166
- resolution.status === 'confirmed' &&
167
- unresolved.relevant.length === 0) {
168
- const transportMissing = ciFacts.transport.status === 'missing'
169
- return getFailure(
170
- framework,
171
- 'The checksum-bound CI job reaches the selected test framework through a bounded static command path, but ' +
172
- `does not configure the dd-trace/ci/init preload${
173
- transportMissing ? ' and declares no visible Datadog Agent or agentless reporting transport' : ''
174
- }. Test Optimization is not configured in that job.`,
175
- {
176
- ...evidence,
177
- ciConfigurationStatus: 'not_configured',
178
- ciRemediation: remediation,
179
- conclusion: 'confirmed_misconfigured',
180
- evidenceStrength: 'confirmed_static',
181
- recommendation: remediation.summary,
182
- }
183
- )
184
- }
185
-
186
- if (resolution.status !== 'confirmed') {
187
- let visibleFacts = ''
188
- if (initialization.status === 'missing') {
189
- visibleFacts = 'The selected job has no visible dd-trace/ci/init preload.'
190
- }
191
- if (ciFacts.transport.status === 'missing') {
192
- if (visibleFacts) visibleFacts += ' '
193
- visibleFacts += 'The recorded review found no visible Datadog Agent or agentless reporting transport.'
194
- }
195
- const recommendation = /working directory/i.test(resolution.reason)
196
- ? 'Keep the CI job\'s actual working directory. Resolve the repository-root wrapper to the selected test ' +
197
- 'runner statically; do not substitute the framework package directory merely to make the audit conclusive.'
198
- : 'Resolve the remaining wrapper or dynamic command statically, or confirm the effective NODE_OPTIONS value ' +
199
- 'in the final test process with DD_TRACE_DEBUG=1.'
200
- return getIncomplete(
201
- framework,
202
- 'The CI audit remains incomplete because the selected command could not be resolved to the ' +
203
- `${framework.framework} runner: ${resolution.reason}. ${visibleFacts}`.trim(),
204
- {
205
- ...evidence,
206
- recommendation,
207
- }
208
- )
209
- }
210
-
211
- if (unresolved.relevant.length > 0) {
212
- return getIncomplete(
213
- framework,
214
- 'The framework invocation was resolved statically, but relevant CI evidence remains unresolved: ' +
215
- `${unresolved.relevant.join('; ')}.`,
216
- {
217
- ...evidence,
218
- recommendation: 'Resolve only the listed configuration that can affect initialization, runner invocation, ' +
219
- 'or transport. Unrelated runtime matrices do not need further analysis.',
220
- }
221
- )
222
- }
223
-
224
- if (initialization.status !== 'configured') {
225
- return getIncomplete(
226
- framework,
227
- 'Static evidence does not establish whether dd-trace/ci/init is configured for the selected test path.',
228
- {
229
- ...evidence,
230
- recommendation: 'Record the literal NODE_OPTIONS configuration for this job or rerun the CI step with ' +
231
- 'DD_TRACE_DEBUG=1.',
232
- }
233
- )
234
- }
235
-
236
- if (ci.transport?.mode === 'agentless' &&
237
- /DD_CIVISIBILITY_AGENTLESS_ENABLED/.test(jobSource) &&
238
- !/\b(?:DD_API_KEY|DATADOG_API_KEY)\b/.test(jobSource)) {
239
- return getIncomplete(
240
- framework,
241
- 'The selected job visibly enables agentless reporting but has no Datadog API key reference in the ' +
242
- 'checksum-bound CI file. The key may still be injected outside this file.',
243
- {
244
- ...evidence,
245
- ciRemediation: remediation,
246
- recommendation: 'Confirm that DD_API_KEY reaches this test job from the CI secret store.',
247
- }
248
- )
249
- }
250
-
251
- return getIncomplete(
252
- framework,
253
- 'The selected CI job contains Test Optimization initialization, but static inspection cannot prove that the ' +
254
- 'effective environment and reporting transport reach the final process at runtime.',
255
- {
256
- ...evidence,
257
- conclusion: 'configured_propagation_unverified',
258
- evidenceStrength: 'inferred_static',
259
- recommendation: 'Rerun this exact CI step with DD_TRACE_DEBUG=1 and confirm initialization in the final test ' +
260
- 'runner.',
261
- }
262
- )
263
- }
264
-
265
- /**
266
- * Returns the final inline NODE_OPTIONS override along the resolved command path.
267
- *
268
- * @param {string[]} commandPath selected command and expanded package scripts
269
- * @returns {string|undefined} final literal override
270
- */
271
- function getEffectiveNodeOptionsOverride (commandPath = []) {
272
- let value
273
- for (const command of commandPath) {
274
- for (const assignment of normalizeDirectCommand(command).assignments) {
275
- if (environmentNamesEqual(assignment.name, 'NODE_OPTIONS')) value = assignment.value
276
- }
277
- }
278
- return value
279
- }
280
-
281
- /**
282
- * Resolves a direct runner or a bounded chain of local package scripts.
283
- *
284
- * @param {string} command selected CI command
285
- * @param {object} framework framework manifest entry
286
- * @param {object} ci selected CI evidence
287
- * @param {Map<string, Buffer|undefined>} [projectFileSources] approval-bound project sources
288
- * @returns {object} static runner resolution
289
- */
290
- function getRunnerResolution (command, framework, ci, projectFileSources) {
291
- if (getDirectRunner(command, framework.framework)) {
292
- return {
293
- commandPath: [command],
294
- resolvedCommand: command,
295
- source: 'direct_ci_command',
296
- status: 'confirmed',
297
- }
298
- }
299
-
300
- if (!ci.workingDirectory ||
301
- path.resolve(ci.workingDirectory) !== path.resolve(framework.project.root)) {
302
- return {
303
- reason: ci.workingDirectory
304
- ? 'the selected working directory does not match the approval-bound project package'
305
- : 'the selected package-script command has no approval-bound effective working directory',
306
- source: 'unresolved_wrapper',
307
- status: 'unresolved',
308
- }
309
- }
310
- const scripts = readProjectScripts(framework.project.packageJson, projectFileSources)
311
- if (!scripts) {
312
- return {
313
- reason: 'the approval-bound project package.json is unavailable or invalid',
314
- source: 'unresolved_wrapper',
315
- status: 'unresolved',
316
- }
317
- }
318
- const expansion = expandLocalPackageScripts(command, scripts)
319
- if (expansion.error) {
320
- return {
321
- lifecycleScripts: expansion.lifecycleScripts,
322
- reason: expansion.error,
323
- source: 'local_package_script',
324
- status: 'unresolved',
325
- }
326
- }
327
- const candidates = expansion.terminals.filter(terminal => {
328
- return getDirectRunner(terminal.command, framework.framework)
329
- })
330
- if (candidates.length === 0) {
331
- return {
332
- lifecycleScripts: expansion.lifecycleScripts,
333
- reason: 'no bounded local package-script path reaches the selected framework runner',
334
- source: 'unresolved_wrapper',
335
- status: 'unresolved',
336
- }
337
- }
338
- if (candidates.length > 1) {
339
- return {
340
- lifecycleScripts: expansion.lifecycleScripts,
341
- reason: 'more than one bounded local package-script path reaches the selected framework runner',
342
- source: 'unresolved_wrapper',
343
- status: 'unresolved',
344
- }
345
- }
346
- const candidate = candidates[0]
347
- return {
348
- commandPath: candidate.path,
349
- lifecycleScripts: expansion.lifecycleScripts,
350
- resolvedCommand: candidate.command,
351
- source: 'local_package_script',
352
- status: 'confirmed',
353
- }
354
- }
355
-
356
- function readProjectScripts (filename, projectFileSources) {
357
- try {
358
- const source = readProjectSource(filename, projectFileSources)
359
- if (source === undefined) return
360
- const packageJson = JSON.parse(source)
361
- if (!packageJson.scripts || typeof packageJson.scripts !== 'object' ||
362
- Array.isArray(packageJson.scripts)) return {}
363
- return packageJson.scripts
364
- } catch {}
365
- }
366
-
367
- function getInitializationFact (ci, hasInitialization) {
368
- if (ci.initialization?.status === 'configured' && hasInitialization) {
369
- return { status: 'configured', evidence: ci.initialization.evidence }
370
- }
371
- if (ci.initialization?.status === 'not_configured' && !hasInitialization) {
372
- return { status: 'missing', evidence: ci.initialization.evidence }
373
- }
374
- return {
375
- status: 'unresolved',
376
- reason: 'recorded initialization status and checksum-bound CI source do not establish the same conclusion',
377
- }
378
- }
379
-
380
- function getTransportFact (ci, jobSource) {
381
- const mode = ci.transport?.mode
382
- if (mode === 'agentless' &&
383
- /DD_CIVISIBILITY_AGENTLESS_ENABLED/.test(jobSource) &&
384
- !/\b(?:DD_API_KEY|DATADOG_API_KEY)\b/.test(jobSource)) {
385
- return { status: 'credentials_unverified', mode }
386
- }
387
- if (mode === 'agent' || mode === 'agentless') {
388
- return { status: 'configured', mode, evidence: ci.transport.evidence }
389
- }
390
- if (mode === 'none') return { status: 'missing', mode }
391
- return { status: 'unresolved', mode: mode || 'unknown' }
392
- }
393
-
394
- function classifyUnresolved (ci, resolution, matrixRelevant, jobSource) {
395
- const relevant = []
396
- const ignored = []
397
- const unresolved = Array.isArray(ci.unresolved) ? ci.unresolved : []
398
- const githubHosted = /[/\\]\.github[/\\]workflows[/\\]/.test(ci.configFile) &&
399
- /^[ \t]*runs-on:[ \t]*(?:ubuntu|windows|macos)-/mi.test(jobSource)
400
-
401
- for (const item of unresolved) {
402
- const isMatrix = /\bmatrix\b/i.test(item)
403
- const isResolvedPackagePath = resolution.status === 'confirmed' &&
404
- resolution.source === 'local_package_script' &&
405
- /\b(?:bun|lifecycle|npm|package script|pnpm|pretest|posttest|yarn)\b/i.test(item)
406
- const isAmbientGithubSettings = githubHosted &&
407
- /\b(?:repository|organization|environment)[-\s,\w]+\b(?:secrets?|variables?)\b/i.test(item) &&
408
- /\b(?:inject|inherit|outside)\b/i.test(item)
409
- const isOtherJob = /^Other jobs?\b/i.test(item) ||
410
- /\bsecond\b.+\bjob\b.+\bonly\b.+\bselected\b/i.test(item) ||
411
- /\brelease\b.+\bcontains no test job\b/i.test(item)
412
- if ((isMatrix && !matrixRelevant) ||
413
- isResolvedPackagePath ||
414
- isAmbientGithubSettings ||
415
- isOtherJob) {
416
- ignored.push(item)
417
- } else {
418
- relevant.push(item)
419
- }
420
- }
421
- if (ci.reviewComplete !== true && unresolved.length === 0) {
422
- relevant.push('the CI evidence review is not marked complete')
423
- }
424
- return { ignored, relevant }
425
- }
426
-
427
- function hasNoSupportedCiConfiguration (manifest, ci) {
428
- if (ci.configFile || ci.job || ci.command) return false
429
- const unresolved = Array.isArray(ci.unresolved) ? ci.unresolved : []
430
- return manifest.ciDiscovery?.found?.length === 0 ||
431
- unresolved.some(item => /No supported CI configuration file was found/i.test(item))
432
- }
433
-
434
- function hasUnavailableRemoteCiCommand (ci) {
435
- if (ci.command) return false
436
- const evidence = [
437
- ci.step,
438
- ...(Array.isArray(ci.unresolved) ? ci.unresolved : []),
439
- ].filter(Boolean)
440
- if (evidence.some(item => {
441
- return /\b(?:remote|external|third-party)\s+(?:action|workflow)\b/i.test(item)
442
- })) return true
443
-
444
- return evidence.some(item => {
445
- const reference = /^[ \t]*uses:[ \t]*["']?([^"'\s]+)["']?[ \t]*$/im.exec(item)?.[1]
446
- return reference && !reference.startsWith('./')
447
- })
448
- }
449
-
450
- function matrixAffectsCiFacts (jobSource, command) {
451
- const matrixReference = /\bmatrix\s*[.[]/
452
- if (!matrixReference.test(jobSource)) return false
453
- if (matrixReference.test(command)) return true
454
- return jobSource.split(/\r?\n/).some(line => {
455
- return matrixReference.test(line) &&
456
- /\b(?:container|DD_[A-Z0-9_]+|DATADOG_[A-Z0-9_]+|NODE_OPTIONS|runs-on|shell|working-directory)\b/i.test(line)
457
- })
458
- }
459
-
460
- /**
461
- * Locates a direct runner only at the executable position after literal environment assignments.
462
- *
463
- * @param {string} command selected CI command
464
- * @param {string} framework framework name
465
- * @returns {{index: number}|undefined} direct runner location
466
- */
467
- function getDirectRunner (command, framework) {
468
- if (DYNAMIC_COMMAND_PATTERN.test(command)) return
469
- const { index, source } = normalizeDirectCommand(command)
470
- if (!RUNNER_PATTERNS[framework]?.test(source)) return
471
- return { index }
472
- }
473
-
474
- function normalizeDirectCommand (command) {
475
- const prefix = parseLiteralEnvironmentPrefix(command)
476
- const assignments = [...prefix.assignments]
477
- let source = String(command).slice(prefix.length).replace(/^(?:c8|nyc)(?:\.cmd)?\s+/, '')
478
- if (/^cross-env(?:\.cmd)?\s+/.test(source)) {
479
- source = source.replace(/^cross-env(?:\.cmd)?\s+/, '')
480
- const crossEnv = parseLiteralEnvironmentPrefix(source)
481
- assignments.push(...crossEnv.assignments)
482
- source = source.slice(crossEnv.length)
483
- }
484
- source = source.replace(/^(?:(?:bunx|npx)(?:\.cmd)?|(?:pnpm|yarn)(?:\.cmd)?\s+exec)\s+/, '')
485
- .replace(/^bun x\s+/, '')
486
- return { assignments, index: prefix.length, source }
487
- }
488
-
489
- /**
490
- * Returns the selected YAML job block, or undefined when structural binding is unsupported.
491
- *
492
- * @param {string} source CI configuration source
493
- * @param {object} ci selected CI evidence
494
- * @returns {string|undefined} selected job source
495
- */
496
- function getSelectedJobSource (source, ci) {
497
- if (!/\.ya?ml$/i.test(String(ci.configFile || ''))) return
498
- const lines = source.replaceAll('\r\n', '\n').split('\n')
499
- const jobName = normalizeYamlKey(ci.job)
500
- if (!jobName) return
501
-
502
- const jobsIndex = lines.findIndex(line => /^jobs:\s*(?:#.*)?$/.test(line))
503
- if (jobsIndex !== -1) {
504
- const jobsEnd = findYamlBlockEnd(lines, jobsIndex, 0)
505
- const entries = []
506
- for (let index = jobsIndex + 1; index < jobsEnd; index++) {
507
- const entry = getYamlKeyEntry(lines[index], index)
508
- if (entry) entries.push(entry)
509
- }
510
- const jobIndent = Math.min(...entries.map(entry => entry.indent))
511
- const selected = entries.find(entry => entry.indent === jobIndent && entry.key === jobName)
512
- if (selected) return getYamlBlock(lines, selected.index, selected.indent)
513
- return
514
- }
515
-
516
- if (!/^\.gitlab-ci\.ya?ml$/i.test(path.basename(ci.configFile))) return
517
- const selected = lines
518
- .map((line, index) => getYamlKeyEntry(line, index))
519
- .find(entry => entry?.indent === 0 && entry.key === jobName)
520
- if (selected) return getYamlBlock(lines, selected.index, selected.indent)
521
- }
522
-
523
- function getYamlKeyEntry (line, index) {
524
- if (!line || /^\s*(?:#|$)/.test(line) || /^\s/.test(line) && line.includes('\t')) return
525
- const match = /^(\s*)(?:"([^"]+)"|'([^']+)'|([^\s:#][^:]*)):\s*(?:#.*)?$/.exec(line)
526
- if (!match) return
527
- return {
528
- indent: match[1].length,
529
- index,
530
- key: String(match[2] ?? match[3] ?? match[4]).trim(),
531
- }
532
- }
533
-
534
- function normalizeYamlKey (value) {
535
- const key = String(value || '').trim().replace(/:\s*$/, '').trim()
536
- if ((key.startsWith('"') && key.endsWith('"')) || (key.startsWith("'") && key.endsWith("'"))) {
537
- return key.slice(1, -1)
538
- }
539
- return key
540
- }
541
-
542
- function getYamlBlock (lines, start, indent) {
543
- return lines.slice(start, findYamlBlockEnd(lines, start, indent)).join('\n')
544
- }
545
-
546
- function findYamlBlockEnd (lines, start, indent) {
547
- for (let index = start + 1; index < lines.length; index++) {
548
- if (/^\s*(?:#|$)/.test(lines[index])) continue
549
- const nextIndent = /^\s*/.exec(lines[index])[0].length
550
- if (nextIndent <= indent) return index
551
- }
552
- return lines.length
553
- }
554
-
555
- /**
556
- * Returns missing fields required for a conclusive static audit.
557
- *
558
- * @param {object} ci CI evidence
559
- * @returns {string[]} missing field labels
560
- */
561
- function getMissingReviewFields (ci) {
562
- return [
563
- ['CI file', ci.configFile],
564
- ['job', ci.job],
565
- ['exact command', ci.command],
566
- ].filter(([, value]) => typeof value !== 'string' || !value.trim()).map(([label]) => label)
567
- }
568
-
569
- /**
570
- * Reads one bounded regular project file or its approval-bound snapshot.
571
- *
572
- * @param {string} filename project file
573
- * @param {Map<string, Buffer|undefined>} [projectFileSources] approval-bound project sources
574
- * @returns {string|undefined} source
575
- */
576
- function readProjectSource (filename, projectFileSources) {
577
- if (typeof filename !== 'string') return
578
- const resolved = path.resolve(filename)
579
- if (projectFileSources) {
580
- if (!projectFileSources.has(resolved)) return
581
- return projectFileSources.get(resolved)?.toString('utf8')
582
- }
583
- try {
584
- const stat = fs.lstatSync(resolved)
585
- if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_CI_FILE_BYTES) return
586
- return fs.readFileSync(resolved, 'utf8')
587
- } catch {}
588
- }
589
-
590
- /**
591
- * Checks whether recorded text appears literally after line-ending normalization.
592
- *
593
- * @param {string} source file source
594
- * @param {string} value recorded value
595
- */
596
- function containsLiteral (source, value) {
597
- const normalizedSource = source.replaceAll('\r\n', '\n')
598
- const normalizedValue = value.replaceAll('\r\n', '\n').trim()
599
- return normalizedValue !== '' && normalizedSource.includes(normalizedValue)
600
- }
601
-
602
- function containsExecutionCommand (source, value) {
603
- const command = String(value).replaceAll('\r\n', '\n').trim()
604
- if (!command) return false
605
- const lines = source.replaceAll('\r\n', '\n').split('\n')
606
- return lines.some((line, index) => {
607
- if (/^\s*#/.test(line)) return false
608
- const match = /^\s*(?:-\s*)?(?:run|script):(.*)$/.exec(line)
609
- if (!match) return false
610
- const scalar = match[1].trim()
611
- if (!/^\|[+-]?$/.test(scalar)) return scalar === command
612
-
613
- const indicatorIndent = /^\s*/.exec(line)[0].length
614
- const block = []
615
- let contentIndent
616
- for (let next = index + 1; next < lines.length; next++) {
617
- if (!lines[next].trim()) {
618
- block.push('')
619
- continue
620
- }
621
- const nextIndent = /^\s*/.exec(lines[next])[0].length
622
- if (contentIndent === undefined) {
623
- if (nextIndent <= indicatorIndent) break
624
- contentIndent = nextIndent
625
- } else if (nextIndent < contentIndent) {
626
- break
627
- }
628
- block.push(lines[next])
629
- }
630
- if (contentIndent === undefined) return false
631
- const blockCommand = block.map(candidate => candidate.slice(contentIndent)).join('\n').trim()
632
- return blockCommand === command
633
- })
634
- }
635
-
636
- /**
637
- * Builds an incomplete CI result.
638
- *
639
- * @param {object} framework framework entry
640
- * @param {string} diagnosis diagnosis
641
- * @param {object} evidence evidence
642
- * @returns {object} result
643
- */
644
- function getIncomplete (framework, diagnosis, evidence) {
645
- return incomplete(framework, 'ci-wiring', diagnosis, {
646
- ciWiring: framework.ciWiring,
647
- ...evidence,
648
- })
649
- }
650
-
651
- /**
652
- * Builds a confirmed CI failure.
653
- *
654
- * @param {object} framework framework entry
655
- * @param {string} diagnosis diagnosis
656
- * @param {object} evidence evidence
657
- * @returns {object} result
658
- */
659
- function getFailure (framework, diagnosis, evidence) {
660
- return fail(framework, 'ci-wiring', diagnosis, {
661
- ciWiring: framework.ciWiring,
662
- ...evidence,
663
- })
664
- }
665
-
666
- module.exports = { runCiWiring }