Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions packages/desktop/tests/test_dependency_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,21 @@ def _locked_version(name: str) -> Version:
return Version(versions[0])


def _bundled_flow_types_specifier() -> SpecifierSet:
def _bundled_flow_pin() -> Version | None:
pyproject = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
for raw in pyproject["project"]["optional-dependencies"].get("build", []):
requirement = Requirement(raw)
if _canonical(requirement.name) == FLOW:
for item in requirement.specifier:
if item.operator == "==":
return Version(item.version)
return None


def _bundled_flow_types_specifier() -> tuple[Version, SpecifierSet]:
try:
requires = distribution(FLOW).requires or []
dist = distribution(FLOW)
requires = dist.requires or []
except PackageNotFoundError:
pytest.skip(
"the bundled openadapt-flow runtime is not installed; the "
Expand All @@ -56,7 +68,7 @@ def _bundled_flow_types_specifier() -> SpecifierSet:
for raw in requires:
requirement = Requirement(raw)
if _canonical(requirement.name) == TYPES and requirement.marker is None:
return requirement.specifier
return Version(dist.version), requirement.specifier
pytest.fail(f"the bundled {FLOW} no longer declares a base {TYPES} requirement")


Expand All @@ -73,11 +85,34 @@ def test_types_requirement_is_a_bounded_range_not_an_exact_pin() -> None:


def test_types_range_matches_the_bundled_flow_runtime() -> None:
"""Desktop accepts every shared-types release the bundled Flow accepts."""
"""Desktop accepts every shared-types release the bundled Flow accepts.

The qualification-contract job installs the exact Flow release pinned in
the ``build`` extra and enforces exact specifier equality. The unit-test
job overlays the newer in-tree Flow; there, Desktop must still accept the
installed shared-types release and share the same upper bound so neither
package forces a downgrade.
"""

desktop = _desktop_types_requirement().specifier
flow = _bundled_flow_types_specifier()
assert desktop == flow, (
f"Desktop declares {TYPES}{desktop} but the bundled {FLOW} declares "
f"{TYPES}{flow}; release Desktop with the same range as its Flow pin"
installed_flow_version, flow = _bundled_flow_types_specifier()
bundled_pin = _bundled_flow_pin()
if bundled_pin is None or installed_flow_version == bundled_pin:
assert desktop == flow, (
f"Desktop declares {TYPES}{desktop} but the bundled {FLOW} declares "
f"{TYPES}{flow}; release Desktop with the same range as its Flow pin"
)
return
installed_types = Version(distribution(TYPES).version)
assert installed_types in desktop, (
f"Desktop declares {TYPES}{desktop} which excludes installed {TYPES}=={installed_types}"
)
assert installed_types in flow, (
f"In-tree {FLOW} declares {TYPES}{flow} which excludes installed {TYPES}=={installed_types}"
)
desktop_upper = {str(s) for s in desktop if s.operator in ("<", "<=")}
flow_upper = {str(s) for s in flow if s.operator in ("<", "<=")}
assert desktop_upper == flow_upper, (
f"Desktop upper bound {desktop_upper} disagrees with "
f"in-tree {FLOW} upper bound {flow_upper}"
)
Loading