|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +import runpy |
| 7 | +import shutil |
| 8 | +import subprocess |
| 9 | +import tomllib |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +import pytest |
| 13 | +import setuptools |
| 14 | +from packaging.version import Version |
| 15 | +from setuptools_scm import get_version |
| 16 | + |
| 17 | +from ci.tools import check_pixi_cuda_version |
| 18 | +from ci.tools.bindings_config import BindingsPackage, load_config |
| 19 | + |
| 20 | +ROOT = Path(__file__).resolve().parents[3] |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture |
| 24 | +def legacy_config(tmp_path): |
| 25 | + path = tmp_path / "versions.yml" |
| 26 | + path.write_text('cuda:\n build:\n version: "13.4.2"\n prev_build:\n version: "12.9.1"\n') |
| 27 | + return path |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.agent_authored(model="gpt-6") |
| 31 | +def test_normalizes_legacy_toolkit_pins(legacy_config): |
| 32 | + config = load_config(legacy_config) |
| 33 | + current = config.package_for_release_status("current") |
| 34 | + maintenance = config.get_package("cuda_bindings_12") |
| 35 | + assert current == BindingsPackage("cuda_bindings_13", (13, 4, 2), "current") |
| 36 | + assert maintenance == config.package_for_release_status("maintenance") |
| 37 | + assert maintenance.toolkit_version == "12.9.1" |
| 38 | + assert maintenance.ctk_target == "12.9" |
| 39 | + assert maintenance.cuda_major == "12" |
| 40 | + assert maintenance.cuda_variant == "cu12" |
| 41 | + |
| 42 | + |
| 43 | +@pytest.fixture |
| 44 | +def pixi_checkout(tmp_path, monkeypatch, legacy_config): |
| 45 | + for package_root in ("cuda_bindings_13", "cuda_core"): |
| 46 | + path = tmp_path / package_root / "pixi.toml" |
| 47 | + path.parent.mkdir() |
| 48 | + path.write_text( |
| 49 | + '[workspace.build-variants]\ncuda-version = ["13.4.*"]\n' |
| 50 | + '[feature.cu13.dependencies]\ncuda-version = "13.4.*"\n' |
| 51 | + ) |
| 52 | + monkeypatch.setattr(check_pixi_cuda_version, "ROOT", tmp_path) |
| 53 | + monkeypatch.setattr(check_pixi_cuda_version, "VERSIONS_FILE_PATH", legacy_config) |
| 54 | + return tmp_path |
| 55 | + |
| 56 | + |
| 57 | +@pytest.mark.agent_authored(model="gpt-6") |
| 58 | +def test_pixi_check_keeps_current_bindings_and_core_contract(pixi_checkout, capsys): |
| 59 | + # The hook requires only the current bindings workspace. |
| 60 | + assert check_pixi_cuda_version.main() == 0 |
| 61 | + output = capsys.readouterr().out |
| 62 | + assert "cuda_bindings_13/pixi.toml" in output |
| 63 | + assert "cuda_core/pixi.toml" in output |
| 64 | + |
| 65 | + |
| 66 | +@pytest.mark.agent_authored(model="gpt-6") |
| 67 | +def test_pixi_check_reports_core_pin_drift(pixi_checkout, capsys): |
| 68 | + path = pixi_checkout / "cuda_core" / "pixi.toml" |
| 69 | + path.write_text(path.read_text().replace('cuda-version = "13.4.*"', 'cuda-version = "13.3.*"')) |
| 70 | + assert check_pixi_cuda_version.main() == 1 |
| 71 | + assert "cuda_core/pixi.toml: feature.cu13.dependencies.cuda-version='13.3.*'" in capsys.readouterr().err |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.agent_authored(model="gpt-6") |
| 75 | +def test_cuda12_milestone_does_not_change_current_package_versions(tmp_path, monkeypatch): |
| 76 | + for package_root, filename in (("cuda_bindings_13", "pyproject.toml"), ("cuda_python", "setup.py")): |
| 77 | + destination = tmp_path / package_root / filename |
| 78 | + destination.parent.mkdir() |
| 79 | + shutil.copyfile(ROOT / package_root / filename, destination) |
| 80 | + |
| 81 | + def git(*args): |
| 82 | + return subprocess.run( # noqa: S603 |
| 83 | + ["git", "-c", "user.name=CI test", "-c", "user.email=ci-test@example.invalid", *args], # noqa: S607 |
| 84 | + cwd=tmp_path, |
| 85 | + check=True, |
| 86 | + capture_output=True, |
| 87 | + text=True, |
| 88 | + ) |
| 89 | + |
| 90 | + git("init", "--quiet") |
| 91 | + git("add", ".") |
| 92 | + git("commit", "--quiet", "-m", "Current CUDA 13 release") |
| 93 | + git("tag", "v13.4.3") |
| 94 | + (tmp_path / "maintenance-change").touch() |
| 95 | + git("add", ".") |
| 96 | + git("commit", "--quiet", "-m", "CUDA 12 maintenance milestone") |
| 97 | + git("tag", "v12.9.11a0") |
| 98 | + |
| 99 | + with (tmp_path / "cuda_bindings_13" / "pyproject.toml").open("rb") as stream: |
| 100 | + scm = tomllib.load(stream)["tool"]["setuptools_scm"] |
| 101 | + bindings_version = get_version(root=tmp_path, git_describe_command=scm["git_describe_command"]) |
| 102 | + metadata = {} |
| 103 | + monkeypatch.setattr(setuptools, "setup", lambda **kwargs: metadata.update(kwargs)) |
| 104 | + runpy.run_path(str(tmp_path / "cuda_python" / "setup.py")) |
| 105 | + assert Version(bindings_version).release[:2] == (13, 4) |
| 106 | + assert metadata["version"] == bindings_version |
0 commit comments