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,1276 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs')
|
|
4
|
-
const path = require('node:path')
|
|
5
|
-
|
|
6
|
-
const { runDiagnosis } = require('../diagnose')
|
|
7
|
-
const { BLOCKER_CATEGORIES } = require('./blocker-category')
|
|
8
|
-
const cucumber = require('./framework-adapters/cucumber')
|
|
9
|
-
const cypress = require('./framework-adapters/cypress')
|
|
10
|
-
const playwright = require('./framework-adapters/playwright')
|
|
11
|
-
const vitest = require('./framework-adapters/vitest')
|
|
12
|
-
const { isProjectBuildArtifactPath } = require('./project-build-artifact')
|
|
13
|
-
const {
|
|
14
|
-
GENERATED_SCENARIOS,
|
|
15
|
-
getGeneratedRetryStatePath,
|
|
16
|
-
getGeneratedTestContent,
|
|
17
|
-
} = require('./generated-test-contract')
|
|
18
|
-
const { validateManifest } = require('./manifest-schema')
|
|
19
|
-
const {
|
|
20
|
-
getProjectNodeRunner,
|
|
21
|
-
getRunnerConfigurationContract,
|
|
22
|
-
getRunnerContract,
|
|
23
|
-
getRunnerSearchRoots,
|
|
24
|
-
} = require('./runner-contract')
|
|
25
|
-
|
|
26
|
-
const SUPPORTED_FRAMEWORKS = new Set(['cucumber', 'cypress', 'jest', 'mocha', 'playwright', 'vitest'])
|
|
27
|
-
const MAX_DISCOVERY_ENTRIES = 5000
|
|
28
|
-
const MAX_DIRECTORY_ENTRIES = 1024
|
|
29
|
-
const MAX_FILE_BYTES = 512 * 1024
|
|
30
|
-
const MAX_CI_FILES = 256
|
|
31
|
-
const MAX_CI_REVIEW_TARGETS = 3
|
|
32
|
-
const SKIPPED_DIRECTORIES = new Set([
|
|
33
|
-
'.git',
|
|
34
|
-
'.hg',
|
|
35
|
-
'.svn',
|
|
36
|
-
'.yarn',
|
|
37
|
-
'build',
|
|
38
|
-
'coverage',
|
|
39
|
-
'dd-test-optimization-validation-results',
|
|
40
|
-
'dist',
|
|
41
|
-
'node_modules',
|
|
42
|
-
'out',
|
|
43
|
-
'target',
|
|
44
|
-
'vendor',
|
|
45
|
-
])
|
|
46
|
-
const CI_PATHS = [
|
|
47
|
-
'.github/workflows',
|
|
48
|
-
'.gitlab-ci.yml',
|
|
49
|
-
'.circleci/config.yml',
|
|
50
|
-
'.buildkite/pipeline.yml',
|
|
51
|
-
'bitbucket-pipelines.yml',
|
|
52
|
-
'azure-pipelines.yml',
|
|
53
|
-
'Jenkinsfile',
|
|
54
|
-
]
|
|
55
|
-
const CONFIG_PATTERNS = {
|
|
56
|
-
cucumber: cucumber.CONFIG_PATTERN,
|
|
57
|
-
cypress: cypress.CONFIG_PATTERN,
|
|
58
|
-
jest: /^(?:jest|config-jest)\.config\.(?:[cm]?[jt]s|json)$/,
|
|
59
|
-
mocha: /^\.mocharc\.(?:json|ya?ml|[cm]?js)$/,
|
|
60
|
-
playwright: playwright.CONFIG_PATTERN,
|
|
61
|
-
vitest: /^(?:vite\.config|vitest\.(?:config|workspace))\.[cm]?[jt]s$/,
|
|
62
|
-
}
|
|
63
|
-
const JS_CONFIG_EXTENSIONS = ['js', 'cjs', 'mjs', 'ts', 'cts', 'mts']
|
|
64
|
-
const IMPLICIT_CONFIG_FILENAMES = {
|
|
65
|
-
cucumber: ['json', 'yaml', 'yml', ...JS_CONFIG_EXTENSIONS].map(extension => `cucumber.${extension}`),
|
|
66
|
-
cypress: ['json', ...JS_CONFIG_EXTENSIONS].flatMap(extension => [
|
|
67
|
-
`cypress.${extension}`,
|
|
68
|
-
`cypress.config.${extension}`,
|
|
69
|
-
]),
|
|
70
|
-
jest: ['json', ...JS_CONFIG_EXTENSIONS].flatMap(extension => [
|
|
71
|
-
`jest.config.${extension}`,
|
|
72
|
-
`config-jest.config.${extension}`,
|
|
73
|
-
]),
|
|
74
|
-
mocha: ['json', 'yaml', 'yml', ...JS_CONFIG_EXTENSIONS].map(extension => `.mocharc.${extension}`),
|
|
75
|
-
playwright: JS_CONFIG_EXTENSIONS.map(extension => `playwright.config.${extension}`),
|
|
76
|
-
vitest: JS_CONFIG_EXTENSIONS.flatMap(extension => [
|
|
77
|
-
`vite.config.${extension}`,
|
|
78
|
-
`vitest.config.${extension}`,
|
|
79
|
-
`vitest.workspace.${extension}`,
|
|
80
|
-
]),
|
|
81
|
-
}
|
|
82
|
-
const TEST_FILE_PATTERN = /^.+[._-](?:test|spec)\.[cm]?[jt]sx?$/
|
|
83
|
-
const BARE_TEST_FILE_PATTERN = /^test\.[cm]?[jt]sx?$/
|
|
84
|
-
const TYPE_ONLY_TEST_PATTERN = /\.(?:test|spec)-d\.[cm]?tsx?$|\.d\.[cm]?ts$/i
|
|
85
|
-
const TYPE_ONLY_DIRECTORY_PATTERN = /(?:^|\/)(?:type[-_]?tests?|test-dts?)(?:\/|$)/i
|
|
86
|
-
const LOCAL_SOCKET_PATTERN =
|
|
87
|
-
/\bcreateServer\s*\(|\.listen\s*\(|\b(?:localhost|127\.0\.0\.1|supertest)\b|\bcy\.(?:visit|request)\s*\(/
|
|
88
|
-
const IMPORT_SPECIFIER_PATTERN = /(?:from\s+|require\s*\(\s*|import\s*\(\s*)(['"])([^'"]+)\1/g
|
|
89
|
-
const CUCUMBER_BROWSER_SUPPORT_DIRECTORY_PATTERN =
|
|
90
|
-
/(?:^|\/)(?:features?|helpers?|step_definitions|steps?|support)(?:\/|$)/i
|
|
91
|
-
const CUCUMBER_BROWSER_DRIVER_PATTERN =
|
|
92
|
-
/(?:from\s+|(?:import|require)\s*\(\s*)['"](?:@playwright\/test|nightwatch|playwright(?:-core)?|puppeteer(?:-core)?|selenium-webdriver|webdriverio)['"]/
|
|
93
|
-
const CYPRESS_LOCAL_ORIGIN_PATTERN =
|
|
94
|
-
/\bcy\.(?:visit|request)\s*\([\s\S]{0,512}\b(?:https?:\/\/)?(?:localhost|127\.0\.0\.1)(?=[:/'"`\s}])/i
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Creates a schema-valid data-only manifest without executing project code.
|
|
98
|
-
*
|
|
99
|
-
* @param {object} input scaffold inputs
|
|
100
|
-
* @param {string} input.root repository root
|
|
101
|
-
* @param {Set<string>} [input.frameworks] selected framework ids or kinds
|
|
102
|
-
* @returns {object} validation manifest scaffold
|
|
103
|
-
*/
|
|
104
|
-
function createManifestScaffold ({ root, frameworks = new Set() }) {
|
|
105
|
-
const repositoryRoot = fs.realpathSync(path.resolve(root))
|
|
106
|
-
const diagnosis = runDiagnosis({ root: repositoryRoot, env: {} })
|
|
107
|
-
const ciDiscovery = discoverCiFiles(repositoryRoot)
|
|
108
|
-
const eligible = diagnosis.eligibleFrameworks.filter(detection => isSelected(detection.id, frameworks))
|
|
109
|
-
const eligibleKinds = new Set(eligible.map(detection => detection.id))
|
|
110
|
-
const detectedOnly = diagnosis.supportedFrameworks.filter(detection => {
|
|
111
|
-
return !eligibleKinds.has(detection.id) && isSelected(detection.id, frameworks)
|
|
112
|
-
})
|
|
113
|
-
const unsupported = diagnosis.unsupportedFrameworks.filter(detection => isSelected(detection.id, frameworks))
|
|
114
|
-
|
|
115
|
-
if (eligible.length === 0 && detectedOnly.length === 0 && unsupported.length === 0) {
|
|
116
|
-
throw new Error('No test framework was detected for manifest scaffolding.')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const manifest = {
|
|
120
|
-
schemaVersion: '2.0',
|
|
121
|
-
generatedAt: new Date().toISOString(),
|
|
122
|
-
repository: {
|
|
123
|
-
root: repositoryRoot,
|
|
124
|
-
packageManager: detectPackageManager(repositoryRoot),
|
|
125
|
-
workspaceManager: detectWorkspaceManager(repositoryRoot),
|
|
126
|
-
},
|
|
127
|
-
environment: {
|
|
128
|
-
nodeVersion: process.version,
|
|
129
|
-
os: getManifestOs(process.platform),
|
|
130
|
-
},
|
|
131
|
-
ciDiscovery,
|
|
132
|
-
frameworks: [
|
|
133
|
-
...eligible.map(detection => buildFramework(repositoryRoot, detection, ciDiscovery)),
|
|
134
|
-
...detectedOnly.map(detection => {
|
|
135
|
-
return detection.supportedVersion && SUPPORTED_FRAMEWORKS.has(detection.id)
|
|
136
|
-
? buildFramework(repositoryRoot, detection, ciDiscovery)
|
|
137
|
-
: buildDetectedOnlyFramework(repositoryRoot, detection, ciDiscovery)
|
|
138
|
-
}),
|
|
139
|
-
...unsupported.map(detection => buildUnsupportedFramework(repositoryRoot, detection, ciDiscovery)),
|
|
140
|
-
],
|
|
141
|
-
omitted: [],
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const errors = validateManifest(manifest)
|
|
145
|
-
if (errors.length > 0) {
|
|
146
|
-
throw new Error(`Generated manifest scaffold is invalid:\n- ${errors.join('\n- ')}`)
|
|
147
|
-
}
|
|
148
|
-
return manifest
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Builds one runnable direct-runner framework or a precise setup blocker.
|
|
153
|
-
*
|
|
154
|
-
* @param {string} repositoryRoot repository root
|
|
155
|
-
* @param {object} detection eligible framework detection
|
|
156
|
-
* @param {object} ciDiscovery bounded CI discovery result
|
|
157
|
-
* @returns {object} framework manifest entry
|
|
158
|
-
*/
|
|
159
|
-
function buildFramework (repositoryRoot, detection, ciDiscovery) {
|
|
160
|
-
const framework = detection.id
|
|
161
|
-
const packageJson = getFrameworkPackageJson(repositoryRoot, detection)
|
|
162
|
-
if (!packageJson) {
|
|
163
|
-
return buildDetectedOnlyFramework(
|
|
164
|
-
repositoryRoot,
|
|
165
|
-
detection,
|
|
166
|
-
ciDiscovery,
|
|
167
|
-
`The package that owns ${detection.name} could not be identified from the bounded detection evidence.`
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
const projectRoot = path.dirname(packageJson.path)
|
|
171
|
-
const base = getFrameworkBase({
|
|
172
|
-
ciDiscovery,
|
|
173
|
-
detection,
|
|
174
|
-
framework,
|
|
175
|
-
packageJson,
|
|
176
|
-
projectRoot,
|
|
177
|
-
repositoryRoot,
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
if (!SUPPORTED_FRAMEWORKS.has(framework)) {
|
|
181
|
-
return {
|
|
182
|
-
...base,
|
|
183
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
184
|
-
status: 'unsupported_by_validator',
|
|
185
|
-
notes: [`${detection.name} is supported by dd-trace, but this validator has no direct-runner adapter.`],
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (framework === 'cucumber' && !cucumber.supportsConfigIsolation(base.frameworkVersion)) {
|
|
190
|
-
return {
|
|
191
|
-
...base,
|
|
192
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
193
|
-
status: 'requires_manual_setup',
|
|
194
|
-
notes: [
|
|
195
|
-
`${detection.name} ${base.frameworkVersion || 'with an unknown version'} is supported by dd-trace, but its ` +
|
|
196
|
-
'CLI cannot bypass customer profiles with a validator-owned config. Live validation is unavailable because ' +
|
|
197
|
-
'changing the working directory or loading the profile dynamically would weaken isolation. The static CI ' +
|
|
198
|
-
'audit can still run.',
|
|
199
|
-
],
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const projectRunner = getProjectNodeRunner(detection.command, projectRoot, repositoryRoot)
|
|
204
|
-
const runner = projectRunner || resolveRunner(framework, projectRoot, repositoryRoot)
|
|
205
|
-
if (!runner) {
|
|
206
|
-
return {
|
|
207
|
-
...base,
|
|
208
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
209
|
-
status: 'requires_manual_setup',
|
|
210
|
-
notes: [
|
|
211
|
-
`${detection.name} is detected, but its repository-contained executable is unavailable. Install this ` +
|
|
212
|
-
'package normally, then create a fresh validation plan.',
|
|
213
|
-
],
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const projectFiles = collectProjectFiles(projectRoot)
|
|
218
|
-
const commandRoots = getRunnerSearchRoots(framework, detection.command, projectRoot, repositoryRoot)
|
|
219
|
-
let runnerContract = getRunnerContract(framework, detection.command, projectRoot, repositoryRoot)
|
|
220
|
-
if (runnerContract.error) {
|
|
221
|
-
return {
|
|
222
|
-
...base,
|
|
223
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
224
|
-
status: 'requires_manual_setup',
|
|
225
|
-
notes: [
|
|
226
|
-
`${detection.name} runner configuration was not retained because ${runnerContract.error}. ` +
|
|
227
|
-
'Choose a representative test command manually or adjust the project setup, then create a fresh plan.',
|
|
228
|
-
],
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
const implicitConfigFiles = [...new Set([
|
|
232
|
-
...getImplicitConfigFiles(framework, projectRoot, repositoryRoot),
|
|
233
|
-
...(framework === 'vitest' && commandRoots[0]
|
|
234
|
-
? getImplicitConfigFiles(framework, commandRoots[0], repositoryRoot)
|
|
235
|
-
: []),
|
|
236
|
-
])]
|
|
237
|
-
if (framework === 'cucumber') {
|
|
238
|
-
const expanded = cucumber.expandProfiles({
|
|
239
|
-
configFiles: [...new Set([...runnerContract.inputFiles, ...implicitConfigFiles])],
|
|
240
|
-
projectFiles,
|
|
241
|
-
projectRoot,
|
|
242
|
-
runnerArgs: runnerContract.runnerArgs,
|
|
243
|
-
})
|
|
244
|
-
if (expanded.error) {
|
|
245
|
-
return {
|
|
246
|
-
...base,
|
|
247
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
248
|
-
status: 'requires_manual_setup',
|
|
249
|
-
notes: [
|
|
250
|
-
`${detection.name} runner configuration was not retained because ${expanded.error}. ` +
|
|
251
|
-
'Use a literal Cucumber profile or a direct command with bounded support-code options, then create a ' +
|
|
252
|
-
'fresh plan.',
|
|
253
|
-
],
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
const expandedContract = getRunnerConfigurationContract(
|
|
257
|
-
framework,
|
|
258
|
-
expanded.runnerArgs,
|
|
259
|
-
runnerContract.environment,
|
|
260
|
-
projectRoot,
|
|
261
|
-
repositoryRoot
|
|
262
|
-
)
|
|
263
|
-
if (expandedContract.error) {
|
|
264
|
-
return {
|
|
265
|
-
...base,
|
|
266
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
267
|
-
status: 'requires_manual_setup',
|
|
268
|
-
notes: [
|
|
269
|
-
`${detection.name} profile configuration was not retained because ${expandedContract.error}. ` +
|
|
270
|
-
'Use repository-contained support-code inputs, then create a fresh plan.',
|
|
271
|
-
],
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
runnerContract = {
|
|
275
|
-
...expandedContract,
|
|
276
|
-
omittedOptions: runnerContract.omittedOptions,
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
const vitestProject = framework === 'vitest'
|
|
280
|
-
? vitest.bindLiteralProject({
|
|
281
|
-
configFiles: [...new Set([...runnerContract.inputFiles, ...implicitConfigFiles])],
|
|
282
|
-
projectFiles,
|
|
283
|
-
projectRoot,
|
|
284
|
-
runnerArgs: runnerContract.runnerArgs,
|
|
285
|
-
})
|
|
286
|
-
: undefined
|
|
287
|
-
if (vitestProject?.error) {
|
|
288
|
-
return {
|
|
289
|
-
...base,
|
|
290
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
291
|
-
status: 'requires_manual_setup',
|
|
292
|
-
notes: [
|
|
293
|
-
`${detection.name} runner configuration was not retained because ${vitestProject.error}. ` +
|
|
294
|
-
'Use one literal, uniquely named Vitest project with static configuration, then create a fresh plan.',
|
|
295
|
-
],
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const representativeRoot = vitestProject?.root ||
|
|
299
|
-
commandRoots[0] ||
|
|
300
|
-
findPreferredRepresentativeRoot(projectRoot, repositoryRoot)
|
|
301
|
-
const representativePackage = readJson(path.join(representativeRoot, 'package.json')) || packageJson.json
|
|
302
|
-
const candidateFiles = vitestProject?.files ||
|
|
303
|
-
(representativeRoot === projectRoot ? projectFiles : collectProjectFiles(representativeRoot))
|
|
304
|
-
const candidates = selectRepresentativeTests(
|
|
305
|
-
candidateFiles,
|
|
306
|
-
framework,
|
|
307
|
-
representativeRoot,
|
|
308
|
-
representativePackage.name,
|
|
309
|
-
commandRoots.length > 0 || vitestProject !== undefined
|
|
310
|
-
)
|
|
311
|
-
const candidate = candidates[0]
|
|
312
|
-
if (!candidate) {
|
|
313
|
-
return {
|
|
314
|
-
...base,
|
|
315
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
316
|
-
status: 'requires_manual_setup',
|
|
317
|
-
notes: [
|
|
318
|
-
`No single ${detection.name} test file could be selected confidently. Choose a normal framework-owned ` +
|
|
319
|
-
'test file or validate this framework manually.',
|
|
320
|
-
],
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
if (candidate.requiresExternalService) {
|
|
324
|
-
return {
|
|
325
|
-
...base,
|
|
326
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
327
|
-
status: 'requires_manual_setup',
|
|
328
|
-
notes: [
|
|
329
|
-
`No self-contained ${detection.name} spec could be selected. The available spec accesses a localhost ` +
|
|
330
|
-
'application that discovery will not start. Start the application through the project\'s normal setup and ' +
|
|
331
|
-
'validate Cypress manually, or add a self-contained spec before creating a fresh plan.',
|
|
332
|
-
],
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const plannedGeneratedTestStrategy = buildGeneratedTestStrategy({
|
|
337
|
-
framework,
|
|
338
|
-
projectRoot: vitestProject?.root || projectRoot,
|
|
339
|
-
representative: candidate.path,
|
|
340
|
-
})
|
|
341
|
-
const generatedTestStrategy = vitestProject &&
|
|
342
|
-
!vitest.supportsGeneratedFiles(vitestProject, plannedGeneratedTestStrategy)
|
|
343
|
-
? {
|
|
344
|
-
reason: 'The selected Vitest project include or exclude patterns do not collect ' +
|
|
345
|
-
'validator-generated test files.',
|
|
346
|
-
status: 'not_possible',
|
|
347
|
-
}
|
|
348
|
-
: plannedGeneratedTestStrategy
|
|
349
|
-
const configFiles = [...new Set([
|
|
350
|
-
...runnerContract.inputFiles,
|
|
351
|
-
...(vitestProject?.configFile ? [vitestProject.configFile] : []),
|
|
352
|
-
...implicitConfigFiles,
|
|
353
|
-
...(representativeRoot === projectRoot
|
|
354
|
-
? []
|
|
355
|
-
: getImplicitConfigFiles(framework, representativeRoot, repositoryRoot)),
|
|
356
|
-
...projectFiles.filter(filename => CONFIG_PATTERNS[framework]?.test(path.basename(filename))).slice(0, 5),
|
|
357
|
-
])]
|
|
358
|
-
if (configFiles.length > 20) {
|
|
359
|
-
return {
|
|
360
|
-
...base,
|
|
361
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
362
|
-
status: 'requires_manual_setup',
|
|
363
|
-
notes: [
|
|
364
|
-
`${detection.name} loads more configuration files than the validator can approval-bind safely. ` +
|
|
365
|
-
'Use a narrower project setup before creating a fresh plan.',
|
|
366
|
-
],
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
const runnerDescription = projectRunner ? 'repository test wrapper' : `installed ${framework} runner`
|
|
370
|
-
const runnerConfigurationNote = detection.command
|
|
371
|
-
? 'The validator retained only allowlisted runner configuration from the detected package script.'
|
|
372
|
-
: 'The validator uses the installed runner with repository-contained configuration files; the unresolved ' +
|
|
373
|
-
'package wrapper is not executed.'
|
|
374
|
-
const cucumberBrowserRequired = framework === 'cucumber' &&
|
|
375
|
-
hasCucumberBrowserSupport(candidateFiles, runnerContract.inputFiles, representativeRoot)
|
|
376
|
-
const browserRequired = framework === 'cypress' ||
|
|
377
|
-
framework === 'playwright' ||
|
|
378
|
-
cucumberBrowserRequired ||
|
|
379
|
-
(framework === 'vitest' && runnerContract.runnerArgs.includes('--browser'))
|
|
380
|
-
const fallbackCandidates = candidates
|
|
381
|
-
.slice(1)
|
|
382
|
-
.filter(candidate => hasGeneratedTestContract(
|
|
383
|
-
candidate.path,
|
|
384
|
-
framework,
|
|
385
|
-
vitestProject?.root || projectRoot,
|
|
386
|
-
plannedGeneratedTestStrategy
|
|
387
|
-
))
|
|
388
|
-
const fallbackTests = fallbackCandidates
|
|
389
|
-
.map(candidate => ({
|
|
390
|
-
buildArtifactRequired: candidate.requiresBuildArtifact,
|
|
391
|
-
localSocketRequired: candidate.requiresLocalSocket,
|
|
392
|
-
testFile: candidate.path,
|
|
393
|
-
}))
|
|
394
|
-
const allCandidatesRequireLocalSocket =
|
|
395
|
-
[candidate, ...fallbackCandidates].every(candidate => candidate.requiresLocalSocket)
|
|
396
|
-
|
|
397
|
-
return {
|
|
398
|
-
...base,
|
|
399
|
-
allCandidatesRequireLocalSocket,
|
|
400
|
-
browserRequired,
|
|
401
|
-
buildArtifactRequired: candidate.requiresBuildArtifact,
|
|
402
|
-
language: /\.[cm]?tsx?$/.test(candidate.path) ? 'typescript' : 'javascript',
|
|
403
|
-
localSocketRequired: candidate.requiresLocalSocket,
|
|
404
|
-
status: 'runnable',
|
|
405
|
-
supportLevel: 'validator_direct_runner',
|
|
406
|
-
project: {
|
|
407
|
-
...base.project,
|
|
408
|
-
configFiles,
|
|
409
|
-
},
|
|
410
|
-
validation: {
|
|
411
|
-
environment: runnerContract.environment,
|
|
412
|
-
...(runnerContract.omittedOptions?.length > 0
|
|
413
|
-
? { omittedRunnerOptions: runnerContract.omittedOptions }
|
|
414
|
-
: {}),
|
|
415
|
-
requiredEnvVars: [],
|
|
416
|
-
runner,
|
|
417
|
-
runnerArgs: runnerContract.runnerArgs,
|
|
418
|
-
selectorScope: projectRunner ? 'instrumented_event_identity' : 'bounded_direct_runner',
|
|
419
|
-
testFile: candidate.path,
|
|
420
|
-
...(fallbackTests.length > 0 ? { fallbackTests } : {}),
|
|
421
|
-
timeoutMs: browserRequired ? 300_000 : 180_000,
|
|
422
|
-
},
|
|
423
|
-
preflight: { status: 'pending' },
|
|
424
|
-
generatedTestStrategy,
|
|
425
|
-
notes: [
|
|
426
|
-
`Basic Reporting will invoke the ${runnerDescription} ` +
|
|
427
|
-
'directly for ' +
|
|
428
|
-
`${path.relative(repositoryRoot, candidate.path)}.`,
|
|
429
|
-
runnerConfigurationNote,
|
|
430
|
-
...(projectRunner
|
|
431
|
-
? [
|
|
432
|
-
'Basic Reporting will remain incomplete unless captured test events identify only the approved ' +
|
|
433
|
-
'representative file.',
|
|
434
|
-
]
|
|
435
|
-
: []),
|
|
436
|
-
...(candidate.requiresLocalSocket
|
|
437
|
-
? [
|
|
438
|
-
`${allCandidatesRequireLocalSocket ? 'Every approved candidate appears' : 'The selected test appears'} ` +
|
|
439
|
-
'to require localhost. A restricted execution environment may leave local validation incomplete.',
|
|
440
|
-
]
|
|
441
|
-
: []),
|
|
442
|
-
...(candidate.requiresBuildArtifact
|
|
443
|
-
? [
|
|
444
|
-
'The selected test appears to load a build or dist artifact. Complete the project\'s normal build before ' +
|
|
445
|
-
'validation if that artifact is not already present.',
|
|
446
|
-
]
|
|
447
|
-
: []),
|
|
448
|
-
...(cucumberBrowserRequired
|
|
449
|
-
? [
|
|
450
|
-
'The selected Cucumber support code imports a browser driver. The approved validation command may launch ' +
|
|
451
|
-
'the project browser.',
|
|
452
|
-
]
|
|
453
|
-
: []),
|
|
454
|
-
],
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
function getImplicitConfigFiles (framework, projectRoot, repositoryRoot) {
|
|
459
|
-
const files = []
|
|
460
|
-
if (IMPLICIT_CONFIG_FILENAMES[framework]) {
|
|
461
|
-
for (const basename of IMPLICIT_CONFIG_FILENAMES[framework]) {
|
|
462
|
-
const filename = path.join(projectRoot, basename)
|
|
463
|
-
try {
|
|
464
|
-
const stat = fs.lstatSync(filename)
|
|
465
|
-
const physical = fs.realpathSync(filename)
|
|
466
|
-
if (stat.isFile() && !stat.isSymbolicLink() &&
|
|
467
|
-
fs.statSync(physical).isFile() &&
|
|
468
|
-
isPathInside(fs.realpathSync(repositoryRoot), physical)) files.push(physical)
|
|
469
|
-
} catch {}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
return files
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Builds a diagnostic-only supported framework entry.
|
|
477
|
-
*
|
|
478
|
-
* @param {string} repositoryRoot repository root
|
|
479
|
-
* @param {object} detection supported framework detection
|
|
480
|
-
* @param {object} ciDiscovery bounded CI discovery result
|
|
481
|
-
* @param {string} [blockerNote] precise reason live validation is unavailable
|
|
482
|
-
* @returns {object} framework manifest entry
|
|
483
|
-
*/
|
|
484
|
-
function buildDetectedOnlyFramework (repositoryRoot, detection, ciDiscovery, blockerNote) {
|
|
485
|
-
const packageJson = getDetectionPackageJson(repositoryRoot, getDetectionPackageLocation(detection))
|
|
486
|
-
const projectRoot = path.dirname(packageJson.path)
|
|
487
|
-
const version = detection.supportedVersion?.version ||
|
|
488
|
-
detection.versionDetections?.[0]?.version ||
|
|
489
|
-
detection.versionDetections?.[0]?.rawVersion
|
|
490
|
-
const unsupportedVersion = !detection.supportedVersion &&
|
|
491
|
-
(detection.versionDetections?.[0]?.version || detection.versionDetections?.[0]?.rawVersion)
|
|
492
|
-
return {
|
|
493
|
-
...getFrameworkBase({
|
|
494
|
-
ciDiscovery,
|
|
495
|
-
detection: { ...detection, version },
|
|
496
|
-
framework: detection.id,
|
|
497
|
-
packageJson,
|
|
498
|
-
projectRoot,
|
|
499
|
-
repositoryRoot,
|
|
500
|
-
}),
|
|
501
|
-
blockerCategory: unsupportedVersion
|
|
502
|
-
? BLOCKER_CATEGORIES.UNSUPPORTED_VERSION
|
|
503
|
-
: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
504
|
-
status: 'detected_not_runnable',
|
|
505
|
-
notes: [
|
|
506
|
-
blockerNote || (unsupportedVersion
|
|
507
|
-
? `${detection.name} ${unsupportedVersion} was detected, but live validation requires ` +
|
|
508
|
-
`${detection.supportedRange}. Upgrade ${detection.name} through the project's normal dependency workflow ` +
|
|
509
|
-
'before creating a fresh validation plan.'
|
|
510
|
-
: detection.supportedVersion
|
|
511
|
-
? `A supported ${detection.name} installation was detected, but no project-local validation target was found.`
|
|
512
|
-
: `${detection.name} was detected, but no supported installed version was confirmed.`),
|
|
513
|
-
],
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Builds an unsupported framework entry.
|
|
519
|
-
*
|
|
520
|
-
* @param {string} repositoryRoot repository root
|
|
521
|
-
* @param {object} detection unsupported framework detection
|
|
522
|
-
* @param {object} ciDiscovery bounded CI discovery result
|
|
523
|
-
* @returns {object} framework manifest entry
|
|
524
|
-
*/
|
|
525
|
-
function buildUnsupportedFramework (repositoryRoot, detection, ciDiscovery) {
|
|
526
|
-
const packageJson = getDetectionPackageJson(repositoryRoot, detection.locations?.[0])
|
|
527
|
-
const projectRoot = path.dirname(packageJson.path)
|
|
528
|
-
const framework = detection.id === 'node-test' ? 'node:test' : detection.id
|
|
529
|
-
return {
|
|
530
|
-
...getFrameworkBase({
|
|
531
|
-
ciDiscovery,
|
|
532
|
-
detection,
|
|
533
|
-
framework,
|
|
534
|
-
packageJson,
|
|
535
|
-
projectRoot,
|
|
536
|
-
repositoryRoot,
|
|
537
|
-
}),
|
|
538
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
539
|
-
status: 'unsupported_by_validator',
|
|
540
|
-
notes: [`${detection.name} is not supported by this Test Optimization validator.`],
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Returns fields shared by runnable and diagnostic framework entries.
|
|
546
|
-
*
|
|
547
|
-
* @param {object} input framework inputs
|
|
548
|
-
* @param {object} input.ciDiscovery bounded CI discovery
|
|
549
|
-
* @param {object} input.detection framework detection
|
|
550
|
-
* @param {string} input.framework framework name
|
|
551
|
-
* @param {object} input.packageJson package metadata
|
|
552
|
-
* @param {string} input.projectRoot project root
|
|
553
|
-
* @param {string} input.repositoryRoot repository root
|
|
554
|
-
* @returns {object} shared framework fields
|
|
555
|
-
*/
|
|
556
|
-
function getFrameworkBase ({
|
|
557
|
-
ciDiscovery,
|
|
558
|
-
detection,
|
|
559
|
-
framework,
|
|
560
|
-
packageJson,
|
|
561
|
-
projectRoot,
|
|
562
|
-
repositoryRoot,
|
|
563
|
-
}) {
|
|
564
|
-
return {
|
|
565
|
-
id: `${framework}:${getProjectId(packageJson.json, projectRoot, repositoryRoot)}`,
|
|
566
|
-
framework,
|
|
567
|
-
frameworkVersion: detection.version || detection.supportedVersion?.version || null,
|
|
568
|
-
language: 'unknown',
|
|
569
|
-
supportLevel: 'detected_only',
|
|
570
|
-
project: {
|
|
571
|
-
configFiles: [],
|
|
572
|
-
name: packageJson.json.name || path.basename(projectRoot) || 'root',
|
|
573
|
-
packageJson: packageJson.path,
|
|
574
|
-
root: projectRoot,
|
|
575
|
-
},
|
|
576
|
-
ciWiring: buildCiWiring(ciDiscovery),
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Builds inert CI review fields. The agent may populate only this evidence section.
|
|
582
|
-
*
|
|
583
|
-
* @param {object} ciDiscovery bounded CI discovery result
|
|
584
|
-
* @returns {object} CI evidence scaffold
|
|
585
|
-
*/
|
|
586
|
-
function buildCiWiring (ciDiscovery) {
|
|
587
|
-
const unresolved = ciDiscovery.reviewRequired
|
|
588
|
-
? ['The exact CI test job and its effective environment have not been reviewed.']
|
|
589
|
-
: ['No supported CI configuration file was found by bounded discovery.']
|
|
590
|
-
return {
|
|
591
|
-
command: null,
|
|
592
|
-
configFile: null,
|
|
593
|
-
initialization: { evidence: [], status: 'unknown' },
|
|
594
|
-
job: null,
|
|
595
|
-
reviewComplete: false,
|
|
596
|
-
step: null,
|
|
597
|
-
transport: { evidence: [], mode: 'unknown' },
|
|
598
|
-
unresolved,
|
|
599
|
-
workingDirectory: null,
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Builds canonical generated test data without embedding executable commands.
|
|
605
|
-
*
|
|
606
|
-
* @param {object} input generated-test inputs
|
|
607
|
-
* @param {string} input.framework framework name
|
|
608
|
-
* @param {string} input.projectRoot project root
|
|
609
|
-
* @param {string} input.representative representative test file
|
|
610
|
-
* @returns {object} generated test strategy
|
|
611
|
-
*/
|
|
612
|
-
function buildGeneratedTestStrategy ({ framework, projectRoot, representative }) {
|
|
613
|
-
const convention = getGeneratedTestConvention(framework, representative, projectRoot)
|
|
614
|
-
const testDirectory = convention.testDirectory
|
|
615
|
-
const extension = convention.fileExtension
|
|
616
|
-
const moduleSystem = getModuleSystem(representative, projectRoot)
|
|
617
|
-
const files = []
|
|
618
|
-
const scenarios = []
|
|
619
|
-
const cleanupPaths = []
|
|
620
|
-
|
|
621
|
-
for (const [id, scenario] of Object.entries(GENERATED_SCENARIOS)) {
|
|
622
|
-
const prefix = `dd-test-optimization-validation-${framework}-${id}`
|
|
623
|
-
const filename = convention.exactFilename
|
|
624
|
-
? path.join(testDirectory, prefix, convention.exactFilename)
|
|
625
|
-
: path.join(testDirectory, `${prefix}${extension}`)
|
|
626
|
-
const content = getGeneratedTestContent({
|
|
627
|
-
framework,
|
|
628
|
-
moduleSystem,
|
|
629
|
-
scenarioId: id,
|
|
630
|
-
stateFile: ['cucumber', 'cypress', 'playwright'].includes(framework)
|
|
631
|
-
? undefined
|
|
632
|
-
: getGeneratedRetryStatePath(framework, filename),
|
|
633
|
-
})
|
|
634
|
-
files.push({ path: filename, contentLines: content.split('\n') })
|
|
635
|
-
cleanupPaths.push(filename)
|
|
636
|
-
scenarios.push({
|
|
637
|
-
id,
|
|
638
|
-
expectedWithoutDatadog: scenario.expectedWithoutDatadog,
|
|
639
|
-
testIdentities: [{
|
|
640
|
-
file: filename,
|
|
641
|
-
name: scenario.testName,
|
|
642
|
-
suite: scenario.suiteName,
|
|
643
|
-
}],
|
|
644
|
-
})
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if (framework === 'cucumber') {
|
|
648
|
-
const stepsFile = cucumber.getGeneratedStepsPath(testDirectory)
|
|
649
|
-
files.push({ path: stepsFile, contentLines: cucumber.getGeneratedStepsContent().split('\n') })
|
|
650
|
-
cleanupPaths.push(stepsFile)
|
|
651
|
-
} else if (framework === 'playwright') {
|
|
652
|
-
const configFile = playwright.getGeneratedConfigPath(testDirectory)
|
|
653
|
-
files.push({ path: configFile, contentLines: playwright.getGeneratedConfigContent().split('\n') })
|
|
654
|
-
cleanupPaths.push(configFile)
|
|
655
|
-
}
|
|
656
|
-
if (['jest', 'mocha', 'vitest'].includes(framework)) {
|
|
657
|
-
cleanupPaths.push(getGeneratedRetryStatePath(framework, scenarios[1].testIdentities[0].file))
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
return {
|
|
661
|
-
cleanupPaths,
|
|
662
|
-
fileExtension: extension,
|
|
663
|
-
files,
|
|
664
|
-
moduleSystem,
|
|
665
|
-
reason: 'Validator-owned direct-runner recipes.',
|
|
666
|
-
scenarios,
|
|
667
|
-
status: 'planned',
|
|
668
|
-
testDirectory,
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function hasGeneratedTestContract (representative, framework, projectRoot, strategy) {
|
|
673
|
-
const convention = getGeneratedTestConvention(framework, representative, projectRoot)
|
|
674
|
-
return convention.fileExtension === strategy.fileExtension &&
|
|
675
|
-
convention.testDirectory === strategy.testDirectory &&
|
|
676
|
-
getModuleSystem(representative, projectRoot) === strategy.moduleSystem
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Selects up to three representative framework-owned test files.
|
|
681
|
-
*
|
|
682
|
-
* @param {string[]} files bounded project files
|
|
683
|
-
* @param {string} framework framework name
|
|
684
|
-
* @param {string} projectRoot project root
|
|
685
|
-
* @param {string} packageName project package name
|
|
686
|
-
* @param {boolean} allowDirectoryConvention whether a literal runner selector owns this root
|
|
687
|
-
* @returns {Array<{
|
|
688
|
-
* path: string,
|
|
689
|
-
* requiresBuildArtifact: boolean,
|
|
690
|
-
* requiresExternalService: boolean,
|
|
691
|
-
* requiresLocalSocket: boolean
|
|
692
|
-
* }>} selected tests
|
|
693
|
-
*/
|
|
694
|
-
function selectRepresentativeTests (files, framework, projectRoot, packageName, allowDirectoryConvention) {
|
|
695
|
-
const candidates = []
|
|
696
|
-
for (const filename of files) {
|
|
697
|
-
const source = readText(filename)
|
|
698
|
-
if (source === undefined ||
|
|
699
|
-
!isTestFile(filename, source, framework, projectRoot, allowDirectoryConvention) ||
|
|
700
|
-
hasConflictingFramework(source, framework)) continue
|
|
701
|
-
if (framework === 'cucumber'
|
|
702
|
-
? cucumber.getScenarioCount(source) === 0
|
|
703
|
-
: getStaticTestCount(source) === 0) continue
|
|
704
|
-
if (!hasFrameworkOwnership(filename, source, framework, packageName)) continue
|
|
705
|
-
candidates.push({
|
|
706
|
-
explicitFilename: TEST_FILE_PATTERN.test(path.basename(filename)),
|
|
707
|
-
path: filename,
|
|
708
|
-
rank: getTestRank(filename, source, projectRoot),
|
|
709
|
-
requiresBuildArtifact: requiresProjectBuildArtifact(source, projectRoot, path.dirname(filename)),
|
|
710
|
-
requiresExternalService: framework === 'cypress' && CYPRESS_LOCAL_ORIGIN_PATTERN.test(source),
|
|
711
|
-
requiresLocalSocket: LOCAL_SOCKET_PATTERN.test(source),
|
|
712
|
-
})
|
|
713
|
-
}
|
|
714
|
-
candidates.sort((left, right) => {
|
|
715
|
-
return Number(left.requiresExternalService) - Number(right.requiresExternalService) ||
|
|
716
|
-
Number(right.explicitFilename) - Number(left.explicitFilename) ||
|
|
717
|
-
left.rank - right.rank ||
|
|
718
|
-
left.path.localeCompare(right.path)
|
|
719
|
-
})
|
|
720
|
-
return candidates.slice(0, 3)
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
function requiresProjectBuildArtifact (source, projectRoot, sourceDirectory) {
|
|
724
|
-
for (const match of source.matchAll(IMPORT_SPECIFIER_PATTERN)) {
|
|
725
|
-
if (isProjectBuildArtifactPath(match[2], projectRoot, sourceDirectory)) return true
|
|
726
|
-
}
|
|
727
|
-
return false
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
function hasCucumberBrowserSupport (files, retainedInputs, projectRoot) {
|
|
731
|
-
const retained = new Set(retainedInputs)
|
|
732
|
-
for (const filename of new Set([...files, ...retained])) {
|
|
733
|
-
const relative = path.relative(projectRoot, filename).replaceAll('\\', '/')
|
|
734
|
-
if (!retained.has(filename) && !CUCUMBER_BROWSER_SUPPORT_DIRECTORY_PATTERN.test(relative)) continue
|
|
735
|
-
const source = readText(filename)
|
|
736
|
-
if (source !== undefined && CUCUMBER_BROWSER_DRIVER_PATTERN.test(source)) return true
|
|
737
|
-
}
|
|
738
|
-
return false
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
* Reports whether a file follows a selected framework's test convention.
|
|
743
|
-
*
|
|
744
|
-
* @param {string} filename candidate file
|
|
745
|
-
* @param {string} source candidate source
|
|
746
|
-
* @param {string} framework framework name
|
|
747
|
-
* @param {string} projectRoot project root
|
|
748
|
-
* @param {boolean} allowDirectoryConvention whether a literal runner selector owns this root
|
|
749
|
-
*/
|
|
750
|
-
function isTestFile (filename, source, framework, projectRoot, allowDirectoryConvention) {
|
|
751
|
-
const basename = path.basename(filename)
|
|
752
|
-
const normalized = filename.replaceAll('\\', '/')
|
|
753
|
-
if (
|
|
754
|
-
normalized.includes('/dd-test-optimization-validation-') ||
|
|
755
|
-
TYPE_ONLY_TEST_PATTERN.test(basename) ||
|
|
756
|
-
TYPE_ONLY_DIRECTORY_PATTERN.test(normalized)
|
|
757
|
-
) {
|
|
758
|
-
return false
|
|
759
|
-
}
|
|
760
|
-
if (framework === 'cucumber') return cucumber.isTestFile(filename)
|
|
761
|
-
if (framework === 'cypress') return cypress.isTestFile(basename, path.dirname(filename), projectRoot)
|
|
762
|
-
if (framework === 'playwright') return playwright.isTestFile(basename, path.dirname(filename), projectRoot)
|
|
763
|
-
if (TEST_FILE_PATTERN.test(basename)) return true
|
|
764
|
-
const directories = [
|
|
765
|
-
path.basename(projectRoot),
|
|
766
|
-
...path.relative(projectRoot, path.dirname(filename)).split(path.sep),
|
|
767
|
-
]
|
|
768
|
-
const inTestDirectory = directories.some(directory => {
|
|
769
|
-
return ['__tests__', 'spec', 'test', 'tests'].includes(directory)
|
|
770
|
-
})
|
|
771
|
-
if (BARE_TEST_FILE_PATTERN.test(basename)) {
|
|
772
|
-
return (allowDirectoryConvention && inTestDirectory) || hasExplicitFrameworkImport(source, framework)
|
|
773
|
-
}
|
|
774
|
-
return allowDirectoryConvention && inTestDirectory && /\.[cm]?[jt]sx?$/.test(basename)
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* Reports whether an unconventional test file imports the selected framework directly.
|
|
779
|
-
*
|
|
780
|
-
* @param {string} source candidate source
|
|
781
|
-
* @param {string} framework framework name
|
|
782
|
-
*/
|
|
783
|
-
function hasExplicitFrameworkImport (source, framework) {
|
|
784
|
-
if (framework === 'vitest') {
|
|
785
|
-
return /(?:from\s+|require\s*\(\s*)['"]vitest['"]/.test(source)
|
|
786
|
-
}
|
|
787
|
-
if (framework === 'jest') {
|
|
788
|
-
return /(?:from\s+|require\s*\(\s*)['"]@jest\/globals['"]/.test(source)
|
|
789
|
-
}
|
|
790
|
-
if (framework === 'mocha') {
|
|
791
|
-
return /(?:from\s+|require\s*\(\s*)['"]mocha['"]/.test(source)
|
|
792
|
-
}
|
|
793
|
-
return false
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Conservatively associates a test source with one framework.
|
|
798
|
-
*
|
|
799
|
-
* @param {string} filename candidate filename
|
|
800
|
-
* @param {string} source file source
|
|
801
|
-
* @param {string} framework framework name
|
|
802
|
-
* @param {string} packageName project package name
|
|
803
|
-
*/
|
|
804
|
-
function hasFrameworkOwnership (filename, source, framework, packageName) {
|
|
805
|
-
const normalized = filename.replaceAll('\\', '/').toLowerCase()
|
|
806
|
-
if (framework === 'cucumber') return /^[ \t]*(?:Feature|Rule):/m.test(source)
|
|
807
|
-
if (framework === 'cypress') return /\.cy\./.test(filename) || normalized.includes('/cypress/')
|
|
808
|
-
if (framework === 'playwright') {
|
|
809
|
-
return /@playwright\/test/.test(source) || normalized.includes('/playwright/') ||
|
|
810
|
-
normalized.includes('/e2e/')
|
|
811
|
-
}
|
|
812
|
-
if (framework === 'vitest') return /\bvitest\b/.test(source) || getStaticTestCount(source) > 0
|
|
813
|
-
if (framework === 'jest') return /\bjest\b/.test(source) || getStaticTestCount(source) > 0
|
|
814
|
-
if (framework === 'mocha') {
|
|
815
|
-
return /\bmocha\b/.test(source) || /\bdescribe\s*\(/.test(source) ||
|
|
816
|
-
packageName === 'mocha'
|
|
817
|
-
}
|
|
818
|
-
return false
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
/**
|
|
822
|
-
* Rejects files visibly owned by another supported runner.
|
|
823
|
-
*
|
|
824
|
-
* @param {string} source candidate source
|
|
825
|
-
* @param {string} framework selected framework
|
|
826
|
-
*/
|
|
827
|
-
function hasConflictingFramework (source, framework) {
|
|
828
|
-
const markers = {
|
|
829
|
-
cypress: /\bcy\.(?:visit|request|get)\b|from\s+['"]cypress/,
|
|
830
|
-
jest: /@jest\/globals|\bjest\.(?:mock|fn|spyOn)\b/,
|
|
831
|
-
'node:test': /(?:from\s+|require\s*\(\s*)['"]node:test['"]/,
|
|
832
|
-
playwright: /@playwright\/test/,
|
|
833
|
-
vitest: /from\s+['"]vitest['"]|require\s*\(\s*['"]vitest['"]\s*\)|\bvi\./,
|
|
834
|
-
}
|
|
835
|
-
return Object.entries(markers).some(([name, pattern]) => name !== framework && pattern.test(source))
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
/**
|
|
839
|
-
* Ranks simpler unit tests ahead of integration and service-dependent tests.
|
|
840
|
-
*
|
|
841
|
-
* @param {string} filename candidate filename
|
|
842
|
-
* @param {string} source candidate source
|
|
843
|
-
* @param {string} projectRoot project root
|
|
844
|
-
*/
|
|
845
|
-
function getTestRank (filename, source, projectRoot) {
|
|
846
|
-
const relative = path.relative(projectRoot, filename).replaceAll('\\', '/').toLowerCase()
|
|
847
|
-
let rank = relative.split('/').length
|
|
848
|
-
if (/(?:^|\/)(?:test|tests|__tests__|spec)\//.test(relative)) rank -= 20
|
|
849
|
-
if (/(?:^|[._/-])unit(?:[._/-]|$)/.test(relative)) rank -= 15
|
|
850
|
-
if (/e2e|integration|acceptance|browser|conformance|fixtures?/.test(relative)) rank += 20
|
|
851
|
-
if (LOCAL_SOCKET_PATTERN.test(source)) rank += 30
|
|
852
|
-
rank += Math.min(getStaticTestCount(source), 50)
|
|
853
|
-
return rank
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* Counts static test declarations for preferring small representative files.
|
|
858
|
-
*
|
|
859
|
-
* @param {string} source test source
|
|
860
|
-
*/
|
|
861
|
-
function getStaticTestCount (source) {
|
|
862
|
-
const direct = [...source.matchAll(/\b(?:it|test)((?:\.[A-Za-z]+)*)\s*\(\s*(['"`])/g)]
|
|
863
|
-
.filter(match => !/\.(?:skip|todo)\b/.test(match[1]))
|
|
864
|
-
const parameterized = [...source.matchAll(
|
|
865
|
-
/\b(?:it|test)((?:\.[A-Za-z]+)*)\.each\s*(?:\([^()]*\)|`(?:\\[\s\S]|[^\\`])*`)((?:\.[A-Za-z]+)*)\s*\(\s*(['"`])/g
|
|
866
|
-
)].filter(match => !/\.(?:skip|todo)\b/.test(`${match[1]}${match[2]}`))
|
|
867
|
-
return direct.length + parameterized.length
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
/**
|
|
871
|
-
* Narrows a repository root to the conventional package matching its identity.
|
|
872
|
-
*
|
|
873
|
-
* @param {string} projectRoot detected project root
|
|
874
|
-
* @param {string} repositoryRoot repository root
|
|
875
|
-
*/
|
|
876
|
-
function findPreferredRepresentativeRoot (projectRoot, repositoryRoot) {
|
|
877
|
-
if (path.resolve(projectRoot) !== path.resolve(repositoryRoot)) return projectRoot
|
|
878
|
-
const repositoryName = normalizeProjectIdentity(path.basename(repositoryRoot))
|
|
879
|
-
|
|
880
|
-
for (const containerName of ['packages', 'pkgs', 'modules']) {
|
|
881
|
-
const container = path.join(repositoryRoot, containerName)
|
|
882
|
-
for (const entry of readDirectoryEntries(container)) {
|
|
883
|
-
if (!entry.isDirectory()) continue
|
|
884
|
-
const candidate = path.join(container, entry.name)
|
|
885
|
-
const packageJson = readJson(path.join(candidate, 'package.json'))
|
|
886
|
-
if (normalizeProjectIdentity(packageJson?.name || entry.name) === repositoryName) return candidate
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
return projectRoot
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* Normalizes repository and package names for exact identity comparison.
|
|
894
|
-
*
|
|
895
|
-
* @param {string} value package identity
|
|
896
|
-
*/
|
|
897
|
-
function normalizeProjectIdentity (value) {
|
|
898
|
-
const unscoped = String(value || '').toLowerCase().replace(/^@[^/]+\//, '')
|
|
899
|
-
return unscoped.replaceAll(/[^a-z0-9]+/g, '').replace(/js$/, '')
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
/**
|
|
903
|
-
* Collects bounded regular project files without following symbolic links.
|
|
904
|
-
*
|
|
905
|
-
* @param {string} root project root
|
|
906
|
-
* @returns {string[]} absolute files
|
|
907
|
-
*/
|
|
908
|
-
function collectProjectFiles (root) {
|
|
909
|
-
const files = []
|
|
910
|
-
const pending = [root]
|
|
911
|
-
let visited = 0
|
|
912
|
-
|
|
913
|
-
while (pending.length > 0 && visited < MAX_DISCOVERY_ENTRIES) {
|
|
914
|
-
const directory = pending.shift()
|
|
915
|
-
for (const entry of readDirectoryEntries(directory)) {
|
|
916
|
-
if (++visited > MAX_DISCOVERY_ENTRIES) break
|
|
917
|
-
const filename = path.join(directory, entry.name)
|
|
918
|
-
if (entry.isSymbolicLink()) continue
|
|
919
|
-
if (entry.isDirectory()) {
|
|
920
|
-
if (!SKIPPED_DIRECTORIES.has(entry.name)) pending.push(filename)
|
|
921
|
-
} else if (entry.isFile()) {
|
|
922
|
-
files.push(filename)
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
return files
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
/**
|
|
930
|
-
* Resolves a framework package executable only inside the repository.
|
|
931
|
-
*
|
|
932
|
-
* @param {string} framework framework name
|
|
933
|
-
* @param {string} projectRoot project root
|
|
934
|
-
* @param {string} repositoryRoot repository root
|
|
935
|
-
* @returns {string|undefined} physical runner path
|
|
936
|
-
*/
|
|
937
|
-
function resolveRunner (framework, projectRoot, repositoryRoot) {
|
|
938
|
-
const packageName = getRunnerPackageName(framework)
|
|
939
|
-
const packageRoot = findPackageRoot(packageName, projectRoot, repositoryRoot)
|
|
940
|
-
if (!packageRoot) return
|
|
941
|
-
|
|
942
|
-
const packageJson = readJson(path.join(packageRoot, 'package.json'))
|
|
943
|
-
const binName = framework === 'cucumber' ? 'cucumber-js' : framework === 'playwright' ? 'playwright' : framework
|
|
944
|
-
const bin = typeof packageJson?.bin === 'string' ? packageJson.bin : packageJson?.bin?.[binName]
|
|
945
|
-
if (typeof bin !== 'string') return
|
|
946
|
-
|
|
947
|
-
try {
|
|
948
|
-
const runner = fs.realpathSync(path.resolve(packageRoot, bin))
|
|
949
|
-
return isPathInside(fs.realpathSync(repositoryRoot), runner) && fs.statSync(runner).isFile()
|
|
950
|
-
? runner
|
|
951
|
-
: undefined
|
|
952
|
-
} catch {}
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
/**
|
|
956
|
-
* Finds an installed package or a framework source checkout.
|
|
957
|
-
*
|
|
958
|
-
* @param {string} packageName runner package name
|
|
959
|
-
* @param {string} projectRoot project root
|
|
960
|
-
* @param {string} repositoryRoot repository root
|
|
961
|
-
* @returns {string|undefined} physical package root
|
|
962
|
-
*/
|
|
963
|
-
function findPackageRoot (packageName, projectRoot, repositoryRoot) {
|
|
964
|
-
const ownPackage = readJson(path.join(projectRoot, 'package.json'))
|
|
965
|
-
if (ownPackage?.name === packageName) return projectRoot
|
|
966
|
-
|
|
967
|
-
let directory = projectRoot
|
|
968
|
-
while (isPathInside(repositoryRoot, directory)) {
|
|
969
|
-
const candidate = path.join(directory, 'node_modules', ...packageName.split('/'))
|
|
970
|
-
try {
|
|
971
|
-
const physical = fs.realpathSync(candidate)
|
|
972
|
-
if (isPathInside(fs.realpathSync(repositoryRoot), physical)) return physical
|
|
973
|
-
} catch {}
|
|
974
|
-
if (directory === repositoryRoot) break
|
|
975
|
-
directory = path.dirname(directory)
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
/**
|
|
980
|
-
* Returns a runner package name.
|
|
981
|
-
*
|
|
982
|
-
* @param {string} framework framework name
|
|
983
|
-
*/
|
|
984
|
-
function getRunnerPackageName (framework) {
|
|
985
|
-
return {
|
|
986
|
-
cucumber: '@cucumber/cucumber',
|
|
987
|
-
playwright: '@playwright/test',
|
|
988
|
-
}[framework] || framework
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
* Returns a generated-test location that follows the representative discovery convention.
|
|
993
|
-
*
|
|
994
|
-
* @param {string} framework framework name
|
|
995
|
-
* @param {string} representative representative test
|
|
996
|
-
* @param {string} projectRoot detected project root
|
|
997
|
-
* @returns {{exactFilename: string|undefined, fileExtension: string, testDirectory: string}} convention
|
|
998
|
-
*/
|
|
999
|
-
function getGeneratedTestConvention (framework, representative, projectRoot) {
|
|
1000
|
-
const basename = path.basename(representative)
|
|
1001
|
-
if (/^test\.[cm]?[jt]s$/.test(basename)) {
|
|
1002
|
-
const representativeDirectory = path.dirname(representative)
|
|
1003
|
-
return {
|
|
1004
|
-
exactFilename: basename,
|
|
1005
|
-
fileExtension: path.extname(basename),
|
|
1006
|
-
testDirectory: representativeDirectory === projectRoot
|
|
1007
|
-
? projectRoot
|
|
1008
|
-
: path.dirname(representativeDirectory),
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
return {
|
|
1012
|
-
exactFilename: undefined,
|
|
1013
|
-
fileExtension: getTestExtension(framework, representative),
|
|
1014
|
-
testDirectory: path.dirname(representative),
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* Returns the complete suffix needed for framework discovery.
|
|
1020
|
-
*
|
|
1021
|
-
* @param {string} framework framework name
|
|
1022
|
-
* @param {string} representative representative test
|
|
1023
|
-
*/
|
|
1024
|
-
function getTestExtension (framework, representative) {
|
|
1025
|
-
if (framework === 'cucumber') return '.feature'
|
|
1026
|
-
if (framework === 'cypress') return cypress.getTestExtension(representative)
|
|
1027
|
-
if (framework === 'playwright') return playwright.getTestExtension(representative)
|
|
1028
|
-
const match = /([.-](?:test|spec)\.[cm]?[jt]sx?)$/.exec(representative)
|
|
1029
|
-
if (match) return match[1]
|
|
1030
|
-
const moduleExtension = /\.([cm]js|[cm]ts)$/.exec(representative)?.[1]
|
|
1031
|
-
return moduleExtension ? `.test.${moduleExtension}` : '.test.js'
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
/**
|
|
1035
|
-
* Determines the generated JavaScript module system.
|
|
1036
|
-
*
|
|
1037
|
-
* @param {string} representative representative test
|
|
1038
|
-
* @param {string} projectRoot project root
|
|
1039
|
-
* @returns {'commonjs'|'esm'} module system
|
|
1040
|
-
*/
|
|
1041
|
-
function getModuleSystem (representative, projectRoot) {
|
|
1042
|
-
if (/\.(?:mjs|mts)$/.test(representative)) return 'esm'
|
|
1043
|
-
if (/\.(?:cjs|cts)$/.test(representative)) return 'commonjs'
|
|
1044
|
-
|
|
1045
|
-
let directory = path.dirname(representative)
|
|
1046
|
-
while (isPathInside(projectRoot, directory)) {
|
|
1047
|
-
const packageJson = readJson(path.join(directory, 'package.json'))
|
|
1048
|
-
if (packageJson) return packageJson.type === 'module' ? 'esm' : 'commonjs'
|
|
1049
|
-
if (directory === projectRoot) break
|
|
1050
|
-
directory = path.dirname(directory)
|
|
1051
|
-
}
|
|
1052
|
-
return 'commonjs'
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
/**
|
|
1056
|
-
* Discovers bounded CI configuration paths without interpreting them.
|
|
1057
|
-
*
|
|
1058
|
-
* @param {string} root repository root
|
|
1059
|
-
* @returns {object} CI discovery data
|
|
1060
|
-
*/
|
|
1061
|
-
function discoverCiFiles (root) {
|
|
1062
|
-
const found = []
|
|
1063
|
-
for (const relativePath of CI_PATHS) {
|
|
1064
|
-
const absolutePath = path.join(root, relativePath)
|
|
1065
|
-
try {
|
|
1066
|
-
const stat = fs.lstatSync(absolutePath)
|
|
1067
|
-
if (stat.isSymbolicLink()) continue
|
|
1068
|
-
if (stat.isFile()) {
|
|
1069
|
-
found.push(relativePath)
|
|
1070
|
-
} else if (stat.isDirectory()) {
|
|
1071
|
-
for (const entry of readDirectoryEntries(absolutePath).slice(0, MAX_CI_FILES)) {
|
|
1072
|
-
if (entry.isFile() && /\.ya?ml$/i.test(entry.name)) found.push(path.join(relativePath, entry.name))
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
} catch {}
|
|
1076
|
-
}
|
|
1077
|
-
const normalized = found.map(filename => filename.split(path.sep).join('/')).sort()
|
|
1078
|
-
return {
|
|
1079
|
-
found: normalized,
|
|
1080
|
-
reviewRequired: normalized.length > 0,
|
|
1081
|
-
reviewTargets: rankCiReviewTargets(normalized).slice(0, MAX_CI_REVIEW_TARGETS),
|
|
1082
|
-
searched: CI_PATHS,
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
/**
|
|
1087
|
-
* Ranks likely test workflows first.
|
|
1088
|
-
*
|
|
1089
|
-
* @param {string[]} files discovered CI paths
|
|
1090
|
-
* @returns {string[]} ranked paths
|
|
1091
|
-
*/
|
|
1092
|
-
function rankCiReviewTargets (files) {
|
|
1093
|
-
return [...files].sort((left, right) => getCiRank(left) - getCiRank(right) || left.localeCompare(right))
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
/**
|
|
1097
|
-
* Returns a lower-is-better CI review rank.
|
|
1098
|
-
*
|
|
1099
|
-
* @param {string} filename CI path
|
|
1100
|
-
*/
|
|
1101
|
-
function getCiRank (filename) {
|
|
1102
|
-
const value = filename.toLowerCase()
|
|
1103
|
-
if (/test|ci|build|unit|integration/.test(value)) return 0
|
|
1104
|
-
return 10
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
/**
|
|
1108
|
-
* Finds the package manifest that owns a detection.
|
|
1109
|
-
*
|
|
1110
|
-
* @param {string} repositoryRoot repository root
|
|
1111
|
-
* @param {string|undefined} location detected relative path
|
|
1112
|
-
* @returns {{json: object, path: string}} package metadata
|
|
1113
|
-
*/
|
|
1114
|
-
function getDetectionPackageJson (repositoryRoot, location) {
|
|
1115
|
-
const candidate = typeof location === 'string' && path.basename(location) === 'package.json'
|
|
1116
|
-
? path.resolve(repositoryRoot, location)
|
|
1117
|
-
: path.join(repositoryRoot, 'package.json')
|
|
1118
|
-
const json = readJson(candidate)
|
|
1119
|
-
if (json) return { json, path: candidate }
|
|
1120
|
-
return {
|
|
1121
|
-
json: readJson(path.join(repositoryRoot, 'package.json')) || {},
|
|
1122
|
-
path: path.join(repositoryRoot, 'package.json'),
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
function getFrameworkPackageJson (repositoryRoot, detection) {
|
|
1127
|
-
const preciseLocation = detection.commandLocation ||
|
|
1128
|
-
detection.supportedVersion?.relativePath ||
|
|
1129
|
-
detection.eligibleCommand?.relativePath ||
|
|
1130
|
-
detection.versionLocation
|
|
1131
|
-
if (preciseLocation) return findOwningPackageJson(repositoryRoot, preciseLocation)
|
|
1132
|
-
|
|
1133
|
-
const owners = new Map()
|
|
1134
|
-
if (detection.locations) {
|
|
1135
|
-
for (const location of detection.locations) {
|
|
1136
|
-
const owner = findOwningPackageJson(repositoryRoot, location)
|
|
1137
|
-
if (owner) owners.set(owner.path, owner)
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
if (owners.size === 1) return [...owners.values()][0]
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
function findOwningPackageJson (repositoryRoot, location) {
|
|
1144
|
-
let candidate = path.resolve(repositoryRoot, location)
|
|
1145
|
-
if (!isPathInside(repositoryRoot, candidate)) return
|
|
1146
|
-
try {
|
|
1147
|
-
if (!fs.statSync(candidate).isDirectory()) candidate = path.dirname(candidate)
|
|
1148
|
-
} catch {
|
|
1149
|
-
candidate = path.dirname(candidate)
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
while (isPathInside(repositoryRoot, candidate)) {
|
|
1153
|
-
const packageJson = path.join(candidate, 'package.json')
|
|
1154
|
-
const json = readJson(packageJson)
|
|
1155
|
-
if (json) return { json, path: packageJson }
|
|
1156
|
-
if (candidate === repositoryRoot) return
|
|
1157
|
-
candidate = path.dirname(candidate)
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
function getDetectionPackageLocation (detection) {
|
|
1162
|
-
return detection.commandLocation ||
|
|
1163
|
-
detection.supportedVersion?.relativePath ||
|
|
1164
|
-
detection.eligibleCommand?.relativePath ||
|
|
1165
|
-
detection.versionLocation ||
|
|
1166
|
-
detection.locations?.[0]
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
/**
|
|
1170
|
-
* Safely reads a bounded directory.
|
|
1171
|
-
*
|
|
1172
|
-
* @param {string} directory directory path
|
|
1173
|
-
* @returns {fs.Dirent[]} entries
|
|
1174
|
-
*/
|
|
1175
|
-
function readDirectoryEntries (directory) {
|
|
1176
|
-
try {
|
|
1177
|
-
return fs.readdirSync(directory, { withFileTypes: true }).slice(0, MAX_DIRECTORY_ENTRIES)
|
|
1178
|
-
} catch {
|
|
1179
|
-
return []
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
/**
|
|
1184
|
-
* Reads bounded UTF-8 source.
|
|
1185
|
-
*
|
|
1186
|
-
* @param {string} filename file path
|
|
1187
|
-
* @returns {string|undefined} source
|
|
1188
|
-
*/
|
|
1189
|
-
function readText (filename) {
|
|
1190
|
-
try {
|
|
1191
|
-
const stat = fs.lstatSync(filename)
|
|
1192
|
-
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_FILE_BYTES) return
|
|
1193
|
-
return fs.readFileSync(filename, 'utf8')
|
|
1194
|
-
} catch {}
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
/**
|
|
1198
|
-
* Reads JSON without throwing.
|
|
1199
|
-
*
|
|
1200
|
-
* @param {string} filename JSON path
|
|
1201
|
-
* @returns {object|undefined} parsed object
|
|
1202
|
-
*/
|
|
1203
|
-
function readJson (filename) {
|
|
1204
|
-
const source = readText(filename)
|
|
1205
|
-
if (source === undefined) return
|
|
1206
|
-
try {
|
|
1207
|
-
return JSON.parse(source)
|
|
1208
|
-
} catch {}
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
/**
|
|
1212
|
-
* Returns whether a framework target was selected.
|
|
1213
|
-
*
|
|
1214
|
-
* @param {string} framework framework id
|
|
1215
|
-
* @param {Set<string>} selected selected ids
|
|
1216
|
-
*/
|
|
1217
|
-
function isSelected (framework, selected) {
|
|
1218
|
-
return selected.size === 0 || selected.has(framework)
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
/**
|
|
1222
|
-
* Returns a stable project identifier.
|
|
1223
|
-
*
|
|
1224
|
-
* @param {object} packageJson package metadata
|
|
1225
|
-
* @param {string} projectRoot project root
|
|
1226
|
-
* @param {string} repositoryRoot repository root
|
|
1227
|
-
*/
|
|
1228
|
-
function getProjectId (packageJson, projectRoot, repositoryRoot) {
|
|
1229
|
-
const value = packageJson.name || path.relative(repositoryRoot, projectRoot) || 'root'
|
|
1230
|
-
return value.replace(/^@/, '').replaceAll(/[^A-Za-z0-9_.-]+/g, '-')
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
/**
|
|
1234
|
-
* Detects package-manager metadata for reporting only.
|
|
1235
|
-
*
|
|
1236
|
-
* @param {string} root repository root
|
|
1237
|
-
*/
|
|
1238
|
-
function detectPackageManager (root) {
|
|
1239
|
-
if (fs.existsSync(path.join(root, 'pnpm-lock.yaml'))) return 'pnpm'
|
|
1240
|
-
if (fs.existsSync(path.join(root, 'yarn.lock'))) return 'yarn'
|
|
1241
|
-
if (fs.existsSync(path.join(root, 'package-lock.json'))) return 'npm'
|
|
1242
|
-
return 'unknown'
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* Detects workspace metadata for reporting only.
|
|
1247
|
-
*
|
|
1248
|
-
* @param {string} root repository root
|
|
1249
|
-
*/
|
|
1250
|
-
function detectWorkspaceManager (root) {
|
|
1251
|
-
if (fs.existsSync(path.join(root, 'pnpm-workspace.yaml'))) return 'pnpm'
|
|
1252
|
-
const packageJson = readJson(path.join(root, 'package.json'))
|
|
1253
|
-
return packageJson?.workspaces ? detectPackageManager(root) : 'none'
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
/**
|
|
1257
|
-
* Returns a manifest operating-system name.
|
|
1258
|
-
*
|
|
1259
|
-
* @param {string} platform Node.js platform
|
|
1260
|
-
*/
|
|
1261
|
-
function getManifestOs (platform) {
|
|
1262
|
-
return platform === 'win32' ? 'windows' : platform
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* Checks lexical path containment.
|
|
1267
|
-
*
|
|
1268
|
-
* @param {string} root root path
|
|
1269
|
-
* @param {string} filename candidate path
|
|
1270
|
-
*/
|
|
1271
|
-
function isPathInside (root, filename) {
|
|
1272
|
-
const relative = path.relative(path.resolve(root), path.resolve(filename))
|
|
1273
|
-
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
module.exports = { createManifestScaffold }
|