dd-trace 6.22.0 → 6.24.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.
- package/LICENSE-3rdparty.csv +0 -1
- package/ci/cypress/support.js +15 -1
- package/ci/diagnose.js +4 -4
- package/ci/test-annotations.d.ts +5 -0
- package/ci/test-annotations.js +5 -0
- package/ci/test-optimization-validation/approval-artifacts.js +2 -2
- package/ci/test-optimization-validation/approval.js +2 -2
- package/ci/test-optimization-validation/artifact-id.js +2 -3
- package/ci/test-optimization-validation/ci-package-scripts.js +1 -1
- package/ci/test-optimization-validation/cli.js +1 -1
- package/ci/test-optimization-validation/command-runner.js +2 -3
- package/ci/test-optimization-validation/executable.js +1 -1
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +1 -1
- package/ci/test-optimization-validation/literal-environment.js +2 -2
- package/ci/test-optimization-validation/manifest-scaffold.js +1 -1
- package/ci/test-optimization-validation/offline-fixtures.js +1 -1
- package/ci/test-optimization-validation/redaction.js +3 -3
- package/ci/test-optimization-validation/runner-contract.js +10 -10
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -1
- package/ci/vitest-no-worker-init-annotations.mjs +4 -0
- package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
- package/ci/vitest-no-worker-init-runner-setup.mjs +7 -5
- package/ci/vitest-no-worker-init-setup.mjs +34 -12
- package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
- package/ext/exporters.js +1 -0
- package/index.d.ts +35 -5
- package/loader-hook.mjs +53 -0
- package/openfeature/exposure-hook.d.ts +66 -0
- package/openfeature/exposure-hook.js +5 -0
- package/package.json +23 -20
- package/packages/datadog-core/src/storage.js +1 -1
- package/packages/datadog-esbuild/index.js +70 -7
- package/packages/datadog-instrumentations/index.js +2 -1
- package/packages/datadog-instrumentations/src/cucumber.js +64 -21
- package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
- package/packages/datadog-instrumentations/src/graphql.js +9 -3
- package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
- package/packages/datadog-instrumentations/src/helpers/bundler-register.js +27 -8
- package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
- package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
- package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -1
- package/packages/datadog-instrumentations/src/helpers/register.js +9 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +16 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +10 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/jest.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/vitest.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +13 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +1 -1
- package/packages/datadog-instrumentations/src/jest.js +332 -137
- package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
- package/packages/datadog-instrumentations/src/mariadb.js +13 -6
- package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
- package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
- package/packages/datadog-instrumentations/src/mocha/utils.js +92 -13
- package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
- package/packages/datadog-instrumentations/src/nova-sonic/session.js +25 -16
- package/packages/datadog-instrumentations/src/oracledb.js +33 -0
- package/packages/datadog-instrumentations/src/pg.js +2 -1
- package/packages/datadog-instrumentations/src/playwright.js +81 -26
- package/packages/datadog-instrumentations/src/react-router.js +106 -0
- package/packages/datadog-instrumentations/src/stripe.js +23 -12
- package/packages/datadog-instrumentations/src/typesafe.js +89 -0
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -47
- package/packages/datadog-instrumentations/src/vitest-main.js +33 -3
- package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
- package/packages/datadog-instrumentations/src/vitest-util.js +5 -2
- package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
- package/packages/datadog-instrumentations/src/vitest.js +16 -6
- package/packages/datadog-plugin-cucumber/src/index.js +5 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +277 -44
- package/packages/datadog-plugin-cypress/src/index.js +1 -1
- package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
- package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
- package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
- package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
- package/packages/datadog-plugin-cypress/src/support.js +1217 -437
- package/packages/datadog-plugin-graphql/src/execute.js +2 -2
- package/packages/datadog-plugin-graphql/src/utils.js +5 -5
- package/packages/datadog-plugin-jest/src/index.js +25 -3
- package/packages/datadog-plugin-mocha/src/index.js +47 -6
- package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
- package/packages/datadog-plugin-playwright/src/index.js +4 -0
- package/packages/datadog-plugin-react-router/src/index.js +118 -0
- package/packages/datadog-plugin-typesafe/src/index.js +17 -0
- package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
- package/packages/datadog-plugin-vitest/src/index.js +8 -0
- package/packages/dd-trace/src/agent/info.js +2 -1
- package/packages/dd-trace/src/aiguard/evaluation.js +143 -1
- package/packages/dd-trace/src/aiguard/sdk.js +0 -11
- package/packages/dd-trace/src/appsec/iast/path-line.js +2 -1
- package/packages/dd-trace/src/appsec/stack_trace.js +3 -2
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +3 -2
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +9 -16
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +9 -16
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
- package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
- package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
- package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
- package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +9 -16
- package/packages/dd-trace/src/config/defaults.js +4 -3
- package/packages/dd-trace/src/config/generated-config-types.d.ts +6 -0
- package/packages/dd-trace/src/config/index.js +140 -39
- package/packages/dd-trace/src/config/parsers.js +9 -1
- package/packages/dd-trace/src/config/supported-configurations.json +25 -0
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +6 -5
- package/packages/dd-trace/src/debugger/devtools_client/condition.js +5 -5
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +4 -6
- package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +16 -0
- package/packages/dd-trace/src/encode/0.4.js +2 -2
- package/packages/dd-trace/src/esm-module-load.js +58 -0
- package/packages/dd-trace/src/exporter.js +25 -6
- package/packages/dd-trace/src/exporters/agent/index.js +3 -1
- package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
- package/packages/dd-trace/src/exporters/common/request.js +4 -4
- package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
- package/packages/dd-trace/src/exporters/log/index.js +4 -3
- package/packages/dd-trace/src/llmobs/agent-manifest.js +19 -2
- package/packages/dd-trace/src/llmobs/constants/tags.js +4 -0
- package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
- package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
- package/packages/dd-trace/src/llmobs/index.js +13 -2
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +8 -4
- package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +5 -0
- package/packages/dd-trace/src/llmobs/plugins/openai/index.js +9 -1
- package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
- package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
- package/packages/dd-trace/src/llmobs/sdk.js +17 -5
- package/packages/dd-trace/src/llmobs/span_processor.js +222 -12
- package/packages/dd-trace/src/llmobs/tagger.js +21 -8
- package/packages/dd-trace/src/llmobs/util.js +10 -4
- package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
- package/packages/dd-trace/src/log/writer.js +7 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +64 -6
- package/packages/dd-trace/src/openfeature/configuration_source.js +18 -2
- package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
- package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +39 -13
- package/packages/dd-trace/src/openfeature/index.js +6 -0
- package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
- package/packages/dd-trace/src/openfeature/writers/base.js +62 -27
- package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
- package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
- package/packages/dd-trace/src/openfeature/writers/util.js +4 -4
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +18 -1
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
- package/packages/dd-trace/src/opentracing/tracer.js +9 -13
- package/packages/dd-trace/src/otel-thread-ctx.js +47 -21
- package/packages/dd-trace/src/plugin_manager.js +1 -2
- package/packages/dd-trace/src/plugins/ci_plugin.js +4 -4
- package/packages/dd-trace/src/plugins/index.js +3 -0
- package/packages/dd-trace/src/plugins/tracing.js +1 -2
- package/packages/dd-trace/src/plugins/util/git.js +102 -40
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -4
- package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -1
- package/packages/dd-trace/src/plugins/util/test.js +28 -6
- package/packages/dd-trace/src/plugins/util/web.js +106 -20
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiling/config.js +6 -3
- package/packages/dd-trace/src/proxy.js +15 -4
- package/packages/dd-trace/src/serverless.js +3 -2
- package/packages/dd-trace/src/span_processor.js +21 -9
- package/packages/dd-trace/src/span_stats.js +32 -3
- package/packages/dd-trace/src/startup-log.js +2 -1
- package/packages/dd-trace/src/tagger.js +7 -5
- package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
- package/packages/dd-trace/src/telemetry/index.js +3 -0
- package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
- package/packages/dd-trace/src/telemetry/logs/log-collector.js +2 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
- package/packages/dd-trace/src/util.js +9 -5
- package/register.js +2 -1
- package/vendor/dist/@apm-js-collab/code-transformer/index.js +8 -8
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/@opentelemetry/resources/LICENSE +0 -201
- package/vendor/dist/@opentelemetry/resources/index.js +0 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const observeSetupHandoff = require('./setup-handoff')
|
|
4
|
+
|
|
5
|
+
// Configuration inspection must not evaluate accessors before Cypress serializes them.
|
|
6
|
+
function snapshot (value, previous) {
|
|
7
|
+
if (!value || typeof value !== 'object') return value
|
|
8
|
+
const result = Array.isArray(value) ? [] : {}
|
|
9
|
+
for (const key of Object.keys(value)) {
|
|
10
|
+
const property = Object.getOwnPropertyDescriptor(value, key)
|
|
11
|
+
const entry = 'value' in property ? snapshot(property.value, previous?.[key]) : previous?.[key]
|
|
12
|
+
if (entry !== undefined) result[key] = entry
|
|
13
|
+
}
|
|
14
|
+
return result
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function snapshotMetadata (metadata) {
|
|
18
|
+
return metadata && { native: snapshot(metadata.native), observed: snapshot(metadata.observed) }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Observe user writes after plugin initialization without changing the config's identity.
|
|
23
|
+
*
|
|
24
|
+
* @param {object} config
|
|
25
|
+
* @param {Function} onChange
|
|
26
|
+
* @param {{ nativeRetries: unknown, updateNative: Function, reconcileNative?: Function }} [options]
|
|
27
|
+
*/
|
|
28
|
+
module.exports = function observeRetryConfig (config, onChange, options) {
|
|
29
|
+
const descriptor = Object.getOwnPropertyDescriptor(config, 'retries')
|
|
30
|
+
if (!descriptor?.writable || !('value' in descriptor)) return
|
|
31
|
+
|
|
32
|
+
const initial = config.retries
|
|
33
|
+
let active = true
|
|
34
|
+
const roots = new WeakMap()
|
|
35
|
+
const targets = new WeakMap()
|
|
36
|
+
// Cypress keeps nested retry settings in first-level options objects.
|
|
37
|
+
const children = new WeakMap()
|
|
38
|
+
const unwrap = value => targets.get(value) || value
|
|
39
|
+
const rememberChild = (metadata, key, value) => {
|
|
40
|
+
const raw = unwrap(value)
|
|
41
|
+
if (!options || !raw || typeof raw !== 'object' || children.has(raw)) return
|
|
42
|
+
children.set(raw, { raw, native: metadata.native?.[key], observed: snapshot(raw) })
|
|
43
|
+
}
|
|
44
|
+
const refreshChild = (key, child) => {
|
|
45
|
+
if (!active || !options?.reconcileNative) return
|
|
46
|
+
child.native = options.reconcileNative(
|
|
47
|
+
{ [key]: child.native }, { [key]: child.observed }, { [key]: snapshot(child.raw, child.observed) }
|
|
48
|
+
)[key]
|
|
49
|
+
child.observed = snapshot(child.raw, child.observed)
|
|
50
|
+
}
|
|
51
|
+
const refreshNative = metadata => {
|
|
52
|
+
if (active && metadata && options?.reconcileNative) {
|
|
53
|
+
const actual = snapshot(metadata.raw, metadata.observed)
|
|
54
|
+
for (const key of Object.keys(actual)) {
|
|
55
|
+
const property = Object.getOwnPropertyDescriptor(metadata.raw, key)
|
|
56
|
+
const child = property && 'value' in property && children.get(unwrap(property.value))
|
|
57
|
+
if (child) {
|
|
58
|
+
refreshChild(key, child)
|
|
59
|
+
actual[key] = child.native
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
metadata.native = options.reconcileNative(metadata.native, metadata.observed, actual)
|
|
63
|
+
metadata.observed = snapshot(actual)
|
|
64
|
+
for (const key of Object.keys(metadata.raw)) {
|
|
65
|
+
const property = Object.getOwnPropertyDescriptor(metadata.raw, key)
|
|
66
|
+
if ('value' in property) rememberChild(metadata, key, property.value)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const refreshTarget = (metadata, path, target) => {
|
|
71
|
+
if (active && path.length === 1) {
|
|
72
|
+
const child = children.get(unwrap(target))
|
|
73
|
+
if (child) refreshChild(path[0], child)
|
|
74
|
+
}
|
|
75
|
+
refreshNative(metadata)
|
|
76
|
+
}
|
|
77
|
+
const notify = (value, path, metadata) => {
|
|
78
|
+
refreshNative(metadata)
|
|
79
|
+
let native
|
|
80
|
+
if (options) {
|
|
81
|
+
native = metadata ? metadata.native : options.updateNative(undefined, snapshot(value), [])
|
|
82
|
+
if (!metadata && value && typeof value === 'object') {
|
|
83
|
+
// A new root can select options already observed under another root.
|
|
84
|
+
for (const key of Object.keys(value)) {
|
|
85
|
+
const property = Object.getOwnPropertyDescriptor(value, key)
|
|
86
|
+
const child = property && 'value' in property && children.get(unwrap(property.value))
|
|
87
|
+
if (child) {
|
|
88
|
+
refreshChild(key, child)
|
|
89
|
+
native = options.updateNative(native, { [key]: child.native }, [key])
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const provenance = options && { retries: native }
|
|
95
|
+
onChange(value, path, provenance)
|
|
96
|
+
}
|
|
97
|
+
const initialMetadata = initial && typeof initial === 'object'
|
|
98
|
+
? {
|
|
99
|
+
raw: initial,
|
|
100
|
+
native: options?.nativeRetries,
|
|
101
|
+
proxies: new WeakMap(),
|
|
102
|
+
observed: options?.reconcileNative ? snapshot(initial) : undefined,
|
|
103
|
+
}
|
|
104
|
+
: undefined
|
|
105
|
+
if (initialMetadata) {
|
|
106
|
+
roots.set(initial, initialMetadata)
|
|
107
|
+
for (const key of Object.keys(initial)) {
|
|
108
|
+
const property = Object.getOwnPropertyDescriptor(initial, key)
|
|
109
|
+
if ('value' in property) rememberChild(initialMetadata, key, property.value)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const record = (metadata, path, target) => {
|
|
113
|
+
if (!active) return
|
|
114
|
+
if (options) {
|
|
115
|
+
const [key] = path
|
|
116
|
+
const child = path.length === 2 && children.get(unwrap(target))
|
|
117
|
+
if (child) {
|
|
118
|
+
refreshChild(key, child)
|
|
119
|
+
child.native = options.updateNative(
|
|
120
|
+
{ [key]: child.native }, { [key]: snapshot(child.raw, child.observed) }, path
|
|
121
|
+
)[key]
|
|
122
|
+
child.observed = snapshot(child.raw, child.observed)
|
|
123
|
+
// A saved options object can change while a different object is selected.
|
|
124
|
+
if (unwrap(Object.getOwnPropertyDescriptor(metadata.raw, key)?.value) !== child.raw) return
|
|
125
|
+
metadata.native = { ...metadata.native, [key]: child.native }
|
|
126
|
+
} else {
|
|
127
|
+
const restored = path.length === 1 && children.get(
|
|
128
|
+
unwrap(Object.getOwnPropertyDescriptor(metadata.raw, key)?.value)
|
|
129
|
+
)
|
|
130
|
+
if (restored) refreshChild(key, restored)
|
|
131
|
+
const actual = snapshot(metadata.raw, metadata.observed)
|
|
132
|
+
const supplied = restored ? { ...actual, [key]: restored.native } : actual
|
|
133
|
+
metadata.native = options.updateNative(metadata.native, supplied, path)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// A detached alias updates only its own provenance until that root is selected again.
|
|
137
|
+
const selected = Object.getOwnPropertyDescriptor(config, 'retries')?.value
|
|
138
|
+
if (metadata.raw === unwrap(selected)) notify(metadata.raw, path, metadata)
|
|
139
|
+
else refreshNative(metadata)
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @param {object} target
|
|
143
|
+
* @param {string|symbol} key
|
|
144
|
+
* @param {unknown} value
|
|
145
|
+
*/
|
|
146
|
+
const isSameObjectValue = (target, key, value) => {
|
|
147
|
+
const raw = unwrap(value)
|
|
148
|
+
const previous = Object.getOwnPropertyDescriptor(target, key)
|
|
149
|
+
return raw !== null && typeof raw === 'object' && previous &&
|
|
150
|
+
'value' in previous && raw === unwrap(previous.value)
|
|
151
|
+
}
|
|
152
|
+
const wrap = (value, metadata, path = []) => {
|
|
153
|
+
value = unwrap(value)
|
|
154
|
+
if (value === null || typeof value !== 'object') return value
|
|
155
|
+
if (path.length === 1 && options && !children.has(value)) {
|
|
156
|
+
refreshNative(metadata)
|
|
157
|
+
rememberChild(metadata, path[0], value)
|
|
158
|
+
}
|
|
159
|
+
if (metadata.proxies.has(value)) return metadata.proxies.get(value)
|
|
160
|
+
const proxy = new Proxy(value, {
|
|
161
|
+
get (target, key) {
|
|
162
|
+
const result = Reflect.get(target, key)
|
|
163
|
+
const property = Object.getOwnPropertyDescriptor(target, key)
|
|
164
|
+
// Frozen values must be returned unchanged to preserve Proxy invariants.
|
|
165
|
+
return property && !property.configurable && !property.writable && 'value' in property
|
|
166
|
+
? result
|
|
167
|
+
: wrap(result, metadata, [...path, key])
|
|
168
|
+
},
|
|
169
|
+
set (target, key, value) {
|
|
170
|
+
const sameObject = isSameObjectValue(target, key, value)
|
|
171
|
+
const result = Reflect.set(target, key, unwrap(value))
|
|
172
|
+
if (result) {
|
|
173
|
+
if (sameObject) refreshTarget(metadata, path, target)
|
|
174
|
+
else record(metadata, [...path, key], target)
|
|
175
|
+
}
|
|
176
|
+
return result
|
|
177
|
+
},
|
|
178
|
+
deleteProperty (target, key) {
|
|
179
|
+
const result = Reflect.deleteProperty(target, key)
|
|
180
|
+
if (result) record(metadata, [...path, key], target)
|
|
181
|
+
return result
|
|
182
|
+
},
|
|
183
|
+
defineProperty (target, key, property) {
|
|
184
|
+
const hasValue = 'value' in property
|
|
185
|
+
const sameObject = hasValue && isSameObjectValue(target, key, property.value)
|
|
186
|
+
const result = Reflect.defineProperty(target, key, property)
|
|
187
|
+
if (result) {
|
|
188
|
+
if (hasValue && !sameObject) record(metadata, [...path, key], target)
|
|
189
|
+
else refreshTarget(metadata, path, target)
|
|
190
|
+
}
|
|
191
|
+
return result
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
metadata.proxies.set(value, proxy)
|
|
195
|
+
targets.set(proxy, value)
|
|
196
|
+
return proxy
|
|
197
|
+
}
|
|
198
|
+
// Keep the native data descriptor: freeze/seal must retain JavaScript's own
|
|
199
|
+
// strict/sloppy write semantics. Fresh root replacements are reconciled by
|
|
200
|
+
// identity at the setup handoff; only injected objects need nested proxies.
|
|
201
|
+
config.retries = wrap(initial, initialMetadata)
|
|
202
|
+
|
|
203
|
+
// Cypress serializes the actual setupNodeEvents return value through this reply.
|
|
204
|
+
// Observing it before serialization also handles a fresh partial return when the
|
|
205
|
+
// manual plugin was loaded inside an already-running setup callback.
|
|
206
|
+
const stop = (reconcileCurrent = true) => {
|
|
207
|
+
if (active && reconcileCurrent) {
|
|
208
|
+
const retries = unwrap(config.retries)
|
|
209
|
+
notify(retries, [], retries && typeof retries === 'object' && roots.get(retries))
|
|
210
|
+
}
|
|
211
|
+
active = false
|
|
212
|
+
stopIpc?.()
|
|
213
|
+
const currentDescriptor = Object.getOwnPropertyDescriptor(config, 'retries')
|
|
214
|
+
if (currentDescriptor?.writable && targets.has(currentDescriptor.value)) {
|
|
215
|
+
config.retries = unwrap(currentDescriptor.value)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const stopIpc = observeSetupHandoff((returnedConfig, event, context) => {
|
|
219
|
+
try {
|
|
220
|
+
if (active && event === 'setupTestingType:reply') {
|
|
221
|
+
const property = returnedConfig && Object.getOwnPropertyDescriptor(returnedConfig, 'retries')
|
|
222
|
+
const retries = property?.enumerable ? returnedConfig.retries : undefined
|
|
223
|
+
const original = value => context?.originalFor(value) ?? value
|
|
224
|
+
const source = original(retries)
|
|
225
|
+
const raw = unwrap(source)
|
|
226
|
+
const cached = context?.snapshotFor(retries) ?? retries
|
|
227
|
+
const captured = context?.stateFor(cached)
|
|
228
|
+
const metadata = captured ? captured.root : raw && typeof raw === 'object' && roots.get(raw)
|
|
229
|
+
const actual = snapshot(cached, metadata?.observed)
|
|
230
|
+
let native = options && (metadata
|
|
231
|
+
? (options.reconcileNative
|
|
232
|
+
? options.reconcileNative(metadata.native, metadata.observed, actual)
|
|
233
|
+
: metadata.native)
|
|
234
|
+
: options.updateNative(undefined, actual, []))
|
|
235
|
+
if (options && actual && typeof actual === 'object') {
|
|
236
|
+
for (const key of Object.keys(actual)) {
|
|
237
|
+
const sourceChild = original(cached[key])
|
|
238
|
+
const rawChild = unwrap(sourceChild)
|
|
239
|
+
const capturedChild = context?.stateFor(cached[key])
|
|
240
|
+
const child = capturedChild
|
|
241
|
+
? capturedChild.child
|
|
242
|
+
: rawChild && typeof rawChild === 'object' && children.get(rawChild)
|
|
243
|
+
if (!child) continue
|
|
244
|
+
let childNative = options.reconcileNative
|
|
245
|
+
? options.reconcileNative(
|
|
246
|
+
{ [key]: child.native }, { [key]: child.observed }, { [key]: actual[key] }
|
|
247
|
+
)[key]
|
|
248
|
+
: child.native
|
|
249
|
+
if (context) {
|
|
250
|
+
for (const getterKey of context.getterKeys(cached[key])) {
|
|
251
|
+
childNative = options.updateNative(
|
|
252
|
+
{ [key]: childNative }, { [key]: actual[key] }, [key, getterKey]
|
|
253
|
+
)[key]
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
native = options.updateNative(native, { [key]: childNative }, [key])
|
|
257
|
+
}
|
|
258
|
+
if (context) {
|
|
259
|
+
for (const key of context.getterKeys(cached)) {
|
|
260
|
+
native = options.updateNative(native, actual, [key])
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
onChange(retries, [], options && { retries: native })
|
|
265
|
+
}
|
|
266
|
+
} finally {
|
|
267
|
+
// Later child-local writes cannot change the parent's serialized config.
|
|
268
|
+
stop(false)
|
|
269
|
+
}
|
|
270
|
+
}, unwrap, value => {
|
|
271
|
+
// Freeze provenance at this serialized occurrence. Later config getters can
|
|
272
|
+
// mutate the same retry object after its active value has already crossed IPC.
|
|
273
|
+
return { root: snapshotMetadata(roots.get(value)), child: snapshotMetadata(children.get(value)) }
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
isWatching: candidate => active && candidate === config,
|
|
278
|
+
stopIpc,
|
|
279
|
+
stop,
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Observe the actual setup serialization boundary without retaining ownership of process.send.
|
|
4
|
+
module.exports = function observeSetupHandoff (onHandoff, normalizeIdentity = value => value, captureIdentity) {
|
|
5
|
+
const originalSend = process.send
|
|
6
|
+
if (typeof originalSend !== 'function') return () => {}
|
|
7
|
+
let active = true
|
|
8
|
+
const stop = () => {
|
|
9
|
+
active = false
|
|
10
|
+
if (process.send === send) process.send = originalSend
|
|
11
|
+
}
|
|
12
|
+
const send = function (message) {
|
|
13
|
+
let forwardedArguments = arguments
|
|
14
|
+
if (active && (message?.event === 'setupTestingType:reply' || message?.event === 'setupTestingType:error')) {
|
|
15
|
+
try {
|
|
16
|
+
let wireConfig = message.event === 'setupTestingType:reply' && message.args?.[0]?.setupConfig
|
|
17
|
+
const snapshots = new WeakMap()
|
|
18
|
+
const originals = new WeakMap()
|
|
19
|
+
const getters = new WeakMap()
|
|
20
|
+
const states = new WeakMap()
|
|
21
|
+
const materialize = (value, propertyKey) => {
|
|
22
|
+
if (!value || typeof value !== 'object') return value
|
|
23
|
+
const identity = normalizeIdentity(value)
|
|
24
|
+
if (snapshots.has(identity)) return snapshots.get(identity)
|
|
25
|
+
const paths = new WeakMap()
|
|
26
|
+
const records = []
|
|
27
|
+
const occurrences = new WeakMap()
|
|
28
|
+
let holder
|
|
29
|
+
// JSON owns the traversal: earlier getters and toJSON methods can change
|
|
30
|
+
// later retry values. Observe the same values that will cross IPC once.
|
|
31
|
+
const serialized = JSON.stringify({ [propertyKey]: value }, function (key, current) {
|
|
32
|
+
if (!holder) holder = this
|
|
33
|
+
const path = this === holder ? [] : [...paths.get(this), key]
|
|
34
|
+
const property = Object.getOwnPropertyDescriptor(this, key)
|
|
35
|
+
if (property && !('value' in property)) occurrences.get(this)?.keys.add(key)
|
|
36
|
+
if (current && typeof current === 'object') {
|
|
37
|
+
const keys = new Set()
|
|
38
|
+
const names = Array.isArray(current) ? Object.getOwnPropertyNames(current) : Object.keys(current)
|
|
39
|
+
for (const name of names) {
|
|
40
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, name)
|
|
41
|
+
if (descriptor && !('value' in descriptor)) keys.add(name)
|
|
42
|
+
}
|
|
43
|
+
const original = normalizeIdentity(current)
|
|
44
|
+
const record = { path, original, keys, state: captureIdentity?.(original) }
|
|
45
|
+
paths.set(current, path)
|
|
46
|
+
occurrences.set(current, record)
|
|
47
|
+
records.push(record)
|
|
48
|
+
}
|
|
49
|
+
return current
|
|
50
|
+
})
|
|
51
|
+
const envelope = JSON.parse(serialized)
|
|
52
|
+
for (const { path, original, keys, state } of records) {
|
|
53
|
+
let snapshot = envelope
|
|
54
|
+
for (const key of path) snapshot = snapshot[key]
|
|
55
|
+
snapshots.set(original, snapshot)
|
|
56
|
+
if (snapshot && typeof snapshot === 'object') {
|
|
57
|
+
originals.set(snapshot, original)
|
|
58
|
+
snapshots.set(snapshot, snapshot)
|
|
59
|
+
getters.set(snapshot, keys)
|
|
60
|
+
states.set(snapshot, state)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return envelope[propertyKey]
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @param {unknown} original
|
|
67
|
+
* @param {unknown} cached
|
|
68
|
+
*/
|
|
69
|
+
const selectOverrides = (original, cached) => {
|
|
70
|
+
if (!original || typeof original !== 'object' || !cached || typeof cached !== 'object') return cached
|
|
71
|
+
const prototype = Object.getPrototypeOf(original)
|
|
72
|
+
const source = originals.get(cached) || normalizeIdentity(cached)
|
|
73
|
+
if ((prototype !== Object.prototype && prototype !== null) || normalizeIdentity(original) === source ||
|
|
74
|
+
typeof Object.getOwnPropertyDescriptor(original, 'toJSON')?.value === 'function') return cached
|
|
75
|
+
// Keep partial-override membership, taking values from the occurrence already sent to Cypress.
|
|
76
|
+
return Object.fromEntries(Object.keys(original).flatMap(key => {
|
|
77
|
+
const property = Object.getOwnPropertyDescriptor(cached, key)
|
|
78
|
+
return property
|
|
79
|
+
? [[key, selectOverrides(Object.getOwnPropertyDescriptor(original, key).value, property.value)]]
|
|
80
|
+
: []
|
|
81
|
+
}))
|
|
82
|
+
}
|
|
83
|
+
if (wireConfig && typeof wireConfig === 'object') {
|
|
84
|
+
const cached = materialize(wireConfig, 'setupConfig')
|
|
85
|
+
if (cached !== wireConfig) {
|
|
86
|
+
const metadataKey = Symbol.for('dd-trace.cypress.returned-config')
|
|
87
|
+
const metadata = Object.getOwnPropertyDescriptor(wireConfig, metadataKey)
|
|
88
|
+
if (metadata && cached && typeof cached === 'object') {
|
|
89
|
+
Object.defineProperty(cached, metadataKey, metadata)
|
|
90
|
+
}
|
|
91
|
+
wireConfig = cached
|
|
92
|
+
forwardedArguments = [...arguments]
|
|
93
|
+
forwardedArguments[0] = {
|
|
94
|
+
...message,
|
|
95
|
+
args: [{ ...message.args[0], setupConfig: wireConfig }, ...message.args.slice(1)],
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const returnedConfig = wireConfig?.[Symbol.for('dd-trace.cypress.returned-config')] ?? wireConfig
|
|
100
|
+
const returnedDescriptor = returnedConfig && typeof returnedConfig === 'object' &&
|
|
101
|
+
Object.getOwnPropertyDescriptor(returnedConfig, 'retries')
|
|
102
|
+
let observedConfig
|
|
103
|
+
if (returnedDescriptor?.enumerable) {
|
|
104
|
+
const original = 'value' in returnedDescriptor ? returnedDescriptor.value : returnedConfig.retries
|
|
105
|
+
const wireRetry = wireConfig && typeof wireConfig === 'object' &&
|
|
106
|
+
Object.getOwnPropertyDescriptor(wireConfig, 'retries')
|
|
107
|
+
const wireValue = wireRetry && 'value' in wireRetry ? wireRetry.value : undefined
|
|
108
|
+
const cached = returnedConfig === wireConfig ? wireValue : selectOverrides(original, wireValue)
|
|
109
|
+
observedConfig = original === cached && 'value' in returnedDescriptor ? returnedConfig : { retries: cached }
|
|
110
|
+
}
|
|
111
|
+
onHandoff(observedConfig, message.event, {
|
|
112
|
+
originalFor: value => originals.get(value) || normalizeIdentity(value),
|
|
113
|
+
snapshotFor: value => snapshots.get(normalizeIdentity(value)) ?? value,
|
|
114
|
+
stateFor: value => states.get(normalizeIdentity(value)),
|
|
115
|
+
getterKeys: value => getters.get(normalizeIdentity(value)) || new Set(),
|
|
116
|
+
})
|
|
117
|
+
} finally {
|
|
118
|
+
stop()
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return originalSend.apply(this, forwardedArguments)
|
|
122
|
+
}
|
|
123
|
+
process.send = send
|
|
124
|
+
return stop
|
|
125
|
+
}
|