mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 22:37:29 +00:00
fix(roles): bring the role_version lookup and its image-check resolution to main
Custom roles such as web-app-cst-store pin their images to their own release,
`v{{ lookup('role_version', '<role>') }}`. Main had neither the lookup nor the
image discovery that resolves it, so core's external image tests rejected the
template as neither version nor digest and asked the registry for the literal
string (GUI CI job core / custom-role (test), red since 2026-11-11).
Ports e615f5fa22 (record the source semver in the pull marker, add the
role_version lookup) and ed9101780e (resolve role_version pins in image
checks) from the production line, without the rest of that branch. Adds
tests/unit/python/tests/external/update/docker/test_role_version_pins.py,
which runs the real pin-policy and reachability checks against a custom-role
fixture with the registry mocked; reverting the discovery change fails it at
the same lines as the GUI CI.
🎯 Fix: 94 %
💥 Break: 3 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 91
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c57939d717
commit
f6613b78fd
20 files changed
+600
-49
No files matched your search
@@ -68,12 +68,15 @@ def write(path: Path, text: str) -> Path:
|
||||
def role_repo(root: Path, application_id: str = ROLE) -> Path:
|
||||
"""A repository whose tag ``v1.0.0`` holds the role and whose branch ``feature`` moved on.
|
||||
|
||||
The repository root declares ``version = "1.0.0"`` in ``Cargo.toml``.
|
||||
|
||||
Args:
|
||||
root: directory the repository is created in.
|
||||
application_id: the ``vars/main.yml`` application_id of the role.
|
||||
"""
|
||||
repo = root / "repo"
|
||||
write(repo / "README.md", "repository root\n")
|
||||
write(repo / "Cargo.toml", '[package]\nname = "demo"\nversion = "1.0.0"\n')
|
||||
write(repo / ROLE_PATH / ROLE_FILE_META_MAIN, "galaxy_info: {}\n")
|
||||
write(repo / ROLE_PATH / ROLE_FILE_VARS_MAIN, f"application_id: {application_id}\n")
|
||||
write(repo / ROLE_PATH / ROLE_FILE_TASKS_MAIN, "release: v1\n")
|
||||
|
||||
@@ -20,7 +20,8 @@ class TestListMain(unittest.TestCase):
|
||||
marker = roles / "web-app-cst-a" / MARKER_FILE
|
||||
marker.parent.mkdir()
|
||||
marker.write_text(
|
||||
marker_text("web-app-cst-a", "web-app-cst-a", ORIGIN), encoding="utf-8"
|
||||
marker_text("web-app-cst-a", "web-app-cst-a", ORIGIN, "1.0.0"),
|
||||
encoding="utf-8",
|
||||
)
|
||||
(roles / "web-app-cst-hand").mkdir()
|
||||
(roles / "web-app-nextcloud").mkdir()
|
||||
|
||||
@@ -16,11 +16,13 @@ from cli.administration.roles.marker import (
|
||||
provenance,
|
||||
write_marker,
|
||||
)
|
||||
from utils.roles.custom import marker_fields
|
||||
|
||||
from ._fixtures import write
|
||||
|
||||
ORIGIN = "https://example.invalid/w.git ansible/roles/web-app-cst-a @ v1 (commit abc)"
|
||||
PLACED = "web-app-cst-a"
|
||||
VERSION = "1.4.2"
|
||||
|
||||
|
||||
class TestMarker(unittest.TestCase):
|
||||
@@ -28,7 +30,10 @@ class TestMarker(unittest.TestCase):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.roles = Path(tmp.name) / "roles"
|
||||
write(self.roles / PLACED / MARKER_FILE, marker_text(PLACED, PLACED, ORIGIN))
|
||||
write(
|
||||
self.roles / PLACED / MARKER_FILE,
|
||||
marker_text(PLACED, PLACED, ORIGIN, VERSION),
|
||||
)
|
||||
write(self.roles / "web-app-cst-hand" / "mine.yml", "mine: true\n")
|
||||
write(self.roles / "web-app-cst-forged" / MARKER_FILE, "something else\n")
|
||||
shutil.copytree(self.roles / PLACED, self.roles / "web-app-cst-copy")
|
||||
@@ -38,7 +43,7 @@ class TestMarker(unittest.TestCase):
|
||||
)
|
||||
write(
|
||||
self.roles / "web-app-nextcloud" / MARKER_FILE,
|
||||
marker_text("web-app-nextcloud", "web-app-nextcloud", ORIGIN),
|
||||
marker_text("web-app-nextcloud", "web-app-nextcloud", ORIGIN, ""),
|
||||
)
|
||||
(self.roles / "web-app-cst-link").symlink_to(self.roles / PLACED)
|
||||
|
||||
@@ -65,6 +70,12 @@ class TestMarker(unittest.TestCase):
|
||||
def test_provenance_reads_back_what_the_pull_recorded(self):
|
||||
self.assertEqual(ORIGIN, provenance(self.roles / PLACED))
|
||||
|
||||
def test_the_version_the_pull_recorded_reads_back(self):
|
||||
self.assertEqual(VERSION, marker_fields(self.roles / PLACED)["version"])
|
||||
|
||||
def test_a_marker_without_a_version_has_no_version_field(self):
|
||||
self.assertNotIn("version", marker_fields(self.roles / "web-app-nextcloud"))
|
||||
|
||||
def test_custom_entries_are_every_prefixed_entry(self):
|
||||
self.assertEqual(
|
||||
[
|
||||
@@ -91,14 +102,15 @@ class TestWriteMarker(unittest.TestCase):
|
||||
self.role.mkdir()
|
||||
|
||||
def test_marker_names_the_directory_and_the_group(self):
|
||||
write_marker(self.role, PLACED, ORIGIN)
|
||||
write_marker(self.role, PLACED, ORIGIN, VERSION)
|
||||
self.assertTrue(is_placed(self.role))
|
||||
self.assertEqual(ORIGIN, provenance(self.role))
|
||||
self.assertEqual(VERSION, marker_fields(self.role)["version"])
|
||||
|
||||
def test_a_symbolic_link_under_the_marker_name_is_replaced_not_followed(self):
|
||||
victim = write(self.root / "victim.yml", "victim: true\n")
|
||||
(self.role / MARKER_FILE).symlink_to(victim)
|
||||
write_marker(self.role, PLACED, ORIGIN)
|
||||
write_marker(self.role, PLACED, ORIGIN, VERSION)
|
||||
text = victim.read_text(encoding="utf-8") # nocheck: cache-read tempdir
|
||||
self.assertEqual("victim: true\n", text)
|
||||
self.assertFalse((self.role / MARKER_FILE).is_symlink())
|
||||
@@ -106,13 +118,13 @@ class TestWriteMarker(unittest.TestCase):
|
||||
|
||||
def test_a_directory_under_the_marker_name_is_replaced(self):
|
||||
write(self.role / MARKER_FILE / "nested.yml", "nested: true\n")
|
||||
write_marker(self.role, PLACED, ORIGIN)
|
||||
write_marker(self.role, PLACED, ORIGIN, VERSION)
|
||||
self.assertTrue((self.role / MARKER_FILE).is_file())
|
||||
self.assertTrue(is_placed(self.role))
|
||||
|
||||
def test_the_marker_is_readable_by_its_owner_only_whatever_the_umask(self):
|
||||
self.addCleanup(os.umask, os.umask(0))
|
||||
write_marker(self.role, PLACED, ORIGIN)
|
||||
write_marker(self.role, PLACED, ORIGIN, VERSION)
|
||||
mode = (self.role / MARKER_FILE).stat().st_mode
|
||||
self.assertEqual(0o600, stat.S_IMODE(mode))
|
||||
self.assertTrue(is_placed(self.role))
|
||||
|
||||
@@ -108,7 +108,25 @@ class TestStage(_SourceFixture, unittest.TestCase):
|
||||
sha = git(self.repo, "rev-parse", "v1.0.0^{commit}").strip()
|
||||
self.assertEqual("release: v1\n", read_text(str(target / ROLE_FILE_TASKS_MAIN)))
|
||||
self.assertFalse((target / "README.md").exists())
|
||||
self.assertIn(f"(commit {sha})", origin)
|
||||
self.assertFalse((target / "Cargo.toml").exists())
|
||||
self.assertIn(f"(commit {sha})", origin.provenance)
|
||||
self.assertEqual("1.0.0", origin.version)
|
||||
|
||||
def test_tag_reads_the_version_its_own_commit_declares(self):
|
||||
write(self.repo / "Cargo.toml", '[package]\nname = "demo"\nversion = "2.0.0"\n')
|
||||
git(self.repo, "commit", "-q", "-am", "bump")
|
||||
git(self.repo, "tag", "v2.0.0")
|
||||
target = self.root / "staged"
|
||||
origin = stage(ROLE, Source(str(self.repo), "v1.0.0", ROLE_PATH), target)
|
||||
self.assertEqual("1.0.0", origin.version)
|
||||
|
||||
def test_tag_without_a_version_manifest_records_none(self):
|
||||
git(self.repo, "rm", "-q", "Cargo.toml")
|
||||
git(self.repo, "commit", "-q", "-m", "drop manifest")
|
||||
git(self.repo, "tag", "v3.0.0")
|
||||
target = self.root / "staged"
|
||||
origin = stage(ROLE, Source(str(self.repo), "v3.0.0", ROLE_PATH), target)
|
||||
self.assertEqual("", origin.version)
|
||||
|
||||
def test_full_commit_sha_is_staged(self):
|
||||
sha = git(self.repo, "rev-parse", "v1.0.0^{commit}").strip()
|
||||
@@ -125,7 +143,17 @@ class TestStage(_SourceFixture, unittest.TestCase):
|
||||
"release: uncommitted\n", read_text(str(target / ROLE_FILE_TASKS_MAIN))
|
||||
)
|
||||
self.assertFalse((target / "__pycache__").exists())
|
||||
self.assertIn("(working tree)", origin)
|
||||
self.assertIn("(working tree)", origin.provenance)
|
||||
self.assertEqual("1.0.0", origin.version)
|
||||
|
||||
def test_local_directory_reads_the_version_of_its_working_tree(self):
|
||||
write(
|
||||
self.repo / "Cargo.toml",
|
||||
'[package]\nname = "demo"\nversion = "1.1.0-rc.1"\n',
|
||||
)
|
||||
target = self.root / "staged"
|
||||
origin = stage(ROLE, Source(str(self.repo), None, ROLE_PATH), target)
|
||||
self.assertEqual("1.1.0-rc.1", origin.version)
|
||||
|
||||
def test_local_directory_skips_unreadable_agent_harness_state(self):
|
||||
harness = self.repo / ROLE_PATH / ".claude" / ".cc-writes"
|
||||
|
||||
Reference in new issue
Block a user