dd-trace 6.24.0 → 6.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/ci/init.js +2 -22
  2. package/ext/exporters.js +0 -1
  3. package/index.d.ts +105 -5
  4. package/initialize.mjs +5 -2
  5. package/lambda.d.ts +39 -0
  6. package/lambda.js +3 -0
  7. package/package.json +11 -9
  8. package/packages/datadog-esbuild/index.js +8 -55
  9. package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
  10. package/packages/datadog-instrumentations/src/cucumber.js +5 -2
  11. package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
  12. package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
  13. package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
  14. package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
  15. package/packages/datadog-instrumentations/src/graphql.js +20 -17
  16. package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
  17. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
  18. package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
  21. package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -1
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -3
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
  33. package/packages/datadog-instrumentations/src/ioredis.js +101 -3
  34. package/packages/datadog-instrumentations/src/next.js +19 -6
  35. package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
  36. package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
  37. package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
  38. package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
  39. package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
  40. package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
  41. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
  42. package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
  43. package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
  44. package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
  45. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +22 -11
  46. package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
  48. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
  49. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
  50. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
  51. package/packages/datadog-plugin-http/src/client.js +32 -9
  52. package/packages/datadog-plugin-http2/src/client.js +38 -13
  53. package/packages/datadog-plugin-next/src/index.js +112 -14
  54. package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
  55. package/packages/datadog-plugin-trpc/src/index.js +15 -0
  56. package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
  57. package/packages/datadog-plugin-trpc/src/request.js +81 -0
  58. package/packages/datadog-plugin-undici/src/index.js +22 -7
  59. package/packages/datadog-turbopack/index.js +4 -28
  60. package/packages/datadog-turbopack/src/loader.js +14 -452
  61. package/packages/datadog-webpack/index.js +3 -55
  62. package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
  63. package/packages/dd-trace/src/aiguard/sdk.js +8 -2
  64. package/packages/dd-trace/src/aiguard/tags.js +2 -0
  65. package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
  66. package/packages/dd-trace/src/appsec/graphql.js +91 -6
  67. package/packages/dd-trace/src/appsec/recommended.json +1287 -90
  68. package/packages/dd-trace/src/before-exit.js +32 -0
  69. package/packages/dd-trace/src/bootstrap.js +5 -3
  70. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
  71. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
  72. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
  73. package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
  74. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
  75. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
  76. package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
  77. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  78. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
  79. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
  80. package/packages/dd-trace/src/config/config-types.d.ts +3 -0
  81. package/packages/dd-trace/src/config/defaults.js +5 -0
  82. package/packages/dd-trace/src/config/generated-config-types.d.ts +42 -2
  83. package/packages/dd-trace/src/config/index.js +17 -5
  84. package/packages/dd-trace/src/config/parsers.js +9 -0
  85. package/packages/dd-trace/src/config/supported-configurations.json +158 -4
  86. package/packages/dd-trace/src/constants.js +1 -0
  87. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
  88. package/packages/dd-trace/src/exporter.js +0 -11
  89. package/packages/dd-trace/src/exporters/common/request.js +81 -48
  90. package/packages/dd-trace/src/exporters/common/retry.js +12 -7
  91. package/packages/dd-trace/src/exporters/common/url.js +1 -1
  92. package/packages/dd-trace/src/id.js +1 -1
  93. package/packages/dd-trace/src/lambda/facade.js +74 -0
  94. package/packages/dd-trace/src/lambda/handler.js +3 -41
  95. package/packages/dd-trace/src/lambda/index.js +38 -15
  96. package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
  97. package/packages/dd-trace/src/lambda/wrap.js +44 -0
  98. package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
  99. package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
  100. package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
  101. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
  102. package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
  103. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
  104. package/packages/dd-trace/src/llmobs/sdk.js +19 -0
  105. package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
  106. package/packages/dd-trace/src/llmobs/tagger.js +22 -0
  107. package/packages/dd-trace/src/log/channels.js +4 -0
  108. package/packages/dd-trace/src/log/writer.js +6 -1
  109. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +4 -0
  110. package/packages/dd-trace/src/openfeature/configuration_source.js +35 -27
  111. package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
  112. package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
  113. package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
  114. package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
  115. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
  116. package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
  117. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
  118. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
  119. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
  120. package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
  121. package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
  122. package/packages/dd-trace/src/opentelemetry/span.js +2 -2
  123. package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
  124. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
  125. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
  126. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
  127. package/packages/dd-trace/src/opentracing/tracer.js +24 -0
  128. package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
  129. package/packages/dd-trace/src/plugin_manager.js +34 -7
  130. package/packages/dd-trace/src/plugins/ci_plugin.js +41 -10
  131. package/packages/dd-trace/src/plugins/index.js +6 -0
  132. package/packages/dd-trace/src/plugins/plugin.js +4 -2
  133. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  134. package/packages/dd-trace/src/plugins/util/ci.js +18 -1
  135. package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
  136. package/packages/dd-trace/src/plugins/util/git.js +263 -82
  137. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
  138. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
  139. package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
  140. package/packages/dd-trace/src/plugins/util/tags.js +6 -0
  141. package/packages/dd-trace/src/plugins/util/test.js +64 -39
  142. package/packages/dd-trace/src/plugins/util/url.js +10 -2
  143. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
  144. package/packages/dd-trace/src/plugins/util/web.js +65 -10
  145. package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
  146. package/packages/dd-trace/src/proxy.js +33 -53
  147. package/packages/dd-trace/src/span_processor.js +20 -0
  148. package/packages/dd-trace/src/startup-log.js +8 -6
  149. package/packages/dd-trace/src/telemetry/metrics.js +2 -1
  150. package/packages/dd-trace/src/tracer.js +0 -2
  151. package/packages/dd-trace/src/web-tags-cache.js +8 -9
  152. package/register.js +2 -1
  153. package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
  154. package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
  155. package/vendor/dist/@datadog/flagging-core/index.js +1 -0
  156. package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
  157. package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
  158. package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
  159. package/vendor/dist/@datadog/source-map/LICENSE +1 -0
  160. package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
  161. package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
  162. package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
  163. package/vendor/dist/escape-string-regexp/LICENSE +13 -0
  164. package/vendor/dist/esquery/LICENSE +2 -0
  165. package/vendor/dist/https-proxy-agent/LICENSE +80 -1
  166. package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
  167. package/vendor/dist/jest-docblock/LICENSE +16 -0
  168. package/vendor/dist/jsonpath-plus/LICENSE +13 -0
  169. package/vendor/dist/limiter/LICENSE +2 -0
  170. package/vendor/dist/lodash.sortby/LICENSE +2 -0
  171. package/vendor/dist/lru-cache/LICENSE +13 -0
  172. package/vendor/dist/meriyah/LICENSE +13 -0
  173. package/vendor/dist/module-details-from-path/LICENSE +2 -0
  174. package/vendor/dist/mutexify/promise/LICENSE +28 -0
  175. package/vendor/dist/pprof-format/LICENSE +13 -0
  176. package/vendor/dist/pprof-format/index.js +1 -1
  177. package/vendor/dist/protobufjs/LICENSE +219 -0
  178. package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
  179. package/vendor/dist/proxy-from-env/LICENSE +13 -0
  180. package/vendor/dist/retry/LICENSE +2 -0
  181. package/vendor/dist/rfdc/LICENSE +2 -0
  182. package/vendor/dist/semifies/LICENSE +3 -1
  183. package/vendor/dist/shell-quote/LICENSE +3 -1
  184. package/vendor/dist/source-map/LICENSE +1 -0
  185. package/vendor/dist/source-map/lib/util/LICENSE +1 -0
  186. package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
  187. package/vendor/dist/ttl-set/LICENSE +28 -0
  188. package/ci/diagnose.js +0 -2215
  189. package/ci/runbook.md +0 -299
  190. package/ci/test-optimization-validation/approval-artifacts.js +0 -175
  191. package/ci/test-optimization-validation/approval.js +0 -386
  192. package/ci/test-optimization-validation/artifact-id.js +0 -18
  193. package/ci/test-optimization-validation/blocker-category.js +0 -24
  194. package/ci/test-optimization-validation/bounded-json.js +0 -120
  195. package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
  196. package/ci/test-optimization-validation/ci-discovery.js +0 -192
  197. package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
  198. package/ci/test-optimization-validation/ci-remediation.js +0 -283
  199. package/ci/test-optimization-validation/cli.js +0 -954
  200. package/ci/test-optimization-validation/command-blocker.js +0 -377
  201. package/ci/test-optimization-validation/command-output-policy.js +0 -188
  202. package/ci/test-optimization-validation/command-runner.js +0 -649
  203. package/ci/test-optimization-validation/environment.js +0 -88
  204. package/ci/test-optimization-validation/executable-approval.js +0 -47
  205. package/ci/test-optimization-validation/executable.js +0 -244
  206. package/ci/test-optimization-validation/execution-lock.js +0 -70
  207. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
  208. package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
  209. package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
  210. package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
  211. package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
  212. package/ci/test-optimization-validation/generated-file-policy.js +0 -63
  213. package/ci/test-optimization-validation/generated-files.js +0 -425
  214. package/ci/test-optimization-validation/generated-test-contract.js +0 -284
  215. package/ci/test-optimization-validation/generated-verifier.js +0 -235
  216. package/ci/test-optimization-validation/literal-environment.js +0 -56
  217. package/ci/test-optimization-validation/literal-glob.js +0 -52
  218. package/ci/test-optimization-validation/manifest-loader.js +0 -116
  219. package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
  220. package/ci/test-optimization-validation/manifest-schema.js +0 -695
  221. package/ci/test-optimization-validation/offline-fixtures.js +0 -335
  222. package/ci/test-optimization-validation/offline-output.js +0 -406
  223. package/ci/test-optimization-validation/package-check.js +0 -97
  224. package/ci/test-optimization-validation/payload-normalizer.js +0 -72
  225. package/ci/test-optimization-validation/plan-writer.js +0 -541
  226. package/ci/test-optimization-validation/preflight-runner.js +0 -186
  227. package/ci/test-optimization-validation/project-build-artifact.js +0 -31
  228. package/ci/test-optimization-validation/redaction.js +0 -319
  229. package/ci/test-optimization-validation/report-writer.js +0 -666
  230. package/ci/test-optimization-validation/result-semantics.js +0 -103
  231. package/ci/test-optimization-validation/runner-command.js +0 -264
  232. package/ci/test-optimization-validation/runner-contract.js +0 -695
  233. package/ci/test-optimization-validation/safe-files.js +0 -202
  234. package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
  235. package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
  236. package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
  237. package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
  238. package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
  239. package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
  240. package/ci/test-optimization-validation/source-text.js +0 -84
  241. package/ci/test-optimization-validation/static-diagnosis.js +0 -166
  242. package/ci/test-optimization-validation/test-output.js +0 -120
  243. package/ci/test-optimization-validation/validation-blocker.js +0 -21
  244. package/ci/validate-test-optimization.js +0 -3
  245. package/packages/datadog-esbuild/src/resolver.js +0 -284
  246. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
  247. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
  248. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
  249. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
  250. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
@@ -1,202 +0,0 @@
1
- 'use strict'
2
-
3
- const crypto = require('node:crypto')
4
- const fs = require('node:fs')
5
- const path = require('node:path')
6
-
7
- /**
8
- * Creates a directory while refusing symlink components and paths outside the allowed root.
9
- *
10
- * @param {string} root allowed root
11
- * @param {string} directory directory to create or validate
12
- * @param {string} label customer-facing path label
13
- * @param {{allowRootSymlink?: boolean}} [options] validation options
14
- */
15
- function ensureSafeDirectory (root, directory, label, options = {}) {
16
- const lexicalRoot = path.resolve(root)
17
- const resolvedDirectory = path.resolve(directory)
18
- const rootStat = fs.lstatSync(lexicalRoot)
19
- if (rootStat.isSymbolicLink() && !options.allowRootSymlink) {
20
- throw new Error(`Refusing ${label} because its allowed root is a symbolic link: ${lexicalRoot}`)
21
- }
22
- if (!rootStat.isDirectory() && !rootStat.isSymbolicLink()) {
23
- throw new Error(`Refusing ${label} because its allowed root is not a directory: ${lexicalRoot}`)
24
- }
25
- if (!isPathInside(lexicalRoot, resolvedDirectory)) {
26
- throw new Error(`Refusing ${label} outside allowed root: ${resolvedDirectory}`)
27
- }
28
-
29
- let current = lexicalRoot
30
- const relative = path.relative(lexicalRoot, resolvedDirectory)
31
- for (const segment of relative ? relative.split(path.sep) : []) {
32
- current = path.join(current, segment)
33
- let stat
34
- try {
35
- stat = fs.lstatSync(current)
36
- } catch (error) {
37
- if (error.code !== 'ENOENT') throw error
38
- fs.mkdirSync(current)
39
- stat = fs.lstatSync(current)
40
- }
41
-
42
- if (stat.isSymbolicLink()) {
43
- throw new Error(`Refusing ${label} through symbolic link: ${current}`)
44
- }
45
- if (!stat.isDirectory()) {
46
- throw new Error(`Refusing ${label} through non-directory path: ${current}`)
47
- }
48
- }
49
-
50
- const physicalRoot = fs.realpathSync(lexicalRoot)
51
- const physicalDirectory = fs.realpathSync(resolvedDirectory)
52
- if (!isPathInside(physicalRoot, physicalDirectory)) {
53
- throw new Error(`Refusing ${label} outside physical allowed root: ${resolvedDirectory}`)
54
- }
55
- }
56
-
57
- /**
58
- * Writes a regular file without following a symbolic-link target.
59
- *
60
- * @param {string} root allowed root
61
- * @param {string} filename output filename
62
- * @param {string|Buffer} data output data
63
- * @param {string} label customer-facing path label
64
- */
65
- function writeFileSafely (root, filename, data, label) {
66
- const resolvedFilename = path.resolve(filename)
67
- const parent = path.dirname(resolvedFilename)
68
- ensureSafeDirectory(root, parent, label)
69
- const parentIdentity = getDirectoryIdentity(parent, label)
70
- const temporaryFilename = path.join(
71
- parent,
72
- `.${path.basename(filename)}.${crypto.randomBytes(12).toString('hex')}.tmp`
73
- )
74
-
75
- try {
76
- openAndWrite(root, temporaryFilename, data, label, fs.constants.O_EXCL)
77
- assertDirectoryIdentity(parent, parentIdentity, label)
78
- fs.renameSync(temporaryFilename, resolvedFilename)
79
- } catch (error) {
80
- removeTemporaryFile(temporaryFilename, parent, parentIdentity)
81
- throw error
82
- }
83
- }
84
-
85
- /**
86
- * Creates a new regular file without following or replacing an existing path.
87
- *
88
- * @param {string} root allowed root
89
- * @param {string} filename output filename
90
- * @param {string|Buffer} data output data
91
- * @param {string} label customer-facing path label
92
- */
93
- function createFileSafely (root, filename, data, label) {
94
- openAndWrite(root, filename, data, label, fs.constants.O_EXCL)
95
- }
96
-
97
- /**
98
- * Opens and writes a file with no-follow semantics.
99
- *
100
- * @param {string} root allowed root
101
- * @param {string} filename output filename
102
- * @param {string|Buffer} data output data
103
- * @param {string} label customer-facing path label
104
- * @param {number} creationFlag file creation mode
105
- */
106
- function openAndWrite (root, filename, data, label, creationFlag) {
107
- const resolvedFilename = path.resolve(filename)
108
- ensureSafeDirectory(root, path.dirname(resolvedFilename), label)
109
- refuseSymbolicLink(resolvedFilename, label)
110
-
111
- const flags = fs.constants.O_WRONLY |
112
- fs.constants.O_CREAT |
113
- creationFlag |
114
- (fs.constants.O_NOFOLLOW || 0)
115
- const file = fs.openSync(resolvedFilename, flags, 0o600)
116
- try {
117
- const stat = fs.fstatSync(file)
118
- if (!stat.isFile() || stat.nlink !== 1) {
119
- throw new Error(`Refusing ${label} because its output is not a private regular file: ${resolvedFilename}`)
120
- }
121
- fs.writeFileSync(file, data)
122
- } finally {
123
- fs.closeSync(file)
124
- }
125
- }
126
-
127
- /**
128
- * Captures one directory identity without accepting a symbolic link.
129
- *
130
- * @param {string} directory directory path
131
- * @param {string} label customer-facing path label
132
- * @returns {{dev: bigint, ino: bigint}} directory identity
133
- */
134
- function getDirectoryIdentity (directory, label) {
135
- const stat = fs.lstatSync(directory, { bigint: true })
136
- if (!stat.isDirectory() || stat.isSymbolicLink()) {
137
- throw new Error(`Refusing ${label} because its parent is not a regular directory: ${directory}`)
138
- }
139
- return { dev: stat.dev, ino: stat.ino }
140
- }
141
-
142
- /**
143
- * Refuses replacement of a parent directory between safe creation and publication.
144
- *
145
- * @param {string} directory directory path
146
- * @param {{dev: bigint, ino: bigint}} expected expected identity
147
- * @param {string} label customer-facing path label
148
- */
149
- function assertDirectoryIdentity (directory, expected, label) {
150
- const current = getDirectoryIdentity(directory, label)
151
- if (current.dev !== expected.dev || current.ino !== expected.ino) {
152
- throw new Error(`Refusing ${label} because its parent directory changed during the write: ${directory}`)
153
- }
154
- }
155
-
156
- /**
157
- * Removes only the validator-created temporary regular file or symbolic link.
158
- *
159
- * @param {string} filename temporary filename
160
- * @param {string} parent expected parent directory
161
- * @param {{dev: bigint, ino: bigint}} parentIdentity expected parent identity
162
- */
163
- function removeTemporaryFile (filename, parent, parentIdentity) {
164
- try {
165
- assertDirectoryIdentity(parent, parentIdentity, 'temporary file cleanup')
166
- const stat = fs.lstatSync(filename)
167
- if (stat.isFile() || stat.isSymbolicLink()) fs.unlinkSync(filename)
168
- } catch {}
169
- }
170
-
171
- /**
172
- * Refuses a final path component that is a symbolic link.
173
- *
174
- * @param {string} filename candidate filename
175
- * @param {string} label customer-facing path label
176
- */
177
- function refuseSymbolicLink (filename, label) {
178
- try {
179
- if (fs.lstatSync(filename).isSymbolicLink()) {
180
- throw new Error(`Refusing ${label} symbolic-link target: ${filename}`)
181
- }
182
- } catch (error) {
183
- if (error.code !== 'ENOENT') throw error
184
- }
185
- }
186
-
187
- /**
188
- * Checks lexical path containment.
189
- *
190
- * @param {string} root allowed root
191
- * @param {string} filename candidate path
192
- */
193
- function isPathInside (root, filename) {
194
- const relative = path.relative(root, filename)
195
- return relative === '' || (relative && !relative.startsWith('..') && !path.isAbsolute(relative))
196
- }
197
-
198
- module.exports = {
199
- createFileSafely,
200
- ensureSafeDirectory,
201
- writeFileSafely,
202
- }
@@ -1,171 +0,0 @@
1
- 'use strict'
2
-
3
- const {
4
- discoverScenarioTests,
5
- discoveryEvidence,
6
- error,
7
- failWithDebugRerun,
8
- pass,
9
- prepareGeneratedScenario,
10
- reportMissingGeneratedTest,
11
- requireGeneratedScenario,
12
- runInstrumentedCommand,
13
- skip,
14
- testEventSamples,
15
- testsForDiscoveredScenario,
16
- } = require('./helpers')
17
-
18
- async function runAutoTestRetries ({ framework, out, options }) {
19
- const scenarioName = 'atr'
20
- if (isUnsupportedCucumberVersion(framework)) {
21
- return skip(
22
- framework,
23
- scenarioName,
24
- 'Auto Test Retries validation requires @cucumber/cucumber >=8.0.0. Basic Reporting and other eligible ' +
25
- `checks remain available for detected version ${framework.frameworkVersion}.`,
26
- {
27
- featureEligibility: {
28
- eligible: false,
29
- blockedBy: 'framework-version',
30
- reasonCode: 'cucumber-atr-version-unsupported',
31
- requiredVersion: '>=8.0.0',
32
- detectedVersion: framework.frameworkVersion,
33
- scenario: scenarioName,
34
- },
35
- }
36
- )
37
- }
38
- const skipResult = requireGeneratedScenario(framework, 'atr-fail-once', scenarioName)
39
- if (skipResult) return skipResult
40
-
41
- let outDir
42
- try {
43
- const { scenario } = await prepareGeneratedScenario(framework, 'atr-fail-once')
44
- const discovery = await discoverScenarioTests({ framework, out, scenarioName, scenario, options })
45
- if (discovery.tests.length === 0) {
46
- return reportMissingGeneratedTest({
47
- command: scenario.runCommand,
48
- diagnosis: 'The fail-once generated test was not reported during baseline identity discovery.',
49
- discovery,
50
- framework,
51
- options,
52
- out,
53
- scenario,
54
- scenarioName,
55
- })
56
- }
57
-
58
- const fixtureConfig = {
59
- settings: {
60
- flaky_test_retries_enabled: true,
61
- },
62
- }
63
-
64
- const run = await runInstrumentedCommand({
65
- framework,
66
- out,
67
- scenarioName,
68
- command: scenario.runCommand,
69
- options,
70
- fixtureConfig,
71
- })
72
- outDir = run.outDir
73
-
74
- const tests = testsForDiscoveredScenario(run.events, scenario, discovery)
75
- const autoTestRetryEvents = tests.filter(test => test.retryReason === 'auto_test_retry')
76
- const externalRetryEvents = tests.filter(test => test.isRetry && test.retryReason !== 'auto_test_retry')
77
- const evidence = {
78
- ...discoveryEvidence(discovery),
79
- commandExitCode: run.result.exitCode,
80
- settingsLoadedFromCache: run.offline.inputs.settings?.status === 'loaded',
81
- matchingTestEvents: tests.length,
82
- autoTestRetryEvents: autoTestRetryEvents.length,
83
- externalRetryEvents: externalRetryEvents.length,
84
- failedAttempts: tests.filter(test => test.testStatus === 'fail' || test.error === 1).length,
85
- passedAttempts: tests.filter(test => test.testStatus === 'pass').length,
86
- samples: testEventSamples(tests),
87
- }
88
-
89
- if (!evidence.settingsLoadedFromCache) {
90
- return failWithDebugRerun({
91
- command: scenario.runCommand,
92
- fixtureConfig,
93
- diagnosis: 'Auto Test Retries settings were not loaded from the offline cache fixture.',
94
- evidence,
95
- framework,
96
- options,
97
- out,
98
- outDir,
99
- scenarioName,
100
- })
101
- }
102
-
103
- if (run.result.exitCode !== 0 || tests.length < 2 || autoTestRetryEvents.length === 0) {
104
- return failWithDebugRerun({
105
- command: scenario.runCommand,
106
- fixtureConfig,
107
- diagnosis: getAutoTestRetriesFailureDiagnosis(framework, evidence),
108
- evidence,
109
- framework,
110
- options,
111
- out,
112
- outDir,
113
- scenarioName,
114
- })
115
- }
116
-
117
- return pass(
118
- framework,
119
- scenarioName,
120
- 'The fail-once generated test was retried and the command passed.',
121
- evidence,
122
- outDir
123
- )
124
- } catch (err) {
125
- return error(framework, scenarioName, err, outDir)
126
- }
127
- }
128
-
129
- function isUnsupportedCucumberVersion (framework) {
130
- if (framework.framework !== 'cucumber') return false
131
- const major = Number.parseInt(String(framework.frameworkVersion || '').split('.')[0], 10)
132
- return Number.isInteger(major) && major < 8
133
- }
134
-
135
- function getAutoTestRetriesFailureDiagnosis (framework, evidence) {
136
- const frameworkName = getFrameworkName(framework)
137
- const retryTagSummary = getRetryTagSummary(evidence.autoTestRetryEvents)
138
- if (evidence.autoTestRetryEvents > 0 || evidence.failedAttempts > 1) {
139
- return 'Auto Test Retries executed for the generated test, but every attempt failed. Observed ' +
140
- `${formatAttemptCount(evidence.failedAttempts, 'failed')}, ` +
141
- `${formatAttemptCount(evidence.passedAttempts, 'passed retry')}, and ${retryTagSummary}. ` +
142
- 'Review the generated test failure because retry execution itself was observed.'
143
- }
144
- return 'Auto Test Retries was enabled, and the generated failing test was reported, but ' +
145
- `${frameworkName} ` +
146
- `did not execute a retry attempt. Observed ${formatAttemptCount(evidence.failedAttempts, 'failed')}, ` +
147
- `${formatAttemptCount(evidence.passedAttempts, 'passed retry')}, and ${retryTagSummary}.`
148
- }
149
-
150
- function formatAttemptCount (count, label) {
151
- return `${count} ${label} attempt${count === 1 ? '' : 's'}`
152
- }
153
-
154
- function getRetryTagSummary (count) {
155
- if (count === 0) return 'no test.retry_reason=auto_test_retry tag'
156
- if (count === 1) return '1 event tagged with test.retry_reason=auto_test_retry'
157
- return `${count} events tagged with test.retry_reason=auto_test_retry`
158
- }
159
-
160
- function getFrameworkName (framework) {
161
- return {
162
- cucumber: 'Cucumber',
163
- cypress: 'Cypress',
164
- jest: 'Jest',
165
- mocha: 'Mocha',
166
- playwright: 'Playwright',
167
- vitest: 'Vitest',
168
- }[framework.framework] || 'the test runner'
169
- }
170
-
171
- module.exports = { getAutoTestRetriesFailureDiagnosis, runAutoTestRetries }