|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +import os |
| 7 | +import sys |
| 8 | + |
| 9 | +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) |
| 10 | +from check_release_notes import ( |
| 11 | + check_release_notes, |
| 12 | + is_post_release, |
| 13 | + main, |
| 14 | + parse_version_from_tag, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +class TestParseVersionFromTag: |
| 19 | + def test_plain_tag_bindings(self): |
| 20 | + assert parse_version_from_tag("v13.1.0", "cuda-bindings") == "13.1.0" |
| 21 | + |
| 22 | + def test_plain_tag_python(self): |
| 23 | + assert parse_version_from_tag("v13.1.0", "cuda-python") == "13.1.0" |
| 24 | + |
| 25 | + def test_component_prefix_core(self): |
| 26 | + assert parse_version_from_tag("cuda-core-v0.7.0", "cuda-core") == "0.7.0" |
| 27 | + |
| 28 | + def test_component_prefix_pathfinder(self): |
| 29 | + assert parse_version_from_tag("cuda-pathfinder-v1.5.2", "cuda-pathfinder") == "1.5.2" |
| 30 | + |
| 31 | + def test_post_release(self): |
| 32 | + assert parse_version_from_tag("v12.6.2.post1", "cuda-bindings") == "12.6.2.post1" |
| 33 | + |
| 34 | + def test_invalid_tag(self): |
| 35 | + assert parse_version_from_tag("not-a-tag", "cuda-core") is None |
| 36 | + |
| 37 | + def test_no_v_prefix(self): |
| 38 | + assert parse_version_from_tag("13.1.0", "cuda-bindings") is None |
| 39 | + |
| 40 | + def test_component_prefix_mismatch(self): |
| 41 | + # cuda-core-v* must not be accepted for component=cuda-pathfinder |
| 42 | + assert parse_version_from_tag("cuda-core-v0.7.0", "cuda-pathfinder") is None |
| 43 | + |
| 44 | + def test_bare_v_rejected_for_core(self): |
| 45 | + # bare v* belongs to cuda-bindings/cuda-python, not cuda-core |
| 46 | + assert parse_version_from_tag("v0.7.0", "cuda-core") is None |
| 47 | + |
| 48 | + def test_unknown_component(self): |
| 49 | + assert parse_version_from_tag("v13.1.0", "bogus") is None |
| 50 | + |
| 51 | + def test_path_traversal_rejected(self): |
| 52 | + assert parse_version_from_tag("v1.0.0/../evil", "cuda-bindings") is None |
| 53 | + |
| 54 | + def test_path_separator_rejected(self): |
| 55 | + assert parse_version_from_tag("v1/2/3", "cuda-bindings") is None |
| 56 | + |
| 57 | + def test_leading_dot_rejected(self): |
| 58 | + assert parse_version_from_tag("v.1.0", "cuda-bindings") is None |
| 59 | + |
| 60 | + def test_whitespace_rejected(self): |
| 61 | + assert parse_version_from_tag("v1.0.0 ", "cuda-bindings") is None |
| 62 | + |
| 63 | + def test_trailing_suffix_rejected(self): |
| 64 | + # \w permits alphanumerics + underscore only; hyphens and shell meta-chars are out |
| 65 | + assert parse_version_from_tag("v1.0.0-extra", "cuda-bindings") is None |
| 66 | + |
| 67 | + |
| 68 | +class TestIsPostRelease: |
| 69 | + def test_normal(self): |
| 70 | + assert not is_post_release("13.1.0") |
| 71 | + |
| 72 | + def test_post(self): |
| 73 | + assert is_post_release("12.6.2.post1") |
| 74 | + |
| 75 | + def test_post_no_number(self): |
| 76 | + assert is_post_release("1.0.0.post") |
| 77 | + |
| 78 | + |
| 79 | +class TestCheckReleaseNotes: |
| 80 | + def _make_notes(self, tmp_path, pkg, version, content="Release notes."): |
| 81 | + d = tmp_path / pkg / "docs" / "source" / "release" |
| 82 | + d.mkdir(parents=True, exist_ok=True) |
| 83 | + f = d / f"{version}-notes.rst" |
| 84 | + f.write_text(content) |
| 85 | + return f |
| 86 | + |
| 87 | + def test_present_and_nonempty(self, tmp_path): |
| 88 | + self._make_notes(tmp_path, "cuda_core", "0.7.0") |
| 89 | + problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path)) |
| 90 | + assert problems == [] |
| 91 | + |
| 92 | + def test_missing(self, tmp_path): |
| 93 | + problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path)) |
| 94 | + assert len(problems) == 1 |
| 95 | + assert problems[0][1] == "missing" |
| 96 | + |
| 97 | + def test_empty(self, tmp_path): |
| 98 | + self._make_notes(tmp_path, "cuda_core", "0.7.0", content="") |
| 99 | + problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path)) |
| 100 | + assert len(problems) == 1 |
| 101 | + assert problems[0][1] == "empty" |
| 102 | + |
| 103 | + def test_post_release_skipped(self, tmp_path): |
| 104 | + problems = check_release_notes("v12.6.2.post1", "cuda-bindings", str(tmp_path)) |
| 105 | + assert problems == [] |
| 106 | + |
| 107 | + def test_invalid_tag(self, tmp_path): |
| 108 | + problems = check_release_notes("not-a-tag", "cuda-core", str(tmp_path)) |
| 109 | + assert len(problems) == 1 |
| 110 | + assert "cannot parse" in problems[0][1] |
| 111 | + |
| 112 | + def test_component_prefix_mismatch(self, tmp_path): |
| 113 | + # Pass a cuda-core tag with component=cuda-pathfinder; must be rejected. |
| 114 | + problems = check_release_notes("cuda-core-v0.7.0", "cuda-pathfinder", str(tmp_path)) |
| 115 | + assert len(problems) == 1 |
| 116 | + assert "cannot parse" in problems[0][1] |
| 117 | + |
| 118 | + def test_unknown_component(self, tmp_path): |
| 119 | + problems = check_release_notes("v13.1.0", "bogus", str(tmp_path)) |
| 120 | + assert len(problems) == 1 |
| 121 | + assert "unknown component" in problems[0][1] |
| 122 | + |
| 123 | + def test_plain_v_tag(self, tmp_path): |
| 124 | + self._make_notes(tmp_path, "cuda_python", "13.1.0") |
| 125 | + problems = check_release_notes("v13.1.0", "cuda-python", str(tmp_path)) |
| 126 | + assert problems == [] |
| 127 | + |
| 128 | + |
| 129 | +class TestMain: |
| 130 | + def test_success(self, tmp_path): |
| 131 | + d = tmp_path / "cuda_core" / "docs" / "source" / "release" |
| 132 | + d.mkdir(parents=True) |
| 133 | + (d / "0.7.0-notes.rst").write_text("Notes here.") |
| 134 | + rc = main(["--git-tag", "cuda-core-v0.7.0", "--component", "cuda-core", "--repo-root", str(tmp_path)]) |
| 135 | + assert rc == 0 |
| 136 | + |
| 137 | + def test_failure(self, tmp_path): |
| 138 | + rc = main(["--git-tag", "cuda-core-v0.7.0", "--component", "cuda-core", "--repo-root", str(tmp_path)]) |
| 139 | + assert rc == 1 |
| 140 | + |
| 141 | + def test_post_skip(self, tmp_path): |
| 142 | + rc = main(["--git-tag", "v12.6.2.post1", "--component", "cuda-bindings", "--repo-root", str(tmp_path)]) |
| 143 | + assert rc == 0 |
| 144 | + |
| 145 | + def test_unparsable_tag_returns_2(self, tmp_path): |
| 146 | + rc = main(["--git-tag", "not-a-tag", "--component", "cuda-core", "--repo-root", str(tmp_path)]) |
| 147 | + assert rc == 2 |
| 148 | + |
| 149 | + def test_path_traversal_returns_2(self, tmp_path): |
| 150 | + rc = main(["--git-tag", "v1.0.0/../evil", "--component", "cuda-bindings", "--repo-root", str(tmp_path)]) |
| 151 | + assert rc == 2 |
| 152 | + |
| 153 | + def test_component_prefix_mismatch_returns_2(self, tmp_path): |
| 154 | + rc = main( |
| 155 | + [ |
| 156 | + "--git-tag", |
| 157 | + "cuda-core-v0.7.0", |
| 158 | + "--component", |
| 159 | + "cuda-pathfinder", |
| 160 | + "--repo-root", |
| 161 | + str(tmp_path), |
| 162 | + ] |
| 163 | + ) |
| 164 | + assert rc == 2 |
0 commit comments