dd-trace 6.23.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.
- package/LICENSE-3rdparty.csv +0 -1
- package/ci/cypress/support.js +15 -1
- package/ci/init.js +2 -22
- package/ci/test-annotations.d.ts +5 -0
- package/ci/test-annotations.js +5 -0
- 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 -32
- 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 -1
- package/index.d.ts +124 -5
- package/initialize.mjs +5 -2
- package/lambda.d.ts +39 -0
- package/lambda.js +3 -0
- package/loader-hook.mjs +53 -0
- package/openfeature/exposure-hook.d.ts +66 -0
- package/openfeature/exposure-hook.js +5 -0
- package/package.json +19 -15
- package/packages/datadog-core/src/storage.js +1 -1
- package/packages/datadog-esbuild/index.js +78 -62
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +56 -19
- package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
- package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
- package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
- package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
- package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
- package/packages/datadog-instrumentations/src/graphql.js +29 -20
- package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
- package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- 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/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +4 -8
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +18 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +58 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +25 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/jest.js +265 -82
- 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 +58 -12
- package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
- package/packages/datadog-instrumentations/src/next.js +19 -6
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/oracledb.js +33 -0
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/pg.js +2 -1
- package/packages/datadog-instrumentations/src/playwright.js +81 -28
- package/packages/datadog-instrumentations/src/react-router.js +106 -0
- package/packages/datadog-instrumentations/src/typesafe.js +89 -0
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
- package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
- package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
- package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
- package/packages/datadog-instrumentations/src/vitest.js +10 -8
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-cucumber/src/index.js +5 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +296 -55
- 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 -439
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-graphql/src/execute.js +2 -2
- package/packages/datadog-plugin-graphql/src/utils.js +5 -5
- package/packages/datadog-plugin-http/src/client.js +32 -9
- package/packages/datadog-plugin-http2/src/client.js +38 -13
- package/packages/datadog-plugin-jest/src/index.js +25 -3
- package/packages/datadog-plugin-mocha/src/index.js +47 -6
- package/packages/datadog-plugin-next/src/index.js +112 -14
- 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-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-react-router/src/index.js +118 -0
- package/packages/datadog-plugin-trpc/src/index.js +15 -0
- package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
- package/packages/datadog-plugin-trpc/src/request.js +81 -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-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +8 -0
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/dd-trace/src/agent/info.js +2 -1
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/sdk.js +8 -13
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
- package/packages/dd-trace/src/appsec/graphql.js +91 -6
- package/packages/dd-trace/src/appsec/recommended.json +1287 -90
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +24 -18
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +16 -36
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +10 -18
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +10 -15
- 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/telemetry.js +6 -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 +10 -17
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
- package/packages/dd-trace/src/config/config-types.d.ts +3 -0
- package/packages/dd-trace/src/config/defaults.js +9 -3
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -2
- package/packages/dd-trace/src/config/index.js +111 -43
- package/packages/dd-trace/src/config/parsers.js +18 -1
- package/packages/dd-trace/src/config/supported-configurations.json +174 -4
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
- package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
- 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 +23 -15
- 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 +83 -50
- package/packages/dd-trace/src/exporters/common/retry.js +12 -7
- package/packages/dd-trace/src/exporters/common/url.js +1 -1
- 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/id.js +1 -1
- package/packages/dd-trace/src/lambda/facade.js +74 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +3 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- 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/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +27 -10
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
- package/packages/dd-trace/src/llmobs/sdk.js +21 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +219 -12
- package/packages/dd-trace/src/llmobs/tagger.js +25 -0
- package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +13 -2
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +68 -6
- package/packages/dd-trace/src/openfeature/configuration_source.js +41 -17
- 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/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +58 -14
- package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
- package/packages/dd-trace/src/openfeature/writers/base.js +63 -30
- 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/opentelemetry/logs/index.js +11 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
- package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
- package/packages/dd-trace/src/opentelemetry/span.js +2 -2
- package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +33 -13
- package/packages/dd-trace/src/otel-thread-ctx.js +72 -49
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +45 -14
- package/packages/dd-trace/src/plugins/index.js +9 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +18 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +273 -86
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +77 -50
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
- package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
- package/packages/dd-trace/src/plugins/util/tags.js +6 -0
- package/packages/dd-trace/src/plugins/util/test.js +90 -45
- package/packages/dd-trace/src/plugins/util/url.js +10 -2
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
- package/packages/dd-trace/src/plugins/util/web.js +81 -10
- 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/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/proxy.js +48 -57
- package/packages/dd-trace/src/serverless.js +3 -2
- package/packages/dd-trace/src/span_processor.js +41 -9
- package/packages/dd-trace/src/span_stats.js +28 -2
- package/packages/dd-trace/src/startup-log.js +8 -5
- 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 +1 -0
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/util.js +1 -1
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +4 -2
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/{@opentelemetry/resources → @datadog/flagging-core}/LICENSE +22 -2
- package/vendor/dist/@datadog/flagging-core/index.js +1 -0
- package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -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/@datadog/sketches-js/LICENSE +263 -0
- package/vendor/dist/@datadog/source-map/LICENSE +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -19
- package/ci/test-optimization-validation/blocker-category.js +0 -24
- package/ci/test-optimization-validation/bounded-json.js +0 -120
- package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
- package/ci/test-optimization-validation/ci-discovery.js +0 -192
- package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
- package/ci/test-optimization-validation/ci-remediation.js +0 -283
- package/ci/test-optimization-validation/cli.js +0 -954
- package/ci/test-optimization-validation/command-blocker.js +0 -377
- package/ci/test-optimization-validation/command-output-policy.js +0 -188
- package/ci/test-optimization-validation/command-runner.js +0 -650
- package/ci/test-optimization-validation/environment.js +0 -88
- package/ci/test-optimization-validation/executable-approval.js +0 -47
- package/ci/test-optimization-validation/executable.js +0 -244
- package/ci/test-optimization-validation/execution-lock.js +0 -70
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
- package/ci/test-optimization-validation/generated-file-policy.js +0 -63
- package/ci/test-optimization-validation/generated-files.js +0 -425
- package/ci/test-optimization-validation/generated-test-contract.js +0 -284
- package/ci/test-optimization-validation/generated-verifier.js +0 -235
- package/ci/test-optimization-validation/literal-environment.js +0 -56
- package/ci/test-optimization-validation/literal-glob.js +0 -52
- package/ci/test-optimization-validation/manifest-loader.js +0 -116
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
- package/ci/test-optimization-validation/manifest-schema.js +0 -695
- package/ci/test-optimization-validation/offline-fixtures.js +0 -335
- package/ci/test-optimization-validation/offline-output.js +0 -406
- package/ci/test-optimization-validation/package-check.js +0 -97
- package/ci/test-optimization-validation/payload-normalizer.js +0 -72
- package/ci/test-optimization-validation/plan-writer.js +0 -541
- package/ci/test-optimization-validation/preflight-runner.js +0 -186
- package/ci/test-optimization-validation/project-build-artifact.js +0 -31
- package/ci/test-optimization-validation/redaction.js +0 -319
- package/ci/test-optimization-validation/report-writer.js +0 -666
- package/ci/test-optimization-validation/result-semantics.js +0 -103
- package/ci/test-optimization-validation/runner-command.js +0 -264
- package/ci/test-optimization-validation/runner-contract.js +0 -695
- package/ci/test-optimization-validation/safe-files.js +0 -202
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
- package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
- package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
- package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
- package/ci/test-optimization-validation/source-text.js +0 -84
- package/ci/test-optimization-validation/static-diagnosis.js +0 -166
- package/ci/test-optimization-validation/test-output.js +0 -120
- package/ci/test-optimization-validation/validation-blocker.js +0 -21
- package/ci/validate-test-optimization.js +0 -3
- package/packages/datadog-esbuild/src/resolver.js +0 -284
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
- package/vendor/dist/@opentelemetry/resources/index.js +0 -1
|
@@ -1,650 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-console, eslint-rules/eslint-process-env */
|
|
4
|
-
|
|
5
|
-
const fs = require('node:fs')
|
|
6
|
-
const path = require('path')
|
|
7
|
-
const { spawn, spawnSync } = require('child_process')
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
cleanupCommandOutputs,
|
|
11
|
-
prepareCommandOutputs,
|
|
12
|
-
} = require('./command-output-policy')
|
|
13
|
-
const { getExecutableForSpawn } = require('./executable')
|
|
14
|
-
const {
|
|
15
|
-
environmentNamesEqual,
|
|
16
|
-
getEnvironmentValue,
|
|
17
|
-
isDatadogEnvironmentName,
|
|
18
|
-
mergeEnvironment,
|
|
19
|
-
setEnvironmentValue,
|
|
20
|
-
} = require('./environment')
|
|
21
|
-
const { sanitizeConsoleText, sanitizeString } = require('./redaction')
|
|
22
|
-
const { ensureSafeDirectory, writeFileSafely } = require('./safe-files')
|
|
23
|
-
|
|
24
|
-
const INIT_PATH = path.resolve(__dirname, '..', 'init.js')
|
|
25
|
-
const REGISTER_PATH = path.resolve(__dirname, '..', '..', 'register.js')
|
|
26
|
-
const VALIDATION_MODE_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MODE'
|
|
27
|
-
const VALIDATION_MANIFEST_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_MANIFEST_FILE'
|
|
28
|
-
const VALIDATION_OUTPUT_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_OUTPUT_DIR'
|
|
29
|
-
const VALIDATION_CAPTURE_MODE_ENV = '_DD_TEST_OPTIMIZATION_VALIDATION_CAPTURE_MODE'
|
|
30
|
-
const APM_AGENTLESS_ENV = '_DD_APM_TRACING_AGENTLESS_ENABLED'
|
|
31
|
-
const VALIDATION_RESERVED_ENV_NAMES = [
|
|
32
|
-
'NODE_OPTIONS',
|
|
33
|
-
VALIDATION_MANIFEST_ENV,
|
|
34
|
-
VALIDATION_MODE_ENV,
|
|
35
|
-
VALIDATION_OUTPUT_ENV,
|
|
36
|
-
VALIDATION_CAPTURE_MODE_ENV,
|
|
37
|
-
APM_AGENTLESS_ENV,
|
|
38
|
-
]
|
|
39
|
-
const CLEAN_ENV_ALLOWLIST = new Set([
|
|
40
|
-
'COMSPEC',
|
|
41
|
-
'ComSpec',
|
|
42
|
-
'HOME',
|
|
43
|
-
'LOGNAME',
|
|
44
|
-
'PATH',
|
|
45
|
-
'Path',
|
|
46
|
-
'PATHEXT',
|
|
47
|
-
'SHELL',
|
|
48
|
-
'SystemRoot',
|
|
49
|
-
'TEMP',
|
|
50
|
-
'TMP',
|
|
51
|
-
'TMPDIR',
|
|
52
|
-
'USER',
|
|
53
|
-
'USERNAME',
|
|
54
|
-
'VOLTA_HOME',
|
|
55
|
-
'WINDIR',
|
|
56
|
-
'windir',
|
|
57
|
-
])
|
|
58
|
-
const VALIDATION_SUPPRESSION_ENV = {
|
|
59
|
-
DD_AGENTLESS_LOG_SUBMISSION_ENABLED: 'false',
|
|
60
|
-
DD_APPSEC_ENABLED: 'false',
|
|
61
|
-
DD_CRASHTRACKING_ENABLED: 'false',
|
|
62
|
-
DD_DATA_STREAMS_ENABLED: 'false',
|
|
63
|
-
DD_DYNAMIC_INSTRUMENTATION_ENABLED: 'false',
|
|
64
|
-
DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED: 'false',
|
|
65
|
-
DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED: 'false',
|
|
66
|
-
DD_HEAP_SNAPSHOT_COUNT: '0',
|
|
67
|
-
DD_IAST_ENABLED: 'false',
|
|
68
|
-
DD_INSTRUMENTATION_TELEMETRY_ENABLED: 'false',
|
|
69
|
-
DD_LLMOBS_ENABLED: 'false',
|
|
70
|
-
DD_LOGS_OTEL_ENABLED: 'false',
|
|
71
|
-
DD_METRICS_OTEL_ENABLED: 'false',
|
|
72
|
-
DD_PROFILING_ENABLED: 'false',
|
|
73
|
-
DD_REMOTE_CONFIGURATION_ENABLED: 'false',
|
|
74
|
-
DD_RUNTIME_METRICS_ENABLED: 'false',
|
|
75
|
-
DD_TRACE_OTEL_ENABLED: 'false',
|
|
76
|
-
DD_TRACE_SPAN_LEAK_DEBUG: '0',
|
|
77
|
-
// Offline validation only needs test-cycle events and explicitly configured filesystem inputs.
|
|
78
|
-
DD_CIVISIBILITY_GIT_UPLOAD_ENABLED: 'false',
|
|
79
|
-
DD_CIVISIBILITY_GIT_UNSHALLOW_ENABLED: 'false',
|
|
80
|
-
DD_CIVISIBILITY_IMPACTED_TESTS_DETECTION_ENABLED: 'false',
|
|
81
|
-
DD_EXPERIMENTAL_TEST_REQUESTS_FS_CACHE: 'false',
|
|
82
|
-
DD_TEST_FAILED_TEST_REPLAY_ENABLED: 'false',
|
|
83
|
-
}
|
|
84
|
-
const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024
|
|
85
|
-
const EARLY_STOP_KILL_GRACE_MS = 500
|
|
86
|
-
const TIMEOUT_KILL_GRACE_MS = 5000
|
|
87
|
-
const TIMEOUT_FINALIZE_GRACE_MS = 1000
|
|
88
|
-
const WINDOWS_TASKKILL_TIMEOUT_MS = 10_000
|
|
89
|
-
|
|
90
|
-
function runCommand (command, options = {}) {
|
|
91
|
-
const {
|
|
92
|
-
env = {},
|
|
93
|
-
envMode = 'inherit',
|
|
94
|
-
outDir,
|
|
95
|
-
label,
|
|
96
|
-
repositoryRoot,
|
|
97
|
-
requireExecutableApproval = false,
|
|
98
|
-
stopWhen,
|
|
99
|
-
verbose = false,
|
|
100
|
-
} = options
|
|
101
|
-
const artifactRoot = options.artifactRoot || path.dirname(outDir)
|
|
102
|
-
const startedAt = Date.now()
|
|
103
|
-
const {
|
|
104
|
-
maxOutputBytes,
|
|
105
|
-
timeoutFinalizeGraceMs,
|
|
106
|
-
timeoutKillGraceMs,
|
|
107
|
-
timeoutMs,
|
|
108
|
-
} = getCommandExecutionSettings(command)
|
|
109
|
-
const result = {
|
|
110
|
-
label,
|
|
111
|
-
command: serializeCommand(command),
|
|
112
|
-
displayCommand: serializeDisplayCommand(command),
|
|
113
|
-
commandDetails: getCommandDetails(command),
|
|
114
|
-
cwd: command.cwd,
|
|
115
|
-
exitCode: null,
|
|
116
|
-
signal: null,
|
|
117
|
-
stoppedEarly: false,
|
|
118
|
-
durationMs: 0,
|
|
119
|
-
timedOut: false,
|
|
120
|
-
stdout: '',
|
|
121
|
-
stdoutOmittedBytes: 0,
|
|
122
|
-
stdoutTruncated: false,
|
|
123
|
-
stderr: '',
|
|
124
|
-
stderrOmittedBytes: 0,
|
|
125
|
-
stderrTruncated: false,
|
|
126
|
-
artifacts: {},
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
ensureSafeDirectory(artifactRoot, outDir, 'command artifact directory')
|
|
130
|
-
try {
|
|
131
|
-
assertNoInlineValidationEnvOverrides(command, env)
|
|
132
|
-
} catch (error) {
|
|
133
|
-
return Promise.reject(error)
|
|
134
|
-
}
|
|
135
|
-
const missingRequiredEnvVars = getMissingRequiredEnvironmentNames(command.requiredEnvVars)
|
|
136
|
-
if (missingRequiredEnvVars.length > 0) {
|
|
137
|
-
result.missingRequiredEnvVars = missingRequiredEnvVars
|
|
138
|
-
result.stderr = 'The approved command requires environment variables that are not available: ' +
|
|
139
|
-
`${missingRequiredEnvVars.join(', ')}.\n`
|
|
140
|
-
result.durationMs = Date.now() - startedAt
|
|
141
|
-
return Promise.resolve(result)
|
|
142
|
-
}
|
|
143
|
-
const outputStates = prepareCommandOutputs({ command, artifactRoot, outDir, repositoryRoot })
|
|
144
|
-
|
|
145
|
-
return new Promise((resolve) => {
|
|
146
|
-
let finalized = false
|
|
147
|
-
let processTreeCleanupPending = false
|
|
148
|
-
let pendingCloseResult
|
|
149
|
-
const childEnv = { ...getBaseEnv(envMode, command.requiredEnvVars) }
|
|
150
|
-
mergeEnvironment(childEnv, command.env)
|
|
151
|
-
mergeEnvironment(childEnv, env)
|
|
152
|
-
const commandNodeOptions = getEnvironmentValue(command.env || {}, 'NODE_OPTIONS')
|
|
153
|
-
const injectedNodeOptions = getEnvironmentValue(env, 'NODE_OPTIONS')
|
|
154
|
-
if (commandNodeOptions && injectedNodeOptions) {
|
|
155
|
-
setEnvironmentValue(childEnv, 'NODE_OPTIONS', mergeNodeOptions(injectedNodeOptions, commandNodeOptions))
|
|
156
|
-
}
|
|
157
|
-
for (const [name, value] of Object.entries(childEnv)) {
|
|
158
|
-
if (value === undefined) delete childEnv[name]
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const useProcessGroup = shouldUseProcessGroup()
|
|
162
|
-
const windowsTaskkillPath = getWindowsTaskkillPath()
|
|
163
|
-
if (process.platform === 'win32' && !windowsTaskkillPath) {
|
|
164
|
-
result.stderr = 'Validation cannot safely bound test processes because the Windows process-tree cleanup ' +
|
|
165
|
-
'executable is unavailable.\n'
|
|
166
|
-
result.durationMs = Date.now() - startedAt
|
|
167
|
-
try {
|
|
168
|
-
finishCommandOutputCleanup(result, outputStates)
|
|
169
|
-
} catch (cleanupError) {
|
|
170
|
-
result.outputCleanupError = cleanupError?.message || String(cleanupError)
|
|
171
|
-
}
|
|
172
|
-
resolve(result)
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
const managesProcessTree = useProcessGroup || Boolean(windowsTaskkillPath)
|
|
176
|
-
let child
|
|
177
|
-
try {
|
|
178
|
-
const executable = getExecutableForSpawn(command, { requireApproval: requireExecutableApproval })
|
|
179
|
-
const argv0 = process.platform === 'win32' ? {} : { argv0: executable.argv0 }
|
|
180
|
-
child = spawn(executable.path, command.argv.slice(1), {
|
|
181
|
-
...argv0,
|
|
182
|
-
cwd: command.cwd,
|
|
183
|
-
detached: useProcessGroup,
|
|
184
|
-
env: childEnv,
|
|
185
|
-
shell: false,
|
|
186
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
187
|
-
})
|
|
188
|
-
} catch (error) {
|
|
189
|
-
result.stderr = `${error.stack || error}\n`
|
|
190
|
-
result.durationMs = Date.now() - startedAt
|
|
191
|
-
try {
|
|
192
|
-
finishCommandOutputCleanup(result, outputStates)
|
|
193
|
-
} catch (cleanupError) {
|
|
194
|
-
result.outputCleanupError = cleanupError?.message || String(cleanupError)
|
|
195
|
-
}
|
|
196
|
-
resolve(result)
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (verbose) {
|
|
201
|
-
console.log(sanitizeConsoleText(
|
|
202
|
-
`[test-optimization-validator] running ${label || serializeCommand(command)}`
|
|
203
|
-
))
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
let killTimer
|
|
207
|
-
let finalizeTimer
|
|
208
|
-
let stopTimer
|
|
209
|
-
let stdoutCapture
|
|
210
|
-
let stderrCapture
|
|
211
|
-
const timeout = setTimeout(() => {
|
|
212
|
-
result.timedOut = true
|
|
213
|
-
processTreeCleanupPending = managesProcessTree
|
|
214
|
-
signalChild(child, 'SIGTERM', useProcessGroup, windowsTaskkillPath)
|
|
215
|
-
killTimer = setTimeout(() => {
|
|
216
|
-
signalChild(child, 'SIGKILL', useProcessGroup, windowsTaskkillPath)
|
|
217
|
-
finishProcessTreeCleanup('SIGKILL')
|
|
218
|
-
}, timeoutKillGraceMs)
|
|
219
|
-
}, timeoutMs)
|
|
220
|
-
|
|
221
|
-
if (stopWhen) {
|
|
222
|
-
stopTimer = setInterval(() => {
|
|
223
|
-
let shouldStop = false
|
|
224
|
-
try {
|
|
225
|
-
shouldStop = stopWhen()
|
|
226
|
-
} catch {}
|
|
227
|
-
if (!shouldStop) return
|
|
228
|
-
|
|
229
|
-
clearInterval(stopTimer)
|
|
230
|
-
result.stoppedEarly = true
|
|
231
|
-
processTreeCleanupPending = managesProcessTree
|
|
232
|
-
signalChild(child, 'SIGTERM', useProcessGroup, windowsTaskkillPath)
|
|
233
|
-
killTimer = setTimeout(() => {
|
|
234
|
-
signalChild(child, 'SIGKILL', useProcessGroup, windowsTaskkillPath)
|
|
235
|
-
finishProcessTreeCleanup('SIGKILL')
|
|
236
|
-
}, EARLY_STOP_KILL_GRACE_MS)
|
|
237
|
-
}, 25)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
child.stdout.on('data', chunk => {
|
|
241
|
-
const capture = appendCapturedOutput(stdoutCapture, chunk, maxOutputBytes)
|
|
242
|
-
stdoutCapture = capture
|
|
243
|
-
result.stdout = capture.output
|
|
244
|
-
result.stdoutOmittedBytes = capture.omittedBytes
|
|
245
|
-
result.stdoutTruncated = capture.truncated
|
|
246
|
-
})
|
|
247
|
-
child.stderr.on('data', chunk => {
|
|
248
|
-
const capture = appendCapturedOutput(stderrCapture, chunk, maxOutputBytes)
|
|
249
|
-
stderrCapture = capture
|
|
250
|
-
result.stderr = capture.output
|
|
251
|
-
result.stderrOmittedBytes = capture.omittedBytes
|
|
252
|
-
result.stderrTruncated = capture.truncated
|
|
253
|
-
})
|
|
254
|
-
child.on('error', err => {
|
|
255
|
-
result.stderr += `${err.stack || err}\n`
|
|
256
|
-
finalize(null, null)
|
|
257
|
-
})
|
|
258
|
-
child.on('close', (code, signal) => {
|
|
259
|
-
if (processTreeCleanupPending) {
|
|
260
|
-
pendingCloseResult = { code, signal }
|
|
261
|
-
signalChild(child, 'SIGKILL', useProcessGroup, windowsTaskkillPath)
|
|
262
|
-
finishProcessTreeCleanup(signal)
|
|
263
|
-
return
|
|
264
|
-
}
|
|
265
|
-
finalize(code, signal)
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
function finishProcessTreeCleanup (fallbackSignal) {
|
|
269
|
-
processTreeCleanupPending = false
|
|
270
|
-
if (pendingCloseResult) {
|
|
271
|
-
finalize(pendingCloseResult.code, pendingCloseResult.signal || fallbackSignal)
|
|
272
|
-
return
|
|
273
|
-
}
|
|
274
|
-
finalizeTimer = setTimeout(() => finalize(null, fallbackSignal), timeoutFinalizeGraceMs)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function finalize (code, signal) {
|
|
278
|
-
if (finalized) return
|
|
279
|
-
finalized = true
|
|
280
|
-
clearTimeout(timeout)
|
|
281
|
-
clearTimeout(killTimer)
|
|
282
|
-
clearTimeout(finalizeTimer)
|
|
283
|
-
clearInterval(stopTimer)
|
|
284
|
-
result.exitCode = code
|
|
285
|
-
result.signal = signal
|
|
286
|
-
result.durationMs = Date.now() - startedAt
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
finishCommandOutputCleanup(result, outputStates)
|
|
290
|
-
} catch (err) {
|
|
291
|
-
result.outputCleanupError = err && err.message ? err.message : String(err)
|
|
292
|
-
result.stderr += '\n[test-optimization-validator] could not clean up command outputs: ' +
|
|
293
|
-
`${result.outputCleanupError}\n`
|
|
294
|
-
if (result.exitCode === 0) result.exitCode = 1
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
result.artifacts.stdout = path.join(outDir, 'stdout.txt')
|
|
298
|
-
result.artifacts.stderr = path.join(outDir, 'stderr.txt')
|
|
299
|
-
result.artifacts.command = path.join(outDir, 'command.json')
|
|
300
|
-
|
|
301
|
-
try {
|
|
302
|
-
writeFileSafely(
|
|
303
|
-
artifactRoot,
|
|
304
|
-
result.artifacts.stdout,
|
|
305
|
-
sanitizeString(result.stdout),
|
|
306
|
-
'command stdout artifact'
|
|
307
|
-
)
|
|
308
|
-
writeFileSafely(
|
|
309
|
-
artifactRoot,
|
|
310
|
-
result.artifacts.stderr,
|
|
311
|
-
sanitizeString(result.stderr),
|
|
312
|
-
'command stderr artifact'
|
|
313
|
-
)
|
|
314
|
-
writeFileSafely(artifactRoot, result.artifacts.command, `${JSON.stringify({
|
|
315
|
-
command: sanitizeString(result.command),
|
|
316
|
-
displayCommand: sanitizeString(result.displayCommand),
|
|
317
|
-
commandDetails: result.commandDetails,
|
|
318
|
-
cwd: result.cwd,
|
|
319
|
-
exitCode: result.exitCode,
|
|
320
|
-
signal: result.signal,
|
|
321
|
-
durationMs: result.durationMs,
|
|
322
|
-
timedOut: result.timedOut,
|
|
323
|
-
stoppedEarly: result.stoppedEarly,
|
|
324
|
-
stdoutTruncated: result.stdoutTruncated,
|
|
325
|
-
stdoutOmittedBytes: result.stdoutOmittedBytes,
|
|
326
|
-
stderrTruncated: result.stderrTruncated,
|
|
327
|
-
stderrOmittedBytes: result.stderrOmittedBytes,
|
|
328
|
-
maxOutputBytes,
|
|
329
|
-
commandOutputPaths: result.commandOutputPaths,
|
|
330
|
-
outputCleanupError: result.outputCleanupError,
|
|
331
|
-
}, null, 2)}\n`, 'command metadata artifact')
|
|
332
|
-
} catch (error) {
|
|
333
|
-
result.artifactWriteError = error?.message || String(error)
|
|
334
|
-
result.stderr += '\n[test-optimization-validator] could not write command artifacts: ' +
|
|
335
|
-
`${result.artifactWriteError}\n`
|
|
336
|
-
if (!Number.isInteger(result.exitCode) || result.exitCode === 0) result.exitCode = 1
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
resolve(result)
|
|
340
|
-
}
|
|
341
|
-
})
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Cleans command outputs after the command exits.
|
|
346
|
-
*
|
|
347
|
-
* @param {object} result command result
|
|
348
|
-
* @param {object[]} outputStates prepared command output state
|
|
349
|
-
*/
|
|
350
|
-
function finishCommandOutputCleanup (result, outputStates) {
|
|
351
|
-
result.commandOutputPaths = cleanupCommandOutputs(outputStates)
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Returns the effective bounded execution settings used for one project command.
|
|
356
|
-
*
|
|
357
|
-
* @param {object} command structured command
|
|
358
|
-
* @returns {{maxOutputBytes: number, timeoutFinalizeGraceMs: number, timeoutKillGraceMs: number, timeoutMs: number}}
|
|
359
|
-
* execution settings
|
|
360
|
-
*/
|
|
361
|
-
function getCommandExecutionSettings (command) {
|
|
362
|
-
return {
|
|
363
|
-
maxOutputBytes: command.maxOutputBytes || DEFAULT_MAX_OUTPUT_BYTES,
|
|
364
|
-
timeoutFinalizeGraceMs: command.timeoutFinalizeGraceMs || TIMEOUT_FINALIZE_GRACE_MS,
|
|
365
|
-
timeoutKillGraceMs: command.timeoutKillGraceMs || TIMEOUT_KILL_GRACE_MS,
|
|
366
|
-
timeoutMs: command.timeoutMs || 300_000,
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Appends output while retaining only the latest bytes for diagnostic artifacts.
|
|
372
|
-
*
|
|
373
|
-
* @param {object|undefined} current currently captured output state
|
|
374
|
-
* @param {Buffer|string} chunk new output chunk
|
|
375
|
-
* @param {number} maxBytes maximum retained bytes
|
|
376
|
-
* @returns {{output: string, truncated: boolean}} retained output and truncation flag
|
|
377
|
-
*/
|
|
378
|
-
function appendCapturedOutput (current, chunk, maxBytes) {
|
|
379
|
-
const nextChunk = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))
|
|
380
|
-
const totalBytes = (current?.totalBytes || 0) + nextChunk.length
|
|
381
|
-
const headLimit = Math.floor(maxBytes / 2)
|
|
382
|
-
const tailLimit = maxBytes - headLimit
|
|
383
|
-
let head = current?.head || Buffer.alloc(0)
|
|
384
|
-
let tail
|
|
385
|
-
|
|
386
|
-
if (current?.truncated) {
|
|
387
|
-
const combinedTail = Buffer.concat([current.tail, nextChunk])
|
|
388
|
-
tail = combinedTail.subarray(Math.max(0, combinedTail.length - tailLimit))
|
|
389
|
-
} else {
|
|
390
|
-
const combined = Buffer.concat([current?.tail || Buffer.alloc(0), nextChunk])
|
|
391
|
-
if (combined.length <= maxBytes) {
|
|
392
|
-
return {
|
|
393
|
-
head,
|
|
394
|
-
tail: combined,
|
|
395
|
-
totalBytes,
|
|
396
|
-
omittedBytes: 0,
|
|
397
|
-
output: combined.toString('utf8'),
|
|
398
|
-
truncated: false,
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
head = combined.subarray(0, headLimit)
|
|
402
|
-
tail = combined.subarray(combined.length - tailLimit)
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const omittedBytes = totalBytes - head.length - tail.length
|
|
406
|
-
return {
|
|
407
|
-
head,
|
|
408
|
-
tail,
|
|
409
|
-
totalBytes,
|
|
410
|
-
omittedBytes,
|
|
411
|
-
output: `${head.toString('utf8')}\n[test-optimization-validator] ${omittedBytes} bytes omitted\n` +
|
|
412
|
-
tail.toString('utf8'),
|
|
413
|
-
truncated: true,
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function shouldUseProcessGroup () {
|
|
418
|
-
return process.platform !== 'win32'
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Resolves the fixed Windows process-tree cleanup executable without PATH lookup.
|
|
423
|
-
*
|
|
424
|
-
* @returns {string|undefined} physical taskkill executable
|
|
425
|
-
*/
|
|
426
|
-
function getWindowsTaskkillPath () {
|
|
427
|
-
if (process.platform !== 'win32') return
|
|
428
|
-
|
|
429
|
-
const systemRoot = getEnvironmentValue(process.env, 'SystemRoot') ||
|
|
430
|
-
getEnvironmentValue(process.env, 'WINDIR')
|
|
431
|
-
if (!systemRoot || !path.win32.isAbsolute(systemRoot)) return
|
|
432
|
-
|
|
433
|
-
try {
|
|
434
|
-
const root = fs.realpathSync(systemRoot)
|
|
435
|
-
const candidate = path.win32.join(root, 'System32', 'taskkill.exe')
|
|
436
|
-
const stat = fs.lstatSync(candidate)
|
|
437
|
-
const physical = fs.realpathSync(candidate)
|
|
438
|
-
const relative = path.win32.relative(root, physical)
|
|
439
|
-
if (!stat.isFile() || stat.isSymbolicLink() ||
|
|
440
|
-
relative.startsWith('..') || path.win32.isAbsolute(relative)) return
|
|
441
|
-
return physical
|
|
442
|
-
} catch {}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
function signalChild (child, signal, useProcessGroup, windowsTaskkillPath) {
|
|
446
|
-
if (windowsTaskkillPath) {
|
|
447
|
-
try {
|
|
448
|
-
const args = ['/PID', String(child.pid), '/T', '/F']
|
|
449
|
-
const outcome = spawnSync(windowsTaskkillPath, args, {
|
|
450
|
-
shell: false,
|
|
451
|
-
stdio: 'ignore',
|
|
452
|
-
timeout: WINDOWS_TASKKILL_TIMEOUT_MS,
|
|
453
|
-
windowsHide: true,
|
|
454
|
-
})
|
|
455
|
-
if (!outcome.error && outcome.status === 0) return
|
|
456
|
-
} catch {}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
try {
|
|
460
|
-
if (useProcessGroup) {
|
|
461
|
-
process.kill(-child.pid, signal)
|
|
462
|
-
return
|
|
463
|
-
}
|
|
464
|
-
} catch {}
|
|
465
|
-
|
|
466
|
-
child.kill(signal)
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function getBaseEnv (envMode, requiredEnvVars = []) {
|
|
470
|
-
if (envMode !== 'clean') return process.env
|
|
471
|
-
|
|
472
|
-
const cleanEnv = {}
|
|
473
|
-
for (const name of [...CLEAN_ENV_ALLOWLIST, ...requiredEnvVars]) {
|
|
474
|
-
const entry = Object.entries(process.env).find(([candidate]) => {
|
|
475
|
-
return environmentNamesEqual(candidate, name)
|
|
476
|
-
})
|
|
477
|
-
if (entry) setEnvironmentValue(cleanEnv, name, entry[1])
|
|
478
|
-
}
|
|
479
|
-
return cleanEnv
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Finds explicitly approved ambient variables that are unavailable at execution time.
|
|
484
|
-
*
|
|
485
|
-
* @param {string[]|undefined} requiredEnvVars approved variable names
|
|
486
|
-
* @returns {string[]} missing names
|
|
487
|
-
*/
|
|
488
|
-
function getMissingRequiredEnvironmentNames (requiredEnvVars = []) {
|
|
489
|
-
return requiredEnvVars.filter(name => getEnvironmentValue(process.env, name) === undefined)
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
function buildDatadogEnv ({ fixture, outputRoot, scenario, framework }) {
|
|
493
|
-
const offline = buildOfflineValidationEnv({ fixture, outputRoot })
|
|
494
|
-
return {
|
|
495
|
-
...offline,
|
|
496
|
-
DD_CIVISIBILITY_AGENTLESS_ENABLED: '0',
|
|
497
|
-
DD_CIVISIBILITY_ENABLED: '1',
|
|
498
|
-
DD_TRACE_ENABLED: 'true',
|
|
499
|
-
...VALIDATION_SUPPRESSION_ENV,
|
|
500
|
-
DD_SERVICE: 'dd-test-optimization-validation',
|
|
501
|
-
DD_ENV: 'local-validation',
|
|
502
|
-
DD_CIVISIBILITY_FLAKY_RETRY_COUNT: '2',
|
|
503
|
-
DD_TAGS: `test_optimization.validation.scenario:${scenario}`,
|
|
504
|
-
NODE_OPTIONS: withCiPreloads('', framework),
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function buildOfflineCaptureEnv ({ fixture, outputRoot }) {
|
|
509
|
-
return {
|
|
510
|
-
...buildOfflineValidationEnv({ fixture, outputRoot }),
|
|
511
|
-
[VALIDATION_CAPTURE_MODE_ENV]: 'sample',
|
|
512
|
-
DD_TRACE_DEBUG: '1',
|
|
513
|
-
DD_TRACE_LOG_LEVEL: 'debug',
|
|
514
|
-
...VALIDATION_SUPPRESSION_ENV,
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* Builds the private environment used by the filesystem-only validation exporter.
|
|
520
|
-
*
|
|
521
|
-
* @param {object} input offline validation inputs
|
|
522
|
-
* @param {{manifestPath: string}} input.fixture authoritative cache fixture
|
|
523
|
-
* @param {string} input.outputRoot pre-created payload output root
|
|
524
|
-
* @returns {typeof process.env} validation transport environment
|
|
525
|
-
*/
|
|
526
|
-
function buildOfflineValidationEnv ({ fixture, outputRoot }) {
|
|
527
|
-
return {
|
|
528
|
-
DD_AGENT_HOST: undefined,
|
|
529
|
-
DD_API_KEY: undefined,
|
|
530
|
-
DD_APP_KEY: undefined,
|
|
531
|
-
DATADOG_API_KEY: undefined,
|
|
532
|
-
[APM_AGENTLESS_ENV]: undefined,
|
|
533
|
-
DD_CIVISIBILITY_AGENTLESS_ENABLED: '0',
|
|
534
|
-
DD_CIVISIBILITY_AGENTLESS_URL: undefined,
|
|
535
|
-
DD_EXPERIMENTAL_TEST_OPT_SETTINGS_CACHE: undefined,
|
|
536
|
-
DD_TRACE_AGENT_HOSTNAME: undefined,
|
|
537
|
-
DD_TRACE_AGENT_PORT: undefined,
|
|
538
|
-
DD_TRACE_AGENT_UNIX_DOMAIN_SOCKET: undefined,
|
|
539
|
-
DD_TRACE_AGENT_URL: undefined,
|
|
540
|
-
OTEL_LOGS_EXPORTER: undefined,
|
|
541
|
-
OTEL_METRICS_EXPORTER: undefined,
|
|
542
|
-
OTEL_TRACES_EXPORTER: undefined,
|
|
543
|
-
[VALIDATION_MANIFEST_ENV]: fixture.manifestPath,
|
|
544
|
-
[VALIDATION_MODE_ENV]: '1',
|
|
545
|
-
[VALIDATION_OUTPUT_ENV]: outputRoot,
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Rejects command-local assignments that can bypass validator-controlled offline routing.
|
|
551
|
-
*
|
|
552
|
-
* @param {object} command command to execute
|
|
553
|
-
* @param {typeof process.env} env validator environment overrides
|
|
554
|
-
*/
|
|
555
|
-
function assertNoInlineValidationEnvOverrides (command, env) {
|
|
556
|
-
if (!env[VALIDATION_MODE_ENV]) return
|
|
557
|
-
if (command.env) {
|
|
558
|
-
for (const name of Object.keys(command.env)) {
|
|
559
|
-
const normalized = process.platform === 'win32' ? name.toUpperCase() : name
|
|
560
|
-
if (VALIDATION_RESERVED_ENV_NAMES.some(reserved => environmentNamesEqual(reserved, name)) ||
|
|
561
|
-
isDatadogEnvironmentName(name) || normalized.startsWith('OTEL_')) {
|
|
562
|
-
throw new Error(`Direct-runner adapter must not override validator-controlled environment variable ${name}.`)
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
function withCiPreloads (nodeOptions = '', framework) {
|
|
569
|
-
let result = nodeOptions.trim()
|
|
570
|
-
|
|
571
|
-
if (framework?.framework === 'vitest' && !hasRegister(result)) {
|
|
572
|
-
result = `--import ${formatNodeRequire(REGISTER_PATH)}${result ? ` ${result}` : ''}`
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
if (!hasCiInit(result)) {
|
|
576
|
-
result = `${result ? `${result} ` : ''}-r ${formatNodeRequire(INIT_PATH)}`
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
return result
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
function mergeNodeOptions (...nodeOptions) {
|
|
583
|
-
return nodeOptions
|
|
584
|
-
.map(value => String(value || '').trim())
|
|
585
|
-
.filter(Boolean)
|
|
586
|
-
.join(' ')
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
function hasCiInit (nodeOptions) {
|
|
590
|
-
return nodeOptions.includes('dd-trace/ci/init') || nodeOptions.includes(INIT_PATH)
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
function hasRegister (nodeOptions) {
|
|
594
|
-
return nodeOptions.includes('dd-trace/register.js') || nodeOptions.includes(REGISTER_PATH)
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function formatNodeRequire (filename) {
|
|
598
|
-
if (!/\s/.test(filename)) return filename
|
|
599
|
-
return JSON.stringify(filename)
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
function serializeCommand (command) {
|
|
603
|
-
return command.argv.join(' ')
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* Renders the command that will actually execute without trusting display-only manifest fields.
|
|
608
|
-
*
|
|
609
|
-
* @param {object} command command to render
|
|
610
|
-
*/
|
|
611
|
-
function serializeApprovalCommand (command) {
|
|
612
|
-
return command.argv.map(formatApprovalArgument).join(' ')
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Quotes arguments whose boundaries would otherwise be ambiguous in an approval plan.
|
|
617
|
-
*
|
|
618
|
-
* @param {string} value argument value
|
|
619
|
-
*/
|
|
620
|
-
function formatApprovalArgument (value) {
|
|
621
|
-
const argument = String(value)
|
|
622
|
-
if (/^[A-Za-z0-9_@%+=:,./\\-]+$/.test(argument)) return argument
|
|
623
|
-
if (process.platform === 'win32') return JSON.stringify(argument)
|
|
624
|
-
return `'${argument.replaceAll('\'', '\'"\'"\'')}'`
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
function serializeDisplayCommand (command) {
|
|
628
|
-
return command.argv.join(' ')
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
function getCommandDetails (command) {
|
|
632
|
-
return {
|
|
633
|
-
executionBoundary: 'validator-owned-direct-runner',
|
|
634
|
-
runner: command.argv[1],
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
module.exports = {
|
|
639
|
-
runCommand,
|
|
640
|
-
buildOfflineCaptureEnv,
|
|
641
|
-
buildDatadogEnv,
|
|
642
|
-
getBaseEnv,
|
|
643
|
-
getCommandDetails,
|
|
644
|
-
getCommandExecutionSettings,
|
|
645
|
-
serializeApprovalCommand,
|
|
646
|
-
serializeCommand,
|
|
647
|
-
serializeDisplayCommand,
|
|
648
|
-
withCiPreloads,
|
|
649
|
-
mergeNodeOptions,
|
|
650
|
-
}
|