Skip to content

Commit ec6b32a

Browse files
vishkatydamaz91
andauthored
ci: verify committed models match regeneration from the pinned UCP spec (#62)
* ci: verify committed models match regeneration from the pinned UCP spec The Tests workflow installs the committed generated models and runs the unit suite, but never executes the generation pipeline itself (generate_models.sh + preprocess_schemas.py + postprocess_models.py end-to-end). A defect in the pipeline's wiring stays invisible as long as the committed models are fine, and models edited or left stale without regeneration are equally invisible. This is not hypothetical: with the floating datamodel-code-generator>=0.50.0 bound, the 0.72.0 release (2026-08-03) mis-resolves the spec's remote $refs (HTTP 404 on a doubled path), generation emits incomplete models, postprocess_models.py exits 1 -- and CI stays green because it only ever tests the committed artifacts. Add a model-drift job that regenerates the models against the pinned UCP spec version for this SDK line (0.4.x -> 2026-04-08, per the README compatibility table), normalizes file endings the way pre-commit does, and fails if the result is not byte-identical to the committed models. This catches a broken generator and uncommitted regeneration in one check, without changing the release flow of committing generated artifacts. Pin the codegen toolchain (datamodel-code-generator==0.71.0, ruff==0.16.1) so regeneration is reproducible; 0.71.0 + ruff 0.16.1 reproduce the committed models byte-for-byte after end-of-file normalization. * ci: pin github actions to commit hashes in tests.yml * ci: upgrade and pin actions to latest versions in tests.yml --------- Co-authored-by: damaz91 <federico.damato91@gmail.com>
1 parent ce385e2 commit ec6b32a

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

.github/workflows/tests.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,48 @@ jobs:
3333
python-version: ["3.10", "3.11", "3.12"]
3434
steps:
3535
- name: Checkout repository
36-
uses: actions/checkout@v5
36+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
3737
- name: Set up Python
38-
uses: actions/setup-python@v6
38+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
3939
with:
4040
python-version: ${{ matrix.python-version }}
4141
- name: Install package (generated-model tests import it)
4242
run: pip install -e .
4343
- name: Run preprocessing tests
4444
run: python -m unittest discover -s tests -p "test_*.py"
45+
46+
model-drift:
47+
name: Generated models match the pinned UCP spec
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
52+
- name: Install uv
53+
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
54+
with:
55+
enable-cache: true
56+
- name: Regenerate models from the pinned spec version
57+
# SDK 0.4.x targets UCP 2026-04-08 (see the README compatibility
58+
# table). Bump this pin together with the SDK version line.
59+
run: ./generate_models.sh 2026-04-08
60+
- name: Normalize file endings (as pre-commit's end-of-file-fixer does)
61+
run: |
62+
python3 - <<'PY'
63+
from pathlib import Path
64+
65+
for path in Path("src/ucp_sdk/models/schemas").rglob("*.py"):
66+
text = path.read_text(encoding="utf-8")
67+
fixed = text.rstrip("\n") + "\n" if text.strip() else ""
68+
if fixed != text:
69+
path.write_text(fixed, encoding="utf-8")
70+
PY
71+
- name: Fail if regeneration does not reproduce the committed models
72+
run: |
73+
git add -A -- src/ucp_sdk/models/schemas
74+
if ! git diff --cached --quiet -- src/ucp_sdk/models/schemas; then
75+
echo "::error::Committed models differ from regeneration against the pinned UCP spec. Either the generation pipeline is broken, or the models were edited without regenerating. Run ./generate_models.sh 2026-04-08 and commit the result."
76+
git --no-pager diff --cached --stat -- src/ucp_sdk/models/schemas
77+
git --no-pager diff --cached -- src/ucp_sdk/models/schemas
78+
exit 1
79+
fi
80+
echo "Committed models match regeneration."

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ dependencies = [
2727

2828
[dependency-groups]
2929
dev = [
30-
"datamodel-code-generator[http,ruff]>=0.50.0",
30+
# Exact pins: the model-drift CI job regenerates the models against the
31+
# pinned UCP spec and asserts byte-identical output, so the codegen
32+
# toolchain must resolve reproducibly. (The floating ">=0.50.0" bound
33+
# broke on 2026-08-03: datamodel-code-generator 0.72.0 mis-resolves the
34+
# spec's remote $refs and emits incomplete models.) Bump these pins and
35+
# regenerate the models in the same PR.
36+
"datamodel-code-generator[http]==0.71.0",
37+
"ruff==0.16.1",
3138
]
3239

3340
[build-system]

0 commit comments

Comments
 (0)