|
7 | 7 |
|
8 | 8 | from __future__ import annotations |
9 | 9 |
|
| 10 | +import json |
10 | 11 | import re |
11 | 12 |
|
12 | 13 | # --------------------------------------------------------------------------- |
@@ -45,6 +46,18 @@ def _patch_lfx_pyproject(txt: str, langflow_version: str) -> str: |
45 | 46 | return re.sub(r'^version = ".*"', f'version = "{langflow_version}"', txt, flags=re.MULTILINE) |
46 | 47 |
|
47 | 48 |
|
| 49 | +def _patch_sdk_pyproject(txt: str, sdk_version: str) -> str: |
| 50 | + return re.sub(r'^version = ".*"', f'version = "{sdk_version}"', txt, flags=re.MULTILINE) |
| 51 | + |
| 52 | + |
| 53 | +def _patch_lfx_sdk_dependency(txt: str, sdk_version: str) -> str: |
| 54 | + return re.sub(r'"langflow-sdk(?:==|>=|~=)[^"]*"', f'"langflow-sdk>={sdk_version}"', txt) |
| 55 | + |
| 56 | + |
| 57 | +def _component_index_version_matches(txt: str, langflow_version: str) -> bool: |
| 58 | + return json.loads(txt).get("version") == langflow_version |
| 59 | + |
| 60 | + |
48 | 61 | # --------------------------------------------------------------------------- |
49 | 62 | # langflow-core pins in main pyproject.toml |
50 | 63 | # --------------------------------------------------------------------------- |
@@ -220,6 +233,43 @@ def test_realistic_lfx_fragment(self): |
220 | 233 | assert "Lightweight executor" in result |
221 | 234 |
|
222 | 235 |
|
| 236 | +# --------------------------------------------------------------------------- |
| 237 | +# SDK version and LFX SDK dependency |
| 238 | +# --------------------------------------------------------------------------- |
| 239 | + |
| 240 | + |
| 241 | +class TestSdkVersionSubstitution: |
| 242 | + def test_updates_sdk_version(self): |
| 243 | + txt = '[project]\nname = "langflow-sdk"\nversion = "0.3.0"\n' |
| 244 | + result = _patch_sdk_pyproject(txt, "0.4.0") |
| 245 | + assert 'version = "0.4.0"' in result |
| 246 | + assert 'name = "langflow-sdk"' in result |
| 247 | + |
| 248 | + def test_updates_lfx_sdk_dependency(self): |
| 249 | + txt = 'dependencies = ["langflow-sdk~=0.3.0", "orjson>=3.10.0"]' |
| 250 | + result = _patch_lfx_sdk_dependency(txt, "0.4.0") |
| 251 | + assert '"langflow-sdk>=0.4.0"' in result |
| 252 | + assert '"orjson>=3.10.0"' in result |
| 253 | + |
| 254 | + |
| 255 | +# --------------------------------------------------------------------------- |
| 256 | +# component-index version validation |
| 257 | +# --------------------------------------------------------------------------- |
| 258 | + |
| 259 | + |
| 260 | +class TestComponentIndexVersionValidation: |
| 261 | + def test_accepts_matching_top_level_version(self): |
| 262 | + index = {"entries": [], "version": "1.12.0"} |
| 263 | + assert _component_index_version_matches(json.dumps(index), "1.12.0") |
| 264 | + |
| 265 | + def test_rejects_nested_match_when_top_level_version_is_stale(self): |
| 266 | + index = { |
| 267 | + "entries": [["example", {"metadata": {"dependencies": [{"name": "langflow", "version": "1.12.0"}]}}]], |
| 268 | + "version": "1.11.0", |
| 269 | + } |
| 270 | + assert not _component_index_version_matches(json.dumps(index), "1.12.0") |
| 271 | + |
| 272 | + |
223 | 273 | # --------------------------------------------------------------------------- |
224 | 274 | # release.yml: major.minor extraction from the current lfx constraint |
225 | 275 | # |
|
0 commit comments