|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +from __future__ import annotations |
| 18 | + |
| 19 | +import re |
| 20 | + |
| 21 | +import pytest |
| 22 | + |
| 23 | +from airflow.serialization.serialized_objects import DagSerialization |
| 24 | + |
| 25 | +from tests_common.pytest_plugin import AIRFLOW_ROOT_PATH |
| 26 | + |
| 27 | +GENERATED_FIELDS_PATH = AIRFLOW_ROOT_PATH / "ts-sdk" / "src" / "generated" / "dag-schema-fields.ts" |
| 28 | + |
| 29 | +SERIALIZATION_VERSION_PATTERN = re.compile( |
| 30 | + r"^export const SERIALIZATION_VERSION = (?P<version>\d+);$", re.MULTILINE |
| 31 | +) |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.skipif( |
| 35 | + not GENERATED_FIELDS_PATH.is_file(), |
| 36 | + reason="TypeScript SDK sources are absent (source distribution build)", |
| 37 | +) |
| 38 | +def test_ts_sdk_pins_the_current_serialization_version(): |
| 39 | + """ |
| 40 | + The schema constrains ``__version`` only to a positive integer, so the TypeScript SDK |
| 41 | + pins it by hand. Without this check, bumping the serializer would leave the SDK emitting |
| 42 | + Dags stamped with a version core no longer writes. |
| 43 | + """ |
| 44 | + match = SERIALIZATION_VERSION_PATTERN.search(GENERATED_FIELDS_PATH.read_text(encoding="utf-8")) |
| 45 | + assert match is not None, f"No SERIALIZATION_VERSION export found in {GENERATED_FIELDS_PATH}" |
| 46 | + |
| 47 | + assert int(match.group("version")) == DagSerialization.SERIALIZER_VERSION, ( |
| 48 | + f"{GENERATED_FIELDS_PATH.relative_to(AIRFLOW_ROOT_PATH)} pins serialization version " |
| 49 | + f"{match.group('version')}, but DagSerialization.SERIALIZER_VERSION is " |
| 50 | + f"{DagSerialization.SERIALIZER_VERSION}. Update SERIALIZATION_VERSION in " |
| 51 | + "ts-sdk/scripts/generate-dag-schema.mjs, re-run `pnpm run generate:dag-schema`, and make " |
| 52 | + "sure the SDK still emits Dags core can read." |
| 53 | + ) |
0 commit comments