Merge origin/main into fix/branch-cleanup-held-once
CI / quality (push) Skipped
CI / security-codeql (push) Blocked by required conditions
CodeQL Advanced / Check security (none, actions) (push) Blocked by required conditions
CodeQL Advanced / Check security (none, python) (push) Blocked by required conditions
CI / test-unit (push) Blocked by required conditions
Test Units / test-unit (push) Blocked by required conditions
CI / test-integration (push) Blocked by required conditions
Test Code Integration / test-integration (push) Blocked by required conditions
CI / test-env-virtual (push) Blocked by required conditions
Test OS Containers / test-env-virtual (arch) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (centos) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (debian) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (fedora) (push) Blocked by required conditions
Test OS Containers / test-env-virtual (ubuntu) (push) Blocked by required conditions
CI / test-env-nix (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (arch) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (centos) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (debian) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (fedora) (push) Blocked by required conditions
Test Virgin Nix (flake only) / test-env-nix (ubuntu) (push) Blocked by required conditions
CI / test-e2e (push) Blocked by required conditions
Test End-To-End / test-e2e (arch) (push) Blocked by required conditions
Test End-To-End / test-e2e (centos) (push) Blocked by required conditions
Test End-To-End / test-e2e (debian) (push) Blocked by required conditions
Test End-To-End / test-e2e (fedora) (push) Blocked by required conditions
Test End-To-End / test-e2e (ubuntu) (push) Blocked by required conditions
CI / test-virgin-user (push) Blocked by required conditions
Test Virgin User / test-virgin-user (arch) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (centos) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (debian) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (fedora) (push) Blocked by required conditions
Test Virgin User / test-virgin-user (ubuntu) (push) Blocked by required conditions
CI / test-virgin-root (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (arch) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (centos) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (debian) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (fedora) (push) Blocked by required conditions
Test Virgin Root / test-virgin-root (ubuntu) (push) Blocked by required conditions
CI / lint-shell (push) Blocked by required conditions
ShellCheck / lint-shell (push) Blocked by required conditions
CI / lint-python (push) Blocked by required conditions
Ruff (Python code sniffer) / lint-python (push) Blocked by required conditions
CI / lint-docker (push) Blocked by required conditions
Docker Linter / Lint Dockerfile (push) Blocked by required conditions

Brings the 11-14 held-branches fix (e017af0) up to main 895ec2f; clean merge, no conflicts. test_branch_cleanup_local passes 76/76 on the merge and both new tests fail on the unfixed main on the held-branches read count.

🎯 Fix: 90 %
💥 Break: 3 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 87
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-28 09:35:52 +00:00
commit 5e08847286
7 files changed
+381 -43

No files matched your search

@@ -0,0 +1,124 @@
import os
import shutil
import sys
import tempfile
import unittest
from contextlib import ExitStack
from unittest.mock import MagicMock, patch
from pkgmgr.actions.publish.workflow import publish
class TestPublishWorkflowChildren(unittest.TestCase):
def publish_with(self, mirror: str, environ: dict) -> tuple[list, str]:
"""
Args:
mirror: the PyPI project URL of the mirrors file.
environ: extra environment variables of the pkgmgr process;
"{repo}" in a value becomes the repository directory.
Returns:
The recorded subprocess.run calls and the repository directory,
whose dist is a symlink to a foreign directory with an old
artifact.
"""
repo_dir = tempfile.mkdtemp()
foreign = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, repo_dir)
self.addCleanup(shutil.rmtree, foreign)
with open(os.path.join(foreign, "example-0.9.0.tar.gz"), "w"):
pass
os.symlink(foreign, os.path.join(repo_dir, "dist"))
def run(argv, *_args, **kwargs):
if argv[2] == "build" and "--help" not in argv:
if "--outdir" in argv:
out = argv[argv.index("--outdir") + 1]
else:
out = os.path.join(kwargs["cwd"], "dist")
with open(os.path.join(out, "example-1.0.0.tar.gz"), "w"):
pass
return kwargs
module = "pkgmgr.actions.publish.workflow"
with ExitStack() as stack:
stack.enter_context(
patch(f"{module}.read_mirrors_file", return_value={"pypi": mirror})
)
stack.enter_context(
patch(f"{module}.head_semver_tags", return_value=["v1.0.0"])
)
resolver = stack.enter_context(patch(f"{module}.TokenResolver"))
mock_run = stack.enter_context(
patch(f"{module}.subprocess.run", side_effect=run)
)
stack.enter_context(
patch.dict(
os.environ,
{
name: value.format(repo=repo_dir)
for name, value in environ.items()
},
)
)
resolver.return_value.get_token.return_value = MagicMock(token="t")
publish(repo={}, repo_dir=repo_dir, interactive=False, allow_prompt=False)
return mock_run.call_args_list, repo_dir
def test_every_child_runs_under_the_current_interpreter(self):
calls, _ = self.publish_with("https://pypi.org/project/example/", {})
argvs = [call.args[0] for call in calls]
self.assertEqual(
[argv[2] for argv in argvs], ["build", "twine", "build", "twine"]
)
self.assertEqual({argv[0] for argv in argvs}, {sys.executable})
def test_children_never_run_in_the_repository(self):
calls, repo_dir = self.publish_with("https://pypi.org/project/example/", {})
cwds = {call.kwargs["cwd"] for call in calls}
self.assertEqual(len(cwds), 1)
self.assertNotEqual(os.path.realpath(cwds.pop()), os.path.realpath(repo_dir))
def test_only_the_fresh_build_is_uploaded(self):
calls, repo_dir = self.publish_with("https://pypi.org/project/example/", {})
upload = calls[-1].args[0]
self.assertEqual(
[os.path.basename(path) for path in upload if path.endswith(".tar.gz")],
["example-1.0.0.tar.gz"],
)
self.assertEqual(calls[2].args[0][-1], repo_dir)
def test_no_pkgmgr_variable_reaches_a_child(self):
calls, _ = self.publish_with(
"https://pypi.org/project/example/",
{"PKGMGR_PYPI_TOKEN": "secret", "PKGMGR_GITHUB_TOKEN": "secret"},
)
for call in calls:
self.assertFalse(
[name for name in call.kwargs["env"] if name.startswith("PKGMGR_")]
)
self.assertEqual(calls[-1].kwargs["env"]["TWINE_PASSWORD"], "t")
def test_no_repository_path_stays_on_the_children_pythonpath(self):
calls, _ = self.publish_with(
"https://pypi.org/project/example/",
{"PYTHONPATH": os.pathsep.join(["{repo}", "{repo}/src", "/opt/keep"])},
)
self.assertEqual(
{call.kwargs["env"]["PYTHONPATH"] for call in calls}, {"/opt/keep"}
)
def test_the_upload_goes_to_the_host_of_the_mirror(self):
for mirror, url in (
("https://pypi.org/project/example/", "https://upload.pypi.org/legacy/"),
("https://test.pypi.org/project/example/", "https://test.pypi.org/legacy/"),
):
with self.subTest(mirror=mirror):
calls, _ = self.publish_with(mirror, {})
upload = calls[-1].args[0]
self.assertIn("--non-interactive", upload)
self.assertEqual(upload[upload.index("--repository-url") + 1], url)
if __name__ == "__main__":
unittest.main()
@@ -140,6 +140,75 @@ class TestUpdatePyprojectVersion(unittest.TestCase):
self.assertEqual(content, original)
def write_dynamic_attr_project(self, tmpdir: str, module: str) -> str:
with open(os.path.join(tmpdir, "pyproject.toml"), "w", encoding="utf-8") as f:
f.write(
textwrap.dedent(
"""
[project]
name = "quality"
dynamic = ["version"]
[tool.setuptools]
package-dir = {"" = "src"}
[tool.setuptools.dynamic]
version = {attr = "quality.__version__"}
"""
).lstrip()
)
os.makedirs(os.path.join(tmpdir, "src", "quality"))
path = os.path.join(tmpdir, "src", "quality", "__init__.py")
with open(path, "w", encoding="utf-8") as f:
f.write(module)
return path
def test_a_dynamic_attr_version_is_bumped_in_its_module_and_read_back(self) -> None:
from pkgmgr.core.version.source import read_pyproject_version
with tempfile.TemporaryDirectory() as tmpdir:
module = self.write_dynamic_attr_project(
tmpdir, '"""Quality."""\n\n__version__ = "0.1.0"\n'
)
with open(os.path.join(tmpdir, "pyproject.toml"), encoding="utf-8") as f:
before = f.read()
self.assertEqual(read_pyproject_version(tmpdir), "0.1.0")
update_pyproject_version(
os.path.join(tmpdir, "pyproject.toml"), "0.2.0", preview=False
)
with open(module, encoding="utf-8") as f:
self.assertEqual(f.read(), '"""Quality."""\n\n__version__ = "0.2.0"\n')
with open(os.path.join(tmpdir, "pyproject.toml"), encoding="utf-8") as f:
self.assertEqual(f.read(), before)
self.assertEqual(read_pyproject_version(tmpdir), "0.2.0")
def test_a_dynamic_attr_version_preview_writes_nothing(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
module = self.write_dynamic_attr_project(tmpdir, "__version__ = '0.1.0'\n")
update_pyproject_version(
os.path.join(tmpdir, "pyproject.toml"), "0.2.0", preview=True
)
with open(module, encoding="utf-8") as f:
self.assertEqual(f.read(), "__version__ = '0.1.0'\n")
def test_a_dynamic_attr_module_without_the_literal_raises(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
self.write_dynamic_attr_project(
tmpdir,
"from importlib.metadata import version\n__version__ = version('quality')\n",
)
with self.assertRaises(RuntimeError) as cm:
update_pyproject_version(
os.path.join(tmpdir, "pyproject.toml"), "0.2.0", preview=False
)
self.assertIn("Missing __version__ literal", str(cm.exception))
def test_update_pyproject_version_missing_file_is_skipped(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
path = os.path.join(tmpdir, "pyproject.toml")