Skip to content

Commit bd6b987

Browse files
rustyconoverclaude
andcommitted
ci: fail when engine pins drift from the vgi extension's engine line
vgi-python ran its whole suite on DuckDB 1.5.5 for a month after the extension moved to DuckDB 2.0, because nothing compared the two. engine-drift.yml reads the Haybarn tag from Query-farm/vgi's distribution workflow and fails if the [haybarn]/[duckdb] pins are on a different major.minor line. Runs on push, pull requests, and weekly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1455d82 commit bd6b987

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

‎.github/workflows/engine-drift.yml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Engine drift
2+
3+
# vgi-python's exact engine pins (the haybarn/duckdb extras, which are also the
4+
# vgi.duckdb.standard.v1 filter oracle) must stay on the same DuckDB line as the
5+
# engine the DuckDB vgi extension is built against. Runs on every change here
6+
# and weekly, so an engine bump in the extension is caught even while this repo
7+
# is quiet. See scripts/check_engine_drift.py.
8+
9+
on:
10+
push:
11+
branches: [main]
12+
pull_request:
13+
branches: [main]
14+
schedule:
15+
- cron: "17 6 * * 1"
16+
workflow_dispatch:
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
engine-drift:
23+
name: Engine pins match the vgi extension's engine
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v7
27+
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v10.3.3
30+
31+
- name: Compare engine lines
32+
env:
33+
GITHUB_TOKEN: ${{ github.token }}
34+
run: uv run --no-project --python 3.13 scripts/check_engine_drift.py

‎scripts/check_engine_drift.py‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Copyright 2025, 2026 Query Farm LLC - https://query.farm
2+
3+
"""Fail when vgi-python's engine pins drift from the DuckDB ``vgi`` extension's engine.
4+
5+
vgi-python pins its embedded engine exactly (the ``haybarn``/``duckdb`` extras,
6+
which are also the ``vgi.duckdb.standard.v1`` filter oracle). The extension is
7+
built against the Haybarn tag named in its distribution workflow. When the two
8+
are on different engine lines (major.minor), vgi-python's own suite tests an
9+
engine no deployed extension uses: the 1.5 -> 2.0 move went unnoticed for a
10+
month that way, because every vgi-python test, and every extension test that
11+
launched a vgi-python worker, ran on 1.5.5.
12+
13+
The exact release candidate may differ (the extension builds from a Haybarn tag
14+
that need not have a PyPI wheel), so only the engine line is compared.
15+
16+
Usage: ``python scripts/check_engine_drift.py`` (set ``GITHUB_TOKEN`` to avoid
17+
the anonymous API rate limit; ``VGI_REPO`` / ``VGI_REF`` override the source).
18+
"""
19+
20+
from __future__ import annotations
21+
22+
import json
23+
import os
24+
import re
25+
import sys
26+
import tomllib
27+
import urllib.request
28+
from pathlib import Path
29+
30+
ROOT = Path(__file__).resolve().parents[1]
31+
VGI_REPO = os.environ.get("VGI_REPO", "Query-farm/vgi")
32+
WORKFLOW = ".github/workflows/MainDistributionPipeline.yml"
33+
_LINE = re.compile(r"(\d+)\.(\d+)\.")
34+
35+
36+
def _get(url: str) -> bytes:
37+
request = urllib.request.Request(url, headers={"User-Agent": "vgi-python-engine-drift-check"})
38+
token = os.environ.get("GITHUB_TOKEN")
39+
if token and url.startswith("https://api.github.com/"):
40+
request.add_header("Authorization", f"Bearer {token}")
41+
with urllib.request.urlopen(request, timeout=30) as response: # noqa: S310 - fixed https URLs
42+
data: bytes = response.read()
43+
return data
44+
45+
46+
def extension_engine() -> tuple[str, str]:
47+
"""Return ``(ref, haybarn tag)`` the extension's distribution build uses."""
48+
ref = os.environ.get("VGI_REF") or json.loads(_get(f"https://api.github.com/repos/{VGI_REPO}"))["default_branch"]
49+
text = _get(f"https://raw.githubusercontent.com/{VGI_REPO}/{ref}/{WORKFLOW}").decode()
50+
tags = set(re.findall(r"^\s*duckdb_version:\s*['\"]?([^'\"\s#]+)", text, re.MULTILINE))
51+
if len(tags) != 1:
52+
raise SystemExit(f"expected one duckdb_version in {VGI_REPO}@{ref}:{WORKFLOW}, found {sorted(tags) or 'none'}")
53+
return ref, tags.pop()
54+
55+
56+
def pinned_engines() -> dict[str, str]:
57+
"""Return ``{distribution: exact version}`` from the engine extras."""
58+
extras = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]["optional-dependencies"]
59+
pins = {}
60+
for name in ("haybarn", "duckdb"):
61+
specs = [s.replace(" ", "") for s in extras[name] if re.match(rf"{name}\b", s)]
62+
match = re.fullmatch(rf"{name}==(\S+)", specs[0]) if len(specs) == 1 else None
63+
if match is None:
64+
raise SystemExit(f"the [{name}] extra must pin {name} exactly, got {specs}")
65+
pins[name] = match.group(1)
66+
return pins
67+
68+
69+
def engine_line(version: str) -> str:
70+
"""``haybarn-v2.0.0-rc10`` / ``2.0.0rc11`` -> ``2.0``."""
71+
match = _LINE.search(version)
72+
if match is None:
73+
raise SystemExit(f"cannot read an engine version from {version!r}")
74+
return f"{match.group(1)}.{match.group(2)}"
75+
76+
77+
def main() -> int:
78+
"""Compare the engine lines and report.
79+
80+
Returns:
81+
The process exit status (0 when every pin is on the extension's line).
82+
"""
83+
ref, tag = extension_engine()
84+
want = engine_line(tag)
85+
pins = pinned_engines()
86+
print(f"extension ({VGI_REPO}@{ref}) builds on {tag} -> engine line {want}")
87+
drift = []
88+
for name, version in pins.items():
89+
line = engine_line(version)
90+
print(f"vgi-python [{name}] pins {name}=={version} -> engine line {line}")
91+
if line != want:
92+
drift.append(f"{name}=={version}")
93+
if drift:
94+
print(
95+
f"\nENGINE DRIFT: {', '.join(drift)} is not on the extension's DuckDB {want} line. Move the engine pins "
96+
"(pyproject extras + dev group), STANDARD_V1_ENGINE_VERSIONS in vgi/filter_v2.py and the oracle in "
97+
"docs/protocol/vgi-filter-encoding-v2-spec.md section 6 together, then run the suite on the new engine.",
98+
file=sys.stderr,
99+
)
100+
return 1
101+
return 0
102+
103+
104+
if __name__ == "__main__":
105+
sys.exit(main())

0 commit comments

Comments
 (0)