dd-trace 6.24.0 → 6.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ci/init.js +2 -22
- package/ext/exporters.js +0 -1
- package/index.d.ts +105 -5
- package/initialize.mjs +5 -2
- package/lambda.d.ts +39 -0
- package/lambda.js +3 -0
- package/package.json +11 -9
- package/packages/datadog-esbuild/index.js +8 -55
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +5 -2
- 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 +20 -17
- 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/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -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.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/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -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/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/otel-sdk-trace.js +11 -9
- 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-cypress/src/cypress-plugin.js +22 -11
- 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-http/src/client.js +32 -9
- package/packages/datadog-plugin-http2/src/client.js +38 -13
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- 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-undici/src/index.js +22 -7
- 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/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/sdk.js +8 -2
- 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 +15 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
- 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 +1 -2
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
- 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 +5 -0
- package/packages/dd-trace/src/config/generated-config-types.d.ts +42 -2
- package/packages/dd-trace/src/config/index.js +17 -5
- package/packages/dd-trace/src/config/parsers.js +9 -0
- package/packages/dd-trace/src/config/supported-configurations.json +158 -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/exporter.js +0 -11
- package/packages/dd-trace/src/exporters/common/request.js +81 -48
- 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/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 +2 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/sdk.js +19 -0
- package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
- package/packages/dd-trace/src/llmobs/tagger.js +22 -0
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +6 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +4 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +35 -27
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
- package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
- 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/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/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +24 -0
- package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +41 -10
- package/packages/dd-trace/src/plugins/index.js +6 -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 +263 -82
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
- 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 +64 -39
- 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 +65 -10
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/proxy.js +33 -53
- package/packages/dd-trace/src/span_processor.js +20 -0
- package/packages/dd-trace/src/startup-log.js +8 -6
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +2 -1
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
- 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/rules-based/LICENSE +3 -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/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 -18
- 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 -649
- 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
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs')
|
|
4
|
-
const path = require('node:path')
|
|
5
|
-
|
|
6
|
-
const { BLOCKER_CATEGORIES } = require('./blocker-category')
|
|
7
|
-
const { isProjectBuildArtifactPath } = require('./project-build-artifact')
|
|
8
|
-
const { stripAnsi } = require('./test-output')
|
|
9
|
-
|
|
10
|
-
const FILESYSTEM_PERMISSION_PATTERN = /\b(?:EACCES|EPERM|Operation not permitted|Permission denied)\b/i
|
|
11
|
-
const LOCAL_SOCKET_PATTERN = /\b(?:127\.0\.0\.1|localhost|listen)\b/i
|
|
12
|
-
const CONNECTION_REFUSED_PATTERN = /\bECONNREFUSED\b|\bconnection refused\b/i
|
|
13
|
-
const NO_TESTS_FOUND_PATTERN =
|
|
14
|
-
/\b(?:No test files? found|No tests? found|No test files? were found|0 tests? collected)\b/i
|
|
15
|
-
const MODULE_OR_TRANSFORM_PATTERN =
|
|
16
|
-
/\b(?:Cannot find (?:module|package)|ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND|ERR_PACKAGE_PATH_NOT_EXPORTED|Package subpath\b[\s\S]+\bnot defined by "exports"|Could not resolve|transform failed)\b/i
|
|
17
|
-
const BUILD_ARTIFACT_PATH_PATTERN = String.raw`(?:^|[\\/])(?:build|dist|generated)(?:[\\/]|['"])`
|
|
18
|
-
const MISSING_ARTIFACT_MESSAGE_PATTERN =
|
|
19
|
-
/Cannot find (?:module|package)|ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND|ENOENT|no such file or directory|is not found|does not exist|could not be found/
|
|
20
|
-
/* eslint-disable regexp/no-useless-non-capturing-group, regexp/prefer-character-class --
|
|
21
|
-
* The interpolated message fragment contains alternatives and must stay grouped on both sides of the path. */
|
|
22
|
-
const BUILD_ARTIFACT_MISSING_PATTERN = new RegExp(
|
|
23
|
-
String.raw`(?:(?:${MISSING_ARTIFACT_MESSAGE_PATTERN.source})[^\r\n]{0,500}${BUILD_ARTIFACT_PATH_PATTERN}|` +
|
|
24
|
-
String.raw`${BUILD_ARTIFACT_PATH_PATTERN}[^\r\n]{0,500}(?:${MISSING_ARTIFACT_MESSAGE_PATTERN.source}))`,
|
|
25
|
-
'im'
|
|
26
|
-
)
|
|
27
|
-
/* eslint-enable regexp/no-useless-non-capturing-group, regexp/prefer-character-class */
|
|
28
|
-
const FILE_PATH_REFERENCE_PATTERN = /(?:^|[\s('"`])((?:\.{1,2}[\\/]|[\\/]|[A-Za-z]:[\\/])[^'"`\s),;]*)/g
|
|
29
|
-
const CUCUMBER_CONFIG_OPTION_UNSUPPORTED_PATTERN = /unknown option ['"]--config['"]/i
|
|
30
|
-
const CYPRESS_BINARY_PATTERN =
|
|
31
|
-
/Cypress executable not found|Cypress binary is missing|Cypress failed to start|Please reinstall Cypress/i
|
|
32
|
-
const PLAYWRIGHT_BROWSER_PATTERN = new RegExp(
|
|
33
|
-
String.raw`browserType\.launch: Executable doesn't exist|` +
|
|
34
|
-
'Please run the following command to download new browsers|playwright install',
|
|
35
|
-
'i'
|
|
36
|
-
)
|
|
37
|
-
const PLAYWRIGHT_BROWSER_LAUNCH_PATTERN =
|
|
38
|
-
/Failed to launch the browser process|bootstrap_check_in|MachPortRendezvous/i
|
|
39
|
-
const PLAYWRIGHT_BROWSER_ABORT_PATTERN =
|
|
40
|
-
/(?:browserType\.launch: Target page, context or browser has been closed|Browser logs:)[\s\S]*?(?:signal=SIGABRT|Received signal 6|Abort trap: 6)/i
|
|
41
|
-
const PUPPETEER_BROWSER_PATTERN =
|
|
42
|
-
/(?:Could not find (?:Chrome|Chromium)|Failed to launch the browser process|Troubleshooting:\s*https:\/\/pptr\.dev)/i
|
|
43
|
-
const PUPPETEER_BROWSER_ABORT_PATTERN =
|
|
44
|
-
/Failed to launch the browser process[\s\S]*?(?:signal=SIGABRT|Received signal 6|Abort trap: 6)/i
|
|
45
|
-
const CUCUMBER_BROWSER_FAILURE_PATTERN =
|
|
46
|
-
/(?:browser|puppeteer|playwright|webdriver)[^\r\n]{1,160}\b(?:aborted|closed|crashed|failed|terminated|unavailable)\b|(?:Failed|Unable) to (?:connect to|launch|start) (?:the )?browser/i
|
|
47
|
-
const VITEST_BROWSER_PROVIDER_PATTERN =
|
|
48
|
-
/Cannot find (?:module|package).*@vitest\/browser|@vitest\/browser-[^\s'"].*(?:missing|not (?:found|installed))/i
|
|
49
|
-
const RUNNER_COMMAND_NOT_FOUND_PATTERN =
|
|
50
|
-
/command not found|is not recognized as an internal or external command|spawn [^\r\n]+ ENOENT/i
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Identifies toolchain and execution-environment failures that happen before tests start.
|
|
54
|
-
*
|
|
55
|
-
* @param {object} result command result
|
|
56
|
-
* @param {string} [result.stdout] captured stdout
|
|
57
|
-
* @param {string} [result.stderr] captured stderr
|
|
58
|
-
* @param {object} [options] classification options
|
|
59
|
-
* @param {boolean} [options.browserRequired] whether the selected runner uses browser mode
|
|
60
|
-
* @param {string} [options.framework] test framework identifier
|
|
61
|
-
* @param {string} [options.packageJson] approval-bound project package.json
|
|
62
|
-
* @param {boolean} [options.testsRan] whether reliable test output was observed
|
|
63
|
-
* @returns {object|undefined} structured blocker diagnosis
|
|
64
|
-
*/
|
|
65
|
-
function getCommandBlocker (result, options = {}) {
|
|
66
|
-
const output = `${result.stdout || ''}\n${result.stderr || ''}`
|
|
67
|
-
if (Array.isArray(result.missingRequiredEnvVars) && result.missingRequiredEnvVars.length > 0) {
|
|
68
|
-
return {
|
|
69
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
70
|
-
kind: 'project-command-environment-missing',
|
|
71
|
-
summary: 'The selected project test command requires approved non-secret environment variables that are not ' +
|
|
72
|
-
'available in the validator process. No Test Optimization conclusion was reached.',
|
|
73
|
-
recommendation: `Set the required project test variables (${result.missingRequiredEnvVars.join(', ')}) in the ` +
|
|
74
|
-
'environment that launches the validator, then render and approve a fresh plan.',
|
|
75
|
-
signals: result.missingRequiredEnvVars.map(name => `${name} is not set.`),
|
|
76
|
-
toolchainBlocked: true,
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (options.framework === 'cucumber' && result.exitCode !== 0 &&
|
|
80
|
-
CUCUMBER_CONFIG_OPTION_UNSUPPORTED_PATTERN.test(output)) {
|
|
81
|
-
return {
|
|
82
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
83
|
-
kind: 'cucumber-config-isolation-unsupported',
|
|
84
|
-
summary: 'The installed Cucumber CLI rejected the validator-owned configuration-isolation option. This is a ' +
|
|
85
|
-
'validator compatibility limitation, not a project test or Test Optimization failure.',
|
|
86
|
-
recommendation: 'Report this Cucumber version to validator engineering. Use the static CI audit and do not ' +
|
|
87
|
-
'change the customer profile, command, or working directory to bypass this limitation.',
|
|
88
|
-
signals: getMatchingLines(output, CUCUMBER_CONFIG_OPTION_UNSUPPORTED_PATTERN),
|
|
89
|
-
validatorBlocked: true,
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (LOCAL_SOCKET_PATTERN.test(output) && FILESYSTEM_PERMISSION_PATTERN.test(output)) {
|
|
93
|
-
return {
|
|
94
|
-
blockerCategory: BLOCKER_CATEGORIES.EXECUTION_ENVIRONMENT_BLOCKED,
|
|
95
|
-
kind: 'local-test-socket-blocked',
|
|
96
|
-
summary: 'The selected project test could not start its localhost listener in this execution environment. ' +
|
|
97
|
-
'The offline Datadog validator did not open this socket. No Test Optimization conclusion was reached.',
|
|
98
|
-
recommendation: 'Run the same approved plan in an environment that permits the project test to use its ' +
|
|
99
|
-
'required localhost socket. Use the unchanged command and SHA from execution-plan.md. This may require ' +
|
|
100
|
-
'normal project-test permissions. Do not request broader permissions automatically or interpret this as a ' +
|
|
101
|
-
'Test Optimization failure.',
|
|
102
|
-
signals: getMatchingLines(
|
|
103
|
-
output,
|
|
104
|
-
/127\.0\.0\.1|localhost|listen|EACCES|EPERM|Operation not permitted|Permission denied/i
|
|
105
|
-
),
|
|
106
|
-
blockedByExecutionEnvironment: true,
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (options.framework === 'cypress' && result.exitCode !== 0 &&
|
|
110
|
-
CONNECTION_REFUSED_PATTERN.test(output) && LOCAL_SOCKET_PATTERN.test(output)) {
|
|
111
|
-
return {
|
|
112
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
113
|
-
kind: 'cypress-application-unavailable',
|
|
114
|
-
summary: 'The selected Cypress spec could not connect to its localhost application. Discovery does not start ' +
|
|
115
|
-
'customer services, so no Test Optimization conclusion was reached.',
|
|
116
|
-
recommendation: 'Start the application through the project\'s normal setup, confirm the selected Cypress spec ' +
|
|
117
|
-
'passes normally, then render and approve a fresh validation plan.',
|
|
118
|
-
signals: getMatchingLines(output, /ECONNREFUSED|connection refused|127\.0\.0\.1|localhost/i),
|
|
119
|
-
blockedByProjectSetup: true,
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (options.testsRan !== true && NO_TESTS_FOUND_PATTERN.test(output)) {
|
|
123
|
-
return {
|
|
124
|
-
blockerCategory: BLOCKER_CATEGORIES.VALIDATOR_LIMITATION,
|
|
125
|
-
kind: 'no-tests-collected',
|
|
126
|
-
summary: 'The selected representative was not collected by the project test runner. No Test Optimization ' +
|
|
127
|
-
'conclusion was reached.',
|
|
128
|
-
recommendation: 'Use the project\'s normal configuration to make a single runtime test collectible, then ' +
|
|
129
|
-
'create a fresh validation plan. Type-only tests and files outside the runner\'s include rules are not valid ' +
|
|
130
|
-
'representatives.',
|
|
131
|
-
signals: getMatchingLines(output, NO_TESTS_FOUND_PATTERN),
|
|
132
|
-
blockedByProjectSetup: true,
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const browserMode = options.framework === 'playwright' ||
|
|
137
|
-
(options.framework === 'cucumber' && options.browserRequired === true) ||
|
|
138
|
-
(options.framework === 'vitest' && options.browserRequired === true)
|
|
139
|
-
if (browserMode &&
|
|
140
|
-
result.exitCode !== 0 &&
|
|
141
|
-
PLAYWRIGHT_BROWSER_LAUNCH_PATTERN.test(output) && FILESYSTEM_PERMISSION_PATTERN.test(output)) {
|
|
142
|
-
const runner = getBrowserRunnerName(options.framework)
|
|
143
|
-
return {
|
|
144
|
-
blockerCategory: BLOCKER_CATEGORIES.EXECUTION_ENVIRONMENT_BLOCKED,
|
|
145
|
-
kind: `${options.framework}-browser-launch-blocked`,
|
|
146
|
-
summary: `${runner} needs to launch the project browser, but the current execution environment denied that ` +
|
|
147
|
-
'launch. ' +
|
|
148
|
-
'No Test Optimization conclusion was reached.',
|
|
149
|
-
recommendation: 'Retry the same approved plan from a host shell or another environment where the installed ' +
|
|
150
|
-
'project browser can launch. Use the unchanged command and SHA from execution-plan.md. Do not request ' +
|
|
151
|
-
'broader permissions automatically or change the command, approval file, or approval SHA.',
|
|
152
|
-
signals: getMatchingLines(
|
|
153
|
-
output,
|
|
154
|
-
/Failed to launch the browser process|bootstrap_check_in|MachPortRendezvous|EACCES|EPERM|Operation not permitted|Permission denied/i
|
|
155
|
-
),
|
|
156
|
-
blockedByExecutionEnvironment: true,
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (options.framework === 'playwright' && result.exitCode !== 0 &&
|
|
161
|
-
PLAYWRIGHT_BROWSER_ABORT_PATTERN.test(stripAnsi(output))) {
|
|
162
|
-
return {
|
|
163
|
-
blockerCategory: BLOCKER_CATEGORIES.CLEAN_TEST_FAILED,
|
|
164
|
-
kind: 'playwright-browser-process-aborted',
|
|
165
|
-
summary: 'A browser launched by Playwright aborted before the selected tests could produce reliable results. ' +
|
|
166
|
-
'The available evidence does not identify whether the browser/runtime setup, the project, the execution ' +
|
|
167
|
-
'environment, or another local condition caused the abort. No Test Optimization conclusion was reached.',
|
|
168
|
-
recommendation: 'Run the same approved Playwright command directly in the project\'s normal test environment ' +
|
|
169
|
-
'and collect Playwright, browser, and operating-system crash diagnostics. If it succeeds there, render and ' +
|
|
170
|
-
'approve a fresh validation plan in that environment. Do not treat this result as a Test Optimization failure.',
|
|
171
|
-
signals: getMatchingLines(
|
|
172
|
-
output,
|
|
173
|
-
/browserType\.launch: Target page, context or browser has been closed|signal=SIGABRT|Received signal 6|Abort trap: 6/i
|
|
174
|
-
),
|
|
175
|
-
localRuntimeBlocked: true,
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (options.framework === 'cucumber' && options.browserRequired === true && result.exitCode !== 0 &&
|
|
180
|
-
PUPPETEER_BROWSER_ABORT_PATTERN.test(stripAnsi(output))) {
|
|
181
|
-
return {
|
|
182
|
-
blockerCategory: BLOCKER_CATEGORIES.CLEAN_TEST_FAILED,
|
|
183
|
-
kind: 'cucumber-browser-process-aborted',
|
|
184
|
-
summary: 'A browser launched by the selected Cucumber support code aborted before a reliable scenario result ' +
|
|
185
|
-
'was observed. No Test Optimization conclusion was reached.',
|
|
186
|
-
recommendation: 'Run the same approved plan where the project\'s normal Cucumber browser tests can launch. ' +
|
|
187
|
-
'Collect the browser and operating-system crash diagnostics if it still fails; do not treat this result as ' +
|
|
188
|
-
'a Test Optimization failure.',
|
|
189
|
-
signals: getMatchingLines(
|
|
190
|
-
output,
|
|
191
|
-
/Failed to launch the browser process|signal=SIGABRT|Received signal 6|Abort trap: 6/i
|
|
192
|
-
),
|
|
193
|
-
localRuntimeBlocked: true,
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (options.framework === 'cypress' && result.exitCode !== 0 &&
|
|
198
|
-
options.testsRan !== true && CYPRESS_BINARY_PATTERN.test(output)) {
|
|
199
|
-
return {
|
|
200
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
201
|
-
kind: 'cypress-runtime-missing',
|
|
202
|
-
summary: 'The Cypress npm package is installed, but its application binary is missing or could not start. ' +
|
|
203
|
-
'No Test Optimization conclusion was reached.',
|
|
204
|
-
recommendation: 'Complete the project\'s normal Cypress binary/browser setup, then render and approve a ' +
|
|
205
|
-
'fresh validation plan. The validator does not download browsers automatically.',
|
|
206
|
-
signals: getMatchingLines(output, CYPRESS_BINARY_PATTERN),
|
|
207
|
-
toolchainBlocked: true,
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (browserMode && result.exitCode !== 0 && options.testsRan !== true &&
|
|
212
|
-
(PLAYWRIGHT_BROWSER_PATTERN.test(output) || PUPPETEER_BROWSER_PATTERN.test(output))) {
|
|
213
|
-
const vitestBrowser = options.framework === 'vitest' && options.browserRequired === true
|
|
214
|
-
const cucumberBrowser = options.framework === 'cucumber'
|
|
215
|
-
const browserPattern = cucumberBrowser ? PUPPETEER_BROWSER_PATTERN : PLAYWRIGHT_BROWSER_PATTERN
|
|
216
|
-
return {
|
|
217
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
218
|
-
kind: vitestBrowser
|
|
219
|
-
? 'vitest-browser-provider-missing'
|
|
220
|
-
: cucumberBrowser
|
|
221
|
-
? 'cucumber-browser-missing'
|
|
222
|
-
: 'playwright-browser-missing',
|
|
223
|
-
summary: `${getBrowserRunnerName(options.framework)} is installed, but the selected project ` +
|
|
224
|
-
'test requires a browser binary or provider that is not installed. ' +
|
|
225
|
-
'No Test Optimization conclusion was reached.',
|
|
226
|
-
recommendation: `Complete the project's normal ${getBrowserRunnerName(options.framework)} setup, then render ` +
|
|
227
|
-
'and approve a fresh ' +
|
|
228
|
-
'validation plan. The validator does not download browsers automatically.',
|
|
229
|
-
signals: getMatchingLines(output, browserPattern),
|
|
230
|
-
toolchainBlocked: true,
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (result.exitCode !== 0 && options.testsRan !== true && options.framework === 'vitest' &&
|
|
235
|
-
options.browserRequired === true && VITEST_BROWSER_PROVIDER_PATTERN.test(output)) {
|
|
236
|
-
return {
|
|
237
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
238
|
-
kind: 'vitest-browser-provider-missing',
|
|
239
|
-
summary: 'Vitest browser mode could not load its configured browser provider. Local Test Optimization ' +
|
|
240
|
-
'compatibility was not tested. No Test Optimization conclusion was reached.',
|
|
241
|
-
recommendation: 'Complete the project\'s normal Vitest browser setup, then render and approve a fresh ' +
|
|
242
|
-
'validation plan. The validator does not install browser providers or download browsers automatically.',
|
|
243
|
-
signals: getMatchingLines(output, VITEST_BROWSER_PROVIDER_PATTERN),
|
|
244
|
-
toolchainBlocked: true,
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (result.exitCode !== 0 && options.testsRan !== true && RUNNER_COMMAND_NOT_FOUND_PATTERN.test(output)) {
|
|
249
|
-
return {
|
|
250
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
251
|
-
kind: 'test-runner-command-missing',
|
|
252
|
-
summary: 'The selected project test command could not find its test-runner executable, so local Test ' +
|
|
253
|
-
'Optimization compatibility was not tested. No Test Optimization conclusion was reached.',
|
|
254
|
-
recommendation: 'Complete the project\'s normal dependency or package-manager setup so the selected test ' +
|
|
255
|
-
'command can resolve its runner, then render and approve a fresh validation plan.',
|
|
256
|
-
signals: getMatchingLines(output, RUNNER_COMMAND_NOT_FOUND_PATTERN),
|
|
257
|
-
toolchainBlocked: true,
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const projectRoot = typeof options.packageJson === 'string' ? path.dirname(options.packageJson) : undefined
|
|
262
|
-
if (result.exitCode !== 0 && hasMissingProjectBuildArtifact(output, projectRoot)) {
|
|
263
|
-
const buildScript = getBuildScript(options.packageJson)
|
|
264
|
-
return {
|
|
265
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
266
|
-
kind: 'project-build-artifact-missing',
|
|
267
|
-
summary: 'The selected test requires a conventional build or generated output that is missing. The validator ' +
|
|
268
|
-
'does not run project build commands, so no Test Optimization conclusion was reached.',
|
|
269
|
-
recommendation: `Complete the project's normal build workflow${
|
|
270
|
-
buildScript ? `; package.json declares "build": ${JSON.stringify(buildScript)}` : ''
|
|
271
|
-
}. Confirm the selected test passes normally, then render and approve a fresh validation plan.`,
|
|
272
|
-
signals: getMatchingLines(output, BUILD_ARTIFACT_MISSING_PATTERN),
|
|
273
|
-
blockedByProjectSetup: true,
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (result.exitCode !== 0 && options.testsRan !== true && MODULE_OR_TRANSFORM_PATTERN.test(output)) {
|
|
278
|
-
return {
|
|
279
|
-
blockerCategory: BLOCKER_CATEGORIES.PROJECT_SETUP_REQUIRED,
|
|
280
|
-
kind: 'project-command-initialization-failed',
|
|
281
|
-
summary: 'The selected project test command failed during module resolution, transformation, or runner ' +
|
|
282
|
-
'initialization before a reliable test result was observed. No Test Optimization conclusion was reached.',
|
|
283
|
-
recommendation: 'Satisfy the selected test command\'s build and module prerequisites, or select a focused ' +
|
|
284
|
-
'test command whose prerequisites already exist, then render and approve a fresh plan.',
|
|
285
|
-
signals: getMatchingLines(output, MODULE_OR_TRANSFORM_PATTERN),
|
|
286
|
-
toolchainBlocked: true,
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (options.framework === 'cypress' && result.exitCode === 134 && options.testsRan !== true) {
|
|
291
|
-
return {
|
|
292
|
-
blockerCategory: BLOCKER_CATEGORIES.CLEAN_TEST_FAILED,
|
|
293
|
-
kind: 'cypress-process-aborted',
|
|
294
|
-
summary: 'Cypress exited with code 134 before any test result was observed. The available evidence does not ' +
|
|
295
|
-
'identify whether Cypress, its browser/runtime setup, the project, or the execution environment caused the ' +
|
|
296
|
-
'abort. No Test Optimization conclusion was reached.',
|
|
297
|
-
recommendation: 'Run the same project Cypress command directly in the project\'s normal test environment and ' +
|
|
298
|
-
'capture Cypress or operating-system crash diagnostics. If that command succeeds there, render and approve ' +
|
|
299
|
-
'a fresh validation plan in that environment. Do not treat this result as a Test Optimization failure.',
|
|
300
|
-
signals: [
|
|
301
|
-
'Cypress exited with code 134 before any test result was observed.',
|
|
302
|
-
'The captured output did not match a known setup or execution-environment failure.',
|
|
303
|
-
],
|
|
304
|
-
localRuntimeBlocked: true,
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (options.framework === 'cucumber' && options.browserRequired === true &&
|
|
309
|
-
result.exitCode !== 0 && options.testsRan !== true &&
|
|
310
|
-
CUCUMBER_BROWSER_FAILURE_PATTERN.test(output)) {
|
|
311
|
-
return {
|
|
312
|
-
blockerCategory: BLOCKER_CATEGORIES.CLEAN_TEST_FAILED,
|
|
313
|
-
kind: 'cucumber-browser-execution-incomplete',
|
|
314
|
-
summary: 'The selected Cucumber scenario uses browser-backed support code and exited before a reliable ' +
|
|
315
|
-
'scenario result was observed. A secondary Cucumber formatter exception is not enough to identify the root ' +
|
|
316
|
-
'cause. No Test Optimization conclusion was reached.',
|
|
317
|
-
recommendation: 'Run the same approved plan where the project\'s normal Cucumber browser tests can launch, ' +
|
|
318
|
-
'then create a fresh plan. If it still fails, preserve the earliest browser or project error rather than ' +
|
|
319
|
-
'treating a later formatter exception as the cause.',
|
|
320
|
-
signals: getMatchingLines(
|
|
321
|
-
output,
|
|
322
|
-
/Failed to launch|Received signal|TypeError|Cannot read|browser|puppeteer|playwright/i
|
|
323
|
-
),
|
|
324
|
-
localRuntimeBlocked: true,
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function hasMissingProjectBuildArtifact (output, projectRoot) {
|
|
330
|
-
for (const line of output.split(/\r?\n/)) {
|
|
331
|
-
if (!BUILD_ARTIFACT_MISSING_PATTERN.test(line)) continue
|
|
332
|
-
for (const match of line.matchAll(FILE_PATH_REFERENCE_PATTERN)) {
|
|
333
|
-
if (isProjectBuildArtifactPath(match[1], projectRoot)) return true
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return false
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function getBuildScript (packageJson) {
|
|
340
|
-
if (typeof packageJson !== 'string') return
|
|
341
|
-
try {
|
|
342
|
-
const stat = fs.statSync(packageJson)
|
|
343
|
-
if (!stat.isFile() || stat.size > 512 * 1024) return
|
|
344
|
-
const script = JSON.parse(fs.readFileSync(packageJson, 'utf8'))?.scripts?.build
|
|
345
|
-
if (typeof script !== 'string' || !script.trim() || Buffer.byteLength(script) > 500 ||
|
|
346
|
-
/[\0\r\n]/.test(script)) return
|
|
347
|
-
return script.trim()
|
|
348
|
-
} catch {}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function getBrowserRunnerName (framework) {
|
|
352
|
-
if (framework === 'cucumber') return 'Cucumber browser support'
|
|
353
|
-
if (framework === 'vitest') return 'Vitest browser mode'
|
|
354
|
-
return 'Playwright Test'
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Returns a small de-duplicated set of matching output lines.
|
|
359
|
-
*
|
|
360
|
-
* @param {string} output command output
|
|
361
|
-
* @param {RegExp} pattern interesting-line pattern
|
|
362
|
-
* @returns {string[]} matching lines
|
|
363
|
-
*/
|
|
364
|
-
function getMatchingLines (output, pattern) {
|
|
365
|
-
const lines = []
|
|
366
|
-
const seen = new Set()
|
|
367
|
-
for (const line of output.split(/\r?\n/)) {
|
|
368
|
-
const value = stripAnsi(line).trim()
|
|
369
|
-
if (!value || seen.has(value) || !pattern.test(value)) continue
|
|
370
|
-
seen.add(value)
|
|
371
|
-
lines.push(value)
|
|
372
|
-
if (lines.length === 6) break
|
|
373
|
-
}
|
|
374
|
-
return lines
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
module.exports = { getCommandBlocker }
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs')
|
|
4
|
-
const path = require('node:path')
|
|
5
|
-
|
|
6
|
-
const { createValidationBlocker } = require('./validation-blocker')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns command-created paths that must be declared and removed after validation.
|
|
10
|
-
*
|
|
11
|
-
* @param {object} command structured command
|
|
12
|
-
* @returns {string[]} absolute output paths
|
|
13
|
-
*/
|
|
14
|
-
function getCommandOutputPaths (command) {
|
|
15
|
-
return [...new Set((command.outputPaths || []).map(outputPath => path.resolve(command.cwd, outputPath)))]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Refuses pre-existing outputs and records parent identities for fail-closed cleanup.
|
|
20
|
-
*
|
|
21
|
-
* @param {object} input isolation inputs
|
|
22
|
-
* @param {object} input.command structured command
|
|
23
|
-
* @param {string} input.artifactRoot validation results root
|
|
24
|
-
* @param {string} [input.repositoryRoot] repository root
|
|
25
|
-
* @returns {{outputPath: string, repositoryRoot: string, parentIdentities: object[]}[]} cleanup state
|
|
26
|
-
*/
|
|
27
|
-
function prepareCommandOutputs ({ command, artifactRoot, repositoryRoot }) {
|
|
28
|
-
repositoryRoot = path.resolve(repositoryRoot || path.dirname(path.resolve(artifactRoot)))
|
|
29
|
-
const states = []
|
|
30
|
-
const outputPaths = getCommandOutputPaths(command)
|
|
31
|
-
|
|
32
|
-
for (const outputPath of outputPaths) {
|
|
33
|
-
assertSafeOutputPath({ outputPath, repositoryRoot, artifactRoot, command })
|
|
34
|
-
}
|
|
35
|
-
for (const outputPath of outputPaths) {
|
|
36
|
-
if (pathExists(outputPath)) {
|
|
37
|
-
throw createValidationBlocker(
|
|
38
|
-
`Command output path already exists and will not be moved or overwritten: ${outputPath}. ` +
|
|
39
|
-
'The validator will not delete pre-existing output.',
|
|
40
|
-
{
|
|
41
|
-
kind: 'command-output-exists',
|
|
42
|
-
recommendation: `Inspect ${outputPath}. Remove it manually only if it is disposable validator or test ` +
|
|
43
|
-
'output, or choose a fresh output path, then render and approve a fresh plan.',
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
states.push({
|
|
48
|
-
outputPath,
|
|
49
|
-
repositoryRoot,
|
|
50
|
-
parentIdentities: captureExistingParentIdentities(outputPath, repositoryRoot),
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return states
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Removes outputs created by a command after revalidating every parent component.
|
|
59
|
-
*
|
|
60
|
-
* @param {{outputPath: string, repositoryRoot: string, parentIdentities: object[]}[]} states cleanup state
|
|
61
|
-
* @returns {object[]} customer-safe cleanup summary
|
|
62
|
-
*/
|
|
63
|
-
function cleanupCommandOutputs (states) {
|
|
64
|
-
const actions = []
|
|
65
|
-
for (let index = states.length - 1; index >= 0; index--) {
|
|
66
|
-
const state = states[index]
|
|
67
|
-
assertOutputParentsUnchanged(state)
|
|
68
|
-
const existed = fs.existsSync(state.outputPath)
|
|
69
|
-
if (existed) fs.rmSync(state.outputPath, { force: true, recursive: true })
|
|
70
|
-
actions.push({ outputPath: state.outputPath, action: existed ? 'removed' : 'absent' })
|
|
71
|
-
}
|
|
72
|
-
return actions.reverse()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Records every existing directory from repository.root through an output parent.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} outputPath output path
|
|
79
|
-
* @param {string} repositoryRoot repository root
|
|
80
|
-
* @returns {{path: string, dev: bigint, ino: bigint}[]} parent identities
|
|
81
|
-
*/
|
|
82
|
-
function captureExistingParentIdentities (outputPath, repositoryRoot) {
|
|
83
|
-
const identities = []
|
|
84
|
-
const relative = path.relative(repositoryRoot, path.dirname(outputPath))
|
|
85
|
-
let current = repositoryRoot
|
|
86
|
-
for (const segment of relative ? relative.split(path.sep) : []) {
|
|
87
|
-
const stat = fs.lstatSync(current, { bigint: true })
|
|
88
|
-
assertRegularDirectory(stat, current)
|
|
89
|
-
identities.push({ path: current, dev: stat.dev, ino: stat.ino })
|
|
90
|
-
current = path.join(current, segment)
|
|
91
|
-
if (!pathExists(current)) return identities
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const stat = fs.lstatSync(current, { bigint: true })
|
|
95
|
-
assertRegularDirectory(stat, current)
|
|
96
|
-
identities.push({ path: current, dev: stat.dev, ino: stat.ino })
|
|
97
|
-
return identities
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Refuses cleanup if an existing parent changed or a new parent is a symbolic link.
|
|
102
|
-
*
|
|
103
|
-
* @param {object} state cleanup state
|
|
104
|
-
*/
|
|
105
|
-
function assertOutputParentsUnchanged (state) {
|
|
106
|
-
for (const identity of state.parentIdentities) {
|
|
107
|
-
const stat = fs.lstatSync(identity.path, { bigint: true })
|
|
108
|
-
assertRegularDirectory(stat, identity.path)
|
|
109
|
-
if (stat.dev !== identity.dev || stat.ino !== identity.ino) {
|
|
110
|
-
throw new Error(`Refusing command output cleanup because a parent directory changed: ${identity.path}`)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const lastExisting = state.parentIdentities.at(-1).path
|
|
115
|
-
const relative = path.relative(lastExisting, path.dirname(state.outputPath))
|
|
116
|
-
let current = lastExisting
|
|
117
|
-
for (const segment of relative ? relative.split(path.sep) : []) {
|
|
118
|
-
current = path.join(current, segment)
|
|
119
|
-
if (!pathExists(current)) break
|
|
120
|
-
assertRegularDirectory(fs.lstatSync(current), current)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Refuses symbolic links and non-directory parent components.
|
|
126
|
-
*
|
|
127
|
-
* @param {fs.Stats | fs.BigIntStats} stat path status
|
|
128
|
-
* @param {string} directory directory path
|
|
129
|
-
*/
|
|
130
|
-
function assertRegularDirectory (stat, directory) {
|
|
131
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
132
|
-
throw new Error(`Refusing command output cleanup through a non-regular directory: ${directory}`)
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function pathExists (filename) {
|
|
137
|
-
try {
|
|
138
|
-
fs.lstatSync(filename)
|
|
139
|
-
return true
|
|
140
|
-
} catch (error) {
|
|
141
|
-
if (error.code === 'ENOENT') return false
|
|
142
|
-
throw error
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function assertSafeOutputPath ({ outputPath, repositoryRoot, artifactRoot, command }) {
|
|
147
|
-
const relative = path.relative(repositoryRoot, outputPath)
|
|
148
|
-
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
149
|
-
throw new Error(`Command output path must be a child of repository.root: ${outputPath}`)
|
|
150
|
-
}
|
|
151
|
-
assertPhysicalOutputPathInsideRepository(outputPath, repositoryRoot)
|
|
152
|
-
if (isPathInside(artifactRoot, outputPath) || isPathInside(outputPath, artifactRoot)) {
|
|
153
|
-
throw new Error(`Command output path must not contain or overlap validation artifacts: ${outputPath}`)
|
|
154
|
-
}
|
|
155
|
-
if (path.resolve(command.cwd) === outputPath) {
|
|
156
|
-
throw new Error(`Command output path must not replace the command working directory: ${outputPath}`)
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Rejects an output whose nearest existing ancestor resolves outside the repository.
|
|
162
|
-
*
|
|
163
|
-
* @param {string} outputPath absolute output path
|
|
164
|
-
* @param {string} repositoryRoot absolute repository root
|
|
165
|
-
*/
|
|
166
|
-
function assertPhysicalOutputPathInsideRepository (outputPath, repositoryRoot) {
|
|
167
|
-
const physicalRoot = fs.realpathSync(repositoryRoot)
|
|
168
|
-
let existingPath = outputPath
|
|
169
|
-
while (!fs.existsSync(existingPath) && path.dirname(existingPath) !== existingPath) {
|
|
170
|
-
existingPath = path.dirname(existingPath)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const physicalExistingPath = fs.realpathSync(existingPath)
|
|
174
|
-
if (!isPathInside(physicalRoot, physicalExistingPath)) {
|
|
175
|
-
throw new Error(`Command output path must not resolve outside physical repository.root: ${outputPath}`)
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function isPathInside (directory, filename) {
|
|
180
|
-
const relative = path.relative(path.resolve(directory), path.resolve(filename))
|
|
181
|
-
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
module.exports = {
|
|
185
|
-
cleanupCommandOutputs,
|
|
186
|
-
getCommandOutputPaths,
|
|
187
|
-
prepareCommandOutputs,
|
|
188
|
-
}
|