From 1f2eaa30dd581e144eaa2f79af147d7997aa7e7a Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 15 Jul 2026 10:06:43 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=8B=E7=BC=A9=20PaC=20schema=20?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E8=BD=BD=E8=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pac-feature-config-schema-stage.test.ts | 10 ++++-- .../src/pac-feature-config-schema-stage.ts | 33 +++++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/scripts/src/pac-feature-config-schema-stage.test.ts b/scripts/src/pac-feature-config-schema-stage.test.ts index 5da4e6ba..ff704691 100644 --- a/scripts/src/pac-feature-config-schema-stage.test.ts +++ b/scripts/src/pac-feature-config-schema-stage.test.ts @@ -21,11 +21,13 @@ test("shared stage injects owning YAML OTel values for all three PaC repositorie renderedRootExpression: "'/workspace/rendered'", }); expect(stage).toContain("feature-config-schema-validation"); - expect(stage).toContain("cicd.feature_config.schema"); expect(stage).toContain("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT='http://otel-collector.platform-infra.svc.cluster.local:4318/v1/traces'"); expect(stage).toContain("OTEL_TRACES_SAMPLER_ARG='1'"); expect(stage).toContain("OTEL_EXPORTER_TIMEOUT_MS='300'"); - expect(stage).toContain("NODE_UNIDESK_AJV2020_BUNDLE"); + expect(stage).toContain("base64 -d | gzip -d"); + expect(stage).toContain("NODE_UNIDESK_FEATURE_CONFIG_SCHEMA"); + expect(stage).not.toContain("cicd.feature_config.schema"); + expect(stage).not.toContain("NODE_UNIDESK_AJV2020_BUNDLE"); expect(stage).not.toContain("process.env.webProbeSentinel"); } }); @@ -112,7 +114,9 @@ test("AgentRun normal GitOps publish task contains the shared warning-only stage expect(scripts).toContain("feature-config-schema-validation"); expect(scripts).toContain("feature-config-validator-process-failure"); expect(scripts).toContain("OTEL_EXPORTER_TIMEOUT_MS='300'"); - expect(scripts).toContain("NODE_UNIDESK_AJV2020_BUNDLE"); + expect(scripts).toContain("base64 -d | gzip -d"); + expect(scripts).toContain("NODE_UNIDESK_FEATURE_CONFIG_SCHEMA"); + expect(scripts).not.toContain("NODE_UNIDESK_AJV2020_BUNDLE"); }); test("repo-owned schema is Draft 2020-12 with one canonical feature property", () => { diff --git a/scripts/src/pac-feature-config-schema-stage.ts b/scripts/src/pac-feature-config-schema-stage.ts index 4eb70a3d..cf8bb8cc 100644 --- a/scripts/src/pac-feature-config-schema-stage.ts +++ b/scripts/src/pac-feature-config-schema-stage.ts @@ -1,10 +1,13 @@ import { readFileSync } from "node:fs"; +import { gzipSync } from "node:zlib"; import { rootPath } from "./config"; import { loadCicdOtelRuntimeConfig } from "../native/cicd/otel-runtime-config"; const validatorSource = readFileSync(rootPath("scripts/native/cicd/feature-config-schema-warning.mjs"), "utf8").trimEnd(); const ajv2020BundleSource = readFileSync(rootPath("scripts/vendor/ajv-dist/8.17.1/ajv2020.min.js"), "utf8").trimEnd(); +const validatorGzipBase64 = gzipBase64(validatorSource); +const ajv2020GzipBase64 = gzipBase64(ajv2020BundleSource); export interface PacFeatureConfigSchemaStageOptions { readonly repositoryId: string; @@ -26,14 +29,21 @@ export function renderPacFeatureConfigSchemaStage(options: PacFeatureConfigSchem `export OTEL_SERVICE_NAME=${shellSingle(otel.serviceName)}`, `export OTEL_TRACES_SAMPLER_ARG=${shellSingle(String(otel.samplingRatio))}`, `export OTEL_EXPORTER_TIMEOUT_MS=${shellSingle(String(otel.timeoutMs))}`, + "feature_config_validator_base=''", + "feature_config_validator=''", + "if feature_config_validator_base=\"$(mktemp \"${TMPDIR:-/tmp}/unidesk-feature-config-validator.XXXXXX\" 2>/dev/null)\"; then", + " feature_config_validator=\"${feature_config_validator_base}.mjs\"", + " if ! printf '%s' " + shellSingle(validatorGzipBase64) + " | base64 -d | gzip -d >\"$feature_config_validator\"; then", + " rm -f \"$feature_config_validator_base\" \"$feature_config_validator\" || true", + " feature_config_validator=''", + " fi", + " rm -f \"$feature_config_validator_base\" || true", + "fi", ...(materializeBundle ? [ "feature_config_ajv_bundle=''", "if feature_config_ajv_bundle=\"$(mktemp \"${TMPDIR:-/tmp}/unidesk-ajv2020.XXXXXX\" 2>/dev/null)\"; then", - " if ! cat >\"$feature_config_ajv_bundle\" <<'NODE_UNIDESK_AJV2020_BUNDLE'", - ajv2020BundleSource, - "NODE_UNIDESK_AJV2020_BUNDLE", - " then", + " if ! printf '%s' " + shellSingle(ajv2020GzipBase64) + " | base64 -d | gzip -d >\"$feature_config_ajv_bundle\"; then", " rm -f \"$feature_config_ajv_bundle\" || true", " feature_config_ajv_bundle=''", " fi", @@ -41,17 +51,16 @@ export function renderPacFeatureConfigSchemaStage(options: PacFeatureConfigSchem "export UNIDESK_AJV2020_BUNDLE=\"${feature_config_ajv_bundle:-${TMPDIR:-/tmp}/unidesk-ajv2020-unavailable}\"", ] : [`export UNIDESK_AJV2020_BUNDLE=${options.ajvBundleExpression}`]), + "export UNIDESK_FEATURE_CONFIG_VALIDATOR=\"${feature_config_validator:-${TMPDIR:-/tmp}/unidesk-feature-config-validator-unavailable.mjs}\"", "if ! node --input-type=module <<'NODE_UNIDESK_FEATURE_CONFIG_SCHEMA'", - validatorSource, - "await runFeatureConfigSchemaValidation({", - " repoDir: process.env.UNIDESK_FEATURE_CONFIG_REPO_DIR,", - " renderedRoot: process.env.UNIDESK_FEATURE_CONFIG_RENDERED_ROOT,", - " consumer: process.env.UNIDESK_PAC_CONSUMER,", - "});", + "import { pathToFileURL } from 'node:url';", + "const validator = await import(pathToFileURL(process.env.UNIDESK_FEATURE_CONFIG_VALIDATOR).href);", + "await validator.runFeatureConfigSchemaValidation({ repoDir: process.env.UNIDESK_FEATURE_CONFIG_REPO_DIR, renderedRoot: process.env.UNIDESK_FEATURE_CONFIG_RENDERED_ROOT, consumer: process.env.UNIDESK_PAC_CONSUMER });", "NODE_UNIDESK_FEATURE_CONFIG_SCHEMA", "then", " printf '{\"event\":\"feature-config-schema-validation\",\"warning\":true,\"blocking\":false,\"code\":\"feature-config-validator-process-failure\",\"mutation\":false,\"valuesPrinted\":false}\\n' >&2", "fi", + "if [ -n \"$feature_config_validator\" ]; then rm -f \"$feature_config_validator\" || true; fi", ...(materializeBundle ? ["if [ -n \"$feature_config_ajv_bundle\" ]; then rm -f \"$feature_config_ajv_bundle\" || true; fi"] : []), "if command -v ci_timing_emit >/dev/null 2>&1; then", " ci_timing_emit feature-config-schema-validation succeeded \"$feature_config_schema_started_ms\"", @@ -64,3 +73,7 @@ export function renderPacFeatureConfigSchemaStage(options: PacFeatureConfigSchem function shellSingle(value: string): string { return `'${value.replaceAll("'", `'"'"'`)}'`; } + +function gzipBase64(value: string): string { + return gzipSync(Buffer.from(value, "utf8"), { level: 9 }).toString("base64"); +}