dd-trace 5.134.0 → 5.135.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 (168) hide show
  1. package/LICENSE-3rdparty.csv +0 -1
  2. package/ci/cypress/support.js +15 -1
  3. package/ci/diagnose.js +4 -4
  4. package/ci/test-annotations.d.ts +5 -0
  5. package/ci/test-annotations.js +5 -0
  6. package/ci/test-optimization-validation/approval-artifacts.js +2 -2
  7. package/ci/test-optimization-validation/approval.js +2 -2
  8. package/ci/test-optimization-validation/artifact-id.js +2 -3
  9. package/ci/test-optimization-validation/ci-package-scripts.js +1 -1
  10. package/ci/test-optimization-validation/cli.js +1 -1
  11. package/ci/test-optimization-validation/command-runner.js +2 -3
  12. package/ci/test-optimization-validation/executable.js +1 -1
  13. package/ci/test-optimization-validation/framework-adapters/cucumber.js +1 -1
  14. package/ci/test-optimization-validation/literal-environment.js +2 -2
  15. package/ci/test-optimization-validation/manifest-scaffold.js +1 -1
  16. package/ci/test-optimization-validation/offline-fixtures.js +1 -1
  17. package/ci/test-optimization-validation/redaction.js +3 -3
  18. package/ci/test-optimization-validation/runner-contract.js +10 -10
  19. package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -1
  20. package/ci/vitest-no-worker-init-annotations.mjs +4 -0
  21. package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
  22. package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
  23. package/ci/vitest-no-worker-init-setup.mjs +34 -12
  24. package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
  25. package/ext/exporters.js +1 -0
  26. package/index.d.ts +19 -0
  27. package/loader-hook.mjs +53 -0
  28. package/openfeature/exposure-hook.d.ts +66 -0
  29. package/openfeature/exposure-hook.js +5 -0
  30. package/package.json +11 -9
  31. package/packages/datadog-core/src/storage.js +1 -1
  32. package/packages/datadog-esbuild/index.js +70 -7
  33. package/packages/datadog-instrumentations/src/cucumber.js +53 -19
  34. package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
  35. package/packages/datadog-instrumentations/src/graphql.js +9 -3
  36. package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
  37. package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
  38. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
  39. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -1
  40. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +16 -6
  41. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +8 -0
  42. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
  43. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
  44. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
  45. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
  46. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +8 -0
  47. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
  48. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +8 -0
  49. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +1 -1
  50. package/packages/datadog-instrumentations/src/jest.js +265 -82
  51. package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
  52. package/packages/datadog-instrumentations/src/mariadb.js +13 -6
  53. package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
  54. package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
  55. package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
  56. package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
  57. package/packages/datadog-instrumentations/src/oracledb.js +33 -0
  58. package/packages/datadog-instrumentations/src/pg.js +2 -1
  59. package/packages/datadog-instrumentations/src/playwright.js +81 -28
  60. package/packages/datadog-instrumentations/src/react-router.js +106 -0
  61. package/packages/datadog-instrumentations/src/typesafe.js +89 -0
  62. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
  63. package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
  64. package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
  65. package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
  66. package/packages/datadog-instrumentations/src/vitest.js +10 -8
  67. package/packages/datadog-plugin-cucumber/src/index.js +5 -0
  68. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +274 -44
  69. package/packages/datadog-plugin-cypress/src/index.js +1 -1
  70. package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
  71. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  72. package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
  73. package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
  74. package/packages/datadog-plugin-cypress/src/support.js +1217 -439
  75. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  76. package/packages/datadog-plugin-graphql/src/utils.js +5 -5
  77. package/packages/datadog-plugin-jest/src/index.js +25 -3
  78. package/packages/datadog-plugin-mocha/src/index.js +47 -6
  79. package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
  80. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  81. package/packages/datadog-plugin-react-router/src/index.js +118 -0
  82. package/packages/datadog-plugin-typesafe/src/index.js +17 -0
  83. package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
  84. package/packages/datadog-plugin-vitest/src/index.js +8 -0
  85. package/packages/dd-trace/src/agent/info.js +2 -1
  86. package/packages/dd-trace/src/aiguard/sdk.js +0 -11
  87. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +9 -16
  88. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
  89. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +9 -16
  90. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
  91. package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
  92. package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
  93. package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
  94. package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
  95. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +9 -16
  96. package/packages/dd-trace/src/config/defaults.js +4 -3
  97. package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -0
  98. package/packages/dd-trace/src/config/index.js +95 -39
  99. package/packages/dd-trace/src/config/parsers.js +9 -1
  100. package/packages/dd-trace/src/config/supported-configurations.json +16 -0
  101. package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
  102. package/packages/dd-trace/src/encode/0.4.js +2 -2
  103. package/packages/dd-trace/src/esm-module-load.js +58 -0
  104. package/packages/dd-trace/src/exporter.js +25 -6
  105. package/packages/dd-trace/src/exporters/agent/index.js +3 -1
  106. package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
  107. package/packages/dd-trace/src/exporters/common/request.js +4 -4
  108. package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
  109. package/packages/dd-trace/src/exporters/log/index.js +4 -3
  110. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  111. package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
  112. package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
  113. package/packages/dd-trace/src/llmobs/index.js +13 -2
  114. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
  115. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
  116. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +8 -4
  117. package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
  118. package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
  119. package/packages/dd-trace/src/llmobs/sdk.js +2 -1
  120. package/packages/dd-trace/src/llmobs/span_processor.js +210 -12
  121. package/packages/dd-trace/src/llmobs/tagger.js +3 -0
  122. package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
  123. package/packages/dd-trace/src/log/writer.js +7 -1
  124. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +64 -6
  125. package/packages/dd-trace/src/openfeature/configuration_source.js +18 -2
  126. package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
  127. package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
  128. package/packages/dd-trace/src/openfeature/flagging_provider.js +39 -13
  129. package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
  130. package/packages/dd-trace/src/openfeature/writers/base.js +62 -27
  131. package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
  132. package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
  133. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
  134. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
  135. package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
  136. package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
  137. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
  138. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
  139. package/packages/dd-trace/src/opentracing/tracer.js +9 -13
  140. package/packages/dd-trace/src/otel-thread-ctx.js +47 -21
  141. package/packages/dd-trace/src/plugins/ci_plugin.js +4 -4
  142. package/packages/dd-trace/src/plugins/index.js +3 -0
  143. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  144. package/packages/dd-trace/src/plugins/util/git.js +11 -5
  145. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -4
  146. package/packages/dd-trace/src/plugins/util/test.js +26 -6
  147. package/packages/dd-trace/src/plugins/util/web.js +16 -0
  148. package/packages/dd-trace/src/process-tags/index.js +1 -1
  149. package/packages/dd-trace/src/profiling/config.js +6 -3
  150. package/packages/dd-trace/src/proxy.js +15 -4
  151. package/packages/dd-trace/src/serverless.js +3 -2
  152. package/packages/dd-trace/src/span_processor.js +21 -9
  153. package/packages/dd-trace/src/span_stats.js +28 -2
  154. package/packages/dd-trace/src/startup-log.js +2 -1
  155. package/packages/dd-trace/src/tagger.js +7 -5
  156. package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
  157. package/packages/dd-trace/src/telemetry/index.js +3 -0
  158. package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
  159. package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
  160. package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
  161. package/packages/dd-trace/src/util.js +1 -1
  162. package/register.js +2 -1
  163. package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
  164. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
  165. package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
  166. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  167. package/vendor/dist/@opentelemetry/resources/LICENSE +0 -201
  168. package/vendor/dist/@opentelemetry/resources/index.js +0 -1
@@ -3,6 +3,7 @@
3
3
  // Capture real timers at module load, before any test can install fake timers.
4
4
  const { performance } = require('perf_hooks')
5
5
  const { basename } = require('node:path')
6
+ const { isDeepStrictEqual } = require('node:util')
6
7
  const dateNow = Date.now
7
8
 
8
9
  const { createCoverageMap } = require('../../../vendor/dist/istanbul-lib-coverage')
@@ -67,6 +68,8 @@ const {
67
68
  TEST_MANAGEMENT_ENABLED,
68
69
  TEST_MANAGEMENT_IS_DISABLED,
69
70
  TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX,
71
+ TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION,
72
+ TEST_MANAGEMENT_NO_AUTO_RETRY,
70
73
  TEST_MANAGEMENT_ATTEMPT_TO_FIX_PASSED,
71
74
  TEST_HAS_FAILED_ALL_RETRIES,
72
75
  getLibraryCapabilitiesTags,
@@ -147,6 +150,8 @@ const {
147
150
  RUNTIME_VERSION,
148
151
  } = require('../../dd-trace/src/plugins/util/env')
149
152
  const { DD_MAJOR } = require('../../../version')
153
+ const observeRetryConfig = require('./retry-config-observer')
154
+ const observeSetupHandoff = require('./setup-handoff')
150
155
  const {
151
156
  resolveOriginalSourceFile,
152
157
  resolveSourceLineForTest,
@@ -420,7 +425,8 @@ function getFinalStatusRetryKind ({
420
425
  return FINAL_STATUS_RETRY_KIND.efd
421
426
  }
422
427
 
423
- if (finishedTestAttempts.length > 1 && (isDynamicAtrEnabled || flakyTestRetriesCount > 0)) {
428
+ if (!finishedTest.noAutoRetry && finishedTestAttempts.length > 1 &&
429
+ (isDynamicAtrEnabled || flakyTestRetriesCount > 0)) {
424
430
  return FINAL_STATUS_RETRY_KIND.atr
425
431
  }
426
432
 
@@ -453,6 +459,61 @@ function getFinalStatus ({
453
459
  }
454
460
  }
455
461
 
462
+ /**
463
+ * Copies retry configuration without sharing nested experimental options with user code.
464
+ *
465
+ * @template T
466
+ * @param {T} retries
467
+ * @returns {T}
468
+ */
469
+ function copyCypressRetries (retries) {
470
+ // Cypress 6 supports Node.js 12, which does not provide structuredClone.
471
+ // eslint-disable-next-line unicorn/prefer-structured-clone
472
+ return retries !== null && typeof retries === 'object' ? JSON.parse(JSON.stringify(retries)) : retries
473
+ }
474
+
475
+ // Cypress treats omitted/undefined object fields as defaults, while null replaces them.
476
+ function mergeNativeRetries (baseline, supplied) {
477
+ if (supplied === undefined) return copyCypressRetries(baseline)
478
+ if (!supplied || typeof supplied !== 'object') return supplied
479
+ const result = baseline && typeof baseline === 'object' ? copyCypressRetries(baseline) : {}
480
+ for (const key of Object.keys(supplied)) result[key] = mergeNativeRetries(result[key], supplied[key])
481
+ return result
482
+ }
483
+
484
+ function updateNativeRetries (native, baseline, supplied, path) {
485
+ if (!path.length) return mergeNativeRetries(baseline, supplied)
486
+ if (typeof native === 'number') native = { runMode: native, openMode: native }
487
+ if (typeof baseline === 'number') baseline = { runMode: baseline, openMode: baseline }
488
+ const [key, ...rest] = path
489
+ const result = native && typeof native === 'object' ? copyCypressRetries(native) : {}
490
+ result[key] = updateNativeRetries(result[key], baseline && baseline[key], supplied && supplied[key], rest)
491
+ return result
492
+ }
493
+
494
+ function reconcileNativeRetries (native, baseline, configured, actual) {
495
+ if (isDeepStrictEqual(configured, actual)) return native
496
+ if (!actual || typeof actual !== 'object' || !configured || typeof configured !== 'object') {
497
+ return mergeNativeRetries(baseline, actual)
498
+ }
499
+ if (typeof native === 'number') native = { runMode: native, openMode: native }
500
+ if (typeof baseline === 'number') baseline = { runMode: baseline, openMode: baseline }
501
+ const result = native && typeof native === 'object' ? copyCypressRetries(native) : {}
502
+ for (const key of Object.keys(actual)) {
503
+ if (!isDeepStrictEqual(configured[key], actual[key])) {
504
+ result[key] = reconcileNativeRetries(result[key], baseline && baseline[key], configured[key], actual[key])
505
+ }
506
+ }
507
+ for (const key of Object.keys(configured)) {
508
+ // Cypress 6's plugin process uses Node 12, which predates Object.hasOwn.
509
+ // eslint-disable-next-line prefer-object-has-own
510
+ if (!Object.prototype.hasOwnProperty.call(actual, key)) {
511
+ result[key] = copyCypressRetries(baseline && baseline[key])
512
+ }
513
+ }
514
+ return result
515
+ }
516
+
456
517
  class CypressPlugin {
457
518
  #pendingTestSuiteSpans = new Map()
458
519
 
@@ -489,6 +550,7 @@ class CypressPlugin {
489
550
  hasForcedToRunSuites = false
490
551
  hasUnskippableSuites = false
491
552
  unskippableSuites = []
553
+ testAnnotationsBySuite = new Map()
492
554
  knownTests = []
493
555
  isTestManagementTestsEnabled = false
494
556
  testManagementAttemptToFixRetries = 0
@@ -556,6 +618,7 @@ class CypressPlugin {
556
618
  this.#pendingTestSuiteSpans.clear()
557
619
  this._isInit = false
558
620
  this.finishedTestsByFile = {}
621
+ this.resolvedCypressRetries = undefined
559
622
  this.hasTestsReported = false
560
623
  this.testSuiteStatuses = new Set()
561
624
  this.testStatuses = {}
@@ -590,6 +653,7 @@ class CypressPlugin {
590
653
  this.isTestManagementTestsEnabled = false
591
654
  this.testManagementAttemptToFixRetries = 0
592
655
  this.testManagementTests = undefined
656
+ this.testAnnotationsBySuite = new Map()
593
657
  this.isImpactedTestsEnabled = false
594
658
  this.modifiedFiles = []
595
659
  this.attemptToFixExecutions = new Map()
@@ -839,17 +903,24 @@ class CypressPlugin {
839
903
  // Depending on the received configuration, the Cypress configuration can be modified:
840
904
  // for example, to enable retries for failed tests.
841
905
  init (tracer, cypressConfig) {
842
- if (this.cypressConfig === cypressConfig && this.hasOriginalCypressRetries) {
843
- cypressConfig.retries = this.originalCypressRetries !== null &&
844
- typeof this.originalCypressRetries === 'object'
845
- ? { ...this.originalCypressRetries }
846
- : this.originalCypressRetries
906
+ this.retryConfigObserver?.stop()
907
+ this.retryConfigObserver = undefined
908
+ this.stopSetupHandoff?.()
909
+ this.stopSetupHandoff = undefined
910
+ const isReusedConfig = this.cypressConfig === cypressConfig && this.hasOriginalCypressRetries
911
+ const retryDescriptor = Object.getOwnPropertyDescriptor(cypressConfig, 'retries')
912
+ if (retryDescriptor && !retryDescriptor.writable && !retryDescriptor.set) {
913
+ // Setup may make the retry root read-only before initial or repeated use.
914
+ // Work on a private copy without changing the external retry descriptor.
915
+ cypressConfig = { ...cypressConfig }
916
+ }
917
+ if (isReusedConfig) {
918
+ cypressConfig.retries = copyCypressRetries(this.originalCypressRetries)
847
919
  } else {
848
- this.originalCypressRetries = cypressConfig.retries !== null && typeof cypressConfig.retries === 'object'
849
- ? { ...cypressConfig.retries }
850
- : cypressConfig.retries
920
+ this.originalCypressRetries = copyCypressRetries(cypressConfig.retries)
851
921
  this.hasOriginalCypressRetries = true
852
922
  }
923
+ this.nativeCypressRetriesBaseline = copyCypressRetries(cypressConfig.retries)
853
924
  this.resetRunState()
854
925
  this._isInit = true
855
926
  this.tracer = tracer
@@ -878,8 +949,47 @@ class CypressPlugin {
878
949
  tracer._tracer._config.isServiceUserProvided ? 'true' : 'false'
879
950
 
880
951
  this._pendingRequestErrorTags = []
952
+ const handoff = { seen: false, hasReply: false, retries: undefined }
953
+ const stopSetupHandoff = observeSetupHandoff((returnedConfig, event) => {
954
+ handoff.seen = true
955
+ if (event === 'setupTestingType:reply') {
956
+ handoff.hasReply = true
957
+ const retryProperty = returnedConfig && Object.getOwnPropertyDescriptor(returnedConfig, 'retries')
958
+ handoff.retries = mergeNativeRetries(
959
+ this.nativeCypressRetriesBaseline, retryProperty?.enumerable ? returnedConfig.retries : undefined
960
+ )
961
+ }
962
+ })
963
+ this.stopSetupHandoff = stopSetupHandoff
881
964
  this.libraryConfigurationPromise = getLibraryConfiguration(this.tracer, this.testConfiguration)
882
965
  .then((libraryConfigurationResponse) => {
966
+ stopSetupHandoff()
967
+ if (this.stopSetupHandoff === stopSetupHandoff) this.stopSetupHandoff = undefined
968
+ if (handoff.hasReply) {
969
+ // Keep the serialized retry snapshot independent of later child-local writes.
970
+ const properties = Object.getOwnPropertyDescriptors(this.cypressConfig)
971
+ for (const key of Reflect.ownKeys(properties)) {
972
+ const property = properties[key]
973
+ property.configurable = true
974
+ if ('value' in property) property.writable = true
975
+ }
976
+ properties.retries = {
977
+ value: copyCypressRetries(handoff.retries), enumerable: true, configurable: true, writable: true,
978
+ }
979
+ this.cypressConfig = Object.defineProperties({}, properties)
980
+ }
981
+ // Manual setup can make retries read-only while settings are pending.
982
+ // Keep later SDK writes private without changing the user's retry descriptor.
983
+ const pendingRetryDescriptor = Object.getOwnPropertyDescriptor(this.cypressConfig, 'retries')
984
+ if (pendingRetryDescriptor && !pendingRetryDescriptor.writable && !pendingRetryDescriptor.set) {
985
+ this.cypressConfig = { ...this.cypressConfig }
986
+ }
987
+ // Setup can change native retries while backend settings are resolving.
988
+ // Capture them before the first SDK retry write, including on settings errors.
989
+ this.cypressConfig.retries = mergeNativeRetries(
990
+ this.nativeCypressRetriesBaseline, this.cypressConfig.retries
991
+ )
992
+ this.originalCypressRetries = copyCypressRetries(this.cypressConfig.retries)
883
993
  if (libraryConfigurationResponse.err) {
884
994
  log.error('Cypress plugin library config response error', libraryConfigurationResponse.err)
885
995
  this._pendingRequestErrorTags.push({
@@ -928,15 +1038,36 @@ class CypressPlugin {
928
1038
  }
929
1039
  // Dynamic ATR starts at the maximum budget, then narrows each test
930
1040
  // after its initial duration is known.
931
- if (this.isDynamicAtrEnabled) {
932
- this.cypressConfig.retries.runMode = Math.max(
1041
+ const retryCount = this.isDynamicAtrEnabled
1042
+ ? Math.max(
933
1043
  1,
934
1044
  this.dynamicAtrBuckets
935
1045
  ? Math.max(...this.dynamicAtrBuckets)
936
1046
  : this.earlyFlakeDetectionRetryPolicy.schedulingRetryCount
937
1047
  )
1048
+ : this.flakyTestRetriesCount
1049
+ if (this.cypressConfig.retries.experimentalStrategy) {
1050
+ if (this.cypressConfig.isTextTerminal !== false) {
1051
+ if (this.cypressConfig.retries.runMode === true) {
1052
+ // Keep an active native strategy and its budget floor.
1053
+ this.cypressConfig.retries.experimentalOptions = {
1054
+ ...this.cypressConfig.retries.experimentalOptions,
1055
+ maxRetries: Math.max(this.cypressConfig.retries.experimentalOptions?.maxRetries ?? 0, retryCount),
1056
+ }
1057
+ } else if (retryCount > 0) {
1058
+ // An inactive experimental strategy must not change ordinary ATR policy.
1059
+ const { openMode, experimentalOptions } = this.cypressConfig.retries
1060
+ this.cypressConfig.retries = {
1061
+ // Explicit nulls prevent Cypress's config merge from retaining inactive options.
1062
+ experimentalStrategy: null,
1063
+ experimentalOptions: null,
1064
+ openMode: openMode === true ? experimentalOptions?.maxRetries ?? 0 : 0,
1065
+ runMode: retryCount,
1066
+ }
1067
+ }
1068
+ }
938
1069
  } else {
939
- this.cypressConfig.retries.runMode = this.flakyTestRetriesCount
1070
+ this.cypressConfig.retries.runMode = retryCount
940
1071
  }
941
1072
  } else {
942
1073
  this.flakyTestRetriesCount = 0
@@ -945,6 +1076,20 @@ class CypressPlugin {
945
1076
  this.testManagementAttemptToFixRetries = testManagementAttemptToFixRetries
946
1077
  this.isImpactedTestsEnabled = isImpactedTestsEnabled
947
1078
  }
1079
+ this.configuredCypressRetries = copyCypressRetries(this.cypressConfig.retries)
1080
+ if (!handoff.seen) {
1081
+ this.retryConfigObserver = observeRetryConfig(this.cypressConfig, (retries, path, provenance) => {
1082
+ this.originalCypressRetries = copyCypressRetries(provenance.retries)
1083
+ }, {
1084
+ nativeRetries: copyCypressRetries(this.originalCypressRetries),
1085
+ reconcileNative: (native, observed, actual) => reconcileNativeRetries(
1086
+ native, this.nativeCypressRetriesBaseline, observed, actual
1087
+ ),
1088
+ updateNative: (native, retries, path) => updateNativeRetries(
1089
+ native, this.nativeCypressRetriesBaseline, retries, path
1090
+ ),
1091
+ })
1092
+ }
948
1093
  return this.cypressConfig
949
1094
  })
950
1095
  return this.libraryConfigurationPromise
@@ -1001,8 +1146,9 @@ class CypressPlugin {
1001
1146
  * @param {string} testSuite
1002
1147
  * @param {string} testId
1003
1148
  * @param {number | undefined} duration
1149
+ * @param {number} [nativeRetryFloor]
1004
1150
  */
1005
- setDynamicAtrRetryCountForTest (testSuite, testId, duration) {
1151
+ setDynamicAtrRetryCountForTest (testSuite, testId, duration, nativeRetryFloor = 0) {
1006
1152
  if (!this.dynamicAtrRetryCountByTest) {
1007
1153
  this.dynamicAtrRetryCountByTest = new Map()
1008
1154
  }
@@ -1011,11 +1157,11 @@ class CypressPlugin {
1011
1157
  retryCountByTestId = new Map()
1012
1158
  this.dynamicAtrRetryCountByTest.set(testSuite, retryCountByTestId)
1013
1159
  }
1014
- const retryCount = getDynamicAtrRetryCount(
1160
+ const retryCount = Math.max(nativeRetryFloor, getDynamicAtrRetryCount(
1015
1161
  duration ?? 0,
1016
1162
  this.earlyFlakeDetectionRetryPolicy,
1017
1163
  this.dynamicAtrBuckets
1018
- )
1164
+ ))
1019
1165
  retryCountByTestId.set(testId, retryCount)
1020
1166
  return retryCount
1021
1167
  }
@@ -1079,7 +1225,8 @@ class CypressPlugin {
1079
1225
  }
1080
1226
 
1081
1227
  getTestSpan ({
1082
- testName, testSuite, isUnskippable, isForcedToRun, testSourceFile, isDisabled, isQuarantined, startTime,
1228
+ testName, testSuite, isUnskippable, isForcedToRun, testSourceFile, isDisabled, isQuarantined,
1229
+ isAttemptToFix, annotations, startTime,
1083
1230
  }) {
1084
1231
  const testSuiteTags = {
1085
1232
  [TEST_MODULE]: TEST_FRAMEWORK_NAME,
@@ -1125,6 +1272,10 @@ class CypressPlugin {
1125
1272
  testSpanMetadata[TEST_ITR_FORCED_RUN] = 'true'
1126
1273
  }
1127
1274
 
1275
+ if (annotations && annotations.mustFail) testSpanMetadata[TEST_MANAGEMENT_PREVENT_FAILURE_SUPPRESSION] = 'true'
1276
+ if (annotations && annotations.noAutoRetry) testSpanMetadata[TEST_MANAGEMENT_NO_AUTO_RETRY] = 'true'
1277
+ if (isAttemptToFix) testSpanMetadata[TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX] = 'true'
1278
+
1128
1279
  if (isDisabled) {
1129
1280
  testSpanMetadata[TEST_MANAGEMENT_IS_DISABLED] = 'true'
1130
1281
  }
@@ -1176,6 +1327,15 @@ class CypressPlugin {
1176
1327
  }
1177
1328
 
1178
1329
  async beforeRun (details) {
1330
+ this.retryConfigObserver?.stop()
1331
+ // Manual setup can change the developer budget after awaiting init. Capture it
1332
+ // before interactive reinitialization can restore the previous native value.
1333
+ const finalRetries = copyCypressRetries(details.config?.retries ?? this.cypressConfig?.retries)
1334
+ if (!this._isInit && !isDeepStrictEqual(finalRetries, this.configuredCypressRetries)) {
1335
+ this.originalCypressRetries = reconcileNativeRetries(
1336
+ this.originalCypressRetries, this.nativeCypressRetriesBaseline, this.configuredCypressRetries, finalRetries
1337
+ )
1338
+ }
1179
1339
  if (this._isInit) {
1180
1340
  // The user may not have returned the promise from the init function.
1181
1341
  await this.libraryConfigurationPromise
@@ -1183,7 +1343,15 @@ class CypressPlugin {
1183
1343
  // Cypress open reuses the same plugin process for every interactive run.
1184
1344
  await this.init(this.tracer, this.cypressConfig)
1185
1345
  }
1346
+ this.retryConfigObserver?.stop()
1347
+
1348
+ if (!isDeepStrictEqual(finalRetries, this.configuredCypressRetries)) {
1349
+ this.originalCypressRetries = reconcileNativeRetries(
1350
+ this.originalCypressRetries, this.nativeCypressRetriesBaseline, this.configuredCypressRetries, finalRetries
1351
+ )
1352
+ }
1186
1353
 
1354
+ this.resolvedCypressRetries = finalRetries
1187
1355
  this.command = getCypressCommand(details)
1188
1356
  this.frameworkVersion = getCypressVersion(details)
1189
1357
  this.rootDir = getRootDir(details)
@@ -1560,13 +1728,21 @@ class CypressPlugin {
1560
1728
 
1561
1729
  // Get tests that didn't go through `dd:afterEach`
1562
1730
  // and create a skipped test span for each of them
1563
- for (const { title } of cypressTests) {
1564
- const cypressTestName = title.join(' ')
1565
- const isTestFinished = finishedTests.some(({ testName }) => cypressTestName === testName)
1731
+ const annotationOffsets = new Map()
1732
+ const matchedCypressTests = new Set()
1733
+ for (const cypressTest of cypressTests) {
1734
+ const cypressTestName = cypressTest.title.join(' ')
1735
+ const declarationIndex = annotationOffsets.get(cypressTestName) || 0
1736
+ const annotations = this.testAnnotationsBySuite.get(spec.relative)?.get(cypressTestName)?.[declarationIndex]
1737
+ annotationOffsets.set(cypressTestName, declarationIndex + 1)
1738
+ const isTestFinished = annotations?.testId
1739
+ ? finishedTests.some(({ testId }) => testId === annotations.testId)
1740
+ : finishedTests.some(({ testName }) => cypressTestName === testName)
1566
1741
 
1567
1742
  if (isTestFinished) {
1568
1743
  continue
1569
1744
  }
1745
+ matchedCypressTests.add(cypressTest)
1570
1746
 
1571
1747
  const isSkippedByItr = this.testsToSkip.some(test =>
1572
1748
  cypressTestName === test.name && spec.relative === test.suite
@@ -1577,7 +1753,7 @@ class CypressPlugin {
1577
1753
 
1578
1754
  // Recovered tests that never ran have no execution time; keep them at the recorded suite end.
1579
1755
  const skippedTestSpan = this.getTestSpan({
1580
- testName: cypressTestName, testSuite: spec.relative, testSourceFile, startTime: finishTime,
1756
+ testName: cypressTestName, testSuite: spec.relative, testSourceFile, annotations, startTime: finishTime,
1581
1757
  })
1582
1758
  skippedTestSpan.setTag(TEST_FINAL_STATUS, 'skip')
1583
1759
 
@@ -1594,25 +1770,27 @@ class CypressPlugin {
1594
1770
 
1595
1771
  if (isDisabled) {
1596
1772
  skippedTestSpan.setTag(TEST_MANAGEMENT_IS_DISABLED, 'true')
1597
- } else if (isQuarantined) {
1773
+ }
1774
+ if (isQuarantined) {
1598
1775
  skippedTestSpan.setTag(TEST_MANAGEMENT_IS_QUARANTINED, 'true')
1599
1776
  }
1600
1777
 
1778
+ if (isAttemptToFix) skippedTestSpan.setTag(TEST_MANAGEMENT_IS_ATTEMPT_TO_FIX, 'true')
1601
1779
  recordTestManagementExecution({
1602
1780
  testSuite: spec.relative,
1603
1781
  testName: cypressTestName,
1604
1782
  status: 'skip',
1605
- isAttemptToFix,
1606
- isDisabled,
1607
- isQuarantined,
1783
+ isAttemptToFix: isAttemptToFix && !annotations?.noAutoRetry,
1784
+ isDisabled: isDisabled && !annotations?.mustFail,
1785
+ isQuarantined: isQuarantined && !annotations?.mustFail,
1608
1786
  })
1609
- if (isAttemptToFix) {
1787
+ if (isAttemptToFix && !annotations?.noAutoRetry) {
1610
1788
  recordAttemptToFixExecution(this.attemptToFixExecutions, {
1611
1789
  testSuite: spec.relative,
1612
1790
  testName: cypressTestName,
1613
1791
  status: 'skip',
1614
- isDisabled,
1615
- isQuarantined,
1792
+ isDisabled: isDisabled && !annotations?.mustFail,
1793
+ isQuarantined: isQuarantined && !annotations?.mustFail,
1616
1794
  })
1617
1795
  }
1618
1796
 
@@ -1636,7 +1814,6 @@ class CypressPlugin {
1636
1814
  finishedTestAttempts.push(finishedTest)
1637
1815
  }
1638
1816
 
1639
- const matchedCypressTests = new Set()
1640
1817
  for (const finishedTestAttempts of finishedTestsByTest.values()) {
1641
1818
  const { testName } = finishedTestAttempts[0]
1642
1819
  // Cypress reports one result per original runnable, including Datadog-managed clones.
@@ -1664,7 +1841,9 @@ class CypressPlugin {
1664
1841
  cypressTestStatus = CYPRESS_STATUS_TO_TEST_STATUS[cypressTest.attempts[attemptIndex].state]
1665
1842
  const isAtrRetry = attemptIndex > 0 &&
1666
1843
  this.isFlakyTestRetriesEnabled &&
1844
+ (this.isDynamicAtrEnabled || this.flakyTestRetriesCount > 0) &&
1667
1845
  (!finishedTest.hasNativeRetries || this.isDynamicAtrEnabled) &&
1846
+ !finishedTest.noAutoRetry &&
1668
1847
  !finishedTest.isAttemptToFix &&
1669
1848
  !finishedTest.isEfdRetry
1670
1849
  if (attemptIndex > 0) {
@@ -1700,7 +1879,8 @@ class CypressPlugin {
1700
1879
 
1701
1880
  // Update test status - but NOT for non-ATF quarantined tests where we intentionally
1702
1881
  // report 'fail' to Datadog even though Cypress sees it as 'pass'
1703
- const isQuarantinedTest = finishedTest.testSpan?.context()?.getTag(TEST_MANAGEMENT_IS_QUARANTINED) === 'true'
1882
+ const isQuarantinedTest = !finishedTest.mustFail &&
1883
+ finishedTest.testSpan?.context()?.getTag(TEST_MANAGEMENT_IS_QUARANTINED) === 'true'
1704
1884
  if (cypressTestStatus !== finishedTest.testStatus && (!isQuarantinedTest || finishedTest.isAttemptToFix)) {
1705
1885
  finishedTest.testSpan.setTag(TEST_STATUS, cypressTestStatus)
1706
1886
  finishedTest.testSpan.setTag('error', latestError)
@@ -1714,8 +1894,8 @@ class CypressPlugin {
1714
1894
  testName,
1715
1895
  status: testManagementTags[TEST_STATUS] || cypressTestStatus,
1716
1896
  isAttemptToFix: finishedTest.isAttemptToFix,
1717
- isDisabled: testManagementTags[TEST_MANAGEMENT_IS_DISABLED] === 'true',
1718
- isQuarantined: testManagementTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
1897
+ isDisabled: !finishedTest.mustFail && testManagementTags[TEST_MANAGEMENT_IS_DISABLED] === 'true',
1898
+ isQuarantined: !finishedTest.mustFail && testManagementTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
1719
1899
  })
1720
1900
  if (this.itrCorrelationId) {
1721
1901
  finishedTest.testSpan.setTag(ITR_CORRELATION_ID, this.itrCorrelationId)
@@ -1762,13 +1942,24 @@ class CypressPlugin {
1762
1942
  const isQuarantined = testSpanTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true'
1763
1943
  const isDisabled = testSpanTags[TEST_MANAGEMENT_IS_DISABLED] === 'true'
1764
1944
 
1945
+ // Explicit experimental strategies can fail after a passing attempt. Their native
1946
+ // aggregate outcome remains authoritative when ATR supplies the retry budget.
1947
+ const hasNativeExperimentalRetries = typeof finishedTest.hasNativeExperimentalRetries === 'boolean'
1948
+ ? finishedTest.hasNativeExperimentalRetries
1949
+ : Boolean(this.resolvedCypressRetries?.experimentalStrategy)
1950
+ const finalRetryKind = hasNativeExperimentalRetries && !isDatadogManagedAttempt
1951
+ ? FINAL_STATUS_RETRY_KIND.none
1952
+ : retryKind
1765
1953
  const finalStatus = getFinalStatus({
1766
- status: cypressTestStatus,
1767
- retryKind,
1954
+ // Native retries use Cypress's aggregate outcome; managed attempts retain their own policy.
1955
+ status: finalRetryKind === FINAL_STATUS_RETRY_KIND.none && !isDatadogManagedAttempt
1956
+ ? CYPRESS_STATUS_TO_TEST_STATUS[isCypressHookFailure(cypressTest) ? 'failed' : cypressTest.state]
1957
+ : cypressTestStatus,
1958
+ retryKind: finalRetryKind,
1768
1959
  hasFailedAllAttempts,
1769
1960
  hasPassedAllAtfRetries,
1770
- isQuarantined,
1771
- isDisabled,
1961
+ isQuarantined: isQuarantined && !finishedTest.mustFail,
1962
+ isDisabled: isDisabled && !finishedTest.mustFail,
1772
1963
  })
1773
1964
 
1774
1965
  if (finalStatus) {
@@ -2045,9 +2236,29 @@ class CypressPlugin {
2045
2236
  if (finishPromises.length > 0) return Promise.all(finishPromises).then(() => null)
2046
2237
  }
2047
2238
 
2239
+ /**
2240
+ * @param {string} testSuite Suite path shared with Cypress results.
2241
+ * @param {object[]} testAnnotations Declaration metadata from the browser.
2242
+ */
2243
+ recordTestDeclarations (testSuite, testAnnotations) {
2244
+ const declarationsByName = new Map()
2245
+ for (const annotation of testAnnotations) {
2246
+ if (!declarationsByName.has(annotation.testName)) declarationsByName.set(annotation.testName, [])
2247
+ declarationsByName.get(annotation.testName).push(annotation)
2248
+ }
2249
+ this.testAnnotationsBySuite.set(testSuite, declarationsByName)
2250
+ }
2251
+
2048
2252
  getTasks () {
2049
2253
  return {
2050
- 'dd:testSuiteStart': ({ testSuite, testSuiteAbsolutePath, isTextTerminal: browserIsTextTerminal }) => {
2254
+ 'dd:testDeclarations': ({ testSuite, testAnnotations }) => {
2255
+ this.recordTestDeclarations(testSuite, testAnnotations)
2256
+ return null
2257
+ },
2258
+ 'dd:testSuiteStart': ({
2259
+ testSuite, testSuiteAbsolutePath, isTextTerminal: browserIsTextTerminal, testAnnotations = [],
2260
+ }) => {
2261
+ this.recordTestDeclarations(testSuite, testAnnotations)
2051
2262
  // Cypress 6 omits the execution mode from the Node plugin configuration.
2052
2263
  const isTextTerminal = this.cypressConfig.isTextTerminal ?? browserIsTextTerminal
2053
2264
  if (!isTextTerminal) {
@@ -2055,9 +2266,19 @@ class CypressPlugin {
2055
2266
  this.isDynamicAtrEnabled = false
2056
2267
  this.flakyTestRetriesCount = 0
2057
2268
  }
2269
+ let frameworkRetries = this.originalCypressRetries
2270
+ if (typeof frameworkRetries !== 'number') {
2271
+ const configured = this.originalCypressRetries?.[isTextTerminal ? 'runMode' : 'openMode']
2272
+ frameworkRetries = configured === true
2273
+ ? this.originalCypressRetries.experimentalOptions?.maxRetries ?? 0
2274
+ : configured || 0
2275
+ }
2058
2276
  const suitePayload = {
2059
2277
  isEarlyFlakeDetectionEnabled:
2060
2278
  this.isEarlyFlakeDetectionEnabled && hasEfdRetries(this.earlyFlakeDetectionRetryPolicy),
2279
+ frameworkRetries,
2280
+ configuredRetries: this.configuredCypressRetries,
2281
+ originalRetries: this.originalCypressRetries,
2061
2282
  knownTestsForSuite: this.knownTestsByTestSuite?.[testSuite] || [],
2062
2283
  earlyFlakeDetectionSchedulingRetryCount: this.earlyFlakeDetectionRetryPolicy.schedulingRetryCount,
2063
2284
  isKnownTestsEnabled: this.isKnownTestsEnabled,
@@ -2080,7 +2301,7 @@ class CypressPlugin {
2080
2301
  },
2081
2302
  'dd:beforeEach': (test) => {
2082
2303
  this.hasTestsReported = true
2083
- const { testId, testName, testSuite, isEfdRetry, efdRetryIndex } = test
2304
+ const { testId, testName, testSuite, isEfdRetry, efdRetryIndex, annotations } = test
2084
2305
  if (isEfdRetry && this.shouldSkipEfdRetry(testSuite, testName, efdRetryIndex)) {
2085
2306
  return { shouldSkip: true, shouldDiscard: true }
2086
2307
  }
@@ -2111,12 +2332,12 @@ class CypressPlugin {
2111
2332
  return { shouldSkip: true }
2112
2333
  }
2113
2334
 
2114
- if (isAttemptToFix) {
2335
+ if (isAttemptToFix && !annotations?.noAutoRetry) {
2115
2336
  logAttemptToFixTestExecution(testSuite, testName, this.loggedAttemptToFixTests)
2116
2337
  }
2117
2338
 
2118
2339
  // For disabled tests (not attemptToFix), skip them
2119
- if (!isAttemptToFix && isDisabled) {
2340
+ if ((!isAttemptToFix || annotations?.noAutoRetry) && isDisabled && !annotations?.mustFail) {
2120
2341
  return { shouldSkip: true }
2121
2342
  }
2122
2343
  // Quarantined tests (not attemptToFix) run normally but their failures are caught
@@ -2130,6 +2351,8 @@ class CypressPlugin {
2130
2351
  isForcedToRun,
2131
2352
  isDisabled,
2132
2353
  isQuarantined,
2354
+ isAttemptToFix,
2355
+ annotations,
2133
2356
  })
2134
2357
  }
2135
2358
 
@@ -2154,8 +2377,11 @@ class CypressPlugin {
2154
2377
  isNew,
2155
2378
  isEfdRetry,
2156
2379
  isAttemptToFix,
2380
+ annotations,
2157
2381
  isModified,
2158
2382
  hasNativeRetries,
2383
+ hasNativeExperimentalRetries,
2384
+ nativeRetryFloor,
2159
2385
  duration,
2160
2386
  isQuarantined: isQuarantinedFromSupport,
2161
2387
  isDisabled: isDisabledFromSupport,
@@ -2185,7 +2411,7 @@ class CypressPlugin {
2185
2411
  }
2186
2412
  this.tracer._tracer._exporter.exportCoverage(formattedCoverage)
2187
2413
  }
2188
- const isEfdManagedTest = (isNew || isModified) &&
2414
+ const isEfdManagedTest = !annotations?.noAutoRetry && (isNew || isModified) &&
2189
2415
  this.isEarlyFlakeDetectionEnabled &&
2190
2416
  hasEfdRetries(this.earlyFlakeDetectionRetryPolicy) &&
2191
2417
  !isAttemptToFix
@@ -2200,6 +2426,7 @@ class CypressPlugin {
2200
2426
  }
2201
2427
  // Dynamic ATR: after the first attempt, compute the duration-based retry budget.
2202
2428
  if (
2429
+ !annotations?.noAutoRetry &&
2203
2430
  this.isDynamicAtrEnabled &&
2204
2431
  this.isFlakyTestRetriesEnabled &&
2205
2432
  !isAttemptToFix &&
@@ -2207,7 +2434,7 @@ class CypressPlugin {
2207
2434
  !isEfdManagedTest &&
2208
2435
  this.getDynamicAtrRetryCountForTest(testSuite, testId) === undefined
2209
2436
  ) {
2210
- this.setDynamicAtrRetryCountForTest(testSuite, testId, duration)
2437
+ this.setDynamicAtrRetryCountForTest(testSuite, testId, duration, nativeRetryFloor)
2211
2438
  }
2212
2439
  if (didAbortSlowEfdRetries && testStatus === 'skip' && !error && duration > 0) {
2213
2440
  testStatus = 'pass'
@@ -2300,14 +2527,14 @@ class CypressPlugin {
2300
2527
  testSuite,
2301
2528
  testName,
2302
2529
  status: testStatus,
2303
- isDisabled: activeSpanTags[TEST_MANAGEMENT_IS_DISABLED] === 'true',
2304
- isQuarantined: activeSpanTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
2530
+ isDisabled: !annotations?.mustFail && activeSpanTags[TEST_MANAGEMENT_IS_DISABLED] === 'true',
2531
+ isQuarantined: !annotations?.mustFail && activeSpanTags[TEST_MANAGEMENT_IS_QUARANTINED] === 'true',
2305
2532
  })
2306
2533
  }
2307
2534
  // ATR: set TEST_HAS_FAILED_ALL_RETRIES when all auto test retries were exhausted and every attempt failed
2308
2535
  const dynamicAtrRetryCount = this.getDynamicAtrRetryCountForTest(testSuite, testId)
2309
2536
  const atrRetryCount = this.isDynamicAtrEnabled ? dynamicAtrRetryCount : this.flakyTestRetriesCount
2310
- if (this.isFlakyTestRetriesEnabled && !isAttemptToFix && !isEfdRetry &&
2537
+ if (!annotations?.noAutoRetry && this.isFlakyTestRetriesEnabled && !isAttemptToFix && !isEfdRetry &&
2311
2538
  atrRetryCount > 0 && testStatuses.length === atrRetryCount + 1 &&
2312
2539
  testStatuses.every(status => status === 'fail')) {
2313
2540
  this.activeTestSpan.setTag(TEST_HAS_FAILED_ALL_RETRIES, 'true')
@@ -2357,6 +2584,9 @@ class CypressPlugin {
2357
2584
  isEfdManagedTest,
2358
2585
  isAttemptToFix,
2359
2586
  hasNativeRetries,
2587
+ hasNativeExperimentalRetries,
2588
+ mustFail: annotations?.mustFail,
2589
+ noAutoRetry: annotations?.noAutoRetry,
2360
2590
  }
2361
2591
  if (this.finishedTestsByFile[testSuite]) {
2362
2592
  this.finishedTestsByFile[testSuite].push(finishedTest)
@@ -118,7 +118,7 @@ class CypressPlugin extends Plugin {
118
118
  payload.registered = true
119
119
  // cypressPlugin.init expects the proxy tracer (with ._tracer._exporter),
120
120
  // not the unwrapped internal tracer that this.tracer returns.
121
- payload.configPromise = Promise.resolve(cypressPlugin.init(this._tracer, config)).then(() => config)
121
+ payload.configPromise = Promise.resolve(cypressPlugin.init(this._tracer, config))
122
122
  })
123
123
  }
124
124
  }
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ // Older manual support predates the shared installation marker. Its lifecycle
4
+ // still registers these two stable Datadog task hooks on the Mocha root.
5
+ function callsTask (hook, name) {
6
+ if (!hook || typeof hook.fn !== 'function') return false
7
+ // Keep string literals as single tokens and omit comments, so documentation
8
+ // or a quoted example cannot masquerade as an actual task invocation.
9
+ const tokens = Function.prototype.toString.call(hook.fn)
10
+ .match(/\/\/[^\n]*|\/\*[\s\S]*?\*\/|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|[A-Za-z_$][\w$]*|[^\s]/g) || []
11
+ const code = tokens.filter(token => !token.startsWith('//') && !token.startsWith('/*'))
12
+ return code.some((token, index) => token === '.' && code[index + 1] === 'task' &&
13
+ code[index + 2] === '(' && (code[index + 3] === `"${name}"` || code[index + 3] === `'${name}'`))
14
+ }
15
+
16
+ module.exports = function hasCypressLifecycle (root) {
17
+ return Boolean(root && root._beforeAll && root._afterEach &&
18
+ root._beforeAll.some(hook => callsTask(hook, 'dd:testSuiteStart')) &&
19
+ root._afterEach.some(hook => callsTask(hook, 'dd:afterEach')))
20
+ }
@@ -12,6 +12,9 @@ const DD_CYPRESS_TASK_HANDLER = Symbol.for('dd-trace.cypress.task.handler')
12
12
  const DD_CYPRESS_NOOP_TASK_HANDLER = Symbol.for('dd-trace.cypress.noop-task.handler')
13
13
 
14
14
  const noopTask = {
15
+ 'dd:testDeclarations': () => {
16
+ return null
17
+ },
15
18
  'dd:testSuiteStart': () => {
16
19
  return null
17
20
  },
@@ -46,6 +49,13 @@ module.exports = function CypressPlugin (on, config) {
46
49
  return config
47
50
  }
48
51
 
52
+ // Browser retry intent must be observed before any user support code executes.
53
+ // Cypress 6's plugin process uses Node 12 and retains its existing manual path.
54
+ if (satisfies(config.version, '>=12.0.0')) {
55
+ const { installManualSupportFile } = require('../../datadog-instrumentations/src/cypress-config')
56
+ installManualSupportFile(config)
57
+ }
58
+
49
59
  on('before:run', cypressPlugin.beforeRun.bind(cypressPlugin))
50
60
  on('after:screenshot', cypressPlugin.getAfterScreenshotHandler())
51
61
  const afterSpecHandler = cypressPlugin.afterSpec.bind(cypressPlugin)