-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_version_guard.py
More file actions
65 lines (43 loc) · 2.08 KB
/
Copy pathtest_version_guard.py
File metadata and controls
65 lines (43 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Unit tests for the runtime backend version guard (agentex.lib.core.compat.version_guard)."""
from __future__ import annotations
import asyncio
import pytest
from agentex.lib.core.compat import version_guard as vg
def _run(coro):
return asyncio.run(coro)
def test_parse_versions():
assert vg._parse("0.2.1") == (0, 2, 1)
assert vg._parse("v1.4.0") == (1, 4, 0)
assert vg._parse("0.2.1-rc.1+build5") == (0, 2, 1)
assert vg._parse("garbage") is None
assert vg._parse(None) is None
def test_compatible_backend_passes(monkeypatch):
async def fake(url, **kw):
return "0.2.0"
monkeypatch.setattr(vg, "fetch_backend_version", fake)
# backend (0.2.0) >= min (0.1.0) → no raise
_run(vg.assert_backend_compatible("http://backend", min_version="0.1.0"))
def test_incompatible_backend_raises(monkeypatch):
async def fake(url, **kw):
return "0.0.9"
monkeypatch.setattr(vg, "fetch_backend_version", fake)
with pytest.raises(vg.IncompatibleBackendError) as exc:
_run(vg.assert_backend_compatible("http://backend", min_version="0.1.0", sdk_version="0.13.0"))
msg = str(exc.value)
assert "0.13.0" in msg and "0.1.0" in msg and "0.0.9" in msg # actionable message
def test_skip_env_bypasses(monkeypatch):
async def fake(url, **kw):
raise AssertionError("must not fetch when skip env is set")
monkeypatch.setattr(vg, "fetch_backend_version", fake)
monkeypatch.setenv(vg.SKIP_ENV, "1")
# even an impossible min must not raise when explicitly skipped
_run(vg.assert_backend_compatible("http://backend", min_version="9.9.9"))
def test_unknown_backend_version_does_not_crash(monkeypatch):
async def fake(url, **kw):
return None # unreachable / no version → unknown
monkeypatch.setattr(vg, "fetch_backend_version", fake)
# unknown version warns but must not raise (transient/contract-less server)
_run(vg.assert_backend_compatible("http://backend", min_version="9.9.9"))
def test_no_base_url_is_noop():
_run(vg.assert_backend_compatible(None))
_run(vg.assert_backend_compatible(""))