ci(lint): accept an apm-cli bump in the bot-diff check
A Renovate pull request may now change pyproject.toml and uv.lock, but only together, so the pep621 manager can move the apm pin. In pyproject.toml only the version of a quoted name==version pin may change. uv.lock is parsed with tomllib in a module of its own, check_uv_lock.py, because uv installs whatever the lock names and a line-shape rule cannot tie a file to its package: a file of another package under apm-cli, an added package, a marker that drops a dependency and a downgrade all passed one. The parsed rule allows only apm-cli moving up to the pin in pyproject.toml, as plain releases compared as numbers, with the same kinds of file as before (an sdist if it had one, the same wheel tags), each on files.pythonhosted.org under /packages/ without dot segments or escapes, named for apm-cli at the pin, by sha256. Every other package, the root project beyond its apm-cli specifier and the top level beyond `revision` must stay as they are. Without the same file kinds, a lock could drop the wheels and make uv build apm-cli from its sdist with a build backend fetched at sync time. A bump that moves anything else is made by hand. Refs: #518 Assisted-by: Claude Code
This commit is contained in:
1 parent
535926b36e
commit
47641ae01d
7 files changed
+754
-10
No files matched your search
@@ -0,0 +1,321 @@
|
||||
# SPDX-FileCopyrightText: Defame1297 and contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Run with: python3 -m unittest discover -s tests/scripts"""
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
import check_uv_lock as cul
|
||||
|
||||
APM_OLD, APM_NEW, CLICK_OLD, OTHER = "c" * 64, "d" * 64, "e" * 64, "f" * 64
|
||||
PYPI_FILES = "https://files.pythonhosted.org/packages/ab/cd/"
|
||||
|
||||
|
||||
def uv_files(dist, version, digest):
|
||||
return (
|
||||
f'sdist = {{ url = "{PYPI_FILES}{dist}-{version}.tar.gz", hash = "sha256:{digest}", '
|
||||
f'size = 3132901, upload-time = "2026-12-01T18:11:22.037Z" }}\n'
|
||||
f'wheels = [\n {{ url = "{PYPI_FILES}{dist}-{version}-py3-none-any.whl", '
|
||||
f'hash = "sha256:{digest}", size = 3536708, upload-time = "2026-12-01T18:11:19.761Z" }},\n]\n'
|
||||
)
|
||||
|
||||
|
||||
# A uv.lock as uv 0.13.1 writes it: apm-cli, two of its dependencies and the root project.
|
||||
UV_LOCK = (
|
||||
'version = 1\nrevision = 5\nrequires-python = ">=3.11"\n\n'
|
||||
'[[package]]\nname = "apm-cli"\nversion = "0.39.3"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
'dependencies = [\n { name = "click" },\n { name = "watchdog" },\n]\n'
|
||||
+ uv_files("apm_cli", "0.39.3", APM_OLD)
|
||||
+ '\n[[package]]\nname = "click"\nversion = "8.5.1"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("click", "8.5.1", CLICK_OLD)
|
||||
+ '\n[[package]]\nname = "kamino"\nversion = "0"\nsource = { virtual = "." }\n\n'
|
||||
'[package.dev-dependencies]\ndev = [\n { name = "apm-cli" },\n]\n\n'
|
||||
"[package.metadata]\n\n[package.metadata.requires-dev]\n"
|
||||
'dev = [{ name = "apm-cli", specifier = "==0.39.3" }]\n'
|
||||
'\n[[package]]\nname = "watchdog"\nversion = "7.1.1"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("watchdog", "7.1.1", OTHER)
|
||||
)
|
||||
PYPROJECT = (
|
||||
'[project]\nname = "kamino"\n\n[dependency-groups]\ndev = ["apm-cli==VERSION"]\n'
|
||||
)
|
||||
|
||||
|
||||
def bumped(lock=UV_LOCK):
|
||||
"""The lock after Renovate's apm-cli 0.39.4 bump."""
|
||||
return (
|
||||
lock.replace('version = "0.39.3"', 'version = "0.39.4"')
|
||||
.replace('"==0.39.3"', '"==0.39.4"')
|
||||
.replace("apm_cli-0.39.3", "apm_cli-0.39.4")
|
||||
.replace(APM_OLD, APM_NEW)
|
||||
)
|
||||
|
||||
|
||||
def problem(new, pin="0.39.4", old=UV_LOCK):
|
||||
return cul.lock_problem(old, new, PYPROJECT.replace("VERSION", pin))
|
||||
|
||||
|
||||
class AllowedTest(unittest.TestCase):
|
||||
def test_an_apm_cli_bump_is_allowed(self):
|
||||
self.assertIsNone(problem(bumped()))
|
||||
|
||||
def test_a_new_lock_revision_is_allowed(self):
|
||||
old = UV_LOCK.replace("revision = 5", "revision = 3")
|
||||
self.assertIsNone(problem(bumped(), old=old))
|
||||
|
||||
def test_a_package_without_an_sdist_is_allowed(self):
|
||||
start = UV_LOCK.index("sdist = { url")
|
||||
old = UV_LOCK[:start] + UV_LOCK[UV_LOCK.index("wheels = [", start) :]
|
||||
self.assertIsNone(problem(bumped(old), old=old))
|
||||
|
||||
|
||||
class RefusedTest(unittest.TestCase):
|
||||
def assert_refused(self, new, **kwargs):
|
||||
self.assertIsNotNone(problem(new, **kwargs))
|
||||
|
||||
def test_a_lock_that_is_not_toml_is_refused(self):
|
||||
self.assert_refused(bumped() + "[[package\n")
|
||||
|
||||
def test_a_lock_of_another_shape_is_refused(self):
|
||||
top = 'version = 1\nrevision = 5\nrequires-python = ">=3.11"\n'
|
||||
for package in ('package = ["x"]\n', "package = 1\n"):
|
||||
with self.subTest(package=package):
|
||||
self.assertEqual(
|
||||
problem(top + package), "the lock does not have the shape uv writes"
|
||||
)
|
||||
|
||||
def test_the_lock_version_must_be_the_pin(self):
|
||||
self.assert_refused(bumped(), pin="0.39.5")
|
||||
self.assert_refused(
|
||||
bumped().replace('version = "0.39.4"', 'version = "0.39.5"')
|
||||
)
|
||||
|
||||
def test_the_dev_specifier_must_be_the_pin(self):
|
||||
self.assert_refused(bumped().replace('"==0.39.4"', '"==0.39.3"'))
|
||||
self.assert_refused(bumped().replace('"==0.39.4"', '">=0.39.4"'))
|
||||
|
||||
def test_a_pyproject_without_one_apm_cli_pin_is_refused(self):
|
||||
for pyproject in (
|
||||
'[dependency-groups]\ndev = ["apm-cli>=0.39.4"]\n',
|
||||
'[dependency-groups]\ndev = ["apm-cli==0.39.4", "apm-cli==0.39.5"]\n',
|
||||
"[dependency-groups]\ndev = [\n",
|
||||
):
|
||||
with self.subTest(pyproject=pyproject):
|
||||
self.assertIsNotNone(cul.lock_problem(UV_LOCK, bumped(), pyproject))
|
||||
|
||||
def test_another_top_level_setting_is_refused(self):
|
||||
for old, new in (
|
||||
('requires-python = ">=3.11"', 'requires-python = ">=3.12"'),
|
||||
("version = 1\n", "version = 2\n"),
|
||||
("revision = 5", 'revision = "5"'),
|
||||
(
|
||||
"revision = 5",
|
||||
'revision = 5\n[options]\nexclude-newer = "2026-01-01T00:00:00Z"',
|
||||
),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(bumped().replace(old, new, 1))
|
||||
|
||||
def test_an_apm_cli_dependency_change_is_refused(self):
|
||||
for new in (
|
||||
' { name = "click" },\n { name = "watchdog" },\n { name = "six" },\n',
|
||||
' { name = "click" },\n',
|
||||
' { name = "click", marker = "sys_platform == \'never\'" },\n { name = "watchdog" },\n',
|
||||
' { name = "click", extra = ["evil"] },\n { name = "watchdog" },\n',
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(
|
||||
bumped().replace(
|
||||
' { name = "click" },\n { name = "watchdog" },\n', new, 1
|
||||
)
|
||||
)
|
||||
|
||||
def test_a_changed_apm_cli_source_is_refused(self):
|
||||
lock = bumped()
|
||||
start = lock.index('name = "apm-cli"')
|
||||
for source in (
|
||||
'source = { registry = "https://evil.example/simple" }',
|
||||
'source = { git = "https://evil.example/apm.git?rev=main#0123abc" }',
|
||||
'source = { url = "https://evil.example/apm_cli-0.39.4.tar.gz" }',
|
||||
):
|
||||
with self.subTest(source=source):
|
||||
self.assert_refused(
|
||||
lock[:start]
|
||||
+ lock[start:].replace(
|
||||
'source = { registry = "https://pypi.org/simple" }', source, 1
|
||||
)
|
||||
)
|
||||
|
||||
def test_a_file_that_is_not_the_pinned_apm_cli_from_pypi_is_refused(self):
|
||||
wheel = f"{PYPI_FILES}apm_cli-0.39.4-py3-none-any.whl"
|
||||
for old, new in (
|
||||
(wheel, wheel.replace("files.pythonhosted.org", "files.evil.example")),
|
||||
(wheel, wheel.replace("https://", "http://")),
|
||||
(
|
||||
wheel,
|
||||
wheel.replace(
|
||||
"files.pythonhosted.org", "files.pythonhosted.org.evil.example"
|
||||
),
|
||||
),
|
||||
(wheel, wheel.replace("/packages/", "/other/")),
|
||||
(wheel, wheel + "?x=/packages/apm_cli-0.39.4-py3-none-any.whl"),
|
||||
(wheel, wheel.replace("apm_cli-0.39.4", "six-1.17.0")),
|
||||
(wheel, wheel.replace("apm_cli-0.39.4", "apm_cli-0.39.3")),
|
||||
(wheel, wheel.replace("apm_cli-0.39.4", "apm_cli-0.39.40")),
|
||||
(wheel, wheel.replace(".whl", ".exe")),
|
||||
(f"sha256:{APM_NEW}", "md5:" + "d" * 32),
|
||||
(f"sha256:{APM_NEW}", "sha256:" + "d" * 63),
|
||||
(f"sha256:{APM_NEW}", "sha256:" + "D" * 64),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(bumped().replace(old, new))
|
||||
|
||||
def test_a_file_with_another_key_is_refused(self):
|
||||
wheel = f'{{ url = "{PYPI_FILES}apm_cli-0.39.4-py3-none-any.whl", '
|
||||
self.assert_refused(
|
||||
bumped().replace(wheel, wheel + 'path = "../evil.whl", ', 1)
|
||||
)
|
||||
|
||||
def test_an_apm_cli_without_files_is_refused(self):
|
||||
lock = bumped()
|
||||
start = lock.index("sdist = { url", lock.index('name = "apm-cli"'))
|
||||
end = lock.index("]\n", start) + 2
|
||||
self.assert_refused(lock[:start] + lock[end:])
|
||||
|
||||
def test_a_change_to_another_package_is_refused(self):
|
||||
for old, new in (
|
||||
('version = "8.5.1"', 'version = "8.5.0"'),
|
||||
(CLICK_OLD, OTHER),
|
||||
(
|
||||
'name = "watchdog"\n',
|
||||
'name = "watchdog"\ndependencies = [{ name = "click" }]\n',
|
||||
),
|
||||
(
|
||||
'version = "0"\nsource = { virtual = "." }',
|
||||
'version = "1"\nsource = { virtual = "." }',
|
||||
),
|
||||
(
|
||||
'dev = [\n { name = "apm-cli" },\n]',
|
||||
'dev = [\n { name = "apm-cli" },\n { name = "click" },\n]',
|
||||
),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assert_refused(bumped().replace(old, new, 1))
|
||||
|
||||
def test_an_added_or_removed_package_is_refused(self):
|
||||
six = (
|
||||
'\n[[package]]\nname = "six"\nversion = "1.17.0"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("six", "1.17.0", OTHER)
|
||||
)
|
||||
self.assert_refused(bumped() + six)
|
||||
watchdog = bumped().index('\n[[package]]\nname = "watchdog"')
|
||||
self.assert_refused(bumped()[:watchdog])
|
||||
|
||||
def test_a_second_apm_cli_or_root_entry_is_refused(self):
|
||||
apm = bumped()
|
||||
start = apm.index('[[package]]\nname = "apm-cli"')
|
||||
end = apm.index("[[package]]", start + 1)
|
||||
self.assert_refused(apm + "\n" + apm[start:end])
|
||||
root = apm.index('[[package]]\nname = "kamino"')
|
||||
self.assert_refused(
|
||||
apm
|
||||
+ '\n[[package]]\nname = "other"\nversion = "0"\nsource = { virtual = "." }\n',
|
||||
old=UV_LOCK
|
||||
+ '\n[[package]]\nname = "other"\nversion = "0"\nsource = { virtual = "." }\n',
|
||||
)
|
||||
self.assertGreater(root, 0)
|
||||
|
||||
|
||||
def moved(lock, old, new):
|
||||
"""lock with apm-cli moved from version old to new."""
|
||||
return (
|
||||
lock.replace(f'version = "{old}"', f'version = "{new}"')
|
||||
.replace(f'"=={old}"', f'"=={new}"')
|
||||
.replace(f"apm_cli-{old}", f"apm_cli-{new}")
|
||||
)
|
||||
|
||||
|
||||
def without_apm_wheels(lock):
|
||||
start = lock.index("wheels = [", lock.index('name = "apm-cli"'))
|
||||
return lock[:start] + lock[lock.index("]\n", start) + 2 :]
|
||||
|
||||
|
||||
class FileKindsAndOrderTest(unittest.TestCase):
|
||||
def test_dropped_wheels_without_a_version_change_are_refused(self):
|
||||
new = without_apm_wheels(UV_LOCK).replace("size = 3132901", "size = 3132902", 1)
|
||||
self.assertIsNotNone(problem(new, pin="0.39.3"))
|
||||
|
||||
def test_a_downgrade_is_refused(self):
|
||||
self.assertIsNotNone(problem(UV_LOCK, pin="0.39.3", old=bumped()))
|
||||
|
||||
def test_the_version_must_rise(self):
|
||||
self.assertIsNotNone(problem(UV_LOCK.replace(APM_OLD, APM_NEW), pin="0.39.3"))
|
||||
|
||||
def test_versions_are_compared_as_numbers(self):
|
||||
old = moved(UV_LOCK, "0.39.3", "0.39.9")
|
||||
self.assertIsNone(
|
||||
problem(moved(old, "0.39.9", "0.39.10"), pin="0.39.10", old=old)
|
||||
)
|
||||
old = moved(UV_LOCK, "0.39.3", "0.9.0")
|
||||
self.assertIsNone(problem(moved(old, "0.9.0", "0.10.0"), pin="0.10.0", old=old))
|
||||
old = moved(UV_LOCK, "0.39.3", "0.40.0")
|
||||
self.assertIsNotNone(
|
||||
problem(moved(old, "0.40.0", "0.39.10"), pin="0.39.10", old=old)
|
||||
)
|
||||
|
||||
def test_a_version_that_is_not_a_plain_release_is_refused(self):
|
||||
for version in (
|
||||
"0.40.0rc1",
|
||||
"0.40.0.post1",
|
||||
"0.40.0.dev1",
|
||||
"1!0.1.0",
|
||||
"0.40.0+local",
|
||||
):
|
||||
with self.subTest(version=version):
|
||||
self.assertIsNotNone(
|
||||
problem(moved(UV_LOCK, "0.39.3", version), pin=version)
|
||||
)
|
||||
|
||||
def test_the_kinds_of_file_stay_the_same(self):
|
||||
self.assertIsNotNone(problem(without_apm_wheels(bumped())))
|
||||
start = bumped().index("sdist = { url", bumped().index('name = "apm-cli"'))
|
||||
no_sdist = bumped()[:start] + bumped()[bumped().index("wheels = [", start) :]
|
||||
self.assertIsNotNone(problem(no_sdist))
|
||||
old_no_sdist = (
|
||||
UV_LOCK[: UV_LOCK.index("sdist = { url")]
|
||||
+ UV_LOCK[UV_LOCK.index("wheels = [") :]
|
||||
)
|
||||
self.assertIsNotNone(problem(bumped(), old=old_no_sdist))
|
||||
self.assertIsNone(problem(no_sdist, old=old_no_sdist))
|
||||
for tag in ("cp311-cp311-manylinux_2_17_x86_64", "py2.py3-none-any"):
|
||||
with self.subTest(tag=tag):
|
||||
self.assertIsNotNone(
|
||||
problem(bumped().replace("0.39.4-py3-none-any", f"0.39.4-{tag}"))
|
||||
)
|
||||
|
||||
def test_a_path_that_leaves_packages_is_refused(self):
|
||||
wheel = f"{PYPI_FILES}apm_cli-0.39.4-py3-none-any.whl"
|
||||
for path in (
|
||||
"/packages/../../simple/x/",
|
||||
"/packages/ab/./cd/",
|
||||
"/packages//ab/",
|
||||
"/packages/%2e%2e/%2e%2e/simple/x/",
|
||||
"/packages/ab/cd%2F/",
|
||||
):
|
||||
with self.subTest(path=path):
|
||||
bad = (
|
||||
"https://files.pythonhosted.org"
|
||||
+ path
|
||||
+ "apm_cli-0.39.4-py3-none-any.whl"
|
||||
)
|
||||
self.assertIsNotNone(problem(bumped().replace(wheel, bad)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user