dd-trace 5.135.0 → 5.136.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,695 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const path = require('node:path')
|
|
4
|
-
|
|
5
|
-
const { getArtifactId } = require('./artifact-id')
|
|
6
|
-
const { BLOCKER_CATEGORY_VALUES } = require('./blocker-category')
|
|
7
|
-
const {
|
|
8
|
-
MAX_GENERATED_FILES,
|
|
9
|
-
getGeneratedFileContentError,
|
|
10
|
-
} = require('./generated-file-policy')
|
|
11
|
-
const { getGeneratedTestContractError } = require('./generated-test-contract')
|
|
12
|
-
const { hasUnsafeInvisibleCharacter, sanitizeString } = require('./redaction')
|
|
13
|
-
const {
|
|
14
|
-
getRunnerArgsError,
|
|
15
|
-
getRunnerEnvironmentError,
|
|
16
|
-
getRunnerInputError,
|
|
17
|
-
} = require('./runner-contract')
|
|
18
|
-
|
|
19
|
-
const FRAMEWORKS = new Set(['cucumber', 'cypress', 'jest', 'mocha', 'playwright', 'vitest'])
|
|
20
|
-
const STATUSES = new Set([
|
|
21
|
-
'detected_not_runnable',
|
|
22
|
-
'requires_manual_setup',
|
|
23
|
-
'runnable',
|
|
24
|
-
'unsupported_by_validator',
|
|
25
|
-
])
|
|
26
|
-
const INITIALIZATION_STATUSES = new Set(['configured', 'not_configured', 'unknown'])
|
|
27
|
-
const TRANSPORT_MODES = new Set(['agent', 'agentless', 'none', 'unknown'])
|
|
28
|
-
const GENERATED_SCENARIOS = new Set(['basic-pass', 'atr-fail-once', 'test-management-target'])
|
|
29
|
-
const GENERATED_EXIT_CODES = {
|
|
30
|
-
'basic-pass': 0,
|
|
31
|
-
'atr-fail-once': 1,
|
|
32
|
-
'test-management-target': 0,
|
|
33
|
-
}
|
|
34
|
-
const FORBIDDEN_EXECUTION_FIELDS = new Set([
|
|
35
|
-
'argv',
|
|
36
|
-
'existingTestCommand',
|
|
37
|
-
'forcedLocalCommand',
|
|
38
|
-
'isolationTestCandidate',
|
|
39
|
-
'isolationTestCandidates',
|
|
40
|
-
'localTestCandidates',
|
|
41
|
-
'runCommand',
|
|
42
|
-
'setup',
|
|
43
|
-
'shell',
|
|
44
|
-
'shellCommand',
|
|
45
|
-
'usesShell',
|
|
46
|
-
])
|
|
47
|
-
const ENV_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/
|
|
48
|
-
const SECRET_ENV_PATTERN =
|
|
49
|
-
/(?:^|_)(?:API_?KEY|AUTH(?:ORIZATION)?|CREDENTIALS?|PASS(?:WORD|WD)?|PRIVATE_?KEY|SECRET|TOKEN)(?:_|$)/i
|
|
50
|
-
const EXECUTION_ENV_PATTERN =
|
|
51
|
-
/^(?:(?:BASH_ENV|ENV|NODE_EXTRA_CA_CERTS|NODE_PATH|NODE_REPL_EXTERNAL_MODULE|NODE_TLS_REJECT_UNAUTHORIZED)$|LD_|DYLD_)/i
|
|
52
|
-
const MAX_ARRAY_ENTRIES = 1000
|
|
53
|
-
const MAX_FRAMEWORKS = 100
|
|
54
|
-
const MAX_STRING_BYTES = 256 * 1024
|
|
55
|
-
const MAX_TIMEOUT_MS = 30 * 60 * 1000
|
|
56
|
-
const MAX_VALIDATION_ERRORS = 50
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Validates a data-only Test Optimization manifest.
|
|
60
|
-
*
|
|
61
|
-
* @param {object} manifest parsed manifest
|
|
62
|
-
* @returns {string[]} bounded validation errors
|
|
63
|
-
*/
|
|
64
|
-
function validateManifest (manifest) {
|
|
65
|
-
const errors = createErrorCollector()
|
|
66
|
-
if (!isObject(manifest)) return ['Manifest must be a JSON object.']
|
|
67
|
-
|
|
68
|
-
requiredString(manifest, 'schemaVersion', 'manifest', errors)
|
|
69
|
-
if (manifest.schemaVersion !== '2.0') errors.push('schemaVersion must be "2.0".')
|
|
70
|
-
requiredObject(manifest, 'repository', 'manifest', errors)
|
|
71
|
-
requiredObject(manifest, 'environment', 'manifest', errors)
|
|
72
|
-
requiredArray(manifest, 'frameworks', 'manifest', errors)
|
|
73
|
-
rejectExecutionFields(manifest, 'manifest', errors)
|
|
74
|
-
|
|
75
|
-
if (isObject(manifest.repository)) {
|
|
76
|
-
requiredAbsolutePath(manifest.repository, 'root', 'repository', errors)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (Array.isArray(manifest.frameworks)) {
|
|
80
|
-
if (manifest.frameworks.length === 0) errors.push('frameworks must not be empty.')
|
|
81
|
-
if (manifest.frameworks.length > MAX_FRAMEWORKS) {
|
|
82
|
-
errors.push(`frameworks must contain at most ${MAX_FRAMEWORKS} entries.`)
|
|
83
|
-
}
|
|
84
|
-
validateFrameworks(manifest, errors)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
validateStringArray(manifest.omitted, 'omitted', errors)
|
|
88
|
-
validateAllStrings(manifest, 'manifest', errors)
|
|
89
|
-
return errors.finalize()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Validates framework entries and cross-framework uniqueness.
|
|
94
|
-
*
|
|
95
|
-
* @param {object} manifest validation manifest
|
|
96
|
-
* @param {{push: function(string): void, full: function(): boolean}} errors error collector
|
|
97
|
-
*/
|
|
98
|
-
function validateFrameworks (manifest, errors) {
|
|
99
|
-
const ids = new Set()
|
|
100
|
-
const artifactIds = new Set()
|
|
101
|
-
const generatedPaths = new Map()
|
|
102
|
-
|
|
103
|
-
for (const [index, framework] of manifest.frameworks.slice(0, MAX_FRAMEWORKS).entries()) {
|
|
104
|
-
if (errors.full()) return
|
|
105
|
-
const prefix = `frameworks[${index}]`
|
|
106
|
-
if (!isObject(framework)) {
|
|
107
|
-
errors.push(`${prefix} must be an object.`)
|
|
108
|
-
continue
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
requiredString(framework, 'id', prefix, errors)
|
|
112
|
-
requiredString(framework, 'framework', prefix, errors)
|
|
113
|
-
enumString(framework, 'status', STATUSES, prefix, errors)
|
|
114
|
-
if (framework.blockerCategory !== undefined &&
|
|
115
|
-
!BLOCKER_CATEGORY_VALUES.has(framework.blockerCategory)) {
|
|
116
|
-
errors.push(
|
|
117
|
-
`${prefix}.blockerCategory must be one of ${[...BLOCKER_CATEGORY_VALUES].join(', ')} when provided.`
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
requiredObject(framework, 'project', prefix, errors)
|
|
121
|
-
rejectExecutionFields(framework, prefix, errors)
|
|
122
|
-
|
|
123
|
-
if (typeof framework.framework === 'string' &&
|
|
124
|
-
framework.status !== 'unsupported_by_validator' &&
|
|
125
|
-
!FRAMEWORKS.has(framework.framework)) {
|
|
126
|
-
errors.push(`${prefix}.framework must be one of: ${[...FRAMEWORKS].join(', ')}.`)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (typeof framework.id === 'string') {
|
|
130
|
-
if (ids.has(framework.id)) errors.push(`${prefix}.id must be unique.`)
|
|
131
|
-
ids.add(framework.id)
|
|
132
|
-
const artifactId = getArtifactId(framework.id)
|
|
133
|
-
if (artifactIds.has(artifactId)) errors.push(`${prefix}.id collides after artifact normalization.`)
|
|
134
|
-
artifactIds.add(artifactId)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
validateProject(manifest.repository?.root, framework.project, `${prefix}.project`, errors)
|
|
138
|
-
validateCiWiring(manifest.repository?.root, framework.ciWiring, `${prefix}.ciWiring`, errors)
|
|
139
|
-
|
|
140
|
-
if (framework.status === 'runnable') {
|
|
141
|
-
if (typeof framework.allCandidatesRequireLocalSocket !== 'boolean') {
|
|
142
|
-
errors.push(`${prefix}.allCandidatesRequireLocalSocket must be a boolean.`)
|
|
143
|
-
}
|
|
144
|
-
if (typeof framework.buildArtifactRequired !== 'boolean') {
|
|
145
|
-
errors.push(`${prefix}.buildArtifactRequired must be a boolean.`)
|
|
146
|
-
}
|
|
147
|
-
validateRunnableFramework(manifest.repository?.root, framework, prefix, generatedPaths, errors)
|
|
148
|
-
} else {
|
|
149
|
-
for (const field of ['validation', 'preflight', 'generatedTestStrategy']) {
|
|
150
|
-
if (framework[field] !== undefined) {
|
|
151
|
-
errors.push(`${prefix}.${field} must be omitted when status is not runnable.`)
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
validateStringArray(framework.notes, `${prefix}.notes`, errors)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Validates project metadata.
|
|
161
|
-
*
|
|
162
|
-
* @param {string} repositoryRoot repository root
|
|
163
|
-
* @param {object} project project metadata
|
|
164
|
-
* @param {string} prefix error prefix
|
|
165
|
-
* @param {{push: function(string): void}} errors error collector
|
|
166
|
-
*/
|
|
167
|
-
function validateProject (repositoryRoot, project, prefix, errors) {
|
|
168
|
-
if (!isObject(project)) return
|
|
169
|
-
requiredString(project, 'name', prefix, errors)
|
|
170
|
-
requiredAbsolutePath(project, 'root', prefix, errors)
|
|
171
|
-
requiredAbsolutePath(project, 'packageJson', prefix, errors)
|
|
172
|
-
containedPath(repositoryRoot, project.root, `${prefix}.root`, errors)
|
|
173
|
-
containedPath(repositoryRoot, project.packageJson, `${prefix}.packageJson`, errors)
|
|
174
|
-
if (Array.isArray(project.configFiles)) {
|
|
175
|
-
if (project.configFiles.length > 20) errors.push(`${prefix}.configFiles must contain at most 20 entries.`)
|
|
176
|
-
for (const [index, filename] of project.configFiles.slice(0, 20).entries()) {
|
|
177
|
-
absolutePathValue(filename, `${prefix}.configFiles[${index}]`, errors)
|
|
178
|
-
containedPath(repositoryRoot, filename, `${prefix}.configFiles[${index}]`, errors)
|
|
179
|
-
}
|
|
180
|
-
} else {
|
|
181
|
-
errors.push(`${prefix}.configFiles must be an array.`)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Validates direct-runner fields and generated recipes.
|
|
187
|
-
*
|
|
188
|
-
* @param {string} repositoryRoot repository root
|
|
189
|
-
* @param {object} framework runnable framework entry
|
|
190
|
-
* @param {string} prefix error prefix
|
|
191
|
-
* @param {Map<string, string>} generatedPaths generated paths used by other frameworks
|
|
192
|
-
* @param {{push: function(string): void}} errors error collector
|
|
193
|
-
*/
|
|
194
|
-
function validateRunnableFramework (repositoryRoot, framework, prefix, generatedPaths, errors) {
|
|
195
|
-
if (!isObject(framework.validation)) {
|
|
196
|
-
errors.push(`${prefix}.validation must be an object for a runnable framework.`)
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const validation = framework.validation
|
|
201
|
-
rejectExecutionFields(validation, `${prefix}.validation`, errors)
|
|
202
|
-
requiredAbsolutePath(validation, 'runner', `${prefix}.validation`, errors)
|
|
203
|
-
requiredAbsolutePath(validation, 'testFile', `${prefix}.validation`, errors)
|
|
204
|
-
if (!['bounded_direct_runner', 'instrumented_event_identity'].includes(validation.selectorScope)) {
|
|
205
|
-
errors.push(
|
|
206
|
-
`${prefix}.validation.selectorScope must be bounded_direct_runner or instrumented_event_identity.`
|
|
207
|
-
)
|
|
208
|
-
}
|
|
209
|
-
containedPath(repositoryRoot, validation.runner, `${prefix}.validation.runner`, errors)
|
|
210
|
-
containedPath(repositoryRoot, validation.testFile, `${prefix}.validation.testFile`, errors)
|
|
211
|
-
validateFallbackTests(repositoryRoot, validation, `${prefix}.validation`, errors)
|
|
212
|
-
const runnerArgsError = getRunnerArgsError(framework.framework, validation.runnerArgs)
|
|
213
|
-
if (runnerArgsError) errors.push(`${prefix}.validation.runnerArgs ${runnerArgsError}.`)
|
|
214
|
-
if (validation.omittedRunnerOptions !== undefined) {
|
|
215
|
-
validateStringArray(validation.omittedRunnerOptions, `${prefix}.validation.omittedRunnerOptions`, errors)
|
|
216
|
-
for (const option of Array.isArray(validation.omittedRunnerOptions) ? validation.omittedRunnerOptions : []) {
|
|
217
|
-
if (!['-R', '--reporter', '--run', '--typecheck'].includes(option)) {
|
|
218
|
-
errors.push(`${prefix}.validation.omittedRunnerOptions contains unsupported option ${option}.`)
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const runnerEnvironmentError = getRunnerEnvironmentError(validation.environment)
|
|
223
|
-
if (runnerEnvironmentError) errors.push(`${prefix}.validation.environment ${runnerEnvironmentError}.`)
|
|
224
|
-
if (!runnerArgsError &&
|
|
225
|
-
!runnerEnvironmentError &&
|
|
226
|
-
typeof framework.project?.root === 'string' &&
|
|
227
|
-
typeof repositoryRoot === 'string' &&
|
|
228
|
-
Array.isArray(framework.project?.configFiles)) {
|
|
229
|
-
const runnerInputError = getRunnerInputError(
|
|
230
|
-
validation.runnerArgs,
|
|
231
|
-
validation.environment,
|
|
232
|
-
framework.project?.root,
|
|
233
|
-
repositoryRoot,
|
|
234
|
-
framework.project?.configFiles
|
|
235
|
-
)
|
|
236
|
-
if (runnerInputError) errors.push(`${prefix}.validation runner configuration ${runnerInputError}.`)
|
|
237
|
-
}
|
|
238
|
-
validateStringArray(validation.requiredEnvVars, `${prefix}.validation.requiredEnvVars`, errors)
|
|
239
|
-
if (validation.requiredEnvVars) {
|
|
240
|
-
for (const name of validation.requiredEnvVars) {
|
|
241
|
-
if (!ENV_NAME_PATTERN.test(name)) {
|
|
242
|
-
errors.push(`${prefix}.validation.requiredEnvVars contains an invalid environment name.`)
|
|
243
|
-
}
|
|
244
|
-
if (/^(?:DD_|DATADOG_|OTEL_|NODE_OPTIONS$|TS_NODE_PROJECT$)/i.test(name)) {
|
|
245
|
-
errors.push(
|
|
246
|
-
`${prefix}.validation.requiredEnvVars must not inherit Datadog, OpenTelemetry, NODE_OPTIONS, or ` +
|
|
247
|
-
'TS_NODE_PROJECT.'
|
|
248
|
-
)
|
|
249
|
-
}
|
|
250
|
-
if (SECRET_ENV_PATTERN.test(name)) {
|
|
251
|
-
errors.push(`${prefix}.validation.requiredEnvVars must not inherit secret-like environment variables.`)
|
|
252
|
-
}
|
|
253
|
-
if (EXECUTION_ENV_PATTERN.test(name)) {
|
|
254
|
-
errors.push(`${prefix}.validation.requiredEnvVars must not inherit executable-loading environment variables.`)
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (!Number.isInteger(validation.timeoutMs) || validation.timeoutMs < 1 || validation.timeoutMs > MAX_TIMEOUT_MS) {
|
|
259
|
-
errors.push(`${prefix}.validation.timeoutMs must be an integer between 1 and ${MAX_TIMEOUT_MS}.`)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (!isObject(framework.generatedTestStrategy)) {
|
|
263
|
-
errors.push(`${prefix}.generatedTestStrategy must be an object for a runnable framework.`)
|
|
264
|
-
return
|
|
265
|
-
}
|
|
266
|
-
validateGeneratedStrategy(repositoryRoot, framework, prefix, generatedPaths, errors)
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Validates bounded fallback test paths and their statically discovered prerequisites.
|
|
271
|
-
*
|
|
272
|
-
* @param {string} repositoryRoot repository root
|
|
273
|
-
* @param {object} validation direct-runner validation data
|
|
274
|
-
* @param {string} prefix error prefix
|
|
275
|
-
* @param {{push: function(string): void}} errors error collector
|
|
276
|
-
*/
|
|
277
|
-
function validateFallbackTests (repositoryRoot, validation, prefix, errors) {
|
|
278
|
-
if (validation.fallbackTests === undefined) return
|
|
279
|
-
if (!Array.isArray(validation.fallbackTests)) {
|
|
280
|
-
errors.push(`${prefix}.fallbackTests must be an array.`)
|
|
281
|
-
return
|
|
282
|
-
}
|
|
283
|
-
if (validation.fallbackTests.length > 2) {
|
|
284
|
-
errors.push(`${prefix}.fallbackTests must contain at most 2 entries.`)
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const testFiles = new Set()
|
|
288
|
-
for (const [index, fallback] of validation.fallbackTests.slice(0, 2).entries()) {
|
|
289
|
-
const fallbackPrefix = `${prefix}.fallbackTests[${index}]`
|
|
290
|
-
if (!isObject(fallback)) {
|
|
291
|
-
errors.push(`${fallbackPrefix} must be an object.`)
|
|
292
|
-
continue
|
|
293
|
-
}
|
|
294
|
-
rejectExecutionFields(fallback, fallbackPrefix, errors)
|
|
295
|
-
requiredAbsolutePath(fallback, 'testFile', fallbackPrefix, errors)
|
|
296
|
-
containedPath(repositoryRoot, fallback.testFile, `${fallbackPrefix}.testFile`, errors)
|
|
297
|
-
if (typeof fallback.buildArtifactRequired !== 'boolean') {
|
|
298
|
-
errors.push(`${fallbackPrefix}.buildArtifactRequired must be a boolean.`)
|
|
299
|
-
}
|
|
300
|
-
if (typeof fallback.localSocketRequired !== 'boolean') {
|
|
301
|
-
errors.push(`${fallbackPrefix}.localSocketRequired must be a boolean.`)
|
|
302
|
-
}
|
|
303
|
-
if (fallback.testFile === validation.testFile) {
|
|
304
|
-
errors.push(`${fallbackPrefix}.testFile must differ from ${prefix}.testFile.`)
|
|
305
|
-
}
|
|
306
|
-
if (testFiles.has(fallback.testFile)) {
|
|
307
|
-
errors.push(`${prefix}.fallbackTests must contain unique testFile values.`)
|
|
308
|
-
}
|
|
309
|
-
testFiles.add(fallback.testFile)
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Validates canonical generated test data.
|
|
315
|
-
*
|
|
316
|
-
* @param {string} repositoryRoot repository root
|
|
317
|
-
* @param {object} framework framework entry
|
|
318
|
-
* @param {string} prefix framework error prefix
|
|
319
|
-
* @param {Map<string, string>} generatedPaths generated paths used by other frameworks
|
|
320
|
-
* @param {{push: function(string): void}} errors error collector
|
|
321
|
-
*/
|
|
322
|
-
function validateGeneratedStrategy (repositoryRoot, framework, prefix, generatedPaths, errors) {
|
|
323
|
-
const strategy = framework.generatedTestStrategy
|
|
324
|
-
if (!['planned', 'verified', 'not_possible'].includes(strategy.status)) {
|
|
325
|
-
errors.push(`${prefix}.generatedTestStrategy.status must be planned, verified, or not_possible.`)
|
|
326
|
-
}
|
|
327
|
-
if (strategy.status === 'not_possible') {
|
|
328
|
-
requiredString(strategy, 'reason', `${prefix}.generatedTestStrategy`, errors)
|
|
329
|
-
return
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
requiredAbsolutePath(strategy, 'testDirectory', `${prefix}.generatedTestStrategy`, errors)
|
|
333
|
-
containedPath(repositoryRoot, strategy.testDirectory, `${prefix}.generatedTestStrategy.testDirectory`, errors)
|
|
334
|
-
requiredArray(strategy, 'files', `${prefix}.generatedTestStrategy`, errors)
|
|
335
|
-
requiredArray(strategy, 'scenarios', `${prefix}.generatedTestStrategy`, errors)
|
|
336
|
-
requiredArray(strategy, 'cleanupPaths', `${prefix}.generatedTestStrategy`, errors)
|
|
337
|
-
|
|
338
|
-
if (Array.isArray(strategy.files)) {
|
|
339
|
-
if (strategy.files.length > MAX_GENERATED_FILES) {
|
|
340
|
-
errors.push(`${prefix}.generatedTestStrategy.files must contain at most ${MAX_GENERATED_FILES} entries.`)
|
|
341
|
-
}
|
|
342
|
-
for (const [index, file] of strategy.files.slice(0, MAX_GENERATED_FILES).entries()) {
|
|
343
|
-
const filePrefix = `${prefix}.generatedTestStrategy.files[${index}]`
|
|
344
|
-
if (!isObject(file)) {
|
|
345
|
-
errors.push(`${filePrefix} must be an object.`)
|
|
346
|
-
continue
|
|
347
|
-
}
|
|
348
|
-
requiredAbsolutePath(file, 'path', filePrefix, errors)
|
|
349
|
-
validateStringArray(file.contentLines, `${filePrefix}.contentLines`, errors)
|
|
350
|
-
containedPath(repositoryRoot, file.path, `${filePrefix}.path`, errors)
|
|
351
|
-
const policyError = getGeneratedFileContentError(file.contentLines)
|
|
352
|
-
if (policyError) errors.push(`${filePrefix}.contentLines ${policyError}.`)
|
|
353
|
-
claimGeneratedPath(file.path, framework.id, filePrefix, generatedPaths, errors)
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if (Array.isArray(strategy.cleanupPaths)) {
|
|
358
|
-
for (const [index, filename] of strategy.cleanupPaths.slice(0, MAX_ARRAY_ENTRIES).entries()) {
|
|
359
|
-
const pathPrefix = `${prefix}.generatedTestStrategy.cleanupPaths[${index}]`
|
|
360
|
-
absolutePathValue(filename, pathPrefix, errors)
|
|
361
|
-
containedPath(repositoryRoot, filename, pathPrefix, errors)
|
|
362
|
-
claimGeneratedPath(filename, framework.id, pathPrefix, generatedPaths, errors)
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (Array.isArray(strategy.scenarios)) {
|
|
367
|
-
if (strategy.scenarios.length !== GENERATED_SCENARIOS.size) {
|
|
368
|
-
errors.push(`${prefix}.generatedTestStrategy.scenarios must contain all three canonical scenarios.`)
|
|
369
|
-
}
|
|
370
|
-
const scenarioIds = new Set()
|
|
371
|
-
for (const [index, scenario] of strategy.scenarios.slice(0, GENERATED_SCENARIOS.size).entries()) {
|
|
372
|
-
const scenarioPrefix = `${prefix}.generatedTestStrategy.scenarios[${index}]`
|
|
373
|
-
if (!isObject(scenario)) {
|
|
374
|
-
errors.push(`${scenarioPrefix} must be an object.`)
|
|
375
|
-
continue
|
|
376
|
-
}
|
|
377
|
-
enumString(scenario, 'id', GENERATED_SCENARIOS, scenarioPrefix, errors)
|
|
378
|
-
rejectExecutionFields(scenario, scenarioPrefix, errors)
|
|
379
|
-
scenarioIds.add(scenario.id)
|
|
380
|
-
validateScenarioIdentity(repositoryRoot, scenario, scenarioPrefix, errors)
|
|
381
|
-
const expected = scenario.expectedWithoutDatadog
|
|
382
|
-
if (!isObject(expected) ||
|
|
383
|
-
expected.exitCode !== GENERATED_EXIT_CODES[scenario.id] ||
|
|
384
|
-
expected.observedTestCount !== 1) {
|
|
385
|
-
errors.push(`${scenarioPrefix}.expectedWithoutDatadog must retain the canonical exit code and one test.`)
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
for (const id of GENERATED_SCENARIOS) {
|
|
389
|
-
if (!scenarioIds.has(id)) errors.push(`${prefix}.generatedTestStrategy.scenarios is missing ${id}.`)
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const contractError = getGeneratedTestContractError(framework)
|
|
394
|
-
if (contractError) errors.push(`${prefix}.generatedTestStrategy ${contractError}`)
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Validates one generated test identity.
|
|
399
|
-
*
|
|
400
|
-
* @param {string} repositoryRoot repository root
|
|
401
|
-
* @param {object} scenario generated scenario
|
|
402
|
-
* @param {string} prefix error prefix
|
|
403
|
-
* @param {{push: function(string): void}} errors error collector
|
|
404
|
-
*/
|
|
405
|
-
function validateScenarioIdentity (repositoryRoot, scenario, prefix, errors) {
|
|
406
|
-
if (!Array.isArray(scenario.testIdentities) || scenario.testIdentities.length !== 1) {
|
|
407
|
-
errors.push(`${prefix}.testIdentities must contain exactly one identity.`)
|
|
408
|
-
return
|
|
409
|
-
}
|
|
410
|
-
const identity = scenario.testIdentities[0]
|
|
411
|
-
if (!isObject(identity)) {
|
|
412
|
-
errors.push(`${prefix}.testIdentities[0] must be an object.`)
|
|
413
|
-
return
|
|
414
|
-
}
|
|
415
|
-
requiredAbsolutePath(identity, 'file', `${prefix}.testIdentities[0]`, errors)
|
|
416
|
-
requiredString(identity, 'name', `${prefix}.testIdentities[0]`, errors)
|
|
417
|
-
requiredString(identity, 'suite', `${prefix}.testIdentities[0]`, errors)
|
|
418
|
-
containedPath(repositoryRoot, identity.file, `${prefix}.testIdentities[0].file`, errors)
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Validates inert CI evidence.
|
|
423
|
-
*
|
|
424
|
-
* @param {string} repositoryRoot repository root
|
|
425
|
-
* @param {object|undefined} ciWiring CI evidence
|
|
426
|
-
* @param {string} prefix error prefix
|
|
427
|
-
* @param {{push: function(string): void}} errors error collector
|
|
428
|
-
*/
|
|
429
|
-
function validateCiWiring (repositoryRoot, ciWiring, prefix, errors) {
|
|
430
|
-
if (ciWiring === undefined) return
|
|
431
|
-
if (!isObject(ciWiring)) {
|
|
432
|
-
errors.push(`${prefix} must be an object.`)
|
|
433
|
-
return
|
|
434
|
-
}
|
|
435
|
-
rejectExecutionFields(ciWiring, prefix, errors, new Set(['command']))
|
|
436
|
-
for (const field of ['command', 'job', 'step']) optionalStringOrNull(ciWiring, field, prefix, errors)
|
|
437
|
-
optionalAbsolutePathOrNull(ciWiring, 'configFile', prefix, errors)
|
|
438
|
-
optionalAbsolutePathOrNull(ciWiring, 'workingDirectory', prefix, errors)
|
|
439
|
-
containedPath(repositoryRoot, ciWiring.configFile, `${prefix}.configFile`, errors)
|
|
440
|
-
containedPath(repositoryRoot, ciWiring.workingDirectory, `${prefix}.workingDirectory`, errors)
|
|
441
|
-
if (typeof ciWiring.reviewComplete !== 'boolean') errors.push(`${prefix}.reviewComplete must be a boolean.`)
|
|
442
|
-
validateStringArray(ciWiring.unresolved, `${prefix}.unresolved`, errors)
|
|
443
|
-
|
|
444
|
-
if (isObject(ciWiring.initialization) && INITIALIZATION_STATUSES.has(ciWiring.initialization.status)) {
|
|
445
|
-
validateStringArray(ciWiring.initialization.evidence, `${prefix}.initialization.evidence`, errors)
|
|
446
|
-
} else {
|
|
447
|
-
errors.push(`${prefix}.initialization.status must be configured, not_configured, or unknown.`)
|
|
448
|
-
}
|
|
449
|
-
if (isObject(ciWiring.transport) && TRANSPORT_MODES.has(ciWiring.transport.mode)) {
|
|
450
|
-
validateStringArray(ciWiring.transport.evidence, `${prefix}.transport.evidence`, errors)
|
|
451
|
-
} else {
|
|
452
|
-
errors.push(`${prefix}.transport.mode must be agent, agentless, none, or unknown.`)
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Rejects execution-shaped keys anywhere in a data object.
|
|
458
|
-
*
|
|
459
|
-
* @param {object} value object to inspect
|
|
460
|
-
* @param {string} prefix error prefix
|
|
461
|
-
* @param {{push: function(string): void}} errors error collector
|
|
462
|
-
* @param {Set<string>} [allowed] explicitly inert keys
|
|
463
|
-
*/
|
|
464
|
-
function rejectExecutionFields (value, prefix, errors, allowed = new Set()) {
|
|
465
|
-
if (!isObject(value)) return
|
|
466
|
-
for (const key of Object.keys(value)) {
|
|
467
|
-
if (FORBIDDEN_EXECUTION_FIELDS.has(key) && !allowed.has(key)) {
|
|
468
|
-
errors.push(`${prefix}.${key} is not supported. Executable commands are validator-owned.`)
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Claims a generated path for one framework.
|
|
475
|
-
*
|
|
476
|
-
* @param {string} filename generated path
|
|
477
|
-
* @param {string} owner framework id
|
|
478
|
-
* @param {string} prefix error prefix
|
|
479
|
-
* @param {Map<string, string>} generatedPaths previously claimed paths
|
|
480
|
-
* @param {{push: function(string): void}} errors error collector
|
|
481
|
-
*/
|
|
482
|
-
function claimGeneratedPath (filename, owner, prefix, generatedPaths, errors) {
|
|
483
|
-
if (typeof filename !== 'string' || !path.isAbsolute(filename)) return
|
|
484
|
-
const normalized = path.normalize(filename)
|
|
485
|
-
const previousOwner = generatedPaths.get(normalized)
|
|
486
|
-
if (previousOwner !== undefined && previousOwner !== owner) {
|
|
487
|
-
errors.push(`${prefix} conflicts with another framework's generated or cleanup path.`)
|
|
488
|
-
}
|
|
489
|
-
generatedPaths.set(normalized, owner)
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Validates every string in a bounded object graph.
|
|
494
|
-
*
|
|
495
|
-
* @param {unknown} value current value
|
|
496
|
-
* @param {string} prefix error prefix
|
|
497
|
-
* @param {{push: function(string): void, full: function(): boolean}} errors error collector
|
|
498
|
-
*/
|
|
499
|
-
function validateAllStrings (value, prefix, errors) {
|
|
500
|
-
if (errors.full()) return
|
|
501
|
-
if (typeof value === 'string') {
|
|
502
|
-
if (Buffer.byteLength(value) > MAX_STRING_BYTES) errors.push(`${prefix} exceeds the string size limit.`)
|
|
503
|
-
const inertCiLabel = /\.ciWiring\.(?:job|step)$/.test(prefix)
|
|
504
|
-
const text = inertCiLabel ? value.replaceAll(/[\uFE0E\uFE0F]/g, '') : value
|
|
505
|
-
if (hasUnsafeInvisibleCharacter(text)) errors.push(`${prefix} contains an unsafe invisible character.`)
|
|
506
|
-
return
|
|
507
|
-
}
|
|
508
|
-
if (Array.isArray(value)) {
|
|
509
|
-
for (const [index, item] of value.slice(0, MAX_ARRAY_ENTRIES).entries()) {
|
|
510
|
-
validateAllStrings(item, `${prefix}[${index}]`, errors)
|
|
511
|
-
}
|
|
512
|
-
return
|
|
513
|
-
}
|
|
514
|
-
if (isObject(value)) {
|
|
515
|
-
for (const [key, item] of Object.entries(value)) validateAllStrings(item, `${prefix}.${key}`, errors)
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Validates a required object.
|
|
521
|
-
*
|
|
522
|
-
* @param {object} object parent object
|
|
523
|
-
* @param {string} field field name
|
|
524
|
-
* @param {string} prefix error prefix
|
|
525
|
-
* @param {{push: function(string): void}} errors error collector
|
|
526
|
-
*/
|
|
527
|
-
function requiredObject (object, field, prefix, errors) {
|
|
528
|
-
if (!isObject(object[field])) errors.push(`${prefix}.${field} must be an object.`)
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
/**
|
|
532
|
-
* Validates a required array.
|
|
533
|
-
*
|
|
534
|
-
* @param {object} object parent object
|
|
535
|
-
* @param {string} field field name
|
|
536
|
-
* @param {string} prefix error prefix
|
|
537
|
-
* @param {{push: function(string): void}} errors error collector
|
|
538
|
-
*/
|
|
539
|
-
function requiredArray (object, field, prefix, errors) {
|
|
540
|
-
if (!Array.isArray(object[field])) errors.push(`${prefix}.${field} must be an array.`)
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Validates a required string.
|
|
545
|
-
*
|
|
546
|
-
* @param {object} object parent object
|
|
547
|
-
* @param {string} field field name
|
|
548
|
-
* @param {string} prefix error prefix
|
|
549
|
-
* @param {{push: function(string): void}} errors error collector
|
|
550
|
-
*/
|
|
551
|
-
function requiredString (object, field, prefix, errors) {
|
|
552
|
-
if (typeof object?.[field] !== 'string' || object[field].trim() === '') {
|
|
553
|
-
errors.push(`${prefix}.${field} must be a non-empty string.`)
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
/**
|
|
558
|
-
* Validates an enum string.
|
|
559
|
-
*
|
|
560
|
-
* @param {object} object parent object
|
|
561
|
-
* @param {string} field field name
|
|
562
|
-
* @param {Set<string>} values accepted values
|
|
563
|
-
* @param {string} prefix error prefix
|
|
564
|
-
* @param {{push: function(string): void}} errors error collector
|
|
565
|
-
*/
|
|
566
|
-
function enumString (object, field, values, prefix, errors) {
|
|
567
|
-
if (!values.has(object?.[field])) {
|
|
568
|
-
errors.push(`${prefix}.${field} must be one of: ${[...values].join(', ')}.`)
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Validates a required absolute path.
|
|
574
|
-
*
|
|
575
|
-
* @param {object} object parent object
|
|
576
|
-
* @param {string} field field name
|
|
577
|
-
* @param {string} prefix error prefix
|
|
578
|
-
* @param {{push: function(string): void}} errors error collector
|
|
579
|
-
*/
|
|
580
|
-
function requiredAbsolutePath (object, field, prefix, errors) {
|
|
581
|
-
absolutePathValue(object?.[field], `${prefix}.${field}`, errors)
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Validates an absolute path value.
|
|
586
|
-
*
|
|
587
|
-
* @param {unknown} value path value
|
|
588
|
-
* @param {string} prefix error prefix
|
|
589
|
-
* @param {{push: function(string): void}} errors error collector
|
|
590
|
-
*/
|
|
591
|
-
function absolutePathValue (value, prefix, errors) {
|
|
592
|
-
if (typeof value !== 'string' || !path.isAbsolute(value)) errors.push(`${prefix} must be an absolute path.`)
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Validates an optional nullable absolute path.
|
|
597
|
-
*
|
|
598
|
-
* @param {object} object parent object
|
|
599
|
-
* @param {string} field field name
|
|
600
|
-
* @param {string} prefix error prefix
|
|
601
|
-
* @param {{push: function(string): void}} errors error collector
|
|
602
|
-
*/
|
|
603
|
-
function optionalAbsolutePathOrNull (object, field, prefix, errors) {
|
|
604
|
-
if (object[field] !== null && object[field] !== undefined &&
|
|
605
|
-
(typeof object[field] !== 'string' || !path.isAbsolute(object[field]))) {
|
|
606
|
-
errors.push(`${prefix}.${field} must be an absolute path or null.`)
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Validates an optional nullable string.
|
|
612
|
-
*
|
|
613
|
-
* @param {object} object parent object
|
|
614
|
-
* @param {string} field field name
|
|
615
|
-
* @param {string} prefix error prefix
|
|
616
|
-
* @param {{push: function(string): void}} errors error collector
|
|
617
|
-
*/
|
|
618
|
-
function optionalStringOrNull (object, field, prefix, errors) {
|
|
619
|
-
if (object[field] !== null && object[field] !== undefined && typeof object[field] !== 'string') {
|
|
620
|
-
errors.push(`${prefix}.${field} must be a string or null.`)
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Validates a string array when present.
|
|
626
|
-
*
|
|
627
|
-
* @param {unknown} value array value
|
|
628
|
-
* @param {string} prefix error prefix
|
|
629
|
-
* @param {{push: function(string): void}} errors error collector
|
|
630
|
-
*/
|
|
631
|
-
function validateStringArray (value, prefix, errors) {
|
|
632
|
-
if (value === undefined) return
|
|
633
|
-
if (!Array.isArray(value)) {
|
|
634
|
-
errors.push(`${prefix} must be an array of strings.`)
|
|
635
|
-
return
|
|
636
|
-
}
|
|
637
|
-
if (value.length > MAX_ARRAY_ENTRIES) errors.push(`${prefix} must contain at most ${MAX_ARRAY_ENTRIES} entries.`)
|
|
638
|
-
if (value.slice(0, MAX_ARRAY_ENTRIES).some(item => typeof item !== 'string')) {
|
|
639
|
-
errors.push(`${prefix} must contain only strings.`)
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* Checks lexical repository containment.
|
|
645
|
-
*
|
|
646
|
-
* @param {string} root repository root
|
|
647
|
-
* @param {unknown} filename candidate path
|
|
648
|
-
* @param {string} prefix error prefix
|
|
649
|
-
* @param {{push: function(string): void}} errors error collector
|
|
650
|
-
*/
|
|
651
|
-
function containedPath (root, filename, prefix, errors) {
|
|
652
|
-
if (typeof root !== 'string' || !path.isAbsolute(root) ||
|
|
653
|
-
typeof filename !== 'string' || !path.isAbsolute(filename)) return
|
|
654
|
-
const relative = path.relative(path.resolve(root), path.resolve(filename))
|
|
655
|
-
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
656
|
-
errors.push(`${prefix} must be inside repository.root.`)
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
/**
|
|
661
|
-
* Returns whether a value is a plain object.
|
|
662
|
-
*
|
|
663
|
-
* @param {unknown} value candidate value
|
|
664
|
-
*/
|
|
665
|
-
function isObject (value) {
|
|
666
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* Creates a bounded error collector.
|
|
671
|
-
*
|
|
672
|
-
* @returns {{push: function(string): void, full: function(): boolean, finalize: function(): string[]}} collector
|
|
673
|
-
*/
|
|
674
|
-
function createErrorCollector () {
|
|
675
|
-
const errors = []
|
|
676
|
-
let omitted = false
|
|
677
|
-
return {
|
|
678
|
-
push (message) {
|
|
679
|
-
if (errors.length < MAX_VALIDATION_ERRORS) {
|
|
680
|
-
errors.push(sanitizeString(message))
|
|
681
|
-
} else {
|
|
682
|
-
omitted = true
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
|
-
full () {
|
|
686
|
-
return errors.length >= MAX_VALIDATION_ERRORS
|
|
687
|
-
},
|
|
688
|
-
finalize () {
|
|
689
|
-
if (omitted) errors.push('Additional validation errors were omitted.')
|
|
690
|
-
return errors
|
|
691
|
-
},
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
module.exports = { validateManifest }
|