dd-trace 5.135.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 (250) hide show
  1. package/ci/init.js +2 -22
  2. package/ext/exporters.js +0 -1
  3. package/index.d.ts +105 -5
  4. package/initialize.mjs +5 -2
  5. package/lambda.d.ts +39 -0
  6. package/lambda.js +3 -0
  7. package/package.json +11 -9
  8. package/packages/datadog-esbuild/index.js +8 -55
  9. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  10. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  11. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  12. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  13. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  14. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  15. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  16. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  17. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  18. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  21. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -1
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -3
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  33. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  34. package/packages/datadog-instrumentations/src/next.js +19 -6
  35. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  36. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  37. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  38. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  39. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  40. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  41. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  42. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  43. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  44. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  45. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +22 -11
  46. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  48. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  49. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  50. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  51. package/packages/datadog-plugin-http/src/client.js +32 -9
  52. package/packages/datadog-plugin-http2/src/client.js +38 -13
  53. package/packages/datadog-plugin-next/src/index.js +112 -14
  54. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  55. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  56. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  57. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  58. package/packages/datadog-plugin-undici/src/index.js +22 -7
  59. package/packages/datadog-turbopack/index.js +4 -28
  60. package/packages/datadog-turbopack/src/loader.js +14 -452
  61. package/packages/datadog-webpack/index.js +3 -55
  62. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  63. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  64. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  65. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  66. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  67. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  68. package/packages/dd-trace/src/before-exit.js +32 -0
  69. package/packages/dd-trace/src/bootstrap.js +5 -3
  70. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  71. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  72. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  73. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  74. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  75. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  76. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  77. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  78. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  79. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  80. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  81. package/packages/dd-trace/src/config/defaults.js +5 -0
  82. package/packages/dd-trace/src/config/generated-config-types.d.ts +42 -2
  83. package/packages/dd-trace/src/config/index.js +17 -5
  84. package/packages/dd-trace/src/config/parsers.js +9 -0
  85. package/packages/dd-trace/src/config/supported-configurations.json +158 -4
  86. package/packages/dd-trace/src/constants.js +1 -0
  87. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  88. package/packages/dd-trace/src/exporter.js +0 -11
  89. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  90. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  91. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  92. package/packages/dd-trace/src/id.js +1 -1
  93. package/packages/dd-trace/src/lambda/facade.js +74 -0
  94. package/packages/dd-trace/src/lambda/handler.js +3 -41
  95. package/packages/dd-trace/src/lambda/index.js +38 -15
  96. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  97. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  98. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  99. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  100. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  101. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  102. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  103. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  104. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  105. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  106. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  107. package/packages/dd-trace/src/log/channels.js +4 -0
  108. package/packages/dd-trace/src/log/writer.js +6 -1
  109. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +4 -0
  110. package/packages/dd-trace/src/openfeature/configuration_source.js +35 -27
  111. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  112. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  113. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  114. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  115. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  116. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  117. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  118. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  119. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  120. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  121. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  122. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  123. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  124. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  125. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  126. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  127. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  128. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  129. package/packages/dd-trace/src/plugin_manager.js +34 -7
  130. package/packages/dd-trace/src/plugins/ci_plugin.js +41 -10
  131. package/packages/dd-trace/src/plugins/index.js +6 -0
  132. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  133. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  134. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  135. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  136. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  137. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
  138. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  139. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  140. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  141. package/packages/dd-trace/src/plugins/util/test.js +64 -39
  142. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  143. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  144. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  145. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  146. package/packages/dd-trace/src/proxy.js +33 -53
  147. package/packages/dd-trace/src/span_processor.js +20 -0
  148. package/packages/dd-trace/src/startup-log.js +8 -6
  149. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  150. package/packages/dd-trace/src/tracer.js +0 -2
  151. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  152. package/register.js +2 -1
  153. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  154. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  155. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  156. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  157. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  158. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  159. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  160. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  161. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  162. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  163. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  164. package/vendor/dist/esquery/LICENSE +2 -0
  165. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  166. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  167. package/vendor/dist/jest-docblock/LICENSE +16 -0
  168. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  169. package/vendor/dist/limiter/LICENSE +2 -0
  170. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  171. package/vendor/dist/lru-cache/LICENSE +13 -0
  172. package/vendor/dist/meriyah/LICENSE +13 -0
  173. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  174. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  175. package/vendor/dist/pprof-format/LICENSE +13 -0
  176. package/vendor/dist/pprof-format/index.js +1 -1
  177. package/vendor/dist/protobufjs/LICENSE +219 -0
  178. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  179. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  180. package/vendor/dist/retry/LICENSE +2 -0
  181. package/vendor/dist/rfdc/LICENSE +2 -0
  182. package/vendor/dist/semifies/LICENSE +3 -1
  183. package/vendor/dist/shell-quote/LICENSE +3 -1
  184. package/vendor/dist/source-map/LICENSE +1 -0
  185. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  186. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  187. package/vendor/dist/ttl-set/LICENSE +28 -0
  188. package/ci/diagnose.js +0 -2215
  189. package/ci/runbook.md +0 -299
  190. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  191. package/ci/test-optimization-validation/approval.js +0 -386
  192. package/ci/test-optimization-validation/artifact-id.js +0 -18
  193. package/ci/test-optimization-validation/blocker-category.js +0 -24
  194. package/ci/test-optimization-validation/bounded-json.js +0 -120
  195. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  196. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  197. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  198. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  199. package/ci/test-optimization-validation/cli.js +0 -954
  200. package/ci/test-optimization-validation/command-blocker.js +0 -377
  201. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  202. package/ci/test-optimization-validation/command-runner.js +0 -649
  203. package/ci/test-optimization-validation/environment.js +0 -88
  204. package/ci/test-optimization-validation/executable-approval.js +0 -47
  205. package/ci/test-optimization-validation/executable.js +0 -244
  206. package/ci/test-optimization-validation/execution-lock.js +0 -70
  207. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  208. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  209. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  210. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  211. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  212. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  213. package/ci/test-optimization-validation/generated-files.js +0 -425
  214. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  215. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  216. package/ci/test-optimization-validation/literal-environment.js +0 -56
  217. package/ci/test-optimization-validation/literal-glob.js +0 -52
  218. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  219. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  220. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  221. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  222. package/ci/test-optimization-validation/offline-output.js +0 -406
  223. package/ci/test-optimization-validation/package-check.js +0 -97
  224. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  225. package/ci/test-optimization-validation/plan-writer.js +0 -541
  226. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  227. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  228. package/ci/test-optimization-validation/redaction.js +0 -319
  229. package/ci/test-optimization-validation/report-writer.js +0 -666
  230. package/ci/test-optimization-validation/result-semantics.js +0 -103
  231. package/ci/test-optimization-validation/runner-command.js +0 -264
  232. package/ci/test-optimization-validation/runner-contract.js +0 -695
  233. package/ci/test-optimization-validation/safe-files.js +0 -202
  234. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  235. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  236. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  237. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  238. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  239. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  240. package/ci/test-optimization-validation/source-text.js +0 -84
  241. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  242. package/ci/test-optimization-validation/test-output.js +0 -120
  243. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  244. package/ci/validate-test-optimization.js +0 -3
  245. package/packages/datadog-esbuild/src/resolver.js +0 -284
  246. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  247. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  248. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  249. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  250. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -1,541 +0,0 @@
1
- 'use strict'
2
-
3
- const crypto = require('node:crypto')
4
- const path = require('node:path')
5
-
6
- const { VERSION } = require('../../version')
7
- const { getRequiredCapabilities } = require('./approval')
8
- const { writeApprovalArtifacts } = require('./approval-artifacts')
9
- const { serializeApprovalCommand } = require('./command-runner')
10
- const { getUnavailableExecutable } = require('./executable')
11
- const { sanitizeString } = require('./redaction')
12
- const {
13
- getBasicCommand,
14
- getGeneratedCommand,
15
- } = require('./runner-command')
16
- const { writeFileSafely } = require('./safe-files')
17
-
18
- const VALIDATOR_PATH = path.resolve(__dirname, '..', 'validate-test-optimization.js')
19
- const EXECUTION_PLAN_FILENAME = 'execution-plan.md'
20
- const SCENARIO_TO_GENERATED_ID = {
21
- atr: 'atr-fail-once',
22
- efd: 'basic-pass',
23
- 'test-management': 'test-management-target',
24
- }
25
-
26
- /**
27
- * Produces the deterministic execution plan shown before live validation.
28
- *
29
- * @param {object} input plan inputs
30
- */
31
- function formatExecutionPlan (input) {
32
- return formatExecutionPlanArtifacts(input).plan
33
- }
34
-
35
- /**
36
- * Writes approval artifacts and the customer-visible plan without running project code.
37
- *
38
- * @param {object} input plan inputs
39
- * @param {object} input.manifest normalized manifest
40
- * @param {string} input.out output directory
41
- * @param {string[]} [input.selectedFrameworkIds] selected framework ids
42
- * @param {string|null} [input.requestedScenario] selected scenario
43
- * @param {boolean} [input.keepTempFiles] retain temporary files
44
- * @param {object} [input.packageCheck] installed package-load result
45
- * @param {Map<string, object>} [input.ciPreflightResults] static CI results by framework
46
- * @param {Array<{path: string, sha256: string}>} [input.expectedProjectFiles] preflight project snapshot
47
- * @param {boolean} [input.verbose] print progress
48
- * @returns {{plan: string}} written plan
49
- */
50
- function formatExecutionPlanArtifacts ({
51
- manifest,
52
- out,
53
- selectedFrameworkIds = [],
54
- requestedScenario = null,
55
- keepTempFiles = false,
56
- packageCheck,
57
- ciPreflightResults = new Map(),
58
- expectedProjectFiles,
59
- verbose = false,
60
- }) {
61
- const offlineFixtureNonce = crypto.randomBytes(16).toString('hex')
62
- const approvalArtifacts = writeApprovalArtifacts({
63
- manifest,
64
- out,
65
- selectedFrameworkIds,
66
- requestedScenario,
67
- offlineFixtureNonce,
68
- keepTempFiles,
69
- verbose,
70
- expectedProjectFiles,
71
- })
72
- const validatorArgv = [
73
- process.execPath,
74
- VALIDATOR_PATH,
75
- '--run-approved-plan',
76
- approvalArtifacts.approvalJsonPath,
77
- '--sha256',
78
- approvalArtifacts.digest,
79
- ]
80
- const plan = formatApprovalPlan({
81
- approvalArtifacts,
82
- ciPreflightResults,
83
- manifest,
84
- out,
85
- keepTempFiles,
86
- packageCheck,
87
- requestedScenario,
88
- validatorArgv,
89
- })
90
- writeFileSafely(out, getExecutionPlanPath(out), `${plan}\n`, 'validation execution plan')
91
- return { plan }
92
- }
93
-
94
- /**
95
- * Formats the complete bounded approval plan.
96
- *
97
- * @param {object} input formatting inputs
98
- * @param {object} input.approvalArtifacts approval artifact paths and digest
99
- * @param {Map<string, object>} input.ciPreflightResults static CI results by framework
100
- * @param {object} input.manifest normalized manifest
101
- * @param {string} input.out output directory
102
- * @param {boolean} input.keepTempFiles retain temporary files
103
- * @param {object|undefined} input.packageCheck installed package-load result
104
- * @param {string|null} input.requestedScenario selected scenario
105
- * @param {string[]} input.validatorArgv exact validator command
106
- */
107
- function formatApprovalPlan ({
108
- approvalArtifacts,
109
- ciPreflightResults,
110
- manifest,
111
- out,
112
- keepTempFiles,
113
- packageCheck,
114
- requestedScenario,
115
- validatorArgv,
116
- }) {
117
- const root = manifest.repository.root
118
- const runnableFrameworks = manifest.frameworks.filter(framework => framework.status === 'runnable')
119
- const requiredCapabilities = getRequiredCapabilities({
120
- manifest,
121
- requestedScenario,
122
- })
123
- const buildPrerequisites = runnableFrameworks.filter(framework => {
124
- return framework.buildArtifactRequired === true ||
125
- (framework.validation?.fallbackTests || []).some(fallback => fallback.buildArtifactRequired === true)
126
- }).length
127
- const lines = [
128
- '# Test Optimization Validation Plan',
129
- '',
130
- `Repository: ${inline(root)}`,
131
- `Validator: ${inline(`dd-trace ${VERSION}`)}`,
132
- `Results: ${inline(relative(root, out))}`,
133
- ...(packageCheck?.ok
134
- ? [`Installed package check: ${plain(packageCheck.diagnosis)}`]
135
- : []),
136
- '',
137
- '## Approval Summary',
138
- '',
139
- requestedScenario === 'ci-wiring'
140
- ? 'Local execution: none; this plan performs static CI analysis only.'
141
- : `Local execution: ${runnableFrameworks.length} framework target${
142
- runnableFrameworks.length === 1 ? '' : 's'
143
- } eligible; ${manifest.frameworks.length - runnableFrameworks.length} setup or static-only.`,
144
- `Required host capabilities: ${
145
- requiredCapabilities.length > 0 ? requiredCapabilities.map(formatCapability).join(', ') : 'none declared'
146
- }.`,
147
- `Build prerequisites: ${
148
- buildPrerequisites > 0
149
- ? `${buildPrerequisites} eligible framework target${
150
- buildPrerequisites === 1 ? '' : 's'
151
- } may require the project's normal build`
152
- : 'none detected statically'
153
- }.`,
154
- `Mutable paths: ${inline(relative(root, out))} and the temporary files disclosed below; temporary files ${
155
- keepTempFiles ? 'will be retained by request' : 'will be removed after validation'
156
- }.`,
157
- 'CI replay: none. CI configuration is inspected statically and CI commands are never executed.',
158
- 'Approval: one checksum-bound validator command, shown once at the end of this plan.',
159
- '',
160
- 'The validator will run only the displayed `node <repository-contained-runner> <one-test-file>` commands. The ' +
161
- 'runner may be an exact repository-owned Node test wrapper. The validator itself will not directly invoke ' +
162
- 'package managers, shells, setup commands, or CI commands; approved repository code may start subprocesses.',
163
- '',
164
- '## Checks',
165
- '',
166
- ]
167
-
168
- for (const framework of manifest.frameworks) {
169
- lines.push(`### ${plain(getFrameworkLabel(framework, root))}`, '')
170
- if (framework.status !== 'runnable') {
171
- lines.push(
172
- `Status: ${plain(formatStatus(framework.status))}.`,
173
- ...(framework.blockerCategory
174
- ? [`Blocker: ${plain(framework.blockerCategory.replaceAll('_', ' '))}.`]
175
- : [])
176
- )
177
- if (framework.notes) {
178
- for (const note of framework.notes) lines.push(`- ${plain(note)}`)
179
- }
180
- lines.push('')
181
- continue
182
- }
183
-
184
- if (requestedScenario === 'ci-wiring') {
185
- lines.push('Status: static CI audit only; no project test command is selected.', '')
186
- } else {
187
- const basic = getBasicCommand(framework)
188
- const fallbackTests = framework.validation.fallbackTests || []
189
- const unavailable = getUnavailableExecutable(basic)
190
- const status = unavailable
191
- ? `local validation will be incomplete because ${inline(unavailable)} is unavailable`
192
- : 'eligible for approved clean preflight; runtime prerequisites are unverified'
193
- lines.push(
194
- `Status: ${status}.`,
195
- `Representative test: ${inline(relative(root, framework.validation.testFile))}${formatCandidateRequirements({
196
- buildArtifactRequired: framework.buildArtifactRequired,
197
- localSocketRequired: framework.localSocketRequired,
198
- })}`,
199
- ...(fallbackTests.length > 0
200
- ? [
201
- 'Fallback tests, tried in order only if the representative does not pass cleanly:',
202
- ...fallbackTests.map(fallback => {
203
- return `- ${inline(relative(root, fallback.testFile))}${formatCandidateRequirements(fallback)}`
204
- }),
205
- ]
206
- : []),
207
- `Working directory: ${inline(relative(root, basic.cwd))}`,
208
- `Timeout: ${basic.timeoutMs} ms`,
209
- ...(Object.keys(basic.env || {}).length > 0
210
- ? [`Runner environment: ${inline(JSON.stringify(basic.env))}`]
211
- : []),
212
- ...formatOmittedRunnerOptions(framework.validation.omittedRunnerOptions),
213
- '',
214
- ...(framework.browserRequired
215
- ? [
216
- 'Browser permission: this approved validation command launches the project browser through its ' +
217
- 'selected test runner. If the agent platform blocks browser processes, request its narrow permission ' +
218
- 'for the exact checksum-bound validator command below; do not change or broaden the command. ' +
219
- 'Complete ' +
220
- 'the project\'s normal browser installation, application startup, and build first when the selected ' +
221
- 'test depends on them.',
222
- '',
223
- ]
224
- : []),
225
- ...(framework.localSocketRequired
226
- ? [
227
- `Localhost prerequisite: ${
228
- framework.allCandidatesRequireLocalSocket
229
- ? 'every approved candidate appears'
230
- : 'the selected test appears'
231
- } to open or contact a local listener. A restricted execution environment may require narrow ` +
232
- 'permission for the exact validator command.',
233
- '',
234
- ]
235
- : []),
236
- ...(framework.buildArtifactRequired
237
- ? [
238
- 'Build prerequisite: the selected test appears to load a build or dist artifact. Complete the ' +
239
- 'project\'s normal build before validation if that artifact is not already present.',
240
- '',
241
- ]
242
- : []),
243
- 'Basic Reporting command:',
244
- '',
245
- codeBlock(serializeApprovalCommand(basic)),
246
- '',
247
- 'The command runs once without Datadog and once with validator-owned offline initialization. A debug rerun ' +
248
- 'and one clean confirmation may run only when needed to diagnose a mismatch.',
249
- ...(fallbackTests.length > 0
250
- ? [
251
- 'If this test does not pass cleanly, the validator may try the disclosed fallback tests in order. It ' +
252
- 'will initialize only the first candidate that passes, and will stop early when the failure is a ' +
253
- 'confirmed shared runtime prerequisite rather than a candidate-specific test failure.',
254
- ]
255
- : []),
256
- ''
257
- )
258
-
259
- for (const [index, fallback] of fallbackTests.entries()) {
260
- const fallbackCommand = getBasicCommand(framework, fallback.testFile)
261
- lines.push(
262
- `Fallback Basic Reporting command ${index + 1}:`,
263
- '',
264
- codeBlock(serializeApprovalCommand(fallbackCommand)),
265
- ''
266
- )
267
- }
268
-
269
- const selectedScenarios = getSelectedGeneratedScenarios(framework, requestedScenario)
270
- if (selectedScenarios.length > 0) {
271
- lines.push(
272
- `Advanced checks use working directory: ${inline(relative(
273
- root,
274
- getGeneratedCommand(framework, selectedScenarios[0]).cwd
275
- ))}`,
276
- ''
277
- )
278
- }
279
- for (const scenario of selectedScenarios) {
280
- const command = getGeneratedCommand(framework, scenario)
281
- const source = getGeneratedSource(framework, scenario)
282
- lines.push(
283
- `Advanced check ${inline(scenario.id)}:`,
284
- '',
285
- codeBlock(serializeApprovalCommand(command)),
286
- '',
287
- `Temporary file: ${inline(relative(root, scenario.testIdentities[0].file))}`,
288
- '',
289
- codeBlock(source),
290
- ''
291
- )
292
- }
293
- for (const file of getSelectedSupportFiles(framework, selectedScenarios)) {
294
- lines.push(
295
- 'Advanced check support file:',
296
- '',
297
- `Temporary file: ${inline(relative(root, file.path))}`,
298
- '',
299
- codeBlock(file.contentLines.join('\n')),
300
- ''
301
- )
302
- }
303
- if (selectedScenarios.length > 0) {
304
- lines.push(
305
- 'Advanced execution policy: each generated scenario has one clean verification, one instrumented ' +
306
- 'identity-discovery run, and one feature-validation run. One debug rerun may run only after a failure.',
307
- ''
308
- )
309
- }
310
- }
311
-
312
- const ci = framework.ciWiring
313
- const ciPreflight = ciPreflightResults.get(framework.id)
314
- lines.push(
315
- 'CI audit: static only; no CI or package command will execute.',
316
- `CI review: ${plain(ci?.reviewComplete ? 'complete' : 'incomplete')}.`,
317
- ...(ciPreflight
318
- ? [`CI pre-approval result: ${plain(formatCiPreflightResult(ciPreflight))}`]
319
- : []),
320
- ...(ci?.configFile ? [`CI file: ${inline(relative(root, ci.configFile))}`] : []),
321
- ''
322
- )
323
- }
324
-
325
- lines.push(
326
- '## Writes and Cleanup',
327
- '',
328
- `- Validation artifacts: ${inline(relative(root, out))}`,
329
- '- Single-flight lock: the approved validator creates one fixed lock in the result directory while it runs. An ' +
330
- 'existing lock blocks execution and is never reclaimed automatically.',
331
- ...(requestedScenario === 'ci-wiring'
332
- ? []
333
- : [
334
- '- Temporary generated tests shown above are created only for advanced checks and removed afterward.',
335
- '- Declared framework output is refused if it already exists and removed after each command.',
336
- '- Private offline fixtures are created outside the repository and removed after each check.',
337
- ]),
338
- '',
339
- '## Security Boundary',
340
- '',
341
- '- The validation transport opens no listener, contacts no Datadog endpoint, and uses no real Datadog ' +
342
- 'credentials.',
343
- ...(requestedScenario === 'ci-wiring'
344
- ? ['- This CI-only plan executes no project test command.']
345
- : [
346
- '- Project runners and tests are arbitrary repository code. Approval means trusting the listed files, ' +
347
- 'their imported code, and any subprocesses they start.',
348
- ]),
349
- '- The approval digest binds the manifest, validator package, Node.js binary, runner, selected test, config ' +
350
- 'files, CI evidence file, generated source, options, and output directory.',
351
- '- Missing dependencies, unsupported launchers, arbitrary wrapper chains, dynamic CI, and ambiguous evidence ' +
352
- 'produce an incomplete result.',
353
- '',
354
- 'Approval details:',
355
- '',
356
- `- JSON: ${inline(relative(root, approvalArtifacts.approvalJsonPath))}`,
357
- `- Checksums: ${inline(relative(root, approvalArtifacts.coveredFilesPath))}`,
358
- `- SHA-256: ${inline(approvalArtifacts.digest)}`,
359
- '',
360
- 'Run exactly this command after approval:',
361
- '',
362
- codeBlock(serializeApprovalCommand({
363
- argv: validatorArgv,
364
- cwd: root,
365
- usesShell: false,
366
- })),
367
- '',
368
- `Working directory: ${inline(root)}`,
369
- '',
370
- 'If an agent platform hard-denies the exact command, do not alter it or broaden permissions. Run this same ' +
371
- 'command in a normal project terminal and ask the agent to interpret the generated report.'
372
- )
373
- return lines.join('\n')
374
- }
375
-
376
- function formatCapability (capability) {
377
- const labels = {
378
- browser_process: 'browser process',
379
- localhost_socket: 'localhost socket',
380
- }
381
- return labels[capability] || capability
382
- }
383
-
384
- function formatCandidateRequirements (candidate) {
385
- const requirements = [
386
- ...(candidate.localSocketRequired ? ['localhost'] : []),
387
- ...(candidate.buildArtifactRequired ? ['build output'] : []),
388
- ]
389
- return requirements.length > 0 ? ` (${requirements.join(', ')} required)` : ''
390
- }
391
-
392
- function formatCiPreflightResult (result) {
393
- const status = result.status === 'fail'
394
- ? 'confirmed actionable problem'
395
- : result.status === 'pass'
396
- ? 'no confirmed problem'
397
- : 'incomplete'
398
- return `${status}: ${result.diagnosis}`
399
- }
400
-
401
- function formatOmittedRunnerOptions (options = []) {
402
- const descriptions = {
403
- '-R': 'Omitted runner option: `-R` selects only Mocha report presentation; the validator uses its bounded ' +
404
- 'reporter.',
405
- '--reporter': 'Omitted runner option: `--reporter` selects only Mocha report presentation; the validator uses ' +
406
- 'its bounded reporter.',
407
- '--run': 'Normalized runner option: `--run` is omitted because the validator supplies Vitest `run` itself.',
408
- '--typecheck': 'Omitted runner option: `--typecheck` is excluded because validation executes runtime tests only.',
409
- }
410
- return options.map(option => descriptions[option])
411
- }
412
-
413
- /**
414
- * Selects generated scenarios covered by a plan.
415
- *
416
- * @param {object} framework framework entry
417
- * @param {string|null} requestedScenario selected scenario
418
- * @returns {object[]} selected generated scenarios
419
- */
420
- function getSelectedGeneratedScenarios (framework, requestedScenario) {
421
- if (requestedScenario === 'basic-reporting' || requestedScenario === 'ci-wiring') return []
422
- const scenarios = framework.generatedTestStrategy?.scenarios || []
423
- if (!requestedScenario) return scenarios
424
- const id = SCENARIO_TO_GENERATED_ID[requestedScenario]
425
- return id ? scenarios.filter(scenario => scenario.id === id) : []
426
- }
427
-
428
- /**
429
- * Returns adapter support files required by selected generated scenarios.
430
- *
431
- * @param {object} framework framework entry
432
- * @param {object[]} selectedScenarios selected generated scenarios
433
- * @returns {object[]} support files
434
- */
435
- function getSelectedSupportFiles (framework, selectedScenarios) {
436
- if (selectedScenarios.length === 0) return []
437
- const scenarioPaths = new Set((framework.generatedTestStrategy?.scenarios || []).map(scenario => {
438
- return path.resolve(scenario.testIdentities[0].file)
439
- }))
440
- return (framework.generatedTestStrategy?.files || []).filter(file => {
441
- return !scenarioPaths.has(path.resolve(file.path))
442
- })
443
- }
444
-
445
- /**
446
- * Returns canonical generated source for a scenario.
447
- *
448
- * @param {object} framework framework entry
449
- * @param {object} scenario generated scenario
450
- */
451
- function getGeneratedSource (framework, scenario) {
452
- const filename = path.resolve(scenario.testIdentities[0].file)
453
- const file = framework.generatedTestStrategy.files.find(candidate => path.resolve(candidate.path) === filename)
454
- return file?.contentLines?.join('\n') || '<generated source unavailable>'
455
- }
456
-
457
- /**
458
- * Returns the execution plan path.
459
- *
460
- * @param {string} out output directory
461
- */
462
- function getExecutionPlanPath (out) {
463
- return path.join(out, EXECUTION_PLAN_FILENAME)
464
- }
465
-
466
- /**
467
- * Formats a framework label.
468
- *
469
- * @param {object} framework framework entry
470
- * @param {string} root repository root
471
- */
472
- function getFrameworkLabel (framework, root) {
473
- const project = framework.project?.name || relative(root, framework.project?.root || root)
474
- return `${framework.framework} in ${project || 'root project'}`
475
- }
476
-
477
- /**
478
- * Formats a framework status.
479
- *
480
- * @param {string} status status id
481
- */
482
- function formatStatus (status) {
483
- return {
484
- detected_not_runnable: 'detected but no direct target was selected',
485
- requires_manual_setup: 'requires normal project setup',
486
- unsupported_by_validator: 'unsupported by this validator',
487
- }[status] || status
488
- }
489
-
490
- /**
491
- * Formats a repository-relative path.
492
- *
493
- * @param {string} root repository root
494
- * @param {string} filename absolute path
495
- */
496
- function relative (root, filename) {
497
- const value = path.relative(root, filename)
498
- return value || '.'
499
- }
500
-
501
- /**
502
- * Formats a safe Markdown code block.
503
- *
504
- * @param {string} value text
505
- */
506
- function codeBlock (value) {
507
- return `\`\`\`text\n${plainMultiline(value).replaceAll('```', String.raw`\u0060\u0060\u0060`)}\n\`\`\``
508
- }
509
-
510
- /**
511
- * Formats safe inline code.
512
- *
513
- * @param {string} value text
514
- */
515
- function inline (value) {
516
- return `\`${plain(value).replaceAll('`', String.raw`\u0060`)}\``
517
- }
518
-
519
- /**
520
- * Sanitizes one line of plan text.
521
- *
522
- * @param {unknown} value text
523
- */
524
- function plain (value) {
525
- return sanitizeString(String(value ?? '')).replaceAll(/\p{Cc}+/gu, ' ').trim()
526
- }
527
-
528
- /**
529
- * Sanitizes multiline plan text.
530
- *
531
- * @param {unknown} value text
532
- */
533
- function plainMultiline (value) {
534
- return sanitizeString(String(value ?? '')).replaceAll('\r\n', '\n').replaceAll('\r', '\n').trim()
535
- }
536
-
537
- module.exports = {
538
- formatExecutionPlan,
539
- formatExecutionPlanArtifacts,
540
- getExecutionPlanPath,
541
- }