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,368 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const crypto = require('node:crypto')
|
|
4
|
-
const fs = require('node:fs')
|
|
5
|
-
const path = require('node:path')
|
|
6
|
-
|
|
7
|
-
const { MAX_OUTPUT_BYTES, msgpackToJson } = require('./msgpack-to-json')
|
|
8
|
-
const { projectTestCyclePayload } = require('./payload-projection')
|
|
9
|
-
|
|
10
|
-
const MAX_OUTPUT_FILES = 10_000
|
|
11
|
-
const MAX_SAMPLED_TESTS = 8
|
|
12
|
-
const MAX_SUMMARY_ERRORS = 20
|
|
13
|
-
const SUMMARY_PREFIX = 'DD_TEST_OPTIMIZATION_VALIDATION_V1 '
|
|
14
|
-
|
|
15
|
-
let payloadFileSequence = 0
|
|
16
|
-
|
|
17
|
-
class CiValidationSink {
|
|
18
|
-
#bytesWritten = 0
|
|
19
|
-
#captureMode
|
|
20
|
-
#completionDirectory
|
|
21
|
-
#errors = []
|
|
22
|
-
#eventsObserved = 0
|
|
23
|
-
#eventsRetained = 0
|
|
24
|
-
#fileCount = 0
|
|
25
|
-
#inputs = Object.create(null)
|
|
26
|
-
#outputRoot
|
|
27
|
-
#outputRootDirectory
|
|
28
|
-
#payloadsDirectory
|
|
29
|
-
#processId = crypto.randomBytes(16).toString('hex')
|
|
30
|
-
#sampledLifecycle = new Map()
|
|
31
|
-
#sampledTests = []
|
|
32
|
-
#summaryWritten = false
|
|
33
|
-
#testsDirectory
|
|
34
|
-
#testsObserved = 0
|
|
35
|
-
#testPayloadFileCount = 0
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Creates a bounded payload-file sink under a validator-owned output root.
|
|
39
|
-
*
|
|
40
|
-
* @param {string} outputRoot absolute validator-owned output directory
|
|
41
|
-
* @param {object} [options] sink options
|
|
42
|
-
* @param {'sample'|'strict'} [options.captureMode] evidence retention mode
|
|
43
|
-
*/
|
|
44
|
-
constructor (outputRoot, { captureMode = 'strict' } = {}) {
|
|
45
|
-
if (typeof outputRoot !== 'string' || !path.isAbsolute(outputRoot)) {
|
|
46
|
-
throw new Error('Offline Test Optimization validation output root must be absolute.')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!['sample', 'strict'].includes(captureMode)) {
|
|
50
|
-
throw new Error('Offline Test Optimization validation capture mode is invalid.')
|
|
51
|
-
}
|
|
52
|
-
this.#captureMode = captureMode
|
|
53
|
-
this.#outputRoot = outputRoot
|
|
54
|
-
this.#outputRootDirectory = captureDirectory(outputRoot, 'output root')
|
|
55
|
-
const payloadsRoot = path.join(outputRoot, 'payloads')
|
|
56
|
-
this.#payloadsDirectory = createDirectory(outputRoot, this.#outputRootDirectory, payloadsRoot, 'payloads')
|
|
57
|
-
this.#testsDirectory = createDirectory(
|
|
58
|
-
payloadsRoot,
|
|
59
|
-
this.#payloadsDirectory,
|
|
60
|
-
path.join(payloadsRoot, 'tests'),
|
|
61
|
-
'tests'
|
|
62
|
-
)
|
|
63
|
-
this.#completionDirectory = createDirectory(
|
|
64
|
-
outputRoot,
|
|
65
|
-
this.#outputRootDirectory,
|
|
66
|
-
path.join(outputRoot, 'completions'),
|
|
67
|
-
'completions'
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Converts and writes one Test Optimization payload using the Bazel-compatible JSON layout.
|
|
73
|
-
*
|
|
74
|
-
* @param {Buffer} payload encoded Test Optimization payload
|
|
75
|
-
*/
|
|
76
|
-
writeTestCycle (payload) {
|
|
77
|
-
let decoded
|
|
78
|
-
try {
|
|
79
|
-
decoded = JSON.parse(msgpackToJson(payload).toString('utf8'))
|
|
80
|
-
} catch {
|
|
81
|
-
this.#fail('output_payload_decode_failed')
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let projected
|
|
86
|
-
try {
|
|
87
|
-
projected = projectTestCyclePayload(decoded)
|
|
88
|
-
} catch {
|
|
89
|
-
this.#fail('output_payload_projection_failed')
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
this.#eventsObserved += projected.events.length
|
|
94
|
-
if (this.#captureMode === 'sample') {
|
|
95
|
-
this.#retainSample(projected.events)
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const json = Buffer.from(JSON.stringify(projected))
|
|
100
|
-
if (this.#writePayloadFile(json)) {
|
|
101
|
-
this.#eventsRetained += projected.events.length
|
|
102
|
-
this.#testPayloadFileCount++
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Records whether a control-plane fixture was loaded from the filesystem cache.
|
|
108
|
-
*
|
|
109
|
-
* @param {string} name fixed fixture name
|
|
110
|
-
* @param {Error|undefined|null} error cache-load error
|
|
111
|
-
*/
|
|
112
|
-
writeInputResult (name, error) {
|
|
113
|
-
if (error) this.#addError(`invalid_${name}`)
|
|
114
|
-
this.#inputs[name] = { status: error ? 'error' : 'loaded' }
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Records an exporter failure in the bounded validation summary.
|
|
119
|
-
*
|
|
120
|
-
* @param {string} code stable failure code
|
|
121
|
-
*/
|
|
122
|
-
recordError (code) {
|
|
123
|
-
this.#fail(code)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Emits this process's single bounded stderr summary for validator aggregation.
|
|
128
|
-
*/
|
|
129
|
-
writeSummary () {
|
|
130
|
-
if (this.#summaryWritten) return
|
|
131
|
-
this.#summaryWritten = true
|
|
132
|
-
if (this.#captureMode === 'sample') this.#writeSampledEvents()
|
|
133
|
-
const summary = {
|
|
134
|
-
events: this.#eventsRetained,
|
|
135
|
-
payloadFiles: this.#testPayloadFileCount,
|
|
136
|
-
input: 'filesystem-cache',
|
|
137
|
-
inputs: this.#inputs,
|
|
138
|
-
errors: this.#errors,
|
|
139
|
-
}
|
|
140
|
-
if (!this.#writeCompletionRecord()) this.#fail('completion_write_failed')
|
|
141
|
-
process.stderr.write(`${SUMMARY_PREFIX}${JSON.stringify(summary)}\n`)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Retains bounded first/late test evidence and the latest lifecycle event of each type.
|
|
146
|
-
*
|
|
147
|
-
* @param {object[]} events projected events
|
|
148
|
-
*/
|
|
149
|
-
#retainSample (events) {
|
|
150
|
-
for (const event of events) {
|
|
151
|
-
if (event.type !== 'test') {
|
|
152
|
-
this.#sampledLifecycle.set(event.type, event)
|
|
153
|
-
continue
|
|
154
|
-
}
|
|
155
|
-
this.#testsObserved++
|
|
156
|
-
if (this.#sampledTests.length < MAX_SAMPLED_TESTS) {
|
|
157
|
-
this.#sampledTests.push(event)
|
|
158
|
-
} else {
|
|
159
|
-
const lateIndex = Math.floor(MAX_SAMPLED_TESTS / 2) +
|
|
160
|
-
(this.#testsObserved % Math.ceil(MAX_SAMPLED_TESTS / 2))
|
|
161
|
-
this.#sampledTests[lateIndex] = event
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Persists the final bounded CI-replay sample after all process-local events have been observed.
|
|
168
|
-
*/
|
|
169
|
-
#writeSampledEvents () {
|
|
170
|
-
const events = [...this.#sampledTests, ...this.#sampledLifecycle.values()]
|
|
171
|
-
if (events.length === 0) return
|
|
172
|
-
const payload = Buffer.from(JSON.stringify({ version: 1, events }))
|
|
173
|
-
if (this.#writePayloadFile(payload)) {
|
|
174
|
-
this.#eventsRetained = events.length
|
|
175
|
-
this.#testPayloadFileCount++
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Atomically publishes this process's bounded completion evidence.
|
|
181
|
-
*
|
|
182
|
-
*/
|
|
183
|
-
#writeCompletionRecord () {
|
|
184
|
-
const directoryPath = path.join(this.#outputRoot, 'completions')
|
|
185
|
-
const filename = path.join(directoryPath, `completion-${this.#processId}.json`)
|
|
186
|
-
const temporary = `${filename}.tmp`
|
|
187
|
-
const completion = Buffer.from(JSON.stringify({
|
|
188
|
-
version: 1,
|
|
189
|
-
processId: this.#processId,
|
|
190
|
-
captureMode: this.#captureMode,
|
|
191
|
-
counts: {
|
|
192
|
-
eventsObserved: this.#eventsObserved,
|
|
193
|
-
eventsRetained: this.#eventsRetained,
|
|
194
|
-
payloadFiles: this.#testPayloadFileCount,
|
|
195
|
-
},
|
|
196
|
-
inputs: this.#inputs,
|
|
197
|
-
errors: this.#errors,
|
|
198
|
-
}))
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
assertDirectoryUnchanged(this.#outputRoot, this.#outputRootDirectory, 'output root')
|
|
202
|
-
assertDirectoryUnchanged(directoryPath, this.#completionDirectory, 'completions')
|
|
203
|
-
writeNewFile(temporary, completion)
|
|
204
|
-
assertDirectoryUnchanged(directoryPath, this.#completionDirectory, 'completions')
|
|
205
|
-
fs.renameSync(temporary, filename)
|
|
206
|
-
return true
|
|
207
|
-
} catch {
|
|
208
|
-
removePartialFile(temporary, directoryPath, this.#completionDirectory)
|
|
209
|
-
return false
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Writes one completed JSON payload to a unique file.
|
|
215
|
-
*
|
|
216
|
-
* @param {Buffer} payload JSON payload
|
|
217
|
-
*/
|
|
218
|
-
#writePayloadFile (payload) {
|
|
219
|
-
if (this.#fileCount >= MAX_OUTPUT_FILES) {
|
|
220
|
-
this.#fail('output_file_limit_exceeded')
|
|
221
|
-
return false
|
|
222
|
-
}
|
|
223
|
-
if (this.#bytesWritten + payload.length > MAX_OUTPUT_BYTES) {
|
|
224
|
-
this.#fail('output_byte_limit_exceeded')
|
|
225
|
-
return false
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const directoryPath = path.join(this.#outputRoot, 'payloads', 'tests')
|
|
229
|
-
const sequence = ++payloadFileSequence
|
|
230
|
-
const timestamp = BigInt(Date.now()) * 1_000_000n + process.hrtime.bigint() % 1_000_000n
|
|
231
|
-
const filename = path.join(
|
|
232
|
-
directoryPath,
|
|
233
|
-
`tests-${this.#processId}-${timestamp}-${process.pid}-${sequence}.json`
|
|
234
|
-
)
|
|
235
|
-
let writeFailed = false
|
|
236
|
-
try {
|
|
237
|
-
assertDirectoryUnchanged(this.#outputRoot, this.#outputRootDirectory, 'output root')
|
|
238
|
-
assertDirectoryUnchanged(path.join(this.#outputRoot, 'payloads'), this.#payloadsDirectory, 'payloads')
|
|
239
|
-
assertDirectoryUnchanged(directoryPath, this.#testsDirectory, 'tests')
|
|
240
|
-
writeNewFile(filename, payload)
|
|
241
|
-
} catch {
|
|
242
|
-
writeFailed = true
|
|
243
|
-
}
|
|
244
|
-
if (writeFailed) {
|
|
245
|
-
this.#fail('output_write_failed')
|
|
246
|
-
removePartialFile(filename, directoryPath, this.#testsDirectory)
|
|
247
|
-
return false
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
this.#bytesWritten += payload.length
|
|
251
|
-
this.#fileCount++
|
|
252
|
-
return true
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Records a sink failure and makes the process unsuccessful.
|
|
257
|
-
*
|
|
258
|
-
* @param {string} code stable failure code
|
|
259
|
-
*/
|
|
260
|
-
#fail (code) {
|
|
261
|
-
this.#addError(code)
|
|
262
|
-
process.exitCode = 1
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Adds one unique bounded summary error.
|
|
267
|
-
*
|
|
268
|
-
* @param {string} code stable failure code
|
|
269
|
-
*/
|
|
270
|
-
#addError (code) {
|
|
271
|
-
if (this.#errors.length >= MAX_SUMMARY_ERRORS || this.#errors.includes(code)) return
|
|
272
|
-
this.#errors.push(code)
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Writes one new private regular file and rejects hard links or non-files.
|
|
278
|
-
*
|
|
279
|
-
* @param {string} filename output filename
|
|
280
|
-
* @param {Buffer} payload output bytes
|
|
281
|
-
*/
|
|
282
|
-
function writeNewFile (filename, payload) {
|
|
283
|
-
const flags = fs.constants.O_WRONLY |
|
|
284
|
-
fs.constants.O_CREAT |
|
|
285
|
-
fs.constants.O_EXCL |
|
|
286
|
-
(fs.constants.O_NOFOLLOW || 0)
|
|
287
|
-
const file = fs.openSync(filename, flags, 0o600)
|
|
288
|
-
try {
|
|
289
|
-
const stat = fs.fstatSync(file)
|
|
290
|
-
if (!stat.isFile() || stat.nlink !== 1) {
|
|
291
|
-
throw new Error('Offline Test Optimization output is not a private regular file.')
|
|
292
|
-
}
|
|
293
|
-
fs.writeFileSync(file, payload)
|
|
294
|
-
} finally {
|
|
295
|
-
fs.closeSync(file)
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Captures the identity of one existing non-symbolic directory.
|
|
301
|
-
*
|
|
302
|
-
* @param {string} directory directory path
|
|
303
|
-
* @param {string} label directory label
|
|
304
|
-
* @returns {{dev: bigint, ino: bigint}} stable directory identity
|
|
305
|
-
*/
|
|
306
|
-
function captureDirectory (directory, label) {
|
|
307
|
-
// Windows file reference numbers exceed 2^53, where distinct directories round to one number.
|
|
308
|
-
const stat = fs.lstatSync(directory, { bigint: true })
|
|
309
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
310
|
-
throw new Error(`Offline Test Optimization validation ${label} must be a regular directory.`)
|
|
311
|
-
}
|
|
312
|
-
return { dev: stat.dev, ino: stat.ino }
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Creates or validates one child directory without accepting symbolic links.
|
|
317
|
-
*
|
|
318
|
-
* @param {string} parent parent directory path
|
|
319
|
-
* @param {{dev: bigint, ino: bigint}} parentIdentity expected parent identity
|
|
320
|
-
* @param {string} directory child directory path
|
|
321
|
-
* @param {string} label directory label
|
|
322
|
-
* @returns {{dev: bigint, ino: bigint}} stable child identity
|
|
323
|
-
*/
|
|
324
|
-
function createDirectory (parent, parentIdentity, directory, label) {
|
|
325
|
-
assertDirectoryUnchanged(parent, parentIdentity, 'parent output')
|
|
326
|
-
try {
|
|
327
|
-
fs.mkdirSync(directory, { mode: 0o700 })
|
|
328
|
-
} catch (error) {
|
|
329
|
-
if (error.code !== 'EEXIST') throw error
|
|
330
|
-
}
|
|
331
|
-
return captureDirectory(directory, `${label} output directory`)
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Rejects a directory that changed after sink construction.
|
|
336
|
-
*
|
|
337
|
-
* @param {string} directory directory path
|
|
338
|
-
* @param {{dev: bigint, ino: bigint}} identity expected directory identity
|
|
339
|
-
* @param {string} label directory label
|
|
340
|
-
*/
|
|
341
|
-
function assertDirectoryUnchanged (directory, identity, label) {
|
|
342
|
-
const current = captureDirectory(directory, label)
|
|
343
|
-
if (current.dev !== identity.dev || current.ino !== identity.ino) {
|
|
344
|
-
throw new Error(`Offline Test Optimization validation ${label} changed during execution.`)
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Removes a partially written final path without following symbolic links.
|
|
350
|
-
*
|
|
351
|
-
* @param {string} filename partial payload path
|
|
352
|
-
* @param {string} directory expected parent directory
|
|
353
|
-
* @param {{dev: bigint, ino: bigint}} identity expected parent identity
|
|
354
|
-
*/
|
|
355
|
-
function removePartialFile (filename, directory, identity) {
|
|
356
|
-
try {
|
|
357
|
-
assertDirectoryUnchanged(directory, identity, 'partial-file parent')
|
|
358
|
-
const stat = fs.lstatSync(filename)
|
|
359
|
-
if (stat.isFile() || stat.isSymbolicLink()) fs.unlinkSync(filename)
|
|
360
|
-
} catch {}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
module.exports = {
|
|
364
|
-
CiValidationSink,
|
|
365
|
-
MAX_OUTPUT_BYTES,
|
|
366
|
-
MAX_OUTPUT_FILES,
|
|
367
|
-
SUMMARY_PREFIX,
|
|
368
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { AgentlessCiVisibilityEncoder } = require('../../../encode/agentless-ci-visibility')
|
|
4
|
-
|
|
5
|
-
class CiValidationWriter {
|
|
6
|
-
/**
|
|
7
|
-
* Creates an offline writer that preserves CI Visibility event encoding.
|
|
8
|
-
*
|
|
9
|
-
* @param {object} options writer options
|
|
10
|
-
* @param {object} options.sink bounded validation sink
|
|
11
|
-
* @param {object} options.tags tracer tags
|
|
12
|
-
*/
|
|
13
|
-
constructor ({ sink, tags }) {
|
|
14
|
-
this._sink = sink
|
|
15
|
-
this._encoder = new AgentlessCiVisibilityEncoder(this, { tags })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Encodes a CI Visibility trace without using an HTTP writer.
|
|
20
|
-
*
|
|
21
|
-
* @param {object[]} trace formatted trace
|
|
22
|
-
*/
|
|
23
|
-
append (trace) {
|
|
24
|
-
this._encoder.encode(trace)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Flushes encoded events synchronously to an offline payload file.
|
|
29
|
-
*
|
|
30
|
-
* @param {Function} [done] completion callback
|
|
31
|
-
*/
|
|
32
|
-
flush (done = () => {}) {
|
|
33
|
-
if (this._encoder.count() > 0) {
|
|
34
|
-
let payload
|
|
35
|
-
try {
|
|
36
|
-
payload = this._encoder.makePayload()
|
|
37
|
-
} catch (error) {
|
|
38
|
-
if (error.code !== 'ERR_MSGPACK_CHUNK_OVERFLOW') throw error
|
|
39
|
-
this._encoder.reset()
|
|
40
|
-
this._sink.recordError('output_payload_too_large')
|
|
41
|
-
done()
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
this._sink.writeTestCycle(payload)
|
|
45
|
-
}
|
|
46
|
-
done()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Adds CI event metadata before the next payload is encoded.
|
|
51
|
-
*
|
|
52
|
-
* @param {object} tags metadata grouped by event type
|
|
53
|
-
*/
|
|
54
|
-
addMetadataTags (tags) {
|
|
55
|
-
this._encoder.addMetadataTags(tags)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
module.exports = CiValidationWriter
|