"""Tests for plugin versioning: upgrade, downgrade, compatibility checks.""" from __future__ import annotations import pytest from app.plugins.semver import SemVer from app.plugins.manifest import PluginManifest class TestManifestVersioning: def test_manifest_has_min_app_version(self): """PluginManifest has min_app_version field.""" m = PluginManifest( name="test", version="1.0.0", display_name="Test", ) assert hasattr(m, "min_app_version") assert m.min_app_version == "0.0.0" def test_manifest_with_min_app_version(self): """PluginManifest can set min_app_version.""" m = PluginManifest( name="test", version="1.0.0", display_name="Test", min_app_version="1.5.0", ) assert m.min_app_version == "1.5.0" def test_manifest_extra_forbid_still_works(self): """Manifest still rejects unknown fields.""" with pytest.raises(Exception): PluginManifest( name="test", version="1.0.0", display_name="Test", unknown_field="value", ) class TestVersionComparison: def test_upgrade_detection(self): """SemVer correctly detects upgrades.""" old = SemVer.parse("1.0.0") new = SemVer.parse("1.1.0") assert new.is_upgrade_from(old) assert not old.is_upgrade_from(new) def test_downgrade_detection(self): """SemVer correctly detects downgrades.""" old = SemVer.parse("1.1.0") new = SemVer.parse("1.0.0") assert new.is_downgrade_from(old) def test_breaking_change_detection(self): """Major version change is a breaking change.""" assert SemVer.parse("1.0.0").is_breaking_change(SemVer.parse("2.0.0")) assert not SemVer.parse("1.0.0").is_breaking_change(SemVer.parse("1.5.0")) def test_compatibility_check(self): """Version compatibility works correctly.""" assert SemVer.parse("1.5.0").is_compatible_with(SemVer.parse("1.0.0")) assert not SemVer.parse("1.0.0").is_compatible_with(SemVer.parse("1.5.0")) assert SemVer.parse("2.0.0").is_compatible_with(SemVer.parse("1.0.0")) assert not SemVer.parse("1.0.0").is_compatible_with(SemVer.parse("2.0.0"))