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
@@ -13,6 +13,7 @@ from unittest import mock
|
||||
SCRIPTS = pathlib.Path(__file__).resolve().parents[2] / "scripts"
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
import check_bot_pr_diff as cbd
|
||||
from test_check_uv_lock import APM_NEW, APM_OLD, CLICK_OLD, UV_LOCK, uv_files
|
||||
|
||||
D1, D2 = "sha256:" + "a" * 64, "sha256:" + "b" * 64
|
||||
FILES = {
|
||||
@@ -30,6 +31,7 @@ FILES = {
|
||||
".gitea/workflows/lint.yml": f"container:\n image: git.rkdr.net/mortis/ci:0.2.0@{D1}\nrun: echo a\n",
|
||||
".gitea/workflows/molecule.yml": f"env:\n MOLECULE_IMAGE: >-\n git.rkdr.net/mortis/mol:0.1.0@{D1}\n",
|
||||
"renovate.json": "{}\n",
|
||||
"pyproject.toml": '[project]\nrequires-python = ">=3.11"\n\n[dependency-groups]\ndev = ["apm-cli==0.39.3"]\n',
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +51,7 @@ def run(cwd, *cmd):
|
||||
|
||||
|
||||
H1, H2 = "a" * 64, "b" * 64
|
||||
FILES["uv.lock"] = UV_LOCK
|
||||
|
||||
|
||||
class LockRuleTest(unittest.TestCase):
|
||||
@@ -113,6 +116,69 @@ class LockRuleTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class PyprojectRuleTest(unittest.TestCase):
|
||||
def test_an_apm_cli_bump_is_allowed(self):
|
||||
self.assertIsNone(
|
||||
cbd.file_problem(
|
||||
"pyproject.toml",
|
||||
['dev = ["apm-cli==0.39.3"]'],
|
||||
['dev = ["apm-cli==0.39.4"]'],
|
||||
)
|
||||
)
|
||||
|
||||
def test_a_new_dependency_is_refused(self):
|
||||
old = 'dev = ["apm-cli==0.39.3"]'
|
||||
for new in (
|
||||
'dev = ["apm-cli==0.39.4", "evil==1.0"]',
|
||||
'dev = ["evil==0.39.4"]',
|
||||
'dev = ["apm-cli==0.39.4"]\nprod = ["evil==1.0"]',
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assertIsNotNone(
|
||||
cbd.file_problem("pyproject.toml", [old], new.split("\n"))
|
||||
)
|
||||
|
||||
def test_a_pinned_name_keeps_its_spelling(self):
|
||||
self.assertIsNotNone(
|
||||
cbd.file_problem(
|
||||
"pyproject.toml",
|
||||
['dev = ["apm-cli==0.39.3"]'],
|
||||
['dev = ["APM-CLI==0.39.4"]'],
|
||||
)
|
||||
)
|
||||
|
||||
def test_an_edit_to_another_setting_is_refused(self):
|
||||
for old, new in (
|
||||
('requires-python = ">=3.11"', 'requires-python = ">=3.12"'),
|
||||
("package = false", "package = true"),
|
||||
(
|
||||
'dev = ["apm-cli==0.39.3"]',
|
||||
'dev = ["apm-cli @ https://evil.example/apm.tgz"]',
|
||||
),
|
||||
(
|
||||
'dev = ["apm-cli==0.39.3"]',
|
||||
'dev = ["apm-cli==0.39.4"] # index-url = "https://evil/simple"',
|
||||
),
|
||||
):
|
||||
with self.subTest(new=new):
|
||||
self.assertIsNotNone(cbd.file_problem("pyproject.toml", [old], [new]))
|
||||
|
||||
|
||||
class UvLockTest(unittest.TestCase):
|
||||
def test_uv_lock_is_refused_without_both_sides_to_parse(self):
|
||||
entries = [
|
||||
("100644", "100644", "M", "pyproject.toml"),
|
||||
("100644", "100644", "M", "uv.lock"),
|
||||
]
|
||||
patches = {
|
||||
"pyproject.toml": '@@ -1 +1 @@\n-dev = ["apm-cli==0.39.3"]\n+dev = ["apm-cli==0.39.4"]\n',
|
||||
"uv.lock": "@@ -1 +1 @@\n-revision = 3\n+revision = 5\n",
|
||||
}
|
||||
problems = cbd.check(entries, patches.get)
|
||||
self.assertEqual(len(problems), 1, problems)
|
||||
self.assertTrue(problems[0].startswith("uv.lock: "), problems)
|
||||
|
||||
|
||||
class RuleTest(unittest.TestCase):
|
||||
def problem(self, path, old, new):
|
||||
return cbd.file_problem(path, [old], [new])
|
||||
@@ -499,6 +565,109 @@ class RepoTest(unittest.TestCase):
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("5 file(s)", out)
|
||||
|
||||
def bump_apm_cli(self):
|
||||
"""The change Renovate makes for apm-cli 0.39.4, as uv 0.13.1 writes it."""
|
||||
self.edit("pyproject.toml", "apm-cli==0.39.3", "apm-cli==0.39.4")
|
||||
self.edit("uv.lock", 'version = "0.39.3"', 'version = "0.39.4"')
|
||||
self.edit("uv.lock", '"==0.39.3"', '"==0.39.4"')
|
||||
self.edit("uv.lock", "apm_cli-0.39.3", "apm_cli-0.39.4")
|
||||
self.edit("uv.lock", APM_OLD, APM_NEW)
|
||||
|
||||
def assert_lock_refused(self):
|
||||
self.commit("bot")
|
||||
code, _unused, err = self.gate()
|
||||
self.assertEqual(code, 1, err)
|
||||
self.assertIn("uv.lock", err)
|
||||
|
||||
def test_an_apm_cli_bump_with_its_lock_passes(self):
|
||||
self.bump_apm_cli()
|
||||
self.commit("bot")
|
||||
code, out, err = self.gate()
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("2 file(s)", out)
|
||||
|
||||
def test_another_packages_file_under_the_apm_cli_entry_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
lock = (self.repo / "uv.lock").read_text()
|
||||
start = lock.index('version = "0.39.4"')
|
||||
end = lock.index("[[package]]", start)
|
||||
six = (
|
||||
'version = "1.17.0"\nsource = { registry = "https://pypi.org/simple" }\n'
|
||||
'dependencies = [\n { name = "click" },\n { name = "watchdog" },\n]\n'
|
||||
'wheels = [\n { url = "https://files.pythonhosted.org/packages/b7/ce/'
|
||||
'149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", '
|
||||
'hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", '
|
||||
'size = 11050, upload-time = "2024-12-04T17:35:26.475Z" },\n]\n\n'
|
||||
)
|
||||
self.write("uv.lock", lock[:start] + six + lock[end:])
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_new_package_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit(
|
||||
"uv.lock",
|
||||
'dev = [\n { name = "apm-cli" },\n]',
|
||||
'dev = [\n { name = "apm-cli" },\n { name = "six" },\n]',
|
||||
)
|
||||
self.write(
|
||||
"uv.lock",
|
||||
(self.repo / "uv.lock").read_text()
|
||||
+ '\n[[package]]\nname = "six"\nversion = "1.17.0"\n'
|
||||
'source = { registry = "https://pypi.org/simple" }\n'
|
||||
+ uv_files("six", "1.17.0", H2),
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_marker_that_drops_a_dependency_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit(
|
||||
"uv.lock",
|
||||
' { name = "watchdog" },',
|
||||
' { name = "watchdog", marker = "sys_platform == \'never\'" },',
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_downgraded_transitive_package_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit("uv.lock", 'version = "8.5.1"', 'version = "8.5.0"')
|
||||
self.edit("uv.lock", "click-8.5.1", "click-8.5.0")
|
||||
self.edit("uv.lock", CLICK_OLD, H2)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_pyproject_change_without_its_lock_is_refused(self):
|
||||
self.edit("pyproject.toml", "apm-cli==0.39.3", "apm-cli==0.39.4")
|
||||
self.commit("bot")
|
||||
code, _unused, err = self.gate()
|
||||
self.assertEqual(code, 1, err)
|
||||
self.assertIn("pyproject.toml", err)
|
||||
|
||||
def test_an_apm_cli_lock_change_without_pyproject_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit("pyproject.toml", "apm-cli==0.39.4", "apm-cli==0.39.3")
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_changed_apm_cli_source_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
lock = (self.repo / "uv.lock").read_text()
|
||||
start = lock.index('name = "apm-cli"')
|
||||
self.write(
|
||||
"uv.lock",
|
||||
lock[:start]
|
||||
+ lock[start:].replace(
|
||||
"https://pypi.org/simple", "https://evil.example/simple", 1
|
||||
),
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_a_changed_apm_cli_download_host_is_refused(self):
|
||||
self.bump_apm_cli()
|
||||
self.edit(
|
||||
"uv.lock",
|
||||
"https://files.pythonhosted.org/packages/ab/cd/apm_cli-0.39.4-py3",
|
||||
"https://files.evil.example/packages/ab/cd/apm_cli-0.39.4-py3",
|
||||
)
|
||||
self.assert_lock_refused()
|
||||
|
||||
def test_each_violation_gets_one_line(self):
|
||||
self.edit(".gitea/workflows/lint.yml", "echo a", "echo b")
|
||||
self.write("roles/x/main.yml", "a\n")
|
||||
|
||||
Reference in new issue
Block a user